Esempio n. 1
0
    def sign_transaction(self, keystore: TrezorKeyStore, tx: Transaction,
                         xpub_path: Dict[str, str],
                         tx_context: TransactionContext) -> None:
        prev_txtypes: Dict[bytes, TransactionType] = {}
        for prev_tx_hash, prev_tx in tx_context.prev_txs.items():
            txtype = TransactionType()
            txtype.version = prev_tx.version
            txtype.lock_time = prev_tx.locktime
            txtype.inputs = self.tx_inputs(prev_tx, is_prev_tx=True)
            txtype.bin_outputs = [
                TxOutputBinType(amount=tx_output.value,
                                script_pubkey=bytes(tx_output.script_pubkey))
                for tx_output in prev_tx.outputs
            ]
            # Trezor tx hashes are same byte order as the reversed hex tx id.
            prev_trezor_tx_hash = bytes(reversed(prev_tx_hash))
            prev_txtypes[prev_trezor_tx_hash] = txtype

        client = self.get_client(keystore)
        inputs = self.tx_inputs(tx, xpub_path)
        outputs = self.tx_outputs(keystore, keystore.get_derivation(), tx)
        details = SignTx(lock_time=tx.locktime)
        signatures, _ = client.sign_tx(self.get_coin_name(),
                                       inputs,
                                       outputs,
                                       details=details,
                                       prev_txes=prev_txtypes)
        tx.update_signatures(signatures)
Esempio n. 2
0
 def sign_transaction(self, keystore: TrezorKeyStore, tx, xpub_path):
     client = self.get_client(keystore)
     inputs = self.tx_inputs(tx, xpub_path)
     outputs = self.tx_outputs(keystore, keystore.get_derivation(), tx)
     details = SignTx(lock_time=tx.locktime)
     signatures, _ = client.sign_tx(self.get_coin_name(), inputs, outputs, details=details,
                                    prev_txes=defaultdict(TransactionType))
     tx.update_signatures(signatures)
Esempio n. 3
0
 def sign_transaction(self, keystore, tx, xpub_path):
     client = self.get_client(keystore)
     inputs = self.tx_inputs(tx, xpub_path, True)
     outputs = self.tx_outputs(keystore.get_derivation(), tx, client)
     details = SignTx(lock_time=tx.locktime)
     signed_tx = client.sign_tx(self.get_coin_name(), inputs, outputs, details=details,prev_txes=defaultdict(TransactionType))[1]
     raw = bh2u(signed_tx)
     tx.update_signatures(raw)
 def sign_transaction(self, keystore, tx: PartialTransaction, prev_tx):
     prev_tx = {bfh(txhash): self.electrum_tx_to_txtype(tx) for txhash, tx in prev_tx.items()}
     client = self.get_client(keystore)
     inputs = self.tx_inputs(tx, for_sig=True, keystore=keystore)
     outputs = self.tx_outputs(tx, keystore=keystore)
     details = SignTx(lock_time=tx.locktime, version=tx.version)
     signatures, _ = client.sign_tx(self.get_coin_name(), inputs, outputs, details=details, prev_txes=prev_tx)
     signatures = [(bh2u(x) + '01') for x in signatures]
     tx.update_signatures(signatures)
Esempio n. 5
0
 def sign_transaction(self, keystore, tx, prev_tx, xpub_path):
     prev_tx = { bfh(txhash): self.electrum_tx_to_txtype(tx, xpub_path) for txhash, tx in prev_tx.items() }
     client = self.get_client(keystore)
     inputs = self.tx_inputs(tx, xpub_path, True)
     outputs = self.tx_outputs(keystore.get_derivation(), tx, client)
     details = SignTx(lock_time=tx.locktime)
     signatures, signed_tx = client.sign_tx(self.get_coin_name(), inputs, outputs, details=details, prev_txes=prev_tx)
     signatures = [bh2u(x) for x in signatures]
     tx.update_signatures(signatures)
Esempio n. 6
0
 def sign_transaction(self, keystore, tx: PartialTransaction, prev_tx):
     prev_tx = {bfh(txhash): self.electrum_tx_to_txtype(tx) for txhash, tx in prev_tx.items()}
     if not self.client:
         raise Exception("client is None")
     xpub = keystore.xpub
     derivation = keystore.get_derivation_prefix()
     if not self.force_pair_with_xpub(self.client, xpub, derivation):
         raise Exception("Can't Pair With You Device When Sign tx")
     inputs = self.tx_inputs(tx, for_sig=True, keystore=keystore)
     outputs = self.tx_outputs(tx, keystore=keystore)
     details = SignTx(lock_time=tx.locktime, version=tx.version)
     signatures, _ = self.client.sign_tx(self.get_coin_name(), inputs, outputs, details=details, prev_txes=prev_tx)
     signatures = [(bh2u(x) + '01') for x in signatures]
     tx.update_signatures(signatures)
     raise Exception("sign success")
Esempio n. 7
0
 def sign_transaction(self, keystore, tx, prev_tx, xpub_path):
     prev_tx = {
         bfh(txhash): self.electrum_tx_to_txtype(tx, xpub_path)
         for txhash, tx in prev_tx.items()
     }
     client = self.get_client(keystore)
     inputs = self.tx_inputs(tx, xpub_path, True)
     outputs = self.tx_outputs(keystore.get_derivation(), tx)
     details = SignTx(lock_time=tx.locktime, version=tx.version)
     z = (
         "self.get_coin_name()  : {} \n inputs  :   {}  \n outputs  :   {}  \n  details   :   {} \n  prev_tx  :   {}"
     ).format(self.get_coin_name(), inputs, outputs, details, prev_tx)
     print(z)
     signatures, _ = client.sign_tx(self.get_coin_name(),
                                    inputs,
                                    outputs,
                                    details=details,
                                    prev_txes=prev_tx)
     signatures = [(bh2u(x) + '01') for x in signatures]
     tx.update_signatures(signatures)
Esempio n. 8
0
def signing_data(account, utxos, recipients, change_address, change_amount):
    details = SignTx(version=2)
    prev_txes = {
        bytes.fromhex(u.tx["txid"]): coins.json_to_tx(account.coin, u.tx)
        for u in utxos
    }
    inputs = [
        utxo_to_input(u, account.account_type.input_script_type) for u in utxos
    ]
    outputs = [
        recipient_to_output(address, amount) for address, amount in recipients
    ]
    if change_address is not None:
        outputs.append(
            recipient_to_output(change_address, change_amount,
                                account.account_type.output_script_type))

    return TrezorSigningData(
        coin_name=account.coin_name,
        details=details,
        inputs=inputs,
        outputs=outputs,
        prev_txes=prev_txes,
    )