Skip to content

Commit

Permalink
Merge pull request #1114 from WalletConnect/develop
Browse files Browse the repository at this point in the history
1.8.0
  • Loading branch information
llbartekll authored Sep 18, 2023
2 parents 1a07a37 + 97fb8d3 commit 81fa22d
Show file tree
Hide file tree
Showing 103 changed files with 1,803 additions and 707 deletions.
79 changes: 50 additions & 29 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 @@ -147,11 +147,11 @@
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
buildForTesting = "NO"
buildForRunning = "NO"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "WalletConnectChat"
Expand Down
2 changes: 1 addition & 1 deletion Example/IntegrationTests/Auth/Signer/SignerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ class SignerTest: XCTestCase {
func testSignerAddressFromAccount() throws {
let account = Account("eip155:1:0xBAc675C310721717Cd4A37F6cbeA1F081b1C2a07")!

XCTAssertEqual(DIDPKH(account: account).string, "did:pkh:eip155:1:0xBAc675C310721717Cd4A37F6cbeA1F081b1C2a07")
XCTAssertEqual(account.did, "did:pkh:eip155:1:0xBAc675C310721717Cd4A37F6cbeA1F081b1C2a07")
}
}
4 changes: 2 additions & 2 deletions Example/IntegrationTests/Chat/ChatTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ final class ChatTests: XCTestCase {
invitee1 = makeClient(prefix: "🦖 Invitee", account: inviteeAccount)
inviter1 = makeClient(prefix: "🍄 Inviter", account: inviterAccount)

try await invitee1.register(account: inviteeAccount) { message in
try await invitee1.register(account: inviteeAccount, domain: "") { message in
return self.sign(message, privateKey: self.privateKey1)
}
try await inviter1.register(account: inviterAccount) { message in
try await inviter1.register(account: inviterAccount, domain: "") { message in
return self.sign(message, privateKey: self.privateKey2)
}
}
Expand Down
140 changes: 98 additions & 42 deletions Example/IntegrationTests/Push/NotifyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ import WalletConnectSigner

final class NotifyTests: XCTestCase {

var walletPairingClient: PairingClient!
var walletNotifyClientA: NotifyClient!

var walletNotifyClient: NotifyClient!

let gmDappUrl = "https://notify.gm.walletconnect.com/"
let gmDappDomain = "gm.walletconnect.com"

let pk = try! EthereumPrivateKey()

Expand All @@ -39,6 +37,7 @@ final class NotifyTests: XCTestCase {
let relayLogger = ConsoleLogger(prefix: prefix + " [Relay]", loggingLevel: .debug)
let pairingLogger = ConsoleLogger(prefix: prefix + " [Pairing]", loggingLevel: .debug)
let networkingLogger = ConsoleLogger(prefix: prefix + " [Networking]", loggingLevel: .debug)
let kmsLogger = ConsoleLogger(prefix: prefix + " [KMS]", loggingLevel: .debug)

let relayClient = RelayClientFactory.create(
relayHost: InputConfig.relayHost,
Expand All @@ -52,7 +51,8 @@ final class NotifyTests: XCTestCase {
relayClient: relayClient,
logger: networkingLogger,
keychainStorage: keychain,
keyValueStorage: keyValueStorage)
keyValueStorage: keyValueStorage,
kmsLogger: kmsLogger)

let pairingClient = PairingClientFactory.create(
logger: pairingLogger,
Expand All @@ -65,17 +65,15 @@ final class NotifyTests: XCTestCase {
return (pairingClient, networkingClient, keychain, keyValueStorage)
}

func makeWalletClients() {
let prefix = "🦋 Wallet: "
func makeWalletClient(prefix: String = "🦋 Wallet: ") -> NotifyClient {
let (pairingClient, networkingInteractor, keychain, keyValueStorage) = makeClientDependencies(prefix: prefix)
let notifyLogger = ConsoleLogger(prefix: prefix + " [Notify]", loggingLevel: .debug)
walletPairingClient = pairingClient
let pushClient = PushClientFactory.create(projectId: "",
pushHost: "echo.walletconnect.com",
keychainStorage: keychain,
environment: .sandbox)
let keyserverURL = URL(string: "https://keys.walletconnect.com")!
walletNotifyClient = NotifyClientFactory.create(keyserverURL: keyserverURL,
let client = NotifyClientFactory.create(keyserverURL: keyserverURL,
logger: notifyLogger,
keyValueStorage: keyValueStorage,
keychainStorage: keychain,
Expand All @@ -84,51 +82,102 @@ final class NotifyTests: XCTestCase {
pairingRegisterer: pairingClient,
pushClient: pushClient,
crypto: DefaultCryptoProvider())
return client
}

override func setUp() {
makeWalletClients()
walletNotifyClientA = makeWalletClient()
}

func testWalletCreatesSubscription() async {
let expectation = expectation(description: "expects to create notify subscription")
let metadata = AppMetadata(name: "GM Dapp", description: "", url: gmDappUrl, icons: [])

walletNotifyClient.newSubscriptionPublisher
.sink { [unowned self] subscription in
walletNotifyClientA.subscriptionsPublisher
.sink { [unowned self] subscriptions in
guard let subscription = subscriptions.first else {return}
Task(priority: .high) {
try! await walletNotifyClient.deleteSubscription(topic: subscription.topic)
try await walletNotifyClientA.deleteSubscription(topic: subscription.topic)
expectation.fulfill()
}
}.store(in: &publishers)

try! await walletNotifyClient.register(account: account, onSign: sign)
try! await walletNotifyClient.subscribe(metadata: metadata, account: account, onSign: sign)
try! await walletNotifyClientA.register(account: account, domain: gmDappDomain, onSign: sign)
try! await walletNotifyClientA.subscribe(appDomain: gmDappDomain, account: account)

wait(for: [expectation], timeout: InputConfig.defaultTimeout)
}

func testNotifyWatchSubscriptions() async throws {
let expectation = expectation(description: "expects client B to receive subscription created by client A")
expectation.assertForOverFulfill = false

let clientB = makeWalletClient(prefix: "👐🏼 Wallet B: ")
clientB.subscriptionsPublisher.sink { subscriptions in
Task(priority: .high) {
if !subscriptions.isEmpty {
expectation.fulfill()
}
}
}.store(in: &publishers)

try! await walletNotifyClientA.register(account: account, domain: gmDappDomain, onSign: sign)
try! await walletNotifyClientA.subscribe(appDomain: gmDappDomain, account: account)

sleep(1)

try! await clientB.register(account: account, domain: gmDappDomain, onSign: sign)

wait(for: [expectation], timeout: InputConfig.defaultTimeout)
}

func testNotifySubscriptionChanged() async throws {
let expectation = expectation(description: "expects client B to receive subscription after both clients are registered and client A creates one")
expectation.assertForOverFulfill = false

let clientB = makeWalletClient(prefix: "👐🏼 Wallet B: ")
clientB.subscriptionsPublisher.sink { subscriptions in
Task(priority: .high) {
if !subscriptions.isEmpty {
expectation.fulfill()
}
}
}.store(in: &publishers)

try! await walletNotifyClientA.register(account: account, domain: gmDappDomain, onSign: sign)
try! await clientB.register(account: account, domain: gmDappDomain, onSign: sign)

sleep(1)

try! await walletNotifyClientA.subscribe(appDomain: gmDappDomain, account: account)

wait(for: [expectation], timeout: InputConfig.defaultTimeout)
}

func testWalletCreatesAndUpdatesSubscription() async {
let expectation = expectation(description: "expects to create and update notify subscription")
let metadata = AppMetadata(name: "GM Dapp", description: "", url: gmDappUrl, icons: [])
let updateScope: Set<String> = ["alerts"]
try! await walletNotifyClient.register(account: account, onSign: sign)
try! await walletNotifyClient.subscribe(metadata: metadata, account: account, onSign: sign)
walletNotifyClient.newSubscriptionPublisher
.sink { [unowned self] subscription in
Task(priority: .high) {
try! await walletNotifyClient.update(topic: subscription.topic, scope: updateScope)
}
}
.store(in: &publishers)
expectation.assertForOverFulfill = false

try! await walletNotifyClientA.register(account: account, domain: gmDappDomain, onSign: sign)
try! await walletNotifyClientA.subscribe(appDomain: gmDappDomain, account: account)

walletNotifyClient.updateSubscriptionPublisher
.sink { [unowned self] subscription in
var didUpdate = false
walletNotifyClientA.subscriptionsPublisher
.sink { [unowned self] subscriptions in
guard let subscription = subscriptions.first else {return}
let updatedScope = Set(subscription.scope.filter{ $0.value.enabled == true }.keys)
XCTAssertEqual(updatedScope, updateScope)
Task(priority: .high) {
try! await walletNotifyClient.deleteSubscription(topic: subscription.topic)
expectation.fulfill()

if !didUpdate {
didUpdate = true
Task(priority: .high) {
try await walletNotifyClientA.update(topic: subscription.topic, scope: updateScope)
}
}
if updateScope == updatedScope {
Task(priority: .high) {
try await walletNotifyClientA.deleteSubscription(topic: subscription.topic)
expectation.fulfill()
}
}
}.store(in: &publishers)

Expand All @@ -140,31 +189,38 @@ final class NotifyTests: XCTestCase {
let messageExpectation = expectation(description: "receives a notify message")
let notifyMessage = NotifyMessage.stub()

let metadata = AppMetadata(name: "GM Dapp", description: "", url: gmDappUrl, icons: [])
try! await walletNotifyClient.register(account: account, onSign: sign)
try! await walletNotifyClient.subscribe(metadata: metadata, account: account, onSign: sign)
let metadata = AppMetadata(name: "GM Dapp", description: "", url: gmDappDomain, icons: [])

try! await walletNotifyClientA.register(account: account, domain: gmDappDomain, onSign: sign)
try! await walletNotifyClientA.subscribe(appDomain: gmDappDomain, account: account)

walletNotifyClient.newSubscriptionPublisher
.sink { subscription in
var didNotify = false
walletNotifyClientA.subscriptionsPublisher
.sink { subscriptions in
guard let subscription = subscriptions.first else {return}
let notifier = Publisher()
Task(priority: .high) {
try await notifier.notify(topic: subscription.topic, account: subscription.account, message: notifyMessage)
subscribeExpectation.fulfill()
if !didNotify {
didNotify = true
Task(priority: .high) {
try await notifier.notify(topic: subscription.topic, account: subscription.account, message: notifyMessage)
subscribeExpectation.fulfill()
}
}
}.store(in: &publishers)

walletNotifyClient.notifyMessagePublisher
walletNotifyClientA.notifyMessagePublisher
.sink { [unowned self] notifyMessageRecord in
XCTAssertEqual(notifyMessage, notifyMessageRecord.message)

Task(priority: .high) {
try await walletNotifyClient.deleteSubscription(topic: notifyMessageRecord.topic)
try await walletNotifyClientA.deleteSubscription(topic: notifyMessageRecord.topic)
messageExpectation.fulfill()
}
}.store(in: &publishers)

wait(for: [subscribeExpectation, messageExpectation], timeout: InputConfig.defaultTimeout)
}

}


Expand Down
4 changes: 2 additions & 2 deletions Example/PNDecryptionService/NotificationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class NotificationService: UNNotificationServiceExtension {
let ciphertext = bestAttemptContent.userInfo["blob"] as! String
NSLog("Push decryption, topic=%@", topic)
do {
let service = NotifyDecryptionService()
let service = NotifyDecryptionService(groupIdentifier: "group.com.walletconnect.sdk")
let pushMessage = try service.decryptMessage(topic: topic, ciphertext: ciphertext)
bestAttemptContent.title = pushMessage.title
bestAttemptContent.body = pushMessage.body
Expand All @@ -25,7 +25,7 @@ class NotificationService: UNNotificationServiceExtension {
catch {
NSLog("Push decryption, error=%@", error.localizedDescription)
bestAttemptContent.title = ""
bestAttemptContent.body = "content not set"
bestAttemptContent.body = error.localizedDescription
}
contentHandler(bestAttemptContent)
}
Expand Down
4 changes: 2 additions & 2 deletions Example/WalletApp/ApplicationLayer/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UIKit
import Web3Inbox
import Combine
import WalletConnectNotify

@main
final class AppDelegate: UIResponder, UIApplicationDelegate {
Expand Down Expand Up @@ -29,7 +29,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
UserDefaults.standard.set(deviceTokenString.joined(), forKey: "deviceToken")

Task(priority: .high) {
try await Web3Inbox.instance.register(deviceToken: deviceToken)
try await Notify.instance.register(deviceToken: deviceToken)
}
}

Expand Down
16 changes: 8 additions & 8 deletions Example/WalletApp/ApplicationLayer/ConfigurationService.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import WalletConnectNetworking
import WalletConnectNotify
import Web3Wallet
import Web3Inbox

final class ConfigurationService {

Expand All @@ -18,15 +18,15 @@ final class ConfigurationService {

Web3Wallet.configure(metadata: metadata, crypto: DefaultCryptoProvider(), environment: BuildConfiguration.shared.apnsEnvironment)

Web3Inbox.configure(
account: importAccount.account,
bip44: DefaultBIP44Provider(),
config: [.chatEnabled: false, .settingsEnabled: false],
Notify.configure(
groupIdentifier: "group.com.walletconnect.sdk",
environment: BuildConfiguration.shared.apnsEnvironment,
crypto: DefaultCryptoProvider(),
onSign: importAccount.onSign
crypto: DefaultCryptoProvider()
)
Web3Inbox.instance.setLogging(level: .debug)

Notify.instance.setLogging(level: .debug)

Task { try await Notify.instance.register(account: importAccount.account, domain: "com.walletconnect", onSign: importAccount.onSign) }

if let clientId = try? Networking.interactor.getClientId() {
LoggingService.instance.setUpUser(account: importAccount.account.absoluteString, clientId: clientId)
Expand Down
2 changes: 0 additions & 2 deletions Example/WalletApp/ApplicationLayer/ProfilingService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Foundation
import Mixpanel
import WalletConnectNetworking
import Combine
import Web3Inbox

final class ProfilingService {
public static var instance = ProfilingService()
Expand Down Expand Up @@ -32,7 +31,6 @@ final class ProfilingService {
mixpanel.people.set(properties: ["$name": account, "account": account])

handleLogs(from: Networking.instance.logsPublisher)
handleLogs(from: Web3Inbox.instance.logsPublisher)
}

private func handleLogs(from publisher: AnyPublisher<Log, Never>) {
Expand Down
45 changes: 45 additions & 0 deletions Example/WalletApp/BusinessLayer/ListingsSertice/Listings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import Foundation

struct Listing: Codable {
struct ImageURL: Codable {
@FailableDecodable
private(set) var sm: URL?

@FailableDecodable
private(set) var md: URL?

@FailableDecodable
private(set) var lg: URL?
}
struct App: Codable {
@FailableDecodable
private(set) var ios: URL?

@FailableDecodable
private(set) var android: URL?

@FailableDecodable
private(set) var browser: URL?
}
struct Mobile: Codable {
let native: String?
let universal: String?
}
struct Metadata: Codable {
struct Colors: Codable {
let primary: String?
let secondary: String?
}
let shortName: String
let colors: Colors
}
let id: String
let name: String
let description: String
let homepage: String
let image_url: ImageURL
let app: App
let mobile: Mobile
let metadata: Metadata
let chains: [String]
}
Loading

0 comments on commit 81fa22d

Please sign in to comment.