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.RecoverAccount, skg.FlowParams{skg.PIN: "234567"})
testFlow(skg.Login, skg.FlowParams{})
testFlow(skg.UnpairThis, skg.FlowParams{skg.PIN: correctPIN})
}

44
flow.go
View File

@ -216,7 +216,9 @@ func (f *KeycardFlow) connectedFlow() (FlowStatus, error) {
case GetAppInfo:
return f.getAppInfoFlow(kc)
case RecoverAccount:
return f.recoverAccountFlow(kc)
return f.exportKeysFlow(kc, true)
case Login:
return f.exportKeysFlow(kc, false)
case UnpairThis:
return f.unpairThisFlow(kc)
default:
@ -228,7 +230,7 @@ func (f *KeycardFlow) getAppInfoFlow(kc *keycardContext) (FlowStatus, error) {
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()
if err != nil {
@ -241,7 +243,7 @@ func (f *KeycardFlow) recoverAccountFlow(kc *keycardContext) (FlowStatus, error)
return nil, err
}
result := FlowStatus{}
result := FlowStatus{KeyUID: f.cardInfo.keyUID}
key, err := f.exportKey(kc, encryptionPath, false)
if err != nil {
@ -255,23 +257,31 @@ func (f *KeycardFlow) recoverAccountFlow(kc *keycardContext) (FlowStatus, error)
}
result[WhisperKey] = key
key, err = f.exportKey(kc, walletRoothPath, true)
if err != nil {
return nil, err
}
result[WalleRootKey] = key
if recover {
key, err = f.exportKey(kc, eip1581Path, true)
if err != nil {
return nil, err
}
result[EIP1581Key] = key
key, err = f.exportKey(kc, walletPath, true)
if err != nil {
return nil, err
}
result[WalletKey] = key
key, err = f.exportKey(kc, walletRoothPath, true)
if err != nil {
return nil, err
}
result[WalleRootKey] = key
key, err = f.exportKey(kc, masterPath, true)
if err != nil {
return nil, err
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
}
result[MasterKey] = key
return result, nil
}