Persistent Replay Protection for Bitcoin Agent Messages
Persistent Replay Protection for Bitcoin Agent Messages
Claim authenticated message identifiers once using a durable ledger.
Design and trust boundary
Call the ledger only after authentication, strict parsing and recipient checks. The unique constraint coordinates concurrent claims on one SQLite database. A claim is not proof of payment: a crash after insertion requires a durable workflow state and reconciliation. This example never deletes identifiers, so storage grows; production retention must account for expiry, clock skew and identifier reuse. It does not coordinate separate database replicas.
Independent reference implementation
1# SPDX-License-Identifier: 0BSD
2import sqlite3, tempfile
3from pathlib import Path
4
5def claim(path,sender,request_id,expires,now):
6 if type(expires) is not int or not now < expires <= now+300:
7 return False
8 with sqlite3.connect(path) as db:
9 db.execute('CREATE TABLE IF NOT EXISTS seen(sender TEXT, id TEXT, PRIMARY KEY(sender,id))')
10 cur=db.execute('INSERT OR IGNORE INTO seen VALUES (?,?)',(sender,request_id))
11 return cur.rowcount == 1
12
13with tempfile.TemporaryDirectory() as d:
14 p=Path(d)/'ledger.db'
15 assert claim(p,'a','r1',110,100)
16 assert not claim(p,'a','r1',110,100)
17 assert not claim(p,'a','r2',99,100)Validation and limitations
Run the example with Python 3. Assertions use synthetic fixtures and do not contact a wallet or agent service. This is a proposed application-level pattern, not an established interoperability standard. Keep BTC KEY outside agent messages. The WAB Engine API and signed fee law remain unchanged.
Related research
https://thamer.org/learn/bitcoin-for-ai-agents-open-integration-guide
https://thamer.org/api
