Exemplo n.º 1
0
 def _cleaned_address(self, addr):
     if addr[:2] == 'tz':
         return TZ_VERSION[addr[:3]] + hexlify(
             b58decode_check(addr)).decode()[6:]
     elif addr[:2] == 'KT':
         return '01' + hexlify(b58decode_check(addr)).decode()[6:] + '00'
     else:
         raise KeyError('Unknown address: {}'.format(addr))
Exemplo n.º 2
0
 def signature(self, key):
     raw_tx = self.serialize()
     sk_str = b58decode_check(key)[4:]
     pk = secp256k1.PrivateKey(sk_str)
     signature = pk.ecdsa_serialize_compact(
         pk.ecdsa_sign(b'\x03' + unhexlify(raw_tx), digest=blake2b_32))
     return hexlify(signature)
Exemplo n.º 3
0
 def serialize(self):
     result = hexlify(b58decode_check(self.branch)).decode()[4:]
     result += '07'  # tag for revelation
     result += self._cleaned_address(self.source)
     result += numToZarith(round(self.fee / 2))
     result += numToZarith(self.counter)
     result += numToZarith(self.gas_limit)
     result += numToZarith(self.storage_limit)
     result += '01'
     result += hexlify(b58decode_check(self.public_key)).decode()[8:]
     result += '08'  # tag for tx
     result += self._cleaned_address(self.source)
     result += numToZarith(round(self.fee / 2))
     result += numToZarith(self.counter + 1)
     result += numToZarith(self.gas_limit)
     result += numToZarith(self.storage_limit)
     result += numToZarith(self.amount)
     result += self._cleaned_address(self.destination)
     result += '00'  # params
     return result
Exemplo n.º 4
0
    def from_wif(network, wif):

        if not 51 <= len(wif) <= 52:
            raise ValueError('Invalid wif length: {}'.format(len(wif)))

        decoded = b58decode_check(wif)
        prefix, *rest = decoded

        if prefix != network.wif_prefix:
            raise ValueError(
                'Unknown private key prefix: {:02x}'.format(prefix))

        public_compressed = len(rest) == 33
        privk = rest[0:32]

        return PrivateKey(bytearray(privk), public_compressed)
Exemplo n.º 5
0
def priv2pub(priv):
    setup_btcpy('mainnet')
    priv_hex = hexlify(b58decode_check(priv)[4:])
    pk = PrivateKey.unhexlify(priv_hex)
    sppk = b'\x03\xfe\xe2V'
    return b58encode_check(sppk + pk.pub().serialize())
Exemplo n.º 6
0
 def test_b58decode_check(self):
     for hexa, encoded in b58chk:
         self.assertEqual(hexlify(b58decode_check(encoded)).decode(), hexa)