@fgv/ts-extras 5.1.0-17 → 5.1.0-18

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 (33) hide show
  1. package/dist/packlets/crypto-utils/index.browser.js +2 -0
  2. package/dist/packlets/crypto-utils/index.js +2 -0
  3. package/dist/packlets/crypto-utils/keyPairAlgorithmParams.js +47 -0
  4. package/dist/packlets/crypto-utils/keystore/converters.js +101 -9
  5. package/dist/packlets/crypto-utils/keystore/index.js +1 -0
  6. package/dist/packlets/crypto-utils/keystore/keyStore.js +271 -46
  7. package/dist/packlets/crypto-utils/keystore/model.js +22 -1
  8. package/dist/packlets/crypto-utils/keystore/privateKeyStorage.js +21 -0
  9. package/dist/packlets/crypto-utils/model.js +5 -0
  10. package/dist/packlets/crypto-utils/nodeCryptoProvider.js +44 -1
  11. package/dist/test/unit/crypto/keystore/inMemoryPrivateKeyStorage.js +78 -0
  12. package/dist/ts-extras.d.ts +577 -32
  13. package/lib/packlets/crypto-utils/index.browser.d.ts +1 -0
  14. package/lib/packlets/crypto-utils/index.browser.js +4 -1
  15. package/lib/packlets/crypto-utils/index.d.ts +1 -0
  16. package/lib/packlets/crypto-utils/index.js +4 -1
  17. package/lib/packlets/crypto-utils/keyPairAlgorithmParams.d.ts +39 -0
  18. package/lib/packlets/crypto-utils/keyPairAlgorithmParams.js +50 -0
  19. package/lib/packlets/crypto-utils/keystore/converters.d.ts +68 -6
  20. package/lib/packlets/crypto-utils/keystore/converters.js +100 -8
  21. package/lib/packlets/crypto-utils/keystore/index.d.ts +1 -0
  22. package/lib/packlets/crypto-utils/keystore/index.js +1 -0
  23. package/lib/packlets/crypto-utils/keystore/keyStore.d.ts +77 -9
  24. package/lib/packlets/crypto-utils/keystore/keyStore.js +271 -46
  25. package/lib/packlets/crypto-utils/keystore/model.d.ts +238 -19
  26. package/lib/packlets/crypto-utils/keystore/model.js +24 -2
  27. package/lib/packlets/crypto-utils/keystore/privateKeyStorage.d.ts +50 -0
  28. package/lib/packlets/crypto-utils/keystore/privateKeyStorage.js +22 -0
  29. package/lib/packlets/crypto-utils/model.d.ts +38 -0
  30. package/lib/packlets/crypto-utils/model.js +6 -1
  31. package/lib/packlets/crypto-utils/nodeCryptoProvider.d.ts +26 -1
  32. package/lib/packlets/crypto-utils/nodeCryptoProvider.js +43 -0
  33. package/package.json +7 -7
@@ -0,0 +1,78 @@
1
+ // Copyright (c) 2026 Erik Fortune
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in all
11
+ // copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ // SOFTWARE.
20
+ import { fail, succeed } from '@fgv/ts-utils';
21
+ /**
22
+ * In-memory implementation of `IPrivateKeyStorage` for keystore tests.
23
+ *
24
+ * Not exported from `@fgv/ts-extras`. Lives in the test tree as a reference
25
+ * implementation downstream packages may copy if useful, but the public API
26
+ * delegates concrete backends to platform-specific packages
27
+ * (browser/IDB in `@fgv/ts-web-extras`, encrypted-file in `@fgv/ts-chocolate`).
28
+ *
29
+ * Holds `CryptoKey` objects directly in a `Map`, so it advertises
30
+ * `supportsNonExtractable: true` by default. The constructor accepts overrides
31
+ * useful for negative tests:
32
+ * - `supportsNonExtractable: false` exercises the extractable=true codepath.
33
+ * - `failOn: { store?, load?, delete?, list? }` makes the named operations
34
+ * return Failure with a stable message so tests can assert downstream
35
+ * warning/error propagation without resorting to mocks.
36
+ */
37
+ export class InMemoryPrivateKeyStorage {
38
+ constructor(options) {
39
+ var _a, _b;
40
+ this.supportsNonExtractable = (_a = options === null || options === void 0 ? void 0 : options.supportsNonExtractable) !== null && _a !== void 0 ? _a : true;
41
+ this.entries = new Map();
42
+ this._failOn = (_b = options === null || options === void 0 ? void 0 : options.failOn) !== null && _b !== void 0 ? _b : {};
43
+ }
44
+ async store(id, key) {
45
+ if (this._failOn.store) {
46
+ return fail(this._failOn.store);
47
+ }
48
+ this.entries.set(id, key);
49
+ return succeed(id);
50
+ }
51
+ async load(id) {
52
+ if (this._failOn.load) {
53
+ return fail(this._failOn.load);
54
+ }
55
+ const key = this.entries.get(id);
56
+ if (!key) {
57
+ return fail(`No private key for id '${id}'`);
58
+ }
59
+ return succeed(key);
60
+ }
61
+ async delete(id) {
62
+ if (this._failOn.delete) {
63
+ return fail(this._failOn.delete);
64
+ }
65
+ if (!this.entries.has(id)) {
66
+ return fail(`No private key for id '${id}'`);
67
+ }
68
+ this.entries.delete(id);
69
+ return succeed(id);
70
+ }
71
+ async list() {
72
+ if (this._failOn.list) {
73
+ return fail(this._failOn.list);
74
+ }
75
+ return succeed(Array.from(this.entries.keys()));
76
+ }
77
+ }
78
+ //# sourceMappingURL=inMemoryPrivateKeyStorage.js.map