@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.
- package/CHANGELOG.md +31 -0
- package/bundle/crypto.js +1 -0
- package/bundle/ecies-R65pUoo3.js +124 -0
- package/bundle/ecies.js +3 -1
- package/bundle/encryption-zFGfcjHZ.js +6356 -0
- package/bundle/index-alzPvot7.js +17 -0
- package/bundle/index.js +5 -1
- package/bundle/symmetric-7aAyizy_.js +124 -0
- package/bundle/symmetric-CXVjdTdV.js +2815 -0
- package/bundle/symmetric.js +3 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/crypto/ecies.js +1 -1
- package/dist/crypto/ecies.js.map +1 -1
- package/dist/crypto/index.d.ts +3 -29
- package/dist/crypto/index.js +3 -59
- package/dist/crypto/index.js.map +1 -1
- package/dist/crypto/symmetric.js +2 -2
- package/dist/crypto/symmetric.js.map +1 -1
- package/dist/crypto/utils.d.ts +29 -0
- package/dist/crypto/utils.js +60 -0
- package/dist/crypto/utils.js.map +1 -0
- 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 +13 -10
- package/dist/ecies.js +10 -9
- package/dist/ecies.js.map +1 -1
- package/dist/{waku_payload.d.ts → encryption.d.ts} +5 -1
- package/dist/{waku_payload.js → encryption.js} +3 -5
- package/dist/encryption.js.map +1 -0
- package/dist/index.d.ts +1 -6
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/{constants.d.ts → misc.d.ts} +2 -0
- package/dist/{constants.js → misc.js} +3 -1
- package/dist/misc.js.map +1 -0
- package/dist/symmetric.d.ts +9 -9
- package/dist/symmetric.js +10 -9
- package/dist/symmetric.js.map +1 -1
- package/package.json +112 -1
- package/src/crypto/ecies.ts +1 -1
- package/src/crypto/index.ts +3 -76
- package/src/crypto/symmetric.ts +2 -2
- package/src/crypto/utils.ts +76 -0
- package/src/decoded_message.ts +13 -0
- package/src/ecies.ts +36 -25
- package/src/{waku_payload.ts → encryption.ts} +13 -6
- package/src/index.ts +1 -9
- package/src/{constants.ts → misc.ts} +4 -0
- package/src/symmetric.ts +32 -21
- package/bundle/index-62691783.js +0 -25363
- package/dist/constants.js.map +0 -1
- 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 {
|
4
|
-
|
5
|
-
|
6
|
-
IDecoder,
|
7
|
-
IEncoder,
|
8
|
-
IMessage,
|
9
|
-
|
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 "./
|
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 {
|
30
|
-
|
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:
|
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
|
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:
|
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
|
-
|
203
|
+
pubsubTopicShardInfo: SingleShardInfo | PubsubTopic = DefaultPubsubTopic
|
197
204
|
): Decoder {
|
198
|
-
return new Decoder(
|
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 {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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";
|
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
|
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
|
|
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 "./
|
22
|
-
|
23
|
-
import { generateSymmetricKey, OneMillion, Version } from "./index.js";
|
23
|
+
} from "./encryption.js";
|
24
|
+
import { OneMillion, Version } from "./misc.js";
|
24
25
|
|
25
|
-
export {
|
26
|
-
|
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:
|
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 =
|
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:
|
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
|
-
|
199
|
+
pubsubTopicShardInfo: SingleShardInfo | PubsubTopic = DefaultPubsubTopic
|
193
200
|
): Decoder {
|
194
|
-
return new Decoder(
|
201
|
+
return new Decoder(
|
202
|
+
determinePubsubTopic(contentTopic, pubsubTopicShardInfo),
|
203
|
+
contentTopic,
|
204
|
+
symKey
|
205
|
+
);
|
195
206
|
}
|