Beispiel #1
0
def sign(priv_key, data):
    acc = Account.from_secret_key_string(priv_key)
    tx_signer = TxSigner(acc, 'ae_uat')
    tx_builder = TxBuilder()
    tx = TxObject(tx=data)
    signature = tx_signer.sign_transaction(tx, None)
    signed = tx_builder.tx_signed([signature], tx, metadata=None)
    return signed.tx
Beispiel #2
0
def test_transaction_tx_signer():
    sk = 'ed067bef18b3e2be42822b32e3fa468ceee1c8c2c8744ca15e96855b0db10199af08c7e24c71c39f119f07616621cb86d774c7af07b84e9fd82cc9592c7f7d0a'
    pk = 'ak_2L61wjvTKBKK985sbgn7vryr66K8F4ZwyUVrzYYvro85j5sCeU'
    tx = 'tx_+FAMAaEBrwjH4kxxw58RnwdhZiHLhtd0x68HuE6f2CzJWSx/fQqhAa8Ix+JMccOfEZ8HYWYhy4bXdMevB7hOn9gsyVksf30KZIUukO3QAAABgJoyIic='
    sg = 'sg_Tzrf8pDzK53RVfiTdr3GnM86E4jWoGmA2RR6XaCws4PFfnbUTGQ2adRWc8Y55NpxXBaEYD5b1FP5RzNST1GpBZUVfZrLo'
    network_id = "ae_testnet"
    account = Account.from_secret_key_string(sk)
    with raises(ValueError):
        txs = transactions.TxSigner(None, network_id)
    with raises(ValueError):
        txs = transactions.TxSigner(account, None)

    # parse the transaction
    txo = transactions.TxBuilder().parse_tx_string(tx)
    # verify the signature
    signer = transactions.TxSigner(account, network_id)
    signature = signer.sign_transaction(txo)
    assert f"{signer}" == f"{network_id}:{account.get_address()}"
    assert signature == sg
    # incorrect network_id
    signer = transactions.TxSigner(account, "not_good")
    signature = signer.sign_transaction(txo)
    assert signature != sg