@waku/message-encryption 0.0.21 → 0.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/bundle/ecies.js +1 -1
- package/bundle/index-fd9d08d6.js +25311 -0
- package/bundle/index.js +1 -1
- package/bundle/symmetric.js +1 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/decoded_message.d.ts +1 -1
- package/dist/decoded_message.js +2 -2
- package/dist/ecies.d.ts +10 -10
- package/dist/ecies.js +15 -13
- package/dist/ecies.js.map +1 -1
- package/dist/symmetric.d.ts +9 -10
- package/dist/symmetric.js +14 -13
- package/dist/symmetric.js.map +1 -1
- package/package.json +8 -18
- package/src/decoded_message.ts +2 -2
- package/src/ecies.ts +15 -10
- package/src/symmetric.ts +22 -11
- package/bundle/index-f743130b.js +0 -8755
package/dist/symmetric.js
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import { DefaultPubSubTopic } from "@waku/core";
|
1
2
|
import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
|
2
3
|
import { WakuMessage } from "@waku/proto";
|
3
4
|
import debug from "debug";
|
@@ -7,12 +8,14 @@ import { generateSymmetricKey, OneMillion, Version } from "./index.js";
|
|
7
8
|
export { generateSymmetricKey };
|
8
9
|
const log = debug("waku:message-encryption:symmetric");
|
9
10
|
class Encoder {
|
11
|
+
pubsubTopic;
|
10
12
|
contentTopic;
|
11
13
|
symKey;
|
12
14
|
sigPrivKey;
|
13
15
|
ephemeral;
|
14
16
|
metaSetter;
|
15
|
-
constructor(contentTopic, symKey, sigPrivKey, ephemeral = false, metaSetter) {
|
17
|
+
constructor(pubsubTopic, contentTopic, symKey, sigPrivKey, ephemeral = false, metaSetter) {
|
18
|
+
this.pubsubTopic = pubsubTopic;
|
16
19
|
this.contentTopic = contentTopic;
|
17
20
|
this.symKey = symKey;
|
18
21
|
this.sigPrivKey = sigPrivKey;
|
@@ -54,23 +57,22 @@ class Encoder {
|
|
54
57
|
*
|
55
58
|
* An encoder is used to encode messages in the [`14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
|
56
59
|
* format to be sent over the Waku network. The resulting encoder can then be
|
57
|
-
* pass to { @link @waku/interfaces.
|
58
|
-
* { @link @waku/interfaces.Relay.send } to automatically encrypt
|
60
|
+
* pass to { @link @waku/interfaces!ISender.send } to automatically encrypt
|
59
61
|
* and encode outgoing messages.
|
60
62
|
*
|
61
63
|
* The payload can optionally be signed with the given private key as defined
|
62
64
|
* in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
|
63
65
|
*/
|
64
|
-
export function createEncoder({ contentTopic, symKey, sigPrivKey, ephemeral = false, metaSetter }) {
|
65
|
-
return new Encoder(contentTopic, symKey, sigPrivKey, ephemeral, metaSetter);
|
66
|
+
export function createEncoder({ pubsubTopic = DefaultPubSubTopic, contentTopic, symKey, sigPrivKey, ephemeral = false, metaSetter }) {
|
67
|
+
return new Encoder(pubsubTopic, contentTopic, symKey, sigPrivKey, ephemeral, metaSetter);
|
66
68
|
}
|
67
69
|
class Decoder extends DecoderV0 {
|
68
70
|
symKey;
|
69
|
-
constructor(contentTopic, symKey) {
|
70
|
-
super(contentTopic);
|
71
|
+
constructor(pubsubTopic, contentTopic, symKey) {
|
72
|
+
super(pubsubTopic, contentTopic);
|
71
73
|
this.symKey = symKey;
|
72
74
|
}
|
73
|
-
async fromProtoObj(
|
75
|
+
async fromProtoObj(pubsubTopic, protoMessage) {
|
74
76
|
const cipherPayload = protoMessage.payload;
|
75
77
|
if (protoMessage.version !== Version) {
|
76
78
|
log("Failed to decrypt due to incorrect version, expected:", Version, ", actual:", protoMessage.version);
|
@@ -94,7 +96,7 @@ class Decoder extends DecoderV0 {
|
|
94
96
|
return;
|
95
97
|
}
|
96
98
|
log("Message decrypted", protoMessage);
|
97
|
-
return new DecodedMessage(
|
99
|
+
return new DecodedMessage(pubsubTopic, protoMessage, res.payload, res.sig?.signature, res.sig?.publicKey);
|
98
100
|
}
|
99
101
|
}
|
100
102
|
/**
|
@@ -103,14 +105,13 @@ class Decoder extends DecoderV0 {
|
|
103
105
|
*
|
104
106
|
* A decoder is used to decode messages from the [14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
|
105
107
|
* format when received from the Waku network. The resulting decoder can then be
|
106
|
-
* pass to { @link @waku/interfaces.
|
107
|
-
* { @link @waku/interfaces.Relay.subscribe } to automatically decrypt and
|
108
|
+
* pass to { @link @waku/interfaces!IReceiver.subscribe } to automatically decrypt and
|
108
109
|
* decode incoming messages.
|
109
110
|
*
|
110
111
|
* @param contentTopic The resulting decoder will only decode messages with this content topic.
|
111
112
|
* @param symKey The symmetric key used to decrypt the message.
|
112
113
|
*/
|
113
|
-
export function createDecoder(contentTopic, symKey) {
|
114
|
-
return new Decoder(contentTopic, symKey);
|
114
|
+
export function createDecoder(contentTopic, symKey, pubsubTopic = DefaultPubSubTopic) {
|
115
|
+
return new Decoder(pubsubTopic, contentTopic, symKey);
|
115
116
|
}
|
116
117
|
//# sourceMappingURL=symmetric.js.map
|
package/dist/symmetric.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"symmetric.js","sourceRoot":"","sources":["../src/symmetric.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,kCAAkC,CAAC;
|
1
|
+
{"version":3,"file":"symmetric.js","sourceRoot":"","sources":["../src/symmetric.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAUxE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,E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AAO,CAAC,EAAE;YACV,GAAG,CACD,2EAA2E,IAAI,CAAC,YAAY,EAAE,EAC9F,CAAC,CACF,CAAC;YACF,OAAO;SACR;QAED,IAAI,CAAC,OAAO,EAAE;YACZ,GAAG,CAAC,8CAA8C,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC;YACvE,OAAO;SACR;QAED,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;QAEhC,IAAI,CAAC,GAAG,EAAE;YACR,GAAG,CAAC,6CAA6C,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC;YACtE,OAAO;SACR;QAED,GAAG,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC;QACvC,OAAO,IAAI,cAAc,CACvB,WAAW,EACX,YAAY,EACZ,GAAG,CAAC,OAAO,EACX,GAAG,CAAC,GAAG,EAAE,SAAS,EAClB,GAAG,CAAC,GAAG,EAAE,SAAS,CACnB,CAAC;IACJ,CAAC;CACF;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,aAAa,CAC3B,YAAoB,EACpB,MAAkB,EAClB,cAA2B,kBAAkB;IAE7C,OAAO,IAAI,OAAO,CAAC,WAAW,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;AACxD,CAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@waku/message-encryption",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.22",
|
4
4
|
"description": "Waku Message Payload Encryption",
|
5
5
|
"types": "./dist/index.d.ts",
|
6
6
|
"module": "./dist/index.js",
|
@@ -65,19 +65,19 @@
|
|
65
65
|
"reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build"
|
66
66
|
},
|
67
67
|
"engines": {
|
68
|
-
"node": ">=
|
68
|
+
"node": ">=18"
|
69
69
|
},
|
70
70
|
"browser": {
|
71
71
|
"crypto": false
|
72
72
|
},
|
73
73
|
"dependencies": {
|
74
74
|
"@noble/secp256k1": "^1.7.1",
|
75
|
-
"@waku/core": "0.0.
|
76
|
-
"@waku/interfaces": "0.0.
|
75
|
+
"@waku/core": "0.0.24",
|
76
|
+
"@waku/interfaces": "0.0.19",
|
77
77
|
"@waku/proto": "0.0.5",
|
78
|
-
"@waku/utils": "0.0.
|
78
|
+
"@waku/utils": "0.0.12",
|
79
79
|
"debug": "^4.3.4",
|
80
|
-
"js-sha3": "^0.
|
80
|
+
"js-sha3": "^0.9.2"
|
81
81
|
},
|
82
82
|
"devDependencies": {
|
83
83
|
"@rollup/plugin-commonjs": "^25.0.4",
|
@@ -88,21 +88,11 @@
|
|
88
88
|
"@waku/build-utils": "*",
|
89
89
|
"chai": "^4.3.7",
|
90
90
|
"cspell": "^7.3.2",
|
91
|
-
"fast-check": "^3.
|
92
|
-
"karma": "^6.4.1",
|
93
|
-
"karma-chrome-launcher": "^3.2.0",
|
94
|
-
"karma-mocha": "^2.0.1",
|
95
|
-
"karma-webpack": "^5.0.0",
|
91
|
+
"fast-check": "^3.13.1",
|
96
92
|
"mocha": "^10.2.0",
|
97
93
|
"npm-run-all": "^4.1.5",
|
98
94
|
"process": "^0.11.10",
|
99
|
-
"
|
100
|
-
"rollup": "^3.29.0",
|
101
|
-
"ts-loader": "^9.4.2",
|
102
|
-
"typescript": "^5.0.4"
|
103
|
-
},
|
104
|
-
"typedoc": {
|
105
|
-
"entryPoint": "./src/index.ts"
|
95
|
+
"rollup": "^3.29.2"
|
106
96
|
},
|
107
97
|
"files": [
|
108
98
|
"dist",
|
package/src/decoded_message.ts
CHANGED
@@ -11,13 +11,13 @@ export class DecodedMessage
|
|
11
11
|
private readonly _decodedPayload: Uint8Array;
|
12
12
|
|
13
13
|
constructor(
|
14
|
-
|
14
|
+
pubsubTopic: string,
|
15
15
|
proto: proto.WakuMessage,
|
16
16
|
decodedPayload: Uint8Array,
|
17
17
|
public signature?: Uint8Array,
|
18
18
|
public signaturePublicKey?: Uint8Array
|
19
19
|
) {
|
20
|
-
super(
|
20
|
+
super(pubsubTopic, proto);
|
21
21
|
this._decodedPayload = decodedPayload;
|
22
22
|
}
|
23
23
|
|
package/src/ecies.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
+
import { DefaultPubSubTopic } from "@waku/core";
|
1
2
|
import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
|
2
|
-
import { IMetaSetter } from "@waku/interfaces";
|
3
|
+
import { IMetaSetter, PubSubTopic } from "@waku/interfaces";
|
3
4
|
import type {
|
4
5
|
EncoderOptions as BaseEncoderOptions,
|
5
6
|
IDecoder,
|
@@ -32,6 +33,7 @@ const log = debug("waku:message-encryption:ecies");
|
|
32
33
|
|
33
34
|
class Encoder implements IEncoder {
|
34
35
|
constructor(
|
36
|
+
public pubsubTopic: PubSubTopic,
|
35
37
|
public contentTopic: string,
|
36
38
|
private publicKey: Uint8Array,
|
37
39
|
private sigPrivKey?: Uint8Array,
|
@@ -88,13 +90,14 @@ export interface EncoderOptions extends BaseEncoderOptions {
|
|
88
90
|
*
|
89
91
|
* An encoder is used to encode messages in the [`14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
|
90
92
|
* format to be sent over the Waku network. The resulting encoder can then be
|
91
|
-
* pass to { @link @waku/interfaces.
|
92
|
-
* { @link @waku/interfaces.
|
93
|
+
* pass to { @link @waku/interfaces!ISender.send } or
|
94
|
+
* { @link @waku/interfaces!ISender.send } to automatically encrypt
|
93
95
|
* and encode outgoing messages.
|
94
96
|
* The payload can optionally be signed with the given private key as defined
|
95
97
|
* in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
|
96
98
|
*/
|
97
99
|
export function createEncoder({
|
100
|
+
pubsubTopic = DefaultPubSubTopic,
|
98
101
|
contentTopic,
|
99
102
|
publicKey,
|
100
103
|
sigPrivKey,
|
@@ -102,6 +105,7 @@ export function createEncoder({
|
|
102
105
|
metaSetter
|
103
106
|
}: EncoderOptions): Encoder {
|
104
107
|
return new Encoder(
|
108
|
+
pubsubTopic,
|
105
109
|
contentTopic,
|
106
110
|
publicKey,
|
107
111
|
sigPrivKey,
|
@@ -112,14 +116,15 @@ export function createEncoder({
|
|
112
116
|
|
113
117
|
class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
114
118
|
constructor(
|
119
|
+
pubsubTopic: PubSubTopic,
|
115
120
|
contentTopic: string,
|
116
121
|
private privateKey: Uint8Array
|
117
122
|
) {
|
118
|
-
super(contentTopic);
|
123
|
+
super(pubsubTopic, contentTopic);
|
119
124
|
}
|
120
125
|
|
121
126
|
async fromProtoObj(
|
122
|
-
|
127
|
+
pubsubTopic: string,
|
123
128
|
protoMessage: IProtoMessage
|
124
129
|
): Promise<DecodedMessage | undefined> {
|
125
130
|
const cipherPayload = protoMessage.payload;
|
@@ -160,7 +165,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
|
160
165
|
|
161
166
|
log("Message decrypted", protoMessage);
|
162
167
|
return new DecodedMessage(
|
163
|
-
|
168
|
+
pubsubTopic,
|
164
169
|
protoMessage,
|
165
170
|
res.payload,
|
166
171
|
res.sig?.signature,
|
@@ -175,8 +180,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
|
175
180
|
*
|
176
181
|
* A decoder is used to decode messages from the [14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
|
177
182
|
* format when received from the Waku network. The resulting decoder can then be
|
178
|
-
* pass to { @link @waku/interfaces.
|
179
|
-
* { @link @waku/interfaces.Relay.subscribe } to automatically decrypt and
|
183
|
+
* pass to { @link @waku/interfaces!IReceiver.subscribe } to automatically decrypt and
|
180
184
|
* decode incoming messages.
|
181
185
|
*
|
182
186
|
* @param contentTopic The resulting decoder will only decode messages with this content topic.
|
@@ -184,7 +188,8 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
|
184
188
|
*/
|
185
189
|
export function createDecoder(
|
186
190
|
contentTopic: string,
|
187
|
-
privateKey: Uint8Array
|
191
|
+
privateKey: Uint8Array,
|
192
|
+
pubsubTopic: PubSubTopic = DefaultPubSubTopic
|
188
193
|
): Decoder {
|
189
|
-
return new Decoder(contentTopic, privateKey);
|
194
|
+
return new Decoder(pubsubTopic, contentTopic, privateKey);
|
190
195
|
}
|
package/src/symmetric.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import { DefaultPubSubTopic } from "@waku/core";
|
1
2
|
import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
|
2
3
|
import type {
|
3
4
|
EncoderOptions as BaseEncoderOptions,
|
@@ -5,7 +6,8 @@ import type {
|
|
5
6
|
IEncoder,
|
6
7
|
IMessage,
|
7
8
|
IMetaSetter,
|
8
|
-
IProtoMessage
|
9
|
+
IProtoMessage,
|
10
|
+
PubSubTopic
|
9
11
|
} from "@waku/interfaces";
|
10
12
|
import { WakuMessage } from "@waku/proto";
|
11
13
|
import debug from "debug";
|
@@ -27,6 +29,7 @@ const log = debug("waku:message-encryption:symmetric");
|
|
27
29
|
|
28
30
|
class Encoder implements IEncoder {
|
29
31
|
constructor(
|
32
|
+
public pubsubTopic: PubSubTopic,
|
30
33
|
public contentTopic: string,
|
31
34
|
private symKey: Uint8Array,
|
32
35
|
private sigPrivKey?: Uint8Array,
|
@@ -83,33 +86,41 @@ export interface EncoderOptions extends BaseEncoderOptions {
|
|
83
86
|
*
|
84
87
|
* An encoder is used to encode messages in the [`14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
|
85
88
|
* format to be sent over the Waku network. The resulting encoder can then be
|
86
|
-
* pass to { @link @waku/interfaces.
|
87
|
-
* { @link @waku/interfaces.Relay.send } to automatically encrypt
|
89
|
+
* pass to { @link @waku/interfaces!ISender.send } to automatically encrypt
|
88
90
|
* and encode outgoing messages.
|
89
91
|
*
|
90
92
|
* The payload can optionally be signed with the given private key as defined
|
91
93
|
* in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
|
92
94
|
*/
|
93
95
|
export function createEncoder({
|
96
|
+
pubsubTopic = DefaultPubSubTopic,
|
94
97
|
contentTopic,
|
95
98
|
symKey,
|
96
99
|
sigPrivKey,
|
97
100
|
ephemeral = false,
|
98
101
|
metaSetter
|
99
102
|
}: EncoderOptions): Encoder {
|
100
|
-
return new Encoder(
|
103
|
+
return new Encoder(
|
104
|
+
pubsubTopic,
|
105
|
+
contentTopic,
|
106
|
+
symKey,
|
107
|
+
sigPrivKey,
|
108
|
+
ephemeral,
|
109
|
+
metaSetter
|
110
|
+
);
|
101
111
|
}
|
102
112
|
|
103
113
|
class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
104
114
|
constructor(
|
115
|
+
pubsubTopic: PubSubTopic,
|
105
116
|
contentTopic: string,
|
106
117
|
private symKey: Uint8Array
|
107
118
|
) {
|
108
|
-
super(contentTopic);
|
119
|
+
super(pubsubTopic, contentTopic);
|
109
120
|
}
|
110
121
|
|
111
122
|
async fromProtoObj(
|
112
|
-
|
123
|
+
pubsubTopic: string,
|
113
124
|
protoMessage: IProtoMessage
|
114
125
|
): Promise<DecodedMessage | undefined> {
|
115
126
|
const cipherPayload = protoMessage.payload;
|
@@ -150,7 +161,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
|
150
161
|
|
151
162
|
log("Message decrypted", protoMessage);
|
152
163
|
return new DecodedMessage(
|
153
|
-
|
164
|
+
pubsubTopic,
|
154
165
|
protoMessage,
|
155
166
|
res.payload,
|
156
167
|
res.sig?.signature,
|
@@ -165,8 +176,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
|
165
176
|
*
|
166
177
|
* A decoder is used to decode messages from the [14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
|
167
178
|
* format when received from the Waku network. The resulting decoder can then be
|
168
|
-
* pass to { @link @waku/interfaces.
|
169
|
-
* { @link @waku/interfaces.Relay.subscribe } to automatically decrypt and
|
179
|
+
* pass to { @link @waku/interfaces!IReceiver.subscribe } to automatically decrypt and
|
170
180
|
* decode incoming messages.
|
171
181
|
*
|
172
182
|
* @param contentTopic The resulting decoder will only decode messages with this content topic.
|
@@ -174,7 +184,8 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
|
174
184
|
*/
|
175
185
|
export function createDecoder(
|
176
186
|
contentTopic: string,
|
177
|
-
symKey: Uint8Array
|
187
|
+
symKey: Uint8Array,
|
188
|
+
pubsubTopic: PubSubTopic = DefaultPubSubTopic
|
178
189
|
): Decoder {
|
179
|
-
return new Decoder(contentTopic, symKey);
|
190
|
+
return new Decoder(pubsubTopic, contentTopic, symKey);
|
180
191
|
}
|