Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Commit fcc2ab5

Browse files
committed
feat: add util.serialize, util.deserialize and util.cid
1 parent 89f1715 commit fcc2ab5

11 files changed

Lines changed: 83 additions & 174 deletions

File tree

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
"babel-runtime": "^6.6.1",
4141
"bs58": "^3.0.0",
4242
"cbor": "^1.0.4",
43+
"cbor-sync": "^1.0.2",
44+
"cids": "^0.1.1",
4345
"lodash.clonedeep": "^4.3.2",
4446
"lodash.defaults": "^4.0.1",
4547
"lodash.includes": "^4.1.3",
@@ -49,7 +51,7 @@
4951
"nofilter": "0.0.2"
5052
},
5153
"devDependencies": {
52-
"aegir": "^3.0.4",
54+
"aegir": "8.1.2",
5355
"chai": "^3.5.0",
5456
"pre-commit": "^1.1.3"
5557
},

src/cbor.js

Lines changed: 0 additions & 105 deletions
This file was deleted.

src/dag-node.js

Whitespace-only changes.

src/index.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
'use strict'
22

3-
const cbor = require('./cbor')
4-
const multihash = require('./multihash')
5-
6-
exports = module.exports
7-
8-
exports.LINK_TAG = cbor.LINK_TAG
9-
exports.LINK_SYMBOL = cbor.LINK_SYMBOL
10-
exports.marshal = cbor.marshal
11-
exports.unmarshal = cbor.unmarshal
12-
exports.multihash = multihash
3+
exports.DAGNode = require('./dag-node.js')
4+
exports.util = require('./util.js')
5+
exports.resolver = require('./resolver.js')

src/multihash.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/resolver.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict'
2+
3+
exports = module.exports
4+
5+
exports.multicodec = 'dag-cbor'
6+
7+
/*
8+
* resolve: receives a path and a block and returns the value on path,
9+
* throw if not possible. `block` is an IPFS Block instance (contains data+key)
10+
*/
11+
exports.resolve = (block, path) => {
12+
}
13+
14+
/*
15+
* tree: returns a flattened array with paths: values of the project. options
16+
* are option (i.e. nestness)
17+
*/
18+
exports.tree = (block, options) => {
19+
if (!options) {
20+
options = {}
21+
}
22+
}
23+
24+
// TODO recheck this API
25+
/*
26+
* patch: modifies or adds value on path, yields a new block with that change
27+
*/
28+
exports.patch = (block, path, value) => {}

src/util.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict'
2+
3+
const cbor = require('cbor-sync')
4+
const multihashing = require('multihashing')
5+
const CID = require('cids')
6+
const resolver = require('./resolver')
7+
8+
exports = module.exports
9+
10+
exports.serialize = (dagNode) => {
11+
return cbor.encode(dagNode)
12+
}
13+
14+
exports.deserialize = (data) => {
15+
return cbor.decode(data)
16+
}
17+
18+
exports.cid = (dagNode) => {
19+
const serialized = exports.serialize(dagNode)
20+
const mh = multihashing(serialized, 'sha2-256')
21+
return new CID(1, resolver.multicodec, mh)
22+
}

test/multihash.spec.js

Lines changed: 0 additions & 44 deletions
This file was deleted.
File renamed without changes.

test/resolver.spec.js

Whitespace-only changes.

0 commit comments

Comments
 (0)