internxt-crypto 0.0.8-alpha → 0.0.10-alpha
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 +0 -2
- package/dist/asymmetric-crypto.d.mts +41 -0
- package/dist/asymmetric-crypto.d.ts +41 -0
- package/dist/asymmetric-crypto.js +92 -0
- package/dist/asymmetric-crypto.js.map +1 -0
- package/dist/asymmetric-crypto.mjs +85 -0
- package/dist/asymmetric-crypto.mjs.map +1 -0
- package/dist/constants.d.mts +39 -0
- package/dist/constants.d.ts +39 -0
- package/dist/constants.js +80 -0
- package/dist/constants.js.map +1 -0
- package/dist/constants.mjs +42 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/derive-key.d.mts +91 -0
- package/dist/derive-key.d.ts +91 -0
- package/dist/derive-key.js +795 -0
- package/dist/derive-key.js.map +1 -0
- package/dist/derive-key.mjs +784 -0
- package/dist/derive-key.mjs.map +1 -0
- package/dist/email-crypto.d.mts +106 -0
- package/dist/email-crypto.d.ts +106 -0
- package/dist/email-crypto.js +1409 -0
- package/dist/email-crypto.js.map +1 -0
- package/dist/email-crypto.mjs +1381 -0
- package/dist/email-crypto.mjs.map +1 -0
- package/dist/email-search.d.mts +228 -0
- package/dist/email-search.d.ts +228 -0
- package/dist/email-search.js +605 -0
- package/dist/email-search.js.map +1 -0
- package/dist/email-search.mjs +580 -0
- package/dist/email-search.mjs.map +1 -0
- package/dist/email-service.d.mts +38 -0
- package/dist/email-service.d.ts +38 -0
- package/dist/email-service.js +154 -0
- package/dist/email-service.js.map +1 -0
- package/dist/email-service.mjs +147 -0
- package/dist/email-service.mjs.map +1 -0
- package/dist/hash.d.mts +59 -0
- package/dist/hash.d.ts +59 -0
- package/dist/hash.js +95 -0
- package/dist/hash.js.map +1 -0
- package/dist/hash.mjs +85 -0
- package/dist/hash.mjs.map +1 -0
- package/dist/index.d.mts +35 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +2697 -2054
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2138 -8187
- package/dist/index.mjs.map +1 -1
- package/dist/keystore-crypto.d.mts +66 -0
- package/dist/keystore-crypto.d.ts +66 -0
- package/dist/keystore-crypto.js +530 -0
- package/dist/keystore-crypto.js.map +1 -0
- package/dist/keystore-crypto.mjs +501 -0
- package/dist/keystore-crypto.mjs.map +1 -0
- package/dist/keystore-service.d.mts +82 -0
- package/dist/keystore-service.d.ts +82 -0
- package/dist/keystore-service.js +349 -0
- package/dist/keystore-service.js.map +1 -0
- package/dist/keystore-service.mjs +342 -0
- package/dist/keystore-service.mjs.map +1 -0
- package/dist/kyber768-B87rMQ7u.d.mts +30 -0
- package/dist/kyber768-B87rMQ7u.d.ts +30 -0
- package/dist/post-quantum-crypto.d.mts +72 -0
- package/dist/post-quantum-crypto.d.ts +72 -0
- package/dist/post-quantum-crypto.js +96 -0
- package/dist/post-quantum-crypto.js.map +1 -0
- package/dist/post-quantum-crypto.mjs +90 -0
- package/dist/post-quantum-crypto.mjs.map +1 -0
- package/dist/storage-service.d.mts +53 -0
- package/dist/storage-service.d.ts +53 -0
- package/dist/storage-service.js +70 -0
- package/dist/storage-service.js.map +1 -0
- package/dist/storage-service.mjs +67 -0
- package/dist/storage-service.mjs.map +1 -0
- package/dist/symmetric-crypto.d.mts +56 -0
- package/dist/symmetric-crypto.d.ts +56 -0
- package/dist/symmetric-crypto.js +142 -0
- package/dist/symmetric-crypto.js.map +1 -0
- package/dist/symmetric-crypto.mjs +134 -0
- package/dist/symmetric-crypto.mjs.map +1 -0
- package/dist/types.d.mts +102 -0
- package/dist/types.d.ts +102 -0
- package/dist/types.js +14 -0
- package/dist/types.js.map +1 -0
- package/dist/types.mjs +12 -0
- package/dist/types.mjs.map +1 -0
- package/dist/utils-BDaK_d6T.d.ts +114 -0
- package/dist/utils-v34IRTIx.d.mts +114 -0
- package/dist/utils.d.mts +140 -0
- package/dist/utils.d.ts +140 -0
- package/dist/utils.js +313 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.mjs +273 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +83 -7
- package/dist/__vite-browser-external-Dyvby5gX.js +0 -2
- package/dist/__vite-browser-external-Dyvby5gX.js.map +0 -1
- package/dist/__vite-browser-external-l0sNRNKZ.mjs +0 -2
- package/dist/__vite-browser-external-l0sNRNKZ.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -124,13 +124,11 @@ const emailBody: EmailBody = {
|
|
|
124
124
|
const userAlice = {
|
|
125
125
|
email: 'alice email',
|
|
126
126
|
name: 'alice',
|
|
127
|
-
id: '1',
|
|
128
127
|
};
|
|
129
128
|
|
|
130
129
|
const userBob = {
|
|
131
130
|
email: 'bob email',
|
|
132
131
|
name: 'bob',
|
|
133
|
-
id: '2',
|
|
134
132
|
};
|
|
135
133
|
const { privateKeys: alicePrivateKeys, publicKeys: alicePublicKeys } = await emailCrypto.generateEmailKeys();
|
|
136
134
|
const { privateKeys: bobPrivateKeys, publicKeys: bobPublicKeys } = await emailCrypto.generateEmailKeys();
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derives secret key from the other user's public key and own private key
|
|
3
|
+
*
|
|
4
|
+
* @param otherUserPublicKey - The public key of the other user
|
|
5
|
+
* @param ownPrivateKey - The private key
|
|
6
|
+
* @returns The derived secret key bits
|
|
7
|
+
*/
|
|
8
|
+
declare function deriveSecretKey(otherUserPublicKey: CryptoKey, ownPrivateKey: CryptoKey): Promise<Uint8Array>;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Generates elliptic curve key pair
|
|
12
|
+
*
|
|
13
|
+
* @returns The generated key pair
|
|
14
|
+
*/
|
|
15
|
+
declare function generateEccKeys(): Promise<CryptoKeyPair>;
|
|
16
|
+
/**
|
|
17
|
+
* Converts public CryptoKey into Uint8Array using SubjectPublicKeyInfo format (RFC 5280)
|
|
18
|
+
*
|
|
19
|
+
* @returns The Uint8Array representation of the public key
|
|
20
|
+
*/
|
|
21
|
+
declare function exportPublicKey(key: CryptoKey): Promise<Uint8Array>;
|
|
22
|
+
/**
|
|
23
|
+
* Converts public key in SubjectPublicKeyInfo format (RFC 5280) to CryptoKey
|
|
24
|
+
*
|
|
25
|
+
* @returns The CryptoKey representation of the public key
|
|
26
|
+
*/
|
|
27
|
+
declare function importPublicKey(spkiKeyData: Uint8Array): Promise<CryptoKey>;
|
|
28
|
+
/**
|
|
29
|
+
* Converts private key in CryptoKey to PKCS #8 format (RFC 5208)
|
|
30
|
+
*
|
|
31
|
+
* @returns The Uint8Array representation of the private key
|
|
32
|
+
*/
|
|
33
|
+
declare function exportPrivateKey(key: CryptoKey): Promise<Uint8Array>;
|
|
34
|
+
/**
|
|
35
|
+
* Converts private key in PKCS #8 format (RFC 5208) to CryptoKey
|
|
36
|
+
*
|
|
37
|
+
* @returns The CryptoKey representation of the private key
|
|
38
|
+
*/
|
|
39
|
+
declare function importPrivateKey(pkcs8KeyData: Uint8Array): Promise<CryptoKey>;
|
|
40
|
+
|
|
41
|
+
export { deriveSecretKey, exportPrivateKey, exportPublicKey, generateEccKeys, importPrivateKey, importPublicKey };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derives secret key from the other user's public key and own private key
|
|
3
|
+
*
|
|
4
|
+
* @param otherUserPublicKey - The public key of the other user
|
|
5
|
+
* @param ownPrivateKey - The private key
|
|
6
|
+
* @returns The derived secret key bits
|
|
7
|
+
*/
|
|
8
|
+
declare function deriveSecretKey(otherUserPublicKey: CryptoKey, ownPrivateKey: CryptoKey): Promise<Uint8Array>;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Generates elliptic curve key pair
|
|
12
|
+
*
|
|
13
|
+
* @returns The generated key pair
|
|
14
|
+
*/
|
|
15
|
+
declare function generateEccKeys(): Promise<CryptoKeyPair>;
|
|
16
|
+
/**
|
|
17
|
+
* Converts public CryptoKey into Uint8Array using SubjectPublicKeyInfo format (RFC 5280)
|
|
18
|
+
*
|
|
19
|
+
* @returns The Uint8Array representation of the public key
|
|
20
|
+
*/
|
|
21
|
+
declare function exportPublicKey(key: CryptoKey): Promise<Uint8Array>;
|
|
22
|
+
/**
|
|
23
|
+
* Converts public key in SubjectPublicKeyInfo format (RFC 5280) to CryptoKey
|
|
24
|
+
*
|
|
25
|
+
* @returns The CryptoKey representation of the public key
|
|
26
|
+
*/
|
|
27
|
+
declare function importPublicKey(spkiKeyData: Uint8Array): Promise<CryptoKey>;
|
|
28
|
+
/**
|
|
29
|
+
* Converts private key in CryptoKey to PKCS #8 format (RFC 5208)
|
|
30
|
+
*
|
|
31
|
+
* @returns The Uint8Array representation of the private key
|
|
32
|
+
*/
|
|
33
|
+
declare function exportPrivateKey(key: CryptoKey): Promise<Uint8Array>;
|
|
34
|
+
/**
|
|
35
|
+
* Converts private key in PKCS #8 format (RFC 5208) to CryptoKey
|
|
36
|
+
*
|
|
37
|
+
* @returns The CryptoKey representation of the private key
|
|
38
|
+
*/
|
|
39
|
+
declare function importPrivateKey(pkcs8KeyData: Uint8Array): Promise<CryptoKey>;
|
|
40
|
+
|
|
41
|
+
export { deriveSecretKey, exportPrivateKey, exportPublicKey, generateEccKeys, importPrivateKey, importPublicKey };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/constants.ts
|
|
4
|
+
var AES_KEY_BIT_LENGTH = 256;
|
|
5
|
+
var ECC_ALGORITHM = "X25519";
|
|
6
|
+
|
|
7
|
+
// src/asymmetric-crypto/ellipticCurve.ts
|
|
8
|
+
async function deriveSecretKey(otherUserPublicKey, ownPrivateKey) {
|
|
9
|
+
try {
|
|
10
|
+
const result = await crypto.subtle.deriveBits(
|
|
11
|
+
{
|
|
12
|
+
name: ECC_ALGORITHM,
|
|
13
|
+
public: otherUserPublicKey
|
|
14
|
+
},
|
|
15
|
+
ownPrivateKey,
|
|
16
|
+
AES_KEY_BIT_LENGTH
|
|
17
|
+
);
|
|
18
|
+
return new Uint8Array(result);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
throw new Error("Failed to derive elliptic curve secret key", { cause: error });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/asymmetric-crypto/keys.ts
|
|
25
|
+
async function generateEccKeys() {
|
|
26
|
+
try {
|
|
27
|
+
return await crypto.subtle.generateKey(
|
|
28
|
+
{
|
|
29
|
+
name: ECC_ALGORITHM
|
|
30
|
+
},
|
|
31
|
+
true,
|
|
32
|
+
["deriveBits"]
|
|
33
|
+
);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
throw new Error("Failed to generate elliptic curve key pair", { cause: error });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async function exportPublicKey(key) {
|
|
39
|
+
try {
|
|
40
|
+
const result = await crypto.subtle.exportKey("spki", key);
|
|
41
|
+
return new Uint8Array(result);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
throw new Error("Failed to export public key", { cause: error });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async function importPublicKey(spkiKeyData) {
|
|
47
|
+
try {
|
|
48
|
+
return await crypto.subtle.importKey(
|
|
49
|
+
"spki",
|
|
50
|
+
spkiKeyData,
|
|
51
|
+
{
|
|
52
|
+
name: ECC_ALGORITHM
|
|
53
|
+
},
|
|
54
|
+
true,
|
|
55
|
+
[]
|
|
56
|
+
);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
throw new Error("Failed to import public key", { cause: error });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async function exportPrivateKey(key) {
|
|
62
|
+
try {
|
|
63
|
+
const result = await crypto.subtle.exportKey("pkcs8", key);
|
|
64
|
+
return new Uint8Array(result);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
throw new Error("Failed to export private key", { cause: error });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async function importPrivateKey(pkcs8KeyData) {
|
|
70
|
+
try {
|
|
71
|
+
return await crypto.subtle.importKey(
|
|
72
|
+
"pkcs8",
|
|
73
|
+
pkcs8KeyData,
|
|
74
|
+
{
|
|
75
|
+
name: ECC_ALGORITHM
|
|
76
|
+
},
|
|
77
|
+
true,
|
|
78
|
+
["deriveBits"]
|
|
79
|
+
);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
throw new Error("Failed to import private key", { cause: error });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
exports.deriveSecretKey = deriveSecretKey;
|
|
86
|
+
exports.exportPrivateKey = exportPrivateKey;
|
|
87
|
+
exports.exportPublicKey = exportPublicKey;
|
|
88
|
+
exports.generateEccKeys = generateEccKeys;
|
|
89
|
+
exports.importPrivateKey = importPrivateKey;
|
|
90
|
+
exports.importPublicKey = importPublicKey;
|
|
91
|
+
//# sourceMappingURL=asymmetric-crypto.js.map
|
|
92
|
+
//# sourceMappingURL=asymmetric-crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts","../src/asymmetric-crypto/ellipticCurve.ts","../src/asymmetric-crypto/keys.ts"],"names":[],"mappings":";;;AACO,IAAM,kBAAA,GAAqB,GAAA;AAQ3B,IAAM,aAAA,GAAgB,QAAA;;;ACA7B,eAAsB,eAAA,CAAgB,oBAA+B,aAAA,EAA+C;AAClH,EAAA,IAAI;AACF,IAAA,MAAM,MAAA,GAAS,MAAM,MAAA,CAAO,MAAA,CAAO,UAAA;AAAA,MACjC;AAAA,QACE,IAAA,EAAM,aAAA;AAAA,QACN,MAAA,EAAQ;AAAA,OACV;AAAA,MACA,aAAA;AAAA,MACA;AAAA,KACF;AACA,IAAA,OAAO,IAAI,WAAW,MAAM,CAAA;AAAA,EAC9B,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,KAAA,CAAM,4CAAA,EAA8C,EAAE,KAAA,EAAO,OAAO,CAAA;AAAA,EAChF;AACF;;;AChBA,eAAsB,eAAA,GAA0C;AAC9D,EAAA,IAAI;AACF,IAAA,OAAQ,MAAM,OAAO,MAAA,CAAO,WAAA;AAAA,MAC1B;AAAA,QACE,IAAA,EAAM;AAAA,OACR;AAAA,MACA,IAAA;AAAA,MACA,CAAC,YAAY;AAAA,KACf;AAAA,EACF,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,KAAA,CAAM,4CAAA,EAA8C,EAAE,KAAA,EAAO,OAAO,CAAA;AAAA,EAChF;AACF;AAOA,eAAsB,gBAAgB,GAAA,EAAqC;AACzE,EAAA,IAAI;AACF,IAAA,MAAM,SAAS,MAAM,MAAA,CAAO,MAAA,CAAO,SAAA,CAAU,QAAQ,GAAG,CAAA;AACxD,IAAA,OAAO,IAAI,WAAW,MAAM,CAAA;AAAA,EAC9B,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,KAAA,CAAM,6BAAA,EAA+B,EAAE,KAAA,EAAO,OAAO,CAAA;AAAA,EACjE;AACF;AAOA,eAAsB,gBAAgB,WAAA,EAA6C;AACjF,EAAA,IAAI;AACF,IAAA,OAAO,MAAM,OAAO,MAAA,CAAO,SAAA;AAAA,MACzB,MAAA;AAAA,MACA,WAAA;AAAA,MACA;AAAA,QACE,IAAA,EAAM;AAAA,OACR;AAAA,MACA,IAAA;AAAA,MACA;AAAC,KACH;AAAA,EACF,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,KAAA,CAAM,6BAAA,EAA+B,EAAE,KAAA,EAAO,OAAO,CAAA;AAAA,EACjE;AACF;AAOA,eAAsB,iBAAiB,GAAA,EAAqC;AAC1E,EAAA,IAAI;AACF,IAAA,MAAM,SAAS,MAAM,MAAA,CAAO,MAAA,CAAO,SAAA,CAAU,SAAS,GAAG,CAAA;AACzD,IAAA,OAAO,IAAI,WAAW,MAAM,CAAA;AAAA,EAC9B,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,KAAA,CAAM,8BAAA,EAAgC,EAAE,KAAA,EAAO,OAAO,CAAA;AAAA,EAClE;AACF;AAOA,eAAsB,iBAAiB,YAAA,EAA8C;AACnF,EAAA,IAAI;AACF,IAAA,OAAO,MAAM,OAAO,MAAA,CAAO,SAAA;AAAA,MACzB,OAAA;AAAA,MACA,YAAA;AAAA,MACA;AAAA,QACE,IAAA,EAAM;AAAA,OACR;AAAA,MACA,IAAA;AAAA,MACA,CAAC,YAAY;AAAA,KACf;AAAA,EACF,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,KAAA,CAAM,8BAAA,EAAgC,EAAE,KAAA,EAAO,OAAO,CAAA;AAAA,EAClE;AACF","file":"asymmetric-crypto.js","sourcesContent":["export const AES_ALGORITHM = 'AES-GCM';\nexport const AES_KEY_BIT_LENGTH = 256;\nexport const AUX_LEN = 128;\nexport const IV_LEN_BYTES = 16;\n\nexport const KEY_WRAPPING_ALGORITHM = 'AES-KW';\nexport const KEY_FORMAT = 'raw';\nexport const CONTEXT_WRAPPING = 'CRYPTO library 2025-08-22 18:10:00 key derived from ecc and kyber secrets';\n\nexport const ECC_ALGORITHM = 'X25519';\n\nexport const CONTEXT_LOGIN = 'CRYPTO library 2025-07-26 16:18:03 key for opening identity keystore';\nexport const CONTEXT_ENC_KEYSTORE = 'CRYPTO library 2025-07-30 16:18:03 key for opening encryption keys keystore';\nexport const CONTEXT_RECOVERY = 'CRYPTO library 2025-07-30 16:20:00 key for account recovery';\nexport const CONTEXT_INDEX = 'CRYPTO library 2025-07-30 17:20:00 key for protecting current search indices';\nexport const CONTEXT_DERIVE = 'CRYPTO library 2025-08-27 17:08:00 derive one key from two keys';\n\nexport const PREFIX_MEDIA_KEY_COMMITMENT = 'CRYPTO library 2025-08-26 18:29:00 prefix for commitment to media keys';\nexport const PREFIX_PUBLIC_KEY_COMMITMENT = 'CRYPTO library 2025-08-26 18:30:00 prefix for commitment to public keys';\nexport const PREFIX_IDENTITY_KEY_COMMITMENT =\n 'CRYPTO library 2025-08-26 18:45:00 prefix for commitment to identity keys';\n\n// Second recommended parameter set from RFC 9106\nexport const ARGON2ID_PARALLELISM = 3;\nexport const ARGON2ID_ITERATIONS = 4;\nexport const ARGON2ID_MEMORY_SIZE = 65536;\nexport const ARGON2ID_SALT_BYTE_LENGTH = 16;\nexport const ARGON2ID_OUTPUT_BYTE_LENGTH = 32;\n\nexport const IDENTITY_KEYSTORE_TAG = 'Identity keystore';\nexport const ENCRYPTION_KEYSTORE_TAG = 'Encryption keystore';\nexport const RECOVERY_KEYSTORE_TAG = 'Key recovery keystroe';\nexport const INDEX_KEYSTORE_TAG = 'Current encrypted indices';\n\nexport const KYBER512_PUBLIC_KEY_LENGTH = 800;\nexport const KYBER512_SECRET_KEY_LENGTH = 1632;\n\nexport const KYBER768_PUBLIC_KEY_LENGTH = 1184;\nexport const KYBER768_SECRET_KEY_LENGTH = 2400;\n\nexport const KYBER1024_PUBLIC_KEY_LENGTH = 1568;\nexport const KYBER1024_SECRET_KEY_LENGTH = 3168;\n\nexport const KYBER_SEED_LENGTH = 64;\n\nexport const HASH_BIT_LEN = 256;\n\nexport const MAX_CACHE_SIZE = 600000000; // 600 MB\nexport const MAX_EMAIL_PER_BATCH = 100;\nexport const DB_LABEL = 'email';\nexport const DB_VERSION = 1;\n","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"]}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// src/constants.ts
|
|
2
|
+
var AES_KEY_BIT_LENGTH = 256;
|
|
3
|
+
var ECC_ALGORITHM = "X25519";
|
|
4
|
+
|
|
5
|
+
// src/asymmetric-crypto/ellipticCurve.ts
|
|
6
|
+
async function deriveSecretKey(otherUserPublicKey, ownPrivateKey) {
|
|
7
|
+
try {
|
|
8
|
+
const result = await crypto.subtle.deriveBits(
|
|
9
|
+
{
|
|
10
|
+
name: ECC_ALGORITHM,
|
|
11
|
+
public: otherUserPublicKey
|
|
12
|
+
},
|
|
13
|
+
ownPrivateKey,
|
|
14
|
+
AES_KEY_BIT_LENGTH
|
|
15
|
+
);
|
|
16
|
+
return new Uint8Array(result);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
throw new Error("Failed to derive elliptic curve secret key", { cause: error });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/asymmetric-crypto/keys.ts
|
|
23
|
+
async function generateEccKeys() {
|
|
24
|
+
try {
|
|
25
|
+
return await crypto.subtle.generateKey(
|
|
26
|
+
{
|
|
27
|
+
name: ECC_ALGORITHM
|
|
28
|
+
},
|
|
29
|
+
true,
|
|
30
|
+
["deriveBits"]
|
|
31
|
+
);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
throw new Error("Failed to generate elliptic curve key pair", { cause: error });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function exportPublicKey(key) {
|
|
37
|
+
try {
|
|
38
|
+
const result = await crypto.subtle.exportKey("spki", key);
|
|
39
|
+
return new Uint8Array(result);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
throw new Error("Failed to export public key", { cause: error });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function importPublicKey(spkiKeyData) {
|
|
45
|
+
try {
|
|
46
|
+
return await crypto.subtle.importKey(
|
|
47
|
+
"spki",
|
|
48
|
+
spkiKeyData,
|
|
49
|
+
{
|
|
50
|
+
name: ECC_ALGORITHM
|
|
51
|
+
},
|
|
52
|
+
true,
|
|
53
|
+
[]
|
|
54
|
+
);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
throw new Error("Failed to import public key", { cause: error });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function exportPrivateKey(key) {
|
|
60
|
+
try {
|
|
61
|
+
const result = await crypto.subtle.exportKey("pkcs8", key);
|
|
62
|
+
return new Uint8Array(result);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
throw new Error("Failed to export private key", { cause: error });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async function importPrivateKey(pkcs8KeyData) {
|
|
68
|
+
try {
|
|
69
|
+
return await crypto.subtle.importKey(
|
|
70
|
+
"pkcs8",
|
|
71
|
+
pkcs8KeyData,
|
|
72
|
+
{
|
|
73
|
+
name: ECC_ALGORITHM
|
|
74
|
+
},
|
|
75
|
+
true,
|
|
76
|
+
["deriveBits"]
|
|
77
|
+
);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
throw new Error("Failed to import private key", { cause: error });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export { deriveSecretKey, exportPrivateKey, exportPublicKey, generateEccKeys, importPrivateKey, importPublicKey };
|
|
84
|
+
//# sourceMappingURL=asymmetric-crypto.mjs.map
|
|
85
|
+
//# sourceMappingURL=asymmetric-crypto.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts","../src/asymmetric-crypto/ellipticCurve.ts","../src/asymmetric-crypto/keys.ts"],"names":[],"mappings":";AACO,IAAM,kBAAA,GAAqB,GAAA;AAQ3B,IAAM,aAAA,GAAgB,QAAA;;;ACA7B,eAAsB,eAAA,CAAgB,oBAA+B,aAAA,EAA+C;AAClH,EAAA,IAAI;AACF,IAAA,MAAM,MAAA,GAAS,MAAM,MAAA,CAAO,MAAA,CAAO,UAAA;AAAA,MACjC;AAAA,QACE,IAAA,EAAM,aAAA;AAAA,QACN,MAAA,EAAQ;AAAA,OACV;AAAA,MACA,aAAA;AAAA,MACA;AAAA,KACF;AACA,IAAA,OAAO,IAAI,WAAW,MAAM,CAAA;AAAA,EAC9B,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,KAAA,CAAM,4CAAA,EAA8C,EAAE,KAAA,EAAO,OAAO,CAAA;AAAA,EAChF;AACF;;;AChBA,eAAsB,eAAA,GAA0C;AAC9D,EAAA,IAAI;AACF,IAAA,OAAQ,MAAM,OAAO,MAAA,CAAO,WAAA;AAAA,MAC1B;AAAA,QACE,IAAA,EAAM;AAAA,OACR;AAAA,MACA,IAAA;AAAA,MACA,CAAC,YAAY;AAAA,KACf;AAAA,EACF,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,KAAA,CAAM,4CAAA,EAA8C,EAAE,KAAA,EAAO,OAAO,CAAA;AAAA,EAChF;AACF;AAOA,eAAsB,gBAAgB,GAAA,EAAqC;AACzE,EAAA,IAAI;AACF,IAAA,MAAM,SAAS,MAAM,MAAA,CAAO,MAAA,CAAO,SAAA,CAAU,QAAQ,GAAG,CAAA;AACxD,IAAA,OAAO,IAAI,WAAW,MAAM,CAAA;AAAA,EAC9B,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,KAAA,CAAM,6BAAA,EAA+B,EAAE,KAAA,EAAO,OAAO,CAAA;AAAA,EACjE;AACF;AAOA,eAAsB,gBAAgB,WAAA,EAA6C;AACjF,EAAA,IAAI;AACF,IAAA,OAAO,MAAM,OAAO,MAAA,CAAO,SAAA;AAAA,MACzB,MAAA;AAAA,MACA,WAAA;AAAA,MACA;AAAA,QACE,IAAA,EAAM;AAAA,OACR;AAAA,MACA,IAAA;AAAA,MACA;AAAC,KACH;AAAA,EACF,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,KAAA,CAAM,6BAAA,EAA+B,EAAE,KAAA,EAAO,OAAO,CAAA;AAAA,EACjE;AACF;AAOA,eAAsB,iBAAiB,GAAA,EAAqC;AAC1E,EAAA,IAAI;AACF,IAAA,MAAM,SAAS,MAAM,MAAA,CAAO,MAAA,CAAO,SAAA,CAAU,SAAS,GAAG,CAAA;AACzD,IAAA,OAAO,IAAI,WAAW,MAAM,CAAA;AAAA,EAC9B,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,KAAA,CAAM,8BAAA,EAAgC,EAAE,KAAA,EAAO,OAAO,CAAA;AAAA,EAClE;AACF;AAOA,eAAsB,iBAAiB,YAAA,EAA8C;AACnF,EAAA,IAAI;AACF,IAAA,OAAO,MAAM,OAAO,MAAA,CAAO,SAAA;AAAA,MACzB,OAAA;AAAA,MACA,YAAA;AAAA,MACA;AAAA,QACE,IAAA,EAAM;AAAA,OACR;AAAA,MACA,IAAA;AAAA,MACA,CAAC,YAAY;AAAA,KACf;AAAA,EACF,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,KAAA,CAAM,8BAAA,EAAgC,EAAE,KAAA,EAAO,OAAO,CAAA;AAAA,EAClE;AACF","file":"asymmetric-crypto.mjs","sourcesContent":["export const AES_ALGORITHM = 'AES-GCM';\nexport const AES_KEY_BIT_LENGTH = 256;\nexport const AUX_LEN = 128;\nexport const IV_LEN_BYTES = 16;\n\nexport const KEY_WRAPPING_ALGORITHM = 'AES-KW';\nexport const KEY_FORMAT = 'raw';\nexport const CONTEXT_WRAPPING = 'CRYPTO library 2025-08-22 18:10:00 key derived from ecc and kyber secrets';\n\nexport const ECC_ALGORITHM = 'X25519';\n\nexport const CONTEXT_LOGIN = 'CRYPTO library 2025-07-26 16:18:03 key for opening identity keystore';\nexport const CONTEXT_ENC_KEYSTORE = 'CRYPTO library 2025-07-30 16:18:03 key for opening encryption keys keystore';\nexport const CONTEXT_RECOVERY = 'CRYPTO library 2025-07-30 16:20:00 key for account recovery';\nexport const CONTEXT_INDEX = 'CRYPTO library 2025-07-30 17:20:00 key for protecting current search indices';\nexport const CONTEXT_DERIVE = 'CRYPTO library 2025-08-27 17:08:00 derive one key from two keys';\n\nexport const PREFIX_MEDIA_KEY_COMMITMENT = 'CRYPTO library 2025-08-26 18:29:00 prefix for commitment to media keys';\nexport const PREFIX_PUBLIC_KEY_COMMITMENT = 'CRYPTO library 2025-08-26 18:30:00 prefix for commitment to public keys';\nexport const PREFIX_IDENTITY_KEY_COMMITMENT =\n 'CRYPTO library 2025-08-26 18:45:00 prefix for commitment to identity keys';\n\n// Second recommended parameter set from RFC 9106\nexport const ARGON2ID_PARALLELISM = 3;\nexport const ARGON2ID_ITERATIONS = 4;\nexport const ARGON2ID_MEMORY_SIZE = 65536;\nexport const ARGON2ID_SALT_BYTE_LENGTH = 16;\nexport const ARGON2ID_OUTPUT_BYTE_LENGTH = 32;\n\nexport const IDENTITY_KEYSTORE_TAG = 'Identity keystore';\nexport const ENCRYPTION_KEYSTORE_TAG = 'Encryption keystore';\nexport const RECOVERY_KEYSTORE_TAG = 'Key recovery keystroe';\nexport const INDEX_KEYSTORE_TAG = 'Current encrypted indices';\n\nexport const KYBER512_PUBLIC_KEY_LENGTH = 800;\nexport const KYBER512_SECRET_KEY_LENGTH = 1632;\n\nexport const KYBER768_PUBLIC_KEY_LENGTH = 1184;\nexport const KYBER768_SECRET_KEY_LENGTH = 2400;\n\nexport const KYBER1024_PUBLIC_KEY_LENGTH = 1568;\nexport const KYBER1024_SECRET_KEY_LENGTH = 3168;\n\nexport const KYBER_SEED_LENGTH = 64;\n\nexport const HASH_BIT_LEN = 256;\n\nexport const MAX_CACHE_SIZE = 600000000; // 600 MB\nexport const MAX_EMAIL_PER_BATCH = 100;\nexport const DB_LABEL = 'email';\nexport const DB_VERSION = 1;\n","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"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
declare const AES_ALGORITHM = "AES-GCM";
|
|
2
|
+
declare const AES_KEY_BIT_LENGTH = 256;
|
|
3
|
+
declare const AUX_LEN = 128;
|
|
4
|
+
declare const IV_LEN_BYTES = 16;
|
|
5
|
+
declare const KEY_WRAPPING_ALGORITHM = "AES-KW";
|
|
6
|
+
declare const KEY_FORMAT = "raw";
|
|
7
|
+
declare const CONTEXT_WRAPPING = "CRYPTO library 2025-08-22 18:10:00 key derived from ecc and kyber secrets";
|
|
8
|
+
declare const ECC_ALGORITHM = "X25519";
|
|
9
|
+
declare const CONTEXT_LOGIN = "CRYPTO library 2025-07-26 16:18:03 key for opening identity keystore";
|
|
10
|
+
declare const CONTEXT_ENC_KEYSTORE = "CRYPTO library 2025-07-30 16:18:03 key for opening encryption keys keystore";
|
|
11
|
+
declare const CONTEXT_RECOVERY = "CRYPTO library 2025-07-30 16:20:00 key for account recovery";
|
|
12
|
+
declare const CONTEXT_INDEX = "CRYPTO library 2025-07-30 17:20:00 key for protecting current search indices";
|
|
13
|
+
declare const CONTEXT_DERIVE = "CRYPTO library 2025-08-27 17:08:00 derive one key from two keys";
|
|
14
|
+
declare const PREFIX_MEDIA_KEY_COMMITMENT = "CRYPTO library 2025-08-26 18:29:00 prefix for commitment to media keys";
|
|
15
|
+
declare const PREFIX_PUBLIC_KEY_COMMITMENT = "CRYPTO library 2025-08-26 18:30:00 prefix for commitment to public keys";
|
|
16
|
+
declare const PREFIX_IDENTITY_KEY_COMMITMENT = "CRYPTO library 2025-08-26 18:45:00 prefix for commitment to identity keys";
|
|
17
|
+
declare const ARGON2ID_PARALLELISM = 3;
|
|
18
|
+
declare const ARGON2ID_ITERATIONS = 4;
|
|
19
|
+
declare const ARGON2ID_MEMORY_SIZE = 65536;
|
|
20
|
+
declare const ARGON2ID_SALT_BYTE_LENGTH = 16;
|
|
21
|
+
declare const ARGON2ID_OUTPUT_BYTE_LENGTH = 32;
|
|
22
|
+
declare const IDENTITY_KEYSTORE_TAG = "Identity keystore";
|
|
23
|
+
declare const ENCRYPTION_KEYSTORE_TAG = "Encryption keystore";
|
|
24
|
+
declare const RECOVERY_KEYSTORE_TAG = "Key recovery keystroe";
|
|
25
|
+
declare const INDEX_KEYSTORE_TAG = "Current encrypted indices";
|
|
26
|
+
declare const KYBER512_PUBLIC_KEY_LENGTH = 800;
|
|
27
|
+
declare const KYBER512_SECRET_KEY_LENGTH = 1632;
|
|
28
|
+
declare const KYBER768_PUBLIC_KEY_LENGTH = 1184;
|
|
29
|
+
declare const KYBER768_SECRET_KEY_LENGTH = 2400;
|
|
30
|
+
declare const KYBER1024_PUBLIC_KEY_LENGTH = 1568;
|
|
31
|
+
declare const KYBER1024_SECRET_KEY_LENGTH = 3168;
|
|
32
|
+
declare const KYBER_SEED_LENGTH = 64;
|
|
33
|
+
declare const HASH_BIT_LEN = 256;
|
|
34
|
+
declare const MAX_CACHE_SIZE = 600000000;
|
|
35
|
+
declare const MAX_EMAIL_PER_BATCH = 100;
|
|
36
|
+
declare const DB_LABEL = "email";
|
|
37
|
+
declare const DB_VERSION = 1;
|
|
38
|
+
|
|
39
|
+
export { AES_ALGORITHM, AES_KEY_BIT_LENGTH, ARGON2ID_ITERATIONS, ARGON2ID_MEMORY_SIZE, ARGON2ID_OUTPUT_BYTE_LENGTH, ARGON2ID_PARALLELISM, ARGON2ID_SALT_BYTE_LENGTH, AUX_LEN, CONTEXT_DERIVE, CONTEXT_ENC_KEYSTORE, CONTEXT_INDEX, CONTEXT_LOGIN, CONTEXT_RECOVERY, CONTEXT_WRAPPING, DB_LABEL, DB_VERSION, ECC_ALGORITHM, ENCRYPTION_KEYSTORE_TAG, HASH_BIT_LEN, IDENTITY_KEYSTORE_TAG, INDEX_KEYSTORE_TAG, IV_LEN_BYTES, KEY_FORMAT, KEY_WRAPPING_ALGORITHM, KYBER1024_PUBLIC_KEY_LENGTH, KYBER1024_SECRET_KEY_LENGTH, KYBER512_PUBLIC_KEY_LENGTH, KYBER512_SECRET_KEY_LENGTH, KYBER768_PUBLIC_KEY_LENGTH, KYBER768_SECRET_KEY_LENGTH, KYBER_SEED_LENGTH, MAX_CACHE_SIZE, MAX_EMAIL_PER_BATCH, PREFIX_IDENTITY_KEY_COMMITMENT, PREFIX_MEDIA_KEY_COMMITMENT, PREFIX_PUBLIC_KEY_COMMITMENT, RECOVERY_KEYSTORE_TAG };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
declare const AES_ALGORITHM = "AES-GCM";
|
|
2
|
+
declare const AES_KEY_BIT_LENGTH = 256;
|
|
3
|
+
declare const AUX_LEN = 128;
|
|
4
|
+
declare const IV_LEN_BYTES = 16;
|
|
5
|
+
declare const KEY_WRAPPING_ALGORITHM = "AES-KW";
|
|
6
|
+
declare const KEY_FORMAT = "raw";
|
|
7
|
+
declare const CONTEXT_WRAPPING = "CRYPTO library 2025-08-22 18:10:00 key derived from ecc and kyber secrets";
|
|
8
|
+
declare const ECC_ALGORITHM = "X25519";
|
|
9
|
+
declare const CONTEXT_LOGIN = "CRYPTO library 2025-07-26 16:18:03 key for opening identity keystore";
|
|
10
|
+
declare const CONTEXT_ENC_KEYSTORE = "CRYPTO library 2025-07-30 16:18:03 key for opening encryption keys keystore";
|
|
11
|
+
declare const CONTEXT_RECOVERY = "CRYPTO library 2025-07-30 16:20:00 key for account recovery";
|
|
12
|
+
declare const CONTEXT_INDEX = "CRYPTO library 2025-07-30 17:20:00 key for protecting current search indices";
|
|
13
|
+
declare const CONTEXT_DERIVE = "CRYPTO library 2025-08-27 17:08:00 derive one key from two keys";
|
|
14
|
+
declare const PREFIX_MEDIA_KEY_COMMITMENT = "CRYPTO library 2025-08-26 18:29:00 prefix for commitment to media keys";
|
|
15
|
+
declare const PREFIX_PUBLIC_KEY_COMMITMENT = "CRYPTO library 2025-08-26 18:30:00 prefix for commitment to public keys";
|
|
16
|
+
declare const PREFIX_IDENTITY_KEY_COMMITMENT = "CRYPTO library 2025-08-26 18:45:00 prefix for commitment to identity keys";
|
|
17
|
+
declare const ARGON2ID_PARALLELISM = 3;
|
|
18
|
+
declare const ARGON2ID_ITERATIONS = 4;
|
|
19
|
+
declare const ARGON2ID_MEMORY_SIZE = 65536;
|
|
20
|
+
declare const ARGON2ID_SALT_BYTE_LENGTH = 16;
|
|
21
|
+
declare const ARGON2ID_OUTPUT_BYTE_LENGTH = 32;
|
|
22
|
+
declare const IDENTITY_KEYSTORE_TAG = "Identity keystore";
|
|
23
|
+
declare const ENCRYPTION_KEYSTORE_TAG = "Encryption keystore";
|
|
24
|
+
declare const RECOVERY_KEYSTORE_TAG = "Key recovery keystroe";
|
|
25
|
+
declare const INDEX_KEYSTORE_TAG = "Current encrypted indices";
|
|
26
|
+
declare const KYBER512_PUBLIC_KEY_LENGTH = 800;
|
|
27
|
+
declare const KYBER512_SECRET_KEY_LENGTH = 1632;
|
|
28
|
+
declare const KYBER768_PUBLIC_KEY_LENGTH = 1184;
|
|
29
|
+
declare const KYBER768_SECRET_KEY_LENGTH = 2400;
|
|
30
|
+
declare const KYBER1024_PUBLIC_KEY_LENGTH = 1568;
|
|
31
|
+
declare const KYBER1024_SECRET_KEY_LENGTH = 3168;
|
|
32
|
+
declare const KYBER_SEED_LENGTH = 64;
|
|
33
|
+
declare const HASH_BIT_LEN = 256;
|
|
34
|
+
declare const MAX_CACHE_SIZE = 600000000;
|
|
35
|
+
declare const MAX_EMAIL_PER_BATCH = 100;
|
|
36
|
+
declare const DB_LABEL = "email";
|
|
37
|
+
declare const DB_VERSION = 1;
|
|
38
|
+
|
|
39
|
+
export { AES_ALGORITHM, AES_KEY_BIT_LENGTH, ARGON2ID_ITERATIONS, ARGON2ID_MEMORY_SIZE, ARGON2ID_OUTPUT_BYTE_LENGTH, ARGON2ID_PARALLELISM, ARGON2ID_SALT_BYTE_LENGTH, AUX_LEN, CONTEXT_DERIVE, CONTEXT_ENC_KEYSTORE, CONTEXT_INDEX, CONTEXT_LOGIN, CONTEXT_RECOVERY, CONTEXT_WRAPPING, DB_LABEL, DB_VERSION, ECC_ALGORITHM, ENCRYPTION_KEYSTORE_TAG, HASH_BIT_LEN, IDENTITY_KEYSTORE_TAG, INDEX_KEYSTORE_TAG, IV_LEN_BYTES, KEY_FORMAT, KEY_WRAPPING_ALGORITHM, KYBER1024_PUBLIC_KEY_LENGTH, KYBER1024_SECRET_KEY_LENGTH, KYBER512_PUBLIC_KEY_LENGTH, KYBER512_SECRET_KEY_LENGTH, KYBER768_PUBLIC_KEY_LENGTH, KYBER768_SECRET_KEY_LENGTH, KYBER_SEED_LENGTH, MAX_CACHE_SIZE, MAX_EMAIL_PER_BATCH, PREFIX_IDENTITY_KEY_COMMITMENT, PREFIX_MEDIA_KEY_COMMITMENT, PREFIX_PUBLIC_KEY_COMMITMENT, RECOVERY_KEYSTORE_TAG };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/constants.ts
|
|
4
|
+
var AES_ALGORITHM = "AES-GCM";
|
|
5
|
+
var AES_KEY_BIT_LENGTH = 256;
|
|
6
|
+
var AUX_LEN = 128;
|
|
7
|
+
var IV_LEN_BYTES = 16;
|
|
8
|
+
var KEY_WRAPPING_ALGORITHM = "AES-KW";
|
|
9
|
+
var KEY_FORMAT = "raw";
|
|
10
|
+
var CONTEXT_WRAPPING = "CRYPTO library 2025-08-22 18:10:00 key derived from ecc and kyber secrets";
|
|
11
|
+
var ECC_ALGORITHM = "X25519";
|
|
12
|
+
var CONTEXT_LOGIN = "CRYPTO library 2025-07-26 16:18:03 key for opening identity keystore";
|
|
13
|
+
var CONTEXT_ENC_KEYSTORE = "CRYPTO library 2025-07-30 16:18:03 key for opening encryption keys keystore";
|
|
14
|
+
var CONTEXT_RECOVERY = "CRYPTO library 2025-07-30 16:20:00 key for account recovery";
|
|
15
|
+
var CONTEXT_INDEX = "CRYPTO library 2025-07-30 17:20:00 key for protecting current search indices";
|
|
16
|
+
var CONTEXT_DERIVE = "CRYPTO library 2025-08-27 17:08:00 derive one key from two keys";
|
|
17
|
+
var PREFIX_MEDIA_KEY_COMMITMENT = "CRYPTO library 2025-08-26 18:29:00 prefix for commitment to media keys";
|
|
18
|
+
var PREFIX_PUBLIC_KEY_COMMITMENT = "CRYPTO library 2025-08-26 18:30:00 prefix for commitment to public keys";
|
|
19
|
+
var PREFIX_IDENTITY_KEY_COMMITMENT = "CRYPTO library 2025-08-26 18:45:00 prefix for commitment to identity keys";
|
|
20
|
+
var ARGON2ID_PARALLELISM = 3;
|
|
21
|
+
var ARGON2ID_ITERATIONS = 4;
|
|
22
|
+
var ARGON2ID_MEMORY_SIZE = 65536;
|
|
23
|
+
var ARGON2ID_SALT_BYTE_LENGTH = 16;
|
|
24
|
+
var ARGON2ID_OUTPUT_BYTE_LENGTH = 32;
|
|
25
|
+
var IDENTITY_KEYSTORE_TAG = "Identity keystore";
|
|
26
|
+
var ENCRYPTION_KEYSTORE_TAG = "Encryption keystore";
|
|
27
|
+
var RECOVERY_KEYSTORE_TAG = "Key recovery keystroe";
|
|
28
|
+
var INDEX_KEYSTORE_TAG = "Current encrypted indices";
|
|
29
|
+
var KYBER512_PUBLIC_KEY_LENGTH = 800;
|
|
30
|
+
var KYBER512_SECRET_KEY_LENGTH = 1632;
|
|
31
|
+
var KYBER768_PUBLIC_KEY_LENGTH = 1184;
|
|
32
|
+
var KYBER768_SECRET_KEY_LENGTH = 2400;
|
|
33
|
+
var KYBER1024_PUBLIC_KEY_LENGTH = 1568;
|
|
34
|
+
var KYBER1024_SECRET_KEY_LENGTH = 3168;
|
|
35
|
+
var KYBER_SEED_LENGTH = 64;
|
|
36
|
+
var HASH_BIT_LEN = 256;
|
|
37
|
+
var MAX_CACHE_SIZE = 6e8;
|
|
38
|
+
var MAX_EMAIL_PER_BATCH = 100;
|
|
39
|
+
var DB_LABEL = "email";
|
|
40
|
+
var DB_VERSION = 1;
|
|
41
|
+
|
|
42
|
+
exports.AES_ALGORITHM = AES_ALGORITHM;
|
|
43
|
+
exports.AES_KEY_BIT_LENGTH = AES_KEY_BIT_LENGTH;
|
|
44
|
+
exports.ARGON2ID_ITERATIONS = ARGON2ID_ITERATIONS;
|
|
45
|
+
exports.ARGON2ID_MEMORY_SIZE = ARGON2ID_MEMORY_SIZE;
|
|
46
|
+
exports.ARGON2ID_OUTPUT_BYTE_LENGTH = ARGON2ID_OUTPUT_BYTE_LENGTH;
|
|
47
|
+
exports.ARGON2ID_PARALLELISM = ARGON2ID_PARALLELISM;
|
|
48
|
+
exports.ARGON2ID_SALT_BYTE_LENGTH = ARGON2ID_SALT_BYTE_LENGTH;
|
|
49
|
+
exports.AUX_LEN = AUX_LEN;
|
|
50
|
+
exports.CONTEXT_DERIVE = CONTEXT_DERIVE;
|
|
51
|
+
exports.CONTEXT_ENC_KEYSTORE = CONTEXT_ENC_KEYSTORE;
|
|
52
|
+
exports.CONTEXT_INDEX = CONTEXT_INDEX;
|
|
53
|
+
exports.CONTEXT_LOGIN = CONTEXT_LOGIN;
|
|
54
|
+
exports.CONTEXT_RECOVERY = CONTEXT_RECOVERY;
|
|
55
|
+
exports.CONTEXT_WRAPPING = CONTEXT_WRAPPING;
|
|
56
|
+
exports.DB_LABEL = DB_LABEL;
|
|
57
|
+
exports.DB_VERSION = DB_VERSION;
|
|
58
|
+
exports.ECC_ALGORITHM = ECC_ALGORITHM;
|
|
59
|
+
exports.ENCRYPTION_KEYSTORE_TAG = ENCRYPTION_KEYSTORE_TAG;
|
|
60
|
+
exports.HASH_BIT_LEN = HASH_BIT_LEN;
|
|
61
|
+
exports.IDENTITY_KEYSTORE_TAG = IDENTITY_KEYSTORE_TAG;
|
|
62
|
+
exports.INDEX_KEYSTORE_TAG = INDEX_KEYSTORE_TAG;
|
|
63
|
+
exports.IV_LEN_BYTES = IV_LEN_BYTES;
|
|
64
|
+
exports.KEY_FORMAT = KEY_FORMAT;
|
|
65
|
+
exports.KEY_WRAPPING_ALGORITHM = KEY_WRAPPING_ALGORITHM;
|
|
66
|
+
exports.KYBER1024_PUBLIC_KEY_LENGTH = KYBER1024_PUBLIC_KEY_LENGTH;
|
|
67
|
+
exports.KYBER1024_SECRET_KEY_LENGTH = KYBER1024_SECRET_KEY_LENGTH;
|
|
68
|
+
exports.KYBER512_PUBLIC_KEY_LENGTH = KYBER512_PUBLIC_KEY_LENGTH;
|
|
69
|
+
exports.KYBER512_SECRET_KEY_LENGTH = KYBER512_SECRET_KEY_LENGTH;
|
|
70
|
+
exports.KYBER768_PUBLIC_KEY_LENGTH = KYBER768_PUBLIC_KEY_LENGTH;
|
|
71
|
+
exports.KYBER768_SECRET_KEY_LENGTH = KYBER768_SECRET_KEY_LENGTH;
|
|
72
|
+
exports.KYBER_SEED_LENGTH = KYBER_SEED_LENGTH;
|
|
73
|
+
exports.MAX_CACHE_SIZE = MAX_CACHE_SIZE;
|
|
74
|
+
exports.MAX_EMAIL_PER_BATCH = MAX_EMAIL_PER_BATCH;
|
|
75
|
+
exports.PREFIX_IDENTITY_KEY_COMMITMENT = PREFIX_IDENTITY_KEY_COMMITMENT;
|
|
76
|
+
exports.PREFIX_MEDIA_KEY_COMMITMENT = PREFIX_MEDIA_KEY_COMMITMENT;
|
|
77
|
+
exports.PREFIX_PUBLIC_KEY_COMMITMENT = PREFIX_PUBLIC_KEY_COMMITMENT;
|
|
78
|
+
exports.RECOVERY_KEYSTORE_TAG = RECOVERY_KEYSTORE_TAG;
|
|
79
|
+
//# sourceMappingURL=constants.js.map
|
|
80
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAO,IAAM,aAAA,GAAgB;AACtB,IAAM,kBAAA,GAAqB;AAC3B,IAAM,OAAA,GAAU;AAChB,IAAM,YAAA,GAAe;AAErB,IAAM,sBAAA,GAAyB;AAC/B,IAAM,UAAA,GAAa;AACnB,IAAM,gBAAA,GAAmB;AAEzB,IAAM,aAAA,GAAgB;AAEtB,IAAM,aAAA,GAAgB;AACtB,IAAM,oBAAA,GAAuB;AAC7B,IAAM,gBAAA,GAAmB;AACzB,IAAM,aAAA,GAAgB;AACtB,IAAM,cAAA,GAAiB;AAEvB,IAAM,2BAAA,GAA8B;AACpC,IAAM,4BAAA,GAA+B;AACrC,IAAM,8BAAA,GACX;AAGK,IAAM,oBAAA,GAAuB;AAC7B,IAAM,mBAAA,GAAsB;AAC5B,IAAM,oBAAA,GAAuB;AAC7B,IAAM,yBAAA,GAA4B;AAClC,IAAM,2BAAA,GAA8B;AAEpC,IAAM,qBAAA,GAAwB;AAC9B,IAAM,uBAAA,GAA0B;AAChC,IAAM,qBAAA,GAAwB;AAC9B,IAAM,kBAAA,GAAqB;AAE3B,IAAM,0BAAA,GAA6B;AACnC,IAAM,0BAAA,GAA6B;AAEnC,IAAM,0BAAA,GAA6B;AACnC,IAAM,0BAAA,GAA6B;AAEnC,IAAM,2BAAA,GAA8B;AACpC,IAAM,2BAAA,GAA8B;AAEpC,IAAM,iBAAA,GAAoB;AAE1B,IAAM,YAAA,GAAe;AAErB,IAAM,cAAA,GAAiB;AACvB,IAAM,mBAAA,GAAsB;AAC5B,IAAM,QAAA,GAAW;AACjB,IAAM,UAAA,GAAa","file":"constants.js","sourcesContent":["export const AES_ALGORITHM = 'AES-GCM';\nexport const AES_KEY_BIT_LENGTH = 256;\nexport const AUX_LEN = 128;\nexport const IV_LEN_BYTES = 16;\n\nexport const KEY_WRAPPING_ALGORITHM = 'AES-KW';\nexport const KEY_FORMAT = 'raw';\nexport const CONTEXT_WRAPPING = 'CRYPTO library 2025-08-22 18:10:00 key derived from ecc and kyber secrets';\n\nexport const ECC_ALGORITHM = 'X25519';\n\nexport const CONTEXT_LOGIN = 'CRYPTO library 2025-07-26 16:18:03 key for opening identity keystore';\nexport const CONTEXT_ENC_KEYSTORE = 'CRYPTO library 2025-07-30 16:18:03 key for opening encryption keys keystore';\nexport const CONTEXT_RECOVERY = 'CRYPTO library 2025-07-30 16:20:00 key for account recovery';\nexport const CONTEXT_INDEX = 'CRYPTO library 2025-07-30 17:20:00 key for protecting current search indices';\nexport const CONTEXT_DERIVE = 'CRYPTO library 2025-08-27 17:08:00 derive one key from two keys';\n\nexport const PREFIX_MEDIA_KEY_COMMITMENT = 'CRYPTO library 2025-08-26 18:29:00 prefix for commitment to media keys';\nexport const PREFIX_PUBLIC_KEY_COMMITMENT = 'CRYPTO library 2025-08-26 18:30:00 prefix for commitment to public keys';\nexport const PREFIX_IDENTITY_KEY_COMMITMENT =\n 'CRYPTO library 2025-08-26 18:45:00 prefix for commitment to identity keys';\n\n// Second recommended parameter set from RFC 9106\nexport const ARGON2ID_PARALLELISM = 3;\nexport const ARGON2ID_ITERATIONS = 4;\nexport const ARGON2ID_MEMORY_SIZE = 65536;\nexport const ARGON2ID_SALT_BYTE_LENGTH = 16;\nexport const ARGON2ID_OUTPUT_BYTE_LENGTH = 32;\n\nexport const IDENTITY_KEYSTORE_TAG = 'Identity keystore';\nexport const ENCRYPTION_KEYSTORE_TAG = 'Encryption keystore';\nexport const RECOVERY_KEYSTORE_TAG = 'Key recovery keystroe';\nexport const INDEX_KEYSTORE_TAG = 'Current encrypted indices';\n\nexport const KYBER512_PUBLIC_KEY_LENGTH = 800;\nexport const KYBER512_SECRET_KEY_LENGTH = 1632;\n\nexport const KYBER768_PUBLIC_KEY_LENGTH = 1184;\nexport const KYBER768_SECRET_KEY_LENGTH = 2400;\n\nexport const KYBER1024_PUBLIC_KEY_LENGTH = 1568;\nexport const KYBER1024_SECRET_KEY_LENGTH = 3168;\n\nexport const KYBER_SEED_LENGTH = 64;\n\nexport const HASH_BIT_LEN = 256;\n\nexport const MAX_CACHE_SIZE = 600000000; // 600 MB\nexport const MAX_EMAIL_PER_BATCH = 100;\nexport const DB_LABEL = 'email';\nexport const DB_VERSION = 1;\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// src/constants.ts
|
|
2
|
+
var AES_ALGORITHM = "AES-GCM";
|
|
3
|
+
var AES_KEY_BIT_LENGTH = 256;
|
|
4
|
+
var AUX_LEN = 128;
|
|
5
|
+
var IV_LEN_BYTES = 16;
|
|
6
|
+
var KEY_WRAPPING_ALGORITHM = "AES-KW";
|
|
7
|
+
var KEY_FORMAT = "raw";
|
|
8
|
+
var CONTEXT_WRAPPING = "CRYPTO library 2025-08-22 18:10:00 key derived from ecc and kyber secrets";
|
|
9
|
+
var ECC_ALGORITHM = "X25519";
|
|
10
|
+
var CONTEXT_LOGIN = "CRYPTO library 2025-07-26 16:18:03 key for opening identity keystore";
|
|
11
|
+
var CONTEXT_ENC_KEYSTORE = "CRYPTO library 2025-07-30 16:18:03 key for opening encryption keys keystore";
|
|
12
|
+
var CONTEXT_RECOVERY = "CRYPTO library 2025-07-30 16:20:00 key for account recovery";
|
|
13
|
+
var CONTEXT_INDEX = "CRYPTO library 2025-07-30 17:20:00 key for protecting current search indices";
|
|
14
|
+
var CONTEXT_DERIVE = "CRYPTO library 2025-08-27 17:08:00 derive one key from two keys";
|
|
15
|
+
var PREFIX_MEDIA_KEY_COMMITMENT = "CRYPTO library 2025-08-26 18:29:00 prefix for commitment to media keys";
|
|
16
|
+
var PREFIX_PUBLIC_KEY_COMMITMENT = "CRYPTO library 2025-08-26 18:30:00 prefix for commitment to public keys";
|
|
17
|
+
var PREFIX_IDENTITY_KEY_COMMITMENT = "CRYPTO library 2025-08-26 18:45:00 prefix for commitment to identity keys";
|
|
18
|
+
var ARGON2ID_PARALLELISM = 3;
|
|
19
|
+
var ARGON2ID_ITERATIONS = 4;
|
|
20
|
+
var ARGON2ID_MEMORY_SIZE = 65536;
|
|
21
|
+
var ARGON2ID_SALT_BYTE_LENGTH = 16;
|
|
22
|
+
var ARGON2ID_OUTPUT_BYTE_LENGTH = 32;
|
|
23
|
+
var IDENTITY_KEYSTORE_TAG = "Identity keystore";
|
|
24
|
+
var ENCRYPTION_KEYSTORE_TAG = "Encryption keystore";
|
|
25
|
+
var RECOVERY_KEYSTORE_TAG = "Key recovery keystroe";
|
|
26
|
+
var INDEX_KEYSTORE_TAG = "Current encrypted indices";
|
|
27
|
+
var KYBER512_PUBLIC_KEY_LENGTH = 800;
|
|
28
|
+
var KYBER512_SECRET_KEY_LENGTH = 1632;
|
|
29
|
+
var KYBER768_PUBLIC_KEY_LENGTH = 1184;
|
|
30
|
+
var KYBER768_SECRET_KEY_LENGTH = 2400;
|
|
31
|
+
var KYBER1024_PUBLIC_KEY_LENGTH = 1568;
|
|
32
|
+
var KYBER1024_SECRET_KEY_LENGTH = 3168;
|
|
33
|
+
var KYBER_SEED_LENGTH = 64;
|
|
34
|
+
var HASH_BIT_LEN = 256;
|
|
35
|
+
var MAX_CACHE_SIZE = 6e8;
|
|
36
|
+
var MAX_EMAIL_PER_BATCH = 100;
|
|
37
|
+
var DB_LABEL = "email";
|
|
38
|
+
var DB_VERSION = 1;
|
|
39
|
+
|
|
40
|
+
export { AES_ALGORITHM, AES_KEY_BIT_LENGTH, ARGON2ID_ITERATIONS, ARGON2ID_MEMORY_SIZE, ARGON2ID_OUTPUT_BYTE_LENGTH, ARGON2ID_PARALLELISM, ARGON2ID_SALT_BYTE_LENGTH, AUX_LEN, CONTEXT_DERIVE, CONTEXT_ENC_KEYSTORE, CONTEXT_INDEX, CONTEXT_LOGIN, CONTEXT_RECOVERY, CONTEXT_WRAPPING, DB_LABEL, DB_VERSION, ECC_ALGORITHM, ENCRYPTION_KEYSTORE_TAG, HASH_BIT_LEN, IDENTITY_KEYSTORE_TAG, INDEX_KEYSTORE_TAG, IV_LEN_BYTES, KEY_FORMAT, KEY_WRAPPING_ALGORITHM, KYBER1024_PUBLIC_KEY_LENGTH, KYBER1024_SECRET_KEY_LENGTH, KYBER512_PUBLIC_KEY_LENGTH, KYBER512_SECRET_KEY_LENGTH, KYBER768_PUBLIC_KEY_LENGTH, KYBER768_SECRET_KEY_LENGTH, KYBER_SEED_LENGTH, MAX_CACHE_SIZE, MAX_EMAIL_PER_BATCH, PREFIX_IDENTITY_KEY_COMMITMENT, PREFIX_MEDIA_KEY_COMMITMENT, PREFIX_PUBLIC_KEY_COMMITMENT, RECOVERY_KEYSTORE_TAG };
|
|
41
|
+
//# sourceMappingURL=constants.mjs.map
|
|
42
|
+
//# sourceMappingURL=constants.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts"],"names":[],"mappings":";AAAO,IAAM,aAAA,GAAgB;AACtB,IAAM,kBAAA,GAAqB;AAC3B,IAAM,OAAA,GAAU;AAChB,IAAM,YAAA,GAAe;AAErB,IAAM,sBAAA,GAAyB;AAC/B,IAAM,UAAA,GAAa;AACnB,IAAM,gBAAA,GAAmB;AAEzB,IAAM,aAAA,GAAgB;AAEtB,IAAM,aAAA,GAAgB;AACtB,IAAM,oBAAA,GAAuB;AAC7B,IAAM,gBAAA,GAAmB;AACzB,IAAM,aAAA,GAAgB;AACtB,IAAM,cAAA,GAAiB;AAEvB,IAAM,2BAAA,GAA8B;AACpC,IAAM,4BAAA,GAA+B;AACrC,IAAM,8BAAA,GACX;AAGK,IAAM,oBAAA,GAAuB;AAC7B,IAAM,mBAAA,GAAsB;AAC5B,IAAM,oBAAA,GAAuB;AAC7B,IAAM,yBAAA,GAA4B;AAClC,IAAM,2BAAA,GAA8B;AAEpC,IAAM,qBAAA,GAAwB;AAC9B,IAAM,uBAAA,GAA0B;AAChC,IAAM,qBAAA,GAAwB;AAC9B,IAAM,kBAAA,GAAqB;AAE3B,IAAM,0BAAA,GAA6B;AACnC,IAAM,0BAAA,GAA6B;AAEnC,IAAM,0BAAA,GAA6B;AACnC,IAAM,0BAAA,GAA6B;AAEnC,IAAM,2BAAA,GAA8B;AACpC,IAAM,2BAAA,GAA8B;AAEpC,IAAM,iBAAA,GAAoB;AAE1B,IAAM,YAAA,GAAe;AAErB,IAAM,cAAA,GAAiB;AACvB,IAAM,mBAAA,GAAsB;AAC5B,IAAM,QAAA,GAAW;AACjB,IAAM,UAAA,GAAa","file":"constants.mjs","sourcesContent":["export const AES_ALGORITHM = 'AES-GCM';\nexport const AES_KEY_BIT_LENGTH = 256;\nexport const AUX_LEN = 128;\nexport const IV_LEN_BYTES = 16;\n\nexport const KEY_WRAPPING_ALGORITHM = 'AES-KW';\nexport const KEY_FORMAT = 'raw';\nexport const CONTEXT_WRAPPING = 'CRYPTO library 2025-08-22 18:10:00 key derived from ecc and kyber secrets';\n\nexport const ECC_ALGORITHM = 'X25519';\n\nexport const CONTEXT_LOGIN = 'CRYPTO library 2025-07-26 16:18:03 key for opening identity keystore';\nexport const CONTEXT_ENC_KEYSTORE = 'CRYPTO library 2025-07-30 16:18:03 key for opening encryption keys keystore';\nexport const CONTEXT_RECOVERY = 'CRYPTO library 2025-07-30 16:20:00 key for account recovery';\nexport const CONTEXT_INDEX = 'CRYPTO library 2025-07-30 17:20:00 key for protecting current search indices';\nexport const CONTEXT_DERIVE = 'CRYPTO library 2025-08-27 17:08:00 derive one key from two keys';\n\nexport const PREFIX_MEDIA_KEY_COMMITMENT = 'CRYPTO library 2025-08-26 18:29:00 prefix for commitment to media keys';\nexport const PREFIX_PUBLIC_KEY_COMMITMENT = 'CRYPTO library 2025-08-26 18:30:00 prefix for commitment to public keys';\nexport const PREFIX_IDENTITY_KEY_COMMITMENT =\n 'CRYPTO library 2025-08-26 18:45:00 prefix for commitment to identity keys';\n\n// Second recommended parameter set from RFC 9106\nexport const ARGON2ID_PARALLELISM = 3;\nexport const ARGON2ID_ITERATIONS = 4;\nexport const ARGON2ID_MEMORY_SIZE = 65536;\nexport const ARGON2ID_SALT_BYTE_LENGTH = 16;\nexport const ARGON2ID_OUTPUT_BYTE_LENGTH = 32;\n\nexport const IDENTITY_KEYSTORE_TAG = 'Identity keystore';\nexport const ENCRYPTION_KEYSTORE_TAG = 'Encryption keystore';\nexport const RECOVERY_KEYSTORE_TAG = 'Key recovery keystroe';\nexport const INDEX_KEYSTORE_TAG = 'Current encrypted indices';\n\nexport const KYBER512_PUBLIC_KEY_LENGTH = 800;\nexport const KYBER512_SECRET_KEY_LENGTH = 1632;\n\nexport const KYBER768_PUBLIC_KEY_LENGTH = 1184;\nexport const KYBER768_SECRET_KEY_LENGTH = 2400;\n\nexport const KYBER1024_PUBLIC_KEY_LENGTH = 1568;\nexport const KYBER1024_SECRET_KEY_LENGTH = 3168;\n\nexport const KYBER_SEED_LENGTH = 64;\n\nexport const HASH_BIT_LEN = 256;\n\nexport const MAX_CACHE_SIZE = 600000000; // 600 MB\nexport const MAX_EMAIL_PER_BATCH = 100;\nexport const DB_LABEL = 'email';\nexport const DB_VERSION = 1;\n"]}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derives a symmetric key from the base key and context string
|
|
3
|
+
*
|
|
4
|
+
* @param context - The context string.
|
|
5
|
+
* The context string should be hardcoded, globally unique, and application-specific.
|
|
6
|
+
* @param baseKey - The base key (NOT PASSWORD!)
|
|
7
|
+
* @returns The derived secret key
|
|
8
|
+
*/
|
|
9
|
+
declare function deriveSymmetricKeyFromContext(context: string, baseKey: Uint8Array): Uint8Array;
|
|
10
|
+
/**
|
|
11
|
+
* Derives a symmetric CryptoKey from the base key and context string
|
|
12
|
+
*
|
|
13
|
+
* @param context - The context string.
|
|
14
|
+
* The context string should be hardcoded, globally unique, and application-specific.
|
|
15
|
+
* @param baseKey - The base key (NOT PASSWORD!)
|
|
16
|
+
* @returns The derived secret CryptoKey
|
|
17
|
+
*/
|
|
18
|
+
declare function deriveSymmetricCryptoKeyFromContext(context: string, baseKey: Uint8Array): Promise<CryptoKey>;
|
|
19
|
+
/**
|
|
20
|
+
* Derives a symmetric key from two keys
|
|
21
|
+
*
|
|
22
|
+
* @param key1 - The 32-bytes key
|
|
23
|
+
* @param key2 - The 32-bytes key
|
|
24
|
+
* @returns The derived secret key
|
|
25
|
+
*/
|
|
26
|
+
declare function deriveSymmetricKeyFromTwoKeys(key1: Uint8Array, key2: Uint8Array): Uint8Array;
|
|
27
|
+
/**
|
|
28
|
+
* Derives a symmetric CryptoKey from two keys
|
|
29
|
+
*
|
|
30
|
+
* @param key1 - The 32-bytes key
|
|
31
|
+
* @param key2 - The 32-bytes key
|
|
32
|
+
* @returns The derived secret CryptoKey
|
|
33
|
+
*/
|
|
34
|
+
declare function deriveSymmetricCryptoKeyFromTwoKeys(key1: Uint8Array, key2: Uint8Array): Promise<CryptoKey>;
|
|
35
|
+
/**
|
|
36
|
+
* Derives a symmetric key from two keys and context
|
|
37
|
+
*
|
|
38
|
+
* @param key1 - The 32-bytes key
|
|
39
|
+
* @param key2 - The 32-bytes key
|
|
40
|
+
* @param context - The context string
|
|
41
|
+
* @returns The derived symmetric key
|
|
42
|
+
*/
|
|
43
|
+
declare function deriveKeyFromTwoKeysAndContext(key1: Uint8Array, key2: Uint8Array, context: string): Uint8Array;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Derives a symmetric key from a user's password with a randomly sampled salt
|
|
47
|
+
*
|
|
48
|
+
* @param password - The user's password
|
|
49
|
+
* @returns The derived secret key and randomly sampled salt
|
|
50
|
+
*/
|
|
51
|
+
declare function getKeyFromPassword(password: string): Promise<{
|
|
52
|
+
key: Uint8Array;
|
|
53
|
+
salt: Uint8Array;
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Derives a symmetric key from a user's password and salt
|
|
57
|
+
*
|
|
58
|
+
* @param password - The user's password
|
|
59
|
+
* @param salt - The given salt
|
|
60
|
+
* @returns The derived secret key
|
|
61
|
+
*/
|
|
62
|
+
declare function getKeyFromPasswordAndSalt(password: string, salt: Uint8Array): Promise<Uint8Array>;
|
|
63
|
+
/**
|
|
64
|
+
* Derives a HEX symmetric key from a user's password with a randomly sampled salt
|
|
65
|
+
*
|
|
66
|
+
* @param password - The user's password
|
|
67
|
+
* @returns The derived HEX secret key and randomly sampled HEX salt
|
|
68
|
+
*/
|
|
69
|
+
declare function getKeyFromPasswordHex(password: string): Promise<{
|
|
70
|
+
keyHex: string;
|
|
71
|
+
saltHex: string;
|
|
72
|
+
}>;
|
|
73
|
+
/**
|
|
74
|
+
* Derives a HEX symmetric key from a user's password and salt
|
|
75
|
+
*
|
|
76
|
+
* @param password - The user's password
|
|
77
|
+
* @param saltHex - The given HEX salt
|
|
78
|
+
* @returns The derived HEX secret key
|
|
79
|
+
*/
|
|
80
|
+
declare function getKeyFromPasswordAndSaltHex(password: string, saltHex: string): Promise<string>;
|
|
81
|
+
/**
|
|
82
|
+
* Verifies the derived key
|
|
83
|
+
*
|
|
84
|
+
* @param password - The user's password
|
|
85
|
+
* @param saltHex - The given HEX salt
|
|
86
|
+
* @param keyHex - The derived HEX key
|
|
87
|
+
* @returns The result of the key verification
|
|
88
|
+
*/
|
|
89
|
+
declare function verifyKeyFromPasswordHex(password: string, saltHex: string, keyHex: string): Promise<boolean>;
|
|
90
|
+
|
|
91
|
+
export { deriveKeyFromTwoKeysAndContext, deriveSymmetricCryptoKeyFromContext, deriveSymmetricCryptoKeyFromTwoKeys, deriveSymmetricKeyFromContext, deriveSymmetricKeyFromTwoKeys, getKeyFromPassword, getKeyFromPasswordAndSalt, getKeyFromPasswordAndSaltHex, getKeyFromPasswordHex, verifyKeyFromPasswordHex };
|