@dcentralab/d402-client 0.3.14 → 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 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
  /**
@@ -56,8 +56,6 @@ interface PaymentAuthorization {
56
56
  validBefore: string;
57
57
  /** Unique nonce */
58
58
  nonce: `0x${string}`;
59
- /** Request path/resource */
60
- requestPath: string;
61
59
  }
62
60
  /**
63
61
  * Signed payment ready to send
@@ -448,7 +446,6 @@ declare class D402Client {
448
446
  * @param params.walletClient - Optional wallet client for signing (wagmi). If provided, uses walletClient.signTypedData
449
447
  * @param params.paymentRequirement - Payment requirements from 402 response
450
448
  * @param params.iatpWalletAddress - IATPWallet contract address (optional)
451
- * @param params.requestPath - API request path (optional, uses payment_requirements.resource if not provided)
452
449
  * @returns Signed payment ready to encode and send
453
450
  *
454
451
  * @example
@@ -473,7 +470,6 @@ declare function signD402Payment(params: {
473
470
  walletClient?: WalletClient;
474
471
  paymentRequirement: PaymentRequirement;
475
472
  iatpWalletAddress: `0x${string}`;
476
- requestPath?: string;
477
473
  d402Version?: number;
478
474
  }): Promise<SignedPayment>;
479
475
 
@@ -802,6 +798,33 @@ declare function getWalletEIP712Domain(params: {
802
798
  chainId: bigint;
803
799
  verifyingContract: Address;
804
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>;
805
828
 
806
829
  /**
807
830
  * IATPWallet withdrawal functions
@@ -1413,4 +1436,4 @@ declare class UnsupportedNetworkError extends PaymentError {
1413
1436
  constructor(network: string);
1414
1437
  }
1415
1438
 
1416
- 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
  /**
@@ -56,8 +56,6 @@ interface PaymentAuthorization {
56
56
  validBefore: string;
57
57
  /** Unique nonce */
58
58
  nonce: `0x${string}`;
59
- /** Request path/resource */
60
- requestPath: string;
61
59
  }
