mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-04-25 17:32:25 +00:00
fix return types
This commit is contained in:
parent
87f641f650
commit
dbb896c249
@ -54,7 +54,7 @@ export class IKHandshake implements IHandshake {
|
||||
logger("IK Stage 0 - Responder receiving message...");
|
||||
const receivedMsg = await this.connection.readLP();
|
||||
try {
|
||||
const receivedMessageBuffer = decode1(receivedMsg);
|
||||
const receivedMessageBuffer = decode1(receivedMsg.slice());
|
||||
const plaintext = this.ik.recvMessage(this.session, receivedMessageBuffer);
|
||||
logger("IK Stage 0 - Responder got message, going to verify payload.");
|
||||
const decodedPayload = await decodePayload(plaintext);
|
||||
|
@ -57,7 +57,7 @@ export class XXHandshake implements IHandshake {
|
||||
logger("Stage 0 - Initiator finished sending first message.");
|
||||
} else {
|
||||
logger("Stage 0 - Responder waiting to receive first message...");
|
||||
const receivedMessageBuffer = decode0(await this.connection.readLP());
|
||||
const receivedMessageBuffer = decode0((await this.connection.readLP()).slice());
|
||||
this.xx.recvMessage(this.session, receivedMessageBuffer);
|
||||
logger("Stage 0 - Responder received first message.");
|
||||
}
|
||||
@ -67,7 +67,7 @@ export class XXHandshake implements IHandshake {
|
||||
public async exchange(): Promise<void> {
|
||||
if (this.isInitiator) {
|
||||
logger('Stage 1 - Initiator waiting to receive first message from responder...');
|
||||
const receivedMessageBuffer = decode1(await this.connection.readLP());
|
||||
const receivedMessageBuffer = decode1((await this.connection.readLP()).slice());
|
||||
const plaintext = this.xx.recvMessage(this.session, receivedMessageBuffer);
|
||||
logger('Stage 1 - Initiator received the message. Got remote\'s static key.');
|
||||
|
||||
@ -97,7 +97,7 @@ export class XXHandshake implements IHandshake {
|
||||
logger('Stage 2 - Initiator sent message with signed payload.');
|
||||
} else {
|
||||
logger('Stage 2 - Responder waiting for third handshake message...');
|
||||
const receivedMessageBuffer = decode1(await this.connection.readLP());
|
||||
const receivedMessageBuffer = decode1((await this.connection.readLP()).slice());
|
||||
const plaintext = this.xx.recvMessage(this.session, receivedMessageBuffer);
|
||||
logger('Stage 2 - Responder received the message, finished handshake. Got remote\'s static key.');
|
||||
|
||||
|
@ -74,7 +74,9 @@ export async function decodePayload(payload: bytes): Promise<INoisePayload> {
|
||||
) as INoisePayload;
|
||||
}
|
||||
|
||||
export const getHandshakePayload = (publicKey: bytes ) => Buffer.concat([Buffer.from("noise-libp2p-static-key:"), publicKey]);
|
||||
export function getHandshakePayload(publicKey: bytes): bytes {
|
||||
return Buffer.concat([Buffer.from("noise-libp2p-static-key:"), publicKey]);
|
||||
}
|
||||
|
||||
async function isValidPeerId(peerId: bytes, publicKeyProtobuf: bytes) {
|
||||
const generatedPeerId = await PeerId.createFromPubKey(publicKeyProtobuf);
|
||||
|
Loading…
x
Reference in New Issue
Block a user