uvd-x402-sdk 2.62.0 → 2.63.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 +4 -1
- package/dist/backend/index.d.ts +4 -1
- package/dist/backend/index.js +29 -21
- package/dist/backend/index.js.map +1 -1
- package/dist/backend/index.mjs +29 -21
- package/dist/backend/index.mjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/backend/index.ts +18 -2
- package/src/escrow-preauth.ts +2 -2
package/dist/backend/index.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import 'ethers';
|
|
2
|
+
|
|
1
3
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
4
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
5
|
}) : x)(function(x) {
|
|
@@ -1086,6 +1088,8 @@ function decodeX402Header(encoded) {
|
|
|
1086
1088
|
const json = decodeBase64Utf8(encoded);
|
|
1087
1089
|
return JSON.parse(json);
|
|
1088
1090
|
}
|
|
1091
|
+
var REVIEW_WINDOW_SEC = 7 * 24 * 3600;
|
|
1092
|
+
var REFUND_WINDOW_SEC = 7 * 24 * 3600;
|
|
1089
1093
|
|
|
1090
1094
|
// src/backend/index.ts
|
|
1091
1095
|
function parsePaymentHeader(headerValue) {
|
|
@@ -3502,9 +3506,13 @@ var AdvancedEscrowClient = class {
|
|
|
3502
3506
|
* @param tier - Task tier determines timing parameters
|
|
3503
3507
|
* @param salt - Random salt (auto-generated if not provided)
|
|
3504
3508
|
*/
|
|
3505
|
-
buildPaymentInfo(receiver, amount, tier = "standard", salt) {
|
|
3509
|
+
buildPaymentInfo(receiver, amount, tier = "standard", salt, opts) {
|
|
3506
3510
|
const now = Math.floor(Date.now() / 1e3);
|
|
3507
3511
|
const t = TIER_TIMINGS[tier];
|
|
3512
|
+
const reviewWindow = opts?.reviewWindowSec ?? REVIEW_WINDOW_SEC;
|
|
3513
|
+
const reviewBase = Math.max(now, opts?.deadline ?? now);
|
|
3514
|
+
const authorizationExpiry = Math.max(now + t.auth, reviewBase + reviewWindow);
|
|
3515
|
+
const refundExpiry = Math.max(now + t.refund, authorizationExpiry + REFUND_WINDOW_SEC);
|
|
3508
3516
|
let generatedSalt = salt;
|
|
3509
3517
|
if (!generatedSalt) {
|
|
3510
3518
|
const bytes = new Uint8Array(32);
|
|
@@ -3523,8 +3531,8 @@ var AdvancedEscrowClient = class {
|
|
|
3523
3531
|
token: this.contracts.usdc,
|
|
3524
3532
|
maxAmount: amount,
|
|
3525
3533
|
preApprovalExpiry: now + t.pre,
|
|
3526
|
-
authorizationExpiry
|
|
3527
|
-
refundExpiry
|
|
3534
|
+
authorizationExpiry,
|
|
3535
|
+
refundExpiry,
|
|
3528
3536
|
minFeeBps: 0,
|
|
3529
3537
|
maxFeeBps: 800,
|
|
3530
3538
|
feeReceiver: this.contracts.operator,
|
|
@@ -3536,8 +3544,8 @@ var AdvancedEscrowClient = class {
|
|
|
3536
3544
|
* Matches the on-chain AuthCaptureEscrow nonce derivation.
|
|
3537
3545
|
*/
|
|
3538
3546
|
async computeNonce(paymentInfo) {
|
|
3539
|
-
const { ethers } = await import('ethers');
|
|
3540
|
-
const piTuple =
|
|
3547
|
+
const { ethers: ethers2 } = await import('ethers');
|
|
3548
|
+
const piTuple = ethers2.AbiCoder.defaultAbiCoder().encode(
|
|
3541
3549
|
["bytes32", "tuple(address,address,address,address,uint120,uint48,uint48,uint48,uint16,uint16,address,uint256)"],
|
|
3542
3550
|
[
|
|
3543
3551
|
PAYMENT_INFO_TYPEHASH,
|
|
@@ -3558,12 +3566,12 @@ var AdvancedEscrowClient = class {
|
|
|
3558
3566
|
]
|
|
3559
3567
|
]
|
|
3560
3568
|
);
|
|
3561
|
-
const piHash =
|
|
3562
|
-
const finalEncoded =
|
|
3569
|
+
const piHash = ethers2.keccak256(piTuple);
|
|
3570
|
+
const finalEncoded = ethers2.AbiCoder.defaultAbiCoder().encode(
|
|
3563
3571
|
["uint256", "address", "bytes32"],
|
|
3564
3572
|
[this.chainId, this.contracts.escrow, piHash]
|
|
3565
3573
|
);
|
|
3566
|
-
return
|
|
3574
|
+
return ethers2.keccak256(finalEncoded);
|
|
3567
3575
|
}
|
|
3568
3576
|
/**
|
|
3569
3577
|
* Sign ReceiveWithAuthorization for ERC-3009.
|
|
@@ -3720,17 +3728,17 @@ var AdvancedEscrowClient = class {
|
|
|
3720
3728
|
async release(paymentInfo, amount) {
|
|
3721
3729
|
if (!this.payerAddress) await this.init();
|
|
3722
3730
|
try {
|
|
3723
|
-
const { ethers } = await import('ethers');
|
|
3731
|
+
const { ethers: ethers2 } = await import('ethers');
|
|
3724
3732
|
const isCreate3 = CREATE3_CHAIN_IDS.has(this.chainId);
|
|
3725
3733
|
const abi = isCreate3 ? OPERATOR_ABI_CREATE3 : OPERATOR_ABI;
|
|
3726
3734
|
const amt = amount || paymentInfo.maxAmount;
|
|
3727
3735
|
const tuple = this.buildTuple(paymentInfo);
|
|
3728
3736
|
if (this.walletAdapter) {
|
|
3729
|
-
return this.sendViaAdapter(
|
|
3737
|
+
return this.sendViaAdapter(ethers2, abi, (iface) => {
|
|
3730
3738
|
return isCreate3 ? iface.encodeFunctionData("release", [tuple, amt, "0x"]) : iface.encodeFunctionData("release", [tuple, amt]);
|
|
3731
3739
|
});
|
|
3732
3740
|
}
|
|
3733
|
-
const contract = new
|
|
3741
|
+
const contract = new ethers2.Contract(this.contracts.operator, abi, this.signer);
|
|
3734
3742
|
const tx = isCreate3 ? await contract.release(tuple, amt, "0x", { gasLimit: this.gasLimit }) : await contract.release(tuple, amt, { gasLimit: this.gasLimit });
|
|
3735
3743
|
const receipt = await tx.wait();
|
|
3736
3744
|
return {
|
|
@@ -3754,17 +3762,17 @@ var AdvancedEscrowClient = class {
|
|
|
3754
3762
|
async refundInEscrow(paymentInfo, amount) {
|
|
3755
3763
|
if (!this.payerAddress) await this.init();
|
|
3756
3764
|
try {
|
|
3757
|
-
const { ethers } = await import('ethers');
|
|
3765
|
+
const { ethers: ethers2 } = await import('ethers');
|
|
3758
3766
|
const isCreate3 = CREATE3_CHAIN_IDS.has(this.chainId);
|
|
3759
3767
|
const abi = isCreate3 ? OPERATOR_ABI_CREATE3 : OPERATOR_ABI;
|
|
3760
3768
|
const amt = amount || paymentInfo.maxAmount;
|
|
3761
3769
|
const tuple = this.buildTuple(paymentInfo);
|
|
3762
3770
|
if (this.walletAdapter) {
|
|
3763
|
-
return this.sendViaAdapter(
|
|
3771
|
+
return this.sendViaAdapter(ethers2, abi, (iface) => {
|
|
3764
3772
|
return isCreate3 ? iface.encodeFunctionData("refundInEscrow", [tuple, amt, "0x"]) : iface.encodeFunctionData("refundInEscrow", [tuple, amt]);
|
|
3765
3773
|
});
|
|
3766
3774
|
}
|
|
3767
|
-
const contract = new
|
|
3775
|
+
const contract = new ethers2.Contract(this.contracts.operator, abi, this.signer);
|
|
3768
3776
|
const tx = isCreate3 ? await contract.refundInEscrow(tuple, amt, "0x", { gasLimit: this.gasLimit }) : await contract.refundInEscrow(tuple, amt, { gasLimit: this.gasLimit });
|
|
3769
3777
|
const receipt = await tx.wait();
|
|
3770
3778
|
return {
|
|
@@ -4027,7 +4035,7 @@ var AdvancedEscrowClient = class {
|
|
|
4027
4035
|
async charge(paymentInfo, amount) {
|
|
4028
4036
|
if (!this.payerAddress) await this.init();
|
|
4029
4037
|
try {
|
|
4030
|
-
const { ethers } = await import('ethers');
|
|
4038
|
+
const { ethers: ethers2 } = await import('ethers');
|
|
4031
4039
|
const nonce = await this.computeNonce(paymentInfo);
|
|
4032
4040
|
const amt = amount || paymentInfo.maxAmount;
|
|
4033
4041
|
const auth = {
|
|
@@ -4039,10 +4047,10 @@ var AdvancedEscrowClient = class {
|
|
|
4039
4047
|
nonce
|
|
4040
4048
|
};
|
|
4041
4049
|
const signature = await this.signErc3009(auth);
|
|
4042
|
-
const collectorData =
|
|
4050
|
+
const collectorData = ethers2.getBytes(signature);
|
|
4043
4051
|
const tuple = this.buildTuple(paymentInfo);
|
|
4044
4052
|
if (this.walletAdapter) {
|
|
4045
|
-
return this.sendViaAdapter(
|
|
4053
|
+
return this.sendViaAdapter(ethers2, OPERATOR_ABI, (iface) => {
|
|
4046
4054
|
return iface.encodeFunctionData("charge", [
|
|
4047
4055
|
tuple,
|
|
4048
4056
|
amt,
|
|
@@ -4051,7 +4059,7 @@ var AdvancedEscrowClient = class {
|
|
|
4051
4059
|
]);
|
|
4052
4060
|
});
|
|
4053
4061
|
}
|
|
4054
|
-
const contract = new
|
|
4062
|
+
const contract = new ethers2.Contract(this.contracts.operator, OPERATOR_ABI, this.signer);
|
|
4055
4063
|
const tx = await contract.charge(
|
|
4056
4064
|
tuple,
|
|
4057
4065
|
amt,
|
|
@@ -4093,11 +4101,11 @@ var AdvancedEscrowClient = class {
|
|
|
4093
4101
|
async refundPostEscrow(paymentInfo, amount, tokenCollector, collectorData) {
|
|
4094
4102
|
if (!this.payerAddress) await this.init();
|
|
4095
4103
|
try {
|
|
4096
|
-
const { ethers } = await import('ethers');
|
|
4104
|
+
const { ethers: ethers2 } = await import('ethers');
|
|
4097
4105
|
const amt = amount || paymentInfo.maxAmount;
|
|
4098
4106
|
const tuple = this.buildTuple(paymentInfo);
|
|
4099
4107
|
if (this.walletAdapter) {
|
|
4100
|
-
return this.sendViaAdapter(
|
|
4108
|
+
return this.sendViaAdapter(ethers2, OPERATOR_ABI, (iface) => {
|
|
4101
4109
|
return iface.encodeFunctionData("refundPostEscrow", [
|
|
4102
4110
|
tuple,
|
|
4103
4111
|
amt,
|
|
@@ -4106,7 +4114,7 @@ var AdvancedEscrowClient = class {
|
|
|
4106
4114
|
]);
|
|
4107
4115
|
});
|
|
4108
4116
|
}
|
|
4109
|
-
const contract = new
|
|
4117
|
+
const contract = new ethers2.Contract(this.contracts.operator, OPERATOR_ABI, this.signer);
|
|
4110
4118
|
const tx = await contract.refundPostEscrow(
|
|
4111
4119
|
tuple,
|
|
4112
4120
|
amt,
|