add login flow

This commit is contained in:
Michele Balistreri 2021-10-21 09:31:54 +03:00
parent f284636027
commit 22e2f8a743
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
2 changed files with 28 additions and 17 deletions

View File

@ -92,5 +92,6 @@ func main() {
testFlow(skg.GetAppInfo, skg.FlowParams{}) testFlow(skg.GetAppInfo, skg.FlowParams{})
testFlow(skg.RecoverAccount, skg.FlowParams{skg.PIN: "234567"}) testFlow(skg.RecoverAccount, skg.FlowParams{skg.PIN: "234567"})
testFlow(skg.Login, skg.FlowParams{})
testFlow(skg.UnpairThis, skg.FlowParams{skg.PIN: correctPIN}) testFlow(skg.UnpairThis, skg.FlowParams{skg.PIN: correctPIN})
} }

16
flow.go
View File

@ -216,7 +216,9 @@ func (f *KeycardFlow) connectedFlow() (FlowStatus, error) {
case GetAppInfo: case GetAppInfo:
return f.getAppInfoFlow(kc) return f.getAppInfoFlow(kc)
case RecoverAccount: case RecoverAccount:
return f.recoverAccountFlow(kc) return f.exportKeysFlow(kc, true)
case Login:
return f.exportKeysFlow(kc, false)
case UnpairThis: case UnpairThis:
return f.unpairThisFlow(kc) return f.unpairThisFlow(kc)
default: default:
@ -228,7 +230,7 @@ func (f *KeycardFlow) getAppInfoFlow(kc *keycardContext) (FlowStatus, error) {
return FlowStatus{ErrorKey: ErrorOK, AppInfo: toAppInfo(kc.cmdSet.ApplicationInfo)}, nil return FlowStatus{ErrorKey: ErrorOK, AppInfo: toAppInfo(kc.cmdSet.ApplicationInfo)}, nil
} }
func (f *KeycardFlow) recoverAccountFlow(kc *keycardContext) (FlowStatus, error) { func (f *KeycardFlow) exportKeysFlow(kc *keycardContext, recover bool) (FlowStatus, error) {
err := f.requireKeys() err := f.requireKeys()
if err != nil { if err != nil {
@ -241,7 +243,7 @@ func (f *KeycardFlow) recoverAccountFlow(kc *keycardContext) (FlowStatus, error)
return nil, err return nil, err
} }
result := FlowStatus{} result := FlowStatus{KeyUID: f.cardInfo.keyUID}
key, err := f.exportKey(kc, encryptionPath, false) key, err := f.exportKey(kc, encryptionPath, false)
if err != nil { if err != nil {
@ -255,6 +257,13 @@ func (f *KeycardFlow) recoverAccountFlow(kc *keycardContext) (FlowStatus, error)
} }
result[WhisperKey] = key result[WhisperKey] = key
if recover {
key, err = f.exportKey(kc, eip1581Path, true)
if err != nil {
return nil, err
}
result[EIP1581Key] = key
key, err = f.exportKey(kc, walletRoothPath, true) key, err = f.exportKey(kc, walletRoothPath, true)
if err != nil { if err != nil {
return nil, err return nil, err
@ -272,6 +281,7 @@ func (f *KeycardFlow) recoverAccountFlow(kc *keycardContext) (FlowStatus, error)
return nil, err return nil, err
} }
result[MasterKey] = key result[MasterKey] = key
}
return result, nil return result, nil
} }