parse export key response
This commit is contained in:
parent
c8058144ce
commit
c32310e39b
|
@ -229,7 +229,7 @@ func (cs *CommandSet) DeriveKey(path string) error {
|
|||
return cs.checkOK(resp, err)
|
||||
}
|
||||
|
||||
func (cs *CommandSet) ExportKey(derive bool, makeCurrent bool, onlyPublic bool, path string) ([]byte, error) {
|
||||
func (cs *CommandSet) ExportKey(derive bool, makeCurrent bool, onlyPublic bool, path string) ([]byte, []byte, error) {
|
||||
var p1 uint8
|
||||
if derive == false {
|
||||
p1 = P1ExportKeyCurrent
|
||||
|
@ -244,18 +244,19 @@ func (cs *CommandSet) ExportKey(derive bool, makeCurrent bool, onlyPublic bool,
|
|||
} else {
|
||||
p2 = P2ExportKeyPrivateAndPublic
|
||||
}
|
||||
|
||||
cmd, err := NewCommandExportKey(p1, p2, path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
resp, err := cs.sc.Send(cmd)
|
||||
err = cs.checkOK(resp, err)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
return resp.Data, nil
|
||||
|
||||
return types.ParseExportKeyResponse(resp.Data)
|
||||
}
|
||||
|
||||
func (cs *CommandSet) SetPinlessPath(path string) error {
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
ethcrypto "github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/status-im/keycard-go/apdu"
|
||||
)
|
||||
|
||||
var (
|
||||
TagExportKeyTemplate = uint8(0xA1)
|
||||
TagExportKeyPublic = uint8(0x81)
|
||||
)
|
||||
|
||||
func ParseExportKeyResponse(data []byte) ([]byte, []byte, error) {
|
||||
tpl, err := apdu.FindTag(data, apdu.Tag{0xA1})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
privKey, err := apdu.FindTag(tpl, apdu.Tag{0x81})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
ecdsaKey, err := ethcrypto.HexToECDSA(fmt.Sprintf("%x", privKey))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return privKey, ethcrypto.FromECDSAPub(&ecdsaKey.PublicKey), nil
|
||||
}
|
Loading…
Reference in New Issue