# Sign Message SDK

To sign a message a user  / an account would need to have to have been register and authenticated  by going through  [Register using SDK](/authentication/passkeys/registration/register-using-sdk.md) flow.&#x20;

Once you have registered the user, you can choose one of the below 2 flows

## **Session-Based Authentication**

In order to use this flow, you must  [Authenticating with SDK](/authentication/passkeys/authentication/authenticating-with-sdk.md) first to obtain a JWT.  Here is a sample of how to use it

```javascript
import { Passport } from "@0xpass/passport";
import { WebauthnSigner } from "@0xpass/webauthn-signer";
import { stringToHex } from "viem";
import { Passport } from "@0xpass/passport";
import { WebauthnSigner } from "@0xpass/webauthn-signer";

const signer = new WebauthnSigner({
      rpId: window.location.hostname,
      rpName: "rpName",
});

const passport = new Passport({
    scopeId: "insert_your_scope_id",
    signer: signer
});

const userInput {
   username: "insert_registered_username_here"
   userDisplayName: "insert_registered_user_display_name_here"
}

await passport.setupEncryption();
await passport.authenticate(userInput);

// Generate a signature
const signature = await passport.signMessage(stringToHex("hello world!"));
console.log(signature);
```

### signMessage Parameters

| Parameter | Description                    | Example Values                                                |
| --------- | ------------------------------ | ------------------------------------------------------------- |
| `message` | The message you'd like to sign | `68656c6c6f20776f726c64` (hex represenation of "hello world") |

#### signMessage Response

A successful response will return the following, a signature of the signed message by the authenticated account.

```json
{
    "jsonrpc": "2.0",
    "result": "signature_here",
    "id": 1
}
```

## **Direct Passkey Authentication**

Since you will be directly authenticating with Passkeys here, you don't need to go through authentication step. Here is a code sample:

```javascript
import { Passport } from "@0xpass/passport";
import { WebauthnSigner } from "@0xpass/webauthn-signer";
import { stringToHex } from "viem";
import { Passport } from "@0xpass/passport";
import { WebauthnSigner } from "@0xpass/webauthn-signer";

const signer = new WebauthnSigner({
      rpId: window.location.hostname,
      rpName: "rpName",
});

const passport = new Passport({
    scope_id: "insert_your_scope_id",
    signer: signer
    allow_sessions: false
});

const userInput {
   username: "insert_registered_username_here"
   userDisplayName: "insert_registered_user_display_name_here"
}

await passport.setupEncryption();
//This step is different for direct authentication
passport.setUserData(userInput)

// Generate a signature
const signature = await passport.signMessage(stringToHex("hello world!"));
console.log(signature);
```

### signMessage Parameters

| Parameter | Description                    | Example Values                                                |
| --------- | ------------------------------ | ------------------------------------------------------------- |
| `message` | The message you'd like to sign | `68656c6c6f20776f726c64` (hex represenation of "hello world") |

#### signMessage Response

A successful response will return the following, a signature of the signed message by the authenticated account.

```json
{
    "jsonrpc": "2.0",
    "result": "signature_here",
    "id": 1
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.0xpass.io/wallet-operations/passkeys-signer/sign-message/sign-message-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
