Skip to content

Commit

Permalink
beta100 (#238)
Browse files Browse the repository at this point in the history
* add update methods tests

* add updateEvents to ControllerSessionStateMachine

* add handleUpdateEventsResponse

* Add expiry date concept test case

* Add inactive pairing expiry tests

* Change pairing creation pattern

* Add pairing extension tests

* Add pairing activation test

* Activate pairing created from URI

* Update Tests/WalletConnectTests/Helpers/Error+Extension.swift

Co-authored-by: André Vants <[email protected]>

* build fix

* refactor ControllerSessionStateMachine

* add onSessionUpdateEventsRequest handling

* add session update events integration test

* add NonControllerSessionStateMachine unit tests

* Add ControllerSessionStateMachineTests events tests

* Change test case name

* Fix build

* Renamed PairingSequence to WCPairing

* Renamed SessionSequence to WCSession

* Adds Commons and Toolbox packages

* update session proposal data model

* update public proposal data model

* update methods with protocol requirements

* update account params

* remove comment

* Removing sequence name from storage variables names

* Dropping sequence term from storage protocols signature

* Renamed sequence params in storage mocks

* Fixes Bad access when trying to modify subscriptions #156

* migrate update methods to state machines

* rename notifications to events

* move update accounts to state machines

* savepoint

* update client delegate

* Add integration test for expiry

* simplify method

* Fix example wallet build

* Fix example dapp build

* Renamed responder VC to wallet VC

* Revert "Adds Commons and Toolbox packages"

This reverts commit 8b9ce2b.

* Update swift.yml

* Update swift.yml

* refactor pairing model

* refactor session model

* update gitignore

* savepoint

* add session to pairing topic storage

* Update gitignore

* Update Gemfile.lock

* Update fix gitignore

* Workaround a double precision bug in AnyCodable tests

* Fix AnyCodable double test w/ workaround

* Re-enable app build actions

* Disable app actions test

* Re-enable test wallet build step

* Test build example with xcodebuild

* Fix Xcode version

* Change action command place

* Change xcodebuild params

* Try running with destination param

* Test without specifying the platform

* Try using custom simulator

* Fix Xcode version in path

* Try adding 13.1 runtime

* Test with device type param

* Try listing device types

* Revert version workaround, running generic build

* update session delete params, change propose response body

* Update swift.yml

* remove update pairing metadata method from pairing engine

* Fixed conflict in CI file

* remove subscriber from pairing engine

* fix pairing engine tests

* remove subscriber from session engine

* build session engine tests

* remove wcsubscriber implementation

* Fixes blurry QR code when running on device

* rename notify to emit

* remove duplicated subscriber from walletconnect relayer

* add methods and events params to client's approve method

* Update docs

* fix build

* fix build

* fix crash

* savepoint

* Updated project structure

* Renamed session proposal view & controller

* Formatted some code

* savepoint - namespaces check

* build auth package after protocol change

* savepoint

* remove blockchains from proposal, refactor tests

* compile test target

* fix integration tests

* disable automatic sample apps builds

* Add empty namespace test cases

* Add remaining request authorization tests

* Fixed implementation to comply with test cases

* Refactored request stubbing on tests

* Declared namespace members as public

* Fixed example wallet build

* Fixed dapp build

* Re-enable app build workflows

* Fixed integration tests

* savepoint

* savepoint

* Approve with proposal id

* fix wallet build

* remove duplicated client delegate extension method

* Add SwiftUI previews extension for UIKit views

* Add previews for session proposal and details

* Add preview to request view

* SwiftUI experiment with proposal view

* Redesigned view to show namespaces data

* Moved Proposal type to another file

* Using async image to load icon

* Refactored proposal view controller

* Refactor proposal view code

* savepoint

* add new publish method to relayer

* Adds Relayer async publish method

* savepoint

* fix fing integration tests

* distinguish three separate wc relaying reguest methods:
-request
-requestNetworkAck
-requestPeerResponse

* Rename WalletConnectRelay to NetworkingInteractor

* refactor networking interactor async method

* refactor client's disconnect method to be async

* turn off dispatching retry
fix example apps after client interface changes

* fix tests

* Small tweaks to example wallet

* fix wallet to not operate on mocked data

* build package with starscream
delete urlsession

* fix relay client tests
remove unused classes

* add logs, integration tests wait clients connected

* fix example apps

* add socket connection status

* add diddisconnect delegate method

* fix unit tsts

* Fix integration tests issue

* fix delete session issue when no internet connection

* Fix tests

* Update project structure

* Removed optional from event chainId

* Removed optional from request chainId

* Fixed integration test case

* remove unused code

* savepoint

* add pair method engine actor

* update client's connect to async

* Added validation checks for empty namespaces

* Fixed build

* savepoint

* fix client's connect method, uncomment integration tests

* restructure project

* add Concurrency to emit method

* savepoint

* fix dapp build

* fix deeplinking

* remove commented code

* clean up

* Add split namespaces

* Changed proposal schema with required namespaces

* Change client API to use namespace dict for approval

* Remove update accounts method

* Updated wc methods signatures

* Fixed test build

* Removed update accounts commented code

* Changed update call to new specs

* Disable CI app build

* rename WalletConnectClient to AuthClient

* Rename Relayer to Relay Client

* rename auth and relay packages

* Fix package issues after renaming

* Add validation test cases

* Implemented namespace validation

* Removed previous namespace code

* Removed previous namespace code

* Added peer validation matching test cases

* Implemented namespace peer validation

* Added approver side namespace checks

* Added proposer side namespace checks on approval

* Removed leftover unnecessary check

* remove code examples

* add Concurrency to extend and update functions

* fix tests, add XCTAssertNoThrowAsync

* Moved namespace validation when proposal is received

* Remove unnecessary todo

* Merge callbacks on proposal response

* map proposed namespaces to session namespaces

* fix wallet build

* remove  session state validating and namespace type

* fix dapp build

* reenable app builds

* fix swift.yml

* fix tests

* Setting proposal to nil after using it on settlement

* tvOS support

* #219 auth wrapper (#222)

* Add Auth singleton

* savepoint

* Add combine publishers

* savepoint

* change build number

* add socket connection status publisher

* fix sample apps builds

* savepoiint

* savepoint

* add Auth to sample dapp

* remove client delegate

* fix dapp with Auth consumption

* subscribe main scheduler

* add all delegate methods to Auth

* Add missing Auth publishers

* restructure project

* Add Auth to the sample wallet

* add connect and disconnect methods to Auth

* fix tests

* adjust style

* remove logger from Auth

* fix build

* #220 Permission validation for requests and events (#221)

* Add permission checks for requests

* Add permission checks for event emissions

* Add tests for basic permission validation

* Fixed permission validation with test cases

* Improve session permission tests

Co-authored-by: André Vants

* remove getAcknowledgedSessions (#228)

* remove getAcknowledgedSessions

* rename method

* fix Auth connect method (#229)

* remove getAcknowledgedSessions

* rename method

* fix connect() bug

* Update namespaces (#230)

* remove getAcknowledgedSessions

* rename method

* fix connect() bug

* update namespaces on controller request

* turn off logger

* [Wallet] Edit session namespaces (#231)

* Edit session namespaces UI

* Update namespace error handling

* Pending requests

* Show SessionRequest Screen

* Reload SessionDetails on request respond

* Unused import removed

* Hot fix dapp personal sign (#234)

use session account for personal_sign request

* #226 Rename Auth package to Sign (#232)

* Renamed package and base directories

* Renamed imports to WalletConnectSign

* Renamed client and delegate

* Renamed Auth type to Sign

* Fixed a log typo

* Removed auth reference from build scheme

Co-authored-by: André Vants

* rename update expiry to extend on Sign publishers (#237)

rename update expiry to extend

Co-authored-by: André Vants <[email protected]>
Co-authored-by: André Vants <[email protected]>
Co-authored-by: Krypto Pank <[email protected]>
Co-authored-by: Artur Guseinov <[email protected]>
  • Loading branch information
5 people authored May 25, 2022
1 parent ed14c2e commit cf4c81b
Show file tree
Hide file tree
Showing 238 changed files with 6,908 additions and 6,426 deletions.
25 changes: 14 additions & 11 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@ on:

jobs:
build:
runs-on: macos-11
runs-on: macos-latest

steps:
- uses: actions/checkout@v2
- uses: maxim-lobanov/setup-xcode@v1
- name: Checkout
uses: actions/checkout@v2

- name: Setup Xcode Version
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '13.1'
xcode-version: '13.2'

# Package builds
- name: Build Package
run: swift build -v
- name: Run tests
run: swift test -v
- name: Test Wallet
working-directory: ./Example
run: fastlane test_wallet
- name: Test Dapp
working-directory: ./Example
run: fastlane test_dapp


# Example app builds
- name: Build Example Wallet
run: xcodebuild -project Example/ExampleApp.xcodeproj -scheme Wallet -sdk iphonesimulator
- name: Build Example Dapp
run: xcodebuild -project Example/ExampleApp.xcodeproj -scheme DApp -sdk iphonesimulator
23 changes: 20 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
.build/

## User settings
xcuserdata/

**/xcshareddata/WorkspaceSettings.xcsettings


# Swift Package Manager
Packages/
Package.pins
Package.resolved
/*.xcodeproj

# Fastlane
*/fastlane/report.xml
*/fastlane/Preview.html
*/fastlane/screenshots/**/*.png
*/fastlane/test_output
*/fastlane/README.md

52 changes: 52 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/WalletConnect.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,48 @@
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "WalletConnectKMS"
BuildableName = "WalletConnectKMS"
BlueprintName = "WalletConnectKMS"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "WalletConnectRelay"
BuildableName = "WalletConnectRelay"
BlueprintName = "WalletConnectRelay"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "WalletConnectSign"
BuildableName = "WalletConnectSign"
BlueprintName = "WalletConnectSign"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
Expand Down Expand Up @@ -134,6 +176,16 @@
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "WalletConnectSignTests"
BuildableName = "WalletConnectSignTests"
BlueprintName = "WalletConnectSignTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
26 changes: 16 additions & 10 deletions Example/DApp/ Accounts/AccountsViewController.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import UIKit
import WalletConnect
import WalletConnectSign

struct AccountDetails {
let chain: String
Expand All @@ -9,7 +9,6 @@ struct AccountDetails {

final class AccountsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

let client = ClientDelegate.shared.client
let session: Session
var accountsDetails: [AccountDetails] = []
var onDisconnect: (()->())?
Expand Down Expand Up @@ -43,19 +42,26 @@ final class AccountsViewController: UIViewController, UITableViewDataSource, UIT
)
accountsView.tableView.dataSource = self
accountsView.tableView.delegate = self
client.logger.setLogging(level: .debug)
session.accounts.forEach { account in
let splits = account.split(separator: ":", omittingEmptySubsequences: false)
guard splits.count == 3 else { return }
let chain = String(splits[0] + ":" + splits[1])
accountsDetails.append(AccountDetails(chain: chain, methods: Array(session.permissions.methods), account: account))
session.namespaces.values.forEach { namespace in
namespace.accounts.forEach { account in
accountsDetails.append(AccountDetails(chain: account.blockchainIdentifier, methods: Array(namespace.methods), account: account.address)) // TODO: Rethink how this info is displayed on example
}
}
}

@objc
private func disconnect() {
client.disconnect(topic: session.topic, reason: Reason(code: 0, message: "disconnect"))
onDisconnect?()
Task {
do {
try await Sign.instance.disconnect(topic: session.topic, reason: Reason(code: 0, message: "disconnect"))
DispatchQueue.main.async { [weak self] in
self?.onDisconnect?()
}
} catch {
print(error)
//show failure alert
}
}
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
Expand Down
22 changes: 15 additions & 7 deletions Example/DApp/AccountRequest/AccountRequestViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import Foundation
import UIKit
import WalletConnect
import WalletConnectSign
import WalletConnectUtils

class AccountRequestViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
private let session: Session
private let client: WalletConnectClient = ClientDelegate.shared.client
private let chainId: String
private let account: String
private let methods = ["eth_sendTransaction", "personal_sign", "eth_signTypedData"]
Expand Down Expand Up @@ -58,9 +57,18 @@ class AccountRequestViewController: UIViewController, UITableViewDelegate, UITab
let requestParams = getRequest(for: method)


let request = Request(topic: session.topic, method: method, params: requestParams, chainId: chainId)
client.request(params: request)
presentConfirmationAlert()
let request = Request(topic: session.topic, method: method, params: requestParams, chainId: Blockchain(chainId)!)
Task {
do {
try await Sign.instance.request(params: request)
DispatchQueue.main.async { [weak self] in
self?.presentConfirmationAlert()
}
} catch {
print(error)
//show failure alert
}
}
}

private func presentConfirmationAlert() {
Expand All @@ -71,12 +79,12 @@ class AccountRequestViewController: UIViewController, UITableViewDelegate, UITab
}

private func getRequest(for method: String) -> AnyCodable {
let account = "0x9b2055d370f73ec7d8a03e965129118dc8f5bf83"
let account = session.namespaces.first!.value.accounts.first!.absoluteString
if method == "eth_sendTransaction" {
let tx = Stub.tx
return AnyCodable(tx)
} else if method == "personal_sign" {
return AnyCodable(["0xdeadbeaf", account])
return AnyCodable(["0x4d7920656d61696c206973206a6f686e40646f652e636f6d202d2031363533333933373535313531", account])
} else if method == "eth_signTypedData" {
return AnyCodable([account, Stub.eth_signTypedData])
}
Expand Down
1 change: 0 additions & 1 deletion Example/DApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ class AppDelegate: UIResponder, UIApplicationDelegate {


}

39 changes: 0 additions & 39 deletions Example/DApp/ClientDelegate.swift

This file was deleted.

2 changes: 1 addition & 1 deletion Example/DApp/Connect/ConnectView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ final class ConnectView: UIView {

let qrCodeView: UIImageView = {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFit
imageView.contentMode = .center
return imageView
}()

Expand Down
27 changes: 15 additions & 12 deletions Example/DApp/Connect/ConnectViewController.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

import Foundation
import UIKit
import WalletConnect
import WalletConnectSign

class ConnectViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
let uriString: String
let activePairings: [Pairing] = ClientDelegate.shared.client.getSettledPairings()
let activePairings: [Pairing] = Sign.instance.getSettledPairings()
let segmentedControl = UISegmentedControl(items: ["Pairings", "New Pairing"])

init(uri: String) {
Expand Down Expand Up @@ -66,7 +66,8 @@ class ConnectViewController: UIViewController, UITableViewDataSource, UITableVie
let data = string.data(using: .ascii)
if let filter = CIFilter(name: "CIQRCodeGenerator") {
filter.setValue(data, forKey: "inputMessage")
if let output = filter.outputImage {
let transform = CGAffineTransform(scaleX: 4, y: 4)
if let output = filter.outputImage?.transformed(by: transform) {
return UIImage(ciImage: output)
}
}
Expand All @@ -75,8 +76,10 @@ class ConnectViewController: UIViewController, UITableViewDataSource, UITableVie

@objc func connectWithExampleWallet() {
let url = URL(string: "https://walletconnect.com/wc?uri=\(uriString)")!
UIApplication.shared.open(url, options: [:]) { [weak self] _ in
self?.dismiss(animated: true, completion: nil)
DispatchQueue.main.async {
UIApplication.shared.open(url, options: [:]) { [weak self] _ in
self?.dismiss(animated: true, completion: nil)
}
}
}

Expand All @@ -92,12 +95,12 @@ class ConnectViewController: UIViewController, UITableViewDataSource, UITableVie

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let pairingTopic = activePairings[indexPath.row].topic
let permissions = Session.Permissions(
blockchains: ["eip155:1", "eip155:137"],
methods: ["eth_sendTransaction", "personal_sign", "eth_signTypedData"],
notifications: []
)
_ = try! ClientDelegate.shared.client.connect(sessionPermissions: permissions, topic: pairingTopic)
connectWithExampleWallet()
let blockchains: Set<Blockchain> = [Blockchain("eip155:1")!, Blockchain("eip155:137")!]
let methods: Set<String> = ["eth_sendTransaction", "personal_sign", "eth_signTypedData"]
let namespaces: [String: ProposalNamespace] = ["eip155": ProposalNamespace(chains: blockchains, methods: methods, events: [], extensions: nil)]
Task {
_ = try await Sign.instance.connect(requiredNamespaces: namespaces, topic: pairingTopic)
connectWithExampleWallet()
}
}
}
4 changes: 2 additions & 2 deletions Example/DApp/ResponseViewController.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import Foundation
import WalletConnect
import WalletConnectSign
import UIKit

class ResponseViewController: UIViewController {
Expand All @@ -24,7 +24,7 @@ class ResponseViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
let record = ClientDelegate.shared.client.getSessionRequestRecord(id: response.result.id)!
let record = Sign.instance.getSessionRequestRecord(id: response.result.id)!
switch response.result {
case .response(let response):
responseView.nameLabel.text = "Received Response\n\(record.request.method)"
Expand Down
Loading

0 comments on commit cf4c81b

Please sign in to comment.