@dcentralab/d402-client 0.3.9 → 0.3.10

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.mjs CHANGED
@@ -10480,6 +10480,42 @@ async function createIATPWallet(params) {
10480
10480
  };
10481
10481
  }
10482
10482
  init_utils();
10483
+
10484
+ // src/core/debug.ts
10485
+ var DEBUG_ENABLED = false;
10486
+ if (typeof window !== "undefined" && typeof localStorage !== "undefined") {
10487
+ try {
10488
+ DEBUG_ENABLED = localStorage.getItem("D402_DEBUG") === "true";
10489
+ } catch {
10490
+ }
10491
+ } else if (typeof process !== "undefined" && process.env) {
10492
+ DEBUG_ENABLED = process.env.D402_DEBUG === "true";
10493
+ }
10494
+ function debugGroup(category, title) {
10495
+ if (!DEBUG_ENABLED) {
10496
+ return {
10497
+ log: () => {
10498
+ },
10499
+ end: () => {
10500
+ }
10501
+ };
10502
+ }
10503
+ console.group(`[D402 ${category}] ${title}`);
10504
+ return {
10505
+ log: (msg, data) => {
10506
+ if (data !== void 0) {
10507
+ console.log(msg, data);
10508
+ } else {
10509
+ console.log(msg);
10510
+ }
10511
+ },
10512
+ end: () => {
10513
+ console.groupEnd();
10514
+ }
10515
+ };
10516
+ }
10517
+
10518
+ // src/wallet/queries.ts
10483
10519
  async function getAvailableBalance(params) {
10484
10520
  const { publicClient, walletAddress, tokenAddress, network = "sepolia" } = params;
10485
10521
  const walletAbi = getContractAbi("IATPWallet" /* IATP_WALLET */, network);
@@ -10514,6 +10550,84 @@ async function getWalletsByOwner(params) {
10514
10550
  });
10515
10551
  return wallets;
10516
10552
  }
10553
+ async function getWalletInfo(params) {
10554
+ const { publicClient, walletAddress, network = "sepolia" } = params;
10555
+ const walletAbi = getContractAbi("IATPWallet" /* IATP_WALLET */, network);
10556
+ if (!walletAbi) {
10557
+ throw new Error(`IATPWallet ABI not found for network: ${network}`);
10558
+ }
10559
+ const group = debugGroup("WALLET", `getWalletInfo ${walletAddress.slice(0, 10)}...`);
10560
+ try {
10561
+ const owner = await publicClient.readContract({
10562
+ address: walletAddress,
10563
+ abi: walletAbi,
10564
+ functionName: "owner",
10565
+ args: []
10566
+ });
10567
+ const operator = await publicClient.readContract({
10568
+ address: walletAddress,
10569
+ abi: walletAbi,
10570
+ functionName: "operatorAddress",
10571
+ args: []
10572
+ });
10573
+ const settlementLayer = await publicClient.readContract({
10574
+ address: walletAddress,
10575
+ abi: walletAbi,
10576
+ functionName: "settlementLayer",
10577
+ args: []
10578
+ });
10579
+ const result = { owner, operator, settlementLayer };
10580
+ group.log("=== WALLET INFO ===");
10581
+ group.log("Wallet Address:", walletAddress);
10582
+ group.log("Owner:", owner);
10583
+ group.log("Operator:", operator);
10584
+ group.log("Settlement Layer:", settlementLayer);
10585
+ group.end();
10586
+ return result;
10587
+ } catch (error) {
10588
+ group.log("Error querying wallet info:", error);
10589
+ group.end();
10590
+ throw error;
10591
+ }
10592
+ }
10593
+ async function getWalletEIP712Domain(params) {
10594
+ const { publicClient, walletAddress, network = "sepolia" } = params;
10595
+ const walletAbi = getContractAbi("IATPWallet" /* IATP_WALLET */, network);
10596
+ if (!walletAbi) {
10597
+ throw new Error(`IATPWallet ABI not found for network: ${network}`);
10598
+ }
10599
+ const group = debugGroup("WALLET", `getWalletEIP712Domain ${walletAddress.slice(0, 10)}...`);
10600
+ try {
10601
+ const result = await publicClient.readContract({
10602
+ address: walletAddress,
10603
+ abi: walletAbi,
10604
+ functionName: "eip712Domain",
10605
+ args: []
10606
+ });
10607
+ const domain = {
10608
+ name: result[1],
10609
+ version: result[2],
10610
+ chainId: result[3],
10611
+ verifyingContract: result[4]
10612
+ };
10613
+ group.log("=== EIP-712 DOMAIN FROM CONTRACT ===");
10614
+ group.log("Name:", domain.name);
10615
+ group.log("Version:", domain.version);
10616
+ group.log("Chain ID:", domain.chainId.toString());
10617
+ group.log("Verifying Contract:", domain.verifyingContract);
10618
+ group.end();
10619
+ return domain;
10620
+ } catch (error) {
10621
+ group.log("Error querying EIP-712 domain (may not be supported):", error);
10622
+ group.end();
10623
+ return {
10624
+ name: "IATPWallet",
10625
+ version: "1",
10626
+ chainId: BigInt(network === "sepolia" ? 11155111 : 42161),
10627
+ verifyingContract: walletAddress
10628
+ };
10629
+ }
10630
+ }
10517
10631
 
10518
10632
  // src/wallet/withdrawals.ts
10519
10633
  async function getWithdrawalRequest(params) {
@@ -10940,6 +11054,6 @@ async function withdrawAllAvailableEpochs(params) {
10940
11054
  init_utils();
10941
11055
  init_errors();
10942
11056
 
10943
- export { ContractName, D402Client, Invalid402ResponseError, MissingRequestConfigError, PaymentAlreadyAttemptedError, PaymentAmountExceededError, PaymentError, PaymentVerificationError, UnsupportedNetworkError, UnsupportedSchemeError, buildMcpHeaders, buildToolCallPayload, createIATPWallet, createPaymentSelector, decodePayment, decodePaymentResponse, encodePayment, executeWithdrawal, extractToolResult, findMatchingPaymentRequirement, formatMoney, generateNonce, getAvailableBalance, getChain, getChainId, getContractAbi, getContractAddress, getContractConfig, getCurrentTimestamp, getLockedBalanceForProvider, getUnlockedBalanceForProvider, getUsdcAddress, getWalletsByOwner, getWithdrawalRequest, initMcpSession, isValidAddress, normalizeAddress, parseAllPaymentRequirements, parseMcpResponse, parseMoney, parsePaymentRequirement, requestWithdrawal, selectPaymentRequirement, signD402Payment, sortPaymentRequirements, usdToUsdc, withdrawAllAvailableEpochs };
11057
+ export { ContractName, D402Client, Invalid402ResponseError, MissingRequestConfigError, PaymentAlreadyAttemptedError, PaymentAmountExceededError, PaymentError, PaymentVerificationError, UnsupportedNetworkError, UnsupportedSchemeError, 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 };
10944
11058
  //# sourceMappingURL=index.mjs.map
10945
11059
  //# sourceMappingURL=index.mjs.map