@@ -145,8 +145,11 @@ pub struct KeySet {
145145}
146146
147147impl KeySet {
148- fn default_keys ( seed : & [ u8 ] , network : Network ) -> Result < Self , DefaultSignerError > {
149- let account_number = account_number ( network) ;
148+ fn default_keys (
149+ seed : & [ u8 ] ,
150+ network : Network ,
151+ account_number : u32 ,
152+ ) -> Result < Self , DefaultSignerError > {
150153 let derivation_path = format ! ( "m/8797555'/{account_number}'" ) . parse ( ) ?;
151154 let derived_key_set = DerivedKeySet :: new ( seed, network, derivation_path) ?;
152155 derived_key_set. to_key_set ( ChildNumber :: from_hardened_idx ( 0 ) . ok ( ) )
@@ -156,8 +159,8 @@ impl KeySet {
156159 seed : & [ u8 ] ,
157160 network : Network ,
158161 use_address_index : bool ,
162+ account_number : u32 ,
159163 ) -> Result < Self , DefaultSignerError > {
160- let account_number = account_number ( network) ;
161164 let derivation_path = if use_address_index {
162165 format ! ( "m/86'/0'/0'/0/{account_number}" )
163166 } else {
@@ -190,8 +193,8 @@ impl KeySet {
190193 seed : & [ u8 ] ,
191194 network : Network ,
192195 use_address_index : bool ,
196+ account_number : u32 ,
193197 ) -> Result < Self , DefaultSignerError > {
194- let account_number = account_number ( network) ;
195198 let derivation_path = if use_address_index {
196199 format ! ( "m/84'/0'/0'/0/{account_number}" )
197200 } else {
@@ -206,8 +209,8 @@ impl KeySet {
206209 seed : & [ u8 ] ,
207210 network : Network ,
208211 use_address_index : bool ,
212+ account_number : u32 ,
209213 ) -> Result < Self , DefaultSignerError > {
210- let account_number = account_number ( network) ;
211214 let derivation_path = if use_address_index {
212215 format ! ( "m/49'/0'/0'/0/{account_number}" )
213216 } else {
@@ -222,8 +225,8 @@ impl KeySet {
222225 seed : & [ u8 ] ,
223226 network : Network ,
224227 use_address_index : bool ,
228+ account_number : u32 ,
225229 ) -> Result < Self , DefaultSignerError > {
226- let account_number = account_number ( network) ;
227230 let derivation_path = if use_address_index {
228231 format ! ( "m/44'/0'/0'/0/{account_number}" )
229232 } else {
@@ -264,25 +267,31 @@ impl From<bitcoin::bip32::Error> for DefaultSignerError {
264267
265268impl DefaultSigner {
266269 pub fn new ( seed : & [ u8 ] , network : Network ) -> Result < Self , DefaultSignerError > {
267- Self :: with_keyset_type ( seed, network, KeySetType :: Default , false )
270+ Self :: with_keyset_type ( seed, network, KeySetType :: Default , false , None )
268271 }
269272
270273 pub fn with_keyset_type (
271274 seed : & [ u8 ] ,
272275 network : Network ,
273276 key_type : KeySetType ,
274277 use_address_index : bool ,
278+ account_no : Option < u32 > ,
275279 ) -> Result < Self , DefaultSignerError > {
280+ let account_number = account_no. unwrap_or_else ( || account_number ( network) ) ;
276281 let key_set = match key_type {
277- KeySetType :: Default => KeySet :: default_keys ( seed, network) ,
278- KeySetType :: Taproot => KeySet :: taproot_keys ( seed, network, use_address_index) ,
282+ KeySetType :: Default => KeySet :: default_keys ( seed, network, account_number) ,
283+ KeySetType :: Taproot => {
284+ KeySet :: taproot_keys ( seed, network, use_address_index, account_number)
285+ }
279286 KeySetType :: NativeSegwit => {
280- KeySet :: native_segwit_keys ( seed, network, use_address_index)
287+ KeySet :: native_segwit_keys ( seed, network, use_address_index, account_number )
281288 }
282289 KeySetType :: WrappedSegwit => {
283- KeySet :: wrapped_segwit_keys ( seed, network, use_address_index)
290+ KeySet :: wrapped_segwit_keys ( seed, network, use_address_index, account_number)
291+ }
292+ KeySetType :: Legacy => {
293+ KeySet :: legacy_bitcoin_keys ( seed, network, use_address_index, account_number)
284294 }
285- KeySetType :: Legacy => KeySet :: legacy_bitcoin_keys ( seed, network, use_address_index) ,
286295 } ?;
287296 Ok ( Self :: from_key_set ( key_set) )
288297 }
0 commit comments