Skip to content

Commit

Permalink
Merge pull request #8657 from gnasnik/master
Browse files Browse the repository at this point in the history
feat: add create ledger wallet address by account index command
  • Loading branch information
magik6k authored May 27, 2022
2 parents 44d415a + c33f87d commit d38cd87
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions cmd/lotus-shed/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var ledgerCmd = &cli.Command{
ledgerKeyInfoCmd,
ledgerSignTestCmd,
ledgerShowCmd,
ledgerNewAddressesCmd,
},
}

Expand Down Expand Up @@ -291,3 +292,68 @@ var ledgerShowCmd = &cli.Command{
return nil
},
}

var ledgerNewAddressesCmd = &cli.Command{
Name: "new",
Flags: []cli.Flag{},
Action: func(cctx *cli.Context) error {
ctx := lcli.ReqContext(cctx)

if cctx.NArg() != 1 {
return fmt.Errorf("must pass account index")
}

index, err := strconv.ParseUint(cctx.Args().First(), 10, 32)
if err != nil {
return err
}

api, closer, err := lcli.GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()

fl, err := ledgerfil.FindLedgerFilecoinApp()
if err != nil {
return err
}
defer fl.Close() // nolint

if err := ctx.Err(); err != nil {
return err
}

p := []uint32{hdHard | 44, hdHard | 461, hdHard, 0, uint32(index)}
pubk, err := fl.GetPublicKeySECP256K1(p)
if err != nil {
return err
}

addr, err := address.NewSecp256k1Address(pubk)
if err != nil {
return err
}

var pd ledgerwallet.LedgerKeyInfo
pd.Address = addr
pd.Path = p

b, err := json.Marshal(pd)
if err != nil {
return err
}

var ki types.KeyInfo
ki.Type = types.KTSecp256k1Ledger
ki.PrivateKey = b

_, err = api.WalletImport(ctx, &ki)
if err != nil {
return err
}

fmt.Printf("%s %s\n", addr, printHDPath(p))
return nil
},
}

0 comments on commit d38cd87

Please sign in to comment.