@1sat/wallet-toolbox 0.0.34 → 0.0.35

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.
@@ -378,15 +378,24 @@ export const sweepOrdinals = {
378
378
  }
379
379
  }
380
380
  await tx.sign();
381
- // Log signed transaction
381
+ // Log signed transaction details for debugging
382
+ const localTxid = tx.id("hex");
383
+ console.log(`[sweepOrdinals] === LOCAL SIGNED TX ===`);
384
+ console.log(`[sweepOrdinals] Local txid: ${localTxid}`);
382
385
  console.log(`[sweepOrdinals] Signed tx hex: ${tx.toHex()}`);
383
386
  // Extract unlocking scripts for signAction
384
387
  const spends = {};
388
+ console.log(`[sweepOrdinals] === UNLOCKING SCRIPTS FOR SIGNACTION ===`);
385
389
  for (let i = 0; i < tx.inputs.length; i++) {
386
390
  const txInput = tx.inputs[i];
387
391
  const inputOutpoint = `${txInput.sourceTXID}.${txInput.sourceOutputIndex}`;
388
392
  if (ourOutpoints.has(inputOutpoint)) {
389
- spends[i] = { unlockingScript: txInput.unlockingScript?.toHex() ?? "" };
393
+ const unlockHex = txInput.unlockingScript?.toHex() ?? "";
394
+ spends[i] = { unlockingScript: unlockHex };
395
+ console.log(` [${i}] ${inputOutpoint}: ${unlockHex.length} chars`);
396
+ }
397
+ else {
398
+ console.log(` [${i}] ${inputOutpoint}: (wallet input - not ours)`);
390
399
  }
391
400
  }
392
401
  // Complete the action with our signatures
@@ -397,6 +406,47 @@ export const sweepOrdinals = {
397
406
  if ("error" in signResult) {
398
407
  return { error: String(signResult.error) };
399
408
  }
409
+ // Debug: compare local vs signAction result
410
+ console.log(`[sweepOrdinals] === SIGN ACTION RESULT ===`);
411
+ console.log(`[sweepOrdinals] signAction txid: ${signResult.txid}`);
412
+ // Log broadcast results if available
413
+ if ("sendWithResults" in signResult) {
414
+ console.log(`[sweepOrdinals] sendWithResults:`, JSON.stringify(signResult.sendWithResults));
415
+ }
416
+ console.log(`[sweepOrdinals] Local txid (partial): ${localTxid}`);
417
+ console.log(`[sweepOrdinals] Note: TXIDs differ because local is partial (wallet input unsigned)`);
418
+ if (signResult.tx) {
419
+ // Parse returned BEEF to show final transaction structure
420
+ const returnedTx = Transaction.fromBEEF(signResult.tx);
421
+ console.log(`[sweepOrdinals] === FINAL TX STRUCTURE (broadcast) ===`);
422
+ console.log(`[sweepOrdinals] Final inputs (${returnedTx.inputs.length}):`);
423
+ let returnedInputSats = 0;
424
+ for (let i = 0; i < returnedTx.inputs.length; i++) {
425
+ const inp = returnedTx.inputs[i];
426
+ const sats = inp.sourceTransaction?.outputs[inp.sourceOutputIndex]?.satoshis ?? 0;
427
+ returnedInputSats += sats;
428
+ const isOurs = ourOutpoints.has(`${inp.sourceTXID}.${inp.sourceOutputIndex}`);
429
+ console.log(` [${i}] ${inp.sourceTXID?.slice(0, 8)}...:${inp.sourceOutputIndex} = ${sats} sats, unlock=${inp.unlockingScript?.toHex().length ?? 0} chars ${isOurs ? "(ours)" : "(wallet fee)"}`);
430
+ }
431
+ console.log(`[sweepOrdinals] Final outputs (${returnedTx.outputs.length}):`);
432
+ let returnedOutputSats = 0;
433
+ for (let i = 0; i < returnedTx.outputs.length; i++) {
434
+ const out = returnedTx.outputs[i];
435
+ returnedOutputSats += out.satoshis ?? 0;
436
+ console.log(` [${i}] ${out.satoshis} sats, script=${out.lockingScript?.toHex().length ?? 0} chars`);
437
+ }
438
+ const finalFee = returnedInputSats - returnedOutputSats;
439
+ console.log(`[sweepOrdinals] Final: Total in=${returnedInputSats}, Total out=${returnedOutputSats}, Fee=${finalFee} sats`);
440
+ console.log(`[sweepOrdinals] Final tx hex: ${returnedTx.toHex()}`);
441
+ console.log(`[sweepOrdinals] Final tx computed id: ${returnedTx.id("hex")}`);
442
+ // Check if fee seems too low (less than 1 sat/byte)
443
+ const txSize = returnedTx.toHex().length / 2;
444
+ const satPerByte = finalFee / txSize;
445
+ console.log(`[sweepOrdinals] Tx size: ${txSize} bytes, Fee rate: ${satPerByte.toFixed(2)} sat/byte`);
446
+ if (satPerByte < 0.5) {
447
+ console.warn(`[sweepOrdinals] WARNING: Fee rate seems very low!`);
448
+ }
449
+ }
400
450
  return {
401
451
  txid: signResult.txid,
402
452
  beef: signResult.tx ? Array.from(signResult.tx) : undefined,
@@ -569,6 +619,18 @@ export const sweepBsv21 = {
569
619
  if ("error" in signResult) {
570
620
  return { error: String(signResult.error) };
571
621
  }
622
+ // Submit to overlay service for indexing
623
+ if (signResult.tx) {
624
+ try {
625
+ const services = ctx.services;
626
+ const overlayResult = await services.overlay.submitBsv21(signResult.tx, tokenId);
627
+ console.log(`[sweepBsv21] Overlay submission result:`, overlayResult);
628
+ }
629
+ catch (overlayError) {
630
+ // Log but don't fail the sweep - tx is already broadcast
631
+ console.warn(`[sweepBsv21] Overlay submission failed:`, overlayError);
632
+ }
633
+ }
572
634
  return {
573
635
  txid: signResult.txid,
574
636
  beef: signResult.tx ? Array.from(signResult.tx) : undefined,
@@ -308,6 +308,17 @@ export const sendBsv21 = {
308
308
  if ("error" in signResult) {
309
309
  return { error: String(signResult.error) };
310
310
  }
311
+ // Submit to overlay service for indexing
312
+ if (signResult.tx && ctx.services) {
313
+ try {
314
+ const services = ctx.services;
315
+ const overlayResult = await services.overlay.submitBsv21(signResult.tx, tokenId);
316
+ console.log(`[sendBsv21] Overlay submission result:`, overlayResult);
317
+ }
318
+ catch (overlayError) {
319
+ console.warn(`[sendBsv21] Overlay submission failed:`, overlayError);
320
+ }
321
+ }
311
322
  return {
312
323
  txid: signResult.txid,
313
324
  rawtx: signResult.tx ? Utils.toHex(signResult.tx) : undefined,
@@ -444,6 +455,17 @@ export const purchaseBsv21 = {
444
455
  if ("error" in signResult) {
445
456
  return { error: String(signResult.error) };
446
457
  }
458
+ // Submit to overlay service for indexing
459
+ if (signResult.tx && ctx.services) {
460
+ try {
461
+ const services = ctx.services;
462
+ const overlayResult = await services.overlay.submitBsv21(signResult.tx, tokenId);
463
+ console.log(`[purchaseBsv21] Overlay submission result:`, overlayResult);
464
+ }
465
+ catch (overlayError) {
466
+ console.warn(`[purchaseBsv21] Overlay submission failed:`, overlayError);
467
+ }
468
+ }
447
469
  return {
448
470
  txid: signResult.txid,
449
471
  rawtx: signResult.tx ? Utils.toHex(signResult.tx) : undefined,
@@ -42,4 +42,25 @@ export declare class OverlayClient extends BaseClient {
42
42
  * Returns tokenId, symbol (from name), and icon for each active token.
43
43
  */
44
44
  getActiveBsv21Tokens(): Promise<Bsv21TokenInfo[]>;
45
+ /**
46
+ * Submit a transaction to the overlay service for indexing.
47
+ * @param beef - BEEF data as Uint8Array or number[]
48
+ * @param topics - Topic names to submit to (e.g., ["tm_tokenId"])
49
+ */
50
+ submit(beef: Uint8Array | number[], topics: string[]): Promise<{
51
+ status: string;
52
+ txid?: string;
53
+ message?: string;
54
+ }>;
55
+ /**
56
+ * Submit a BSV-21 token transaction to the overlay.
57
+ * Convenience method that formats the topic correctly.
58
+ * @param beef - BEEF data
59
+ * @param tokenId - Token ID (txid_vout format)
60
+ */
61
+ submitBsv21(beef: Uint8Array | number[], tokenId: string): Promise<{
62
+ status: string;
63
+ txid?: string;
64
+ message?: string;
65
+ }>;
45
66
  }
@@ -52,4 +52,29 @@ export class OverlayClient extends BaseClient {
52
52
  }
53
53
  return tokens;
54
54
  }
55
+ /**
56
+ * Submit a transaction to the overlay service for indexing.
57
+ * @param beef - BEEF data as Uint8Array or number[]
58
+ * @param topics - Topic names to submit to (e.g., ["tm_tokenId"])
59
+ */
60
+ async submit(beef, topics) {
61
+ const beefArray = beef instanceof Uint8Array ? Array.from(beef) : beef;
62
+ return this.request("/1sat/overlay/submit", {
63
+ method: "POST",
64
+ headers: {
65
+ "Content-Type": "application/octet-stream",
66
+ "X-Topics": JSON.stringify(topics),
67
+ },
68
+ body: new Blob([new Uint8Array(beefArray)]),
69
+ });
70
+ }
71
+ /**
72
+ * Submit a BSV-21 token transaction to the overlay.
73
+ * Convenience method that formats the topic correctly.
74
+ * @param beef - BEEF data
75
+ * @param tokenId - Token ID (txid_vout format)
76
+ */
77
+ async submitBsv21(beef, tokenId) {
78
+ return this.submit(beef, [`tm_${tokenId}`]);
79
+ }
55
80
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1sat/wallet-toolbox",
3
- "version": "0.0.34",
3
+ "version": "0.0.35",
4
4
  "description": "BSV wallet library extending @bsv/wallet-toolbox with 1Sat Ordinals protocol support",
5
5
  "author": "1Sat Team",
6
6
  "license": "MIT",