Mnemonics and Offline Transactions in Bitcoin Cash

in #utopian-io7 years ago

I've created a simple set of tools that you can use to generate your mnemonic, decode a bitcoin cash private key from existing mnemonic, and create an offline transaction that you can broadcast manually once online:

https://github.com/jurev/codemojo

Note, this is not the standard 12-word mnemonic that can be used as a seed for wallet addresses. We are interested in the mnemonic that corresponds to one 256-bit private key directly. To achieve that we need 24 words, giving 264 bits. Since that's 8 bits too much, we use the last 8 bits for a checksum.

Here's how it works:

First we need to generate the first 23 words.

$ python3 generate_23words.py
token boy sense already frog spoon beyond cradle lyrics actress quantum amazing proud danger repeat noodle midnight sight infant swallow decade coral certain


Once we have them, we are given a choice of 8 words to select for the last word. There are only 8 words because we need only 3 more bits, the rest is then checksum.

$ python3 word24_select.py token boy sense already frog spoon beyond cradle lyrics actress quantum amazing proud danger repeat noodle midnight sight infant swallow decade coral certain
word 24 candidates:
00001111010 aunt
00101111011 control
01001111011 exhaust
01101111100 hurdle
10001111011 month
10101111100 question
11001111100 sort
11101111101 use


Here I selected control, and now I can decode my private key:

$ python3 mnemonic_to_privatekey.py token boy sense already frog spoon beyond cradle lyrics actress quantum amazing proud danger repeat noodle midnight sight infant swallow decade coral certain control
...
checksum OK

Private key (hex):
e3e3570f0395d3a505718f85605abd03eacc6eedacb08c7905cd6d8388604969


To create a transaction I simply run this in python shell:

$ python3
>>> from bitcash import Key
>>> bytes = (int("e3e3570f0395d3a505718f85605abd03eacc6eedacb08c7905cd6d8388604969", 16)).to_bytes(32, byteorder='big')
>>> k = Key.from_bytes(bytes)
>>> k.address
'15moyH8GXXztZjeRTT2Ys1fC3LsXaBevvS'
>>> k.get_balance()
411192
>>> target = "1PCmvL6hrX5ih6JRFPxPke3mABtbYRviTD"
>>> outputs = [(target, 30000, "satoshi")]
>>> tx = k.create_transaction(outputs=outputs, message="mojo was here")
>>> print(tx)
010000000121fad95cecaf4ca3b6767f7f93543700286d9e99d9ad5cafd589ff0c9fdaec9d010000006a4730440220128fdd812f7b52f16873a56c6857ec7d1da96fe0e5d2a75886b1c1db7024e6d8022027c5febfaed8e2a2af07d50e252018eb14b30177479ea4293f181bc1804731bb412102c9d10032ec23553821a1bc9200dc4ac28d1081c733cc1af635a9f335d9d362eeffffffff0330750000000000001976a914f38cd6f7200c7a09fe4c2c3cf22ce6af48a5536a88acb0ba0500000000001976a914345a03a8d12e338689bbaaf583138443c3e8359188ac00000000000000000f6a0d6d6f6a6f20776173206865726500000000


The long string of characters at the end is my transaction, that I broadcasted here:
https://blockdozer.com/insight/tx/send

That's it, hope you find it useful.

My plan is to distribute my secret 24 words to various people, places and riddles and by my calculations if someone is able to gather at least 21 of the words, they would be able to spend my cold storage, and the number of words each person contributed would be proportional to the chunk they would be eligible to spend. In a perfect world, that is.

Tested with Python 3.5.2

Uses bitcash (pip install bitcash).

Sort:  

This post has received a 1.59 % upvote from @boomerang thanks to: @codemojo