-1

How to generate pub key from prive key ? All examples and explain skip this. but i dont need steps to address etc . i only need steps from priv to pub ( compressed or not ) what using at that. if possible example or python , or simple algo what used. example i hv priv key 981F3AF336E23EEFF4384A939065C4C623E394F1AE7E4D922C045CEDC3F258D2 i want make from them pub key , (i not need generation priv key i have them!) compressed or uncompressed . what steps i need to do for make valid public key for bitcoin address .

Update sorry for my qustion , i cannot undestand this logic. i try make pub key as example with 04 uncompresed from priv key 0x64hex, i not need steps for make it base58. i stuck at that step. as example i hv some words i make from them hex 0x64digits. how i can do from them not public key as example 049f35c793522be1fdcfd50c3fb15f455cda37fb3fb779b9e4707c89a49cdf47242c3dc34778f7361a44c074a6a21e5972bbf5ca5265c9ea121ce4f2a5dc4964b6

tseries
  • 205
  • 2
  • 13
  • I just tried to fix the grammar, spelling and punctuation, but the question is a bit jumbled. In the first part it seems to me that you say you don't need instructions to get to an address, but then in the last sentence you say "what steps i need to do for make public key for bitcoin address"? Could you clarify the scope of your question please? – Murch Sep 18 '20 at 17:46
  • sorry for my qustion , i cannot undestand this logic. i try make pub key as example with 04 uncompresed from priv key 0x64hex, i not need steps for make it base58. i stuck at that step. – tseries Sep 18 '20 at 21:46

1 Answers1

1

Private key used in the example: a84860187211d36cddfb77fc7638c996b8b8a77d3e16f2e47a5172fe6e8e2be6

Converting Private Key to WIF (Ruby)


require 'digest'

Checksums use hash256 (where data is hashed twice through sha256)

def hash256(hex) binary = [hex].pack("H") hash1 = Digest::SHA256.digest(binary) hash2 = Digest::SHA256.digest(hash1) result = hash2.unpack("H")[0] return result end

def checksum(hex) hash = hash256(hex) # Hash the data through SHA256 twice return hash[0...8] # Return the first 4 bytes (8 characters) end

def base58_encode(hex) @chars = %w[ 1 2 3 4 5 6 7 8 9 A B C D E F G H J K L M N P Q R S T U V W X Y Z a b c d e f g h i j k m n o p q r s t u v w x y z ] @base = @chars.length

i = hex.to_i(16) buffer = String.new

while i > 0 remainder = i % @base i = i / @base buffer = @chars[remainder] + buffer end

#! Is it just the 00, or does 05 get converted to 3, etc.

add '1's to the start based on number of leading bytes of zeros

leading_zero_bytes = (hex.match(/^([0]+)/) ? $1 : '').size / 2

("1"*leading_zero_bytes) + buffer end

Convert Private Key to WIF

privatekey = "a84860187211d36cddfb77fc7638c996b8b8a77d3e16f2e47a5172fe6e8e2be6" extended = "80" + privatekey + "01" extendedchecksum = extended + checksum(extended) wif = base58_encode(extendedchecksum)

puts wif

Get Public Key from WIF (Python)


from bitcoinutils.setup import setup
from bitcoinutils.keys import PrivateKey, PublicKey

def main(): # setup the network setup('mainnet')

# existing WIF key
priv = PrivateKey.from_wif('L2rq82XD1P9bwnyithBaRYn7v91WxRCSraTrfbu6g86VLYsnCmbt')


# get the public key
pub = priv.get_public_key()

# compressed public key
print("Public key:", pub.to_hex(compressed=True))

if name == "main": main()

Source:

https://github.com/in3rsha/learnmeabitcoin-code/blob/master/keygenerator.rb

https://github.com/karask/python-bitcoin-utils/blob/master/examples/keys_addresses.py