@enbox/crypto 0.0.1 → 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 +21 -34
  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
@@ -1,11 +1,17 @@
1
+ import type { AsymmetricKeyGenerator } from '../types/key-generator.js';
1
2
  import type { Jwk } from '../jose/jwk.js';
2
3
  import type { Signer } from '../types/signer.js';
3
- import type { AsymmetricKeyGenerator } from '../types/key-generator.js';
4
- import type { ComputePublicKeyParams, GenerateKeyParams, GetPublicKeyParams, SignParams, VerifyParams } from '../types/params-direct.js';
4
+ import type {
5
+ ComputePublicKeyParams,
6
+ GenerateKeyParams,
7
+ GetPublicKeyParams,
8
+ SignParams,
9
+ VerifyParams,
10
+ } from '../types/params-direct.js';
5
11
 
12
+ import { CryptoAlgorithm } from './crypto-algorithm.js';
6
13
  import { Secp256k1 } from '../primitives/secp256k1.js';
7
14
  import { Secp256r1 } from '../primitives/secp256r1.js';
8
- import { CryptoAlgorithm } from './crypto-algorithm.js';
9
15
  import { isEcPrivateJwk, isEcPublicJwk } from '../jose/jwk.js';
10
16
 
11
17
  /**
@@ -60,7 +66,7 @@ export class EcdsaAlgorithm extends CryptoAlgorithm
60
66
  public async computePublicKey({ key }:
61
67
  ComputePublicKeyParams
62
68
  ): Promise<Jwk> {
63
- if (!isEcPrivateJwk(key)) throw new TypeError('Invalid key provided. Must be an elliptic curve (EC) private key.');
69
+ if (!isEcPrivateJwk(key)) {throw new TypeError('Invalid key provided. Must be an elliptic curve (EC) private key.');}
64
70
 
65
71
  switch (key.crv) {
66
72
 
@@ -146,7 +152,7 @@ export class EcdsaAlgorithm extends CryptoAlgorithm
146
152
  public async getPublicKey({ key }:
147
153
  GetPublicKeyParams
148
154
  ): Promise<Jwk> {
149
- if (!isEcPrivateJwk(key)) throw new TypeError('Invalid key provided. Must be an elliptic curve (EC) private key.');
155
+ if (!isEcPrivateJwk(key)) {throw new TypeError('Invalid key provided. Must be an elliptic curve (EC) private key.');}
150
156
 
151
157
  switch (key.crv) {
152
158
 
@@ -199,7 +205,7 @@ export class EcdsaAlgorithm extends CryptoAlgorithm
199
205
  public async sign({ key, data }:
200
206
  SignParams
201
207
  ): Promise<Uint8Array> {
202
- if (!isEcPrivateJwk(key)) throw new TypeError('Invalid key provided. Must be an elliptic curve (EC) private key.');
208
+ if (!isEcPrivateJwk(key)) {throw new TypeError('Invalid key provided. Must be an elliptic curve (EC) private key.');}
203
209
 
204
210
  switch (key.crv) {
205
211
 
@@ -249,7 +255,7 @@ export class EcdsaAlgorithm extends CryptoAlgorithm
249
255
  public async verify({ key, signature, data }:
250
256
  VerifyParams
251
257
  ): Promise<boolean> {
252
- if (!isEcPublicJwk(key)) throw new TypeError('Invalid key provided. Must be an elliptic curve (EC) public key.');
258
+ if (!isEcPublicJwk(key)) {throw new TypeError('Invalid key provided. Must be an elliptic curve (EC) public key.');}
253
259
 
254
260
  switch (key.crv) {
255
261
 
@@ -1,16 +1,16 @@
1
+ import type { AsymmetricKeyGenerator } from '../types/key-generator.js';
1
2
  import type { Jwk } from '../jose/jwk.js';
2
3
  import type { Signer } from '../types/signer.js';
3
- import type { AsymmetricKeyGenerator } from '../types/key-generator.js';
4
4
  import type {
5
- SignParams,
6
- VerifyParams,
5
+ ComputePublicKeyParams,
7
6
  GenerateKeyParams,
8
7
  GetPublicKeyParams,
9
- ComputePublicKeyParams,
8
+ SignParams,
9
+ VerifyParams,
10
10
  } from '../types/params-direct.js';
11
11
 
12
- import { Ed25519 } from '../primitives/ed25519.js';
13
12
  import { CryptoAlgorithm } from './crypto-algorithm.js';
13
+ import { Ed25519 } from '../primitives/ed25519.js';
14
14
  import { isOkpPrivateJwk, isOkpPublicJwk } from '../jose/jwk.js';
15
15
 
16
16
  /**
@@ -62,7 +62,7 @@ export class EdDsaAlgorithm extends CryptoAlgorithm
62
62
  public async computePublicKey({ key }:
63
63
  ComputePublicKeyParams
64
64
  ): Promise<Jwk> {
65
- if (!isOkpPrivateJwk(key)) throw new TypeError('Invalid key provided. Must be an octet key pair (OKP) private key.');
65
+ if (!isOkpPrivateJwk(key)) {throw new TypeError('Invalid key provided. Must be an octet key pair (OKP) private key.');}
66
66
 
67
67
  switch (key.crv) {
68
68
 
@@ -134,7 +134,7 @@ export class EdDsaAlgorithm extends CryptoAlgorithm
134
134
  public async getPublicKey({ key }:
135
135
  GetPublicKeyParams
136
136
  ): Promise<Jwk> {
137
- if (!isOkpPrivateJwk(key)) throw new TypeError('Invalid key provided. Must be an octet key pair (OKP) private key.');
137
+ if (!isOkpPrivateJwk(key)) {throw new TypeError('Invalid key provided. Must be an octet key pair (OKP) private key.');}
138
138
 
139
139
  switch (key.crv) {
140
140
 
@@ -181,7 +181,7 @@ export class EdDsaAlgorithm extends CryptoAlgorithm
181
181
  public async sign({ key, data }:
182
182
  SignParams
183
183
  ): Promise<Uint8Array> {
184
- if (!isOkpPrivateJwk(key)) throw new TypeError('Invalid key provided. Must be an octet key pair (OKP) private key.');
184
+ if (!isOkpPrivateJwk(key)) {throw new TypeError('Invalid key provided. Must be an octet key pair (OKP) private key.');}
185
185
 
186
186
  switch (key.crv) {
187
187
 
@@ -227,7 +227,7 @@ export class EdDsaAlgorithm extends CryptoAlgorithm
227
227
  public async verify({ key, signature, data }:
228
228
  VerifyParams
229
229
  ): Promise<boolean> {
230
- if (!isOkpPublicJwk(key)) throw new TypeError('Invalid key provided. Must be an octet key pair (OKP) public key.');
230
+ if (!isOkpPublicJwk(key)) {throw new TypeError('Invalid key provided. Must be an octet key pair (OKP) public key.');}
231
231
 
232
232
  switch (key.crv) {
233
233
 
@@ -1,8 +1,8 @@
1
- import type { Hasher } from '../types/hasher.js';
2
1
  import type { DigestParams } from '../types/params-direct.js';
2
+ import type { Hasher } from '../types/hasher.js';
3
3
 
4
- import { Sha256 } from '../primitives/sha256.js';
5
4
  import { CryptoAlgorithm } from './crypto-algorithm.js';
5
+ import { Sha256 } from '../primitives/sha256.js';
6
6
 
7
7
  /**
8
8
  * The `Sha2DigestParams` interface defines the algorithm-specific parameters that should be
@@ -0,0 +1,45 @@
1
+ /**
2
+ * A custom error class for Crypto-related errors.
3
+ */
4
+ export class CryptoError extends Error {
5
+ /**
6
+ * Constructs an instance of CryptoError, a custom error class for handling Crypto-related errors.
7
+ *
8
+ * @param code - A {@link CryptoErrorCode} representing the specific type of error encountered.
9
+ * @param message - A human-readable description of the error.
10
+ */
11
+ constructor(public code: CryptoErrorCode, message: string) {
12
+ super(message);
13
+ this.name = 'CryptoError';
14
+
15
+ // Ensures that instanceof works properly, the correct prototype chain when using inheritance,
16
+ // and that V8 stack traces (like Chrome, Edge, and Node.js) are more readable and relevant.
17
+ Object.setPrototypeOf(this, new.target.prototype);
18
+
19
+ // Captures the stack trace in V8 engines (like Chrome, Edge, and Node.js).
20
+ // In non-V8 environments, the stack trace will still be captured.
21
+ if (Error.captureStackTrace) {
22
+ Error.captureStackTrace(this, CryptoError);
23
+ }
24
+ }
25
+ }
26
+
27
+ /**
28
+ * An enumeration of possible Crypto error codes.
29
+ */
30
+ export enum CryptoErrorCode {
31
+ /** The supplied algorithm identifier is not supported by the implementation. */
32
+ AlgorithmNotSupported = 'algorithmNotSupported',
33
+
34
+ /** The encoding operation (either encoding or decoding) failed. */
35
+ EncodingError = 'encodingError',
36
+
37
+ /** The JWE supplied does not conform to valid syntax. */
38
+ InvalidJwe = 'invalidJwe',
39
+
40
+ /** The JWK supplied does not conform to valid syntax. */
41
+ InvalidJwk = 'invalidJwk',
42
+
43
+ /** The requested operation is not supported by the implementation. */
44
+ OperationNotSupported = 'operationNotSupported',
45
+ }
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './crypto-error.js';
1
2
  export * from './local-key-manager.js';
