#!/usr/bin/env node // qlock-verify.mjs: check a QLOCK record against the chain, trusting nobody but a Solana RPC node. // // npm i @noble/post-quantum @noble/hashes // node qlock-verify.mjs [--api https://qlock.lol] [--rpc https://api.mainnet-beta.solana.com] [--slot N] // // 1. reads the record (public key, proof, tx signature) from the API // 2. reads the transaction from the RPC: succeeded, signed + paid by the wallet, memo qlock:v1:: // 3. sha256(public key) must equal the memo's commitment // 4. the PQ signature must verify over "qlock:v1:bind\nwallet:\nscheme:" with context "qlock/v1" import { ml_dsa44, ml_dsa65 } from '@noble/post-quantum/ml-dsa.js'; import { slh_dsa_sha2_128s } from '@noble/post-quantum/slh-dsa.js'; import { sha256 } from '@noble/hashes/sha2.js'; import { bytesToHex } from '@noble/hashes/utils.js'; const SCHEMES = { 'ml-dsa-44': ml_dsa44, 'ml-dsa-65': ml_dsa65, 'slh-dsa-sha2-128s': slh_dsa_sha2_128s }; const MEMO_PROGRAM = 'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr'; const args = process.argv.slice(2); const opt = (k, d) => { const i = args.indexOf(k); return i >= 0 ? args[i + 1] : d; }; const wallet = args.find((a) => !a.startsWith('--') && !['--api', '--rpc', '--slot'].includes(args[args.indexOf(a) - 1])); const API = (opt('--api', 'https://qlock.lol')).replace(/\/$/, ''); const RPC = opt('--rpc', 'https://api.mainnet-beta.solana.com'); const SLOT = opt('--slot'); if (!wallet) { console.error('usage: node qlock-verify.mjs [--api URL] [--rpc URL] [--slot N]'); process.exit(2); } const enc = new TextEncoder(); const b64 = (s) => new Uint8Array(Buffer.from(s, 'base64')); let failed = 0; const check = (ok, msg) => { console.log(`${ok ? ' ok ' : ' FAIL '} ${msg}`); if (!ok) failed++; }; const view = await (await fetch(`${API}/api/registry/${wallet}${SLOT ? `?slot=${SLOT}` : ''}`)).json(); if (!view.bound) { console.log(`${wallet} has no QLOCK record${SLOT ? ` at or before slot ${SLOT}` : ''}.`); process.exit(1); } const r = view.current; console.log(`record #${r.n} (wallet record ${r.seq}) · ${r.scheme} · slot ${r.slot}\ntx ${r.signature}\n`); const res = await (await fetch(RPC, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'getTransaction', params: [r.signature, { encoding: 'jsonParsed', commitment: 'confirmed', maxSupportedTransactionVersion: 0 }] }) })).json(); const tx = res.result; check(Boolean(tx), 'transaction exists on chain'); if (!tx) process.exit(1); check(tx.meta.err === null, 'transaction succeeded'); check(tx.slot === r.slot, `slot matches (${tx.slot})`); const payer = tx.transaction.message.accountKeys[0]; check(payer.pubkey === wallet && payer.signer, 'the wallet is fee payer and signer'); const memos = tx.transaction.message.instructions.filter((ix) => ix.programId === MEMO_PROGRAM).map((ix) => ix.parsed); const memo = memos.find((m) => typeof m === 'string' && m.startsWith('qlock:v1:')); check(memo === `qlock:v1:${r.scheme}:${r.commitment}`, `memo on chain: ${memo}`); if (!r.publicKey) { check(false, 'public key published (only the fingerprint is on chain so far)'); process.exit(1); } const pk = b64(r.publicKey), proof = b64(r.proof), impl = SCHEMES[r.scheme]; check(bytesToHex(sha256(pk)) === r.commitment, 'sha256(public key) equals the on-chain commitment'); const statement = `qlock:v1:bind\nwallet:${wallet}\nscheme:${r.scheme}`; check(impl.verify(proof, enc.encode(statement), pk, { context: enc.encode('qlock/v1') }), `${r.scheme} signature over the statement verifies`); console.log(failed ? `\n${failed} check(s) failed.` : `\nVerified: ${wallet} committed to this ${r.scheme} key at slot ${r.slot}.`); process.exit(failed ? 1 : 0);