diff --git a/packages/interface-ipfs-core/src/block/get.js b/packages/interface-ipfs-core/src/block/get.js index 7ab52f83ff..c9790daa1f 100644 --- a/packages/interface-ipfs-core/src/block/get.js +++ b/packages/interface-ipfs-core/src/block/get.js @@ -2,7 +2,7 @@ 'use strict' const uint8ArrayFromString = require('uint8arrays/from-string') -const multihash = require('multihashing-async').multihash +const multihashing = require('multihashing-async') const CID = require('cids') const { getDescribe, getIt, expect } = require('../utils/mocha') const testTimeout = require('../utils/test-timeout') @@ -43,7 +43,7 @@ module.exports = (common, options) => { }) it('should get by CID in string', async () => { - const block = await ipfs.block.get(multihash.toB58String(hash)) + const block = await ipfs.block.get(multihashing.multihash.toB58String(hash)) expect(block.data).to.eql(uint8ArrayFromString('blorb')) expect(block.cid.multihash).to.eql(hash) @@ -89,6 +89,14 @@ module.exports = (common, options) => { expect(block.data).to.eql(input) }) + it('should get a block with an identity CID, without putting first', async () => { + const identityData = uint8ArrayFromString('A16461736466190144', 'base16upper') + const identityHash = await multihashing(identityData, 'identity') + const identityCID = new CID(1, 'dag-cbor', identityHash) + const block = await ipfs.block.get(identityCID) + expect(block.data).to.eql(identityData) + }) + it('should return an error for an invalid CID', () => { return expect(ipfs.block.get('Non-base58 character')).to.eventually.be.rejected .and.be.an.instanceOf(Error) diff --git a/packages/interface-ipfs-core/src/dag/get.js b/packages/interface-ipfs-core/src/dag/get.js index 4bff6a9528..cc7f7803e6 100644 --- a/packages/interface-ipfs-core/src/dag/get.js +++ b/packages/interface-ipfs-core/src/dag/get.js @@ -11,6 +11,7 @@ const all = require('it-all') const CID = require('cids') const { getDescribe, getIt, expect } = require('../utils/mocha') const testTimeout = require('../utils/test-timeout') +const multihashing = require('multihashing-async') /** @typedef { import("ipfsd-ctl/src/factory") } Factory */ /** @@ -240,6 +241,14 @@ module.exports = (common, options) => { expect(result.value).to.deep.equal(buf) }) + it('should be able to get a dag-cbor node with the identity hash', async () => { + const identityData = uint8ArrayFromString('A16461736466190144', 'base16upper') + const identityHash = await multihashing(identityData, 'identity') + const identityCID = new CID(1, 'dag-cbor', identityHash) + const result = await ipfs.dag.get(identityCID) + expect(result.value).to.deep.equal({ asdf: 324 }) + }) + it('should throw error for invalid string CID input', () => { return expect(ipfs.dag.get('INVALID CID')) .to.eventually.be.rejected() diff --git a/packages/ipfs-core/src/components/repo/gc.js b/packages/ipfs-core/src/components/repo/gc.js index cc3fdfd138..e022c23f89 100644 --- a/packages/ipfs-core/src/components/repo/gc.js +++ b/packages/ipfs-core/src/components/repo/gc.js @@ -17,6 +17,7 @@ const BLOCK_RM_CONCURRENCY = 256 * @typedef {import('ipfs-core-types/src/refs').API} RefsAPI * @typedef {import('ipfs-repo')} IPFSRepo * @typedef {import('interface-datastore').Key} Key + * @typedef {import('ipld-block')} Block */ /** diff --git a/packages/ipfs-http-server/src/api/resources/block.js b/packages/ipfs-http-server/src/api/resources/block.js index be4e47ecae..df8108da05 100644 --- a/packages/ipfs-http-server/src/api/resources/block.js +++ b/packages/ipfs-http-server/src/api/resources/block.js @@ -69,7 +69,7 @@ exports.get = { throw Boom.notFound('Block was unwanted before it could be remotely retrieved') } - return h.response(block.data).header('X-Stream-Output', '1') + return h.response(Buffer.from(block.data.buffer, block.data.byteOffset, block.data.byteLength)).header('X-Stream-Output', '1') } } exports.put = {