3
3
use bitcoin:: secp256k1:: { Keypair , Secp256k1 , SecretKey , schnorr} ;
4
4
use bitcoin:: taproot:: { LeafVersion , TaprootBuilder , TaprootSpendInfo } ;
5
5
use bitcoin:: {
6
- Address , Amount , FeeRate , Network , OutPoint , ScriptBuf , Sequence , TapLeafHash , TapNodeHash ,
7
- TapSighash , TapTweakHash , Transaction , TxIn , TxOut , Txid , Weight , Witness , XOnlyPublicKey ,
6
+ Amount , FeeRate , Network , OutPoint , ScriptBuf , Sequence , TapLeafHash , TapNodeHash , TapSighash ,
7
+ TapTweakHash , Transaction , TxIn , TxOut , Txid , Weight , Witness , XOnlyPublicKey ,
8
8
} ;
9
9
use colored:: * ;
10
10
use std:: io:: { self , Write } ;
11
11
use std:: str:: FromStr ;
12
12
use std:: sync:: LazyLock ;
13
13
14
- use crate :: EVMAddress ;
15
14
use crate :: config:: { BRIDGE_AMOUNT , UNSPENDABLE_XONLY_PUBKEY , USER_TAKES_AFTER , get_verifier_pks} ;
16
15
use crate :: musig2:: AggregateFromPublicKeys ;
17
16
use crate :: script:: { deposit_script, recover_script} ;
17
+ use crate :: { BitcoinAddress , CitreaAddress } ;
18
18
use bitcoin:: hashes:: Hash ;
19
19
20
20
pub static SECP : LazyLock < Secp256k1 < bitcoin:: secp256k1:: All > > = LazyLock :: new ( Secp256k1 :: new) ;
21
21
22
22
/// Calculate taproot address from a keypair
23
- pub fn calculate_taproot_address ( keypair : & Keypair , network : Network ) -> Address {
23
+ pub fn calculate_taproot_address ( keypair : & Keypair , network : Network ) -> BitcoinAddress {
24
24
let ( xonly_public_key, _parity) = keypair. public_key ( ) . x_only_public_key ( ) ;
25
- Address :: p2tr ( & SECP , xonly_public_key, None , network)
25
+ BitcoinAddress :: p2tr ( & SECP , xonly_public_key, None , network)
26
26
}
27
27
28
28
/// Generate a new random secret key and calculate its corresponding taproot address
29
29
pub fn generate_key_and_taproot_address (
30
30
network : Network ,
31
- ) -> Result < ( Keypair , Address ) , Box < dyn std:: error:: Error > > {
31
+ ) -> Result < ( Keypair , BitcoinAddress ) , Box < dyn std:: error:: Error > > {
32
32
let keypair = Keypair :: new ( & SECP , & mut bitcoin:: secp256k1:: rand:: thread_rng ( ) ) ;
33
33
let address = calculate_taproot_address ( & keypair, network) ;
34
34
Ok ( ( keypair, address) )
@@ -37,7 +37,7 @@ pub fn generate_key_and_taproot_address(
37
37
pub fn generate_keypair_and_taproot_address_from_private_key (
38
38
private_key : & str ,
39
39
network : Network ,
40
- ) -> Result < ( Keypair , Address ) , Box < dyn std:: error:: Error > > {
40
+ ) -> Result < ( Keypair , BitcoinAddress ) , Box < dyn std:: error:: Error > > {
41
41
let sk = SecretKey :: from_str ( private_key) ?;
42
42
let keypair = Keypair :: from_secret_key ( & SECP , & sk) ;
43
43
let address = calculate_taproot_address ( & keypair, network) ;
@@ -66,17 +66,17 @@ pub fn confirm_private_key_storage(auto_yes: bool) -> Result<bool, Box<dyn std::
66
66
Ok ( input. trim ( ) . to_lowercase ( ) == "y" || input. trim ( ) . to_lowercase ( ) == "yes" )
67
67
}
68
68
69
- /// Calculate the deposit address and taproot spend info for a given EVM address and recovery taproot address
69
+ /// Calculate the deposit address and taproot spend info for a given Citrea address and recovery taproot address
70
70
pub fn calculate_deposit_address (
71
- evm_address : & EVMAddress ,
72
- recovery_taproot_address : & Address ,
71
+ citrea_address : & CitreaAddress ,
72
+ recovery_taproot_address : & BitcoinAddress ,
73
73
network : Network ,
74
- ) -> Result < ( Address , TaprootSpendInfo ) , Box < dyn std:: error:: Error > > {
74
+ ) -> Result < ( BitcoinAddress , TaprootSpendInfo ) , Box < dyn std:: error:: Error > > {
75
75
let verifiers_public_keys = get_verifier_pks ( network) ;
76
76
let agg_pk = XOnlyPublicKey :: from_musig2_pks ( & verifiers_public_keys) ?;
77
77
debug ! ( "agg_pk: {:?}" , agg_pk. to_string( ) ) ;
78
78
debug ! ( "verifiers_public_keys: {:?}" , verifiers_public_keys) ;
79
- let deposit_script = deposit_script ( * evm_address , agg_pk) ;
79
+ let deposit_script = deposit_script ( * citrea_address , agg_pk) ;
80
80
let recovery_key =
81
81
XOnlyPublicKey :: from_slice ( & recovery_taproot_address. script_pubkey ( ) . to_bytes ( ) [ 2 ..34 ] ) ?;
82
82
let recover_script = recover_script ( recovery_key, USER_TAKES_AFTER ) ;
@@ -89,7 +89,7 @@ pub fn calculate_deposit_address(
89
89
. finalize ( & SECP , * UNSPENDABLE_XONLY_PUBKEY )
90
90
. expect ( "finalized script is valid" ) ;
91
91
92
- let deposit_address = Address :: p2tr (
92
+ let deposit_address = BitcoinAddress :: p2tr (
93
93
& SECP ,
94
94
* UNSPENDABLE_XONLY_PUBKEY ,
95
95
taproot_spend_info. merkle_root ( ) ,
@@ -126,19 +126,19 @@ pub fn sign_with_tweak(
126
126
}
127
127
128
128
#[ allow( clippy:: too_many_arguments) ]
129
- /// Sign a recovery transaction with a given keypair, EVM address, recovery taproot address, deposit outpoint, deposit amount, claim address, fee rate, and network
129
+ /// Sign a recovery transaction with a given keypair, Citrea address, recovery taproot address, deposit outpoint, deposit amount, claim address, fee rate, and network
130
130
pub fn sign_recovery_tx (
131
131
keypair : & Keypair ,
132
- evm_address : & EVMAddress ,
133
- recovery_taproot_address : & Address ,
132
+ citrea_address : & CitreaAddress ,
133
+ recovery_taproot_address : & BitcoinAddress ,
134
134
deposit_outpoint : & OutPoint ,
135
135
deposit_amount : Option < Amount > ,
136
- claim_address : & Address ,
136
+ claim_address : & BitcoinAddress ,
137
137
fee_rate : Option < FeeRate > ,
138
138
network : Network ,
139
139
) -> Result < Transaction , Box < dyn std:: error:: Error > > {
140
140
let ( deposit_address, taproot_spend_info) =
141
- calculate_deposit_address ( evm_address , recovery_taproot_address, network) ?;
141
+ calculate_deposit_address ( citrea_address , recovery_taproot_address, network) ?;
142
142
143
143
let recovery_script = recover_script (
144
144
XOnlyPublicKey :: from_slice ( & recovery_taproot_address. script_pubkey ( ) . to_bytes ( ) [ 2 ..34 ] ) ?,
@@ -249,11 +249,11 @@ pub fn sign_recovery_tx(
249
249
250
250
pub fn verify_recovery_tx (
251
251
recovery_tx : & Transaction ,
252
- evm_address : & EVMAddress ,
253
- recovery_taproot_address : & Address ,
252
+ citrea_address : & CitreaAddress ,
253
+ recovery_taproot_address : & BitcoinAddress ,
254
254
input_amount : Option < Amount > ,
255
255
network : Network ,
256
- ) -> Result < ( Txid , Address , Amount ) , Box < dyn std:: error:: Error > > {
256
+ ) -> Result < ( Txid , BitcoinAddress , Amount ) , Box < dyn std:: error:: Error > > {
257
257
// sanity check input count
258
258
if recovery_tx. input . len ( ) != 1 {
259
259
return Err ( "Recovery transaction must have exactly one input" . into ( ) ) ;
@@ -275,7 +275,7 @@ pub fn verify_recovery_tx(
275
275
}
276
276
277
277
let ( deposit_address, taproot_spend_info) =
278
- calculate_deposit_address ( evm_address , recovery_taproot_address, network) ?;
278
+ calculate_deposit_address ( citrea_address , recovery_taproot_address, network) ?;
279
279
280
280
let recovery_key =
281
281
XOnlyPublicKey :: from_slice ( & recovery_taproot_address. script_pubkey ( ) . to_bytes ( ) [ 2 ..34 ] ) ?;
@@ -359,7 +359,7 @@ pub fn verify_recovery_tx(
359
359
"Signature verification failed. Possible causes include an incorrect input amount, an invalid signature, or a mismatched public key." . into ( )
360
360
} ) ?;
361
361
362
- let output_address = Address :: from_script (
362
+ let output_address = BitcoinAddress :: from_script (
363
363
& recovery_tx. output [ 0 ] . script_pubkey ,
364
364
network,
365
365
)
@@ -376,9 +376,9 @@ pub fn verify_recovery_tx(
376
376
377
377
pub fn sign_withdrawal_signature (
378
378
keypair : & Keypair ,
379
- signer_address : & Address ,
379
+ signer_address : & BitcoinAddress ,
380
380
withdrawal_utxo : & OutPoint ,
381
- claim_address : & Address ,
381
+ claim_address : & BitcoinAddress ,
382
382
amount : Amount ,
383
383
) -> Result < bitcoin:: taproot:: Signature , Box < dyn std:: error:: Error > > {
384
384
let txin = TxIn {
@@ -427,9 +427,9 @@ pub fn sign_withdrawal_signature(
427
427
428
428
pub fn verify_withdrawal_signature (
429
429
sig : & bitcoin:: taproot:: Signature ,
430
- signer_address : & Address ,
430
+ signer_address : & BitcoinAddress ,
431
431
withdrawal_utxo : & OutPoint ,
432
- claim_address : & Address ,
432
+ claim_address : & BitcoinAddress ,
433
433
amount : Amount ,
434
434
) -> Result < ( ) , Box < dyn std:: error:: Error > > {
435
435
let txin = TxIn {
0 commit comments