@waku/message-encryption 0.0.20 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waku/message-encryption",
3
- "version": "0.0.20",
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,51 +65,34 @@
65
65
  "reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build"
66
66
  },
67
67
  "engines": {
68
- "node": ">=16"
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.22",
76
- "@waku/interfaces": "0.0.17",
75
+ "@waku/core": "0.0.24",
76
+ "@waku/interfaces": "0.0.19",
77
77
  "@waku/proto": "0.0.5",
78
- "@waku/utils": "0.0.10",
78
+ "@waku/utils": "0.0.12",
79
79
  "debug": "^4.3.4",
80
- "js-sha3": "^0.8.0"
80
+ "js-sha3": "^0.9.2"
81
81
  },
82
82
  "devDependencies": {
83
- "@libp2p/interface-connection": "^5.1.1",
84
- "@libp2p/interface-connection-manager": "^3.0.1",
85
- "@libp2p/interface-libp2p": "^3.2.0",
86
- "@libp2p/interface-peer-id": "^2.0.2",
87
- "@libp2p/interface-peer-store": "^2.0.4",
88
- "@libp2p/interface-registrar": "^2.0.12",
89
- "@rollup/plugin-commonjs": "^24.0.1",
83
+ "@rollup/plugin-commonjs": "^25.0.4",
90
84
  "@rollup/plugin-json": "^6.0.0",
91
- "@rollup/plugin-node-resolve": "^15.0.2",
92
- "@types/chai": "^4.3.4",
85
+ "@rollup/plugin-node-resolve": "^15.1.0",
86
+ "@types/chai": "^4.3.5",
93
87
  "@types/mocha": "^10.0.1",
94
88
  "@waku/build-utils": "*",
95
89
  "chai": "^4.3.7",
96
- "cspell": "^6.31.1",
97
- "fast-check": "^3.8.1",
98
- "karma": "^6.4.1",
99
- "karma-chrome-launcher": "^3.2.0",
100
- "karma-mocha": "^2.0.1",
101
- "karma-webpack": "^5.0.0",
90
+ "cspell": "^7.3.2",
91
+ "fast-check": "^3.13.1",
102
92
  "mocha": "^10.2.0",
103
93
  "npm-run-all": "^4.1.5",
104
- "prettier": "^2.8.8",
105
94
  "process": "^0.11.10",
106
- "puppeteer": "^20.4.0",
107
- "rollup": "^3.21.3",
108
- "ts-loader": "^9.4.2",
109
- "typescript": "^5.0.4"
110
- },
111
- "typedoc": {
112
- "entryPoint": "./src/index.ts"
95
+ "rollup": "^3.29.2"
113
96
  },
