mirror of
https://github.com/aljazceru/cdk.git
synced 2026-02-05 05:06:14 +01:00
refactor: nut11 features
This commit is contained in:
@@ -7,8 +7,11 @@ use std::str::FromStr;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{Id, Proofs, PublicKey, Signatures, SigningKey};
|
||||
use super::{Id, Proofs, PublicKey};
|
||||
#[cfg(feature = "nut11")]
|
||||
use super::{Signatures, SigningKey};
|
||||
use crate::error::Error;
|
||||
#[cfg(feature = "nut11")]
|
||||
use crate::nuts::nut11::{witness_deserialize, witness_serialize};
|
||||
use crate::secret::Secret;
|
||||
use crate::url::UncheckedUrl;
|
||||
@@ -26,6 +29,7 @@ pub struct BlindedMessage {
|
||||
#[serde(rename = "B_")]
|
||||
pub b: PublicKey,
|
||||
/// Witness
|
||||
#[cfg(feature = "nut11")]
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Signatures::is_empty")]
|
||||
#[serde(serialize_with = "witness_serialize")]
|
||||
@@ -39,10 +43,12 @@ impl BlindedMessage {
|
||||
amount,
|
||||
keyset_id,
|
||||
b,
|
||||
#[cfg(feature = "nut11")]
|
||||
witness: Signatures::default(),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "nut11")]
|
||||
pub fn sign_p2pk_blinded_message(&mut self, secret_key: SigningKey) -> Result<(), Error> {
|
||||
let msg_to_sign = hex::decode(self.b.to_string())?;
|
||||
|
||||
@@ -131,7 +137,9 @@ pub mod wallet {
|
||||
use super::{CurrencyUnit, MintProofs};
|
||||
use crate::dhke::blind_message;
|
||||
use crate::error::wallet;
|
||||
use crate::nuts::{BlindedMessage, Id, P2PKConditions, Proofs, SecretKey};
|
||||
#[cfg(feature = "nut11")]
|
||||
use crate::nuts::P2PKConditions;
|
||||
use crate::nuts::{BlindedMessage, Id, Proofs, SecretKey};
|
||||
use crate::secret::Secret;
|
||||
use crate::url::UncheckedUrl;
|
||||
use crate::{error, Amount};
|
||||
|
||||
@@ -7,6 +7,7 @@ use std::str::FromStr;
|
||||
use bip32::{DerivationPath, XPrv};
|
||||
use bip39::Mnemonic;
|
||||
use k256::elliptic_curve::generic_array::GenericArray;
|
||||
#[cfg(feature = "nut11")]
|
||||
use k256::schnorr::{SigningKey, VerifyingKey};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -36,6 +37,7 @@ impl From<k256::PublicKey> for PublicKey {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "nut11")]
|
||||
impl TryFrom<PublicKey> for VerifyingKey {
|
||||
type Error = Error;
|
||||
fn try_from(value: PublicKey) -> Result<VerifyingKey, Self::Error> {
|
||||
@@ -43,6 +45,7 @@ impl TryFrom<PublicKey> for VerifyingKey {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "nut11")]
|
||||
impl TryFrom<&PublicKey> for VerifyingKey {
|
||||
type Error = Error;
|
||||
fn try_from(value: &PublicKey) -> Result<VerifyingKey, Self::Error> {
|
||||
@@ -58,12 +61,14 @@ impl TryFrom<&PublicKey> for VerifyingKey {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "nut11")]
|
||||
impl From<VerifyingKey> for PublicKey {
|
||||
fn from(value: VerifyingKey) -> PublicKey {
|
||||
PublicKey(value.try_into().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "nut11")]
|
||||
impl From<super::VerifyingKey> for PublicKey {
|
||||
fn from(value: super::VerifyingKey) -> PublicKey {
|
||||
let v: VerifyingKey = value.into();
|
||||
@@ -108,6 +113,7 @@ impl From<k256::SecretKey> for SecretKey {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "nut11")]
|
||||
impl TryFrom<SecretKey> for SigningKey {
|
||||
type Error = Error;
|
||||
fn try_from(value: SecretKey) -> Result<SigningKey, Self::Error> {
|
||||
|
||||
@@ -103,6 +103,7 @@ impl TryFrom<&Secret> for Vec<u8> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "nut10")]
|
||||
impl TryFrom<Secret> for crate::nuts::nut10::Secret {
|
||||
type Error = serde_json::Error;
|
||||
|
||||
@@ -111,6 +112,7 @@ impl TryFrom<Secret> for crate::nuts::nut10::Secret {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "nut10")]
|
||||
impl TryFrom<&Secret> for crate::nuts::nut10::Secret {
|
||||
type Error = serde_json::Error;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user