2
3
  export * from './utils.js';
3
4
 
@@ -16,8 +17,10 @@ export * from './jose/utils.js';
16
17
 
17
18
  export * from './primitives/aes-ctr.js';
18
19
  export * from './primitives/aes-gcm.js';
20
+ export * from './primitives/aes-kw.js';
19
21
  export * from './primitives/concat-kdf.js';
20
22
  export * from './primitives/ed25519.js';
23
+ export * from './primitives/hkdf.js';
21
24
  export * from './primitives/secp256r1.js';
22
25
  export * from './primitives/pbkdf2.js';
23
26
  export * from './primitives/secp256k1.js';
package/src/jose/jwk.ts CHANGED
@@ -106,7 +106,7 @@ export type JwkType =
106
106
  * A type of public key that is used with algorithms such as EdDSA (Ed25519 and
107
107
  * Ed448 curves) and ECDH (X25519 and X448 curves).
108
108
  */
109
- | 'OKP'
109
+ | 'OKP';
110
110
 
111
111
  /**
112
112
  * JSON Web Key Elliptic Curve
@@ -155,7 +155,7 @@ export type JwkParamsAnyKeyType = {
155
155
  'x5t#S256'?: string;
156
156
  /** JWK X.509 URL Parameter */
157
157
  x5u?: string;
