@@ -36,7 +36,6 @@ use bitcoin::consensus::encode;
3636use bitcoin:: ext:: * ;
3737use bitcoin:: locktime:: absolute;
3838use bitcoin:: psbt:: { self , Input , Psbt , PsbtSighashType } ;
39- use bitcoin:: secp256k1:: { Secp256k1 , Signing , Verification } ;
4039use bitcoin:: {
4140 transaction, Address , Amount , CompressedPublicKey , Network , OutPoint , RedeemScriptBuf ,
4241 ScriptPubKeyBuf , ScriptSigBuf , Sequence , Transaction , TxIn , TxOut , Witness ,
@@ -66,17 +65,15 @@ const CHANGE_AMOUNT_BTC: &str = "48.99999 BTC"; // 1000 sat transaction fee.
6665const NETWORK : Network = Network :: Regtest ;
6766
6867fn main ( ) -> Result < ( ) > {
69- let secp = Secp256k1 :: new ( ) ;
70-
7168 let ( offline, fingerprint, account_0_xpub, input_xpub) =
72- ColdStorage :: new ( & secp , EXTENDED_MASTER_PRIVATE_KEY ) ?;
69+ ColdStorage :: new ( EXTENDED_MASTER_PRIVATE_KEY ) ?;
7370
7471 let online = WatchOnly :: new ( account_0_xpub, input_xpub, fingerprint) ;
7572
76- let created = online. create_psbt ( & secp ) ?;
73+ let created = online. create_psbt ( ) ?;
7774 let updated = online. update_psbt ( created) ?;
7875
79- let signed = offline. sign_psbt ( & secp , updated) ?;
76+ let signed = offline. sign_psbt ( updated) ?;
8077
8178 let finalized = online. finalize_psbt ( signed) ?;
8279
@@ -90,6 +87,7 @@ fn main() -> Result<()> {
9087 Ok ( ( ) )
9188}
9289
90+ // TODO: This comment is stale now, re-visit.
9391// We cache the pubkeys for convenience because it requires a secp context to convert the private key.
9492/// An example of an offline signer i.e., a cold-storage device.
9593struct ColdStorage {
@@ -109,20 +107,20 @@ impl ColdStorage {
109107 /// # Returns
110108 ///
111109 /// The newly created signer along with the data needed to configure a watch-only wallet.
112- fn new < C : Signing > ( secp : & Secp256k1 < C > , xpriv : & str ) -> Result < ExportData > {
110+ fn new ( xpriv : & str ) -> Result < ExportData > {
113111 let master_xpriv = xpriv. parse :: < Xpriv > ( ) ?;
114- let master_xpub = Xpub :: from_xpriv ( secp , & master_xpriv) ;
112+ let master_xpub = Xpub :: from_xpriv ( & master_xpriv) ;
115113
116114 // Hardened children require secret data to derive.
117115
118116 let path = "84h/0h/0h" . into_derivation_path ( ) ?;
119117 let account_0_xpriv =
120- master_xpriv. derive_xpriv ( secp , & path) . expect ( "derivation path is short" ) ;
121- let account_0_xpub = Xpub :: from_xpriv ( secp , & account_0_xpriv) ;
118+ master_xpriv. derive_xpriv ( & path) . expect ( "derivation path is short" ) ;
119+ let account_0_xpub = Xpub :: from_xpriv ( & account_0_xpriv) ;
122120
123121 let path = INPUT_UTXO_DERIVATION_PATH . into_derivation_path ( ) ?;
124- let input_xpriv = master_xpriv. derive_xpriv ( secp , & path) . expect ( "derivation path is short" ) ;
125- let input_xpub = Xpub :: from_xpriv ( secp , & input_xpriv) ;
122+ let input_xpriv = master_xpriv. derive_xpriv ( & path) . expect ( "derivation path is short" ) ;
123+ let input_xpub = Xpub :: from_xpriv ( & input_xpriv) ;
126124
127125 let wallet = ColdStorage { master_xpriv, master_xpub } ;
128126 let fingerprint = wallet. master_fingerprint ( ) ;
@@ -134,12 +132,11 @@ impl ColdStorage {
134132 fn master_fingerprint ( & self ) -> Fingerprint { self . master_xpub . fingerprint ( ) }
135133
136134 /// Signs `psbt` with this signer.
137- fn sign_psbt < C : Signing + Verification > (
135+ fn sign_psbt (
138136 & self ,
139- secp : & Secp256k1 < C > ,
140137 mut psbt : Psbt ,
141138 ) -> Result < Psbt > {
142- match psbt. sign ( & self . master_xpriv , secp ) {
139+ match psbt. sign ( & self . master_xpriv ) {
143140 Ok ( keys) => assert_eq ! ( keys. len( ) , 1 ) ,
144141 Err ( ( _, e) ) => {
145142 let e = e. get ( & 0 ) . expect ( "at least one error" ) ;
@@ -173,12 +170,12 @@ impl WatchOnly {
173170 }
174171
175172 /// Creates the PSBT, in BIP-0174 parlance this is the 'Creator'.
176- fn create_psbt < C : Verification > ( & self , secp : & Secp256k1 < C > ) -> Result < Psbt > {
173+ fn create_psbt ( & self ) -> Result < Psbt > {
177174 let to_address =
178175 RECEIVE_ADDRESS . parse :: < Address < _ > > ( ) ?. require_network ( Network :: Regtest ) ?;
179176 let to_amount = OUTPUT_AMOUNT_BTC . parse :: < Amount > ( ) ?;
180177
181- let ( _, change_address, _) = self . change_address ( secp ) ?;
178+ let ( _, change_address, _) = self . change_address ( ) ?;
182179 let change_amount = CHANGE_AMOUNT_BTC . parse :: < Amount > ( ) ?;
183180
184181 let tx = Transaction {
@@ -253,12 +250,11 @@ impl WatchOnly {
253250 /// "m/84h/0h/0h/1/0"). A real wallet would have access to the chain so could determine if an
254251 /// address has been used or not. We ignore this detail and just re-use the first change address
255252 /// without loss of generality.
256- fn change_address < C : Verification > (
253+ fn change_address (
257254 & self ,
258- secp : & Secp256k1 < C > ,
259255 ) -> Result < ( CompressedPublicKey , Address , DerivationPath ) > {
260256 let path = [ ChildNumber :: ONE_NORMAL , ChildNumber :: ZERO_NORMAL ] ;
261- let derived = self . account_0_xpub . derive_xpub ( secp , path) ?;
257+ let derived = self . account_0_xpub . derive_xpub ( path) ?;
262258
263259 let pk = derived. to_public_key ( ) ;
264260 let addr = Address :: p2wpkh ( pk, NETWORK ) ;
0 commit comments