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.
The operation result is returned in the callback object passed to the signMessage
function or the Promise
object returned by the signMessage
function.
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.
sdk.signMessage(
// message
"Hello World",
// signing reason
"reason",
// Callback
Callback(
onSuccess = { response: JsonResponse ->
Log.d("onSuccess", response.toString())
},
onFailure = { error: JsonResponse ->
Log.d("onFailure", error.toString())
},
),
)
sdk.signMessage(
// message
message: "Hello World",
// signing reason
reason: "reason",
// Callback
callback: Callback(
onSuccess: { (result: JsonResponse) in
print("onSuccess")
print(result.description)
},
onFailure: { (error: JsonResponse) in
print("onFailure")
print(error.description)
}
)
)
await sdk.signMessage(
// message
"Hello World",
// signing reason
"reason",
);
await sdk.signMessage(
// message
"Hello World",
// signing reason
"reason",
);
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
On success, the callback onSuccess
or the Promise resolve
function is called with the signed message data as a JsonResponse
object. This is what the data looks like:
{
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
Callback onFailure
or the Promise reject
function is called when the user cancels the operation or if there's an error. The error object contains a status field which is a string indicating the status of the operation. Here's what the error object looks like:
{
status: "USER_CONSENT_DENIED"
}
Here's a table of all possible error status returned by the SDK
Status | Description |
---|---|
USER_REQUEST_DENIED | The user has denied the sign operation. In this case, you should ask the user if they want to try again. |
INVALID_REQUEST | Invalid data passed to sign operation. Please get in touch with us if you are unable to fix this. |
APP_ID_REQUIRED | No app id was provided when initializing the SDK. You can find the app ID in the MetaKeep Developer Console. |
APP_NOT_FOUND | The provided app id is invalid. You can find the correct app id in the MetaKeep Developer Console. |
SOMETHING_WENT_WRONG | An unknown error happened. Please get in touch with us if you continue seeing this error. |
Ā© Copyright 2024, Passbird Research Inc.