Title: I need help to generate my own key pair Post by: boldfi on May 03, 2024, 09:42:53 AM As a Newbie, i DCA-ed BTC for the past 6 months on Binance :o
I don't want to use any CEX no more. I want my keys. So based on internet articles and a bit of chat-gpt :o i could generate my key pair locally as follow: Use secp256k1 elliptic curve to generate a priv key: > openssl ecparam -genkey -name secp256k1 -noout -out privatekey.pem Find matching pub key on the curve: > openssl ec -in privatekey.pem -pubout -out publickey.pem Derive an address in python: from ecdsa import VerifyingKey import hashlib import base58 def generate_bitcoin_address_from_public_key(public_key_bytes): public_key = VerifyingKey.from_pem(public_key_bytes) # Hash the public key hash_pubkey = hashlib.sha256(public_key.to_string()).digest() hash_pubkey_ripemd160 = hashlib.new('ripemd160', hash_pubkey).digest() version_byte = b'\x00' hash_pubkey_with_version = version_byte + hash_pubkey_ripemd160 checksum = hashlib.sha256(hashlib.sha256(hash_pubkey_with_version).digest()).digest()[:4] binary_address = hash_pubkey_with_version + checksum bitcoin_address = base58.b58encode(binary_address).decode('utf-8') return bitcoin_address with open('publickey.pem', 'r') as file: public_key_pem = file.read() bitcoin_address = generate_bitcoin_address_from_public_key(public_key_pem.encode('utf-8')) print("Bitcoin Address:", bitcoin_address) This got me the following: -----BEGIN EC PRIVATE KEY----- MHQCAQEEIDRd6/hvSUmI3jubQv+FEve/bkPRBi4d4ddCKf1Cdz8yoAcGBSuBBAAK oUQDQgAEr6/Q3oyxMl6Fourug/AVW2a/WyrhoGDPP0iXBPp2rEKSRF+p1G5DL7BL gFsOOBN/U0IT3iiw7agk/DCTxEO0wQ== gFsOOBN/U0IT3iiw7agk/DCTxEO0wQ== -----END EC PRIVATE KEY----- -----BEGIN PUBLIC KEY----- MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEr6/Q3oyxMl6Fourug/AVW2a/WyrhoGDP P0iXBPp2rEKSRF+p1G5DL7BLgFsOOBN/U0IT3iiw7agk/DCTxEO0wQ== -----END PUBLIC KEY----- Bitcoin Address: 12XjArifNjhfNWDo5MBZaBMXjyYVVbVgxZ So, did i do the correct thing ? Is it safe to transfer my BTC to an address generated this way (not this one ofc) Or is there a better way to do it ? Also keys seem to be base64 encoded, should i save it in another form ? Thnaks in advance. Title: Re: I need help to generate my own key pair Post by: hd49728 on May 03, 2024, 10:22:06 AM You complicate your life because there are open source Bitcoin softwares to use
Bitcoin Core, Electrum and more. [General] Bitcoin Wallets - Which, what, why? (https://bitcointalk.org/index.php?topic=1631151.0) You can use the wallet software to create your wallet, backup, and use it to store your bitcoin. [GUIDE] How to Safely Download and Verify Electrum (https://bitcointalk.org/index.php?topic=5240594.0) Title: Re: I need help to generate my own key pair Post by: boldfi on May 03, 2024, 10:59:43 AM You complicate your life because there are open source Bitcoin softwares to use Bitcoin Core, Electrum and more. [General] Bitcoin Wallets - Which, what, why? (https://bitcointalk.org/index.php?topic=1631151.0) You can use the wallet software to create your wallet, backup, and use it to store your bitcoin. [GUIDE] How to Safely Download and Verify Electrum (https://bitcointalk.org/index.php?topic=5240594.0) Thanks for the documentation. I'm checking it out rn. How to keep my DCA going on when migrating to a cold/paper wallet ? Do i still have to buy through a CEX manually every week ? Title: Re: I need help to generate my own key pair Post by: Amphenomenon on May 03, 2024, 11:17:54 AM Thanks for the documentation. I'm checking it out rn. Actually its more better to go Hardware wallet which is still the best option for cold wallet and i will advice you to go for Trezor hardware wallet, this thread will be helpful in your choice of picking though 55 Hardware Wallets, compared feature by feature (https://bitcointalk.org/index.php?topic=5416497.0)How to keep my DCA going on when migrating to a cold/paper wallet ? Quote Do i still have to buy through a CEX manually every week ? Actually this is up to you, though there are Decentralise exchanges like peachbitcoin.com and others you can find here https://kycnot.me/this also will be helpful in addition to what hd49728 shared Protect yourself from fake wallet software (guide) (https://bitcointalk.org/index.php?topic=5471306.msg63039976#msg63039976) Title: Re: I need help to generate my own key pair Post by: nc50lc on May 04, 2024, 11:39:16 AM Also keys seem to be base64 encoded, should i save it in another form ? The standard paper wallet backup for Bitcoin private keys is "WIF" (wallet import format).More info: learnmeabitcoin.com/technical/keys/private-key/wif/ (http://learnmeabitcoin.com/technical/keys/private-key/wif/) For public key, hex with compression prefix (pubKey isn't usually required to write in the backup). More info: learnmeabitcoin.com/technical/keys/public-key/ (http://learnmeabitcoin.com/technical/keys/public-key/) However, those base64 strings when decoded don't look right, Better stick to open-source software/hardware wallets than use the output from that script. How to keep my DCA going on when migrating to a cold/paper wallet ? Do i still have to buy through a CEX manually every week ? You can still use what you're familiar with (CEX to purchase) or use P2P.But I would only suggest you to send bitcoin from the Exchange to your cold storage wallet when you accumulate a significant amount. That's not only to minimize the accumulated fee when sending from exchange, but also to minimize the number of UTXO your wallet will be keeping. The goal is to keep only a few higher value unspent outputs so that your wallet wouldn't have to use a lot of inputs in your future transactions. The lower number of inputs, the lower the transaction's size will be; lower the transaction size results to lower absolute fee. If you want to go P2P, you can use P2P exchanges available in your Country or purchase from users in this forum in Currency Exchange board. Link: http://bitcointalk.org/index.php?board=53.0 (make use the "Trust system" since this is quite risky) |