@enbox/crypto 0.0.2 → 0.0.3

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 (182) hide show
  1. package/README.md +34 -102
  2. package/dist/browser.js +6 -10
  3. package/dist/browser.js.map +4 -4
  4. package/dist/browser.mjs +6 -10
  5. package/dist/browser.mjs.map +4 -4
  6. package/dist/esm/algorithms/aes-gcm.js +1 -1
  7. package/dist/esm/algorithms/aes-gcm.js.map +1 -1
  8. package/dist/esm/algorithms/ecdsa.js +9 -5
  9. package/dist/esm/algorithms/ecdsa.js.map +1 -1
  10. package/dist/esm/algorithms/eddsa.js +9 -5
  11. package/dist/esm/algorithms/eddsa.js.map +1 -1
  12. package/dist/esm/algorithms/sha-2.js +1 -1
  13. package/dist/esm/algorithms/sha-2.js.map +1 -1
  14. package/dist/esm/crypto-error.js +41 -0
  15. package/dist/esm/crypto-error.js.map +1 -0
  16. package/dist/esm/index.js +3 -0
  17. package/dist/esm/index.js.map +1 -1
  18. package/dist/esm/jose/jwk.js +52 -26
  19. package/dist/esm/jose/jwk.js.map +1 -1
  20. package/dist/esm/local-key-manager.js +3 -2
  21. package/dist/esm/local-key-manager.js.map +1 -1
  22. package/dist/esm/primitives/aes-ctr.js.map +1 -1
  23. package/dist/esm/primitives/aes-gcm.js.map +1 -1
  24. package/dist/esm/primitives/aes-kw.js +246 -0
  25. package/dist/esm/primitives/aes-kw.js.map +1 -0
  26. package/dist/esm/primitives/concat-kdf.js +1 -1
  27. package/dist/esm/primitives/concat-kdf.js.map +1 -1
  28. package/dist/esm/primitives/ed25519.js +3 -3
  29. package/dist/esm/primitives/ed25519.js.map +1 -1
  30. package/dist/esm/primitives/hkdf.js +79 -0
  31. package/dist/esm/primitives/hkdf.js.map +1 -0
  32. package/dist/esm/primitives/pbkdf2.js +49 -0
  33. package/dist/esm/primitives/pbkdf2.js.map +1 -1
  34. package/dist/esm/primitives/secp256k1.js +4 -4
  35. package/dist/esm/primitives/secp256k1.js.map +1 -1
  36. package/dist/esm/primitives/secp256r1.js +4 -4
  37. package/dist/esm/primitives/secp256r1.js.map +1 -1
  38. package/dist/esm/primitives/x25519.js +1 -1
  39. package/dist/esm/primitives/x25519.js.map +1 -1
  40. package/dist/esm/primitives/xchacha20-poly1305.js +48 -3
  41. package/dist/esm/primitives/xchacha20-poly1305.js.map +1 -1
  42. package/dist/esm/primitives/xchacha20.js +1 -1
  43. package/dist/esm/primitives/xchacha20.js.map +1 -1
  44. package/dist/esm/utils.js.map +1 -1
  45. package/dist/types/algorithms/aes-ctr.d.ts +1 -1
  46. package/dist/types/algorithms/aes-ctr.d.ts.map +1 -1
  47. package/dist/types/algorithms/aes-gcm.d.ts +2 -2
  48. package/dist/types/algorithms/aes-gcm.d.ts.map +1 -1
  49. package/dist/types/algorithms/ecdsa.d.ts +1 -1
  50. package/dist/types/algorithms/ecdsa.d.ts.map +1 -1
  51. package/dist/types/algorithms/eddsa.d.ts +2 -2
  52. package/dist/types/algorithms/eddsa.d.ts.map +1 -1
  53. package/dist/types/algorithms/sha-2.d.ts +1 -1
  54. package/dist/types/algorithms/sha-2.d.ts.map +1 -1
  55. package/dist/types/crypto-error.d.ts +29 -0
  56. package/dist/types/crypto-error.d.ts.map +1 -0
  57. package/dist/types/index.d.ts +3 -0
  58. package/dist/types/index.d.ts.map +1 -1
  59. package/dist/types/jose/jwk.d.ts.map +1 -1
  60. package/dist/types/local-key-manager.d.ts +3 -3
  61. package/dist/types/local-key-manager.d.ts.map +1 -1
  62. package/dist/types/primitives/aes-kw.d.ts +103 -0
  63. package/dist/types/primitives/aes-kw.d.ts.map +1 -0
  64. package/dist/types/primitives/concat-kdf.d.ts +1 -1
  65. package/dist/types/primitives/concat-kdf.d.ts.map +1 -1
  66. package/dist/types/primitives/hkdf.d.ts +90 -0
  67. package/dist/types/primitives/hkdf.d.ts.map +1 -0
  68. package/dist/types/primitives/pbkdf2.d.ts +58 -0
  69. package/dist/types/primitives/pbkdf2.d.ts.map +1 -1
  70. package/dist/types/primitives/xchacha20-poly1305.d.ts +47 -0
  71. package/dist/types/primitives/xchacha20-poly1305.d.ts.map +1 -1
  72. package/dist/types/types/cipher.d.ts +1 -1
  73. package/dist/types/types/crypto-api.d.ts +3 -3
  74. package/dist/types/types/crypto-api.d.ts.map +1 -1
  75. package/dist/types/types/params-direct.d.ts +79 -1
  76. package/dist/types/types/params-direct.d.ts.map +1 -1
  77. package/dist/utils.js.map +2 -2
  78. package/package.json +26 -39
  79. package/src/algorithms/aes-ctr.ts +1 -1
  80. package/src/algorithms/aes-gcm.ts +3 -2
  81. package/src/algorithms/ecdsa.ts +13 -7
  82. package/src/algorithms/eddsa.ts +9 -9
  83. package/src/algorithms/sha-2.ts +2 -2
  84. package/src/crypto-error.ts +45 -0
  85. package/src/index.ts +3 -0
  86. package/src/jose/jwk.ts +32 -32
  87. package/src/local-key-manager.ts +14 -13
  88. package/src/primitives/aes-ctr.ts +1 -1
  89. package/src/primitives/aes-gcm.ts +5 -5
  90. package/src/primitives/aes-kw.ts +269 -0
  91. package/src/primitives/concat-kdf.ts +4 -2
  92. package/src/primitives/ed25519.ts +6 -6
  93. package/src/primitives/hkdf.ts +121 -0
  94. package/src/primitives/pbkdf2.ts +91 -0
  95. package/src/primitives/secp256k1.ts +6 -6
  96. package/src/primitives/secp256r1.ts +6 -6
  97. package/src/primitives/x25519.ts +3 -3
  98. package/src/primitives/xchacha20-poly1305.ts +57 -4
  99. package/src/primitives/xchacha20.ts +1 -1
  100. package/src/types/cipher.ts +1 -1
  101. package/src/types/crypto-api.ts +5 -5
  102. package/src/types/params-direct.ts +97 -1
  103. package/src/utils.ts +2 -2
  104. package/dist/cjs/algorithms/aes-ctr.js +0 -188
  105. package/dist/cjs/algorithms/aes-ctr.js.map +0 -1
  106. package/dist/cjs/algorithms/aes-gcm.js +0 -196
  107. package/dist/cjs/algorithms/aes-gcm.js.map +0 -1
  108. package/dist/cjs/algorithms/crypto-algorithm.js +0 -13
  109. package/dist/cjs/algorithms/crypto-algorithm.js.map +0 -1
  110. package/dist/cjs/algorithms/ecdsa.js +0 -352
  111. package/dist/cjs/algorithms/ecdsa.js.map +0 -1
  112. package/dist/cjs/algorithms/eddsa.js +0 -325
  113. package/dist/cjs/algorithms/eddsa.js.map +0 -1
  114. package/dist/cjs/algorithms/sha-2.js +0 -119
  115. package/dist/cjs/algorithms/sha-2.js.map +0 -1
  116. package/dist/cjs/index.js +0 -41
  117. package/dist/cjs/index.js.map +0 -1
  118. package/dist/cjs/jose/jwe.js +0 -3
  119. package/dist/cjs/jose/jwe.js.map +0 -1
  120. package/dist/cjs/jose/jwk.js +0 -278
  121. package/dist/cjs/jose/jwk.js.map +0 -1
  122. package/dist/cjs/jose/jws.js +0 -3
  123. package/dist/cjs/jose/jws.js.map +0 -1
  124. package/dist/cjs/jose/jwt.js +0 -3
  125. package/dist/cjs/jose/jwt.js.map +0 -1
  126. package/dist/cjs/jose/utils.js +0 -60
  127. package/dist/cjs/jose/utils.js.map +0 -1
  128. package/dist/cjs/local-key-manager.js +0 -521
  129. package/dist/cjs/local-key-manager.js.map +0 -1
  130. package/dist/cjs/package.json +0 -1
  131. package/dist/cjs/primitives/aes-ctr.js +0 -398
  132. package/dist/cjs/primitives/aes-ctr.js.map +0 -1
  133. package/dist/cjs/primitives/aes-gcm.js +0 -425
  134. package/dist/cjs/primitives/aes-gcm.js.map +0 -1
  135. package/dist/cjs/primitives/concat-kdf.js +0 -215
  136. package/dist/cjs/primitives/concat-kdf.js.map +0 -1
  137. package/dist/cjs/primitives/ed25519.js +0 -651
  138. package/dist/cjs/primitives/ed25519.js.map +0 -1
  139. package/dist/cjs/primitives/pbkdf2.js +0 -120
  140. package/dist/cjs/primitives/pbkdf2.js.map +0 -1
  141. package/dist/cjs/primitives/secp256k1.js +0 -958
  142. package/dist/cjs/primitives/secp256k1.js.map +0 -1
  143. package/dist/cjs/primitives/secp256r1.js +0 -959
  144. package/dist/cjs/primitives/secp256r1.js.map +0 -1
  145. package/dist/cjs/primitives/sha256.js +0 -93
  146. package/dist/cjs/primitives/sha256.js.map +0 -1
  147. package/dist/cjs/primitives/x25519.js +0 -498
  148. package/dist/cjs/primitives/x25519.js.map +0 -1
  149. package/dist/cjs/primitives/xchacha20-poly1305.js +0 -340
  150. package/dist/cjs/primitives/xchacha20-poly1305.js.map +0 -1
  151. package/dist/cjs/primitives/xchacha20.js +0 -316
  152. package/dist/cjs/primitives/xchacha20.js.map +0 -1
  153. package/dist/cjs/types/cipher.js +0 -3
  154. package/dist/cjs/types/cipher.js.map +0 -1
  155. package/dist/cjs/types/crypto-api.js +0 -3
  156. package/dist/cjs/types/crypto-api.js.map +0 -1
  157. package/dist/cjs/types/hasher.js +0 -3
  158. package/dist/cjs/types/hasher.js.map +0 -1
  159. package/dist/cjs/types/identifier.js +0 -3
  160. package/dist/cjs/types/identifier.js.map +0 -1
  161. package/dist/cjs/types/key-compressor.js +0 -3
  162. package/dist/cjs/types/key-compressor.js.map +0 -1
  163. package/dist/cjs/types/key-converter.js +0 -3
  164. package/dist/cjs/types/key-converter.js.map +0 -1
  165. package/dist/cjs/types/key-deriver.js +0 -3
  166. package/dist/cjs/types/key-deriver.js.map +0 -1
  167. package/dist/cjs/types/key-generator.js +0 -3
  168. package/dist/cjs/types/key-generator.js.map +0 -1
  169. package/dist/cjs/types/key-io.js +0 -3
  170. package/dist/cjs/types/key-io.js.map +0 -1
  171. package/dist/cjs/types/key-wrapper.js +0 -3
  172. package/dist/cjs/types/key-wrapper.js.map +0 -1
  173. package/dist/cjs/types/params-direct.js +0 -3
  174. package/dist/cjs/types/params-direct.js.map +0 -1
  175. package/dist/cjs/types/params-enclosed.js +0 -3
  176. package/dist/cjs/types/params-enclosed.js.map +0 -1
  177. package/dist/cjs/types/params-kms.js +0 -3
  178. package/dist/cjs/types/params-kms.js.map +0 -1
  179. package/dist/cjs/types/signer.js +0 -3
  180. package/dist/cjs/types/signer.js.map +0 -1
  181. package/dist/cjs/utils.js +0 -173
  182. package/dist/cjs/utils.js.map +0 -1
