VerifyMessage in server-side

This scenario mainly explains how the server-side verify the result of the signMessage. Fields verification can also be implemented using mina-signer. Only signMessage examples are provided here.

The features is implemented through mina-signer.

mina-signer is the NodeJS SDK provided by Mina Protocol for sign, verify signatures, etc.

Verify Message

  1. Add mina-signer to package.json.

"dependencies": {
    "mina-signer": "2.1.1"
  1. Import and init mina-signer.

var Client = require("mina-signer");

// type Network = 'mainnet' | 'testnet'
var signerClient = new Client({ network: "mainnet" });

There are two types of initialization supported here. The main network type is mainnet, and the type of other network are testnet. See original definition.

  1. Implement code.

const publicKey = 'B62qj6z7oseWTr37SQTn53mF8ebHn45cmSfRC58Sy52wG6KcaPZNWjw'

const verifyMessage = `Click "Sign" to sign in. No password needed!

  This request will not trigger a blockchain transaction or cost any gas fees.
  I accept the Auro Test zkApp Terms of Service:
  address: B62qj6z7oseWTr37SQTn53mF8ebHn45cmSfRC58Sy52wG6KcaPZNWjw
  iat: 1701069403643`;

const signature = {
    field: '25087624681052481871246375076085075176624243458008290192358519021588472251513',
    scalar: '17285357755862735391605884635523872951699156489623612197745807470058903167470'

const verifyBody = {
    data: verifyMessage, // Signature content that needs to be verified.
    publicKey: publicKey, // Public key that needs to be verified.
    signature: signature, // Signature results that need to be verified.

// When verifyResult is true, the verification is successful.
const verifyResult = signerClient.verifyMessage(verifyBody);

This is an example of server-side verification of signature. You can refer to the implementation or run it locally.

Last updated