internxt-crypto 0.0.9-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 +47 -0
- package/dist/asymmetric-crypto.d.ts +47 -0
- package/dist/asymmetric-crypto.js +8 -0
- package/dist/asymmetric-crypto.mjs +3 -0
- 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 +33 -0
- package/dist/constants.d.ts +33 -0
- package/dist/constants.js +31 -0
- package/dist/constants.mjs +3 -0
- 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 +97 -0
- package/dist/derive-key.d.ts +97 -0
- package/dist/derive-key.js +15 -0
- package/dist/derive-key.mjs +6 -0
- 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 +86 -0
- package/dist/email-crypto.d.ts +86 -0
- package/dist/email-crypto.js +17 -0
- package/dist/email-crypto.mjs +8 -0
- package/dist/email-search.d.mts +235 -0
- package/dist/email-search.d.ts +235 -0
- package/dist/email-search.js +637 -0
- package/dist/email-search.js.map +1 -0
- package/dist/email-search.mjs +608 -0
- package/dist/email-search.mjs.map +1 -0
- 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 +65 -0
- package/dist/hash.d.ts +65 -0
- package/dist/hash.js +11 -0
- package/dist/hash.mjs +3 -0
- 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 +52 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +116 -2055
- package/dist/index.mjs +15 -8712
- 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 +40 -0
- package/dist/keystore-crypto.d.ts +40 -0
- package/dist/keystore-crypto.js +11 -0
- package/dist/keystore-crypto.mjs +9 -0
- package/dist/keystore-service.d.mts +48 -0
- package/dist/keystore-service.d.ts +48 -0
- package/dist/keystore-service.js +122 -0
- package/dist/keystore-service.js.map +1 -0
- package/dist/keystore-service.mjs +114 -0
- package/dist/keystore-service.mjs.map +1 -0
- 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 -0
- package/dist/post-quantum-crypto.d.ts +2 -0
- package/dist/post-quantum-crypto.js +17 -0
- package/dist/post-quantum-crypto.mjs +3 -0
- 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 -0
- package/dist/storage-service.d.ts +2 -0
- package/dist/storage-service.js +14 -0
- package/dist/storage-service.mjs +3 -0
- 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 +60 -0
- package/dist/symmetric-crypto.d.ts +60 -0
- package/dist/symmetric-crypto.js +10 -0
- package/dist/symmetric-crypto.mjs +4 -0
- 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 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +3 -0
- package/dist/types.mjs +3 -0
- 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 +99 -0
- package/dist/utils.d.ts +99 -0
- package/dist/utils.js +16 -0
- package/dist/utils.mjs +3 -0
- package/package.json +12 -11
- 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/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -73,7 +73,6 @@ import {
|
|
|
73
73
|
keystoreService,
|
|
74
74
|
deriveKey,
|
|
75
75
|
hash,
|
|
76
|
-
SymmetricCiphertext
|
|
77
76
|
} from 'internxt-crypto';
|
|
78
77
|
|
|
79
78
|
// Asymmetric encryption
|
|
@@ -87,7 +86,7 @@ expect(resultAlice).toStrictEqual(resultBob);
|
|
|
87
86
|
const data = utils.UTF8ToUint8('Sensitive information to encrypt'); // convert to Uint8Array
|
|
88
87
|
const additionalData = 'Additional non-secret data';
|
|
89
88
|
const key = await symmetric.genSymmetricCryptoKey(); // CryptoKey
|
|
90
|
-
const ciphertext:
|
|
89
|
+
const ciphertext: Uint8Array = await symmetric.encryptSymmetrically(key, data, additionalData);
|
|
91
90
|
const plainText = await symmetric.decryptSymmetrically(encryptionKey, ciphertext, additionalData);
|
|
92
91
|
expect(data).toStrictEqual(plainText);
|
|
93
92
|
|
|
@@ -143,11 +142,11 @@ const emailParams: EmailPublicParameters = {
|
|
|
143
142
|
subject: 'email subject',
|
|
144
143
|
sender: userAlice,
|
|
145
144
|
recipient: userBob,
|
|
146
|
-
replyToEmailID:
|
|
145
|
+
replyToEmailID: generateUuid(),
|
|
147
146
|
};
|
|
148
147
|
|
|
149
148
|
const email: Email = {
|
|
150
|
-
id:
|
|
149
|
+
id: generateUuid(),
|
|
151
150
|
params: emailParams,
|
|
152
151
|
body: emailBody,
|
|
153
152
|
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-Dt-PWiN7.js');
|
|
2
|
+
const require_constants = require('./constants-Ccp21E03.js');
|
|
3
|
+
|
|
4
|
+
//#region src/asymmetric-crypto/ellipticCurve.ts
|
|
5
|
+
/**
|
|
6
|
+
* Derives secret key from the other user's public key and own private key
|
|
7
|
+
*
|
|
8
|
+
* @param otherUserPublicKey - The public key of the other user
|
|
9
|
+
* @param ownPrivateKey - The private key
|
|
10
|
+
* @returns The derived secret key bits
|
|
11
|
+
*/
|
|
12
|
+
async function deriveSecretKey(otherUserPublicKey, ownPrivateKey) {
|
|
13
|
+
try {
|
|
14
|
+
const result = await crypto.subtle.deriveBits({
|
|
15
|
+
name: require_constants.ECC_ALGORITHM,
|
|
16
|
+
public: otherUserPublicKey
|
|
17
|
+
}, ownPrivateKey, require_constants.AES_KEY_BIT_LENGTH);
|
|
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
|
+
//#endregion
|
|
25
|
+
//#region src/asymmetric-crypto/keys.ts
|
|
26
|
+
/**
|
|
27
|
+
* Generates elliptic curve key pair
|
|
28
|
+
*
|
|
29
|
+
* @returns The generated key pair
|
|
30
|
+
*/
|
|
31
|
+
async function generateEccKeys() {
|
|
32
|
+
try {
|
|
33
|
+
return await crypto.subtle.generateKey({ name: require_constants.ECC_ALGORITHM }, true, ["deriveBits"]);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
throw new Error("Failed to generate elliptic curve key pair", { cause: error });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts public CryptoKey into Uint8Array using SubjectPublicKeyInfo format (RFC 5280)
|
|
40
|
+
*
|
|
41
|
+
* @returns The Uint8Array representation of the public key
|
|
42
|
+
*/
|
|
43
|
+
async function exportPublicKey(key) {
|
|
44
|
+
try {
|
|
45
|
+
const result = await crypto.subtle.exportKey("spki", key);
|
|
46
|
+
return new Uint8Array(result);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
throw new Error("Failed to export public key", { cause: error });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Converts public key in SubjectPublicKeyInfo format (RFC 5280) to CryptoKey
|
|
53
|
+
*
|
|
54
|
+
* @returns The CryptoKey representation of the public key
|
|
55
|
+
*/
|
|
56
|
+
async function importPublicKey(spkiKeyData) {
|
|
57
|
+
try {
|
|
58
|
+
return await crypto.subtle.importKey("spki", spkiKeyData, { name: require_constants.ECC_ALGORITHM }, true, []);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
throw new Error("Failed to import public key", { cause: error });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Converts private key in CryptoKey to PKCS #8 format (RFC 5208)
|
|
65
|
+
*
|
|
66
|
+
* @returns The Uint8Array representation of the private key
|
|
67
|
+
*/
|
|
68
|
+
async function exportPrivateKey(key) {
|
|
69
|
+
try {
|
|
70
|
+
const result = await crypto.subtle.exportKey("pkcs8", key);
|
|
71
|
+
return new Uint8Array(result);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
throw new Error("Failed to export private key", { cause: error });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Converts private key in PKCS #8 format (RFC 5208) to CryptoKey
|
|
78
|
+
*
|
|
79
|
+
* @returns The CryptoKey representation of the private key
|
|
80
|
+
*/
|
|
81
|
+
async function importPrivateKey(pkcs8KeyData) {
|
|
82
|
+
try {
|
|
83
|
+
return await crypto.subtle.importKey("pkcs8", pkcs8KeyData, { name: require_constants.ECC_ALGORITHM }, true, ["deriveBits"]);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
throw new Error("Failed to import private key", { cause: error });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/asymmetric-crypto/index.ts
|
|
91
|
+
var asymmetric_crypto_exports = /* @__PURE__ */ require_chunk.__exportAll({
|
|
92
|
+
deriveSecretKey: () => deriveSecretKey,
|
|
93
|
+
exportPrivateKey: () => exportPrivateKey,
|
|
94
|
+
exportPublicKey: () => exportPublicKey,
|
|
95
|
+
generateEccKeys: () => generateEccKeys,
|
|
96
|
+
importPrivateKey: () => importPrivateKey,
|
|
97
|
+
importPublicKey: () => importPublicKey
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
//#endregion
|
|
101
|
+
Object.defineProperty(exports, 'asymmetric_crypto_exports', {
|
|
102
|
+
enumerable: true,
|
|
103
|
+
get: function () {
|
|
104
|
+
return asymmetric_crypto_exports;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
Object.defineProperty(exports, 'deriveSecretKey', {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
get: function () {
|
|
110
|
+
return deriveSecretKey;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
Object.defineProperty(exports, 'exportPrivateKey', {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
get: function () {
|
|
116
|
+
return exportPrivateKey;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
Object.defineProperty(exports, 'exportPublicKey', {
|
|
120
|
+
enumerable: true,
|
|
121
|
+
get: function () {
|
|
122
|
+
return exportPublicKey;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
Object.defineProperty(exports, 'generateEccKeys', {
|
|
126
|
+
enumerable: true,
|
|
127
|
+
get: function () {
|
|
128
|
+
return generateEccKeys;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
Object.defineProperty(exports, 'importPrivateKey', {
|
|
132
|
+
enumerable: true,
|
|
133
|
+
get: function () {
|
|
134
|
+
return importPrivateKey;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
Object.defineProperty(exports, 'importPublicKey', {
|
|
138
|
+
enumerable: true,
|
|
139
|
+
get: function () {
|
|
140
|
+
return importPublicKey;
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
//# sourceMappingURL=asymmetric-crypto-BORmLhnx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asymmetric-crypto-BORmLhnx.js","names":["ECC_ALGORITHM","AES_KEY_BIT_LENGTH","ECC_ALGORITHM"],"sources":["../src/asymmetric-crypto/ellipticCurve.ts","../src/asymmetric-crypto/keys.ts","../src/asymmetric-crypto/index.ts"],"sourcesContent":["import { ECC_ALGORITHM, AES_KEY_BIT_LENGTH } from '../constants';\n\n/**\n * Derives secret key from the other user's public key and own private key\n *\n * @param otherUserPublicKey - The public key of the other user\n * @param ownPrivateKey - The private key\n * @returns The derived secret key bits\n */\nexport async function deriveSecretKey(otherUserPublicKey: CryptoKey, ownPrivateKey: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.deriveBits(\n {\n name: ECC_ALGORITHM,\n public: otherUserPublicKey,\n },\n ownPrivateKey,\n AES_KEY_BIT_LENGTH,\n );\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to derive elliptic curve secret key', { cause: error });\n }\n}\n","import { ECC_ALGORITHM } from '../constants';\n\n/**\n * Generates elliptic curve key pair\n *\n * @returns The generated key pair\n */\nexport async function generateEccKeys(): Promise<CryptoKeyPair> {\n try {\n return (await crypto.subtle.generateKey(\n {\n name: ECC_ALGORITHM,\n },\n true,\n ['deriveBits'],\n )) as CryptoKeyPair;\n } catch (error) {\n throw new Error('Failed to generate elliptic curve key pair', { cause: error });\n }\n}\n\n/**\n * Converts public CryptoKey into Uint8Array using SubjectPublicKeyInfo format (RFC 5280)\n *\n * @returns The Uint8Array representation of the public key\n */\nexport async function exportPublicKey(key: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.exportKey('spki', key);\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to export public key', { cause: error });\n }\n}\n\n/**\n * Converts public key in SubjectPublicKeyInfo format (RFC 5280) to CryptoKey\n *\n * @returns The CryptoKey representation of the public key\n */\nexport async function importPublicKey(spkiKeyData: Uint8Array): Promise<CryptoKey> {\n try {\n return await crypto.subtle.importKey(\n 'spki',\n spkiKeyData as BufferSource,\n {\n name: ECC_ALGORITHM,\n },\n true,\n [],\n );\n } catch (error) {\n throw new Error('Failed to import public key', { cause: error });\n }\n}\n\n/**\n * Converts private key in CryptoKey to PKCS #8 format (RFC 5208)\n *\n * @returns The Uint8Array representation of the private key\n */\nexport async function exportPrivateKey(key: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.exportKey('pkcs8', key);\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to export private key', { cause: error });\n }\n}\n\n/**\n * Converts private key in PKCS #8 format (RFC 5208) to CryptoKey\n *\n * @returns The CryptoKey representation of the private key\n */\nexport async function importPrivateKey(pkcs8KeyData: Uint8Array): Promise<CryptoKey> {\n try {\n return await crypto.subtle.importKey(\n 'pkcs8',\n pkcs8KeyData as BufferSource,\n {\n name: ECC_ALGORITHM,\n },\n true,\n ['deriveBits'],\n );\n } catch (error) {\n throw new Error('Failed to import private key', { cause: error });\n }\n}\n","export * from './ellipticCurve';\nexport * from './keys';\n"],"mappings":";;;;;;;;;;;AASA,eAAsB,gBAAgB,oBAA+B,eAA+C;AAClH,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,WACjC;GACE,MAAMA;GACN,QAAQ;GACT,EACD,eACAC,qCACD;AACD,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,8CAA8C,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;ACdnF,eAAsB,kBAA0C;AAC9D,KAAI;AACF,SAAQ,MAAM,OAAO,OAAO,YAC1B,EACE,MAAMC,iCACP,EACD,MACA,CAAC,aAAa,CACf;UACM,OAAO;AACd,QAAM,IAAI,MAAM,8CAA8C,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASnF,eAAsB,gBAAgB,KAAqC;AACzE,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,UAAU,QAAQ,IAAI;AACzD,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,+BAA+B,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASpE,eAAsB,gBAAgB,aAA6C;AACjF,KAAI;AACF,SAAO,MAAM,OAAO,OAAO,UACzB,QACA,aACA,EACE,MAAMA,iCACP,EACD,MACA,EAAE,CACH;UACM,OAAO;AACd,QAAM,IAAI,MAAM,+BAA+B,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASpE,eAAsB,iBAAiB,KAAqC;AAC1E,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,UAAU,SAAS,IAAI;AAC1D,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,gCAAgC,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASrE,eAAsB,iBAAiB,cAA8C;AACnF,KAAI;AACF,SAAO,MAAM,OAAO,OAAO,UACzB,SACA,cACA,EACE,MAAMA,iCACP,EACD,MACA,CAAC,aAAa,CACf;UACM,OAAO;AACd,QAAM,IAAI,MAAM,gCAAgC,EAAE,OAAO,OAAO,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { t as __exportAll } from "./chunk-DWirmd9C.mjs";
|
|
2
|
+
import { g as ECC_ALGORITHM, n as AES_KEY_BIT_LENGTH } from "./constants-kTeX-2T0.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/asymmetric-crypto/ellipticCurve.ts
|
|
5
|
+
/**
|
|
6
|
+
* Derives secret key from the other user's public key and own private key
|
|
7
|
+
*
|
|
8
|
+
* @param otherUserPublicKey - The public key of the other user
|
|
9
|
+
* @param ownPrivateKey - The private key
|
|
10
|
+
* @returns The derived secret key bits
|
|
11
|
+
*/
|
|
12
|
+
async function deriveSecretKey(otherUserPublicKey, ownPrivateKey) {
|
|
13
|
+
try {
|
|
14
|
+
const result = await crypto.subtle.deriveBits({
|
|
15
|
+
name: ECC_ALGORITHM,
|
|
16
|
+
public: otherUserPublicKey
|
|
17
|
+
}, ownPrivateKey, AES_KEY_BIT_LENGTH);
|
|
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
|
+
//#endregion
|
|
25
|
+
//#region src/asymmetric-crypto/keys.ts
|
|
26
|
+
/**
|
|
27
|
+
* Generates elliptic curve key pair
|
|
28
|
+
*
|
|
29
|
+
* @returns The generated key pair
|
|
30
|
+
*/
|
|
31
|
+
async function generateEccKeys() {
|
|
32
|
+
try {
|
|
33
|
+
return await crypto.subtle.generateKey({ name: ECC_ALGORITHM }, true, ["deriveBits"]);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
throw new Error("Failed to generate elliptic curve key pair", { cause: error });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts public CryptoKey into Uint8Array using SubjectPublicKeyInfo format (RFC 5280)
|
|
40
|
+
*
|
|
41
|
+
* @returns The Uint8Array representation of the public key
|
|
42
|
+
*/
|
|
43
|
+
async function exportPublicKey(key) {
|
|
44
|
+
try {
|
|
45
|
+
const result = await crypto.subtle.exportKey("spki", key);
|
|
46
|
+
return new Uint8Array(result);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
throw new Error("Failed to export public key", { cause: error });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Converts public key in SubjectPublicKeyInfo format (RFC 5280) to CryptoKey
|
|
53
|
+
*
|
|
54
|
+
* @returns The CryptoKey representation of the public key
|
|
55
|
+
*/
|
|
56
|
+
async function importPublicKey(spkiKeyData) {
|
|
57
|
+
try {
|
|
58
|
+
return await crypto.subtle.importKey("spki", spkiKeyData, { name: ECC_ALGORITHM }, true, []);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
throw new Error("Failed to import public key", { cause: error });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Converts private key in CryptoKey to PKCS #8 format (RFC 5208)
|
|
65
|
+
*
|
|
66
|
+
* @returns The Uint8Array representation of the private key
|
|
67
|
+
*/
|
|
68
|
+
async function exportPrivateKey(key) {
|
|
69
|
+
try {
|
|
70
|
+
const result = await crypto.subtle.exportKey("pkcs8", key);
|
|
71
|
+
return new Uint8Array(result);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
throw new Error("Failed to export private key", { cause: error });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Converts private key in PKCS #8 format (RFC 5208) to CryptoKey
|
|
78
|
+
*
|
|
79
|
+
* @returns The CryptoKey representation of the private key
|
|
80
|
+
*/
|
|
81
|
+
async function importPrivateKey(pkcs8KeyData) {
|
|
82
|
+
try {
|
|
83
|
+
return await crypto.subtle.importKey("pkcs8", pkcs8KeyData, { name: ECC_ALGORITHM }, true, ["deriveBits"]);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
throw new Error("Failed to import private key", { cause: error });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/asymmetric-crypto/index.ts
|
|
91
|
+
var asymmetric_crypto_exports = /* @__PURE__ */ __exportAll({
|
|
92
|
+
deriveSecretKey: () => deriveSecretKey,
|
|
93
|
+
exportPrivateKey: () => exportPrivateKey,
|
|
94
|
+
exportPublicKey: () => exportPublicKey,
|
|
95
|
+
generateEccKeys: () => generateEccKeys,
|
|
96
|
+
importPrivateKey: () => importPrivateKey,
|
|
97
|
+
importPublicKey: () => importPublicKey
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
//#endregion
|
|
101
|
+
export { importPrivateKey as a, generateEccKeys as i, exportPrivateKey as n, importPublicKey as o, exportPublicKey as r, deriveSecretKey as s, asymmetric_crypto_exports as t };
|
|
102
|
+
//# sourceMappingURL=asymmetric-crypto-CyXsV4XT.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asymmetric-crypto-CyXsV4XT.mjs","names":[],"sources":["../src/asymmetric-crypto/ellipticCurve.ts","../src/asymmetric-crypto/keys.ts","../src/asymmetric-crypto/index.ts"],"sourcesContent":["import { ECC_ALGORITHM, AES_KEY_BIT_LENGTH } from '../constants';\n\n/**\n * Derives secret key from the other user's public key and own private key\n *\n * @param otherUserPublicKey - The public key of the other user\n * @param ownPrivateKey - The private key\n * @returns The derived secret key bits\n */\nexport async function deriveSecretKey(otherUserPublicKey: CryptoKey, ownPrivateKey: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.deriveBits(\n {\n name: ECC_ALGORITHM,\n public: otherUserPublicKey,\n },\n ownPrivateKey,\n AES_KEY_BIT_LENGTH,\n );\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to derive elliptic curve secret key', { cause: error });\n }\n}\n","import { ECC_ALGORITHM } from '../constants';\n\n/**\n * Generates elliptic curve key pair\n *\n * @returns The generated key pair\n */\nexport async function generateEccKeys(): Promise<CryptoKeyPair> {\n try {\n return (await crypto.subtle.generateKey(\n {\n name: ECC_ALGORITHM,\n },\n true,\n ['deriveBits'],\n )) as CryptoKeyPair;\n } catch (error) {\n throw new Error('Failed to generate elliptic curve key pair', { cause: error });\n }\n}\n\n/**\n * Converts public CryptoKey into Uint8Array using SubjectPublicKeyInfo format (RFC 5280)\n *\n * @returns The Uint8Array representation of the public key\n */\nexport async function exportPublicKey(key: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.exportKey('spki', key);\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to export public key', { cause: error });\n }\n}\n\n/**\n * Converts public key in SubjectPublicKeyInfo format (RFC 5280) to CryptoKey\n *\n * @returns The CryptoKey representation of the public key\n */\nexport async function importPublicKey(spkiKeyData: Uint8Array): Promise<CryptoKey> {\n try {\n return await crypto.subtle.importKey(\n 'spki',\n spkiKeyData as BufferSource,\n {\n name: ECC_ALGORITHM,\n },\n true,\n [],\n );\n } catch (error) {\n throw new Error('Failed to import public key', { cause: error });\n }\n}\n\n/**\n * Converts private key in CryptoKey to PKCS #8 format (RFC 5208)\n *\n * @returns The Uint8Array representation of the private key\n */\nexport async function exportPrivateKey(key: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.exportKey('pkcs8', key);\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to export private key', { cause: error });\n }\n}\n\n/**\n * Converts private key in PKCS #8 format (RFC 5208) to CryptoKey\n *\n * @returns The CryptoKey representation of the private key\n */\nexport async function importPrivateKey(pkcs8KeyData: Uint8Array): Promise<CryptoKey> {\n try {\n return await crypto.subtle.importKey(\n 'pkcs8',\n pkcs8KeyData as BufferSource,\n {\n name: ECC_ALGORITHM,\n },\n true,\n ['deriveBits'],\n );\n } catch (error) {\n throw new Error('Failed to import private key', { cause: error });\n }\n}\n","export * from './ellipticCurve';\nexport * from './keys';\n"],"mappings":";;;;;;;;;;;AASA,eAAsB,gBAAgB,oBAA+B,eAA+C;AAClH,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,WACjC;GACE,MAAM;GACN,QAAQ;GACT,EACD,eACA,mBACD;AACD,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,8CAA8C,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;ACdnF,eAAsB,kBAA0C;AAC9D,KAAI;AACF,SAAQ,MAAM,OAAO,OAAO,YAC1B,EACE,MAAM,eACP,EACD,MACA,CAAC,aAAa,CACf;UACM,OAAO;AACd,QAAM,IAAI,MAAM,8CAA8C,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASnF,eAAsB,gBAAgB,KAAqC;AACzE,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,UAAU,QAAQ,IAAI;AACzD,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,+BAA+B,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASpE,eAAsB,gBAAgB,aAA6C;AACjF,KAAI;AACF,SAAO,MAAM,OAAO,OAAO,UACzB,QACA,aACA,EACE,MAAM,eACP,EACD,MACA,EAAE,CACH;UACM,OAAO;AACd,QAAM,IAAI,MAAM,+BAA+B,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASpE,eAAsB,iBAAiB,KAAqC;AAC1E,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,UAAU,SAAS,IAAI;AAC1D,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,gCAAgC,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASrE,eAAsB,iBAAiB,cAA8C;AACnF,KAAI;AACF,SAAO,MAAM,OAAO,OAAO,UACzB,SACA,cACA,EACE,MAAM,eACP,EACD,MACA,CAAC,aAAa,CACf;UACM,OAAO;AACd,QAAM,IAAI,MAAM,gCAAgC,EAAE,OAAO,OAAO,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
//#region src/asymmetric-crypto/ellipticCurve.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Derives secret key from the other user's public key and own private key
|
|
4
|
+
*
|
|
5
|
+
* @param otherUserPublicKey - The public key of the other user
|
|
6
|
+
* @param ownPrivateKey - The private key
|
|
7
|
+
* @returns The derived secret key bits
|
|
8
|
+
*/
|
|
9
|
+
declare function deriveSecretKey(otherUserPublicKey: CryptoKey, ownPrivateKey: CryptoKey): Promise<Uint8Array>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/asymmetric-crypto/keys.d.ts
|
|
12
|
+
/**
|
|
13
|
+
* Generates elliptic curve key pair
|
|
14
|
+
*
|
|
15
|
+
* @returns The generated key pair
|
|
16
|
+
*/
|
|
17
|
+
declare function generateEccKeys(): Promise<CryptoKeyPair>;
|
|
18
|
+
/**
|
|
19
|
+
* Converts public CryptoKey into Uint8Array using SubjectPublicKeyInfo format (RFC 5280)
|
|
20
|
+
*
|
|
21
|
+
* @returns The Uint8Array representation of the public key
|
|
22
|
+
*/
|
|
23
|
+
declare function exportPublicKey(key: CryptoKey): Promise<Uint8Array>;
|
|
24
|
+
/**
|
|
25
|
+
* Converts public key in SubjectPublicKeyInfo format (RFC 5280) to CryptoKey
|
|
26
|
+
*
|
|
27
|
+
* @returns The CryptoKey representation of the public key
|
|
28
|
+
*/
|
|
29
|
+
declare function importPublicKey(spkiKeyData: Uint8Array): Promise<CryptoKey>;
|
|
30
|
+
/**
|
|
31
|
+
* Converts private key in CryptoKey to PKCS #8 format (RFC 5208)
|
|
32
|
+
*
|
|
33
|
+
* @returns The Uint8Array representation of the private key
|
|
34
|
+
*/
|
|
35
|
+
declare function exportPrivateKey(key: CryptoKey): Promise<Uint8Array>;
|
|
36
|
+
/**
|
|
37
|
+
* Converts private key in PKCS #8 format (RFC 5208) to CryptoKey
|
|
38
|
+
*
|
|
39
|
+
* @returns The CryptoKey representation of the private key
|
|
40
|
+
*/
|
|
41
|
+
declare function importPrivateKey(pkcs8KeyData: Uint8Array): Promise<CryptoKey>;
|
|
42
|
+
declare namespace index_d_exports {
|
|
43
|
+
export { deriveSecretKey, exportPrivateKey, exportPublicKey, generateEccKeys, importPrivateKey, importPublicKey };
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { deriveSecretKey, exportPrivateKey, exportPublicKey, generateEccKeys, importPrivateKey, importPublicKey, index_d_exports as t };
|
|
47
|
+
//# sourceMappingURL=asymmetric-crypto.d.mts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
//#region src/asymmetric-crypto/ellipticCurve.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Derives secret key from the other user's public key and own private key
|
|
4
|
+
*
|
|
5
|
+
* @param otherUserPublicKey - The public key of the other user
|
|
6
|
+
* @param ownPrivateKey - The private key
|
|
7
|
+
* @returns The derived secret key bits
|
|
8
|
+
*/
|
|
9
|
+
declare function deriveSecretKey(otherUserPublicKey: CryptoKey, ownPrivateKey: CryptoKey): Promise<Uint8Array>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/asymmetric-crypto/keys.d.ts
|
|
12
|
+
/**
|
|
13
|
+
* Generates elliptic curve key pair
|
|
14
|
+
*
|
|
15
|
+
* @returns The generated key pair
|
|
16
|
+
*/
|
|
17
|
+
declare function generateEccKeys(): Promise<CryptoKeyPair>;
|
|
18
|
+
/**
|
|
19
|
+
* Converts public CryptoKey into Uint8Array using SubjectPublicKeyInfo format (RFC 5280)
|
|
20
|
+
*
|
|
21
|
+
* @returns The Uint8Array representation of the public key
|
|
22
|
+
*/
|
|
23
|
+
declare function exportPublicKey(key: CryptoKey): Promise<Uint8Array>;
|
|
24
|
+
/**
|
|
25
|
+
* Converts public key in SubjectPublicKeyInfo format (RFC 5280) to CryptoKey
|
|
26
|
+
*
|
|
27
|
+
* @returns The CryptoKey representation of the public key
|
|
28
|
+
*/
|
|
29
|
+
declare function importPublicKey(spkiKeyData: Uint8Array): Promise<CryptoKey>;
|
|
30
|
+
/**
|
|
31
|
+
* Converts private key in CryptoKey to PKCS #8 format (RFC 5208)
|
|
32
|
+
*
|
|
33
|
+
* @returns The Uint8Array representation of the private key
|
|
34
|
+
*/
|
|
35
|
+
declare function exportPrivateKey(key: CryptoKey): Promise<Uint8Array>;
|
|
36
|
+
/**
|
|
37
|
+
* Converts private key in PKCS #8 format (RFC 5208) to CryptoKey
|
|
38
|
+
*
|
|
39
|
+
* @returns The CryptoKey representation of the private key
|
|
40
|
+
*/
|
|
41
|
+
declare function importPrivateKey(pkcs8KeyData: Uint8Array): Promise<CryptoKey>;
|
|
42
|
+
declare namespace index_d_exports {
|
|
43
|
+
export { deriveSecretKey, exportPrivateKey, exportPublicKey, generateEccKeys, importPrivateKey, importPublicKey };
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { deriveSecretKey, exportPrivateKey, exportPublicKey, generateEccKeys, importPrivateKey, importPublicKey, index_d_exports as t };
|
|
47
|
+
//# sourceMappingURL=asymmetric-crypto.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const require_asymmetric_crypto = require('./asymmetric-crypto-BORmLhnx.js');
|
|
2
|
+
|
|
3
|
+
exports.deriveSecretKey = require_asymmetric_crypto.deriveSecretKey;
|
|
4
|
+
exports.exportPrivateKey = require_asymmetric_crypto.exportPrivateKey;
|
|
5
|
+
exports.exportPublicKey = require_asymmetric_crypto.exportPublicKey;
|
|
6
|
+
exports.generateEccKeys = require_asymmetric_crypto.generateEccKeys;
|
|
7
|
+
exports.importPrivateKey = require_asymmetric_crypto.importPrivateKey;
|
|
8
|
+
exports.importPublicKey = require_asymmetric_crypto.importPublicKey;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as importPrivateKey, i as generateEccKeys, n as exportPrivateKey, o as importPublicKey, r as exportPublicKey, s as deriveSecretKey } from "./asymmetric-crypto-CyXsV4XT.mjs";
|
|
2
|
+
|
|
3
|
+
export { deriveSecretKey, exportPrivateKey, exportPublicKey, generateEccKeys, importPrivateKey, importPublicKey };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) {
|
|
6
|
+
__defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
if (symbols) {
|
|
12
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
|
+
}
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { __exportAll as t };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
9
|
+
var __exportAll = (all, symbols) => {
|
|
10
|
+
let target = {};
|
|
11
|
+
for (var name in all) {
|
|
12
|
+
__defProp(target, name, {
|
|
13
|
+
get: all[name],
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
if (symbols) {
|
|
18
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
19
|
+
}
|
|
20
|
+
return target;
|
|
21
|
+
};
|
|
22
|
+
var __copyProps = (to, from, except, desc) => {
|
|
23
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
24
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
25
|
+
key = keys[i];
|
|
26
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
27
|
+
__defProp(to, key, {
|
|
28
|
+
get: ((k) => from[k]).bind(null, key),
|
|
29
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
35
|
+
};
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
37
|
+
value: mod,
|
|
38
|
+
enumerable: true
|
|
39
|
+
}) : target, mod));
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
|
|
43
|
+
Object.defineProperty(exports, '__commonJSMin', {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return __commonJSMin;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(exports, '__exportAll', {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
get: function () {
|
|
52
|
+
return __exportAll;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(exports, '__toESM', {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
get: function () {
|
|
58
|
+
return __toESM;
|
|
59
|
+
}
|
|
60
|
+
});
|