Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
ipld-dag-pb
Advanced tools
JavaScript Implementation of the IPLD Format MerkleDAG Node in Protobuf. In addition to the IPLD Format methods, this module also provides an API for creating the nodes and manipulating them (adding and removing links, etc).
dagPB.util.cid
dagPB.util.serialize
dagPB.util.deserialize
> npm install ipld-dag-pb --save
const dagPB = require('ipld-dag-pb')
dagPB.DAGNode.create // create a DAGNode
dagPB.DAGNode.clone // clone a DAGNode
dagPB.DAGNode.addLink // add a Link to a DAGNode, creating a new one
dagPB.DAGNode.rmLink // remove a Link to a DAGNode, creating a new one
// IPLD Format specifics
dagPB.resolver
dagPB.util
const node1 = DAGNode.create(Buffer.from('some data'))
// node2 will have the same data as node1
const node2 = DAGNode.create('some data')
const link = {
Name: 'I am a link',
Hash: 'QmHash..',
Tsize: 42
}
const nodeA = await DAGNode.addLink(node, link)
// nodeA - DAGNode instance with the link
console.log('with link', nodeA.toJSON())
const nodeB = await DAGNode.rmLink(nodeA, 'I am a link')
// nodeB - DAGNode instance without the link, equal to just node
console.log('without link', nodeB.toJSON())
DAGNodes are immutable objects, in order to manipulate them you have to follow a function approach of applying function and getting new instances of the given DAGNode.
You can incude it in your project with:
const dagPB = require('ipld-dag-pb')
const DAGNode = dagPB.DAGNode
data
- type: Bufferlinks
- type: Array of DAGLink instances or Array of DAGLink instances in its json format (link.toJSON)Create a DAGNode.
const dagNode = DAGNode.create('data', links)
links can be a single or an array of DAGLinks instances or objects with the following pattern
{
Name: '<some name>',
Hash: '<some cid>',
TSize: <sizeInBytes>
}
node
- type: DAGNodelink
- type: DAGLink or DAGLink in its json formatCreates a link on node A to node B by using node B to get its CID. Returns a new instance of DAGNode without modifying the old one.
Creates a new DAGNode instance with the union of node.links plus the new link.
link
can be:
const link = {
Name: '<some string>', // optional
Tsize: <size in bytes>,
Hash: <cid> // can be a String CID, CID buffer or CID object
}
const dagNode = await DAGNode.addLink(node, link)
node
- type: DAGNodenameOrCid
- type: String, CID object or CID bufferRemoves a link from the node by name. Returns a new instance of DAGNode without modifying the old one.
const dagNode = await DAGNode.rmLink(node, 'Link1')
node
- type: DAGNodeCreates a clone of the DAGNode instance passed
const nodeClone = DAGNode.clone(node)
You have the following methods and properties available in every DAGNode instance.
node.Data
node.Links
An array of JSON Objects with fields named Hash
, Name
, and Tsize
.
node.size
Size of the node, in bytes
node.toJSON()
node.toString()
Following the same pattern as DAGNode functions
above, DAGLink also offers a function for its creation.
You can incude it in your project with:
const dagPB = require('ipld-dag-pb')
const DAGLink = dagPB.DAGLink
// link is a DAGLink instance
const link = new DAGLink(
'link-to-file', // name of the link (can be empty)
10, // size in bytes
'QmSomeHash...', // can be CID object, CID buffer or string
)
link.Name
link.Tsize
link.Hash
link.toJSON()
link.toString()
See: https://github.com/ipld/interface-ipld-format#local-resolver-methods
dagPB.resolver.resolve
dagPB.resolver.tree
See: https://github.com/ipld/interface-ipld-format#ipld-format-utils
dagPB.util.cid
dagPB.util.serialize
dagPB.util.deserialize
Please contribute! Look at the issues!
Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to IPLD are subject to the IPFS Code of Conduct.
Small note: If editing the README, please conform to the standard-readme specification.
ISC © 2016 Protocol Labs Inc.
FAQs
JavaScript Implementation of the MerkleDAG Node in Protobuf.
The npm package ipld-dag-pb receives a total of 22,495 weekly downloads. As such, ipld-dag-pb popularity was classified as popular.
We found that ipld-dag-pb demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.