> ## Documentation Index
> Fetch the complete documentation index at: https://dynamic-docs-feat-sidebar-revamp.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Raw Signing

## 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:

```typescript
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:

```typescript
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.

```typescript
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.

```typescript
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:

```typescript
import { keccak256, stringToHex } from 'viem';

const message = "Hello World";
const hash = keccak256(stringToHex(message));
```

### SHA256

Standard cryptographic hash function:

```typescript
import { createHash } from 'crypto';

const message = "Hello World";
const hash = createHash('sha256').update(message).digest('hex');
```

## Advanced Examples

### Custom Message Formatting

For chains with specific message formatting requirements:

```typescript
// 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:

```typescript
// 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,
});
```
