Skip to content

Commit c159ca4

Browse files
authored
fix: identity hashes display object info (#465)
1 parent db2fed4 commit c159ca4

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

src/components/object-info/ObjectInfo.stories.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,23 @@ export const CidV0DagPb1240Links = () => (
7575
CidV0DagPb1240Links.story = {
7676
name: 'cid v0 dag-pb 1240 links...'
7777
}
78+
79+
export const identityCID = () => (
80+
<ObjectInfo
81+
format="identity"
82+
localPath="/"
83+
className="ma2"
84+
cid="bafkqaddjnzzxazldoqwxizltoq"
85+
size={BigInt(0)}
86+
links={[]}
87+
data={new Uint8Array([105, 110, 115, 112, 101, 99, 116, 45, 116, 101, 115, 116])}
88+
type="identity"
89+
gatewayUrl="https://ipfs.io"
90+
publicGatewayUrl="https://dweb.link"
91+
onLinkClick={action('link clicked')}
92+
/>
93+
)
94+
identityCID.story = {
95+
name: 'identity CID'
96+
}
97+

src/lib/hash-importer.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/* global globalThis */
22
import { sha3512, keccak256 } from '@multiformats/sha3'
33
import { type Hasher, from } from 'multiformats/hashes/hasher'
4+
import { identity } from 'multiformats/hashes/identity'
45
import * as sha2 from 'multiformats/hashes/sha2'
56

67
// #WhenAddingNewHasher
78
export type SupportedHashers = typeof sha2.sha256 |
89
typeof sha2.sha512 |
10+
Hasher<'identity', 0x0> |
911
Hasher<'keccak-256', 27> |
1012
Hasher<'sha1', 17> |
1113
Hasher<'blake2b-256', 0xb220> |
@@ -39,6 +41,11 @@ function getBoundHasher <T extends SupportedHashers> (hasher: T): T {
3941
export async function getHasherForCode (code: number): Promise<SupportedHashers> {
4042
// #WhenAddingNewHasher
4143
switch (code) {
44+
case identity.code:
45+
return getBoundHasher({
46+
...identity,
47+
name: 'identity' // multiformats/hashes/identity doesn't export a proper Hasher<Name, Code> type. See https://github.com/multiformats/js-multiformats/issues/313
48+
})
4249
case sha2.sha256.code:
4350
return getBoundHasher(sha2.sha256)
4451
case sha2.sha512.code:

test/e2e/edge-cases.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,19 @@ test.describe('edge-cases', () => {
3636
type: 'dag-pb'
3737
})
3838
})
39+
40+
test('identity CIDs render object info properly', async ({ page }) => {
41+
// Test for https://github.com/ipfs/ipld-explorer-components/issues/464
42+
const cid = 'bafkqaddjnzzxazldoqwxizltoq'
43+
44+
await page.goto('/#/explore/bafkqaddjnzzxazldoqwxizltoq')
45+
46+
await testExploredCid({
47+
fillOutForm: false,
48+
page,
49+
cid,
50+
humanReadableCID: 'base32 - cidv1 - raw - identity~96~696E73706563742D74657374',
51+
type: 'raw'
52+
})
53+
})
3954
})

0 commit comments

Comments
 (0)