exportKey always parse both pub and priv keys
This commit is contained in:
parent
557c4c58b3
commit
b3978ba458
|
@ -18,15 +18,27 @@ func ParseExportKeyResponse(data []byte) ([]byte, []byte, error) {
|
|||
return nil, nil, err
|
||||
}
|
||||
|
||||
privKey, err := apdu.FindTag(tpl, apdu.Tag{0x81})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
pubKey := tryFindTag(tpl, apdu.Tag{0x80})
|
||||
privKey := tryFindTag(tpl, apdu.Tag{0x81})
|
||||
|
||||
if len(pubKey) == 0 && len(privKey) > 0 {
|
||||
ecdsaKey, err := ethcrypto.HexToECDSA(fmt.Sprintf("%x", privKey))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
pubKey = ethcrypto.FromECDSAPub(&ecdsaKey.PublicKey)
|
||||
}
|
||||
|
||||
ecdsaKey, err := ethcrypto.HexToECDSA(fmt.Sprintf("%x", privKey))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return privKey, ethcrypto.FromECDSAPub(&ecdsaKey.PublicKey), nil
|
||||
return privKey, pubKey, nil
|
||||
}
|
||||
|
||||
func tryFindTag(tpl []byte, tags ...apdu.Tag) []byte {
|
||||
data, err := apdu.FindTag(tpl, tags...)
|
||||
if err != nil {
|
||||
fmt.Printf("returning nil %+v\n", tags)
|
||||
return nil
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue