Skip to content

Commit

Permalink
fix: use hasCode from multiformats
Browse files Browse the repository at this point in the history
No need to duplicate the function now.
  • Loading branch information
achingbrain committed Sep 16, 2024
1 parent 23e62e1 commit aaa16db
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
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
9 changes: 0 additions & 9 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
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 aaa16db

Please sign in to comment.