cdk_signatory/
signatory.rs1use cdk_common::error::Error;
10use cdk_common::mint::MintKeySetInfo;
11use cdk_common::{
12 BlindSignature, BlindedMessage, CurrencyUnit, Id, KeySet, Keys, MintKeySet, Proof, PublicKey,
13};
14
15#[derive(Debug)]
16pub enum KeysetIdentifier {
18 Unit(CurrencyUnit),
20 Id(Id),
22}
23
24impl From<Id> for KeysetIdentifier {
25 fn from(id: Id) -> Self {
26 Self::Id(id)
27 }
28}
29
30impl From<CurrencyUnit> for KeysetIdentifier {
31 fn from(unit: CurrencyUnit) -> Self {
32 Self::Unit(unit)
33 }
34}
35
36#[derive(Debug, Clone)]
42pub struct RotateKeyArguments {
43 pub unit: CurrencyUnit,
45 pub amounts: Vec<u64>,
47 pub input_fee_ppk: u64,
49}
50
51#[derive(Debug, Clone)]
52pub struct SignatoryKeysets {
54 pub pubkey: PublicKey,
56 pub keysets: Vec<SignatoryKeySet>,
58}
59
60#[derive(Debug, Clone)]
61pub struct SignatoryKeySet {
66 pub id: Id,
68 pub unit: CurrencyUnit,
70 pub active: bool,
72 pub keys: Keys,
74 pub input_fee_ppk: u64,
76 pub final_expiry: Option<u64>,
78}
79
80impl From<&SignatoryKeySet> for KeySet {
81 fn from(val: &SignatoryKeySet) -> Self {
82 val.to_owned().into()
83 }
84}
85
86impl From<SignatoryKeySet> for KeySet {
87 fn from(val: SignatoryKeySet) -> Self {
88 KeySet {
89 id: val.id,
90 unit: val.unit,
91 keys: val.keys,
92 final_expiry: val.final_expiry,
93 }
94 }
95}
96
97impl From<&SignatoryKeySet> for MintKeySetInfo {
98 fn from(val: &SignatoryKeySet) -> Self {
99 val.to_owned().into()
100 }
101}
102
103impl From<SignatoryKeySet> for MintKeySetInfo {
104 fn from(val: SignatoryKeySet) -> Self {
105 MintKeySetInfo {
106 id: val.id,
107 unit: val.unit,
108 active: val.active,
109 input_fee_ppk: val.input_fee_ppk,
110 derivation_path: Default::default(),
111 derivation_path_index: Default::default(),
112 max_order: 0,
113 amounts: vec![],
114 final_expiry: val.final_expiry,
115 valid_from: 0,
116 }
117 }
118}
119
120impl From<&(MintKeySetInfo, MintKeySet)> for SignatoryKeySet {
121 fn from((info, key): &(MintKeySetInfo, MintKeySet)) -> Self {
122 Self {
123 id: info.id,
124 unit: key.unit.clone(),
125 active: info.active,
126 input_fee_ppk: info.input_fee_ppk,
127 keys: key.keys.clone().into(),
128 final_expiry: key.final_expiry,
129 }
130 }
131}
132
133#[async_trait::async_trait]
134pub trait Signatory {
136 fn name(&self) -> String;
139
140 async fn blind_sign(
144 &self,
145 blinded_messages: Vec<BlindedMessage>,
146 ) -> Result<Vec<BlindSignature>, Error>;
147
148 async fn verify_proofs(&self, proofs: Vec<Proof>) -> Result<(), Error>;
150
151 async fn keysets(&self) -> Result<SignatoryKeysets, Error>;
153
154 async fn rotate_keyset(&self, args: RotateKeyArguments) -> Result<SignatoryKeySet, Error>;
157}