Version 0.7.0
This commit is contained in:
parent
19ed9d8096
commit
08c5b76805
28 changed files with 934 additions and 627 deletions
24
MANIFEST
24
MANIFEST
|
|
@ -1,7 +1,7 @@
|
|||
# file GENERATED by distutils, do NOT edit
|
||||
__init__.py
|
||||
mmgen-addrgen
|
||||
mmgen-addrimport
|
||||
mmgen-keygen
|
||||
mmgen-passchg
|
||||
mmgen-pywallet
|
||||
mmgen-txcreate
|
||||
|
|
@ -19,8 +19,9 @@ mmgen/license.py
|
|||
mmgen/mn_electrum.py
|
||||
mmgen/mn_tirosh.py
|
||||
mmgen/mnemonic.py
|
||||
mmgen/term.py
|
||||
mmgen/tx.py
|
||||
mmgen/utils.py
|
||||
mmgen/util.py
|
||||
mmgen/walletgen.py
|
||||
mmgen/rpc/__init__.py
|
||||
mmgen/rpc/config.py
|
||||
|
|
@ -29,13 +30,12 @@ mmgen/rpc/data.py
|
|||
mmgen/rpc/exceptions.py
|
||||
mmgen/rpc/proxy.py
|
||||
mmgen/rpc/util.py
|
||||
scripts/bitcoind-walletunlock.py
|
||||
scripts/deinstall.sh
|
||||
tests/addr.py
|
||||
tests/bitcoin.py
|
||||
tests/mn_electrum.py
|
||||
tests/mn_tirosh.py
|
||||
tests/mnemonic.py
|
||||
tests/test.py
|
||||
tests/utils.py
|
||||
tests/walletgen.py
|
||||
mmgen/tests/__init__.py
|
||||
mmgen/tests/addr.py
|
||||
mmgen/tests/bitcoin.py
|
||||
mmgen/tests/mn_electrum.py
|
||||
mmgen/tests/mn_tirosh.py
|
||||
mmgen/tests/mnemonic.py
|
||||
mmgen/tests/test.py
|
||||
mmgen/tests/util.py
|
||||
mmgen/tests/walletgen.py
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ addresses can be tracked and spent as well, creating an easy migration path from
|
|||
other wallets.
|
||||
|
||||
To track address balances, MMGen relies on a bitcoin daemon modified by
|
||||
Bitcoin's core developer team to support watch-only addresses. This feature
|
||||
is soon to be included in the mainline Satoshi build. In the meantime,
|
||||
Bitcoin core developers to support watch-only addresses. This feature
|
||||
will one day be included in the mainline Satoshi build. In the meantime,
|
||||
instructions are provided below for compiling the modified bitcoind. Under
|
||||
Linux, this is a trivial task for even a casual user. Unfortunately, the same
|
||||
can't be said for Windows, but the thoroughly tested, step-by-step Windows build
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ time-consuming process of compiling the whole boost package.
|
|||
|
||||
#### 5. Build Bitcoind:
|
||||
|
||||
Download Sipa's watchonly bitcoind [zip archive][05] (commit a13f1e8 [[check][]])
|
||||
Download Sipa's watchonly bitcoind [zip archive][05] (commit #a13f1e8 [[check][]])
|
||||
from GitHub and unpack it. At the MSYS prompt, run:
|
||||
|
||||
$ cd /c/bitcoin-watchonly
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ sending it to the addresses labeled "Storage 1", "Storage 2" and "Storage 3"
|
|||
|
||||
To refresh your memory, here are the three addresses in question:
|
||||
|
||||
$ cat my_addrs
|
||||
$ cat my.addrs
|
||||
# My first MMGen addresses
|
||||
89ABCDEF {
|
||||
1 16bNmyYISiptuvJG3X7MPwiiS4HYvD7ksE Donations
|
||||
|
|
@ -175,11 +175,7 @@ the change amount (3.399 BTC in this case) automatically.
|
|||
Alternatively, and more conveniently, you can list your three addresses in MMGen
|
||||
format:
|
||||
|
||||
$ mmgen-txcreate 89ABCDEF:2,3.3 89ABCDEF:3,3.3 89ABCDEF:4 my_addrs
|
||||
|
||||
Note that an MMGen address file containing the requested output addresses must
|
||||
be provided on the command line. Any extra addresses in the file will be
|
||||
ignored.
|
||||
$ mmgen-txcreate 89ABCDEF:2,3.3 89ABCDEF:3,3.3 89ABCDEF:4
|
||||
|
||||
Now hit ENTER, choose the transaction's input from the list (10 BTC, address
|
||||
1F9495H8EJL..., txid 04f97185...,2), and confirm. If all goes well,
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ the version should be 1.48 or greater):
|
|||
libboost-test-dev
|
||||
libboost-thread-dev
|
||||
|
||||
Download the bitcoin-watchonly [zip archive][00] (commit a13f1e8 [[check][]])
|
||||
Download the bitcoin-watchonly [zip archive][00] (commit #a13f1e8 [[check][]])
|
||||
from GitHub, configure, and build:
|
||||
|
||||
$ unzip watchonly.zip
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ MMGen = Multi-Mode GENerator
|
|||
============================
|
||||
##### a Bitcoin cold storage solution for the command line
|
||||
|
||||
#### A word on text editors:
|
||||
### A word on text editors:
|
||||
|
||||
The text file editors that come with Windows, "edit" and "notepad", are
|
||||
unsuitable for editing source code for many reasons, but above all because they
|
||||
|
|
|
|||
|
|
@ -121,6 +121,8 @@ if invoked_as == "addrgen":
|
|||
opts,cmd_args = process_opts(sys.argv,help_data,"".join(short_opts),long_opts)
|
||||
|
||||
if 'show_hash_presets' in opts: show_hash_presets()
|
||||
if 'quiet' in opts: g.quiet = True
|
||||
if 'verbose' in opts: g.verbose = True
|
||||
|
||||
opts['gen_what'] = gen_what
|
||||
|
||||
|
|
@ -143,10 +145,10 @@ addr_list = parse_address_list(addr_list_arg)
|
|||
|
||||
if not addr_list: sys.exit(2)
|
||||
|
||||
if not 'quiet' in opts: do_license_msg()
|
||||
do_license_msg()
|
||||
|
||||
# Interact with user:
|
||||
if invoked_as == "keygen" and not 'quiet' in opts:
|
||||
if invoked_as == "keygen" and not g.quiet:
|
||||
confirm_or_exit(cmessages['unencrypted_secret_keys'], 'continue')
|
||||
|
||||
# Generate data:
|
||||
|
|
@ -163,7 +165,7 @@ addr_data_str = format_addr_data(addr_data, seed_id, opts)
|
|||
|
||||
# Output data:
|
||||
if 'stdout' in opts:
|
||||
if invoked_as == "keygen" and not 'quiet' in opts:
|
||||
if invoked_as == "keygen" and not g.quiet:
|
||||
confirm = True
|
||||
else: confirm = False
|
||||
write_to_stdout(addr_data_str,"secret keys",confirm)
|
||||
|
|
|
|||
|
|
@ -23,9 +23,8 @@ mmgen-addrimport: Import addresses into a bitcoind watching wallet.
|
|||
import sys
|
||||
from mmgen.Opts import *
|
||||
from mmgen.license import *
|
||||
from mmgen.util import check_infile,confirm_or_exit,msg,msg_r,secs_to_hms,get_lines_from_file
|
||||
from mmgen.util import *
|
||||
from mmgen.tx import connect_to_bitcoind,parse_addrs_file
|
||||
from mmgen.bitcoin import verify_addr
|
||||
|
||||
help_data = {
|
||||
'prog_name': sys.argv[0].split("/")[-1],
|
||||
|
|
@ -43,6 +42,7 @@ short_opts = "hl:q"
|
|||
long_opts = "help", "addrlist=", "quiet"
|
||||
|
||||
opts,cmd_args = process_opts(sys.argv,help_data,"".join(short_opts),long_opts)
|
||||
if 'quiet' in opts: g.quiet = True
|
||||
|
||||
if len(cmd_args) != 1 and not 'addrlist' in opts:
|
||||
msg("You must specify an mmgen address list (and/or non-mmgen addresses with the '--addrlist' option)")
|
||||
|
|
@ -57,28 +57,27 @@ else:
|
|||
seed_id,addr_data = "",[]
|
||||
|
||||
if 'addrlist' in opts:
|
||||
l = get_lines_from_file(
|
||||
opts['addrlist'],"non-mmgen addresses",remove_comments=True)
|
||||
l = get_lines_from_file(opts['addrlist'],"non-mmgen addresses",
|
||||
remove_comments=True)
|
||||
addr_data += [(None,i) for i in l]
|
||||
|
||||
msg_r("Validating addresses...")
|
||||
from mmgen.bitcoin import verify_addr
|
||||
qmsg_r("Validating addresses...")
|
||||
for i in addr_data:
|
||||
if not verify_addr(i[1]):
|
||||
if not verify_addr(i[1],verbose=True):
|
||||
msg("%s: invalid address" % i)
|
||||
sys.exit(2)
|
||||
|
||||
msg("OK")
|
||||
qmsg("OK")
|
||||
|
||||
import mmgen.config as g
|
||||
g.http_timeout = 3600
|
||||
|
||||
c = connect_to_bitcoind()
|
||||
|
||||
if not 'quiet' in opts:
|
||||
message = """
|
||||
m = """
|
||||
Importing addresses can take a long time (>30 min.) on a low-powered computer.
|
||||
"""
|
||||
confirm_or_exit(message, "continue", expect="YES")
|
||||
""".strip()
|
||||
confirm_or_exit(m, "continue", expect="YES")
|
||||
|
||||
import threading
|
||||
import time
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ help_data = {
|
|||
-p, --hash-preset p Change scrypt.hash() parameters to preset 'p'
|
||||
(default: '{}')
|
||||
-P, --passwd-file f Get new passphrase from file 'f'
|
||||
-q, --quiet Suppress warnings; overwrite files without
|
||||
prompting
|
||||
-v, --verbose Produce more verbose output
|
||||
|
||||
NOTE: The key ID will change if either the passphrase or hash preset
|
||||
|
|
@ -46,23 +48,24 @@ NOTE: The key ID will change if either the passphrase or hash preset
|
|||
""".format(g.hash_preset)
|
||||
}
|
||||
|
||||
short_opts = "hd:HkL:p:P:v"
|
||||
short_opts = "hd:HkL:p:P:qv"
|
||||
long_opts = "help","outdir=","show_hash_presets","keep_old_passphrase",\
|
||||
"label=","hash_preset=","passwd_file=","verbose"
|
||||
"label=","hash_preset=","passwd_file=","quiet","verbose"
|
||||
|
||||
opts,cmd_args = process_opts(sys.argv,help_data,short_opts,long_opts)
|
||||
if 'quiet' in opts: g.quiet = True
|
||||
if 'verbose' in opts: g.verbose = True
|
||||
check_opts(opts,long_opts)
|
||||
|
||||
if 'show_hash_presets' in opts: show_hash_presets()
|
||||
|
||||
check_opts(opts,long_opts)
|
||||
|
||||
if len(cmd_args) != 1:
|
||||
msg("One input file must be specified")
|
||||
sys.exit(2)
|
||||
infile = cmd_args[0]
|
||||
|
||||
# Old key:
|
||||
label,metadata,hash_preset,salt,enc_seed = get_data_from_wallet(infile,opts)
|
||||
label,metadata,hash_preset,salt,enc_seed = get_data_from_wallet(infile)
|
||||
seed_id,key_id = metadata[:2]
|
||||
|
||||
# Repeat on incorrect pw entry
|
||||
|
|
@ -86,7 +89,7 @@ else: opts['label'] = label # Copy the old label
|
|||
|
||||
if 'hash_preset' in opts:
|
||||
if hash_preset != opts['hash_preset']:
|
||||
msg("Hash preset has changed (%s -> %s)" %
|
||||
qmsg("Hash preset has changed (%s -> %s)" %
|
||||
(hash_preset, opts['hash_preset']))
|
||||
changed['preset'] = True
|
||||
else:
|
||||
|
|
@ -100,14 +103,14 @@ else:
|
|||
new_passwd = get_new_passphrase("new passphrase", opts)
|
||||
|
||||
if new_passwd == passwd:
|
||||
msg("Passphrase is unchanged")
|
||||
qmsg("Passphrase is unchanged")
|
||||
else:
|
||||
msg("Passphrase has changed")
|
||||
qmsg("Passphrase has changed")
|
||||
passwd = new_passwd
|
||||
changed['passwd'] = True
|
||||
|
||||
if 'preset' in changed or 'passwd' in changed: # Update key ID, salt
|
||||
msg("Will update salt and key ID")
|
||||
qmsg("Will update salt and key ID")
|
||||
|
||||
from hashlib import sha256
|
||||
from Crypto import Random
|
||||
|
|
@ -115,9 +118,9 @@ if 'preset' in changed or 'passwd' in changed: # Update key ID, salt
|
|||
salt = sha256(salt + Random.new().read(128)).digest()[:g.salt_len]
|
||||
key = make_key(passwd, salt, opts['hash_preset'])
|
||||
new_key_id = make_chksum_8(key)
|
||||
msg("Key ID changed: %s -> %s" % (key_id,new_key_id))
|
||||
qmsg("Key ID changed: %s -> %s" % (key_id,new_key_id))
|
||||
key_id = new_key_id
|
||||
enc_seed = encrypt_seed(seed, key, opts)
|
||||
enc_seed = encrypt_seed(seed, key)
|
||||
elif not 'label' in changed:
|
||||
msg("Data unchanged. No file will be written")
|
||||
sys.exit(2)
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ mmgen-pywallet: Dump contents of a bitcoind wallet to file
|
|||
|
||||
from mmgen.Opts import *
|
||||
from mmgen.util import msg
|
||||
import mmgen.config as g
|
||||
from bsddb.db import *
|
||||
import sys, time
|
||||
import json
|
||||
|
|
@ -81,21 +82,18 @@ help_data = {
|
|||
-a, --addrs Dump all addresses (flat list)
|
||||
-K, --keysforaddrs f Dump private keys for addresses listed in file 'f'
|
||||
-P, --passwd-file f Get passphrase from file 'f'
|
||||
-q, --quiet Suppress warnings; overwrite files without prompting
|
||||
-S, --stdout Dump to stdout rather than file
|
||||
"""
|
||||
}
|
||||
|
||||
short_opts = "hd:ejkaK:P:qS"
|
||||
short_opts = "hd:ejkaK:P:S"
|
||||
long_opts = "help","outdir=","echo_passphrase","json","keys","addrs",\
|
||||
"keysforaddrs=","passwd_file=","quiet","stdout"
|
||||
"keysforaddrs=","passwd_file=","stdout"
|
||||
|
||||
opts,cmd_args = process_opts(sys.argv,help_data,short_opts,long_opts)
|
||||
|
||||
from mmgen.util import check_infile
|
||||
|
||||
check_opts(opts,long_opts)
|
||||
|
||||
from mmgen.util import check_infile
|
||||
if len(cmd_args) == 1:
|
||||
check_infile(cmd_args[0])
|
||||
else:
|
||||
|
|
@ -1683,14 +1681,11 @@ elif 'addrs' in opts:
|
|||
|
||||
elif 'keysforaddrs' in opts:
|
||||
from mmgen.util import get_lines_from_file
|
||||
usr_addrs = get_lines_from_file(opts['keysforaddrs'],"addresses")
|
||||
for addr in usr_addrs:
|
||||
try:
|
||||
idx = wallet_addrs.index(addr)
|
||||
data.append(json_db['keys'][idx]['sec'])
|
||||
except:
|
||||
msg("WARNING: Address '%s' not found" % addr)
|
||||
data,ext,what = sorted(data),"keys","private keys"
|
||||
usr_addrs = set(get_lines_from_file(opts['keysforaddrs'],"addresses",remove_comments=True))
|
||||
data = [i['sec'] for i in json_db['keys'] if i['addr'] in usr_addrs]
|
||||
ext,what = "keys","private keys"
|
||||
if len(data) < len(usr_addrs):
|
||||
msg("Warning: not all requested keys found")
|
||||
|
||||
len_arg = "%s" % len(wallet_addrs) \
|
||||
if len(data) == len(wallet_addrs) or ext == "json" \
|
||||
|
|
@ -1703,8 +1698,7 @@ data = "\n".join(data) + "\n"
|
|||
|
||||
# Output data
|
||||
if 'stdout' in opts:
|
||||
if 'addrs' in opts or 'quiet' in opts: confirm = False
|
||||
else: confirm = True
|
||||
confirm = False if 'addrs' in opts else True
|
||||
write_to_stdout(data,"secret keys",confirm)
|
||||
elif not sys.stdout.isatty():
|
||||
write_to_stdout(data,"secret keys",confirm=False)
|
||||
|
|
|
|||
136
mmgen-txcreate
136
mmgen-txcreate
|
|
@ -51,77 +51,82 @@ via an interactive menu.
|
|||
Ages of transactions are approximate based on an average block creation
|
||||
interval of %s minutes.
|
||||
|
||||
Addresses on the command line can be Bitcoin addresses or MMGen
|
||||
addresses in the form <seed ID>:<number>
|
||||
Addresses on the command line can be Bitcoin addresses or MMGen addresses
|
||||
of the form <seed ID>:<number>.
|
||||
|
||||
To send all inputs (minus TX fee) to a single output, specify one address
|
||||
with no amount on the command line.
|
||||
""" % (Decimal(g.tx_fee),g.mins_per_block)
|
||||
}
|
||||
|
||||
short_opts = "ha:d:eiqf:"
|
||||
long_opts = "help","addr_file","outdir=","echo_passphrase","info","quiet",\
|
||||
"tx_fee="
|
||||
short_opts = "hd:eiqf:"
|
||||
long_opts = "help","outdir=","echo_passphrase","info","quiet","tx_fee="
|
||||
|
||||
opts,cmd_args = process_opts(sys.argv,help_data,short_opts,long_opts)
|
||||
|
||||
if 'quiet' in opts: g.quiet = True
|
||||
check_opts(opts,long_opts)
|
||||
|
||||
if g.debug: show_opts_and_cmd_args(opts,cmd_args)
|
||||
|
||||
c = connect_to_bitcoind()
|
||||
|
||||
if not 'info' in opts:
|
||||
|
||||
outputs,addr_files,change_addr = [],[],""
|
||||
tx_out,addr_data,b2m_map,acct_data,change_addr = {},[],{},[],""
|
||||
|
||||
for a in cmd_args:
|
||||
if a.split(".")[-1] == g.addrfile_ext:
|
||||
for a in [i for i in cmd_args if match_ext(i,g.addrfile_ext)]:
|
||||
if match_ext(a,g.addrfile_ext):
|
||||
check_infile(a)
|
||||
addr_files.append(a)
|
||||
elif "," in a:
|
||||
outputs.append(a)
|
||||
else:
|
||||
addr_data.append(parse_addrs_file(a))
|
||||
|
||||
def mm2btc_addr_proc(c,mmadr,acct_data,addr_data,b2m_map):
|
||||
btaddr,label = mmgen_addr_to_walletd(c,mmadr,acct_data)
|
||||
if not btaddr:
|
||||
btaddr,label = mmgen_addr_to_addr_data(mmadr,addr_data)
|
||||
b2m_map[btaddr] = mmadr,label
|
||||
return btaddr
|
||||
|
||||
for a in [i for i in cmd_args if not match_ext(i,g.addrfile_ext)]:
|
||||
if "," in a:
|
||||
a1,a2 = a.split(",")
|
||||
if is_mmgen_addr(a1) or is_btc_addr(a1):
|
||||
if is_mmgen_addr(a1):
|
||||
btaddr = mm2btc_addr_proc(c,a1,acct_data,addr_data,b2m_map)
|
||||
if is_btc_amt(a2):
|
||||
tx_out[btaddr] = check_btc_amt(a2)
|
||||
else:
|
||||
msg("%s: invalid amount in argument '%s'" % (a2,a))
|
||||
sys.exit(2)
|
||||
else:
|
||||
msg("%s: unrecognized subargument in argument '%s'" % (a1,a))
|
||||
sys.exit(2)
|
||||
elif is_mmgen_addr(a) or is_btc_addr(a):
|
||||
if change_addr:
|
||||
msg("More than one change address specified: %s, %s" %
|
||||
(change_addr, a))
|
||||
sys.exit(2)
|
||||
change_addr = a
|
||||
if is_mmgen_addr(a):
|
||||
change_addr = mm2btc_addr_proc(c,a,acct_data,addr_data,b2m_map)
|
||||
else:
|
||||
change_addr = a
|
||||
tx_out[change_addr] = 0
|
||||
else:
|
||||
msg("%s: unrecognized argument" % a)
|
||||
sys.exit(2)
|
||||
|
||||
if not outputs:
|
||||
if not tx_out:
|
||||
msg("At least one output must be specified on the command line")
|
||||
sys.exit(2)
|
||||
|
||||
addr_data = [parse_addrs_file(f) for f in addr_files]
|
||||
|
||||
tx_fee = opts['tx_fee'] if 'tx_fee' in opts else g.tx_fee
|
||||
|
||||
try:
|
||||
tx_fee = Decimal(tx_fee)
|
||||
except:
|
||||
msg("Invalid transaction fee format: %s" % tx_fee)
|
||||
sys.exit(2)
|
||||
|
||||
tx_fee = check_btc_amt(tx_fee)
|
||||
if tx_fee > g.max_tx_fee:
|
||||
msg("Transaction fee too large: %s > %s" % (tx_fee,g.max_tx_fee))
|
||||
sys.exit(2)
|
||||
|
||||
if change_addr:
|
||||
if ":" in change_addr:
|
||||
change_addr = mmgen_addr_to_btc_addr(change_addr,addr_data)
|
||||
else:
|
||||
check_address(change_addr)
|
||||
|
||||
|
||||
tx_out = make_tx_out(outputs,addr_data)
|
||||
|
||||
for i in tx_out.keys(): check_address(i)
|
||||
for i in tx_out.values(): check_btc_amt(i)
|
||||
|
||||
tx_fee = check_btc_amt(tx_fee)
|
||||
|
||||
if g.debug: show_opts_and_cmd_args(opts,cmd_args)
|
||||
|
||||
# Begin execution
|
||||
c = connect_to_bitcoind()
|
||||
|
||||
if not 'quiet' in opts and not 'info' in opts:
|
||||
do_license_msg(immed=True)
|
||||
if not 'info' in opts: do_license_msg(immed=True)
|
||||
|
||||
# Begin test
|
||||
# import mmgen.rpc
|
||||
|
|
@ -131,10 +136,9 @@ if not 'quiet' in opts and not 'info' in opts:
|
|||
us = c.listunspent()
|
||||
|
||||
if not us:
|
||||
msg_r("""
|
||||
msg("""
|
||||
No spendable outputs found! Import addresses with balances into your
|
||||
watch-only wallet using 'mmgen-addrimport' and then re-run this program.
|
||||
""")
|
||||
watch-only wallet using 'mmgen-addrimport' and then re-run this program.""")
|
||||
sys.exit(2)
|
||||
|
||||
# write_to_file("listunspent.json",repr(us))
|
||||
|
|
@ -146,8 +150,9 @@ total = trim_exponent(sum([i.amount for i in unspent]))
|
|||
msg("Total unspent: %s BTC (%s outputs)" % (total, len(unspent)))
|
||||
if 'info' in opts: sys.exit(0)
|
||||
|
||||
send_amt = sum(tx_out.values())
|
||||
msg("Total amount to spend: %s BTC" % send_amt)
|
||||
send_amt = sum([tx_out[i] for i in tx_out.keys()])
|
||||
msg("Total amount to spend: %s%s" % (
|
||||
(send_amt or "Unknown")," BTC" if send_amt else ""))
|
||||
|
||||
while True:
|
||||
sel_nums = select_outputs(unspent,
|
||||
|
|
@ -155,17 +160,15 @@ while True:
|
|||
msg("Selected outputs: %s" % " ".join(str(i) for i in sel_nums))
|
||||
sel_unspent = [unspent[i-1] for i in sel_nums]
|
||||
|
||||
lbls = set([verify_mmgen_label(
|
||||
i.account,return_str=True,check_label_len=True)
|
||||
for i in sel_unspent])
|
||||
lbls.discard("")
|
||||
mmaddrs = set([parse_mmgen_label(i.account)[0] for i in sel_unspent])
|
||||
mmaddrs.discard("")
|
||||
|
||||
if lbls and len(lbls) < len(sel_unspent):
|
||||
msg(txmsg['mixed_inputs'] % ", ".join(sorted(lbls)))
|
||||
if mmaddrs and len(mmaddrs) < len(sel_unspent):
|
||||
msg(txmsg['mixed_inputs'] % ", ".join(sorted(mmaddrs)))
|
||||
if not user_confirm("Accept?"):
|
||||
continue
|
||||
|
||||
total_in = trim_exponent(sum([o.amount for o in sel_unspent]))
|
||||
total_in = trim_exponent(sum([i.amount for i in sel_unspent]))
|
||||
change = trim_exponent(total_in - (send_amt + tx_fee))
|
||||
|
||||
if change >= 0:
|
||||
|
|
@ -175,28 +178,35 @@ while True:
|
|||
else:
|
||||
msg(txmsg['not_enough_btc'] % change)
|
||||
|
||||
|
||||
if change > 0 and not change_addr:
|
||||
msg(txmsg['throwaway_change'] % (change, total_in-tx_fee))
|
||||
msg(txmsg['throwaway_change'] % change)
|
||||
sys.exit(2)
|
||||
|
||||
if change_addr in tx_out and not change:
|
||||
msg("Warning: Change address will be unused as transaction produces no change")
|
||||
del tx_out[change_addr]
|
||||
|
||||
for k,v in tx_out.items(): tx_out[k] = float(v)
|
||||
|
||||
if change > 0: tx_out[change_addr] = float(change)
|
||||
|
||||
tx_in = [{"txid":i.txid, "vout":i.vout} for i in sel_unspent]
|
||||
for i in tx_out.keys(): tx_out[i] = float(tx_out[i])
|
||||
if change: tx_out[change_addr] = float(change)
|
||||
|
||||
if g.debug:
|
||||
print "tx_in:", repr(tx_in)
|
||||
print "tx_out:", repr(tx_out)
|
||||
tx_hex = c.createrawtransaction(tx_in,tx_out)
|
||||
|
||||
msg("Transaction successfully created")
|
||||
tx_hex = c.createrawtransaction(tx_in,tx_out)
|
||||
qmsg("Transaction successfully created")
|
||||
prompt = "View decoded transaction? (y)es, (N)o, (v)iew in pager"
|
||||
reply = prompt_and_get_char(prompt,"YyNnVv",enter_ok=True)
|
||||
|
||||
if reply and reply in "YyVv":
|
||||
pager = True if reply in "Vv" else False
|
||||
view_tx_data(c,[i.__dict__ for i in sel_unspent],tx_hex,pager=pager)
|
||||
view_tx_data(c,[i.__dict__ for i in sel_unspent],tx_hex,b2m_map,pager=pager)
|
||||
|
||||
prompt = "Save transaction?"
|
||||
if user_confirm(prompt,default_yes=True):
|
||||
print_tx_to_file(tx_hex,sel_unspent,send_amt,opts)
|
||||
print_tx_to_file(tx_hex,sel_unspent,send_amt or change,b2m_map,opts)
|
||||
else:
|
||||
msg("Transaction not saved")
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ short_opts = "hd:q"
|
|||
long_opts = "help","outdir=","quiet"
|
||||
|
||||
opts,cmd_args = process_opts(sys.argv,help_data,short_opts,long_opts)
|
||||
|
||||
if 'quiet' in opts: g.quiet = True
|
||||
check_opts(opts,long_opts)
|
||||
|
||||
if len(cmd_args) == 1:
|
||||
|
|
@ -71,9 +71,9 @@ except:
|
|||
msg("Invalid signed transaction data")
|
||||
sys.exit(3)
|
||||
|
||||
if not 'quiet' in opts: do_license_msg()
|
||||
do_license_msg()
|
||||
|
||||
msg("\nSigned transaction file '%s' appears valid" % infile)
|
||||
qmsg("Signed transaction file '%s' is valid" % infile)
|
||||
|
||||
warn = "Once this transaction is sent, there's no taking it back!"
|
||||
what = "broadcast this transaction to the network"
|
||||
|
|
@ -86,7 +86,6 @@ c = connect_to_bitcoind()
|
|||
|
||||
try:
|
||||
tx = c.sendrawtransaction(tx_sig)
|
||||
# tx = "deadbeef"
|
||||
except:
|
||||
msg("Unable to send transaction")
|
||||
sys.exit(3)
|
||||
|
|
|
|||
87
mmgen-txsign
87
mmgen-txsign
|
|
@ -25,7 +25,7 @@ from mmgen.Opts import *
|
|||
from mmgen.license import *
|
||||
import mmgen.config as g
|
||||
from mmgen.tx import *
|
||||
from mmgen.util import msg
|
||||
from mmgen.util import msg,qmsg
|
||||
|
||||
help_data = {
|
||||
'prog_name': sys.argv[0].split("/")[-1],
|
||||
|
|
@ -36,18 +36,19 @@ help_data = {
|
|||
-d, --outdir d Specify an alternate directory 'd' for output
|
||||
-e, --echo-passphrase Print passphrase to screen when typing it
|
||||
-i, --info Display information about the transaction and exit
|
||||
-I, --tx_id Display transaction ID and exit
|
||||
-I, --tx-id Display transaction ID and exit
|
||||
-k, --keys-from-file k Provide additional key data from file 'k'
|
||||
-P, --passwd-file f Get passphrase from file 'f'
|
||||
-q, --quiet Suppress warnings; overwrite files without
|
||||
prompting
|
||||
-V, --skip-key-preverify Skip optional key pre-verification step
|
||||
|
||||
-b, --from-brain l,p Generate keys from a user-created password,
|
||||
i.e. a "brainwallet", using seed length 'l' and
|
||||
hash preset 'p' (comma-separated)
|
||||
hash preset 'p'
|
||||
-m, --from-mnemonic Generate keys from an electrum-like mnemonic
|
||||
-s, --from-seed Generate keys from a seed in .{} format
|
||||
-w, --use-wallet-dat Use the keys in the bitcoind wallet.dat file too
|
||||
-w, --use-wallet-dat Get keys from a running bitcoind
|
||||
|
||||
Transactions with either mmgen or non-mmgen input addresses may be signed.
|
||||
For non-mmgen inputs, the bitcoind wallet.dat is used as the key source.
|
||||
|
|
@ -60,9 +61,13 @@ prompted to enter the data.
|
|||
|
||||
In cases of transactions with mixed mmgen and non-mmgen inputs, non-mmgen
|
||||
keys must be supplied in a separate file (WIF format, one key per line)
|
||||
using the '--keys-from-file' option. Alternatively, one may import the
|
||||
required mmgen keys into the bitcoind wallet.dat and use the
|
||||
'--force-wallet-dat' option.
|
||||
using the '--keys-from-file' option. Alternatively, one may get keys from
|
||||
a running bitcoind using the '--force-wallet-dat' option. First import the
|
||||
required mmgen keys using 'bitcoind importprivkey'.
|
||||
|
||||
For transaction outputs that are MMGen addresses, MMGen-to-Bitcoin address
|
||||
mappings are verified. Therefore, seed material for these addresses must
|
||||
be supplied on the command line.
|
||||
|
||||
Seed data supplied in files must have the following extensions:
|
||||
wallet: '.{}'
|
||||
|
|
@ -72,78 +77,84 @@ Seed data supplied in files must have the following extensions:
|
|||
""".format(g.seed_ext,g.wallet_ext,g.seed_ext,g.mn_ext,g.brain_ext)
|
||||
}
|
||||
|
||||
short_opts = "hd:eiIk:P:qb:msw"
|
||||
short_opts = "hd:eiIk:P:qVb:msw"
|
||||
long_opts = "help","outdir=","echo_passphrase","info","tx_id",\
|
||||
"keys_from_file=","passwd_file=","quiet","from_brain=",\
|
||||
"from_mnemonic","from_seed","use_wallet_dat"
|
||||
"keys_from_file=","passwd_file=","quiet","skip_key_preverify",\
|
||||
"from_brain=","from_mnemonic","from_seed","use_wallet_dat"
|
||||
|
||||
opts,infiles = process_opts(sys.argv,help_data,short_opts,long_opts)
|
||||
|
||||
if "quiet" in opts: g.quiet = True
|
||||
check_opts(opts,long_opts)
|
||||
|
||||
if not infiles: usage(help_data)
|
||||
for i in infiles: check_infile(i)
|
||||
|
||||
# Begin execution
|
||||
c = connect_to_bitcoind()
|
||||
|
||||
tx_file = infiles.pop(0)
|
||||
m = "" if 'tx_id' in opts else "transaction data"
|
||||
tx_data = get_lines_from_file(tx_file,m)
|
||||
|
||||
metadata,tx_hex,sig_data,inputs_data = parse_tx_data(tx_data,tx_file)
|
||||
metadata,tx_hex,inputs_data,b2m_map = parse_tx_data(tx_data,tx_file)
|
||||
|
||||
if 'tx_id' in opts:
|
||||
msg(metadata[0])
|
||||
sys.exit(0)
|
||||
|
||||
if 'info' in opts:
|
||||
view_tx_data(c,inputs_data,tx_hex,metadata)
|
||||
view_tx_data(c,inputs_data,tx_hex,b2m_map,metadata)
|
||||
sys.exit(0)
|
||||
|
||||
if not 'quiet' in opts: do_license_msg(immed=True)
|
||||
do_license_msg(immed=True)
|
||||
|
||||
msg("Successfully opened transaction file '%s'" % tx_file)
|
||||
# Are inputs mmgen addresses?
|
||||
mmgen_addrs = [i for i in inputs_data if parse_mmgen_label(i['account'])[0]]
|
||||
other_addrs = [i for i in inputs_data if not parse_mmgen_label(i['account'])[0]]
|
||||
|
||||
keys = get_lines_from_file(opts['keys_from_file'],"key data",remove_comments=True) \
|
||||
if 'keys_from_file' in opts else []
|
||||
|
||||
if other_addrs and not keys and not 'use_wallet_dat' in opts:
|
||||
missing_keys_errormsg(other_addrs)
|
||||
sys.exit(2)
|
||||
|
||||
if other_addrs and keys and not 'skip_key_preverify' in opts:
|
||||
a = [i['address'] for i in other_addrs]
|
||||
preverify_keys(a, keys)
|
||||
|
||||
seeds = {}
|
||||
check_mmgen_to_btc_addr_mappings(inputs_data,b2m_map,infiles,seeds,opts)
|
||||
|
||||
qmsg("Successfully opened transaction file '%s'" % tx_file)
|
||||
|
||||
prompt = "View transaction data? (y)es, (N)o, (v)iew in pager"
|
||||
reply = prompt_and_get_char(prompt,"YyNnVv",enter_ok=True)
|
||||
if reply and reply in "YyVv":
|
||||
p = True if reply in "Vv" else False
|
||||
view_tx_data(c,inputs_data,tx_hex,metadata,pager=p)
|
||||
view_tx_data(c,inputs_data,tx_hex,b2m_map,metadata,pager=p)
|
||||
|
||||
# Are inputs mmgen addresses?
|
||||
mmgen_addrs = [i for i in inputs_data if verify_mmgen_label(i['account'])]
|
||||
other_addrs = [i for i in inputs_data if not verify_mmgen_label(i['account'])]
|
||||
|
||||
keys = get_lines_from_file(opts['keys_from_file'],"key data") \
|
||||
if 'keys_from_file' in opts else []
|
||||
sig_data = [
|
||||
{"txid":i['txid'],"vout":i['vout'],"scriptPubKey":i['scriptPubKey']}
|
||||
for i in inputs_data]
|
||||
|
||||
if mmgen_addrs:
|
||||
if other_addrs and not keys and not 'use_wallet_dat' in opts:
|
||||
missing_keys_errormsg(other_addrs)
|
||||
sys.exit(2)
|
||||
|
||||
keys += get_keys_for_mmgen_addrs(mmgen_addrs,infiles,opts)
|
||||
ml = [i['account'].split()[0] for i in mmgen_addrs]
|
||||
keys += get_keys_for_mmgen_addrs(ml,infiles,seeds,opts)
|
||||
|
||||
if 'use_wallet_dat' in opts:
|
||||
sig_tx = sign_tx_with_bitcoind_wallet(c,tx_hex,sig_data,keys,opts)
|
||||
else:
|
||||
sig_tx = sign_transaction(c,tx_hex,sig_data,keys)
|
||||
elif other_addrs:
|
||||
if 'use_wallet_dat' in opts:
|
||||
sig_tx = sign_tx_with_bitcoind_wallet(c,tx_hex,sig_data,keys,opts)
|
||||
if keys:
|
||||
sig_tx = sign_transaction(c,tx_hex,sig_data,keys)
|
||||
else:
|
||||
if keys:
|
||||
sig_tx = sign_transaction(c,tx_hex,sig_data,keys)
|
||||
else:
|
||||
missing_keys_errormsg(other_addrs)
|
||||
sys.exit(2)
|
||||
sig_tx = sign_tx_with_bitcoind_wallet(c,tx_hex,sig_data,keys,opts)
|
||||
|
||||
if sig_tx['complete']:
|
||||
msg("Signing completed")
|
||||
prompt = "Save signed transaction?"
|
||||
prompt = "OK\nSave signed transaction?"
|
||||
if user_confirm(prompt,default_yes=True):
|
||||
print_signed_tx_to_file(tx_hex,sig_tx['hex'],metadata,opts)
|
||||
else:
|
||||
msg("Some keys were missing. Transaction could not be signed.")
|
||||
msg("failed\nSome keys were missing. Transaction could not be signed.")
|
||||
sys.exit(3)
|
||||
|
|
|
|||
|
|
@ -37,17 +37,20 @@ help_data = {
|
|||
-e, --echo-passphrase Print passphrase to screen when typing it
|
||||
-m, --export-mnemonic Export the wallet's mnemonic to file
|
||||
-P, --passwd-file f Get passphrase from file 'f'
|
||||
-q, --quiet Suppress warnings; overwrite files without prompting
|
||||
-s, --export-seed Export the wallet's seed to file
|
||||
-S, --stdout Print seed or mnemonic data to standard output
|
||||
-v, --verbose Produce more verbose output
|
||||
"""
|
||||
}
|
||||
|
||||
short_opts = "hd:emP:sSv"
|
||||
short_opts = "hd:emP:qsSv"
|
||||
long_opts = "help","outdir=","echo_passphrase","export_mnemonic",\
|
||||
"passwd_file=","export_seed","stdout","verbose"
|
||||
"passwd_file=","quiet","export_seed","stdout","verbose"
|
||||
|
||||
opts,cmd_args = process_opts(sys.argv,help_data,short_opts,long_opts)
|
||||
if 'quiet' in opts: g.quiet = True
|
||||
if 'verbose' in opts: g.verbose = True
|
||||
|
||||
# Argument sanity checks and processing:
|
||||
check_opts(opts,long_opts)
|
||||
|
|
@ -57,12 +60,12 @@ if len(cmd_args) != 1: usage(help_data)
|
|||
check_infile(cmd_args[0])
|
||||
|
||||
if 'export_mnemonic' in opts:
|
||||
msg("Exporting mnemonic data to file by user request")
|
||||
qmsg("Exporting mnemonic data to file by user request")
|
||||
if 'export_seed' in opts:
|
||||
msg("Exporting seed data to file by user request")
|
||||
qmsg("Exporting seed data to file by user request")
|
||||
|
||||
seed = get_seed_from_wallet(cmd_args[0], opts)
|
||||
if seed: msg("Wallet is OK")
|
||||
if seed: qmsg("Wallet is OK")
|
||||
|
||||
if 'export_mnemonic' in opts:
|
||||
wl = get_default_wordlist()
|
||||
|
|
|
|||
|
|
@ -45,10 +45,11 @@ help_data = {
|
|||
-p, --hash-preset p Use scrypt.hash() parameters from preset 'p'
|
||||
(default: '{}')
|
||||
-P, --passwd-file f Get passphrase from file 'f'
|
||||
-q, --quiet Suppress warnings; overwrite files without
|
||||
-q, --quiet Produce quieter output; overwrite files without
|
||||
prompting
|
||||
-u, --usr-randlen n Get 'n' characters of randomness from the user
|
||||
(default: {})
|
||||
-v, --verbose Produce more verbose output
|
||||
|
||||
-b, --from-brain l,p Generate wallet from a user-created passphrase,
|
||||
i.e. a "brainwallet", using seed length 'l' and
|
||||
|
|
@ -92,13 +93,14 @@ in all future invocations with that passphrase.
|
|||
)
|
||||
}
|
||||
|
||||
short_opts = "hd:eHl:L:p:P:qu:b:ms"
|
||||
short_opts = "hd:eHl:L:p:P:qu:vb:ms"
|
||||
long_opts = "help","outdir=","echo_passphrase","show_hash_presets","seed_len=",\
|
||||
"label=","hash_preset=","passwd_file=","quiet","usr_randlen=",\
|
||||
"from_brain=","from_mnemonic","from_seed"
|
||||
"verbose","from_brain=","from_mnemonic","from_seed"
|
||||
|
||||
opts,cmd_args = process_opts(sys.argv,help_data,short_opts,long_opts)
|
||||
|
||||
if 'quiet' in opts: g.quiet = True
|
||||
if 'verbose' in opts: g.verbose = True
|
||||
if 'show_hash_presets' in opts: show_hash_presets()
|
||||
|
||||
check_opts(opts,long_opts)
|
||||
|
|
@ -108,15 +110,23 @@ if g.debug: show_opts_and_cmd_args(opts,cmd_args)
|
|||
if len(cmd_args) == 1:
|
||||
infile = cmd_args[0]
|
||||
check_infile(infile)
|
||||
ext = infile.split(".")[-1]
|
||||
ok_exts = g.seed_ext, g.mn_ext, g.brain_ext
|
||||
for e in ok_exts:
|
||||
if e == ext: break
|
||||
else:
|
||||
msg(
|
||||
"Input file must have one of the following extensions: .%s" % ", .".join(ok_exts))
|
||||
sys.exit(1)
|
||||
elif len(cmd_args) == 0:
|
||||
infile = ""
|
||||
else: usage(help_data)
|
||||
|
||||
# Begin execution
|
||||
|
||||
if not 'quiet' in opts: do_license_msg()
|
||||
do_license_msg()
|
||||
|
||||
msg_r("Acquiring random data from your computer...")
|
||||
qmsg_r("Acquiring random data from your computer...")
|
||||
|
||||
from time import sleep
|
||||
sleep(0.25)
|
||||
|
|
@ -129,12 +139,12 @@ except:
|
|||
msg("FAILED\nUnable to generate random numbers. Exiting")
|
||||
sys.exit(2)
|
||||
|
||||
msg("OK")
|
||||
qmsg("OK")
|
||||
|
||||
if g.debug: display_os_random_data(os_rand_data)
|
||||
|
||||
usr_keys,key_timings = get_random_data_from_user(opts)
|
||||
msg("")
|
||||
qmsg("")
|
||||
|
||||
if g.debug: display_user_random_data(usr_keys,key_timings)
|
||||
|
||||
|
|
@ -143,7 +153,8 @@ usr_rand_data = sha256(usr_keys).digest() + \
|
|||
|
||||
for i in 'from_mnemonic','from_brain','from_seed':
|
||||
if infile or (i in opts):
|
||||
seed = get_seed_retry(infile,opts); break
|
||||
seed = get_seed_retry(infile,opts)
|
||||
qmsg(""); break
|
||||
else:
|
||||
# Truncate random data for smaller seed lengths
|
||||
seed = os_rand_data[0] + usr_rand_data
|
||||
|
|
@ -152,9 +163,7 @@ else:
|
|||
salt = os_rand_data[1] + usr_rand_data
|
||||
salt = sha256(salt).digest()[:g.salt_len]
|
||||
|
||||
if not 'quiet' in opts:
|
||||
msg("""
|
||||
Now you must choose a passphrase to encrypt the seed with. A key will be
|
||||
qmsg("""Now you must choose a passphrase to encrypt the seed with. A key will be
|
||||
generated from your passphrase using a hash preset of '%s'. Please note that
|
||||
no strength checking of passphrases is performed. For an empty passphrase,
|
||||
just hit ENTER twice.
|
||||
|
|
@ -164,6 +173,6 @@ passwd = get_new_passphrase("{} wallet passphrase".format(g.proj_name), opts)
|
|||
|
||||
key = make_key(passwd, salt, opts['hash_preset'])
|
||||
|
||||
enc_seed = encrypt_seed(seed, key, opts)
|
||||
enc_seed = encrypt_seed(seed, key)
|
||||
|
||||
write_wallet_to_file(seed,passwd,make_chksum_8(key),salt,enc_seed,opts)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
import sys, getopt
|
||||
import mmgen.config as g
|
||||
from mmgen.util import msg
|
||||
from mmgen.util import msg,check_infile
|
||||
|
||||
def usage(hd):
|
||||
print "USAGE: %s %s" % (hd['prog_name'], hd['usage'])
|
||||
|
|
@ -117,7 +117,9 @@ def check_opts(opts,long_opts):
|
|||
|
||||
for ch in list(label):
|
||||
if ch not in g.wallet_label_symbols:
|
||||
msg("'%s': illegal character in label" % ch)
|
||||
msg("""
|
||||
"%s": illegal character in label. Only ASCII characters are permitted.
|
||||
""".strip() % ch)
|
||||
sys.exit(1)
|
||||
elif opt == 'from_brain':
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ from hashlib import sha256, sha512
|
|||
from binascii import hexlify, unhexlify
|
||||
|
||||
from mmgen.bitcoin import numtowif
|
||||
from mmgen.util import msg,qmsg,qmsg_r
|
||||
import mmgen.config as g
|
||||
|
||||
def test_for_keyconv():
|
||||
|
|
@ -47,27 +48,12 @@ faster address generation.
|
|||
|
||||
|
||||
def generate_addrs(seed, addrnums, opts):
|
||||
"""
|
||||
generate_addresses(start, end, seed, opts) => None
|
||||
|
||||
Generate a Bitcoin address or addresses end based on a seed, optionally
|
||||
outputting secret keys
|
||||
|
||||
The 'keyconv' utility will be used for address generation if installed.
|
||||
Otherwise an internal function is used
|
||||
|
||||
Supported options:
|
||||
print_secret, no_addresses, no_keyconv, gen_what
|
||||
|
||||
Addresses are returned in a list of dictionaries with the following keys:
|
||||
num, sec, wif, addr
|
||||
"""
|
||||
|
||||
if not 'no_addresses' in opts:
|
||||
if 'no_keyconv' in opts or test_for_keyconv() == False:
|
||||
sys.stderr.write("Using (slow) internal ECDSA library for address generation\n")
|
||||
msg("Using (slow) internal ECDSA library for address generation")
|
||||
from mmgen.bitcoin import privnum2addr
|
||||
keyconv = ""
|
||||
keyconv = False
|
||||
else:
|
||||
from subprocess import Popen, PIPE
|
||||
keyconv = "keyconv"
|
||||
|
|
@ -75,12 +61,13 @@ def generate_addrs(seed, addrnums, opts):
|
|||
a,t_addrs,i,out = sorted(addrnums),len(addrnums),0,[]
|
||||
|
||||
while a:
|
||||
seed = sha512(seed).digest(); i += 1 # round /i/
|
||||
seed = sha512(seed).digest()
|
||||
i += 1 # round /i/
|
||||
if i < a[0]: continue
|
||||
|
||||
a.pop(0)
|
||||
|
||||
sys.stderr.write("\rGenerating %s %s (%s of %s)" %
|
||||
qmsg_r("\rGenerating %s %s (%s of %s)" %
|
||||
(opts['gen_what'], i, t_addrs-len(a), t_addrs))
|
||||
|
||||
# Secret key is double sha256 of seed hash round /i/
|
||||
|
|
@ -110,7 +97,7 @@ def generate_addrs(seed, addrnums, opts):
|
|||
import re
|
||||
w = re.sub('e*s$','',w)
|
||||
|
||||
sys.stderr.write("\rGenerated %s %s%s\n"%(t_addrs, w, " "*15))
|
||||
qmsg("\rGenerated %s %s%s"%(t_addrs, w, " "*15))
|
||||
|
||||
return out
|
||||
|
||||
|
|
@ -153,10 +140,9 @@ def format_addr_data(addrlist, seed_chksum, opts):
|
|||
# Everything following a hash symbol '#' is a comment and ignored by {}.
|
||||
# A text label of {} characters or less may be added to the right of each
|
||||
# address, and it will be appended to the bitcoind wallet label upon import.
|
||||
# The label may contain ASCII letters, numerals, and the symbols
|
||||
# '{}' and '{}'.
|
||||
""".format(g.proj_name.capitalize(),g.max_addr_label_len,
|
||||
"', '".join(g.addr_label_punc[0:-1]), g.addr_label_punc[-1]).strip()
|
||||
# The label may contain printable ASCII symbols.
|
||||
""".strip().format(g.proj_name_cap,g.max_addr_label_len)
|
||||
|
||||
data = []
|
||||
if not 'stdout' in opts: data.append(header + "\n")
|
||||
data.append("%s {" % seed_chksum.upper())
|
||||
|
|
@ -210,7 +196,7 @@ def write_addr_data_to_file(seed, data, addr_list, opts):
|
|||
else: ext = "akeys"
|
||||
|
||||
if 'b16' in opts: ext = ext.replace("keys","xkeys")
|
||||
from mmgen.util import write_to_file, make_chksum_8, msg
|
||||
from mmgen.util import write_to_file, make_chksum_8
|
||||
outfile = "{}[{}].{}".format(
|
||||
make_chksum_8(seed),
|
||||
fmt_addr_list(addr_list),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
|
||||
# MMGen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
|
||||
# Copyright (C) 2013 by philemon <mmgen-py@yandex.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
|
|
@ -61,15 +61,10 @@ def pubhex2addr(pubhex):
|
|||
pubkey = int(step2 + step4[:8], 16)
|
||||
return "1" + ("1" * extra_ones) + _numtob58(pubkey)
|
||||
|
||||
def privnum2addr(numpriv):
|
||||
pko = ecdsa.SigningKey.from_secret_exponent(numpriv,secp256k1)
|
||||
pubkey = hexlify(pko.get_verifying_key().to_string())
|
||||
return pubhex2addr('04'+pubkey)
|
||||
|
||||
def verify_addr(addr):
|
||||
def verify_addr(addr,verbose=False):
|
||||
|
||||
if addr[0] != "1":
|
||||
print "%s: Invalid address" % addr
|
||||
if verbose: print "%s: Invalid address" % addr
|
||||
return False
|
||||
|
||||
num = _b58tonum(addr[1:])
|
||||
|
|
@ -80,7 +75,7 @@ def verify_addr(addr):
|
|||
step2 = sha256(step1).hexdigest()
|
||||
|
||||
if step2[:8] != addr_hex[40:]:
|
||||
print "Invalid checksum in address %s" % ("1" + addr)
|
||||
if verbose: print "Invalid checksum in address %s" % ("1" + addr)
|
||||
return False
|
||||
|
||||
return True
|
||||
|
|
@ -115,8 +110,7 @@ def numtowif(numpriv):
|
|||
key = step1 + step3[:8]
|
||||
return _numtob58(int(key,16))
|
||||
|
||||
|
||||
# The following are mmgen internal (non-bitcoin) b58 functions
|
||||
# The following are MMGen internal (non-Bitcoin) b58 functions
|
||||
|
||||
# Drop-in replacements for b64encode() and b64decode():
|
||||
# (well, not exactly: they yield numeric but not bytewise equivalence)
|
||||
|
|
@ -159,19 +153,36 @@ def b58decode_pad(s):
|
|||
return _b58_pad(s,
|
||||
a=b58_lens,b=bin_lens,pad='\0',f=b58decode,w="base 58 numbers")
|
||||
|
||||
# Compressed address support:
|
||||
|
||||
################### FUNCTIONS UNUSED BY MMGEN: ###################
|
||||
def wiftohex(wifpriv,compressed=False):
|
||||
idx = 68 if compressed else 66
|
||||
num = _b58tonum(wifpriv)
|
||||
if num == False: return False
|
||||
key = hex(num)[2:].rstrip('L')
|
||||
if compressed and key[66:68] != '01': return False
|
||||
round1 = sha256(unhexlify(key[:idx])).digest()
|
||||
round2 = sha256(round1).hexdigest()
|
||||
return key[2:66] if (key[:2] == '80' and key[idx:] == round2[:8]) else False
|
||||
|
||||
# To check validity, recode with numtowif()
|
||||
def hextowif(hexpriv,compressed=False):
|
||||
step1 = '80' + hexpriv + ('01' if compressed else '')
|
||||
step2 = sha256(unhexlify(step1)).digest()
|
||||
step3 = sha256(step2).hexdigest()
|
||||
key = step1 + step3[:8]
|
||||
return _numtob58(int(key,16))
|
||||
|
||||
def privnum2addr(numpriv,compressed=False):
|
||||
pko = ecdsa.SigningKey.from_secret_exponent(numpriv,secp256k1)
|
||||
pubkey = hexlify(pko.get_verifying_key().to_string())
|
||||
if compressed:
|
||||
p = '03' if pubkey[-1] in "13579bdf" else '02'
|
||||
return pubhex2addr(p+pubkey[:64])
|
||||
else:
|
||||
return pubhex2addr('04'+pubkey)
|
||||
|
||||
# Used only in test suite. To check validity, recode with numtowif()
|
||||
def wiftonum(wifpriv):
|
||||
num = _b58tonum(wifpriv)
|
||||
if num == False: return False
|
||||
return (num % (1<<288)) >> 32
|
||||
|
||||
def wiftohex(wifpriv):
|
||||
num = _b58tonum(wifpriv)
|
||||
if num == False: return False
|
||||
key = hex(num)[2:].rstrip('L')
|
||||
round1 = sha256(unhexlify(key[:66])).digest()
|
||||
round2 = sha256(round1).hexdigest()
|
||||
return key[2:66] if (key[:2] == '80' and key[66:] == round2[:8]) else False
|
||||
|
|
|
|||
|
|
@ -18,12 +18,15 @@
|
|||
"""
|
||||
config.py: Constants and configuration options for the mmgen suite
|
||||
"""
|
||||
quiet,verbose = False,False
|
||||
min_screen_width = 80
|
||||
|
||||
from decimal import Decimal
|
||||
tx_fee = Decimal("0.001")
|
||||
max_tx_fee = Decimal("0.1")
|
||||
|
||||
proj_name = "mmgen"
|
||||
proj_name_cap = "MMGen"
|
||||
|
||||
wallet_ext = "mmdat"
|
||||
seed_ext = "mmseed"
|
||||
|
|
@ -71,12 +74,16 @@ hash_presets = {
|
|||
'6': [17, 8, 20],
|
||||
}
|
||||
|
||||
mmgen_idx_max_digits = 7
|
||||
|
||||
from string import ascii_letters, digits
|
||||
|
||||
addr_label_punc = ".","_",",","-"," "
|
||||
addr_label_symbols = tuple(ascii_letters + digits) + addr_label_punc
|
||||
max_addr_label_len = 16
|
||||
addr_label_symbols = tuple([chr(i) for i in range(0x20,0x7f)])
|
||||
max_addr_label_len = 32
|
||||
|
||||
wallet_label_punc = ".", "_", " "
|
||||
wallet_label_symbols = tuple(ascii_letters + digits) + wallet_label_punc
|
||||
wallet_label_symbols = addr_label_symbols
|
||||
max_wallet_label_len = 32
|
||||
|
||||
#addr_label_punc = ".","_",",","-"," ","(",")"
|
||||
#addr_label_symbols = tuple(ascii_letters + digits) + addr_label_punc
|
||||
#wallet_label_punc = addr_label_punc
|
||||
|
|
|
|||
|
|
@ -585,6 +585,10 @@ copy of the Program in return for a fee.
|
|||
}
|
||||
|
||||
def do_license_msg(immed=False):
|
||||
|
||||
import mmgen.config as g
|
||||
if g.quiet: return
|
||||
|
||||
msg(gpl['warning'])
|
||||
prompt = "%s " % gpl['prompt'].strip()
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue