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

chore: make libp2p-crypto a dev dep #115

Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"buffer": "^6.0.3",
"chai": "^4.3.4",
"events": "^3.3.0",
"libp2p-crypto": "^0.19.7",
"microtime": "^3.0.0",
"mocha": "^9.0.2",
"sinon": "^11.1.1"
Expand All @@ -56,7 +57,6 @@
"it-pair": "^1.0.0",
"it-pb-rpc": "^0.1.11",
"it-pipe": "^1.1.0",
"libp2p-crypto": "^0.19.7",
"peer-id": "^0.15.3",
"protobufjs": "^6.11.2",
"uint8arrays": "^3.0.0"
Expand Down
7 changes: 3 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { SHA256 } from '@stablelib/sha256'
import * as x25519 from '@stablelib/x25519'
import { Buffer } from 'buffer'
import PeerId from 'peer-id'
import { keys } from 'libp2p-crypto'
import { KeyPair } from './@types/libp2p'
import { bytes, bytes32 } from './@types/basic'
import { Hkdf, INoisePayload } from './@types/handshake'
Expand Down Expand Up @@ -92,13 +91,13 @@ export async function verifySignedPayload (
}
const generatedPayload = getHandshakePayload(noiseStaticKey)
// Unmarshaling from PublicKey protobuf
const publicKey = keys.unmarshalPublicKey(identityKey)
const peerId = await PeerId.createFromPubKey(identityKey)
// TODO remove this after libp2p-crypto ships proper types
// eslint-disable-next-line @typescript-eslint/no-misused-promises
if (!payload.identitySig || !publicKey.verify(generatedPayload, Buffer.from(payload.identitySig))) {
if (!payload.identitySig || !peerId.pubKey.verify(generatedPayload, Buffer.from(payload.identitySig))) {
throw new Error("Static key doesn't match to peer that signed payload!")
}
return await PeerId.createFromPubKey(identityKey)
return peerId
}

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