signMessage
Signs a Safe message with the connected signer.
Usage
_16import { SigningMethod } from '@safe-global/protocol-kit'_16import { EIP712TypedData } from '@safe-global/types-kit'_16import { protocolKit } from './setup.ts'_16_16const rawMessage: string | EIP712TypedData = 'Example message'_16const message = protocolKit.createMessage(rawMessage)_16_16const signingMethod = SigningMethod.ETH_SIGN_TYPED_DATA_V4_16_16const preimageSafeAddress = '0x...'_16_16const signedMessage = await protocolKit.signMessage(_16 message,_16 signingMethod, // Optional_16 preimageSafeAddress // Optional_16)
Parameters
message
- Type:
string
The message to be signed.
_10const signedMessage = await protocolKit.signMessage(_10 '0x...'_10)
signingMethod
(Optional)
- Type:
SigningMethodType
(opens in a new tab) - Default:
SigningMethod.ETH_SIGN_TYPED_DATA_V4
The signature type.
You can use multiple signing methods, such as:
ETH_SIGN
(eth_sign
): Regular hash signature.ETH_SIGN_TYPED_DATA_V4
(eth_signTypedData_v4
): Typed data signaturev4
.ETH_SIGN_TYPED_DATA_V3
(eth_signTypedData_v3
): Typed data signaturev3
.ETH_SIGN_TYPED_DATA
(eth_signTypedData
): Typed data signature.SAFE_SIGNATURE
: Signature from another Safe that acts as a signer.
_10const signedMessage = await protocolKit.signMessage(_10 '0x...',_10 SigningMethod.ETH_SIGN_TYPED_DATA_V4_10)
preimageSafeAddress
(Optional)
- Type:
string
The address of the Safe that will be used to calculate the preimage.
Required parameter for v1.3.0
and v1.4.1
Safe smart accounts. These versions use the old EIP-1271 interface, which uses bytes
instead of bytes32
for the message. You need to use the pre-image of the message to calculate the message hash.
_10const signedMessage = await protocolKit.signMessage(_10 '0x...',_10 SigningMethod.ETH_SIGN_TYPED_DATA_V4,_10 '0x...'_10)
Returns
Promise<SafeMessage>
The Safe message with the generated signature.