@zanii/certify 0.0.0-stage → 0.6.0

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 (141) hide show
  1. package/LICENSE +159 -0
  2. package/README.md +144 -2
  3. package/dist/appliance-execution.d.ts +18 -0
  4. package/dist/appliance-execution.js +12 -0
  5. package/dist/appliance.d.ts +135 -0
  6. package/dist/appliance.js +253 -0
  7. package/dist/assurance-status.d.ts +58 -0
  8. package/dist/assurance-status.js +86 -0
  9. package/dist/audit-renewal.d.ts +39 -0
  10. package/dist/audit-renewal.js +62 -0
  11. package/dist/audit.d.ts +69 -0
  12. package/dist/audit.js +112 -0
  13. package/dist/beacon-client.d.ts +40 -0
  14. package/dist/beacon-client.js +151 -0
  15. package/dist/beacon.d.ts +84 -0
  16. package/dist/beacon.js +106 -0
  17. package/dist/bitstring-status.d.ts +56 -0
  18. package/dist/bitstring-status.js +135 -0
  19. package/dist/board.d.ts +218 -0
  20. package/dist/board.js +428 -0
  21. package/dist/bundle.d.ts +100 -0
  22. package/dist/bundle.js +122 -0
  23. package/dist/certificate.d.ts +161 -0
  24. package/dist/certificate.js +346 -0
  25. package/dist/cli-messages.json +148 -0
  26. package/dist/cli.d.ts +16 -0
  27. package/dist/cli.js +369 -0
  28. package/dist/current-issuer-vc.d.ts +20 -0
  29. package/dist/current-issuer-vc.js +60 -0
  30. package/dist/evidence-share.d.ts +89 -0
  31. package/dist/evidence-share.js +479 -0
  32. package/dist/federation.d.ts +103 -0
  33. package/dist/federation.js +240 -0
  34. package/dist/feed-snapshot.d.ts +97 -0
  35. package/dist/feed-snapshot.js +186 -0
  36. package/dist/fingerprint.d.ts +23 -0
  37. package/dist/fingerprint.js +48 -0
  38. package/dist/formats/status-v2.schema.json +31 -0
  39. package/dist/governance.d.ts +244 -0
  40. package/dist/governance.js +418 -0
  41. package/dist/identity.d.ts +79 -0
  42. package/dist/identity.js +146 -0
  43. package/dist/impartiality.d.ts +47 -0
  44. package/dist/impartiality.js +85 -0
  45. package/dist/index.d.ts +61 -0
  46. package/dist/index.js +63 -0
  47. package/dist/issuer-authorization.d.ts +4 -0
  48. package/dist/issuer-authorization.js +52 -0
  49. package/dist/issuer-resolution.d.ts +25 -0
  50. package/dist/issuer-resolution.js +89 -0
  51. package/dist/licence-owner-entry.d.ts +20 -0
  52. package/dist/licence-owner-entry.js +33 -0
  53. package/dist/licence-owner.d.ts +67 -0
  54. package/dist/licence-owner.js +180 -0
  55. package/dist/licence.d.ts +174 -0
  56. package/dist/licence.js +400 -0
  57. package/dist/live-evidence.d.ts +135 -0
  58. package/dist/live-evidence.js +210 -0
  59. package/dist/nitro-roots.d.ts +3 -0
  60. package/dist/nitro-roots.js +20 -0
  61. package/dist/nitro-x509.d.ts +16 -0
  62. package/dist/nitro-x509.js +141 -0
  63. package/dist/nitro.d.ts +74 -0
  64. package/dist/nitro.js +329 -0
  65. package/dist/normalization.d.ts +8 -0
  66. package/dist/normalization.js +10 -0
  67. package/dist/pq.d.ts +32 -0
  68. package/dist/pq.js +69 -0
  69. package/dist/profile.d.ts +15 -0
  70. package/dist/profile.js +165 -0
  71. package/dist/register.d.ts +79 -0
  72. package/dist/register.js +134 -0
  73. package/dist/rotation.d.ts +49 -0
  74. package/dist/rotation.js +124 -0
  75. package/dist/royalty-reconciliation.d.ts +24 -0
  76. package/dist/royalty-reconciliation.js +88 -0
  77. package/dist/runtime-client.d.ts +40 -0
  78. package/dist/runtime-client.js +190 -0
  79. package/dist/runtime-gateway.d.ts +26 -0
  80. package/dist/runtime-gateway.js +169 -0
  81. package/dist/runtime-knowledge.d.ts +28 -0
  82. package/dist/runtime-knowledge.js +75 -0
  83. package/dist/runtime-nitro.d.ts +30 -0
  84. package/dist/runtime-nitro.js +57 -0
  85. package/dist/runtime.d.ts +226 -0
  86. package/dist/runtime.js +254 -0
  87. package/dist/sandbox-delegation.d.ts +38 -0
  88. package/dist/sandbox-delegation.js +61 -0
  89. package/dist/schema-dialect.d.ts +1 -0
  90. package/dist/schema-dialect.js +97 -0
  91. package/dist/schemas/clause-map.schema.json +52 -0
  92. package/dist/schemas/profile.schema.json +81 -0
  93. package/dist/schemas/scenarios.schema.json +573 -0
  94. package/dist/schemas/suite.schema.json +138 -0
  95. package/dist/schemas/trajectory.schema.json +1396 -0
  96. package/dist/scheme-authority.d.ts +5 -0
  97. package/dist/scheme-authority.js +15 -0
  98. package/dist/scheme-entry.d.ts +25 -0
  99. package/dist/scheme-entry.js +85 -0
  100. package/dist/scheme-history.d.ts +5 -0
  101. package/dist/scheme-history.js +87 -0
  102. package/dist/scheme-log.d.ts +98 -0
  103. package/dist/scheme-log.js +266 -0
  104. package/dist/scheme-merkle.d.ts +2 -0
  105. package/dist/scheme-merkle.js +20 -0
  106. package/dist/scheme-text.d.ts +25 -0
  107. package/dist/scheme-text.js +46 -0
  108. package/dist/scheme-timing.d.ts +16 -0
  109. package/dist/scheme-timing.js +22 -0
  110. package/dist/scheme-transition.d.ts +47 -0
  111. package/dist/scheme-transition.js +101 -0
  112. package/dist/scoring.d.ts +35 -0
  113. package/dist/scoring.js +50 -0
  114. package/dist/shared.d.ts +16 -0
  115. package/dist/shared.js +20 -0
  116. package/dist/signer.d.ts +18 -0
  117. package/dist/signer.js +49 -0
  118. package/dist/signing-identity.d.ts +1 -0
  119. package/dist/signing-identity.js +11 -0
  120. package/dist/status.d.ts +113 -0
  121. package/dist/status.js +204 -0
  122. package/dist/succession.d.ts +21 -0
  123. package/dist/succession.js +67 -0
  124. package/dist/suite.d.ts +261 -0
  125. package/dist/suite.js +458 -0
  126. package/dist/trajectory.d.ts +216 -0
  127. package/dist/trajectory.js +409 -0
  128. package/dist/transcript-provenance.d.ts +25 -0
  129. package/dist/transcript-provenance.js +37 -0
  130. package/dist/transport-key.d.ts +3 -0
  131. package/dist/transport-key.js +16 -0
  132. package/dist/vc.d.ts +29 -0
  133. package/dist/vc.js +96 -0
  134. package/dist/verification-bounds.d.ts +5 -0
  135. package/dist/verification-bounds.js +78 -0
  136. package/dist/verification-policy.d.ts +32 -0
  137. package/dist/verification-policy.js +85 -0
  138. package/dist/witness.d.ts +19 -0
  139. package/dist/witness.js +80 -0
  140. package/package.json +65 -4
  141. package/src/cli.ts +331 -0
