diff --git a/package.json b/package.json index 413527a4..18549d1a 100644 --- a/package.json +++ b/package.json @@ -54,10 +54,12 @@ }, "dependencies": { "block-stream2": "^1.1.0", + "bs58": "^3.0.0", "debug": "^2.2.0", "field-trip": "0.0.2", "ipfs-merkle-dag": "^0.5.0", "ipfs-unixfs": "^0.1.0", + "is-ipfs": "^0.2.0", "isstream": "^0.1.2", "readable-stream": "^1.1.13", "run-series": "^1.1.4", diff --git a/src/exporter.js b/src/exporter.js index 239d2613..519079b6 100644 --- a/src/exporter.js +++ b/src/exporter.js @@ -3,6 +3,8 @@ const debug = require('debug') const log = debug('exporter') log.err = debug('exporter:error') +const isIPFS = require('is-ipfs') +const bs58 = require('bs58') const UnixFS = require('ipfs-unixfs') const series = require('run-series') const Readable = require('readable-stream').Readable @@ -19,6 +21,14 @@ function Exporter (hash, dagService, options) { return new Exporter(hash, dagService, options) } + // Sanitize hash. + if (!isIPFS.multihash(hash)) { + throw new Error('not valid multihash') + } + if (Buffer.isBuffer(hash)) { + hash = bs58.encode(hash) + } + Readable.call(this, { objectMode: true }) this.options = options || {}