proof.rs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. use std::ops::Deref;
  2. use std::sync::Arc;
  3. use cashu::nuts::nut00::Proof as ProofSdk;
  4. use crate::types::Secret;
  5. use crate::{Amount, Id, PublicKey};
  6. pub struct Proof {
  7. inner: ProofSdk,
  8. }
  9. impl Deref for Proof {
  10. type Target = ProofSdk;
  11. fn deref(&self) -> &Self::Target {
  12. &self.inner
  13. }
  14. }
  15. impl Proof {
  16. pub fn new(
  17. amount: Arc<Amount>,
  18. secret: Arc<Secret>,
  19. c: Arc<PublicKey>,
  20. keyset_id: Arc<Id>,
  21. ) -> Self {
  22. Self {
  23. inner: ProofSdk {
  24. amount: *amount.as_ref().deref(),
  25. secret: secret.as_ref().deref().clone(),
  26. c: c.as_ref().deref().clone(),
  27. keyset_id: *keyset_id.as_ref().deref(),
  28. },
  29. }
  30. }
  31. pub fn amount(&self) -> Arc<Amount> {
  32. Arc::new(self.inner.amount.into())
  33. }
  34. pub fn secret(&self) -> Arc<Secret> {
  35. Arc::new(self.inner.secret.clone().into())
  36. }
  37. pub fn c(&self) -> Arc<PublicKey> {
  38. Arc::new(self.inner.c.clone().into())
  39. }
  40. pub fn keyset_id(&self) -> Arc<Id> {
  41. Arc::new(self.keyset_id.into())
  42. }
  43. }
  44. impl From<&Proof> for ProofSdk {
  45. fn from(proof: &Proof) -> ProofSdk {
  46. ProofSdk {
  47. amount: *proof.amount().as_ref().deref(),
  48. secret: proof.secret().as_ref().deref().clone(),
  49. c: proof.c().deref().into(),
  50. keyset_id: proof.keyset_id,
  51. }
  52. }
  53. }
  54. impl From<ProofSdk> for Proof {
  55. fn from(inner: ProofSdk) -> Proof {
  56. Proof { inner }
  57. }
  58. }
  59. pub mod mint {
  60. use std::ops::Deref;
  61. use std::sync::Arc;
  62. use cashu::nuts::nut00::mint::Proof as ProofSdk;
  63. use crate::types::Secret;
  64. use crate::{Amount, Id, PublicKey};
  65. pub struct Proof {
  66. inner: ProofSdk,
  67. }
  68. impl Deref for Proof {
  69. type Target = ProofSdk;
  70. fn deref(&self) -> &Self::Target {
  71. &self.inner
  72. }
  73. }
  74. impl Proof {
  75. pub fn new(
  76. amount: Option<Arc<Amount>>,
  77. secret: Arc<Secret>,
  78. c: Option<Arc<PublicKey>>,
  79. keyset_id: Option<Arc<Id>>,
  80. ) -> Self {
  81. Self {
  82. inner: ProofSdk {
  83. amount: amount.map(|a| *a.as_ref().deref()),
  84. secret: secret.as_ref().deref().clone(),
  85. c: c.map(|c| c.as_ref().into()),
  86. keyset_id: keyset_id.map(|id| *id.as_ref().deref()),
  87. },
  88. }
  89. }
  90. pub fn amount(&self) -> Option<Arc<Amount>> {
  91. self.inner.amount.map(|a| Arc::new(a.into()))
  92. }
  93. pub fn secret(&self) -> Arc<Secret> {
  94. Arc::new(self.inner.secret.clone().into())
  95. }
  96. pub fn c(&self) -> Option<Arc<PublicKey>> {
  97. self.inner.c.clone().map(|c| Arc::new(c.into()))
  98. }
  99. pub fn keyset_id(&self) -> Option<Arc<Id>> {
  100. self.inner.keyset_id.map(|id| Arc::new(id.into()))
  101. }
  102. }
  103. impl From<ProofSdk> for Proof {
  104. fn from(proof: ProofSdk) -> Proof {
  105. Proof { inner: proof }
  106. }
  107. }
  108. impl From<&Proof> for ProofSdk {
  109. fn from(proof: &Proof) -> ProofSdk {
  110. proof.inner.clone()
  111. }
  112. }
  113. }