Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve docs #45

Merged
merged 6 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Concordium/Domain/Identity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public typealias IdentityVerificationResult = Result<Versioned<IdentityObject>,
public typealias IdentityVerificationStatusRequest = HTTPRequest<IdentityVerificationStatusResponse>

public enum IdentityVerificationError: Error {
/// Identity verification failed with the attached string containing any reason provided by the IP.
/// Identity verification failed with the attached string containing any reason provided by the identity provider.
case failure(String?)
}

Expand Down
4 changes: 1 addition & 3 deletions Sources/Concordium/HTTP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ public struct HTTPRequest<Response: Decodable> {
public init(url: URL) {
self.init(request: URLRequest(url: url))
}
}

public extension HTTPRequest {
func decodeResponse(data: Data) throws -> Response {
try JSONDecoder().decode(Response.self, from: data)
}

func send(session: URLSession) async throws -> Response {
public func send(session: URLSession) async throws -> Response {
let (data, _) = try await session.data(for: request)
return try decodeResponse(data: data)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/DocSnippets/Sources/CreateAccount/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ let identityProviderID = IdentityProviderID(3)
let identityIndex = IdentityIndex(7)
let credentialCounter = CredentialCounter(21)
let walletProxyBaseURL = URL(string: "https://wallet-proxy.testnet.concordium.com")!
let anonymityRevocationThreshold = RevocationThreshold(2)
let expiry = TransactionTime(9_999_999_999)

/// Perform account creation (on recovered identity) based on the inputs above.
Expand Down Expand Up @@ -54,6 +53,7 @@ func createAccount(client: NodeClient) async throws {
}

// Duplicated in 'RecoverIdentity/main.swift'.
// TODO: Figure out how to depend on 'RecoverIdentity' and use its impl (got it to compile but linking failed).
func makeIdentityRecoveryRequest(
_ seed: WalletSeed,
_ cryptoParams: CryptographicParameters,
Expand Down
34 changes: 15 additions & 19 deletions examples/DocSnippets/Sources/CreateIdentity/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ func createIdentity(client: NodeClient) async throws {

// Construct identity creation request and start verification.
let cryptoParams = try await client.cryptographicParameters(block: .lastFinal)
let statusURL = try issueIdentitySync(seed, cryptoParams, identityProvider, identityIndex, anonymityRevocationThreshold) { issuanceStartURL, requestJSON in
print("Preparing identity issuance request.")
let identityRequestBuilder = SeedBasedIdentityRequestBuilder(
seed: seed,
cryptoParams: cryptoParams
)
let reqJSON = try identityRequestBuilder.issuanceRequestJSON(
provider: identityProvider,
index: identityIndex,
anonymityRevocationThreshold: anonymityRevocationThreshold
)
let statusURL = try issueIdentitySync(reqJSON, identityProvider) { issuanceStartURL, requestJSON in
// The URL to be invoked when once the ID verification process has started (i.e. once the data has been filled in).
let callbackURL = URL(string: "concordiumwallet-example://identity-issuer/callback")!

Expand All @@ -38,26 +48,12 @@ func createIdentity(client: NodeClient) async throws {
}

func issueIdentitySync(
_ seed: WalletSeed,
_ cryptoParams: CryptographicParameters,
_ issuanceRequestJSON: String,
_ identityProvider: IdentityProvider,
_ identityIndex: IdentityIndex,
_ anonymityRevocationThreshold: RevocationThreshold,
_ runIdentityProviderFlow: (_ issuanceStartURL: URL, _ requestJSON: String) throws -> URL
) throws -> IdentityVerificationStatusRequest {
print("Preparing identity issuance request.")
let identityRequestBuilder = SeedBasedIdentityRequestBuilder(
seed: seed,
cryptoParams: cryptoParams
)
let reqJSON = try identityRequestBuilder.issuanceRequestJSON(
provider: identityProvider,
index: identityIndex,
anonymityRevocationThreshold: anonymityRevocationThreshold
)

print("Start identity provider issuance flow.")
let url = try runIdentityProviderFlow(identityProvider.metadata.issuanceStart, reqJSON)
let url = try runIdentityProviderFlow(identityProvider.metadata.issuanceStart, issuanceRequestJSON)
print("Identity verification process started!")
return .init(url: url)
}
Expand All @@ -79,11 +75,11 @@ func todoAwaitCallbackWithVerificationPollingURL() -> URL {
}

func todoAwaitVerification(_ request: IdentityVerificationStatusRequest) async throws -> IdentityVerificationResult {
// Block the thread, periodically polling for the verification status.
// Return the result once it's no longer "pending" (i.e. the result is non-nil).
// Dummy impl that simply blocks the thread and periodically polls the verification status.
while true {
let status = try await request.send(session: URLSession.shared)
if let r = status.result {
// Status is no longer "pending"; return the result.
return r
}
try await Task.sleep(nanoseconds: 10 * 1_000_000_000) // check once every 10s
Expand Down