uvd-x402-sdk 2.86.0 → 2.87.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 +1 -1
- package/dist/backend/index.d.ts +1 -1
- package/dist/backend/index.js +44 -17
- package/dist/backend/index.js.map +1 -1
- package/dist/backend/index.mjs +44 -17
- package/dist/backend/index.mjs.map +1 -1
- package/dist/{index-De03nksW.d.mts → index-BHfYxpzI.d.mts} +136 -27
- package/dist/{index-4_LWWlyF.d.ts → index-D67eNxY8.d.ts} +136 -27
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +62 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/backend/index.ts +87 -27
- package/src/index.ts +2 -0
- package/src/lifecycle-auth.ts +209 -32
package/dist/backend/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import '../wallet-w7BnImDG.mjs';
|
|
2
2
|
import '../index-DOBhTF-j.mjs';
|
|
3
|
-
export { A as AMBIGUOUS_LEASE_REASONS,
|
|
3
|
+
export { A as AMBIGUOUS_LEASE_REASONS, ab as AdvancedAuthorizationResult, ac as AdvancedEscrowClient, ad as AdvancedEscrowClientOptions, ae as AdvancedEscrowContracts, af as AdvancedEscrowTaskTier, ag as AdvancedPaymentInfo, ah as AdvancedTransactionResult, ai as AgentId, aj as AgentIdentity, ak as AgentRegistration, al as AgentRegistrationFile, am as AgentService, an as AtomStats, ao as BASE_MAINNET_CONTRACTS, ap as BazaarClient, aq as BazaarClientOptions, ar as BazaarDiscoverOptions, as as BazaarDiscoverResponse, at as BazaarRegisterOptions, au as BazaarResource, av as CreateEscrowOptions, D as DEFAULT_FACILITATOR_RETRIES, a as DEFAULT_RETRY_AFTER_SECONDS, aw as DEPOSIT_LIMIT_USDC, ax as DiscoveryAccepts, ay as DiscoveryCuration, az as DiscoveryHealth, aA as DiscoveryHealthStatus, aB as DiscoveryListOptions, aC as DiscoveryPagination, aD as DiscoveryRegisterOptions, aE as DiscoveryResource, aF as DiscoveryResponse, aG as DiscoverySource, aH as DiscoveryStats, aI as DiscoveryTier, aJ as Dispute, aK as DisputeOutcome, aL as ERC8004_CONTRACTS, aM as ERC8004_EXTENSION_ID, aN as ESCROW_CONTRACTS, aO as ESCROW_TIMEOUT_MS, aP as Erc8004Client, aQ as Erc8004ClientOptions, aR as Erc8004LookupError, aS as Erc8004Network, aT as EscrowClient, aU as EscrowClientOptions, aV as EscrowPayment, aW as EscrowStateResponse, aX as EscrowStatus, F as FacilitatorClient, b as FacilitatorClientOptions, c as FacilitatorErrorInfo, d as FacilitatorFailureFields, e as FacilitatorFetchOptions, aY as FeedbackEntry, aZ as FeedbackParams, a_ as FeedbackRequest, a$ as FeedbackResponse, b0 as HEALTH_FILTERS, H as HonoMiddlewareOptions, b1 as IdentityByOwnerResponse, b2 as IdentityMetadataResponse, b3 as IdentityTotalSupplyResponse, b4 as LifecycleAuthOptions, M as MAX_RETRY_AFTER_SECONDS, b5 as MAX_SEARCH_LEN, b6 as MetadataEntryParam, b7 as OPERATOR_ABI, b8 as OPERATOR_ABI_CREATE3, b9 as PAYMENT_INFO_TYPEHASH, P as ParsedFacilitatorErrorBody, q as PaymentAcceptance, r as PaymentMiddlewareOptions, s as PaymentPayloadV2, ba as PaymentRequirementResolver, bb as PaymentRequirements, bc as PaymentRequirementsOptions, t as PaymentRequirementsV2, bd as PrepareRelayFeedbackRequest, be as PrepareRelayFeedbackResponse, bf as PrepareRelayResponseRequest, bg as ProofOfPayment, bh as RELAYED_FEEDBACK_NETWORKS, R as REPLAYABLE_LEASE_REASONS, bi as RefundRequest, bj as RefundStatus, bk as RegisterAgentRequest, bl as RegisterAgentResponse, bm as RegisterJobResponse, bn as RegisterJobStatus, bo as RegistrationPendingError, bp as RelayAuthorizationParams, bq as ReputationResponse, br as ReputationSummary, bs as RequestRefundOptions, u as ResourceInfoV2, S as SETTLEMENT_UNCONFIRMED, bt as SettleRequest, v as SettleRequestV2, bu as SettleResponse, bv as SettleResponseWithProof, bw as SubmitRelayFeedbackRequest, bx as SubmitRelayResponseRequest, by as TIER_FILTERS, bz as TIER_TIMINGS, bA as USDC_DOMAIN_NAME, bB as UnavailableBody, bC as UnavailableResponse, V as VerifiedPaymentState, bD as VerifyRequest, w as VerifyRequestV2, bE as VerifyResponse, W as WRITER_LEASE_REASONS, y as WriterLeaseReason, X as X402_CORS_HEADERS, z as X402_HEADER_NAMES, bF as ZERO_ADDRESS, bG as buildErc8004PaymentRequirements, G as buildPaymentRequirements, I as buildSettleRequest, J as buildSettleRequestForVersion, K as buildSettleRequestV2, bH as buildUnavailableResponse, N as buildVerifyRequest, O as buildVerifyRequestForVersion, Q as buildVerifyRequestV2, bI as canRefundEscrow, bJ as canReleaseEscrow, bK as carryFailureFields, T as create402Response, U as createHonoMiddleware, Y as createPaymentMiddleware, bL as epochToDate, bM as escrowTimeRemaining, Z as extractPaymentFromHeaders, _ as facilitatorFetch, $ as getCorsHeaders, bN as getEscrowContractsByChainId, bO as getEscrowSupportedChainIds, bP as isAlive, a0 as isAmbiguousLeaseReason, bQ as isEscrowExpired, bR as isEscrowSupportedOnChain, bS as isRegisterJobTerminal, a1 as isReplayableLeaseReason, a2 as isSettlementUnconfirmed, a4 as parseFacilitatorErrorBody, bT as parsePaymentHeader, a5 as parseRetryAfterSeconds, a6 as readFacilitatorError, a7 as resolveEnvelopeVersion, bU as supportsRelayedFeedback, a8 as toPaymentRequirementsV2, a9 as toResourceInfoV2, bV as wireNetwork } from '../index-BHfYxpzI.mjs';
|
package/dist/backend/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import '../wallet-w7BnImDG.js';
|
|
2
2
|
import '../index-DOBhTF-j.js';
|
|
3
|
-
export { A as AMBIGUOUS_LEASE_REASONS,
|
|
3
|
+
export { A as AMBIGUOUS_LEASE_REASONS, ab as AdvancedAuthorizationResult, ac as AdvancedEscrowClient, ad as AdvancedEscrowClientOptions, ae as AdvancedEscrowContracts, af as AdvancedEscrowTaskTier, ag as AdvancedPaymentInfo, ah as AdvancedTransactionResult, ai as AgentId, aj as AgentIdentity, ak as AgentRegistration, al as AgentRegistrationFile, am as AgentService, an as AtomStats, ao as BASE_MAINNET_CONTRACTS, ap as BazaarClient, aq as BazaarClientOptions, ar as BazaarDiscoverOptions, as as BazaarDiscoverResponse, at as BazaarRegisterOptions, au as BazaarResource, av as CreateEscrowOptions, D as DEFAULT_FACILITATOR_RETRIES, a as DEFAULT_RETRY_AFTER_SECONDS, aw as DEPOSIT_LIMIT_USDC, ax as DiscoveryAccepts, ay as DiscoveryCuration, az as DiscoveryHealth, aA as DiscoveryHealthStatus, aB as DiscoveryListOptions, aC as DiscoveryPagination, aD as DiscoveryRegisterOptions, aE as DiscoveryResource, aF as DiscoveryResponse, aG as DiscoverySource, aH as DiscoveryStats, aI as DiscoveryTier, aJ as Dispute, aK as DisputeOutcome, aL as ERC8004_CONTRACTS, aM as ERC8004_EXTENSION_ID, aN as ESCROW_CONTRACTS, aO as ESCROW_TIMEOUT_MS, aP as Erc8004Client, aQ as Erc8004ClientOptions, aR as Erc8004LookupError, aS as Erc8004Network, aT as EscrowClient, aU as EscrowClientOptions, aV as EscrowPayment, aW as EscrowStateResponse, aX as EscrowStatus, F as FacilitatorClient, b as FacilitatorClientOptions, c as FacilitatorErrorInfo, d as FacilitatorFailureFields, e as FacilitatorFetchOptions, aY as FeedbackEntry, aZ as FeedbackParams, a_ as FeedbackRequest, a$ as FeedbackResponse, b0 as HEALTH_FILTERS, H as HonoMiddlewareOptions, b1 as IdentityByOwnerResponse, b2 as IdentityMetadataResponse, b3 as IdentityTotalSupplyResponse, b4 as LifecycleAuthOptions, M as MAX_RETRY_AFTER_SECONDS, b5 as MAX_SEARCH_LEN, b6 as MetadataEntryParam, b7 as OPERATOR_ABI, b8 as OPERATOR_ABI_CREATE3, b9 as PAYMENT_INFO_TYPEHASH, P as ParsedFacilitatorErrorBody, q as PaymentAcceptance, r as PaymentMiddlewareOptions, s as PaymentPayloadV2, ba as PaymentRequirementResolver, bb as PaymentRequirements, bc as PaymentRequirementsOptions, t as PaymentRequirementsV2, bd as PrepareRelayFeedbackRequest, be as PrepareRelayFeedbackResponse, bf as PrepareRelayResponseRequest, bg as ProofOfPayment, bh as RELAYED_FEEDBACK_NETWORKS, R as REPLAYABLE_LEASE_REASONS, bi as RefundRequest, bj as RefundStatus, bk as RegisterAgentRequest, bl as RegisterAgentResponse, bm as RegisterJobResponse, bn as RegisterJobStatus, bo as RegistrationPendingError, bp as RelayAuthorizationParams, bq as ReputationResponse, br as ReputationSummary, bs as RequestRefundOptions, u as ResourceInfoV2, S as SETTLEMENT_UNCONFIRMED, bt as SettleRequest, v as SettleRequestV2, bu as SettleResponse, bv as SettleResponseWithProof, bw as SubmitRelayFeedbackRequest, bx as SubmitRelayResponseRequest, by as TIER_FILTERS, bz as TIER_TIMINGS, bA as USDC_DOMAIN_NAME, bB as UnavailableBody, bC as UnavailableResponse, V as VerifiedPaymentState, bD as VerifyRequest, w as VerifyRequestV2, bE as VerifyResponse, W as WRITER_LEASE_REASONS, y as WriterLeaseReason, X as X402_CORS_HEADERS, z as X402_HEADER_NAMES, bF as ZERO_ADDRESS, bG as buildErc8004PaymentRequirements, G as buildPaymentRequirements, I as buildSettleRequest, J as buildSettleRequestForVersion, K as buildSettleRequestV2, bH as buildUnavailableResponse, N as buildVerifyRequest, O as buildVerifyRequestForVersion, Q as buildVerifyRequestV2, bI as canRefundEscrow, bJ as canReleaseEscrow, bK as carryFailureFields, T as create402Response, U as createHonoMiddleware, Y as createPaymentMiddleware, bL as epochToDate, bM as escrowTimeRemaining, Z as extractPaymentFromHeaders, _ as facilitatorFetch, $ as getCorsHeaders, bN as getEscrowContractsByChainId, bO as getEscrowSupportedChainIds, bP as isAlive, a0 as isAmbiguousLeaseReason, bQ as isEscrowExpired, bR as isEscrowSupportedOnChain, bS as isRegisterJobTerminal, a1 as isReplayableLeaseReason, a2 as isSettlementUnconfirmed, a4 as parseFacilitatorErrorBody, bT as parsePaymentHeader, a5 as parseRetryAfterSeconds, a6 as readFacilitatorError, a7 as resolveEnvelopeVersion, bU as supportsRelayedFeedback, a8 as toPaymentRequirementsV2, a9 as toResourceInfoV2, bV as wireNetwork } from '../index-D67eNxY8.js';
|
package/dist/backend/index.js
CHANGED
|
@@ -1213,6 +1213,14 @@ function randomNonce() {
|
|
|
1213
1213
|
}
|
|
1214
1214
|
return ethers.ethers.hexlify(ethers.ethers.randomBytes(32));
|
|
1215
1215
|
}
|
|
1216
|
+
function resolveOrderTiming(params) {
|
|
1217
|
+
const nowSec = params.now === void 0 ? Math.floor(Date.now() / 1e3) : Math.floor(params.now);
|
|
1218
|
+
return {
|
|
1219
|
+
nowSec,
|
|
1220
|
+
deadline: params.deadline === void 0 ? nowSec + LIFECYCLE_DEFAULT_DEADLINE_SECS : Math.floor(params.deadline),
|
|
1221
|
+
nonce: params.nonce === void 0 ? randomNonce() : params.nonce
|
|
1222
|
+
};
|
|
1223
|
+
}
|
|
1216
1224
|
function toUintString(value, field) {
|
|
1217
1225
|
let n;
|
|
1218
1226
|
try {
|
|
@@ -1226,7 +1234,8 @@ function toUintString(value, field) {
|
|
|
1226
1234
|
return n.toString();
|
|
1227
1235
|
}
|
|
1228
1236
|
function buildLifecycleTypedData(params) {
|
|
1229
|
-
const { action, paymentInfo, payer, amount, chainId
|
|
1237
|
+
const { action, paymentInfo, payer, amount, chainId } = params;
|
|
1238
|
+
const { deadline, nonce } = resolveOrderTiming(params);
|
|
1230
1239
|
if (!LIFECYCLE_ACTIONS.includes(action)) {
|
|
1231
1240
|
throw new X402Error(
|
|
1232
1241
|
`unknown lifecycle action ${String(action)}; the facilitator only signs ${LIFECYCLE_ACTIONS.join(", ")}`,
|
|
@@ -1285,10 +1294,8 @@ function buildLifecycleTypedData(params) {
|
|
|
1285
1294
|
};
|
|
1286
1295
|
}
|
|
1287
1296
|
async function buildLifecycleAuth(params) {
|
|
1288
|
-
const { wallet,
|
|
1289
|
-
const nowSec
|
|
1290
|
-
const dl = deadline === void 0 ? nowSec + LIFECYCLE_DEFAULT_DEADLINE_SECS : Math.floor(deadline);
|
|
1291
|
-
const nonceHex = nonce === void 0 ? randomNonce() : nonce;
|
|
1297
|
+
const { wallet, ...rest } = params;
|
|
1298
|
+
const { nowSec, deadline: dl, nonce: nonceHex } = resolveOrderTiming(params);
|
|
1292
1299
|
if (dl < nowSec) {
|
|
1293
1300
|
throw new X402Error(
|
|
1294
1301
|
`deadline ${dl} is in the past (now ${nowSec}): the facilitator discards it as \`expired\``,
|
|
@@ -4259,6 +4266,25 @@ var TIER_TIMINGS = {
|
|
|
4259
4266
|
premium: { pre: 14400, auth: 172800, refund: 1209600 },
|
|
4260
4267
|
enterprise: { pre: 86400, auth: 604800, refund: 2592e3 }
|
|
4261
4268
|
};
|
|
4269
|
+
async function resolveLifecycleAuth(action, options, order) {
|
|
4270
|
+
if (options?.lifecycleSigner && options?.lifecycleAuth) {
|
|
4271
|
+
throw new X402Error(
|
|
4272
|
+
"lifecycleSigner and lifecycleAuth are mutually exclusive: the first signs an order here, the second was already signed elsewhere. Passing both means two different orders exist and only one can travel.",
|
|
4273
|
+
"INVALID_CONFIG"
|
|
4274
|
+
);
|
|
4275
|
+
}
|
|
4276
|
+
if (options?.lifecycleAuth) return options.lifecycleAuth;
|
|
4277
|
+
if (!options?.lifecycleSigner) return void 0;
|
|
4278
|
+
return buildLifecycleAuth({
|
|
4279
|
+
action,
|
|
4280
|
+
paymentInfo: order.paymentInfo,
|
|
4281
|
+
payer: order.payer,
|
|
4282
|
+
amount: order.amount,
|
|
4283
|
+
chainId: order.chainId,
|
|
4284
|
+
wallet: options.lifecycleSigner,
|
|
4285
|
+
deadline: options.lifecycleDeadline
|
|
4286
|
+
});
|
|
4287
|
+
}
|
|
4262
4288
|
var OPERATOR_ABI = [
|
|
4263
4289
|
"function release(tuple(address operator, address payer, address receiver, address token, uint120 maxAmount, uint48 preApprovalExpiry, uint48 authorizationExpiry, uint48 refundExpiry, uint16 minFeeBps, uint16 maxFeeBps, address feeReceiver, uint256 salt) paymentInfo, uint256 amount)",
|
|
4264
4290
|
"function refundInEscrow(tuple(address operator, address payer, address receiver, address token, uint120 maxAmount, uint48 preApprovalExpiry, uint48 authorizationExpiry, uint48 refundExpiry, uint16 minFeeBps, uint16 maxFeeBps, address feeReceiver, uint256 salt) paymentInfo, uint120 amount)",
|
|
@@ -4669,6 +4695,13 @@ var AdvancedEscrowClient = class {
|
|
|
4669
4695
|
* lifecycleSigner: payerWallet, // EnvKeyAdapter, OWS, wagmiLifecycleSigner(...)
|
|
4670
4696
|
* });
|
|
4671
4697
|
* ```
|
|
4698
|
+
*
|
|
4699
|
+
* @example Transporting an order the publisher signed in their browser
|
|
4700
|
+
* ```typescript
|
|
4701
|
+
* // The browser sent back a signature over a document THIS backend built.
|
|
4702
|
+
* const lifecycleAuth = lifecycleAuthFromSignature(typedData, signature, payer);
|
|
4703
|
+
* await client.releaseViaFacilitator(pi, amount, { lifecycleAuth });
|
|
4704
|
+
* ```
|
|
4672
4705
|
*/
|
|
4673
4706
|
async releaseViaFacilitator(paymentInfo, amount, options) {
|
|
4674
4707
|
if (!this.payerAddress) await this.init();
|
|
@@ -4687,15 +4720,12 @@ var AdvancedEscrowClient = class {
|
|
|
4687
4720
|
salt: paymentInfo.salt
|
|
4688
4721
|
};
|
|
4689
4722
|
const releaseAmount = amount || paymentInfo.maxAmount;
|
|
4690
|
-
const lifecycleAuth =
|
|
4691
|
-
action: "release",
|
|
4723
|
+
const lifecycleAuth = await resolveLifecycleAuth("release", options, {
|
|
4692
4724
|
paymentInfo: wirePaymentInfo,
|
|
4693
4725
|
payer: this.payerAddress,
|
|
4694
4726
|
amount: releaseAmount,
|
|
4695
|
-
chainId: this.chainId
|
|
4696
|
-
|
|
4697
|
-
deadline: options.lifecycleDeadline
|
|
4698
|
-
}) : void 0;
|
|
4727
|
+
chainId: this.chainId
|
|
4728
|
+
});
|
|
4699
4729
|
const payload = {
|
|
4700
4730
|
x402Version: 2,
|
|
4701
4731
|
scheme: "escrow",
|
|
@@ -4824,15 +4854,12 @@ var AdvancedEscrowClient = class {
|
|
|
4824
4854
|
salt: paymentInfo.salt
|
|
4825
4855
|
};
|
|
4826
4856
|
const refundAmount = amount || paymentInfo.maxAmount;
|
|
4827
|
-
const lifecycleAuth =
|
|
4828
|
-
action: "refundInEscrow",
|
|
4857
|
+
const lifecycleAuth = await resolveLifecycleAuth("refundInEscrow", options, {
|
|
4829
4858
|
paymentInfo: wirePaymentInfo,
|
|
4830
4859
|
payer: this.payerAddress,
|
|
4831
4860
|
amount: refundAmount,
|
|
4832
|
-
chainId: this.chainId
|
|
4833
|
-
|
|
4834
|
-
deadline: options.lifecycleDeadline
|
|
4835
|
-
}) : void 0;
|
|
4861
|
+
chainId: this.chainId
|
|
4862
|
+
});
|
|
4836
4863
|
const payload = {
|
|
4837
4864
|
x402Version: 2,
|
|
4838
4865
|
scheme: "escrow",
|