#!/usr/bin/env node /** * JesusOS BTC V4 · ORIGINAL Termux watch-only wallet ledger. * Strictly read-only, no spending, wallet/key creation, signing or mining. * Uses only the existing BIP84 PUBLIC account xpub, NEVER private keys/seeds. * Optional --network opt-in: sends ONLY derived public addresses to two * independent BTC explorers; displays agreement, NOT consensus verified funds. * Neither explorer nor Floot/JesusOS receives xpub, seed, keys or tokens. */ import fs from 'node:fs'; import path from 'node:path'; import {HDKey} from '@scure/bip32'; import {bech32} from '@scure/base'; import {sha256} from '@noble/hashes/sha2.js'; import {ripemd160} from '@noble/hashes/legacy.js'; import {createInterface} from 'node:readline/promises'; const HOME=process.env.HOME||''; const dir=path.join(HOME,'jesusos-sovereign-wallet'); const manifest=path.join(dir,'watch.json'); const basePath="m/84'/0'/0'"; const providers=[ {name:'Mempool.space',base:'https://mempool.space'}, {name:'Blockstream Esplora',base:'https://blockstream.info'} ]; const MAX_ISSUED=20; const MAX_SATS=21000000*100000000; function safeNumber(value,max=MAX_SATS){ return Number.isSafeInteger(value)&&value>=0&&value<=max; } function address(account,branch,index){ if(![0,1].includes(branch)||!safeNumber(index,100000))throw Error('Unexpected BIP84 derivation path'); const child=account.derive('m/'+branch+'/'+index); if(!child.publicKey||child.publicKey.length!==33)throw Error('Invalid compressed BIP84 public key'); return bech32.encode('bc',[0,...bech32.toWords(ripemd160(sha256(child.publicKey)))]); } function originalWallet(){ if(!HOME||HOME==='/')throw Error('Original Termux HOME unavailable'); let dirStat,st; try{dirStat=fs.lstatSync(dir);st=fs.lstatSync(manifest)} catch(e){ if(e.code==='ENOENT')return null; throw e; } if(!dirStat.isDirectory()||dirStat.isSymbolicLink()||(dirStat.mode&0o077)!==0)throw Error('Original wallet folder is not owner-only'); if(!st.isFile()||st.isSymbolicLink()||(st.mode&0o077)!==0||st.size>8192)throw Error('Original watch-only wallet manifest is not owner-only'); const d=JSON.parse(fs.readFileSync(manifest,'utf8')); if(d.schema!=='jesusos.btc.watchonly.bip84.v1'||d.path!==basePath||d.network!=='mainnet'|| !safeNumber(d.nextIndex,999999)||d.nextIndex<1||typeof d.accountXpub!=='string'|| !/^xpub[A-Za-z0-9]{100,120}$/.test(d.accountXpub))throw Error('Unrecognized original Bitcoin watch-only manifest'); const account=HDKey.fromExtendedKey(d.accountXpub); if(account.privateKey||address(account,0,0)!==d.firstAddress)throw Error('Bitcoin mainnet first address fails BIP84/xpub verification'); return {d,account}; } function ranges({d,account}){ const issued=d.nextIndex; if(issued>MAX_ISSUED)throw Error('Original wallet has '+issued+' issued receive addresses; scanner V4 handles at most '+MAX_ISSUED+'. NO incomplete wallet total claimed.'); const all=[]; for(let i=0;i32768)throw Error('Oversized explorer data'); const str=await res.text(); if(str.length>32768)throw Error('Oversized explorer data'); return parseStats(JSON.parse(str),address); } async function inspectEntries(entries){ const observed=[]; let sum=0; let confirmedAddresses=0; for(const item of entries){ const outcome=await Promise.all(providers.map(async p=>{ try{return{provider:p.name,data:await fetchReport(p.base,item.address)}} catch(e){return{provider:p.name,error:e instanceof Error?e.message:'unavailable'}} })); const a=outcome[0],b=outcome[1]; if(!a.data||!b.data){ observed.push({...item,state:'UNVERIFIED',reason:outcome.map(x=>x.error?x.provider+': '+x.error:'').filter(Boolean).join('; ')}); continue; } const agree=a.data.confirmed===b.data.confirmed&&a.data.txCount===b.data.txCount; if(!agree){ observed.push({...item,state:'DISAGREE',reason:'Public explorers disagree on confirmed address value or transaction count; no amount credited'}); continue; } observed.push({...item,state:'CORROBORATED',confirmed:a.data.confirmed,confirmedTx:a.data.txCount, pendingAgreement:a.data.mempoolDelta===b.data.mempoolDelta, pendingDelta:a.data.mempoolDelta===b.data.mempoolDelta?a.data.mempoolDelta:null}); sum+=a.data.confirmed;confirmedAddresses++; } return{observed,reportedTotal:confirmedAddresses===entries.length?sum:null,checked:confirmedAddresses,requested:entries.length}; } function showAudit(wallet,entries){ console.log('=== JesusOS MAIN Bitcoin watch-only V4 · original Android Termux ==='); console.log('HeavenCoin, mining reporter, local status 3340: NOT MODIFIED.'); console.log('No keys, seeds, passwords, transactions, or mining processes touched.'); if(!wallet){ console.log('WALLET NOT ACTIVATED: watch.json absent from original device.'); console.log('Use the existing JesusOS V2 owner wallet activation; do not invent or paste recovery words here.'); return; } console.log('Original Bitcoin mainnet BIP84 public account: VERIFIED ON THIS DEVICE.'); console.log('Local handwritten backup verified: '+(wallet.d.backupVerifiedAt?'YES (device record)':'NOT YET RECORDED')); console.log('Original first public receive address: '+wallet.d.firstAddress); console.log('Issued receiving addresses included: '+wallet.d.nextIndex); console.log("Internal change address m/84'/0'/0'/1/0 included: YES."); console.log('Wallet account xpub: NOT SHOWN, NOT TRANSMITTED.'); for(const e of entries)console.log('LOCAL',e.type+'['+e.index+']',e.address,'('+e.derivation+')'); console.log('Offline derivation is NOT a wallet balance, ownership proof, spendability check, or confirmation of mined BTC.'); } async function network(wallet,entries){ if(!wallet){console.log('No original wallet exists. No network requests made.');return} if(!process.stdin.isTTY)throw Error('Network opt-in requires an interactive original Termux terminal'); console.log('\nNETWORK OPT-IN: public receiving/change addresses will be sent to Mempool.space and Blockstream.'); console.log('Public explorers can associate these addresses with your device/IP and with one another.'); console.log('They do NOT receive your seed or xpub; the JesusOS/Floot server receives NO query.'); console.log('This is not a full-node consensus audit or a mining-pool payment receipt.'); const rl=createInterface({input:process.stdin,output:process.stdout}); let answer; try{answer=(await rl.question('Type CHECK-PUBLIC-ADDRESSES to perform bounded read-only explorer queries: ')).trim()} finally{rl.close()} if(answer!=='CHECK-PUBLIC-ADDRESSES'){console.log('CANCELLED. No public addresses transmitted.');return} const results=await inspectEntries(entries); for(const r of results.observed){ console.log(r.type+'['+r.index+'] '+r.address+' '+r.state); if(r.state==='CORROBORATED'){ console.log(' Two explorers report '+r.confirmed+' confirmed sats and '+r.confirmedTx+' confirmed transactions.'); console.log(r.pendingAgreement? ' Both report the same pending net change '+r.pendingDelta+' sats.' : ' Unconfirmed mempool views differ; not counted as confirmed funds.'); }else console.log(' '+r.reason); } if(results.reportedTotal===null){ console.log('COMPLETE TOTAL: UNAVAILABLE — '+results.checked+'/'+results.requested+' addresses corroborated. No wallet-total assertion.'); }else{ console.log('EXPLORER-AGREED confirmed value across '+results.requested+' scanned addresses: '+results.reportedTotal+' sats.'); console.log('This is ONLY a limited external-reported tally. It may omit other wallet paths, unknown address indices, prior change, or Bitcoin chain reorganizations.'); } console.log('No auto-polling, keys, blockchain consensus verification, BTC payout claim or on-chain spending.'); } const arg=process.argv[2]||'--audit'; try{ const wallet=originalWallet(); const entries=wallet?ranges(wallet):[]; if(arg==='--audit')showAudit(wallet,entries); else if(arg==='--network'){showAudit(wallet,entries);await network(wallet,entries)} else console.log('JesusOS BTC V4 watch-only commands: --audit (offline) | --network (interactive opt-in).'); }catch(e){ console.error('JesusOS BTC watch-only V4 STOPPED: '+(e instanceof Error?e.message:'unknown error')); process.exitCode=2; }