2

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
}

1 Answer 1

2

So the problem is that I need to form the message in the offchain message format:

- \xffsolana offchain (16 bytes)
- 0 (header version - 1 byte)
- 0 (format - 1 byte)
- len(message) (message length - 2 bytes)
- message body

Then it works fine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.