Bitcoin Forum
September 29, 2025, 07:20:17 PM *
News: Latest Bitcoin Core release: 29.0 [Torrent]
 
  Home Help Search Login Register More  
  Show Posts
Pages: [1]
1  Bitcoin / Electrum / Re: Using Electrum codebase in another project. on: October 02, 2017, 09:17:39 PM
Yeah. I can see that now. However, from what I can gather now, EC_KEY wants a secret not a private key. So if you pass 'BB7529C7834A210374035F50E884C6CA1E42C6DFB43004463AE3BC38A2585E19' as a paremeter, it's not going to work. How would I go about signing messages with that specific private key?.

sign_message_with_wif_privkey also requires the secret.

So let's say I generate a key through bitaddress.org which gives me WIF format, hex format and all that, how would I go about using that?.

In other side of spectrum, how would I generate a private key & its secret through electrum's source code?. All I can see is mnemonic.py which can create a seed through its make_seed method (to return a set of words) and mnemonic_to_seed which gives me a hex that looks like this:

b'\x1f\x8f\x85S\xe4\x8a\x12mL\xd5&\xe6\x11Z\xdfYAm$-kq|w\xd9\xa1\x00\xd6).L\x95\xc1q\xe6\x1b\x80\xa4w\x19\x1ah\x00[{\xab\x9f\xfe\x8b$\xcc\'a\x99;"Y\xcee(Bx\xa7p' which turns into: b'f7c4fb817c11f2e8e4a93e646168cbbf6fb74648f765b529da2d892a9eb22cbf9dde6e3810f1f28 05d5c522db262f6b3e750beb6f1e4a8bd9f6138ec324d5cfe'

However, regardless of what I pass to EC_KEY, when trying to sign it fails with:

Traceback (most recent call last):
  File "test.py", line 24, in <module>
    print(key.sign_message('Testing', False))
  File "...\src\bitcoin.py", line 739, in sign_message
    signature = self.sign(Hash(msg_magic(message)))
  File "...\src\bitcoin.py", line 731, in sign
    private_key = MySigningKey.from_secret_exponent(self.secret, curve = SECP256k1)
  File "...\Python35\lib\site-packages\ecdsa\keys.py", line 137, in from_secret_exponent
    assert 1 <= secexp < n
AssertionError
2  Bitcoin / Electrum / Using Electrum codebase in another project. on: October 02, 2017, 04:58:28 AM
Hello!

I'm in the need of using the bitcoin code base for Electrum to generate seeds, addresses, sign messages & verify messages. So I've been taking a look at the the code and I'm slightly confused.

So the flow I' following is:

Use Mnemonic.py to generate new seed, use new seed generate private key, create a EC_KEY object from bitcoin.py then use its sign_message & verify_message class methods to do the whole verifying with said key. I know that I can also use the verify_message function to verify any messages.

However, it's throwing several errors:

This is the verify_message:

assert bytes failed [<class 'str'>, <class 'str'>]
Traceback (most recent call last):
  File "test.py", line 8, in <module>
    print(bitcoin.verify_message('19M16LN1k5Emc8qBuDEYv9Aggpe2ttuABk', 'TEST', '19M16LN1k5Emc8qBuDEYv9Aggpe2ttuABk H6jdr/wEW/E8mBYGwIdDOGJLBYyou9kMHT2GCzKaKsJsjjw9Fd4cj1fI2/wbAiRDkuedcd0DZEDxpnEvbYap+DY='))
  File "...\src\bitcoin.py", line 597, in verify_message
    assert_bytes(sig, message)
  File "...\src\util.py", line 255, in assert_bytes
    assert isinstance(x, (bytes, bytearray))
AssertionError

EC_KEY.sign_message:

Traceback (most recent call last):
  File "test.py", line 9, in <module>
    key = bitcoin.EC_KEY('L4xnRyP8ARQHZ1BwVkUVfk8sMkXsyBJxd9zhEMXci6NjHkFd9ewp')
  File "...\src\bitcoin.py", line 722, in __init__
    secret = string_to_number(k)
  File "...\Python\Python35\lib\site-packages\ecdsa\util.py", line 175, in string_to_number
    return int(binascii.hexlify(string), 16)
TypeError: a bytes-like object is required, not 'str'


I can't for the life of me figure out what's wrong, considering I'm not changing anything from the codebase.


Any help is appreciated. Cheers!
Pages: [1]
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!