status-go/protocol/requests/restore_account.go
Igor Sirotin 49eaabaca5
feat: adapt create/restore/login endpoints for keycard usage (#5311)
* chore_: remove duplicated `StartNodeWithKey`

* feat(KeycardPairing)_: added GetPairings method

* chore_: simplify startNode... methods

* chore_: added encryption path to be derived

* fix_: error handling in StartNodeWithKey

* feat_: added keycard properties to CreateAccount

* feat_: moved KeycardWhisperPrivateKey to LoginAccount

* fix_: LoginAccount during local pairing

* feat_: added chat key handling to loginAccount

* chore_: struct response from generateOrImportAccount

* fix_: do not store keycard account to keystore

* feat_: added Mnemonic parameter to LoginAccount

* chore_: wrap loginAccount errors

* feat_: RestoreKeycardAccountAndLogin endpoint

* chore_: merge RestoreKeycardAccountRequest into RestoreAccountRequest

* fix_: TestRestoreKeycardAccountAndLogin

* fix_: MessengerRawMessageResendTest

* chore_: cleanup

* chore_: cleanup according to pr comments

* chore_: better doc for Login.Mnemonic

* chore_: add/fix comments

* fix_: lint
2024-06-26 13:14:27 +02:00

50 lines
1.4 KiB
Go

package requests
import (
"errors"
)
var (
ErrRestoreAccountInvalidMnemonic = errors.New("restore-account: no mnemonic or keycard is set")
ErrRestoreAccountMnemonicAndKeycard = errors.New("restore-account: both mnemonic and keycard info are set")
)
type RestoreAccount struct {
Mnemonic string `json:"mnemonic"`
// Keycard info can be set instead of Mnemonic.
// This is to log in using a keycard with existing account.
Keycard *KeycardData `json:"keycard"`
FetchBackup bool `json:"fetchBackup"`
CreateAccount
}
func (c *RestoreAccount) Validate() error {
if len(c.Mnemonic) == 0 && c.Keycard == nil {
return ErrRestoreAccountInvalidMnemonic
}
if len(c.Mnemonic) > 0 && c.Keycard != nil {
return ErrRestoreAccountMnemonicAndKeycard
}
return c.CreateAccount.Validate(&CreateAccountValidation{
AllowEmptyDisplayName: true,
})
}
type KeycardData struct {
KeyUID string `json:"keyUID"`
Address string `json:"address"`
WhisperPrivateKey string `json:"whisperPrivateKey"`
WhisperPublicKey string `json:"whisperPublicKey"`
WhisperAddress string `json:"whisperAddress"`
WalletPublicKey string `json:"walletPublicKey"`
WalletAddress string `json:"walletAddress"`
WalletRootAddress string `json:"walletRootAddress"`
Eip1581Address string `json:"eip1581Address"`
EncryptionPublicKey string `json:"encryptionPublicKey"`
}