158
- }
158
+ };
159
159
 
160
160
  /** Parameters used with "EC" (elliptic curve) public keys. */
161
161
  export type JwkParamsEcPublic = Omit<JwkParamsAnyKeyType, 'alg' | 'kty'> & {
@@ -194,7 +194,7 @@ export type JwkParamsEcPublic = Omit<JwkParamsAnyKeyType, 'alg' | 'kty'> & {
194
194
  * MUST be present only for secp256k1 public keys.
195
195
  */
196
196
  y?: string;
197
- }
197
+ };
198
198
 
199
199
  /** Parameters used with "EC" (elliptic curve) private keys. */
200
200
  export type JwkParamsEcPrivate = JwkParamsEcPublic & {
@@ -205,7 +205,7 @@ export type JwkParamsEcPrivate = JwkParamsEcPublic & {
205
205
  * MUST be present for all EC private keys.
206
206
  */
207
207
  d: string;
208
- }
208
+ };
209
209
 
210
210
  /** Parameters used with "OKP" (octet key pair) public keys. */
211
211
  export type JwkParamsOkpPublic =
@@ -229,7 +229,7 @@ export type JwkParamsOkpPublic =
229
229
  * strings as private and public keys.
230
230
  */
231
231
  kty: 'OKP';
232
- }
232
+ };
233
233
 
234
234
  /** Parameters used with "OKP" (octet key pair) private keys. */
235
235
  export type JwkParamsOkpPrivate = JwkParamsOkpPublic & {
@@ -288,7 +288,7 @@ export type JwkParamsOctPrivate = Omit<JwkParamsAnyKeyType, 'alg' | 'kty'> & {
288
288
  * symmetric signature algorithms.
289
289
  */
290
290
  kty: 'oct';
291
- }
291
+ };
292
292
 
