mirror of
https://github.com/aljazceru/cdk.git
synced 2026-02-05 05:06:14 +01:00
improve: 'cashu' use thiserror for 'NUT02', 'SECRET' and 'URL'
This commit is contained in:
@@ -2,33 +2,24 @@
|
||||
// https://github.com/cashubtc/nuts/blob/main/02.md
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::fmt;
|
||||
|
||||
use base64::engine::general_purpose;
|
||||
use base64::Engine as _;
|
||||
use bitcoin::hashes::{sha256, Hash};
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
|
||||
use super::nut01::Keys;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[derive(Debug, Error, PartialEq, Eq)]
|
||||
pub enum Error {
|
||||
Base64(base64::DecodeError),
|
||||
#[error("`{0}`")]
|
||||
Base64(#[from] base64::DecodeError),
|
||||
#[error("NUT01: ID length invalid")]
|
||||
Length,
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Length => write!(f, "NUT02: Id invalid length"),
|
||||
Self::Base64(err) => write!(f, "NUT02: {:?}", err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A keyset ID is an identifier for a specific keyset. It can be derived by
|
||||
/// anyone who knows the set of public keys of a mint. The keyset ID **CAN**
|
||||
/// be stored in a Cashu token such that the token can be used to identify
|
||||
|
||||
@@ -5,14 +5,16 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
|
||||
/// The secret data that allows spending ecash
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct Secret(String);
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum Error {
|
||||
#[error("Invalid secret length: `{0}`")]
|
||||
InvalidLength(u64),
|
||||
}
|
||||
|
||||
|
||||
@@ -7,29 +7,15 @@ use core::fmt;
|
||||
use core::str::FromStr;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
use url::{ParseError, Url};
|
||||
|
||||
/// Url Error
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[derive(Debug, Error, PartialEq, Eq)]
|
||||
pub enum Error {
|
||||
/// Url error
|
||||
Url(ParseError),
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Url(e) => write!(f, "Url: {e}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ParseError> for Error {
|
||||
fn from(e: ParseError) -> Self {
|
||||
Self::Url(e)
|
||||
}
|
||||
#[error("`{0}`")]
|
||||
Url(#[from] ParseError),
|
||||
}
|
||||
|
||||
/// Unchecked Url
|
||||
|
||||
Reference in New Issue
Block a user