You can use MetaKeep to generate signatures for messages using the private key of the asymmetric key pair. The signature can be verified using the public key.
Calling sign
You can ask the user to sign a bigint
by using thesignMessage
function in MetaKeep SDK. The bigint
is converted to a big-endian
byte array and then converted to a hex string
. The hex string is then sent to the signMessage
function along with the reason
. 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.
await sdk.signMessage(
// bigint as big-endian byte hex string
"0x0000260e66bea5cc8114947584de9f68574710c9e472378d4595febfd51eb853",
// signing reason
"reason",
);
sdk.signMessage(
// bigint as big-endian byte hex string
"0x0000260e66bea5cc8114947584de9f68574710c9e472378d4595febfd51eb853",
// signing reason
"reason",
// Callback
Callback(
onSuccess = { response: JsonResponse ->
Log.d("onSuccess", response.toString())
},
onFailure = { error: JsonResponse ->
Log.d("onFailure", error.toString())
},
),
)
sdk.signMessage(
// bigint as big-endian byte hex string
message: "0x0000260e66bea5cc8114947584de9f68574710c9e472378d4595febfd51eb853",
// 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(
// bigint as big-endian byte hex string
"0x0000260e66bea5cc8114947584de9f68574710c9e472378d4595febfd51eb853",
// signing reason
"reason",
);
await sdk.signMessage(
// bigint as big-endian byte hex string
"0x0000260e66bea5cc8114947584de9f68574710c9e472378d4595febfd51eb853",
// signing reason
"reason",
);
Response
On success, the callback onSuccess
or the Promise resolve
function is called with the signature inside a JSON
object. The signature is a 64-byte compressed EdDSA signature
in hex format as defined in RFC 8032.
This is what the response looks like:
{
"status": "SUCCESS",
// 64-byte compressed EdDSA signature in hex format
"signature": "0x20ba78dcc23893aefaa3c8c2c9d99598831265e3ce32638d3cfda6c4d2028c8ade8b897c9d4542259204224ff59b72f7fea835727df8cee40cafd3a6d101ff02"
}
Here's a reference implementation of this code for JS SDK: https://jsfiddle.net/passbird/14er9xoy/
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, 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. |
INVALID_MESSAGE | The message to sign is not valid. Make sure that it's a valid hex string. |
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.