@avow-finance/spec 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 (179) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +119 -2
  3. package/dist/agent-connect.d.ts +90 -0
  4. package/dist/agent-connect.d.ts.map +1 -0
  5. package/dist/agent-connect.js +102 -0
  6. package/dist/agent-connect.js.map +1 -0
  7. package/dist/agent-session.d.ts +791 -0
  8. package/dist/agent-session.d.ts.map +1 -0
  9. package/dist/agent-session.js +176 -0
  10. package/dist/agent-session.js.map +1 -0
  11. package/dist/ap2.d.ts +79 -0
  12. package/dist/ap2.d.ts.map +1 -0
  13. package/dist/ap2.js +151 -0
  14. package/dist/ap2.js.map +1 -0
  15. package/dist/api-request.d.ts +144 -0
  16. package/dist/api-request.d.ts.map +1 -0
  17. package/dist/api-request.js +246 -0
  18. package/dist/api-request.js.map +1 -0
  19. package/dist/api.d.ts +288 -0
  20. package/dist/api.d.ts.map +1 -0
  21. package/dist/api.js +332 -0
  22. package/dist/api.js.map +1 -0
  23. package/dist/canonical.d.ts +22 -0
  24. package/dist/canonical.d.ts.map +1 -0
  25. package/dist/canonical.js +66 -0
  26. package/dist/canonical.js.map +1 -0
  27. package/dist/commitment-card.d.ts +78 -0
  28. package/dist/commitment-card.d.ts.map +1 -0
  29. package/dist/commitment-card.js +224 -0
  30. package/dist/commitment-card.js.map +1 -0
  31. package/dist/commitment.d.ts +185 -0
  32. package/dist/commitment.d.ts.map +1 -0
  33. package/dist/commitment.js +148 -0
  34. package/dist/commitment.js.map +1 -0
  35. package/dist/compute-offers.d.ts +128 -0
  36. package/dist/compute-offers.d.ts.map +1 -0
  37. package/dist/compute-offers.js +111 -0
  38. package/dist/compute-offers.js.map +1 -0
  39. package/dist/contest.d.ts +88 -0
  40. package/dist/contest.d.ts.map +1 -0
  41. package/dist/contest.js +131 -0
  42. package/dist/contest.js.map +1 -0
  43. package/dist/demo.d.ts +69 -0
  44. package/dist/demo.d.ts.map +1 -0
  45. package/dist/demo.js +152 -0
  46. package/dist/demo.js.map +1 -0
  47. package/dist/dependencies.d.ts +308 -0
  48. package/dist/dependencies.d.ts.map +1 -0
  49. package/dist/dependencies.js +133 -0
  50. package/dist/dependencies.js.map +1 -0
  51. package/dist/eip712.d.ts +1569 -0
  52. package/dist/eip712.d.ts.map +1 -0
  53. package/dist/eip712.js +550 -0
  54. package/dist/eip712.js.map +1 -0
  55. package/dist/elided-terms.d.ts +37 -0
  56. package/dist/elided-terms.d.ts.map +1 -0
  57. package/dist/elided-terms.js +48 -0
  58. package/dist/elided-terms.js.map +1 -0
  59. package/dist/erc8183.d.ts +78 -0
  60. package/dist/erc8183.d.ts.map +1 -0
  61. package/dist/erc8183.js +88 -0
  62. package/dist/erc8183.js.map +1 -0
  63. package/dist/facts.d.ts +70 -0
  64. package/dist/facts.d.ts.map +1 -0
  65. package/dist/facts.js +33 -0
  66. package/dist/facts.js.map +1 -0
  67. package/dist/gpu-reservation.d.ts +79 -0
  68. package/dist/gpu-reservation.d.ts.map +1 -0
  69. package/dist/gpu-reservation.js +135 -0
  70. package/dist/gpu-reservation.js.map +1 -0
  71. package/dist/index.d.ts +49 -0
  72. package/dist/index.d.ts.map +1 -0
  73. package/dist/index.js +49 -0
  74. package/dist/index.js.map +1 -0
  75. package/dist/job-session.d.ts +981 -0
  76. package/dist/job-session.d.ts.map +1 -0
  77. package/dist/job-session.js +170 -0
  78. package/dist/job-session.js.map +1 -0
  79. package/dist/job-verification.d.ts +244 -0
  80. package/dist/job-verification.d.ts.map +1 -0
  81. package/dist/job-verification.js +89 -0
  82. package/dist/job-verification.js.map +1 -0
  83. package/dist/job-wording.d.ts +48 -0
  84. package/dist/job-wording.d.ts.map +1 -0
  85. package/dist/job-wording.js +134 -0
  86. package/dist/job-wording.js.map +1 -0
  87. package/dist/job.d.ts +117 -0
  88. package/dist/job.d.ts.map +1 -0
  89. package/dist/job.js +166 -0
  90. package/dist/job.js.map +1 -0
  91. package/dist/json-fields.d.ts +13 -0
  92. package/dist/json-fields.d.ts.map +1 -0
  93. package/dist/json-fields.js +30 -0
  94. package/dist/json-fields.js.map +1 -0
  95. package/dist/keychain.d.ts +51 -0
  96. package/dist/keychain.d.ts.map +1 -0
  97. package/dist/keychain.js +133 -0
  98. package/dist/keychain.js.map +1 -0
  99. package/dist/mailbox.d.ts +1650 -0
  100. package/dist/mailbox.d.ts.map +1 -0
  101. package/dist/mailbox.js +87 -0
  102. package/dist/mailbox.js.map +1 -0
  103. package/dist/mandate.d.ts +53 -0
  104. package/dist/mandate.d.ts.map +1 -0
  105. package/dist/mandate.js +97 -0
  106. package/dist/mandate.js.map +1 -0
  107. package/dist/networks.d.ts +18 -0
  108. package/dist/networks.d.ts.map +1 -0
  109. package/dist/networks.js +24 -0
  110. package/dist/networks.js.map +1 -0
  111. package/dist/profiles.d.ts +31 -0
  112. package/dist/profiles.d.ts.map +1 -0
  113. package/dist/profiles.js +33 -0
  114. package/dist/profiles.js.map +1 -0
  115. package/dist/rail.d.ts +48 -0
  116. package/dist/rail.d.ts.map +1 -0
  117. package/dist/rail.js +28 -0
  118. package/dist/rail.js.map +1 -0
  119. package/dist/reasons.d.ts +173 -0
  120. package/dist/reasons.d.ts.map +1 -0
  121. package/dist/reasons.js +174 -0
  122. package/dist/reasons.js.map +1 -0
  123. package/dist/reference-link.d.ts +23 -0
  124. package/dist/reference-link.d.ts.map +1 -0
  125. package/dist/reference-link.js +56 -0
  126. package/dist/reference-link.js.map +1 -0
  127. package/dist/references.d.ts +125 -0
  128. package/dist/references.d.ts.map +1 -0
  129. package/dist/references.js +108 -0
  130. package/dist/references.js.map +1 -0
  131. package/dist/replay.d.ts +30 -0
  132. package/dist/replay.d.ts.map +1 -0
  133. package/dist/replay.js +27 -0
  134. package/dist/replay.js.map +1 -0
  135. package/dist/sandbox-registration.d.ts +200 -0
  136. package/dist/sandbox-registration.d.ts.map +1 -0
  137. package/dist/sandbox-registration.js +172 -0
  138. package/dist/sandbox-registration.js.map +1 -0
  139. package/dist/sandbox.d.ts +3478 -0
  140. package/dist/sandbox.d.ts.map +1 -0
  141. package/dist/sandbox.js +316 -0
  142. package/dist/sandbox.js.map +1 -0
  143. package/dist/session-fields.d.ts +203 -0
  144. package/dist/session-fields.d.ts.map +1 -0
  145. package/dist/session-fields.js +43 -0
  146. package/dist/session-fields.js.map +1 -0
  147. package/dist/supplier-adapter.d.ts +65 -0
  148. package/dist/supplier-adapter.d.ts.map +1 -0
  149. package/dist/supplier-adapter.js +91 -0
  150. package/dist/supplier-adapter.js.map +1 -0
  151. package/dist/terms-v1.d.ts +74 -0
  152. package/dist/terms-v1.d.ts.map +1 -0
  153. package/dist/terms-v1.js +156 -0
  154. package/dist/terms-v1.js.map +1 -0
  155. package/dist/terms.d.ts +341 -0
  156. package/dist/terms.d.ts.map +1 -0
  157. package/dist/terms.js +715 -0
  158. package/dist/terms.js.map +1 -0
  159. package/dist/test-customer.d.ts +1525 -0
  160. package/dist/test-customer.d.ts.map +1 -0
  161. package/dist/test-customer.js +260 -0
  162. package/dist/test-customer.js.map +1 -0
  163. package/dist/types.d.ts +272 -0
  164. package/dist/types.d.ts.map +1 -0
  165. package/dist/types.js +32 -0
  166. package/dist/types.js.map +1 -0
  167. package/dist/version.d.ts +51 -0
  168. package/dist/version.d.ts.map +1 -0
  169. package/dist/version.js +66 -0
  170. package/dist/version.js.map +1 -0
  171. package/dist/wire.d.ts +2698 -0
  172. package/dist/wire.d.ts.map +1 -0
  173. package/dist/wire.js +678 -0
  174. package/dist/wire.js.map +1 -0
  175. package/package.json +37 -3
  176. package/vectors/api-request-v1.json +53 -0
  177. package/vectors/contest-statement-v1.json +42 -0
  178. package/vectors/terms-v2.json +398 -0
  179. package/vectors/terms-v3.json +2103 -0
