@sebastienrousseau/crypto-lib 0.0.35 → 0.0.36
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 +17 -2
- package/dist/accel/index.d.ts +5 -4
- package/dist/accel/index.d.ts.map +1 -1
- package/dist/accel/index.js +5 -5
- package/dist/accel/kdf-backend.d.ts +13 -0
- package/dist/accel/kdf-backend.d.ts.map +1 -0
- package/dist/accel/kdf-backend.js +81 -0
- package/dist/accel/native-pqc-bridge.d.ts.map +1 -1
- package/dist/accel/native-pqc-bridge.js +12 -52
- package/dist/accel/pq-backend.d.ts +3652 -0
- package/dist/accel/pq-backend.d.ts.map +1 -0
- package/dist/accel/pq-backend.js +215 -0
- package/dist/accel/runtime.d.ts +3 -0
- package/dist/accel/runtime.d.ts.map +1 -0
- package/dist/accel/runtime.js +9 -0
- package/dist/accel/wasm-bridge.d.ts.map +1 -1
- package/dist/accel/wasm-bridge.js +14 -13
- package/dist/accel/webcrypto-bridge.d.ts.map +1 -1
- package/dist/accel/webcrypto-bridge.js +14 -13
- package/dist/accel/webcrypto-modern.d.ts.map +1 -1
- package/dist/accel/webcrypto-modern.js +15 -14
- package/dist/accel/worker-pool.d.ts +18 -0
- package/dist/accel/worker-pool.d.ts.map +1 -1
- package/dist/accel/worker-pool.js +113 -37
- package/dist/bin/cryptolib.d.ts +7 -4
- package/dist/bin/cryptolib.d.ts.map +1 -1
- package/dist/bin/cryptolib.js +6 -6
- package/dist/crypto.d.ts.map +1 -1
- package/dist/crypto.js +2 -1
- package/dist/encoding.d.ts +10 -0
- package/dist/encoding.d.ts.map +1 -0
- package/dist/encoding.js +84 -0
- package/dist/errors.d.ts +11 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +20 -1
- package/dist/high-level/key-wrap.d.ts.map +1 -1
- package/dist/high-level/key-wrap.js +12 -17
- package/dist/high-level/multi-recipient.d.ts.map +1 -1
- package/dist/high-level/multi-recipient.js +15 -28
- package/dist/high-level/password-encrypt.d.ts.map +1 -1
- package/dist/high-level/password-encrypt.js +11 -11
- package/dist/high-level/sealedbox.d.ts.map +1 -1
- package/dist/high-level/sealedbox.js +16 -28
- package/dist/high-level/secretbox.d.ts.map +1 -1
- package/dist/high-level/secretbox.js +11 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/key/keystore.d.ts.map +1 -1
- package/dist/key/keystore.js +2 -1
- package/dist/keys/keygen.d.ts.map +1 -1
- package/dist/keys/keygen.js +13 -14
- package/dist/keys/keyring.d.ts.map +1 -1
- package/dist/keys/keyring.js +4 -2
- package/dist/keys/serialize.d.ts.map +1 -1
- package/dist/keys/serialize.js +18 -16
- package/dist/lib/decrypt.d.ts.map +1 -1
- package/dist/lib/decrypt.js +2 -1
- package/dist/lib/generate.d.ts +2 -1
- package/dist/lib/generate.d.ts.map +1 -1
- package/dist/lib/generate.js +7 -6
- package/dist/lib/key-output.d.ts +4 -1
- package/dist/lib/key-output.d.ts.map +1 -1
- package/dist/lib/key-output.js +2 -2
- package/dist/lib/reformat.d.ts +2 -1
- package/dist/lib/reformat.d.ts.map +1 -1
- package/dist/lib/reformat.js +2 -2
- package/dist/lib/revoke.d.ts +2 -1
- package/dist/lib/revoke.d.ts.map +1 -1
- package/dist/lib/revoke.js +2 -2
- package/dist/lib/verify.d.ts +6 -2
- package/dist/lib/verify.d.ts.map +1 -1
- package/dist/lib/verify.js +28 -9
- package/dist/modern/aead.d.ts.map +1 -1
- package/dist/modern/aead.js +11 -10
- package/dist/modern/aes.d.ts.map +1 -1
- package/dist/modern/aes.js +10 -9
- package/dist/modern/cost-limits.d.ts.map +1 -1
- package/dist/modern/cost-limits.js +3 -2
- package/dist/modern/curves.d.ts +10 -5
- package/dist/modern/curves.d.ts.map +1 -1
- package/dist/modern/curves.js +43 -36
- package/dist/modern/ecdh.d.ts +2 -1
- package/dist/modern/ecdh.d.ts.map +1 -1
- package/dist/modern/ecdh.js +10 -9
- package/dist/modern/fn-dsa.d.ts.map +1 -1
- package/dist/modern/fn-dsa.js +9 -8
- package/dist/modern/hash.d.ts.map +1 -1
- package/dist/modern/hash.js +5 -3
- package/dist/modern/hpke-xwing.d.ts +10 -0
- package/dist/modern/hpke-xwing.d.ts.map +1 -0
- package/dist/modern/hpke-xwing.js +26 -0
- package/dist/modern/hpke.d.ts +1 -1
- package/dist/modern/hpke.d.ts.map +1 -1
- package/dist/modern/hpke.js +60 -28
- package/dist/modern/hybrid-combiner.d.ts +20 -0
- package/dist/modern/hybrid-combiner.d.ts.map +1 -0
- package/dist/modern/hybrid-combiner.js +79 -0
- package/dist/modern/index.d.ts +10 -10
- package/dist/modern/index.d.ts.map +1 -1
- package/dist/modern/index.js +17 -7
- package/dist/modern/kdf.d.ts.map +1 -1
- package/dist/modern/kdf.js +12 -12
- package/dist/modern/mac.d.ts +1 -0
- package/dist/modern/mac.d.ts.map +1 -1
- package/dist/modern/mac.js +24 -15
- package/dist/modern/password.d.ts.map +1 -1
- package/dist/modern/password.js +19 -18
- package/dist/modern/pq-hash-sign.d.ts.map +1 -1
- package/dist/modern/pq-hash-sign.js +23 -22
- package/dist/modern/pq-kem.d.ts +8 -0
- package/dist/modern/pq-kem.d.ts.map +1 -1
- package/dist/modern/pq-kem.js +71 -79
- package/dist/modern/pq-sign.d.ts +9 -2
- package/dist/modern/pq-sign.d.ts.map +1 -1
- package/dist/modern/pq-sign.js +60 -23
- package/dist/modern/pq.d.ts +0 -17
- package/dist/modern/pq.d.ts.map +1 -1
- package/dist/modern/pq.js +15 -43
- package/dist/modern/signing.d.ts +2 -1
- package/dist/modern/signing.d.ts.map +1 -1
- package/dist/modern/signing.js +14 -13
- package/dist/protocols/iso20022.d.ts.map +1 -1
- package/dist/protocols/iso20022.js +12 -6
- package/dist/protocols/opaque/ksf.js +2 -2
- package/dist/protocols/opaque/suite.d.ts +1 -8
- package/dist/protocols/opaque/suite.d.ts.map +1 -1
- package/dist/protocols/opaque/suite.js +5 -10
- package/dist/protocols/pqxdh.d.ts +9 -2
- package/dist/protocols/pqxdh.d.ts.map +1 -1
- package/dist/protocols/pqxdh.js +99 -94
- package/dist/protocols/ratchet.d.ts.map +1 -1
- package/dist/protocols/ratchet.js +14 -15
- package/dist/protocols/threshold.d.ts.map +1 -1
- package/dist/protocols/threshold.js +16 -15
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +26 -0
- package/dist/streaming/chunks.d.ts +31 -0
- package/dist/streaming/chunks.d.ts.map +1 -1
- package/dist/streaming/chunks.js +149 -13
- package/dist/streaming/stream-aead.d.ts +9 -0
- package/dist/streaming/stream-aead.d.ts.map +1 -1
- package/dist/streaming/stream-aead.js +27 -53
- package/dist/streaming/stream-hash.d.ts.map +1 -1
- package/dist/streaming/stream-hash.js +6 -4
- package/dist/streaming/stream-multi-pq-aead.d.ts +12 -0
- package/dist/streaming/stream-multi-pq-aead.d.ts.map +1 -1
- package/dist/streaming/stream-multi-pq-aead.js +82 -106
- package/dist/streaming/stream-pq-aead.d.ts +7 -2
- package/dist/streaming/stream-pq-aead.d.ts.map +1 -1
- package/dist/streaming/stream-pq-aead.js +29 -79
- package/dist/streaming/web-streams.d.ts +5 -2
- package/dist/streaming/web-streams.d.ts.map +1 -1
- package/dist/streaming/web-streams.js +90 -151
- package/dist/testing/index.d.ts +5 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +13 -0
- package/dist/tokens/index.d.ts.map +1 -1
- package/dist/tokens/key-rotation.d.ts.map +1 -1
- package/dist/tokens/key-rotation.js +4 -2
- package/dist/tokens/paseto.d.ts +2 -0
- package/dist/tokens/paseto.d.ts.map +1 -1
- package/dist/tokens/paseto.js +56 -29
- package/dist/types/types.d.ts +1 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +3 -2
- package/package.json +12 -2
- package/dist/config/config.d.ts +0 -8
- package/dist/config/config.d.ts.map +0 -1
- package/dist/config/config.js +0 -13
- package/dist/key/key.d.ts +0 -10
- package/dist/key/key.d.ts.map +0 -1
- package/dist/key/key.js +0 -25
package/dist/lib/reformat.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { type KeyOutputOptions } from "./key-output";
|
|
1
2
|
import * as types from "../types/types";
|
|
2
3
|
export interface ArmoredKeyResult {
|
|
3
4
|
publicKey: string;
|
|
4
5
|
privateKey: string;
|
|
5
6
|
revocationCertificate?: string;
|
|
6
7
|
}
|
|
7
|
-
export declare const reformat: (data: types.dataReformat) => Promise<ArmoredKeyResult>;
|
|
8
|
+
export declare const reformat: (data: types.dataReformat, output?: KeyOutputOptions) => Promise<ArmoredKeyResult>;
|
|
8
9
|
export default reformat;
|
|
9
10
|
//# sourceMappingURL=reformat.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reformat.d.ts","sourceRoot":"","sources":["../../src/lib/reformat.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reformat.d.ts","sourceRoot":"","sources":["../../src/lib/reformat.ts"],"names":[],"mappings":"AAMA,OAAO,EAAmB,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEtE,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AAWxC,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IAKnB,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAqBD,eAAO,MAAM,QAAQ,GACnB,MAAM,KAAK,CAAC,YAAY,EACxB,SAAQ,gBAAqB,KAC5B,OAAO,CAAC,gBAAgB,CAgC1B,CAAC;AAGF,eAAe,QAAQ,CAAC"}
|
package/dist/lib/reformat.js
CHANGED
|
@@ -37,7 +37,7 @@ exports.reformat = void 0;
|
|
|
37
37
|
const openpgp = __importStar(require("openpgp"));
|
|
38
38
|
const key_output_1 = require("./key-output");
|
|
39
39
|
const keystore_1 = require("../key/keystore");
|
|
40
|
-
const reformat = async (data) => {
|
|
40
|
+
const reformat = async (data, output = {}) => {
|
|
41
41
|
const { expiration, passphrase } = data;
|
|
42
42
|
const { privateKeyArmored } = await (0, keystore_1.loadKeystore)();
|
|
43
43
|
const privateKey = await (0, keystore_1.unlockPrivateKey)(privateKeyArmored, passphrase);
|
|
@@ -59,7 +59,7 @@ const reformat = async (data) => {
|
|
|
59
59
|
content: reformatted.revocationCertificate,
|
|
60
60
|
secret: false,
|
|
61
61
|
},
|
|
62
|
-
]);
|
|
62
|
+
], output);
|
|
63
63
|
return reformatted;
|
|
64
64
|
};
|
|
65
65
|
exports.reformat = reformat;
|
package/dist/lib/revoke.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { type KeyOutputOptions } from "./key-output";
|
|
1
2
|
import * as types from "../types/types";
|
|
2
3
|
import type { ArmoredKeyResult } from "./reformat.js";
|
|
3
|
-
export declare const revoke: (data: types.dataRevoke) => Promise<ArmoredKeyResult>;
|
|
4
|
+
export declare const revoke: (data: types.dataRevoke, output?: KeyOutputOptions) => Promise<ArmoredKeyResult>;
|
|
4
5
|
export default revoke;
|
|
5
6
|
//# sourceMappingURL=revoke.d.ts.map
|
package/dist/lib/revoke.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"revoke.d.ts","sourceRoot":"","sources":["../../src/lib/revoke.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"revoke.d.ts","sourceRoot":"","sources":["../../src/lib/revoke.ts"],"names":[],"mappings":"AAMA,OAAO,EAAmB,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEtE,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AAExC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAmBtD,eAAO,MAAM,MAAM,GACjB,MAAM,KAAK,CAAC,UAAU,EACtB,SAAQ,gBAAqB,KAC5B,OAAO,CAAC,gBAAgB,CAyB1B,CAAC;AAGF,eAAe,MAAM,CAAC"}
|
package/dist/lib/revoke.js
CHANGED
|
@@ -37,7 +37,7 @@ exports.revoke = void 0;
|
|
|
37
37
|
const openpgp = __importStar(require("openpgp"));
|
|
38
38
|
const key_output_1 = require("./key-output");
|
|
39
39
|
const keystore_1 = require("../key/keystore");
|
|
40
|
-
const revoke = async (data) => {
|
|
40
|
+
const revoke = async (data, output = {}) => {
|
|
41
41
|
const { flag, passphrase, reason } = data;
|
|
42
42
|
const { privateKeyArmored } = await (0, keystore_1.loadKeystore)();
|
|
43
43
|
const privateKey = await (0, keystore_1.unlockPrivateKey)(privateKeyArmored, passphrase);
|
|
@@ -52,7 +52,7 @@ const revoke = async (data) => {
|
|
|
52
52
|
await (0, key_output_1.writeKeyOutputs)([
|
|
53
53
|
{ name: "rsa-revoke.pub", content: revokedPubArmored, secret: false },
|
|
54
54
|
{ name: "rsa-revoke.key", content: revokedPrivArmored, secret: true },
|
|
55
|
-
]);
|
|
55
|
+
], output);
|
|
56
56
|
return revoked;
|
|
57
57
|
};
|
|
58
58
|
exports.revoke = revoke;
|
package/dist/lib/verify.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import * as openpgp from "openpgp";
|
|
2
1
|
import * as types from "../types/types";
|
|
3
|
-
export
|
|
2
|
+
export interface PgpVerifyResult {
|
|
3
|
+
verified: boolean;
|
|
4
|
+
data: string;
|
|
5
|
+
keyIDs: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare const verify: (data: types.dataVerify) => Promise<PgpVerifyResult>;
|
|
4
8
|
export default verify;
|
|
5
9
|
//# sourceMappingURL=verify.d.ts.map
|
package/dist/lib/verify.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../src/lib/verify.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../src/lib/verify.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AAGxC,MAAM,WAAW,eAAe;IAK9B,QAAQ,EAAE,OAAO,CAAC;IAElB,IAAI,EAAE,MAAM,CAAC;IAEb,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AA4CD,eAAO,MAAM,MAAM,GACjB,MAAM,KAAK,CAAC,UAAU,KACrB,OAAO,CAAC,eAAe,CAuBzB,CAAC;AAGF,eAAe,MAAM,CAAC"}
|
package/dist/lib/verify.js
CHANGED
|
@@ -35,17 +35,36 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.verify = void 0;
|
|
37
37
|
const openpgp = __importStar(require("openpgp"));
|
|
38
|
+
const unbase64 = (value) => Buffer.from(value, "base64").toString("latin1");
|
|
39
|
+
async function signedInput(data) {
|
|
40
|
+
if (data.signature !== undefined) {
|
|
41
|
+
return {
|
|
42
|
+
message: await openpgp.createMessage({ text: data.message }),
|
|
43
|
+
signature: await openpgp.readSignature({
|
|
44
|
+
armoredSignature: unbase64(data.signature),
|
|
45
|
+
}),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
message: await openpgp.readCleartextMessage({
|
|
50
|
+
cleartextMessage: data.message,
|
|
51
|
+
}),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
38
54
|
const verify = async (data) => {
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
message: await openpgp.createMessage({ text: message }),
|
|
46
|
-
verificationKeys: await openpgp.readKey({ armoredKey: publicKey }),
|
|
47
|
-
date,
|
|
55
|
+
const keys = [data.verificationKeys].flat();
|
|
56
|
+
const verificationKeys = await Promise.all(keys.map((key) => openpgp.readKey({ armoredKey: unbase64(key) })));
|
|
57
|
+
const result = await openpgp.verify({
|
|
58
|
+
...(await signedInput(data)),
|
|
59
|
+
verificationKeys,
|
|
60
|
+
date: data.date,
|
|
48
61
|
});
|
|
62
|
+
const outcomes = await Promise.all(result.signatures.map((s) => s.verified.then(() => true, () => false)));
|
|
63
|
+
return {
|
|
64
|
+
verified: outcomes.length > 0 && outcomes.every(Boolean),
|
|
65
|
+
data: result.data,
|
|
66
|
+
keyIDs: result.signatures.map((s) => s.keyID.toHex()),
|
|
67
|
+
};
|
|
49
68
|
};
|
|
50
69
|
exports.verify = verify;
|
|
51
70
|
exports.default = exports.verify;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aead.d.ts","sourceRoot":"","sources":["../../src/modern/aead.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"aead.d.ts","sourceRoot":"","sources":["../../src/modern/aead.ts"],"names":[],"mappings":"AAqBA,MAAM,WAAW,iBAAiB;IAEhC,UAAU,EAAE,MAAM,CAAC;IAEnB,SAAS,EAAE,oBAAoB,CAAC;CACjC;AAGD,MAAM,WAAW,kBAAkB;IAEjC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;IAEzB,SAAS,EAAE,MAAM,GAAG,UAAU,CAAC;IAE/B,GAAG,CAAC,EAAE,UAAU,CAAC;CAClB;AAGD,MAAM,WAAW,kBAAkB;IAEjC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;IAEzB,UAAU,EAAE,MAAM,CAAC;IAEnB,GAAG,CAAC,EAAE,UAAU,CAAC;CAClB;AAyBD,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,iBAAiB,CAwB1E;AAOD,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,UAAU,CAsBnE"}
|
package/dist/modern/aead.js
CHANGED
|
@@ -4,23 +4,24 @@ exports.aeadEncrypt = aeadEncrypt;
|
|
|
4
4
|
exports.aeadDecrypt = aeadDecrypt;
|
|
5
5
|
const chacha_js_1 = require("@noble/ciphers/chacha.js");
|
|
6
6
|
const utils_js_1 = require("@noble/ciphers/utils.js");
|
|
7
|
-
const
|
|
7
|
+
const errors_1 = require("../errors");
|
|
8
|
+
const encoding_1 = require("../encoding");
|
|
8
9
|
function toBytes(input, encoding = "utf8") {
|
|
9
10
|
if (input instanceof Uint8Array)
|
|
10
11
|
return input;
|
|
11
12
|
if (encoding === "hex") {
|
|
12
|
-
if (!
|
|
13
|
-
throw new
|
|
13
|
+
if (!(0, encoding_1.isHex)(input)) {
|
|
14
|
+
throw new errors_1.CryptoError("Invalid hex string", errors_1.CryptoErrorCode.INVALID_HEX);
|
|
14
15
|
}
|
|
15
|
-
return
|
|
16
|
+
return (0, encoding_1.decodeHex)(input);
|
|
16
17
|
}
|
|
17
|
-
return
|
|
18
|
+
return (0, encoding_1.utf8)(input);
|
|
18
19
|
}
|
|
19
20
|
const NONCE_LENGTH = 24;
|
|
20
21
|
function aeadEncrypt(options) {
|
|
21
22
|
const key = toBytes(options.key, "hex");
|
|
22
23
|
if (key.length !== 32) {
|
|
23
|
-
throw new
|
|
24
|
+
throw new errors_1.CryptoError(`Key must be 32 bytes (256 bits), got ${key.length}`, errors_1.CryptoErrorCode.INVALID_KEY);
|
|
24
25
|
}
|
|
25
26
|
const plaintext = toBytes(options.plaintext, "utf8");
|
|
26
27
|
const nonce = (0, utils_js_1.randomBytes)(NONCE_LENGTH);
|
|
@@ -30,18 +31,18 @@ function aeadEncrypt(options) {
|
|
|
30
31
|
combined.set(nonce);
|
|
31
32
|
combined.set(sealed, NONCE_LENGTH);
|
|
32
33
|
return {
|
|
33
|
-
ciphertext:
|
|
34
|
+
ciphertext: (0, encoding_1.toBase64)(combined),
|
|
34
35
|
algorithm: "xchacha20-poly1305",
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
38
|
function aeadDecrypt(options) {
|
|
38
39
|
const key = toBytes(options.key, "hex");
|
|
39
40
|
if (key.length !== 32) {
|
|
40
|
-
throw new
|
|
41
|
+
throw new errors_1.CryptoError(`Key must be 32 bytes (256 bits), got ${key.length}`, errors_1.CryptoErrorCode.INVALID_KEY);
|
|
41
42
|
}
|
|
42
|
-
const combined =
|
|
43
|
+
const combined = (0, encoding_1.fromBase64)(options.ciphertext);
|
|
43
44
|
if (combined.length < NONCE_LENGTH + 16) {
|
|
44
|
-
throw new
|
|
45
|
+
throw new errors_1.CryptoError("Ciphertext too short — missing nonce or auth tag", errors_1.CryptoErrorCode.INVALID_CIPHERTEXT);
|
|
45
46
|
}
|
|
46
47
|
const nonce = combined.subarray(0, NONCE_LENGTH);
|
|
47
48
|
const sealed = combined.subarray(NONCE_LENGTH);
|
package/dist/modern/aes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aes.d.ts","sourceRoot":"","sources":["../../src/modern/aes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"aes.d.ts","sourceRoot":"","sources":["../../src/modern/aes.ts"],"names":[],"mappings":"AA0BA,MAAM,WAAW,oBAAoB;IAEnC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;IAEzB,SAAS,EAAE,MAAM,GAAG,UAAU,CAAC;IAE/B,GAAG,CAAC,EAAE,UAAU,CAAC;CAClB;AAGD,MAAM,MAAM,eAAe,GAAG,aAAa,GAAG,aAAa,CAAC;AAE5D,MAAM,MAAM,kBAAkB,GAAG,iBAAiB,GAAG,iBAAiB,CAAC;AAGvE,MAAM,WAAW,mBAAmB;IAElC,UAAU,EAAE,MAAM,CAAC;IAEnB,SAAS,EAAE,eAAe,CAAC;CAC5B;AAGD,MAAM,WAAW,uBAAuB;IAEtC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;IAEzB,SAAS,EAAE,MAAM,GAAG,UAAU,CAAC;IAE/B,GAAG,CAAC,EAAE,UAAU,CAAC;CAClB;AAGD,MAAM,WAAW,sBAAsB;IAErC,UAAU,EAAE,MAAM,CAAC;IAEnB,SAAS,EAAE,kBAAkB,CAAC;CAC/B;AAGD,MAAM,WAAW,uBAAuB;IAEtC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;IAEzB,UAAU,EAAE,MAAM,CAAC;IAEnB,GAAG,CAAC,EAAE,UAAU,CAAC;CAClB;AAGD,MAAM,WAAW,oBAAoB;IAEnC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;IAEzB,UAAU,EAAE,MAAM,CAAC;IAEnB,GAAG,CAAC,EAAE,UAAU,CAAC;CAClB;AAqED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,oBAAoB,GAC5B,mBAAmB,CAcrB;AAOD,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,UAAU,CAKvE;AAaD,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,uBAAuB,GAC/B,sBAAsB,CAcxB;AAOD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,UAAU,CAK7E"}
|
package/dist/modern/aes.js
CHANGED
|
@@ -6,24 +6,25 @@ exports.aesGcmSivEncrypt = aesGcmSivEncrypt;
|
|
|
6
6
|
exports.aesGcmSivDecrypt = aesGcmSivDecrypt;
|
|
7
7
|
const aes_js_1 = require("@noble/ciphers/aes.js");
|
|
8
8
|
const utils_js_1 = require("@noble/ciphers/utils.js");
|
|
9
|
-
const
|
|
9
|
+
const errors_1 = require("../errors");
|
|
10
|
+
const encoding_1 = require("../encoding");
|
|
10
11
|
function toBytes(input, encoding = "utf8") {
|
|
11
12
|
if (input instanceof Uint8Array)
|
|
12
13
|
return input;
|
|
13
14
|
if (encoding === "hex") {
|
|
14
|
-
if (!
|
|
15
|
-
throw new
|
|
15
|
+
if (!(0, encoding_1.isHex)(input)) {
|
|
16
|
+
throw new errors_1.CryptoError("Invalid hex string", errors_1.CryptoErrorCode.INVALID_HEX);
|
|
16
17
|
}
|
|
17
|
-
return
|
|
18
|
+
return (0, encoding_1.decodeHex)(input);
|
|
18
19
|
}
|
|
19
|
-
return
|
|
20
|
+
return (0, encoding_1.utf8)(input);
|
|
20
21
|
}
|
|
21
22
|
const NONCE_LENGTH = 12;
|
|
22
23
|
const TAG_LENGTH = 16;
|
|
23
24
|
function validateAesKey(rawKey) {
|
|
24
25
|
const key = toBytes(rawKey, "hex");
|
|
25
26
|
if (key.length !== 16 && key.length !== 32) {
|
|
26
|
-
throw new
|
|
27
|
+
throw new errors_1.CryptoError(`Key must be 16 bytes (128 bits) or 32 bytes (256 bits), got ${key.length}`, errors_1.CryptoErrorCode.INVALID_KEY);
|
|
27
28
|
}
|
|
28
29
|
return key;
|
|
29
30
|
}
|
|
@@ -31,12 +32,12 @@ function packNonceAndSealed(nonce, sealed) {
|
|
|
31
32
|
const combined = new Uint8Array(NONCE_LENGTH + sealed.length);
|
|
32
33
|
combined.set(nonce);
|
|
33
34
|
combined.set(sealed, NONCE_LENGTH);
|
|
34
|
-
return
|
|
35
|
+
return (0, encoding_1.toBase64)(combined);
|
|
35
36
|
}
|
|
36
37
|
function unpackNonceAndSealed(ciphertext) {
|
|
37
|
-
const combined =
|
|
38
|
+
const combined = (0, encoding_1.fromBase64)(ciphertext);
|
|
38
39
|
if (combined.length < NONCE_LENGTH + TAG_LENGTH) {
|
|
39
|
-
throw new
|
|
40
|
+
throw new errors_1.CryptoError("Ciphertext too short — missing nonce or auth tag", errors_1.CryptoErrorCode.INVALID_CIPHERTEXT);
|
|
40
41
|
}
|
|
41
42
|
return {
|
|
42
43
|
nonce: combined.subarray(0, NONCE_LENGTH),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cost-limits.d.ts","sourceRoot":"","sources":["../../src/modern/cost-limits.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cost-limits.d.ts","sourceRoot":"","sources":["../../src/modern/cost-limits.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,eAAe,KAAK,CAAC;AAElC,eAAO,MAAM,iBAAiB,SAAS,CAAC;AAExC,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAExC,eAAO,MAAM,YAAY,SAAS,CAAC;AAEnC,eAAO,MAAM,YAAY,IAAI,CAAC;AAE9B,eAAO,MAAM,YAAY,IAAI,CAAC;AAE9B,eAAO,MAAM,qBAAqB,UAAY,CAAC;AAa/C,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAItE;AAGD,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAUtE;AAGD,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAE9D"}
|
|
@@ -4,6 +4,7 @@ exports.MAX_PBKDF2_ITERATIONS = exports.MAX_SCRYPT_P = exports.MAX_SCRYPT_R = ex
|
|
|
4
4
|
exports.checkArgon2Costs = checkArgon2Costs;
|
|
5
5
|
exports.checkScryptCosts = checkScryptCosts;
|
|
6
6
|
exports.checkPbkdf2Iterations = checkPbkdf2Iterations;
|
|
7
|
+
const errors_1 = require("../errors");
|
|
7
8
|
exports.MAX_ARGON2_TIME = 10;
|
|
8
9
|
exports.MAX_ARGON2_MEMORY = 262144;
|
|
9
10
|
exports.MAX_ARGON2_PARALLELISM = 8;
|
|
@@ -13,7 +14,7 @@ exports.MAX_SCRYPT_P = 4;
|
|
|
13
14
|
exports.MAX_PBKDF2_ITERATIONS = 1_000_000;
|
|
14
15
|
function checkRange(name, value, min, max) {
|
|
15
16
|
if (!Number.isInteger(value) || value < min || value > max) {
|
|
16
|
-
throw new
|
|
17
|
+
throw new errors_1.CryptoError(`${name} must be an integer ${min}–${max}, got ${value}`, errors_1.CryptoErrorCode.INVALID_INPUT);
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
function checkArgon2Costs(t, m, p) {
|
|
@@ -24,7 +25,7 @@ function checkArgon2Costs(t, m, p) {
|
|
|
24
25
|
function checkScryptCosts(N, r, p) {
|
|
25
26
|
checkRange("scrypt N", N, 2, exports.MAX_SCRYPT_N);
|
|
26
27
|
if ((N & (N - 1)) !== 0) {
|
|
27
|
-
throw new
|
|
28
|
+
throw new errors_1.CryptoError(`scrypt N must be a power of two, got ${N}`, errors_1.CryptoErrorCode.INVALID_INPUT);
|
|
28
29
|
}
|
|
29
30
|
checkRange("scrypt r", r, 1, exports.MAX_SCRYPT_R);
|
|
30
31
|
checkRange("scrypt p", p, 1, exports.MAX_SCRYPT_P);
|
package/dist/modern/curves.d.ts
CHANGED
|
@@ -67,20 +67,25 @@ export interface SchnorrVerifyResult {
|
|
|
67
67
|
valid: boolean;
|
|
68
68
|
algorithm: "schnorr";
|
|
69
69
|
}
|
|
70
|
-
export declare function
|
|
70
|
+
export declare function p256Keygen(): P256KeyPair;
|
|
71
|
+
export declare const generateP256KeyPair: typeof p256Keygen;
|
|
71
72
|
export declare function p256Sign(privateKeyHex: string, message: string | Uint8Array): P256SignResult;
|
|
72
73
|
export declare function p256Verify(publicKeyHex: string, message: string | Uint8Array, signatureHex: string): P256VerifyResult;
|
|
73
|
-
export declare function
|
|
74
|
+
export declare function p384Keygen(): P384KeyPair;
|
|
75
|
+
export declare const generateP384KeyPair: typeof p384Keygen;
|
|
74
76
|
export declare function p384Sign(privateKeyHex: string, message: string | Uint8Array): P384SignResult;
|
|
75
77
|
export declare function p384Verify(publicKeyHex: string, message: string | Uint8Array, signatureHex: string): P384VerifyResult;
|
|
76
|
-
export declare function
|
|
78
|
+
export declare function ed448Keygen(): Ed448KeyPair;
|
|
79
|
+
export declare const generateEd448KeyPair: typeof ed448Keygen;
|
|
77
80
|
export declare function ed448Sign(privateKeyHex: string, message: string | Uint8Array): Ed448SignResult;
|
|
78
81
|
export declare function ed448Verify(publicKeyHex: string, message: string | Uint8Array, signatureHex: string): Ed448VerifyResult;
|
|
79
|
-
export declare function
|
|
82
|
+
export declare function x448Keygen(): X448KeyPair;
|
|
83
|
+
export declare const generateX448KeyPair: typeof x448Keygen;
|
|
80
84
|
export declare function x448Exchange(privateKeyHex: string, theirPublicKeyHex: string): X448ExchangeResult;
|
|
81
85
|
export declare function ecdhP256(privateKeyHex: string, theirPublicKeyHex: string): EcdhP256Result;
|
|
82
86
|
export declare function ecdhP384(privateKeyHex: string, theirPublicKeyHex: string): EcdhP384Result;
|
|
83
|
-
export declare function
|
|
87
|
+
export declare function schnorrKeygen(): SchnorrKeyPair;
|
|
88
|
+
export declare const generateSchnorrKeyPair: typeof schnorrKeygen;
|
|
84
89
|
export declare function schnorrSign(privateKeyHex: string, message: string | Uint8Array): SchnorrSignResult;
|
|
85
90
|
export declare function schnorrVerify(publicKeyHex: string, message: string | Uint8Array, signatureHex: string): SchnorrVerifyResult;
|
|
86
91
|
//# sourceMappingURL=curves.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"curves.d.ts","sourceRoot":"","sources":["../../src/modern/curves.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"curves.d.ts","sourceRoot":"","sources":["../../src/modern/curves.ts"],"names":[],"mappings":"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"}
|
package/dist/modern/curves.js
CHANGED
|
@@ -1,52 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateP256KeyPair =
|
|
3
|
+
exports.generateSchnorrKeyPair = exports.generateX448KeyPair = exports.generateEd448KeyPair = exports.generateP384KeyPair = exports.generateP256KeyPair = void 0;
|
|
4
|
+
exports.p256Keygen = p256Keygen;
|
|
4
5
|
exports.p256Sign = p256Sign;
|
|
5
6
|
exports.p256Verify = p256Verify;
|
|
6
|
-
exports.
|
|
7
|
+
exports.p384Keygen = p384Keygen;
|
|
7
8
|
exports.p384Sign = p384Sign;
|
|
8
9
|
exports.p384Verify = p384Verify;
|
|
9
|
-
exports.
|
|
10
|
+
exports.ed448Keygen = ed448Keygen;
|
|
10
11
|
exports.ed448Sign = ed448Sign;
|
|
11
12
|
exports.ed448Verify = ed448Verify;
|
|
12
|
-
exports.
|
|
13
|
+
exports.x448Keygen = x448Keygen;
|
|
13
14
|
exports.x448Exchange = x448Exchange;
|
|
14
15
|
exports.ecdhP256 = ecdhP256;
|
|
15
16
|
exports.ecdhP384 = ecdhP384;
|
|
16
|
-
exports.
|
|
17
|
+
exports.schnorrKeygen = schnorrKeygen;
|
|
17
18
|
exports.schnorrSign = schnorrSign;
|
|
18
19
|
exports.schnorrVerify = schnorrVerify;
|
|
19
20
|
const nist_js_1 = require("@noble/curves/nist.js");
|
|
20
21
|
const ed448_js_1 = require("@noble/curves/ed448.js");
|
|
21
22
|
const secp256k1_js_1 = require("@noble/curves/secp256k1.js");
|
|
22
23
|
const utils_js_1 = require("@noble/ciphers/utils.js");
|
|
23
|
-
const
|
|
24
|
+
const errors_1 = require("../errors");
|
|
25
|
+
const encoding_1 = require("../encoding");
|
|
24
26
|
function assertHex(input, label) {
|
|
25
|
-
if (!
|
|
26
|
-
throw new
|
|
27
|
+
if (!(0, encoding_1.isHex)(input)) {
|
|
28
|
+
throw new errors_1.CryptoError(`Invalid hex string for ${label}`, errors_1.CryptoErrorCode.INVALID_HEX);
|
|
27
29
|
}
|
|
28
|
-
return
|
|
30
|
+
return (0, encoding_1.decodeHex)(input);
|
|
29
31
|
}
|
|
30
32
|
function toBytes(input) {
|
|
31
33
|
if (input instanceof Uint8Array)
|
|
32
34
|
return input;
|
|
33
|
-
return
|
|
35
|
+
return (0, encoding_1.utf8)(input);
|
|
34
36
|
}
|
|
35
|
-
function
|
|
37
|
+
function p256Keygen() {
|
|
36
38
|
const privateKey = nist_js_1.p256.utils.randomSecretKey();
|
|
37
39
|
const publicKey = nist_js_1.p256.getPublicKey(privateKey, false);
|
|
38
40
|
return {
|
|
39
|
-
privateKey:
|
|
40
|
-
publicKey:
|
|
41
|
+
privateKey: (0, encoding_1.toHex)(privateKey),
|
|
42
|
+
publicKey: (0, encoding_1.toHex)(publicKey),
|
|
41
43
|
algorithm: "ecdsa-p256",
|
|
42
44
|
};
|
|
43
45
|
}
|
|
46
|
+
exports.generateP256KeyPair = p256Keygen;
|
|
44
47
|
function p256Sign(privateKeyHex, message) {
|
|
45
48
|
const key = assertHex(privateKeyHex, "privateKey");
|
|
46
49
|
const msg = toBytes(message);
|
|
47
50
|
const signature = nist_js_1.p256.sign(msg, key);
|
|
48
51
|
return {
|
|
49
|
-
signature:
|
|
52
|
+
signature: (0, encoding_1.toHex)(signature),
|
|
50
53
|
algorithm: "ecdsa-p256",
|
|
51
54
|
};
|
|
52
55
|
}
|
|
@@ -54,24 +57,25 @@ function p256Verify(publicKeyHex, message, signatureHex) {
|
|
|
54
57
|
const key = assertHex(publicKeyHex, "publicKey");
|
|
55
58
|
const msg = toBytes(message);
|
|
56
59
|
const sig = assertHex(signatureHex, "signature");
|
|
57
|
-
const valid = nist_js_1.p256.verify(sig, msg, key);
|
|
60
|
+
const valid = nist_js_1.p256.verify(sig, msg, key, { lowS: false });
|
|
58
61
|
return { valid, algorithm: "ecdsa-p256" };
|
|
59
62
|
}
|
|
60
|
-
function
|
|
63
|
+
function p384Keygen() {
|
|
61
64
|
const privateKey = nist_js_1.p384.utils.randomSecretKey();
|
|
62
65
|
const publicKey = nist_js_1.p384.getPublicKey(privateKey, false);
|
|
63
66
|
return {
|
|
64
|
-
privateKey:
|
|
65
|
-
publicKey:
|
|
67
|
+
privateKey: (0, encoding_1.toHex)(privateKey),
|
|
68
|
+
publicKey: (0, encoding_1.toHex)(publicKey),
|
|
66
69
|
algorithm: "ecdsa-p384",
|
|
67
70
|
};
|
|
68
71
|
}
|
|
72
|
+
exports.generateP384KeyPair = p384Keygen;
|
|
69
73
|
function p384Sign(privateKeyHex, message) {
|
|
70
74
|
const key = assertHex(privateKeyHex, "privateKey");
|
|
71
75
|
const msg = toBytes(message);
|
|
72
76
|
const signature = nist_js_1.p384.sign(msg, key);
|
|
73
77
|
return {
|
|
74
|
-
signature:
|
|
78
|
+
signature: (0, encoding_1.toHex)(signature),
|
|
75
79
|
algorithm: "ecdsa-p384",
|
|
76
80
|
};
|
|
77
81
|
}
|
|
@@ -79,24 +83,25 @@ function p384Verify(publicKeyHex, message, signatureHex) {
|
|
|
79
83
|
const key = assertHex(publicKeyHex, "publicKey");
|
|
80
84
|
const msg = toBytes(message);
|
|
81
85
|
const sig = assertHex(signatureHex, "signature");
|
|
82
|
-
const valid = nist_js_1.p384.verify(sig, msg, key);
|
|
86
|
+
const valid = nist_js_1.p384.verify(sig, msg, key, { lowS: false });
|
|
83
87
|
return { valid, algorithm: "ecdsa-p384" };
|
|
84
88
|
}
|
|
85
|
-
function
|
|
89
|
+
function ed448Keygen() {
|
|
86
90
|
const privateKey = (0, utils_js_1.randomBytes)(57);
|
|
87
91
|
const publicKey = ed448_js_1.ed448.getPublicKey(privateKey);
|
|
88
92
|
return {
|
|
89
|
-
privateKey:
|
|
90
|
-
publicKey:
|
|
93
|
+
privateKey: (0, encoding_1.toHex)(privateKey),
|
|
94
|
+
publicKey: (0, encoding_1.toHex)(publicKey),
|
|
91
95
|
algorithm: "ed448",
|
|
92
96
|
};
|
|
93
97
|
}
|
|
98
|
+
exports.generateEd448KeyPair = ed448Keygen;
|
|
94
99
|
function ed448Sign(privateKeyHex, message) {
|
|
95
100
|
const key = assertHex(privateKeyHex, "privateKey");
|
|
96
101
|
const msg = toBytes(message);
|
|
97
102
|
const signature = ed448_js_1.ed448.sign(msg, key);
|
|
98
103
|
return {
|
|
99
|
-
signature:
|
|
104
|
+
signature: (0, encoding_1.toHex)(signature),
|
|
100
105
|
algorithm: "ed448",
|
|
101
106
|
};
|
|
102
107
|
}
|
|
@@ -107,57 +112,59 @@ function ed448Verify(publicKeyHex, message, signatureHex) {
|
|
|
107
112
|
const valid = ed448_js_1.ed448.verify(sig, msg, key);
|
|
108
113
|
return { valid, algorithm: "ed448" };
|
|
109
114
|
}
|
|
110
|
-
function
|
|
115
|
+
function x448Keygen() {
|
|
111
116
|
const privateKey = ed448_js_1.x448.utils.randomSecretKey();
|
|
112
117
|
const publicKey = ed448_js_1.x448.getPublicKey(privateKey);
|
|
113
118
|
return {
|
|
114
|
-
privateKey:
|
|
115
|
-
publicKey:
|
|
119
|
+
privateKey: (0, encoding_1.toHex)(privateKey),
|
|
120
|
+
publicKey: (0, encoding_1.toHex)(publicKey),
|
|
116
121
|
algorithm: "x448",
|
|
117
122
|
};
|
|
118
123
|
}
|
|
124
|
+
exports.generateX448KeyPair = x448Keygen;
|
|
119
125
|
function x448Exchange(privateKeyHex, theirPublicKeyHex) {
|
|
120
126
|
const priv = assertHex(privateKeyHex, "privateKey");
|
|
121
127
|
const pub = assertHex(theirPublicKeyHex, "theirPublicKey");
|
|
122
128
|
const shared = ed448_js_1.x448.getSharedSecret(priv, pub);
|
|
123
129
|
return {
|
|
124
|
-
sharedSecret:
|
|
130
|
+
sharedSecret: (0, encoding_1.toHex)(shared),
|
|
125
131
|
algorithm: "x448",
|
|
126
132
|
};
|
|
127
133
|
}
|
|
128
134
|
function ecdhP256(privateKeyHex, theirPublicKeyHex) {
|
|
129
135
|
const priv = assertHex(privateKeyHex, "privateKey");
|
|
130
136
|
const pub = assertHex(theirPublicKeyHex, "theirPublicKey");
|
|
131
|
-
const shared = nist_js_1.p256.getSharedSecret(priv, pub);
|
|
137
|
+
const shared = nist_js_1.p256.getSharedSecret(priv, pub).subarray(1);
|
|
132
138
|
return {
|
|
133
|
-
sharedSecret:
|
|
139
|
+
sharedSecret: (0, encoding_1.toHex)(shared),
|
|
134
140
|
algorithm: "ecdh-p256",
|
|
135
141
|
};
|
|
136
142
|
}
|
|
137
143
|
function ecdhP384(privateKeyHex, theirPublicKeyHex) {
|
|
138
144
|
const priv = assertHex(privateKeyHex, "privateKey");
|
|
139
145
|
const pub = assertHex(theirPublicKeyHex, "theirPublicKey");
|
|
140
|
-
const shared = nist_js_1.p384.getSharedSecret(priv, pub);
|
|
146
|
+
const shared = nist_js_1.p384.getSharedSecret(priv, pub).subarray(1);
|
|
141
147
|
return {
|
|
142
|
-
sharedSecret:
|
|
148
|
+
sharedSecret: (0, encoding_1.toHex)(shared),
|
|
143
149
|
algorithm: "ecdh-p384",
|
|
144
150
|
};
|
|
145
151
|
}
|
|
146
|
-
function
|
|
152
|
+
function schnorrKeygen() {
|
|
147
153
|
const privateKey = (0, utils_js_1.randomBytes)(32);
|
|
148
154
|
const publicKey = secp256k1_js_1.schnorr.getPublicKey(privateKey);
|
|
149
155
|
return {
|
|
150
|
-
privateKey:
|
|
151
|
-
publicKey:
|
|
156
|
+
privateKey: (0, encoding_1.toHex)(privateKey),
|
|
157
|
+
publicKey: (0, encoding_1.toHex)(publicKey),
|
|
152
158
|
algorithm: "schnorr",
|
|
153
159
|
};
|
|
154
160
|
}
|
|
161
|
+
exports.generateSchnorrKeyPair = schnorrKeygen;
|
|
155
162
|
function schnorrSign(privateKeyHex, message) {
|
|
156
163
|
const key = assertHex(privateKeyHex, "privateKey");
|
|
157
164
|
const msg = toBytes(message);
|
|
158
165
|
const signature = secp256k1_js_1.schnorr.sign(msg, key);
|
|
159
166
|
return {
|
|
160
|
-
signature:
|
|
167
|
+
signature: (0, encoding_1.toHex)(signature),
|
|
161
168
|
algorithm: "schnorr",
|
|
162
169
|
};
|
|
163
170
|
}
|
package/dist/modern/ecdh.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export interface KeyExchangeResult {
|
|
|
6
6
|
sharedSecret: string;
|
|
7
7
|
algorithm: "x25519";
|
|
8
8
|
}
|
|
9
|
-
export declare function
|
|
9
|
+
export declare function x25519Keygen(): X25519KeyPair;
|
|
10
|
+
export declare const generateX25519KeyPair: typeof x25519Keygen;
|
|
10
11
|
export declare function x25519Exchange(privateKey: string | Uint8Array, theirPublicKey: string | Uint8Array): KeyExchangeResult;
|
|
11
12
|
//# sourceMappingURL=ecdh.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecdh.d.ts","sourceRoot":"","sources":["../../src/modern/ecdh.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ecdh.d.ts","sourceRoot":"","sources":["../../src/modern/ecdh.ts"],"names":[],"mappings":"AAkBA,MAAM,WAAW,aAAa;IAE5B,UAAU,EAAE,MAAM,CAAC;IAEnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAGD,MAAM,WAAW,iBAAiB;IAEhC,YAAY,EAAE,MAAM,CAAC;IAErB,SAAS,EAAE,QAAQ,CAAC;CACrB;AAKD,wBAAgB,YAAY,IAAI,aAAa,CAQ5C;AAGD,eAAO,MAAM,qBAAqB,qBAAe,CAAC;AASlD,wBAAgB,cAAc,CAC5B,UAAU,EAAE,MAAM,GAAG,UAAU,EAC/B,cAAc,EAAE,MAAM,GAAG,UAAU,GAClC,iBAAiB,CAcnB"}
|
package/dist/modern/ecdh.js
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateX25519KeyPair =
|
|
3
|
+
exports.generateX25519KeyPair = void 0;
|
|
4
|
+
exports.x25519Keygen = x25519Keygen;
|
|
4
5
|
exports.x25519Exchange = x25519Exchange;
|
|
5
6
|
const ed25519_js_1 = require("@noble/curves/ed25519.js");
|
|
6
7
|
const utils_js_1 = require("@noble/ciphers/utils.js");
|
|
7
|
-
|
|
8
|
+
const encoding_1 = require("../encoding");
|
|
9
|
+
function x25519Keygen() {
|
|
8
10
|
const privateKey = (0, utils_js_1.randomBytes)(32);
|
|
9
11
|
const publicKey = ed25519_js_1.x25519.getPublicKey(privateKey);
|
|
10
12
|
return {
|
|
11
|
-
privateKey:
|
|
12
|
-
publicKey:
|
|
13
|
+
privateKey: (0, encoding_1.toHex)(privateKey),
|
|
14
|
+
publicKey: (0, encoding_1.toHex)(publicKey),
|
|
13
15
|
};
|
|
14
16
|
}
|
|
17
|
+
exports.generateX25519KeyPair = x25519Keygen;
|
|
15
18
|
function x25519Exchange(privateKey, theirPublicKey) {
|
|
16
|
-
const priv = typeof privateKey === "string"
|
|
17
|
-
? Buffer.from(privateKey, "hex")
|
|
18
|
-
: privateKey;
|
|
19
|
+
const priv = typeof privateKey === "string" ? (0, encoding_1.decodeHex)(privateKey) : privateKey;
|
|
19
20
|
const pub = typeof theirPublicKey === "string"
|
|
20
|
-
?
|
|
21
|
+
? (0, encoding_1.decodeHex)(theirPublicKey)
|
|
21
22
|
: theirPublicKey;
|
|
22
23
|
const shared = ed25519_js_1.x25519.getSharedSecret(priv, pub);
|
|
23
24
|
return {
|
|
24
|
-
sharedSecret:
|
|
25
|
+
sharedSecret: (0, encoding_1.toHex)(shared),
|
|
25
26
|
algorithm: "x25519",
|
|
26
27
|
};
|
|
27
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fn-dsa.d.ts","sourceRoot":"","sources":["../../src/modern/fn-dsa.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fn-dsa.d.ts","sourceRoot":"","sources":["../../src/modern/fn-dsa.ts"],"names":[],"mappings":"AA2BA,MAAM,MAAM,UAAU,GAAG,GAAG,GAAG,IAAI,CAAC;AAUpC,MAAM,MAAM,cAAc,GAAG,YAAY,GAAG,aAAa,CAAC;AAW1D,MAAM,WAAW,kBAAkB;IAEjC,SAAS,EAAE,MAAM,CAAC;IAElB,SAAS,EAAE,MAAM,CAAC;IAElB,SAAS,EAAE,cAAc,CAAC;CAC3B;AAWD,MAAM,WAAW,eAAe;IAE9B,SAAS,EAAE,MAAM,CAAC;IAElB,SAAS,EAAE,cAAc,CAAC;CAC3B;AAWD,MAAM,WAAW,iBAAiB;IAEhC,KAAK,EAAE,OAAO,CAAC;IAEf,SAAS,EAAE,cAAc,CAAC;CAC3B;AAmDD,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,kBAAkB,CAQjE;AAkBD,wBAAgB,SAAS,CACvB,KAAK,EAAE,UAAU,EACjB,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,GACjB,eAAe,CASjB;AAoBD,wBAAgB,WAAW,CACzB,KAAK,EAAE,UAAU,EACjB,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,GACnB,iBAAiB,CAUnB"}
|