Skip to content

Commit

Permalink
Remove opt-in/out flag for VerifyAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-lsvk committed Jul 6, 2023
1 parent e56f00a commit 7dfdce0
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ struct ThirdPartyConfigurator: Configurator {
name: "Example Wallet",
description: "wallet description",
url: "example.wallet",
icons: ["https://avatars.githubusercontent.com/u/37784886"],
verifyUrl: "verify.walletconnect.com"
icons: ["https://avatars.githubusercontent.com/u/37784886"]
)

Web3Wallet.configure(metadata: metadata, crypto: DefaultCryptoProvider(), environment: BuildConfiguration.shared.apnsEnvironment)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Auth/AuthClientFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public struct AuthClientFactory {
let history = RPCHistoryFactory.createForNetwork(keyValueStorage: keyValueStorage)
let messageFormatter = SIWECacaoFormatter()
let appRequestService = AppRequestService(networkingInteractor: networkingClient, kms: kms, appMetadata: metadata, logger: logger, iatProvader: iatProvider)
let verifyClient = try? VerifyClientFactory.create(verifyHost: metadata.verifyUrl)
let verifyClient = VerifyClientFactory.create()
let messageVerifierFactory = MessageVerifierFactory(crypto: crypto)
let signatureVerifier = messageVerifierFactory.create(projectId: projectId)
let appRespondSubscriber = AppRespondSubscriber(networkingInteractor: networkingClient, logger: logger, rpcHistory: history, signatureVerifier: signatureVerifier, pairingRegisterer: pairingRegisterer, messageFormatter: messageFormatter)
Expand Down
25 changes: 13 additions & 12 deletions Sources/Auth/Services/Wallet/WalletRequestSubscriber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class WalletRequestSubscriber {
private var publishers = [AnyCancellable]()
private let walletErrorResponder: WalletErrorResponder
private let pairingRegisterer: PairingRegisterer
private let verifyClient: VerifyClient?
private let verifyClient: VerifyClient
var onRequest: (((request: AuthRequest, context: VerifyContext?)) -> Void)?

init(
Expand All @@ -17,7 +17,7 @@ class WalletRequestSubscriber {
kms: KeyManagementServiceProtocol,
walletErrorResponder: WalletErrorResponder,
pairingRegisterer: PairingRegisterer,
verifyClient: VerifyClient?
verifyClient: VerifyClient
) {
self.networkingInteractor = networkingInteractor
self.logger = logger
Expand All @@ -40,18 +40,19 @@ class WalletRequestSubscriber {

let request = AuthRequest(id: payload.id, topic: payload.topic, payload: payload.request.payloadParams)

guard let verifyClient else {
onRequest?((request, nil))
return
}
Task(priority: .high) {
let assertionId = payload.decryptedPayload.sha256().toHexString()
let origin = try? await verifyClient.verifyOrigin(assertionId: assertionId)
let verifyContext = await verifyClient.createVerifyContext(
origin: origin,
domain: payload.request.payloadParams.domain
)
onRequest?((request, verifyContext))
do {
let origin = try await verifyClient.verifyOrigin(assertionId: assertionId)
let verifyContext = await verifyClient.createVerifyContext(
origin: origin,
domain: payload.request.payloadParams.domain
)
onRequest?((request, verifyContext))
} catch {
onRequest?((request, nil))
return
}
}
}.store(in: &publishers)
}
Expand Down
6 changes: 0 additions & 6 deletions Sources/WalletConnectPairing/Types/AppMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ public struct AppMetadata: Codable, Equatable {

/// An array of URL strings pointing to the icon assets on the web.
public let icons: [String]

/// The URL which used by VerifyClient.
public let verifyUrl: String?

/// Redirect links which could be manually used on wallet side.
public let redirect: Redirect?
Expand All @@ -57,22 +54,19 @@ public struct AppMetadata: Codable, Equatable {
- description: A brief textual description of the app that can be displayed to peers.
- url: The URL string that identifies the official domain of the app.
- icons: An array of URL strings pointing to the icon assets on the web.
- verifyUrl: The URL which used by VerifyClient.
- redirect: Redirect links which could be manually used on wallet side.
*/
public init(
name: String,
description: String,
url: String,
icons: [String],
verifyUrl: String? = nil,
redirect: Redirect? = nil
) {
self.name = name
self.description = description
self.url = url
self.icons = icons
self.verifyUrl = verifyUrl
self.redirect = redirect
}
}
25 changes: 13 additions & 12 deletions Sources/WalletConnectSign/Engine/Common/ApproveEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class ApproveEngine {
private let networkingInteractor: NetworkInteracting
private let pairingStore: WCPairingStorage
private let sessionStore: WCSessionStorage
private let verifyClient: VerifyClient?
private let verifyClient: VerifyClient
private let proposalPayloadsStore: CodableStore<RequestSubscriptionPayload<SessionType.ProposeParams>>
private let sessionTopicToProposal: CodableStore<Session.Proposal>
private let pairingRegisterer: PairingRegisterer
Expand All @@ -38,7 +38,7 @@ final class ApproveEngine {
logger: ConsoleLogging,
pairingStore: WCPairingStorage,
sessionStore: WCSessionStorage,
verifyClient: VerifyClient?
verifyClient: VerifyClient
) {
self.networkingInteractor = networkingInteractor
self.proposalPayloadsStore = proposalPayloadsStore
Expand Down Expand Up @@ -293,18 +293,19 @@ private extension ApproveEngine {
}
proposalPayloadsStore.set(payload, forKey: proposal.proposer.publicKey)

guard let verifyClient else {
onSessionProposal?(proposal.publicRepresentation(pairingTopic: payload.topic), nil)
return
}
Task(priority: .high) {
let assertionId = payload.decryptedPayload.sha256().toHexString()
let origin = try? await verifyClient.verifyOrigin(assertionId: assertionId)
let verifyContext = await verifyClient.createVerifyContext(
origin: origin,
domain: payload.request.proposer.metadata.url
)
onSessionProposal?(proposal.publicRepresentation(pairingTopic: payload.topic), verifyContext)
do {
let origin = try await verifyClient.verifyOrigin(assertionId: assertionId)
let verifyContext = await verifyClient.createVerifyContext(
origin: origin,
domain: payload.request.proposer.metadata.url
)
onSessionProposal?(proposal.publicRepresentation(pairingTopic: payload.topic), verifyContext)
} catch {
onSessionProposal?(proposal.publicRepresentation(pairingTopic: payload.topic), nil)
return
}
}
}

Expand Down
25 changes: 13 additions & 12 deletions Sources/WalletConnectSign/Engine/Common/SessionEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ final class SessionEngine {
private let sessionStore: WCSessionStorage
private let networkingInteractor: NetworkInteracting
private let historyService: HistoryService
private let verifyClient: VerifyClient?
private let verifyClient: VerifyClient
private let kms: KeyManagementServiceProtocol
private var publishers = [AnyCancellable]()
private let logger: ConsoleLogging

init(
networkingInteractor: NetworkInteracting,
historyService: HistoryService,
verifyClient: VerifyClient?,
verifyClient: VerifyClient,
kms: KeyManagementServiceProtocol,
sessionStore: WCSessionStorage,
logger: ConsoleLogging
Expand Down Expand Up @@ -238,18 +238,19 @@ private extension SessionEngine {
guard !request.isExpired() else {
return respondError(payload: payload, reason: .sessionRequestExpired, protocolMethod: protocolMethod)
}
guard let verifyClient else {
onSessionRequest?(request, nil)
return
}
Task(priority: .high) {
let assertionId = payload.decryptedPayload.sha256().toHexString()
let origin = try? await verifyClient.verifyOrigin(assertionId: assertionId)
let verifyContext = await verifyClient.createVerifyContext(
origin: origin,
domain: session.peerParticipant.metadata.url
)
onSessionRequest?(request, verifyContext)
do {
let origin = try await verifyClient.verifyOrigin(assertionId: assertionId)
let verifyContext = await verifyClient.createVerifyContext(
origin: origin,
domain: session.peerParticipant.metadata.url
)
onSessionRequest?(request, verifyContext)
} catch {
onSessionRequest?(request, nil)
return
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/WalletConnectSign/Sign/SignClientFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public struct SignClientFactory {
let sessionStore = SessionStorage(storage: SequenceStore<WCSession>(store: .init(defaults: keyValueStorage, identifier: SignStorageIdentifiers.sessions.rawValue)))
let proposalPayloadsStore = CodableStore<RequestSubscriptionPayload<SessionType.ProposeParams>>(defaults: RuntimeKeyValueStorage(), identifier: SignStorageIdentifiers.proposals.rawValue)
let historyService = HistoryService(history: rpcHistory)
let verifyClient = try? VerifyClientFactory.create(verifyHost: metadata.verifyUrl)
let verifyClient = VerifyClientFactory.create()
let sessionEngine = SessionEngine(networkingInteractor: networkingClient, historyService: historyService, verifyClient: verifyClient, kms: kms, sessionStore: sessionStore, logger: logger)
let nonControllerSessionStateMachine = NonControllerSessionStateMachine(networkingInteractor: networkingClient, kms: kms, sessionStore: sessionStore, logger: logger)
let controllerSessionStateMachine = ControllerSessionStateMachine(networkingInteractor: networkingClient, kms: kms, sessionStore: sessionStore, logger: logger)
Expand Down
2 changes: 1 addition & 1 deletion Sources/WalletConnectVerify/VerifyClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public actor VerifyClient {
originVerifier: OriginVerifier,
assertionRegistrer: AssertionRegistrer,
appAttestationRegistrer: AppAttestationRegistrer
) throws {
) {
self.verifyHost = verifyHost
self.originVerifier = originVerifier
self.assertionRegistrer = assertionRegistrer
Expand Down
7 changes: 2 additions & 5 deletions Sources/WalletConnectVerify/VerifyClientFactory.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import Foundation

public class VerifyClientFactory {
public static func create(verifyHost: String?) throws -> VerifyClient? {
guard let verifyHost else {
return nil
}
public static func create(verifyHost: String = "verify.walletconnect.com") -> VerifyClient {
let originVerifier = OriginVerifier(verifyHost: verifyHost)
let assertionRegistrer = AssertionRegistrer()
let logger = ConsoleLogger(loggingLevel: .off)
Expand All @@ -20,7 +17,7 @@ public class VerifyClientFactory {
attestChallengeProvider: attestChallengeProvider,
keyAttestationService: keyAttestationService
)
return try VerifyClient(
return VerifyClient(
verifyHost: verifyHost,
originVerifier: originVerifier,
assertionRegistrer: assertionRegistrer,
Expand Down

0 comments on commit 7dfdce0

Please sign in to comment.