memeputer 1.1.3 → 1.2.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.
Files changed (52) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/LICENSE +22 -0
  3. package/README.md +2 -2
  4. package/dist/__tests__/config.test.d.ts +2 -0
  5. package/dist/__tests__/config.test.d.ts.map +1 -0
  6. package/dist/__tests__/config.test.js +40 -0
  7. package/dist/__tests__/config.test.js.map +1 -0
  8. package/dist/__tests__/formatting.test.d.ts +2 -0
  9. package/dist/__tests__/formatting.test.d.ts.map +1 -0
  10. package/dist/__tests__/formatting.test.js +57 -0
  11. package/dist/__tests__/formatting.test.js.map +1 -0
  12. package/dist/__tests__/wallet.test.d.ts +2 -0
  13. package/dist/__tests__/wallet.test.d.ts.map +1 -0
  14. package/dist/__tests__/wallet.test.js +30 -0
  15. package/dist/__tests__/wallet.test.js.map +1 -0
  16. package/dist/commands/agents.js +2 -2
  17. package/dist/commands/agents.js.map +1 -1
  18. package/dist/commands/balance.js +1 -1
  19. package/dist/commands/balance.js.map +1 -1
  20. package/dist/commands/command.d.ts.map +1 -1
  21. package/dist/commands/command.js +56 -9
  22. package/dist/commands/command.js.map +1 -1
  23. package/dist/commands/prompt.d.ts +3 -0
  24. package/dist/commands/prompt.d.ts.map +1 -0
  25. package/dist/commands/{ask.js → prompt.js} +19 -10
  26. package/dist/commands/prompt.js.map +1 -0
  27. package/dist/index.js +5 -3
  28. package/dist/index.js.map +1 -1
  29. package/dist/lib/config.d.ts.map +1 -1
  30. package/dist/lib/config.js +18 -8
  31. package/dist/lib/config.js.map +1 -1
  32. package/dist/utils/formatting.d.ts +2 -0
  33. package/dist/utils/formatting.d.ts.map +1 -1
  34. package/dist/utils/formatting.js +13 -1
  35. package/dist/utils/formatting.js.map +1 -1
  36. package/package.json +22 -18
  37. package/vitest.config.ts +9 -0
  38. package/dist/commands/ask.d.ts +0 -3
  39. package/dist/commands/ask.d.ts.map +0 -1
  40. package/dist/commands/ask.js.map +0 -1
  41. package/dist/commands/pfp.d.ts +0 -3
  42. package/dist/commands/pfp.d.ts.map +0 -1
  43. package/dist/commands/pfp.js +0 -99
  44. package/dist/commands/pfp.js.map +0 -1
  45. package/dist/lib/api.d.ts +0 -56
  46. package/dist/lib/api.d.ts.map +0 -1
  47. package/dist/lib/api.js +0 -160
  48. package/dist/lib/api.js.map +0 -1
  49. package/dist/lib/x402Client.d.ts +0 -14
  50. package/dist/lib/x402Client.d.ts.map +0 -1
  51. package/dist/lib/x402Client.js +0 -105
  52. package/dist/lib/x402Client.js.map +0 -1
