@fgv/ts-extras 5.1.0-41 → 5.1.0-43

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 (54) hide show
  1. package/dist/packlets/crypto-utils/index.browser.js +4 -1
  2. package/dist/packlets/crypto-utils/index.browser.js.map +1 -1
  3. package/dist/packlets/crypto-utils/index.js +3 -1
  4. package/dist/packlets/crypto-utils/index.js.map +1 -1
  5. package/dist/packlets/crypto-utils/keystore/converters.js +8 -4
  6. package/dist/packlets/crypto-utils/keystore/converters.js.map +1 -1
  7. package/dist/packlets/crypto-utils/keystore/keyStore.js +101 -2
  8. package/dist/packlets/crypto-utils/keystore/keyStore.js.map +1 -1
  9. package/dist/packlets/crypto-utils/keystore/model.js +9 -4
  10. package/dist/packlets/crypto-utils/keystore/model.js.map +1 -1
  11. package/dist/packlets/crypto-utils/model.js.map +1 -1
  12. package/dist/packlets/crypto-utils/nodeCryptoProvider.js +11 -0
  13. package/dist/packlets/crypto-utils/nodeCryptoProvider.js.map +1 -1
  14. package/dist/packlets/crypto-utils/seedDerivedKeyPair.js +120 -0
  15. package/dist/packlets/crypto-utils/seedDerivedKeyPair.js.map +1 -0
  16. package/dist/packlets/crypto-utils/spkiHelpers.js +44 -0
  17. package/dist/packlets/crypto-utils/spkiHelpers.js.map +1 -1
  18. package/dist/ts-extras.d.ts +270 -7
  19. package/lib/packlets/crypto-utils/index.browser.d.ts +2 -1
  20. package/lib/packlets/crypto-utils/index.browser.d.ts.map +1 -1
  21. package/lib/packlets/crypto-utils/index.browser.js +7 -1
  22. package/lib/packlets/crypto-utils/index.browser.js.map +1 -1
  23. package/lib/packlets/crypto-utils/index.d.ts +2 -1
  24. package/lib/packlets/crypto-utils/index.d.ts.map +1 -1
  25. package/lib/packlets/crypto-utils/index.js +6 -1
  26. package/lib/packlets/crypto-utils/index.js.map +1 -1
  27. package/lib/packlets/crypto-utils/keystore/converters.d.ts +1 -1
  28. package/lib/packlets/crypto-utils/keystore/converters.d.ts.map +1 -1
  29. package/lib/packlets/crypto-utils/keystore/converters.js +8 -4
  30. package/lib/packlets/crypto-utils/keystore/converters.js.map +1 -1
  31. package/lib/packlets/crypto-utils/keystore/keyStore.d.ts +45 -1
  32. package/lib/packlets/crypto-utils/keystore/keyStore.d.ts.map +1 -1
  33. package/lib/packlets/crypto-utils/keystore/keyStore.js +101 -2
  34. package/lib/packlets/crypto-utils/keystore/keyStore.js.map +1 -1
  35. package/lib/packlets/crypto-utils/keystore/model.d.ts +57 -3
  36. package/lib/packlets/crypto-utils/keystore/model.d.ts.map +1 -1
  37. package/lib/packlets/crypto-utils/keystore/model.js +9 -4
  38. package/lib/packlets/crypto-utils/keystore/model.js.map +1 -1
  39. package/lib/packlets/crypto-utils/model.d.ts +84 -3
  40. package/lib/packlets/crypto-utils/model.d.ts.map +1 -1
  41. package/lib/packlets/crypto-utils/model.js.map +1 -1
  42. package/lib/packlets/crypto-utils/nodeCryptoProvider.d.ts +9 -1
  43. package/lib/packlets/crypto-utils/nodeCryptoProvider.d.ts.map +1 -1
  44. package/lib/packlets/crypto-utils/nodeCryptoProvider.js +11 -0
  45. package/lib/packlets/crypto-utils/nodeCryptoProvider.js.map +1 -1
  46. package/lib/packlets/crypto-utils/seedDerivedKeyPair.d.ts +42 -0
  47. package/lib/packlets/crypto-utils/seedDerivedKeyPair.d.ts.map +1 -0
  48. package/lib/packlets/crypto-utils/seedDerivedKeyPair.js +123 -0
  49. package/lib/packlets/crypto-utils/seedDerivedKeyPair.js.map +1 -0
  50. package/lib/packlets/crypto-utils/spkiHelpers.d.ts +26 -0
  51. package/lib/packlets/crypto-utils/spkiHelpers.d.ts.map +1 -1
  52. package/lib/packlets/crypto-utils/spkiHelpers.js +46 -0
  53. package/lib/packlets/crypto-utils/spkiHelpers.js.map +1 -1
  54. package/package.json +7 -7
