From 68c868844580d57efdda7cabb690ca5ac8215095 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Mon, 2 Dec 2024 16:18:24 -0600 Subject: [PATCH] fix: identity hashes display object info --- .../object-info/ObjectInfo.stories.tsx | 20 +++++++++++++++++++ src/lib/hash-importer.ts | 7 +++++++ test/e2e/edge-cases.test.ts | 15 ++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/src/components/object-info/ObjectInfo.stories.tsx b/src/components/object-info/ObjectInfo.stories.tsx index 85a27dce..2eb28298 100644 --- a/src/components/object-info/ObjectInfo.stories.tsx +++ b/src/components/object-info/ObjectInfo.stories.tsx @@ -75,3 +75,23 @@ export const CidV0DagPb1240Links = () => ( CidV0DagPb1240Links.story = { name: 'cid v0 dag-pb 1240 links...' } + +export const identityCID = () => ( + +) +identityCID.story = { + name: 'identity CID' +} + diff --git a/src/lib/hash-importer.ts b/src/lib/hash-importer.ts index 1b11d081..b7cace0f 100644 --- a/src/lib/hash-importer.ts +++ b/src/lib/hash-importer.ts @@ -1,11 +1,13 @@ /* global globalThis */ import { sha3512, keccak256 } from '@multiformats/sha3' import { type Hasher, from } from 'multiformats/hashes/hasher' +import { identity } from 'multiformats/hashes/identity' import * as sha2 from 'multiformats/hashes/sha2' // #WhenAddingNewHasher export type SupportedHashers = typeof sha2.sha256 | typeof sha2.sha512 | + Hasher<'identity', 0x0> | Hasher<'keccak-256', 27> | Hasher<'sha1', 17> | Hasher<'blake2b-256', 0xb220> | @@ -39,6 +41,11 @@ function getBoundHasher (hasher: T): T { export async function getHasherForCode (code: number): Promise { // #WhenAddingNewHasher switch (code) { + case identity.code: + return getBoundHasher({ + ...identity, + name: 'identity' // multiformats/hashes/identity doesn't export a proper Hasher type. See https://github.com/multiformats/js-multiformats/issues/313 + }) case sha2.sha256.code: return getBoundHasher(sha2.sha256) case sha2.sha512.code: diff --git a/test/e2e/edge-cases.test.ts b/test/e2e/edge-cases.test.ts index 3c6974c1..695d35f5 100644 --- a/test/e2e/edge-cases.test.ts +++ b/test/e2e/edge-cases.test.ts @@ -36,4 +36,19 @@ test.describe('edge-cases', () => { type: 'dag-pb' }) }) + + test('identity CIDs render object info properly', async ({ page }) => { + // Test for https://github.com/ipfs/ipld-explorer-components/issues/464 + const cid = 'bafkqaddjnzzxazldoqwxizltoq' + + await page.goto('/#/explore/bafkqaddjnzzxazldoqwxizltoq') + + await testExploredCid({ + fillOutForm: false, + page, + cid, + humanReadableCID: 'base32 - cidv1 - raw - identity~96~696E73706563742D74657374', + type: 'raw' + }) + }) })