@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,325 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
- return new (P || (P = Promise))(function (resolve, reject) {
20
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
- step((generator = generator.apply(thisArg, _arguments || [])).next());
24
- });
25
- };
26
- var __generator = (this && this.__generator) || function (thisArg, body) {
27
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
- function verb(n) { return function (v) { return step([n, v]); }; }
30
- function step(op) {
31
- if (f) throw new TypeError("Generator is already executing.");
32
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
- if (y = 0, t) op = [op[0] & 2, t.value];
35
- switch (op[0]) {
36
- case 0: case 1: t = op; break;
37
- case 4: _.label++; return { value: op[1], done: false };
38
- case 5: _.label++; y = op[1]; op = [0]; continue;
39
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
- default:
41
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
- if (t[2]) _.ops.pop();
46
- _.trys.pop(); continue;
47
- }
48
- op = body.call(thisArg, _);
49
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
- }
52
- };
53
- Object.defineProperty(exports, "__esModule", { value: true });
54
- exports.EdDsaAlgorithm = void 0;
55
- var ed25519_js_1 = require("../primitives/ed25519.js");
56
- var crypto_algorithm_js_1 = require("./crypto-algorithm.js");
57
- var jwk_js_1 = require("../jose/jwk.js");
58
- /**
59
- * The `EdDsaAlgorithm` class provides a concrete implementation for cryptographic operations using
60
- * the Edwards-curve Digital Signature Algorithm (EdDSA). This class implements both
61
- * {@link Signer | `Signer`} and { @link AsymmetricKeyGenerator | `AsymmetricKeyGenerator`}
62
- * interfaces, providing private key generation, public key derivation, and creation/verification
63
- * of signatures.
64
- *
65
- * This class is typically accessed through implementations that extend the
66
- * {@link CryptoApi | `CryptoApi`} interface.
67
- */
68
- var EdDsaAlgorithm = /** @class */ (function (_super) {
69
- __extends(EdDsaAlgorithm, _super);
70
- function EdDsaAlgorithm() {
71
- return _super !== null && _super.apply(this, arguments) || this;
72
- }
73
- /**
74
- * Derives the public key in JWK format from a given private key.
75
- *
76
- * @remarks
77
- * This method takes a private key in JWK format and derives its corresponding public key,
78
- * also in JWK format. The process ensures that the derived public key correctly corresponds to
79
- * the given private key.
80
- *
81
- * @example
82
- * ```ts
83
- * const eddsa = new EdDsaAlgorithm();
84
- * const privateKey = { ... }; // A Jwk object representing a private key
85
- * const publicKey = await eddsa.computePublicKey({ key: privateKey });
86
- * ```
87
- *
88
- * @param params - The parameters for the public key derivation.
89
- * @param params.key - The private key in JWK format from which to derive the public key.
90
- *
91
- * @returns A Promise that resolves to the derived public key in JWK format.
92
- */
93
- EdDsaAlgorithm.prototype.computePublicKey = function (_a) {
94
- return __awaiter(this, arguments, void 0, function (_b) {
95
- var _c, publicKey;
96
- var key = _b.key;
97
- return __generator(this, function (_d) {
98
- switch (_d.label) {
99
- case 0:
100
- if (!(0, jwk_js_1.isOkpPrivateJwk)(key))
101
- throw new TypeError('Invalid key provided. Must be an octet key pair (OKP) private key.');
102
- _c = key.crv;
103
- switch (_c) {
104
- case 'Ed25519': return [3 /*break*/, 1];
105
- }
106
- return [3 /*break*/, 3];
107
- case 1: return [4 /*yield*/, ed25519_js_1.Ed25519.computePublicKey({ key: key })];
108
- case 2:
109
- publicKey = _d.sent();
110
- publicKey.alg = 'EdDSA';
111
- return [2 /*return*/, publicKey];
112
- case 3:
113
- {
114
- throw new Error("Unsupported curve: ".concat(key.crv));
115
- }
116
- _d.label = 4;
117
- case 4: return [2 /*return*/];
118
- }
119
- });
120
- });
121
- };
122
- /**
123
- * Generates a new private key with the specified algorithm in JSON Web Key (JWK) format.
124
- *
125
- * @example
126
- * ```ts
127
- * const eddsa = new EdDsaAlgorithm();
128
- * const privateKey = await eddsa.generateKey({ algorithm: 'Ed25519' });
129
- * ```
130
- *
131
- * @param params - The parameters for key generation.
132
- * @param params.algorithm - The algorithm to use for key generation.
133
- *
134
- * @returns A Promise that resolves to the generated private key in JWK format.
135
- */
136
- EdDsaAlgorithm.prototype.generateKey = function (_a) {
137
- return __awaiter(this, arguments, void 0, function (_b) {
138
- var _c, privateKey;
139
- var algorithm = _b.algorithm;
140
- return __generator(this, function (_d) {
141
- switch (_d.label) {
142
- case 0:
143
- _c = algorithm;
144
- switch (_c) {
145
- case 'Ed25519': return [3 /*break*/, 1];
146
- }
147
- return [3 /*break*/, 3];
148
- case 1: return [4 /*yield*/, ed25519_js_1.Ed25519.generateKey()];
149
- case 2:
150
- privateKey = _d.sent();
151
- privateKey.alg = 'EdDSA';
152
- return [2 /*return*/, privateKey];
153
- case 3: return [2 /*return*/];
154
- }
155
- });
156
- });
157
- };
158
- /**
159
- * Retrieves the public key properties from a given private key in JWK format.
160
- *
161
- * @remarks
162
- * This method extracts the public key portion from an EdDSA private key in JWK format. It does
163
- * so by removing the private key property 'd' and making a shallow copy, effectively yielding the
164
- * public key.
165
- *
166
- * Note: This method offers a significant performance advantage, being about 100 times faster
167
- * than `computePublicKey()`. However, it does not mathematically validate the private key, nor
168
- * does it derive the public key from the private key. It simply extracts existing public key
169
- * properties from the private key object. This makes it suitable for scenarios where speed is
170
- * critical and the private key's integrity is already assured.
171
- *
172
- * @example
173
- * ```ts
174
- * const eddsa = new EdDsaAlgorithm();
175
- * const privateKey = { ... }; // A Jwk object representing a private key
176
- * const publicKey = await eddsa.getPublicKey({ key: privateKey });
177
- * ```
178
- *
179
- * @param params - The parameters for retrieving the public key properties.
180
- * @param params.key - The private key in JWK format.
181
- *
182
- * @returns A Promise that resolves to the public key in JWK format.
183
- */
184
- EdDsaAlgorithm.prototype.getPublicKey = function (_a) {
185
- return __awaiter(this, arguments, void 0, function (_b) {
186
- var _c, publicKey;
187
- var key = _b.key;
188
- return __generator(this, function (_d) {
189
- switch (_d.label) {
190
- case 0:
191
- if (!(0, jwk_js_1.isOkpPrivateJwk)(key))
192
- throw new TypeError('Invalid key provided. Must be an octet key pair (OKP) private key.');
193
- _c = key.crv;
194
- switch (_c) {
195
- case 'Ed25519': return [3 /*break*/, 1];
196
- }
197
- return [3 /*break*/, 3];
198
- case 1: return [4 /*yield*/, ed25519_js_1.Ed25519.getPublicKey({ key: key })];
199
- case 2:
200
- publicKey = _d.sent();
201
- publicKey.alg = 'EdDSA';
202
- return [2 /*return*/, publicKey];
203
- case 3:
204
- {
205
- throw new Error("Unsupported curve: ".concat(key.crv));
206
- }
207
- _d.label = 4;
208
- case 4: return [2 /*return*/];
209
- }
210
- });
211
- });
212
- };
213
- /**
214
- * Generates an EdDSA signature of given data using a private key.
215
- *
216
- * @remarks
217
- * This method uses the signature algorithm determined by the given `algorithm` to sign the
218
- * provided data.
219
- *
220
- * The signature can later be verified by parties with access to the corresponding
221
- * public key, ensuring that the data has not been tampered with and was indeed signed by the
222
- * holder of the private key.
223
- *
224
- * @example
225
- * ```ts
226
- * const eddsa = new EdDsaAlgorithm();
227
- * const data = new TextEncoder().encode('Message');
228
- * const privateKey = { ... }; // A Jwk object representing a private key
229
- * const signature = await eddsa.sign({
230
- * key: privateKey,
231
- * data
232
- * });
233
- * ```
234
- *
235
- * @param params - The parameters for the signing operation.
236
- * @param params.key - The private key to use for signing, represented in JWK format.
237
- * @param params.data - The data to sign.
238
- *
239
- * @returns A Promise resolving to the digital signature as a `Uint8Array`.
240
- */
241
- EdDsaAlgorithm.prototype.sign = function (_a) {
242
- return __awaiter(this, arguments, void 0, function (_b) {
243
- var _c;
244
- var key = _b.key, data = _b.data;
245
- return __generator(this, function (_d) {
246
- switch (_d.label) {
247
- case 0:
248
- if (!(0, jwk_js_1.isOkpPrivateJwk)(key))
249
- throw new TypeError('Invalid key provided. Must be an octet key pair (OKP) private key.');
250
- _c = key.crv;
251
- switch (_c) {
252
- case 'Ed25519': return [3 /*break*/, 1];
253
- }
254
- return [3 /*break*/, 3];
255
- case 1: return [4 /*yield*/, ed25519_js_1.Ed25519.sign({ key: key, data: data })];
256
- case 2: return [2 /*return*/, _d.sent()];
257
- case 3:
258
- {
259
- throw new Error("Unsupported curve: ".concat(key.crv));
260
- }
261
- _d.label = 4;
262
- case 4: return [2 /*return*/];
263
- }
264
- });
265
- });
266
- };
267
- /**
268
- * Verifies an EdDSA signature associated with the provided data using the provided key.
269
- *
270
- * @remarks
271
- * This method uses the signature algorithm determined by the `crv` property of the provided key
272
- * to check the validity of a digital signature against the original data. It confirms whether the
273
- * signature was created by the holder of the corresponding private key and that the data has not
274
- * been tampered with.
275
- *s
276
- * @example
277
- * ```ts
278
- * const eddsa = new EdDsaAlgorithm();
279
- * const publicKey = { ... }; // Public key in JWK format corresponding to the private key that signed the data
280
- * const signature = new Uint8Array([...]); // Signature to verify
281
- * const data = new TextEncoder().encode('Message');
282
- * const isValid = await eddsa.verify({
283
- * key: publicKey,
284
- * signature,
285
- * data
286
- * });
287
- * ```
288
- *
289
- * @param params - The parameters for the verification operation.
290
- * @param params.key - The key to use for verification.
291
- * @param params.signature - The signature to verify.
292
- * @param params.data - The data to verify.
293
- *
294
- * @returns A Promise resolving to a boolean indicating whether the signature is valid.
295
- */
296
- EdDsaAlgorithm.prototype.verify = function (_a) {
297
- return __awaiter(this, arguments, void 0, function (_b) {
298
- var _c;
299
- var key = _b.key, signature = _b.signature, data = _b.data;
300
- return __generator(this, function (_d) {
301
- switch (_d.label) {
302
- case 0:
303
- if (!(0, jwk_js_1.isOkpPublicJwk)(key))
304
- throw new TypeError('Invalid key provided. Must be an octet key pair (OKP) public key.');
305
- _c = key.crv;
306
- switch (_c) {
307
- case 'Ed25519': return [3 /*break*/, 1];
308
- }
309
- return [3 /*break*/, 3];
310
- case 1: return [4 /*yield*/, ed25519_js_1.Ed25519.verify({ key: key, signature: signature, data: data })];
311
- case 2: return [2 /*return*/, _d.sent()];
312
- case 3:
313
- {
314
- throw new Error("Unsupported curve: ".concat(key.crv));
315
- }
316
- _d.label = 4;
317
- case 4: return [2 /*return*/];
318
- }
319
- });
320
- });
321
- };
322
- return EdDsaAlgorithm;
323
- }(crypto_algorithm_js_1.CryptoAlgorithm));
324
- exports.EdDsaAlgorithm = EdDsaAlgorithm;
325
- //# sourceMappingURL=eddsa.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"eddsa.js","sourceRoot":"","sources":["../../../src/algorithms/eddsa.ts"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BAAM,oBAAO,CAAC,MAAM,CAAC,EAAE,GAAG,KAAA,EAAE,SAAS,WAAA,EAAE,IAAI,MAAA,EAAE,CAAC,EAAA;4BAArD,sBAAO,SAA8C,EAAC;;wBAG/C,CAAC;4BACR,MAAM,IAAI,KAAK,CAAC,6BAAsB,GAAG,CAAC,GAAG,CAAE,CAAC,CAAC;wBACnD,CAAC;;;;;;KAEJ;IACH,qBAAC;AAAD,CAAC,AA7MD,CAAoC,qCAAe,GA6MlD;AA7MY,wCAAc"}
@@ -1,119 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
- return new (P || (P = Promise))(function (resolve, reject) {
20
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
- step((generator = generator.apply(thisArg, _arguments || [])).next());
24
- });
25
- };
26
- var __generator = (this && this.__generator) || function (thisArg, body) {
27
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
- function verb(n) { return function (v) { return step([n, v]); }; }
30
- function step(op) {
31
- if (f) throw new TypeError("Generator is already executing.");
32
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
- if (y = 0, t) op = [op[0] & 2, t.value];
35
- switch (op[0]) {
36
- case 0: case 1: t = op; break;
37
- case 4: _.label++; return { value: op[1], done: false };
38
- case 5: _.label++; y = op[1]; op = [0]; continue;
39
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
- default:
41
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
- if (t[2]) _.ops.pop();
46
- _.trys.pop(); continue;
47
- }
48
- op = body.call(thisArg, _);
49
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
- }
52
- };
53
- Object.defineProperty(exports, "__esModule", { value: true });
54
- exports.Sha2Algorithm = void 0;
55
- var sha256_js_1 = require("../primitives/sha256.js");
56
- var crypto_algorithm_js_1 = require("./crypto-algorithm.js");
57
- /**
58
- * The `Sha2Algorithm` class is an implementation of the {@link Hasher | `Hasher`} interface for the
59
- * SHA-2 family of cryptographic hash functions. The `digest` method takes the algorithm identifier
60
- * of the hash function and arbitrary data as input and returns the hash digest of the data.
61
- *
62
- * This class is typically accessed through implementations that extend the
63
- * {@link CryptoApi | `CryptoApi`} interface.
64
- */
65
- var Sha2Algorithm = /** @class */ (function (_super) {
66
- __extends(Sha2Algorithm, _super);
67
- function Sha2Algorithm() {
68
- return _super !== null && _super.apply(this, arguments) || this;
69
- }
70
- /**
71
- * Generates a hash digest of the provided data.
72
- *
73
- * @remarks
74
- * A digest is the output of the hash function. It's a fixed-size string of bytes
75
- * that uniquely represents the data input into the hash function. The digest is often used for
76
- * data integrity checks, as any alteration in the input data results in a significantly
77
- * different digest.
78
- *
79
- * It takes the algorithm identifier of the hash function and data to digest as input and returns
80
- * the digest of the data.
81
- *
82
- * @example
83
- * ```ts
84
- * const sha2 = new Sha2Algorithm();
85
- * const data = new TextEncoder().encode('Messsage');
86
- * const digest = await sha2.digest({ data });
87
- * ```
88
- *
89
- * @param params - The parameters for the digest operation.
90
- * @param params.algorithm - The name of hash function to use.
91
- * @param params.data - The data to digest.
92
- *
93
- * @returns A Promise which will be fulfilled with the hash digest.
94
- */
95
- Sha2Algorithm.prototype.digest = function (_a) {
96
- return __awaiter(this, arguments, void 0, function (_b) {
97
- var _c, hash;
98
- var algorithm = _b.algorithm, data = _b.data;
99
- return __generator(this, function (_d) {
100
- switch (_d.label) {
101
- case 0:
102
- _c = algorithm;
103
- switch (_c) {
104
- case 'SHA-256': return [3 /*break*/, 1];
105
- }
106
- return [3 /*break*/, 3];
107
- case 1: return [4 /*yield*/, sha256_js_1.Sha256.digest({ data: data })];
108
- case 2:
109
- hash = _d.sent();
110
- return [2 /*return*/, hash];
111
- case 3: return [2 /*return*/];
112
- }
113
- });
114
- });
115
- };
116
- return Sha2Algorithm;
117
- }(crypto_algorithm_js_1.CryptoAlgorithm));
118
- exports.Sha2Algorithm = Sha2Algorithm;
119
- //# sourceMappingURL=sha-2.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sha-2.js","sourceRoot":"","sources":["../../../src/algorithms/sha-2.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,qDAAiD;AACjD,6DAAwD;AAcxD;;;;;;;GAOG;AACH;IAAmC,iCAAe;IAAlD;;IAsCA,CAAC;IAnCC;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACU,8BAAM,GAAnB;4DAAoB,EAAqC;;gBAAnC,SAAS,eAAA,EAAE,IAAI,UAAA;;;;wBAC3B,KAAA,SAAS,CAAA;;iCAEV,SAAS,CAAC,CAAV,wBAAS;;;4BACC,qBAAM,kBAAM,CAAC,MAAM,CAAC,EAAE,IAAI,MAAA,EAAE,CAAC,EAAA;;wBAApC,IAAI,GAAG,SAA6B;wBAC1C,sBAAO,IAAI,EAAC;;;;;KAIjB;IACH,oBAAC;AAAD,CAAC,AAtCD,CAAmC,qCAAe,GAsCjD;AAtCY,sCAAa"}
package/dist/cjs/index.js DELETED
@@ -1,41 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./local-key-manager.js"), exports);
18
- __exportStar(require("./utils.js"), exports);
19
- __exportStar(require("./algorithms/aes-ctr.js"), exports);
20
- __exportStar(require("./algorithms/aes-gcm.js"), exports);
21
- __exportStar(require("./algorithms/crypto-algorithm.js"), exports);
22
- __exportStar(require("./algorithms/ecdsa.js"), exports);
23
- __exportStar(require("./algorithms/eddsa.js"), exports);
24
- __exportStar(require("./algorithms/sha-2.js"), exports);
25
- __exportStar(require("./jose/jwe.js"), exports);
26
- __exportStar(require("./jose/jwk.js"), exports);
27
- __exportStar(require("./jose/jws.js"), exports);
28
- __exportStar(require("./jose/jwt.js"), exports);
29
- __exportStar(require("./jose/utils.js"), exports);
30
- __exportStar(require("./primitives/aes-ctr.js"), exports);
31
- __exportStar(require("./primitives/aes-gcm.js"), exports);
32
- __exportStar(require("./primitives/concat-kdf.js"), exports);
33
- __exportStar(require("./primitives/ed25519.js"), exports);
34
- __exportStar(require("./primitives/secp256r1.js"), exports);
35
- __exportStar(require("./primitives/pbkdf2.js"), exports);
36
- __exportStar(require("./primitives/secp256k1.js"), exports);
37
- __exportStar(require("./primitives/sha256.js"), exports);
38
- __exportStar(require("./primitives/x25519.js"), exports);
39
- __exportStar(require("./primitives/xchacha20.js"), exports);
40
- __exportStar(require("./primitives/xchacha20-poly1305.js"), exports);
41
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAuC;AACvC,6CAA2B;AAE3B,0DAAwC;AACxC,0DAAwC;AACxC,mEAAiD;AACjD,wDAAsC;AACtC,wDAAsC;AACtC,wDAAsC;AAEtC,gDAA8B;AAC9B,gDAA8B;AAC9B,gDAA8B;AAC9B,gDAA8B;AAC9B,kDAAgC;AAEhC,0DAAwC;AACxC,0DAAwC;AACxC,6DAA2C;AAC3C,0DAAwC;AACxC,4DAA0C;AAC1C,yDAAuC;AACvC,4DAA0C;AAC1C,yDAAuC;AACvC,yDAAuC;AACvC,4DAA0C;AAC1C,qEAAmD"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=jwe.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jwe.js","sourceRoot":"","sources":["../../../src/jose/jwe.ts"],"names":[],"mappings":""}