gitmark 0.0.74 → 0.0.76

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 (2) hide show
  1. package/bin/git-mark.js +43 -4
  2. package/package.json +1 -1
package/bin/git-mark.js CHANGED
@@ -194,7 +194,7 @@ function getHead() {
194
194
  function getPrivkey() {
195
195
  try { return gitExec('git config --local nostr.privkey'); } catch { return null; }
196
196
  }
197
- function setPrivkey(key) { gitExec(`git config --local nostr.privkey ${key}`); }
197
+ function setPrivkey(key) { gitExec(`git config --local nostr.privkey '${key}'`); }
198
198
  function isGitRoot() { return existsSync('.git'); }
199
199
 
200
200
  // --- Trail file helpers ---
@@ -218,13 +218,13 @@ function loadPrivateState() {
218
218
  }
219
219
  function savePrivateState(state, chain, head) {
220
220
  const txoUri = `txo:${chain}:${state.txid}:${state.vout}?amount=${state.amount}${head ? '&commit=' + head : ''}`;
221
- gitExec(`git config --local gitmark.txo ${txoUri}`);
221
+ gitExec(`git config --local gitmark.txo '${txoUri}'`);
222
222
  }
223
223
  function isDirty() {
224
224
  try { return gitExec('git config --local gitmark.dirty') !== 'false'; } catch { return true; }
225
225
  }
226
226
  function addGitNote(commitHash, note) {
227
- try { gitExec(`git notes add -f -m ${note} ${commitHash}`); } catch { /* ignore if no commits */ }
227
+ try { gitExec(`git notes add -f -m '${note}' '${commitHash}'`); } catch { /* ignore if no commits */ }
228
228
  }
229
229
  function loadTrailFromNotes() {
230
230
  const trail = loadTrail();
@@ -336,7 +336,11 @@ async function cmdInit(args) {
336
336
 
337
337
  savePrivateState({ txid: newTxid, vout: 0, amount: outputAmount }, chain);
338
338
  const xonly = pubkey.slice(2); // 64-char x-only Nostr pubkey
339
- trail['@id'] = `txo:${chain}:${newTxid}:0?amount=${outputAmount}&pubkey=${xonly}`;
339
+ // Insert @id first
340
+ const reordered = { '@id': `txo:${chain}:${newTxid}:0?amount=${outputAmount}&pubkey=${xonly}`, '@type': trail['@type'] };
341
+ for (const [k, v] of Object.entries(trail)) { if (k !== '@type') reordered[k] = v; }
342
+ Object.keys(trail).forEach(k => delete trail[k]);
343
+ Object.assign(trail, reordered);
340
344
  console.log(`Funded: ${outputAmount} sats (txid: ${newTxid})`);
341
345
  }
342
346
 
@@ -436,6 +440,41 @@ async function cmdInfo() {
436
440
  console.log(`Current address: ${currentAddr}`);
437
441
  console.log(`Last commit: ${trail.states[trail.states.length - 1]}`);
438
442
  console.log(`Last TXO: ${trail.txo[trail.txo.length - 1]}`);
443
+
444
+ // Check confirmation status of latest tx
445
+ const explorer = CHAINS[trail.chain]?.explorer;
446
+ if (explorer && priv) {
447
+ try {
448
+ const txResp = await fetch(`${explorer}/tx/${priv.txid}`);
449
+ if (txResp.ok) {
450
+ const txData = await txResp.json();
451
+ if (txData.status?.confirmed) {
452
+ console.log(`Status: ✓ confirmed (block ${txData.status.block_height})`);
453
+ } else {
454
+ console.log(`Status: ⏳ unconfirmed`);
455
+ }
456
+ }
457
+ } catch (e) {}
458
+
459
+ // Check chain depth safety
460
+ const numMarks = trail.states.length;
461
+ if (numMarks < 25) {
462
+ console.log(`Chain depth: safe (${numMarks} marks, under 25)`);
463
+ } else {
464
+ try {
465
+ const ancestorTxo = parseTxoUri(trail.txo[trail.txo.length - 24]);
466
+ const ancResp = await fetch(`${explorer}/tx/${ancestorTxo.txid}`);
467
+ if (ancResp.ok) {
468
+ const ancData = await ancResp.json();
469
+ if (ancData.status?.confirmed) {
470
+ console.log(`Chain depth: safe (ancestor at -24 confirmed)`);
471
+ } else {
472
+ console.log(`Chain depth: ⚠ ancestor at -24 unconfirmed`);
473
+ }
474
+ }
475
+ } catch (e) {}
476
+ }
477
+ }
439
478
  }
440
479
  if (priv) {
441
480
  console.log(`Balance: ${priv.amount} sats`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitmark",
3
- "version": "0.0.74",
3
+ "version": "0.0.76",
4
4
  "type": "module",
5
5
  "description": "Anchor git commits to Bitcoin via blocktrails",
6
6
  "main": "bin/git-mark.js",