Write handshake test

This commit is contained in:
morrigan
2019-11-22 12:52:59 +01:00
parent f5888f6405
commit 7e3c35ed8a
6 changed files with 67 additions and 16 deletions

View File

@ -1,9 +1,10 @@
import { x25519, ed25519 } from 'bcrypto';
import protobuf from "protobufjs";
import { Buffer } from "buffer";
import { KeyPair } from "./@types/libp2p";
import { bytes } from "./@types/basic";
import {Buffer} from "buffer";
import { MessageBuffer } from "./xx";
export async function loadPayloadProto () {
const payloadProtoBuf = await protobuf.load("protos/payload.proto");
@ -58,3 +59,15 @@ function resolveEarlyDataPayload(privateKey?: bytes, earlyData?: bytes) : Object
}
}
export function encodeMessageBuffer(message: MessageBuffer) : bytes {
return Buffer.concat([message.ne, message.ns, message.ciphertext]);
}
export function decodeMessageBuffer(message: bytes) : MessageBuffer {
return {
ne: message.slice(0, 32),
ns: message.slice(32, 80),
ciphertext: message.slice(80, message.length),
}
}