diff --git a/package.json b/package.json index 2a3675d4..78cf262f 100644 --- a/package.json +++ b/package.json @@ -144,6 +144,10 @@ "import": "./src/traversal.js" } }, + "browser": { + "./hashes/sha2": "./src/hashes/sha2-browser.js", + "./src/hashes/sha2.js": "./src/hashes/sha2-browser.js" + }, "eslintConfig": { "extends": "ipfs", "parserOptions": { @@ -244,7 +248,6 @@ "test:browser": "aegir test --target browser" }, "devDependencies": { - "@ipld/dag-pb": "^2.1.14", "@stablelib/sha256": "^1.0.1", "@stablelib/sha512": "^1.0.1", "@types/chai": "^4.3.0", diff --git a/test/test-block.spec.js b/test/test-block.spec.js index 8f6d6fa9..8b1dbe43 100644 --- a/test/test-block.spec.js +++ b/test/test-block.spec.js @@ -1,8 +1,8 @@ /* globals describe, it */ -import * as codec from 'multiformats/codecs/json' -import { sha256 as hasher } from 'multiformats/hashes/sha2' -import * as main from 'multiformats/block' -import { CID, bytes } from 'multiformats' +import * as codec from '../src/codecs/json.js' +import { sha256 as hasher } from '../src/hashes/sha2.js' +import * as main from '../src/block.js' +import { CID, bytes } from '../src/index.js' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' diff --git a/test/test-bytes.spec.js b/test/test-bytes.spec.js index c420fa9b..a764ded6 100644 --- a/test/test-bytes.spec.js +++ b/test/test-bytes.spec.js @@ -1,5 +1,5 @@ /* globals describe, it */ -import * as bytes from 'multiformats/bytes' +import * as bytes from '../src/bytes.js' import { assert } from 'chai' describe('bytes', () => { diff --git a/test/test-cid.spec.js b/test/test-cid.spec.js index d35d8209..d819618f 100644 --- a/test/test-cid.spec.js +++ b/test/test-cid.spec.js @@ -1,13 +1,13 @@ /* globals describe, it */ -import OLDCID from 'cids' -import { fromHex, toHex, equals } from 'multiformats/bytes' -import { varint, CID } from 'multiformats' -import { base58btc } from 'multiformats/bases/base58' -import { base32 } from 'multiformats/bases/base32' -import { base64 } from 'multiformats/bases/base64' -import { sha256, sha512 } from 'multiformats/hashes/sha2' +import { fromHex, toHex, equals } from '../src/bytes.js' +import { varint, CID } from '../src/index.js' +import { base58btc } from '../src/bases/base58.js' +import { base32 } from '../src/bases/base32.js' +import { base64 } from '../src/bases/base64.js' +import { sha256, sha512 } from '../src/hashes/sha2.js' import invalidMultihash from './fixtures/invalid-multihash.js' +import OLDCID from 'cids' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' // Linter can see that API is used in types. diff --git a/test/test-link.spec.js b/test/test-link.spec.js index bb555526..7dba3798 100644 --- a/test/test-link.spec.js +++ b/test/test-link.spec.js @@ -1,10 +1,10 @@ /* globals describe, it */ -import * as Link from 'multiformats/link' -import { CID } from 'multiformats' +import * as Link from '../src/link.js' +import { CID } from '../src/cid.js' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' -import { sha256 } from 'multiformats/hashes/sha2' +import { sha256 } from '../src/hashes/sha2.js' chai.use(chaiAsPromised) const { assert } = chai diff --git a/test/test-multibase-spec.spec.js b/test/test-multibase-spec.spec.js index 619d78e7..aa060f76 100644 --- a/test/test-multibase-spec.spec.js +++ b/test/test-multibase-spec.spec.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ -import { bases } from 'multiformats/basics' -import { fromString } from 'multiformats/bytes' +import { bases } from '../src/basics.js' +import { fromString } from '../src/bytes.js' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' diff --git a/test/test-multibase.spec.js b/test/test-multibase.spec.js index 1c63ce1c..fa5a685a 100644 --- a/test/test-multibase.spec.js +++ b/test/test-multibase.spec.js @@ -1,13 +1,13 @@ /* globals describe, it */ -import * as bytes from 'multiformats/bytes' -import * as b2 from 'multiformats/bases/base2' -import * as b8 from 'multiformats/bases/base8' -import * as b10 from 'multiformats/bases/base10' -import * as b16 from 'multiformats/bases/base16' -import * as b32 from 'multiformats/bases/base32' -import * as b36 from 'multiformats/bases/base36' -import * as b58 from 'multiformats/bases/base58' -import * as b64 from 'multiformats/bases/base64' +import * as bytes from '../src/bytes.js' +import * as b2 from '../src/bases/base2.js' +import * as b8 from '../src/bases/base8.js' +import * as b10 from '../src/bases/base10.js' +import * as b16 from '../src/bases/base16.js' +import * as b32 from '../src/bases/base32.js' +import * as b36 from '../src/bases/base36.js' +import * as b58 from '../src/bases/base58.js' +import * as b64 from '../src/bases/base64.js' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' diff --git a/test/test-multicodec.spec.js b/test/test-multicodec.spec.js index ee449de8..831c72f7 100644 --- a/test/test-multicodec.spec.js +++ b/test/test-multicodec.spec.js @@ -1,7 +1,7 @@ /* globals describe, it */ -import * as bytes from 'multiformats/bytes' -import * as raw from 'multiformats/codecs/raw' -import * as json from 'multiformats/codecs/json' +import * as bytes from '../src/bytes.js' +import * as raw from '../src/codecs/raw.js' +import * as json from '../src/codecs/json.js' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' diff --git a/test/test-multihash.spec.js b/test/test-multihash.spec.js index 85d48245..857fbe10 100644 --- a/test/test-multihash.spec.js +++ b/test/test-multihash.spec.js @@ -1,12 +1,12 @@ /* globals describe, it */ -import { fromHex, fromString } from 'multiformats/bytes' -import { hash as slSha256 } from '@stablelib/sha256' -import { hash as slSha512 } from '@stablelib/sha512' +import { fromHex, fromString } from '../src/bytes.js' +import { sha256, sha512 } from '../src/hashes/sha2.js' +import { identity } from '../src/hashes/identity.js' +import { decode as decodeDigest, create as createDigest } from '../src/hashes/digest.js' import valid from './fixtures/valid-multihash.js' import invalid from './fixtures/invalid-multihash.js' -import { sha256, sha512 } from 'multiformats/hashes/sha2' -import { identity } from 'multiformats/hashes/identity' -import { decode as decodeDigest, create as createDigest } from 'multiformats/hashes/digest' +import { hash as slSha256 } from '@stablelib/sha256' +import { hash as slSha512 } from '@stablelib/sha512' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' diff --git a/test/test-traversal.spec.js b/test/test-traversal.spec.js index dc411a01..62f9c2bd 100644 --- a/test/test-traversal.spec.js +++ b/test/test-traversal.spec.js @@ -1,13 +1,32 @@ /* globals describe, it */ -import * as codec from 'multiformats/codecs/json' -import * as dagPB from '@ipld/dag-pb' -import { sha256 as hasher } from 'multiformats/hashes/sha2' -import * as main from 'multiformats/block' -import { walk } from 'multiformats/traversal' +import * as codec from '../src/codecs/json.js' +import { sha256 as hasher } from '../src/hashes/sha2.js' +import * as main from '../src/block.js' +import { walk } from '../src/traversal.js' +import { fromString } from '../src/bytes.js' import { assert } from 'chai' -import { fromString } from 'multiformats/bytes' -const { createLink, createNode } = dagPB +/** @typedef {import('../src/cid.js').CID} CID */ + +// from dag-pb, simplified +/** + * @param {Uint8Array} data + * @param {{Hash:CID, Name:string, Tsize:number}[]} links + * @returns {{Data:Uint8Array, Links:{Hash:CID, Name:string, Tsize:number}[]}} + */ +function createNode (data, links) { + return { Data: data, Links: links } +} + +/** + * @param {string} name + * @param {number} size + * @param {CID} cid + * @returns {{Hash:CID, Name:string, Tsize:number}} + */ +function createLink (name, size, cid) { + return { Hash: cid, Name: name, Tsize: size } +} describe('traversal', () => { describe('walk', async () => { @@ -43,7 +62,7 @@ describe('traversal', () => { const cidA = blockA.cid /** - * @param {import('multiformats').CID} cid + * @param {CID} cid */ const load = async (cid) => { if (cid.equals(cidE)) { @@ -70,7 +89,7 @@ describe('traversal', () => { */ const loadWrapper = (load, arr = []) => /** - * @param {import('multiformats').CID} cid + * @param {CID} cid */ (cid) => { arr.push(cid.toString())