@dcentralab/d402-client 0.3.0 → 0.3.3
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 +87 -65
- package/dist/index.d.ts +87 -65
- package/dist/index.js +30 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -33
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -10
- package/LICENSE +0 -22
package/dist/index.mjs
CHANGED
|
@@ -265,13 +265,6 @@ function getChainId(network) {
|
|
|
265
265
|
}
|
|
266
266
|
return chainId;
|
|
267
267
|
}
|
|
268
|
-
function findMatchingPaymentRequirement(requirements, scheme = "exact", network) {
|
|
269
|
-
return requirements.find((req) => {
|
|
270
|
-
const schemeMatches = req.scheme === scheme;
|
|
271
|
-
const networkMatches = !network || req.network === network;
|
|
272
|
-
return schemeMatches && networkMatches;
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
268
|
function usdToUsdc(usdAmount, decimals = 6) {
|
|
276
269
|
return parseMoney(usdAmount, decimals);
|
|
277
270
|
}
|
|
@@ -289,16 +282,6 @@ function isValidAddress(address) {
|
|
|
289
282
|
function normalizeAddress(address) {
|
|
290
283
|
return address.toLowerCase();
|
|
291
284
|
}
|
|
292
|
-
function decodePaymentResponse(header) {
|
|
293
|
-
try {
|
|
294
|
-
const binString = atob(header);
|
|
295
|
-
const bytes = Uint8Array.from(binString, (m) => m.codePointAt(0));
|
|
296
|
-
const decoded = new TextDecoder().decode(bytes);
|
|
297
|
-
return JSON.parse(decoded);
|
|
298
|
-
} catch (error) {
|
|
299
|
-
throw new Error(`Failed to decode payment response: ${error}`);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
285
|
var init_utils = __esm({
|
|
303
286
|
"src/core/utils.ts"() {
|
|
304
287
|
init_constants();
|
|
@@ -387,6 +370,7 @@ var init_signer = __esm({
|
|
|
387
370
|
var encoder_exports = {};
|
|
388
371
|
__export(encoder_exports, {
|
|
389
372
|
decodePayment: () => decodePayment,
|
|
373
|
+
decodePaymentResponse: () => decodePaymentResponse,
|
|
390
374
|
encodePayment: () => encodePayment,
|
|
391
375
|
safeBase64Decode: () => safeBase64Decode,
|
|
392
376
|
safeBase64Encode: () => safeBase64Encode
|
|
@@ -409,6 +393,14 @@ function decodePayment(encodedPayment) {
|
|
|
409
393
|
const jsonString = safeBase64Decode(encodedPayment);
|
|
410
394
|
return JSON.parse(jsonString);
|
|
411
395
|
}
|
|
396
|
+
function decodePaymentResponse(header) {
|
|
397
|
+
try {
|
|
398
|
+
const jsonString = safeBase64Decode(header);
|
|
399
|
+
return JSON.parse(jsonString);
|
|
400
|
+
} catch (error) {
|
|
401
|
+
throw new Error(`Failed to decode payment response: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
412
404
|
var init_encoder = __esm({
|
|
413
405
|
"src/payment/encoder.ts"() {
|
|
414
406
|
}
|
|
@@ -496,6 +488,13 @@ function sortPaymentRequirements(requirements, preferredNetwork) {
|
|
|
496
488
|
return 0;
|
|
497
489
|
});
|
|
498
490
|
}
|
|
491
|
+
function findMatchingPaymentRequirement(requirements, scheme = "exact", network) {
|
|
492
|
+
return requirements.find((req) => {
|
|
493
|
+
const schemeMatches = req.scheme === scheme;
|
|
494
|
+
const networkMatches = !network || req.network === network;
|
|
495
|
+
return schemeMatches && networkMatches;
|
|
496
|
+
});
|
|
497
|
+
}
|
|
499
498
|
|
|
500
499
|
// src/contracts/abis/sepolia.json
|
|
501
500
|
var sepolia_default = {
|
|
@@ -5106,6 +5105,20 @@ async function createIATPWallet(params) {
|
|
|
5106
5105
|
chainId: chain.id
|
|
5107
5106
|
};
|
|
5108
5107
|
}
|
|
5108
|
+
async function getAvailableBalance(params) {
|
|
5109
|
+
const { publicClient, walletAddress, tokenAddress, network = "sepolia" } = params;
|
|
5110
|
+
const walletConfig = getContractConfig("IATPWallet" /* IATP_WALLET */, network);
|
|
5111
|
+
if (!walletConfig) {
|
|
5112
|
+
throw new Error(`IATPWallet contract not found for network: ${network}`);
|
|
5113
|
+
}
|
|
5114
|
+
const balance = await publicClient.readContract({
|
|
5115
|
+
address: walletAddress,
|
|
5116
|
+
abi: walletConfig.abi,
|
|
5117
|
+
functionName: "getAvailableBalance",
|
|
5118
|
+
args: [tokenAddress]
|
|
5119
|
+
});
|
|
5120
|
+
return balance;
|
|
5121
|
+
}
|
|
5109
5122
|
async function getWalletsByOwner(params) {
|
|
5110
5123
|
const { ownerAddress, network = "sepolia", rpcUrl } = params;
|
|
5111
5124
|
const factoryConfig = getContractConfig("IATPWalletFactory" /* IATP_WALLET_FACTORY */, network);
|
|
@@ -5127,22 +5140,6 @@ async function getWalletsByOwner(params) {
|
|
|
5127
5140
|
return wallets;
|
|
5128
5141
|
}
|
|
5129
5142
|
|
|
5130
|
-
// src/wallet/queries.ts
|
|
5131
|
-
async function getAvailableBalance(params) {
|
|
5132
|
-
const { publicClient, walletAddress, tokenAddress, network = "sepolia" } = params;
|
|
5133
|
-
const walletConfig = getContractConfig("IATPWallet" /* IATP_WALLET */, network);
|
|
5134
|
-
if (!walletConfig) {
|
|
5135
|
-
throw new Error(`IATPWallet contract not found for network: ${network}`);
|
|
5136
|
-
}
|
|
5137
|
-
const balance = await publicClient.readContract({
|
|
5138
|
-
address: walletAddress,
|
|
5139
|
-
abi: walletConfig.abi,
|
|
5140
|
-
functionName: "getAvailableBalance",
|
|
5141
|
-
args: [tokenAddress]
|
|
5142
|
-
});
|
|
5143
|
-
return balance;
|
|
5144
|
-
}
|
|
5145
|
-
|
|
5146
5143
|
// src/wallet/withdrawals.ts
|
|
5147
5144
|
async function getWithdrawalRequest(params) {
|
|
5148
5145
|
const { publicClient, walletAddress, tokenAddress, network = "sepolia" } = params;
|