Skip to content

Commit

Permalink
Merge pull request #629 from WalletConnect/develop
Browse files Browse the repository at this point in the history
1.1.0
  • Loading branch information
flypaper0 authored Dec 7, 2022
2 parents 41966b4 + 6a02605 commit 2bbbb2b
Show file tree
Hide file tree
Showing 77 changed files with 1,016 additions and 411 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Setup Xcode Version
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '13.4.1'
xcode-version: 14.1

- uses: actions/cache@v2
with:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/set-user-agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
with:
token: ${{ secrets.GH_TOKEN }}

- name: Set User Agent
shell: bash
run: ./.github/scripts/set-user-agent.sh
Expand Down
67 changes: 67 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/WalletConnectVerify.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1340"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "WalletConnectVerify"
BuildableName = "WalletConnectVerify"
BlueprintName = "WalletConnectVerify"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "WalletConnectVerify"
BuildableName = "WalletConnectVerify"
BlueprintName = "WalletConnectVerify"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
13 changes: 3 additions & 10 deletions Example/DApp/SceneDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import UIKit
import Starscream
import Auth
import WalletConnectRelay
import WalletConnectNetworking

extension WebSocket: WebSocketConnecting { }

struct SocketFactory: WebSocketFactory {
func create(with url: URL) -> WebSocketConnecting {
return WebSocket(url: url)
}
}

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

var window: UIWindow?
Expand All @@ -19,7 +11,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
private let authCoordinator = AuthCoordinator()

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
Networking.configure(projectId: InputConfig.projectId, socketFactory: SocketFactory())
Networking.configure(projectId: InputConfig.projectId, socketFactory: DefaultSocketFactory())
Auth.configure(signerFactory: DefaultSignerFactory())

setupWindow(scene: scene)
}
Expand Down
107 changes: 82 additions & 25 deletions Example/ExampleApp.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
"repositoryURL": "https://github.com/WalletConnect/Web3.swift",
"state": {
"branch": null,
"revision": "bdaaed96eee3a9bf7f341165f89a94288961d14c",
"version": "1.0.0"
"revision": "569255adcfff0b37e4cb8004aea29d0e2d6266df",
"version": "1.0.2"
}
}
]
Expand Down
11 changes: 1 addition & 10 deletions Example/ExampleApp/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@ import WalletConnectSign
import WalletConnectNetworking
import WalletConnectRelay
import WalletConnectPairing
import Starscream

extension WebSocket: WebSocketConnecting { }

struct SocketFactory: WebSocketFactory {
func create(with url: URL) -> WebSocketConnecting {
return WebSocket(url: url)
}
}

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

Expand All @@ -27,7 +18,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
url: "example.wallet",
icons: ["https://avatars.githubusercontent.com/u/37784886"])

Networking.configure(projectId: InputConfig.projectId, socketFactory: SocketFactory())
Networking.configure(projectId: InputConfig.projectId, socketFactory: DefaultSocketFactory())
Pair.configure(metadata: metadata)
#if DEBUG
if CommandLine.arguments.contains("-cleanInstall") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import Commons
import Web3

