Skip to content

Commit

Permalink
fix: identity hashes display object info (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki authored Dec 3, 2024
1 parent db2fed4 commit c159ca4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
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'
})
})
})

0 comments on commit c159ca4

Please sign in to comment.