Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: identity hashes display object info #465

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/components/object-info/ObjectInfo.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,23 @@ export const CidV0DagPb1240Links = () => (
CidV0DagPb1240Links.story = {
name: 'cid v0 dag-pb 1240 links...'
}

export const identityCID = () => (
<ObjectInfo
format="identity"
localPath="/"
className="ma2"
cid="bafkqaddjnzzxazldoqwxizltoq"
size={BigInt(0)}
links={[]}
data={new Uint8Array([105, 110, 115, 112, 101, 99, 116, 45, 116, 101, 115, 116])}
type="identity"
gatewayUrl="https://ipfs.io"
publicGatewayUrl="https://dweb.link"
onLinkClick={action('link clicked')}
/>
)
identityCID.story = {
name: 'identity CID'
}

7 changes: 7 additions & 0 deletions src/lib/hash-importer.ts
Original file line number Diff line number Diff line change
@@ -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> |
Expand Down Expand Up @@ -39,6 +41,11 @@ function getBoundHasher <T extends SupportedHashers> (hasher: T): T {
export async function getHasherForCode (code: number): Promise<SupportedHashers> {
// #WhenAddingNewHasher
switch (code) {
case identity.code:
return getBoundHasher({
...identity,
name: 'identity' // multiformats/hashes/identity doesn't export a proper Hasher<Name, Code> type. See https://github.com/multiformats/js-multiformats/issues/313
})
case sha2.sha256.code:
return getBoundHasher(sha2.sha256)
case sha2.sha512.code:
Expand Down
15 changes: 15 additions & 0 deletions test/e2e/edge-cases.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
})
})
})
Loading