implement recover account

This commit is contained in:
Michele Balistreri 2021-10-21 09:09:20 +03:00
parent e7dd1cc9a3
commit f284636027
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
3 changed files with 56 additions and 3 deletions

50
flow.go
View File

@ -152,6 +152,14 @@ func (f *KeycardFlow) pauseAndRestart(action string, errMsg string) error {
return restartErr() return restartErr()
} }
func (f *KeycardFlow) requireKeys() error {
if f.cardInfo.keyUID != "" {
return nil
}
return f.pauseAndRestart(SwapCard, ErrorNoKeys)
}
func (f *KeycardFlow) closeKeycard(kc *keycardContext) { func (f *KeycardFlow) closeKeycard(kc *keycardContext) {
if kc != nil { if kc != nil {
kc.stop() kc.stop()
@ -221,13 +229,51 @@ func (f *KeycardFlow) getAppInfoFlow(kc *keycardContext) (FlowStatus, error) {
} }
func (f *KeycardFlow) recoverAccountFlow(kc *keycardContext) (FlowStatus, error) { func (f *KeycardFlow) recoverAccountFlow(kc *keycardContext) (FlowStatus, error) {
err := f.openSCAndAuthenticate(kc) err := f.requireKeys()
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, errors.New("not yet implemented") err = f.openSCAndAuthenticate(kc)
if err != nil {
return nil, err
}
result := FlowStatus{}
key, err := f.exportKey(kc, encryptionPath, false)
if err != nil {
return nil, err
}
result[EncKey] = key
key, err = f.exportKey(kc, whisperPath, false)
if err != nil {
return nil, err
}
result[WhisperKey] = key
key, err = f.exportKey(kc, walletRoothPath, true)
if err != nil {
return nil, err
}
result[WalleRootKey] = key
key, err = f.exportKey(kc, walletPath, true)
if err != nil {
return nil, err
}
result[WalletKey] = key
key, err = f.exportKey(kc, masterPath, true)
if err != nil {
return nil, err
}
result[MasterKey] = key
return result, nil
} }
func (f *KeycardFlow) unpairThisFlow(kc *keycardContext) (FlowStatus, error) { func (f *KeycardFlow) unpairThisFlow(kc *keycardContext) (FlowStatus, error) {

View File

@ -51,6 +51,7 @@ const (
ErrorConnection = "connection-error" ErrorConnection = "connection-error"
ErrorUnknownFlow = "unknown-flow" ErrorUnknownFlow = "unknown-flow"
ErrorNotAKeycard = "not-a-keycard" ErrorNotAKeycard = "not-a-keycard"
ErrorNoKeys = "no-keys"
) )
const ( const (
@ -63,6 +64,12 @@ const (
PUKRetries = "puk-retries" PUKRetries = "puk-retries"
PairingPass = "pairing-pass" PairingPass = "pairing-pass"
PIN = "pin" PIN = "pin"
MasterKey = "master-key"
WalleRootKey = "wallet-root-key"
WalletKey = "wallet-key"
EIP1581Key = "eip1581-key"
WhisperKey = "whisper-key"
EncKey = "encryption-key"
) )
const ( const (

View File

@ -112,5 +112,5 @@ type ApplicationStatus struct {
type KeyPair struct { type KeyPair struct {
Address string `json:"address"` Address string `json:"address"`
PublicKey hexString `json:"publicKey"` PublicKey hexString `json:"publicKey"`
PrivateKey hexString `json:"privateKey"` PrivateKey hexString `json:"privateKey,omitempty"`
} }