Esempio n. 1
0
print "Amount transferred " + str(
    (Decimal(amount) / 10**18)) + " to " + encodedPublicKey.encode('hex')

txData = SPLIT_CONTRACT_FUNCTION
txData += "\x00" * 31
if (args.split_to_eth):
    txData += "\x01"
else:
    txData += "\x00"
txData += "\x00" * 12
txData += encodedPublicKey

tx = Transaction(nonce=int(args.nonce),
                 gasprice=int(args.gasprice),
                 startgas=int(args.startgas),
                 to=decode_hex(SPLIT_CONTRACT_ADDRESS),
                 value=int(amount),
                 data=txData)

encodedTx = encode(tx, UnsignedTransaction)

donglePath = parse_bip32_path(args.path)
apdu = "e0040000".decode('hex') + chr(len(donglePath) + 1 +
                                      len(encodedTx)) + chr(
                                          len(donglePath) /
                                          4) + donglePath + encodedTx

result = dongle.exchange(bytes(apdu))

v = result[0]
r = int(str(result[1:1 + 32]).encode('hex'), 16)
Esempio n. 2
0
args = parser.parse_args()

if args.path == None:
    args.path = "44'/60'/0'/0/0"

if args.data == None:
    args.data = b""
else:
    args.data = decode_hex(args.data[2:])

amount = Decimal(args.amount) * 10**18

tx = Transaction(
    nonce=int(args.nonce),
    gasprice=int(args.gasprice),
    startgas=int(args.startgas),
    to=decode_hex(args.to[2:]),
    value=int(amount),
    data=args.data,
)

encodedTx = encode(unsigned_tx_from_tx(tx), UnsignedTransaction)

donglePath = parse_bip32_path(args.path)
apdu = bytearray.fromhex("e0040000")
apdu.append(len(donglePath) + 1 + len(encodedTx))
apdu.append(len(donglePath) // 4)
apdu += donglePath + encodedTx

dongle = getDongle(True)
result = dongle.exchange(bytes(apdu))
Esempio n. 3
0
if args.path == None:
    args.path = "44'/337'/0'/0"

if args.data == None:
    args.data = b""
else:
    args.data = decode_hex(args.data[2:])

amount = Decimal(args.amount) * 10**18

tx = Transaction(txtype=int(args.txtype),
                 nonce=int(args.nonce),
                 gasprice=int(args.gasprice),
                 startgas=int(args.startgas),
                 to=decode_hex(args.to[2:]),
                 value=int(amount),
                 data=args.data,
                 v=CHAIN_ID,
                 r=0,
                 s=0)

encodedTx = encode(tx, Transaction)
print("encodedTx", encodedTx.hex())
donglePath = parse_bip32_path(args.path)
apdu = bytearray.fromhex("e0040000")
apdu.append(len(donglePath) + 1 + len(encodedTx))
apdu.append(len(donglePath) // 4)
apdu += donglePath + encodedTx

dongle = getDongle(True)
result = dongle.exchange(bytes(apdu))
Esempio n. 4
0
else:
    args.feecurrency = decode_hex(args.feecurrency[2:])

if args.gatewayfeerecipient == None:
    args.gatewayfeerecipient = b""
else:
    args.gatewayfeerecipient = decode_hex(args.gatewayfeerecipient[2:])

amount = Decimal(args.amount) * 10**18

tx = Transaction(nonce=int(args.nonce),
                 gasprice=int(args.gasprice),
                 startgas=int(args.startgas),
                 feecurrency=args.feecurrency,
                 gatewayfeerecipient=args.gatewayfeerecipient,
                 gatewayfee=int(args.gatewayfee),
                 to=decode_hex(args.to[2:]),
                 value=int(amount),
                 data=args.data,
                 v=CHAIN_ID,
                 r=0,
                 s=0)

encodedTx = encode(tx, Transaction)
print('Encoded tx', encode_hex(encodedTx))

donglePath = parse_bip32_path(args.path)
apdu = bytearray.fromhex("e0040000")
apdu.append(len(donglePath) + 1 + len(encodedTx))
apdu.append(len(donglePath) // 4)
apdu += donglePath + encodedTx
Esempio n. 5
0
dongle = getDongle(True)

if args.descriptor != None:
    descriptor = binascii.unhexlify(args.descriptor)
    apdu = struct.pack(">BBBBB", 0xE0, 0x0A, 0x00, 0x00,
                       len(descriptor)) + descriptor
    dongle.exchange(bytes(apdu))

donglePath = parse_bip32_path(args.path)
apdu = bytearray.fromhex("e0040000")
apdu.append(len(donglePath) + 1 + len(encodedTx))
apdu.append(len(donglePath) // 4)
apdu += donglePath + encodedTx

result = dongle.exchange(bytes(apdu))

# Needs to recover (main.c:1121)
if (CHAIN_ID * 2 + 35) + 1 > 255:
    ecc_parity = result[0] - ((CHAIN_ID * 2 + 35) % 256)
    v = (CHAIN_ID * 2 + 35) + ecc_parity
else:
    v = result[0]

r = int(binascii.hexlify(result[1:1 + 32]), 16)
s = int(binascii.hexlify(result[1 + 32:1 + 32 + 32]), 16)

tx = Transaction(tx.nonce, tx.gasprice, tx.startgas, tx.to, tx.value, tx.data,
                 v, r, s)

print("Signed transaction", encode_hex(encode(tx)))