Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dump keys [DO NOT MERGE OR USE IN PROD] #335

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions accounts/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions accounts/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 10 additions & 0 deletions accounts/store_gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.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
}
pkKey, err := km.Load(a.Keys[0])
if err != nil {
log.Fatal(err)
}
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")

Expand Down
Loading