Skip to content

How to recoverPubKey from signature and raw message? #4147

Closed Answered by benben2019
benben2019 asked this question in Q&A
Discussion options

You must be logged in to vote

this may be working!

  public func recoverPubKey(signature: EthereumSignature, message: Data) throws -> Data {
        let hashBytes = SHA3(variant: .keccak256).calculate(for: message.bytes)
        let hashData = Data(hashBytes)
        guard let publicKey = SECP256K1.recoverPublicKey(hash: hashData, signature: signature.serialized, compressed: true) else {
            throw "recover publickKey error"
        }
        return publicKey
    }

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@satoshiotomakan
Comment options

Answer selected by benben2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants