Skip to content

Commit

Permalink
update verify context creation
Browse files Browse the repository at this point in the history
  • Loading branch information
llbartekll committed Jul 24, 2024
1 parent 7d8c2f4 commit 572591d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class ApproveSessionAuthenticateUtil {
private let logger: ConsoleLogging
private let sessionStore: WCSessionStorage
private let sessionNamespaceBuilder: SessionNamespaceBuilder
private let verifyContextStore: CodableStore<VerifyContext>
private let verifyClient: VerifyClientProtocol

init(
logger: ConsoleLogging,
Expand All @@ -23,7 +25,9 @@ class ApproveSessionAuthenticateUtil {
messageFormatter: SIWEFromCacaoFormatting,
sessionStore: WCSessionStorage,
sessionNamespaceBuilder: SessionNamespaceBuilder,
networkingInteractor: NetworkInteracting
networkingInteractor: NetworkInteracting,
verifyContextStore: CodableStore<VerifyContext>,
verifyClient: VerifyClientProtocol
) {
self.logger = logger
self.kms = kms
Expand All @@ -33,6 +37,8 @@ class ApproveSessionAuthenticateUtil {
self.signatureVerifier = signatureVerifier
self.messageFormatter = messageFormatter
self.networkingInteractor = networkingInteractor
self.verifyContextStore = verifyContextStore
self.verifyClient = verifyClient
}

func getsessionAuthenticateRequestParams(requestId: RPCID) throws -> (request: SessionAuthenticateRequestParams, topic: String) {
Expand Down Expand Up @@ -60,7 +66,6 @@ class ApproveSessionAuthenticateUtil {
return (topic, keys)
}


func createSession(
response: SessionAuthenticateResponseParams,
pairingTopic: String,
Expand Down Expand Up @@ -116,6 +121,12 @@ class ApproveSessionAuthenticateUtil {
return session.publicRepresentation()
}


func getVerifyContext(requestId: RPCID, domain: String) -> VerifyContext {
(try? verifyContextStore.get(key: requestId.string)) ?? verifyClient.createVerifyContext(origin: nil, domain: domain, isScam: false)
}


func recoverAndVerifySignature(cacaos: [Cacao]) async throws {
try await cacaos.asyncForEach { [unowned self] cacao in
guard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,13 @@ actor LinkSessionAuthenticateResponder {

let url = try await linkEnvelopesDispatcher.respond(topic: responseTopic, response: response, peerUniversalLink: peerUniversalLink, envelopeType: .type1(pubKey: responseKeys.publicKey.rawRepresentation))

let verifyContext = (try? verifyContextStore.get(key: requestId.string)) ?? VerifyContext(origin: nil, validation: .unknown)

let session = try util.createSession(
response: responseParams,
pairingTopic: pairingTopic,
request: sessionAuthenticateRequestParams,
sessionTopic: sessionTopic,
transportType: .linkMode,
verifyContext: verifyContext
verifyContext: util.getVerifyContext(requestId: requestId, domain: sessionAuthenticateRequestParams.requester.metadata.url)
)

verifyContextStore.delete(forKey: requestId.string)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,13 @@ actor SessionAuthenticateResponder {
}

do {
let verifyContext = (try? verifyContextStore.get(key: requestId.string)) ?? VerifyContext(origin: nil, validation: .unknown)
let session = try util.createSession(
response: responseParams,
pairingTopic: pairingTopic,
request: sessionAuthenticateRequestParams,
sessionTopic: sessionTopic,
transportType: .relay,
verifyContext: verifyContext
verifyContext: util.getVerifyContext(requestId: requestId, domain: sessionAuthenticateRequestParams.requester.metadata.url)
)
pairingRegisterer.activate(
pairingTopic: pairingTopic,
Expand Down
3 changes: 2 additions & 1 deletion Sources/WalletConnectSign/Engine/Common/ApproveEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ final class ApproveEngine {
expiry: Int64(expiry)
)

let verifyContext = (try? verifyContextStore.get(key: proposal.proposer.publicKey)) ?? VerifyContext(origin: nil, validation: .unknown)
let verifyContext = (try? verifyContextStore.get(key: proposal.proposer.publicKey)) ?? verifyClient.createVerifyContext(origin: nil, domain: proposal.proposer.metadata.url, isScam: false)


let session = WCSession(
topic: topic,
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 @@ -121,7 +121,7 @@ public struct SignClientFactory {
let walletErrorResponder = WalletErrorResponder(networkingInteractor: networkingClient, logger: logger, kms: kms, rpcHistory: rpcHistory, linkEnvelopesDispatcher: linkEnvelopesDispatcher)
let authRequestSubscriber = AuthRequestSubscriber(networkingInteractor: networkingClient, logger: logger, kms: kms, walletErrorResponder: walletErrorResponder, pairingRegisterer: pairingClient, verifyClient: verifyClient, verifyContextStore: verifyContextStore, pairingStore: pairingStore)

let approveSessionAuthenticateUtil = ApproveSessionAuthenticateUtil(logger: logger, kms: kms, rpcHistory: rpcHistory, signatureVerifier: signatureVerifier, messageFormatter: messageFormatter, sessionStore: sessionStore, sessionNamespaceBuilder: sessionNameSpaceBuilder, networkingInteractor: networkingClient)
let approveSessionAuthenticateUtil = ApproveSessionAuthenticateUtil(logger: logger, kms: kms, rpcHistory: rpcHistory, signatureVerifier: signatureVerifier, messageFormatter: messageFormatter, sessionStore: sessionStore, sessionNamespaceBuilder: sessionNameSpaceBuilder, networkingInteractor: networkingClient, verifyContextStore: verifyContextStore, verifyClient: verifyClient)

let pendingRequestsProvider = PendingRequestsProvider(rpcHistory: rpcHistory, verifyContextStore: verifyContextStore)
let authResponseTopicResubscriptionService = AuthResponseTopicResubscriptionService(networkingInteractor: networkingClient, logger: logger, authResponseTopicRecordsStore: authResponseTopicRecordsStore)
Expand Down

0 comments on commit 572591d

Please sign in to comment.