feat_: add KeycardPairingKey for mobile (#6101)

This commit is contained in:
flexsurfer 2024-11-20 12:35:20 +01:00 committed by GitHub
parent 735a422230
commit c2d79e785e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 12 deletions

View File

@ -1713,24 +1713,33 @@ func (b *GethStatusBackend) prepareForKeycard(request *requests.CreateAccount, i
return response, nil
}
kp := wallet.NewKeycardPairings()
kp.SetKeycardPairingsFile(response.nodeConfig.KeycardPairingDataFile)
pairings, err := kp.GetPairings()
if err != nil {
return nil, errors.Wrap(err, "failed to get keycard pairings")
}
if request.KeycardPairingKey != "" {
// KeycardPairingKey is used only on mobile
response.settings.KeycardPairing = request.KeycardPairingKey
response.account.KeycardPairing = request.KeycardPairingKey
} else {
// KeycardPairingDataFile is used only on desktop
kp := wallet.NewKeycardPairings()
kp.SetKeycardPairingsFile(response.nodeConfig.KeycardPairingDataFile)
pairings, err := kp.GetPairings()
if err != nil {
return nil, errors.Wrap(err, "failed to get keycard pairings")
}
keycard, ok := pairings[request.KeycardInstanceUID]
if !ok {
return nil, errors.New("keycard not found in pairings file")
keycard, ok := pairings[request.KeycardInstanceUID]
if !ok {
return nil, errors.New("keycard not found in pairings file")
}
response.settings.KeycardPairing = keycard.Key
response.account.KeycardPairing = keycard.Key
}
response.settings.KeycardInstanceUID = request.KeycardInstanceUID
response.settings.KeycardPairedOn = time.Now().Unix()
response.settings.KeycardPairing = keycard.Key
response.account.KeycardPairing = keycard.Key
privateKeyHex := strings.TrimPrefix(input.derivedAddresses[pathDefaultChat].PrivateKey, "0x")
var err error
response.chatPrivateKey, err = crypto.HexToECDSA(privateKeyHex)
if err != nil {
return nil, errors.Wrap(err, "failed to parse chat private key hex")

View File

@ -79,7 +79,11 @@ type CreateAccount struct {
APIConfig *APIConfig `json:"apiConfig"`
KeycardInstanceUID string `json:"keycardInstanceUID"`
KeycardInstanceUID string `json:"keycardInstanceUID"`
// on mobile there is no KeycardPairingDataFile, so for now KeycardPairingKey will be used
// for recovering account
KeycardPairingKey string `json:"keycardPairingKey"`
KeycardPairingDataFile *string `json:"keycardPairingDataFile"`
StatusProxyEnabled bool `json:"statusProxyEnabled"`
}