@@ -0,0 +1,90 @@
1
+ import type { DeriveKeyBytesParams } from '../types/params-direct.js';
2
+ /**
3
+ * The object that should be passed into `Hkdf.deriveKeyBytes()`, when using the HKDF algorithm.
4
+ */
5
+ export type HkdfParams = {
6
+ /**
7
+ * A string representing the digest algorithm to use. This may be one of:
8
+ * - 'SHA-256'
9
+ * - 'SHA-384'
10
+ * - 'SHA-512'
11
+ */
12
+ hash: 'SHA-256' | 'SHA-384' | 'SHA-512';
13
+ /**
14
+ * The salt value to use in the derivation process.
15
+ *
16
+ * Ideally, the salt is a random or pseudo-random value with the same length as the output of the
17
+ * digest function. Unlike the input key material passed into deriveKey(), salt does not need to
18
+ * be kept secret.
19
+ *
20
+ * Note: The {@link https://datatracker.ietf.org/doc/html/rfc5869 | HKDF specification} states
21
+ * that adding salt "adds significantly to the strength of HKDF".
22
+ */
23
+ salt: string | Uint8Array;
24
+ /**
25
+ * Optional application-specific information to use in the HKDF.
26
+ *
27
+ * If given, this value is used to bind the derived key to application-specific contextual
28
+ * information. This makes it possible to derive different keys for different contexts while using
29
+ * the same input key material.
30
+ *
31
+ * If not provided, the `info` value is set to an empty array.
32
+ *
33
+ * Note: It is important that the `info` value be independent and unrelated to the input key
34
+ * material.
35
+ */
36
+ info?: string | Uint8Array;
37
+ };
38
+ /**
39
+ * The `Hkdf` class provides an interface for HMAC-based Extract-and-Expand Key Derivation Function (HKDF)
40
+ * as defined in RFC 5869.
41
+ *
42
+ * Note: The `baseKeyBytes` that will be the input key material for HKDF should be a high-entropy secret
43
+ * value, such as a cryptographic key. It should be kept confidential and not be derived from a
44
+ * low-entropy value, such as a password.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * const info = new Uint8Array([...]);
49
+ * const derivedKeyBytes = await Hkdf.deriveKeyBytes({
50
+ * baseKeyBytes: new Uint8Array([...]), // Input keying material
51
+ * hash: 'SHA-256', // The hash function to use ('SHA-256', 'SHA-384', 'SHA-512')
52
+ * salt: new Uint8Array([...]), // The salt value
53
+ * info: new Uint8Array([...]), // Optional application-specific information
54
+ * length: 256 // The length of the derived key in bits
55
+ * });
56
+ * ```
57
+ */
58
+ export declare class Hkdf {
59
+ /**
60
+ * Derives a key using the HMAC-based Extract-and-Expand Key Derivation Function (HKDF).
61
+ *
62
+ * This method generates a derived key using a hash function from input keying material given as
63
+ * `baseKeyBytes`. The length of the derived key can be specified. Optionally, it can also use a salt
64
+ * and info for the derivation process.
65
+ *
66
+ * HKDF is useful in various cryptographic applications and protocols, especially when
67
+ * there's a need to derive multiple keys from a single source of key material.
68
+ *
69
+ * Note: The `baseKeyBytes` that will be the input key material for HKDF should be a high-entropy
70
+ * secret value, such as a cryptographic key. It should be kept confidential and not be derived
71
+ * from a low-entropy value, such as a password.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * const info = new Uint8Array([...]);
76
+ * const derivedKeyBytes = await Hkdf.deriveKeyBytes({
77
+ * baseKeyBytes: new Uint8Array([...]), // Input keying material
78
+ * hash: 'SHA-256', // The hash function to use ('SHA-256', 'SHA-384', 'SHA-512')
79
+ * salt: new Uint8Array([...]), // The salt value
80
+ * info: new Uint8Array([...]), // Optional application-specific information
81
+ * length: 256 // The length of the derived key in bits
82
+ * });
83
+ * ```
84
+ *
85
+ * @param params - The parameters for key derivation.
86
+ * @returns A Promise that resolves to the derived key as a byte array.
87
+ */
88
+ static deriveKeyBytes({ baseKeyBytes, length, hash, salt, info }: DeriveKeyBytesParams & HkdfParams): Promise<Uint8Array>;
89
+ }
90
+ //# sourceMappingURL=hkdf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hkdf.d.ts","sourceRoot":"","sources":["../../../src/primitives/hkdf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAMtE;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;;;;OAKG;IACH,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;IAExC;;;;;;;;;OASG;IACH,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC;IAE1B;;;;;;;;;;;OAWG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;CAC5B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,IAAI;IACf;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;WACiB,cAAc,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAuB,EAAE,EAC9F,oBAAoB,GAAG,UAAU,GAChC,OAAO,CAAC,UAAU,CAAC;CAuBvB"}
@@ -1,3 +1,30 @@
1
+ import type { DeriveKeyBytesParams } from '../types/params-direct.js';
2
+ /**
3
+ * The object that should be passed into `Pbkdf2.deriveKeyBytes()`, when using the PBKDF2 algorithm.
4
+ */
5
+ export interface Pbkdf2Params {
6
+ /**
7
+ * A string representing the digest algorithm to use. This may be one of:
8
+ * - 'SHA-256'
9
+ * - 'SHA-384'
10
+ * - 'SHA-512'
11
+ */
12
+ hash: 'SHA-256' | 'SHA-384' | 'SHA-512';
13
+ /**
14
+ * The salt value to use in the derivation process, as a Uint8Array. This should be a random or
15
+ * pseudo-random value of at least 16 bytes. Unlike the `password`, `salt` does not need to be
16
+ * kept secret.
17
+ */
18
+ salt: Uint8Array;
19
+ /**
20
+ * A `Number` representing the number of iterations the hash function will be executed in
21
+ * `deriveKey()`. This impacts the computational cost of the `deriveKey()` operation, making it
22
+ * more resistant to dictionary attacks. The higher the number, the more secure, but also slower,
23
+ * the operation. Choose a value that balances security needs and performance for your
24
+ * application.
25
+ */
26
+ iterations: number;
27
+ }
1
28
  /**
2
29
  * The object that should be passed into `Pbkdf2.deriveKey()`, when using the PBKDF2 algorithm.
3
30
  */
