Created
December 27, 2021 04:01
-
-
Save celsoagra/29f0fefbdb88b0222d001a1faf55709e to your computer and use it in GitHub Desktop.
Wallet in python language
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib,binascii,codecs,base58,ecdsa | |
class Wallet(object): | |
def __init__(self): | |
""" | |
private key | |
public key | |
address | |
https://github.com/burakcanekici/BitcoinAddressGenerator | |
https://medium.com/coinmonks/bitcoin-address-generation-on-python-e267df5ff3a3 | |
""" | |
dataPem = ""; | |
with open('walletkey.pem', 'r') as file: | |
dataPem = file.read() | |
print("{}".format(dataPem)) | |
privateKey = ecdsa.SigningKey.from_pem(dataPem) | |
print("ECDSA Private Key: ", privateKey.to_string().hex()) | |
ecdsaPublicKey = '04' + privateKey.get_verifying_key().to_string().hex() | |
print("ECDSA Public Key: ", ecdsaPublicKey) | |
hash256FromECDSAPublicKey = hashlib.sha256(binascii.unhexlify(ecdsaPublicKey)).hexdigest() | |
print("SHA256(ECDSA Public Key): ", hash256FromECDSAPublicKey) | |
ridemp160FromHash256 = hashlib.new('ripemd160', binascii.unhexlify(hash256FromECDSAPublicKey)) | |
print("RIDEMP160(SHA256(ECDSA Public Key)): ", ridemp160FromHash256.hexdigest()) | |
prependNetworkByte = '00' + ridemp160FromHash256.hexdigest() | |
print("Prepend Network Byte to RIDEMP160(SHA256(ECDSA Public Key)): ", prependNetworkByte) | |
hash = prependNetworkByte | |
for x in range(1,3): | |
hash = hashlib.sha256(binascii.unhexlify(hash)).hexdigest() | |
print("\t|___>SHA256 #", x, " : ", hash) | |
cheksum = hash[:8] | |
print("Checksum(first 4 bytes): ", cheksum) | |
appendChecksum = prependNetworkByte + cheksum | |
print("Append Checksum to RIDEMP160(SHA256(ECDSA Public Key)): ", appendChecksum) | |
self._bitcoinAddress = base58.b58encode(binascii.unhexlify(appendChecksum)) | |
print("Bitcoin Address: ", self._bitcoinAddress.decode('utf8')) | |
def _send(self): | |
""" | |
Create transaction | |
sign transaction | |
""" | |
raise AttributeError("Não implementado") | |
def _balance(self): | |
""" | |
show balances | |
""" | |
raise AttributeError("Não implementado") | |
def _address(self): | |
""" | |
show address | |
""" | |
return self._bitcoinAddress.decode('utf8') | |
wallet = Wallet() | |
print(wallet._address()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-----BEGIN PRIVATE KEY----- | |
MIGNAgEAMBAGByqGSM49AgEGBSuBBAAKBHYwdAIBAQQgEruPALWble03fp01nL45 | |
ibaXNefVFXVh4PennCux1fmgBwYFK4EEAAqhRANCAASnSF+TXum0ZI6I4W8afjtB | |
6qIRbuHhXHgnTM2j9CZcroSvR5JZXXDI02+IdEaT8LkZ5UMb4sxLvWy1B5rXAZ5n | |
-----END PRIVATE KEY----- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment