Skip to content

Commit 07a6cd6

Browse files
authored
chore: make libp2p-crypto a dev dep (#115)
It's only used to verify incoming message payloads but the `pubKey` property on `PeerId` can do that.
1 parent 735f287 commit 07a6cd6

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"buffer": "^6.0.3",
4242
"chai": "^4.3.4",
4343
"events": "^3.3.0",
44+
"libp2p-crypto": "^0.19.7",
4445
"microtime": "^3.0.0",
4546
"mocha": "^9.0.2",
4647
"sinon": "^11.1.1"
@@ -56,7 +57,6 @@
5657
"it-pair": "^1.0.0",
5758
"it-pb-rpc": "^0.1.11",
5859
"it-pipe": "^1.1.0",
59-
"libp2p-crypto": "^0.19.7",
6060
"peer-id": "^0.15.3",
6161
"protobufjs": "^6.11.2",
6262
"uint8arrays": "^3.0.0"

src/utils.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { SHA256 } from '@stablelib/sha256'
33
import * as x25519 from '@stablelib/x25519'
44
import { Buffer } from 'buffer'
55
import PeerId from 'peer-id'
6-
import { keys } from 'libp2p-crypto'
76
import { KeyPair } from './@types/libp2p'
87
import { bytes, bytes32 } from './@types/basic'
98
import { Hkdf, INoisePayload } from './@types/handshake'
@@ -92,13 +91,13 @@ export async function verifySignedPayload (
9291
}
9392
const generatedPayload = getHandshakePayload(noiseStaticKey)
9493
// Unmarshaling from PublicKey protobuf
95-
const publicKey = keys.unmarshalPublicKey(identityKey)
94+
const peerId = await PeerId.createFromPubKey(identityKey)
9695
// TODO remove this after libp2p-crypto ships proper types
9796
// eslint-disable-next-line @typescript-eslint/no-misused-promises
98-
if (!payload.identitySig || !publicKey.verify(generatedPayload, Buffer.from(payload.identitySig))) {
97+
if (!payload.identitySig || !peerId.pubKey.verify(generatedPayload, Buffer.from(payload.identitySig))) {
9998
throw new Error("Static key doesn't match to peer that signed payload!")
10099
}
101-
return await PeerId.createFromPubKey(identityKey)
100+
return peerId
102101
}
103102

104103
export function getHkdf (ck: bytes32, ikm: bytes): Hkdf {

0 commit comments

Comments
 (0)