How to Protect Bitcoin Wallet API Keys in a Website Backend
A browser must never receive BTC KEY. Build public responses from an explicit allowlist instead of forwarding raw engine JSON.
Implementation approach
The example projects a normalized internal checkout record. Authentication, CSRF protection, rate limiting and secret storage belong in the surrounding web application. Avoid logging raw headers or upstream responses.
Source code
1def public_checkout(record):
2 return {k:record[k] for k in ('order_id','address','expected_sat','status')}
3
4if __name__=='__main__':
5 record=dict(order_id='o1',address='fixture',expected_sat=5000,status='pending',btc_key='secret',watch_id='internal')
6 assert set(public_checkout(record))=={'order_id','address','expected_sat','status'}
7 assert 'secret' not in str(public_checkout(record))Local validation
Run python3 stage22-credential-boundary.py. The assertions use synthetic fixtures, not real Bitcoin addresses or payments. This is a reference example, not a complete production checkout. No SEND operation is included.
Related documentation
https://thamer.org/api
https://thamer.org/learn/bitcoin-ai-agents-advanced-research-guide
