gitmark 0.0.73 → 0.0.75
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/bin/git-mark.js +25 -3
- package/package.json +1 -1
- package/test/git-mark.test.js +13 -0
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();
|
|
@@ -335,6 +335,12 @@ async function cmdInit(args) {
|
|
|
335
335
|
const newTxid = await broadcastTx(rawTx, explorer);
|
|
336
336
|
|
|
337
337
|
savePrivateState({ txid: newTxid, vout: 0, amount: outputAmount }, chain);
|
|
338
|
+
const xonly = pubkey.slice(2); // 64-char x-only Nostr pubkey
|
|
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);
|
|
338
344
|
console.log(`Funded: ${outputAmount} sats (txid: ${newTxid})`);
|
|
339
345
|
}
|
|
340
346
|
|
|
@@ -434,6 +440,22 @@ async function cmdInfo() {
|
|
|
434
440
|
console.log(`Current address: ${currentAddr}`);
|
|
435
441
|
console.log(`Last commit: ${trail.states[trail.states.length - 1]}`);
|
|
436
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
|
+
}
|
|
437
459
|
}
|
|
438
460
|
if (priv) {
|
|
439
461
|
console.log(`Balance: ${priv.amount} sats`);
|
package/package.json
CHANGED
package/test/git-mark.test.js
CHANGED
|
@@ -189,6 +189,19 @@ describe('Trail format', () => {
|
|
|
189
189
|
assert.strictEqual(trail.states.length, trail.txo.length);
|
|
190
190
|
});
|
|
191
191
|
|
|
192
|
+
it('@id is valid txo URI with amount and 64-char x-only pubkey', () => {
|
|
193
|
+
const privkey = secp256k1.utils.randomPrivateKey();
|
|
194
|
+
const pubkey = bytesToHex(secp256k1.getPublicKey(privkey, true));
|
|
195
|
+
const xonly = pubkey.slice(2);
|
|
196
|
+
const txid = 'a'.repeat(64);
|
|
197
|
+
const id = `txo:tbtc4:${txid}:0?amount=14968&pubkey=${xonly}`;
|
|
198
|
+
const parsed = parseTxoUri(id);
|
|
199
|
+
assert.strictEqual(parsed.chain, 'tbtc4');
|
|
200
|
+
assert.strictEqual(parsed.txid, txid);
|
|
201
|
+
assert.strictEqual(parsed.amount, 14968);
|
|
202
|
+
assert.strictEqual(xonly.length, 64);
|
|
203
|
+
});
|
|
204
|
+
|
|
192
205
|
it('txo URIs include amount and commit params', () => {
|
|
193
206
|
const txoUri = 'txo:tbtc4:abc123:0?amount=9700&commit=deadbeef';
|
|
194
207
|
const parsed = parseTxoUri(txoUri);
|