Skip to content

Commit f5a03fc

Browse files
authored
fix: use hasCode from multiformats (#635)
No need to duplicate the function now.
1 parent 23e62e1 commit f5a03fc

File tree

3 files changed

+4
-13
lines changed

3 files changed

+4
-13
lines changed

packages/interop/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
"@helia/mfs": "^3.0.8",
7070
"@helia/routers": "^1.1.1",
7171
"@helia/strings": "^3.0.6",
72-
"@helia/utils": "^0.3.3",
7372
"@helia/unixfs": "^3.0.7",
7473
"@ipld/car": "^5.3.0",
7574
"@ipld/dag-cbor": "^9.2.0",

packages/interop/src/ipns-pubsub.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
import { gossipsub } from '@chainsafe/libp2p-gossipsub'
55
import { ipns } from '@helia/ipns'
66
import { pubsub } from '@helia/ipns/routing'
7-
import { hasCode } from '@helia/utils'
87
import { generateKeyPair } from '@libp2p/crypto/keys'
98
import { peerIdFromCID } from '@libp2p/peer-id'
109
import { expect } from 'aegir/chai'
1110
import last from 'it-last'
1211
import { base36 } from 'multiformats/bases/base36'
1312
import { CID } from 'multiformats/cid'
1413
import * as raw from 'multiformats/codecs/raw'
14+
import { hasCode } from 'multiformats/hashes/digest'
15+
import { identity } from 'multiformats/hashes/identity'
1516
import { sha256 } from 'multiformats/hashes/sha2'
1617
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
1718
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
@@ -129,7 +130,7 @@ keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
129130
const peerCid = CID.parse(result.id, base36)
130131
const peerId = peerIdFromCID(peerCid)
131132

132-
if (!hasCode(peerCid.multihash, 0)) {
133+
if (!hasCode(peerCid.multihash, identity.code)) {
133134
throw new Error('Incorrect hash type')
134135
}
135136

packages/utils/src/index.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import type { Blockstore } from 'interface-blockstore'
3838
import type { Datastore } from 'interface-datastore'
3939
import type { BlockCodec } from 'multiformats'
4040
import type { CID } from 'multiformats/cid'
41-
import type { MultihashDigest, MultihashHasher } from 'multiformats/hashes/interface'
41+
import type { MultihashHasher } from 'multiformats/hashes/interface'
4242

4343
export { AbstractSession, type AbstractCreateSessionOptions } from './abstract-session.js'
4444
export { BloomFilter } from './bloom-filter.js'
@@ -280,12 +280,3 @@ export class Helia implements HeliaInterface {
280280
this.log('gc finished')
281281
}
282282
}
283-
284-
/**
285-
* Used to check that the passed multihash has the passed code
286-
*
287-
* Remove after https://github.com/multiformats/js-multiformats/pull/308
288-
*/
289-
export function hasCode <T extends number> (digest: MultihashDigest, code: T): digest is MultihashDigest<T> {
290-
return digest.code === code
291-
}

0 commit comments

Comments
 (0)