@@ -90,5 +117,36 @@ export declare class Pbkdf2 {
90
117
  * @returns A Promise that resolves to the derived key as a Uint8Array.
91
118
  */
92
119
  static deriveKey({ hash, password, salt, iterations, length }: Pbkdf2DeriveKeyParams): Promise<Uint8Array>;
120
+ /**
121
+ * Derives cryptographic key bytes from base key material using the PBKDF2 algorithm.
122
+ *
123
+ * @remarks
124
+ * This method is similar to {@link Pbkdf2.deriveKey | `deriveKey()`} but accepts
125
+ * raw key bytes (`baseKeyBytes`) instead of a password. It is intended for use cases
126
+ * where the input key material is already available as a byte array.
127
+ *
128
+ * Notes:
129
+ * - The `baseKeyBytes` that will be the input key material for PBKDF2 is expected to be a
130
+ * low-entropy value, such as a password or passphrase. It should be kept confidential.
131
+ * - In 2023,
132
+ * {@link https://web.archive.org/web/20230123232056/https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#pbkdf2
133
+ * | OWASP recommended}
134
+ * a minimum of 600,000 iterations for PBKDF2-HMAC-SHA256 and 210,000 for PBKDF2-HMAC-SHA512.
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * const derivedKeyBytes = await Pbkdf2.deriveKeyBytes({
139
+ * baseKeyBytes: new TextEncoder().encode('password'),
140
+ * hash: 'SHA-256',
141
+ * salt: new Uint8Array([...]),
142
+ * iterations: 600_000,
143
+ * length: 256
144
+ * });
145
+ * ```
146
+ *
147
+ * @param params - The parameters for key derivation.
148
+ * @returns A Promise that resolves to the derived key as a byte array.
149
+ */
150
+ static deriveKeyBytes({ baseKeyBytes, hash, salt, iterations, length }: DeriveKeyBytesParams & Pbkdf2Params): Promise<Uint8Array>;
93
151
  }
94
152
  //# sourceMappingURL=pbkdf2.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pbkdf2.d.ts","sourceRoot":"","sources":["../../../src/primitives/pbkdf2.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;;;OAKG;IACH,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;IAExC;;OAEG;IACH,QAAQ,EAAE,UAAU,CAAC;IAErB;;;;OAIG;IACH,IAAI,EAAE,UAAU,CAAC;I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AU,CAAC;IAsBtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;WACiB,cAAc,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,EACjF,oBAAoB,GAAG,YAAY,GAClC,OAAO,CAAC,UAAU,CAAC;CAyBvB"}
@@ -124,6 +124,28 @@ export declare class XChaCha20Poly1305 {
124
124
  key: Jwk;
125
125
  nonce: Uint8Array;
126
126
  }): Promise<Uint8Array>;
127
+ /**
128
+ * Decrypts data using XChaCha20-Poly1305 with a raw byte array key.
129
+ *
130
+ * @remarks
131
+ * This is a lower-level method that accepts the key as a raw `Uint8Array` instead of a JWK.
132
+ * It is useful in scenarios where the key material is already in byte form (e.g., derived
133
+ * from ECDH + HKDF) and constructing a JWK would add unnecessary overhead.
134
+ *
135
+ * @param params - The parameters for the decryption operation.
136
+ * @param params.data - The encrypted data including the authentication tag.
137
+ * @param params.keyBytes - The 256-bit (32-byte) decryption key as a Uint8Array.
138
+ * @param params.nonce - The 24-byte nonce used during encryption.
139
+ * @param params.additionalData - Optional additional authenticated data.
140
+ *
141
+ * @returns A Promise that resolves to the decrypted plaintext as a Uint8Array.
142
+ */
143
+ static decryptRaw({ data, keyBytes, nonce, additionalData }: {
144
+ additionalData?: Uint8Array;
145
+ data: Uint8Array;
146
+ keyBytes: Uint8Array;
147
+ nonce: Uint8Array;
148
+ }): Promise<Uint8Array>;
127
149
  /**
128
150
  * Encrypts the provided data using XChaCha20-Poly1305.
129
151
  *
@@ -163,6 +185,31 @@ export declare class XChaCha20Poly1305 {
163
185
  key: Jwk;
164
186
  nonce: Uint8Array;
165
187
  }): Promise<Uint8Array>;
188
+ /**
189
+ * Encrypts data using XChaCha20-Poly1305 with a raw byte array key.
190
+ *
191
+ * @remarks
192
+ * This is a lower-level method that accepts the key as a raw `Uint8Array` instead of a JWK.
193
+ * It is useful in scenarios where the key material is already in byte form (e.g., derived
194
+ * from ECDH + HKDF) and constructing a JWK would add unnecessary overhead.
195
+ *
196
+ * The returned `Uint8Array` contains the ciphertext followed by the 16-byte Poly1305
197
+ * authentication tag.
198
+ *
199
+ * @param params - The parameters for the encryption operation.
200
+ * @param params.data - The plaintext data to encrypt.
201
+ * @param params.keyBytes - The 256-bit (32-byte) encryption key as a Uint8Array.
202
+ * @param params.nonce - A 24-byte nonce for the encryption process.
203
+ * @param params.additionalData - Optional additional authenticated data.
204
+ *
205
+ * @returns A Promise that resolves to the ciphertext + authentication tag as a Uint8Array.
206
+ */
207
+ static encryptRaw({ data, keyBytes, nonce, additionalData }: {
208
+ additionalData?: Uint8Array;
209
+ data: Uint8Array;
210
+ keyBytes: Uint8Array;
211
+ nonce: Uint8Array;
212
+ }): Promise<Uint8Array>;
166
213
  /**
167
214
  * Generates a symmetric key for XChaCha20-Poly1305 in JSON Web Key (JWK) format.
168
215
  *
@@ -1 +1 @@
1
- {"version":3,"file":"xchacha20-poly1305.d.ts","sourceRoot":"","sources":["../../../src/primitives/xchacha20-poly1305.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAI1C;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,qBAAa,iBAAiB;IAC5B;;;;;;;;;;;;;;;;;;;;;;;OAuBG;WACiB,iBAAiB,CAAC,EAAE,eAAe,EAAE,EAAE;QACzD,eAAe,EAAE,UAAU,CAAC;KAC7B,GAAG,OAAO,CAAC,GAAG,CAAC;IAahB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;WACiB,OAAO,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,cAAc,EAAE,EAAE;QAChE,cAAc,CAAC,EAAE,UAAU,CAAC;QAC5B,IAAI,EAAE,UAAU,CAAC;QACjB,GAAG,EAAE,GAAG,CAAC;QAC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ryptParams } from './params-enclosed.js';
1
+ import type { EnclosedDecryptParams, EnclosedEncryptParams } from './params-enclosed.js';
2
2
  /**
3
3
  * The `Cipher` interface provides methods for encrypting and decrypting data.
4
4
  *
@@ -1,8 +1,8 @@
1
+ import type { AsymmetricKeyGenerator } from './key-generator.js';
1
2
  import type { Hasher } from './hasher.js';
2
- import type { Signer } from './signer.js';
3
3
  import type { KeyIdentifier } from './identifier.js';
4
- import type { AsymmetricKeyGenerator } from './key-generator.js';
5
- import type { KmsSignParams, KmsDigestParams, KmsVerifyParams, KmsGetKeyUriParams, KmsGenerateKeyParams, KmsGetPublicKeyParams } from './params-kms.js';
4
+ import type { Signer } from './signer.js';
5
+ import type { KmsDigestParams, KmsGenerateKeyParams, KmsGetKeyUriParams, KmsGetPublicKeyParams, KmsSignParams, KmsVerifyParams } from './params-kms.js';
6
6
  /**
7
7
  * The `CryptoApi` interface integrates key generation, hashing, and signing functionalities,
8
8
  * designed for use with a Key Management System (KMS). It extends `AsymmetricKeyGenerator` for
@@ -1 +1 @@
1
- {"version":3,"file":"crypto-api.d.ts","sourceRoot":"","sources":["../../../src/types/crypto-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,WAAW,SAAS,CACxB,gBAAgB,GAAG,oBAAoB,EACvC,iBAAiB,GAAG,aAAa,EACjC,iBAAiB,GAAG,qBAAqB,EACzC,WAAW,GAA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../jose/jwk.js';
2
1
  import type { AlgorithmIdentifier } from './identifier.js';
2
+ import type { Jwk } from '../jose/jwk.js';
3
+ /**
4
+ * Parameters for converting raw private key bytes to a JWK.
5
+ */
6
+ export interface BytesToPrivateKeyParams {
7
+ /** The algorithm identifier. */
8
+ algorithm: AlgorithmIdentifier;
9
+ /** The raw private key bytes. */
10
+ privateKeyBytes: Uint8Array;
11
+ }
12
+ /**
13
+ * Parameters for converting raw public key bytes to a JWK.
14
+ */
15
+ export interface BytesToPublicKeyParams {
16
+ /** The algorithm identifier. */
17
+ algorithm: AlgorithmIdentifier;
18
+ /** The raw public key bytes. */
19
+ publicKeyBytes: Uint8Array;
20
+ }
3
21
  /**
4
22
  * Parameters for computing a public key.
5
23
  */
6
24
  export interface ComputePublicKeyParams extends GetPublicKeyParams {
7
25
  }
