From 5a37a5eb4fc9c806a82740c5ba93f018eaf2b043 Mon Sep 17 00:00:00 2001
From: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Date: Wed, 29 Nov 2023 21:06:51 -0700
Subject: [PATCH] fix(hasher): Introducing Blake3-multihash (#395)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* feat(blake3): :heavy_plus_sign: Adding blake3-multihash
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
* feat(blake3): :necktie: Adding blake3 hasher
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
* fix: ♻️ Addressing comments
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
* fix: 🔀 Marking dep as peerDep
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
---------
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
---
README.md | 24 +++++++++++++++++++-----
package.json | 1 +
src/components/StartExploringPage.jsx | 6 ++++++
src/lib/codec-importer.ts | 1 +
src/lib/get-codec-for-cid.ts | 1 +
src/lib/get-codec-name-from-code.ts | 1 +
src/lib/hash-importer.ts | 17 ++++++++++++++---
src/lib/init-helia.ts | 7 +++++--
src/lib/resolve-ipld-path.test.js | 1 +
9 files changed, 49 insertions(+), 10 deletions(-)
diff --git a/README.md b/README.md
index 7444a746..0dd672b7 100644
--- a/README.md
+++ b/README.md
@@ -60,15 +60,29 @@ import 'ipld-explorer-components/dist/components/loader/Loader.css'
**NOTE:** PRs adding an old IPLDFormat codec would need the old `blockcodec-to-ipld-format` tool which has many out of date deps. We will only accept PRs for adding BlockCodec interface codecs.
-To add another codec you will need to:
+To add another codec you will need to update all locations containing the comment `// #WhenAddingNewCodec`:
-1. Add a dependency on the codec to this package
-1. Add the codec in the switch statement in src/lib/codec-importer.ts
-1. Add a unit test to src/lib/resolve-ipld-path.test.js and ensure that calling `resolveIpldPath` returns the expected results
- * If the default `resolveFn` in src/lib/get-codec-for-cid.ts doesn't resolve your paths correctly, you will need to add a resolver method for your codec to the `codecResolverMap` in src/lib/get-codec-for-cid.ts
+1. Add a dependency on the codec to this package (if it's not already in multiformats or other package)
+1. Add the codec in the switch statement in [./src/lib/codec-importer.ts](./src/lib/codec-importer.ts)
+1. Update [./src/lib/get-codec-name-from-code.ts](./src/lib/get-codec-name-from-code.ts) to return the codec name for your codec
+1. Add a unit test to [./src/lib/resolve-ipld-path.test.js](./src/lib/resolve-ipld-path.test.js) and ensure that calling `resolveIpldPath` returns the expected results
+ * If the default `resolveFn` in [./src/lib/get-codec-for-cid.ts](./src/lib/get-codec-for-cid.ts) doesn't resolve your paths correctly, you will need to add a resolver method for your codec to the `codecResolverMap` in [./src/lib/get-codec-for-cid.ts](./src/lib/get-codec-for-cid.ts)
see https://github.com/ipfs/ipld-explorer-components/pull/360#discussion_r1206251817 for history.
+### Adding another hasher
+
+To add another hasher you will need to update all locations containing the comment `// #WhenAddingNewHasher`:
+
+1. Add a dependency on the hasher to this package (if it's not already in multiformats or other package)
+1. Add the hasher in the switch statement in [./src/lib/get-codec-for-cid.ts](./src/lib/get-codec-for-cid.ts)
+1. Update [./src/lib/hash-importer.ts](./src/lib/hash-importer.ts)
+ - Update `SupportedHashers` to include your hasher type
+ - Update `getHasherForCode` to return your hasher
+1. Update the hasher codes used by the `hashers` property passed to Helia init in [./src/lib/init-helia.ts](./src/lib/init-helia.ts)
+
+see https://github.com/ipfs/ipld-explorer-components/pull/395 for an example.
+
### Redux-bundler requirements
These components use [redux-bundler](https://reduxbundler.com/) and your app will need to use a redux-bundler provider in order to propogate the properties and selectors. You can find a basic example of this in ./dev/devPage.jsx.
diff --git a/package.json b/package.json
index 1ce9f5af..f6a8ced2 100644
--- a/package.json
+++ b/package.json
@@ -248,6 +248,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",
diff --git a/src/components/StartExploringPage.jsx b/src/components/StartExploringPage.jsx
index 49497443..a05609b9 100644
--- a/src/components/StartExploringPage.jsx
+++ b/src/components/StartExploringPage.jsx
@@ -59,6 +59,9 @@ const StartExploringPage = ({ t, embed, runTour = false, joyrideCallback }) => (
*/}