@@ -1,105 +0,0 @@
1
- import { ComputeBudgetProgram, TransactionMessage, VersionedTransaction, } from "@solana/web3.js";
2
- import { getAssociatedTokenAddress, createTransferCheckedInstruction, createAssociatedTokenAccountInstruction, TOKEN_PROGRAM_ID, } from "@solana/spl-token";
3
- import { PublicKey } from "@solana/web3.js";
4
- // USDC mint on Solana mainnet
5
- const USDC_MINT = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
6
- /**
7
- * Create a simple USDC payment transaction (for CLI use)
8
- * This creates a signed transaction that can be sent in the X-PAYMENT header
9
- */
10
- export async function createPaymentTransaction(connection, payer, recipient, amountUsdc, scheme = "exact", network = "solana") {
11
- try {
12
- const recipientPubkey = new PublicKey(recipient);
13
- // Convert USDC amount to micro-USDC (6 decimals)
14
- const amount = Math.floor(amountUsdc * 1_000_000);
15
- // Get token accounts (allowOwnerOffCurve fixes wallet adapter key issues)
16
- const payerTokenAccount = await getAssociatedTokenAddress(USDC_MINT, payer.publicKey, true, // allowOwnerOffCurve - critical for wallet adapter keys!
17
- TOKEN_PROGRAM_ID);
18
- const recipientTokenAccount = await getAssociatedTokenAddress(USDC_MINT, recipientPubkey, true, // allowOwnerOffCurve - critical for wallet adapter keys!
19
- TOKEN_PROGRAM_ID);
20
- // Build instructions array
21
- const instructions = [];
22
- // Add ComputeBudget instructions FIRST (required by facilitator!)
23
- instructions.push(ComputeBudgetProgram.setComputeUnitLimit({
24
- units: 40_000,
25
- }));
26
- instructions.push(ComputeBudgetProgram.setComputeUnitPrice({
27
- microLamports: 1,
28
- }));
29
- // Check if recipient token account exists, if not create it
30
- const recipientAccountInfo = await connection.getAccountInfo(recipientTokenAccount);
31
- if (!recipientAccountInfo) {
32
- console.log(` 📝 Recipient token account doesn't exist, will create it`);
33
- instructions.push(createAssociatedTokenAccountInstruction(payer.publicKey, // payer
34
- recipientTokenAccount, // ata
35
- recipientPubkey, // owner
36
- USDC_MINT, // mint
37
- TOKEN_PROGRAM_ID));
38
- }
39
- // Add the transfer instruction (use checked version like agent-to-agent payments)
40
- instructions.push(createTransferCheckedInstruction(payerTokenAccount, USDC_MINT, recipientTokenAccount, payer.publicKey, amount, 6, // USDC has 6 decimals
41
- [], TOKEN_PROGRAM_ID));
42
- // Get recent blockhash
43
- const { blockhash } = await connection.getLatestBlockhash("confirmed");
44
- // Set facilitator as fee payer for gas-free transactions!
45
- const facilitatorPublicKey = new PublicKey("2wKupLR9q6wXYppw8Gr2NvWxKBUqm4PPJKkQfoxHDBg4");
46
- // Create VersionedTransaction (x402 standard)
47
- const message = new TransactionMessage({
48
- payerKey: facilitatorPublicKey,
49
- recentBlockhash: blockhash,
50
- instructions,
51
- }).compileToV0Message();
52
- const transaction = new VersionedTransaction(message);
53
- // Find which signature slot corresponds to the user's public key
54
- // The facilitator is at index 0 (fee payer), user is at a different index
55
- const userPubkey = payer.publicKey;
56
- const staticAccountKeys = transaction.message.staticAccountKeys;
57
- const userSignatureIndex = staticAccountKeys.findIndex((key) => key.equals(userPubkey));
58
- // Sign with user's wallet (facilitator will add its signature)
59
- transaction.sign([payer]);
60
- // Serialize transaction
61
- const serialized = transaction.serialize();
62
- const serializedTx = Buffer.from(serialized).toString("base64");
63
- // Extract the user's signature from the correct slot (bs58 encoded)
64
- const bs58 = await import("bs58");
65
- const userSignature = userSignatureIndex >= 0 &&
66
- transaction.signatures?.[userSignatureIndex] &&
67
- !transaction.signatures[userSignatureIndex].every((b) => b === 0)
68
- ? bs58.default.encode(transaction.signatures[userSignatureIndex])
69
- : undefined;
70
- // Create X-PAYMENT header in x402 format (minimal format matching agent-to-agent)
71
- // This matches the exact format from @payai/x402-solana
72
- const paymentPayload = {
73
- x402Version: 1,
74
- scheme: scheme,
75
- network: network,
76
- payload: {
77
- transaction: serializedTx,
78
- signature: userSignature, // Include signature for reference (optional)
79
- },
80
- };
81
- // Encode as base64
82
- const paymentHeader = Buffer.from(JSON.stringify(paymentPayload)).toString("base64");
83
- return { transaction, signature: paymentHeader };
84
- }
85
- catch (error) {
86
- console.error("Error creating payment transaction:", error);
87
- throw new Error(`Failed to create payment: ${error instanceof Error ? error.message : String(error)}`);
88
- }
89
- }
90
- /**
91
- * Get USDC balance for a wallet
92
- */
93
- export async function getUsdcBalance(connection, keypair) {
94
- try {
95
- const tokenAccount = await getAssociatedTokenAddress(USDC_MINT, keypair.publicKey, true, // allowOwnerOffCurve - critical for wallet adapter keys!
96
- TOKEN_PROGRAM_ID);
97
- const balance = await connection.getTokenAccountBalance(tokenAccount);
98
- return parseFloat(balance.value.uiAmount?.toString() || "0");
99
- }
100
- catch (error) {
101
- // Token account doesn't exist or other error
102
- return 0;
103
- }
104
- }
105
- //# sourceMappingURL=x402Client.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"x402Client.js","sourceRoot":"","sources":["../../src/lib/x402Client.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,oBAAoB,EAEpB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,yBAAyB,EACzB,gCAAgC,EAChC,uCAAuC,EACvC,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,8BAA8B;AAC9B,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,8CAA8C,CAAC,CAAC;AAEhF;;;G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