26
+ /**
27
+ * Parameters for encryption and decryption operations.
28
+ *
29
+ * Intended for use with a Key Management System.
30
+ */
31
+ export interface CipherParams {
32
+ /** A {@link Jwk} containing the key to be used for encryption or decryption. */
33
+ key: Jwk;
34
+ /** Data to be encrypted or decrypted. */
35
+ data: Uint8Array;
36
+ /** Additional algorithm-specific parameters for encryption or decryption. */
37
+ [key: string]: unknown;
38
+ }
8
39
  /**
9
40
  * Parameters for decrypting data.
10
41
  */
@@ -35,6 +66,15 @@ export interface DeriveKeyParams {
35
66
  /** An object defining the algorithm-specific parameters for the derived key. */
36
67
  derivedKeyParams: unknown;
37
68
  }
69
+ /**
70
+ * Parameters for derivation of cryptographic byte arrays.
71
+ */
72
+ export interface DeriveKeyBytesParams {
73
+ /** The base key to be used for derivation as a byte array. */
74
+ baseKeyBytes: Uint8Array;
75
+ /** The desired length of the derived key in bits. */
76
+ length: number;
77
+ }
38
78
  /**
39
79
  * Parameters for computing a hash digest.
40
80
  */
@@ -76,6 +116,33 @@ export interface SignParams {
76
116
  /** Data to be signed. */
77
117
  data: Uint8Array;
78
118
  }
119
+ /**
120
+ * Parameters for converting a private key JWK to raw bytes.
121
+ */
122
+ export interface PrivateKeyToBytesParams {
123
+ /** The private key in JWK format. */
124
+ privateKey: Jwk;
125
+ }
126
+ /**
127
+ * Parameters for converting a public key JWK to raw bytes.
128
+ */
129
+ export interface PublicKeyToBytesParams {
130
+ /** The public key in JWK format. */
131
+ publicKey: Jwk;
132
+ }
133
+ /**
134
+ * Parameters for unwrapping a key.
135
+ */
136
+ export interface UnwrapKeyParams {
137
+ /** A {@link Jwk} containing the key used to decrypt the unwrapped key. */
138
+ decryptionKey: Jwk;
139
+ /** The wrapped private key as a byte array. */
140
+ wrappedKeyBytes: Uint8Array;
141
+ /** The algorithm identifier of the key encrypted in `wrappedKeyBytes`. */
142
+ wrappedKeyAlgorithm: string;
143
+ /** An object defining the algorithm-specific parameters for decrypting the `wrappedKeyBytes`. */
144
+ decryptParams?: unknown;
145
+ }
79
146
  /**
80
147
  * Parameters for verifying a signature.
81
148
  */
@@ -87,4 +154,15 @@ export interface VerifyParams {
87
154
  /** The data associated with the signature. */
88
155
  data: Uint8Array;
89
156
  }
157
+ /**
158
+ * Parameters for wrapping a key.
159
+ */
160
+ export interface WrapKeyParams {
161
+ /** A {@link Jwk} containing the key used to encrypt the unwrapped key. */
162
+ encryptionKey: Jwk;
163
+ /** A {@link Jwk} containing the private key to be wrapped. */
164
+ unwrappedKey: Jwk;
165
+ /** An object defining the algorithm-specific parameters for encrypting the `unwrappedKey`. */
166
+ encryptParams?: unknown;
167
+ }
90
168
  //# sourceMappingURL=params-direct.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"params-direct.d.ts","sourceRoot":"","sources":["../../../src/types/params-direct.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,kBAAkB;CAAI;AAEtE;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,kEAAkE;IAClE,GAAG,EAAE,GAAG,CAAC;IAET,4BAA4B;IAC5B,IAAI,EAAE,UAAU,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,uEAAuE;IACvE,GAAG,EAAE,GAAG,CAAC;IAET;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,uEAAuE;IACvE,GAAG,EAAE,GAAG,CAAC;IAET,gFAAgF;IAChF,gBAAgB,EAAE,OAAO,CAAA;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,gCAAgC;IAChC,SAAS,EAAE,mBAAmB,CAAC;IAE/B,2BAA2B;IAC3B,IAAI,EAAE,UAAU,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,kEAAkE;IAClE,GAAG,EAAE,GAAG,CAAC;IAET,4BAA4B;IAC5B,IAAI,EAAE,UAAU,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,gCAAgC;IAChC,SAAS,EAAE,mBAAmB,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,4EAA4E;IAC5E,GAAG,EAAE,GAAG,CAAC;CACV;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,yDAAyD;IACzD,GAAG,EAAE,GAAG,CAAC;IAET,yBAAyB;IACzB,IAAI,EAAE,UAAU,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,8DAA8D;IAC9D,GAAG,EAAE,GAAG,CAAC;IAET,+BAA+B;IAC/B,SAAS,EAAE,UAAU,CAAC;IAEtB,8CAA8C;IAC9C,IAAI,EAAE,UAAU,CAAC;CAClB"}
