https://github.com/blocto/ethereumsigntypeddatautil
A collection of functions for signing Ethereum typed data hash(EIP712).
https://github.com/blocto/ethereumsigntypeddatautil
Last synced: 4 months ago
JSON representation
A collection of functions for signing Ethereum typed data hash(EIP712).
- Host: GitHub
- URL: https://github.com/blocto/ethereumsigntypeddatautil
- Owner: blocto
- License: mit
- Created: 2022-05-25T10:53:02.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-05-26T14:36:10.000Z (about 3 years ago)
- Last Synced: 2025-01-22T06:37:37.644Z (5 months ago)
- Language: Swift
- Size: 24.4 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# EthereumSignTypedDataUtil
This is collection of functions for signing Ethereum typed data hash(EIP712).
This project is inspired by the project [web3.swift](https://github.com/argentlabs/web3.swift).
## Installation
### Swift Package Manager
Use Xcode to add to the project (**File -> Swift Packages**) or add this to your `Package.swift` file:
```swift
.package(url: "https://github.com/portto/EthereumSignTypedDataUtil", from: "0.1.0")
```### CocoaPods
Add web3.swift to your `Podfile`:
```ruby
pod 'EthereumSignTypedDataUtil'
```Then run the following command:
```bash
$ pod install
```## Usage
### Getting Started
Create an instance of `JSONDecoder()` to decode data to EIP712TypedData and call signableHash with specific supported version v3 or v4, the latest type point to v4 for now.
```swift
import EthereumSignTypedDataUtillet typeDataSignMessageV3 = #"{"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"}],"Mail":[{"name":"from","type":"Person"},{"name":"to","type":"Person"},{"name":"contents","type":"string"}]},"primaryType":"Mail","domain":{"name":"Ether Mail","version":"1","chainId":4,"verifyingContract":"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"},"message":{"from":{"name":"Cow","wallet":"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"},"to":{"name":"Bob","wallet":"0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"},"contents":"Hello, Bob!"}}"#
let typedData = try JSONDecoder().decode(EIP712TypedData.self, from: Data(typeDataSignMessage.utf8))
let result = try typedData.signableHash(version: EIP712TypedDataSignVersion.v3)
```## Author
andrew.wang, [email protected]
## LicenseEthereumSignTypedDataUtil is released under an MIT license. See [LICENSE.md](https://github.com/portto/EthereumSignTypedDataUtil/blob/main/LICENSE.md) for more information.