Skip to content

Commit

Permalink
Add docstrings
Browse files Browse the repository at this point in the history
To properly refer to types located in concordium-base in the docstrings, an explicit dependency to that type has been added.
  • Loading branch information
bisgardo committed Mar 19, 2024
1 parent 1e1916b commit 2248a46
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 16 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ crate-type = ["staticlib", "lib"]
[dependencies]
thiserror = "1"
uniffi = { version = "0.26", features = ["cli"] }
wallet_library = { path = "./concordium-base/rust-src/wallet_library" }
serde = "1.0"
serde_json = "1.0"

[dependencies.concordium_base]
path = "./concordium-base/rust-src/concordium_base"

[dependencies.wallet_library]
path = "./concordium-base/rust-src/wallet_library"

[build-dependencies]
uniffi = { version = "0.26", features = ["build"] }

Expand Down
88 changes: 82 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub enum ConcordiumWalletCryptoError {
CallFailed { call: String, msg: String },
}

/// Implements UDL definition of the same name.
pub fn identity_cred_sec_hex(
seed_hex: String,
net: String,
Expand All @@ -44,6 +45,7 @@ pub fn identity_cred_sec_hex(
})
}

/// Implements UDL definition of the same name.
pub fn identity_prf_key_hex(
seed_hex: String,
net: String,
Expand All @@ -57,6 +59,7 @@ pub fn identity_prf_key_hex(
})
}

/// Implements UDL definition of the same name.
pub fn identity_attributes_signature_blinding_randomness_hex(
seed_hex: String,
net: String,
Expand All @@ -70,6 +73,7 @@ pub fn identity_attributes_signature_blinding_randomness_hex(
})
}

/// Implements UDL definition of the same name.
pub fn account_credential_signing_key_hex(
seed_hex: String,
net: String,
Expand All @@ -84,6 +88,7 @@ pub fn account_credential_signing_key_hex(
})
}

/// Implements UDL definition of the same name.
pub fn account_credential_public_key_hex(
seed_hex: String,
net: String,
Expand All @@ -98,6 +103,7 @@ pub fn account_credential_public_key_hex(
})
}

/// Implements UDL definition of the same name.
pub fn account_credential_id_hex(
seed_hex: String,
net: String,
Expand All @@ -113,6 +119,7 @@ pub fn account_credential_id_hex(
})
}

/// Implements UDL definition of the same name.
pub fn account_credential_attribute_commitment_randomness_hex(
seed_hex: String,
net: String,
Expand All @@ -128,6 +135,7 @@ pub fn account_credential_attribute_commitment_randomness_hex(
})
}

/// Implements UDL definition of the same name.
pub fn verifiable_credential_signing_key_hex(
seed_hex: String,
net: String,
Expand All @@ -142,6 +150,7 @@ pub fn verifiable_credential_signing_key_hex(
})
}

/// Implements UDL definition of the same name.
pub fn verifiable_credential_public_key_hex(
seed_hex: String,
net: String,
Expand All @@ -156,6 +165,7 @@ pub fn verifiable_credential_public_key_hex(
})
}

/// Implements UDL definition of the same name.
pub fn verifiable_credential_backup_encryption_key_hex(
seed_hex: String,
net: String,
Expand All @@ -168,9 +178,9 @@ pub fn verifiable_credential_backup_encryption_key_hex(
})
}

// TODO: Use 'derivative' to implement Debug in a way that doesn't include fields containing secrets
// and log the serialized debug string into the error message.

