Last active
November 15, 2018 02:51
-
-
Save rgruesbeck/d75fc0f054f42489610e6824acef5358 to your computer and use it in GitHub Desktop.
create an offline address by coin toss: requires https://github.com/libbitcoin/libbitcoin-explorer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
length=256 | |
bits=() | |
prvk="" | |
pubk="" | |
mnemonic="" | |
# collect coin flips | |
function getBits() { | |
msg="Start flipping!" | |
echo $msg | |
msg="Enter 1 for heads, 0 for tails: " | |
while [ "${#bits[*]}" -lt "$length" ]; do | |
read -p "$msg" bit | |
if [[ $bit =~ ^-?[0-1]$ ]]; then | |
bits+=($bit) | |
msg="${#bits[*]} of $length bits: " | |
else | |
msg="Enter 1 for heads, 0 for tails: " | |
fi | |
done | |
} | |
# convert to string | |
function getBitString() { | |
local str=$(echo "${bits[@]}") | |
echo ${str// /} | |
} | |
# convert to hex | |
function getHexString() { | |
local bitstr=$(getBitString) | |
echo $(printf '%x\n' "$((2#$bitstr))") | |
} | |
function mnemonic() { | |
mnemonic=$(bx mnemonic-new --SEED $1) | |
} | |
function privateKey() { | |
prvk=$(bx hd-new $1) | |
} | |
function publicKey() { | |
pubk=$(bx hd-public -d $1) | |
} | |
function newAddress() { | |
local seed=$(getHexString) | |
mnemonic $seed | |
privateKey $(bx mnemonic-to-seed $mnemonic) | |
publicKey $prvk | |
echo "" | |
echo "You have created a new Bitcoin Address!" | |
echo "Public Key: $pubk" | |
echo "Private Key: $prvk" | |
echo "" | |
echo "$mnemonic" | |
} | |
function main() { | |
getBits | |
newAddress | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
requires https://github.com/libbitcoin/libbitcoin-explorer