# Sign a message

`signMessage` produces a signature over an arbitrary string using the embedded wallet's key. It implements the EIP-191 [`personal_sign`](https://docs.metamask.io/wallet/reference/personal_sign/) standard — the message is prefixed and hashed before signing, so the result is safe to verify on-chain or off-chain. Use it for login challenges, terms acceptance, or any proof that the user controls the wallet.

:::note
The wallet must be [`.ready`](/docs/products/embedded-wallet/swift/wallet/state) before signing.
:::

## Usage

`signMessage` returns the signature as a `String?` (`OFSignMessageResponse` is a typealias for `String`):

```swift
do {
    let signature = try await OFSDK.shared.signMessage(
        params: OFSignMessageParams(message: "Sign in to My App — nonce: 8f3a")
    )
    print("Signature: \(signature ?? "")")
} catch {
    print("Failed to sign message: \(error.localizedDescription)")
}
```

You can verify the returned signature against the wallet address with any EVM library (for example, `ecrecover` server-side) to confirm the user signed it.

## Options

`OFSignMessageParams.Options` lets you control how the message is processed before signing. The defaults match standard `personal_sign` behavior — only set these if you have a specific need (for example, signing a pre-computed hash):

```swift
let params = OFSignMessageParams(
    message: "0x...",
    options: OFSignMessageParams.Options(
        hashMessage: true,     // hash the message before signing
        arrayifyMessage: true  // treat the message as a byte array, not UTF-8 text
    )
)
```

## Parameters

```swift
public struct OFSignMessageParams: OFCodableSendable {
    public let message: String
    public let options: Options?

    public struct Options: OFCodableSendable {
        public let hashMessage: Bool?
        public let arrayifyMessage: Bool?
    }
}
```

## Returns

```swift
OFSignMessageResponse? // typealias for String? — the signature
```

## Next steps

* [Sign typed data](/docs/products/embedded-wallet/swift/wallet/sign-typed) — for structured EIP-712 payloads.
* [Send a transaction](/docs/products/embedded-wallet/swift/wallet/send)
