Sign message
Use signMessage() to request a signature from the connected Canton wallet. The method expects the
message as a base64 string and returns the result through a callback.
To view the sign message flow, visit our source code.
Source code: https://github.com/nightly-labs/canton-web3-template/blob/main/app/components/StickyHeader.tsx
Types
export type SignRequestResponse =
| { type: 'sign_request_approved'; data: { /** Base64-encoded signature */ signature?: string } }
| { type: 'sign_request_rejected'; data: { reason: string } }
| { type: 'sign_request_error'; data: { error: string } }
export type SignMessage = (
message: string,
onResponse: (response: SignRequestResponse) => void
) => void
import adapter, { SignRequestResponseType } from '../misc/adapter'
import type { SignRequestResponse } from '../misc/adapter'
const message: string = Buffer.from('I love Nightly', 'utf-8').toString('base64')
const onResponse = (response: SignRequestResponse): void => {
if (response.type === SignRequestResponseType.SIGN_REQUEST_APPROVED) {
const data = response.data
console.log('Signature:', data.signature)
} else if (response.type === SignRequestResponseType.SIGN_REQUEST_REJECTED) {
const data = response.data
console.log('Rejected:', data.reason)
} else {
const data = response.data
console.log('Error:', data.error)
}
}
adapter.signMessage(message, onResponse)
info
signMessage() is callback-based and the response can be one of:
SIGN_REQUEST_APPROVED
SIGN_REQUEST_REJECTED
SIGN_REQUEST_ERROR
If you want to verify the signature, the template uses tweetnacl to verify the base64 payload with
the wallet public key.