Sign & verify messages
Every network descriptor provides signMessage() and verifyMessage() methods. These let you cryptographically prove ownership of an address without broadcasting a transaction.
UTXO networks
UTXO networks (Bitcoin, Litecoin, Dogecoin, Bitcoin Cash) use the standard Bitcoin message signing format:
import { ChainGate, newWallet } from 'chaingate'
const cg = new ChainGate({ apiKey: 'your-api-key' })
const wallet = newWallet()
const connector = cg.connect(cg.networks.bitcoin, wallet)
// Get the private key for the current address
const key = connector.addressKeyPair()
// Sign a message
const signature = cg.networks.bitcoin.signMessage('Hello ChainGate', key.privateKey.raw)
// Verify the signature
const address = connector.address()
const isValid = cg.networks.bitcoin.verifyMessage('Hello ChainGate', signature, address)
console.log(isValid) // true
EVM networks
EVM networks (Ethereum and custom RPC networks) use EIP-191 personal message signing:
import { ChainGate, newWallet } from 'chaingate'
const cg = new ChainGate({ apiKey: 'your-api-key' })
const wallet = newWallet()
const connector = cg.connect(cg.networks.ethereum, wallet)
// Get the private key for the current address
const key = connector.addressKeyPair()
// Sign with EIP-191
const signature = cg.networks.ethereum.signMessage('Hello ChainGate', key.privateKey.raw)
// Verify
const address = connector.address()
const isValid = cg.networks.ethereum.verifyMessage('Hello ChainGate', signature, address)
console.log(isValid) // true
Use cases
- Proof of ownership — Prove you control an address without spending funds.
- Authentication — Sign a server-provided challenge to log in with your wallet.
- Off-chain attestation — Sign arbitrary data for off-chain verification (e.g., agreements, votes).