@integraledger/profile-facilitator 0.4.0 → 0.5.1
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/CHANGELOG.md +107 -0
- package/README.md +781 -456
- package/dist/answers.d.ts +11 -4
- package/dist/answers.js +24 -0
- package/dist/core.d.ts +51 -0
- package/dist/core.js +758 -0
- package/dist/http.d.ts +20 -3
- package/dist/http.js +32 -7
- package/dist/index.d.ts +12 -36
- package/dist/index.js +9 -162
- package/dist/module.d.ts +372 -0
- package/dist/module.js +13 -0
- package/dist/modules/algorand/index.d.ts +22 -0
- package/dist/modules/algorand/index.js +247 -0
- package/dist/modules/algorand/own.d.ts +26 -0
- package/dist/modules/algorand/own.js +231 -0
- package/dist/modules/aptos/index.d.ts +23 -0
- package/dist/modules/aptos/index.js +232 -0
- package/dist/modules/cardano/index.d.ts +18 -0
- package/dist/modules/cardano/index.js +124 -0
- package/dist/modules/casper/index.d.ts +120 -0
- package/dist/modules/casper/index.js +442 -0
- package/dist/modules/concordium/index.d.ts +16 -0
- package/dist/modules/concordium/index.js +77 -0
- package/dist/modules/erc7710/index.d.ts +26 -0
- package/dist/modules/erc7710/index.js +220 -0
- package/dist/modules/evm/forms.d.ts +74 -0
- package/dist/modules/evm/forms.js +204 -0
- package/dist/modules/evm/index.d.ts +40 -0
- package/dist/modules/evm/index.js +154 -0
- package/dist/modules/evm/node.d.ts +29 -0
- package/dist/modules/evm/node.js +222 -0
- package/dist/modules/hedera/executor.d.ts +63 -0
- package/dist/modules/hedera/executor.js +343 -0
- package/dist/modules/hedera/index.d.ts +23 -0
- package/dist/modules/hedera/index.js +136 -0
- package/dist/modules/hedera/mirror.d.ts +32 -0
- package/dist/modules/hedera/mirror.js +111 -0
- package/dist/modules/index.d.ts +23 -0
- package/dist/modules/index.js +24 -0
- package/dist/modules/lnbtc/index.d.ts +10 -0
- package/dist/modules/lnbtc/index.js +112 -0
- package/dist/modules/near/index.d.ts +18 -0
- package/dist/modules/near/index.js +246 -0
- package/dist/modules/polkadot/index.d.ts +12 -0
- package/dist/modules/polkadot/index.js +149 -0
- package/dist/modules/polkadot/rail.d.ts +40 -0
- package/dist/{polkadot.js → modules/polkadot/rail.js} +214 -288
- package/dist/modules/solana/index.d.ts +60 -0
- package/dist/modules/solana/index.js +326 -0
- package/dist/modules/solana/reader.d.ts +25 -0
- package/dist/modules/solana/reader.js +194 -0
- package/dist/modules/solana/state.d.ts +6 -0
- package/dist/modules/solana/state.js +103 -0
- package/dist/modules/starknet/index.d.ts +35 -0
- package/dist/modules/starknet/index.js +548 -0
- package/dist/modules/starknet/node.d.ts +78 -0
- package/dist/modules/starknet/node.js +339 -0
- package/dist/modules/stellar/index.d.ts +44 -0
- package/dist/modules/stellar/index.js +481 -0
- package/dist/modules/stellar/node.d.ts +57 -0
- package/dist/modules/stellar/node.js +151 -0
- package/dist/modules/sui/index.d.ts +16 -0
- package/dist/modules/sui/index.js +310 -0
- package/dist/modules/sui/node.d.ts +49 -0
- package/dist/modules/sui/node.js +197 -0
- package/dist/modules/ton/index.d.ts +16 -0
- package/dist/modules/ton/index.js +73 -0
- package/dist/modules/tron/index.d.ts +12 -0
- package/dist/modules/tron/index.js +120 -0
- package/dist/modules/tron/rail.d.ts +32 -0
- package/dist/{tron.js → modules/tron/rail.js} +206 -195
- package/dist/modules/xrpl/index.d.ts +28 -0
- package/dist/modules/xrpl/index.js +299 -0
- package/dist/modules/xrpl/node.d.ts +52 -0
- package/dist/modules/xrpl/node.js +231 -0
- package/dist/modules/xrpl/upto.d.ts +5 -0
- package/dist/modules/xrpl/upto.js +269 -0
- package/dist/record.d.ts +131 -0
- package/dist/record.js +330 -0
- package/dist/unexpected.d.ts +3 -2
- package/dist/unexpected.js +2 -1
- package/dist/wrapper.d.ts +68 -0
- package/dist/wrapper.js +126 -0
- package/package.json +48 -12
- package/dist/polkadot.d.ts +0 -21
- package/dist/store.d.ts +0 -59
- package/dist/store.js +0 -103
- package/dist/tron.d.ts +0 -12
- /package/dist/{base58check.d.ts → modules/tron/base58check.d.ts} +0 -0
- /package/dist/{base58check.js → modules/tron/base58check.js} +0 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { FacilitatorAvmSigner } from "@x402/avm";
|
|
2
|
+
import type { PaymentPayload, PaymentRequirements, SchemeNetworkFacilitator } from "@x402/core/types";
|
|
3
|
+
/** The authority the payment entry's own members name, where it is one only this path settles. */
|
|
4
|
+
export type OwnAuthority = "rekeyed" | "falcon";
|
|
5
|
+
/**
|
|
6
|
+
* Which own authority signs the payment entry, by its members: `pqsig`, a Falcon signature; or `sig` beside `sgnr` with
|
|
7
|
+
* no other signature, the one key a rekeyed account answers to. Any other entry is the class's.
|
|
8
|
+
*/
|
|
9
|
+
export declare function ownAuthority(payload: PaymentPayload): OwnAuthority | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* The own path's facilitator: `admitted` gives lcp's checks and the payment's id (lcp's, under the transaction's own
|
|
12
|
+
* fields), or the refusal with lcp's code.
|
|
13
|
+
*/
|
|
14
|
+
export declare function ownFacilitator(signer: FacilitatorAvmSigner, admitted: (payload: PaymentPayload, r: PaymentRequirements) => Promise<{
|
|
15
|
+
txid: string;
|
|
16
|
+
} | {
|
|
17
|
+
reason: string;
|
|
18
|
+
code?: string;
|
|
19
|
+
}>): SchemeNetworkFacilitator;
|
|
20
|
+
/**
|
|
21
|
+
* The senders of the group's entries that one of `ours` sends, each of which x402's class and the own path sign as the
|
|
22
|
+
* fee payer, whatever the option names; undefined where the group does not decode, which both refuse.
|
|
23
|
+
*/
|
|
24
|
+
export declare function keyEntries(payload: PaymentPayload, ours: readonly string[]): string[] | undefined;
|
|
25
|
+
/** The fee the key's transactions in the payment's group pay: each one's own `fee`, which is what it pays once it lands. */
|
|
26
|
+
export declare function feePayerFee(signer: FacilitatorAvmSigner, payload: PaymentPayload): bigint;
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The settler's own path for the two payers of `x402/exact/algorand` that `@x402/avm` 2.31.0's class cannot settle, each
|
|
3
|
+
* told apart by the payment entry's own members: a payer whose account is rekeyed and who signs with the one key it is
|
|
4
|
+
* rekeyed to (`sig` with `sgnr`), whose signature the class checks against the sender's key instead; and a payer who
|
|
5
|
+
* signs with a Falcon key (`pqsig`), a member the class's decoder does not read. It makes lcp's checks, then the class's
|
|
6
|
+
* own checks of the group, the payment and the fee payer's transaction, with the signature checked against the key
|
|
7
|
+
* `sgnr` names; it signs the fee payer's transaction through the signer object the class takes, simulates the group,
|
|
8
|
+
* whose node verifies every signature and the account's authorization, sends it with the payment entry exactly as
|
|
9
|
+
* presented, and waits for it.
|
|
10
|
+
*/
|
|
11
|
+
import { decodeMsgpack } from "@algorandfoundation/algokit-utils/common";
|
|
12
|
+
import { ed25519Verifier } from "@algorandfoundation/algokit-utils/crypto";
|
|
13
|
+
import { bytesForSigning, decodeSignedTransaction, decodeTransaction, encodeTransactionRaw, } from "@algorandfoundation/algokit-utils/transact";
|
|
14
|
+
/** An atomic group's most transactions (go-algorand's `MaxTxGroupSize`). */
|
|
15
|
+
const MAX_GROUP = 16;
|
|
16
|
+
/** The class's cap on the fee of the fee payer's transaction: 5 000 µAlgo per transaction of the group. */
|
|
17
|
+
const MAX_FEE_PER_TRANSACTION = 5000n;
|
|
18
|
+
/** The payment entry of a payload in the scheme's form, as its bytes, or undefined. */
|
|
19
|
+
function entryOf(payload) {
|
|
20
|
+
const { paymentGroup, paymentIndex } = payload.payload;
|
|
21
|
+
if (!Array.isArray(paymentGroup) || typeof paymentIndex !== "number")
|
|
22
|
+
return undefined;
|
|
23
|
+
const entry = paymentGroup[paymentIndex];
|
|
24
|
+
return typeof entry === "string" ? new Uint8Array(Buffer.from(entry, "base64")) : undefined;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Which own authority signs the payment entry, by its members: `pqsig`, a Falcon signature; or `sig` beside `sgnr` with
|
|
28
|
+
* no other signature, the one key a rekeyed account answers to. Any other entry is the class's.
|
|
29
|
+
*/
|
|
30
|
+
export function ownAuthority(payload) {
|
|
31
|
+
const entry = entryOf(payload);
|
|
32
|
+
if (entry === undefined)
|
|
33
|
+
return undefined;
|
|
34
|
+
let members;
|
|
35
|
+
try {
|
|
36
|
+
const decoded = decodeMsgpack(entry);
|
|
37
|
+
if (!(decoded instanceof Map))
|
|
38
|
+
return undefined;
|
|
39
|
+
members = [...decoded.keys()].map((k) => (typeof k === "string" ? k : Buffer.from(k).toString("utf8")));
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
if (members.includes("pqsig"))
|
|
45
|
+
return "falcon";
|
|
46
|
+
const others = members.filter((m) => m === "msig" || m === "lsig").length;
|
|
47
|
+
return members.includes("sgnr") && members.includes("sig") && others === 0 ? "rekeyed" : undefined;
|
|
48
|
+
}
|
|
49
|
+
function fail(reason, message) {
|
|
50
|
+
return { reason, message };
|
|
51
|
+
}
|
|
52
|
+
/** Each entry of the group decoded: a signed transaction, or an unsigned one only where a fee payer the key holds sends it. */
|
|
53
|
+
function decodeGroup(group, ours) {
|
|
54
|
+
const out = [];
|
|
55
|
+
for (let i = 0; i < group.length; i++) {
|
|
56
|
+
const bytes = new Uint8Array(Buffer.from(group[i], "base64"));
|
|
57
|
+
try {
|
|
58
|
+
const signed = decodeSignedTransaction(bytes);
|
|
59
|
+
if (!signed.txn.type || signed.txn.type === "unknown")
|
|
60
|
+
throw new Error("no type");
|
|
61
|
+
out.push(signed);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
try {
|
|
65
|
+
const txn = decodeTransaction(bytes);
|
|
66
|
+
if (!ours.includes(txn.sender.toString())) {
|
|
67
|
+
return fail("invalid_exact_avm_unsigned_non_facilitator", `the unsigned transaction at ${i} is not the fee payer's`);
|
|
68
|
+
}
|
|
69
|
+
out.push({ txn });
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return fail("invalid_exact_avm_invalid_transaction", `the transaction at ${i} does not decode`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const groupOf = (s) => (s.txn.group === undefined ? "" : Buffer.from(s.txn.group).toString("base64"));
|
|
77
|
+
if (out.length > 1 && out.some((s) => groupOf(s) !== groupOf(out[0]))) {
|
|
78
|
+
return fail("invalid_exact_avm_invalid_group_id", "the transactions name different groups");
|
|
79
|
+
}
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
/** The class's checks of the fee payer's transaction: a zero payment to itself, closing nothing, rekeying nothing, its fee capped. */
|
|
83
|
+
function feePayerRefusal(s, size) {
|
|
84
|
+
const t = s.txn;
|
|
85
|
+
if (t.type !== "pay")
|
|
86
|
+
return fail("invalid_exact_avm_invalid_fee_payer", "the fee payer's transaction is not a payment");
|
|
87
|
+
if ((t.payment?.amount ?? 0n) > 0n)
|
|
88
|
+
return fail("invalid_exact_avm_invalid_fee_payer", "the fee payer pays an amount");
|
|
89
|
+
const receiver = t.payment?.receiver?.toString();
|
|
90
|
+
if (receiver !== undefined && receiver !== t.sender.toString())
|
|
91
|
+
return fail("invalid_exact_avm_invalid_fee_payer", "the fee payer pays another account");
|
|
92
|
+
if (t.payment?.closeRemainderTo !== undefined)
|
|
93
|
+
return fail("invalid_exact_avm_invalid_fee_payer", "the fee payer closes its account");
|
|
94
|
+
if (t.rekeyTo !== undefined)
|
|
95
|
+
return fail("invalid_exact_avm_invalid_fee_payer", "the fee payer rekeys its account");
|
|
96
|
+
if ((t.fee ?? 0n) > MAX_FEE_PER_TRANSACTION * BigInt(size))
|
|
97
|
+
return fail("invalid_exact_avm_fee_too_high", "the fee payer's fee exceeds its cap");
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The checks of an own payer, after lcp's (`admitted`): the group, the payment against the requirements, the
|
|
102
|
+
* authority, the fee payer's transaction, which the key then signs, and the node's simulation. The payer and the
|
|
103
|
+
* group to send, or the refusal.
|
|
104
|
+
*/
|
|
105
|
+
async function prepared(signer, payload, r) {
|
|
106
|
+
const { paymentGroup: group, paymentIndex: index } = payload.payload;
|
|
107
|
+
if (group.length > MAX_GROUP)
|
|
108
|
+
return fail("invalid_exact_avm_group_size_exceeded", `the group holds ${group.length} transactions`);
|
|
109
|
+
if (!Number.isSafeInteger(index) || index < 0 || index >= group.length)
|
|
110
|
+
return fail("invalid_exact_avm_payment_index", "the payment index is outside the group");
|
|
111
|
+
const ours = signer.getAddresses();
|
|
112
|
+
const decoded = decodeGroup(group, ours);
|
|
113
|
+
if (!Array.isArray(decoded))
|
|
114
|
+
return decoded;
|
|
115
|
+
const payment = decoded[index];
|
|
116
|
+
const t = payment.txn;
|
|
117
|
+
const payer = t.sender.toString();
|
|
118
|
+
if (ours.includes(payer))
|
|
119
|
+
return fail("invalid_exact_avm_facilitator_transferring", "the fee payer is the payment's sender");
|
|
120
|
+
if (t.type !== "axfer" || t.assetTransfer === undefined)
|
|
121
|
+
return fail("invalid_exact_avm_not_asset_transfer", "the payment is not an asset transfer");
|
|
122
|
+
if ((t.assetTransfer.amount ?? 0n) !== BigInt(r.amount))
|
|
123
|
+
return fail("invalid_exact_avm_amount_mismatch", "the amount differs");
|
|
124
|
+
if (t.assetTransfer.receiver?.toString() !== r.payTo)
|
|
125
|
+
return fail("invalid_exact_avm_receiver_mismatch", "the receiver differs");
|
|
126
|
+
if (t.assetTransfer.assetId?.toString() !== r.asset)
|
|
127
|
+
return fail("invalid_exact_avm_asset_mismatch", "the asset differs");
|
|
128
|
+
if (ownAuthority(payload) === "rekeyed") {
|
|
129
|
+
const by = payment.authAddress;
|
|
130
|
+
// The key that authorises the payment is the payer's: never the payee's and never the fee payer's own.
|
|
131
|
+
if (by.toString() === r.payTo || ours.includes(by.toString())) {
|
|
132
|
+
return fail("invalid_exact_avm_invalid_signature", "the payment is signed by the payee's or the fee payer's key");
|
|
133
|
+
}
|
|
134
|
+
if (!(await ed25519Verifier(payment.sig, bytesForSigning.transaction(t), by.publicKey))) {
|
|
135
|
+
return fail("invalid_exact_avm_invalid_signature", "the signature is not by the key sgnr names");
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const signed = [];
|
|
139
|
+
for (let i = 0; i < decoded.length; i++) {
|
|
140
|
+
const s = decoded[i];
|
|
141
|
+
const sender = s.txn.sender.toString();
|
|
142
|
+
if (!ours.includes(sender)) {
|
|
143
|
+
// Every entry the payer gave is sent as presented, a Falcon signature among it.
|
|
144
|
+
signed.push(new Uint8Array(Buffer.from(group[i], "base64")));
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
const refused = feePayerRefusal(s, decoded.length);
|
|
148
|
+
if (refused !== undefined)
|
|
149
|
+
return refused;
|
|
150
|
+
signed.push(await signer.signTransaction(encodeTransactionRaw(s.txn), sender));
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
const simulated = await signer.simulateTransactions(signed, r.network);
|
|
154
|
+
const failure = simulated.txnGroups?.[0]?.failureMessage;
|
|
155
|
+
if (failure)
|
|
156
|
+
return fail("invalid_exact_avm_simulation_failed", failure);
|
|
157
|
+
}
|
|
158
|
+
catch (e) {
|
|
159
|
+
return fail("invalid_exact_avm_simulation_failed", e instanceof Error ? e.message : String(e));
|
|
160
|
+
}
|
|
161
|
+
return { payer, signed };
|
|
162
|
+
}
|
|
163
|
+
const isFailure = (v) => "reason" in v;
|
|
164
|
+
/**
|
|
165
|
+
* The own path's facilitator: `admitted` gives lcp's checks and the payment's id (lcp's, under the transaction's own
|
|
166
|
+
* fields), or the refusal with lcp's code.
|
|
167
|
+
*/
|
|
168
|
+
export function ownFacilitator(signer, admitted) {
|
|
169
|
+
const checked = async (payload, r) => {
|
|
170
|
+
const lcp = await admitted(payload, r);
|
|
171
|
+
if ("reason" in lcp)
|
|
172
|
+
return fail(lcp.reason, lcp.code ?? lcp.reason);
|
|
173
|
+
const p = await prepared(signer, payload, r);
|
|
174
|
+
return isFailure(p) ? p : { ...p, txid: lcp.txid };
|
|
175
|
+
};
|
|
176
|
+
return {
|
|
177
|
+
scheme: "exact",
|
|
178
|
+
caipFamily: "algorand:*",
|
|
179
|
+
getExtra: () => undefined,
|
|
180
|
+
getSigners: () => [...signer.getAddresses()],
|
|
181
|
+
async verify(payload, r) {
|
|
182
|
+
const p = await checked(payload, r);
|
|
183
|
+
return isFailure(p) ? { isValid: false, invalidReason: p.reason, invalidMessage: p.message } : { isValid: true, payer: p.payer };
|
|
184
|
+
},
|
|
185
|
+
async settle(payload, r) {
|
|
186
|
+
const network = r.network;
|
|
187
|
+
const p = await checked(payload, r);
|
|
188
|
+
if (isFailure(p))
|
|
189
|
+
return { success: false, errorReason: p.reason, errorMessage: p.message, transaction: "", network };
|
|
190
|
+
try {
|
|
191
|
+
await signer.sendTransactions(p.signed, network);
|
|
192
|
+
}
|
|
193
|
+
catch (e) {
|
|
194
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
195
|
+
return { success: false, errorReason: "invalid_exact_avm_settlement_failed", errorMessage: message, transaction: p.txid, network, payer: p.payer };
|
|
196
|
+
}
|
|
197
|
+
try {
|
|
198
|
+
await signer.waitForConfirmation(p.txid, network, 10);
|
|
199
|
+
}
|
|
200
|
+
catch (e) {
|
|
201
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
202
|
+
return { success: false, errorReason: "invalid_exact_avm_confirmation_failed", errorMessage: message, transaction: p.txid, network, payer: p.payer };
|
|
203
|
+
}
|
|
204
|
+
return { success: true, transaction: p.txid, network, payer: p.payer };
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* The senders of the group's entries that one of `ours` sends, each of which x402's class and the own path sign as the
|
|
210
|
+
* fee payer, whatever the option names; undefined where the group does not decode, which both refuse.
|
|
211
|
+
*/
|
|
212
|
+
export function keyEntries(payload, ours) {
|
|
213
|
+
const { paymentGroup } = payload.payload;
|
|
214
|
+
if (!Array.isArray(paymentGroup) || !paymentGroup.every((e) => typeof e === "string"))
|
|
215
|
+
return undefined;
|
|
216
|
+
const decoded = decodeGroup(paymentGroup, ours);
|
|
217
|
+
if (!Array.isArray(decoded))
|
|
218
|
+
return undefined;
|
|
219
|
+
return decoded.map((s) => s.txn.sender.toString()).filter((s) => ours.includes(s));
|
|
220
|
+
}
|
|
221
|
+
/** The fee the key's transactions in the payment's group pay: each one's own `fee`, which is what it pays once it lands. */
|
|
222
|
+
export function feePayerFee(signer, payload) {
|
|
223
|
+
const { paymentGroup } = payload.payload;
|
|
224
|
+
if (!Array.isArray(paymentGroup))
|
|
225
|
+
return 0n;
|
|
226
|
+
const decoded = decodeGroup(paymentGroup, signer.getAddresses());
|
|
227
|
+
if (!Array.isArray(decoded))
|
|
228
|
+
return 0n;
|
|
229
|
+
const ours = signer.getAddresses();
|
|
230
|
+
return decoded.filter((s) => ours.includes(s.txn.sender.toString())).reduce((sum, s) => sum + (s.txn.fee ?? 0n), 0n);
|
|
231
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type AptosNetwork, type AptosReader } from "@integraledger/lcp/aptos";
|
|
2
|
+
import type { FacilitatorAptosSigner } from "@x402/aptos";
|
|
3
|
+
import { type FeeMeter, type Module, type ModuleStarter, type Registration } from "../../module.js";
|
|
4
|
+
export interface AptosConfig {
|
|
5
|
+
/** The network, exactly one. */
|
|
6
|
+
readonly network: AptosNetwork;
|
|
7
|
+
/** The seller's account, as `@x402/aptos`'s facilitator class takes it. */
|
|
8
|
+
readonly signer: FacilitatorAptosSigner;
|
|
9
|
+
/** Whether the module pays the payer's gas as its fee payer; default true, as the class's own default. */
|
|
10
|
+
readonly sponsor?: boolean;
|
|
11
|
+
/** The seller's REST endpoint (its base, without `/v1`), which lcp's read and the fee count use. */
|
|
12
|
+
readonly node: string;
|
|
13
|
+
}
|
|
14
|
+
/** lcp's reader over the REST endpoint at `base`, its calls ending by `deadline`. */
|
|
15
|
+
export declare function aptosReader(network: AptosNetwork, base: string, deadline: number): AptosReader;
|
|
16
|
+
/**
|
|
17
|
+
* The module of `x402/exact/aptos` on the configured network. With `meter`, the network's fee meter, every transaction
|
|
18
|
+
* the key sponsors is counted.
|
|
19
|
+
*/
|
|
20
|
+
export declare function aptosModule(c: AptosConfig, meter?: FeeMeter): Module;
|
|
21
|
+
export declare function aptosRegistration(c: AptosConfig, meter?: FeeMeter): Registration;
|
|
22
|
+
/** The module's start: one registration of `exact` per configured network, its fee meter counting what the key sponsors. */
|
|
23
|
+
export declare const starter: ModuleStarter<readonly AptosConfig[]>;
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Aptos module for `x402/exact/aptos` on each configured network: `@x402/aptos` 2.31.0's facilitator class,
|
|
3
|
+
* registered unchanged. Where it sponsors, the key is the seller's fee payer (`extra.key` `fee-payer`), which signs
|
|
4
|
+
* the payer's transaction as its fee payer: it reaches the module as the `FacilitatorAptosSigner` the class takes, and
|
|
5
|
+
* its address is in `signers` and the class's `extra.feePayer`. Where it does not sponsor, the payer pays its own gas,
|
|
6
|
+
* the class submits what the payer signed, and the key signs nothing (`none`, no signer): the class pays the gas of any
|
|
7
|
+
* payment whose option names one of the key's addresses as `extra.feePayer`, whatever it was built with, so the module
|
|
8
|
+
* refuses such an option before the class is asked. lcp's checks name the instrument, the
|
|
9
|
+
* sender and its sequence number; lcp's read goes through the seller's REST endpoint. The script form,
|
|
10
|
+
* `x402/exact/aptos/lcp-script`, is not built here.
|
|
11
|
+
*/
|
|
12
|
+
import { isRefusal } from "@integraledger/lcp";
|
|
13
|
+
import { exactAptos } from "@integraledger/lcp/aptos";
|
|
14
|
+
import { ExactAptosScheme } from "@x402/aptos/exact/facilitator";
|
|
15
|
+
import { isObject } from "../../answers.js";
|
|
16
|
+
import { NODE_MAX_BYTES, NODE_TIMEOUT_MS, NodeError, site } from "../../http.js";
|
|
17
|
+
import { outcomeOf, } from "../../module.js";
|
|
18
|
+
function reasonOf(r) {
|
|
19
|
+
if (r.code === "x402/not-v2")
|
|
20
|
+
return "invalid_x402_version";
|
|
21
|
+
if (r.code.startsWith("x402/option") || r.code === "aptos/option-malformed")
|
|
22
|
+
return "invalid_payment_requirements";
|
|
23
|
+
return "invalid_payload";
|
|
24
|
+
}
|
|
25
|
+
async function checked(p) {
|
|
26
|
+
const bound = await exactAptos.bound(p.payload);
|
|
27
|
+
if (isRefusal(bound))
|
|
28
|
+
return bound;
|
|
29
|
+
// The requirements arrive as JSON, which lcp's option type names.
|
|
30
|
+
return exactAptos.reference(p.payload, p.requirements);
|
|
31
|
+
}
|
|
32
|
+
/** One bounded GET of the REST endpoint: the status, the JSON answer and the headers. */
|
|
33
|
+
async function rest(url, deadline) {
|
|
34
|
+
const ms = Math.min(NODE_TIMEOUT_MS, deadline - performance.now());
|
|
35
|
+
if (ms <= 0)
|
|
36
|
+
throw new NodeError("spent", false, site(url));
|
|
37
|
+
let res;
|
|
38
|
+
try {
|
|
39
|
+
res = await fetch(url, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(Math.ceil(ms)) });
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
throw new NodeError("transport", true, e instanceof Error ? e.message : String(e), { cause: e });
|
|
43
|
+
}
|
|
44
|
+
const text = await res.text();
|
|
45
|
+
if (text.length > NODE_MAX_BYTES)
|
|
46
|
+
throw new NodeError("too-large", true, site(url));
|
|
47
|
+
if (res.status !== 404 && (res.status < 200 || res.status > 299))
|
|
48
|
+
throw new NodeError("http-status", true, `status ${res.status}`);
|
|
49
|
+
try {
|
|
50
|
+
return { status: res.status, json: JSON.parse(text), headers: res.headers };
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
throw new NodeError("malformed", true, "the answer is not JSON", { cause: e });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function header(h, name) {
|
|
57
|
+
const v = h.get(name);
|
|
58
|
+
if (v === null || !/^\d+$/.test(v))
|
|
59
|
+
throw new NodeError("malformed", true, `the ${name} header`);
|
|
60
|
+
return BigInt(v);
|
|
61
|
+
}
|
|
62
|
+
/** lcp's reader over the REST endpoint at `base`, its calls ending by `deadline`. */
|
|
63
|
+
export function aptosReader(network, base, deadline) {
|
|
64
|
+
const root = `${base.replace(/\/+$/, "")}/v1`;
|
|
65
|
+
return {
|
|
66
|
+
network,
|
|
67
|
+
async byHash(hash) {
|
|
68
|
+
const a = await rest(`${root}/transactions/by_hash/${encodeURIComponent(hash)}`, deadline);
|
|
69
|
+
if (a.status === 404)
|
|
70
|
+
return null;
|
|
71
|
+
if (isObject(a.json) && a.json["type"] === "pending_transaction")
|
|
72
|
+
return { type: "pending_transaction" };
|
|
73
|
+
return a.json;
|
|
74
|
+
},
|
|
75
|
+
async bySequence(sender, n) {
|
|
76
|
+
const a = await rest(`${root}/accounts/${encodeURIComponent(sender)}/transactions?start=${n}&limit=1`, deadline);
|
|
77
|
+
const first = a.status === 200 && Array.isArray(a.json) ? a.json[0] : undefined;
|
|
78
|
+
if (isObject(first) && first["sequence_number"] === n.toString())
|
|
79
|
+
return first;
|
|
80
|
+
return { notFound: true, timestampUsecs: header(a.headers, "x-aptos-ledger-timestampusec"), oldestVersion: header(a.headers, "x-aptos-ledger-oldest-version") };
|
|
81
|
+
},
|
|
82
|
+
async account(sender) {
|
|
83
|
+
const a = await rest(`${root}/accounts/${encodeURIComponent(sender)}`, deadline);
|
|
84
|
+
const seq = a.status === 200 && isObject(a.json) ? a.json["sequence_number"] : "0";
|
|
85
|
+
if (typeof seq !== "string" || !/^\d+$/.test(seq))
|
|
86
|
+
throw new NodeError("malformed", true, "an account");
|
|
87
|
+
return {
|
|
88
|
+
sequenceNumber: BigInt(seq),
|
|
89
|
+
timestampUsecs: header(a.headers, "x-aptos-ledger-timestampusec"),
|
|
90
|
+
oldestVersion: header(a.headers, "x-aptos-ledger-oldest-version"),
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
async ledger() {
|
|
94
|
+
const a = await rest(root, deadline);
|
|
95
|
+
const chainId = isObject(a.json) ? a.json["chain_id"] : undefined;
|
|
96
|
+
const t = isObject(a.json) ? a.json["ledger_timestamp"] : undefined;
|
|
97
|
+
if (typeof chainId !== "number" || typeof t !== "string" || !/^\d+$/.test(t))
|
|
98
|
+
throw new NodeError("malformed", true, "the ledger");
|
|
99
|
+
return { chainId, timestampUsecs: BigInt(t) };
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* What a transaction the key sponsored cost it, in octas: the gas used times its unit price once the node shows it
|
|
105
|
+
* committed, else `bound`, the most its own fields let it pay.
|
|
106
|
+
*/
|
|
107
|
+
async function feeOf(c, transaction, bound, deadline) {
|
|
108
|
+
const t = await aptosReader(c.network, c.node, deadline).byHash(transaction);
|
|
109
|
+
const used = isObject(t) ? t["gas_used"] : undefined;
|
|
110
|
+
const price = isObject(t) ? t["gas_unit_price"] : undefined;
|
|
111
|
+
if (typeof used === "string" && /^\d+$/.test(used) && typeof price === "string" && /^\d+$/.test(price)) {
|
|
112
|
+
return { fee: BigInt(used) * BigInt(price), included: true };
|
|
113
|
+
}
|
|
114
|
+
return { fee: bound, included: false };
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The fee payer's signer object as the class takes it, each transaction it sponsors given to the network's fee meter
|
|
118
|
+
* once submitted and again once the class's wait for it ends, every other member unchanged: the class answers a
|
|
119
|
+
* payment whose wait threw naming no transaction, though it was submitted. A submission that throws gives no hash, and
|
|
120
|
+
* is not counted.
|
|
121
|
+
*/
|
|
122
|
+
function counted(c, meter) {
|
|
123
|
+
const sponsored = new Map();
|
|
124
|
+
const count = (hash, bound) => meter.sent(hash, () => feeOf(c, hash, bound, performance.now() + NODE_TIMEOUT_MS));
|
|
125
|
+
return new Proxy(c.signer, {
|
|
126
|
+
get(inner, member) {
|
|
127
|
+
const value = Reflect.get(inner, member);
|
|
128
|
+
if (typeof value !== "function")
|
|
129
|
+
return value;
|
|
130
|
+
if (member === "signAndSubmitAsFeePayer") {
|
|
131
|
+
return async (...args) => {
|
|
132
|
+
const pending = (await value.apply(inner, args));
|
|
133
|
+
const raw = args[0].rawTransaction;
|
|
134
|
+
const bound = BigInt(raw.max_gas_amount) * BigInt(raw.gas_unit_price);
|
|
135
|
+
sponsored.set(pending.hash, bound);
|
|
136
|
+
count(pending.hash, bound);
|
|
137
|
+
return pending;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
if (member === "waitForTransaction") {
|
|
141
|
+
return async (...args) => {
|
|
142
|
+
try {
|
|
143
|
+
return await value.apply(inner, args);
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
const bound = sponsored.get(args[0]);
|
|
147
|
+
if (bound !== undefined) {
|
|
148
|
+
sponsored.delete(args[0]);
|
|
149
|
+
count(args[0], bound);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
return value.bind(inner);
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/** The class, where the module does not sponsor stating no signer, its key signing nothing. */
|
|
159
|
+
function unsponsored(cls) {
|
|
160
|
+
return {
|
|
161
|
+
scheme: cls.scheme,
|
|
162
|
+
caipFamily: cls.caipFamily,
|
|
163
|
+
getExtra: (n) => cls.getExtra(n),
|
|
164
|
+
getSigners: () => [],
|
|
165
|
+
verify: (payload, requirements, context) => cls.verify(payload, requirements, context),
|
|
166
|
+
settle: (payload, requirements, context) => cls.settle(payload, requirements, context),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* The module of `x402/exact/aptos` on the configured network. With `meter`, the network's fee meter, every transaction
|
|
171
|
+
* the key sponsors is counted.
|
|
172
|
+
*/
|
|
173
|
+
export function aptosModule(c, meter) {
|
|
174
|
+
const network = c.network;
|
|
175
|
+
const sponsor = c.sponsor !== false;
|
|
176
|
+
const cls = new ExactAptosScheme(meter === undefined ? c.signer : counted(c, meter), sponsor);
|
|
177
|
+
return {
|
|
178
|
+
// A zero amount is not established on Aptos, so the kind does not take zero.
|
|
179
|
+
descriptor: { name: "aptos", key: sponsor ? "fee-payer" : "none", pairings: [exactAptos.id], acceptsZero: [] },
|
|
180
|
+
network,
|
|
181
|
+
facilitator: sponsor ? cls : unsponsored(cls),
|
|
182
|
+
record: {
|
|
183
|
+
async instrument(p) {
|
|
184
|
+
if (!sponsor && p.requirements.extra?.["feePayer"] !== undefined)
|
|
185
|
+
return { refused: "invalid_payment_requirements" };
|
|
186
|
+
const ref = await checked(p);
|
|
187
|
+
if (isRefusal(ref))
|
|
188
|
+
return { refused: reasonOf(ref), message: ref.code };
|
|
189
|
+
return {
|
|
190
|
+
pairing: exactAptos.id,
|
|
191
|
+
// The sequence number is single-use for the sender; the hash changes with the fee payer's signature.
|
|
192
|
+
instrument: { by: "single-use", network, signer: ref.sender, value: ref.sequenceNumber },
|
|
193
|
+
nonce: exactAptos.data.nonce,
|
|
194
|
+
keep: { until: "lapse", at: Number(ref.expiresAt) * 1000 },
|
|
195
|
+
};
|
|
196
|
+
},
|
|
197
|
+
async read(p, at) {
|
|
198
|
+
const ref = await checked(p);
|
|
199
|
+
if (isRefusal(ref))
|
|
200
|
+
return outcomeOf({ state: "unreadable", reason: "unparseable", foreign: [] });
|
|
201
|
+
const search = at.search;
|
|
202
|
+
const named = at.transaction === undefined ? ref : { ...ref, transaction: at.transaction };
|
|
203
|
+
return outcomeOf(await exactAptos.status(named, aptosReader(c.network, c.node, at.deadline), {
|
|
204
|
+
act: "payment",
|
|
205
|
+
finality: "committed",
|
|
206
|
+
...(search === undefined ? {} : { search }),
|
|
207
|
+
}));
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
fees: {
|
|
211
|
+
// The class's own rule: with extra.feePayer the module's key pays the gas; without it the payer does.
|
|
212
|
+
paysFee: (p) => typeof p.requirements.extra?.["feePayer"] === "string",
|
|
213
|
+
payerBroadcast: () => false,
|
|
214
|
+
async charged(p, sent) {
|
|
215
|
+
const ref = await checked(p);
|
|
216
|
+
if (isRefusal(ref))
|
|
217
|
+
throw new TypeError(`a payment lcp refuses was sent: ${ref.code}`);
|
|
218
|
+
return feeOf(c, sent.transaction, BigInt(ref.maxGasAmount ?? "0") * BigInt(ref.gasUnitPrice ?? "0"), sent.deadline);
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
export function aptosRegistration(c, meter) {
|
|
224
|
+
return { network: c.network, module: aptosModule(c, meter), own: [] };
|
|
225
|
+
}
|
|
226
|
+
/** The module's start: one registration of `exact` per configured network, its fee meter counting what the key sponsors. */
|
|
227
|
+
export const starter = {
|
|
228
|
+
name: "aptos",
|
|
229
|
+
async start(config, core) {
|
|
230
|
+
return { registrations: config.map((c) => aptosRegistration(c, core.meter(c.network))) };
|
|
231
|
+
},
|
|
232
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type CardanoNetwork, type CardanoReader } from "@integraledger/lcp/cardano";
|
|
2
|
+
import type { FacilitatorCardanoSigner } from "@x402/cardano";
|
|
3
|
+
import { type CardanoSettlementStore } from "@x402/cardano/exact/facilitator";
|
|
4
|
+
import { type Module, type ModuleState, type ModuleStarter } from "../../module.js";
|
|
5
|
+
export interface CardanoConfig {
|
|
6
|
+
/** The network, exactly one. */
|
|
7
|
+
readonly network: CardanoNetwork;
|
|
8
|
+
/** The chain-query object `@x402/cardano`'s facilitator class takes, over the seller's provider. */
|
|
9
|
+
readonly signer: FacilitatorCardanoSigner;
|
|
10
|
+
/** lcp's reader over the seller's indexer for the network (`CardanoReader` of `@integraledger/lcp/cardano`). */
|
|
11
|
+
readonly reader: CardanoReader;
|
|
12
|
+
}
|
|
13
|
+
/** `@x402/cardano`'s duplicate-settlement guard over the module's durable state: one value per transaction id. */
|
|
14
|
+
export declare function settlementStore(state: ModuleState, network: string): CardanoSettlementStore;
|
|
15
|
+
/** The module of the two Cardano pairings on the configured network. */
|
|
16
|
+
export declare function cardanoModule(c: CardanoConfig, state: ModuleState): Module;
|
|
17
|
+
/** The module's start: one registration of `exact` per configured network, its guard in the module's state. */
|
|
18
|
+
export declare const starter: ModuleStarter<readonly CardanoConfig[]>;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Cardano module for `x402/exact/cardano` (the address method) and `x402/exact/cardano/lock` (the `masumi` and
|
|
3
|
+
* `script` locks) on each configured network: `@x402/cardano` 2.31.0's facilitator class, registered unchanged. The
|
|
4
|
+
* module holds no key (`extra.key` `none`): the class broadcasts the transaction the buyer signed, whose fee the buyer
|
|
5
|
+
* pays. A provider's project id or endpoint is the configuration of the chain-query object the class takes, which is
|
|
6
|
+
* not a key. The class's guard against broadcasting one transaction twice is kept in the settler's database, so a
|
|
7
|
+
* repeat after a restart resumes observing what was broadcast. lcp's checks name the instrument, the transaction id,
|
|
8
|
+
* which the body alone fixes; lcp's read goes through the reader the configuration gives over the seller's indexer.
|
|
9
|
+
*/
|
|
10
|
+
import { isRefusal } from "@integraledger/lcp";
|
|
11
|
+
import { exactCardano, exactCardanoLock } from "@integraledger/lcp/cardano";
|
|
12
|
+
import { ExactCardanoScheme } from "@x402/cardano/exact/facilitator";
|
|
13
|
+
import { outcomeOf } from "../../module.js";
|
|
14
|
+
function reasonOf(r) {
|
|
15
|
+
if (r.code === "x402/not-v2")
|
|
16
|
+
return "invalid_x402_version";
|
|
17
|
+
if (r.code.startsWith("x402/option") || r.code === "cardano/option-malformed")
|
|
18
|
+
return "invalid_payment_requirements";
|
|
19
|
+
return "invalid_payload";
|
|
20
|
+
}
|
|
21
|
+
/** The pairing an option is: a lock where its method names one, else the address method. */
|
|
22
|
+
function codecOf(p) {
|
|
23
|
+
const method = p.requirements.extra?.["assetTransferMethod"];
|
|
24
|
+
return method === "masumi" || method === "script" ? exactCardanoLock : exactCardano;
|
|
25
|
+
}
|
|
26
|
+
async function checked(p) {
|
|
27
|
+
const codec = codecOf(p);
|
|
28
|
+
const bound = await codec.bound(p.payload);
|
|
29
|
+
if (isRefusal(bound))
|
|
30
|
+
return bound;
|
|
31
|
+
// The requirements arrive as JSON, which lcp's option type names.
|
|
32
|
+
return codec.reference(p.payload, p.requirements);
|
|
33
|
+
}
|
|
34
|
+
/** `@x402/cardano`'s duplicate-settlement guard over the module's durable state: one value per transaction id. */
|
|
35
|
+
export function settlementStore(state, network) {
|
|
36
|
+
const key = (txHash) => `settlement:${network}:${txHash}`;
|
|
37
|
+
async function move(txHash, owner, to) {
|
|
38
|
+
const now = (await state.get(key(txHash)));
|
|
39
|
+
if (now?.owner !== owner)
|
|
40
|
+
return;
|
|
41
|
+
if (to === undefined) {
|
|
42
|
+
if (now.state === "in-flight")
|
|
43
|
+
await state.delete(key(txHash));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
await state.swap(key(txHash), now, { state: to, owner });
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
async claimSettlement(claim) {
|
|
50
|
+
if (claim.termsDigest !== undefined) {
|
|
51
|
+
const terms = `terms:${network}:${claim.termsDigest}`;
|
|
52
|
+
const bound = await state.swap(terms, undefined, claim.txHash);
|
|
53
|
+
if (!bound && (await state.get(terms)) !== claim.txHash)
|
|
54
|
+
return "terms-conflict";
|
|
55
|
+
}
|
|
56
|
+
if (await state.swap(key(claim.txHash), undefined, { state: "in-flight", owner: claim.ownerToken }))
|
|
57
|
+
return "fresh";
|
|
58
|
+
const now = (await state.get(key(claim.txHash)));
|
|
59
|
+
return now?.state ?? "in-flight";
|
|
60
|
+
},
|
|
61
|
+
markSubmitted: (txHash, owner) => move(txHash, owner, "submitted"),
|
|
62
|
+
markRejected: (txHash, owner) => move(txHash, owner, "rejected"),
|
|
63
|
+
releaseClaim: (txHash, owner) => move(txHash, owner, undefined),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** The module of the two Cardano pairings on the configured network. */
|
|
67
|
+
export function cardanoModule(c, state) {
|
|
68
|
+
const network = c.network;
|
|
69
|
+
if (c.reader.network !== c.network)
|
|
70
|
+
throw new TypeError(`the Cardano reader serves ${c.reader.network}, not ${c.network}`);
|
|
71
|
+
return {
|
|
72
|
+
// Every output carries at least the ledger's smallest, so neither pairing takes zero.
|
|
73
|
+
descriptor: { name: "cardano", key: "none", pairings: [exactCardano.id, exactCardanoLock.id], acceptsZero: [] },
|
|
74
|
+
network,
|
|
75
|
+
facilitator: new ExactCardanoScheme(c.signer, { settlementStore: settlementStore(state, c.network) }),
|
|
76
|
+
record: {
|
|
77
|
+
async instrument(p) {
|
|
78
|
+
const ref = await checked(p);
|
|
79
|
+
if (isRefusal(ref))
|
|
80
|
+
return { refused: reasonOf(ref) };
|
|
81
|
+
const codec = codecOf(p);
|
|
82
|
+
return {
|
|
83
|
+
pairing: codec.id,
|
|
84
|
+
// The id is the Blake2b-256 of the body; the witnesses are outside it.
|
|
85
|
+
instrument: { by: "transaction", network, transaction: ref.txId.replace(/^0x/, "") },
|
|
86
|
+
nonce: codec.data.nonce,
|
|
87
|
+
// Its TTL is a slot, which no clock bounds from above.
|
|
88
|
+
keep: { until: "settler" },
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
// The position recorded at issue: the block the security parameter below the tip.
|
|
92
|
+
async position() {
|
|
93
|
+
const [tip, k] = await Promise.all([c.reader.tip(), c.reader.securityParam()]);
|
|
94
|
+
return tip.blockHeight - k;
|
|
95
|
+
},
|
|
96
|
+
async read(p, at) {
|
|
97
|
+
const ref = await checked(p);
|
|
98
|
+
if (isRefusal(ref))
|
|
99
|
+
return outcomeOf({ state: "unreadable", reason: "unparseable", foreign: [] });
|
|
100
|
+
const search = at.search;
|
|
101
|
+
const after = at.from;
|
|
102
|
+
return outcomeOf(await codecOf(p).status(ref, c.reader, {
|
|
103
|
+
act: "payment",
|
|
104
|
+
finality: await c.reader.securityParam(),
|
|
105
|
+
...(search === undefined ? {} : { search }),
|
|
106
|
+
...(after === undefined ? {} : { after }),
|
|
107
|
+
}));
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
fees: {
|
|
111
|
+
// The buyer's own transaction pays its fee; the module sends it and pays nothing.
|
|
112
|
+
paysFee: () => false,
|
|
113
|
+
payerBroadcast: () => false,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/** The module's start: one registration of `exact` per configured network, its guard in the module's state. */
|
|
118
|
+
export const starter = {
|
|
119
|
+
name: "cardano",
|
|
120
|
+
async start(config, core) {
|
|
121
|
+
const registrations = config.map((c) => ({ network: c.network, module: cardanoModule(c, core.state), own: [] }));
|
|
122
|
+
return { registrations };
|
|
123
|
+
},
|
|
124
|
+
};
|