yoshimitsu777 (OP)
Newbie
Offline
Activity: 72
Merit: 0
|
|
December 20, 2022, 06:47:43 PM |
|
it should be possible but i did not find a python lib that supports this kind of data extraction any clues?
|
|
|
|
|
|
|
|
There are several different types of Bitcoin clients. The most secure are full nodes like Bitcoin Core, which will follow the rules of the network no matter what miners do. Even if every miner decided to create 1000 bitcoins per block, full nodes would stick to the rules and reject those blocks.
|
|
|
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
|
|
|
BlackHatCoiner
Legendary
Online
Activity: 1512
Merit: 7364
Farewell, Leo
|
I'm not a cryptography expert, but I know that you can't do that with just the signature. You need at least the signature and the message that was signed (curve details asides). If there's no library that does this operation (I highly doubt, but if), you'll have to implement the paragraph 4.1.6 from this paper: https://www.secg.org/sec1-v2.pdf. You're already starting to sweat, I can feel it. You better do some good search for already implemented code. How about this?
|
. .HUGE. | | | | | | █▀▀▀▀ █ █ █ █ █ █ █ █ █ █ █ █▄▄▄▄ | ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ . CASINO & SPORTSBOOK ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ | ▀▀▀▀█ █ █ █ █ █ █ █ █ █ █ █ ▄▄▄▄█ | | |
|
|
|
pooya87
Legendary
Offline
Activity: 3444
Merit: 10558
|
|
December 21, 2022, 04:16:22 AM |
|
Look inside any bitcoin library that has the "message verification" function implemented (which is almost all of them) then follow that code to find a method that performs public key recovery using the signature and the message (hash) before it verifies the signature against that public key. That is how you recover public keys from ECDSA signatures.
|
. .BLACKJACK ♠ FUN. | | | ███▄██████ ██████████████▀ ████████████ █████████████████ ████████████████▄▄ ░█████████████▀░▀▀ ██████████████████ ░██████████████ █████████████████▄ ░██████████████▀ ████████████ ███████████████░██ ██████████ | | CRYPTO CASINO & SPORTS BETTING | | │ | | │ | ▄▄███████▄▄ ▄███████████████▄ ███████████████████ █████████████████████ ███████████████████████ █████████████████████████ █████████████████████████ █████████████████████████ ███████████████████████ █████████████████████ ███████████████████ ▀███████████████▀ ███████████████████ | | .
|
|
|
|
|
riceberryrice
Newbie
Offline
Activity: 3
Merit: 0
|
|
December 26, 2022, 05:23:53 AM |
|
|
|
|
|
citb0in
|
|
December 26, 2022, 08:11:08 AM Last edit: December 26, 2022, 04:48:02 PM by citb0in |
|
My understanding is that the example demonstrated is not what OP is looking for. In the example shown, the private key is created first and everything that follows is based on it. But the OP does not know the private key, he wants to extract the pubkey from an existing signature without knowing the private key. @yoshimitsu777: have a look at https://pypi.org/project/secp256k1/, there is a function "recpub" which you can use comfortably and it does exactly what you are looking for. Example: $ python -m secp256k1 recpub \ -s 515fe95d0780b11633f3352deb064f1517d58f295a99131e9389da8bfacd64422513d0cd4e18a58d9f4873b592afe54cf63e8f294351d1e612c8a297b5255079 \ -i 1 \ -m hello
Public key: 02477ce3b986ab14d123d6c4167b085f4d08c1569963a0201b2ffc7d9d6086d2f3
I do not understand what the switch -i 1 stands for, but the result seems to be correct. I tried to implement the whole thing in Python using the ecdsa library. Here is my approach: #!/usr/bin/env python3 # 2022-Dec-26 by citb0in
import hashlib from ecdsa import SigningKey, VerifyingKey, SECP256k1 from ecdsa.util import sigencode_der, sigdecode_der
# private key in hex, 32 bytes privateKeyHex = "2bb80d537b1da3e38bd30361aa855686bde0eacd7162fef6a25fe97bf527a25b"
# convert private key from hex to bytes privateKeyBytes = bytes.fromhex(privateKeyHex)
# create a SigningKey object of the private key privateKey = SigningKey.from_string(privateKeyBytes, curve=SECP256k1)
# get the associated public key publicKey = privateKey.get_verifying_key()
# message to sign message = "hello"
# calculate the hash of that message messageHash = hashlib.sha256(message.encode("utf-8")).digest()
# create the signature signature = privateKey.sign(messageHash, sigencode=sigencode_der)
# encode signatur in hex signatureHex = signature.hex()
# show some output print(f"privKey in hex: {privateKeyHex}") print(f"SigningKey object: {privateKey}") print(f"pubKey in hex: {publicKey}") print(f"message: {message}") print(f"messageHash: {messageHash}") print(f"Signature: {signature}") print(f"Signature in hex: {signatureHex}") # output is "3045022075ace5b099991073ef11947127249d0c43f16e1069762360ae1b892b13aeffb50221009792e26181f84f1882944626f669fdfc8eb0c63e80058e498ff56ee5ac1e6041" but is wrong
# the correct and expected signatureHex should be: signatureHex = "304502210095ade2b0fd9caa90e4993e59232b774e4dc2082fdb8a30267abf21fc6a076715022016d762b4a23e30e8151f2852e88f6beebe65290266aafbbd0cbf2c1f6b3dc78c" print(f"correct signature in hex should be: {signatureHex}") # verify signature with pubKey try: publicKey.verify(signature, message, hashlib.sha256, sigdecode=sigdecode_der) print("Signature is valid.") except: print("Invalid signature!")
Unfortunately, the generated signature is not correct, I would have expected something else. Even if I write the correct signature into the variable, I still get "Invalid signature" as error message. Where do I have a (thinking) error ?
|
. .HUGE. | | | | | | █▀▀▀▀ █ █ █ █ █ █ █ █ █ █ █ █▄▄▄▄ | ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ . CASINO & SPORTSBOOK ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ | ▀▀▀▀█ █ █ █ █ █ █ █ █ █ █ █ ▄▄▄▄█ | | |
|
|
|
yoshimitsu777 (OP)
Newbie
Offline
Activity: 72
Merit: 0
|
|
January 02, 2023, 09:36:03 AM |
|
is this available for python? thanks citb0in but i get the same error as you. yes you are right.i do now know the private key only signature and message and the address. how can we fix this to have a python program that can make this conversion to pubkey without knowing the private key?
|
|
|
|
brainless
Member
Offline
Activity: 316
Merit: 34
|
|
January 02, 2023, 01:46:44 PM |
|
is this available for python? thanks citb0in but i get the same error as you. yes you are right.i do now know the private key only signature and message and the address. how can we fix this to have a python program that can make this conversion to pubkey without knowing the private key? you mean RSZ to pubkey ?
|
13sXkWqtivcMtNGQpskD78iqsgVy9hcHLF
|
|
|
yoshimitsu777 (OP)
Newbie
Offline
Activity: 72
Merit: 0
|
|
January 02, 2023, 02:21:26 PM |
|
i dont know what RSZ is. i have signature,message and bitcoin address. i want pubkey, if possible in small python script
|
|
|
|
brainless
Member
Offline
Activity: 316
Merit: 34
|
|
January 02, 2023, 02:32:17 PM |
|
i dont know what RSZ is. i have signature,message and bitcoin address. i want pubkey, if possible in small python script
write here you have information , which you want convert to pubkey
|
13sXkWqtivcMtNGQpskD78iqsgVy9hcHLF
|
|
|
brainless
Member
Offline
Activity: 316
Merit: 34
|
|
January 02, 2023, 02:32:41 PM |
|
i dont know what RSZ is. i have signature,message and bitcoin address. i want pubkey, if possible in small python script
write here you have information , which you want convert to pubkey write signature,message and bitcoin address
|
13sXkWqtivcMtNGQpskD78iqsgVy9hcHLF
|
|
|
yoshimitsu777 (OP)
Newbie
Offline
Activity: 72
Merit: 0
|
|
January 02, 2023, 02:49:05 PM |
|
Bitcoin address: "1NLbHuJebVwUZ1XqDjsAyfTRUPwDQbemfv" Message: "Hello, world!" Signature: "HxhJdJzdl0W7TeL/GWJ2bCp5gGE+kLNhRfZYKfPhQdWWcuGXkWx3W60lvCM/3bfnwdYL58ZNCcx4sgohPkCrwH4="
|
|
|
|
brainless
Member
Offline
Activity: 316
Merit: 34
|
|
January 02, 2023, 03:25:36 PM |
|
Bitcoin address: "1NLbHuJebVwUZ1XqDjsAyfTRUPwDQbemfv" Message: "Hello, world!" Signature: "HxhJdJzdl0W7TeL/GWJ2bCp5gGE+kLNhRfZYKfPhQdWWcuGXkWx3W60lvCM/3bfnwdYL58ZNCcx4sgohPkCrwH4="
long time ago i converted sign messages to transaction , RSZ generate, and then to pubkey, need to find python scripts inside my big bank, you may study this old topic here https://bitcointalk.org/index.php?topic=5192074.0
|
13sXkWqtivcMtNGQpskD78iqsgVy9hcHLF
|
|
|
yoshimitsu777 (OP)
Newbie
Offline
Activity: 72
Merit: 0
|
|
January 03, 2023, 08:31:39 AM |
|
did you find? still looking for helpful answers. anybody knows if secp256k1 from iceland can be used for this task?
|
|
|
|
yoshimitsu777 (OP)
Newbie
Offline
Activity: 72
Merit: 0
|
|
January 05, 2023, 03:55:31 PM |
|
@yoshimitsu777: have a look at https://pypi.org/project/secp256k1/, there is a function "recpub" which you can use comfortably and it does exactly what you are looking for. Example: $ python -m secp256k1 recpub \ -s 515fe95d0780b11633f3352deb064f1517d58f295a99131e9389da8bfacd64422513d0cd4e18a58d9f4873b592afe54cf63e8f294351d1e612c8a297b5255079 \ -i 1 \ -m hello
Public key: 02477ce3b986ab14d123d6c4167b085f4d08c1569963a0201b2ffc7d9d6086d2f3 but how works?look my message and signature is Bitcoin address: "1NLbHuJebVwUZ1XqDjsAyfTRUPwDQbemfv" Message: "Hello, world!" Signature: "HxhJdJzdl0W7TeL/GWJ2bCp5gGE+kLNhRfZYKfPhQdWWcuGXkWx3W60lvCM/3bfnwdYL58ZNCcx4sgohPkCrwH4="
this is not accepted by tool i get error python3 -m secp256k1 recpub -s HxhJdJzdl0W7TeL/GWJ2bCp5gGE+kLNhRfZYKfPhQdWWcuGXkWx3W60lvCM/3bfnwdYL58ZNCcx4sgohPkCrwH4= -i 1 -m "Hello, world!" Traceback (most recent call last): File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/lib/python3.10/runpy.py", line 86, in _run_code exec(code, run_globals) File "/home/yin4/.local/lib/python3.10/site-packages/secp256k1/__main__.py", line 7, in <module> main() File "/home/yin4/.local/lib/python3.10/site-packages/secp256k1/__init__.py", line 543, in main sys.exit(_main_cli(args, sys.stdout, enc)) File "/home/yin4/.local/lib/python3.10/site-packages/secp256k1/__init__.py", line 491, in _main_cli sig_raw = bytes(bytearray.fromhex(args.signature)) ValueError: non-hexadecimal number found in fromhex() arg at position 0
please somebody explain what is correct way to use this tool correctly. do i need to convert signature to something else before input into command line? where do i enter bitcoin address? please show instruction
|
|
|
|
|