Approve msg
After connecting to UKey Wallet, an application can ask the user to sign a message. Message signatures do not incur on-chain fees and are often used for login authentication, proving address ownership or confirming off-chain operations.
Before initiating a signature, the application needs to prepare message content that is clear, readable, and will not be reused:
- Encode a hex or UTF-8 string to
Uint8Array. - Call UKey Wallet Provider to request user confirmation and signature.
- Verify the public key corresponding to the signature on the server or application side.
Use signMessage method
const provider = getProvider();
const message = `To prevent digital asset theft, sign below to authenticate with CryptoCorgis`;
const encodedMessage = new TextEncoder().encode(message);
const signedMessage = await provider.signMessage(encodedMessage, "utf8");
Use request
const provider = getProvider();
const message = `To prevent digital asset theft, sign below to authenticate with CryptoCorgis`;
const encodedMessage = new TextEncoder().encode(message);
const signedMessage = await provider.request({
method: "signMessage",
requestParams: {
message: encodedMessage,
display: "hex",
},
});
Sign off-chain messages
This method is used to sign versioned off-chain messages and is suitable for identity verification or off-chain proof scenarios:
Use the solSignOffchainMessage method
const provider = getProvider();
const message = "Sign this message to verify your identity";
const signedMessage = await provider.request({
method: "solSignOffchainMessage",
requestParams: {
message: message,
version: 0, // Version marker when needed
},
});
console.log({
signature: signedMessage.signature,
publicKey: signedMessage.publicKey,
});