mirror of
https://github.com/status-im/status-go.git
synced 2025-01-09 14:16:21 +00:00
49eaabaca5
* 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
71 lines
1.3 KiB
Go
71 lines
1.3 KiB
Go
package wallet
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
type KeycardPairings struct {
|
|
pairingsFile string
|
|
}
|
|
|
|
type KeycardPairing struct {
|
|
Key string `json:"key"`
|
|
Index int `json:"index"`
|
|
}
|
|
|
|
func NewKeycardPairings() *KeycardPairings {
|
|
return &KeycardPairings{}
|
|
}
|
|
|
|
func (kp *KeycardPairings) SetKeycardPairingsFile(filePath string) {
|
|
kp.pairingsFile = filePath
|
|
}
|
|
|
|
func (kp *KeycardPairings) GetPairingsJSONFileContent() ([]byte, error) {
|
|
_, err := os.Stat(kp.pairingsFile)
|
|
if os.IsNotExist(err) {
|
|
return []byte{}, nil
|
|
}
|
|
|
|
return ioutil.ReadFile(kp.pairingsFile)
|
|
}
|
|
|
|
func (kp *KeycardPairings) SetPairingsJSONFileContent(content []byte) error {
|
|
if len(content) == 0 {
|
|
// Nothing to write
|
|
return nil
|
|
}
|
|
_, err := os.Stat(kp.pairingsFile)
|
|
if os.IsNotExist(err) {
|
|
dir, _ := filepath.Split(kp.pairingsFile)
|
|
err = os.MkdirAll(dir, 0700)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return ioutil.WriteFile(kp.pairingsFile, content, 0600)
|
|
}
|
|
|
|
func (kp *KeycardPairings) GetPairings() (map[string]KeycardPairing, error) {
|
|
content, err := kp.GetPairingsJSONFileContent()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if len(content) == 0 {
|
|
return nil, os.ErrNotExist
|
|
}
|
|
|
|
pairings := make(map[string]KeycardPairing)
|
|
err = json.Unmarshal(content, &pairings)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return pairings, nil
|
|
}
|