@ziongateway/sdk 0.1.7 → 0.1.8
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/ZionAgent.js +16 -8
- package/package.json +1 -1
package/dist/ZionAgent.js
CHANGED
|
@@ -167,7 +167,9 @@ class ZionAgent {
|
|
|
167
167
|
// Parse payment requirements
|
|
168
168
|
const requirements = await this.parsePaymentRequirements(initialResponse);
|
|
169
169
|
if (this.debug) {
|
|
170
|
-
|
|
170
|
+
// Log requirements but filter out undefined fields for cleaner output
|
|
171
|
+
const cleanRequirements = Object.fromEntries(Object.entries(requirements).filter(([_, v]) => v !== undefined));
|
|
172
|
+
console.log(`[ZionAgent] Payment requirements:`, cleanRequirements);
|
|
171
173
|
}
|
|
172
174
|
// Execute payment
|
|
173
175
|
let signature;
|
|
@@ -283,17 +285,24 @@ class ZionAgent {
|
|
|
283
285
|
console.log("[ZionAgent] Attempting Gasless Transaction via Kora...");
|
|
284
286
|
const assetMint = new web3_js_1.PublicKey(requirements.asset);
|
|
285
287
|
// 1. Get payer signer from Kora (this is the account paying gas)
|
|
286
|
-
|
|
287
|
-
|
|
288
|
+
let payerResponse;
|
|
289
|
+
try {
|
|
290
|
+
payerResponse = await this.koraClient.getPayerSigner();
|
|
291
|
+
}
|
|
292
|
+
catch (error) {
|
|
293
|
+
throw new Error(`Kora unreachable: ${error.message || "Unknown error"}`);
|
|
294
|
+
}
|
|
295
|
+
// Handle Kora API errors or invalid format
|
|
288
296
|
if (!payerResponse || !payerResponse.signer_address) {
|
|
289
|
-
|
|
297
|
+
const errorMsg = payerResponse?.message || "Invalid response format";
|
|
298
|
+
throw new Error(`Kora API error: ${errorMsg}`);
|
|
290
299
|
}
|
|
291
300
|
const feePayerAddress = payerResponse.signer_address;
|
|
292
301
|
const feePayer = new web3_js_1.PublicKey(feePayerAddress);
|
|
293
|
-
// 2. Build instructions
|
|
302
|
+
// 2. Build instructions
|
|
294
303
|
const instructions = await index_1.PaymentBuilder.createExactInstructions({
|
|
295
304
|
sender: this.wallet.publicKey.toBase58(),
|
|
296
|
-
recipient: requirements.payTo || requirements.recipient,
|
|
305
|
+
recipient: requirements.payTo || requirements.recipient,
|
|
297
306
|
amount: requirements.amount,
|
|
298
307
|
asset: requirements.asset,
|
|
299
308
|
connection: this.connection
|
|
@@ -340,7 +349,6 @@ class ZionAgent {
|
|
|
340
349
|
*/
|
|
341
350
|
async executePayment(requirements) {
|
|
342
351
|
const assetMint = new web3_js_1.PublicKey(requirements.asset);
|
|
343
|
-
// x402 v2 uses payTo, fallback to recipient for compatibility
|
|
344
352
|
const recipientAddress = requirements.payTo || requirements.recipient;
|
|
345
353
|
const recipient = new web3_js_1.PublicKey(recipientAddress);
|
|
346
354
|
const senderAta = await (0, spl_token_1.getAssociatedTokenAddress)(assetMint, this.wallet.publicKey);
|
|
@@ -367,7 +375,7 @@ class ZionAgent {
|
|
|
367
375
|
}
|
|
368
376
|
const instructions = await index_1.PaymentBuilder.createExactInstructions({
|
|
369
377
|
sender: this.wallet.publicKey.toBase58(),
|
|
370
|
-
recipient: recipientAddress,
|
|
378
|
+
recipient: recipientAddress,
|
|
371
379
|
amount: requirements.amount,
|
|
372
380
|
asset: requirements.asset,
|
|
373
381
|
connection: this.connection
|