@bolyra/receipts 0.11.0 → 0.12.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,201 @@
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 accept and charge a
167
+ fee for the acceptance of support, warranty, indemnity, or other
168
+ liability obligations and/or rights consistent with this License.
169
+ However, in accepting such obligations, You may act only on Your
170
+ own behalf and on Your sole responsibility, not on behalf of any
171
+ other Contributor, and only if You agree to indemnify, defend,
172
+ and hold each Contributor harmless for any liability incurred by,
173
+ or claims asserted against, such Contributor by reason of your
174
+ 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 Viswanadha Pratap Kondoju
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.
package/NOTICE ADDED
@@ -0,0 +1,121 @@
1
+ Bolyra
2
+ Copyright 2026 ZKProva Inc. and the Bolyra contributors.
3
+
4
+ This product includes software developed by ZKProva Inc.
5
+ (https://bolyra.ai).
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License").
8
+ See the LICENSE file at the repository root, or
9
+ https://www.apache.org/licenses/LICENSE-2.0, for the full license text.
10
+
11
+ ================================================================================
12
+ THIRD-PARTY ATTRIBUTIONS
13
+ ================================================================================
14
+
15
+ This product includes, depends on, or is derived from the following third-party
16
+ works. Each is distributed under its own license; the corresponding LICENSE
17
+ files are reproduced or referenced in the dependency tree (node_modules,
18
+ site-packages) at install time.
19
+
20
+ ----------------------------------------
21
+ Cryptography and Zero-Knowledge Proofs
22
+ ----------------------------------------
23
+
24
+ circom (https://github.com/iden3/circom)
25
+ Copyright (c) iden3. Licensed under GPL-3.0.
26
+ NOTE: circom is the compiler. The compiled circuits in this repository
27
+ (circuits/build/*.r1cs, *.wasm, *.zkey) are project artifacts of Bolyra
28
+ and are not encumbered by circom's GPL-3.0 — Section 7 of GPL-3.0 and
29
+ iden3's published clarification confirm that circuits compiled by circom
30
+ are not derivative works of circom itself.
31
+
32
+ circomlib (https://github.com/iden3/circomlib)
33
+ circomlibjs (https://github.com/iden3/circomlibjs)
34
+ Copyright (c) iden3. Licensed under GPL-3.0.
35
+ Used as Circom-language template libraries (Poseidon, EdDSA, Baby Jubjub,
36
+ SMT). Same Section 7 reasoning as circom.
37
+
38
+ snarkjs (https://github.com/iden3/snarkjs)
39
+ Copyright (c) iden3. Licensed under GPL-3.0.
40
+ Used as a development/testing prover only. Production proving uses the
41
+ rapidsnark binary (see below). Distribution paths that ship snarkjs
42
+ reproduce its license verbatim.
43
+
44
+ rapidsnark (https://github.com/iden3/rapidsnark)
45
+ Copyright (c) iden3. Licensed under GPL-3.0.
46
+ Native prover binary; redistributed at circuits/build/rapidsnark_prover
47
+ on supported platforms. Not statically linked into Bolyra source.
48
+
49
+ Semaphore Protocol (https://github.com/semaphoreprotocol/semaphore)
50
+ Copyright (c) PSE / Ethereum Foundation. Licensed under MIT.
51
+ @semaphore-protocol/circuits, @semaphore-protocol/contracts,
52
+ @semaphore-protocol/core. The HumanUniqueness circuit reuses the
53
+ Semaphore v4 trusted-setup ceremony at depth 20 (per its public terms).
54
+
55
+ poseidon-solidity (https://github.com/chancehudson/poseidon-solidity)
56
+ Copyright (c) Chance Hudson. Licensed under MIT.
57
+ Solidity implementation of the Poseidon hash family.
58
+
59
+ ----------------------------------------
60
+ Smart Contracts
61
+ ----------------------------------------
62
+
63
+ OpenZeppelin Contracts (https://github.com/OpenZeppelin/openzeppelin-contracts)
64
+ Copyright (c) OpenZeppelin. Licensed under MIT.
65
+
66
+ Hardhat (https://hardhat.org)
67
+ Copyright (c) Nomic Foundation. Licensed under MIT.
68
+
69
+ ----------------------------------------
70
+ JavaScript / TypeScript
71
+ ----------------------------------------
72
+
73
+ ethers.js (https://github.com/ethers-io/ethers.js)
74
+ Copyright (c) Richard Moore and contributors. Licensed under MIT.
75
+
76
+ jose (https://github.com/panva/jose)
77
+ Copyright (c) Filip Skokan. Licensed under MIT.
78
+
79
+ TypeScript (https://github.com/microsoft/TypeScript)
80
+ Copyright (c) Microsoft Corporation. Licensed under Apache-2.0.
81
+
82
+ mocha, chai, jest, ts-jest, circom_tester (test tooling)
83
+ Copyright (c) respective authors. Licensed under MIT.
84
+
85
+ dotenv
86
+ Copyright (c) Scott Motte. Licensed under BSD-2-Clause.
87
+
88
+ ----------------------------------------
89
+ Python
90
+ ----------------------------------------
91
+
92
+ pytest, ruff (development tooling)
93
+ Copyright (c) respective authors. Licensed under MIT.
94
+
95
+ ================================================================================
96
+ TRADEMARK NOTICE
97
+ ================================================================================
98
+
99
+ "Bolyra" and the Bolyra wordmark are trademarks of ZKProva Inc.
100
+
101
+ References to "Anthropic", "OpenAI", "GPT", and other model-provider names
102
+ within examples (e.g., examples/provider-mock/) are included for illustrative
103
+ purposes only and do not imply endorsement, partnership, or licensing
104
+ relationship with the named entity. Mock provider keys in the test fixtures
105
+ are explicitly labeled "MOCK ONLY — NOT A REAL <PROVIDER> KEY".
106
+
107
+ ================================================================================
108
+ PATENT NOTICE
109
+ ================================================================================
110
+
111
+ Apache License 2.0 includes an express patent grant from contributors (§3).
112
+ By contributing to this repository under the Developer Certificate of Origin
113
+ sign-off, contributors grant the patent license described in §3 of the
114
+ Apache License 2.0 to all downstream users of the contribution.
115
+
116
+ ZKProva Inc. has filed United States provisional patent applications covering
117
+ inventions implemented in this repository. The patent grant in Apache-2.0 §3
118
+ applies to ZKProva Inc.'s contributions; downstream users of this software
119
+ under the Apache-2.0 license receive that patent license. ZKProva Inc.'s
120
+ own patent rights against parties who do NOT comply with the Apache-2.0
121
+ license terms are unaffected by that grant.
package/README.md CHANGED
@@ -100,6 +100,121 @@ CLI: `bolyra receipt verify-chain audit-log.jsonl` (from
100
100
  file, with `--signer`, `--expect-count`, `--expect-head`, and
101
101
  `--allow-unchained`.
102
102
 
103
+ ## Approval-to-execution binding
104
+
105
+ Gateways that hold an agent's tool call for human approval usually scope the resulting grant to the
106
+ requester, the server and the tool. This module binds an approval to the **exact arguments** and links
107
+ the execution back to it, with evidence a reviewer can verify offline. No Bolyra gateway is needed in
108
+ the request path; the operator keeps its approval UI, policy, runtime, keys and storage.
109
+
110
+ Three steps:
111
+
112
+ ```typescript
113
+ import {
114
+ createApprovalReceipt, executeApproved, verifyApprovalExecutionLink, ApprovedExecutionError,
115
+ } from '@bolyra/receipts';
116
+
117
+ // 1. When the approval source reports a decision, bind it to the reviewed action.
118
+ const argumentsJson = JSON.stringify({ orderId: 'o-1001', amount: 40 });
119
+ const context = { requester: 'agent:refunds-bot', audience: 'crm.example', tool: 'refund.issue', operationId: 'op-7f3a' };
120
+ const approval = createApprovalReceipt(
121
+ {
122
+ binding: context,
123
+ approval: {
124
+ approver: 'ops-lead@example', source: 'gateway:acme', decision: 'approved',
125
+ decidedAt: '2026-10-25T18:00:00.000Z', validity: { kind: 'once' },
126
+ },
127
+ argumentsJson,
128
+ },
129
+ { issuer: 'https://approvals.example', keyId: 'k1', privateKey: process.env.APPROVAL_KEY! },
130
+ );
131
+
132
+ // 2. Immediately before dispatch, re-verify and dispatch only the checked snapshot.
133
+ const result = await executeApproved(
134
+ {
135
+ receipt: approval,
136
+ expectedSigner: '0xApprovalSignerAddress', // obtained out of band, never read from the receipt
137
+ context,
138
+ argumentsJson, // the arguments you are about to send
139
+ attemptId: 'attempt-1',
140
+ consume: (claim) => replayStore.consumeOnce(claim), // operator-owned, atomic, durable
141
+ observer: { issuer: 'https://executor.example', keyId: 'x1', privateKey: process.env.EXEC_KEY! },
142
+ },
143
+ (snapshot, checkedContext) => crm.issueRefund(checkedContext.audience, snapshot),
144
+ );
145
+ // result.outcome: 'blocked' (dispatch never called; result.code says why)
146
+ // or 'returned' (result.value + result.observation)
147
+ // A throwing dispatch rejects with ApprovedExecutionError { cause, observation? }.
148
+
149
+ // 3. Later, a reviewer verifies the pair offline.
150
+ if (result.outcome === 'returned' && result.observation) {
151
+ const link = verifyApprovalExecutionLink({
152
+ approval,
153
+ observation: result.observation,
154
+ expectedApprovalSigner: '0xApprovalSignerAddress',
155
+ expectedExecutionSigner: '0xExecutionSignerAddress',
156
+ });
157
+ // link.ok, link.checks (A1..L4), link.statement
158
+ }
159
+ ```
160
+
161
+ What a blocked result means: the approval receipt failed closed on one of the typed codes
162
+ (`signature_invalid`, `untrusted_signer`, `decision_not_approved`, `expired`, `future_decision`,
163
+ `context_mismatch`, `arguments_mismatch`, `consume_required`, `consume_rejected`, …) and `dispatch`
164
+ was never called.
165
+
166
+ **Argument domain (`bab1`).** Arguments enter only as immutable JSON text (`argumentsJson`); there is no
167
+ API that accepts an arbitrary JavaScript value. The text is parsed once, validated and deep-frozen, and
168
+ that frozen tree is what is digested and what `dispatch` receives. The digest is `sha256(utf8("bolyra.approval.arguments/1") || 0x00 || utf8(canonicalize(value)))`
169
+ over a JSON object whose values are objects, arrays, strings, finite numbers, booleans or null. Keys named
170
+ `__proto__`, `constructor` or `prototype`, negative zero, and non-finite numbers (`1e400` parses to
171
+ `Infinity`) are rejected by the validator; cycles, sparse arrays, accessors, proxies, symbols and custom
172
+ prototypes are unrepresentable through JSON ingress rather than detected at runtime. Limits: text and
173
+ canonical form at most 1 MiB each, depth at most 64. Numbers and non-ASCII strings follow `JSON.stringify`, not RFC 8785; both
174
+ sides must use this library's `computeArgumentsDigest`. The receipt carries the digest only, never the
175
+ arguments.
176
+
177
+ **Ordered checks and limits.** `executeApproved` captures every parameter once at entry (receipt,
178
+ context and arguments are cloned, parsed and deep-frozen; the observer config is cloned; callbacks are
179
+ captured as bare functions, never re-read), preflights the observer key before anything is consumed, validates the receipt's closed schema
180
+ and signature against `expectedSigner`, compares the full context and the argument digest, samples the
181
+ clock (`t0`: the decision must not be in the future, an `until` receipt must not have expired), consumes
182
+ (`once` only, synchronously), samples the clock again (`td`, same checks) and only then calls `dispatch`
183
+ with the frozen snapshot, awaiting settlement. Arguments: JSON text at most 1 MiB, canonical form at
184
+ most 1 MiB, nesting depth at most 64. Duplicate JSON keys collapse last-wins before digesting: the
185
+ binding covers the parsed JavaScript value, so an approval display must render that same interpretation.
186
+ Observations are optional (`observer`); a signing failure after dispatch is returned as
187
+ `observationError` beside the `returned` value (or inside `ApprovedExecutionError`) and never retries the
188
+ dispatch.
189
+
190
+ **Operator-owned interfaces.** `consume({ signer, payloadHash, operationId })` must store the claim
191
+ atomically and durably, namespaced by the recovered signer, across every executor; only the literal
192
+ `true` permits dispatch, and a consumed-then-blocked operation is never released. `until` receipts permit
193
+ repeats; reconciling repeated operations is the operator's job. Business-state checks (is the order still
194
+ refundable?) belong to the operator and must be made atomically with the mutation: the receipt cannot
195
+ know whether the approved operation already produced its effect.
196
+
197
+ **What this does not claim.** Universal compatibility with any gateway; verified human identity because
198
+ a name was signed; authorization correctness; downstream commitment from dispatch; exactly-once
199
+ execution; protection against bypassing the hook; complete logs without completeness anchors; live
200
+ vendor integration; compliance certification. Imported approval metadata cannot establish which
201
+ arguments a human actually reviewed; the receipt records what the operator asserted was reviewed. An
202
+ offline PASS establishes signed assertions and their linkage only: not human review, actual dispatch,
203
+ consumption, response success, business-state freshness or committed effect.
204
+
205
+ TypeScript compatibility: ordinary legacy calls, the default `SignedReceipt`
206
+ payload, and legacy `ReturnType`/`Parameters` inference are preserved. Added
207
+ overloads can require changes to legacy-only mocks or wrappers annotated with
208
+ `typeof verifyReceipt`. Type those wrappers explicitly as
209
+ `(receipt: SignedReceipt, expectedSigner?: string) => boolean`.
210
+ Legacy receipt, hash and signature bytes are unchanged.
211
+
212
+ Runnable [synthetic-key example](https://github.com/bolyra/bolyra/blob/2e505cdc/integrations/receipts/examples/approval-binding.ts):
213
+ from a repository checkout, run `npm ci` and then
214
+ `npx tsx examples/approval-binding.ts` in `integrations/receipts/`.
215
+ The example is not included in the npm package.
216
+ [Design](https://github.com/bolyra/bolyra/blob/2e505cdc/docs/superpowers/specs/2026-10-25-approval-binding-design.md).
217
+
103
218
  ## License
104
219
 
105
220
  Apache-2.0