package/LICENSE ADDED
@@ -0,0 +1,159 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work; and
103
+
104
+ (d) If the Work includes a "NOTICE" text file as part of its
105
+ distribution, then any Derivative Works that You distribute must
106
+ include a readable copy of the attribution notices contained
107
+ within such NOTICE file.
108
+
109
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
110
+ any Contribution intentionally submitted for inclusion in the Work
111
+ by You to the Licensor shall be under the terms and conditions of
112
+ this License, without any additional terms or conditions.
113
+
114
+ 6. Trademarks. This License does not grant permission to use the trade
115
+ names, trademarks, service marks, or product names of the Licensor,
116
+ except as required for reasonable and customary use in describing the
117
+ origin of the Work and reproducing the content of the NOTICE file.
118
+
119
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed
120
+ to in writing, Licensor provides the Work (and each Contributor
121
+ provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES
122
+ OR CONDITIONS OF ANY KIND, either express or implied, including,
123
+ without limitation, any warranties or conditions of TITLE,
124
+ NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
125
+
126
+ 8. Limitation of Liability. In no event and under no legal theory,
127
+ whether in tort (including negligence), contract, or otherwise,
128
+ unless required by applicable law (such as deliberate and grossly
129
+ negligent acts) or agreed to in writing, shall any Contributor be
130
+ liable to You for damages, including any direct, indirect, special,
131
+ incidental, or consequential damages of any character arising as a
132
+ result of this License or out of the use or inability to use the
133
+ Work.
134
+
135
+ 9. Accepting Warranty or Additional Liability. While redistributing
136
+ the Work or Derivative Works thereof, You may choose to offer,
137
+ and charge a fee for, acceptance of support, warranty, indemnity,
138
+ or other liability obligations and/or rights consistent with this
139
+ License. However, in accepting such obligations, You may act only
140
+ on Your own behalf and on Your sole responsibility, not on behalf
141
+ of any other Contributor, and only if You agree to indemnify,
142
+ defend, and hold each Contributor harmless for any liability
143
+ incurred by, or claims asserted against, such Contributor.
144
+
145
+ END OF TERMS AND CONDITIONS
146
+
147
+ Copyright 2026 Zanii
148
+
149
+ Licensed under the Apache License, Version 2.0 (the "License");
150
+ you may not use this file except in compliance with the License.
151
+ You may obtain a copy of the License at
152
+
153
+ http://www.apache.org/licenses/LICENSE-2.0
154
+
155
+ Unless required by applicable law or agreed to in writing, software
156
+ distributed under the License is distributed on an "AS IS" BASIS,
157
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
158
+ See the License for the specific language governing permissions and
159
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,145 @@
1
- # Temporary Holding Version
1
+ # @zanii/certify
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ TypeScript SDK and `certify` CLI for Zanii Certify fingerprints, signed certificates,
4
+ status, evidence sharing, runtime assurance and scheme governance. The package uses
5
+ ES modules and requires Node.js 24 or newer. Every public function is exported from the
6
+ package root; the signed formats are defined in the Zanii Certify specification (`spec/`).
7
+
8
+ ## Install
9
+
10
+ ```sh
11
+ npm install @zanii/certify
12
+ npx certify verify cert.json --online https://lab.zanii.agency
13
+ ```
14
+
15
+ Paths in backticks below (`spec/...`, `conformance/...`) are files of the Zanii Certify source repository, which is private; the specification documents are available from Zanii on request (info@zanii.agency).
16
+
17
+ ## Use this checkout
18
+
19
+ From the repository root, with the pnpm version declared in the root `package.json`:
20
+
21
+ ```sh
22
+ pnpm install --frozen-lockfile
23
+ node packages/certify/src/cli.ts --help-v2
24
+ ```
25
+
26
+ The workspace package resolves directly to TypeScript source. Save the following as
27
+ `example.mjs` at the repository root and run `node example.mjs`. It needs no server,
28
+ network access or signing key:
29
+
30
+ ```js
31
+ import {
32
+ buildFingerprint, checkFingerprint, promptSha256,
33
+ runtimeRequestHash, sha256Bytes,
34
+ } from "@zanii/certify";
35
+
36
+ const fingerprint = buildFingerprint({
37
+ model: "example-model@1",
38
+ prompt: promptSha256("Answer using the approved policy."),
39
+ tools: null,
40
+ policy: null,
41
+ knowledge: null,
42
+ });
43
+ if (!checkFingerprint(fingerprint)) throw new Error("Invalid fingerprint");
44
+ console.log(fingerprint.id);
45
+
46
+ // Commit the exact request body bytes; this hash alone grants no permission.
47
+ const body = '{"amount_minor":100,"currency":"USD"}';
48
+ console.log(runtimeRequestHash({
49
+ method: "POST",
50
+ url: "https://bank.example/payments",
51
+ body_sha256: sha256Bytes(body),
52
+ }));
53
+ ```
54
+
55
+ Fingerprint fields contain hashes or `null`, rather than raw prompts/documents.
56
+ Keep the original bytes: changing whitespace can change a commitment.
57
+
58
+ ## Verification policy
59
+
60
+ `await verifyCertificate(certificate, options)` returns a structured check with
61
+ `ok` and `reasons`. Optional checks run when their inputs/policies are supplied;
62
+ an `ok` result alone does not mean every relying-party requirement was checked.
63
+
64
+ - Supply fresh signed `status` and `revocationList`, the expected `fingerprint`,
65
+ and an explicit verification time (`now`) when reproducibility is required.
66
+ - Supply an independently approved `issuerPolicy` and the corresponding `issuerDoc`.
67
+ A downloaded document cannot choose its own trusted keys. Changed keys/PQ metadata
68
+ require local policy review; `allowNoPq` cannot override this pinned policy.
69
+ - Supply `pq`/`statusPq` when required. For Level 3, supply the audit plus trusted
70
+ bodies or an independently rooted body register. Add witness, licence and release
71
+ policies where the relying party requires them. Strict withdrawal checking needs
72
+ the withdrawal log and `releases.rejectWithdrawn: true`.
73
+
74
+ The complete option types are in certificate.ts (`packages/certify/src/certificate.ts`), and executable
75
+ positive/negative policy examples are in verification-policy.test.ts (`packages/certify/src/verification-policy.test.ts`).
76
+ Legacy optional behavior is retained for compatibility; select your policy explicitly.
77
+ Offline evidence cannot reveal an undisclosed newer checkpoint or revocation.
78
+
79
+ The CLI is offline by default. `--help-v2` lists current audit, witness, release and
80
+ strict-policy inputs. `--online` enables bounded retrieval, including required PQ
81
+ material. A relying party requiring every CLI check should accept only exit code 0;
82
+ exit code 2 means not fully checked. See the CLI contract (`spec/cli.md`).
83
+
84
+ ## Contracts and limits
85
+
86
+ | Area | Contract |
87
+ | --- | --- |
88
+ | Fingerprints and certificate verification | Fingerprint (`spec/fingerprint.md`), certificate and pinned policy (`spec/certificate.md`) |
89
+ | Status and freshness | Status v1/v2 (`spec/status.md`), witness checkpoints (`spec/witness.md`), Bitstring Status List (`spec/bitstring-status.md`), assurance withdrawal (`spec/assurance-status.md`) |
90
+ | Runtime releases, mandates, leases and knowledge proofs | Runtime assurance (`spec/runtime.md`) |
91
+ | Scheme releases, exact text and transitions | Scheme (`spec/scheme.md`), immutable text (`spec/scheme-text.md`), checkpointed log (`spec/scheme-log.md`) |
92
+ | Redacted evidence and inclusion proofs | Evidence sharing (`spec/evidence-share.md`) |
93
+
94
+ Builders and verifiers enforce format-specific byte/count limits. Read each contract
95
+ before choosing workload sizes or persisting freshness watermarks. A valid inclusion
96
+ proof establishes commitment to supplied data; it does not establish content truth,
97
+ ACL permission or quality. The Node package also exposes Nitro verification, a runtime
98
+ reporter and a reference gateway; those host integrations are not Python SDK equivalents.
99
+
100
+ ## Beacon reporting
101
+
102
+ `startBeacon` sends immediately, then waits the configured interval after each completed
103
+ operation. Intervals must be between 1,000 and 2,147,483,647 milliseconds. Each client allows
104
+ one underlying operation; concurrent `send()` calls return a busy failure without queuing.
105
+ The full operation has a ten second deadline, including fingerprint collection, signing and
106
+ reading the response. Replies are capped at 32KiB; redirects and credentialed URLs are refused.
107
+
108
+ `stop()` disables automatic reporting and aborts the active request. Manual `send()` remains
109
+ available. An injected callback that ignores cancellation keeps its slot until it returns;
110
+ late callbacks cannot submit a report. Result observer exceptions do not interrupt reporting.
111
+
112
+ `startBeacon`, `createRuntimeReporter` and `createRuntimeGateway` accept optional
113
+ `transportKey: process.env.CERTIFY_TRANSPORT_KEY`. Use an agent-bound `ctk_` admission
114
+ credential issued by the owner/admin transport-key controls, never a management API key.
115
+ It travels only in the authority's Authorization header, outside signed documents and
116
+ hashes. The gateway never forwards it to a protected backend. Invalid prefixes and
117
+ non-HTTPS beacon endpoints are refused before I/O, except literal loopback/localhost
118
+ for local development. Runtime reporter/gateway authority URLs keep their existing
119
+ HTTPS requirement. Anonymous signed clients still work; transport admission does not
120
+ replace signatures, approved workload binding or replay checks. Redirects remain refused.
121
+ Callback error messages and beacon response echoes redact the supplied credential.
122
+
123
+ The reporter handles challenge/evidence and the gateway handles consume. Lease request
124
+ builders produce signed documents; this package does not provide a general HTTP lease
125
+ acquisition or management client. Injected transports must keep credentials private and
126
+ honor the same redirect/deadline contract.
127
+
128
+ The package root also exports `JsonFetchResult`, `logPositionOk`,
129
+ `RUNTIME_NITRO_MAX_BYTES` and `RUNTIME_NITRO_MAX_SKEW_SECONDS` for callers validating
130
+ issuer responses, status log positions and raw runtime attestations.
131
+
132
+ ## Check changes
133
+
134
+ Run from the repository root:
135
+
136
+ ```sh
137
+ pnpm typecheck
138
+ pnpm --filter @zanii/certify test
139
+ node --test packages/certify/src/verification-policy.test.ts
140
+ ```
141
+
142
+ Shared vectors (`spec/vectors`) and conformance tests (`conformance`)
143
+ check the common TypeScript/Python wire formats. New versioned formats preserve the
144
+ old signed bytes. Local SDK tests do not qualify deployment security or capacity;
145
+ see the readiness report (`docs/readiness-report.md`).
@@ -0,0 +1,18 @@
1
+ export interface ApplianceExportIdentity {
2
+ v: 1;
3
+ type: "certify.appliance-export-identity";
4
+ appliance: string;
5
+ source_run: string;
6
+ recipient: string;
7
+ }
8
+ export interface ApplianceExecution {
9
+ v: 1;
10
+ type: "certify.appliance-execution";
11
+ appliance: string;
12
+ source_run: string;
13
+ source_bundle: string;
14
+ export: string;
15
+ attestation: "quote_verified" | "not_verified";
16
+ }
17
+ export declare function applianceExportIdentity(value: unknown): ApplianceExportIdentity;
18
+ export declare function applianceExecution(value: unknown): ApplianceExecution;
@@ -0,0 +1,12 @@
1
+ import { isDid, isObj, isSha } from "./shared.js";
2
+ const run = (value) => typeof value === "string" && /^[A-Za-z0-9._:-]{1,128}$/.test(value);
3
+ export function applianceExportIdentity(value) {
4
+ if (!isObj(value) || Object.keys(value).length !== 5 || value.v !== 1 || value.type !== "certify.appliance-export-identity" || !isDid(value.appliance) || !run(value.source_run) || !isSha(value.recipient))
5
+ throw new Error("invalid appliance export identity (v1)");
6
+ return { v: 1, type: "certify.appliance-export-identity", appliance: value.appliance, source_run: value.source_run, recipient: value.recipient };
7
+ }
8
+ export function applianceExecution(value) {
9
+ if (!isObj(value) || Object.keys(value).length !== 7 || value.v !== 1 || value.type !== "certify.appliance-execution" || !isDid(value.appliance) || !run(value.source_run) || !isSha(value.source_bundle) || !isSha(value.export) || typeof value.attestation !== "string" || !["quote_verified", "not_verified"].includes(value.attestation))
10
+ throw new Error("invalid appliance execution provenance (v1)");
11
+ return { v: 1, type: "certify.appliance-execution", appliance: value.appliance, source_run: value.source_run, source_bundle: value.source_bundle, export: value.export, attestation: value.attestation };
12
+ }
@@ -0,0 +1,135 @@
1
+ import { type QuoteVerifier } from "@zanii/attest";
2
+ import { type HybridKemKeypair, type HybridSealed } from "@zanii/pq";
3
+ import { type ApplianceExportBundle, type ResultBundle } from "./bundle.ts";
4
+ import { type Signer } from "./signer.ts";
5
+ export interface ApplianceCheck {
6
+ ok: boolean;
7
+ reasons: string[];
8
+ }
9
+ export interface ApplianceEnrolment {
10
+ v: 1;
11
+ type: "certify.appliance-enrolment";
12
+ appliance: string;
13
+ customer: {
14
+ name: string;
15
+ country: string;
16
+ };
17
+ measurements: string[];
18
+ enrolled_at: string;
19
+ valid_until: string;
20
+ signer: string;
21
+ sig: string;
22
+ }
23
+ /** Section 1: the central lab enrols an appliance key and the code measurements it may run. */
24
+ export declare function buildApplianceEnrolment(f: {
25
+ appliance: string;
26
+ customer: {
27
+ name: string;
28
+ country: string;
29
+ };
30
+ measurements: readonly string[];
31
+ enrolledAt: string;
32
+ validUntil: string;
33
+ }, signer: Signer): Promise<ApplianceEnrolment>;
34
+ export interface EvidenceHead {
35
+ chain: string;
36
+ head: string;
37
+ size: number;
38
+ }
39
+ /** Section 2: the transcripts, sealed to the central lab's hybrid key, and that key's hash. */
40
+ export interface SealedTranscripts {
41
+ recipient: string;
42
+ sealed: HybridSealed;
43
+ }
44
+ export interface ApplianceAttestation {
45
+ v: 1;
46
+ platform: string;
47
+ measurement: string;
48
+ quote_hash: string;
49
+ /** `applianceChallenge` of the export. */
50
+ nonce: string;
51
+ attested_at: string;
52
+ }
53
+ export interface ApplianceExport {
54
+ v: 1;
55
+ type: "certify.appliance-export";
56
+ appliance: string;
57
+ enrolment: ApplianceEnrolment;
58
+ attestation: ApplianceAttestation;
59
+ bundle: ResultBundle | ApplianceExportBundle;
60
+ evidence: EvidenceHead[];
61
+ transcripts: SealedTranscripts;
62
+ exported_at: string;
63
+ signer: string;
64
+ sig: string;
65
+ }
66
+ /** Section 2: the hash of the central lab's public key, `{x25519, mlkem}` hex. */
67
+ export declare const labKeyId: (key: HybridKemKeypair["publicKey"]) => string;
68
+ /** Section 2: seal the transcripts (any JSON value) to the central lab: its canonical bytes, hybrid sealed. */
69
+ export declare function sealTranscripts(transcripts: unknown, labKey: HybridKemKeypair["publicKey"]): SealedTranscripts;
70
+ /** Section 2: the report data the appliance's attestation quote binds. */
71
+ export declare const applianceChallenge: (f: {
72
+ appliance: string;
73
+ bundle: string;
74
+ evidence: readonly EvidenceHead[];
75
+ transcripts: SealedTranscripts;
76
+ exportedAt: string;
77
+ }) => string;
78
+ export interface ApplianceExportInput {
79
+ enrolment: ApplianceEnrolment;
80
+ attestation: ApplianceAttestation;
81
+ bundle: ResultBundle | ApplianceExportBundle;
82
+ evidence: readonly EvidenceHead[];
83
+ transcripts: SealedTranscripts;
84
+ exportedAt: string;
85
+ }
86
+ /** Section 2: the export, signed by the appliance key (`signer`, the enrolled appliance). */
87
+ export declare function buildApplianceExport(f: ApplianceExportInput, signer: Signer): Promise<ApplianceExport>;
88
+ /**
89
+ * Section 3: signed by its appliance, enrolled by a trusted central lab (`labs`) for the time of
90
+ * export, attested for this export with an enrolled measurement, sealed to `labKey` when given, and
91
+ * (with `verifyQuote`) the attestation quote verified by the injected platform verifier.
92
+ */
93
+ export declare function verifyApplianceExport(doc: unknown, opts?: {
94
+ labs?: readonly string[];
95
+ labKey?: HybridKemKeypair["publicKey"];
96
+ now?: string;
97
+ verifyQuote?: QuoteVerifier;
98
+ }): Promise<ApplianceCheck & {
99
+ attested: boolean | null;
100
+ }>;
101
+ /** Section 4: the central lab opens the transcripts with its secret key; throws on a wrong key or tampering. */
102
+ export declare function openApplianceExport(doc: ApplianceExport, secretKey: HybridKemKeypair["secretKey"]): unknown;
103
+ export interface ApplianceUpdate {
104
+ v: 1;
105
+ type: "certify.appliance-update";
106
+ version: string;
107
+ sha256: string;
108
+ /** jcsHash of the enrolment of the one appliance the update is for. */
109
+ enrolment: string;
110
+ released_at: string;
111
+ notes: {
112
+ en: string;
113
+ ar: string;
114
+ };
115
+ signer: string;
116
+ sig: string;
117
+ }
118
+ /** Section 5: an offline update bundle's manifest for one enrolled appliance (`enrolment`, the jcsHash of its enrolment), signed by the lab release key. */
119
+ export declare function buildApplianceUpdate(f: {
120
+ version: string;
121
+ sha256: string;
122
+ enrolment: string;
123
+ releasedAt: string;
124
+ notes: {
125
+ en: string;
126
+ ar: string;
127
+ };
128
+ }, signer: Signer): Promise<ApplianceUpdate>;
129
+ /** Section 5: signed by a trusted release key (`keys`), for `content` when given, for the appliance whose enrolment hash is `enrolment`, and newer than `installed` when given. */
130
+ export declare function verifyApplianceUpdate(doc: unknown, opts?: {
131
+ keys?: readonly string[];
132
+ content?: Uint8Array;
133
+ installed?: string;
134
+ enrolment?: string;
135
+ }): ApplianceCheck;