> For the complete documentation index, see [llms.txt](https://docs.constellationnetwork.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.constellationnetwork.io/stargazer-wallet/constellation-rpc-api/dag_signdata.md).

# dag\_signData

Creates a request to generate a safe signature of arbitrary data from the selected wallet. This method is intended to be used for interaction with custom data requests to metagraphs and other similar use cases.

This method adds a standard `"\u0019Constellation Signed Data:\n" + len(message) + "\n"` prefix when calculating the signature hash. The addition of the prefix prevents users from being tricked into signing a valid token transaction with this method.

The final string looks like this: `"\u0019Constellation Signed Data:\n" + len(message) + "\n" + message`

{% hint style="info" %}
**Warning**

Please be sure you use the correct prefix for the correct method when verifying signatures, `dag_signData` uses "Constellation Signed Data:" while `dag_signMessage` uses "Constellation Signed Message:"
{% endhint %}

**Parameters**[**​**](https://docs.constellationnetwork.io/stargazer/APIReference/constellationRPCAPI/dag_signData#parameters)

| Name    | Type                                             | Description           |
| ------- | ------------------------------------------------ | --------------------- |
| Account | `Address`                                        | Account to sign from. |
| Request | `Base64<JSONEncoded>` \| `Base64<StringEncoded>` | Signature Request.    |

**Return Type**[**​**](https://docs.constellationnetwork.io/stargazer/APIReference/constellationRPCAPI/dag_signData#return-type)

`HexString` - The prefixed ECDSA signature.

Base64

```typescript
/**
 * A base64 encoded string
 * */
type Base64 = string;
```

JSONEncoded

```typescript
/**
 * A JSON encoded string
 * */
type JSONEncoded = string;
```

StringEncoded

```typescript
/**
 * A String encoded
 * */
type StringEncoded = string;
```

**Example**[**​**](https://docs.constellationnetwork.io/stargazer/APIReference/constellationRPCAPI/dag_signData#example)

```typescript
// Build the signature request
const signatureRequest: any = {
  field1: "content_field_1",
  field2: {
    field2_1: true,
    field2_2: 12332435,
    field2_3: {
      field2_3_1: "content_field2_3_1",
    },
  },
  field3: [1, 2, 3, 4],
  field4: null,
};

// Encode the signature request - Base64 < JSON < Request
const signatureRequestEncoded = window.btoa(JSON.stringify(signatureRequest));

// Encode the string directly if "signatureRequest" is a string:
// const signatureRequest = "This is a custom string.";
//
//                                      Base64 < String
// const signatureRequestEncoded = window.btoa(signatureRequest);

await provider.request({
  method: "dag_signData",
  params: ["DAG88C9WDSKH451sisyEP3hAkgCKn5DN72fuwjfX", signatureRequestEncoded],
});
// "3045022100b35798008516373fcc6eef75fe8e322ce8fe0dccc4802b052f3ddc7c6b5dc2900220154cac1e4f3e7d9a64f4ed9d2a518221b273fe782f037a5842725054f1c62280"
```

**Verify**[**​**](https://docs.constellationnetwork.io/stargazer/APIReference/constellationRPCAPI/dag_signData#verify)

In order to verify the signature you can use the `verifyData()` method from `dag4.js`:

```typescript
// Build the same signature request
const signatureRequest: any = {
  field1: "content_field_1",
  field2: {
    field2_1: true,
    field2_2: 12332435,
    field2_3: {
      field2_3_1: "content_field2_3_1",
    },
  },
  field3: [1, 2, 3, 4],
  field4: null,
};

// get the public key
const publicKey = await provider.request({
  method: "dag_getPublicKey",
  params: [
    "DAG88C9WDSKH451sisyEP3hAkgCKn5DN72fuwjfX", // Your DAG address
  ],
});

// same request used in dag_signData
const signatureRequestEncoded = window.btoa(JSON.stringify(signatureRequest));

// hash returned by dag_signData in the pevious example
const signature =
  "3045022100b35798008516373fcc6eef75fe8e322ce8fe0dccc4802b052f3ddc7c6b5dc2900220154cac1e4f3e7d9a64f4ed9d2a518221b273fe782f037a5842725054f1c62280";

const message = `\u0019Constellation Signed Data:\n${signatureRequestEncoded.length}\n${signatureRequestEncoded}`;

const result = await dag4.keyStore.verifyData(publicKey, message, signature);
// true -> verification succeeded
// false -> verification failed
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.constellationnetwork.io/stargazer-wallet/constellation-rpc-api/dag_signdata.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
