Signing is a cryptographic action that lets a user prove ownership of an address without exposing their private key or initiating an onchain transaction. When a user signs a message, the signed message:

  • Demonstrates control of the address.
  • Can be used to approve a particular action or set of actions.
  • Is a verifiable piece of cryptographic data that can be used onchain or offchain.

In existing apps, signatures are used to authorize transfers of particular assets, prove ownership of an address to sign into an app, and vote in Decentralized Autonomous Organizations (DAOs).

Example Use Cases

  • Identity/Sign-on: Use API Wallets to sign into applications or prove ownership of a wallet.
  • Multi-signature API Wallets: Have multiple parties sign partial messages, which are then combined to create a valid transaction or decrypt information.
  • Scalable, high-frequency interactions: Have games or trading apps use signatures to verify actions and submit batch updates to the blockchain.

Examples

Signing a Payload

You can sign an arbitrary string using the EIP-191 standard.

   [**SDK Documentation**](https://coinbase.github.io/coinbase-sdk-nodejs/index.html)

    // EIP-191 Message signing of hashed payload.
    const message: string = hashMessage("hello world")

    let payloadSignature: PayloadSignature = await wallet.createPayloadSignature(message);
    payloadSignature = await payloadSignature.wait();

Signing Typed Structured Data

EIP-712 is the standard for signing typed structured data, which improves the readability of messages and helps prevent signing opaque, potentially malicious messages.

   [**SDK Documentation**](https://coinbase.github.io/coinbase-sdk-nodejs/index.html)

    // EIP-712 Typed Data Message
    // Define the EIP-712 typed data structure
    const domain = {
      name: "MyDapp",
      version: "1",
      chainId: 1,
      verifyingContract: "0xYourContractAddress",
    };

    const types = {
      MyType: [
        { name: "sender", type: "address" },
        { name: "amount", type: "uint256" },
      ],
    };

    const typedDataMessage = {
      sender: "0xSenderAddress",
      amount: 1000,
    };

    const typedDataMessage = hashTypedData({
      domains,
      types,
      primaryType: "MyType",
      typedDataMessage,
    });

    let payloadSignature: PayloadSignature = await wallet.createPayloadSignature(typedDataMessage);
    payloadSignature = await payloadSignature.wait();