mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-06-15 14:11:26 +00:00
Address PR comments
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "js-libp2p-noise",
|
"name": "js-libp2p-noise",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"main": "index",
|
"main": "dist/index.js",
|
||||||
"repository": "git@github.com:NodeFactoryIo/js-libp2p-noise.git",
|
"repository": "git@github.com:NodeFactoryIo/js-libp2p-noise.git",
|
||||||
"author": "NodeFactory <info@nodefactory.io>",
|
"author": "NodeFactory <info@nodefactory.io>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
36
src/xx.ts
36
src/xx.ts
@ -28,17 +28,17 @@ type SymmetricState = {
|
|||||||
type HandshakeState = {
|
type HandshakeState = {
|
||||||
ss: SymmetricState,
|
ss: SymmetricState,
|
||||||
s: KeyPair,
|
s: KeyPair,
|
||||||
e: KeyPair,
|
e?: KeyPair,
|
||||||
rs: bytes32,
|
rs: bytes32,
|
||||||
re: bytes32,
|
re?: bytes32,
|
||||||
psk: bytes32,
|
psk: bytes32,
|
||||||
}
|
}
|
||||||
|
|
||||||
type NoiseSession = {
|
type NoiseSession = {
|
||||||
hs: HandshakeState,
|
hs: HandshakeState,
|
||||||
h: bytes32,
|
h?: bytes32,
|
||||||
cs1: CipherState,
|
cs1?: CipherState,
|
||||||
cs2: CipherState,
|
cs2?: CipherState,
|
||||||
mc: uint64,
|
mc: uint64,
|
||||||
i: boolean,
|
i: boolean,
|
||||||
}
|
}
|
||||||
@ -51,25 +51,19 @@ export class XXHandshake {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async initializeInitiator(prologue: bytes32, s: KeyPair, rs: bytes32, psk: bytes32) : Promise<HandshakeState> {
|
private async initializeInitiator(prologue: bytes32, s: KeyPair, rs: bytes32, psk: bytes32) : Promise<HandshakeState> {
|
||||||
let e: KeyPair;
|
|
||||||
let re: bytes32;
|
|
||||||
const name = "Noise_XX_25519_ChaChaPoly_SHA256";
|
const name = "Noise_XX_25519_ChaChaPoly_SHA256";
|
||||||
const ss = await this.initializeSymmetric(name);
|
const ss = await this.initializeSymmetric(name);
|
||||||
await this.mixHash(ss, prologue);
|
await this.mixHash(ss, prologue);
|
||||||
|
|
||||||
// @ts-ignore-next-line
|
return { ss, s, rs, psk };
|
||||||
return {ss, s, e, rs, re, psk};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async initializeResponder(prologue: bytes32, s: KeyPair, rs: bytes32, psk: bytes32) : Promise<HandshakeState> {
|
private async initializeResponder(prologue: bytes32, s: KeyPair, rs: bytes32, psk: bytes32) : Promise<HandshakeState> {
|
||||||
let e: KeyPair;
|
|
||||||
let re: bytes32;
|
|
||||||
const name = "Noise_XX_25519_ChaChaPoly_SHA256";
|
const name = "Noise_XX_25519_ChaChaPoly_SHA256";
|
||||||
const ss = await this.initializeSymmetric(name);
|
const ss = await this.initializeSymmetric(name);
|
||||||
await this.mixHash(ss, prologue);
|
await this.mixHash(ss, prologue);
|
||||||
|
|
||||||
// @ts-ignore-next-line
|
return { ss, s, rs, psk };
|
||||||
return {ss, s, e, rs, re, psk};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private incrementNonce(n: uint32) : uint32 {
|
private incrementNonce(n: uint32) : uint32 {
|
||||||
@ -257,20 +251,20 @@ export class XXHandshake {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async initSession(initiator: boolean, prologue: bytes32, s: KeyPair, rs: bytes32) : Promise<NoiseSession> {
|
public async initSession(initiator: boolean, prologue: bytes32, s: KeyPair, rs: bytes32) : Promise<NoiseSession> {
|
||||||
// TODO: Create noisesession object/class
|
|
||||||
// @ts-ignore-next-line
|
|
||||||
let session: NoiseSession = {};
|
|
||||||
const psk = this.createEmptyKey();
|
const psk = this.createEmptyKey();
|
||||||
|
let hs;
|
||||||
|
|
||||||
if (initiator) {
|
if (initiator) {
|
||||||
session.hs = await this.initializeInitiator(prologue, s, rs, psk);
|
hs = await this.initializeInitiator(prologue, s, rs, psk);
|
||||||
} else {
|
} else {
|
||||||
session.hs = await this.initializeResponder(prologue, s, rs, psk);
|
hs = await this.initializeResponder(prologue, s, rs, psk);
|
||||||
}
|
}
|
||||||
|
|
||||||
session.i = initiator;
|
return {
|
||||||
session.mc = 0;
|
hs,
|
||||||
return session;
|
i: initiator,
|
||||||
|
mc: 0
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendMessage(session: NoiseSession, message: bytes) : Promise<MessageBuffer> {
|
public async sendMessage(session: NoiseSession, message: bytes) : Promise<MessageBuffer> {
|
||||||
|
@ -6,12 +6,12 @@
|
|||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"noImplicitAny": false,
|
"noImplicitAny": false,
|
||||||
"typeRoots": [
|
"typeRoots": [
|
||||||
"./node_modules/@types"
|
"./node_modules/@types",
|
||||||
|
"./node_modules/bn.js-typings/index.d.ts"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"**/src/**/*.ts",
|
"**/src/**/*.ts"
|
||||||
"./node_modules/bn.js-typings/index.d.ts"
|
|
||||||
],
|
],
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"node_modules"
|
"node_modules"
|
||||||
|
Reference in New Issue
Block a user