internxt-crypto 0.0.14 → 1.0.1

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 (144) hide show
  1. package/README.md +44 -72
  2. package/dist/aes-B8TA-JKq.mjs +49 -0
  3. package/dist/aes-B8TA-JKq.mjs.map +1 -0
  4. package/dist/aes-CuW_SPl-.js +67 -0
  5. package/dist/aes-CuW_SPl-.js.map +1 -0
  6. package/dist/asymmetric-crypto.d.mts +8 -31
  7. package/dist/asymmetric-crypto.d.mts.map +1 -1
  8. package/dist/asymmetric-crypto.d.ts +8 -31
  9. package/dist/asymmetric-crypto.d.ts.map +1 -1
  10. package/dist/asymmetric-crypto.js +30 -7
  11. package/dist/asymmetric-crypto.js.map +1 -0
  12. package/dist/asymmetric-crypto.mjs +28 -2
  13. package/dist/asymmetric-crypto.mjs.map +1 -0
  14. package/dist/constants.d.mts +3 -10
  15. package/dist/constants.d.mts.map +1 -1
  16. package/dist/constants.d.ts +3 -10
  17. package/dist/constants.d.ts.map +1 -1
  18. package/dist/constants.js +3 -17
  19. package/dist/constants.js.map +1 -1
  20. package/dist/constants.mjs +3 -10
  21. package/dist/constants.mjs.map +1 -1
  22. package/dist/core-Bj26rNdA.js +227 -0
  23. package/dist/core-Bj26rNdA.js.map +1 -0
  24. package/dist/core-pEGygy6S.mjs +173 -0
  25. package/dist/core-pEGygy6S.mjs.map +1 -0
  26. package/dist/derive-key.d.mts +1 -74
  27. package/dist/derive-key.d.mts.map +1 -1
  28. package/dist/derive-key.d.ts +1 -74
  29. package/dist/derive-key.d.ts.map +1 -1
  30. package/dist/derive-key.js +3 -11
  31. package/dist/derive-key.mjs +2 -2
  32. package/dist/derive-password.d.mts +22 -0
  33. package/dist/derive-password.d.mts.map +1 -0
  34. package/dist/derive-password.d.ts +22 -0
  35. package/dist/derive-password.d.ts.map +1 -0
  36. package/dist/derive-password.js +5 -0
  37. package/dist/derive-password.mjs +3 -0
  38. package/dist/deriveKeysFromKey-C4McqO6_.js +47 -0
  39. package/dist/deriveKeysFromKey-C4McqO6_.js.map +1 -0
  40. package/dist/deriveKeysFromKey-DPU_h7wr.mjs +35 -0
  41. package/dist/deriveKeysFromKey-DPU_h7wr.mjs.map +1 -0
  42. package/dist/{deriveKeysFromPassword-BYaiSGKL.js → deriveKeysFromPassword-C7xAGGsh.js} +5 -172
  43. package/dist/deriveKeysFromPassword-C7xAGGsh.js.map +1 -0
  44. package/dist/{deriveKeysFromPassword-XIwzErlL.mjs → deriveKeysFromPassword-DXgSvTNC.mjs} +6 -125
  45. package/dist/deriveKeysFromPassword-DXgSvTNC.mjs.map +1 -0
  46. package/dist/email-crypto.d.mts +24 -46
  47. package/dist/email-crypto.d.mts.map +1 -1
  48. package/dist/email-crypto.d.ts +24 -46
  49. package/dist/email-crypto.d.ts.map +1 -1
  50. package/dist/email-crypto.js +121 -12
  51. package/dist/email-crypto.js.map +1 -0
  52. package/dist/email-crypto.mjs +115 -2
  53. package/dist/email-crypto.mjs.map +1 -0
  54. package/dist/email-search.d.mts.map +1 -1
  55. package/dist/email-search.d.ts.map +1 -1
  56. package/dist/email-search.js +25 -597
  57. package/dist/email-search.mjs +2 -573
  58. package/dist/{emailEncryptionKey-B9xHw1h_.mjs → emailEncryptionKey-BtSPYd9M.mjs} +22 -45
  59. package/dist/emailEncryptionKey-BtSPYd9M.mjs.map +1 -0
  60. package/dist/{emailEncryptionKey-CQNe5W_T.js → emailEncryptionKey-C4X1Bwy4.js} +22 -45
  61. package/dist/emailEncryptionKey-C4X1Bwy4.js.map +1 -0
  62. package/dist/{genID-3Er5IowC.mjs → genID-D08K7JPr.mjs} +4 -40
  63. package/dist/genID-D08K7JPr.mjs.map +1 -0
  64. package/dist/{genID-YJSl3YhL.js → genID-cWOPmspk.js} +2 -50
  65. package/dist/genID-cWOPmspk.js.map +1 -0
  66. package/dist/hash.d.mts +24 -36
  67. package/dist/hash.d.mts.map +1 -1
  68. package/dist/hash.d.ts +24 -36
  69. package/dist/hash.d.ts.map +1 -1
  70. package/dist/hash.js +88 -10
  71. package/dist/hash.js.map +1 -0
  72. package/dist/hash.mjs +82 -2
  73. package/dist/hash.mjs.map +1 -0
  74. package/dist/index.d.mts +9 -8
  75. package/dist/index.d.mts.map +1 -1
  76. package/dist/index.d.ts +9 -8
  77. package/dist/index.d.ts.map +1 -1
  78. package/dist/index.js +56 -79
  79. package/dist/index.mjs +13 -11
  80. package/dist/keystore-crypto.d.mts +6 -6
  81. package/dist/keystore-crypto.d.mts.map +1 -1
  82. package/dist/keystore-crypto.d.ts +6 -6
  83. package/dist/keystore-crypto.d.ts.map +1 -1
  84. package/dist/keystore-crypto.js +1 -1
  85. package/dist/keystore-crypto.mjs +1 -1
  86. package/dist/post-quantum-crypto.js +49 -4
  87. package/dist/post-quantum-crypto.js.map +1 -0
  88. package/dist/post-quantum-crypto.mjs +46 -2
  89. package/dist/post-quantum-crypto.mjs.map +1 -0
  90. package/dist/search-B9YM3XAA.mjs +587 -0
  91. package/dist/search-B9YM3XAA.mjs.map +1 -0
  92. package/dist/search-DUTm4-rN.js +731 -0
  93. package/dist/search-DUTm4-rN.js.map +1 -0
  94. package/dist/symmetric-crypto.d.mts +11 -40
  95. package/dist/symmetric-crypto.d.mts.map +1 -1
  96. package/dist/symmetric-crypto.d.ts +11 -40
  97. package/dist/symmetric-crypto.d.ts.map +1 -1
  98. package/dist/symmetric-crypto.js +2 -6
  99. package/dist/symmetric-crypto.mjs +2 -2
  100. package/dist/types.d.mts +13 -40
  101. package/dist/types.d.mts.map +1 -1
  102. package/dist/types.d.ts +13 -40
  103. package/dist/types.d.ts.map +1 -1
  104. package/dist/types.js.map +1 -1
  105. package/dist/types.mjs.map +1 -1
  106. package/dist/utils.d.mts +1 -19
  107. package/dist/utils.d.mts.map +1 -1
  108. package/dist/utils.d.ts +1 -19
  109. package/dist/utils.d.ts.map +1 -1
  110. package/dist/utils.js +1 -3
  111. package/dist/utils.mjs +2 -2
  112. package/dist/xwing-CQmQX6hn.mjs +16 -0
  113. package/dist/xwing-CQmQX6hn.mjs.map +1 -0
  114. package/dist/xwing-iRWVRtNE.js +34 -0
  115. package/dist/xwing-iRWVRtNE.js.map +1 -0
  116. package/package.json +4 -3
  117. package/dist/aes-DCb9dJqb.mjs +0 -161
  118. package/dist/aes-DCb9dJqb.mjs.map +0 -1
  119. package/dist/aes-DQo1MyCz.js +0 -203
  120. package/dist/aes-DQo1MyCz.js.map +0 -1
  121. package/dist/deriveKeysFromPassword-BYaiSGKL.js.map +0 -1
  122. package/dist/deriveKeysFromPassword-XIwzErlL.mjs.map +0 -1
  123. package/dist/email-search.js.map +0 -1
  124. package/dist/email-search.mjs.map +0 -1
  125. package/dist/emailEncryptionKey-B9xHw1h_.mjs.map +0 -1
  126. package/dist/emailEncryptionKey-CQNe5W_T.js.map +0 -1
  127. package/dist/emailKeys-C0KhtfNP.js +0 -572
  128. package/dist/emailKeys-C0KhtfNP.js.map +0 -1
  129. package/dist/emailKeys-D4lp9NRv.mjs +0 -488
  130. package/dist/emailKeys-D4lp9NRv.mjs.map +0 -1
  131. package/dist/genID-3Er5IowC.mjs.map +0 -1
  132. package/dist/genID-YJSl3YhL.js.map +0 -1
  133. package/dist/keys-BfcaiAOv.mjs +0 -90
  134. package/dist/keys-BfcaiAOv.mjs.map +0 -1
  135. package/dist/keys-CinT7kEY.js +0 -125
  136. package/dist/keys-CinT7kEY.js.map +0 -1
  137. package/dist/kyber768-SXnIo-Nw.mjs +0 -47
  138. package/dist/kyber768-SXnIo-Nw.mjs.map +0 -1
  139. package/dist/kyber768-WUVc2fIR.js +0 -65
  140. package/dist/kyber768-WUVc2fIR.js.map +0 -1
  141. package/dist/mac-BMb1F0dN.js +0 -170
  142. package/dist/mac-BMb1F0dN.js.map +0 -1
  143. package/dist/mac-ZpRlx8Fs.mjs +0 -116
  144. package/dist/mac-ZpRlx8Fs.mjs.map +0 -1
