Skip to content

Commit

Permalink
add signmessage to wallet, update version
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamISZ committed Jun 22, 2017
1 parent cd80f72 commit 28912ac
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 14 deletions.
2 changes: 1 addition & 1 deletion jmbase/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


setup(name='joinmarketbase',
version='0.2.0',
version='0.2.1',
description='Joinmarket client library for Bitcoin coinjoins',
url='http://github.com/AdamISZ/joinmarket-clientserver/jmbase',
author='Adam Gibson',
Expand Down
15 changes: 9 additions & 6 deletions jmbitcoin/jmbitcoin/secp256k1_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,12 @@ def from_wif_privkey(wif_priv, compressed=True, vbyte=0):
raise Exception("Private key has incorrect compression byte")
return safe_hexlify(bin_key)

def ecdsa_sign(msg, priv, usehex=True):
def ecdsa_sign(msg, priv, formsg=False, usehex=True):
hashed_msg = message_sig_hash(msg)
if usehex:
#arguments to raw sign must be consistently hex or bin
hashed_msg = binascii.hexlify(hashed_msg)
sig = ecdsa_raw_sign(hashed_msg, priv, usehex, rawmsg=True)
sig = ecdsa_raw_sign(hashed_msg, priv, usehex, rawmsg=True, formsg=formsg)
#note those functions only handles binary, not hex
if usehex:
sig = binascii.unhexlify(sig)
Expand Down Expand Up @@ -365,7 +365,8 @@ def ecdsa_raw_sign(msg,
usehex,
rawpriv=True,
rawmsg=False,
usenonce=None):
usenonce=None,
formsg=False):
'''Take the binary message msg and sign it with the private key
priv.
By default priv is just a 32 byte string, if rawpriv is false
Expand All @@ -386,17 +387,19 @@ def ecdsa_raw_sign(msg,
newpriv = secp256k1.PrivateKey(p, raw=True, ctx=ctx)
else:
newpriv = secp256k1.PrivateKey(priv, raw=False, ctx=ctx)
if formsg:
sig = newpriv.ecdsa_sign_recoverable(msg, raw=rawmsg)
s, rid = newpriv.ecdsa_recoverable_serialize(sig)
return chr(31+rid) + s
#Donations, thus custom nonce, currently disabled, hence not covered.
if usenonce: #pragma: no cover
elif usenonce: #pragma: no cover
raise NotImplementedError
#if len(usenonce) != 32:
# raise ValueError("Invalid nonce passed to ecdsa_sign: " + str(
# usenonce))
#nf = ffi.addressof(_noncefunc.lib, "nonce_function_rand")
#ndata = ffi.new("char [32]", usenonce)
#usenonce = (nf, ndata)
if usenonce: #pragma: no cover
raise NotImplementedError
#sig = newpriv.ecdsa_sign(msg, raw=rawmsg, custom_nonce=usenonce)
else:
#partial fix for secp256k1-transient not including customnonce;
Expand Down
2 changes: 1 addition & 1 deletion jmbitcoin/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


setup(name='joinmarketbitcoin',
version='0.2.0',
version='0.2.1',
description='Joinmarket client library for Bitcoin coinjoins',
url='http://github.com/AdamISZ/joinmarket-clientserver/jmbitcoin',
author='Adam Gibson',
Expand Down
4 changes: 2 additions & 2 deletions jmclient/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@


setup(name='joinmarketclient',
version='0.2.0',
version='0.2.1',
description='Joinmarket client library for Bitcoin coinjoins',
url='http://github.com/AdamISZ/joinmarket-clientserver/jmclient',
author='Adam Gibson',
author_email='[email protected]',
license='GPL',
packages=['jmclient'],
install_requires=['joinmarketbase==0.2.0'],
install_requires=['joinmarketbase==0.2.1'],
zip_safe=False)
4 changes: 2 additions & 2 deletions jmdaemon/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@


setup(name='joinmarketdaemon',
version='0.2.0',
version='0.2.1',
description='Joinmarket client library for Bitcoin coinjoins',
url='http://github.com/AdamISZ/joinmarket-clientserver/jmdaemon',
author='Adam Gibson',
author_email='[email protected]',
license='GPL',
packages=['jmdaemon'],
install_requires=['txsocksx', 'pyopenssl', 'libnacl', 'joinmarketbase==0.2.0'],
install_requires=['txsocksx', 'pyopenssl', 'libnacl', 'joinmarketbase==0.2.1'],
zip_safe=False)
19 changes: 17 additions & 2 deletions scripts/wallet-tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
'privkeys are spaces or commas separated. (dumpprivkey) Export '
'a single private key, specify an hd wallet path (listwallets) '
'Lists all wallets with creator and timestamp. (history) Show '
'all historical transaction details. Requires Bitcoin Core.')
'all historical transaction details. Requires Bitcoin Core.\n'
'signmessage\t\tSign a message with the private key from an address\n'
'\t\t\tin the wallet. Use with -H and specify an HD wallet\n'
'\t\t\tpath for the address.')

parser = OptionParser(usage='usage: %prog [options] [wallet file] [method]',
description=description)
Expand Down Expand Up @@ -92,7 +95,7 @@
methods = ['display', 'displayall', 'summary', 'showseed', 'importprivkey',
'history', 'showutxos']
methods.extend(noseed_methods)
noscan_methods = ['showseed', 'importprivkey', 'dumpprivkey']
noscan_methods = ['showseed', 'importprivkey', 'dumpprivkey', 'signmessage']

if len(args) < 1:
parser.error('Needs a wallet file or method')
Expand Down Expand Up @@ -316,6 +319,18 @@ def cus_print(s):
print(' ')
i += 1
print(str(i - 1) + ' Wallets have been found.')
elif method == 'signmessage':
message = args[2]
if options.hd_path.startswith('m/0/'):
m, forchange, k = [int(y) for y in options.hd_path[4:].split('/')]
key = wallet.get_key(m, forchange, k)
addr = btc.privkey_to_address(key, magicbyte=get_p2pk_vbyte())
print('Using address: ' + addr)
else:
print('%s is not a valid hd wallet path' % options.hd_path)
sig = btc.ecdsa_sign(message, key, formsg=True)
print("Signature: " + str(sig))
print("To verify this in Bitcoin Core use the RPC command 'verifymessage'")
elif method == 'history':
#sort txes in a db because python can be really bad with large lists
con = sqlite3.connect(":memory:")
Expand Down

0 comments on commit 28912ac

Please sign in to comment.