Skip to content

Commit

Permalink
savepoint
Browse files Browse the repository at this point in the history
  • Loading branch information
llbartekll committed Aug 12, 2024
1 parent bd983cb commit a009088
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class ApproveSessionAuthenticateUtil {


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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ class AuthRequestSubscriber {
let assertionId = payload.decryptedPayload.sha256().toHexString()
response = try await verifyClient.verify(.v1(assertionId: assertionId))
}
let verifyContext = verifyClient.createVerifyContext(origin: response.origin, domain: payload.request.authPayload.domain, isScam: response.isScam)
let verifyContext = verifyClient.createVerifyContext(origin: response.origin, domain: payload.request.authPayload.domain, isScam: response.isScam, isVerified: response.isVerified)
verifyContextStore.set(verifyContext, forKey: request.id.string)
onRequest?((request, verifyContext))
} catch {
let verifyContext = verifyClient.createVerifyContext(origin: nil, domain: payload.request.authPayload.domain, isScam: nil)
let verifyContext = verifyClient.createVerifyContext(origin: nil, domain: payload.request.authPayload.domain, isScam: nil, isVerified: nil)
verifyContextStore.set(verifyContext, forKey: request.id.string)
onRequest?((request, verifyContext))
return
Expand Down
7 changes: 4 additions & 3 deletions Sources/WalletConnectSign/Engine/Common/ApproveEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ final class ApproveEngine {
expiry: Int64(expiry)
)

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


let session = WCSession(
Expand Down Expand Up @@ -411,12 +411,13 @@ private extension ApproveEngine {
let verifyContext = verifyClient.createVerifyContext(
origin: response.origin,
domain: payload.request.proposer.metadata.url,
isScam: response.isScam
isScam: response.isScam,
isVerified: response.isVerified
)
verifyContextStore.set(verifyContext, forKey: proposal.proposer.publicKey)
onSessionProposal?(proposal.publicRepresentation(pairingTopic: payload.topic), verifyContext)
} catch {
let verifyContext = verifyClient.createVerifyContext(origin: nil, domain: payload.request.proposer.metadata.url, isScam: nil)
let verifyContext = verifyClient.createVerifyContext(origin: nil, domain: payload.request.proposer.metadata.url, isScam: nil, isVerified: nil)
onSessionProposal?(proposal.publicRepresentation(pairingTopic: payload.topic), verifyContext)
return
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/WalletConnectVerify/AttestationJWTVerifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AttestationJWTVerifier {
throw Errors.messageIdMismatch
}

return VerifyResponse(origin: claims.origin, isScam: claims.isScam)
return VerifyResponse(origin: claims.origin, isScam: claims.isScam, isVerified: claims.isVerified)
}

func verifyJWTAgainstPubKey(_ jwtString: String, signingPubKey: P256.Signing.PublicKey) throws {
Expand Down
1 change: 1 addition & 0 deletions Sources/WalletConnectVerify/Register/VerifyResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import Foundation
public struct VerifyResponse: Decodable {
public let origin: String?
public let isScam: Bool?
public let isVerified: Bool?
}
11 changes: 5 additions & 6 deletions Sources/WalletConnectVerify/VerifyClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation

public protocol VerifyClientProtocol {
func verify(_ verificationType: VerificationType) async throws -> VerifyResponse
func createVerifyContext(origin: String?, domain: String, isScam: Bool?) -> VerifyContext
func createVerifyContext(origin: String?, domain: String, isScam: Bool?, isVerified: Bool?) -> VerifyContext
func createVerifyContextForLinkMode(redirectUniversalLink: String, domain: String) -> VerifyContext
}

Expand Down Expand Up @@ -53,8 +53,8 @@ public actor VerifyClient: VerifyClientProtocol {
}
}

nonisolated public func createVerifyContext(origin: String?, domain: String, isScam: Bool?) -> VerifyContext {
verifyContextFactory.createVerifyContext(origin: origin, domain: domain, isScam: isScam)
nonisolated public func createVerifyContext(origin: String?, domain: String, isScam: Bool?, isVerified: Bool?) -> VerifyContext {
verifyContextFactory.createVerifyContext(origin: origin, domain: domain, isScam: isScam, isVerified: isVerified)
}

nonisolated public func createVerifyContextForLinkMode(redirectUniversalLink: String, domain: String) -> VerifyContext {
Expand All @@ -69,14 +69,13 @@ public actor VerifyClient: VerifyClientProtocol {
#if DEBUG

public struct VerifyClientMock: VerifyClientProtocol {

public init() {}

public func verify(_ verificationType: VerificationType) async throws -> VerifyResponse {
return VerifyResponse(origin: "domain.com", isScam: nil)
return VerifyResponse(origin: "domain.com", isScam: nil, isVerified: nil)
}

public func createVerifyContext(origin: String?, domain: String, isScam: Bool?) -> VerifyContext {
public func createVerifyContext(origin: String?, domain: String, isScam: Bool?, isVerified: Bool?) -> VerifyContext {
return VerifyContext(origin: "domain.com", validation: .valid)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/WalletConnectVerify/VerifyContextFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Foundation

class VerifyContextFactory {
public func createVerifyContext(origin: String?, domain: String, isScam: Bool?, isVerified: Bool? = nil) -> VerifyContext {
public func createVerifyContext(origin: String?, domain: String, isScam: Bool?, isVerified: Bool?) -> VerifyContext {

guard isScam != true else {
return VerifyContext(
Expand Down
8 changes: 4 additions & 4 deletions Tests/VerifyTests/VerifyContextFactoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ class VerifyContextFactoryTests: XCTestCase {
}

func testScamValidation() {
let context = factory.createVerifyContext(origin: "http://example.com", domain: "http://example.com", isScam: true)
let context = factory.createVerifyContext(origin: "http://example.com", domain: "http://example.com", isScam: true, isVerified: nil)
XCTAssertEqual(context.validation, .scam)
}

func testValidOriginAndDomain() {
let context = factory.createVerifyContext(origin: "http://example.com", domain: "http://example.com", isScam: false)
let context = factory.createVerifyContext(origin: "http://example.com", domain: "http://example.com", isScam: false, isVerified: nil)
XCTAssertEqual(context.validation, .valid)
}

func testInvalidOriginAndDomain() {
let context = factory.createVerifyContext(origin: "http://example.com", domain: "http://different.com", isScam: false)
let context = factory.createVerifyContext(origin: "http://example.com", domain: "http://different.com", isScam: false, isVerified: nil)
XCTAssertEqual(context.validation, .invalid)
}

func testUnknownValidation() {
let context = factory.createVerifyContext(origin: nil, domain: "http://example.com", isScam: false)
let context = factory.createVerifyContext(origin: nil, domain: "http://example.com", isScam: false, isVerified: nil)
XCTAssertEqual(context.validation, .unknown)
}

Expand Down

0 comments on commit a009088

Please sign in to comment.