-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TODO: * refactor and rename a a few things Signed-off-by: Moriarty <[email protected]>
- Loading branch information
Moriarty
committed
Dec 13, 2022
1 parent
bb3d00f
commit d02d78c
Showing
8 changed files
with
134 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,98 @@ | ||
use crate::agent::CloudAgentPython; | ||
use crate::fill_query; | ||
use async_trait::async_trait; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::json; | ||
use siera_agent::error::Result; | ||
use siera_agent::modules::wallet::{WalletCreate, WalletCreateOptions, WalletModule}; | ||
use siera_agent::modules::wallet::{ | ||
CreateLocalDidOptions, DidEndpointResult, DidList, DidSpec, SetDidEndpointOptions, | ||
SingleDidResultResponse, WalletModule, | ||
}; | ||
|
||
/// Response from the cloudagent that contains the wrapped schema | ||
#[derive(Serialize, Deserialize, Debug)] | ||
struct Response { | ||
/// Schema wrapper | ||
schema: Schema, | ||
/// Wallet wrapper | ||
result: DidSpec, | ||
} | ||
|
||
#[async_trait] | ||
impl WalletModule for CloudAgentPython { | ||
async fn create(&self, options: SchemaCreateOptions) -> Result<Schema> { | ||
let url = self.create_url(&["schemas"])?; | ||
async fn get_wallet_dids(&self, options: DidSpec) -> Result<DidList> { | ||
let url = self.create_url(&["wallet", "did"])?; | ||
|
||
let query = fill_query!(options, did, key_type, method, posture, verkey); | ||
// let body = json!({ | ||
// "attributes": options.attributes, | ||
// "schema_name": options.name, | ||
// "schema_version": options.version | ||
// }); | ||
|
||
let did_list: DidList = self.get(url, Some(query)).await?; | ||
|
||
Ok(did_list) | ||
} | ||
|
||
async fn create_local_did( | ||
&self, | ||
options: CreateLocalDidOptions, | ||
) -> Result<SingleDidResultResponse> { | ||
let url = self.create_url(&["wallet", "did", "create"])?; | ||
|
||
let body = json!({ | ||
"attributes": options.attributes, | ||
"schema_name": options.name, | ||
"schema_version": options.version | ||
|
||
"method": options.method, | ||
"options": options.options | ||
}); | ||
|
||
Ok(self.post::<Response>(url, None, Some(body)).await?.schema) | ||
self.post(url, None, Some(body)).await | ||
} | ||
|
||
async fn rotate_keypair(&self, did: String) -> Result<()> { | ||
let url = self.create_url(&["wallet", "did", "local", "rotate-keypair"])?; | ||
|
||
let _rotated_keypair: SingleDidResultResponse = | ||
self.patch(url, Some(Vec::from([("did", did)]))).await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn fetch_public_did(&self) -> Result<DidSpec> { | ||
let url = self.create_url(&["wallet", "did", "public"])?; | ||
|
||
let public_did: SingleDidResultResponse = self.get(url, None).await?; | ||
|
||
Ok(public_did.result) | ||
} | ||
|
||
async fn assign_public_did(&self, did: String) -> Result<DidSpec> { | ||
let url = self.create_url(&["wallet", "did", "public"])?; | ||
|
||
let public_did_assign_result: SingleDidResultResponse = self | ||
.post(url, Some(Vec::from([("did", did)])), None) | ||
.await?; | ||
|
||
Ok(public_did_assign_result.result) | ||
} | ||
|
||
async fn get_by_id(&self, id: String) -> Result<Schema> { | ||
let url = self.create_url(&["schemas", &id])?; | ||
Ok(self.get::<Response>(url, None).await?.schema) | ||
async fn fetch_did_endpoint(&self, did: String) -> Result<DidEndpointResult> { | ||
let url = self.create_url(&["wallet", "fetch-did-endpoint"])?; | ||
|
||
let did_endpoint: DidEndpointResult = | ||
self.get(url, Some(Vec::from([("did", did)]))).await?; | ||
|
||
Ok(did_endpoint) | ||
} | ||
|
||
async fn get_all(&self) -> Result<SchemasGetAllResponse> { | ||
let url = self.create_url(&["schemas", "created"])?; | ||
self.get(url, None).await | ||
async fn set_did_endpoint(&self, options: SetDidEndpointOptions) -> Result<()> { | ||
let url = self.create_url(&["wallet", "set-did-endpoint"])?; | ||
|
||
let body = json!({ | ||
"did": options.did, | ||
"endpoint": options.endpoint, | ||
"endpoint_type": options.endpoint_type | ||
}); | ||
|
||
self.post(url, None, Some(body)).await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters