From 29ce594a199c56637e0feba97564b6b36cd7b41e Mon Sep 17 00:00:00 2001 From: Navid TehraniFar Date: Tue, 10 Sep 2024 12:52:32 -0700 Subject: [PATCH 1/2] dump keys --- main.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/main.go b/main.go index 92480a4e..1ba6c21c 100644 --- a/main.go +++ b/main.go @@ -147,6 +147,44 @@ func runServer(cfg *configs.Config) { log.Fatal(err) } + // dump keys + log.Error("Admin key info:") + log.Errorf("Admin address: %s", cfg.AdminAddress) + log.Errorf("Admin key type: %s", cfg.AdminKeyType) + log.Errorf("Admin key index: %d", cfg.AdminKeyIndex) + log.Errorf("Admin key: %s", cfg.AdminPrivateKey) + log.Errorf("Admin proposal key count: %d", cfg.AdminProposalKeyCount) + + log.Errorf("User key type: %s", cfg.DefaultKeyType) + log.Errorf("User key index: %d", cfg.DefaultKeyIndex) + log.Errorf("User key weight: %d", cfg.DefaultKeyWeight) + log.Errorf("User hash algo: %s", cfg.DefaultHashAlgo) + log.Errorf("User sig algo: %s", cfg.DefaultSignAlgo) + + log.Errorf("User encryption key: %s", cfg.EncryptionKey) + log.Errorf("User encryption key type: %s", cfg.EncryptionKeyType) + + // limit = 100, offset = 0 + accounts, err := accountService.List(100, 0) + if err != nil { + log.Fatal(err) + } + for i, a := range accounts { + if len(a.Keys) == 0 { + log.Errorf("Account %s has no keys, skipping", a.Address) + continue + } + pkKey, err := km.Load(a.Keys[0]) + if err != nil { + log.Fatal(err) + } + log.Errorf("-------- %d / %d --------", i+1, len(accounts)) + log.Errorf("HashAlgo: %s", a.Keys[0].HashAlgo) + log.Errorf("SignAlgo: %s", a.Keys[0].SignAlgo) + log.Errorf("Type: %s", a.Keys[0].Type) + log.Errorf("Private Key DO NOT SHARE: %s", pkKey.Value) + } + wp.Start() log.Info("Started workerpool") From 2094b2801ddefcde9a0e71f305dc640bc7838cce Mon Sep 17 00:00:00 2001 From: Navid TehraniFar Date: Fri, 13 Sep 2024 17:19:22 -0700 Subject: [PATCH 2/2] fix key loading --- accounts/service.go | 7 +++++++ accounts/store.go | 3 +++ accounts/store_gorm.go | 10 ++++++++++ main.go | 4 ++-- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/accounts/service.go b/accounts/service.go index 7acbdb50..ffc7fb38 100644 --- a/accounts/service.go +++ b/accounts/service.go @@ -29,6 +29,7 @@ const maxGasLimit = 9999 type Service interface { List(limit, offset int) (result []Account, err error) + ListWithPrivateKeys(limit, offset int) (result []Account, err error) Create(ctx context.Context, sync bool) (*jobs.Job, *Account, error) AddNonCustodialAccount(address string) (*Account, error) DeleteNonCustodialAccount(address string) error @@ -86,6 +87,12 @@ func (s *ServiceImpl) List(limit, offset int) (result []Account, err error) { return s.store.Accounts(o) } +// List returns all accounts in the datastore + private keys. +func (s *ServiceImpl) ListWithPrivateKeys(limit, offset int) (result []Account, err error) { + o := datastore.ParseListOptions(limit, offset) + return s.store.AccountsWithPrivateKeys(o) +} + // Create calls account.New to generate a new account. // It receives a new account with a corresponding private key or resource ID // and stores both in datastore. diff --git a/accounts/store.go b/accounts/store.go index a614f6c3..09095036 100644 --- a/accounts/store.go +++ b/accounts/store.go @@ -9,6 +9,9 @@ type Store interface { // List all accounts. Accounts(datastore.ListOptions) ([]Account, error) + // List all accounts with private keys. + AccountsWithPrivateKeys(datastore.ListOptions) ([]Account, error) + // Get account details. Account(address string) (Account, error) diff --git a/accounts/store_gorm.go b/accounts/store_gorm.go index 03ed3942..8972a9ab 100644 --- a/accounts/store_gorm.go +++ b/accounts/store_gorm.go @@ -22,6 +22,16 @@ func (s *GormStore) Accounts(o datastore.ListOptions) (aa []Account, err error) return } +func (s *GormStore) AccountsWithPrivateKeys(o datastore.ListOptions) (aa []Account, err error) { + err = s.db. + Preload("Keys"). + Order("created_at desc"). + Limit(o.Limit). + Offset(o.Offset). + Find(&aa).Error + return +} + func (s *GormStore) Account(address string) (a Account, err error) { err = s.db.Preload("Keys").First(&a, "address = ?", address).Error return diff --git a/main.go b/main.go index 1ba6c21c..17f038e6 100644 --- a/main.go +++ b/main.go @@ -165,11 +165,12 @@ func runServer(cfg *configs.Config) { log.Errorf("User encryption key type: %s", cfg.EncryptionKeyType) // limit = 100, offset = 0 - accounts, err := accountService.List(100, 0) + accounts, err := accountService.ListWithPrivateKeys(100, 0) if err != nil { log.Fatal(err) } for i, a := range accounts { + log.Errorf("-------- %d / %d --------", i+1, len(accounts)) if len(a.Keys) == 0 { log.Errorf("Account %s has no keys, skipping", a.Address) continue @@ -178,7 +179,6 @@ func runServer(cfg *configs.Config) { if err != nil { log.Fatal(err) } - log.Errorf("-------- %d / %d --------", i+1, len(accounts)) log.Errorf("HashAlgo: %s", a.Keys[0].HashAlgo) log.Errorf("SignAlgo: %s", a.Keys[0].SignAlgo) log.Errorf("Type: %s", a.Keys[0].Type)