phantom / docs

32 stars 17 forks source link

Verify the signed message #4

Closed tuphan-dn closed 3 years ago

tuphan-dn commented 3 years ago

Could you add the documentation for the signed message verification? I really appreciate it if you can mention which algorithm you're using to sign/verify the message. By default, I thought you guys are using nacl.sign as Solana Web3, but it seems not.

fragosti commented 3 years ago
const signAndVerifyMessage = async (message: string) => {
  const data = new TextEncoder().encode(message);
  const res = await provider.signMessage(data);
  const { signature, publicKey } = res;
  const verificationResult = nacl.sign.detached.verify(
    data,
    signature,
    publicKey.toBuffer()
  );
  console.log(verificationResult ? 'Signature verified' : 'Signature verification failed');
};