mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-06-17 20:31:27 +00:00
Write handshake test
This commit is contained in:
15
src/utils.ts
15
src/utils.ts
@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user