mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-06-10 19:31:26 +00:00
use libp2p keys from PeerId argument
This commit is contained in:
@ -5,10 +5,6 @@ import { KeyPair, PeerId } from "./@types/libp2p";
|
|||||||
import { bytes, bytes32 } from "./@types/basic";
|
import { bytes, bytes32 } from "./@types/basic";
|
||||||
import { NoiseSession } from "./@types/handshake";
|
import { NoiseSession } from "./@types/handshake";
|
||||||
import {
|
import {
|
||||||
createHandshakePayload,
|
|
||||||
getHandshakePayload,
|
|
||||||
signEarlyDataPayload,
|
|
||||||
signPayload,
|
|
||||||
verifySignedPayload,
|
verifySignedPayload,
|
||||||
} from "./utils";
|
} from "./utils";
|
||||||
import { logger } from "./logger";
|
import { logger } from "./logger";
|
||||||
@ -19,8 +15,7 @@ export class Handshake {
|
|||||||
public isInitiator: boolean;
|
public isInitiator: boolean;
|
||||||
public session: NoiseSession;
|
public session: NoiseSession;
|
||||||
|
|
||||||
private libp2pPrivateKey: bytes;
|
private payload: bytes;
|
||||||
private libp2pPublicKey: bytes;
|
|
||||||
private prologue: bytes32;
|
private prologue: bytes32;
|
||||||
private staticKeys: KeyPair;
|
private staticKeys: KeyPair;
|
||||||
private connection: WrappedConnection;
|
private connection: WrappedConnection;
|
||||||
@ -29,8 +24,7 @@ export class Handshake {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
isInitiator: boolean,
|
isInitiator: boolean,
|
||||||
libp2pPrivateKey: bytes,
|
payload: bytes,
|
||||||
libp2pPublicKey: bytes,
|
|
||||||
prologue: bytes32,
|
prologue: bytes32,
|
||||||
staticKeys: KeyPair,
|
staticKeys: KeyPair,
|
||||||
connection: WrappedConnection,
|
connection: WrappedConnection,
|
||||||
@ -38,8 +32,7 @@ export class Handshake {
|
|||||||
handshake?: XXHandshake,
|
handshake?: XXHandshake,
|
||||||
) {
|
) {
|
||||||
this.isInitiator = isInitiator;
|
this.isInitiator = isInitiator;
|
||||||
this.libp2pPrivateKey = libp2pPrivateKey;
|
this.payload = payload;
|
||||||
this.libp2pPublicKey = libp2pPublicKey;
|
|
||||||
this.prologue = prologue;
|
this.prologue = prologue;
|
||||||
this.staticKeys = staticKeys;
|
this.staticKeys = staticKeys;
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
@ -81,16 +74,7 @@ export class Handshake {
|
|||||||
logger("All good with the signature!");
|
logger("All good with the signature!");
|
||||||
} else {
|
} else {
|
||||||
logger('Stage 1 - Responder sending out first message with signed payload and static key.');
|
logger('Stage 1 - Responder sending out first message with signed payload and static key.');
|
||||||
const signedPayload = signPayload(this.libp2pPrivateKey, getHandshakePayload(this.staticKeys.publicKey));
|
const messageBuffer = this.xx.sendMessage(this.session, this.payload);
|
||||||
const signedEarlyDataPayload = signEarlyDataPayload(this.libp2pPrivateKey, Buffer.alloc(0));
|
|
||||||
const handshakePayload = await createHandshakePayload(
|
|
||||||
this.libp2pPublicKey,
|
|
||||||
this.libp2pPrivateKey,
|
|
||||||
signedPayload,
|
|
||||||
signedEarlyDataPayload,
|
|
||||||
);
|
|
||||||
|
|
||||||
const messageBuffer = this.xx.sendMessage(this.session, handshakePayload);
|
|
||||||
this.connection.writeLP(encodeMessageBuffer(messageBuffer));
|
this.connection.writeLP(encodeMessageBuffer(messageBuffer));
|
||||||
logger('Stage 1 - Responder sent the second handshake message with signed payload.')
|
logger('Stage 1 - Responder sent the second handshake message with signed payload.')
|
||||||
}
|
}
|
||||||
@ -100,15 +84,7 @@ export class Handshake {
|
|||||||
async finish(earlyData?: bytes): Promise<void> {
|
async finish(earlyData?: bytes): Promise<void> {
|
||||||
if (this.isInitiator) {
|
if (this.isInitiator) {
|
||||||
logger('Stage 2 - Initiator sending third handshake message.');
|
logger('Stage 2 - Initiator sending third handshake message.');
|
||||||
const signedPayload = signPayload(this.libp2pPrivateKey, getHandshakePayload(this.staticKeys.publicKey));
|
const messageBuffer = this.xx.sendMessage(this.session, this.payload);
|
||||||
const signedEarlyDataPayload = signEarlyDataPayload(this.libp2pPrivateKey, earlyData || Buffer.alloc(0));
|
|
||||||
const handshakePayload = await createHandshakePayload(
|
|
||||||
this.libp2pPublicKey,
|
|
||||||
this.libp2pPrivateKey,
|
|
||||||
signedPayload,
|
|
||||||
signedEarlyDataPayload
|
|
||||||
);
|
|
||||||
const messageBuffer = this.xx.sendMessage(this.session, handshakePayload);
|
|
||||||
this.connection.writeLP(encodeMessageBuffer(messageBuffer));
|
this.connection.writeLP(encodeMessageBuffer(messageBuffer));
|
||||||
logger('Stage 2 - Initiator sent message with signed payload.');
|
logger('Stage 2 - Initiator sent message with signed payload.');
|
||||||
} else {
|
} else {
|
||||||
|
25
src/noise.ts
25
src/noise.ts
@ -7,7 +7,14 @@ import pipe from 'it-pipe';
|
|||||||
import lp from 'it-length-prefixed';
|
import lp from 'it-length-prefixed';
|
||||||
|
|
||||||
import { Handshake } from "./handshake";
|
import { Handshake } from "./handshake";
|
||||||
import { generateKeypair } from "./utils";
|
import {
|
||||||
|
createHandshakePayload,
|
||||||
|
generateKeypair,
|
||||||
|
getHandshakePayload,
|
||||||
|
getPayload,
|
||||||
|
signEarlyDataPayload,
|
||||||
|
signPayload
|
||||||
|
} from "./utils";
|
||||||
import { uint16BEDecode, uint16BEEncode } from "./encoder";
|
import { uint16BEDecode, uint16BEEncode } from "./encoder";
|
||||||
import { decryptStream, encryptStream } from "./crypto";
|
import { decryptStream, encryptStream } from "./crypto";
|
||||||
import { bytes } from "./@types/basic";
|
import { bytes } from "./@types/basic";
|
||||||
@ -19,12 +26,10 @@ export type WrappedConnection = ReturnType<typeof Wrap>;
|
|||||||
export class Noise implements NoiseConnection {
|
export class Noise implements NoiseConnection {
|
||||||
public protocol = "/noise";
|
public protocol = "/noise";
|
||||||
|
|
||||||
private readonly privateKey: bytes;
|
|
||||||
private readonly staticKeys: KeyPair;
|
private readonly staticKeys: KeyPair;
|
||||||
private readonly earlyData?: bytes;
|
private readonly earlyData?: bytes;
|
||||||
|
|
||||||
constructor(privateKey: bytes, staticNoiseKey?: bytes, earlyData?: bytes) {
|
constructor(staticNoiseKey?: bytes, earlyData?: bytes) {
|
||||||
this.privateKey = privateKey;
|
|
||||||
this.earlyData = earlyData || Buffer.alloc(0);
|
this.earlyData = earlyData || Buffer.alloc(0);
|
||||||
|
|
||||||
if (staticNoiseKey) {
|
if (staticNoiseKey) {
|
||||||
@ -47,8 +52,7 @@ export class Noise implements NoiseConnection {
|
|||||||
*/
|
*/
|
||||||
public async secureOutbound(localPeer: PeerId, connection: any, remotePeer: PeerId): Promise<SecureOutbound> {
|
public async secureOutbound(localPeer: PeerId, connection: any, remotePeer: PeerId): Promise<SecureOutbound> {
|
||||||
const wrappedConnection = Wrap(connection);
|
const wrappedConnection = Wrap(connection);
|
||||||
const libp2pPublicKey = localPeer.marshalPubKey();
|
const handshake = await this.performHandshake(wrappedConnection, true, localPeer, remotePeer);
|
||||||
const handshake = await this.performHandshake(wrappedConnection, true, libp2pPublicKey, remotePeer);
|
|
||||||
const conn = await this.createSecureConnection(wrappedConnection, handshake);
|
const conn = await this.createSecureConnection(wrappedConnection, handshake);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -66,8 +70,7 @@ export class Noise implements NoiseConnection {
|
|||||||
*/
|
*/
|
||||||
public async secureInbound(localPeer: PeerId, connection: any, remotePeer: PeerId): Promise<SecureOutbound> {
|
public async secureInbound(localPeer: PeerId, connection: any, remotePeer: PeerId): Promise<SecureOutbound> {
|
||||||
const wrappedConnection = Wrap(connection);
|
const wrappedConnection = Wrap(connection);
|
||||||
const libp2pPublicKey = localPeer.marshalPubKey();
|
const handshake = await this.performHandshake(wrappedConnection, false, localPeer, remotePeer);
|
||||||
const handshake = await this.performHandshake(wrappedConnection, false, libp2pPublicKey, remotePeer);
|
|
||||||
const conn = await this.createSecureConnection(wrappedConnection, handshake);
|
const conn = await this.createSecureConnection(wrappedConnection, handshake);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -79,11 +82,12 @@ export class Noise implements NoiseConnection {
|
|||||||
private async performHandshake(
|
private async performHandshake(
|
||||||
connection: WrappedConnection,
|
connection: WrappedConnection,
|
||||||
isInitiator: boolean,
|
isInitiator: boolean,
|
||||||
libp2pPublicKey: bytes,
|
localPeer: PeerId,
|
||||||
remotePeer: PeerId,
|
remotePeer: PeerId,
|
||||||
): Promise<Handshake> {
|
): Promise<Handshake> {
|
||||||
const prologue = Buffer.from(this.protocol);
|
const prologue = Buffer.from(this.protocol);
|
||||||
const handshake = new Handshake(isInitiator, this.privateKey, libp2pPublicKey, prologue, this.staticKeys, connection, remotePeer);
|
const payload = await getPayload(localPeer, this.staticKeys.publicKey);
|
||||||
|
const handshake = new Handshake(isInitiator, payload, prologue, this.staticKeys, connection, remotePeer);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await handshake.propose();
|
await handshake.propose();
|
||||||
@ -119,5 +123,4 @@ export class Noise implements NoiseConnection {
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
28
src/utils.ts
28
src/utils.ts
@ -23,6 +23,22 @@ export function generateKeypair(): KeyPair {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getPayload(
|
||||||
|
localPeer: PeerId,
|
||||||
|
staticPublicKey: bytes,
|
||||||
|
earlyData?: bytes,
|
||||||
|
): Promise<bytes> {
|
||||||
|
const signedPayload = await signPayload(localPeer, getHandshakePayload(staticPublicKey));
|
||||||
|
const signedEarlyDataPayload = await signEarlyDataPayload(localPeer, earlyData || Buffer.alloc(0));
|
||||||
|
|
||||||
|
return await createHandshakePayload(
|
||||||
|
localPeer.marshalPubKey(),
|
||||||
|
localPeer.marshalPrivKey(),
|
||||||
|
signedPayload,
|
||||||
|
signedEarlyDataPayload
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export async function createHandshakePayload(
|
export async function createHandshakePayload(
|
||||||
libp2pPublicKey: bytes,
|
libp2pPublicKey: bytes,
|
||||||
libp2pPrivateKey: bytes,
|
libp2pPrivateKey: bytes,
|
||||||
@ -46,8 +62,8 @@ export async function createHandshakePayload(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function signPayload(libp2pPrivateKey: bytes, payload: bytes) {
|
export async function signPayload(peerId: PeerId, payload: bytes): Promise<bytes> {
|
||||||
return ed25519.sign(payload, libp2pPrivateKey);
|
return peerId.privKey.sign(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
type EarlyDataPayload = {
|
type EarlyDataPayload = {
|
||||||
@ -55,9 +71,9 @@ type EarlyDataPayload = {
|
|||||||
libp2pDataSignature: bytes;
|
libp2pDataSignature: bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function signEarlyDataPayload(libp2pPrivateKey: bytes, earlyData: bytes): EarlyDataPayload {
|
export async function signEarlyDataPayload(peerId: PeerId, earlyData: bytes): Promise<EarlyDataPayload> {
|
||||||
const payload = getEarlyDataPayload(earlyData);
|
const payload = getEarlyDataPayload(earlyData);
|
||||||
const signedPayload = signPayload(libp2pPrivateKey, payload);
|
const signedPayload = await signPayload(peerId, payload);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
libp2pData: payload,
|
libp2pData: payload,
|
||||||
@ -84,8 +100,8 @@ export async function verifySignedPayload(noiseStaticKey: bytes, plaintext: byte
|
|||||||
|
|
||||||
const generatedPayload = getHandshakePayload(noiseStaticKey);
|
const generatedPayload = getHandshakePayload(noiseStaticKey);
|
||||||
// Unmarshaling from PublicKey protobuf and taking key buffer only.
|
// Unmarshaling from PublicKey protobuf and taking key buffer only.
|
||||||
const publicKey = crypto.keys.unmarshalPublicKey(receivedPayload.libp2pKey).marshal();
|
const publicKey = crypto.keys.unmarshalPublicKey(receivedPayload.libp2pKey);
|
||||||
if (!ed25519.verify(generatedPayload, receivedPayload.noiseStaticKeySignature, publicKey)) {
|
if (!publicKey.verify(generatedPayload, receivedPayload.noiseStaticKeySignature)) {
|
||||||
throw new Error("Static key doesn't match to peer that signed payload!");
|
throw new Error("Static key doesn't match to peer that signed payload!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import {Buffer} from "buffer";
|
|||||||
import Wrap from "it-pb-rpc";
|
import Wrap from "it-pb-rpc";
|
||||||
|
|
||||||
import {Handshake} from "../src/handshake";
|
import {Handshake} from "../src/handshake";
|
||||||
import {generateKeypair} from "../src/utils";
|
import {generateKeypair, getPayload} from "../src/utils";
|
||||||
import {createPeerIdsFromFixtures} from "./fixtures/peer";
|
import {createPeerIdsFromFixtures} from "./fixtures/peer";
|
||||||
import {getKeyPairFromPeerId} from "./utils";
|
import {getKeyPairFromPeerId} from "./utils";
|
||||||
|
|
||||||
@ -26,11 +26,11 @@ describe("Handshake", () => {
|
|||||||
const staticKeysInitiator = generateKeypair();
|
const staticKeysInitiator = generateKeypair();
|
||||||
const staticKeysResponder = generateKeypair();
|
const staticKeysResponder = generateKeypair();
|
||||||
|
|
||||||
const { privateKey: initiatorPrivKey, publicKey: initiatorPubKey } = getKeyPairFromPeerId(peerA);
|
const initPayload = await getPayload(peerA, staticKeysInitiator.publicKey);
|
||||||
const handshakeInitator = new Handshake(true, initiatorPrivKey, initiatorPubKey, prologue, staticKeysInitiator, connectionFrom, peerB);
|
const handshakeInitator = new Handshake(true, initPayload, prologue, staticKeysInitiator, connectionFrom, peerB);
|
||||||
|
|
||||||
const { privateKey: responderPrivKey, publicKey: responderPubKey } = getKeyPairFromPeerId(peerB);
|
const respPayload = await getPayload(peerB, staticKeysResponder.publicKey);
|
||||||
const handshakeResponder = new Handshake(false, responderPrivKey, responderPubKey, prologue, staticKeysResponder, connectionTo, peerA);
|
const handshakeResponder = new Handshake(false, respPayload, prologue, staticKeysResponder, connectionTo, peerA);
|
||||||
|
|
||||||
await handshakeInitator.propose();
|
await handshakeInitator.propose();
|
||||||
await handshakeResponder.propose();
|
await handshakeResponder.propose();
|
||||||
@ -71,11 +71,11 @@ describe("Handshake", () => {
|
|||||||
const staticKeysInitiator = generateKeypair();
|
const staticKeysInitiator = generateKeypair();
|
||||||
const staticKeysResponder = generateKeypair();
|
const staticKeysResponder = generateKeypair();
|
||||||
|
|
||||||
const { privateKey: initiatorPrivKey, publicKey: initiatorPubKey } = getKeyPairFromPeerId(peerA);
|
const initPayload = await getPayload(peerA, staticKeysInitiator.publicKey);
|
||||||
const handshakeInitator = new Handshake(true, initiatorPrivKey, initiatorPubKey, prologue, staticKeysInitiator, connectionFrom, fakePeer);
|
const handshakeInitator = new Handshake(true, initPayload, prologue, staticKeysInitiator, connectionFrom, fakePeer);
|
||||||
|
|
||||||
const { privateKey: responderPrivKey, publicKey: responderPubKey } = getKeyPairFromPeerId(peerB);
|
const respPayload = await getPayload(peerB, staticKeysResponder.publicKey);
|
||||||
const handshakeResponder = new Handshake(false, responderPrivKey, responderPubKey, prologue, staticKeysResponder, connectionTo, peerA);
|
const handshakeResponder = new Handshake(false, respPayload, prologue, staticKeysResponder, connectionTo, peerA);
|
||||||
|
|
||||||
await handshakeInitator.propose();
|
await handshakeInitator.propose();
|
||||||
await handshakeResponder.propose();
|
await handshakeResponder.propose();
|
||||||
@ -99,11 +99,11 @@ describe("Handshake", () => {
|
|||||||
const staticKeysInitiator = generateKeypair();
|
const staticKeysInitiator = generateKeypair();
|
||||||
const staticKeysResponder = generateKeypair();
|
const staticKeysResponder = generateKeypair();
|
||||||
|
|
||||||
const { privateKey: initiatorPrivKey, publicKey: initiatorPubKey } = getKeyPairFromPeerId(peerA);
|
const initPayload = await getPayload(peerA, staticKeysInitiator.publicKey);
|
||||||
const handshakeInitator = new Handshake(true, initiatorPrivKey, initiatorPubKey, prologue, staticKeysInitiator, connectionFrom, peerB);
|
const handshakeInitator = new Handshake(true, initPayload, prologue, staticKeysInitiator, connectionFrom, peerB);
|
||||||
|
|
||||||
const { privateKey: responderPrivKey, publicKey: responderPubKey } = getKeyPairFromPeerId(peerB);
|
const respPayload = await getPayload(peerB, staticKeysResponder.publicKey);
|
||||||
const handshakeResponder = new Handshake(false, responderPrivKey, responderPubKey, prologue, staticKeysResponder, connectionTo, fakePeer);
|
const handshakeResponder = new Handshake(false, respPayload, prologue, staticKeysResponder, connectionTo, fakePeer);
|
||||||
|
|
||||||
await handshakeInitator.propose();
|
await handshakeInitator.propose();
|
||||||
await handshakeResponder.propose();
|
await handshakeResponder.propose();
|
||||||
|
@ -3,7 +3,7 @@ import { Noise } from "../src";
|
|||||||
|
|
||||||
describe("Index", () => {
|
describe("Index", () => {
|
||||||
it("should expose class with tag and required functions", () => {
|
it("should expose class with tag and required functions", () => {
|
||||||
const noise = new Noise(Buffer.from("privatekey"));
|
const noise = new Noise();
|
||||||
expect(noise.protocol).to.equal('/noise');
|
expect(noise.protocol).to.equal('/noise');
|
||||||
expect(typeof(noise.secureInbound)).to.equal('function');
|
expect(typeof(noise.secureInbound)).to.equal('function');
|
||||||
expect(typeof(noise.secureOutbound)).to.equal('function');
|
expect(typeof(noise.secureOutbound)).to.equal('function');
|
||||||
|
@ -9,7 +9,7 @@ import {Handshake} from "../src/handshake";
|
|||||||
import {
|
import {
|
||||||
createHandshakePayload,
|
createHandshakePayload,
|
||||||
generateKeypair,
|
generateKeypair,
|
||||||
getHandshakePayload,
|
getHandshakePayload, getPayload,
|
||||||
signPayload
|
signPayload
|
||||||
} from "../src/utils";
|
} from "../src/utils";
|
||||||
import { decodeMessageBuffer, encodeMessageBuffer } from "../src/encoder";
|
import { decodeMessageBuffer, encodeMessageBuffer } from "../src/encoder";
|
||||||
@ -26,10 +26,8 @@ describe("Noise", () => {
|
|||||||
|
|
||||||
it("should communicate through encrypted streams", async() => {
|
it("should communicate through encrypted streams", async() => {
|
||||||
try {
|
try {
|
||||||
const { privateKey: libp2pInitPrivKey } = getKeyPairFromPeerId(localPeer);
|
const noiseInit = new Noise();
|
||||||
const { privateKey: libp2pRespPrivKey } = getKeyPairFromPeerId(remotePeer);
|
const noiseResp = new Noise();
|
||||||
const noiseInit = new Noise(libp2pInitPrivKey);
|
|
||||||
const noiseResp = new Noise(libp2pRespPrivKey);
|
|
||||||
|
|
||||||
const [inboundConnection, outboundConnection] = DuplexPair();
|
const [inboundConnection, outboundConnection] = DuplexPair();
|
||||||
const [outbound, inbound] = await Promise.all([
|
const [outbound, inbound] = await Promise.all([
|
||||||
@ -48,8 +46,7 @@ describe("Noise", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should test that secureOutbound is spec compliant", async() => {
|
it("should test that secureOutbound is spec compliant", async() => {
|
||||||
const { privateKey: libp2pInitPrivKey } = getKeyPairFromPeerId(localPeer);
|
const noiseInit = new Noise();
|
||||||
const noiseInit = new Noise(libp2pInitPrivKey);
|
|
||||||
const [inboundConnection, outboundConnection] = DuplexPair();
|
const [inboundConnection, outboundConnection] = DuplexPair();
|
||||||
|
|
||||||
const [outbound, { wrapped, handshake }] = await Promise.all([
|
const [outbound, { wrapped, handshake }] = await Promise.all([
|
||||||
@ -59,9 +56,9 @@ describe("Noise", () => {
|
|||||||
const prologue = Buffer.from('/noise');
|
const prologue = Buffer.from('/noise');
|
||||||
const staticKeys = generateKeypair();
|
const staticKeys = generateKeypair();
|
||||||
const xx = new XXHandshake();
|
const xx = new XXHandshake();
|
||||||
const { privateKey: libp2pPrivKey, publicKey: libp2pPubKey } = getKeyPairFromPeerId(remotePeer);
|
|
||||||
|
|
||||||
const handshake = new Handshake(false, libp2pPrivKey, libp2pPubKey, prologue, staticKeys, wrapped, localPeer, xx);
|
const payload = await getPayload(remotePeer, staticKeys.publicKey);
|
||||||
|
const handshake = new Handshake(false, payload, prologue, staticKeys, wrapped, localPeer, xx);
|
||||||
|
|
||||||
let receivedMessageBuffer = decodeMessageBuffer((await wrapped.readLP()).slice());
|
let receivedMessageBuffer = decodeMessageBuffer((await wrapped.readLP()).slice());
|
||||||
// The first handshake message contains the initiator's ephemeral public key
|
// The first handshake message contains the initiator's ephemeral public key
|
||||||
@ -69,7 +66,8 @@ describe("Noise", () => {
|
|||||||
xx.recvMessage(handshake.session, receivedMessageBuffer);
|
xx.recvMessage(handshake.session, receivedMessageBuffer);
|
||||||
|
|
||||||
// Stage 1
|
// Stage 1
|
||||||
const signedPayload = signPayload(libp2pPrivKey, getHandshakePayload(staticKeys.publicKey));
|
const { privateKey: libp2pPrivKey, publicKey: libp2pPubKey } = getKeyPairFromPeerId(remotePeer);
|
||||||
|
const signedPayload = await signPayload(remotePeer, getHandshakePayload(staticKeys.publicKey));
|
||||||
const handshakePayload = await createHandshakePayload(libp2pPubKey, libp2pPrivKey, signedPayload);
|
const handshakePayload = await createHandshakePayload(libp2pPubKey, libp2pPrivKey, signedPayload);
|
||||||
|
|
||||||
const messageBuffer = xx.sendMessage(handshake.session, handshakePayload);
|
const messageBuffer = xx.sendMessage(handshake.session, handshakePayload);
|
||||||
@ -101,10 +99,8 @@ describe("Noise", () => {
|
|||||||
|
|
||||||
it("should test large payloads", async() => {
|
it("should test large payloads", async() => {
|
||||||
try {
|
try {
|
||||||
const { privateKey: libp2pInitPrivKey } = getKeyPairFromPeerId(localPeer);
|
const noiseInit = new Noise();
|
||||||
const { privateKey: libp2pRespPrivKey } = getKeyPairFromPeerId(remotePeer);
|
const noiseResp = new Noise();
|
||||||
const noiseInit = new Noise(libp2pInitPrivKey);
|
|
||||||
const noiseResp = new Noise(libp2pRespPrivKey);
|
|
||||||
|
|
||||||
const [inboundConnection, outboundConnection] = DuplexPair();
|
const [inboundConnection, outboundConnection] = DuplexPair();
|
||||||
const [outbound, inbound] = await Promise.all([
|
const [outbound, inbound] = await Promise.all([
|
||||||
|
Reference in New Issue
Block a user