Skip to content

Commit

Permalink
Merge pull request #1277 from WalletConnect/develop
Browse files Browse the repository at this point in the history
1.11.0
  • Loading branch information
llbartekll authored Jan 16, 2024
2 parents 031c61b + 42ab7ce commit 232090b
Show file tree
Hide file tree
Showing 29 changed files with 172 additions and 84 deletions.
10 changes: 10 additions & 0 deletions Example/DApp/DApp.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.walletconnect.dapp</string>
</array>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Example/DApp/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
Networking.configure(
groupIdentifier: "group.com.walletconnect.sdk",
groupIdentifier: "group.com.walletconnect.dapp",
projectId: InputConfig.projectId,
socketFactory: DefaultSocketFactory()
)
Expand Down
4 changes: 4 additions & 0 deletions Example/ExampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@
84CE6453279FFE1100142511 /* Wallet.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Wallet.entitlements; sourceTree = "<group>"; };
84CEC64528D89D6B00D081A8 /* PairingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PairingTests.swift; sourceTree = "<group>"; };
84D2A66528A4F51E0088AE09 /* AuthTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthTests.swift; sourceTree = "<group>"; };
84D72FC62B4692770057EAF3 /* DApp.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DApp.entitlements; sourceTree = "<group>"; };
84DB38F029828A7C00BFEE37 /* WalletApp.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = WalletApp.entitlements; sourceTree = "<group>"; };
84DB38F129828A7F00BFEE37 /* PNDecryptionService.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = PNDecryptionService.entitlements; sourceTree = "<group>"; };
84DB38F22983CDAE00BFEE37 /* PushRegisterer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PushRegisterer.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -972,6 +973,7 @@
84CE641D27981DED00142511 /* DApp */ = {
isa = PBXGroup;
children = (
84D72FC62B4692770057EAF3 /* DApp.entitlements */,
C5BE01E02AF692F80064FC88 /* ApplicationLayer */,
C5BE02202AF7DDE70064FC88 /* Modules */,
A5BB7FAB28B6AA7100707FC6 /* Common */,
Expand Down Expand Up @@ -2860,6 +2862,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
CODE_SIGN_ENTITLEMENTS = DApp/DApp.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 18;
Expand Down Expand Up @@ -2895,6 +2898,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
CODE_SIGN_ENTITLEMENTS = DApp/DApp.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 18;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "VerifyTests"
BuildableName = "VerifyTests"
BlueprintName = "VerifyTests"
ReferencedContainer = "container:..">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
7 changes: 3 additions & 4 deletions Example/IntegrationTests/Push/NotifyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,12 @@ final class NotifyTests: XCTestCase {
await fulfillment(of: [created], timeout: InputConfig.defaultTimeout)
let updateScope = Set([subscription.scope.keys.first!])
try await walletNotifyClientA.update(topic: subscription.topic, scope: updateScope)
try await walletNotifyClientA.update(topic: subscription.topic, scope: [])
await fulfillment(of: [updated], timeout: InputConfig.defaultTimeout)
let updatedScope = Set(subscription.scope.filter { $0.value.enabled == true }.keys)
XCTAssertEqual(updatedScope, updateScope)
let updatedScope = subscription.scope.filter { $0.value.enabled == true }
XCTAssertTrue(updatedScope.isEmpty)
try await walletNotifyClientA.deleteSubscription(topic: subscription.topic)
}
Expand Down
1 change: 1 addition & 0 deletions Example/PNDecryptionService/NotificationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ private extension NotificationService {
Mixpanel.mainInstance().track(
event: "💬 APNS: " + event,
properties: [
"message_id": message?.id,
"title": message?.title,
"body": message?.body,
"icon": message?.icon,
Expand Down
3 changes: 1 addition & 2 deletions Example/RelayIntegrationTests/RelayClientEndToEndTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ final class RelayClientEndToEndTests: XCTestCase {
let logger = ConsoleLogger(prefix: prefix, loggingLevel: .debug)
let clientIdStorage = ClientIdStorage(defaults: keyValueStorage, keychain: KeychainStorageMock(), logger: logger)
let socketAuthenticator = ClientIdAuthenticator(
clientIdStorage: clientIdStorage,
url: InputConfig.relayUrl
clientIdStorage: clientIdStorage
)
let urlFactory = RelayUrlFactory(
relayHost: InputConfig.relayHost,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct NotifyPreferencesView: View {
Toggle(isOn: .init(get: {
viewModel.update[title]?.enabled ?? value.enabled
}, set: { newValue in
viewModel.update[title] = ScopeValue(id: value.id, name: value.name, description: value.description, enabled: newValue)
viewModel.update[title] = ScopeValue(id: value.id, name: value.name, description: value.description, imageUrls: value.imageUrls, enabled: newValue)
})) {
VStack(alignment: .leading, spacing: 4) {
Text(value.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,24 @@ struct SubscriptionView: View {
.padding(.top, 56.0)
.padding(.bottom, 8.0)

Text(presenter.subscriptionViewModel.name)
.font(.large700)
.foregroundColor(.Foreground100)
.padding(.bottom, 8.0)

Text(presenter.subscriptionViewModel.domain)
.font(.system(size: 12, weight: .medium))
.foregroundColor(.Foreground200)
.padding(.bottom, 16.0)

Text(presenter.subscriptionViewModel.description)
.font(.system(size: 14, weight: .regular))
.foregroundColor(.Foreground100)
.padding(.bottom, 16.0)
Group {
Text(presenter.subscriptionViewModel.name)
.font(.large700)
.foregroundColor(.Foreground100)
.padding(.bottom, 8.0)

Text(presenter.subscriptionViewModel.domain)
.font(.system(size: 12, weight: .medium))
.foregroundColor(.Foreground200)
.padding(.bottom, 16.0)

Text(presenter.subscriptionViewModel.description)
.font(.system(size: 14, weight: .regular))
.foregroundColor(.Foreground100)
.padding(.bottom, 16.0)
}
.padding(.horizontal, 20)
.multilineTextAlignment(.center)

Menu {
Button(role: .destructive, action: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class SessionProposalInteractor {

let supportedRequiredChains = proposal.requiredNamespaces["eip155"]?.chains
let supportedOptionalChains = proposal.optionalNamespaces?["eip155"]?.chains ?? []
let supportedChains = supportedRequiredChains?.union(supportedOptionalChains) ?? []
let supportedChains = (supportedRequiredChains ?? []).union(supportedOptionalChains) ?? []

let supportedAccounts = Array(supportedChains).map { Account(blockchain: $0, address: account.address)! }

Expand Down
8 changes: 6 additions & 2 deletions Sources/Database/SQLiteQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation

public struct SqliteQuery {

public static func replace(table: String, rows: [SqliteRow]) throws -> String {
public static func replace(table: String, rows: [SqliteRow]) -> String? {
var values: [String] = []

for row in rows {
Expand All @@ -12,7 +12,7 @@ public struct SqliteQuery {
}

guard let first = rows.first else {
throw Errors.rowsNotFound
return nil
}

let formattedArguments = first.encode().values
Expand All @@ -37,6 +37,10 @@ public struct SqliteQuery {
return "SELECT * FROM \(table) WHERE \(argument) = '\(value)';"
}

public static func delete(table: String) -> String {
return "DELETE FROM \(table);"
}

public static func delete(table: String, where argument: String, equals value: String) -> String {
return "DELETE FROM \(table) WHERE \(argument) = '\(value)';"
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/WalletConnectHistory/HistoryNetworkService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ private extension HistoryNetworkService {
}

func getJwt(historyUrl: String) throws -> String {
let authenticator = ClientIdAuthenticator(clientIdStorage: clientIdStorage, url: historyUrl)
return try authenticator.createAuthToken()
let authenticator = ClientIdAuthenticator(clientIdStorage: clientIdStorage)
return try authenticator.createAuthToken(url: historyUrl)
}

func host(from url: String) throws -> String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public struct NotifyClientFactory {
let keyserverURL = URL(string: "https://keys.walletconnect.com")!
let keychainStorage = KeychainStorage(serviceIdentifier: "com.walletconnect.sdk", accessGroup: groupIdentifier)
let groupKeychainService = GroupKeychainStorage(serviceIdentifier: groupIdentifier)
let databasePath = databasePath(appGroup: groupIdentifier, database: "notify.db")
let databasePath = databasePath(appGroup: groupIdentifier, database: "notify_v\(version).db")
let sqlite = DiskSqlite(path: databasePath)

return NotifyClientFactory.create(
Expand Down Expand Up @@ -102,4 +102,8 @@ public struct NotifyClientFactory {

return path.absoluteString
}

static var version: String {
return "1"
}
}
8 changes: 2 additions & 6 deletions Sources/WalletConnectNotify/Client/Wallet/NotifyConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@ struct NotifyConfig: Codable {
let id: String
let name: String
let description: String
}
struct ImageUrl: Codable {
let sm: String?
let md: String?
let lg: String?
let imageUrls: NotifyImageUrls?
}
let id: String
let name: String
let homepage: String?
let description: String
let dapp_url: String
let image_url: ImageUrl?
let image_url: NotifyImageUrls?
let notificationTypes: [NotificationType]

var appDomain: String {
Expand Down
17 changes: 13 additions & 4 deletions Sources/WalletConnectNotify/Client/Wallet/NotifyDatabase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,19 @@ final class NotifyDatabase {
}

func save(subscriptions: [NotifySubscription]) throws {
let sql = try SqliteQuery.replace(table: Table.subscriptions, rows: subscriptions)
guard let sql = SqliteQuery.replace(table: Table.subscriptions, rows: subscriptions) else { return }
try execute(sql: sql)
try onSubscriptionsUpdate?()
}

func replace(subscriptions: [NotifySubscription]) throws {
try execute(sql: SqliteQuery.delete(table: Table.subscriptions))
if let sql = SqliteQuery.replace(table: Table.subscriptions, rows: subscriptions) {
try execute(sql: sql)
}
try onSubscriptionsUpdate?()
}

func getSubscription(topic: String) -> NotifySubscription? {
let sql = SqliteQuery.select(table: Table.subscriptions, where: "topic", equals: topic)
let subscriptions: [NotifySubscription]? = try? query(sql: sql)
Expand Down Expand Up @@ -95,7 +103,7 @@ final class NotifyDatabase {
}

func save(messages: [NotifyMessageRecord]) throws {
let sql = try SqliteQuery.replace(table: Table.messages, rows: messages)
guard let sql = SqliteQuery.replace(table: Table.messages, rows: messages) else { return }
try execute(sql: sql)
try onMessagesUpdate?()
}
Expand All @@ -110,14 +118,15 @@ private extension NotifyDatabase {

try sqlite.execute(sql: """
CREATE TABLE IF NOT EXISTS \(Table.subscriptions) (
topic TEXT PRIMARY KEY,
topic TEXT NOT NULL,
account TEXT NOT NULL,
relay TEXT NOT NULL,
metadata TEXT NOT NULL,
scope TEXT NOT NULL,
expiry TEXT NOT NULL,
symKey TEXT NOT NULL,
appAuthenticationKey TEXT NOT NULL
appAuthenticationKey TEXT NOT NULL,
id TEXT PRIMARY KEY
);
""")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Foundation

public struct NotifyImageUrls: Codable, Equatable {
public let sm: String?
public let md: String?
public let lg: String?
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ final class NotifyStorage: NotifyStoring {
}

func replaceAllSubscriptions(_ subscriptions: [NotifySubscription]) throws {
try database.save(subscriptions: subscriptions)
try database.replace(subscriptions: subscriptions)
}

func deleteSubscription(topic: String) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class NotifySubscriptionsBuilder {
$0[$1.id] = ScopeValue(
id: $1.id,
name: $1.name,
description: $1.description,
description: $1.description,
imageUrls: $1.imageUrls,
enabled: selectedScope.contains($1.id)
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import Database

public struct NotifySubscription: DatabaseObject, SqliteRow {
public struct NotifySubscription: Codable, Equatable, SqliteRow {
public let topic: String
public let account: Account
public let relay: RelayProtocolOptions
Expand All @@ -11,8 +11,8 @@ public struct NotifySubscription: DatabaseObject, SqliteRow {
public let symKey: String
public let appAuthenticationKey: String

public var databaseId: String {
return topic
private var id: String {
return "\(account.absoluteString)-\(metadata.url)"
}

public init(decoder: SqliteRowDecoder) throws {
Expand All @@ -36,6 +36,7 @@ public struct NotifySubscription: DatabaseObject, SqliteRow {
encoder.encodeDate(expiry, for: "expiry")
encoder.encodeString(symKey, for: "symKey")
encoder.encodeString(appAuthenticationKey, for: "appAuthenticationKey")
encoder.encodeString(id, for: "id")
return encoder
}

Expand Down Expand Up @@ -66,12 +67,14 @@ public struct ScopeValue: Codable, Equatable {
public let id: String
public let name: String
public let description: String
public let imageUrls: NotifyImageUrls?
public let enabled: Bool

public init(id: String, name: String, description: String, enabled: Bool) {
public init(id: String, name: String, description: String, imageUrls: NotifyImageUrls?, enabled: Bool) {
self.id = id
self.name = name
self.description = description
self.imageUrls = imageUrls
self.enabled = enabled
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import Foundation

public protocol ClientIdAuthenticating {
func createAuthToken(url: String?) throws -> String
func createAuthToken(url: String) throws -> String
}

public final class ClientIdAuthenticator: ClientIdAuthenticating {
private let clientIdStorage: ClientIdStoring
private var url: String

public init(clientIdStorage: ClientIdStoring, url: String) {
public init(clientIdStorage: ClientIdStoring) {
self.clientIdStorage = clientIdStorage
self.url = url
}

public func createAuthToken(url: String? = nil) throws -> String {
url.flatMap { self.url = $0 }

public func createAuthToken(url: String) throws -> String {
let keyPair = try clientIdStorage.getOrCreateKeyPair()
let payload = RelayAuthPayload(subject: getSubject(), audience: self.url)
let payload = RelayAuthPayload(subject: getSubject(), audience: url)
return try payload.signAndCreateWrapper(keyPair: keyPair).jwtString
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/WalletConnectRelay/PackageConfig.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version": "1.10.0"}
{"version": "1.11.0"}
3 changes: 1 addition & 2 deletions Sources/WalletConnectRelay/RelayClientFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public struct RelayClientFactory {
let clientIdStorage = ClientIdStorage(defaults: keyValueStorage, keychain: keychainStorage, logger: logger)

let socketAuthenticator = ClientIdAuthenticator(
clientIdStorage: clientIdStorage,
url: "wss://\(relayHost)"
clientIdStorage: clientIdStorage
)
let relayUrlFactory = RelayUrlFactory(
relayHost: relayHost,
Expand Down
Loading

0 comments on commit 232090b

Please sign in to comment.