Exemplo n.º 1
0
def test_xrp_key_signature():
    key = RippleKey(private_key='ssq55ueDob4yV3kPVnNQLHB6icwpC')
    data = {'Account': key.to_account()}

    # sign data with fixed k value for deterministic result
    signature = key.sign_tx(data, k=3)
    assert signature == (
        b'0E\x02!\x00\xf90\x8a\x01\x92X\xc3\x10I4O\x85\xf8\x9dR)\xb51\xc8E'
        b'\x83o\x99\xb0\x86\x01\xf1\x13\xbc\xe06\xf9\x02 k\x1d*S_\xf1`\x17'
        b'\xae\twl\x94/\x82\x03\x07E\xaf\xa0\xc1\x8e\xed\xfbv\xf6\xf6\xc8'
        b'\xba\x8aW\xdb')
    assert key.verify_tx(data, signature)
Exemplo n.º 2
0
async def test_tx_flow_single_sign(master):
    """
    Tests transaction serialization, signing and submitting flow
    """
    rpc = RippleJsonRpc('http://localhost:5005')
    fee = await rpc.fee()
    reserve = await rpc.get_reserve()

    destination = RippleKey()

    account_info = await rpc.account_info(master.to_account(),
                                          ledger_index='current')

    tx = {
        'Account': master.to_account(),
        'Flags': RippleTransactionFlags.FullyCanonicalSig,
        'Sequence': account_info['account_data']['Sequence'],
        'TransactionType': RippleTransactionType.Payment,
        'Amount': decimals.xrp_to_drops(reserve.base),
        'Destination': destination.to_account(),
        'Fee': int(fee.minimum),  # as drops
        'SigningPubKey': master.to_public()
    }

    # sign and serialize transaction
    signature = master.sign_tx(tx)
    signed_tx = {**tx, 'TxnSignature': signature}
    tx_blob = binascii.hexlify(serializer.serialize(signed_tx)).decode()

    # deserialize and verify signatures
    deserialized_tx = serializer.deserialize(tx_blob)
    public_key = RippleKey(public_key=deserialized_tx['SigningPubKey'])
    assert deserialized_tx == signed_tx
    assert public_key.verify_tx(tx, signature)

    # post TX blob to rippled JSONRPC
    result = await rpc.submit(tx_blob)
    assert result['engine_result'] == 'tesSUCCESS'