internxt-crypto 0.0.10-alpha → 0.0.13
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 +3 -4
- package/dist/aes-DSDxP8uF.mjs +184 -0
- package/dist/aes-DSDxP8uF.mjs.map +1 -0
- package/dist/aes-bOrKZuUC.js +226 -0
- package/dist/aes-bOrKZuUC.js.map +1 -0
- package/dist/asymmetric-crypto.d.mts +5 -2
- package/dist/asymmetric-crypto.d.mts.map +1 -0
- package/dist/asymmetric-crypto.d.ts +5 -2
- package/dist/asymmetric-crypto.d.ts.map +1 -0
- package/dist/asymmetric-crypto.js +9 -92
- package/dist/asymmetric-crypto.mjs +2 -84
- package/dist/chunk-DQk6qfdC.mjs +18 -0
- package/dist/chunk-EbLFQX5m.js +60 -0
- package/dist/constants.d.mts +5 -11
- package/dist/constants.d.mts.map +1 -0
- package/dist/constants.d.ts +5 -11
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +33 -49
- package/dist/constants.js.map +1 -1
- package/dist/constants.mjs +32 -40
- package/dist/constants.mjs.map +1 -1
- package/dist/derive-key.d.mts +11 -8
- package/dist/derive-key.d.mts.map +1 -0
- package/dist/derive-key.d.ts +11 -8
- package/dist/derive-key.d.ts.map +1 -0
- package/dist/derive-key.js +13 -795
- package/dist/derive-key.mjs +2 -783
- package/dist/deriveKeysFromPassword-DJRWZ8Rw.mjs +735 -0
- package/dist/deriveKeysFromPassword-DJRWZ8Rw.mjs.map +1 -0
- package/dist/deriveKeysFromPassword-Ko7NxkHM.js +2492 -0
- package/dist/deriveKeysFromPassword-Ko7NxkHM.js.map +1 -0
- package/dist/email-crypto.d.mts +55 -78
- package/dist/email-crypto.d.mts.map +1 -0
- package/dist/email-crypto.d.ts +55 -78
- package/dist/email-crypto.d.ts.map +1 -0
- package/dist/email-crypto.js +13 -1409
- package/dist/email-crypto.mjs +2 -1380
- package/dist/email-search.d.mts +36 -32
- package/dist/email-search.d.mts.map +1 -0
- package/dist/email-search.d.ts +36 -32
- package/dist/email-search.d.ts.map +1 -0
- package/dist/email-search.js +534 -540
- package/dist/email-search.js.map +1 -1
- package/dist/email-search.mjs +532 -538
- package/dist/email-search.mjs.map +1 -1
- package/dist/emailEncryptionKey-27mIHh18.mjs +150 -0
- package/dist/emailEncryptionKey-27mIHh18.mjs.map +1 -0
- package/dist/emailEncryptionKey-DbaDAdoW.js +167 -0
- package/dist/emailEncryptionKey-DbaDAdoW.js.map +1 -0
- package/dist/emailKeys-BJGdkLrg.js +593 -0
- package/dist/emailKeys-BJGdkLrg.js.map +1 -0
- package/dist/emailKeys-Fp9WR3wl.mjs +509 -0
- package/dist/emailKeys-Fp9WR3wl.mjs.map +1 -0
- package/dist/genID-3Er5IowC.mjs +153 -0
- package/dist/genID-3Er5IowC.mjs.map +1 -0
- package/dist/genID-YJSl3YhL.js +238 -0
- package/dist/genID-YJSl3YhL.js.map +1 -0
- package/dist/hash.d.mts +18 -15
- package/dist/hash.d.mts.map +1 -0
- package/dist/hash.d.ts +18 -15
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +12 -95
- package/dist/hash.mjs +2 -84
- package/dist/index.d.mts +15 -18
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +15 -18
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +125 -2698
- package/dist/index.mjs +13 -2538
- package/dist/keys-BfcaiAOv.mjs +90 -0
- package/dist/keys-BfcaiAOv.mjs.map +1 -0
- package/dist/keys-CinT7kEY.js +125 -0
- package/dist/keys-CinT7kEY.js.map +1 -0
- package/dist/keystore-crypto.d.mts +17 -46
- package/dist/keystore-crypto.d.mts.map +1 -0
- package/dist/keystore-crypto.d.ts +17 -46
- package/dist/keystore-crypto.d.ts.map +1 -0
- package/dist/keystore-crypto.js +5 -529
- package/dist/keystore-crypto.mjs +2 -500
- package/dist/kyber1024-PpwE1rki.mjs +144 -0
- package/dist/kyber1024-PpwE1rki.mjs.map +1 -0
- package/dist/kyber1024-jeKS8CXf.js +173 -0
- package/dist/kyber1024-jeKS8CXf.js.map +1 -0
- package/dist/{kyber768-B87rMQ7u.d.mts → kyber768-DGBB_RS7.d.ts} +8 -6
- package/dist/kyber768-DGBB_RS7.d.ts.map +1 -0
- package/dist/{kyber768-B87rMQ7u.d.ts → kyber768-DzIcGg1i.d.mts} +8 -6
- package/dist/kyber768-DzIcGg1i.d.mts.map +1 -0
- package/dist/mac-BMb1F0dN.js +170 -0
- package/dist/mac-BMb1F0dN.js.map +1 -0
- package/dist/mac-ZpRlx8Fs.mjs +116 -0
- package/dist/mac-ZpRlx8Fs.mjs.map +1 -0
- package/dist/post-quantum-crypto.d.mts +23 -27
- package/dist/post-quantum-crypto.d.mts.map +1 -0
- package/dist/post-quantum-crypto.d.ts +23 -27
- package/dist/post-quantum-crypto.d.ts.map +1 -0
- package/dist/post-quantum-crypto.js +14 -92
- package/dist/post-quantum-crypto.mjs +2 -89
- package/dist/storage-service.d.mts +28 -34
- package/dist/storage-service.d.mts.map +1 -0
- package/dist/storage-service.d.ts +28 -34
- package/dist/storage-service.d.ts.map +1 -0
- package/dist/storage-service.js +51 -53
- package/dist/storage-service.js.map +1 -1
- package/dist/storage-service.mjs +40 -51
- package/dist/storage-service.mjs.map +1 -1
- package/dist/symmetric-crypto.d.mts +8 -7
- package/dist/symmetric-crypto.d.mts.map +1 -0
- package/dist/symmetric-crypto.d.ts +8 -7
- package/dist/symmetric-crypto.d.ts.map +1 -0
- package/dist/symmetric-crypto.js +10 -142
- package/dist/symmetric-crypto.mjs +2 -133
- package/dist/types.d.mts +71 -69
- package/dist/types.d.mts.map +1 -0
- package/dist/types.d.ts +71 -69
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -10
- package/dist/types.js.map +1 -1
- package/dist/types.mjs +7 -9
- package/dist/types.mjs.map +1 -1
- package/dist/utils.d.mts +34 -78
- package/dist/utils.d.mts.map +1 -0
- package/dist/utils.d.ts +34 -78
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +17 -313
- package/dist/utils.mjs +2 -272
- package/package.json +21 -87
- package/dist/asymmetric-crypto.js.map +0 -1
- package/dist/asymmetric-crypto.mjs.map +0 -1
- package/dist/derive-key.js.map +0 -1
- package/dist/derive-key.mjs.map +0 -1
- package/dist/email-crypto.js.map +0 -1
- package/dist/email-crypto.mjs.map +0 -1
- package/dist/email-service.d.mts +0 -38
- package/dist/email-service.d.ts +0 -38
- package/dist/email-service.js +0 -154
- package/dist/email-service.js.map +0 -1
- package/dist/email-service.mjs +0 -147
- package/dist/email-service.mjs.map +0 -1
- package/dist/hash.js.map +0 -1
- package/dist/hash.mjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/keystore-crypto.js.map +0 -1
- package/dist/keystore-crypto.mjs.map +0 -1
- package/dist/keystore-service.d.mts +0 -82
- package/dist/keystore-service.d.ts +0 -82
- package/dist/keystore-service.js +0 -349
- package/dist/keystore-service.js.map +0 -1
- package/dist/keystore-service.mjs +0 -342
- package/dist/keystore-service.mjs.map +0 -1
- package/dist/post-quantum-crypto.js.map +0 -1
- package/dist/post-quantum-crypto.mjs.map +0 -1
- package/dist/symmetric-crypto.js.map +0 -1
- package/dist/symmetric-crypto.mjs.map +0 -1
- package/dist/utils-BDaK_d6T.d.ts +0 -114
- package/dist/utils-v34IRTIx.d.mts +0 -114
- package/dist/utils.js.map +0 -1
- package/dist/utils.mjs.map +0 -1
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-EbLFQX5m.js');
|
|
2
|
+
let _noble_post_quantum_ml_kem_js = require("@noble/post-quantum/ml-kem.js");
|
|
3
|
+
|
|
4
|
+
//#region src/post-quantum-crypto/kyber768.ts
|
|
5
|
+
/**
|
|
6
|
+
* Generates public and secret Kyber keys
|
|
7
|
+
*
|
|
8
|
+
* @param seed - The optional seed
|
|
9
|
+
* @returns The generated Kyber key pair.
|
|
10
|
+
*/
|
|
11
|
+
function generateKyberKeys$2(seed) {
|
|
12
|
+
try {
|
|
13
|
+
return _noble_post_quantum_ml_kem_js.ml_kem768.keygen(seed);
|
|
14
|
+
} catch (error) {
|
|
15
|
+
throw new Error("Failed to generate Kyber keys", { cause: error });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Generates a shared secret of 256-bits and encapsulates it to the given public key using Kyber algorithms
|
|
20
|
+
*
|
|
21
|
+
* @param publicKey - The public Kyber key
|
|
22
|
+
* @returns The resulting encapsulation and the generated shared secret.
|
|
23
|
+
*/
|
|
24
|
+
function encapsulateKyber$2(publicKey) {
|
|
25
|
+
try {
|
|
26
|
+
return _noble_post_quantum_ml_kem_js.ml_kem768.encapsulate(publicKey);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
throw new Error("Failed to encapsulate", { cause: error });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Decapsulates the encapsulated shared secret using Kyber algorithms
|
|
33
|
+
*
|
|
34
|
+
* @param cipherText - The encapsulated key
|
|
35
|
+
* @param secretKey - The private Kyber key
|
|
36
|
+
* @returns The resulting decapsulated shared secret.
|
|
37
|
+
*/
|
|
38
|
+
function decapsulateKyber$2(cipherText, secretKey) {
|
|
39
|
+
try {
|
|
40
|
+
return _noble_post_quantum_ml_kem_js.ml_kem768.decapsulate(cipherText, secretKey);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
throw new Error("Failed to decapsulate", { cause: error });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/post-quantum-crypto/kyber512.ts
|
|
48
|
+
var kyber512_exports = /* @__PURE__ */ require_chunk.__exportAll({
|
|
49
|
+
decapsulateKyber: () => decapsulateKyber$1,
|
|
50
|
+
encapsulateKyber: () => encapsulateKyber$1,
|
|
51
|
+
generateKyberKeys: () => generateKyberKeys$1
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* Generates public and secret Kyber keys
|
|
55
|
+
*
|
|
56
|
+
* @param seed - The optional seed
|
|
57
|
+
* @returns The generated Kyber key pair.
|
|
58
|
+
*/
|
|
59
|
+
function generateKyberKeys$1(seed) {
|
|
60
|
+
try {
|
|
61
|
+
return _noble_post_quantum_ml_kem_js.ml_kem512.keygen(seed);
|
|
62
|
+
} catch (error) {
|
|
63
|
+
throw new Error("Failed to generate Kyber keys", { cause: error });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Generates a shared secret of 256-bits and encapsulates it to the given public key using Kyber algorithms
|
|
68
|
+
*
|
|
69
|
+
* @param publicKey - The public Kyber key
|
|
70
|
+
* @returns The resulting encapsulation and the generated shared secret.
|
|
71
|
+
*/
|
|
72
|
+
function encapsulateKyber$1(publicKey) {
|
|
73
|
+
try {
|
|
74
|
+
return _noble_post_quantum_ml_kem_js.ml_kem512.encapsulate(publicKey);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
throw new Error("Failed to encapsulate", { cause: error });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Decapsulates the encapsulated shared secret using Kyber algorithms
|
|
81
|
+
*
|
|
82
|
+
* @param cipherText - The encapsulated key
|
|
83
|
+
* @param secretKey - The private Kyber key
|
|
84
|
+
* @returns The resulting decapsulated shared secret.
|
|
85
|
+
*/
|
|
86
|
+
function decapsulateKyber$1(cipherText, secretKey) {
|
|
87
|
+
try {
|
|
88
|
+
return _noble_post_quantum_ml_kem_js.ml_kem512.decapsulate(cipherText, secretKey);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
throw new Error("Failed to decapsulate", { cause: error });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/post-quantum-crypto/kyber1024.ts
|
|
96
|
+
var kyber1024_exports = /* @__PURE__ */ require_chunk.__exportAll({
|
|
97
|
+
decapsulateKyber: () => decapsulateKyber,
|
|
98
|
+
encapsulateKyber: () => encapsulateKyber,
|
|
99
|
+
generateKyberKeys: () => generateKyberKeys
|
|
100
|
+
});
|
|
101
|
+
/**
|
|
102
|
+
* Generates public and secret Kyber keys
|
|
103
|
+
*
|
|
104
|
+
* @param seed - The optional seed
|
|
105
|
+
* @returns The generated Kyber key pair.
|
|
106
|
+
*/
|
|
107
|
+
function generateKyberKeys(seed) {
|
|
108
|
+
try {
|
|
109
|
+
return _noble_post_quantum_ml_kem_js.ml_kem1024.keygen(seed);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
throw new Error("Failed to generate Kyber keys", { cause: error });
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Generates a shared secret of 256-bits and encapsulates it to the given public key using Kyber algorithms
|
|
116
|
+
*
|
|
117
|
+
* @param publicKey - The public Kyber key
|
|
118
|
+
* @returns The resulting encapsulation and the generated shared secret.
|
|
119
|
+
*/
|
|
120
|
+
function encapsulateKyber(publicKey) {
|
|
121
|
+
try {
|
|
122
|
+
return _noble_post_quantum_ml_kem_js.ml_kem1024.encapsulate(publicKey);
|
|
123
|
+
} catch (error) {
|
|
124
|
+
throw new Error("Failed to encapsulate", { cause: error });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Decapsulates the encapsulated shared secret using Kyber algorithms
|
|
129
|
+
*
|
|
130
|
+
* @param cipherText - The encapsulated key
|
|
131
|
+
* @param secretKey - The private Kyber key
|
|
132
|
+
* @returns The resulting decapsulated shared secret.
|
|
133
|
+
*/
|
|
134
|
+
function decapsulateKyber(cipherText, secretKey) {
|
|
135
|
+
try {
|
|
136
|
+
return _noble_post_quantum_ml_kem_js.ml_kem1024.decapsulate(cipherText, secretKey);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
throw new Error("Failed to decapsulate", { cause: error });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
//#endregion
|
|
143
|
+
Object.defineProperty(exports, 'decapsulateKyber', {
|
|
144
|
+
enumerable: true,
|
|
145
|
+
get: function () {
|
|
146
|
+
return decapsulateKyber$2;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
Object.defineProperty(exports, 'encapsulateKyber', {
|
|
150
|
+
enumerable: true,
|
|
151
|
+
get: function () {
|
|
152
|
+
return encapsulateKyber$2;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
Object.defineProperty(exports, 'generateKyberKeys', {
|
|
156
|
+
enumerable: true,
|
|
157
|
+
get: function () {
|
|
158
|
+
return generateKyberKeys$2;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
Object.defineProperty(exports, 'kyber1024_exports', {
|
|
162
|
+
enumerable: true,
|
|
163
|
+
get: function () {
|
|
164
|
+
return kyber1024_exports;
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
Object.defineProperty(exports, 'kyber512_exports', {
|
|
168
|
+
enumerable: true,
|
|
169
|
+
get: function () {
|
|
170
|
+
return kyber512_exports;
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
//# sourceMappingURL=kyber1024-jeKS8CXf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kyber1024-jeKS8CXf.js","names":["generateKyberKeys","ml_kem768","encapsulateKyber","decapsulateKyber","generateKyberKeys","ml_kem512","encapsulateKyber","decapsulateKyber","ml_kem1024"],"sources":["../src/post-quantum-crypto/kyber768.ts","../src/post-quantum-crypto/kyber512.ts","../src/post-quantum-crypto/kyber1024.ts"],"sourcesContent":["import { ml_kem768 } from '@noble/post-quantum/ml-kem.js';\n\n/**\n * Generates public and secret Kyber keys\n *\n * @param seed - The optional seed\n * @returns The generated Kyber key pair.\n */\nexport function generateKyberKeys(seed?: Uint8Array): {\n publicKey: Uint8Array;\n secretKey: Uint8Array;\n} {\n try {\n return ml_kem768.keygen(seed);\n } catch (error) {\n throw new Error('Failed to generate Kyber keys', { cause: error });\n }\n}\n\n/**\n * Generates a shared secret of 256-bits and encapsulates it to the given public key using Kyber algorithms\n *\n * @param publicKey - The public Kyber key\n * @returns The resulting encapsulation and the generated shared secret.\n */\nexport function encapsulateKyber(publicKey: Uint8Array): {\n cipherText: Uint8Array;\n sharedSecret: Uint8Array;\n} {\n try {\n return ml_kem768.encapsulate(publicKey);\n } catch (error) {\n throw new Error('Failed to encapsulate', { cause: error });\n }\n}\n\n/**\n * Decapsulates the encapsulated shared secret using Kyber algorithms\n *\n * @param cipherText - The encapsulated key\n * @param secretKey - The private Kyber key\n * @returns The resulting decapsulated shared secret.\n */\nexport function decapsulateKyber(cipherText: Uint8Array, secretKey: Uint8Array): Uint8Array {\n try {\n return ml_kem768.decapsulate(cipherText, secretKey);\n } catch (error) {\n throw new Error('Failed to decapsulate', { cause: error });\n }\n}\n","import { ml_kem512 } from '@noble/post-quantum/ml-kem.js';\n\n/**\n * Generates public and secret Kyber keys\n *\n * @param seed - The optional seed\n * @returns The generated Kyber key pair.\n */\nexport function generateKyberKeys(seed?: Uint8Array): {\n publicKey: Uint8Array;\n secretKey: Uint8Array;\n} {\n try {\n return ml_kem512.keygen(seed);\n } catch (error) {\n throw new Error('Failed to generate Kyber keys', { cause: error });\n }\n}\n\n/**\n * Generates a shared secret of 256-bits and encapsulates it to the given public key using Kyber algorithms\n *\n * @param publicKey - The public Kyber key\n * @returns The resulting encapsulation and the generated shared secret.\n */\nexport function encapsulateKyber(publicKey: Uint8Array): {\n cipherText: Uint8Array;\n sharedSecret: Uint8Array;\n} {\n try {\n return ml_kem512.encapsulate(publicKey);\n } catch (error) {\n throw new Error('Failed to encapsulate', { cause: error });\n }\n}\n\n/**\n * Decapsulates the encapsulated shared secret using Kyber algorithms\n *\n * @param cipherText - The encapsulated key\n * @param secretKey - The private Kyber key\n * @returns The resulting decapsulated shared secret.\n */\nexport function decapsulateKyber(cipherText: Uint8Array, secretKey: Uint8Array): Uint8Array {\n try {\n return ml_kem512.decapsulate(cipherText, secretKey);\n } catch (error) {\n throw new Error('Failed to decapsulate', { cause: error });\n }\n}\n","import { ml_kem1024 } from '@noble/post-quantum/ml-kem.js';\n\n/**\n * Generates public and secret Kyber keys\n *\n * @param seed - The optional seed\n * @returns The generated Kyber key pair.\n */\nexport function generateKyberKeys(seed?: Uint8Array): {\n publicKey: Uint8Array;\n secretKey: Uint8Array;\n} {\n try {\n return ml_kem1024.keygen(seed);\n } catch (error) {\n throw new Error('Failed to generate Kyber keys', { cause: error });\n }\n}\n\n/**\n * Generates a shared secret of 256-bits and encapsulates it to the given public key using Kyber algorithms\n *\n * @param publicKey - The public Kyber key\n * @returns The resulting encapsulation and the generated shared secret.\n */\nexport function encapsulateKyber(publicKey: Uint8Array): {\n cipherText: Uint8Array;\n sharedSecret: Uint8Array;\n} {\n try {\n return ml_kem1024.encapsulate(publicKey);\n } catch (error) {\n throw new Error('Failed to encapsulate', { cause: error });\n }\n}\n\n/**\n * Decapsulates the encapsulated shared secret using Kyber algorithms\n *\n * @param cipherText - The encapsulated key\n * @param secretKey - The private Kyber key\n * @returns The resulting decapsulated shared secret.\n */\nexport function decapsulateKyber(cipherText: Uint8Array, secretKey: Uint8Array): Uint8Array {\n try {\n return ml_kem1024.decapsulate(cipherText, secretKey);\n } catch (error) {\n throw new Error('Failed to decapsulate', { cause: error });\n }\n}\n"],"mappings":";;;;;;;;;;AAQA,SAAgBA,oBAAkB,MAGhC;AACA,KAAI;AACF,SAAOC,wCAAU,OAAO,KAAK;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,iCAAiC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;AAUtE,SAAgBC,mBAAiB,WAG/B;AACA,KAAI;AACF,SAAOD,wCAAU,YAAY,UAAU;UAChC,OAAO;AACd,QAAM,IAAI,MAAM,yBAAyB,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;AAW9D,SAAgBE,mBAAiB,YAAwB,WAAmC;AAC1F,KAAI;AACF,SAAOF,wCAAU,YAAY,YAAY,UAAU;UAC5C,OAAO;AACd,QAAM,IAAI,MAAM,yBAAyB,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;;;;;;;ACvC9D,SAAgBG,oBAAkB,MAGhC;AACA,KAAI;AACF,SAAOC,wCAAU,OAAO,KAAK;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,iCAAiC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;AAUtE,SAAgBC,mBAAiB,WAG/B;AACA,KAAI;AACF,SAAOD,wCAAU,YAAY,UAAU;UAChC,OAAO;AACd,QAAM,IAAI,MAAM,yBAAyB,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;AAW9D,SAAgBE,mBAAiB,YAAwB,WAAmC;AAC1F,KAAI;AACF,SAAOF,wCAAU,YAAY,YAAY,UAAU;UAC5C,OAAO;AACd,QAAM,IAAI,MAAM,yBAAyB,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;;;;;;;ACvC9D,SAAgB,kBAAkB,MAGhC;AACA,KAAI;AACF,SAAOG,yCAAW,OAAO,KAAK;UACvB,OAAO;AACd,QAAM,IAAI,MAAM,iCAAiC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;AAUtE,SAAgB,iBAAiB,WAG/B;AACA,KAAI;AACF,SAAOA,yCAAW,YAAY,UAAU;UACjC,OAAO;AACd,QAAM,IAAI,MAAM,yBAAyB,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;AAW9D,SAAgB,iBAAiB,YAAwB,WAAmC;AAC1F,KAAI;AACF,SAAOA,yCAAW,YAAY,YAAY,UAAU;UAC7C,OAAO;AACd,QAAM,IAAI,MAAM,yBAAyB,EAAE,OAAO,OAAO,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/post-quantum-crypto/kyber768.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Generates public and secret Kyber keys
|
|
3
4
|
*
|
|
@@ -5,8 +6,8 @@
|
|
|
5
6
|
* @returns The generated Kyber key pair.
|
|
6
7
|
*/
|
|
7
8
|
declare function generateKyberKeys(seed?: Uint8Array): {
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
publicKey: Uint8Array;
|
|
10
|
+
secretKey: Uint8Array;
|
|
10
11
|
};
|
|
11
12
|
/**
|
|
12
13
|
* Generates a shared secret of 256-bits and encapsulates it to the given public key using Kyber algorithms
|
|
@@ -15,8 +16,8 @@ declare function generateKyberKeys(seed?: Uint8Array): {
|
|
|
15
16
|
* @returns The resulting encapsulation and the generated shared secret.
|
|
16
17
|
*/
|
|
17
18
|
declare function encapsulateKyber(publicKey: Uint8Array): {
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
cipherText: Uint8Array;
|
|
20
|
+
sharedSecret: Uint8Array;
|
|
20
21
|
};
|
|
21
22
|
/**
|
|
22
23
|
* Decapsulates the encapsulated shared secret using Kyber algorithms
|
|
@@ -26,5 +27,6 @@ declare function encapsulateKyber(publicKey: Uint8Array): {
|
|
|
26
27
|
* @returns The resulting decapsulated shared secret.
|
|
27
28
|
*/
|
|
28
29
|
declare function decapsulateKyber(cipherText: Uint8Array, secretKey: Uint8Array): Uint8Array;
|
|
29
|
-
|
|
30
|
-
export {
|
|
30
|
+
//#endregion
|
|
31
|
+
export { encapsulateKyber as n, generateKyberKeys as r, decapsulateKyber as t };
|
|
32
|
+
//# sourceMappingURL=kyber768-DGBB_RS7.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kyber768-DGBB_RS7.d.ts","names":[],"sources":["../src/post-quantum-crypto/kyber768.ts"],"mappings":";;AAQA;;;;;iBAAgB,iBAAA,CAAkB,IAAA,GAAO,UAAA;EACvC,SAAA,EAAW,UAAA;EACX,SAAA,EAAW,UAAA;AAAA;;;;;;;iBAeG,gBAAA,CAAiB,SAAA,EAAW,UAAA;EAC1C,UAAA,EAAY,UAAA;EACZ,YAAA,EAAc,UAAA;AAAA;;;;;;;;iBAgBA,gBAAA,CAAiB,UAAA,EAAY,UAAA,EAAY,SAAA,EAAW,UAAA,GAAa,UAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/post-quantum-crypto/kyber768.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Generates public and secret Kyber keys
|
|
3
4
|
*
|
|
@@ -5,8 +6,8 @@
|
|
|
5
6
|
* @returns The generated Kyber key pair.
|
|
6
7
|
*/
|
|
7
8
|
declare function generateKyberKeys(seed?: Uint8Array): {
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
publicKey: Uint8Array;
|
|
10
|
+
secretKey: Uint8Array;
|
|
10
11
|
};
|
|
11
12
|
/**
|
|
12
13
|
* Generates a shared secret of 256-bits and encapsulates it to the given public key using Kyber algorithms
|
|
@@ -15,8 +16,8 @@ declare function generateKyberKeys(seed?: Uint8Array): {
|
|
|
15
16
|
* @returns The resulting encapsulation and the generated shared secret.
|
|
16
17
|
*/
|
|
17
18
|
declare function encapsulateKyber(publicKey: Uint8Array): {
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
cipherText: Uint8Array;
|
|
20
|
+
sharedSecret: Uint8Array;
|
|
20
21
|
};
|
|
21
22
|
/**
|
|
22
23
|
* Decapsulates the encapsulated shared secret using Kyber algorithms
|
|
@@ -26,5 +27,6 @@ declare function encapsulateKyber(publicKey: Uint8Array): {
|
|
|
26
27
|
* @returns The resulting decapsulated shared secret.
|
|
27
28
|
*/
|
|
28
29
|
declare function decapsulateKyber(cipherText: Uint8Array, secretKey: Uint8Array): Uint8Array;
|
|
29
|
-
|
|
30
|
-
export {
|
|
30
|
+
//#endregion
|
|
31
|
+
export { encapsulateKyber as n, generateKyberKeys as r, decapsulateKyber as t };
|
|
32
|
+
//# sourceMappingURL=kyber768-DzIcGg1i.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kyber768-DzIcGg1i.d.mts","names":[],"sources":["../src/post-quantum-crypto/kyber768.ts"],"mappings":";;AAQA;;;;;iBAAgB,iBAAA,CAAkB,IAAA,GAAO,UAAA;EACvC,SAAA,EAAW,UAAA;EACX,SAAA,EAAW,UAAA;AAAA;;;;;;;iBAeG,gBAAA,CAAiB,SAAA,EAAW,UAAA;EAC1C,UAAA,EAAY,UAAA;EACZ,YAAA,EAAc,UAAA;AAAA;;;;;;;;iBAgBA,gBAAA,CAAiB,UAAA,EAAY,UAAA,EAAY,SAAA,EAAW,UAAA,GAAa,UAAA"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-EbLFQX5m.js');
|
|
2
|
+
const require_constants = require('./constants.js');
|
|
3
|
+
let _noble_hashes_blake3_js = require("@noble/hashes/blake3.js");
|
|
4
|
+
let _noble_hashes_utils_js = require("@noble/hashes/utils.js");
|
|
5
|
+
|
|
6
|
+
//#region src/hash/blake3.ts
|
|
7
|
+
/**
|
|
8
|
+
* Hashes the given array of data
|
|
9
|
+
*
|
|
10
|
+
* @param data - The data to hash
|
|
11
|
+
* @returns The resulting hash array
|
|
12
|
+
*/
|
|
13
|
+
function hashDataArray(data) {
|
|
14
|
+
try {
|
|
15
|
+
const hasher = _noble_hashes_blake3_js.blake3.create();
|
|
16
|
+
for (const d of data) hasher.update(d);
|
|
17
|
+
return hasher.digest();
|
|
18
|
+
} catch (error) {
|
|
19
|
+
throw new Error("Failed to compute hash", { cause: error });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Hashes the given array of data
|
|
24
|
+
*
|
|
25
|
+
* @param data - The data to hash
|
|
26
|
+
* @returns The resulting hash hex string
|
|
27
|
+
*/
|
|
28
|
+
function hashDataArrayHex(data) {
|
|
29
|
+
return (0, _noble_hashes_utils_js.bytesToHex)(hashDataArray(data));
|
|
30
|
+
}
|
|
31
|
+
function hashDataArrayWithKeyHex(hashKey, data) {
|
|
32
|
+
try {
|
|
33
|
+
return (0, _noble_hashes_utils_js.bytesToHex)(hashDataArrayWithKey(hashKey, data));
|
|
34
|
+
} catch (error) {
|
|
35
|
+
throw new Error("Failed to compute hash hex", { cause: error });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function hashDataArrayWithKey(hashKey, data) {
|
|
39
|
+
try {
|
|
40
|
+
const hasher = _noble_hashes_blake3_js.blake3.create({ key: hashKey });
|
|
41
|
+
for (const d of data) hasher.update(d);
|
|
42
|
+
return hasher.digest();
|
|
43
|
+
} catch (error) {
|
|
44
|
+
throw new Error("Failed to compute hash", { cause: error });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Hashes the given array of data using blake3 algorithm
|
|
49
|
+
*
|
|
50
|
+
* @param bytes - The desired output byte-length
|
|
51
|
+
* @param data - The data to hash
|
|
52
|
+
* @returns The resulting hash value
|
|
53
|
+
*/
|
|
54
|
+
function getBytesFromDataArray(bytes, data) {
|
|
55
|
+
try {
|
|
56
|
+
const hasher = _noble_hashes_blake3_js.blake3.create({ dkLen: bytes });
|
|
57
|
+
for (const chunk of data) hasher.update(chunk);
|
|
58
|
+
return hasher.digest();
|
|
59
|
+
} catch (error) {
|
|
60
|
+
throw new Error("Failed to get bytes from data", { cause: error });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Hashes the given array of data using blake3 algorithm
|
|
65
|
+
*
|
|
66
|
+
* @param bytes - The desired output byte-length
|
|
67
|
+
* @param data - The data to hash
|
|
68
|
+
* @returns The resulting hash value
|
|
69
|
+
*/
|
|
70
|
+
function getBytesFromDataArrayHex(bytes, data) {
|
|
71
|
+
try {
|
|
72
|
+
return (0, _noble_hashes_utils_js.bytesToHex)(getBytesFromDataArray(bytes, data));
|
|
73
|
+
} catch (error) {
|
|
74
|
+
throw new Error("Failed to get bytes from data", { cause: error });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Hashes the given string using blake3 algorithm
|
|
79
|
+
*
|
|
80
|
+
* @param bytes - The desired output byte-length
|
|
81
|
+
* @param data - The data to hash
|
|
82
|
+
* @returns The resulting hash value
|
|
83
|
+
*/
|
|
84
|
+
function getBytesFromData(bytes, data) {
|
|
85
|
+
return (0, _noble_hashes_blake3_js.blake3)(data, { dkLen: bytes });
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Hashes the given data using blake3 algorithm
|
|
89
|
+
*
|
|
90
|
+
* @param bytes - The desired output byte-length
|
|
91
|
+
* @param data - The data to hash
|
|
92
|
+
* @returns The resulting hash value
|
|
93
|
+
*/
|
|
94
|
+
function getBytesFromDataHex(bytes, data) {
|
|
95
|
+
return (0, _noble_hashes_utils_js.bytesToHex)(getBytesFromData(bytes, data));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/hash/mac.ts
|
|
100
|
+
/**
|
|
101
|
+
* Computes mac for the given key material and data
|
|
102
|
+
*
|
|
103
|
+
* @param keyMaterial - The key material
|
|
104
|
+
* @param data - The data to hash
|
|
105
|
+
* @returns The resulting hash hex string
|
|
106
|
+
*/
|
|
107
|
+
function computeMac(keyMaterial, data) {
|
|
108
|
+
try {
|
|
109
|
+
return (0, _noble_hashes_utils_js.bytesToHex)(hashDataArrayWithKey(getBytesFromData(require_constants.AES_KEY_BIT_LENGTH / 8, keyMaterial), data));
|
|
110
|
+
} catch (error) {
|
|
111
|
+
throw new Error("Failed to compute mac", { cause: error });
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
//#endregion
|
|
116
|
+
Object.defineProperty(exports, 'computeMac', {
|
|
117
|
+
enumerable: true,
|
|
118
|
+
get: function () {
|
|
119
|
+
return computeMac;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
Object.defineProperty(exports, 'getBytesFromData', {
|
|
123
|
+
enumerable: true,
|
|
124
|
+
get: function () {
|
|
125
|
+
return getBytesFromData;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
Object.defineProperty(exports, 'getBytesFromDataArray', {
|
|
129
|
+
enumerable: true,
|
|
130
|
+
get: function () {
|
|
131
|
+
return getBytesFromDataArray;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
Object.defineProperty(exports, 'getBytesFromDataArrayHex', {
|
|
135
|
+
enumerable: true,
|
|
136
|
+
get: function () {
|
|
137
|
+
return getBytesFromDataArrayHex;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
Object.defineProperty(exports, 'getBytesFromDataHex', {
|
|
141
|
+
enumerable: true,
|
|
142
|
+
get: function () {
|
|
143
|
+
return getBytesFromDataHex;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
Object.defineProperty(exports, 'hashDataArray', {
|
|
147
|
+
enumerable: true,
|
|
148
|
+
get: function () {
|
|
149
|
+
return hashDataArray;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
Object.defineProperty(exports, 'hashDataArrayHex', {
|
|
153
|
+
enumerable: true,
|
|
154
|
+
get: function () {
|
|
155
|
+
return hashDataArrayHex;
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
Object.defineProperty(exports, 'hashDataArrayWithKey', {
|
|
159
|
+
enumerable: true,
|
|
160
|
+
get: function () {
|
|
161
|
+
return hashDataArrayWithKey;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
Object.defineProperty(exports, 'hashDataArrayWithKeyHex', {
|
|
165
|
+
enumerable: true,
|
|
166
|
+
get: function () {
|
|
167
|
+
return hashDataArrayWithKeyHex;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
//# sourceMappingURL=mac-BMb1F0dN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mac-BMb1F0dN.js","names":["blake3","AES_KEY_BIT_LENGTH"],"sources":["../src/hash/blake3.ts","../src/hash/mac.ts"],"sourcesContent":["import { blake3 } from '@noble/hashes/blake3.js';\nimport { bytesToHex } from '@noble/hashes/utils.js';\n\n/**\n * Hashes the given array of data\n *\n * @param data - The data to hash\n * @returns The resulting hash array\n */\nexport function hashDataArray(data: Uint8Array[]): Uint8Array {\n try {\n const hasher = blake3.create();\n for (const d of data) {\n hasher.update(d);\n }\n return hasher.digest();\n } catch (error) {\n throw new Error('Failed to compute hash', { cause: error });\n }\n}\n\n/**\n * Hashes the given array of data\n *\n * @param data - The data to hash\n * @returns The resulting hash hex string\n */\nexport function hashDataArrayHex(data: Uint8Array[]): string {\n return bytesToHex(hashDataArray(data));\n}\n\nexport function hashDataArrayWithKeyHex(hashKey: Uint8Array, data: Uint8Array[]): string {\n try {\n const hash = hashDataArrayWithKey(hashKey, data);\n return bytesToHex(hash);\n } catch (error) {\n throw new Error('Failed to compute hash hex', { cause: error });\n }\n}\n\nexport function hashDataArrayWithKey(hashKey: Uint8Array, data: Uint8Array[]): Uint8Array {\n try {\n const hasher = blake3.create({ key: hashKey });\n for (const d of data) {\n hasher.update(d);\n }\n return hasher.digest();\n } catch (error) {\n throw new Error('Failed to compute hash', { cause: error });\n }\n}\n\n/**\n * Hashes the given array of data using blake3 algorithm\n *\n * @param bytes - The desired output byte-length\n * @param data - The data to hash\n * @returns The resulting hash value\n */\nexport function getBytesFromDataArray(bytes: number, data: Uint8Array[]): Uint8Array {\n try {\n const hasher = blake3.create({ dkLen: bytes });\n for (const chunk of data) {\n hasher.update(chunk);\n }\n return hasher.digest();\n } catch (error) {\n throw new Error('Failed to get bytes from data', { cause: error });\n }\n}\n\n/**\n * Hashes the given array of data using blake3 algorithm\n *\n * @param bytes - The desired output byte-length\n * @param data - The data to hash\n * @returns The resulting hash value\n */\nexport function getBytesFromDataArrayHex(bytes: number, data: Uint8Array[]): string {\n try {\n const hash = getBytesFromDataArray(bytes, data);\n return bytesToHex(hash);\n } catch (error) {\n throw new Error('Failed to get bytes from data', { cause: error });\n }\n}\n\n/**\n * Hashes the given string using blake3 algorithm\n *\n * @param bytes - The desired output byte-length\n * @param data - The data to hash\n * @returns The resulting hash value\n */\nexport function getBytesFromData(bytes: number, data: Uint8Array): Uint8Array {\n return blake3(data, { dkLen: bytes });\n}\n\n/**\n * Hashes the given data using blake3 algorithm\n *\n * @param bytes - The desired output byte-length\n * @param data - The data to hash\n * @returns The resulting hash value\n */\nexport function getBytesFromDataHex(bytes: number, data: Uint8Array): string {\n return bytesToHex(getBytesFromData(bytes, data));\n}\n","import { bytesToHex } from '@noble/hashes/utils.js';\nimport { AES_KEY_BIT_LENGTH } from '../constants';\nimport { getBytesFromData, hashDataArrayWithKey } from './blake3';\n\n/**\n * Computes mac for the given key material and data\n *\n * @param keyMaterial - The key material\n * @param data - The data to hash\n * @returns The resulting hash hex string\n */\nexport function computeMac(keyMaterial: Uint8Array, data: Uint8Array[]): string {\n try {\n const key = getBytesFromData(AES_KEY_BIT_LENGTH / 8, keyMaterial);\n const hash = hashDataArrayWithKey(key, data);\n return bytesToHex(hash);\n } catch (error) {\n throw new Error('Failed to compute mac', { cause: error });\n }\n}\n"],"mappings":";;;;;;;;;;;;AASA,SAAgB,cAAc,MAAgC;AAC5D,KAAI;EACF,MAAM,SAASA,+BAAO,QAAQ;AAC9B,OAAK,MAAM,KAAK,KACd,QAAO,OAAO,EAAE;AAElB,SAAO,OAAO,QAAQ;UACf,OAAO;AACd,QAAM,IAAI,MAAM,0BAA0B,EAAE,OAAO,OAAO,CAAC;;;;;;;;;AAU/D,SAAgB,iBAAiB,MAA4B;AAC3D,+CAAkB,cAAc,KAAK,CAAC;;AAGxC,SAAgB,wBAAwB,SAAqB,MAA4B;AACvF,KAAI;AAEF,gDADa,qBAAqB,SAAS,KAAK,CACzB;UAChB,OAAO;AACd,QAAM,IAAI,MAAM,8BAA8B,EAAE,OAAO,OAAO,CAAC;;;AAInE,SAAgB,qBAAqB,SAAqB,MAAgC;AACxF,KAAI;EACF,MAAM,SAASA,+BAAO,OAAO,EAAE,KAAK,SAAS,CAAC;AAC9C,OAAK,MAAM,KAAK,KACd,QAAO,OAAO,EAAE;AAElB,SAAO,OAAO,QAAQ;UACf,OAAO;AACd,QAAM,IAAI,MAAM,0BAA0B,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;AAW/D,SAAgB,sBAAsB,OAAe,MAAgC;AACnF,KAAI;EACF,MAAM,SAASA,+BAAO,OAAO,EAAE,OAAO,OAAO,CAAC;AAC9C,OAAK,MAAM,SAAS,KAClB,QAAO,OAAO,MAAM;AAEtB,SAAO,OAAO,QAAQ;UACf,OAAO;AACd,QAAM,IAAI,MAAM,iCAAiC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;AAWtE,SAAgB,yBAAyB,OAAe,MAA4B;AAClF,KAAI;AAEF,gDADa,sBAAsB,OAAO,KAAK,CACxB;UAChB,OAAO;AACd,QAAM,IAAI,MAAM,iCAAiC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;AAWtE,SAAgB,iBAAiB,OAAe,MAA8B;AAC5E,4CAAc,MAAM,EAAE,OAAO,OAAO,CAAC;;;;;;;;;AAUvC,SAAgB,oBAAoB,OAAe,MAA0B;AAC3E,+CAAkB,iBAAiB,OAAO,KAAK,CAAC;;;;;;;;;;;;AC/FlD,SAAgB,WAAW,aAAyB,MAA4B;AAC9E,KAAI;AAGF,gDADa,qBADD,iBAAiBC,uCAAqB,GAAG,YAAY,EAC1B,KAAK,CACrB;UAChB,OAAO;AACd,QAAM,IAAI,MAAM,yBAAyB,EAAE,OAAO,OAAO,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { AES_KEY_BIT_LENGTH } from "./constants.mjs";
|
|
2
|
+
import { blake3 } from "@noble/hashes/blake3.js";
|
|
3
|
+
import { bytesToHex } from "@noble/hashes/utils.js";
|
|
4
|
+
|
|
5
|
+
//#region src/hash/blake3.ts
|
|
6
|
+
/**
|
|
7
|
+
* Hashes the given array of data
|
|
8
|
+
*
|
|
9
|
+
* @param data - The data to hash
|
|
10
|
+
* @returns The resulting hash array
|
|
11
|
+
*/
|
|
12
|
+
function hashDataArray(data) {
|
|
13
|
+
try {
|
|
14
|
+
const hasher = blake3.create();
|
|
15
|
+
for (const d of data) hasher.update(d);
|
|
16
|
+
return hasher.digest();
|
|
17
|
+
} catch (error) {
|
|
18
|
+
throw new Error("Failed to compute hash", { cause: error });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Hashes the given array of data
|
|
23
|
+
*
|
|
24
|
+
* @param data - The data to hash
|
|
25
|
+
* @returns The resulting hash hex string
|
|
26
|
+
*/
|
|
27
|
+
function hashDataArrayHex(data) {
|
|
28
|
+
return bytesToHex(hashDataArray(data));
|
|
29
|
+
}
|
|
30
|
+
function hashDataArrayWithKeyHex(hashKey, data) {
|
|
31
|
+
try {
|
|
32
|
+
return bytesToHex(hashDataArrayWithKey(hashKey, data));
|
|
33
|
+
} catch (error) {
|
|
34
|
+
throw new Error("Failed to compute hash hex", { cause: error });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function hashDataArrayWithKey(hashKey, data) {
|
|
38
|
+
try {
|
|
39
|
+
const hasher = blake3.create({ key: hashKey });
|
|
40
|
+
for (const d of data) hasher.update(d);
|
|
41
|
+
return hasher.digest();
|
|
42
|
+
} catch (error) {
|
|
43
|
+
throw new Error("Failed to compute hash", { cause: error });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Hashes the given array of data using blake3 algorithm
|
|
48
|
+
*
|
|
49
|
+
* @param bytes - The desired output byte-length
|
|
50
|
+
* @param data - The data to hash
|
|
51
|
+
* @returns The resulting hash value
|
|
52
|
+
*/
|
|
53
|
+
function getBytesFromDataArray(bytes, data) {
|
|
54
|
+
try {
|
|
55
|
+
const hasher = blake3.create({ dkLen: bytes });
|
|
56
|
+
for (const chunk of data) hasher.update(chunk);
|
|
57
|
+
return hasher.digest();
|
|
58
|
+
} catch (error) {
|
|
59
|
+
throw new Error("Failed to get bytes from data", { cause: error });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Hashes the given array of data using blake3 algorithm
|
|
64
|
+
*
|
|
65
|
+
* @param bytes - The desired output byte-length
|
|
66
|
+
* @param data - The data to hash
|
|
67
|
+
* @returns The resulting hash value
|
|
68
|
+
*/
|
|
69
|
+
function getBytesFromDataArrayHex(bytes, data) {
|
|
70
|
+
try {
|
|
71
|
+
return bytesToHex(getBytesFromDataArray(bytes, data));
|
|
72
|
+
} catch (error) {
|
|
73
|
+
throw new Error("Failed to get bytes from data", { cause: error });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Hashes the given string using blake3 algorithm
|
|
78
|
+
*
|
|
79
|
+
* @param bytes - The desired output byte-length
|
|
80
|
+
* @param data - The data to hash
|
|
81
|
+
* @returns The resulting hash value
|
|
82
|
+
*/
|
|
83
|
+
function getBytesFromData(bytes, data) {
|
|
84
|
+
return blake3(data, { dkLen: bytes });
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Hashes the given data using blake3 algorithm
|
|
88
|
+
*
|
|
89
|
+
* @param bytes - The desired output byte-length
|
|
90
|
+
* @param data - The data to hash
|
|
91
|
+
* @returns The resulting hash value
|
|
92
|
+
*/
|
|
93
|
+
function getBytesFromDataHex(bytes, data) {
|
|
94
|
+
return bytesToHex(getBytesFromData(bytes, data));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/hash/mac.ts
|
|
99
|
+
/**
|
|
100
|
+
* Computes mac for the given key material and data
|
|
101
|
+
*
|
|
102
|
+
* @param keyMaterial - The key material
|
|
103
|
+
* @param data - The data to hash
|
|
104
|
+
* @returns The resulting hash hex string
|
|
105
|
+
*/
|
|
106
|
+
function computeMac(keyMaterial, data) {
|
|
107
|
+
try {
|
|
108
|
+
return bytesToHex(hashDataArrayWithKey(getBytesFromData(AES_KEY_BIT_LENGTH / 8, keyMaterial), data));
|
|
109
|
+
} catch (error) {
|
|
110
|
+
throw new Error("Failed to compute mac", { cause: error });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
export { getBytesFromDataHex as a, hashDataArrayWithKey as c, getBytesFromDataArrayHex as i, hashDataArrayWithKeyHex as l, getBytesFromData as n, hashDataArray as o, getBytesFromDataArray as r, hashDataArrayHex as s, computeMac as t };
|
|
116
|
+
//# sourceMappingURL=mac-ZpRlx8Fs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mac-ZpRlx8Fs.mjs","names":[],"sources":["../src/hash/blake3.ts","../src/hash/mac.ts"],"sourcesContent":["import { blake3 } from '@noble/hashes/blake3.js';\nimport { bytesToHex } from '@noble/hashes/utils.js';\n\n/**\n * Hashes the given array of data\n *\n * @param data - The data to hash\n * @returns The resulting hash array\n */\nexport function hashDataArray(data: Uint8Array[]): Uint8Array {\n try {\n const hasher = blake3.create();\n for (const d of data) {\n hasher.update(d);\n }\n return hasher.digest();\n } catch (error) {\n throw new Error('Failed to compute hash', { cause: error });\n }\n}\n\n/**\n * Hashes the given array of data\n *\n * @param data - The data to hash\n * @returns The resulting hash hex string\n */\nexport function hashDataArrayHex(data: Uint8Array[]): string {\n return bytesToHex(hashDataArray(data));\n}\n\nexport function hashDataArrayWithKeyHex(hashKey: Uint8Array, data: Uint8Array[]): string {\n try {\n const hash = hashDataArrayWithKey(hashKey, data);\n return bytesToHex(hash);\n } catch (error) {\n throw new Error('Failed to compute hash hex', { cause: error });\n }\n}\n\nexport function hashDataArrayWithKey(hashKey: Uint8Array, data: Uint8Array[]): Uint8Array {\n try {\n const hasher = blake3.create({ key: hashKey });\n for (const d of data) {\n hasher.update(d);\n }\n return hasher.digest();\n } catch (error) {\n throw new Error('Failed to compute hash', { cause: error });\n }\n}\n\n/**\n * Hashes the given array of data using blake3 algorithm\n *\n * @param bytes - The desired output byte-length\n * @param data - The data to hash\n * @returns The resulting hash value\n */\nexport function getBytesFromDataArray(bytes: number, data: Uint8Array[]): Uint8Array {\n try {\n const hasher = blake3.create({ dkLen: bytes });\n for (const chunk of data) {\n hasher.update(chunk);\n }\n return hasher.digest();\n } catch (error) {\n throw new Error('Failed to get bytes from data', { cause: error });\n }\n}\n\n/**\n * Hashes the given array of data using blake3 algorithm\n *\n * @param bytes - The desired output byte-length\n * @param data - The data to hash\n * @returns The resulting hash value\n */\nexport function getBytesFromDataArrayHex(bytes: number, data: Uint8Array[]): string {\n try {\n const hash = getBytesFromDataArray(bytes, data);\n return bytesToHex(hash);\n } catch (error) {\n throw new Error('Failed to get bytes from data', { cause: error });\n }\n}\n\n/**\n * Hashes the given string using blake3 algorithm\n *\n * @param bytes - The desired output byte-length\n * @param data - The data to hash\n * @returns The resulting hash value\n */\nexport function getBytesFromData(bytes: number, data: Uint8Array): Uint8Array {\n return blake3(data, { dkLen: bytes });\n}\n\n/**\n * Hashes the given data using blake3 algorithm\n *\n * @param bytes - The desired output byte-length\n * @param data - The data to hash\n * @returns The resulting hash value\n */\nexport function getBytesFromDataHex(bytes: number, data: Uint8Array): string {\n return bytesToHex(getBytesFromData(bytes, data));\n}\n","import { bytesToHex } from '@noble/hashes/utils.js';\nimport { AES_KEY_BIT_LENGTH } from '../constants';\nimport { getBytesFromData, hashDataArrayWithKey } from './blake3';\n\n/**\n * Computes mac for the given key material and data\n *\n * @param keyMaterial - The key material\n * @param data - The data to hash\n * @returns The resulting hash hex string\n */\nexport function computeMac(keyMaterial: Uint8Array, data: Uint8Array[]): string {\n try {\n const key = getBytesFromData(AES_KEY_BIT_LENGTH / 8, keyMaterial);\n const hash = hashDataArrayWithKey(key, data);\n return bytesToHex(hash);\n } catch (error) {\n throw new Error('Failed to compute mac', { cause: error });\n }\n}\n"],"mappings":";;;;;;;;;;;AASA,SAAgB,cAAc,MAAgC;AAC5D,KAAI;EACF,MAAM,SAAS,OAAO,QAAQ;AAC9B,OAAK,MAAM,KAAK,KACd,QAAO,OAAO,EAAE;AAElB,SAAO,OAAO,QAAQ;UACf,OAAO;AACd,QAAM,IAAI,MAAM,0BAA0B,EAAE,OAAO,OAAO,CAAC;;;;;;;;;AAU/D,SAAgB,iBAAiB,MAA4B;AAC3D,QAAO,WAAW,cAAc,KAAK,CAAC;;AAGxC,SAAgB,wBAAwB,SAAqB,MAA4B;AACvF,KAAI;AAEF,SAAO,WADM,qBAAqB,SAAS,KAAK,CACzB;UAChB,OAAO;AACd,QAAM,IAAI,MAAM,8BAA8B,EAAE,OAAO,OAAO,CAAC;;;AAInE,SAAgB,qBAAqB,SAAqB,MAAgC;AACxF,KAAI;EACF,MAAM,SAAS,OAAO,OAAO,EAAE,KAAK,SAAS,CAAC;AAC9C,OAAK,MAAM,KAAK,KACd,QAAO,OAAO,EAAE;AAElB,SAAO,OAAO,QAAQ;UACf,OAAO;AACd,QAAM,IAAI,MAAM,0BAA0B,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;AAW/D,SAAgB,sBAAsB,OAAe,MAAgC;AACnF,KAAI;EACF,MAAM,SAAS,OAAO,OAAO,EAAE,OAAO,OAAO,CAAC;AAC9C,OAAK,MAAM,SAAS,KAClB,QAAO,OAAO,MAAM;AAEtB,SAAO,OAAO,QAAQ;UACf,OAAO;AACd,QAAM,IAAI,MAAM,iCAAiC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;AAWtE,SAAgB,yBAAyB,OAAe,MAA4B;AAClF,KAAI;AAEF,SAAO,WADM,sBAAsB,OAAO,KAAK,CACxB;UAChB,OAAO;AACd,QAAM,IAAI,MAAM,iCAAiC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;AAWtE,SAAgB,iBAAiB,OAAe,MAA8B;AAC5E,QAAO,OAAO,MAAM,EAAE,OAAO,OAAO,CAAC;;;;;;;;;AAUvC,SAAgB,oBAAoB,OAAe,MAA0B;AAC3E,QAAO,WAAW,iBAAiB,OAAO,KAAK,CAAC;;;;;;;;;;;;AC/FlD,SAAgB,WAAW,aAAyB,MAA4B;AAC9E,KAAI;AAGF,SAAO,WADM,qBADD,iBAAiB,qBAAqB,GAAG,YAAY,EAC1B,KAAK,CACrB;UAChB,OAAO;AACd,QAAM,IAAI,MAAM,yBAAyB,EAAE,OAAO,OAAO,CAAC"}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import { n as encapsulateKyber, r as generateKyberKeys, t as decapsulateKyber } from "./kyber768-DzIcGg1i.mjs";
|
|
2
2
|
|
|
3
|
+
//#region src/post-quantum-crypto/kyber512.d.ts
|
|
4
|
+
declare namespace kyber512_d_exports {
|
|
5
|
+
export { decapsulateKyber$2 as decapsulateKyber, encapsulateKyber$2 as encapsulateKyber, generateKyberKeys$2 as generateKyberKeys };
|
|
6
|
+
}
|
|
3
7
|
/**
|
|
4
8
|
* Generates public and secret Kyber keys
|
|
5
9
|
*
|
|
6
10
|
* @param seed - The optional seed
|
|
7
11
|
* @returns The generated Kyber key pair.
|
|
8
12
|
*/
|
|
9
|
-
declare function generateKyberKeys$
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
declare function generateKyberKeys$2(seed?: Uint8Array): {
|
|
14
|
+
publicKey: Uint8Array;
|
|
15
|
+
secretKey: Uint8Array;
|
|
12
16
|
};
|
|
13
17
|
/**
|
|
14
18
|
* Generates a shared secret of 256-bits and encapsulates it to the given public key using Kyber algorithms
|
|
@@ -16,9 +20,9 @@ declare function generateKyberKeys$1(seed?: Uint8Array): {
|
|
|
16
20
|
* @param publicKey - The public Kyber key
|
|
17
21
|
* @returns The resulting encapsulation and the generated shared secret.
|
|
18
22
|
*/
|
|
19
|
-
declare function encapsulateKyber$
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
declare function encapsulateKyber$2(publicKey: Uint8Array): {
|
|
24
|
+
cipherText: Uint8Array;
|
|
25
|
+
sharedSecret: Uint8Array;
|
|
22
26
|
};
|
|
23
27
|
/**
|
|
24
28
|
* Decapsulates the encapsulated shared secret using Kyber algorithms
|
|
@@ -27,21 +31,19 @@ declare function encapsulateKyber$1(publicKey: Uint8Array): {
|
|
|
27
31
|
* @param secretKey - The private Kyber key
|
|
28
32
|
* @returns The resulting decapsulated shared secret.
|
|
29
33
|
*/
|
|
30
|
-
declare function decapsulateKyber$
|
|
31
|
-
|
|
32
|
-
declare namespace kyber512 {
|
|
34
|
+
declare function decapsulateKyber$2(cipherText: Uint8Array, secretKey: Uint8Array): Uint8Array;
|
|
35
|
+
declare namespace kyber1024_d_exports {
|
|
33
36
|
export { decapsulateKyber$1 as decapsulateKyber, encapsulateKyber$1 as encapsulateKyber, generateKyberKeys$1 as generateKyberKeys };
|
|
34
37
|
}
|
|
35
|
-
|
|
36
38
|
/**
|
|
37
39
|
* Generates public and secret Kyber keys
|
|
38
40
|
*
|
|
39
41
|
* @param seed - The optional seed
|
|
40
42
|
* @returns The generated Kyber key pair.
|
|
41
43
|
*/
|
|
42
|
-
declare function generateKyberKeys(seed?: Uint8Array): {
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
declare function generateKyberKeys$1(seed?: Uint8Array): {
|
|
45
|
+
publicKey: Uint8Array;
|
|
46
|
+
secretKey: Uint8Array;
|
|
45
47
|
};
|
|
46
48
|
/**
|
|
47
49
|
* Generates a shared secret of 256-bits and encapsulates it to the given public key using Kyber algorithms
|
|
@@ -49,9 +51,9 @@ declare function generateKyberKeys(seed?: Uint8Array): {
|
|
|
49
51
|
* @param publicKey - The public Kyber key
|
|
50
52
|
* @returns The resulting encapsulation and the generated shared secret.
|
|
51
53
|
*/
|
|
52
|
-
declare function encapsulateKyber(publicKey: Uint8Array): {
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
declare function encapsulateKyber$1(publicKey: Uint8Array): {
|
|
55
|
+
cipherText: Uint8Array;
|
|
56
|
+
sharedSecret: Uint8Array;
|
|
55
57
|
};
|
|
56
58
|
/**
|
|
57
59
|
* Decapsulates the encapsulated shared secret using Kyber algorithms
|
|
@@ -60,13 +62,7 @@ declare function encapsulateKyber(publicKey: Uint8Array): {
|
|
|
60
62
|
* @param secretKey - The private Kyber key
|
|
61
63
|
* @returns The resulting decapsulated shared secret.
|
|
62
64
|
*/
|
|
63
|
-
declare function decapsulateKyber(cipherText: Uint8Array, secretKey: Uint8Array): Uint8Array;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
declare const kyber1024_generateKyberKeys: typeof generateKyberKeys;
|
|
68
|
-
declare namespace kyber1024 {
|
|
69
|
-
export { kyber1024_decapsulateKyber as decapsulateKyber, kyber1024_encapsulateKyber as encapsulateKyber, kyber1024_generateKyberKeys as generateKyberKeys };
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export { kyber1024, kyber512 };
|
|
65
|
+
declare function decapsulateKyber$1(cipherText: Uint8Array, secretKey: Uint8Array): Uint8Array;
|
|
66
|
+
//#endregion
|
|
67
|
+
export { decapsulateKyber, encapsulateKyber, generateKyberKeys, kyber1024_d_exports as kyber1024, kyber512_d_exports as kyber512 };
|
|
68
|
+
//# sourceMappingURL=post-quantum-crypto.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"post-quantum-crypto.d.mts","names":[],"sources":["../src/post-quantum-crypto/kyber512.ts","../src/post-quantum-crypto/kyber1024.ts"],"mappings":";;;;;;;;;;;;iBAQgB,mBAAA,CAAkB,IAAA,GAAO,UAAA;EACvC,SAAA,EAAW,UAAA;EACX,SAAA,EAAW,UAAA;AAAA;;;;;;;iBAeG,kBAAA,CAAiB,SAAA,EAAW,UAAA;EAC1C,UAAA,EAAY,UAAA;EACZ,YAAA,EAAc,UAAA;AAAA;;;;;;AAFhB;;iBAkBgB,kBAAA,CAAiB,UAAA,EAAY,UAAA,EAAY,SAAA,EAAW,UAAA,GAAa,UAAA;AAAA;;;;;;;;;iBCnCjE,mBAAA,CAAkB,IAAA,GAAO,UAAA;EACvC,SAAA,EAAW,UAAA;EACX,SAAA,EAAW,UAAA;AAAA;;;;;;;iBAeG,kBAAA,CAAiB,SAAA,EAAW,UAAA;EAC1C,UAAA,EAAY,UAAA;EACZ,YAAA,EAAc,UAAA;AAAA;;;;;;ADFhB;;iBCkBgB,kBAAA,CAAiB,UAAA,EAAY,UAAA,EAAY,SAAA,EAAW,UAAA,GAAa,UAAA"}
|