/// UniFFI compatible bridge to [`IdentityObjectRequestInput`],
/// providing the implementation of the UDL declaration of the same name.
/// The translation is performed using Serde.
#[derive(Debug, Serialize)]
pub struct IdentityIssuanceRequestParameters {
#[serde(rename = "ipInfo")]
Expand All @@ -189,6 +199,9 @@ pub struct IdentityIssuanceRequestParameters {
pub blinding_randomness_hex: String,
}

/// UniFFI compatible bridge to [`IdentityRecoveryRequestInput`],
/// providing the implementation of the UDL declaration of the same name.
/// The translation is performed using Serde.
#[derive(Debug, Serialize)]
pub struct IdentityRecoveryRequestParameters {
#[serde(rename = "ipInfo")]
Expand All @@ -201,6 +214,9 @@ pub struct IdentityRecoveryRequestParameters {
pub id_cred_sec_hex: String,
}

/// UniFFI compatible bridge to [`concordium_base::id::types::IpInfo<concordium_base::id::constants::IpPairing>`],
/// providing the implementation of the UDL declaration of the same name.
/// The translation is performed using Serde.
#[derive(Debug, Serialize)]
pub struct IdentityProviderInfo {
#[serde(rename = "ipIdentity")]
Expand All @@ -213,6 +229,9 @@ pub struct IdentityProviderInfo {
pub cdi_verify_key_hex: String,
}

/// UniFFI compatible bridge to [`concordium_base::id::types::GlobalContext<concordium_base::id::constants::ArCurve>`],
/// providing the implementation of the UDL declaration of the same name.
/// The translation is performed using Serde.
#[derive(Debug, Serialize)]
pub struct GlobalContext {
#[serde(rename = "onChainCommitmentKey")]
Expand All @@ -223,6 +242,9 @@ pub struct GlobalContext {
pub genesis_string: String,
}

/// UniFFI compatible bridge to [`concordium_base::id::types::ArInfo<concordium_base::id::constants::ArCurve>`],
/// providing the implementation of the UDL declaration of the same name.
/// The translation is performed using Serde.
#[derive(Debug, Serialize)]
pub struct AnonymityRevokerInfo {
#[serde(rename = "arIdentity")]
Expand All @@ -233,6 +255,9 @@ pub struct AnonymityRevokerInfo {
pub public_key_hex: String,
}

/// UniFFI compatible bridge to [`concordium_base::id::types::Description`],
/// providing the implementation of the UDL declaration of the same name.
/// The translation is performed using Serde.
#[derive(Debug, Serialize)]
pub struct Description {
#[serde(rename = "name")]
Expand All @@ -243,6 +268,9 @@ pub struct Description {
pub description: String,
}

/// UniFFI compatible bridge to [`UnsignedCredentialInput`],
/// providing the implementation of the UDL declaration of the same name.
/// The translation is performed using Serde.
#[derive(Debug, Serialize)]
pub struct AccountCredentialParameters {
#[serde(rename = "ipInfo")]
Expand All @@ -269,6 +297,9 @@ pub struct AccountCredentialParameters {
pub credential_public_keys: CredentialPublicKeys,
}

/// UniFFI compatible bridge to [`concordium_base::id::types::IdentityObjectV1<concordium_base::id::constants::IpPairing,concordium_base::id::constants::ArCurve,concordium_base::id::constants::AttributeKind>`],
/// providing the implementation of the UDL declaration of the same name.
/// The translation is performed using Serde.
#[derive(Debug, Serialize)]
pub struct IdentityObject {
#[serde(rename = "preIdentityObject")]
Expand All @@ -279,6 +310,9 @@ pub struct IdentityObject {
pub signature_hex: String,
}

/// UniFFI compatible bridge to [`concordium_base::id::types::PreIdentityObjectV1<concordium_base::id::constants::IpPairing,concordium_base::id::constants::ArCurve>`],
/// providing the implementation of the UDL declaration of the same name.
/// The translation is performed using Serde.
#[derive(Debug, Deserialize, Serialize, PartialEq)]
pub struct PreIdentityObject {
#[serde(rename = "idCredPub")]
Expand All @@ -297,6 +331,9 @@ pub struct PreIdentityObject {
pub proofs_of_knowledge_hex: String,
}

/// UniFFI compatible bridge to [`concordium_base::id::types::ChoiceArParameters`],
/// providing the implementation of the UDL declaration of the same name.
/// The translation is performed using Serde.
#[derive(Debug, Deserialize, Serialize, PartialEq)]
pub struct ChoiceArParameters {
#[serde(rename = "arIdentities")]
Expand All @@ -305,6 +342,9 @@ pub struct ChoiceArParameters {
pub threshold: u32,
}

/// UniFFI compatible bridge to [`concordium_base::id::types::IpArData<concordium_base::id::constants::ArCurve>`],
/// providing the implementation of the UDL declaration of the same name.
/// The translation is performed using Serde.
#[derive(Debug, Deserialize, Serialize, PartialEq)]
pub struct ArData {
#[serde(rename = "encPrfKeyShare")]
Expand All @@ -313,6 +353,9 @@ pub struct ArData {
pub proof_com_enc_eq_hex: String,
}

/// UniFFI compatible bridge to [`concordium_base::id::types::AttributeList<concordium_base::id::constants::IpPairing,concordium_base::id::constants::ArCurve> `],
/// providing the implementation of the UDL declaration of the same name.
/// The translation is performed using Serde.
#[derive(Debug, Serialize)]
pub struct AttributeList {
#[serde(rename = "validTo")]
Expand All @@ -325,6 +368,9 @@ pub struct AttributeList {
pub chosen_attributes: HashMap<String, String>,
}

/// UniFFI compatible bridge to [`concordium_base::id::types::CredentialPublicKeys`],
/// providing the implementation of the UDL declaration of the same name.
/// The translation is performed using Serde.
#[derive(Debug, Deserialize, Serialize)]
pub struct CredentialPublicKeys {
#[serde(rename = "keys")]
Expand All @@ -333,6 +379,9 @@ pub struct CredentialPublicKeys {
pub threshold: u8,
}

/// UniFFI compatible bridge to [`concordium_base::id::types::VerifyKey`],
/// providing the implementation of the UDL declaration of the same name.
/// The translation is performed using Serde.
#[derive(Debug, Deserialize, Serialize)]
pub struct VerifyKey {
#[serde(rename = "schemeId")]
Expand All @@ -343,14 +392,20 @@ pub struct VerifyKey {

/* OUTPUTS */

/// UniFFI compatible bridge to [`wallet_library::credential::UnsignedCredentialDeploymentInfoWithRandomness`] (internal),
/// providing the implementation of the UDL declaration of the same name.
/// The translation is performed using Serde.
#[derive(Debug, Deserialize)]
pub struct AccountCredentialResult {
#[serde(rename = "randomness")]
randomness: Randomness,
#[serde(rename = "unsignedCdi")]
credential: AccountCredential,
#[serde(rename = "randomness")]
randomness: Randomness,
}

/// UniFFI compatible bridge to [`concordium_base::id::types::CommitmentsRandomness<concordium_base::id::constants::ArCurve>`],
/// providing the implementation of the UDL declaration of the same name.
/// The translation is performed using Serde.
#[derive(Debug, Deserialize)]
pub struct Randomness {
#[serde(rename = "attributesRand")]
Expand All @@ -365,7 +420,8 @@ pub struct Randomness {
pub prf_rand_hex: String,
}

// Response is (versioned) PreIdentityObject encoded as JSON.
/// Implements UDL definition of the same name.
/// The returned string is a versioned [`PreIdentityObject`] encoded as JSON.
pub fn identity_issuance_request_json(
params: IdentityIssuanceRequestParameters,
) -> Result<String, ConcordiumWalletCryptoError> {
Expand All @@ -384,6 +440,8 @@ pub fn identity_issuance_request_json(
})
}

/// Implements UDL definition of the same name.
/// The returned string is a versioned `IdentityRecoveryRequestResultValue` (defined in `lib_test.rs`) encoded as JSON.
pub fn identity_recovery_request_json(
params: IdentityRecoveryRequestParameters,
) -> Result<String, ConcordiumWalletCryptoError> {
Expand All @@ -402,6 +460,9 @@ pub fn identity_recovery_request_json(
})
}

/// UniFFI compatible bridge to [`concordium_base::id::types::UnsignedCredentialDeploymentInfo<concordium_base::id::constants::IpPairing,concordium_base::id::constants::ArCurve,concordium_base::id::constants::AttributeKind>`],
/// providing the implementation of the UDL declaration of the same name.
/// The translation is performed using Serde.
#[derive(Debug, Deserialize, Serialize)]
pub struct AccountCredential {
#[serde(rename = "arData")]
Expand All @@ -420,12 +481,18 @@ pub struct AccountCredential {
pub revocation_threshold: u8,
}

/// UniFFI compatible bridge to [`concordium_base::id::types::ChainArData<concordium_base::id::constants::ArCurve>`],
/// providing the implementation of the UDL declaration of the same name.
/// The translation is performed using Serde.
#[derive(Debug, Deserialize, Serialize)]
pub struct ChainArData {
#[serde(rename = "encIdCredPubShare")]
pub end_id_cred_pub_share_hex: String,
}

/// UniFFI compatible bridge to [`concordium_base::id::types::Policy<concordium_base::id::constants::ArCurve,concordium_base::id::constants::AttributeKind> `],
/// providing the implementation of the UDL declaration of the same name.
/// The translation is performed using Serde.
#[derive(Debug, Deserialize, Serialize)]
pub struct Policy {
#[serde(rename = "createdAt")]
Expand All @@ -436,6 +503,9 @@ pub struct Policy {
pub valid_to_year_month: String,
}

/// UniFFI compatible bridge to [`concordium_base::id::types::IdOwnershipProofs<concordium_base::id::constants::IpPairing,concordium_base::id::constants::ArCurve>`],
/// providing the implementation of the UDL declaration of the same name.
/// The translation is performed using Serde.
#[derive(Debug, Deserialize, Serialize, PartialEq)]
pub struct Proofs {
#[serde(rename = "challenge")]
Expand All @@ -454,6 +524,7 @@ pub struct Proofs {
pub signature_hex: String,
}

/// Implements UDL definition of the same name.
pub fn account_credential(
params: AccountCredentialParameters,
) -> Result<AccountCredentialResult, ConcordiumWalletCryptoError> {
Expand Down Expand Up @@ -486,6 +557,7 @@ struct CredentialDeploymentPayloadHashInput {
credential: AccountCredential,
}

/// Implements UDL definition of the same name.
pub fn account_credential_deployment_hash_hex(
credential: AccountCredential,
expiry_unix_secs: u64,
Expand All @@ -507,6 +579,9 @@ pub fn account_credential_deployment_hash_hex(
})
}

/// UniFFI compatible bridge to [`CredentialDeploymentPayload`],
/// providing the implementation of the UDL declaration of the same name.
/// The translation is performed using Serde.
#[derive(Debug, Serialize)]
pub struct SignedAccountCredential {
#[serde(rename = "unsignedCdi")]
Expand All @@ -515,6 +590,7 @@ pub struct SignedAccountCredential {
pub signatures_hex: HashMap<u8, String>,
}

/// Implements UDL definition of the same name.
pub fn account_credential_deployment_signed_payload_hex(
credential: SignedAccountCredential,
) -> Result<String, ConcordiumWalletCryptoError> {
Expand Down
Loading

0 comments on commit 2248a46

Please sign in to comment.