@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/CHANGELOG.md
CHANGED
@@ -68,6 +68,37 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
68
68
|
* @waku/interfaces bumped from 0.0.17 to 0.0.18
|
69
69
|
* @waku/utils bumped from 0.0.10 to 0.0.11
|
70
70
|
|
71
|
+
## [0.0.24](https://github.com/waku-org/js-waku/compare/message-encryption-v0.0.23...message-encryption-v0.0.24) (2024-01-10)
|
72
|
+
|
73
|
+
|
74
|
+
### ⚠ BREAKING CHANGES
|
75
|
+
|
76
|
+
* add support for sharded pubsub topics & remove support for named pubsub topics ([#1697](https://github.com/waku-org/js-waku/issues/1697))
|
77
|
+
* export crypto primitives ([#1728](https://github.com/waku-org/js-waku/issues/1728))
|
78
|
+
* change all instances of `PubSubTopic` to `PubsubTopic` ([#1703](https://github.com/waku-org/js-waku/issues/1703))
|
79
|
+
|
80
|
+
### Features
|
81
|
+
|
82
|
+
* Add support for autosharded pubsub topics ([2bc3735](https://github.com/waku-org/js-waku/commit/2bc3735e4dcf85f06b3dee542024d7f20a40fac2))
|
83
|
+
* Add support for sharded pubsub topics & remove support for named pubsub topics ([#1697](https://github.com/waku-org/js-waku/issues/1697)) ([4cf2ffe](https://github.com/waku-org/js-waku/commit/4cf2ffefa75e0571805036b71644d2cdd4fe3192))
|
84
|
+
* Export crypto primitives ([#1728](https://github.com/waku-org/js-waku/issues/1728)) ([7eb3375](https://github.com/waku-org/js-waku/commit/7eb3375f50265240096d70bd2814549c8156a0eb))
|
85
|
+
* New `verifySignature` ([2f67a3b](https://github.com/waku-org/js-waku/commit/2f67a3baffc085d61b057f9fdb5ab404bfd70a1b))
|
86
|
+
|
87
|
+
|
88
|
+
### Miscellaneous Chores
|
89
|
+
|
90
|
+
* Change all instances of `PubSubTopic` to `PubsubTopic` ([#1703](https://github.com/waku-org/js-waku/issues/1703)) ([3166a51](https://github.com/waku-org/js-waku/commit/3166a5135e77583da4fa722ee2aa47c785854a38))
|
91
|
+
|
92
|
+
|
93
|
+
### Dependencies
|
94
|
+
|
95
|
+
* The following workspace dependencies were updated
|
96
|
+
* dependencies
|
97
|
+
* @waku/core bumped from 0.0.25 to 0.0.26
|
98
|
+
* @waku/interfaces bumped from 0.0.20 to 0.0.21
|
99
|
+
* @waku/proto bumped from 0.0.5 to 0.0.6
|
100
|
+
* @waku/utils bumped from 0.0.13 to 0.0.14
|
101
|
+
|
71
102
|
## [0.0.23](https://github.com/waku-org/js-waku/compare/message-encryption-v0.0.22...message-encryption-v0.0.23) (2023-11-01)
|
72
103
|
|
73
104
|
|
package/bundle/crypto.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export { e as ecies, g as generatePrivateKey, a as generateSymmetricKey, b as getPublicKey, c as getSubtle, k as keccak256, r as randomBytes, s as sha256, d as sign, f as symmetric } from './symmetric-CXVjdTdV.js';
|
@@ -0,0 +1,124 @@
|
|
1
|
+
import { L as Logger, d as determinePubsubTopic, D as DefaultPubsubTopic, W as WakuMessage, p as preCipher, e as encryptAsymmetric, a as Decoder$1, b as decryptAsymmetric, c as postCipher, f as DecodedMessage } from './encryption-zFGfcjHZ.js';
|
2
|
+
import { V as Version, O as OneMillion, g as generatePrivateKey } from './symmetric-CXVjdTdV.js';
|
3
|
+
|
4
|
+
const log = new Logger("message-encryption:ecies");
|
5
|
+
class Encoder {
|
6
|
+
pubsubTopic;
|
7
|
+
contentTopic;
|
8
|
+
publicKey;
|
9
|
+
sigPrivKey;
|
10
|
+
ephemeral;
|
11
|
+
metaSetter;
|
12
|
+
constructor(pubsubTopic, contentTopic, publicKey, sigPrivKey, ephemeral = false, metaSetter) {
|
13
|
+
this.pubsubTopic = pubsubTopic;
|
14
|
+
this.contentTopic = contentTopic;
|
15
|
+
this.publicKey = publicKey;
|
16
|
+
this.sigPrivKey = sigPrivKey;
|
17
|
+
this.ephemeral = ephemeral;
|
18
|
+
this.metaSetter = metaSetter;
|
19
|
+
if (!contentTopic || contentTopic === "") {
|
20
|
+
throw new Error("Content topic must be specified");
|
21
|
+
}
|
22
|
+
}
|
23
|
+
async toWire(message) {
|
24
|
+
const protoMessage = await this.toProtoObj(message);
|
25
|
+
if (!protoMessage)
|
26
|
+
return;
|
27
|
+
return WakuMessage.encode(protoMessage);
|
28
|
+
}
|
29
|
+
async toProtoObj(message) {
|
30
|
+
const timestamp = message.timestamp ?? new Date();
|
31
|
+
const preparedPayload = await preCipher(message.payload, this.sigPrivKey);
|
32
|
+
const payload = await encryptAsymmetric(preparedPayload, this.publicKey);
|
33
|
+
const protoMessage = {
|
34
|
+
payload,
|
35
|
+
version: Version,
|
36
|
+
contentTopic: this.contentTopic,
|
37
|
+
timestamp: BigInt(timestamp.valueOf()) * OneMillion,
|
38
|
+
meta: undefined,
|
39
|
+
rateLimitProof: message.rateLimitProof,
|
40
|
+
ephemeral: this.ephemeral
|
41
|
+
};
|
42
|
+
if (this.metaSetter) {
|
43
|
+
const meta = this.metaSetter(protoMessage);
|
44
|
+
return { ...protoMessage, meta };
|
45
|
+
}
|
46
|
+
return protoMessage;
|
47
|
+
}
|
48
|
+
}
|
49
|
+
/**
|
50
|
+
* Creates an encoder that encrypts messages using ECIES for the given public,
|
51
|
+
* as defined in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
|
52
|
+
*
|
53
|
+
* An encoder is used to encode messages in the [`14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
|
54
|
+
* format to be sent over the Waku network. The resulting encoder can then be
|
55
|
+
* pass to { @link @waku/interfaces!ISender.send } or
|
56
|
+
* { @link @waku/interfaces!ISender.send } to automatically encrypt
|
57
|
+
* and encode outgoing messages.
|
58
|
+
* The payload can optionally be signed with the given private key as defined
|
59
|
+
* in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
|
60
|
+
*/
|
61
|
+
function createEncoder({ pubsubTopic, pubsubTopicShardInfo, contentTopic, publicKey, sigPrivKey, ephemeral = false, metaSetter }) {
|
62
|
+
return new Encoder(determinePubsubTopic(contentTopic, pubsubTopic ?? pubsubTopicShardInfo), contentTopic, publicKey, sigPrivKey, ephemeral, metaSetter);
|
63
|
+
}
|
64
|
+
class Decoder extends Decoder$1 {
|
65
|
+
privateKey;
|
66
|
+
constructor(pubsubTopic, contentTopic, privateKey) {
|
67
|
+
super(pubsubTopic, contentTopic);
|
68
|
+
this.privateKey = privateKey;
|
69
|
+
}
|
70
|
+
async fromProtoObj(pubsubTopic, protoMessage) {
|
71
|
+
const cipherPayload = protoMessage.payload;
|
72
|
+
if (protoMessage.version !== Version) {
|
73
|
+
log.error("Failed to decrypt due to incorrect version, expected:", Version, ", actual:", protoMessage.version);
|
74
|
+
return;
|
75
|
+
}
|
76
|
+
let payload;
|
77
|
+
try {
|
78
|
+
payload = await decryptAsymmetric(cipherPayload, this.privateKey);
|
79
|
+
}
|
80
|
+
catch (e) {
|
81
|
+
log.error(`Failed to decrypt message using asymmetric decryption for contentTopic: ${this.contentTopic}`, e);
|
82
|
+
return;
|
83
|
+
}
|
84
|
+
if (!payload) {
|
85
|
+
log.error(`Failed to decrypt payload for contentTopic ${this.contentTopic}`);
|
86
|
+
return;
|
87
|
+
}
|
88
|
+
const res = postCipher(payload);
|
89
|
+
if (!res) {
|
90
|
+
log.error(`Failed to decode payload for contentTopic ${this.contentTopic}`);
|
91
|
+
return;
|
92
|
+
}
|
93
|
+
log.info("Message decrypted", protoMessage);
|
94
|
+
return new DecodedMessage(pubsubTopic, protoMessage, res.payload, res.sig?.signature, res.sig?.publicKey);
|
95
|
+
}
|
96
|
+
}
|
97
|
+
/**
|
98
|
+
* Creates a decoder that decrypts messages using ECIES, using the given private
|
99
|
+
* key as defined in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
|
100
|
+
*
|
101
|
+
* A decoder is used to decode messages from the [14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
|
102
|
+
* format when received from the Waku network. The resulting decoder can then be
|
103
|
+
* pass to { @link @waku/interfaces!IReceiver.subscribe } to automatically decrypt and
|
104
|
+
* decode incoming messages.
|
105
|
+
*
|
106
|
+
* @param contentTopic The resulting decoder will only decode messages with this content topic.
|
107
|
+
* @param privateKey The private key used to decrypt the message.
|
108
|
+
*/
|
109
|
+
function createDecoder(contentTopic, privateKey, pubsubTopicShardInfo = DefaultPubsubTopic) {
|
110
|
+
return new Decoder(determinePubsubTopic(contentTopic, pubsubTopicShardInfo), contentTopic, privateKey);
|
111
|
+
}
|
112
|
+
|
113
|
+
var ecies = /*#__PURE__*/Object.freeze({
|
114
|
+
__proto__: null,
|
115
|
+
createDecoder: createDecoder,
|
116
|
+
createEncoder: createEncoder,
|
117
|
+
decryptAsymmetric: decryptAsymmetric,
|
118
|
+
encryptAsymmetric: encryptAsymmetric,
|
119
|
+
generatePrivateKey: generatePrivateKey,
|
120
|
+
postCipher: postCipher,
|
121
|
+
preCipher: preCipher
|
122
|
+
});
|
123
|
+
|
124
|
+
export { createDecoder as a, createEncoder as c, ecies as e };
|
package/bundle/ecies.js
CHANGED
@@ -1 +1,3 @@
|
|
1
|
-
export { b as
|
1
|
+
export { b as decryptAsymmetric, e as encryptAsymmetric, c as postCipher, p as preCipher } from './encryption-zFGfcjHZ.js';
|
2
|
+
export { g as generatePrivateKey } from './symmetric-CXVjdTdV.js';
|
3
|
+
export { a as createDecoder, c as createEncoder } from './ecies-R65pUoo3.js';
|