Example #1
0
def sign(txdata, signatories):
    tx = txutil.from_hex(txdata['tx'])
    for i in range(wally.tx_get_num_inputs(tx)):
        script = wally.hex_to_bytes(txdata['prevout_scripts'][i])
        script_type = txdata['prevout_script_types'][i]
        flags, value, sighash = 0, 0, wally.WALLY_SIGHASH_ALL

        if script_type == gaconstants.P2SH_P2WSH_FORTIFIED_OUT:
            flags = wally.WALLY_TX_FLAG_USE_WITNESS
            value = int(txdata['prevout_values'][i])
        preimage_hash = wally.tx_get_btc_signature_hash(
            tx, i, script, value, sighash, flags)

        sigs = [s.get_signature(preimage_hash) for s in signatories]

        if script_type == gaconstants.P2SH_P2WSH_FORTIFIED_OUT:
            txutil.set_witness(
                tx, i, [None, _to_der(sigs[0]),
                        _to_der(sigs[1]), script])
            flags = wally.WALLY_SCRIPT_SHA256 | wally.WALLY_SCRIPT_AS_PUSH
            script = wally.witness_program_from_bytes(script, flags)
        else:
            sigs = sigs[0] + sigs[1]
            script = wally.scriptsig_multisig_from_bytes(
                script, sigs, [sighash, sighash], 0)
        wally.tx_set_input_script(tx, i, script)

    return tx
Example #2
0
    def sign_tx(self, details):
        txdetails = details['transaction']

        utxos = txdetails['used_utxos'] or txdetails['old_used_utxos']
        signatures = []
        for index, utxo in enumerate(utxos):
            wally_tx = wally.tx_from_hex(txdetails['transaction'],
                                         wally.WALLY_TX_FLAG_USE_WITNESS)
            is_segwit = utxo['script_type'] in [14, 15, 159, 162]  # FIXME!!
            if not is_segwit:
                # FIXME
                raise NotImplementedError("Non-segwit input")
            flags = wally.WALLY_TX_FLAG_USE_WITNESS if is_segwit else 0
            prevout_script = wally.hex_to_bytes(utxo['prevout_script'])
            txhash = wally.tx_get_btc_signature_hash(wally_tx, index,
                                                     prevout_script,
                                                     utxo['satoshi'],
                                                     wally.WALLY_SIGHASH_ALL,
                                                     flags)

            path = utxo['user_path']
            privkey = self.get_privkey(path)
            signature = wally.ec_sig_from_bytes(
                privkey, txhash, wally.EC_FLAG_ECDSA | wally.EC_FLAG_GRIND_R)
            signature = wally.ec_sig_to_der(signature)
            signature.append(wally.WALLY_SIGHASH_ALL)
            signatures.append(wally.hex_from_bytes(signature))
            logging.debug('Signature (der) input %s path %s: %s', index, path,
                          signature)

        return json.dumps({'signatures': signatures})
Example #3
0
 def sign(self, tx, i: int):
     flags = wally.WALLY_TX_FLAG_USE_WITNESS
     scriptcode = wally.scriptpubkey_p2pkh_from_bytes(self.witness_script(), wally.WALLY_SCRIPT_HASH160)
     signature_hash = wally.tx_get_btc_signature_hash(tx, i, scriptcode, self.amount, wally.WALLY_SIGHASH_ALL, flags)
     wally.tx_set_input_witness(tx, i, self.witness(signature_hash))
Example #4
0
 def sign(self, tx, i):
     signature_hash = wally.tx_get_btc_signature_hash(tx, i, self.scriptpubkey(), 0, wally.WALLY_SIGHASH_ALL, 0)
     wally.tx_set_input_script(tx, i, self.script_sig(signature_hash))
Example #5
0
 def sign(self, tx, i: int):
     flags = wally.WALLY_TX_FLAG_USE_WITNESS
     signature_hash = wally.tx_get_btc_signature_hash(tx, i, self.witness_script(), self.amount, wally.WALLY_SIGHASH_ALL, flags)
     wally.tx_set_input_witness(tx, i, self.witness(signature_hash))
Example #6
0
 def _get_sighash(self, wally_tx, index, utxo):
     flags = wally.WALLY_TX_FLAG_USE_WITNESS
     prevout_script = wally.hex_to_bytes(utxo['prevout_script'])
     return wally.tx_get_btc_signature_hash(
             wally_tx, index, prevout_script, utxo['satoshi'], wally.WALLY_SIGHASH_ALL, flags)
Example #7
0
        vin,
        0xffffffff,
        None,  # scriptSig
        None,  # witness
        None,  # nonce
        None,  # entropy
        None,  # issuance amount
        None,  # inflation keys
        None,  # issuance amount rangeproof
        None,  # inflation keys rangeproof
        None,  # pegin witness
        vout)

    privkey = wally.bip32_key_get_priv_key(wallet_derived_key)
    pubkey = wally.ec_public_key_from_private_key(privkey)

    sighash = wally.tx_get_btc_signature_hash(output_tx, vout, script_pubkey,
                                              0, wally.WALLY_SIGHASH_ALL, 0)

    signature = wally.ec_sig_from_bytes(privkey, sighash, wally.EC_FLAG_ECDSA)

    scriptsig = wally.scriptsig_p2pkh_from_sig(pubkey, signature,
                                               wally.WALLY_SIGHASH_ALL)

    wally.tx_set_input_script(output_tx, vout, scriptsig)
# end-sign

# start-to_hex
tx_hex = wally.tx_to_hex(output_tx, wally.WALLY_TX_FLAG_USE_WITNESS)
# end-to_hex
Example #8
0
 def _get_signature_hash(self, tx, index):
     return wally.tx_get_btc_signature_hash(tx, index,
                                            self.output.witness_script,
                                            self.satoshi,
                                            wally.WALLY_SIGHASH_ALL,
                                            wally.WALLY_TX_FLAG_USE_WITNESS)