From 3a6f7cc51c188d886a84478b2f8f25e36ae68684 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Thu, 31 Aug 2023 22:20:43 -0600 Subject: [PATCH 1/4] feat(blake3): :heavy_plus_sign: Adding blake3-multihash Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- package-lock.json | 6 ++++++ package.json | 1 + 2 files changed, 7 insertions(+) diff --git a/package-lock.json b/package-lock.json index f551207c..fdac4685 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "@libp2p/ipni-content-routing": "^1.0.1", "@loadable/component": "^5.14.1", "@tableflip/react-inspector": "^2.3.0", + "blake3-multihash": "^0.0.4", "cytoscape": "^3.18.1", "cytoscape-dagre": "^2.3.2", "filesize": "^6.1.0", @@ -11835,6 +11836,11 @@ "readable-stream": "^3.4.0" } }, + "node_modules/blake3-multihash": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/blake3-multihash/-/blake3-multihash-0.0.4.tgz", + "integrity": "sha512-J7zhBQ1GrO5is+CfzRw2O8FUlQ1ztdxzXbqYzYwhsHoO9klB9CYT5ajqH0w6t43UIUwBHAq/3CohKWms+9UKsA==" + }, "node_modules/blakejs": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/blakejs/-/blakejs-1.2.1.tgz", diff --git a/package.json b/package.json index 13fc001a..98aeff4a 100644 --- a/package.json +++ b/package.json @@ -130,6 +130,7 @@ "@libp2p/ipni-content-routing": "^1.0.1", "@loadable/component": "^5.14.1", "@tableflip/react-inspector": "^2.3.0", + "blake3-multihash": "^0.0.4", "cytoscape": "^3.18.1", "cytoscape-dagre": "^2.3.2", "filesize": "^6.1.0", From 23a5d5cdddf98a44bc45ecc70a108ecb6c974d78 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Thu, 31 Aug 2023 22:22:35 -0600 Subject: [PATCH 2/4] feat(blake3): :necktie: Adding blake3 hasher Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- src/lib/hash-importer.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/lib/hash-importer.ts b/src/lib/hash-importer.ts index 5f13a491..48a6e667 100644 --- a/src/lib/hash-importer.ts +++ b/src/lib/hash-importer.ts @@ -1,9 +1,15 @@ /* global globalThis */ +import { digest as blake3Digest } from 'blake3-multihash' import { keccak256 } from 'js-sha3' import { type Hasher, from } from 'multiformats/hashes/hasher' import * as sha2 from 'multiformats/hashes/sha2' -type SupportedHashers = typeof sha2.sha256 | typeof sha2.sha512 | Hasher<'keccak-256', 27> | Hasher<'sha1', 17> +type SupportedHashers = typeof sha2.sha256 + | typeof sha2.sha512 + | Hasher<'blake3-multihash', 30> + | Hasher<'keccak-256', 27> + | Hasher<'sha1', 17> + export default async function getHasherForCode (code: number): Promise { switch (code) { case sha2.sha256.code: @@ -15,7 +21,7 @@ export default async function getHasherForCode (code: number): Promise { + encode: async (data: Uint8Array): Promise => { const crypto = globalThis.crypto ?? (await import('crypto')).webcrypto const hashBuffer = await crypto.subtle.digest('SHA-1', data) return new Uint8Array(hashBuffer) @@ -25,10 +31,19 @@ export default async function getHasherForCode (code: number): Promise { + encode: async (data: Uint8Array): Promise => { return new Uint8Array(keccak256.arrayBuffer(data)) } }) + case 30: // blake3-multihash + return from({ + name: 'blake3-multihash', + code, + encode: async (data: Uint8Array): Promise => { + const { digest } = await blake3Digest(data) + return digest + } + }) default: throw new Error(`unknown multihasher code '${code}'`) From 81ad51bcd032042f53a8f895d72611961391ced2 Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Sun, 29 Oct 2023 22:10:27 -0600 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=E2=99=BB=EF=B8=8F=20Addressing=20co?= =?UTF-8?q?mments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- src/lib/hash-importer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/hash-importer.ts b/src/lib/hash-importer.ts index 48a6e667..825d55da 100644 --- a/src/lib/hash-importer.ts +++ b/src/lib/hash-importer.ts @@ -1,5 +1,4 @@ /* global globalThis */ -import { digest as blake3Digest } from 'blake3-multihash' import { keccak256 } from 'js-sha3' import { type Hasher, from } from 'multiformats/hashes/hasher' import * as sha2 from 'multiformats/hashes/sha2' @@ -40,6 +39,7 @@ export default async function getHasherForCode (code: number): Promise => { + const { digest: blake3Digest } = await import('blake3-multihash') const { digest } = await blake3Digest(data) return digest } From 4e946f0be1092ea7bfa1446839c0d53a9149774d Mon Sep 17 00:00:00 2001 From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> Date: Sun, 29 Oct 2023 22:14:20 -0600 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20=F0=9F=94=80=20Marking=20dep=20as=20?= =?UTF-8?q?peerDep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com> --- package-lock.json | 5 +++-- package.json | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index fdac4685..4113af06 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,6 @@ "@libp2p/ipni-content-routing": "^1.0.1", "@loadable/component": "^5.14.1", "@tableflip/react-inspector": "^2.3.0", - "blake3-multihash": "^0.0.4", "cytoscape": "^3.18.1", "cytoscape-dagre": "^2.3.2", "filesize": "^6.1.0", @@ -146,6 +145,7 @@ }, "peerDependencies": { "@loadable/component": "^5.14.1", + "blake3-multihash": "^0.0.4", "i18next": "^21.6.16", "i18next-browser-languagedetector": "^6.1.0", "i18next-http-backend": "^1.2.1", @@ -11839,7 +11839,8 @@ "node_modules/blake3-multihash": { "version": "0.0.4", "resolved": "https://registry.npmjs.org/blake3-multihash/-/blake3-multihash-0.0.4.tgz", - "integrity": "sha512-J7zhBQ1GrO5is+CfzRw2O8FUlQ1ztdxzXbqYzYwhsHoO9klB9CYT5ajqH0w6t43UIUwBHAq/3CohKWms+9UKsA==" + "integrity": "sha512-J7zhBQ1GrO5is+CfzRw2O8FUlQ1ztdxzXbqYzYwhsHoO9klB9CYT5ajqH0w6t43UIUwBHAq/3CohKWms+9UKsA==", + "peer": true }, "node_modules/blakejs": { "version": "1.2.1", diff --git a/package.json b/package.json index 98aeff4a..59c9ba45 100644 --- a/package.json +++ b/package.json @@ -130,7 +130,6 @@ "@libp2p/ipni-content-routing": "^1.0.1", "@loadable/component": "^5.14.1", "@tableflip/react-inspector": "^2.3.0", - "blake3-multihash": "^0.0.4", "cytoscape": "^3.18.1", "cytoscape-dagre": "^2.3.2", "filesize": "^6.1.0", @@ -251,6 +250,7 @@ }, "peerDependencies": { "@loadable/component": "^5.14.1", + "blake3-multihash": "^0.0.4", "i18next": "^21.6.16", "i18next-browser-languagedetector": "^6.1.0", "i18next-http-backend": "^1.2.1",