Skip to content

Commit b8e55b2

Browse files
chore(EIP712): example for EIP712Parser;
1 parent 4669bfe commit b8e55b2

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Sources/web3swift/Utils/EIP/EIP712/EIP712.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public extension EIP712Hashable {
6363
case let boolean as Bool:
6464
result = ABIEncoder.encodeSingleType(type: .uint(bits: 8), value: boolean ? 1 : 0)!
6565
case let hashable as EIP712Hashable:
66-
// TODO: should it be hashed here?
6766
result = try hashable.hash()
6867
default:
6968
/// Cast to `AnyObject` is required. Otherwise, `nil` value will fail this condition.

Sources/web3swift/Utils/EIP/EIP712/EIP712Parser.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import Foundation
88
import Web3Core
99

10-
/// The only purpose of this class is to parse raw JSON and output an EIP712 hash.
10+
/// The only purpose of this class is to parse raw JSON and output an EIP712 hash ready for signing.
1111
/// Example of a payload that is received via `eth_signTypedData` for signing:
1212
/// ```
1313
/// {
@@ -75,7 +75,19 @@ import Web3Core
7575
/// }
7676
/// }
7777
/// ```
78+
///
79+
/// Example use case:
80+
/// ```
81+
/// let payload: String = ... // This is the payload received from eth_signTypedData
82+
/// let eip712TypedData = try EIP712Parser.parse(payload)
83+
/// let signature = try Web3Signer.signEIP712(
84+
/// eip712TypedData,
85+
/// keystore: keystore,
86+
/// account: account,
87+
/// password: password)
88+
/// ```
7889
public class EIP712Parser {
90+
7991
static func toData(_ json: String) throws -> Data {
8092
guard let json = json.data(using: .utf8) else {
8193
throw Web3Error.inputError(desc: "Failed to parse EIP712 payload. Given string is not valid UTF8 string. \(json)")

0 commit comments

Comments
 (0)