Skip to content

Commit a7cbd75

Browse files
OttoAllmendingerllm-git
andcommitted
feat(wasm-utxo): bump rust-miniscript to v13.0.0-opdrop
Updates miniscript dependency from v12.3.4-opdrop to v13.0.0-opdrop and adapts code to API changes. Key changes include: - Updated TapTree representation and handling - Renamed `parse` method to `decode` for scripts - Changed `output_key().to_inner()` to `output_key().to_x_only_public_key()` - Updated error type from `ConversionError` to `NonDefiniteKeyError` Issue: BTC-2656 Co-authored-by: llm-git <[email protected]>
1 parent 8f4c723 commit a7cbd75

File tree

6 files changed

+37
-19
lines changed

6 files changed

+37
-19
lines changed

packages/wasm-utxo/Cargo.lock

Lines changed: 15 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/wasm-utxo/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ all = "warn"
1616
[dependencies]
1717
wasm-bindgen = "0.2"
1818
js-sys = "0.3"
19-
miniscript = { git = "https://github.com/BitGo/rust-miniscript", tag = "miniscript-12.3.4-opdrop" }
19+
miniscript = { git = "https://github.com/BitGo/rust-miniscript", tag = "miniscript-13.0.0-opdrop" }
2020
bech32 = "0.11"
2121
musig2 = { version = "0.3.1", default-features = false, features = ["k256"] }
2222
getrandom = { version = "0.2", features = ["js"] }

packages/wasm-utxo/src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ impl From<miniscript::Error> for WasmUtxoError {
3232
}
3333
}
3434

35-
impl From<miniscript::descriptor::ConversionError> for WasmUtxoError {
36-
fn from(err: miniscript::descriptor::ConversionError) -> Self {
35+
impl From<miniscript::descriptor::NonDefiniteKeyError> for WasmUtxoError {
36+
fn from(err: miniscript::descriptor::NonDefiniteKeyError) -> Self {
3737
WasmUtxoError::StringError(err.to_string())
3838
}
3939
}

packages/wasm-utxo/src/fixed_script_wallet/wallet_scripts/checksigverify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl ScriptP2tr {
8888
}
8989

9090
pub fn output_script(&self) -> ScriptBuf {
91-
let output_key = self.spend_info.output_key().to_inner();
91+
let output_key = self.spend_info.output_key().to_x_only_public_key();
9292

9393
Builder::new()
9494
.push_int(1)

packages/wasm-utxo/src/wasm/miniscript.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ impl WrapMiniscript {
7575
let script = bitcoin::Script::from_bytes(script);
7676
match context_type {
7777
"tap" => Ok(WrapMiniscript::from(
78-
Miniscript::<XOnlyPublicKey, Tap>::parse(script).map_err(WasmUtxoError::from)?,
78+
Miniscript::<XOnlyPublicKey, Tap>::decode(script).map_err(WasmUtxoError::from)?,
7979
)),
8080
"segwitv0" => Ok(WrapMiniscript::from(
81-
Miniscript::<PublicKey, Segwitv0>::parse(script).map_err(WasmUtxoError::from)?,
81+
Miniscript::<PublicKey, Segwitv0>::decode(script).map_err(WasmUtxoError::from)?,
8282
)),
8383
"legacy" => Ok(WrapMiniscript::from(
84-
Miniscript::<PublicKey, Legacy>::parse(script).map_err(WasmUtxoError::from)?,
84+
Miniscript::<PublicKey, Legacy>::decode(script).map_err(WasmUtxoError::from)?,
8585
)),
8686
_ => Err(WasmUtxoError::new("Invalid context type")),
8787
}

packages/wasm-utxo/src/wasm/try_into_js_value.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,27 @@ impl<Pk: MiniscriptKey + TryIntoJsValue> TryIntoJsValue for WshInner<Pk> {
235235

236236
impl<Pk: MiniscriptKey + TryIntoJsValue> TryIntoJsValue for Tr<Pk> {
237237
fn try_to_js_value(&self) -> Result<JsValue, WasmUtxoError> {
238-
Ok(js_arr!(self.internal_key(), self.tap_tree()))
238+
let tap_tree_js: JsValue = match self.tap_tree() {
239+
Some(tree) => tree.try_to_js_value()?,
240+
None => JsValue::NULL,
241+
};
242+
Ok(js_arr!(self.internal_key(), tap_tree_js))
239243
}
240244
}
241245

242246
impl<Pk: MiniscriptKey + TryIntoJsValue> TryIntoJsValue for TapTree<Pk> {
243247
fn try_to_js_value(&self) -> Result<JsValue, WasmUtxoError> {
244-
match self {
245-
TapTree::Tree { left, right, .. } => js_obj!("Tree" => js_arr!(left, right)),
246-
TapTree::Leaf(ms) => ms.try_to_js_value(),
248+
// TapTree is now a flat representation of leaves with depths
249+
// Convert to an array of {depth, miniscript} objects
250+
let arr = Array::new();
251+
for item in self.leaves() {
252+
let leaf_obj = js_obj!(
253+
"depth" => item.depth() as u32,
254+
"miniscript" => item.miniscript()
255+
)?;
256+
arr.push(&leaf_obj);
247257
}
258+
Ok(arr.into())
248259
}
249260
}
250261

0 commit comments

Comments
 (0)