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") }) return signatures
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,))