def test_from_invalid_wif(self): too_short = encoding.b2a_base58check('a') with raises(privkey.InvalidEncoding): PrivateKey.from_wif(too_short) too_long = encoding.b2a_base58check('a' * 30) with raises(privkey.InvalidEncoding): PrivateKey.from_wif(too_long) valid = encoding.a2b_base58check(PrivateKey.generate().to_wif()) with raises(privkey.InvalidEncoding): PrivateKey.from_wif(encoding.b2a_base58check(valid[:-1] + 'a')) with raises(privkey.InvalidEncoding): PrivateKey.from_wif(encoding.b2a_base58check('a' + valid[1:]))
def to_wif(self): """TODO""" data = bytearray() data.append(self.network.wif_prefix) data.extend(self.to_bytes()) if self.compressed: data.append(1) return encoding.b2a_base58check(bytes(data))
def to_string(self): """TODO""" return encoding.b2a_base58check(self.to_bytes())