nansen-cli 1.14.0 → 1.16.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/CHANGELOG.md +21 -0
- package/README.md +1 -1
- package/package.json +2 -1
- package/src/api.js +107 -64
- package/src/chain-ids.js +2 -3
- package/src/cli.js +1 -1
- package/src/privy.js +359 -0
- package/src/schema.json +42 -2
- package/src/trading.js +290 -108
- package/src/transfer.js +151 -26
- package/src/wallet.js +112 -39
- package/src/walletconnect-trading.js +73 -9
- package/src/x402-svm.js +43 -24
package/src/x402-svm.js
CHANGED
|
@@ -268,28 +268,15 @@ function signEd25519(message, keypairHex) {
|
|
|
268
268
|
// ============= x402 Solana Payment =============
|
|
269
269
|
|
|
270
270
|
/**
|
|
271
|
-
* Build
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
* The facilitator is the fee payer (index 0), client signs at index 1.
|
|
275
|
-
*
|
|
276
|
-
* NOTE: This requires a recent blockhash from Solana RPC. For the initial implementation,
|
|
277
|
-
* we fetch it inline. In production, this should be cached.
|
|
271
|
+
* Build an unsigned Solana x402 payment transaction.
|
|
272
|
+
* Returns the serialized MessageV0 bytes and the full transaction bytes
|
|
273
|
+
* (with both signature slots as 64 zero bytes).
|
|
278
274
|
*
|
|
279
|
-
*
|
|
280
|
-
* @param {string} keypairHex - 128-char hex string (64 bytes: seed + pubkey)
|
|
281
|
-
* @param {string} walletAddress - Signer's Solana address (base58)
|
|
282
|
-
* @param {string} resource - Original request URL
|
|
283
|
-
* @param {string} recentBlockhash - Recent blockhash from Solana RPC (base58)
|
|
284
|
-
* @param {number} decimals - Token decimals (default 6 for USDC)
|
|
285
|
-
* @param {string} tokenProgram - Token program address (auto-detect if not provided)
|
|
286
|
-
* @returns {string} Base64-encoded PaymentPayload for Payment-Signature header
|
|
275
|
+
* Used by local-key signing (createSvmPaymentPayload) and Privy server wallet signing.
|
|
287
276
|
*/
|
|
288
|
-
export function
|
|
277
|
+
export function buildUnsignedSvmTransaction(
|
|
289
278
|
requirements,
|
|
290
|
-
keypairHex,
|
|
291
279
|
walletAddress,
|
|
292
|
-
resource,
|
|
293
280
|
recentBlockhash,
|
|
294
281
|
decimals = 6,
|
|
295
282
|
tokenProgram = TOKEN_PROGRAM,
|
|
@@ -356,7 +343,6 @@ export function createSvmPaymentPayload(
|
|
|
356
343
|
},
|
|
357
344
|
];
|
|
358
345
|
|
|
359
|
-
// Build MessageV0
|
|
360
346
|
const messageBytes = buildMessageV0({
|
|
361
347
|
feePayer: feePayerStr,
|
|
362
348
|
instructions,
|
|
@@ -364,17 +350,50 @@ export function createSvmPaymentPayload(
|
|
|
364
350
|
accounts: null,
|
|
365
351
|
});
|
|
366
352
|
|
|
353
|
+
// Build transaction: compact-u16(numSignatures) + signatures + message
|
|
354
|
+
// 2 signatures: [facilitator placeholder (64 zero bytes), client placeholder (64 zero bytes)]
|
|
355
|
+
const numSigs = encodeCompactU16(2);
|
|
356
|
+
const txBytes = Buffer.concat([
|
|
357
|
+
numSigs,
|
|
358
|
+
Buffer.alloc(64), // facilitator placeholder
|
|
359
|
+
Buffer.alloc(64), // client placeholder
|
|
360
|
+
messageBytes,
|
|
361
|
+
]);
|
|
362
|
+
|
|
363
|
+
return { messageBytes, txBase64: txBytes.toString('base64') };
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Build a signed Solana x402 payment transaction using a local Ed25519 keypair.
|
|
368
|
+
* Calls buildUnsignedSvmTransaction internally, then signs with the private key.
|
|
369
|
+
*
|
|
370
|
+
* @returns {string} Base64-encoded PaymentPayload JSON for Payment-Signature header
|
|
371
|
+
*/
|
|
372
|
+
export function createSvmPaymentPayload(
|
|
373
|
+
requirements,
|
|
374
|
+
keypairHex,
|
|
375
|
+
walletAddress,
|
|
376
|
+
resource,
|
|
377
|
+
recentBlockhash,
|
|
378
|
+
decimals = 6,
|
|
379
|
+
tokenProgram = TOKEN_PROGRAM,
|
|
380
|
+
) {
|
|
381
|
+
const { messageBytes } = buildUnsignedSvmTransaction(
|
|
382
|
+
requirements,
|
|
383
|
+
walletAddress,
|
|
384
|
+
recentBlockhash,
|
|
385
|
+
decimals,
|
|
386
|
+
tokenProgram,
|
|
387
|
+
);
|
|
388
|
+
|
|
367
389
|
// Sign: client signs the full message (with 0x80 version prefix already included)
|
|
368
390
|
const clientSignature = signEd25519(messageBytes, keypairHex);
|
|
369
391
|
|
|
370
|
-
//
|
|
371
|
-
// 2 signatures: [facilitator placeholder (64 zero bytes), client signature]
|
|
392
|
+
// Rebuild transaction with the real client signature at slot 1
|
|
372
393
|
const numSigs = encodeCompactU16(2);
|
|
373
|
-
const facilitatorPlaceholder = Buffer.alloc(64); // all zeros
|
|
374
|
-
|
|
375
394
|
const txBytes = Buffer.concat([
|
|
376
395
|
numSigs,
|
|
377
|
-
|
|
396
|
+
Buffer.alloc(64), // facilitator placeholder
|
|
378
397
|
clientSignature,
|
|
379
398
|
messageBytes,
|
|
380
399
|
]);
|