Skip to content

Move bitcoin signer to rust#361

Open
0xh3rman wants to merge 5 commits into
mainfrom
bitcoin-signer
Open

Move bitcoin signer to rust#361
0xh3rman wants to merge 5 commits into
mainfrom
bitcoin-signer

Conversation

@0xh3rman
Copy link
Copy Markdown
Collaborator

@0xh3rman 0xh3rman commented May 21, 2026

Transfer Matrix

ID Coverage Builder / branch Example Status
T1 Native segwit P2WPKH transfer with change sign_bitcoin_like + UtxoPlanner::Exact BTC bc1q → bc1q Tested (9f71a30b…)
T2 Max-send (sweep) leaving no change UtxoPlanner::Max BTC/LTC max-send Tested — BTC/LTC/Doge (5072b15a…)
T4 Transfer with memo (OP_RETURN at output index 1) op_return_output + spend_outputs Covered indirectly by W1 Via W1
T5 Legacy P2PKH transfer sign_bitcoin_like legacy path Doge D… → D… Tested (b99c4551…)
T6 Bitcoin Cash P2PKH with FORKID sighash bitcoin_cash::sign_plan (BIP143 + 0x41) BCH bitcoincash:q… → bitcoincash:q… Tested (7360dbab…)
T7 Zcash t1 → t1 transparent transfer zcash::sign_transparent ZIP-244 v5 Zcash t1… → t1… Tested (09cc92df…)
T8 Zcash max-send Zcash branch in UtxoPlanner::Max + ZIP-317 fee Zcash sweep Tested (e5d68d6b…)

Swap Matrix

ID Coverage Builder / branch Example Status
W1 Swap via Transfer path (memo OP_RETURN), exact amount SpendRequest::swap Transfer BTC → ETH via Thorchain Pending (Thorchain paused)
W2 Swap via Transfer path, max amount (memo optional) Transfer + use_max_amount BCH → SOL via NEAR Intents max Tested (7360dbab…, intent)
W3 Swap via Contract path (hex-decoded nulldata), exact amount SpendRequest::swap Contract (request.rs:42-58) BTC → SOL via Chainflip Tested + credited (scan, 9931d6dd…)
W4 Swap via Contract path, max-intent (must still emit change as refund) Contract + exact-amount with change BTC → SOL via Chainflip max Fixed + tested (scan, 759ef7a6…)

@0xh3rman 0xh3rman marked this pull request as ready for review May 22, 2026 12:57
@0xh3rman 0xh3rman force-pushed the bitcoin-signer branch 2 times, most recently from 479d3b4 to 403aebb Compare May 30, 2026 08:17
@0xh3rman 0xh3rman self-assigned this May 30, 2026
}
}

fn metadata_utxos(chain: BitcoinChain, metadata: &TransactionLoadMetadata) -> Result<Vec<UTXO>, SignerError> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use metadata.get_utxos()

pub use primitives::testkit::signer_mock::TEST_PRIVATE_KEY;

pub const TEST_UTXO_TXID: &str = "0000000000000000000000000000000000000000000000000000000000000001";
pub const TEST_ZCASH_BRANCH_ID: &str = "4dec4df0";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is two TEST_ZCASH_BRANCH_ID vars

struct EstimateFeeService {
init() {}

func provider(chain: Primitives.Chain) throws -> any GemGatewayEstimateFee {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove EstimateFeeService?

})
}

pub(crate) fn assert_invalid_input<T>(result: Result<T, SignerError>, expected: &str) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we ditch it?

Ok(hex::encode(tx.encode()))
}

pub(crate) fn branch_id_from_metadata(metadata: &TransactionLoadMetadata) -> Result<u32, SignerError> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to TransactionLoadMetadata extension

pub(super) fn estimate_fee(chain: BitcoinChain, inputs: &[PlanInput], outputs: &[PlanOutput], fee_rate: u64) -> Result<u64, SignerError> {
match chain {
BitcoinChain::Zcash => return estimate_zcash_fee(inputs, outputs),
BitcoinChain::Bitcoin | BitcoinChain::BitcoinCash | BitcoinChain::Litecoin | BitcoinChain::Doge => {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this code to estimate_bitcoin_fee

}

fn estimate_zcash_fee(inputs: &[PlanInput], outputs: &[PlanOutput]) -> Result<u64, SignerError> {
const MARGINAL_FEE: u64 = 5_000;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move out of. the function

const P2PKH_STANDARD_INPUT_SIZE: u64 = 150;
const P2PKH_STANDARD_OUTPUT_SIZE: u64 = 34;

let tx_in_total_size = inputs
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never use tx_

address_for_hash(chain, public_key_hash(&public_key.to_bytes()))
}

pub fn destination_address(chain: BitcoinChain) -> String {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add prefix mock_ in many places

Comment thread core/Cargo.toml
bitcoincash-addr = { version = "0.5.2" }
blake2b_simd = { version = "1.0.4" }
bs58 = { version = "0.5.1", features = ["check"] }
hex = { version = "0.4.3" }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review if any typeshare models could be removed as well

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