@enbox/crypto 0.0.3 → 0.0.5

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 (116) hide show
  1. package/dist/browser.mjs +1 -1
  2. package/dist/browser.mjs.map +4 -4
  3. package/dist/esm/algorithms/aes-ctr.js +1 -1
  4. package/dist/esm/algorithms/aes-gcm.js +34 -1
  5. package/dist/esm/algorithms/aes-gcm.js.map +1 -1
  6. package/dist/esm/algorithms/aes-kw.js +154 -0
  7. package/dist/esm/algorithms/aes-kw.js.map +1 -0
  8. package/dist/esm/algorithms/ecdsa.js +110 -1
  9. package/dist/esm/algorithms/ecdsa.js.map +1 -1
  10. package/dist/esm/algorithms/eddsa.js +90 -1
  11. package/dist/esm/algorithms/eddsa.js.map +1 -1
  12. package/dist/esm/algorithms/hkdf.js +53 -0
  13. package/dist/esm/algorithms/hkdf.js.map +1 -0
  14. package/dist/esm/algorithms/pbkdf2.js +55 -0
  15. package/dist/esm/algorithms/pbkdf2.js.map +1 -0
  16. package/dist/esm/algorithms/sha-2.js +1 -1
  17. package/dist/esm/algorithms/x25519.js +125 -0
  18. package/dist/esm/algorithms/x25519.js.map +1 -0
  19. package/dist/esm/cose/cbor.js +35 -0
  20. package/dist/esm/cose/cbor.js.map +1 -0
  21. package/dist/esm/cose/cose-key.js +312 -0
  22. package/dist/esm/cose/cose-key.js.map +1 -0
  23. package/dist/esm/cose/cose-sign1.js +283 -0
  24. package/dist/esm/cose/cose-sign1.js.map +1 -0
  25. package/dist/esm/cose/eat.js +254 -0
  26. package/dist/esm/cose/eat.js.map +1 -0
  27. package/dist/esm/crypto-error.js +4 -0
  28. package/dist/esm/crypto-error.js.map +1 -1
  29. package/dist/esm/index.js +9 -0
  30. package/dist/esm/index.js.map +1 -1
  31. package/dist/esm/local-key-manager.js +6 -1
  32. package/dist/esm/local-key-manager.js.map +1 -1
  33. package/dist/esm/primitives/ecies-secp256k1.js +79 -0
  34. package/dist/esm/primitives/ecies-secp256k1.js.map +1 -0
  35. package/dist/esm/primitives/x25519.js +9 -16
  36. package/dist/esm/primitives/x25519.js.map +1 -1
  37. package/dist/esm/utils.js +30 -0
  38. package/dist/esm/utils.js.map +1 -1
  39. package/dist/types/algorithms/aes-ctr.d.ts +1 -1
  40. package/dist/types/algorithms/aes-gcm.d.ts +23 -3
  41. package/dist/types/algorithms/aes-gcm.d.ts.map +1 -1
  42. package/dist/types/algorithms/aes-kw.d.ts +129 -0
  43. package/dist/types/algorithms/aes-kw.d.ts.map +1 -0
  44. package/dist/types/algorithms/ecdsa.d.ts +48 -3
  45. package/dist/types/algorithms/ecdsa.d.ts.map +1 -1
  46. package/dist/types/algorithms/eddsa.d.ts +48 -3
  47. package/dist/types/algorithms/eddsa.d.ts.map +1 -1
  48. package/dist/types/algorithms/hkdf.d.ts +35 -0
  49. package/dist/types/algorithms/hkdf.d.ts.map +1 -0
  50. package/dist/types/algorithms/pbkdf2.d.ts +35 -0
  51. package/dist/types/algorithms/pbkdf2.d.ts.map +1 -0
  52. package/dist/types/algorithms/sha-2.d.ts +1 -1
  53. package/dist/types/algorithms/x25519.d.ts +76 -0
  54. package/dist/types/algorithms/x25519.d.ts.map +1 -0
  55. package/dist/types/cose/cbor.d.ts +30 -0
  56. package/dist/types/cose/cbor.d.ts.map +1 -0
  57. package/dist/types/cose/cose-key.d.ts +106 -0
  58. package/dist/types/cose/cose-key.d.ts.map +1 -0
  59. package/dist/types/cose/cose-sign1.d.ts +195 -0
  60. package/dist/types/cose/cose-sign1.d.ts.map +1 -0
  61. package/dist/types/cose/eat.d.ts +203 -0
  62. package/dist/types/cose/eat.d.ts.map +1 -0
  63. package/dist/types/crypto-error.d.ts +4 -0
  64. package/dist/types/crypto-error.d.ts.map +1 -1
  65. package/dist/types/index.d.ts +9 -0
  66. package/dist/types/index.d.ts.map +1 -1
  67. package/dist/types/local-key-manager.d.ts +4 -4
  68. package/dist/types/local-key-manager.d.ts.map +1 -1
  69. package/dist/types/primitives/ecies-secp256k1.d.ts +53 -0
  70. package/dist/types/primitives/ecies-secp256k1.d.ts.map +1 -0
  71. package/dist/types/primitives/x25519.d.ts +9 -16
  72. package/dist/types/primitives/x25519.d.ts.map +1 -1
  73. package/dist/types/types/crypto-api.d.ts +52 -4
  74. package/dist/types/types/crypto-api.d.ts.map +1 -1
  75. package/dist/types/types/key-converter.d.ts +37 -15
  76. package/dist/types/types/key-converter.d.ts.map +1 -1
  77. package/dist/types/types/key-deriver.d.ts +41 -0
  78. package/dist/types/types/key-deriver.d.ts.map +1 -1
  79. package/dist/types/types/key-io.d.ts +37 -0
  80. package/dist/types/types/key-io.d.ts.map +1 -1
  81. package/dist/types/types/params-direct.d.ts +17 -0
  82. package/dist/types/types/params-direct.d.ts.map +1 -1
  83. package/dist/types/types/params-kms.d.ts +55 -0
  84. package/dist/types/types/params-kms.d.ts.map +1 -1
  85. package/dist/types/utils.d.ts +19 -0
  86. package/dist/types/utils.d.ts.map +1 -1
  87. package/dist/utils.js +1 -1
  88. package/dist/utils.js.map +3 -3
  89. package/package.json +12 -14
  90. package/src/algorithms/aes-ctr.ts +1 -1
  91. package/src/algorithms/aes-gcm.ts +38 -2
  92. package/src/algorithms/aes-kw.ts +182 -0
  93. package/src/algorithms/ecdsa.ts +132 -1
  94. package/src/algorithms/eddsa.ts +108 -1
  95. package/src/algorithms/hkdf.ts +54 -0
  96. package/src/algorithms/pbkdf2.ts +57 -0
  97. package/src/algorithms/sha-2.ts +1 -1
  98. package/src/algorithms/x25519.ts +153 -0
  99. package/src/cose/cbor.ts +36 -0
  100. package/src/cose/cose-key.ts +344 -0
  101. package/src/cose/cose-sign1.ts +473 -0
  102. package/src/cose/eat.ts +368 -0
  103. package/src/crypto-error.ts +6 -0
  104. package/src/index.ts +10 -0
  105. package/src/local-key-manager.ts +9 -4
  106. package/src/primitives/ecies-secp256k1.ts +113 -0
  107. package/src/primitives/x25519.ts +9 -16
  108. package/src/types/crypto-api.ts +124 -6
  109. package/src/types/key-converter.ts +33 -7
  110. package/src/types/key-deriver.ts +49 -0
  111. package/src/types/key-io.ts +40 -0
  112. package/src/types/params-direct.ts +21 -0
  113. package/src/types/params-kms.ts +67 -0
  114. package/src/utils.ts +53 -0
  115. package/dist/browser.js +0 -60
  116. package/dist/browser.js.map +0 -7
