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,90 @@
|
|
|
1
|
+
import { AES_KEY_BIT_LENGTH, ECC_ALGORITHM } from "./constants.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/asymmetric-crypto/ellipticCurve.ts
|
|
4
|
+
/**
|
|
5
|
+
* Derives secret key from the other user's public key and own private key
|
|
6
|
+
*
|
|
7
|
+
* @param otherUserPublicKey - The public key of the other user
|
|
8
|
+
* @param ownPrivateKey - The private key
|
|
9
|
+
* @returns The derived secret key bits
|
|
10
|
+
*/
|
|
11
|
+
async function deriveSecretKey(otherUserPublicKey, ownPrivateKey) {
|
|
12
|
+
try {
|
|
13
|
+
const result = await crypto.subtle.deriveBits({
|
|
14
|
+
name: ECC_ALGORITHM,
|
|
15
|
+
public: otherUserPublicKey
|
|
16
|
+
}, ownPrivateKey, AES_KEY_BIT_LENGTH);
|
|
17
|
+
return new Uint8Array(result);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
throw new Error("Failed to derive elliptic curve secret key", { cause: error });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/asymmetric-crypto/keys.ts
|
|
25
|
+
/**
|
|
26
|
+
* Generates elliptic curve key pair
|
|
27
|
+
*
|
|
28
|
+
* @returns The generated key pair
|
|
29
|
+
*/
|
|
30
|
+
async function generateEccKeys() {
|
|
31
|
+
try {
|
|
32
|
+
return await crypto.subtle.generateKey({ name: ECC_ALGORITHM }, true, ["deriveBits"]);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
throw new Error("Failed to generate elliptic curve key pair", { cause: error });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Converts public CryptoKey into Uint8Array using SubjectPublicKeyInfo format (RFC 5280)
|
|
39
|
+
*
|
|
40
|
+
* @returns The Uint8Array representation of the public key
|
|
41
|
+
*/
|
|
42
|
+
async function exportPublicKey(key) {
|
|
43
|
+
try {
|
|
44
|
+
const result = await crypto.subtle.exportKey("spki", key);
|
|
45
|
+
return new Uint8Array(result);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
throw new Error("Failed to export public key", { cause: error });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Converts public key in SubjectPublicKeyInfo format (RFC 5280) to CryptoKey
|
|
52
|
+
*
|
|
53
|
+
* @returns The CryptoKey representation of the public key
|
|
54
|
+
*/
|
|
55
|
+
async function importPublicKey(spkiKeyData) {
|
|
56
|
+
try {
|
|
57
|
+
return await crypto.subtle.importKey("spki", spkiKeyData, { name: ECC_ALGORITHM }, true, []);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
throw new Error("Failed to import public key", { cause: error });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Converts private key in CryptoKey to PKCS #8 format (RFC 5208)
|
|
64
|
+
*
|
|
65
|
+
* @returns The Uint8Array representation of the private key
|
|
66
|
+
*/
|
|
67
|
+
async function exportPrivateKey(key) {
|
|
68
|
+
try {
|
|
69
|
+
const result = await crypto.subtle.exportKey("pkcs8", key);
|
|
70
|
+
return new Uint8Array(result);
|
|
71
|
+
} catch (error) {
|
|
72
|
+
throw new Error("Failed to export private key", { cause: error });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Converts private key in PKCS #8 format (RFC 5208) to CryptoKey
|
|
77
|
+
*
|
|
78
|
+
* @returns The CryptoKey representation of the private key
|
|
79
|
+
*/
|
|
80
|
+
async function importPrivateKey(pkcs8KeyData) {
|
|
81
|
+
try {
|
|
82
|
+
return await crypto.subtle.importKey("pkcs8", pkcs8KeyData, { name: ECC_ALGORITHM }, true, ["deriveBits"]);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
throw new Error("Failed to import private key", { cause: error });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
export { importPublicKey as a, importPrivateKey as i, exportPublicKey as n, deriveSecretKey as o, generateEccKeys as r, exportPrivateKey as t };
|
|
90
|
+
//# sourceMappingURL=keys-BfcaiAOv.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys-BfcaiAOv.mjs","names":[],"sources":["../src/asymmetric-crypto/ellipticCurve.ts","../src/asymmetric-crypto/keys.ts"],"sourcesContent":["import { ECC_ALGORITHM, AES_KEY_BIT_LENGTH } from '../constants';\n\n/**\n * Derives secret key from the other user's public key and own private key\n *\n * @param otherUserPublicKey - The public key of the other user\n * @param ownPrivateKey - The private key\n * @returns The derived secret key bits\n */\nexport async function deriveSecretKey(otherUserPublicKey: CryptoKey, ownPrivateKey: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.deriveBits(\n {\n name: ECC_ALGORITHM,\n public: otherUserPublicKey,\n },\n ownPrivateKey,\n AES_KEY_BIT_LENGTH,\n );\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to derive elliptic curve secret key', { cause: error });\n }\n}\n","import { ECC_ALGORITHM } from '../constants';\n\n/**\n * Generates elliptic curve key pair\n *\n * @returns The generated key pair\n */\nexport async function generateEccKeys(): Promise<CryptoKeyPair> {\n try {\n return (await crypto.subtle.generateKey(\n {\n name: ECC_ALGORITHM,\n },\n true,\n ['deriveBits'],\n )) as CryptoKeyPair;\n } catch (error) {\n throw new Error('Failed to generate elliptic curve key pair', { cause: error });\n }\n}\n\n/**\n * Converts public CryptoKey into Uint8Array using SubjectPublicKeyInfo format (RFC 5280)\n *\n * @returns The Uint8Array representation of the public key\n */\nexport async function exportPublicKey(key: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.exportKey('spki', key);\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to export public key', { cause: error });\n }\n}\n\n/**\n * Converts public key in SubjectPublicKeyInfo format (RFC 5280) to CryptoKey\n *\n * @returns The CryptoKey representation of the public key\n */\nexport async function importPublicKey(spkiKeyData: Uint8Array): Promise<CryptoKey> {\n try {\n return await crypto.subtle.importKey(\n 'spki',\n spkiKeyData as BufferSource,\n {\n name: ECC_ALGORITHM,\n },\n true,\n [],\n );\n } catch (error) {\n throw new Error('Failed to import public key', { cause: error });\n }\n}\n\n/**\n * Converts private key in CryptoKey to PKCS #8 format (RFC 5208)\n *\n * @returns The Uint8Array representation of the private key\n */\nexport async function exportPrivateKey(key: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.exportKey('pkcs8', key);\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to export private key', { cause: error });\n }\n}\n\n/**\n * Converts private key in PKCS #8 format (RFC 5208) to CryptoKey\n *\n * @returns The CryptoKey representation of the private key\n */\nexport async function importPrivateKey(pkcs8KeyData: Uint8Array): Promise<CryptoKey> {\n try {\n return await crypto.subtle.importKey(\n 'pkcs8',\n pkcs8KeyData as BufferSource,\n {\n name: ECC_ALGORITHM,\n },\n true,\n ['deriveBits'],\n );\n } catch (error) {\n throw new Error('Failed to import private key', { cause: error });\n }\n}\n"],"mappings":";;;;;;;;;;AASA,eAAsB,gBAAgB,oBAA+B,eAA+C;AAClH,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,WACjC;GACE,MAAM;GACN,QAAQ;GACT,EACD,eACA,mBACD;AACD,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,8CAA8C,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;ACdnF,eAAsB,kBAA0C;AAC9D,KAAI;AACF,SAAQ,MAAM,OAAO,OAAO,YAC1B,EACE,MAAM,eACP,EACD,MACA,CAAC,aAAa,CACf;UACM,OAAO;AACd,QAAM,IAAI,MAAM,8CAA8C,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASnF,eAAsB,gBAAgB,KAAqC;AACzE,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,UAAU,QAAQ,IAAI;AACzD,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,+BAA+B,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASpE,eAAsB,gBAAgB,aAA6C;AACjF,KAAI;AACF,SAAO,MAAM,OAAO,OAAO,UACzB,QACA,aACA,EACE,MAAM,eACP,EACD,MACA,EAAE,CACH;UACM,OAAO;AACd,QAAM,IAAI,MAAM,+BAA+B,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASpE,eAAsB,iBAAiB,KAAqC;AAC1E,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,UAAU,SAAS,IAAI;AAC1D,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,gCAAgC,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASrE,eAAsB,iBAAiB,cAA8C;AACnF,KAAI;AACF,SAAO,MAAM,OAAO,OAAO,UACzB,SACA,cACA,EACE,MAAM,eACP,EACD,MACA,CAAC,aAAa,CACf;UACM,OAAO;AACd,QAAM,IAAI,MAAM,gCAAgC,EAAE,OAAO,OAAO,CAAC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
const require_constants = require('./constants.js');
|
|
2
|
+
|
|
3
|
+
//#region src/asymmetric-crypto/ellipticCurve.ts
|
|
4
|
+
/**
|
|
5
|
+
* Derives secret key from the other user's public key and own private key
|
|
6
|
+
*
|
|
7
|
+
* @param otherUserPublicKey - The public key of the other user
|
|
8
|
+
* @param ownPrivateKey - The private key
|
|
9
|
+
* @returns The derived secret key bits
|
|
10
|
+
*/
|
|
11
|
+
async function deriveSecretKey(otherUserPublicKey, ownPrivateKey) {
|
|
12
|
+
try {
|
|
13
|
+
const result = await crypto.subtle.deriveBits({
|
|
14
|
+
name: require_constants.ECC_ALGORITHM,
|
|
15
|
+
public: otherUserPublicKey
|
|
16
|
+
}, ownPrivateKey, require_constants.AES_KEY_BIT_LENGTH);
|
|
17
|
+
return new Uint8Array(result);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
throw new Error("Failed to derive elliptic curve secret key", { cause: error });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/asymmetric-crypto/keys.ts
|
|
25
|
+
/**
|
|
26
|
+
* Generates elliptic curve key pair
|
|
27
|
+
*
|
|
28
|
+
* @returns The generated key pair
|
|
29
|
+
*/
|
|
30
|
+
async function generateEccKeys() {
|
|
31
|
+
try {
|
|
32
|
+
return await crypto.subtle.generateKey({ name: require_constants.ECC_ALGORITHM }, true, ["deriveBits"]);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
throw new Error("Failed to generate elliptic curve key pair", { cause: error });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Converts public CryptoKey into Uint8Array using SubjectPublicKeyInfo format (RFC 5280)
|
|
39
|
+
*
|
|
40
|
+
* @returns The Uint8Array representation of the public key
|
|
41
|
+
*/
|
|
42
|
+
async function exportPublicKey(key) {
|
|
43
|
+
try {
|
|
44
|
+
const result = await crypto.subtle.exportKey("spki", key);
|
|
45
|
+
return new Uint8Array(result);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
throw new Error("Failed to export public key", { cause: error });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Converts public key in SubjectPublicKeyInfo format (RFC 5280) to CryptoKey
|
|
52
|
+
*
|
|
53
|
+
* @returns The CryptoKey representation of the public key
|
|
54
|
+
*/
|
|
55
|
+
async function importPublicKey(spkiKeyData) {
|
|
56
|
+
try {
|
|
57
|
+
return await crypto.subtle.importKey("spki", spkiKeyData, { name: require_constants.ECC_ALGORITHM }, true, []);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
throw new Error("Failed to import public key", { cause: error });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Converts private key in CryptoKey to PKCS #8 format (RFC 5208)
|
|
64
|
+
*
|
|
65
|
+
* @returns The Uint8Array representation of the private key
|
|
66
|
+
*/
|
|
67
|
+
async function exportPrivateKey(key) {
|
|
68
|
+
try {
|
|
69
|
+
const result = await crypto.subtle.exportKey("pkcs8", key);
|
|
70
|
+
return new Uint8Array(result);
|
|
71
|
+
} catch (error) {
|
|
72
|
+
throw new Error("Failed to export private key", { cause: error });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Converts private key in PKCS #8 format (RFC 5208) to CryptoKey
|
|
77
|
+
*
|
|
78
|
+
* @returns The CryptoKey representation of the private key
|
|
79
|
+
*/
|
|
80
|
+
async function importPrivateKey(pkcs8KeyData) {
|
|
81
|
+
try {
|
|
82
|
+
return await crypto.subtle.importKey("pkcs8", pkcs8KeyData, { name: require_constants.ECC_ALGORITHM }, true, ["deriveBits"]);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
throw new Error("Failed to import private key", { cause: error });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
Object.defineProperty(exports, 'deriveSecretKey', {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
get: function () {
|
|
92
|
+
return deriveSecretKey;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
Object.defineProperty(exports, 'exportPrivateKey', {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
get: function () {
|
|
98
|
+
return exportPrivateKey;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
Object.defineProperty(exports, 'exportPublicKey', {
|
|
102
|
+
enumerable: true,
|
|
103
|
+
get: function () {
|
|
104
|
+
return exportPublicKey;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
Object.defineProperty(exports, 'generateEccKeys', {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
get: function () {
|
|
110
|
+
return generateEccKeys;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
Object.defineProperty(exports, 'importPrivateKey', {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
get: function () {
|
|
116
|
+
return importPrivateKey;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
Object.defineProperty(exports, 'importPublicKey', {
|
|
120
|
+
enumerable: true,
|
|
121
|
+
get: function () {
|
|
122
|
+
return importPublicKey;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
//# sourceMappingURL=keys-CinT7kEY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys-CinT7kEY.js","names":["ECC_ALGORITHM","AES_KEY_BIT_LENGTH","ECC_ALGORITHM"],"sources":["../src/asymmetric-crypto/ellipticCurve.ts","../src/asymmetric-crypto/keys.ts"],"sourcesContent":["import { ECC_ALGORITHM, AES_KEY_BIT_LENGTH } from '../constants';\n\n/**\n * Derives secret key from the other user's public key and own private key\n *\n * @param otherUserPublicKey - The public key of the other user\n * @param ownPrivateKey - The private key\n * @returns The derived secret key bits\n */\nexport async function deriveSecretKey(otherUserPublicKey: CryptoKey, ownPrivateKey: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.deriveBits(\n {\n name: ECC_ALGORITHM,\n public: otherUserPublicKey,\n },\n ownPrivateKey,\n AES_KEY_BIT_LENGTH,\n );\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to derive elliptic curve secret key', { cause: error });\n }\n}\n","import { ECC_ALGORITHM } from '../constants';\n\n/**\n * Generates elliptic curve key pair\n *\n * @returns The generated key pair\n */\nexport async function generateEccKeys(): Promise<CryptoKeyPair> {\n try {\n return (await crypto.subtle.generateKey(\n {\n name: ECC_ALGORITHM,\n },\n true,\n ['deriveBits'],\n )) as CryptoKeyPair;\n } catch (error) {\n throw new Error('Failed to generate elliptic curve key pair', { cause: error });\n }\n}\n\n/**\n * Converts public CryptoKey into Uint8Array using SubjectPublicKeyInfo format (RFC 5280)\n *\n * @returns The Uint8Array representation of the public key\n */\nexport async function exportPublicKey(key: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.exportKey('spki', key);\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to export public key', { cause: error });\n }\n}\n\n/**\n * Converts public key in SubjectPublicKeyInfo format (RFC 5280) to CryptoKey\n *\n * @returns The CryptoKey representation of the public key\n */\nexport async function importPublicKey(spkiKeyData: Uint8Array): Promise<CryptoKey> {\n try {\n return await crypto.subtle.importKey(\n 'spki',\n spkiKeyData as BufferSource,\n {\n name: ECC_ALGORITHM,\n },\n true,\n [],\n );\n } catch (error) {\n throw new Error('Failed to import public key', { cause: error });\n }\n}\n\n/**\n * Converts private key in CryptoKey to PKCS #8 format (RFC 5208)\n *\n * @returns The Uint8Array representation of the private key\n */\nexport async function exportPrivateKey(key: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.exportKey('pkcs8', key);\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to export private key', { cause: error });\n }\n}\n\n/**\n * Converts private key in PKCS #8 format (RFC 5208) to CryptoKey\n *\n * @returns The CryptoKey representation of the private key\n */\nexport async function importPrivateKey(pkcs8KeyData: Uint8Array): Promise<CryptoKey> {\n try {\n return await crypto.subtle.importKey(\n 'pkcs8',\n pkcs8KeyData as BufferSource,\n {\n name: ECC_ALGORITHM,\n },\n true,\n ['deriveBits'],\n );\n } catch (error) {\n throw new Error('Failed to import private key', { cause: error });\n }\n}\n"],"mappings":";;;;;;;;;;AASA,eAAsB,gBAAgB,oBAA+B,eAA+C;AAClH,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,WACjC;GACE,MAAMA;GACN,QAAQ;GACT,EACD,eACAC,qCACD;AACD,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,8CAA8C,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;ACdnF,eAAsB,kBAA0C;AAC9D,KAAI;AACF,SAAQ,MAAM,OAAO,OAAO,YAC1B,EACE,MAAMC,iCACP,EACD,MACA,CAAC,aAAa,CACf;UACM,OAAO;AACd,QAAM,IAAI,MAAM,8CAA8C,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASnF,eAAsB,gBAAgB,KAAqC;AACzE,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,UAAU,QAAQ,IAAI;AACzD,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,+BAA+B,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASpE,eAAsB,gBAAgB,aAA6C;AACjF,KAAI;AACF,SAAO,MAAM,OAAO,OAAO,UACzB,QACA,aACA,EACE,MAAMA,iCACP,EACD,MACA,EAAE,CACH;UACM,OAAO;AACd,QAAM,IAAI,MAAM,+BAA+B,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASpE,eAAsB,iBAAiB,KAAqC;AAC1E,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,UAAU,SAAS,IAAI;AAC1D,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,gCAAgC,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASrE,eAAsB,iBAAiB,cAA8C;AACnF,KAAI;AACF,SAAO,MAAM,OAAO,OAAO,UACzB,SACA,cACA,EACE,MAAMA,iCACP,EACD,MACA,CAAC,aAAa,CACf;UACM,OAAO;AACd,QAAM,IAAI,MAAM,gCAAgC,EAAE,OAAO,OAAO,CAAC"}
|
|
@@ -1,36 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EmailKeys, EncryptedKeystore } from "./types.mjs";
|
|
2
2
|
|
|
3
|
+
//#region src/keystore-crypto/emailEncryptionKey.d.ts
|
|
3
4
|
/**
|
|
4
|
-
* Generates recovery
|
|
5
|
+
* Generates email keys and creates encrypted main and recovery keystores
|
|
6
|
+
* The main keystore encryption key is derived from the base key (stored in session storage)
|
|
7
|
+
* The recovery keystore encryption key is derived from the recovery codes
|
|
5
8
|
*
|
|
6
|
-
* @returns The
|
|
9
|
+
* @returns The encryption and recovery keystores, recovery codes and email keys
|
|
7
10
|
*/
|
|
8
|
-
declare function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*/
|
|
14
|
-
declare function generateEncryptionKeys(): Promise<EncryptionKeys>;
|
|
15
|
-
/**
|
|
16
|
-
* Generates email encryption keys and creates encrypted encryption and recovery keystores
|
|
17
|
-
* The encryption key is derived from the base key (stored in session storage)
|
|
18
|
-
*
|
|
19
|
-
* @returns The encryption and recovery keystores
|
|
20
|
-
*/
|
|
21
|
-
declare function createEncryptionAndRecoveryKeystores(): Promise<{
|
|
22
|
-
encryptionKeystore: EncryptedKeystore;
|
|
23
|
-
recoveryKeystore: EncryptedKeystore;
|
|
24
|
-
recoveryCodes: string;
|
|
11
|
+
declare function createEncryptionAndRecoveryKeystores(userEmail: string, baseKey: Uint8Array): Promise<{
|
|
12
|
+
encryptionKeystore: EncryptedKeystore;
|
|
13
|
+
recoveryKeystore: EncryptedKeystore;
|
|
14
|
+
recoveryCodes: string;
|
|
15
|
+
keys: EmailKeys;
|
|
25
16
|
}>;
|
|
26
17
|
/**
|
|
27
18
|
* Opens the encryption keystore and returns the email encryption keys
|
|
28
19
|
* The decryption key is derived from the base key (stored in session storage)
|
|
29
20
|
*
|
|
30
21
|
* @param encryptedKeystore - The encrypted keystore containing encryption keys
|
|
22
|
+
* @param baseKey - The base key from which the decryption key will be derived
|
|
31
23
|
* @returns The encryption keys
|
|
32
24
|
*/
|
|
33
|
-
declare function openEncryptionKeystore(encryptedKeystore: EncryptedKeystore): Promise<
|
|
25
|
+
declare function openEncryptionKeystore(encryptedKeystore: EncryptedKeystore, baseKey: Uint8Array): Promise<EmailKeys>;
|
|
34
26
|
/**
|
|
35
27
|
* Opens the recovery keystore and returns the email encryption keys
|
|
36
28
|
* The decryption key is derived from the base key (stored in session storage)
|
|
@@ -39,28 +31,7 @@ declare function openEncryptionKeystore(encryptedKeystore: EncryptedKeystore): P
|
|
|
39
31
|
* @param encryptedKeystore - The encrypted keystore containing encryption keys
|
|
40
32
|
* @returns The encryption keys
|
|
41
33
|
*/
|
|
42
|
-
declare function openRecoveryKeystore(recoveryCodes: string, encryptedKeystore: EncryptedKeystore): Promise<
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
*
|
|
47
|
-
* @returns The user identity keys
|
|
48
|
-
*/
|
|
49
|
-
declare function generateIdentityKeys(): Promise<IdentityKeys>;
|
|
50
|
-
/**
|
|
51
|
-
* Generates user identity keys and creates an encrypted identity keystore
|
|
52
|
-
* The encryption key is derived from the base key (stored in session storage)
|
|
53
|
-
*
|
|
54
|
-
* @returns The encrypted idenity keystore
|
|
55
|
-
*/
|
|
56
|
-
declare function createIdentityKeystore(): Promise<EncryptedKeystore>;
|
|
57
|
-
/**
|
|
58
|
-
* Opens the encrypted identity keystore
|
|
59
|
-
* The decryption key is derived from the base key (stored in session storage)
|
|
60
|
-
*
|
|
61
|
-
* @param encryptedKeystore - The encrypted identity keystore
|
|
62
|
-
* @returns The identity keys
|
|
63
|
-
*/
|
|
64
|
-
declare function openIdentityKeystore(encryptedKeystore: EncryptedKeystore): Promise<IdentityKeys>;
|
|
65
|
-
|
|
66
|
-
export { createEncryptionAndRecoveryKeystores, createIdentityKeystore, generateEncryptionKeys, generateIdentityKeys, generateRecoveryCodes, openEncryptionKeystore, openIdentityKeystore, openRecoveryKeystore };
|
|
34
|
+
declare function openRecoveryKeystore(recoveryCodes: string, encryptedKeystore: EncryptedKeystore): Promise<EmailKeys>;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { createEncryptionAndRecoveryKeystores, openEncryptionKeystore, openRecoveryKeystore };
|
|
37
|
+
//# sourceMappingURL=keystore-crypto.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keystore-crypto.d.mts","names":[],"sources":["../src/keystore-crypto/emailEncryptionKey.ts"],"mappings":";;;;;AAYA;;;;;iBAAsB,oCAAA,CACpB,SAAA,UACA,OAAA,EAAS,UAAA,GACR,OAAA;EACD,kBAAA,EAAoB,iBAAA;EACpB,gBAAA,EAAkB,iBAAA;EAClB,aAAA;EACA,IAAA,EAAM,SAAA;AAAA;;;;;;;;;iBA0Bc,sBAAA,CACpB,iBAAA,EAAmB,iBAAA,EACnB,OAAA,EAAS,UAAA,GACR,OAAA,CAAQ,SAAA;;;;AAHX;;;;;iBAwBsB,oBAAA,CACpB,aAAA,UACA,iBAAA,EAAmB,iBAAA,GAClB,OAAA,CAAQ,SAAA"}
|
|
@@ -1,36 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EmailKeys, EncryptedKeystore } from "./types.js";
|
|
2
2
|
|
|
3
|
+
//#region src/keystore-crypto/emailEncryptionKey.d.ts
|
|
3
4
|
/**
|
|
4
|
-
* Generates recovery
|
|
5
|
+
* Generates email keys and creates encrypted main and recovery keystores
|
|
6
|
+
* The main keystore encryption key is derived from the base key (stored in session storage)
|
|
7
|
+
* The recovery keystore encryption key is derived from the recovery codes
|
|
5
8
|
*
|
|
6
|
-
* @returns The
|
|
9
|
+
* @returns The encryption and recovery keystores, recovery codes and email keys
|
|
7
10
|
*/
|
|
8
|
-
declare function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*/
|
|
14
|
-
declare function generateEncryptionKeys(): Promise<EncryptionKeys>;
|
|
15
|
-
/**
|
|
16
|
-
* Generates email encryption keys and creates encrypted encryption and recovery keystores
|
|
17
|
-
* The encryption key is derived from the base key (stored in session storage)
|
|
18
|
-
*
|
|
19
|
-
* @returns The encryption and recovery keystores
|
|
20
|
-
*/
|
|
21
|
-
declare function createEncryptionAndRecoveryKeystores(): Promise<{
|
|
22
|
-
encryptionKeystore: EncryptedKeystore;
|
|
23
|
-
recoveryKeystore: EncryptedKeystore;
|
|
24
|
-
recoveryCodes: string;
|
|
11
|
+
declare function createEncryptionAndRecoveryKeystores(userEmail: string, baseKey: Uint8Array): Promise<{
|
|
12
|
+
encryptionKeystore: EncryptedKeystore;
|
|
13
|
+
recoveryKeystore: EncryptedKeystore;
|
|
14
|
+
recoveryCodes: string;
|
|
15
|
+
keys: EmailKeys;
|
|
25
16
|
}>;
|
|
26
17
|
/**
|
|
27
18
|
* Opens the encryption keystore and returns the email encryption keys
|
|
28
19
|
* The decryption key is derived from the base key (stored in session storage)
|
|
29
20
|
*
|
|
30
21
|
* @param encryptedKeystore - The encrypted keystore containing encryption keys
|
|
22
|
+
* @param baseKey - The base key from which the decryption key will be derived
|
|
31
23
|
* @returns The encryption keys
|
|
32
24
|
*/
|
|
33
|
-
declare function openEncryptionKeystore(encryptedKeystore: EncryptedKeystore): Promise<
|
|
25
|
+
declare function openEncryptionKeystore(encryptedKeystore: EncryptedKeystore, baseKey: Uint8Array): Promise<EmailKeys>;
|
|
34
26
|
/**
|
|
35
27
|
* Opens the recovery keystore and returns the email encryption keys
|
|
36
28
|
* The decryption key is derived from the base key (stored in session storage)
|
|
@@ -39,28 +31,7 @@ declare function openEncryptionKeystore(encryptedKeystore: EncryptedKeystore): P
|
|
|
39
31
|
* @param encryptedKeystore - The encrypted keystore containing encryption keys
|
|
40
32
|
* @returns The encryption keys
|
|
41
33
|
*/
|
|
42
|
-
declare function openRecoveryKeystore(recoveryCodes: string, encryptedKeystore: EncryptedKeystore): Promise<
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
*
|
|
47
|
-
* @returns The user identity keys
|
|
48
|
-
*/
|
|
49
|
-
declare function generateIdentityKeys(): Promise<IdentityKeys>;
|
|
50
|
-
/**
|
|
51
|
-
* Generates user identity keys and creates an encrypted identity keystore
|
|
52
|
-
* The encryption key is derived from the base key (stored in session storage)
|
|
53
|
-
*
|
|
54
|
-
* @returns The encrypted idenity keystore
|
|
55
|
-
*/
|
|
56
|
-
declare function createIdentityKeystore(): Promise<EncryptedKeystore>;
|
|
57
|
-
/**
|
|
58
|
-
* Opens the encrypted identity keystore
|
|
59
|
-
* The decryption key is derived from the base key (stored in session storage)
|
|
60
|
-
*
|
|
61
|
-
* @param encryptedKeystore - The encrypted identity keystore
|
|
62
|
-
* @returns The identity keys
|
|
63
|
-
*/
|
|
64
|
-
declare function openIdentityKeystore(encryptedKeystore: EncryptedKeystore): Promise<IdentityKeys>;
|
|
65
|
-
|
|
66
|
-
export { createEncryptionAndRecoveryKeystores, createIdentityKeystore, generateEncryptionKeys, generateIdentityKeys, generateRecoveryCodes, openEncryptionKeystore, openIdentityKeystore, openRecoveryKeystore };
|
|
34
|
+
declare function openRecoveryKeystore(recoveryCodes: string, encryptedKeystore: EncryptedKeystore): Promise<EmailKeys>;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { createEncryptionAndRecoveryKeystores, openEncryptionKeystore, openRecoveryKeystore };
|
|
37
|
+
//# sourceMappingURL=keystore-crypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keystore-crypto.d.ts","names":[],"sources":["../src/keystore-crypto/emailEncryptionKey.ts"],"mappings":";;;;;AAYA;;;;;iBAAsB,oCAAA,CACpB,SAAA,UACA,OAAA,EAAS,UAAA,GACR,OAAA;EACD,kBAAA,EAAoB,iBAAA;EACpB,gBAAA,EAAkB,iBAAA;EAClB,aAAA;EACA,IAAA,EAAM,SAAA;AAAA;;;;;;;;;iBA0Bc,sBAAA,CACpB,iBAAA,EAAmB,iBAAA,EACnB,OAAA,EAAS,UAAA,GACR,OAAA,CAAQ,SAAA;;;;AAHX;;;;;iBAwBsB,oBAAA,CACpB,aAAA,UACA,iBAAA,EAAmB,iBAAA,GAClB,OAAA,CAAQ,SAAA"}
|