@dcentralab/d402-client 0.3.9 → 0.3.11
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/LICENSE +22 -0
- package/dist/index.d.mts +41 -1
- package/dist/index.d.ts +41 -1
- package/dist/index.js +116 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +115 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -11
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Traia
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/dist/index.d.mts
CHANGED
|
@@ -636,6 +636,7 @@ interface WithdrawalRequest {
|
|
|
636
636
|
token: Address;
|
|
637
637
|
amount: bigint;
|
|
638
638
|
requestedAt: bigint;
|
|
639
|
+
unlockTime: bigint;
|
|
639
640
|
executed: boolean;
|
|
640
641
|
}
|
|
641
642
|
|
|
@@ -762,6 +763,45 @@ declare function getWalletsByOwner(params: {
|
|
|
762
763
|
network?: SupportedNetwork;
|
|
763
764
|
rpcUrl?: string;
|
|
764
765
|
}): Promise<Address[]>;
|
|
766
|
+
/**
|
|
767
|
+
* Get wallet info for debugging - includes owner, operator, and settlement layer addresses.
|
|
768
|
+
*
|
|
769
|
+
* @param params - Query parameters
|
|
770
|
+
* @param params.publicClient - Viem PublicClient
|
|
771
|
+
* @param params.walletAddress - IATPWallet contract address
|
|
772
|
+
* @param params.network - Network to query
|
|
773
|
+
* @returns Wallet info object
|
|
774
|
+
*/
|
|
775
|
+
declare function getWalletInfo(params: {
|
|
776
|
+
publicClient: PublicClient;
|
|
777
|
+
walletAddress: Address;
|
|
778
|
+
network?: SupportedNetwork;
|
|
779
|
+
}): Promise<{
|
|
780
|
+
owner: Address;
|
|
781
|
+
operator: Address;
|
|
782
|
+
settlementLayer: Address;
|
|
783
|
+
}>;
|
|
784
|
+
/**
|
|
785
|
+
* Get EIP-712 domain info for an IATPWallet - used for debugging signature issues.
|
|
786
|
+
*
|
|
787
|
+
* Reads the eip712Domain function from the wallet contract.
|
|
788
|
+
*
|
|
789
|
+
* @param params - Query parameters
|
|
790
|
+
* @param params.publicClient - Viem PublicClient
|
|
791
|
+
* @param params.walletAddress - IATPWallet contract address
|
|
792
|
+
* @param params.network - Network to query
|
|
793
|
+
* @returns EIP-712 domain info
|
|
794
|
+
*/
|
|
795
|
+
declare function getWalletEIP712Domain(params: {
|
|
796
|
+
publicClient: PublicClient;
|
|
797
|
+
walletAddress: Address;
|
|
798
|
+
network?: SupportedNetwork;
|
|
799
|
+
}): Promise<{
|
|
800
|
+
name: string;
|
|
801
|
+
version: string;
|
|
802
|
+
chainId: bigint;
|
|
803
|
+
verifyingContract: Address;
|
|
804
|
+
}>;
|
|
765
805
|
|
|
766
806
|
/**
|
|
767
807
|
* IATPWallet withdrawal functions
|
|
@@ -1336,4 +1376,4 @@ declare class UnsupportedNetworkError extends PaymentError {
|
|
|
1336
1376
|
constructor(network: string);
|
|
1337
1377
|
}
|
|
1338
1378
|
|
|
1339
|
-
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, getWalletsByOwner, getWithdrawalRequest, initMcpSession, isValidAddress, normalizeAddress, parseAllPaymentRequirements, parseMcpResponse, parseMoney, parsePaymentRequirement, requestWithdrawal, selectPaymentRequirement, signD402Payment, sortPaymentRequirements, usdToUsdc, withdrawAllAvailableEpochs };
|
|
1379
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -636,6 +636,7 @@ interface WithdrawalRequest {
|
|
|
636
636
|
token: Address;
|
|
637
637
|
amount: bigint;
|
|
638
638
|
requestedAt: bigint;
|
|
639
|
+
unlockTime: bigint;
|
|
639
640
|
executed: boolean;
|
|
640
641
|
}
|
|
641
642
|
|
|
@@ -762,6 +763,45 @@ declare function getWalletsByOwner(params: {
|
|
|
762
763
|
network?: SupportedNetwork;
|
|
763
764
|
rpcUrl?: string;
|
|
764
765
|
}): Promise<Address[]>;
|
|
766
|
+
/**
|
|
767
|
+
* Get wallet info for debugging - includes owner, operator, and settlement layer addresses.
|
|
768
|
+
*
|
|
769
|
+
* @param params - Query parameters
|
|
770
|
+
* @param params.publicClient - Viem PublicClient
|
|
771
|
+
* @param params.walletAddress - IATPWallet contract address
|
|
772
|
+
* @param params.network - Network to query
|
|
773
|
+
* @returns Wallet info object
|
|
774
|
+
*/
|
|
775
|
+
declare function getWalletInfo(params: {
|
|
776
|
+
publicClient: PublicClient;
|
|
777
|
+
walletAddress: Address;
|
|
778
|
+
network?: SupportedNetwork;
|
|
779
|
+
}): Promise<{
|
|
780
|
+
owner: Address;
|
|
781
|
+
operator: Address;
|
|
782
|
+
settlementLayer: Address;
|
|
783
|
+
}>;
|
|
784
|
+
/**
|
|
785
|
+
* Get EIP-712 domain info for an IATPWallet - used for debugging signature issues.
|
|
786
|
+
*
|
|
787
|
+
* Reads the eip712Domain function from the wallet contract.
|
|
788
|
+
*
|
|
789
|
+
* @param params - Query parameters
|
|
790
|
+
* @param params.publicClient - Viem PublicClient
|
|
791
|
+
* @param params.walletAddress - IATPWallet contract address
|
|
792
|
+
* @param params.network - Network to query
|
|
793
|
+
* @returns EIP-712 domain info
|
|
794
|
+
*/
|
|
795
|
+
declare function getWalletEIP712Domain(params: {
|
|
796
|
+
publicClient: PublicClient;
|
|
797
|
+
walletAddress: Address;
|
|
798
|
+
network?: SupportedNetwork;
|
|
799
|
+
}): Promise<{
|
|
800
|
+
name: string;
|
|
801
|
+
version: string;
|
|
802
|
+
chainId: bigint;
|
|
803
|
+
verifyingContract: Address;
|
|
804
|
+
}>;
|
|
765
805
|
|
|
766
806
|
/**
|
|
767
807
|
* IATPWallet withdrawal functions
|
|
@@ -1336,4 +1376,4 @@ declare class UnsupportedNetworkError extends PaymentError {
|
|
|
1336
1376
|
constructor(network: string);
|
|
1337
1377
|
}
|
|
1338
1378
|
|
|
1339
|
-
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, getWalletsByOwner, getWithdrawalRequest, initMcpSession, isValidAddress, normalizeAddress, parseAllPaymentRequirements, parseMcpResponse, parseMoney, parsePaymentRequirement, requestWithdrawal, selectPaymentRequirement, signD402Payment, sortPaymentRequirements, usdToUsdc, withdrawAllAvailableEpochs };
|
|
1379
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -10482,6 +10482,42 @@ async function createIATPWallet(params) {
|
|
|
10482
10482
|
};
|
|
10483
10483
|
}
|
|
10484
10484
|
init_utils();
|
|
10485
|
+
|
|
10486
|
+
// src/core/debug.ts
|
|
10487
|
+
var DEBUG_ENABLED = false;
|
|
10488
|
+
if (typeof window !== "undefined" && typeof localStorage !== "undefined") {
|
|
10489
|
+
try {
|
|
10490
|
+
DEBUG_ENABLED = localStorage.getItem("D402_DEBUG") === "true";
|
|
10491
|
+
} catch {
|
|
10492
|
+
}
|
|
10493
|
+
} else if (typeof process !== "undefined" && process.env) {
|
|
10494
|
+
DEBUG_ENABLED = process.env.D402_DEBUG === "true";
|
|
10495
|
+
}
|
|
10496
|
+
function debugGroup(category, title) {
|
|
10497
|
+
if (!DEBUG_ENABLED) {
|
|
10498
|
+
return {
|
|
10499
|
+
log: () => {
|
|
10500
|
+
},
|
|
10501
|
+
end: () => {
|
|
10502
|
+
}
|
|
10503
|
+
};
|
|
10504
|
+
}
|
|
10505
|
+
console.group(`[D402 ${category}] ${title}`);
|
|
10506
|
+
return {
|
|
10507
|
+
log: (msg, data) => {
|
|
10508
|
+
if (data !== void 0) {
|
|
10509
|
+
console.log(msg, data);
|
|
10510
|
+
} else {
|
|
10511
|
+
console.log(msg);
|
|
10512
|
+
}
|
|
10513
|
+
},
|
|
10514
|
+
end: () => {
|
|
10515
|
+
console.groupEnd();
|
|
10516
|
+
}
|
|
10517
|
+
};
|
|
10518
|
+
}
|
|
10519
|
+
|
|
10520
|
+
// src/wallet/queries.ts
|
|
10485
10521
|
async function getAvailableBalance(params) {
|
|
10486
10522
|
const { publicClient, walletAddress, tokenAddress, network = "sepolia" } = params;
|
|
10487
10523
|
const walletAbi = getContractAbi("IATPWallet" /* IATP_WALLET */, network);
|
|
@@ -10516,6 +10552,84 @@ async function getWalletsByOwner(params) {
|
|
|
10516
10552
|
});
|
|
10517
10553
|
return wallets;
|
|
10518
10554
|
}
|
|
10555
|
+
async function getWalletInfo(params) {
|
|
10556
|
+
const { publicClient, walletAddress, network = "sepolia" } = params;
|
|
10557
|
+
const walletAbi = getContractAbi("IATPWallet" /* IATP_WALLET */, network);
|
|
10558
|
+
if (!walletAbi) {
|
|
10559
|
+
throw new Error(`IATPWallet ABI not found for network: ${network}`);
|
|
10560
|
+
}
|
|
10561
|
+
const group = debugGroup("WALLET", `getWalletInfo ${walletAddress.slice(0, 10)}...`);
|
|
10562
|
+
try {
|
|
10563
|
+
const owner = await publicClient.readContract({
|
|
10564
|
+
address: walletAddress,
|
|
10565
|
+
abi: walletAbi,
|
|
10566
|
+
functionName: "owner",
|
|
10567
|
+
args: []
|
|
10568
|
+
});
|
|
10569
|
+
const operator = await publicClient.readContract({
|
|
10570
|
+
address: walletAddress,
|
|
10571
|
+
abi: walletAbi,
|
|
10572
|
+
functionName: "operatorAddress",
|
|
10573
|
+
args: []
|
|
10574
|
+
});
|
|
10575
|
+
const settlementLayer = await publicClient.readContract({
|
|
10576
|
+
address: walletAddress,
|
|
10577
|
+
abi: walletAbi,
|
|
10578
|
+
functionName: "settlementLayer",
|
|
10579
|
+
args: []
|
|
10580
|
+
});
|
|
10581
|
+
const result = { owner, operator, settlementLayer };
|
|
10582
|
+
group.log("=== WALLET INFO ===");
|
|
10583
|
+
group.log("Wallet Address:", walletAddress);
|
|
10584
|
+
group.log("Owner:", owner);
|
|
10585
|
+
group.log("Operator:", operator);
|
|
10586
|
+
group.log("Settlement Layer:", settlementLayer);
|
|
10587
|
+
group.end();
|
|
10588
|
+
return result;
|
|
10589
|
+
} catch (error) {
|
|
10590
|
+
group.log("Error querying wallet info:", error);
|
|
10591
|
+
group.end();
|
|
10592
|
+
throw error;
|
|
10593
|
+
}
|
|
10594
|
+
}
|
|
10595
|
+
async function getWalletEIP712Domain(params) {
|
|
10596
|
+
const { publicClient, walletAddress, network = "sepolia" } = params;
|
|
10597
|
+
const walletAbi = getContractAbi("IATPWallet" /* IATP_WALLET */, network);
|
|
10598
|
+
if (!walletAbi) {
|
|
10599
|
+
throw new Error(`IATPWallet ABI not found for network: ${network}`);
|
|
10600
|
+
}
|
|
10601
|
+
const group = debugGroup("WALLET", `getWalletEIP712Domain ${walletAddress.slice(0, 10)}...`);
|
|
10602
|
+
try {
|
|
10603
|
+
const result = await publicClient.readContract({
|
|
10604
|
+
address: walletAddress,
|
|
10605
|
+
abi: walletAbi,
|
|
10606
|
+
functionName: "eip712Domain",
|
|
10607
|
+
args: []
|
|
10608
|
+
});
|
|
10609
|
+
const domain = {
|
|
10610
|
+
name: result[1],
|
|
10611
|
+
version: result[2],
|
|
10612
|
+
chainId: result[3],
|
|
10613
|
+
verifyingContract: result[4]
|
|
10614
|
+
};
|
|
10615
|
+
group.log("=== EIP-712 DOMAIN FROM CONTRACT ===");
|
|
10616
|
+
group.log("Name:", domain.name);
|
|
10617
|
+
group.log("Version:", domain.version);
|
|
10618
|
+
group.log("Chain ID:", domain.chainId.toString());
|
|
10619
|
+
group.log("Verifying Contract:", domain.verifyingContract);
|
|
10620
|
+
group.end();
|
|
10621
|
+
return domain;
|
|
10622
|
+
} catch (error) {
|
|
10623
|
+
group.log("Error querying EIP-712 domain (may not be supported):", error);
|
|
10624
|
+
group.end();
|
|
10625
|
+
return {
|
|
10626
|
+
name: "IATPWallet",
|
|
10627
|
+
version: "1",
|
|
10628
|
+
chainId: BigInt(network === "sepolia" ? 11155111 : 42161),
|
|
10629
|
+
verifyingContract: walletAddress
|
|
10630
|
+
};
|
|
10631
|
+
}
|
|
10632
|
+
}
|
|
10519
10633
|
|
|
10520
10634
|
// src/wallet/withdrawals.ts
|
|
10521
10635
|
async function getWithdrawalRequest(params) {
|
|
@@ -10966,6 +11080,8 @@ exports.getCurrentTimestamp = getCurrentTimestamp;
|
|
|
10966
11080
|
exports.getLockedBalanceForProvider = getLockedBalanceForProvider;
|
|
10967
11081
|
exports.getUnlockedBalanceForProvider = getUnlockedBalanceForProvider;
|
|
10968
11082
|
exports.getUsdcAddress = getUsdcAddress;
|
|
11083
|
+
exports.getWalletEIP712Domain = getWalletEIP712Domain;
|
|
11084
|
+
exports.getWalletInfo = getWalletInfo;
|
|
10969
11085
|
exports.getWalletsByOwner = getWalletsByOwner;
|
|
10970
11086
|
exports.getWithdrawalRequest = getWithdrawalRequest;
|
|
10971
11087
|
exports.initMcpSession = initMcpSession;
|