def makeCryptor(privkey): privkey_bin = '\x02\xca\x00 ' + a.changebase(privkey, 16, 256, minlen=32) pubkey = a.changebase(a.privtopub(privkey), 16, 256, minlen=65)[1:] pubkey_bin = '\x02\xca\x00 ' + pubkey[:32] + '\x00 ' + pubkey[32:] cryptor = pyelliptic.ECC(curve='secp256k1', privkey=privkey_bin, pubkey=pubkey_bin) return cryptor
def makePrivCryptor(privkey): privkey_bin = '\x02\xca\x00 ' + arithmetic.changebase(privkey, 16, 256, minlen=32) pubkey = arithmetic.changebase(arithmetic.privtopub(privkey), 16, 256, minlen=65)[1:] pubkey_bin = '\x02\xca\x00 ' + pubkey[:32] + '\x00 ' + pubkey[32:] cryptor = ec.ECC(curve='secp256k1', privkey=privkey_bin, pubkey=pubkey_bin) return cryptor
def decodeWalletImportFormat(WIFstring): fullString = arithmetic.changebase(WIFstring, 58, 256) privkey = fullString[:-4] if fullString[-4:] != \ hashlib.sha256(hashlib.sha256(privkey).digest()).digest()[:4]: print( 'Major problem! When trying to decode one of your' ' private keys, the checksum failed. Here are the first' ' 6 characters of the PRIVATE key: %s', str(WIFstring)[:6]) os._exit(0) # return "" elif privkey[0] == '\x80': # checksum passed return privkey[1:] print( 'Major problem! When trying to decode one of your private keys,' ' the checksum passed but the key doesn\'t begin with hex 80.' ' Here is the PRIVATE key: %s', WIFstring) os._exit(0)
def hexToPubkey(pubkey): pubkey_raw = arithmetic.changebase(pubkey[2:], 16, 256, minlen=64) pubkey_bin = '\x02\xca\x00 ' + pubkey_raw[:32] + '\x00 ' + pubkey_raw[32:] return pubkey_bin
def makeCryptor(privkey): privkey_bin = "\x02\xca\x00 " + a.changebase(privkey, 16, 256, minlen=32) pubkey = a.changebase(a.privtopub(privkey), 16, 256, minlen=65)[1:] pubkey_bin = "\x02\xca\x00 " + pubkey[:32] + "\x00 " + pubkey[32:] cryptor = pyelliptic.ECC(curve="secp256k1", privkey=privkey_bin, pubkey=pubkey_bin) return cryptor
def hexToPubkey(pubkey): pubkey_raw = a.changebase(pubkey[2:], 16, 256, minlen=64) pubkey_bin = "\x02\xca\x00 " + pubkey_raw[:32] + "\x00 " + pubkey_raw[32:] return pubkey_bin
publicSigningKey = arithmetic.privtopub(privateSigningKey) publicEncryptionKey = arithmetic.privtopub(privateEncryptionKey) print( '\npublicSigningKey = %s\npublicEncryptionKey = %s' % (publicSigningKey, publicEncryptionKey) ) print( '\nNotice that they both begin with the \\x04 which specifies' ' the encoding type. This prefix is not send over the wire.' ' You must strip if off before you send your public key across' ' the wire, and you must add it back when you receive a public key.' ) publicSigningKeyBinary = \ arithmetic.changebase(publicSigningKey, 16, 256, minlen=64) publicEncryptionKeyBinary = \ arithmetic.changebase(publicEncryptionKey, 16, 256, minlen=64) ripe = hashlib.new('ripemd160') sha = hashlib.new('sha512') sha.update(publicSigningKeyBinary + publicEncryptionKeyBinary) ripe.update(sha.digest()) addressVersionNumber = 2 streamNumber = 1 print( '\nRipe digest that we will encode in the address: %s' % hexlify(ripe.digest()) ) returnedAddress = \