This repository has been archived by the owner on Aug 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: It's no longer possible to pass a `DAGNode` into `addLink()`. Intead of passing in a `DAGNode` into `addLink()`, convert that node into a `DAGLink` via `toDAGLink()`. Example: Prior to this change: const node = new DAGNode('some data') const node2 = new DAGNode('use that as link') await DAGNode.addLink(node, node2) Now: const node = new DAGNode('some data') const node2 = new DAGNode('use that as link') DAGNode.addLink(node, await node2.toDAGLink()) Closes #128.
- Loading branch information
Showing
7 changed files
with
84 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict' | ||
|
||
const CID = require('cids') | ||
const multicodec = require('multicodec') | ||
const multihashing = require('multihashing-async') | ||
|
||
exports = module.exports | ||
|
||
exports.codec = multicodec.DAG_PB | ||
exports.defaultHashAlg = multicodec.SHA2_256 | ||
|
||
/** | ||
* Calculate the CID of the binary blob. | ||
* | ||
* @param {Object} binaryBlob - Encoded IPLD Node | ||
* @param {Object} [userOptions] - Options to create the CID | ||
* @param {number} [userOptions.cidVersion=1] - CID version number | ||
* @param {string} [UserOptions.hashAlg] - Defaults to the defaultHashAlg of the format | ||
* @returns {Promise.<CID>} | ||
*/ | ||
const cid = async (binaryBlob, userOptions) => { | ||
const defaultOptions = { cidVersion: 1, hashAlg: exports.defaultHashAlg } | ||
const options = Object.assign(defaultOptions, userOptions) | ||
|
||
const multihash = await multihashing(binaryBlob, options.hashAlg) | ||
const codecName = multicodec.print[exports.codec] | ||
const cid = new CID(options.cidVersion, codecName, multihash) | ||
|
||
return cid | ||
} | ||
|
||
exports.cid = cid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters