I'm trying to verify the offchain message signed by solana cli
in golang. but it doesn't work.
Step i did:
- base58 decode the address to get the public key
- base58 decode the signature to get the signature
- append the message with
\xffsolana offchain
- call ad25519.verify,
Am I missing something?
my code:
const SOLANA_MESSAGE_HEADER = "\xffsolana offchain"
func verifySolana(address, message, signature string) (bool, error) {
publicKeyBytes := base58.Decode(address)
if len(publicKeyBytes) != ed25519.PublicKeySize {
return false, errors.New("invalid public key")
}
signatureBytes := base58.Decode(signature)
messageWithHeader := fmt.Sprintf("%s%s", SOLANA_MESSAGE_HEADER, message)
if len(signatureBytes) != ed25519.SignatureSize {
return false, errors.New("invalid signature")
}
isValid := ed25519.Verify(
publicKeyBytes,
[]byte(messageWithHeader),
signatureBytes,
)
return isValid, nil
}