浏览代码

feat(cashu): Premint from secret

thesimplekid 1 年之前
父节点
当前提交
1aea753ea2
共有 1 个文件被更改,包括 27 次插入0 次删除
  1. 27 0
      crates/cashu/src/nuts/nut00.rs

+ 27 - 0
crates/cashu/src/nuts/nut00.rs

@@ -184,6 +184,33 @@ pub mod wallet {
             Ok(PreMintSecrets { secrets: output })
         }
 
+        pub fn from_secrets(
+            keyset_id: Id,
+            amounts: Vec<Amount>,
+            secrets: Vec<Secret>,
+        ) -> Result<Self, wallet::Error> {
+            let mut output = Vec::with_capacity(secrets.len());
+
+            for (secret, amount) in secrets.into_iter().zip(amounts) {
+                let (blinded, r) = blind_message(secret.as_bytes(), None)?;
+
+                let blinded_message = BlindedMessage {
+                    amount,
+                    b: blinded,
+                    keyset_id,
+                };
+
+                output.push(PreMint {
+                    secret,
+                    blinded_message,
+                    r: r.into(),
+                    amount,
+                });
+            }
+
+            Ok(PreMintSecrets { secrets: output })
+        }
+
         /// Blank Outputs used for NUT-08 change
         pub fn blank(keyset_id: Id, fee_reserve: Amount) -> Result<Self, wallet::Error> {
             let count = ((u64::from(fee_reserve) as f64).log2().ceil() as u64).max(1);