THAMER
Sovereign Bitcoin Wallet

WALLET AI BITCOIN

Your Bitcoin Wallet. Your Keys. Your Engine.

Self-hosted Bitcoin software built for developers, applications, and AI agents.

CREATE WALLET

Bitcoin Invoice Agents: Exact Satoshi Amount Validation

permalink THAMER
#ai-agents#bitcoin#commerce#wab-engine

Bitcoin Invoice Agents: Exact Satoshi Amount Validation

Research question

Avoid floating-point arithmetic when interpreting Bitcoin-denominated invoice amounts.

Architecture and trust boundary

Separate the model, business ledger, operator authorization and local wallet executor. The model may propose an action but cannot establish financial evidence or grant itself permission. Keep BTC KEY out of prompts, browser contexts and business logs. A restricted tool does not turn the underlying credential into a restricted key.

Source implementation

Python · 17 lines
1import re
2
3def btc_to_sat(text):
4    if not isinstance(text,str) or not re.fullmatch(r'[0-9]{1,8}(\.[0-9]{1,8})?',text):
5        raise ValueError('invalid decimal')
6    whole, _, fraction = text.partition('.')
7    sat = int(whole)*100_000_000 + int(fraction.ljust(8,'0'))
8    if not 0 < sat <= 21_000_000*100_000_000:
9        raise ValueError('out of range')
10    return sat
11
12if __name__ == '__main__':
13    assert btc_to_sat('0.00000001') == 1
14    assert btc_to_sat('0.0012') == 120000
15    try: btc_to_sat('0.000000001')
16    except ValueError: pass
17    else: raise AssertionError('fractional satoshi accepted')

Integration with WAB ENGINE

The local executor can request Testnet SegWit balance using POST /api/v5/btc/wallet/balance with X-BTC-KEY and JSON body {"net":"test","type":"segwit"}. A balance is not settlement evidence. Any future SEND must bind authorization to the exact intent, use persistent idempotency and preserve the wallet's signed birth fee law. Treat the sender total and recipient net amount as distinct accounting values under the applicable inclusive fee law; never assume they are equal. No SEND is implemented here.

Limitations and failure handling

Amount parsing is not invoice authentication or Bitcoin address validation. Bind the amount to a verified destination, network, merchant and expiry before requesting approval.

The included assertions exercise synthetic inputs only. No live engine, model or blockchain connection was tested. Fail closed on ambiguous financial state; investigate before retrying writes.

References

  • https://thamer.org/api
  • https://thamer.org/engine
  • https://developer.bitcoin.org/devguide/transactions.html

These links are reference pointers, not a claim of current external documentation verification.

Questions & Answers

Explore all questions →

Latest from the Lab

THAMER illustrated developer portrait and signature

ABOUT THE DEVELOPER

Independent Software Developer specializing in Bitcoin Script, Golang, and AI Agents.

Software engineering · Independent research · Open-source projects