@avow-finance/verifier 0.0.0-stage → 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.
Files changed (63) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +112 -2
  3. package/dist/accept.d.ts +170 -0
  4. package/dist/accept.d.ts.map +1 -0
  5. package/dist/accept.js +268 -0
  6. package/dist/accept.js.map +1 -0
  7. package/dist/authorization.d.ts +65 -0
  8. package/dist/authorization.d.ts.map +1 -0
  9. package/dist/authorization.js +192 -0
  10. package/dist/authorization.js.map +1 -0
  11. package/dist/chain.d.ts +160 -0
  12. package/dist/chain.d.ts.map +1 -0
  13. package/dist/chain.js +72 -0
  14. package/dist/chain.js.map +1 -0
  15. package/dist/consent.d.ts +69 -0
  16. package/dist/consent.d.ts.map +1 -0
  17. package/dist/consent.js +98 -0
  18. package/dist/consent.js.map +1 -0
  19. package/dist/dependency.d.ts +252 -0
  20. package/dist/dependency.d.ts.map +1 -0
  21. package/dist/dependency.js +353 -0
  22. package/dist/dependency.js.map +1 -0
  23. package/dist/disclosure.d.ts +88 -0
  24. package/dist/disclosure.d.ts.map +1 -0
  25. package/dist/disclosure.js +210 -0
  26. package/dist/disclosure.js.map +1 -0
  27. package/dist/index.d.ts +17 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +17 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/issued.d.ts +5 -0
  32. package/dist/issued.d.ts.map +1 -0
  33. package/dist/issued.js +24 -0
  34. package/dist/issued.js.map +1 -0
  35. package/dist/lock-abi.d.ts +471 -0
  36. package/dist/lock-abi.d.ts.map +1 -0
  37. package/dist/lock-abi.js +452 -0
  38. package/dist/lock-abi.js.map +1 -0
  39. package/dist/nonce.d.ts +3 -0
  40. package/dist/nonce.d.ts.map +1 -0
  41. package/dist/nonce.js +4 -0
  42. package/dist/nonce.js.map +1 -0
  43. package/dist/references.d.ts +38 -0
  44. package/dist/references.d.ts.map +1 -0
  45. package/dist/references.js +93 -0
  46. package/dist/references.js.map +1 -0
  47. package/dist/report.d.ts +128 -0
  48. package/dist/report.d.ts.map +1 -0
  49. package/dist/report.js +155 -0
  50. package/dist/report.js.map +1 -0
  51. package/dist/signing.d.ts +47 -0
  52. package/dist/signing.d.ts.map +1 -0
  53. package/dist/signing.js +51 -0
  54. package/dist/signing.js.map +1 -0
  55. package/dist/tempo.d.ts +70 -0
  56. package/dist/tempo.d.ts.map +1 -0
  57. package/dist/tempo.js +341 -0
  58. package/dist/tempo.js.map +1 -0
  59. package/dist/verify.d.ts +65 -0
  60. package/dist/verify.d.ts.map +1 -0
  61. package/dist/verify.js +36 -0
  62. package/dist/verify.js.map +1 -0
  63. package/package.json +34 -3
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 reasonable and customary use in describing the
141
+ origin of the Work and 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 [yyyy] [name of copyright owner]
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/README.md CHANGED
@@ -1,3 +1,113 @@
1
- # Temporary Holding Version
1
+ # @avow-finance/verifier
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
+ Lets a supplier check an Avow commitment before it grants capacity, accept it and report a charge on it, without calling Avow. It reads the signed authorization, the buyer's signed mandate, the supplier's own record of what it agreed to and the chain, and nothing else.
4
+
5
+ > **Status:** pre-release and testnet only. `tempoChainReader` reads the lock and the keychain on Tempo, and `MemoryChain` stands in for the chain in tests.
6
+
7
+ ## What it checks
8
+
9
+ `verifySupplierAuthorization` refuses with the first reason code that applies, in this order.
10
+
11
+ 1. The envelope names a message type, that type's version and a chain this code reads. The authorization hasn't expired, stays valid for no more than five minutes, and one of Avow's published keys signed it.
12
+ 2. It's for the commitment the supplier agreed to, with the terms hash the supplier signed. KYB marked as test data passes only where the supplier allows it, and only on a testnet.
13
+ 3. The supplier's terms hold nothing the terms hash leaves out, and they and the salt produce that terms hash. The terms are version 2 under a template this code knows, or version 1 for a commitment made under it. Version 3 terms are refused here, since this check doesn't read the bookings they rely on. The reserve equals the largest charge, the contest window meets the supplier's profile, and the terms name an arbiter and a day-90 share from 0 to 10,000.
14
+ 4. The token is one the supplier accepts for the terms' currency, the amount and deadlines match what the terms map to, the payee is the supplier's own payout address, and the acceptance deadline hasn't passed.
15
+ 5. On the chain, the lock comes from Avow's factory and holds a reserve for this commitment that nobody has accepted yet and that matches the authorization. Every value the lock stores and enforces is what `lockTerms` maps the supplier's terms to, and the agent's key or the account's root key funded the reserve.
16
+ 6. The agent's key is active, lasts until the release date, and carries the mandate hash Avow named, in the transaction the authorization points to.
17
+ 7. When the supplier passes the buyer's signed mandate, the mandate hashes to that value, the buyer's account signed it in Tempo's keychain envelope, and its own limits allow this reserve.
18
+ 8. The commitment hasn't passed this check before. That's recorded only after every other check passes.
19
+
20
+ It throws, rather than refusing, when the setup is wrong, such as a chain reader for another chain or test data on a chain that isn't a testnet.
21
+
22
+ ## Accepting
23
+
24
+ An acceptance binds the supplier to everything in Avow's approval, so a supplier gets one to sign only from `prepareAcceptance`, and signs it only with `signAcceptance`. `prepareAcceptance` refuses with the first reason that applies.
25
+
26
+ 1. Avow's authorization passes every check above, with the buyer's signed mandate required. It names the buyer and the mandate the supplier's own terms agreement names, and the mandate is that buyer's. A mandate that's forged, expired, revoked with its agent key, or that doesn't allow this supplier, category, currency, token or amount refuses.
27
+ 2. Avow's approval names the commitment the supplier agreed to, the supplier's own account, signing key and payout, and the token. Every field the lock enforces is what `lockTerms` maps the supplier's own terms to, the mapping Avow's API signs with, under the terms hash the supplier agreed to.
28
+ 3. It names the mandate the authorization names, that mandate's two caps, and a funding key that's the mandate's agent key or the account's root key and that funded the reserve.
29
+ 4. The lock stores the digest of exactly this approval and the same terms, and its token and dispute timing are the ones the supplier's profile accepts.
30
+
31
+ Then it builds the acceptance, which names the lock's digest of the approval and expires within ten minutes, and a disclosure for the person who approves the signature. The disclosure states the reserve and what each charge can take and from when, who receives charges, the free-cancellation and acceptance deadlines, the charge deadline and the release date, and the dispute terms: Avow's confirmation window, the contest window, how long Avow's ruling key and then the arbiter can rule, when a ruling takes effect, and the supplier's day-90 share. `signAcceptance` takes the disclosure's id back, so nothing is signed until an integration has fetched the disclosure and the person has confirmed it. It signs only the frozen object `prepareAcceptance` returned, so a copy or an edit throws, and it refuses a key other than the signing key the approval names.
32
+
33
+ ## Bookings a booking relies on
34
+
35
+ `verifyDependencies` checks the bookings version 3 terms rely on, `prepareAcceptance` runs it before anything else reads those terms, and [Checking dependencies](../../fern/docs/pages/dependency-check.mdx) says what both check and what they leave unchecked.
36
+
37
+ ## Release consents
38
+
39
+ A release consent gives the reserve back to the business, and the lock takes it only while the commitment's report count equals the count it names. It gives up the supplier's charge, a reported or confirmed one included. Nothing caps how long a consent lasts, so its disclosure states the exact expiry and how long that is from when it was prepared. `prepareReleaseConsent` reads the commitment from the lock and refuses another supplier's commitment, one the lock wouldn't release on consent, a consent that has expired, and a count the commitment has passed or can never reach. A consent for a later count than the commitment has becomes valid once reports reach it. That's preauthorization, so its disclosure says so, and `signReleaseConsent` refuses to sign it without `preauthorize: true` as well as the disclosure's id. Like `signAcceptance`, it signs only the frozen object its prepare call returned. The consent is signed by the supplier account's root key or an admin key, in Tempo's keychain envelope, and the signature is checked against the chain before it's returned.
40
+
41
+ ## Reports
42
+
43
+ A report asks the lock to charge the business's reserve, so a supplier gets one to sign only from `prepareReport`, and signs it only with `signReport`. `prepareReport` refuses a kind, commitment id, evidence hash or amount it can't read with `message.invalid`. Then it reads the commitment from the lock and refuses with the first reason that applies.
44
+
45
+ 1. The lock comes from Avow's factory (`chain.lock_unknown`) and holds the commitment (`chain.reserve_missing`) with this supplier's signing key (`chain.supplier_mismatch`).
46
+ 2. The commitment is accepted (`report.not_reportable`), no report on it is open (`report.open`), and it has fewer than two reports (`report.limit_reached`).
47
+ 3. Its terms carry a charge of the reported kind (`report.kind_not_allowed`), and the amount is above zero and within that charge's most, which is the amount when the supplier names none (`report.amount_invalid`).
48
+ 4. The time is at or after that charge's earliest (`report.too_early`) and before the charge deadline (`commitment.ended`). The lock judges both by the chain's clock, so a supplier passes the latest block's time.
49
+
50
+ Then it builds the report, which expires within ten minutes and never past the charge deadline, and a disclosure for the person who approves the signature. The disclosure states the charge and who it pays, how long Avow has to confirm or refer it, that the rest of the reserve goes back to the business once Avow answers, the contest window, the day-90 share and which of the commitment's two reports this is. The prepared report carries that number as `reportNumber`, and a supplier that keeps it can tell from the lock's report count whether the report landed, even once it's withdrawn. `signReport` takes the disclosure's id back, signs only the frozen object `prepareReport` returned, and refuses a key other than the signing key the lock holds. `reportCall` hands the signed report to the lock with exactly the fields the signature covers, which it takes from the spec's `REPORT_TYPES`. Anyone can send it, so a supplier pays the fee from whichever account it likes.
51
+
52
+ ## References and payments
53
+
54
+ `verifyCommitmentReference` checks that a commitment reference names a lock Avow's factory created and that the lock holds that commitment under the reference's terms hash. `verifyCommitmentTerms` goes further for anyone holding the terms and salt. The terms have to give that hash, the reference has to name the side the terms' backing secures, and the lock's token has to be one the caller accepts for the terms' currency. The lock then has to enforce exactly what the terms map to, in that token's units. It reads version 1 and version 2 terms, so a commitment made under version 1 stays checkable without Avow.
55
+
56
+ `verifyPaymentReference` checks a settled payment against the chain. A reference names its own token and any contract can emit an event shaped like a token's, so the caller passes the tokens it accepts, and a reference to any other token is refused before the chain is read. The Tempo reader reads the finalized block, then the receipt and the log at the reference's index. It counts the transaction as final only when its block is at or below the finalized one and is the chain's block at that height, so a receipt from a block that lost a reorg never counts. The check passes only when the transaction succeeded and is final and the log is the TIP-20 `TransferWithMemo` event that token emitted, with exactly the reference's sender, recipient, amount and memo. A plain transfer without a memo, the same event from a contract that isn't a TIP-20 token, and anything read from calldata don't count. A payment is evidence that money moved, and nothing here treats it as backing. A live test sends a payment with a memo on Moderato and checks it end to end.
57
+
58
+ ## Contests
59
+
60
+ `readBacking` reads a commitment's contest state with the rest of the lock's record. It gives whether the business has contested, the latest report's kind and amount, when a confirmed charge became pending and when the charge paused. `contestInLogs` finds a contest of one side of a commitment among a transaction's logs, from the `Paused` event the lock itself logged with a contest as its cause, and returns the reason code, the statement hash and the pause time. Any contract can log an event shaped like it, so a log from another address counts for nothing. `ChainReader.contest` reads the same from a transaction's receipt on the chain, with the contest's block, whether that block is final as `verifyPaymentReference` judges a payment's, and the report the contest named, read from the lock as of that block. It finds nothing in a transaction that failed or isn't on the chain, and throws when the node can't answer, so an outage never reads as a missing contest. A test decodes the `Paused` log a demo lock on Moderato wrote for a contest.
61
+
62
+ ## What this doesn't protect
63
+
64
+ These checks are an application-level gate. They protect a supplier that signs only what `prepareAcceptance`, `prepareReleaseConsent` and `prepareReport` return. The lock checks a signature and a digest, so it takes a correctly signed acceptance, consent or report however it was built, and a supplier whose signing tool skips this library gets none of these checks.
65
+
66
+ The checks also rest on things the verifier doesn't prove.
67
+
68
+ - **The node.** Everything read from the chain comes through the node the reader talks to, so a supplier reads through a node it chose.
69
+ - **The pinned factory.** A lock counts as Avow's only when the factory the supplier configured says it created it.
70
+ - **Avow's signature.** The authorization stands for the business's KYB, for a person's approval when the mandate asks for one, and for any revocation Avow recorded off the chain.
71
+ - **The supplier's own records.** The terms, the agreed commitment and the supplier's account, key and payout come from the supplier, so a wrong record checks the wrong terms.
72
+ - **The mandate's contents.** The supplier sees the buyer's whole mandate, including its other suppliers, categories and caps.
73
+ - **The lock after the read.** The prepare calls read the lock once. Before an acceptance lands, the reserve can still go back to the business, and the lock then refuses the acceptance, so a supplier grants capacity only once the acceptance's receipt shows it landed.
74
+ - **The person.** The disclosure is only as good as the screen that shows it. The library can make an integration fetch it, but it can't make a person read it, and code that holds the signing key can always sign without this library.
75
+
76
+ ## Use
77
+
78
+ ```ts
79
+ import { TESTNET_DEMO_PROFILE } from '@avow-finance/spec'
80
+ import { prepareAcceptance, signAcceptance, tempoChainReader } from '@avow-finance/verifier'
81
+
82
+ const chain = tempoChainReader(client, { factory: AVOW_FACTORY })
83
+ const config = {
84
+ chainId: 42431,
85
+ avowKeys: [AVOW_AUTHORIZATION_KEY],
86
+ businessId: MY_BUSINESS_ID,
87
+ payee: MY_PAYOUT_ADDRESS,
88
+ account: MY_ACCOUNT,
89
+ signingKey: MY_SIGNING_KEY_ADDRESS,
90
+ acceptedTokens: [MY_TOKEN],
91
+ profile: TESTNET_DEMO_PROFILE,
92
+ acceptTestData: true,
93
+ }
94
+ // From the terms agreement this supplier signed for the booking.
95
+ const agreed = { commitmentId, termsHash, category: 'compute', buyerBusinessId, mandateHash }
96
+ const now = BigInt(Math.floor(Date.now() / 1000))
97
+
98
+ const prepared = await prepareAcceptance(
99
+ { authorization, approval, mandate, agreed, terms, now },
100
+ { config, chain },
101
+ )
102
+ if (!prepared.ok) throw new Error(prepared.reason)
103
+
104
+ // Show every section of prepared.disclosure, and sign only once the person confirms it.
105
+ const acceptance = await signAcceptance(prepared, signingKey, {
106
+ disclosureId: prepared.disclosure.id,
107
+ })
108
+ // Send the acceptance to the lock, wait for the transaction's receipt, then grant the capacity.
109
+ ```
110
+
111
+ Accept on the lock before granting anything. Until acceptance lands, the reserve can still go back to the buyer, for example when the buyer revokes the agent or the acceptance deadline passes. Even after it lands, the business can take the whole reserve back until the free-cancellation deadline.
112
+
113
+ `verifySupplierAuthorization` passes each commitment once, so a supplier that uses it keeps the first successful result, and keeps its replay guard in a database so a restart doesn't forget which commitments have passed. `prepareAcceptance` records nothing, since the lock takes one acceptance per reserve.
@@ -0,0 +1,170 @@
1
+ import { type Acceptance, type AnyTerms, type AvowDomain, type ChainedTerms, type HashSigner, type ReasonCode, type Signed } from '@avow-finance/spec';
2
+ import { type Address, type Hex } from 'viem';
3
+ import { type Agreed } from './authorization.js';
4
+ import type { ChainReader } from './chain.js';
5
+ import { type CheckedDependency, type DependencyDeps, type DependencyRefusal } from './dependency.js';
6
+ import { type Disclosure } from './disclosure.js';
7
+ import type { VerifierConfig } from './verify.js';
8
+ /** An acceptance stays valid for ten minutes at most, and never past the acceptance deadline. */
9
+ export declare const ACCEPTANCE_VALIDITY = 600n;
10
+ export interface AcceptanceConfig extends VerifierConfig {
11
+ /** The supplier's account on the rail, which Avow's approval must name. */
12
+ account: Address;
13
+ /** The supplier's signing key, which signs the acceptance and which the approval must name. */
14
+ signingKey: Address;
15
+ }
16
+ export interface AcceptanceDeps {
17
+ config: AcceptanceConfig;
18
+ chain: ChainReader;
19
+ /**
20
+ * The chain and factory pairs whose locks a booking relied on may sit in, each with its reader.
21
+ * Version 3 terms are refused with `dependency.lock_unknown` when this is left out.
22
+ */
23
+ dependencies?: DependencyDeps;
24
+ }
25
+ /** What a supplier hands the verifier to get an acceptance to sign. */
26
+ export interface AcceptanceRequest {
27
+ /** Avow's signed supplier authorization for the commitment, as JSON. */
28
+ authorization: unknown;
29
+ /** Avow's signed approval that the reserve carried to the lock, as JSON. */
30
+ approval: unknown;
31
+ /** The buyer's signed mandate, as JSON. The acceptance path refuses without it. */
32
+ mandate: unknown;
33
+ /**
34
+ * The commitment the supplier agreed to, from the terms agreement it signed, with the buyer
35
+ * and the buyer's mandate that agreement names.
36
+ */
37
+ agreed: Required<Agreed>;
38
+ /**
39
+ * The terms this supplier agreed to for the booking, from its own records. Version 2, version 3
40
+ * in full for a booking that relies on the supplier's own bookings, or version 1 for a commitment
41
+ * made under it.
42
+ */
43
+ terms: AnyTerms | ChainedTerms;
44
+ /**
45
+ * For version 3 terms, the section of each booking they rely on that the supplier shows whoever
46
+ * checks it, as JSON, in the terms' order.
47
+ */
48
+ disclosed?: readonly unknown[];
49
+ now: bigint;
50
+ /** The acceptance's nonce, a fresh random one when left out. */
51
+ nonce?: bigint;
52
+ }
53
+ export interface ReadyAcceptance {
54
+ ok: true;
55
+ acceptance: Acceptance;
56
+ domain: AvowDomain;
57
+ /** The digest the supplier's signing key signs. */
58
+ digest: Hex;
59
+ /** The digest of Avow's approval, which the lock stored and the acceptance names. */
60
+ approvalDigest: Hex;
61
+ /** The key that has to sign, the supplier's own signing key. */
62
+ signingKey: Address;
63
+ /** What to show the person who approves the signature, before signing. */
64
+ disclosure: Disclosure;
65
+ /**
66
+ * Each booking version 3 terms rely on, with the block it was read at. Empty for a booking that
67
+ * relies on none.
68
+ */
69
+ dependencies: readonly CheckedDependency[];
70
+ }
71
+ /**
72
+ * The acceptance, or why it was refused. A refusal by the check of a booking relied on says which
73
+ * one failed and the block it was read at.
74
+ */
75
+ export type PreparedAcceptance = ReadyAcceptance | {
76
+ ok: false;
77
+ reason: ReasonCode;
78
+ } | DependencyRefusal;
79
+ /**
80
+ * The supported way for a supplier to get an acceptance to sign. An acceptance binds the supplier
81
+ * to everything in Avow's approval, so this builds one only after every check passes, and refuses
82
+ * with the first reason that applies.
83
+ *
84
+ * 0. For version 3 terms, every booking they rely on passes `verifyDependencies` first, with the
85
+ * account Avow's approval names as supplier as the one whose lock has to hold it. That holds
86
+ * whoever the terms say checks for the buyer, since the supplier has the terms in full. Nothing
87
+ * below reads them before, and the checks below confirm the lock holds exactly that approval.
88
+ * 1. Avow's authorization passes every check `verifySupplierAuthorization` makes, with the buyer's
89
+ * signed mandate required, so a mandate that's forged, expired, revoked with its agent key, or
90
+ * that doesn't allow this supplier, category, currency, token or amount refuses.
91
+ * 2. Avow's approval names the commitment the supplier agreed to, the supplier's own account,
92
+ * signing key and payout, and the token, amount, deadlines, contest window, terms hash, charges,
93
+ * day-90 share and arbiter of the supplier's own terms.
94
+ * 3. It names the mandate Avow's authorization names, that mandate's two caps, and a funding key
95
+ * that's the mandate's agent key or the account's root key and that funded the reserve.
96
+ * 4. The lock stores the digest of exactly this approval and the same terms, and its token and
97
+ * dispute timing are the ones the supplier's profile accepts.
98
+ *
99
+ * It records nothing, since the lock takes one acceptance per reserve. What it returns is frozen,
100
+ * and `signAcceptance` signs nothing else. The checks protect a supplier who signs only through
101
+ * these two calls. The lock checks the signature and the digest, so it takes a correctly signed
102
+ * acceptance however it was built.
103
+ *
104
+ * Throws when the setup is wrong or the chain can't be read, as `verifySupplierAuthorization` does.
105
+ */
106
+ export declare function prepareAcceptance(request: AcceptanceRequest, deps: AcceptanceDeps): Promise<PreparedAcceptance>;
107
+ /**
108
+ * Signs an acceptance with the supplier's signing key, once the person has seen its disclosure. It
109
+ * signs only the object `prepareAcceptance` returned, which is frozen, so a copy or an edit of it
110
+ * throws. It also throws when the confirmation names another disclosure, or when the key isn't
111
+ * the signing key Avow's approval names.
112
+ */
113
+ export declare function signAcceptance(prepared: ReadyAcceptance, key: HashSigner, confirmation: {
114
+ disclosureId: Hex;
115
+ }): Promise<Signed<Acceptance>>;
116
+ /**
117
+ * The lock's `accept`, as the testnet lock declares it. Anyone can send it, since the lock checks
118
+ * the supplier's signing key signed the acceptance, so a supplier can send it from any account
119
+ * that pays the fee.
120
+ */
121
+ export declare const ACCEPT_ABI: readonly [{
122
+ readonly type: 'function';
123
+ readonly name: 'accept';
124
+ readonly inputs: readonly [{
125
+ readonly name: 'm';
126
+ readonly type: 'tuple';
127
+ readonly components: readonly [{
128
+ readonly name: 'commitmentId';
129
+ readonly type: 'bytes32';
130
+ }, {
131
+ readonly name: 'side';
132
+ readonly type: 'uint8';
133
+ }, {
134
+ readonly name: 'approvalHash';
135
+ readonly type: 'bytes32';
136
+ }, {
137
+ readonly name: 'termsHash';
138
+ readonly type: 'bytes32';
139
+ }, {
140
+ readonly name: 'amount';
141
+ readonly type: 'uint256';
142
+ }, {
143
+ readonly name: 'token';
144
+ readonly type: 'address';
145
+ }, {
146
+ readonly name: 'acceptBy';
147
+ readonly type: 'uint64';
148
+ }, {
149
+ readonly name: 'nonce';
150
+ readonly type: 'uint256';
151
+ }, {
152
+ readonly name: 'expiry';
153
+ readonly type: 'uint64';
154
+ }];
155
+ }, {
156
+ readonly name: 'signature';
157
+ readonly type: 'bytes';
158
+ }];
159
+ readonly outputs: readonly [];
160
+ readonly stateMutability: 'nonpayable';
161
+ }];
162
+ /**
163
+ * The call that hands a signed acceptance to its lock, with the fields exactly as they were signed,
164
+ * so the lock checks the same digest the supplier's key signed.
165
+ */
166
+ export declare function acceptCall(acceptance: Signed<Acceptance>): {
167
+ to: Address;
168
+ data: Hex;
169
+ };
170
+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