@waku/message-encryption 0.0.35-c7fe44e.0 → 0.0.36-3545a8e.0

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/dist/ecies.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
2
2
  import { WakuMessage } from "@waku/proto";
3
- import { determinePubsubTopic, Logger } from "@waku/utils";
3
+ import { Logger } from "@waku/utils";
4
4
  import { generatePrivateKey } from "./crypto/utils.js";
5
5
  import { DecodedMessage } from "./decoded_message.js";
6
6
  import { decryptAsymmetric, encryptAsymmetric, postCipher, preCipher } from "./encryption.js";
@@ -8,15 +8,15 @@ import { OneMillion, Version } from "./misc.js";
8
8
  export { decryptAsymmetric, encryptAsymmetric, postCipher, preCipher, generatePrivateKey };
9
9
  const log = new Logger("message-encryption:ecies");
10
10
  class Encoder {
11
- pubsubTopic;
12
11
  contentTopic;
12
+ routingInfo;
13
13
  publicKey;
14
14
  sigPrivKey;
15
15
  ephemeral;
16
16
  metaSetter;
17
- constructor(pubsubTopic, contentTopic, publicKey, sigPrivKey, ephemeral = false, metaSetter) {
18
- this.pubsubTopic = pubsubTopic;
17
+ constructor(contentTopic, routingInfo, publicKey, sigPrivKey, ephemeral = false, metaSetter) {
19
18
  this.contentTopic = contentTopic;
19
+ this.routingInfo = routingInfo;
20
20
  this.publicKey = publicKey;
21
21
  this.sigPrivKey = sigPrivKey;
22
22
  this.ephemeral = ephemeral;
@@ -25,6 +25,9 @@ class Encoder {
25
25
  throw new Error("Content topic must be specified");
26
26
  }
27
27
  }
28
+ get pubsubTopic() {
29
+ return this.routingInfo.pubsubTopic;
30
+ }
28
31
  async toWire(message) {
29
32
  const protoMessage = await this.toProtoObj(message);
30
33
  if (!protoMessage)
@@ -63,13 +66,13 @@ class Encoder {
63
66
  * The payload can optionally be signed with the given private key as defined
64
67
  * in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
65
68
  */
66
- export function createEncoder({ pubsubTopic, pubsubTopicShardInfo, contentTopic, publicKey, sigPrivKey, ephemeral = false, metaSetter }) {
67
- return new Encoder(determinePubsubTopic(contentTopic, pubsubTopic ?? pubsubTopicShardInfo), contentTopic, publicKey, sigPrivKey, ephemeral, metaSetter);
69
+ export function createEncoder({ contentTopic, routingInfo, publicKey, sigPrivKey, ephemeral = false, metaSetter }) {
70
+ return new Encoder(contentTopic, routingInfo, publicKey, sigPrivKey, ephemeral, metaSetter);
68
71
  }
69
72
  class Decoder extends DecoderV0 {
70
73
  privateKey;
71
- constructor(pubsubTopic, contentTopic, privateKey) {
72
- super(pubsubTopic, contentTopic);
74
+ constructor(contentTopic, routingInfo, privateKey) {
75
+ super(contentTopic, routingInfo);
73
76
  this.privateKey = privateKey;
74
77
  }
75
78
  async fromProtoObj(pubsubTopic, protoMessage) {
@@ -109,9 +112,10 @@ class Decoder extends DecoderV0 {
109
112
  * decode incoming messages.
110
113
  *
111
114
  * @param contentTopic The resulting decoder will only decode messages with this content topic.
115
+ * @param routingInfo
112
116
  * @param privateKey The private key used to decrypt the message.
113
117
  */
114
- export function createDecoder(contentTopic, privateKey, pubsubTopicShardInfo) {
115
- return new Decoder(determinePubsubTopic(contentTopic, pubsubTopicShardInfo), contentTopic, privateKey);
118
+ export function createDecoder(contentTopic, routingInfo, privateKey) {
119
+ return new Decoder(contentTopic, routingInfo, privateKey);
116
120
  }
117
121
  //# sourceMappingURL=ecies.js.map
package/dist/ecies.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ecies.js","sourceRoot":"","sources":["../src/ecies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAYxE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE3D,OAAO,EAAE,kBAAkB,EAAE,MAA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;IAEtB,OAAO,IAAI,OAAO,CAAC,YAAY,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;AAC5D,CAAC"}
@@ -1,16 +1,17 @@
1
1
  import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
2
- import type { EncoderOptions as BaseEncoderOptions, IDecoder, IEncoder, IEncryptedMessage, IMessage, IMetaSetter, IProtoMessage, PubsubTopic, SingleShardInfo } from "@waku/interfaces";
2
+ import type { EncoderOptions as BaseEncoderOptions, IDecoder, IEncoder, IEncryptedMessage, IMessage, IMetaSetter, IProtoMessage, IRoutingInfo, PubsubTopic } from "@waku/interfaces";
3
3
  import { generateSymmetricKey } from "./crypto/utils.js";
4
4
  import { decryptSymmetric, encryptSymmetric, postCipher, preCipher } from "./encryption.js";
5
5
  export { decryptSymmetric, encryptSymmetric, postCipher, preCipher, generateSymmetricKey };
6
6
  declare class Encoder implements IEncoder {
7
- pubsubTopic: PubsubTopic;
8
7
  contentTopic: string;
8
+ routingInfo: IRoutingInfo;
9
9
  private symKey;
10
10
  private sigPrivKey?;
11
11
  ephemeral: boolean;
12
12
  metaSetter?: IMetaSetter | undefined;
13
- constructor(pubsubTopic: PubsubTopic, contentTopic: string, symKey: Uint8Array, sigPrivKey?: Uint8Array | undefined, ephemeral?: boolean, metaSetter?: IMetaSetter | undefined);
13
+ constructor(contentTopic: string, routingInfo: IRoutingInfo, symKey: Uint8Array, sigPrivKey?: Uint8Array | undefined, ephemeral?: boolean, metaSetter?: IMetaSetter | undefined);
14
+ get pubsubTopic(): PubsubTopic;
14
15
  toWire(message: IMessage): Promise<Uint8Array | undefined>;
15
16
  toProtoObj(message: IMessage): Promise<IProtoMessage | undefined>;
16
17
  }
@@ -32,10 +33,10 @@ export interface EncoderOptions extends BaseEncoderOptions {
32
33
  * The payload can optionally be signed with the given private key as defined
33
34
  * in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
34
35
  */
35
- export declare function createEncoder({ pubsubTopic, pubsubTopicShardInfo, contentTopic, symKey, sigPrivKey, ephemeral, metaSetter }: EncoderOptions): Encoder;
36
+ export declare function createEncoder({ contentTopic, routingInfo, symKey, sigPrivKey, ephemeral, metaSetter }: EncoderOptions): Encoder;
36
37
  declare class Decoder extends DecoderV0 implements IDecoder<IEncryptedMessage> {
37
38
  private symKey;
38
- constructor(pubsubTopic: PubsubTopic, contentTopic: string, symKey: Uint8Array);
39
+ constructor(contentTopic: string, routingInfo: IRoutingInfo, symKey: Uint8Array);
39
40
  fromProtoObj(pubsubTopic: string, protoMessage: IProtoMessage): Promise<IEncryptedMessage | undefined>;
40
41
  }
41
42
  /**
@@ -48,6 +49,7 @@ declare class Decoder extends DecoderV0 implements IDecoder<IEncryptedMessage> {
48
49
  * decode incoming messages.
49
50
  *
50
51
  * @param contentTopic The resulting decoder will only decode messages with this content topic.
52
+ * @param routingInfo Routing information, depends on the network config (static vs auto sharding)
51
53
  * @param symKey The symmetric key used to decrypt the message.
52
54
  */
53
- export declare function createDecoder(contentTopic: string, symKey: Uint8Array, pubsubTopicShardInfo?: SingleShardInfo | PubsubTopic): Decoder;
55
+ export declare function createDecoder(contentTopic: string, routingInfo: IRoutingInfo, symKey: Uint8Array): Decoder;
package/dist/symmetric.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
2
2
  import { WakuMessage } from "@waku/proto";
3
- import { determinePubsubTopic, Logger } from "@waku/utils";
3
+ import { Logger } from "@waku/utils";
4
4
  import { generateSymmetricKey } from "./crypto/utils.js";
5
5
  import { DecodedMessage } from "./decoded_message.js";
6
6
  import { decryptSymmetric, encryptSymmetric, postCipher, preCipher } from "./encryption.js";
@@ -8,15 +8,15 @@ import { OneMillion, Version } from "./misc.js";
8
8
  export { decryptSymmetric, encryptSymmetric, postCipher, preCipher, generateSymmetricKey };
9
9
  const log = new Logger("message-encryption:symmetric");
10
10
  class Encoder {
11
- pubsubTopic;
12
11
  contentTopic;
12
+ routingInfo;
13
13
  symKey;
14
14
  sigPrivKey;
15
15
  ephemeral;
16
16
  metaSetter;
17
- constructor(pubsubTopic, contentTopic, symKey, sigPrivKey, ephemeral = false, metaSetter) {
18
- this.pubsubTopic = pubsubTopic;
17
+ constructor(contentTopic, routingInfo, symKey, sigPrivKey, ephemeral = false, metaSetter) {
19
18
  this.contentTopic = contentTopic;
19
+ this.routingInfo = routingInfo;
20
20
  this.symKey = symKey;
21
21
  this.sigPrivKey = sigPrivKey;
22
22
  this.ephemeral = ephemeral;
@@ -25,6 +25,9 @@ class Encoder {
25
25
  throw new Error("Content topic must be specified");
26
26
  }
27
27
  }
28
+ get pubsubTopic() {
29
+ return this.routingInfo.pubsubTopic;
30
+ }
28
31
  async toWire(message) {
29
32
  const protoMessage = await this.toProtoObj(message);
30
33
  if (!protoMessage)
@@ -63,13 +66,13 @@ class Encoder {
63
66
  * The payload can optionally be signed with the given private key as defined
64
67
  * in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
65
68
  */
66
- export function createEncoder({ pubsubTopic, pubsubTopicShardInfo, contentTopic, symKey, sigPrivKey, ephemeral = false, metaSetter }) {
67
- return new Encoder(determinePubsubTopic(contentTopic, pubsubTopic ?? pubsubTopicShardInfo), contentTopic, symKey, sigPrivKey, ephemeral, metaSetter);
69
+ export function createEncoder({ contentTopic, routingInfo, symKey, sigPrivKey, ephemeral = false, metaSetter }) {
70
+ return new Encoder(contentTopic, routingInfo, symKey, sigPrivKey, ephemeral, metaSetter);
68
71
  }
69
72
  class Decoder extends DecoderV0 {
70
73
  symKey;
71
- constructor(pubsubTopic, contentTopic, symKey) {
72
- super(pubsubTopic, contentTopic);
74
+ constructor(contentTopic, routingInfo, symKey) {
75
+ super(contentTopic, routingInfo);
73
76
  this.symKey = symKey;
74
77
  }
75
78
  async fromProtoObj(pubsubTopic, protoMessage) {
@@ -109,9 +112,10 @@ class Decoder extends DecoderV0 {
109
112
  * decode incoming messages.
110
113
  *
111
114
  * @param contentTopic The resulting decoder will only decode messages with this content topic.
115
+ * @param routingInfo Routing information, depends on the network config (static vs auto sharding)
112
116
  * @param symKey The symmetric key used to decrypt the message.
113
117
  */
114
- export function createDecoder(contentTopic, symKey, pubsubTopicShardInfo) {
115
- return new Decoder(determinePubsubTopic(contentTopic, pubsubTopicShardInfo), contentTopic, symKey);
118
+ export function createDecoder(contentTopic, routingInfo, symKey) {
119
+ return new Decoder(contentTopic, routingInfo, symKey);
116
120
  }
117
121
  //# sourceMappingURL=symmetric.js.map
@@ -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;AAYxE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,SAAS,EACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,SAAS,EACT,oBAAoB,EACrB,CAAC;AAEF,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,8BAA8B,CAAC,CAAC;AAEvD,MAAM,OAAO;IAEF;IACA;IACC;IACA;IACD;IACA;IANT,YACS,WAAwB,EACxB,YAAoB,EACnB,MAAkB,EAClB,UAAuB,EACxB,YAAqB,KAAK,EAC1B,UAAwB;QALxB,gBAAW,GAAX,WAAW,CAAa;QACxB,iBAAY,GAAZ,YAAY,CAAQ;QACnB,WAAM,GAAN,MAAM,CAAY;QAClB,eAAU,GAAV,UAAU,CAAa;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AC;YACb,GAAG,CAAC,KAAK,CACP,8CAA8C,IAAI,CAAC,YAAY,EAAE,CAClE,CAAC;YACF,OAAO;QACT,CAAC;QAED,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;QAEhC,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,GAAG,CAAC,KAAK,CACP,6CAA6C,IAAI,CAAC,YAAY,EAAE,CACjE,CAAC;YACF,OAAO;QACT,CAAC;QAED,GAAG,CAAC,IAAI,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC;QAC5C,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;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAC3B,YAAoB,EACpB,WAAyB,EACzB,MAAkB;IAElB,OAAO,IAAI,OAAO,CAAC,YAAY,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;AACxD,CAAC"}
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@waku/message-encryption","version":"0.0.35-c7fe44e.0","description":"Waku Message Payload Encryption","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./ecies":{"types":"./dist/ecies.d.ts","import":"./dist/ecies.js"},"./symmetric":{"types":"./dist/symmetric.d.ts","import":"./dist/symmetric.js"},"./crypto":{"types":"./dist/crypto/index.d.ts","import":"./dist/crypto/index.js"}},"typesVersions":{"*":{"*":["*","dist/*","dist/*/index"]}},"type":"module","author":"Waku Team","homepage":"https://github.com/waku-org/js-waku/tree/master/packages/message-encryption#readme","repository":{"type":"git","url":"https://github.com/waku-org/js-waku.git"},"bugs":{"url":"https://github.com/waku-org/js-waku/issues"},"license":"MIT OR Apache-2.0","keywords":["waku","decentralized","secure","communication","web3","ethereum","dapps","privacy"],"scripts":{"build":"run-s build:**","build:esm":"tsc","build:bundle":"rollup --config rollup.config.js","fix":"run-s fix:*","fix:lint":"eslint src *.js --fix","check":"run-s check:*","check:lint":"eslint src *.js","check:spelling":"cspell \"{README.md,src/**/*.ts}\"","check:tsc":"tsc -p tsconfig.dev.json","test":"NODE_ENV=test run-s test:*","test:node":"NODE_ENV=test TS_NODE_PROJECT=./tsconfig.dev.json mocha","test:browser":"NODE_ENV=test karma start karma.conf.cjs","prepublish":"npm run build","reset-hard":"git clean -dfx -e .idea && git reset --hard && npm i && npm run build"},"engines":{"node":">=22"},"browser":{"crypto":false},"dependencies":{"@noble/secp256k1":"^1.7.1","@waku/core":"0.0.37-c7fe44e.0","@waku/interfaces":"0.0.32-c7fe44e.0","@waku/proto":"0.0.12-c7fe44e.0","@waku/utils":"0.0.25-c7fe44e.0","debug":"^4.3.4","js-sha3":"^0.9.2","uint8arrays":"^5.0.1"},"devDependencies":{"@rollup/plugin-commonjs":"^25.0.7","@rollup/plugin-json":"^6.0.0","@rollup/plugin-node-resolve":"^15.2.3","@types/chai":"^4.3.11","@types/mocha":"^10.0.6","@waku/build-utils":"*","chai":"^4.3.10","cspell":"^8.6.1","fast-check":"^3.19.0","mocha":"^10.3.0","npm-run-all":"^4.1.5","process":"^0.11.10","rollup":"^4.12.0"},"files":["dist","bundle","src/**/*.ts","!**/*.spec.*","!**/*.json","CHANGELOG.md","LICENSE","README.md"]}
1
+ {"name":"@waku/message-encryption","version":"0.0.36-3545a8e.0","description":"Waku Message Payload Encryption","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./ecies":{"types":"./dist/ecies.d.ts","import":"./dist/ecies.js"},"./symmetric":{"types":"./dist/symmetric.d.ts","import":"./dist/symmetric.js"},"./crypto":{"types":"./dist/crypto/index.d.ts","import":"./dist/crypto/index.js"}},"typesVersions":{"*":{"*":["*","dist/*","dist/*/index"]}},"type":"module","author":"Waku Team","homepage":"https://github.com/waku-org/js-waku/tree/master/packages/message-encryption#readme","repository":{"type":"git","url":"https://github.com/waku-org/js-waku.git"},"bugs":{"url":"https://github.com/waku-org/js-waku/issues"},"license":"MIT OR Apache-2.0","keywords":["waku","decentralized","secure","communication","web3","ethereum","dapps","privacy"],"scripts":{"build":"run-s build:**","build:esm":"tsc","build:bundle":"rollup --config rollup.config.js","fix":"run-s fix:*","fix:lint":"eslint src *.js --fix","check":"run-s check:*","check:lint":"eslint src *.js","check:spelling":"cspell \"{README.md,src/**/*.ts}\"","check:tsc":"tsc -p tsconfig.dev.json","test":"NODE_ENV=test run-s test:*","test:node":"NODE_ENV=test TS_NODE_PROJECT=./tsconfig.dev.json mocha","test:browser":"NODE_ENV=test karma start karma.conf.cjs","prepublish":"npm run build","reset-hard":"git clean -dfx -e .idea && git reset --hard && npm i && npm run build"},"engines":{"node":">=22"},"browser":{"crypto":false},"dependencies":{"@noble/secp256k1":"^1.7.1","@waku/core":"0.0.38-3545a8e.0","@waku/interfaces":"0.0.33-3545a8e.0","@waku/proto":"0.0.13-3545a8e.0","@waku/utils":"0.0.26-3545a8e.0","debug":"^4.3.4","js-sha3":"^0.9.2","uint8arrays":"^5.0.1"},"devDependencies":{"@rollup/plugin-commonjs":"^25.0.7","@rollup/plugin-json":"^6.0.0","@rollup/plugin-node-resolve":"^15.2.3","@types/chai":"^4.3.11","@types/mocha":"^10.0.6","@waku/build-utils":"*","chai":"^4.3.10","cspell":"^8.6.1","fast-check":"^3.19.0","mocha":"^10.3.0","npm-run-all":"^4.1.5","process":"^0.11.10","rollup":"^4.12.0"},"files":["dist","bundle","src/**/*.ts","!**/*.spec.*","!**/*.json","CHANGELOG.md","LICENSE","README.md"]}
package/src/ecies.ts CHANGED
@@ -7,11 +7,11 @@ import {
7
7
  type IMessage,
8
8
  type IMetaSetter,
9
9
  type IProtoMessage,
10
- type PubsubTopic,
11
- type SingleShardInfo
10
+ type IRoutingInfo,
11
+ type PubsubTopic
12
12
  } from "@waku/interfaces";
13
13
  import { WakuMessage } from "@waku/proto";
14
- import { determinePubsubTopic, Logger } from "@waku/utils";
14
+ import { Logger } from "@waku/utils";
15
15
 
16
16
  import { generatePrivateKey } from "./crypto/utils.js";
17
17
  import { DecodedMessage } from "./decoded_message.js";
@@ -35,8 +35,8 @@ const log = new Logger("message-encryption:ecies");
35
35
 
36
36
  class Encoder implements IEncoder {
37
37
  public constructor(
38
- public pubsubTopic: PubsubTopic,
39
38
  public contentTopic: string,
39
+ public routingInfo: IRoutingInfo,
40
40
  private publicKey: Uint8Array,
41
41
  private sigPrivKey?: Uint8Array,
42
42
  public ephemeral: boolean = false,
@@ -47,6 +47,10 @@ class Encoder implements IEncoder {
47
47
  }
48
48
  }
49
49
 
50
+ public get pubsubTopic(): PubsubTopic {
51
+ return this.routingInfo.pubsubTopic;
52
+ }
53
+
50
54
  public async toWire(message: IMessage): Promise<Uint8Array | undefined> {
51
55
  const protoMessage = await this.toProtoObj(message);
52
56
  if (!protoMessage) return;
@@ -82,10 +86,6 @@ class Encoder implements IEncoder {
82
86
  }
83
87
 
84
88
  export interface EncoderOptions extends BaseEncoderOptions {
85
- /**
86
- * @deprecated
87
- */
88
- pubsubTopic?: PubsubTopic;
89
89
  /** The public key to encrypt the payload for. */
90
90
  publicKey: Uint8Array;
91
91
  /** An optional private key to be used to sign the payload before encryption. */
@@ -105,17 +105,16 @@ export interface EncoderOptions extends BaseEncoderOptions {
105
105
  * in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
106
106
  */
107
107
  export function createEncoder({
108
- pubsubTopic,
109
- pubsubTopicShardInfo,
110
108
  contentTopic,
109
+ routingInfo,
111
110
  publicKey,
112
111
  sigPrivKey,
113
112
  ephemeral = false,
114
113
  metaSetter
115
114
  }: EncoderOptions): Encoder {
116
115
  return new Encoder(
117
- determinePubsubTopic(contentTopic, pubsubTopic ?? pubsubTopicShardInfo),
118
116
  contentTopic,
117
+ routingInfo,
119
118
  publicKey,
120
119
  sigPrivKey,
121
120
  ephemeral,
@@ -125,11 +124,11 @@ export function createEncoder({
125
124
 
126
125
  class Decoder extends DecoderV0 implements IDecoder<IEncryptedMessage> {
127
126
  public constructor(
128
- pubsubTopic: PubsubTopic,
129
127
  contentTopic: string,
128
+ routingInfo: IRoutingInfo,
130
129
  private privateKey: Uint8Array
131
130
  ) {
132
- super(pubsubTopic, contentTopic);
131
+ super(contentTopic, routingInfo);
133
132
  }
134
133
 
135
134
  public async fromProtoObj(
@@ -197,16 +196,13 @@ class Decoder extends DecoderV0 implements IDecoder<IEncryptedMessage> {
197
196
  * decode incoming messages.
198
197
  *
199
198
  * @param contentTopic The resulting decoder will only decode messages with this content topic.
199
+ * @param routingInfo
200
200
  * @param privateKey The private key used to decrypt the message.
201
201
  */
202
202
  export function createDecoder(
203
203
  contentTopic: string,
204
- privateKey: Uint8Array,
205
- pubsubTopicShardInfo?: SingleShardInfo | PubsubTopic
204
+ routingInfo: IRoutingInfo,
205
+ privateKey: Uint8Array
206
206
  ): Decoder {
207
- return new Decoder(
208
- determinePubsubTopic(contentTopic, pubsubTopicShardInfo),
209
- contentTopic,
210
- privateKey
211
- );
207
+ return new Decoder(contentTopic, routingInfo, privateKey);
212
208
  }
package/src/symmetric.ts CHANGED
@@ -7,11 +7,11 @@ import type {
7
7
  IMessage,
8
8
  IMetaSetter,
9
9
  IProtoMessage,
10
- PubsubTopic,
11
- SingleShardInfo
10
+ IRoutingInfo,
11
+ PubsubTopic
12
12
  } from "@waku/interfaces";
13
13
  import { WakuMessage } from "@waku/proto";
14
- import { determinePubsubTopic, Logger } from "@waku/utils";
14
+ import { Logger } from "@waku/utils";
15
15
 
16
16
  import { generateSymmetricKey } from "./crypto/utils.js";
17
17
  import { DecodedMessage } from "./decoded_message.js";
@@ -35,8 +35,8 @@ const log = new Logger("message-encryption:symmetric");
35
35
 
36
36
  class Encoder implements IEncoder {
37
37
  public constructor(
38
- public pubsubTopic: PubsubTopic,
39
38
  public contentTopic: string,
39
+ public routingInfo: IRoutingInfo,
40
40
  private symKey: Uint8Array,
41
41
  private sigPrivKey?: Uint8Array,
42
42
  public ephemeral: boolean = false,
@@ -47,6 +47,10 @@ class Encoder implements IEncoder {
47
47
  }
48
48
  }
49
49
 
50
+ public get pubsubTopic(): PubsubTopic {
51
+ return this.routingInfo.pubsubTopic;
52
+ }
53
+
50
54
  public async toWire(message: IMessage): Promise<Uint8Array | undefined> {
51
55
  const protoMessage = await this.toProtoObj(message);
52
56
  if (!protoMessage) return;
@@ -101,17 +105,16 @@ export interface EncoderOptions extends BaseEncoderOptions {
101
105
  * in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
102
106
  */
103
107
  export function createEncoder({
104
- pubsubTopic,
105
- pubsubTopicShardInfo,
106
108
  contentTopic,
109
+ routingInfo,
107
110
  symKey,
108
111
  sigPrivKey,
109
112
  ephemeral = false,
110
113
  metaSetter
111
114
  }: EncoderOptions): Encoder {
112
115
  return new Encoder(
113
- determinePubsubTopic(contentTopic, pubsubTopic ?? pubsubTopicShardInfo),
114
116
  contentTopic,
117
+ routingInfo,
115
118
  symKey,
116
119
  sigPrivKey,
117
120
  ephemeral,
@@ -121,11 +124,11 @@ export function createEncoder({
121
124
 
122
125
  class Decoder extends DecoderV0 implements IDecoder<IEncryptedMessage> {
123
126
  public constructor(
124
- pubsubTopic: PubsubTopic,
125
127
  contentTopic: string,
128
+ routingInfo: IRoutingInfo,
126
129
  private symKey: Uint8Array
127
130
  ) {
128
- super(pubsubTopic, contentTopic);
131
+ super(contentTopic, routingInfo);
129
132
  }
130
133
 
131
134
  public async fromProtoObj(
@@ -193,16 +196,13 @@ class Decoder extends DecoderV0 implements IDecoder<IEncryptedMessage> {
193
196
  * decode incoming messages.
194
197
  *
195
198
  * @param contentTopic The resulting decoder will only decode messages with this content topic.
199
+ * @param routingInfo Routing information, depends on the network config (static vs auto sharding)
196
200
  * @param symKey The symmetric key used to decrypt the message.
197
201
  */
198
202
  export function createDecoder(
199
203
  contentTopic: string,
200
- symKey: Uint8Array,
201
- pubsubTopicShardInfo?: SingleShardInfo | PubsubTopic
204
+ routingInfo: IRoutingInfo,
205
+ symKey: Uint8Array
202
206
  ): Decoder {
203
- return new Decoder(
204
- determinePubsubTopic(contentTopic, pubsubTopicShardInfo),
205
- contentTopic,
206
- symKey
207
- );
207
+ return new Decoder(contentTopic, routingInfo, symKey);
208
208
  }