@wildo-ai/platform-config-lib 1.1.9 → 1.1.11

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 (188) hide show
  1. package/dist/esm/_unimplemented/unimplemented-field-warning.d.ts +1 -1
  2. package/dist/esm/_unimplemented/unimplemented-field-warning.js +1 -1
  3. package/dist/esm/_unimplemented/unimplemented-field-warning.js.map +1 -1
  4. package/dist/esm/blueprint/anchored-region.d.ts +83 -0
  5. package/dist/esm/blueprint/anchored-region.d.ts.map +1 -0
  6. package/dist/esm/blueprint/anchored-region.js +263 -0
  7. package/dist/esm/blueprint/anchored-region.js.map +1 -0
  8. package/dist/esm/blueprint/blueprint.schemas.d.ts +689 -0
  9. package/dist/esm/blueprint/blueprint.schemas.d.ts.map +1 -0
  10. package/dist/esm/blueprint/blueprint.schemas.js +638 -0
  11. package/dist/esm/blueprint/blueprint.schemas.js.map +1 -0
  12. package/dist/esm/bootstrap/bootstrap.contracts.d.ts +13 -1
  13. package/dist/esm/bootstrap/bootstrap.contracts.d.ts.map +1 -1
  14. package/dist/esm/bootstrap/bootstrap.contracts.js +6 -0
  15. package/dist/esm/bootstrap/bootstrap.contracts.js.map +1 -1
  16. package/dist/esm/bootstrap/bootstrap.schemas.d.ts +21 -3
  17. package/dist/esm/bootstrap/bootstrap.schemas.d.ts.map +1 -1
  18. package/dist/esm/bootstrap/bootstrap.schemas.js +14 -3
  19. package/dist/esm/bootstrap/bootstrap.schemas.js.map +1 -1
  20. package/dist/esm/bootstrap/platform-runtime-env.contracts.d.ts +121 -0
  21. package/dist/esm/bootstrap/platform-runtime-env.contracts.d.ts.map +1 -1
  22. package/dist/esm/bootstrap/platform-runtime-env.contracts.js +129 -0
  23. package/dist/esm/bootstrap/platform-runtime-env.contracts.js.map +1 -1
  24. package/dist/esm/bootstrap/runtime-response-integrity.d.ts +249 -0
  25. package/dist/esm/bootstrap/runtime-response-integrity.d.ts.map +1 -0
  26. package/dist/esm/bootstrap/runtime-response-integrity.js +353 -0
  27. package/dist/esm/bootstrap/runtime-response-integrity.js.map +1 -0
  28. package/dist/esm/bootstrap/runtime-secret-env.contracts.d.ts +32 -0
  29. package/dist/esm/bootstrap/runtime-secret-env.contracts.d.ts.map +1 -0
  30. package/dist/esm/bootstrap/runtime-secret-env.contracts.js +43 -0
  31. package/dist/esm/bootstrap/runtime-secret-env.contracts.js.map +1 -0
  32. package/dist/esm/canonical-json/rfc8785-canonical-json.d.ts +51 -0
  33. package/dist/esm/canonical-json/rfc8785-canonical-json.d.ts.map +1 -0
  34. package/dist/esm/canonical-json/rfc8785-canonical-json.js +231 -0
  35. package/dist/esm/canonical-json/rfc8785-canonical-json.js.map +1 -0
  36. package/dist/esm/index.d.ts +15 -0
  37. package/dist/esm/index.d.ts.map +1 -1
  38. package/dist/esm/index.js +15 -0
  39. package/dist/esm/index.js.map +1 -1
  40. package/dist/esm/key-management/approval-seal-verifier.d.ts +216 -0
  41. package/dist/esm/key-management/approval-seal-verifier.d.ts.map +1 -0
  42. package/dist/esm/key-management/approval-seal-verifier.js +233 -0
  43. package/dist/esm/key-management/approval-seal-verifier.js.map +1 -0
  44. package/dist/esm/key-management/approval-seal.contracts.d.ts +131 -0
  45. package/dist/esm/key-management/approval-seal.contracts.d.ts.map +1 -0
  46. package/dist/esm/key-management/approval-seal.contracts.js +115 -0
  47. package/dist/esm/key-management/approval-seal.contracts.js.map +1 -0
  48. package/dist/esm/key-management/data-key.contracts.d.ts +108 -0
  49. package/dist/esm/key-management/data-key.contracts.d.ts.map +1 -0
  50. package/dist/esm/key-management/data-key.contracts.js +54 -0
  51. package/dist/esm/key-management/data-key.contracts.js.map +1 -0
  52. package/dist/esm/key-management/es256-jws.d.ts +60 -0
  53. package/dist/esm/key-management/es256-jws.d.ts.map +1 -0
  54. package/dist/esm/key-management/es256-jws.js +135 -0
  55. package/dist/esm/key-management/es256-jws.js.map +1 -0
  56. package/dist/esm/key-management/key-provider.spi.d.ts +151 -0
  57. package/dist/esm/key-management/key-provider.spi.d.ts.map +1 -0
  58. package/dist/esm/key-management/key-provider.spi.js +38 -0
  59. package/dist/esm/key-management/key-provider.spi.js.map +1 -0
  60. package/dist/esm/key-management/keyring-rotation.contracts.d.ts +93 -0
  61. package/dist/esm/key-management/keyring-rotation.contracts.d.ts.map +1 -0
  62. package/dist/esm/key-management/keyring-rotation.contracts.js +101 -0
  63. package/dist/esm/key-management/keyring-rotation.contracts.js.map +1 -0
  64. package/dist/esm/key-management/keyring-status.contracts.d.ts +66 -0
  65. package/dist/esm/key-management/keyring-status.contracts.d.ts.map +1 -0
  66. package/dist/esm/key-management/keyring-status.contracts.js +45 -0
  67. package/dist/esm/key-management/keyring-status.contracts.js.map +1 -0
  68. package/dist/esm/key-management/signature-request.contracts.d.ts +95 -0
  69. package/dist/esm/key-management/signature-request.contracts.d.ts.map +1 -0
  70. package/dist/esm/key-management/signature-request.contracts.js +96 -0
  71. package/dist/esm/key-management/signature-request.contracts.js.map +1 -0
  72. package/dist/esm/key-management/signing-log-export.contracts.d.ts +216 -0
  73. package/dist/esm/key-management/signing-log-export.contracts.d.ts.map +1 -0
  74. package/dist/esm/key-management/signing-log-export.contracts.js +268 -0
  75. package/dist/esm/key-management/signing-log-export.contracts.js.map +1 -0
  76. package/dist/esm/key-management/vault-custody.contracts.d.ts +55 -0
  77. package/dist/esm/key-management/vault-custody.contracts.d.ts.map +1 -0
  78. package/dist/esm/key-management/vault-custody.contracts.js +88 -0
  79. package/dist/esm/key-management/vault-custody.contracts.js.map +1 -0
  80. package/dist/esm/lockfile/lockfile-io.d.ts +7 -9
  81. package/dist/esm/lockfile/lockfile-io.d.ts.map +1 -1
  82. package/dist/esm/lockfile/lockfile-io.js +23 -22
  83. package/dist/esm/lockfile/lockfile-io.js.map +1 -1
  84. package/dist/esm/lockfile/materialize-infra-section.d.ts +17 -14
  85. package/dist/esm/lockfile/materialize-infra-section.d.ts.map +1 -1
  86. package/dist/esm/lockfile/materialize-infra-section.js +9 -9
  87. package/dist/esm/lockfile/materialize-infra-section.js.map +1 -1
  88. package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.d.ts +26 -2
  89. package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.d.ts.map +1 -1
  90. package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.js +27 -2
  91. package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.js.map +1 -1
  92. package/dist/esm/project-config/application-public-pricing-catalog.loader.d.ts.map +1 -1
  93. package/dist/esm/project-config/application-public-pricing-catalog.loader.js +9 -2
  94. package/dist/esm/project-config/application-public-pricing-catalog.loader.js.map +1 -1
  95. package/dist/esm/project-config/application-served-public-documents.loader.d.ts +26 -0
  96. package/dist/esm/project-config/application-served-public-documents.loader.d.ts.map +1 -0
  97. package/dist/esm/project-config/application-served-public-documents.loader.js +78 -0
  98. package/dist/esm/project-config/application-served-public-documents.loader.js.map +1 -0
  99. package/dist/esm/project-config/define-infra-env-config.d.ts +236 -15
  100. package/dist/esm/project-config/define-infra-env-config.d.ts.map +1 -1
  101. package/dist/esm/project-config/define-infra-env-config.js +104 -91
  102. package/dist/esm/project-config/define-infra-env-config.js.map +1 -1
  103. package/dist/esm/project-config/define-saas-config.d.ts +133 -3
  104. package/dist/esm/project-config/define-saas-config.d.ts.map +1 -1
  105. package/dist/esm/project-config/define-saas-config.js +170 -19
  106. package/dist/esm/project-config/define-saas-config.js.map +1 -1
  107. package/dist/esm/project-config/hosted-infra-env-config.d.ts.map +1 -1
  108. package/dist/esm/project-config/hosted-infra-env-config.js +3 -0
  109. package/dist/esm/project-config/hosted-infra-env-config.js.map +1 -1
  110. package/dist/esm/project-config/index.d.ts +3 -0
  111. package/dist/esm/project-config/index.d.ts.map +1 -1
  112. package/dist/esm/project-config/index.js +3 -0
  113. package/dist/esm/project-config/index.js.map +1 -1
  114. package/dist/esm/project-config/npm-version-range.d.ts.map +1 -1
  115. package/dist/esm/project-config/npm-version-range.js +39 -16
  116. package/dist/esm/project-config/npm-version-range.js.map +1 -1
  117. package/dist/esm/project-config/owning-package-tsconfig.d.ts +15 -0
  118. package/dist/esm/project-config/owning-package-tsconfig.d.ts.map +1 -0
  119. package/dist/esm/project-config/owning-package-tsconfig.js +29 -0
  120. package/dist/esm/project-config/owning-package-tsconfig.js.map +1 -0
  121. package/dist/esm/project-config/provider-companion-discovery.d.ts +4 -4
  122. package/dist/esm/project-config/provider-companion-discovery.d.ts.map +1 -1
  123. package/dist/esm/project-config/provider-companion-discovery.js +13 -9
  124. package/dist/esm/project-config/provider-companion-discovery.js.map +1 -1
  125. package/dist/esm/project-config/provider-runtime-artifacts.d.ts +32 -3
  126. package/dist/esm/project-config/provider-runtime-artifacts.d.ts.map +1 -1
  127. package/dist/esm/project-config/provider-runtime-artifacts.js +67 -13
  128. package/dist/esm/project-config/provider-runtime-artifacts.js.map +1 -1
  129. package/dist/esm/project-config/shared/csp-defaults.d.ts +4 -5
  130. package/dist/esm/project-config/shared/csp-defaults.d.ts.map +1 -1
  131. package/dist/esm/project-config/shared/csp-defaults.js +4 -5
  132. package/dist/esm/project-config/shared/csp-defaults.js.map +1 -1
  133. package/dist/esm/project-config/shared/csp.schemas.d.ts +1 -2
  134. package/dist/esm/project-config/shared/csp.schemas.d.ts.map +1 -1
  135. package/dist/esm/project-config/shared/csp.schemas.js +1 -2
  136. package/dist/esm/project-config/shared/csp.schemas.js.map +1 -1
  137. package/dist/esm/project-config/shared/environment.schemas.d.ts +6 -0
  138. package/dist/esm/project-config/shared/environment.schemas.d.ts.map +1 -1
  139. package/dist/esm/project-config/shared/environment.schemas.js +8 -1
  140. package/dist/esm/project-config/shared/environment.schemas.js.map +1 -1
  141. package/dist/esm/project-config/shared/infrastructure-defaults.schemas.d.ts +1 -0
  142. package/dist/esm/project-config/shared/infrastructure-defaults.schemas.d.ts.map +1 -1
  143. package/dist/esm/project-config/shared/infrastructure-defaults.schemas.js +3 -0
  144. package/dist/esm/project-config/shared/infrastructure-defaults.schemas.js.map +1 -1
  145. package/dist/esm/project-config/shared/minion-resource-access.validation.d.ts +4 -0
  146. package/dist/esm/project-config/shared/minion-resource-access.validation.d.ts.map +1 -1
  147. package/dist/esm/project-config/shared/minion-resource-access.validation.js +6 -2
  148. package/dist/esm/project-config/shared/minion-resource-access.validation.js.map +1 -1
  149. package/dist/esm/project-config/shared/platform-key-management.schemas.d.ts +250 -0
  150. package/dist/esm/project-config/shared/platform-key-management.schemas.d.ts.map +1 -0
  151. package/dist/esm/project-config/shared/platform-key-management.schemas.js +194 -0
  152. package/dist/esm/project-config/shared/platform-key-management.schemas.js.map +1 -0
  153. package/dist/esm/registry/index.d.ts +1 -0
  154. package/dist/esm/registry/index.d.ts.map +1 -1
  155. package/dist/esm/registry/index.js +1 -0
  156. package/dist/esm/registry/index.js.map +1 -1
  157. package/dist/esm/registry/local-checkout-source.d.ts +22 -2
  158. package/dist/esm/registry/local-checkout-source.d.ts.map +1 -1
  159. package/dist/esm/registry/local-checkout-source.js +66 -3
  160. package/dist/esm/registry/local-checkout-source.js.map +1 -1
  161. package/dist/esm/registry/lockfile-modules-section.schemas.d.ts +10 -0
  162. package/dist/esm/registry/lockfile-modules-section.schemas.d.ts.map +1 -1
  163. package/dist/esm/registry/module-artifact.schemas.d.ts +23 -0
  164. package/dist/esm/registry/module-artifact.schemas.d.ts.map +1 -1
  165. package/dist/esm/registry/module-manifest.schemas.d.ts +336 -18
  166. package/dist/esm/registry/module-manifest.schemas.d.ts.map +1 -1
  167. package/dist/esm/registry/module-manifest.schemas.js +245 -19
  168. package/dist/esm/registry/module-manifest.schemas.js.map +1 -1
  169. package/dist/esm/registry/module-search.schemas.d.ts +2 -0
  170. package/dist/esm/registry/module-search.schemas.d.ts.map +1 -1
  171. package/dist/esm/registry/module-search.schemas.js +14 -1
  172. package/dist/esm/registry/module-search.schemas.js.map +1 -1
  173. package/dist/esm/registry/registry-errors.d.ts +22 -2
  174. package/dist/esm/registry/registry-errors.d.ts.map +1 -1
  175. package/dist/esm/registry/registry-errors.js +28 -2
  176. package/dist/esm/registry/registry-errors.js.map +1 -1
  177. package/dist/esm/registry/registry-section-schemas.constants.d.ts +5 -0
  178. package/dist/esm/registry/registry-section-schemas.constants.d.ts.map +1 -1
  179. package/dist/esm/registry/registry-url-resolution.d.ts +72 -0
  180. package/dist/esm/registry/registry-url-resolution.d.ts.map +1 -0
  181. package/dist/esm/registry/registry-url-resolution.js +157 -0
  182. package/dist/esm/registry/registry-url-resolution.js.map +1 -0
  183. package/dist/esm/schemas/framework-secrets.schemas.d.ts +55 -0
  184. package/dist/esm/schemas/framework-secrets.schemas.d.ts.map +1 -1
  185. package/dist/esm/schemas/framework-secrets.schemas.js +53 -0
  186. package/dist/esm/schemas/framework-secrets.schemas.js.map +1 -1
  187. package/dist/tsconfig.build.tsbuildinfo +1 -1
  188. package/package.json +7 -7
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key-provider.spi.js","sourceRoot":"","sources":["../../../../src/key-management/key-provider.spi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,UAAU,EAAE,WAAW,EAAkB,MAAM,aAAa,CAAC;AA+IxG,4CAA4C;AAC5C,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,CAAC;AAEjC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAEhC;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,WAAsB,EAAE,OAAmB,EAAE,cAA0B;IACxG,IAAI,OAAO,CAAC,MAAM,KAAK,cAAc;QAAE,MAAM,IAAI,KAAK,CAAC,iBAAiB,cAAc,eAAe,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;IACxH,MAAM,EAAE,GAAG,WAAW,CAAC,mBAAmB,CAAC,CAAC;IAC5C,MAAM,MAAM,GAAG,cAAc,CAAC,aAAa,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC;IAC9D,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC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W,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACrJ,CAAC","sourcesContent":["import { createCipheriv, createDecipheriv, createHash, randomBytes, type KeyObject } from 'node:crypto';\nimport type {\n CryptoKey_MaterialAccess,\n CryptoKey_MaterialProvenance,\n CryptoKey_OperationMode,\n CryptoKey_Primitive,\n CryptoKey_ProtectionLevel,\n CryptoKeyFloor,\n} from '@wildo-ai/saas-models';\nimport type { EcdsaSignatureEncoding, P256PublicJwk } from './es256-jws';\n\n/**\n * # The key provider SPI (#2891)\n *\n * What a key provider implements: the engine's LOCAL provider today, Vault, cloud KMS and HSM providers in slice 2\n * (#2933, #2896, #2934), a customer's own provider later (#2919). The custodian (apps-manager for platform custody)\n * drives a provider through this interface and nothing else; a consumer never reaches one, it asks the key-management\n * API by purpose.\n *\n * A provider declares, per key, how operations happen:\n * - **REMOTE**: the key never leaves. Every operation is a call: `signDigest` names the exact version (no call may\n * resolve \"latest\"), and the digest is SHA-256 over the ASCII JWS signing input (RFC 7515 §5.1).\n * - **RETRIEVED**: the provider hands the material to the custodian, which operates locally. The LOCAL provider is\n * RETRIEVED to its custodian only; the purpose's `heldBy` decides whether any runtime may retrieve too.\n *\n * Data-key wrapping (#2894): a wrapping version (`AES_256_GCM_DATA_KEY`) wraps the application's data keys. A REMOTE\n * provider wraps and unwraps itself (`wrapDataKey` / `unwrapDataKey`), with the associated data bound into the wrap; a\n * RETRIEVED provider hands the custodian the AES key and the custodian wraps locally ({@link wrapDataKeyLocally}). MAC is\n * not on this interface: no purpose's MAC key is provider-held (#2893's keys are the application's own).\n *\n * Verification is never a provider call: the custodian verifies every returned signature locally against the public\n * JWK of the version it named (verify-after-sign), and every verifier works from published public keys.\n */\n\n/** Names one version of one key at one provider, exactly. */\nexport interface KeyVersionRef {\n readonly providerRef: string;\n /** The provider's name for the key (a KMS key id, a Vault key name, a LOCAL key id). */\n readonly keyRef: string;\n /** The provider's name for the version. Never \"latest\". */\n readonly versionRef: string;\n}\n\n/** What a provider attests about one key version, re-read at every keyring refresh. */\nexport interface KeyVersionAttestation {\n readonly protectionLevel: CryptoKey_ProtectionLevel;\n readonly materialAccess: CryptoKey_MaterialAccess;\n readonly provenance: CryptoKey_MaterialProvenance;\n /** False once the provider has disabled or destroyed the version's private material. */\n readonly privateMaterialUsable: boolean;\n}\n\n/** A newly created key version. */\nexport interface CreatedKeyVersion {\n readonly ref: KeyVersionRef;\n readonly primitive: CryptoKey_Primitive;\n /** The public half, for an asymmetric primitive. */\n readonly publicJwk?: P256PublicJwk;\n readonly attestation: KeyVersionAttestation;\n}\n\n/**\n * What a vendor charges and allows for a provider's operations (#2896): stated, as prose a person reads, when a purpose is\n * bound to the provider, so the cost of binding a busy purpose to a paid KMS is never a surprise. Each value is the\n * vendor's published default at the time it was written; an account's own quota may differ, and the provider's source\n * file cites where each figure comes from.\n */\nexport interface KeyProviderVendorTerms {\n /** How many signing requests the vendor serves before throttling. */\n readonly signRequestQuota: string;\n /** What one signing request costs. */\n readonly signCost: string;\n /** What holding one key version costs. */\n readonly keyCost: string;\n /** How a throttle shows itself, and how the keyring treats it. */\n readonly throttling: string;\n /**\n * What wrapping a data key costs (#2894), for a provider that wraps: one wrap per data key, and one unwrap per data key\n * each time an application runtime starts, so far fewer calls than signatures.\n */\n readonly wrapCost?: string;\n /** Where the vendor records each signature, for corroboration against the signing log. */\n readonly auditLog: string;\n}\n\n/** A key provider, as the custodian drives it. */\nexport interface KeyProvider {\n readonly providerRef: string;\n /** How this provider performs operations. A provider may support both; the custodian prefers REMOTE. */\n readonly operationModes: readonly CryptoKey_OperationMode[];\n /** The encoding of the signatures `signDigest` returns; the custodian normalizes to raw R ‖ S. */\n readonly signatureEncoding: EcdsaSignatureEncoding;\n /** The primitives this provider can create keys for. */\n readonly primitives: readonly CryptoKey_Primitive[];\n /**\n * A paid vendor's terms, stated in apps-manager's log when the provider registers at boot (the moment the operator who\n * declared the account reads it); absent for a provider that costs nothing per call.\n */\n readonly vendorTerms?: KeyProviderVendorTerms;\n /**\n * The vendor's quota on signatures, as a rate, and what it is shared across. apps-manager keeps its own signing under\n * a share of it (a throttle answers a retryable PROVIDER_FAULT), so the relay retries instead of the vendor refusing.\n * Absent: the provider states no quota (a dedicated HSM's throughput is the operator's own).\n */\n readonly signRequestQuota?: { readonly perSecond: number; readonly sharedAcross: string };\n /**\n * The most this provider's DEPLOYMENT can offer, as configured: a Google key ring creating SOFTWARE keys, an Azure\n * vault making `EC` keys, a PKCS#11 token whose model is not allow-listed. The keyring refuses a purpose whose floor it\n * cannot meet BEFORE creating a version, rather than creating a vendor key and destroying it on every attempt. Absent:\n * only the version's own attestation is checked.\n */\n deploymentCeiling?(): Promise<CryptoKeyFloor>;\n\n /** Create a new version of `keyRef` (the key itself is created with its first version). */\n createKeyVersion(input: { readonly keyRef: string; readonly primitive: CryptoKey_Primitive }): Promise<CreatedKeyVersion>;\n /** What the provider attests about the version now. */\n describeKeyVersion(ref: KeyVersionRef): Promise<KeyVersionAttestation>;\n /** The public half of an asymmetric version. */\n getPublicKey(ref: KeyVersionRef): Promise<P256PublicJwk>;\n /** REMOTE: sign a SHA-256 digest with exactly this version. */\n signDigest?(ref: KeyVersionRef, digest: Uint8Array): Promise<Uint8Array>;\n /** RETRIEVED: the private (or secret, for a wrapping key) material of exactly this version, to the custodian. */\n retrieveKeyMaterial?(ref: KeyVersionRef): Promise<KeyObject>;\n /**\n * REMOTE: wrap a data key under exactly this wrapping version, binding `associatedData` into the wrap, so a wrapped key\n * moved to another data key's row does not unwrap. The wrap must be AUTHENTICATED encryption made with a secret only the\n * provider holds (AES-GCM and its vendor forms): a public-key wrap (RSA `wrapKey`) can be made by anyone holding the\n * public half, so a substituted data key would unwrap (#2894 stage D review). Returns the provider's opaque wrapped form.\n */\n wrapDataKey?(ref: KeyVersionRef, dataKey: Uint8Array, associatedData: Uint8Array): Promise<Uint8Array>;\n /** REMOTE: unwrap what {@link wrapDataKey} returned, refusing it under any other associated data. */\n unwrapDataKey?(ref: KeyVersionRef, wrapped: Uint8Array, associatedData: Uint8Array): Promise<Uint8Array>;\n /** Stop the version from signing; its material is kept until destroyed. */\n disableKeyVersion(ref: KeyVersionRef): Promise<void>;\n /** Destroy the version's private material. Irreversible; the public half is the custodian's to keep. */\n destroyKeyVersion(ref: KeyVersionRef): Promise<void>;\n /**\n * Whether the version's private material can still be used: false when what protects it is gone (the LOCAL provider's\n * key-encryption root was lost). Only a provider that can LOSE its own access implements it; absent means always.\n */\n materialIsReadable?(ref: KeyVersionRef): Promise<boolean>;\n}\n\n/** A data key is an AES-256 key (#2894). */\nexport const DATA_KEY_BYTES = 32;\n\nconst LOCAL_WRAP_IV_BYTES = 12;\nconst LOCAL_WRAP_TAG_BYTES = 16;\n\n/**\n * Wrap a data key with a wrapping key the custodian holds (a RETRIEVED provider's version): AES-256-GCM with a random IV,\n * the associated data authenticated, as `iv ‖ tag ‖ ciphertext`. One IV per wrap, and a wrapping key wraps few keys (one\n * per data key, each used for many values), far below the 2^32 random-IV bound (NIST SP 800-38D §8.3).\n */\nexport function wrapDataKeyLocally(wrappingKey: KeyObject, dataKey: Uint8Array, associatedData: Uint8Array): Uint8Array {\n if (dataKey.length !== DATA_KEY_BYTES) throw new Error(`A data key is ${DATA_KEY_BYTES} bytes, not ${dataKey.length}.`);\n const iv = randomBytes(LOCAL_WRAP_IV_BYTES);\n const cipher = createCipheriv('aes-256-gcm', wrappingKey, iv);\n cipher.setAAD(associatedData);\n const ciphertext = Buffer.concat([cipher.update(dataKey), cipher.final()]);\n return Buffer.concat([iv, cipher.getAuthTag(), ciphertext]);\n}\n\n/** Unwrap what {@link wrapDataKeyLocally} returned; throws when the wrap, the key or the associated data differ. */\nexport function unwrapDataKeyLocally(wrappingKey: KeyObject, wrapped: Uint8Array, associatedData: Uint8Array): Uint8Array {\n const bytes = Buffer.from(wrapped);\n if (bytes.length !== LOCAL_WRAP_IV_BYTES + LOCAL_WRAP_TAG_BYTES + DATA_KEY_BYTES) throw new Error('Not a locally wrapped data key.');\n const decipher = createDecipheriv('aes-256-gcm', wrappingKey, bytes.subarray(0, LOCAL_WRAP_IV_BYTES));\n decipher.setAAD(associatedData);\n decipher.setAuthTag(bytes.subarray(LOCAL_WRAP_IV_BYTES, LOCAL_WRAP_IV_BYTES + LOCAL_WRAP_TAG_BYTES));\n return Buffer.concat([decipher.update(bytes.subarray(LOCAL_WRAP_IV_BYTES + LOCAL_WRAP_TAG_BYTES)), decipher.final()]);\n}\n\n/**\n * The `kid` of a wrapping version (#2894). A signing version's `kid` is its public key's thumbprint; a wrapping key has no\n * public half, so its `kid` is derived from the version's provider references, never from its material, and names it in\n * every envelope sealed under a data key it wraps.\n */\nexport function wrappingKeyKidOf(ref: KeyVersionRef): string {\n return createHash('sha256').update(`wildo-wrapping-key-id:v1|${ref.providerRef}|${ref.keyRef}|${ref.versionRef}`).digest('base64url').slice(0, 22);\n}\n"]}
@@ -0,0 +1,93 @@
1
+ import { z } from 'zod';
2
+ import { CryptoKey_Purpose } from '@wildo-ai/saas-models';
3
+ /**
4
+ * # Rotating a keyring by hand (#2891)
5
+ *
6
+ * The operator's door onto an application's keyring, behind apps-manager's admin secret (`wildo keys rotate`). Three
7
+ * modes, because three different things happened:
8
+ *
9
+ * - {@link KeyringRotationMode.PLANNED}: the published NEXT version is promoted and the ACTIVE one retires, still
10
+ * verifying everything it signed. Refused while NEXT is younger than {@link NEXT_KEY_PUBLICATION_LEAD_SECONDS}: a
11
+ * verifier may not hold it yet.
12
+ * - {@link KeyringRotationMode.EMERGENCY}: the key may have LEAKED. ACTIVE is marked COMPROMISED from the operator's
13
+ * earliest estimate of exposure, its private material is destroyed at once, and NEXT is promoted. Seals made before
14
+ * that instant can still be corroborated; seals after it cannot.
15
+ * - {@link KeyringRotationMode.ROOT_LOST}: the key-encryption root that sealed the LOCAL keys is gone (and not leaked).
16
+ * No sealed key can be opened again, so every version whose material cannot be read is DESTROYED (its public half
17
+ * stays, and still verifies what it signed) and a fresh ACTIVE and NEXT are made under the current root.
18
+ *
19
+ * Only a purpose whose key is held in the platform keyring can be rotated here. The runtime-response key is held in
20
+ * apps-manager's environment ({@link CryptoKey_Holding.CUSTODIAN_ENVIRONMENT}): rotate it by promoting
21
+ * `platform.appsManagerResponseSigning.next*` to the current pair in the environment's secrets, minting a new next, and
22
+ * running `wildo config sync`. A rotation request for it is refused rather than reported as done.
23
+ */
24
+ /** Which rotation the operator is asking for. */
25
+ export declare enum KeyringRotationMode {
26
+ PLANNED = "planned",
27
+ EMERGENCY = "emergency",
28
+ ROOT_LOST = "root_lost"
29
+ }
30
+ /**
31
+ * How long a NEXT version must have been published before a planned rotation may promote it: the application's refresh
32
+ * interval (5 minutes) plus the seal JWKS cache lifetime (5 minutes), with margin. A verifier that fetched the key set
33
+ * just before the NEXT version existed holds it by then.
34
+ */
35
+ export declare const NEXT_KEY_PUBLICATION_LEAD_SECONDS: number;
36
+ /** The admin path of an application's keyring rotation. */
37
+ export declare function buildAdminKeyringRotationPath(appSlug: string): string;
38
+ /** Whether a purpose's key is held in the platform keyring, so the rotation door may act on it. */
39
+ export declare function cryptoKeyPurposeIsKeyringHeld(purpose: CryptoKey_Purpose): boolean;
40
+ /**
41
+ * Why a purpose the keyring does not hold cannot be rotated here, and what to do instead, by where its key IS held. Each
42
+ * holding has its own procedure (#2892 review F9): an application's own keys have none yet, so pointing at the
43
+ * response-key procedure would send an operator to a step that changes nothing.
44
+ */
45
+ export declare function keyringRotationRefusalOf(purpose: CryptoKey_Purpose): string | undefined;
46
+ export declare const KeyringRotationRequestSchema: z.ZodObject<{
47
+ purpose: z.ZodDefault<z.ZodEnum<typeof CryptoKey_Purpose>>;
48
+ /** For an organization-scoped binding: the organization whose key rotates. Absent for an application-scoped one. */
49
+ organizationId: z.ZodOptional<z.ZodString>;
50
+ mode: z.ZodDefault<z.ZodEnum<typeof KeyringRotationMode>>;
51
+ /**
52
+ * Emergency only, and required there: the earliest instant the key may have been exposed (ISO 8601). Never defaulted
53
+ * to now, which would vouch for every seal made between the leak and its discovery, and never in the future, which
54
+ * would vouch for seals not yet made.
55
+ */
56
+ compromiseInstant: z.ZodOptional<z.ZodISODateTime>;
57
+ /**
58
+ * Emergency and root-lost only, and required there: why, in the operator's words. Recorded on the audit row, where the
59
+ * shared admin secret names nobody. A planned rotation records no reason, so it accepts none.
60
+ */
61
+ justification: z.ZodOptional<z.ZodString>;
62
+ }, z.core.$strict>;
63
+ export type KeyringRotationRequest = z.input<typeof KeyringRotationRequestSchema>;
64
+ /** The answer: the application's keyring status after the rotation. */
65
+ export declare const KeyringRotationResponseSchema: z.ZodObject<{
66
+ iss: z.ZodString;
67
+ versions: z.ZodArray<z.ZodObject<{
68
+ kid: z.ZodString;
69
+ alg: z.ZodLiteral<"ES256">;
70
+ purpose: z.ZodEnum<typeof CryptoKey_Purpose>;
71
+ scope: z.ZodEnum<typeof import("@wildo-ai/saas-models").CryptoKey_Scope>;
72
+ scopeId: z.ZodString;
73
+ generation: z.ZodNumber;
74
+ state: z.ZodEnum<typeof import("@wildo-ai/saas-models").CryptoKey_VersionState>;
75
+ providerRef: z.ZodString;
76
+ protectionLevel: z.ZodEnum<typeof import("@wildo-ai/saas-models").CryptoKey_ProtectionLevel>;
77
+ materialAccess: z.ZodEnum<typeof import("@wildo-ai/saas-models").CryptoKey_MaterialAccess>;
78
+ provenance: z.ZodEnum<typeof import("@wildo-ai/saas-models").CryptoKey_MaterialProvenance>;
79
+ publicJwk: z.ZodObject<{
80
+ kty: z.ZodLiteral<"EC">;
81
+ crv: z.ZodLiteral<"P-256">;
82
+ x: z.ZodString;
83
+ y: z.ZodString;
84
+ }, z.core.$strict>;
85
+ createdAt: z.ZodString;
86
+ activatedAt: z.ZodOptional<z.ZodString>;
87
+ retiredAt: z.ZodOptional<z.ZodString>;
88
+ compromisedAt: z.ZodOptional<z.ZodString>;
89
+ compromiseInstant: z.ZodOptional<z.ZodString>;
90
+ privateMaterialDestroyedAt: z.ZodOptional<z.ZodString>;
91
+ }, z.core.$strict>>;
92
+ }, z.core.$strict>;
93
+ //# sourceMappingURL=keyring-rotation.contracts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyring-rotation.contracts.d.ts","sourceRoot":"","sources":["../../../../src/key-management/keyring-rotation.contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAqD,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAI7G;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,iDAAiD;AACjD,oBAAY,mBAAmB;IAC7B,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,SAAS,cAAc;CACxB;AAED;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,QAAU,CAAC;AAEzD,2DAA2D;AAC3D,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,mGAAmG;AACnG,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAEjF;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,GAAG,SAAS,CAcvF;AAED,eAAO,MAAM,4BAA4B;;IAGrC,oHAAoH;;;IAGpH;;;;OAIG;;IAEH;;;OAGG;;kBAkBH,CAAC;AACL,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAElF,uEAAuE;AACvE,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAAsB,CAAC"}
@@ -0,0 +1,101 @@
1
+ import { z } from 'zod';
2
+ import { CRYPTO_KEY_PURPOSE_DESCRIPTORS, CryptoKey_Holding, CryptoKey_Purpose } from '@wildo-ai/saas-models';
3
+ import { KeyringStatusSchema } from './keyring-status.contracts.js';
4
+ import { SIGNATURE_CLOCK_SKEW_TOLERANCE_SECONDS } from './signature-request.contracts.js';
5
+ /**
6
+ * # Rotating a keyring by hand (#2891)
7
+ *
8
+ * The operator's door onto an application's keyring, behind apps-manager's admin secret (`wildo keys rotate`). Three
9
+ * modes, because three different things happened:
10
+ *
11
+ * - {@link KeyringRotationMode.PLANNED}: the published NEXT version is promoted and the ACTIVE one retires, still
12
+ * verifying everything it signed. Refused while NEXT is younger than {@link NEXT_KEY_PUBLICATION_LEAD_SECONDS}: a
13
+ * verifier may not hold it yet.
14
+ * - {@link KeyringRotationMode.EMERGENCY}: the key may have LEAKED. ACTIVE is marked COMPROMISED from the operator's
15
+ * earliest estimate of exposure, its private material is destroyed at once, and NEXT is promoted. Seals made before
16
+ * that instant can still be corroborated; seals after it cannot.
17
+ * - {@link KeyringRotationMode.ROOT_LOST}: the key-encryption root that sealed the LOCAL keys is gone (and not leaked).
18
+ * No sealed key can be opened again, so every version whose material cannot be read is DESTROYED (its public half
19
+ * stays, and still verifies what it signed) and a fresh ACTIVE and NEXT are made under the current root.
20
+ *
21
+ * Only a purpose whose key is held in the platform keyring can be rotated here. The runtime-response key is held in
22
+ * apps-manager's environment ({@link CryptoKey_Holding.CUSTODIAN_ENVIRONMENT}): rotate it by promoting
23
+ * `platform.appsManagerResponseSigning.next*` to the current pair in the environment's secrets, minting a new next, and
24
+ * running `wildo config sync`. A rotation request for it is refused rather than reported as done.
25
+ */
26
+ /** Which rotation the operator is asking for. */
27
+ export var KeyringRotationMode;
28
+ (function (KeyringRotationMode) {
29
+ KeyringRotationMode["PLANNED"] = "planned";
30
+ KeyringRotationMode["EMERGENCY"] = "emergency";
31
+ KeyringRotationMode["ROOT_LOST"] = "root_lost";
32
+ })(KeyringRotationMode || (KeyringRotationMode = {}));
33
+ /**
34
+ * How long a NEXT version must have been published before a planned rotation may promote it: the application's refresh
35
+ * interval (5 minutes) plus the seal JWKS cache lifetime (5 minutes), with margin. A verifier that fetched the key set
36
+ * just before the NEXT version existed holds it by then.
37
+ */
38
+ export const NEXT_KEY_PUBLICATION_LEAD_SECONDS = 15 * 60;
39
+ /** The admin path of an application's keyring rotation. */
40
+ export function buildAdminKeyringRotationPath(appSlug) {
41
+ return `/admin/apps/${encodeURIComponent(appSlug)}/keys/rotate`;
42
+ }
43
+ /** Whether a purpose's key is held in the platform keyring, so the rotation door may act on it. */
44
+ export function cryptoKeyPurposeIsKeyringHeld(purpose) {
45
+ return CRYPTO_KEY_PURPOSE_DESCRIPTORS[purpose].holding === CryptoKey_Holding.PLATFORM_KEYRING;
46
+ }
47
+ /**
48
+ * Why a purpose the keyring does not hold cannot be rotated here, and what to do instead, by where its key IS held. Each
49
+ * holding has its own procedure (#2892 review F9): an application's own keys have none yet, so pointing at the
50
+ * response-key procedure would send an operator to a step that changes nothing.
51
+ */
52
+ export function keyringRotationRefusalOf(purpose) {
53
+ switch (CRYPTO_KEY_PURPOSE_DESCRIPTORS[purpose].holding) {
54
+ case CryptoKey_Holding.PLATFORM_KEYRING:
55
+ return undefined;
56
+ case CryptoKey_Holding.CUSTODIAN_ENVIRONMENT:
57
+ return `The ${purpose} key is held in apps-manager's environment, not the keyring: rotate it by promoting the next response key in the environment's secrets and running \`wildo config sync\`.`;
58
+ case CryptoKey_Holding.APPLICATION_SECRETS:
59
+ return `The ${purpose} key is held in the application's secrets, not the keyring, and its rotation is not built yet (#2895). A key that is missing is minted at the next registration (\`wildo local init\`).`;
60
+ default: {
61
+ // A holding added later must name its procedure here: an unhandled one would otherwise read as keyring-held.
62
+ const unhandled = CRYPTO_KEY_PURPOSE_DESCRIPTORS[purpose].holding;
63
+ return `The ${purpose} key's holding (${String(unhandled)}) has no rotation procedure here.`;
64
+ }
65
+ }
66
+ }
67
+ export const KeyringRotationRequestSchema = z
68
+ .strictObject({
69
+ purpose: z.enum(CryptoKey_Purpose).default(CryptoKey_Purpose.APPROVAL_SEAL),
70
+ /** For an organization-scoped binding: the organization whose key rotates. Absent for an application-scoped one. */
71
+ organizationId: z.string().min(1).optional(),
72
+ mode: z.enum(KeyringRotationMode).default(KeyringRotationMode.PLANNED),
73
+ /**
74
+ * Emergency only, and required there: the earliest instant the key may have been exposed (ISO 8601). Never defaulted
75
+ * to now, which would vouch for every seal made between the leak and its discovery, and never in the future, which
76
+ * would vouch for seals not yet made.
77
+ */
78
+ compromiseInstant: z.iso.datetime({ offset: true }).optional(),
79
+ /**
80
+ * Emergency and root-lost only, and required there: why, in the operator's words. Recorded on the audit row, where the
81
+ * shared admin secret names nobody. A planned rotation records no reason, so it accepts none.
82
+ */
83
+ justification: z.string().trim().min(10).optional(),
84
+ })
85
+ .superRefine((request, ctx) => {
86
+ const refusal = keyringRotationRefusalOf(request.purpose);
87
+ if (refusal)
88
+ ctx.addIssue({ code: 'custom', message: refusal, path: ['purpose'] });
89
+ })
90
+ .refine((request) => (request.mode === KeyringRotationMode.EMERGENCY) === (request.compromiseInstant !== undefined), {
91
+ message: 'An emergency rotation states the earliest instant the key may have been exposed (compromiseInstant); no other rotation takes one.',
92
+ path: ['compromiseInstant'],
93
+ })
94
+ .refine((request) => request.compromiseInstant === undefined || new Date(request.compromiseInstant).getTime() <= Date.now() + SIGNATURE_CLOCK_SKEW_TOLERANCE_SECONDS * 1000, { message: 'The compromise instant is in the future: name the earliest instant the key may already have been exposed.', path: ['compromiseInstant'] })
95
+ .refine((request) => (request.mode !== KeyringRotationMode.PLANNED) === (request.justification !== undefined), {
96
+ message: 'An emergency or root-lost rotation states why (justification); a planned one records no reason and takes none.',
97
+ path: ['justification'],
98
+ });
99
+ /** The answer: the application's keyring status after the rotation. */
100
+ export const KeyringRotationResponseSchema = KeyringStatusSchema;
101
+ //# sourceMappingURL=keyring-rotation.contracts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyring-rotation.contracts.js","sourceRoot":"","sources":["../../../../src/key-management/keyring-rotation.contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,8BAA8B,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC7G,OAAO,EAA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I,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,OAAO,EAAE,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,sCAAsC,GAAG,IAAI,EACnK,EAAE,OAAO,EAAE,2GAA2G,EAAE,IAAI,EAAE,CAAC,mBAAmB,CAAC,EAAE,CACtJ;KACA,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,KAAK,mBAAmB,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,KAAK,SAAS,CAAC,EAAE;IAC7G,OAAO,EAAE,gHAAgH;IACzH,IAAI,EAAE,CAAC,eAAe,CAAC;CACxB,CAAC,CAAC;AAGL,uEAAuE;AACvE,MAAM,CAAC,MAAM,6BAA6B,GAAG,mBAAmB,CAAC","sourcesContent":["import { z } from 'zod';\nimport { CRYPTO_KEY_PURPOSE_DESCRIPTORS, CryptoKey_Holding, CryptoKey_Purpose } from '@wildo-ai/saas-models';\nimport { KeyringStatusSchema } from './keyring-status.contracts';\nimport { SIGNATURE_CLOCK_SKEW_TOLERANCE_SECONDS } from './signature-request.contracts';\n\n/**\n * # Rotating a keyring by hand (#2891)\n *\n * The operator's door onto an application's keyring, behind apps-manager's admin secret (`wildo keys rotate`). Three\n * modes, because three different things happened:\n *\n * - {@link KeyringRotationMode.PLANNED}: the published NEXT version is promoted and the ACTIVE one retires, still\n * verifying everything it signed. Refused while NEXT is younger than {@link NEXT_KEY_PUBLICATION_LEAD_SECONDS}: a\n * verifier may not hold it yet.\n * - {@link KeyringRotationMode.EMERGENCY}: the key may have LEAKED. ACTIVE is marked COMPROMISED from the operator's\n * earliest estimate of exposure, its private material is destroyed at once, and NEXT is promoted. Seals made before\n * that instant can still be corroborated; seals after it cannot.\n * - {@link KeyringRotationMode.ROOT_LOST}: the key-encryption root that sealed the LOCAL keys is gone (and not leaked).\n * No sealed key can be opened again, so every version whose material cannot be read is DESTROYED (its public half\n * stays, and still verifies what it signed) and a fresh ACTIVE and NEXT are made under the current root.\n *\n * Only a purpose whose key is held in the platform keyring can be rotated here. The runtime-response key is held in\n * apps-manager's environment ({@link CryptoKey_Holding.CUSTODIAN_ENVIRONMENT}): rotate it by promoting\n * `platform.appsManagerResponseSigning.next*` to the current pair in the environment's secrets, minting a new next, and\n * running `wildo config sync`. A rotation request for it is refused rather than reported as done.\n */\n\n/** Which rotation the operator is asking for. */\nexport enum KeyringRotationMode {\n PLANNED = 'planned',\n EMERGENCY = 'emergency',\n ROOT_LOST = 'root_lost',\n}\n\n/**\n * How long a NEXT version must have been published before a planned rotation may promote it: the application's refresh\n * interval (5 minutes) plus the seal JWKS cache lifetime (5 minutes), with margin. A verifier that fetched the key set\n * just before the NEXT version existed holds it by then.\n */\nexport const NEXT_KEY_PUBLICATION_LEAD_SECONDS = 15 * 60;\n\n/** The admin path of an application's keyring rotation. */\nexport function buildAdminKeyringRotationPath(appSlug: string): string {\n return `/admin/apps/${encodeURIComponent(appSlug)}/keys/rotate`;\n}\n\n/** Whether a purpose's key is held in the platform keyring, so the rotation door may act on it. */\nexport function cryptoKeyPurposeIsKeyringHeld(purpose: CryptoKey_Purpose): boolean {\n return CRYPTO_KEY_PURPOSE_DESCRIPTORS[purpose].holding === CryptoKey_Holding.PLATFORM_KEYRING;\n}\n\n/**\n * Why a purpose the keyring does not hold cannot be rotated here, and what to do instead, by where its key IS held. Each\n * holding has its own procedure (#2892 review F9): an application's own keys have none yet, so pointing at the\n * response-key procedure would send an operator to a step that changes nothing.\n */\nexport function keyringRotationRefusalOf(purpose: CryptoKey_Purpose): string | undefined {\n switch (CRYPTO_KEY_PURPOSE_DESCRIPTORS[purpose].holding) {\n case CryptoKey_Holding.PLATFORM_KEYRING:\n return undefined;\n case CryptoKey_Holding.CUSTODIAN_ENVIRONMENT:\n return `The ${purpose} key is held in apps-manager's environment, not the keyring: rotate it by promoting the next response key in the environment's secrets and running \\`wildo config sync\\`.`;\n case CryptoKey_Holding.APPLICATION_SECRETS:\n return `The ${purpose} key is held in the application's secrets, not the keyring, and its rotation is not built yet (#2895). A key that is missing is minted at the next registration (\\`wildo local init\\`).`;\n default: {\n // A holding added later must name its procedure here: an unhandled one would otherwise read as keyring-held.\n const unhandled: never = CRYPTO_KEY_PURPOSE_DESCRIPTORS[purpose].holding;\n return `The ${purpose} key's holding (${String(unhandled)}) has no rotation procedure here.`;\n }\n }\n}\n\nexport const KeyringRotationRequestSchema = z\n .strictObject({\n purpose: z.enum(CryptoKey_Purpose).default(CryptoKey_Purpose.APPROVAL_SEAL),\n /** For an organization-scoped binding: the organization whose key rotates. Absent for an application-scoped one. */\n organizationId: z.string().min(1).optional(),\n mode: z.enum(KeyringRotationMode).default(KeyringRotationMode.PLANNED),\n /**\n * Emergency only, and required there: the earliest instant the key may have been exposed (ISO 8601). Never defaulted\n * to now, which would vouch for every seal made between the leak and its discovery, and never in the future, which\n * would vouch for seals not yet made.\n */\n compromiseInstant: z.iso.datetime({ offset: true }).optional(),\n /**\n * Emergency and root-lost only, and required there: why, in the operator's words. Recorded on the audit row, where the\n * shared admin secret names nobody. A planned rotation records no reason, so it accepts none.\n */\n justification: z.string().trim().min(10).optional(),\n })\n .superRefine((request, ctx) => {\n const refusal = keyringRotationRefusalOf(request.purpose);\n if (refusal) ctx.addIssue({ code: 'custom', message: refusal, path: ['purpose'] });\n })\n .refine((request) => (request.mode === KeyringRotationMode.EMERGENCY) === (request.compromiseInstant !== undefined), {\n message: 'An emergency rotation states the earliest instant the key may have been exposed (compromiseInstant); no other rotation takes one.',\n path: ['compromiseInstant'],\n })\n .refine(\n (request) => request.compromiseInstant === undefined || new Date(request.compromiseInstant).getTime() <= Date.now() + SIGNATURE_CLOCK_SKEW_TOLERANCE_SECONDS * 1000,\n { message: 'The compromise instant is in the future: name the earliest instant the key may already have been exposed.', path: ['compromiseInstant'] },\n )\n .refine((request) => (request.mode !== KeyringRotationMode.PLANNED) === (request.justification !== undefined), {\n message: 'An emergency or root-lost rotation states why (justification); a planned one records no reason and takes none.',\n path: ['justification'],\n });\nexport type KeyringRotationRequest = z.input<typeof KeyringRotationRequestSchema>;\n\n/** The answer: the application's keyring status after the rotation. */\nexport const KeyringRotationResponseSchema = KeyringStatusSchema;\n"]}
@@ -0,0 +1,66 @@
1
+ import { z } from 'zod';
2
+ import { CryptoKey_MaterialAccess, CryptoKey_MaterialProvenance, CryptoKey_ProtectionLevel, CryptoKey_Purpose, CryptoKey_Scope, CryptoKey_VersionState } from '@wildo-ai/saas-models';
3
+ /** One key version, as the application stores it. Instants are ISO 8601. */
4
+ export declare const KeyringStatusVersionSchema: z.ZodObject<{
5
+ kid: z.ZodString;
6
+ /** The JWS algorithm the key verifies; pinned per key, never taken from a seal's header. */
7
+ alg: z.ZodLiteral<"ES256">;
8
+ purpose: z.ZodEnum<typeof CryptoKey_Purpose>;
9
+ scope: z.ZodEnum<typeof CryptoKey_Scope>;
10
+ /** The application's id for an application-scoped key, the organization's for an organization-scoped one. */
11
+ scopeId: z.ZodString;
12
+ generation: z.ZodNumber;
13
+ state: z.ZodEnum<typeof CryptoKey_VersionState>;
14
+ providerRef: z.ZodString;
15
+ protectionLevel: z.ZodEnum<typeof CryptoKey_ProtectionLevel>;
16
+ materialAccess: z.ZodEnum<typeof CryptoKey_MaterialAccess>;
17
+ provenance: z.ZodEnum<typeof CryptoKey_MaterialProvenance>;
18
+ publicJwk: z.ZodObject<{
19
+ kty: z.ZodLiteral<"EC">;
20
+ crv: z.ZodLiteral<"P-256">;
21
+ x: z.ZodString;
22
+ y: z.ZodString;
23
+ }, z.core.$strict>;
24
+ createdAt: z.ZodString;
25
+ activatedAt: z.ZodOptional<z.ZodString>;
26
+ retiredAt: z.ZodOptional<z.ZodString>;
27
+ compromisedAt: z.ZodOptional<z.ZodString>;
28
+ /** The earliest instant the material may have been exposed: a seal before it can still be corroborated. */
29
+ compromiseInstant: z.ZodOptional<z.ZodString>;
30
+ privateMaterialDestroyedAt: z.ZodOptional<z.ZodString>;
31
+ }, z.core.$strict>;
32
+ export type KeyringStatusVersion = z.infer<typeof KeyringStatusVersionSchema>;
33
+ export declare const KeyringStatusSchema: z.ZodObject<{
34
+ /** The issuer the custodian sets on this application's seals. */
35
+ iss: z.ZodString;
36
+ versions: z.ZodArray<z.ZodObject<{
37
+ kid: z.ZodString;
38
+ /** The JWS algorithm the key verifies; pinned per key, never taken from a seal's header. */
39
+ alg: z.ZodLiteral<"ES256">;
40
+ purpose: z.ZodEnum<typeof CryptoKey_Purpose>;
41
+ scope: z.ZodEnum<typeof CryptoKey_Scope>;
42
+ /** The application's id for an application-scoped key, the organization's for an organization-scoped one. */
43
+ scopeId: z.ZodString;
44
+ generation: z.ZodNumber;
45
+ state: z.ZodEnum<typeof CryptoKey_VersionState>;
46
+ providerRef: z.ZodString;
47
+ protectionLevel: z.ZodEnum<typeof CryptoKey_ProtectionLevel>;
48
+ materialAccess: z.ZodEnum<typeof CryptoKey_MaterialAccess>;
49
+ provenance: z.ZodEnum<typeof CryptoKey_MaterialProvenance>;
50
+ publicJwk: z.ZodObject<{
51
+ kty: z.ZodLiteral<"EC">;
52
+ crv: z.ZodLiteral<"P-256">;
53
+ x: z.ZodString;
54
+ y: z.ZodString;
55
+ }, z.core.$strict>;
56
+ createdAt: z.ZodString;
57
+ activatedAt: z.ZodOptional<z.ZodString>;
58
+ retiredAt: z.ZodOptional<z.ZodString>;
59
+ compromisedAt: z.ZodOptional<z.ZodString>;
60
+ /** The earliest instant the material may have been exposed: a seal before it can still be corroborated. */
61
+ compromiseInstant: z.ZodOptional<z.ZodString>;
62
+ privateMaterialDestroyedAt: z.ZodOptional<z.ZodString>;
63
+ }, z.core.$strict>>;
64
+ }, z.core.$strict>;
65
+ export type KeyringStatus = z.infer<typeof KeyringStatusSchema>;
66
+ //# sourceMappingURL=keyring-status.contracts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyring-status.contracts.d.ts","sourceRoot":"","sources":["../../../../src/key-management/keyring-status.contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,wBAAwB,EACxB,4BAA4B,EAC5B,yBAAyB,EACzB,iBAAiB,EACjB,eAAe,EACf,sBAAsB,EACvB,MAAM,uBAAuB,CAAC;AAiB/B,4EAA4E;AAC5E,eAAO,MAAM,0BAA0B;;IAErC,4FAA4F;;;;IAI5F,6GAA6G;;;;;;;;;;;;;;;;;;IAa7G,2GAA2G;;;kBAG3G,CAAC;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAE9E,eAAO,MAAM,mBAAmB;IAC9B,iEAAiE;;;;QAxBjE,4FAA4F;;;;QAI5F,6GAA6G;;;;;;;;;;;;;;;;;;QAa7G,2GAA2G;;;;kBAU3G,CAAC;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
@@ -0,0 +1,45 @@
1
+ import { z } from 'zod';
2
+ import { CryptoKey_MaterialAccess, CryptoKey_MaterialProvenance, CryptoKey_ProtectionLevel, CryptoKey_Purpose, CryptoKey_Scope, CryptoKey_VersionState, } from '@wildo-ai/saas-models';
3
+ import { ES256_JWS_ALGORITHM } from './es256-jws.js';
4
+ /**
5
+ * # Keyring status (#2891)
6
+ *
7
+ * What the platform custodian tells an application about the keys it signs with for it: every version of every
8
+ * published-verification keyring, public halves only, in a SIGNED answer (#2921). The application stores each version in
9
+ * its own `publishedVerificationKeys` resource, so a seal it holds verifies from its own store, and keeps verifying after
10
+ * a rotation, after the keyring is rebuilt, and after the application moves to another platform.
11
+ *
12
+ * A COMPROMISED version is listed with its compromise instant, so the application can move it out of its live JWKS and
13
+ * into its compromised-keys document. A DESTROYED version is listed too: only its private half is gone.
14
+ */
15
+ const P256PublicJwkSchema = z.strictObject({ kty: z.literal('EC'), crv: z.literal('P-256'), x: z.string().min(1), y: z.string().min(1) });
16
+ /** One key version, as the application stores it. Instants are ISO 8601. */
17
+ export const KeyringStatusVersionSchema = z.strictObject({
18
+ kid: z.string().min(1),
19
+ /** The JWS algorithm the key verifies; pinned per key, never taken from a seal's header. */
20
+ alg: z.literal(ES256_JWS_ALGORITHM),
21
+ purpose: z.enum(CryptoKey_Purpose),
22
+ scope: z.enum(CryptoKey_Scope),
23
+ /** The application's id for an application-scoped key, the organization's for an organization-scoped one. */
24
+ scopeId: z.string().min(1),
25
+ generation: z.number().int().min(1),
26
+ state: z.enum(CryptoKey_VersionState),
27
+ providerRef: z.string().min(1),
28
+ protectionLevel: z.enum(CryptoKey_ProtectionLevel),
29
+ materialAccess: z.enum(CryptoKey_MaterialAccess),
30
+ provenance: z.enum(CryptoKey_MaterialProvenance),
31
+ publicJwk: P256PublicJwkSchema,
32
+ createdAt: z.string(),
33
+ activatedAt: z.string().optional(),
34
+ retiredAt: z.string().optional(),
35
+ compromisedAt: z.string().optional(),
36
+ /** The earliest instant the material may have been exposed: a seal before it can still be corroborated. */
37
+ compromiseInstant: z.string().optional(),
38
+ privateMaterialDestroyedAt: z.string().optional(),
39
+ });
40
+ export const KeyringStatusSchema = z.strictObject({
41
+ /** The issuer the custodian sets on this application's seals. */
42
+ iss: z.string().min(1),
43
+ versions: z.array(KeyringStatusVersionSchema),
44
+ });
45
+ //# sourceMappingURL=keyring-status.contracts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyring-status.contracts.js","sourceRoot":"","sources":["../../../../src/key-management/keyring-status.contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,wBAAwB,EACxB,4BAA4B,EAC5B,yBAAyB,EACzB,iBAAiB,EACjB,eAAe,EACf,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD;;;;;;;;;;GAUG;AAEH,MAAM,mBAAmB,GAAG,CAAC,CAAC,YAAY,CAAC,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E,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACpC,2GAA2G;IAC3G,iBAAiB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACxC,0BAA0B,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAClD,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,YAAY,CAAC;IAChD,iEAAiE;IACjE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACtB,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,0BAA0B,CAAC;CAC9C,CAAC,CAAC","sourcesContent":["import { z } from 'zod';\nimport {\n CryptoKey_MaterialAccess,\n CryptoKey_MaterialProvenance,\n CryptoKey_ProtectionLevel,\n CryptoKey_Purpose,\n CryptoKey_Scope,\n CryptoKey_VersionState,\n} from '@wildo-ai/saas-models';\nimport { ES256_JWS_ALGORITHM } from './es256-jws';\n\n/**\n * # Keyring status (#2891)\n *\n * What the platform custodian tells an application about the keys it signs with for it: every version of every\n * published-verification keyring, public halves only, in a SIGNED answer (#2921). The application stores each version in\n * its own `publishedVerificationKeys` resource, so a seal it holds verifies from its own store, and keeps verifying after\n * a rotation, after the keyring is rebuilt, and after the application moves to another platform.\n *\n * A COMPROMISED version is listed with its compromise instant, so the application can move it out of its live JWKS and\n * into its compromised-keys document. A DESTROYED version is listed too: only its private half is gone.\n */\n\nconst P256PublicJwkSchema = z.strictObject({ kty: z.literal('EC'), crv: z.literal('P-256'), x: z.string().min(1), y: z.string().min(1) });\n\n/** One key version, as the application stores it. Instants are ISO 8601. */\nexport const KeyringStatusVersionSchema = z.strictObject({\n kid: z.string().min(1),\n /** The JWS algorithm the key verifies; pinned per key, never taken from a seal's header. */\n alg: z.literal(ES256_JWS_ALGORITHM),\n purpose: z.enum(CryptoKey_Purpose),\n scope: z.enum(CryptoKey_Scope),\n /** The application's id for an application-scoped key, the organization's for an organization-scoped one. */\n scopeId: z.string().min(1),\n generation: z.number().int().min(1),\n state: z.enum(CryptoKey_VersionState),\n providerRef: z.string().min(1),\n protectionLevel: z.enum(CryptoKey_ProtectionLevel),\n materialAccess: z.enum(CryptoKey_MaterialAccess),\n provenance: z.enum(CryptoKey_MaterialProvenance),\n publicJwk: P256PublicJwkSchema,\n createdAt: z.string(),\n activatedAt: z.string().optional(),\n retiredAt: z.string().optional(),\n compromisedAt: z.string().optional(),\n /** The earliest instant the material may have been exposed: a seal before it can still be corroborated. */\n compromiseInstant: z.string().optional(),\n privateMaterialDestroyedAt: z.string().optional(),\n});\nexport type KeyringStatusVersion = z.infer<typeof KeyringStatusVersionSchema>;\n\nexport const KeyringStatusSchema = z.strictObject({\n /** The issuer the custodian sets on this application's seals. */\n iss: z.string().min(1),\n versions: z.array(KeyringStatusVersionSchema),\n});\nexport type KeyringStatus = z.infer<typeof KeyringStatusSchema>;\n"]}
@@ -0,0 +1,95 @@
1
+ import { z } from 'zod';
2
+ import { CryptoKey_Purpose, type RateLimitConfiguration } from '@wildo-ai/saas-models';
3
+ /**
4
+ * # Asking the platform custodian for a signature (#2891)
5
+ *
6
+ * An application backend never holds a platform-custody key. It asks apps-manager, the custodian, to sign claims for a
7
+ * purpose, and apps-manager decides everything that makes the signature mean something: the issuer (from the
8
+ * application's own record), the key version (`kid`), the media type (`typ`) and the signing instant (`iat`). The request
9
+ * carries only what the application decided, the CLAIMS, and the digest of them it recorded when the decision committed.
10
+ *
11
+ * Both sides import this module, so the digest the application records at commit and the one the custodian recomputes
12
+ * are the same function.
13
+ */
14
+ /** The media type of an approval seal's JWS (`typ` header, RFC 7515 §4.1.9): its purpose's, from the descriptor. */
15
+ export declare const APPROVAL_SEAL_JWS_TYPE: string;
16
+ /**
17
+ * The claims the custodian sets itself, which a request may never carry: an application that could set `iss` could
18
+ * issue in another application's name, and one that could set `iat` could date its own seals. Refused rather than
19
+ * overwritten, so a caller that tries learns it.
20
+ */
21
+ export declare const CUSTODIAN_SET_CLAIMS: readonly string[];
22
+ /**
23
+ * How far a decision may be dated AFTER the signing instant: the two clocks are different machines. Five minutes, the
24
+ * customary leeway for JWT time claims (RFC 7519 §4.1.4 leaves it to the implementer; five minutes is what major JWT
25
+ * libraries and identity providers default to).
26
+ */
27
+ export declare const SIGNATURE_CLOCK_SKEW_TOLERANCE_SECONDS: number;
28
+ /**
29
+ * How long a request may be retried as the SAME request: the outbox that relays seals (#2903) gives up on a row after
30
+ * this age and marks it DEAD. Within it, the same claims get the signature already made back; past it, a re-drive is
31
+ * signed anew. Also the grace a retired key version keeps its private material for.
32
+ */
33
+ export declare const SIGNATURE_REQUEST_MAXIMUM_RETRY_AGE_SECONDS: number;
34
+ /** The longest apps-manager outage the platform is designed to absorb without an operator. */
35
+ export declare const LONGEST_SUPPORTED_CUSTODIAN_OUTAGE_SECONDS: number;
36
+ /**
37
+ * A decision older than this when it is signed is sealed with `lateSeal: true`, which the verifier shows. Longer than
38
+ * the retry age plus the longest supported outage, so no seal the normal path produces is late; a late seal is a
39
+ * re-driven DEAD one. An old decision is never refused: refusing would leave it with no seal at all.
40
+ */
41
+ export declare const LATE_SEAL_BOUND_SECONDS: number;
42
+ /**
43
+ * How often one application runtime may ask: per application and principal. A ceiling against a runaway loop, set well
44
+ * above any decision volume a person produces; bulk decisions are one seal over a list (#2903). A refusal for rate is
45
+ * retryable, never DEAD.
46
+ */
47
+ export declare const SIGNATURE_REQUEST_RATE_LIMIT: RateLimitConfiguration;
48
+ /**
49
+ * The approval seal's request claims, as far as the custodian checks them (#2891). The full seal shape is #2903's
50
+ * `ApprovalSealClaims`; the custodian needs only what it decides on: the seal's id, when the decision was taken, and
51
+ * the tenant (which selects an organization-scoped key). Other members pass through unchanged, and are covered by the
52
+ * decision-payload digest.
53
+ */
54
+ export declare const ApprovalSealRequestClaimsSchema: z.ZodObject<{
55
+ /** The seal's id, minted at commit: at least 128 bits, base64url. With `iss` it is the idempotency key. */
56
+ jti: z.ZodString;
57
+ /** When the decision was taken, in seconds since the epoch. Distinct from `iat`, when it was signed. */
58
+ decidedAt: z.ZodNumber;
59
+ /** The organization the decision was taken in. */
60
+ tenant: z.ZodString;
61
+ }, z.core.$loose>;
62
+ export type ApprovalSealRequestClaims = z.infer<typeof ApprovalSealRequestClaimsSchema>;
63
+ /** The claims schema of each purpose that may be requested. */
64
+ export declare const SIGNATURE_REQUEST_CLAIMS_SCHEMA_BY_PURPOSE: Readonly<Partial<Record<CryptoKey_Purpose, typeof ApprovalSealRequestClaimsSchema>>>;
65
+ /** The request body. */
66
+ export declare const SignatureRequestSchema: z.ZodObject<{
67
+ purpose: z.ZodEnum<typeof CryptoKey_Purpose>;
68
+ claims: z.ZodRecord<z.ZodString, z.ZodUnknown>;
69
+ /** {@link decisionPayloadDigestOf} the claims, as the application recorded it when the decision committed. */
70
+ decisionPayloadDigest: z.ZodString;
71
+ }, z.core.$strict>;
72
+ export type SignatureRequest = z.infer<typeof SignatureRequestSchema>;
73
+ /** The answer: the compact JWS and what the custodian decided in it. */
74
+ export interface SignatureResponse {
75
+ readonly jws: string;
76
+ readonly kid: string;
77
+ readonly iss: string;
78
+ readonly iat: number;
79
+ /** {@link sealClaimsDigestOf} the signed claims: with `iss` and `jti`, the seal's identity (never the JWS bytes). */
80
+ readonly claimsDigest: string;
81
+ readonly lateSeal: boolean;
82
+ /** True when the same claims had been signed already, and that signature is returned. */
83
+ readonly replayed: boolean;
84
+ }
85
+ /**
86
+ * The decision-payload digest: over every claim the APPLICATION decided, i.e. the request claims (the custodian-set
87
+ * claims are excluded by construction, since a request may not carry them). Recorded at commit, recomputed by the
88
+ * custodian, and a mismatch is refused.
89
+ */
90
+ export declare function decisionPayloadDigestOf(claims: Readonly<Record<string, unknown>>): string;
91
+ /** The signed claims' digest, custodian-set claims included: the seal's identity with (`iss`, `jti`). */
92
+ export declare function sealClaimsDigestOf(signedClaims: Readonly<Record<string, unknown>>): string;
93
+ /** The issuer the custodian sets for an application: a URN of its slug, which is stable and names no person. */
94
+ export declare function signatureIssuerOf(appSlug: string): string;
95
+ //# sourceMappingURL=signature-request.contracts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signature-request.contracts.d.ts","sourceRoot":"","sources":["../../../../src/key-management/signature-request.contracts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAmB,iBAAiB,EAAE,KAAK,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAIxG;;;;;;;;;;GAUG;AAEH,oHAAoH;AACpH,eAAO,MAAM,sBAAsB,EAAE,MAAyD,CAAC;AAE/F;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,EAAE,SAAS,MAAM,EAA6C,CAAC;AAEhG;;;;GAIG;AACH,eAAO,MAAM,sCAAsC,QAAS,CAAC;AAE7D;;;;GAIG;AACH,eAAO,MAAM,2CAA2C,QAAmB,CAAC;AAE5E,8FAA8F;AAC9F,eAAO,MAAM,0CAA0C,QAAmB,CAAC;AAE3E;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,QAA0G,CAAC;AAE/I;;;;GAIG;AACH,eAAO,MAAM,4BAA4B,EAAE,sBAA4E,CAAC;AAExH;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B;IAC1C,2GAA2G;;IAE3G,wGAAwG;;IAExG,kDAAkD;;iBAElD,CAAC;AACH,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAC;AAExF,+DAA+D;AAC/D,eAAO,MAAM,0CAA0C,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,iBAAiB,EAAE,OAAO,+BAA+B,CAAC,CAAC,CAE3I,CAAC;AAEF,wBAAwB;AACxB,eAAO,MAAM,sBAAsB;;;IAGjC,8GAA8G;;kBAE9G,CAAC;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEtE,wEAAwE;AACxE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,qHAAqH;IACrH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,yFAAyF;IACzF,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAOD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAEzF;AAED,yGAAyG;AACzG,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAE1F;AAED,gHAAgH;AAChH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEzD"}
@@ -0,0 +1,96 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { z } from 'zod';
3
+ import { singleJwsTypeOf, CryptoKey_Purpose } from '@wildo-ai/saas-models';
4
+ import { canonicalizeJson } from '../canonical-json/rfc8785-canonical-json.js';
5
+ import { base64url } from './es256-jws.js';
6
+ /**
7
+ * # Asking the platform custodian for a signature (#2891)
8
+ *
9
+ * An application backend never holds a platform-custody key. It asks apps-manager, the custodian, to sign claims for a
10
+ * purpose, and apps-manager decides everything that makes the signature mean something: the issuer (from the
11
+ * application's own record), the key version (`kid`), the media type (`typ`) and the signing instant (`iat`). The request
12
+ * carries only what the application decided, the CLAIMS, and the digest of them it recorded when the decision committed.
13
+ *
14
+ * Both sides import this module, so the digest the application records at commit and the one the custodian recomputes
15
+ * are the same function.
16
+ */
17
+ /** The media type of an approval seal's JWS (`typ` header, RFC 7515 §4.1.9): its purpose's, from the descriptor. */
18
+ export const APPROVAL_SEAL_JWS_TYPE = singleJwsTypeOf(CryptoKey_Purpose.APPROVAL_SEAL);
19
+ /**
20
+ * The claims the custodian sets itself, which a request may never carry: an application that could set `iss` could
21
+ * issue in another application's name, and one that could set `iat` could date its own seals. Refused rather than
22
+ * overwritten, so a caller that tries learns it.
23
+ */
24
+ export const CUSTODIAN_SET_CLAIMS = ['iss', 'iat', 'kid', 'typ', 'lateSeal'];
25
+ /**
26
+ * How far a decision may be dated AFTER the signing instant: the two clocks are different machines. Five minutes, the
27
+ * customary leeway for JWT time claims (RFC 7519 §4.1.4 leaves it to the implementer; five minutes is what major JWT
28
+ * libraries and identity providers default to).
29
+ */
30
+ export const SIGNATURE_CLOCK_SKEW_TOLERANCE_SECONDS = 5 * 60;
31
+ /**
32
+ * How long a request may be retried as the SAME request: the outbox that relays seals (#2903) gives up on a row after
33
+ * this age and marks it DEAD. Within it, the same claims get the signature already made back; past it, a re-drive is
34
+ * signed anew. Also the grace a retired key version keeps its private material for.
35
+ */
36
+ export const SIGNATURE_REQUEST_MAXIMUM_RETRY_AGE_SECONDS = 7 * 24 * 60 * 60;
37
+ /** The longest apps-manager outage the platform is designed to absorb without an operator. */
38
+ export const LONGEST_SUPPORTED_CUSTODIAN_OUTAGE_SECONDS = 3 * 24 * 60 * 60;
39
+ /**
40
+ * A decision older than this when it is signed is sealed with `lateSeal: true`, which the verifier shows. Longer than
41
+ * the retry age plus the longest supported outage, so no seal the normal path produces is late; a late seal is a
42
+ * re-driven DEAD one. An old decision is never refused: refusing would leave it with no seal at all.
43
+ */
44
+ export const LATE_SEAL_BOUND_SECONDS = SIGNATURE_REQUEST_MAXIMUM_RETRY_AGE_SECONDS + LONGEST_SUPPORTED_CUSTODIAN_OUTAGE_SECONDS + 24 * 60 * 60;
45
+ /**
46
+ * How often one application runtime may ask: per application and principal. A ceiling against a runaway loop, set well
47
+ * above any decision volume a person produces; bulk decisions are one seal over a list (#2903). A refusal for rate is
48
+ * retryable, never DEAD.
49
+ */
50
+ export const SIGNATURE_REQUEST_RATE_LIMIT = { requestsPerMinute: 600, requestsPerHour: 20_000 };
51
+ /**
52
+ * The approval seal's request claims, as far as the custodian checks them (#2891). The full seal shape is #2903's
53
+ * `ApprovalSealClaims`; the custodian needs only what it decides on: the seal's id, when the decision was taken, and
54
+ * the tenant (which selects an organization-scoped key). Other members pass through unchanged, and are covered by the
55
+ * decision-payload digest.
56
+ */
57
+ export const ApprovalSealRequestClaimsSchema = z.looseObject({
58
+ /** The seal's id, minted at commit: at least 128 bits, base64url. With `iss` it is the idempotency key. */
59
+ jti: z.string().regex(/^[A-Za-z0-9_-]{22,}$/),
60
+ /** When the decision was taken, in seconds since the epoch. Distinct from `iat`, when it was signed. */
61
+ decidedAt: z.number().int().positive(),
62
+ /** The organization the decision was taken in. */
63
+ tenant: z.string().min(1),
64
+ });
65
+ /** The claims schema of each purpose that may be requested. */
66
+ export const SIGNATURE_REQUEST_CLAIMS_SCHEMA_BY_PURPOSE = {
67
+ [CryptoKey_Purpose.APPROVAL_SEAL]: ApprovalSealRequestClaimsSchema,
68
+ };
69
+ /** The request body. */
70
+ export const SignatureRequestSchema = z.strictObject({
71
+ purpose: z.enum(CryptoKey_Purpose),
72
+ claims: z.record(z.string(), z.unknown()),
73
+ /** {@link decisionPayloadDigestOf} the claims, as the application recorded it when the decision committed. */
74
+ decisionPayloadDigest: z.string().min(1),
75
+ });
76
+ /** SHA-256, base64url, over the RFC 8785 serialization of a JSON value. */
77
+ function jcsSha256(value) {
78
+ return base64url(createHash('sha256').update(canonicalizeJson(value), 'utf8').digest());
79
+ }
80
+ /**
81
+ * The decision-payload digest: over every claim the APPLICATION decided, i.e. the request claims (the custodian-set
82
+ * claims are excluded by construction, since a request may not carry them). Recorded at commit, recomputed by the
83
+ * custodian, and a mismatch is refused.
84
+ */
85
+ export function decisionPayloadDigestOf(claims) {
86
+ return jcsSha256(claims);
87
+ }
88
+ /** The signed claims' digest, custodian-set claims included: the seal's identity with (`iss`, `jti`). */
89
+ export function sealClaimsDigestOf(signedClaims) {
90
+ return jcsSha256(signedClaims);
91
+ }
92
+ /** The issuer the custodian sets for an application: a URN of its slug, which is stable and names no person. */
93
+ export function signatureIssuerOf(appSlug) {
94
+ return `urn:wildo:application:${appSlug}`;
95
+ }
96
+ //# sourceMappingURL=signature-request.contracts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signature-request.contracts.js","sourceRoot":"","sources":["../../../../src/key-management/signature-request.contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAA+B,MAAM,uBAAuB,CAAC;AACxG,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;;;;;;;;GAUG;AAEH,oHAAoH;AACpH,MAAM,CAAC,MAAM,sBAAsB,GAAW,eAAe,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC;AAE/F;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAsB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;AAEhG;;;;GAIG;AACH,MAAM,CAAC,MAAM,sCAAsC,GAAG,CAAC,GAAG,EAAE,CAAC;AAE7D;;;;GAIG;AACH,MAAM,CAAC,MAAM,2CAA2C,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AAE5E,8FAA8F;AAC9F,MAAM,CAAC,MAAM,0CAA0C,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAA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AC,CAAC,MAAM,EAAE,CAAC,CAAC;AAC1F,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAAyC;IAC/E,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC;AAC3B,CAAC;AAED,yGAAyG;AACzG,MAAM,UAAU,kBAAkB,CAAC,YAA+C;IAChF,OAAO,SAAS,CAAC,YAAY,CAAC,CAAC;AACjC,CAAC;AAED,gHAAgH;AAChH,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC/C,OAAO,yBAAyB,OAAO,EAAE,CAAC;AAC5C,CAAC","sourcesContent":["import { createHash } from 'node:crypto';\nimport { z } from 'zod';\nimport { singleJwsTypeOf, CryptoKey_Purpose, type RateLimitConfiguration } from '@wildo-ai/saas-models';\nimport { canonicalizeJson } from '../canonical-json/rfc8785-canonical-json';\nimport { base64url } from './es256-jws';\n\n/**\n * # Asking the platform custodian for a signature (#2891)\n *\n * An application backend never holds a platform-custody key. It asks apps-manager, the custodian, to sign claims for a\n * purpose, and apps-manager decides everything that makes the signature mean something: the issuer (from the\n * application's own record), the key version (`kid`), the media type (`typ`) and the signing instant (`iat`). The request\n * carries only what the application decided, the CLAIMS, and the digest of them it recorded when the decision committed.\n *\n * Both sides import this module, so the digest the application records at commit and the one the custodian recomputes\n * are the same function.\n */\n\n/** The media type of an approval seal's JWS (`typ` header, RFC 7515 §4.1.9): its purpose's, from the descriptor. */\nexport const APPROVAL_SEAL_JWS_TYPE: string = singleJwsTypeOf(CryptoKey_Purpose.APPROVAL_SEAL);\n\n/**\n * The claims the custodian sets itself, which a request may never carry: an application that could set `iss` could\n * issue in another application's name, and one that could set `iat` could date its own seals. Refused rather than\n * overwritten, so a caller that tries learns it.\n */\nexport const CUSTODIAN_SET_CLAIMS: readonly string[] = ['iss', 'iat', 'kid', 'typ', 'lateSeal'];\n\n/**\n * How far a decision may be dated AFTER the signing instant: the two clocks are different machines. Five minutes, the\n * customary leeway for JWT time claims (RFC 7519 §4.1.4 leaves it to the implementer; five minutes is what major JWT\n * libraries and identity providers default to).\n */\nexport const SIGNATURE_CLOCK_SKEW_TOLERANCE_SECONDS = 5 * 60;\n\n/**\n * How long a request may be retried as the SAME request: the outbox that relays seals (#2903) gives up on a row after\n * this age and marks it DEAD. Within it, the same claims get the signature already made back; past it, a re-drive is\n * signed anew. Also the grace a retired key version keeps its private material for.\n */\nexport const SIGNATURE_REQUEST_MAXIMUM_RETRY_AGE_SECONDS = 7 * 24 * 60 * 60;\n\n/** The longest apps-manager outage the platform is designed to absorb without an operator. */\nexport const LONGEST_SUPPORTED_CUSTODIAN_OUTAGE_SECONDS = 3 * 24 * 60 * 60;\n\n/**\n * A decision older than this when it is signed is sealed with `lateSeal: true`, which the verifier shows. Longer than\n * the retry age plus the longest supported outage, so no seal the normal path produces is late; a late seal is a\n * re-driven DEAD one. An old decision is never refused: refusing would leave it with no seal at all.\n */\nexport const LATE_SEAL_BOUND_SECONDS = SIGNATURE_REQUEST_MAXIMUM_RETRY_AGE_SECONDS + LONGEST_SUPPORTED_CUSTODIAN_OUTAGE_SECONDS + 24 * 60 * 60;\n\n/**\n * How often one application runtime may ask: per application and principal. A ceiling against a runaway loop, set well\n * above any decision volume a person produces; bulk decisions are one seal over a list (#2903). A refusal for rate is\n * retryable, never DEAD.\n */\nexport const SIGNATURE_REQUEST_RATE_LIMIT: RateLimitConfiguration = { requestsPerMinute: 600, requestsPerHour: 20_000 };\n\n/**\n * The approval seal's request claims, as far as the custodian checks them (#2891). The full seal shape is #2903's\n * `ApprovalSealClaims`; the custodian needs only what it decides on: the seal's id, when the decision was taken, and\n * the tenant (which selects an organization-scoped key). Other members pass through unchanged, and are covered by the\n * decision-payload digest.\n */\nexport const ApprovalSealRequestClaimsSchema = z.looseObject({\n /** The seal's id, minted at commit: at least 128 bits, base64url. With `iss` it is the idempotency key. */\n jti: z.string().regex(/^[A-Za-z0-9_-]{22,}$/),\n /** When the decision was taken, in seconds since the epoch. Distinct from `iat`, when it was signed. */\n decidedAt: z.number().int().positive(),\n /** The organization the decision was taken in. */\n tenant: z.string().min(1),\n});\nexport type ApprovalSealRequestClaims = z.infer<typeof ApprovalSealRequestClaimsSchema>;\n\n/** The claims schema of each purpose that may be requested. */\nexport const SIGNATURE_REQUEST_CLAIMS_SCHEMA_BY_PURPOSE: Readonly<Partial<Record<CryptoKey_Purpose, typeof ApprovalSealRequestClaimsSchema>>> = {\n [CryptoKey_Purpose.APPROVAL_SEAL]: ApprovalSealRequestClaimsSchema,\n};\n\n/** The request body. */\nexport const SignatureRequestSchema = z.strictObject({\n purpose: z.enum(CryptoKey_Purpose),\n claims: z.record(z.string(), z.unknown()),\n /** {@link decisionPayloadDigestOf} the claims, as the application recorded it when the decision committed. */\n decisionPayloadDigest: z.string().min(1),\n});\nexport type SignatureRequest = z.infer<typeof SignatureRequestSchema>;\n\n/** The answer: the compact JWS and what the custodian decided in it. */\nexport interface SignatureResponse {\n readonly jws: string;\n readonly kid: string;\n readonly iss: string;\n readonly iat: number;\n /** {@link sealClaimsDigestOf} the signed claims: with `iss` and `jti`, the seal's identity (never the JWS bytes). */\n readonly claimsDigest: string;\n readonly lateSeal: boolean;\n /** True when the same claims had been signed already, and that signature is returned. */\n readonly replayed: boolean;\n}\n\n/** SHA-256, base64url, over the RFC 8785 serialization of a JSON value. */\nfunction jcsSha256(value: unknown): string {\n return base64url(createHash('sha256').update(canonicalizeJson(value), 'utf8').digest());\n}\n\n/**\n * The decision-payload digest: over every claim the APPLICATION decided, i.e. the request claims (the custodian-set\n * claims are excluded by construction, since a request may not carry them). Recorded at commit, recomputed by the\n * custodian, and a mismatch is refused.\n */\nexport function decisionPayloadDigestOf(claims: Readonly<Record<string, unknown>>): string {\n return jcsSha256(claims);\n}\n\n/** The signed claims' digest, custodian-set claims included: the seal's identity with (`iss`, `jti`). */\nexport function sealClaimsDigestOf(signedClaims: Readonly<Record<string, unknown>>): string {\n return jcsSha256(signedClaims);\n}\n\n/** The issuer the custodian sets for an application: a URN of its slug, which is stable and names no person. */\nexport function signatureIssuerOf(appSlug: string): string {\n return `urn:wildo:application:${appSlug}`;\n}\n"]}