Basic altcoin framework, full Litecoin support
- LTC: tested on mainnet, full test suite support - simultaneous autosigning for all supported coins (BTC,BCH,LTC)
This commit is contained in:
parent
2435f60b03
commit
35d1091159
64 changed files with 2065 additions and 1105 deletions
|
|
@ -2,6 +2,7 @@ include README.md SIGNING_KEY.pub LICENSE INSTALL
|
|||
include doc/wiki/using-mmgen/*
|
||||
include test/*.py
|
||||
include test/ref/*
|
||||
include test/ref/litecoin/*
|
||||
|
||||
include scripts/bitcoind-walletunlock.py
|
||||
include scripts/compute-file-chksum.py
|
||||
|
|
|
|||
|
|
@ -129,3 +129,4 @@ Donate: 15TLdmi5NYLdqmtCqczUs5pBPkJDXRs83w
|
|||
[9]: https://cloud.githubusercontent.com/assets/6071028/20677261/6ccab1bc-b58a-11e6-8ab6-094f88befef2.jpg
|
||||
[r]: https://github.com/mmgen/mmgen/wiki/Recovering-Your-Keys-Without-the-MMGen-Software
|
||||
[x]: https://github.com/mmgen/mmgen/wiki/Getting-Started-with-MMGen#a_bch
|
||||
[z]: https://user-images.githubusercontent.com/6071028/31656274-a35a1252-b31a-11e7-93b7-3d666f50f70f.png
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
# this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
mmgen-passgen: Generate a series or range of passwords from an MMGen
|
||||
mmgen-passgen: Generate a range or series of passwords from an MMGen
|
||||
deterministic wallet
|
||||
"""
|
||||
|
||||
|
|
@ -23,16 +23,16 @@
|
|||
# Uncomment to use testnet instead of mainnet:
|
||||
# testnet true
|
||||
|
||||
# Set the RPC host (the host bitcoind is running on):
|
||||
# Set the RPC host (the host the coin daemon is running on):
|
||||
# rpc_host localhost
|
||||
|
||||
# Set the RPC host's port number
|
||||
# rpc_port 8332
|
||||
|
||||
# Uncomment to override 'rpcuser' in bitcoin.conf
|
||||
# Uncomment to override 'rpcuser' from coin daemon config file
|
||||
# rpc_user myusername
|
||||
|
||||
# Uncomment to override 'rpcpassword' in bitcoin.conf
|
||||
# Uncomment to override 'rpcpassword' from coin daemon config file
|
||||
# rpc_password mypassword
|
||||
|
||||
# Uncomment to set the coin daemon datadir
|
||||
|
|
@ -46,8 +46,14 @@
|
|||
# A value of 0 disables user entropy, but this is not recommended:
|
||||
# usr_randchars 30
|
||||
|
||||
# Set the maximum transaction fee in BTC:
|
||||
# max_tx_fee 0.01
|
||||
# Set the maximum transaction fee for BTC:
|
||||
# btc_max_tx_fee 0.01
|
||||
|
||||
# Set the maximum transaction fee for BCH:
|
||||
# bch_max_tx_fee 0.1
|
||||
|
||||
# Set the maximum transaction fee for LTC:
|
||||
# ltc_max_tx_fee 0.3
|
||||
|
||||
# Set the transaction fee adjustment factor. Auto-calculated fees are
|
||||
# multiplied by this value:
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class AddrGeneratorP2PKH(AddrGenerator):
|
|||
def to_addr(self,pubhex):
|
||||
from mmgen.protocol import hash160
|
||||
assert type(pubhex) == PubKey
|
||||
return CoinAddr(g.proto.hexaddr2addr(hash160(pubhex)))
|
||||
return CoinAddr(g.proto.hexaddr2addr(hash160(pubhex),p2sh=False))
|
||||
|
||||
def to_segwit_redeem_script(self,pubhex):
|
||||
raise NotImplementedError
|
||||
|
|
@ -160,10 +160,9 @@ class AddrListIDStr(unicode,Hilite):
|
|||
|
||||
if fmt_str:
|
||||
ret = fmt_str.format(s)
|
||||
elif addrlist.al_id.mmtype == 'L':
|
||||
ret = '{}[{}]'.format(addrlist.al_id.sid,s)
|
||||
else:
|
||||
ret = '{}-{}[{}]'.format(addrlist.al_id.sid,addrlist.al_id.mmtype,s)
|
||||
bc,mt = g.proto.base_coin,addrlist.al_id.mmtype
|
||||
ret = '{}{}{}[{}]'.format(addrlist.al_id.sid,('-'+bc,'')[bc=='BTC'],('-'+mt,'')[mt=='L'],s)
|
||||
|
||||
return unicode.__new__(cls,ret)
|
||||
|
||||
|
|
@ -175,7 +174,7 @@ class AddrList(MMGenObject): # Address info for a single seed ID
|
|||
# This file is editable.
|
||||
# Everything following a hash symbol '#' is a comment and ignored by {pnm}.
|
||||
# A text label of {n} characters or less may be added to the right of each
|
||||
# address, and it will be appended to the bitcoind wallet label upon import.
|
||||
# address, and it will be appended to the tracking wallet label upon import.
|
||||
# The label may contain any printable ASCII symbol.
|
||||
""".strip().format(n=TwComment.max_len,pnm=pnm),
|
||||
'record_chksum': """
|
||||
|
|
@ -187,7 +186,7 @@ Removed %s duplicate WIF key%s from keylist (also in {pnm} key-address file
|
|||
""".strip().format(pnm=pnm)
|
||||
}
|
||||
entry_type = AddrListEntry
|
||||
main_key = 'addr'
|
||||
main_attr = 'addr'
|
||||
data_desc = 'address'
|
||||
file_desc = 'addresses'
|
||||
gen_desc = 'address'
|
||||
|
|
@ -197,7 +196,6 @@ Removed %s duplicate WIF key%s from keylist (also in {pnm} key-address file
|
|||
gen_keys = False
|
||||
has_keys = False
|
||||
ext = 'addrs'
|
||||
dfl_mmtype = MMGenAddrType('L')
|
||||
cook_hash_rounds = 10 # not too many rounds, so hand decoding can still be feasible
|
||||
chksum_rec_f = lambda foo,e: (str(e.idx), e.addr)
|
||||
|
||||
|
|
@ -205,7 +203,7 @@ Removed %s duplicate WIF key%s from keylist (also in {pnm} key-address file
|
|||
addrlist='',keylist='',mmtype=None,do_chksum=True,chksum_only=False):
|
||||
|
||||
self.update_msgs()
|
||||
mmtype = mmtype or self.dfl_mmtype
|
||||
mmtype = mmtype or MMGenAddrType.dfl_mmtype
|
||||
assert mmtype in MMGenAddrType.mmtypes
|
||||
|
||||
if seed and addr_idxs: # data from seed + idxs
|
||||
|
|
@ -296,21 +294,16 @@ Removed %s duplicate WIF key%s from keylist (also in {pnm} key-address file
|
|||
self.al_id.hl(),t_addrs,self.gen_desc,suf(t_addrs,self.gen_desc_pl),' '*15))
|
||||
return out
|
||||
|
||||
def is_mainnet(self):
|
||||
return self.data[0].addr.is_mainnet()
|
||||
|
||||
def is_for_current_chain(self):
|
||||
return self.data[0].addr.is_for_current_chain()
|
||||
|
||||
def check_format(self,addr): return True # format is checked when added to list entry object
|
||||
|
||||
def cook_seed(self,seed):
|
||||
if self.al_id.mmtype == 'L':
|
||||
is_btcfork = g.proto.base_coin == 'BTC'
|
||||
if is_btcfork and self.al_id.mmtype == 'L':
|
||||
return seed
|
||||
else:
|
||||
from mmgen.crypto import sha256_rounds
|
||||
import hmac
|
||||
key = self.al_id.mmtype.name
|
||||
key = (g.coin.lower()+':','')[is_btcfork] + self.al_id.mmtype.name
|
||||
cseed = hmac.new(seed,key,sha256).digest()
|
||||
dmsg('Seed: {}\nKey: {}\nCseed: {}\nCseed len: {}'.format(hexlify(seed),key,hexlify(cseed),len(cseed)))
|
||||
return sha256_rounds(cseed,self.cook_hash_rounds)
|
||||
|
|
@ -406,10 +399,10 @@ Removed %s duplicate WIF key%s from keylist (also in {pnm} key-address file
|
|||
if type(self) == PasswordList:
|
||||
out.append(u'{} {} {}:{} {{'.format(
|
||||
self.al_id.sid,self.pw_id_str,self.pw_fmt,self.pw_len))
|
||||
elif self.al_id.mmtype == 'L':
|
||||
out.append('{} {{'.format(self.al_id.sid))
|
||||
else:
|
||||
out.append('{} {} {{'.format(self.al_id.sid,self.al_id.mmtype.name.upper()))
|
||||
bc,mt = g.proto.base_coin,self.al_id.mmtype
|
||||
lbl = ':'.join(([bc],[])[bc=='BTC']+([mt.name.upper()],[])[mt=='L'])
|
||||
out.append('{} {}{{'.format(self.al_id.sid,('',lbl+' ')[bool(lbl)]))
|
||||
|
||||
fs = ' {:<%s} {:<34}{}' % len(str(self.data[-1].idx))
|
||||
for e in self.data:
|
||||
|
|
@ -447,16 +440,16 @@ Removed %s duplicate WIF key%s from keylist (also in {pnm} key-address file
|
|||
|
||||
if len(d) != 3: d.append('')
|
||||
|
||||
a = le(**{'idx':int(d[0]),self.main_key:d[1],'label':d[2]})
|
||||
a = le(**{'idx':int(d[0]),self.main_attr:d[1],'label':d[2]})
|
||||
|
||||
if self.has_keys:
|
||||
l = lines.pop(0)
|
||||
d = l.split(None,2)
|
||||
|
||||
if d[0] != 'wif:':
|
||||
return "Invalid key line in file: '%s'" % l
|
||||
return "Invalid key line in file: '{}'".format(l)
|
||||
if not is_wif(d[1]):
|
||||
return "'%s': invalid Bitcoin key" % d[1]
|
||||
return "'{}': invalid {} key".format(d[1],g.proto.name.capitalize())
|
||||
|
||||
a.sec = PrivKey(wif=d[1])
|
||||
|
||||
|
|
@ -498,6 +491,38 @@ Removed %s duplicate WIF key%s from keylist (also in {pnm} key-address file
|
|||
if not is_mmgen_seed_id(sid):
|
||||
return do_error("'%s': invalid Seed ID" % ls[0])
|
||||
|
||||
def parse_addrfile_label(lbl): # we must maintain backwards compat, so parse is tricky
|
||||
al_base_coin,al_mmtype = None,None
|
||||
lbl = lbl.split(':',1)
|
||||
if len(lbl) == 2:
|
||||
al_base_coin = lbl[0]
|
||||
al_mmtype = lbl[1].lower()
|
||||
else:
|
||||
if lbl[0].lower() in MMGenAddrType.get_names():
|
||||
al_mmtype = lbl[0].lower()
|
||||
else:
|
||||
al_base_coin = lbl[0]
|
||||
|
||||
# this block fails if al_mmtype is invalid for g.coin
|
||||
if not al_mmtype:
|
||||
mmtype = MMGenAddrType('L')
|
||||
else:
|
||||
try:
|
||||
mmtype = MMGenAddrType(al_mmtype)
|
||||
except:
|
||||
return do_error(u"'{}': invalid address type in address file. Must be one of: {}".format(
|
||||
mmtype.upper(),' '.join([i['name'].upper() for i in MMGenAddrType.mmtypes.values()])))
|
||||
|
||||
from mmgen.protocol import CoinProtocol
|
||||
base_coin = CoinProtocol(al_base_coin or 'BTC',testnet=False).base_coin
|
||||
if not base_coin:
|
||||
die(2,"'{}': unknown base coin in address file label!".format(al_base_coin))
|
||||
return base_coin,mmtype
|
||||
|
||||
def check_coin_mismatch(base_coin): # die if addrfile coin doesn't match g.coin
|
||||
if not base_coin == g.proto.base_coin:
|
||||
die(2,'{} address file format, but base coin is {}!'.format(base_coin,g.proto.base_coin))
|
||||
|
||||
if type(self) == PasswordList and len(ls) == 2:
|
||||
ss = ls.pop().split(':')
|
||||
if len(ss) != 2:
|
||||
|
|
@ -507,14 +532,11 @@ Removed %s duplicate WIF key%s from keylist (also in {pnm} key-address file
|
|||
self.pw_id_str = MMGenPWIDString(ls.pop())
|
||||
mmtype = MMGenPasswordType('P')
|
||||
elif len(ls) == 1:
|
||||
mmtype = ls.pop().lower()
|
||||
try:
|
||||
mmtype = MMGenAddrType(mmtype)
|
||||
except:
|
||||
return do_error(u"'{}': invalid address type in address file. Must be one of: {}".format(
|
||||
mmtype.upper(),' '.join([i['name'].upper() for i in MMGenAddrType.mmtypes.values()])))
|
||||
base_coin,mmtype = parse_addrfile_label(ls[0])
|
||||
check_coin_mismatch(base_coin)
|
||||
elif len(ls) == 0:
|
||||
mmtype = MMGenAddrType('L')
|
||||
base_coin,mmtype = 'BTC',MMGenAddrType('L')
|
||||
check_coin_mismatch(base_coin)
|
||||
else:
|
||||
return do_error(u"Invalid first line for {} file: '{}'".format(self.gen_desc,lines[0]))
|
||||
|
||||
|
|
@ -572,7 +594,7 @@ Record this checksum: it will be used to verify the password file in the future
|
|||
""".strip()
|
||||
}
|
||||
entry_type = PasswordListEntry
|
||||
main_key = 'passwd'
|
||||
main_attr = 'passwd'
|
||||
data_desc = 'password'
|
||||
file_desc = 'passwords'
|
||||
gen_desc = 'password'
|
||||
|
|
@ -666,14 +688,14 @@ Record this checksum: it will be used to verify the password file in the future
|
|||
|
||||
def cook_seed(self,seed):
|
||||
from mmgen.crypto import sha256_rounds
|
||||
# Changing either pw_fmt, pw_len or id_str will cause a different, unrelated set of
|
||||
# passwords to be generated: this is what we want
|
||||
# Changing either pw_fmt, pw_len or cook_str will cause a different,
|
||||
# unrelated set of passwords to be generated: this is what we want.
|
||||
# NB: In original implementation, pw_id_str was 'baseN', not 'bN'
|
||||
fid_str = '{}:{}:{}'.format(self.pw_fmt,self.pw_len,self.pw_id_str.encode('utf8'))
|
||||
dmsg(u'Full ID string: {}'.format(fid_str.decode('utf8')))
|
||||
# Original implementation was 'cseed = seed + fid_str'; hmac was not used
|
||||
cook_str = '{}:{}:{}'.format(self.pw_fmt,self.pw_len,self.pw_id_str.encode('utf8'))
|
||||
dmsg(u'Full ID string: {}'.format(cook_str.decode('utf8')))
|
||||
# Original implementation was 'cseed = seed + cook_str'; hmac was not used
|
||||
import hmac
|
||||
cseed = hmac.new(seed,fid_str,sha256).digest()
|
||||
cseed = hmac.new(seed,cook_str,sha256).digest()
|
||||
dmsg('Seed: {}\nCooked seed: {}\nCooked seed len: {}'.format(hexlify(seed),hexlify(cseed),len(cseed)))
|
||||
return sha256_rounds(cseed,self.cook_hash_rounds)
|
||||
|
||||
|
|
@ -712,10 +734,9 @@ re-import your addresses.
|
|||
|
||||
def add_tw_data(self):
|
||||
vmsg('Getting address data from tracking wallet')
|
||||
c = rpc_connection()
|
||||
accts = c.listaccounts(0,True)
|
||||
accts = g.rpch.listaccounts(0,True)
|
||||
data,i = {},0
|
||||
alists = c.getaddressesbyaccount([[k] for k in accts],batch=True)
|
||||
alists = g.rpch.getaddressesbyaccount([[k] for k in accts],batch=True)
|
||||
for acct,addrlist in zip(accts,alists):
|
||||
l = TwLabel(acct,on_fail='silent')
|
||||
if l and l.mmid.type == 'mmgen':
|
||||
|
|
|
|||
|
|
@ -26,16 +26,79 @@ import mmgen.opts as opts
|
|||
from mmgen.opts import opt
|
||||
from mmgen.util import *
|
||||
|
||||
pw_note = """
|
||||
def help_notes(k):
|
||||
from mmgen.seed import SeedSource
|
||||
return {
|
||||
'passwd': """
|
||||
For passphrases all combinations of whitespace are equal and leading and
|
||||
trailing space is ignored. This permits reading passphrase or brainwallet
|
||||
data from a multi-line file with free spacing and indentation.
|
||||
""".strip()
|
||||
|
||||
bw_note = """
|
||||
""".strip(),
|
||||
'brainwallet': """
|
||||
BRAINWALLET NOTE:
|
||||
|
||||
To thwart dictionary attacks, it's recommended to use a strong hash preset
|
||||
with brainwallets. For a brainwallet passphrase to generate the correct
|
||||
seed, the same seed length and hash preset parameters must always be used.
|
||||
""".strip()
|
||||
""".strip(),
|
||||
'txcreate': """
|
||||
The transaction's outputs are specified on the command line, while its inputs
|
||||
are chosen from a list of the user's unpent outputs via an interactive menu.
|
||||
|
||||
If the transaction fee is not specified on the command line (see FEE
|
||||
SPECIFICATION below), it will be calculated dynamically using {dn}'s
|
||||
"estimatefee" function for the default (or user-specified) number of
|
||||
confirmations. If "estimatefee" fails, the user will be prompted for a fee.
|
||||
|
||||
Dynamic ("estimatefee") fees will be multiplied by the value of '--tx-fee-adj',
|
||||
if specified.
|
||||
|
||||
Ages of transactions are approximate based on an average block discovery
|
||||
interval of one per {g.proto.secs_per_block} seconds.
|
||||
|
||||
All addresses on the command line can be either {pnu} addresses or {pnm}
|
||||
addresses of the form <seed ID>:<index>.
|
||||
|
||||
To send the value of all inputs (minus TX fee) to a single output, specify
|
||||
one address with no amount on the command line.
|
||||
""".format( g=g,
|
||||
pnm=g.proj_name,
|
||||
dn=g.proto.daemon_name,
|
||||
pnu=g.proto.name.capitalize()),
|
||||
'fee': """
|
||||
FEE SPECIFICATION: Transaction fees, both on the command line and at the
|
||||
interactive prompt, may be specified as either absolute {} amounts, using
|
||||
a plain decimal number, or as satoshis per byte, using an integer followed by
|
||||
the letter 's'.
|
||||
""".format(g.coin),
|
||||
'txsign': """
|
||||
Transactions may contain both {pnm} or non-{pnm} input addresses.
|
||||
|
||||
To sign non-{pnm} inputs, a {dn} wallet dump or flat key list is used
|
||||
as the key source ('--keys-from-file' option).
|
||||
|
||||
To sign {pnm} inputs, key data is generated from a seed as with the
|
||||
{pnl}-addrgen and {pnl}-keygen commands. Alternatively, a key-address file
|
||||
may be used (--mmgen-keys-from-file option).
|
||||
|
||||
Multiple wallets or other seed files can be listed on the command line in
|
||||
any order. If the seeds required to sign the transaction's inputs are not
|
||||
found in these files (or in the default wallet), the user will be prompted
|
||||
for seed data interactively.
|
||||
|
||||
To prevent an attacker from crafting transactions with bogus {pnm}-to-{pnu}
|
||||
address mappings, all outputs to {pnm} addresses are verified with a seed
|
||||
source. Therefore, seed files or a key-address file for all {pnm} outputs
|
||||
must also be supplied on the command line if the data can't be found in the
|
||||
default wallet.
|
||||
|
||||
Seed source files must have the canonical extensions listed in the 'FileExt'
|
||||
column below:
|
||||
|
||||
{n_fmt}
|
||||
""".format( dn=g.proto.daemon_name,
|
||||
n_fmt='\n '.join(SeedSource.format_fmt_codes().splitlines()),
|
||||
pnm=g.proj_name,
|
||||
pnu=g.proto.name.capitalize(),
|
||||
pnl=g.proj_name.lower())
|
||||
}[k]
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue