secretkeylabs / sats-connect-example

38 stars 28 forks source link

How can I verify message signatures #5

Closed aximili-dev closed 7 months ago

aximili-dev commented 1 year ago

I have the following code in my frontend, how would I verify that the signature is correct in the backend?

import {
  signMessage,
  SignMessageOptions,
} from "sats-connect";

async signMessage(
  address: string,
  msg: string,
): Promise<string> {
  return new Promise(async (resolve, reject) => {
    const signMessageOptions: SignMessageOptions = {
      payload: {
        message: "foobar",
        address,
        network: {
          type: "Mainnet",
        },
      },
      onFinish: (response) => resolve(response),
      onCancel: () => reject(new Error()),
    };

    await signMessage(signMessageOptions);
  });
}
jakehobbs commented 1 year ago

i'm also trying to figure out the same thing

jakehobbs commented 1 year ago

@aximili-dev I found this library which seems to work perfectly out of the box to verify the signature: https://github.com/ACken2/bip322-js