WDK logoWDK documentation

Sign and Verify Messages

Sign messages and verify signatures with Bitcoin accounts.

This guide explains how to sign messages and verify signatures.

Sign a Message

You can sign a message with the account's private key using account.sign():

Sign Message
const message = 'Hello, Bitcoin!'
const signature = await account.sign(message)
console.log('Signature:', signature)

The signature is returned as a base64-encoded string.

Verify a Signature

You can verify that a signature was produced by the corresponding private key using account.verify():

Verify Signature
const isValid = await account.verify(message, signature)
console.log('Signature valid:', isValid)

You can also verify signatures using a read-only account. Use account.toReadOnlyAccount() to create one from an owned account, then call readOnlyAccount.verify():

Verify with Read-Only Account
const readOnlyAccount = await account.toReadOnlyAccount()
const isValid = await readOnlyAccount.verify('Hello, Bitcoin!', signature)
console.log('Verified with read-only account:', isValid)

Next Steps

Learn how to handle errors and manage resources.

On this page