GithubHelp home page GithubHelp logo

mrtenz / eip-712 Goto Github PK

View Code? Open in Web Editor NEW
108.0 7.0 12.0 1.19 MB

Tiny library with utility functions that can help with signing and verifying EIP-712 based messages

License: MIT License

JavaScript 0.63% TypeScript 99.37%
ethereum eip712 signtypeddata

eip-712's Introduction

eip-712's People

Contributors

dependabot[bot] avatar mrtenz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

eip-712's Issues

2nd-order nesting fails to generate correct type string

Maybe related to #34

I am able to successfully test several payloads, but all payloads with 2nd-order nesting fail, specifically meaning they do not match the hashes from ethers-eip712, which are correct.

I think there may be multiple issues, but the first one I found is that encodeType is not working properly for 2nd-order nesting. For example, I am using the following message:

const msg = {
  types: {
    EIP712Domain: [
      { name: 'name', type: 'string' },
      { name: 'version', type: 'string' },
      { name: 'chainId', type: 'uint256' },
      { name: 'verifyingContract', type: 'address' }
    ],
    Wallet: [
      { name: 'balance', type: 'Balance' },
    ],
    Person: [
      { name: 'wallet', type: 'Wallet' }
    ],
    Mail: [
      { name: 'from', type: 'Person' },
    ],
    Balance: [
      { name: 'currency', type: 'string' }
    ]
  },
  primaryType: 'Mail',
  domain: {
    name: 'Ether Mail',
    version: '1',
    chainId: 12,
    verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC'
  },
  message: {
    from: {
      wallet: {
        balance: {
          currency: 'ETH',
        }
      },
    },
  }
};

Here are the full type names I get for primaryType:

  • ethers-eip712 (correct): Mail(Person from)Person(Wallet wallet)Wallet(Balance balance)Balance(string currency)
  • eip-712 (incorrect): Mail(Person from)Balance(string currency)Person(Wallet wallet)Wallet(Balance balance)

It appears there is an edge case somewhere in your encodeType function, which differs significantly from that of ethers-eip712. Note that payloads with 1st order nesting work just fine.

Failed with recursive data

For example

{
        CIP23Domain: [
          { name: 'name', type: 'string' },
          { name: 'version', type: 'string' },
          { name: 'chainId', type: 'uint256' },
          { name: 'verifyingContract', type: 'address' }
        ],
        Person: [
          { name: 'name', type: 'string' },
          { name: 'mother', type: 'Person' },
          { name: 'father', type: 'Person' }
        ]
}

EIP712 - encoding array types throws an error

Hi,
it seems like the encoding for array fields doesn't work.
Example for the typedData

{
  "types": {
    "EIP712Domain": [
      {
        "name": "name",
        "type": "string"
      },
      {
        "name": "version",
        "type": "string"
      },
      {
        "name": "chainId",
        "type": "uint256"
      },
      {
        "name": "verifyingContract",
        "type": "address"
      },
      {
        "name": "salt",
        "type": "bytes32"
      }
    ],
    "Person": [
      {
        "name": "name",
        "type": "string"
      },
      {
        "name": "wallet",
        "type": "address"
      }
    ],
    "Mail": [
      {
        "name": "from",
        "type": "Person[]"
      },
      {
        "name": "to",
        "type": "Person[]"
      }
    ]
  },
  "primaryType": "Mail",
  "domain": {
    "name": "Ether Mail",
    "version": "1",
    "chainId": 3,
    "verifyingContract": "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
    "salt": "0x00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff"
  },
  "message": {
    "from": [
      {
        "name": "Alice",
        "wallet": "0xaaAAaaaAaaAAAAaaaaaAaaAAAaAAAAAAAaaAaaAA"
      }
    ],
    "to": [
      {
        "name": "Alice",
        "wallet": "0xaaAAaaaAaaAAAAaaaaaAaaAAAaAAAAAAAaaAaaAA"
      },
      {
        "name": "Bob",
        "wallet": "0xaaAAaaaAaaAAAAaaaaaAaaAAAaAAAAAAAaaAaaAA"
      }
    ]
  }
}

I used the following commands

const eip712 = require('eip-712');
eip712.getMessage(message, false);

And got the following error

Uncaught TypeError: Cannot read property 'map' of undefined
    at /app_dir/app/node_modules/eip-712/lib/cjs/eip-712.js:39:57
    at Array.map (<anonymous>)
    at encodeType (/app_dir/app/node_modules/eip-712/lib/cjs/eip-712.js:38:16)
    at getTypeHash (/app_dir/app/node_modules/eip-712/lib/cjs/eip-712.js:46:32)
    at encodeData (/app_dir/app/node_modules/eip-712/lib/cjs/eip-712.js:96:21)
    at getStructHash (/app_dir/app/node_modules/eip-712/lib/cjs/eip-712.js:103:32)
    at Object.getMessage (/app_dir/app/node_modules/eip-712/lib/cjs/eip-712.js:109:110)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.