refactor: use blindedmessage in nut00

This commit is contained in:
thesimplekid
2024-03-03 22:11:12 +00:00
parent 6afb873d05
commit 3930712b4d
3 changed files with 17 additions and 33 deletions

View File

@@ -17,8 +17,8 @@ pub mod nut11;
#[cfg(feature = "wallet")]
pub use nut00::wallet::{PreMint, PreMintSecrets, Token};
#[cfg(not(feature = "nut11"))]
pub use nut00::{BlindedMessage, Proof};
pub use nut00::{BlindedSignature, CurrencyUnit, PaymentMethod};
pub use nut00::Proof;
pub use nut00::{BlindedMessage, BlindedSignature, CurrencyUnit, PaymentMethod};
pub use nut01::{Keys, KeysResponse, PublicKey, SecretKey};
pub use nut02::mint::KeySet as MintKeySet;
pub use nut02::{Id, KeySet, KeySetInfo, KeysetResponse};
@@ -40,8 +40,6 @@ pub use nut08::{MeltBolt11Request, MeltBolt11Response};
#[cfg(feature = "nut10")]
pub use nut10::{Kind, Secret as Nut10Secret, SecretData};
#[cfg(feature = "nut11")]
pub use nut11::{
BlindedMessage, P2PKConditions, Proof, SigFlag, Signatures, SigningKey, VerifyingKey,
};
pub use nut11::{P2PKConditions, Proof, SigFlag, Signatures, SigningKey, VerifyingKey};
pub type Proofs = Vec<Proof>;

View File

@@ -9,6 +9,10 @@ use serde::{Deserialize, Serialize};
use super::{Id, Proofs, PublicKey};
use crate::error::Error;
#[cfg(feature = "nut11")]
use crate::nuts::nut11::Signatures;
#[cfg(feature = "nut11")]
use crate::nuts::nut11::{witness_deserialize, witness_serialize};
use crate::secret::Secret;
use crate::url::UncheckedUrl;
use crate::Amount;
@@ -24,6 +28,13 @@ pub struct BlindedMessage {
/// encrypted secret message (B_)
#[serde(rename = "B_")]
pub b: PublicKey,
/// Witness
#[cfg(feature = "nut11")]
#[serde(default)]
#[serde(skip_serializing_if = "Signatures::is_empty")]
#[serde(serialize_with = "witness_serialize")]
#[serde(deserialize_with = "witness_deserialize")]
pub witness: Signatures,
}
impl BlindedMessage {
@@ -32,6 +43,8 @@ impl BlindedMessage {
amount,
keyset_id,
b,
#[cfg(feature = "nut11")]
witness: Signatures::default(),
}
}
}

View File

@@ -18,6 +18,7 @@ use super::nut02::Id;
use super::nut10::{Secret, SecretData};
use super::SecretKey;
use crate::error::Error;
use crate::nuts::nut00::BlindedMessage;
use crate::utils::unix_time;
use crate::Amount;
@@ -170,35 +171,7 @@ impl PartialOrd for Proof {
}
}
/// Blinded Message [NUT-00]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BlindedMessage {
/// Amount
pub amount: Amount,
/// Keyset Id
#[serde(rename = "id")]
pub keyset_id: Id,
/// encrypted secret message (B_)
#[serde(rename = "B_")]
pub b: PublicKey,
/// Witness
#[serde(default)]
#[serde(skip_serializing_if = "Signatures::is_empty")]
#[serde(serialize_with = "witness_serialize")]
#[serde(deserialize_with = "witness_deserialize")]
pub witness: Signatures,
}
impl BlindedMessage {
pub fn new(amount: Amount, keyset_id: Id, b: PublicKey) -> Self {
Self {
amount,
keyset_id,
b,
witness: Signatures::default(),
}
}
pub fn sign_p2pk(&mut self, secret_key: SigningKey) -> Result<(), Error> {
let msg_to_sign = hex::decode(self.b.to_string())?;