diff --git a/src/index.js b/src/index.js index c060c12..f8a2465 100644 --- a/src/index.js +++ b/src/index.js @@ -85,7 +85,7 @@ exports.getNumber = (name) => { if (code === undefined) { throw new Error('Codec `' + name + '` not found') } - return util.varintUint8ArrayDecode(code)[0] + return varint.decode(code) } /** diff --git a/src/util.js b/src/util.js index bde8c0d..9ff77aa 100644 --- a/src/util.js +++ b/src/util.js @@ -8,7 +8,6 @@ module.exports = { numberToUint8Array, uint8ArrayToNumber, varintUint8ArrayEncode, - varintUint8ArrayDecode, varintEncode } @@ -28,10 +27,6 @@ function varintUint8ArrayEncode (input) { return Uint8Array.from(varint.encode(uint8ArrayToNumber(input))) } -function varintUint8ArrayDecode (input) { - return numberToUint8Array(varint.decode(input)) -} - function varintEncode (num) { return Uint8Array.from(varint.encode(num)) } diff --git a/test/multicodec.spec.js b/test/multicodec.spec.js index b45635b..857d2d4 100644 --- a/test/multicodec.spec.js +++ b/test/multicodec.spec.js @@ -4,6 +4,7 @@ const { expect } = require('aegir/utils/chai') const multicodec = require('../src') const uint8ArrayFromString = require('uint8arrays/from-string') +const baseTable = require('../src/base-table.json') describe('multicodec', () => { it('add prefix through multicodec (string)', () => { @@ -53,9 +54,13 @@ describe('multicodec', () => { it('returns the codec number from name', () => { expect(multicodec.getNumber('eth-block')).to.eql(144) expect(multicodec.getNumber('dag-pb')).to.eql(112) - // NOTE vmx 2019-09019: Uncomment once - // https://github.com/multiformats/js-multicodec/issues/50 is fixed - // expect(multicodec.getNumber('blake2b-8')).to.eql(0xb201) + expect(multicodec.getNumber('blake2b-8')).to.eql(0xb201) + }) + + it('returns all codec numbers from names', () => { + for (const name in baseTable) { + expect(multicodec.getNumber(name)).to.eql(baseTable[name]) + } }) it('returns the codec number from constant', () => {