mirror of
https://github.com/status-im/status-keycard-go.git
synced 2025-01-18 18:31:56 +00:00
exportKey return the address too
This commit is contained in:
parent
e494db0f35
commit
fafb1a2f56
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ebfe/scard"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
keycard "github.com/status-im/keycard-go"
|
||||
"github.com/status-im/keycard-go/apdu"
|
||||
"github.com/status-im/keycard-go/globalplatform"
|
||||
@ -273,19 +274,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, error) {
|
||||
func (kc *keycardContext) exportKey(derive bool, makeCurrent bool, onlyPublic bool, path string) ([]byte, []byte, string, error) {
|
||||
<-kc.connected
|
||||
if kc.runErr != nil {
|
||||
return nil, nil, kc.runErr
|
||||
return nil, 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, nil, "", err
|
||||
}
|
||||
|
||||
return privKey, pubKey, nil
|
||||
if pubKey != nil {
|
||||
ecdsaPubKey, err := crypto.UnmarshalPubkey(pubKey)
|
||||
if err != nil {
|
||||
return nil, nil, "", err
|
||||
}
|
||||
|
||||
address = crypto.PubkeyToAddress(*ecdsaPubKey).Hex()
|
||||
}
|
||||
|
||||
return privKey, pubKey, address, nil
|
||||
}
|
||||
|
||||
func (kc *keycardContext) loadSeed(seed []byte) ([]byte, error) {
|
||||
|
4
main.go
4
main.go
@ -262,12 +262,12 @@ func ExportKey(jsonParams *C.char) *C.char {
|
||||
return retValue("error", err.Error())
|
||||
}
|
||||
|
||||
privKey, pubKey, err := kctx.exportKey(params.Derive, params.MakeCurrent, params.OnlyPublic, params.Path)
|
||||
privKey, pubKey, address, err := kctx.exportKey(params.Derive, params.MakeCurrent, params.OnlyPublic, params.Path)
|
||||
if err != nil {
|
||||
return retValue("error", err.Error())
|
||||
}
|
||||
|
||||
return retValue("ok", true, "privateKey", hexString(privKey), "publicKey", hexString(pubKey))
|
||||
return retValue("ok", true, "privateKey", hexString(privKey), "publicKey", hexString(pubKey), "address", address)
|
||||
}
|
||||
|
||||
//export LoadSeed
|
||||
|
Loading…
x
Reference in New Issue
Block a user