nut00.rs 17 KB

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