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

Feat/164/json output #240

Closed
wants to merge 12 commits into from
Closed
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;
108 changes: 108 additions & 0 deletions crates/agent/src/modules/wallet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
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, bls1238g2
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
/// Whether DID is 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 {
/// List of all the ids of every schema that the cloudagent has registered
pub results: Vec<Did>,
}

/// Response from the cloudagent when requesting info about dids
/// of a wallet
#[derive(Debug, Deserialize, Serialize)]
pub struct DidResult {
/// Single definition information about a DID of a wallet
pub result: 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, bls1238g2
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, bls1238g2
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<Vec<Did>>;

/// 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<()>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use siera_agent::modules::credential_definition::CredentialDefinitionModule;
use siera_agent::modules::schema::{SchemaCreateOptions, SchemaModule};

use colored::Colorize;
use siera_logger::pretty_stringify_obj;

use crate::error::Result;

Expand Down Expand Up @@ -51,15 +52,19 @@ impl<'a> CreateCredentialDefinition<'a> {
..CredentialDefinitionCreateOptions::default()
};

log!("{} the credential definition...", "Registering".cyan());
log_info!("{} the credential definition...", "Registering".cyan());
morrieinmaas marked this conversation as resolved.
Show resolved Hide resolved
// Create or fetch the credential definition
let credential_definition = CredentialDefinitionModule::create(agent, options).await?;

log!(
log_info!(
"{} credential definition with id {}",
"Created".green(),
String::from(&credential_definition.credential_definition_id).green()
);
log!(
"{}",
pretty_stringify_obj(&credential_definition.credential_definition_id)
);
copy!("{}", credential_definition.credential_definition_id);
Ok(credential_definition)
}
Expand Down
8 changes: 5 additions & 3 deletions crates/automations/src/automations/credential_offer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use siera_agent::modules::{
credential_definition::CredentialDefinitionModule,
schema::SchemaModule,
};
use siera_logger::pretty_stringify_obj;
use std::collections::HashMap;

/// Credential offer Automation which offers an prebuilt credential to a connection
Expand All @@ -24,7 +25,7 @@ impl CredentialOfferAutomation {
/// 1. Create a connection
/// 2. Register the schema
/// 3. Register the credential definition
/// 4. Offer the credentail to the connection id
/// 4. Offer the credential to the connection id
///
/// # Errors
///
Expand All @@ -51,7 +52,7 @@ impl CredentialOfferAutomation {
let attribute_values: Vec<String> = self.attributes.values().cloned().collect();

// Check if it as a valid connection
log!("{} the connection...", "Fetching".cyan());
log_info!("{} the connection...", "Fetching".cyan());
let connection = ConnectionModule::get_by_id(&agent, self.connection_id.clone()).await?;
if connection.state != "active" && connection.state != "response" {
return Err(Error::ConnectionNotReady.into());
Expand All @@ -65,7 +66,7 @@ impl CredentialOfferAutomation {

let credential_definition = create_credential_definition.execute(&agent).await?;

log!("{} the credential...", "Offering".cyan());
log_info!("{} the credential...", "Offering".cyan());
let credential_offer_response = agent
.send_offer(CredentialOfferOptions {
keys: attribute_keys.iter().map(|x| String::from(*x)).collect(),
Expand All @@ -77,6 +78,7 @@ impl CredentialOfferAutomation {

log_trace!("Automation completed and offered a credential");
log_trace!("{:#?}", credential_offer_response);
log!("{}", pretty_stringify_obj(credential_offer_response));
Ok(())
}
}
8 changes: 6 additions & 2 deletions 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 @@ -39,7 +39,7 @@ pub struct Cli {
pub copy: bool,

/// Whether the output should be quiet
#[clap(long, short, help = HelpStrings::Quiet, conflicts_with = "verbose")]
#[clap(long, short, help = HelpStrings::Quiet, conflicts_with = "verbose", conflicts_with = "json")]
pub quiet: bool,

/// Which config path to use instead of the default one
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, bls1238g2",
Self::WalletEndpoint => "The endpoint url",
Self::WalletEndpointType => "The endpoint type",
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, bls1238g2",
Self::WalletListMethod => "DID method to query for. e.g. sov to only fetch indy/sov DIDs Available values : key, sov",
Self::WalletListPosture => "Whether DID is 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 => "E.g. 'Endpoint'",
Self::WalletSetPublic => "Set the public DID of the wallet",
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions crates/cli/src/modules/basic_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ use crate::help_strings::HelpStrings;
use crate::utils::loader::{Loader, LoaderVariant};
use clap::Args;
use siera_agent::modules::basic_message::{BasicMessageModule, SendBasicMessageOptions};
use siera_logger::pretty_stringify_obj;

/// Basic Message options and flags
#[derive(Args)]
#[clap(about = HelpStrings::Message)]
pub struct BasicMessageOptions {
/// The connection id to which to send the connectoon to
/// The connection id to which to send the connection to
#[clap(short = 'i', long, help=HelpStrings::MessageId)]
connection_id: String,

Expand All @@ -22,13 +23,14 @@ pub async fn parse_basic_message_args(
options: &BasicMessageOptions,
agent: impl BasicMessageModule + Send + Sync,
) -> Result<()> {
let loader = Loader::start(&LoaderVariant::default());
let loader: Loader = Loader::start(&LoaderVariant::default());
let send_options = SendBasicMessageOptions {
connection_id: options.connection_id.clone(),
message: options.message.clone(),
};
agent.send_message(send_options).await.map(|_| {
agent.send_message(send_options).await.map(|response| {
loader.stop();
log!("Successfully sent message")
log_info!("Successfully sent message");
log!("{}", pretty_stringify_obj(response));
})
}
8 changes: 4 additions & 4 deletions crates/cli/src/modules/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub async fn parse_connection_args(
options: &ConnectionOptions,
agent: impl ConnectionModule + Send + Sync,
) -> Result<()> {
let loader = Loader::start(&LoaderVariant::default());
let loader: Loader = Loader::start(&LoaderVariant::default());

match &options.commands {
ConnectionSubcommands::Invite {
Expand All @@ -117,13 +117,13 @@ pub async fn parse_connection_args(
agent.create_invitation(options).await.map(|response| {
loader.stop();
log_info!("Created invite with connection id:");
log!("{}", response.id);
log_info!("{}", response.id);
if *qr {
log_info!("Scan this QR code to accept the invitation:\n");
print_qr_code(&response.invitation_url).unwrap();
} else {
log_info!("Another agent can use this URL to accept your invitation:");
log!("{}", &response.invitation_url);
log!("{}", pretty_stringify_obj(&response.invitation_url));
}
copy!("{}", response.invitation_url);
})
Expand All @@ -136,7 +136,7 @@ pub async fn parse_connection_args(
.map(|connection| {
log_debug!("{}", pretty_stringify_obj(&connection));
log_info!("Fetched connection id:");
log!("{}", connection.id);
log!("{}", pretty_stringify_obj(connection.id));
})
}
ConnectionSubcommands::List {
Expand Down
6 changes: 3 additions & 3 deletions crates/cli/src/modules/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub async fn parse_credentials_args(
commands: &CredentialSubcommands,
agent: impl CredentialModule + Send + Sync,
) -> Result<()> {
let loader = Loader::start(&LoaderVariant::default());
let loader: Loader = Loader::start(&LoaderVariant::default());
morrieinmaas marked this conversation as resolved.
Show resolved Hide resolved
match commands {
CredentialSubcommands::Offer {
connection_id,
Expand All @@ -66,8 +66,8 @@ pub async fn parse_credentials_args(
agent.send_offer(options).await.map(|cred| {
loader.stop();
log_debug!("{}", pretty_stringify_obj(&cred));
log_info!("Successefully offered a credential. Credential exchange id: ",);
log!("{}", cred.credential_exchange_id);
log_info!("Successfully offered a credential. Credential exchange id: ",);
morrieinmaas marked this conversation as resolved.
Show resolved Hide resolved
log!("{}", pretty_stringify_obj(cred.credential_exchange_id));
})
}
}
Expand Down
Loading