293
293
  /** Parameters Used with "RSA" public keys. */
294
294
  export type JwkParamsRsaPublic = Omit<JwkParamsAnyKeyType, 'kty'> & {
@@ -519,11 +519,11 @@ export async function computeJwkThumbprint({ jwk }: {
519
519
  * @returns True if the object is a valid EC private JWK; otherwise, false.
520
520
  */
521
521
  export function isEcPrivateJwk(obj: unknown): obj is JwkParamsEcPrivate {
522
- if (!obj || typeof obj !== 'object') return false;
523
- if (!('kty' in obj && 'crv' in obj && 'x' in obj && 'd' in obj)) return false;
524
- if (obj.kty !== 'EC') return false;
525
- if (typeof obj.d !== 'string') return false;
526
- if (typeof obj.x !== 'string') return false;
522
+ if (!obj || typeof obj !== 'object') {return false;}
523
+ if (!('kty' in obj && 'crv' in obj && 'x' in obj && 'd' in obj)) {return false;}
524
+ if (obj.kty !== 'EC') {return false;}
525
+ if (typeof obj.d !== 'string') {return false;}
526
+ if (typeof obj.x !== 'string') {return false;}
527
527
  return true;
528
528
  }
529
529
 
@@ -534,11 +534,11 @@ export function isEcPrivateJwk(obj: unknown): obj is JwkParamsEcPrivate {
534
534
  * @returns True if the object is a valid EC public JWK; otherwise, false.
535
535
  */
536
536
  export function isEcPublicJwk(obj: unknown): obj is JwkParamsEcPublic {
537
- if (!obj || typeof obj !== 'object') return false;
538
- if (!('kty' in obj && 'crv' in obj && 'x' in obj)) return false;
539
- if ('d' in obj) return false;
540
- if (obj.kty !== 'EC') return false;
541
- if (typeof obj.x !== 'string') return false;
537
+ if (!obj || typeof obj !== 'object') {return false;}
538
+ if (!('kty' in obj && 'crv' in obj && 'x' in obj)) {return false;}
539
+ if ('d' in obj) {return false;}
540
+ if (obj.kty !== 'EC') {return false;}
541
+ if (typeof obj.x !== 'string') {return false;}
542
542
  return true;
543
543
  }
544
544
 
@@ -549,10 +549,10 @@ export function isEcPublicJwk(obj: unknown): obj is JwkParamsEcPublic {
549
549
  * @returns True if the object is a valid oct private JWK; otherwise, false.
550
550
  */
551
551
  export function isOctPrivateJwk(obj: unknown): obj is JwkParamsOctPrivate {
552
- if (!obj || typeof obj !== 'object') return false;
553
- if (!('kty' in obj && 'k' in obj)) return false;
554
- if (obj.kty !== 'oct') return false;
555
- if (typeof obj.k !== 'string') return false;
552
+ if (!obj || typeof obj !== 'object') {return false;}
553
+ if (!('kty' in obj && 'k' in obj)) {return false;}
554
+ if (obj.kty !== 'oct') {return false;}
555
+ if (typeof obj.k !== 'string') {return false;}
556
556
  return true;
557
557
  }
558
558
 
@@ -563,11 +563,11 @@ export function isOctPrivateJwk(obj: unknown): obj is JwkParamsOctPrivate {
563
563
  * @returns True if the object is a valid OKP private JWK; otherwise, false.
564
564
  */
565
565
  export function isOkpPrivateJwk(obj: unknown): obj is JwkParamsOkpPrivate {
566
- if (!obj || typeof obj !== 'object') return false;
567
- if (!('kty' in obj && 'crv' in obj && 'x' in obj && 'd' in obj)) return false;
568
- if (obj.kty !== 'OKP') return false;
569
- if (typeof obj.d !== 'string') return false;
570
- if (typeof obj.x !== 'string') return false;
566
+ if (!obj || typeof obj !== 'object') {return false;}
567
+ if (!('kty' in obj && 'crv' in obj && 'x' in obj && 'd' in obj)) {return false;}
568
+ if (obj.kty !== 'OKP') {return false;}
569
+ if (typeof obj.d !== 'string') {return false;}
570
+ if (typeof obj.x !== 'string') {return false;}
571
571
  return true;
572
572
  }
573
573
 
@@ -578,11 +578,11 @@ export function isOkpPrivateJwk(obj: unknown): obj is JwkParamsOkpPrivate {
578
578
  * @returns True if the object is a valid OKP public JWK; otherwise, false.
579
579
  */
580
580
  export function isOkpPublicJwk(obj: unknown): obj is JwkParamsOkpPublic {
581
- if (!obj || typeof obj !== 'object') return false;
582
- if ('d' in obj) return false;
583
- if (!('kty' in obj && 'crv' in obj && 'x' in obj)) return false;
584
- if (obj.kty !== 'OKP') return false;
585
- if (typeof obj.x !== 'string') return false;
581
+ if (!obj || typeof obj !== 'object') {return false;}
582
+ if ('d' in obj) {return false;}
583
+ if (!('kty' in obj && 'crv' in obj && 'x' in obj)) {return false;}
584
+ if (obj.kty !== 'OKP') {return false;}
585
+ if (typeof obj.x !== 'string') {return false;}
586
586
  return true;
587
587
  }
588
588
 
@@ -593,7 +593,7 @@ export function isOkpPublicJwk(obj: unknown): obj is JwkParamsOkpPublic {
593
593
  * @returns True if the object is a valid private JWK; otherwise, false.
594
594
  */
595
595
  export function isPrivateJwk(obj: unknown): obj is PrivateKeyJwk {
596
- if (!obj || typeof obj !== 'object') return false;
596
+ if (!obj || typeof obj !== 'object') {return false;}
597
597
 
598
598
  const kty = (obj as { kty: string }).kty;
599
599
 
@@ -616,7 +616,7 @@ export function isPrivateJwk(obj: unknown): obj is PrivateKeyJwk {
616
616
  * @returns True if the object is a valid public JWK; otherwise, false.
617
617
  */
618
618
  export function isPublicJwk(obj: unknown): obj is PublicKeyJwk {
619
- if (!obj || typeof obj !== 'object') return false;
619
+ if (!obj || typeof obj !== 'object') {return false;}
620
620
 
621
621
  const kty = (obj as { kty: string }).kty;
622
622
 
@@ -1,28 +1,29 @@
1
- import { KeyValueStore, MemoryStore } from '@enbox/common';
1
+ import type { KeyValueStore } from '@enbox/common';
2
+ import { MemoryStore } from '@enbox/common';
2
3
 
3
- import type { Jwk } from './jose/jwk.js';
4
- import type { Hasher } from './types/hasher.js';
5
- import type { Signer } from './types/signer.js';
4
+ import type { CryptoAlgorithm } from './algorithms/crypto-algorithm.js';
6
5
  import type { CryptoApi } from './types/crypto-api.js';
6
+ import type { Hasher } from './types/hasher.js';
7
+ import type { Jwk } from './jose/jwk.js';
7
8
  import type { KeyIdentifier } from './types/identifier.js';
8
9
  import type { KeyImporterExporter } from './types/key-io.js';
9
- import type { KeyGenerator, AsymmetricKeyGenerator } from './types/key-generator.js';
10
+ import type { Signer } from './types/signer.js';
11
+ import type { AsymmetricKeyGenerator, KeyGenerator } from './types/key-generator.js';
10
12
  import type { GetPublicKeyParams, SignParams, VerifyParams } from './types/params-direct.js';
11
13
  import type {
12
- KmsSignParams,
13
14
  KmsDigestParams,
14
- KmsVerifyParams,
15
15
  KmsExportKeyParams,
16
- KmsGetKeyUriParams,
17
- KmsImportKeyParams,
18
16
  KmsGenerateKeyParams,
17
+ KmsGetKeyUriParams,
19
18
  KmsGetPublicKeyParams,
19
+ KmsImportKeyParams,
20
+ KmsSignParams,
21
+ KmsVerifyParams,
20
22
  } from './types/params-kms.js';
21
23
 
22
- import { Sha2Algorithm } from './algorithms/sha-2.js';
23
24
  import { EcdsaAlgorithm } from './algorithms/ecdsa.js';
24
25
  import { EdDsaAlgorithm } from './algorithms/eddsa.js';
25
- import { CryptoAlgorithm } from './algorithms/crypto-algorithm.js';
26
+ import { Sha2Algorithm } from './algorithms/sha-2.js';
26
27
  import { computeJwkThumbprint, isPrivateJwk, KEY_URI_PREFIX_JWK } from './jose/jwk.js';
27
28
 
28
29
  /**
@@ -53,7 +54,7 @@ const supportedAlgorithms = {
53
54
  } satisfies {
54
55
  [key: string]: {
55
56
  implementation : typeof CryptoAlgorithm;
56
- names : string[];
57
+ names : string[];
57
58
  }
58
59
  };
59
60
 
@@ -335,7 +336,7 @@ export class LocalKeyManager implements
335
336
  public async importKey({ key }:
336
337
  KmsImportKeyParams
337
338
  ): Promise<KeyIdentifier> {
338
- if (!isPrivateJwk(key)) throw new TypeError('Invalid key provided. Must be a private key in JWK format.');
339
+ if (!isPrivateJwk(key)) {throw new TypeError('Invalid key provided. Must be a private key in JWK format.');}
339
340
 
340
341
  // Make a deep copy of the key to avoid mutating the original.
341
342
  const privateKey = structuredClone(key);
@@ -296,7 +296,7 @@ export class AesCtr {
296
296
  length: typeof AES_KEY_LENGTHS[number];
297
297
  }): Promise<Jwk> {
298
298
  // Validate the key length.
299
- if (!AES_KEY_LENGTHS.includes(length as any)) {
299
+ if (!(AES_KEY_LENGTHS as readonly number[]).includes(length)) {
300
300
  throw new RangeError(`The key length is invalid: Must be ${AES_KEY_LENGTHS.join(', ')} bits`);
301
301
  }
302
302
 
@@ -187,7 +187,7 @@ export class AesGcm {
187
187
  }
188
188
 
189
189
  // Validate the tag length.
190
- if (tagLength && !AES_GCM_TAG_LENGTHS.includes(tagLength as any)) {
190
+ if (tagLength && !(AES_GCM_TAG_LENGTHS as readonly number[]).includes(tagLength)) {
191
191
  throw new RangeError(`The tag length is invalid: Must be ${AES_GCM_TAG_LENGTHS.join(', ')} bits`);
192
192
  }
193
193
 
@@ -203,7 +203,7 @@ export class AesGcm {
203
203
  name: 'AES-GCM',
204
204
  iv,
205
205
  ...(tagLength && { tagLength }),
206
- ...(additionalData && { additionalData})
206
+ ...(additionalData && { additionalData })
207
207
  };
208
208
 
209
209
  // Decrypt the data.
@@ -263,7 +263,7 @@ export class AesGcm {
263
263
  }
264
264
 
265
265
  // Validate the tag length.
266
- if (tagLength && !AES_GCM_TAG_LENGTHS.includes(tagLength as any)) {
266
+ if (tagLength && !(AES_GCM_TAG_LENGTHS as readonly number[]).includes(tagLength)) {
267
267
  throw new RangeError(`The tag length is invalid: Must be ${AES_GCM_TAG_LENGTHS.join(', ')} bits`);
268
268
  }
269
269
 
@@ -279,7 +279,7 @@ export class AesGcm {
279
279
  name: 'AES-GCM',
280
280
  iv,
281
281
  ...(tagLength && { tagLength }),
282
- ...(additionalData && { additionalData})
282
+ ...(additionalData && { additionalData })
283
283
  };
284
284
 
285
285
  // Encrypt the data.
@@ -321,7 +321,7 @@ export class AesGcm {
321
321
  length: typeof AES_KEY_LENGTHS[number];
322
322
  }): Promise<Jwk> {
323
323
  // Validate the key length.
324
- if (!AES_KEY_LENGTHS.includes(length as any)) {
324
+ if (!(AES_KEY_LENGTHS as readonly number[]).includes(length)) {
325
325
  throw new RangeError(`The key length is invalid: Must be ${AES_KEY_LENGTHS.join(', ')} bits`);
326
326
  }
327
327