def bip32_serialize(rawtuple): vbytes, depth, fingerprint, i, chaincode, key = rawtuple if isinstance(i, int): i = struct.pack(b'>L', i) chaincode = chaincode keydata = b'\x00' + key[:-1] if vbytes in PRIVATE else key bindata = vbytes + struct.pack(b'B',depth % 256) + fingerprint + i + chaincode + keydata return base58.encode(bindata + Hash(bindata)[:4])
def test_encode_decode(self): for exp_bin, exp_base58 in load_test_vectors('base58_encode_decode.json'): exp_bin = unhexlify(exp_bin.encode('utf8')) act_base58 = encode(exp_bin) act_bin = decode(exp_base58) self.assertEqual(act_base58, exp_base58) self.assertEqual(act_bin, exp_bin)
def orchestrate_spend(self, address: ExternalAddress, selection: CoinSelection) -> str: tx = self.assemble_transaction(address, selection) psbt = self.assemble_psbt(tx, selection) signed_tx = self.serial_client.request_sign_transaction(psbt) if not signed_tx: return False self.tx_broadcast_client.broadcast_transaction(signed_tx) self.persist_spend(selection) return base58.encode(tx.GetTxid())
def bin_to_b58check(inp, magicbyte=b'\x00'): """ The magic byte (prefix byte) should be passed either as a single byte or an integer. What is returned is a string in base58 encoding, with the prefix and the checksum. """ if not isinstance(magicbyte, int): magicbyte = struct.unpack(b'B', magicbyte)[0] assert(0 <= magicbyte <= 0xff) if magicbyte == 0: inp_fmtd = struct.pack(b'B', magicbyte) + inp while magicbyte > 0: inp_fmtd = struct.pack(b'B', magicbyte % 256) + inp magicbyte //= 256 checksum = Hash(inp_fmtd)[:4] return base58.encode(inp_fmtd + checksum)