0

I'm trying to sign a simple transfer transaction using digitalbitbox's python api (see here and code snippet below).

I send the following json to the HW wallet api:

Sending: {"sign":{"data":[{"keypath":"m/1/1/1/0", "hash":"f2243e10c5c4f4ca1ba2f4cac89e5996ede01c101c8f510440a027b5faaf96a7"}]}}

The signed TX hash returned by the HW wallet is:

0653b763d72e0dc39624310f88b1bda611e94611c5f79ad75132d4305f25dc2c3aac17c3c94a519fbc7da3b9c898a7fae26c68d49d13b604ea8a7ceaad0f1da9

However, when pasting this into etherscan I receive the following error:

Error! Unable to broadcast Tx : {"jsonrpc":"2.0","id":1,"error":{"code":-32000,"message":"rlp: expected input list for types.txdata"}}

I was expecting too see some error message like insufficient funds, but it seems like my encoding is wrong.

Does anybody know why this isn't working?

import sys
from dbb_utils import *
import time
import rlp

try:
    password = 'password'
    openHid()

    # Start up options - factory reset; initial password setting
    if 0:
        hid_send_encrypt('{"reset":"__ERASE__"}', password)
        hid_send_plain('{"password":"' + password + '"}')
        sys.exit()

    import ethereum
    from ethereum.transactions import Transaction
    import hashlib

    # Create test TX
    testTx = Transaction(nonce=5, gasprice=24000000000, startgas=21000, to=int("0xfc5d975c3738b1eed1f072d72912bea31f9d1eb1", 16), value=1, data="")
    rawTx = ethereum.utils.encode_hex(ethereum.utils.sha3(rlp.encode(testTx))) #hashlib.sha256(rlp.encode(testTx)).hexdigest()
    message = '{"sign":{"data":[{"keypath":"m/1/1/1/0", "hash": "' + rawTx + '"}]}}'

    # Send a JSON command
    response = hid_send_encrypt(message, password)
    print(response)
    print("*"*40)
    cmd = '{"sign":""}'
    response = hid_send_encrypt(message, password)
    print(response)

except IOError as ex:
    print(ex)
except(KeyboardInterrupt, SystemExit):
    print("Exiting code")

dbb_hid.close()
0

Looks like I forgot to add the signature into the transaction object. After adding the associated v, r and s parameters to the raw TX and computing the corresponding hex of the rlp encoded TX it now seems to work!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.