def test_sequence(self): coin_settings = { 'rpcport': 0, 'rpcauth': 'none', 'blocks_confirmed': 1, 'conf_target': 1 } ci = BTCInterface(coin_settings, 'regtest') time_val = 48 * 60 * 60 encoded = ci.getExpectedSequence(SEQUENCE_LOCK_TIME, time_val) decoded = ci.decodeSequence(encoded) assert (decoded >= time_val) assert (decoded <= time_val + 512) time_val = 24 * 60 encoded = ci.getExpectedSequence(SEQUENCE_LOCK_TIME, time_val) decoded = ci.decodeSequence(encoded) assert (decoded >= time_val) assert (decoded <= time_val + 512) blocks_val = 123 encoded = ci.getExpectedSequence(SEQUENCE_LOCK_BLOCKS, blocks_val) decoded = ci.decodeSequence(encoded) assert (decoded == blocks_val)
def test_ecdsa_otves(self): coin_settings = { 'rpcport': 0, 'rpcauth': 'none', 'blocks_confirmed': 1, 'conf_target': 1 } ci = BTCInterface(coin_settings, 'regtest') vk_sign = i2b(ci.getNewSecretKey()) vk_encrypt = i2b(ci.getNewSecretKey()) pk_sign = ci.getPubkey(vk_sign) pk_encrypt = ci.getPubkey(vk_encrypt) sign_hash = secrets.token_bytes(32) cipher_text = ecdsaotves_enc_sign(vk_sign, pk_encrypt, sign_hash) assert (ecdsaotves_enc_verify(pk_sign, pk_encrypt, sign_hash, cipher_text)) sig = ecdsaotves_dec_sig(vk_encrypt, cipher_text) assert (ci.verifySig(pk_sign, sign_hash, sig)) recovered_key = ecdsaotves_rec_enc_key(pk_encrypt, cipher_text, sig) assert (vk_encrypt == recovered_key)
def test_sign_compact(self): coin_settings = {'rpcport': 0, 'rpcauth': 'none', 'blocks_confirmed': 1, 'conf_target': 1} ci = BTCInterface(coin_settings, 'regtest') vk = i2b(ci.getNewSecretKey()) pk = ci.getPubkey(vk) sig = ci.signCompact(vk, 'test signing message') assert(len(sig) == 64) ci.verifyCompact(pk, 'test signing message', sig)
def test_sign(self): coin_settings = {'rpcport': 0, 'rpcauth': 'none', 'blocks_confirmed': 1, 'conf_target': 1} ci = BTCInterface(coin_settings, 'regtest') vk = i2b(ci.getNewSecretKey()) pk = ci.getPubkey(vk) message = 'test signing message' message_hash = hashlib.sha256(bytes(message, 'utf-8')).digest() eck = PrivateKey(vk) sig = eck.sign(message.encode('utf-8')) ci.verifySig(pk, message_hash, sig)