62
60
  /**
63
61
  * Signed payment ready to send
@@ -448,7 +446,6 @@ declare class D402Client {
448
446
  * @param params.walletClient - Optional wallet client for signing (wagmi). If provided, uses walletClient.signTypedData
449
447
  * @param params.paymentRequirement - Payment requirements from 402 response
450
448
  * @param params.iatpWalletAddress - IATPWallet contract address (optional)
451
- * @param params.requestPath - API request path (optional, uses payment_requirements.resource if not provided)
452
449
  * @returns Signed payment ready to encode and send
453
450
  *
454
451
  * @example
@@ -473,7 +470,6 @@ declare function signD402Payment(params: {
473
470
  walletClient?: WalletClient;
474
471
  paymentRequirement: PaymentRequirement;
475
472
  iatpWalletAddress: `0x${string}`;
476
- requestPath?: string;
477
473
  d402Version?: number;
478
474
  }): Promise<SignedPayment>;
479
475
 
@@ -802,6 +798,33 @@ declare function getWalletEIP712Domain(params: {
802
798
  chainId: bigint;
803
799
  verifyingContract: Address;
804
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>;
805
828
 
806
829
  /**
807
830
  * IATPWallet withdrawal functions
@@ -1413,4 +1436,4 @@ declare class UnsupportedNetworkError extends PaymentError {
1413
1436
  constructor(network: string);
1414
1437
  }
1415
1438
 
1416
- 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
@@ -97,8 +97,7 @@ var init_constants = __esm({
97
97
  { name: "provider", type: "address" },
98
98
  { name: "token", type: "address" },
99
99
  { name: "amount", type: "uint256" },
100
- { name: "deadline", type: "uint256" },
101
- { name: "requestPath", type: "string" }
100
+ { name: "deadline", type: "uint256" }
102
101
  ]
103
102
  };
104
103
  }
@@ -301,13 +300,8 @@ async function signD402Payment(params) {
301
300
  walletClient,
302
301
  paymentRequirement,
303
302
  iatpWalletAddress,
304
- requestPath,
305
303
  d402Version = 1
306
304
  } = params;
307
- let finalRequestPath = requestPath || paymentRequirement.resource || "/mcp";
308
- if (!finalRequestPath || finalRequestPath.trim() === "") {
309
- finalRequestPath = "/mcp";
310
- }
311
305
  const nonce = generateNonce();
312
306
  const now = getCurrentTimestamp();
313
307
  const validAfter = (now - 60).toString();
@@ -327,8 +321,7 @@ async function signD402Payment(params) {
327
321
  provider: paymentRequirement.payTo,
328
322
  token: paymentRequirement.asset,
329
323
  amount: BigInt(paymentRequirement.maxAmountRequired),
330
- deadline: BigInt(validBefore),
331
- requestPath: finalRequestPath
324
+ deadline: BigInt(validBefore)
332
325
  };
333
326
  let signature;
334
327
  if (walletClient) {
@@ -365,8 +358,7 @@ async function signD402Payment(params) {
365
358
  value: paymentRequirement.maxAmountRequired,
366
359
  validAfter,
367
360
  validBefore,
368
- nonce,
369
- requestPath: finalRequestPath
361
+ nonce
370
362
  }
371
363
  }
372
364
  };
@@ -1191,19 +1183,6 @@ var sepolia_default = {
1191
1183
  stateMutability: "view",
1192
1184
  type: "function"
1193
1185
  },
1194
- {
1195
- inputs: [],
1196
- name: "MAX_REQUEST_PATH_LENGTH",
1197
- outputs: [
1198
- {
1199
- internalType: "uint256",
1200
- name: "",
1201
- type: "uint256"
1202
- }
1203
- ],
1204
- stateMutability: "view",
1205
- type: "function"
1206
- },
1207
1186
  {
1208
1187
  inputs: [],
1209
1188
  name: "PROVIDER_ATTESTATION_TYPEHASH",
@@ -1516,11 +1495,6 @@ var sepolia_default = {
1516
1495
  name: "deadline",
1517
1496
  type: "uint256"
1518
1497
  },
1519
- {
1520
- internalType: "string",
1521
- name: "requestPath",
1522
- type: "string"
1523
- },
1524
1498
  {
1525
1499
  internalType: "bytes",
1526
1500
  name: "signature",
@@ -1612,11 +1586,6 @@ var sepolia_default = {
1612
1586
  name: "deadline",
1613
1587
  type: "uint256"
1614
1588
  },
1615
- {
1616
- internalType: "string",
1617
- name: "requestPath",
1618
- type: "string"
1619
- },
1620
1589
  {
1621
1590
  internalType: "bytes",
1622
1591
  name: "signature",
@@ -1761,11 +1730,6 @@ var sepolia_default = {
1761
1730
  name: "deadline",
1762
1731
  type: "uint256"
1763
1732
  },
1764
- {
1765
- internalType: "string",
1766
- name: "requestPath",
1767
- type: "string"
1768
- },
1769
1733
  {
1770
1734
  internalType: "bytes",
1771
1735
  name: "signature",
@@ -1786,14 +1750,14 @@ var sepolia_default = {
1786
1750
  {
1787
1751
  inputs: [
1788
1752
  {
1789
- internalType: "bytes",
1790
- name: "consumerSignature",
1791
- type: "bytes"
1753
+ internalType: "bytes32",
1754
+ name: "consumerSignatureHash",
1755
+ type: "bytes32"
1792
1756
  },
1793
1757
  {
1794
- internalType: "bytes",
1758
+ internalType: "bytes32",
1795
1759
  name: "outputHash",
1796
- type: "bytes"
1760
+ type: "bytes32"
1797
1761
  },
1798
1762
  {
1799
1763
  internalType: "uint256",
@@ -1852,24 +1816,6 @@ var sepolia_default = {
1852
1816
  stateMutability: "nonpayable",
1853
1817
  type: "function"
1854
1818
  },
1855
- {
1856
- inputs: [
1857
- {
1858
- internalType: "uint256",
1859
- name: "epoch",
1860
- type: "uint256"
1861
- },
1862
- {
1863
- internalType: "address",
1864
- name: "token",
1865
- type: "address"
1866
- }
1867
- ],
1868
- name: "withdrawEpochFromSettlement",
1869
- outputs: [],
1870
- stateMutability: "nonpayable",
1871
- type: "function"
1872
- },
1873
1819
  {
1874
1820
  inputs: [],
1875
1821
  name: "withdrawalLockupPeriod",
@@ -10685,6 +10631,20 @@ async function getWalletEIP712Domain(params) {
10685
10631
  };
10686
10632
  }
10687
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
+ }
10688
10648
 
10689
10649
  // src/wallet/withdrawals.ts
10690
10650
  async function getWithdrawalRequest(params) {
@@ -11194,6 +11154,7 @@ exports.selectPaymentRequirement = selectPaymentRequirement;
11194
11154
  exports.signD402Payment = signD402Payment;
11195
11155
  exports.sortPaymentRequirements = sortPaymentRequirements;
11196
11156
  exports.usdToUsdc = usdToUsdc;
11157
+ exports.validateConsumerSignature = validateConsumerSignature;
11197
11158
  exports.withdrawAllAvailableEpochs = withdrawAllAvailableEpochs;
11198
11159
  exports.withdrawAllFromSettlement = withdrawAllFromSettlement;
11199
11160
  //# sourceMappingURL=index.js.map