mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-06-12 08:11:35 +00:00
Merge remote-tracking branch 'remotes/origin/master' into feature/xx-fallback
# Conflicts: # src/handshake-xx.ts # src/noise.ts # src/utils.ts # test/noise.test.ts # test/xx-handshake.test.ts
This commit is contained in:
@ -31,7 +31,7 @@ describe("Index", () => {
|
||||
const initSignedPayload = await libp2pInitKeys.sign(getHandshakePayload(kpInitiator.publicKey));
|
||||
const libp2pInitPrivKey = libp2pInitKeys.marshal().slice(0, 32);
|
||||
const libp2pInitPubKey = libp2pInitKeys.marshal().slice(32, 64);
|
||||
const payloadInitEnc = await createHandshakePayload(libp2pInitPubKey, libp2pInitPrivKey, initSignedPayload);
|
||||
const payloadInitEnc = await createHandshakePayload(libp2pInitPubKey, initSignedPayload);
|
||||
|
||||
// initiator sends message
|
||||
const message = Buffer.concat([Buffer.alloc(0), payloadInitEnc]);
|
||||
@ -48,7 +48,7 @@ describe("Index", () => {
|
||||
const libp2pRespPrivKey = libp2pRespKeys.marshal().slice(0, 32);
|
||||
const libp2pRespPubKey = libp2pRespKeys.marshal().slice(32, 64);
|
||||
const respSignedPayload = await libp2pRespKeys.sign(getHandshakePayload(kpResponder.publicKey));
|
||||
const payloadRespEnc = await createHandshakePayload(libp2pRespPubKey, libp2pRespPrivKey, respSignedPayload);
|
||||
const payloadRespEnc = await createHandshakePayload(libp2pRespPubKey, respSignedPayload);
|
||||
|
||||
const message1 = Buffer.concat([message, payloadRespEnc]);
|
||||
const messageBuffer2 = ikR.sendMessage(responderSession, message1);
|
||||
|
@ -58,7 +58,7 @@ describe("Index", () => {
|
||||
const libp2pInitPrivKey = libp2pInitKeys.marshal().slice(0, 32);
|
||||
const libp2pInitPubKey = libp2pInitKeys.marshal().slice(32, 64);
|
||||
|
||||
const payloadInitEnc = await createHandshakePayload(libp2pInitPubKey, libp2pInitPrivKey, initSignedPayload);
|
||||
const payloadInitEnc = await createHandshakePayload(libp2pInitPubKey, initSignedPayload);
|
||||
|
||||
// initiator sends message
|
||||
const message = Buffer.concat([Buffer.alloc(0), payloadInitEnc]);
|
||||
@ -75,7 +75,7 @@ describe("Index", () => {
|
||||
// responder creates payload
|
||||
const libp2pRespPrivKey = libp2pRespKeys.marshal().slice(0, 32);
|
||||
const libp2pRespPubKey = libp2pRespKeys.marshal().slice(32, 64);
|
||||
const payloadRespEnc = await createHandshakePayload(libp2pRespPubKey, libp2pRespPrivKey, respSignedPayload);
|
||||
const payloadRespEnc = await createHandshakePayload(libp2pRespPubKey, respSignedPayload);
|
||||
|
||||
const message1 = Buffer.concat([message, payloadRespEnc]);
|
||||
const messageBuffer2 = xx.sendMessage(nsResp, message1);
|
||||
|
@ -3,7 +3,7 @@ import { Noise } from "../src";
|
||||
|
||||
describe("Index", () => {
|
||||
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(typeof(noise.secureInbound)).to.equal('function');
|
||||
expect(typeof(noise.secureOutbound)).to.equal('function');
|
||||
|
@ -9,7 +9,7 @@ import {XXHandshake} from "../src/handshake-xx";
|
||||
import {
|
||||
createHandshakePayload,
|
||||
generateKeypair,
|
||||
getHandshakePayload,
|
||||
getHandshakePayload, getPayload,
|
||||
signPayload
|
||||
} from "../src/utils";
|
||||
import {decode0, decode1, encode1} from "../src/encoder";
|
||||
@ -26,10 +26,8 @@ describe("Noise", () => {
|
||||
|
||||
it("should communicate through encrypted streams", async() => {
|
||||
try {
|
||||
const { privateKey: libp2pInitPrivKey } = getKeyPairFromPeerId(localPeer);
|
||||
const { privateKey: libp2pRespPrivKey } = getKeyPairFromPeerId(remotePeer);
|
||||
const noiseInit = new Noise(libp2pInitPrivKey);
|
||||
const noiseResp = new Noise(libp2pRespPrivKey);
|
||||
const noiseInit = new Noise();
|
||||
const noiseResp = new Noise();
|
||||
|
||||
const [inboundConnection, outboundConnection] = DuplexPair();
|
||||
const [outbound, inbound] = await Promise.all([
|
||||
@ -48,8 +46,7 @@ describe("Noise", () => {
|
||||
});
|
||||
|
||||
it("should test that secureOutbound is spec compliant", async() => {
|
||||
const { privateKey: libp2pInitPrivKey } = getKeyPairFromPeerId(localPeer);
|
||||
const noiseInit = new Noise(libp2pInitPrivKey);
|
||||
const noiseInit = new Noise();
|
||||
const [inboundConnection, outboundConnection] = DuplexPair();
|
||||
|
||||
const [outbound, { wrapped, handshake }] = await Promise.all([
|
||||
@ -59,9 +56,10 @@ describe("Noise", () => {
|
||||
const prologue = Buffer.from('/noise');
|
||||
const staticKeys = generateKeypair();
|
||||
const xx = new XX();
|
||||
const { privateKey: libp2pPrivKey, publicKey: libp2pPubKey } = getKeyPairFromPeerId(remotePeer);
|
||||
|
||||
const handshake = new XXHandshake(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 = decode0((await wrapped.readLP()).slice());
|
||||
// The first handshake message contains the initiator's ephemeral public key
|
||||
@ -69,7 +67,8 @@ describe("Noise", () => {
|
||||
xx.recvMessage(handshake.session, receivedMessageBuffer);
|
||||
|
||||
// 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 messageBuffer = xx.sendMessage(handshake.session, handshakePayload);
|
||||
@ -101,10 +100,8 @@ describe("Noise", () => {
|
||||
|
||||
it("should test large payloads", async() => {
|
||||
try {
|
||||
const { privateKey: libp2pInitPrivKey } = getKeyPairFromPeerId(localPeer);
|
||||
const { privateKey: libp2pRespPrivKey } = getKeyPairFromPeerId(remotePeer);
|
||||
const noiseInit = new Noise(libp2pInitPrivKey);
|
||||
const noiseResp = new Noise(libp2pRespPrivKey);
|
||||
const noiseInit = new Noise();
|
||||
const noiseResp = new Noise();
|
||||
|
||||
const [inboundConnection, outboundConnection] = DuplexPair();
|
||||
const [outbound, inbound] = await Promise.all([
|
||||
|
@ -1,6 +1,5 @@
|
||||
import * as crypto from 'libp2p-crypto';
|
||||
import {KeyPair, PeerId} from "../src/@types/libp2p";
|
||||
import {bytes} from "../src/@types/basic";
|
||||
|
||||
export async function generateEd25519Keys() {
|
||||
return await crypto.keys.generateKeyPair('ed25519');
|
||||
|
@ -26,11 +26,11 @@ describe("XX Handshake", () => {
|
||||
const staticKeysInitiator = generateKeypair();
|
||||
const staticKeysResponder = generateKeypair();
|
||||
|
||||
const { privateKey: initiatorPrivKey, publicKey: initiatorPubKey } = getKeyPairFromPeerId(peerA);
|
||||
const handshakeInitator = new XXHandshake(true, initiatorPrivKey, initiatorPubKey, prologue, staticKeysInitiator, connectionFrom, peerB);
|
||||
const initPayload = await getPayload(peerA, staticKeysInitiator.publicKey);
|
||||
const handshakeInitator = new XXHandshake(true, initPayload, prologue, staticKeysInitiator, connectionFrom, peerB);
|
||||
|
||||
const { privateKey: responderPrivKey, publicKey: responderPubKey } = getKeyPairFromPeerId(peerB);
|
||||
const handshakeResponder = new XXHandshake(false, responderPrivKey, responderPubKey, prologue, staticKeysResponder, connectionTo, peerA);
|
||||
const respPayload = await getPayload(peerB, staticKeysResponder.publicKey);
|
||||
const handshakeResponder = new XXHandshake(false, respPayload, prologue, staticKeysResponder, connectionTo, peerA);
|
||||
|
||||
await handshakeInitator.propose();
|
||||
await handshakeResponder.propose();
|
||||
@ -71,11 +71,11 @@ describe("XX Handshake", () => {
|
||||
const staticKeysInitiator = generateKeypair();
|
||||
const staticKeysResponder = generateKeypair();
|
||||
|
||||
const { privateKey: initiatorPrivKey, publicKey: initiatorPubKey } = getKeyPairFromPeerId(peerA);
|
||||
const handshakeInitator = new XXHandshake(true, initiatorPrivKey, initiatorPubKey, prologue, staticKeysInitiator, connectionFrom, fakePeer);
|
||||
const initPayload = await getPayload(peerA, staticKeysInitiator.publicKey);
|
||||
const handshakeInitator = new XXHandshake(true, initPayload, prologue, staticKeysInitiator, connectionFrom, fakePeer);
|
||||
|
||||
const { privateKey: responderPrivKey, publicKey: responderPubKey } = getKeyPairFromPeerId(peerB);
|
||||
const handshakeResponder = new XXHandshake(false, responderPrivKey, responderPubKey, prologue, staticKeysResponder, connectionTo, peerA);
|
||||
const respPayload = await getPayload(peerB, staticKeysResponder.publicKey);
|
||||
const handshakeResponder = new XXHandshake(false, respPayload, prologue, staticKeysResponder, connectionTo, peerA);
|
||||
|
||||
await handshakeInitator.propose();
|
||||
await handshakeResponder.propose();
|
||||
@ -99,11 +99,11 @@ describe("XX Handshake", () => {
|
||||
const staticKeysInitiator = generateKeypair();
|
||||
const staticKeysResponder = generateKeypair();
|
||||
|
||||
const { privateKey: initiatorPrivKey, publicKey: initiatorPubKey } = getKeyPairFromPeerId(peerA);
|
||||
const handshakeInitator = new XXHandshake(true, initiatorPrivKey, initiatorPubKey, prologue, staticKeysInitiator, connectionFrom, peerB);
|
||||
const initPayload = await getPayload(peerA, staticKeysInitiator.publicKey);
|
||||
const handshakeInitator = new XXHandshake(true, initPayload, prologue, staticKeysInitiator, connectionFrom, peerB);
|
||||
|
||||
const { privateKey: responderPrivKey, publicKey: responderPubKey } = getKeyPairFromPeerId(peerB);
|
||||
const handshakeResponder = new XXHandshake(false, responderPrivKey, responderPubKey, prologue, staticKeysResponder, connectionTo, fakePeer);
|
||||
const respPayload = await getPayload(peerB, staticKeysResponder.publicKey);
|
||||
const handshakeResponder = new XXHandshake(false, respPayload, prologue, staticKeysResponder, connectionTo, fakePeer);
|
||||
|
||||
await handshakeInitator.propose();
|
||||
await handshakeResponder.propose();
|
||||
|
Reference in New Issue
Block a user