javascript-solid-server 0.0.134 → 0.0.135

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "javascript-solid-server",
3
- "version": "0.0.134",
3
+ "version": "0.0.135",
4
4
  "description": "A minimal, fast Solid server",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -311,6 +311,49 @@ export function createPayHandler(options = {}) {
311
311
  return reply.code(401).send({ error: 'NIP-98 authentication required' });
312
312
  }
313
313
  const didUri = pubkeyToDidNostr(pubkey);
314
+
315
+ // Auto-detect deposits to user's tweaked address (Phase 3)
316
+ if (payChains) {
317
+ try {
318
+ const kp = await loadOrCreateKeypair();
319
+ const utxos = await loadUtxos();
320
+ const ledger = await readLedger();
321
+ let credited = 0;
322
+
323
+ for (const chainId of payChains) {
324
+ const chain = CHAIN_REGISTRY[chainId];
325
+ const network = chainId === 'btc' ? 'mainnet' : (chainId === 'tbtc3' ? 'testnet' : 'testnet4');
326
+ const userAddr = btAddress(kp.pubkey, [didUri], network);
327
+
328
+ const resp = await fetch(`${chain.explorer}/address/${userAddr}/utxo`);
329
+ if (!resp.ok) continue;
330
+ const addrUtxos = await resp.json();
331
+
332
+ for (const u of addrUtxos) {
333
+ if (utxos.find(x => x.txid === u.txid && x.vout === u.vout)) continue;
334
+ // New UTXO — fetch tx for scriptpubkey, then auto-credit
335
+ let scriptpubkey = '';
336
+ try {
337
+ const txResp = await fetch(`${chain.explorer}/tx/${u.txid}`);
338
+ if (txResp.ok) {
339
+ const txData = await txResp.json();
340
+ scriptpubkey = txData.vout?.[u.vout]?.scriptpubkey || '';
341
+ }
342
+ } catch { /* best effort */ }
343
+ const currency = chain.unit;
344
+ credit(ledger, didUri, u.value, currency);
345
+ utxos.push({ txid: u.txid, vout: u.vout, amount: u.value, scriptpubkey, chain: chainId, tweak: didUri, spent: false });
346
+ credited += u.value;
347
+ }
348
+ }
349
+
350
+ if (credited > 0) {
351
+ await writeLedger(ledger);
352
+ await saveUtxos(utxos);
353
+ }
354
+ } catch { /* scan failure is non-fatal */ }
355
+ }
356
+
314
357
  const ledger = await readLedger();
315
358
  const response = {
316
359
  did: didUri,