@sebastienrousseau/crypto-lib 0.0.2 → 0.0.7
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 +334 -185
- 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 +25 -0
- package/dist/bin/cryptolib.d.ts.map +1 -0
- package/dist/bin/cryptolib.js +87 -0
- package/dist/config/config.d.ts +8 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +13 -0
- 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 +81 -0
- package/dist/enums.d.ts.map +1 -0
- package/dist/enums.js +82 -0
- 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 +16 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +61 -2
- package/dist/key/key.d.ts +10 -0
- package/dist/key/key.d.ts.map +1 -0
- package/dist/key/key.js +25 -0
- 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 +5 -5
- package/dist/lib/decrypt.d.ts.map +1 -1
- package/dist/lib/decrypt.js +49 -39
- package/dist/lib/encrypt.d.ts +2 -5
- package/dist/lib/encrypt.d.ts.map +1 -1
- package/dist/lib/encrypt.js +34 -39
- package/dist/lib/generate.d.ts +2 -11
- package/dist/lib/generate.d.ts.map +1 -1
- package/dist/lib/generate.js +57 -29
- package/dist/lib/index.d.ts +10 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +53 -0
- 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 +9 -0
- package/dist/lib/reformat.d.ts.map +1 -0
- package/dist/lib/reformat.js +67 -0
- package/dist/lib/revoke.d.ts +3 -3
- package/dist/lib/revoke.d.ts.map +1 -1
- package/dist/lib/revoke.js +36 -28
- package/dist/lib/session.d.ts +5 -0
- package/dist/lib/session.d.ts.map +1 -0
- package/dist/lib/session.js +55 -0
- package/dist/lib/sign.d.ts +4 -0
- package/dist/lib/sign.d.ts.map +1 -0
- package/dist/lib/sign.js +63 -0
- package/dist/lib/verify.d.ts +5 -0
- package/dist/lib/verify.d.ts.map +1 -0
- package/dist/lib/verify.js +52 -0
- 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 +57 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js +1 -0
- 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 -130
- package/dist/COPYRIGHT +0 -15
- package/dist/Report.txt +0 -72
- package/dist/bin/crypto-lib.d.ts +0 -13
- package/dist/bin/crypto-lib.d.ts.map +0 -1
- package/dist/bin/crypto-lib.js +0 -52
- package/dist/bin/crypto-lib.js.map +0 -1
- package/dist/index.js.map +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/revoke.js.map +0 -1
- package/dist/package.json +0 -131
- package/dist/types/types.js.map +0 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type AlgorithmCategory = "encryption" | "hash" | "kdf" | "mac" | "signing" | "key-exchange" | "kem";
|
|
2
|
+
export type SecurityLevel = 1 | 2 | 3 | 5;
|
|
3
|
+
export type AlgorithmStatus = "recommended" | "acceptable" | "deprecated" | "experimental";
|
|
4
|
+
export interface AlgorithmInfo {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
category: AlgorithmCategory;
|
|
8
|
+
securityLevel: SecurityLevel;
|
|
9
|
+
status: AlgorithmStatus;
|
|
10
|
+
standard?: string | undefined;
|
|
11
|
+
aliases?: string[] | undefined;
|
|
12
|
+
}
|
|
13
|
+
export declare function getAlgorithm(idOrAlias: string): AlgorithmInfo | undefined;
|
|
14
|
+
export declare function listAlgorithms(filters?: {
|
|
15
|
+
category?: AlgorithmCategory | undefined;
|
|
16
|
+
status?: AlgorithmStatus | undefined;
|
|
17
|
+
}): AlgorithmInfo[];
|
|
18
|
+
export declare function recommended(category?: AlgorithmCategory): AlgorithmInfo[];
|
|
19
|
+
export declare function isDeprecated(idOrAlias: string): boolean;
|
|
20
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,iBAAiB,GAC3B,YAAY,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,SAAS,GAAG,cAAc,GAAG,KAAK,CAAC;AAG7E,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAG1C,MAAM,MAAM,eAAe,GACzB,aAAa,GAAG,YAAY,GAAG,YAAY,GAAG,cAAc,CAAC;AAG/D,MAAM,WAAW,aAAa;IAE5B,EAAE,EAAE,MAAM,CAAC;IAEX,IAAI,EAAE,MAAM,CAAC;IAEb,QAAQ,EAAE,iBAAiB,CAAC;IAE5B,aAAa,EAAE,aAAa,CAAC;IAE7B,MAAM,EAAE,eAAe,CAAC;IAExB,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE9B,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;CAChC;AAqYD,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAGzE;AAKD,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE;IACvC,QAAQ,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;IACzC,MAAM,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC;CACtC,GAAG,aAAa,EAAE,CASlB;AAKD,wBAAgB,WAAW,CAAC,QAAQ,CAAC,EAAE,iBAAiB,GAAG,aAAa,EAAE,CAQzE;AAKD,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAGvD"}
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAlgorithm = getAlgorithm;
|
|
4
|
+
exports.listAlgorithms = listAlgorithms;
|
|
5
|
+
exports.recommended = recommended;
|
|
6
|
+
exports.isDeprecated = isDeprecated;
|
|
7
|
+
const REGISTRY = [
|
|
8
|
+
{
|
|
9
|
+
id: "xchacha20-poly1305",
|
|
10
|
+
name: "XChaCha20-Poly1305",
|
|
11
|
+
category: "encryption",
|
|
12
|
+
securityLevel: 1,
|
|
13
|
+
status: "recommended",
|
|
14
|
+
standard: "draft-irtf-cfrg-xchacha",
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: "aes-256-gcm",
|
|
18
|
+
name: "AES-256-GCM",
|
|
19
|
+
category: "encryption",
|
|
20
|
+
securityLevel: 1,
|
|
21
|
+
status: "recommended",
|
|
22
|
+
standard: "NIST SP 800-38D",
|
|
23
|
+
aliases: ["aes256gcm"],
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: "aes-128-gcm",
|
|
27
|
+
name: "AES-128-GCM",
|
|
28
|
+
category: "encryption",
|
|
29
|
+
securityLevel: 1,
|
|
30
|
+
status: "acceptable",
|
|
31
|
+
standard: "NIST SP 800-38D",
|
|
32
|
+
aliases: ["aes128gcm"],
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: "aes-256-gcm-siv",
|
|
36
|
+
name: "AES-256-GCM-SIV",
|
|
37
|
+
category: "encryption",
|
|
38
|
+
securityLevel: 1,
|
|
39
|
+
status: "recommended",
|
|
40
|
+
standard: "RFC 8452",
|
|
41
|
+
aliases: ["aes256gcmsiv"],
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: "aes-128-gcm-siv",
|
|
45
|
+
name: "AES-128-GCM-SIV",
|
|
46
|
+
category: "encryption",
|
|
47
|
+
securityLevel: 1,
|
|
48
|
+
status: "acceptable",
|
|
49
|
+
standard: "RFC 8452",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: "sha256",
|
|
53
|
+
name: "SHA-256",
|
|
54
|
+
category: "hash",
|
|
55
|
+
securityLevel: 1,
|
|
56
|
+
status: "recommended",
|
|
57
|
+
standard: "FIPS 180-4",
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: "sha384",
|
|
61
|
+
name: "SHA-384",
|
|
62
|
+
category: "hash",
|
|
63
|
+
securityLevel: 1,
|
|
64
|
+
status: "recommended",
|
|
65
|
+
standard: "FIPS 180-4",
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
id: "sha512",
|
|
69
|
+
name: "SHA-512",
|
|
70
|
+
category: "hash",
|
|
71
|
+
securityLevel: 1,
|
|
72
|
+
status: "recommended",
|
|
73
|
+
standard: "FIPS 180-4",
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: "sha3-256",
|
|
77
|
+
name: "SHA3-256",
|
|
78
|
+
category: "hash",
|
|
79
|
+
securityLevel: 1,
|
|
80
|
+
status: "recommended",
|
|
81
|
+
standard: "FIPS 202",
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
id: "sha3-512",
|
|
85
|
+
name: "SHA3-512",
|
|
86
|
+
category: "hash",
|
|
87
|
+
securityLevel: 1,
|
|
88
|
+
status: "recommended",
|
|
89
|
+
standard: "FIPS 202",
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
id: "blake2b",
|
|
93
|
+
name: "BLAKE2b",
|
|
94
|
+
category: "hash",
|
|
95
|
+
securityLevel: 1,
|
|
96
|
+
status: "acceptable",
|
|
97
|
+
standard: "RFC 7693",
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
id: "blake3",
|
|
101
|
+
name: "BLAKE3",
|
|
102
|
+
category: "hash",
|
|
103
|
+
securityLevel: 1,
|
|
104
|
+
status: "acceptable",
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
id: "argon2id",
|
|
108
|
+
name: "Argon2id",
|
|
109
|
+
category: "kdf",
|
|
110
|
+
securityLevel: 1,
|
|
111
|
+
status: "recommended",
|
|
112
|
+
standard: "RFC 9106",
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
id: "hkdf-sha256",
|
|
116
|
+
name: "HKDF-SHA256",
|
|
117
|
+
category: "kdf",
|
|
118
|
+
securityLevel: 1,
|
|
119
|
+
status: "recommended",
|
|
120
|
+
standard: "RFC 5869",
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
id: "scrypt",
|
|
124
|
+
name: "scrypt",
|
|
125
|
+
category: "kdf",
|
|
126
|
+
securityLevel: 1,
|
|
127
|
+
status: "acceptable",
|
|
128
|
+
standard: "RFC 7914",
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
id: "pbkdf2-sha256",
|
|
132
|
+
name: "PBKDF2-SHA256",
|
|
133
|
+
category: "kdf",
|
|
134
|
+
securityLevel: 1,
|
|
135
|
+
status: "deprecated",
|
|
136
|
+
standard: "RFC 8018",
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
id: "hmac-sha256",
|
|
140
|
+
name: "HMAC-SHA256",
|
|
141
|
+
category: "mac",
|
|
142
|
+
securityLevel: 1,
|
|
143
|
+
status: "recommended",
|
|
144
|
+
standard: "RFC 2104",
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
id: "hmac-sha384",
|
|
148
|
+
name: "HMAC-SHA384",
|
|
149
|
+
category: "mac",
|
|
150
|
+
securityLevel: 1,
|
|
151
|
+
status: "recommended",
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
id: "hmac-sha512",
|
|
155
|
+
name: "HMAC-SHA512",
|
|
156
|
+
category: "mac",
|
|
157
|
+
securityLevel: 1,
|
|
158
|
+
status: "recommended",
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
id: "hmac-sha3-256",
|
|
162
|
+
name: "HMAC-SHA3-256",
|
|
163
|
+
category: "mac",
|
|
164
|
+
securityLevel: 1,
|
|
165
|
+
status: "recommended",
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
id: "hmac-sha3-512",
|
|
169
|
+
name: "HMAC-SHA3-512",
|
|
170
|
+
category: "mac",
|
|
171
|
+
securityLevel: 1,
|
|
172
|
+
status: "recommended",
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
id: "kmac-128",
|
|
176
|
+
name: "KMAC-128",
|
|
177
|
+
category: "mac",
|
|
178
|
+
securityLevel: 1,
|
|
179
|
+
status: "recommended",
|
|
180
|
+
standard: "NIST SP 800-185",
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
id: "kmac-256",
|
|
184
|
+
name: "KMAC-256",
|
|
185
|
+
category: "mac",
|
|
186
|
+
securityLevel: 1,
|
|
187
|
+
status: "recommended",
|
|
188
|
+
standard: "NIST SP 800-185",
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
id: "ed25519",
|
|
192
|
+
name: "Ed25519",
|
|
193
|
+
category: "signing",
|
|
194
|
+
securityLevel: 1,
|
|
195
|
+
status: "recommended",
|
|
196
|
+
standard: "RFC 8032",
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
id: "ed448",
|
|
200
|
+
name: "Ed448",
|
|
201
|
+
category: "signing",
|
|
202
|
+
securityLevel: 2,
|
|
203
|
+
status: "recommended",
|
|
204
|
+
standard: "RFC 8032",
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
id: "ecdsa-p256",
|
|
208
|
+
name: "ECDSA P-256",
|
|
209
|
+
category: "signing",
|
|
210
|
+
securityLevel: 1,
|
|
211
|
+
status: "acceptable",
|
|
212
|
+
standard: "FIPS 186-5",
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
id: "ecdsa-p384",
|
|
216
|
+
name: "ECDSA P-384",
|
|
217
|
+
category: "signing",
|
|
218
|
+
securityLevel: 2,
|
|
219
|
+
status: "acceptable",
|
|
220
|
+
standard: "FIPS 186-5",
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
id: "ml-dsa-44",
|
|
224
|
+
name: "ML-DSA-44",
|
|
225
|
+
category: "signing",
|
|
226
|
+
securityLevel: 2,
|
|
227
|
+
status: "recommended",
|
|
228
|
+
standard: "FIPS 204",
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
id: "ml-dsa-65",
|
|
232
|
+
name: "ML-DSA-65",
|
|
233
|
+
category: "signing",
|
|
234
|
+
securityLevel: 3,
|
|
235
|
+
status: "recommended",
|
|
236
|
+
standard: "FIPS 204",
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
id: "ml-dsa-87",
|
|
240
|
+
name: "ML-DSA-87",
|
|
241
|
+
category: "signing",
|
|
242
|
+
securityLevel: 5,
|
|
243
|
+
status: "recommended",
|
|
244
|
+
standard: "FIPS 204",
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
id: "slh-dsa-shake-256s",
|
|
248
|
+
name: "SLH-DSA-SHAKE-256s",
|
|
249
|
+
category: "signing",
|
|
250
|
+
securityLevel: 5,
|
|
251
|
+
status: "recommended",
|
|
252
|
+
standard: "FIPS 205",
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
id: "slh-dsa-shake-128f",
|
|
256
|
+
name: "SLH-DSA-SHAKE-128f",
|
|
257
|
+
category: "signing",
|
|
258
|
+
securityLevel: 1,
|
|
259
|
+
status: "acceptable",
|
|
260
|
+
standard: "FIPS 205",
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
id: "schnorr",
|
|
264
|
+
name: "Schnorr (BIP-340)",
|
|
265
|
+
category: "signing",
|
|
266
|
+
securityLevel: 1,
|
|
267
|
+
status: "acceptable",
|
|
268
|
+
standard: "BIP-340",
|
|
269
|
+
aliases: ["bip340", "schnorr-secp256k1"],
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
id: "x25519",
|
|
273
|
+
name: "X25519",
|
|
274
|
+
category: "key-exchange",
|
|
275
|
+
securityLevel: 1,
|
|
276
|
+
status: "recommended",
|
|
277
|
+
standard: "RFC 7748",
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
id: "x448",
|
|
281
|
+
name: "X448",
|
|
282
|
+
category: "key-exchange",
|
|
283
|
+
securityLevel: 2,
|
|
284
|
+
status: "recommended",
|
|
285
|
+
standard: "RFC 7748",
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
id: "ecdh-p256",
|
|
289
|
+
name: "ECDH P-256",
|
|
290
|
+
category: "key-exchange",
|
|
291
|
+
securityLevel: 1,
|
|
292
|
+
status: "acceptable",
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
id: "ecdh-p384",
|
|
296
|
+
name: "ECDH P-384",
|
|
297
|
+
category: "key-exchange",
|
|
298
|
+
securityLevel: 2,
|
|
299
|
+
status: "acceptable",
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
id: "ml-kem-512",
|
|
303
|
+
name: "ML-KEM-512",
|
|
304
|
+
category: "kem",
|
|
305
|
+
securityLevel: 1,
|
|
306
|
+
status: "acceptable",
|
|
307
|
+
standard: "FIPS 203",
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
id: "ml-kem-768",
|
|
311
|
+
name: "ML-KEM-768",
|
|
312
|
+
category: "kem",
|
|
313
|
+
securityLevel: 3,
|
|
314
|
+
status: "recommended",
|
|
315
|
+
standard: "FIPS 203",
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
id: "ml-kem-1024",
|
|
319
|
+
name: "ML-KEM-1024",
|
|
320
|
+
category: "kem",
|
|
321
|
+
securityLevel: 5,
|
|
322
|
+
status: "recommended",
|
|
323
|
+
standard: "FIPS 203",
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
id: "x25519-ml-kem-768",
|
|
327
|
+
name: "X25519+ML-KEM-768 Hybrid",
|
|
328
|
+
category: "kem",
|
|
329
|
+
securityLevel: 3,
|
|
330
|
+
status: "recommended",
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
id: "x25519-ml-kem-512",
|
|
334
|
+
name: "X25519+ML-KEM-512 Hybrid",
|
|
335
|
+
category: "kem",
|
|
336
|
+
securityLevel: 1,
|
|
337
|
+
status: "acceptable",
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
id: "x25519-ml-kem-1024",
|
|
341
|
+
name: "X25519+ML-KEM-1024 Hybrid",
|
|
342
|
+
category: "kem",
|
|
343
|
+
securityLevel: 5,
|
|
344
|
+
status: "recommended",
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
id: "p256-ml-kem-768",
|
|
348
|
+
name: "P-256+ML-KEM-768 Hybrid",
|
|
349
|
+
category: "kem",
|
|
350
|
+
securityLevel: 3,
|
|
351
|
+
status: "recommended",
|
|
352
|
+
standard: "IETF draft-ietf-tls-ecdhe-mlkem",
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
id: "x448-ml-kem-1024",
|
|
356
|
+
name: "X448+ML-KEM-1024 Hybrid",
|
|
357
|
+
category: "kem",
|
|
358
|
+
securityLevel: 5,
|
|
359
|
+
status: "recommended",
|
|
360
|
+
},
|
|
361
|
+
];
|
|
362
|
+
const aliasMap = new Map();
|
|
363
|
+
const idMap = new Map();
|
|
364
|
+
for (const algo of REGISTRY) {
|
|
365
|
+
idMap.set(algo.id, algo);
|
|
366
|
+
if (algo.aliases) {
|
|
367
|
+
for (const alias of algo.aliases) {
|
|
368
|
+
aliasMap.set(alias, algo.id);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
function getAlgorithm(idOrAlias) {
|
|
373
|
+
const resolved = aliasMap.get(idOrAlias) ?? idOrAlias;
|
|
374
|
+
return idMap.get(resolved);
|
|
375
|
+
}
|
|
376
|
+
function listAlgorithms(filters) {
|
|
377
|
+
let result = REGISTRY;
|
|
378
|
+
if (filters?.category) {
|
|
379
|
+
result = result.filter((a) => a.category === filters.category);
|
|
380
|
+
}
|
|
381
|
+
if (filters?.status) {
|
|
382
|
+
result = result.filter((a) => a.status === filters.status);
|
|
383
|
+
}
|
|
384
|
+
return result;
|
|
385
|
+
}
|
|
386
|
+
function recommended(category) {
|
|
387
|
+
const filters = {
|
|
388
|
+
status: "recommended",
|
|
389
|
+
};
|
|
390
|
+
if (category) {
|
|
391
|
+
filters.category = category;
|
|
392
|
+
}
|
|
393
|
+
return listAlgorithms(filters);
|
|
394
|
+
}
|
|
395
|
+
function isDeprecated(idOrAlias) {
|
|
396
|
+
const algo = getAlgorithm(idOrAlias);
|
|
397
|
+
return algo?.status === "deprecated";
|
|
398
|
+
}
|
|
399
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createHasher, STREAM_HASH_ALGORITHMS } from "./stream-hash";
|
|
2
|
+
export type { StreamingHasher, StreamHashAlgorithm } from "./stream-hash";
|
|
3
|
+
export { streamEncrypt, streamDecrypt } from "./stream-aead";
|
|
4
|
+
export type { StreamEncryptOptions, StreamEncryptResult, StreamDecryptOptions, } from "./stream-aead";
|
|
5
|
+
export { createEncryptStream, createDecryptStream, createHashStream, WEB_STREAM_HASH_ALGORITHMS, } from "./web-streams";
|
|
6
|
+
export type { WebStreamHashAlgorithm, HashStreamResult, EncryptStreamOptions, DecryptStreamOptions, CryptoTransformStream, } from "./web-streams";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/streaming/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAErE,YAAY,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAE1E,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE7D,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,0BAA0B,GAC3B,MAAM,eAAe,CAAC;AAEvB,YAAY,EACV,sBAAsB,EACtB,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WEB_STREAM_HASH_ALGORITHMS = exports.createHashStream = exports.createDecryptStream = exports.createEncryptStream = exports.streamDecrypt = exports.streamEncrypt = exports.STREAM_HASH_ALGORITHMS = exports.createHasher = void 0;
|
|
4
|
+
var stream_hash_1 = require("./stream-hash");
|
|
5
|
+
Object.defineProperty(exports, "createHasher", { enumerable: true, get: function () { return stream_hash_1.createHasher; } });
|
|
6
|
+
Object.defineProperty(exports, "STREAM_HASH_ALGORITHMS", { enumerable: true, get: function () { return stream_hash_1.STREAM_HASH_ALGORITHMS; } });
|
|
7
|
+
var stream_aead_1 = require("./stream-aead");
|
|
8
|
+
Object.defineProperty(exports, "streamEncrypt", { enumerable: true, get: function () { return stream_aead_1.streamEncrypt; } });
|
|
9
|
+
Object.defineProperty(exports, "streamDecrypt", { enumerable: true, get: function () { return stream_aead_1.streamDecrypt; } });
|
|
10
|
+
var web_streams_1 = require("./web-streams");
|
|
11
|
+
Object.defineProperty(exports, "createEncryptStream", { enumerable: true, get: function () { return web_streams_1.createEncryptStream; } });
|
|
12
|
+
Object.defineProperty(exports, "createDecryptStream", { enumerable: true, get: function () { return web_streams_1.createDecryptStream; } });
|
|
13
|
+
Object.defineProperty(exports, "createHashStream", { enumerable: true, get: function () { return web_streams_1.createHashStream; } });
|
|
14
|
+
Object.defineProperty(exports, "WEB_STREAM_HASH_ALGORITHMS", { enumerable: true, get: function () { return web_streams_1.WEB_STREAM_HASH_ALGORITHMS; } });
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface StreamEncryptOptions {
|
|
2
|
+
key: string | Uint8Array;
|
|
3
|
+
plaintext: Uint8Array;
|
|
4
|
+
chunkSize?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface StreamEncryptResult {
|
|
7
|
+
ciphertext: Uint8Array;
|
|
8
|
+
algorithm: "xchacha20-poly1305-stream";
|
|
9
|
+
}
|
|
10
|
+
export interface StreamDecryptOptions {
|
|
11
|
+
key: string | Uint8Array;
|
|
12
|
+
ciphertext: Uint8Array;
|
|
13
|
+
chunkSize?: number;
|
|
14
|
+
}
|
|
15
|
+
export declare function streamEncrypt(options: StreamEncryptOptions): StreamEncryptResult;
|
|
16
|
+
export declare function streamDecrypt(options: StreamDecryptOptions): Uint8Array;
|
|
17
|
+
//# sourceMappingURL=stream-aead.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-aead.d.ts","sourceRoot":"","sources":["../../src/streaming/stream-aead.ts"],"names":[],"mappings":"AAkEA,MAAM,WAAW,oBAAoB;IAEnC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;IAEzB,SAAS,EAAE,UAAU,CAAC;IAEtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAGD,MAAM,WAAW,mBAAmB;IAElC,UAAU,EAAE,UAAU,CAAC;IAEvB,SAAS,EAAE,2BAA2B,CAAC;CACxC;AAGD,MAAM,WAAW,oBAAoB;IAEnC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;IAEzB,UAAU,EAAE,UAAU,CAAC;IAEvB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA2BD,wBAAgB,aAAa,CAC3B,OAAO,EAAE,oBAAoB,GAC5B,mBAAmB,CA8CrB;AAsCD,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,UAAU,CAwDvE"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.streamEncrypt = streamEncrypt;
|
|
4
|
+
exports.streamDecrypt = streamDecrypt;
|
|
5
|
+
const chacha_js_1 = require("@noble/ciphers/chacha.js");
|
|
6
|
+
const utils_js_1 = require("@noble/ciphers/utils.js");
|
|
7
|
+
const NONCE_LEN = 24;
|
|
8
|
+
const TAG_LEN = 16;
|
|
9
|
+
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
10
|
+
const CHUNK_TAG_MESSAGE = 0x00;
|
|
11
|
+
const CHUNK_TAG_FINAL = 0x01;
|
|
12
|
+
function deriveChunkNonce(baseNonce, counter, tag) {
|
|
13
|
+
const nonce = new Uint8Array(baseNonce);
|
|
14
|
+
const view = new DataView(nonce.buffer, nonce.byteOffset, nonce.byteLength);
|
|
15
|
+
const low = counter & 0xffffffff;
|
|
16
|
+
const high = (counter / 0x100000000) | 0;
|
|
17
|
+
view.setUint32(nonce.length - 8, view.getUint32(nonce.length - 8) ^ low, true);
|
|
18
|
+
view.setUint32(nonce.length - 4, view.getUint32(nonce.length - 4) ^ high, true);
|
|
19
|
+
nonce[0] = nonce[0] ^ tag;
|
|
20
|
+
return nonce;
|
|
21
|
+
}
|
|
22
|
+
const HEX_RE = /^[0-9a-fA-F]*$/;
|
|
23
|
+
function toKey(key) {
|
|
24
|
+
if (key instanceof Uint8Array) {
|
|
25
|
+
if (key.length !== 32) {
|
|
26
|
+
throw new Error(`Key must be 32 bytes, got ${key.length}`);
|
|
27
|
+
}
|
|
28
|
+
return key;
|
|
29
|
+
}
|
|
30
|
+
if (!HEX_RE.test(key))
|
|
31
|
+
throw new Error("Invalid hex key");
|
|
32
|
+
const buf = Buffer.from(key, "hex");
|
|
33
|
+
if (buf.length !== 32) {
|
|
34
|
+
throw new Error(`Key must be 32 bytes (256 bits), got ${buf.length}`);
|
|
35
|
+
}
|
|
36
|
+
return buf;
|
|
37
|
+
}
|
|
38
|
+
function streamEncrypt(options) {
|
|
39
|
+
const key = toKey(options.key);
|
|
40
|
+
const chunkSize = options.chunkSize ?? DEFAULT_CHUNK_SIZE;
|
|
41
|
+
const plaintext = options.plaintext;
|
|
42
|
+
const baseNonce = (0, utils_js_1.randomBytes)(NONCE_LEN);
|
|
43
|
+
const numFullChunks = Math.floor(plaintext.length / chunkSize);
|
|
44
|
+
const lastChunkLen = plaintext.length - numFullChunks * chunkSize;
|
|
45
|
+
const hasExtraChunk = lastChunkLen > 0 || plaintext.length === 0;
|
|
46
|
+
const totalChunks = hasExtraChunk ? numFullChunks + 1 : numFullChunks;
|
|
47
|
+
let outputSize = NONCE_LEN;
|
|
48
|
+
for (let i = 0; i < totalChunks; i++) {
|
|
49
|
+
const ptLen = i < numFullChunks ? chunkSize : lastChunkLen > 0 ? lastChunkLen : 0;
|
|
50
|
+
outputSize += 1 + ptLen + TAG_LEN;
|
|
51
|
+
}
|
|
52
|
+
const output = new Uint8Array(outputSize);
|
|
53
|
+
output.set(baseNonce);
|
|
54
|
+
let offset = NONCE_LEN;
|
|
55
|
+
for (let i = 0; i < totalChunks; i++) {
|
|
56
|
+
const isFinal = i === totalChunks - 1;
|
|
57
|
+
const chunkTag = isFinal ? CHUNK_TAG_FINAL : CHUNK_TAG_MESSAGE;
|
|
58
|
+
const start = i * chunkSize;
|
|
59
|
+
const end = isFinal ? plaintext.length : start + chunkSize;
|
|
60
|
+
const chunk = plaintext.subarray(start, end);
|
|
61
|
+
const nonce = deriveChunkNonce(baseNonce, i, chunkTag);
|
|
62
|
+
const cipher = (0, chacha_js_1.xchacha20poly1305)(key, nonce);
|
|
63
|
+
const encrypted = cipher.encrypt(chunk);
|
|
64
|
+
output[offset] = chunkTag;
|
|
65
|
+
offset += 1;
|
|
66
|
+
output.set(encrypted, offset);
|
|
67
|
+
offset += encrypted.length;
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
ciphertext: output,
|
|
71
|
+
algorithm: "xchacha20-poly1305-stream",
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function readChunkHeader(ciphertext, offset, chunkSize) {
|
|
75
|
+
const chunkTag = ciphertext[offset];
|
|
76
|
+
if (chunkTag !== CHUNK_TAG_MESSAGE && chunkTag !== CHUNK_TAG_FINAL) {
|
|
77
|
+
throw new Error(`Invalid chunk tag: 0x${chunkTag.toString(16)}`);
|
|
78
|
+
}
|
|
79
|
+
const isFinal = chunkTag === CHUNK_TAG_FINAL;
|
|
80
|
+
const start = offset + 1;
|
|
81
|
+
const encLen = isFinal ? ciphertext.length - start : chunkSize + TAG_LEN;
|
|
82
|
+
if (start + encLen > ciphertext.length) {
|
|
83
|
+
throw new Error("Ciphertext truncated — incomplete chunk");
|
|
84
|
+
}
|
|
85
|
+
return { chunkTag, isFinal, encLen };
|
|
86
|
+
}
|
|
87
|
+
function streamDecrypt(options) {
|
|
88
|
+
const key = toKey(options.key);
|
|
89
|
+
const chunkSize = options.chunkSize ?? DEFAULT_CHUNK_SIZE;
|
|
90
|
+
const ciphertext = options.ciphertext;
|
|
91
|
+
if (ciphertext.length < NONCE_LEN + 1 + TAG_LEN) {
|
|
92
|
+
throw new Error("Ciphertext too short — missing header or chunk data");
|
|
93
|
+
}
|
|
94
|
+
const baseNonce = ciphertext.subarray(0, NONCE_LEN);
|
|
95
|
+
let offset = NONCE_LEN;
|
|
96
|
+
const plaintextChunks = [];
|
|
97
|
+
let totalPtLen = 0;
|
|
98
|
+
let sawFinal = false;
|
|
99
|
+
while (offset < ciphertext.length) {
|
|
100
|
+
const { chunkTag, isFinal, encLen } = readChunkHeader(ciphertext, offset, chunkSize);
|
|
101
|
+
offset += 1;
|
|
102
|
+
const chunkIdx = plaintextChunks.length;
|
|
103
|
+
const nonce = deriveChunkNonce(baseNonce, chunkIdx, chunkTag);
|
|
104
|
+
const cipher = (0, chacha_js_1.xchacha20poly1305)(key, nonce);
|
|
105
|
+
const decrypted = cipher.decrypt(ciphertext.subarray(offset, offset + encLen));
|
|
106
|
+
plaintextChunks.push(decrypted);
|
|
107
|
+
totalPtLen += decrypted.length;
|
|
108
|
+
offset += encLen;
|
|
109
|
+
if (isFinal) {
|
|
110
|
+
sawFinal = true;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (!sawFinal) {
|
|
115
|
+
throw new Error("Ciphertext truncated — final chunk missing");
|
|
116
|
+
}
|
|
117
|
+
const result = new Uint8Array(totalPtLen);
|
|
118
|
+
let pos = 0;
|
|
119
|
+
for (const chunk of plaintextChunks) {
|
|
120
|
+
result.set(chunk, pos);
|
|
121
|
+
pos += chunk.length;
|
|
122
|
+
}
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=stream-aead.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const STREAM_HASH_ALGORITHMS: readonly ["sha256", "sha384", "sha512", "sha3-256", "sha3-512", "blake2b", "blake3"];
|
|
2
|
+
export type StreamHashAlgorithm = (typeof STREAM_HASH_ALGORITHMS)[number];
|
|
3
|
+
export interface StreamingHasher {
|
|
4
|
+
update(data: string | Uint8Array): StreamingHasher;
|
|
5
|
+
digest(): string;
|
|
6
|
+
digestBytes(): Uint8Array;
|
|
7
|
+
}
|
|
8
|
+
export declare function createHasher(algorithm: StreamHashAlgorithm): StreamingHasher;
|
|
9
|
+
//# sourceMappingURL=stream-hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-hash.d.ts","sourceRoot":"","sources":["../../src/streaming/stream-hash.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,sBAAsB,sFAQzB,CAAC;AAEX,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC;AAoB1E,MAAM,WAAW,eAAe;IAE9B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,eAAe,CAAC;IAEnD,MAAM,IAAI,MAAM,CAAC;IAEjB,WAAW,IAAI,UAAU,CAAC;CAC3B;AAYD,wBAAgB,YAAY,CAAC,SAAS,EAAE,mBAAmB,GAAG,eAAe,CAwB5E"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.STREAM_HASH_ALGORITHMS = void 0;
|
|
4
|
+
exports.createHasher = createHasher;
|
|
5
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
6
|
+
const sha3_js_1 = require("@noble/hashes/sha3.js");
|
|
7
|
+
const blake2_js_1 = require("@noble/hashes/blake2.js");
|
|
8
|
+
const blake3_js_1 = require("@noble/hashes/blake3.js");
|
|
9
|
+
exports.STREAM_HASH_ALGORITHMS = [
|
|
10
|
+
"sha256",
|
|
11
|
+
"sha384",
|
|
12
|
+
"sha512",
|
|
13
|
+
"sha3-256",
|
|
14
|
+
"sha3-512",
|
|
15
|
+
"blake2b",
|
|
16
|
+
"blake3",
|
|
17
|
+
];
|
|
18
|
+
const factories = {
|
|
19
|
+
sha256: () => sha2_js_1.sha256.create(),
|
|
20
|
+
sha384: () => sha2_js_1.sha384.create(),
|
|
21
|
+
sha512: () => sha2_js_1.sha512.create(),
|
|
22
|
+
"sha3-256": () => sha3_js_1.sha3_256.create(),
|
|
23
|
+
"sha3-512": () => sha3_js_1.sha3_512.create(),
|
|
24
|
+
blake2b: () => blake2_js_1.blake2b.create(),
|
|
25
|
+
blake3: () => blake3_js_1.blake3.create(),
|
|
26
|
+
};
|
|
27
|
+
function createHasher(algorithm) {
|
|
28
|
+
const factory = factories[algorithm];
|
|
29
|
+
if (!factory) {
|
|
30
|
+
throw new Error(`Unsupported streaming hash algorithm: ${algorithm}`);
|
|
31
|
+
}
|
|
32
|
+
const inner = factory();
|
|
33
|
+
let finalized = false;
|
|
34
|
+
return {
|
|
35
|
+
update(data) {
|
|
36
|
+
if (finalized)
|
|
37
|
+
throw new Error("Hasher already finalized");
|
|
38
|
+
const bytes = typeof data === "string" ? Buffer.from(data, "utf8") : data;
|
|
39
|
+
inner.update(bytes);
|
|
40
|
+
return this;
|
|
41
|
+
},
|
|
42
|
+
digest() {
|
|
43
|
+
finalized = true;
|
|
44
|
+
return Buffer.from(inner.digest()).toString("hex");
|
|
45
|
+
},
|
|
46
|
+
digestBytes() {
|
|
47
|
+
finalized = true;
|
|
48
|
+
return inner.digest();
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=stream-hash.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type CryptoTransformStream<I, O> = import("stream/web").TransformStream<I, O>;
|
|
2
|
+
export type WebStreamHashAlgorithm = "sha256" | "sha512" | "sha3-256" | "sha3-512" | "blake3";
|
|
3
|
+
export declare const WEB_STREAM_HASH_ALGORITHMS: readonly WebStreamHashAlgorithm[];
|
|
4
|
+
export interface HashStreamResult {
|
|
5
|
+
digest: string;
|
|
6
|
+
algorithm: WebStreamHashAlgorithm;
|
|
7
|
+
}
|
|
8
|
+
export interface EncryptStreamOptions {
|
|
9
|
+
key: string | Uint8Array;
|
|
10
|
+
}
|
|
11
|
+
export interface DecryptStreamOptions {
|
|
12
|
+
key: string | Uint8Array;
|
|
13
|
+
}
|
|
14
|
+
export declare function createEncryptStream(options: EncryptStreamOptions): CryptoTransformStream<Uint8Array, Uint8Array>;
|
|
15
|
+
export declare function createDecryptStream(options: DecryptStreamOptions): CryptoTransformStream<Uint8Array, Uint8Array>;
|
|
16
|
+
export declare function createHashStream(algorithm: WebStreamHashAlgorithm): CryptoTransformStream<Uint8Array, HashStreamResult>;
|
|
17
|
+
//# sourceMappingURL=web-streams.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-streams.d.ts","sourceRoot":"","sources":["../../src/streaming/web-streams.ts"],"names":[],"mappings":"AA6BA,MAAM,MAAM,qBAAqB,CAAC,CAAC,EAAE,CAAC,IAAI,OAAO,YAAY,EAAE,eAAe,CAC5E,CAAC,EACD,CAAC,CACF,CAAC;AAMF,MAAM,MAAM,sBAAsB,GAChC,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,UAAU,GAAG,QAAQ,CAAC;AAY3D,eAAO,MAAM,0BAA0B,EAAE,SAAS,sBAAsB,EAM9D,CAAC;AAUX,MAAM,WAAW,gBAAgB;IAE/B,MAAM,EAAE,MAAM,CAAC;IAEf,SAAS,EAAE,sBAAsB,CAAC;CACnC;AAUD,MAAM,WAAW,oBAAoB;IAEnC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;CAC1B;AAUD,MAAM,WAAW,oBAAoB;IAEnC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;CAC1B;AAkDD,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,oBAAoB,GAC5B,qBAAqB,CAAC,UAAU,EAAE,UAAU,CAAC,CA8B/C;AAoBD,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,oBAAoB,GAC5B,qBAAqB,CAAC,UAAU,EAAE,UAAU,CAAC,CA8B/C;AAuBD,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,sBAAsB,GAChC,qBAAqB,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAgBrD"}
|