From aaa16dbc862c441b2686909891a18967c38b4185 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 16 Sep 2024 14:17:45 +0200 Subject: [PATCH 1/3] fix: use hasCode from multiformats No need to duplicate the function now. --- packages/interop/src/ipns-pubsub.spec.ts | 5 +++-- packages/utils/src/index.ts | 9 --------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/packages/interop/src/ipns-pubsub.spec.ts b/packages/interop/src/ipns-pubsub.spec.ts index bcbdbd42..43e7c9e4 100644 --- a/packages/interop/src/ipns-pubsub.spec.ts +++ b/packages/interop/src/ipns-pubsub.spec.ts @@ -4,7 +4,6 @@ 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' @@ -12,6 +11,8 @@ 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' @@ -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') } diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index b48d5733..c7b32aae 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -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 (digest: MultihashDigest, code: T): digest is MultihashDigest { - return digest.code === code -} From a4848befd59f676d26f57f7e7ab2ed00152c3b23 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 16 Sep 2024 14:35:16 +0200 Subject: [PATCH 2/3] chore: remove unused import --- packages/utils/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index c7b32aae..79d69cbf 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -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' From 433d9872871dcd6cb2be7778959ab405114c6f74 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 16 Sep 2024 15:28:07 +0200 Subject: [PATCH 3/3] chore: remove usused dep --- packages/interop/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/interop/package.json b/packages/interop/package.json index bb898f02..d13a4f44 100644 --- a/packages/interop/package.json +++ b/packages/interop/package.json @@ -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",