Skip to content

Commit

Permalink
Feat/162/add wallet endpoints (#239)
Browse files Browse the repository at this point in the history
Signed-off-by: Moriarty <[email protected]>
  • Loading branch information
morrieinmaas authored Dec 17, 2022
1 parent 5e6f8bf commit c563262
Show file tree
Hide file tree
Showing 14 changed files with 472 additions and 14 deletions.
2 changes: 1 addition & 1 deletion crates/afj-rest/src/cloudagent/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use siera_agent::modules::connection::{
};

/// Create invitation response
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Response {
/// Invitation url
Expand Down
4 changes: 2 additions & 2 deletions crates/agent/src/modules/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct ConnectionGetAllOptions {
}

/// Create invitation response
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct Invitation {
/// Invitation url
#[serde(alias = "invitationUrl")]
Expand All @@ -46,7 +46,7 @@ pub struct Invitation {
}

/// A single connection structure
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Connection {
/// The connection id used for further functionality
#[serde(alias = "connection_id")]
Expand Down
3 changes: 3 additions & 0 deletions crates/agent/src/modules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ pub mod schema;
/// Multitenancy module for a generic cloudagent
pub mod multitenancy;

/// wallet module for a generic cloudagent
pub mod wallet;

/// webhook module for a generic cloudagent
pub mod webhook;
105 changes: 105 additions & 0 deletions crates/agent/src/modules/wallet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
use crate::error::Result;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};

/// Options that are supplied when querying a wallet for DIDs
#[derive(Debug, Deserialize, Serialize)]
pub struct Did {
/// The DID of interest
pub did: Option<String>,

// TODO: enum
/// The key type to query for eg. ed25519, bls12381g2
pub key_type: Option<String>,

// TODO: enum
/// DID method to query for. e.g. sov to only fetch indy/sov DIDs Available values : key, sov
pub method: Option<String>,

// TODO: enum
/// The DID posture specifying whether the DID is
/// the current public DID,
/// posted to ledger but current public DID,
/// or local to the wallet
/// Available values : public, posted, wallet_only
pub posture: Option<String>,

/// The verification key of interest
pub verkey: Option<String>,
}

/// Response from the cloudagent when requesting info about dids
/// of a wallet
#[derive(Debug, Deserialize, Serialize)]
pub struct DidList(Vec<Did>);

/// Response from the cloudagent when requesting info about dids
/// of a wallet
#[derive(Debug, Deserialize, Serialize)]
pub struct DidResult(Did);

/// Key type in a JSON format k,v pair
#[derive(Debug, Deserialize, Serialize)]
pub struct KeyType {
// TODO: enum
/// The key type to query for eg. ed25519, bls12381g2
pub key_type: String,
}

/// Options that are supplied when querying a wallet for DIDs
#[derive(Debug, Deserialize, Serialize)]
pub struct CreateLocalDidOptions {
/// DID method to query for. e.g. sov to only fetch indy/sov DIDs Available values : key, sov
pub method: String,

/// The key type to query for eg. ed25519, bls12381g2
pub options: KeyType,
}

/// Options that are supplied when querying a wallet for DIDs
#[derive(Debug, Deserialize, Serialize)]
pub struct DidEndpoint {
/// The DID of interest
pub did: String,

/// The endpoint url
pub endpoint: String,
}

/// Options that are supplied when querying a wallet for DIDs
#[derive(Debug, Deserialize, Serialize)]
pub struct SetDidEndpointOptions {
/// The DID of interest
pub did: String,

/// The endpoint url
pub endpoint: String,

///The endpoint type eg. 'Endpoint'
pub endpoint_type: String,
}

/// Generic cloudagent basic message module
#[async_trait]
pub trait WalletModule {
/// Query a wallet for DIDs
async fn get_wallet_dids(&self, options: Did) -> Result<DidList>;

/// Create a local DID
async fn create_local_did(&self, options: CreateLocalDidOptions) -> Result<Did>;

/// Rotate key pair
async fn rotate_keypair(&self, did: String) -> Result<()>;

/// Fetch public did
async fn fetch_public_did(&self) -> Result<Did>;

/// Assign the current public DID
async fn assign_public_did(&self, did: String) -> Result<Did>;

/// Query DID endpoint of wallet
async fn fetch_did_endpoint(&self, did: String) -> Result<DidEndpoint>;

/// Set DID endpoint of wallet
async fn set_did_endpoint(&self, options: SetDidEndpointOptions) -> Result<()>;
}
6 changes: 5 additions & 1 deletion crates/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::modules::{
basic_message::BasicMessageOptions, configuration::ConfigurationOptions,
connection::ConnectionOptions, credential::CredentialOptions,
credential_definition::CredentialDefinitionOptions, feature::FeaturesOptions, oob::OobOptions,
proof::ProofOptions, schema::SchemaOptions, webhook::WebhookOptions,
proof::ProofOptions, schema::SchemaOptions, wallet::WalletOptions, webhook::WebhookOptions,
};

/// Main command with options, flags and subcommands
Expand Down Expand Up @@ -97,6 +97,9 @@ pub enum Commands {

/// Multitenancy subcommands
Multitenancy(MultitenancyOptions),

/// Wallet subcommands
Wallet(WalletOptions),
}

impl From<Commands> for String {
Expand All @@ -114,6 +117,7 @@ impl From<Commands> for String {
Commands::Configuration(_) => "Configuration",
Commands::Proof(_) => "Proof",
Commands::Multitenancy(_) => "Multitenancy",
Commands::Wallet(_) => "Wallet",
};

Self::from(s)
Expand Down
37 changes: 37 additions & 0 deletions crates/cli/src/help_strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,25 @@ pub enum HelpStrings {
AutomationCreateCredentialDefinitionName,
AutomationCreateCredentialDefinitionAttributes,
AutomationCreateCredentialDefinitionVersion,

// Wallet
Wallet,
WalletCreate,
WalletCreateMethod,
WalletCreateOptions,
WalletEndpoint,
WalletEndpointType,
WalletFetchDidEndpoint,
WalletGetPublic,
WalletList,
WalletListDid,
WalletListKeyType,
WalletListMethod,
WalletListPosture,
WalletListVerkey,
WalletRotateKeypair,
WalletSetEndpoint,
WalletSetPublic,
}

impl From<HelpStrings> for Option<&str> {
Expand Down Expand Up @@ -251,6 +270,24 @@ impl HelpStrings {
Self::MultitenancyCreate => "Create a new sub agent",
Self::MultitenancyRemove => "Remove a sub agent",
Self::MultitenancyRemoveWalletId => "Remove the wallet by id of a sub agent",

Self::Wallet => "Interacts with a wallet",
Self::WalletCreate => "Create a local DID",
Self::WalletCreateMethod => "The did method. One of 'key' or 'sov'",
Self::WalletCreateOptions => "Key types are e.g. ed25519, bls12381g2",
Self::WalletEndpoint => "The endpoint url",
Self::WalletEndpointType => "The endpoint type. E.g. 'Endpoint'",
Self::WalletFetchDidEndpoint => "Get the endpoint information associated with a DID",
Self::WalletGetPublic => "Get the public DID of the wallet",
Self::WalletList => "Query for DID associated with a wallet",
Self::WalletListDid => "A DID to query for",
Self::WalletListKeyType => "Key types are e.g. ed25519, bls12381g2",
Self::WalletListMethod => "DID method to query for. e.g. sov to only fetch indy/sov DIDs Available values : key, sov",
Self::WalletListPosture => "The DID posture specifying whether the DID is the current public DID, posted to ledger but current public DID, or local to the wallet. Available values : public, posted, wallet_only",
Self::WalletListVerkey => "The verification key of interest",
Self::WalletRotateKeypair => "Rotate the keypair for a DID",
Self::WalletSetEndpoint => "Set the endpoint information for a DID",
Self::WalletSetPublic => "Set the public DID of the wallet",
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/cli/src/modules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ pub mod schema;
/// Module for multitenancy
pub mod multitenancy;

/// Module for wallet
pub mod wallet;

/// Module for webhook
pub mod webhook;
Loading

0 comments on commit c563262

Please sign in to comment.