1
+ {"version":3,"file":"params-direct.d.ts","sourceRoot":"","sources":["../../../src/types/params-direct.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAA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AC,EAAE,OAAO,CAAC;CACzB"}
package/dist/utils.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/src/crypto.ts", "../../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/src/utils.ts", "../src/utils.ts"],
4
- "sourcesContent": ["// We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.\n// See utils.ts for details.\ndeclare const globalThis: Record<string, any> | undefined;\nexport const crypto =\n typeof globalThis === 'object' && 'crypto' in globalThis ? globalThis.crypto : undefined;\n", "/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */\n\n// We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.\n// node.js versions earlier than v19 don't declare it in global scope.\n// For node.js, package.json#exports field mapping rewrites import\n// from `crypto` to `cryptoNode`, which imports native module.\n// Makes the utils un-importable in browsers without a bundler.\n// Once node.js 18 is deprecated (2025-04-30), we can just drop the import.\nimport { crypto } from '@noble/hashes/crypto';\nimport { bytes as abytes } from './_assert.js';\n// export { isBytes } from './_assert.js';\n// We can't reuse isBytes from _assert, because somehow this causes huge perf issues\nexport function isBytes(a: unknown): a is Uint8Array {\n return (\n a instanceof Uint8Array ||\n (a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array')\n );\n}\n\n// prettier-ignore\nexport type TypedArray = Int8Array | Uint8ClampedArray | Uint8Array |\n Uint16Array | Int16Array | Uint32Array | Int32Array;\n\n// Cast array to different type\nexport const u8 = (arr: TypedArray) => new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);\nexport const u32 = (arr: TypedArray) =>\n new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));\n\n// Cast array to view\nexport const createView = (arr: TypedArray) =>\n new DataView(arr.buffer, arr.byteOffset, arr.byteLength);\n\n// The rotate right (circular right shift) operation for uint32\nexport const rotr = (word: number, shift: number) => (word << (32 - shift)) | (word >>> shift);\n// The rotate left (circular left shift) operation for uint32\nexport const rotl = (word: number, shift: number) =>\n (word << shift) | ((word >>> (32 - shift)) >>> 0);\n\nexport const isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;\n// The byte swap operation for uint32\nexport const byteSwap = (word: number) =>\n ((word << 24) & 0xff000000) |\n ((word << 8) & 0xff0000) |\n ((word >>> 8) & 0xff00) |\n ((word >>> 24) & 0xff);\n// Conditionally byte swap if on a big-endian platform\nexport const byteSwapIfBE = isLE ? (n: number) => n : (n: number) => byteSwap(n);\n\n// In place byte swap for Uint32Array\nexport function byteSwap32(arr: Uint32Array) {\n for (let i = 0; i < arr.length; i++) {\n arr[i] = byteSwap(arr[i]);\n }\n}\n\n// Array where index 0xf0 (240) is mapped to string 'f0'\nconst hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) =>\n i.toString(16).padStart(2, '0')\n);\n/**\n * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'\n */\nexport function bytesToHex(bytes: Uint8Array): string {\n abytes(bytes);\n // pre-caching improves the speed 6x\n let hex = '';\n for (let i = 0; i < bytes.length; i++) {\n hex += hexes[bytes[i]];\n }\n return hex;\n}\n\n// We use optimized technique to convert hex string to byte array\nconst asciis = { _0: 48, _9: 57, _A: 65, _F: 70, _a: 97, _f: 102 } as const;\nfunction asciiToBase16(char: number): number | undefined {\n if (char >= asciis._0 && char <= asciis._9) return char - asciis._0;\n if (char >= asciis._A && char <= asciis._F) return char - (asciis._A - 10);\n if (char >= asciis._a && char <= asciis._f) return char - (asciis._a - 10);\n return;\n}\n\n/**\n * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])\n */\nexport function hexToBytes(hex: string): Uint8Array {\n if (typeof hex !== 'string') throw new Error('hex string expected, got ' + typeof hex);\n const hl = hex.length;\n const al = hl / 2;\n if (hl % 2) throw new Error('padded hex string expected, got unpadded hex of length ' + hl);\n const array = new Uint8Array(al);\n for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {\n const n1 = asciiToBase16(hex.charCodeAt(hi));\n const n2 = asciiToBase16(hex.charCodeAt(hi + 1));\n if (n1 === undefined || n2 === undefined) {\n const char = hex[hi] + hex[hi + 1];\n throw new Error('hex string expected, got non-hex character \"' + char + '\" at index ' + hi);\n }\n array[ai] = n1 * 16 + n2;\n }\n return array;\n}\n\n// There is no setImmediate in browser and setTimeout is slow.\n// call of async fn will return Promise, which will be fullfiled only on\n// next scheduler queue processing step and this is exactly what we need.\nexport const nextTick = async () => {};\n\n// Returns control to thread each 'tick' ms to avoid blocking\nexport async function asyncLoop(iters: number, tick: number, cb: (i: number) => void) {\n let ts = Date.now();\n for (let i = 0; i < iters; i++) {\n cb(i);\n // Date.now() is not monotonic, so in case if clock goes backwards we return return control too\n const diff = Date.now() - ts;\n if (diff >= 0 && diff < tick) continue;\n await nextTick();\n ts += diff;\n }\n}\n\n// Global symbols in both browsers and Node.js since v11\n// See https://github.com/microsoft/TypeScript/issues/31535\ndeclare const TextEncoder: any;\n\n/**\n * @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])\n */\nexport function utf8ToBytes(str: string): Uint8Array {\n if (typeof str !== 'string') throw new Error(`utf8ToBytes expected string, got ${typeof str}`);\n return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809\n}\n\nexport type Input = Uint8Array | string;\n/**\n * Normalizes (non-hex) string or Uint8Array to Uint8Array.\n * Warning: when Uint8Array is passed, it would NOT get copied.\n * Keep in mind for future mutable operations.\n */\nexport function toBytes(data: Input): Uint8Array {\n if (typeof data === 'string') data = utf8ToBytes(data);\n abytes(data);\n return data;\n}\n\n/**\n * Copies several Uint8Arrays into one.\n */\nexport function concatBytes(...arrays: Uint8Array[]): Uint8Array {\n let sum = 0;\n for (let i = 0; i < arrays.length; i++) {\n const a = arrays[i];\n abytes(a);\n sum += a.length;\n }\n const res = new Uint8Array(sum);\n for (let i = 0, pad = 0; i < arrays.length; i++) {\n const a = arrays[i];\n res.set(a, pad);\n pad += a.length;\n }\n return res;\n}\n\n// For runtime check if class implements interface\nexport abstract class Hash<T extends Hash<T>> {\n abstract blockLen: number; // Bytes per block\n abstract outputLen: number; // Bytes in output\n abstract update(buf: Input): this;\n // Writes digest into buf\n abstract digestInto(buf: Uint8Array): void;\n abstract digest(): Uint8Array;\n /**\n * Resets internal state. Makes Hash instance unusable.\n * Reset is impossible for keyed hashes if key is consumed into state. If digest is not consumed\n * by user, they will need to manually call `destroy()` when zeroing is necessary.\n */\n abstract destroy(): void;\n /**\n * Clones hash instance. Unsafe: doesn't check whether `to` is valid. Can be used as `clone()`\n * when no options are passed.\n * Reasons to use `_cloneInto` instead of clone: 1) performance 2) reuse instance => all internal\n * buffers are overwritten => causes buffer overwrite which is used for digest in some cases.\n * There are no guarantees for clean-up because it's impossible in JS.\n */\n abstract _cloneInto(to?: T): T;\n // Safe version that clones internal state\n clone(): T {\n return this._cloneInto();\n }\n}\n\n/**\n * XOF: streaming API to read digest in chunks.\n * Same as 'squeeze' in keccak/k12 and 'seek' in blake3, but more generic name.\n * When hash used in XOF mode it is up to user to call '.destroy' afterwards, since we cannot\n * destroy state, next call can require more bytes.\n */\nexport type HashXOF<T extends Hash<T>> = Hash<T> & {\n xof(bytes: number): Uint8Array; // Read 'bytes' bytes from digest stream\n xofInto(buf: Uint8Array): Uint8Array; // read buf.length bytes from digest stream into buf\n};\n\nconst toStr = {}.toString;\ntype EmptyObj = {};\nexport function checkOpts<T1 extends EmptyObj, T2 extends EmptyObj>(\n defaults: T1,\n opts?: T2\n): T1 & T2 {\n if (opts !== undefined && toStr.call(opts) !== '[object Object]')\n throw new Error('Options should be object or undefined');\n const merged = Object.assign(defaults, opts);\n return merged as T1 & T2;\n}\n\nexport type CHash = ReturnType<typeof wrapConstructor>;\n\nexport function wrapConstructor<T extends Hash<T>>(hashCons: () => Hash<T>) {\n const hashC = (msg: Input): Uint8Array => hashCons().update(toBytes(msg)).digest();\n const tmp = hashCons();\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = () => hashCons();\n return hashC;\n}\n\nexport function wrapConstructorWithOpts<H extends Hash<H>, T extends Object>(\n hashCons: (opts?: T) => Hash<H>\n) {\n const hashC = (msg: Input, opts?: T): Uint8Array => hashCons(opts).update(toBytes(msg)).digest();\n const tmp = hashCons({} as T);\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = (opts: T) => hashCons(opts);\n return hashC;\n}\n\nexport function wrapXOFConstructorWithOpts<H extends HashXOF<H>, T extends Object>(\n hashCons: (opts?: T) => HashXOF<H>\n) {\n const hashC = (msg: Input, opts?: T): Uint8Array => hashCons(opts).update(toBytes(msg)).digest();\n const tmp = hashCons({} as T);\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = (opts: T) => hashCons(opts);\n return hashC;\n}\n\n/**\n * Secure PRNG. Uses `crypto.getRandomValues`, which defers to OS.\n */\nexport function randomBytes(bytesLength = 32): Uint8Array {\n if (crypto && typeof crypto.getRandomValues === 'function') {\n return crypto.getRandomValues(new Uint8Array(bytesLength));\n }\n throw new Error('crypto.getRandomValues must be defined');\n}\n", "import type { Jwk } from './jose/jwk.js';\n\nimport { crypto } from '@noble/hashes/crypto';\nimport { randomBytes as nobleRandomBytes } from '@noble/hashes/utils';\n\n/**\n * A collection of cryptographic utility methods.\n */\nexport class CryptoUtils {\n\n /**\n * Determines the JOSE algorithm identifier of the digital signature algorithm based on the `alg` or\n * `crv` property of a {@link Jwk | JWK}.\n *\n * If the `alg` property is present, its value takes precedence and is returned. Otherwise, the\n * `crv` property is used to determine the algorithm.\n *\n * @memberof CryptoUtils\n * @see {@link https://www.iana.org/assignments/jose/jose.xhtml#web-signature-encryption-algorithms | JOSE Algorithms}\n * @see {@link https://datatracker.ietf.org/doc/draft-ietf-jose-fully-specified-algorithms/ | Fully-Specified Algorithms for JOSE and COSE}\n *\n * @example\n * ```ts\n * const publicKey: Jwk = {\n * \"kty\": \"OKP\",\n * \"crv\": \"Ed25519\",\n * \"x\": \"FEJG7OakZi500EydXxuE8uMc8uaAzEJkmQeG8khXANw\"\n * }\n * const algorithm = getJoseSignatureAlgorithmFromPublicKey(publicKey);\n * console.log(algorithm); // Output: \"EdDSA\"\n * ```\n * @param publicKey - A JWK containing the `alg` and/or `crv` properties.\n * @returns The name of the algorithm associated with the key.\n * @throws Error if the algorithm cannot be determined from the provided input.\n */\n static getJoseSignatureAlgorithmFromPublicKey(publicKey: Jwk): string {\n const curveToJoseAlgorithm: Record<string, string> = {\n 'Ed25519' : 'EdDSA',\n 'P-256' : 'ES256',\n 'P-384' : 'ES384',\n 'P-521' : 'ES512',\n 'secp256k1' : 'ES256K',\n };\n\n // If the key contains an `alg` property that matches a JOSE registered algorithm identifier,\n // return its value.\n if (publicKey.alg && Object.values(curveToJoseAlgorithm).includes(publicKey.alg)) {\n return publicKey.alg;\n }\n\n // If the key contains a `crv` property, return the corresponding algorithm.\n if (publicKey.crv && Object.keys(curveToJoseAlgorithm).includes(publicKey.crv)) {\n return curveToJoseAlgorithm[publicKey.crv];\n }\n\n throw new Error(\n `Unable to determine algorithm based on provided input: alg=${publicKey.alg}, crv=${publicKey.crv}. ` +\n `Supported 'alg' values: ${Object.values(curveToJoseAlgorithm).join(', ')}. ` +\n `Supported 'crv' values: ${Object.keys(curveToJoseAlgorithm).join(', ')}.`\n );\n }\n\n /**\n * Generates secure pseudorandom values of the specified length using\n * `crypto.getRandomValues`, which defers to the operating system.\n *\n * @memberof CryptoUtils\n * @remarks\n * This function is a wrapper around `randomBytes` from the '@noble/hashes'\n * package. It's designed to be cryptographically strong, suitable for\n * generating initialization vectors, nonces, and other random values.\n *\n * @see {@link https://www.npmjs.com/package/@noble/hashes | @noble/hashes on NPM} for more\n * information about the underlying implementation.\n *\n * @example\n * ```ts\n * const bytes = randomBytes(32); // Generates 32 random bytes\n * ```\n *\n * @param bytesLength - The number of bytes to generate.\n * @returns A Uint8Array containing the generated random bytes.\n */\n static randomBytes(bytesLength: number): Uint8Array {\n return nobleRandomBytes(bytesLength);\n }\n\n /**\n * Generates a UUID (Universally Unique Identifier) using a\n * cryptographically strong random number generator following\n * the version 4 format, as specified in RFC 4122.\n *\n * A version 4 UUID is a randomly generated UUID. The 13th character\n * is set to '4' to denote version 4, and the 17th character is one\n * of '8', '9', 'A', or 'B' to comply with the variant 1 format of\n * UUIDs (the high bits are set to '10').\n *\n * The UUID is a 36 character string, including hyphens, and looks like this:\n * xxxxxxxx-xxxx-4xxx-axxx-xxxxxxxxxxxx\n *\n * Note that while UUIDs are not guaranteed to be unique, they are\n * practically unique\" given the large number of possible UUIDs and\n * the randomness of generation.\n * @memberof CryptoUtils\n * @example\n * ```ts\n * const uuid = randomUuid();\n * console.log(uuid); // Outputs a version 4 UUID, e.g., '123e4567-e89b-12d3-a456-426655440000'\n * ```\n *\n * @returns A string containing a randomly generated, 36 character long v4 UUID.\n */\n static randomUuid(): string {\n const uuid = crypto.randomUUID();\n\n return uuid;\n }\n\n\n /**\n * Generates a secure random PIN (Personal Identification Number) of a\n * specified length.\n *\n * This function ensures that the generated PIN is cryptographically secure and\n * uniformly distributed by using rejection sampling. It repeatedly generates\n * random numbers until it gets one in the desired range [0, max]. This avoids\n * bias introduced by simply taking the modulus or truncating the number.\n *\n * Note: The function can generate PINs of 3 to 10 digits in length.\n * Any request for a PIN outside this range will result in an error.\n *\n * Example usage:\n *\n * ```ts\n * const pin = randomPin({ length: 4 });\n * console.log(pin); // Outputs a 4-digit PIN, e.g., \"0231\"\n * ```\n * @memberof CryptoUtils\n * @param options - The options object containing the desired length of the generated PIN.\n * @param options.length - The desired length of the generated PIN. The value should be\n * an integer between 3 and 8 inclusive.\n *\n * @returns A string representing the generated PIN. The PIN will be zero-padded\n * to match the specified length, if necessary.\n *\n * @throws Will throw an error if the requested PIN length is less than 3 or greater than 8.\n */\n static randomPin({ length }: { length: number }): string {\n if (3 > length || length > 10) {\n throw new Error('randomPin() can securely generate a PIN between 3 to 10 digits.');\n }\n\n const max = Math.pow(10, length) - 1;\n\n let pin;\n\n if (length <= 6) {\n const rejectionRange = Math.pow(10, length);\n do {\n // Adjust the byte generation based on length.\n const randomBuffer = CryptoUtils.randomBytes(Math.ceil(length / 2) ); // 2 digits per byte.\n const view = new DataView(randomBuffer.buffer);\n // Convert the buffer to integer and take modulus based on length.\n pin = view.getUint16(0, false) % rejectionRange;\n } while (pin > max);\n } else {\n const rejectionRange = Math.pow(10, 10); // For max 10 digit number.\n do {\n // Generates 4 random bytes.\n const randomBuffer = CryptoUtils.randomBytes(4);\n // Create a DataView to read from the randomBuffer.\n const view = new DataView(randomBuffer.buffer);\n // Transform bytes to number (big endian).\n pin = view.getUint32(0, false) % rejectionRange;\n } while (pin > max); // Reject if the number is outside the desired range.\n }\n\n // Pad the PIN with leading zeros to the desired length.\n return pin.toString().padStart(length, '0');\n }\n}\n"],
3
+ "sources": ["../../../node_modules/.bun/@noble+hashes@1.4.0/node_modules/@noble/hashes/src/crypto.ts", "../../../node_modules/.bun/@noble+hashes@1.4.0/node_modules/@noble/hashes/src/utils.ts", "../src/utils.ts"],
4
+ "sourcesContent": ["// We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.\n// See utils.ts for details.\ndeclare const globalThis: Record<string, any> | undefined;\nexport const crypto =\n typeof globalThis === 'object' && 'crypto' in globalThis ? globalThis.crypto : undefined;\n", "/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */\n\n// We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.\n// node.js versions earlier than v19 don't declare it in global scope.\n// For node.js, package.json#exports field mapping rewrites import\n// from `crypto` to `cryptoNode`, which imports native module.\n// Makes the utils un-importable in browsers without a bundler.\n// Once node.js 18 is deprecated (2025-04-30), we can just drop the import.\nimport { crypto } from '@noble/hashes/crypto';\nimport { bytes as abytes } from './_assert.js';\n// export { isBytes } from './_assert.js';\n// We can't reuse isBytes from _assert, because somehow this causes huge perf issues\nexport function isBytes(a: unknown): a is Uint8Array {\n return (\n a instanceof Uint8Array ||\n (a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array')\n );\n}\n\n// prettier-ignore\nexport type TypedArray = Int8Array | Uint8ClampedArray | Uint8Array |\n Uint16Array | Int16Array | Uint32Array | Int32Array;\n\n// Cast array to different type\nexport const u8 = (arr: TypedArray) => new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);\nexport const u32 = (arr: TypedArray) =>\n new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));\n\n// Cast array to view\nexport const createView = (arr: TypedArray) =>\n new DataView(arr.buffer, arr.byteOffset, arr.byteLength);\n\n// The rotate right (circular right shift) operation for uint32\nexport const rotr = (word: number, shift: number) => (word << (32 - shift)) | (word >>> shift);\n// The rotate left (circular left shift) operation for uint32\nexport const rotl = (word: number, shift: number) =>\n (word << shift) | ((word >>> (32 - shift)) >>> 0);\n\nexport const isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;\n// The byte swap operation for uint32\nexport const byteSwap = (word: number) =>\n ((word << 24) & 0xff000000) |\n ((word << 8) & 0xff0000) |\n ((word >>> 8) & 0xff00) |\n ((word >>> 24) & 0xff);\n// Conditionally byte swap if on a big-endian platform\nexport const byteSwapIfBE = isLE ? (n: number) => n : (n: number) => byteSwap(n);\n\n// In place byte swap for Uint32Array\nexport function byteSwap32(arr: Uint32Array) {\n for (let i = 0; i < arr.length; i++) {\n arr[i] = byteSwap(arr[i]);\n }\n}\n\n// Array where index 0xf0 (240) is mapped to string 'f0'\nconst hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) =>\n i.toString(16).padStart(2, '0')\n);\n/**\n * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'\n */\nexport function bytesToHex(bytes: Uint8Array): string {\n abytes(bytes);\n // pre-caching improves the speed 6x\n let hex = '';\n for (let i = 0; i < bytes.length; i++) {\n hex += hexes[bytes[i]];\n }\n return hex;\n}\n\n// We use optimized technique to convert hex string to byte array\nconst asciis = { _0: 48, _9: 57, _A: 65, _F: 70, _a: 97, _f: 102 } as const;\nfunction asciiToBase16(char: number): number | undefined {\n if (char >= asciis._0 && char <= asciis._9) return char - asciis._0;\n if (char >= asciis._A && char <= asciis._F) return char - (asciis._A - 10);\n if (char >= asciis._a && char <= asciis._f) return char - (asciis._a - 10);\n return;\n}\n\n/**\n * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])\n */\nexport function hexToBytes(hex: string): Uint8Array {\n if (typeof hex !== 'string') throw new Error('hex string expected, got ' + typeof hex);\n const hl = hex.length;\n const al = hl / 2;\n if (hl % 2) throw new Error('padded hex string expected, got unpadded hex of length ' + hl);\n const array = new Uint8Array(al);\n for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {\n const n1 = asciiToBase16(hex.charCodeAt(hi));\n const n2 = asciiToBase16(hex.charCodeAt(hi + 1));\n if (n1 === undefined || n2 === undefined) {\n const char = hex[hi] + hex[hi + 1];\n throw new Error('hex string expected, got non-hex character \"' + char + '\" at index ' + hi);\n }\n array[ai] = n1 * 16 + n2;\n }\n return array;\n}\n\n// There is no setImmediate in browser and setTimeout is slow.\n// call of async fn will return Promise, which will be fullfiled only on\n// next scheduler queue processing step and this is exactly what we need.\nexport const nextTick = async () => {};\n\n// Returns control to thread each 'tick' ms to avoid blocking\nexport async function asyncLoop(iters: number, tick: number, cb: (i: number) => void) {\n let ts = Date.now();\n for (let i = 0; i < iters; i++) {\n cb(i);\n // Date.now() is not monotonic, so in case if clock goes backwards we return return control too\n const diff = Date.now() - ts;\n if (diff >= 0 && diff < tick) continue;\n await nextTick();\n ts += diff;\n }\n}\n\n// Global symbols in both browsers and Node.js since v11\n// See https://github.com/microsoft/TypeScript/issues/31535\ndeclare const TextEncoder: any;\n\n/**\n * @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])\n */\nexport function utf8ToBytes(str: string): Uint8Array {\n if (typeof str !== 'string') throw new Error(`utf8ToBytes expected string, got ${typeof str}`);\n return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809\n}\n\nexport type Input = Uint8Array | string;\n/**\n * Normalizes (non-hex) string or Uint8Array to Uint8Array.\n * Warning: when Uint8Array is passed, it would NOT get copied.\n * Keep in mind for future mutable operations.\n */\nexport function toBytes(data: Input): Uint8Array {\n if (typeof data === 'string') data = utf8ToBytes(data);\n abytes(data);\n return data;\n}\n\n/**\n * Copies several Uint8Arrays into one.\n */\nexport function concatBytes(...arrays: Uint8Array[]): Uint8Array {\n let sum = 0;\n for (let i = 0; i < arrays.length; i++) {\n const a = arrays[i];\n abytes(a);\n sum += a.length;\n }\n const res = new Uint8Array(sum);\n for (let i = 0, pad = 0; i < arrays.length; i++) {\n const a = arrays[i];\n res.set(a, pad);\n pad += a.length;\n }\n return res;\n}\n\n// For runtime check if class implements interface\nexport abstract class Hash<T extends Hash<T>> {\n abstract blockLen: number; // Bytes per block\n abstract outputLen: number; // Bytes in output\n abstract update(buf: Input): this;\n // Writes digest into buf\n abstract digestInto(buf: Uint8Array): void;\n abstract digest(): Uint8Array;\n /**\n * Resets internal state. Makes Hash instance unusable.\n * Reset is impossible for keyed hashes if key is consumed into state. If digest is not consumed\n * by user, they will need to manually call `destroy()` when zeroing is necessary.\n */\n abstract destroy(): void;\n /**\n * Clones hash instance. Unsafe: doesn't check whether `to` is valid. Can be used as `clone()`\n * when no options are passed.\n * Reasons to use `_cloneInto` instead of clone: 1) performance 2) reuse instance => all internal\n * buffers are overwritten => causes buffer overwrite which is used for digest in some cases.\n * There are no guarantees for clean-up because it's impossible in JS.\n */\n abstract _cloneInto(to?: T): T;\n // Safe version that clones internal state\n clone(): T {\n return this._cloneInto();\n }\n}\n\n/**\n * XOF: streaming API to read digest in chunks.\n * Same as 'squeeze' in keccak/k12 and 'seek' in blake3, but more generic name.\n * When hash used in XOF mode it is up to user to call '.destroy' afterwards, since we cannot\n * destroy state, next call can require more bytes.\n */\nexport type HashXOF<T extends Hash<T>> = Hash<T> & {\n xof(bytes: number): Uint8Array; // Read 'bytes' bytes from digest stream\n xofInto(buf: Uint8Array): Uint8Array; // read buf.length bytes from digest stream into buf\n};\n\nconst toStr = {}.toString;\ntype EmptyObj = {};\nexport function checkOpts<T1 extends EmptyObj, T2 extends EmptyObj>(\n defaults: T1,\n opts?: T2\n): T1 & T2 {\n if (opts !== undefined && toStr.call(opts) !== '[object Object]')\n throw new Error('Options should be object or undefined');\n const merged = Object.assign(defaults, opts);\n return merged as T1 & T2;\n}\n\nexport type CHash = ReturnType<typeof wrapConstructor>;\n\nexport function wrapConstructor<T extends Hash<T>>(hashCons: () => Hash<T>) {\n const hashC = (msg: Input): Uint8Array => hashCons().update(toBytes(msg)).digest();\n const tmp = hashCons();\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = () => hashCons();\n return hashC;\n}\n\nexport function wrapConstructorWithOpts<H extends Hash<H>, T extends Object>(\n hashCons: (opts?: T) => Hash<H>\n) {\n const hashC = (msg: Input, opts?: T): Uint8Array => hashCons(opts).update(toBytes(msg)).digest();\n const tmp = hashCons({} as T);\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = (opts: T) => hashCons(opts);\n return hashC;\n}\n\nexport function wrapXOFConstructorWithOpts<H extends HashXOF<H>, T extends Object>(\n hashCons: (opts?: T) => HashXOF<H>\n) {\n const hashC = (msg: Input, opts?: T): Uint8Array => hashCons(opts).update(toBytes(msg)).digest();\n const tmp = hashCons({} as T);\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = (opts: T) => hashCons(opts);\n return hashC;\n}\n\n/**\n * Secure PRNG. Uses `crypto.getRandomValues`, which defers to OS.\n */\nexport function randomBytes(bytesLength = 32): Uint8Array {\n if (crypto && typeof crypto.getRandomValues === 'function') {\n return crypto.getRandomValues(new Uint8Array(bytesLength));\n }\n throw new Error('crypto.getRandomValues must be defined');\n}\n", "import type { Jwk } from './jose/jwk.js';\n\nimport { crypto } from '@noble/hashes/crypto';\nimport { randomBytes as nobleRandomBytes } from '@noble/hashes/utils';\n\n/**\n * A collection of cryptographic utility methods.\n */\nexport class CryptoUtils {\n\n /**\n * Determines the JOSE algorithm identifier of the digital signature algorithm based on the `alg` or\n * `crv` property of a {@link Jwk | JWK}.\n *\n * If the `alg` property is present, its value takes precedence and is returned. Otherwise, the\n * `crv` property is used to determine the algorithm.\n *\n * @memberof CryptoUtils\n * @see {@link https://www.iana.org/assignments/jose/jose.xhtml#web-signature-encryption-algorithms | JOSE Algorithms}\n * @see {@link https://datatracker.ietf.org/doc/draft-ietf-jose-fully-specified-algorithms/ | Fully-Specified Algorithms for JOSE and COSE}\n *\n * @example\n * ```ts\n * const publicKey: Jwk = {\n * \"kty\": \"OKP\",\n * \"crv\": \"Ed25519\",\n * \"x\": \"FEJG7OakZi500EydXxuE8uMc8uaAzEJkmQeG8khXANw\"\n * }\n * const algorithm = getJoseSignatureAlgorithmFromPublicKey(publicKey);\n * console.log(algorithm); // Output: \"EdDSA\"\n * ```\n * @param publicKey - A JWK containing the `alg` and/or `crv` properties.\n * @returns The name of the algorithm associated with the key.\n * @throws Error if the algorithm cannot be determined from the provided input.\n */\n static getJoseSignatureAlgorithmFromPublicKey(publicKey: Jwk): string {\n const curveToJoseAlgorithm: Record<string, string> = {\n 'Ed25519' : 'EdDSA',\n 'P-256' : 'ES256',\n 'P-384' : 'ES384',\n 'P-521' : 'ES512',\n 'secp256k1' : 'ES256K',\n };\n\n // If the key contains an `alg` property that matches a JOSE registered algorithm identifier,\n // return its value.\n if (publicKey.alg && Object.values(curveToJoseAlgorithm).includes(publicKey.alg)) {\n return publicKey.alg;\n }\n\n // If the key contains a `crv` property, return the corresponding algorithm.\n if (publicKey.crv && Object.keys(curveToJoseAlgorithm).includes(publicKey.crv)) {\n return curveToJoseAlgorithm[publicKey.crv];\n }\n\n throw new Error(\n `Unable to determine algorithm based on provided input: alg=${publicKey.alg}, crv=${publicKey.crv}. ` +\n `Supported 'alg' values: ${Object.values(curveToJoseAlgorithm).join(', ')}. ` +\n `Supported 'crv' values: ${Object.keys(curveToJoseAlgorithm).join(', ')}.`\n );\n }\n\n /**\n * Generates secure pseudorandom values of the specified length using\n * `crypto.getRandomValues`, which defers to the operating system.\n *\n * @memberof CryptoUtils\n * @remarks\n * This function is a wrapper around `randomBytes` from the '@noble/hashes'\n * package. It's designed to be cryptographically strong, suitable for\n * generating initialization vectors, nonces, and other random values.\n *\n * @see {@link https://www.npmjs.com/package/@noble/hashes | @noble/hashes on NPM} for more\n * information about the underlying implementation.\n *\n * @example\n * ```ts\n * const bytes = randomBytes(32); // Generates 32 random bytes\n * ```\n *\n * @param bytesLength - The number of bytes to generate.\n * @returns A Uint8Array containing the generated random bytes.\n */\n static randomBytes(bytesLength: number): Uint8Array {\n return nobleRandomBytes(bytesLength);\n }\n\n /**\n * Generates a UUID (Universally Unique Identifier) using a\n * cryptographically strong random number generator following\n * the version 4 format, as specified in RFC 4122.\n *\n * A version 4 UUID is a randomly generated UUID. The 13th character\n * is set to '4' to denote version 4, and the 17th character is one\n * of '8', '9', 'A', or 'B' to comply with the variant 1 format of\n * UUIDs (the high bits are set to '10').\n *\n * The UUID is a 36 character string, including hyphens, and looks like this:\n * xxxxxxxx-xxxx-4xxx-axxx-xxxxxxxxxxxx\n *\n * Note that while UUIDs are not guaranteed to be unique, they are\n * practically unique\" given the large number of possible UUIDs and\n * the randomness of generation.\n * @memberof CryptoUtils\n * @example\n * ```ts\n * const uuid = randomUuid();\n * console.log(uuid); // Outputs a version 4 UUID, e.g., '123e4567-e89b-12d3-a456-426655440000'\n * ```\n *\n * @returns A string containing a randomly generated, 36 character long v4 UUID.\n */\n static randomUuid(): string {\n const uuid = crypto.randomUUID();\n\n return uuid;\n }\n\n\n /**\n * Generates a secure random PIN (Personal Identification Number) of a\n * specified length.\n *\n * This function ensures that the generated PIN is cryptographically secure and\n * uniformly distributed by using rejection sampling. It repeatedly generates\n * random numbers until it gets one in the desired range [0, max]. This avoids\n * bias introduced by simply taking the modulus or truncating the number.\n *\n * Note: The function can generate PINs of 3 to 10 digits in length.\n * Any request for a PIN outside this range will result in an error.\n *\n * Example usage:\n *\n * ```ts\n * const pin = randomPin({ length: 4 });\n * console.log(pin); // Outputs a 4-digit PIN, e.g., \"0231\"\n * ```\n * @memberof CryptoUtils\n * @param options - The options object containing the desired length of the generated PIN.\n * @param options.length - The desired length of the generated PIN. The value should be\n * an integer between 3 and 8 inclusive.\n *\n * @returns A string representing the generated PIN. The PIN will be zero-padded\n * to match the specified length, if necessary.\n *\n * @throws Will throw an error if the requested PIN length is less than 3 or greater than 8.\n */\n static randomPin({ length }: { length: number }): string {\n if (3 > length || length > 10) {\n throw new Error('randomPin() can securely generate a PIN between 3 to 10 digits.');\n }\n\n const max = Math.pow(10, length) - 1;\n\n let pin;\n\n if (length <= 6) {\n const rejectionRange = Math.pow(10, length);\n do {\n // Adjust the byte generation based on length.\n const randomBuffer = CryptoUtils.randomBytes(Math.ceil(length / 2) ); // 2 digits per byte.\n const view = new DataView(randomBuffer.buffer);\n // Convert the buffer to integer and take modulus based on length.\n pin = view.getUint16(0, false) % rejectionRange;\n } while (pin > max);\n } else {\n const rejectionRange = Math.pow(10, 10); // For max 10 digit number.\n do {\n // Generates 4 random bytes.\n const randomBuffer = CryptoUtils.randomBytes(4);\n // Create a DataView to read from the randomBuffer.\n const view = new DataView(randomBuffer.buffer);\n // Transform bytes to number (big endian).\n pin = view.getUint32(0, false) % rejectionRange;\n } while (pin > max); // Reject if the number is outside the desired range.\n }\n\n // Pad the PIN with leading zeros to the desired length.\n return pin.toString().padStart(length, '0');\n }\n}\n"],
5
5
  "mappings": "AAGO,IAAMA,EACX,OAAO,YAAe,UAAY,WAAY,WAAa,WAAW,OAAS,OCkC1E,IAAMC,EAAO,IAAI,WAAW,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AAI,SAASE,EAAa,MAAM,EAElC,UAAU,EAAG,EAAK,EAAID,CACnC,OAASD,EAAMD,EACjB,KAAO,CACL,IAAME,EAAiB,KAAK,IAAI,GAAI,EAAE,EACtC,EAAG,CAED,IAAMC,EAAeV,EAAY,YAAY,CAAC,EAI9CQ,EAFa,IAAI,SAASE,EAAa,MAAM,EAElC,UAAU,EAAG,EAAK,EAAID,CACnC,OAASD,EAAMD,EACjB,CAGA,OAAOC,EAAI,SAAS,EAAE,SAASF,EAAQ,GAAG,CAC5C,CACF",
6
6
  "names": ["crypto", "isLE", "toStr", "randomBytes", "bytesLength", "crypto", "CryptoUtils", "_CryptoUtils", "publicKey", "curveToJoseAlgorithm", "bytesLength", "randomBytes", "crypto", "length", "max", "pin", "rejectionRange", "randomBuffer"]
7
7
  }
