From d5e55c9c577feb6f8000bad3c37045a2cd7c9b4c Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 23 Jun 2026 23:05:52 -0700 Subject: Add QR scanner to the send page (lazy-loaded decoder) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Scan a Bitcoin address, a BIP21 URI (fills address + amount), or a signed-transaction QR (opens a broadcast confirmation, then relays it) from a viewfinder button on the Send form. Decoder strategy keeps the main bundle small: - Prefer the native BarcodeDetector (Chrome desktop/Android) — no lib. - Otherwise lazy-load jsQR from a separate dist/jsqr.js, only when the scanner is opened. jsQR stays out of index.html (~424 KB vs ~551 KB) and off the initial load. - The service worker precaches jsqr.js so offline scanning works for installed PWAs on browsers without BarcodeDetector. The scanner needs a camera + secure context, so it never shows on a standalone file:// page; offline air-gapped signing is unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/wallet.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/wallet.js') diff --git a/src/wallet.js b/src/wallet.js index 7152d31..2547b45 100644 --- a/src/wallet.js +++ b/src/wallet.js @@ -577,6 +577,25 @@ export class Wallet { return this.api.broadcast(hexTx); } + // Parse a raw (signed) transaction hex — used by scan-to-broadcast to show a + // confirmation (txid + outputs) before relaying someone's exported tx. + parseRawTx(rawHex) { + const tx = btc.Transaction.fromRaw(hex.decode(rawHex.trim()), { allowUnknownOutputs: true }); + const network = NETS[this.netName].net; + const outputs = []; + let total = 0; + for (let i = 0; i < tx.outputsLength; i++) { + const o = tx.getOutput(i); + total += Number(o.amount); + let address = ''; + try { + address = btc.Address(network).encode(btc.OutScript.decode(o.script)); + } catch {} + outputs.push({ address, value: Number(o.amount) }); + } + return { txid: tx.id, total, outputs }; + } + // --- realtime (mempool.space WebSocket) --------------------------------- // Pushes us new mempool/confirmed transactions for our addresses so history // and balances update with no polling. -- cgit v1.2.3