Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 927cc47

Browse files
committedSep 12, 2024
chore: be stricter about cid types
1 parent 975eaca commit 927cc47

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed
 

‎src/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export const publicKeyToIPNSRoutingKey = (publicKey: PublicKey): Uint8Array => {
139139
return multihashToIPNSRoutingKey(publicKey.toMultihash())
140140
}
141141

142-
export const multihashToIPNSRoutingKey = (digest: MultihashDigest): Uint8Array => {
142+
export const multihashToIPNSRoutingKey = (digest: MultihashDigest<0x00 | 0x12>): Uint8Array => {
143143
return uint8ArrayConcat([
144144
IPNS_PREFIX,
145145
digest.bytes
@@ -153,7 +153,7 @@ export const publicKeyFromIPNSRoutingKey = (key: Uint8Array): Ed25519PublicKey |
153153
} catch {}
154154
}
155155

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

159159
if (digest.code !== 0x00 && digest.code !== 0x12) {

‎test/index.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ describe('ipns', function () {
356356

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

0 commit comments

Comments
 (0)
Please sign in to comment.