@wildo-ai/platform-config-lib 1.1.10 → 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 (231) 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/application-backend-env.contracts.d.ts.map +1 -1
  13. package/dist/esm/bootstrap/bootstrap-planner.d.ts.map +1 -1
  14. package/dist/esm/bootstrap/bootstrap.contracts.d.ts +13 -1
  15. package/dist/esm/bootstrap/bootstrap.contracts.d.ts.map +1 -1
  16. package/dist/esm/bootstrap/bootstrap.contracts.js +6 -0
  17. package/dist/esm/bootstrap/bootstrap.contracts.js.map +1 -1
  18. package/dist/esm/bootstrap/bootstrap.schemas.d.ts +21 -3
  19. package/dist/esm/bootstrap/bootstrap.schemas.d.ts.map +1 -1
  20. package/dist/esm/bootstrap/bootstrap.schemas.js +14 -3
  21. package/dist/esm/bootstrap/bootstrap.schemas.js.map +1 -1
  22. package/dist/esm/bootstrap/platform-runtime-env.contracts.d.ts +121 -0
  23. package/dist/esm/bootstrap/platform-runtime-env.contracts.d.ts.map +1 -1
  24. package/dist/esm/bootstrap/platform-runtime-env.contracts.js +129 -0
  25. package/dist/esm/bootstrap/platform-runtime-env.contracts.js.map +1 -1
  26. package/dist/esm/bootstrap/platform-store-preconnect.d.ts.map +1 -1
  27. package/dist/esm/bootstrap/runtime-backing-service-access.d.ts.map +1 -1
  28. package/dist/esm/bootstrap/runtime-network-policy.d.ts.map +1 -1
  29. package/dist/esm/bootstrap/runtime-network-topology.d.ts.map +1 -1
  30. package/dist/esm/bootstrap/runtime-platform-access.d.ts.map +1 -1
  31. package/dist/esm/bootstrap/runtime-principal.contracts.d.ts.map +1 -1
  32. package/dist/esm/bootstrap/runtime-response-integrity.d.ts +249 -0
  33. package/dist/esm/bootstrap/runtime-response-integrity.d.ts.map +1 -0
  34. package/dist/esm/bootstrap/runtime-response-integrity.js +353 -0
  35. package/dist/esm/bootstrap/runtime-response-integrity.js.map +1 -0
  36. package/dist/esm/bootstrap/runtime-secret-env.contracts.d.ts +32 -0
  37. package/dist/esm/bootstrap/runtime-secret-env.contracts.d.ts.map +1 -0
  38. package/dist/esm/bootstrap/runtime-secret-env.contracts.js +43 -0
  39. package/dist/esm/bootstrap/runtime-secret-env.contracts.js.map +1 -0
  40. package/dist/esm/bootstrap/runtime-topology.contracts.d.ts.map +1 -1
  41. package/dist/esm/bootstrap/wildo-owner-organization.contracts.d.ts.map +1 -1
  42. package/dist/esm/canonical-json/rfc8785-canonical-json.d.ts +51 -0
  43. package/dist/esm/canonical-json/rfc8785-canonical-json.d.ts.map +1 -0
  44. package/dist/esm/canonical-json/rfc8785-canonical-json.js +231 -0
  45. package/dist/esm/canonical-json/rfc8785-canonical-json.js.map +1 -0
  46. package/dist/esm/config-authoring.entry.d.ts.map +1 -1
  47. package/dist/esm/index.d.ts +15 -0
  48. package/dist/esm/index.d.ts.map +1 -1
  49. package/dist/esm/index.js +15 -0
  50. package/dist/esm/index.js.map +1 -1
  51. package/dist/esm/key-management/approval-seal-verifier.d.ts +216 -0
  52. package/dist/esm/key-management/approval-seal-verifier.d.ts.map +1 -0
  53. package/dist/esm/key-management/approval-seal-verifier.js +233 -0
  54. package/dist/esm/key-management/approval-seal-verifier.js.map +1 -0
  55. package/dist/esm/key-management/approval-seal.contracts.d.ts +131 -0
  56. package/dist/esm/key-management/approval-seal.contracts.d.ts.map +1 -0
  57. package/dist/esm/key-management/approval-seal.contracts.js +115 -0
  58. package/dist/esm/key-management/approval-seal.contracts.js.map +1 -0
  59. package/dist/esm/key-management/data-key.contracts.d.ts +108 -0
  60. package/dist/esm/key-management/data-key.contracts.d.ts.map +1 -0
  61. package/dist/esm/key-management/data-key.contracts.js +54 -0
  62. package/dist/esm/key-management/data-key.contracts.js.map +1 -0
  63. package/dist/esm/key-management/es256-jws.d.ts +60 -0
  64. package/dist/esm/key-management/es256-jws.d.ts.map +1 -0
  65. package/dist/esm/key-management/es256-jws.js +135 -0
  66. package/dist/esm/key-management/es256-jws.js.map +1 -0
  67. package/dist/esm/key-management/key-provider.spi.d.ts +151 -0
  68. package/dist/esm/key-management/key-provider.spi.d.ts.map +1 -0
  69. package/dist/esm/key-management/key-provider.spi.js +38 -0
  70. package/dist/esm/key-management/key-provider.spi.js.map +1 -0
  71. package/dist/esm/key-management/keyring-rotation.contracts.d.ts +93 -0
  72. package/dist/esm/key-management/keyring-rotation.contracts.d.ts.map +1 -0
  73. package/dist/esm/key-management/keyring-rotation.contracts.js +101 -0
  74. package/dist/esm/key-management/keyring-rotation.contracts.js.map +1 -0
  75. package/dist/esm/key-management/keyring-status.contracts.d.ts +66 -0
  76. package/dist/esm/key-management/keyring-status.contracts.d.ts.map +1 -0
  77. package/dist/esm/key-management/keyring-status.contracts.js +45 -0
  78. package/dist/esm/key-management/keyring-status.contracts.js.map +1 -0
  79. package/dist/esm/key-management/signature-request.contracts.d.ts +95 -0
  80. package/dist/esm/key-management/signature-request.contracts.d.ts.map +1 -0
  81. package/dist/esm/key-management/signature-request.contracts.js +96 -0
  82. package/dist/esm/key-management/signature-request.contracts.js.map +1 -0
  83. package/dist/esm/key-management/signing-log-export.contracts.d.ts +216 -0
  84. package/dist/esm/key-management/signing-log-export.contracts.d.ts.map +1 -0
  85. package/dist/esm/key-management/signing-log-export.contracts.js +268 -0
  86. package/dist/esm/key-management/signing-log-export.contracts.js.map +1 -0
  87. package/dist/esm/key-management/vault-custody.contracts.d.ts +55 -0
  88. package/dist/esm/key-management/vault-custody.contracts.d.ts.map +1 -0
  89. package/dist/esm/key-management/vault-custody.contracts.js +88 -0
  90. package/dist/esm/key-management/vault-custody.contracts.js.map +1 -0
  91. package/dist/esm/lockfile/file-lock-hold.d.ts.map +1 -1
  92. package/dist/esm/lockfile/lockfile-io.d.ts +7 -9
  93. package/dist/esm/lockfile/lockfile-io.d.ts.map +1 -1
  94. package/dist/esm/lockfile/lockfile-io.js +23 -22
  95. package/dist/esm/lockfile/lockfile-io.js.map +1 -1
  96. package/dist/esm/lockfile/materialize-infra-section.d.ts +17 -14
  97. package/dist/esm/lockfile/materialize-infra-section.d.ts.map +1 -1
  98. package/dist/esm/lockfile/materialize-infra-section.js +9 -9
  99. package/dist/esm/lockfile/materialize-infra-section.js.map +1 -1
  100. package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.d.ts +26 -2
  101. package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.d.ts.map +1 -1
  102. package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.js +27 -2
  103. package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.js.map +1 -1
  104. package/dist/esm/project-config/application-public-pricing-catalog.loader.d.ts.map +1 -1
  105. package/dist/esm/project-config/application-public-pricing-catalog.loader.js +9 -2
  106. package/dist/esm/project-config/application-public-pricing-catalog.loader.js.map +1 -1
  107. package/dist/esm/project-config/application-served-public-documents.loader.d.ts +26 -0
  108. package/dist/esm/project-config/application-served-public-documents.loader.d.ts.map +1 -0
  109. package/dist/esm/project-config/application-served-public-documents.loader.js +78 -0
  110. package/dist/esm/project-config/application-served-public-documents.loader.js.map +1 -0
  111. package/dist/esm/project-config/define-framework-config.d.ts.map +1 -1
  112. package/dist/esm/project-config/define-infra-env-config.d.ts +236 -15
  113. package/dist/esm/project-config/define-infra-env-config.d.ts.map +1 -1
  114. package/dist/esm/project-config/define-infra-env-config.js +104 -91
  115. package/dist/esm/project-config/define-infra-env-config.js.map +1 -1
  116. package/dist/esm/project-config/define-minion-config.d.ts.map +1 -1
  117. package/dist/esm/project-config/define-saas-config.d.ts +133 -3
  118. package/dist/esm/project-config/define-saas-config.d.ts.map +1 -1
  119. package/dist/esm/project-config/define-saas-config.js +170 -19
  120. package/dist/esm/project-config/define-saas-config.js.map +1 -1
  121. package/dist/esm/project-config/define-worker-config.d.ts.map +1 -1
  122. package/dist/esm/project-config/hosted-infra-env-config.d.ts.map +1 -1
  123. package/dist/esm/project-config/hosted-infra-env-config.js +3 -0
  124. package/dist/esm/project-config/hosted-infra-env-config.js.map +1 -1
  125. package/dist/esm/project-config/index.d.ts +3 -0
  126. package/dist/esm/project-config/index.d.ts.map +1 -1
  127. package/dist/esm/project-config/index.js +3 -0
  128. package/dist/esm/project-config/index.js.map +1 -1
  129. package/dist/esm/project-config/loader.d.ts.map +1 -1
  130. package/dist/esm/project-config/npm-version-range.d.ts.map +1 -1
  131. package/dist/esm/project-config/npm-version-range.js +39 -16
  132. package/dist/esm/project-config/npm-version-range.js.map +1 -1
  133. package/dist/esm/project-config/owning-package-tsconfig.d.ts +15 -0
  134. package/dist/esm/project-config/owning-package-tsconfig.d.ts.map +1 -0
  135. package/dist/esm/project-config/owning-package-tsconfig.js +29 -0
  136. package/dist/esm/project-config/owning-package-tsconfig.js.map +1 -0
  137. package/dist/esm/project-config/provider-catalog-types.d.ts.map +1 -1
  138. package/dist/esm/project-config/provider-companion-discovery.d.ts +4 -4
  139. package/dist/esm/project-config/provider-companion-discovery.d.ts.map +1 -1
  140. package/dist/esm/project-config/provider-companion-discovery.js +13 -9
  141. package/dist/esm/project-config/provider-companion-discovery.js.map +1 -1
  142. package/dist/esm/project-config/provider-runtime-artifacts.d.ts +32 -3
  143. package/dist/esm/project-config/provider-runtime-artifacts.d.ts.map +1 -1
  144. package/dist/esm/project-config/provider-runtime-artifacts.js +67 -13
  145. package/dist/esm/project-config/provider-runtime-artifacts.js.map +1 -1
  146. package/dist/esm/project-config/shared/application-creation-verification.schemas.d.ts.map +1 -1
  147. package/dist/esm/project-config/shared/application-modules.schemas.d.ts.map +1 -1
  148. package/dist/esm/project-config/shared/application-modules.utils.d.ts.map +1 -1
  149. package/dist/esm/project-config/shared/auth.schemas.d.ts.map +1 -1
  150. package/dist/esm/project-config/shared/backing-service-servability.d.ts.map +1 -1
  151. package/dist/esm/project-config/shared/backing-services.schemas.d.ts.map +1 -1
  152. package/dist/esm/project-config/shared/cdn.example.d.ts.map +1 -1
  153. package/dist/esm/project-config/shared/cdn.schemas.d.ts.map +1 -1
  154. package/dist/esm/project-config/shared/csp-defaults.d.ts +4 -5
  155. package/dist/esm/project-config/shared/csp-defaults.d.ts.map +1 -1
  156. package/dist/esm/project-config/shared/csp-defaults.js +4 -5
  157. package/dist/esm/project-config/shared/csp-defaults.js.map +1 -1
  158. package/dist/esm/project-config/shared/csp-emit.d.ts.map +1 -1
  159. package/dist/esm/project-config/shared/csp.schemas.d.ts +1 -2
  160. package/dist/esm/project-config/shared/csp.schemas.d.ts.map +1 -1
  161. package/dist/esm/project-config/shared/csp.schemas.js +1 -2
  162. package/dist/esm/project-config/shared/csp.schemas.js.map +1 -1
  163. package/dist/esm/project-config/shared/data-services.schemas.d.ts.map +1 -1
  164. package/dist/esm/project-config/shared/environment.schemas.d.ts +6 -0
  165. package/dist/esm/project-config/shared/environment.schemas.d.ts.map +1 -1
  166. package/dist/esm/project-config/shared/environment.schemas.js +8 -1
  167. package/dist/esm/project-config/shared/environment.schemas.js.map +1 -1
  168. package/dist/esm/project-config/shared/infra-providers.schemas.d.ts.map +1 -1
  169. package/dist/esm/project-config/shared/infra-service.schemas.d.ts.map +1 -1
  170. package/dist/esm/project-config/shared/infrastructure-defaults.schemas.d.ts +1 -0
  171. package/dist/esm/project-config/shared/infrastructure-defaults.schemas.d.ts.map +1 -1
  172. package/dist/esm/project-config/shared/infrastructure-defaults.schemas.js +3 -0
  173. package/dist/esm/project-config/shared/infrastructure-defaults.schemas.js.map +1 -1
  174. package/dist/esm/project-config/shared/minion-resource-access.validation.d.ts +4 -0
  175. package/dist/esm/project-config/shared/minion-resource-access.validation.d.ts.map +1 -1
  176. package/dist/esm/project-config/shared/minion-resource-access.validation.js +6 -2
  177. package/dist/esm/project-config/shared/minion-resource-access.validation.js.map +1 -1
  178. package/dist/esm/project-config/shared/platform-key-management.schemas.d.ts +250 -0
  179. package/dist/esm/project-config/shared/platform-key-management.schemas.d.ts.map +1 -0
  180. package/dist/esm/project-config/shared/platform-key-management.schemas.js +194 -0
  181. package/dist/esm/project-config/shared/platform-key-management.schemas.js.map +1 -0
  182. package/dist/esm/project-config/shared/platform-services.schemas.d.ts.map +1 -1
  183. package/dist/esm/project-config/shared/platform-storage.schemas.d.ts.map +1 -1
  184. package/dist/esm/project-config/shared/schema-version.schemas.d.ts.map +1 -1
  185. package/dist/esm/project-config/shared/service-definitions.schemas.d.ts.map +1 -1
  186. package/dist/esm/project-config/shared/systems-of-record-env.schemas.d.ts.map +1 -1
  187. package/dist/esm/registry/artifact-domain.schemas.d.ts.map +1 -1
  188. package/dist/esm/registry/digest.schemas.d.ts.map +1 -1
  189. package/dist/esm/registry/index.d.ts +1 -0
  190. package/dist/esm/registry/index.d.ts.map +1 -1
  191. package/dist/esm/registry/index.js +1 -0
  192. package/dist/esm/registry/index.js.map +1 -1
  193. package/dist/esm/registry/local-checkout-source.d.ts +22 -2
  194. package/dist/esm/registry/local-checkout-source.d.ts.map +1 -1
  195. package/dist/esm/registry/local-checkout-source.js +66 -3
  196. package/dist/esm/registry/local-checkout-source.js.map +1 -1
  197. package/dist/esm/registry/lockfile-modules-section.schemas.d.ts +10 -0
  198. package/dist/esm/registry/lockfile-modules-section.schemas.d.ts.map +1 -1
  199. package/dist/esm/registry/module-artifact.schemas.d.ts +23 -0
  200. package/dist/esm/registry/module-artifact.schemas.d.ts.map +1 -1
  201. package/dist/esm/registry/module-manifest.schemas.d.ts +336 -18
  202. package/dist/esm/registry/module-manifest.schemas.d.ts.map +1 -1
  203. package/dist/esm/registry/module-manifest.schemas.js +245 -19
  204. package/dist/esm/registry/module-manifest.schemas.js.map +1 -1
  205. package/dist/esm/registry/module-search.schemas.d.ts +2 -0
  206. package/dist/esm/registry/module-search.schemas.d.ts.map +1 -1
  207. package/dist/esm/registry/module-search.schemas.js +14 -1
  208. package/dist/esm/registry/module-search.schemas.js.map +1 -1
  209. package/dist/esm/registry/registry-config.schemas.d.ts.map +1 -1
  210. package/dist/esm/registry/registry-errors.d.ts +22 -2
  211. package/dist/esm/registry/registry-errors.d.ts.map +1 -1
  212. package/dist/esm/registry/registry-errors.js +28 -2
  213. package/dist/esm/registry/registry-errors.js.map +1 -1
  214. package/dist/esm/registry/registry-keys.schemas.d.ts.map +1 -1
  215. package/dist/esm/registry/registry-section-schemas.constants.d.ts +5 -0
  216. package/dist/esm/registry/registry-section-schemas.constants.d.ts.map +1 -1
  217. package/dist/esm/registry/registry-url-resolution.d.ts +72 -0
  218. package/dist/esm/registry/registry-url-resolution.d.ts.map +1 -0
  219. package/dist/esm/registry/registry-url-resolution.js +157 -0
  220. package/dist/esm/registry/registry-url-resolution.js.map +1 -0
  221. package/dist/esm/schemas/framework-info.schemas.d.ts.map +1 -1
  222. package/dist/esm/schemas/framework-secrets.schemas.d.ts +55 -0
  223. package/dist/esm/schemas/framework-secrets.schemas.d.ts.map +1 -1
  224. package/dist/esm/schemas/framework-secrets.schemas.js +53 -0
  225. package/dist/esm/schemas/framework-secrets.schemas.js.map +1 -1
  226. package/dist/esm/schemas/platform-application-config.schemas.d.ts.map +1 -1
  227. package/dist/esm/schemas/platform-application-secrets.schemas.d.ts.map +1 -1
  228. package/dist/esm/schemas/platform-config.schemas.d.ts.map +1 -1
  229. package/dist/esm/workspace-scope/application-subject-manifest.d.ts.map +1 -1
  230. package/dist/esm/workspace-scope/index.d.ts.map +1 -1
  231. package/package.json +7 -7
