Sign Message

Personal Sign

If a user is logged in to the Face Wallet, the user can sign the message from the wallet using Ethers.js. When signing the message, the user confirms the message to sign through the Face Wallet modal then enters the PIN code.

import { Face, Network } from '@haechi-labs/face-sdk';
import { ethers } from 'ethers';

const face = new Face({
  network: Network.SEPOLIA, 
  apiKey: 'YOUR_DAPP_API_KEY'
});
const provider = new ethers.providers.Web3Provider(face.getEthLikeProvider());
const signer = provider.getSigner();

const originalMessage = 'YOUR_MESSAGE_TO_SIGN';
const signedMessage = await signer.signMessage(originalMessage);

Sign Typed Data

If a user logs into Face Wallet, they can sign typed data using Ethers.js. When signing the typed data, the user will review the data to be signed through the Face Wallet modal and enter a PIN code.

eth_signTypedData_v3

import { Face, Network } from '@haechi-labs/face-sdk';
import { ethers } from 'ethers';

const face = new Face({
  network: Network.SEPOLIA, 
  apiKey: 'YOUR_DAPP_API_KEY'
});
const provider = new ethers.providers.Web3Provider(face.getEthLikeProvider());
const signer = provider.getSigner();

const originalMessage = {
  types: {
    EIP712Domain: [
      {
        name: "name",
        type: "string",
      },
      {
        name: "version",
        type: "string",
      },
      {
        name: "chainId",
        type: "uint256",
      },
      {
        name: "verifyingContract",
        type: "address",
      },
    ],
    Order: [
      { name: "isSeller", type: "uint8" },
      { name: "maker", type: "address" },
      { name: "listingTime", type: "uint64" },
      { name: "expirationTime", type: "uint64" },
      { name: "tokenAddress", type: "address" },
      { name: "tokenAmount", type: "uint256" },
      { name: "nftAddress", type: "address" },
      { name: "nftId", type: "uint256" },
      { name: "nftAmount", type: "uint256" },
      { name: "salt", type: "uint256" },
      { name: "mail", type: "Mail" },
    ],
    Mail: [
      { name: "from", type: "address" },
      { name: "to", type: "address" },
      { name: "contents", type: "string" },
    ],
  },
  primaryType: "Order",
  domain: {
    name: "Marketplace",
    version: "1.0",
    chainId: 5,
    verifyingContract: "0x1234567890ABCDEFGHIJ1234567890ABCDEFGHIJ",
  },
  message: {
    isSeller: 0,
    maker: "0xABCDEFGHIJ12345678901234567890ABCDEFGHIJ",
    listingTime: 1681262000,
    expirationTime: 1681348400,
    tokenAddress: "0xABCDEFGHIJABCDEFGHIJ12345678901234567890",
    tokenAmount: 190,
    nftAddress: "0xDaE15C34154cf9FBef6Ed4723481ae44EB63CdBE",
    nftId: "7913031215882140490192549673218",
    nftAmount: 0,
    salt: 0,
    mail: {
      from: "0xD444D35e329f49889b78182DCdDC556Ec29cE714",
      to: "0xD444D35e329f49889b78182DCdDC556Ec29cE714",
      contents: "Hello, World!",
    },
  },
};;
const address = await signer.getAddress();
const signature = await provider.send('eth_signTypedData_v3', [
  address.toLowerCase(),
  message,
]);

eth_signTypedData_v4

import { Face, Network } from '@haechi-labs/face-sdk';
import { ethers } from 'ethers';

const face = new Face({
  network: Network.SEPOLIA, 
  apiKey: 'YOUR_DAPP_API_KEY'
});
const provider = new ethers.providers.Web3Provider(face.getEthLikeProvider());
const signer = provider.getSigner();

const originalMessage = {
  types: {
    EIP712Domain: [
      {
        name: "name",
        type: "string",
      },
      {
        name: "version",
        type: "string",
      },
      {
        name: "chainId",
        type: "uint256",
      },
      {
        name: "verifyingContract",
        type: "address",
      },
    ],
    Order: [
      { name: "isSeller", type: "uint8" },
      { name: "maker", type: "address" },
      { name: "listingTime", type: "uint64" },
      { name: "expirationTime", type: "uint64" },
      { name: "tokenAddress", type: "address" },
      { name: "tokenAmount", type: "uint256" },
      { name: "nftAddress", type: "address" },
      { name: "nftId", type: "uint256" },
      { name: "nftAmount", type: "uint256" },
      { name: "salt", type: "uint256" },
      { name: "mails", type: "Mail[]" },
    ],
    Mail: [
      { name: "from", type: "address" },
      { name: "to", type: "address" },
      { name: "contents", type: "string" },
    ],
  },
  primaryType: "Order",
  domain: {
    name: "Marketplace",
    version: "1.0",
    chainId: 5,
    verifyingContract: "0x1234567890ABCDEFGHIJ1234567890ABCDEFGHIJ",
  },
  message: {
    isSeller: 0,
    maker: "0xABCDEFGHIJ12345678901234567890ABCDEFGHIJ",
    listingTime: 1681262000,
    expirationTime: 1681348400,
    tokenAddress: "0xABCDEFGHIJABCDEFGHIJ12345678901234567890",
    tokenAmount: 190,
    nftAddress: "0xBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB,
    nftId: "7913031215882140490192549673218",
    nftAmount: 0,
    salt: 0,
    mail: [
      {
      	from: "0x1234567890ABCDEFGHIJ1234567890ABCDEFGHIJ",
	      to: "0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
  	    contents: "Hello, World!",
    	},
      {
      	from: "0x1234567890ABCDEFGHIJ1234567890ABCDEFGHIJ",
	      to: "0xCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC",
  	    contents: "Hello, World!",
    	},
    ]
  },
};;
const address = await signer.getAddress();
const signature = await provider.send('eth_signTypedData_v4', [
  address.toLowerCase(),
  message,
]);