@waku/message-encryption 0.0.4 → 0.0.6
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 +43 -0
- package/README.md +65 -0
- package/bundle/ecies.js +1 -0
- package/bundle/index-80756c1f.js +15281 -0
- package/bundle/index.js +1 -13530
- package/bundle/symmetric.js +1 -0
- package/dist/crypto/ecies.d.ts +17 -0
- package/dist/crypto/ecies.js +126 -0
- package/dist/crypto/ecies.js.map +1 -0
- package/dist/{crypto.d.ts → crypto/index.d.ts} +0 -0
- package/dist/{crypto.js → crypto/index.js} +2 -2
- package/dist/crypto/index.js.map +1 -0
- package/dist/crypto/symmetric.d.ts +3 -0
- package/dist/crypto/symmetric.js +18 -0
- package/dist/crypto/symmetric.js.map +1 -0
- package/dist/ecies.d.ts +45 -11
- package/dist/ecies.js +97 -112
- package/dist/ecies.js.map +1 -1
- package/dist/index.d.ts +7 -84
- package/dist/index.js +6 -316
- package/dist/index.js.map +1 -1
- package/dist/symmetric.d.ts +51 -3
- package/dist/symmetric.js +107 -14
- package/dist/symmetric.js.map +1 -1
- package/dist/waku_payload.d.ts +53 -0
- package/dist/waku_payload.js +178 -0
- package/dist/waku_payload.js.map +1 -0
- package/package.json +19 -2
- package/src/crypto/ecies.ts +194 -0
- package/src/{crypto.ts → crypto/index.ts} +1 -1
- package/src/crypto/symmetric.ts +33 -0
- package/src/ecies.ts +147 -173
- package/src/index.ts +12 -444
- package/src/symmetric.ts +161 -27
- package/src/waku_payload.ts +239 -0
- package/dist/crypto.js.map +0 -1
@@ -0,0 +1 @@
|
|
1
|
+
export { D as DecodedMessage, f as createDecoder, e as createEncoder, d as generateSymmetricKey } from './index-80756c1f.js';
|
@@ -0,0 +1,17 @@
|
|
1
|
+
/**
|
2
|
+
* Encrypt message for given recipient's public key.
|
3
|
+
*
|
4
|
+
* @param publicKeyTo Recipient's public key (65 bytes)
|
5
|
+
* @param msg The message being encrypted
|
6
|
+
* @return A promise that resolves with the ECIES structure serialized
|
7
|
+
*/
|
8
|
+
export declare function encrypt(publicKeyTo: Uint8Array, msg: Uint8Array): Promise<Uint8Array>;
|
9
|
+
/**
|
10
|
+
* Decrypt message using given private key.
|
11
|
+
*
|
12
|
+
* @param privateKey A 32-byte private key of recipient of the message
|
13
|
+
* @param encrypted ECIES serialized structure (result of ECIES encryption)
|
14
|
+
* @returns The clear text
|
15
|
+
* @throws Error If decryption fails
|
16
|
+
*/
|
17
|
+
export declare function decrypt(privateKey: Uint8Array, encrypted: Uint8Array): Promise<Uint8Array>;
|
@@ -0,0 +1,126 @@
|
|
1
|
+
import * as secp from "@noble/secp256k1";
|
2
|
+
import { concat, hexToBytes } from "@waku/byte-utils";
|
3
|
+
import { getSubtle, randomBytes, sha256 } from "./index.js";
|
4
|
+
/**
|
5
|
+
* HKDF as implemented in go-ethereum.
|
6
|
+
*/
|
7
|
+
function kdf(secret, outputLength) {
|
8
|
+
let ctr = 1;
|
9
|
+
let written = 0;
|
10
|
+
let willBeResult = Promise.resolve(new Uint8Array());
|
11
|
+
while (written < outputLength) {
|
12
|
+
const counters = new Uint8Array([ctr >> 24, ctr >> 16, ctr >> 8, ctr]);
|
13
|
+
const countersSecret = concat([counters, secret], counters.length + secret.length);
|
14
|
+
const willBeHashResult = sha256(countersSecret);
|
15
|
+
willBeResult = willBeResult.then((result) => willBeHashResult.then((hashResult) => {
|
16
|
+
const _hashResult = new Uint8Array(hashResult);
|
17
|
+
return concat([result, _hashResult], result.length + _hashResult.length);
|
18
|
+
}));
|
19
|
+
written += 32;
|
20
|
+
ctr += 1;
|
21
|
+
}
|
22
|
+
return willBeResult;
|
23
|
+
}
|
24
|
+
function aesCtrEncrypt(counter, key, data) {
|
25
|
+
return getSubtle()
|
26
|
+
.importKey("raw", key, "AES-CTR", false, ["encrypt"])
|
27
|
+
.then((cryptoKey) => getSubtle().encrypt({ name: "AES-CTR", counter: counter, length: 128 }, cryptoKey, data))
|
28
|
+
.then((bytes) => new Uint8Array(bytes));
|
29
|
+
}
|
30
|
+
function aesCtrDecrypt(counter, key, data) {
|
31
|
+
return getSubtle()
|
32
|
+
.importKey("raw", key, "AES-CTR", false, ["decrypt"])
|
33
|
+
.then((cryptoKey) => getSubtle().decrypt({ name: "AES-CTR", counter: counter, length: 128 }, cryptoKey, data))
|
34
|
+
.then((bytes) => new Uint8Array(bytes));
|
35
|
+
}
|
36
|
+
function hmacSha256Sign(key, msg) {
|
37
|
+
const algorithm = { name: "HMAC", hash: { name: "SHA-256" } };
|
38
|
+
return getSubtle()
|
39
|
+
.importKey("raw", key, algorithm, false, ["sign"])
|
40
|
+
.then((cryptoKey) => getSubtle().sign(algorithm, cryptoKey, msg))
|
41
|
+
.then((bytes) => new Uint8Array(bytes));
|
42
|
+
}
|
43
|
+
function hmacSha256Verify(key, msg, sig) {
|
44
|
+
const algorithm = { name: "HMAC", hash: { name: "SHA-256" } };
|
45
|
+
const _key = getSubtle().importKey("raw", key, algorithm, false, ["verify"]);
|
46
|
+
return _key.then((cryptoKey) => getSubtle().verify(algorithm, cryptoKey, sig, msg));
|
47
|
+
}
|
48
|
+
/**
|
49
|
+
* Derive shared secret for given private and public keys.
|
50
|
+
*
|
51
|
+
* @param privateKeyA Sender's private key (32 bytes)
|
52
|
+
* @param publicKeyB Recipient's public key (65 bytes)
|
53
|
+
* @returns A promise that resolves with the derived shared secret (Px, 32 bytes)
|
54
|
+
* @throws Error If arguments are invalid
|
55
|
+
*/
|
56
|
+
function derive(privateKeyA, publicKeyB) {
|
57
|
+
if (privateKeyA.length !== 32) {
|
58
|
+
throw new Error(`Bad private key, it should be 32 bytes but it's actually ${privateKeyA.length} bytes long`);
|
59
|
+
}
|
60
|
+
else if (publicKeyB.length !== 65) {
|
61
|
+
throw new Error(`Bad public key, it should be 65 bytes but it's actually ${publicKeyB.length} bytes long`);
|
62
|
+
}
|
63
|
+
else if (publicKeyB[0] !== 4) {
|
64
|
+
throw new Error("Bad public key, a valid public key would begin with 4");
|
65
|
+
}
|
66
|
+
else {
|
67
|
+
const px = secp.getSharedSecret(privateKeyA, publicKeyB, true);
|
68
|
+
// Remove the compression prefix
|
69
|
+
return new Uint8Array(hexToBytes(px).slice(1));
|
70
|
+
}
|
71
|
+
}
|
72
|
+
/**
|
73
|
+
* Encrypt message for given recipient's public key.
|
74
|
+
*
|
75
|
+
* @param publicKeyTo Recipient's public key (65 bytes)
|
76
|
+
* @param msg The message being encrypted
|
77
|
+
* @return A promise that resolves with the ECIES structure serialized
|
78
|
+
*/
|
79
|
+
export async function encrypt(publicKeyTo, msg) {
|
80
|
+
const ephemPrivateKey = randomBytes(32);
|
81
|
+
const sharedPx = await derive(ephemPrivateKey, publicKeyTo);
|
82
|
+
const hash = await kdf(sharedPx, 32);
|
83
|
+
const iv = randomBytes(16);
|
84
|
+
const encryptionKey = hash.slice(0, 16);
|
85
|
+
const cipherText = await aesCtrEncrypt(iv, encryptionKey, msg);
|
86
|
+
const ivCipherText = concat([iv, cipherText], iv.length + cipherText.length);
|
87
|
+
const macKey = await sha256(hash.slice(16));
|
88
|
+
const hmac = await hmacSha256Sign(macKey, ivCipherText);
|
89
|
+
const ephemPublicKey = secp.getPublicKey(ephemPrivateKey, false);
|
90
|
+
return concat([ephemPublicKey, ivCipherText, hmac], ephemPublicKey.length + ivCipherText.length + hmac.length);
|
91
|
+
}
|
92
|
+
const metaLength = 1 + 64 + 16 + 32;
|
93
|
+
/**
|
94
|
+
* Decrypt message using given private key.
|
95
|
+
*
|
96
|
+
* @param privateKey A 32-byte private key of recipient of the message
|
97
|
+
* @param encrypted ECIES serialized structure (result of ECIES encryption)
|
98
|
+
* @returns The clear text
|
99
|
+
* @throws Error If decryption fails
|
100
|
+
*/
|
101
|
+
export async function decrypt(privateKey, encrypted) {
|
102
|
+
if (encrypted.length <= metaLength) {
|
103
|
+
throw new Error(`Invalid Ciphertext. Data is too small. It should ba at least ${metaLength} bytes`);
|
104
|
+
}
|
105
|
+
else if (encrypted[0] !== 4) {
|
106
|
+
throw new Error(`Not a valid ciphertext. It should begin with 4 but actually begin with ${encrypted[0]}`);
|
107
|
+
}
|
108
|
+
else {
|
109
|
+
// deserialize
|
110
|
+
const ephemPublicKey = encrypted.slice(0, 65);
|
111
|
+
const cipherTextLength = encrypted.length - metaLength;
|
112
|
+
const iv = encrypted.slice(65, 65 + 16);
|
113
|
+
const cipherAndIv = encrypted.slice(65, 65 + 16 + cipherTextLength);
|
114
|
+
const ciphertext = cipherAndIv.slice(16);
|
115
|
+
const msgMac = encrypted.slice(65 + 16 + cipherTextLength);
|
116
|
+
// check HMAC
|
117
|
+
const px = derive(privateKey, ephemPublicKey);
|
118
|
+
const hash = await kdf(px, 32);
|
119
|
+
const [encryptionKey, macKey] = await sha256(hash.slice(16)).then((macKey) => [hash.slice(0, 16), macKey]);
|
120
|
+
if (!(await hmacSha256Verify(macKey, cipherAndIv, msgMac))) {
|
121
|
+
throw new Error("Incorrect MAC");
|
122
|
+
}
|
123
|
+
return aesCtrDecrypt(iv, encryptionKey, ciphertext);
|
124
|
+
}
|
125
|
+
}
|
126
|
+
//# sourceMappingURL=ecies.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ecies.js","sourceRoot":"","sources":["../../src/crypto/ecies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAC5D;;GAEG;AACH,SAAS,GAAG,CAAC,MAAkB,EAAE,YAAoB;IACnD,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,UAAU,EAAE,CAAC,CAAC;IACrD,OAAO,OAAO,GAAG,YAAY,EAAE;QAC7B,MAAM,QA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C,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;QACxC,MAAM,WAAW,GAAG,SAAS,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,gBAAgB,CAAC,CAAC;QACpE,MAAM,UAAU,GAAG,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACzC,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,GAAG,gBAAgB,CAAC,CAAC;QAE3D,aAAa;QACb,MAAM,EAAE,GAAG,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;QAC9C,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAC/B,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAC/D,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,CAAC,CACxC,CAAC;QAEF,IAAI,CAAC,CAAC,MAAM,gBAAgB,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC,EAAE;YAC1D,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;SAClC;QAED,OAAO,aAAa,CAAC,EAAE,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC;KACrD;AACH,CAAC"}
|
File without changes
|
@@ -2,7 +2,7 @@ import nodeCrypto from "crypto";
|
|
2
2
|
import * as secp from "@noble/secp256k1";
|
3
3
|
import { concat } from "@waku/byte-utils";
|
4
4
|
import sha3 from "js-sha3";
|
5
|
-
import { Asymmetric, Symmetric } from "
|
5
|
+
import { Asymmetric, Symmetric } from "../constants.js";
|
6
6
|
const crypto = {
|
7
7
|
node: nodeCrypto,
|
8
8
|
web: typeof self === "object" && "crypto" in self ? self.crypto : undefined,
|
@@ -57,4 +57,4 @@ export async function sign(message, privateKey) {
|
|
57
57
|
export function keccak256(input) {
|
58
58
|
return new Uint8Array(sha3.keccak256.arrayBuffer(input));
|
59
59
|
}
|
60
|
-
//# sourceMappingURL=
|
60
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/crypto/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,QAAQ,CAAC;AAEhC,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,IAAI,MAAM,SAAS,CAAC;AAE3B,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGxD,MAAM,MAAM,GAA8B;IACxC,IAAI,EAAE,UAAU;IAChB,GAAG,EAAE,OAAO,IAAI,KAAK,QAAQ,IAAI,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;CAC5E,CAAC;AAEF,MAAM,UAAU,SAAS;IACvB,IAAI,MAAM,CAAC,GAAG,EAAE;QACd,OAAO,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;KAC1B;SAAM,IAAI,MAAM,CAAC,IAAI,EAAE;QACtB,OAAO,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;KACrC;SAAM;QACL,MAAM,IAAI,KAAK,CACb,yHAAyH,CAC1H,CAAC;KACH;AACH,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC;AAClD,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;AAExC;;;;GAIG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AACzC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAClC,OAAO,WAAW,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AACxC,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;AAE9C;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CACxB,OAAmB,EACnB,UAAsB;IAEtB,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE;QACnE,SAAS,EAAE,IAAI;QACf,GAAG,EAAE,KAAK;KACX,CAAC,CAAC;IACH,OAAO,MAAM,CACX,CAAC,SAAS,EAAE,IAAI,UAAU,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EACzC,SAAS,CAAC,MAAM,GAAG,CAAC,CACrB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,KAAiB;IACzC,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { Symmetric } from "../constants.js";
|
2
|
+
import { getSubtle, randomBytes } from "./index.js";
|
3
|
+
export async function encrypt(iv, key, clearText) {
|
4
|
+
return getSubtle()
|
5
|
+
.importKey("raw", key, Symmetric.algorithm, false, ["encrypt"])
|
6
|
+
.then((cryptoKey) => getSubtle().encrypt({ iv, ...Symmetric.algorithm }, cryptoKey, clearText))
|
7
|
+
.then((cipher) => new Uint8Array(cipher));
|
8
|
+
}
|
9
|
+
export async function decrypt(iv, key, cipherText) {
|
10
|
+
return getSubtle()
|
11
|
+
.importKey("raw", key, Symmetric.algorithm, false, ["decrypt"])
|
12
|
+
.then((cryptoKey) => getSubtle().decrypt({ iv, ...Symmetric.algorithm }, cryptoKey, cipherText))
|
13
|
+
.then((clear) => new Uint8Array(clear));
|
14
|
+
}
|
15
|
+
export function generateIv() {
|
16
|
+
return randomBytes(Symmetric.ivSize);
|
17
|
+
}
|
18
|
+
//# sourceMappingURL=symmetric.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"symmetric.js","sourceRoot":"","sources":["../../src/crypto/symmetric.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,EAAc,EACd,GAAe,EACf,SAAqB;IAErB,OAAO,SAAS,EAAE;SACf,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,SAAS,CAAC,SAAS,EAAE,KAAK,EAAE,CAAC,SAAS,CAAC,CAAC;SAC9D,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAClB,SAAS,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,GAAG,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,SAAS,CAAC,CAC1E;SACA,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,EAAc,EACd,GAAe,EACf,UAAsB;IAEtB,OAAO,SAAS,EAAE;SACf,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,SAAS,CAAC,SAAS,EAAE,KAAK,EAAE,CAAC,SAAS,CAAC,CAAC;SAC9D,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAClB,SAAS,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,GAAG,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,UAAU,CAAC,CAC3E;SACA,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,OAAO,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AACvC,CAAC"}
|
package/dist/ecies.d.ts
CHANGED
@@ -1,17 +1,51 @@
|
|
1
|
+
import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
|
2
|
+
import type { IDecoder, IEncoder, IMessage, IProtoMessage } from "@waku/interfaces";
|
3
|
+
import { DecodedMessage, generatePrivateKey, getPublicKey } from "./index.js";
|
4
|
+
export { DecodedMessage, generatePrivateKey, getPublicKey };
|
5
|
+
declare class Encoder implements IEncoder {
|
6
|
+
contentTopic: string;
|
7
|
+
private publicKey;
|
8
|
+
private sigPrivKey?;
|
9
|
+
ephemeral: boolean;
|
10
|
+
constructor(contentTopic: string, publicKey: Uint8Array, sigPrivKey?: Uint8Array | undefined, ephemeral?: boolean);
|
11
|
+
toWire(message: IMessage): Promise<Uint8Array | undefined>;
|
12
|
+
toProtoObj(message: IMessage): Promise<IProtoMessage | undefined>;
|
13
|
+
}
|
1
14
|
/**
|
2
|
-
*
|
15
|
+
* Creates an encoder that encrypts messages using ECIES for the given public,
|
16
|
+
* as defined in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
|
3
17
|
*
|
4
|
-
*
|
5
|
-
*
|
6
|
-
*
|
18
|
+
* An encoder is used to encode messages in the [`14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
|
19
|
+
* format to be sent over the Waku network. The resulting encoder can then be
|
20
|
+
* pass to { @link @waku/interfaces.LightPush.push } or
|
21
|
+
* { @link @waku/interfaces.Relay.send } to automatically encrypt
|
22
|
+
* and encode outgoing messages.
|
23
|
+
*
|
24
|
+
* The payload can optionally be signed with the given private key as defined
|
25
|
+
* in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
|
26
|
+
*
|
27
|
+
* @param contentTopic The content topic to set on outgoing messages.
|
28
|
+
* @param publicKey The public key to encrypt the payload for.
|
29
|
+
* @param sigPrivKey An optional private key to used to sign the payload before encryption.
|
30
|
+
* @param ephemeral An optional flag to mark message as ephemeral, ie, not to be stored by Waku Store nodes.
|
7
31
|
*/
|
8
|
-
export declare function
|
32
|
+
export declare function createEncoder(contentTopic: string, publicKey: Uint8Array, sigPrivKey?: Uint8Array, ephemeral?: boolean): Encoder;
|
33
|
+
declare class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
34
|
+
private privateKey;
|
35
|
+
constructor(contentTopic: string, privateKey: Uint8Array);
|
36
|
+
fromProtoObj(protoMessage: IProtoMessage): Promise<DecodedMessage | undefined>;
|
37
|
+
}
|
9
38
|
/**
|
10
|
-
*
|
39
|
+
* Creates a decoder that decrypts messages using ECIES, using the given private
|
40
|
+
* key as defined in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
|
41
|
+
*
|
42
|
+
* A decoder is used to decode messages from the [14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
|
43
|
+
* format when received from the Waku network. The resulting decoder can then be
|
44
|
+
* pass to { @link @waku/interfaces.Filter.subscribe } or
|
45
|
+
* { @link @waku/interfaces.Relay.subscribe } to automatically decrypt and
|
46
|
+
* decode incoming messages.
|
11
47
|
*
|
12
|
-
* @param
|
13
|
-
* @param
|
14
|
-
* @returns The clear text
|
15
|
-
* @throws Error If decryption fails
|
48
|
+
* @param contentTopic The resulting decoder will only decode messages with this content topic.
|
49
|
+
* @param privateKey The private key used to decrypt the message.
|
16
50
|
*/
|
17
|
-
export declare function
|
51
|
+
export declare function createDecoder(contentTopic: string, privateKey: Uint8Array): Decoder;
|
package/dist/ecies.js
CHANGED
@@ -1,126 +1,111 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
return
|
18
|
-
|
19
|
-
|
20
|
-
|
1
|
+
import { Decoder as DecoderV0, proto } from "@waku/core/lib/message/version_0";
|
2
|
+
import debug from "debug";
|
3
|
+
import { decryptAsymmetric, encryptAsymmetric, postCipher, preCipher, } from "./waku_payload.js";
|
4
|
+
import { DecodedMessage, generatePrivateKey, getPublicKey, OneMillion, Version, } from "./index.js";
|
5
|
+
export { DecodedMessage, generatePrivateKey, getPublicKey };
|
6
|
+
const log = debug("waku:message-encryption:ecies");
|
7
|
+
class Encoder {
|
8
|
+
constructor(contentTopic, publicKey, sigPrivKey, ephemeral = false) {
|
9
|
+
this.contentTopic = contentTopic;
|
10
|
+
this.publicKey = publicKey;
|
11
|
+
this.sigPrivKey = sigPrivKey;
|
12
|
+
this.ephemeral = ephemeral;
|
13
|
+
}
|
14
|
+
async toWire(message) {
|
15
|
+
const protoMessage = await this.toProtoObj(message);
|
16
|
+
if (!protoMessage)
|
17
|
+
return;
|
18
|
+
return proto.WakuMessage.encode(protoMessage);
|
19
|
+
}
|
20
|
+
async toProtoObj(message) {
|
21
|
+
const timestamp = message.timestamp ?? new Date();
|
22
|
+
if (!message.payload) {
|
23
|
+
log("No payload to encrypt, skipping: ", message);
|
24
|
+
return;
|
25
|
+
}
|
26
|
+
const preparedPayload = await preCipher(message.payload, this.sigPrivKey);
|
27
|
+
const payload = await encryptAsymmetric(preparedPayload, this.publicKey);
|
28
|
+
return {
|
29
|
+
payload,
|
30
|
+
version: Version,
|
31
|
+
contentTopic: this.contentTopic,
|
32
|
+
timestamp: BigInt(timestamp.valueOf()) * OneMillion,
|
33
|
+
rateLimitProof: message.rateLimitProof,
|
34
|
+
ephemeral: this.ephemeral,
|
35
|
+
};
|
21
36
|
}
|
22
|
-
return willBeResult;
|
23
|
-
}
|
24
|
-
function aesCtrEncrypt(counter, key, data) {
|
25
|
-
return getSubtle()
|
26
|
-
.importKey("raw", key, "AES-CTR", false, ["encrypt"])
|
27
|
-
.then((cryptoKey) => getSubtle().encrypt({ name: "AES-CTR", counter: counter, length: 128 }, cryptoKey, data))
|
28
|
-
.then((bytes) => new Uint8Array(bytes));
|
29
|
-
}
|
30
|
-
function aesCtrDecrypt(counter, key, data) {
|
31
|
-
return getSubtle()
|
32
|
-
.importKey("raw", key, "AES-CTR", false, ["decrypt"])
|
33
|
-
.then((cryptoKey) => getSubtle().decrypt({ name: "AES-CTR", counter: counter, length: 128 }, cryptoKey, data))
|
34
|
-
.then((bytes) => new Uint8Array(bytes));
|
35
|
-
}
|
36
|
-
function hmacSha256Sign(key, msg) {
|
37
|
-
const algorithm = { name: "HMAC", hash: { name: "SHA-256" } };
|
38
|
-
return getSubtle()
|
39
|
-
.importKey("raw", key, algorithm, false, ["sign"])
|
40
|
-
.then((cryptoKey) => getSubtle().sign(algorithm, cryptoKey, msg))
|
41
|
-
.then((bytes) => new Uint8Array(bytes));
|
42
|
-
}
|
43
|
-
function hmacSha256Verify(key, msg, sig) {
|
44
|
-
const algorithm = { name: "HMAC", hash: { name: "SHA-256" } };
|
45
|
-
const _key = getSubtle().importKey("raw", key, algorithm, false, ["verify"]);
|
46
|
-
return _key.then((cryptoKey) => getSubtle().verify(algorithm, cryptoKey, sig, msg));
|
47
37
|
}
|
48
38
|
/**
|
49
|
-
*
|
39
|
+
* Creates an encoder that encrypts messages using ECIES for the given public,
|
40
|
+
* as defined in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
|
41
|
+
*
|
42
|
+
* An encoder is used to encode messages in the [`14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
|
43
|
+
* format to be sent over the Waku network. The resulting encoder can then be
|
44
|
+
* pass to { @link @waku/interfaces.LightPush.push } or
|
45
|
+
* { @link @waku/interfaces.Relay.send } to automatically encrypt
|
46
|
+
* and encode outgoing messages.
|
47
|
+
*
|
48
|
+
* The payload can optionally be signed with the given private key as defined
|
49
|
+
* in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
|
50
50
|
*
|
51
|
-
* @param
|
52
|
-
* @param
|
53
|
-
* @
|
54
|
-
* @
|
51
|
+
* @param contentTopic The content topic to set on outgoing messages.
|
52
|
+
* @param publicKey The public key to encrypt the payload for.
|
53
|
+
* @param sigPrivKey An optional private key to used to sign the payload before encryption.
|
54
|
+
* @param ephemeral An optional flag to mark message as ephemeral, ie, not to be stored by Waku Store nodes.
|
55
55
|
*/
|
56
|
-
function
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
else if (publicKeyB[0] !== 4) {
|
64
|
-
throw new Error("Bad public key, a valid public key would begin with 4");
|
56
|
+
export function createEncoder(contentTopic, publicKey, sigPrivKey, ephemeral = false) {
|
57
|
+
return new Encoder(contentTopic, publicKey, sigPrivKey, ephemeral);
|
58
|
+
}
|
59
|
+
class Decoder extends DecoderV0 {
|
60
|
+
constructor(contentTopic, privateKey) {
|
61
|
+
super(contentTopic);
|
62
|
+
this.privateKey = privateKey;
|
65
63
|
}
|
66
|
-
|
67
|
-
const
|
68
|
-
|
69
|
-
|
64
|
+
async fromProtoObj(protoMessage) {
|
65
|
+
const cipherPayload = protoMessage.payload;
|
66
|
+
if (protoMessage.version !== Version) {
|
67
|
+
log("Failed to decrypt due to incorrect version, expected:", Version, ", actual:", protoMessage.version);
|
68
|
+
return;
|
69
|
+
}
|
70
|
+
let payload;
|
71
|
+
if (!cipherPayload) {
|
72
|
+
log(`No payload to decrypt for contentTopic ${this.contentTopic}`);
|
73
|
+
return;
|
74
|
+
}
|
75
|
+
try {
|
76
|
+
payload = await decryptAsymmetric(cipherPayload, this.privateKey);
|
77
|
+
}
|
78
|
+
catch (e) {
|
79
|
+
log(`Failed to decrypt message using asymmetric decryption for contentTopic: ${this.contentTopic}`, e);
|
80
|
+
return;
|
81
|
+
}
|
82
|
+
if (!payload) {
|
83
|
+
log(`Failed to decrypt payload for contentTopic ${this.contentTopic}`);
|
84
|
+
return;
|
85
|
+
}
|
86
|
+
const res = await postCipher(payload);
|
87
|
+
if (!res) {
|
88
|
+
log(`Failed to decode payload for contentTopic ${this.contentTopic}`);
|
89
|
+
return;
|
90
|
+
}
|
91
|
+
log("Message decrypted", protoMessage);
|
92
|
+
return new DecodedMessage(protoMessage, res.payload, res.sig?.signature, res.sig?.publicKey);
|
70
93
|
}
|
71
94
|
}
|
72
95
|
/**
|
73
|
-
*
|
96
|
+
* Creates a decoder that decrypts messages using ECIES, using the given private
|
97
|
+
* key as defined in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
|
74
98
|
*
|
75
|
-
*
|
76
|
-
*
|
77
|
-
*
|
78
|
-
|
79
|
-
|
80
|
-
const ephemPrivateKey = randomBytes(32);
|
81
|
-
const sharedPx = await derive(ephemPrivateKey, publicKeyTo);
|
82
|
-
const hash = await kdf(sharedPx, 32);
|
83
|
-
const iv = randomBytes(16);
|
84
|
-
const encryptionKey = hash.slice(0, 16);
|
85
|
-
const cipherText = await aesCtrEncrypt(iv, encryptionKey, msg);
|
86
|
-
const ivCipherText = concat([iv, cipherText], iv.length + cipherText.length);
|
87
|
-
const macKey = await sha256(hash.slice(16));
|
88
|
-
const hmac = await hmacSha256Sign(macKey, ivCipherText);
|
89
|
-
const ephemPublicKey = secp.getPublicKey(ephemPrivateKey, false);
|
90
|
-
return concat([ephemPublicKey, ivCipherText, hmac], ephemPublicKey.length + ivCipherText.length + hmac.length);
|
91
|
-
}
|
92
|
-
const metaLength = 1 + 64 + 16 + 32;
|
93
|
-
/**
|
94
|
-
* Decrypt message using given private key.
|
99
|
+
* A decoder is used to decode messages from the [14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
|
100
|
+
* format when received from the Waku network. The resulting decoder can then be
|
101
|
+
* pass to { @link @waku/interfaces.Filter.subscribe } or
|
102
|
+
* { @link @waku/interfaces.Relay.subscribe } to automatically decrypt and
|
103
|
+
* decode incoming messages.
|
95
104
|
*
|
96
|
-
* @param
|
97
|
-
* @param
|
98
|
-
* @returns The clear text
|
99
|
-
* @throws Error If decryption fails
|
105
|
+
* @param contentTopic The resulting decoder will only decode messages with this content topic.
|
106
|
+
* @param privateKey The private key used to decrypt the message.
|
100
107
|
*/
|
101
|
-
export
|
102
|
-
|
103
|
-
throw new Error(`Invalid Ciphertext. Data is too small. It should ba at least ${metaLength} bytes`);
|
104
|
-
}
|
105
|
-
else if (encrypted[0] !== 4) {
|
106
|
-
throw new Error(`Not a valid ciphertext. It should begin with 4 but actually begin with ${encrypted[0]}`);
|
107
|
-
}
|
108
|
-
else {
|
109
|
-
// deserialize
|
110
|
-
const ephemPublicKey = encrypted.slice(0, 65);
|
111
|
-
const cipherTextLength = encrypted.length - metaLength;
|
112
|
-
const iv = encrypted.slice(65, 65 + 16);
|
113
|
-
const cipherAndIv = encrypted.slice(65, 65 + 16 + cipherTextLength);
|
114
|
-
const ciphertext = cipherAndIv.slice(16);
|
115
|
-
const msgMac = encrypted.slice(65 + 16 + cipherTextLength);
|
116
|
-
// check HMAC
|
117
|
-
const px = derive(privateKey, ephemPublicKey);
|
118
|
-
const hash = await kdf(px, 32);
|
119
|
-
const [encryptionKey, macKey] = await sha256(hash.slice(16)).then((macKey) => [hash.slice(0, 16), macKey]);
|
120
|
-
if (!(await hmacSha256Verify(macKey, cipherAndIv, msgMac))) {
|
121
|
-
throw new Error("Incorrect MAC");
|
122
|
-
}
|
123
|
-
return aesCtrDecrypt(iv, encryptionKey, ciphertext);
|
124
|
-
}
|
108
|
+
export function createDecoder(contentTopic, privateKey) {
|
109
|
+
return new Decoder(contentTopic, privateKey);
|
125
110
|
}
|
126
111
|
//# 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,
|
1
|
+
{"version":3,"file":"ecies.js","sourceRoot":"","sources":["../src/ecies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,KAAK,EAAE,MAAM,kCAAkC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