@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.
Files changed (2) hide show
  1. package/dist/ZionAgent.js +16 -8
  2. 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
- console.log(`[ZionAgent] Payment requirements:`, requirements);
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
- const payerResponse = await this.koraClient.getPayerSigner();
287
- // Handle potential API format changes
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
- throw new Error("Kora API error: Invalid response format - missing signer_address");
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 (use payTo for x402 v2)
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, // v2 uses payTo
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, // Use the resolved address
378
+ recipient: recipientAddress,
371
379
  amount: requirements.amount,
372
380
  asset: requirements.asset,
373
381
  connection: this.connection
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziongateway/sdk",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "TypeScript SDK for Zion x402 Facilitator",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",