Skip to content

Commit

Permalink
Integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flypaper0 committed Dec 6, 2023
1 parent 5f5cf67 commit b437f19
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
13 changes: 11 additions & 2 deletions Example/IntegrationTests/Push/NotifyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,17 @@ final class NotifyTests: XCTestCase {


private extension NotifyTests {
func sign(_ message: String) -> SigningResult {
func sign(_ message: String) -> CacaoSignature {
let signer = MessageSignerFactory(signerFactory: DefaultSignerFactory()).create(projectId: InputConfig.projectId)
return .signed(try! signer.sign(message: message, privateKey: privateKey, type: .eip191))
return try! signer.sign(message: message, privateKey: privateKey, type: .eip191)
}
}

private extension NotifyClient {

func register(account: Account, domain: String, isLimited: Bool = false, onSign: @escaping (String) -> CacaoSignature) async throws {
let params = try await prepareRegistration(account: account, domain: domain)
let signature = onSign(params.message)
try await register(params: params, signature: signature)
}
}
33 changes: 21 additions & 12 deletions Sources/Chat/ChatClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,34 @@ public class ChatClient {
domain: String,
onSign: @escaping SigningCallback
) async throws -> String {
let publicKey = try await identityClient.register(

let params = try await identityClient.prepareRegistration(
account: account,
domain: domain,
statement: "statement",
resources: ["https://keys.walletconnect.com"],
onSign: onSign
resources: ["https://keys.walletconnect.com"]
)
if !syncRegisterService.isRegistered(account: account) {
try await chatStorage.initializeHistory(account: account)
try await syncRegisterService.register(account: account, onSign: onSign)
}

guard !isPrivate else {
return publicKey
}
switch await onSign(params.message) {
case .signed(let signature):
let publicKey = try await identityClient.register(params: params, signature: signature)

if !syncRegisterService.isRegistered(account: account) {
try await chatStorage.initializeHistory(account: account)
try await syncRegisterService.register(account: account, onSign: onSign)
}

try await goPublic(account: account)
guard !isPrivate else {
return publicKey
}

return publicKey
try await goPublic(account: account)

return publicKey

case .rejected:
fatalError("Not implemented")
}
}

/// Unregisters a blockchain account with previously registered identity key
Expand Down
6 changes: 4 additions & 2 deletions Sources/WalletConnectIdentity/IdentityClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ public final class IdentityClient {
return registration
}

public func register(params: IdentityRegistrationParams, signature: CacaoSignature) async throws {
@discardableResult
public func register(params: IdentityRegistrationParams, signature: CacaoSignature) async throws -> String {
let account = try params.account
try await identityService.registerIdentity(params: params, signature: signature)
let pubKey = try await identityService.registerIdentity(params: params, signature: signature)
logger.debug("Did register an account: \(account)")
return pubKey
}

public func goPublic(account: Account) async throws -> AgreementPublicKey {
Expand Down
5 changes: 3 additions & 2 deletions Sources/WalletConnectIdentity/IdentityService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ actor IdentityService {
}

// TODO: Verifications
func registerIdentity(params: IdentityRegistrationParams, signature: CacaoSignature) async throws {
func registerIdentity(params: IdentityRegistrationParams, signature: CacaoSignature) async throws -> String {
let account = try params.account

if let identityKey = try? storage.getIdentityKey(for: account) {
return
return identityKey.publicKey.hexRepresentation
}

let cacaoHeader = CacaoHeader(t: "eip4361")
Expand All @@ -64,6 +64,7 @@ actor IdentityService {
try await networkService.registerIdentity(cacao: cacao)
try storage.saveIdentityKey(params.privateIdentityKey, for: account)

return params.privateIdentityKey.publicKey.hexRepresentation
}

func registerInvite(account: Account) async throws -> AgreementPublicKey {
Expand Down

0 comments on commit b437f19

Please sign in to comment.