internxt-crypto 0.0.14 → 1.0.0

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 +3 -2
  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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emailEncryptionKey-BtSPYd9M.mjs","names":[],"sources":["../src/keystore-crypto/core.ts","../src/keystore-crypto/emailEncryptionKey.ts"],"sourcesContent":["import { encryptSymmetrically, decryptSymmetrically } from '../symmetric-crypto';\nimport { base64ToUint8Array, uint8ArrayToBase64, UTF8ToUint8, mnemonicToBytes } from '../utils';\nimport { deriveSymmetricKeyFromContext } from '../derive-key';\nimport { CONTEXT_ENC_KEYSTORE, CONTEXT_RECOVERY } from '../constants';\nimport { EncryptedKeystore, HybridKeyPair, KeystoreType } from '../types';\n\n/**\n * Encrypts the user's hybrid key using symmetric encryption to get a keystore\n *\n * @param secretKey - The symmetric key to encrypt the keystore content\n * @param key - The hybrid key pair\n * @param userEmail - The email of the user\n * @param type - The keystore type\n * @returns The encrypted keystore\n */\nexport async function encryptKeystoreContent(\n secretKey: Uint8Array,\n keys: HybridKeyPair,\n userEmail: string,\n type: KeystoreType,\n): Promise<EncryptedKeystore> {\n try {\n const aux = UTF8ToUint8(userEmail + type);\n const publicKey = uint8ArrayToBase64(keys.publicKey);\n const secretKeyEncrypted = await encryptSymmetrically(secretKey, keys.secretKey, aux);\n\n const keystore: EncryptedKeystore = {\n userEmail,\n type,\n publicKey,\n privateKeyEncrypted: uint8ArrayToBase64(secretKeyEncrypted),\n };\n return keystore;\n } catch (error) {\n throw new Error('Failed to encrypt keystore content', { cause: error });\n }\n}\n\n/**\n * Decrypts the keystore content using symmetric encryption\n *\n * @param kesytoreOpeningKey - The symmetric key to decrypt the keystore content\n * @param encryptedKeys - The encrypted keystore content\n * @returns The decrypted hybrid key pair contained in the keystore\n */\nexport async function decryptKeystoreContent(\n kesytoreOpeningKey: Uint8Array,\n encryptedKeystore: EncryptedKeystore,\n): Promise<HybridKeyPair> {\n try {\n const aux = UTF8ToUint8(encryptedKeystore.userEmail + encryptedKeystore.type);\n const publicKey = base64ToUint8Array(encryptedKeystore.publicKey);\n const ciphertext = base64ToUint8Array(encryptedKeystore.privateKeyEncrypted);\n const secretKey = await decryptSymmetrically(kesytoreOpeningKey, ciphertext, aux);\n return {\n publicKey,\n secretKey,\n };\n } catch (error) {\n throw new Error('Failed to decrypt keystore content', { cause: error });\n }\n}\n\n/**\n * Derives a secret key for protecting the recovery keystore\n *\n * @param recoveryCodes - The recovery codes\n * @returns The derived secret key for protecting the recovery keystore\n */\nexport async function deriveRecoveryKey(recoveryCodes: string): Promise<Uint8Array> {\n const recoverCodesArray = mnemonicToBytes(recoveryCodes);\n return deriveSymmetricKeyFromContext(CONTEXT_RECOVERY, recoverCodesArray);\n}\n\n/**\n * Derives a secret key for protecting the encryption keystore\n *\n * @param baseKey - The base secret key from which a new key secret will be derived\n * @returns The derived secret key for protecting the encryption keystore\n */\nexport async function deriveEncryptionKeystoreKey(baseKey: Uint8Array): Promise<Uint8Array> {\n return deriveSymmetricKeyFromContext(CONTEXT_ENC_KEYSTORE, baseKey);\n}\n","import { EncryptedKeystore, KeystoreType, HybridKeyPair } from '../types';\nimport { genMnemonic } from '../utils';\nimport { encryptKeystoreContent, decryptKeystoreContent, deriveEncryptionKeystoreKey, deriveRecoveryKey } from './core';\nimport { genHybridKeys } from '../hybrid-crypto';\n\n/**\n * Generates hybrid keys and creates encrypted main and recovery keystores\n * The main keystore encryption key is derived from the base key (stored in session storage)\n * The recovery keystore encryption key is derived from the recovery codes\n *\n * @returns The encryption and recovery keystores, recovery codes and hybrid keys\n */\nexport async function createEncryptionAndRecoveryKeystores(\n userEmail: string,\n baseKey: Uint8Array,\n): Promise<{\n encryptionKeystore: EncryptedKeystore;\n recoveryKeystore: EncryptedKeystore;\n recoveryCodes: string;\n keys: HybridKeyPair;\n}> {\n try {\n const keys = genHybridKeys();\n\n const secretKey = await deriveEncryptionKeystoreKey(baseKey);\n const encryptionKeystore = await encryptKeystoreContent(secretKey, keys, userEmail, KeystoreType.ENCRYPTION);\n\n const recoveryCodes = genMnemonic();\n const recoveryKey = await deriveRecoveryKey(recoveryCodes);\n const recoveryKeystore = await encryptKeystoreContent(recoveryKey, keys, userEmail, KeystoreType.RECOVERY);\n\n return { encryptionKeystore, recoveryKeystore, recoveryCodes, keys };\n } catch (error) {\n throw new Error('Failed to create encryption and recovery keystores', { cause: error });\n }\n}\n\n/**\n * Opens the encryption keystore and returns the email encryption keys\n * The decryption key is derived from the base key (stored in session storage)\n *\n * @param encryptedKeystore - The encrypted keystore containing encryption keys\n * @param baseKey - The base key from which the decryption key will be derived\n * @returns The encryption keys\n */\nexport async function openEncryptionKeystore(\n encryptedKeystore: EncryptedKeystore,\n baseKey: Uint8Array,\n): Promise<HybridKeyPair> {\n try {\n if (encryptedKeystore.type != KeystoreType.ENCRYPTION) {\n throw new Error('Input is invalid');\n }\n const secretKey = await deriveEncryptionKeystoreKey(baseKey);\n const keys = await decryptKeystoreContent(secretKey, encryptedKeystore);\n return keys;\n } catch (error) {\n throw new Error('Failed to open encryption keystore', { cause: error });\n }\n}\n\n/**\n * Opens the recovery keystore and returns the email encryption keys\n * The decryption key is derived from the base key (stored in session storage)\n *\n * @param recoveryCodes - The user's recovery codes\n * @param encryptedKeystore - The encrypted keystore containing encryption keys\n * @returns The encryption keys\n */\nexport async function openRecoveryKeystore(\n recoveryCodes: string,\n encryptedKeystore: EncryptedKeystore,\n): Promise<HybridKeyPair> {\n try {\n if (encryptedKeystore.type != KeystoreType.RECOVERY) {\n throw new Error('Input is invalid');\n }\n const recoveryKey = await deriveRecoveryKey(recoveryCodes);\n const keys = await decryptKeystoreContent(recoveryKey, encryptedKeystore);\n return keys;\n } catch (error) {\n throw new Error('Failed to open recovery keystore', { cause: error });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAeA,eAAsB,uBACpB,WACA,MACA,WACA,MAC4B;AAC5B,KAAI;EACF,MAAM,MAAM,YAAY,YAAY,KAAK;AAUzC,SANoC;GAClC;GACA;GACA,WANgB,mBAAmB,KAAK,UAAU;GAOlD,qBAAqB,mBANI,MAAM,qBAAqB,WAAW,KAAK,WAAW,IAAI,CAMxB;GAC5D;UAEM,OAAO;AACd,QAAM,IAAI,MAAM,sCAAsC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;AAW3E,eAAsB,uBACpB,oBACA,mBACwB;AACxB,KAAI;EACF,MAAM,MAAM,YAAY,kBAAkB,YAAY,kBAAkB,KAAK;AAI7E,SAAO;GACL,WAJgB,mBAAmB,kBAAkB,UAAU;GAK/D,WAHgB,MAAM,qBAAqB,oBAD1B,mBAAmB,kBAAkB,oBAAoB,EACC,IAAI;GAIhF;UACM,OAAO;AACd,QAAM,IAAI,MAAM,sCAAsC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;AAU3E,eAAsB,kBAAkB,eAA4C;AAElF,QAAO,8BAA8B,kBADX,gBAAgB,cAAc,CACiB;;;;;;;;AAS3E,eAAsB,4BAA4B,SAA0C;AAC1F,QAAO,8BAA8B,sBAAsB,QAAQ;;;;;;;;;;;;ACrErE,eAAsB,qCACpB,WACA,SAMC;AACD,KAAI;EACF,MAAM,OAAO,eAAe;EAG5B,MAAM,qBAAqB,MAAM,uBADf,MAAM,4BAA4B,QAAQ,EACO,MAAM,WAAW,aAAa,WAAW;EAE5G,MAAM,gBAAgB,aAAa;AAInC,SAAO;GAAE;GAAoB,kBAFJ,MAAM,uBADX,MAAM,kBAAkB,cAAc,EACS,MAAM,WAAW,aAAa,SAAS;GAE3D;GAAe;GAAM;UAC7D,OAAO;AACd,QAAM,IAAI,MAAM,sDAAsD,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;AAY3F,eAAsB,uBACpB,mBACA,SACwB;AACxB,KAAI;AACF,MAAI,kBAAkB,QAAQ,aAAa,WACzC,OAAM,IAAI,MAAM,mBAAmB;AAIrC,SADa,MAAM,uBADD,MAAM,4BAA4B,QAAQ,EACP,kBAAkB;UAEhE,OAAO;AACd,QAAM,IAAI,MAAM,sCAAsC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;AAY3E,eAAsB,qBACpB,eACA,mBACwB;AACxB,KAAI;AACF,MAAI,kBAAkB,QAAQ,aAAa,SACzC,OAAM,IAAI,MAAM,mBAAmB;AAIrC,SADa,MAAM,uBADC,MAAM,kBAAkB,cAAc,EACH,kBAAkB;UAElE,OAAO;AACd,QAAM,IAAI,MAAM,oCAAoC,EAAE,OAAO,OAAO,CAAC"}
@@ -1,38 +1,28 @@
1
1
  const require_constants = require('./constants.js');
2
- const require_keys = require('./keys-CinT7kEY.js');
3
- const require_genID = require('./genID-YJSl3YhL.js');
4
- const require_mac = require('./mac-BMb1F0dN.js');
5
- const require_aes = require('./aes-DQo1MyCz.js');
6
- const require_deriveKeysFromPassword = require('./deriveKeysFromPassword-BYaiSGKL.js');
7
- const require_emailKeys = require('./emailKeys-C0KhtfNP.js');
2
+ const require_genID = require('./genID-cWOPmspk.js');
3
+ const require_deriveKeysFromKey = require('./deriveKeysFromKey-C4McqO6_.js');
4
+ const require_aes = require('./aes-CuW_SPl-.js');
5
+ const require_xwing = require('./xwing-iRWVRtNE.js');
8
6
  const require_types = require('./types.js');
9
7
 
10
8
  //#region src/keystore-crypto/core.ts
11
9
  /**
12
- * Encrypts the keystore content using symmetric encryption
10
+ * Encrypts the user's hybrid key using symmetric encryption to get a keystore
13
11
  *
14
12
  * @param secretKey - The symmetric key to encrypt the keystore content
15
- * @param content - The content of the keystore
16
- * @param userID - The ID of the user
17
- * @param tag - The keystore type-specific tag string
18
- * @returns The encrypted keystore content
13
+ * @param key - The hybrid key pair
14
+ * @param userEmail - The email of the user
15
+ * @param type - The keystore type
16
+ * @returns The encrypted keystore
19
17
  */
20
18
  async function encryptKeystoreContent(secretKey, keys, userEmail, type) {
21
19
  try {
22
20
  const aux = require_genID.UTF8ToUint8(userEmail + type);
23
- const publicKeys = await require_genID.publicKeyToBase64(keys.publicKeys);
24
- const kyberPrivateKeyEnc = await require_aes.encryptSymmetrically(secretKey, keys.privateKeys.kyberPrivateKey, aux);
25
- const eccPrivateKeyEnc = await require_aes.encryptSymmetrically(secretKey, await require_keys.exportPrivateKey(keys.privateKeys.eccPrivateKey), aux);
26
21
  return {
27
22
  userEmail,
28
23
  type,
29
- encryptedKeys: {
30
- publicKeys,
31
- privateKeys: {
32
- kyberPrivateKeyBase64: require_genID.uint8ArrayToBase64(kyberPrivateKeyEnc),
33
- eccPrivateKeyBase64: require_genID.uint8ArrayToBase64(eccPrivateKeyEnc)
34
- }
35
- }
24
+ publicKey: require_genID.uint8ArrayToBase64(keys.publicKey),
25
+ privateKeyEncrypted: require_genID.uint8ArrayToBase64(await require_aes.encryptSymmetrically(secretKey, keys.secretKey, aux))
36
26
  };
37
27
  } catch (error) {
38
28
  throw new Error("Failed to encrypt keystore content", { cause: error });
@@ -41,28 +31,16 @@ async function encryptKeystoreContent(secretKey, keys, userEmail, type) {
41
31
  /**
42
32
  * Decrypts the keystore content using symmetric encryption
43
33
  *
44
- * @param secretKey - The symmetric key to decrypt the keystore content
34
+ * @param kesytoreOpeningKey - The symmetric key to decrypt the keystore content
45
35
  * @param encryptedKeys - The encrypted keystore content
46
- * @param userEmail - The ID of the user
47
- * @param tag - The keystore type-specific tag string
48
- * @returns The decrypted keystore content
36
+ * @returns The decrypted hybrid key pair contained in the keystore
49
37
  */
50
- async function decryptKeystoreContent(secretKey, encryptedKeystore) {
38
+ async function decryptKeystoreContent(kesytoreOpeningKey, encryptedKeystore) {
51
39
  try {
52
40
  const aux = require_genID.UTF8ToUint8(encryptedKeystore.userEmail + encryptedKeystore.type);
53
- const kyberPublicKey = require_genID.base64ToUint8Array(encryptedKeystore.encryptedKeys.publicKeys.kyberPublicKeyBase64);
54
- const eccPublicKey = await require_keys.importPublicKey(require_genID.base64ToUint8Array(encryptedKeystore.encryptedKeys.publicKeys.eccPublicKeyBase64));
55
- const kyberPrivateKey = await require_aes.decryptSymmetrically(secretKey, require_genID.base64ToUint8Array(encryptedKeystore.encryptedKeys.privateKeys.kyberPrivateKeyBase64), aux);
56
- const eccPrivateKey = await require_keys.importPrivateKey(await require_aes.decryptSymmetrically(secretKey, require_genID.base64ToUint8Array(encryptedKeystore.encryptedKeys.privateKeys.eccPrivateKeyBase64), aux));
57
41
  return {
58
- publicKeys: {
59
- kyberPublicKey,
60
- eccPublicKey
61
- },
62
- privateKeys: {
63
- kyberPrivateKey,
64
- eccPrivateKey
65
- }
42
+ publicKey: require_genID.base64ToUint8Array(encryptedKeystore.publicKey),
43
+ secretKey: await require_aes.decryptSymmetrically(kesytoreOpeningKey, require_genID.base64ToUint8Array(encryptedKeystore.privateKeyEncrypted), aux)
66
44
  };
67
45
  } catch (error) {
68
46
  throw new Error("Failed to decrypt keystore content", { cause: error });
@@ -75,8 +53,7 @@ async function decryptKeystoreContent(secretKey, encryptedKeystore) {
75
53
  * @returns The derived secret key for protecting the recovery keystore
76
54
  */
77
55
  async function deriveRecoveryKey(recoveryCodes) {
78
- const recoverCodesArray = require_genID.mnemonicToBytes(recoveryCodes);
79
- return require_deriveKeysFromPassword.deriveSymmetricKeyFromContext(require_constants.CONTEXT_RECOVERY, require_mac.getBytesFromData(require_constants.AES_KEY_BIT_LENGTH / 8, recoverCodesArray));
56
+ return require_deriveKeysFromKey.deriveSymmetricKeyFromContext(require_constants.CONTEXT_RECOVERY, require_genID.mnemonicToBytes(recoveryCodes));
80
57
  }
81
58
  /**
82
59
  * Derives a secret key for protecting the encryption keystore
@@ -85,21 +62,21 @@ async function deriveRecoveryKey(recoveryCodes) {
85
62
  * @returns The derived secret key for protecting the encryption keystore
86
63
  */
87
64
  async function deriveEncryptionKeystoreKey(baseKey) {
88
- return require_deriveKeysFromPassword.deriveSymmetricKeyFromContext(require_constants.CONTEXT_ENC_KEYSTORE, baseKey);
65
+ return require_deriveKeysFromKey.deriveSymmetricKeyFromContext(require_constants.CONTEXT_ENC_KEYSTORE, baseKey);
89
66
  }
90
67
 
91
68
  //#endregion
92
69
  //#region src/keystore-crypto/emailEncryptionKey.ts
93
70
  /**
94
- * Generates email keys and creates encrypted main and recovery keystores
71
+ * Generates hybrid keys and creates encrypted main and recovery keystores
95
72
  * The main keystore encryption key is derived from the base key (stored in session storage)
96
73
  * The recovery keystore encryption key is derived from the recovery codes
97
74
  *
98
- * @returns The encryption and recovery keystores, recovery codes and email keys
75
+ * @returns The encryption and recovery keystores, recovery codes and hybrid keys
99
76
  */
100
77
  async function createEncryptionAndRecoveryKeystores(userEmail, baseKey) {
101
78
  try {
102
- const keys = await require_emailKeys.generateEmailKeys();
79
+ const keys = require_xwing.genHybridKeys();
103
80
  const encryptionKeystore = await encryptKeystoreContent(await deriveEncryptionKeystoreKey(baseKey), keys, userEmail, require_types.KeystoreType.ENCRYPTION);
104
81
  const recoveryCodes = require_genID.genMnemonic();
105
82
  return {
@@ -164,4 +141,4 @@ Object.defineProperty(exports, 'openRecoveryKeystore', {
164
141
  return openRecoveryKeystore;
165
142
  }
166
143
  });
167
- //# sourceMappingURL=emailEncryptionKey-CQNe5W_T.js.map
144
+ //# sourceMappingURL=emailEncryptionKey-C4X1Bwy4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emailEncryptionKey-C4X1Bwy4.js","names":["UTF8ToUint8","uint8ArrayToBase64","encryptSymmetrically","base64ToUint8Array","decryptSymmetrically","deriveSymmetricKeyFromContext","CONTEXT_RECOVERY","mnemonicToBytes","CONTEXT_ENC_KEYSTORE","genHybridKeys","KeystoreType","genMnemonic"],"sources":["../src/keystore-crypto/core.ts","../src/keystore-crypto/emailEncryptionKey.ts"],"sourcesContent":["import { encryptSymmetrically, decryptSymmetrically } from '../symmetric-crypto';\nimport { base64ToUint8Array, uint8ArrayToBase64, UTF8ToUint8, mnemonicToBytes } from '../utils';\nimport { deriveSymmetricKeyFromContext } from '../derive-key';\nimport { CONTEXT_ENC_KEYSTORE, CONTEXT_RECOVERY } from '../constants';\nimport { EncryptedKeystore, HybridKeyPair, KeystoreType } from '../types';\n\n/**\n * Encrypts the user's hybrid key using symmetric encryption to get a keystore\n *\n * @param secretKey - The symmetric key to encrypt the keystore content\n * @param key - The hybrid key pair\n * @param userEmail - The email of the user\n * @param type - The keystore type\n * @returns The encrypted keystore\n */\nexport async function encryptKeystoreContent(\n secretKey: Uint8Array,\n keys: HybridKeyPair,\n userEmail: string,\n type: KeystoreType,\n): Promise<EncryptedKeystore> {\n try {\n const aux = UTF8ToUint8(userEmail + type);\n const publicKey = uint8ArrayToBase64(keys.publicKey);\n const secretKeyEncrypted = await encryptSymmetrically(secretKey, keys.secretKey, aux);\n\n const keystore: EncryptedKeystore = {\n userEmail,\n type,\n publicKey,\n privateKeyEncrypted: uint8ArrayToBase64(secretKeyEncrypted),\n };\n return keystore;\n } catch (error) {\n throw new Error('Failed to encrypt keystore content', { cause: error });\n }\n}\n\n/**\n * Decrypts the keystore content using symmetric encryption\n *\n * @param kesytoreOpeningKey - The symmetric key to decrypt the keystore content\n * @param encryptedKeys - The encrypted keystore content\n * @returns The decrypted hybrid key pair contained in the keystore\n */\nexport async function decryptKeystoreContent(\n kesytoreOpeningKey: Uint8Array,\n encryptedKeystore: EncryptedKeystore,\n): Promise<HybridKeyPair> {\n try {\n const aux = UTF8ToUint8(encryptedKeystore.userEmail + encryptedKeystore.type);\n const publicKey = base64ToUint8Array(encryptedKeystore.publicKey);\n const ciphertext = base64ToUint8Array(encryptedKeystore.privateKeyEncrypted);\n const secretKey = await decryptSymmetrically(kesytoreOpeningKey, ciphertext, aux);\n return {\n publicKey,\n secretKey,\n };\n } catch (error) {\n throw new Error('Failed to decrypt keystore content', { cause: error });\n }\n}\n\n/**\n * Derives a secret key for protecting the recovery keystore\n *\n * @param recoveryCodes - The recovery codes\n * @returns The derived secret key for protecting the recovery keystore\n */\nexport async function deriveRecoveryKey(recoveryCodes: string): Promise<Uint8Array> {\n const recoverCodesArray = mnemonicToBytes(recoveryCodes);\n return deriveSymmetricKeyFromContext(CONTEXT_RECOVERY, recoverCodesArray);\n}\n\n/**\n * Derives a secret key for protecting the encryption keystore\n *\n * @param baseKey - The base secret key from which a new key secret will be derived\n * @returns The derived secret key for protecting the encryption keystore\n */\nexport async function deriveEncryptionKeystoreKey(baseKey: Uint8Array): Promise<Uint8Array> {\n return deriveSymmetricKeyFromContext(CONTEXT_ENC_KEYSTORE, baseKey);\n}\n","import { EncryptedKeystore, KeystoreType, HybridKeyPair } from '../types';\nimport { genMnemonic } from '../utils';\nimport { encryptKeystoreContent, decryptKeystoreContent, deriveEncryptionKeystoreKey, deriveRecoveryKey } from './core';\nimport { genHybridKeys } from '../hybrid-crypto';\n\n/**\n * Generates hybrid keys and creates encrypted main and recovery keystores\n * The main keystore encryption key is derived from the base key (stored in session storage)\n * The recovery keystore encryption key is derived from the recovery codes\n *\n * @returns The encryption and recovery keystores, recovery codes and hybrid keys\n */\nexport async function createEncryptionAndRecoveryKeystores(\n userEmail: string,\n baseKey: Uint8Array,\n): Promise<{\n encryptionKeystore: EncryptedKeystore;\n recoveryKeystore: EncryptedKeystore;\n recoveryCodes: string;\n keys: HybridKeyPair;\n}> {\n try {\n const keys = genHybridKeys();\n\n const secretKey = await deriveEncryptionKeystoreKey(baseKey);\n const encryptionKeystore = await encryptKeystoreContent(secretKey, keys, userEmail, KeystoreType.ENCRYPTION);\n\n const recoveryCodes = genMnemonic();\n const recoveryKey = await deriveRecoveryKey(recoveryCodes);\n const recoveryKeystore = await encryptKeystoreContent(recoveryKey, keys, userEmail, KeystoreType.RECOVERY);\n\n return { encryptionKeystore, recoveryKeystore, recoveryCodes, keys };\n } catch (error) {\n throw new Error('Failed to create encryption and recovery keystores', { cause: error });\n }\n}\n\n/**\n * Opens the encryption keystore and returns the email encryption keys\n * The decryption key is derived from the base key (stored in session storage)\n *\n * @param encryptedKeystore - The encrypted keystore containing encryption keys\n * @param baseKey - The base key from which the decryption key will be derived\n * @returns The encryption keys\n */\nexport async function openEncryptionKeystore(\n encryptedKeystore: EncryptedKeystore,\n baseKey: Uint8Array,\n): Promise<HybridKeyPair> {\n try {\n if (encryptedKeystore.type != KeystoreType.ENCRYPTION) {\n throw new Error('Input is invalid');\n }\n const secretKey = await deriveEncryptionKeystoreKey(baseKey);\n const keys = await decryptKeystoreContent(secretKey, encryptedKeystore);\n return keys;\n } catch (error) {\n throw new Error('Failed to open encryption keystore', { cause: error });\n }\n}\n\n/**\n * Opens the recovery keystore and returns the email encryption keys\n * The decryption key is derived from the base key (stored in session storage)\n *\n * @param recoveryCodes - The user's recovery codes\n * @param encryptedKeystore - The encrypted keystore containing encryption keys\n * @returns The encryption keys\n */\nexport async function openRecoveryKeystore(\n recoveryCodes: string,\n encryptedKeystore: EncryptedKeystore,\n): Promise<HybridKeyPair> {\n try {\n if (encryptedKeystore.type != KeystoreType.RECOVERY) {\n throw new Error('Input is invalid');\n }\n const recoveryKey = await deriveRecoveryKey(recoveryCodes);\n const keys = await decryptKeystoreContent(recoveryKey, encryptedKeystore);\n return keys;\n } catch (error) {\n throw new Error('Failed to open recovery keystore', { cause: error });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAeA,eAAsB,uBACpB,WACA,MACA,WACA,MAC4B;AAC5B,KAAI;EACF,MAAM,MAAMA,0BAAY,YAAY,KAAK;AAUzC,SANoC;GAClC;GACA;GACA,WANgBC,iCAAmB,KAAK,UAAU;GAOlD,qBAAqBA,iCANI,MAAMC,iCAAqB,WAAW,KAAK,WAAW,IAAI,CAMxB;GAC5D;UAEM,OAAO;AACd,QAAM,IAAI,MAAM,sCAAsC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;AAW3E,eAAsB,uBACpB,oBACA,mBACwB;AACxB,KAAI;EACF,MAAM,MAAMF,0BAAY,kBAAkB,YAAY,kBAAkB,KAAK;AAI7E,SAAO;GACL,WAJgBG,iCAAmB,kBAAkB,UAAU;GAK/D,WAHgB,MAAMC,iCAAqB,oBAD1BD,iCAAmB,kBAAkB,oBAAoB,EACC,IAAI;GAIhF;UACM,OAAO;AACd,QAAM,IAAI,MAAM,sCAAsC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;AAU3E,eAAsB,kBAAkB,eAA4C;AAElF,QAAOE,wDAA8BC,oCADXC,8BAAgB,cAAc,CACiB;;;;;;;;AAS3E,eAAsB,4BAA4B,SAA0C;AAC1F,QAAOF,wDAA8BG,wCAAsB,QAAQ;;;;;;;;;;;;ACrErE,eAAsB,qCACpB,WACA,SAMC;AACD,KAAI;EACF,MAAM,OAAOC,6BAAe;EAG5B,MAAM,qBAAqB,MAAM,uBADf,MAAM,4BAA4B,QAAQ,EACO,MAAM,WAAWC,2BAAa,WAAW;EAE5G,MAAM,gBAAgBC,2BAAa;AAInC,SAAO;GAAE;GAAoB,kBAFJ,MAAM,uBADX,MAAM,kBAAkB,cAAc,EACS,MAAM,WAAWD,2BAAa,SAAS;GAE3D;GAAe;GAAM;UAC7D,OAAO;AACd,QAAM,IAAI,MAAM,sDAAsD,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;AAY3F,eAAsB,uBACpB,mBACA,SACwB;AACxB,KAAI;AACF,MAAI,kBAAkB,QAAQA,2BAAa,WACzC,OAAM,IAAI,MAAM,mBAAmB;AAIrC,SADa,MAAM,uBADD,MAAM,4BAA4B,QAAQ,EACP,kBAAkB;UAEhE,OAAO;AACd,QAAM,IAAI,MAAM,sCAAsC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;AAY3E,eAAsB,qBACpB,eACA,mBACwB;AACxB,KAAI;AACF,MAAI,kBAAkB,QAAQA,2BAAa,SACzC,OAAM,IAAI,MAAM,mBAAmB;AAIrC,SADa,MAAM,uBADC,MAAM,kBAAkB,cAAc,EACH,kBAAkB;UAElE,OAAO;AACd,QAAM,IAAI,MAAM,oCAAoC,EAAE,OAAO,OAAO,CAAC"}
@@ -1,5 +1,4 @@
1
- import { AES_KEY_BIT_LENGTH } from "./constants.mjs";
2
- import { a as importPublicKey, n as exportPublicKey } from "./keys-BfcaiAOv.mjs";
1
+ import { AES_KEY_BYTE_LENGTH } from "./constants.mjs";
3
2
  import { bytesToHex, hexToBytes } from "@noble/hashes/utils.js";
4
3
  import * as bip39 from "@scure/bip39";
5
4
  import { wordlist } from "@scure/bip39/wordlists/english.js";
@@ -67,41 +66,6 @@ function base64ToUint8Array(str) {
67
66
  return new Uint8Array(array.buffer);
68
67
  }
69
68
 
70
- //#endregion
71
- //#region src/utils/keyConverters.ts
72
- /**
73
- * Converts a base64 string into PublicKeys type.
74
- *
75
- * @param base64 - The base64 representation of the public key.
76
- * @returns The resulting PublicKeys.
77
- */
78
- async function base64ToPublicKey(base64) {
79
- try {
80
- return {
81
- eccPublicKey: await importPublicKey(base64ToUint8Array(base64.eccPublicKeyBase64)),
82
- kyberPublicKey: base64ToUint8Array(base64.kyberPublicKeyBase64)
83
- };
84
- } catch (error) {
85
- throw new Error("Failed to convert base64 to PublicKeys", { cause: error });
86
- }
87
- }
88
- /**
89
- * Converts a PublicKeys type into PublicKeysBase64.
90
- *
91
- * @param key - The PublicKeys key.
92
- * @returns The resulting PublicKeysBase64.
93
- */
94
- async function publicKeyToBase64(key) {
95
- try {
96
- return {
97
- eccPublicKeyBase64: uint8ArrayToBase64(await exportPublicKey(key.eccPublicKey)),
98
- kyberPublicKeyBase64: uint8ArrayToBase64(key.kyberPublicKey)
99
- };
100
- } catch (error) {
101
- throw new Error("Failed to convert key of the type PublicKeys to PublicKeysBase64", { cause: error });
102
- }
103
- }
104
-
105
69
  //#endregion
106
70
  //#region src/utils/genMnemonic.ts
107
71
  /**
@@ -110,7 +74,7 @@ async function publicKeyToBase64(key) {
110
74
  * @returns The generated mnemonic.
111
75
  */
112
76
  function genMnemonic() {
113
- return bip39.generateMnemonic(wordlist, AES_KEY_BIT_LENGTH);
77
+ return bip39.generateMnemonic(wordlist, AES_KEY_BYTE_LENGTH * 8);
114
78
  }
115
79
  /**
116
80
  * Converts a mnemonic to Uint8Array
@@ -149,5 +113,5 @@ function bytesToUuid(bytes) {
149
113
  }
150
114
 
151
115
  //#endregion
152
- export { genMnemonic as a, publicKeyToBase64 as c, hexToUint8Array as d, uint8ArrayToBase64 as f, bytesToMnemonic as i, UTF8ToUint8 as l, uint8ToUTF8 as m, generateUuid as n, mnemonicToBytes as o, uint8ArrayToHex as p, uuidToBytes as r, base64ToPublicKey as s, bytesToUuid as t, base64ToUint8Array as u };
153
- //# sourceMappingURL=genID-3Er5IowC.mjs.map
116
+ export { genMnemonic as a, base64ToUint8Array as c, uint8ArrayToHex as d, uint8ToUTF8 as f, bytesToMnemonic as i, hexToUint8Array as l, generateUuid as n, mnemonicToBytes as o, uuidToBytes as r, UTF8ToUint8 as s, bytesToUuid as t, uint8ArrayToBase64 as u };
117
+ //# sourceMappingURL=genID-D08K7JPr.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"genID-D08K7JPr.mjs","names":["uuidv4"],"sources":["../src/utils/converters.ts","../src/utils/genMnemonic.ts","../src/utils/genID.ts"],"sourcesContent":["import { bytesToHex, hexToBytes } from '@noble/hashes/utils.js';\n\n/**\n * Converts a Uint8Array into a hexadecimal string.\n *\n * @param array - The Uint8Array to convert.\n * @returns The hexadecimal string representation of the array.\n */\nexport function uint8ArrayToHex(array: Uint8Array): string {\n return bytesToHex(array);\n}\n\n/**\n * Converts a UTF-8 string into a Uint8Array.\n *\n * @param str - The UTF-8 string to convert.\n * @returns A Uint8Array created from the UTF-8 string.\n */\nexport function UTF8ToUint8(str: string): Uint8Array {\n return new TextEncoder().encode(str);\n}\n\n/**\n * Converts an Uint8Array into a UTF-8 string.\n *\n * @param array - The Uint8Array to convert.\n * @returns The UTF-8 string representation of the array.\n */\nexport function uint8ToUTF8(array: Uint8Array): string {\n return new TextDecoder().decode(array);\n}\n\n/**\n * Converts a hexadecimal string into a Uint8Array.\n *\n * @param hex - The hexadecimal string to convert.\n * @returns A Uint8Array created from the hex string.\n */\nexport function hexToUint8Array(hex: string): Uint8Array {\n return hexToBytes(hex);\n}\n\n/**\n * Converts a Uint8Array into a base64 string.\n *\n * @param array - The Uint8Array to convert.\n * @returns The base64 string representation of the array.\n */\nexport function uint8ArrayToBase64(buffer: Uint8Array): string {\n const array = Uint16Array.from(buffer);\n const binaryString = new TextDecoder('UTF-16').decode(array);\n return btoa(binaryString);\n}\n\n/**\n * Converts a base64 string into a Uint8Array.\n *\n * @param str - The base64 string to convert.\n * @returns A Uint8Array created from the base64 string.\n */\nexport function base64ToUint8Array(str: string): Uint8Array {\n const binaryString = atob(str);\n const len = binaryString.length;\n const array = new Uint8Array(len);\n for (let i = 0; i < len; i++) {\n array[i] = binaryString.codePointAt(i)!;\n }\n return new Uint8Array(array.buffer);\n}\n","import * as bip39 from '@scure/bip39';\nimport { wordlist } from '@scure/bip39/wordlists/english.js';\nimport { AES_KEY_BYTE_LENGTH } from '../constants';\n/**\n * Generates a mnemonic\n *\n * @returns The generated mnemonic.\n */\nexport function genMnemonic(): string {\n return bip39.generateMnemonic(wordlist, AES_KEY_BYTE_LENGTH * 8);\n}\n\n/**\n * Converts a mnemonic to Uint8Array\n *\n * @param mnemonic - The mnemonic to convert\n * @returns The mnemonic as Uint8Array\n */\nexport function mnemonicToBytes(mnemonic: string): Uint8Array {\n return bip39.mnemonicToEntropy(mnemonic, wordlist);\n}\n\n/**\n * Converts a Uint8Array to a mnemonic\n *\n * @param bytes - The bytes to convert\n * @returns The mnemonic string\n */\nexport function bytesToMnemonic(bytes: Uint8Array): string {\n return bip39.entropyToMnemonic(bytes, wordlist);\n}\n","import { v4 as uuidv4, parse, stringify } from 'uuid';\n/**\n * Creates a random identifier.\n *\n * @returns The resulting auxilary string\n */\nexport function generateUuid(): string {\n return uuidv4();\n}\n\nexport function uuidToBytes(uuid: string): Uint8Array {\n return parse(uuid);\n}\n\nexport function bytesToUuid(bytes: Uint8Array): string {\n return stringify(bytes);\n}\n"],"mappings":";;;;;;;;;;;;;AAQA,SAAgB,gBAAgB,OAA2B;AACzD,QAAO,WAAW,MAAM;;;;;;;;AAS1B,SAAgB,YAAY,KAAyB;AACnD,QAAO,IAAI,aAAa,CAAC,OAAO,IAAI;;;;;;;;AAStC,SAAgB,YAAY,OAA2B;AACrD,QAAO,IAAI,aAAa,CAAC,OAAO,MAAM;;;;;;;;AASxC,SAAgB,gBAAgB,KAAyB;AACvD,QAAO,WAAW,IAAI;;;;;;;;AASxB,SAAgB,mBAAmB,QAA4B;CAC7D,MAAM,QAAQ,YAAY,KAAK,OAAO;CACtC,MAAM,eAAe,IAAI,YAAY,SAAS,CAAC,OAAO,MAAM;AAC5D,QAAO,KAAK,aAAa;;;;;;;;AAS3B,SAAgB,mBAAmB,KAAyB;CAC1D,MAAM,eAAe,KAAK,IAAI;CAC9B,MAAM,MAAM,aAAa;CACzB,MAAM,QAAQ,IAAI,WAAW,IAAI;AACjC,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,IACvB,OAAM,KAAK,aAAa,YAAY,EAAE;AAExC,QAAO,IAAI,WAAW,MAAM,OAAO;;;;;;;;;;AC3DrC,SAAgB,cAAsB;AACpC,QAAO,MAAM,iBAAiB,UAAU,sBAAsB,EAAE;;;;;;;;AASlE,SAAgB,gBAAgB,UAA8B;AAC5D,QAAO,MAAM,kBAAkB,UAAU,SAAS;;;;;;;;AASpD,SAAgB,gBAAgB,OAA2B;AACzD,QAAO,MAAM,kBAAkB,OAAO,SAAS;;;;;;;;;;ACvBjD,SAAgB,eAAuB;AACrC,QAAOA,IAAQ;;AAGjB,SAAgB,YAAY,MAA0B;AACpD,QAAO,MAAM,KAAK;;AAGpB,SAAgB,YAAY,OAA2B;AACrD,QAAO,UAAU,MAAM"}
@@ -1,6 +1,5 @@
1
1
  const require_chunk = require('./chunk-EbLFQX5m.js');
2
2
  const require_constants = require('./constants.js');
3
- const require_keys = require('./keys-CinT7kEY.js');
4
3
  let _noble_hashes_utils_js = require("@noble/hashes/utils.js");
5
4
  let _scure_bip39 = require("@scure/bip39");
6
5
  _scure_bip39 = require_chunk.__toESM(_scure_bip39);
@@ -69,41 +68,6 @@ function base64ToUint8Array(str) {
69
68
  return new Uint8Array(array.buffer);
70
69
  }
71
70
 
72
- //#endregion
73
- //#region src/utils/keyConverters.ts
74
- /**
75
- * Converts a base64 string into PublicKeys type.
76
- *
77
- * @param base64 - The base64 representation of the public key.
78
- * @returns The resulting PublicKeys.
79
- */
80
- async function base64ToPublicKey(base64) {
81
- try {
82
- return {
83
- eccPublicKey: await require_keys.importPublicKey(base64ToUint8Array(base64.eccPublicKeyBase64)),
84
- kyberPublicKey: base64ToUint8Array(base64.kyberPublicKeyBase64)
85
- };
86
- } catch (error) {
87
- throw new Error("Failed to convert base64 to PublicKeys", { cause: error });
88
- }
89
- }
90
- /**
91
- * Converts a PublicKeys type into PublicKeysBase64.
92
- *
93
- * @param key - The PublicKeys key.
94
- * @returns The resulting PublicKeysBase64.
95
- */
96
- async function publicKeyToBase64(key) {
97
- try {
98
- return {
99
- eccPublicKeyBase64: uint8ArrayToBase64(await require_keys.exportPublicKey(key.eccPublicKey)),
100
- kyberPublicKeyBase64: uint8ArrayToBase64(key.kyberPublicKey)
101
- };
102
- } catch (error) {
103
- throw new Error("Failed to convert key of the type PublicKeys to PublicKeysBase64", { cause: error });
104
- }
105
- }
106
-
107
71
  //#endregion
108
72
  //#region src/utils/genMnemonic.ts
109
73
  /**
@@ -112,7 +76,7 @@ async function publicKeyToBase64(key) {
112
76
  * @returns The generated mnemonic.
113
77
  */
114
78
  function genMnemonic() {
115
- return _scure_bip39.generateMnemonic(_scure_bip39_wordlists_english_js.wordlist, require_constants.AES_KEY_BIT_LENGTH);
79
+ return _scure_bip39.generateMnemonic(_scure_bip39_wordlists_english_js.wordlist, require_constants.AES_KEY_BYTE_LENGTH * 8);
116
80
  }
117
81
  /**
118
82
  * Converts a mnemonic to Uint8Array
@@ -157,12 +121,6 @@ Object.defineProperty(exports, 'UTF8ToUint8', {
157
121
  return UTF8ToUint8;
158
122
  }
159
123
  });
160
- Object.defineProperty(exports, 'base64ToPublicKey', {
161
- enumerable: true,
162
- get: function () {
163
- return base64ToPublicKey;
164
- }
165
- });
166
124
  Object.defineProperty(exports, 'base64ToUint8Array', {
167
125
  enumerable: true,
168
126
  get: function () {
@@ -205,12 +163,6 @@ Object.defineProperty(exports, 'mnemonicToBytes', {
205
163
  return mnemonicToBytes;
206
164
  }
207
165
  });
208
- Object.defineProperty(exports, 'publicKeyToBase64', {
209
- enumerable: true,
210
- get: function () {
211
- return publicKeyToBase64;
212
- }
213
- });
214
166
  Object.defineProperty(exports, 'uint8ArrayToBase64', {
215
167
  enumerable: true,
216
168
  get: function () {
@@ -235,4 +187,4 @@ Object.defineProperty(exports, 'uuidToBytes', {
235
187
  return uuidToBytes;
236
188
  }
237
189
  });
238
- //# sourceMappingURL=genID-YJSl3YhL.js.map
190
+ //# sourceMappingURL=genID-cWOPmspk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"genID-cWOPmspk.js","names":["bip39","wordlist","AES_KEY_BYTE_LENGTH","uuid"],"sources":["../src/utils/converters.ts","../src/utils/genMnemonic.ts","../src/utils/genID.ts"],"sourcesContent":["import { bytesToHex, hexToBytes } from '@noble/hashes/utils.js';\n\n/**\n * Converts a Uint8Array into a hexadecimal string.\n *\n * @param array - The Uint8Array to convert.\n * @returns The hexadecimal string representation of the array.\n */\nexport function uint8ArrayToHex(array: Uint8Array): string {\n return bytesToHex(array);\n}\n\n/**\n * Converts a UTF-8 string into a Uint8Array.\n *\n * @param str - The UTF-8 string to convert.\n * @returns A Uint8Array created from the UTF-8 string.\n */\nexport function UTF8ToUint8(str: string): Uint8Array {\n return new TextEncoder().encode(str);\n}\n\n/**\n * Converts an Uint8Array into a UTF-8 string.\n *\n * @param array - The Uint8Array to convert.\n * @returns The UTF-8 string representation of the array.\n */\nexport function uint8ToUTF8(array: Uint8Array): string {\n return new TextDecoder().decode(array);\n}\n\n/**\n * Converts a hexadecimal string into a Uint8Array.\n *\n * @param hex - The hexadecimal string to convert.\n * @returns A Uint8Array created from the hex string.\n */\nexport function hexToUint8Array(hex: string): Uint8Array {\n return hexToBytes(hex);\n}\n\n/**\n * Converts a Uint8Array into a base64 string.\n *\n * @param array - The Uint8Array to convert.\n * @returns The base64 string representation of the array.\n */\nexport function uint8ArrayToBase64(buffer: Uint8Array): string {\n const array = Uint16Array.from(buffer);\n const binaryString = new TextDecoder('UTF-16').decode(array);\n return btoa(binaryString);\n}\n\n/**\n * Converts a base64 string into a Uint8Array.\n *\n * @param str - The base64 string to convert.\n * @returns A Uint8Array created from the base64 string.\n */\nexport function base64ToUint8Array(str: string): Uint8Array {\n const binaryString = atob(str);\n const len = binaryString.length;\n const array = new Uint8Array(len);\n for (let i = 0; i < len; i++) {\n array[i] = binaryString.codePointAt(i)!;\n }\n return new Uint8Array(array.buffer);\n}\n","import * as bip39 from '@scure/bip39';\nimport { wordlist } from '@scure/bip39/wordlists/english.js';\nimport { AES_KEY_BYTE_LENGTH } from '../constants';\n/**\n * Generates a mnemonic\n *\n * @returns The generated mnemonic.\n */\nexport function genMnemonic(): string {\n return bip39.generateMnemonic(wordlist, AES_KEY_BYTE_LENGTH * 8);\n}\n\n/**\n * Converts a mnemonic to Uint8Array\n *\n * @param mnemonic - The mnemonic to convert\n * @returns The mnemonic as Uint8Array\n */\nexport function mnemonicToBytes(mnemonic: string): Uint8Array {\n return bip39.mnemonicToEntropy(mnemonic, wordlist);\n}\n\n/**\n * Converts a Uint8Array to a mnemonic\n *\n * @param bytes - The bytes to convert\n * @returns The mnemonic string\n */\nexport function bytesToMnemonic(bytes: Uint8Array): string {\n return bip39.entropyToMnemonic(bytes, wordlist);\n}\n","import { v4 as uuidv4, parse, stringify } from 'uuid';\n/**\n * Creates a random identifier.\n *\n * @returns The resulting auxilary string\n */\nexport function generateUuid(): string {\n return uuidv4();\n}\n\nexport function uuidToBytes(uuid: string): Uint8Array {\n return parse(uuid);\n}\n\nexport function bytesToUuid(bytes: Uint8Array): string {\n return stringify(bytes);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAQA,SAAgB,gBAAgB,OAA2B;AACzD,+CAAkB,MAAM;;;;;;;;AAS1B,SAAgB,YAAY,KAAyB;AACnD,QAAO,IAAI,aAAa,CAAC,OAAO,IAAI;;;;;;;;AAStC,SAAgB,YAAY,OAA2B;AACrD,QAAO,IAAI,aAAa,CAAC,OAAO,MAAM;;;;;;;;AASxC,SAAgB,gBAAgB,KAAyB;AACvD,+CAAkB,IAAI;;;;;;;;AASxB,SAAgB,mBAAmB,QAA4B;CAC7D,MAAM,QAAQ,YAAY,KAAK,OAAO;CACtC,MAAM,eAAe,IAAI,YAAY,SAAS,CAAC,OAAO,MAAM;AAC5D,QAAO,KAAK,aAAa;;;;;;;;AAS3B,SAAgB,mBAAmB,KAAyB;CAC1D,MAAM,eAAe,KAAK,IAAI;CAC9B,MAAM,MAAM,aAAa;CACzB,MAAM,QAAQ,IAAI,WAAW,IAAI;AACjC,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,IACvB,OAAM,KAAK,aAAa,YAAY,EAAE;AAExC,QAAO,IAAI,WAAW,MAAM,OAAO;;;;;;;;;;AC3DrC,SAAgB,cAAsB;AACpC,QAAOA,aAAM,iBAAiBC,4CAAUC,wCAAsB,EAAE;;;;;;;;AASlE,SAAgB,gBAAgB,UAA8B;AAC5D,QAAOF,aAAM,kBAAkB,UAAUC,2CAAS;;;;;;;;AASpD,SAAgB,gBAAgB,OAA2B;AACzD,QAAOD,aAAM,kBAAkB,OAAOC,2CAAS;;;;;;;;;;ACvBjD,SAAgB,eAAuB;AACrC,sBAAe;;AAGjB,SAAgB,YAAY,QAA0B;AACpD,wBAAaE,OAAK;;AAGpB,SAAgB,YAAY,OAA2B;AACrD,4BAAiB,MAAM"}
package/dist/hash.d.mts CHANGED
@@ -2,61 +2,49 @@
2
2
  /**
3
3
  * Hashes the given array of data
4
4
  *
5
- * @param data - The data to hash
6
- * @returns The resulting hash array
5
+ * @param data - The array of data
6
+ * @returns The resulting hash
7
7
  */
8
8
  declare function hashDataArray(data: Uint8Array[]): Uint8Array;
9
9
  /**
10
- * Hashes the given array of data
10
+ * Hashes the given array of data with the given key
11
11
  *
12
- * @param data - The data to hash
13
- * @returns The resulting hash hex string
12
+ * @param hashKey - The key for keyed hashing
13
+ * @param data - The array of data
14
+ * @returns The resulting keyed hash
14
15
  */
15
- declare function hashDataArrayHex(data: Uint8Array[]): string;
16
- declare function hashDataArrayWithKeyHex(hashKey: Uint8Array, data: Uint8Array[]): string;
17
16
  declare function hashDataArrayWithKey(hashKey: Uint8Array, data: Uint8Array[]): Uint8Array;
18
17
  /**
19
- * Hashes the given array of data using blake3 algorithm
18
+ * Hashes the given array of data to the desired byte-length
20
19
  *
20
+ * @param data - The array of data
21
21
  * @param bytes - The desired output byte-length
22
- * @param data - The data to hash
23
- * @returns The resulting hash value
22
+ * @returns The resulting hash of the desired byte-length
24
23
  */
25
- declare function getBytesFromDataArray(bytes: number, data: Uint8Array[]): Uint8Array;
24
+ declare function getBytesFromDataArray(data: Uint8Array[], bytes: number): Uint8Array;
26
25
  /**
27
- * Hashes the given array of data using blake3 algorithm
26
+ * Hashes the given data
28
27
  *
29
- * @param bytes - The desired output byte-length
30
- * @param data - The data to hash
31
- * @returns The resulting hash value
28
+ * @param data - The data
29
+ * @returns The resulting hash
32
30
  */
33
- declare function getBytesFromDataArrayHex(bytes: number, data: Uint8Array[]): string;
31
+ declare function hashData(data: Uint8Array): Uint8Array;
34
32
  /**
35
- * Hashes the given string using blake3 algorithm
33
+ * Hashes the given data with the given key
36
34
  *
37
- * @param bytes - The desired output byte-length
38
- * @param data - The data to hash
39
- * @returns The resulting hash value
35
+ * @param hashKey - The key for keyed hashing
36
+ * @param data - The data
37
+ * @returns The resulting keyed hash
40
38
  */
41
- declare function getBytesFromData(bytes: number, data: Uint8Array): Uint8Array;
39
+ declare function hashDataWithKey(hashKey: Uint8Array, data: Uint8Array): Uint8Array;
42
40
  /**
43
- * Hashes the given data using blake3 algorithm
41
+ * Hashes the given data to the desired byte-length
44
42
  *
43
+ * @param data - The data
45
44
  * @param bytes - The desired output byte-length
46
- * @param data - The data to hash
47
- * @returns The resulting hash value
48
- */
49
- declare function getBytesFromDataHex(bytes: number, data: Uint8Array): string;
50
- //#endregion
51
- //#region src/hash/mac.d.ts
52
- /**
53
- * Computes mac for the given key material and data
54
- *
55
- * @param keyMaterial - The key material
56
- * @param data - The data to hash
57
- * @returns The resulting hash hex string
45
+ * @returns The resulting hash of the desired byte-length
58
46
  */
59
- declare function computeMac(keyMaterial: Uint8Array, data: Uint8Array[]): string;
47
+ declare function getBytesFromData(data: Uint8Array, bytes: number): Uint8Array;
60
48
  //#endregion
61
- export { computeMac, getBytesFromData, getBytesFromDataArray, getBytesFromDataArrayHex, getBytesFromDataHex, hashDataArray, hashDataArrayHex, hashDataArrayWithKey, hashDataArrayWithKeyHex };
49
+ export { getBytesFromData, getBytesFromDataArray, hashData, hashDataArray, hashDataArrayWithKey, hashDataWithKey };
62
50
  //# sourceMappingURL=hash.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hash.d.mts","names":[],"sources":["../src/hash/blake3.ts","../src/hash/mac.ts"],"mappings":";;AASA;;;;;iBAAgB,aAAA,CAAc,IAAA,EAAM,UAAA,KAAe,UAAA;;;;AAkBnD;;;iBAAgB,gBAAA,CAAiB,IAAA,EAAM,UAAA;AAAA,iBAIvB,uBAAA,CAAwB,OAAA,EAAS,UAAA,EAAY,IAAA,EAAM,UAAA;AAAA,iBASnD,oBAAA,CAAqB,OAAA,EAAS,UAAA,EAAY,IAAA,EAAM,UAAA,KAAe,UAAA;;;;;;;;iBAmB/D,qBAAA,CAAsB,KAAA,UAAe,IAAA,EAAM,UAAA,KAAe,UAAA;;AAnB1E;;;;;;iBAsCgB,wBAAA,CAAyB,KAAA,UAAe,IAAA,EAAM,UAAA;;;;;;;;iBAgB9C,gBAAA,CAAiB,KAAA,UAAe,IAAA,EAAM,UAAA,GAAa,UAAA;AAnCnE;;;;;;;AAAA,iBA8CgB,mBAAA,CAAoB,KAAA,UAAe,IAAA,EAAM,UAAA;;;;AAhGzD;;;;;;iBCEgB,UAAA,CAAW,WAAA,EAAa,UAAA,EAAY,IAAA,EAAM,UAAA"}
1
+ {"version":3,"file":"hash.d.mts","names":[],"sources":["../src/hash/blake3.ts"],"mappings":";;AAQA;;;;;iBAAgB,aAAA,CAAc,IAAA,EAAM,UAAA,KAAe,UAAA;;;;AAmBnD;;;;iBAAgB,oBAAA,CAAqB,OAAA,EAAS,UAAA,EAAY,IAAA,EAAM,UAAA,KAAe,UAAA;;;;;;;;iBAmB/D,qBAAA,CAAsB,IAAA,EAAM,UAAA,IAAc,KAAA,WAAgB,UAAA;;;AAA1E;;;;iBAkBgB,QAAA,CAAS,IAAA,EAAM,UAAA,GAAa,UAAA;;;;;;AAA5C;;iBAWgB,eAAA,CAAgB,OAAA,EAAS,UAAA,EAAY,IAAA,EAAM,UAAA,GAAa,UAAA;;;;;;;AAAxE;iBAWgB,gBAAA,CAAiB,IAAA,EAAM,UAAA,EAAY,KAAA,WAAgB,UAAA"}
package/dist/hash.d.ts CHANGED
@@ -2,61 +2,49 @@
2
2
  /**
3
3
  * Hashes the given array of data
4
4
  *
5
- * @param data - The data to hash
6
- * @returns The resulting hash array
5
+ * @param data - The array of data
6
+ * @returns The resulting hash
7
7
  */
8
8
  declare function hashDataArray(data: Uint8Array[]): Uint8Array;
9
9
  /**
10
- * Hashes the given array of data
10
+ * Hashes the given array of data with the given key
11
11
  *
12
- * @param data - The data to hash
13
- * @returns The resulting hash hex string
12
+ * @param hashKey - The key for keyed hashing
13
+ * @param data - The array of data
14
+ * @returns The resulting keyed hash
14
15
  */
15
- declare function hashDataArrayHex(data: Uint8Array[]): string;
16
- declare function hashDataArrayWithKeyHex(hashKey: Uint8Array, data: Uint8Array[]): string;
17
16
  declare function hashDataArrayWithKey(hashKey: Uint8Array, data: Uint8Array[]): Uint8Array;
18
17
  /**
19
- * Hashes the given array of data using blake3 algorithm
18
+ * Hashes the given array of data to the desired byte-length
20
19
  *
20
+ * @param data - The array of data
21
21
  * @param bytes - The desired output byte-length
22
- * @param data - The data to hash
23
- * @returns The resulting hash value
22
+ * @returns The resulting hash of the desired byte-length
24
23
  */
25
- declare function getBytesFromDataArray(bytes: number, data: Uint8Array[]): Uint8Array;
24
+ declare function getBytesFromDataArray(data: Uint8Array[], bytes: number): Uint8Array;
26
25
  /**
27
- * Hashes the given array of data using blake3 algorithm
26
+ * Hashes the given data
28
27
  *
29
- * @param bytes - The desired output byte-length
30
- * @param data - The data to hash
31
- * @returns The resulting hash value
28
+ * @param data - The data
29
+ * @returns The resulting hash
32
30
  */
33
- declare function getBytesFromDataArrayHex(bytes: number, data: Uint8Array[]): string;
31
+ declare function hashData(data: Uint8Array): Uint8Array;
34
32
  /**
35
- * Hashes the given string using blake3 algorithm
33
+ * Hashes the given data with the given key
36
34
  *
37
- * @param bytes - The desired output byte-length
38
- * @param data - The data to hash
39
- * @returns The resulting hash value
35
+ * @param hashKey - The key for keyed hashing
36
+ * @param data - The data
37
+ * @returns The resulting keyed hash
40
38
  */
41
- declare function getBytesFromData(bytes: number, data: Uint8Array): Uint8Array;
39
+ declare function hashDataWithKey(hashKey: Uint8Array, data: Uint8Array): Uint8Array;
42
40
  /**
43
- * Hashes the given data using blake3 algorithm
41
+ * Hashes the given data to the desired byte-length
44
42
  *
43
+ * @param data - The data
45
44
  * @param bytes - The desired output byte-length
46
- * @param data - The data to hash
47
- * @returns The resulting hash value
48
- */
49
- declare function getBytesFromDataHex(bytes: number, data: Uint8Array): string;
50
- //#endregion
51
- //#region src/hash/mac.d.ts
52
- /**
53
- * Computes mac for the given key material and data
54
- *
55
- * @param keyMaterial - The key material
56
- * @param data - The data to hash
57
- * @returns The resulting hash hex string
45
+ * @returns The resulting hash of the desired byte-length
58
46
  */
59
- declare function computeMac(keyMaterial: Uint8Array, data: Uint8Array[]): string;
47
+ declare function getBytesFromData(data: Uint8Array, bytes: number): Uint8Array;
60
48
  //#endregion
61
- export { computeMac, getBytesFromData, getBytesFromDataArray, getBytesFromDataArrayHex, getBytesFromDataHex, hashDataArray, hashDataArrayHex, hashDataArrayWithKey, hashDataArrayWithKeyHex };
49
+ export { getBytesFromData, getBytesFromDataArray, hashData, hashDataArray, hashDataArrayWithKey, hashDataWithKey };
62
50
  //# sourceMappingURL=hash.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hash.d.ts","names":[],"sources":["../src/hash/blake3.ts","../src/hash/mac.ts"],"mappings":";;AASA;;;;;iBAAgB,aAAA,CAAc,IAAA,EAAM,UAAA,KAAe,UAAA;;;;AAkBnD;;;iBAAgB,gBAAA,CAAiB,IAAA,EAAM,UAAA;AAAA,iBAIvB,uBAAA,CAAwB,OAAA,EAAS,UAAA,EAAY,IAAA,EAAM,UAAA;AAAA,iBASnD,oBAAA,CAAqB,OAAA,EAAS,UAAA,EAAY,IAAA,EAAM,UAAA,KAAe,UAAA;;;;;;;;iBAmB/D,qBAAA,CAAsB,KAAA,UAAe,IAAA,EAAM,UAAA,KAAe,UAAA;;AAnB1E;;;;;;iBAsCgB,wBAAA,CAAyB,KAAA,UAAe,IAAA,EAAM,UAAA;;;;;;;;iBAgB9C,gBAAA,CAAiB,KAAA,UAAe,IAAA,EAAM,UAAA,GAAa,UAAA;AAnCnE;;;;;;;AAAA,iBA8CgB,mBAAA,CAAoB,KAAA,UAAe,IAAA,EAAM,UAAA;;;;AAhGzD;;;;;;iBCEgB,UAAA,CAAW,WAAA,EAAa,UAAA,EAAY,IAAA,EAAM,UAAA"}
1
+ {"version":3,"file":"hash.d.ts","names":[],"sources":["../src/hash/blake3.ts"],"mappings":";;AAQA;;;;;iBAAgB,aAAA,CAAc,IAAA,EAAM,UAAA,KAAe,UAAA;;;;AAmBnD;;;;iBAAgB,oBAAA,CAAqB,OAAA,EAAS,UAAA,EAAY,IAAA,EAAM,UAAA,KAAe,UAAA;;;;;;;;iBAmB/D,qBAAA,CAAsB,IAAA,EAAM,UAAA,IAAc,KAAA,WAAgB,UAAA;;;AAA1E;;;;iBAkBgB,QAAA,CAAS,IAAA,EAAM,UAAA,GAAa,UAAA;;;;;;AAA5C;;iBAWgB,eAAA,CAAgB,OAAA,EAAS,UAAA,EAAY,IAAA,EAAM,UAAA,GAAa,UAAA;;;;;;;AAAxE;iBAWgB,gBAAA,CAAiB,IAAA,EAAM,UAAA,EAAY,KAAA,WAAgB,UAAA"}
package/dist/hash.js CHANGED
@@ -1,12 +1,90 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_mac = require('./mac-BMb1F0dN.js');
2
+ const require_chunk = require('./chunk-EbLFQX5m.js');
3
+ let _noble_hashes_blake3_js = require("@noble/hashes/blake3.js");
3
4
 
4
- exports.computeMac = require_mac.computeMac;
5
- exports.getBytesFromData = require_mac.getBytesFromData;
6
- exports.getBytesFromDataArray = require_mac.getBytesFromDataArray;
7
- exports.getBytesFromDataArrayHex = require_mac.getBytesFromDataArrayHex;
8
- exports.getBytesFromDataHex = require_mac.getBytesFromDataHex;
9
- exports.hashDataArray = require_mac.hashDataArray;
10
- exports.hashDataArrayHex = require_mac.hashDataArrayHex;
11
- exports.hashDataArrayWithKey = require_mac.hashDataArrayWithKey;
12
- exports.hashDataArrayWithKeyHex = require_mac.hashDataArrayWithKeyHex;
5
+ //#region src/hash/blake3.ts
6
+ /**
7
+ * Hashes the given array of data
8
+ *
9
+ * @param data - The array of data
10
+ * @returns The resulting hash
11
+ */
12
+ function hashDataArray(data) {
13
+ try {
14
+ const hasher = _noble_hashes_blake3_js.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 with the given key
23
+ *
24
+ * @param hashKey - The key for keyed hashing
25
+ * @param data - The array of data
26
+ * @returns The resulting keyed hash
27
+ */
28
+ function hashDataArrayWithKey(hashKey, data) {
29
+ try {
30
+ const hasher = _noble_hashes_blake3_js.blake3.create({ key: hashKey });
31
+ for (const d of data) hasher.update(d);
32
+ return hasher.digest();
33
+ } catch (error) {
34
+ throw new Error("Failed to compute hash", { cause: error });
35
+ }
36
+ }
37
+ /**
38
+ * Hashes the given array of data to the desired byte-length
39
+ *
40
+ * @param data - The array of data
41
+ * @param bytes - The desired output byte-length
42
+ * @returns The resulting hash of the desired byte-length
43
+ */
44
+ function getBytesFromDataArray(data, bytes) {
45
+ try {
46
+ const hasher = _noble_hashes_blake3_js.blake3.create({ dkLen: bytes });
47
+ for (const chunk of data) hasher.update(chunk);
48
+ return hasher.digest();
49
+ } catch (error) {
50
+ throw new Error("Failed to get bytes from data", { cause: error });
51
+ }
52
+ }
53
+ /**
54
+ * Hashes the given data
55
+ *
56
+ * @param data - The data
57
+ * @returns The resulting hash
58
+ */
59
+ function hashData(data) {
60
+ return (0, _noble_hashes_blake3_js.blake3)(data);
61
+ }
62
+ /**
63
+ * Hashes the given data with the given key
64
+ *
65
+ * @param hashKey - The key for keyed hashing
66
+ * @param data - The data
67
+ * @returns The resulting keyed hash
68
+ */
69
+ function hashDataWithKey(hashKey, data) {
70
+ return (0, _noble_hashes_blake3_js.blake3)(data, { key: hashKey });
71
+ }
72
+ /**
73
+ * Hashes the given data to the desired byte-length
74
+ *
75
+ * @param data - The data
76
+ * @param bytes - The desired output byte-length
77
+ * @returns The resulting hash of the desired byte-length
78
+ */
79
+ function getBytesFromData(data, bytes) {
80
+ return (0, _noble_hashes_blake3_js.blake3)(data, { dkLen: bytes });
81
+ }
82
+
83
+ //#endregion
84
+ exports.getBytesFromData = getBytesFromData;
85
+ exports.getBytesFromDataArray = getBytesFromDataArray;
86
+ exports.hashData = hashData;
87
+ exports.hashDataArray = hashDataArray;
88
+ exports.hashDataArrayWithKey = hashDataArrayWithKey;
89
+ exports.hashDataWithKey = hashDataWithKey;
90
+ //# sourceMappingURL=hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.js","names":["blake3"],"sources":["../src/hash/blake3.ts"],"sourcesContent":["import { blake3 } from '@noble/hashes/blake3.js';\n\n/**\n * Hashes the given array of data\n *\n * @param data - The array of data\n * @returns The resulting hash\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 with the given key\n *\n * @param hashKey - The key for keyed hashing\n * @param data - The array of data\n * @returns The resulting keyed hash\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 to the desired byte-length\n *\n * @param data - The array of data\n * @param bytes - The desired output byte-length\n * @returns The resulting hash of the desired byte-length\n */\nexport function getBytesFromDataArray(data: Uint8Array[], bytes: number): 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 data\n *\n * @param data - The data\n * @returns The resulting hash\n */\nexport function hashData(data: Uint8Array): Uint8Array {\n return blake3(data);\n}\n\n/**\n * Hashes the given data with the given key\n *\n * @param hashKey - The key for keyed hashing\n * @param data - The data\n * @returns The resulting keyed hash\n */\nexport function hashDataWithKey(hashKey: Uint8Array, data: Uint8Array): Uint8Array {\n return blake3(data, { key: hashKey });\n}\n\n/**\n * Hashes the given data to the desired byte-length\n *\n * @param data - The data\n * @param bytes - The desired output byte-length\n * @returns The resulting hash of the desired byte-length\n */\nexport function getBytesFromData(data: Uint8Array, bytes: number): Uint8Array {\n return blake3(data, { dkLen: bytes });\n}\n"],"mappings":";;;;;;;;;;;AAQA,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;;;;;;;;;;AAW/D,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,MAAoB,OAA2B;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;;;;;;;;;AAUtE,SAAgB,SAAS,MAA8B;AACrD,4CAAc,KAAK;;;;;;;;;AAUrB,SAAgB,gBAAgB,SAAqB,MAA8B;AACjF,4CAAc,MAAM,EAAE,KAAK,SAAS,CAAC;;;;;;;;;AAUvC,SAAgB,iBAAiB,MAAkB,OAA2B;AAC5E,4CAAc,MAAM,EAAE,OAAO,OAAO,CAAC"}