Move handshake types to separate file

This commit is contained in:
Belma Gutlic 2019-12-24 20:54:45 +01:00
parent e66ee7d677
commit dbbf579288
4 changed files with 44 additions and 38 deletions

39
src/@types/handshake.ts Normal file
View File

@ -0,0 +1,39 @@
import {bytes, bytes32, uint32, uint64} from "./basic";
import {KeyPair} from "./libp2p";
export type Hkdf = [bytes, bytes, bytes];
export interface MessageBuffer {
ne: bytes32;
ns: bytes;
ciphertext: bytes;
}
export type CipherState = {
k: bytes32;
n: uint32;
}
export type SymmetricState = {
cs: CipherState;
ck: bytes32; // chaining key
h: bytes32; // handshake hash
}
export type HandshakeState = {
ss: SymmetricState;
s: KeyPair;
e?: KeyPair;
rs: bytes32;
re: bytes32;
psk: bytes32;
}
export type NoiseSession = {
hs: HandshakeState;
h?: bytes32;
cs1?: CipherState;
cs2?: CipherState;
mc: uint64;
i: boolean;
}

View File

@ -1,6 +1,6 @@
import {Buffer} from "buffer";
import {bytes} from "./@types/basic";
import {MessageBuffer} from "./handshakes/xx";
import {MessageBuffer} from "./@types/handshake";
export const int16BEEncode = (value, target, offset) => {
target = target || Buffer.allocUnsafe(2);

View File

@ -1,8 +1,9 @@
import { Buffer } from "buffer";
import { bytes, bytes32 } from "./@types/basic";
import { NoiseSession, XXHandshake } from "./handshakes/xx";
import { XXHandshake } from "./handshakes/xx";
import { KeyPair, PeerId } from "./@types/libp2p";
import { bytes, bytes32 } from "./@types/basic";
import { NoiseSession } from "./@types/handshake";
import {
createHandshakePayload,
getHandshakePayload,

View File

@ -5,42 +5,8 @@ import { BN } from 'bn.js';
import { bytes32, uint32, uint64, bytes } from '../@types/basic'
import { KeyPair } from '../@types/libp2p'
import { generateKeypair } from '../utils';
import { CipherState, HandshakeState, Hkdf, MessageBuffer, NoiseSession, SymmetricState } from "../@types/handshake";
export interface MessageBuffer {
ne: bytes32;
ns: bytes;
ciphertext: bytes;
}
type CipherState = {
k: bytes32;
n: uint32;
}
type SymmetricState = {
cs: CipherState;
ck: bytes32; // chaining key
h: bytes32; // handshake hash
}
type HandshakeState = {
ss: SymmetricState;
s: KeyPair;
e?: KeyPair;
rs: bytes32;
re: bytes32;
psk: bytes32;
}
export type NoiseSession = {
hs: HandshakeState;
h?: bytes32;
cs1?: CipherState;
cs2?: CipherState;
mc: uint64;
i: boolean;
}
export type Hkdf = [bytes, bytes, bytes];
const minNonce = 0;