[PATCH] bitcoin scratch-off cards
This patch adds the “sendscratchoff” RPC call, which creates transactions that are an electronic attempt at scratch-off cards:
http://yyz.us/bitcoin/patch.bitcoin-scratch-card
or git://github.com/jgarzik/bitcoin.git#scratch-card
To create a scratch-off card for 0.82 BTC from the ‘master’ account via JSON-RPC:
$ bitcoind sendscratchoff master 0.82 '{ "bits" : 64, "salt" : "myawesome.com" }' 1 "my awesome scratch-off"
{
"txid" : "4a16969aa4764dd7507fc1de7f0baa4850a246de90c45e59a3207f9a26b5036f",
"password" : "719d17195638f937"
}
And presumably you will have a fancy print-out or display saying
Redeem this card for 0.82 bitcoins!
card# 4a16 969a
presented by: myawesome.com
password 719d 1719 5638 f937
Some time later, the holder of this card may redeem their 0.82 BTC with another new RPC ‘scratchoff’:
$ bitcoind scratchoff 4a16969a 719d17195638f937 "myawesome.com"
994dd0219f6dea648a6d5f8d33850114a2a0787e136a36e8b24ccafcd6ff0e59
^^^ transaction that "claims" the scratch-off card
How it works
After re-reading this old thread (http://bitcointalk.org/index.php?topic=1514.0), a discussion on IRC led ArtForz to note that ByteCoin suggested a way to create bitcoin scratch-off cards within a standard transaction. Unless I’ve totally bollock’s up the works, which is entirely possible, here’s how it works:
- Our EC private keys are 256 bits
- Generate 64-1024 random bits (def. 64) — this is your scratch-off password
- Perform a great many rounds of hashing the password, and a user-supplied salt string (default “bitcoin”), to produce 256 bits of data
- Create EC keypair with the resultant 256 bits of post-hash data
- Create transaction, sending n.nn BTC to the hash of the EC public key
- Return 32 bits of transaction hash (“id”) and scratch-off password (“password”) via JSON-RPC
To redeem a scratch-off,
- Retrieve transaction by looking up N bits of the transaction hash (“txid”)
- Build raw 256-bit private key, through many rounds of hashing the password (“password”) and salt (“salt”)
- Create EC keypair from raw private key
- Verify transaction output’s pubkey hash matches EC pubkey hash
- Add EC keypair and scratch-off TX to local wallet
- Create transaction that sends bitcoins from scratch-off TX to a new key in your own wallet, thereby “claiming” the card.
- You may now spend those bitcoins, once your claim is confirmed (requires at least 1 confirmation by default)
Because this is an entirely normal transaction, willingly relayed by all existing clients, no outside observer will know that this spend is a scratch-off card, rather than a regular spend to a regular bitcoin address.
Variations:
(1) Use decimal digits instead of hexidecimal, for id and password. More consumer friendly. Requires a small amount of brute forcing, if one limits the password to 16 digits, to recover the lost bits.
(2) If you have a full block chain, and EC pub/private keys, the transaction hash (“txid”) is optional. One could simply scan the block chain for an unspent transaction to the given bitcoin address (derived from the password).
Credit for all bugs goes to me. Credit for the ideas goes to bytecoin, art, theymos and the authors of RFC 2898.
EDIT: Updated to reflect changes through March 23.