@leashmarket/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -0
- package/dist/agent/agent.d.ts +8 -0
- package/dist/agent/agent.d.ts.map +1 -0
- package/dist/agent/agent.js +14 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/agent/treasury-pda.d.ts +49 -0
- package/dist/agent/treasury-pda.d.ts.map +1 -0
- package/dist/agent/treasury-pda.js +55 -0
- package/dist/agent/treasury-pda.js.map +1 -0
- package/dist/explorer/index.d.ts +55 -0
- package/dist/explorer/index.d.ts.map +1 -0
- package/dist/explorer/index.js +95 -0
- package/dist/explorer/index.js.map +1 -0
- package/dist/fees/leash-fee.d.ts +248 -0
- package/dist/fees/leash-fee.d.ts.map +1 -0
- package/dist/fees/leash-fee.js +246 -0
- package/dist/fees/leash-fee.js.map +1 -0
- package/dist/format/index.d.ts +55 -0
- package/dist/format/index.d.ts.map +1 -0
- package/dist/format/index.js +130 -0
- package/dist/format/index.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/policy/evaluate.d.ts +17 -0
- package/dist/policy/evaluate.d.ts.map +1 -0
- package/dist/policy/evaluate.js +46 -0
- package/dist/policy/evaluate.js.map +1 -0
- package/dist/policy/state.d.ts +8 -0
- package/dist/policy/state.d.ts.map +1 -0
- package/dist/policy/state.js +2 -0
- package/dist/policy/state.js.map +1 -0
- package/dist/receipt/build.d.ts +5 -0
- package/dist/receipt/build.d.ts.map +1 -0
- package/dist/receipt/build.js +9 -0
- package/dist/receipt/build.js.map +1 -0
- package/dist/receipt/hash.d.ts +15 -0
- package/dist/receipt/hash.d.ts.map +1 -0
- package/dist/receipt/hash.js +40 -0
- package/dist/receipt/hash.js.map +1 -0
- package/dist/receipt/verify.d.ts +10 -0
- package/dist/receipt/verify.d.ts.map +1 -0
- package/dist/receipt/verify.js +36 -0
- package/dist/receipt/verify.js.map +1 -0
- package/dist/tokens/index.d.ts +86 -0
- package/dist/tokens/index.d.ts.map +1 -0
- package/dist/tokens/index.js +163 -0
- package/dist/tokens/index.js.map +1 -0
- package/dist/treasury/balance.d.ts +3 -0
- package/dist/treasury/balance.d.ts.map +1 -0
- package/dist/treasury/balance.js +13 -0
- package/dist/treasury/balance.js.map +1 -0
- package/dist/treasury/inspect-token-account.d.ts +46 -0
- package/dist/treasury/inspect-token-account.d.ts.map +1 -0
- package/dist/treasury/inspect-token-account.js +67 -0
- package/dist/treasury/inspect-token-account.js.map +1 -0
- package/dist/treasury/list-balances.d.ts +57 -0
- package/dist/treasury/list-balances.d.ts.map +1 -0
- package/dist/treasury/list-balances.js +115 -0
- package/dist/treasury/list-balances.js.map +1 -0
- package/dist/treasury/pause.d.ts +32 -0
- package/dist/treasury/pause.d.ts.map +1 -0
- package/dist/treasury/pause.js +40 -0
- package/dist/treasury/pause.js.map +1 -0
- package/dist/treasury/withdraw.d.ts +13 -0
- package/dist/treasury/withdraw.d.ts.map +1 -0
- package/dist/treasury/withdraw.js +4 -0
- package/dist/treasury/withdraw.js.map +1 -0
- package/dist/wallet/index.d.ts +3 -0
- package/dist/wallet/index.d.ts.map +1 -0
- package/dist/wallet/index.js +2 -0
- package/dist/wallet/index.js.map +1 -0
- package/dist/x402/client.d.ts +72 -0
- package/dist/x402/client.d.ts.map +1 -0
- package/dist/x402/client.js +94 -0
- package/dist/x402/client.js.map +1 -0
- package/dist/x402/delegate-scheme.d.ts +107 -0
- package/dist/x402/delegate-scheme.d.ts.map +1 -0
- package/dist/x402/delegate-scheme.js +268 -0
- package/dist/x402/delegate-scheme.js.map +1 -0
- package/dist/x402/discovery.d.ts +110 -0
- package/dist/x402/discovery.d.ts.map +1 -0
- package/dist/x402/discovery.js +213 -0
- package/dist/x402/discovery.js.map +1 -0
- package/dist/x402/envelope.d.ts +65 -0
- package/dist/x402/envelope.d.ts.map +1 -0
- package/dist/x402/envelope.js +67 -0
- package/dist/x402/envelope.js.map +1 -0
- package/dist/x402/facilitator.d.ts +45 -0
- package/dist/x402/facilitator.d.ts.map +1 -0
- package/dist/x402/facilitator.js +61 -0
- package/dist/x402/facilitator.js.map +1 -0
- package/dist/x402/headers.d.ts +51 -0
- package/dist/x402/headers.d.ts.map +1 -0
- package/dist/x402/headers.js +84 -0
- package/dist/x402/headers.js.map +1 -0
- package/dist/x402/parse.d.ts +20 -0
- package/dist/x402/parse.d.ts.map +1 -0
- package/dist/x402/parse.js +31 -0
- package/dist/x402/parse.js.map +1 -0
- package/dist/x402/webhook.d.ts +48 -0
- package/dist/x402/webhook.d.ts.map +1 -0
- package/dist/x402/webhook.js +88 -0
- package/dist/x402/webhook.js.map +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* x402 SVM payment scheme variants used by Leash buyers. Both schemes
|
|
3
|
+
* are wire-compatible with the upstream `@x402/svm` Exact scheme but
|
|
4
|
+
* append the **Leash protocol fee leg** when the seller's
|
|
5
|
+
* `paymentRequirements.extra['leash.fee']` block is present.
|
|
6
|
+
*
|
|
7
|
+
* Two variants are exported:
|
|
8
|
+
*
|
|
9
|
+
* - {@link LeashExactSvmScheme} — the buyer signs as the **owner** of
|
|
10
|
+
* the source ATA. Drop-in replacement for the vanilla
|
|
11
|
+
* `@x402/svm` `ExactSvmScheme`; the only difference is the optional
|
|
12
|
+
* fee leg.
|
|
13
|
+
*
|
|
14
|
+
* - {@link LeashDelegateExactSvmScheme} — the source ATA is provided
|
|
15
|
+
* externally (e.g. an agent treasury PDA's USDC ATA) and the buyer
|
|
16
|
+
* signs as the **SPL delegate** of that account. Used by Leash
|
|
17
|
+
* agents whose Privy embedded wallet is the delegate of a treasury
|
|
18
|
+
* it doesn't own.
|
|
19
|
+
*
|
|
20
|
+
* Transaction shape (with fee leg + auto-provisioning of destination ATAs):
|
|
21
|
+
*
|
|
22
|
+
* ix[0] SetComputeUnitLimit
|
|
23
|
+
* ix[1] SetComputeUnitPrice
|
|
24
|
+
* ix[2] CreateAssociatedTokenAccountIdempotent (seller `payTo` ATA; payer = facilitator)
|
|
25
|
+
* ix[3] CreateAssociatedTokenAccountIdempotent (fee vault ATA; payer = facilitator)
|
|
26
|
+
* ix[4] TransferChecked (seller leg, amount = paymentRequirements.amount)
|
|
27
|
+
* ix[5] TransferChecked (fee leg, amount = extra['leash.fee'].feeAtomic)
|
|
28
|
+
* ix[6] Memo
|
|
29
|
+
*
|
|
30
|
+
* Idempotent creates are always emitted so first-time settlements on a
|
|
31
|
+
* fresh mint (e.g. devnet USDG) succeed without an out-of-band ATA-init.
|
|
32
|
+
* The facilitator skips any leading idempotent ATA creates whose target
|
|
33
|
+
* matches the seller-`payTo` or fee-vault ATA.
|
|
34
|
+
*
|
|
35
|
+
* When `extra['leash.fee']` is absent (vanilla x402 seller, no Leash
|
|
36
|
+
* facilitator), the fee leg is skipped and the transaction degrades to
|
|
37
|
+
* the upstream 4-instruction shape: `[setLimit, setPrice, transfer, memo]`.
|
|
38
|
+
*
|
|
39
|
+
* Both legs share the same authority + source ATA, so a single signature
|
|
40
|
+
* covers both. Atomicity is guaranteed by Solana's all-or-nothing
|
|
41
|
+
* transaction semantics — either the seller AND treasury get paid, or
|
|
42
|
+
* neither does.
|
|
43
|
+
*/
|
|
44
|
+
import { address as toAddress } from '@solana/kit';
|
|
45
|
+
import { appendTransactionMessageInstructions, createTransactionMessage, getBase64EncodedWireTransaction, partiallySignTransactionMessageWithSigners, pipe, prependTransactionMessageInstruction, setTransactionMessageFeePayer, setTransactionMessageLifetimeUsingBlockhash, } from '@solana/kit';
|
|
46
|
+
import { getSetComputeUnitLimitInstruction, setTransactionMessageComputeUnitPrice, } from '@solana-program/compute-budget';
|
|
47
|
+
import { fetchMint, findAssociatedTokenPda, getCreateAssociatedTokenIdempotentInstruction, getTransferCheckedInstruction, TOKEN_2022_PROGRAM_ADDRESS, } from '@solana-program/token-2022';
|
|
48
|
+
import { TOKEN_PROGRAM_ADDRESS } from '@solana-program/token';
|
|
49
|
+
import { createRpcClient, MAX_MEMO_BYTES, MEMO_PROGRAM_ADDRESS } from '@x402/svm';
|
|
50
|
+
import { computeLeashFeeForRequirements, parseLeashFeeExtra } from '../fees/leash-fee.js';
|
|
51
|
+
/** Map x402 `paymentRequirements.network` (CAIP-2) to fee-module network. */
|
|
52
|
+
function tokenNetworkFromPaymentNetwork(network) {
|
|
53
|
+
const lower = network.toLowerCase();
|
|
54
|
+
if (lower === 'solana-mainnet' || lower.startsWith('solana:5eykt4u'))
|
|
55
|
+
return 'mainnet';
|
|
56
|
+
return 'devnet';
|
|
57
|
+
}
|
|
58
|
+
const DEFAULT_COMPUTE_UNIT_LIMIT = 200_000;
|
|
59
|
+
const DEFAULT_COMPUTE_UNIT_PRICE_MICROLAMPORTS = 10_000;
|
|
60
|
+
/**
|
|
61
|
+
* SVM client implementation of the x402 "exact" scheme that signs as a
|
|
62
|
+
* **delegate** of an externally owned source ATA. Wire-compatible with
|
|
63
|
+
* the vanilla `ExactSvmScheme` plus the Leash protocol fee leg.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* import { x402Client } from '@x402/core/client';
|
|
68
|
+
* import { LeashDelegateExactSvmScheme } from '@leashmarket/core';
|
|
69
|
+
*
|
|
70
|
+
* const client = new x402Client();
|
|
71
|
+
* client.register('solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1XkXr8aBmpfk5', new LeashDelegateExactSvmScheme({
|
|
72
|
+
* signer: privySigner,
|
|
73
|
+
* sourceTokenAccount: agentUsdcAta,
|
|
74
|
+
* }));
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export class LeashDelegateExactSvmScheme {
|
|
78
|
+
scheme = 'exact';
|
|
79
|
+
signer;
|
|
80
|
+
sourceTokenAccount;
|
|
81
|
+
rpcUrl;
|
|
82
|
+
constructor(options) {
|
|
83
|
+
this.signer = options.signer;
|
|
84
|
+
this.sourceTokenAccount =
|
|
85
|
+
typeof options.sourceTokenAccount === 'string'
|
|
86
|
+
? toAddress(options.sourceTokenAccount)
|
|
87
|
+
: options.sourceTokenAccount;
|
|
88
|
+
this.rpcUrl = options.rpcUrl;
|
|
89
|
+
}
|
|
90
|
+
async createPaymentPayload(x402Version, paymentRequirements) {
|
|
91
|
+
return buildLeashPaymentPayload({
|
|
92
|
+
x402Version,
|
|
93
|
+
paymentRequirements,
|
|
94
|
+
signer: this.signer,
|
|
95
|
+
sourceTokenAccount: this.sourceTokenAccount,
|
|
96
|
+
...(this.rpcUrl ? { rpcUrl: this.rpcUrl } : {}),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* SVM client implementation of the x402 "exact" scheme where the buyer
|
|
102
|
+
* signs as the **owner** of the source ATA (i.e. their own wallet).
|
|
103
|
+
* Replaces the upstream `@x402/svm` `ExactSvmScheme` for Leash buyers
|
|
104
|
+
* who want the Leash protocol fee leg appended whenever the seller
|
|
105
|
+
* advertises one.
|
|
106
|
+
*
|
|
107
|
+
* Falls back to the upstream wire shape when no fee block is present,
|
|
108
|
+
* so this scheme can be used unconditionally — calling code does not
|
|
109
|
+
* need to branch based on the seller's facilitator.
|
|
110
|
+
*/
|
|
111
|
+
export class LeashExactSvmScheme {
|
|
112
|
+
scheme = 'exact';
|
|
113
|
+
signer;
|
|
114
|
+
rpcUrl;
|
|
115
|
+
constructor(options) {
|
|
116
|
+
this.signer = options.signer;
|
|
117
|
+
this.rpcUrl = options.rpcUrl;
|
|
118
|
+
}
|
|
119
|
+
async createPaymentPayload(x402Version, paymentRequirements) {
|
|
120
|
+
return buildLeashPaymentPayload({
|
|
121
|
+
x402Version,
|
|
122
|
+
paymentRequirements,
|
|
123
|
+
signer: this.signer,
|
|
124
|
+
sourceTokenAccount: null, // derive from signer.address
|
|
125
|
+
...(this.rpcUrl ? { rpcUrl: this.rpcUrl } : {}),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Shared payload builder used by both Leash schemes. Walks the seller's
|
|
131
|
+
* `paymentRequirements`, fetches the mint to learn its token program +
|
|
132
|
+
* decimals, builds the seller `TransferChecked` leg, optionally appends
|
|
133
|
+
* the Leash fee leg, and signs the resulting transaction as the buyer.
|
|
134
|
+
*
|
|
135
|
+
* The fee leg is built using the seller-supplied `extra['leash.fee']`
|
|
136
|
+
* block as the source of truth (so the buyer doesn't have to care about
|
|
137
|
+
* which env vars the seller ran with). The facilitator independently
|
|
138
|
+
* recomputes everything in `verify`, so a tampered seller can't trick
|
|
139
|
+
* the buyer into overpaying — the worst case is a `verify` failure.
|
|
140
|
+
*/
|
|
141
|
+
async function buildLeashPaymentPayload(args) {
|
|
142
|
+
const { x402Version, paymentRequirements, signer, sourceTokenAccount } = args;
|
|
143
|
+
const rpc = createRpcClient(paymentRequirements.network, args.rpcUrl);
|
|
144
|
+
const tokenMint = await fetchMint(rpc, paymentRequirements.asset);
|
|
145
|
+
const tokenProgramAddress = tokenMint.programAddress;
|
|
146
|
+
if (tokenProgramAddress.toString() !== TOKEN_PROGRAM_ADDRESS.toString() &&
|
|
147
|
+
tokenProgramAddress.toString() !== TOKEN_2022_PROGRAM_ADDRESS.toString()) {
|
|
148
|
+
throw new Error('Asset was not created by a known token program');
|
|
149
|
+
}
|
|
150
|
+
// Resolve source ATA: explicit (delegate mode) or derived (owner mode).
|
|
151
|
+
let source;
|
|
152
|
+
if (sourceTokenAccount) {
|
|
153
|
+
source = sourceTokenAccount;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
const [ownerAta] = await findAssociatedTokenPda({
|
|
157
|
+
mint: paymentRequirements.asset,
|
|
158
|
+
owner: signer.address,
|
|
159
|
+
tokenProgram: tokenProgramAddress,
|
|
160
|
+
});
|
|
161
|
+
source = ownerAta;
|
|
162
|
+
}
|
|
163
|
+
const [destinationATA] = await findAssociatedTokenPda({
|
|
164
|
+
mint: paymentRequirements.asset,
|
|
165
|
+
owner: paymentRequirements.payTo,
|
|
166
|
+
tokenProgram: tokenProgramAddress,
|
|
167
|
+
});
|
|
168
|
+
const transferIx = getTransferCheckedInstruction({
|
|
169
|
+
source,
|
|
170
|
+
mint: paymentRequirements.asset,
|
|
171
|
+
destination: destinationATA,
|
|
172
|
+
authority: signer,
|
|
173
|
+
amount: BigInt(paymentRequirements.amount),
|
|
174
|
+
decimals: tokenMint.data.decimals,
|
|
175
|
+
}, { programAddress: tokenProgramAddress });
|
|
176
|
+
// Build the optional fee leg. The wire shape only carries (bps,
|
|
177
|
+
// feeAuthority); we recompute (feeAtomic, feeDestination) here from
|
|
178
|
+
// the same inputs the facilitator uses, so both sides agree without
|
|
179
|
+
// the seller having to pre-derive an ATA. If the seller tampers with
|
|
180
|
+
// bps or feeAuthority, the facilitator's independent recomputation
|
|
181
|
+
// rejects the transaction at verify time.
|
|
182
|
+
const feeExtra = parseLeashFeeExtra((paymentRequirements.extra ?? null));
|
|
183
|
+
const tokenProgramKind = tokenProgramAddress.toString() === TOKEN_2022_PROGRAM_ADDRESS.toString()
|
|
184
|
+
? 'spl-token-2022'
|
|
185
|
+
: 'spl-token';
|
|
186
|
+
const resolvedFee = await computeLeashFeeForRequirements({
|
|
187
|
+
network: tokenNetworkFromPaymentNetwork(paymentRequirements.network),
|
|
188
|
+
asset: paymentRequirements.asset,
|
|
189
|
+
tokenProgram: tokenProgramKind,
|
|
190
|
+
amount: paymentRequirements.amount,
|
|
191
|
+
extra: feeExtra,
|
|
192
|
+
});
|
|
193
|
+
const feeIx = resolvedFee && resolvedFee.feeAtomic > 0n
|
|
194
|
+
? getTransferCheckedInstruction({
|
|
195
|
+
source,
|
|
196
|
+
mint: paymentRequirements.asset,
|
|
197
|
+
destination: resolvedFee.feeDestination,
|
|
198
|
+
authority: signer,
|
|
199
|
+
amount: resolvedFee.feeAtomic,
|
|
200
|
+
decimals: tokenMint.data.decimals,
|
|
201
|
+
}, { programAddress: tokenProgramAddress })
|
|
202
|
+
: null;
|
|
203
|
+
const feePayer = paymentRequirements.extra?.feePayer;
|
|
204
|
+
if (!feePayer) {
|
|
205
|
+
throw new Error('feePayer is required in paymentRequirements.extra for SVM transactions');
|
|
206
|
+
}
|
|
207
|
+
/** Create-ATA helper types `payer` as a signer; the facilitator co-signs later. */
|
|
208
|
+
const feePayerSigner = feePayer;
|
|
209
|
+
/**
|
|
210
|
+
* Ensure the seller `payTo` ATA exists before `TransferChecked`. New
|
|
211
|
+
* stables (devnet USDG, etc.) frequently land on a wallet that has
|
|
212
|
+
* never received that mint, so the seller ATA hasn't been created.
|
|
213
|
+
* Idempotent — a no-op (small CU cost) when it already exists.
|
|
214
|
+
*/
|
|
215
|
+
const provisionSellerAtaIx = getCreateAssociatedTokenIdempotentInstruction({
|
|
216
|
+
payer: feePayerSigner,
|
|
217
|
+
ata: destinationATA,
|
|
218
|
+
owner: paymentRequirements.payTo,
|
|
219
|
+
mint: paymentRequirements.asset,
|
|
220
|
+
tokenProgram: tokenProgramAddress,
|
|
221
|
+
});
|
|
222
|
+
/** Ensures the fee vault ATA exists before the second `TransferChecked`. */
|
|
223
|
+
const provisionFeeVaultAtaIx = resolvedFee && resolvedFee.feeAtomic > 0n
|
|
224
|
+
? getCreateAssociatedTokenIdempotentInstruction({
|
|
225
|
+
payer: feePayerSigner,
|
|
226
|
+
ata: resolvedFee.feeDestination,
|
|
227
|
+
owner: resolvedFee.feeAuthority,
|
|
228
|
+
mint: paymentRequirements.asset,
|
|
229
|
+
tokenProgram: tokenProgramAddress,
|
|
230
|
+
})
|
|
231
|
+
: null;
|
|
232
|
+
const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
|
|
233
|
+
const sellerMemo = paymentRequirements.extra?.memo;
|
|
234
|
+
let memoData;
|
|
235
|
+
if (sellerMemo) {
|
|
236
|
+
memoData = new TextEncoder().encode(sellerMemo);
|
|
237
|
+
if (memoData.byteLength > MAX_MEMO_BYTES) {
|
|
238
|
+
throw new Error(`extra.memo exceeds maximum ${MAX_MEMO_BYTES} bytes`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
const nonce = crypto.getRandomValues(new Uint8Array(16));
|
|
243
|
+
memoData = new TextEncoder().encode(Array.from(nonce)
|
|
244
|
+
.map((b) => b.toString(16).padStart(2, '0'))
|
|
245
|
+
.join(''));
|
|
246
|
+
}
|
|
247
|
+
const memoIx = {
|
|
248
|
+
programAddress: MEMO_PROGRAM_ADDRESS,
|
|
249
|
+
accounts: [],
|
|
250
|
+
data: memoData,
|
|
251
|
+
};
|
|
252
|
+
// Order: [setLimit, setPrice, sellerAtaCreate, feeAtaCreate?, transferIx, feeIx?, memoIx].
|
|
253
|
+
// ATA creates are paid for by the facilitator (`feePayer`) so a fresh
|
|
254
|
+
// mint settles first try without the buyer pre-funding rent.
|
|
255
|
+
const trailingIxs = feeIx
|
|
256
|
+
? provisionFeeVaultAtaIx
|
|
257
|
+
? [provisionSellerAtaIx, provisionFeeVaultAtaIx, transferIx, feeIx, memoIx]
|
|
258
|
+
: [provisionSellerAtaIx, transferIx, feeIx, memoIx]
|
|
259
|
+
: [provisionSellerAtaIx, transferIx, memoIx];
|
|
260
|
+
const tx = pipe(createTransactionMessage({ version: 0 }), (t) => setTransactionMessageComputeUnitPrice(DEFAULT_COMPUTE_UNIT_PRICE_MICROLAMPORTS, t), (t) => setTransactionMessageFeePayer(feePayer, t), (t) => prependTransactionMessageInstruction(getSetComputeUnitLimitInstruction({ units: DEFAULT_COMPUTE_UNIT_LIMIT }), t), (t) => appendTransactionMessageInstructions(trailingIxs, t), (t) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, t));
|
|
261
|
+
const signedTransaction = await partiallySignTransactionMessageWithSigners(tx);
|
|
262
|
+
const base64EncodedWireTransaction = getBase64EncodedWireTransaction(signedTransaction);
|
|
263
|
+
return {
|
|
264
|
+
x402Version,
|
|
265
|
+
payload: { transaction: base64EncodedWireTransaction },
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
//# sourceMappingURL=delegate-scheme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delegate-scheme.js","sourceRoot":"","sources":["../../src/x402/delegate-scheme.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,OAAO,EAAE,OAAO,IAAI,SAAS,EAAwC,MAAM,aAAa,CAAC;AACzF,OAAO,EACL,oCAAoC,EACpC,wBAAwB,EACxB,+BAA+B,EAC/B,0CAA0C,EAC1C,IAAI,EACJ,oCAAoC,EACpC,6BAA6B,EAC7B,2CAA2C,GAC5C,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,iCAAiC,EACjC,qCAAqC,GACtC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,SAAS,EACT,sBAAsB,EACtB,6CAA6C,EAC7C,6BAA6B,EAC7B,0BAA0B,GAC3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAIlF,OAAO,EAAE,8BAA8B,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1F,6EAA6E;AAC7E,SAAS,8BAA8B,CAAC,OAAe;IACrD,MAAM,KAAK,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IACpC,IAAI,KAAK,KAAK,gBAAgB,IAAI,KAAK,CAAC,UAAU,CAAC,gBAAgB,CAAC;QAAE,OAAO,SAAS,CAAC;IACvF,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,0BAA0B,GAAG,OAAO,CAAC;AAC3C,MAAM,wCAAwC,GAAG,MAAM,CAAC;AAqBxD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,2BAA2B;IAC7B,MAAM,GA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AAC,oCAAoC,CAAC,WAAW,EAAE,CAAC,CAAC,EAC3D,CAAC,CAAC,EAAE,EAAE,CAAC,2CAA2C,CAAC,eAAe,EAAE,CAAC,CAAC,CACvE,CAAC;IACF,MAAM,iBAAiB,GAAG,MAAM,0CAA0C,CAAC,EAAE,CAAC,CAAC;IAC/E,MAAM,4BAA4B,GAAG,+BAA+B,CAAC,iBAAiB,CAAC,CAAC;IACxF,OAAO;QACL,WAAW;QACX,OAAO,EAAE,EAAE,WAAW,EAAE,4BAA4B,EAAE;KACvD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
export type PaymentLinkMetaEndpoint = {
|
|
2
|
+
id: string;
|
|
3
|
+
label: string;
|
|
4
|
+
description: string | null;
|
|
5
|
+
method: 'GET' | 'POST';
|
|
6
|
+
url: string;
|
|
7
|
+
price: string;
|
|
8
|
+
/** Primary settlement currency (USDC by default). */
|
|
9
|
+
currency: 'USDC' | 'USDT' | 'USDG';
|
|
10
|
+
/**
|
|
11
|
+
* Other stablecoins this endpoint accepts at the equivalent dollar
|
|
12
|
+
* amount. Empty array when the endpoint is single-currency.
|
|
13
|
+
*/
|
|
14
|
+
accepts_currencies: ReadonlyArray<'USDC' | 'USDT' | 'USDG'>;
|
|
15
|
+
network: string;
|
|
16
|
+
owner_agent: string;
|
|
17
|
+
payTo: string | null;
|
|
18
|
+
response: {
|
|
19
|
+
status: number;
|
|
20
|
+
mimeType: string;
|
|
21
|
+
body_kind: 'json' | 'text';
|
|
22
|
+
};
|
|
23
|
+
hooks: {
|
|
24
|
+
wrap_receipt: boolean;
|
|
25
|
+
webhook_url: string | null;
|
|
26
|
+
};
|
|
27
|
+
created_at: string;
|
|
28
|
+
updated_at: string;
|
|
29
|
+
};
|
|
30
|
+
export type PaymentLinkMeta = {
|
|
31
|
+
ok: true;
|
|
32
|
+
kind: 'leash.payment-link';
|
|
33
|
+
docs?: string;
|
|
34
|
+
note?: string;
|
|
35
|
+
endpoint: PaymentLinkMetaEndpoint;
|
|
36
|
+
facilitator?: string | null;
|
|
37
|
+
explorer?: {
|
|
38
|
+
agent?: string;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Inputs for {@link buildPaymentLinkMeta} — the producer-side builder used by
|
|
43
|
+
* the Leash web app's `/x/<id>` route. Keeping the builder in `@leashmarket/core`
|
|
44
|
+
* means producer and consumer share one TypeScript shape, so any change to
|
|
45
|
+
* the discovery contract becomes a typecheck error in both places.
|
|
46
|
+
*/
|
|
47
|
+
export type BuildPaymentLinkMetaInput = {
|
|
48
|
+
endpoint: {
|
|
49
|
+
id: string;
|
|
50
|
+
label: string;
|
|
51
|
+
description?: string | null;
|
|
52
|
+
method: 'GET' | 'POST';
|
|
53
|
+
price: string;
|
|
54
|
+
/** Primary settlement currency. Defaults to `'USDC'` when omitted. */
|
|
55
|
+
currency?: 'USDC' | 'USDT' | 'USDG';
|
|
56
|
+
/** Additional accepted stablecoins. Defaults to `[]` when omitted. */
|
|
57
|
+
accepts_currencies?: ReadonlyArray<'USDC' | 'USDT' | 'USDG'>;
|
|
58
|
+
network: string;
|
|
59
|
+
owner_agent: string;
|
|
60
|
+
response: {
|
|
61
|
+
status: number;
|
|
62
|
+
mimeType: string;
|
|
63
|
+
/** Pass `body` so we can derive `body_kind` from its runtime type. */
|
|
64
|
+
body: unknown;
|
|
65
|
+
};
|
|
66
|
+
webhook_url?: string | null;
|
|
67
|
+
wrap_receipt: boolean;
|
|
68
|
+
created_at: string;
|
|
69
|
+
updated_at: string;
|
|
70
|
+
};
|
|
71
|
+
/** Origin used to construct absolute URLs (e.g. `https://leash.app`). */
|
|
72
|
+
origin: string;
|
|
73
|
+
/** Asset Signer PDA the seller pays to (best-effort; can be null). */
|
|
74
|
+
payTo: string | null;
|
|
75
|
+
/** Optional facilitator URL recorded on the descriptor. */
|
|
76
|
+
facilitator?: string | null;
|
|
77
|
+
/** Optional docs URL exposed in the payload. */
|
|
78
|
+
docsUrl?: string | null;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Construct a typed {@link PaymentLinkMeta} payload to be returned by the
|
|
82
|
+
* web app's `/x/<id>` GET discovery handler.
|
|
83
|
+
*
|
|
84
|
+
* This is the producer-side counterpart to {@link fetchPaymentLinkMeta}.
|
|
85
|
+
* Both sides share the same TS types, so the wire contract stays in sync.
|
|
86
|
+
*/
|
|
87
|
+
export declare function buildPaymentLinkMeta(input: BuildPaymentLinkMetaInput): PaymentLinkMeta;
|
|
88
|
+
type FetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
89
|
+
export type FetchPaymentLinkMetaOptions = {
|
|
90
|
+
/** Optional fetch override (defaults to global fetch). */
|
|
91
|
+
fetch?: FetchLike;
|
|
92
|
+
/** Extra init headers/timeouts/etc when dialing the discovery endpoint. */
|
|
93
|
+
init?: RequestInit;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Resolve a payment-link metadata descriptor from a Leash web host.
|
|
97
|
+
*
|
|
98
|
+
* This is a typed wrapper around the browser-friendly `GET /x/<id>` discovery
|
|
99
|
+
* surface implemented by the playground app route (`apps/playground/app/x/[id]/route.ts`).
|
|
100
|
+
*
|
|
101
|
+
* Overloads:
|
|
102
|
+
* 1) `fetchPaymentLinkMeta("https://host/x/abc123")`
|
|
103
|
+
* 2) `fetchPaymentLinkMeta("https://host", "abc123")`
|
|
104
|
+
*
|
|
105
|
+
* Throws on non-2xx responses, invalid JSON, or payloads that don't match the
|
|
106
|
+
* expected `kind: "leash.payment-link"` contract.
|
|
107
|
+
*/
|
|
108
|
+
export declare function fetchPaymentLinkMeta(urlOrBase: string | URL, idOrOpts?: string | FetchPaymentLinkMetaOptions, maybeOpts?: FetchPaymentLinkMetaOptions): Promise<PaymentLinkMeta>;
|
|
109
|
+
export {};
|
|
110
|
+
//# sourceMappingURL=discovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.d.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K,CAAC,EAAE,SAAS,CAAC;IAClB,2EAA2E;IAC3E,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAsB,oBAAoB,CACxC,SAAS,EAAE,MAAM,GAAG,GAAG,EACvB,QAAQ,CAAC,EAAE,MAAM,GAAG,2BAA2B,EAC/C,SAAS,CAAC,EAAE,2BAA2B,GACtC,OAAO,CAAC,eAAe,CAAC,CAqB1B"}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Construct a typed {@link PaymentLinkMeta} payload to be returned by the
|
|
3
|
+
* web app's `/x/<id>` GET discovery handler.
|
|
4
|
+
*
|
|
5
|
+
* This is the producer-side counterpart to {@link fetchPaymentLinkMeta}.
|
|
6
|
+
* Both sides share the same TS types, so the wire contract stays in sync.
|
|
7
|
+
*/
|
|
8
|
+
export function buildPaymentLinkMeta(input) {
|
|
9
|
+
const { endpoint, origin, payTo, facilitator, docsUrl } = input;
|
|
10
|
+
const linkUrl = `${origin}/x/${endpoint.id}`;
|
|
11
|
+
const meta = {
|
|
12
|
+
ok: true,
|
|
13
|
+
kind: 'leash.payment-link',
|
|
14
|
+
...(docsUrl ? { docs: docsUrl } : {}),
|
|
15
|
+
note: `Send ${endpoint.method} ${linkUrl} with an x402 client (e.g. @leashmarket/buyer-kit) to pay this link. This GET surface is metadata-only — no payment is taken.`,
|
|
16
|
+
endpoint: {
|
|
17
|
+
id: endpoint.id,
|
|
18
|
+
label: endpoint.label,
|
|
19
|
+
description: endpoint.description ?? null,
|
|
20
|
+
method: endpoint.method,
|
|
21
|
+
url: linkUrl,
|
|
22
|
+
price: endpoint.price,
|
|
23
|
+
currency: endpoint.currency ?? 'USDC',
|
|
24
|
+
accepts_currencies: endpoint.accepts_currencies ?? [],
|
|
25
|
+
network: endpoint.network,
|
|
26
|
+
owner_agent: endpoint.owner_agent,
|
|
27
|
+
payTo,
|
|
28
|
+
response: {
|
|
29
|
+
status: endpoint.response.status,
|
|
30
|
+
mimeType: endpoint.response.mimeType,
|
|
31
|
+
body_kind: typeof endpoint.response.body === 'string' ? 'text' : 'json',
|
|
32
|
+
},
|
|
33
|
+
hooks: {
|
|
34
|
+
wrap_receipt: endpoint.wrap_receipt,
|
|
35
|
+
webhook_url: endpoint.webhook_url ?? null,
|
|
36
|
+
},
|
|
37
|
+
created_at: endpoint.created_at,
|
|
38
|
+
updated_at: endpoint.updated_at,
|
|
39
|
+
},
|
|
40
|
+
...(facilitator ? { facilitator } : {}),
|
|
41
|
+
explorer: {
|
|
42
|
+
agent: `${origin}/agents/${endpoint.owner_agent}`,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
return meta;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Resolve a payment-link metadata descriptor from a Leash web host.
|
|
49
|
+
*
|
|
50
|
+
* This is a typed wrapper around the browser-friendly `GET /x/<id>` discovery
|
|
51
|
+
* surface implemented by the playground app route (`apps/playground/app/x/[id]/route.ts`).
|
|
52
|
+
*
|
|
53
|
+
* Overloads:
|
|
54
|
+
* 1) `fetchPaymentLinkMeta("https://host/x/abc123")`
|
|
55
|
+
* 2) `fetchPaymentLinkMeta("https://host", "abc123")`
|
|
56
|
+
*
|
|
57
|
+
* Throws on non-2xx responses, invalid JSON, or payloads that don't match the
|
|
58
|
+
* expected `kind: "leash.payment-link"` contract.
|
|
59
|
+
*/
|
|
60
|
+
export async function fetchPaymentLinkMeta(urlOrBase, idOrOpts, maybeOpts) {
|
|
61
|
+
const id = typeof idOrOpts === 'string' ? idOrOpts : null;
|
|
62
|
+
const opts = (typeof idOrOpts === 'string' ? maybeOpts : idOrOpts) ?? {};
|
|
63
|
+
const fetchImpl = opts.fetch ?? globalThis.fetch;
|
|
64
|
+
const target = buildTargetUrl(urlOrBase, id);
|
|
65
|
+
const res = await fetchImpl(target, opts.init);
|
|
66
|
+
if (!res.ok) {
|
|
67
|
+
const body = await res.text().catch(() => '');
|
|
68
|
+
throw new Error(`payment-link discovery failed (${res.status} ${res.statusText}) for ${target}: ${body || 'empty response'}`);
|
|
69
|
+
}
|
|
70
|
+
let json;
|
|
71
|
+
try {
|
|
72
|
+
json = await res.json();
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
throw new Error(`payment-link discovery returned non-JSON for ${target}: ${err.message}`);
|
|
76
|
+
}
|
|
77
|
+
return parsePaymentLinkMeta(json, target.toString());
|
|
78
|
+
}
|
|
79
|
+
function buildTargetUrl(urlOrBase, id) {
|
|
80
|
+
const raw = typeof urlOrBase === 'string' ? urlOrBase : urlOrBase.toString();
|
|
81
|
+
const base = new URL(raw);
|
|
82
|
+
if (!id)
|
|
83
|
+
return base;
|
|
84
|
+
const cleanBasePath = base.pathname.replace(/\/+$/, '');
|
|
85
|
+
const encoded = encodeURIComponent(id);
|
|
86
|
+
base.pathname = `${cleanBasePath}/x/${encoded}`;
|
|
87
|
+
return base;
|
|
88
|
+
}
|
|
89
|
+
function parsePaymentLinkMeta(input, source) {
|
|
90
|
+
if (!input || typeof input !== 'object') {
|
|
91
|
+
throw new Error(`invalid payment-link metadata from ${source}: body is not an object`);
|
|
92
|
+
}
|
|
93
|
+
const obj = input;
|
|
94
|
+
if (obj.ok !== true || obj.kind !== 'leash.payment-link') {
|
|
95
|
+
throw new Error(`invalid payment-link metadata from ${source}: expected { ok: true, kind: "leash.payment-link" }`);
|
|
96
|
+
}
|
|
97
|
+
const endpointRaw = obj.endpoint;
|
|
98
|
+
if (!endpointRaw || typeof endpointRaw !== 'object') {
|
|
99
|
+
throw new Error(`invalid payment-link metadata from ${source}: missing endpoint object`);
|
|
100
|
+
}
|
|
101
|
+
const endpointObj = endpointRaw;
|
|
102
|
+
const method = endpointObj.method;
|
|
103
|
+
if (method !== 'GET' && method !== 'POST') {
|
|
104
|
+
throw new Error(`invalid payment-link metadata from ${source}: endpoint.method must be GET|POST`);
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
ok: true,
|
|
108
|
+
kind: 'leash.payment-link',
|
|
109
|
+
...(typeof obj.docs === 'string' ? { docs: obj.docs } : {}),
|
|
110
|
+
...(typeof obj.note === 'string' ? { note: obj.note } : {}),
|
|
111
|
+
endpoint: {
|
|
112
|
+
id: asString(endpointObj.id, 'endpoint.id', source),
|
|
113
|
+
label: asString(endpointObj.label, 'endpoint.label', source),
|
|
114
|
+
description: endpointObj.description == null
|
|
115
|
+
? null
|
|
116
|
+
: asString(endpointObj.description, 'endpoint.description', source),
|
|
117
|
+
method,
|
|
118
|
+
url: asString(endpointObj.url, 'endpoint.url', source),
|
|
119
|
+
price: asString(endpointObj.price, 'endpoint.price', source),
|
|
120
|
+
currency: parseCurrency(endpointObj.currency, 'endpoint.currency', source),
|
|
121
|
+
accepts_currencies: parseAcceptsCurrencies(endpointObj.accepts_currencies, source),
|
|
122
|
+
network: asString(endpointObj.network, 'endpoint.network', source),
|
|
123
|
+
owner_agent: asString(endpointObj.owner_agent, 'endpoint.owner_agent', source),
|
|
124
|
+
payTo: endpointObj.payTo == null ? null : asString(endpointObj.payTo, 'endpoint.payTo', source),
|
|
125
|
+
response: parseResponse(endpointObj.response, source),
|
|
126
|
+
hooks: parseHooks(endpointObj.hooks, source),
|
|
127
|
+
created_at: asString(endpointObj.created_at, 'endpoint.created_at', source),
|
|
128
|
+
updated_at: asString(endpointObj.updated_at, 'endpoint.updated_at', source),
|
|
129
|
+
},
|
|
130
|
+
...(obj.facilitator == null
|
|
131
|
+
? {}
|
|
132
|
+
: { facilitator: asString(obj.facilitator, 'facilitator', source) }),
|
|
133
|
+
...(obj.explorer && typeof obj.explorer === 'object'
|
|
134
|
+
? {
|
|
135
|
+
explorer: {
|
|
136
|
+
...(typeof obj.explorer.agent === 'string'
|
|
137
|
+
? { agent: obj.explorer.agent }
|
|
138
|
+
: {}),
|
|
139
|
+
},
|
|
140
|
+
}
|
|
141
|
+
: {}),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function parseResponse(input, source) {
|
|
145
|
+
if (!input || typeof input !== 'object') {
|
|
146
|
+
throw new Error(`invalid payment-link metadata from ${source}: endpoint.response missing`);
|
|
147
|
+
}
|
|
148
|
+
const obj = input;
|
|
149
|
+
const bodyKind = obj.body_kind;
|
|
150
|
+
if (bodyKind !== 'json' && bodyKind !== 'text') {
|
|
151
|
+
throw new Error(`invalid payment-link metadata from ${source}: endpoint.response.body_kind must be "json" or "text"`);
|
|
152
|
+
}
|
|
153
|
+
const status = obj.status;
|
|
154
|
+
if (typeof status !== 'number' || !Number.isInteger(status)) {
|
|
155
|
+
throw new Error(`invalid payment-link metadata from ${source}: endpoint.response.status must be int`);
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
status,
|
|
159
|
+
mimeType: asString(obj.mimeType, 'endpoint.response.mimeType', source),
|
|
160
|
+
body_kind: bodyKind,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function parseHooks(input, source) {
|
|
164
|
+
if (!input || typeof input !== 'object') {
|
|
165
|
+
throw new Error(`invalid payment-link metadata from ${source}: endpoint.hooks missing`);
|
|
166
|
+
}
|
|
167
|
+
const obj = input;
|
|
168
|
+
return {
|
|
169
|
+
wrap_receipt: asBoolean(obj.wrap_receipt, 'endpoint.hooks.wrap_receipt', source),
|
|
170
|
+
webhook_url: obj.webhook_url == null
|
|
171
|
+
? null
|
|
172
|
+
: asString(obj.webhook_url, 'endpoint.hooks.webhook_url', source),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function asString(value, field, source) {
|
|
176
|
+
if (typeof value !== 'string' || value.length === 0) {
|
|
177
|
+
throw new Error(`invalid payment-link metadata from ${source}: ${field} must be non-empty string`);
|
|
178
|
+
}
|
|
179
|
+
return value;
|
|
180
|
+
}
|
|
181
|
+
function asBoolean(value, field, source) {
|
|
182
|
+
if (typeof value !== 'boolean') {
|
|
183
|
+
throw new Error(`invalid payment-link metadata from ${source}: ${field} must be boolean`);
|
|
184
|
+
}
|
|
185
|
+
return value;
|
|
186
|
+
}
|
|
187
|
+
const KNOWN_DISCOVERY_CURRENCIES = ['USDC', 'USDT', 'USDG'];
|
|
188
|
+
/**
|
|
189
|
+
* Parse a currency tag from a discovery payload. Defaults to `'USDC'` when
|
|
190
|
+
* the field is missing so older `/x/<id>` responses (pre multi-currency)
|
|
191
|
+
* still parse cleanly.
|
|
192
|
+
*/
|
|
193
|
+
function parseCurrency(value, field, source) {
|
|
194
|
+
if (value == null)
|
|
195
|
+
return 'USDC';
|
|
196
|
+
if (typeof value !== 'string') {
|
|
197
|
+
throw new Error(`invalid payment-link metadata from ${source}: ${field} must be a string`);
|
|
198
|
+
}
|
|
199
|
+
const upper = value.toUpperCase();
|
|
200
|
+
if (!KNOWN_DISCOVERY_CURRENCIES.includes(upper)) {
|
|
201
|
+
throw new Error(`invalid payment-link metadata from ${source}: ${field} must be one of ${KNOWN_DISCOVERY_CURRENCIES.join(', ')}`);
|
|
202
|
+
}
|
|
203
|
+
return upper;
|
|
204
|
+
}
|
|
205
|
+
function parseAcceptsCurrencies(value, source) {
|
|
206
|
+
if (value == null)
|
|
207
|
+
return [];
|
|
208
|
+
if (!Array.isArray(value)) {
|
|
209
|
+
throw new Error(`invalid payment-link metadata from ${source}: endpoint.accepts_currencies must be an array`);
|
|
210
|
+
}
|
|
211
|
+
return value.map((entry, idx) => parseCurrency(entry, `endpoint.accepts_currencies[${idx}]`, source));
|
|
212
|
+
}
|
|
213
|
+
//# sourceMappingURL=discovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../src/x402/discovery.ts"],"names":[],"mappings":"AAkFA;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAgC;IACnE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAChE,MAAM,OAAO,GAAG,GAAG,MAAM,MAAM,QAAQ,CAAC,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