uvd-x402-sdk 2.85.0 → 2.86.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/dist/backend/index.d.mts +3 -3474
- package/dist/backend/index.d.ts +3 -3474
- package/dist/backend/index.js +275 -49
- package/dist/backend/index.js.map +1 -1
- package/dist/backend/index.mjs +275 -49
- package/dist/backend/index.mjs.map +1 -1
- package/dist/index-4_LWWlyF.d.ts +3756 -0
- package/dist/index-De03nksW.d.mts +3756 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +217 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +209 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/backend/index.ts +107 -28
- package/src/index.ts +22 -0
- package/src/lifecycle-auth.ts +513 -0
- package/src/lifecycle-auth.vectors.json +28 -0
package/dist/backend/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
require('ethers');
|
|
3
|
+
var ethers = require('ethers');
|
|
4
4
|
|
|
5
5
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
6
6
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
@@ -48,6 +48,19 @@ var CAIP2_IDENTIFIERS = {
|
|
|
48
48
|
var CAIP2_TO_CHAIN = Object.fromEntries(
|
|
49
49
|
Object.entries(CAIP2_IDENTIFIERS).map(([k, v]) => [v, k])
|
|
50
50
|
);
|
|
51
|
+
var X402Error = class _X402Error extends Error {
|
|
52
|
+
code;
|
|
53
|
+
details;
|
|
54
|
+
constructor(message, code, details) {
|
|
55
|
+
super(message);
|
|
56
|
+
this.name = "X402Error";
|
|
57
|
+
this.code = code;
|
|
58
|
+
this.details = details;
|
|
59
|
+
if (Error.captureStackTrace) {
|
|
60
|
+
Error.captureStackTrace(this, _X402Error);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
51
64
|
|
|
52
65
|
// src/chains/index.ts
|
|
53
66
|
var DEFAULT_FACILITATOR_URL = "https://facilitator.ultravioletadao.xyz";
|
|
@@ -1115,6 +1128,188 @@ var DEFAULT_MIN_FEE_BPS = 0;
|
|
|
1115
1128
|
var DEFAULT_MAX_FEE_BPS = OPERATOR_FEE_BPS + MAX_PROTOCOL_FEE_BPS;
|
|
1116
1129
|
var REVIEW_WINDOW_SEC = 7 * 24 * 3600;
|
|
1117
1130
|
var REFUND_WINDOW_SEC = 7 * 24 * 3600;
|
|
1131
|
+
var LIFECYCLE_DOMAIN_NAME = "x402 escrow lifecycle";
|
|
1132
|
+
var LIFECYCLE_DOMAIN_VERSION = "1";
|
|
1133
|
+
var LIFECYCLE_MAX_DEADLINE_SECS = 900;
|
|
1134
|
+
var LIFECYCLE_DEFAULT_DEADLINE_SECS = 600;
|
|
1135
|
+
var LIFECYCLE_ACTIONS = ["release", "refundInEscrow"];
|
|
1136
|
+
var LIFECYCLE_ORDER_TYPES = {
|
|
1137
|
+
LifecycleOrder: [
|
|
1138
|
+
{ name: "action", type: "string" },
|
|
1139
|
+
{ name: "amount", type: "uint256" },
|
|
1140
|
+
{ name: "deadline", type: "uint256" },
|
|
1141
|
+
{ name: "nonce", type: "bytes32" },
|
|
1142
|
+
{ name: "paymentInfo", type: "PaymentInfo" }
|
|
1143
|
+
],
|
|
1144
|
+
PaymentInfo: [
|
|
1145
|
+
{ name: "operator", type: "address" },
|
|
1146
|
+
{ name: "payer", type: "address" },
|
|
1147
|
+
{ name: "receiver", type: "address" },
|
|
1148
|
+
{ name: "token", type: "address" },
|
|
1149
|
+
{ name: "maxAmount", type: "uint120" },
|
|
1150
|
+
{ name: "preApprovalExpiry", type: "uint48" },
|
|
1151
|
+
{ name: "authorizationExpiry", type: "uint48" },
|
|
1152
|
+
{ name: "refundExpiry", type: "uint48" },
|
|
1153
|
+
{ name: "minFeeBps", type: "uint16" },
|
|
1154
|
+
{ name: "maxFeeBps", type: "uint16" },
|
|
1155
|
+
{ name: "feeReceiver", type: "address" },
|
|
1156
|
+
{ name: "salt", type: "uint256" }
|
|
1157
|
+
]
|
|
1158
|
+
};
|
|
1159
|
+
var LIFECYCLE_PI_KEYS = [
|
|
1160
|
+
"operator",
|
|
1161
|
+
"receiver",
|
|
1162
|
+
"token",
|
|
1163
|
+
"maxAmount",
|
|
1164
|
+
"preApprovalExpiry",
|
|
1165
|
+
"authorizationExpiry",
|
|
1166
|
+
"refundExpiry",
|
|
1167
|
+
"minFeeBps",
|
|
1168
|
+
"maxFeeBps",
|
|
1169
|
+
"feeReceiver",
|
|
1170
|
+
"salt"
|
|
1171
|
+
];
|
|
1172
|
+
function saltToBigInt(salt) {
|
|
1173
|
+
if (typeof salt === "bigint") return salt;
|
|
1174
|
+
if (typeof salt === "number") {
|
|
1175
|
+
if (!Number.isInteger(salt) || salt < 0) {
|
|
1176
|
+
throw new X402Error(`paymentInfo.salt invalid: ${String(salt)}`, "INVALID_CONFIG");
|
|
1177
|
+
}
|
|
1178
|
+
return BigInt(salt);
|
|
1179
|
+
}
|
|
1180
|
+
if (typeof salt === "string") {
|
|
1181
|
+
const trimmed = salt.trim();
|
|
1182
|
+
const hex = trimmed.startsWith("0x") || trimmed.startsWith("0X") ? trimmed : `0x${trimmed}`;
|
|
1183
|
+
try {
|
|
1184
|
+
return BigInt(hex);
|
|
1185
|
+
} catch {
|
|
1186
|
+
throw new X402Error(`paymentInfo.salt invalid: ${salt}`, "INVALID_CONFIG");
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
throw new X402Error(`paymentInfo.salt invalid: ${String(salt)}`, "INVALID_CONFIG");
|
|
1190
|
+
}
|
|
1191
|
+
function nonceToBytes32(nonce) {
|
|
1192
|
+
if (typeof nonce !== "string") {
|
|
1193
|
+
throw new X402Error(`lifecycleAuth.nonce invalid: ${String(nonce)}`, "INVALID_CONFIG");
|
|
1194
|
+
}
|
|
1195
|
+
const raw = nonce.startsWith("0x") || nonce.startsWith("0X") ? nonce.slice(2) : nonce;
|
|
1196
|
+
if (!/^[0-9a-fA-F]*$/.test(raw)) {
|
|
1197
|
+
throw new X402Error(`lifecycleAuth.nonce is not hex: ${nonce}`, "INVALID_CONFIG");
|
|
1198
|
+
}
|
|
1199
|
+
if (raw.length !== 64) {
|
|
1200
|
+
throw new X402Error(
|
|
1201
|
+
`lifecycleAuth.nonce must be 32 bytes, got ${raw.length / 2}`,
|
|
1202
|
+
"INVALID_CONFIG"
|
|
1203
|
+
);
|
|
1204
|
+
}
|
|
1205
|
+
return `0x${raw.toLowerCase()}`;
|
|
1206
|
+
}
|
|
1207
|
+
function randomNonce() {
|
|
1208
|
+
const webCrypto = globalThis.crypto;
|
|
1209
|
+
if (webCrypto?.getRandomValues) {
|
|
1210
|
+
const bytes = new Uint8Array(32);
|
|
1211
|
+
webCrypto.getRandomValues(bytes);
|
|
1212
|
+
return ethers.ethers.hexlify(bytes);
|
|
1213
|
+
}
|
|
1214
|
+
return ethers.ethers.hexlify(ethers.ethers.randomBytes(32));
|
|
1215
|
+
}
|
|
1216
|
+
function toUintString(value, field) {
|
|
1217
|
+
let n;
|
|
1218
|
+
try {
|
|
1219
|
+
n = typeof value === "bigint" ? value : BigInt(value);
|
|
1220
|
+
} catch {
|
|
1221
|
+
throw new X402Error(`${field} must be a non-negative integer, got ${String(value)}`, "INVALID_CONFIG");
|
|
1222
|
+
}
|
|
1223
|
+
if (n < 0n) {
|
|
1224
|
+
throw new X402Error(`${field} must be a non-negative integer, got ${String(value)}`, "INVALID_CONFIG");
|
|
1225
|
+
}
|
|
1226
|
+
return n.toString();
|
|
1227
|
+
}
|
|
1228
|
+
function buildLifecycleTypedData(params) {
|
|
1229
|
+
const { action, paymentInfo, payer, amount, chainId, deadline, nonce } = params;
|
|
1230
|
+
if (!LIFECYCLE_ACTIONS.includes(action)) {
|
|
1231
|
+
throw new X402Error(
|
|
1232
|
+
`unknown lifecycle action ${String(action)}; the facilitator only signs ${LIFECYCLE_ACTIONS.join(", ")}`,
|
|
1233
|
+
"INVALID_CONFIG"
|
|
1234
|
+
);
|
|
1235
|
+
}
|
|
1236
|
+
let amountBig;
|
|
1237
|
+
try {
|
|
1238
|
+
amountBig = typeof amount === "bigint" ? amount : BigInt(amount);
|
|
1239
|
+
} catch {
|
|
1240
|
+
throw new X402Error(`amount must be an integer >= 0, got ${String(amount)}`, "INVALID_AMOUNT");
|
|
1241
|
+
}
|
|
1242
|
+
if (amountBig < 0n) {
|
|
1243
|
+
throw new X402Error(`amount must be an integer >= 0, got ${String(amount)}`, "INVALID_AMOUNT");
|
|
1244
|
+
}
|
|
1245
|
+
const pi = paymentInfo ?? {};
|
|
1246
|
+
const missing = LIFECYCLE_PI_KEYS.filter((k) => pi[k] === void 0);
|
|
1247
|
+
if (missing.length > 0) {
|
|
1248
|
+
throw new X402Error(
|
|
1249
|
+
`paymentInfo is missing fields that enter the signature: ${missing.join(", ")}. The paymentInfo that is SENT is the one that is signed; defaulting a field would sign a different struct than the one that reaches the facilitator.`,
|
|
1250
|
+
"INVALID_CONFIG"
|
|
1251
|
+
);
|
|
1252
|
+
}
|
|
1253
|
+
return {
|
|
1254
|
+
domain: {
|
|
1255
|
+
name: LIFECYCLE_DOMAIN_NAME,
|
|
1256
|
+
version: LIFECYCLE_DOMAIN_VERSION,
|
|
1257
|
+
chainId: Number(chainId)
|
|
1258
|
+
},
|
|
1259
|
+
types: LIFECYCLE_ORDER_TYPES,
|
|
1260
|
+
primaryType: "LifecycleOrder",
|
|
1261
|
+
message: {
|
|
1262
|
+
action,
|
|
1263
|
+
amount: amountBig.toString(),
|
|
1264
|
+
deadline: toUintString(deadline, "deadline"),
|
|
1265
|
+
nonce: nonceToBytes32(nonce),
|
|
1266
|
+
paymentInfo: {
|
|
1267
|
+
operator: ethers.ethers.getAddress(paymentInfo.operator),
|
|
1268
|
+
payer: ethers.ethers.getAddress(payer),
|
|
1269
|
+
receiver: ethers.ethers.getAddress(paymentInfo.receiver),
|
|
1270
|
+
token: ethers.ethers.getAddress(paymentInfo.token),
|
|
1271
|
+
maxAmount: toUintString(paymentInfo.maxAmount, "paymentInfo.maxAmount"),
|
|
1272
|
+
preApprovalExpiry: toUintString(paymentInfo.preApprovalExpiry, "paymentInfo.preApprovalExpiry"),
|
|
1273
|
+
authorizationExpiry: toUintString(
|
|
1274
|
+
paymentInfo.authorizationExpiry,
|
|
1275
|
+
"paymentInfo.authorizationExpiry"
|
|
1276
|
+
),
|
|
1277
|
+
refundExpiry: toUintString(paymentInfo.refundExpiry, "paymentInfo.refundExpiry"),
|
|
1278
|
+
minFeeBps: toUintString(paymentInfo.minFeeBps, "paymentInfo.minFeeBps"),
|
|
1279
|
+
maxFeeBps: toUintString(paymentInfo.maxFeeBps, "paymentInfo.maxFeeBps"),
|
|
1280
|
+
feeReceiver: ethers.ethers.getAddress(paymentInfo.feeReceiver),
|
|
1281
|
+
// uint256 in the signature, bytes32 on the wire — see saltToBigInt.
|
|
1282
|
+
salt: saltToBigInt(paymentInfo.salt).toString()
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
};
|
|
1286
|
+
}
|
|
1287
|
+
async function buildLifecycleAuth(params) {
|
|
1288
|
+
const { wallet, deadline, nonce, now, ...rest } = params;
|
|
1289
|
+
const nowSec = now === void 0 ? Math.floor(Date.now() / 1e3) : Math.floor(now);
|
|
1290
|
+
const dl = deadline === void 0 ? nowSec + LIFECYCLE_DEFAULT_DEADLINE_SECS : Math.floor(deadline);
|
|
1291
|
+
const nonceHex = nonce === void 0 ? randomNonce() : nonce;
|
|
1292
|
+
if (dl < nowSec) {
|
|
1293
|
+
throw new X402Error(
|
|
1294
|
+
`deadline ${dl} is in the past (now ${nowSec}): the facilitator discards it as \`expired\``,
|
|
1295
|
+
"INVALID_CONFIG"
|
|
1296
|
+
);
|
|
1297
|
+
}
|
|
1298
|
+
if (dl - nowSec > LIFECYCLE_MAX_DEADLINE_SECS) {
|
|
1299
|
+
throw new X402Error(
|
|
1300
|
+
`deadline ${dl} is ${dl - nowSec} s ahead and the facilitator's ceiling is ${LIFECYCLE_MAX_DEADLINE_SECS} s (\`deadline_too_far\`): a leaked order cannot be a standing permission`,
|
|
1301
|
+
"INVALID_CONFIG"
|
|
1302
|
+
);
|
|
1303
|
+
}
|
|
1304
|
+
const typed = buildLifecycleTypedData({ ...rest, deadline: dl, nonce: nonceHex });
|
|
1305
|
+
const signed = await wallet.signTypedData(JSON.stringify(typed));
|
|
1306
|
+
return {
|
|
1307
|
+
signer: wallet.getAddress(),
|
|
1308
|
+
deadline: dl,
|
|
1309
|
+
nonce: nonceToBytes32(nonceHex),
|
|
1310
|
+
signature: signed.signature
|
|
1311
|
+
};
|
|
1312
|
+
}
|
|
1118
1313
|
|
|
1119
1314
|
// src/backend/facilitator-error.ts
|
|
1120
1315
|
var WRITER_LEASE_REASONS = [
|
|
@@ -4204,8 +4399,8 @@ var AdvancedEscrowClient = class {
|
|
|
4204
4399
|
* Matches the on-chain AuthCaptureEscrow nonce derivation.
|
|
4205
4400
|
*/
|
|
4206
4401
|
async computeNonce(paymentInfo) {
|
|
4207
|
-
const { ethers:
|
|
4208
|
-
const piTuple =
|
|
4402
|
+
const { ethers: ethers4 } = await import('ethers');
|
|
4403
|
+
const piTuple = ethers4.AbiCoder.defaultAbiCoder().encode(
|
|
4209
4404
|
["bytes32", "tuple(address,address,address,address,uint120,uint48,uint48,uint48,uint16,uint16,address,uint256)"],
|
|
4210
4405
|
[
|
|
4211
4406
|
PAYMENT_INFO_TYPEHASH,
|
|
@@ -4226,12 +4421,12 @@ var AdvancedEscrowClient = class {
|
|
|
4226
4421
|
]
|
|
4227
4422
|
]
|
|
4228
4423
|
);
|
|
4229
|
-
const piHash =
|
|
4230
|
-
const finalEncoded =
|
|
4424
|
+
const piHash = ethers4.keccak256(piTuple);
|
|
4425
|
+
const finalEncoded = ethers4.AbiCoder.defaultAbiCoder().encode(
|
|
4231
4426
|
["uint256", "address", "bytes32"],
|
|
4232
4427
|
[this.chainId, this.contracts.escrow, piHash]
|
|
4233
4428
|
);
|
|
4234
|
-
return
|
|
4429
|
+
return ethers4.keccak256(finalEncoded);
|
|
4235
4430
|
}
|
|
4236
4431
|
/**
|
|
4237
4432
|
* Sign ReceiveWithAuthorization for ERC-3009.
|
|
@@ -4388,17 +4583,17 @@ var AdvancedEscrowClient = class {
|
|
|
4388
4583
|
async release(paymentInfo, amount) {
|
|
4389
4584
|
if (!this.payerAddress) await this.init();
|
|
4390
4585
|
try {
|
|
4391
|
-
const { ethers:
|
|
4586
|
+
const { ethers: ethers4 } = await import('ethers');
|
|
4392
4587
|
const isCreate3 = CREATE3_CHAIN_IDS.has(this.chainId);
|
|
4393
4588
|
const abi = isCreate3 ? OPERATOR_ABI_CREATE3 : OPERATOR_ABI;
|
|
4394
4589
|
const amt = amount || paymentInfo.maxAmount;
|
|
4395
4590
|
const tuple = this.buildTuple(paymentInfo);
|
|
4396
4591
|
if (this.walletAdapter) {
|
|
4397
|
-
return this.sendViaAdapter(
|
|
4592
|
+
return this.sendViaAdapter(ethers4, abi, (iface) => {
|
|
4398
4593
|
return isCreate3 ? iface.encodeFunctionData("release", [tuple, amt, "0x"]) : iface.encodeFunctionData("release", [tuple, amt]);
|
|
4399
4594
|
});
|
|
4400
4595
|
}
|
|
4401
|
-
const contract = new
|
|
4596
|
+
const contract = new ethers4.Contract(this.contracts.operator, abi, this.signer);
|
|
4402
4597
|
const tx = isCreate3 ? await contract.release(tuple, amt, "0x", { gasLimit: this.gasLimit }) : await contract.release(tuple, amt, { gasLimit: this.gasLimit });
|
|
4403
4598
|
const receipt = await tx.wait();
|
|
4404
4599
|
return {
|
|
@@ -4422,17 +4617,17 @@ var AdvancedEscrowClient = class {
|
|
|
4422
4617
|
async refundInEscrow(paymentInfo, amount) {
|
|
4423
4618
|
if (!this.payerAddress) await this.init();
|
|
4424
4619
|
try {
|
|
4425
|
-
const { ethers:
|
|
4620
|
+
const { ethers: ethers4 } = await import('ethers');
|
|
4426
4621
|
const isCreate3 = CREATE3_CHAIN_IDS.has(this.chainId);
|
|
4427
4622
|
const abi = isCreate3 ? OPERATOR_ABI_CREATE3 : OPERATOR_ABI;
|
|
4428
4623
|
const amt = amount || paymentInfo.maxAmount;
|
|
4429
4624
|
const tuple = this.buildTuple(paymentInfo);
|
|
4430
4625
|
if (this.walletAdapter) {
|
|
4431
|
-
return this.sendViaAdapter(
|
|
4626
|
+
return this.sendViaAdapter(ethers4, abi, (iface) => {
|
|
4432
4627
|
return isCreate3 ? iface.encodeFunctionData("refundInEscrow", [tuple, amt, "0x"]) : iface.encodeFunctionData("refundInEscrow", [tuple, amt]);
|
|
4433
4628
|
});
|
|
4434
4629
|
}
|
|
4435
|
-
const contract = new
|
|
4630
|
+
const contract = new ethers4.Contract(this.contracts.operator, abi, this.signer);
|
|
4436
4631
|
const tx = isCreate3 ? await contract.refundInEscrow(tuple, amt, "0x", { gasLimit: this.gasLimit }) : await contract.refundInEscrow(tuple, amt, { gasLimit: this.gasLimit });
|
|
4437
4632
|
const receipt = await tx.wait();
|
|
4438
4633
|
return {
|
|
@@ -4467,30 +4662,49 @@ var AdvancedEscrowClient = class {
|
|
|
4467
4662
|
* const result = await client.releaseViaFacilitator(pi);
|
|
4468
4663
|
* console.log(result.transactionHash);
|
|
4469
4664
|
* ```
|
|
4665
|
+
*
|
|
4666
|
+
* @example Signed release (the payer proves the release is theirs to ask for)
|
|
4667
|
+
* ```typescript
|
|
4668
|
+
* await client.releaseViaFacilitator(pi, undefined, {
|
|
4669
|
+
* lifecycleSigner: payerWallet, // EnvKeyAdapter, OWS, wagmiLifecycleSigner(...)
|
|
4670
|
+
* });
|
|
4671
|
+
* ```
|
|
4470
4672
|
*/
|
|
4471
|
-
async releaseViaFacilitator(paymentInfo, amount) {
|
|
4673
|
+
async releaseViaFacilitator(paymentInfo, amount, options) {
|
|
4472
4674
|
if (!this.payerAddress) await this.init();
|
|
4473
4675
|
try {
|
|
4676
|
+
const wirePaymentInfo = {
|
|
4677
|
+
operator: paymentInfo.operator,
|
|
4678
|
+
receiver: paymentInfo.receiver,
|
|
4679
|
+
token: paymentInfo.token,
|
|
4680
|
+
maxAmount: paymentInfo.maxAmount,
|
|
4681
|
+
preApprovalExpiry: paymentInfo.preApprovalExpiry,
|
|
4682
|
+
authorizationExpiry: paymentInfo.authorizationExpiry,
|
|
4683
|
+
refundExpiry: paymentInfo.refundExpiry,
|
|
4684
|
+
minFeeBps: paymentInfo.minFeeBps,
|
|
4685
|
+
maxFeeBps: paymentInfo.maxFeeBps,
|
|
4686
|
+
feeReceiver: paymentInfo.feeReceiver,
|
|
4687
|
+
salt: paymentInfo.salt
|
|
4688
|
+
};
|
|
4689
|
+
const releaseAmount = amount || paymentInfo.maxAmount;
|
|
4690
|
+
const lifecycleAuth = options?.lifecycleSigner ? await buildLifecycleAuth({
|
|
4691
|
+
action: "release",
|
|
4692
|
+
paymentInfo: wirePaymentInfo,
|
|
4693
|
+
payer: this.payerAddress,
|
|
4694
|
+
amount: releaseAmount,
|
|
4695
|
+
chainId: this.chainId,
|
|
4696
|
+
wallet: options.lifecycleSigner,
|
|
4697
|
+
deadline: options.lifecycleDeadline
|
|
4698
|
+
}) : void 0;
|
|
4474
4699
|
const payload = {
|
|
4475
4700
|
x402Version: 2,
|
|
4476
4701
|
scheme: "escrow",
|
|
4477
4702
|
action: "release",
|
|
4478
4703
|
payload: {
|
|
4479
|
-
paymentInfo:
|
|
4480
|
-
operator: paymentInfo.operator,
|
|
4481
|
-
receiver: paymentInfo.receiver,
|
|
4482
|
-
token: paymentInfo.token,
|
|
4483
|
-
maxAmount: paymentInfo.maxAmount,
|
|
4484
|
-
preApprovalExpiry: paymentInfo.preApprovalExpiry,
|
|
4485
|
-
authorizationExpiry: paymentInfo.authorizationExpiry,
|
|
4486
|
-
refundExpiry: paymentInfo.refundExpiry,
|
|
4487
|
-
minFeeBps: paymentInfo.minFeeBps,
|
|
4488
|
-
maxFeeBps: paymentInfo.maxFeeBps,
|
|
4489
|
-
feeReceiver: paymentInfo.feeReceiver,
|
|
4490
|
-
salt: paymentInfo.salt
|
|
4491
|
-
},
|
|
4704
|
+
paymentInfo: wirePaymentInfo,
|
|
4492
4705
|
payer: this.payerAddress,
|
|
4493
|
-
amount:
|
|
4706
|
+
amount: releaseAmount,
|
|
4707
|
+
...lifecycleAuth ? { lifecycleAuth } : {}
|
|
4494
4708
|
},
|
|
4495
4709
|
paymentRequirements: {
|
|
4496
4710
|
scheme: "escrow",
|
|
@@ -4593,29 +4807,41 @@ var AdvancedEscrowClient = class {
|
|
|
4593
4807
|
* }
|
|
4594
4808
|
* ```
|
|
4595
4809
|
*/
|
|
4596
|
-
async refundViaFacilitator(paymentInfo, amount) {
|
|
4810
|
+
async refundViaFacilitator(paymentInfo, amount, options) {
|
|
4597
4811
|
if (!this.payerAddress) await this.init();
|
|
4598
4812
|
try {
|
|
4813
|
+
const wirePaymentInfo = {
|
|
4814
|
+
operator: paymentInfo.operator,
|
|
4815
|
+
receiver: paymentInfo.receiver,
|
|
4816
|
+
token: paymentInfo.token,
|
|
4817
|
+
maxAmount: paymentInfo.maxAmount,
|
|
4818
|
+
preApprovalExpiry: paymentInfo.preApprovalExpiry,
|
|
4819
|
+
authorizationExpiry: paymentInfo.authorizationExpiry,
|
|
4820
|
+
refundExpiry: paymentInfo.refundExpiry,
|
|
4821
|
+
minFeeBps: paymentInfo.minFeeBps,
|
|
4822
|
+
maxFeeBps: paymentInfo.maxFeeBps,
|
|
4823
|
+
feeReceiver: paymentInfo.feeReceiver,
|
|
4824
|
+
salt: paymentInfo.salt
|
|
4825
|
+
};
|
|
4826
|
+
const refundAmount = amount || paymentInfo.maxAmount;
|
|
4827
|
+
const lifecycleAuth = options?.lifecycleSigner ? await buildLifecycleAuth({
|
|
4828
|
+
action: "refundInEscrow",
|
|
4829
|
+
paymentInfo: wirePaymentInfo,
|
|
4830
|
+
payer: this.payerAddress,
|
|
4831
|
+
amount: refundAmount,
|
|
4832
|
+
chainId: this.chainId,
|
|
4833
|
+
wallet: options.lifecycleSigner,
|
|
4834
|
+
deadline: options.lifecycleDeadline
|
|
4835
|
+
}) : void 0;
|
|
4599
4836
|
const payload = {
|
|
4600
4837
|
x402Version: 2,
|
|
4601
4838
|
scheme: "escrow",
|
|
4602
4839
|
action: "refundInEscrow",
|
|
4603
4840
|
payload: {
|
|
4604
|
-
paymentInfo:
|
|
4605
|
-
operator: paymentInfo.operator,
|
|
4606
|
-
receiver: paymentInfo.receiver,
|
|
4607
|
-
token: paymentInfo.token,
|
|
4608
|
-
maxAmount: paymentInfo.maxAmount,
|
|
4609
|
-
preApprovalExpiry: paymentInfo.preApprovalExpiry,
|
|
4610
|
-
authorizationExpiry: paymentInfo.authorizationExpiry,
|
|
4611
|
-
refundExpiry: paymentInfo.refundExpiry,
|
|
4612
|
-
minFeeBps: paymentInfo.minFeeBps,
|
|
4613
|
-
maxFeeBps: paymentInfo.maxFeeBps,
|
|
4614
|
-
feeReceiver: paymentInfo.feeReceiver,
|
|
4615
|
-
salt: paymentInfo.salt
|
|
4616
|
-
},
|
|
4841
|
+
paymentInfo: wirePaymentInfo,
|
|
4617
4842
|
payer: this.payerAddress,
|
|
4618
|
-
amount:
|
|
4843
|
+
amount: refundAmount,
|
|
4844
|
+
...lifecycleAuth ? { lifecycleAuth } : {}
|
|
4619
4845
|
},
|
|
4620
4846
|
paymentRequirements: {
|
|
4621
4847
|
scheme: "escrow",
|
|
@@ -4735,7 +4961,7 @@ var AdvancedEscrowClient = class {
|
|
|
4735
4961
|
async charge(paymentInfo, amount) {
|
|
4736
4962
|
if (!this.payerAddress) await this.init();
|
|
4737
4963
|
try {
|
|
4738
|
-
const { ethers:
|
|
4964
|
+
const { ethers: ethers4 } = await import('ethers');
|
|
4739
4965
|
const nonce = await this.computeNonce(paymentInfo);
|
|
4740
4966
|
const amt = amount || paymentInfo.maxAmount;
|
|
4741
4967
|
const auth = {
|
|
@@ -4747,10 +4973,10 @@ var AdvancedEscrowClient = class {
|
|
|
4747
4973
|
nonce
|
|
4748
4974
|
};
|
|
4749
4975
|
const signature = await this.signErc3009(auth);
|
|
4750
|
-
const collectorData =
|
|
4976
|
+
const collectorData = ethers4.getBytes(signature);
|
|
4751
4977
|
const tuple = this.buildTuple(paymentInfo);
|
|
4752
4978
|
if (this.walletAdapter) {
|
|
4753
|
-
return this.sendViaAdapter(
|
|
4979
|
+
return this.sendViaAdapter(ethers4, OPERATOR_ABI, (iface) => {
|
|
4754
4980
|
return iface.encodeFunctionData("charge", [
|
|
4755
4981
|
tuple,
|
|
4756
4982
|
amt,
|
|
@@ -4759,7 +4985,7 @@ var AdvancedEscrowClient = class {
|
|
|
4759
4985
|
]);
|
|
4760
4986
|
});
|
|
4761
4987
|
}
|
|
4762
|
-
const contract = new
|
|
4988
|
+
const contract = new ethers4.Contract(this.contracts.operator, OPERATOR_ABI, this.signer);
|
|
4763
4989
|
const tx = await contract.charge(
|
|
4764
4990
|
tuple,
|
|
4765
4991
|
amt,
|
|
@@ -4801,11 +5027,11 @@ var AdvancedEscrowClient = class {
|
|
|
4801
5027
|
async refundPostEscrow(paymentInfo, amount, tokenCollector, collectorData) {
|
|
4802
5028
|
if (!this.payerAddress) await this.init();
|
|
4803
5029
|
try {
|
|
4804
|
-
const { ethers:
|
|
5030
|
+
const { ethers: ethers4 } = await import('ethers');
|
|
4805
5031
|
const amt = amount || paymentInfo.maxAmount;
|
|
4806
5032
|
const tuple = this.buildTuple(paymentInfo);
|
|
4807
5033
|
if (this.walletAdapter) {
|
|
4808
|
-
return this.sendViaAdapter(
|
|
5034
|
+
return this.sendViaAdapter(ethers4, OPERATOR_ABI, (iface) => {
|
|
4809
5035
|
return iface.encodeFunctionData("refundPostEscrow", [
|
|
4810
5036
|
tuple,
|
|
4811
5037
|
amt,
|
|
@@ -4814,7 +5040,7 @@ var AdvancedEscrowClient = class {
|
|
|
4814
5040
|
]);
|
|
4815
5041
|
});
|
|
4816
5042
|
}
|
|
4817
|
-
const contract = new
|
|
5043
|
+
const contract = new ethers4.Contract(this.contracts.operator, OPERATOR_ABI, this.signer);
|
|
4818
5044
|
const tx = await contract.refundPostEscrow(
|
|
4819
5045
|
tuple,
|
|
4820
5046
|
amt,
|