From 1b6be138ab91b16860b4d83a45df92da5027ade1 Mon Sep 17 00:00:00 2001 From: Michael Bisgaard Olesen Date: Mon, 26 Feb 2024 14:25:54 +0100 Subject: [PATCH] Implement getIdentityProviderInfo --- .../WalletProxyClient.swift | 47 +++++++++++++++++++ .../GrpcCli/Sources/GrpcCli/GrpcCli.swift | 26 +++++++++- 2 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 Sources/ConcordiumSwiftSdk/WalletProxyClient.swift diff --git a/Sources/ConcordiumSwiftSdk/WalletProxyClient.swift b/Sources/ConcordiumSwiftSdk/WalletProxyClient.swift new file mode 100644 index 0000000..e9df5b3 --- /dev/null +++ b/Sources/ConcordiumSwiftSdk/WalletProxyClient.swift @@ -0,0 +1,47 @@ +import Foundation + +public class WalletProxyClient { + let baseUrl: String + + public init(baseUrl: String) { + self.baseUrl = baseUrl + } + + public func getIdentityProviderInfo() async throws -> [IdentityProviderJson] { + let url = URL(string: "\(baseUrl)/v1/ip_info")! + let (data, _) = try await URLSession.shared.data(from: url) + return try JSONDecoder().decode([IdentityProviderJson].self, from: data) + } +} + +public struct IdentityProviderJson: Decodable { + public var ipInfo: IdentityProvider + public var arsInfos: [String: AnonymityRevoker] + public var metadata: Metadata + + public struct IdentityProvider: Decodable { + public var ipIdentity: UInt32 + public var ipDescription: Description + public var ipCdiVerifyKey: String + public var ipVerifyKey: String + } + + public struct AnonymityRevoker: Decodable { + public var arIdentity: UInt32 + public var arDescription: Description + public var arPublicKey: String + } + + public struct Description: Decodable { + public var name: String + public var description: String + public var url: String + } + + public struct Metadata: Decodable { + public var icon: String + public var issuanceStart: String + public var support: String? + public var recoveryStart: String + } +} diff --git a/examples/GrpcCli/Sources/GrpcCli/GrpcCli.swift b/examples/GrpcCli/Sources/GrpcCli/GrpcCli.swift index aa98946..91cf64a 100644 --- a/examples/GrpcCli/Sources/GrpcCli/GrpcCli.swift +++ b/examples/GrpcCli/Sources/GrpcCli/GrpcCli.swift @@ -66,7 +66,7 @@ struct GrpcCli: AsyncParsableCommand { static var configuration = CommandConfiguration( abstract: "A CLI for demonstrating and testing use of the gRPC client of the SDK.", version: "1.0.0", - subcommands: [CryptographicParameters.self, Account.self, Wallet.self, LegacyWallet.self] + subcommands: [CryptographicParameters.self, Account.self, Wallet.self, LegacyWallet.self, Identity.self] ) struct CryptographicParameters: AsyncParsableCommand { @@ -197,7 +197,7 @@ struct GrpcCli: AsyncParsableCommand { ).generateAccount( credentials: [ AccountCredential( - identity: Identity(providerIndex: walletCli.identityProviderIndex, index: walletCli.identityIndex), + identity: ConcordiumSwiftSdk.Identity(providerIndex: walletCli.identityProviderIndex, index: walletCli.identityIndex), counter: walletCli.credentialCounter ), ] @@ -270,6 +270,28 @@ struct GrpcCli: AsyncParsableCommand { } } } + + struct Identity: AsyncParsableCommand { + static var configuration = CommandConfiguration( + abstract: "Commands related to identity management.", + subcommands: [Providers.self] + ) + + struct Providers: AsyncParsableCommand { + static var configuration = CommandConfiguration( + abstract: "List all Identity Providers." + ) + + @Option(help: "Base URL of WalletProxy instance.") + var walletProxyBaseUrl: String = "https://wallet-proxy.testnet.concordium.com" + + func run() async throws { + let wp = WalletProxyClient(baseUrl: walletProxyBaseUrl) + let res = try await wp.getIdentityProviderInfo() + print(res) + } + } + } } func transfer(client: NodeClientProtocol, sender: WalletAccount, receiver: AccountAddress, amount: MicroCcdAmount, expiry: TransactionTime) async throws -> TransactionHash {