Bitcoin Stack Exchange is a question and answer site for Bitcoin crypto-currency enthusiasts. It only takes a minute to sign up.
Sign up to join this communityAnybody can ask a question
Anybody can answer
The best answers are voted up and rise to the top
On a local elements testnet I've sent some coins to a p2sh address, now I'd like to build the scriptSig to spend them. Here is the code I'm trying to build:
let redeem_script = elements::script::Builder::new().push_key(&pubkey_a) .push_opcode(elements::opcodes::all::OP_CHECKSIG) .push_opcode(elements::opcodes::all::OP_IFDUP) .push_opcode(elements::opcodes::all::OP_NOTIF) .push_key(&pubkey_b) .push_opcode(elements::opcodes::all::OP_CHECKSIGVERIFY) .push_int(locktime_int) .push_opcode(elements::opcodes::all::OP_CSV) .push_opcode(elements::opcodes::all::OP_ENDIF) .into_script(); let redeem_script_bytes = redeem_script.as_bytes(); //sign the redeem script and create the script_sig let privka_key = bitcoin::PrivateKey::from_wif(&privkey_a).unwrap(); let redeem_message = bitcoin::secp256k1::Message::from_slice(redeem_script_bytes).unwrap(); let curve = bitcoin::secp256k1::SECP256K1; let signature = curve.sign(&redeem_message, &privka_key.key); let sig_bytes = signature.serialize_compact(); let script_sig = elements::script::Builder::new()//.push_opcode(elements::opcodes::all::OP_0) //.push_opcodes(elements::opcodes::all::OP_PUSHBYTES_64) .push_slice(&sig_bytes) .push_slice(redeem_script_bytes);
Questions are:
- First of all, does this make sense? I'm re-building the script used to obtain the address, then I use the private key linked to pubkey_a to sign the full script in bytes, finally try to build the scripSig that will be used in the Txin
- Is
sig_bytes
the correct way to get the bytes of the signed message and put them into the script?(serialise_compact()
returns 64 bytes: 32 from r and 32 from s signature elements) - the script_sig, I think, should be
OP_0 <sig_a> <redeem_script>
, is this correct (sig_a is the signed redeem script with privkey a)? There's apparently noOP_0
in elements opcodes, also, ispush_slice
enough or should I explicitly say how many bytes I'm pushing?
You can get bonuses upto $100 FREE BONUS when you:
π° Install these recommended apps:
π² SocialGood - 100% Crypto Back on Everyday Shopping
π² xPortal - The DeFi For The Next Billion
π² CryptoTab Browser - Lightweight, fast, and ready to mine!
π° Register on these recommended exchanges:
π‘ Binanceπ‘ Bitfinexπ‘ Bitmartπ‘ Bittrexπ‘ Bitget
π‘ CoinExπ‘ Crypto.comπ‘ Gate.ioπ‘ Huobiπ‘ Kucoin.
Comments