def wifToPrivateKey(s): if s[0] == "K" or s[0] == "L" or s[0] == "c": b = utils.base58CheckDecode(s, pk_for_compressed=True) print "aa" else: b = utils.base58CheckDecode(s) return b.encode('hex')
def getSignableTxn(parsed, compressed='no'): first, sig, pub, rest = parsed #inputAddr = utils.base58CheckDecode(keyUtils.pubKeyToAddr(pub.decode())) print('first: ', first, 'sig: ', sig, 'pub: ', pub, 'rest: ', rest) #if (compressed=='yes'): # inputAddr = codecs.encode(utils.base58CheckDecode(keyUtils.pubKeyToAddr('03' + pub[2:66],net= 'test', compressed='yes')),'hex').decode() # print('pubk ','03' + pub[2:66] ) #else: # inputAddr = codecs.encode(utils.base58CheckDecode(keyUtils.pubKeyToAddr(pub)),'hex').decode() inputAddr = codecs.encode( utils.base58CheckDecode(keyUtils.pubKeyToAddr(pub)), 'hex').decode() #inputAddr = codecs.encode(utils.base58CheckDecode('moyDyvi7VeAhZnGEWtvE62PoDdmoRXRRkf'),'hex').decode() print('pub uncompressed: ', keyUtils.pubKeyToAddr(pub, net='test')) print('pub compressed: ', keyUtils.pubKeyToAddr('03' + pub[2:66], net='test')) print("inputAddr:", keyUtils.pubKeyToAddr('02' + pub[2:66], net='test')) print( 'a:', codecs.encode( utils.base58CheckDecode('1MMMMSUb1piy2ufrSguNUdFmAcvqrQF8M5'), 'hex').decode()) print( 'b:', codecs.encode( utils.base58CheckDecode('muwc2rRij1XuJZ5JqsevtjCvqMw9CenJfK'), 'hex').decode()) print("inputAddr:", inputAddr) #inputAddr = 'msZwQEA3dYTXDEUjHgfXkGSkLXpfEpLZEA' #print(codecs.encode(inputAddr,'hex').decode()) #return first + "1976a914" + inputAddr.encode('hex') + "88ac" + rest + "01000000" return first.encode('utf-8') + b"1976a914" + inputAddr.encode( 'utf-8') + b"88ac" + rest.encode('utf-8') + b"01000000"
def test_pairs3(self): # Can import into multibit # http://bitaddress.org wallet_private = "5J8PhneLEaL9qEPvW5voRgrELeXcmM12B6FbiA9wZAwDMnJMb2L" wallet_addr = "1Q2SuNLDXDtda7DPnBTocQWtUg1v4xZMrV" self.assertEqual( keyToAddr(utils.base58CheckDecode(wallet_private).encode('hex')), wallet_addr)
def test_pairs3(self): # Can import into multibit # http://bitaddress.org wallet_private = "5J8PhneLEaL9qEPvW5voRgrELeXcmM12B6FbiA9wZAwDMnJMb2L" wallet_addr = "1Q2SuNLDXDtda7DPnBTocQWtUg1v4xZMrV" wallet_private = codecs.encode(utils.base58CheckDecode(wallet_private),'hex').decode() #self.assertEqual(keyToAddr(utils.base58CheckDecode(wallet_private).encode('hex')), wallet_addr) self.assertEqual(keyToAddr(wallet_private), wallet_addr)
def test_pairs1(self): wallet_addr = "1EyBEhrriJeghX4iqATQEWDq38Ae8ubBJe" wallet_private = "8tnArBrrp4KHVjv8WA6HiX4ev56WDhqGA16XJCHJzhNH" wallet_key = utils.base256encode(utils.base58decode(wallet_private)).encode('hex') self.assertEqual(keyToAddr(wallet_key), wallet_addr) bitcoin_qt = "5Jhw8B9J9QLaMmcBRfz7x8KkD9gwbNoyBMfWyANqiDwm3FFwgGC" wallet_key = utils.base58CheckDecode(bitcoin_qt).encode('hex') self.assertEqual(keyToAddr(wallet_key), wallet_addr) wallet_key = "754580de93eea21579441b58e0c9b09f54f6005fc71135f5cfac027394b22caa" self.assertEqual(keyToAddr(wallet_key), wallet_addr)
def getSignableTxn(parsed, compressed='no'): first, sig, pub, rest = parsed #inputAddr = utils.base58CheckDecode(keyUtils.pubKeyToAddr(pub.decode())) print('first: ', first, 'sig: ', sig, 'pub: ', pub, 'rest: ', rest) #if (compressed=='yes'): # inputAddr = codecs.encode(utils.base58CheckDecode(keyUtils.pubKeyToAddr('03' + pub[2:66],net= 'test', compressed='yes')),'hex').decode() # print('pubk ','03' + pub[2:66] ) #else: # inputAddr = codecs.encode(utils.base58CheckDecode(keyUtils.pubKeyToAddr(pub)),'hex').decode() inputAddr = codecs.encode(utils.base58CheckDecode(keyUtils.pubKeyToAddr(pub)),'hex').decode() #inputAddr = codecs.encode(utils.base58CheckDecode('moyDyvi7VeAhZnGEWtvE62PoDdmoRXRRkf'),'hex').decode() print('pub uncompressed: ', keyUtils.pubKeyToAddr(pub,net='test')) print('pub compressed: ', keyUtils.pubKeyToAddr('03' + pub[2:66],net='test')) print("inputAddr:", keyUtils.pubKeyToAddr('02' +pub[2:66],net= 'test')) print('a:', codecs.encode(utils.base58CheckDecode('1MMMMSUb1piy2ufrSguNUdFmAcvqrQF8M5'),'hex').decode()) print('b:', codecs.encode(utils.base58CheckDecode('muwc2rRij1XuJZ5JqsevtjCvqMw9CenJfK'),'hex').decode()) print("inputAddr:", inputAddr) #inputAddr = 'msZwQEA3dYTXDEUjHgfXkGSkLXpfEpLZEA' #print(codecs.encode(inputAddr,'hex').decode()) #return first + "1976a914" + inputAddr.encode('hex') + "88ac" + rest + "01000000" return first.encode('utf-8') + b"1976a914" + inputAddr.encode('utf-8') + b"88ac" + rest.encode('utf-8') + b"01000000"
def test_pairs1(self): #blockchain.info wallet_addr = "1EyBEhrriJeghX4iqATQEWDq38Ae8ubBJe" wallet_private = "8tnArBrrp4KHVjv8WA6HiX4ev56WDhqGA16XJCHJzhNH" wallet_key = utils.base256encode(utils.base58decode(wallet_private)).encode('hex') self.assertEqual(keyToAddr(wallet_key), wallet_addr) # can import into multibit bitcoin_qt = "5Jhw8B9J9QLaMmcBRfz7x8KkD9gwbNoyBMfWyANqiDwm3FFwgGC" wallet_key = utils.base58CheckDecode(bitcoin_qt).encode('hex') self.assertEqual(keyToAddr(wallet_key), wallet_addr) wallet_key = "754580de93eea21579441b58e0c9b09f54f6005fc71135f5cfac027394b22caa" self.assertEqual(keyToAddr(wallet_key), wallet_addr)
def addrHashToScriptPubKey(b58str): assert(len(b58str) == 34) # 76 A9 14 (20 bytes) 88 AC return '76a914' + utils.base58CheckDecode(b58str).encode('hex') + '88ac'
def wifToPrivateKey(s): b = utils.base58CheckDecode(s) return b[0:]
def getSignableTxn(parsed): first, sig, pub, rest = parsed inputAddr = utils.base58CheckDecode(keyUtils.pubKeyToAddr(pub)) return first + "1976a914" + inputAddr.encode( 'hex') + "88ac" + rest + "01000000"
def wifToPrivateKey(s): b = utils.base58CheckDecode(s) return b.encode('hex')
def addrHashToScriptPubKey(b58str): assert(len(b58str) == 34) return ('76a914' + utils.base58CheckDecode(b58str).encode('hex') + '88ac')
def getSignableTxn(parsed): first, sig, pub, rest = parsed inputAddr = utils.base58CheckDecode(keyUtils.pubKeyToAddr(pub)) return first + "1976a914" + inputAddr.encode('hex') + "88ac" + rest + "01000000"
def addrHashToScriptPubKey(b58str): print len(b58str) assert (len(b58str) == 34) # 76 A9 14 (20 bytes) 88 AC return '76a914' + utils.base58CheckDecode(b58str).encode('hex') + '88ac'
def addrHashToScriptPubKey(b58str , net='main', compressed='no'): assert(len(b58str) == 34) # 76 A9 14 (20 bytes) 88 AC #return '76a914' + utils.base58CheckDecode(b58str).encode('hex') + '88ac' #return b'76a914' + utils.base58CheckDecode(b58str) + b'88ac' return b'76a914' + codecs.encode(utils.base58CheckDecode(b58str),'hex') + b'88ac'
def wif_to_privkey(s): b = utils.base58CheckDecode(s) return b.encode('hex')
def myRollBack(address): print 'Rollback address {}'.format(address) basedecode = utils.base58CheckDecode(address) print 'Rollback basedecode {}'.format(basedecode) hex_data = basedecode.encode('hex') print 'Rollback hexl {}'.format(hex_data) Af_hex = hex_data[:8] Bf_hex = hex_data[8:16] Cf_hex = hex_data[16:24] Df_hex = hex_data[24:32] Ef_hex = hex_data[32:40] print 'hnew {} {} {} {} {}'.format(Af_hex, Bf_hex, Cf_hex, Df_hex, Ef_hex) print 'TO DO un-add final values' Al = int('82a24ea5', 16) Bl = int('11e8ef41', 16) Cl = int('e109aea8', 16) Dl = int('e3474402', 16) El = int('302cc6dc', 16) Ar = int('5592219f', 16) Br = int('4eb93ee3', 16) Cr = int('a91d7fa6', 16) Dr = int('0c8673c2', 16) Er = int('ac4b8c30', 16) print '' print 'h_left 15 {} {} {} {} {}'.format(hex(Al), hex(Bl), hex(Cl), hex(Dl), hex(El)) print 'h_right 15 {} {} {} {} {}'.format(hex(Ar), hex(Br), hex(Cr), hex(Dr), hex(Er)) print '' X = ['' for i in range(8)] + [ int('00000080', 16), int('00000000', 16), int('00000000', 16), int('00000000', 16), int('00000000', 16), int('00000000', 16), int('00000100', 16), int('00000000', 16) ] #X[6]=int('9fd3a02e',16) Xrr = ['' for i in range(8)] + [ int('00000080', 16), int('00000000', 16), int('00000000', 16), int('00000000', 16), int('00000000', 16), int('00000000', 16), int('00000100', 16), int('00000000', 16) ] for round in range(4, 3, -1): #for round in range(4,-1,-1): print 'round {}'.format(round) for j in range(15, 10, -1): #for j in range(15,-1,-1): print 'j {}'.format(j) #left #print 'left' #Al,Bl,Cl,Dl,El,Xl=dcompression(Al,Bl,Cl,Dl,El,functionmap_left.get(round, "nothing"),X[r],K,s) Al, Bl, Cl, Dl, El, Xl = rcompression( Al, Bl, Cl, Dl, El, functionmap_left.get(round, "nothing"), X, round, j) #print '' #right #print 'right' #Ar,Br,Cr,Dr,Er,Xr=dcompression(Ar,Br,Cr,Dr,Er,functionmap_right.get(round, "nothing"),Xrr[rr],Kr,sr) #Ar,Br,Cr,Dr,Er,Xr=rcompression(Ar,Br,Cr,Dr,Er,functionmap_right.get(round, "nothing"),X,round,j) print '' print 'h_left {} {} {} {} {} {}'.format(j - 1, hex(Al), hex(Bl), hex(Cl), hex(Dl), hex(El)) print 'X {} '.format(X)