-
-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
Summary
The dust validation in packages/snap/src/handlers/validation.ts currently hardcodes dust thresholds per address type:
function getDustLimitSats(addressType: AddressType): bigint {
switch (addressType) {
case 'p2wpkh': return 294n;
case 'p2pkh': return 546n;
case 'p2sh': return 540n;
case 'p2wsh': return 330n;
case 'p2tr': return 330n;
default: return 546n;
}
}With bitcoindevkit/bdk-wasm v0.3.0, the following dust check methods are now available:
Amount.is_dust(script)— check if an amount is below the dust limit for a given scriptScriptBuf.minimal_non_dust()— get the minimum non-dust amount for a scriptScriptBuf.minimal_non_dust_custom(fee_rate)— same with a custom dust relay fee rate
These were added in bitcoindevkit/bdk-wasm#13 and delegate to BDK / Bitcoin Core's actual dust relay policy logic.
Suggested change
// Before: hardcoded switch + manual comparison
const sats = Amount.from_btc(Number(amountInBtc)).to_sat();
const min = getDustLimitSats(account.addressType);
if (sats < min) { ... }
// After: delegate to BDK
const amount = Amount.from_btc(Number(amountInBtc));
if (amount.is_dust(account.publicAddress.script_pubkey)) { ... }Benefits
- Correct by construction — matches Bitcoin Core's exact dust relay policy
- Future-proof — automatically handles new script types without code changes
- Less maintenance — no hardcoded constants to keep in sync
- Simpler — removes ~25 lines of code
Dependency
Requires upgrading @metamask/bitcoindevkit to a version built from bitcoindevkit/bdk-wasm v0.3.0+.
Existing dust limit tests in RpcHandler.test.ts should continue to pass since BDK computes the same thresholds (e.g. 294 sats for p2wpkh).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels