Skip to content

Commit

Permalink
introducing verification method
Browse files Browse the repository at this point in the history
  • Loading branch information
bangtoven committed Feb 27, 2024
1 parent 2cc4c3f commit a5c40ce
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
12 changes: 8 additions & 4 deletions ios/CoinbaseWalletSDK/CoinbaseWalletSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class CoinbaseWalletSDK {

static private var host: URL?
static private var callback: URL?
static private var verificationMethod: VerificationMethod?
static private var verificationMethod: VerificationMethod = .callbackConfirmation
static public var isConfigured: Bool {
return host != nil && callback != nil
}
Expand Down Expand Up @@ -61,14 +61,15 @@ public final class CoinbaseWalletSDK {
preconditionFailure("Missing configuration: call `CoinbaseWalletSDK.configure` before accessing the `shared` instance.")
}

return CoinbaseWalletSDK(host: host, callback: callback)
return CoinbaseWalletSDK(host: host, callback: callback, verificationMethod: verificationMethod)
}()

// MARK: - Properties

private let appId: String
private let host: URL
private let callback: URL
private let verificationMethod: VerificationMethod

private lazy var keyManager: KeyManager = {
KeyManager(host: self.host)
Expand All @@ -79,10 +80,12 @@ public final class CoinbaseWalletSDK {

private init(
host: URL,
callback: URL
callback: URL,
verificationMethod: VerificationMethod
) {
self.host = host
self.callback = callback
self.verificationMethod = verificationMethod

self.appId = Bundle.main.bundleIdentifier!
}
Expand All @@ -102,7 +105,7 @@ public final class CoinbaseWalletSDK {
return unsupportedHandShakeMethod.contains(where: {action.method == $0 })
})

guard hasUnsupportedAction != true else {
guard !(CoinbaseWalletSDK.verificationMethod == .callbackConfirmation && hasUnsupportedAction == true) else {
onResponse(.failure(Error.invalidHandshakeRequest), nil)
return
}
Expand All @@ -114,6 +117,7 @@ public final class CoinbaseWalletSDK {
content: .handshake(
appId: appId,
callback: callback,
verificationMethod: verificationMethod,
initialActions: initialActions
),
version: CoinbaseWalletSDK.version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import CryptoKit

@available(iOS 13.0, *)
public enum EncryptedRequestContent: EncryptedContent {
case handshake(appId: String, callback: URL, initialActions: [Action]?)
case handshake(appId: String, callback: URL, verificationMethod: VerificationMethod, initialActions: [Action]?)
case request(data: Data)

public func decrypt(with symmetricKey: SymmetricKey?) throws -> RequestContent {
switch self {
case let .handshake(appId, callback, initialActions):
return .handshake(appId: appId, callback: callback, initialActions: initialActions)
case let .handshake(appId, callback, verificationMethod, initialActions):
return .handshake(appId: appId, callback: callback, verificationMethod: verificationMethod, initialActions: initialActions)
case let .request(data):
guard let symmetricKey = symmetricKey else {
throw CoinbaseWalletSDK.Error.missingSymmetricKey
Expand All @@ -31,8 +31,8 @@ public enum EncryptedRequestContent: EncryptedContent {
extension RequestContent {
public func encrypt(with symmetricKey: SymmetricKey?) throws -> EncryptedRequestContent {
switch self {
case let .handshake(appId, callback, initialActions):
return .handshake(appId: appId, callback: callback, initialActions: initialActions)
case let .handshake(appId, callback, verificationMethod, initialActions):
return .handshake(appId: appId, callback: callback, verificationMethod: verificationMethod, initialActions: initialActions)
case let .request(actions, account):
guard let symmetricKey = symmetricKey else {
throw CoinbaseWalletSDK.Error.missingSymmetricKey
Expand Down
2 changes: 1 addition & 1 deletion ios/CoinbaseWalletSDK/Message/Request/RequestMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

@available(iOS 13.0, *)
public enum RequestContent: UnencryptedContent {
case handshake(appId: String, callback: URL, initialActions: [Action]?)
case handshake(appId: String, callback: URL, verificationMethod: VerificationMethod, initialActions: [Action]?)
case request(actions: [Action], account: Account? = nil)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/// domain ownership verification
public enum VerificationMethod {
public enum VerificationMethod: Equatable, Codable {
case callbackConfirmation
/// Advanced configuration with public key-based domain ownership verification.
case publicKeyVerification(message: String, signature: String, publicKeySubpath: String?)
Expand Down
2 changes: 1 addition & 1 deletion ios/example/SampleWallet/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extension AppDelegate: UIAlertViewDelegate {
guard let request: RequestMessage = try? CoinbaseWalletHostSDK.decode(url, with: symmetricKey) else { return }

self.requestMessage = request
if case .handshake(_, let callback, _) = request.content {
if case .handshake(_, let callback, _, _) = request.content {
self.peerCallback = callback
}

Expand Down

0 comments on commit a5c40ce

Please sign in to comment.