Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Bitcoin/Rust]: Finalize Bitcoin V2 refactoring (#3848)
* [Bitcoin/V2]: Add a `rust/frameworks` directory, move `tw_utxo` there * [Bitcoin/V2]: Add Bitcoin Legacy address implementation * [Bitcoin/V2]: Add `StandardBitcoinAddres` * [Bitcoin/V2]: Add segwit address * Switch to TW Bitcoin Address implementation in `BitcoinEntry` * [Bitcoin/V2]: Implement signAsDER and verifyAsDER used in Bitcoin * [BitcoinV2]: Add standard Unsigned and Signed Transaction declarations * Add and implement Bitcoin encoding for Signed Transaction * [BitcoinV2]: Refactor `TWDerivation` to avoid Coin names * [BitcoinV2]: Refactor preimage hashing * Delegate transaction preimage hashing to `LegacyPreimage`, `Witness0Preimage` helpers * [BitcoinV2]: Design a `TransactionSigner` API * [BitcoinV2]: Design an API for `TransactionPlanner`, `TransactionBuilder` * add Script check methods * cargo fmt * make signing_method optional, try to automatically determine signing method if unavailable * start expanding verify_signatures * add schnorr module to tw_keypair, wip * expand KeyPair impl for schnorr * expand enums in tw module with Schnorr * simplify schnorr module structure * complete SigningKeyTrait and VerifyingKeyTrait impl for KeyPair * complete verify_signatures mechanism * adjust some types, complete compile method * add test interface for signer, wip * handle Schnorr variant in tw_keypair * ignore the recovery byte in ECDSA signature * update comment * specify the keys explicitly in tests * continue debugging * remove UseDefault from SighashBase, use All as default, fix sighash calculation * formatting * add Witness type, correctly consensus-encode items * fix P2WPKH scriptPubkey generation * add standard OPCodes and add convenience functions for Script * complete standard Script builders and checkers * update script submodule structures * build claim scripts for standardized transaction variants * fix Script method call * update comments, use H264 for new_p2pk instead of PublicKey type * small cleanup to push_slice * fix typo * rename Sighash to SighashType * expand TransactionBuilder * adjust builder and add test, wip * update TransactionBuilder, init test, wip * complete build_legacy_tx test * assert in build_legacy_tx * add BitcoinEcdsaSignature type, serialize correctly for claim script * add SER_SIZE const to BitcoinEcdsaSignature * rename TransactionSigner to SighashComputer * add a ClaimBuilder * rename some types * add tests for building Segwit transactions * delete playgrounds * track transaction builder test * add fee calculation traits, implement for standard Transaction, Inputs and Outputs * implement TransactionFee::fee * implement CompactInteger::serialized_len * consider Segwith flag and marker when calculating weight/size/fee * add select_inputs logic to TransactionFee, handle vbyte/size calculation edge case * expand tests with size, vsize and weight calculation * add fee() calculation tests * add input selection tests, wip * add base_size to TransactionFee trait, implement method * move input selection logic out of TransactionFee trait and to ComputedTransaction * add change amount related methods * continue with change output build pattern, wip * mvoe utxo input selector to separate module * complete test for utxo selection with change output generation * add note slight fee difference * extra comments * introduce CompiledSelectionBuilder * add p2tr condition builder functions * add builders for input, claim and output P2TR-key-path scripts * track taproot1_sighash, wip * extra conditions * add tests for Taproot inputs, spending conditions and claims. wip * continue on Taproot sighash calculation, wip * continuing with Taproot Sighash debugging... * add mockup of TapsighHash * extend test, wip * remove unused fields in UtxoPreiamgeArgs * implement Hasher::TapSighash variant * rename TapSighash prefix const * seperate sighash methods on PreimageInterface into legacy/segwit and taproot * move spent_* hashing methods to TransactionHasher * adjust TapSighash workflow to other variants * move tx_hasher and sighash_ty to a per-input basis * add const for Annex indicator * include leaf_hash and separator as part of TapSighash * construct Taproot script-path spending info and merkle root, wip * add p2tr_script_path spending script builder * init asset/ module, move brc20 and ordinals there * adjust brc20 and ordinal code for new changes, add brc20_transfer input builder * separate input builder into individual modules * fix and format * remove unused DEFAULT_TX_HASHER in utxo_selector * build brc20 spending input * build brc20 transfer output * add tweak support to tw_keypair * build brc20 transfer output * add support for non aux rand data when signing for schnorr, complete P2TR key-path test * add test for BRC20 transfer output, fix issue with payload * testing brc20 transfer reveal, wip * finalize brc20 reveal construction with tests * get rid of dbg! * add custom script builders * wipe tw_bitcoin's preimage_hashes_impl, start with utxo builder migration * handle custom script proto builder * start migrating output proto to builder matcher, wip * use SelectionBuilder * expand migration of tw_bitcoin preimage_hashes_impl * create dummy claims for preiamge_hashes_impl * add and handle a UseAll selector * complete construction of proto outputs * add init module with proto_input_to_native function * implement proto_output_to_native * process change output * handle custom script_pubkey outputs * fix signature issue for p2tr_script_path, expand p2wsh impl * set send_to_address tests to ignore for now * remove ignore attribute for ordinals and brc20, all related tests pass * derive P2PKH and P2SH from base58 address * derive P2WSH and P2WPKH from bech32 address * move address to native derivation logic to individual function * init taproot module with TaprootAddress * implement p2tr_with_coin_and_prefix for TaprootAddress, derive from StandardBitcoinAddress * fix tests for reference changes * distinguish between Segwit and Taproot for StandardBitcoinAddress * derive Taproot program from address, do extra witness program check * complete builders for P2WPKH and P2WSH derived from address string * complete legacy P2PKH and P2SH builders derived from address string * move address derivation logic to address_to_native * complete proto builders for p2pkh and p2wpkh from_hash variants * expand output builder for P2SH, both redeem script and hash * expand P2SH input claiming, wip * set ignore attribute to p2sh tests for now * add option to provide sigs to proto_input_to_native, deprecate some legacy code * construct proto return value for compile method * implement txid and fix ownership issue with proto return structure * update tw_bitcoin calls in wallet_core_rs for legacy FFI functions * update p2tr_script_path test module, use updated tw_utxo crate * adjust legacy_script tests to tw_utxo changes * remove unused imports * remove print/dbg statements * remove proto interface for tw_utxo * add proto_input_to_spending_data function * rename to proto_sighash_to_sig * sign sighashes and compile final transaction in tw_bitcon entry * formatting * add todo to fn txid * [Bitcoin]: Cleanups * [Bitcoin]: Fix most of clippy warnings * [Bitcoin]: Refactor schnorr private and public keys * [Bitcoin]: Fix BRC20 tests * [Bitcoin]: Fix txid * [Bitcoin]: Temporary add `BitcoinV3.proto` - refactored API * [Bitcoin]: Deprecate tw_bitcoin/src/modules * [Bitcoin]: Add `TransactionProtobuf` module * [Bitcoin]: Use `TWError<SigningError>` in tw_utxo * [Bitcoin]: Add `UtxoProtobuf` builder * Merge `SigningMethod::TaprootAll` and `SigningMethod::TaprootOnePrevout` * Temporary remove `OrdinalInscription` * [Bitcoin]: Add a `SpendingDataConstructor` pattern * Refactor `UtxoBuilder` to create a corresponding `SpendingDataConstructor` * Slightly refactor `BitcoinV3.proto` API * [Bitcoin]: Finalize UTXO selectors * Add `MaxSelector`, add `SigningInput::max_amount_output` * Refactor `SelectorBuilder` as `ExactSelector` * Add `DustFilter` and `DustPolicy` * Slightly refactor `BitcoinV3.proto` API * [Bitcoin]: Finalize UTXO selectors, split `SighashComputer` * Add `MaxSelector`, add `SigningInput::max_amount_output` * Refactor `SelectorBuilder` as `ExactSelector` * Add `DustFilter` and `DustPolicy` * Slightly refactor `BitcoinV3.proto` API * Split `SighashComputer` into several modules * Finalize `TxCompiler` * Finalize `SighashVerifier` * [Bitcoin]: Add `TxSigner` * [Bitcoin]: Add `OutputProtobuf` builder * Fix Segwit address to not allow witness version > 0 * [Bitcoin]: Refactor `TaprootAddress` and `SegwitAddress` * [Bitcoin]: Add transaction signer * [Bitcoin]: Add transaction planner * [Bitcoin]: Add transaction compiler * [Bitcoin]: Make `TxPlanner` generic * [Bitcoin]: Some clean ups * [Bitcoin]: Remove legacy BRC20 API * [Bitcoin]: Add BRC20 test * Add default chain info if not provided * Add default sequence if not provided * [Bitcoin]: Add P2PKH test * [Bitcoin]: Fix final fee calculation * [Bitcoin]: Add p2tr_key_path * [Bitcoin]: Move unit tests to `tw_any_coin/tests/chains/bitcoin` * [Bitcoin]: Fix `send_to_address` tests * [Bitcoin]: Fix broken tests * [Bitcoin]: Move UTXO selection to `tw_any_coin/tests` * [Bitcoin]: Add exact selector with and without change test * [Bitcoin]: Check transaction weight * Add more exact_selector tests * [Bitcoin]: Add more selector tests, increase code coverage * [Bitcoin]: Add p2pkh compile test * [Bitcoin]: Add mainnet BCH test * Fix fork_id sighashing * [Bitcoin]: Add send to p2sh and p2wsh address tests * Add p2wpkh signing test * Set V1 default transaction version * [Bitcoin]: Add OP_RETURN test * [Bitcoin]: Allow to pass a DER encoded signature to `TransactionCompiler` * [Bitcoin]: Test Bitcoin addresses * [Bitcoin]: Add BRC20 compile tests * [Bitcoin]: Fix transaction weight * [Bitcoin]: Remove legacy FFI TWBitcoinFeeCalculateFee * Return an error if `is_it_brc_operation` is true * [Bitcoin]: Add P2SH output signing test * [Bitcoin]: Add p2tr_script_path output test * Reorg p2tr_key_path tests to cover multiple protobuf types * [Bitcoin]: Fix p2tr custom script * [Bitcoin]: Fix P2PK * Extend P2PKH test to cover all protobuf inputs * Add P2WSH output test * Add sighash single test * [Bitcoin]: Fix some TODOs * [Bitcoin]: Finalize BitcoinV2 * Remove `Bitcoin.SigningInput.is_it_brc_operation` and `Bitcoin.SigningInput.planning_v2` * TODO adopt C++ BRC20 tests for BitcoinV2 * [Bitcoin]: Fix one of Android tests * Add Rust `test_bitcoin_sign_brc20_transfer` test * [Bitcoin]: Uncomment out Android tests * [Bitcoin]: Fix iOS tests * Remove NFT data from Android and iOS test suits * [Bitcoin]: Fix WASM BRC20 tests * [CI] Trigger CI * [Bitcoin]: Minor fixes * [Bitcoin]: Fix Rust WASM tests * [Bitcoin]: Add real P2TR transaction tests * [TON]: Add P2TR test in WASM --------- Co-authored-by: lamafab <42901763+lamafab@users.noreply.github.com>
- Loading branch information