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:: { CliConfig , UNSPENDABLE_XONLY_PUBKEY } ;
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,16 +66,16 @@ 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
config : CliConfig ,
74
- ) -> Result < ( Address , TaprootSpendInfo ) , Box < dyn std:: error:: Error > > {
74
+ ) -> Result < ( BitcoinAddress , TaprootSpendInfo ) , Box < dyn std:: error:: Error > > {
75
75
let agg_pk = XOnlyPublicKey :: from_musig2_pks ( config. verifiers_pks . as_slice ( ) ) ?;
76
76
debug ! ( "verifiers_public_keys: {:?}" , config. verifiers_pks) ;
77
77
debug ! ( "agg_pk: {:?}" , agg_pk. to_string( ) ) ;
78
- let deposit_script = deposit_script ( * evm_address , agg_pk) ;
78
+ let deposit_script = deposit_script ( * citrea_address , agg_pk) ;
79
79
let recovery_key =
80
80
XOnlyPublicKey :: from_slice ( & recovery_taproot_address. script_pubkey ( ) . to_bytes ( ) [ 2 ..34 ] ) ?;
81
81
let recover_script = recover_script ( recovery_key, config. user_takes_after ) ;
@@ -88,7 +88,7 @@ pub fn calculate_deposit_address(
88
88
. finalize ( & SECP , * UNSPENDABLE_XONLY_PUBKEY )
89
89
. expect ( "finalized script is valid" ) ;
90
90
91
- let deposit_address = Address :: p2tr (
91
+ let deposit_address = BitcoinAddress :: p2tr (
92
92
& SECP ,
93
93
* UNSPENDABLE_XONLY_PUBKEY ,
94
94
taproot_spend_info. merkle_root ( ) ,
@@ -125,19 +125,19 @@ pub fn sign_with_tweak(
125
125
}
126
126
127
127
#[ allow( clippy:: too_many_arguments) ]
128
- /// Sign a recovery transaction with a given keypair, EVM address, recovery taproot address, deposit outpoint, deposit amount, claim address, fee rate, and network
128
+ /// Sign a recovery transaction with a given keypair, Citrea address, recovery taproot address, deposit outpoint, deposit amount, claim address, fee rate, and network
129
129
pub fn sign_recovery_tx (
130
130
keypair : & Keypair ,
131
- evm_address : & EVMAddress ,
132
- recovery_taproot_address : & Address ,
131
+ citrea_address : & CitreaAddress ,
132
+ recovery_taproot_address : & BitcoinAddress ,
133
133
deposit_outpoint : & OutPoint ,
134
134
deposit_amount : Option < Amount > ,
135
- claim_address : & Address ,
135
+ claim_address : & BitcoinAddress ,
136
136
fee_rate : Option < FeeRate > ,
137
137
config : CliConfig ,
138
138
) -> Result < Transaction , Box < dyn std:: error:: Error > > {
139
139
let ( deposit_address, taproot_spend_info) =
140
- calculate_deposit_address ( evm_address , recovery_taproot_address, config. clone ( ) ) ?;
140
+ calculate_deposit_address ( citrea_address , recovery_taproot_address, config. clone ( ) ) ?;
141
141
142
142
let recovery_script = recover_script (
143
143
XOnlyPublicKey :: from_slice ( & recovery_taproot_address. script_pubkey ( ) . to_bytes ( ) [ 2 ..34 ] ) ?,
@@ -248,11 +248,11 @@ pub fn sign_recovery_tx(
248
248
249
249
pub fn verify_recovery_tx (
250
250
recovery_tx : & Transaction ,
251
- evm_address : & EVMAddress ,
252
- recovery_taproot_address : & Address ,
251
+ citrea_address : & CitreaAddress ,
252
+ recovery_taproot_address : & BitcoinAddress ,
253
253
input_amount : Option < Amount > ,
254
254
config : CliConfig ,
255
- ) -> Result < ( Txid , Address , Amount ) , Box < dyn std:: error:: Error > > {
255
+ ) -> Result < ( Txid , BitcoinAddress , Amount ) , Box < dyn std:: error:: Error > > {
256
256
// sanity check input count
257
257
if recovery_tx. input . len ( ) != 1 {
258
258
return Err ( "Recovery transaction must have exactly one input" . into ( ) ) ;
@@ -274,7 +274,7 @@ pub fn verify_recovery_tx(
274
274
}
275
275
276
276
let ( deposit_address, taproot_spend_info) =
277
- calculate_deposit_address ( evm_address , recovery_taproot_address, config. clone ( ) ) ?;
277
+ calculate_deposit_address ( citrea_address , recovery_taproot_address, config. clone ( ) ) ?;
278
278
279
279
let recovery_key =
280
280
XOnlyPublicKey :: from_slice ( & recovery_taproot_address. script_pubkey ( ) . to_bytes ( ) [ 2 ..34 ] ) ?;
@@ -358,7 +358,7 @@ pub fn verify_recovery_tx(
358
358
"Signature verification failed. Possible causes include an incorrect input amount, an invalid signature, or a mismatched public key." . into ( )
359
359
} ) ?;
360
360
361
- let output_address = Address :: from_script (
361
+ let output_address = BitcoinAddress :: from_script (
362
362
& recovery_tx. output [ 0 ] . script_pubkey ,
363
363
config. network ,
364
364
)
@@ -375,9 +375,9 @@ pub fn verify_recovery_tx(
375
375
376
376
pub fn sign_withdrawal_signature (
377
377
keypair : & Keypair ,
378
- signer_address : & Address ,
378
+ signer_address : & BitcoinAddress ,
379
379
withdrawal_utxo : & OutPoint ,
380
- claim_address : & Address ,
380
+ claim_address : & BitcoinAddress ,
381
381
amount : Amount ,
382
382
) -> Result < bitcoin:: taproot:: Signature , Box < dyn std:: error:: Error > > {
383
383
let txin = TxIn {
@@ -426,9 +426,9 @@ pub fn sign_withdrawal_signature(
426
426
427
427
pub fn verify_withdrawal_signature (
428
428
sig : & bitcoin:: taproot:: Signature ,
429
- signer_address : & Address ,
429
+ signer_address : & BitcoinAddress ,
430
430
withdrawal_utxo : & OutPoint ,
431
- claim_address : & Address ,
431
+ claim_address : & BitcoinAddress ,
432
432
amount : Amount ,
433
433
) -> Result < ( ) , Box < dyn std:: error:: Error > > {
434
434
let txin = TxIn {
0 commit comments