2023-11-15 15:58:15 +00:00
|
|
|
package common
|
2019-07-26 07:17:29 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/ecdsa"
|
2020-01-02 09:10:19 +00:00
|
|
|
|
2019-11-23 17:57:05 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/crypto"
|
2023-11-15 15:58:15 +00:00
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
2019-07-26 07:17:29 +00:00
|
|
|
)
|
|
|
|
|
2023-11-15 15:58:15 +00:00
|
|
|
func RecoverKey(m *protobuf.ApplicationMetadataMessage) (*ecdsa.PublicKey, error) {
|
2019-07-26 07:17:29 +00:00
|
|
|
if m.Signature == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
recoveredKey, err := crypto.SigToPub(
|
|
|
|
crypto.Keccak256(m.Payload),
|
|
|
|
m.Signature,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return recoveredKey, nil
|
|
|
|
}
|