Skip to content

Commit f4575be

Browse files
OttoAllmendingerllm-git
andcommitted
feat(wasm-utxo): add utxolibCompat option for consistent size estimates
Adds compatibility mode to make input size estimates match @bitgo/unspents. This allows wasm-utxo to produce the same transaction size estimates as utxo-lib when needed, while still supporting accurate min/max bounds. The key change is using 72-byte signatures for ECDSA inputs in compat mode instead of 73-byte for the max calculation, which matches @bitgo/unspents behavior. The implementation also replicates specific encoding choices used in utxo-lib. Issue: BTC-2908 Co-authored-by: llm-git <llm-git@ttll.de>
1 parent de6894d commit f4575be

5 files changed

Lines changed: 852 additions & 29 deletions

File tree

package-lock.json

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

packages/wasm-utxo/js/fixedScriptWallet/Dimensions.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ import { toOutputScriptWithCoin } from "../address.js";
66

77
type FromInputParams = { chain: number; signPath?: SignPath } | { scriptType: InputScriptType };
88

9+
/**
10+
* Options for input dimension calculation
11+
*/
12+
export type FromInputOptions = {
13+
/**
14+
* When true, use @bitgo/unspents-compatible signature sizes (72 bytes)
15+
* for the "max" calculation instead of true maximum (73 bytes).
16+
*/
17+
utxolibCompat?: boolean;
18+
};
19+
920
/**
1021
* Dimensions class for estimating transaction virtual size.
1122
*
@@ -39,13 +50,20 @@ export class Dimensions {
3950
* Create dimensions for a single input
4051
*
4152
* @param params - Either `{ chain, signPath? }` or `{ scriptType }`
53+
* @param options - Optional settings like `{ utxolibCompat: true }` for @bitgo/unspents-compatible sizing
4254
*/
43-
static fromInput(params: FromInputParams): Dimensions {
55+
static fromInput(params: FromInputParams, options?: FromInputOptions): Dimensions {
56+
const compat = options?.utxolibCompat;
4457
if ("scriptType" in params) {
45-
return new Dimensions(WasmDimensions.from_input_script_type(params.scriptType));
58+
return new Dimensions(WasmDimensions.from_input_script_type(params.scriptType, compat));
4659
}
4760
return new Dimensions(
48-
WasmDimensions.from_input(params.chain, params.signPath?.signer, params.signPath?.cosigner),
61+
WasmDimensions.from_input(
62+
params.chain,
63+
params.signPath?.signer,
64+
params.signPath?.cosigner,
65+
compat,
66+
),
4967
);
5068
}
5169

packages/wasm-utxo/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"lint:fix": "eslint . --fix"
5353
},
5454
"devDependencies": {
55+
"@bitgo/unspents": "^0.50.13",
5556
"@bitgo/utxo-lib": "^10.1.0",
5657
"@eslint/js": "^9.17.0",
5758
"@types/mocha": "^10.0.7",

0 commit comments

Comments
 (0)