@avow-finance/sdk 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.
- package/LICENSE +201 -0
- package/README.md +122 -2
- package/dist/agent-entry.d.ts +15 -0
- package/dist/agent-entry.d.ts.map +1 -0
- package/dist/agent-entry.js +11 -0
- package/dist/agent-entry.js.map +1 -0
- package/dist/agent-key.d.ts +34 -0
- package/dist/agent-key.d.ts.map +1 -0
- package/dist/agent-key.js +33 -0
- package/dist/agent-key.js.map +1 -0
- package/dist/agent.d.ts +261 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +493 -0
- package/dist/agent.js.map +1 -0
- package/dist/avow-api.d.ts +78 -0
- package/dist/avow-api.d.ts.map +1 -0
- package/dist/avow-api.js +2 -0
- package/dist/avow-api.js.map +1 -0
- package/dist/contest.d.ts +135 -0
- package/dist/contest.d.ts.map +1 -0
- package/dist/contest.js +186 -0
- package/dist/contest.js.map +1 -0
- package/dist/http.d.ts +161 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +311 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/job/accept.d.ts +84 -0
- package/dist/job/accept.d.ts.map +1 -0
- package/dist/job/accept.js +136 -0
- package/dist/job/accept.js.map +1 -0
- package/dist/job/customer.d.ts +43 -0
- package/dist/job/customer.d.ts.map +1 -0
- package/dist/job/customer.js +83 -0
- package/dist/job/customer.js.map +1 -0
- package/dist/job/quote.d.ts +34 -0
- package/dist/job/quote.d.ts.map +1 -0
- package/dist/job/quote.js +37 -0
- package/dist/job/quote.js.map +1 -0
- package/dist/lock.d.ts +269 -0
- package/dist/lock.d.ts.map +1 -0
- package/dist/lock.js +283 -0
- package/dist/lock.js.map +1 -0
- package/dist/moderato.d.ts +27 -0
- package/dist/moderato.d.ts.map +1 -0
- package/dist/moderato.js +34 -0
- package/dist/moderato.js.map +1 -0
- package/dist/node/cli.d.ts +3 -0
- package/dist/node/cli.d.ts.map +1 -0
- package/dist/node/cli.js +346 -0
- package/dist/node/cli.js.map +1 -0
- package/dist/node/connect.d.ts +15 -0
- package/dist/node/connect.d.ts.map +1 -0
- package/dist/node/connect.js +91 -0
- package/dist/node/connect.js.map +1 -0
- package/dist/node/eval.d.ts +3 -0
- package/dist/node/eval.d.ts.map +1 -0
- package/dist/node/eval.js +67 -0
- package/dist/node/eval.js.map +1 -0
- package/dist/node/first-run.d.ts +50 -0
- package/dist/node/first-run.d.ts.map +1 -0
- package/dist/node/first-run.js +149 -0
- package/dist/node/first-run.js.map +1 -0
- package/dist/node/job.d.ts +50 -0
- package/dist/node/job.d.ts.map +1 -0
- package/dist/node/job.js +176 -0
- package/dist/node/job.js.map +1 -0
- package/dist/node/mailbox.d.ts +19 -0
- package/dist/node/mailbox.d.ts.map +1 -0
- package/dist/node/mailbox.js +81 -0
- package/dist/node/mailbox.js.map +1 -0
- package/dist/node/mcp.d.ts +74 -0
- package/dist/node/mcp.d.ts.map +1 -0
- package/dist/node/mcp.js +367 -0
- package/dist/node/mcp.js.map +1 -0
- package/dist/node/platform.d.ts +35 -0
- package/dist/node/platform.d.ts.map +1 -0
- package/dist/node/platform.js +102 -0
- package/dist/node/platform.js.map +1 -0
- package/dist/node/runner-session.d.ts +41 -0
- package/dist/node/runner-session.d.ts.map +1 -0
- package/dist/node/runner-session.js +100 -0
- package/dist/node/runner-session.js.map +1 -0
- package/dist/node/runner.d.ts +63 -0
- package/dist/node/runner.d.ts.map +1 -0
- package/dist/node/runner.js +341 -0
- package/dist/node/runner.js.map +1 -0
- package/dist/node/service-child.d.ts +2 -0
- package/dist/node/service-child.d.ts.map +1 -0
- package/dist/node/service-child.js +40 -0
- package/dist/node/service-child.js.map +1 -0
- package/dist/node/service-excerpt.d.ts +21 -0
- package/dist/node/service-excerpt.d.ts.map +1 -0
- package/dist/node/service-excerpt.js +32 -0
- package/dist/node/service-excerpt.js.map +1 -0
- package/dist/node/service-process.d.ts +12 -0
- package/dist/node/service-process.d.ts.map +1 -0
- package/dist/node/service-process.js +132 -0
- package/dist/node/service-process.js.map +1 -0
- package/dist/node/session-input.d.ts +12 -0
- package/dist/node/session-input.d.ts.map +1 -0
- package/dist/node/session-input.js +42 -0
- package/dist/node/session-input.js.map +1 -0
- package/dist/node/session-view.d.ts +20 -0
- package/dist/node/session-view.d.ts.map +1 -0
- package/dist/node/session-view.js +198 -0
- package/dist/node/session-view.js.map +1 -0
- package/dist/node-agent.d.ts +2 -0
- package/dist/node-agent.d.ts.map +1 -0
- package/dist/node-agent.js +6 -0
- package/dist/node-agent.js.map +1 -0
- package/dist/node.d.ts +2 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +9 -0
- package/dist/node.js.map +1 -0
- package/dist/sandbox/agent.d.ts +187 -0
- package/dist/sandbox/agent.d.ts.map +1 -0
- package/dist/sandbox/agent.js +468 -0
- package/dist/sandbox/agent.js.map +1 -0
- package/dist/sandbox/business-store.d.ts +19 -0
- package/dist/sandbox/business-store.d.ts.map +1 -0
- package/dist/sandbox/business-store.js +19 -0
- package/dist/sandbox/business-store.js.map +1 -0
- package/dist/sandbox/business.d.ts +70 -0
- package/dist/sandbox/business.d.ts.map +1 -0
- package/dist/sandbox/business.js +115 -0
- package/dist/sandbox/business.js.map +1 -0
- package/dist/sandbox/connect.d.ts +64 -0
- package/dist/sandbox/connect.d.ts.map +1 -0
- package/dist/sandbox/connect.js +182 -0
- package/dist/sandbox/connect.js.map +1 -0
- package/dist/sandbox/deployment.d.ts +14 -0
- package/dist/sandbox/deployment.d.ts.map +1 -0
- package/dist/sandbox/deployment.js +38 -0
- package/dist/sandbox/deployment.js.map +1 -0
- package/dist/sandbox/keys.d.ts +45 -0
- package/dist/sandbox/keys.d.ts.map +1 -0
- package/dist/sandbox/keys.js +132 -0
- package/dist/sandbox/keys.js.map +1 -0
- package/dist/sandbox/mailbox.d.ts +90 -0
- package/dist/sandbox/mailbox.d.ts.map +1 -0
- package/dist/sandbox/mailbox.js +400 -0
- package/dist/sandbox/mailbox.js.map +1 -0
- package/dist/sandbox/mandate.d.ts +84 -0
- package/dist/sandbox/mandate.d.ts.map +1 -0
- package/dist/sandbox/mandate.js +107 -0
- package/dist/sandbox/mandate.js.map +1 -0
- package/dist/sandbox/namespace.d.ts +16 -0
- package/dist/sandbox/namespace.d.ts.map +1 -0
- package/dist/sandbox/namespace.js +16 -0
- package/dist/sandbox/namespace.js.map +1 -0
- package/dist/sandbox/session.d.ts +60 -0
- package/dist/sandbox/session.d.ts.map +1 -0
- package/dist/sandbox/session.js +94 -0
- package/dist/sandbox/session.js.map +1 -0
- package/dist/sandbox/setup.d.ts +136 -0
- package/dist/sandbox/setup.d.ts.map +1 -0
- package/dist/sandbox/setup.js +490 -0
- package/dist/sandbox/setup.js.map +1 -0
- package/dist/sandbox/store.d.ts +69 -0
- package/dist/sandbox/store.d.ts.map +1 -0
- package/dist/sandbox/store.js +115 -0
- package/dist/sandbox/store.js.map +1 -0
- package/dist/sandbox/supplier-key.d.ts +73 -0
- package/dist/sandbox/supplier-key.d.ts.map +1 -0
- package/dist/sandbox/supplier-key.js +180 -0
- package/dist/sandbox/supplier-key.js.map +1 -0
- package/dist/sandbox/suppliers.d.ts +7 -0
- package/dist/sandbox/suppliers.d.ts.map +1 -0
- package/dist/sandbox/suppliers.js +29 -0
- package/dist/sandbox/suppliers.js.map +1 -0
- package/dist/sandbox/terms.d.ts +32 -0
- package/dist/sandbox/terms.d.ts.map +1 -0
- package/dist/sandbox/terms.js +58 -0
- package/dist/sandbox/terms.js.map +1 -0
- package/dist/sandbox/vault.d.ts +24 -0
- package/dist/sandbox/vault.d.ts.map +1 -0
- package/dist/sandbox/vault.js +54 -0
- package/dist/sandbox/vault.js.map +1 -0
- package/dist/send.d.ts +122 -0
- package/dist/send.d.ts.map +1 -0
- package/dist/send.js +328 -0
- package/dist/send.js.map +1 -0
- package/dist/service-entry.d.ts +6 -0
- package/dist/service-entry.d.ts.map +1 -0
- package/dist/service-entry.js +6 -0
- package/dist/service-entry.js.map +1 -0
- package/dist/session/anthropic.d.ts +17 -0
- package/dist/session/anthropic.d.ts.map +1 -0
- package/dist/session/anthropic.js +215 -0
- package/dist/session/anthropic.js.map +1 -0
- package/dist/session/charge.d.ts +13 -0
- package/dist/session/charge.d.ts.map +1 -0
- package/dist/session/charge.js +33 -0
- package/dist/session/charge.js.map +1 -0
- package/dist/session/data.d.ts +8 -0
- package/dist/session/data.d.ts.map +1 -0
- package/dist/session/data.js +20 -0
- package/dist/session/data.js.map +1 -0
- package/dist/session/eval.d.ts +41 -0
- package/dist/session/eval.d.ts.map +1 -0
- package/dist/session/eval.js +281 -0
- package/dist/session/eval.js.map +1 -0
- package/dist/session/executor.d.ts +80 -0
- package/dist/session/executor.d.ts.map +1 -0
- package/dist/session/executor.js +381 -0
- package/dist/session/executor.js.map +1 -0
- package/dist/session/fixture-world.d.ts +29 -0
- package/dist/session/fixture-world.d.ts.map +1 -0
- package/dist/session/fixture-world.js +708 -0
- package/dist/session/fixture-world.js.map +1 -0
- package/dist/session/live-world.d.ts +22 -0
- package/dist/session/live-world.d.ts.map +1 -0
- package/dist/session/live-world.js +329 -0
- package/dist/session/live-world.js.map +1 -0
- package/dist/session/ollama.d.ts +29 -0
- package/dist/session/ollama.d.ts.map +1 -0
- package/dist/session/ollama.js +177 -0
- package/dist/session/ollama.js.map +1 -0
- package/dist/session/provider.d.ts +79 -0
- package/dist/session/provider.d.ts.map +1 -0
- package/dist/session/provider.js +19 -0
- package/dist/session/provider.js.map +1 -0
- package/dist/session/scripted.d.ts +45 -0
- package/dist/session/scripted.d.ts.map +1 -0
- package/dist/session/scripted.js +236 -0
- package/dist/session/scripted.js.map +1 -0
- package/dist/session/selection.d.ts +37 -0
- package/dist/session/selection.d.ts.map +1 -0
- package/dist/session/selection.js +104 -0
- package/dist/session/selection.js.map +1 -0
- package/dist/session/service-check.d.ts +48 -0
- package/dist/session/service-check.d.ts.map +1 -0
- package/dist/session/service-check.js +86 -0
- package/dist/session/service-check.js.map +1 -0
- package/dist/session/service.d.ts +128 -0
- package/dist/session/service.d.ts.map +1 -0
- package/dist/session/service.js +150 -0
- package/dist/session/service.js.map +1 -0
- package/dist/session/session.d.ts +95 -0
- package/dist/session/session.d.ts.map +1 -0
- package/dist/session/session.js +312 -0
- package/dist/session/session.js.map +1 -0
- package/dist/session/toolbox.d.ts +69 -0
- package/dist/session/toolbox.d.ts.map +1 -0
- package/dist/session/toolbox.js +391 -0
- package/dist/session/toolbox.js.map +1 -0
- package/dist/session/tools.d.ts +45 -0
- package/dist/session/tools.d.ts.map +1 -0
- package/dist/session/tools.js +137 -0
- package/dist/session/tools.js.map +1 -0
- package/dist/session/world.d.ts +188 -0
- package/dist/session/world.d.ts.map +1 -0
- package/dist/session/world.js +2 -0
- package/dist/session/world.js.map +1 -0
- package/dist/sign.d.ts +19 -0
- package/dist/sign.d.ts.map +1 -0
- package/dist/sign.js +33 -0
- package/dist/sign.js.map +1 -0
- package/dist/supplier.d.ts +41 -0
- package/dist/supplier.d.ts.map +1 -0
- package/dist/supplier.js +57 -0
- package/dist/supplier.js.map +1 -0
- package/package.json +56 -3
package/dist/agent.js
ADDED
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
import { approvalCaps, approvalDigest, approvalMandateProblem, approvalPartiesProblem, approvalTermsProblem, approvalTokenProblem, chainedTermsShapeProblem, checkEnvelope, checkMandate, digestOf, isChainedTerms, isKeySignature, isTermsV1, lockTerms, MESSAGE_VERSIONS, mandateHash, newSalt, startReceiptTypedData, termsAgreementTypedData, termsHash, termsShapeProblem, } from '@avow-finance/spec';
|
|
2
|
+
import { readBacking, verifyDependencies, } from '@avow-finance/verifier';
|
|
3
|
+
import { hexToBigInt, isAddressEqual, toHex, } from 'viem';
|
|
4
|
+
import { getBlock, getTransactionReceipt } from 'viem/actions';
|
|
5
|
+
import { reserveCalls } from './lock.js';
|
|
6
|
+
import { SEND_LIMITS, SendError, sendSponsored } from './send.js';
|
|
7
|
+
/**
|
|
8
|
+
* A booking whose funding failed after Avow approved it. The agent has already read the lock
|
|
9
|
+
* after the approval stopped working, so `failed` means no reserve was funded and none can be.
|
|
10
|
+
* `unknown` means the chain didn't show the outcome in time. It carries the commitment and every
|
|
11
|
+
* transaction hash sent, so the agent can `reconcile` this booking later instead of making
|
|
12
|
+
* another one.
|
|
13
|
+
*/
|
|
14
|
+
export class BookingError extends Error {
|
|
15
|
+
outcome;
|
|
16
|
+
/** The commitment, whose terms are version 3 only when `commitToQuote` made it. */
|
|
17
|
+
commitment;
|
|
18
|
+
hashes;
|
|
19
|
+
constructor(message, outcome, commitment, hashes, options) {
|
|
20
|
+
super(message, options);
|
|
21
|
+
this.name = 'BookingError';
|
|
22
|
+
this.outcome = outcome;
|
|
23
|
+
this.commitment = commitment;
|
|
24
|
+
this.hashes = [...hashes];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Every call of Avow's records, so a JavaScript caller's `records` is checked for each. */
|
|
28
|
+
const RECORD_CALLS = Object.keys({
|
|
29
|
+
cancel: true,
|
|
30
|
+
requestStart: true,
|
|
31
|
+
recordStart: true,
|
|
32
|
+
});
|
|
33
|
+
const randomUint = () => hexToBigInt(toHex(crypto.getRandomValues(new Uint8Array(16))));
|
|
34
|
+
const systemClock = () => BigInt(Math.floor(Date.now() / 1000));
|
|
35
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
36
|
+
/**
|
|
37
|
+
* An agent that makes commitments under its mandate. It agrees terms with a supplier, asks Avow to
|
|
38
|
+
* approve the reserve, checks Avow's approval against the terms and the mandate before any money
|
|
39
|
+
* moves, and funds the reserve from the business's account with its own key while Avow's relay
|
|
40
|
+
* pays the fee. It cancels and starts jobs only through an `AvowApi` that has `records`.
|
|
41
|
+
*/
|
|
42
|
+
export function createAgent(config) {
|
|
43
|
+
const { client, key, avow, token } = config;
|
|
44
|
+
const mandate = config.mandate.message;
|
|
45
|
+
const d = {
|
|
46
|
+
chainId: config.mandate.chainId,
|
|
47
|
+
verifyingContract: config.mandate.lock,
|
|
48
|
+
};
|
|
49
|
+
const envelope = checkEnvelope(config.mandate, { type: 'Mandate', chainId: client.chain.id });
|
|
50
|
+
if (envelope)
|
|
51
|
+
throw new Error(`The mandate can't be used on this chain (${envelope})`);
|
|
52
|
+
if (!isAddressEqual(mandate.agentKey, key.accessKeyAddress)) {
|
|
53
|
+
throw new Error("The mandate names another agent key than this agent's");
|
|
54
|
+
}
|
|
55
|
+
if (!isAddressEqual(mandate.account, key.address)) {
|
|
56
|
+
throw new Error("The mandate names another business account than the key's");
|
|
57
|
+
}
|
|
58
|
+
if (token.chainId !== d.chainId || token.currency !== mandate.currency) {
|
|
59
|
+
throw new Error("The token isn't on the mandate's chain or in its currency");
|
|
60
|
+
}
|
|
61
|
+
const mHash = mandateHash(mandate, d);
|
|
62
|
+
const now = config.now ?? systemClock;
|
|
63
|
+
const offerValidity = config.offerValidity ?? 600n;
|
|
64
|
+
const maxApprovalValidity = config.maxApprovalValidity ?? 300n;
|
|
65
|
+
const permits = (action) => mandate.actions.includes(action);
|
|
66
|
+
// An AvowApi serves all of Avow's record calls or none. TypeScript refuses a partial group, and
|
|
67
|
+
// this refuses one from a JavaScript caller when the agent is made, before any call needs it.
|
|
68
|
+
const served = avow.records;
|
|
69
|
+
if (served) {
|
|
70
|
+
const missing = RECORD_CALLS.filter((call) => typeof served[call] !== 'function');
|
|
71
|
+
if (missing.length > 0) {
|
|
72
|
+
throw new Error(`The AvowApi's records lack ${missing.join(' and ')}. An AvowApi serves all of Avow's record calls or none.`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Avow's records of cancellations and starts. TypeScript gives an agent `cancel` and `start` only
|
|
77
|
+
* when its `AvowApi` has them, so this refusal is for a JavaScript caller, before anything is
|
|
78
|
+
* read or sent.
|
|
79
|
+
*/
|
|
80
|
+
const records = (what) => {
|
|
81
|
+
if (!served) {
|
|
82
|
+
throw new Error(`The AvowApi this agent uses has no records, so it can't ${what}. httpAvowApi serves them.`);
|
|
83
|
+
}
|
|
84
|
+
return served;
|
|
85
|
+
};
|
|
86
|
+
const send = config.send ??
|
|
87
|
+
((calls) => sendSponsored({
|
|
88
|
+
client,
|
|
89
|
+
account: key,
|
|
90
|
+
calls,
|
|
91
|
+
sponsor: (transaction) => avow.sponsor(transaction),
|
|
92
|
+
...(config.limits ? { limits: config.limits } : {}),
|
|
93
|
+
}));
|
|
94
|
+
/**
|
|
95
|
+
* Why an approval differs from what the agent asked for, or null when it doesn't. The lock
|
|
96
|
+
* enforces what the approval says, so the agent funds only an approval that names exactly the
|
|
97
|
+
* terms, parties and mandate it agreed, and that the lock will still take.
|
|
98
|
+
*/
|
|
99
|
+
function approvalProblem(approval, expected) {
|
|
100
|
+
const envelopeProblem = checkEnvelope(approval, {
|
|
101
|
+
type: 'Approval',
|
|
102
|
+
chainId: d.chainId,
|
|
103
|
+
lock: d.verifyingContract,
|
|
104
|
+
});
|
|
105
|
+
if (envelopeProblem)
|
|
106
|
+
return envelopeProblem;
|
|
107
|
+
const a = approval.message;
|
|
108
|
+
if (a.commitmentId.toLowerCase() !== expected.commitmentId.toLowerCase()) {
|
|
109
|
+
return 'approval.commitment_mismatch';
|
|
110
|
+
}
|
|
111
|
+
const parties = approvalPartiesProblem(a, expected.supplier);
|
|
112
|
+
if (parties)
|
|
113
|
+
return parties;
|
|
114
|
+
const tokenProblem = approvalTokenProblem(a, token.token);
|
|
115
|
+
if (tokenProblem)
|
|
116
|
+
return tokenProblem;
|
|
117
|
+
const termsProblem = approvalTermsProblem(a, {
|
|
118
|
+
lock: lockTerms(expected.terms, token.decimals),
|
|
119
|
+
termsHash: expected.termsHash,
|
|
120
|
+
});
|
|
121
|
+
if (termsProblem)
|
|
122
|
+
return termsProblem;
|
|
123
|
+
// The agent funds the reserve with its own key, so the approval has to name that key.
|
|
124
|
+
const mandateProblem = approvalMandateProblem(a, {
|
|
125
|
+
mandateHash: mHash,
|
|
126
|
+
caps: approvalCaps(mandate, token.decimals),
|
|
127
|
+
fundingKeys: [key.accessKeyAddress],
|
|
128
|
+
});
|
|
129
|
+
if (mandateProblem)
|
|
130
|
+
return mandateProblem;
|
|
131
|
+
// The lock refuses an approval past its expiry or its acceptance deadline.
|
|
132
|
+
if (a.expiry <= now())
|
|
133
|
+
return 'message.expired';
|
|
134
|
+
if (a.acceptBy <= now())
|
|
135
|
+
return 'authorization.accept_by_passed';
|
|
136
|
+
if (a.expiry > now() + maxApprovalValidity)
|
|
137
|
+
return 'message.validity_too_long';
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* What the lock holds for the commitment as of the block the funding landed in, read again
|
|
142
|
+
* while the node answers with an error, since a node without the block refuses the read.
|
|
143
|
+
*/
|
|
144
|
+
async function backingAt(commitmentId, blockNumber) {
|
|
145
|
+
for (let i = 1;; i++) {
|
|
146
|
+
try {
|
|
147
|
+
return await readBacking(client, d.verifyingContract, commitmentId, 'buyer', {
|
|
148
|
+
blockNumber,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
if (i >= 6)
|
|
153
|
+
throw error;
|
|
154
|
+
await sleep(1500);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const limits = config.limits ?? SEND_LIMITS;
|
|
159
|
+
/**
|
|
160
|
+
* The first of the agent's own transactions whose receipt shows it succeeded with a log from the
|
|
161
|
+
* lock, or null when none shows one. That's when the reserve landed in a transaction the agent
|
|
162
|
+
* didn't send, or when a receipt couldn't be read.
|
|
163
|
+
*/
|
|
164
|
+
async function landedOf(hashes) {
|
|
165
|
+
for (const hash of hashes) {
|
|
166
|
+
const receipt = await getTransactionReceipt(client, { hash }).catch(() => null);
|
|
167
|
+
if (receipt?.status === 'success' &&
|
|
168
|
+
receipt.logs.some((l) => isAddressEqual(l.address, d.verifyingContract))) {
|
|
169
|
+
return hash;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Reads the lock for an approved commitment once no transaction carrying Avow's approval can
|
|
176
|
+
* still land. The lock takes the approval only in a block before its expiry and before the
|
|
177
|
+
* acceptance deadline, so it reads the lock as of a finalized block at or past the earlier of
|
|
178
|
+
* the two, which no later block can change. It waits for that block up to the limit's receipt
|
|
179
|
+
* timeout.
|
|
180
|
+
*/
|
|
181
|
+
async function reconcile(approved, hashes = []) {
|
|
182
|
+
const a = approved.approval.message;
|
|
183
|
+
const closes = a.expiry < a.acceptBy ? a.expiry : a.acceptBy;
|
|
184
|
+
const digest = approvalDigest(a, d).toLowerCase();
|
|
185
|
+
const deadline = Date.now() + limits.receiptTimeout;
|
|
186
|
+
for (;;) {
|
|
187
|
+
const final = await getBlock(client, { blockTag: 'finalized' }).catch(() => null);
|
|
188
|
+
if (final && final.timestamp >= closes) {
|
|
189
|
+
const read = (at) => readBacking(client, d.verifyingContract, approved.commitmentId, 'buyer', at === undefined ? {} : { blockNumber: at }).catch(() => undefined);
|
|
190
|
+
// A read that fails is read again, never taken as an empty lock.
|
|
191
|
+
const held = await read(final.number);
|
|
192
|
+
if (held) {
|
|
193
|
+
if (held.approvalHash.toLowerCase() !== digest)
|
|
194
|
+
return { outcome: 'unknown' };
|
|
195
|
+
return { outcome: 'funded', reservedIn: await landedOf(hashes) };
|
|
196
|
+
}
|
|
197
|
+
if (held === null) {
|
|
198
|
+
// Nothing carrying the approval can land after that block, so the latest block has to
|
|
199
|
+
// agree. A node that answered the past block from other state shows up here.
|
|
200
|
+
const latest = await read();
|
|
201
|
+
if (latest === null)
|
|
202
|
+
return { outcome: 'failed' };
|
|
203
|
+
if (latest)
|
|
204
|
+
return { outcome: 'unknown' };
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (Date.now() > deadline)
|
|
208
|
+
return { outcome: 'unknown' };
|
|
209
|
+
await sleep(limits.wait);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/** Why a supplier's start receipt doesn't answer the start request, or null when it does. */
|
|
213
|
+
function receiptProblem(receipt, expected) {
|
|
214
|
+
const envelopeProblem = checkEnvelope(receipt, {
|
|
215
|
+
type: 'StartReceipt',
|
|
216
|
+
chainId: d.chainId,
|
|
217
|
+
lock: d.verifyingContract,
|
|
218
|
+
});
|
|
219
|
+
if (envelopeProblem)
|
|
220
|
+
return envelopeProblem;
|
|
221
|
+
const m = receipt.message;
|
|
222
|
+
if (m.commitmentId.toLowerCase() !== expected.commitmentId.toLowerCase() ||
|
|
223
|
+
m.startRequestHash.toLowerCase() !== expected.startRequestHash.toLowerCase() ||
|
|
224
|
+
m.side !== 'buyer' ||
|
|
225
|
+
m.startedAt < expected.requestedAt) {
|
|
226
|
+
return 'message.invalid';
|
|
227
|
+
}
|
|
228
|
+
if (m.expiry <= now())
|
|
229
|
+
return 'message.expired';
|
|
230
|
+
const digest = digestOf(startReceiptTypedData(m, d));
|
|
231
|
+
if (!isKeySignature(digest, receipt.signature, expected.signer)) {
|
|
232
|
+
return 'message.signature_invalid';
|
|
233
|
+
}
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
// Every agent has `cancel` and `start` at run time, so a JavaScript caller whose `AvowApi` has
|
|
237
|
+
// no records learns why from the error. `Agent<A>` shows them only when `A` has records.
|
|
238
|
+
/** The reserve request Avow approves and the mandate check reads, for terms of either version. */
|
|
239
|
+
function requestOf(commitmentId, supplier, category, terms) {
|
|
240
|
+
return {
|
|
241
|
+
commitmentId,
|
|
242
|
+
agentKey: key.accessKeyAddress,
|
|
243
|
+
supplier: supplier.businessId,
|
|
244
|
+
payee: supplier.payee,
|
|
245
|
+
category,
|
|
246
|
+
terms,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* The same check Avow and a supplier's verifier run, or null when it approves. The lock enforces
|
|
251
|
+
* the open reserves cap, so this check counts none open, as the verifier does. The SDK can't yet
|
|
252
|
+
* carry the administrator's approval in person, so a reserve the mandate sends to them is
|
|
253
|
+
* refused.
|
|
254
|
+
*/
|
|
255
|
+
function mandateCheck(request) {
|
|
256
|
+
const allowed = checkMandate({
|
|
257
|
+
mandate,
|
|
258
|
+
request,
|
|
259
|
+
token,
|
|
260
|
+
openReserves: 0n,
|
|
261
|
+
revoked: false,
|
|
262
|
+
now: now(),
|
|
263
|
+
profile: config.profile,
|
|
264
|
+
});
|
|
265
|
+
return allowed.result === 'approved' ? null : allowed.reason;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Signs the agreement as the buyer once the supplier's signature checks out, asks Avow to
|
|
269
|
+
* approve the reserve, and checks the approval against the terms and the mandate. Version 3
|
|
270
|
+
* terms then pass `verifyDependencies` on that approval, which names the owner of each booking
|
|
271
|
+
* they rely on, and the mandate check on the checked terms. Only then is the reserve funded.
|
|
272
|
+
*/
|
|
273
|
+
async function commitAgreed(a) {
|
|
274
|
+
const { supplier, terms, salt, agreement } = a;
|
|
275
|
+
const digest = digestOf(termsAgreementTypedData(agreement, d));
|
|
276
|
+
if (!isKeySignature(digest, a.supplierSignature, supplier.signingKey)) {
|
|
277
|
+
return { ok: false, reason: 'message.signature_invalid', layer: 'sdk' };
|
|
278
|
+
}
|
|
279
|
+
const buyerSignature = await key.sign({ hash: digest, raw: true });
|
|
280
|
+
const signed = {
|
|
281
|
+
type: 'TermsAgreement',
|
|
282
|
+
schemaVersion: MESSAGE_VERSIONS.TermsAgreement,
|
|
283
|
+
chainId: d.chainId,
|
|
284
|
+
lock: d.verifyingContract,
|
|
285
|
+
message: agreement,
|
|
286
|
+
buyerSignature,
|
|
287
|
+
supplierSignature: a.supplierSignature,
|
|
288
|
+
};
|
|
289
|
+
const { commitmentId } = agreement;
|
|
290
|
+
const request = requestOf(commitmentId, supplier, agreement.category, terms);
|
|
291
|
+
const answer = await avow.approveReserve({
|
|
292
|
+
request,
|
|
293
|
+
salt,
|
|
294
|
+
agreement: signed,
|
|
295
|
+
fundedBy: 'agent',
|
|
296
|
+
});
|
|
297
|
+
if (!answer.ok) {
|
|
298
|
+
return { ok: false, reason: answer.reason, layer: 'avow', decisionId: answer.decisionId };
|
|
299
|
+
}
|
|
300
|
+
const { decisionId } = answer;
|
|
301
|
+
const problem = approvalProblem(answer.approval, {
|
|
302
|
+
commitmentId,
|
|
303
|
+
supplier,
|
|
304
|
+
terms,
|
|
305
|
+
termsHash: agreement.termsHash,
|
|
306
|
+
});
|
|
307
|
+
if (problem)
|
|
308
|
+
return { ok: false, reason: problem, layer: 'sdk', decisionId };
|
|
309
|
+
let dependencies = [];
|
|
310
|
+
if (isChainedTerms(terms)) {
|
|
311
|
+
const relied = await verifyDependencies({ terms, approval: answer.approval.message, disclosed: a.disclosed ?? [], now: now() }, config.dependencies ?? { readers: [] });
|
|
312
|
+
if (!relied.ok)
|
|
313
|
+
return { ...relied, layer: 'sdk', decisionId };
|
|
314
|
+
const allowed = mandateCheck({ ...request, terms: relied.terms });
|
|
315
|
+
if (allowed)
|
|
316
|
+
return { ok: false, reason: allowed, layer: 'sdk', decisionId };
|
|
317
|
+
dependencies = relied.checked;
|
|
318
|
+
}
|
|
319
|
+
const approved = {
|
|
320
|
+
commitmentId,
|
|
321
|
+
supplier,
|
|
322
|
+
terms,
|
|
323
|
+
salt,
|
|
324
|
+
termsHash: agreement.termsHash,
|
|
325
|
+
agreement: signed,
|
|
326
|
+
approval: answer.approval,
|
|
327
|
+
};
|
|
328
|
+
const reservedIn = await fund(approved);
|
|
329
|
+
return { ok: true, commitment: { ...approved, reservedIn }, dependencies };
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Funds an approved reserve with the agent's key and returns the transaction that funded it,
|
|
333
|
+
* once the lock holds the commitment under exactly the approval the agent checked. When funding
|
|
334
|
+
* fails it reads the lock after the approval stops working, returns if the reserve landed
|
|
335
|
+
* anyway, and otherwise throws a `BookingError`.
|
|
336
|
+
*/
|
|
337
|
+
async function fund(approved) {
|
|
338
|
+
const { commitmentId, approval } = approved;
|
|
339
|
+
let landed = null;
|
|
340
|
+
let failure = null;
|
|
341
|
+
try {
|
|
342
|
+
landed = await send(reserveCalls(approval, d));
|
|
343
|
+
}
|
|
344
|
+
catch (error) {
|
|
345
|
+
failure = error;
|
|
346
|
+
}
|
|
347
|
+
if (landed) {
|
|
348
|
+
const held = await backingAt(commitmentId, landed.blockNumber).catch(() => null);
|
|
349
|
+
const expected = approvalDigest(approval.message, d).toLowerCase();
|
|
350
|
+
if (held && held.approvalHash.toLowerCase() === expected)
|
|
351
|
+
return landed.transactionHash;
|
|
352
|
+
}
|
|
353
|
+
const hashes = failure instanceof SendError ? failure.hashes : landed ? [landed.transactionHash] : [];
|
|
354
|
+
const what = failure
|
|
355
|
+
? failure instanceof Error
|
|
356
|
+
? failure.message
|
|
357
|
+
: String(failure)
|
|
358
|
+
: `${landed?.transactionHash} landed, but the lock didn't show the reserve under Avow's approval`;
|
|
359
|
+
// A transaction the key never signed can't land, so a send that failed before signing
|
|
360
|
+
// settles the booking.
|
|
361
|
+
if (failure instanceof SendError && failure.signings === 0) {
|
|
362
|
+
throw new BookingError(`Funding ${commitmentId} failed: ${what}`, 'failed', approved, hashes, {
|
|
363
|
+
cause: failure,
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
const settled = await reconcile(approved, hashes);
|
|
367
|
+
if (settled.outcome === 'funded')
|
|
368
|
+
return settled.reservedIn;
|
|
369
|
+
throw new BookingError(settled.outcome === 'failed'
|
|
370
|
+
? `Funding ${commitmentId} failed, and the lock holds no reserve for it: ${what}`
|
|
371
|
+
: `Whether ${commitmentId} was funded is unknown: ${what}`, settled.outcome, approved, hashes, { cause: failure ?? undefined });
|
|
372
|
+
}
|
|
373
|
+
const agent = {
|
|
374
|
+
account: mandate.account,
|
|
375
|
+
lock: d.verifyingContract,
|
|
376
|
+
domain: d,
|
|
377
|
+
mandateHash: mHash,
|
|
378
|
+
async book(b) {
|
|
379
|
+
const { terms } = b;
|
|
380
|
+
// A new commitment takes version 2 terms. Version 1 is only for commitments made under it,
|
|
381
|
+
// and version 3 terms come signed by their supplier through `commitToQuote`, so both stop
|
|
382
|
+
// here, before anything is signed.
|
|
383
|
+
if (isTermsV1(terms) || isChainedTerms(terms)) {
|
|
384
|
+
return { ok: false, reason: 'terms.version_unknown' };
|
|
385
|
+
}
|
|
386
|
+
const supplier = b.supplier.profile;
|
|
387
|
+
const commitmentId = toHex(crypto.getRandomValues(new Uint8Array(32)));
|
|
388
|
+
const allowed = mandateCheck(requestOf(commitmentId, supplier, b.category, terms));
|
|
389
|
+
if (allowed)
|
|
390
|
+
return { ok: false, reason: allowed };
|
|
391
|
+
const salt = newSalt();
|
|
392
|
+
const agreement = {
|
|
393
|
+
commitmentId,
|
|
394
|
+
termsHash: termsHash(terms, salt),
|
|
395
|
+
category: b.category,
|
|
396
|
+
buyerBusinessId: mandate.businessId,
|
|
397
|
+
supplierBusinessId: supplier.businessId,
|
|
398
|
+
mandateHash: mHash,
|
|
399
|
+
nonce: randomUint(),
|
|
400
|
+
expiry: now() + offerValidity,
|
|
401
|
+
};
|
|
402
|
+
const supplierSignature = await b.supplier.signAgreement({
|
|
403
|
+
agreement,
|
|
404
|
+
terms,
|
|
405
|
+
salt,
|
|
406
|
+
domain: d,
|
|
407
|
+
});
|
|
408
|
+
const done = await commitAgreed({ supplier, terms, salt, agreement, supplierSignature });
|
|
409
|
+
if (done.ok)
|
|
410
|
+
return { ok: true, commitment: { ...done.commitment, terms } };
|
|
411
|
+
return done.decisionId === undefined
|
|
412
|
+
? { ok: false, reason: done.reason }
|
|
413
|
+
: { ok: false, reason: done.reason, decisionId: done.decisionId };
|
|
414
|
+
},
|
|
415
|
+
async commitToQuote(q) {
|
|
416
|
+
const { terms, agreement: a } = q;
|
|
417
|
+
if (isTermsV1(terms))
|
|
418
|
+
return { ok: false, reason: 'terms.version_unknown', layer: 'sdk' };
|
|
419
|
+
const shape = isChainedTerms(terms)
|
|
420
|
+
? chainedTermsShapeProblem(terms)
|
|
421
|
+
: termsShapeProblem(terms);
|
|
422
|
+
if (shape)
|
|
423
|
+
return { ok: false, reason: shape, layer: 'sdk' };
|
|
424
|
+
if (termsHash(terms, q.salt).toLowerCase() !== a.termsHash.toLowerCase()) {
|
|
425
|
+
return { ok: false, reason: 'terms.hash_mismatch', layer: 'sdk' };
|
|
426
|
+
}
|
|
427
|
+
const parties = a.buyerBusinessId === mandate.businessId &&
|
|
428
|
+
a.mandateHash.toLowerCase() === mHash.toLowerCase() &&
|
|
429
|
+
a.supplierBusinessId === q.supplier.businessId;
|
|
430
|
+
if (!parties)
|
|
431
|
+
return { ok: false, reason: 'agreement.parties_mismatch', layer: 'sdk' };
|
|
432
|
+
if (a.expiry <= now())
|
|
433
|
+
return { ok: false, reason: 'message.expired', layer: 'sdk' };
|
|
434
|
+
if (a.expiry > now() + offerValidity) {
|
|
435
|
+
return { ok: false, reason: 'message.validity_too_long', layer: 'sdk' };
|
|
436
|
+
}
|
|
437
|
+
// Version 2 terms go through the mandate check before anything is signed, as in `book`.
|
|
438
|
+
// Version 3 terms go through it once their bookings are checked, since it takes them only as
|
|
439
|
+
// checked terms.
|
|
440
|
+
if (!isChainedTerms(terms)) {
|
|
441
|
+
const allowed = mandateCheck(requestOf(a.commitmentId, q.supplier, a.category, terms));
|
|
442
|
+
if (allowed)
|
|
443
|
+
return { ok: false, reason: allowed, layer: 'sdk' };
|
|
444
|
+
}
|
|
445
|
+
return commitAgreed({
|
|
446
|
+
supplier: q.supplier,
|
|
447
|
+
terms,
|
|
448
|
+
salt: q.salt,
|
|
449
|
+
agreement: a,
|
|
450
|
+
supplierSignature: q.supplierSignature,
|
|
451
|
+
disclosed: q.disclosed ?? [],
|
|
452
|
+
});
|
|
453
|
+
},
|
|
454
|
+
reconcile,
|
|
455
|
+
async cancel(commitmentId) {
|
|
456
|
+
const served = records('record a cancellation');
|
|
457
|
+
if (!permits('cancel'))
|
|
458
|
+
return { ok: false, reason: 'mandate.action_not_permitted' };
|
|
459
|
+
const { cancelledAt } = await served.cancel({ commitmentId });
|
|
460
|
+
return { ok: true, cancelledAt };
|
|
461
|
+
},
|
|
462
|
+
async start(commitmentId, supplier) {
|
|
463
|
+
const served = records('start the job');
|
|
464
|
+
if (!permits('start'))
|
|
465
|
+
return { ok: false, reason: 'mandate.action_not_permitted' };
|
|
466
|
+
// The receipt has to come from the signing key the lock holds for the commitment.
|
|
467
|
+
const held = await readBacking(client, d.verifyingContract, commitmentId, 'buyer');
|
|
468
|
+
if (!held)
|
|
469
|
+
return { ok: false, reason: 'chain.reserve_missing' };
|
|
470
|
+
if (!isAddressEqual(held.supplierSigner, supplier.profile.signingKey)) {
|
|
471
|
+
return { ok: false, reason: 'chain.supplier_mismatch' };
|
|
472
|
+
}
|
|
473
|
+
const request = await served.requestStart({ commitmentId });
|
|
474
|
+
const receipt = await supplier.startJob({ commitmentId, ...request });
|
|
475
|
+
const problem = receiptProblem(receipt, {
|
|
476
|
+
commitmentId,
|
|
477
|
+
...request,
|
|
478
|
+
signer: held.supplierSigner,
|
|
479
|
+
});
|
|
480
|
+
if (problem)
|
|
481
|
+
return { ok: false, reason: problem };
|
|
482
|
+
const recorded = await served.recordStart({ commitmentId, receipt });
|
|
483
|
+
if (!recorded.ok)
|
|
484
|
+
return { ok: false, reason: recorded.reason };
|
|
485
|
+
return { ok: true, receipt };
|
|
486
|
+
},
|
|
487
|
+
commitment(commitmentId) {
|
|
488
|
+
return readBacking(client, d.verifyingContract, commitmentId, 'buyer');
|
|
489
|
+
},
|
|
490
|
+
};
|
|
491
|
+
return agent;
|
|
492
|
+
}
|
|
493
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EACZ,cAAc,EACd,sBAAsB,EACtB,sBAA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,CAAC,EAAE,YAAY,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;YACrE,MAAM,OAAO,GAAG,cAAc,CAAC,OAAO,EAAE;gBACtC,YAAY;gBACZ,GAAG,OAAO;gBACV,MAAM,EAAE,IAAI,CAAC,cAAc;aAC5B,CAAC,CAAA;YACF,IAAI,OAAO;gBAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAA;YAClD,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC,CAAA;YACpE,IAAI,CAAC,QAAQ,CAAC,EAAE;gBAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAA;YAC/D,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;QAC9B,CAAC;QAED,UAAU,CAAC,YAAiB;YAC1B,OAAO,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,iBAAiB,EAAE,YAAY,EAAE,OAAO,CAAC,CAAA;QACxE,CAAC;KACF,CAAA;IACD,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { ContestStatementAnswer, ContestStatementRequest, ReasonCode, ReserveApproval, ReserveApprovalRequest, Signed, StartReceipt } from '@avow-finance/spec';
|
|
2
|
+
import type { Hex } from 'viem';
|
|
3
|
+
export type { ReserveApproval, ReserveApprovalRequest } from '@avow-finance/spec';
|
|
4
|
+
/**
|
|
5
|
+
* Avow's records of cancellations and job starts. An `AvowApi` serves all three calls together, as
|
|
6
|
+
* its `records`, or none of them. Avow's hosted API serves all three, each answer carrying Avow's
|
|
7
|
+
* timestamp on the request.
|
|
8
|
+
*/
|
|
9
|
+
export interface AvowRecords {
|
|
10
|
+
/**
|
|
11
|
+
* Records the business cancelling a commitment, timestamped by Avow, once free cancellation has
|
|
12
|
+
* ended and until the no-show charge can be reported. Before then the business cancels on the
|
|
13
|
+
* lock, and Avow refuses with `commitment.cancel_on_lock`. After it a cancellation no longer
|
|
14
|
+
* changes the charge, and Avow refuses with `commitment.cancel_closed`. A commitment has one
|
|
15
|
+
* cancellation, so every later call gives the first one's time.
|
|
16
|
+
*/
|
|
17
|
+
cancel(request: {
|
|
18
|
+
commitmentId: Hex;
|
|
19
|
+
}): Promise<{
|
|
20
|
+
cancelledAt: bigint;
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* Timestamps the business's request to start a job. The supplier's start receipt names the
|
|
24
|
+
* request's hash, and the job can't have started before the timestamp.
|
|
25
|
+
*/
|
|
26
|
+
requestStart(request: {
|
|
27
|
+
commitmentId: Hex;
|
|
28
|
+
}): Promise<{
|
|
29
|
+
startRequestHash: Hex;
|
|
30
|
+
requestedAt: bigint;
|
|
31
|
+
}>;
|
|
32
|
+
/** Records the supplier's start receipt, which a kept booking rests on, or refuses it. */
|
|
33
|
+
recordStart(request: {
|
|
34
|
+
commitmentId: Hex;
|
|
35
|
+
receipt: Signed<StartReceipt>;
|
|
36
|
+
}): Promise<{
|
|
37
|
+
ok: true;
|
|
38
|
+
} | {
|
|
39
|
+
ok: false;
|
|
40
|
+
reason: ReasonCode;
|
|
41
|
+
}>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Avow's side of an agent's commitments. Avow's hosted API implements it over HTTP through
|
|
45
|
+
* `httpAvowApi`, which signs each request with the agent's key, and a local stand-in implements it
|
|
46
|
+
* for a demo or a test. Pre-release, so it may change before 1.0.
|
|
47
|
+
*
|
|
48
|
+
* Avow's records of cancellations and job starts are one optional group, `records`, which a
|
|
49
|
+
* stand-in for a demo or a test may leave out. `createAgent` gives an agent `cancel` and `start`
|
|
50
|
+
* only when its `AvowApi` has `records`.
|
|
51
|
+
*/
|
|
52
|
+
export interface AvowApi {
|
|
53
|
+
/** Avow's reserve check. It signs an approval the lock takes, or refuses with a reason code. */
|
|
54
|
+
approveReserve(request: ReserveApprovalRequest): Promise<ReserveApproval>;
|
|
55
|
+
/**
|
|
56
|
+
* Has Avow's relay co-sign a transaction the agent signed with `feePayer: true`, so the relay
|
|
57
|
+
* pays its fee and the business needs no fee token. It takes and returns serialized bytes, and
|
|
58
|
+
* never sends them. The relay signs only when each call goes to the business's own lock or
|
|
59
|
+
* approves that lock to pull the reserve token. The agent checks the co-signed bytes, sends them
|
|
60
|
+
* itself and tracks their hash.
|
|
61
|
+
*/
|
|
62
|
+
sponsor(transaction: Hex): Promise<Hex>;
|
|
63
|
+
/** Avow's records of cancellations and job starts, all three calls or none. */
|
|
64
|
+
records?: AvowRecords;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Avow's records the business account's own root key writes to, which Avow's hosted API serves
|
|
68
|
+
* through `httpBusinessRecords`. Pre-release, so it may change before 1.0.
|
|
69
|
+
*/
|
|
70
|
+
export interface BusinessRecords {
|
|
71
|
+
/**
|
|
72
|
+
* Gives Avow the statement for a contest the lock already took, naming the transaction that
|
|
73
|
+
* carried it, so Avow holds the text it rules on. A commitment has one statement, so posting the
|
|
74
|
+
* same one again gets the first answer, and posting again is always safe.
|
|
75
|
+
*/
|
|
76
|
+
postContestStatement(request: ContestStatementRequest): Promise<ContestStatementAnswer>;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=avow-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"avow-api.d.ts","sourceRoot":"","sources":["../src/avow-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,uBAAuB,EACvB,UAAU,EACV,eAAe,EACf,sBAAsB,EACtB,MAAM,EACN,YAAY,EACb,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAE/B,YAAY,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAEjF;;;;GAI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