siera_cloudagent_python/cloudagent/
wallet.rs1use crate::agent::CloudAgentPython;
2use crate::fill_query;
3use async_trait::async_trait;
4use serde::{Deserialize, Serialize};
5use serde_json::json;
6use siera_agent::error::Result;
7use siera_agent::modules::wallet::{
8 CreateLocalDidOptions, Did, DidEndpoint, DidList, SetDidEndpointOptions, WalletModule,
9};
10
11#[derive(Serialize, Deserialize, Debug)]
13struct Response {
14 result: Did,
16}
17
18#[derive(Debug, Deserialize, Serialize)]
21pub struct DidListResults {
22 results: DidList,
24}
25
26#[async_trait]
27impl WalletModule for CloudAgentPython {
28 async fn get_wallet_dids(&self, options: Did) -> Result<DidList> {
29 let url = self.create_url(&["wallet", "did"])?;
30
31 let query = fill_query!(options, did, key_type, method, posture, verkey);
32
33 let did_list: DidListResults = self.get(url, Some(query)).await?;
34
35 Ok(did_list.results)
36 }
37
38 async fn create_local_did(&self, options: CreateLocalDidOptions) -> Result<Did> {
39 let url = self.create_url(&["wallet", "did", "create"])?;
40
41 let body = json!({
42 "method": options.method,
43 "options": options.options
44 });
45
46 self.post(url, None, Some(body)).await
47 }
48
49 async fn rotate_keypair(&self, did: String) -> Result<()> {
50 let url = self.create_url(&["wallet", "did", "local", "rotate-keypair"])?;
51
52 self.patch(url, Some(Vec::from([("did", did)]))).await
53 }
54
55 async fn fetch_public_did(&self) -> Result<Did> {
56 let url = self.create_url(&["wallet", "did", "public"])?;
57
58 self.get(url, None).await
59 }
60
61 async fn assign_public_did(&self, did: String) -> Result<Did> {
62 let url = self.create_url(&["wallet", "did", "public"])?;
63
64 self.post(url, Some(Vec::from([("did", did)])), None).await
65 }
66
67 async fn fetch_did_endpoint(&self, did: String) -> Result<DidEndpoint> {
68 let url = self.create_url(&["wallet", "fetch-did-endpoint"])?;
69
70 self.get(url, Some(Vec::from([("did", did)]))).await
71 }
72
73 async fn set_did_endpoint(&self, options: SetDidEndpointOptions) -> Result<()> {
74 let url = self.create_url(&["wallet", "set-did-endpoint"])?;
75
76 let body = json!({
77 "did": options.did,
78 "endpoint": options.endpoint,
79 "endpoint_type": options.endpoint_type
80 });
81
82 self.post(url, None, Some(body)).await
83 }
84}