diff --git a/flow.go b/flow.go index 6a2db4f..ee64543 100644 --- a/flow.go +++ b/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 } diff --git a/flow_commands.go b/flow_commands.go index ec94620..5c63099 100644 --- a/flow_commands.go +++ b/flow_commands.go @@ -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 +} diff --git a/flow_types.go b/flow_types.go index 7e04434..5d2d8ca 100644 --- a/flow_types.go +++ b/flow_types.go @@ -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" +) diff --git a/keycard_context.go b/keycard_context.go index 6abc801..f798234 100644 --- a/keycard_context.go +++ b/keycard_context.go @@ -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) { diff --git a/types.go b/types.go index 708c96a..0ad73ae 100644 --- a/types.go +++ b/types.go @@ -108,3 +108,9 @@ type ApplicationStatus struct { KeyInitialized bool `json:"keyInitialized"` Path string `json:"path"` } + +type KeyPair struct { + Address string `json:"address"` + PublicKey hexString `json:"publicKey"` + PrivateKey hexString `json:"privateKey"` +}