@wildo-ai/platform-config-lib 1.1.10 → 1.1.12
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.
- package/dist/esm/_unimplemented/soft-warn.d.ts +24 -49
- package/dist/esm/_unimplemented/soft-warn.d.ts.map +1 -1
- package/dist/esm/_unimplemented/soft-warn.js +24 -49
- package/dist/esm/_unimplemented/soft-warn.js.map +1 -1
- package/dist/esm/blueprint/anchored-region.d.ts +83 -0
- package/dist/esm/blueprint/anchored-region.d.ts.map +1 -0
- package/dist/esm/blueprint/anchored-region.js +263 -0
- package/dist/esm/blueprint/anchored-region.js.map +1 -0
- package/dist/esm/blueprint/blueprint.schemas.d.ts +600 -0
- package/dist/esm/blueprint/blueprint.schemas.d.ts.map +1 -0
- package/dist/esm/blueprint/blueprint.schemas.js +638 -0
- package/dist/esm/blueprint/blueprint.schemas.js.map +1 -0
- package/dist/esm/bootstrap/application-backend-env.contracts.js.map +1 -1
- package/dist/esm/bootstrap/application-creation-verification-env.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/application-creation-verification-env.contracts.js.map +1 -1
- package/dist/esm/bootstrap/bootstrap-planner.js.map +1 -1
- package/dist/esm/bootstrap/bootstrap.contracts.d.ts +13 -1
- package/dist/esm/bootstrap/bootstrap.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/bootstrap.contracts.js +6 -0
- package/dist/esm/bootstrap/bootstrap.contracts.js.map +1 -1
- package/dist/esm/bootstrap/bootstrap.schemas.d.ts +29 -4
- package/dist/esm/bootstrap/bootstrap.schemas.d.ts.map +1 -1
- package/dist/esm/bootstrap/bootstrap.schemas.js +29 -4
- package/dist/esm/bootstrap/bootstrap.schemas.js.map +1 -1
- package/dist/esm/bootstrap/platform-runtime-env.contracts.d.ts +131 -2
- package/dist/esm/bootstrap/platform-runtime-env.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/platform-runtime-env.contracts.js +139 -2
- package/dist/esm/bootstrap/platform-runtime-env.contracts.js.map +1 -1
- package/dist/esm/bootstrap/platform-store-preconnect.d.ts +21 -0
- package/dist/esm/bootstrap/platform-store-preconnect.d.ts.map +1 -1
- package/dist/esm/bootstrap/platform-store-preconnect.js +25 -0
- package/dist/esm/bootstrap/platform-store-preconnect.js.map +1 -1
- package/dist/esm/bootstrap/postgresql-owed-grants.contracts.d.ts +80 -0
- package/dist/esm/bootstrap/postgresql-owed-grants.contracts.d.ts.map +1 -0
- package/dist/esm/bootstrap/postgresql-owed-grants.contracts.js +81 -0
- package/dist/esm/bootstrap/postgresql-owed-grants.contracts.js.map +1 -0
- package/dist/esm/bootstrap/runtime-backing-service-access.d.ts +41 -9
- package/dist/esm/bootstrap/runtime-backing-service-access.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-backing-service-access.js +77 -28
- package/dist/esm/bootstrap/runtime-backing-service-access.js.map +1 -1
- package/dist/esm/bootstrap/runtime-network-policy.d.ts +117 -12
- package/dist/esm/bootstrap/runtime-network-policy.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-network-policy.js +222 -23
- package/dist/esm/bootstrap/runtime-network-policy.js.map +1 -1
- package/dist/esm/bootstrap/runtime-network-topology.d.ts +31 -4
- package/dist/esm/bootstrap/runtime-network-topology.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-network-topology.js +43 -2
- package/dist/esm/bootstrap/runtime-network-topology.js.map +1 -1
- package/dist/esm/bootstrap/runtime-platform-access.js.map +1 -1
- package/dist/esm/bootstrap/runtime-principal.contracts.d.ts +40 -2
- package/dist/esm/bootstrap/runtime-principal.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-principal.contracts.js +66 -3
- package/dist/esm/bootstrap/runtime-principal.contracts.js.map +1 -1
- package/dist/esm/bootstrap/runtime-response-integrity.d.ts +249 -0
- package/dist/esm/bootstrap/runtime-response-integrity.d.ts.map +1 -0
- package/dist/esm/bootstrap/runtime-response-integrity.js +353 -0
- package/dist/esm/bootstrap/runtime-response-integrity.js.map +1 -0
- package/dist/esm/bootstrap/runtime-secret-env.contracts.d.ts +32 -0
- package/dist/esm/bootstrap/runtime-secret-env.contracts.d.ts.map +1 -0
- package/dist/esm/bootstrap/runtime-secret-env.contracts.js +43 -0
- package/dist/esm/bootstrap/runtime-secret-env.contracts.js.map +1 -0
- package/dist/esm/bootstrap/runtime-topology.contracts.js.map +1 -1
- package/dist/esm/bootstrap/wildo-owner-organization.contracts.js.map +1 -1
- package/dist/esm/canonical-json/rfc8785-canonical-json.d.ts +51 -0
- package/dist/esm/canonical-json/rfc8785-canonical-json.d.ts.map +1 -0
- package/dist/esm/canonical-json/rfc8785-canonical-json.js +231 -0
- package/dist/esm/canonical-json/rfc8785-canonical-json.js.map +1 -0
- package/dist/esm/config-authoring.entry.js.map +1 -1
- package/dist/esm/credentials/credential-generator.service.d.ts.map +1 -1
- package/dist/esm/credentials/credential-generator.service.js.map +1 -1
- package/dist/esm/index.d.ts +20 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +20 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/key-management/application-legacy-envelope-key.contracts.d.ts +119 -0
- package/dist/esm/key-management/application-legacy-envelope-key.contracts.d.ts.map +1 -0
- package/dist/esm/key-management/application-legacy-envelope-key.contracts.js +109 -0
- package/dist/esm/key-management/application-legacy-envelope-key.contracts.js.map +1 -0
- package/dist/esm/key-management/application-signing-key-rotation.contracts.d.ts +182 -0
- package/dist/esm/key-management/application-signing-key-rotation.contracts.d.ts.map +1 -0
- package/dist/esm/key-management/application-signing-key-rotation.contracts.js +145 -0
- package/dist/esm/key-management/application-signing-key-rotation.contracts.js.map +1 -0
- package/dist/esm/key-management/approval-seal-manifested-copy.d.ts +156 -0
- package/dist/esm/key-management/approval-seal-manifested-copy.d.ts.map +1 -0
- package/dist/esm/key-management/approval-seal-manifested-copy.js +617 -0
- package/dist/esm/key-management/approval-seal-manifested-copy.js.map +1 -0
- package/dist/esm/key-management/approval-seal-verifier.d.ts +278 -0
- package/dist/esm/key-management/approval-seal-verifier.d.ts.map +1 -0
- package/dist/esm/key-management/approval-seal-verifier.js +355 -0
- package/dist/esm/key-management/approval-seal-verifier.js.map +1 -0
- package/dist/esm/key-management/approval-seal.contracts.d.ts +128 -0
- package/dist/esm/key-management/approval-seal.contracts.d.ts.map +1 -0
- package/dist/esm/key-management/approval-seal.contracts.js +135 -0
- package/dist/esm/key-management/approval-seal.contracts.js.map +1 -0
- package/dist/esm/key-management/data-key.contracts.d.ts +106 -0
- package/dist/esm/key-management/data-key.contracts.d.ts.map +1 -0
- package/dist/esm/key-management/data-key.contracts.js +54 -0
- package/dist/esm/key-management/data-key.contracts.js.map +1 -0
- package/dist/esm/key-management/es256-jws.d.ts +60 -0
- package/dist/esm/key-management/es256-jws.d.ts.map +1 -0
- package/dist/esm/key-management/es256-jws.js +135 -0
- package/dist/esm/key-management/es256-jws.js.map +1 -0
- package/dist/esm/key-management/key-provider.spi.d.ts +158 -0
- package/dist/esm/key-management/key-provider.spi.d.ts.map +1 -0
- package/dist/esm/key-management/key-provider.spi.js +38 -0
- package/dist/esm/key-management/key-provider.spi.js.map +1 -0
- package/dist/esm/key-management/keyring-rotation.contracts.d.ts +83 -0
- package/dist/esm/key-management/keyring-rotation.contracts.d.ts.map +1 -0
- package/dist/esm/key-management/keyring-rotation.contracts.js +101 -0
- package/dist/esm/key-management/keyring-rotation.contracts.js.map +1 -0
- package/dist/esm/key-management/keyring-status.contracts.d.ts +59 -0
- package/dist/esm/key-management/keyring-status.contracts.d.ts.map +1 -0
- package/dist/esm/key-management/keyring-status.contracts.js +45 -0
- package/dist/esm/key-management/keyring-status.contracts.js.map +1 -0
- package/dist/esm/key-management/pdf-incremental-update.d.ts +158 -0
- package/dist/esm/key-management/pdf-incremental-update.d.ts.map +1 -0
- package/dist/esm/key-management/pdf-incremental-update.js +730 -0
- package/dist/esm/key-management/pdf-incremental-update.js.map +1 -0
- package/dist/esm/key-management/pdf-truetype-font.d.ts +35 -0
- package/dist/esm/key-management/pdf-truetype-font.d.ts.map +1 -0
- package/dist/esm/key-management/pdf-truetype-font.js +152 -0
- package/dist/esm/key-management/pdf-truetype-font.js.map +1 -0
- package/dist/esm/key-management/qr-code.d.ts +38 -0
- package/dist/esm/key-management/qr-code.d.ts.map +1 -0
- package/dist/esm/key-management/qr-code.js +325 -0
- package/dist/esm/key-management/qr-code.js.map +1 -0
- package/dist/esm/key-management/signature-request.contracts.d.ts +91 -0
- package/dist/esm/key-management/signature-request.contracts.d.ts.map +1 -0
- package/dist/esm/key-management/signature-request.contracts.js +96 -0
- package/dist/esm/key-management/signature-request.contracts.js.map +1 -0
- package/dist/esm/key-management/signing-log-export.contracts.d.ts +215 -0
- package/dist/esm/key-management/signing-log-export.contracts.d.ts.map +1 -0
- package/dist/esm/key-management/signing-log-export.contracts.js +268 -0
- package/dist/esm/key-management/signing-log-export.contracts.js.map +1 -0
- package/dist/esm/key-management/vault-custody.contracts.d.ts +98 -0
- package/dist/esm/key-management/vault-custody.contracts.d.ts.map +1 -0
- package/dist/esm/key-management/vault-custody.contracts.js +154 -0
- package/dist/esm/key-management/vault-custody.contracts.js.map +1 -0
- package/dist/esm/lockfile/build-parallelism.d.ts.map +1 -1
- package/dist/esm/lockfile/build-parallelism.js.map +1 -1
- package/dist/esm/lockfile/canonical-json.d.ts +1 -1
- package/dist/esm/lockfile/canonical-json.d.ts.map +1 -1
- package/dist/esm/lockfile/canonical-json.js +1 -1
- package/dist/esm/lockfile/canonical-json.js.map +1 -1
- package/dist/esm/lockfile/file-lock-hold.d.ts.map +1 -1
- package/dist/esm/lockfile/file-lock-hold.js +2 -1
- package/dist/esm/lockfile/file-lock-hold.js.map +1 -1
- package/dist/esm/lockfile/lockfile-io.d.ts +13 -17
- package/dist/esm/lockfile/lockfile-io.d.ts.map +1 -1
- package/dist/esm/lockfile/lockfile-io.js +29 -30
- package/dist/esm/lockfile/lockfile-io.js.map +1 -1
- package/dist/esm/lockfile/materialize-infra-section.d.ts +22 -20
- package/dist/esm/lockfile/materialize-infra-section.d.ts.map +1 -1
- package/dist/esm/lockfile/materialize-infra-section.js +13 -14
- package/dist/esm/lockfile/materialize-infra-section.js.map +1 -1
- package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.d.ts +27 -249
- package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.d.ts.map +1 -1
- package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.js +28 -3
- package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.js.map +1 -1
- package/dist/esm/pnpm-settings/application-pnpm-settings.d.ts +146 -0
- package/dist/esm/pnpm-settings/application-pnpm-settings.d.ts.map +1 -0
- package/dist/esm/pnpm-settings/application-pnpm-settings.js +573 -0
- package/dist/esm/pnpm-settings/application-pnpm-settings.js.map +1 -0
- package/dist/esm/project-config/application-public-pricing-catalog.loader.d.ts.map +1 -1
- package/dist/esm/project-config/application-public-pricing-catalog.loader.js +22 -3
- package/dist/esm/project-config/application-public-pricing-catalog.loader.js.map +1 -1
- package/dist/esm/project-config/application-served-public-documents.loader.d.ts +26 -0
- package/dist/esm/project-config/application-served-public-documents.loader.d.ts.map +1 -0
- package/dist/esm/project-config/application-served-public-documents.loader.js +86 -0
- package/dist/esm/project-config/application-served-public-documents.loader.js.map +1 -0
- package/dist/esm/project-config/backend-compliance-section.reader.d.ts +35 -0
- package/dist/esm/project-config/backend-compliance-section.reader.d.ts.map +1 -0
- package/dist/esm/project-config/backend-compliance-section.reader.js +123 -0
- package/dist/esm/project-config/backend-compliance-section.reader.js.map +1 -0
- package/dist/esm/project-config/backend-compliance-section.worker.d.ts +20 -0
- package/dist/esm/project-config/backend-compliance-section.worker.d.ts.map +1 -0
- package/dist/esm/project-config/backend-compliance-section.worker.js +78 -0
- package/dist/esm/project-config/backend-compliance-section.worker.js.map +1 -0
- package/dist/esm/project-config/config-module-resolution.d.ts +32 -0
- package/dist/esm/project-config/config-module-resolution.d.ts.map +1 -0
- package/dist/esm/project-config/config-module-resolution.js +33 -0
- package/dist/esm/project-config/config-module-resolution.js.map +1 -0
- package/dist/esm/project-config/define-framework-config.js.map +1 -1
- package/dist/esm/project-config/define-infra-env-config.d.ts +344 -69
- package/dist/esm/project-config/define-infra-env-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-infra-env-config.js +194 -143
- package/dist/esm/project-config/define-infra-env-config.js.map +1 -1
- package/dist/esm/project-config/define-minion-config.d.ts +26 -36
- package/dist/esm/project-config/define-minion-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-minion-config.js +64 -25
- package/dist/esm/project-config/define-minion-config.js.map +1 -1
- package/dist/esm/project-config/define-saas-config.d.ts +82 -348
- package/dist/esm/project-config/define-saas-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-saas-config.js +262 -103
- package/dist/esm/project-config/define-saas-config.js.map +1 -1
- package/dist/esm/project-config/define-worker-config.d.ts +10 -20
- package/dist/esm/project-config/define-worker-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-worker-config.js +10 -12
- package/dist/esm/project-config/define-worker-config.js.map +1 -1
- package/dist/esm/project-config/hosted-infra-env-config.d.ts.map +1 -1
- package/dist/esm/project-config/hosted-infra-env-config.js +4 -1
- package/dist/esm/project-config/hosted-infra-env-config.js.map +1 -1
- package/dist/esm/project-config/index.d.ts +5 -0
- package/dist/esm/project-config/index.d.ts.map +1 -1
- package/dist/esm/project-config/index.js +5 -0
- package/dist/esm/project-config/index.js.map +1 -1
- package/dist/esm/project-config/loader-instances-zod.d.ts +19 -0
- package/dist/esm/project-config/loader-instances-zod.d.ts.map +1 -0
- package/dist/esm/project-config/loader-instances-zod.js +40 -0
- package/dist/esm/project-config/loader-instances-zod.js.map +1 -0
- package/dist/esm/project-config/loader.d.ts +131 -14
- package/dist/esm/project-config/loader.d.ts.map +1 -1
- package/dist/esm/project-config/loader.js +226 -12
- package/dist/esm/project-config/loader.js.map +1 -1
- package/dist/esm/project-config/minion-liveness.contracts.d.ts +131 -0
- package/dist/esm/project-config/minion-liveness.contracts.d.ts.map +1 -0
- package/dist/esm/project-config/minion-liveness.contracts.js +167 -0
- package/dist/esm/project-config/minion-liveness.contracts.js.map +1 -0
- package/dist/esm/project-config/minion-local-provider-registration.d.ts.map +1 -1
- package/dist/esm/project-config/minion-local-provider-registration.js.map +1 -1
- package/dist/esm/project-config/npm-version-range.d.ts.map +1 -1
- package/dist/esm/project-config/npm-version-range.js +39 -16
- package/dist/esm/project-config/npm-version-range.js.map +1 -1
- package/dist/esm/project-config/owning-package-tsconfig.d.ts +15 -0
- package/dist/esm/project-config/owning-package-tsconfig.d.ts.map +1 -0
- package/dist/esm/project-config/owning-package-tsconfig.js +29 -0
- package/dist/esm/project-config/owning-package-tsconfig.js.map +1 -0
- package/dist/esm/project-config/provider-catalog-types.js.map +1 -1
- package/dist/esm/project-config/provider-companion-discovery.d.ts +4 -4
- package/dist/esm/project-config/provider-companion-discovery.d.ts.map +1 -1
- package/dist/esm/project-config/provider-companion-discovery.js +16 -10
- package/dist/esm/project-config/provider-companion-discovery.js.map +1 -1
- package/dist/esm/project-config/provider-runtime-artifacts.d.ts +103 -49
- package/dist/esm/project-config/provider-runtime-artifacts.d.ts.map +1 -1
- package/dist/esm/project-config/provider-runtime-artifacts.js +216 -16
- package/dist/esm/project-config/provider-runtime-artifacts.js.map +1 -1
- package/dist/esm/project-config/shared/application-creation-verification.schemas.d.ts +0 -2
- package/dist/esm/project-config/shared/application-creation-verification.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/application-creation-verification.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/application-modules.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/application-modules.utils.js.map +1 -1
- package/dist/esm/project-config/shared/auth.schemas.d.ts +0 -17
- package/dist/esm/project-config/shared/auth.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/auth.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/backing-service-servability.js.map +1 -1
- package/dist/esm/project-config/shared/backing-services.schemas.d.ts +9 -10
- package/dist/esm/project-config/shared/backing-services.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/backing-services.schemas.js +13 -15
- package/dist/esm/project-config/shared/backing-services.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/cdn.schemas.d.ts +0 -51
- package/dist/esm/project-config/shared/cdn.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/cdn.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/csp-defaults.d.ts +36 -9
- package/dist/esm/project-config/shared/csp-defaults.d.ts.map +1 -1
- package/dist/esm/project-config/shared/csp-defaults.js +54 -11
- package/dist/esm/project-config/shared/csp-defaults.js.map +1 -1
- package/dist/esm/project-config/shared/csp-emit.d.ts +60 -13
- package/dist/esm/project-config/shared/csp-emit.d.ts.map +1 -1
- package/dist/esm/project-config/shared/csp-emit.js +77 -24
- package/dist/esm/project-config/shared/csp-emit.js.map +1 -1
- package/dist/esm/project-config/shared/csp.schemas.d.ts +72 -85
- package/dist/esm/project-config/shared/csp.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/csp.schemas.js +40 -13
- package/dist/esm/project-config/shared/csp.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/data-services.schemas.d.ts +0 -8
- package/dist/esm/project-config/shared/data-services.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/data-services.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/env-example-defaults.d.ts.map +1 -1
- package/dist/esm/project-config/shared/env-example-defaults.js.map +1 -1
- package/dist/esm/project-config/shared/environment.schemas.d.ts +101 -8
- package/dist/esm/project-config/shared/environment.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/environment.schemas.js +128 -9
- package/dist/esm/project-config/shared/environment.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/infra-providers.schemas.d.ts +10 -4
- package/dist/esm/project-config/shared/infra-providers.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/infra-providers.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/infra-service.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/infrastructure-defaults.schemas.d.ts +2 -1
- package/dist/esm/project-config/shared/infrastructure-defaults.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/infrastructure-defaults.schemas.js +4 -1
- package/dist/esm/project-config/shared/infrastructure-defaults.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/k8s-utils.d.ts.map +1 -1
- package/dist/esm/project-config/shared/k8s-utils.js.map +1 -1
- package/dist/esm/project-config/shared/minion-platform-access.vocabulary.d.ts.map +1 -1
- package/dist/esm/project-config/shared/minion-platform-access.vocabulary.js.map +1 -1
- package/dist/esm/project-config/shared/minion-resource-access.validation.d.ts +24 -0
- package/dist/esm/project-config/shared/minion-resource-access.validation.d.ts.map +1 -1
- package/dist/esm/project-config/shared/minion-resource-access.validation.js +25 -2
- package/dist/esm/project-config/shared/minion-resource-access.validation.js.map +1 -1
- package/dist/esm/project-config/shared/object-storage-session-policy.d.ts.map +1 -1
- package/dist/esm/project-config/shared/object-storage-session-policy.js.map +1 -1
- package/dist/esm/project-config/shared/platform-key-management.schemas.d.ts +276 -0
- package/dist/esm/project-config/shared/platform-key-management.schemas.d.ts.map +1 -0
- package/dist/esm/project-config/shared/platform-key-management.schemas.js +296 -0
- package/dist/esm/project-config/shared/platform-key-management.schemas.js.map +1 -0
- package/dist/esm/project-config/shared/platform-services.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/platform-storage.schemas.d.ts +2 -2
- package/dist/esm/project-config/shared/platform-storage.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/platform-storage.schemas.js +16 -2
- package/dist/esm/project-config/shared/platform-storage.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/service-definitions.schemas.d.ts +21 -23
- package/dist/esm/project-config/shared/service-definitions.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/service-definitions.schemas.js +4 -5
- package/dist/esm/project-config/shared/service-definitions.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/systems-of-record-env.schemas.d.ts +0 -18
- package/dist/esm/project-config/shared/systems-of-record-env.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/systems-of-record-env.schemas.js.map +1 -1
- package/dist/esm/project-config/static-asset-import-noop.d.ts +20 -3
- package/dist/esm/project-config/static-asset-import-noop.d.ts.map +1 -1
- package/dist/esm/project-config/static-asset-import-noop.js +36 -20
- package/dist/esm/project-config/static-asset-import-noop.js.map +1 -1
- package/dist/esm/registry/artifact-domain.schemas.d.ts +0 -5
- package/dist/esm/registry/artifact-domain.schemas.d.ts.map +1 -1
- package/dist/esm/registry/artifact-domain.schemas.js.map +1 -1
- package/dist/esm/registry/digest.schemas.js.map +1 -1
- package/dist/esm/registry/index.d.ts +3 -3
- package/dist/esm/registry/index.d.ts.map +1 -1
- package/dist/esm/registry/index.js +3 -3
- package/dist/esm/registry/index.js.map +1 -1
- package/dist/esm/registry/local-checkout-source.d.ts +22 -2
- package/dist/esm/registry/local-checkout-source.d.ts.map +1 -1
- package/dist/esm/registry/local-checkout-source.js +66 -3
- package/dist/esm/registry/local-checkout-source.js.map +1 -1
- package/dist/esm/registry/lockfile-modules-section.schemas.d.ts +11 -98
- package/dist/esm/registry/lockfile-modules-section.schemas.d.ts.map +1 -1
- package/dist/esm/registry/lockfile-modules-section.schemas.js +1 -2
- package/dist/esm/registry/lockfile-modules-section.schemas.js.map +1 -1
- package/dist/esm/registry/module-artifact.schemas.d.ts +40 -17
- package/dist/esm/registry/module-artifact.schemas.d.ts.map +1 -1
- package/dist/esm/registry/module-artifact.schemas.js.map +1 -1
- package/dist/esm/registry/module-manifest.schemas.d.ts +324 -74
- package/dist/esm/registry/module-manifest.schemas.d.ts.map +1 -1
- package/dist/esm/registry/module-manifest.schemas.js +377 -19
- package/dist/esm/registry/module-manifest.schemas.js.map +1 -1
- package/dist/esm/registry/module-search.schemas.d.ts +2 -0
- package/dist/esm/registry/module-search.schemas.d.ts.map +1 -1
- package/dist/esm/registry/module-search.schemas.js +14 -1
- package/dist/esm/registry/module-search.schemas.js.map +1 -1
- package/dist/esm/registry/registry-config.schemas.d.ts +0 -18
- package/dist/esm/registry/registry-config.schemas.d.ts.map +1 -1
- package/dist/esm/registry/registry-config.schemas.js.map +1 -1
- package/dist/esm/registry/registry-defaults.constants.d.ts.map +1 -1
- package/dist/esm/registry/registry-defaults.constants.js.map +1 -1
- package/dist/esm/registry/registry-errors.d.ts +103 -5
- package/dist/esm/registry/registry-errors.d.ts.map +1 -1
- package/dist/esm/registry/registry-errors.js +213 -6
- package/dist/esm/registry/registry-errors.js.map +1 -1
- package/dist/esm/registry/registry-keys.schemas.js.map +1 -1
- package/dist/esm/registry/registry-section-schemas.constants.d.ts +5 -0
- package/dist/esm/registry/registry-section-schemas.constants.d.ts.map +1 -1
- package/dist/esm/registry/registry-section-schemas.constants.js.map +1 -1
- package/dist/esm/registry/registry-url-resolution.d.ts +72 -0
- package/dist/esm/registry/registry-url-resolution.d.ts.map +1 -0
- package/dist/esm/registry/registry-url-resolution.js +157 -0
- package/dist/esm/registry/registry-url-resolution.js.map +1 -0
- package/dist/esm/release/framework-release.constants.d.ts.map +1 -1
- package/dist/esm/release/framework-release.constants.js.map +1 -1
- package/dist/esm/schemas/framework-info.schemas.js.map +1 -1
- package/dist/esm/schemas/framework-secrets.schemas.d.ts +48 -0
- package/dist/esm/schemas/framework-secrets.schemas.d.ts.map +1 -1
- package/dist/esm/schemas/framework-secrets.schemas.js +53 -0
- package/dist/esm/schemas/framework-secrets.schemas.js.map +1 -1
- package/dist/esm/schemas/platform-application-config.schemas.d.ts +1 -1
- package/dist/esm/schemas/platform-application-config.schemas.js.map +1 -1
- package/dist/esm/schemas/platform-application-secrets.schemas.d.ts +1 -1
- package/dist/esm/schemas/platform-application-secrets.schemas.js.map +1 -1
- package/dist/esm/schemas/platform-config.schemas.d.ts +2 -2
- package/dist/esm/schemas/platform-config.schemas.js.map +1 -1
- package/dist/esm/workspace-scope/application-subject-manifest.js.map +1 -1
- package/dist/esm/workspace-scope/index.js.map +1 -1
- package/dist/esm/workspace-scope/resolve-homes.d.ts.map +1 -1
- package/dist/esm/workspace-scope/resolve-homes.js.map +1 -1
- package/dist/esm/workspace-scope/workspace-homes.schemas.d.ts.map +1 -1
- package/dist/esm/workspace-scope/workspace-homes.schemas.js.map +1 -1
- package/dist/esm/workspace-scope/workspace-scope-detector.d.ts.map +1 -1
- package/dist/esm/workspace-scope/workspace-scope-detector.js.map +1 -1
- package/dist/esm/workspace-scope/workspace-scope.schemas.d.ts.map +1 -1
- package/dist/esm/workspace-scope/workspace-scope.schemas.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +12 -12
- package/dist/esm/_unimplemented/index.d.ts +0 -3
- package/dist/esm/_unimplemented/index.d.ts.map +0 -1
- package/dist/esm/_unimplemented/index.js +0 -3
- package/dist/esm/_unimplemented/index.js.map +0 -1
- package/dist/esm/_unimplemented/unimplemented-field-warning.d.ts +0 -137
- package/dist/esm/_unimplemented/unimplemented-field-warning.d.ts.map +0 -1
- package/dist/esm/_unimplemented/unimplemented-field-warning.js +0 -153
- package/dist/esm/_unimplemented/unimplemented-field-warning.js.map +0 -1
- package/dist/esm/project-config/shared/cdn.example.d.ts +0 -14
- package/dist/esm/project-config/shared/cdn.example.d.ts.map +0 -1
- package/dist/esm/project-config/shared/cdn.example.js +0 -38
- package/dist/esm/project-config/shared/cdn.example.js.map +0 -1
- package/dist/esm/project-config/shared/schema-version.schemas.d.ts +0 -15
- package/dist/esm/project-config/shared/schema-version.schemas.d.ts.map +0 -1
- package/dist/esm/project-config/shared/schema-version.schemas.js +0 -40
- package/dist/esm/project-config/shared/schema-version.schemas.js.map +0 -1
|
@@ -0,0 +1,135 @@
|
|
|
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
|
+
/**
|
|
53
|
+
* When the step-up factor was proven, epoch seconds (#2923): beside `stepUpMethod`, it shows which factor answered and
|
|
54
|
+
* how long before `decidedAt`, which is what a decision requiring a fresh factor (`stepUp.maximumAgeSeconds`) asked.
|
|
55
|
+
*/
|
|
56
|
+
stepUpAt: z.number().int().nonnegative().optional(),
|
|
57
|
+
/**
|
|
58
|
+
* For a passkey step-up, whether the authenticator verified the person (the assertion's UV flag, #2923). The assertion
|
|
59
|
+
* itself, which names the credential, is in the salted approver disclosure, never here.
|
|
60
|
+
*/
|
|
61
|
+
stepUpUserVerified: z.boolean().optional(),
|
|
62
|
+
/** For a chat answer: the inbound source it arrived through (`slack:interactions`). Names a channel, not a person. */
|
|
63
|
+
inboundSourceKey: z.string().min(1).optional(),
|
|
64
|
+
});
|
|
65
|
+
/** Who asked. A machine is named by kind only; a person by their disclosure. */
|
|
66
|
+
export const ApprovalSealRequesterClaimsSchema = z.strictObject({
|
|
67
|
+
kind: z.enum(HumanDecision_RequesterKind),
|
|
68
|
+
clientId: z.string().min(1).optional(),
|
|
69
|
+
/** The digest of the requester's disclosure, when the requester is a person. */
|
|
70
|
+
disclosure: DigestSchema.optional(),
|
|
71
|
+
});
|
|
72
|
+
/** The approval seal's claims, version 1: everything but what the custodian sets (`iss`, `iat`, `kid`, `typ`, `lateSeal`). */
|
|
73
|
+
export const ApprovalSealClaimsV1Schema = z.strictObject({
|
|
74
|
+
v: z.literal(APPROVAL_SEAL_CLAIMS_VERSION),
|
|
75
|
+
/** Minted at commit: at least 128 bits, base64url. With `iss` the seal's id. */
|
|
76
|
+
jti: z.string().regex(/^[A-Za-z0-9_-]{22,}$/),
|
|
77
|
+
source: z.enum(ApprovalSource),
|
|
78
|
+
decisionRef: z.string().min(1),
|
|
79
|
+
step: z.number().int().min(0),
|
|
80
|
+
sequence: z.number().int().min(1),
|
|
81
|
+
/** The jti of the seal this one supersedes. */
|
|
82
|
+
supersedes: z.string().min(1).optional(),
|
|
83
|
+
/** The organization the decision belongs to, or the application's id when it belongs to none. */
|
|
84
|
+
tenant: z.string().min(1),
|
|
85
|
+
subject: z.strictObject({
|
|
86
|
+
resourceType: z.string().min(1),
|
|
87
|
+
resourceId: z.string().min(1),
|
|
88
|
+
presentationSchemaVersion: z.number().int().min(1).optional(),
|
|
89
|
+
}),
|
|
90
|
+
/** What was presented, when the engine built it (#2903 S6): its id, how its rendering is known, its salted digest. */
|
|
91
|
+
presentation: z.strictObject({
|
|
92
|
+
/** The id the act echoed, or the one the engine derived for what it sent. Absent when the application held no key. */
|
|
93
|
+
id: z.string().min(1).optional(),
|
|
94
|
+
provenance: z.enum(ApprovalPresentationProvenance),
|
|
95
|
+
digest: DigestSchema,
|
|
96
|
+
}).optional(),
|
|
97
|
+
/** The digest of the approver's statement (the `statement` disclosure): what they answered. */
|
|
98
|
+
statementDigest: DigestSchema.optional(),
|
|
99
|
+
meaning: z.enum(ApprovalSealMeaning),
|
|
100
|
+
/** Only an outcome a person decided (`APPROVAL_SEAL_OUTCOMES`). */
|
|
101
|
+
outcome: z.enum(APPROVAL_SEAL_OUTCOMES),
|
|
102
|
+
/** When the person decided, epoch seconds: distinct from `iat`, when the custodian signed. */
|
|
103
|
+
decidedAt: z.number().int().positive(),
|
|
104
|
+
decider: ApprovalSealDeciderClaimsSchema,
|
|
105
|
+
requester: ApprovalSealRequesterClaimsSchema.optional(),
|
|
106
|
+
/** The digest of the approver's disclosure. */
|
|
107
|
+
approver: DigestSchema,
|
|
108
|
+
});
|
|
109
|
+
/** A fresh disclosure salt: 128 bits from the CSPRNG, base64url. Never reused. */
|
|
110
|
+
export function newApprovalSealDisclosureSalt() {
|
|
111
|
+
return randomBytes(16).toString('base64url');
|
|
112
|
+
}
|
|
113
|
+
/** The disclosure's encoded form: base64url of the RFC 8785 canonical JSON array `[salt, claimName, value]`. */
|
|
114
|
+
export function encodeApprovalSealDisclosure(disclosure) {
|
|
115
|
+
return base64url(canonicalizeJson([disclosure.salt, disclosure.claimName, disclosure.value]));
|
|
116
|
+
}
|
|
117
|
+
/** The commitment a payload carries for a disclosure: base64url SHA-256 of its encoded form. */
|
|
118
|
+
export function approvalSealDisclosureDigestOf(disclosure) {
|
|
119
|
+
return base64url(createHash('sha256').update(encodeApprovalSealDisclosure(disclosure), 'ascii').digest());
|
|
120
|
+
}
|
|
121
|
+
/** A new seal id: 128 bits, base64url. */
|
|
122
|
+
export function newApprovalSealJti() {
|
|
123
|
+
return randomBytes(16).toString('base64url');
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The commitment a seal binds a FILE deliverable by (#2904, the form #2903's design names): base64url SHA-256 of the ASCII
|
|
127
|
+
* string `salt + contentSha256`, the salt base64url and the hash the file's lowercase hex SHA-256. The presentation carries
|
|
128
|
+
* the commitment and the seal's row the salt, so the clear hash stays in the file's metadata: a JWS, or a presentation,
|
|
129
|
+
* shared without the salt cannot be used to confirm a guessed document. Given the file's bytes and the salt, anyone can
|
|
130
|
+
* recompute it, and one changed byte changes it.
|
|
131
|
+
*/
|
|
132
|
+
export function approvalSealFileCommitmentOf(salt, contentSha256) {
|
|
133
|
+
return base64url(createHash('sha256').update(`${salt}${contentSha256}`, 'ascii').digest());
|
|
134
|
+
}
|
|
135
|
+
//# 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,sDAAu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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;AAED;;;;;;GAMG;AACH,MAAM,UAAU,4BAA4B,CAAC,IAAY,EAAE,aAAqB;IAC9E,OAAO,SAAS,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,aAAa,EAAE,EAAE,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;AAC7F,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 /**\n * When the step-up factor was proven, epoch seconds (#2923): beside `stepUpMethod`, it shows which factor answered and\n * how long before `decidedAt`, which is what a decision requiring a fresh factor (`stepUp.maximumAgeSeconds`) asked.\n */\n stepUpAt: z.number().int().nonnegative().optional(),\n /**\n * For a passkey step-up, whether the authenticator verified the person (the assertion's UV flag, #2923). The assertion\n * itself, which names the credential, is in the salted approver disclosure, never here.\n */\n stepUpUserVerified: z.boolean().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\n/**\n * The commitment a seal binds a FILE deliverable by (#2904, the form #2903's design names): base64url SHA-256 of the ASCII\n * string `salt + contentSha256`, the salt base64url and the hash the file's lowercase hex SHA-256. The presentation carries\n * the commitment and the seal's row the salt, so the clear hash stays in the file's metadata: a JWS, or a presentation,\n * shared without the salt cannot be used to confirm a guessed document. Given the file's bytes and the salt, anyone can\n * recompute it, and one changed byte changes it.\n */\nexport function approvalSealFileCommitmentOf(salt: string, contentSha256: string): string {\n return base64url(createHash('sha256').update(`${salt}${contentSha256}`, 'ascii').digest());\n}\n"]}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { CryptoKey_Purpose, CryptoKey_Scope, type CryptoKey_VersionState } from '@wildo-ai/saas-models';
|
|
3
|
+
/**
|
|
4
|
+
* # Data keys: what the application and the custodian exchange (#2894)
|
|
5
|
+
*
|
|
6
|
+
* The application seals its stored secrets under DATA keys, and a data key is only ever stored WRAPPED by its purpose's
|
|
7
|
+
* wrapping key, which never leaves the custodian (apps-manager). Five requests, all on the signed apps-to-manager channel:
|
|
8
|
+
*
|
|
9
|
+
* - **issue** a new data key: the custodian mints it, wraps it under the ACTIVE wrapping version, and answers with both
|
|
10
|
+
* halves (the application stores the wrapped one and holds the plaintext in memory only);
|
|
11
|
+
* - **unwrap** a stored data key, at boot or when a process first needs it;
|
|
12
|
+
* - **rewrap** a data key under the ACTIVE version after a rotation, without its plaintext leaving the custodian;
|
|
13
|
+
* - **release** a retired wrapping version once no stored data key is wrapped under it, so it can be destroyed;
|
|
14
|
+
* - **read the wrapping versions** and their states, from which the application derives, at every refresh, what it
|
|
15
|
+
* re-wraps, which data key stops sealing (one a COMPROMISED version wrapped), and which version it releases.
|
|
16
|
+
*
|
|
17
|
+
* The custodian builds the associated data of every wrap itself ({@link dataKeyAssociatedDataOf}): the purpose, the
|
|
18
|
+
* scope, the scope's id and the data key's id, so a wrapped key copied to another data key, organization or application
|
|
19
|
+
* does not unwrap. Both sides import this module.
|
|
20
|
+
*/
|
|
21
|
+
/** The associated data a data key is wrapped under. */
|
|
22
|
+
export declare function dataKeyAssociatedDataOf(input: {
|
|
23
|
+
readonly purpose: CryptoKey_Purpose;
|
|
24
|
+
readonly scope: CryptoKey_Scope;
|
|
25
|
+
readonly scopeId: string;
|
|
26
|
+
readonly dataKeyId: string;
|
|
27
|
+
}): Buffer;
|
|
28
|
+
export declare const DataKeyIssueRequestSchema: z.ZodObject<{
|
|
29
|
+
purpose: z.ZodEnum<typeof CryptoKey_Purpose>;
|
|
30
|
+
organizationId: z.ZodOptional<z.ZodString>;
|
|
31
|
+
}, z.core.$strict>;
|
|
32
|
+
export type DataKeyIssueRequest = z.infer<typeof DataKeyIssueRequestSchema>;
|
|
33
|
+
export declare const DataKeyUnwrapRequestSchema: z.ZodObject<{
|
|
34
|
+
purpose: z.ZodEnum<typeof CryptoKey_Purpose>;
|
|
35
|
+
organizationId: z.ZodOptional<z.ZodString>;
|
|
36
|
+
kid: z.ZodString;
|
|
37
|
+
dataKeyId: z.ZodString;
|
|
38
|
+
wrapped: z.ZodString;
|
|
39
|
+
}, z.core.$strict>;
|
|
40
|
+
export type DataKeyUnwrapRequest = z.infer<typeof DataKeyUnwrapRequestSchema>;
|
|
41
|
+
export declare const DataKeyRewrapRequestSchema: z.ZodObject<{
|
|
42
|
+
purpose: z.ZodEnum<typeof CryptoKey_Purpose>;
|
|
43
|
+
organizationId: z.ZodOptional<z.ZodString>;
|
|
44
|
+
kid: z.ZodString;
|
|
45
|
+
dataKeyId: z.ZodString;
|
|
46
|
+
wrapped: z.ZodString;
|
|
47
|
+
}, z.core.$strict>;
|
|
48
|
+
export type DataKeyRewrapRequest = z.infer<typeof DataKeyRewrapRequestSchema>;
|
|
49
|
+
/**
|
|
50
|
+
* The header by which a rewrap declares that the application recorded the data key's exposure before asking (#3029),
|
|
51
|
+
* with the value {@link DATA_KEY_EXPOSURE_RECORDED}. The custodian refuses a rewrap off a COMPROMISED version without it
|
|
52
|
+
* (`exposure_unrecorded`): once the row is re-wrapped it no longer names the compromised version, and only the mark tells
|
|
53
|
+
* the application that the values sealed under that data key must be sealed again. A runtime from before #3029 records
|
|
54
|
+
* no mark and sends no header, so it is refused and the row waits for a current runtime to mark and move it.
|
|
55
|
+
*
|
|
56
|
+
* A header rather than a body field, decided: the request body is a strict object, so a custodian from before #3029
|
|
57
|
+
* would refuse an unknown field as `request_invalid`, which an application reads as "this runtime is refused" and stops
|
|
58
|
+
* sealing on. A custodian from before #3029 ignores the header, and the application marks its rows either way.
|
|
59
|
+
*/
|
|
60
|
+
export declare const DATA_KEY_EXPOSURE_RECORDED_HEADER = "x-wildo-data-key-exposure-recorded";
|
|
61
|
+
export declare const DATA_KEY_EXPOSURE_RECORDED = "recorded";
|
|
62
|
+
export declare const DataKeyReleaseRequestSchema: z.ZodObject<{
|
|
63
|
+
purpose: z.ZodEnum<typeof CryptoKey_Purpose>;
|
|
64
|
+
organizationId: z.ZodOptional<z.ZodString>;
|
|
65
|
+
kid: z.ZodString;
|
|
66
|
+
}, z.core.$strict>;
|
|
67
|
+
export type DataKeyReleaseRequest = z.infer<typeof DataKeyReleaseRequestSchema>;
|
|
68
|
+
export declare const DataKeyWrappingVersionsRequestSchema: z.ZodObject<{
|
|
69
|
+
purpose: z.ZodEnum<typeof CryptoKey_Purpose>;
|
|
70
|
+
organizationId: z.ZodOptional<z.ZodString>;
|
|
71
|
+
}, z.core.$strict>;
|
|
72
|
+
export type DataKeyWrappingVersionsRequest = z.infer<typeof DataKeyWrappingVersionsRequestSchema>;
|
|
73
|
+
/** Where a data key belongs: the keyring scope the custodian resolved for the request. */
|
|
74
|
+
export interface DataKeyScope {
|
|
75
|
+
readonly scope: CryptoKey_Scope;
|
|
76
|
+
readonly scopeId: string;
|
|
77
|
+
}
|
|
78
|
+
/** A new data key: its id, its wrapping version, both halves (base64url), and the scope it was wrapped for. */
|
|
79
|
+
export interface DataKeyIssueResponse extends DataKeyScope {
|
|
80
|
+
readonly dataKeyId: string;
|
|
81
|
+
readonly kid: string;
|
|
82
|
+
readonly dataKey: string;
|
|
83
|
+
readonly wrapped: string;
|
|
84
|
+
}
|
|
85
|
+
export interface DataKeyUnwrapResponse {
|
|
86
|
+
readonly dataKey: string;
|
|
87
|
+
}
|
|
88
|
+
/** One wrapping version of the keyring, as the application needs it: its `kid`, its state, and whether it was released. */
|
|
89
|
+
export interface DataKeyWrappingVersion {
|
|
90
|
+
readonly kid: string;
|
|
91
|
+
readonly state: CryptoKey_VersionState;
|
|
92
|
+
readonly released: boolean;
|
|
93
|
+
}
|
|
94
|
+
/** Every wrapping version of the keyring that serves the request (none before its first data key). */
|
|
95
|
+
export interface DataKeyWrappingVersionsResponse {
|
|
96
|
+
readonly versions: readonly DataKeyWrappingVersion[];
|
|
97
|
+
}
|
|
98
|
+
export interface DataKeyRewrapResponse {
|
|
99
|
+
readonly kid: string;
|
|
100
|
+
readonly wrapped: string;
|
|
101
|
+
}
|
|
102
|
+
export interface DataKeyReleaseResponse {
|
|
103
|
+
readonly kid: string;
|
|
104
|
+
readonly releasedAt: string;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=data-key.contracts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-key.contracts.d.ts","sourceRoot":"","sources":["../../../src/key-management/data-key.contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,KAAK,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAExG;;;;;;;;;;;;;;;;;GAiBG;AAEH,uDAAuD;AACvD,wBAAgB,uBAAuB,CAAC,KAAK,EAAE;IAAE,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAErL;AAWD,eAAO,MAAM,yBAAyB;;;kBAA4B,CAAC;AACnE,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAE5E,eAAO,MAAM,0BAA0B;;;;;;kBAIrC,CAAC;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAE9E,eAAO,MAAM,0BAA0B;;;;;;kBAA6B,CAAC;AACrE,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAE9E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iCAAiC,uCAAuC,CAAC;AACtF,eAAO,MAAM,0BAA0B,aAAa,CAAC;AAErD,eAAO,MAAM,2BAA2B;;;;kBAA+D,CAAC;AACxG,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEhF,eAA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and the custodian exchange (#2894)
|
|
5
|
+
*
|
|
6
|
+
* The application seals its stored secrets under DATA keys, and a data key is only ever stored WRAPPED by its purpose's
|
|
7
|
+
* wrapping key, which never leaves the custodian (apps-manager). Five requests, all on the signed apps-to-manager channel:
|
|
8
|
+
*
|
|
9
|
+
* - **issue** a new data key: the custodian mints it, wraps it under the ACTIVE wrapping version, and answers with both
|
|
10
|
+
* halves (the application stores the wrapped one and holds the plaintext in memory only);
|
|
11
|
+
* - **unwrap** a stored data key, at boot or when a process first needs it;
|
|
12
|
+
* - **rewrap** a data key under the ACTIVE version after a rotation, without its plaintext leaving the custodian;
|
|
13
|
+
* - **release** a retired wrapping version once no stored data key is wrapped under it, so it can be destroyed;
|
|
14
|
+
* - **read the wrapping versions** and their states, from which the application derives, at every refresh, what it
|
|
15
|
+
* re-wraps, which data key stops sealing (one a COMPROMISED version wrapped), and which version it releases.
|
|
16
|
+
*
|
|
17
|
+
* The custodian builds the associated data of every wrap itself ({@link dataKeyAssociatedDataOf}): the purpose, the
|
|
18
|
+
* scope, the scope's id and the data key's id, so a wrapped key copied to another data key, organization or application
|
|
19
|
+
* does not unwrap. Both sides import this module.
|
|
20
|
+
*/
|
|
21
|
+
/** The associated data a data key is wrapped under. */
|
|
22
|
+
export function dataKeyAssociatedDataOf(input) {
|
|
23
|
+
return Buffer.from(`wildo-data-key:v1|${input.purpose}|${input.scope}|${input.scopeId}|${input.dataKeyId}`, 'utf8');
|
|
24
|
+
}
|
|
25
|
+
const base64urlString = z.string().regex(/^[A-Za-z0-9_-]+$/);
|
|
26
|
+
/** Which keyring: the purpose, and the organization when the purpose's binding is organization-scoped. */
|
|
27
|
+
const DataKeyScopeRequestSchema = z.strictObject({
|
|
28
|
+
purpose: z.enum(CryptoKey_Purpose),
|
|
29
|
+
/** The organization whose key serves the request, when the binding is organization-scoped; ignored otherwise. */
|
|
30
|
+
organizationId: z.string().min(1).optional(),
|
|
31
|
+
});
|
|
32
|
+
export const DataKeyIssueRequestSchema = DataKeyScopeRequestSchema;
|
|
33
|
+
export const DataKeyUnwrapRequestSchema = DataKeyScopeRequestSchema.extend({
|
|
34
|
+
kid: z.string().min(1),
|
|
35
|
+
dataKeyId: z.string().min(1),
|
|
36
|
+
wrapped: base64urlString,
|
|
37
|
+
});
|
|
38
|
+
export const DataKeyRewrapRequestSchema = DataKeyUnwrapRequestSchema;
|
|
39
|
+
/**
|
|
40
|
+
* The header by which a rewrap declares that the application recorded the data key's exposure before asking (#3029),
|
|
41
|
+
* with the value {@link DATA_KEY_EXPOSURE_RECORDED}. The custodian refuses a rewrap off a COMPROMISED version without it
|
|
42
|
+
* (`exposure_unrecorded`): once the row is re-wrapped it no longer names the compromised version, and only the mark tells
|
|
43
|
+
* the application that the values sealed under that data key must be sealed again. A runtime from before #3029 records
|
|
44
|
+
* no mark and sends no header, so it is refused and the row waits for a current runtime to mark and move it.
|
|
45
|
+
*
|
|
46
|
+
* A header rather than a body field, decided: the request body is a strict object, so a custodian from before #3029
|
|
47
|
+
* would refuse an unknown field as `request_invalid`, which an application reads as "this runtime is refused" and stops
|
|
48
|
+
* sealing on. A custodian from before #3029 ignores the header, and the application marks its rows either way.
|
|
49
|
+
*/
|
|
50
|
+
export const DATA_KEY_EXPOSURE_RECORDED_HEADER = 'x-wildo-data-key-exposure-recorded';
|
|
51
|
+
export const DATA_KEY_EXPOSURE_RECORDED = 'recorded';
|
|
52
|
+
export const DataKeyReleaseRequestSchema = DataKeyScopeRequestSchema.extend({ kid: z.string().min(1) });
|
|
53
|
+
export const DataKeyWrappingVersionsRequestSchema = DataKeyScopeRequestSchema;
|
|
54
|
+
//# sourceMappingURL=data-key.contracts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-key.contracts.js","sourceRoot":"","sources":["../../../src/key-management/data-key.contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAgD,MAAM,uB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AC,EAAE,CAAC,CAAC;AAGxG,MAAM,CAAC,MAAM,oCAAoC,GAAG,yBAAyB,CAAC","sourcesContent":["import { z } from 'zod';\nimport { CryptoKey_Purpose, CryptoKey_Scope, type CryptoKey_VersionState } from '@wildo-ai/saas-models';\n\n/**\n * # Data keys: what the application and the custodian exchange (#2894)\n *\n * The application seals its stored secrets under DATA keys, and a data key is only ever stored WRAPPED by its purpose's\n * wrapping key, which never leaves the custodian (apps-manager). Five requests, all on the signed apps-to-manager channel:\n *\n * - **issue** a new data key: the custodian mints it, wraps it under the ACTIVE wrapping version, and answers with both\n * halves (the application stores the wrapped one and holds the plaintext in memory only);\n * - **unwrap** a stored data key, at boot or when a process first needs it;\n * - **rewrap** a data key under the ACTIVE version after a rotation, without its plaintext leaving the custodian;\n * - **release** a retired wrapping version once no stored data key is wrapped under it, so it can be destroyed;\n * - **read the wrapping versions** and their states, from which the application derives, at every refresh, what it\n * re-wraps, which data key stops sealing (one a COMPROMISED version wrapped), and which version it releases.\n *\n * The custodian builds the associated data of every wrap itself ({@link dataKeyAssociatedDataOf}): the purpose, the\n * scope, the scope's id and the data key's id, so a wrapped key copied to another data key, organization or application\n * does not unwrap. Both sides import this module.\n */\n\n/** The associated data a data key is wrapped under. */\nexport function dataKeyAssociatedDataOf(input: { readonly purpose: CryptoKey_Purpose; readonly scope: CryptoKey_Scope; readonly scopeId: string; readonly dataKeyId: string }): Buffer {\n return Buffer.from(`wildo-data-key:v1|${input.purpose}|${input.scope}|${input.scopeId}|${input.dataKeyId}`, 'utf8');\n}\n\nconst base64urlString = z.string().regex(/^[A-Za-z0-9_-]+$/);\n\n/** Which keyring: the purpose, and the organization when the purpose's binding is organization-scoped. */\nconst DataKeyScopeRequestSchema = z.strictObject({\n purpose: z.enum(CryptoKey_Purpose),\n /** The organization whose key serves the request, when the binding is organization-scoped; ignored otherwise. */\n organizationId: z.string().min(1).optional(),\n});\n\nexport const DataKeyIssueRequestSchema = DataKeyScopeRequestSchema;\nexport type DataKeyIssueRequest = z.infer<typeof DataKeyIssueRequestSchema>;\n\nexport const DataKeyUnwrapRequestSchema = DataKeyScopeRequestSchema.extend({\n kid: z.string().min(1),\n dataKeyId: z.string().min(1),\n wrapped: base64urlString,\n});\nexport type DataKeyUnwrapRequest = z.infer<typeof DataKeyUnwrapRequestSchema>;\n\nexport const DataKeyRewrapRequestSchema = DataKeyUnwrapRequestSchema;\nexport type DataKeyRewrapRequest = z.infer<typeof DataKeyRewrapRequestSchema>;\n\n/**\n * The header by which a rewrap declares that the application recorded the data key's exposure before asking (#3029),\n * with the value {@link DATA_KEY_EXPOSURE_RECORDED}. The custodian refuses a rewrap off a COMPROMISED version without it\n * (`exposure_unrecorded`): once the row is re-wrapped it no longer names the compromised version, and only the mark tells\n * the application that the values sealed under that data key must be sealed again. A runtime from before #3029 records\n * no mark and sends no header, so it is refused and the row waits for a current runtime to mark and move it.\n *\n * A header rather than a body field, decided: the request body is a strict object, so a custodian from before #3029\n * would refuse an unknown field as `request_invalid`, which an application reads as \"this runtime is refused\" and stops\n * sealing on. A custodian from before #3029 ignores the header, and the application marks its rows either way.\n */\nexport const DATA_KEY_EXPOSURE_RECORDED_HEADER = 'x-wildo-data-key-exposure-recorded';\nexport const DATA_KEY_EXPOSURE_RECORDED = 'recorded';\n\nexport const DataKeyReleaseRequestSchema = DataKeyScopeRequestSchema.extend({ kid: z.string().min(1) });\nexport type DataKeyReleaseRequest = z.infer<typeof DataKeyReleaseRequestSchema>;\n\nexport const DataKeyWrappingVersionsRequestSchema = DataKeyScopeRequestSchema;\nexport type DataKeyWrappingVersionsRequest = z.infer<typeof DataKeyWrappingVersionsRequestSchema>;\n\n/** Where a data key belongs: the keyring scope the custodian resolved for the request. */\nexport interface DataKeyScope {\n readonly scope: CryptoKey_Scope;\n readonly scopeId: string;\n}\n\n/** A new data key: its id, its wrapping version, both halves (base64url), and the scope it was wrapped for. */\nexport interface DataKeyIssueResponse extends DataKeyScope {\n readonly dataKeyId: string;\n readonly kid: string;\n readonly dataKey: string;\n readonly wrapped: string;\n}\n\nexport interface DataKeyUnwrapResponse {\n readonly dataKey: string;\n}\n\n/** One wrapping version of the keyring, as the application needs it: its `kid`, its state, and whether it was released. */\nexport interface DataKeyWrappingVersion {\n readonly kid: string;\n readonly state: CryptoKey_VersionState;\n readonly released: boolean;\n}\n\n/** Every wrapping version of the keyring that serves the request (none before its first data key). */\nexport interface DataKeyWrappingVersionsResponse {\n readonly versions: readonly DataKeyWrappingVersion[];\n}\n\nexport interface DataKeyRewrapResponse {\n readonly kid: string;\n readonly wrapped: string;\n}\n\nexport interface DataKeyReleaseResponse {\n readonly kid: string;\n readonly releasedAt: string;\n}\n"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type KeyObject } from 'node:crypto';
|
|
2
|
+
/**
|
|
3
|
+
* The ES256 / JWS primitives every signer and verifier in the platform shares (#2891): the platform's answers to its
|
|
4
|
+
* runtimes (#2921), the keyring's signatures and the approval seal's verifier (#2903). One implementation, in a
|
|
5
|
+
* package with no JOSE dependency, so the offline verifier and every runtime read signatures the same way.
|
|
6
|
+
*
|
|
7
|
+
* spec-cite: RFC 7515 §5.1 (the JWS signing input), RFC 7518 §3.4 (ES256: ECDSA P-256 SHA-256, signature as the
|
|
8
|
+
* 64-byte concatenation R ‖ S, each left-padded to 32 bytes), RFC 7638 §3 (the JWK thumbprint over the required
|
|
9
|
+
* members in lexicographic order).
|
|
10
|
+
*/
|
|
11
|
+
/** The public half of an ES256 key, as a JWK carrying only the members RFC 7638 hashes. */
|
|
12
|
+
export interface P256PublicJwk {
|
|
13
|
+
readonly kty: 'EC';
|
|
14
|
+
readonly crv: 'P-256';
|
|
15
|
+
readonly x: string;
|
|
16
|
+
readonly y: string;
|
|
17
|
+
}
|
|
18
|
+
/** The only JWS algorithm the platform signs with, pinned rather than read from a header (RFC 8725 §3.1). */
|
|
19
|
+
export declare const ES256_JWS_ALGORITHM = "ES256";
|
|
20
|
+
/** The length of a raw ES256 signature: R and S, 32 bytes each. */
|
|
21
|
+
export declare const ES256_RAW_SIGNATURE_BYTES = 64;
|
|
22
|
+
/** base64url without padding (RFC 7515 §2). */
|
|
23
|
+
export declare function base64url(input: Buffer | Uint8Array | string): string;
|
|
24
|
+
/** Whether a value is a P-256 public JWK with the members RFC 7638 hashes. */
|
|
25
|
+
export declare function isP256PublicJwk(value: unknown): value is P256PublicJwk;
|
|
26
|
+
/** The RFC 7638 thumbprint of a P-256 public key: SHA-256 over `{"crv","kty","x","y"}` in that order, base64url. */
|
|
27
|
+
export declare function p256JwkThumbprint(jwk: P256PublicJwk): string;
|
|
28
|
+
/** The P-256 public JWK of a key object (public or private); refuses any other key type. */
|
|
29
|
+
export declare function p256PublicJwkOf(key: KeyObject): P256PublicJwk;
|
|
30
|
+
/** The verification key object of a P-256 public JWK. */
|
|
31
|
+
export declare function p256KeyObjectOf(jwk: P256PublicJwk): KeyObject;
|
|
32
|
+
/** The JWS signing input, `base64url(header).base64url(payload)` (RFC 7515 §5.1), for JSON header and claims. */
|
|
33
|
+
export declare function jwsSigningInput(header: Readonly<Record<string, unknown>>, claims: unknown): string;
|
|
34
|
+
/** The SHA-256 digest of a JWS signing input over its ASCII bytes: what a remote key provider is asked to sign. */
|
|
35
|
+
export declare function jwsSigningInputDigest(signingInput: string): Buffer;
|
|
36
|
+
/** How a key provider encodes the ECDSA signatures it returns. Declared by the provider, never guessed from the bytes. */
|
|
37
|
+
export declare enum EcdsaSignatureEncoding {
|
|
38
|
+
/** R ‖ S, 32 bytes each: what JWS requires and what a JOSE-native provider returns. */
|
|
39
|
+
RAW = "raw",
|
|
40
|
+
/** The DER `SEQUENCE { INTEGER r, INTEGER s }` a cloud KMS or an HSM returns. */
|
|
41
|
+
DER = "der"
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Normalize an ECDSA P-256 signature to the raw form ES256 requires: R ‖ S, each exactly 32 bytes, left-padded with
|
|
45
|
+
* zeros, never stripped (RFC 7518 §3.4). The encoding is the provider's declaration: guessing it from the bytes would be
|
|
46
|
+
* wrong for a valid raw signature whose first bytes happen to read as a DER header. Refuses a malformed signature, so
|
|
47
|
+
* one is never stored or returned.
|
|
48
|
+
*/
|
|
49
|
+
export declare function normalizeEs256Signature(signature: Uint8Array, encoding: EcdsaSignatureEncoding): Buffer;
|
|
50
|
+
/**
|
|
51
|
+
* The low-S form of a raw ES256 signature: S replaced by n − S when S > n/2. Both forms verify; signing only the low
|
|
52
|
+
* one removes the trivial malleability (a second valid signature over the same input), which is why a seal's identity
|
|
53
|
+
* never rests on its signature bytes and the signing proxy still emits low-S only (#2903).
|
|
54
|
+
*/
|
|
55
|
+
export declare function toLowSEs256Signature(signature: Uint8Array): Buffer;
|
|
56
|
+
/** Whether a raw ES256 signature is in the low-S form. */
|
|
57
|
+
export declare function isLowSEs256Signature(signature: Uint8Array): boolean;
|
|
58
|
+
/** Whether a raw ES256 signature verifies over a signing input under a public JWK. Verification is always local. */
|
|
59
|
+
export declare function verifyEs256(signingInput: string, signature: Uint8Array, publicJwk: P256PublicJwk): boolean;
|
|
60
|
+
//# sourceMappingURL=es256-jws.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"es256-jws.d.ts","sourceRoot":"","sources":["../../../src/key-management/es256-jws.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAEpH;;;;;;;;GAQG;AAEH,2FAA2F;AAC3F,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC;IACnB,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,6GAA6G;AAC7G,eAAO,MAAM,mBAAmB,UAAU,CAAC;AAE3C,mEAAmE;AACnE,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAE5C,+CAA+C;AA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
+
/** The only JWS algorithm the platform signs with, pinned rather than read from a header (RFC 8725 §3.1). */
|
|
3
|
+
export const ES256_JWS_ALGORITHM = 'ES256';
|
|
4
|
+
/** The length of a raw ES256 signature: R and S, 32 bytes each. */
|
|
5
|
+
export const ES256_RAW_SIGNATURE_BYTES = 64;
|
|
6
|
+
/** base64url without padding (RFC 7515 §2). */
|
|
7
|
+
export function base64url(input) {
|
|
8
|
+
return Buffer.from(input).toString('base64url');
|
|
9
|
+
}
|
|
10
|
+
/** Whether a value is a P-256 public JWK with the members RFC 7638 hashes. */
|
|
11
|
+
export function isP256PublicJwk(value) {
|
|
12
|
+
if (!value || typeof value !== 'object')
|
|
13
|
+
return false;
|
|
14
|
+
const jwk = value;
|
|
15
|
+
return jwk.kty === 'EC' && jwk.crv === 'P-256' && typeof jwk.x === 'string' && typeof jwk.y === 'string';
|
|
16
|
+
}
|
|
17
|
+
/** The RFC 7638 thumbprint of a P-256 public key: SHA-256 over `{"crv","kty","x","y"}` in that order, base64url. */
|
|
18
|
+
export function p256JwkThumbprint(jwk) {
|
|
19
|
+
const canonical = `{"crv":"${jwk.crv}","kty":"${jwk.kty}","x":"${jwk.x}","y":"${jwk.y}"}`;
|
|
20
|
+
return base64url(createHash('sha256').update(canonical).digest());
|
|
21
|
+
}
|
|
22
|
+
/** The P-256 public JWK of a key object (public or private); refuses any other key type. */
|
|
23
|
+
export function p256PublicJwkOf(key) {
|
|
24
|
+
const exported = (key.type === 'private' ? createPublicKey(key) : key).export({ format: 'jwk' });
|
|
25
|
+
if (!isP256PublicJwk(exported)) {
|
|
26
|
+
throw new Error('An ES256 key must be an EC P-256 key.');
|
|
27
|
+
}
|
|
28
|
+
return { kty: 'EC', crv: 'P-256', x: exported.x, y: exported.y };
|
|
29
|
+
}
|
|
30
|
+
/** The verification key object of a P-256 public JWK. */
|
|
31
|
+
export function p256KeyObjectOf(jwk) {
|
|
32
|
+
return createPublicKey({ key: { kty: 'EC', crv: 'P-256', x: jwk.x, y: jwk.y }, format: 'jwk' });
|
|
33
|
+
}
|
|
34
|
+
/** The JWS signing input, `base64url(header).base64url(payload)` (RFC 7515 §5.1), for JSON header and claims. */
|
|
35
|
+
export function jwsSigningInput(header, claims) {
|
|
36
|
+
return `${base64url(JSON.stringify(header))}.${base64url(JSON.stringify(claims))}`;
|
|
37
|
+
}
|
|
38
|
+
/** The SHA-256 digest of a JWS signing input over its ASCII bytes: what a remote key provider is asked to sign. */
|
|
39
|
+
export function jwsSigningInputDigest(signingInput) {
|
|
40
|
+
return createHash('sha256').update(Buffer.from(signingInput, 'ascii')).digest();
|
|
41
|
+
}
|
|
42
|
+
/** How a key provider encodes the ECDSA signatures it returns. Declared by the provider, never guessed from the bytes. */
|
|
43
|
+
export var EcdsaSignatureEncoding;
|
|
44
|
+
(function (EcdsaSignatureEncoding) {
|
|
45
|
+
/** R ‖ S, 32 bytes each: what JWS requires and what a JOSE-native provider returns. */
|
|
46
|
+
EcdsaSignatureEncoding["RAW"] = "raw";
|
|
47
|
+
/** The DER `SEQUENCE { INTEGER r, INTEGER s }` a cloud KMS or an HSM returns. */
|
|
48
|
+
EcdsaSignatureEncoding["DER"] = "der";
|
|
49
|
+
})(EcdsaSignatureEncoding || (EcdsaSignatureEncoding = {}));
|
|
50
|
+
/**
|
|
51
|
+
* Normalize an ECDSA P-256 signature to the raw form ES256 requires: R ‖ S, each exactly 32 bytes, left-padded with
|
|
52
|
+
* zeros, never stripped (RFC 7518 §3.4). The encoding is the provider's declaration: guessing it from the bytes would be
|
|
53
|
+
* wrong for a valid raw signature whose first bytes happen to read as a DER header. Refuses a malformed signature, so
|
|
54
|
+
* one is never stored or returned.
|
|
55
|
+
*/
|
|
56
|
+
export function normalizeEs256Signature(signature, encoding) {
|
|
57
|
+
const bytes = Buffer.from(signature);
|
|
58
|
+
const fail = (why) => {
|
|
59
|
+
throw new Error(`Not an ES256 signature: ${why}.`);
|
|
60
|
+
};
|
|
61
|
+
if (encoding === EcdsaSignatureEncoding.RAW) {
|
|
62
|
+
if (bytes.length !== ES256_RAW_SIGNATURE_BYTES)
|
|
63
|
+
fail(`a raw signature is ${ES256_RAW_SIGNATURE_BYTES} bytes, got ${bytes.length}`);
|
|
64
|
+
return bytes;
|
|
65
|
+
}
|
|
66
|
+
if (bytes[0] !== 0x30)
|
|
67
|
+
fail('not a DER sequence');
|
|
68
|
+
let offset = 1;
|
|
69
|
+
const [sequenceLength, sequenceLengthBytes] = readDerLength(bytes, offset) ?? fail('bad sequence length');
|
|
70
|
+
offset += sequenceLengthBytes;
|
|
71
|
+
if (offset + sequenceLength !== bytes.length)
|
|
72
|
+
fail('the sequence length does not match the signature length');
|
|
73
|
+
const integers = [];
|
|
74
|
+
for (let index = 0; index < 2; index += 1) {
|
|
75
|
+
if (bytes[offset] !== 0x02)
|
|
76
|
+
fail('expected an INTEGER');
|
|
77
|
+
offset += 1;
|
|
78
|
+
const [integerLength, integerLengthBytes] = readDerLength(bytes, offset) ?? fail('bad integer length');
|
|
79
|
+
offset += integerLengthBytes;
|
|
80
|
+
let integer = bytes.subarray(offset, offset + integerLength);
|
|
81
|
+
offset += integerLength;
|
|
82
|
+
while (integer.length > 1 && integer[0] === 0x00)
|
|
83
|
+
integer = integer.subarray(1);
|
|
84
|
+
if (integer.length > 32)
|
|
85
|
+
fail('an integer is wider than 32 bytes');
|
|
86
|
+
integers.push(Buffer.concat([Buffer.alloc(32 - integer.length), integer]));
|
|
87
|
+
}
|
|
88
|
+
if (offset !== bytes.length)
|
|
89
|
+
fail('trailing bytes after the two integers');
|
|
90
|
+
return Buffer.concat(integers);
|
|
91
|
+
}
|
|
92
|
+
function readDerLength(bytes, offset) {
|
|
93
|
+
const first = bytes[offset];
|
|
94
|
+
if (first === undefined)
|
|
95
|
+
return undefined;
|
|
96
|
+
if (first < 0x80)
|
|
97
|
+
return [first, 1];
|
|
98
|
+
const count = first & 0x7f;
|
|
99
|
+
if (count === 0 || count > 2 || offset + 1 + count > bytes.length)
|
|
100
|
+
return undefined;
|
|
101
|
+
let length = 0;
|
|
102
|
+
for (let index = 0; index < count; index += 1)
|
|
103
|
+
length = (length << 8) | bytes[offset + 1 + index];
|
|
104
|
+
return [length, 1 + count];
|
|
105
|
+
}
|
|
106
|
+
/** The order of the P-256 group (SEC 2 §2.4.2), for the low-S form. */
|
|
107
|
+
const P256_ORDER = 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551n;
|
|
108
|
+
/**
|
|
109
|
+
* The low-S form of a raw ES256 signature: S replaced by n − S when S > n/2. Both forms verify; signing only the low
|
|
110
|
+
* one removes the trivial malleability (a second valid signature over the same input), which is why a seal's identity
|
|
111
|
+
* never rests on its signature bytes and the signing proxy still emits low-S only (#2903).
|
|
112
|
+
*/
|
|
113
|
+
export function toLowSEs256Signature(signature) {
|
|
114
|
+
const bytes = Buffer.from(signature);
|
|
115
|
+
if (bytes.length !== ES256_RAW_SIGNATURE_BYTES)
|
|
116
|
+
throw new Error(`Not a raw ES256 signature: ${bytes.length} bytes.`);
|
|
117
|
+
const s = BigInt(`0x${bytes.subarray(32).toString('hex')}`);
|
|
118
|
+
if (s <= P256_ORDER >> 1n)
|
|
119
|
+
return bytes;
|
|
120
|
+
const lowS = Buffer.from((P256_ORDER - s).toString(16).padStart(64, '0'), 'hex');
|
|
121
|
+
return Buffer.concat([bytes.subarray(0, 32), lowS]);
|
|
122
|
+
}
|
|
123
|
+
/** Whether a raw ES256 signature is in the low-S form. */
|
|
124
|
+
export function isLowSEs256Signature(signature) {
|
|
125
|
+
if (signature.length !== ES256_RAW_SIGNATURE_BYTES)
|
|
126
|
+
return false;
|
|
127
|
+
return BigInt(`0x${Buffer.from(signature).subarray(32).toString('hex')}`) <= P256_ORDER >> 1n;
|
|
128
|
+
}
|
|
129
|
+
/** Whether a raw ES256 signature verifies over a signing input under a public JWK. Verification is always local. */
|
|
130
|
+
export function verifyEs256(signingInput, signature, publicJwk) {
|
|
131
|
+
if (signature.length !== ES256_RAW_SIGNATURE_BYTES)
|
|
132
|
+
return false;
|
|
133
|
+
return verifyWithKey('sha256', Buffer.from(signingInput, 'ascii'), { key: p256KeyObjectOf(publicJwk), dsaEncoding: 'ieee-p1363' }, signature);
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=es256-jws.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"es256-jws.js","sourceRoot":"","sources":["../../../src/key-management/es256-jws.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,IAAI,aAAa,EAAmC,MAAM,aAAa,CAAC;AAoBpH,6GAA6G;AAC7G,MAAM,CAAC,MAAM,mBAAmB,GAAG,OAAO,CAAC;AAE3C,mEAAmE;AACnE,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAE5C,+CAA+C;AAC/C,MAAM,UAAU,SAAS,CAAC,KAAmC;IAC3D,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AAClD,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACtD,MAAM,GAAG,GAAG,KAAgC,CAAC;IAC7C,OAAO,GAAG,CAAC,GAAG,KAAK,IAAI,IAAI,GAAG,CAAC,GAAG,KAAK,OAAO,IAAI,OAAO,GAAG,CAAC,CAAC,KAAK,QAAQ,IAAI,OAAO,GAAG,CAAC,CAAC,KAAK,QAAQ,CAAC;AAC3G,CAAC;AAED,oHAAoH;AACpH,MAAM,UAAU,iBAAiB,CAAC,GAAkB;IAClD,MAAM,SAAS,GAAG,WAAW,GAAG,CAAC,GAAG,YAAY,GAAG,CAAC,GAAG,UAAU,GAAG,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,IAAI,CAAC;IAC1F,OAAO,SAAS,CAAC,UAAU,CAAC,QAAQ,CAA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D;AAC1D,MAAM,UAAU,oBAAoB,CAAC,SAAqB;IACxD,IAAI,SAAS,CAAC,MAAM,KAAK,yBAAyB;QAAE,OAAO,KAAK,CAAC;IACjE,OAAO,MAAM,CAAC,KAAK,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,UAAU,IAAI,EAAE,CAAC;AAChG,CAAC;AAED,oHAAoH;AACpH,MAAM,UAAU,WAAW,CAAC,YAAoB,EAAE,SAAqB,EAAE,SAAwB;IAC/F,IAAI,SAAS,CAAC,MAAM,KAAK,yBAAyB;QAAE,OAAO,KAAK,CAAC;IACjE,OAAO,aAAa,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,EAAE,EAAE,GAAG,EAAE,eAAe,CAAC,SAAS,CAAC,EAAE,WAAW,EAAE,YAAY,EAAE,EAAE,SAAS,CAAC,CAAC;AAChJ,CAAC","sourcesContent":["import { createHash, createPublicKey, verify as verifyWithKey, type JsonWebKey, type KeyObject } from 'node:crypto';\n\n/**\n * The ES256 / JWS primitives every signer and verifier in the platform shares (#2891): the platform's answers to its\n * runtimes (#2921), the keyring's signatures and the approval seal's verifier (#2903). One implementation, in a\n * package with no JOSE dependency, so the offline verifier and every runtime read signatures the same way.\n *\n * spec-cite: RFC 7515 §5.1 (the JWS signing input), RFC 7518 §3.4 (ES256: ECDSA P-256 SHA-256, signature as the\n * 64-byte concatenation R ‖ S, each left-padded to 32 bytes), RFC 7638 §3 (the JWK thumbprint over the required\n * members in lexicographic order).\n */\n\n/** The public half of an ES256 key, as a JWK carrying only the members RFC 7638 hashes. */\nexport interface P256PublicJwk {\n readonly kty: 'EC';\n readonly crv: 'P-256';\n readonly x: string;\n readonly y: string;\n}\n\n/** The only JWS algorithm the platform signs with, pinned rather than read from a header (RFC 8725 §3.1). */\nexport const ES256_JWS_ALGORITHM = 'ES256';\n\n/** The length of a raw ES256 signature: R and S, 32 bytes each. */\nexport const ES256_RAW_SIGNATURE_BYTES = 64;\n\n/** base64url without padding (RFC 7515 §2). */\nexport function base64url(input: Buffer | Uint8Array | string): string {\n return Buffer.from(input).toString('base64url');\n}\n\n/** Whether a value is a P-256 public JWK with the members RFC 7638 hashes. */\nexport function isP256PublicJwk(value: unknown): value is P256PublicJwk {\n if (!value || typeof value !== 'object') return false;\n const jwk = value as Record<string, unknown>;\n return jwk.kty === 'EC' && jwk.crv === 'P-256' && typeof jwk.x === 'string' && typeof jwk.y === 'string';\n}\n\n/** The RFC 7638 thumbprint of a P-256 public key: SHA-256 over `{\"crv\",\"kty\",\"x\",\"y\"}` in that order, base64url. */\nexport function p256JwkThumbprint(jwk: P256PublicJwk): string {\n const canonical = `{\"crv\":\"${jwk.crv}\",\"kty\":\"${jwk.kty}\",\"x\":\"${jwk.x}\",\"y\":\"${jwk.y}\"}`;\n return base64url(createHash('sha256').update(canonical).digest());\n}\n\n/** The P-256 public JWK of a key object (public or private); refuses any other key type. */\nexport function p256PublicJwkOf(key: KeyObject): P256PublicJwk {\n const exported = (key.type === 'private' ? createPublicKey(key) : key).export({ format: 'jwk' }) as JsonWebKey;\n if (!isP256PublicJwk(exported)) {\n throw new Error('An ES256 key must be an EC P-256 key.');\n }\n return { kty: 'EC', crv: 'P-256', x: exported.x, y: exported.y };\n}\n\n/** The verification key object of a P-256 public JWK. */\nexport function p256KeyObjectOf(jwk: P256PublicJwk): KeyObject {\n return createPublicKey({ key: { kty: 'EC', crv: 'P-256', x: jwk.x, y: jwk.y }, format: 'jwk' });\n}\n\n/** The JWS signing input, `base64url(header).base64url(payload)` (RFC 7515 §5.1), for JSON header and claims. */\nexport function jwsSigningInput(header: Readonly<Record<string, unknown>>, claims: unknown): string {\n return `${base64url(JSON.stringify(header))}.${base64url(JSON.stringify(claims))}`;\n}\n\n/** The SHA-256 digest of a JWS signing input over its ASCII bytes: what a remote key provider is asked to sign. */\nexport function jwsSigningInputDigest(signingInput: string): Buffer {\n return createHash('sha256').update(Buffer.from(signingInput, 'ascii')).digest();\n}\n\n/** How a key provider encodes the ECDSA signatures it returns. Declared by the provider, never guessed from the bytes. */\nexport enum EcdsaSignatureEncoding {\n /** R ‖ S, 32 bytes each: what JWS requires and what a JOSE-native provider returns. */\n RAW = 'raw',\n /** The DER `SEQUENCE { INTEGER r, INTEGER s }` a cloud KMS or an HSM returns. */\n DER = 'der',\n}\n\n/**\n * Normalize an ECDSA P-256 signature to the raw form ES256 requires: R ‖ S, each exactly 32 bytes, left-padded with\n * zeros, never stripped (RFC 7518 §3.4). The encoding is the provider's declaration: guessing it from the bytes would be\n * wrong for a valid raw signature whose first bytes happen to read as a DER header. Refuses a malformed signature, so\n * one is never stored or returned.\n */\nexport function normalizeEs256Signature(signature: Uint8Array, encoding: EcdsaSignatureEncoding): Buffer {\n const bytes = Buffer.from(signature);\n const fail = (why: string): never => {\n throw new Error(`Not an ES256 signature: ${why}.`);\n };\n if (encoding === EcdsaSignatureEncoding.RAW) {\n if (bytes.length !== ES256_RAW_SIGNATURE_BYTES) fail(`a raw signature is ${ES256_RAW_SIGNATURE_BYTES} bytes, got ${bytes.length}`);\n return bytes;\n }\n if (bytes[0] !== 0x30) fail('not a DER sequence');\n let offset = 1;\n const [sequenceLength, sequenceLengthBytes] = readDerLength(bytes, offset) ?? fail('bad sequence length');\n offset += sequenceLengthBytes;\n if (offset + sequenceLength !== bytes.length) fail('the sequence length does not match the signature length');\n const integers: Buffer[] = [];\n for (let index = 0; index < 2; index += 1) {\n if (bytes[offset] !== 0x02) fail('expected an INTEGER');\n offset += 1;\n const [integerLength, integerLengthBytes] = readDerLength(bytes, offset) ?? fail('bad integer length');\n offset += integerLengthBytes;\n let integer = bytes.subarray(offset, offset + integerLength);\n offset += integerLength;\n while (integer.length > 1 && integer[0] === 0x00) integer = integer.subarray(1);\n if (integer.length > 32) fail('an integer is wider than 32 bytes');\n integers.push(Buffer.concat([Buffer.alloc(32 - integer.length), integer]));\n }\n if (offset !== bytes.length) fail('trailing bytes after the two integers');\n return Buffer.concat(integers);\n}\n\nfunction readDerLength(bytes: Buffer, offset: number): [number, number] | undefined {\n const first = bytes[offset];\n if (first === undefined) return undefined;\n if (first < 0x80) return [first, 1];\n const count = first & 0x7f;\n if (count === 0 || count > 2 || offset + 1 + count > bytes.length) return undefined;\n let length = 0;\n for (let index = 0; index < count; index += 1) length = (length << 8) | (bytes[offset + 1 + index] as number);\n return [length, 1 + count];\n}\n\n/** The order of the P-256 group (SEC 2 §2.4.2), for the low-S form. */\nconst P256_ORDER = 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551n;\n\n/**\n * The low-S form of a raw ES256 signature: S replaced by n − S when S > n/2. Both forms verify; signing only the low\n * one removes the trivial malleability (a second valid signature over the same input), which is why a seal's identity\n * never rests on its signature bytes and the signing proxy still emits low-S only (#2903).\n */\nexport function toLowSEs256Signature(signature: Uint8Array): Buffer {\n const bytes = Buffer.from(signature);\n if (bytes.length !== ES256_RAW_SIGNATURE_BYTES) throw new Error(`Not a raw ES256 signature: ${bytes.length} bytes.`);\n const s = BigInt(`0x${bytes.subarray(32).toString('hex')}`);\n if (s <= P256_ORDER >> 1n) return bytes;\n const lowS = Buffer.from((P256_ORDER - s).toString(16).padStart(64, '0'), 'hex');\n return Buffer.concat([bytes.subarray(0, 32), lowS]);\n}\n\n/** Whether a raw ES256 signature is in the low-S form. */\nexport function isLowSEs256Signature(signature: Uint8Array): boolean {\n if (signature.length !== ES256_RAW_SIGNATURE_BYTES) return false;\n return BigInt(`0x${Buffer.from(signature).subarray(32).toString('hex')}`) <= P256_ORDER >> 1n;\n}\n\n/** Whether a raw ES256 signature verifies over a signing input under a public JWK. Verification is always local. */\nexport function verifyEs256(signingInput: string, signature: Uint8Array, publicJwk: P256PublicJwk): boolean {\n if (signature.length !== ES256_RAW_SIGNATURE_BYTES) return false;\n return verifyWithKey('sha256', Buffer.from(signingInput, 'ascii'), { key: p256KeyObjectOf(publicJwk), dsaEncoding: 'ieee-p1363' }, signature);\n}\n"]}
|