JSPM

ethers-eip712

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1502
  • Score
    100M100P100Q117460F
  • License MIT

Ethereum Typed Data Hashing and Signing (EIP712) implementation for ethers.js

Package Exports

  • ethers-eip712

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ethers-eip712) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ethers-eip712

ethers-eip712 is an npm package that implements the Ethereum Typed Data (EIP712) for structured data hashing and signing proposal, written in TypeScript for ethers.js.

EIP712: https://eips.ethereum.org/EIPS/eip-712

Usage

yarn install ethers-eip712 or npm install ethers-eip712

Example

import { ethers } from 'ethers'
import { TypedDataUtils } from 'ethers-eip712'

const typedData = {
  types: {
    EIP712Domain: [
      {name: "name", type: "string"},
      {name: "version", type: "string"},
      {name: "chainId", type: "uint256"},
      {name: "verifyingContract", type: "address"},
    ],
    Person: [
      {name: "name", type: "string"},
      {name: "wallet", type: "address"},  
    ]
  },
  primaryType: 'Person' as const,
  domain: {
    name: 'Ether Mail',
    version: '1',
    chainId: 1,
    verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC'
  },
  message: {
    'name': 'Bob',
    'wallet': '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB'
  }
}

const digest = TypedDataUtils.encodeDigest(typedData)
const digestHex = ethers.utils.hexlify(digest)

const wallet = ethers.Wallet.createRandom()
const signature = wallet.signMessage(digest)

See tests for more examples

License

MIT