@waku/message-encryption 0.0.24-7eb3375.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.
- package/CHANGELOG.md +31 -0
- package/bundle/crypto.js +1 -1
- package/bundle/{ecies-137fdfde.js → ecies-R65pUoo3.js} +6 -6
- package/bundle/ecies.js +3 -3
- package/bundle/encryption-zFGfcjHZ.js +6356 -0
- package/bundle/{index-268375db.js → index-alzPvot7.js} +1 -1
- package/bundle/index.js +5 -5
- package/bundle/{symmetric-d25c7b7a.js → symmetric-7aAyizy_.js} +6 -6
- package/bundle/{symmetric-58d457ca.js → symmetric-CXVjdTdV.js} +7 -28
- package/bundle/symmetric.js +3 -3
- package/dist/.tsbuildinfo +1 -1
- package/dist/crypto/ecies.js.map +1 -1
- package/dist/crypto/utils.js.map +1 -1
- package/dist/decoded_message.d.ts +6 -0
- package/dist/decoded_message.js +12 -0
- package/dist/decoded_message.js.map +1 -1
- package/dist/ecies.d.ts +7 -3
- package/dist/ecies.js +6 -6
- package/dist/ecies.js.map +1 -1
- package/dist/encryption.js.map +1 -1
- package/dist/symmetric.d.ts +3 -3
- package/dist/symmetric.js +6 -6
- package/dist/symmetric.js.map +1 -1
- package/package.json +112 -1
- package/src/decoded_message.ts +13 -0
- package/src/ecies.ts +24 -14
- package/src/symmetric.ts +19 -13
- package/bundle/encryption-d94ff773.js +0 -21078
package/dist/encryption.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"encryption.js","sourceRoot":"","sources":["../src/encryption.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EACL,KAAK,EACL,SAAS,EACT,WAAW,EACX,IAAI,EACJ,SAAS,EACV,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,WA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,GAAG,MAAM,CAAC,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC;IAChD,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAOD;;;;GAIG;AACH,MAAM,UAAU,UAAU,CACxB,OAAmB;IAEnB,MAAM,sBAAsB,GAAG,yBAAyB,CAAC,OAAO,CAAC,CAAC;IAClE,IAAI,sBAAsB,KAAK,CAAC;QAAE,OAAO;IAEzC,MAAM,WAAW,GAAG,cAAc,CAAC,OAAO,EAAE,sBAAsB,CAAC,CAAC;IACpE,MAAM,YAAY,GAAG,CAAC,GAAG,sBAAsB,CAAC;IAChD,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,YAAY,GAAG,WAAW,CAAC,CAAC;IAExE,MAAM,QAAQ,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;IAE1C,IAAI,GAAG,CAAC;IACR,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;QACxC,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACxC,MAAM,SAAS,GAAG,eAAe,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QACnD,GAAG,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;IACjC,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;AAC1B,CAAC"}
|
package/dist/symmetric.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
|
2
|
-
import type
|
2
|
+
import { type EncoderOptions as BaseEncoderOptions, type IDecoder, type IEncoder, type IMessage, type IMetaSetter, type IProtoMessage, type PubsubTopic, type SingleShardInfo } from "@waku/interfaces";
|
3
3
|
import { generateSymmetricKey } from "./crypto/utils.js";
|
4
4
|
import { DecodedMessage } from "./decoded_message.js";
|
5
5
|
import { decryptSymmetric, encryptSymmetric, postCipher, preCipher } from "./encryption.js";
|
@@ -33,7 +33,7 @@ export interface EncoderOptions extends BaseEncoderOptions {
|
|
33
33
|
* The payload can optionally be signed with the given private key as defined
|
34
34
|
* in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
|
35
35
|
*/
|
36
|
-
export declare function createEncoder({ pubsubTopic, contentTopic, symKey, sigPrivKey, ephemeral, metaSetter }: EncoderOptions): Encoder;
|
36
|
+
export declare function createEncoder({ pubsubTopic, pubsubTopicShardInfo, contentTopic, symKey, sigPrivKey, ephemeral, metaSetter }: EncoderOptions): Encoder;
|
37
37
|
declare class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
38
38
|
private symKey;
|
39
39
|
constructor(pubsubTopic: PubsubTopic, contentTopic: string, symKey: Uint8Array);
|
@@ -51,4 +51,4 @@ declare class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
|
51
51
|
* @param contentTopic The resulting decoder will only decode messages with this content topic.
|
52
52
|
* @param symKey The symmetric key used to decrypt the message.
|
53
53
|
*/
|
54
|
-
export declare function createDecoder(contentTopic: string, symKey: Uint8Array,
|
54
|
+
export declare function createDecoder(contentTopic: string, symKey: Uint8Array, pubsubTopicShardInfo?: SingleShardInfo | PubsubTopic): Decoder;
|
package/dist/symmetric.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import { DefaultPubsubTopic } from "@waku/core";
|
2
1
|
import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
|
2
|
+
import { DefaultPubsubTopic } from "@waku/interfaces";
|
3
3
|
import { WakuMessage } from "@waku/proto";
|
4
|
-
import { Logger } from "@waku/utils";
|
4
|
+
import { determinePubsubTopic, Logger } from "@waku/utils";
|
5
5
|
import { generateSymmetricKey } from "./crypto/utils.js";
|
6
6
|
import { DecodedMessage } from "./decoded_message.js";
|
7
7
|
import { decryptSymmetric, encryptSymmetric, postCipher, preCipher } from "./encryption.js";
|
@@ -64,8 +64,8 @@ class Encoder {
|
|
64
64
|
* The payload can optionally be signed with the given private key as defined
|
65
65
|
* in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
|
66
66
|
*/
|
67
|
-
export function createEncoder({ pubsubTopic = DefaultPubsubTopic, contentTopic, symKey, sigPrivKey, ephemeral = false, metaSetter }) {
|
68
|
-
return new Encoder(pubsubTopic, contentTopic, symKey, sigPrivKey, ephemeral, metaSetter);
|
67
|
+
export function createEncoder({ pubsubTopic = DefaultPubsubTopic, pubsubTopicShardInfo, contentTopic, symKey, sigPrivKey, ephemeral = false, metaSetter }) {
|
68
|
+
return new Encoder(determinePubsubTopic(contentTopic, pubsubTopic ?? pubsubTopicShardInfo), contentTopic, symKey, sigPrivKey, ephemeral, metaSetter);
|
69
69
|
}
|
70
70
|
class Decoder extends DecoderV0 {
|
71
71
|
symKey;
|
@@ -112,7 +112,7 @@ class Decoder extends DecoderV0 {
|
|
112
112
|
* @param contentTopic The resulting decoder will only decode messages with this content topic.
|
113
113
|
* @param symKey The symmetric key used to decrypt the message.
|
114
114
|
*/
|
115
|
-
export function createDecoder(contentTopic, symKey,
|
116
|
-
return new Decoder(
|
115
|
+
export function createDecoder(contentTopic, symKey, pubsubTopicShardInfo = DefaultPubsubTopic) {
|
116
|
+
return new Decoder(determinePubsubTopic(contentTopic, pubsubTopicShardInfo), contentTopic, symKey);
|
117
117
|
}
|
118
118
|
//# 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,
|
1
|
+
{"version":3,"file":"symmetric.js","sourceRoot":"","sources":["../src/symmetric.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAEL,kBAAkB,EAQnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,W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,EAAE,oBAAoB,CAAC,EACxD,YAAY,EACZ,MAAM,CACP,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
@@ -1 +1,112 @@
|
|
1
|
-
{
|
1
|
+
{
|
2
|
+
"name": "@waku/message-encryption",
|
3
|
+
"version": "0.0.24",
|
4
|
+
"description": "Waku Message Payload Encryption",
|
5
|
+
"types": "./dist/index.d.ts",
|
6
|
+
"module": "./dist/index.js",
|
7
|
+
"exports": {
|
8
|
+
".": {
|
9
|
+
"types": "./dist/index.d.ts",
|
10
|
+
"import": "./dist/index.js"
|
11
|
+
},
|
12
|
+
"./ecies": {
|
13
|
+
"types": "./dist/ecies.d.ts",
|
14
|
+
"import": "./dist/ecies.js"
|
15
|
+
},
|
16
|
+
"./symmetric": {
|
17
|
+
"types": "./dist/symmetric.d.ts",
|
18
|
+
"import": "./dist/symmetric.js"
|
19
|
+
},
|
20
|
+
"./crypto": {
|
21
|
+
"types": "./dist/crypto/index.d.ts",
|
22
|
+
"import": "./dist/crypto/index.js"
|
23
|
+
}
|
24
|
+
},
|
25
|
+
"typesVersions": {
|
26
|
+
"*": {
|
27
|
+
"*": [
|
28
|
+
"*",
|
29
|
+
"dist/*",
|
30
|
+
"dist/*/index"
|
31
|
+
]
|
32
|
+
}
|
33
|
+
},
|
34
|
+
"type": "module",
|
35
|
+
"author": "Waku Team",
|
36
|
+
"homepage": "https://github.com/waku-org/js-waku/tree/master/packages/message-encryption#readme",
|
37
|
+
"repository": {
|
38
|
+
"type": "git",
|
39
|
+
"url": "https://github.com/waku-org/js-waku.git"
|
40
|
+
},
|
41
|
+
"bugs": {
|
42
|
+
"url": "https://github.com/waku-org/js-waku/issues"
|
43
|
+
},
|
44
|
+
"license": "MIT OR Apache-2.0",
|
45
|
+
"keywords": [
|
46
|
+
"waku",
|
47
|
+
"decentralized",
|
48
|
+
"secure",
|
49
|
+
"communication",
|
50
|
+
"web3",
|
51
|
+
"ethereum",
|
52
|
+
"dapps",
|
53
|
+
"privacy"
|
54
|
+
],
|
55
|
+
"scripts": {
|
56
|
+
"build": "run-s build:**",
|
57
|
+
"build:esm": "tsc",
|
58
|
+
"build:bundle": "rollup --config rollup.config.js",
|
59
|
+
"fix": "run-s fix:*",
|
60
|
+
"fix:lint": "eslint src *.js --fix",
|
61
|
+
"check": "run-s check:*",
|
62
|
+
"check:lint": "eslint src *.js",
|
63
|
+
"check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
|
64
|
+
"check:tsc": "tsc -p tsconfig.dev.json",
|
65
|
+
"test": "NODE_ENV=test run-s test:*",
|
66
|
+
"test:node": "NODE_ENV=test TS_NODE_PROJECT=./tsconfig.dev.json mocha",
|
67
|
+
"test:browser": "NODE_ENV=test karma start karma.conf.cjs",
|
68
|
+
"prepublish": "npm run build",
|
69
|
+
"reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build"
|
70
|
+
},
|
71
|
+
"engines": {
|
72
|
+
"node": ">=18"
|
73
|
+
},
|
74
|
+
"browser": {
|
75
|
+
"crypto": false
|
76
|
+
},
|
77
|
+
"dependencies": {
|
78
|
+
"@noble/secp256k1": "^1.7.1",
|
79
|
+
"@waku/core": "0.0.26",
|
80
|
+
"@waku/interfaces": "0.0.21",
|
81
|
+
"@waku/proto": "0.0.6",
|
82
|
+
"@waku/utils": "0.0.14",
|
83
|
+
"debug": "^4.3.4",
|
84
|
+
"js-sha3": "^0.9.2",
|
85
|
+
"uint8arrays": "^5.0.0"
|
86
|
+
},
|
87
|
+
"devDependencies": {
|
88
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
89
|
+
"@rollup/plugin-json": "^6.0.0",
|
90
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
91
|
+
"@types/chai": "^4.3.11",
|
92
|
+
"@types/mocha": "^10.0.1",
|
93
|
+
"@waku/build-utils": "*",
|
94
|
+
"chai": "^4.3.10",
|
95
|
+
"cspell": "^7.3.2",
|
96
|
+
"fast-check": "^3.14.0",
|
97
|
+
"mocha": "^10.2.0",
|
98
|
+
"npm-run-all": "^4.1.5",
|
99
|
+
"process": "^0.11.10",
|
100
|
+
"rollup": "^4.6.0"
|
101
|
+
},
|
102
|
+
"files": [
|
103
|
+
"dist",
|
104
|
+
"bundle",
|
105
|
+
"src/**/*.ts",
|
106
|
+
"!**/*.spec.*",
|
107
|
+
"!**/*.json",
|
108
|
+
"CHANGELOG.md",
|
109
|
+
"LICENSE",
|
110
|
+
"README.md"
|
111
|
+
]
|
112
|
+
}
|
package/src/decoded_message.ts
CHANGED
@@ -3,6 +3,7 @@ import {
|
|
3
3
|
proto
|
4
4
|
} from "@waku/core/lib/message/version_0";
|
5
5
|
import type { IDecodedMessage } from "@waku/interfaces";
|
6
|
+
import { equals } from "uint8arrays/equals";
|
6
7
|
|
7
8
|
export class DecodedMessage
|
8
9
|
extends DecodedMessageV0
|
@@ -24,4 +25,16 @@ export class DecodedMessage
|
|
24
25
|
get payload(): Uint8Array {
|
25
26
|
return this._decodedPayload;
|
26
27
|
}
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Verify the message's signature against the public key.
|
31
|
+
*
|
32
|
+
* @returns true if the signature matches the public key, false if not or if no signature is present.
|
33
|
+
*/
|
34
|
+
verifySignature(publicKey: Uint8Array): boolean {
|
35
|
+
if (this.signaturePublicKey) {
|
36
|
+
return equals(this.signaturePublicKey, publicKey);
|
37
|
+
}
|
38
|
+
return false;
|
39
|
+
}
|
27
40
|
}
|
package/src/ecies.ts
CHANGED
@@ -1,16 +1,17 @@
|
|
1
|
-
import { DefaultPubsubTopic } from "@waku/core";
|
2
1
|
import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
|
3
|
-
import
|
4
|
-
EncoderOptions as BaseEncoderOptions,
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
|
15
16
|
import { generatePrivateKey } from "./crypto/utils.js";
|
16
17
|
import { DecodedMessage } from "./decoded_message.js";
|
@@ -79,6 +80,10 @@ class Encoder implements IEncoder {
|
|
79
80
|
}
|
80
81
|
|
81
82
|
export interface EncoderOptions extends BaseEncoderOptions {
|
83
|
+
/**
|
84
|
+
* @deprecated
|
85
|
+
*/
|
86
|
+
pubsubTopic?: PubsubTopic;
|
82
87
|
/** The public key to encrypt the payload for. */
|
83
88
|
publicKey: Uint8Array;
|
84
89
|
/** An optional private key to be used to sign the payload before encryption. */
|
@@ -98,7 +103,8 @@ export interface EncoderOptions extends BaseEncoderOptions {
|
|
98
103
|
* in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
|
99
104
|
*/
|
100
105
|
export function createEncoder({
|
101
|
-
pubsubTopic
|
106
|
+
pubsubTopic,
|
107
|
+
pubsubTopicShardInfo,
|
102
108
|
contentTopic,
|
103
109
|
publicKey,
|
104
110
|
sigPrivKey,
|
@@ -106,7 +112,7 @@ export function createEncoder({
|
|
106
112
|
metaSetter
|
107
113
|
}: EncoderOptions): Encoder {
|
108
114
|
return new Encoder(
|
109
|
-
pubsubTopic,
|
115
|
+
determinePubsubTopic(contentTopic, pubsubTopic ?? pubsubTopicShardInfo),
|
110
116
|
contentTopic,
|
111
117
|
publicKey,
|
112
118
|
sigPrivKey,
|
@@ -194,7 +200,11 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
|
194
200
|
export function createDecoder(
|
195
201
|
contentTopic: string,
|
196
202
|
privateKey: Uint8Array,
|
197
|
-
|
203
|
+
pubsubTopicShardInfo: SingleShardInfo | PubsubTopic = DefaultPubsubTopic
|
198
204
|
): Decoder {
|
199
|
-
return new Decoder(
|
205
|
+
return new Decoder(
|
206
|
+
determinePubsubTopic(contentTopic, pubsubTopicShardInfo),
|
207
|
+
contentTopic,
|
208
|
+
privateKey
|
209
|
+
);
|
200
210
|
}
|
package/src/symmetric.ts
CHANGED
@@ -1,16 +1,17 @@
|
|
1
|
-
import { DefaultPubsubTopic } from "@waku/core";
|
2
1
|
import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
|
3
|
-
import
|
4
|
-
EncoderOptions as BaseEncoderOptions,
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
|
15
16
|
import { generateSymmetricKey } from "./crypto/utils.js";
|
16
17
|
import { DecodedMessage } from "./decoded_message.js";
|
@@ -99,6 +100,7 @@ export interface EncoderOptions extends BaseEncoderOptions {
|
|
99
100
|
*/
|
100
101
|
export function createEncoder({
|
101
102
|
pubsubTopic = DefaultPubsubTopic,
|
103
|
+
pubsubTopicShardInfo,
|
102
104
|
contentTopic,
|
103
105
|
symKey,
|
104
106
|
sigPrivKey,
|
@@ -106,7 +108,7 @@ export function createEncoder({
|
|
106
108
|
metaSetter
|
107
109
|
}: EncoderOptions): Encoder {
|
108
110
|
return new Encoder(
|
109
|
-
pubsubTopic,
|
111
|
+
determinePubsubTopic(contentTopic, pubsubTopic ?? pubsubTopicShardInfo),
|
110
112
|
contentTopic,
|
111
113
|
symKey,
|
112
114
|
sigPrivKey,
|
@@ -194,7 +196,11 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
|
194
196
|
export function createDecoder(
|
195
197
|
contentTopic: string,
|
196
198
|
symKey: Uint8Array,
|
197
|
-
|
199
|
+
pubsubTopicShardInfo: SingleShardInfo | PubsubTopic = DefaultPubsubTopic
|
198
200
|
): Decoder {
|
199
|
-
return new Decoder(
|
201
|
+
return new Decoder(
|
202
|
+
determinePubsubTopic(contentTopic, pubsubTopicShardInfo),
|
203
|
+
contentTopic,
|
204
|
+
symKey
|
205
|
+
);
|
200
206
|
}
|