Skip to content

Commit

Permalink
chore: be stricter about cid types
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Sep 11, 2024
1 parent b242823 commit c15984e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const publicKeyToIPNSRoutingKey = (publicKey: PublicKey): Uint8Array => {
return multihashToIPNSRoutingKey(publicKey.toMultihash())
}

export const multihashToIPNSRoutingKey = (digest: MultihashDigest): Uint8Array => {
export const multihashToIPNSRoutingKey = (digest: MultihashDigest<0x00 | 0x12>): Uint8Array => {
return uint8ArrayConcat([
IPNS_PREFIX,
digest.bytes
Expand All @@ -153,7 +153,7 @@ export const publicKeyFromIPNSRoutingKey = (key: Uint8Array): Ed25519PublicKey |
} catch {}
}

export const multihashFromIPNSRoutingKey = (key: Uint8Array): MultihashDigest<0x00> | MultihashDigest<0x12> => {
export const multihashFromIPNSRoutingKey = (key: Uint8Array): MultihashDigest<0x00 | 0x12> => {
const digest = Digest.decode(key.slice(IPNS_PREFIX.length))

if (digest.code !== 0x00 && digest.code !== 0x12) {
Expand Down
1 change: 1 addition & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ describe('ipns', function () {

keys.forEach(key => {
const digest = Digest.decode(base58btc.decode(`z${key}`))
// @ts-expect-error digest may have the wrong hash type
const routingKey = multihashToIPNSRoutingKey(digest)
const id = multihashFromIPNSRoutingKey(routingKey)

Expand Down

0 comments on commit c15984e

Please sign in to comment.