Bitcoin PIR

SDK playground

Paste a Bitcoin address, pick a backend, hit Run query. We open a real WebSocket to wss://weikeng1.bitcoinpir.org / wss://weikeng2.bitcoinpir.org, attest the server binaries, run the query, and verify the per-bucket Merkle proofs. The right panel shows the equivalent TypeScript code your wallet would write to do the same.

Backend

Try:

Result

No query run yet. Pick a backend, paste an address, hit Run query.

What your wallet would write

TypeScript — drop into your wallet
// DPF-PIR — two servers, low-latency, batch scans.
// npm install pir-sdk-wasm

import init, { WasmDpfClient } from 'pir-sdk-wasm';
import { addressToScriptPubKey, scriptHash, hexToBytes }
  from 'bitcoin-pir-web';
import { AMD_TURIN_ARK_FINGERPRINT, PIR1_PIN, PIR2_TIER3_PIN }
  from 'bitcoin-pir-web/attest-pin';

await init();

const client = new WasmDpfClient(
  'wss://weikeng1.bitcoinpir.org',
  'wss://weikeng2.bitcoinpir.org',
);
await client.connect();

// Pinned-attestation (proves the server is running the binary the
// operator built — required before sending any query).
const att0 = await client.attest(0);
const att1 = await client.attest(1);
if (att1.binarySha256Hex !== PIR2_TIER3_PIN.binarySha256Hex) {
  throw new Error('pir2 binary pin mismatch');
}
if (att1.launchMeasurementHex !== PIR2_TIER3_PIN.measurementHex) {
  throw new Error('pir2 SEV-SNP MEASUREMENT pin mismatch');
}
att1.verifyVcekChain(AMD_TURIN_ARK_FINGERPRINT);  // AMD chain
await client.upgradeToSecureChannel(att0.serverStaticPub, att1.serverStaticPub);

// Address -> scripthash (HASH160 of scriptPubKey).
const spkHex = addressToScriptPubKey('bc1q…')!;
const sh = scriptHash(hexToBytes(spkHex));  // 20 bytes

// Query. Batch up to 8-16 addresses at once for amortised cost.
const packed = sh;  // for a single query
const [result] = await client.queryBatchRaw(packed, 0);

console.log('balance (sats):', result.totalBalance);
for (let i = 0; i < result.entryCount; i++) {
  const u = result.getEntry(i);
  console.log(`  ${u.txid}:${u.vout} = ${u.amountSats} sat`);
}

await client.disconnect();

Add PIR to your wallet in 5 minutes

  1. 1.npm install pir-sdk-wasm
  2. 2.Copy the snippet on the right into your wallet's sync path.
  3. 3.Pin attestation values from bitcoin-pir-web/attest-pin and refuse to query if the chain or pins fail.