mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-04-26 09:02:20 +00:00
Merge remote-tracking branch 'remotes/origin/master' into morrigan/interface
# Conflicts: # src/xx.ts
This commit is contained in:
commit
9c898043b8
12
.travis.yml
Normal file
12
.travis.yml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
language: node_js
|
||||||
|
|
||||||
|
cache: false
|
||||||
|
|
||||||
|
install:
|
||||||
|
- yarn install --frozen-lockfile --network-timeout 1000000
|
||||||
|
|
||||||
|
script:
|
||||||
|
set -e;
|
||||||
|
yarn run lint;
|
||||||
|
yarn run check-types;
|
||||||
|
yarn run build;
|
52
src/xx.ts
52
src/xx.ts
@ -6,40 +6,39 @@ import { bytes32, uint32, uint64, bytes } from './@types/basic'
|
|||||||
import { KeyPair } from './@types/libp2p'
|
import { KeyPair } from './@types/libp2p'
|
||||||
import { generateKeypair } from './utils';
|
import { generateKeypair } from './utils';
|
||||||
|
|
||||||
|
|
||||||
export interface MessageBuffer {
|
export interface MessageBuffer {
|
||||||
ne: bytes32,
|
ne: bytes32;
|
||||||
ns: bytes,
|
ns: bytes;
|
||||||
ciphertext: bytes
|
ciphertext: bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
type CipherState = {
|
type CipherState = {
|
||||||
k: bytes32,
|
k: bytes32;
|
||||||
n: uint32,
|
n: uint32;
|
||||||
}
|
}
|
||||||
|
|
||||||
type SymmetricState = {
|
type SymmetricState = {
|
||||||
cs: CipherState,
|
cs: CipherState;
|
||||||
ck: bytes32, // chaining key
|
ck: bytes32; // chaining key
|
||||||
h: bytes32, // handshake hash
|
h: bytes32; // handshake hash
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type NoiseSession = {
|
export 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;
|
||||||
}
|
}
|
||||||
export type Hkdf = [bytes, bytes, bytes];
|
export type Hkdf = [bytes, bytes, bytes];
|
||||||
|
|
||||||
@ -164,7 +163,7 @@ export class XXHandshake {
|
|||||||
|
|
||||||
private async hashProtocolName(protocolName: bytes): Promise<bytes32> {
|
private async hashProtocolName(protocolName: bytes): Promise<bytes32> {
|
||||||
if (protocolName.length <= 32) {
|
if (protocolName.length <= 32) {
|
||||||
let h = Buffer.alloc(32);
|
const h = Buffer.alloc(32);
|
||||||
protocolName.copy(h);
|
protocolName.copy(h);
|
||||||
return h;
|
return h;
|
||||||
} else {
|
} else {
|
||||||
@ -225,11 +224,8 @@ export class XXHandshake {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async writeMessageA(hs: HandshakeState, payload: bytes): Promise<MessageBuffer> {
|
private async writeMessageA(hs: HandshakeState, payload: bytes): Promise<MessageBuffer> {
|
||||||
let ns = Buffer.alloc(0);
|
const ns = Buffer.alloc(0);
|
||||||
hs.e = generateKeypair();
|
hs.e = generateKeypair();
|
||||||
if (!hs.e) {
|
|
||||||
throw new Error("Handshake state has keypair missing.");
|
|
||||||
}
|
|
||||||
const ne = hs.e.publicKey;
|
const ne = hs.e.publicKey;
|
||||||
|
|
||||||
this.mixHash(hs.ss, ne);
|
this.mixHash(hs.ss, ne);
|
||||||
@ -240,9 +236,6 @@ export class XXHandshake {
|
|||||||
|
|
||||||
private async writeMessageB(hs: HandshakeState, payload: bytes): Promise<MessageBuffer> {
|
private async writeMessageB(hs: HandshakeState, payload: bytes): Promise<MessageBuffer> {
|
||||||
hs.e = generateKeypair();
|
hs.e = generateKeypair();
|
||||||
if (!hs.e) {
|
|
||||||
throw new Error("Handshake state has keypair missing.");
|
|
||||||
}
|
|
||||||
const ne = hs.e.publicKey;
|
const ne = hs.e.publicKey;
|
||||||
this.mixHash(hs.ss, ne);
|
this.mixHash(hs.ss, ne);
|
||||||
|
|
||||||
@ -277,7 +270,6 @@ export class XXHandshake {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async readMessageA(hs: HandshakeState, message: MessageBuffer): Promise<bytes> {
|
private async readMessageA(hs: HandshakeState, message: MessageBuffer): Promise<bytes> {
|
||||||
console.log("publci key: ", message.ne)
|
|
||||||
if (x25519.publicKeyVerify(message.ne)) {
|
if (x25519.publicKeyVerify(message.ne)) {
|
||||||
hs.re = message.ne;
|
hs.re = message.ne;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user