Custody model Attribution Verification & finality Exactly-once crediting BTC / XMR engines Links, webhooks, trust Hardening & assurance Live Demo
01
Custody Model

No spend keys on the box.
Root cannot move settled funds.

Each merchant gets a dedicated VPS. The gateway knows public data only: a receiving address per stablecoin network, a BTC xpub/zpub, an XMR address and private view key. Nothing on the server can sign a transaction, so a full compromise cannot drain what has already been paid.

Stablecoin payments land directly in the merchant's own address — no deposit address per invoice, no sweeping, no intermediate balance. The buyer pays the network fee; the merchant pays nothing to receive.

A key-material tripwire refuses to boot if anything that looks like a private key, seed, mnemonic or xprv appears in the settings.

What root can still do: redirect future payments by swapping an address, and forge webhooks. That is closed on the merchant side, not on the box — see section 06.
NetworkCredited atIdentity check
TRON (TRC-20)Solidified block (/walletsolidity)Genesis block
Ethereum (ERC-20)finalized (opt-in fast credit at safe under a cap)eth_chainId
BNB Smart Chainfinalizedeth_chainId
Solana (SPL)finalized commitmentgetGenesisHash
BitcoinConfigurable confirmations (default 1)Watch-only wallet
MoneroConfigurable confirmations (default 1)View-only wallet
02
Stablecoin Engine

One address, many invoices.
Attributed by exact amount.

Without per-invoice addresses, attribution needs another discriminator. Every open invoice is assigned a unique amount slot on top of the price: $25.00 becomes 25.0042 USDT. Slots are only ever added — the merchant always receives at least the full price.

  • 4 decimals by default: 99 concurrent invoices per exact price, typeable on every exchange withdrawal form we could verify. Overflow to 6 decimals: 9,999 per price.
  • Solana: Solana Pay URI with a per-invoice reference key, with the amount slot as fallback for wallets that drop it.
  • Slots are held for the 7-day late-payment window, so a late transfer can never be matched to a newer invoice.
  • Anything that does not match exactly (typically an exchange deducting its withdrawal fee) is recorded and queued with ranked candidate invoices — never dropped, never guessed. An optional underpayment tolerance auto-accepts only when exactly one invoice can be meant.
Peg guard: new checkouts pause automatically if USDT trades outside $0.985–$1.015, so the merchant never sells at a silent discount.
01
Signed link → interstitial
GET never allocates anything (link previews, mail scanners). Only the buyer's POST creates the invoice.
02
Network picker
Networks in the merchant's order, each with what the buyer pays in fees. Solana appears only once the merchant's token account is confirmed to exist.
03
Slot allocated
Unique amount reserved under a partial UNIQUE index, inside BEGIN IMMEDIATE.
04
Detected → verified
Primary provider detects; an independent verifier proves it final (section 03).
05
Credited once → webhook
Payment row, invoice transition and outbox event in one transaction (section 04).
03
Provider Trust

One provider detects.
Another must prove it.

lib/evm_common.php — verify() (excerpt)
// Runs on the VERIFIER, never the detecting provider.
if (($err = $this->chainIdError($ep)) !== null) {
    return VerifyOutcome::pending($err);   // wrong network
}
$r   = rpc_call($ep, 'eth_getTransactionReceipt', [$t->txid]);
$fin = $this->header($ep, 'finalized')['number'];

if ($status !== '0x1') {
    return VerifyOutcome::rejected('not a successful transfer');
}
if ($claimedHash !== $bh) {         // reorg or disagreement
    return $final ? VerifyOutcome::pending('disagreement')
                  : VerifyOutcome::rejected('reorg');
}
// Canonical block at that height must be the receipt's block
if ($this->header($ep, $bn)['hash'] !== $bh) { /* … */ }

// Pinned token contract, recipient by raw bytes, exact value
$found = EvmCodec::transfersInLogs($logs, $n['token'], [$t->toAddress]);

Public RPC providers are the softest part of any non-custodial gateway: a lying or compromised endpoint can invent a transfer. Detection and verification are therefore split across two operators, enforced at boot by registrable domain (Public Suffix List) plus declared operator labels.

