Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use hasCode from multiformats #635

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading