Python bitcoin.core.script.SignatureHash() Examples
The following are 4
code examples of bitcoin.core.script.SignatureHash().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
bitcoin.core.script
, or try the search function
.
Example #1
Source File: transaction.py From clove with GNU General Public License v3.0 | 5 votes |
def sign(self, default_wallet: BitcoinWallet =None): """Signing transaction using the wallet object.""" for tx_index, tx_in in enumerate(self.tx.vin): utxo = self.solvable_utxo[tx_index] wallet = utxo.wallet or default_wallet if wallet is None: raise RuntimeError('Cannot sign transaction without a wallet.') tx_script = utxo.parsed_script if utxo.contract: sig_hash = script.SignatureHash( script.CScript.fromhex(utxo.contract), self.tx, tx_index, script.SIGHASH_ALL ) else: sig_hash = script.SignatureHash( tx_script, self.tx, tx_index, script.SIGHASH_ALL ) sig = wallet.private_key.sign(sig_hash) + struct.pack('<B', script.SIGHASH_ALL) script_sig = [sig, wallet.private_key.pub] + utxo.unsigned_script_sig tx_in.scriptSig = script.CScript(script_sig) VerifyScript( tx_in.scriptSig, tx_script, self.tx, tx_index, (SCRIPT_VERIFY_P2SH,) ) self.signed = True
Example #2
Source File: transactions.py From OpenBazaar-Server with MIT License | 5 votes |
def sign(self, privkey): """ Sign each of the inputs with the private key. Inputs should all be sent to the same scriptPubkey so we should only need one key. """ seckey = CBitcoinSecret.from_secret_bytes(x(bitcointools.encode_privkey(privkey, "hex"))) for i in range(len(self.tx.vin)): txin_scriptPubKey = self.tx.vin[i].scriptSig sighash = SignatureHash(txin_scriptPubKey, self.tx, i, SIGHASH_ALL) sig = seckey.sign(sighash) + struct.pack('<B', SIGHASH_ALL) self.tx.vin[i].scriptSig = CScript([sig, seckey.pub]) VerifyScript(self.tx.vin[i].scriptSig, txin_scriptPubKey, self.tx, i, (SCRIPT_VERIFY_P2SH,))
Example #3
Source File: transactions.py From OpenBazaar-Server with MIT License | 5 votes |
def create_signature(self, privkey, reedem_script): """ Exports a raw signature suitable for use in a multisig transaction """ seckey = CBitcoinSecret.from_secret_bytes(x(bitcointools.encode_privkey(privkey, "hex"))) signatures = [] for i in range(len(self.tx.vin)): sighash = SignatureHash(CScript(x(reedem_script)), self.tx, i, SIGHASH_ALL) signatures.append({ "index": i, "signature": (seckey.sign(sighash) + struct.pack('<B', SIGHASH_ALL)).encode("hex"), "outpoint": b2lx(self.tx.vin[i].prevout.hash) + b2lx(struct.pack(b"<I", self.tx.vin[i].prevout.n)) }) return signatures
Example #4
Source File: channel.py From Lightning with MIT License | 5 votes |
def signature(self, transaction): """Signature for a transaction.""" sighash = SignatureHash(CScript(self.anchor_redeem), transaction, 0, SIGHASH_ALL) sig = g.seckey.sign(sighash) + bytes([SIGHASH_ALL]) return sig