Skip to content

Commit 0e35201

Browse files
fix(wasm-utxo): use BigInt-specific conversion for unspent values
Replace BigInt::from(v).as_f64() with u64::try_from(BigInt::unchecked_from_js(v)). unchecked_from_js treats the JsValue as a BigInt without re-wrapping it, then try_from converts directly to u64 — no lossy f64 round-trip and no false error when the caller correctly passes a JS bigint. Issue: BTC-3159
1 parent d7c0855 commit 0e35201

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

  • packages/wasm-utxo/src/wasm/fixed_script_wallet

packages/wasm-utxo/src/wasm/fixed_script_wallet/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,8 @@ impl BitGoPsbt {
421421
as u32;
422422
let value_js = js_sys::Reflect::get(&item, &"value".into())
423423
.map_err(|_| WasmUtxoError::new("Missing 'value' field on unspent"))?;
424-
let value = js_sys::BigInt::from(value_js)
425-
.as_f64()
426-
.ok_or_else(|| WasmUtxoError::new("'value' must be a bigint"))?
427-
as u64;
424+
let value = u64::try_from(js_sys::BigInt::unchecked_from_js(value_js))
425+
.map_err(|_| WasmUtxoError::new("'value' must be a bigint convertible to u64"))?;
428426
parsed_unspents.push(ScriptIdWithValue {
429427
chain,
430428
index,

0 commit comments

Comments
 (0)