@@ -16,7 +16,7 @@ import { CryptoAlgorithm } from './crypto-algorithm.js';
16
16
  * decryption features.
17
17
  *
18
18
  * This class is typically accessed through implementations that extend the
19
- * {@link CryptoApi | `CryptoApi`} interface.
19
+ * {@link DsaApi | `DsaApi`} interface.
20
20
  */
21
21
  export class AesCtrAlgorithm extends CryptoAlgorithm {
22
22
  /**
@@ -16,9 +16,27 @@ import { CryptoAlgorithm } from './crypto-algorithm.js';
16
16
  * key generation, encryption, and decryption features.
17
17
  *
18
18
  * This class is typically accessed through implementations that extend the
19
- * {@link CryptoApi | `CryptoApi`} interface.
19
+ * {@link DsaApi | `DsaApi`} interface.
20
20
  */
21
21
  export class AesGcmAlgorithm extends CryptoAlgorithm {
22
+ /**
23
+ * Converts a private key from a byte array to JWK format, setting the `alg` property based on
24
+ * the key length.
25
+ *
26
+ * @param params - The parameters for the private key conversion.
27
+ * @param params.privateKeyBytes - The raw private key as a Uint8Array.
28
+ *
29
+ * @returns A Promise that resolves to the private key in JWK format.
30
+ */
31
+ bytesToPrivateKey(_a) {
32
+ return __awaiter(this, arguments, void 0, function* ({ privateKeyBytes }) {
33
+ // Convert the byte array to a JWK.
34
+ const privateKey = yield AesGcm.bytesToPrivateKey({ privateKeyBytes });
35
+ // Set the `alg` property based on the key length.
36
+ privateKey.alg = { 16: 'A128GCM', 24: 'A192GCM', 32: 'A256GCM' }[privateKeyBytes.length];
37
+ return privateKey;
38
+ });
39
+ }
22
40
  /**
23
41
  * Decrypts the provided data using AES-GCM.
24
42
  *
@@ -128,5 +146,20 @@ export class AesGcmAlgorithm extends CryptoAlgorithm {
128
146
  return privateKey;
129
147
  });
130
148
  }
149
+ /**
150
+ * Converts a private key from JWK format to a byte array.
151
+ *
152
+ * @param params - The parameters for the private key conversion.
153
+ * @param params.privateKey - The private key in JWK format.
154
+ *
155
+ * @returns A Promise that resolves to the private key as a Uint8Array.
156
+ */
157
+ privateKeyToBytes(_a) {
158
+ return __awaiter(this, arguments, void 0, function* ({ privateKey }) {
159
+ // Convert the JWK to a byte array.
160
+ const privateKeyBytes = yield AesGcm.privateKeyToBytes({ privateKey });
161
+ return privateKeyBytes;
162
+ });
163
+ }
131
164
  }
132
165
  //# sourceMappingURL=aes-gcm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"aes-gcm.js","sourceRoot":"","sources":["../../../src/algorithms/aes-gcm.ts"],"names":[],"mappings":";;;;;;;;;AAMA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAmDxD;;;;;;;;GAQG;AACH,MAAM,OAAO,eAAgB,SAAQ,eAAe;IAIlD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACU,OAAO,CAAC,MACS;;YAE5B,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAEzC,OAAO,SAAS,CAAC;QACnB,CAAC;KAAA;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACU,OAAO,CAAC,MACS;;YAE5B,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAE1C,OAAO,UAAU,CAAC;QACpB,CAAC;KAAA;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACU,WAAW;6DAAC,EAAE,SAAS,EACX;YAEvB,oCAAoC;YACpC,MAAM,MAAM,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,CAAoB,CAAC;YAE1F,iCAAiC;YACjC,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,W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AM,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,CAAoB,CAAC;YAE1F,iCAAiC;YACjC,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;YAExD,2DAA2D;YAC3D,UAAU,CAAC,GAAG,GAAG,SAAS,CAAC;YAE3B,OAAO,UAAU,CAAC;QACpB,CAAC;KAAA;IAED;;;;;;;OAOG;IACU,iBAAiB;6DAAC,EAAE,UAAU,EAA2B;YACpE,mCAAmC;YACnC,MAAM,eAAe,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;YAEvE,OAAO,eAAe,CAAC;QACzB,CAAC;KAAA;CACF"}
@@ -0,0 +1,154 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { AesKw } from '../primitives/aes-kw.js';
11
+ import { CryptoAlgorithm } from './crypto-algorithm.js';
12
+ /**
13
+ * The `AesKwAlgorithm` class provides a concrete implementation for cryptographic operations using
14
+ * the AES algorithm for key wrapping. This class implements both
15
+ * {@link KeyGenerator | `KeyGenerator`} and {@link KeyWrapper | `KeyWrapper`} interfaces, providing
16
+ * key generation, key wrapping, and key unwrapping features.
17
+ *
18
+ * This class is typically accessed through implementations that extend the
19
+ * {@link DsaApi | `DsaApi`} interface.
20
+ */
21
+ export class AesKwAlgorithm extends CryptoAlgorithm {
22
+ /**
23
+ * Converts a private key from a byte array to JWK format, setting the `alg` property based on
24
+ * the key length.
25
+ *
26
+ * @param params - The parameters for the private key conversion.
27
+ * @param params.privateKeyBytes - The raw private key as a Uint8Array.
28
+ *
29
+ * @returns A Promise that resolves to the private key in JWK format.
30
+ */
31
+ bytesToPrivateKey(_a) {
32
+ return __awaiter(this, arguments, void 0, function* ({ privateKeyBytes }) {
33
+ // Convert the byte array to a JWK.
34
+ const privateKey = yield AesKw.bytesToPrivateKey({ privateKeyBytes });
35
+ // Set the `alg` property based on the key length.
36
+ privateKey.alg = { 16: 'A128KW', 24: 'A192KW', 32: 'A256KW' }[privateKeyBytes.length];
37
+ return privateKey;
38
+ });
39
+ }
40
+ /**
41
+ * Generates a symmetric key for AES for key wrapping in JSON Web Key (JWK) format.
42
+ *
43
+ * @remarks
44
+ * This method generates a symmetric AES key for use in key wrapping mode, based on the specified
45
+ * `algorithm` parameter which determines the key length. It uses cryptographically secure random
46
+ * number generation to ensure the uniqueness and security of the key. The key is returned in JWK
47
+ * format.
48
+ *
49
+ * The generated key includes the following components:
50
+ * - `kty`: Key Type, set to 'oct' for Octet Sequence.
51
+ * - `k`: The symmetric key component, base64url-encoded.
52
+ * - `kid`: Key ID, generated based on the JWK thumbprint.
53
+ * - `alg`: Algorithm, set to 'A128KW', 'A192KW', or 'A256KW' for AES Key Wrap with the
54
+ * specified key length.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * const aesKw = new AesKwAlgorithm();
59
+ * const privateKey = await aesKw.generateKey({ algorithm: 'A256KW' });
60
+ * ```
61
+ *
62
+ * @param params - The parameters for the key generation.
63
+ *
64
+ * @returns A Promise that resolves to the generated symmetric key in JWK format.
65
+ */
66
+ generateKey(_a) {
67
+ return __awaiter(this, arguments, void 0, function* ({ algorithm }) {
68
+ // Map algorithm name to key length.
69
+ const length = { A128KW: 128, A192KW: 192, A256KW: 256 }[algorithm];
70
+ // Generate a random private key.
71
+ const privateKey = yield AesKw.generateKey({ length });
72
+ // Set the `alg` property based on the specified algorithm.
73
+ privateKey.alg = algorithm;
74
+ return privateKey;
75
+ });
76
+ }
77
+ /**
78
+ * Converts a private key from JWK format to a byte array.
79
+ *
80
+ * @param params - The parameters for the private key conversion.
81
+ * @param params.privateKey - The private key in JWK format.
82
+ *
83
+ * @returns A Promise that resolves to the private key as a Uint8Array.
84
+ */
85
+ privateKeyToBytes(_a) {
86
+ return __awaiter(this, arguments, void 0, function* ({ privateKey }) {
87
+ // Convert the JWK to a byte array.
88
+ const privateKeyBytes = yield AesKw.privateKeyToBytes({ privateKey });
89
+ return privateKeyBytes;
90
+ });
91
+ }
92
+ /**
93
+ * Decrypts a wrapped key using the AES Key Wrap algorithm.
94
+ *
95
+ * @remarks
96
+ * This method unwraps a previously wrapped cryptographic key using the AES Key Wrap algorithm.
97
+ * The wrapped key, provided as a byte array, is unwrapped using the decryption key specified in
98
+ * the parameters.
99
+ *
100
+ * This operation is useful for securely receiving keys transmitted over untrusted mediums. The
101
+ * method returns the unwrapped key as a JSON Web Key (JWK).
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * const aesKw = new AesKwAlgorithm();
106
+ * const wrappedKeyBytes = new Uint8Array([...]); // Byte array of a wrapped AES-256 GCM key
107
+ * const decryptionKey = { ... }; // A Jwk object representing the AES unwrapping key
108
+ * const unwrappedKey = await aesKw.unwrapKey({
109
+ * wrappedKeyBytes,
110
+ * wrappedKeyAlgorithm: 'A256GCM',
111
+ * decryptionKey
112
+ * });
113
+ * ```
114
+ *
115
+ * @param params - The parameters for the key unwrapping operation.
116
+ *
117
+ * @returns A Promise that resolves to the unwrapped key in JWK format.
118
+ */
119
+ unwrapKey(params) {
120
+ return __awaiter(this, void 0, void 0, function* () {
121
+ const unwrappedKey = yield AesKw.unwrapKey(params);
122
+ return unwrappedKey;
123
+ });
124
+ }
125
+ /**
126
+ * Encrypts a given key using the AES Key Wrap algorithm.
127
+ *
128
+ * @remarks
129
+ * This method wraps a given cryptographic key using the AES Key Wrap algorithm. The private key
130
+ * to be wrapped is provided in the form of a JSON Web Key (JWK).
131
+ *
132
+ * This operation is useful for securely transmitting keys over untrusted mediums. The method
133
+ * returns the wrapped key as a byte array.
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * const aesKw = new AesKwAlgorithm();
138
+ * const unwrappedKey = { ... }; // A Jwk object representing the key to be wrapped
139
+ * const encryptionKey = { ... }; // A Jwk object representing the AES wrapping key
140
+ * const wrappedKeyBytes = await aesKw.wrapKey({ unwrappedKey, encryptionKey });
141
+ * ```
142
+ *
143
+ * @param params - The parameters for the key wrapping operation.
144
+ *
145
+ * @returns A Promise that resolves to the wrapped key as a Uint8Array.
146
+ */
147
+ wrapKey(params) {
148
+ return __awaiter(this, void 0, void 0, function* () {
149
+ const wrappedKeyBytes = AesKw.wrapKey(params);
150
+ return wrappedKeyBytes;
151
+ });
152
+ }
153
+ }
154
+ //# sourceMappingURL=aes-kw.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aes-kw.js","sourceRoot":"","sources":["../../../src/algorithms/aes-kw.ts"],"names":[],"mappings":";;;;;;;;;AAOA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAgBxD;;;;;;;;GAQG;AACH,MAAM,OAAO,cAAe,SAAQ,eAAe;IAKjD;;;;;;;;OAQG;IACU,iBAAiB;6DAAC,EAAE,eAAe,EACS;YAEvD,mCAAmC;YACnC,MAAM,UAAU,GAAG,MAAM,KAAK,CAAC,iBAAiB,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC;YAEtE,kDAAkD;YAClD,UAAU,CAAC,GAAG,GAAG,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;YAEtF,OAAO,UAAU,CAAC;QACpB,CAAC;KAAA;IAED;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACU,WAAW;6DAAC,EAAE,SAAS,EACZ;YAEtB,oCAAoC;YACpC,MAAM,MAAM,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,SAAS,CAAoB,CAAC;YAEvF,iCAAiC;YACjC,MAAM,UAAU,GAAG,MAAM,KAAK,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;YAEvD,2DAA2D;YAC3D,UAAU,CAAC,GAAG,GAAG,SAAS,CAAC;YAE3B,OAAO,UAAU,CAAC;QACpB,CAAC;KAAA;IAED;;;;;;;OAOG;IACU,iBAAiB;6DAAC,EAAE,UAAU,EAClB;YAEvB,mCAAmC;YACnC,MAAM,eAAe,GAAG,MAAM,KAAK,CAAC,iBAAiB,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;YAEtE,OAAO,eAAe,CAAC;QACzB,CAAC;KAAA;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACU,SAAS,CAAC,MACN;;YAEf,MAAM,YAAY,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YAEnD,OAAO,YAAY,CAAC;QACtB,CAAC;KAAA;IAED;;;;;;;;;;;;;;;;;;;;;OAqBG;IACU,OAAO,CAAC,MACN;;YAEb,MAAM,eAAe,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAE9C,OAAO,eAAe,CAAC;QACzB,CAAC;KAAA;CACF"}
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { CryptoAlgorithm } from './crypto-algorithm.js';
11
11
  import { Secp256k1 } from '../primitives/secp256k1.js';
12
12
  import { Secp256r1 } from '../primitives/secp256r1.js';
13
+ import { CryptoError, CryptoErrorCode } from '../crypto-error.js';
13
14
  import { isEcPrivateJwk, isEcPublicJwk } from '../jose/jwk.js';
14
15
  /**
15
16
  * The `EcdsaAlgorithm` class provides a concrete implementation for cryptographic operations using
@@ -19,9 +20,71 @@ import { isEcPrivateJwk, isEcPublicJwk } from '../jose/jwk.js';
19
20
  * of signatures.
20
21
  *
21
22
  * This class is typically accessed through implementations that extend the
22
- * {@link CryptoApi | `CryptoApi`} interface.
23
+ * {@link DsaApi | `DsaApi`} interface.
23
24
  */
24
25
  export class EcdsaAlgorithm extends CryptoAlgorithm {
26
+ /**
27
+ * Converts a private key from a byte array to JWK format, setting the `alg` property based on
28
+ * the algorithm.
29
+ *
30
+ * @param params - The parameters for the private key conversion.
31
+ * @param params.algorithm - The ECDSA algorithm identifier.
32
+ * @param params.privateKeyBytes - The raw private key as a Uint8Array.
33
+ *
34
+ * @returns A Promise that resolves to the private key in JWK format.
35
+ */
36
+ bytesToPrivateKey(_a) {
37
+ return __awaiter(this, arguments, void 0, function* ({ algorithm, privateKeyBytes }) {
38
+ switch (algorithm) {
39
+ case 'ES256K':
40
+ case 'secp256k1': {
41
+ const privateKey = yield Secp256k1.bytesToPrivateKey({ privateKeyBytes });
42
+ privateKey.alg = 'ES256K';
43
+ return privateKey;
44
+ }
45
+ case 'ES256':
46
+ case 'secp256r1': {
47
+ const privateKey = yield Secp256r1.bytesToPrivateKey({ privateKeyBytes });
48
+ privateKey.alg = 'ES256';
49
+ return privateKey;
50
+ }
51
+ default: {
52
+ throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Algorithm not supported: ${algorithm}`);
53
+ }
54
+ }
55
+ });
56
+ }
57
+ /**
58
+ * Converts a public key from a byte array to JWK format, setting the `alg` property based on
59
+ * the algorithm.
60
+ *
61
+ * @param params - The parameters for the public key conversion.
62
+ * @param params.algorithm - The ECDSA algorithm identifier.
63
+ * @param params.publicKeyBytes - The raw public key as a Uint8Array.
64
+ *
65
+ * @returns A Promise that resolves to the public key in JWK format.
66
+ */
67
+ bytesToPublicKey(_a) {
68
+ return __awaiter(this, arguments, void 0, function* ({ algorithm, publicKeyBytes }) {
69
+ switch (algorithm) {
70
+ case 'ES256K':
71
+ case 'secp256k1': {
72
+ const publicKey = yield Secp256k1.bytesToPublicKey({ publicKeyBytes });
73
+ publicKey.alg = 'ES256K';
74
+ return publicKey;
75
+ }
76
+ case 'ES256':
77
+ case 'secp256r1': {
78
+ const publicKey = yield Secp256r1.bytesToPublicKey({ publicKeyBytes });
79
+ publicKey.alg = 'ES256';
80
+ return publicKey;
81
+ }
82
+ default: {
83
+ throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Algorithm not supported: ${algorithm}`);
84
+ }
85
+ }
86
+ });
87
+ }
25
88
  /**
26
89
  * Derives the public key in JWK format from a given private key.
27
90
  *
@@ -237,5 +300,51 @@ export class EcdsaAlgorithm extends CryptoAlgorithm {
237
300
  }
238
301
  });
239
302
  }
303
+ /**
304
+ * Converts a private key from JWK format to a byte array.
305
+ *
306
+ * @param params - The parameters for the private key conversion.
307
+ * @param params.privateKey - The private key in JWK format.
308
+ *
309
+ * @returns A Promise that resolves to the private key as a Uint8Array.
310
+ */
311
+ privateKeyToBytes(_a) {
312
+ return __awaiter(this, arguments, void 0, function* ({ privateKey }) {
313
+ switch (privateKey.crv) {
314
+ case 'secp256k1': {
315
+ return yield Secp256k1.privateKeyToBytes({ privateKey });
316
+ }
317
+ case 'P-256': {
318
+ return yield Secp256r1.privateKeyToBytes({ privateKey });
319
+ }
320
+ default: {
321
+ throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Curve not supported: ${privateKey.crv}`);
322
+ }
323
+ }
324
+ });
325
+ }
326
+ /**
327
+ * Converts a public key from JWK format to a byte array.
328
+ *
329
+ * @param params - The parameters for the public key conversion.
330
+ * @param params.publicKey - The public key in JWK format.
331
+ *
332
+ * @returns A Promise that resolves to the public key as a Uint8Array.
333
+ */
334
+ publicKeyToBytes(_a) {
335
+ return __awaiter(this, arguments, void 0, function* ({ publicKey }) {
336
+ switch (publicKey.crv) {
337
+ case 'secp256k1': {
338
+ return yield Secp256k1.publicKeyToBytes({ publicKey });
339
+ }
340
+ case 'P-256': {
341
+ return yield Secp256r1.publicKeyToBytes({ publicKey });
342
+ }
343
+ default: {
344
+ throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Curve not supported: ${publicKey.crv}`);
345
+ }
346
+ }
347
+ });
348
+ }
240
349
  }
