mrtenz / eip-712 Goto Github PK
View Code? Open in Web Editor NEWTiny library with utility functions that can help with signing and verifying EIP-712 based messages
License: MIT License
Tiny library with utility functions that can help with signing and verifying EIP-712 based messages
License: MIT License
Update @findeth/abi
to 0.7.1 to strip keccak
dependency
It is just a suggestion to add example implementation using micro-eth-signer
.
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.
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' }
]
}
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)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.