Skip to main content

Sign message

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

export interface IotaSignPersonalMessageInput {
message: Uint8Array;
account: WalletAccount;
}
To create a simple Iota account from public key, use the following function, using the

@iota/iota-sdk package.

import { publicKeyFromRawBytes } from '@iota/iota-sdk/verify'
import type {
WalletAccount,
} from '@iota/wallet-standard'

const createIotaWalletAccountFromString = (publicKey: string): WalletAccount => {
const iotaPk = publicKeyFromRawBytes('ED25519', bs58.decode(publicKey))
return {
address: iotaPk.toIotaAddress(),
publicKey: iotaPk.toRawBytes(),
chains: ['iota:devnet', 'iota:testnet', 'iota:mainnet'],
features: [
'standard:connect',
'standard:events',
'iota:signTransaction',
'iota:signAndExecuteTransaction',
'iota:signPersonalMessage'
]
}
}

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

const account = createIotaWalletAccountFromString(YOUR_PUBLIC_KEY)
const messageInput = {
message: new TextEncoder().encode('I love Nightly'),
account: account
}

Finally you can sign the message.

await adapter.features['iota:signPersonalMessage'].signPersonalMessage(messageInput)