struct EthereumSigner {
struct ETHSigner {

private init() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Commons
import SolanaSwift
import TweetNacl

struct SolanaSigner {
struct SOLSigner {

static var address: String {
return account.publicKey.base58EncodedString
Expand Down
8 changes: 4 additions & 4 deletions Example/ExampleApp/Shared/Signer/Signer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ class Signer {
static func sign(request: Request) -> AnyCodable {
switch request.method {
case "personal_sign":
return EthereumSigner.personalSign(request.params)
return ETHSigner.personalSign(request.params)

case "eth_signTypedData":
return EthereumSigner.signTypedData(request.params)
return ETHSigner.signTypedData(request.params)

case "eth_sendTransaction":
return EthereumSigner.sendTransaction(request.params)
return ETHSigner.sendTransaction(request.params)

case "solana_signTransaction":
return SolanaSigner.signTransaction(request.params)
return SOLSigner.signTransaction(request.params)
default:
fatalError("not implemented")
}
Expand Down
4 changes: 2 additions & 2 deletions Example/ExampleApp/Wallet/WalletViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import Combine

final class WalletViewController: UIViewController {
lazy var accounts = [
"eip155": EthereumSigner.address,
"solana": SolanaSigner.address
"eip155": ETHSigner.address,
"solana": SOLSigner.address
]

var sessionItems: [ActiveSessionItem] = []
Expand Down
30 changes: 17 additions & 13 deletions Example/IntegrationTests/Auth/AuthTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ final class AuthTests: XCTestCase {

var appAuthClient: AuthClient!
var walletAuthClient: AuthClient!

let walletAccount = Account(chainIdentifier: "eip155:1", address: "0x724d0D2DaD3fbB0C168f947B87Fa5DBe36F1A8bf")!
let prvKey = Data(hex: "462c1dad6832d7d96ccf87bd6a686a4110e114aaaebd5512e552c0e3a87b480f")
let eip1271Signature = "0xc1505719b2504095116db01baaf276361efd3a73c28cf8cc28dabefa945b8d536011289ac0a3b048600c1e692ff173ca944246cf7ceb319ac2262d27b395c82b1c"
private var publishers = [AnyCancellable]()
Expand All @@ -22,16 +24,15 @@ final class AuthTests: XCTestCase {
setupClients()
}

private func setupClients(address: String = "0x724d0D2DaD3fbB0C168f947B87Fa5DBe36F1A8bf", iatProvider: IATProvider = DefaultIATProvider()) {
let walletAccount = Account(chainIdentifier: "eip155:1", address: address)!
private func setupClients(iatProvider: IATProvider = DefaultIATProvider()) {
(appPairingClient, appAuthClient) = makeClients(prefix: "🤖 App", iatProvider: iatProvider)
(walletPairingClient, walletAuthClient) = makeClients(prefix: "🐶 Wallet", account: walletAccount, iatProvider: iatProvider)
(walletPairingClient, walletAuthClient) = makeClients(prefix: "🐶 Wallet", iatProvider: iatProvider)
}

func makeClients(prefix: String, account: Account? = nil, iatProvider: IATProvider) -> (PairingClient, AuthClient) {
func makeClients(prefix: String, iatProvider: IATProvider) -> (PairingClient, AuthClient) {
let logger = ConsoleLogger(suffix: prefix, loggingLevel: .debug)
let keychain = KeychainStorageMock()
let relayClient = RelayClient(relayHost: InputConfig.relayHost, projectId: InputConfig.projectId, keychainStorage: keychain, socketFactory: SocketFactory(), logger: logger)
let relayClient = RelayClient(relayHost: InputConfig.relayHost, projectId: InputConfig.projectId, keychainStorage: keychain, socketFactory: DefaultSocketFactory(), logger: logger)
let keyValueStorage = RuntimeKeyValueStorage()

let networkingClient = NetworkingClientFactory.create(
Expand All @@ -48,8 +49,8 @@ final class AuthTests: XCTestCase {

let authClient = AuthClientFactory.create(
metadata: AppMetadata(name: name, description: "", url: "", icons: [""]),
account: account,
projectId: InputConfig.projectId,
signerFactory: DefaultSignerFactory(),
logger: logger,
keyValueStorage: keyValueStorage,
keychainStorage: keychain,
Expand Down Expand Up @@ -80,9 +81,10 @@ final class AuthTests: XCTestCase {
try! await walletPairingClient.pair(uri: uri)
walletAuthClient.authRequestPublisher.sink { [unowned self] request in
Task(priority: .high) {
let signer = MessageSignerFactory.create(projectId: InputConfig.projectId)
let signature = try! signer.sign(message: request.message, privateKey: prvKey, type: .eip191)
try! await walletAuthClient.respond(requestId: request.id, signature: signature)
let signerFactory = DefaultSignerFactory()
let signer = MessageSignerFactory(signerFactory: signerFactory).create(projectId: InputConfig.projectId)
let signature = try! signer.sign(payload: request.payload, address: walletAccount.address, privateKey: prvKey, type: .eip191)
try! await walletAuthClient.respond(requestId: request.id, signature: signature, from: walletAccount)
}
}
.store(in: &publishers)
Expand All @@ -95,7 +97,9 @@ final class AuthTests: XCTestCase {
}

func testEIP1271RespondSuccess() async {
setupClients(address: "0x2faf83c542b68f1b4cdc0e770e8cb9f567b08f71", iatProvider: IATProviderMock())
setupClients(iatProvider: IATProviderMock())

let account = Account(chainIdentifier: "eip155:1", address: "0x2faf83c542b68f1b4cdc0e770e8cb9f567b08f71")!

let responseExpectation = expectation(description: "successful response delivered")
let uri = try! await appPairingClient.create()
Expand All @@ -115,7 +119,7 @@ final class AuthTests: XCTestCase {
walletAuthClient.authRequestPublisher.sink { [unowned self] request in
Task(priority: .high) {
let signature = CacaoSignature(t: .eip1271, s: eip1271Signature)
try! await walletAuthClient.respond(requestId: request.id, signature: signature)
try! await walletAuthClient.respond(requestId: request.id, signature: signature, from: account)
}
}
.store(in: &publishers)
Expand All @@ -136,7 +140,7 @@ final class AuthTests: XCTestCase {
walletAuthClient.authRequestPublisher.sink { [unowned self] request in
Task(priority: .high) {
let signature = CacaoSignature(t: .eip1271, s: eip1271Signature)
try! await walletAuthClient.respond(requestId: request.id, signature: signature)
try! await walletAuthClient.respond(requestId: request.id, signature: signature, from: walletAccount)
}
}
.store(in: &publishers)
Expand Down Expand Up @@ -179,7 +183,7 @@ final class AuthTests: XCTestCase {
Task(priority: .high) {
let invalidSignature = "438effc459956b57fcd9f3dac6c675f9cee88abf21acab7305e8e32aa0303a883b06dcbd956279a7a2ca21ffa882ff55cc22e8ab8ec0f3fe90ab45f306938cfa1b"
let cacaoSignature = CacaoSignature(t: .eip191, s: invalidSignature)
try! await walletAuthClient.respond(requestId: request.id, signature: cacaoSignature)
try! await walletAuthClient.respond(requestId: request.id, signature: cacaoSignature, from: walletAccount)
}
}
.store(in: &publishers)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Foundation
import XCTest
@testable import Auth
import TestingUtils

class CacaoSignerTest: XCTestCase {

let signer = MessageSignerFactory.create(projectId: "project-id")
let signer = MessageSignerFactory(signerFactory: DefaultSignerFactory())
.create(projectId: InputConfig.projectId)

let privateKey = Data(hex: "305c6cde3846927892cd32762f6120539f3ec74c9e3a16b9b798b1e85351ae2a")

Expand All @@ -26,10 +26,31 @@ class CacaoSignerTest: XCTestCase {
- https://example.com/my-web2-claim.json
"""

let payload = AuthPayload(requestParams: RequestParams(
domain: "service.invalid",
chainId: "eip155:1",
nonce: "32891756",
aud: "https://service.invalid/login",
nbf: nil,
exp: nil,
statement: "I accept the ServiceOrg Terms of Service: https://service.invalid/tos",
requestId: nil,
resources: [
"ipfs://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq/",
"https://example.com/my-web2-claim.json"
]
), iat: "2021-09-30T16:25:24Z")

let signature = CacaoSignature(t: .eip191, s: "0x438effc459956b57fcd9f3dac6c675f9cee88abf21acab7305e8e32aa0303a883b06dcbd956279a7a2ca21ffa882ff55cc22e8ab8ec0f3fe90ab45f306938cfa1b")

func testCacaoSign() throws {
XCTAssertEqual(try signer.sign(message: message, privateKey: privateKey, type: .eip191), signature)
let address = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
let formatted = try SIWEMessageFormatter().formatMessage(
from: payload,
address: address
)
XCTAssertEqual(formatted, message)
XCTAssertEqual(try signer.sign(payload: payload, address: address, privateKey: privateKey, type: .eip191), signature)
}

func testCacaoVerify() async throws {
Expand Down
39 changes: 39 additions & 0 deletions Example/IntegrationTests/Auth/Signer/EIP1271VerifierTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Foundation
import XCTest
@testable import Auth
import JSONRPC

class EIP1271VerifierTests: XCTestCase {

let signature = Data(hex: "c1505719b2504095116db01baaf276361efd3a73c28cf8cc28dabefa945b8d536011289ac0a3b048600c1e692ff173ca944246cf7ceb319ac2262d27b395c82b1c")

let message = Data(hex: "19457468657265756d205369676e6564204d6573736167653a0a3235326c6f63616c686f73742077616e747320796f7520746f207369676e20696e207769746820796f757220457468657265756d206163636f756e743a0a3078326661663833633534326236386631623463646330653737306538636239663536376230386637310a0a5552493a20687474703a2f2f6c6f63616c686f73743a333030302f0a56657273696f6e3a20310a436861696e2049443a20310a4e6f6e63653a20313636353434333031353730300a4973737565642041743a20323032322d31302d31305432333a30333a33352e3730305a0a45787069726174696f6e2054696d653a20323032322d31302d31315432333a30333a33352e3730305a")

let address = "0x2faf83c542b68f1b4cdc0e770e8cb9f567b08f71"
let chainId = "eip155:1"

func testSuccessVerify() async throws {
let httpClient = HTTPNetworkClient(host: "rpc.walletconnect.com")
let signer = DefaultSignerFactory().createEthereumSigner()
let verifier = EIP1271Verifier(projectId: InputConfig.projectId, httpClient: httpClient, signer: signer)
try await verifier.verify(
signature: signature,
message: message,
address: address,
chainId: chainId
)
}

func testFailureVerify() async throws {
let httpClient = HTTPNetworkClient(host: "rpc.walletconnect.com")
let signer = DefaultSignerFactory().createEthereumSigner()
let verifier = EIP1271Verifier(projectId: InputConfig.projectId, httpClient: httpClient, signer: signer)

await XCTAssertThrowsErrorAsync(try await verifier.verify(
signature: Data("deadbeaf"),
message: message,
address: address,
chainId: chainId
))
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import Foundation
import XCTest
import TestingUtils
@testable import Auth

class EIP191VerifierTests: XCTestCase {

private let verifier = EIP191Verifier()
private let verifier = EIP191Verifier(signer: DefaultSignerFactory().createEthereumSigner())

private let address = "0x15bca56b6e2728aec2532df9d436bd1600e86688"
private let message = "\u{19}Ethereum Signed Message:\n7Message".data(using: .utf8)!
Expand Down
Loading

0 comments on commit 2bbbb2b

Please sign in to comment.