241
350
  //# sourceMappingURL=ecdsa.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ecdsa.js","sourceRoot":"","sources":["../../../src/algorithms/ecdsa.ts"],"names":[],"mappings":";;;;;;;;;AAWA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAiB/D;;;;;;;;;GASG;AACH,MAAM,OAAO,cAAe,SAAQ,eAAe;IAIjD;;;;;;;;;;;;;;;;;;;OAmBG;IACU,gBAAgB;6DAAC,EAAE,GAAG,EACX;YAEtB,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;gBAAA,MAAM,IAAI,SAAS,CAAC,mEAAmE,CAAC,CAAC;YAAA,CAAC;YAErH,QAAQ,GAAG,CAAC,GAAG,EAAE,CAAC;gBAEhB,KAAK,WAAW,CAAC,CAAC,CAAC;oBACjB,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,gBAAgB,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;oBAC5D,SAAS,CAAC,GAAG,GAAG,QAAQ,CAAC;oBACzB,OAAO,SAAS,CAAC;gBACnB,CAAC;gBAED,KAAK,OAAO,CAAC,CAAC,CAAC;oBACb,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,gBAAgB,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;oBAC5D,SAAS,CAAC,GAAG,GAAG,OAAO,CAAC;oBACx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gBAC3D,CAAC;gBAED,OAAO,CAAC,CAAC,CAAC;oBACR,MAAM,IAAI,WAAW,CAAC,eAAe,CAAC,qBAAqB,EAAE,wBAAwB,UAAU,CAAC,GAAG,EAAE,CAAC,CAAC;gBACzG,CAAC;YACH,CAAC;QACH,CAAC;KAAA;IAED;;;;;;;OAOG;IACU,gBAAgB;6DAAC,EAAE,SAAS,EACjB;YAEtB,QAAQ,SAAS,CAAC,GAAG,EAAE,CAAC;gBAEtB,KAAK,WAAW,CAAC,CAAC,CAAC;oBACjB,OAAO,MAAM,SAAS,CAAC,gBAAgB,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;gBACzD,CAAC;gBAED,KAAK,OAAO,CAAC,CAAC,CAAC;oBACb,OAAO,MAAM,SAAS,CAAC,gBAAgB,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;gBACzD,CAAC;gBAED,OAAO,CAAC,CAAC,CAAC;oBACR,MAAM,IAAI,WAAW,CAAC,eAAe,CAAC,qBAAqB,EAAE,wBAAwB,SAAS,CAAC,GAAG,EAAE,CAAC,CAAC;gBACxG,CAAC;YACH,CAAC;QACH,CAAC;KAAA;CACF"}
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { CryptoAlgorithm } from './crypto-algorithm.js';
11
11
  import { Ed25519 } from '../primitives/ed25519.js';
