Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add eth_signTypedData method. #84

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Sources/Web3Modal/Core/W3MJSONRPC+Coinbase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ extension W3MJSONRPC {
address: address,
message: message
)
case let .eth_signTypedData(address, message):
return .eth_signTypedData_v4(address: address,
typedDataJson: JSONString(rawValue: message)!)
case .eth_requestAccounts:
return .eth_requestAccounts
case let .eth_signTransaction(from, to, value, data, nonce, _, gasPrice, maxFeePerGas, maxPriorityFeePerGas, gasLimit, chainId):
Expand Down
6 changes: 6 additions & 0 deletions Sources/Web3Modal/Core/W3MJSONRPC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ public enum W3MJSONRPC: Codable {
address: String,
message: String
)

case eth_signTypedData(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be eth_signTypedData_v4?

address: String,
message: String
)

case eth_signTransaction(
from: String,
to: String?,
Expand Down
18 changes: 14 additions & 4 deletions Sources/Web3Modal/Core/Web3ModalClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public class Web3ModalClient {
let chain = getSelectedChain(),
let blockchain = Blockchain(namespace: chain.chainNamespace, reference: chain.chainReference)
else { return }

if case let .personal_sign(address, message) = request {
try await signClient.request(
params: .init(
Expand All @@ -183,6 +183,11 @@ public class Web3ModalClient {
chainId: blockchain
)
)
} else if case let .eth_signTypedData(address, message) = request {
try await signClient.request(params: .init(topic: session.topic,
method: request.rawValues.method,
params: AnyCodable(any: [address, message]),
chainId: blockchain))
} else {
try await signClient.request(
params: .init(
Expand Down Expand Up @@ -235,7 +240,7 @@ public class Web3ModalClient {
break
}
}

/// For sending JSON-RPC requests to wallet.
/// - Parameters:
/// - params: Parameters defining request and related session
Expand Down Expand Up @@ -276,7 +281,12 @@ public class Web3ModalClient {
break
}
}


public func removeSessionAndAccount() {
store.session = nil
store.account = nil
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mooshee My mistake, just a test function. This should be removed.


/// Query sessions
/// - Returns: All sessions
public func getSessions() -> [Session] {
Expand Down Expand Up @@ -329,7 +339,7 @@ public class Web3ModalClient {
let urlString = session.peer.redirect?.native ?? session.peer.redirect?.universal,
let url = URL(string: urlString)
else { return }

DispatchQueue.main.async {
UIApplication.shared.open(url, completionHandler: nil)
}
Expand Down