@getvda/witness 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,30 @@
1
+ Verified Digital Agents (VDA) — Agent Control Plane
2
+ Copyright 2026 getvda.ai
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use these files except in compliance with the License. A copy of the
6
+ License is in the LICENSE file at the repository root and at:
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software distributed
11
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12
+ CONDITIONS OF ANY KIND, either express or implied.
13
+
14
+ ---
15
+
16
+ What these packages do and do NOT carry
17
+ ----------------------------------------
18
+
19
+ The @getvda/* packages VERIFY and ENFORCE governance. They do not carry the
20
+ trust anchors that governance rests on:
21
+
22
+ - Bundle-signing keys (#key-3) live only in getvda's Secret Manager. These
23
+ packages VERIFY a bundle's signature against the public key resolved from
24
+ did:web:acp.getvda.ai; they cannot mint a bundle that verifies.
25
+ - Witness account credentials are the customer's own (customer-managed
26
+ custody). These packages SEAL to a Witness account the caller supplies;
27
+ they carry no standing credential.
28
+
29
+ The code is open. The trust anchors are not in the code — and giving away the
30
+ verifier does not give away the ability to forge what it verifies.
package/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # @getvda/witness
2
+
3
+ > **Status: pre-1.0 (0.x).** Public API may change between minor versions —
4
+ > pin an exact version if you need stability. Part of the [getvda.ai](https://getvda.ai)
5
+ > governance suite. Honesty discipline: nothing documented here is live unless it
6
+ > says so, boundaries (fail-static, condition-assertion) are stated where they apply,
7
+ > and a stub is labelled a stub.
8
+
9
+ > **What this carries — and what it does not.** This package *verifies and
10
+ > enforces* governance. The trust anchors are not in it: bundle-signing keys
11
+ > (`#key-3`) live only in getvda's Secret Manager, and Witness account
12
+ > credentials are the caller's own (customer-managed custody). It verifies a
13
+ > signature against the public key resolved from `did:web:acp.getvda.ai` and
14
+ > seals to a Witness account you supply — it cannot mint a bundle that verifies,
15
+ > and carries no standing credential. Open code, trust anchors elsewhere.
16
+
17
+ Witness sealing substrate for ACP — where governance EVENTS become tamper-evident
18
+ (the document↔event tie: git proves authoring, Witness proves the approval).
19
+
20
+ ## Real client + a no-network fake (same pattern as the in-memory git adapter)
21
+
22
+ - **`WitnessHttpClient`** — the real client, **customer-managed custody**:
23
+ `prepare` → sign `canonicalBytes` with ACP's Ed25519 record key (#key-2) →
24
+ submit `{ record }` with a `proof`. Because ACP signs the record itself, it is
25
+ provable even against Witness. Verified against the live OpenAPI (2026-07-18).
26
+ Needs ACP's ANCHORED, controller-bound Witness account — **not yet
27
+ provisioned**; the client is written to the real contract so the swap is a
28
+ constructor change.
29
+ - **`FakeWitnessClient`** — no network, deterministic, and **faithful**: it signs
30
+ each record with a real Ed25519 key, so `verify()` genuinely re-checks the
31
+ signature and the approval gate exercises the real verification path. Reports
32
+ `ANCHORED` by default (mirroring the account ACP will have). Labelled
33
+ `signer: "fake"`; never for production.
34
+
35
+ ## What it seals
36
+
37
+ `sealHitlDecision(params)` — the `hitl_decision` shape from the live contract:
38
+ `actor{id,type:'human'}` + `decision{statement,disposition}` +
39
+ `governing_clauses[]` (≥1) + `evidence[]` (**the git commit rides here**:
40
+ `ref` = commit, `hash` = `sha256:` of the governance content) + `basis_captured_at`.
41
+
42
+ Also `whoami()` (Contract A) and `verify(record)` (public signature/chain check).
43
+
44
+ ## Keys
45
+
46
+ `Ed25519RecordSigner` takes a PEM or JWK private key (Mike holds it; it arrives
47
+ from Secret Manager at runtime). Its public half is published in ACP's DID doc —
48
+ what Witness `issuer_verified` resolves against. See the Phase-0 provisioning
49
+ brief for the three-key model.
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Canonicalization helpers shared by the fake server + client. Kept in their own
3
+ * module so fake.ts and fake-server.ts can both use them without a cycle.
4
+ */
5
+ import { type RecordSigner } from './signer.js';
6
+ /** Deterministic canonical JSON (sorted keys). */
7
+ export declare function stableStringify(value: unknown): string;
8
+ export declare function sha256Hex(s: string): string;
9
+ /** An ephemeral Ed25519 record signer (for the fake). */
10
+ export declare function ephemeralSigner(keyId?: string): RecordSigner;
11
+ //# sourceMappingURL=canonical.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical.d.ts","sourceRoot":"","sources":["../src/canonical.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAuB,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAErE,kDAAkD;AAClD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEtD;AAaD,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,yDAAyD;AACzD,wBAAgB,eAAe,CAAC,KAAK,SAAgC,GAAG,YAAY,CAInF"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Canonicalization helpers shared by the fake server + client. Kept in their own
3
+ * module so fake.ts and fake-server.ts can both use them without a cycle.
4
+ */
5
+ import { createHash, generateKeyPairSync } from 'node:crypto';
6
+ import { Ed25519RecordSigner } from './signer.js';
7
+ /** Deterministic canonical JSON (sorted keys). */
8
+ export function stableStringify(value) {
9
+ return JSON.stringify(sortKeys(value));
10
+ }
11
+ function sortKeys(v) {
12
+ if (Array.isArray(v))
13
+ return v.map(sortKeys);
14
+ if (v && typeof v === 'object') {
15
+ return Object.fromEntries(Object.keys(v)
16
+ .sort()
17
+ .map((k) => [k, sortKeys(v[k])]));
18
+ }
19
+ return v;
20
+ }
21
+ export function sha256Hex(s) {
22
+ return createHash('sha256').update(s).digest('hex');
23
+ }
24
+ /** An ephemeral Ed25519 record signer (for the fake). */
25
+ export function ephemeralSigner(keyId = 'did:web:acp.getvda.ai#key-2') {
26
+ const { privateKey } = generateKeyPairSync('ed25519');
27
+ const pem = privateKey.export({ type: 'pkcs8', format: 'pem' });
28
+ return new Ed25519RecordSigner(pem, keyId);
29
+ }
30
+ //# sourceMappingURL=canonical.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical.js","sourceRoot":"","sources":["../src/canonical.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAqB,MAAM,aAAa,CAAC;AAErE,kDAAkD;AAClD,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AACzC,CAAC;AACD,SAAS,QAAQ,CAAC,CAAU;IAC1B,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC7C,IAAI,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,IAAI,CAAC,CAA4B,CAAC;aACtC,IAAI,EAAE;aACN,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAE,CAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAChE,CAAC;IACJ,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,CAAS;IACjC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACtD,CAAC;AAED,yDAAyD;AACzD,MAAM,UAAU,eAAe,CAAC,KAAK,GAAG,6BAA6B;IACnE,MAAM,EAAE,UAAU,EAAE,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAAC;IACtD,MAAM,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAW,CAAC;IAC1E,OAAO,IAAI,mBAAmB,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * WitnessHttpClient — the real client, customer-managed custody.
3
+ *
4
+ * Sealing is a three-step prepare → sign → submit (verified against the live
5
+ * OpenAPI, 2026-07-18):
6
+ * 1. POST /api/witness/prepare { skill, params, signingPublicKeyJwk } → { record, canonicalBytes, submit }
7
+ * 2. sign `canonicalBytes` with ACP's Ed25519 record key (#key-2)
8
+ * 3. attach the proof and POST { record } to the submit target (the seal endpoint)
9
+ *
10
+ * Because ACP signs the record itself, the record is provable even against
11
+ * Witness — the Contract-B custody model. The API key (Bearer) only authenticates
12
+ * the call; the SIGNATURE proves the record. Both come from Secret Manager at
13
+ * runtime; neither is in the tree.
14
+ *
15
+ * Requires ACP's Witness account (ANCHORED, controller-bound) — not yet
16
+ * provisioned. Until then, use FakeWitnessClient. This client is written to the
17
+ * REAL contract so the swap is a constructor change, nothing else.
18
+ */
19
+ import type { AgentActionParams, AttestationParams, HitlDecisionParams, SealedRecord, VerifyResult, WhoAmI, WitnessClient, WitnessRecord } from './types.js';
20
+ import type { RecordSigner } from './signer.js';
21
+ export type WitnessErrorCode = 'unauthorized' | 'forbidden' | 'not_found' | 'rate_limited' | 'unprocessable' | 'server_error';
22
+ export declare class WitnessError extends Error {
23
+ readonly code: WitnessErrorCode;
24
+ readonly status?: number;
25
+ constructor(code: WitnessErrorCode, message: string, status?: number);
26
+ }
27
+ export interface WitnessHttpConfig {
28
+ readonly baseUrl?: string;
29
+ /** Bearer API key (wtn.<keyId>.<secret>). Async so it can refresh from Secret Manager. */
30
+ readonly getApiKey: () => Promise<string> | string;
31
+ /** Record-signing key for customer-managed custody. */
32
+ readonly signer: RecordSigner;
33
+ readonly chainKey?: string;
34
+ readonly fetch?: typeof fetch;
35
+ /** Clock for the proof `created` timestamp. Default: real time. */
36
+ readonly now?: () => string;
37
+ }
38
+ export declare class WitnessHttpClient implements WitnessClient {
39
+ private readonly base;
40
+ private readonly getApiKey;
41
+ private readonly signer;
42
+ private readonly chainKey;
43
+ private readonly fetchImpl;
44
+ private readonly now;
45
+ constructor(config: WitnessHttpConfig);
46
+ sealHitlDecision(params: HitlDecisionParams): Promise<SealedRecord>;
47
+ sealAttestation(params: AttestationParams): Promise<SealedRecord>;
48
+ sealAgentAction(params: AgentActionParams): Promise<SealedRecord>;
49
+ /** The shared customer-managed custody path: prepare → sign → submit. */
50
+ private sealViaCustody;
51
+ whoami(): Promise<WhoAmI>;
52
+ verify(record: WitnessRecord): Promise<VerifyResult>;
53
+ private request;
54
+ }
55
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,MAAM,EACN,aAAa,EACb,aAAa,EACd,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAShD,MAAM,MAAM,gBAAgB,GAC1B,cAAc,GAAG,WAAW,GAAG,WAAW,GAAG,cAAc,GAAG,eAAe,GAAG,cAAc,CAAC;AAEjG,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;gBACb,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;CAMrE;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,0FAA0F;IAC1F,QAAQ,CAAC,SAAS,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;IACnD,uDAAuD;IACvD,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IAC9B,mEAAmE;IACnE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CAC7B;AAeD,qBAAa,iBAAkB,YAAW,aAAa;IACrD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAiC;IAC3D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAC9C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAe;IACzC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;gBAEvB,MAAM,EAAE,iBAAiB;IAS/B,gBAAgB,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;IAInE,eAAe,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC;IAIjE,eAAe,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC;IAIvE,yEAAyE;YAC3D,cAAc;IA4BtB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC;IAIzB,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;YAI5C,OAAO;CAoBtB"}
package/dist/client.js ADDED
@@ -0,0 +1,125 @@
1
+ /**
2
+ * WitnessHttpClient — the real client, customer-managed custody.
3
+ *
4
+ * Sealing is a three-step prepare → sign → submit (verified against the live
5
+ * OpenAPI, 2026-07-18):
6
+ * 1. POST /api/witness/prepare { skill, params, signingPublicKeyJwk } → { record, canonicalBytes, submit }
7
+ * 2. sign `canonicalBytes` with ACP's Ed25519 record key (#key-2)
8
+ * 3. attach the proof and POST { record } to the submit target (the seal endpoint)
9
+ *
10
+ * Because ACP signs the record itself, the record is provable even against
11
+ * Witness — the Contract-B custody model. The API key (Bearer) only authenticates
12
+ * the call; the SIGNATURE proves the record. Both come from Secret Manager at
13
+ * runtime; neither is in the tree.
14
+ *
15
+ * Requires ACP's Witness account (ANCHORED, controller-bound) — not yet
16
+ * provisioned. Until then, use FakeWitnessClient. This client is written to the
17
+ * REAL contract so the swap is a constructor change, nothing else.
18
+ */
19
+ const DEFAULT_SUBMIT = {
20
+ seal_hitl_decision: '/api/witness/seal/hitl-decision',
21
+ seal_attestation: '/api/witness/seal/attestation',
22
+ seal_agent_action: '/api/witness/seal/agent-action',
23
+ };
24
+ export class WitnessError extends Error {
25
+ code;
26
+ status;
27
+ constructor(code, message, status) {
28
+ super(message);
29
+ this.name = 'WitnessError';
30
+ this.code = code;
31
+ if (status !== undefined)
32
+ this.status = status;
33
+ }
34
+ }
35
+ const DEFAULT_BASE = 'https://witness.getvda.ai';
36
+ export class WitnessHttpClient {
37
+ base;
38
+ getApiKey;
39
+ signer;
40
+ chainKey;
41
+ fetchImpl;
42
+ now;
43
+ constructor(config) {
44
+ this.base = (config.baseUrl ?? DEFAULT_BASE).replace(/\/+$/, '');
45
+ this.getApiKey = config.getApiKey;
46
+ this.signer = config.signer;
47
+ this.chainKey = config.chainKey;
48
+ this.fetchImpl = config.fetch ?? fetch;
49
+ this.now = config.now ?? (() => new Date().toISOString());
50
+ }
51
+ async sealHitlDecision(params) {
52
+ return this.sealViaCustody('seal_hitl_decision', params);
53
+ }
54
+ async sealAttestation(params) {
55
+ return this.sealViaCustody('seal_attestation', params);
56
+ }
57
+ async sealAgentAction(params) {
58
+ return this.sealViaCustody('seal_agent_action', params);
59
+ }
60
+ /** The shared customer-managed custody path: prepare → sign → submit. */
61
+ async sealViaCustody(skill, params) {
62
+ // 1. prepare — Witness builds the unsigned record + the exact bytes to sign.
63
+ const prep = await this.request('POST', '/api/witness/prepare', {
64
+ skill,
65
+ params,
66
+ signingPublicKeyJwk: this.signer.publicKeyJwk,
67
+ ...(this.signer.keyId ? { signingKeyId: this.signer.keyId } : {}),
68
+ ...(this.chainKey ? { chainKey: this.chainKey } : {}),
69
+ });
70
+ // 2. sign the canonical bytes with ACP's record key.
71
+ const signature = await this.signer.sign(prep.canonicalBytes);
72
+ // 3. attach the proof and submit the signed record to the STRUCTURED routing
73
+ // Witness returns (`submit: { method, endpoint }`). The prose lives in
74
+ // `submitInstructions` and is never used for routing. `DEFAULT_SUBMIT` is a
75
+ // last-resort fallback only if `submit` is absent.
76
+ // proof.created must equal the record's issuedAt, not a fresh clock read.
77
+ const created = typeof prep.record.issuedAt === 'string' ? prep.record.issuedAt : this.now();
78
+ const signedRecord = {
79
+ ...prep.record,
80
+ proof: { algorithm: 'Ed25519', signature, created },
81
+ };
82
+ const endpoint = prep.submit?.endpoint ?? DEFAULT_SUBMIT[skill];
83
+ const method = prep.submit?.method ?? 'POST';
84
+ return this.request(method, endpoint, { record: signedRecord });
85
+ }
86
+ async whoami() {
87
+ return this.request('GET', '/api/witness/whoami');
88
+ }
89
+ async verify(record) {
90
+ return this.request('POST', '/api/witness/verify', { record });
91
+ }
92
+ async request(method, path, body) {
93
+ const apiKey = await this.getApiKey();
94
+ const res = await this.fetchImpl(`${this.base}${path}`, {
95
+ method,
96
+ headers: {
97
+ authorization: `Bearer ${apiKey}`,
98
+ ...(body ? { 'content-type': 'application/json' } : {}),
99
+ },
100
+ ...(body ? { body: JSON.stringify(body) } : {}),
101
+ });
102
+ if (!res.ok) {
103
+ const text = await res.text().catch(() => '');
104
+ throw new WitnessError(mapStatus(res.status), `witness ${path}: ${text || res.statusText}`, res.status);
105
+ }
106
+ return (await res.json());
107
+ }
108
+ }
109
+ function mapStatus(status) {
110
+ switch (status) {
111
+ case 401:
112
+ return 'unauthorized';
113
+ case 403:
114
+ return 'forbidden';
115
+ case 404:
116
+ return 'not_found';
117
+ case 422:
118
+ return 'unprocessable';
119
+ case 429:
120
+ return 'rate_limited';
121
+ default:
122
+ return 'server_error';
123
+ }
124
+ }
125
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAeH,MAAM,cAAc,GAAiC;IACnD,kBAAkB,EAAE,iCAAiC;IACrD,gBAAgB,EAAE,+BAA+B;IACjD,iBAAiB,EAAE,gCAAgC;CACpD,CAAC;AAKF,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,IAAI,CAAmB;IACvB,MAAM,CAAU;IACzB,YAAY,IAAsB,EAAE,OAAe,EAAE,MAAe;QAClE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,MAAM,KAAK,SAAS;YAAE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACjD,CAAC;CACF;AAcD,MAAM,YAAY,GAAG,2BAA2B,CAAC;AAajD,MAAM,OAAO,iBAAiB;IACX,IAAI,CAAS;IACb,SAAS,CAAiC;IAC1C,MAAM,CAAe;IACrB,QAAQ,CAAqB;IAC7B,SAAS,CAAe;IACxB,GAAG,CAAe;IAEnC,YAAY,MAAyB;QACnC,IAAI,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,IAAI,YAAY,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACjE,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChC,IAAI,C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kB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACxD;YACD,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChD,CAAC,CAAC;QACH,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACZ,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;YAC9C,MAAM,IAAI,YAAY,CACpB,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,EACrB,WAAW,IAAI,KAAK,IAAI,IAAI,GAAG,CAAC,UAAU,EAAE,EAC5C,GAAG,CAAC,MAAM,CACX,CAAC;QACJ,CAAC;QACD,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAM,CAAC;IACjC,CAAC;CACF;AAED,SAAS,SAAS,CAAC,MAAc;IAC/B,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,GAAG;YACN,OAAO,cAAc,CAAC;QACxB,KAAK,GAAG;YACN,OAAO,WAAW,CAAC;QACrB,KAAK,GAAG;YACN,OAAO,WAAW,CAAC;QACrB,KAAK,GAAG;YACN,OAAO,eAAe,CAAC;QACzB,KAAK,GAAG;YACN,OAAO,cAAc,CAAC;QACxB;YACE,OAAO,cAAc,CAAC;IAC1B,CAAC;AACH,CAAC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * FakeWitnessServer — a no-network Witness that speaks the REAL HTTP protocol.
3
+ *
4
+ * This is the fidelity fix: a fake that models the actual two-step
5
+ * prepare → sign → submit flow, so the REAL WitnessHttpClient can be exercised
6
+ * end-to-end against it. It is the same principle as the fake doing real signing,
7
+ * extended to the real protocol:
8
+ *
9
+ * - `prepare` returns `submit` as INSTRUCTION TEXT (exactly as real Witness
10
+ * does) — a client that mistakes it for a path will hit no route and 404.
11
+ * - the seal endpoints VERIFY the Ed25519 proof over the canonical bytes with
12
+ * the key presented at prepare, and reject a record submitted to the wrong
13
+ * record-type endpoint.
14
+ * - any unknown path 404s.
15
+ *
16
+ * That combination makes the class of bug that reached production (treating the
17
+ * `submit` field as a URL) impossible to hide in tests.
18
+ *
19
+ * Pass `.fetch` to WitnessHttpClient as its `fetch` implementation.
20
+ */
21
+ import type { WhoAmI } from './types.js';
22
+ export interface FakeWitnessServerConfig {
23
+ readonly anchored?: boolean;
24
+ readonly issuedAt?: string;
25
+ readonly account?: Partial<WhoAmI>;
26
+ }
27
+ export declare class FakeWitnessServer {
28
+ private readonly anchored;
29
+ private readonly issuedAt;
30
+ private readonly account;
31
+ private seq;
32
+ private prevHash;
33
+ private prepared;
34
+ private stored;
35
+ constructor(config?: FakeWitnessServerConfig);
36
+ /** A fetch-compatible entry point. Bind and pass to WitnessHttpClient. */
37
+ fetch: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
38
+ private prepare;
39
+ private submit;
40
+ private verify;
41
+ private readRecord;
42
+ }
43
+ //# sourceMappingURL=fake-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fake-server.d.ts","sourceRoot":"","sources":["../src/fake-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,YAAY,CAAC;AAuBxD,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;CACpC;AAED,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;IACnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,GAAG,CAAK;IAChB,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,QAAQ,CAGZ;IACJ,OAAO,CAAC,MAAM,CAAmF;gBAErF,MAAM,GAAE,uBAA4B;IAehD,0EAA0E;IAC1E,KAAK,GAAU,OAAO,MAAM,GAAG,GAAG,GAAG,OAAO,EAAE,OAAO,WAAW,KAAG,OAAO,CAAC,QAAQ,CAAC,CAelF;IAEF,OAAO,CAAC,OAAO;IA0Cf,OAAO,CAAC,MAAM;IAyBd,OAAO,CAAC,MAAM;IAUd,OAAO,CAAC,UAAU;CAUnB"}