Bitcoin Forum
April 28, 2024, 03:45:57 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: how to get pubkey of signature  (Read 273 times)
yoshimitsu777 (OP)
Newbie
*
Offline Offline

Activity: 72
Merit: 0


View Profile
December 20, 2022, 06:47:43 PM
 #1

it should be possible but i did not find a python lib that supports this kind of data extraction any clues?
1714275957
Hero Member
*
Offline Offline

Posts: 1714275957

View Profile Personal Message (Offline)

Ignore
1714275957
Reply with quote  #2

1714275957
Report to moderator
1714275957
Hero Member
*
Offline Offline

Posts: 1714275957

View Profile Personal Message (Offline)

Ignore
1714275957
Reply with quote  #2

1714275957
Report to moderator
If you see garbage posts (off-topic, trolling, spam, no point, etc.), use the "report to moderator" links. All reports are investigated, though you will rarely be contacted about your reports.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714275957
Hero Member
*
Offline Offline

Posts: 1714275957

View Profile Personal Message (Offline)

Ignore
1714275957
Reply with quote  #2

1714275957
Report to moderator
1714275957
Hero Member
*
Offline Offline

Posts: 1714275957

View Profile Personal Message (Offline)

Ignore
1714275957
Reply with quote  #2

1714275957
Report to moderator
BlackHatCoiner
Legendary
*
Offline Offline

Activity: 1498
Merit: 7294


Farewell, Leo


View Profile
December 20, 2022, 08:47:41 PM
Merited by pooya87 (2), ABCbits (1)
 #2

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.  Tongue

How about this?

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
pooya87
Legendary
*
Offline Offline

Activity: 3430
Merit: 10505



View Profile
December 21, 2022, 04:16:22 AM
Merited by ABCbits (1)
 #3

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
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
yoshimitsu777 (OP)
Newbie
*
Offline Offline

Activity: 72
Merit: 0


View Profile
December 25, 2022, 08:37:38 AM
Last edit: December 25, 2022, 06:19:42 PM by yoshimitsu777
 #4

i stumbled over bit which is very fast.can I use bit library for this task?

https://github.com/ofek/bit/search?q=signature

I do not think it work with bit right?maybe python-ecdsa and keys.py but i have no clue how to run and use it.any example?
riceberryrice
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
December 26, 2022, 05:23:53 AM
 #5

use this

https://github.com/Sean-Bradley/ECDSA_secp256k1_JordonMatrix_nodejs

https://asecuritysite.com/ecdsa/ecdsa_recpub
citb0in
Hero Member
*****
Offline Offline

Activity: 658
Merit: 656


Bitcoin g33k


View Profile
December 26, 2022, 08:11:08 AM
Last edit: December 26, 2022, 04:48:02 PM by citb0in
 #6


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:

Code:
$ python -m secp256k1 recpub \
-s 515fe95d0780b11633f3352deb064f1517d58f295a99131e9389da8bfacd64422513d0cd4e18a58d9f4873b592afe54cf63e8f294351d1e612c8a297b5255079 \
-i 1 \
-m hello
Quote
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:

Code:
#!/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.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
yoshimitsu777 (OP)
Newbie
*
Offline Offline

Activity: 72
Merit: 0


View Profile
January 02, 2023, 09:36:03 AM
 #7

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 Offline

Activity: 318
Merit: 34


View Profile
January 02, 2023, 01:46:44 PM
 #8

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 Offline

Activity: 72
Merit: 0


View Profile
January 02, 2023, 02:21:26 PM
 #9

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 Offline

Activity: 318
Merit: 34


View Profile
January 02, 2023, 02:32:17 PM
 #10

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 Offline

Activity: 318
Merit: 34


View Profile
January 02, 2023, 02:32:41 PM
 #11

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 Offline

Activity: 72
Merit: 0


View Profile
January 02, 2023, 02:49:05 PM
 #12

Bitcoin address: "1NLbHuJebVwUZ1XqDjsAyfTRUPwDQbemfv"
Message: "Hello, world!"
Signature: "HxhJdJzdl0W7TeL/GWJ2bCp5gGE+kLNhRfZYKfPhQdWWcuGXkWx3W60lvCM/3bfnwdYL58ZNCcx4sgohPkCrwH4="

brainless
Member
**
Offline Offline

Activity: 318
Merit: 34


View Profile
January 02, 2023, 03:25:36 PM
 #13

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 Offline

Activity: 72
Merit: 0


View Profile
January 03, 2023, 08:31:39 AM
 #14

did you find? still looking for helpful answers.
anybody knows if secp256k1 from iceland can be used for this task?
yoshimitsu777 (OP)
Newbie
*
Offline Offline

Activity: 72
Merit: 0


View Profile
January 05, 2023, 03:55:31 PM
 #15

@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:

Code:
$ 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
Code:
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
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!