@sebastienrousseau/crypto-lib 0.0.3 → 0.0.8
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/README.md +304 -314
- package/dist/accel/index.d.ts +11 -0
- package/dist/accel/index.d.ts.map +1 -0
- package/dist/accel/index.js +31 -0
- package/dist/accel/native-pqc-bridge.d.ts +18 -0
- package/dist/accel/native-pqc-bridge.d.ts.map +1 -0
- package/dist/accel/native-pqc-bridge.js +100 -0
- package/dist/accel/wasm-bridge.d.ts +35 -0
- package/dist/accel/wasm-bridge.d.ts.map +1 -0
- package/dist/accel/wasm-bridge.js +161 -0
- package/dist/accel/webcrypto-bridge.d.ts +32 -0
- package/dist/accel/webcrypto-bridge.d.ts.map +1 -0
- package/dist/accel/webcrypto-bridge.js +179 -0
- package/dist/accel/webcrypto-modern.d.ts +40 -0
- package/dist/accel/webcrypto-modern.d.ts.map +1 -0
- package/dist/accel/webcrypto-modern.js +213 -0
- package/dist/accel/worker-pool.d.ts +23 -0
- package/dist/accel/worker-pool.d.ts.map +1 -0
- package/dist/accel/worker-pool.js +119 -0
- package/dist/bin/cryptolib.d.ts +9 -7
- package/dist/bin/cryptolib.d.ts.map +1 -1
- package/dist/bin/cryptolib.js +25 -16
- package/dist/config/config.d.ts.map +1 -1
- package/dist/crypto.d.ts +43 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +107 -0
- package/dist/enums.d.ts +29 -29
- package/dist/enums.d.ts.map +1 -1
- package/dist/enums.js +54 -54
- package/dist/errors.d.ts +14 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +22 -0
- package/dist/high-level/index.d.ts +11 -0
- package/dist/high-level/index.d.ts.map +1 -0
- package/dist/high-level/index.js +53 -0
- package/dist/high-level/key-wrap.d.ts +16 -0
- package/dist/high-level/key-wrap.d.ts.map +1 -0
- package/dist/high-level/key-wrap.js +93 -0
- package/dist/high-level/multi-recipient.d.ts +25 -0
- package/dist/high-level/multi-recipient.d.ts.map +1 -0
- package/dist/high-level/multi-recipient.js +122 -0
- package/dist/high-level/password-encrypt.d.ts +14 -0
- package/dist/high-level/password-encrypt.d.ts.map +1 -0
- package/dist/high-level/password-encrypt.js +93 -0
- package/dist/high-level/sealedbox.d.ts +13 -0
- package/dist/high-level/sealedbox.d.ts.map +1 -0
- package/dist/high-level/sealedbox.js +119 -0
- package/dist/high-level/secretbox.d.ts +7 -0
- package/dist/high-level/secretbox.d.ts.map +1 -0
- package/dist/high-level/secretbox.js +54 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +59 -0
- package/dist/key/key.d.ts +6 -13
- package/dist/key/key.d.ts.map +1 -1
- package/dist/key/key.js +20 -14
- package/dist/key/keystore.d.ts +11 -0
- package/dist/key/keystore.d.ts.map +1 -0
- package/dist/key/keystore.js +87 -0
- package/dist/keys/index.d.ts +7 -0
- package/dist/keys/index.d.ts.map +1 -0
- package/dist/keys/index.js +22 -0
- package/dist/keys/keygen.d.ts +16 -0
- package/dist/keys/keygen.d.ts.map +1 -0
- package/dist/keys/keygen.js +128 -0
- package/dist/keys/keyring.d.ts +35 -0
- package/dist/keys/keyring.d.ts.map +1 -0
- package/dist/keys/keyring.js +136 -0
- package/dist/keys/serialize.d.ts +30 -0
- package/dist/keys/serialize.d.ts.map +1 -0
- package/dist/keys/serialize.js +120 -0
- package/dist/lib/decrypt.d.ts +4 -1
- package/dist/lib/decrypt.d.ts.map +1 -1
- package/dist/lib/decrypt.js +43 -51
- package/dist/lib/encrypt.d.ts +1 -1
- package/dist/lib/encrypt.d.ts.map +1 -1
- package/dist/lib/encrypt.js +29 -45
- package/dist/lib/generate.d.ts.map +1 -1
- package/dist/lib/generate.js +56 -63
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +17 -7
- package/dist/lib/key-output.d.ts +7 -0
- package/dist/lib/key-output.d.ts.map +1 -0
- package/dist/lib/key-output.js +50 -0
- package/dist/lib/reformat.d.ts +6 -1
- package/dist/lib/reformat.d.ts.map +1 -1
- package/dist/lib/reformat.js +37 -61
- package/dist/lib/revoke.d.ts +2 -2
- package/dist/lib/revoke.d.ts.map +1 -1
- package/dist/lib/revoke.js +33 -50
- package/dist/lib/session.d.ts.map +1 -1
- package/dist/lib/session.js +21 -36
- package/dist/lib/sign.d.ts.map +1 -1
- package/dist/lib/sign.js +36 -43
- package/dist/lib/verify.d.ts +1 -3
- package/dist/lib/verify.d.ts.map +1 -1
- package/dist/lib/verify.js +25 -30
- package/dist/modern/aead.d.ts +17 -0
- package/dist/modern/aead.d.ts.map +1 -0
- package/dist/modern/aead.js +51 -0
- package/dist/modern/aes.d.ts +35 -0
- package/dist/modern/aes.d.ts.map +1 -0
- package/dist/modern/aes.js +82 -0
- package/dist/modern/cost-limits.d.ts +11 -0
- package/dist/modern/cost-limits.d.ts.map +1 -0
- package/dist/modern/cost-limits.js +35 -0
- package/dist/modern/curves.d.ts +86 -0
- package/dist/modern/curves.d.ts.map +1 -0
- package/dist/modern/curves.js +171 -0
- package/dist/modern/ecdh.d.ts +11 -0
- package/dist/modern/ecdh.d.ts.map +1 -0
- package/dist/modern/ecdh.js +28 -0
- package/dist/modern/fn-dsa.d.ts +19 -0
- package/dist/modern/fn-dsa.d.ts.map +1 -0
- package/dist/modern/fn-dsa.js +57 -0
- package/dist/modern/hash.d.ts +13 -0
- package/dist/modern/hash.d.ts.map +1 -0
- package/dist/modern/hash.js +45 -0
- package/dist/modern/hpke.d.ts +47 -0
- package/dist/modern/hpke.d.ts.map +1 -0
- package/dist/modern/hpke.js +207 -0
- package/dist/modern/index.d.ts +40 -0
- package/dist/modern/index.d.ts.map +1 -0
- package/dist/modern/index.js +194 -0
- package/dist/modern/kdf.d.ts +23 -0
- package/dist/modern/kdf.d.ts.map +1 -0
- package/dist/modern/kdf.js +67 -0
- package/dist/modern/mac.d.ts +51 -0
- package/dist/modern/mac.d.ts.map +1 -0
- package/dist/modern/mac.js +119 -0
- package/dist/modern/password.d.ts +40 -0
- package/dist/modern/password.d.ts.map +1 -0
- package/dist/modern/password.js +123 -0
- package/dist/modern/pq-hash-sign.d.ts +18 -0
- package/dist/modern/pq-hash-sign.d.ts.map +1 -0
- package/dist/modern/pq-hash-sign.js +73 -0
- package/dist/modern/pq-kem.d.ts +88 -0
- package/dist/modern/pq-kem.d.ts.map +1 -0
- package/dist/modern/pq-kem.js +270 -0
- package/dist/modern/pq-sign.d.ts +30 -0
- package/dist/modern/pq-sign.d.ts.map +1 -0
- package/dist/modern/pq-sign.js +94 -0
- package/dist/modern/pq.d.ts +38 -0
- package/dist/modern/pq.d.ts.map +1 -0
- package/dist/modern/pq.js +80 -0
- package/dist/modern/signing.d.ts +16 -0
- package/dist/modern/signing.d.ts.map +1 -0
- package/dist/modern/signing.js +34 -0
- package/dist/protocols/index.d.ts +7 -0
- package/dist/protocols/index.d.ts.map +1 -0
- package/dist/protocols/index.js +46 -0
- package/dist/protocols/iso20022.d.ts +51 -0
- package/dist/protocols/iso20022.d.ts.map +1 -0
- package/dist/protocols/iso20022.js +145 -0
- package/dist/protocols/opaque/ake.d.ts +51 -0
- package/dist/protocols/opaque/ake.d.ts.map +1 -0
- package/dist/protocols/opaque/ake.js +102 -0
- package/dist/protocols/opaque/client.d.ts +45 -0
- package/dist/protocols/opaque/client.d.ts.map +1 -0
- package/dist/protocols/opaque/client.js +63 -0
- package/dist/protocols/opaque/config.d.ts +14 -0
- package/dist/protocols/opaque/config.d.ts.map +1 -0
- package/dist/protocols/opaque/config.js +18 -0
- package/dist/protocols/opaque/credentials.d.ts +29 -0
- package/dist/protocols/opaque/credentials.d.ts.map +1 -0
- package/dist/protocols/opaque/credentials.js +61 -0
- package/dist/protocols/opaque/envelope.d.ts +36 -0
- package/dist/protocols/opaque/envelope.d.ts.map +1 -0
- package/dist/protocols/opaque/envelope.js +77 -0
- package/dist/protocols/opaque/ksf.d.ts +15 -0
- package/dist/protocols/opaque/ksf.d.ts.map +1 -0
- package/dist/protocols/opaque/ksf.js +27 -0
- package/dist/protocols/opaque/messages.d.ts +61 -0
- package/dist/protocols/opaque/messages.d.ts.map +1 -0
- package/dist/protocols/opaque/messages.js +94 -0
- package/dist/protocols/opaque/server.d.ts +33 -0
- package/dist/protocols/opaque/server.d.ts.map +1 -0
- package/dist/protocols/opaque/server.js +74 -0
- package/dist/protocols/opaque/suite.d.ts +58 -0
- package/dist/protocols/opaque/suite.d.ts.map +1 -0
- package/dist/protocols/opaque/suite.js +115 -0
- package/dist/protocols/pake.d.ts +14 -0
- package/dist/protocols/pake.d.ts.map +1 -0
- package/dist/protocols/pake.js +33 -0
- package/dist/protocols/pqxdh.d.ts +53 -0
- package/dist/protocols/pqxdh.d.ts.map +1 -0
- package/dist/protocols/pqxdh.js +143 -0
- package/dist/protocols/ratchet.d.ts +52 -0
- package/dist/protocols/ratchet.d.ts.map +1 -0
- package/dist/protocols/ratchet.js +187 -0
- package/dist/protocols/threshold.d.ts +23 -0
- package/dist/protocols/threshold.d.ts.map +1 -0
- package/dist/protocols/threshold.js +191 -0
- package/dist/registry.d.ts +20 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +399 -0
- package/dist/streaming/index.d.ts +7 -0
- package/dist/streaming/index.d.ts.map +1 -0
- package/dist/streaming/index.js +15 -0
- package/dist/streaming/stream-aead.d.ts +17 -0
- package/dist/streaming/stream-aead.d.ts.map +1 -0
- package/dist/streaming/stream-aead.js +125 -0
- package/dist/streaming/stream-hash.d.ts +9 -0
- package/dist/streaming/stream-hash.d.ts.map +1 -0
- package/dist/streaming/stream-hash.js +52 -0
- package/dist/streaming/web-streams.d.ts +17 -0
- package/dist/streaming/web-streams.d.ts.map +1 -0
- package/dist/streaming/web-streams.js +114 -0
- package/dist/tokens/index.d.ts +5 -0
- package/dist/tokens/index.d.ts.map +1 -0
- package/dist/tokens/index.js +15 -0
- package/dist/tokens/key-rotation.d.ts +20 -0
- package/dist/tokens/key-rotation.d.ts.map +1 -0
- package/dist/tokens/key-rotation.js +76 -0
- package/dist/tokens/paseto.d.ts +46 -0
- package/dist/tokens/paseto.d.ts.map +1 -0
- package/dist/tokens/paseto.js +200 -0
- package/dist/types/types.d.ts +24 -16
- package/dist/types/types.d.ts.map +1 -1
- package/dist/utils.d.ts +13 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +56 -0
- package/package.json +77 -142
- package/dist/COPYRIGHT +0 -15
- package/dist/Report.txt +0 -160
- package/dist/bin/cryptolib.js.map +0 -1
- package/dist/config/config.js.map +0 -1
- package/dist/data/decrypted.txt +0 -1
- package/dist/data/detached.sig +0 -1
- package/dist/data/encrypted.txt +0 -1
- package/dist/data/signed.sig +0 -1
- package/dist/enums.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/key/key.js.map +0 -1
- package/dist/key/rsa-reformat.cert +0 -1
- package/dist/key/rsa-reformat.key +0 -1
- package/dist/key/rsa-reformat.pub +0 -1
- package/dist/key/rsa-revoke.key +0 -1
- package/dist/key/rsa-revoke.pub +0 -1
- package/dist/key/rsa.cert +0 -1
- package/dist/key/rsa.key +0 -1
- package/dist/key/rsa.pub +0 -1
- package/dist/lib/decrypt.js.map +0 -1
- package/dist/lib/encrypt.js.map +0 -1
- package/dist/lib/generate.js.map +0 -1
- package/dist/lib/index.js.map +0 -1
- package/dist/lib/reformat.js.map +0 -1
- package/dist/lib/revoke.js.map +0 -1
- package/dist/lib/session.js.map +0 -1
- package/dist/lib/sign.js.map +0 -1
- package/dist/lib/verify.js.map +0 -1
- package/dist/package.json +0 -143
- package/dist/types/types.js.map +0 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { p256_oprf } from "@noble/curves/nist.js";
|
|
2
|
+
import { concatBytes } from "@noble/hashes/utils.js";
|
|
3
|
+
import type { CHash } from "@noble/hashes/utils.js";
|
|
4
|
+
export type SuiteId = "P256-SHA256" | "ristretto255-SHA512";
|
|
5
|
+
export declare const OpaqueErrorCode: {
|
|
6
|
+
readonly ENVELOPE_RECOVERY: "OPAQUE_ENVELOPE_RECOVERY";
|
|
7
|
+
readonly SERVER_AUTHENTICATION: "OPAQUE_SERVER_AUTHENTICATION";
|
|
8
|
+
readonly CLIENT_AUTHENTICATION: "OPAQUE_CLIENT_AUTHENTICATION";
|
|
9
|
+
readonly DESERIALIZE: "OPAQUE_DESERIALIZE";
|
|
10
|
+
readonly INVALID_INPUT: "OPAQUE_INVALID_INPUT";
|
|
11
|
+
};
|
|
12
|
+
export declare const Nn = 32;
|
|
13
|
+
export declare const Nseed = 32;
|
|
14
|
+
interface Element {
|
|
15
|
+
multiply(scalar: bigint): Element;
|
|
16
|
+
equals(other: Element): boolean;
|
|
17
|
+
toBytes(): Uint8Array;
|
|
18
|
+
}
|
|
19
|
+
interface Group {
|
|
20
|
+
fromBytes(bytes: Uint8Array): Element;
|
|
21
|
+
readonly ZERO: Element;
|
|
22
|
+
readonly Fn: {
|
|
23
|
+
fromBytes(bytes: Uint8Array): bigint;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
type Oprf = typeof p256_oprf.oprf;
|
|
27
|
+
export interface Suite {
|
|
28
|
+
readonly id: SuiteId;
|
|
29
|
+
readonly Nh: number;
|
|
30
|
+
readonly Npk: number;
|
|
31
|
+
readonly Noe: number;
|
|
32
|
+
readonly Nok: number;
|
|
33
|
+
readonly hash: CHash;
|
|
34
|
+
readonly oprf: Oprf;
|
|
35
|
+
readonly group: Group;
|
|
36
|
+
readonly hashToGroup: (msg: Uint8Array, opts: {
|
|
37
|
+
DST: Uint8Array;
|
|
38
|
+
}) => Element;
|
|
39
|
+
readonly blindDst: Uint8Array;
|
|
40
|
+
}
|
|
41
|
+
export declare function utf8(s: string): Uint8Array;
|
|
42
|
+
export declare function toBytes(value: Uint8Array | string): Uint8Array;
|
|
43
|
+
export declare function i2osp(n: number, len: 1 | 2): Uint8Array;
|
|
44
|
+
export declare const concat: typeof concatBytes;
|
|
45
|
+
export declare function xor(a: Uint8Array, b: Uint8Array): Uint8Array;
|
|
46
|
+
export declare function getSuite(id: SuiteId): Suite;
|
|
47
|
+
export declare function kdfExtract(s: Suite, salt: Uint8Array, ikm: Uint8Array): Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>;
|
|
48
|
+
export declare function kdfExpand(s: Suite, prk: Uint8Array, info: Uint8Array, length: number): Uint8Array;
|
|
49
|
+
export declare function mac(s: Suite, key: Uint8Array, msg: Uint8Array): Uint8Array;
|
|
50
|
+
export declare function decodeElement(s: Suite, bytes: Uint8Array, label: string): Element;
|
|
51
|
+
export declare function deriveDiffieHellmanKeyPair(s: Suite, seed: Uint8Array): {
|
|
52
|
+
privateKey: import("@noble/curves/abstract/oprf").ScalarBytes & Uint8Array<ArrayBuffer>;
|
|
53
|
+
publicKey: import("@noble/curves/abstract/oprf").PointBytes & Uint8Array<ArrayBuffer>;
|
|
54
|
+
};
|
|
55
|
+
export declare function diffieHellman(s: Suite, privateKey: Uint8Array, publicKey: Uint8Array): Uint8Array;
|
|
56
|
+
export declare function blindWith(s: Suite, input: Uint8Array, blind: Uint8Array): Uint8Array;
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=suite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suite.d.ts","sourceRoot":"","sources":["../../../src/protocols/opaque/suite.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAqB,SAAS,EAAE,MAAM,uBAAuB,CAAC;AASrE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAIpD,MAAM,MAAM,OAAO,GAAG,aAAa,GAAG,qBAAqB,CAAC;AAG5D,eAAO,MAAM,eAAe;;;;;;CAWlB,CAAC;AAGX,eAAO,MAAM,EAAE,KAAK,CAAC;AAErB,eAAO,MAAM,KAAK,KAAK,CAAC;AAGxB,UAAU,OAAO;IACf,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO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,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,UAAU,CAE5D;AA8BD,wBAAgB,QAAQ,CAAC,EAAE,EAAE,OAAO,GAAG,KAAK,CAS3C;AAGD,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,yDAErE;AAGD,wBAAgB,SAAS,CACvB,CAAC,EAAE,KAAK,EACR,GAAG,EAAE,UAAU,EACf,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,GACb,UAAU,CAEZ;AAGD,wBAAgB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,UAAU,CAE1E;AAOD,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,WAcvE;AAOD,wBAAgB,0BAA0B,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU;;;EAMpE;AAQD,wBAAgB,aAAa,CAC3B,CAAC,EAAE,KAAK,EACR,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,UAAU,GACpB,UAAU,CAIZ;AAOD,wBAAgB,SAAS,CACvB,CAAC,EAAE,KAAK,EACR,KAAK,EAAE,UAAU,EACjB,KAAK,EAAE,UAAU,GAChB,UAAU,CAKZ"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.concat = exports.Nseed = exports.Nn = exports.OpaqueErrorCode = void 0;
|
|
4
|
+
exports.utf8 = utf8;
|
|
5
|
+
exports.toBytes = toBytes;
|
|
6
|
+
exports.i2osp = i2osp;
|
|
7
|
+
exports.xor = xor;
|
|
8
|
+
exports.getSuite = getSuite;
|
|
9
|
+
exports.kdfExtract = kdfExtract;
|
|
10
|
+
exports.kdfExpand = kdfExpand;
|
|
11
|
+
exports.mac = mac;
|
|
12
|
+
exports.decodeElement = decodeElement;
|
|
13
|
+
exports.deriveDiffieHellmanKeyPair = deriveDiffieHellmanKeyPair;
|
|
14
|
+
exports.diffieHellman = diffieHellman;
|
|
15
|
+
exports.blindWith = blindWith;
|
|
16
|
+
const nist_js_1 = require("@noble/curves/nist.js");
|
|
17
|
+
const ed25519_js_1 = require("@noble/curves/ed25519.js");
|
|
18
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
19
|
+
const hkdf_js_1 = require("@noble/hashes/hkdf.js");
|
|
20
|
+
const hmac_js_1 = require("@noble/hashes/hmac.js");
|
|
21
|
+
const utils_js_1 = require("@noble/hashes/utils.js");
|
|
22
|
+
const errors_1 = require("../../errors");
|
|
23
|
+
exports.OpaqueErrorCode = {
|
|
24
|
+
ENVELOPE_RECOVERY: "OPAQUE_ENVELOPE_RECOVERY",
|
|
25
|
+
SERVER_AUTHENTICATION: "OPAQUE_SERVER_AUTHENTICATION",
|
|
26
|
+
CLIENT_AUTHENTICATION: "OPAQUE_CLIENT_AUTHENTICATION",
|
|
27
|
+
DESERIALIZE: "OPAQUE_DESERIALIZE",
|
|
28
|
+
INVALID_INPUT: "OPAQUE_INVALID_INPUT",
|
|
29
|
+
};
|
|
30
|
+
exports.Nn = 32;
|
|
31
|
+
exports.Nseed = 32;
|
|
32
|
+
function utf8(s) {
|
|
33
|
+
return new TextEncoder().encode(s);
|
|
34
|
+
}
|
|
35
|
+
function toBytes(value) {
|
|
36
|
+
return typeof value === "string" ? utf8(value) : value;
|
|
37
|
+
}
|
|
38
|
+
function i2osp(n, len) {
|
|
39
|
+
return len === 1 ? Uint8Array.of(n) : Uint8Array.of(n >> 8, n & 0xff);
|
|
40
|
+
}
|
|
41
|
+
exports.concat = utils_js_1.concatBytes;
|
|
42
|
+
function xor(a, b) {
|
|
43
|
+
return a.map((x, i) => x ^ b[i]);
|
|
44
|
+
}
|
|
45
|
+
const SUITES = {
|
|
46
|
+
"P256-SHA256": {
|
|
47
|
+
id: "P256-SHA256",
|
|
48
|
+
Nh: 32,
|
|
49
|
+
Npk: 33,
|
|
50
|
+
Noe: 33,
|
|
51
|
+
Nok: 32,
|
|
52
|
+
hash: sha2_js_1.sha256,
|
|
53
|
+
oprf: nist_js_1.p256_oprf.oprf,
|
|
54
|
+
group: nist_js_1.p256.Point,
|
|
55
|
+
hashToGroup: nist_js_1.p256_hasher.hashToCurve,
|
|
56
|
+
blindDst: utf8("HashToGroup-OPRFV1-\x00-P256-SHA256"),
|
|
57
|
+
},
|
|
58
|
+
"ristretto255-SHA512": {
|
|
59
|
+
id: "ristretto255-SHA512",
|
|
60
|
+
Nh: 64,
|
|
61
|
+
Npk: 32,
|
|
62
|
+
Noe: 32,
|
|
63
|
+
Nok: 32,
|
|
64
|
+
hash: sha2_js_1.sha512,
|
|
65
|
+
oprf: ed25519_js_1.ristretto255_oprf.oprf,
|
|
66
|
+
group: ed25519_js_1.ristretto255.Point,
|
|
67
|
+
hashToGroup: ed25519_js_1.ristretto255_hasher.hashToCurve,
|
|
68
|
+
blindDst: utf8("HashToGroup-OPRFV1-\x00-ristretto255-SHA512"),
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
function getSuite(id) {
|
|
72
|
+
const suite = Object.hasOwn(SUITES, id) ? SUITES[id] : undefined;
|
|
73
|
+
if (suite === undefined) {
|
|
74
|
+
throw new errors_1.CryptoError(`Unsupported OPAQUE suite: ${String(id)}`, exports.OpaqueErrorCode.INVALID_INPUT);
|
|
75
|
+
}
|
|
76
|
+
return suite;
|
|
77
|
+
}
|
|
78
|
+
function kdfExtract(s, salt, ikm) {
|
|
79
|
+
return (0, hkdf_js_1.extract)(s.hash, ikm, salt);
|
|
80
|
+
}
|
|
81
|
+
function kdfExpand(s, prk, info, length) {
|
|
82
|
+
return (0, hkdf_js_1.expand)(s.hash, prk, info, length);
|
|
83
|
+
}
|
|
84
|
+
function mac(s, key, msg) {
|
|
85
|
+
return (0, hmac_js_1.hmac)(s.hash, key, msg);
|
|
86
|
+
}
|
|
87
|
+
function decodeElement(s, bytes, label) {
|
|
88
|
+
let element;
|
|
89
|
+
try {
|
|
90
|
+
element = s.group.fromBytes(bytes);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
throw new errors_1.CryptoError(`Invalid ${label}`, exports.OpaqueErrorCode.DESERIALIZE);
|
|
94
|
+
}
|
|
95
|
+
if (element.equals(s.group.ZERO)) {
|
|
96
|
+
throw new errors_1.CryptoError(`Invalid ${label}: identity element`, exports.OpaqueErrorCode.DESERIALIZE);
|
|
97
|
+
}
|
|
98
|
+
return element;
|
|
99
|
+
}
|
|
100
|
+
function deriveDiffieHellmanKeyPair(s, seed) {
|
|
101
|
+
const kp = s.oprf.deriveKeyPair(seed, utf8("OPAQUE-DeriveDiffieHellmanKeyPair"));
|
|
102
|
+
return { privateKey: kp.secretKey, publicKey: kp.publicKey };
|
|
103
|
+
}
|
|
104
|
+
function diffieHellman(s, privateKey, publicKey) {
|
|
105
|
+
return decodeElement(s, publicKey, "public key")
|
|
106
|
+
.multiply(s.group.Fn.fromBytes(privateKey))
|
|
107
|
+
.toBytes();
|
|
108
|
+
}
|
|
109
|
+
function blindWith(s, input, blind) {
|
|
110
|
+
return s
|
|
111
|
+
.hashToGroup(input, { DST: s.blindDst })
|
|
112
|
+
.multiply(s.group.Fn.fromBytes(blind))
|
|
113
|
+
.toBytes();
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=suite.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { OpaqueErrorCode } from "./opaque/suite";
|
|
2
|
+
export type { SuiteId } from "./opaque/suite";
|
|
3
|
+
export { RFC9807_SCRYPT_PARAMS, scryptKsf } from "./opaque/ksf";
|
|
4
|
+
export type { Ksf, ScryptKsfParams } from "./opaque/ksf";
|
|
5
|
+
export type { OpaqueConfig } from "./opaque/config";
|
|
6
|
+
export type { Identities } from "./opaque/envelope";
|
|
7
|
+
export type { ServerLoginState } from "./opaque/ake";
|
|
8
|
+
export { deserializeKE1, deserializeKE2, deserializeKE3, deserializeRegistrationRecord, deserializeRegistrationRequest, deserializeRegistrationResponse, serializeKE1, serializeKE2, serializeKE3, serializeRegistrationRecord, serializeRegistrationRequest, serializeRegistrationResponse, } from "./opaque/messages";
|
|
9
|
+
export type { AuthRequest, AuthResponse, CredentialRequest, CredentialResponse, Envelope, KE1, KE2, KE3, RegistrationRecord, RegistrationRequest, RegistrationResponse, } from "./opaque/messages";
|
|
10
|
+
export { createRegistrationRequest, finalizeRegistrationRequest, generateKE1, generateKE3, } from "./opaque/client";
|
|
11
|
+
export type { ClientLoginState } from "./opaque/client";
|
|
12
|
+
export { createFakeRecord, createRegistrationResponse, createServerSetup, generateKE2, serverFinish, } from "./opaque/server";
|
|
13
|
+
export type { GenerateKE2Input, ServerSetup } from "./opaque/server";
|
|
14
|
+
//# sourceMappingURL=pake.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pake.d.ts","sourceRoot":"","sources":["../../src/protocols/pake.ts"],"names":[],"mappings":"AA+EA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,YAAY,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAChE,YAAY,EAAE,GAAG,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACzD,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EACL,cAAc,EACd,cAAc,EACd,cAAc,EACd,6BAA6B,EAC7B,8BAA8B,EAC9B,+BAA+B,EAC/B,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,2BAA2B,EAC3B,4BAA4B,EAC5B,6BAA6B,GAC9B,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EACV,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,QAAQ,EACR,GAAG,EACH,GAAG,EACH,GAAG,EACH,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,yBAAyB,EACzB,2BAA2B,EAC3B,WAAW,EACX,WAAW,GACZ,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,iBAAiB,EACjB,WAAW,EACX,YAAY,GACb,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serverFinish = exports.generateKE2 = exports.createServerSetup = exports.createRegistrationResponse = exports.createFakeRecord = exports.generateKE3 = exports.generateKE1 = exports.finalizeRegistrationRequest = exports.createRegistrationRequest = exports.serializeRegistrationResponse = exports.serializeRegistrationRequest = exports.serializeRegistrationRecord = exports.serializeKE3 = exports.serializeKE2 = exports.serializeKE1 = exports.deserializeRegistrationResponse = exports.deserializeRegistrationRequest = exports.deserializeRegistrationRecord = exports.deserializeKE3 = exports.deserializeKE2 = exports.deserializeKE1 = exports.scryptKsf = exports.RFC9807_SCRYPT_PARAMS = exports.OpaqueErrorCode = void 0;
|
|
4
|
+
var suite_1 = require("./opaque/suite");
|
|
5
|
+
Object.defineProperty(exports, "OpaqueErrorCode", { enumerable: true, get: function () { return suite_1.OpaqueErrorCode; } });
|
|
6
|
+
var ksf_1 = require("./opaque/ksf");
|
|
7
|
+
Object.defineProperty(exports, "RFC9807_SCRYPT_PARAMS", { enumerable: true, get: function () { return ksf_1.RFC9807_SCRYPT_PARAMS; } });
|
|
8
|
+
Object.defineProperty(exports, "scryptKsf", { enumerable: true, get: function () { return ksf_1.scryptKsf; } });
|
|
9
|
+
var messages_1 = require("./opaque/messages");
|
|
10
|
+
Object.defineProperty(exports, "deserializeKE1", { enumerable: true, get: function () { return messages_1.deserializeKE1; } });
|
|
11
|
+
Object.defineProperty(exports, "deserializeKE2", { enumerable: true, get: function () { return messages_1.deserializeKE2; } });
|
|
12
|
+
Object.defineProperty(exports, "deserializeKE3", { enumerable: true, get: function () { return messages_1.deserializeKE3; } });
|
|
13
|
+
Object.defineProperty(exports, "deserializeRegistrationRecord", { enumerable: true, get: function () { return messages_1.deserializeRegistrationRecord; } });
|
|
14
|
+
Object.defineProperty(exports, "deserializeRegistrationRequest", { enumerable: true, get: function () { return messages_1.deserializeRegistrationRequest; } });
|
|
15
|
+
Object.defineProperty(exports, "deserializeRegistrationResponse", { enumerable: true, get: function () { return messages_1.deserializeRegistrationResponse; } });
|
|
16
|
+
Object.defineProperty(exports, "serializeKE1", { enumerable: true, get: function () { return messages_1.serializeKE1; } });
|
|
17
|
+
Object.defineProperty(exports, "serializeKE2", { enumerable: true, get: function () { return messages_1.serializeKE2; } });
|
|
18
|
+
Object.defineProperty(exports, "serializeKE3", { enumerable: true, get: function () { return messages_1.serializeKE3; } });
|
|
19
|
+
Object.defineProperty(exports, "serializeRegistrationRecord", { enumerable: true, get: function () { return messages_1.serializeRegistrationRecord; } });
|
|
20
|
+
Object.defineProperty(exports, "serializeRegistrationRequest", { enumerable: true, get: function () { return messages_1.serializeRegistrationRequest; } });
|
|
21
|
+
Object.defineProperty(exports, "serializeRegistrationResponse", { enumerable: true, get: function () { return messages_1.serializeRegistrationResponse; } });
|
|
22
|
+
var client_1 = require("./opaque/client");
|
|
23
|
+
Object.defineProperty(exports, "createRegistrationRequest", { enumerable: true, get: function () { return client_1.createRegistrationRequest; } });
|
|
24
|
+
Object.defineProperty(exports, "finalizeRegistrationRequest", { enumerable: true, get: function () { return client_1.finalizeRegistrationRequest; } });
|
|
25
|
+
Object.defineProperty(exports, "generateKE1", { enumerable: true, get: function () { return client_1.generateKE1; } });
|
|
26
|
+
Object.defineProperty(exports, "generateKE3", { enumerable: true, get: function () { return client_1.generateKE3; } });
|
|
27
|
+
var server_1 = require("./opaque/server");
|
|
28
|
+
Object.defineProperty(exports, "createFakeRecord", { enumerable: true, get: function () { return server_1.createFakeRecord; } });
|
|
29
|
+
Object.defineProperty(exports, "createRegistrationResponse", { enumerable: true, get: function () { return server_1.createRegistrationResponse; } });
|
|
30
|
+
Object.defineProperty(exports, "createServerSetup", { enumerable: true, get: function () { return server_1.createServerSetup; } });
|
|
31
|
+
Object.defineProperty(exports, "generateKE2", { enumerable: true, get: function () { return server_1.generateKE2; } });
|
|
32
|
+
Object.defineProperty(exports, "serverFinish", { enumerable: true, get: function () { return server_1.serverFinish; } });
|
|
33
|
+
//# sourceMappingURL=pake.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export interface IdentityKeyPair {
|
|
2
|
+
privateKey: string;
|
|
3
|
+
publicKey: string;
|
|
4
|
+
signingPrivateKey: string;
|
|
5
|
+
signingPublicKey: string;
|
|
6
|
+
}
|
|
7
|
+
export interface SignedPreKey {
|
|
8
|
+
privateKey: string;
|
|
9
|
+
publicKey: string;
|
|
10
|
+
signature: string;
|
|
11
|
+
}
|
|
12
|
+
export interface OneTimePreKey {
|
|
13
|
+
privateKey: string;
|
|
14
|
+
publicKey: string;
|
|
15
|
+
}
|
|
16
|
+
export interface PqPreKey {
|
|
17
|
+
publicKey: string;
|
|
18
|
+
secretKey: string;
|
|
19
|
+
signature: string;
|
|
20
|
+
}
|
|
21
|
+
export interface InitiateSessionParams {
|
|
22
|
+
identityKeyPair: IdentityKeyPair;
|
|
23
|
+
remoteIdentityPublic: string;
|
|
24
|
+
remoteSignedPreKeyPublic: string;
|
|
25
|
+
remoteOneTimePreKeyPublic?: string;
|
|
26
|
+
remotePqPreKeyPublic: string;
|
|
27
|
+
}
|
|
28
|
+
export interface InitiateSessionResult {
|
|
29
|
+
sharedSecret: string;
|
|
30
|
+
ephemeralPublicKey: string;
|
|
31
|
+
pqCiphertext: string;
|
|
32
|
+
algorithm: "pqxdh";
|
|
33
|
+
}
|
|
34
|
+
export interface RespondToSessionParams {
|
|
35
|
+
identityKeyPair: IdentityKeyPair;
|
|
36
|
+
signedPreKeyPrivate: string;
|
|
37
|
+
oneTimePreKeyPrivate?: string;
|
|
38
|
+
pqPreKeySecret: string;
|
|
39
|
+
remoteIdentityPublic: string;
|
|
40
|
+
remoteEphemeralPublic: string;
|
|
41
|
+
pqCiphertext: string;
|
|
42
|
+
}
|
|
43
|
+
export interface RespondToSessionResult {
|
|
44
|
+
sharedSecret: string;
|
|
45
|
+
algorithm: "pqxdh";
|
|
46
|
+
}
|
|
47
|
+
export declare function generateIdentityKeyPair(): IdentityKeyPair;
|
|
48
|
+
export declare function generateSignedPreKey(identitySigningPrivate: string): SignedPreKey;
|
|
49
|
+
export declare function generateOneTimePreKey(): OneTimePreKey;
|
|
50
|
+
export declare function generatePqPreKey(identitySigningPrivate: string): PqPreKey;
|
|
51
|
+
export declare function initiateSession(params: InitiateSessionParams): InitiateSessionResult;
|
|
52
|
+
export declare function respondToSession(params: RespondToSessionParams): RespondToSessionResult;
|
|
53
|
+
//# sourceMappingURL=pqxdh.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pqxdh.d.ts","sourceRoot":"","sources":["../../src/protocols/pqxdh.ts"],"names":[],"mappings":"AA8BA,MAAM,WAAW,eAAe;IAE9B,UAAU,EAAE,MAAM,CAAC;IAEnB,SAAS,EAAE,MAAM,CAAC;IAElB,iBAAiB,EAAE,MAAM,CAAC;IAE1B,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAGD,MAAM,WAAW,YAAY;IAE3B,UAAU,EAAE,MAAM,CAAC;IAEnB,SAAS,EAAE,MAAM,CAAC;IAElB,SAAS,EAAE,MAAM,CAAC;CACn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B;AAQD,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,sBAAsB,GAC7B,sBAAsB,CA+DxB"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateIdentityKeyPair = generateIdentityKeyPair;
|
|
4
|
+
exports.generateSignedPreKey = generateSignedPreKey;
|
|
5
|
+
exports.generateOneTimePreKey = generateOneTimePreKey;
|
|
6
|
+
exports.generatePqPreKey = generatePqPreKey;
|
|
7
|
+
exports.initiateSession = initiateSession;
|
|
8
|
+
exports.respondToSession = respondToSession;
|
|
9
|
+
const ed25519_js_1 = require("@noble/curves/ed25519.js");
|
|
10
|
+
const ml_kem_js_1 = require("@noble/post-quantum/ml-kem.js");
|
|
11
|
+
const hkdf_js_1 = require("@noble/hashes/hkdf.js");
|
|
12
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
13
|
+
const utils_js_1 = require("@noble/ciphers/utils.js");
|
|
14
|
+
const HEX_RE = /^[0-9a-fA-F]*$/;
|
|
15
|
+
function hexToBytes(hex, label) {
|
|
16
|
+
if (!HEX_RE.test(hex)) {
|
|
17
|
+
throw new Error(`Invalid hex string for ${label}`);
|
|
18
|
+
}
|
|
19
|
+
return Buffer.from(hex, "hex");
|
|
20
|
+
}
|
|
21
|
+
const PQXDH_INFO = new TextEncoder().encode("pqxdh-v1");
|
|
22
|
+
function generateIdentityKeyPair() {
|
|
23
|
+
const x25519Priv = (0, utils_js_1.randomBytes)(32);
|
|
24
|
+
const x25519Pub = ed25519_js_1.x25519.getPublicKey(x25519Priv);
|
|
25
|
+
const signingPriv = (0, utils_js_1.randomBytes)(32);
|
|
26
|
+
const signingPub = ed25519_js_1.ed25519.getPublicKey(signingPriv);
|
|
27
|
+
return {
|
|
28
|
+
privateKey: Buffer.from(x25519Priv).toString("hex"),
|
|
29
|
+
publicKey: Buffer.from(x25519Pub).toString("hex"),
|
|
30
|
+
signingPrivateKey: Buffer.from(signingPriv).toString("hex"),
|
|
31
|
+
signingPublicKey: Buffer.from(signingPub).toString("hex"),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function generateSignedPreKey(identitySigningPrivate) {
|
|
35
|
+
const sigKey = hexToBytes(identitySigningPrivate, "identitySigningPrivate");
|
|
36
|
+
const prePriv = (0, utils_js_1.randomBytes)(32);
|
|
37
|
+
const prePub = ed25519_js_1.x25519.getPublicKey(prePriv);
|
|
38
|
+
const signature = ed25519_js_1.ed25519.sign(prePub, sigKey);
|
|
39
|
+
return {
|
|
40
|
+
privateKey: Buffer.from(prePriv).toString("hex"),
|
|
41
|
+
publicKey: Buffer.from(prePub).toString("hex"),
|
|
42
|
+
signature: Buffer.from(signature).toString("hex"),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function generateOneTimePreKey() {
|
|
46
|
+
const priv = (0, utils_js_1.randomBytes)(32);
|
|
47
|
+
const pub = ed25519_js_1.x25519.getPublicKey(priv);
|
|
48
|
+
return {
|
|
49
|
+
privateKey: Buffer.from(priv).toString("hex"),
|
|
50
|
+
publicKey: Buffer.from(pub).toString("hex"),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function generatePqPreKey(identitySigningPrivate) {
|
|
54
|
+
const sigKey = hexToBytes(identitySigningPrivate, "identitySigningPrivate");
|
|
55
|
+
const { publicKey, secretKey } = ml_kem_js_1.ml_kem768.keygen();
|
|
56
|
+
const signature = ed25519_js_1.ed25519.sign((0, sha2_js_1.sha256)(publicKey), sigKey);
|
|
57
|
+
return {
|
|
58
|
+
publicKey: Buffer.from(publicKey).toString("hex"),
|
|
59
|
+
secretKey: Buffer.from(secretKey).toString("hex"),
|
|
60
|
+
signature: Buffer.from(signature).toString("hex"),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function initiateSession(params) {
|
|
64
|
+
const { identityKeyPair, remoteIdentityPublic, remoteSignedPreKeyPublic, remoteOneTimePreKeyPublic, remotePqPreKeyPublic, } = params;
|
|
65
|
+
const ikPriv = hexToBytes(identityKeyPair.privateKey, "identityPrivateKey");
|
|
66
|
+
const remoteIkPub = hexToBytes(remoteIdentityPublic, "remoteIdentityPublic");
|
|
67
|
+
const remoteSPKPub = hexToBytes(remoteSignedPreKeyPublic, "remoteSignedPreKeyPublic");
|
|
68
|
+
const remotePqPub = hexToBytes(remotePqPreKeyPublic, "remotePqPreKeyPublic");
|
|
69
|
+
const ephPriv = (0, utils_js_1.randomBytes)(32);
|
|
70
|
+
const ephPub = ed25519_js_1.x25519.getPublicKey(ephPriv);
|
|
71
|
+
const dh1 = ed25519_js_1.x25519.getSharedSecret(ikPriv, remoteSPKPub);
|
|
72
|
+
const dh2 = ed25519_js_1.x25519.getSharedSecret(ephPriv, remoteIkPub);
|
|
73
|
+
const dh3 = ed25519_js_1.x25519.getSharedSecret(ephPriv, remoteSPKPub);
|
|
74
|
+
let dh4 = null;
|
|
75
|
+
if (remoteOneTimePreKeyPublic) {
|
|
76
|
+
const remoteOPKPub = hexToBytes(remoteOneTimePreKeyPublic, "remoteOneTimePreKeyPublic");
|
|
77
|
+
dh4 = ed25519_js_1.x25519.getSharedSecret(ephPriv, remoteOPKPub);
|
|
78
|
+
}
|
|
79
|
+
const { cipherText: pqCt, sharedSecret: pqShared } = ml_kem_js_1.ml_kem768.encapsulate(remotePqPub);
|
|
80
|
+
const dhLen = dh1.length + dh2.length + dh3.length;
|
|
81
|
+
const dh4Len = dh4 ? dh4.length : 0;
|
|
82
|
+
const totalLen = dhLen + dh4Len + pqShared.length;
|
|
83
|
+
const combined = new Uint8Array(totalLen);
|
|
84
|
+
let offset = 0;
|
|
85
|
+
combined.set(dh1, offset);
|
|
86
|
+
offset += dh1.length;
|
|
87
|
+
combined.set(dh2, offset);
|
|
88
|
+
offset += dh2.length;
|
|
89
|
+
combined.set(dh3, offset);
|
|
90
|
+
offset += dh3.length;
|
|
91
|
+
if (dh4) {
|
|
92
|
+
combined.set(dh4, offset);
|
|
93
|
+
offset += dh4.length;
|
|
94
|
+
}
|
|
95
|
+
combined.set(pqShared, offset);
|
|
96
|
+
const sharedSecret = (0, hkdf_js_1.hkdf)(sha2_js_1.sha256, combined, undefined, PQXDH_INFO, 32);
|
|
97
|
+
return {
|
|
98
|
+
sharedSecret: Buffer.from(sharedSecret).toString("hex"),
|
|
99
|
+
ephemeralPublicKey: Buffer.from(ephPub).toString("hex"),
|
|
100
|
+
pqCiphertext: Buffer.from(pqCt).toString("hex"),
|
|
101
|
+
algorithm: "pqxdh",
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function respondToSession(params) {
|
|
105
|
+
const { identityKeyPair, signedPreKeyPrivate, oneTimePreKeyPrivate, pqPreKeySecret, remoteIdentityPublic, remoteEphemeralPublic, pqCiphertext, } = params;
|
|
106
|
+
const ikPriv = hexToBytes(identityKeyPair.privateKey, "identityPrivateKey");
|
|
107
|
+
const spkPriv = hexToBytes(signedPreKeyPrivate, "signedPreKeyPrivate");
|
|
108
|
+
const pqSecret = hexToBytes(pqPreKeySecret, "pqPreKeySecret");
|
|
109
|
+
const remoteIkPub = hexToBytes(remoteIdentityPublic, "remoteIdentityPublic");
|
|
110
|
+
const remoteEphPub = hexToBytes(remoteEphemeralPublic, "remoteEphemeralPublic");
|
|
111
|
+
const pqCt = hexToBytes(pqCiphertext, "pqCiphertext");
|
|
112
|
+
const dh1 = ed25519_js_1.x25519.getSharedSecret(spkPriv, remoteIkPub);
|
|
113
|
+
const dh2 = ed25519_js_1.x25519.getSharedSecret(ikPriv, remoteEphPub);
|
|
114
|
+
const dh3 = ed25519_js_1.x25519.getSharedSecret(spkPriv, remoteEphPub);
|
|
115
|
+
let dh4 = null;
|
|
116
|
+
if (oneTimePreKeyPrivate) {
|
|
117
|
+
const opkPriv = hexToBytes(oneTimePreKeyPrivate, "oneTimePreKeyPrivate");
|
|
118
|
+
dh4 = ed25519_js_1.x25519.getSharedSecret(opkPriv, remoteEphPub);
|
|
119
|
+
}
|
|
120
|
+
const pqShared = ml_kem_js_1.ml_kem768.decapsulate(pqCt, pqSecret);
|
|
121
|
+
const dhLen = dh1.length + dh2.length + dh3.length;
|
|
122
|
+
const dh4Len = dh4 ? dh4.length : 0;
|
|
123
|
+
const totalLen = dhLen + dh4Len + pqShared.length;
|
|
124
|
+
const combined = new Uint8Array(totalLen);
|
|
125
|
+
let offset = 0;
|
|
126
|
+
combined.set(dh1, offset);
|
|
127
|
+
offset += dh1.length;
|
|
128
|
+
combined.set(dh2, offset);
|
|
129
|
+
offset += dh2.length;
|
|
130
|
+
combined.set(dh3, offset);
|
|
131
|
+
offset += dh3.length;
|
|
132
|
+
if (dh4) {
|
|
133
|
+
combined.set(dh4, offset);
|
|
134
|
+
offset += dh4.length;
|
|
135
|
+
}
|
|
136
|
+
combined.set(pqShared, offset);
|
|
137
|
+
const sharedSecret = (0, hkdf_js_1.hkdf)(sha2_js_1.sha256, combined, undefined, PQXDH_INFO, 32);
|
|
138
|
+
return {
|
|
139
|
+
sharedSecret: Buffer.from(sharedSecret).toString("hex"),
|
|
140
|
+
algorithm: "pqxdh",
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=pqxdh.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export interface MessageHeader {
|
|
2
|
+
publicKey: string;
|
|
3
|
+
previousChainLength: number;
|
|
4
|
+
messageNumber: number;
|
|
5
|
+
}
|
|
6
|
+
export interface EncryptedMessage {
|
|
7
|
+
header: MessageHeader;
|
|
8
|
+
ciphertext: string;
|
|
9
|
+
}
|
|
10
|
+
export interface SymmetricRatchetState {
|
|
11
|
+
chainKey: string;
|
|
12
|
+
index: number;
|
|
13
|
+
}
|
|
14
|
+
export interface DoubleRatchetState {
|
|
15
|
+
sendingRatchetPrivate: string;
|
|
16
|
+
sendingRatchetPublic: string;
|
|
17
|
+
receivingRatchetPublic: string | null;
|
|
18
|
+
rootKey: string;
|
|
19
|
+
sendingChainKey: string | null;
|
|
20
|
+
receivingChainKey: string | null;
|
|
21
|
+
sendingMessageNumber: number;
|
|
22
|
+
receivingMessageNumber: number;
|
|
23
|
+
previousChainLength: number;
|
|
24
|
+
skippedKeys: Record<string, string>;
|
|
25
|
+
}
|
|
26
|
+
export declare class SymmetricRatchet {
|
|
27
|
+
private _chainKey;
|
|
28
|
+
private _index;
|
|
29
|
+
constructor(chainKey: string | Uint8Array, index?: number);
|
|
30
|
+
get state(): SymmetricRatchetState;
|
|
31
|
+
next(): {
|
|
32
|
+
messageKey: Uint8Array;
|
|
33
|
+
index: number;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export declare class DoubleRatchet {
|
|
37
|
+
private _state;
|
|
38
|
+
private constructor();
|
|
39
|
+
get state(): DoubleRatchetState;
|
|
40
|
+
static initAlice(sharedSecret: string, remoteRatchetPublic: string): DoubleRatchet;
|
|
41
|
+
static initBob(sharedSecret: string, ourRatchetKeyPair: {
|
|
42
|
+
privateKey: string;
|
|
43
|
+
publicKey: string;
|
|
44
|
+
}): DoubleRatchet;
|
|
45
|
+
static fromState(state: DoubleRatchetState): DoubleRatchet;
|
|
46
|
+
encrypt(plaintext: string | Uint8Array): EncryptedMessage;
|
|
47
|
+
decrypt(header: MessageHeader, ciphertext: string): Uint8Array;
|
|
48
|
+
private _decryptWithKey;
|
|
49
|
+
private _dhRatchetStep;
|
|
50
|
+
private _skipMessages;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=ratchet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ratchet.d.ts","sourceRoot":"","sources":["../../src/protocols/ratchet.ts"],"names":[],"mappings":"AA2BA,MAAM,WAAW,aAAa;IAE5B,SAAS,EAAE,MAAM,CAAC;IAElB,mBAAmB,EAAE,MAAM,CAAC;IAE5B,aAAa,EAAE,MAAM,CAAC;CACvB;AAGD,MAAM,WAAW,gBAAgB;IAE/B,MAAM,EAAE,aAAa,CAAC;IAEtB,UAAU,EAAE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