dgb-wallet/packages/electrum/README.md
Digibyte.X d50286a9a5 DigiByte.X Wallet — recovery-first web wallet monorepo
Packages: core (BIP39/32/44/49/84/86 derivation, WIF), keystore (PBKDF2 +
AES-GCM), psbt, p2p (BIP157/158 SPV daemon, Dandelion++ broadcast with
relay-echo verification), blockbook, rpc, electrum, net, bns, web-ui
(React/Vite), mobile (Expo). ops/ holds the nginx vhost, systemd unit and
push.sh deploy script for digibyte.x/web.
2026-09-20 20:16:52 +02:00

51 lines
2.5 KiB
Markdown

# @dgb-wallet/electrum
Minimal DigiByte Electrum protocol client. TCP+TLS JSON-RPC to public Electrum-DGB servers for balance, UTXO listing, transaction broadcast, and chain tip. No API keys, no signup.
Positioned as a **Convenience-mode backend** in the wallet's privacy design (RESEARCH.md §10.6) — an Electrum server sees which addresses you query. For Maximum Privacy the wallet uses `@dgb-wallet/p2p` (BIP157/158 SPV) instead. Electrum still beats a single hosted Blockbook because you can distribute queries across many community-run servers with connection-per-server privacy.
## API
- `connectAny(servers, opts)` — try servers in order, return the first that connects and handshakes
- `getBalance(client, address)` — `{ confirmed, unconfirmed }` in satoshis
- `getBalances(client, addresses)` — parallelized bulk lookup over one connection
- `listUnspent(client, address)` — array of `{ txid, vout, value, height }`
- `broadcast(client, rawTxHex)` — returns txid or throws with server error
- `getChainTip(client)` — `{ height, headerHex }`
Handles both current DGB address format (`S...`) and legacy Bitcoin-compatible P2SH (`3...`) via `scripthashOf`, so recovery scans that scan both variants (per RESEARCH.md §10.7a) work transparently.
## Demo — real mainnet recovery scan
```bash
cd "D:\Dev\SilentCode\Digibyte"
npm install # first time only
npm run build -w @dgb-wallet/core
npm run demo -w @dgb-wallet/electrum
```
Connects to a public Electrum-DGB server, derives the public all-abandon BIP39 test seed's addresses at every path (BIP44, both BIP49 variants, BIP84, BIP86), and queries live balance for each. Fetches UTXOs for any address that has funds.
Run with your own seed (do NOT paste a seed protecting real funds anywhere but the wallet itself):
```bash
npm run demo -w @dgb-wallet/electrum -- "your twelve word seed phrase here"
```
## Public servers
`src/servers.ts` lists community-run peers. All unaffiliated with this project — availability varies. Update from the DigiByte community forums or `github.com/spesmilo/electrum-doc` when peers change.
## Layout
```
src/
servers.ts — known public DGB Electrum peers
client.ts — JSON-RPC over TCP+TLS, multi-server failover
scripthash.ts — address → Electrum scripthash (handles both DGB P2SH variants)
methods.ts — typed wrappers for common methods
index.ts — re-exports
scripts/
scan-seed-demo.ts — recover any seed, scan real mainnet, print balances & UTXOs
```