@dcentralab/d402-client 0.3.15 → 0.3.16
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 +29 -2
- package/dist/index.d.ts +29 -2
- package/dist/index.js +20 -51
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -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
|
|
@@ -1409,4 +1436,4 @@ declare class UnsupportedNetworkError extends PaymentError {
|
|
|
1409
1436
|
constructor(network: string);
|
|
1410
1437
|
}
|
|
1411
1438
|
|
|
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 };
|
|
1439
|
+
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, 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
|
|
@@ -1409,4 +1436,4 @@ declare class UnsupportedNetworkError extends PaymentError {
|
|
|
1409
1436
|
constructor(network: string);
|
|
1410
1437
|
}
|
|
1411
1438
|
|
|
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 };
|
|
1439
|
+
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, 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) {
|
|
@@ -11186,6 +11154,7 @@ exports.selectPaymentRequirement = selectPaymentRequirement;
|
|
|
11186
11154
|
exports.signD402Payment = signD402Payment;
|
|
11187
11155
|
exports.sortPaymentRequirements = sortPaymentRequirements;
|
|
11188
11156
|
exports.usdToUsdc = usdToUsdc;
|
|
11157
|
+
exports.validateConsumerSignature = validateConsumerSignature;
|
|
11189
11158
|
exports.withdrawAllAvailableEpochs = withdrawAllAvailableEpochs;
|
|
11190
11159
|
exports.withdrawAllFromSettlement = withdrawAllFromSettlement;
|
|
11191
11160
|
//# sourceMappingURL=index.js.map
|