Skip to content

Commit

Permalink
chore(EIP712): example for EIP712Parser;
Browse files Browse the repository at this point in the history
  • Loading branch information
JeneaVranceanu committed Oct 19, 2023
1 parent 4669bfe commit b8e55b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 0 additions & 1 deletion Sources/web3swift/Utils/EIP/EIP712/EIP712.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public extension EIP712Hashable {
case let boolean as Bool:
result = ABIEncoder.encodeSingleType(type: .uint(bits: 8), value: boolean ? 1 : 0)!
case let hashable as EIP712Hashable:
// TODO: should it be hashed here?
result = try hashable.hash()
default:
/// Cast to `AnyObject` is required. Otherwise, `nil` value will fail this condition.
Expand Down
14 changes: 13 additions & 1 deletion Sources/web3swift/Utils/EIP/EIP712/EIP712Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import Foundation
import Web3Core

/// The only purpose of this class is to parse raw JSON and output an EIP712 hash.
/// The only purpose of this class is to parse raw JSON and output an EIP712 hash ready for signing.
/// Example of a payload that is received via `eth_signTypedData` for signing:
/// ```
/// {
Expand Down Expand Up @@ -75,7 +75,19 @@ import Web3Core
/// }
/// }
/// ```
///
/// Example use case:
/// ```
/// let payload: String = ... // This is the payload received from eth_signTypedData
/// let eip712TypedData = try EIP712Parser.parse(payload)
/// let signature = try Web3Signer.signEIP712(
/// eip712TypedData,
/// keystore: keystore,
/// account: account,
/// password: password)
/// ```
public class EIP712Parser {

static func toData(_ json: String) throws -> Data {
guard let json = json.data(using: .utf8) else {
throw Web3Error.inputError(desc: "Failed to parse EIP712 payload. Given string is not valid UTF8 string. \(json)")
Expand Down

0 comments on commit b8e55b2

Please sign in to comment.