@dcentralab/d402-client 0.3.15 → 0.3.17
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/index.d.mts +45 -2
- package/dist/index.d.ts +45 -2
- package/dist/index.js +35 -51
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -52
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Account } from 'viem/accounts';
|
|
2
|
-
import { WalletClient, PublicClient, Hash, Address } from 'viem';
|
|
2
|
+
import { WalletClient, PublicClient, Hash, Address, Hex } from 'viem';
|
|
3
3
|
import { Chain } from 'viem/chains';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -798,6 +798,33 @@ declare function getWalletEIP712Domain(params: {
|
|
|
798
798
|
chainId: bigint;
|
|
799
799
|
verifyingContract: Address;
|
|
800
800
|
}>;
|
|
801
|
+
/**
|
|
802
|
+
* Validate a consumer payment signature on-chain.
|
|
803
|
+
*
|
|
804
|
+
* Calls the IATPWallet's validateConsumerSignature view function to verify
|
|
805
|
+
* that a payment signature is valid for the given parameters.
|
|
806
|
+
*
|
|
807
|
+
* @param params - Query parameters
|
|
808
|
+
* @param params.publicClient - Viem PublicClient
|
|
809
|
+
* @param params.walletAddress - IATPWallet contract address
|
|
810
|
+
* @param params.tokenAddress - Token contract address (e.g., USDC)
|
|
811
|
+
* @param params.amount - Payment amount in token's base units
|
|
812
|
+
* @param params.providerAddress - Provider's address
|
|
813
|
+
* @param params.deadline - Signature deadline (unix timestamp)
|
|
814
|
+
* @param params.signature - The signed payment signature bytes
|
|
815
|
+
* @param params.network - Network: "sepolia" | "arbitrum" (default: "sepolia")
|
|
816
|
+
* @returns true if the signature is valid, false otherwise
|
|
817
|
+
*/
|
|
818
|
+
declare function validateConsumerSignature(params: {
|
|
819
|
+
publicClient: PublicClient;
|
|
820
|
+
walletAddress: Address;
|
|
821
|
+
tokenAddress: Address;
|
|
822
|
+
amount: bigint;
|
|
823
|
+
providerAddress: Address;
|
|
824
|
+
deadline: bigint;
|
|
825
|
+
signature: Hex;
|
|
826
|
+
network?: SupportedNetwork;
|
|
827
|
+
}): Promise<boolean>;
|
|
801
828
|
|
|
802
829
|
/**
|
|
803
830
|
* IATPWallet withdrawal functions
|
|
@@ -1134,6 +1161,22 @@ declare function getUnlockedBalanceForProvider(params: {
|
|
|
1134
1161
|
tokenAddress: Address;
|
|
1135
1162
|
network?: SupportedNetwork;
|
|
1136
1163
|
}): Promise<bigint>;
|
|
1164
|
+
/**
|
|
1165
|
+
* Get total dispute amount currently in progress for a provider.
|
|
1166
|
+
*
|
|
1167
|
+
* @param params - Query parameters
|
|
1168
|
+
* @param params.publicClient - Viem PublicClient (from wagmi usePublicClient)
|
|
1169
|
+
* @param params.providerAddress - Provider (utility agent) IATPWallet address
|
|
1170
|
+
* @param params.tokenAddress - Token contract address
|
|
1171
|
+
* @param params.network - Network: "sepolia" | "arbitrum" (default: "sepolia")
|
|
1172
|
+
* @returns Total dispute amount in progress in base units (wei)
|
|
1173
|
+
*/
|
|
1174
|
+
declare function getProviderTotalDisputeInProgress(params: {
|
|
1175
|
+
publicClient: PublicClient;
|
|
1176
|
+
providerAddress: Address;
|
|
1177
|
+
tokenAddress: Address;
|
|
1178
|
+
network?: SupportedNetwork;
|
|
1179
|
+
}): Promise<bigint>;
|
|
1137
1180
|
|
|
1138
1181
|
/**
|
|
1139
1182
|
* IATPSettlementLayer operations
|
|
@@ -1409,4 +1452,4 @@ declare class UnsupportedNetworkError extends PaymentError {
|
|
|
1409
1452
|
constructor(network: string);
|
|
1410
1453
|
}
|
|
1411
1454
|
|
|
1412
|
-
export { ContractName, D402Client, type D402ClientConfig, type D402Response, type EIP712Domain, Invalid402ResponseError, type JsonRpcPayload, type McpToolResult, MissingRequestConfigError, type ParsedMcpResponse, PaymentAlreadyAttemptedError, PaymentAmountExceededError, type PaymentAuthorization, PaymentError, type PaymentRequirement, type PaymentSelector, type PaymentSelectorOptions, PaymentVerificationError, type SignedPayment, type SupportedNetwork, UnsupportedNetworkError, UnsupportedSchemeError, type WalletCreationResult, type WithdrawalRequest, buildMcpHeaders, buildToolCallPayload, createIATPWallet, createPaymentSelector, decodePayment, decodePaymentResponse, encodePayment, executeWithdrawal, extractToolResult, findMatchingPaymentRequirement, formatMoney, generateNonce, getAvailableBalance, getChain, getChainId, getContractAbi, getContractAddress, getContractConfig, getCurrentTimestamp, getLockedBalanceForProvider, getUnlockedBalanceForProvider, getUsdcAddress, getWalletEIP712Domain, getWalletInfo, getWalletsByOwner, getWithdrawalRequest, initMcpSession, isValidAddress, normalizeAddress, parseAllPaymentRequirements, parseMcpResponse, parseMoney, parsePaymentRequirement, requestWithdrawal, selectPaymentRequirement, signD402Payment, sortPaymentRequirements, usdToUsdc, withdrawAllAvailableEpochs, withdrawAllFromSettlement };
|
|
1455
|
+
export { ContractName, D402Client, type D402ClientConfig, type D402Response, type EIP712Domain, Invalid402ResponseError, type JsonRpcPayload, type McpToolResult, MissingRequestConfigError, type ParsedMcpResponse, PaymentAlreadyAttemptedError, PaymentAmountExceededError, type PaymentAuthorization, PaymentError, type PaymentRequirement, type PaymentSelector, type PaymentSelectorOptions, PaymentVerificationError, type SignedPayment, type SupportedNetwork, UnsupportedNetworkError, UnsupportedSchemeError, type WalletCreationResult, type WithdrawalRequest, buildMcpHeaders, buildToolCallPayload, createIATPWallet, createPaymentSelector, decodePayment, decodePaymentResponse, encodePayment, executeWithdrawal, extractToolResult, findMatchingPaymentRequirement, formatMoney, generateNonce, getAvailableBalance, getChain, getChainId, getContractAbi, getContractAddress, getContractConfig, getCurrentTimestamp, getLockedBalanceForProvider, getProviderTotalDisputeInProgress, getUnlockedBalanceForProvider, getUsdcAddress, getWalletEIP712Domain, getWalletInfo, getWalletsByOwner, getWithdrawalRequest, initMcpSession, isValidAddress, normalizeAddress, parseAllPaymentRequirements, parseMcpResponse, parseMoney, parsePaymentRequirement, requestWithdrawal, selectPaymentRequirement, signD402Payment, sortPaymentRequirements, usdToUsdc, validateConsumerSignature, withdrawAllAvailableEpochs, withdrawAllFromSettlement };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Account } from 'viem/accounts';
|
|
2
|
-
import { WalletClient, PublicClient, Hash, Address } from 'viem';
|
|
2
|
+
import { WalletClient, PublicClient, Hash, Address, Hex } from 'viem';
|
|
3
3
|
import { Chain } from 'viem/chains';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -798,6 +798,33 @@ declare function getWalletEIP712Domain(params: {
|
|
|
798
798
|
chainId: bigint;
|
|
799
799
|
verifyingContract: Address;
|
|
800
800
|
}>;
|
|
801
|
+
/**
|
|
802
|
+
* Validate a consumer payment signature on-chain.
|
|
803
|
+
*
|
|
804
|
+
* Calls the IATPWallet's validateConsumerSignature view function to verify
|
|
805
|
+
* that a payment signature is valid for the given parameters.
|
|
806
|
+
*
|
|
807
|
+
* @param params - Query parameters
|
|
808
|
+
* @param params.publicClient - Viem PublicClient
|
|
809
|
+
* @param params.walletAddress - IATPWallet contract address
|
|
810
|
+
* @param params.tokenAddress - Token contract address (e.g., USDC)
|
|
811
|
+
* @param params.amount - Payment amount in token's base units
|
|
812
|
+
* @param params.providerAddress - Provider's address
|
|
813
|
+
* @param params.deadline - Signature deadline (unix timestamp)
|
|
814
|
+
* @param params.signature - The signed payment signature bytes
|
|
815
|
+
* @param params.network - Network: "sepolia" | "arbitrum" (default: "sepolia")
|
|
816
|
+
* @returns true if the signature is valid, false otherwise
|
|
817
|
+
*/
|
|
818
|
+
declare function validateConsumerSignature(params: {
|
|
819
|
+
publicClient: PublicClient;
|
|
820
|
+
walletAddress: Address;
|
|
821
|
+
tokenAddress: Address;
|
|
822
|
+
amount: bigint;
|
|
823
|
+
providerAddress: Address;
|
|
824
|
+
deadline: bigint;
|
|
825
|
+
signature: Hex;
|
|
826
|
+
network?: SupportedNetwork;
|
|
827
|
+
}): Promise<boolean>;
|
|
801
828
|
|
|
802
829
|
/**
|
|
803
830
|
* IATPWallet withdrawal functions
|
|
@@ -1134,6 +1161,22 @@ declare function getUnlockedBalanceForProvider(params: {
|
|
|
1134
1161
|
tokenAddress: Address;
|
|
1135
1162
|
network?: SupportedNetwork;
|
|
1136
1163
|
}): Promise<bigint>;
|
|
1164
|
+
/**
|
|
1165
|
+
* Get total dispute amount currently in progress for a provider.
|
|
1166
|
+
*
|
|
1167
|
+
* @param params - Query parameters
|
|
1168
|
+
* @param params.publicClient - Viem PublicClient (from wagmi usePublicClient)
|
|
1169
|
+
* @param params.providerAddress - Provider (utility agent) IATPWallet address
|
|
1170
|
+
* @param params.tokenAddress - Token contract address
|
|
1171
|
+
* @param params.network - Network: "sepolia" | "arbitrum" (default: "sepolia")
|
|
1172
|
+
* @returns Total dispute amount in progress in base units (wei)
|
|
1173
|
+
*/
|
|
1174
|
+
declare function getProviderTotalDisputeInProgress(params: {
|
|
1175
|
+
publicClient: PublicClient;
|
|
1176
|
+
providerAddress: Address;
|
|
1177
|
+
tokenAddress: Address;
|
|
1178
|
+
network?: SupportedNetwork;
|
|
1179
|
+
}): Promise<bigint>;
|
|
1137
1180
|
|
|
1138
1181
|
/**
|
|
1139
1182
|
* IATPSettlementLayer operations
|
|
@@ -1409,4 +1452,4 @@ declare class UnsupportedNetworkError extends PaymentError {
|
|
|
1409
1452
|
constructor(network: string);
|
|
1410
1453
|
}
|
|
1411
1454
|
|
|
1412
|
-
export { ContractName, D402Client, type D402ClientConfig, type D402Response, type EIP712Domain, Invalid402ResponseError, type JsonRpcPayload, type McpToolResult, MissingRequestConfigError, type ParsedMcpResponse, PaymentAlreadyAttemptedError, PaymentAmountExceededError, type PaymentAuthorization, PaymentError, type PaymentRequirement, type PaymentSelector, type PaymentSelectorOptions, PaymentVerificationError, type SignedPayment, type SupportedNetwork, UnsupportedNetworkError, UnsupportedSchemeError, type WalletCreationResult, type WithdrawalRequest, buildMcpHeaders, buildToolCallPayload, createIATPWallet, createPaymentSelector, decodePayment, decodePaymentResponse, encodePayment, executeWithdrawal, extractToolResult, findMatchingPaymentRequirement, formatMoney, generateNonce, getAvailableBalance, getChain, getChainId, getContractAbi, getContractAddress, getContractConfig, getCurrentTimestamp, getLockedBalanceForProvider, getUnlockedBalanceForProvider, getUsdcAddress, getWalletEIP712Domain, getWalletInfo, getWalletsByOwner, getWithdrawalRequest, initMcpSession, isValidAddress, normalizeAddress, parseAllPaymentRequirements, parseMcpResponse, parseMoney, parsePaymentRequirement, requestWithdrawal, selectPaymentRequirement, signD402Payment, sortPaymentRequirements, usdToUsdc, withdrawAllAvailableEpochs, withdrawAllFromSettlement };
|
|
1455
|
+
export { ContractName, D402Client, type D402ClientConfig, type D402Response, type EIP712Domain, Invalid402ResponseError, type JsonRpcPayload, type McpToolResult, MissingRequestConfigError, type ParsedMcpResponse, PaymentAlreadyAttemptedError, PaymentAmountExceededError, type PaymentAuthorization, PaymentError, type PaymentRequirement, type PaymentSelector, type PaymentSelectorOptions, PaymentVerificationError, type SignedPayment, type SupportedNetwork, UnsupportedNetworkError, UnsupportedSchemeError, type WalletCreationResult, type WithdrawalRequest, buildMcpHeaders, buildToolCallPayload, createIATPWallet, createPaymentSelector, decodePayment, decodePaymentResponse, encodePayment, executeWithdrawal, extractToolResult, findMatchingPaymentRequirement, formatMoney, generateNonce, getAvailableBalance, getChain, getChainId, getContractAbi, getContractAddress, getContractConfig, getCurrentTimestamp, getLockedBalanceForProvider, getProviderTotalDisputeInProgress, getUnlockedBalanceForProvider, getUsdcAddress, getWalletEIP712Domain, getWalletInfo, getWalletsByOwner, getWithdrawalRequest, initMcpSession, isValidAddress, normalizeAddress, parseAllPaymentRequirements, parseMcpResponse, parseMoney, parsePaymentRequirement, requestWithdrawal, selectPaymentRequirement, signD402Payment, sortPaymentRequirements, usdToUsdc, validateConsumerSignature, withdrawAllAvailableEpochs, withdrawAllFromSettlement };
|
package/dist/index.js
CHANGED
|
@@ -1183,19 +1183,6 @@ var sepolia_default = {
|
|
|
1183
1183
|
stateMutability: "view",
|
|
1184
1184
|
type: "function"
|
|
1185
1185
|
},
|
|
1186
|
-
{
|
|
1187
|
-
inputs: [],
|
|
1188
|
-
name: "MAX_REQUEST_PATH_LENGTH",
|
|
1189
|
-
outputs: [
|
|
1190
|
-
{
|
|
1191
|
-
internalType: "uint256",
|
|
1192
|
-
name: "",
|
|
1193
|
-
type: "uint256"
|
|
1194
|
-
}
|
|
1195
|
-
],
|
|
1196
|
-
stateMutability: "view",
|
|
1197
|
-
type: "function"
|
|
1198
|
-
},
|
|
1199
1186
|
{
|
|
1200
1187
|
inputs: [],
|
|
1201
1188
|
name: "PROVIDER_ATTESTATION_TYPEHASH",
|
|
@@ -1508,11 +1495,6 @@ var sepolia_default = {
|
|
|
1508
1495
|
name: "deadline",
|
|
1509
1496
|
type: "uint256"
|
|
1510
1497
|
},
|
|
1511
|
-
{
|
|
1512
|
-
internalType: "string",
|
|
1513
|
-
name: "requestPath",
|
|
1514
|
-
type: "string"
|
|
1515
|
-
},
|
|
1516
1498
|
{
|
|
1517
1499
|
internalType: "bytes",
|
|
1518
1500
|
name: "signature",
|
|
@@ -1604,11 +1586,6 @@ var sepolia_default = {
|
|
|
1604
1586
|
name: "deadline",
|
|
1605
1587
|
type: "uint256"
|
|
1606
1588
|
},
|
|
1607
|
-
{
|
|
1608
|
-
internalType: "string",
|
|
1609
|
-
name: "requestPath",
|
|
1610
|
-
type: "string"
|
|
1611
|
-
},
|
|
1612
1589
|
{
|
|
1613
1590
|
internalType: "bytes",
|
|
1614
1591
|
name: "signature",
|
|
@@ -1753,11 +1730,6 @@ var sepolia_default = {
|
|
|
1753
1730
|
name: "deadline",
|
|
1754
1731
|
type: "uint256"
|
|
1755
1732
|
},
|
|
1756
|
-
{
|
|
1757
|
-
internalType: "string",
|
|
1758
|
-
name: "requestPath",
|
|
1759
|
-
type: "string"
|
|
1760
|
-
},
|
|
1761
1733
|
{
|
|
1762
1734
|
internalType: "bytes",
|
|
1763
1735
|
name: "signature",
|
|
@@ -1778,14 +1750,14 @@ var sepolia_default = {
|
|
|
1778
1750
|
{
|
|
1779
1751
|
inputs: [
|
|
1780
1752
|
{
|
|
1781
|
-
internalType: "
|
|
1782
|
-
name: "
|
|
1783
|
-
type: "
|
|
1753
|
+
internalType: "bytes32",
|
|
1754
|
+
name: "consumerSignatureHash",
|
|
1755
|
+
type: "bytes32"
|
|
1784
1756
|
},
|
|
1785
1757
|
{
|
|
1786
|
-
internalType: "
|
|
1758
|
+
internalType: "bytes32",
|
|
1787
1759
|
name: "outputHash",
|
|
1788
|
-
type: "
|
|
1760
|
+
type: "bytes32"
|
|
1789
1761
|
},
|
|
1790
1762
|
{
|
|
1791
1763
|
internalType: "uint256",
|
|
@@ -1844,24 +1816,6 @@ var sepolia_default = {
|
|
|
1844
1816
|
stateMutability: "nonpayable",
|
|
1845
1817
|
type: "function"
|
|
1846
1818
|
},
|
|
1847
|
-
{
|
|
1848
|
-
inputs: [
|
|
1849
|
-
{
|
|
1850
|
-
internalType: "uint256",
|
|
1851
|
-
name: "epoch",
|
|
1852
|
-
type: "uint256"
|
|
1853
|
-
},
|
|
1854
|
-
{
|
|
1855
|
-
internalType: "address",
|
|
1856
|
-
name: "token",
|
|
1857
|
-
type: "address"
|
|
1858
|
-
}
|
|
1859
|
-
],
|
|
1860
|
-
name: "withdrawEpochFromSettlement",
|
|
1861
|
-
outputs: [],
|
|
1862
|
-
stateMutability: "nonpayable",
|
|
1863
|
-
type: "function"
|
|
1864
|
-
},
|
|
1865
1819
|
{
|
|
1866
1820
|
inputs: [],
|
|
1867
1821
|
name: "withdrawalLockupPeriod",
|
|
@@ -10677,6 +10631,20 @@ async function getWalletEIP712Domain(params) {
|
|
|
10677
10631
|
};
|
|
10678
10632
|
}
|
|
10679
10633
|
}
|
|
10634
|
+
async function validateConsumerSignature(params) {
|
|
10635
|
+
const { publicClient, walletAddress, tokenAddress, amount, providerAddress, deadline, signature, network = "sepolia" } = params;
|
|
10636
|
+
const walletAbi = getContractAbi("IATPWallet" /* IATP_WALLET */, network);
|
|
10637
|
+
if (!walletAbi) {
|
|
10638
|
+
throw new Error(`IATPWallet ABI not found for network: ${network}`);
|
|
10639
|
+
}
|
|
10640
|
+
const isValid = await publicClient.readContract({
|
|
10641
|
+
address: walletAddress,
|
|
10642
|
+
abi: walletAbi,
|
|
10643
|
+
functionName: "validateConsumerSignature",
|
|
10644
|
+
args: [tokenAddress, amount, providerAddress, deadline, signature]
|
|
10645
|
+
});
|
|
10646
|
+
return isValid;
|
|
10647
|
+
}
|
|
10680
10648
|
|
|
10681
10649
|
// src/wallet/withdrawals.ts
|
|
10682
10650
|
async function getWithdrawalRequest(params) {
|
|
@@ -11103,6 +11071,20 @@ async function getUnlockedBalanceForProvider(params) {
|
|
|
11103
11071
|
});
|
|
11104
11072
|
return balance;
|
|
11105
11073
|
}
|
|
11074
|
+
async function getProviderTotalDisputeInProgress(params) {
|
|
11075
|
+
const { publicClient, providerAddress, tokenAddress, network = "sepolia" } = params;
|
|
11076
|
+
const settlementConfig = getContractConfig("IATPSettlementLayer" /* IATP_SETTLEMENT_LAYER */, network);
|
|
11077
|
+
if (!settlementConfig) {
|
|
11078
|
+
throw new Error(`IATPSettlementLayer contract not found for network: ${network}`);
|
|
11079
|
+
}
|
|
11080
|
+
const amount = await publicClient.readContract({
|
|
11081
|
+
address: settlementConfig.address,
|
|
11082
|
+
abi: settlementConfig.abi,
|
|
11083
|
+
functionName: "providerTotalDisputeInProgress",
|
|
11084
|
+
args: [providerAddress, tokenAddress]
|
|
11085
|
+
});
|
|
11086
|
+
return amount;
|
|
11087
|
+
}
|
|
11106
11088
|
|
|
11107
11089
|
// src/settlement/operations.ts
|
|
11108
11090
|
async function withdrawAllAvailableEpochs(params) {
|
|
@@ -11168,6 +11150,7 @@ exports.getContractAddress = getContractAddress;
|
|
|
11168
11150
|
exports.getContractConfig = getContractConfig;
|
|
11169
11151
|
exports.getCurrentTimestamp = getCurrentTimestamp;
|
|
11170
11152
|
exports.getLockedBalanceForProvider = getLockedBalanceForProvider;
|
|
11153
|
+
exports.getProviderTotalDisputeInProgress = getProviderTotalDisputeInProgress;
|
|
11171
11154
|
exports.getUnlockedBalanceForProvider = getUnlockedBalanceForProvider;
|
|
11172
11155
|
exports.getUsdcAddress = getUsdcAddress;
|
|
11173
11156
|
exports.getWalletEIP712Domain = getWalletEIP712Domain;
|
|
@@ -11186,6 +11169,7 @@ exports.selectPaymentRequirement = selectPaymentRequirement;
|
|
|
11186
11169
|
exports.signD402Payment = signD402Payment;
|
|
11187
11170
|
exports.sortPaymentRequirements = sortPaymentRequirements;
|
|
11188
11171
|
exports.usdToUsdc = usdToUsdc;
|
|
11172
|
+
exports.validateConsumerSignature = validateConsumerSignature;
|
|
11189
11173
|
exports.withdrawAllAvailableEpochs = withdrawAllAvailableEpochs;
|
|
11190
11174
|
exports.withdrawAllFromSettlement = withdrawAllFromSettlement;
|
|
11191
11175
|
//# sourceMappingURL=index.js.map
|