A transfer is credited only when the verifier independently confirms:

  • the network identity (chain id / genesis hash);
  • the pinned token contract or mint — not a look-alike token;
  • execution succeeded and the recipient matches by raw bytes;
  • the block is final and canonical at its height;
  • it agrees with the detection on block, log index and amount.

Disagreements are logged as SECURITY events and never credited. Provider timestamps in the future are refused. Every outbound call goes through one hardened client: https only, verified TLS, no redirects, size and time caps after decompression, per-host backoff on 429.

04
Atomicity & Arithmetic

Exactly once.
In integers, end to end.

There is one path to "paid". The watcher, a buyer-submitted txid, a dashboard lookup and a manual assignment all converge on it, and none of them can create a payment row without a verified transfer.

  • Idempotent ingest: INSERT OR IGNORE keyed on (chain, txid, log_index) — a transfer seen twice is recorded once.
  • Optimistic transition: the invoice update is conditional on its previous status and paid_atomic; a lost race changes nothing and emits nothing.
  • Transactional outbox: payment row, invoice transition and webhook event commit in one BEGIN IMMEDIATE transaction. Delivery happens afterwards, at-least-once, with event_id and a per-invoice sequence for consumer-side dedupe and ordering.
  • Crash consistency: fault injection at 11 kill points between insert, attribution, transition and delivery; invariants re-checked after each.
No floats on the money path: amounts are bcmath decimal strings in atomic units end to end — 6 decimals on TRON/Ethereum/Solana, 18 on BSC, beyond 64-bit range. A token-level static rule fails the build on any float literal, (float) cast or round() in pricing, matching and receipt code.
engine.php — the only path to paid (excerpt)
function engine_record_transfer(PDO $db, VerifiedTransfer $t): string
{
  return db_transaction($db, function () use ($db, $t) {
    $ins = $db->prepare('INSERT OR IGNORE INTO payments …');
    $ins->execute([…]);
    if ($ins->rowCount() !== 1) {
      return 'duplicate';       // recorded by someone else
    }
    $match = engine_match_transfer($db, $t);
    if ($match === null) {
      unmatched_enqueue($db, …);  // review queue, never dropped
      return 'unmatched';
    }
    engine_attach_payment($db, …);
    return 'matched';
  });
}

