Sign Message/Verify Signature

Usage of the sign/verify flow

As of 30/Aug the verifySignature method is only supported by the legacy pem-file method

When using the main methods for generating transactions, the user signs them with their private key automatically upon sending them. However any message can be signed with the private key and the signature can be verified using the public key and comparing, which can be useful for authentication of contracts of any sort between users.

For KleverChain regular accounts, the public key is the address of the account.

Usage example:

import { core } from '@klever/sdk';

const message = 'hello world';

// sign the message "hello world"
const { signature } = await core.signMessage(
        message,
        privateKey,
      );
//signature is a cipher not decryptable with just the message content, but verifiable

//"valid" is a boolean, which is the return of the verifySignature promise
const { valid } = await core.verifySignature(
        message,
        signature,
        walletAddress,
      );
      
console.log(valid);
// should log true if the message/signature and privateKey/walletAddress
// combinations are compatible

Last updated