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

Implement identity (recovery) request #6

Merged
merged 8 commits into from
Mar 19, 2024
Merged

Conversation

bisgardo
Copy link
Contributor

@bisgardo bisgardo commented Feb 27, 2024

Adds the functions with the following UDL signatures:

  • string identity_issuance_request_json(IdentityIssuanceRequestParameters params)
  • string identity_recovery_request_json(IdentityRecoveryRequestParameters params)
  • AccountCredentialResult account_credential(AccountCredentialParameters params)
  • string account_credential_deployment_hash_hex(AccountCredential credential, u64 expiry_unix)
  • string account_credential_deployment_signed_payload_hex(SignedAccountCredential credential)

The parameter types mirror the corresponding "input" types from wallet_library but use only types supported by UniFFI. The values are translated into these library types via JSON encoding/decoding. This is in contrast to the Java SDK where the value is passed as a JSON encoded string which is then decoded directly into the library input type. Doing it this way ensures that type unsafe conversions happen internally in this library where it's easily tested rather than at the FFI boundary. So it makes the FFI boundary type safe and of course also generates the Swift types that we do need on the SDK side anyway.

The identity request functions return their result as JSON encoded strings because the protocol actually is to just send the object as JSON in a URL parameter. So there's no point in decoding them into structured types - they would just be converted right back to JSON on the SDK side. We do decode the payload in a unit test to verify the format.

The existing functions have been renamed and reordered to match the conventions and usage in the SDK, so this is a breaking change. Their implementations have not changed.

Base automatically changed from test to main February 27, 2024 14:46
…t functions

UDL signatures:

- `string identity_issuance_request_json(IdentityIssuanceRequestParameters params)`
- `string identity_recovery_request_json(IdentityRecoveryRequestParameters params)`
- `AccountCredentialResult account_credential(AccountCredentialParameters params)`
- `string account_credential_deployment_hash_hex(AccountCredential credential, u64 expiry_unix)`
- `string account_credential_deployment_signed_payload_hex(SignedAccountCredential credential)`

The parameter types mirror the corresponding "input" types from `wallet_library` but use only types supported by UniFFI.
The values are translated into these library types via JSON encoding/decoding.
This is in contrast to the Java SDK where the value is passed as a JSON encoded string
which is then decoded directly into the library input type.
Doing it this way ensures that type unsafe conversions happen internally in this library where it's easily tested
rather than at the FFI boundary.
So it makes the FFI boundary type safe and of course also generates the Swift types that we do need on the SDK side anyway.

The identity request functions return their result as JSON encoded strings
because the protocol actually is to just send the object as JSON in a URL parameter.
So there's no point in decoding them into structured types - they would just be converted right back to JSON on the SDK side.
We do decode the payload in a unit test to verify the format.
@bisgardo bisgardo changed the base branch from main to restructure March 8, 2024 10:17
@bisgardo bisgardo marked this pull request as ready for review March 8, 2024 12:01
@bisgardo
Copy link
Contributor Author

bisgardo commented Mar 8, 2024

Note that the PR is stacked on #8.

Base automatically changed from restructure to main March 11, 2024 10:03
@bisgardo
Copy link
Contributor Author

Ping @eb-concordium @abizjak, I'm currently blocked by this to proceed on the SDK side. If it helps I can confirm that it all works from there.

@bisgardo
Copy link
Contributor Author

Note that the PR is stacked on #8.

It's no longer stacked.

Copy link

@abizjak abizjak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be missing something, but I don't understand the need for all the duplication that is done here, compared to other SDKs we already have.

CHANGELOG.md Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
tests/lib_test.rs Outdated Show resolved Hide resolved
- Inlined type aliases: They were a somewhat arbitrary set of the used types anyway and weren't used for FFI. There are similar types in concordium-base except those are not aliases which means that UniFFI doesn't support them automatically.
- Reconcile `CredentialPublicKeysHex` with `CredentialPublicKeysWithScheme` into `CredentialPublicKeys` as it turns out that the string (hex) variant is unnecessary because the scheme variant can be used instead of it.
- Unexport internal struct`CredentialDeploymentPayloadHashInput` and rename its field `expiry_unix` to `expiry_unix_secs` to clarify the unit.
- Remove test structs that are just boiled down versions of the actual types. This changes the tests to verify the complete format but no longer any concrete values.
- Changelog: Minor clarification of rationale.
@bisgardo bisgardo requested a review from abizjak March 15, 2024 15:11
src/lib.udl Show resolved Hide resolved
tests/lib_test.rs Outdated Show resolved Hide resolved
tests/lib_test.rs Outdated Show resolved Hide resolved
tests/lib_test.rs Outdated Show resolved Hide resolved
tests/lib_test.rs Outdated Show resolved Hide resolved
tests/lib_test.rs Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
Copy link

@abizjak abizjak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline, in the interest of moving things along we'll go with the current solution of manually rust defined types + JSON conversion.

In the Rust code, the docstrings explain the link between the types generated from UDL and the "original" ones from the core Concordium libraries that they bridge to. To properly refer to types located in concordium-base in the docstrings, an explicit dependency to that library has been added.

The docstrings on the UDL types are mostly what I could find in the docstrings on the original types.

As the dependency to concordium-base was added, the struct `Versioned` in `lib_test` was replaced by its original.
Before this we only verified that the result has the correct JSON format.
@bisgardo bisgardo merged commit 8656822 into main Mar 19, 2024
6 checks passed
@bisgardo bisgardo deleted the identity-recovery-request branch March 19, 2024 14:43
bisgardo added a commit to Concordium/concordium-swift-sdk that referenced this pull request Apr 9, 2024
The `NodeClient` protocol is extended with methods for querying IPs and ARs and a method for sending a credential deployment. The IP info exposed via gRPC doesn't include the URLs for starting identity issuance and recovery, so Wallet Proxy integration is added for use when those are needed.

The crypto functions for construction identity/credential requests added in Concordium/concordium-wallet-crypto-swift#6 are integrated via `WalletSeed`. The credential deployment serialization functions are integrated in `Transaction.swift`.

URLs to invoke the IPs are conveniently built using helpers in `WalletIdentity.swift`. Due to the fact that IPs respond with identity objects etc. encoded as JSON, the relevant types from `ConcordiumWalletCrypto` are extended to conform with `Decodable`. A convenient helper for building the request payloads is included as well.

The example CLI is extended to support all the new functionality via the commands:

- `wallet identity issue` (example: `concordium-example-client wallet --seed-phrase="..." --identity-provider-id=1 --identity-index=2 identity issue`)
- `wallet identity recover` (example: `concordium-example-client wallet --seed-phrase="..." --identity-provider-id=1 --identity-index=2 identity recover`)
- `wallet identity create-account` (example: `concordium-example-client wallet --seed-phrase="..." --identity-provider-id=1 --identity-index=2 identity create-account --credential-counter=0`)

The readme includes all relevant details.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants