Skip to content

refactor(wasm-utxo): add dynamic dispatch and Zcash hydration support#252

Merged
OttoAllmendinger merged 2 commits intomasterfrom
BTC-0.decode-zcash-tx-support
Apr 17, 2026
Merged

refactor(wasm-utxo): add dynamic dispatch and Zcash hydration support#252
OttoAllmendinger merged 2 commits intomasterfrom
BTC-0.decode-zcash-tx-support

Conversation

@OttoAllmendinger
Copy link
Copy Markdown
Contributor

@OttoAllmendinger OttoAllmendinger commented Apr 15, 2026

Extends BitGoPsbt.fromHalfSignedLegacyTransaction() with dynamic
dispatch to detect transaction type (Bitcoin/Dash/Zcash) and early
rejection of Zcash with helpful error message. Accepts Transaction
objects directly instead of Uint8Array to avoid round-tripping
through bytes.

Adds ZcashBitGoPsbt.fromHalfSignedLegacyTransaction() supporting:

  • Block height mode (recommended): auto-determines consensus_branch_id
  • Explicit consensus_branch_id mode for advanced usage
  • Full Sapling field restoration
  • Comprehensive round-trip tests

Rust layer implements:

  • from_half_signed_legacy_transaction_zcash() with block height
  • from_half_signed_legacy_transaction_zcash_with_consensus_branch_id()
  • from_half_signed_legacy_transaction_dash for DashTransaction support
  • Shared logic for Zcash wire format decoding

Transaction classes add supportsCoin() for dispatch routing.
WASM bindings expose both Zcash variants with unified unspent parsing.

Test improvements:

  • Replace network objects with coin-based utilities
  • Update helpers to accept CoinName instead of Network
  • Use supportsScriptType instead of network-based validation
  • Replace network list iteration with coinNames filtering
  • All 13 fromHalfSignedLegacy tests pass

Ref: BTC-0

@OttoAllmendinger OttoAllmendinger force-pushed the BTC-0.decode-zcash-tx-support branch from 9ae1b10 to 781c8c6 Compare April 15, 2026 14:09
@OttoAllmendinger OttoAllmendinger marked this pull request as ready for review April 15, 2026 14:25
@OttoAllmendinger OttoAllmendinger requested a review from a team as a code owner April 15, 2026 14:25
@OttoAllmendinger OttoAllmendinger force-pushed the BTC-0.decode-zcash-tx-support branch from 781c8c6 to 816b3fd Compare April 16, 2026 09:00
@OttoAllmendinger OttoAllmendinger marked this pull request as draft April 16, 2026 09:07
@OttoAllmendinger OttoAllmendinger force-pushed the BTC-0.decode-zcash-tx-support branch 2 times, most recently from eb2bca4 to f3575b7 Compare April 16, 2026 09:46
@OttoAllmendinger OttoAllmendinger changed the title test: add transactionFromBytes factory and supportsCoin methods for mainnet coin dispatch refactor(wasm-utxo)!: add dynamic dispatch and Zcash hydration support Apr 16, 2026
@OttoAllmendinger OttoAllmendinger changed the title refactor(wasm-utxo)!: add dynamic dispatch and Zcash hydration support refactor(wasm-utxo): add dynamic dispatch and Zcash hydration support Apr 16, 2026
@OttoAllmendinger OttoAllmendinger force-pushed the BTC-0.decode-zcash-tx-support branch 2 times, most recently from 55d5154 to 48bbeed Compare April 16, 2026 10:16
OttoAllmendinger and others added 2 commits April 16, 2026 12:16
Changes fromHalfSignedLegacyTransaction to accept Transaction | DashTransaction
instead of Uint8Array, avoiding re-serialization round-trips.

Bitcoin-like transactions:
- Add dynamic dispatch via Transaction.supportsCoin()
- Validate transaction type and reject Zcash with helpful error message
- Pass WASM transaction directly without re-parsing bytes
- Support pre-decoded transaction instances to avoid re-parsing

Zcash support:
- Add ZcashBitGoPsbt.fromHalfSignedLegacyTransaction()
- Support block height mode (recommended) or explicit consensus_branch_id
- Implement full Sapling field restoration
- Add comprehensive round-trip tests

Rust layer:
- Refactor hydration logic into shared hydrate_psbt() helper
- Add from_half_signed_legacy_transaction_zcash_with_block_height()
- Add from_half_signed_legacy_transaction_zcash_with_branch_id()
- Extract HydrationUnspentInput parsing into TryFromJsValue trait

WASM bindings expose both variants with unified unspent parsing.
All fromHalfSignedLegacy tests pass including new Zcash round-trip tests.

Co-authored-by: llm-git <llm-git@ttll.de>
Replace utxolib network objects with coin-based utilities throughout
tests for `fromHalfSignedLegacyTransaction`. Update helper functions
to accept `CoinName` instead of `Network`, and use new coin utilities
for mainnet checks and script type validation.

- Replace `isSupportedNetwork` with `isSupportedCoin` using `CoinName`
- Update `createHalfSignedP2msPsbt` to use coin-based utilities
- Use `supportsScriptType` instead of network-based validation
- Replace network list iteration with `coinNames` filtering
- Remove `getCoinNameForNetwork` dependency
- Clarify test descriptions for transaction instance handling

Co-authored-by: llm-git <llm-git@ttll.de>
@OttoAllmendinger OttoAllmendinger force-pushed the BTC-0.decode-zcash-tx-support branch from 48bbeed to 6a46f4b Compare April 16, 2026 10:16
@OttoAllmendinger OttoAllmendinger marked this pull request as ready for review April 16, 2026 10:49
@OttoAllmendinger OttoAllmendinger merged commit c0ada5b into master Apr 17, 2026
16 checks passed
@OttoAllmendinger OttoAllmendinger deleted the BTC-0.decode-zcash-tx-support branch April 17, 2026 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants