Skip to main content

Signing a Message

Nightly allows you to Sign Message in easy way. Please provide to the function signMessage() message as string that needs to be signed and await for the result.

import { SuiSignMessageInput } from '@mysten/wallet-standard'

async signMessage(input: SuiSignMessageInput) {
try {
const signature = await this._provider.signMessage(input)
return signature
} catch (error) {
console.log(error)
throw new Error('User refused sign message')
}
}

Verification allows us to make sure, that message was successfully signed. Please refer to the code below as an example. For the verification you need to provide hashed message, signed message and publicKey data in form of Uint8Array.

As a result verification will return boolean, which gives information if the message is correctly signed or not.

import { NightlyWalletAdapter } from 'nightly-sui-template'
const NightlySui = new NightlyWalletAdapter()

const messageToSign = 'I like turtles' // string
const messageBytes = new TextEncoder().encode(messageToSign)

const signedMessage = await NightlySui.signMessage({
message: messageBytes,
account: activeAccount
})