Skip to main content

Sign message

To sign a message using the previously created adapter, we recommend you use the function signPersonalMessage() from the adapter. But first you need to create a message that conforms with the type mentioned below.

export interface SuiSignPersonalMessageInput {
message: Uint8Array;
account: WalletAccount;
}
info

To create a simple Sui account from public key, use the following function, using the @mysten/sui package.

import { publicKeyFromRawBytes } from "@mysten/sui/verify";

const createSuiWalletAccountFromString = (publicKey: string): WalletAccount => {
const suiPk = publicKeyFromRawBytes("ED25519", bs58.decode(publicKey));
return {
address: suiPk.toSuiAddress(),
publicKey: suiPk.toRawBytes(),
chains: SUI_CHAINS,
features: [
"standard:connect",
"standard:events",
"sui:signTransactionBlock",
"sui:signAndExecuteTransactionBlock",
"sui:signMessage",
],
};
};

Now you can create an account from your public key, and a message payload.

const account = createSuiWalletAccountFromString(YOUR_PUBLIC_KEY);
const messageInput = {
message: new TextEncoder().encode("I love Nightly"),
account: account,
};

Finally you can sign the message.

await adapter.signPersonalMessage(messageInput);