Giter Club home page Giter Club logo

Comments (2)

h4x3rotab avatar h4x3rotab commented on August 25, 2024

Hi Peswani, I'm quite surprised because it's our first time to see people using Electrum as a Python library. Could you give us more information like how you run the code, so that we can easily reproduce and help figure it out?

Btw, though we do support Electrum in long term, we have another library bgoldjs-lib which is much more developer friendly. It's based on javascript, though. I'm also very happy to help if you want to know how it could be done with bgoldjs-lib.

from electrum.

zebpay-peswani avatar zebpay-peswani commented on August 25, 2024

@h4x3rotab Thanks for the information. I am working on trezor support. elecrtumg does not support it as of now .Because trezor library is in python so I've choose electrumg for referencing. I've created my own UI as well for the wallet. my issue is how can I know that the signature belong to a particular public key in case of multisig. for this I have referenced electrumg code.
The setup is simple you need to download the electrumg code and install all the dependencies. Create a new python file in lib folder and paste below code

from ecdsa import ecdsa, util
from lib.transaction import Transaction, bh2u, SECP256k1

from lib.bitcoin import Hash, MyVerifyingKey, i2o_ECPublicKey, point_to_ser
from lib.util import bfh

raw_tx = '0100000001f479528049ee4b235548a7116f5ca31c607728af3d4ac8f102c5be13e93dcca900000000b40047304402201b83bd2209bc101736f60eeec3bcc1f79d45019d1829af97f5bd3210e8d8d786022020954c15372268d299b5463e1335595221e16222aee0291509a2098a0eb7fe80414c69522103556117b3f9a92f2997529af415c2c07185b872ddf1439995eca7f3acb65c58822103917f2527fc394ae2da48ce0148d29e5b756c4d9d180a6762bbe7abe215b29a562103f03364c624889c99059902524bcd8e2b24fb09cceb2e0f895d6475ef4913676553aeffffffff02a08601000000000017a914fd80725877f902f4491a6dc733fe788c376aeff8875033f4050000000017a9149aba36d2c19b08781230a4301f364610a163fc2d8700000000'
sig = '304402201b83bd2209bc101736f60eeec3bcc1f79d45019d1829af97f5bd3210e8d8d786022020954c15372268d299b5463e1335595221e16222aee0291509a2098a0eb7fe80'


tx = Transaction(raw_tx)

sighash = Hash(bfh(tx.serialize_preimage(0)))

pubkeys, x_pubkeys = tx.get_sorted_pubkeys(tx.inputs()[0])
print(sighash.hex())
print(pubkeys)
# print(x_pubkeys)

order = ecdsa.generator_secp256k1.order()
r, s = util.sigdecode_der(bfh(sig), order)
sig_string = util.sigencode_string(r, s, order)
compressed = True

for recid in range(4):
    print(recid)
    public_key = MyVerifyingKey.from_signature(sig_string, recid, sighash, curve=SECP256k1)
    #key = i2o_ECPublicKey(public_key.pubkey, compressed=True)
    #print("=========" + key.hex() + "============")
    pubkey = bh2u(point_to_ser(public_key.pubkey.point, compressed))
    print(pubkey)
    # print(public_key.verify_digest(sig_string, sighash, sigdecode=ecdsa.util.sigdecode_string))
print(tx.signature_count())
print(sighash.hex())

The above code take reference from Transaction class in lib\transaction.py folder exact 649 line number

from electrum.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.