Constellation Network
IntroductionFundamentalsFor DevelopersNode Validators
  • Index
  • Guide
    • Introduction
    • Provider Activation
    • Sending RPC Requests
    • Signing Data
    • Supported Connectors
    • Using External Libraries
  • API Reference
    • Overview
    • Wallet provider API
      • Overview
      • errorTypes
      • version
      • getProvider()
  • Chain Provider API
    • Overview
    • activated
    • chain
    • version
    • on()
    • removeListener()
    • async activate()
    • async onAsync()
    • async removeListenerAsync()
    • async request()
  • Constellation RPC API
    • Overview
    • dag_accounts
    • dag_chainId
    • dag_getBalance
    • dag_getMetagraphBalance
    • dag_getMetagraphPendingTransaction
    • dag_getMetagraphTransaction
    • dag_getPendingTransaction
    • dag_getPublicKey
    • dag_getTransaction
    • dag_requestAccounts
    • dag_sendMetagraphTransaction
    • dag_sendMetagraphDataTransaction
    • dag_signMetagraphDataTransaction
    • dag_sendTransaction
    • dag_signData
    • dag_signMessage
    • wallet_watchAsset
    • dag_delegatedStake
    • dag_withdrawDelegatedStake
    • dag_allowSpend
    • dag_tokenLock
  • Ethereum RPC API
    • Overview
    • eth_accounts
    • eth_blockNumber
    • eth_call
    • eth_chainId
    • eth_estimateGas
    • eth_gasPrice
    • eth_getBalance
    • eth_getBlockByHash
    • eth_getBlockByNumber
    • eth_getBlockTransactionCountByHash
    • eth_getBlockTransactionCountByNumber
    • eth_getCode
    • eth_getFilterChanges
    • eth_getFilterLogs
    • eth_getLogs
    • eth_getStorageAt
    • eth_getTransactionByBlockHashAndIndex
    • eth_getTransactionByBlockNumberAndIndex
    • eth_getTransactionByHash
    • eth_getTransactionCount
    • eth_getTransactionReceipt
    • eth_getUncleByBlockHashAndIndex
    • eth_getUncleByBlockNumberAndIndex
    • eth_getUncleCountByBlockHash
    • eth_getUncleCountByBlockNumber
    • eth_newBlockFilter
    • eth_newFilter
    • eth_protocolVersion
    • eth_requestAccounts
    • eth_sendTransaction
    • eth_signTypedData
    • eth_signTypedData_v4
    • eth_uninstallFilter
    • net_version
    • personal_sign
    • web3_sha3
  • Resources
    • Stargazer Github
    • Stargazer Connector Github
    • Stargazer Demos Github
    • Stargazer Chrome
    • Stargazer Android
    • Stargazer IOS
    • EIP-1193
Powered by GitBook

Main

  • Website
  • Get DAG
  • Explore Projects
  • Partners

Socials

  • Telegram
  • Discord
  • X (Twitter)

Tools

  • Wallet
  • DAG Explorer
  • Coingecko

© 2025 CONSTELLATION NETWORK

On this page

Was this helpful?

Export as PDF
  1. Constellation RPC API

dag_signData

Previousdag_sendTransactionNextdag_signMessage

Last updated 2 months ago

Was this helpful?

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

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

Parameters

Name
Type
Description

Account

Address

Account to sign from.

Request

Base64<JSONEncoded> | Base64<StringEncoded>

Signature Request.

Return Type

HexString - The prefixed ECDSA signature.

Base64

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

JSONEncoded

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

StringEncoded

/**
 * A String encoded
 * */
type StringEncoded = string;
// 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"

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

// 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

Example

Verify

​
​
​
​