@@ -1 +1 @@
1
- {"version":3,"file":"converters.js","sourceRoot":"","sources":["../../../../src/packlets/crypto-utils/keystore/converters.ts"],"names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+EAA+E;AAC/E,2BAA2B;AAC3B,+EAA+E;AAE/E;;;GAGG;AACU,QAAA,YAAY,GAA6B,qBAAU,CAAC,MAAM,CAAgB;IACrF,MAAM,EAAE,sBAAc;IACtB,SAAS,EAAE,gCAAmB;IAC9B,EAAE,EAAE,yBAAY;IAChB,OAAO,EAAE,yBAAY;IACrB,aAAa,EAAE,yBAAY;IAC3B,aAAa,EAAE,sCAAyB;CACzC,CAAC,CAAC","sourcesContent":["// Copyright (c) 2026 Erik Fortune\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\n\nimport { Converter, Converters, succeed, Validation, Validator, Validators } from '@fgv/ts-utils';\nimport { base64String, encryptionAlgorithm, pbkdf2KeyDerivationParams } from '../converters';\nimport {\n allKeyPairAlgorithms,\n allKeyStoreFormats,\n allKeyStoreSecretTypes,\n allKeyStoreSymmetricSecretTypes,\n IKeyStoreAsymmetricEntryJson,\n IKeyStoreEntryJson,\n IKeyStoreFile,\n IKeyStoreSymmetricEntryJson,\n IKeyStoreVaultContents,\n KeyPairAlgorithm,\n KeyStoreAsymmetricSecretType,\n KeyStoreFormat,\n KeyStoreSecretType,\n KeyStoreSymmetricSecretType,\n allKeyStoreAsymmetricSecretTypes\n} from './model';\n\n// ============================================================================\n// Key Store Format Converter\n// ============================================================================\n\n/**\n * Converter for {@link CryptoUtils.KeyStore.KeyStoreFormat | key store format} version.\n * @public\n */\nexport const keystoreFormat: Converter<KeyStoreFormat> =\n Converters.enumeratedValue<KeyStoreFormat>(allKeyStoreFormats);\n\n// ============================================================================\n// Secret Type Converters\n// ============================================================================\n\n/**\n * Converter for {@link CryptoUtils.KeyStore.KeyStoreSecretType | any key store secret type} discriminator.\n * Accepts both symmetric and asymmetric type values.\n * @public\n */\nexport const keystoreSecretType: Converter<KeyStoreSecretType> =\n Converters.enumeratedValue<KeyStoreSecretType>(allKeyStoreSecretTypes);\n\n/**\n * Converter for {@link CryptoUtils.KeyStore.KeyStoreSymmetricSecretType | symmetric secret type} discriminator.\n * Accepts only `'encryption-key'` and `'api-key'`.\n * @public\n */\nexport const keystoreSymmetricSecretType: Converter<KeyStoreSymmetricSecretType> =\n Converters.enumeratedValue<KeyStoreSymmetricSecretType>(allKeyStoreSymmetricSecretTypes);\n\n/**\n * Converter for {@link CryptoUtils.KeyStore.KeyStoreAsymmetricSecretType | asymmetric secret type} discriminator.\n * Accepts only `'asymmetric-keypair'`.\n * @public\n */\nexport const keystoreAsymmetricSecretType: Converter<KeyStoreAsymmetricSecretType> =\n Converters.enumeratedValue<KeyStoreAsymmetricSecretType>(allKeyStoreAsymmetricSecretTypes);\n\n// ============================================================================\n// Key Pair Algorithm Converter\n// ============================================================================\n\n/**\n * Converter for {@link CryptoUtils.KeyStore.KeyPairAlgorithm | key pair algorithm}.\n * @public\n */\nexport const keyPairAlgorithm: Converter<KeyPairAlgorithm> =\n Converters.enumeratedValue<KeyPairAlgorithm>(allKeyPairAlgorithms);\n\n// ============================================================================\n// JWK Shape Validator\n// ============================================================================\n\n/**\n * In-place shape check for a JSON Web Key. Asserts only that the input is a\n * non-array object whose `kty` discriminator is a string; every other JWK\n * field passes through untouched. This is intentionally **not** a true JWK\n * validator — per-algorithm correctness (RSA `n`/`e`, EC `crv`/`x`/`y`,\n * key-size constraints, etc.) is delegated to `crypto.subtle.importKey` at\n * first use, which is the authoritative checker. The \"shape\" suffix in the\n * name is the warning sign for readers expecting full validation.\n * @remarks\n * Built with `Validators.object` (in-place, non-strict) so unknown JWK fields\n * survive the round-trip; the cast to `FieldValidators<JsonWebKey>` is required\n * only because TypeScript's mapped type demands an entry for every key in\n * `JsonWebKey`. At runtime the `ObjectValidator` only inspects keys present in\n * the field-validators map.\n * @public\n */\nexport const jsonWebKeyShape: Validator<JsonWebKey> = Validators.object<JsonWebKey>({\n kty: Validators.string\n} as Validation.Classes.FieldValidators<JsonWebKey>);\n\n// ============================================================================\n// Symmetric Secret Entry Converter\n// ============================================================================\n\n/**\n * Converter for {@link CryptoUtils.KeyStore.IKeyStoreSymmetricEntryJson | symmetric secret entry} in JSON form.\n *\n * @remarks\n * Backwards compatibility with vaults written before asymmetric-keypair\n * support: those entries may lack the `type` discriminator on the wire. To\n * keep the model type honest (`type` is required on\n * {@link CryptoUtils.KeyStore.IKeyStoreSymmetricEntryJson}, see its docs),\n * we declare `type` in `optionalFields` so the inner `Converters.object` will\n * accept input without it, then `.map()` injects the default\n * `'encryption-key'` when missing. The output therefore always carries the\n * discriminator and downstream code never sees the legacy missing-type form.\n *\n * @public\n */\nexport const keystoreSymmetricEntryJson: Converter<IKeyStoreSymmetricEntryJson> =\n Converters.object<IKeyStoreSymmetricEntryJson>(\n {\n name: Converters.string,\n type: keystoreSymmetricSecretType,\n key: base64String,\n description: Converters.string,\n createdAt: Converters.string\n },\n {\n // `type` is optional at the input layer for legacy-vault compatibility;\n // the .map() below normalizes by injecting the default.\n optionalFields: ['type', 'description']\n }\n ).map((entry) =>\n succeed<IKeyStoreSymmetricEntryJson>({\n ...entry,\n type: entry.type ?? 'encryption-key'\n })\n );\n\n// ============================================================================\n// Asymmetric Keypair Entry Converter\n// ============================================================================\n\n/**\n * Converter for {@link CryptoUtils.KeyStore.IKeyStoreAsymmetricEntryJson | asymmetric keypair entry} in JSON form.\n * The `publicKeyJwk` field passes through {@link CryptoUtils.KeyStore.Converters.jsonWebKeyShape | jsonWebKeyShape}\n * (shape check only — see its docs); cryptographic correctness is enforced by\n * `crypto.subtle.importKey` at use.\n * @public\n */\nexport const keystoreAsymmetricEntryJson: Converter<IKeyStoreAsymmetricEntryJson> =\n Converters.object<IKeyStoreAsymmetricEntryJson>({\n name: Converters.string,\n type: keystoreAsymmetricSecretType,\n id: Converters.string,\n algorithm: keyPairAlgorithm,\n publicKeyJwk: jsonWebKeyShape,\n escrowedPrivateKeyJwk: jsonWebKeyShape.optional(),\n description: Converters.string.optional(),\n createdAt: Converters.string\n });\n\n// ============================================================================\n// Discriminated-Union Entry Converter\n// ============================================================================\n\n/**\n * Discriminated-union converter for any {@link CryptoUtils.KeyStore.IKeyStoreEntryJson | key store entry} in JSON form.\n * Routes by the `type` field: `'asymmetric-keypair'` is parsed by\n * {@link CryptoUtils.KeyStore.Converters.keystoreAsymmetricEntryJson | keystoreAsymmetricEntryJson},\n * anything else (including a missing `type` field for backwards compatibility) by\n * {@link CryptoUtils.KeyStore.Converters.keystoreSymmetricEntryJson | keystoreSymmetricEntryJson}.\n * @public\n */\nexport const keystoreSecretEntryJson: Converter<IKeyStoreEntryJson> = Converters.oneOf<IKeyStoreEntryJson>([\n keystoreAsymmetricEntryJson,\n keystoreSymmetricEntryJson\n]);\n\n// ============================================================================\n// Vault Contents Converter\n// ============================================================================\n\n/**\n * Converter for {@link CryptoUtils.KeyStore.IKeyStoreVaultContents | key store vault contents} (decrypted state).\n * @public\n */\nexport const keystoreVaultContents: Converter<IKeyStoreVaultContents> =\n Converters.object<IKeyStoreVaultContents>({\n version: keystoreFormat,\n secrets: Converters.recordOf(keystoreSecretEntryJson)\n });\n\n// ============================================================================\n// Key Store File Converter\n// ============================================================================\n\n/**\n * Converter for {@link CryptoUtils.KeyStore.IKeyStoreFile | encrypted key store file}.\n * @public\n */\nexport const keystoreFile: Converter<IKeyStoreFile> = Converters.object<IKeyStoreFile>({\n format: keystoreFormat,\n algorithm: encryptionAlgorithm,\n iv: base64String,\n authTag: base64String,\n encryptedData: base64String,\n keyDerivation: pbkdf2KeyDerivationParams\n});\n"]}
1
+ {"version":3,"file":"converters.js","sourceRoot":"","sources":["../../../../src/packlets/crypto-utils/keystore/converters.ts"],"names":[],"mappings":";AAAA,kCAAkC;AAClC,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAC3D,EAAE;AACF,iFAAiF;AACjF,kDAAkD;AAClD,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,gFAAgF;AAChF,gFAAgF;AAChF,YAAY;;;AAEZ,4CAAkG;AAClG,oDAAiE;AACjE,8CAA6F;AAC7F,mCAgBiB;AAEjB,+EAA+E;AAC/E,6BAA6B;AAC7B,+EAA+E;AAE/E;;;GAGG;AACU,QAAA,cAAc,GACzB,qBAAU,CAAC,eAAe,CAAiB,0BAAkB,CAAC,CAAC;AAEjE,+EAA+E;AAC/E,yBAAyB;AACzB,+EAA+E;AAE/E;;;;GAIG;AACU,QAAA,kBAAkB,GAC7B,qBAAU,CAAC,eAAe,CAAqB,8BAAsB,CAAC,CAAC;AAEzE;;;;GAIG;AACU,QAAA,2BAA2B,GACtC,qBAAU,CAAC,eAAe,CAA8B,uCAA+B,CAAC,CAAC;AAE3F;;;;GAIG;AACU,QAAA,4BAA4B,GACvC,qBAAU,CAAC,eAAe,CAA+B,wCAAgC,CAAC,CAAC;AAE7F,+EAA+E;AAC/E,+BAA+B;AAC/B,+EAA+E;AAE/E;;;GAGG;AACU,QAAA,gBAAgB,GAC3B,qBAAU,CAAC,eAAe,CAAmB,4BAAoB,CA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;IACzC,SAAS,EAAE,qBAAU,CAAC,MAAM;CAC7B,CAAC,CAAC;AAEL,+EAA+E;AAC/E,sCAAsC;AACtC,+EAA+E;AAE/E;;;;;;;GAOG;AACU,QAAA,uBAAuB,GAAkC,qBAAU,CAAC,KAAK,CAAqB;IACzG,mCAA2B;IAC3B,kCAA0B;CAC3B,CAAC,CAAC;AAEH,+EAA+E;AAC/E,2BAA2B;AAC3B,+EAA+E;AAE/E;;;GAGG;AACU,QAAA,qBAAqB,GAChC,qBAAU,CAAC,MAAM,CAAyB;IACxC,OAAO,EAAE,sBAAc;IACvB,OAAO,EAAE,qBAAU,CAAC,QAAQ,CAAC,+BAAuB,CAAC;CACtD,CAAC,CAAC;AAEL,+EAA+E;AAC/E,2BAA2B;AAC3B,+EAA+E;AAE/E;;;GAGG;AACU,QAAA,YAAY,GAA6B,qBAAU,CAAC,MAAM,CAAgB;IACrF,MAAM,EAAE,sBAAc;IACtB,SAAS,EAAE,gCAAmB;IAC9B,EAAE,EAAE,yBAAY;IAChB,OAAO,EAAE,yBAAY;IACrB,aAAa,EAAE,yBAAY;IAC3B,aAAa,EAAE,sCAAyB;CACzC,CAAC,CAAC","sourcesContent":["// Copyright (c) 2026 Erik Fortune\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\n\nimport { Converter, Converters, succeed, Validation, Validator, Validators } from '@fgv/ts-utils';\nimport { Converters as JsonConverters } from '@fgv/ts-json-base';\nimport { base64String, encryptionAlgorithm, pbkdf2KeyDerivationParams } from '../converters';\nimport {\n allKeyPairAlgorithms,\n allKeyStoreFormats,\n allKeyStoreSecretTypes,\n allKeyStoreSymmetricSecretTypes,\n IKeyStoreAsymmetricEntryJson,\n IKeyStoreEntryJson,\n IKeyStoreFile,\n IKeyStoreSymmetricEntryJson,\n IKeyStoreVaultContents,\n KeyPairAlgorithm,\n KeyStoreAsymmetricSecretType,\n KeyStoreFormat,\n KeyStoreSecretType,\n KeyStoreSymmetricSecretType,\n allKeyStoreAsymmetricSecretTypes\n} from './model';\n\n// ============================================================================\n// Key Store Format Converter\n// ============================================================================\n\n/**\n * Converter for {@link CryptoUtils.KeyStore.KeyStoreFormat | key store format} version.\n * @public\n */\nexport const keystoreFormat: Converter<KeyStoreFormat> =\n Converters.enumeratedValue<KeyStoreFormat>(allKeyStoreFormats);\n\n// ============================================================================\n// Secret Type Converters\n// ============================================================================\n\n/**\n * Converter for {@link CryptoUtils.KeyStore.KeyStoreSecretType | any key store secret type} discriminator.\n * Accepts both symmetric and asymmetric type values.\n * @public\n */\nexport const keystoreSecretType: Converter<KeyStoreSecretType> =\n Converters.enumeratedValue<KeyStoreSecretType>(allKeyStoreSecretTypes);\n\n/**\n * Converter for {@link CryptoUtils.KeyStore.KeyStoreSymmetricSecretType | symmetric secret type} discriminator.\n * Accepts `'encryption-key'`, `'api-key'`, and `'opaque'`.\n * @public\n */\nexport const keystoreSymmetricSecretType: Converter<KeyStoreSymmetricSecretType> =\n Converters.enumeratedValue<KeyStoreSymmetricSecretType>(allKeyStoreSymmetricSecretTypes);\n\n/**\n * Converter for {@link CryptoUtils.KeyStore.KeyStoreAsymmetricSecretType | asymmetric secret type} discriminator.\n * Accepts only `'asymmetric-keypair'`.\n * @public\n */\nexport const keystoreAsymmetricSecretType: Converter<KeyStoreAsymmetricSecretType> =\n Converters.enumeratedValue<KeyStoreAsymmetricSecretType>(allKeyStoreAsymmetricSecretTypes);\n\n// ============================================================================\n// Key Pair Algorithm Converter\n// ============================================================================\n\n/**\n * Converter for {@link CryptoUtils.KeyStore.KeyPairAlgorithm | key pair algorithm}.\n * @public\n */\nexport const keyPairAlgorithm: Converter<KeyPairAlgorithm> =\n Converters.enumeratedValue<KeyPairAlgorithm>(allKeyPairAlgorithms);\n\n// ============================================================================\n// JWK Shape Validator\n// ============================================================================\n\n/**\n * In-place shape check for a JSON Web Key. Asserts only that the input is a\n * non-array object whose `kty` discriminator is a string; every other JWK\n * field passes through untouched. This is intentionally **not** a true JWK\n * validator — per-algorithm correctness (RSA `n`/`e`, EC `crv`/`x`/`y`,\n * key-size constraints, etc.) is delegated to `crypto.subtle.importKey` at\n * first use, which is the authoritative checker. The \"shape\" suffix in the\n * name is the warning sign for readers expecting full validation.\n * @remarks\n * Built with `Validators.object` (in-place, non-strict) so unknown JWK fields\n * survive the round-trip; the cast to `FieldValidators<JsonWebKey>` is required\n * only because TypeScript's mapped type demands an entry for every key in\n * `JsonWebKey`. At runtime the `ObjectValidator` only inspects keys present in\n * the field-validators map.\n * @public\n */\nexport const jsonWebKeyShape: Validator<JsonWebKey> = Validators.object<JsonWebKey>({\n kty: Validators.string\n} as Validation.Classes.FieldValidators<JsonWebKey>);\n\n// ============================================================================\n// Symmetric Secret Entry Converter\n// ============================================================================\n\n/**\n * Converter for {@link CryptoUtils.KeyStore.IKeyStoreSymmetricEntryJson | symmetric secret entry} in JSON form.\n *\n * @remarks\n * Backwards compatibility with vaults written before asymmetric-keypair\n * support: those entries may lack the `type` discriminator on the wire. To\n * keep the model type honest (`type` is required on\n * {@link CryptoUtils.KeyStore.IKeyStoreSymmetricEntryJson}, see its docs),\n * we declare `type` in `optionalFields` so the inner `Converters.object` will\n * accept input without it, then `.map()` injects the default\n * `'encryption-key'` when missing. The output therefore always carries the\n * discriminator and downstream code never sees the legacy missing-type form.\n *\n * @public\n */\nexport const keystoreSymmetricEntryJson: Converter<IKeyStoreSymmetricEntryJson> =\n Converters.object<IKeyStoreSymmetricEntryJson>(\n {\n name: Converters.string,\n type: keystoreSymmetricSecretType,\n key: base64String,\n description: Converters.string,\n metadata: JsonConverters.jsonValue,\n createdAt: Converters.string,\n updatedAt: Converters.string\n },\n {\n // `type` is optional at the input layer for legacy-vault compatibility;\n // the .map() below normalizes by injecting the default. `metadata` and\n // `updatedAt` are keystore-v3 additions, optional so v1/v2 entries parse.\n optionalFields: ['type', 'description', 'metadata', 'updatedAt']\n }\n ).map((entry) =>\n succeed<IKeyStoreSymmetricEntryJson>({\n ...entry,\n type: entry.type ?? 'encryption-key'\n })\n );\n\n// ============================================================================\n// Asymmetric Keypair Entry Converter\n// ============================================================================\n\n/**\n * Converter for {@link CryptoUtils.KeyStore.IKeyStoreAsymmetricEntryJson | asymmetric keypair entry} in JSON form.\n * The `publicKeyJwk` field passes through {@link CryptoUtils.KeyStore.Converters.jsonWebKeyShape | jsonWebKeyShape}\n * (shape check only — see its docs); cryptographic correctness is enforced by\n * `crypto.subtle.importKey` at use.\n * @public\n */\nexport const keystoreAsymmetricEntryJson: Converter<IKeyStoreAsymmetricEntryJson> =\n Converters.object<IKeyStoreAsymmetricEntryJson>({\n name: Converters.string,\n type: keystoreAsymmetricSecretType,\n id: Converters.string,\n algorithm: keyPairAlgorithm,\n publicKeyJwk: jsonWebKeyShape,\n escrowedPrivateKeyJwk: jsonWebKeyShape.optional(),\n description: Converters.string.optional(),\n createdAt: Converters.string\n });\n\n// ============================================================================\n// Discriminated-Union Entry Converter\n// ============================================================================\n\n/**\n * Discriminated-union converter for any {@link CryptoUtils.KeyStore.IKeyStoreEntryJson | key store entry} in JSON form.\n * Routes by the `type` field: `'asymmetric-keypair'` is parsed by\n * {@link CryptoUtils.KeyStore.Converters.keystoreAsymmetricEntryJson | keystoreAsymmetricEntryJson},\n * anything else (including a missing `type` field for backwards compatibility) by\n * {@link CryptoUtils.KeyStore.Converters.keystoreSymmetricEntryJson | keystoreSymmetricEntryJson}.\n * @public\n */\nexport const keystoreSecretEntryJson: Converter<IKeyStoreEntryJson> = Converters.oneOf<IKeyStoreEntryJson>([\n keystoreAsymmetricEntryJson,\n keystoreSymmetricEntryJson\n]);\n\n// ============================================================================\n// Vault Contents Converter\n// ============================================================================\n\n/**\n * Converter for {@link CryptoUtils.KeyStore.IKeyStoreVaultContents | key store vault contents} (decrypted state).\n * @public\n */\nexport const keystoreVaultContents: Converter<IKeyStoreVaultContents> =\n Converters.object<IKeyStoreVaultContents>({\n version: keystoreFormat,\n secrets: Converters.recordOf(keystoreSecretEntryJson)\n });\n\n// ============================================================================\n// Key Store File Converter\n// ============================================================================\n\n/**\n * Converter for {@link CryptoUtils.KeyStore.IKeyStoreFile | encrypted key store file}.\n * @public\n */\nexport const keystoreFile: Converter<IKeyStoreFile> = Converters.object<IKeyStoreFile>({\n format: keystoreFormat,\n algorithm: encryptionAlgorithm,\n iv: base64String,\n authTag: base64String,\n encryptedData: base64String,\n keyDerivation: pbkdf2KeyDerivationParams\n});\n"]}
@@ -1,7 +1,7 @@
1
1
  import { JsonValue } from '@fgv/ts-json-base';
