Skip to content

Commit c2e89e0

Browse files
authored
Merge pull request #12 from joshdoman/multi-input
feat(api): multi-input emulation
2 parents 67c64b2 + 2183116 commit c2e89e0

2 files changed

Lines changed: 185 additions & 193 deletions

File tree

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,22 @@ Finally, the enclave should be able to expose the master public key, so that use
4242
/// Trait to abstract the behavior of the bitcoin script verifier, allowing
4343
/// users to provide their own verifier.
4444
pub trait Verifier {
45-
/// Verify a bitcoin script, mirroring the API of `bitcoinkernel::verify`.
45+
/// Verify one or more scripts in a bitcoin transaction.
4646
///
4747
/// # Arguments
48-
/// * `script_pubkey` - The script public key to verify.
49-
/// * `amount` - The amount of the input being spent.
50-
/// * `tx_to` - The transaction containing the script.
51-
/// * `input_index` - The index of the input to verify.
48+
/// * `script_pubkeys` - The script public keys to verify.
49+
/// * `tx_to` - The transaction with emulated witness data.
5250
/// * `spent_outputs` - The outputs being spent by the transaction.
51+
/// * `skip_inputs` - The inputs to not verify.
5352
///
5453
/// # Errors
5554
/// Returns `Error` if verification fails.
5655
fn verify(
5756
&self,
58-
script_pubkey: &[u8],
59-
amount: Option<i64>,
57+
script_pubkeys: &[ScriptBuf],
6058
tx_to: &[u8],
61-
input_index: usize,
6259
spent_outputs: &[TxOut],
60+
skip_inputs: HashSet<usize>,
6361
) -> Result<(), Error>;
6462
}
6563

@@ -70,21 +68,24 @@ pub struct DefaultVerifier;
7068
### Convert emulated transaction
7169

7270
```rust
73-
/// Verifies an emulated Bitcoin script and signs the corresponding transaction.
71+
/// Verifies an emulated Bitcoin transaction and signs the corresponding real transaction.
7472
///
75-
/// This function performs script verification using bitcoinkernel, verifying an
76-
/// emulated P2TR input. If successful, it derives an XOnlyPublicKey from the
77-
/// parent key and the emulated merkle root, which is then tweaked with an optional
78-
/// backup merkle root to derive the actual spent UTXO, which is then key-path signed
79-
/// with `SIGHASH_DEFAULT`.
73+
/// This function performs script verification using a Verifier, which verifies one or
74+
/// more emulated P2TR inputs. If successful, it derives for each emulated input an
75+
/// XOnlyPublicKey from the parent key and the emulated merkle root, which is then tweaked
76+
/// with an optional backup merkle root to derive the input's actual spent UTXO. This is
77+
/// then key-path signed with `SIGHASH_DEFAULT`.
8078
///
8179
/// If the emulated script-path spend includes a data-carrying annex (begins with 0x50
8280
/// followed by 0x00), the annex is included in the key-path spend. Otherwise, the annex
8381
/// is dropped.
8482
///
83+
/// Non-emulated inputs are identified by the input type. An emulated input must be a
84+
/// P2TR script-path spend, with a derived scriptPubKey that does not match that of the
85+
/// actual spent output.
86+
///
8587
/// # Arguments
8688
/// * `verifier` - The verifier to use for script validation
87-
/// * `input_index` - Index of the input to verify and sign (0-based)
8889
/// * `emulated_tx_to` - Serialized transaction to verify and sign
8990
/// * `actual_spent_outputs` - Actual outputs being spent
9091
/// * `aux_rand` - Auxiliary random data for signing
@@ -95,7 +96,6 @@ pub struct DefaultVerifier;
9596
/// Returns error if verification fails, key derivation fails, or signing fails
9697
pub fn verify_and_sign<V: Verifier>(
9798
verifier: &V,
98-
input_index: usize,
9999
emulated_tx_to: &[u8],
100100
actual_spent_outputs: &[TxOut],
101101
aux_rand: &[u8; 32],

0 commit comments

Comments
 (0)