@@ -346,19 +346,28 @@ func (api *SignerAPI) startUSBListener() {
346
346
case accounts .WalletOpened :
347
347
status , _ := event .Wallet .Status ()
348
348
log .Info ("New wallet appeared" , "url" , event .Wallet .URL (), "status" , status )
349
-
350
- // Derive first N accounts, hardcoded for now
351
- var nextPath = make (accounts.DerivationPath , len (accounts .DefaultBaseDerivationPath ))
352
- copy (nextPath [:], accounts .DefaultBaseDerivationPath [:])
353
-
354
- for i := 0 ; i < numberOfAccountsToDerive ; i ++ {
355
- acc , err := event .Wallet .Derive (nextPath , true )
356
- if err != nil {
357
- log .Warn ("account derivation failed" , "error" , err )
358
- } else {
359
- log .Info ("derived account" , "address" , acc .Address )
349
+ var derive = func (numToDerive int , base accounts.DerivationPath ) {
350
+ // Derive first N accounts, hardcoded for now
351
+ var nextPath = make (accounts.DerivationPath , len (base ))
352
+ copy (nextPath [:], base [:])
353
+
354
+ for i := 0 ; i < numToDerive ; i ++ {
355
+ acc , err := event .Wallet .Derive (nextPath , true )
356
+ if err != nil {
357
+ log .Warn ("Account derivation failed" , "error" , err )
358
+ } else {
359
+ log .Info ("Derived account" , "address" , acc .Address , "path" , nextPath )
360
+ }
361
+ nextPath [len (nextPath )- 1 ]++
360
362
}
361
- nextPath [len (nextPath )- 1 ]++
363
+ }
364
+ if event .Wallet .URL ().Scheme == "ledger" {
365
+ log .Info ("Deriving ledger default paths" )
366
+ derive (numberOfAccountsToDerive / 2 , accounts .DefaultBaseDerivationPath )
367
+ log .Info ("Deriving ledger legacy paths" )
368
+ derive (numberOfAccountsToDerive / 2 , accounts .LegacyLedgerBaseDerivationPath )
369
+ } else {
370
+ derive (numberOfAccountsToDerive , accounts .DefaultBaseDerivationPath )
362
371
}
363
372
case accounts .WalletDropped :
364
373
log .Info ("Old wallet dropped" , "url" , event .Wallet .URL ())
0 commit comments