@@ -0,0 +1,233 @@
1
+ /**
2
+ * # Verifying an approval seal, offline (#2903)
3
+ *
4
+ * Everything a verifier needs travels with the seal: the compact JWS, the stored records of the keys that may have signed
5
+ * it (their public half, scope and issuer, as an export carries them), and, when the person's content is to be shown,
6
+ * the disclosures. Nothing here calls the application or the platform, so a seal verifies after the application is gone.
7
+ *
8
+ * ## What is checked, and on whose authority
9
+ *
10
+ * - The header: ES256 is pinned per key from the key RECORD, never read from the header (RFC 8725 §3.1); `jku`, `x5u`,
11
+ * `jwk` and `x5c` are never followed (RFC 8725 §3.10, RFC 7515 §10.7); a `crit` naming anything is refused, since no
12
+ * extension is understood (RFC 7515 §4.1.11); `typ` must be the approval seal's.
13
+ * - The signature, under the key the `kid` names among those given.
14
+ * - The issuer: the payload's `iss` must be the key record's, and the expected issuer when one is given.
15
+ * - The claims: the version-1 shape, strict.
16
+ * - The key's scope, from its stored record and never from a JWKS member: an organization-scoped key verifies only a seal
17
+ * whose tenant is that organization.
18
+ * - The disclosures: each must digest to the commitment its claim names; a commitment with no disclosure is reported as
19
+ * erased (the person's content was removed, the seal stands).
20
+ * - A COMPROMISED key: the signature may still verify, but the seal is not PROVABLE unless corroborated by evidence the
21
+ * key's holder could not have forged: the decision's payload digest recorded outside the application before the
22
+ * compromise instant (an exported audit event, an immutable sink).
23
+ * - The OPERATOR'S PIN SET, when one is given (#2932): the key must be pinned, by the RFC 7638 thumbprint of the public
24
+ * half the verifier was handed (so a key record that names a pinned `kid` over another key is refused), and the pin's
25
+ * state, scope and compromise instant are used instead of the record's. The record (from a bundle, from the host)
26
+ * only supplies the public half and the issuer; the operator's pin decides whether that half is theirs and what became
27
+ * of it. Without a pin set the records are trusted as given, as before.
28
+ * - The OPERATOR'S KEPT SIGNING-LOG EXPORTS, when given (#2932): a seal under a key compromised after an export that lists
29
+ * it is corroborated by that export, which the host could not have signed after the compromise without the operator's
30
+ * copy disagreeing. Each export is verified here, with the operator's pin set for the export key.
31
+ *
32
+ * spec-cite: RFC 8725 §3.1 (algorithm verification), §3.10 (do not trust received URLs); RFC 7515 §4.1.11 (`crit`),
33
+ * §10.7 (key selection from header parameters). Cited by section; the behaviour is this file's decision.
34
+ */
35
+ import { z } from 'zod';
36
+ import { singleJwsTypeOf, CryptoKey_Purpose, CryptoKey_Scope, CryptoKey_VersionState } from '@wildo-ai/saas-models';
37
+ import { ES256_JWS_ALGORITHM, isP256PublicJwk, verifyEs256 } from './es256-jws.js';
38
+ import { decisionPayloadDigestOf, sealClaimsDigestOf } from './signature-request.contracts.js';
39
+ import { VerificationKeyRecordSchema, compareSigningLogExports, pinnedVerificationKeyOf, verifySigningLogExport } from './signing-log-export.contracts.js';
40
+ import { ApprovalSealClaimsV1Schema, ApprovalSealDisclosureClaim, approvalSealDisclosureDigestOf, } from './approval-seal.contracts.js';
41
+ /** The approval seal's JWS `typ`. */
42
+ const APPROVAL_SEAL_TYP = singleJwsTypeOf(CryptoKey_Purpose.APPROVAL_SEAL);
43
+ /** The payload members the custodian sets; the rest is the decision's committed payload. */
44
+ const CUSTODIAN_SET_CLAIMS = ['iss', 'iat', 'lateSeal'];
45
+ /** What corroborated a seal under a compromised key. */
46
+ export var ApprovalSealCorroborationSource;
47
+ (function (ApprovalSealCorroborationSource) {
48
+ /** The decision's payload digest, recorded outside the application before the compromise. */
49
+ ApprovalSealCorroborationSource["RECORDED_EVIDENCE"] = "recorded_evidence";
50
+ /** A signing-log export the operator kept, signed before the compromise, lists the seal. */
51
+ ApprovalSealCorroborationSource["SIGNING_LOG_EXPORT"] = "signing_log_export";
52
+ })(ApprovalSealCorroborationSource || (ApprovalSealCorroborationSource = {}));
53
+ /** Why a seal does not verify. */
54
+ export var ApprovalSealVerificationFailure;
55
+ (function (ApprovalSealVerificationFailure) {
56
+ /** Not a compact JWS with a JSON header and payload. */
57
+ ApprovalSealVerificationFailure["MALFORMED"] = "malformed";
58
+ /** The header's `alg` is not the one the key record pins. */
59
+ ApprovalSealVerificationFailure["ALGORITHM_NOT_PINNED"] = "algorithm_not_pinned";
60
+ /** The header names a critical extension, and none is understood. */
61
+ ApprovalSealVerificationFailure["CRITICAL_EXTENSION"] = "critical_extension";
62
+ /** The header's `typ` is not the approval seal's. */
63
+ ApprovalSealVerificationFailure["TYPE_MISMATCH"] = "type_mismatch";
64
+ /** No given key has the header's `kid`. */
65
+ ApprovalSealVerificationFailure["UNKNOWN_KEY"] = "unknown_key";
66
+ ApprovalSealVerificationFailure["SIGNATURE_INVALID"] = "signature_invalid";
67
+ /** The payload's issuer is not the key record's, or not the expected one. */
68
+ ApprovalSealVerificationFailure["ISSUER_MISMATCH"] = "issuer_mismatch";
69
+ /** The payload is not the version-1 claims shape. */
70
+ ApprovalSealVerificationFailure["CLAIMS_INVALID"] = "claims_invalid";
71
+ /** The key's stored scope does not cover the seal's tenant (or is not a scope a seal is signed under). */
72
+ ApprovalSealVerificationFailure["TENANT_OUTSIDE_KEY_SCOPE"] = "tenant_outside_key_scope";
73
+ /** A disclosure does not digest to the commitment its claim names. */
74
+ ApprovalSealVerificationFailure["DISCLOSURE_MISMATCH"] = "disclosure_mismatch";
75
+ /** A pin set was given and does not pin the key, or the key handed over is not the one its pinned `kid` names. */
76
+ ApprovalSealVerificationFailure["UNPINNED"] = "unpinned";
77
+ })(ApprovalSealVerificationFailure || (ApprovalSealVerificationFailure = {}));
78
+ /** What the seal says about one person's disclosure. */
79
+ export var ApprovalSealDisclosureStanding;
80
+ (function (ApprovalSealDisclosureStanding) {
81
+ /** Given, and it digests to the commitment. */
82
+ ApprovalSealDisclosureStanding["DISCLOSED"] = "disclosed";
83
+ /** Committed to, and not given: the content was erased (or withheld). The seal stands. */
84
+ ApprovalSealDisclosureStanding["ERASED"] = "erased";
85
+ })(ApprovalSealDisclosureStanding || (ApprovalSealDisclosureStanding = {}));
86
+ function decodeJson(part) {
87
+ if (!part)
88
+ return null;
89
+ try {
90
+ const value = JSON.parse(Buffer.from(part, 'base64url').toString('utf8'));
91
+ return value !== null && typeof value === 'object' && !Array.isArray(value) ? value : null;
92
+ }
93
+ catch {
94
+ return null;
95
+ }
96
+ }
97
+ function disclosureStanding(claimName, commitment, disclosures, failures) {
98
+ if (!commitment)
99
+ return undefined;
100
+ const given = disclosures.filter((disclosure) => disclosure.claimName === claimName);
101
+ if (given.length === 0)
102
+ return { standing: ApprovalSealDisclosureStanding.ERASED };
103
+ const matching = given.find((disclosure) => approvalSealDisclosureDigestOf(disclosure) === commitment);
104
+ if (!matching) {
105
+ failures.push(ApprovalSealVerificationFailure.DISCLOSURE_MISMATCH);
106
+ return { standing: ApprovalSealDisclosureStanding.ERASED };
107
+ }
108
+ return { standing: ApprovalSealDisclosureStanding.DISCLOSED, value: matching.value };
109
+ }
110
+ /**
111
+ * What corroborates a seal under a compromised key, if anything: evidence of its payload recorded before the compromise,
112
+ * or a kept export signed before the compromise that lists this exact seal (its issuer, its key, its signed claims).
113
+ */
114
+ function corroborationOf(input, key, payload, decisionPayloadDigest) {
115
+ if (key.compromiseInstant === undefined)
116
+ return undefined;
117
+ const compromisedFrom = Date.parse(key.compromiseInstant);
118
+ if (input.corroboration && input.corroboration.decisionPayloadDigest === decisionPayloadDigest && Date.parse(input.corroboration.recordedAt) < compromisedFrom) {
119
+ return ApprovalSealCorroborationSource.RECORDED_EVIDENCE;
120
+ }
121
+ const logged = input.signingLogExports;
122
+ if (!logged)
123
+ return undefined;
124
+ const claimsDigest = sealClaimsDigestOf(payload);
125
+ const evidence = logged.exports.flatMap((jws) => {
126
+ const exported = verifySigningLogExport({ jws, keys: logged.keys, ...(logged.pins ? { pins: logged.pins } : {}), expectedIssuer: key.iss });
127
+ return exported.provable && exported.claims ? [exported.claims] : [];
128
+ });
129
+ // The exports must agree with each other first (#2932 review M3): an export is dated by the instant it states for
130
+ // itself, so a host holding the export key could sign one dated before the compromise; it disagrees with the operator's
131
+ // kept exports (a different hash at some sequence, or a head behind an earlier one), and then none of them corroborates.
132
+ if (!compareSigningLogExports(evidence).consistent)
133
+ return undefined;
134
+ for (const claims of evidence) {
135
+ if (claims.iat * 1000 >= compromisedFrom)
136
+ continue;
137
+ const lists = claims.entries.some((entry) => entry.purpose === CryptoKey_Purpose.APPROVAL_SEAL && entry.kid === key.kid && entry.iss === key.iss && entry.claimsDigest === claimsDigest);
138
+ if (lists)
139
+ return ApprovalSealCorroborationSource.SIGNING_LOG_EXPORT;
140
+ }
141
+ return undefined;
142
+ }
143
+ /** See the file's header. Pure and offline. */
144
+ export function verifyApprovalSeal(input) {
145
+ const failures = [];
146
+ const fail = (failure, extra = {}) => ({ valid: false, provable: false, failures: [...failures, failure], ...extra });
147
+ const parts = input.jws.split('.');
148
+ const header = parts.length === 3 ? decodeJson(parts[0]) : null;
149
+ const payload = parts.length === 3 ? decodeJson(parts[1]) : null;
150
+ if (!header || !payload || !parts[2])
151
+ return fail(ApprovalSealVerificationFailure.MALFORMED);
152
+ const kid = typeof header.kid === 'string' ? header.kid : undefined;
153
+ // The key is chosen by `kid` among the keys the verifier was GIVEN; `jku`/`x5u`/`jwk`/`x5c` are never read.
154
+ const record = kid ? input.keys.find((candidate) => candidate.kid === kid) : undefined;
155
+ if (!record || !isP256PublicJwk(record.publicJwk))
156
+ return fail(ApprovalSealVerificationFailure.UNKNOWN_KEY, kid ? { kid } : {});
157
+ // The operator's pin, when given: the key handed over must be the one the pinned thumbprint names, and the pin (not
158
+ // the record) says what became of it.
159
+ const key = pinnedVerificationKeyOf(record, input.pins);
160
+ if (!key)
161
+ return fail(ApprovalSealVerificationFailure.UNPINNED, { kid });
162
+ if (header.alg !== key.alg || key.alg !== ES256_JWS_ALGORITHM)
163
+ return fail(ApprovalSealVerificationFailure.ALGORITHM_NOT_PINNED, { kid });
164
+ if (header.crit !== undefined)
165
+ return fail(ApprovalSealVerificationFailure.CRITICAL_EXTENSION, { kid });
166
+ if (header.typ !== APPROVAL_SEAL_TYP)
167
+ return fail(ApprovalSealVerificationFailure.TYPE_MISMATCH, { kid });
168
+ if (!verifyEs256(`${parts[0]}.${parts[1]}`, Buffer.from(parts[2], 'base64url'), key.publicJwk)) {
169
+ return fail(ApprovalSealVerificationFailure.SIGNATURE_INVALID, { kid, keyState: key.state });
170
+ }
171
+ const iss = typeof payload.iss === 'string' ? payload.iss : undefined;
172
+ const iat = typeof payload.iat === 'number' ? payload.iat : undefined;
173
+ const lateSeal = payload.lateSeal === true;
174
+ if (!iss || iss !== key.iss || (input.expectedIssuer !== undefined && iss !== input.expectedIssuer))
175
+ failures.push(ApprovalSealVerificationFailure.ISSUER_MISMATCH);
176
+ const committed = Object.fromEntries(Object.entries(payload).filter(([name]) => !CUSTODIAN_SET_CLAIMS.includes(name)));
177
+ const parsed = ApprovalSealClaimsV1Schema.safeParse(committed);
178
+ if (!parsed.success)
179
+ return fail(ApprovalSealVerificationFailure.CLAIMS_INVALID, { kid, keyState: key.state, ...(iss ? { iss } : {}) });
180
+ const claims = parsed.data;
181
+ // The key's scope from its RECORD: an organization key covers only that organization's decisions.
182
+ const scopeCovers = key.scope === CryptoKey_Scope.APPLICATION || (key.scope === CryptoKey_Scope.ORGANIZATION && claims.tenant === key.scopeId);
183
+ if (!scopeCovers)
184
+ failures.push(ApprovalSealVerificationFailure.TENANT_OUTSIDE_KEY_SCOPE);
185
+ const disclosures = input.disclosures ?? [];
186
+ const approver = disclosureStanding(ApprovalSealDisclosureClaim.APPROVER, claims.approver, disclosures, failures);
187
+ const requester = disclosureStanding(ApprovalSealDisclosureClaim.REQUESTER, claims.requester?.disclosure, disclosures, failures);
188
+ const presentation = disclosureStanding(ApprovalSealDisclosureClaim.PRESENTATION, claims.presentation?.digest, disclosures, failures);
189
+ const statement = disclosureStanding(ApprovalSealDisclosureClaim.STATEMENT, claims.statementDigest, disclosures, failures);
190
+ const decisionPayloadDigest = decisionPayloadDigestOf(committed);
191
+ const valid = failures.length === 0;
192
+ const compromised = key.state === CryptoKey_VersionState.COMPROMISED;
193
+ const corroboratedBy = compromised ? corroborationOf(input, key, payload, decisionPayloadDigest) : undefined;
194
+ const corroborated = !compromised || corroboratedBy !== undefined;
195
+ return {
196
+ valid,
197
+ failures,
198
+ provable: valid && corroborated,
199
+ ...(corroboratedBy ? { corroboratedBy } : {}),
200
+ kid,
201
+ keyState: key.state,
202
+ claims,
203
+ iss,
204
+ ...(iat !== undefined ? { iat, signingWindowSeconds: Math.max(0, iat - claims.decidedAt) } : {}),
205
+ lateSeal,
206
+ decisionPayloadDigest,
207
+ ...(approver ? { approver } : {}),
208
+ ...(requester ? { requester } : {}),
209
+ ...(presentation ? { presentation } : {}),
210
+ ...(statement ? { statement } : {}),
211
+ };
212
+ }
213
+ /** A verification key as an export or a CLI file states it (dates as ISO strings): the one shape of a key record. */
214
+ export const ApprovalSealVerificationKeySchema = VerificationKeyRecordSchema;
215
+ /**
216
+ * Evidence recorded outside the application that a decision's payload existed before a key's compromise, as the file an
217
+ * operator keeps it in (`wildo seal verify --corroboration <file>`).
218
+ */
219
+ export const ApprovalSealCorroborationSchema = z.object({ decisionPayloadDigest: z.string().min(1), recordedAt: z.string().min(1) });
220
+ /**
221
+ * What `wildo seal verify` reads: one seal and everything it needs to verify, offline. A bundle is what the HOST exports,
222
+ * so it carries no pin set, no signing-log exports and no corroboration: each is evidence against the host, and reaches
223
+ * the verifier only from the operator's own files (`ApprovalSealVerificationInput.pins` / `signingLogExports` /
224
+ * `corroboration`). The schema is not strict, so a bundle naming any of them has it stripped on parse rather than
225
+ * believed (#2932 review H1, R1).
226
+ */
227
+ export const ApprovalSealVerificationBundleSchema = z.object({
228
+ jws: z.string().min(1),
229
+ keys: z.array(ApprovalSealVerificationKeySchema).min(1),
230
+ expectedIssuer: z.string().min(1).optional(),
231
+ disclosures: z.array(z.object({ claimName: z.enum(ApprovalSealDisclosureClaim), salt: z.string().min(1), value: z.record(z.string(), z.unknown()) })).optional(),
232
+ });
233
+ //# sourceMappingURL=approval-seal-verifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approval-seal-verifier.js","sourceRoot":"","sources":["../../../../src/key-management/approval-seal-verifier.ts"],"names":[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C,QAAQ,EAAE;CACjK,CAAC,CAAC","sourcesContent":["/**\n * # Verifying an approval seal, offline (#2903)\n *\n * Everything a verifier needs travels with the seal: the compact JWS, the stored records of the keys that may have signed\n * it (their public half, scope and issuer, as an export carries them), and, when the person's content is to be shown,\n * the disclosures. Nothing here calls the application or the platform, so a seal verifies after the application is gone.\n *\n * ## What is checked, and on whose authority\n *\n * - The header: ES256 is pinned per key from the key RECORD, never read from the header (RFC 8725 §3.1); `jku`, `x5u`,\n * `jwk` and `x5c` are never followed (RFC 8725 §3.10, RFC 7515 §10.7); a `crit` naming anything is refused, since no\n * extension is understood (RFC 7515 §4.1.11); `typ` must be the approval seal's.\n * - The signature, under the key the `kid` names among those given.\n * - The issuer: the payload's `iss` must be the key record's, and the expected issuer when one is given.\n * - The claims: the version-1 shape, strict.\n * - The key's scope, from its stored record and never from a JWKS member: an organization-scoped key verifies only a seal\n * whose tenant is that organization.\n * - The disclosures: each must digest to the commitment its claim names; a commitment with no disclosure is reported as\n * erased (the person's content was removed, the seal stands).\n * - A COMPROMISED key: the signature may still verify, but the seal is not PROVABLE unless corroborated by evidence the\n * key's holder could not have forged: the decision's payload digest recorded outside the application before the\n * compromise instant (an exported audit event, an immutable sink).\n * - The OPERATOR'S PIN SET, when one is given (#2932): the key must be pinned, by the RFC 7638 thumbprint of the public\n * half the verifier was handed (so a key record that names a pinned `kid` over another key is refused), and the pin's\n * state, scope and compromise instant are used instead of the record's. The record (from a bundle, from the host)\n * only supplies the public half and the issuer; the operator's pin decides whether that half is theirs and what became\n * of it. Without a pin set the records are trusted as given, as before.\n * - The OPERATOR'S KEPT SIGNING-LOG EXPORTS, when given (#2932): a seal under a key compromised after an export that lists\n * it is corroborated by that export, which the host could not have signed after the compromise without the operator's\n * copy disagreeing. Each export is verified here, with the operator's pin set for the export key.\n *\n * spec-cite: RFC 8725 §3.1 (algorithm verification), §3.10 (do not trust received URLs); RFC 7515 §4.1.11 (`crit`),\n * §10.7 (key selection from header parameters). Cited by section; the behaviour is this file's decision.\n */\nimport { z } from 'zod';\nimport { singleJwsTypeOf, CryptoKey_Purpose, CryptoKey_Scope, CryptoKey_VersionState, type CryptoKeyPinSet } from '@wildo-ai/saas-models';\nimport { ES256_JWS_ALGORITHM, isP256PublicJwk, verifyEs256, type P256PublicJwk } from './es256-jws';\nimport { decisionPayloadDigestOf, sealClaimsDigestOf } from './signature-request.contracts';\nimport { VerificationKeyRecordSchema, compareSigningLogExports, pinnedVerificationKeyOf, verifySigningLogExport } from './signing-log-export.contracts';\nimport {\n ApprovalSealClaimsV1Schema,\n ApprovalSealDisclosureClaim,\n approvalSealDisclosureDigestOf,\n type ApprovalSealClaimsV1,\n type ApprovalSealDisclosureValue,\n} from './approval-seal.contracts';\n\n/** The approval seal's JWS `typ`. */\nconst APPROVAL_SEAL_TYP = singleJwsTypeOf(CryptoKey_Purpose.APPROVAL_SEAL);\n\n/** The payload members the custodian sets; the rest is the decision's committed payload. */\nconst CUSTODIAN_SET_CLAIMS = ['iss', 'iat', 'lateSeal'] as const;\n\n/** One key that may have signed a seal: its STORED record (scope, issuer, state), as an export carries it. */\nexport interface ApprovalSealVerificationKey {\n readonly kid: string;\n readonly publicJwk: P256PublicJwk;\n /** The algorithm the key record pins. ES256 for every approval-seal key today. */\n readonly alg: typeof ES256_JWS_ALGORITHM;\n readonly scope: CryptoKey_Scope;\n /** The application's id for an APPLICATION key, the organization's for an ORGANIZATION key. */\n readonly scopeId: string;\n readonly iss: string;\n readonly state: CryptoKey_VersionState;\n /** ISO 8601, for a COMPROMISED key: the earliest instant its private half may have been exposed. */\n readonly compromiseInstant?: string;\n}\n\n/** Evidence recorded OUTSIDE the application that the decision's payload existed before a key's compromise. */\nexport interface ApprovalSealCorroboration {\n readonly decisionPayloadDigest: string;\n /** ISO 8601: when the evidence was recorded where the key's holder could not rewrite it. */\n readonly recordedAt: string;\n}\n\nexport interface ApprovalSealVerificationInput {\n readonly jws: string;\n readonly keys: readonly ApprovalSealVerificationKey[];\n /** The issuer the seal must carry, when the verifier knows which application it expects. */\n readonly expectedIssuer?: string;\n readonly disclosures?: readonly ApprovalSealDisclosureValue[];\n readonly corroboration?: ApprovalSealCorroboration;\n /** The operator's pin set for approval seals (#2932), from a channel the host does not control. */\n readonly pins?: CryptoKeyPinSet;\n /**\n * The signing-log exports the operator kept (#2932), with the records of the keys that signed them and the operator's\n * pin set for SIGNING_LOG_EXPORT. An export that does not verify, or was signed after its own key's compromise, is\n * ignored: it corroborates nothing.\n */\n readonly signingLogExports?: {\n readonly exports: readonly string[];\n readonly keys: readonly ApprovalSealVerificationKey[];\n readonly pins?: CryptoKeyPinSet;\n };\n}\n\n/** What corroborated a seal under a compromised key. */\nexport enum ApprovalSealCorroborationSource {\n /** The decision's payload digest, recorded outside the application before the compromise. */\n RECORDED_EVIDENCE = 'recorded_evidence',\n /** A signing-log export the operator kept, signed before the compromise, lists the seal. */\n SIGNING_LOG_EXPORT = 'signing_log_export',\n}\n\n/** Why a seal does not verify. */\nexport enum ApprovalSealVerificationFailure {\n /** Not a compact JWS with a JSON header and payload. */\n MALFORMED = 'malformed',\n /** The header's `alg` is not the one the key record pins. */\n ALGORITHM_NOT_PINNED = 'algorithm_not_pinned',\n /** The header names a critical extension, and none is understood. */\n CRITICAL_EXTENSION = 'critical_extension',\n /** The header's `typ` is not the approval seal's. */\n TYPE_MISMATCH = 'type_mismatch',\n /** No given key has the header's `kid`. */\n UNKNOWN_KEY = 'unknown_key',\n SIGNATURE_INVALID = 'signature_invalid',\n /** The payload's issuer is not the key record's, or not the expected one. */\n ISSUER_MISMATCH = 'issuer_mismatch',\n /** The payload is not the version-1 claims shape. */\n CLAIMS_INVALID = 'claims_invalid',\n /** The key's stored scope does not cover the seal's tenant (or is not a scope a seal is signed under). */\n TENANT_OUTSIDE_KEY_SCOPE = 'tenant_outside_key_scope',\n /** A disclosure does not digest to the commitment its claim names. */\n DISCLOSURE_MISMATCH = 'disclosure_mismatch',\n /** A pin set was given and does not pin the key, or the key handed over is not the one its pinned `kid` names. */\n UNPINNED = 'unpinned',\n}\n\n/** What the seal says about one person's disclosure. */\nexport enum ApprovalSealDisclosureStanding {\n /** Given, and it digests to the commitment. */\n DISCLOSED = 'disclosed',\n /** Committed to, and not given: the content was erased (or withheld). The seal stands. */\n ERASED = 'erased',\n}\n\nexport interface ApprovalSealVerification {\n /** The signature verifies, under a key whose record covers the seal, over well-formed claims and matching disclosures. */\n readonly valid: boolean;\n readonly failures: readonly ApprovalSealVerificationFailure[];\n /**\n * The seal proves what it says: valid, and its key not compromised, or corroborated before the compromise. A valid seal\n * under a compromised key, uncorroborated, is reported valid and NOT provable.\n */\n readonly provable: boolean;\n /** For a seal under a compromised key, what corroborated it; absent when nothing did (or nothing needed to). */\n readonly corroboratedBy?: ApprovalSealCorroborationSource;\n readonly kid?: string;\n readonly keyState?: CryptoKey_VersionState;\n readonly claims?: ApprovalSealClaimsV1;\n readonly iss?: string;\n /** The signing instant, epoch seconds. */\n readonly iat?: number;\n readonly lateSeal?: boolean;\n /** Seconds between the decision and its signature: what the database held at signing is what is sealed. */\n readonly signingWindowSeconds?: number;\n /** The digest of the decision's committed payload, to compare with the RESOLVED row of an exported trail. */\n readonly decisionPayloadDigest?: string;\n readonly approver?: { readonly standing: ApprovalSealDisclosureStanding; readonly value?: Readonly<Record<string, unknown>> };\n readonly requester?: { readonly standing: ApprovalSealDisclosureStanding; readonly value?: Readonly<Record<string, unknown>> };\n /** What the person was shown (#2903 S6), when the seal binds it: DISCLOSED with the presentation, else not given. */\n readonly presentation?: { readonly standing: ApprovalSealDisclosureStanding; readonly value?: Readonly<Record<string, unknown>> };\n /** What the person answered, when the seal binds it. */\n readonly statement?: { readonly standing: ApprovalSealDisclosureStanding; readonly value?: Readonly<Record<string, unknown>> };\n}\n\nfunction decodeJson(part: string | undefined): Record<string, unknown> | null {\n if (!part) return null;\n try {\n const value: unknown = JSON.parse(Buffer.from(part, 'base64url').toString('utf8'));\n return value !== null && typeof value === 'object' && !Array.isArray(value) ? (value as Record<string, unknown>) : null;\n } catch {\n return null;\n }\n}\n\nfunction disclosureStanding(\n claimName: ApprovalSealDisclosureClaim,\n commitment: string | undefined,\n disclosures: readonly ApprovalSealDisclosureValue[],\n failures: ApprovalSealVerificationFailure[],\n): ApprovalSealVerification['approver'] {\n if (!commitment) return undefined;\n const given = disclosures.filter((disclosure) => disclosure.claimName === claimName);\n if (given.length === 0) return { standing: ApprovalSealDisclosureStanding.ERASED };\n const matching = given.find((disclosure) => approvalSealDisclosureDigestOf(disclosure) === commitment);\n if (!matching) {\n failures.push(ApprovalSealVerificationFailure.DISCLOSURE_MISMATCH);\n return { standing: ApprovalSealDisclosureStanding.ERASED };\n }\n return { standing: ApprovalSealDisclosureStanding.DISCLOSED, value: matching.value };\n}\n\n/**\n * What corroborates a seal under a compromised key, if anything: evidence of its payload recorded before the compromise,\n * or a kept export signed before the compromise that lists this exact seal (its issuer, its key, its signed claims).\n */\nfunction corroborationOf(\n input: ApprovalSealVerificationInput,\n key: ApprovalSealVerificationKey,\n payload: Readonly<Record<string, unknown>>,\n decisionPayloadDigest: string,\n): ApprovalSealCorroborationSource | undefined {\n if (key.compromiseInstant === undefined) return undefined;\n const compromisedFrom = Date.parse(key.compromiseInstant);\n if (input.corroboration && input.corroboration.decisionPayloadDigest === decisionPayloadDigest && Date.parse(input.corroboration.recordedAt) < compromisedFrom) {\n return ApprovalSealCorroborationSource.RECORDED_EVIDENCE;\n }\n const logged = input.signingLogExports;\n if (!logged) return undefined;\n const claimsDigest = sealClaimsDigestOf(payload);\n const evidence = logged.exports.flatMap((jws) => {\n const exported = verifySigningLogExport({ jws, keys: logged.keys, ...(logged.pins ? { pins: logged.pins } : {}), expectedIssuer: key.iss });\n return exported.provable && exported.claims ? [exported.claims] : [];\n });\n // The exports must agree with each other first (#2932 review M3): an export is dated by the instant it states for\n // itself, so a host holding the export key could sign one dated before the compromise; it disagrees with the operator's\n // kept exports (a different hash at some sequence, or a head behind an earlier one), and then none of them corroborates.\n if (!compareSigningLogExports(evidence).consistent) return undefined;\n for (const claims of evidence) {\n if (claims.iat * 1000 >= compromisedFrom) continue;\n const lists = claims.entries.some((entry) =>\n entry.purpose === CryptoKey_Purpose.APPROVAL_SEAL && entry.kid === key.kid && entry.iss === key.iss && entry.claimsDigest === claimsDigest);\n if (lists) return ApprovalSealCorroborationSource.SIGNING_LOG_EXPORT;\n }\n return undefined;\n}\n\n/** See the file's header. Pure and offline. */\nexport function verifyApprovalSeal(input: ApprovalSealVerificationInput): ApprovalSealVerification {\n const failures: ApprovalSealVerificationFailure[] = [];\n const fail = (failure: ApprovalSealVerificationFailure, extra: Partial<ApprovalSealVerification> = {}): ApprovalSealVerification =>\n ({ valid: false, provable: false, failures: [...failures, failure], ...extra });\n\n const parts = input.jws.split('.');\n const header = parts.length === 3 ? decodeJson(parts[0]) : null;\n const payload = parts.length === 3 ? decodeJson(parts[1]) : null;\n if (!header || !payload || !parts[2]) return fail(ApprovalSealVerificationFailure.MALFORMED);\n\n const kid = typeof header.kid === 'string' ? header.kid : undefined;\n // The key is chosen by `kid` among the keys the verifier was GIVEN; `jku`/`x5u`/`jwk`/`x5c` are never read.\n const record = kid ? input.keys.find((candidate) => candidate.kid === kid) : undefined;\n if (!record || !isP256PublicJwk(record.publicJwk)) return fail(ApprovalSealVerificationFailure.UNKNOWN_KEY, kid ? { kid } : {});\n // The operator's pin, when given: the key handed over must be the one the pinned thumbprint names, and the pin (not\n // the record) says what became of it.\n const key = pinnedVerificationKeyOf(record, input.pins);\n if (!key) return fail(ApprovalSealVerificationFailure.UNPINNED, { kid });\n if (header.alg !== key.alg || key.alg !== ES256_JWS_ALGORITHM) return fail(ApprovalSealVerificationFailure.ALGORITHM_NOT_PINNED, { kid });\n if (header.crit !== undefined) return fail(ApprovalSealVerificationFailure.CRITICAL_EXTENSION, { kid });\n if (header.typ !== APPROVAL_SEAL_TYP) return fail(ApprovalSealVerificationFailure.TYPE_MISMATCH, { kid });\n if (!verifyEs256(`${parts[0]}.${parts[1]}`, Buffer.from(parts[2], 'base64url'), key.publicJwk)) {\n return fail(ApprovalSealVerificationFailure.SIGNATURE_INVALID, { kid, keyState: key.state });\n }\n\n const iss = typeof payload.iss === 'string' ? payload.iss : undefined;\n const iat = typeof payload.iat === 'number' ? payload.iat : undefined;\n const lateSeal = payload.lateSeal === true;\n if (!iss || iss !== key.iss || (input.expectedIssuer !== undefined && iss !== input.expectedIssuer)) failures.push(ApprovalSealVerificationFailure.ISSUER_MISMATCH);\n\n const committed = Object.fromEntries(Object.entries(payload).filter(([name]) => !(CUSTODIAN_SET_CLAIMS as readonly string[]).includes(name)));\n const parsed = ApprovalSealClaimsV1Schema.safeParse(committed);\n if (!parsed.success) return fail(ApprovalSealVerificationFailure.CLAIMS_INVALID, { kid, keyState: key.state, ...(iss ? { iss } : {}) });\n const claims = parsed.data;\n\n // The key's scope from its RECORD: an organization key covers only that organization's decisions.\n const scopeCovers = key.scope === CryptoKey_Scope.APPLICATION || (key.scope === CryptoKey_Scope.ORGANIZATION && claims.tenant === key.scopeId);\n if (!scopeCovers) failures.push(ApprovalSealVerificationFailure.TENANT_OUTSIDE_KEY_SCOPE);\n\n const disclosures = input.disclosures ?? [];\n const approver = disclosureStanding(ApprovalSealDisclosureClaim.APPROVER, claims.approver, disclosures, failures);\n const requester = disclosureStanding(ApprovalSealDisclosureClaim.REQUESTER, claims.requester?.disclosure, disclosures, failures);\n const presentation = disclosureStanding(ApprovalSealDisclosureClaim.PRESENTATION, claims.presentation?.digest, disclosures, failures);\n const statement = disclosureStanding(ApprovalSealDisclosureClaim.STATEMENT, claims.statementDigest, disclosures, failures);\n\n const decisionPayloadDigest = decisionPayloadDigestOf(committed);\n const valid = failures.length === 0;\n const compromised = key.state === CryptoKey_VersionState.COMPROMISED;\n const corroboratedBy = compromised ? corroborationOf(input, key, payload, decisionPayloadDigest) : undefined;\n const corroborated = !compromised || corroboratedBy !== undefined;\n return {\n valid,\n failures,\n provable: valid && corroborated,\n ...(corroboratedBy ? { corroboratedBy } : {}),\n kid,\n keyState: key.state,\n claims,\n iss,\n ...(iat !== undefined ? { iat, signingWindowSeconds: Math.max(0, iat - claims.decidedAt) } : {}),\n lateSeal,\n decisionPayloadDigest,\n ...(approver ? { approver } : {}),\n ...(requester ? { requester } : {}),\n ...(presentation ? { presentation } : {}),\n ...(statement ? { statement } : {}),\n };\n}\n\n/** A verification key as an export or a CLI file states it (dates as ISO strings): the one shape of a key record. */\nexport const ApprovalSealVerificationKeySchema = VerificationKeyRecordSchema;\n\n/**\n * Evidence recorded outside the application that a decision's payload existed before a key's compromise, as the file an\n * operator keeps it in (`wildo seal verify --corroboration <file>`).\n */\nexport const ApprovalSealCorroborationSchema = z.object({ decisionPayloadDigest: z.string().min(1), recordedAt: z.string().min(1) });\n\n/**\n * What `wildo seal verify` reads: one seal and everything it needs to verify, offline. A bundle is what the HOST exports,\n * so it carries no pin set, no signing-log exports and no corroboration: each is evidence against the host, and reaches\n * the verifier only from the operator's own files (`ApprovalSealVerificationInput.pins` / `signingLogExports` /\n * `corroboration`). The schema is not strict, so a bundle naming any of them has it stripped on parse rather than\n * believed (#2932 review H1, R1).\n */\nexport const ApprovalSealVerificationBundleSchema = z.object({\n jws: z.string().min(1),\n keys: z.array(ApprovalSealVerificationKeySchema).min(1),\n expectedIssuer: z.string().min(1).optional(),\n disclosures: z.array(z.object({ claimName: z.enum(ApprovalSealDisclosureClaim), salt: z.string().min(1), value: z.record(z.string(), z.unknown()) })).optional(),\n});\nexport type ApprovalSealVerificationBundle = z.infer<typeof ApprovalSealVerificationBundleSchema>;\n"]}
@@ -0,0 +1,131 @@
1
+ import { z } from 'zod';
2
+ import { ApprovalPresentationProvenance, ApprovalSealMeaning, ApprovalSource, AuthMethod, HumanDecision_AnswerChannel, HumanDecision_DeciderKind, HumanDecision_RequesterKind } from '@wildo-ai/saas-models';
3
+ /**
4
+ * # The approval seal's claims, version 1 (#2903)
5
+ *
6
+ * The shape is fixed once seals exist: a seal made today must verify, and read the same, for as long as its record is
7
+ * kept. A change is a new version (`v`), never an edit of this one. The application builds and checks these claims at
8
+ * commit; the custodian (#2891) checks only what it decides on (`jti`, `decidedAt`, `tenant`) and signs the rest as
9
+ * committed, under the decision-payload digest; the offline verifier checks all of it.
10
+ *
11
+ * ## No person in clear
12
+ *
13
+ * No personal value and no deterministic pseudonym is in the payload. Each person (the approver, and a requester who is
14
+ * a person) appears ONLY as the digest of one salted disclosure, in the SD-JWT disclosure form: SHA-256 over the base64url
15
+ * of the JSON array `[salt, claimName, value]`. The claim name is inside the digest, so a disclosure cannot be replayed
16
+ * into another slot. The disclosure, salt and value included, is kept on the seal's row.
17
+ *
18
+ * spec-cite: N/A — the disclosure form is SD-JWT's (RFC 9901 §4.2.1, salted array), reproduced from its structure rather
19
+ * than quoted; the digest here is over the RFC 8785 canonical form of the array so it can be rebuilt from stored fields.
20
+ */
21
+ export declare const APPROVAL_SEAL_CLAIMS_VERSION = 1;
22
+ /** The claim names a disclosure may stand for. */
23
+ export declare enum ApprovalSealDisclosureClaim {
24
+ /** The person who decided: printed name, reference, authentication time, session reference, any assertion. */
25
+ APPROVER = "approver",
26
+ /** The person who asked, when a person asked. */
27
+ REQUESTER = "requester",
28
+ /**
29
+ * What the person was shown (#2903 S6): the decision's presentation, its wording and the values decided on. Salted like a
30
+ * person's disclosure, so a seal shared alone cannot confirm a guessed presentation. Kept with the seal when a person
31
+ * is erased: it is the record of what was decided on, not a fact about the person who decided.
32
+ */
33
+ PRESENTATION = "presentation",
34
+ /** What the person answered (#2903 S6): the option, the values, the arguments they authored, the reason code. */
35
+ STATEMENT = "statement"
36
+ }
37
+ /** The decider's context, as #2905 records it, minus anything that would identify the person (their link id, session). */
38
+ export declare const ApprovalSealDeciderClaimsSchema: z.ZodObject<{
39
+ kind: z.ZodEnum<typeof HumanDecision_DeciderKind>;
40
+ channel: z.ZodEnum<typeof HumanDecision_AnswerChannel>;
41
+ /** The client that acted for the person, in the style of RFC 8693 §4.1 `act`. */
42
+ act: z.ZodOptional<z.ZodObject<{
43
+ clientId: z.ZodString;
44
+ }, z.core.$strict>>;
45
+ authTime: z.ZodOptional<z.ZodNumber>;
46
+ amr: z.ZodOptional<z.ZodArray<z.ZodString>>;
47
+ stepUpMethod: z.ZodOptional<z.ZodEnum<typeof AuthMethod>>;
48
+ /** For a chat answer: the inbound source it arrived through (`slack:interactions`). Names a channel, not a person. */
49
+ inboundSourceKey: z.ZodOptional<z.ZodString>;
50
+ }, z.core.$strict>;
51
+ /** Who asked. A machine is named by kind only; a person by their disclosure. */
52
+ export declare const ApprovalSealRequesterClaimsSchema: z.ZodObject<{
53
+ kind: z.ZodEnum<typeof HumanDecision_RequesterKind>;
54
+ clientId: z.ZodOptional<z.ZodString>;
55
+ /** The digest of the requester's disclosure, when the requester is a person. */
56
+ disclosure: z.ZodOptional<z.ZodString>;
57
+ }, z.core.$strict>;
58
+ /** The approval seal's claims, version 1: everything but what the custodian sets (`iss`, `iat`, `kid`, `typ`, `lateSeal`). */
59
+ export declare const ApprovalSealClaimsV1Schema: z.ZodObject<{
60
+ v: z.ZodLiteral<1>;
61
+ /** Minted at commit: at least 128 bits, base64url. With `iss` the seal's id. */
62
+ jti: z.ZodString;
63
+ source: z.ZodEnum<typeof ApprovalSource>;
64
+ decisionRef: z.ZodString;
65
+ step: z.ZodNumber;
66
+ sequence: z.ZodNumber;
67
+ /** The jti of the seal this one supersedes. */
68
+ supersedes: z.ZodOptional<z.ZodString>;
69
+ /** The organization the decision belongs to, or the application's id when it belongs to none. */
70
+ tenant: z.ZodString;
71
+ subject: z.ZodObject<{
72
+ resourceType: z.ZodString;
73
+ resourceId: z.ZodString;
74
+ presentationSchemaVersion: z.ZodOptional<z.ZodNumber>;
75
+ }, z.core.$strict>;
76
+ /** What was presented, when the engine built it (#2903 S6): its id, how its rendering is known, its salted digest. */
77
+ presentation: z.ZodOptional<z.ZodObject<{
78
+ /** The id the act echoed, or the one the engine derived for what it sent. Absent when the application held no key. */
79
+ id: z.ZodOptional<z.ZodString>;
80
+ provenance: z.ZodEnum<typeof ApprovalPresentationProvenance>;
81
+ digest: z.ZodString;
82
+ }, z.core.$strict>>;
83
+ /** The digest of the approver's statement (the `statement` disclosure): what they answered. */
84
+ statementDigest: z.ZodOptional<z.ZodString>;
85
+ meaning: z.ZodEnum<typeof ApprovalSealMeaning>;
86
+ /** Only an outcome a person decided (`APPROVAL_SEAL_OUTCOMES`). */
87
+ outcome: z.ZodEnum<{
88
+ accepted: import("@wildo-ai/saas-models").HumanDecision_Outcome.ACCEPTED;
89
+ accepted_with_modifications: import("@wildo-ai/saas-models").HumanDecision_Outcome.ACCEPTED_WITH_MODIFICATIONS;
90
+ rejected: import("@wildo-ai/saas-models").HumanDecision_Outcome.REJECTED;
91
+ }>;
92
+ /** When the person decided, epoch seconds: distinct from `iat`, when the custodian signed. */
93
+ decidedAt: z.ZodNumber;
94
+ decider: z.ZodObject<{
95
+ kind: z.ZodEnum<typeof HumanDecision_DeciderKind>;
96
+ channel: z.ZodEnum<typeof HumanDecision_AnswerChannel>;
97
+ /** The client that acted for the person, in the style of RFC 8693 §4.1 `act`. */
98
+ act: z.ZodOptional<z.ZodObject<{
99
+ clientId: z.ZodString;
100
+ }, z.core.$strict>>;
101
+ authTime: z.ZodOptional<z.ZodNumber>;
102
+ amr: z.ZodOptional<z.ZodArray<z.ZodString>>;
103
+ stepUpMethod: z.ZodOptional<z.ZodEnum<typeof AuthMethod>>;
104
+ /** For a chat answer: the inbound source it arrived through (`slack:interactions`). Names a channel, not a person. */
105
+ inboundSourceKey: z.ZodOptional<z.ZodString>;
106
+ }, z.core.$strict>;
107
+ requester: z.ZodOptional<z.ZodObject<{
108
+ kind: z.ZodEnum<typeof HumanDecision_RequesterKind>;
109
+ clientId: z.ZodOptional<z.ZodString>;
110
+ /** The digest of the requester's disclosure, when the requester is a person. */
111
+ disclosure: z.ZodOptional<z.ZodString>;
112
+ }, z.core.$strict>>;
113
+ /** The digest of the approver's disclosure. */
114
+ approver: z.ZodString;
115
+ }, z.core.$strict>;
116
+ export type ApprovalSealClaimsV1 = z.infer<typeof ApprovalSealClaimsV1Schema>;
117
+ /** One disclosure, as stored on the seal's row. */
118
+ export interface ApprovalSealDisclosureValue {
119
+ readonly claimName: ApprovalSealDisclosureClaim;
120
+ readonly salt: string;
121
+ readonly value: Readonly<Record<string, unknown>>;
122
+ }
123
+ /** A fresh disclosure salt: 128 bits from the CSPRNG, base64url. Never reused. */
124
+ export declare function newApprovalSealDisclosureSalt(): string;
125
+ /** The disclosure's encoded form: base64url of the RFC 8785 canonical JSON array `[salt, claimName, value]`. */
126
+ export declare function encodeApprovalSealDisclosure(disclosure: ApprovalSealDisclosureValue): string;
127
+ /** The commitment a payload carries for a disclosure: base64url SHA-256 of its encoded form. */
128
+ export declare function approvalSealDisclosureDigestOf(disclosure: ApprovalSealDisclosureValue): string;
129
+ /** A new seal id: 128 bits, base64url. */
130
+ export declare function newApprovalSealJti(): string;
131
+ //# sourceMappingURL=approval-seal.contracts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approval-seal.contracts.d.ts","sourceRoot":"","sources":["../../../../src/key-management/approval-seal.contracts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,8BAA8B,EAC9B,mBAAmB,EAEnB,cAAc,EACd,UAAU,EACV,2BAA2B,EAC3B,yBAAyB,EACzB,2BAA2B,EAC5B,MAAM,uBAAuB,CAAC;AAI/B;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,4BAA4B,IAAI,CAAC;AAE9C,kDAAkD;AAClD,oBAAY,2BAA2B;IACrC,8GAA8G;IAC9G,QAAQ,aAAa;IACrB,iDAAiD;IACjD,SAAS,cAAc;IACvB;;;;OAIG;IACH,YAAY,iBAAiB;IAC7B,iHAAiH;IACjH,SAAS,cAAc;CACxB;AAKD,0HAA0H;AAC1H,eAAO,MAAM,+BAA+B;;;IAG1C,iFAAiF;;;;;;;IAKjF,sHAAsH;;kBAEtH,CAAC;AAEH,gFAAgF;AAChF,eAAO,MAAM,iCAAiC;;;IAG5C,gFAAgF;;kBAEhF,CAAC;AAEH,8HAA8H;AAC9H,eAAO,MAAM,0BAA0B;;IAErC,gFAAgF;;;;;;IAMhF,+CAA+C;;IAE/C,iGAAiG;;;;;;;IAOjG,sHAAsH;;QAEpH,sHAAsH;;;;;IAKxH,+FAA+F;;;IAG/F,mEAAmE;;;;;;IAEnE,8FAA8F;;;;;QA/C9F,iFAAiF;;;;;;;QAKjF,sHAAsH;;;;;;QAQtH,gFAAgF;;;IAsChF,+CAA+C;;kBAE/C,CAAC;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAE9E,mDAAmD;AACnD,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,SAAS,EAAE,2BAA2B,CAAC;IAChD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACnD;AAED,kFAAkF;AAClF,wBAAgB,6BAA6B,IAAI,MAAM,CAEtD;AAED,gHAAgH;AAChH,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,2BAA2B,GAAG,MAAM,CAE5F;AAED,gGAAgG;AAChG,wBAAgB,8BAA8B,CAAC,UAAU,EAAE,2BAA2B,GAAG,MAAM,CAE9F;AAED,0CAA0C;AAC1C,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C"}
@@ -0,0 +1,115 @@
1
+ import { createHash, randomBytes } from 'node:crypto';
2
+ import { z } from 'zod';
3
+ import { ApprovalPresentationProvenance, ApprovalSealMeaning, APPROVAL_SEAL_OUTCOMES, ApprovalSource, AuthMethod, HumanDecision_AnswerChannel, HumanDecision_DeciderKind, HumanDecision_RequesterKind, } from '@wildo-ai/saas-models';
4
+ import { canonicalizeJson } from '../canonical-json/rfc8785-canonical-json.js';
5
+ import { base64url } from './es256-jws.js';
6
+ /**
7
+ * # The approval seal's claims, version 1 (#2903)
8
+ *
9
+ * The shape is fixed once seals exist: a seal made today must verify, and read the same, for as long as its record is
10
+ * kept. A change is a new version (`v`), never an edit of this one. The application builds and checks these claims at
11
+ * commit; the custodian (#2891) checks only what it decides on (`jti`, `decidedAt`, `tenant`) and signs the rest as
12
+ * committed, under the decision-payload digest; the offline verifier checks all of it.
13
+ *
14
+ * ## No person in clear
15
+ *
16
+ * No personal value and no deterministic pseudonym is in the payload. Each person (the approver, and a requester who is
17
+ * a person) appears ONLY as the digest of one salted disclosure, in the SD-JWT disclosure form: SHA-256 over the base64url
18
+ * of the JSON array `[salt, claimName, value]`. The claim name is inside the digest, so a disclosure cannot be replayed
19
+ * into another slot. The disclosure, salt and value included, is kept on the seal's row.
20
+ *
21
+ * spec-cite: N/A — the disclosure form is SD-JWT's (RFC 9901 §4.2.1, salted array), reproduced from its structure rather
22
+ * than quoted; the digest here is over the RFC 8785 canonical form of the array so it can be rebuilt from stored fields.
23
+ */
24
+ export const APPROVAL_SEAL_CLAIMS_VERSION = 1;
25
+ /** The claim names a disclosure may stand for. */
26
+ export var ApprovalSealDisclosureClaim;
27
+ (function (ApprovalSealDisclosureClaim) {
28
+ /** The person who decided: printed name, reference, authentication time, session reference, any assertion. */
29
+ ApprovalSealDisclosureClaim["APPROVER"] = "approver";
30
+ /** The person who asked, when a person asked. */
31
+ ApprovalSealDisclosureClaim["REQUESTER"] = "requester";
32
+ /**
33
+ * What the person was shown (#2903 S6): the decision's presentation, its wording and the values decided on. Salted like a
34
+ * person's disclosure, so a seal shared alone cannot confirm a guessed presentation. Kept with the seal when a person
35
+ * is erased: it is the record of what was decided on, not a fact about the person who decided.
36
+ */
37
+ ApprovalSealDisclosureClaim["PRESENTATION"] = "presentation";
38
+ /** What the person answered (#2903 S6): the option, the values, the arguments they authored, the reason code. */
39
+ ApprovalSealDisclosureClaim["STATEMENT"] = "statement";
40
+ })(ApprovalSealDisclosureClaim || (ApprovalSealDisclosureClaim = {}));
41
+ /** A disclosure commitment: base64url SHA-256, 43 characters. */
42
+ const DigestSchema = z.string().regex(/^[A-Za-z0-9_-]{43}$/);
43
+ /** The decider's context, as #2905 records it, minus anything that would identify the person (their link id, session). */
44
+ export const ApprovalSealDeciderClaimsSchema = z.strictObject({
45
+ kind: z.enum(HumanDecision_DeciderKind),
46
+ channel: z.enum(HumanDecision_AnswerChannel),
47
+ /** The client that acted for the person, in the style of RFC 8693 §4.1 `act`. */
48
+ act: z.strictObject({ clientId: z.string().min(1) }).optional(),
49
+ authTime: z.number().int().nonnegative().optional(),
50
+ amr: z.array(z.string().min(1)).min(1).optional(),
51
+ stepUpMethod: z.enum(AuthMethod).optional(),
52
+ /** For a chat answer: the inbound source it arrived through (`slack:interactions`). Names a channel, not a person. */
53
+ inboundSourceKey: z.string().min(1).optional(),
54
+ });
55
+ /** Who asked. A machine is named by kind only; a person by their disclosure. */
56
+ export const ApprovalSealRequesterClaimsSchema = z.strictObject({
57
+ kind: z.enum(HumanDecision_RequesterKind),
58
+ clientId: z.string().min(1).optional(),
59
+ /** The digest of the requester's disclosure, when the requester is a person. */
60
+ disclosure: DigestSchema.optional(),
61
+ });
62
+ /** The approval seal's claims, version 1: everything but what the custodian sets (`iss`, `iat`, `kid`, `typ`, `lateSeal`). */
63
+ export const ApprovalSealClaimsV1Schema = z.strictObject({
64
+ v: z.literal(APPROVAL_SEAL_CLAIMS_VERSION),
65
+ /** Minted at commit: at least 128 bits, base64url. With `iss` the seal's id. */
66
+ jti: z.string().regex(/^[A-Za-z0-9_-]{22,}$/),
67
+ source: z.enum(ApprovalSource),
68
+ decisionRef: z.string().min(1),
69
+ step: z.number().int().min(0),
70
+ sequence: z.number().int().min(1),
71
+ /** The jti of the seal this one supersedes. */
72
+ supersedes: z.string().min(1).optional(),
73
+ /** The organization the decision belongs to, or the application's id when it belongs to none. */
74
+ tenant: z.string().min(1),
75
+ subject: z.strictObject({
76
+ resourceType: z.string().min(1),
77
+ resourceId: z.string().min(1),
78
+ presentationSchemaVersion: z.number().int().min(1).optional(),
79
+ }),
80
+ /** What was presented, when the engine built it (#2903 S6): its id, how its rendering is known, its salted digest. */
81
+ presentation: z.strictObject({
82
+ /** The id the act echoed, or the one the engine derived for what it sent. Absent when the application held no key. */
83
+ id: z.string().min(1).optional(),
84
+ provenance: z.enum(ApprovalPresentationProvenance),
85
+ digest: DigestSchema,
86
+ }).optional(),
87
+ /** The digest of the approver's statement (the `statement` disclosure): what they answered. */
88
+ statementDigest: DigestSchema.optional(),
89
+ meaning: z.enum(ApprovalSealMeaning),
90
+ /** Only an outcome a person decided (`APPROVAL_SEAL_OUTCOMES`). */
91
+ outcome: z.enum(APPROVAL_SEAL_OUTCOMES),
92
+ /** When the person decided, epoch seconds: distinct from `iat`, when the custodian signed. */
93
+ decidedAt: z.number().int().positive(),
94
+ decider: ApprovalSealDeciderClaimsSchema,
95
+ requester: ApprovalSealRequesterClaimsSchema.optional(),
96
+ /** The digest of the approver's disclosure. */
97
+ approver: DigestSchema,
98
+ });
99
+ /** A fresh disclosure salt: 128 bits from the CSPRNG, base64url. Never reused. */
100
+ export function newApprovalSealDisclosureSalt() {
101
+ return randomBytes(16).toString('base64url');
102
+ }
103
+ /** The disclosure's encoded form: base64url of the RFC 8785 canonical JSON array `[salt, claimName, value]`. */
104
+ export function encodeApprovalSealDisclosure(disclosure) {
105
+ return base64url(canonicalizeJson([disclosure.salt, disclosure.claimName, disclosure.value]));
106
+ }
107
+ /** The commitment a payload carries for a disclosure: base64url SHA-256 of its encoded form. */
108
+ export function approvalSealDisclosureDigestOf(disclosure) {
109
+ return base64url(createHash('sha256').update(encodeApprovalSealDisclosure(disclosure), 'ascii').digest());
110
+ }
111
+ /** A new seal id: 128 bits, base64url. */
112
+ export function newApprovalSealJti() {
113
+ return randomBytes(16).toString('base64url');
114
+ }
115
+ //# sourceMappingURL=approval-seal.contracts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approval-seal.contracts.js","sourceRoot":"","sources":["../../../../src/key-management/approval-seal.contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,8BAA8B,EAC9B,mBAAmB,EACnB,sBAAsB,EACtB,cAAc,EACd,UAAU,EACV,2BAA2B,EAC3B,yBAAyB,EACzB,2BAA2B,GAC5B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC;AAE9C,kDAAkD;AAClD,MAAM,CAAN,IAAY,2BAaX;AAbD,WAAY,2BAA2B;IACrC,8GAA8G;IAC9G,oDAAqB,CAAA;IACrB,iDAAiD;IACjD,sDAAuB,CAAA;IACvB;;;;OAIG;IACH,4DAA6B,CAAA;IAC7B,iHAAiH;IACjH,sDAAuB,CAAA;AACzB,CAAC,EAbW,2BAA2B,KAA3B,2BAA2B,QAatC;AAED,iEAAiE;AACjE,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;AAE7D,0HAA0H;AAC1H,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAAC,CAAC,YAAY,CAAC;IAC5D,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,yBAAyB,CAAC;IACvC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,2BAA2B,CAAC;IAC5C,iFAAiF;IACjF,GAAG,EAAE,CAAC,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,QAA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Q,EAAE,YAAY;CACvB,CAAC,CAAC;AAUH,kFAAkF;AAClF,MAAM,UAAU,6BAA6B;IAC3C,OAAO,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AAC/C,CAAC;AAED,gHAAgH;AAChH,MAAM,UAAU,4BAA4B,CAAC,UAAuC;IAClF,OAAO,SAAS,CAAC,gBAAgB,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,SAAS,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAChG,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,8BAA8B,CAAC,UAAuC;IACpF,OAAO,SAAS,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,4BAA4B,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;AAC5G,CAAC;AAED,0CAA0C;AAC1C,MAAM,UAAU,kBAAkB;IAChC,OAAO,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import { createHash, randomBytes } from 'node:crypto';\nimport { z } from 'zod';\nimport {\n ApprovalPresentationProvenance,\n ApprovalSealMeaning,\n APPROVAL_SEAL_OUTCOMES,\n ApprovalSource,\n AuthMethod,\n HumanDecision_AnswerChannel,\n HumanDecision_DeciderKind,\n HumanDecision_RequesterKind,\n} from '@wildo-ai/saas-models';\nimport { canonicalizeJson } from '../canonical-json/rfc8785-canonical-json';\nimport { base64url } from './es256-jws';\n\n/**\n * # The approval seal's claims, version 1 (#2903)\n *\n * The shape is fixed once seals exist: a seal made today must verify, and read the same, for as long as its record is\n * kept. A change is a new version (`v`), never an edit of this one. The application builds and checks these claims at\n * commit; the custodian (#2891) checks only what it decides on (`jti`, `decidedAt`, `tenant`) and signs the rest as\n * committed, under the decision-payload digest; the offline verifier checks all of it.\n *\n * ## No person in clear\n *\n * No personal value and no deterministic pseudonym is in the payload. Each person (the approver, and a requester who is\n * a person) appears ONLY as the digest of one salted disclosure, in the SD-JWT disclosure form: SHA-256 over the base64url\n * of the JSON array `[salt, claimName, value]`. The claim name is inside the digest, so a disclosure cannot be replayed\n * into another slot. The disclosure, salt and value included, is kept on the seal's row.\n *\n * spec-cite: N/A — the disclosure form is SD-JWT's (RFC 9901 §4.2.1, salted array), reproduced from its structure rather\n * than quoted; the digest here is over the RFC 8785 canonical form of the array so it can be rebuilt from stored fields.\n */\nexport const APPROVAL_SEAL_CLAIMS_VERSION = 1;\n\n/** The claim names a disclosure may stand for. */\nexport enum ApprovalSealDisclosureClaim {\n /** The person who decided: printed name, reference, authentication time, session reference, any assertion. */\n APPROVER = 'approver',\n /** The person who asked, when a person asked. */\n REQUESTER = 'requester',\n /**\n * What the person was shown (#2903 S6): the decision's presentation, its wording and the values decided on. Salted like a\n * person's disclosure, so a seal shared alone cannot confirm a guessed presentation. Kept with the seal when a person\n * is erased: it is the record of what was decided on, not a fact about the person who decided.\n */\n PRESENTATION = 'presentation',\n /** What the person answered (#2903 S6): the option, the values, the arguments they authored, the reason code. */\n STATEMENT = 'statement',\n}\n\n/** A disclosure commitment: base64url SHA-256, 43 characters. */\nconst DigestSchema = z.string().regex(/^[A-Za-z0-9_-]{43}$/);\n\n/** The decider's context, as #2905 records it, minus anything that would identify the person (their link id, session). */\nexport const ApprovalSealDeciderClaimsSchema = z.strictObject({\n kind: z.enum(HumanDecision_DeciderKind),\n channel: z.enum(HumanDecision_AnswerChannel),\n /** The client that acted for the person, in the style of RFC 8693 §4.1 `act`. */\n act: z.strictObject({ clientId: z.string().min(1) }).optional(),\n authTime: z.number().int().nonnegative().optional(),\n amr: z.array(z.string().min(1)).min(1).optional(),\n stepUpMethod: z.enum(AuthMethod).optional(),\n /** For a chat answer: the inbound source it arrived through (`slack:interactions`). Names a channel, not a person. */\n inboundSourceKey: z.string().min(1).optional(),\n});\n\n/** Who asked. A machine is named by kind only; a person by their disclosure. */\nexport const ApprovalSealRequesterClaimsSchema = z.strictObject({\n kind: z.enum(HumanDecision_RequesterKind),\n clientId: z.string().min(1).optional(),\n /** The digest of the requester's disclosure, when the requester is a person. */\n disclosure: DigestSchema.optional(),\n});\n\n/** The approval seal's claims, version 1: everything but what the custodian sets (`iss`, `iat`, `kid`, `typ`, `lateSeal`). */\nexport const ApprovalSealClaimsV1Schema = z.strictObject({\n v: z.literal(APPROVAL_SEAL_CLAIMS_VERSION),\n /** Minted at commit: at least 128 bits, base64url. With `iss` the seal's id. */\n jti: z.string().regex(/^[A-Za-z0-9_-]{22,}$/),\n source: z.enum(ApprovalSource),\n decisionRef: z.string().min(1),\n step: z.number().int().min(0),\n sequence: z.number().int().min(1),\n /** The jti of the seal this one supersedes. */\n supersedes: z.string().min(1).optional(),\n /** The organization the decision belongs to, or the application's id when it belongs to none. */\n tenant: z.string().min(1),\n subject: z.strictObject({\n resourceType: z.string().min(1),\n resourceId: z.string().min(1),\n presentationSchemaVersion: z.number().int().min(1).optional(),\n }),\n /** What was presented, when the engine built it (#2903 S6): its id, how its rendering is known, its salted digest. */\n presentation: z.strictObject({\n /** The id the act echoed, or the one the engine derived for what it sent. Absent when the application held no key. */\n id: z.string().min(1).optional(),\n provenance: z.enum(ApprovalPresentationProvenance),\n digest: DigestSchema,\n }).optional(),\n /** The digest of the approver's statement (the `statement` disclosure): what they answered. */\n statementDigest: DigestSchema.optional(),\n meaning: z.enum(ApprovalSealMeaning),\n /** Only an outcome a person decided (`APPROVAL_SEAL_OUTCOMES`). */\n outcome: z.enum(APPROVAL_SEAL_OUTCOMES),\n /** When the person decided, epoch seconds: distinct from `iat`, when the custodian signed. */\n decidedAt: z.number().int().positive(),\n decider: ApprovalSealDeciderClaimsSchema,\n requester: ApprovalSealRequesterClaimsSchema.optional(),\n /** The digest of the approver's disclosure. */\n approver: DigestSchema,\n});\nexport type ApprovalSealClaimsV1 = z.infer<typeof ApprovalSealClaimsV1Schema>;\n\n/** One disclosure, as stored on the seal's row. */\nexport interface ApprovalSealDisclosureValue {\n readonly claimName: ApprovalSealDisclosureClaim;\n readonly salt: string;\n readonly value: Readonly<Record<string, unknown>>;\n}\n\n/** A fresh disclosure salt: 128 bits from the CSPRNG, base64url. Never reused. */\nexport function newApprovalSealDisclosureSalt(): string {\n return randomBytes(16).toString('base64url');\n}\n\n/** The disclosure's encoded form: base64url of the RFC 8785 canonical JSON array `[salt, claimName, value]`. */\nexport function encodeApprovalSealDisclosure(disclosure: ApprovalSealDisclosureValue): string {\n return base64url(canonicalizeJson([disclosure.salt, disclosure.claimName, disclosure.value]));\n}\n\n/** The commitment a payload carries for a disclosure: base64url SHA-256 of its encoded form. */\nexport function approvalSealDisclosureDigestOf(disclosure: ApprovalSealDisclosureValue): string {\n return base64url(createHash('sha256').update(encodeApprovalSealDisclosure(disclosure), 'ascii').digest());\n}\n\n/** A new seal id: 128 bits, base64url. */\nexport function newApprovalSealJti(): string {\n return randomBytes(16).toString('base64url');\n}\n"]}