Sign Message

Calling signMessage

You can ask the user to sign a string message by using thesignMessage function in MetaKeep SDK. The function expects a non-empty reason which is shown to the user at the time of message signing.

This function is compliant with the official Ethereum sign API https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign on EVM chains and is also supported on Solana and EOS.

await sdk.signMessage(
    // message
    "Hello World",
    // signing reason
    "reason",
);

Here's a reference implementation of this code:

📘

Signing opaque binary data is not supported.

For security reasons, this API only supports signing human-readable UTF-8 strings. It is not intended for signing opaque binary data since then it can be used to sign an arbitrary hash, which means it can be used to sign transactions, or any other data, making it a dangerous phishing risk.

Use transaction signing for signing transaction data or typed data signing for signing generic data objects.

Response

signMessage returns a promise which succeeds when the sign operation is successful. The response looks like this-

{
  status: "SUCCESS",
  // Signature of the signed message.The signature encodes the r, s and v parameters 
  // from appendix F of the yellow paper in big-endian format. 
  // Bytes 0…32 contain the r parameter, bytes 32…64 the s parameter and the last byte the v parameter.
  signature: "0x1a84678f385553358386051464a252fa25d019335deb20262eb231d4ec1467300e6f1944e872430b7e04af6dd68ece90e2a9995a7abd827b50588602523b525600",
  r: "0x1a84678f385553358386051464a252fa25d019335deb20262eb231d4ec146730",
  s: "0x0e6f1944e872430b7e04af6dd68ece90e2a9995a7abd827b50588602523b5256",
  v: "0x0"
}
{
  "status": "SUCCESS",
  "signature": "0x2cf7781e2c29cbac6a9eaeb8b717f0ddd1f436362d27d97f1d2ca524cd0ec477a753a107dd945e249323f902cd7471141d31f62ea87d9b7432c3151af96c8801"
}
{
  "status": "SUCCESS",
  "signature": "SIG_K1_K1YY3maW1vHjQmmtciiQkkzPaUcpPdCQ631oMqayz4Z3TG9xhjNQwzqL3VCQPV1ZfYTQ14hkoRBkFaUwwrAngLedAxhog6"
}

Error status

signMessage returns a promise which throws an error when the sign operation is unsuccessful. The error object looks like so-

{
  status: "USER_CONSENT_DENIED"
}

Here's a table of all possible error status returned by the SDK

StatusDescription
USER_REQUEST_DENIEDUser has denied the sign operation.
In this case, you should ask the user if they want to try again.
INVALID_REQUESTInvalid data passed to sign operation.
Please get in touch with us if you are unable to fix this.
APP_ID_REQUIREDNo app id provided when initializing the SDK.
You can find the app id in MetaKeep Developer Console.
APP_NOT_FOUNDProvided app id is invalid.
You can find the correct app id in MetaKeep Developer Console.
SOMETHING_WENT_WRONGUnknown error happened.
Please get in touch with us if you continue seeing this error.

© Copyright 2024, Passbird Research Inc.