114
97
  "files": [
115
98
  "dist",
package/src/constants.ts CHANGED
@@ -2,9 +2,9 @@ export const Symmetric = {
2
2
  keySize: 32,
3
3
  ivSize: 12,
4
4
  tagSize: 16,
5
- algorithm: { name: "AES-GCM", length: 128 },
5
+ algorithm: { name: "AES-GCM", length: 128 }
6
6
  };
7
7
 
8
8
  export const Asymmetric = {
9
- keySize: 32,
9
+ keySize: 32
10
10
  };
@@ -9,7 +9,7 @@ import { Asymmetric, Symmetric } from "../constants.js";
9
9
  declare const self: Record<string, any> | undefined;
10
10
  const crypto: { node?: any; web?: any } = {
11
11
  node: nodeCrypto,
12
- web: typeof self === "object" && "crypto" in self ? self.crypto : undefined,
12
+ web: typeof self === "object" && "crypto" in self ? self.crypto : undefined
13
13
  };
14
14
 
15
15
  export function getSubtle(): SubtleCrypto {
@@ -63,7 +63,7 @@ export async function sign(
63
63
  ): Promise<Uint8Array> {
64
64
  const [signature, recoveryId] = await secp.sign(message, privateKey, {
65
65
  recovered: true,
66
- der: false,
66
+ der: false
67
67
  });
68
68
  return concat(
69
69
  [signature, new Uint8Array([recoveryId])],
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  DecodedMessage as DecodedMessageV0,
3
- proto,
3
+ proto
4
4
  } from "@waku/core/lib/message/version_0";
5
5
  import type { IDecodedMessage } from "@waku/interfaces";
6
6
 
@@ -11,13 +11,13 @@ export class DecodedMessage
11
11
  private readonly _decodedPayload: Uint8Array;
12
12
 
13
13
  constructor(
14
- pubSubTopic: string,
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(pubSubTopic, proto);
20
+ super(pubsubTopic, proto);
21
21
  this._decodedPayload = decodedPayload;
22
22
  }
23
23
 
package/src/ecies.ts CHANGED
@@ -1,11 +1,12 @@
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,
6
7
  IEncoder,
7
8
  IMessage,
8
- IProtoMessage,
9
+ IProtoMessage
9
10
  } from "@waku/interfaces";
10
11
  import { WakuMessage } from "@waku/proto";
11
12
  import debug from "debug";
@@ -15,14 +16,14 @@ import {
15
16
  decryptAsymmetric,
16
17
  encryptAsymmetric,
17
18
  postCipher,
18
- preCipher,
19
+ preCipher
19
20
  } from "./waku_payload.js";
20
21
 
21
22
  import {
22
23
  generatePrivateKey,
23
24
  getPublicKey,
24
25
  OneMillion,
25
- Version,
26
+ Version
26
27
  } from "./index.js";
27
28
 
28
29
  export { generatePrivateKey, getPublicKey };
@@ -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,
@@ -63,7 +65,7 @@ class Encoder implements IEncoder {
63
65
  timestamp: BigInt(timestamp.valueOf()) * OneMillion,
64
66
  meta: undefined,
65
67
  rateLimitProof: message.rateLimitProof,
66
- ephemeral: this.ephemeral,
68
+ ephemeral: this.ephemeral
67
69
  };
68
70
 
69
71
  if (this.metaSetter) {
@@ -88,20 +90,22 @@ 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.LightPush.push } or
92
- * { @link @waku/interfaces.Relay.send } to automatically encrypt
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,
101
104
  ephemeral = false,
102
- metaSetter,
105
+ metaSetter
103
106
  }: EncoderOptions): Encoder {
104
107
  return new Encoder(
108
+ pubsubTopic,
105
109
  contentTopic,
106
110
  publicKey,
107
111
  sigPrivKey,
@@ -111,12 +115,16 @@ export function createEncoder({
111
115
  }
112
116
 
113
117
  class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
114
- constructor(contentTopic: string, private privateKey: Uint8Array) {
115
- super(contentTopic);
118
+ constructor(
119
+ pubsubTopic: PubSubTopic,
120
+ contentTopic: string,
121
+ private privateKey: Uint8Array
122
+ ) {
123
+ super(pubsubTopic, contentTopic);
116
124
  }
117
125
 
118
126
  async fromProtoObj(
119
- pubSubTopic: string,
127
+ pubsubTopic: string,
120
128
  protoMessage: IProtoMessage
121
129
  ): Promise<DecodedMessage | undefined> {
122
130
  const cipherPayload = protoMessage.payload;
@@ -157,7 +165,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
157
165
 
158
166
  log("Message decrypted", protoMessage);
159
167
  return new DecodedMessage(
160
- pubSubTopic,
168
+ pubsubTopic,
161
169
  protoMessage,
162
170
  res.payload,
163
171
  res.sig?.signature,
@@ -172,8 +180,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
172
180
  *
173
181
  * A decoder is used to decode messages from the [14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
174
182
  * format when received from the Waku network. The resulting decoder can then be
175
- * pass to { @link @waku/interfaces.Filter.subscribe } or
176
- * { @link @waku/interfaces.Relay.subscribe } to automatically decrypt and
183
+ * pass to { @link @waku/interfaces!IReceiver.subscribe } to automatically decrypt and
177
184
  * decode incoming messages.
178
185
  *
179
186
  * @param contentTopic The resulting decoder will only decode messages with this content topic.
@@ -181,7 +188,8 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
181
188
  */
182
189
  export function createDecoder(
183
190
  contentTopic: string,
184
- privateKey: Uint8Array
191
+ privateKey: Uint8Array,
192
+ pubsubTopic: PubSubTopic = DefaultPubSubTopic
185
193
  ): Decoder {
186
- return new Decoder(contentTopic, privateKey);
194
+ return new Decoder(pubsubTopic, contentTopic, privateKey);
187
195
  }
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  generatePrivateKey,
3
3
  generateSymmetricKey,
4
- getPublicKey,
4
+ getPublicKey
5
5
  } from "./crypto/index.js";
6
6
  import { DecodedMessage } from "./decoded_message.js";
7
7
 
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,
@@ -6,6 +7,7 @@ import type {
6
7
  IMessage,
7
8
  IMetaSetter,
8
9
  IProtoMessage,
10
+ PubSubTopic
9
11
  } from "@waku/interfaces";
10
12
  import { WakuMessage } from "@waku/proto";
11
13
  import debug from "debug";
@@ -15,7 +17,7 @@ import {
15
17
  decryptSymmetric,
16
18
  encryptSymmetric,
17
19
  postCipher,
18
- preCipher,
20
+ preCipher
19
21
  } from "./waku_payload.js";
20
22
 
21
23
  import { generateSymmetricKey, OneMillion, Version } from "./index.js";
@@ -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,
@@ -58,7 +61,7 @@ class Encoder implements IEncoder {
58
61
  timestamp: BigInt(timestamp.valueOf()) * OneMillion,
59
62
  meta: undefined,
60
63
  rateLimitProof: message.rateLimitProof,
61
- ephemeral: this.ephemeral,
64
+ ephemeral: this.ephemeral
62
65
  };
63
66
 
64
67
  if (this.metaSetter) {
@@ -83,30 +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.LightPush.push } or
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
- metaSetter,
101
+ metaSetter
99
102
  }: EncoderOptions): Encoder {
100
- return new Encoder(contentTopic, symKey, sigPrivKey, ephemeral, metaSetter);
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
- constructor(contentTopic: string, private symKey: Uint8Array) {
105
- super(contentTopic);
114
+ constructor(
115
+ pubsubTopic: PubSubTopic,
116
+ contentTopic: string,
117
+ private symKey: Uint8Array
118
+ ) {
119
+ super(pubsubTopic, contentTopic);
106
120
  }
107
121
 
108
122
  async fromProtoObj(
109
- pubSubTopic: string,
123
+ pubsubTopic: string,
110
124
  protoMessage: IProtoMessage
111
125
  ): Promise<DecodedMessage | undefined> {
112
126
  const cipherPayload = protoMessage.payload;
@@ -147,7 +161,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
147
161
 
148
162
  log("Message decrypted", protoMessage);
149
163
  return new DecodedMessage(
150
- pubSubTopic,
164
+ pubsubTopic,
151
165
  protoMessage,
152
166
  res.payload,
153
167
  res.sig?.signature,
@@ -162,8 +176,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
162
176
  *
163
177
  * A decoder is used to decode messages from the [14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
164
178
  * format when received from the Waku network. The resulting decoder can then be
165
- * pass to { @link @waku/interfaces.Filter.subscribe } or
166
- * { @link @waku/interfaces.Relay.subscribe } to automatically decrypt and
179
+ * pass to { @link @waku/interfaces!IReceiver.subscribe } to automatically decrypt and
167
180
  * decode incoming messages.
168
181
  *
169
182
  * @param contentTopic The resulting decoder will only decode messages with this content topic.
@@ -171,7 +184,8 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
171
184
  */
172
185
  export function createDecoder(
173
186
  contentTopic: string,
174
- symKey: Uint8Array
187
+ symKey: Uint8Array,
188
+ pubsubTopic: PubSubTopic = DefaultPubSubTopic
175
189
  ): Decoder {
176
- return new Decoder(contentTopic, symKey);
190
+ return new Decoder(pubsubTopic, contentTopic, symKey);
177
191
  }