mirror of
https://github.com/status-im/status-keycard-go.git
synced 2025-01-31 00:28:40 +00:00
add export key
This commit is contained in:
parent
27bf041c5e
commit
e7dd1cc9a3
6
flow.go
6
flow.go
@ -237,11 +237,9 @@ func (f *KeycardFlow) unpairThisFlow(kc *keycardContext) (FlowStatus, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = kc.unpairCurrent()
|
||||
err = f.unpairCurrent(kc)
|
||||
|
||||
if isSCardError(err) {
|
||||
return nil, restartErr()
|
||||
} else if err != nil {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -155,3 +155,23 @@ func (f *KeycardFlow) openSCAndAuthenticate(kc *keycardContext) error {
|
||||
|
||||
return f.authenticate(kc)
|
||||
}
|
||||
|
||||
func (f *KeycardFlow) unpairCurrent(kc *keycardContext) error {
|
||||
err := kc.unpairCurrent()
|
||||
|
||||
if isSCardError(err) {
|
||||
return restartErr()
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (f *KeycardFlow) exportKey(kc *keycardContext, path string, onlyPublic bool) (*KeyPair, error) {
|
||||
keyPair, err := kc.exportKey(true, false, onlyPublic, path)
|
||||
|
||||
if isSCardError(err) {
|
||||
return nil, restartErr()
|
||||
}
|
||||
|
||||
return keyPair, err
|
||||
}
|
||||
|
@ -70,3 +70,12 @@ const (
|
||||
maxPUKRetries = 5
|
||||
maxFreeSlots = 5
|
||||
)
|
||||
|
||||
const (
|
||||
masterPath = "m"
|
||||
walletRoothPath = "m/44'/60'/0'/0"
|
||||
walletPath = walletRoothPath + "/0"
|
||||
eip1581Path = "m/43'/60'/1581'"
|
||||
whisperPath = eip1581Path + "/0'/0"
|
||||
encryptionPath = eip1581Path + "/1'/0"
|
||||
)
|
||||
|
@ -289,29 +289,29 @@ func (kc *keycardContext) signWithPath(data []byte, path string) (*types.Signatu
|
||||
return sig, nil
|
||||
}
|
||||
|
||||
func (kc *keycardContext) exportKey(derive bool, makeCurrent bool, onlyPublic bool, path string) ([]byte, []byte, string, error) {
|
||||
func (kc *keycardContext) exportKey(derive bool, makeCurrent bool, onlyPublic bool, path string) (*KeyPair, error) {
|
||||
<-kc.connected
|
||||
if kc.runErr != nil {
|
||||
return nil, nil, "", kc.runErr
|
||||
return nil, kc.runErr
|
||||
}
|
||||
|
||||
address := ""
|
||||
privKey, pubKey, err := kc.cmdSet.ExportKey(derive, makeCurrent, onlyPublic, path)
|
||||
if err != nil {
|
||||
l("exportKey failed %+v", err)
|
||||
return nil, nil, "", err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if pubKey != nil {
|
||||
ecdsaPubKey, err := crypto.UnmarshalPubkey(pubKey)
|
||||
if err != nil {
|
||||
return nil, nil, "", err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
address = crypto.PubkeyToAddress(*ecdsaPubKey).Hex()
|
||||
}
|
||||
|
||||
return privKey, pubKey, address, nil
|
||||
return &KeyPair{Address: address, PublicKey: pubKey, PrivateKey: privKey}, nil
|
||||
}
|
||||
|
||||
func (kc *keycardContext) loadSeed(seed []byte) ([]byte, error) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user