Socket
Socket
Sign inDemoInstall

multiformats

Package Overview
Dependencies
Maintainers
1
Versions
150
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multiformats - npm Package Compare versions

Comparing version 2.0.1 to 2.1.0

coverage/tmp/coverage-3726-1595132602370-0.json

9

cid.js

@@ -30,3 +30,3 @@ import * as bytes from 'multiformats/bytes.js'

doSomethingWithCID(value)
}
}

@@ -104,2 +104,9 @@ Is replaced with:

;[code, cid] = parse(cid)
if (code === 18) {
// CIDv0
readonly(this, 'version', 0)
readonly(this, 'code', 0x70)
this._multihash = this.buffer
return
}
if (code > 1) throw new Error(`Invalid CID version ${code}`)

@@ -106,0 +113,0 @@ readonly(this, 'version', code)

2

package.json
{
"name": "multiformats",
"version": "2.0.1",
"version": "2.1.0",
"description": "Interface for multihash, multicodec, multibase and CID.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,2 +0,2 @@

/* globals before, describe, it */
/* globals describe, it */
import crypto from 'crypto'

@@ -51,8 +51,3 @@ import OLDCID from 'cids'

const b58 = multibase.get('base58btc')
let hash
before(async () => {
hash = await multihash.hash(Buffer.from('abc'), 'sha2-256')
})
describe('v0', () => {

@@ -70,3 +65,4 @@ test('handles B58Str multihash', () => {

test('create by parts', () => {
test('create by parts', async () => {
const hash = await multihash.hash(Buffer.from('abc'), 'sha2-256')
const cid = new CID(0, 112, hash)

@@ -81,3 +77,14 @@

test('throws on invalid BS58Str multihash ', () => {
test('create from multihash', async () => {
const hash = await multihash.hash(Buffer.from('abc'), 'sha2-256')
const cid = new CID(hash)
same(cid.code, 112)
same(cid.version, 0)
same(cid.multihash, hash)
cid.toString()
same(cid.toString(), b58.encode(hash))
})
test('throws on invalid BS58Str multihash ', async () => {
const msg = 'Non-base58 character'

@@ -87,3 +94,4 @@ testThrow(() => new CID('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zIII'), msg)

test('throws on trying to create a CIDv0 with a codec other than dag-pb', () => {
test('throws on trying to create a CIDv0 with a codec other than dag-pb', async () => {
const hash = await multihash.hash(Buffer.from('abc'), 'sha2-256')
const msg = 'Version 0 CID must be 112 codec (dag-cbor)'

@@ -93,3 +101,4 @@ testThrow(() => new CID(0, 113, hash), msg)

test('throws on trying to pass specific base encoding [deprecated]', () => {
test('throws on trying to pass specific base encoding [deprecated]', async () => {
const hash = await multihash.hash(Buffer.from('abc'), 'sha2-256')
const msg = 'No longer supported, cannot specify base encoding in instantiation'

@@ -106,3 +115,4 @@ testThrow(() => new CID(0, 112, hash, 'base32'), msg)

test('.buffer', () => {
test('.buffer', async () => {
const hash = await multihash.hash(Buffer.from('abc'), 'sha2-256')
const codec = 112

@@ -143,3 +153,4 @@ const cid = new CID(0, codec, hash)

test('create by parts', () => {
test('create by parts', async () => {
const hash = await multihash.hash(Buffer.from('abc'), 'sha2-256')
const cid = new CID(1, 0x71, hash)

@@ -151,3 +162,4 @@ same(cid.code, 0x71)

test('can roundtrip through cid.toString()', () => {
test('can roundtrip through cid.toString()', async () => {
const hash = await multihash.hash(Buffer.from('abc'), 'sha2-256')
const cid1 = new CID(1, 0x71, hash)

@@ -178,3 +190,4 @@ const cid2 = new CID(cid1.toString())

test('.buffer', () => {
test('.buffer', async () => {
const hash = await multihash.hash(Buffer.from('abc'), 'sha2-256')
const code = 0x71

@@ -260,9 +273,2 @@ const cid = new CID(1, code, hash)

invalid.forEach(mapper)
const invalidVersions = [-1, 2]
mapper = i => {
const name = `new CID(${i}, 112, buffer)`
test(name, () => testThrowAny(new CID(i, 112, hash)))
}
invalidVersions.forEach(mapper)
})

@@ -314,3 +320,4 @@

})
test('should cache string representation when it matches the multibaseName it was constructed with', () => {
test('should cache string representation when it matches the multibaseName it was constructed with', async () => {
const hash = await multihash.hash(Buffer.from('abc'), 'sha2-256')
const cid = new CID(1, 112, hash)

@@ -337,3 +344,4 @@ same(cid._baseCache.size, 0)

test('toJSON()', () => {
test('toJSON()', async () => {
const hash = await multihash.hash(Buffer.from('abc'), 'sha2-256')
const cid = new CID(1, 112, hash)

@@ -343,3 +351,4 @@ same(cid.toJSON(), { code: 112, version: 1, hash })

test('isCID', () => {
test('isCID', async () => {
const hash = await multihash.hash(Buffer.from('abc'), 'sha2-256')
const cid = new CID(1, 112, hash)

@@ -349,3 +358,4 @@ assert.ok(OLDCID.isCID(cid))

test('asCID', () => {
test('asCID', async () => {
const hash = await multihash.hash(Buffer.from('abc'), 'sha2-256')
class IncompatibleCID {

@@ -366,5 +376,5 @@ constructor (version, code, multihash) {

const code = 112
const multihash = hash
const _multihash = hash
const incompatibleCID = new IncompatibleCID(version, code, multihash)
const incompatibleCID = new IncompatibleCID(version, code, _multihash)
assert.ok(CID.isCID(incompatibleCID))

@@ -378,8 +388,8 @@ assert.strictEqual(incompatibleCID.toString(), '[object Object]')

assert.strictEqual(cid1.version, version)
assert.strictEqual(cid1.multihash, multihash)
assert.strictEqual(cid1.multihash, _multihash)
const cid2 = CID.asCID({ version, code, multihash })
const cid2 = CID.asCID({ version, code, _multihash })
assert.strictEqual(cid2, null)
const duckCID = { version, code, multihash }
const duckCID = { version, code, multihash: _multihash }
duckCID.asCID = duckCID

@@ -390,3 +400,3 @@ const cid3 = CID.asCID(duckCID)

assert.strictEqual(cid3.version, version)
assert.strictEqual(cid3.multihash, multihash)
assert.strictEqual(cid3.multihash, _multihash)

@@ -403,3 +413,4 @@ const cid4 = CID.asCID(cid3)

test('new CID from old CID', () => {
test('new CID from old CID', async () => {
const hash = await multihash.hash(Buffer.from('abc'), 'sha2-256')
const cid = new CID(new OLDCID(1, 'raw', Buffer.from(hash)))

@@ -412,3 +423,4 @@ same(cid.version, 1)

if (!process.browser) {
test('util.inspect', () => {
test('util.inspect', async () => {
const hash = await multihash.hash(Buffer.from('abc'), 'sha2-256')
const cid = new CID(1, 112, hash)

@@ -419,4 +431,5 @@ same(util.inspect(cid), 'CID(bafybeif2pall7dybz7vecqka3zo24irdwabwdi4wc55jznaq75q7eaavvu)')

describe('deprecations', () => {
describe('deprecations', async () => {
test('codec', async () => {
const hash = await multihash.hash(Buffer.from('abc'), 'sha2-256')
const cid = new CID(1, 112, hash)

@@ -427,2 +440,3 @@ await testThrow(() => cid.codec, '"codec" property is deprecated, use integer "code" property instead')

test('multibaseName', async () => {
const hash = await multihash.hash(Buffer.from('abc'), 'sha2-256')
const cid = new CID(1, 112, hash)

@@ -432,2 +446,3 @@ await testThrow(() => cid.multibaseName, '"multibaseName" property is deprecated')

test('prefix', async () => {
const hash = await multihash.hash(Buffer.from('abc'), 'sha2-256')
const cid = new CID(1, 112, hash)

@@ -437,2 +452,3 @@ await testThrow(() => cid.prefix, '"prefix" property is deprecated')

test('toBaseEncodedString()', async () => {
const hash = await multihash.hash(Buffer.from('abc'), 'sha2-256')
const cid = new CID(1, 112, hash)

@@ -444,5 +460,5 @@ await testThrow(() => cid.toBaseEncodedString(), 'Deprecated, use .toString()')

test('invalid CID version', async () => {
const encoded = varint.encode(18)
await testThrow(() => new CID(encoded), 'Invalid CID version 18')
const encoded = varint.encode(2)
await testThrow(() => new CID(encoded), 'Invalid CID version 2')
})
})

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc