Skip to content

Commit

Permalink
fix: use hasCode from multiformats (#635)
Browse files Browse the repository at this point in the history
No need to duplicate the function now.
  • Loading branch information
achingbrain authored Sep 17, 2024
1 parent 23e62e1 commit f5a03fc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 13 deletions.
1 change: 0 additions & 1 deletion packages/interop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
"@helia/mfs": "^3.0.8",
"@helia/routers": "^1.1.1",
"@helia/strings": "^3.0.6",
"@helia/utils": "^0.3.3",
"@helia/unixfs": "^3.0.7",
"@ipld/car": "^5.3.0",
"@ipld/dag-cbor": "^9.2.0",
Expand Down
5 changes: 3 additions & 2 deletions packages/interop/src/ipns-pubsub.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import { gossipsub } from '@chainsafe/libp2p-gossipsub'
import { ipns } from '@helia/ipns'
import { pubsub } from '@helia/ipns/routing'
import { hasCode } from '@helia/utils'
import { generateKeyPair } from '@libp2p/crypto/keys'
import { peerIdFromCID } from '@libp2p/peer-id'
import { expect } from 'aegir/chai'
import last from 'it-last'
import { base36 } from 'multiformats/bases/base36'
import { CID } from 'multiformats/cid'
import * as raw from 'multiformats/codecs/raw'
import { hasCode } from 'multiformats/hashes/digest'
import { identity } from 'multiformats/hashes/identity'
import { sha256 } from 'multiformats/hashes/sha2'
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
Expand Down Expand Up @@ -129,7 +130,7 @@ keyTypes.filter(keyType => keyType !== 'RSA').forEach(keyType => {
const peerCid = CID.parse(result.id, base36)
const peerId = peerIdFromCID(peerCid)

if (!hasCode(peerCid.multihash, 0)) {
if (!hasCode(peerCid.multihash, identity.code)) {
throw new Error('Incorrect hash type')
}

Expand Down
11 changes: 1 addition & 10 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import type { Blockstore } from 'interface-blockstore'
import type { Datastore } from 'interface-datastore'
import type { BlockCodec } from 'multiformats'
import type { CID } from 'multiformats/cid'
import type { MultihashDigest, MultihashHasher } from 'multiformats/hashes/interface'
import type { MultihashHasher } from 'multiformats/hashes/interface'

export { AbstractSession, type AbstractCreateSessionOptions } from './abstract-session.js'
export { BloomFilter } from './bloom-filter.js'
Expand Down Expand Up @@ -280,12 +280,3 @@ export class Helia implements HeliaInterface {
this.log('gc finished')
}
}

/**
* Used to check that the passed multihash has the passed code
*
* Remove after https://github.com/multiformats/js-multiformats/pull/308
*/
export function hasCode <T extends number> (digest: MultihashDigest, code: T): digest is MultihashDigest<T> {
return digest.code === code
}

0 comments on commit f5a03fc

Please sign in to comment.