12
+ import { CryptoError, CryptoErrorCode } from '../crypto-error.js';
12
13
  import { isOkpPrivateJwk, isOkpPublicJwk } from '../jose/jwk.js';
13
14
  /**
14
15
  * The `EdDsaAlgorithm` class provides a concrete implementation for cryptographic operations using
@@ -18,9 +19,57 @@ import { isOkpPrivateJwk, isOkpPublicJwk } from '../jose/jwk.js';
18
19
  * of signatures.
19
20
  *
20
21
  * This class is typically accessed through implementations that extend the
21
- * {@link CryptoApi | `CryptoApi`} interface.
22
+ * {@link DsaApi | `DsaApi`} interface.
22
23
  */
23
24
  export class EdDsaAlgorithm extends CryptoAlgorithm {
25
+ /**
26
+ * Converts a private key from a byte array to JWK format, setting the `alg` property to
27
+ * `'EdDSA'`.
28
+ *
29
+ * @param params - The parameters for the private key conversion.
30
+ * @param params.algorithm - The EdDSA algorithm identifier (`'Ed25519'`).
31
+ * @param params.privateKeyBytes - The raw private key as a Uint8Array.
32
+ *
33
+ * @returns A Promise that resolves to the private key in JWK format.
34
+ */
35
+ bytesToPrivateKey(_a) {
36
+ return __awaiter(this, arguments, void 0, function* ({ algorithm, privateKeyBytes }) {
37
+ switch (algorithm) {
38
+ case 'Ed25519': {
39
+ const privateKey = yield Ed25519.bytesToPrivateKey({ privateKeyBytes });
40
+ privateKey.alg = 'EdDSA';
41
+ return privateKey;
42
+ }
43
+ default: {
44
+ throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Algorithm not supported: ${algorithm}`);
45
+ }
46
+ }
47
+ });
48
+ }
49
+ /**
50
+ * Converts a public key from a byte array to JWK format, setting the `alg` property to
51
+ * `'EdDSA'`.
52
+ *
53
+ * @param params - The parameters for the public key conversion.
54
+ * @param params.algorithm - The EdDSA algorithm identifier (`'Ed25519'`).
55
+ * @param params.publicKeyBytes - The raw public key as a Uint8Array.
56
+ *
57
+ * @returns A Promise that resolves to the public key in JWK format.
58
+ */
59
+ bytesToPublicKey(_a) {
60
+ return __awaiter(this, arguments, void 0, function* ({ algorithm, publicKeyBytes }) {
61
+ switch (algorithm) {
62
+ case 'Ed25519': {
63
+ const publicKey = yield Ed25519.bytesToPublicKey({ publicKeyBytes });
64
+ publicKey.alg = 'EdDSA';
65
+ return publicKey;
66
+ }
67
+ default: {
68
+ throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Algorithm not supported: ${algorithm}`);
69
+ }
70
+ }
71
+ });
72
+ }
24
73
  /**
25
74
  * Derives the public key in JWK format from a given private key.
26
75
  *
@@ -213,5 +262,45 @@ export class EdDsaAlgorithm extends CryptoAlgorithm {
213
262
  }
214
263
  });
215
264
  }
265
+ /**
266
+ * Converts a private key from JWK format to a byte array.
267
+ *
268
+ * @param params - The parameters for the private key conversion.
269
+ * @param params.privateKey - The private key in JWK format.
270
+ *
271
+ * @returns A Promise that resolves to the private key as a Uint8Array.
272
+ */
273
+ privateKeyToBytes(_a) {
274
+ return __awaiter(this, arguments, void 0, function* ({ privateKey }) {
275
+ switch (privateKey.crv) {
276
+ case 'Ed25519': {
277
+ return yield Ed25519.privateKeyToBytes({ privateKey });
278
+ }
279
+ default: {
280
+ throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Curve not supported: ${privateKey.crv}`);
281
+ }
282
+ }
283
+ });
284
+ }
285
+ /**
286
+ * Converts a public key from JWK format to a byte array.
287
+ *
288
+ * @param params - The parameters for the public key conversion.
289
+ * @param params.publicKey - The public key in JWK format.
290
+ *
291
+ * @returns A Promise that resolves to the public key as a Uint8Array.
292
+ */
293
+ publicKeyToBytes(_a) {
294
+ return __awaiter(this, arguments, void 0, function* ({ publicKey }) {
295
+ switch (publicKey.crv) {
296
+ case 'Ed25519': {
297
+ return yield Ed25519.publicKeyToBytes({ publicKey });
298
+ }
299
+ default: {
300
+ throw new CryptoError(CryptoErrorCode.AlgorithmNotSupported, `Curve not supported: ${publicKey.crv}`);
301
+ }
302
+ }
303
+ });
304
+ }
216
305
  }
217
306
  //# sourceMappingURL=eddsa.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"eddsa.js","sourceRoot":"","sources":["../../../src/algorithms/eddsa.ts"],"names":[],"mappings":";;;;;;;;;AAWA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAcjE;;;;;;;;;GASG;AACH,MAAM,OAAO,cAAe,SAAQ,eAAe;IAIjD;;;;;;;;;;;;;;;;;;;OAmBG;IACU,gBAAgB;6DAAC,EAAE,GAAG,EACX;YAEtB,IAAI,CA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CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;gBACxD,CAAC;gBAED,OAAO,CAAC,CAAC,CAAC;oBACR,MAAM,IAAI,KAAK,CAAC,sBAAsB,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;gBACnD,CAAC;YACH,CAAC;QACH,CAAC;KAAA;IAED;;;;;;;OAOG;IACU,iBAAiB;6DAAC,EAAE,UAAU,EAClB;YAEvB,QAAQ,UAAU,CAAC,GAAG,EAAE,CAAC;gBAEvB,KAAK,SAAS,CAAC,CAAC,CAAC;oBACf,OAAO,MAAM,OAAO,CAAC,iBAAiB,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;gBACzD,CAAC;gBAED,OAAO,CAAC,CAAC,CAAC;oBACR,MAAM,IAAI,WAAW,CAAC,eAAe,CAAC,qBAAqB,EAAE,wBAAwB,UAAU,CAAC,GAAG,EAAE,CAAC,CAAC;gBACzG,CAAC;YACH,CAAC;QACH,CAAC;KAAA;IAED;;;;;;;OAOG;IACU,gBAAgB;6DAAC,EAAE,SAAS,EACjB;YAEtB,QAAQ,SAAS,CAAC,GAAG,EAAE,CAAC;gBAEtB,KAAK,SAAS,CAAC,CAAC,CAAC;oBACf,OAAO,MAAM,OAAO,CAAC,gBAAgB,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;gBACvD,CAAC;gBAED,OAAO,CAAC,CAAC,CAAC;oBACR,MAAM,IAAI,WAAW,CAAC,eAAe,CAAC,qBAAqB,EAAE,wBAAwB,SAAS,CAAC,GAAG,EAAE,CAAC,CAAC;gBACxG,CAAC;YACH,CAAC;QACH,CAAC;KAAA;CACF"}
@@ -0,0 +1,53 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
21
+ import { CryptoAlgorithm } from './crypto-algorithm.js';
22
+ import { Hkdf } from '../primitives/hkdf.js';
23
+ /**
24
+ * The `HkdfAlgorithm` class provides a concrete implementation for HKDF key derivation. It wraps
25
+ * the {@link Hkdf} primitive and maps JOSE algorithm names to hash functions.
26
+ */
27
+ export class HkdfAlgorithm extends CryptoAlgorithm {
28
+ /**
29
+ * Derives a cryptographic byte array using HKDF.
30
+ *
31
+ * @param params - The parameters for the key derivation operation.
32
+ * @param params.algorithm - The HKDF algorithm variant (e.g., `'HKDF-256'`).
33
+ * @param params.baseKeyBytes - The input key material.
34
+ * @param params.length - The desired length of the output in bits.
35
+ *
36
+ * @returns A Promise that resolves to the derived key bytes.
37
+ */
38
+ deriveKeyBytes(_a) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ var { algorithm } = _a, params = __rest(_a, ["algorithm"]);
41
+ // Map algorithm name to hash function.
42
+ const hash = {
43
+ 'HKDF-256': 'SHA-256',
44
+ 'HKDF-384': 'SHA-384',
45
+ 'HKDF-512': 'SHA-512'
46
+ }[algorithm];
47
+ // Derive a cryptographic byte array using HKDF.
48
+ const derivedKeyBytes = yield Hkdf.deriveKeyBytes(Object.assign(Object.assign({}, params), { hash }));
49
+ return derivedKeyBytes;
50
+ });
51
+ }
52
+ }
53
+ //# sourceMappingURL=hkdf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hkdf.js","sourceRoot":"","sources":["../../../src/algorithms/hkdf.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAgB7C;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,eAAe;IAGhD;;;;;;;;;OASG;IACU,cAAc,CAAC,EACyB;;gBADzB,EAAE,SAAS,OACc,EADT,MAAM,cAAtB,aAAwB,CAAF;YAGhD,uCAAuC;YACvC,MAAM,IAAI,GAAG;gBACX,UAAU,EAAG,SAAkB;gBAC/B,UAAU,EAAG,SAAkB;gBAC/B,UAAU,EAAG,SAAkB;aAChC,CAAC,SAAS,CAAC,CAAC;YAEb,gDAAgD;YAChD,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,cAAc,iCAAM,MAAM,KAAE,IAAI,IAAG,CAAC;YAEvE,OAAO,eAAe,CAAC;QACzB,CAAC;KAAA;CACF"}
@@ -0,0 +1,55 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
21
+ import { CryptoAlgorithm } from './crypto-algorithm.js';
22
+ import { Pbkdf2 } from '../primitives/pbkdf2.js';
23
+ /**
24
+ * The `Pbkdf2Algorithm` class provides a concrete implementation for PBKDF2 key derivation. It
25
+ * wraps the {@link Pbkdf2} primitive and maps PBES2 JOSE algorithm names to hash functions.
26
+ */
27
+ export class Pbkdf2Algorithm extends CryptoAlgorithm {
28
+ /**
29
+ * Derives a cryptographic byte array using PBKDF2.
30
+ *
31
+ * @param params - The parameters for the key derivation operation.
32
+ * @param params.algorithm - The PBES2 algorithm variant (e.g., `'PBES2-HS512+A256KW'`).
33
+ * @param params.baseKeyBytes - The password or passphrase as bytes.
34
+ * @param params.length - The desired length of the output in bits.
35
+ *
36
+ * @returns A Promise that resolves to the derived key bytes.
37
+ */
38
+ deriveKeyBytes(_a) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ var { algorithm } = _a, params = __rest(_a, ["algorithm"]);
41
+ // Extract the hash function component of the `algorithm` parameter.
42
+ const [, hashFunction] = algorithm.split(/[-+]/);
43
+ // Map from JOSE algorithm name to "SHA" hash function identifier.
44
+ const hash = {
45
+ 'HS256': 'SHA-256',
46
+ 'HS384': 'SHA-384',
47
+ 'HS512': 'SHA-512'
48
+ }[hashFunction];
49
+ // Derive a cryptographic byte array using PBKDF2.
50
+ const derivedKeyBytes = yield Pbkdf2.deriveKeyBytes(Object.assign(Object.assign({}, params), { hash }));
51
+ return derivedKeyBytes;
52
+ });
53
+ }
54
+ }
55
+ //# sourceMappingURL=pbkdf2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pbkdf2.js","sourceRoot":"","sources":["../../../src/algorithms/pbkdf2.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAgBjD;;;GAGG;AACH,MAAM,OAAO,eAAgB,SAAQ,eAAe;IAGlD;;;;;;;;;OASG;IACU,cAAc,CAAC,EAC6B;;gBAD7B,EAAE,SAAS,OACkB,EADb,MAAM,cAAtB,aAAwB,CAAF;YAGhD,oEAAoE;YACpE,MAAM,CAAC,EAAE,YAAY,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YAEjD,kEAAkE;YAClE,MAAM,IAAI,GAAG;gBACX,OAAO,EAAG,SAAkB;gBAC5B,OAAO,EAAG,SAAkB;gBAC5B,OAAO,EAAG,SAAkB;aAC7B,CAAC,YAAY,CAAE,CAAC;YAEjB,kDAAkD;YAClD,MAAM,eAAe,GAAG,MAAM,MAAM,CAAC,cAAc,iCAAM,MAAM,KAAE,IAAI,IAAG,CAAC;YAEzE,OAAO,eAAe,CAAC;QACzB,CAAC;KAAA;CACF"}
@@ -15,7 +15,7 @@ import { Sha256 } from '../primitives/sha256.js';
15
15
  * of the hash function and arbitrary data as input and returns the hash digest of the data.
16
16
  *
17
17
  * This class is typically accessed through implementations that extend the
18
- * {@link CryptoApi | `CryptoApi`} interface.
18
+ * {@link DsaApi | `DsaApi`} interface.
19
19
  */
20
20
  export class Sha2Algorithm extends CryptoAlgorithm {
21
21
  /**