@@ -1,90 +0,0 @@
1
- import { AES_KEY_BIT_LENGTH, ECC_ALGORITHM } from "./constants.mjs";
2
-
3
- //#region src/asymmetric-crypto/ellipticCurve.ts
4
- /**
5
- * Derives secret key from the other user's public key and own private key
6
- *
7
- * @param otherUserPublicKey - The public key of the other user
8
- * @param ownPrivateKey - The private key
9
- * @returns The derived secret key bits
10
- */
11
- async function deriveSecretKey(otherUserPublicKey, ownPrivateKey) {
12
- try {
13
- const result = await crypto.subtle.deriveBits({
14
- name: ECC_ALGORITHM,
15
- public: otherUserPublicKey
16
- }, ownPrivateKey, AES_KEY_BIT_LENGTH);
17
- return new Uint8Array(result);
18
- } catch (error) {
19
- throw new Error("Failed to derive elliptic curve secret key", { cause: error });
20
- }
21
- }
22
-
23
- //#endregion
24
- //#region src/asymmetric-crypto/keys.ts
25
- /**
26
- * Generates elliptic curve key pair
27
- *
28
- * @returns The generated key pair
29
- */
30
- async function generateEccKeys() {
31
- try {
32
- return await crypto.subtle.generateKey({ name: ECC_ALGORITHM }, true, ["deriveBits"]);
33
- } catch (error) {
34
- throw new Error("Failed to generate elliptic curve key pair", { cause: error });
35
- }
36
- }
37
- /**
38
- * Converts public CryptoKey into Uint8Array using SubjectPublicKeyInfo format (RFC 5280)
39
- *
40
- * @returns The Uint8Array representation of the public key
41
- */
42
- async function exportPublicKey(key) {
43
- try {
44
- const result = await crypto.subtle.exportKey("spki", key);
45
- return new Uint8Array(result);
46
- } catch (error) {
47
- throw new Error("Failed to export public key", { cause: error });
48
- }
49
- }
50
- /**
51
- * Converts public key in SubjectPublicKeyInfo format (RFC 5280) to CryptoKey
52
- *
53
- * @returns The CryptoKey representation of the public key
54
- */
55
- async function importPublicKey(spkiKeyData) {
56
- try {
57
- return await crypto.subtle.importKey("spki", spkiKeyData, { name: ECC_ALGORITHM }, true, []);
58
- } catch (error) {
59
- throw new Error("Failed to import public key", { cause: error });
60
- }
61
- }
62
- /**
63
- * Converts private key in CryptoKey to PKCS #8 format (RFC 5208)
64
- *
65
- * @returns The Uint8Array representation of the private key
66
- */
67
- async function exportPrivateKey(key) {
68
- try {
69
- const result = await crypto.subtle.exportKey("pkcs8", key);
70
- return new Uint8Array(result);
71
- } catch (error) {
72
- throw new Error("Failed to export private key", { cause: error });
73
- }
74
- }
75
- /**
76
- * Converts private key in PKCS #8 format (RFC 5208) to CryptoKey
77
- *
78
- * @returns The CryptoKey representation of the private key
79
- */
80
- async function importPrivateKey(pkcs8KeyData) {
81
- try {
82
- return await crypto.subtle.importKey("pkcs8", pkcs8KeyData, { name: ECC_ALGORITHM }, true, ["deriveBits"]);
83
- } catch (error) {
84
- throw new Error("Failed to import private key", { cause: error });
85
- }
86
- }
87
-
88
- //#endregion
89
- export { importPublicKey as a, importPrivateKey as i, exportPublicKey as n, deriveSecretKey as o, generateEccKeys as r, exportPrivateKey as t };
90
- //# sourceMappingURL=keys-BfcaiAOv.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"keys-BfcaiAOv.mjs","names":[],"sources":["../src/asymmetric-crypto/ellipticCurve.ts","../src/asymmetric-crypto/keys.ts"],"sourcesContent":["import { ECC_ALGORITHM, AES_KEY_BIT_LENGTH } from '../constants';\n\n/**\n * Derives secret key from the other user's public key and own private key\n *\n * @param otherUserPublicKey - The public key of the other user\n * @param ownPrivateKey - The private key\n * @returns The derived secret key bits\n */\nexport async function deriveSecretKey(otherUserPublicKey: CryptoKey, ownPrivateKey: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.deriveBits(\n {\n name: ECC_ALGORITHM,\n public: otherUserPublicKey,\n },\n ownPrivateKey,\n AES_KEY_BIT_LENGTH,\n );\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to derive elliptic curve secret key', { cause: error });\n }\n}\n","import { ECC_ALGORITHM } from '../constants';\n\n/**\n * Generates elliptic curve key pair\n *\n * @returns The generated key pair\n */\nexport async function generateEccKeys(): Promise<CryptoKeyPair> {\n try {\n return (await crypto.subtle.generateKey(\n {\n name: ECC_ALGORITHM,\n },\n true,\n ['deriveBits'],\n )) as CryptoKeyPair;\n } catch (error) {\n throw new Error('Failed to generate elliptic curve key pair', { cause: error });\n }\n}\n\n/**\n * Converts public CryptoKey into Uint8Array using SubjectPublicKeyInfo format (RFC 5280)\n *\n * @returns The Uint8Array representation of the public key\n */\nexport async function exportPublicKey(key: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.exportKey('spki', key);\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to export public key', { cause: error });\n }\n}\n\n/**\n * Converts public key in SubjectPublicKeyInfo format (RFC 5280) to CryptoKey\n *\n * @returns The CryptoKey representation of the public key\n */\nexport async function importPublicKey(spkiKeyData: Uint8Array): Promise<CryptoKey> {\n try {\n return await crypto.subtle.importKey(\n 'spki',\n spkiKeyData as BufferSource,\n {\n name: ECC_ALGORITHM,\n },\n true,\n [],\n );\n } catch (error) {\n throw new Error('Failed to import public key', { cause: error });\n }\n}\n\n/**\n * Converts private key in CryptoKey to PKCS #8 format (RFC 5208)\n *\n * @returns The Uint8Array representation of the private key\n */\nexport async function exportPrivateKey(key: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.exportKey('pkcs8', key);\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to export private key', { cause: error });\n }\n}\n\n/**\n * Converts private key in PKCS #8 format (RFC 5208) to CryptoKey\n *\n * @returns The CryptoKey representation of the private key\n */\nexport async function importPrivateKey(pkcs8KeyData: Uint8Array): Promise<CryptoKey> {\n try {\n return await crypto.subtle.importKey(\n 'pkcs8',\n pkcs8KeyData as BufferSource,\n {\n name: ECC_ALGORITHM,\n },\n true,\n ['deriveBits'],\n );\n } catch (error) {\n throw new Error('Failed to import private key', { cause: error });\n }\n}\n"],"mappings":";;;;;;;;;;AASA,eAAsB,gBAAgB,oBAA+B,eAA+C;AAClH,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,WACjC;GACE,MAAM;GACN,QAAQ;GACT,EACD,eACA,mBACD;AACD,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,8CAA8C,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;ACdnF,eAAsB,kBAA0C;AAC9D,KAAI;AACF,SAAQ,MAAM,OAAO,OAAO,YAC1B,EACE,MAAM,eACP,EACD,MACA,CAAC,aAAa,CACf;UACM,OAAO;AACd,QAAM,IAAI,MAAM,8CAA8C,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASnF,eAAsB,gBAAgB,KAAqC;AACzE,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,UAAU,QAAQ,IAAI;AACzD,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,+BAA+B,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASpE,eAAsB,gBAAgB,aAA6C;AACjF,KAAI;AACF,SAAO,MAAM,OAAO,OAAO,UACzB,QACA,aACA,EACE,MAAM,eACP,EACD,MACA,EAAE,CACH;UACM,OAAO;AACd,QAAM,IAAI,MAAM,+BAA+B,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASpE,eAAsB,iBAAiB,KAAqC;AAC1E,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,UAAU,SAAS,IAAI;AAC1D,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,gCAAgC,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASrE,eAAsB,iBAAiB,cAA8C;AACnF,KAAI;AACF,SAAO,MAAM,OAAO,OAAO,UACzB,SACA,cACA,EACE,MAAM,eACP,EACD,MACA,CAAC,aAAa,CACf;UACM,OAAO;AACd,QAAM,IAAI,MAAM,gCAAgC,EAAE,OAAO,OAAO,CAAC"}
@@ -1,125 +0,0 @@
1
- const require_constants = require('./constants.js');
2
-
3
- //#region src/asymmetric-crypto/ellipticCurve.ts
4
- /**
5
- * Derives secret key from the other user's public key and own private key
6
- *
7
- * @param otherUserPublicKey - The public key of the other user
8
- * @param ownPrivateKey - The private key
9
- * @returns The derived secret key bits
10
- */
11
- async function deriveSecretKey(otherUserPublicKey, ownPrivateKey) {
12
- try {
13
- const result = await crypto.subtle.deriveBits({
14
- name: require_constants.ECC_ALGORITHM,
15
- public: otherUserPublicKey
16
- }, ownPrivateKey, require_constants.AES_KEY_BIT_LENGTH);
17
- return new Uint8Array(result);
18
- } catch (error) {
19
- throw new Error("Failed to derive elliptic curve secret key", { cause: error });
20
- }
21
- }
22
-
23
- //#endregion
24
- //#region src/asymmetric-crypto/keys.ts
25
- /**
26
- * Generates elliptic curve key pair
27
- *
28
- * @returns The generated key pair
29
- */
30
- async function generateEccKeys() {
31
- try {
32
- return await crypto.subtle.generateKey({ name: require_constants.ECC_ALGORITHM }, true, ["deriveBits"]);
33
- } catch (error) {
34
- throw new Error("Failed to generate elliptic curve key pair", { cause: error });
35
- }
36
- }
37
- /**
38
- * Converts public CryptoKey into Uint8Array using SubjectPublicKeyInfo format (RFC 5280)
39
- *
40
- * @returns The Uint8Array representation of the public key
41
- */
42
- async function exportPublicKey(key) {
43
- try {
44
- const result = await crypto.subtle.exportKey("spki", key);
45
- return new Uint8Array(result);
46
- } catch (error) {
47
- throw new Error("Failed to export public key", { cause: error });
48
- }
49
- }
50
- /**
51
- * Converts public key in SubjectPublicKeyInfo format (RFC 5280) to CryptoKey
52
- *
53
- * @returns The CryptoKey representation of the public key
54
- */
55
- async function importPublicKey(spkiKeyData) {
56
- try {
57
- return await crypto.subtle.importKey("spki", spkiKeyData, { name: require_constants.ECC_ALGORITHM }, true, []);
58
- } catch (error) {
59
- throw new Error("Failed to import public key", { cause: error });
60
- }
61
- }
62
- /**
63
- * Converts private key in CryptoKey to PKCS #8 format (RFC 5208)
64
- *
65
- * @returns The Uint8Array representation of the private key
66
- */
67
- async function exportPrivateKey(key) {
68
- try {
69
- const result = await crypto.subtle.exportKey("pkcs8", key);
70
- return new Uint8Array(result);
71
- } catch (error) {
72
- throw new Error("Failed to export private key", { cause: error });
73
- }
74
- }
75
- /**
76
- * Converts private key in PKCS #8 format (RFC 5208) to CryptoKey
77
- *
78
- * @returns The CryptoKey representation of the private key
79
- */
80
- async function importPrivateKey(pkcs8KeyData) {
81
- try {
82
- return await crypto.subtle.importKey("pkcs8", pkcs8KeyData, { name: require_constants.ECC_ALGORITHM }, true, ["deriveBits"]);
83
- } catch (error) {
84
- throw new Error("Failed to import private key", { cause: error });
85
- }
86
- }
87
-
88
- //#endregion
89
- Object.defineProperty(exports, 'deriveSecretKey', {
90
- enumerable: true,
91
- get: function () {
92
- return deriveSecretKey;
93
- }
94
- });
95
- Object.defineProperty(exports, 'exportPrivateKey', {
96
- enumerable: true,
97
- get: function () {
98
- return exportPrivateKey;
99
- }
100
- });
101
- Object.defineProperty(exports, 'exportPublicKey', {
102
- enumerable: true,
103
- get: function () {
104
- return exportPublicKey;
105
- }
106
- });
107
- Object.defineProperty(exports, 'generateEccKeys', {
108
- enumerable: true,
109
- get: function () {
110
- return generateEccKeys;
111
- }
112
- });
113
- Object.defineProperty(exports, 'importPrivateKey', {
114
- enumerable: true,
115
- get: function () {
116
- return importPrivateKey;
117
- }
118
- });
119
- Object.defineProperty(exports, 'importPublicKey', {
120
- enumerable: true,
121
- get: function () {
122
- return importPublicKey;
123
- }
124
- });
125
- //# sourceMappingURL=keys-CinT7kEY.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"keys-CinT7kEY.js","names":["ECC_ALGORITHM","AES_KEY_BIT_LENGTH","ECC_ALGORITHM"],"sources":["../src/asymmetric-crypto/ellipticCurve.ts","../src/asymmetric-crypto/keys.ts"],"sourcesContent":["import { ECC_ALGORITHM, AES_KEY_BIT_LENGTH } from '../constants';\n\n/**\n * Derives secret key from the other user's public key and own private key\n *\n * @param otherUserPublicKey - The public key of the other user\n * @param ownPrivateKey - The private key\n * @returns The derived secret key bits\n */\nexport async function deriveSecretKey(otherUserPublicKey: CryptoKey, ownPrivateKey: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.deriveBits(\n {\n name: ECC_ALGORITHM,\n public: otherUserPublicKey,\n },\n ownPrivateKey,\n AES_KEY_BIT_LENGTH,\n );\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to derive elliptic curve secret key', { cause: error });\n }\n}\n","import { ECC_ALGORITHM } from '../constants';\n\n/**\n * Generates elliptic curve key pair\n *\n * @returns The generated key pair\n */\nexport async function generateEccKeys(): Promise<CryptoKeyPair> {\n try {\n return (await crypto.subtle.generateKey(\n {\n name: ECC_ALGORITHM,\n },\n true,\n ['deriveBits'],\n )) as CryptoKeyPair;\n } catch (error) {\n throw new Error('Failed to generate elliptic curve key pair', { cause: error });\n }\n}\n\n/**\n * Converts public CryptoKey into Uint8Array using SubjectPublicKeyInfo format (RFC 5280)\n *\n * @returns The Uint8Array representation of the public key\n */\nexport async function exportPublicKey(key: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.exportKey('spki', key);\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to export public key', { cause: error });\n }\n}\n\n/**\n * Converts public key in SubjectPublicKeyInfo format (RFC 5280) to CryptoKey\n *\n * @returns The CryptoKey representation of the public key\n */\nexport async function importPublicKey(spkiKeyData: Uint8Array): Promise<CryptoKey> {\n try {\n return await crypto.subtle.importKey(\n 'spki',\n spkiKeyData as BufferSource,\n {\n name: ECC_ALGORITHM,\n },\n true,\n [],\n );\n } catch (error) {\n throw new Error('Failed to import public key', { cause: error });\n }\n}\n\n/**\n * Converts private key in CryptoKey to PKCS #8 format (RFC 5208)\n *\n * @returns The Uint8Array representation of the private key\n */\nexport async function exportPrivateKey(key: CryptoKey): Promise<Uint8Array> {\n try {\n const result = await crypto.subtle.exportKey('pkcs8', key);\n return new Uint8Array(result);\n } catch (error) {\n throw new Error('Failed to export private key', { cause: error });\n }\n}\n\n/**\n * Converts private key in PKCS #8 format (RFC 5208) to CryptoKey\n *\n * @returns The CryptoKey representation of the private key\n */\nexport async function importPrivateKey(pkcs8KeyData: Uint8Array): Promise<CryptoKey> {\n try {\n return await crypto.subtle.importKey(\n 'pkcs8',\n pkcs8KeyData as BufferSource,\n {\n name: ECC_ALGORITHM,\n },\n true,\n ['deriveBits'],\n );\n } catch (error) {\n throw new Error('Failed to import private key', { cause: error });\n }\n}\n"],"mappings":";;;;;;;;;;AASA,eAAsB,gBAAgB,oBAA+B,eAA+C;AAClH,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,WACjC;GACE,MAAMA;GACN,QAAQ;GACT,EACD,eACAC,qCACD;AACD,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,8CAA8C,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;ACdnF,eAAsB,kBAA0C;AAC9D,KAAI;AACF,SAAQ,MAAM,OAAO,OAAO,YAC1B,EACE,MAAMC,iCACP,EACD,MACA,CAAC,aAAa,CACf;UACM,OAAO;AACd,QAAM,IAAI,MAAM,8CAA8C,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASnF,eAAsB,gBAAgB,KAAqC;AACzE,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,UAAU,QAAQ,IAAI;AACzD,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,+BAA+B,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASpE,eAAsB,gBAAgB,aAA6C;AACjF,KAAI;AACF,SAAO,MAAM,OAAO,OAAO,UACzB,QACA,aACA,EACE,MAAMA,iCACP,EACD,MACA,EAAE,CACH;UACM,OAAO;AACd,QAAM,IAAI,MAAM,+BAA+B,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASpE,eAAsB,iBAAiB,KAAqC;AAC1E,KAAI;EACF,MAAM,SAAS,MAAM,OAAO,OAAO,UAAU,SAAS,IAAI;AAC1D,SAAO,IAAI,WAAW,OAAO;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,gCAAgC,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASrE,eAAsB,iBAAiB,cAA8C;AACnF,KAAI;AACF,SAAO,MAAM,OAAO,OAAO,UACzB,SACA,cACA,EACE,MAAMA,iCACP,EACD,MACA,CAAC,aAAa,CACf;UACM,OAAO;AACd,QAAM,IAAI,MAAM,gCAAgC,EAAE,OAAO,OAAO,CAAC"}
@@ -1,47 +0,0 @@
1
- import { ml_kem768 } from "@noble/post-quantum/ml-kem.js";
2
-
3
- //#region src/post-quantum-crypto/kyber768.ts
4
- /**
5
- * Generates public and secret Kyber keys
6
- *
7
- * @param seed - The optional seed
8
- * @returns The generated Kyber key pair.
9
- */
10
- function generateKyberKeys(seed) {
11
- try {
12
- return ml_kem768.keygen(seed);
13
- } catch (error) {
14
- throw new Error("Failed to generate Kyber keys", { cause: error });
15
- }
16
- }
17
- /**
18
- * Generates a shared secret of 256-bits and encapsulates it to the given public key using Kyber algorithms
19
- *
20
- * @param publicKey - The public Kyber key
21
- * @returns The resulting encapsulation and the generated shared secret.
22
- */
23
- function encapsulateKyber(publicKey) {
24
- try {
25
- return ml_kem768.encapsulate(publicKey);
26
- } catch (error) {
27
- throw new Error("Failed to encapsulate", { cause: error });
28
- }
29
- }
30
- /**
31
- * Decapsulates the encapsulated shared secret using Kyber algorithms
32
- *
33
- * @param cipherText - The encapsulated key
34
- * @param secretKey - The private Kyber key
35
- * @returns The resulting decapsulated shared secret.
36
- */
37
- function decapsulateKyber(cipherText, secretKey) {
38
- try {
39
- return ml_kem768.decapsulate(cipherText, secretKey);
40
- } catch (error) {
41
- throw new Error("Failed to decapsulate", { cause: error });
42
- }
43
- }
44
-
45
- //#endregion
46
- export { encapsulateKyber as n, generateKyberKeys as r, decapsulateKyber as t };
47
- //# sourceMappingURL=kyber768-SXnIo-Nw.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"kyber768-SXnIo-Nw.mjs","names":[],"sources":["../src/post-quantum-crypto/kyber768.ts"],"sourcesContent":["import { ml_kem768 } from '@noble/post-quantum/ml-kem.js';\n\n/**\n * Generates public and secret Kyber keys\n *\n * @param seed - The optional seed\n * @returns The generated Kyber key pair.\n */\nexport function generateKyberKeys(seed?: Uint8Array): {\n publicKey: Uint8Array;\n secretKey: Uint8Array;\n} {\n try {\n return ml_kem768.keygen(seed);\n } catch (error) {\n throw new Error('Failed to generate Kyber keys', { cause: error });\n }\n}\n\n/**\n * Generates a shared secret of 256-bits and encapsulates it to the given public key using Kyber algorithms\n *\n * @param publicKey - The public Kyber key\n * @returns The resulting encapsulation and the generated shared secret.\n */\nexport function encapsulateKyber(publicKey: Uint8Array): {\n cipherText: Uint8Array;\n sharedSecret: Uint8Array;\n} {\n try {\n return ml_kem768.encapsulate(publicKey);\n } catch (error) {\n throw new Error('Failed to encapsulate', { cause: error });\n }\n}\n\n/**\n * Decapsulates the encapsulated shared secret using Kyber algorithms\n *\n * @param cipherText - The encapsulated key\n * @param secretKey - The private Kyber key\n * @returns The resulting decapsulated shared secret.\n */\nexport function decapsulateKyber(cipherText: Uint8Array, secretKey: Uint8Array): Uint8Array {\n try {\n return ml_kem768.decapsulate(cipherText, secretKey);\n } catch (error) {\n throw new Error('Failed to decapsulate', { cause: error });\n }\n}\n"],"mappings":";;;;;;;;;AAQA,SAAgB,kBAAkB,MAGhC;AACA,KAAI;AACF,SAAO,UAAU,OAAO,KAAK;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,iCAAiC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;AAUtE,SAAgB,iBAAiB,WAG/B;AACA,KAAI;AACF,SAAO,UAAU,YAAY,UAAU;UAChC,OAAO;AACd,QAAM,IAAI,MAAM,yBAAyB,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;AAW9D,SAAgB,iBAAiB,YAAwB,WAAmC;AAC1F,KAAI;AACF,SAAO,UAAU,YAAY,YAAY,UAAU;UAC5C,OAAO;AACd,QAAM,IAAI,MAAM,yBAAyB,EAAE,OAAO,OAAO,CAAC"}
@@ -1,65 +0,0 @@
1
- const require_chunk = require('./chunk-EbLFQX5m.js');
2
- let _noble_post_quantum_ml_kem_js = require("@noble/post-quantum/ml-kem.js");
3
-
4
- //#region src/post-quantum-crypto/kyber768.ts
5
- /**
6
- * Generates public and secret Kyber keys
7
- *
8
- * @param seed - The optional seed
9
- * @returns The generated Kyber key pair.
10
- */
11
- function generateKyberKeys(seed) {
12
- try {
13
- return _noble_post_quantum_ml_kem_js.ml_kem768.keygen(seed);
14
- } catch (error) {
15
- throw new Error("Failed to generate Kyber keys", { cause: error });
16
- }
17
- }
18
- /**
19
- * Generates a shared secret of 256-bits and encapsulates it to the given public key using Kyber algorithms
20
- *
21
- * @param publicKey - The public Kyber key
22
- * @returns The resulting encapsulation and the generated shared secret.
23
- */
24
- function encapsulateKyber(publicKey) {
25
- try {
26
- return _noble_post_quantum_ml_kem_js.ml_kem768.encapsulate(publicKey);
27
- } catch (error) {
28
- throw new Error("Failed to encapsulate", { cause: error });
29
- }
30
- }
31
- /**
32
- * Decapsulates the encapsulated shared secret using Kyber algorithms
33
- *
34
- * @param cipherText - The encapsulated key
35
- * @param secretKey - The private Kyber key
36
- * @returns The resulting decapsulated shared secret.
37
- */
38
- function decapsulateKyber(cipherText, secretKey) {
39
- try {
40
- return _noble_post_quantum_ml_kem_js.ml_kem768.decapsulate(cipherText, secretKey);
41
- } catch (error) {
42
- throw new Error("Failed to decapsulate", { cause: error });
43
- }
44
- }
45
-
46
- //#endregion
47
- Object.defineProperty(exports, 'decapsulateKyber', {
48
- enumerable: true,
49
- get: function () {
50
- return decapsulateKyber;
51
- }
52
- });
53
- Object.defineProperty(exports, 'encapsulateKyber', {
54
- enumerable: true,
55
- get: function () {
56
- return encapsulateKyber;
57
- }
58
- });
59
- Object.defineProperty(exports, 'generateKyberKeys', {
60
- enumerable: true,
61
- get: function () {
62
- return generateKyberKeys;
63
- }
64
- });
65
- //# sourceMappingURL=kyber768-WUVc2fIR.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"kyber768-WUVc2fIR.js","names":["ml_kem768"],"sources":["../src/post-quantum-crypto/kyber768.ts"],"sourcesContent":["import { ml_kem768 } from '@noble/post-quantum/ml-kem.js';\n\n/**\n * Generates public and secret Kyber keys\n *\n * @param seed - The optional seed\n * @returns The generated Kyber key pair.\n */\nexport function generateKyberKeys(seed?: Uint8Array): {\n publicKey: Uint8Array;\n secretKey: Uint8Array;\n} {\n try {\n return ml_kem768.keygen(seed);\n } catch (error) {\n throw new Error('Failed to generate Kyber keys', { cause: error });\n }\n}\n\n/**\n * Generates a shared secret of 256-bits and encapsulates it to the given public key using Kyber algorithms\n *\n * @param publicKey - The public Kyber key\n * @returns The resulting encapsulation and the generated shared secret.\n */\nexport function encapsulateKyber(publicKey: Uint8Array): {\n cipherText: Uint8Array;\n sharedSecret: Uint8Array;\n} {\n try {\n return ml_kem768.encapsulate(publicKey);\n } catch (error) {\n throw new Error('Failed to encapsulate', { cause: error });\n }\n}\n\n/**\n * Decapsulates the encapsulated shared secret using Kyber algorithms\n *\n * @param cipherText - The encapsulated key\n * @param secretKey - The private Kyber key\n * @returns The resulting decapsulated shared secret.\n */\nexport function decapsulateKyber(cipherText: Uint8Array, secretKey: Uint8Array): Uint8Array {\n try {\n return ml_kem768.decapsulate(cipherText, secretKey);\n } catch (error) {\n throw new Error('Failed to decapsulate', { cause: error });\n }\n}\n"],"mappings":";;;;;;;;;;AAQA,SAAgB,kBAAkB,MAGhC;AACA,KAAI;AACF,SAAOA,wCAAU,OAAO,KAAK;UACtB,OAAO;AACd,QAAM,IAAI,MAAM,iCAAiC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;AAUtE,SAAgB,iBAAiB,WAG/B;AACA,KAAI;AACF,SAAOA,wCAAU,YAAY,UAAU;UAChC,OAAO;AACd,QAAM,IAAI,MAAM,yBAAyB,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;AAW9D,SAAgB,iBAAiB,YAAwB,WAAmC;AAC1F,KAAI;AACF,SAAOA,wCAAU,YAAY,YAAY,UAAU;UAC5C,OAAO;AACd,QAAM,IAAI,MAAM,yBAAyB,EAAE,OAAO,OAAO,CAAC"}
@@ -1,170 +0,0 @@
1
- const require_chunk = require('./chunk-EbLFQX5m.js');
2
- const require_constants = require('./constants.js');
3
- let _noble_hashes_blake3_js = require("@noble/hashes/blake3.js");
4
- let _noble_hashes_utils_js = require("@noble/hashes/utils.js");
5
-
6
- //#region src/hash/blake3.ts
7
- /**
8
- * Hashes the given array of data
9
- *
10
- * @param data - The data to hash
11
- * @returns The resulting hash array
12
- */
13
- function hashDataArray(data) {
14
- try {
15
- const hasher = _noble_hashes_blake3_js.blake3.create();
16
- for (const d of data) hasher.update(d);
17
- return hasher.digest();
18
- } catch (error) {
19
- throw new Error("Failed to compute hash", { cause: error });
20
- }
21
- }
22
- /**
23
- * Hashes the given array of data
24
- *
25
- * @param data - The data to hash
26
- * @returns The resulting hash hex string
27
- */
28
- function hashDataArrayHex(data) {
29
- return (0, _noble_hashes_utils_js.bytesToHex)(hashDataArray(data));
30
- }
31
- function hashDataArrayWithKeyHex(hashKey, data) {
32
- try {
33
- return (0, _noble_hashes_utils_js.bytesToHex)(hashDataArrayWithKey(hashKey, data));
34
- } catch (error) {
35
- throw new Error("Failed to compute hash hex", { cause: error });
36
- }
37
- }
38
- function hashDataArrayWithKey(hashKey, data) {
39
- try {
40
- const hasher = _noble_hashes_blake3_js.blake3.create({ key: hashKey });
41
- for (const d of data) hasher.update(d);
42
- return hasher.digest();
43
- } catch (error) {
44
- throw new Error("Failed to compute hash", { cause: error });
45
- }
46
- }
47
- /**
48
- * Hashes the given array of data using blake3 algorithm
49
- *
50
- * @param bytes - The desired output byte-length
51
- * @param data - The data to hash
52
- * @returns The resulting hash value
53
- */
54
- function getBytesFromDataArray(bytes, data) {
55
- try {
56
- const hasher = _noble_hashes_blake3_js.blake3.create({ dkLen: bytes });
57
- for (const chunk of data) hasher.update(chunk);
58
- return hasher.digest();
59
- } catch (error) {
60
- throw new Error("Failed to get bytes from data", { cause: error });
61
- }
62
- }
63
- /**
64
- * Hashes the given array of data using blake3 algorithm
65
- *
66
- * @param bytes - The desired output byte-length
67
- * @param data - The data to hash
68
- * @returns The resulting hash value
69
- */
70
- function getBytesFromDataArrayHex(bytes, data) {
71
- try {
72
- return (0, _noble_hashes_utils_js.bytesToHex)(getBytesFromDataArray(bytes, data));
73
- } catch (error) {
74
- throw new Error("Failed to get bytes from data", { cause: error });
75
- }
76
- }
77
- /**
78
- * Hashes the given string using blake3 algorithm
79
- *
80
- * @param bytes - The desired output byte-length
81
- * @param data - The data to hash
82
- * @returns The resulting hash value
83
- */
84
- function getBytesFromData(bytes, data) {
85
- return (0, _noble_hashes_blake3_js.blake3)(data, { dkLen: bytes });
86
- }
87
- /**
88
- * Hashes the given data using blake3 algorithm
89
- *
90
- * @param bytes - The desired output byte-length
91
- * @param data - The data to hash
92
- * @returns The resulting hash value
93
- */
94
- function getBytesFromDataHex(bytes, data) {
95
- return (0, _noble_hashes_utils_js.bytesToHex)(getBytesFromData(bytes, data));
96
- }
97
-
98
- //#endregion
99
- //#region src/hash/mac.ts
100
- /**
101
- * Computes mac for the given key material and data
102
- *
103
- * @param keyMaterial - The key material
104
- * @param data - The data to hash
105
- * @returns The resulting hash hex string
106
- */
107
- function computeMac(keyMaterial, data) {
108
- try {
109
- return (0, _noble_hashes_utils_js.bytesToHex)(hashDataArrayWithKey(getBytesFromData(require_constants.AES_KEY_BIT_LENGTH / 8, keyMaterial), data));
110
- } catch (error) {
111
- throw new Error("Failed to compute mac", { cause: error });
112
- }
113
- }
114
-
115
- //#endregion
116
- Object.defineProperty(exports, 'computeMac', {
117
- enumerable: true,
118
- get: function () {
119
- return computeMac;
120
- }
121
- });
122
- Object.defineProperty(exports, 'getBytesFromData', {
123
- enumerable: true,
124
- get: function () {
125
- return getBytesFromData;
126
- }
127
- });
128
- Object.defineProperty(exports, 'getBytesFromDataArray', {
129
- enumerable: true,
130
- get: function () {
131
- return getBytesFromDataArray;
132
- }
133
- });
134
- Object.defineProperty(exports, 'getBytesFromDataArrayHex', {
135
- enumerable: true,
136
- get: function () {
137
- return getBytesFromDataArrayHex;
138
- }
139
- });
140
- Object.defineProperty(exports, 'getBytesFromDataHex', {
141
- enumerable: true,
142
- get: function () {
143
- return getBytesFromDataHex;
144
- }
145
- });
146
- Object.defineProperty(exports, 'hashDataArray', {
147
- enumerable: true,
148
- get: function () {
149
- return hashDataArray;
150
- }
151
- });
152
- Object.defineProperty(exports, 'hashDataArrayHex', {
153
- enumerable: true,
154
- get: function () {
155
- return hashDataArrayHex;
156
- }
157
- });
158
- Object.defineProperty(exports, 'hashDataArrayWithKey', {
159
- enumerable: true,
160
- get: function () {
161
- return hashDataArrayWithKey;
162
- }
163
- });
164
- Object.defineProperty(exports, 'hashDataArrayWithKeyHex', {
165
- enumerable: true,
166
- get: function () {
167
- return hashDataArrayWithKeyHex;
168
- }
169
- });
170
- //# sourceMappingURL=mac-BMb1F0dN.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mac-BMb1F0dN.js","names":["blake3","AES_KEY_BIT_LENGTH"],"sources":["../src/hash/blake3.ts","../src/hash/mac.ts"],"sourcesContent":["import { blake3 } from '@noble/hashes/blake3.js';\nimport { 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 hashDataArray(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\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 hashDataArrayHex(data: Uint8Array[]): string {\n return bytesToHex(hashDataArray(data));\n}\n\nexport function hashDataArrayWithKeyHex(hashKey: Uint8Array, data: Uint8Array[]): string {\n try {\n const hash = hashDataArrayWithKey(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 hashDataArrayWithKey(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 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 getBytesFromDataArray(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 getBytesFromDataArrayHex(bytes: number, data: Uint8Array[]): string {\n try {\n const hash = getBytesFromDataArray(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 data - The data to hash\n * @returns The resulting hash value\n */\nexport function getBytesFromData(bytes: number, data: Uint8Array): Uint8Array {\n return blake3(data, { dkLen: bytes });\n}\n\n/**\n * Hashes the given 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 return bytesToHex(getBytesFromData(bytes, data));\n}\n","import { bytesToHex } from '@noble/hashes/utils.js';\nimport { AES_KEY_BIT_LENGTH } from '../constants';\nimport { getBytesFromData, hashDataArrayWithKey } 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: Uint8Array, data: Uint8Array[]): string {\n try {\n const key = getBytesFromData(AES_KEY_BIT_LENGTH / 8, keyMaterial);\n const hash = hashDataArrayWithKey(key, data);\n return bytesToHex(hash);\n } catch (error) {\n throw new Error('Failed to compute mac', { cause: error });\n }\n}\n"],"mappings":";;;;;;;;;;;;AASA,SAAgB,cAAc,MAAgC;AAC5D,KAAI;EACF,MAAM,SAASA,+BAAO,QAAQ;AAC9B,OAAK,MAAM,KAAK,KACd,QAAO,OAAO,EAAE;AAElB,SAAO,OAAO,QAAQ;UACf,OAAO;AACd,QAAM,IAAI,MAAM,0BAA0B,EAAE,OAAO,OAAO,CAAC;;;;;;;;;AAU/D,SAAgB,iBAAiB,MAA4B;AAC3D,+CAAkB,cAAc,KAAK,CAAC;;AAGxC,SAAgB,wBAAwB,SAAqB,MAA4B;AACvF,KAAI;AAEF,gDADa,qBAAqB,SAAS,KAAK,CACzB;UAChB,OAAO;AACd,QAAM,IAAI,MAAM,8BAA8B,EAAE,OAAO,OAAO,CAAC;;;AAInE,SAAgB,qBAAqB,SAAqB,MAAgC;AACxF,KAAI;EACF,MAAM,SAASA,+BAAO,OAAO,EAAE,KAAK,SAAS,CAAC;AAC9C,OAAK,MAAM,KAAK,KACd,QAAO,OAAO,EAAE;AAElB,SAAO,OAAO,QAAQ;UACf,OAAO;AACd,QAAM,IAAI,MAAM,0BAA0B,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;AAW/D,SAAgB,sBAAsB,OAAe,MAAgC;AACnF,KAAI;EACF,MAAM,SAASA,+BAAO,OAAO,EAAE,OAAO,OAAO,CAAC;AAC9C,OAAK,MAAM,SAAS,KAClB,QAAO,OAAO,MAAM;AAEtB,SAAO,OAAO,QAAQ;UACf,OAAO;AACd,QAAM,IAAI,MAAM,iCAAiC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;AAWtE,SAAgB,yBAAyB,OAAe,MAA4B;AAClF,KAAI;AAEF,gDADa,sBAAsB,OAAO,KAAK,CACxB;UAChB,OAAO;AACd,QAAM,IAAI,MAAM,iCAAiC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;AAWtE,SAAgB,iBAAiB,OAAe,MAA8B;AAC5E,4CAAc,MAAM,EAAE,OAAO,OAAO,CAAC;;;;;;;;;AAUvC,SAAgB,oBAAoB,OAAe,MAA0B;AAC3E,+CAAkB,iBAAiB,OAAO,KAAK,CAAC;;;;;;;;;;;;AC/FlD,SAAgB,WAAW,aAAyB,MAA4B;AAC9E,KAAI;AAGF,gDADa,qBADD,iBAAiBC,uCAAqB,GAAG,YAAY,EAC1B,KAAK,CACrB;UAChB,OAAO;AACd,QAAM,IAAI,MAAM,yBAAyB,EAAE,OAAO,OAAO,CAAC"}
@@ -1,116 +0,0 @@
1
- import { AES_KEY_BIT_LENGTH } from "./constants.mjs";
2
- import { blake3 } from "@noble/hashes/blake3.js";
3
- import { bytesToHex } from "@noble/hashes/utils.js";
4
-
5
- //#region src/hash/blake3.ts
6
- /**
7
- * Hashes the given array of data
8
- *
9
- * @param data - The data to hash
10
- * @returns The resulting hash array
11
- */
12
- function hashDataArray(data) {
13
- try {
14
- const hasher = blake3.create();
15
- for (const d of data) hasher.update(d);
16
- return hasher.digest();
17
- } catch (error) {
18
- throw new Error("Failed to compute hash", { cause: error });
19
- }
20
- }
21
- /**
22
- * Hashes the given array of data
23
- *
24
- * @param data - The data to hash
25
- * @returns The resulting hash hex string
26
- */
27
- function hashDataArrayHex(data) {
28
- return bytesToHex(hashDataArray(data));
29
- }
30
- function hashDataArrayWithKeyHex(hashKey, data) {
31
- try {
32
- return bytesToHex(hashDataArrayWithKey(hashKey, data));
33
- } catch (error) {
34
- throw new Error("Failed to compute hash hex", { cause: error });
35
- }
36
- }
37
- function hashDataArrayWithKey(hashKey, data) {
38
- try {
39
- const hasher = blake3.create({ key: hashKey });
40
- for (const d of data) hasher.update(d);
41
- return hasher.digest();
42
- } catch (error) {
43
- throw new Error("Failed to compute hash", { cause: error });
44
- }
45
- }
46
- /**
47
- * Hashes the given array of data using blake3 algorithm
48
- *
49
- * @param bytes - The desired output byte-length
50
- * @param data - The data to hash
51
- * @returns The resulting hash value
52
- */
53
- function getBytesFromDataArray(bytes, data) {
54
- try {
55
- const hasher = blake3.create({ dkLen: bytes });
56
- for (const chunk of data) hasher.update(chunk);
57
- return hasher.digest();
58
- } catch (error) {
59
- throw new Error("Failed to get bytes from data", { cause: error });
60
- }
61
- }
62
- /**
63
- * Hashes the given array of data using blake3 algorithm
64
- *
65
- * @param bytes - The desired output byte-length
66
- * @param data - The data to hash
67
- * @returns The resulting hash value
68
- */
69
- function getBytesFromDataArrayHex(bytes, data) {
70
- try {
71
- return bytesToHex(getBytesFromDataArray(bytes, data));
72
- } catch (error) {
73
- throw new Error("Failed to get bytes from data", { cause: error });
74
- }
75
- }
76
- /**
77
- * Hashes the given string using blake3 algorithm
78
- *
79
- * @param bytes - The desired output byte-length
80
- * @param data - The data to hash
81
- * @returns The resulting hash value
82
- */
83
- function getBytesFromData(bytes, data) {
84
- return blake3(data, { dkLen: bytes });
85
- }
86
- /**
87
- * Hashes the given data using blake3 algorithm
88
- *
89
- * @param bytes - The desired output byte-length
90
- * @param data - The data to hash
91
- * @returns The resulting hash value
92
- */
93
- function getBytesFromDataHex(bytes, data) {
94
- return bytesToHex(getBytesFromData(bytes, data));
95
- }
96
-
97
- //#endregion
98
- //#region src/hash/mac.ts
99
- /**
100
- * Computes mac for the given key material and data
101
- *
102
- * @param keyMaterial - The key material
103
- * @param data - The data to hash
104
- * @returns The resulting hash hex string
105
- */
106
- function computeMac(keyMaterial, data) {
107
- try {
108
- return bytesToHex(hashDataArrayWithKey(getBytesFromData(AES_KEY_BIT_LENGTH / 8, keyMaterial), data));
109
- } catch (error) {
110
- throw new Error("Failed to compute mac", { cause: error });
111
- }
112
- }
113
-
114
- //#endregion
115
- export { getBytesFromDataHex as a, hashDataArrayWithKey as c, getBytesFromDataArrayHex as i, hashDataArrayWithKeyHex as l, getBytesFromData as n, hashDataArray as o, getBytesFromDataArray as r, hashDataArrayHex as s, computeMac as t };
116
- //# sourceMappingURL=mac-ZpRlx8Fs.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mac-ZpRlx8Fs.mjs","names":[],"sources":["../src/hash/blake3.ts","../src/hash/mac.ts"],"sourcesContent":["import { blake3 } from '@noble/hashes/blake3.js';\nimport { 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 hashDataArray(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\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 hashDataArrayHex(data: Uint8Array[]): string {\n return bytesToHex(hashDataArray(data));\n}\n\nexport function hashDataArrayWithKeyHex(hashKey: Uint8Array, data: Uint8Array[]): string {\n try {\n const hash = hashDataArrayWithKey(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 hashDataArrayWithKey(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 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 getBytesFromDataArray(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 getBytesFromDataArrayHex(bytes: number, data: Uint8Array[]): string {\n try {\n const hash = getBytesFromDataArray(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 data - The data to hash\n * @returns The resulting hash value\n */\nexport function getBytesFromData(bytes: number, data: Uint8Array): Uint8Array {\n return blake3(data, { dkLen: bytes });\n}\n\n/**\n * Hashes the given 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 return bytesToHex(getBytesFromData(bytes, data));\n}\n","import { bytesToHex } from '@noble/hashes/utils.js';\nimport { AES_KEY_BIT_LENGTH } from '../constants';\nimport { getBytesFromData, hashDataArrayWithKey } 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: Uint8Array, data: Uint8Array[]): string {\n try {\n const key = getBytesFromData(AES_KEY_BIT_LENGTH / 8, keyMaterial);\n const hash = hashDataArrayWithKey(key, data);\n return bytesToHex(hash);\n } catch (error) {\n throw new Error('Failed to compute mac', { cause: error });\n }\n}\n"],"mappings":";;;;;;;;;;;AASA,SAAgB,cAAc,MAAgC;AAC5D,KAAI;EACF,MAAM,SAAS,OAAO,QAAQ;AAC9B,OAAK,MAAM,KAAK,KACd,QAAO,OAAO,EAAE;AAElB,SAAO,OAAO,QAAQ;UACf,OAAO;AACd,QAAM,IAAI,MAAM,0BAA0B,EAAE,OAAO,OAAO,CAAC;;;;;;;;;AAU/D,SAAgB,iBAAiB,MAA4B;AAC3D,QAAO,WAAW,cAAc,KAAK,CAAC;;AAGxC,SAAgB,wBAAwB,SAAqB,MAA4B;AACvF,KAAI;AAEF,SAAO,WADM,qBAAqB,SAAS,KAAK,CACzB;UAChB,OAAO;AACd,QAAM,IAAI,MAAM,8BAA8B,EAAE,OAAO,OAAO,CAAC;;;AAInE,SAAgB,qBAAqB,SAAqB,MAAgC;AACxF,KAAI;EACF,MAAM,SAAS,OAAO,OAAO,EAAE,KAAK,SAAS,CAAC;AAC9C,OAAK,MAAM,KAAK,KACd,QAAO,OAAO,EAAE;AAElB,SAAO,OAAO,QAAQ;UACf,OAAO;AACd,QAAM,IAAI,MAAM,0BAA0B,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;AAW/D,SAAgB,sBAAsB,OAAe,MAAgC;AACnF,KAAI;EACF,MAAM,SAAS,OAAO,OAAO,EAAE,OAAO,OAAO,CAAC;AAC9C,OAAK,MAAM,SAAS,KAClB,QAAO,OAAO,MAAM;AAEtB,SAAO,OAAO,QAAQ;UACf,OAAO;AACd,QAAM,IAAI,MAAM,iCAAiC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;AAWtE,SAAgB,yBAAyB,OAAe,MAA4B;AAClF,KAAI;AAEF,SAAO,WADM,sBAAsB,OAAO,KAAK,CACxB;UAChB,OAAO;AACd,QAAM,IAAI,MAAM,iCAAiC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;AAWtE,SAAgB,iBAAiB,OAAe,MAA8B;AAC5E,QAAO,OAAO,MAAM,EAAE,OAAO,OAAO,CAAC;;;;;;;;;AAUvC,SAAgB,oBAAoB,OAAe,MAA0B;AAC3E,QAAO,WAAW,iBAAiB,OAAO,KAAK,CAAC;;;;;;;;;;;;AC/FlD,SAAgB,WAAW,aAAyB,MAA4B;AAC9E,KAAI;AAGF,SAAO,WADM,qBADD,iBAAiB,qBAAqB,GAAG,YAAY,EAC1B,KAAK,CACrB;UAChB,OAAO;AACd,QAAM,IAAI,MAAM,yBAAyB,EAAE,OAAO,OAAO,CAAC"}