Ver Fonte

contract/money/model/token_id: removed deprecated derive functions as per DEP0003

skoupidi há 1 ano atrás
pai
commit
c0af9925a8

+ 1 - 1
bin/drk/src/token.rs

@@ -70,7 +70,7 @@ impl Drk {
         }
         .to_func_id();
 
-        // Grab the mint autority key public coordinates
+        // Grab the mint authority key public coordinates
         let (mint_auth_x, mint_auth_y) = PublicKey::from_secret(mint_authority).xy();
 
         // Generate the token attributes

+ 26 - 6
bin/vanityaddr/src/main.rs

@@ -24,8 +24,11 @@ use std::{
 
 use arg::Args;
 use darkfi::{util::cli::ProgressInc, ANSI_LOGO};
-use darkfi_money_contract::model::TokenId;
-use darkfi_sdk::crypto::{ContractId, PublicKey, SecretKey};
+use darkfi_money_contract::{model::TokenId, MoneyFunction};
+use darkfi_sdk::crypto::{
+    contract_id::MONEY_CONTRACT_ID, poseidon_hash, BaseBlind, ContractId, FuncRef, PublicKey,
+    SecretKey,
+};
 use rand::rngs::OsRng;
 use rayon::iter::ParallelIterator;
 
@@ -58,6 +61,7 @@ struct DrkAddr {
 struct DrkToken {
     pub token_id: TokenId,
     pub secret: SecretKey,
+    pub blind: BaseBlind,
 }
 
 struct DrkContract {
@@ -101,9 +105,25 @@ impl Prefixable for DrkAddr {
 
 impl Prefixable for DrkToken {
     fn new() -> Self {
+        // Generate the mint authority secret key and blind
         let secret = SecretKey::random(&mut OsRng);
-        let token_id = TokenId::derive(secret);
-        Self { token_id, secret }
+        let blind = BaseBlind::random(&mut OsRng);
+
+        // Create the Auth FuncID
+        let func_id = FuncRef {
+            contract_id: *MONEY_CONTRACT_ID,
+            func_code: MoneyFunction::AuthTokenMintV1 as u8,
+        }
+        .to_func_id();
+
+        // Grab the mint authority user data
+        let (auth_x, auth_y) = PublicKey::from_secret(secret).xy();
+        let user_data = poseidon_hash([auth_x, auth_y]);
+
+        // Derive the Token ID
+        let token_id = TokenId::derive_from(func_id.inner(), user_data, blind.inner());
+
+        Self { token_id, secret, blind }
     }
 
     fn to_string(&self) -> String {
@@ -217,8 +237,8 @@ fn main() -> ExitCode {
             progress_.finish_and_clear();
 
             println!(
-                "{{\"token_id\":\"{}\",\"attempts\":{},\"secret\":\"{}\"}}",
-                tid.token_id, attempts, tid.secret,
+                "{{\"token_id\":\"{}\",\"attempts\":{},\"secret\":\"{}\",\"blind\":\"{}\"}}",
+                tid.token_id, attempts, tid.secret, tid.blind
             );
         }
 

+ 1 - 1
src/contract/money/src/model/mod.rs

@@ -19,7 +19,7 @@
 use darkfi_sdk::{
     crypto::{
         note::AeadEncryptedNote, pasta_prelude::PrimeField, poseidon_hash, BaseBlind, FuncId,
-        MerkleNode, PublicKey, ScalarBlind, SecretKey,
+        MerkleNode, PublicKey, ScalarBlind,
     },
     error::ContractError,
     pasta::pallas,

+ 3 - 19
src/contract/money/src/model/token_id.rs

@@ -29,7 +29,7 @@ use lazy_static::lazy_static;
 #[cfg(feature = "client")]
 use darkfi_serial::async_trait;
 
-use super::{poseidon_hash, PublicKey, SecretKey};
+use super::poseidon_hash;
 
 lazy_static! {
     // Is this even needed? Not used elsewhere except here.
@@ -47,24 +47,8 @@ lazy_static! {
 pub struct TokenId(pallas::Base);
 
 impl TokenId {
-    /// Derives a `TokenId` from a `SecretKey` (mint authority)
-    // TODO: this got deprected from DEP 0003, but why? ain't that mean
-    // we don't allow users to hold mint keys with their secret?
-    //#[deprecated]
-    pub fn derive(mint_authority: SecretKey) -> Self {
-        let public_key = PublicKey::from_secret(mint_authority);
-        Self::derive_public(public_key)
-    }
-
-    /// Derives a `TokenId` from a `PublicKey`
-    // TODO: this got deprected from DEP 0003, but why? ain't that mean
-    // we don't allow users to hold mint keys with their secret?
-    //#[deprecated]
-    pub fn derive_public(public_key: PublicKey) -> Self {
-        let (x, y) = public_key.xy();
-        Self::derive_from(*TOKEN_ID_PREFIX, x, y)
-    }
-
+    /// Derives a `TokenId` from provided function id,
+    /// user data and blind.
     pub fn derive_from(
         func_id: pallas::Base,
         user_data: pallas::Base,