mirror of
https://github.com/logos-messaging/js-noise.git
synced 2026-01-02 13:43:08 +00:00
update waku
This commit is contained in:
parent
9136800038
commit
96e4b46c42
1598
package-lock.json
generated
1598
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -59,7 +59,7 @@
|
|||||||
"@types/uuid": "^8.3.0",
|
"@types/uuid": "^8.3.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.8.1",
|
"@typescript-eslint/eslint-plugin": "^5.8.1",
|
||||||
"@typescript-eslint/parser": "^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",
|
"app-root-path": "^3.0.0",
|
||||||
"chai": "^4.3.4",
|
"chai": "^4.3.4",
|
||||||
"cspell": "^5.14.0",
|
"cspell": "^5.14.0",
|
||||||
@ -121,8 +121,8 @@
|
|||||||
"@stablelib/random": "^1.0.2",
|
"@stablelib/random": "^1.0.2",
|
||||||
"@stablelib/sha256": "^1.0.1",
|
"@stablelib/sha256": "^1.0.1",
|
||||||
"@stablelib/x25519": "^1.0.1",
|
"@stablelib/x25519": "^1.0.1",
|
||||||
"@waku/core": "^0.0.10",
|
"@waku/core": "0.0.16",
|
||||||
"@waku/proto": "^0.0.2",
|
"@waku/proto": "0.0.4",
|
||||||
"bn.js": "^5.2.1",
|
"bn.js": "^5.2.1",
|
||||||
"eventemitter3": "^5.0.0",
|
"eventemitter3": "^5.0.0",
|
||||||
"p-event": "^5.0.1",
|
"p-event": "^5.0.1",
|
||||||
|
|||||||
16
src/codec.ts
16
src/codec.ts
@ -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 type { IDecodedMessage, IDecoder, IEncoder, IMessage, IProtoMessage } from "@waku/interfaces";
|
||||||
import { WakuMessage } from "@waku/proto";
|
import { WakuMessage } from "@waku/proto";
|
||||||
import debug from "debug";
|
import debug from "debug";
|
||||||
@ -52,6 +52,7 @@ export class NoiseHandshakeEncoder implements IEncoder {
|
|||||||
rateLimitProof: undefined,
|
rateLimitProof: undefined,
|
||||||
payload: this.hsStepResult.payload2.serialize(),
|
payload: this.hsStepResult.payload2.serialize(),
|
||||||
version: version,
|
version: version,
|
||||||
|
meta: undefined,
|
||||||
contentTopic: this.contentTopic,
|
contentTopic: this.contentTopic,
|
||||||
timestamp: BigInt(timestamp.valueOf()) * OneMillion,
|
timestamp: BigInt(timestamp.valueOf()) * OneMillion,
|
||||||
};
|
};
|
||||||
@ -74,7 +75,7 @@ export class NoiseHandshakeDecoder implements IDecoder<NoiseHandshakeMessage> {
|
|||||||
return Promise.resolve(protoMessage as IProtoMessage);
|
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
|
// https://github.com/status-im/js-waku/issues/921
|
||||||
if (proto.version === undefined) {
|
if (proto.version === undefined) {
|
||||||
proto.version = 0;
|
proto.version = 0;
|
||||||
@ -90,7 +91,7 @@ export class NoiseHandshakeDecoder implements IDecoder<NoiseHandshakeMessage> {
|
|||||||
return;
|
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 {
|
export class NoiseSecureMessage extends DecodedMessage implements IDecodedMessage {
|
||||||
private readonly _decodedPayload: Uint8Array;
|
private readonly _decodedPayload: Uint8Array;
|
||||||
|
|
||||||
constructor(proto: WakuMessage, decodedPayload: Uint8Array) {
|
constructor(pubSubTopic: string, proto: WakuMessage, decodedPayload: Uint8Array) {
|
||||||
super(proto);
|
super(pubSubTopic, proto);
|
||||||
this._decodedPayload = decodedPayload;
|
this._decodedPayload = decodedPayload;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,6 +147,7 @@ export class NoiseSecureTransferEncoder implements IEncoder {
|
|||||||
rateLimitProof: undefined,
|
rateLimitProof: undefined,
|
||||||
ephemeral: this.ephemeral,
|
ephemeral: this.ephemeral,
|
||||||
version: version,
|
version: version,
|
||||||
|
meta: undefined,
|
||||||
contentTopic: this.contentTopic,
|
contentTopic: this.contentTopic,
|
||||||
timestamp: BigInt(timestamp.valueOf()) * OneMillion,
|
timestamp: BigInt(timestamp.valueOf()) * OneMillion,
|
||||||
};
|
};
|
||||||
@ -171,7 +173,7 @@ export class NoiseSecureTransferDecoder implements IDecoder<NoiseSecureMessage>
|
|||||||
return Promise.resolve(protoMessage as IProtoMessage);
|
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
|
// https://github.com/status-im/js-waku/issues/921
|
||||||
if (proto.version === undefined) {
|
if (proto.version === undefined) {
|
||||||
proto.version = 0;
|
proto.version = 0;
|
||||||
@ -187,7 +189,7 @@ export class NoiseSecureTransferDecoder implements IDecoder<NoiseSecureMessage>
|
|||||||
try {
|
try {
|
||||||
const payloadV2 = PayloadV2.deserialize(proto.payload);
|
const payloadV2 = PayloadV2.deserialize(proto.payload);
|
||||||
const decryptedPayload = this.hsResult.readMessage(payloadV2);
|
const decryptedPayload = this.hsResult.readMessage(payloadV2);
|
||||||
return new NoiseSecureMessage(proto, decryptedPayload);
|
return new NoiseSecureMessage(pubSubTopic, proto, decryptedPayload);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log("could not decode message ", err);
|
log("could not decode message ", err);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -32,7 +32,7 @@ export interface Sender {
|
|||||||
* @param encoder NoiseHandshakeEncoder encoder to use to encrypt the messages
|
* @param encoder NoiseHandshakeEncoder encoder to use to encrypt the messages
|
||||||
* @param msg message to broadcast
|
* @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
|
// We prepare a message from initiator's payload2
|
||||||
// At this point wakuMsg is sent over the Waku network to responder content topic
|
// At this point wakuMsg is sent over the Waku network to responder content topic
|
||||||
let encoder = new NoiseHandshakeEncoder(this.contentTopic, hsStep);
|
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
|
// 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
|
// 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);
|
encoder = new NoiseHandshakeEncoder(this.contentTopic, hsStep);
|
||||||
await this.sender.publish(encoder, {});
|
await this.sender.send(encoder, {
|
||||||
|
payload: new Uint8Array(),
|
||||||
|
});
|
||||||
|
|
||||||
// Secure Transfer Phase
|
// Secure Transfer Phase
|
||||||
this.handshakeResult = this.handshake.finalizeHandshake();
|
this.handshakeResult = this.handshake.finalizeHandshake();
|
||||||
@ -333,7 +337,9 @@ export class WakuPairing {
|
|||||||
|
|
||||||
// We prepare a Waku message from responder's payload2
|
// We prepare a Waku message from responder's payload2
|
||||||
const encoder = new NoiseHandshakeEncoder(this.contentTopic, hsStep);
|
const encoder = new NoiseHandshakeEncoder(this.contentTopic, hsStep);
|
||||||
await this.sender.publish(encoder, {});
|
await this.sender.send(encoder, {
|
||||||
|
payload: new Uint8Array(),
|
||||||
|
});
|
||||||
|
|
||||||
// 3rd step
|
// 3rd step
|
||||||
// -> sA, sAeB, sAsB {s}
|
// -> sA, sAeB, sAsB {s}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user