// inside engine_attach_payment():
$upd = $db->prepare('UPDATE invoices SET status = ?, paid_atomic = ?, …
                      WHERE id = ? AND status = ? AND paid_atomic = ?');
if ($upd->rowCount() !== 1) {
  return [];   // lost a race: the winner emitted the events
}
05
Bitcoin & Monero Engines

A fresh address per invoice.
Derived from public keys only.

config.php — electrum_exec() (excerpt)
// argv array: proc_open() executes the binary directly.
// No shell is ever spawned, so nothing can be parsed as one.
$argv = [BTC_ELECTRUM_CMD, '--dir', BTC_WALLET_DIR,
         '-w', BTC_WALLET_FILE, $sub];
foreach ($args as $a) { $argv[] = (string)$a; }

$proc = proc_open($argv, $desc, $pipes);
// non-blocking pipes + hard deadline (BTC_ELECTRUM_TIMEOUT)

// watcher.php — first writer wins, webhook fires once
$upd = $db->prepare('UPDATE invoices SET status = "paid", …
                      WHERE id = ? AND status != "paid"');
$wasFirst = ($upd->rowCount() === 1);
if ($wasFirst) { trigger_noctyra_webhook(…); }

Bitcoin: a watch-only Electrum wallet restored from the merchant's xpub/zpub derives a new BIP32 address per invoice. Payment is matched per UTXO with its confirmation depth (btc_match_utxos), not an address balance, so unconfirmed value can never satisfy the threshold.

Monero: monero-wallet-rpc listens on loopback only and is provisioned by the deploy script from the address and private view key — a view-only wallet. Each invoice gets a new subaddress from create_address; payments are matched from get_transfers against the stored invoice address. Subaddresses are unlinkable on-chain.

Amounts are priced once from the market rate, then compared as atomic integers — satoshis (10⁸) and piconeros (10¹²) — with a strict >=. Views, polls and creation are HMAC-gated and rate-limited per IP, as in section 06.

Spend-capable XMR wallets: operators who choose one get an auto-sweep to a cold address whose keys never touched the server, bounding exposure to turnover since the last sweep.
06
Signed Links, Webhooks, Residual Trust

Trust the signature.
Then verify the destination.

Checkout links (v2) are HMAC-SHA256 under an HKDF-derived subkey over key id, issue time, expiry, cents, order id, asset, offered chains and per-chain address fingerprints. If the gateway's configured address differs from the merchant's own record, checkout is refused before a buyer sees it. A newer link can replace an unpaid invoice; an older one never can.

Invoice views require a per-invoice HMAC view token; a wrong token is a plain 404, compared with hash_equals(). Stablecoin invoice ids are random 96-bit values; on BTC/XMR the token alone gates each sequential id, so there is nothing to enumerate.

Webhooks carry X-Noctyra-Signature: sha256=… over timestamp.body with a separate WEBHOOK_SECRET; two signatures during rotation; max-age checking against replay.

Closing the root-compromise gap: the merchant library's assertPaidToMerchant() checks every webhook against the merchant's own stored addresses (deriving the Solana token account itself), and an off-box canary compares the addresses the gateway serves with the merchant's records.
NoctyraStableClient.php — link signing
$kid = substr(hash_hmac('sha256', 'noctyra/key-id/v1', $secret), 0, 8);
$key = hash_hkdf('sha256', $secret, 32, 'noctyra/checkout-link/v2');

// v2|kid|iat|exp|cents|order|asset|chains|fingerprints
$canonical = 'v2|' . $kid . '|' . $iat . '|' . $exp . '|' . $usdCents
           . '|' . $orderId . '|' . $asset . '|' . implode(',', $chains)
           . '|' . $fpList;
$sig = hash_hmac('sha256', $canonical, $key);

// fingerprint = the merchant's own idea of each address
substr(hash('sha256', 'noctyra-addr-fp|v1|' . $chain . '|'
       . normalizeAddress($chain, $address)), 0, 16);

// merchant side, before releasing goods:
if (!$client->verifyWebhook($body, $sig, $ts)) { http_response_code(401); exit; }
$client->assertPaidToMerchant($event, MY_ADDRESSES);
07
Hardening & Assurance

Defence in depth.
Measured, not asserted.

LayerControl
BrowserNonce-only CSP (no unsafe-inline), SRI on every script and stylesheet, self-hosted fonts and QR library — no third-party origin on any page that displays an address. no-store, noindex, COOP/CORP, HSTS.
Edgenginx serves an allowlist of entry points; everything else is a bare 404. limit_req per endpoint before PHP is reached; per-IP (IPv6 /64) application rate limits behind trusted-proxy CIDRs only.
RuntimeHardened PHP-FPM pool (open_basedir, disabled exec functions, no uploads); systemd units with sandboxing (exposure score ≤ 2.0); root-owned releases the service user cannot modify.
DashboardArgon2id, mandatory TOTP with one-time recovery codes, __Host- session cookie rotated after 2FA, CSRF + Sec-Fetch-Site, IP allowlist, lockout without account enumeration, full audit log. Signed, replay-proof pull API.
OperationsMonitor with Telegram/email alerts, external address canary, encrypted backups to an off-box key (libsodium), restore drill, settings validated before a release is switched in.
0
PHPStan findings
level max, strict
0
Psalm taint findings
HTML, SQL, shell, header sinks
89%
Mutation score
Infection, covered code
283
Hostile HTTP requests
in the security sweep

Plus an adversarial provider matrix on all four networks, crash consistency at 11 kill points, 60,000 seeded parser mutations per target, load and concurrency tests, and a real root deploy (nginx, PHP-FPM, systemd) in CI. The internal review is OWASP ASVS 4.0.3 Level 2; an independent audit is recommended before significant volume.

Your keys. Your server.
Your settlement.

One VPS per merchant, deployed and hardened in a single command. Try a real payment first, or talk to us about your stack.