https://github.com/0xsequence/ethers-eip712
Ethereum Typed Data Hashing and Signing (EIP712) implementation for ethers.js
https://github.com/0xsequence/ethers-eip712
Last synced: 10 months ago
JSON representation
Ethereum Typed Data Hashing and Signing (EIP712) implementation for ethers.js
- Host: GitHub
- URL: https://github.com/0xsequence/ethers-eip712
- Owner: 0xsequence
- License: mit
- Created: 2020-08-07T14:53:18.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-08-10T17:26:20.000Z (almost 6 years ago)
- Last Synced: 2025-06-06T03:39:54.201Z (about 1 year ago)
- Language: TypeScript
- Size: 95.7 KB
- Stars: 40
- Watchers: 16
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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`
NOTE: both ethers v4 and ethers v5 are compatible by this single library.
## Example
```typescript
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](./tests/typed-data.test.ts)
## License
MIT