Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to figure out how private hex keys and public hex keys should be used from WIF private key (52 character long) #134

Open
shbhmbnsl1 opened this issue Aug 5, 2023 · 0 comments

Comments

@shbhmbnsl1
Copy link

shbhmbnsl1 commented Aug 5, 2023

This is a follow up issue of #118

Here I was facing issue in sending litecoin using simple spend api to p2wpkh style litecoin addresses because it seems to be a problem in simple spend api of blockcypher that it cannot let us send funds to those kind of wallets. (Has there been any fix for it?)

Regardless, I tried the another approach of creating unsigned transaction, then signing the transaction but I am not able to understand what privatekeyhex and publickey hex values should be for the make_tx_signatures function call? To begin with, I have a WIF private key for my litecoin wallet (this is 52 character long key) and a sender litecoin address.

A working example should be good.

Here is my code

import bitcoin
from blockcypher import create_unsigned_tx
from blockcypher import make_tx_signatures
from blockcypher import broadcast_signed_transaction
import base58
from coincurve import PrivateKey

API_KEY = 'my_api_key'

def priv_to_pub(priv_key_hex):
    private_key = PrivateKey.from_hex(priv_key_hex)
    return private_key.public_key.format().hex()

private_key_WIF = 'my_private_key_wif_52_character_long'
first_encode = base58.b58decode(private_key_WIF)

# Not sure how to get the hex from the 52 character private key, this works for 51 but not for 52
hexStr = first_encode.hex()
hexStr = hexStr[:-8]
hexStr = hexStr[2:]

inputs = [{'address': 'LU53RhwffkxLTgby5nE3YJ9LZotnhthwgV'}, ]
outputs = [{'address': 'ltc1q535aq2q3k6rm5atamgesqd49zu7ckmlj45lmpp', 'value': 1000000}]
unsigned_tx = create_unsigned_tx(inputs=inputs, outputs=outputs, coin_symbol='ltc', api_key=API_KEY)

pubkey_list = [priv_to_pub(hexStr)]
privkey_list = [hexStr]

tx_signatures = make_tx_signatures(txs_to_sign=unsigned_tx['tosign'], privkey_list=privkey_list, pubkey_list=pubkey_list)

print(tx_signatures)

print(broadcast_signed_transaction(unsigned_tx=unsigned_tx, signatures=tx_signatures, pubkeys=pubkey_list, api_key=API_KEY))

I get this error 'ValueError: Secret scalar must be greater than 0 and less than 115792089237316195423570985008687907852837564279074904382605163141518161494337.
' when converting private key to public key.

Please suggest some solution to this - I am stuck for a long time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@shbhmbnsl1 and others