-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Auth] #434 auth client factory
- Loading branch information
Showing
13 changed files
with
155 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import Foundation | ||
import XCTest | ||
import WalletConnectUtils | ||
@testable import WalletConnectKMS | ||
import WalletConnectRelay | ||
import Combine | ||
@testable import Auth | ||
|
||
final class AuthTests: XCTestCase { | ||
var app: AuthClient! | ||
var wallet: AuthClient! | ||
private var publishers = [AnyCancellable]() | ||
|
||
override func setUp() { | ||
app = makeClient(prefix: "👻 App") | ||
let walletAccount = Account(chainIdentifier: "eip155:1", address: "0x3627523167367216556273151")! | ||
wallet = makeClient(prefix: "🤑 Wallet", account: walletAccount) | ||
|
||
let expectation = expectation(description: "Wait Clients Connected") | ||
expectation.expectedFulfillmentCount = 2 | ||
|
||
app.socketConnectionStatusPublisher.sink { status in | ||
if status == .connected { | ||
expectation.fulfill() | ||
} | ||
}.store(in: &publishers) | ||
|
||
wallet.socketConnectionStatusPublisher.sink { status in | ||
if status == .connected { | ||
expectation.fulfill() | ||
} | ||
}.store(in: &publishers) | ||
|
||
wait(for: [expectation], timeout: 5) | ||
} | ||
|
||
|
||
func makeClient(prefix: String, account: Account? = nil) -> AuthClient { | ||
let logger = ConsoleLogger(suffix: prefix, loggingLevel: .debug) | ||
let relayHost = "relay.walletconnect.com" | ||
let projectId = "8ba9ee138960775e5231b70cc5ef1c3a" | ||
let keychain = KeychainStorageMock() | ||
let relayClient = RelayClient(relayHost: relayHost, projectId: projectId, keychainStorage: keychain, socketFactory: SocketFactory(), logger: logger) | ||
|
||
return AuthClientFactory.create( | ||
metadata: AppMetadata(name: name, description: "", url: "", icons: [""]), | ||
account: account, | ||
logger: logger, | ||
keyValueStorage: RuntimeKeyValueStorage(), | ||
keychainStorage: keychain, | ||
relayClient: relayClient) | ||
} | ||
|
||
func testRequest() async { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import Foundation | ||
import WalletConnectRelay | ||
import WalletConnectUtils | ||
import WalletConnectKMS | ||
import WalletConnectPairing | ||
|
||
public struct AuthClientFactory { | ||
|
||
public static func create(metadata: AppMetadata, account: Account?, relayClient: RelayClient) -> AuthClient { | ||
let logger = ConsoleLogger(loggingLevel: .off) | ||
let keyValueStorage = UserDefaults.standard | ||
let keychainStorage = KeychainStorage(serviceIdentifier: "com.walletconnect.sdk") | ||
return AuthClientFactory.create(metadata: metadata, account: account, logger: logger, keyValueStorage: keyValueStorage, keychainStorage: keychainStorage, relayClient: relayClient) | ||
} | ||
|
||
static func create(metadata: AppMetadata, account: Account?, logger: ConsoleLogging, keyValueStorage: KeyValueStorage, keychainStorage: KeychainStorageProtocol, relayClient: RelayClient) -> AuthClient { | ||
let historyStorage = CodableStore<RPCHistory.Record>(defaults: keyValueStorage, identifier: StorageDomainIdentifiers.jsonRpcHistory.rawValue) | ||
let pairingStore = PairingStorage(storage: SequenceStore<WCPairing>(store: .init(defaults: keyValueStorage, identifier: StorageDomainIdentifiers.pairings.rawValue))) | ||
let kms = KeyManagementService(keychain: keychainStorage) | ||
let serializer = Serializer(kms: kms) | ||
let history = RPCHistory(keyValueStore: historyStorage) | ||
let networkingInteractor = NetworkingInteractor(relayClient: relayClient, serializer: serializer, logger: logger, rpcHistory: history) | ||
let messageFormatter = SIWEMessageFormatter() | ||
let appPairService = AppPairService(networkingInteractor: networkingInteractor, kms: kms, pairingStorage: pairingStore) | ||
let appRequestService = AppRequestService(networkingInteractor: networkingInteractor, kms: kms, appMetadata: metadata) | ||
let messageSigner = MessageSigner(signer: Signer()) | ||
let appRespondSubscriber = AppRespondSubscriber(networkingInteractor: networkingInteractor, logger: logger, rpcHistory: history, signatureVerifier: messageSigner, messageFormatter: messageFormatter) | ||
let walletPairService = WalletPairService(networkingInteractor: networkingInteractor, kms: kms, pairingStorage: pairingStore) | ||
let walletRequestSubscriber = WalletRequestSubscriber(networkingInteractor: networkingInteractor, logger: logger, messageFormatter: messageFormatter, address: account?.address) | ||
let walletRespondService = WalletRespondService(networkingInteractor: networkingInteractor, logger: logger, kms: kms, rpcHistory: history) | ||
let pendingRequestsProvider = PendingRequestsProvider(rpcHistory: history) | ||
let cleanupService = CleanupService(pairingStore: pairingStore, kms: kms) | ||
|
||
return AuthClient(appPairService: appPairService, | ||
appRequestService: appRequestService, | ||
appRespondSubscriber: appRespondSubscriber, | ||
walletPairService: walletPairService, | ||
walletRequestSubscriber: walletRequestSubscriber, | ||
walletRespondService: walletRespondService, | ||
account: account, | ||
pendingRequestsProvider: pendingRequestsProvider, | ||
cleanupService: cleanupService, | ||
logger: logger, | ||
pairingStorage: pairingStore, socketConnectionStatusPublisher: relayClient.socketConnectionStatusPublisher) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Foundation | ||
|
||
enum StorageDomainIdentifiers: String { | ||
case jsonRpcHistory = "com.walletconnect.sdk.wc_jsonRpcHistoryRecord" | ||
case pairings = "com.walletconnect.sdk.pairingSequences" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import WalletConnectUtils | ||
import Foundation | ||
|
||
typealias Account = WalletConnectUtils.Account | ||
public typealias Account = WalletConnectUtils.Account |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters