Skip to content

Instantly share code, notes, and snippets.

@ccastromar
Last active February 17, 2020 20:12
Show Gist options
  • Save ccastromar/6bd6da81bb3e2df5cd8c6ef35dd718f5 to your computer and use it in GitHub Desktop.
Save ccastromar/6bd6da81bb3e2df5cd8c6ef35dd718f5 to your computer and use it in GitHub Desktop.
Iteración 1
# Copyright 2020 Carlos Castro Martos
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
from ecdsa import SigningKey
from ecdsa import SECP256k1
import hashlib
from base58 import b58encode
def gen_keypair():
priv = SigningKey.generate(curve=SECP256k1)
pub = priv.get_verifying_key()
return priv, pub
def get_keypair():
priv = SigningKey.generate(curve=SECP256k1)
print("privk:", priv.to_string().hex(), len(priv.to_string()))
pub = priv.get_verifying_key().to_string()
print("step1:", pub.hex(), len(pub))
stp2 = hashlib.sha256(pub).digest()
print("step2:", stp2.hex(), len(stp2))
rpub = hashlib.new('ripemd160', stp2).digest()
print("step3:", rpub.hex(), len(rpub))
adr = bytearray(rpub)
# testnet adr.insert(0, 111)
adr.insert(0,00)
print("step4:", adr.hex(), len(adr))
stp5 = hashlib.sha256(adr).digest()
print("step5:", stp5.hex(), len(stp5))
stp6 = hashlib.sha256(stp5).digest()
print("step6:", stp6.hex(), len(stp6))
chksum = stp6[0:4]
print("chsum:", chksum.hex(), len(chksum))
adr.extend(chksum)
print("step8:", adr.hex(), len(adr))
myadr = b58encode(bytes(adr))
print("myadr:",myadr, len(myadr))
if __name__ == "__main__":
get_keypair()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment