Once an application is connected to Martian wallet via connect method, it can also request that the user signs a given message using given api. Applications are free to write their own messages which will be displayed to users from within Martian's signature prompt. Message signatures do not involve network fees and are a convenient way for apps to verify ownership of an address. It takes one parameter listed below:
{
address?: boolean; // Should we include the address of the account in the message
application?: boolean; // Should we include the domain of the dapp
chainId?: boolean; // Should we include the current chain id the wallet is connected to
message: string; // The message to be signed and displayed to the user
nonce: string; // A nonce the dapp should generate,
}
{
message: string || Uint8Array; // The message to be signed and displayed to the user
}
For more information on how to verify the signature of a message, please refer to tweetnacl-js.
Below is an example code describing the way to sign a message.
constmetadata= { address:true, application:true, chainId:true, message:"This is a sample message", nonce:12345,};constsignature=awaitwindow.martian.signMessage(metadata);console.log(signature)// {// "address": "0x34c1e7efa0808b7b0113d71b722f483585e4c4b47ba2b0e703b090937f0c63a1",// "application": "main.d3c4qcdwu8dzdc.amplifyapp.com",// "chainId": 25,// "message": "This is a sample message",// "nonce": 12345,// "fullMessage": "APTOS\naddress: 0x34c1e7efa0808b7b0113d71b722f483585e4c4b47ba2b0e703b090937f0c63a1\napplication: main.d3c4qcdwu8dzdc.amplifyapp.com\nchainId: 25\nmessage: This is a sample message\nnonce: 12345",// "prefix": "APTOS",// "signature": "0x6f9ee0929285b83d385b93ac615784964269e64d756c9538d5fd8c999d9c5b4d3085c363cd034ecd537ea9e522ea0a2a8c7ab898b79b0eb4d7b3cb853291f801"// }