123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- //! Signatory mod
- //!
- //! This module abstract all the key related operations, defining an interface for the necessary
- //! operations, to be implemented by the different signatory implementations.
- //!
- //! There is an in memory implementation, when the keys are stored in memory, in the same process,
- //! but it is isolated from the rest of the application, and they communicate through a channel with
- //! the defined API.
- use cdk_common::error::Error;
- use cdk_common::mint::MintKeySetInfo;
- use cdk_common::{
- BlindSignature, BlindedMessage, CurrencyUnit, Id, KeySet, Keys, MintKeySet, Proof, PublicKey,
- };
- #[derive(Debug)]
- /// Type alias to make the keyset info API more useful, queryable by unit and Id
- pub enum KeysetIdentifier {
- /// Mint Keyset by unit
- Unit(CurrencyUnit),
- /// Mint Keyset by Id
- Id(Id),
- }
- impl From<Id> for KeysetIdentifier {
- fn from(id: Id) -> Self {
- Self::Id(id)
- }
- }
- impl From<CurrencyUnit> for KeysetIdentifier {
- fn from(unit: CurrencyUnit) -> Self {
- Self::Unit(unit)
- }
- }
- /// RotateKeyArguments
- ///
- /// This struct is used to pass the arguments to the rotate_keyset function
- ///
- /// TODO: Change argument to accept a vector of Amount instead of max_order.
- #[derive(Debug, Clone)]
- pub struct RotateKeyArguments {
- /// Unit
- pub unit: CurrencyUnit,
- /// Max order
- pub max_order: u8,
- /// Input fee
- pub input_fee_ppk: u64,
- }
- #[derive(Debug, Clone)]
- /// Signatory keysets
- pub struct SignatoryKeysets {
- /// The public key
- pub pubkey: PublicKey,
- /// The list of keysets
- pub keysets: Vec<SignatoryKeySet>,
- }
- #[derive(Debug, Clone)]
- /// SignatoryKeySet
- ///
- /// This struct is used to represent a keyset and its info, pretty much all the information but the
- /// private key, that will never leave the signatory
- pub struct SignatoryKeySet {
- /// The keyset Id
- pub id: Id,
- /// The Currency Unit
- pub unit: CurrencyUnit,
- /// Whether to set it as active or not
- pub active: bool,
- /// The list of public keys
- pub keys: Keys,
- /// Information about the fee per public key
- pub input_fee_ppk: u64,
- }
- impl From<&SignatoryKeySet> for KeySet {
- fn from(val: &SignatoryKeySet) -> Self {
- val.to_owned().into()
- }
- }
- impl From<SignatoryKeySet> for KeySet {
- fn from(val: SignatoryKeySet) -> Self {
- KeySet {
- id: val.id,
- unit: val.unit,
- keys: val.keys,
- }
- }
- }
- impl From<&SignatoryKeySet> for MintKeySetInfo {
- fn from(val: &SignatoryKeySet) -> Self {
- val.to_owned().into()
- }
- }
- impl From<SignatoryKeySet> for MintKeySetInfo {
- fn from(val: SignatoryKeySet) -> Self {
- MintKeySetInfo {
- id: val.id,
- unit: val.unit,
- active: val.active,
- input_fee_ppk: val.input_fee_ppk,
- derivation_path: Default::default(),
- derivation_path_index: Default::default(),
- max_order: 0,
- valid_to: None,
- valid_from: 0,
- }
- }
- }
- impl From<&(MintKeySetInfo, MintKeySet)> for SignatoryKeySet {
- fn from((info, key): &(MintKeySetInfo, MintKeySet)) -> Self {
- Self {
- id: info.id,
- unit: key.unit.clone(),
- active: info.active,
- input_fee_ppk: info.input_fee_ppk,
- keys: key.keys.clone().into(),
- }
- }
- }
- #[async_trait::async_trait]
- /// Signatory trait
- pub trait Signatory {
- /// The Signatory implementation name. This may be exposed, so being as discreet as possible is
- /// advised.
- fn name(&self) -> String;
- /// Blind sign a message.
- ///
- /// The message can be for a coin or an auth token.
- async fn blind_sign(
- &self,
- blinded_messages: Vec<BlindedMessage>,
- ) -> Result<Vec<BlindSignature>, Error>;
- /// Verify [`Proof`] meets conditions and is signed
- async fn verify_proofs(&self, proofs: Vec<Proof>) -> Result<(), Error>;
- /// Retrieve the list of all mint keysets
- async fn keysets(&self) -> Result<SignatoryKeysets, Error>;
- /// Add current keyset to inactive keysets
- /// Generate new keyset
- async fn rotate_keyset(&self, args: RotateKeyArguments) -> Result<SignatoryKeySet, Error>;
- }
|