@@ -20,22 +20,22 @@ use bitcoin::secp256k1::{self, All, Message, Secp256k1, ecdsa::Signature};
2020use bitcoin_hashes:: sha256;
2121use std:: sync:: Arc ;
2222
23- const BIP84_PATH_LEN : usize = 5 ;
23+ const BIP84_PATH_LEN : u32 = 5 ;
2424
2525// BIP84 derivation path structure, m / 84' / 0' / account' / change / address_index
2626
2727// Derivation sub-path indexes that must be hardened
28- const BIP84_HARDENED_SUBPATH : [ usize ; 3 ] = [ 0 , 1 , 2 ] ;
28+ const BIP84_HARDENED_SUBPATH : [ u32 ; 3 ] = [ 0 , 1 , 2 ] ;
2929
3030pub struct TapSigner {
3131 pub transport : Arc < dyn CkTransport > ,
3232 pub secp : Secp256k1 < All > ,
33- pub proto : usize ,
33+ pub proto : u32 ,
3434 pub ver : String ,
35- pub birth : usize ,
36- pub path : Option < Vec < usize > > ,
35+ pub birth : u32 ,
36+ pub path : Option < Vec < u32 > > ,
3737 // [(1<<31)+84, (1<<31), (1<<31)], user-defined, will be omitted if not yet setup
38- pub num_backups : Option < usize > ,
38+ pub num_backups : Option < u32 > ,
3939 pub pubkey : PublicKey ,
4040 pub card_nonce : [ u8 ; 16 ] ,
4141 pub auth_delay : Option < u8 > ,
@@ -162,32 +162,32 @@ pub trait TapSignerShared: Authentication {
162162 let witness_utxo = input
163163 . witness_utxo
164164 . as_ref ( )
165- . ok_or ( SignPsbtError :: MissingUtxo ( input_index) ) ?;
165+ . ok_or ( SignPsbtError :: MissingUtxo ( input_index as u32 ) ) ?;
166166
167167 let amount = witness_utxo. value ;
168168
169169 // extract the P2WPKH script from PSBT
170170 let script_pubkey = & witness_utxo. script_pubkey ;
171171 if !script_pubkey. is_p2wpkh ( ) {
172- return Err ( SignPsbtError :: InvalidScript ( input_index) ) ;
172+ return Err ( SignPsbtError :: InvalidScript ( input_index as u32 ) ) ;
173173 }
174174
175175 // get the public key from the PSBT
176176 let key_pairs = & input. bip32_derivation ;
177177 let ( psbt_pubkey, ( _fingerprint, path) ) = key_pairs
178178 . iter ( )
179179 . next ( )
180- . ok_or ( SignPsbtError :: MissingPubkey ( input_index) ) ?;
180+ . ok_or ( SignPsbtError :: MissingPubkey ( input_index as u32 ) ) ?;
181181
182182 let path = path. to_u32_vec ( ) ;
183183
184- if path. len ( ) != BIP84_PATH_LEN {
185- return Err ( SignPsbtError :: InvalidPath ( input_index) ) ;
184+ if path. len ( ) as u32 != BIP84_PATH_LEN {
185+ return Err ( SignPsbtError :: InvalidPath ( input_index as u32 ) ) ;
186186 }
187187
188- let sub_path = BIP84_HARDENED_SUBPATH . map ( |i| path[ i] ) ;
188+ let sub_path = BIP84_HARDENED_SUBPATH . map ( |i| path[ i as usize ] ) ;
189189 if sub_path. iter ( ) . any ( |p| * p > BIP32_HARDENED_MASK ) {
190- return Err ( SignPsbtError :: InvalidPath ( input_index) ) ;
190+ return Err ( SignPsbtError :: InvalidPath ( input_index as u32 ) ) ;
191191 }
192192
193193 // calculate sighash
@@ -214,7 +214,7 @@ pub trait TapSignerShared: Authentication {
214214 . collect ( ) ;
215215 let derive_response = self . derive ( path, cvc) . await ;
216216 if derive_response. is_err ( ) {
217- return Err ( SignPsbtError :: PubkeyMismatch ( input_index) ) ;
217+ return Err ( SignPsbtError :: PubkeyMismatch ( input_index as u32 ) ) ;
218218 }
219219
220220 // update signature to the new one we just derived
@@ -223,7 +223,7 @@ pub trait TapSignerShared: Authentication {
223223
224224 // if still not matching, return error
225225 if sign_response. pubkey != psbt_pubkey. serialize ( ) {
226- return Err ( SignPsbtError :: PubkeyMismatch ( input_index) ) ;
226+ return Err ( SignPsbtError :: PubkeyMismatch ( input_index as u32 ) ) ;
227227 }
228228 }
229229
@@ -286,11 +286,11 @@ pub trait TapSignerShared: Authentication {
286286 /// Change the CVC used for card authentication to a new user provided one
287287 async fn change ( & mut self , new_cvc : & str , cvc : & str ) -> Result < ( ) , ChangeError > {
288288 if new_cvc. len ( ) < 6 {
289- return Err ( ChangeError :: TooShort ( new_cvc. len ( ) ) ) ;
289+ return Err ( ChangeError :: TooShort ( new_cvc. len ( ) as u8 ) ) ;
290290 }
291291
292292 if new_cvc. len ( ) > 32 {
293- return Err ( ChangeError :: TooLong ( new_cvc. len ( ) ) ) ;
293+ return Err ( ChangeError :: TooLong ( new_cvc. len ( ) as u8 ) ) ;
294294 }
295295
296296 if new_cvc == cvc {
0 commit comments