From 1363762d9fdf6ff75a71c5dab22f668e7958bf7a Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Tue, 10 Sep 2024 11:58:58 -0500 Subject: [PATCH 1/6] tmp: testing dynamic import --- package-lock.json | 4 ++-- package.json | 2 +- src/lib/hash-importer.ts | 5 ++++- src/lib/init-helia.ts | 7 +++++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3c443d5d..42d7f345 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ipld-explorer-components", - "version": "7.0.1", + "version": "7.0.2-rc1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ipld-explorer-components", - "version": "7.0.1", + "version": "7.0.2-rc1", "license": "Apache-2.0 OR MIT", "dependencies": { "@helia/block-brokers": "^3.0.3", diff --git a/package.json b/package.json index be30c1d7..427e3a1d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipld-explorer-components", - "version": "7.0.1", + "version": "7.0.2-rc1", "description": "React components for https://explore.ipld.io", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/ipfs/ipld-explorer-components#readme", diff --git a/src/lib/hash-importer.ts b/src/lib/hash-importer.ts index 232fed5a..fd20a130 100644 --- a/src/lib/hash-importer.ts +++ b/src/lib/hash-importer.ts @@ -1,6 +1,6 @@ /* global globalThis */ import * as sha3 from '@multiformats/sha3' -import { createBLAKE3, createBLAKE2b } from 'hash-wasm' +// import { createBLAKE3, createBLAKE2b } from 'hash-wasm' import { type Hasher, from } from 'multiformats/hashes/hasher' import * as sha2 from 'multiformats/hashes/sha2' @@ -56,6 +56,7 @@ export async function getHasherForCode (code: number): Promise name: 'blake3', code, encode: async (data: Uint8Array): Promise => { + const { createBLAKE3 } = await import('hash-wasm') const blake3Hasher = await createBLAKE3() blake3Hasher.init() blake3Hasher.update(data) @@ -67,6 +68,7 @@ export async function getHasherForCode (code: number): Promise name: 'blake2b-256', code, encode: async (data: Uint8Array): Promise => { + const { createBLAKE2b } = await import('hash-wasm') const blake2bHasher = await createBLAKE2b(256) blake2bHasher.init() blake2bHasher.update(data) @@ -78,6 +80,7 @@ export async function getHasherForCode (code: number): Promise name: 'blake2b-512', code, encode: async (data: Uint8Array): Promise => { + const { createBLAKE2b } = await import('hash-wasm') const blake2bHasher = await createBLAKE2b(512) blake2bHasher.init() blake2bHasher.update(data) diff --git a/src/lib/init-helia.ts b/src/lib/init-helia.ts index 2078b493..f4377d5b 100644 --- a/src/lib/init-helia.ts +++ b/src/lib/init-helia.ts @@ -40,14 +40,17 @@ export default async function initHelia (kuboGatewayOptions: KuboGatewayOptions) // add helia-only examples // consumers may not have the peer-deps installed for these examples, and we don't want to break them if they're not supported. - await Promise.allSettled([ + const foo = await Promise.allSettled([ addDagNodeToHelia(helia, 'dag-json', { hello: 'world' }), // baguqeerasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea addDagNodeToHelia(helia, 'dag-cbor', { hello: 'world' }, 27), // bafyrwigbexamue2ba3hmtai7hwlcmd6ekiqsduyf5avv7oz6ln3radvjde addDagNodeToHelia(helia, 'json', { hello: 'world' }, 20), // bagaaifcavabu6fzheerrmtxbbwv7jjhc3kaldmm7lbnvfopyrthcvod4m6ygpj3unrcggkzhvcwv5wnhc5ufkgzlsji7agnmofovc2g4a3ui7ja addDagNodeToHelia(helia, 'json', { hello: 'world' }, 30), // bagaaihraf4oq2kddg6o5ewlu6aol6xab75xkwbgzx2dlot7cdun7iirve23a addDagNodeToHelia(helia, 'raw', (new TextEncoder()).encode('hello'), 30), // bafkr4ihkr4ld3m4gqkjf4reryxsy2s5tkbxprqkow6fin2iiyvreuzzab4 - addDagNodeToHelia(helia, 'dag-pb', { Data: (new TextEncoder()).encode('hello'), Links: [] }, 0xb220) // bafykbzacec3ssfzln7bfcn54t5voa4onlcx63kkx3reucaiwc7eaffmla7gci + addDagNodeToHelia(helia, 'dag-pb', { Data: (new TextEncoder()).encode('hello'), Links: [] }, 0xb220), // bafykbzacec3ssfzln7bfcn54t5voa4onlcx63kkx3reucaiwc7eaffmla7gci + addDagNodeToHelia(helia, 'dag-pb', { Data: (new TextEncoder()).encode('hello'), Links: [] }, 0xb240) // bafymbzacia5oqpl3kqdjk6hgisdemv44omuqse33bf3a2gnurnzcmkstjhupcqymbuvsj2qlke4phr5iudjruwbjqsx34psaqsuezr4ivka5ul2y ]) + // eslint-disable-next-line no-console + console.log(foo) return helia } From 6fad7267a0550639a0f5a8c2e5151b957fb269b6 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Tue, 10 Sep 2024 12:39:14 -0500 Subject: [PATCH 2/6] chore: temporarily disable delegated routing --- src/lib/init-helia.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/init-helia.ts b/src/lib/init-helia.ts index f4377d5b..20d9f7f0 100644 --- a/src/lib/init-helia.ts +++ b/src/lib/init-helia.ts @@ -1,7 +1,8 @@ import { trustlessGateway } from '@helia/block-brokers' import { createHeliaHTTP } from '@helia/http' import { type Helia } from '@helia/interface' -import { delegatedHTTPRouting, httpGatewayRouting } from '@helia/routers' +// import { delegatedHTTPRouting, httpGatewayRouting } from '@helia/routers' +import { httpGatewayRouting } from '@helia/routers' import { addDagNodeToHelia } from '../lib/helpers.js' import { getHashersForCodes } from './hash-importer.js' import type { KuboGatewayOptions } from '../types.d.js' @@ -19,7 +20,7 @@ function areRemoteGatewaysEnabled (): boolean { export default async function initHelia (kuboGatewayOptions: KuboGatewayOptions): Promise { const routers = [ // always use delegated routing - delegatedHTTPRouting('http://delegated-ipfs.dev'), + // delegatedHTTPRouting('http://delegated-ipfs.dev'), // Always add the Kubo gatewawy httpGatewayRouting({ gateways: [`${kuboGatewayOptions.protocol ?? 'http'}://${kuboGatewayOptions.host}:${kuboGatewayOptions.port}`] }) ] From 9af8db649cf364dacb40ecbae0b488625a6dbea8 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Wed, 11 Sep 2024 09:46:04 -0500 Subject: [PATCH 3/6] fix: getHashersForCodes handles errors gracefully --- src/lib/hash-importer.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib/hash-importer.ts b/src/lib/hash-importer.ts index fd20a130..2f6de57e 100644 --- a/src/lib/hash-importer.ts +++ b/src/lib/hash-importer.ts @@ -15,7 +15,15 @@ export type SupportedHashers = typeof sha2.sha256 | Hasher<'blake3', 30> export async function getHashersForCodes (...codes: number[]): Promise { - return Promise.all(codes.map(getHasherForCode)) + const hashers: SupportedHashers[] = [] + for (const code of codes) { + try { + hashers.push(await getHasherForCode(code)) + } catch (error) { + console.error(`Failed to get hasher for code ${code}: ${error}`) + } + } + return hashers } /** From ca08ea50f5b516a0cf2bb904b2dc8a30c65e0ea4 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:33:21 -0500 Subject: [PATCH 4/6] fix: revert version, other minor changes --- package-lock.json | 3 ++- package.json | 2 +- src/lib/hash-importer.ts | 1 - src/lib/init-helia.ts | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 42d7f345..8f9ab77a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26090,7 +26090,8 @@ "node_modules/hash-wasm": { "version": "4.11.0", "resolved": "https://registry.npmjs.org/hash-wasm/-/hash-wasm-4.11.0.tgz", - "integrity": "sha512-HVusNXlVqHe0fzIzdQOGolnFN6mX/fqcrSAOcTBXdvzrXVHwTz11vXeKRmkR5gTuwVpvHZEIyKoePDvuAR+XwQ==" + "integrity": "sha512-HVusNXlVqHe0fzIzdQOGolnFN6mX/fqcrSAOcTBXdvzrXVHwTz11vXeKRmkR5gTuwVpvHZEIyKoePDvuAR+XwQ==", + "license": "MIT" }, "node_modules/hasha": { "version": "5.2.2", diff --git a/package.json b/package.json index 427e3a1d..be30c1d7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipld-explorer-components", - "version": "7.0.2-rc1", + "version": "7.0.1", "description": "React components for https://explore.ipld.io", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/ipfs/ipld-explorer-components#readme", diff --git a/src/lib/hash-importer.ts b/src/lib/hash-importer.ts index 2f6de57e..23059164 100644 --- a/src/lib/hash-importer.ts +++ b/src/lib/hash-importer.ts @@ -1,6 +1,5 @@ /* global globalThis */ import * as sha3 from '@multiformats/sha3' -// import { createBLAKE3, createBLAKE2b } from 'hash-wasm' import { type Hasher, from } from 'multiformats/hashes/hasher' import * as sha2 from 'multiformats/hashes/sha2' diff --git a/src/lib/init-helia.ts b/src/lib/init-helia.ts index 20d9f7f0..c450f0c3 100644 --- a/src/lib/init-helia.ts +++ b/src/lib/init-helia.ts @@ -1,8 +1,7 @@ import { trustlessGateway } from '@helia/block-brokers' import { createHeliaHTTP } from '@helia/http' import { type Helia } from '@helia/interface' -// import { delegatedHTTPRouting, httpGatewayRouting } from '@helia/routers' -import { httpGatewayRouting } from '@helia/routers' +import { delegatedHTTPRouting, httpGatewayRouting } from '@helia/routers' import { addDagNodeToHelia } from '../lib/helpers.js' import { getHashersForCodes } from './hash-importer.js' import type { KuboGatewayOptions } from '../types.d.js' @@ -26,6 +25,9 @@ export default async function initHelia (kuboGatewayOptions: KuboGatewayOptions) ] if (areRemoteGatewaysEnabled()) { + // eslint-disable-next-line no-console + console.log('remote gateways are enabled') + routers.push(delegatedHTTPRouting('http://delegated-ipfs.dev')) routers.push(httpGatewayRouting()) } @@ -41,7 +43,7 @@ export default async function initHelia (kuboGatewayOptions: KuboGatewayOptions) // add helia-only examples // consumers may not have the peer-deps installed for these examples, and we don't want to break them if they're not supported. - const foo = await Promise.allSettled([ + await Promise.allSettled([ addDagNodeToHelia(helia, 'dag-json', { hello: 'world' }), // baguqeerasords4njcts6vs7qvdjfcvgnume4hqohf65zsfguprqphs3icwea addDagNodeToHelia(helia, 'dag-cbor', { hello: 'world' }, 27), // bafyrwigbexamue2ba3hmtai7hwlcmd6ekiqsduyf5avv7oz6ln3radvjde addDagNodeToHelia(helia, 'json', { hello: 'world' }, 20), // bagaaifcavabu6fzheerrmtxbbwv7jjhc3kaldmm7lbnvfopyrthcvod4m6ygpj3unrcggkzhvcwv5wnhc5ufkgzlsji7agnmofovc2g4a3ui7ja @@ -50,8 +52,6 @@ export default async function initHelia (kuboGatewayOptions: KuboGatewayOptions) addDagNodeToHelia(helia, 'dag-pb', { Data: (new TextEncoder()).encode('hello'), Links: [] }, 0xb220), // bafykbzacec3ssfzln7bfcn54t5voa4onlcx63kkx3reucaiwc7eaffmla7gci addDagNodeToHelia(helia, 'dag-pb', { Data: (new TextEncoder()).encode('hello'), Links: [] }, 0xb240) // bafymbzacia5oqpl3kqdjk6hgisdemv44omuqse33bf3a2gnurnzcmkstjhupcqymbuvsj2qlke4phr5iudjruwbjqsx34psaqsuezr4ivka5ul2y ]) - // eslint-disable-next-line no-console - console.log(foo) return helia } From cbab34c4a947358ca7008988ddfee73be4408f55 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Wed, 11 Sep 2024 09:38:10 -0700 Subject: [PATCH 5/6] chore: log update --- src/lib/init-helia.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/init-helia.ts b/src/lib/init-helia.ts index c450f0c3..17a5db1a 100644 --- a/src/lib/init-helia.ts +++ b/src/lib/init-helia.ts @@ -26,7 +26,7 @@ export default async function initHelia (kuboGatewayOptions: KuboGatewayOptions) if (areRemoteGatewaysEnabled()) { // eslint-disable-next-line no-console - console.log('remote gateways are enabled') + console.log('remote gateways and delegated routing are enabled') routers.push(delegatedHTTPRouting('http://delegated-ipfs.dev')) routers.push(httpGatewayRouting()) } From 94d28875eeffd90e12024de7742c2463463e69ea Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:39:39 -0500 Subject: [PATCH 6/6] chore: address PR comments --- src/lib/init-helia.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lib/init-helia.ts b/src/lib/init-helia.ts index 17a5db1a..84e3689d 100644 --- a/src/lib/init-helia.ts +++ b/src/lib/init-helia.ts @@ -18,9 +18,7 @@ function areRemoteGatewaysEnabled (): boolean { export default async function initHelia (kuboGatewayOptions: KuboGatewayOptions): Promise { const routers = [ - // always use delegated routing - // delegatedHTTPRouting('http://delegated-ipfs.dev'), - // Always add the Kubo gatewawy + // Always add the Kubo gateway httpGatewayRouting({ gateways: [`${kuboGatewayOptions.protocol ?? 'http'}://${kuboGatewayOptions.host}:${kuboGatewayOptions.port}`] }) ]