uvd-x402-sdk 2.22.0 → 2.24.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 +83 -4
- package/dist/backend/index.d.ts +83 -4
- package/dist/backend/index.js +220 -2
- package/dist/backend/index.js.map +1 -1
- package/dist/backend/index.mjs +220 -2
- package/dist/backend/index.mjs.map +1 -1
- package/package.json +201 -200
- package/src/backend/index.ts +261 -6
package/dist/backend/index.d.mts
CHANGED
|
@@ -1037,7 +1037,7 @@ declare function escrowTimeRemaining(escrow: EscrowPayment): number;
|
|
|
1037
1037
|
*/
|
|
1038
1038
|
declare const ERC8004_EXTENSION_ID = "8004-reputation";
|
|
1039
1039
|
/**
|
|
1040
|
-
* ERC-8004 contract addresses per network (
|
|
1040
|
+
* ERC-8004 contract addresses per network (16 networks)
|
|
1041
1041
|
*/
|
|
1042
1042
|
declare const ERC8004_CONTRACTS: Record<string, {
|
|
1043
1043
|
identityRegistry?: string;
|
|
@@ -1048,9 +1048,9 @@ declare const ERC8004_CONTRACTS: Record<string, {
|
|
|
1048
1048
|
* Network type for ERC-8004 operations
|
|
1049
1049
|
*/
|
|
1050
1050
|
/**
|
|
1051
|
-
* Network type for ERC-8004 operations (
|
|
1051
|
+
* Network type for ERC-8004 operations (16 networks)
|
|
1052
1052
|
*/
|
|
1053
|
-
type Erc8004Network = 'ethereum' | 'base-mainnet' | 'polygon' | 'arbitrum' | 'celo' | 'bsc' | 'monad' | 'ethereum-sepolia' | 'base-sepolia' | 'polygon-amoy' | 'arbitrum-sepolia' | 'celo-sepolia';
|
|
1053
|
+
type Erc8004Network = 'ethereum' | 'base-mainnet' | 'polygon' | 'arbitrum' | 'optimism' | 'celo' | 'bsc' | 'monad' | 'avalanche' | 'ethereum-sepolia' | 'base-sepolia' | 'polygon-amoy' | 'arbitrum-sepolia' | 'optimism-sepolia' | 'celo-sepolia' | 'avalanche-fuji';
|
|
1054
1054
|
/**
|
|
1055
1055
|
* Proof of payment returned when settling with ERC-8004 extension
|
|
1056
1056
|
*/
|
|
@@ -1643,6 +1643,22 @@ interface AdvancedTransactionResult {
|
|
|
1643
1643
|
gasUsed?: number;
|
|
1644
1644
|
error?: string;
|
|
1645
1645
|
}
|
|
1646
|
+
/**
|
|
1647
|
+
* Response from the facilitator's /escrow/state endpoint.
|
|
1648
|
+
* Represents the on-chain state of an escrow for a given paymentInfo + payer.
|
|
1649
|
+
*/
|
|
1650
|
+
interface EscrowStateResponse {
|
|
1651
|
+
/** Whether the payment has already been collected (released) */
|
|
1652
|
+
hasCollectedPayment: boolean;
|
|
1653
|
+
/** Amount that can still be captured/released (in atomic units) */
|
|
1654
|
+
capturableAmount: string;
|
|
1655
|
+
/** Amount that can still be refunded to the payer (in atomic units) */
|
|
1656
|
+
refundableAmount: string;
|
|
1657
|
+
/** Keccak256 hash of the paymentInfo struct */
|
|
1658
|
+
paymentInfoHash: string;
|
|
1659
|
+
/** Network in CAIP-2 format (e.g., "eip155:8453") */
|
|
1660
|
+
network: string;
|
|
1661
|
+
}
|
|
1646
1662
|
/**
|
|
1647
1663
|
* Contract addresses configuration for AdvancedEscrowClient.
|
|
1648
1664
|
*
|
|
@@ -1792,6 +1808,69 @@ declare class AdvancedEscrowClient {
|
|
|
1792
1808
|
* @param amount - Amount to refund (defaults to maxAmount)
|
|
1793
1809
|
*/
|
|
1794
1810
|
refundInEscrow(paymentInfo: AdvancedPaymentInfo, amount?: string): Promise<AdvancedTransactionResult>;
|
|
1811
|
+
/**
|
|
1812
|
+
* GASLESS RELEASE: Release escrowed funds via the facilitator.
|
|
1813
|
+
*
|
|
1814
|
+
* Instead of calling the PaymentOperator contract directly (which requires
|
|
1815
|
+
* gas), this sends a release request to the facilitator, which submits
|
|
1816
|
+
* the transaction on your behalf.
|
|
1817
|
+
*
|
|
1818
|
+
* @param paymentInfo - PaymentInfo from the authorize step
|
|
1819
|
+
* @param amount - Amount to release in atomic units (defaults to maxAmount)
|
|
1820
|
+
* @returns Transaction result from the facilitator
|
|
1821
|
+
*
|
|
1822
|
+
* @example
|
|
1823
|
+
* ```typescript
|
|
1824
|
+
* const pi = client.buildPaymentInfo('0xWorker...', '5000000', 'standard');
|
|
1825
|
+
* await client.authorize(pi);
|
|
1826
|
+
* // Worker completes task...
|
|
1827
|
+
* const result = await client.releaseViaFacilitator(pi);
|
|
1828
|
+
* console.log(result.transactionHash);
|
|
1829
|
+
* ```
|
|
1830
|
+
*/
|
|
1831
|
+
releaseViaFacilitator(paymentInfo: AdvancedPaymentInfo, amount?: string): Promise<AdvancedTransactionResult>;
|
|
1832
|
+
/**
|
|
1833
|
+
* GASLESS REFUND: Refund escrowed funds via the facilitator.
|
|
1834
|
+
*
|
|
1835
|
+
* Instead of calling the PaymentOperator contract directly (which requires
|
|
1836
|
+
* gas), this sends a refundInEscrow request to the facilitator, which
|
|
1837
|
+
* submits the transaction on your behalf.
|
|
1838
|
+
*
|
|
1839
|
+
* @param paymentInfo - PaymentInfo from the authorize step
|
|
1840
|
+
* @param amount - Amount to refund in atomic units (defaults to maxAmount)
|
|
1841
|
+
* @returns Transaction result from the facilitator
|
|
1842
|
+
*
|
|
1843
|
+
* @example
|
|
1844
|
+
* ```typescript
|
|
1845
|
+
* const pi = client.buildPaymentInfo('0xWorker...', '5000000', 'standard');
|
|
1846
|
+
* await client.authorize(pi);
|
|
1847
|
+
* // Task cancelled...
|
|
1848
|
+
* const result = await client.refundViaFacilitator(pi);
|
|
1849
|
+
* console.log(result.transactionHash);
|
|
1850
|
+
* ```
|
|
1851
|
+
*/
|
|
1852
|
+
refundViaFacilitator(paymentInfo: AdvancedPaymentInfo, amount?: string): Promise<AdvancedTransactionResult>;
|
|
1853
|
+
/**
|
|
1854
|
+
* QUERY ESCROW STATE: Read on-chain escrow state via the facilitator.
|
|
1855
|
+
*
|
|
1856
|
+
* This is a read-only operation that queries the facilitator for the
|
|
1857
|
+
* current escrow state without requiring gas or a signer.
|
|
1858
|
+
*
|
|
1859
|
+
* @param paymentInfo - PaymentInfo to query state for
|
|
1860
|
+
* @returns Escrow state including capturable/refundable amounts
|
|
1861
|
+
*
|
|
1862
|
+
* @example
|
|
1863
|
+
* ```typescript
|
|
1864
|
+
* const pi = client.buildPaymentInfo('0xWorker...', '5000000', 'standard');
|
|
1865
|
+
* await client.authorize(pi);
|
|
1866
|
+
*
|
|
1867
|
+
* const state = await client.queryEscrowState(pi);
|
|
1868
|
+
* console.log(`Capturable: ${state.capturableAmount}`);
|
|
1869
|
+
* console.log(`Refundable: ${state.refundableAmount}`);
|
|
1870
|
+
* console.log(`Already collected: ${state.hasCollectedPayment}`);
|
|
1871
|
+
* ```
|
|
1872
|
+
*/
|
|
1873
|
+
queryEscrowState(paymentInfo: AdvancedPaymentInfo): Promise<EscrowStateResponse>;
|
|
1795
1874
|
/**
|
|
1796
1875
|
* CHARGE: Direct instant payment (no escrow hold).
|
|
1797
1876
|
*
|
|
@@ -1825,4 +1904,4 @@ declare class AdvancedEscrowClient {
|
|
|
1825
1904
|
refundPostEscrow(paymentInfo: AdvancedPaymentInfo, amount?: string, tokenCollector?: string, collectorData?: string): Promise<AdvancedTransactionResult>;
|
|
1826
1905
|
}
|
|
1827
1906
|
|
|
1828
|
-
export { type AdvancedAuthorizationResult, AdvancedEscrowClient, type AdvancedEscrowClientOptions, type AdvancedEscrowContracts, type AdvancedEscrowTaskTier, type AdvancedPaymentInfo, type AdvancedTransactionResult, type AgentIdentity, type AgentRegistration, type AgentRegistrationFile, type AgentService, BASE_MAINNET_CONTRACTS, type BazaarCategory, BazaarClient, type BazaarClientOptions, type BazaarDiscoverOptions, type BazaarDiscoverResponse, type BazaarNetwork, type BazaarRegisterOptions, type BazaarResource, type BazaarToken, type CreateEscrowOptions, DEPOSIT_LIMIT_USDC, type Dispute, type DisputeOutcome, ERC8004_CONTRACTS, ERC8004_EXTENSION_ID, ESCROW_CONTRACTS, Erc8004Client, type Erc8004ClientOptions, type Erc8004Network, EscrowClient, type EscrowClientOptions, type EscrowPayment, type EscrowStatus, FacilitatorClient, type FacilitatorClientOptions, type FeedbackEntry, type FeedbackParams, type FeedbackRequest, type FeedbackResponse, type IdentityMetadataResponse, type IdentityTotalSupplyResponse, type MetadataEntryParam, OPERATOR_ABI, PAYMENT_INFO_TYPEHASH, type PaymentRequirements, type PaymentRequirementsOptions, type ProofOfPayment, type RefundRequest, type RefundStatus, type RegisterAgentRequest, type RegisterAgentResponse, type ReputationResponse, type ReputationSummary, type RequestRefundOptions, type SettleRequest, type SettleResponse, type SettleResponseWithProof, TIER_TIMINGS, USDC_DOMAIN_NAME, type VerifyRequest, type VerifyResponse, X402_CORS_HEADERS, X402_HEADER_NAMES, ZERO_ADDRESS, buildErc8004PaymentRequirements, buildPaymentRequirements, buildSettleRequest, buildVerifyRequest, canRefundEscrow, canReleaseEscrow, create402Response, createPaymentMiddleware, escrowTimeRemaining, extractPaymentFromHeaders, getCorsHeaders, getEscrowContractsByChainId, getEscrowSupportedChainIds, isEscrowExpired, isEscrowSupportedOnChain, parsePaymentHeader };
|
|
1907
|
+
export { type AdvancedAuthorizationResult, AdvancedEscrowClient, type AdvancedEscrowClientOptions, type AdvancedEscrowContracts, type AdvancedEscrowTaskTier, type AdvancedPaymentInfo, type AdvancedTransactionResult, type AgentIdentity, type AgentRegistration, type AgentRegistrationFile, type AgentService, BASE_MAINNET_CONTRACTS, type BazaarCategory, BazaarClient, type BazaarClientOptions, type BazaarDiscoverOptions, type BazaarDiscoverResponse, type BazaarNetwork, type BazaarRegisterOptions, type BazaarResource, type BazaarToken, type CreateEscrowOptions, DEPOSIT_LIMIT_USDC, type Dispute, type DisputeOutcome, ERC8004_CONTRACTS, ERC8004_EXTENSION_ID, ESCROW_CONTRACTS, Erc8004Client, type Erc8004ClientOptions, type Erc8004Network, EscrowClient, type EscrowClientOptions, type EscrowPayment, type EscrowStateResponse, type EscrowStatus, FacilitatorClient, type FacilitatorClientOptions, type FeedbackEntry, type FeedbackParams, type FeedbackRequest, type FeedbackResponse, type IdentityMetadataResponse, type IdentityTotalSupplyResponse, type MetadataEntryParam, OPERATOR_ABI, PAYMENT_INFO_TYPEHASH, type PaymentRequirements, type PaymentRequirementsOptions, type ProofOfPayment, type RefundRequest, type RefundStatus, type RegisterAgentRequest, type RegisterAgentResponse, type ReputationResponse, type ReputationSummary, type RequestRefundOptions, type SettleRequest, type SettleResponse, type SettleResponseWithProof, TIER_TIMINGS, USDC_DOMAIN_NAME, type VerifyRequest, type VerifyResponse, X402_CORS_HEADERS, X402_HEADER_NAMES, ZERO_ADDRESS, buildErc8004PaymentRequirements, buildPaymentRequirements, buildSettleRequest, buildVerifyRequest, canRefundEscrow, canReleaseEscrow, create402Response, createPaymentMiddleware, escrowTimeRemaining, extractPaymentFromHeaders, getCorsHeaders, getEscrowContractsByChainId, getEscrowSupportedChainIds, isEscrowExpired, isEscrowSupportedOnChain, parsePaymentHeader };
|
package/dist/backend/index.d.ts
CHANGED
|
@@ -1037,7 +1037,7 @@ declare function escrowTimeRemaining(escrow: EscrowPayment): number;
|
|
|
1037
1037
|
*/
|
|
1038
1038
|
declare const ERC8004_EXTENSION_ID = "8004-reputation";
|
|
1039
1039
|
/**
|
|
1040
|
-
* ERC-8004 contract addresses per network (
|
|
1040
|
+
* ERC-8004 contract addresses per network (16 networks)
|
|
1041
1041
|
*/
|
|
1042
1042
|
declare const ERC8004_CONTRACTS: Record<string, {
|
|
1043
1043
|
identityRegistry?: string;
|
|
@@ -1048,9 +1048,9 @@ declare const ERC8004_CONTRACTS: Record<string, {
|
|
|
1048
1048
|
* Network type for ERC-8004 operations
|
|
1049
1049
|
*/
|
|
1050
1050
|
/**
|
|
1051
|
-
* Network type for ERC-8004 operations (
|
|
1051
|
+
* Network type for ERC-8004 operations (16 networks)
|
|
1052
1052
|
*/
|
|
1053
|
-
type Erc8004Network = 'ethereum' | 'base-mainnet' | 'polygon' | 'arbitrum' | 'celo' | 'bsc' | 'monad' | 'ethereum-sepolia' | 'base-sepolia' | 'polygon-amoy' | 'arbitrum-sepolia' | 'celo-sepolia';
|
|
1053
|
+
type Erc8004Network = 'ethereum' | 'base-mainnet' | 'polygon' | 'arbitrum' | 'optimism' | 'celo' | 'bsc' | 'monad' | 'avalanche' | 'ethereum-sepolia' | 'base-sepolia' | 'polygon-amoy' | 'arbitrum-sepolia' | 'optimism-sepolia' | 'celo-sepolia' | 'avalanche-fuji';
|
|
1054
1054
|
/**
|
|
1055
1055
|
* Proof of payment returned when settling with ERC-8004 extension
|
|
1056
1056
|
*/
|
|
@@ -1643,6 +1643,22 @@ interface AdvancedTransactionResult {
|
|
|
1643
1643
|
gasUsed?: number;
|
|
1644
1644
|
error?: string;
|
|
1645
1645
|
}
|
|
1646
|
+
/**
|
|
1647
|
+
* Response from the facilitator's /escrow/state endpoint.
|
|
1648
|
+
* Represents the on-chain state of an escrow for a given paymentInfo + payer.
|
|
1649
|
+
*/
|
|
1650
|
+
interface EscrowStateResponse {
|
|
1651
|
+
/** Whether the payment has already been collected (released) */
|
|
1652
|
+
hasCollectedPayment: boolean;
|
|
1653
|
+
/** Amount that can still be captured/released (in atomic units) */
|
|
1654
|
+
capturableAmount: string;
|
|
1655
|
+
/** Amount that can still be refunded to the payer (in atomic units) */
|
|
1656
|
+
refundableAmount: string;
|
|
1657
|
+
/** Keccak256 hash of the paymentInfo struct */
|
|
1658
|
+
paymentInfoHash: string;
|
|
1659
|
+
/** Network in CAIP-2 format (e.g., "eip155:8453") */
|
|
1660
|
+
network: string;
|
|
1661
|
+
}
|
|
1646
1662
|
/**
|
|
1647
1663
|
* Contract addresses configuration for AdvancedEscrowClient.
|
|
1648
1664
|
*
|
|
@@ -1792,6 +1808,69 @@ declare class AdvancedEscrowClient {
|
|
|
1792
1808
|
* @param amount - Amount to refund (defaults to maxAmount)
|
|
1793
1809
|
*/
|
|
1794
1810
|
refundInEscrow(paymentInfo: AdvancedPaymentInfo, amount?: string): Promise<AdvancedTransactionResult>;
|
|
1811
|
+
/**
|
|
1812
|
+
* GASLESS RELEASE: Release escrowed funds via the facilitator.
|
|
1813
|
+
*
|
|
1814
|
+
* Instead of calling the PaymentOperator contract directly (which requires
|
|
1815
|
+
* gas), this sends a release request to the facilitator, which submits
|
|
1816
|
+
* the transaction on your behalf.
|
|
1817
|
+
*
|
|
1818
|
+
* @param paymentInfo - PaymentInfo from the authorize step
|
|
1819
|
+
* @param amount - Amount to release in atomic units (defaults to maxAmount)
|
|
1820
|
+
* @returns Transaction result from the facilitator
|
|
1821
|
+
*
|
|
1822
|
+
* @example
|
|
1823
|
+
* ```typescript
|
|
1824
|
+
* const pi = client.buildPaymentInfo('0xWorker...', '5000000', 'standard');
|
|
1825
|
+
* await client.authorize(pi);
|
|
1826
|
+
* // Worker completes task...
|
|
1827
|
+
* const result = await client.releaseViaFacilitator(pi);
|
|
1828
|
+
* console.log(result.transactionHash);
|
|
1829
|
+
* ```
|
|
1830
|
+
*/
|
|
1831
|
+
releaseViaFacilitator(paymentInfo: AdvancedPaymentInfo, amount?: string): Promise<AdvancedTransactionResult>;
|
|
1832
|
+
/**
|
|
1833
|
+
* GASLESS REFUND: Refund escrowed funds via the facilitator.
|
|
1834
|
+
*
|
|
1835
|
+
* Instead of calling the PaymentOperator contract directly (which requires
|
|
1836
|
+
* gas), this sends a refundInEscrow request to the facilitator, which
|
|
1837
|
+
* submits the transaction on your behalf.
|
|
1838
|
+
*
|
|
1839
|
+
* @param paymentInfo - PaymentInfo from the authorize step
|
|
1840
|
+
* @param amount - Amount to refund in atomic units (defaults to maxAmount)
|
|
1841
|
+
* @returns Transaction result from the facilitator
|
|
1842
|
+
*
|
|
1843
|
+
* @example
|
|
1844
|
+
* ```typescript
|
|
1845
|
+
* const pi = client.buildPaymentInfo('0xWorker...', '5000000', 'standard');
|
|
1846
|
+
* await client.authorize(pi);
|
|
1847
|
+
* // Task cancelled...
|
|
1848
|
+
* const result = await client.refundViaFacilitator(pi);
|
|
1849
|
+
* console.log(result.transactionHash);
|
|
1850
|
+
* ```
|
|
1851
|
+
*/
|
|
1852
|
+
refundViaFacilitator(paymentInfo: AdvancedPaymentInfo, amount?: string): Promise<AdvancedTransactionResult>;
|
|
1853
|
+
/**
|
|
1854
|
+
* QUERY ESCROW STATE: Read on-chain escrow state via the facilitator.
|
|
1855
|
+
*
|
|
1856
|
+
* This is a read-only operation that queries the facilitator for the
|
|
1857
|
+
* current escrow state without requiring gas or a signer.
|
|
1858
|
+
*
|
|
1859
|
+
* @param paymentInfo - PaymentInfo to query state for
|
|
1860
|
+
* @returns Escrow state including capturable/refundable amounts
|
|
1861
|
+
*
|
|
1862
|
+
* @example
|
|
1863
|
+
* ```typescript
|
|
1864
|
+
* const pi = client.buildPaymentInfo('0xWorker...', '5000000', 'standard');
|
|
1865
|
+
* await client.authorize(pi);
|
|
1866
|
+
*
|
|
1867
|
+
* const state = await client.queryEscrowState(pi);
|
|
1868
|
+
* console.log(`Capturable: ${state.capturableAmount}`);
|
|
1869
|
+
* console.log(`Refundable: ${state.refundableAmount}`);
|
|
1870
|
+
* console.log(`Already collected: ${state.hasCollectedPayment}`);
|
|
1871
|
+
* ```
|
|
1872
|
+
*/
|
|
1873
|
+
queryEscrowState(paymentInfo: AdvancedPaymentInfo): Promise<EscrowStateResponse>;
|
|
1795
1874
|
/**
|
|
1796
1875
|
* CHARGE: Direct instant payment (no escrow hold).
|
|
1797
1876
|
*
|
|
@@ -1825,4 +1904,4 @@ declare class AdvancedEscrowClient {
|
|
|
1825
1904
|
refundPostEscrow(paymentInfo: AdvancedPaymentInfo, amount?: string, tokenCollector?: string, collectorData?: string): Promise<AdvancedTransactionResult>;
|
|
1826
1905
|
}
|
|
1827
1906
|
|
|
1828
|
-
export { type AdvancedAuthorizationResult, AdvancedEscrowClient, type AdvancedEscrowClientOptions, type AdvancedEscrowContracts, type AdvancedEscrowTaskTier, type AdvancedPaymentInfo, type AdvancedTransactionResult, type AgentIdentity, type AgentRegistration, type AgentRegistrationFile, type AgentService, BASE_MAINNET_CONTRACTS, type BazaarCategory, BazaarClient, type BazaarClientOptions, type BazaarDiscoverOptions, type BazaarDiscoverResponse, type BazaarNetwork, type BazaarRegisterOptions, type BazaarResource, type BazaarToken, type CreateEscrowOptions, DEPOSIT_LIMIT_USDC, type Dispute, type DisputeOutcome, ERC8004_CONTRACTS, ERC8004_EXTENSION_ID, ESCROW_CONTRACTS, Erc8004Client, type Erc8004ClientOptions, type Erc8004Network, EscrowClient, type EscrowClientOptions, type EscrowPayment, type EscrowStatus, FacilitatorClient, type FacilitatorClientOptions, type FeedbackEntry, type FeedbackParams, type FeedbackRequest, type FeedbackResponse, type IdentityMetadataResponse, type IdentityTotalSupplyResponse, type MetadataEntryParam, OPERATOR_ABI, PAYMENT_INFO_TYPEHASH, type PaymentRequirements, type PaymentRequirementsOptions, type ProofOfPayment, type RefundRequest, type RefundStatus, type RegisterAgentRequest, type RegisterAgentResponse, type ReputationResponse, type ReputationSummary, type RequestRefundOptions, type SettleRequest, type SettleResponse, type SettleResponseWithProof, TIER_TIMINGS, USDC_DOMAIN_NAME, type VerifyRequest, type VerifyResponse, X402_CORS_HEADERS, X402_HEADER_NAMES, ZERO_ADDRESS, buildErc8004PaymentRequirements, buildPaymentRequirements, buildSettleRequest, buildVerifyRequest, canRefundEscrow, canReleaseEscrow, create402Response, createPaymentMiddleware, escrowTimeRemaining, extractPaymentFromHeaders, getCorsHeaders, getEscrowContractsByChainId, getEscrowSupportedChainIds, isEscrowExpired, isEscrowSupportedOnChain, parsePaymentHeader };
|
|
1907
|
+
export { type AdvancedAuthorizationResult, AdvancedEscrowClient, type AdvancedEscrowClientOptions, type AdvancedEscrowContracts, type AdvancedEscrowTaskTier, type AdvancedPaymentInfo, type AdvancedTransactionResult, type AgentIdentity, type AgentRegistration, type AgentRegistrationFile, type AgentService, BASE_MAINNET_CONTRACTS, type BazaarCategory, BazaarClient, type BazaarClientOptions, type BazaarDiscoverOptions, type BazaarDiscoverResponse, type BazaarNetwork, type BazaarRegisterOptions, type BazaarResource, type BazaarToken, type CreateEscrowOptions, DEPOSIT_LIMIT_USDC, type Dispute, type DisputeOutcome, ERC8004_CONTRACTS, ERC8004_EXTENSION_ID, ESCROW_CONTRACTS, Erc8004Client, type Erc8004ClientOptions, type Erc8004Network, EscrowClient, type EscrowClientOptions, type EscrowPayment, type EscrowStateResponse, type EscrowStatus, FacilitatorClient, type FacilitatorClientOptions, type FeedbackEntry, type FeedbackParams, type FeedbackRequest, type FeedbackResponse, type IdentityMetadataResponse, type IdentityTotalSupplyResponse, type MetadataEntryParam, OPERATOR_ABI, PAYMENT_INFO_TYPEHASH, type PaymentRequirements, type PaymentRequirementsOptions, type ProofOfPayment, type RefundRequest, type RefundStatus, type RegisterAgentRequest, type RegisterAgentResponse, type ReputationResponse, type ReputationSummary, type RequestRefundOptions, type SettleRequest, type SettleResponse, type SettleResponseWithProof, TIER_TIMINGS, USDC_DOMAIN_NAME, type VerifyRequest, type VerifyResponse, X402_CORS_HEADERS, X402_HEADER_NAMES, ZERO_ADDRESS, buildErc8004PaymentRequirements, buildPaymentRequirements, buildSettleRequest, buildVerifyRequest, canRefundEscrow, canReleaseEscrow, create402Response, createPaymentMiddleware, escrowTimeRemaining, extractPaymentFromHeaders, getCorsHeaders, getEscrowContractsByChainId, getEscrowSupportedChainIds, isEscrowExpired, isEscrowSupportedOnChain, parsePaymentHeader };
|
package/dist/backend/index.js
CHANGED
|
@@ -1921,7 +1921,7 @@ var TESTNET_IDENTITY = "0x8004A818BFB912233c491871b3d84c89A494BD9e";
|
|
|
1921
1921
|
var TESTNET_REPUTATION = "0x8004B663056A597Dffe9eCcC1965A193B7388713";
|
|
1922
1922
|
var TESTNET_VALIDATION = "0x8004Cb1BF31DAf7788923b405b754f57acEB4272";
|
|
1923
1923
|
var ERC8004_CONTRACTS = {
|
|
1924
|
-
// Mainnets (
|
|
1924
|
+
// Mainnets (9)
|
|
1925
1925
|
ethereum: {
|
|
1926
1926
|
identityRegistry: MAINNET_IDENTITY,
|
|
1927
1927
|
reputationRegistry: MAINNET_REPUTATION
|
|
@@ -1938,6 +1938,10 @@ var ERC8004_CONTRACTS = {
|
|
|
1938
1938
|
identityRegistry: MAINNET_IDENTITY,
|
|
1939
1939
|
reputationRegistry: MAINNET_REPUTATION
|
|
1940
1940
|
},
|
|
1941
|
+
optimism: {
|
|
1942
|
+
identityRegistry: MAINNET_IDENTITY,
|
|
1943
|
+
reputationRegistry: MAINNET_REPUTATION
|
|
1944
|
+
},
|
|
1941
1945
|
celo: {
|
|
1942
1946
|
identityRegistry: MAINNET_IDENTITY,
|
|
1943
1947
|
reputationRegistry: MAINNET_REPUTATION
|
|
@@ -1950,7 +1954,11 @@ var ERC8004_CONTRACTS = {
|
|
|
1950
1954
|
identityRegistry: MAINNET_IDENTITY,
|
|
1951
1955
|
reputationRegistry: MAINNET_REPUTATION
|
|
1952
1956
|
},
|
|
1953
|
-
|
|
1957
|
+
avalanche: {
|
|
1958
|
+
identityRegistry: MAINNET_IDENTITY,
|
|
1959
|
+
reputationRegistry: MAINNET_REPUTATION
|
|
1960
|
+
},
|
|
1961
|
+
// Testnets (7)
|
|
1954
1962
|
"ethereum-sepolia": {
|
|
1955
1963
|
identityRegistry: TESTNET_IDENTITY,
|
|
1956
1964
|
reputationRegistry: TESTNET_REPUTATION,
|
|
@@ -1971,10 +1979,20 @@ var ERC8004_CONTRACTS = {
|
|
|
1971
1979
|
reputationRegistry: TESTNET_REPUTATION,
|
|
1972
1980
|
validationRegistry: TESTNET_VALIDATION
|
|
1973
1981
|
},
|
|
1982
|
+
"optimism-sepolia": {
|
|
1983
|
+
identityRegistry: TESTNET_IDENTITY,
|
|
1984
|
+
reputationRegistry: TESTNET_REPUTATION,
|
|
1985
|
+
validationRegistry: TESTNET_VALIDATION
|
|
1986
|
+
},
|
|
1974
1987
|
"celo-sepolia": {
|
|
1975
1988
|
identityRegistry: TESTNET_IDENTITY,
|
|
1976
1989
|
reputationRegistry: TESTNET_REPUTATION,
|
|
1977
1990
|
validationRegistry: TESTNET_VALIDATION
|
|
1991
|
+
},
|
|
1992
|
+
"avalanche-fuji": {
|
|
1993
|
+
identityRegistry: TESTNET_IDENTITY,
|
|
1994
|
+
reputationRegistry: TESTNET_REPUTATION,
|
|
1995
|
+
validationRegistry: TESTNET_VALIDATION
|
|
1978
1996
|
}
|
|
1979
1997
|
};
|
|
1980
1998
|
var Erc8004Client = class {
|
|
@@ -2846,6 +2864,206 @@ var AdvancedEscrowClient = class {
|
|
|
2846
2864
|
return { success: false, error: e.message || String(e) };
|
|
2847
2865
|
}
|
|
2848
2866
|
}
|
|
2867
|
+
// ==========================================================================
|
|
2868
|
+
// GASLESS FACILITATOR METHODS
|
|
2869
|
+
// ==========================================================================
|
|
2870
|
+
/**
|
|
2871
|
+
* GASLESS RELEASE: Release escrowed funds via the facilitator.
|
|
2872
|
+
*
|
|
2873
|
+
* Instead of calling the PaymentOperator contract directly (which requires
|
|
2874
|
+
* gas), this sends a release request to the facilitator, which submits
|
|
2875
|
+
* the transaction on your behalf.
|
|
2876
|
+
*
|
|
2877
|
+
* @param paymentInfo - PaymentInfo from the authorize step
|
|
2878
|
+
* @param amount - Amount to release in atomic units (defaults to maxAmount)
|
|
2879
|
+
* @returns Transaction result from the facilitator
|
|
2880
|
+
*
|
|
2881
|
+
* @example
|
|
2882
|
+
* ```typescript
|
|
2883
|
+
* const pi = client.buildPaymentInfo('0xWorker...', '5000000', 'standard');
|
|
2884
|
+
* await client.authorize(pi);
|
|
2885
|
+
* // Worker completes task...
|
|
2886
|
+
* const result = await client.releaseViaFacilitator(pi);
|
|
2887
|
+
* console.log(result.transactionHash);
|
|
2888
|
+
* ```
|
|
2889
|
+
*/
|
|
2890
|
+
async releaseViaFacilitator(paymentInfo, amount) {
|
|
2891
|
+
if (!this.payerAddress) await this.init();
|
|
2892
|
+
try {
|
|
2893
|
+
const payload = {
|
|
2894
|
+
x402Version: 2,
|
|
2895
|
+
scheme: "escrow",
|
|
2896
|
+
action: "release",
|
|
2897
|
+
payload: {
|
|
2898
|
+
paymentInfo: {
|
|
2899
|
+
operator: paymentInfo.operator,
|
|
2900
|
+
receiver: paymentInfo.receiver,
|
|
2901
|
+
token: paymentInfo.token,
|
|
2902
|
+
maxAmount: paymentInfo.maxAmount,
|
|
2903
|
+
preApprovalExpiry: paymentInfo.preApprovalExpiry,
|
|
2904
|
+
authorizationExpiry: paymentInfo.authorizationExpiry,
|
|
2905
|
+
refundExpiry: paymentInfo.refundExpiry,
|
|
2906
|
+
minFeeBps: paymentInfo.minFeeBps,
|
|
2907
|
+
maxFeeBps: paymentInfo.maxFeeBps,
|
|
2908
|
+
feeReceiver: paymentInfo.feeReceiver,
|
|
2909
|
+
salt: paymentInfo.salt
|
|
2910
|
+
},
|
|
2911
|
+
payer: this.payerAddress,
|
|
2912
|
+
amount: amount || paymentInfo.maxAmount
|
|
2913
|
+
},
|
|
2914
|
+
paymentRequirements: {
|
|
2915
|
+
scheme: "escrow",
|
|
2916
|
+
network: `eip155:${this.chainId}`,
|
|
2917
|
+
extra: {
|
|
2918
|
+
escrowAddress: this.contracts.escrow,
|
|
2919
|
+
operatorAddress: this.contracts.operator,
|
|
2920
|
+
tokenCollector: this.contracts.tokenCollector
|
|
2921
|
+
}
|
|
2922
|
+
}
|
|
2923
|
+
};
|
|
2924
|
+
const response = await fetch(`${this.facilitatorUrl}/settle`, {
|
|
2925
|
+
method: "POST",
|
|
2926
|
+
headers: { "Content-Type": "application/json" },
|
|
2927
|
+
body: JSON.stringify(payload)
|
|
2928
|
+
});
|
|
2929
|
+
const result = await response.json();
|
|
2930
|
+
if (result.success) {
|
|
2931
|
+
return {
|
|
2932
|
+
success: true,
|
|
2933
|
+
transactionHash: result.transaction || result.transactionHash || result.transaction_hash
|
|
2934
|
+
};
|
|
2935
|
+
}
|
|
2936
|
+
return { success: false, error: result.errorReason || result.error || "Release failed" };
|
|
2937
|
+
} catch (e) {
|
|
2938
|
+
return { success: false, error: e.message || String(e) };
|
|
2939
|
+
}
|
|
2940
|
+
}
|
|
2941
|
+
/**
|
|
2942
|
+
* GASLESS REFUND: Refund escrowed funds via the facilitator.
|
|
2943
|
+
*
|
|
2944
|
+
* Instead of calling the PaymentOperator contract directly (which requires
|
|
2945
|
+
* gas), this sends a refundInEscrow request to the facilitator, which
|
|
2946
|
+
* submits the transaction on your behalf.
|
|
2947
|
+
*
|
|
2948
|
+
* @param paymentInfo - PaymentInfo from the authorize step
|
|
2949
|
+
* @param amount - Amount to refund in atomic units (defaults to maxAmount)
|
|
2950
|
+
* @returns Transaction result from the facilitator
|
|
2951
|
+
*
|
|
2952
|
+
* @example
|
|
2953
|
+
* ```typescript
|
|
2954
|
+
* const pi = client.buildPaymentInfo('0xWorker...', '5000000', 'standard');
|
|
2955
|
+
* await client.authorize(pi);
|
|
2956
|
+
* // Task cancelled...
|
|
2957
|
+
* const result = await client.refundViaFacilitator(pi);
|
|
2958
|
+
* console.log(result.transactionHash);
|
|
2959
|
+
* ```
|
|
2960
|
+
*/
|
|
2961
|
+
async refundViaFacilitator(paymentInfo, amount) {
|
|
2962
|
+
if (!this.payerAddress) await this.init();
|
|
2963
|
+
try {
|
|
2964
|
+
const payload = {
|
|
2965
|
+
x402Version: 2,
|
|
2966
|
+
scheme: "escrow",
|
|
2967
|
+
action: "refundInEscrow",
|
|
2968
|
+
payload: {
|
|
2969
|
+
paymentInfo: {
|
|
2970
|
+
operator: paymentInfo.operator,
|
|
2971
|
+
receiver: paymentInfo.receiver,
|
|
2972
|
+
token: paymentInfo.token,
|
|
2973
|
+
maxAmount: paymentInfo.maxAmount,
|
|
2974
|
+
preApprovalExpiry: paymentInfo.preApprovalExpiry,
|
|
2975
|
+
authorizationExpiry: paymentInfo.authorizationExpiry,
|
|
2976
|
+
refundExpiry: paymentInfo.refundExpiry,
|
|
2977
|
+
minFeeBps: paymentInfo.minFeeBps,
|
|
2978
|
+
maxFeeBps: paymentInfo.maxFeeBps,
|
|
2979
|
+
feeReceiver: paymentInfo.feeReceiver,
|
|
2980
|
+
salt: paymentInfo.salt
|
|
2981
|
+
},
|
|
2982
|
+
payer: this.payerAddress,
|
|
2983
|
+
amount: amount || paymentInfo.maxAmount
|
|
2984
|
+
},
|
|
2985
|
+
paymentRequirements: {
|
|
2986
|
+
scheme: "escrow",
|
|
2987
|
+
network: `eip155:${this.chainId}`,
|
|
2988
|
+
extra: {
|
|
2989
|
+
escrowAddress: this.contracts.escrow,
|
|
2990
|
+
operatorAddress: this.contracts.operator,
|
|
2991
|
+
tokenCollector: this.contracts.tokenCollector
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
};
|
|
2995
|
+
const response = await fetch(`${this.facilitatorUrl}/settle`, {
|
|
2996
|
+
method: "POST",
|
|
2997
|
+
headers: { "Content-Type": "application/json" },
|
|
2998
|
+
body: JSON.stringify(payload)
|
|
2999
|
+
});
|
|
3000
|
+
const result = await response.json();
|
|
3001
|
+
if (result.success) {
|
|
3002
|
+
return {
|
|
3003
|
+
success: true,
|
|
3004
|
+
transactionHash: result.transaction || result.transactionHash || result.transaction_hash
|
|
3005
|
+
};
|
|
3006
|
+
}
|
|
3007
|
+
return { success: false, error: result.errorReason || result.error || "Refund failed" };
|
|
3008
|
+
} catch (e) {
|
|
3009
|
+
return { success: false, error: e.message || String(e) };
|
|
3010
|
+
}
|
|
3011
|
+
}
|
|
3012
|
+
/**
|
|
3013
|
+
* QUERY ESCROW STATE: Read on-chain escrow state via the facilitator.
|
|
3014
|
+
*
|
|
3015
|
+
* This is a read-only operation that queries the facilitator for the
|
|
3016
|
+
* current escrow state without requiring gas or a signer.
|
|
3017
|
+
*
|
|
3018
|
+
* @param paymentInfo - PaymentInfo to query state for
|
|
3019
|
+
* @returns Escrow state including capturable/refundable amounts
|
|
3020
|
+
*
|
|
3021
|
+
* @example
|
|
3022
|
+
* ```typescript
|
|
3023
|
+
* const pi = client.buildPaymentInfo('0xWorker...', '5000000', 'standard');
|
|
3024
|
+
* await client.authorize(pi);
|
|
3025
|
+
*
|
|
3026
|
+
* const state = await client.queryEscrowState(pi);
|
|
3027
|
+
* console.log(`Capturable: ${state.capturableAmount}`);
|
|
3028
|
+
* console.log(`Refundable: ${state.refundableAmount}`);
|
|
3029
|
+
* console.log(`Already collected: ${state.hasCollectedPayment}`);
|
|
3030
|
+
* ```
|
|
3031
|
+
*/
|
|
3032
|
+
async queryEscrowState(paymentInfo) {
|
|
3033
|
+
if (!this.payerAddress) await this.init();
|
|
3034
|
+
const payload = {
|
|
3035
|
+
paymentInfo: {
|
|
3036
|
+
operator: paymentInfo.operator,
|
|
3037
|
+
receiver: paymentInfo.receiver,
|
|
3038
|
+
token: paymentInfo.token,
|
|
3039
|
+
maxAmount: paymentInfo.maxAmount,
|
|
3040
|
+
preApprovalExpiry: paymentInfo.preApprovalExpiry,
|
|
3041
|
+
authorizationExpiry: paymentInfo.authorizationExpiry,
|
|
3042
|
+
refundExpiry: paymentInfo.refundExpiry,
|
|
3043
|
+
minFeeBps: paymentInfo.minFeeBps,
|
|
3044
|
+
maxFeeBps: paymentInfo.maxFeeBps,
|
|
3045
|
+
feeReceiver: paymentInfo.feeReceiver,
|
|
3046
|
+
salt: paymentInfo.salt
|
|
3047
|
+
},
|
|
3048
|
+
payer: this.payerAddress,
|
|
3049
|
+
network: `eip155:${this.chainId}`,
|
|
3050
|
+
extra: {
|
|
3051
|
+
escrowAddress: this.contracts.escrow,
|
|
3052
|
+
operatorAddress: this.contracts.operator,
|
|
3053
|
+
tokenCollector: this.contracts.tokenCollector
|
|
3054
|
+
}
|
|
3055
|
+
};
|
|
3056
|
+
const response = await fetch(`${this.facilitatorUrl}/escrow/state`, {
|
|
3057
|
+
method: "POST",
|
|
3058
|
+
headers: { "Content-Type": "application/json" },
|
|
3059
|
+
body: JSON.stringify(payload)
|
|
3060
|
+
});
|
|
3061
|
+
if (!response.ok) {
|
|
3062
|
+
const errorText = await response.text();
|
|
3063
|
+
throw new Error(`Escrow state query failed: ${response.status} - ${errorText}`);
|
|
3064
|
+
}
|
|
3065
|
+
return await response.json();
|
|
3066
|
+
}
|
|
2849
3067
|
/**
|
|
2850
3068
|
* CHARGE: Direct instant payment (no escrow hold).
|
|
2851
3069
|
*
|