update waku

This commit is contained in:
weboko 2023-04-04 01:02:07 +02:00
parent 9136800038
commit 96e4b46c42
No known key found for this signature in database
4 changed files with 1126 additions and 508 deletions

1598
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -59,7 +59,7 @@
"@types/uuid": "^8.3.0",
"@typescript-eslint/eslint-plugin": "^5.8.1",
"@typescript-eslint/parser": "^5.8.1",
"@waku/interfaces": "^0.0.7",
"@waku/interfaces": "0.0.11",
"app-root-path": "^3.0.0",
"chai": "^4.3.4",
"cspell": "^5.14.0",
@ -121,8 +121,8 @@
"@stablelib/random": "^1.0.2",
"@stablelib/sha256": "^1.0.1",
"@stablelib/x25519": "^1.0.1",
"@waku/core": "^0.0.10",
"@waku/proto": "^0.0.2",
"@waku/core": "0.0.16",
"@waku/proto": "0.0.4",
"bn.js": "^5.2.1",
"eventemitter3": "^5.0.0",
"p-event": "^5.0.1",

View File

@ -1,4 +1,4 @@
import { DecodedMessage } from "@waku/core";
import { DecodedMessage } from "@waku/core/lib/message/version_0";
import type { IDecodedMessage, IDecoder, IEncoder, IMessage, IProtoMessage } from "@waku/interfaces";
import { WakuMessage } from "@waku/proto";
import debug from "debug";
@ -52,6 +52,7 @@ export class NoiseHandshakeEncoder implements IEncoder {
rateLimitProof: undefined,
payload: this.hsStepResult.payload2.serialize(),
version: version,
meta: undefined,
contentTopic: this.contentTopic,
timestamp: BigInt(timestamp.valueOf()) * OneMillion,
};
@ -74,7 +75,7 @@ export class NoiseHandshakeDecoder implements IDecoder<NoiseHandshakeMessage> {
return Promise.resolve(protoMessage as IProtoMessage);
}
async fromProtoObj(proto: IProtoMessage): Promise<NoiseHandshakeMessage | undefined> {
async fromProtoObj(pubSubTopic: string, proto: IProtoMessage): Promise<NoiseHandshakeMessage | undefined> {
// https://github.com/status-im/js-waku/issues/921
if (proto.version === undefined) {
proto.version = 0;
@ -90,7 +91,7 @@ export class NoiseHandshakeDecoder implements IDecoder<NoiseHandshakeMessage> {
return;
}
return new NoiseHandshakeMessage(proto);
return new NoiseHandshakeMessage(pubSubTopic, proto);
}
}
@ -101,8 +102,8 @@ export class NoiseHandshakeDecoder implements IDecoder<NoiseHandshakeMessage> {
export class NoiseSecureMessage extends DecodedMessage implements IDecodedMessage {
private readonly _decodedPayload: Uint8Array;
constructor(proto: WakuMessage, decodedPayload: Uint8Array) {
super(proto);
constructor(pubSubTopic: string, proto: WakuMessage, decodedPayload: Uint8Array) {
super(pubSubTopic, proto);
this._decodedPayload = decodedPayload;
}
@ -146,6 +147,7 @@ export class NoiseSecureTransferEncoder implements IEncoder {
rateLimitProof: undefined,
ephemeral: this.ephemeral,
version: version,
meta: undefined,
contentTopic: this.contentTopic,
timestamp: BigInt(timestamp.valueOf()) * OneMillion,
};
@ -171,7 +173,7 @@ export class NoiseSecureTransferDecoder implements IDecoder<NoiseSecureMessage>
return Promise.resolve(protoMessage as IProtoMessage);
}
async fromProtoObj(proto: IProtoMessage): Promise<NoiseSecureMessage | undefined> {
async fromProtoObj(pubSubTopic: string, proto: IProtoMessage): Promise<NoiseSecureMessage | undefined> {
// https://github.com/status-im/js-waku/issues/921
if (proto.version === undefined) {
proto.version = 0;
@ -187,7 +189,7 @@ export class NoiseSecureTransferDecoder implements IDecoder<NoiseSecureMessage>
try {
const payloadV2 = PayloadV2.deserialize(proto.payload);
const decryptedPayload = this.hsResult.readMessage(payloadV2);
return new NoiseSecureMessage(proto, decryptedPayload);
return new NoiseSecureMessage(pubSubTopic, proto, decryptedPayload);
} catch (err) {
log("could not decode message ", err);
return;

View File

@ -32,7 +32,7 @@ export interface Sender {
* @param encoder NoiseHandshakeEncoder encoder to use to encrypt the messages
* @param msg message to broadcast
*/
publish(encoder: IEncoder, msg: IMessage): Promise<void>;
send(encoder: IEncoder, msg: IMessage): Promise<void>;
}
/**
@ -258,7 +258,9 @@ export class WakuPairing {
// We prepare a message from initiator's payload2
// At this point wakuMsg is sent over the Waku network to responder content topic
let encoder = new NoiseHandshakeEncoder(this.contentTopic, hsStep);
await this.sender.publish(encoder, {});
await this.sender.send(encoder, {
payload: new Uint8Array(),
});
// We generate an authorization code using the handshake state
// this check has to be confirmed with a user interaction, comparing auth codes in both ends
@ -294,7 +296,9 @@ export class WakuPairing {
});
encoder = new NoiseHandshakeEncoder(this.contentTopic, hsStep);
await this.sender.publish(encoder, {});
await this.sender.send(encoder, {
payload: new Uint8Array(),
});
// Secure Transfer Phase
this.handshakeResult = this.handshake.finalizeHandshake();
@ -333,7 +337,9 @@ export class WakuPairing {
// We prepare a Waku message from responder's payload2
const encoder = new NoiseHandshakeEncoder(this.contentTopic, hsStep);
await this.sender.publish(encoder, {});
await this.sender.send(encoder, {
payload: new Uint8Array(),
});
// 3rd step
// -> sA, sAeB, sAsB {s}