moltspay 0.2.9 → 0.3.0

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/cli.mjs CHANGED
@@ -415,6 +415,57 @@ var init_AgentWallet = __esm({
415
415
  };
416
416
  }
417
417
  }
418
+ /**
419
+ * Pay for a service (transfer USDC to service provider)
420
+ *
421
+ * This is the main method for Agent-to-Agent payments.
422
+ * Returns payment data ready to submit to service API.
423
+ *
424
+ * @example
425
+ * ```typescript
426
+ * const wallet = new AgentWallet({ chain: 'base' });
427
+ *
428
+ * // Pay for Zen7 video service
429
+ * const payment = await wallet.payService({
430
+ * provider: '0xb8d6f2441e8f8dfB6288A74Cf73804cDd0484E0C',
431
+ * amount: 0.99,
432
+ * service: 'video_generation'
433
+ * });
434
+ *
435
+ * if (payment.success) {
436
+ * // Submit to service API
437
+ * await fetch('/v1/video/generate', {
438
+ * body: JSON.stringify({
439
+ * prompt: "...",
440
+ * payment: payment.paymentData // Ready to use!
441
+ * })
442
+ * });
443
+ * }
444
+ * ```
445
+ */
446
+ async payService(params) {
447
+ const result = await this.transfer({
448
+ to: params.provider,
449
+ amount: params.amount
450
+ });
451
+ if (result.success && result.txHash) {
452
+ return {
453
+ success: true,
454
+ txHash: result.txHash,
455
+ explorerUrl: result.explorerUrl,
456
+ paymentData: {
457
+ method: "transfer",
458
+ chain: this.chain,
459
+ tx_hash: result.txHash
460
+ }
461
+ };
462
+ } else {
463
+ return {
464
+ success: false,
465
+ error: result.error
466
+ };
467
+ }
468
+ }
418
469
  /**
419
470
  * Get gas balance (ETH needed for transactions)
420
471
  */
@@ -1267,6 +1318,10 @@ init_chains();
1267
1318
  // src/index.ts
1268
1319
  init_chains();
1269
1320
 
1321
+ // src/x402/index.ts
1322
+ init_chains();
1323
+ import { ethers as ethers10 } from "ethers";
1324
+
1270
1325
  // src/cli.ts
1271
1326
  var program = new Command();
1272
1327
  program.name("payment-agent").description("Blockchain payment infrastructure for AI Agents").version("0.1.0");
@@ -1384,7 +1439,7 @@ program.command("auth-request").description("Generate authorization request for
1384
1439
  }
1385
1440
  });
1386
1441
  program.command("sign-permit").description("Sign a permit (Owner uses this to authorize Agent)").requiredOption("-o, --owner <address>", "Owner address").requiredOption("-s, --spender <address>", "Spender address (Agent)").requiredOption("-a, --amount <amount>", "Amount in USDC").requiredOption("-d, --deadline <timestamp>", "Deadline timestamp").requiredOption("-n, --nonce <nonce>", "Nonce from contract").option("-c, --chain <chain>", "Chain name", "base").option("-k, --private-key <key>", "Private key (or set OWNER_PRIVATE_KEY env)").action(async (options) => {
1387
- const { ethers: ethers10 } = await import("ethers");
1442
+ const { ethers: ethers11 } = await import("ethers");
1388
1443
  const { getChain: getChain2 } = await Promise.resolve().then(() => (init_chains(), chains_exports));
1389
1444
  const privateKey = options.privateKey || process.env.OWNER_PRIVATE_KEY;
1390
1445
  if (!privateKey) {
@@ -1392,7 +1447,7 @@ program.command("sign-permit").description("Sign a permit (Owner uses this to au
1392
1447
  process.exit(1);
1393
1448
  }
1394
1449
  const chainConfig = getChain2(options.chain);
1395
- const wallet = new ethers10.Wallet(privateKey);
1450
+ const wallet = new ethers11.Wallet(privateKey);
1396
1451
  if (wallet.address.toLowerCase() !== options.owner.toLowerCase()) {
1397
1452
  console.error(`Error: Private key doesn't match owner address`);
1398
1453
  console.error(` Expected: ${options.owner}`);
@@ -1423,7 +1478,7 @@ program.command("sign-permit").description("Sign a permit (Owner uses this to au
1423
1478
  deadline: parseInt(options.deadline)
1424
1479
  };
1425
1480
  const signature = await wallet.signTypedData(domain, types, message);
1426
- const sig = ethers10.Signature.from(signature);
1481
+ const sig = ethers11.Signature.from(signature);
1427
1482
  const permit = {
1428
1483
  owner: options.owner,
1429
1484
  value,