Create a witness which spends the 2of2. */
| 366 | |
| 367 | /* Create a witness which spends the 2of2. */ |
| 368 | u8 **bitcoin_witness_2of2(const tal_t *ctx, |
| 369 | const struct bitcoin_signature *sig1, |
| 370 | const struct bitcoin_signature *sig2, |
| 371 | const struct pubkey *key1, |
| 372 | const struct pubkey *key2) |
| 373 | { |
| 374 | u8 **witness = tal_arr(ctx, u8 *, 4); |
| 375 | |
| 376 | /* OP_CHECKMULTISIG has an out-by-one bug, which MBZ */ |
| 377 | witness[0] = stack_number(witness, 0); |
| 378 | |
| 379 | /* sig order should match key order. */ |
| 380 | if (pubkey_cmp(key1, key2) < 0) { |
| 381 | witness[1] = stack_sig(witness, sig1); |
| 382 | witness[2] = stack_sig(witness, sig2); |
| 383 | } else { |
| 384 | witness[1] = stack_sig(witness, sig2); |
| 385 | witness[2] = stack_sig(witness, sig1); |
| 386 | } |
| 387 | |
| 388 | witness[3] = bitcoin_redeem_2of2(witness, key1, key2); |
| 389 | return witness; |
| 390 | } |
| 391 | |
| 392 | /* Create scriptcode (fake witness, basically) for P2WPKH */ |
| 393 | u8 *p2wpkh_scriptcode(const tal_t *ctx, const struct pubkey *key) |