fix return types

This commit is contained in:
Marin Petrunić 2020-02-14 10:10:42 +01:00
parent 87f641f650
commit dbb896c249
No known key found for this signature in database
GPG Key ID: 834D07135E110DA5
3 changed files with 7 additions and 5 deletions

View File

@ -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);

View File

@ -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.');

View File

@ -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);