@avow-finance/spec 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +119 -2
- package/dist/agent-connect.d.ts +82 -0
- package/dist/agent-connect.d.ts.map +1 -0
- package/dist/agent-connect.js +91 -0
- package/dist/agent-connect.js.map +1 -0
- package/dist/agent-session.d.ts +791 -0
- package/dist/agent-session.d.ts.map +1 -0
- package/dist/agent-session.js +176 -0
- package/dist/agent-session.js.map +1 -0
- package/dist/ap2.d.ts +79 -0
- package/dist/ap2.d.ts.map +1 -0
- package/dist/ap2.js +151 -0
- package/dist/ap2.js.map +1 -0
- package/dist/api-request.d.ts +144 -0
- package/dist/api-request.d.ts.map +1 -0
- package/dist/api-request.js +246 -0
- package/dist/api-request.js.map +1 -0
- package/dist/api.d.ts +288 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +332 -0
- package/dist/api.js.map +1 -0
- package/dist/canonical.d.ts +22 -0
- package/dist/canonical.d.ts.map +1 -0
- package/dist/canonical.js +66 -0
- package/dist/canonical.js.map +1 -0
- package/dist/commitment-card.d.ts +78 -0
- package/dist/commitment-card.d.ts.map +1 -0
- package/dist/commitment-card.js +224 -0
- package/dist/commitment-card.js.map +1 -0
- package/dist/commitment.d.ts +185 -0
- package/dist/commitment.d.ts.map +1 -0
- package/dist/commitment.js +148 -0
- package/dist/commitment.js.map +1 -0
- package/dist/compute-offers.d.ts +128 -0
- package/dist/compute-offers.d.ts.map +1 -0
- package/dist/compute-offers.js +111 -0
- package/dist/compute-offers.js.map +1 -0
- package/dist/contest.d.ts +88 -0
- package/dist/contest.d.ts.map +1 -0
- package/dist/contest.js +131 -0
- package/dist/contest.js.map +1 -0
- package/dist/demo.d.ts +69 -0
- package/dist/demo.d.ts.map +1 -0
- package/dist/demo.js +152 -0
- package/dist/demo.js.map +1 -0
- package/dist/dependencies.d.ts +308 -0
- package/dist/dependencies.d.ts.map +1 -0
- package/dist/dependencies.js +133 -0
- package/dist/dependencies.js.map +1 -0
- package/dist/eip712.d.ts +1569 -0
- package/dist/eip712.d.ts.map +1 -0
- package/dist/eip712.js +550 -0
- package/dist/eip712.js.map +1 -0
- package/dist/elided-terms.d.ts +37 -0
- package/dist/elided-terms.d.ts.map +1 -0
- package/dist/elided-terms.js +48 -0
- package/dist/elided-terms.js.map +1 -0
- package/dist/erc8183.d.ts +78 -0
- package/dist/erc8183.d.ts.map +1 -0
- package/dist/erc8183.js +88 -0
- package/dist/erc8183.js.map +1 -0
- package/dist/facts.d.ts +70 -0
- package/dist/facts.d.ts.map +1 -0
- package/dist/facts.js +33 -0
- package/dist/facts.js.map +1 -0
- package/dist/gpu-reservation.d.ts +79 -0
- package/dist/gpu-reservation.d.ts.map +1 -0
- package/dist/gpu-reservation.js +135 -0
- package/dist/gpu-reservation.js.map +1 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/job-session.d.ts +981 -0
- package/dist/job-session.d.ts.map +1 -0
- package/dist/job-session.js +170 -0
- package/dist/job-session.js.map +1 -0
- package/dist/job-verification.d.ts +244 -0
- package/dist/job-verification.d.ts.map +1 -0
- package/dist/job-verification.js +89 -0
- package/dist/job-verification.js.map +1 -0
- package/dist/job-wording.d.ts +48 -0
- package/dist/job-wording.d.ts.map +1 -0
- package/dist/job-wording.js +134 -0
- package/dist/job-wording.js.map +1 -0
- package/dist/job.d.ts +117 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +166 -0
- package/dist/job.js.map +1 -0
- package/dist/json-fields.d.ts +13 -0
- package/dist/json-fields.d.ts.map +1 -0
- package/dist/json-fields.js +30 -0
- package/dist/json-fields.js.map +1 -0
- package/dist/keychain.d.ts +51 -0
- package/dist/keychain.d.ts.map +1 -0
- package/dist/keychain.js +133 -0
- package/dist/keychain.js.map +1 -0
- package/dist/mailbox.d.ts +1650 -0
- package/dist/mailbox.d.ts.map +1 -0
- package/dist/mailbox.js +87 -0
- package/dist/mailbox.js.map +1 -0
- package/dist/mandate.d.ts +53 -0
- package/dist/mandate.d.ts.map +1 -0
- package/dist/mandate.js +97 -0
- package/dist/mandate.js.map +1 -0
- package/dist/networks.d.ts +18 -0
- package/dist/networks.d.ts.map +1 -0
- package/dist/networks.js +24 -0
- package/dist/networks.js.map +1 -0
- package/dist/profiles.d.ts +31 -0
- package/dist/profiles.d.ts.map +1 -0
- package/dist/profiles.js +33 -0
- package/dist/profiles.js.map +1 -0
- package/dist/rail.d.ts +48 -0
- package/dist/rail.d.ts.map +1 -0
- package/dist/rail.js +28 -0
- package/dist/rail.js.map +1 -0
- package/dist/reasons.d.ts +173 -0
- package/dist/reasons.d.ts.map +1 -0
- package/dist/reasons.js +174 -0
- package/dist/reasons.js.map +1 -0
- package/dist/reference-link.d.ts +23 -0
- package/dist/reference-link.d.ts.map +1 -0
- package/dist/reference-link.js +56 -0
- package/dist/reference-link.js.map +1 -0
- package/dist/references.d.ts +125 -0
- package/dist/references.d.ts.map +1 -0
- package/dist/references.js +108 -0
- package/dist/references.js.map +1 -0
- package/dist/replay.d.ts +30 -0
- package/dist/replay.d.ts.map +1 -0
- package/dist/replay.js +27 -0
- package/dist/replay.js.map +1 -0
- package/dist/sandbox-registration.d.ts +200 -0
- package/dist/sandbox-registration.d.ts.map +1 -0
- package/dist/sandbox-registration.js +172 -0
- package/dist/sandbox-registration.js.map +1 -0
- package/dist/sandbox.d.ts +3478 -0
- package/dist/sandbox.d.ts.map +1 -0
- package/dist/sandbox.js +316 -0
- package/dist/sandbox.js.map +1 -0
- package/dist/session-fields.d.ts +203 -0
- package/dist/session-fields.d.ts.map +1 -0
- package/dist/session-fields.js +43 -0
- package/dist/session-fields.js.map +1 -0
- package/dist/supplier-adapter.d.ts +65 -0
- package/dist/supplier-adapter.d.ts.map +1 -0
- package/dist/supplier-adapter.js +91 -0
- package/dist/supplier-adapter.js.map +1 -0
- package/dist/terms-v1.d.ts +74 -0
- package/dist/terms-v1.d.ts.map +1 -0
- package/dist/terms-v1.js +156 -0
- package/dist/terms-v1.js.map +1 -0
- package/dist/terms.d.ts +341 -0
- package/dist/terms.d.ts.map +1 -0
- package/dist/terms.js +715 -0
- package/dist/terms.js.map +1 -0
- package/dist/test-customer.d.ts +1525 -0
- package/dist/test-customer.d.ts.map +1 -0
- package/dist/test-customer.js +260 -0
- package/dist/test-customer.js.map +1 -0
- package/dist/types.d.ts +272 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +32 -0
- package/dist/types.js.map +1 -0
- package/dist/version.d.ts +51 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +66 -0
- package/dist/version.js.map +1 -0
- package/dist/wire.d.ts +2698 -0
- package/dist/wire.d.ts.map +1 -0
- package/dist/wire.js +678 -0
- package/dist/wire.js.map +1 -0
- package/package.json +37 -3
- package/vectors/api-request-v1.json +53 -0
- package/vectors/contest-statement-v1.json +42 -0
- package/vectors/terms-v2.json +398 -0
- package/vectors/terms-v3.json +2103 -0
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,120 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @avow-finance/spec
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The commitment schema that Avow's API, the SDK and the verifier all read. A supplier checks a commitment with the same code Avow used to approve it.
|
|
4
|
+
|
|
5
|
+
> **Status:** pre-release and testnet only. The terms format here is the working one, and it will change after supplier calls.
|
|
6
|
+
|
|
7
|
+
## What's public and what isn't
|
|
8
|
+
|
|
9
|
+
- **Public now.** This schema, the terms format and the verifier, under the repo's Apache 2.0 license.
|
|
10
|
+
- **Provisional.** Every layer carries its own version, and a reader refuses a version it doesn't know. A change to a signed message, the terms or their canonical JSON gets a new version of the layer it touches. Until 1.0 such a change can come in any release, and each release names it.
|
|
11
|
+
- **Later.** The written specification will go into the public domain (CC0) once a real counterparty has used the format. This code isn't that specification, and it isn't CC0.
|
|
12
|
+
- **Never here.** Customer terms, evidence, identity records and secrets stay out of this repo, its tests and its examples. Tests generate their own keys and use made-up businesses.
|
|
13
|
+
|
|
14
|
+
## What it holds
|
|
15
|
+
|
|
16
|
+
| Part | What it does |
|
|
17
|
+
| --- | --- |
|
|
18
|
+
| Records | Business, administrator, agent, mandate and commitment, with the 11 commitment states, the moves between them, the contest and outcome a record holds in each, and the references a record cites. `parseCommitment` refuses a record whose state can't hold its contest or outcome, or whose outcome's amounts don't fit its ending |
|
|
19
|
+
| Terms | Version 2 terms: a header and five sections, each hashed apart, with templates for what each kind of commitment promises. GPU reservation is the first template, and a job, which commits only under version 3, is the second |
|
|
20
|
+
| Version 3 terms | Version 2 with one more section, `dependencies`, for a booking that relies on another business's booking |
|
|
21
|
+
| Version 1 terms | The flat GPU reservation format published before the terms had a version, frozen so commitments made under it stay verifiable |
|
|
22
|
+
| References | Typed references to a commitment or a settled payment, the checks of a payment against the chain's transfer event in a token the reader accepts, and the rule that a payment's value counts once |
|
|
23
|
+
| Signed messages | The mandate, the terms agreement, the supplier authorization, the administrator's approval, the start receipt and Avow's timestamp, each as EIP-712 typed data. A timestamp names a signed request by its digest and says when Avow received it, so a late cancellation or a start request carries a time anyone can check against Avow's timestamp key |
|
|
24
|
+
| Signed requests | How an agent, a supplier or a business account's root key signs each request to Avow's API, and the bodies the API takes and answers with. [Signed requests](signed-requests.md) fixes the deployment binding, the encoding, request ids and retries, and what a signature proves |
|
|
25
|
+
| Contests | The six reasons a business contests a charge for, by the code the lock takes, with the kinds of charge each answers, and the statement the business gives with its canonical JSON and hash. `vectors/contest-statement-v1.json` pins worked examples, and [contesting a charge](../../fern/docs/pages/contesting.mdx) sets out each rule and the request that gives Avow the statement |
|
|
26
|
+
| Supplier adapter | The two routes a supplier's adapter serves to agents, `SUPPLIER_ADAPTER_PATHS`, with the supplier's profile, the offer an agent sends and the signature or refusal the supplier answers with. The answer takes every kind of signature `isKeySignature` checks, so a supplier whose signing key is a passkey can answer |
|
|
27
|
+
| Lock messages | The messages the lock checks: Avow's approval, the supplier's acceptance, report, evidence and release consent, and the actions a business or supplier account signs with its root or an admin key. The acceptance names the approval's digest (`approvalDigest`), so it covers every term the approval sets for the commitment, and the lock takes the consent only while the commitment's report count equals the one it names. Fixed digests in the tests match the lock contract's, and the signatures the SDK makes for one whole commitment are pinned, so a change to how the SDK signs one fails a pin |
|
|
28
|
+
| Mandate check | The pure check Avow runs before it signs an approval, which the SDK can run before it asks |
|
|
29
|
+
| Jobs | The `job/1` template, a job's session events with the one sentence the terminal and the screen share for each, the routes of Avow's test customer, `TEST_CUSTOMER_PATHS`, and the token a link to verify a job carries. [Jobs](../../fern/docs/pages/jobs.mdx) sets out what the customer's reserve backs and what each check proves |
|
|
30
|
+
| Reason codes | One stable code for every decision and every refusal |
|
|
31
|
+
| Sandbox | The testnet sandbox's routes, `SANDBOX_PATHS`, and the events a sandbox business posts to a session for its screen to show. A run starts, the authority changes, a booking is refused with its reason code, the layer that refused it and the amounts, a reserve is committed, and the supplier accepts it. `refusalSentence` turns a refusal into the one sentence the developer's terminal and the screen both show |
|
|
32
|
+
| Adapters | How a mandate maps onto an AP2 0.1 intent mandate and back, and how a commitment reads as an ERC-8183 job. [Adapters](adapters.md) sets out both mappings and what doesn't carry over, and points a new AP2 adapter at AP2 0.2 |
|
|
33
|
+
| Keychain envelope | Tempo's keychain V2 envelope for signatures a business account's root or admin key makes, with an offline check and a check against Tempo's own verifier |
|
|
34
|
+
| Wire forms | JSON schemas that parse amounts and times from decimal strings. `readCommitmentId` reads a commitment id from text, such as a command's argument, in the lower-case hex every message carries |
|
|
35
|
+
|
|
36
|
+
## The terms, version 2
|
|
37
|
+
|
|
38
|
+
A commitment has three layers. The envelope is universal. The terms agreement both sides sign names the commitment, both businesses, the buyer's mandate, the chain, the lock and the terms hash, and the commitment record carries its state, evidence and references. The terms are a header and five sections. A template fixes what one kind of commitment promises, and only the subject depends on it.
|
|
39
|
+
|
|
40
|
+
| Part | Holds | What reads it |
|
|
41
|
+
| --- | --- | --- |
|
|
42
|
+
| Header | `version` (2), `template`, `currency` and `amountDecimals` (6) | Every reader, before any section |
|
|
43
|
+
| `subject` | What's promised and when, in the template's shape | The template |
|
|
44
|
+
| `consideration` | What the buyer owes for the subject, a `rate` per unit or a `fixed` amount | Nobody enforces it. The terms describe it |
|
|
45
|
+
| `remedies` | `acceptBy`, `freeCancelBy`, the `charges` the supplier can report, and `chargeDeadline` | The lock, through Avow's approval |
|
|
46
|
+
| `resolution` | `contestWindow`, the fallback `arbiter` and `day90SupplierShareBps` | The lock, through Avow's approval |
|
|
47
|
+
| `backing` | What secures the commitment: kind `reserve`, the `side` it backs, the `amount` and the `releaseDate` | The lock, through Avow's approval |
|
|
48
|
+
|
|
49
|
+
Remedies, resolution and backing hold everything a lock enforces, and the core refuses a charge kind, backing kind or side a lock can't enforce. The only backing this version takes is the buyer's reserve. A payment that has already settled is evidence that money moved, so no backing kind refers to one.
|
|
50
|
+
|
|
51
|
+
### Templates
|
|
52
|
+
|
|
53
|
+
`gpu-reservation/1` is the first template. Its subject is the GPU, count, region and SKU with the window's start and length, and its consideration is a rate per `gpu-hour`. Its own rules put free cancellation and acceptance before the window opens, a late cancellation chargeable from the free-cancellation deadline, a no-show chargeable once the grace period after the window's start has passed, and the window's end before the charge deadline. The grace period lives only in the no-show charge's start time. `gpuReservationTerms` builds terms from what a booking states.
|
|
54
|
+
|
|
55
|
+
A template's meaning never changes. A change in how a template reads its terms is a new template version, such as `gpu-reservation/2`. The core knows templates by id and refuses one it doesn't know, so a template is reviewed code and never something a party supplies.
|
|
56
|
+
|
|
57
|
+
### What the lock enforces
|
|
58
|
+
|
|
59
|
+
`lockTerms` maps terms to the fields of Avow's approval, which the lock stores and enforces. The side, amount and release date come from the backing, the deadlines and charges from the remedies, and the contest window, arbiter and day-90 share from the resolution. Avow's API builds its approval with this mapping, and `approvalTermsProblem` refuses an approval that differs from it in any field or names another terms hash. The verifier runs the same check against the supplier's own terms before it builds an acceptance, so an approval can't make a lock enforce anything the terms don't say. The terms name a currency and never a token, so the approval's token sits outside the mapping, and the API and the verifier each check that it's a token accepted for that currency.
|
|
60
|
+
|
|
61
|
+
`LOCK_TERMS_FIELDS` names every field `lockTerms` gives, and `lockTermsDifferences` is the one comparison of them. `approvalTermsProblem` runs it on an approval. `lockRecordDifferences` runs it on a lock's record, which holds every field but the side, since the lock files each record under its side. The verifier runs it on the four fields a supplier authorization carries, `AUTHORIZATION_TERMS_FIELDS`. The build fails when `LockTerms` gains a field the list leaves out, so a new field is compared everywhere at once. `approvalPartiesProblem`, `approvalTokenProblem` and `approvalMandateProblem` check the rest of an approval, and the SDK and the verifier both use them.
|
|
62
|
+
|
|
63
|
+
### Hashing
|
|
64
|
+
|
|
65
|
+
Every hash here is reproducible from these rules, and `vectors/terms-v2.json` holds worked examples that `scripts/write-terms-vectors.mjs` writes and the tests check. One of them has a checksummed arbiter and a region with non-ASCII letters and quotes, where an implementation that skips a rule would hash differently.
|
|
66
|
+
|
|
67
|
+
- **The terms' shape** is exactly the header's four fields and the five sections. The hash covers nothing else, so `termsShapeProblem` refuses a field beside them, a section that isn't an object and a value canonical JSON can't write, and `termsHash` throws on terms it refuses.
|
|
68
|
+
- **Canonical JSON** is RFC 8785. Amounts, times and durations are integers written as decimal strings. Amounts are millionths of the currency, times are UTC Unix seconds and durations are seconds. Every other number is a safe integer, such as a count or a share in basis points. Strings have to be well-formed Unicode, and non-ASCII characters are written as UTF-8 without escapes. Only plain objects and arrays are written, so a Date or a Map throws.
|
|
69
|
+
- **Section salts** come from HKDF-SHA256 (RFC 5869). The input keying material is the commitment's 32-byte salt, there's no HKDF salt, the info is the UTF-8 label `avow:terms:v2:salt:<section>`, and the output is 32 bytes. The commitment's salt comes from a cryptographic random source, one per commitment, and an all-zero salt is refused.
|
|
70
|
+
- **A section's hash** is `keccak256(abi.encode(string label, bytes32 sectionSalt, string canonicalJson))`, with the label `avow:terms:v2:<section>`. The arbiter's address is hashed in lower case.
|
|
71
|
+
- **The terms hash** is `keccak256(abi.encode(string "avow:terms:v2", string headerJson, bytes32 subject, bytes32 consideration, bytes32 remedies, bytes32 resolution, bytes32 backing))`.
|
|
72
|
+
|
|
73
|
+
Each section has its own label, so a section can't be read as another section. A version 1 hash covers the salt followed by the terms' JSON, whose first character is `{`, and a version 2 hash covers an ABI encoding whose 33rd byte is always zero, so a hash of one version can never match the other's. A change of backing changes the terms hash, so it makes a new commitment and no signature carries over to it.
|
|
74
|
+
|
|
75
|
+
### Showing one section
|
|
76
|
+
|
|
77
|
+
`discloseSection` shows one section with its own salt and the other four sections' hashes, and `checkSectionDisclosure` checks it against the terms hash a lock or a signed message holds. A business can show what it booked and when without showing a price. The commitment's salt never leaves the parties.
|
|
78
|
+
|
|
79
|
+
## The terms, version 3
|
|
80
|
+
|
|
81
|
+
Version 3 terms add a `dependencies` section for a booking that relies on another business's booking, and [Version 3 terms](../../fern/docs/pages/terms-v3.mdx) describes them, their dependency disclosure control and the buyer's view.
|
|
82
|
+
|
|
83
|
+
## Version 1 terms
|
|
84
|
+
|
|
85
|
+
Version 1 terms are flat and carry no version field. Commitments made under them stay verifiable. `termsHash`, `validateTerms` and `lockTerms` read version 1 as well as version 2, and version 1 keeps the hash, checks and mapping it was signed under, with its original vectors pinned in the tests. `parseAnyTerms` reads version 1 or 2 for checking a commitment already made, `parseTerms` takes version 2 only, for a new plain booking, and `parseChainedTerms` takes version 3 only.
|
|
86
|
+
|
|
87
|
+
## References and payments
|
|
88
|
+
|
|
89
|
+
A reference has a kind. A commitment reference is chain, lock, commitment id, side and terms hash, checked against the lock. A payment reference names a settled transfer by chain, transaction hash and log index, its canonical id, and states the token, sender, recipient, amount and memo. The reference names its own token and any contract can emit an event shaped like a token's, so `checkPaymentReference` takes the tokens the reader accepts and refuses any other. It passes only when the transaction succeeded and is finalized and the log at that index is that token's own TIP-20 `TransferWithMemo` event with exactly those values. A plain transfer without a memo, or anything read from calldata, doesn't count.
|
|
90
|
+
|
|
91
|
+
`encodeCommitmentReference` writes a commitment reference as one URL-safe token, its canonical JSON in base64url, for a link such as the sandbox screen's `#verify=`. `decodeCommitmentReference` reads it back and refuses anything else. The token names only what anyone can check against the lock, so sharing it shares nothing private.
|
|
92
|
+
|
|
93
|
+
Any number of records can cite one payment as evidence, but its value counts at most once. `checkAttributions` refuses a second attribution of the same payment's value, whichever obligation it names. It proves uniqueness only within the set it's given, and it can't see an attribution another service or a later request makes. Before any version lets a payment's value be allocated, a persistent registry has to record each attribution atomically.
|
|
94
|
+
|
|
95
|
+
## Versions
|
|
96
|
+
|
|
97
|
+
| Layer | Version | Changes when |
|
|
98
|
+
| --- | --- | --- |
|
|
99
|
+
| Messages a lock checks | `LOCK_MESSAGE_VERSION`, 1 | The lock's code changes, which means a new lock |
|
|
100
|
+
| Each message a lock never sees | Its own entry in `MESSAGE_VERSIONS`, each 1 | That message changes |
|
|
101
|
+
| Terms | `version` inside the terms hash, 2 for a plain booking and 3 for one that relies on other bookings | The header, a section's schema, canonical JSON or the hashing changes |
|
|
102
|
+
| Template | In its id, such as `gpu-reservation/1` | What the template means changes |
|
|
103
|
+
| Commitment record | `COMMITMENT_RECORD_VERSION`, 3 | The record's own fields change. Version 2 added the references a record cites. Version 3 gave a reserve that went back at its release date its own kind of outcome, `reached_release_date`, which versions 1 and 2 recorded as `kept`, as they did the supplier's consent. A version 1 or 2 record reads as version 3, citing nothing when it's version 1. One that ended as `kept` stays version 2, so writing it back keeps its meaning |
|
|
104
|
+
|
|
105
|
+
Every signed message names its version, chain and lock in its EIP-712 domain, and carries a nonce and an expiry. A signed request to Avow's API carries a request id in place of the nonce, which names one operation. A reader refuses a version it doesn't know for that message type.
|
|
106
|
+
|
|
107
|
+
## Design rules
|
|
108
|
+
|
|
109
|
+
- Money in terms and mandates is in micros, millionths of the currency unit, so $500 is `500_000_000n`. A USD token on Tempo has 6 decimals, so its base units equal micros.
|
|
110
|
+
- Terms name a currency and never a token, so the same terms and terms hash work on any EVM rail. The token belongs to the commitment's backing record, in `BackingRef`.
|
|
111
|
+
- The reserve equals the largest charge in the terms. A contest window under 72 hours passes only the testnet demo profile. Each profile also fixes the timing of the locks its factory creates, and a supplier's verifier accepts no other. The production profile holds the intended production timing, which is unaudited and which no deployed factory uses yet. The testnet demo factory doesn't enforce every production limit.
|
|
112
|
+
|
|
113
|
+
## Develop
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
pnpm --filter @avow-finance/spec test
|
|
117
|
+
pnpm --filter @avow-finance/spec build && node packages/spec/scripts/write-terms-vectors.mjs
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Tests generate their keys for each run and never write them anywhere. The second line rewrites the version 2 and version 3 vectors, which only a new terms version should need. The tests pin each published file by its hash, so a change that moves a published hash fails. `scripts/write-contest-statement-vectors.mjs` rewrites the contest statement vectors the same way, which only a new statement label should need.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { Address } from 'viem';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* An agent asking a business for authority, from wherever its developer runs it. The agent makes
|
|
5
|
+
* its own key, and sends Avow a request signed by that key naming the business it works for. The
|
|
6
|
+
* business's administrator sees the request in the console, checks the pairing code against the
|
|
7
|
+
* one the agent printed, and signs the agent's mandate and key authorization with the passkey.
|
|
8
|
+
* Avow holds the signed approval for the agent to collect, and the agent enrolls with it. The
|
|
9
|
+
* routes are `SANDBOX_PATHS.agentRequests` and `SANDBOX_PATHS.agentApproval`.
|
|
10
|
+
*
|
|
11
|
+
* The agent asks by sending its request, and hears the answer by sending it again. Each ask is
|
|
12
|
+
* answered with where the request stands, and an ask after a request lapsed starts a fresh one.
|
|
13
|
+
*
|
|
14
|
+
* The request carries no authority. Anyone can ask any business, and nothing is granted until the
|
|
15
|
+
* account's own root key signs. The pairing code is how the administrator tells their own agent's
|
|
16
|
+
* request from someone else's.
|
|
17
|
+
*/
|
|
18
|
+
/** How long a request waits for the administrator, in seconds, before it lapses unanswered. */
|
|
19
|
+
export declare const AGENT_REQUEST_LIFETIME: bigint;
|
|
20
|
+
/**
|
|
21
|
+
* What an agent sends when it asks: the business it works for, a name its developer chose, and for
|
|
22
|
+
* an agent that sells, the signing key it made to quote and accept jobs for the business.
|
|
23
|
+
*/
|
|
24
|
+
export interface AgentRequest {
|
|
25
|
+
businessId: string;
|
|
26
|
+
label: string;
|
|
27
|
+
signingKey?: Address;
|
|
28
|
+
}
|
|
29
|
+
export declare function parseAgentRequest(json: unknown): AgentRequest | null;
|
|
30
|
+
/** Where a request stands. Approved carries the signed approval for the agent to enroll with. */
|
|
31
|
+
export declare const AGENT_REQUEST_STATES: readonly ['pending', 'approved', 'expired'];
|
|
32
|
+
export type AgentRequestState = (typeof AGENT_REQUEST_STATES)[number];
|
|
33
|
+
declare const agentRequestStatusJson: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
34
|
+
businessId: z.ZodString;
|
|
35
|
+
agentKey: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
36
|
+
lock: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
37
|
+
label: z.ZodString;
|
|
38
|
+
pairingCode: z.ZodString;
|
|
39
|
+
requestedAt: z.ZodPipe<z.ZodString, z.ZodTransform<bigint, string>>;
|
|
40
|
+
expiresAt: z.ZodPipe<z.ZodString, z.ZodTransform<bigint, string>>;
|
|
41
|
+
signingKey: z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>>;
|
|
42
|
+
state: z.ZodLiteral<"pending">;
|
|
43
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
44
|
+
businessId: z.ZodString;
|
|
45
|
+
agentKey: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
46
|
+
lock: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
47
|
+
label: z.ZodString;
|
|
48
|
+
pairingCode: z.ZodString;
|
|
49
|
+
requestedAt: z.ZodPipe<z.ZodString, z.ZodTransform<bigint, string>>;
|
|
50
|
+
expiresAt: z.ZodPipe<z.ZodString, z.ZodTransform<bigint, string>>;
|
|
51
|
+
signingKey: z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>>;
|
|
52
|
+
state: z.ZodLiteral<"expired">;
|
|
53
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
54
|
+
businessId: z.ZodString;
|
|
55
|
+
agentKey: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
56
|
+
lock: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
57
|
+
label: z.ZodString;
|
|
58
|
+
pairingCode: z.ZodString;
|
|
59
|
+
requestedAt: z.ZodPipe<z.ZodString, z.ZodTransform<bigint, string>>;
|
|
60
|
+
expiresAt: z.ZodPipe<z.ZodString, z.ZodTransform<bigint, string>>;
|
|
61
|
+
signingKey: z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>>;
|
|
62
|
+
state: z.ZodLiteral<"approved">;
|
|
63
|
+
approval: z.ZodObject<{
|
|
64
|
+
mandate: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
65
|
+
keyAuthorizedIn: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
66
|
+
}, z.core.$strict>;
|
|
67
|
+
supplierRegistration: z.ZodNullable<z.ZodObject<{
|
|
68
|
+
registration: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
69
|
+
accountSignature: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
70
|
+
}, z.core.$strict>>;
|
|
71
|
+
}, z.core.$strict>], "state">;
|
|
72
|
+
/** A request as Avow answers it, to the agent that made it or to the business's console. */
|
|
73
|
+
export type AgentRequestStatus = z.infer<typeof agentRequestStatusJson>;
|
|
74
|
+
export declare function parseAgentRequestStatus(json: unknown): AgentRequestStatus | null;
|
|
75
|
+
/**
|
|
76
|
+
* The code an agent prints when it asks, and the console shows beside the request. Both work it
|
|
77
|
+
* out from the agent's key, so it needs no channel of its own: matching codes mean the request in
|
|
78
|
+
* the console came from the agent in the developer's terminal. Eight characters, 40 bits.
|
|
79
|
+
*/
|
|
80
|
+
export declare function pairingCode(agentKey: Address): string;
|
|
81
|
+
export {};
|
|
82
|
+
//# sourceMappingURL=agent-connect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-connect.d.ts","sourceRoot":"","sources":["../src/agent-connect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAO,MAAM,MAAM,CAAA;AAExC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB;;;;;;;;;;;;;;GAcG;AAEH,+FAA+F;AAC/F,eAAO,MAAM,sBAAsB,QAAY,CAAA;AAE/C;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAeD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,GAAG,YAAY,GAAG,IAAI,CAKpE;AAED,iGAAiG;AACjG,eAAO,MAAM,oBAAoB,YAAI,SAAS,EAAE,UAAU,EAAE,SAAS,CAAU,CAAA;AAC/E,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAA;AAcrE,QAAA,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAiB1B,CAAA;AAEF,4FAA4F;AAC5F,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAA;AAEvE,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,OAAO,GAAG,kBAAkB,GAAG,IAAI,CAGhF;AAKD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,CASrD"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { keccak256, stringToHex } from 'viem';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { address, bytes32, hexBytes, u64 } from './json-fields.js';
|
|
4
|
+
/**
|
|
5
|
+
* An agent asking a business for authority, from wherever its developer runs it. The agent makes
|
|
6
|
+
* its own key, and sends Avow a request signed by that key naming the business it works for. The
|
|
7
|
+
* business's administrator sees the request in the console, checks the pairing code against the
|
|
8
|
+
* one the agent printed, and signs the agent's mandate and key authorization with the passkey.
|
|
9
|
+
* Avow holds the signed approval for the agent to collect, and the agent enrolls with it. The
|
|
10
|
+
* routes are `SANDBOX_PATHS.agentRequests` and `SANDBOX_PATHS.agentApproval`.
|
|
11
|
+
*
|
|
12
|
+
* The agent asks by sending its request, and hears the answer by sending it again. Each ask is
|
|
13
|
+
* answered with where the request stands, and an ask after a request lapsed starts a fresh one.
|
|
14
|
+
*
|
|
15
|
+
* The request carries no authority. Anyone can ask any business, and nothing is granted until the
|
|
16
|
+
* account's own root key signs. The pairing code is how the administrator tells their own agent's
|
|
17
|
+
* request from someone else's.
|
|
18
|
+
*/
|
|
19
|
+
/** How long a request waits for the administrator, in seconds, before it lapses unanswered. */
|
|
20
|
+
export const AGENT_REQUEST_LIFETIME = 60n * 60n;
|
|
21
|
+
const labelJson = z
|
|
22
|
+
.string()
|
|
23
|
+
.trim()
|
|
24
|
+
.min(1)
|
|
25
|
+
.max(60)
|
|
26
|
+
.regex(/^[^\p{Cc}]+$/u, 'printable characters only');
|
|
27
|
+
const agentRequestJson = z.strictObject({
|
|
28
|
+
businessId: z.string().min(1).max(200),
|
|
29
|
+
label: labelJson,
|
|
30
|
+
signingKey: address.optional(),
|
|
31
|
+
});
|
|
32
|
+
export function parseAgentRequest(json) {
|
|
33
|
+
const parsed = agentRequestJson.safeParse(json);
|
|
34
|
+
if (!parsed.success)
|
|
35
|
+
return null;
|
|
36
|
+
const { signingKey, ...rest } = parsed.data;
|
|
37
|
+
return signingKey ? { ...rest, signingKey } : rest;
|
|
38
|
+
}
|
|
39
|
+
/** Where a request stands. Approved carries the signed approval for the agent to enroll with. */
|
|
40
|
+
export const AGENT_REQUEST_STATES = ['pending', 'approved', 'expired'];
|
|
41
|
+
const statusBase = {
|
|
42
|
+
businessId: z.string().min(1),
|
|
43
|
+
agentKey: address,
|
|
44
|
+
lock: address,
|
|
45
|
+
label: labelJson,
|
|
46
|
+
pairingCode: z.string().regex(/^[0-9A-Z]{4}-[0-9A-Z]{4}$/),
|
|
47
|
+
requestedAt: u64,
|
|
48
|
+
expiresAt: u64,
|
|
49
|
+
/** The signing key an agent that sells asked to quote and accept with, or null. */
|
|
50
|
+
signingKey: address.nullable(),
|
|
51
|
+
};
|
|
52
|
+
const agentRequestStatusJson = z.discriminatedUnion('state', [
|
|
53
|
+
z.strictObject({ ...statusBase, state: z.literal('pending') }),
|
|
54
|
+
z.strictObject({ ...statusBase, state: z.literal('expired') }),
|
|
55
|
+
z.strictObject({
|
|
56
|
+
...statusBase,
|
|
57
|
+
state: z.literal('approved'),
|
|
58
|
+
// The body the agent sends to enroll, exactly as the administrator's console posted it.
|
|
59
|
+
approval: z.strictObject({
|
|
60
|
+
mandate: z.record(z.string(), z.unknown()),
|
|
61
|
+
keyAuthorizedIn: bytes32,
|
|
62
|
+
}),
|
|
63
|
+
// For an agent that sells, the supplier registration of its signing key with the account's
|
|
64
|
+
// signature on it, which the agent completes with its own and sends to Avow. Null otherwise.
|
|
65
|
+
supplierRegistration: z
|
|
66
|
+
.strictObject({ registration: z.record(z.string(), z.unknown()), accountSignature: hexBytes })
|
|
67
|
+
.nullable(),
|
|
68
|
+
}),
|
|
69
|
+
]);
|
|
70
|
+
export function parseAgentRequestStatus(json) {
|
|
71
|
+
const parsed = agentRequestStatusJson.safeParse(json);
|
|
72
|
+
return parsed.success ? parsed.data : null;
|
|
73
|
+
}
|
|
74
|
+
// Crockford's base32, which leaves out I, L, O and U so a code read aloud or retyped stays right.
|
|
75
|
+
const CODE_ALPHABET = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
|
|
76
|
+
/**
|
|
77
|
+
* The code an agent prints when it asks, and the console shows beside the request. Both work it
|
|
78
|
+
* out from the agent's key, so it needs no channel of its own: matching codes mean the request in
|
|
79
|
+
* the console came from the agent in the developer's terminal. Eight characters, 40 bits.
|
|
80
|
+
*/
|
|
81
|
+
export function pairingCode(agentKey) {
|
|
82
|
+
const digest = keccak256(stringToHex(`avow-pairing:${agentKey.toLowerCase()}`));
|
|
83
|
+
let bits = BigInt(digest.slice(0, 12)); // the first 5 bytes
|
|
84
|
+
let code = '';
|
|
85
|
+
for (let i = 0; i < 8; i++) {
|
|
86
|
+
code = (CODE_ALPHABET[Number(bits & 31n)] ?? '0') + code;
|
|
87
|
+
bits >>= 5n;
|
|
88
|
+
}
|
|
89
|
+
return `${code.slice(0, 4)}-${code.slice(4)}`;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=agent-connect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-connect.js","sourceRoot":"","sources":["../src/agent-connect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,MAAM,CAAA;AAC7C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,MA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