nut00.rs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. //! Notation and Models
  2. // https://github.com/cashubtc/nuts/blob/main/00.md
  3. use std::fmt;
  4. use std::hash::{self, Hasher};
  5. use std::str::FromStr;
  6. use serde::{Deserialize, Serialize};
  7. use super::{Id, Proofs, PublicKey};
  8. use crate::error::Error;
  9. #[cfg(feature = "nut11")]
  10. use crate::nuts::nut11::Signatures;
  11. #[cfg(feature = "nut11")]
  12. use crate::nuts::nut11::{witness_deserialize, witness_serialize};
  13. use crate::secret::Secret;
  14. use crate::url::UncheckedUrl;
  15. use crate::Amount;
  16. /// Blinded Message [NUT-00]
  17. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
  18. pub struct BlindedMessage {
  19. /// Amount
  20. pub amount: Amount,
  21. /// Keyset Id
  22. #[serde(rename = "id")]
  23. pub keyset_id: Id,
  24. /// encrypted secret message (B_)
  25. #[serde(rename = "B_")]
  26. pub b: PublicKey,
  27. /// Witness
  28. #[cfg(feature = "nut11")]
  29. #[serde(default)]
  30. #[serde(skip_serializing_if = "Signatures::is_empty")]
  31. #[serde(serialize_with = "witness_serialize")]
  32. #[serde(deserialize_with = "witness_deserialize")]
  33. pub witness: Signatures,
  34. }
  35. impl BlindedMessage {
  36. pub fn new(amount: Amount, keyset_id: Id, b: PublicKey) -> Self {
  37. Self {
  38. amount,
  39. keyset_id,
  40. b,
  41. #[cfg(feature = "nut11")]
  42. witness: Signatures::default(),
  43. }
  44. }
  45. }
  46. #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, hash::Hash)]
  47. #[serde(rename_all = "lowercase")]
  48. pub enum CurrencyUnit {
  49. #[default]
  50. Sat,
  51. Usd,
  52. Custom(String),
  53. }
  54. impl FromStr for CurrencyUnit {
  55. type Err = Error;
  56. fn from_str(s: &str) -> Result<Self, Self::Err> {
  57. match s {
  58. "sat" => Ok(Self::Sat),
  59. "usd" => Ok(Self::Usd),
  60. _ => Ok(Self::Custom(s.to_string())),
  61. }
  62. }
  63. }
  64. impl fmt::Display for CurrencyUnit {
  65. fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
  66. match self {
  67. CurrencyUnit::Sat => write!(f, "sat"),
  68. CurrencyUnit::Usd => write!(f, "usd"),
  69. CurrencyUnit::Custom(unit) => write!(f, "{}", unit),
  70. }
  71. }
  72. }
  73. #[derive(Default, Deserialize, Serialize, Debug, PartialEq, Eq, Clone, Hash)]
  74. #[serde(rename_all = "lowercase")]
  75. pub enum PaymentMethod {
  76. #[default]
  77. Bolt11,
  78. Custom(String),
  79. }
  80. impl FromStr for PaymentMethod {
  81. type Err = Error;
  82. fn from_str(s: &str) -> Result<Self, Self::Err> {
  83. match s {
  84. "bolt11" => Ok(Self::Bolt11),
  85. _ => Ok(Self::Custom(s.to_string())),
  86. }
  87. }
  88. }
  89. impl fmt::Display for PaymentMethod {
  90. fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
  91. match self {
  92. PaymentMethod::Bolt11 => write!(f, "bolt11"),
  93. PaymentMethod::Custom(unit) => write!(f, "{}", unit),
  94. }
  95. }
  96. }
  97. #[cfg(feature = "wallet")]
  98. pub mod wallet {
  99. use std::cmp::Ordering;
  100. use std::fmt;
  101. use std::str::FromStr;
  102. use base64::engine::{general_purpose, GeneralPurpose};
  103. use base64::{alphabet, Engine as _};
  104. use bip39::Mnemonic;
  105. use serde::{Deserialize, Serialize};
  106. use url::Url;
  107. use super::{CurrencyUnit, MintProofs};
  108. use crate::dhke::blind_message;
  109. use crate::error::wallet;
  110. #[cfg(feature = "nut11")]
  111. use crate::nuts::P2PKConditions;
  112. use crate::nuts::{BlindedMessage, Id, Proofs, SecretKey};
  113. use crate::secret::Secret;
  114. use crate::url::UncheckedUrl;
  115. use crate::{error, Amount};
  116. #[derive(Debug, Clone, PartialEq, Eq, Serialize)]
  117. pub struct PreMint {
  118. /// Blinded message
  119. pub blinded_message: BlindedMessage,
  120. /// Secret
  121. pub secret: Secret,
  122. /// R
  123. pub r: SecretKey,
  124. /// Amount
  125. pub amount: Amount,
  126. }
  127. impl Ord for PreMint {
  128. fn cmp(&self, other: &Self) -> std::cmp::Ordering {
  129. self.amount.cmp(&other.amount)
  130. }
  131. }
  132. impl PartialOrd for PreMint {
  133. fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
  134. Some(self.cmp(other))
  135. }
  136. }
  137. #[derive(Debug, Default, Clone, PartialEq, Eq, Serialize)]
  138. pub struct PreMintSecrets {
  139. secrets: Vec<PreMint>,
  140. }
  141. impl PreMintSecrets {
  142. /// Outputs for speceifed amount with random secret
  143. pub fn random(keyset_id: Id, amount: Amount) -> Result<Self, wallet::Error> {
  144. let amount_split = amount.split();
  145. let mut output = Vec::with_capacity(amount_split.len());
  146. for amount in amount_split {
  147. let secret = Secret::new();
  148. let (blinded, r) = blind_message(&secret.to_bytes(), None)?;
  149. let blinded_message = BlindedMessage::new(amount, keyset_id, blinded);
  150. output.push(PreMint {
  151. secret,
  152. blinded_message,
  153. r: r.into(),
  154. amount,
  155. });
  156. }
  157. Ok(PreMintSecrets { secrets: output })
  158. }
  159. pub fn from_secrets(
  160. keyset_id: Id,
  161. amounts: Vec<Amount>,
  162. secrets: Vec<Secret>,
  163. ) -> Result<Self, wallet::Error> {
  164. let mut output = Vec::with_capacity(secrets.len());
  165. for (secret, amount) in secrets.into_iter().zip(amounts) {
  166. let (blinded, r) = blind_message(&secret.to_bytes(), None)?;
  167. let blinded_message = BlindedMessage::new(amount, keyset_id, blinded);
  168. output.push(PreMint {
  169. secret,
  170. blinded_message,
  171. r: r.into(),
  172. amount,
  173. });
  174. }
  175. Ok(PreMintSecrets { secrets: output })
  176. }
  177. /// Blank Outputs used for NUT-08 change
  178. pub fn blank(keyset_id: Id, fee_reserve: Amount) -> Result<Self, wallet::Error> {
  179. let count = ((u64::from(fee_reserve) as f64).log2().ceil() as u64).max(1);
  180. let mut output = Vec::with_capacity(count as usize);
  181. for _i in 0..count {
  182. let secret = Secret::new();
  183. let (blinded, r) = blind_message(&secret.to_bytes(), None)?;
  184. let blinded_message = BlindedMessage::new(Amount::ZERO, keyset_id, blinded);
  185. output.push(PreMint {
  186. secret,
  187. blinded_message,
  188. r: r.into(),
  189. amount: Amount::ZERO,
  190. })
  191. }
  192. Ok(PreMintSecrets { secrets: output })
  193. }
  194. /// Generate blinded messages from predetermined secrets and blindings
  195. /// factor
  196. /// TODO: Put behind feature
  197. pub fn from_seed(
  198. keyset_id: Id,
  199. counter: u64,
  200. mnemonic: &Mnemonic,
  201. amount: Amount,
  202. ) -> Result<Self, wallet::Error> {
  203. let mut pre_mint_secrets = PreMintSecrets::default();
  204. let mut counter = counter;
  205. for amount in amount.split() {
  206. let secret = Secret::from_seed(mnemonic, keyset_id, counter);
  207. let blinding_factor = SecretKey::from_seed(mnemonic, keyset_id, counter);
  208. let (blinded, r) = blind_message(&secret.to_bytes(), Some(blinding_factor.into()))?;
  209. let blinded_message = BlindedMessage::new(amount, keyset_id, blinded);
  210. let pre_mint = PreMint {
  211. blinded_message,
  212. secret: secret.clone(),
  213. r: r.into(),
  214. amount: Amount::ZERO,
  215. };
  216. pre_mint_secrets.secrets.push(pre_mint);
  217. counter += 1;
  218. }
  219. Ok(pre_mint_secrets)
  220. }
  221. #[cfg(feature = "nut11")]
  222. pub fn with_p2pk_conditions(
  223. keyset_id: Id,
  224. amount: Amount,
  225. conditions: P2PKConditions,
  226. ) -> Result<Self, wallet::Error> {
  227. let amount_split = amount.split();
  228. let mut output = Vec::with_capacity(amount_split.len());
  229. for amount in amount_split {
  230. let secret: Secret = conditions.clone().try_into()?;
  231. let (blinded, r) = blind_message(&secret.to_bytes(), None)?;
  232. let blinded_message = BlindedMessage::new(amount, keyset_id, blinded);
  233. output.push(PreMint {
  234. secret,
  235. blinded_message,
  236. r: r.into(),
  237. amount,
  238. });
  239. }
  240. Ok(PreMintSecrets { secrets: output })
  241. }
  242. pub fn iter(&self) -> impl Iterator<Item = &PreMint> {
  243. self.secrets.iter()
  244. }
  245. pub fn len(&self) -> usize {
  246. self.secrets.len()
  247. }
  248. pub fn is_empty(&self) -> bool {
  249. self.secrets.is_empty()
  250. }
  251. pub fn total_amount(&self) -> Amount {
  252. self.secrets
  253. .iter()
  254. .map(|PreMint { amount, .. }| *amount)
  255. .sum()
  256. }
  257. pub fn blinded_messages(&self) -> Vec<BlindedMessage> {
  258. self.iter().map(|pm| pm.blinded_message.clone()).collect()
  259. }
  260. pub fn secrets(&self) -> Vec<Secret> {
  261. self.iter().map(|pm| pm.secret.clone()).collect()
  262. }
  263. pub fn rs(&self) -> Vec<SecretKey> {
  264. self.iter().map(|pm| pm.r.clone()).collect()
  265. }
  266. pub fn amounts(&self) -> Vec<Amount> {
  267. self.iter().map(|pm| pm.amount).collect()
  268. }
  269. pub fn combine(&mut self, mut other: Self) {
  270. self.secrets.append(&mut other.secrets)
  271. }
  272. pub fn sort_secrets(&mut self) {
  273. self.secrets.sort();
  274. }
  275. }
  276. // Implement Iterator for PreMintSecrets
  277. impl Iterator for PreMintSecrets {
  278. type Item = PreMint;
  279. fn next(&mut self) -> Option<Self::Item> {
  280. // Use the iterator of the vector
  281. self.secrets.pop()
  282. }
  283. }
  284. impl Ord for PreMintSecrets {
  285. fn cmp(&self, other: &Self) -> Ordering {
  286. self.secrets.cmp(&other.secrets)
  287. }
  288. }
  289. impl PartialOrd for PreMintSecrets {
  290. fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
  291. Some(self.cmp(other))
  292. }
  293. }
  294. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
  295. pub struct Token {
  296. pub token: Vec<MintProofs>,
  297. /// Memo for token
  298. #[serde(skip_serializing_if = "Option::is_none")]
  299. pub memo: Option<String>,
  300. /// Token Unit
  301. #[serde(skip_serializing_if = "Option::is_none")]
  302. pub unit: Option<CurrencyUnit>,
  303. }
  304. impl Token {
  305. pub fn new(
  306. mint_url: UncheckedUrl,
  307. proofs: Proofs,
  308. memo: Option<String>,
  309. unit: Option<CurrencyUnit>,
  310. ) -> Result<Self, wallet::Error> {
  311. if proofs.is_empty() {
  312. return Err(wallet::Error::ProofsRequired);
  313. }
  314. // Check Url is valid
  315. let _: Url = (&mint_url).try_into()?;
  316. Ok(Self {
  317. token: vec![MintProofs::new(mint_url, proofs)],
  318. memo,
  319. unit,
  320. })
  321. }
  322. pub fn token_info(&self) -> (u64, String) {
  323. let mut amount = Amount::ZERO;
  324. for proofs in &self.token {
  325. for proof in &proofs.proofs {
  326. amount += proof.amount;
  327. }
  328. }
  329. (amount.into(), self.token[0].mint.to_string())
  330. }
  331. }
  332. impl FromStr for Token {
  333. type Err = error::wallet::Error;
  334. fn from_str(s: &str) -> Result<Self, Self::Err> {
  335. let s = if s.starts_with("cashuA") {
  336. s.replace("cashuA", "")
  337. } else {
  338. return Err(wallet::Error::UnsupportedToken);
  339. };
  340. let decode_config = general_purpose::GeneralPurposeConfig::new()
  341. .with_decode_padding_mode(base64::engine::DecodePaddingMode::Indifferent);
  342. let decoded = GeneralPurpose::new(&alphabet::STANDARD, decode_config).decode(s)?;
  343. let decoded_str = String::from_utf8(decoded)?;
  344. let token: Token = serde_json::from_str(&decoded_str)?;
  345. Ok(token)
  346. }
  347. }
  348. impl fmt::Display for Token {
  349. fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
  350. let json_string = serde_json::to_string(self).map_err(|_| fmt::Error)?;
  351. let encoded = general_purpose::STANDARD.encode(json_string);
  352. write!(f, "cashuA{}", encoded)
  353. }
  354. }
  355. }
  356. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
  357. pub struct MintProofs {
  358. pub mint: UncheckedUrl,
  359. pub proofs: Proofs,
  360. }
  361. #[cfg(feature = "wallet")]
  362. impl MintProofs {
  363. fn new(mint_url: UncheckedUrl, proofs: Proofs) -> Self {
  364. Self {
  365. mint: mint_url,
  366. proofs,
  367. }
  368. }
  369. }
  370. /// Promise (BlindedSignature) [NUT-00]
  371. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
  372. pub struct BlindedSignature {
  373. pub amount: Amount,
  374. /// Keyset Id
  375. #[serde(rename = "id")]
  376. pub keyset_id: Id,
  377. /// blinded signature (C_) on the secret message `B_` of [BlindedMessage]
  378. #[serde(rename = "C_")]
  379. pub c: PublicKey,
  380. }
  381. /// Proofs [NUT-00]
  382. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
  383. pub struct Proof {
  384. /// Amount in satoshi
  385. pub amount: Amount,
  386. /// `Keyset id`
  387. #[serde(rename = "id")]
  388. pub keyset_id: Id,
  389. /// Secret message
  390. pub secret: Secret,
  391. /// Unblinded signature
  392. #[serde(rename = "C")]
  393. pub c: PublicKey,
  394. #[cfg(feature = "nut11")]
  395. /// Witness
  396. #[serde(default)]
  397. #[serde(skip_serializing_if = "Signatures::is_empty")]
  398. #[serde(serialize_with = "witness_serialize")]
  399. #[serde(deserialize_with = "witness_deserialize")]
  400. pub witness: Signatures,
  401. }
  402. impl Proof {
  403. pub fn new(amount: Amount, keyset_id: Id, secret: Secret, c: PublicKey) -> Self {
  404. Proof {
  405. amount,
  406. keyset_id,
  407. secret,
  408. c,
  409. #[cfg(feature = "nut11")]
  410. witness: Signatures::default(),
  411. }
  412. }
  413. }
  414. impl hash::Hash for Proof {
  415. fn hash<H: Hasher>(&self, state: &mut H) {
  416. self.secret.hash(state);
  417. }
  418. }
  419. impl Ord for Proof {
  420. fn cmp(&self, other: &Self) -> std::cmp::Ordering {
  421. self.amount.cmp(&other.amount)
  422. }
  423. }
  424. impl PartialOrd for Proof {
  425. fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
  426. Some(self.cmp(other))
  427. }
  428. }
  429. #[cfg(test)]
  430. mod tests {
  431. use std::str::FromStr;
  432. use super::wallet::*;
  433. use super::*;
  434. #[test]
  435. fn test_proof_serialize() {
  436. let proof = "[{\"id\":\"009a1f293253e41e\",\"amount\":2,\"secret\":\"407915bc212be61a77e3e6d2aeb4c727980bda51cd06a6afc29e2861768a7837\",\"C\":\"02bc9097997d81afb2cc7346b5e4345a9346bd2a506eb7958598a72f0cf85163ea\"},{\"id\":\"009a1f293253e41e\",\"amount\":8,\"secret\":\"fe15109314e61d7756b0f8ee0f23a624acaa3f4e042f61433c728c7057b931be\",\"C\":\"029e8e5050b890a7d6c0968db16bc1d5d5fa040ea1de284f6ec69d61299f671059\"}]";
  437. let proof: Proofs = serde_json::from_str(proof).unwrap();
  438. assert_eq!(
  439. proof[0].clone().keyset_id,
  440. Id::from_str("009a1f293253e41e").unwrap()
  441. );
  442. assert_eq!(proof.len(), 2);
  443. }
  444. #[test]
  445. fn test_token_str_round_trip() {
  446. let token_str = "cashuAeyJ0b2tlbiI6W3sibWludCI6Imh0dHBzOi8vODMzMy5zcGFjZTozMzM4IiwicHJvb2ZzIjpbeyJhbW91bnQiOjIsImlkIjoiMDA5YTFmMjkzMjUzZTQxZSIsInNlY3JldCI6IjQwNzkxNWJjMjEyYmU2MWE3N2UzZTZkMmFlYjRjNzI3OTgwYmRhNTFjZDA2YTZhZmMyOWUyODYxNzY4YTc4MzciLCJDIjoiMDJiYzkwOTc5OTdkODFhZmIyY2M3MzQ2YjVlNDM0NWE5MzQ2YmQyYTUwNmViNzk1ODU5OGE3MmYwY2Y4NTE2M2VhIn0seyJhbW91bnQiOjgsImlkIjoiMDA5YTFmMjkzMjUzZTQxZSIsInNlY3JldCI6ImZlMTUxMDkzMTRlNjFkNzc1NmIwZjhlZTBmMjNhNjI0YWNhYTNmNGUwNDJmNjE0MzNjNzI4YzcwNTdiOTMxYmUiLCJDIjoiMDI5ZThlNTA1MGI4OTBhN2Q2YzA5NjhkYjE2YmMxZDVkNWZhMDQwZWExZGUyODRmNmVjNjlkNjEyOTlmNjcxMDU5In1dfV0sInVuaXQiOiJzYXQiLCJtZW1vIjoiVGhhbmsgeW91LiJ9";
  447. let token = Token::from_str(token_str).unwrap();
  448. assert_eq!(
  449. token.token[0].mint,
  450. UncheckedUrl::from_str("https://8333.space:3338").unwrap()
  451. );
  452. assert_eq!(
  453. token.token[0].proofs[0].clone().keyset_id,
  454. Id::from_str("009a1f293253e41e").unwrap()
  455. );
  456. assert_eq!(token.unit.clone().unwrap(), CurrencyUnit::Sat);
  457. let encoded = &token.to_string();
  458. let token_data = Token::from_str(encoded).unwrap();
  459. assert_eq!(token_data, token);
  460. }
  461. #[test]
  462. fn test_blank_blinded_messages() {
  463. // TODO: Need to update id to new type in proof
  464. let b = PreMintSecrets::blank(
  465. Id::from_str("009a1f293253e41e").unwrap(),
  466. Amount::from(1000),
  467. )
  468. .unwrap();
  469. assert_eq!(b.len(), 10);
  470. // TODO: Need to update id to new type in proof
  471. let b = PreMintSecrets::blank(Id::from_str("009a1f293253e41e").unwrap(), Amount::from(1))
  472. .unwrap();
  473. assert_eq!(b.len(), 1);
  474. }
  475. #[test]
  476. fn incorrect_tokens() {
  477. let incorrect_prefix = "casshuAeyJ0b2tlbiI6W3sibWludCI6Imh0dHBzOi8vODMzMy5zcGFjZTozMzM4IiwicHJvb2ZzIjpbeyJhbW91bnQiOjIsImlkIjoiMDA5YTFmMjkzMjUzZTQxZSIsInNlY3JldCI6IjQwNzkxNWJjMjEyYmU2MWE3N2UzZTZkMmFlYjRjNzI3OTgwYmRhNTFjZDA2YTZhZmMyOWUyODYxNzY4YTc4MzciLCJDIjoiMDJiYzkwOTc5OTdkODFhZmIyY2M3MzQ2YjVlNDM0NWE5MzQ2YmQyYTUwNmViNzk1ODU5OGE3MmYwY2Y4NTE2M2VhIn0seyJhbW91bnQiOjgsImlkIjoiMDA5YTFmMjkzMjUzZTQxZSIsInNlY3JldCI6ImZlMTUxMDkzMTRlNjFkNzc1NmIwZjhlZTBmMjNhNjI0YWNhYTNmNGUwNDJmNjE0MzNjNzI4YzcwNTdiOTMxYmUiLCJDIjoiMDI5ZThlNTA1MGI4OTBhN2Q2YzA5NjhkYjE2YmMxZDVkNWZhMDQwZWExZGUyODRmNmVjNjlkNjEyOTlmNjcxMDU5In1dfV0sInVuaXQiOiJzYXQiLCJtZW1vIjoiVGhhbmsgeW91LiJ9";
  478. let incorrect_prefix_token = Token::from_str(incorrect_prefix);
  479. assert!(incorrect_prefix_token.is_err());
  480. let no_prefix = "eyJ0b2tlbiI6W3sibWludCI6Imh0dHBzOi8vODMzMy5zcGFjZTozMzM4IiwicHJvb2ZzIjpbeyJhbW91bnQiOjIsImlkIjoiMDA5YTFmMjkzMjUzZTQxZSIsInNlY3JldCI6IjQwNzkxNWJjMjEyYmU2MWE3N2UzZTZkMmFlYjRjNzI3OTgwYmRhNTFjZDA2YTZhZmMyOWUyODYxNzY4YTc4MzciLCJDIjoiMDJiYzkwOTc5OTdkODFhZmIyY2M3MzQ2YjVlNDM0NWE5MzQ2YmQyYTUwNmViNzk1ODU5OGE3MmYwY2Y4NTE2M2VhIn0seyJhbW91bnQiOjgsImlkIjoiMDA5YTFmMjkzMjUzZTQxZSIsInNlY3JldCI6ImZlMTUxMDkzMTRlNjFkNzc1NmIwZjhlZTBmMjNhNjI0YWNhYTNmNGUwNDJmNjE0MzNjNzI4YzcwNTdiOTMxYmUiLCJDIjoiMDI5ZThlNTA1MGI4OTBhN2Q2YzA5NjhkYjE2YmMxZDVkNWZhMDQwZWExZGUyODRmNmVjNjlkNjEyOTlmNjcxMDU5In1dfV0sInVuaXQiOiJzYXQiLCJtZW1vIjoiVGhhbmsgeW91LiJ9";
  481. let no_prefix_token = Token::from_str(no_prefix);
  482. assert!(no_prefix_token.is_err());
  483. let correct_token = "cashuAeyJ0b2tlbiI6W3sibWludCI6Imh0dHBzOi8vODMzMy5zcGFjZTozMzM4IiwicHJvb2ZzIjpbeyJhbW91bnQiOjIsImlkIjoiMDA5YTFmMjkzMjUzZTQxZSIsInNlY3JldCI6IjQwNzkxNWJjMjEyYmU2MWE3N2UzZTZkMmFlYjRjNzI3OTgwYmRhNTFjZDA2YTZhZmMyOWUyODYxNzY4YTc4MzciLCJDIjoiMDJiYzkwOTc5OTdkODFhZmIyY2M3MzQ2YjVlNDM0NWE5MzQ2YmQyYTUwNmViNzk1ODU5OGE3MmYwY2Y4NTE2M2VhIn0seyJhbW91bnQiOjgsImlkIjoiMDA5YTFmMjkzMjUzZTQxZSIsInNlY3JldCI6ImZlMTUxMDkzMTRlNjFkNzc1NmIwZjhlZTBmMjNhNjI0YWNhYTNmNGUwNDJmNjE0MzNjNzI4YzcwNTdiOTMxYmUiLCJDIjoiMDI5ZThlNTA1MGI4OTBhN2Q2YzA5NjhkYjE2YmMxZDVkNWZhMDQwZWExZGUyODRmNmVjNjlkNjEyOTlmNjcxMDU5In1dfV0sInVuaXQiOiJzYXQiLCJtZW1vIjoiVGhhbmsgeW91LiJ9";
  484. let correct_token = Token::from_str(correct_token);
  485. assert!(correct_token.is_ok());
  486. }
  487. }