Skip to main content

Try it Live

Run SIWE examples in the interactive playground

Signing

EIP-191 message hash generation for SIWE messages.

getMessageHash

Get EIP-191 personal sign message hash for signing.

Signature

Parameters

  • message - BrandedMessage to hash

Returns

32-byte Keccak-256 hash with EIP-191 prefix

EIP-191 Format

Prefix: \x19Ethereum Signed Message:\n{length} Message: EIP-4361 formatted message Hash: Keccak-256 of concatenated bytes

Example

Process

  1. Format Message: Convert message to EIP-4361 string
  2. Encode to Bytes: UTF-8 encode message text
  3. Build Prefix: Create EIP-191 prefix
  4. Concatenate: Combine prefix + message
  5. Hash: Keccak-256 hash

Usage Patterns

Client-Side Signing

Wallets apply EIP-191 prefix automatically. Do not hash before sending to wallet.

Server-Side Verification

Manual Signing (Testing)

Instance Method

EIP-191 Specification

EIP-191 defines three types of signed data. SIWE uses personal sign format:
Version byte: 0x19 (25 decimal) Identifier: "Ethereum Signed Message:\n" Length: ASCII decimal length of message Message: Raw message bytes (UTF-8 encoded)

Common Mistakes

Don’t Double-Hash

Use Correct Encoding

Length as String

Security Considerations

  • Prefix prevents signature reuse: EIP-191 prefix ensures message can’t be interpreted as transaction
  • Length prevents manipulation: Including length prevents message truncation attacks
  • UTF-8 encoding: Ensures consistent byte representation across platforms
  • Keccak-256: Same hash function as Ethereum transactions
  • Deterministic: Same message always produces same hash

Performance

  • Formatting: O(n) where n = message size
  • Encoding: O(n) UTF-8 encoding
  • Hashing: O(n) Keccak-256 hash
  • Total: Linear in message size, typically less than 1ms

See Also