@@ -0,0 +1,246 @@
1
+ import { keccak256, toHex } from 'viem';
2
+ import { canonicalJson } from './canonical.js';
3
+ import { apiRequestTypedData, digestOf, } from './eip712.js';
4
+ import { isKeySignature } from './keychain.js';
5
+ import { MESSAGE_VERSIONS } from './version.js';
6
+ /** The scheme name a signed request puts in its Authorization header. */
7
+ export const API_AUTH_SCHEME = 'Avow';
8
+ /** The longest a signed request may stay valid, in seconds from when Avow receives it. */
9
+ export const API_REQUEST_MAX_VALIDITY = 300n;
10
+ /** The largest body a signed request may carry, in bytes. */
11
+ export const API_BODY_MAX_BYTES = 65_536;
12
+ /** The methods a signed request may use. A GET carries no body. */
13
+ export const API_METHODS = ['GET', 'POST'];
14
+ /**
15
+ * The request targets a signed request may name: `/v1` and one or more segments of lower-case
16
+ * letters, digits, `-` and `_`. No query, fragment, trailing slash, dot segment or
17
+ * percent-encoding, so the target a client signs is the target a server reads and routes on,
18
+ * whatever either side's URL parser does.
19
+ */
20
+ export const API_PATH_PATTERN = /^\/v1(\/[a-z0-9_-]+)+$/;
21
+ const LABEL = '[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?';
22
+ const AUDIENCE = new RegExp(`^(https?)://(${LABEL}(?:\\.${LABEL})*)(?::([1-9][0-9]{0,4}))?$`);
23
+ /**
24
+ * Whether a string is a deployment's audience in its one canonical form: an http or https origin
25
+ * in lower case, with a port only when it isn't the scheme's default, and no path, query or
26
+ * trailing slash. `https://api.testnet.avow.finance` is one, and `https://api.testnet.avow.finance:443`
27
+ * isn't, so one deployment never has two audiences.
28
+ */
29
+ export function isApiAudience(audience) {
30
+ const m = AUDIENCE.exec(audience);
31
+ if (!m)
32
+ return false;
33
+ const [, scheme, , port] = m;
34
+ if (port === undefined)
35
+ return true;
36
+ const n = Number(port);
37
+ return n <= 65_535 && !(scheme === 'https' && n === 443) && !(scheme === 'http' && n === 80);
38
+ }
39
+ /** keccak256 of a request body's exact bytes. A request with no body hashes no bytes. */
40
+ export function apiBodyHash(body) {
41
+ return keccak256(body);
42
+ }
43
+ /** A fresh request id, 32 random bytes. */
44
+ export function newRequestId() {
45
+ return toHex(crypto.getRandomValues(new Uint8Array(32)));
46
+ }
47
+ /**
48
+ * A request body as a client sends it: the value's canonical JSON, with bigints as decimal
49
+ * strings, in UTF-8. Canonical JSON has one encoding for each value, so the bytes a client signs
50
+ * are the only bytes Avow accepts for that value.
51
+ */
52
+ export function encodeApiBody(value) {
53
+ return new TextEncoder().encode(canonicalJson(value));
54
+ }
55
+ /**
56
+ * Reads a body Avow received. It has to be well-formed UTF-8 holding canonical JSON, so a body with
57
+ * a repeated key, extra whitespace or keys out of order is refused rather than read one way here
58
+ * and another way by whoever reads the stored copy. No bytes read as no body.
59
+ */
60
+ export function readApiBody(body) {
61
+ if (body.length === 0)
62
+ return { ok: true, value: undefined };
63
+ let text;
64
+ let value;
65
+ try {
66
+ text = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(body);
67
+ value = JSON.parse(text);
68
+ if (canonicalJson(value) !== text)
69
+ return { ok: false, reason: 'request.invalid' };
70
+ }
71
+ catch {
72
+ return { ok: false, reason: 'request.invalid' };
73
+ }
74
+ return { ok: true, value };
75
+ }
76
+ /**
77
+ * Why a request can't be signed or checked as it stands, or null when it can. Both the client and
78
+ * the API run this, so neither signs or verifies a request the other would read differently.
79
+ * `path` is the request target exactly as sent on the wire, which a server reads before any
80
+ * routing or decoding. A signed request's target is only ever a path.
81
+ */
82
+ export function apiRequestProblem(r) {
83
+ if (!isApiAudience(r.audience))
84
+ return 'request.invalid';
85
+ if (!API_METHODS.includes(r.method))
86
+ return 'request.invalid';
87
+ if (!API_PATH_PATTERN.test(r.path))
88
+ return 'request.invalid';
89
+ if (r.body.length > API_BODY_MAX_BYTES)
90
+ return 'request.invalid';
91
+ if (r.method === 'GET' && r.body.length > 0)
92
+ return 'request.invalid';
93
+ return null;
94
+ }
95
+ /**
96
+ * Why Avow won't start a request with this expiry, or null when it will. A request starts only
97
+ * while its expiry is after Avow's clock and at most `API_REQUEST_MAX_VALIDITY` ahead of it. Avow
98
+ * checks this after looking up the request id, so an identical repeat of a request it already
99
+ * answered gets that answer even once the request has expired.
100
+ */
101
+ export function apiRequestExpiryProblem(expiry, now) {
102
+ if (expiry <= now)
103
+ return 'message.expired';
104
+ if (expiry > now + API_REQUEST_MAX_VALIDITY)
105
+ return 'message.validity_too_long';
106
+ return null;
107
+ }
108
+ export function formatApiAuthorization(c) {
109
+ return `${API_AUTH_SCHEME} signer=${c.signer}, lock=${c.lock}, requestId=${c.requestId}, expiry=${c.expiry}, signature=${c.signature}`;
110
+ }
111
+ const ADDRESS = /^0x[0-9a-fA-F]{40}$/;
112
+ const BYTES32 = /^0x[0-9a-fA-F]{64}$/;
113
+ const DECIMAL = /^(0|[1-9][0-9]*)$/;
114
+ const SIGNATURE = /^0x([0-9a-fA-F]{2})+$/;
115
+ const FIELDS = ['signer', 'lock', 'requestId', 'expiry', 'signature'];
116
+ /**
117
+ * Reads a signed request's Authorization header, or returns null when it isn't one. The fields are
118
+ * separated by a comma and one space, each appears once and nothing else may, so two readers can't
119
+ * take different values from one header. Hex comes back in lower case.
120
+ */
121
+ export function parseApiAuthorization(header) {
122
+ if (!header?.startsWith(`${API_AUTH_SCHEME} `))
123
+ return null;
124
+ const fields = new Map();
125
+ for (const part of header.slice(API_AUTH_SCHEME.length + 1).split(', ')) {
126
+ const eq = part.indexOf('=');
127
+ if (eq < 1)
128
+ return null;
129
+ const name = part.slice(0, eq);
130
+ if (!FIELDS.includes(name) || fields.has(name))
131
+ return null;
132
+ fields.set(name, part.slice(eq + 1));
133
+ }
134
+ const signer = fields.get('signer');
135
+ const lock = fields.get('lock');
136
+ const requestId = fields.get('requestId');
137
+ const expiry = fields.get('expiry');
138
+ const signature = fields.get('signature');
139
+ if (signer === undefined || !ADDRESS.test(signer))
140
+ return null;
141
+ if (lock === undefined || !ADDRESS.test(lock))
142
+ return null;
143
+ if (requestId === undefined || !BYTES32.test(requestId))
144
+ return null;
145
+ if (expiry === undefined || !DECIMAL.test(expiry) || BigInt(expiry) >= 2n ** 64n)
146
+ return null;
147
+ if (signature === undefined || !SIGNATURE.test(signature))
148
+ return null;
149
+ return {
150
+ signer: signer.toLowerCase(),
151
+ lock: lock.toLowerCase(),
152
+ requestId: requestId.toLowerCase(),
153
+ expiry: BigInt(expiry),
154
+ signature: signature.toLowerCase(),
155
+ };
156
+ }
157
+ /**
158
+ * The first two steps Avow takes with every request, in order. It checks the request's form and
159
+ * reads the header, then rebuilds the signed message from its own audience and chain, the header's
160
+ * lock, and the method, path and body it received, and checks the signature. A refusal here
161
+ * comes before Avow looks anything up or records anything. What comes next, in order, is the
162
+ * request-id lookup, the expiry check, the route's own checks, and one transaction that records
163
+ * the request with what it did.
164
+ */
165
+ export function verifyApiRequest(r) {
166
+ const problem = apiRequestProblem(r);
167
+ if (problem)
168
+ return { ok: false, reason: problem };
169
+ const credentials = parseApiAuthorization(r.authorization);
170
+ if (!credentials)
171
+ return { ok: false, reason: 'request.unsigned' };
172
+ const message = {
173
+ audience: r.audience,
174
+ method: r.method,
175
+ path: r.path,
176
+ bodyHash: apiBodyHash(r.body),
177
+ signer: credentials.signer,
178
+ requestId: credentials.requestId,
179
+ expiry: credentials.expiry,
180
+ };
181
+ const domain = { chainId: r.chainId, verifyingContract: credentials.lock };
182
+ const digest = digestOf(apiRequestTypedData(message, domain));
183
+ if (!isKeySignature(digest, credentials.signature, credentials.signer)) {
184
+ return { ok: false, reason: 'message.signature_invalid' };
185
+ }
186
+ return {
187
+ ok: true,
188
+ value: {
189
+ digest,
190
+ credentials,
191
+ request: {
192
+ type: 'ApiRequest',
193
+ schemaVersion: MESSAGE_VERSIONS.ApiRequest,
194
+ chainId: r.chainId,
195
+ lock: credentials.lock,
196
+ message,
197
+ signature: credentials.signature,
198
+ },
199
+ },
200
+ };
201
+ }
202
+ /**
203
+ * Signs one request to Avow's API. It returns the Authorization header to send with exactly these
204
+ * body bytes, and the signed request, the record of what the client asked. It throws for a request
205
+ * `apiRequestProblem` refuses, since the API would refuse it too.
206
+ */
207
+ export async function signApiRequest(args) {
208
+ const problem = apiRequestProblem(args);
209
+ if (problem)
210
+ throw new Error(`The request can't be signed as it stands (${problem})`);
211
+ if (!BYTES32.test(args.requestId))
212
+ throw new Error('The request id has to be 32 bytes of hex');
213
+ // Hex goes in lower case, so the client's record of the request is the one Avow rebuilds.
214
+ const signer = args.key.address.toLowerCase();
215
+ const lock = args.domain.verifyingContract.toLowerCase();
216
+ const message = {
217
+ audience: args.audience,
218
+ method: args.method,
219
+ path: args.path,
220
+ bodyHash: apiBodyHash(args.body),
221
+ signer,
222
+ requestId: args.requestId.toLowerCase(),
223
+ expiry: args.expiry,
224
+ };
225
+ const digest = digestOf(apiRequestTypedData(message, args.domain));
226
+ const signature = (await args.key.signDigest(digest)).toLowerCase();
227
+ return {
228
+ digest,
229
+ authorization: formatApiAuthorization({
230
+ signer,
231
+ lock,
232
+ requestId: message.requestId,
233
+ expiry: args.expiry,
234
+ signature,
235
+ }),
236
+ request: {
237
+ type: 'ApiRequest',
238
+ schemaVersion: MESSAGE_VERSIONS.ApiRequest,
239
+ chainId: args.domain.chainId,
240
+ lock,
241
+ message,
242
+ signature,
243
+ },
244
+ };
245
+ }
246
+ //# sourceMappingURL=api-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-request.js","sourceRoot":"","sources":["../src/api-request.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,SAAS,EAAE,KAAK,EAAE,MAAM,MAAM,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAGL,mBAAmB,EACnB,QAAQ,GAET,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAE/C,yEAAyE;AACzE,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAA;AAErC,0FAA0F;AAC1F,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,CAAA;AAE5C,6DAA6D;AAC7D,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CA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AAI,CAAC,MAAM,CAAC,CAAC,CAAA;IAClE,MAAM,SAAS,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,EAAS,CAAA;IAC1E,OAAO;QACL,MAAM;QACN,aAAa,EAAE,sBAAsB,CAAC;YACpC,MAAM;YACN,IAAI;YACJ,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,SAAS;SACV,CAAC;QACF,OAAO,EAAE;YACP,IAAI,EAAE,YAAY;YAClB,aAAa,EAAE,gBAAgB,CAAC,UAAU;YAC1C,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;YAC5B,IAAI;YACJ,OAAO;YACP,SAAS;SACV;KACF,CAAA;AACH,CAAC"}
package/dist/api.d.ts ADDED
@@ -0,0 +1,288 @@
1
+ import type { Address, Hex } from 'viem';
2
+ import { type ContestStatement } from './contest.js';
3
+ import { type ApiRequest, type Approval, type HumanApproval, type Signed, type SignedAgreement, type StartReceipt, type SupplierAuthorization, type Timestamp } from './eip712.js';
4
+ import { type ReasonCode } from './reasons.js';
5
+ import type { Mandate, ReserveRequest } from './types.js';
6
+ import { type Parsed } from './wire.js';
7
+ /**
8
+ * The bodies Avow's API takes and answers with, which the SDK sends, a supplier's adapter sends and
9
+ * the API reads. Every request is signed as an `ApiRequest`, and every body travels as JSON with
10
+ * amounts and times as decimal strings.
11
+ */
12
+ export declare const API_PATHS: {
13
+ readonly enrollments: '/v1/enrollments';
14
+ readonly reserveApprovals: '/v1/reserve-approvals';
15
+ readonly sponsorships: '/v1/sponsorships';
16
+ readonly supplierAuthorizations: (commitmentId: Hex) => string;
17
+ readonly cancellations: (commitmentId: Hex) => string;
18
+ readonly startRequests: (commitmentId: Hex) => string;
19
+ readonly startReceipts: (commitmentId: Hex) => string;
20
+ readonly contestStatements: (commitmentId: Hex) => string;
21
+ };
22
+ /**
23
+ * What an agent asks Avow's reserve check to approve. Avow reads the business, its administrator,
24
+ * the agent, the supplier and the mandate from its own records, and the open reserves from the
25
+ * lock, so the request carries only what the agent and the supplier agreed.
26
+ */
27
+ export interface ReserveApprovalRequest {
28
+ request: ReserveRequest;
29
+ /** The commitment's salt. Avow passes it to the supplier in its authorization. */
30
+ salt: Hex;
31
+ agreement: SignedAgreement;
32
+ /** Which key funds the reserve, the agent's or the administrator's. */
33
+ fundedBy: 'agent' | 'administrator';
34
+ /** The administrator's approval, when the mandate asks for one. */
35
+ humanApproval?: Signed<HumanApproval>;
36
+ }
37
+ /** Avow's answer to a reserve request, with the id of the decision Avow recorded either way. */
38
+ export type ReserveApproval = {
39
+ ok: true;
40
+ decisionId: string;
41
+ approval: Signed<Approval>;
42
+ } | {
43
+ ok: false;
44
+ decisionId: string;
45
+ reason: ReasonCode;
46
+ };
47
+ /**
48
+ * An agent enrolling with Avow once its key is on the chain. The mandate the administrator signed
49
+ * names the business, the agent and its key, and the transaction put that key on the business
50
+ * account with the mandate's hash. The agent signs the request with that key.
51
+ */
52
+ export interface EnrollmentRequest {
53
+ mandate: Signed<Mandate>;
54
+ keyAuthorizedIn: Hex;
55
+ }
56
+ export interface Enrollment {
57
+ businessId: string;
58
+ agentId: string;
59
+ agentKey: Address;
60
+ mandateHash: Hex;
61
+ }
62
+ /** A transaction an agent signed with `feePayer: true`, which Avow's relay co-signs or refuses. */
63
+ export interface SponsorshipRequest {
64
+ transaction: Hex;
65
+ }
66
+ export interface Sponsorship {
67
+ transaction: Hex;
68
+ }
69
+ /**
70
+ * Avow's answer to a supplier asking for a fresh authorization for a commitment's reserve. With it
71
+ * come Avow's approval the reserve was funded under and the buyer's signed mandate, which the
72
+ * supplier's verifier checks against its own terms and the lock before it accepts. Avow's word on
73
+ * either is never taken, since the verifier checks the approval against the digest the lock
74
+ * stored and the mandate against the business account's signature.
75
+ */
76
+ export type SupplierAuthorizationAnswer = {
77
+ ok: true;
78
+ authorization: Signed<SupplierAuthorization>;
79
+ approval: Signed<Approval>;
80
+ mandate: Signed<Mandate>;
81
+ } | {
82
+ ok: false;
83
+ reason: ReasonCode;
84
+ };
85
+ /**
86
+ * Avow's answer to a business cancelling a commitment once free cancellation has ended: when Avow
87
+ * received the cancellation, and Avow's timestamp on the signed request that carried it. A late
88
+ * cancellation charge rests on this record. Avow records a cancellation from the end of free
89
+ * cancellation until the no-show charge can be reported, or until the charge deadline when the
90
+ * terms carry no no-show charge. Before free cancellation ends the business cancels on the lock,
91
+ * and Avow refuses with `commitment.cancel_on_lock`. Once the no-show charge can be reported, a
92
+ * cancellation can no longer change the charge, and Avow refuses with `commitment.cancel_closed`.
93
+ * From the charge deadline on it refuses with `commitment.ended`.
94
+ *
95
+ * A commitment has one cancellation, so a later request to cancel it gets the first one's answer,
96
+ * whatever the time. That answer's timestamp names the first request, and `cancelledBy` carries
97
+ * what the later caller needs to rebuild that request's digest.
98
+ */
99
+ export interface CancellationAnswer {
100
+ cancelledAt: bigint;
101
+ timestamp: Signed<Timestamp>;
102
+ /** The request that cancelled the commitment, present when it isn't the one this answers. */
103
+ cancelledBy?: CancelledBy;
104
+ }
105
+ /**
106
+ * What a later caller can't know about the signed request that cancelled a commitment: the key
107
+ * that signed it, its request id, its expiry and its body's hash. With the caller's own audience,
108
+ * `POST` and the commitment's cancellations path, they rebuild that request's digest, which Avow's
109
+ * timestamp names.
110
+ */
111
+ export type CancelledBy = Pick<ApiRequest, 'signer' | 'requestId' | 'expiry' | 'bodyHash'>;
112
+ /**
113
+ * Avow's answer to a business asking to start a job: the digest of the signed request, which the
114
+ * supplier's start receipt names, and Avow's timestamp on it. The job can't have started before
115
+ * the timestamp.
116
+ */
117
+ export interface StartRequestAnswer {
118
+ startRequestHash: Hex;
119
+ requestedAt: bigint;
120
+ timestamp: Signed<Timestamp>;
121
+ }
122
+ /** The supplier's start receipt, which the business's agent passes on for Avow to record. */
123
+ export interface StartReceiptRequest {
124
+ receipt: Signed<StartReceipt>;
125
+ }
126
+ /** Avow's answer to a start receipt: recorded, or refused with the reason. */
127
+ export type StartReceiptAnswer = {
128
+ ok: true;
129
+ } | {
130
+ ok: false;
131
+ reason: ReasonCode;
132
+ };
133
+ /**
134
+ * The business's statement for a contest the lock already took, which the business account's root
135
+ * key signs and sends so Avow holds the text it rules on. Avow records it only when the named
136
+ * transaction holds the lock's `Paused` event for this commitment with the statement's reason code
137
+ * and hash, so a statement can't stand for another contest, and a commitment has one statement.
138
+ */
139
+ export interface ContestStatementRequest {
140
+ statement: ContestStatement;
141
+ /** The transaction that carried the contest to the business's lock. */
142
+ contestedIn: Hex;
143
+ }
144
+ /**
145
+ * Avow's answer once it holds a contest's statement: the statement's hash and when Avow first
146
+ * recorded it. A commitment has one contest, so posting its statement again, with any request id,
147
+ * gets the same answer and records nothing more.
148
+ */
149
+ export interface ContestStatementAnswer {
150
+ statementHash: Hex;
151
+ /** When Avow first recorded the statement, in unix seconds by Avow's clock. */
152
+ recordedAt: bigint;
153
+ }
154
+ /**
155
+ * What the API answers when it refuses a request outright, with a status of 400 or more, as
156
+ * `{ "error": { "reason": "<code>", "message": "<sentence>" } }`. A refusal by Avow's relay adds
157
+ * the fields `SponsorshipRefusal` gives for its code. Readers ignore any other field.
158
+ */
159
+ export interface ApiError {
160
+ error: {
161
+ reason: ReasonCode;
162
+ message: string;
163
+ };
164
+ }
165
+ /**
166
+ * The most gas Avow's relay pays for in an agent's reserve, unless a deployment sets a lower cap,
167
+ * which a `sponsorship.over_cap` refusal names.
168
+ */
169
+ export declare const SPONSORED_RESERVE_GAS_CAP = 6000000n;
170
+ /** The caps Avow's relay holds a transaction to: its gas, its fee per gas, and the most it could pay in fees. */
171
+ export declare const SPONSORSHIP_CAPS: readonly ['gas', 'fee_per_gas', 'fee'];
172
+ export type SponsorshipCap = (typeof SPONSORSHIP_CAPS)[number];
173
+ /** The budgets of Avow's relay, each counting gas over the last 24 hours. */
174
+ export declare const SPONSORSHIP_BUDGETS: readonly ['agent_key', 'business', 'supplier', 'relay'];
175
+ export type SponsorshipBudget = (typeof SPONSORSHIP_BUDGETS)[number];
176
+ /**
177
+ * What a refusal by Avow's relay adds to its error, so an agent can act on it without reading the
178
+ * message. Times are unix seconds by Avow's clock.
179
+ *
180
+ * - `sponsorship.over_cap` names the cap and its limit, in gas for `gas`, in attodollars a gas for
181
+ * `fee_per_gas`, and in base units of the fee token for `fee`.
182
+ * - `sponsorship.rate_limited` gives the time the signing key can ask again.
183
+ * - `sponsorship.simulation_failed` carries the revert data the simulation returned. It's `0x` when
184
+ * the run returned none, as when the transaction runs out of gas, can't start on its gas limit,
185
+ * is signed by a key the node won't take, or reverts without a reason, and the message says
186
+ * which.
187
+ * - `sponsorship.budget_spent` names the budget and the time enough of it frees up for the
188
+ * transaction at the latest. Gas held for a transaction that never lands frees up sooner.
189
+ */
190
+ export type SponsorshipRefusal = {
191
+ reason: 'sponsorship.over_cap';
192
+ cap: SponsorshipCap;
193
+ limit: bigint;
194
+ } | {
195
+ reason: 'sponsorship.rate_limited';
196
+ retryAt: bigint;
197
+ } | {
198
+ reason: 'sponsorship.simulation_failed';
199
+ revert: Hex;
200
+ } | {
201
+ reason: 'sponsorship.budget_spent';
202
+ budget: SponsorshipBudget;
203
+ retryAt: bigint;
204
+ };
205
+ /**
206
+ * Parses a reserve approval request. Its agreement and any human approval have to be for this chain
207
+ * and for the lock the request was signed under.
208
+ */
209
+ export declare function parseReserveApprovalRequest(json: unknown, expected: {
210
+ chainId: number;
211
+ lock: Address;
212
+ }): Parsed<ReserveApprovalRequest>;
213
+ /** Parses Avow's answer to a reserve request. An approval has to be for this chain and lock. */
214
+ export declare function parseReserveApproval(json: unknown, expected: {
215
+ chainId: number;
216
+ lock: Address;
217
+ }): Parsed<ReserveApproval>;
218
+ /** Parses an enrollment. The mandate has to be for this chain and the lock the request was signed under. */
219
+ export declare function parseEnrollmentRequest(json: unknown, expected: {
220
+ chainId: number;
221
+ lock: Address;
222
+ }): Parsed<EnrollmentRequest>;
223
+ export declare function parseEnrollment(json: unknown): Parsed<Enrollment>;
224
+ export declare function parseSponsorshipRequest(json: unknown): Parsed<SponsorshipRequest>;
225
+ export declare function parseSponsorship(json: unknown): Parsed<Sponsorship>;
226
+ /** Parses Avow's answer to a supplier's request. An authorization has to be for this chain and lock. */
227
+ export declare function parseSupplierAuthorizationAnswer(json: unknown, expected: {
228
+ chainId: number;
229
+ lock: Address;
230
+ }): Parsed<SupplierAuthorizationAnswer>;
231
+ /**
232
+ * Parses Avow's answer to a cancellation. Its timestamp has to be for this chain and lock and give
233
+ * the same time as the answer. Without `cancelledBy`, the timestamp has to name `requestHash`, the
234
+ * digest of the request the caller signed. With it, an earlier request cancelled the commitment,
235
+ * and the timestamp has to name that request's digest, rebuilt from the caller's `audience`,
236
+ * `POST`, the commitment's cancellations path and what `cancelledBy` carries. Either way the
237
+ * timestamp names a request to cancel this commitment on this deployment, chain and lock.
238
+ */
239
+ export declare function parseCancellationAnswer(json: unknown, expected: {
240
+ chainId: number;
241
+ lock: Address;
242
+ audience: string;
243
+ commitmentId: Hex;
244
+ requestHash: Hex;
245
+ }): Parsed<CancellationAnswer>;
246
+ /**
247
+ * Parses Avow's answer to a start request. Its hash has to be `requestHash`, the digest of the
248
+ * request the caller signed, and its timestamp has to be for this chain and lock and name that
249
+ * hash and the answer's time.
250
+ */
251
+ export declare function parseStartRequestAnswer(json: unknown, expected: {
252
+ chainId: number;
253
+ lock: Address;
254
+ requestHash: Hex;
255
+ }): Parsed<StartRequestAnswer>;
256
+ /** Parses a start receipt the agent passes on. It has to be for this chain and lock. */
257
+ export declare function parseStartReceiptRequest(json: unknown, expected: {
258
+ chainId: number;
259
+ lock: Address;
260
+ }): Parsed<StartReceiptRequest>;
261
+ /** Parses Avow's answer to a start receipt. */
262
+ export declare function parseStartReceiptAnswer(json: unknown): Parsed<StartReceiptAnswer>;
263
+ /**
264
+ * Parses a contest statement the business's root key sends. Its statement has to parse as
265
+ * `parseContestStatement` reads one, and a refusal keeps that reason.
266
+ */
267
+ export declare function parseContestStatementRequest(json: unknown): Parsed<ContestStatementRequest>;
268
+ /**
269
+ * Parses Avow's answer to a contest statement. Its hash has to be `statementHash`, the hash of the
270
+ * statement the caller sent, so an answer about any other statement is refused.
271
+ */
272
+ export declare function parseContestStatementAnswer(json: unknown, expected: {
273
+ statementHash: Hex;
274
+ }): Parsed<ContestStatementAnswer>;
275
+ /**
276
+ * Reads an error body, or returns null when the body isn't one. Other fields are ignored, and a
277
+ * reason code this package doesn't know reads as null, so a newer API's refusals still read.
278
+ */
279
+ export declare function parseApiError(json: unknown): {
280
+ reason: ReasonCode | null;
281
+ message: string;
282
+ } | null;
283
+ /**
284
+ * Reads what a refusal by Avow's relay adds to an error body, or returns null for any other body,
285
+ * including a relay refusal whose fields don't parse. Other fields are ignored.
286
+ */
287
+ export declare function parseSponsorshipRefusal(json: unknown): SponsorshipRefusal | null;
288
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAExC,OAAO,EAAE,KAAK,gBAAgB,EAAyB,MAAM,cAAc,CAAA;AAC3E,OAAO,EACL,KAAK,UAAU,EACf,KAAK,QAAQ,EAGb,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,qBAAqB,EAC1B,KAAK,SAAS,EACf,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,cAAc,CAAA;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AACzD,OAAO,EAIL,KAAK,MAAM,EAOZ,MAAM,WAAW,CAAA;AAElB;;;;GAIG;AACH,eAAO,MAAM,SAAS;aACpB,WAAW,EAAE,iBAAiB;aAC9B,gBAAgB,EAAE,uBAAuB;aACzC,YAAY,EAAE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