dfns_sdk_rs/api/wallets/
delegated_client.rs

1// @dfns-sdk-rs/src/api/wallets/delegated_client.rs
2
3use super::types::*;
4use crate::{
5    client::{
6        base_auth_api::{
7            BaseAuthApi, CreateUserActionChallengeRequest, SignUserActionChallengeRequest,
8        },
9        delegated_api_client::DfnsDelegatedApiClientOptions,
10    },
11    error::DfnsError,
12    signer::UserActionChallenge,
13    utils::{
14        fetch::{simple_fetch, FetchOptions, HttpMethod},
15        url::{build_path_and_query, PathAndQueryParams},
16    },
17};
18use serde_json::json;
19use std::collections::HashMap;
20
21pub struct DelegatedWalletsClient {
22    api_options: DfnsDelegatedApiClientOptions,
23}
24
25impl DelegatedWalletsClient {
26    pub fn new(api_options: DfnsDelegatedApiClientOptions) -> Self {
27        Self { api_options }
28    }
29
30    pub async fn broadcast_transaction_init(
31        &self,
32        request: BroadcastTransactionRequest,
33    ) -> Result<UserActionChallenge, DfnsError> {
34        let path = build_path_and_query(
35            "/wallets/:walletId/transactions",
36            &PathAndQueryParams {
37                path: {
38                    let mut map = HashMap::new();
39                    map.insert("walletId".to_string(), request.wallet_id.clone());
40                    map
41                },
42                query: HashMap::new(),
43            },
44        );
45
46        BaseAuthApi::create_user_action_challenge(
47            CreateUserActionChallengeRequest {
48                user_action_http_method: HttpMethod::POST,
49                user_action_http_path: path,
50                user_action_payload: serde_json::to_string(&request.body)?,
51                user_action_server_kind: "Api".to_string(),
52            },
53            self.api_options.base.clone(),
54        )
55        .await
56    }
57
58    pub async fn broadcast_transaction_complete(
59        &self,
60        request: BroadcastTransactionRequest,
61        signed_challenge: SignUserActionChallengeRequest,
62    ) -> Result<BroadcastTransactionResponse, DfnsError> {
63        let path = build_path_and_query(
64            "/wallets/:walletId/transactions",
65            &PathAndQueryParams {
66                path: {
67                    let mut map = HashMap::new();
68                    map.insert("walletId".to_string(), request.wallet_id.clone());
69                    map
70                },
71                query: HashMap::new(),
72            },
73        );
74
75        let user_action = BaseAuthApi::sign_user_action_challenge(
76            signed_challenge,
77            self.api_options.base.clone(),
78        )
79        .await?
80        .user_action;
81
82        let mut headers = HashMap::new();
83        headers.insert("x-dfns-useraction".to_string(), user_action);
84
85        simple_fetch(
86            &path,
87            FetchOptions {
88                method: HttpMethod::POST,
89                headers: Some(headers),
90                body: Some(json!(request.body)),
91                api_options: self.api_options.base.clone(),
92            },
93        )
94        .await
95    }
96
97    pub async fn create_wallet_init(
98        &self,
99        request: CreateWalletRequest,
100    ) -> Result<UserActionChallenge, DfnsError> {
101        let path = build_path_and_query(
102            "/wallets",
103            &PathAndQueryParams {
104                path: HashMap::new(),
105                query: HashMap::new(),
106            },
107        );
108
109        BaseAuthApi::create_user_action_challenge(
110            CreateUserActionChallengeRequest {
111                user_action_http_method: HttpMethod::POST,
112                user_action_http_path: path,
113                user_action_payload: serde_json::to_string(&request.body)?,
114                user_action_server_kind: "Api".to_string(),
115            },
116            self.api_options.base.clone(),
117        )
118        .await
119    }
120
121    pub async fn create_wallet_complete(
122        &self,
123        request: CreateWalletRequest,
124        signed_challenge: SignUserActionChallengeRequest,
125    ) -> Result<CreateWalletResponse, DfnsError> {
126        let path = build_path_and_query(
127            "/wallets",
128            &PathAndQueryParams {
129                path: HashMap::new(),
130                query: HashMap::new(),
131            },
132        );
133
134        let user_action = BaseAuthApi::sign_user_action_challenge(
135            signed_challenge,
136            self.api_options.base.clone(),
137        )
138        .await?
139        .user_action;
140
141        let mut headers = HashMap::new();
142        headers.insert("x-dfns-useraction".to_string(), user_action);
143
144        simple_fetch(
145            &path,
146            FetchOptions {
147                method: HttpMethod::POST,
148                headers: Some(headers),
149                body: Some(json!(request.body)),
150                api_options: self.api_options.base.clone(),
151            },
152        )
153        .await
154    }
155
156    pub async fn delegate_wallet_init(
157        &self,
158        request: DelegateWalletRequest,
159    ) -> Result<UserActionChallenge, DfnsError> {
160        let path = build_path_and_query(
161            "/wallets/:walletId/delegate",
162            &PathAndQueryParams {
163                path: {
164                    let mut map = HashMap::new();
165                    map.insert("walletId".to_string(), request.wallet_id.clone());
166                    map
167                },
168                query: HashMap::new(),
169            },
170        );
171
172        BaseAuthApi::create_user_action_challenge(
173            CreateUserActionChallengeRequest {
174                user_action_http_method: HttpMethod::POST,
175                user_action_http_path: path,
176                user_action_payload: serde_json::to_string(&request.body)?,
177                user_action_server_kind: "Api".to_string(),
178            },
179            self.api_options.base.clone(),
180        )
181        .await
182    }
183
184    pub async fn delegate_wallet_complete(
185        &self,
186        request: DelegateWalletRequest,
187        signed_challenge: SignUserActionChallengeRequest,
188    ) -> Result<DelegateWalletResponse, DfnsError> {
189        let path = build_path_and_query(
190            "/wallets/:walletId/delegate",
191            &PathAndQueryParams {
192                path: {
193                    let mut map = HashMap::new();
194                    map.insert("walletId".to_string(), request.wallet_id.clone());
195                    map
196                },
197                query: HashMap::new(),
198            },
199        );
200
201        let user_action = BaseAuthApi::sign_user_action_challenge(
202            signed_challenge,
203            self.api_options.base.clone(),
204        )
205        .await?
206        .user_action;
207
208        let mut headers = HashMap::new();
209        headers.insert("x-dfns-useraction".to_string(), user_action);
210
211        simple_fetch(
212            &path,
213            FetchOptions {
214                method: HttpMethod::POST,
215                headers: Some(headers),
216                body: Some(json!(request.body)),
217                api_options: self.api_options.base.clone(),
218            },
219        )
220        .await
221    }
222
223    pub async fn export_wallet_init(
224        &self,
225        request: ExportWalletRequest,
226    ) -> Result<UserActionChallenge, DfnsError> {
227        let path = build_path_and_query(
228            "/wallets/:walletId/export",
229            &PathAndQueryParams {
230                path: {
231                    let mut map = HashMap::new();
232                    map.insert("walletId".to_string(), request.wallet_id.clone());
233                    map
234                },
235                query: HashMap::new(),
236            },
237        );
238
239        BaseAuthApi::create_user_action_challenge(
240            CreateUserActionChallengeRequest {
241                user_action_http_method: HttpMethod::POST,
242                user_action_http_path: path,
243                user_action_payload: serde_json::to_string(&request.body)?,
244                user_action_server_kind: "Api".to_string(),
245            },
246            self.api_options.base.clone(),
247        )
248        .await
249    }
250
251    pub async fn export_wallet_complete(
252        &self,
253        request: ExportWalletRequest,
254        signed_challenge: SignUserActionChallengeRequest,
255    ) -> Result<ExportWalletResponse, DfnsError> {
256        let path = build_path_and_query(
257            "/wallets/:walletId/export",
258            &PathAndQueryParams {
259                path: {
260                    let mut map = HashMap::new();
261                    map.insert("walletId".to_string(), request.wallet_id.clone());
262                    map
263                },
264                query: HashMap::new(),
265            },
266        );
267
268        let user_action = BaseAuthApi::sign_user_action_challenge(
269            signed_challenge,
270            self.api_options.base.clone(),
271        )
272        .await?
273        .user_action;
274
275        let mut headers = HashMap::new();
276        headers.insert("x-dfns-useraction".to_string(), user_action);
277
278        simple_fetch(
279            &path,
280            FetchOptions {
281                method: HttpMethod::POST,
282                headers: Some(headers),
283                body: Some(json!(request.body)),
284                api_options: self.api_options.base.clone(),
285            },
286        )
287        .await
288    }
289
290    pub async fn get_signature(
291        &self,
292        request: GetSignatureRequest,
293    ) -> Result<GetSignatureResponse, DfnsError> {
294        let path = build_path_and_query(
295            "/wallets/:walletId/signatures/:signatureId",
296            &PathAndQueryParams {
297                path: {
298                    let mut map = HashMap::new();
299                    map.insert("walletId".to_string(), request.wallet_id.clone());
300                    map.insert("signatureId".to_string(), request.signature_id.clone());
301                    map
302                },
303                query: HashMap::new(),
304            },
305        );
306
307        simple_fetch(
308            &path,
309            FetchOptions {
310                method: HttpMethod::GET,
311                headers: None,
312                body: None,
313                api_options: self.api_options.base.clone(),
314            },
315        )
316        .await
317    }
318
319    pub async fn get_transaction(
320        &self,
321        request: GetTransactionRequest,
322    ) -> Result<GetTransactionResponse, DfnsError> {
323        let path = build_path_and_query(
324            "/wallets/:walletId/transactions/:transactionId",
325            &PathAndQueryParams {
326                path: {
327                    let mut map = HashMap::new();
328                    map.insert("walletId".to_string(), request.wallet_id.clone());
329                    map.insert("transactionId".to_string(), request.transaction_id.clone());
330                    map
331                },
332                query: HashMap::new(),
333            },
334        );
335
336        simple_fetch(
337            &path,
338            FetchOptions {
339                method: HttpMethod::GET,
340                headers: None,
341                body: None,
342                api_options: self.api_options.base.clone(),
343            },
344        )
345        .await
346    }
347
348    pub async fn get_transfer(
349        &self,
350        request: GetTransferRequest,
351    ) -> Result<GetTransferResponse, DfnsError> {
352        let path = build_path_and_query(
353            "/wallets/:walletId/transfers/:transferId",
354            &PathAndQueryParams {
355                path: {
356                    let mut map = HashMap::new();
357                    map.insert("walletId".to_string(), request.wallet_id.clone());
358                    map.insert("transferId".to_string(), request.transfer_id.clone());
359                    map
360                },
361                query: HashMap::new(),
362            },
363        );
364
365        simple_fetch(
366            &path,
367            FetchOptions {
368                method: HttpMethod::GET,
369                headers: None,
370                body: None,
371                api_options: self.api_options.base.clone(),
372            },
373        )
374        .await
375    }
376
377    pub async fn get_wallet(
378        &self,
379        request: GetWalletRequest,
380    ) -> Result<GetWalletResponse, DfnsError> {
381        let path = build_path_and_query(
382            "/wallets/:walletId",
383            &PathAndQueryParams {
384                path: {
385                    let mut map = HashMap::new();
386                    map.insert("walletId".to_string(), request.wallet_id.clone());
387                    map
388                },
389                query: HashMap::new(),
390            },
391        );
392
393        simple_fetch(
394            &path,
395            FetchOptions {
396                method: HttpMethod::GET,
397                headers: None,
398                body: None,
399                api_options: self.api_options.base.clone(),
400            },
401        )
402        .await
403    }
404
405    pub async fn get_wallet_assets(
406        &self,
407        request: GetWalletAssetsRequest,
408    ) -> Result<GetWalletAssetsResponse, DfnsError> {
409        let path = build_path_and_query(
410            "/wallets/:walletId/assets",
411            &PathAndQueryParams {
412                path: {
413                    let mut map = HashMap::new();
414                    map.insert("walletId".to_string(), request.wallet_id.clone());
415                    map
416                },
417                query: request
418                    .query
419                    .map(|q| {
420                        let mut map = HashMap::new();
421                        if let Some(net_worth) = q.net_worth {
422                            map.insert("netWorth".to_string(), net_worth.to_string());
423                        }
424                        map
425                    })
426                    .unwrap_or_default(),
427            },
428        );
429
430        simple_fetch(
431            &path,
432            FetchOptions {
433                method: HttpMethod::GET,
434                headers: None,
435                body: None,
436                api_options: self.api_options.base.clone(),
437            },
438        )
439        .await
440    }
441
442    pub async fn get_wallet_history(
443        &self,
444        request: GetWalletHistoryRequest,
445    ) -> Result<GetWalletHistoryResponse, DfnsError> {
446        let path = build_path_and_query(
447            "/wallets/:walletId/history",
448            &PathAndQueryParams {
449                path: {
450                    let mut map = HashMap::new();
451                    map.insert("walletId".to_string(), request.wallet_id.clone());
452                    map
453                },
454                query: request
455                    .query
456                    .map(|q| {
457                        let mut map = HashMap::new();
458                        if let Some(contract) = q.contract {
459                            map.insert("contract".to_string(), contract);
460                        }
461                        if let Some(direction) = q.direction {
462                            map.insert("direction".to_string(), direction.to_string());
463                        }
464                        if let Some(kind) = q.kind {
465                            map.insert("kind".to_string(), kind.to_string());
466                        }
467                        if let Some(limit) = q.limit {
468                            map.insert("limit".to_string(), limit);
469                        }
470                        if let Some(token) = q.pagination_token {
471                            map.insert("paginationToken".to_string(), token);
472                        }
473                        map
474                    })
475                    .unwrap_or_default(),
476            },
477        );
478
479        simple_fetch(
480            &path,
481            FetchOptions {
482                method: HttpMethod::GET,
483                headers: None,
484                body: None,
485                api_options: self.api_options.base.clone(),
486            },
487        )
488        .await
489    }
490
491    pub async fn get_wallet_nfts(
492        &self,
493        request: GetWalletNftsRequest,
494    ) -> Result<GetWalletNftsResponse, DfnsError> {
495        let path = build_path_and_query(
496            "/wallets/:walletId/nfts",
497            &PathAndQueryParams {
498                path: {
499                    let mut map = HashMap::new();
500                    map.insert("walletId".to_string(), request.wallet_id.clone());
501                    map
502                },
503                query: HashMap::new(),
504            },
505        );
506
507        simple_fetch(
508            &path,
509            FetchOptions {
510                method: HttpMethod::GET,
511                headers: None,
512                body: None,
513                api_options: self.api_options.base.clone(),
514            },
515        )
516        .await
517    }
518
519    pub async fn import_wallet_init(
520        &self,
521        request: ImportWalletRequest,
522    ) -> Result<UserActionChallenge, DfnsError> {
523        let path = build_path_and_query(
524            "/wallets/import",
525            &PathAndQueryParams {
526                path: HashMap::new(),
527                query: HashMap::new(),
528            },
529        );
530
531        BaseAuthApi::create_user_action_challenge(
532            CreateUserActionChallengeRequest {
533                user_action_http_method: HttpMethod::POST,
534                user_action_http_path: path,
535                user_action_payload: serde_json::to_string(&request.body)?,
536                user_action_server_kind: "Api".to_string(),
537            },
538            self.api_options.base.clone(),
539        )
540        .await
541    }
542
543    pub async fn import_wallet_complete(
544        &self,
545        request: ImportWalletRequest,
546        signed_challenge: SignUserActionChallengeRequest,
547    ) -> Result<ImportWalletResponse, DfnsError> {
548        let path = build_path_and_query(
549            "/wallets/import",
550            &PathAndQueryParams {
551                path: HashMap::new(),
552                query: HashMap::new(),
553            },
554        );
555
556        let user_action = BaseAuthApi::sign_user_action_challenge(
557            signed_challenge,
558            self.api_options.base.clone(),
559        )
560        .await?
561        .user_action;
562
563        let mut headers = HashMap::new();
564        headers.insert("x-dfns-useraction".to_string(), user_action);
565
566        simple_fetch(
567            &path,
568            FetchOptions {
569                method: HttpMethod::POST,
570                headers: Some(headers),
571                body: Some(json!(request.body)),
572                api_options: self.api_options.base.clone(),
573            },
574        )
575        .await
576    }
577
578    pub async fn list_signatures(
579        &self,
580        request: ListSignaturesRequest,
581    ) -> Result<ListSignaturesResponse, DfnsError> {
582        let path = build_path_and_query(
583            "/wallets/:walletId/signatures",
584            &PathAndQueryParams {
585                path: {
586                    let mut map = HashMap::new();
587                    map.insert("walletId".to_string(), request.wallet_id.clone());
588                    map
589                },
590                query: request
591                    .query
592                    .map(|q| {
593                        let mut map = HashMap::new();
594                        if let Some(limit) = q.limit {
595                            map.insert("limit".to_string(), limit);
596                        }
597                        if let Some(token) = q.pagination_token {
598                            map.insert("paginationToken".to_string(), token);
599                        }
600                        map
601                    })
602                    .unwrap_or_default(),
603            },
604        );
605
606        simple_fetch(
607            &path,
608            FetchOptions {
609                method: HttpMethod::GET,
610                headers: None,
611                body: None,
612                api_options: self.api_options.base.clone(),
613            },
614        )
615        .await
616    }
617
618    pub async fn list_transactions(
619        &self,
620        request: ListTransactionsRequest,
621    ) -> Result<ListTransactionsResponse, DfnsError> {
622        let path = build_path_and_query(
623            "/wallets/:walletId/transactions",
624            &PathAndQueryParams {
625                path: {
626                    let mut map = HashMap::new();
627                    map.insert("walletId".to_string(), request.wallet_id.clone());
628                    map
629                },
630                query: request
631                    .query
632                    .map(|q| {
633                        let mut map = HashMap::new();
634                        if let Some(limit) = q.limit {
635                            map.insert("limit".to_string(), limit);
636                        }
637                        if let Some(token) = q.pagination_token {
638                            map.insert("paginationToken".to_string(), token);
639                        }
640                        map
641                    })
642                    .unwrap_or_default(),
643            },
644        );
645
646        simple_fetch(
647            &path,
648            FetchOptions {
649                method: HttpMethod::GET,
650                headers: None,
651                body: None,
652                api_options: self.api_options.base.clone(),
653            },
654        )
655        .await
656    }
657
658    pub async fn list_transfers(
659        &self,
660        request: ListTransfersRequest,
661    ) -> Result<ListTransfersResponse, DfnsError> {
662        let path = build_path_and_query(
663            "/wallets/:walletId/transfers",
664            &PathAndQueryParams {
665                path: {
666                    let mut map = HashMap::new();
667                    map.insert("walletId".to_string(), request.wallet_id.clone());
668                    map
669                },
670                query: request
671                    .query
672                    .map(|q| {
673                        let mut map = HashMap::new();
674                        if let Some(limit) = q.limit {
675                            map.insert("limit".to_string(), limit);
676                        }
677                        if let Some(token) = q.pagination_token {
678                            map.insert("paginationToken".to_string(), token);
679                        }
680                        map
681                    })
682                    .unwrap_or_default(),
683            },
684        );
685
686        simple_fetch(
687            &path,
688            FetchOptions {
689                method: HttpMethod::GET,
690                headers: None,
691                body: None,
692                api_options: self.api_options.base.clone(),
693            },
694        )
695        .await
696    }
697
698    pub async fn list_wallets(
699        &self,
700        request: Option<ListWalletsRequest>,
701    ) -> Result<ListWalletsResponse, DfnsError> {
702        let path = build_path_and_query(
703            "/wallets",
704            &PathAndQueryParams {
705                path: HashMap::new(),
706                query: request
707                    .and_then(|r| r.query)
708                    .map(|q| {
709                        let mut map = HashMap::new();
710                        if let Some(limit) = q.limit {
711                            map.insert("limit".to_string(), limit);
712                        }
713                        if let Some(owner_id) = q.owner_id {
714                            map.insert("ownerId".to_string(), owner_id);
715                        }
716                        if let Some(owner_username) = q.owner_username {
717                            map.insert("ownerUsername".to_string(), owner_username);
718                        }
719                        if let Some(token) = q.pagination_token {
720                            map.insert("paginationToken".to_string(), token);
721                        }
722                        map
723                    })
724                    .unwrap_or_default(),
725            },
726        );
727
728        simple_fetch(
729            &path,
730            FetchOptions {
731                method: HttpMethod::GET,
732                headers: None,
733                body: None,
734                api_options: self.api_options.base.clone(),
735            },
736        )
737        .await
738    }
739
740    pub async fn tag_wallet_init(
741        &self,
742        request: TagWalletRequest,
743    ) -> Result<UserActionChallenge, DfnsError> {
744        let path = build_path_and_query(
745            "/wallets/:walletId/tags",
746            &PathAndQueryParams {
747                path: {
748                    let mut map = HashMap::new();
749                    map.insert("walletId".to_string(), request.wallet_id.clone());
750                    map
751                },
752                query: HashMap::new(),
753            },
754        );
755
756        BaseAuthApi::create_user_action_challenge(
757            CreateUserActionChallengeRequest {
758                user_action_http_method: HttpMethod::PUT,
759                user_action_http_path: path,
760                user_action_payload: serde_json::to_string(&request.body)?,
761                user_action_server_kind: "Api".to_string(),
762            },
763            self.api_options.base.clone(),
764        )
765        .await
766    }
767
768    pub async fn tag_wallet_complete(
769        &self,
770        request: TagWalletRequest,
771        signed_challenge: SignUserActionChallengeRequest,
772    ) -> Result<TagWalletResponse, DfnsError> {
773        let path = build_path_and_query(
774            "/wallets/:walletId/tags",
775            &PathAndQueryParams {
776                path: {
777                    let mut map = HashMap::new();
778                    map.insert("walletId".to_string(), request.wallet_id.clone());
779                    map
780                },
781                query: HashMap::new(),
782            },
783        );
784
785        let user_action = BaseAuthApi::sign_user_action_challenge(
786            signed_challenge,
787            self.api_options.base.clone(),
788        )
789        .await?
790        .user_action;
791
792        let mut headers = HashMap::new();
793        headers.insert("x-dfns-useraction".to_string(), user_action);
794
795        simple_fetch(
796            &path,
797            FetchOptions {
798                method: HttpMethod::PUT,
799                headers: Some(headers),
800                body: Some(json!(request.body)),
801                api_options: self.api_options.base.clone(),
802            },
803        )
804        .await
805    }
806
807    pub async fn transfer_asset_init(
808        &self,
809        request: TransferAssetRequest,
810    ) -> Result<UserActionChallenge, DfnsError> {
811        let path = build_path_and_query(
812            "/wallets/:walletId/transfers",
813            &PathAndQueryParams {
814                path: {
815                    let mut map = HashMap::new();
816                    map.insert("walletId".to_string(), request.wallet_id.clone());
817                    map
818                },
819                query: HashMap::new(),
820            },
821        );
822
823        BaseAuthApi::create_user_action_challenge(
824            CreateUserActionChallengeRequest {
825                user_action_http_method: HttpMethod::POST,
826                user_action_http_path: path,
827                user_action_payload: serde_json::to_string(&request.body)?,
828                user_action_server_kind: "Api".to_string(),
829            },
830            self.api_options.base.clone(),
831        )
832        .await
833    }
834
835    pub async fn transfer_asset_complete(
836        &self,
837        request: TransferAssetRequest,
838        signed_challenge: SignUserActionChallengeRequest,
839    ) -> Result<TransferAssetResponse, DfnsError> {
840        let path = build_path_and_query(
841            "/wallets/:walletId/transfers",
842            &PathAndQueryParams {
843                path: {
844                    let mut map = HashMap::new();
845                    map.insert("walletId".to_string(), request.wallet_id.clone());
846                    map
847                },
848                query: HashMap::new(),
849            },
850        );
851
852        let user_action = BaseAuthApi::sign_user_action_challenge(
853            signed_challenge,
854            self.api_options.base.clone(),
855        )
856        .await?
857        .user_action;
858
859        let mut headers = HashMap::new();
860        headers.insert("x-dfns-useraction".to_string(), user_action);
861
862        simple_fetch(
863            &path,
864            FetchOptions {
865                method: HttpMethod::POST,
866                headers: Some(headers),
867                body: Some(json!(request.body)),
868                api_options: self.api_options.base.clone(),
869            },
870        )
871        .await
872    }
873
874    pub async fn untag_wallet_init(
875        &self,
876        request: UntagWalletRequest,
877    ) -> Result<UserActionChallenge, DfnsError> {
878        let path = build_path_and_query(
879            "/wallets/:walletId/tags",
880            &PathAndQueryParams {
881                path: {
882                    let mut map = HashMap::new();
883                    map.insert("walletId".to_string(), request.wallet_id.clone());
884                    map
885                },
886                query: HashMap::new(),
887            },
888        );
889
890        BaseAuthApi::create_user_action_challenge(
891            CreateUserActionChallengeRequest {
892                user_action_http_method: HttpMethod::DELETE,
893                user_action_http_path: path,
894                user_action_payload: serde_json::to_string(&request.body)?,
895                user_action_server_kind: "Api".to_string(),
896            },
897            self.api_options.base.clone(),
898        )
899        .await
900    }
901
902    pub async fn untag_wallet_complete(
903        &self,
904        request: UntagWalletRequest,
905        signed_challenge: SignUserActionChallengeRequest,
906    ) -> Result<UntagWalletResponse, DfnsError> {
907        let path = build_path_and_query(
908            "/wallets/:walletId/tags",
909            &PathAndQueryParams {
910                path: {
911                    let mut map = HashMap::new();
912                    map.insert("walletId".to_string(), request.wallet_id.clone());
913                    map
914                },
915                query: HashMap::new(),
916            },
917        );
918
919        let user_action = BaseAuthApi::sign_user_action_challenge(
920            signed_challenge,
921            self.api_options.base.clone(),
922        )
923        .await?
924        .user_action;
925
926        let mut headers = HashMap::new();
927        headers.insert("x-dfns-useraction".to_string(), user_action);
928
929        simple_fetch(
930            &path,
931            FetchOptions {
932                method: HttpMethod::DELETE,
933                headers: Some(headers),
934                body: Some(json!(request.body)),
935                api_options: self.api_options.base.clone(),
936            },
937        )
938        .await
939    }
940
941    pub async fn update_wallet_init(
942        &self,
943        request: UpdateWalletRequest,
944    ) -> Result<UserActionChallenge, DfnsError> {
945        let path = build_path_and_query(
946            "/wallets/:walletId",
947            &PathAndQueryParams {
948                path: {
949                    let mut map = HashMap::new();
950                    map.insert("walletId".to_string(), request.wallet_id.clone());
951                    map
952                },
953                query: HashMap::new(),
954            },
955        );
956
957        BaseAuthApi::create_user_action_challenge(
958            CreateUserActionChallengeRequest {
959                user_action_http_method: HttpMethod::PUT,
960                user_action_http_path: path,
961                user_action_payload: serde_json::to_string(&request.body)?,
962                user_action_server_kind: "Api".to_string(),
963            },
964            self.api_options.base.clone(),
965        )
966        .await
967    }
968
969    pub async fn update_wallet_complete(
970        &self,
971        request: UpdateWalletRequest,
972        signed_challenge: SignUserActionChallengeRequest,
973    ) -> Result<UpdateWalletResponse, DfnsError> {
974        let path = build_path_and_query(
975            "/wallets/:walletId",
976            &PathAndQueryParams {
977                path: {
978                    let mut map = HashMap::new();
979                    map.insert("walletId".to_string(), request.wallet_id.clone());
980                    map
981                },
982                query: HashMap::new(),
983            },
984        );
985
986        let user_action = BaseAuthApi::sign_user_action_challenge(
987            signed_challenge,
988            self.api_options.base.clone(),
989        )
990        .await?
991        .user_action;
992
993        let mut headers = HashMap::new();
994        headers.insert("x-dfns-useraction".to_string(), user_action);
995
996        simple_fetch(
997            &path,
998            FetchOptions {
999                method: HttpMethod::PUT,
1000                headers: Some(headers),
1001                body: Some(json!(request.body)),
1002                api_options: self.api_options.base.clone(),
1003            },
1004        )
1005        .await
1006    }
1007
1008    pub async fn generate_signature_init(
1009        &self,
1010        request: GenerateSignatureRequest,
1011    ) -> Result<UserActionChallenge, DfnsError> {
1012        let path = build_path_and_query(
1013            "/wallets/:walletId/signatures",
1014            &PathAndQueryParams {
1015                path: {
1016                    let mut map = HashMap::new();
1017                    map.insert("walletId".to_string(), request.wallet_id.clone());
1018                    map
1019                },
1020                query: HashMap::new(),
1021            },
1022        );
1023
1024        BaseAuthApi::create_user_action_challenge(
1025            CreateUserActionChallengeRequest {
1026                user_action_http_method: HttpMethod::POST,
1027                user_action_http_path: path,
1028                user_action_payload: serde_json::to_string(&request.body)?,
1029                user_action_server_kind: "Api".to_string(),
1030            },
1031            self.api_options.base.clone(),
1032        )
1033        .await
1034    }
1035
1036    pub async fn generate_signature_complete(
1037        &self,
1038        request: GenerateSignatureRequest,
1039        signed_challenge: SignUserActionChallengeRequest,
1040    ) -> Result<GenerateSignatureResponse, DfnsError> {
1041        let path = build_path_and_query(
1042            "/wallets/:walletId/signatures",
1043            &PathAndQueryParams {
1044                path: {
1045                    let mut map = HashMap::new();
1046                    map.insert("walletId".to_string(), request.wallet_id.clone());
1047                    map
1048                },
1049                query: HashMap::new(),
1050            },
1051        );
1052
1053        let user_action = BaseAuthApi::sign_user_action_challenge(
1054            signed_challenge,
1055            self.api_options.base.clone(),
1056        )
1057        .await?
1058        .user_action;
1059
1060        let mut headers = HashMap::new();
1061        headers.insert("x-dfns-useraction".to_string(), user_action);
1062
1063        simple_fetch(
1064            &path,
1065            FetchOptions {
1066                method: HttpMethod::POST,
1067                headers: Some(headers),
1068                body: Some(json!(request.body)),
1069                api_options: self.api_options.base.clone(),
1070            },
1071        )
1072        .await
1073    }
1074}