@waku/message-encryption 0.0.24-678635e.0 → 0.0.24

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.
Files changed (53) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/bundle/crypto.js +1 -0
  3. package/bundle/ecies-R65pUoo3.js +124 -0
  4. package/bundle/ecies.js +3 -1
  5. package/bundle/encryption-zFGfcjHZ.js +6356 -0
  6. package/bundle/index-alzPvot7.js +17 -0
  7. package/bundle/index.js +5 -1
  8. package/bundle/symmetric-7aAyizy_.js +124 -0
  9. package/bundle/symmetric-CXVjdTdV.js +2815 -0
  10. package/bundle/symmetric.js +3 -1
  11. package/dist/.tsbuildinfo +1 -1
  12. package/dist/crypto/ecies.js +1 -1
  13. package/dist/crypto/ecies.js.map +1 -1
  14. package/dist/crypto/index.d.ts +3 -29
  15. package/dist/crypto/index.js +3 -59
  16. package/dist/crypto/index.js.map +1 -1
  17. package/dist/crypto/symmetric.js +2 -2
  18. package/dist/crypto/symmetric.js.map +1 -1
  19. package/dist/crypto/utils.d.ts +29 -0
  20. package/dist/crypto/utils.js +60 -0
  21. package/dist/crypto/utils.js.map +1 -0
  22. package/dist/decoded_message.d.ts +6 -0
  23. package/dist/decoded_message.js +12 -0
  24. package/dist/decoded_message.js.map +1 -1
  25. package/dist/ecies.d.ts +13 -10
  26. package/dist/ecies.js +10 -9
  27. package/dist/ecies.js.map +1 -1
  28. package/dist/{waku_payload.d.ts → encryption.d.ts} +5 -1
  29. package/dist/{waku_payload.js → encryption.js} +3 -5
  30. package/dist/encryption.js.map +1 -0
  31. package/dist/index.d.ts +1 -6
  32. package/dist/index.js +1 -2
  33. package/dist/index.js.map +1 -1
  34. package/dist/{constants.d.ts → misc.d.ts} +2 -0
  35. package/dist/{constants.js → misc.js} +3 -1
  36. package/dist/misc.js.map +1 -0
  37. package/dist/symmetric.d.ts +9 -9
  38. package/dist/symmetric.js +10 -9
  39. package/dist/symmetric.js.map +1 -1
  40. package/package.json +112 -1
  41. package/src/crypto/ecies.ts +1 -1
  42. package/src/crypto/index.ts +3 -76
  43. package/src/crypto/symmetric.ts +2 -2
  44. package/src/crypto/utils.ts +76 -0
  45. package/src/decoded_message.ts +13 -0
  46. package/src/ecies.ts +36 -25
  47. package/src/{waku_payload.ts → encryption.ts} +13 -6
  48. package/src/index.ts +1 -9
  49. package/src/{constants.ts → misc.ts} +4 -0
  50. package/src/symmetric.ts +32 -21
  51. package/bundle/index-62691783.js +0 -25363
  52. package/dist/constants.js.map +0 -1
  53. package/dist/waku_payload.js.map +0 -1
package/src/ecies.ts CHANGED
@@ -1,39 +1,41 @@
1
- import { DefaultPubSubTopic } from "@waku/core";
2
1
  import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
3
- import { IMetaSetter, PubSubTopic } from "@waku/interfaces";
4
- import type {
5
- EncoderOptions as BaseEncoderOptions,
6
- IDecoder,
7
- IEncoder,
8
- IMessage,
9
- IProtoMessage
2
+ import {
3
+ type EncoderOptions as BaseEncoderOptions,
4
+ DefaultPubsubTopic,
5
+ type IDecoder,
6
+ type IEncoder,
7
+ type IMessage,
8
+ type IMetaSetter,
9
+ type IProtoMessage,
10
+ type PubsubTopic,
11
+ type SingleShardInfo
10
12
  } from "@waku/interfaces";
11
13
  import { WakuMessage } from "@waku/proto";
12
- import { Logger } from "@waku/utils";
14
+ import { determinePubsubTopic, Logger } from "@waku/utils";
13
15
 
16
+ import { generatePrivateKey } from "./crypto/utils.js";
14
17
  import { DecodedMessage } from "./decoded_message.js";
15
18
  import {
16
19
  decryptAsymmetric,
17
20
  encryptAsymmetric,
18
21
  postCipher,
19
22
  preCipher
20
- } from "./waku_payload.js";
21
-
22
- import {
23
- generatePrivateKey,
24
- getPublicKey,
25
- OneMillion,
26
- Version
27
- } from "./index.js";
23
+ } from "./encryption.js";
24
+ import { OneMillion, Version } from "./misc.js";
28
25
 
