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.js +58 -3
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +58 -3
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +175 -1
- package/dist/index.d.ts +175 -1
- package/dist/index.js +236 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +222 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -1
package/dist/cli.js
CHANGED
|
@@ -436,6 +436,57 @@ var init_AgentWallet = __esm({
|
|
|
436
436
|
};
|
|
437
437
|
}
|
|
438
438
|
}
|
|
439
|
+
/**
|
|
440
|
+
* Pay for a service (transfer USDC to service provider)
|
|
441
|
+
*
|
|
442
|
+
* This is the main method for Agent-to-Agent payments.
|
|
443
|
+
* Returns payment data ready to submit to service API.
|
|
444
|
+
*
|
|
445
|
+
* @example
|
|
446
|
+
* ```typescript
|
|
447
|
+
* const wallet = new AgentWallet({ chain: 'base' });
|
|
448
|
+
*
|
|
449
|
+
* // Pay for Zen7 video service
|
|
450
|
+
* const payment = await wallet.payService({
|
|
451
|
+
* provider: '0xb8d6f2441e8f8dfB6288A74Cf73804cDd0484E0C',
|
|
452
|
+
* amount: 0.99,
|
|
453
|
+
* service: 'video_generation'
|
|
454
|
+
* });
|
|
455
|
+
*
|
|
456
|
+
* if (payment.success) {
|
|
457
|
+
* // Submit to service API
|
|
458
|
+
* await fetch('/v1/video/generate', {
|
|
459
|
+
* body: JSON.stringify({
|
|
460
|
+
* prompt: "...",
|
|
461
|
+
* payment: payment.paymentData // Ready to use!
|
|
462
|
+
* })
|
|
463
|
+
* });
|
|
464
|
+
* }
|
|
465
|
+
* ```
|
|
466
|
+
*/
|
|
467
|
+
async payService(params) {
|
|
468
|
+
const result = await this.transfer({
|
|
469
|
+
to: params.provider,
|
|
470
|
+
amount: params.amount
|
|
471
|
+
});
|
|
472
|
+
if (result.success && result.txHash) {
|
|
473
|
+
return {
|
|
474
|
+
success: true,
|
|
475
|
+
txHash: result.txHash,
|
|
476
|
+
explorerUrl: result.explorerUrl,
|
|
477
|
+
paymentData: {
|
|
478
|
+
method: "transfer",
|
|
479
|
+
chain: this.chain,
|
|
480
|
+
tx_hash: result.txHash
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
} else {
|
|
484
|
+
return {
|
|
485
|
+
success: false,
|
|
486
|
+
error: result.error
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
}
|
|
439
490
|
/**
|
|
440
491
|
* Get gas balance (ETH needed for transactions)
|
|
441
492
|
*/
|
|
@@ -1288,6 +1339,10 @@ init_chains();
|
|
|
1288
1339
|
// src/index.ts
|
|
1289
1340
|
init_chains();
|
|
1290
1341
|
|
|
1342
|
+
// src/x402/index.ts
|
|
1343
|
+
var import_ethers10 = require("ethers");
|
|
1344
|
+
init_chains();
|
|
1345
|
+
|
|
1291
1346
|
// src/cli.ts
|
|
1292
1347
|
var program = new import_commander.Command();
|
|
1293
1348
|
program.name("payment-agent").description("Blockchain payment infrastructure for AI Agents").version("0.1.0");
|
|
@@ -1405,7 +1460,7 @@ program.command("auth-request").description("Generate authorization request for
|
|
|
1405
1460
|
}
|
|
1406
1461
|
});
|
|
1407
1462
|
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) => {
|
|
1408
|
-
const { ethers:
|
|
1463
|
+
const { ethers: ethers11 } = await import("ethers");
|
|
1409
1464
|
const { getChain: getChain2 } = await Promise.resolve().then(() => (init_chains(), chains_exports));
|
|
1410
1465
|
const privateKey = options.privateKey || process.env.OWNER_PRIVATE_KEY;
|
|
1411
1466
|
if (!privateKey) {
|
|
@@ -1413,7 +1468,7 @@ program.command("sign-permit").description("Sign a permit (Owner uses this to au
|
|
|
1413
1468
|
process.exit(1);
|
|
1414
1469
|
}
|
|
1415
1470
|
const chainConfig = getChain2(options.chain);
|
|
1416
|
-
const wallet = new
|
|
1471
|
+
const wallet = new ethers11.Wallet(privateKey);
|
|
1417
1472
|
if (wallet.address.toLowerCase() !== options.owner.toLowerCase()) {
|
|
1418
1473
|
console.error(`Error: Private key doesn't match owner address`);
|
|
1419
1474
|
console.error(` Expected: ${options.owner}`);
|
|
@@ -1444,7 +1499,7 @@ program.command("sign-permit").description("Sign a permit (Owner uses this to au
|
|
|
1444
1499
|
deadline: parseInt(options.deadline)
|
|
1445
1500
|
};
|
|
1446
1501
|
const signature = await wallet.signTypedData(domain, types, message);
|
|
1447
|
-
const sig =
|
|
1502
|
+
const sig = ethers11.Signature.from(signature);
|
|
1448
1503
|
const permit = {
|
|
1449
1504
|
owner: options.owner,
|
|
1450
1505
|
value,
|