How to sign an arbitrary message (arbitrary sequence of bytes) using the MultiversX SDK for JavaScript / TypeScript?
Then, how to verify the signature?
How to sign an arbitrary message (arbitrary sequence of bytes) using the MultiversX SDK for JavaScript / TypeScript?
Then, how to verify the signature?
The code below is relying on the libraries
@multiversx/sdk-wallet
(v4) and@multiversx/sdk-core
(v12).Signing the message:
The example above uses Alice's test wallet (generally used for examples on MultiversX). The address (public key) of this wallet is
erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th
.Verifying the message signature:
Extra notes and references:
serializeForSigning
andserializedMessage
in the example above) is obtained as follows:keccak256(SPECIAL_PREFIX_BYTES concat MESSAGE_LENGTH_AS_STRING_BYTES concat MESSAGE_BYTES)
.