29
- export { generatePrivateKey, getPublicKey };
30
- export type { Encoder, Decoder, DecodedMessage };
26
+ export {
27
+ decryptAsymmetric,
28
+ encryptAsymmetric,
29
+ postCipher,
30
+ preCipher,
31
+ generatePrivateKey
32
+ };
31
33
 
32
34
  const log = new Logger("message-encryption:ecies");
33
35
 
34
36
  class Encoder implements IEncoder {
35
37
  constructor(
36
- public pubsubTopic: PubSubTopic,
38
+ public pubsubTopic: PubsubTopic,
37
39
  public contentTopic: string,
38
40
  private publicKey: Uint8Array,
39
41
  private sigPrivKey?: Uint8Array,
@@ -78,6 +80,10 @@ class Encoder implements IEncoder {
78
80
  }
79
81
 
80
82
  export interface EncoderOptions extends BaseEncoderOptions {
83
+ /**
84
+ * @deprecated
85
+ */
86
+ pubsubTopic?: PubsubTopic;
81
87
  /** The public key to encrypt the payload for. */
82
88
  publicKey: Uint8Array;
83
89
  /** An optional private key to be used to sign the payload before encryption. */
@@ -97,7 +103,8 @@ export interface EncoderOptions extends BaseEncoderOptions {
97
103
  * in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
98
104
  */
99
105
  export function createEncoder({
100
- pubsubTopic = DefaultPubSubTopic,
106
+ pubsubTopic,
107
+ pubsubTopicShardInfo,
101
108
  contentTopic,
102
109
  publicKey,
103
110
  sigPrivKey,
@@ -105,7 +112,7 @@ export function createEncoder({
105
112
  metaSetter
106
113
  }: EncoderOptions): Encoder {
107
114
  return new Encoder(
108
- pubsubTopic,
115
+ determinePubsubTopic(contentTopic, pubsubTopic ?? pubsubTopicShardInfo),
109
116
  contentTopic,
110
117
  publicKey,
111
118
  sigPrivKey,
@@ -116,7 +123,7 @@ export function createEncoder({
116
123
 
117
124
  class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
118
125
  constructor(
119
- pubsubTopic: PubSubTopic,
126
+ pubsubTopic: PubsubTopic,
120
127
  contentTopic: string,
121
128
  private privateKey: Uint8Array
122
129
  ) {
@@ -193,7 +200,11 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
193
200
  export function createDecoder(
194
201
  contentTopic: string,
195
202
  privateKey: Uint8Array,
196
- pubsubTopic: PubSubTopic = DefaultPubSubTopic
203
+ pubsubTopicShardInfo: SingleShardInfo | PubsubTopic = DefaultPubsubTopic
197
204
  ): Decoder {
198
- return new Decoder(pubsubTopic, contentTopic, privateKey);
205
+ return new Decoder(
206
+ determinePubsubTopic(contentTopic, pubsubTopicShardInfo),
207
+ contentTopic,
208
+ privateKey
209
+ );
199
210
  }
@@ -1,12 +1,14 @@
1
1
  import * as secp from "@noble/secp256k1";
2
2
  import { concat, hexToBytes } from "@waku/utils/bytes";
3
3
 
4
- import { Symmetric } from "./constants.js";
5
- import * as ecies from "./crypto/ecies.js";
6
- import { keccak256, randomBytes, sign } from "./crypto/index.js";
7
- import * as symmetric from "./crypto/symmetric.js";
8
-
9
- import { Signature } from "./index.js";
4
+ import {
5
+ ecies,
6
+ keccak256,
7
+ randomBytes,
8
+ sign,
9
+ symmetric
10
+ } from "./crypto/index.js";
11
+ import { Symmetric } from "./misc.js";
10
12
 
11
13
  const FlagsLength = 1;
12
14
  const FlagMask = 3; // 0011
@@ -210,6 +212,11 @@ export async function preCipher(
210
212
  return envelope;
211
213
  }
212
214
 
215
+ type Signature = {
216
+ signature: Uint8Array;
217
+ publicKey: Uint8Array | undefined;
218
+ };
219
+
213
220
  /**
214
221
  * Decode a decrypted payload.
215
222
  *
package/src/index.ts CHANGED
@@ -5,17 +5,9 @@ import {
5
5
  } from "./crypto/index.js";
6
6
  import { DecodedMessage } from "./decoded_message.js";
7
7
 
8
- export const OneMillion = BigInt(1_000_000);
9
-
10
8
  export { generatePrivateKey, generateSymmetricKey, getPublicKey };
11
9
  export type { DecodedMessage };
12
10
 
13
11
  export * as ecies from "./ecies.js";
14
12
  export * as symmetric from "./symmetric.js";
15
-
16
- export const Version = 1;
17
-
18
- export type Signature = {
19
- signature: Uint8Array;
20
- publicKey: Uint8Array | undefined;
21
- };
13
+ export * as crypto from "./crypto";
@@ -8,3 +8,7 @@ export const Symmetric = {
8
8
  export const Asymmetric = {
9
9
  keySize: 32
10
10
  };
11
+
12
+ export const OneMillion = BigInt(1_000_000);
13
+
14
+ export const Version = 1;
package/src/symmetric.ts CHANGED
@@ -1,35 +1,41 @@
1
- import { DefaultPubSubTopic } from "@waku/core";
2
1
  import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
3
- import type {
4
- EncoderOptions as BaseEncoderOptions,
5
- IDecoder,
6
- IEncoder,
7
- IMessage,
8
- IMetaSetter,
9
- IProtoMessage,
10
- PubSubTopic
2
+ import {
3
+ type EncoderOptions as BaseEncoderOptions,
4
+ DefaultPubsubTopic,
5
+ type IDecoder,
6
+ type IEncoder,
7
+ type IMessage,
8
+ type IMetaSetter,
9
+ type IProtoMessage,
10
+ type PubsubTopic,
11
+ type SingleShardInfo
11
12
  } from "@waku/interfaces";
12
13
  import { WakuMessage } from "@waku/proto";
13
- import { Logger } from "@waku/utils";
14
+ import { determinePubsubTopic, Logger } from "@waku/utils";
14
15
 
16
+ import { generateSymmetricKey } from "./crypto/utils.js";
15
17
  import { DecodedMessage } from "./decoded_message.js";
16
18
  import {
17
19
  decryptSymmetric,
18
20
  encryptSymmetric,
19
21
  postCipher,
20
22
  preCipher
21
- } from "./waku_payload.js";
22
-
23
- import { generateSymmetricKey, OneMillion, Version } from "./index.js";
23
+ } from "./encryption.js";
24
+ import { OneMillion, Version } from "./misc.js";
24
25
 
25
- export { generateSymmetricKey };
26
- export type { DecodedMessage, Encoder, Decoder };
26
+ export {
27
+ decryptSymmetric,
28
+ encryptSymmetric,
29
+ postCipher,
30
+ preCipher,
31
+ generateSymmetricKey
32
+ };
27
33
 
28
34
  const log = new Logger("message-encryption:symmetric");
29
35
 
30
36
  class Encoder implements IEncoder {
31
37
  constructor(
32
- public pubsubTopic: PubSubTopic,
38
+ public pubsubTopic: PubsubTopic,
33
39
  public contentTopic: string,
34
40
  private symKey: Uint8Array,
35
41
  private sigPrivKey?: Uint8Array,
@@ -93,7 +99,8 @@ export interface EncoderOptions extends BaseEncoderOptions {
93
99
  * in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
94
100
  */
95
101
  export function createEncoder({
96
- pubsubTopic = DefaultPubSubTopic,
102
+ pubsubTopic = DefaultPubsubTopic,
103
+ pubsubTopicShardInfo,
97
104
  contentTopic,
98
105
  symKey,
99
106
  sigPrivKey,
@@ -101,7 +108,7 @@ export function createEncoder({
101
108
  metaSetter
102
109
  }: EncoderOptions): Encoder {
103
110
  return new Encoder(
104
- pubsubTopic,
111
+ determinePubsubTopic(contentTopic, pubsubTopic ?? pubsubTopicShardInfo),
105
112
  contentTopic,
106
113
  symKey,
107
114
  sigPrivKey,
@@ -112,7 +119,7 @@ export function createEncoder({
112
119
 
113
120
  class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
114
121
  constructor(
115
- pubsubTopic: PubSubTopic,
122
+ pubsubTopic: PubsubTopic,
116
123
  contentTopic: string,
117
124
  private symKey: Uint8Array
118
125
  ) {
@@ -189,7 +196,11 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
189
196
  export function createDecoder(
190
197
  contentTopic: string,
191
198
  symKey: Uint8Array,
192
- pubsubTopic: PubSubTopic = DefaultPubSubTopic
199
+ pubsubTopicShardInfo: SingleShardInfo | PubsubTopic = DefaultPubsubTopic
193
200
  ): Decoder {
194
- return new Decoder(pubsubTopic, contentTopic, symKey);
201
+ return new Decoder(
202
+ determinePubsubTopic(contentTopic, pubsubTopicShardInfo),
203
+ contentTopic,
204
+ symKey
205
+ );
195
206
  }