Name: js-ipld-graph-builder
Owner: IPLD
Description: Provides an efficient way to build and manipulate IPLD DAGs as JSON
Created: 2016-10-18 17:54:18.0
Updated: 2018-05-20 06:40:53.0
Pushed: 2018-05-07 08:59:11.0
Size: 511
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
This provides an efficent way to build and manipulate IPLD DAGs as JSON. This is accomplished by only producing merkle roots when flush
ing the DAG. If any object has a “/” property, its value will be replaced with the merkle hash of that value when flushed. This allows you to build object anyway you like.
npm install ipld-graph-builder
t IPFS = require('ipfs')
t Graph = require('ipld-graph-builder')
t ipfs = new IPFS()
.on('start', () => {
nst graph = new Graph(ipfs.dag)
nst a = {
some: {
thing: 'nested'
}
nst b = {
lol: 1
aph.set(a, 'some/thing/else', b).then(result => {
// set "patches" together two objects
console.log(JSON.stringify(result))
> {
> "some": {
> "thing": {
> "else": {
> "/": {
> "lol": 1
> }
> }
> }
> }
>}
// flush replaces the links with merkle links, resulting in a single root hash
graph.flush(result).then((result) => {
console.log(result)
> { '/': 'zdpuAqnGt7k49xSfawetvZXSLm4b1vvkSMnDrk4NFqnCCnW5V' }
// taverse paths through merkle links given a starting vertex
graph.get(result, 'some/thing/else').then(result2 => {
console.log(result2)
> { lol: 1 }
})
})
Additonally you can define the encoding of each link by adding the follow options
property to un-merklized links. options
will be used as the options argument for DAG.put
. For Example:
y-link': {
'/': {
'some': 'stuff here'
},
'options': {
format: 'dag-cbor',
hashAlg: 'sha2-256'
}
npm run tests