-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add registry manager * Update api methods * update resolve * Add description to api methods * update invite method * remove teardown * make registryStore private
- Loading branch information
1 parent
9e94672
commit 147e100
Showing
17 changed files
with
170 additions
and
62 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
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,35 @@ | ||
|
||
import Foundation | ||
import WalletConnectUtils | ||
import WalletConnectKMS | ||
|
||
actor RegistryManager { | ||
let networkingInteractor: NetworkInteracting | ||
let topicToInvitationPubKeyStore: CodableStore<String> | ||
let registry: Registry | ||
let logger: ConsoleLogging | ||
let kms: KeyManagementServiceProtocol | ||
|
||
init(registry: Registry, | ||
networkingInteractor: NetworkInteracting, | ||
kms: KeyManagementServiceProtocol, | ||
logger: ConsoleLogging, | ||
topicToInvitationPubKeyStore: CodableStore<String>) { | ||
self.registry = registry | ||
self.kms = kms | ||
self.networkingInteractor = networkingInteractor | ||
self.logger = logger | ||
self.topicToInvitationPubKeyStore = topicToInvitationPubKeyStore | ||
} | ||
|
||
func register(account: Account) async throws -> String { | ||
let pubKey = try kms.createX25519KeyPair() | ||
let pubKeyHex = pubKey.hexRepresentation | ||
try await registry.register(account: account, pubKey: pubKeyHex) | ||
let topic = pubKey.rawRepresentation.sha256().toHexString() | ||
topicToInvitationPubKeyStore.set(pubKeyHex, forKey: topic) | ||
try await networkingInteractor.subscribe(topic: topic) | ||
logger.debug("Did register an account: \(account) and is subscribing on topic: \(topic)") | ||
return pubKeyHex | ||
} | ||
} |
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 |
---|---|---|
|
@@ -4,4 +4,5 @@ import Foundation | |
enum ChatError: Error { | ||
case noPublicKeyForInviteId | ||
case noInviteForId | ||
case recordNotFound | ||
} |
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,15 @@ | ||
|
||
import Foundation | ||
@testable import Chat | ||
|
||
class NetworkingInteractorMock: NetworkInteracting { | ||
private(set) var subscriptions: [String] = [] | ||
|
||
func subscribe(topic: String) async throws { | ||
subscriptions.append(topic) | ||
} | ||
|
||
func didSubscribe(to topic: String) -> Bool { | ||
subscriptions.contains { $0 == topic } | ||
} | ||
} |
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,37 @@ | ||
import Foundation | ||
import XCTest | ||
@testable import Chat | ||
import WalletConnectUtils | ||
@testable import WalletConnectKMS | ||
@testable import TestingUtils | ||
|
||
final class RegistryManagerTests: XCTestCase { | ||
var registryManager: RegistryManager! | ||
var networkingInteractor: NetworkingInteractorMock! | ||
var topicToInvitationPubKeyStore: CodableStore<String>! | ||
var registry: Registry! | ||
var kms: KeyManagementServiceMock! | ||
|
||
override func setUp() { | ||
registry = KeyValueRegistry() | ||
networkingInteractor = NetworkingInteractorMock() | ||
kms = KeyManagementServiceMock() | ||
topicToInvitationPubKeyStore = CodableStore(defaults: RuntimeKeyValueStorage(), identifier: "") | ||
registryManager = RegistryManager( | ||
registry: registry, | ||
networkingInteractor: networkingInteractor, | ||
kms: kms, | ||
logger: ConsoleLoggerMock(), | ||
topicToInvitationPubKeyStore: topicToInvitationPubKeyStore) | ||
} | ||
|
||
func testRegister() async { | ||
let account = Account("eip155:1:0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb")! | ||
try! await registryManager.register(account: account) | ||
XCTAssert(!networkingInteractor.subscriptions.isEmpty, "networkingInteractors subscribes to new topic") | ||
let resolved = try! await registry.resolve(account: account) | ||
XCTAssertNotNil(resolved, "register account is resolvable") | ||
XCTAssertFalse(topicToInvitationPubKeyStore.getAll().isEmpty, "stores topic to invitation") | ||
} | ||
} | ||
|
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
Oops, something went wrong.