Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

[WIP] refactor: default to CID v1 and encode with base32 #1868

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"execa": "^1.0.0",
"form-data": "^2.3.3",
"hat": "0.0.3",
"interface-ipfs-core": "~0.97.1",
"interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#refactor/cidv1b32-default",
"ipfsd-ctl": "~0.41.0",
"libp2p-websocket-star": "~0.10.2",
"ncp": "^2.0.0",
Expand All @@ -86,8 +86,8 @@
"boom": "^7.2.0",
"bs58": "^4.0.1",
"byteman": "^1.3.5",
"cid-tool": "~0.2.0",
"cids": "~0.5.5",
"cid-tool": "github:multiformats/js-cid-tool#refactor/cidv1base32-default",
"cids": "github:multiformats/js-cid#refactor/cidv1base32-default",
"class-is": "^1.1.0",
"datastore-core": "~0.6.0",
"datastore-pubsub": "~0.1.1",
Expand All @@ -103,24 +103,24 @@
"hoek": "^6.1.2",
"human-to-milliseconds": "^1.0.0",
"interface-datastore": "~0.6.0",
"ipfs-bitswap": "~0.22.0",
"ipfs-block": "~0.8.0",
"ipfs-bitswap": "github:ipfs/js-ipfs-bitswap#refactor/cidv1base32-default",
"ipfs-block": "github:ipfs/js-ipfs-block#refactor/cidv1base32-default",
"ipfs-block-service": "~0.15.1",
"ipfs-http-client": "^29.0.0",
"ipfs-http-response": "~0.2.1",
"ipfs-mfs": "~0.9.1",
"ipfs-http-response": "github:ipfs/js-ipfs-http-response#refactor/cidv1base32-default",
"ipfs-mfs": "github:ipfs/js-ipfs-mfs#refactor/cidv1b32-default",
"ipfs-multipart": "~0.1.0",
"ipfs-repo": "~0.26.1",
"ipfs-unixfs": "~0.1.16",
"ipfs-unixfs-engine": "~0.35.3",
"ipld": "~0.21.1",
"ipld-bitcoin": "~0.1.8",
"ipld-dag-pb": "~0.15.0",
"ipld-ethereum": "^2.0.1",
"ipld-git": "~0.2.2",
"ipld-zcash": "~0.1.6",
"ipfs-unixfs-engine": "github:ipfs/js-ipfs-unixfs-engine#refactor/cidv1b32-default",
"ipld": "github:ipld/js-ipld#refactor/cidv1base32-default",
"ipld-bitcoin": "github:ipld/js-ipld-bitcoin#refactor/cidv1base32-default",
"ipld-dag-pb": "github:ipld/js-ipld-dag-pb#refactor/cidv1b32-default",
"ipld-ethereum": "github:ipld/js-ipld-ethereum#refactor/cidv1base32-default",
"ipld-git": "github:ipld/js-ipld-git#refactor/cidv1base32-default",
"ipld-zcash": "github:ipld/js-ipld-zcash#refactor/cidv1base32-default",
"ipns": "~0.5.0",
"is-ipfs": "~0.4.8",
"is-ipfs": "github:ipfs/is-ipfs#refactor/cidv1base32-default",
"is-pull-stream": "~0.0.0",
"is-stream": "^1.1.0",
"joi": "^14.3.0",
Expand Down
9 changes: 1 addition & 8 deletions src/core/components/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,9 @@ module.exports = function block (self) {

const mhtype = options.mhtype || 'sha2-256'
const format = options.format || 'dag-pb'
let cidVersion
const cidVersion = options.version == null ? 1 : options.version
// const mhlen = options.mhlen || 0

if (options.version == null) {
// Pick appropriate CID version
cidVersion = mhtype === 'sha2-256' && format === 'dag-pb' ? 0 : 1
} else {
cidVersion = options.version
}

multihashing(block, mhtype, (err, multihash) => {
if (err) {
return cb(err)
Expand Down
6 changes: 3 additions & 3 deletions src/core/components/files-regular/add-pull-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function prepareFile (file, self, opts, callback) {
? cb(null, file)
: self.object.get(file.multihash, Object.assign({}, opts, { preload: false }), cb),
(node, cb) => {
const b58Hash = cid.toBaseEncodedString()
const cidStr = cid.toBaseEncodedString()

let size = node.size

Expand All @@ -38,8 +38,8 @@ function prepareFile (file, self, opts, callback) {
cb(null, {
path: opts.wrapWithDirectory
? file.path.substring(WRAPPER.length)
: (file.path || b58Hash),
hash: b58Hash,
: (file.path || cidStr),
hash: cidStr,
size
})
}
Expand Down
9 changes: 4 additions & 5 deletions src/core/components/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const dagPB = require('ipld-dag-pb')
const DAGNode = dagPB.DAGNode
const DAGLink = dagPB.DAGLink
const CID = require('cids')
const mh = require('multihashes')
const Unixfs = require('ipfs-unixfs')
const errCode = require('err-code')

Expand Down Expand Up @@ -50,7 +49,7 @@ function parseJSONBuffer (buf, callback) {
return new DAGLink(
link.Name || link.name,
link.Size || link.size,
mh.fromB58String(link.Hash || link.hash || link.multihash)
link.Hash || link.hash || link.multihash
)
})
data = Buffer.from(parsed.Data)
Expand Down Expand Up @@ -88,7 +87,7 @@ module.exports = function object (self) {
}

self._ipld.put(node, {
version: 0,
version: 1,
hashAlg: 'sha2-256',
format: 'dag-pb'
}, (err, cid) => {
Expand Down Expand Up @@ -138,7 +137,7 @@ module.exports = function object (self) {
}

self._ipld.put(node, {
version: 0,
version: 1,
hashAlg: 'sha2-256',
format: 'dag-pb'
}, (err, cid) => {
Expand Down Expand Up @@ -201,7 +200,7 @@ module.exports = function object (self) {

function next () {
self._ipld.put(node, {
version: 0,
version: 1,
hashAlg: 'sha2-256',
format: 'dag-pb'
}, (err, cid) => {
Expand Down
18 changes: 6 additions & 12 deletions test/cli/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ describe('object', () => runOnAndOff((thing) => {
})
})

// TODO: unskip after switch to v1 CIDs by default
it.skip('should new and print CID encoded in specified base', () => {
it('should new and print CID encoded in specified base', () => {
return ipfs('object new --cid-base=base64').then((out) => {
expect(out).to.eql(
'mAXASIOOwxEKY/BwUmvv0yJlvuSQnrkHkZJuTTKSVmRt4UrhV\n'
Expand Down Expand Up @@ -103,8 +102,7 @@ describe('object', () => runOnAndOff((thing) => {
})
})

// TODO: unskip after switch to v1 CIDs by default
it.skip('should put and print CID encoded in specified base', () => {
it('should put and print CID encoded in specified base', () => {
return ipfs('object put test/fixtures/test-data/node.json --cid-base=base64')
.then((out) => {
expect(out).to.eql(
Expand Down Expand Up @@ -188,8 +186,7 @@ describe('object', () => runOnAndOff((thing) => {
})
})

// TODO: unskip after switch to v1 CIDs by default
it.skip('should append-data and print CID encoded in specified base', () => {
it('should append-data and print CID encoded in specified base', () => {
return ipfs('object patch append-data QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n test/fixtures/test-data/badconfig --cid-base=base64').then((out) => {
expect(out).to.eql(
'mAXASIP+BZ7jGtaTyLGOs0xYcQvH7K9kVKEbyzXAkwLoZwrRj\n'
Expand All @@ -205,8 +202,7 @@ describe('object', () => runOnAndOff((thing) => {
})
})

// TODO: unskip after switch to v1 CIDs by default
it.skip('should set-data and print CID encoded in specified base', () => {
it('should set-data and print CID encoded in specified base', () => {
return ipfs('object patch set-data QmfY37rjbPCZRnhvvJuQ46htW3VCAWziVB991P79h6WSv6 test/fixtures/test-data/badconfig --cid-base=base64').then((out) => {
expect(out).to.eql(
'mAXASIP+BZ7jGtaTyLGOs0xYcQvH7K9kVKEbyzXAkwLoZwrRj\n'
Expand All @@ -222,8 +218,7 @@ describe('object', () => runOnAndOff((thing) => {
})
})

// TODO: unskip after switch to v1 CIDs by default
it.skip('should add-link and print CID encoded in specified base', () => {
it('should add-link and print CID encoded in specified base', () => {
return ipfs('object patch add-link QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n foo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn --cid-base=base64').then((out) => {
expect(out).to.eql(
'mAXASIOEVPbXq2xYoEsRZhaPB61btcy1x359osjv4a2L/lgPs\n'
Expand All @@ -239,8 +234,7 @@ describe('object', () => runOnAndOff((thing) => {
})
})

// TODO: unskip after switch to v1 CIDs by default
it.skip('should rm-link and print CID encoded in specified base', () => {
it('should rm-link and print CID encoded in specified base', () => {
return ipfs('object patch rm-link QmdVHE8fUD6FLNLugtNxqDFyhaCgdob372hs6BYEe75VAK foo --cid-base=base64').then((out) => {
expect(out).to.eql(
'mAXASIOOwxEKY/BwUmvv0yJlvuSQnrkHkZJuTTKSVmRt4UrhV\n'
Expand Down
27 changes: 9 additions & 18 deletions test/http-api/inject/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ module.exports = (http) => {
expect(res.result.Links).to.be.eql([])
})

// TODO: unskip after switch to v1 CIDs by default
it.skip('should create a new object and return a base64 encoded CID', async () => {
it('should create a new object and return a base64 encoded CID', async () => {
const res = await api.inject({
method: 'POST',
url: '/api/v0/object/new?cid-base=base64'
Expand Down Expand Up @@ -88,8 +87,7 @@ module.exports = (http) => {
expect(res.result.Data).to.be.empty()
})

// TODO: unskip after switch to v1 CIDs by default
it.skip('should get object and return a base64 encoded CID', async () => {
it('should get object and return a base64 encoded CID', async () => {
let res = await api.inject({
method: 'POST',
url: '/api/v0/object/new'
Expand Down Expand Up @@ -185,8 +183,7 @@ module.exports = (http) => {
expect(res.result).to.eql(expectedResult)
})

// TODO: unskip after switch to v1 CIDs by default
it.skip('should put data and return a base64 encoded CID', async () => {
it('should put data and return a base64 encoded CID', async () => {
const form = new FormData()
form.append('file', JSON.stringify({ Data: 'TEST' + Date.now(), Links: [] }), { filename: 'node.json' })
const headers = form.getHeaders()
Expand Down Expand Up @@ -258,8 +255,7 @@ module.exports = (http) => {
expect(res.result.CumulativeSize).to.equal(60 + 8)
})

// TODO: unskip after switch to v1 CIDs by default
it.skip('should stat object and return a base64 encoded CID', async () => {
it('should stat object and return a base64 encoded CID', async () => {
let res = await api.inject({
method: 'POST',
url: '/api/v0/object/new'
Expand Down Expand Up @@ -366,8 +362,7 @@ module.exports = (http) => {
expect(res.result).to.deep.equal(expectedResult)
})

// TODO: unskip after switch to v1 CIDs by default
it.skip('should list object links and return a base64 encoded CID', async () => {
it('should list object links and return a base64 encoded CID', async () => {
let res = await api.inject({
method: 'POST',
url: '/api/v0/object/new'
Expand Down Expand Up @@ -509,8 +504,7 @@ module.exports = (http) => {
expect(res.result).to.deep.equal(expectedResult)
})

// TODO: unskip after switch to v1 CIDs by default
it.skip('should append data to object and return a base64 encoded CID', async () => {
it('should append data to object and return a base64 encoded CID', async () => {
let res = await api.inject({
method: 'POST',
url: '/api/v0/object/new'
Expand Down Expand Up @@ -624,8 +618,7 @@ module.exports = (http) => {
expect(res.result).to.deep.equal(expectedResult)
})

// TODO: unskip after switch to v1 CIDs by default
it.skip('should set data for object and return a base64 encoded CID', async () => {
it('should set data for object and return a base64 encoded CID', async () => {
let res = await api.inject({
method: 'POST',
url: '/api/v0/object/new'
Expand Down Expand Up @@ -731,8 +724,7 @@ module.exports = (http) => {
})
})

// TODO: unskip after switch to v1 CIDs by default
it.skip('should add a link to an object and return a base64 encoded CID', async () => {
it('should add a link to an object and return a base64 encoded CID', async () => {
let res = await api.inject({
method: 'POST',
url: '/api/v0/object/new'
Expand Down Expand Up @@ -820,8 +812,7 @@ module.exports = (http) => {
expect(res.result.Hash).to.equal('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')
})

// TODO: unskip after switch to v1 CIDs by default
it.skip('should remove a link from an object and return a base64 encoded CID', async () => {
it('should remove a link from an object and return a base64 encoded CID', async () => {
const linkName = 'TEST' + Date.now()

let res = await api.inject({
Expand Down