2
2
  import { Result } from '@fgv/ts-utils';
3
3
  import { ICryptoProvider, IEncryptedFile, IEncryptionConfig, IEncryptionProvider, IArgon2idKeyDerivationParams, IArgon2idProvider, IKeyDerivationParams, SecretProvider } from '../model';
4
- import { IAddKeyPairOptions, IAddKeyPairResult, IAddSecretFromPasswordArgon2idOptions, IAddSecretFromPasswordOptions, IAddSecretFromPasswordResult, IAddSecretOptions, IAddSecretResult, IGetKeyPairOptions, IImportKeyOptions, IImportSecretOptions, IKeyStoreCreateParams, IKeyStoreEntry, IKeyStoreFile, IKeyStoreOpenParams, IRemoveSecretResult, KeyStoreLockState, KeyStoreSecretType } from './model';
4
+ import { IAddKeyPairOptions, IAddKeyPairResult, IAddSecretFromPasswordArgon2idOptions, IAddSecretFromPasswordOptions, IAddSecretFromPasswordResult, IAddSecretOptions, IAddSecretResult, IGetKeyPairOptions, IImportKeyOptions, IImportSecretBytesOptions, IImportSecretOptions, IKeyStoreCreateParams, IKeyStoreEntry, IKeyStoreFile, IKeyStoreOpenParams, IKeyStoreSymmetricEntry, IRemoveSecretResult, KeyStoreLockState, KeyStoreSecretType } from './model';
5
5
  /**
6
6
  * Password-protected key store for managing encryption secrets.
7
7
  *
@@ -310,6 +310,50 @@ export declare class KeyStore implements IEncryptionProvider {
310
310
  * @public
311
311
  */
