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.
Files changed (148) hide show
  1. package/README.md +3 -4
  2. package/dist/asymmetric-crypto-BORmLhnx.js +143 -0
  3. package/dist/asymmetric-crypto-BORmLhnx.js.map +1 -0
  4. package/dist/asymmetric-crypto-CyXsV4XT.mjs +102 -0
  5. package/dist/asymmetric-crypto-CyXsV4XT.mjs.map +1 -0
  6. package/dist/asymmetric-crypto.d.mts +9 -3
  7. package/dist/asymmetric-crypto.d.ts +9 -3
  8. package/dist/asymmetric-crypto.js +8 -92
  9. package/dist/asymmetric-crypto.mjs +2 -84
  10. package/dist/chunk-DWirmd9C.mjs +18 -0
  11. package/dist/chunk-Dt-PWiN7.js +60 -0
  12. package/dist/constants-Ccp21E03.js +208 -0
  13. package/dist/constants-Ccp21E03.js.map +1 -0
  14. package/dist/constants-kTeX-2T0.mjs +34 -0
  15. package/dist/constants-kTeX-2T0.mjs.map +1 -0
  16. package/dist/constants.d.mts +5 -11
  17. package/dist/constants.d.ts +5 -11
  18. package/dist/constants.js +30 -79
  19. package/dist/constants.mjs +2 -41
  20. package/dist/derive-key-Be7hS-cN.mjs +751 -0
  21. package/dist/derive-key-Be7hS-cN.mjs.map +1 -0
  22. package/dist/derive-key-CBf2WxJd.js +2513 -0
  23. package/dist/derive-key-CBf2WxJd.js.map +1 -0
  24. package/dist/derive-key.d.mts +14 -8
  25. package/dist/derive-key.d.ts +14 -8
  26. package/dist/derive-key.js +15 -795
  27. package/dist/derive-key.mjs +5 -783
  28. package/dist/email-crypto-BrT98taw.js +617 -0
  29. package/dist/email-crypto-BrT98taw.js.map +1 -0
  30. package/dist/email-crypto-DJUEjTxA.mjs +534 -0
  31. package/dist/email-crypto-DJUEjTxA.mjs.map +1 -0
  32. package/dist/email-crypto.d.mts +58 -78
  33. package/dist/email-crypto.d.ts +58 -78
  34. package/dist/email-crypto.js +17 -1409
  35. package/dist/email-crypto.mjs +8 -1381
  36. package/dist/email-search.d.mts +39 -32
  37. package/dist/email-search.d.ts +39 -32
  38. package/dist/email-search.js +572 -540
  39. package/dist/email-search.js.map +1 -1
  40. package/dist/email-search.mjs +567 -539
  41. package/dist/email-search.mjs.map +1 -1
  42. package/dist/hash-BoqwNkcd.js +190 -0
  43. package/dist/hash-BoqwNkcd.js.map +1 -0
  44. package/dist/hash-CXeGAwai.mjs +131 -0
  45. package/dist/hash-CXeGAwai.mjs.map +1 -0
  46. package/dist/hash.d.mts +21 -15
  47. package/dist/hash.d.ts +21 -15
  48. package/dist/hash.js +11 -95
  49. package/dist/hash.mjs +2 -84
  50. package/dist/index-CQqgKsbX.d.ts +50 -0
  51. package/dist/index-CintVUbp.d.ts +97 -0
  52. package/dist/index-D5pBU_A5.d.mts +50 -0
  53. package/dist/index-MaOov-ag.d.mts +97 -0
  54. package/dist/index.d.mts +35 -18
  55. package/dist/index.d.ts +35 -18
  56. package/dist/index.js +103 -2685
  57. package/dist/index.mjs +15 -2538
  58. package/dist/keystore-crypto-B4yCVo9l.js +182 -0
  59. package/dist/keystore-crypto-B4yCVo9l.js.map +1 -0
  60. package/dist/keystore-crypto-Bjgriq9h.mjs +159 -0
  61. package/dist/keystore-crypto-Bjgriq9h.mjs.map +1 -0
  62. package/dist/keystore-crypto.d.mts +20 -46
  63. package/dist/keystore-crypto.d.ts +20 -46
  64. package/dist/keystore-crypto.js +11 -530
  65. package/dist/keystore-crypto.mjs +9 -501
  66. package/dist/keystore-service.d.mts +44 -78
  67. package/dist/keystore-service.d.ts +44 -78
  68. package/dist/keystore-service.js +113 -340
  69. package/dist/keystore-service.js.map +1 -1
  70. package/dist/keystore-service.mjs +107 -335
  71. package/dist/keystore-service.mjs.map +1 -1
  72. package/dist/post-quantum-crypto-CAi-cEkV.js +189 -0
  73. package/dist/post-quantum-crypto-CAi-cEkV.js.map +1 -0
  74. package/dist/post-quantum-crypto-Vv34t6gX.mjs +154 -0
  75. package/dist/post-quantum-crypto-Vv34t6gX.mjs.map +1 -0
  76. package/dist/post-quantum-crypto.d.mts +2 -72
  77. package/dist/post-quantum-crypto.d.ts +2 -72
  78. package/dist/post-quantum-crypto.js +13 -92
  79. package/dist/post-quantum-crypto.mjs +2 -89
  80. package/dist/storage-service-BgIK2aYZ.js +82 -0
  81. package/dist/storage-service-BgIK2aYZ.js.map +1 -0
  82. package/dist/storage-service-CubCbhY2.mjs +65 -0
  83. package/dist/storage-service-CubCbhY2.mjs.map +1 -0
  84. package/dist/storage-service.d.mts +2 -53
  85. package/dist/storage-service.d.ts +2 -53
  86. package/dist/storage-service.js +12 -68
  87. package/dist/storage-service.mjs +2 -66
  88. package/dist/symmetric-crypto-CrdS1Che.mjs +197 -0
  89. package/dist/symmetric-crypto-CrdS1Che.mjs.map +1 -0
  90. package/dist/symmetric-crypto-D65zB396.js +244 -0
  91. package/dist/symmetric-crypto-D65zB396.js.map +1 -0
  92. package/dist/symmetric-crypto.d.mts +12 -8
  93. package/dist/symmetric-crypto.d.ts +12 -8
  94. package/dist/symmetric-crypto.js +10 -142
  95. package/dist/symmetric-crypto.mjs +3 -133
  96. package/dist/types-52g887Zi.js +16 -0
  97. package/dist/types-52g887Zi.js.map +1 -0
  98. package/dist/types-BiEoleqw.mjs +10 -0
  99. package/dist/types-BiEoleqw.mjs.map +1 -0
  100. package/dist/types-Ds3ivE9W.d.ts +104 -0
  101. package/dist/types-DwQJtrTx.d.mts +104 -0
  102. package/dist/types.d.mts +2 -102
  103. package/dist/types.d.ts +2 -102
  104. package/dist/types.js +2 -13
  105. package/dist/types.mjs +2 -11
  106. package/dist/utils-CNs3cyDj.js +263 -0
  107. package/dist/utils-CNs3cyDj.js.map +1 -0
  108. package/dist/utils-DS04iUcX.mjs +173 -0
  109. package/dist/utils-DS04iUcX.mjs.map +1 -0
  110. package/dist/utils.d.mts +37 -78
  111. package/dist/utils.d.ts +37 -78
  112. package/dist/utils.js +16 -313
  113. package/dist/utils.mjs +2 -272
  114. package/package.json +15 -90
  115. package/dist/asymmetric-crypto.js.map +0 -1
  116. package/dist/asymmetric-crypto.mjs.map +0 -1
  117. package/dist/constants.js.map +0 -1
  118. package/dist/constants.mjs.map +0 -1
  119. package/dist/derive-key.js.map +0 -1
  120. package/dist/derive-key.mjs.map +0 -1
  121. package/dist/email-crypto.js.map +0 -1
  122. package/dist/email-crypto.mjs.map +0 -1
  123. package/dist/email-service.d.mts +0 -38
  124. package/dist/email-service.d.ts +0 -38
  125. package/dist/email-service.js +0 -154
  126. package/dist/email-service.js.map +0 -1
  127. package/dist/email-service.mjs +0 -147
  128. package/dist/email-service.mjs.map +0 -1
  129. package/dist/hash.js.map +0 -1
  130. package/dist/hash.mjs.map +0 -1
  131. package/dist/index.js.map +0 -1
  132. package/dist/index.mjs.map +0 -1
  133. package/dist/keystore-crypto.js.map +0 -1
  134. package/dist/keystore-crypto.mjs.map +0 -1
  135. package/dist/kyber768-B87rMQ7u.d.mts +0 -30
  136. package/dist/kyber768-B87rMQ7u.d.ts +0 -30
  137. package/dist/post-quantum-crypto.js.map +0 -1
  138. package/dist/post-quantum-crypto.mjs.map +0 -1
  139. package/dist/storage-service.js.map +0 -1
  140. package/dist/storage-service.mjs.map +0 -1
  141. package/dist/symmetric-crypto.js.map +0 -1
  142. package/dist/symmetric-crypto.mjs.map +0 -1
  143. package/dist/types.js.map +0 -1
  144. package/dist/types.mjs.map +0 -1
  145. package/dist/utils-BDaK_d6T.d.ts +0 -114
  146. package/dist/utils-v34IRTIx.d.mts +0 -114
  147. package/dist/utils.js.map +0 -1
  148. package/dist/utils.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: SymmetricCiphertext = await symmetric.encryptSymmetrically(key, data, additionalData);
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: 2,
145
+ replyToEmailID: generateUuid(),
147
146
  };