package/package.json CHANGED
@@ -1,11 +1,23 @@
1
1
  {
2
2
  "name": "@enbox/crypto",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Web5 cryptographic library",
5
5
  "type": "module",
6
- "main": "./dist/cjs/index.js",
6
+ "main": "./dist/esm/index.js",
7
7
  "module": "./dist/esm/index.js",
8
8
  "types": "./dist/types/index.d.ts",
9
+ "scripts": {
10
+ "clean": "rimraf dist",
11
+ "build:esm": "rimraf dist/esm dist/types && bun tsc -p tsconfig.json",
12
+ "build:browser": "rimraf dist/browser.mjs dist/browser.js && bun build/bundles.js",
13
+ "build:tests:browser": "rimraf tests/compiled && bun build/esbuild-tests.cjs",
14
+ "build": "bun run clean && bun run build:esm && bun run build:browser",
15
+ "lint": "eslint . --max-warnings 0",
16
+ "lint:fix": "eslint . --fix",
17
+ "test:node": "bun test tests/",
18
+ "test:node:coverage": "bun test --coverage --coverage-reporter=text --coverage-reporter=lcov --coverage-dir=coverage tests/",
19
+ "test:browser": "bun run build:tests:browser && bunx web-test-runner"
20
+ },
9
21
  "homepage": "https://github.com/enboxorg/enbox/tree/main/packages/crypto#readme",
10
22
  "bugs": "https://github.com/enboxorg/enbox/issues",
11
23
  "repository": {
@@ -15,6 +27,10 @@
15
27
  },
16
28
  "license": "Apache-2.0",
17
29
  "contributors": [
30
+ {
31
+ "name": "Liran Cohen",
32
+ "url": "https://github.com/LiranCohen"
33
+ },
18
34
  {
19
35
  "name": "Daniel Buchner",
20
36
  "url": "https://github.com/csuwildcat"
@@ -35,13 +51,9 @@
35
51
  "exports": {
36
52
  ".": {
37
53
  "types": "./dist/types/index.d.ts",
38
- "import": "./dist/esm/index.js",
39
- "require": "./dist/cjs/index.js"
54
+ "import": "./dist/esm/index.js"
40
55
  }
41
56
  },
42
- "browser": {
43
- "node:crypto": false
44
- },
45
57
  "react-native": "./dist/esm/index.js",
46
58
  "keywords": [
47
59
  "cryptography",
@@ -53,51 +65,26 @@
53
65
  "access": "public"
54
66
  },
55
67
  "engines": {
56
- "node": ">=18.0.0"
68
+ "bun": ">=1.0.0"
57
69
  },
58
70
  "dependencies": {
59
71
  "@noble/ciphers": "0.5.3",
60
72
  "@noble/curves": "1.3.0",
61
73
  "@noble/hashes": "1.4.0",
62
- "@enbox/common": "0.0.2"
74
+ "@enbox/common": "0.0.3"
63
75
  },
64
76
  "devDependencies": {
65
77
  "@playwright/test": "1.45.3",
66
- "@types/chai": "4.3.16",
67
- "@types/chai-as-promised": "7.1.8",
68
- "@types/eslint": "8.56.10",
69
- "@types/mocha": "10.0.6",
70
78
  "@types/node": "20.14.8",
71
- "@types/sinon": "17.0.3",
72
- "@typescript-eslint/eslint-plugin": "7.14.1",
73
- "@typescript-eslint/parser": "7.14.1",
79
+ "@typescript-eslint/eslint-plugin": "8.32.1",
80
+ "@typescript-eslint/parser": "8.32.1",
74
81
  "@web/test-runner": "0.18.2",
75
82
  "@web/test-runner-playwright": "0.11.0",
76
- "c8": "10.1.2",
77
- "chai": "5.1.1",
78
- "chai-as-promised": "8.0.0",
79
83
  "esbuild": "0.23.0",
80
- "eslint": "9.5.0",
81
- "eslint-plugin-mocha": "10.4.3",
82
- "mocha": "10.4.0",
83
- "mocha-junit-reporter": "2.2.1",
84
+ "eslint": "9.7.0",
84
85
  "playwright": "1.45.3",
85
86
  "rimraf": "5.0.7",
86
- "sinon": "18.0.0",
87
87
  "source-map-loader": "5.0.0",
88
- "typescript": "5.4.5"
89
- },
90
- "scripts": {
91
- "clean": "rimraf dist tests/compiled",
92
- "build:esm": "rimraf dist/esm dist/types && pnpm tsc -p tsconfig.json",
93
- "build:cjs": "rimraf dist/cjs && pnpm tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json",
94
- "build:browser": "rimraf dist/browser.mjs dist/browser.js && node build/bundles.js",
95
- "build:tests:node": "rimraf tests/compiled && pnpm tsc -p tests/tsconfig.json",
96
- "build:tests:browser": "rimraf tests/compiled && node build/esbuild-tests.cjs",
97
- "build": "pnpm clean && pnpm build:esm && pnpm build:cjs && pnpm build:browser",
98
- "lint": "eslint . --max-warnings 0",
99
- "lint:fix": "eslint . --fix",
100
- "test:node": "pnpm build:tests:node && pnpm c8 mocha",
101
- "test:browser": "pnpm build:tests:browser && web-test-runner"
88
+ "typescript": "5.5.4"
102
89
  }
103
- }
90
+ }
@@ -1,5 +1,5 @@
1
- import type { Jwk } from '../jose/jwk.js';
2
1
  import type { Cipher } from '../types/cipher.js';
2
+ import type { Jwk } from '../jose/jwk.js';
3
3
  import type { KeyGenerator } from '../types/key-generator.js';
4
4
  import type { DecryptParams, EncryptParams, GenerateKeyParams } from '../types/params-direct.js';
5
5
 
@@ -1,10 +1,11 @@
1
- import type { Jwk } from '../jose/jwk.js';
1
+ import type { AES_GCM_TAG_LENGTHS } from '../primitives/aes-gcm.js';
2
2
  import type { Cipher } from '../types/cipher.js';
3
+ import type { Jwk } from '../jose/jwk.js';
3
4
  import type { KeyGenerator } from '../types/key-generator.js';
4
5
  import type { DecryptParams, EncryptParams, GenerateKeyParams } from '../types/params-direct.js';
5
6
 
7
+ import { AesGcm } from '../primitives/aes-gcm.js';
6
8
  import { CryptoAlgorithm } from './crypto-algorithm.js';
7
- import { AesGcm, AES_GCM_TAG_LENGTHS } from '../primitives/aes-gcm.js';
8
9
 
9
10
  /**
10
11
  * The `AesGcmGenerateKeyParams` interface defines the algorithm-specific parameters that should be