Skip to content

Sign Message (daccSignMessage)

The daccSignMessage function allows you to sign messages using a Dacc wallet. It creates a wallet client and signs the specified message, returning the signature with metadata.

Import

import { daccSignMessage } from 'dacc-js';

Usage

import { daccSignMessage } from 'dacc-js';

import { optimismSepolia } from 'viem/chains'; // used `viem` - npm i viem
 
const result = await daccSignMessage({
  // account: "0xPrivatekey...", // Can call with `allowDaccWallet` function
  daccPublickey: 'daccPublickey_0x123_XxX..',
  // address: "0xYourAccountAddress..", // Only the address created is set to `publicEncryption: true`
  passwordSecretkey: 'my+Password123..',
  network: optimismSepolia,
  message: 'Hello World'
});
 
console.log(result); // {signature, chainId, from, message}
console.log(result?.signature); // 0xsignature...

Arguments

ParameterTypeDescription
accountAccount or 0x${string}Conditional: The account to use for signing (Account object is private key).
daccPublickeystringConditional: The encrypted wallet data from createDaccWallet.
address0x${string}Conditional: wallet address from a created with createDaccWallet in publicEncryption: true mode (can use instead of daccPublickey).
passwordSecretkeystringConditional: The user's password used to decrypt the wallet.
networkChainThe blockchain network configuration.
messagestring or { raw: 0x${string} }The message to sign (string or hex format).

Return Value

The response result is an object containing {signature, chainId, from, message}

Parameters

account (conditional)

  • Type: Account | 0x${string}

The user's account to use for signing the message.

const result = await daccSignMessage({
  account: "0xPrivatekey...", 
//   address: '0x123...', //
//   daccPublickey: 'daccPublickey_0x123_XxX..', //
//   passwordSecretkey: 'my+Password123..', //
  network: optimismSepolia,
  message: 'Hello World'
});

daccPublickey (conditional)

  • Type: string

The user's encrypted public key to address.

daccPublickey is the most reliable addressing solution and supports all types of data storage using daccPublickey.

const result = await daccSignMessage({
//   account: "0xPrivatekey...", //
  daccPublickey: 'daccPublickey_0x123_XxX..', 
  passwordSecretkey: 'my+Password123..', 
  network: optimismSepolia,
  message: 'Hello World'
});

daccPublickey is the most reliable addressing solution and supports all types of data storage using daccPublickey.

address (optional)

  • Type: 0x${string}

The encrypted wallet data returned from createDaccWallet.

const result = await daccSignMessage({
//   account: "0xPrivatekey...", //
//   daccPublickey: 'daccPublickey_0x123_XxX..', // Match with address
  address: '0x123address...', // Only the address created is set to `publicEncryption: true`
  passwordSecretkey: 'my+Password123..', 
  network: optimismSepolia,
  message: 'Hello World'
});

passwordSecretkey (conditional)

  • Type: string

The same password used when creating the wallet.

const result = await daccSignMessage({
  daccPublickey: 'daccPublickey_0x123_XxX..',
  passwordSecretkey: 'my+Password123..', 
  network: optimismSepolia,
  message: 'Hello World'
});

network

  • Type: Chain

The blockchain network configuration for the signing operation.

const result = await daccSignMessage({
  address: '0x123...',
  daccPublickey: 'daccPublickey_0x123_XxX..',
  passwordSecretkey: 'my+Password123..',
  network: optimismSepolia, 
  // network: myCustomChain, // For Custom Chain Network
  message: 'Hello World'
});

message

  • Type: string | { raw: 0x${string} }

The message to sign. Can be a plain text string or a hex-encoded message object.

// Plain text message
const result = await daccSignMessage({
  address: '0x123...',
  daccPublickey: 'daccPublickey_0x123_XxX..',
  passwordSecretkey: 'my+Password123..',
  network: optimismSepolia,
  message: 'Hello World'
});
 
// Hex-encoded message
const result2 = await daccSignMessage({
  address: '0x123...',
  daccPublickey: 'daccPublickey_0x123_XxX..',
  passwordSecretkey: 'my+Password123..',
  network: optimismSepolia,
  message: { raw: '0x48656c6c6f20576f726c64' }, // "Hello World" in hex
});

Examples

Sign a simple message

const result = await daccSignMessage({
  daccPublickey: 'daccPublickey_0x123_XxX..',
  address: '0x123...',
  passwordSecretkey: 'my+Password123..',
  network: optimismSepolia,
  message: 'Welcome to Dacc Wallet!'
});
 
console.log(`Signature: ${result.signature}`);
console.log(`Signer: ${result.from}`);
console.log(`Chain ID: ${result.chainId}`);
console.log(`Original message: ${result.message}`);

Sign with private key account

const result = await daccSignMessage({
  account: "0xYourPrivateKey...",
  message: 'Authentication request',
  network: sepolia
});
 
console.log(`Message signed successfully: ${result.signature}`);

Sign hex-encoded message

const hexMessage = '0x48656c6c6f20446563656e7472616c697a6564205761626333'; // "Hello Decentralized Web3"
 
const result = await daccSignMessage({
  daccPublickey: 'daccPublickey_0x123_XxX..',
  address: '0x123...',
  passwordSecretkey: 'my+Password123..',
  message: { raw: hexMessage },
  network: mainnet
});
 
console.log(`Hex message signed: ${result.signature}`);

Sign message for authentication

const authMessage = `Sign this message to authenticate with our dApp.
Nonce: ${Date.now()}
Timestamp: ${new Date().toISOString()}`;
 
const result = await daccSignMessage({
  daccPublickey: 'daccPublickey_0x123_XxX..',
  address: '0x123...',
  passwordSecretkey: 'my+Password123..',
  message: authMessage,
  network: polygon
});
 
// Use the signature for authentication
console.log(`Authentication signature: ${result.signature}`);
console.log(`Authenticated user: ${result.from}`);

Sign JSON message

const jsonMessage = JSON.stringify({
  action: 'login',
  timestamp: Date.now(),
  domain: 'example.com'
});
 
const result = await daccSignMessage({
  account: "0xPrivateKey...",
  message: jsonMessage,
  network: arbitrum
});
 
console.log(`JSON message signed: ${result.signature}`);

Verify message with different networks

// Sign on different networks
const networks = [mainnet, sepolia, optimism, polygon];
 
for (const network of networks) {
  const result = await daccSignMessage({
    daccPublickey: 'daccPublickey_0x123_XxX..',
    address: '0x123...',
    passwordSecretkey: 'my+Password123..',
    message: `Multi-chain signature on ${network.name}`,
    network
  });
  
  console.log(`${network.name} signature: ${result.signature}`);
}