mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-04-25 15:42:34 +00:00
Merge remote-tracking branch 'origin/master' into mpetrunic/fix-outbount-remote-peer
# Conflicts: # CHANGELOG.md
This commit is contained in:
commit
ea67a7d7d1
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Bugfixes
|
||||
- return handshake remote peer from secureOutbound
|
||||
- fix browser usage of buffer
|
||||
|
||||
## [1.0.0-rc.8] - 2019-03-05
|
||||
|
||||
|
13
src/utils.ts
13
src/utils.ts
@ -58,9 +58,9 @@ export async function getPeerIdFromPayload(payload: pb.INoiseHandshakePayload):
|
||||
return await PeerId.createFromPubKey(Buffer.from(payload.identityKey as Uint8Array));
|
||||
}
|
||||
|
||||
export async function decodePayload(payload: bytes): Promise<pb.INoiseHandshakePayload> {
|
||||
export async function decodePayload(payload: bytes|Uint8Array): Promise<pb.INoiseHandshakePayload> {
|
||||
return NoiseHandshakePayloadProto.toObject(
|
||||
NoiseHandshakePayloadProto.decode(payload)
|
||||
NoiseHandshakePayloadProto.decode(Buffer.from(payload))
|
||||
) as INoisePayload;
|
||||
}
|
||||
|
||||
@ -85,19 +85,16 @@ export async function verifySignedPayload(
|
||||
payload: pb.INoiseHandshakePayload,
|
||||
remotePeer: PeerId
|
||||
): Promise<PeerId> {
|
||||
|
||||
if (!(await isValidPeerId(remotePeer.id, Buffer.from(payload.identityKey as Uint8Array)))) {
|
||||
const identityKey = Buffer.from(payload.identityKey as Uint8Array);
|
||||
if (!(await isValidPeerId(remotePeer.id, identityKey))) {
|
||||
throw new Error("Peer ID doesn't match libp2p public key.");
|
||||
}
|
||||
|
||||
const generatedPayload = getHandshakePayload(noiseStaticKey);
|
||||
|
||||
// Unmarshaling from PublicKey protobuf
|
||||
const publicKey = crypto.keys.unmarshalPublicKey(payload.identityKey);
|
||||
const publicKey = crypto.keys.unmarshalPublicKey(identityKey);
|
||||
if (!publicKey.verify(generatedPayload, payload.identitySig)) {
|
||||
throw new Error("Static key doesn't match to peer that signed payload!");
|
||||
}
|
||||
|
||||
return remotePeer;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user