@motebit/state-export-client 0.2.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,206 @@
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
95
+ Derivative 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,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Motebit, Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
203
+ "Motebit" is a trademark of Motebit, Inc. The Apache License grants rights to
204
+ this software, not to any Motebit trademarks, logos, or branding. You may not
205
+ use Motebit branding in a way that suggests endorsement or affiliation without
206
+ written permission.
package/NOTICE ADDED
@@ -0,0 +1,19 @@
1
+ Motebit
2
+ Copyright 2026 Motebit, Inc.
3
+
4
+ This product includes software developed at Motebit, Inc. (https://motebit.com).
5
+
6
+ The permissive-floor packages (the protocol, SDK, cryptographic primitives,
7
+ platform-attestation verifier leaves, scaffolding CLI, and GitHub Action) are
8
+ licensed under the Apache License, Version 2.0. See LICENSE files in each
9
+ `packages/*/` subdirectory and in `spec/` for the full license text.
10
+
11
+ The remaining packages, apps, and services are licensed under the Business
12
+ Source License 1.1 and convert to the Apache License, Version 2.0 four years
13
+ after each version's first public release. See `LICENSE` at the repository
14
+ root and `LICENSING.md` for the full license boundary.
15
+
16
+ "Motebit" is a trademark of Motebit, Inc. The licenses granted here cover
17
+ this software only, not Motebit trademarks, logos, or branding. Use of
18
+ Motebit branding in a way that suggests endorsement or affiliation requires
19
+ written permission.
package/README.md ADDED
@@ -0,0 +1,135 @@
1
+ # @motebit/state-export-client
2
+
3
+ Browser-safe verifier for motebit state-export responses. Wraps `fetch` with `X-Motebit-Content-Manifest` verification, performs trust-on-first-use bootstrap from `/.well-known/motebit-transparency.json`, and recursively verifies inner agent signatures on v1.1 execution-ledger bundles.
4
+
5
+ Apache-2.0 (permissive floor). Consumes `@motebit/crypto` + `@motebit/protocol` only. Zero new cryptographic logic; zero implicit network calls; fail-closed on every verification path.
6
+
7
+ ## Why
8
+
9
+ Every state-export endpoint in `services/relay/src/state-export.ts` emits a relay-signed `ContentArtifactManifest` in the `X-Motebit-Content-Manifest` HTTP header. Producer-side signing is invisible truth unless a consumer demands the signature. This package is that consumer — drop it into any browser app and every state-export read becomes self-attesting.
10
+
11
+ A v1.1 execution-ledger goes one layer deeper: the outer manifest is signed by the relay (witness-composition "I assembled these bytes"); the inner `signed_receipts[]` field carries byte-identical canonical JSON of each delegated motebit's own signed `ExecutionReceipt`. `verifyInnerSignedReceipts` recursively audits each one. A relay cannot fabricate inner signatures without holding the delegate motebits' private keys.
12
+
13
+ ## Quick start — verified state-export fetch (outer envelope)
14
+
15
+ ```ts
16
+ import { fetchTransparencyAnchor, verifiedStateExportFetch } from "@motebit/state-export-client";
17
+
18
+ // Once, at app boot — trust-on-first-use bootstrap.
19
+ const anchor = await fetchTransparencyAnchor("https://relay.example.com");
20
+ if (!anchor.ok) throw new Error(`anchor: ${anchor.reason}`);
21
+
22
+ // Per state-export call — wrap fetch.
23
+ const { body, verification } = await verifiedStateExportFetch(
24
+ "https://relay.example.com/api/v1/audit/MY_MOTEBIT_ID",
25
+ {
26
+ anchor: anchor.anchor,
27
+ init: { headers: { Authorization: `Bearer ${token}` } },
28
+ },
29
+ );
30
+
31
+ if (verification.valid) {
32
+ console.log("✓", verification.artifactType, verification.producerDid);
33
+ } else {
34
+ // Banner the panel; log to audit; never silently render unverified state.
35
+ console.error("✗", verification.reason);
36
+ }
37
+ ```
38
+
39
+ ## Quick start — inner-receipt recursive verification (v1.1 execution-ledger)
40
+
41
+ ```ts
42
+ import { verifiedStateExportFetch, verifyInnerSignedReceipts } from "@motebit/state-export-client";
43
+
44
+ const { body, verification } = await verifiedStateExportFetch(
45
+ `https://relay.example.com/api/v1/execution/${motebitId}/${goalId}`,
46
+ { anchor: anchor.anchor, init: { headers: { Authorization: `Bearer ${token}` } } },
47
+ );
48
+ if (!verification.valid) throw new Error(`outer: ${verification.reason}`);
49
+
50
+ const inner = await verifyInnerSignedReceipts(body);
51
+ if (inner.applicable && !inner.allValid) {
52
+ for (const r of inner.results) {
53
+ if (!r.valid) console.error(`✗ ${r.taskId} (${r.motebitId}): ${r.reason}`);
54
+ }
55
+ }
56
+ ```
57
+
58
+ `verifyInnerSignedReceipts` returns `applicable: false` for v1.0 bodies, non-execution-ledger bodies, or bodies with an empty `signed_receipts` field — calm-software default, no flag required. On v1.1 bodies, every entry is parsed, every signature is checked against its embedded public key, and `delegation_receipts` chains are walked recursively.
59
+
60
+ ## Trust-anchor chain
61
+
62
+ ```
63
+ /.well-known/motebit-transparency.json
64
+ → declaration is self-signed; signature verifies against embedded relay_public_key
65
+ → cache the key (TOFU)
66
+ → every X-Motebit-Content-Manifest verifies against the pinned key
67
+ → every inner signed_receipts[] entry verifies against its own embedded public_key
68
+ ```
69
+
70
+ The operator-transparency declaration is the trust root. The relay's identity key signs the declaration _and_ every state-export manifest, so a single TOFU bootstrap commits the relay to a specific Ed25519 key across every endpoint. Inner receipts carry their own embedded public keys signed by the delegate motebits — the relay cannot rotate those without holding the delegates' private keys.
71
+
72
+ See [`docs/doctrine/operator-transparency.md`](https://github.com/motebit/motebit/blob/main/docs/doctrine/operator-transparency.md), [`docs/doctrine/nist-alignment.md`](https://github.com/motebit/motebit/blob/main/docs/doctrine/nist-alignment.md) §8, and [`spec/execution-ledger-v1.md`](https://github.com/motebit/motebit/blob/main/spec/execution-ledger-v1.md) §4.3.
73
+
74
+ ## Onchain anchoring (Stage 2)
75
+
76
+ The transparency declaration is anchored to Solana via a Memo program transaction. `verifyDeclarationOnchainAnchor` and `lookupTransparencyAnchor` together let a verifier confirm the declaration's hash was posted onchain by the relay's identity key, closing the "operator deletes the JSON file" disappearance gap.
77
+
78
+ ```ts
79
+ import {
80
+ lookupTransparencyAnchor,
81
+ verifyDeclarationOnchainAnchor,
82
+ } from "@motebit/state-export-client";
83
+
84
+ const lookup = await lookupTransparencyAnchor({
85
+ declarationHashHex: anchor.anchor.declarationHashHex,
86
+ signerAddress: anchor.anchor.relaySolanaAddress, // optional pin
87
+ });
88
+ if (lookup.ok) {
89
+ const proof = await verifyDeclarationOnchainAnchor(declaration, lookup.anchor);
90
+ if (!proof.ok) console.error("✗", proof.reason);
91
+ }
92
+ ```
93
+
94
+ ## Programmatic surface
95
+
96
+ | Export | Kind | Role |
97
+ | ---------------------------------------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------- |
98
+ | `fetchTransparencyAnchor(baseUrl, opts?)` | function | TOFU bootstrap — fetch `/.well-known/motebit-transparency.json`, verify self-signature, return pinned `TransparencyAnchor` |
99
+ | `verifyTransparencyDeclaration(declaration)` | function | Lower-level: verify a `SignedTransparencyDeclaration` from any source (cached, archived, fixture) |
100
+ | `verifiedStateExportFetch(url, opts)` | function | Wrap `fetch` — verify outer envelope against body bytes + optional anchor pin |
101
+ | `verifyManifestAgainstBytes(manifest, bodyBytes, anchor?)` | function | Lower-level: verify a parsed `ContentArtifactManifest` against bytes you already have |
102
+ | `verifyInnerSignedReceipts(body)` | function | Recursive v1.1 inner-receipt audit — per-receipt verdict with typed failure reasons |
103
+ | `lookupTransparencyAnchor(opts)` | function | Onchain — query Solana RPC for a Memo program transaction posting the declaration hash |
104
+ | `verifyDeclarationOnchainAnchor(declaration, anchor)` | function | Onchain — verify the Memo transaction's signer and content match the declaration |
105
+ | `StateExportFetchError` | class | Thrown on non-2xx HTTP; verifier never attempts to verify error envelopes |
106
+ | `MANIFEST_HEADER` | constant | The header name (`"X-Motebit-Content-Manifest"`) — exposed for custom transports |
107
+
108
+ All result types (`TransparencyAnchorResult`, `StateExportVerification`, `InnerReceiptsVerification`, etc.) and failure-reason unions are also exported — discriminated unions, type-narrowable by the `ok` / `valid` / `applicable` field.
109
+
110
+ ## Failure reasons
111
+
112
+ Every verification path surfaces a typed reason for audit logging.
113
+
114
+ **Outer envelope** (`StateExportVerification.reason`):
115
+
116
+ - `manifest_header_missing` — response had no `X-Motebit-Content-Manifest` header
117
+ - `malformed_manifest_header` — header was not valid base64url-encoded JSON
118
+ - `content_hash_mismatch` — body bytes don't match the manifest's content_hash
119
+ - `signature_invalid` — manifest signature did not verify against the declared key
120
+ - `malformed_public_key` / `malformed_signature` / `unsupported_suite` — manifest internals
121
+ - `producer_key_mismatch` — declared key differs from the anchor's pinned key
122
+
123
+ **Inner receipts** (`InnerReceiptVerification.reason`, per-receipt):
124
+
125
+ - `malformed_json` — an entry in `signed_receipts[]` was not valid JSON
126
+ - `missing_public_key` — the parsed receipt had no `public_key` field to verify against
127
+ - `signature_invalid` — the receipt's Ed25519 signature did not verify against its embedded key
128
+ - `delegation_failed` — a nested entry in `delegation_receipts[]` failed verification
129
+ - `unknown` — wrapped crypto exception (shouldn't normally fire — surfaces opaque failures from the underlying primitive)
130
+
131
+ Non-2xx HTTP throws `StateExportFetchError` — the verifier never attempts to verify error envelopes (signing 5xx pages would be misleading provenance for a service outage).
132
+
133
+ ## License
134
+
135
+ Apache-2.0. See `LICENSE` and `NOTICE`.
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @motebit/state-export-client — verified fetch wrapper for motebit
3
+ * state-export endpoints. Closes the producer-consumer asymmetry that
4
+ * the state-export-signing arc opened: every endpoint in
5
+ * `services/relay/src/state-export.ts` emits a `ContentArtifactManifest`
6
+ * in the `X-Motebit-Content-Manifest` HTTP header; consumers wrap
7
+ * `fetch` through this package to verify each manifest against the
8
+ * response body and (optionally) pin the signer against an anchor from
9
+ * `/.well-known/motebit-transparency.json`.
10
+ *
11
+ * Apache-2.0 permissive floor; browser-safe; consumes `@motebit/crypto`
12
+ * and `@motebit/protocol` only. No network at module-load time, no
13
+ * implicit fetches — the caller controls every round-trip.
14
+ *
15
+ * Programmatic shape:
16
+ *
17
+ * ```ts
18
+ * import {
19
+ * fetchTransparencyAnchor,
20
+ * verifiedStateExportFetch,
21
+ * } from "@motebit/state-export-client";
22
+ *
23
+ * // Once, at app boot — TOFU bootstrap.
24
+ * const result = await fetchTransparencyAnchor("https://relay.example.com");
25
+ * if (!result.ok) throw new Error(`anchor: ${result.reason}`);
26
+ *
27
+ * // Per state-export call — wrap fetch.
28
+ * const { body, verification } = await verifiedStateExportFetch<AuditResponse>(
29
+ * `${baseUrl}/api/v1/audit/${motebitId}`,
30
+ * {
31
+ * anchor: result.anchor,
32
+ * init: { headers: { Authorization: `Bearer ${token}` } },
33
+ * },
34
+ * );
35
+ *
36
+ * if (!verification.valid) {
37
+ * // Banner the inspector panel; log to audit.
38
+ * showTamperBadge(verification.reason);
39
+ * }
40
+ * ```
41
+ *
42
+ * Doctrine: `docs/doctrine/nist-alignment.md` §8, `docs/doctrine/self-attesting-system.md`,
43
+ * `docs/doctrine/operator-transparency.md`.
44
+ */
45
+ export { fetchTransparencyAnchor, verifyTransparencyDeclaration } from "./transparency-anchor.js";
46
+ export type { TransparencyAnchor, SignedTransparencyDeclaration, TransparencyAnchorResult, TransparencyAnchorFailureReason, FetchTransparencyAnchorOptions, } from "./transparency-anchor.js";
47
+ export { verifiedStateExportFetch, verifyManifestAgainstBytes, StateExportFetchError, MANIFEST_HEADER, } from "./verified-fetch.js";
48
+ export type { StateExportVerification, StateExportVerificationFailureReason, VerifiedFetchOptions, VerifiedStateExportResponse, } from "./verified-fetch.js";
49
+ export { lookupTransparencyAnchor, verifyDeclarationOnchainAnchor } from "./onchain-anchor.js";
50
+ export type { OnchainAnchorLookupOptions, OnchainAnchorResult, OnchainAnchorFailureReason, } from "./onchain-anchor.js";
51
+ export { verifyInnerSignedReceipts } from "./inner-receipts.js";
52
+ export type { InnerReceiptVerification, InnerReceiptVerificationFailureReason, InnerReceiptsVerification, } from "./inner-receipts.js";
53
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,EAAE,uBAAuB,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AAClG,YAAY,EACV,kBAAkB,EAClB,6BAA6B,EAC7B,wBAAwB,EACxB,+BAA+B,EAC/B,8BAA8B,GAC/B,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,wBAAwB,EACxB,0BAA0B,EAC1B,qBAAqB,EACrB,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,uBAAuB,EACvB,oCAAoC,EACpC,oBAAoB,EACpB,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,wBAAwB,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AAC/F,YAAY,EACV,0BAA0B,EAC1B,mBAAmB,EACnB,0BAA0B,GAC3B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,YAAY,EACV,wBAAwB,EACxB,qCAAqC,EACrC,yBAAyB,GAC1B,MAAM,qBAAqB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @motebit/state-export-client — verified fetch wrapper for motebit
3
+ * state-export endpoints. Closes the producer-consumer asymmetry that
4
+ * the state-export-signing arc opened: every endpoint in
5
+ * `services/relay/src/state-export.ts` emits a `ContentArtifactManifest`
6
+ * in the `X-Motebit-Content-Manifest` HTTP header; consumers wrap
7
+ * `fetch` through this package to verify each manifest against the
8
+ * response body and (optionally) pin the signer against an anchor from
9
+ * `/.well-known/motebit-transparency.json`.
10
+ *
11
+ * Apache-2.0 permissive floor; browser-safe; consumes `@motebit/crypto`
12
+ * and `@motebit/protocol` only. No network at module-load time, no
13
+ * implicit fetches — the caller controls every round-trip.
14
+ *
15
+ * Programmatic shape:
16
+ *
17
+ * ```ts
18
+ * import {
19
+ * fetchTransparencyAnchor,
20
+ * verifiedStateExportFetch,
21
+ * } from "@motebit/state-export-client";
22
+ *
23
+ * // Once, at app boot — TOFU bootstrap.
24
+ * const result = await fetchTransparencyAnchor("https://relay.example.com");
25
+ * if (!result.ok) throw new Error(`anchor: ${result.reason}`);
26
+ *
27
+ * // Per state-export call — wrap fetch.
28
+ * const { body, verification } = await verifiedStateExportFetch<AuditResponse>(
29
+ * `${baseUrl}/api/v1/audit/${motebitId}`,
30
+ * {
31
+ * anchor: result.anchor,
32
+ * init: { headers: { Authorization: `Bearer ${token}` } },
33
+ * },
34
+ * );
35
+ *
36
+ * if (!verification.valid) {
37
+ * // Banner the inspector panel; log to audit.
38
+ * showTamperBadge(verification.reason);
39
+ * }
40
+ * ```
41
+ *
42
+ * Doctrine: `docs/doctrine/nist-alignment.md` §8, `docs/doctrine/self-attesting-system.md`,
43
+ * `docs/doctrine/operator-transparency.md`.
44
+ */
45
+ export { fetchTransparencyAnchor, verifyTransparencyDeclaration } from "./transparency-anchor.js";
46
+ export { verifiedStateExportFetch, verifyManifestAgainstBytes, StateExportFetchError, MANIFEST_HEADER, } from "./verified-fetch.js";
47
+ export { lookupTransparencyAnchor, verifyDeclarationOnchainAnchor } from "./onchain-anchor.js";
48
+ export { verifyInnerSignedReceipts } from "./inner-receipts.js";
49
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,EAAE,uBAAuB,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AASlG,OAAO,EACL,wBAAwB,EACxB,0BAA0B,EAC1B,qBAAqB,EACrB,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAQ7B,OAAO,EAAE,wBAAwB,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AAO/F,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Recursive verification for v1.1 inner signed receipts.
3
+ *
4
+ * The relay-assembled execution-ledger reconstruction at
5
+ * `/api/v1/execution/:motebitId/:goalId` carries the v1.1 optional
6
+ * `signed_receipts: string[]` field — byte-identical canonical-JSON of
7
+ * each delegated motebit's signed `ExecutionReceipt`, sourced from the
8
+ * relay's `relay_receipts.receipt_json` archive (per
9
+ * `services/relay/CLAUDE.md` Rule 11). The wire shape and rationale
10
+ * live in `spec/execution-ledger-v1.md` §4.3 (Inner Signed Receipts —
11
+ * v1.1 additive).
12
+ *
13
+ * Without recursive verification, the v1.1 wire change is invisible
14
+ * truth: the verifier sees the field but does nothing with it. This
15
+ * module closes the consumer-side asymmetry. Each receipt is parsed
16
+ * back into its `ExecutionReceipt` shape, passed to
17
+ * `verifyReceipt` from `@motebit/crypto`, and its Ed25519 signature
18
+ * checked against the embedded `public_key` independently of the
19
+ * relay. Multi-hop delegation chains are walked recursively.
20
+ *
21
+ * Doctrine: `docs/doctrine/nist-alignment.md` §8 "Inner-receipt
22
+ * verification closed"; `docs/doctrine/self-attesting-system.md`.
23
+ */
24
+ /** Per-receipt verification outcome surfaced to UI / audit logging. */
25
+ export interface InnerReceiptVerification {
26
+ /** Task identifier of the inner receipt. Pulled from the parsed receipt body. */
27
+ readonly taskId: string;
28
+ /** The producing motebit's identifier — what the relay claims; the signature proves it. */
29
+ readonly motebitId: string;
30
+ /** `did:key:zXXX` derived from the receipt's embedded public key when verification succeeded. */
31
+ readonly signerDid?: string;
32
+ /** Whether the inner receipt's signature verifies against its embedded `public_key`. */
33
+ readonly valid: boolean;
34
+ /** Typed failure reason when `valid === false`. */
35
+ readonly reason?: InnerReceiptVerificationFailureReason;
36
+ /** Free-form detail (e.g. underlying error message). */
37
+ readonly detail?: string;
38
+ /** Nested delegations verified recursively. Present when the receipt carries `delegation_receipts`. */
39
+ readonly delegations?: InnerReceiptVerification[];
40
+ }
41
+ export type InnerReceiptVerificationFailureReason = "malformed_json" | "missing_public_key" | "signature_invalid" | "delegation_failed" | "unknown";
42
+ /** Aggregate result for the whole `signed_receipts` array on a v1.1 ledger body. */
43
+ export interface InnerReceiptsVerification {
44
+ /** True only when every entry's outer signature + every nested delegation verifies. */
45
+ readonly allValid: boolean;
46
+ /** Number of top-level entries successfully verified. */
47
+ readonly verifiedCount: number;
48
+ /** Number of top-level entries inspected (`signed_receipts.length` when the field is present). */
49
+ readonly totalCount: number;
50
+ /** Per-receipt outcomes, ordered as `signed_receipts` appeared on the wire. */
51
+ readonly results: ReadonlyArray<InnerReceiptVerification>;
52
+ /** True when the body declared a v1.1 spec and carried a non-empty `signed_receipts` array. */
53
+ readonly applicable: boolean;
54
+ }
55
+ /**
56
+ * Verify the inner signed receipts inside an execution-ledger response
57
+ * body. Idempotent + side-effect-free; no network calls beyond what
58
+ * `verifyReceipt` performs (which itself is offline — every receipt
59
+ * carries its own `public_key`).
60
+ *
61
+ * Returns `{ applicable: false }` for v1.0 bodies, bodies without
62
+ * `signed_receipts`, or bodies that aren't execution-ledger shape.
63
+ * Returns `{ applicable: true, allValid, ... }` with per-receipt
64
+ * outcomes for v1.1 bodies that carry the field.
65
+ */
66
+ export declare function verifyInnerSignedReceipts(body: unknown): Promise<InnerReceiptsVerification>;
67
+ //# sourceMappingURL=inner-receipts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inner-receipts.d.ts","sourceRoot":"","sources":["../src/inner-receipts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAMH,uEAAuE;AACvE,MAAM,WAAW,wBAAwB;IACvC,iFAAiF;IACjF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,2FAA2F;IAC3F,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,iGAAiG;IACjG,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,wFAAwF;IACxF,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,mDAAmD;IACnD,QAAQ,CAAC,MAAM,CAAC,EAAE,qCAAqC,CAAC;IACxD,wDAAwD;IACxD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,uGAAuG;IACvG,QAAQ,CAAC,WAAW,CAAC,EAAE,wBAAwB,EAAE,CAAC;CACnD;AAED,MAAM,MAAM,qCAAqC,GAC7C,gBAAgB,GAChB,oBAAoB,GACpB,mBAAmB,GACnB,mBAAmB,GACnB,SAAS,CAAC;AAEd,oFAAoF;AACpF,MAAM,WAAW,yBAAyB;IACxC,uFAAuF;IACvF,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,yDAAyD;IACzD,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,kGAAkG;IAClG,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,+EAA+E;IAC/E,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,wBAAwB,CAAC,CAAC;IAC1D,+FAA+F;IAC/F,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAC9B;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,yBAAyB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAkCjG"}