MessageModifyingSigner
so you can easily use it with the kit SDK.
Create a hook for signing messages
- To sign a message, we need the user’s wallet address and the message payload. First, we
establish and authorize an MWA session. Then, we call the
signMessagesmethod to sign the payloads(messages).
services/mwa/useSignMessage.ts
- Add an option to abort the operation : this is a small inspiration from kit to run abortable sign message operations.
services/mwa/useSignMessage.ts
getAbortablePromise utility from @solana/promises to automatically stop the operation when the abort signal is triggered.
Create the Message Signer
We can leverageMessagePartialSigner and MessageModifyingSigner abstractions
from kit to create signers that can sign messages. But to make them compatible with MWA we need to transform input from the signer method,
So let’s use MessageModifyingSigner.
services/mwa/MessageModifyingSigner.ts
useMessageSigner that accepts AuthorizeInput, Address and returns a MessageModifyingSigner instance.
Now we need to transform the messages into the input format required by our useSignMessage hook by extracting the addresses and payloads.
Once this is done we can proceed in executing the sign message operation.
To create abortable operations, we pass the Abort signal in the config parameter of modifyAndSignMessages method. This method will check the
status of the abort signal and execute our sign messages hook.
services/mwa/MessageModifyingSigner.ts
signMessage method from MWA modifies the output structure of the signed messages.
So we need to transform it back to the format expected by the MessageModifyingSigner.