internxt-crypto 0.0.10-alpha → 0.0.11
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/asymmetric-crypto-BORmLhnx.js +143 -0
- package/dist/asymmetric-crypto-BORmLhnx.js.map +1 -0
- package/dist/asymmetric-crypto-CyXsV4XT.mjs +102 -0
- package/dist/asymmetric-crypto-CyXsV4XT.mjs.map +1 -0
- package/dist/asymmetric-crypto.d.mts +9 -3
- package/dist/asymmetric-crypto.d.ts +9 -3
- package/dist/asymmetric-crypto.js +8 -92
- package/dist/asymmetric-crypto.mjs +2 -84
- package/dist/chunk-DWirmd9C.mjs +18 -0
- package/dist/chunk-Dt-PWiN7.js +60 -0
- package/dist/constants-Ccp21E03.js +208 -0
- package/dist/constants-Ccp21E03.js.map +1 -0
- package/dist/constants-kTeX-2T0.mjs +34 -0
- package/dist/constants-kTeX-2T0.mjs.map +1 -0
- package/dist/constants.d.mts +5 -11
- package/dist/constants.d.ts +5 -11
- package/dist/constants.js +30 -79
- package/dist/constants.mjs +2 -41
- package/dist/derive-key-Be7hS-cN.mjs +751 -0
- package/dist/derive-key-Be7hS-cN.mjs.map +1 -0
- package/dist/derive-key-CBf2WxJd.js +2513 -0
- package/dist/derive-key-CBf2WxJd.js.map +1 -0
- package/dist/derive-key.d.mts +14 -8
- package/dist/derive-key.d.ts +14 -8
- package/dist/derive-key.js +15 -795
- package/dist/derive-key.mjs +5 -783
- package/dist/email-crypto-BrT98taw.js +617 -0
- package/dist/email-crypto-BrT98taw.js.map +1 -0
- package/dist/email-crypto-DJUEjTxA.mjs +534 -0
- package/dist/email-crypto-DJUEjTxA.mjs.map +1 -0
- package/dist/email-crypto.d.mts +58 -78
- package/dist/email-crypto.d.ts +58 -78
- package/dist/email-crypto.js +17 -1409
- package/dist/email-crypto.mjs +8 -1381
- package/dist/email-search.d.mts +39 -32
- package/dist/email-search.d.ts +39 -32
- package/dist/email-search.js +572 -540
- package/dist/email-search.js.map +1 -1
- package/dist/email-search.mjs +567 -539
- package/dist/email-search.mjs.map +1 -1
- package/dist/hash-BoqwNkcd.js +190 -0
- package/dist/hash-BoqwNkcd.js.map +1 -0
- package/dist/hash-CXeGAwai.mjs +131 -0
- package/dist/hash-CXeGAwai.mjs.map +1 -0
- package/dist/hash.d.mts +21 -15
- package/dist/hash.d.ts +21 -15
- package/dist/hash.js +11 -95
- package/dist/hash.mjs +2 -84
- package/dist/index-CQqgKsbX.d.ts +50 -0
- package/dist/index-CintVUbp.d.ts +97 -0
- package/dist/index-D5pBU_A5.d.mts +50 -0
- package/dist/index-MaOov-ag.d.mts +97 -0
- package/dist/index.d.mts +35 -18
- package/dist/index.d.ts +35 -18
- package/dist/index.js +103 -2685
- package/dist/index.mjs +15 -2538
- package/dist/keystore-crypto-B4yCVo9l.js +182 -0
- package/dist/keystore-crypto-B4yCVo9l.js.map +1 -0
- package/dist/keystore-crypto-Bjgriq9h.mjs +159 -0
- package/dist/keystore-crypto-Bjgriq9h.mjs.map +1 -0
- package/dist/keystore-crypto.d.mts +20 -46
- package/dist/keystore-crypto.d.ts +20 -46
- package/dist/keystore-crypto.js +11 -530
- package/dist/keystore-crypto.mjs +9 -501
- package/dist/keystore-service.d.mts +44 -78
- package/dist/keystore-service.d.ts +44 -78
- package/dist/keystore-service.js +113 -340
- package/dist/keystore-service.js.map +1 -1
- package/dist/keystore-service.mjs +107 -335
- package/dist/keystore-service.mjs.map +1 -1
- package/dist/post-quantum-crypto-CAi-cEkV.js +189 -0
- package/dist/post-quantum-crypto-CAi-cEkV.js.map +1 -0
- package/dist/post-quantum-crypto-Vv34t6gX.mjs +154 -0
- package/dist/post-quantum-crypto-Vv34t6gX.mjs.map +1 -0
- package/dist/post-quantum-crypto.d.mts +2 -72
- package/dist/post-quantum-crypto.d.ts +2 -72
- package/dist/post-quantum-crypto.js +13 -92
- package/dist/post-quantum-crypto.mjs +2 -89
- package/dist/storage-service-BgIK2aYZ.js +82 -0
- package/dist/storage-service-BgIK2aYZ.js.map +1 -0
- package/dist/storage-service-CubCbhY2.mjs +65 -0
- package/dist/storage-service-CubCbhY2.mjs.map +1 -0
- package/dist/storage-service.d.mts +2 -53
- package/dist/storage-service.d.ts +2 -53
- package/dist/storage-service.js +12 -68
- package/dist/storage-service.mjs +2 -66
- package/dist/symmetric-crypto-CrdS1Che.mjs +197 -0
- package/dist/symmetric-crypto-CrdS1Che.mjs.map +1 -0
- package/dist/symmetric-crypto-D65zB396.js +244 -0
- package/dist/symmetric-crypto-D65zB396.js.map +1 -0
- package/dist/symmetric-crypto.d.mts +12 -8
- package/dist/symmetric-crypto.d.ts +12 -8
- package/dist/symmetric-crypto.js +10 -142
- package/dist/symmetric-crypto.mjs +3 -133
- package/dist/types-52g887Zi.js +16 -0
- package/dist/types-52g887Zi.js.map +1 -0
- package/dist/types-BiEoleqw.mjs +10 -0
- package/dist/types-BiEoleqw.mjs.map +1 -0
- package/dist/types-Ds3ivE9W.d.ts +104 -0
- package/dist/types-DwQJtrTx.d.mts +104 -0
- package/dist/types.d.mts +2 -102
- package/dist/types.d.ts +2 -102
- package/dist/types.js +2 -13
- package/dist/types.mjs +2 -11
- package/dist/utils-CNs3cyDj.js +263 -0
- package/dist/utils-CNs3cyDj.js.map +1 -0
- package/dist/utils-DS04iUcX.mjs +173 -0
- package/dist/utils-DS04iUcX.mjs.map +1 -0
- package/dist/utils.d.mts +37 -78
- package/dist/utils.d.ts +37 -78
- package/dist/utils.js +16 -313
- package/dist/utils.mjs +2 -272
- package/package.json +15 -90
- package/dist/asymmetric-crypto.js.map +0 -1
- package/dist/asymmetric-crypto.mjs.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/constants.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/kyber768-B87rMQ7u.d.mts +0 -30
- package/dist/kyber768-B87rMQ7u.d.ts +0 -30
- package/dist/post-quantum-crypto.js.map +0 -1
- package/dist/post-quantum-crypto.mjs.map +0 -1
- package/dist/storage-service.js.map +0 -1
- package/dist/storage-service.mjs.map +0 -1
- package/dist/symmetric-crypto.js.map +0 -1
- package/dist/symmetric-crypto.mjs.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/types.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
package/dist/email-service.d.mts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { EmailPublicParameters, HybridEncryptedEmail, PwdProtectedEmail } from './types.mjs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Email sender class
|
|
5
|
-
*
|
|
6
|
-
*/
|
|
7
|
-
declare class EmailServiceAPI {
|
|
8
|
-
private readonly serviceId;
|
|
9
|
-
private readonly templateId;
|
|
10
|
-
private readonly publicKey;
|
|
11
|
-
constructor(serviceId: string, templateId: string, publicKey: string);
|
|
12
|
-
/**
|
|
13
|
-
* Sends an email to the server
|
|
14
|
-
*
|
|
15
|
-
* @param content - The email content (encrypted)
|
|
16
|
-
* @param param - The email public parameters
|
|
17
|
-
* @returns The server response
|
|
18
|
-
*/
|
|
19
|
-
sendEmail(content: string, param: EmailPublicParameters): Promise<void>;
|
|
20
|
-
/**
|
|
21
|
-
* Sends a hybridly encrypted email to a particular recipient recipient
|
|
22
|
-
*
|
|
23
|
-
* @param encryptedEmail - The hybridly encrypted email
|
|
24
|
-
* @returns The server reply
|
|
25
|
-
*/
|
|
26
|
-
sendHybridEmail(encryptedEmail: HybridEncryptedEmail): Promise<void>;
|
|
27
|
-
/**
|
|
28
|
-
* Sends a password-protected email to a particular recipient
|
|
29
|
-
*
|
|
30
|
-
* @param protectedEmail - The password protected email
|
|
31
|
-
* @param recipient - The email recipient
|
|
32
|
-
* @returns The server reply
|
|
33
|
-
*/
|
|
34
|
-
sendPwdProtectedEmail(protectedEmail: PwdProtectedEmail): Promise<void>;
|
|
35
|
-
}
|
|
36
|
-
declare function getEmailServiceAPI(serviceId: string, templateId: string, publicKey: string): EmailServiceAPI;
|
|
37
|
-
|
|
38
|
-
export { EmailServiceAPI, getEmailServiceAPI };
|
package/dist/email-service.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { EmailPublicParameters, HybridEncryptedEmail, PwdProtectedEmail } from './types.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Email sender class
|
|
5
|
-
*
|
|
6
|
-
*/
|
|
7
|
-
declare class EmailServiceAPI {
|
|
8
|
-
private readonly serviceId;
|
|
9
|
-
private readonly templateId;
|
|
10
|
-
private readonly publicKey;
|
|
11
|
-
constructor(serviceId: string, templateId: string, publicKey: string);
|
|
12
|
-
/**
|
|
13
|
-
* Sends an email to the server
|
|
14
|
-
*
|
|
15
|
-
* @param content - The email content (encrypted)
|
|
16
|
-
* @param param - The email public parameters
|
|
17
|
-
* @returns The server response
|
|
18
|
-
*/
|
|
19
|
-
sendEmail(content: string, param: EmailPublicParameters): Promise<void>;
|
|
20
|
-
/**
|
|
21
|
-
* Sends a hybridly encrypted email to a particular recipient recipient
|
|
22
|
-
*
|
|
23
|
-
* @param encryptedEmail - The hybridly encrypted email
|
|
24
|
-
* @returns The server reply
|
|
25
|
-
*/
|
|
26
|
-
sendHybridEmail(encryptedEmail: HybridEncryptedEmail): Promise<void>;
|
|
27
|
-
/**
|
|
28
|
-
* Sends a password-protected email to a particular recipient
|
|
29
|
-
*
|
|
30
|
-
* @param protectedEmail - The password protected email
|
|
31
|
-
* @param recipient - The email recipient
|
|
32
|
-
* @returns The server reply
|
|
33
|
-
*/
|
|
34
|
-
sendPwdProtectedEmail(protectedEmail: PwdProtectedEmail): Promise<void>;
|
|
35
|
-
}
|
|
36
|
-
declare function getEmailServiceAPI(serviceId: string, templateId: string, publicKey: string): EmailServiceAPI;
|
|
37
|
-
|
|
38
|
-
export { EmailServiceAPI, getEmailServiceAPI };
|
package/dist/email-service.js
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var emailjs = require('@emailjs/browser');
|
|
4
|
-
require('@noble/hashes/utils.js');
|
|
5
|
-
|
|
6
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
-
|
|
8
|
-
var emailjs__default = /*#__PURE__*/_interopDefault(emailjs);
|
|
9
|
-
|
|
10
|
-
// src/email-service/api-send.ts
|
|
11
|
-
function uint8ArrayToBase64(buffer) {
|
|
12
|
-
const array = Uint16Array.from(buffer);
|
|
13
|
-
const binaryString = new TextDecoder("UTF-16").decode(array);
|
|
14
|
-
return btoa(binaryString);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// src/utils/aesConverters.ts
|
|
18
|
-
function ciphertextToBase64(encryptedMessage) {
|
|
19
|
-
try {
|
|
20
|
-
const ivBase64 = uint8ArrayToBase64(encryptedMessage.iv);
|
|
21
|
-
const ciphertextBase64 = uint8ArrayToBase64(encryptedMessage.ciphertext);
|
|
22
|
-
const json = JSON.stringify({ ciphertext: ciphertextBase64, iv: ivBase64 });
|
|
23
|
-
const base64 = btoa(json);
|
|
24
|
-
return base64;
|
|
25
|
-
} catch (error) {
|
|
26
|
-
throw new Error("Failed to convert ciphertext to base64", { cause: error });
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// src/email-crypto/converters.ts
|
|
31
|
-
function encHybridKeyToBase64(encHybridKey) {
|
|
32
|
-
try {
|
|
33
|
-
const json = JSON.stringify({
|
|
34
|
-
kyberCiphertext: uint8ArrayToBase64(encHybridKey.kyberCiphertext),
|
|
35
|
-
encryptedKey: uint8ArrayToBase64(encHybridKey.encryptedKey)
|
|
36
|
-
});
|
|
37
|
-
const base64 = btoa(json);
|
|
38
|
-
return base64;
|
|
39
|
-
} catch (error) {
|
|
40
|
-
throw new Error("Failed to convert hybrid key to base64", { cause: error });
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function pwdProtectedKeyToBase64(pwdProtectedKey) {
|
|
44
|
-
try {
|
|
45
|
-
const json = JSON.stringify({
|
|
46
|
-
encryptedKey: uint8ArrayToBase64(pwdProtectedKey.encryptedKey),
|
|
47
|
-
salt: uint8ArrayToBase64(pwdProtectedKey.salt)
|
|
48
|
-
});
|
|
49
|
-
const base64 = btoa(json);
|
|
50
|
-
return base64;
|
|
51
|
-
} catch (error) {
|
|
52
|
-
throw new Error("Failed to convert password-protected key to base64", { cause: error });
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
function hybridEncyptedEmailToBase64(email) {
|
|
56
|
-
try {
|
|
57
|
-
const json = JSON.stringify({
|
|
58
|
-
encryptedKey: encHybridKeyToBase64(email.encryptedKey),
|
|
59
|
-
enc: ciphertextToBase64(email.enc),
|
|
60
|
-
recipientEmail: email.recipientEmail
|
|
61
|
-
});
|
|
62
|
-
const base64 = btoa(json);
|
|
63
|
-
return base64;
|
|
64
|
-
} catch (error) {
|
|
65
|
-
throw new Error("Failed to convert hybrid email to base64", { cause: error });
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
function pwdProtectedEmailToBase64(email) {
|
|
69
|
-
try {
|
|
70
|
-
const json = JSON.stringify({
|
|
71
|
-
encryptedKey: pwdProtectedKeyToBase64(email.encryptedKey),
|
|
72
|
-
enc: ciphertextToBase64(email.enc)
|
|
73
|
-
});
|
|
74
|
-
const base64 = btoa(json);
|
|
75
|
-
return base64;
|
|
76
|
-
} catch (error) {
|
|
77
|
-
throw new Error("Failed to convert pwd protected email to base64", { cause: error });
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// src/email-service/api-send.ts
|
|
82
|
-
var EmailServiceAPI = class {
|
|
83
|
-
serviceId;
|
|
84
|
-
templateId;
|
|
85
|
-
publicKey;
|
|
86
|
-
constructor(serviceId, templateId, publicKey) {
|
|
87
|
-
this.serviceId = serviceId;
|
|
88
|
-
this.templateId = templateId;
|
|
89
|
-
this.publicKey = publicKey;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Sends an email to the server
|
|
93
|
-
*
|
|
94
|
-
* @param content - The email content (encrypted)
|
|
95
|
-
* @param param - The email public parameters
|
|
96
|
-
* @returns The server response
|
|
97
|
-
*/
|
|
98
|
-
async sendEmail(content, param) {
|
|
99
|
-
try {
|
|
100
|
-
const templateParams = {
|
|
101
|
-
from_email: param.sender.email,
|
|
102
|
-
from_name: param.sender.name,
|
|
103
|
-
to_email: param.recipient.email,
|
|
104
|
-
to_name: param.recipient.name,
|
|
105
|
-
email_subject: param.subject,
|
|
106
|
-
email_body: content,
|
|
107
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
108
|
-
};
|
|
109
|
-
await emailjs__default.default.send(this.serviceId, this.templateId, templateParams, this.publicKey);
|
|
110
|
-
} catch (error) {
|
|
111
|
-
throw new Error(`Failed to send an email ${error.message}`, { cause: error });
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Sends a hybridly encrypted email to a particular recipient recipient
|
|
116
|
-
*
|
|
117
|
-
* @param encryptedEmail - The hybridly encrypted email
|
|
118
|
-
* @returns The server reply
|
|
119
|
-
*/
|
|
120
|
-
async sendHybridEmail(encryptedEmail) {
|
|
121
|
-
try {
|
|
122
|
-
if (encryptedEmail.recipientEmail !== encryptedEmail.params.recipient.email) {
|
|
123
|
-
throw new Error("Email is encrypted for another recipient");
|
|
124
|
-
}
|
|
125
|
-
const body = hybridEncyptedEmailToBase64(encryptedEmail);
|
|
126
|
-
await this.sendEmail(body, encryptedEmail.params);
|
|
127
|
-
} catch (error) {
|
|
128
|
-
throw new Error(`Failed to email to the recipient: ${error.message}`, { cause: error });
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Sends a password-protected email to a particular recipient
|
|
133
|
-
*
|
|
134
|
-
* @param protectedEmail - The password protected email
|
|
135
|
-
* @param recipient - The email recipient
|
|
136
|
-
* @returns The server reply
|
|
137
|
-
*/
|
|
138
|
-
async sendPwdProtectedEmail(protectedEmail) {
|
|
139
|
-
try {
|
|
140
|
-
const body = pwdProtectedEmailToBase64(protectedEmail);
|
|
141
|
-
await this.sendEmail(body, protectedEmail.params);
|
|
142
|
-
} catch (error) {
|
|
143
|
-
throw new Error(`Failed to email to the recipient ${error.message}`, { cause: error });
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
function getEmailServiceAPI(serviceId, templateId, publicKey) {
|
|
148
|
-
return new EmailServiceAPI(serviceId, templateId, publicKey);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
exports.EmailServiceAPI = EmailServiceAPI;
|
|
152
|
-
exports.getEmailServiceAPI = getEmailServiceAPI;
|
|
153
|
-
//# sourceMappingURL=email-service.js.map
|
|
154
|
-
//# sourceMappingURL=email-service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/converters.ts","../src/utils/aesConverters.ts","../src/email-crypto/converters.ts","../src/email-service/api-send.ts"],"names":["emailjs"],"mappings":";;;;;;;;;;AAgDO,SAAS,mBAAmB,MAAA,EAA4B;AAC7D,EAAA,MAAM,KAAA,GAAQ,WAAA,CAAY,IAAA,CAAK,MAAM,CAAA;AACrC,EAAA,MAAM,eAAe,IAAI,WAAA,CAAY,QAAQ,CAAA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;AACvD,MAAA,MAAM,IAAA,CAAK,SAAA,CAAU,IAAA,EAAM,cAAA,CAAe,MAAM,CAAA;AAAA,IAClD,SAAS,KAAA,EAAO;AACd,MAAA,MAAM,IAAI,MAAM,CAAA,kCAAA,EAAsC,KAAA,CAAgB,OAAO,CAAA,CAAA,EAAI,EAAE,KAAA,EAAO,KAAA,EAAO,CAAA;AAAA,IACnG;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,sBAAsB,cAAA,EAAmC;AAC7D,IAAA,IAAI;AACF,MAAA,MAAM,IAAA,GAAO,0BAA0B,cAAc,CAAA;AACrD,MAAA,MAAM,IAAA,CAAK,SAAA,CAAU,IAAA,EAAM,cAAA,CAAe,MAAM,CAAA;AAAA,IAClD,SAAS,KAAA,EAAO;AACd,MAAA,MAAM,IAAI,MAAM,CAAA,iCAAA,EAAqC,KAAA,CAAgB,OAAO,CAAA,CAAA,EAAI,EAAE,KAAA,EAAO,KAAA,EAAO,CAAA;AAAA,IAClG;AAAA,EACF;AACF;AAEO,SAAS,kBAAA,CAAmB,SAAA,EAAmB,UAAA,EAAoB,SAAA,EAAoC;AAC5G,EAAA,OAAO,IAAI,eAAA,CAAgB,SAAA,EAAW,UAAA,EAAY,SAAS,CAAA;AAC7D","file":"email-service.js","sourcesContent":["import { bytesToHex, hexToBytes } from '@noble/hashes/utils.js';\n\n/**\n * Converts a Uint8Array into a hexadecimal string.\n *\n * @param array - The Uint8Array to convert.\n * @returns The hexadecimal string representation of the array.\n */\nexport function uint8ArrayToHex(array: Uint8Array): string {\n return bytesToHex(array);\n}\n\n/**\n * Converts a UTF-8 string into a Uint8Array.\n *\n * @param str - The UTF-8 string to convert.\n * @returns A Uint8Array created from the UTF-8 string.\n */\nexport function UTF8ToUint8(str: string): Uint8Array {\n return new TextEncoder().encode(str);\n}\n\n/**\n * Converts an Uint8Array into a UTF-8 string.\n *\n * @param array - The Uint8Array to convert.\n * @returns The UTF-8 string representation of the array.\n */\nexport function uint8ToUTF8(array: Uint8Array): string {\n return new TextDecoder().decode(array);\n}\n\n/**\n * Converts a hexadecimal string into a Uint8Array.\n *\n * @param hex - The hexadecimal string to convert.\n * @returns A Uint8Array created from the hex string.\n */\nexport function hexToUint8Array(hex: string): Uint8Array {\n return hexToBytes(hex);\n}\n\n/**\n * Converts a Uint8Array into a base64 string.\n *\n * @param array - The Uint8Array to convert.\n * @returns The base64 string representation of the array.\n */\nexport function uint8ArrayToBase64(buffer: Uint8Array): string {\n const array = Uint16Array.from(buffer);\n const binaryString = new TextDecoder('UTF-16').decode(array);\n return btoa(binaryString);\n}\n\n/**\n * Converts a base64 string into a Uint8Array.\n *\n * @param str - The base64 string to convert.\n * @returns A Uint8Array created from the base64 string.\n */\nexport function base64ToUint8Array(str: string): Uint8Array {\n const binaryString = atob(str);\n const len = binaryString.length;\n const array = new Uint8Array(len);\n for (let i = 0; i < len; i++) {\n array[i] = binaryString.charCodeAt(i);\n }\n return new Uint8Array(array.buffer);\n}\n","import { uint8ArrayToBase64, base64ToUint8Array } from './converters';\nimport { SymmetricCiphertext } from '../types';\n\n/**\n * Converts encrypted message to base64 string\n *\n * @param encryptedMessage - The encrypted message\n * @returns The resulting base64 string.\n */\nexport function ciphertextToBase64(encryptedMessage: SymmetricCiphertext): string {\n try {\n const ivBase64 = uint8ArrayToBase64(encryptedMessage.iv);\n const ciphertextBase64 = uint8ArrayToBase64(encryptedMessage.ciphertext);\n const json = JSON.stringify({ ciphertext: ciphertextBase64, iv: ivBase64 });\n const base64 = btoa(json);\n return base64;\n } catch (error) {\n throw new Error('Failed to convert ciphertext to base64', { cause: error });\n }\n}\n\n/**\n * Converts base64 string to encrypted message\n *\n * @param base64 - The base64 representation of the encrypted message\n * @returns The resulting encrypted message.\n */\nexport function base64ToCiphertext(base64: string): SymmetricCiphertext {\n try {\n const json = atob(base64);\n const obj = JSON.parse(json);\n const iv = base64ToUint8Array(obj.iv);\n const ciphertext = base64ToUint8Array(obj.ciphertext);\n const result: SymmetricCiphertext = {\n ciphertext,\n iv,\n };\n return result;\n } catch (error) {\n throw new Error('Failed to convert base64 to ciphertext', { cause: error });\n }\n}\n","import { uint8ArrayToBase64, base64ToUint8Array, UTF8ToUint8, uint8ToUTF8, ciphertextToBase64 } from '../utils';\nimport {\n EmailBody,\n HybridEncKey,\n PwdProtectedKey,\n User,\n EmailPublicParameters,\n HybridEncryptedEmail,\n PwdProtectedEmail,\n Email,\n} from '../types';\n\n/**\n * Converts a User type into a base64 string.\n *\n * @param user - The given user.\n * @returns The base64 representation of the user.\n */\nexport function userToBase64(user: User): string {\n try {\n const json = JSON.stringify(user);\n return btoa(json);\n } catch (error) {\n throw new Error('Failed to convert User to base64', { cause: error });\n }\n}\n\n/**\n * Converts a base64 string into a User type\n *\n * @param base64 - The base64 representation of the user.\n * @returns The User type.\n */\nexport function base64ToUser(base64: string): User {\n try {\n const json = atob(base64);\n const user: User = JSON.parse(json);\n return user;\n } catch (error) {\n throw new Error('Failed to convert base64 to User', { cause: error });\n }\n}\n\n/**\n * Converts an EmailBody type into a Uint8Array array.\n *\n * @param body - The email body.\n * @returns The Uint8Array array representation of the EmailBody type.\n */\nexport function emailBodyToBinary(body: EmailBody): Uint8Array {\n try {\n const json = JSON.stringify(body);\n return UTF8ToUint8(json);\n } catch (error) {\n throw new Error('Failed to convert EmailBody to Uint8Array', { cause: error });\n }\n}\n\n/**\n * Converts an Uint8Array array into EmailBody type.\n *\n * @param array - The Uint8Array array.\n * @returns The EmailBody type representation of the Uint8Array.\n */\nexport function binaryToEmailBody(array: Uint8Array): EmailBody {\n try {\n const json = uint8ToUTF8(array);\n const email: EmailBody = JSON.parse(json);\n return email;\n } catch (error) {\n throw new Error('Failed to convert Uint8Array to EmailBody', { cause: error });\n }\n}\n\n/**\n * Converts a hybrid key of the type HybridEncKey into base64 string.\n *\n * @param encHybridKey - The HybridEncKey key.\n * @returns The resulting base64 key encoding.\n */\nexport function encHybridKeyToBase64(encHybridKey: HybridEncKey): string {\n try {\n const json = JSON.stringify({\n kyberCiphertext: uint8ArrayToBase64(encHybridKey.kyberCiphertext),\n encryptedKey: uint8ArrayToBase64(encHybridKey.encryptedKey),\n });\n const base64 = btoa(json);\n return base64;\n } catch (error) {\n throw new Error('Failed to convert hybrid key to base64', { cause: error });\n }\n}\n\n/**\n * Converts a base64 string into a hybrid key of the type HybridEncKey.\n *\n * @param base - The base64 encoding of the hybrid key.\n * @returns The resulting HybridEncKey key.\n */\nexport function base64ToEncHybridKey(base64: string): HybridEncKey {\n try {\n const json = atob(base64);\n const obj = JSON.parse(json);\n return {\n encryptedKey: base64ToUint8Array(obj.encryptedKey),\n kyberCiphertext: base64ToUint8Array(obj.kyberCiphertext),\n };\n } catch (error) {\n throw new Error('Failed to convert base64 to hybrid key', { cause: error });\n }\n}\n\n/**\n * Converts a password-protected key of the type PwdProtectedKey into base64 string.\n *\n * @param pwdProtectedKey - The password-protected key of the type PwdProtectedKey.\n * @returns The resulting base64 key encoding.\n */\nexport function pwdProtectedKeyToBase64(pwdProtectedKey: PwdProtectedKey): string {\n try {\n const json = JSON.stringify({\n encryptedKey: uint8ArrayToBase64(pwdProtectedKey.encryptedKey),\n salt: uint8ArrayToBase64(pwdProtectedKey.salt),\n });\n const base64 = btoa(json);\n return base64;\n } catch (error) {\n throw new Error('Failed to convert password-protected key to base64', { cause: error });\n }\n}\n\n/**\n * Converts a base64 string into a password-protected key of the type PwdProtectedKey.\n *\n * @param base64 - The base64 string.\n * @returns The resulting PwdProtectedKey key.\n */\nexport function base64ToPwdProtectedKey(base64: string): PwdProtectedKey {\n try {\n const json = atob(base64);\n const obj = JSON.parse(json);\n return {\n encryptedKey: base64ToUint8Array(obj.encryptedKey),\n salt: base64ToUint8Array(obj.salt),\n };\n } catch (error) {\n throw new Error('Failed to convert base64 to password-protected key', { cause: error });\n }\n}\n\n/**\n * Converts an email public parameters of type EmailPublicParameters into base64 string.\n *\n * @param params - The EmailPublicParameters email paramaters.\n * @returns The resulting base64 string encoding.\n */\nexport function paramsToBase64(params: EmailPublicParameters): string {\n try {\n const json = JSON.stringify({\n ...params,\n sender: userToBase64(params.sender),\n recipient: userToBase64(params.recipient),\n recipients: params.recipients?.map(userToBase64),\n });\n const base64 = btoa(json);\n return base64;\n } catch (error) {\n throw new Error('Failed to convert email public parameters to base64', { cause: error });\n }\n}\n\n/**\n * Converts a base64 string into an email paramaters of the type EmailPublicParameters.\n *\n * @param base64 - The base64 string.\n * @returns The resulting EmailPublicParameters email parameters.\n */\nexport function base64ToParams(base64: string): EmailPublicParameters {\n try {\n const json = atob(base64);\n const obj = JSON.parse(json);\n return {\n ...obj,\n sender: base64ToUser(obj.sender),\n recipient: base64ToUser(obj.recipient),\n recipients: obj.recipients?.map(base64ToUser),\n };\n } catch (error) {\n throw new Error('Failed to convert base64 to email params', { cause: error });\n }\n}\n\n/**\n * Converts an encrypted via hybrid encryption email into base64 string.\n *\n * @param email - The HybridEncryptedEmail encrypted via hybrid encryption email.\n * @returns The resulting base64 string encoding.\n */\nexport function hybridEncyptedEmailToBase64(email: HybridEncryptedEmail): string {\n try {\n const json = JSON.stringify({\n encryptedKey: encHybridKeyToBase64(email.encryptedKey),\n enc: ciphertextToBase64(email.enc),\n recipientEmail: email.recipientEmail,\n });\n const base64 = btoa(json);\n return base64;\n } catch (error) {\n throw new Error('Failed to convert hybrid email to base64', { cause: error });\n }\n}\n\n/**\n * Converts a pwd protected email into base64 string.\n *\n * @param email - The PwdProtectedEmail pwd protected email.\n * @returns The resulting base64 string encoding.\n */\nexport function pwdProtectedEmailToBase64(email: PwdProtectedEmail): string {\n try {\n const json = JSON.stringify({\n encryptedKey: pwdProtectedKeyToBase64(email.encryptedKey),\n enc: ciphertextToBase64(email.enc),\n });\n const base64 = btoa(json);\n return base64;\n } catch (error) {\n throw new Error('Failed to convert pwd protected email to base64', { cause: error });\n }\n}\n\n/**\n * Converts an Email type into a Uint8Array array.\n *\n * @param email - The email.\n * @returns The Uint8Array array representation of the Email type.\n */\nexport function emailToBinary(email: Email): Uint8Array {\n try {\n const json = JSON.stringify(email);\n return UTF8ToUint8(json);\n } catch (error) {\n throw new Error('Failed to convert EmailBody to Uint8Array', { cause: error });\n }\n}\n","import emailjs from '@emailjs/browser';\nimport { EmailPublicParameters, HybridEncryptedEmail, PwdProtectedEmail } from '../types';\nimport { hybridEncyptedEmailToBase64, pwdProtectedEmailToBase64 } from '../email-crypto/converters';\n\n/**\n * Email sender class\n *\n */\nexport class EmailServiceAPI {\n private readonly serviceId: string;\n private readonly templateId: string;\n private readonly publicKey: string;\n\n constructor(serviceId: string, templateId: string, publicKey: string) {\n this.serviceId = serviceId;\n this.templateId = templateId;\n this.publicKey = publicKey;\n }\n\n /**\n * Sends an email to the server\n *\n * @param content - The email content (encrypted)\n * @param param - The email public parameters\n * @returns The server response\n */\n async sendEmail(content: string, param: EmailPublicParameters) {\n try {\n const templateParams = {\n from_email: param.sender.email,\n from_name: param.sender.name,\n to_email: param.recipient.email,\n to_name: param.recipient.name,\n email_subject: param.subject,\n email_body: content,\n timestamp: new Date().toISOString(),\n };\n\n await emailjs.send(this.serviceId, this.templateId, templateParams, this.publicKey);\n } catch (error) {\n throw new Error(`Failed to send an email ${(error as Error).message}`, { cause: error });\n }\n }\n\n /**\n * Sends a hybridly encrypted email to a particular recipient recipient\n *\n * @param encryptedEmail - The hybridly encrypted email\n * @returns The server reply\n */\n async sendHybridEmail(encryptedEmail: HybridEncryptedEmail) {\n try {\n if (encryptedEmail.recipientEmail !== encryptedEmail.params.recipient.email) {\n throw new Error('Email is encrypted for another recipient');\n }\n const body = hybridEncyptedEmailToBase64(encryptedEmail);\n await this.sendEmail(body, encryptedEmail.params);\n } catch (error) {\n throw new Error(`Failed to email to the recipient: ${(error as Error).message}`, { cause: error });\n }\n }\n\n /**\n * Sends a password-protected email to a particular recipient\n *\n * @param protectedEmail - The password protected email\n * @param recipient - The email recipient\n * @returns The server reply\n */\n async sendPwdProtectedEmail(protectedEmail: PwdProtectedEmail) {\n try {\n const body = pwdProtectedEmailToBase64(protectedEmail);\n await this.sendEmail(body, protectedEmail.params);\n } catch (error) {\n throw new Error(`Failed to email to the recipient ${(error as Error).message}`, { cause: error });\n }\n }\n}\n\nexport function getEmailServiceAPI(serviceId: string, templateId: string, publicKey: string): EmailServiceAPI {\n return new EmailServiceAPI(serviceId, templateId, publicKey);\n}\n"]}
|
package/dist/email-service.mjs
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import emailjs from '@emailjs/browser';
|
|
2
|
-
import '@noble/hashes/utils.js';
|
|
3
|
-
|
|
4
|
-
// src/email-service/api-send.ts
|
|
5
|
-
function uint8ArrayToBase64(buffer) {
|
|
6
|
-
const array = Uint16Array.from(buffer);
|
|
7
|
-
const binaryString = new TextDecoder("UTF-16").decode(array);
|
|
8
|
-
return btoa(binaryString);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// src/utils/aesConverters.ts
|
|
12
|
-
function ciphertextToBase64(encryptedMessage) {
|
|
13
|
-
try {
|
|
14
|
-
const ivBase64 = uint8ArrayToBase64(encryptedMessage.iv);
|
|
15
|
-
const ciphertextBase64 = uint8ArrayToBase64(encryptedMessage.ciphertext);
|
|
16
|
-
const json = JSON.stringify({ ciphertext: ciphertextBase64, iv: ivBase64 });
|
|
17
|
-
const base64 = btoa(json);
|
|
18
|
-
return base64;
|
|
19
|
-
} catch (error) {
|
|
20
|
-
throw new Error("Failed to convert ciphertext to base64", { cause: error });
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// src/email-crypto/converters.ts
|
|
25
|
-
function encHybridKeyToBase64(encHybridKey) {
|
|
26
|
-
try {
|
|
27
|
-
const json = JSON.stringify({
|
|
28
|
-
kyberCiphertext: uint8ArrayToBase64(encHybridKey.kyberCiphertext),
|
|
29
|
-
encryptedKey: uint8ArrayToBase64(encHybridKey.encryptedKey)
|
|
30
|
-
});
|
|
31
|
-
const base64 = btoa(json);
|
|
32
|
-
return base64;
|
|
33
|
-
} catch (error) {
|
|
34
|
-
throw new Error("Failed to convert hybrid key to base64", { cause: error });
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
function pwdProtectedKeyToBase64(pwdProtectedKey) {
|
|
38
|
-
try {
|
|
39
|
-
const json = JSON.stringify({
|
|
40
|
-
encryptedKey: uint8ArrayToBase64(pwdProtectedKey.encryptedKey),
|
|
41
|
-
salt: uint8ArrayToBase64(pwdProtectedKey.salt)
|
|
42
|
-
});
|
|
43
|
-
const base64 = btoa(json);
|
|
44
|
-
return base64;
|
|
45
|
-
} catch (error) {
|
|
46
|
-
throw new Error("Failed to convert password-protected key to base64", { cause: error });
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
function hybridEncyptedEmailToBase64(email) {
|
|
50
|
-
try {
|
|
51
|
-
const json = JSON.stringify({
|
|
52
|
-
encryptedKey: encHybridKeyToBase64(email.encryptedKey),
|
|
53
|
-
enc: ciphertextToBase64(email.enc),
|
|
54
|
-
recipientEmail: email.recipientEmail
|
|
55
|
-
});
|
|
56
|
-
const base64 = btoa(json);
|
|
57
|
-
return base64;
|
|
58
|
-
} catch (error) {
|
|
59
|
-
throw new Error("Failed to convert hybrid email to base64", { cause: error });
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
function pwdProtectedEmailToBase64(email) {
|
|
63
|
-
try {
|
|
64
|
-
const json = JSON.stringify({
|
|
65
|
-
encryptedKey: pwdProtectedKeyToBase64(email.encryptedKey),
|
|
66
|
-
enc: ciphertextToBase64(email.enc)
|
|
67
|
-
});
|
|
68
|
-
const base64 = btoa(json);
|
|
69
|
-
return base64;
|
|
70
|
-
} catch (error) {
|
|
71
|
-
throw new Error("Failed to convert pwd protected email to base64", { cause: error });
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// src/email-service/api-send.ts
|
|
76
|
-
var EmailServiceAPI = class {
|
|
77
|
-
serviceId;
|
|
78
|
-
templateId;
|
|
79
|
-
publicKey;
|
|
80
|
-
constructor(serviceId, templateId, publicKey) {
|
|
81
|
-
this.serviceId = serviceId;
|
|
82
|
-
this.templateId = templateId;
|
|
83
|
-
this.publicKey = publicKey;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Sends an email to the server
|
|
87
|
-
*
|
|
88
|
-
* @param content - The email content (encrypted)
|
|
89
|
-
* @param param - The email public parameters
|
|
90
|
-
* @returns The server response
|
|
91
|
-
*/
|
|
92
|
-
async sendEmail(content, param) {
|
|
93
|
-
try {
|
|
94
|
-
const templateParams = {
|
|
95
|
-
from_email: param.sender.email,
|
|
96
|
-
from_name: param.sender.name,
|
|
97
|
-
to_email: param.recipient.email,
|
|
98
|
-
to_name: param.recipient.name,
|
|
99
|
-
email_subject: param.subject,
|
|
100
|
-
email_body: content,
|
|
101
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
102
|
-
};
|
|
103
|
-
await emailjs.send(this.serviceId, this.templateId, templateParams, this.publicKey);
|
|
104
|
-
} catch (error) {
|
|
105
|
-
throw new Error(`Failed to send an email ${error.message}`, { cause: error });
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Sends a hybridly encrypted email to a particular recipient recipient
|
|
110
|
-
*
|
|
111
|
-
* @param encryptedEmail - The hybridly encrypted email
|
|
112
|
-
* @returns The server reply
|
|
113
|
-
*/
|
|
114
|
-
async sendHybridEmail(encryptedEmail) {
|
|
115
|
-
try {
|
|
116
|
-
if (encryptedEmail.recipientEmail !== encryptedEmail.params.recipient.email) {
|
|
117
|
-
throw new Error("Email is encrypted for another recipient");
|
|
118
|
-
}
|
|
119
|
-
const body = hybridEncyptedEmailToBase64(encryptedEmail);
|
|
120
|
-
await this.sendEmail(body, encryptedEmail.params);
|
|
121
|
-
} catch (error) {
|
|
122
|
-
throw new Error(`Failed to email to the recipient: ${error.message}`, { cause: error });
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Sends a password-protected email to a particular recipient
|
|
127
|
-
*
|
|
128
|
-
* @param protectedEmail - The password protected email
|
|
129
|
-
* @param recipient - The email recipient
|
|
130
|
-
* @returns The server reply
|
|
131
|
-
*/
|
|
132
|
-
async sendPwdProtectedEmail(protectedEmail) {
|
|
133
|
-
try {
|
|
134
|
-
const body = pwdProtectedEmailToBase64(protectedEmail);
|
|
135
|
-
await this.sendEmail(body, protectedEmail.params);
|
|
136
|
-
} catch (error) {
|
|
137
|
-
throw new Error(`Failed to email to the recipient ${error.message}`, { cause: error });
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
function getEmailServiceAPI(serviceId, templateId, publicKey) {
|
|
142
|
-
return new EmailServiceAPI(serviceId, templateId, publicKey);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export { EmailServiceAPI, getEmailServiceAPI };
|
|
146
|
-
//# sourceMappingURL=email-service.mjs.map
|
|
147
|
-
//# sourceMappingURL=email-service.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/converters.ts","../src/utils/aesConverters.ts","../src/email-crypto/converters.ts","../src/email-service/api-send.ts"],"names":[],"mappings":";;;;AAgDO,SAAS,mBAAmB,MAAA,EAA4B;AAC7D,EAAA,MAAM,KAAA,GAAQ,WAAA,CAAY,IAAA,CAAK,MAAM,CAAA;AACrC,EAAA,MAAM,eAAe,IAAI,WAAA,CAAY,QAAQ,CAAA,CAAE,OAAO,KAAK,CAAA;AAC3D,EAAA,OAAO,KAAK,YAAY,CAAA;AAC1B;;;AC3CO,SAAS,mBAAmB,gBAAA,EAA+C;AAChF,EAAA,IAAI;AACF,IAAA,MAAM,QAAA,GAAW,kBAAA,CAAmB,gBAAA,CAAiB,EAAE,CAAA;AACvD,IAAA,MAAM,gBAAA,GAAmB,kBAAA,CAAmB,gBAAA,CAAiB,UAAU,CAAA;AACvE,IAAA,MAAM,IAAA,GAAO,KAAK,SAAA,CAAU,EAAE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AA,EAAmC;AAC7D,IAAA,IAAI;AACF,MAAA,MAAM,IAAA,GAAO,0BAA0B,cAAc,CAAA;AACrD,MAAA,MAAM,IAAA,CAAK,SAAA,CAAU,IAAA,EAAM,cAAA,CAAe,MAAM,CAAA;AAAA,IAClD,SAAS,KAAA,EAAO;AACd,MAAA,MAAM,IAAI,MAAM,CAAA,iCAAA,EAAqC,KAAA,CAAgB,OAAO,CAAA,CAAA,EAAI,EAAE,KAAA,EAAO,KAAA,EAAO,CAAA;AAAA,IAClG;AAAA,EACF;AACF;AAEO,SAAS,kBAAA,CAAmB,SAAA,EAAmB,UAAA,EAAoB,SAAA,EAAoC;AAC5G,EAAA,OAAO,IAAI,eAAA,CAAgB,SAAA,EAAW,UAAA,EAAY,SAAS,CAAA;AAC7D","file":"email-service.mjs","sourcesContent":["import { bytesToHex, hexToBytes } from '@noble/hashes/utils.js';\n\n/**\n * Converts a Uint8Array into a hexadecimal string.\n *\n * @param array - The Uint8Array to convert.\n * @returns The hexadecimal string representation of the array.\n */\nexport function uint8ArrayToHex(array: Uint8Array): string {\n return bytesToHex(array);\n}\n\n/**\n * Converts a UTF-8 string into a Uint8Array.\n *\n * @param str - The UTF-8 string to convert.\n * @returns A Uint8Array created from the UTF-8 string.\n */\nexport function UTF8ToUint8(str: string): Uint8Array {\n return new TextEncoder().encode(str);\n}\n\n/**\n * Converts an Uint8Array into a UTF-8 string.\n *\n * @param array - The Uint8Array to convert.\n * @returns The UTF-8 string representation of the array.\n */\nexport function uint8ToUTF8(array: Uint8Array): string {\n return new TextDecoder().decode(array);\n}\n\n/**\n * Converts a hexadecimal string into a Uint8Array.\n *\n * @param hex - The hexadecimal string to convert.\n * @returns A Uint8Array created from the hex string.\n */\nexport function hexToUint8Array(hex: string): Uint8Array {\n return hexToBytes(hex);\n}\n\n/**\n * Converts a Uint8Array into a base64 string.\n *\n * @param array - The Uint8Array to convert.\n * @returns The base64 string representation of the array.\n */\nexport function uint8ArrayToBase64(buffer: Uint8Array): string {\n const array = Uint16Array.from(buffer);\n const binaryString = new TextDecoder('UTF-16').decode(array);\n return btoa(binaryString);\n}\n\n/**\n * Converts a base64 string into a Uint8Array.\n *\n * @param str - The base64 string to convert.\n * @returns A Uint8Array created from the base64 string.\n */\nexport function base64ToUint8Array(str: string): Uint8Array {\n const binaryString = atob(str);\n const len = binaryString.length;\n const array = new Uint8Array(len);\n for (let i = 0; i < len; i++) {\n array[i] = binaryString.charCodeAt(i);\n }\n return new Uint8Array(array.buffer);\n}\n","import { uint8ArrayToBase64, base64ToUint8Array } from './converters';\nimport { SymmetricCiphertext } from '../types';\n\n/**\n * Converts encrypted message to base64 string\n *\n * @param encryptedMessage - The encrypted message\n * @returns The resulting base64 string.\n */\nexport function ciphertextToBase64(encryptedMessage: SymmetricCiphertext): string {\n try {\n const ivBase64 = uint8ArrayToBase64(encryptedMessage.iv);\n const ciphertextBase64 = uint8ArrayToBase64(encryptedMessage.ciphertext);\n const json = JSON.stringify({ ciphertext: ciphertextBase64, iv: ivBase64 });\n const base64 = btoa(json);\n return base64;\n } catch (error) {\n throw new Error('Failed to convert ciphertext to base64', { cause: error });\n }\n}\n\n/**\n * Converts base64 string to encrypted message\n *\n * @param base64 - The base64 representation of the encrypted message\n * @returns The resulting encrypted message.\n */\nexport function base64ToCiphertext(base64: string): SymmetricCiphertext {\n try {\n const json = atob(base64);\n const obj = JSON.parse(json);\n const iv = base64ToUint8Array(obj.iv);\n const ciphertext = base64ToUint8Array(obj.ciphertext);\n const result: SymmetricCiphertext = {\n ciphertext,\n iv,\n };\n return result;\n } catch (error) {\n throw new Error('Failed to convert base64 to ciphertext', { cause: error });\n }\n}\n","import { uint8ArrayToBase64, base64ToUint8Array, UTF8ToUint8, uint8ToUTF8, ciphertextToBase64 } from '../utils';\nimport {\n EmailBody,\n HybridEncKey,\n PwdProtectedKey,\n User,\n EmailPublicParameters,\n HybridEncryptedEmail,\n PwdProtectedEmail,\n Email,\n} from '../types';\n\n/**\n * Converts a User type into a base64 string.\n *\n * @param user - The given user.\n * @returns The base64 representation of the user.\n */\nexport function userToBase64(user: User): string {\n try {\n const json = JSON.stringify(user);\n return btoa(json);\n } catch (error) {\n throw new Error('Failed to convert User to base64', { cause: error });\n }\n}\n\n/**\n * Converts a base64 string into a User type\n *\n * @param base64 - The base64 representation of the user.\n * @returns The User type.\n */\nexport function base64ToUser(base64: string): User {\n try {\n const json = atob(base64);\n const user: User = JSON.parse(json);\n return user;\n } catch (error) {\n throw new Error('Failed to convert base64 to User', { cause: error });\n }\n}\n\n/**\n * Converts an EmailBody type into a Uint8Array array.\n *\n * @param body - The email body.\n * @returns The Uint8Array array representation of the EmailBody type.\n */\nexport function emailBodyToBinary(body: EmailBody): Uint8Array {\n try {\n const json = JSON.stringify(body);\n return UTF8ToUint8(json);\n } catch (error) {\n throw new Error('Failed to convert EmailBody to Uint8Array', { cause: error });\n }\n}\n\n/**\n * Converts an Uint8Array array into EmailBody type.\n *\n * @param array - The Uint8Array array.\n * @returns The EmailBody type representation of the Uint8Array.\n */\nexport function binaryToEmailBody(array: Uint8Array): EmailBody {\n try {\n const json = uint8ToUTF8(array);\n const email: EmailBody = JSON.parse(json);\n return email;\n } catch (error) {\n throw new Error('Failed to convert Uint8Array to EmailBody', { cause: error });\n }\n}\n\n/**\n * Converts a hybrid key of the type HybridEncKey into base64 string.\n *\n * @param encHybridKey - The HybridEncKey key.\n * @returns The resulting base64 key encoding.\n */\nexport function encHybridKeyToBase64(encHybridKey: HybridEncKey): string {\n try {\n const json = JSON.stringify({\n kyberCiphertext: uint8ArrayToBase64(encHybridKey.kyberCiphertext),\n encryptedKey: uint8ArrayToBase64(encHybridKey.encryptedKey),\n });\n const base64 = btoa(json);\n return base64;\n } catch (error) {\n throw new Error('Failed to convert hybrid key to base64', { cause: error });\n }\n}\n\n/**\n * Converts a base64 string into a hybrid key of the type HybridEncKey.\n *\n * @param base - The base64 encoding of the hybrid key.\n * @returns The resulting HybridEncKey key.\n */\nexport function base64ToEncHybridKey(base64: string): HybridEncKey {\n try {\n const json = atob(base64);\n const obj = JSON.parse(json);\n return {\n encryptedKey: base64ToUint8Array(obj.encryptedKey),\n kyberCiphertext: base64ToUint8Array(obj.kyberCiphertext),\n };\n } catch (error) {\n throw new Error('Failed to convert base64 to hybrid key', { cause: error });\n }\n}\n\n/**\n * Converts a password-protected key of the type PwdProtectedKey into base64 string.\n *\n * @param pwdProtectedKey - The password-protected key of the type PwdProtectedKey.\n * @returns The resulting base64 key encoding.\n */\nexport function pwdProtectedKeyToBase64(pwdProtectedKey: PwdProtectedKey): string {\n try {\n const json = JSON.stringify({\n encryptedKey: uint8ArrayToBase64(pwdProtectedKey.encryptedKey),\n salt: uint8ArrayToBase64(pwdProtectedKey.salt),\n });\n const base64 = btoa(json);\n return base64;\n } catch (error) {\n throw new Error('Failed to convert password-protected key to base64', { cause: error });\n }\n}\n\n/**\n * Converts a base64 string into a password-protected key of the type PwdProtectedKey.\n *\n * @param base64 - The base64 string.\n * @returns The resulting PwdProtectedKey key.\n */\nexport function base64ToPwdProtectedKey(base64: string): PwdProtectedKey {\n try {\n const json = atob(base64);\n const obj = JSON.parse(json);\n return {\n encryptedKey: base64ToUint8Array(obj.encryptedKey),\n salt: base64ToUint8Array(obj.salt),\n };\n } catch (error) {\n throw new Error('Failed to convert base64 to password-protected key', { cause: error });\n }\n}\n\n/**\n * Converts an email public parameters of type EmailPublicParameters into base64 string.\n *\n * @param params - The EmailPublicParameters email paramaters.\n * @returns The resulting base64 string encoding.\n */\nexport function paramsToBase64(params: EmailPublicParameters): string {\n try {\n const json = JSON.stringify({\n ...params,\n sender: userToBase64(params.sender),\n recipient: userToBase64(params.recipient),\n recipients: params.recipients?.map(userToBase64),\n });\n const base64 = btoa(json);\n return base64;\n } catch (error) {\n throw new Error('Failed to convert email public parameters to base64', { cause: error });\n }\n}\n\n/**\n * Converts a base64 string into an email paramaters of the type EmailPublicParameters.\n *\n * @param base64 - The base64 string.\n * @returns The resulting EmailPublicParameters email parameters.\n */\nexport function base64ToParams(base64: string): EmailPublicParameters {\n try {\n const json = atob(base64);\n const obj = JSON.parse(json);\n return {\n ...obj,\n sender: base64ToUser(obj.sender),\n recipient: base64ToUser(obj.recipient),\n recipients: obj.recipients?.map(base64ToUser),\n };\n } catch (error) {\n throw new Error('Failed to convert base64 to email params', { cause: error });\n }\n}\n\n/**\n * Converts an encrypted via hybrid encryption email into base64 string.\n *\n * @param email - The HybridEncryptedEmail encrypted via hybrid encryption email.\n * @returns The resulting base64 string encoding.\n */\nexport function hybridEncyptedEmailToBase64(email: HybridEncryptedEmail): string {\n try {\n const json = JSON.stringify({\n encryptedKey: encHybridKeyToBase64(email.encryptedKey),\n enc: ciphertextToBase64(email.enc),\n recipientEmail: email.recipientEmail,\n });\n const base64 = btoa(json);\n return base64;\n } catch (error) {\n throw new Error('Failed to convert hybrid email to base64', { cause: error });\n }\n}\n\n/**\n * Converts a pwd protected email into base64 string.\n *\n * @param email - The PwdProtectedEmail pwd protected email.\n * @returns The resulting base64 string encoding.\n */\nexport function pwdProtectedEmailToBase64(email: PwdProtectedEmail): string {\n try {\n const json = JSON.stringify({\n encryptedKey: pwdProtectedKeyToBase64(email.encryptedKey),\n enc: ciphertextToBase64(email.enc),\n });\n const base64 = btoa(json);\n return base64;\n } catch (error) {\n throw new Error('Failed to convert pwd protected email to base64', { cause: error });\n }\n}\n\n/**\n * Converts an Email type into a Uint8Array array.\n *\n * @param email - The email.\n * @returns The Uint8Array array representation of the Email type.\n */\nexport function emailToBinary(email: Email): Uint8Array {\n try {\n const json = JSON.stringify(email);\n return UTF8ToUint8(json);\n } catch (error) {\n throw new Error('Failed to convert EmailBody to Uint8Array', { cause: error });\n }\n}\n","import emailjs from '@emailjs/browser';\nimport { EmailPublicParameters, HybridEncryptedEmail, PwdProtectedEmail } from '../types';\nimport { hybridEncyptedEmailToBase64, pwdProtectedEmailToBase64 } from '../email-crypto/converters';\n\n/**\n * Email sender class\n *\n */\nexport class EmailServiceAPI {\n private readonly serviceId: string;\n private readonly templateId: string;\n private readonly publicKey: string;\n\n constructor(serviceId: string, templateId: string, publicKey: string) {\n this.serviceId = serviceId;\n this.templateId = templateId;\n this.publicKey = publicKey;\n }\n\n /**\n * Sends an email to the server\n *\n * @param content - The email content (encrypted)\n * @param param - The email public parameters\n * @returns The server response\n */\n async sendEmail(content: string, param: EmailPublicParameters) {\n try {\n const templateParams = {\n from_email: param.sender.email,\n from_name: param.sender.name,\n to_email: param.recipient.email,\n to_name: param.recipient.name,\n email_subject: param.subject,\n email_body: content,\n timestamp: new Date().toISOString(),\n };\n\n await emailjs.send(this.serviceId, this.templateId, templateParams, this.publicKey);\n } catch (error) {\n throw new Error(`Failed to send an email ${(error as Error).message}`, { cause: error });\n }\n }\n\n /**\n * Sends a hybridly encrypted email to a particular recipient recipient\n *\n * @param encryptedEmail - The hybridly encrypted email\n * @returns The server reply\n */\n async sendHybridEmail(encryptedEmail: HybridEncryptedEmail) {\n try {\n if (encryptedEmail.recipientEmail !== encryptedEmail.params.recipient.email) {\n throw new Error('Email is encrypted for another recipient');\n }\n const body = hybridEncyptedEmailToBase64(encryptedEmail);\n await this.sendEmail(body, encryptedEmail.params);\n } catch (error) {\n throw new Error(`Failed to email to the recipient: ${(error as Error).message}`, { cause: error });\n }\n }\n\n /**\n * Sends a password-protected email to a particular recipient\n *\n * @param protectedEmail - The password protected email\n * @param recipient - The email recipient\n * @returns The server reply\n */\n async sendPwdProtectedEmail(protectedEmail: PwdProtectedEmail) {\n try {\n const body = pwdProtectedEmailToBase64(protectedEmail);\n await this.sendEmail(body, protectedEmail.params);\n } catch (error) {\n throw new Error(`Failed to email to the recipient ${(error as Error).message}`, { cause: error });\n }\n }\n}\n\nexport function getEmailServiceAPI(serviceId: string, templateId: string, publicKey: string): EmailServiceAPI {\n return new EmailServiceAPI(serviceId, templateId, publicKey);\n}\n"]}
|
package/dist/hash.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hash/blake3.ts","../src/const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,GAAM,kBAAA,CAAmB,kBAAA,GAAqB,CAAA,EAAG,WAAW,CAAA;AAClE,IAAA,MAAM,IAAA,GAAO,SAAA,CAAU,GAAA,EAAK,IAAI,CAAA;AAChC,IAAA,OAAOA,oBAAW,IAAI,CAAA;AAAA,EACxB,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,KAAA,CAAM,uBAAA,EAAyB,EAAE,KAAA,EAAO,OAAO,CAAA;AAAA,EAC3D;AACF","file":"hash.js","sourcesContent":["import { blake3 } from '@noble/hashes/blake3.js';\nimport { utf8ToBytes, 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 hashData(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\nexport function keyedHashHex(hashKey: Uint8Array, data: Uint8Array[]): string {\n try {\n const hash = keyedHash(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 keyedHash(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\n *\n * @param data - The data to hash\n * @returns The resulting hash hex string\n */\nexport function hashDataHex(data: Uint8Array[]): string {\n try {\n const hash = hashData(data);\n return bytesToHex(hash);\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 getBytesFromData(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 getBytesFromDataHex(bytes: number, data: Uint8Array[]): string {\n try {\n const hash = getBytesFromData(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 value - The string to hash\n * @returns The resulting hash value\n */\nexport function getBytesFromString(bytes: number, value: string): Uint8Array {\n return blake3(utf8ToBytes(value), { dkLen: bytes });\n}\n\n/**\n * Hashes the given string using blake3 algorithm\n *\n * @param bytes - The desired output byte-length\n * @param value - The string to hash\n * @returns The resulting hash value\n */\nexport function getBytesFromStrinHex(bytes: number, value: string): string {\n return bytesToHex(getBytesFromString(bytes, value));\n}\n","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 { bytesToHex } from '@noble/hashes/utils.js';\nimport { AES_KEY_BIT_LENGTH } from '../constants';\nimport { getBytesFromString, keyedHash } 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: string, data: Uint8Array[]): string {\n try {\n const key = getBytesFromString(AES_KEY_BIT_LENGTH / 8, keyMaterial);\n const hash = keyedHash(key, data);\n return bytesToHex(hash);\n } catch (error) {\n throw new Error('Failed to compute mac', { cause: error });\n }\n}\n"]}
|
package/dist/hash.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hash/blake3.ts","../src/constants.ts","../src/hash/mac.ts"],"names":["bytesToHex"],"mappings":";;;;AASO,SAAS,SAAS,IAAA,EAAgC;AACvD,EAAA,IAAI;AACF,IAAA,MAAM,MAAA,GAAS,OAAO,MAAA,EAAO;AAC7B,IAAA,KAAA,MAAW,KAAK,IAAA,EAAM;AACpB,MAAA,MAAA,CAAO,OAAO,CAAC,CAAA;AAAA,IACjB;AACA,IAAA,OAAO,OAAO,MAAA,EAAO;AAAA,EACvB,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,KAAA,CAAM,wBAAA,EAA0B,EAAE,KAAA,EAAO,OAAO,CAAA;AAAA,EAC5D;AACF;AAEO,SAAS,YAAA,CAAa,SAAqB,IAAA,EAA4B;AAC5E,EAAA,IAAI;AACF,IAAA,MAAM,IAAA,GAAO,SAAA,CAAU,OAAA,EAAS,IAAI,CAAA;AACpC,IAAA,OAAO,WAAW,IAAI,CAAA;AAAA,EACxB,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,KAAA,CAAM,4BAAA,EAA8B,EAAE,KAAA,EAAO,OAAO,CAAA;AAAA,EAChE;AACF;AAEO,SAAS,SAAA,CAAU,SAAqB,IAAA,EAAgC;AAC7E,EAAA,IAAI;AACF,IAAA,MAAM,SAAS,MAAA,CAAO,MAAA,CAAO,EAAE,GAAA,EAAK,SAAS,CAAA;AAC7C,IAAA,KAAA,MAAW,KAAK,IAAA,EAAM;AACpB,MAAA,MAAA,CAAO,OAAO,CAAC,CAAA;AAAA,IACjB;AACA,IAAA,OAAO,OAAO,MAAA,EAAO;AAAA,EACvB,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,KAAA,CAAM,wB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,KAAA,EAAO,KAAK,CAAC,CAAA;AACpD;;;AC/GO,IAAM,kBAAA,GAAqB,GAAA;;;ACU3B,SAAS,UAAA,CAAW,aAAqB,IAAA,EAA4B;AAC1E,EAAA,IAAI;AACF,IAAA,MAAM,GAAA,GAAM,kBAAA,CAAmB,kBAAA,GAAqB,CAAA,EAAG,WAAW,CAAA;AAClE,IAAA,MAAM,IAAA,GAAO,SAAA,CAAU,GAAA,EAAK,IAAI,CAAA;AAChC,IAAA,OAAOA,WAAW,IAAI,CAAA;AAAA,EACxB,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,KAAA,CAAM,uBAAA,EAAyB,EAAE,KAAA,EAAO,OAAO,CAAA;AAAA,EAC3D;AACF","file":"hash.mjs","sourcesContent":["import { blake3 } from '@noble/hashes/blake3.js';\nimport { utf8ToBytes, 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 hashData(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\nexport function keyedHashHex(hashKey: Uint8Array, data: Uint8Array[]): string {\n try {\n const hash = keyedHash(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 keyedHash(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\n *\n * @param data - The data to hash\n * @returns The resulting hash hex string\n */\nexport function hashDataHex(data: Uint8Array[]): string {\n try {\n const hash = hashData(data);\n return bytesToHex(hash);\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 getBytesFromData(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 getBytesFromDataHex(bytes: number, data: Uint8Array[]): string {\n try {\n const hash = getBytesFromData(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 value - The string to hash\n * @returns The resulting hash value\n */\nexport function getBytesFromString(bytes: number, value: string): Uint8Array {\n return blake3(utf8ToBytes(value), { dkLen: bytes });\n}\n\n/**\n * Hashes the given string using blake3 algorithm\n *\n * @param bytes - The desired output byte-length\n * @param value - The string to hash\n * @returns The resulting hash value\n */\nexport function getBytesFromStrinHex(bytes: number, value: string): string {\n return bytesToHex(getBytesFromString(bytes, value));\n}\n","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 { bytesToHex } from '@noble/hashes/utils.js';\nimport { AES_KEY_BIT_LENGTH } from '../constants';\nimport { getBytesFromString, keyedHash } 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: string, data: Uint8Array[]): string {\n try {\n const key = getBytesFromString(AES_KEY_BIT_LENGTH / 8, keyMaterial);\n const hash = keyedHash(key, data);\n return bytesToHex(hash);\n } catch (error) {\n throw new Error('Failed to compute mac', { cause: error });\n }\n}\n"]}
|