312
312
  getApiKey(name: string): Result<string>;
313
+ /**
314
+ * Imports arbitrary raw bytes into the vault with type `'opaque'`.
315
+ *
316
+ * Unlike {@link KeyStore.importSecret} (which enforces a 32-byte AES-256 key)
317
+ * and {@link KeyStore.importApiKey} (which UTF-8 encodes a string), this
318
+ * accepts a byte buffer of any length and stores it verbatim — including
319
+ * embedded NUL bytes. Use it for byte blobs that are neither a fixed-size key
320
+ * nor a UTF-8 string (e.g. a serialized credential bundle), so they are not
321
+ * mistyped as `'api-key'`.
322
+ *
323
+ * @param name - Unique name for the secret
324
+ * @param bytes - The raw bytes to store
325
+ * @param options - Optional description, initial metadata, whether to replace existing
326
+ * @returns Success with entry, Failure if locked, empty, or exists and !replace
327
+ * @public
328
+ */
329
+ importSecretBytes(name: string, bytes: Uint8Array, options?: IImportSecretBytesOptions): Promise<Result<IAddSecretResult>>;
330
+ /**
331
+ * Retrieves the raw stored bytes for a symmetric entry, returned verbatim
332
+ * (never UTF-8 decoded). Intended for `'opaque'` entries but works for any
333
+ * symmetric type; asymmetric-keypair entries carry no raw key material and
334
+ * are rejected.
335
+ *
336
+ * @param name - Name of the secret
337
+ * @returns Success with a copy of the stored bytes, Failure if not found,
338
+ * locked, or the entry is asymmetric
339
+ * @public
340
+ */
341
+ getSecretBytes(name: string): Result<Uint8Array>;
342
+ /**
343
+ * Replaces the mutable metadata on a symmetric entry and stamps `updatedAt`
344
+ * with the current timestamp. Does NOT touch the secret `key` bytes — the
345
+ * material reads back identically afterward.
346
+ *
347
+ * Metadata is non-secret by contract but physically lives inside the vault
348
+ * ciphertext (see {@link CryptoUtils.KeyStore.IKeyStoreSymmetricEntry.metadata}).
349
+ *
350
+ * @param name - Name of the secret to update
351
+ * @param value - New metadata value (replaces any prior metadata)
352
+ * @returns Success with the updated entry, Failure if not found, locked, or
353
+ * the entry is asymmetric
354
+ * @public
355
+ */
356
+ setSecretMetadata(name: string, value: JsonValue): Result<IKeyStoreSymmetricEntry>;
313
357
  /**
314
358
  * Adds a new asymmetric keypair to the vault. Storage-first: the private key
315
359
  * is stored under a freshly-minted `id` before the public-key vault entry is
@@ -1 +1 @@
1
- {"version":3,"file":"keyStore.d.ts","sourceRoot":"","sources":["../../../../src/packlets/crypto-utils/keystore/keyStore.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAA2C,MAAM,EAAW,MAAM,eAAe,CAAC;AAIzF,OAAO,EACL,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,4BAA4B,EAC5B,iBAAiB,EAEjB,oBAAoB,EAGpB,cAAc,EACf,MAAM,UAAU,CAAC;AAClB,OAAO,EAGL,kBAAkB,EAClB,iBAAiB,EACjB,qCAAqC,EACrC,6BAA6B,EAC7B,4BAA4B,EAC5B,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EAEpB,qBAAqB,EACrB,cAAc,EAEd,aAAa,EACb,mBAAmB,EAGnB,mBAAmB,EAEnB,iBAAiB,EACjB,kBAAkB,EAEnB,MAAM,SAAS,CAAC;AAqBjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;G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C;;;;;OAKG;IACI,iBAAiB,IAAI,MAAM,CAAC,cAAc,CAAC;IAoBlD;;;;OAIG;IACI,mBAAmB,IAAI,MAAM,CAAC,IAAI,CAAC,iBAAiB,EAAE,gBAAgB,GAAG,gBAAgB,CAAC,CAAC;IAgBlG;;;OAGG;YACW,aAAa;IAwE3B;;;OAGG;YACW,aAAa;IAgG3B;;;;;;;;;OASG;YACW,sBAAsB;IAepC;;;;;;OAMG;YACW,oBAAoB;IAMlC;;;;;;;;OAQG;YACW,yBAAyB;IAYvC;;;;;OAKG;YACW,0BAA0B;IAmCxC;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;IASnC;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAa/B;;;;OAIG;IACH,OAAO,CAAC,WAAW;CAkBpB"}
@@ -781,6 +781,101 @@ class KeyStore {
781
781
  const decoder = new TextDecoder();
782
782
  return (0, ts_utils_1.succeed)(decoder.decode(entry.key));
783
783
  }
784
+ /**
785
+ * Imports arbitrary raw bytes into the vault with type `'opaque'`.
786
+ *
787
+ * Unlike {@link KeyStore.importSecret} (which enforces a 32-byte AES-256 key)
788
+ * and {@link KeyStore.importApiKey} (which UTF-8 encodes a string), this
789
+ * accepts a byte buffer of any length and stores it verbatim — including
790
+ * embedded NUL bytes. Use it for byte blobs that are neither a fixed-size key
791
+ * nor a UTF-8 string (e.g. a serialized credential bundle), so they are not
792
+ * mistyped as `'api-key'`.
793
+ *
794
+ * @param name - Unique name for the secret
795
+ * @param bytes - The raw bytes to store
796
+ * @param options - Optional description, initial metadata, whether to replace existing
797
+ * @returns Success with entry, Failure if locked, empty, or exists and !replace
798
+ * @public
799
+ */
800
+ async importSecretBytes(name, bytes, options) {
801
+ if (!this._secrets) {
802
+ return (0, ts_utils_1.fail)('Key store is locked');
803
+ }
804
+ if (!name || name.length === 0) {
805
+ return (0, ts_utils_1.fail)('Secret name cannot be empty');
806
+ }
807
+ const existing = this._secrets.get(name);
808
+ if (existing && !(options === null || options === void 0 ? void 0 : options.replace)) {
809
+ return (0, ts_utils_1.fail)(`Secret '${name}' already exists - use replace=true to overwrite`);
810
+ }
811
+ const entry = {
812
+ name,
813
+ type: 'opaque',
814
+ key: new Uint8Array(bytes), // Copy to prevent external modification
815
+ description: options === null || options === void 0 ? void 0 : options.description,
816
+ metadata: options === null || options === void 0 ? void 0 : options.metadata,
817
+ createdAt: getCurrentTimestamp()
818
+ };
819
+ const warning = existing ? await this._releaseEntryResources(existing) : undefined;
820
+ this._secrets.set(name, entry);
821
+ this._dirty = true;
822
+ return (0, ts_utils_1.succeed)({ entry, replaced: existing !== undefined, warning });
823
+ }
824
+ /**
825
+ * Retrieves the raw stored bytes for a symmetric entry, returned verbatim
826
+ * (never UTF-8 decoded). Intended for `'opaque'` entries but works for any
827
+ * symmetric type; asymmetric-keypair entries carry no raw key material and
828
+ * are rejected.
829
+ *
830
+ * @param name - Name of the secret
831
+ * @returns Success with a copy of the stored bytes, Failure if not found,
832
+ * locked, or the entry is asymmetric
833
+ * @public
834
+ */
835
+ getSecretBytes(name) {
836
+ if (!this._secrets) {
837
+ return (0, ts_utils_1.fail)('Key store is locked');
838
+ }
839
+ const entry = this._secrets.get(name);
840
+ if (!entry) {
841
+ return (0, ts_utils_1.fail)(`Secret '${name}' not found`);
842
+ }
843
+ if (entry.type === 'asymmetric-keypair') {
844
+ return (0, ts_utils_1.fail)(`Secret '${name}' is an asymmetric keypair, not raw byte material (type: ${entry.type})`);
845
+ }
846
+ // Copy so callers cannot mutate the in-memory vault buffer.
847
+ return (0, ts_utils_1.succeed)(new Uint8Array(entry.key));
848
+ }
849
+ /**
850
+ * Replaces the mutable metadata on a symmetric entry and stamps `updatedAt`
851
+ * with the current timestamp. Does NOT touch the secret `key` bytes — the
852
+ * material reads back identically afterward.
853
+ *
854
+ * Metadata is non-secret by contract but physically lives inside the vault
855
+ * ciphertext (see {@link CryptoUtils.KeyStore.IKeyStoreSymmetricEntry.metadata}).
856
+ *
857
+ * @param name - Name of the secret to update
858
+ * @param value - New metadata value (replaces any prior metadata)
859
+ * @returns Success with the updated entry, Failure if not found, locked, or
860
+ * the entry is asymmetric
861
+ * @public
862
+ */
863
+ setSecretMetadata(name, value) {
864
+ if (!this._secrets) {
865
+ return (0, ts_utils_1.fail)('Key store is locked');
866
+ }
867
+ const entry = this._secrets.get(name);
868
+ if (!entry) {
869
+ return (0, ts_utils_1.fail)(`Secret '${name}' not found`);
870
+ }
871
+ if (entry.type === 'asymmetric-keypair') {
872
+ return (0, ts_utils_1.fail)(`Secret '${name}' is an asymmetric keypair; metadata is only supported on symmetric entries (type: ${entry.type})`);
873
+ }
874
+ const updated = Object.assign(Object.assign({}, entry), { metadata: value, updatedAt: getCurrentTimestamp() });
875
+ this._secrets.set(name, updated);
876
+ this._dirty = true;
877
+ return (0, ts_utils_1.succeed)(updated);
878
+ }
784
879
  // ============================================================================
785
880
  // Asymmetric Keypair Management
786
881
  // ============================================================================
@@ -1193,7 +1288,9 @@ class KeyStore {
1193
1288
  type: entry.type,
1194
1289
  key: this._cryptoProvider.toBase64(entry.key),
1195
1290
  description: entry.description,
1196
- createdAt: entry.createdAt
1291
+ metadata: entry.metadata,
1292
+ createdAt: entry.createdAt,
1293
+ updatedAt: entry.updatedAt
1197
1294
  };
1198
1295
  }
1199
1296
  }
@@ -1299,7 +1396,9 @@ class KeyStore {
1299
1396
  type: jsonEntry.type,
1300
1397
  key: keyBytesResult.value,
1301
1398
  description: jsonEntry.description,
1302
- createdAt: jsonEntry.createdAt
1399
+ metadata: jsonEntry.metadata,
1400
+ createdAt: jsonEntry.createdAt,
1401
+ updatedAt: jsonEntry.updatedAt
1303
1402
  };
1304
1403
  secrets.set(name, entry);
1305
1404
  }