148
147
 
149
148
  const email: Email = {
150
- id: 'email 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"}
@@ -1,3 +1,4 @@
1
+ //#region src/asymmetric-crypto/ellipticCurve.d.ts
1
2
  /**
2
3
  * Derives secret key from the other user's public key and own private key
3
4
  *
@@ -6,7 +7,8 @@
6
7
  * @returns The derived secret key bits
7
8
  */
8
9
  declare function deriveSecretKey(otherUserPublicKey: CryptoKey, ownPrivateKey: CryptoKey): Promise<Uint8Array>;
9
-
10
+ //#endregion
11
+ //#region src/asymmetric-crypto/keys.d.ts
10
12
  /**
11
13
  * Generates elliptic curve key pair
12
14
  *
@@ -37,5 +39,9 @@ declare function exportPrivateKey(key: CryptoKey): Promise<Uint8Array>;
37
39
  * @returns The CryptoKey representation of the private key
38
40
  */
39
41
  declare function importPrivateKey(pkcs8KeyData: Uint8Array): Promise<CryptoKey>;
40
-
41
- export { deriveSecretKey, exportPrivateKey, exportPublicKey, generateEccKeys, importPrivateKey, importPublicKey };
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
@@ -1,3 +1,4 @@
1
+ //#region src/asymmetric-crypto/ellipticCurve.d.ts
1
2
  /**
2
3
  * Derives secret key from the other user's public key and own private key
3
4
  *
@@ -6,7 +7,8 @@
6
7
  * @returns The derived secret key bits
7
8
  */
8
9
  declare function deriveSecretKey(otherUserPublicKey: CryptoKey, ownPrivateKey: CryptoKey): Promise<Uint8Array>;
9
-
10
+ //#endregion
11
+ //#region src/asymmetric-crypto/keys.d.ts
10
12
  /**
11
13
  * Generates elliptic curve key pair
12
14
  *
@@ -37,5 +39,9 @@ declare function exportPrivateKey(key: CryptoKey): Promise<Uint8Array>;
37
39
  * @returns The CryptoKey representation of the private key
38
40
  */
39
41
  declare function importPrivateKey(pkcs8KeyData: Uint8Array): Promise<CryptoKey>;
40
-
41
- export { deriveSecretKey, exportPrivateKey, exportPublicKey, generateEccKeys, importPrivateKey, importPublicKey };
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
@@ -1,92 +1,8 @@
1
- 'use strict';
2
-
3
- // src/constants.ts
4
- var AES_KEY_BIT_LENGTH = 256;
5
- var ECC_ALGORITHM = "X25519";
6
-
7
- // src/asymmetric-crypto/ellipticCurve.ts
8
- async function deriveSecretKey(otherUserPublicKey, ownPrivateKey) {
9
- try {
10
- const result = await crypto.subtle.deriveBits(
11
- {
12
- name: ECC_ALGORITHM,
13
- public: otherUserPublicKey
14
- },
15
- ownPrivateKey,
16
- AES_KEY_BIT_LENGTH
17
- );
18
- return new Uint8Array(result);
19
- } catch (error) {
20
- throw new Error("Failed to derive elliptic curve secret key", { cause: error });
21
- }
22
- }
23
-
24
- // src/asymmetric-crypto/keys.ts
25
- async function generateEccKeys() {
26
- try {
27
- return await crypto.subtle.generateKey(
28
- {
29
- name: ECC_ALGORITHM
30
- },
31
- true,
32
- ["deriveBits"]
33
- );
34
- } catch (error) {
35
- throw new Error("Failed to generate elliptic curve key pair", { cause: error });
36
- }
37
- }
38
- async function exportPublicKey(key) {
39
- try {
40
- const result = await crypto.subtle.exportKey("spki", key);
41
- return new Uint8Array(result);
42
- } catch (error) {
43
- throw new Error("Failed to export public key", { cause: error });
44
- }
45
- }
46
- async function importPublicKey(spkiKeyData) {
47
- try {
48
- return await crypto.subtle.importKey(
49
- "spki",
50
- spkiKeyData,
51
- {
52
- name: ECC_ALGORITHM
53
- },
54
- true,
55
- []
56
- );
57
- } catch (error) {
58
- throw new Error("Failed to import public key", { cause: error });
59
- }
60
- }
61
- async function exportPrivateKey(key) {
62
- try {
63
- const result = await crypto.subtle.exportKey("pkcs8", key);
64
- return new Uint8Array(result);
65
- } catch (error) {
66
- throw new Error("Failed to export private key", { cause: error });
67
- }
68
- }
69
- async function importPrivateKey(pkcs8KeyData) {
70
- try {
71
- return await crypto.subtle.importKey(
72
- "pkcs8",
73
- pkcs8KeyData,
74
- {
75
- name: ECC_ALGORITHM
76
- },
77
- true,
78
- ["deriveBits"]
79
- );
80
- } catch (error) {
81
- throw new Error("Failed to import private key", { cause: error });
82
- }
83
- }
84
-
85
- exports.deriveSecretKey = deriveSecretKey;
86
- exports.exportPrivateKey = exportPrivateKey;
87
- exports.exportPublicKey = exportPublicKey;
88
- exports.generateEccKeys = generateEccKeys;
89
- exports.importPrivateKey = importPrivateKey;
90
- exports.importPublicKey = importPublicKey;
91
- //# sourceMappingURL=asymmetric-crypto.js.map
92
- //# sourceMappingURL=asymmetric-crypto.js.map
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;
@@ -1,85 +1,3 @@
1
- // src/constants.ts
2
- var AES_KEY_BIT_LENGTH = 256;
3
- var ECC_ALGORITHM = "X25519";
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";
4
2
 
5
- // src/asymmetric-crypto/ellipticCurve.ts
6
- async function deriveSecretKey(otherUserPublicKey, ownPrivateKey) {
7
- try {
8
- const result = await crypto.subtle.deriveBits(
9
- {
10
- name: ECC_ALGORITHM,
11
- public: otherUserPublicKey
12
- },
13
- ownPrivateKey,
14
- AES_KEY_BIT_LENGTH
15
- );
16
- return new Uint8Array(result);
17
- } catch (error) {
18
- throw new Error("Failed to derive elliptic curve secret key", { cause: error });
19
- }
20
- }
21
-
22
- // src/asymmetric-crypto/keys.ts
23
- async function generateEccKeys() {
24
- try {
25
- return await crypto.subtle.generateKey(
26
- {
27
- name: ECC_ALGORITHM
28
- },
29
- true,
30
- ["deriveBits"]
31
- );
32
- } catch (error) {
33
- throw new Error("Failed to generate elliptic curve key pair", { cause: error });
34
- }
35
- }
36
- async function exportPublicKey(key) {
37
- try {
38
- const result = await crypto.subtle.exportKey("spki", key);
39
- return new Uint8Array(result);
40
- } catch (error) {
41
- throw new Error("Failed to export public key", { cause: error });
42
- }
43
- }
44
- async function importPublicKey(spkiKeyData) {
45
- try {
46
- return await crypto.subtle.importKey(
47
- "spki",
48
- spkiKeyData,
49
- {
50
- name: ECC_ALGORITHM
51
- },
52
- true,
53
- []
54
- );
55
- } catch (error) {
56
- throw new Error("Failed to import public key", { cause: error });
57
- }
58
- }
59
- async function exportPrivateKey(key) {
60
- try {
61
- const result = await crypto.subtle.exportKey("pkcs8", key);
62
- return new Uint8Array(result);
63
- } catch (error) {
64
- throw new Error("Failed to export private key", { cause: error });
65
- }
66
- }
67
- async function importPrivateKey(pkcs8KeyData) {
68
- try {
69
- return await crypto.subtle.importKey(
70
- "pkcs8",
71
- pkcs8KeyData,
72
- {
73
- name: ECC_ALGORITHM
74
- },
75
- true,
76
- ["deriveBits"]
77
- );
78
- } catch (error) {
79
- throw new Error("Failed to import private key", { cause: error });
80
- }
81
- }
82
-
83
- export { deriveSecretKey, exportPrivateKey, exportPublicKey, generateEccKeys, importPrivateKey, importPublicKey };
84
- //# sourceMappingURL=asymmetric-crypto.mjs.map
85
- //# sourceMappingURL=asymmetric-crypto.mjs.map
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
+ });