Skip to content

Commit 6c6f455

Browse files
committed
fix: remote outdated dep
Removes `@libp2p/pubsub` dep
1 parent 7fff925 commit 6c6f455

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

packages/gossipsub/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
},
4444
"scripts": {
4545
"lint": "aegir lint",
46+
"dep-check": "aegir dep-check",
4647
"release": "aegir release --no-types",
4748
"build": "aegir build",
4849
"generate": "protons ./src/message/rpc.proto",
@@ -75,7 +76,7 @@
7576
"@libp2p/interface": "^3.1.0",
7677
"@libp2p/interface-internal": "^3.0.9",
7778
"@libp2p/peer-id": "^6.0.4",
78-
"@libp2p/pubsub": "^10.0.0",
79+
"@libp2p/utils": "^7.0.9",
7980
"@multiformats/multiaddr": "^13.0.1",
8081
"denque": "^2.1.0",
8182
"it-length-prefixed": "^10.0.1",
@@ -90,7 +91,6 @@
9091
"@chainsafe/as-sha256": "^1.2.0",
9192
"@dapplion/benchmark": "^1.0.0",
9293
"@libp2p/floodsub": "^11.0.10",
93-
"@libp2p/interface-compliance-tests": "^7.0.10",
9494
"@libp2p/logger": "^6.2.2",
9595
"@libp2p/peer-store": "^12.0.9",
9696
"@types/node": "^22.18.1",

packages/gossipsub/src/utils/msgIdFn.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
1-
import { msgId } from '@libp2p/pubsub/utils'
1+
import { publicKeyToProtobuf } from '@libp2p/crypto/keys'
22
import { sha256 } from 'multiformats/hashes/sha2'
3+
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
34
import type { Message } from '../index.js'
5+
import type { PublicKey } from '@libp2p/interface'
6+
7+
/**
8+
* Generate a message id, based on the `key` and `seqno`
9+
*/
10+
export const msgId = (key: PublicKey, seqno: bigint): Uint8Array => {
11+
const seqnoBytes = uint8ArrayFromString(seqno.toString(16).padStart(16, '0'), 'base16')
12+
const keyBytes = publicKeyToProtobuf(key)
13+
14+
const msgId = new Uint8Array(keyBytes.byteLength + seqnoBytes.length)
15+
msgId.set(keyBytes, 0)
16+
msgId.set(seqnoBytes, keyBytes.byteLength)
17+
18+
return msgId
19+
}
420

521
/**
622
* Generate a message id, based on the `key` and `seqno`

packages/gossipsub/test/message-cache.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
import * as utils from '@libp2p/pubsub/utils'
1+
import { randomBytes } from '@libp2p/crypto'
22
import { expect } from 'aegir/chai'
33
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
4+
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
45
import { MessageCache } from '../src/message-cache.js'
56
import { messageIdToString } from '../src/utils/messageIdToString.js'
67
import { getMsgId } from './utils/index.js'
78
import type { RPC } from '../src/message/rpc.js'
89
import type { MessageId } from '../src/types.js'
910

11+
function randomSeqno (): bigint {
12+
return BigInt(`0x${uint8ArrayToString(randomBytes(8), 'base16')}`)
13+
}
14+
1015
const toMessageId = (msgId: Uint8Array): MessageId => {
1116
return {
1217
msgId,
@@ -28,7 +33,7 @@ describe('Testing Message Cache Operations', () => {
2833
return {
2934
from: new Uint8Array(0),
3035
data: uint8ArrayFromString(n.toString()),
31-
seqno: uint8ArrayFromString(utils.randomSeqno().toString(16).padStart(16, '0'), 'base16'),
36+
seqno: uint8ArrayFromString(randomSeqno().toString(16).padStart(16, '0'), 'base16'),
3237
topic
3338
}
3439
}

0 commit comments

Comments
 (0)