Overview
Raw signing allows you to sign arbitrary data with your MPC wallet, giving you full control over the message format and hashing process. This is useful for custom signing scenarios, non-standard message formats, or when you need to implement chain-specific signing requirements. Note that raw signing is currently only available for EVM chains.
Connector Types
Dynamic provides different connectors depending on the signing algorithm you need:
EVM Connector (ECDSA Signing)
Use the EVM connector for ECDSA-based signing, which is used by Ethereum, Bitcoin, and most other blockchains:
import { DynamicWaasEVMConnector } from '@dynamic-labs/sdk-react-core';
const connector = primaryWallet.connector as DynamicWaasEVMConnector;
Basic Raw Signing
Hereโs how to sign a raw message using Dynamicโs MPC wallets with the EVM connector:
import { keccak256, stringToHex } from 'viem';
import { DynamicWaasEVMConnector } from '@dynamic-labs/sdk-react-core';
const rawMessage = "Hello World";
const connector = primaryWallet.connector as DynamicWaasEVMConnector;
const hash = keccak256(stringToHex(rawMessage)).slice(2);
const signature = await connector.signRawMessage({
accountAddress: primaryWallet.address,
message: hash,
});
console.log("Signature:", signature);
Encoding Options
Dynamic supports different encoding formats for your raw messages:
Hexadecimal Encoding
Most common for blockchain applications. The message is encoded as a hex string.
import { stringToHex } from 'viem';
const message = "Hello World";
const hexEncoded = stringToHex(message);
// Result: "0x48656c6c6f20576f726c64"
UTF-8 Text Encoding
For plain text messages that donโt require hex encoding.
const message = "Hello World";
// Use directly as string
Hash Functions
Different hash functions serve different purposes in cryptographic signing:
Keccak256 (Ethereum Standard)
Most commonly used for Ethereum and EVM-compatible chains:
import { keccak256, stringToHex } from 'viem';
const message = "Hello World";
const hash = keccak256(stringToHex(message));
Standard cryptographic hash function:
import { createHash } from 'crypto';
const message = "Hello World";
const hash = createHash('sha256').update(message).digest('hex');
Advanced Examples
For chains with specific message formatting requirements:
// Example: Custom prefix for a specific blockchain
const customPrefix = "\x19MyChain Signed Message:\n";
const message = "Hello World";
const formattedMessage = customPrefix + message.length + message;
const hash = keccak256(stringToHex(formattedMessage)).slice(2);
const signature = await connector.signRawMessage({
accountAddress: primaryWallet.address,
message: hash,
});
Binary Data Signing
For signing binary data or structured payloads:
// Example: Signing a binary payload
const binaryData = new Uint8Array([0x01, 0x02, 0x03, 0x04]);
const hexData = Array.from(binaryData)
.map(b => b.toString(16).padStart(2, '0'))
.join('');
const signature = await connector.signRawMessage({
accountAddress: primaryWallet.address,
message: hexData,
});