mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-10 07:08:05 -05:00
Apply new TokenID API throughout codebase.
This commit is contained in:
@@ -29,13 +29,12 @@ simplelog = "0.12.0"
|
||||
thiserror = "1.0.37"
|
||||
|
||||
# Crypto
|
||||
incrementalmerkletree = "0.3.0"
|
||||
pasta_curves = "0.4.0"
|
||||
halo2_gadgets = "0.2.0"
|
||||
halo2_proofs = "0.2.0"
|
||||
rand = "0.8.5"
|
||||
chacha20poly1305 = "0.10.1"
|
||||
group = "0.12.0"
|
||||
pasta_curves = "0.4.1"
|
||||
incrementalmerkletree = "0.3.0"
|
||||
|
||||
# Encoding and parsing
|
||||
serde_json = "1.0.85"
|
||||
|
||||
@@ -77,7 +77,7 @@ impl Builder {
|
||||
dao_quorum,
|
||||
dao_approval_ratio_quot,
|
||||
dao_approval_ratio_base,
|
||||
self.dao.gov_token_id,
|
||||
self.dao.gov_token_id.inner(),
|
||||
dao_pub_x,
|
||||
dao_pub_y,
|
||||
self.dao.bulla_blind,
|
||||
@@ -88,7 +88,7 @@ impl Builder {
|
||||
proposal_dest_y,
|
||||
proposal_amount,
|
||||
self.proposal.serial,
|
||||
self.proposal.token_id,
|
||||
self.proposal.token_id.inner(),
|
||||
dao_bulla,
|
||||
self.proposal.blind,
|
||||
// @tmp-workaround
|
||||
@@ -99,7 +99,7 @@ impl Builder {
|
||||
proposal_dest_x,
|
||||
proposal_dest_y,
|
||||
proposal_amount,
|
||||
self.proposal.token_id,
|
||||
self.proposal.token_id.inner(),
|
||||
self.proposal.serial,
|
||||
user_spend_hook,
|
||||
user_data,
|
||||
@@ -110,7 +110,7 @@ impl Builder {
|
||||
dao_pub_x,
|
||||
dao_pub_y,
|
||||
change,
|
||||
self.proposal.token_id,
|
||||
self.proposal.token_id.inner(),
|
||||
self.dao_serial,
|
||||
self.hook_dao_exec,
|
||||
dao_bulla,
|
||||
@@ -142,14 +142,14 @@ impl Builder {
|
||||
Witness::Base(Value::known(proposal_dest_y)),
|
||||
Witness::Base(Value::known(proposal_amount)),
|
||||
Witness::Base(Value::known(self.proposal.serial)),
|
||||
Witness::Base(Value::known(self.proposal.token_id)),
|
||||
Witness::Base(Value::known(self.proposal.token_id.inner())),
|
||||
Witness::Base(Value::known(self.proposal.blind)),
|
||||
// DAO params
|
||||
Witness::Base(Value::known(dao_proposer_limit)),
|
||||
Witness::Base(Value::known(dao_quorum)),
|
||||
Witness::Base(Value::known(dao_approval_ratio_quot)),
|
||||
Witness::Base(Value::known(dao_approval_ratio_base)),
|
||||
Witness::Base(Value::known(self.dao.gov_token_id)),
|
||||
Witness::Base(Value::known(self.dao.gov_token_id.inner())),
|
||||
Witness::Base(Value::known(dao_pub_x)),
|
||||
Witness::Base(Value::known(dao_pub_y)),
|
||||
Witness::Base(Value::known(self.dao.bulla_blind)),
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use darkfi_sdk::crypto::{poseidon_hash, PublicKey, SecretKey};
|
||||
use darkfi_sdk::crypto::{poseidon_hash, PublicKey, SecretKey, TokenId};
|
||||
use halo2_proofs::circuit::Value;
|
||||
use pasta_curves::pallas;
|
||||
use rand::rngs::OsRng;
|
||||
@@ -37,7 +37,7 @@ pub struct DaoParams {
|
||||
pub quorum: u64,
|
||||
pub approval_ratio_quot: u64,
|
||||
pub approval_ratio_base: u64,
|
||||
pub gov_token_id: pallas::Base,
|
||||
pub gov_token_id: TokenId,
|
||||
pub public_key: PublicKey,
|
||||
pub bulla_blind: pallas::Base,
|
||||
}
|
||||
@@ -47,7 +47,7 @@ pub struct Builder {
|
||||
pub dao_quorum: u64,
|
||||
pub dao_approval_ratio_quot: u64,
|
||||
pub dao_approval_ratio_base: u64,
|
||||
pub gov_token_id: pallas::Base,
|
||||
pub gov_token_id: TokenId,
|
||||
pub dao_pubkey: PublicKey,
|
||||
pub dao_bulla_blind: pallas::Base,
|
||||
pub _signature_secret: SecretKey,
|
||||
@@ -69,7 +69,7 @@ impl Builder {
|
||||
dao_quorum,
|
||||
dao_approval_ratio_quot,
|
||||
dao_approval_ratio_base,
|
||||
self.gov_token_id,
|
||||
self.gov_token_id.inner(),
|
||||
dao_pub_x,
|
||||
dao_pub_y,
|
||||
self.dao_bulla_blind,
|
||||
@@ -89,7 +89,7 @@ impl Builder {
|
||||
Witness::Base(Value::known(dao_quorum)),
|
||||
Witness::Base(Value::known(dao_approval_ratio_quot)),
|
||||
Witness::Base(Value::known(dao_approval_ratio_base)),
|
||||
Witness::Base(Value::known(self.gov_token_id)),
|
||||
Witness::Base(Value::known(self.gov_token_id.inner())),
|
||||
Witness::Base(Value::known(dao_pub_x)),
|
||||
Witness::Base(Value::known(dao_pub_y)),
|
||||
Witness::Base(Value::known(self.dao_bulla_blind)),
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
use darkfi_sdk::crypto::{
|
||||
pedersen::pedersen_commitment_u64, poseidon_hash, MerkleNode, PublicKey, SecretKey,
|
||||
pedersen::pedersen_commitment_u64, poseidon_hash, MerkleNode, PublicKey, SecretKey, TokenId,
|
||||
};
|
||||
use darkfi_serial::{SerialDecodable, SerialEncodable};
|
||||
use halo2_proofs::circuit::Value;
|
||||
@@ -65,7 +65,7 @@ pub struct Proposal {
|
||||
pub dest: PublicKey,
|
||||
pub amount: u64,
|
||||
pub serial: pallas::Base,
|
||||
pub token_id: pallas::Base,
|
||||
pub token_id: TokenId,
|
||||
pub blind: pallas::Base,
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ impl Builder {
|
||||
Witness::Base(Value::known(pallas::Base::from(0))),
|
||||
Witness::Base(Value::known(pallas::Base::from(0))),
|
||||
Witness::Base(Value::known(pallas::Base::from(note.value))),
|
||||
Witness::Base(Value::known(note.token_id)),
|
||||
Witness::Base(Value::known(note.token_id.inner())),
|
||||
Witness::Base(Value::known(note.coin_blind)),
|
||||
Witness::Scalar(Value::known(funds_blind)),
|
||||
Witness::Base(Value::known(gov_token_blind)),
|
||||
@@ -129,7 +129,7 @@ impl Builder {
|
||||
pub_x,
|
||||
pub_y,
|
||||
pallas::Base::from(note.value),
|
||||
note.token_id,
|
||||
note.token_id.inner(),
|
||||
note.serial,
|
||||
pallas::Base::from(0),
|
||||
pallas::Base::from(0),
|
||||
@@ -150,7 +150,7 @@ impl Builder {
|
||||
current
|
||||
};
|
||||
|
||||
let token_commit = poseidon_hash::<2>([note.token_id, gov_token_blind]);
|
||||
let token_commit = poseidon_hash::<2>([note.token_id.inner(), gov_token_blind]);
|
||||
assert_eq!(self.dao.gov_token_id, note.token_id);
|
||||
|
||||
let value_commit = pedersen_commitment_u64(note.value, funds_blind);
|
||||
@@ -181,7 +181,7 @@ impl Builder {
|
||||
let total_funds_coords = total_funds_commit.to_affine().coordinates().unwrap();
|
||||
let total_funds = pallas::Base::from(total_funds);
|
||||
|
||||
let token_commit = poseidon_hash::<2>([self.dao.gov_token_id, gov_token_blind]);
|
||||
let token_commit = poseidon_hash::<2>([self.dao.gov_token_id.inner(), gov_token_blind]);
|
||||
|
||||
let (proposal_dest_x, proposal_dest_y) = self.proposal.dest.xy();
|
||||
|
||||
@@ -199,7 +199,7 @@ impl Builder {
|
||||
dao_quorum,
|
||||
dao_approval_ratio_quot,
|
||||
dao_approval_ratio_base,
|
||||
self.dao.gov_token_id,
|
||||
self.dao.gov_token_id.inner(),
|
||||
dao_pub_x,
|
||||
dao_pub_y,
|
||||
self.dao.bulla_blind,
|
||||
@@ -212,7 +212,7 @@ impl Builder {
|
||||
proposal_dest_y,
|
||||
proposal_amount,
|
||||
self.proposal.serial,
|
||||
self.proposal.token_id,
|
||||
self.proposal.token_id.inner(),
|
||||
dao_bulla,
|
||||
self.proposal.blind,
|
||||
// @tmp-workaround
|
||||
@@ -237,14 +237,14 @@ impl Builder {
|
||||
Witness::Base(Value::known(proposal_dest_y)),
|
||||
Witness::Base(Value::known(proposal_amount)),
|
||||
Witness::Base(Value::known(self.proposal.serial)),
|
||||
Witness::Base(Value::known(self.proposal.token_id)),
|
||||
Witness::Base(Value::known(self.proposal.token_id.inner())),
|
||||
Witness::Base(Value::known(self.proposal.blind)),
|
||||
// DAO params
|
||||
Witness::Base(Value::known(dao_proposer_limit)),
|
||||
Witness::Base(Value::known(dao_quorum)),
|
||||
Witness::Base(Value::known(dao_approval_ratio_quot)),
|
||||
Witness::Base(Value::known(dao_approval_ratio_base)),
|
||||
Witness::Base(Value::known(self.dao.gov_token_id)),
|
||||
Witness::Base(Value::known(self.dao.gov_token_id.inner())),
|
||||
Witness::Base(Value::known(dao_pub_x)),
|
||||
Witness::Base(Value::known(dao_pub_y)),
|
||||
Witness::Base(Value::known(self.dao.bulla_blind)),
|
||||
|
||||
@@ -119,7 +119,7 @@ impl Builder {
|
||||
Witness::Base(Value::known(pallas::Base::from(0))),
|
||||
Witness::Base(Value::known(pallas::Base::from(0))),
|
||||
Witness::Base(Value::known(pallas::Base::from(note.value))),
|
||||
Witness::Base(Value::known(note.token_id)),
|
||||
Witness::Base(Value::known(note.token_id.inner())),
|
||||
Witness::Base(Value::known(note.coin_blind)),
|
||||
Witness::Scalar(Value::known(vote_value_blind)),
|
||||
Witness::Base(Value::known(gov_token_blind)),
|
||||
@@ -135,7 +135,7 @@ impl Builder {
|
||||
pub_x,
|
||||
pub_y,
|
||||
pallas::Base::from(note.value),
|
||||
note.token_id,
|
||||
note.token_id.inner(),
|
||||
note.serial,
|
||||
pallas::Base::from(0),
|
||||
pallas::Base::from(0),
|
||||
@@ -156,7 +156,7 @@ impl Builder {
|
||||
current
|
||||
};
|
||||
|
||||
let token_commit = poseidon_hash::<2>([note.token_id, gov_token_blind]);
|
||||
let token_commit = poseidon_hash::<2>([note.token_id.inner(), gov_token_blind]);
|
||||
assert_eq!(self.dao.gov_token_id, note.token_id);
|
||||
|
||||
let nullifier = poseidon_hash::<2>([input.secret.inner(), note.serial]);
|
||||
@@ -192,7 +192,7 @@ impl Builder {
|
||||
inputs.push(input);
|
||||
}
|
||||
|
||||
let token_commit = poseidon_hash::<2>([self.dao.gov_token_id, gov_token_blind]);
|
||||
let token_commit = poseidon_hash::<2>([self.dao.gov_token_id.inner(), gov_token_blind]);
|
||||
|
||||
let (proposal_dest_x, proposal_dest_y) = self.proposal.dest.xy();
|
||||
|
||||
@@ -210,7 +210,7 @@ impl Builder {
|
||||
dao_quorum,
|
||||
dao_approval_ratio_quot,
|
||||
dao_approval_ratio_base,
|
||||
self.dao.gov_token_id,
|
||||
self.dao.gov_token_id.inner(),
|
||||
dao_pub_x,
|
||||
dao_pub_y,
|
||||
self.dao.bulla_blind,
|
||||
@@ -221,7 +221,7 @@ impl Builder {
|
||||
proposal_dest_y,
|
||||
proposal_amount,
|
||||
self.proposal.serial,
|
||||
self.proposal.token_id,
|
||||
self.proposal.token_id.inner(),
|
||||
dao_bulla,
|
||||
self.proposal.blind,
|
||||
// @tmp-workaround
|
||||
@@ -252,14 +252,14 @@ impl Builder {
|
||||
Witness::Base(Value::known(proposal_dest_y)),
|
||||
Witness::Base(Value::known(proposal_amount)),
|
||||
Witness::Base(Value::known(self.proposal.serial)),
|
||||
Witness::Base(Value::known(self.proposal.token_id)),
|
||||
Witness::Base(Value::known(self.proposal.token_id.inner())),
|
||||
Witness::Base(Value::known(self.proposal.blind)),
|
||||
// DAO params
|
||||
Witness::Base(Value::known(dao_proposer_limit)),
|
||||
Witness::Base(Value::known(dao_quorum)),
|
||||
Witness::Base(Value::known(dao_approval_ratio_quot)),
|
||||
Witness::Base(Value::known(dao_approval_ratio_base)),
|
||||
Witness::Base(Value::known(self.dao.gov_token_id)),
|
||||
Witness::Base(Value::known(self.dao.gov_token_id.inner())),
|
||||
Witness::Base(Value::known(dao_pub_x)),
|
||||
Witness::Base(Value::known(dao_pub_y)),
|
||||
Witness::Base(Value::known(self.dao.bulla_blind)),
|
||||
|
||||
@@ -20,7 +20,7 @@ use std::any::{Any, TypeId};
|
||||
|
||||
use darkfi_sdk::crypto::{
|
||||
pedersen::{pedersen_commitment_base, pedersen_commitment_u64},
|
||||
MerkleNode, Nullifier, PublicKey,
|
||||
MerkleNode, Nullifier, PublicKey, TokenId,
|
||||
};
|
||||
use darkfi_serial::{Encodable, SerialDecodable, SerialEncodable};
|
||||
use incrementalmerkletree::Tree;
|
||||
@@ -30,7 +30,7 @@ use pasta_curves::{group::Group, pallas};
|
||||
use darkfi::{
|
||||
crypto::{
|
||||
coin::Coin,
|
||||
types::{DrkCircuitField, DrkTokenId, DrkValueBlind, DrkValueCommit},
|
||||
types::{DrkCircuitField, DrkValueBlind, DrkValueCommit},
|
||||
BurnRevealedValues, MintRevealedValues,
|
||||
},
|
||||
Error as DarkFiError,
|
||||
@@ -287,7 +287,8 @@ impl CallData {
|
||||
|
||||
failed = failed ||
|
||||
self.clear_inputs.iter().any(|input| {
|
||||
pedersen_commitment_base(input.token_id, input.token_blind) != token_commit_value
|
||||
pedersen_commitment_base(input.token_id.inner(), input.token_blind) !=
|
||||
token_commit_value
|
||||
});
|
||||
!failed
|
||||
}
|
||||
@@ -299,7 +300,7 @@ pub struct ClearInput {
|
||||
/// Input's value (amount)
|
||||
pub value: u64,
|
||||
/// Input's token ID
|
||||
pub token_id: DrkTokenId,
|
||||
pub token_id: TokenId,
|
||||
/// Blinding factor for `value`
|
||||
pub value_blind: DrkValueBlind,
|
||||
/// Blinding factor for `token_id`
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use darkfi_sdk::crypto::{MerkleNode, PublicKey, SecretKey};
|
||||
use darkfi_sdk::crypto::{MerkleNode, PublicKey, SecretKey, TokenId};
|
||||
use darkfi_serial::{SerialDecodable, SerialEncodable};
|
||||
use pasta_curves::group::ff::Field;
|
||||
use rand::rngs::OsRng;
|
||||
@@ -26,8 +26,7 @@ use darkfi::{
|
||||
burn_proof::create_burn_proof,
|
||||
mint_proof::create_mint_proof,
|
||||
types::{
|
||||
DrkCoinBlind, DrkSerial, DrkSpendHook, DrkTokenId, DrkUserData, DrkUserDataBlind,
|
||||
DrkValueBlind,
|
||||
DrkCoinBlind, DrkSerial, DrkSpendHook, DrkUserData, DrkUserDataBlind, DrkValueBlind,
|
||||
},
|
||||
},
|
||||
Result,
|
||||
@@ -46,7 +45,7 @@ use crate::{
|
||||
pub struct Note {
|
||||
pub serial: DrkSerial,
|
||||
pub value: u64,
|
||||
pub token_id: DrkTokenId,
|
||||
pub token_id: TokenId,
|
||||
pub spend_hook: DrkSpendHook,
|
||||
pub user_data: DrkUserData,
|
||||
pub coin_blind: DrkCoinBlind,
|
||||
@@ -62,7 +61,7 @@ pub struct Builder {
|
||||
|
||||
pub struct BuilderClearInputInfo {
|
||||
pub value: u64,
|
||||
pub token_id: DrkTokenId,
|
||||
pub token_id: TokenId,
|
||||
pub signature_secret: SecretKey,
|
||||
}
|
||||
|
||||
@@ -78,7 +77,7 @@ pub struct BuilderInputInfo {
|
||||
|
||||
pub struct BuilderOutputInfo {
|
||||
pub value: u64,
|
||||
pub token_id: DrkTokenId,
|
||||
pub token_id: TokenId,
|
||||
pub public: PublicKey,
|
||||
pub serial: DrkSerial,
|
||||
pub coin_blind: DrkCoinBlind,
|
||||
|
||||
@@ -18,6 +18,12 @@
|
||||
|
||||
use std::{sync::Arc, time::Instant};
|
||||
|
||||
use fxhash::FxHashMap;
|
||||
use log::debug;
|
||||
use rand::rngs::OsRng;
|
||||
use simplelog::{ColorChoice, LevelFilter, TermLogger, TerminalMode};
|
||||
use url::Url;
|
||||
|
||||
use darkfi::{
|
||||
crypto::{
|
||||
proof::{ProvingKey, VerifyingKey},
|
||||
@@ -30,18 +36,13 @@ use darkfi::{
|
||||
};
|
||||
use darkfi_sdk::crypto::{
|
||||
pedersen::pedersen_commitment_u64, poseidon_hash, Keypair, MerkleNode, PublicKey, SecretKey,
|
||||
TokenId,
|
||||
};
|
||||
use fxhash::FxHashMap;
|
||||
use group::ff::PrimeField;
|
||||
use incrementalmerkletree::{Position, Tree};
|
||||
use log::debug;
|
||||
use pasta_curves::{
|
||||
group::{ff::Field, Group},
|
||||
pallas,
|
||||
};
|
||||
use rand::rngs::OsRng;
|
||||
use simplelog::{ColorChoice, LevelFilter, TermLogger, TerminalMode};
|
||||
use url::Url;
|
||||
|
||||
mod contract;
|
||||
mod error;
|
||||
@@ -252,7 +253,7 @@ impl Client {
|
||||
dao_quorum: u64,
|
||||
dao_approval_ratio_quot: u64,
|
||||
dao_approval_ratio_base: u64,
|
||||
token_id: pallas::Base,
|
||||
token_id: TokenId,
|
||||
) -> DaoResult<pallas::Base> {
|
||||
let tx = self.dao_wallet.mint_tx(
|
||||
dao_proposer_limit,
|
||||
@@ -296,7 +297,7 @@ impl Client {
|
||||
|
||||
fn mint_treasury(
|
||||
&mut self,
|
||||
token_id: pallas::Base,
|
||||
token_id: TokenId,
|
||||
token_supply: u64,
|
||||
recipient: PublicKey,
|
||||
) -> DaoResult<()> {
|
||||
@@ -316,12 +317,7 @@ impl Client {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn airdrop_user(
|
||||
&mut self,
|
||||
value: u64,
|
||||
token_id: pallas::Base,
|
||||
addr: PublicKey,
|
||||
) -> DaoResult<()> {
|
||||
fn airdrop_user(&mut self, value: u64, token_id: TokenId, addr: PublicKey) -> DaoResult<()> {
|
||||
// let wallet = self.money_wallets.get(&nym).unwrap();
|
||||
// let addr = wallet.get_public_key();
|
||||
|
||||
@@ -410,7 +406,7 @@ impl Client {
|
||||
pub_x,
|
||||
pub_y,
|
||||
DrkValue::from(note.value),
|
||||
note.token_id,
|
||||
note.token_id.inner(),
|
||||
note.serial,
|
||||
note.spend_hook,
|
||||
note.user_data,
|
||||
@@ -435,7 +431,7 @@ impl Client {
|
||||
pub_x,
|
||||
pub_y,
|
||||
DrkValue::from(note.value),
|
||||
note.token_id,
|
||||
note.token_id.inner(),
|
||||
note.serial,
|
||||
note.spend_hook,
|
||||
note.user_data,
|
||||
@@ -453,7 +449,7 @@ impl Client {
|
||||
fn propose(
|
||||
&mut self,
|
||||
recipient: PublicKey,
|
||||
token_id: pallas::Base,
|
||||
token_id: TokenId,
|
||||
amount: u64,
|
||||
sender: PublicKey,
|
||||
) -> DaoResult<pallas::Base> {
|
||||
@@ -610,7 +606,7 @@ impl DaoWallet {
|
||||
dao_quorum: u64,
|
||||
dao_approval_ratio_quot: u64,
|
||||
dao_approval_ratio_base: u64,
|
||||
token_id: pallas::Base,
|
||||
token_id: TokenId,
|
||||
zk_bins: &ZkContractTable,
|
||||
) -> Transaction {
|
||||
debug!(target: "dao-demo::dao::mint_tx()", "START");
|
||||
@@ -651,7 +647,7 @@ impl DaoWallet {
|
||||
for (coin, is_spent) in &self.own_coins {
|
||||
if *is_spent {}
|
||||
if coin.note.token_id == *DRK_ID || coin.note.token_id == *GOV_ID {
|
||||
let token_id = bs58::encode(coin.note.token_id.to_repr()).into_string();
|
||||
let token_id = format!("{}", coin.note.token_id);
|
||||
ret.insert(token_id, coin.note.value);
|
||||
}
|
||||
}
|
||||
@@ -917,7 +913,7 @@ impl MoneyWallet {
|
||||
for (coin, is_spent) in &self.own_coins {
|
||||
if *is_spent {}
|
||||
if coin.note.token_id == *DRK_ID || coin.note.token_id == *GOV_ID {
|
||||
let token_id = bs58::encode(coin.note.token_id.to_repr()).into_string();
|
||||
let token_id = format!("{}", coin.note.token_id);
|
||||
ret.insert(token_id, coin.note.value);
|
||||
}
|
||||
}
|
||||
@@ -928,7 +924,7 @@ impl MoneyWallet {
|
||||
&mut self,
|
||||
params: DaoParams,
|
||||
recipient: PublicKey,
|
||||
token_id: pallas::Base,
|
||||
token_id: TokenId,
|
||||
amount: u64,
|
||||
dao_leaf_position: Position,
|
||||
zk_bins: &ZkContractTable,
|
||||
@@ -1119,7 +1115,7 @@ impl CashierWallet {
|
||||
|
||||
fn mint(
|
||||
&mut self,
|
||||
token_id: pallas::Base,
|
||||
token_id: TokenId,
|
||||
token_supply: u64,
|
||||
dao_bulla: pallas::Base,
|
||||
recipient: PublicKey,
|
||||
@@ -1137,7 +1133,7 @@ impl CashierWallet {
|
||||
fn transfer_tx(
|
||||
&self,
|
||||
value: u64,
|
||||
token_id: pallas::Base,
|
||||
token_id: TokenId,
|
||||
spend_hook: pallas::Base,
|
||||
user_data: pallas::Base,
|
||||
recipient: PublicKey,
|
||||
@@ -1177,7 +1173,7 @@ impl CashierWallet {
|
||||
fn airdrop(
|
||||
&mut self,
|
||||
value: u64,
|
||||
token_id: pallas::Base,
|
||||
token_id: TokenId,
|
||||
recipient: PublicKey,
|
||||
zk_bins: &ZkContractTable,
|
||||
) -> Result<Transaction> {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
|
||||
use chacha20poly1305::{AeadInPlace, ChaCha20Poly1305, KeyInit};
|
||||
use darkfi_sdk::crypto::{PublicKey, SecretKey};
|
||||
use darkfi_serial::{Decodable, Encodable, SerialDecodable, SerialEncodable};
|
||||
use rand::rngs::OsRng;
|
||||
|
||||
@@ -25,6 +24,10 @@ use darkfi::{
|
||||
crypto::diffie_hellman::{kdf_sapling, sapling_ka_agree},
|
||||
Error, Result,
|
||||
};
|
||||
use darkfi_sdk::{
|
||||
crypto::{PublicKey, SecretKey},
|
||||
pasta::pallas,
|
||||
};
|
||||
|
||||
pub const AEAD_TAG_SIZE: usize = 16;
|
||||
|
||||
@@ -79,9 +82,11 @@ impl EncryptedNote2 {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use darkfi::crypto::types::{DrkCoinBlind, DrkSerial, DrkTokenId, DrkValueBlind};
|
||||
use darkfi_sdk::crypto::Keypair;
|
||||
use group::ff::Field;
|
||||
use darkfi::crypto::types::{DrkCoinBlind, DrkSerial, DrkValueBlind};
|
||||
use darkfi_sdk::{
|
||||
crypto::{Keypair, TokenId},
|
||||
pasta::group::ff::Field,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test_note_encdec() {
|
||||
@@ -89,7 +94,7 @@ mod tests {
|
||||
struct MyNote {
|
||||
serial: DrkSerial,
|
||||
value: u64,
|
||||
token_id: DrkTokenId,
|
||||
token_id: TokenId,
|
||||
coin_blind: DrkCoinBlind,
|
||||
value_blind: DrkValueBlind,
|
||||
token_blind: DrkValueBlind,
|
||||
@@ -98,7 +103,7 @@ mod tests {
|
||||
let note = MyNote {
|
||||
serial: DrkSerial::random(&mut OsRng),
|
||||
value: 110,
|
||||
token_id: DrkTokenId::random(&mut OsRng),
|
||||
token_id: TokenId::from(pallas::Base::random(&mut OsRng)),
|
||||
coin_blind: DrkCoinBlind::random(&mut OsRng),
|
||||
value_blind: DrkValueBlind::random(&mut OsRng),
|
||||
token_blind: DrkValueBlind::random(&mut OsRng),
|
||||
|
||||
@@ -20,9 +20,11 @@ use std::{str::FromStr, sync::Arc};
|
||||
|
||||
use async_std::sync::Mutex;
|
||||
use async_trait::async_trait;
|
||||
use darkfi_sdk::crypto::{Keypair, PublicKey, SecretKey};
|
||||
use darkfi_sdk::{
|
||||
crypto::{Keypair, PublicKey, SecretKey},
|
||||
pasta::group::ff::PrimeField,
|
||||
};
|
||||
use log::{debug, error};
|
||||
use pasta_curves::group::ff::PrimeField;
|
||||
use rand::rngs::OsRng;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
@@ -161,8 +163,7 @@ impl JsonRpcInterface {
|
||||
for proposal in proposals {
|
||||
let dest = proposal.dest;
|
||||
let amount = proposal.amount;
|
||||
let token_id = proposal.token_id;
|
||||
let token_id: String = bs58::encode(token_id.to_repr()).into_string();
|
||||
let token_id = format!("{}", proposal.token_id);
|
||||
//let dest: String = bs58::encode(dest.to_bytes()).into_string();
|
||||
let dest = dest.to_string();
|
||||
proposal_data.push((dest, amount, token_id));
|
||||
@@ -371,7 +372,7 @@ impl JsonRpcInterface {
|
||||
Ok(key) => match client.money_wallets.get(&key.to_bytes()) {
|
||||
Some(wallet) => {
|
||||
let balance = wallet.balances().unwrap();
|
||||
let token_id = bs58::encode((*GOV_ID).to_repr()).into_string();
|
||||
let token_id = format!("{}", *GOV_ID);
|
||||
if balance.get(&token_id).is_some() {
|
||||
*balance.get(&token_id).unwrap()
|
||||
} else {
|
||||
|
||||
@@ -20,7 +20,7 @@ use std::{any::Any, collections::HashMap};
|
||||
|
||||
use darkfi_sdk::crypto::{
|
||||
schnorr::{SchnorrPublic, SchnorrSecret, Signature},
|
||||
PublicKey, SecretKey,
|
||||
PublicKey, SecretKey, TokenId,
|
||||
};
|
||||
use darkfi_serial::Encodable;
|
||||
use lazy_static::lazy_static;
|
||||
@@ -61,12 +61,12 @@ pub fn parse_b58(s: &str) -> std::result::Result<pallas::Base, darkfi::Error> {
|
||||
|
||||
// The token of the DAO treasury.
|
||||
lazy_static! {
|
||||
pub static ref DRK_ID: pallas::Base = pallas::Base::random(&mut OsRng);
|
||||
pub static ref DRK_ID: TokenId = TokenId::from(pallas::Base::random(&mut OsRng));
|
||||
}
|
||||
|
||||
// Governance tokens that are airdropped to users to operate the DAO.
|
||||
lazy_static! {
|
||||
pub static ref GOV_ID: pallas::Base = pallas::Base::random(&mut OsRng);
|
||||
pub static ref GOV_ID: TokenId = TokenId::from(pallas::Base::random(&mut OsRng));
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
||||
@@ -18,13 +18,12 @@
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
use darkfi_sdk::crypto::{Address, PublicKey};
|
||||
use darkfi_sdk::crypto::{Address, PublicKey, TokenId};
|
||||
use darkfi_serial::{deserialize, serialize};
|
||||
use log::{error, warn};
|
||||
use serde_json::{json, Value};
|
||||
|
||||
use darkfi::{
|
||||
crypto::token_id,
|
||||
rpc::jsonrpc::{ErrorCode::InvalidParams, JsonError, JsonResponse, JsonResult},
|
||||
tx::Transaction,
|
||||
};
|
||||
@@ -77,7 +76,7 @@ impl Darkfid {
|
||||
}
|
||||
};
|
||||
|
||||
let token_id = match token_id::parse_b58(token) {
|
||||
let token_id = match TokenId::try_from(token) {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
error!("[RPC] tx.transfer: Failed parsing Token ID from string: {}", e);
|
||||
|
||||
@@ -16,16 +16,14 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use darkfi_sdk::crypto::{Address, Keypair, PublicKey, SecretKey};
|
||||
use darkfi_sdk::crypto::{Address, Keypair, PublicKey, SecretKey, TokenId};
|
||||
use darkfi_serial::{deserialize, serialize};
|
||||
use fxhash::FxHashMap;
|
||||
use incrementalmerkletree::Tree;
|
||||
use log::error;
|
||||
use pasta_curves::group::ff::PrimeField;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
use darkfi::{
|
||||
crypto::token_id,
|
||||
node::State,
|
||||
rpc::jsonrpc::{
|
||||
ErrorCode::{InternalError, InvalidParams, ParseError},
|
||||
@@ -241,7 +239,7 @@ impl Darkfid {
|
||||
let mut ret: FxHashMap<String, u64> = FxHashMap::default();
|
||||
|
||||
for balance in balances.list {
|
||||
let token_id = bs58::encode(balance.token_id.to_repr()).into_string();
|
||||
let token_id = format!("{}", TokenId::from(balance.token_id));
|
||||
let mut amount = balance.value;
|
||||
|
||||
if let Some(prev) = ret.get(&token_id) {
|
||||
@@ -271,7 +269,7 @@ impl Darkfid {
|
||||
|
||||
let value = params[0].as_u64().unwrap();
|
||||
let unspent = params[2].as_bool().unwrap();
|
||||
let token_id = match token_id::parse_b58(params[1].as_str().unwrap()) {
|
||||
let token_id = match TokenId::try_from(params[1].as_str().unwrap()) {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
error!("[RPC] wallet.get_coins_valtok: Failed parsing token_id from base58: {}", e);
|
||||
|
||||
@@ -18,9 +18,8 @@
|
||||
|
||||
use std::process::exit;
|
||||
|
||||
use halo2_proofs::pasta::group::ff::PrimeField;
|
||||
|
||||
use darkfi::{crypto::types::DrkTokenId, util::parse::decode_base10, Result};
|
||||
use darkfi::{util::parse::decode_base10, Result};
|
||||
use darkfi_sdk::crypto::TokenId;
|
||||
|
||||
pub fn parse_value_pair(s: &str) -> Result<(u64, u64)> {
|
||||
let v: Vec<&str> = s.split(':').collect();
|
||||
@@ -41,7 +40,7 @@ pub fn parse_value_pair(s: &str) -> Result<(u64, u64)> {
|
||||
Ok((val0.unwrap(), val1.unwrap()))
|
||||
}
|
||||
|
||||
pub fn parse_token_pair(s: &str) -> Result<(String, String)> {
|
||||
pub fn parse_token_pair(s: &str) -> Result<(TokenId, TokenId)> {
|
||||
let v: Vec<&str> = s.split(':').collect();
|
||||
if v.len() != 2 {
|
||||
eprintln!("Invalid token pair. Use a pair such as:");
|
||||
@@ -49,8 +48,8 @@ pub fn parse_token_pair(s: &str) -> Result<(String, String)> {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
let tok0 = bs58::decode(v[0]).into_vec();
|
||||
let tok1 = bs58::decode(v[1]).into_vec();
|
||||
let tok0 = TokenId::try_from(v[0]);
|
||||
let tok1 = TokenId::try_from(v[1]);
|
||||
|
||||
if tok0.is_err() || tok1.is_err() {
|
||||
eprintln!("Invalid token pair. Use a pair such as:");
|
||||
@@ -58,19 +57,5 @@ pub fn parse_token_pair(s: &str) -> Result<(String, String)> {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if tok0.as_ref().unwrap().len() != 32 ||
|
||||
DrkTokenId::from_repr(tok0.unwrap().try_into().unwrap()).is_some().unwrap_u8() == 0
|
||||
{
|
||||
eprintln!("Error: {} is not a valid token ID", v[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if tok1.as_ref().unwrap().len() != 32 ||
|
||||
DrkTokenId::from_repr(tok1.unwrap().try_into().unwrap()).is_some().unwrap_u8() == 0
|
||||
{
|
||||
eprintln!("Error: {} is not a valid token ID", v[1]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
Ok((v[0].to_string(), v[1].to_string()))
|
||||
Ok((tok0.unwrap(), tok1.unwrap()))
|
||||
}
|
||||
|
||||
@@ -26,10 +26,10 @@ use darkfi_sdk::crypto::{
|
||||
pedersen::{pedersen_commitment_base, pedersen_commitment_u64},
|
||||
schnorr,
|
||||
schnorr::SchnorrSecret,
|
||||
PublicKey, SecretKey,
|
||||
PublicKey, SecretKey, TokenId,
|
||||
};
|
||||
use darkfi_serial::{deserialize, serialize, SerialDecodable, SerialEncodable};
|
||||
use halo2_proofs::{arithmetic::Field, pasta::group::ff::PrimeField};
|
||||
use halo2_proofs::arithmetic::Field;
|
||||
use rand::rngs::OsRng;
|
||||
use url::Url;
|
||||
|
||||
@@ -40,10 +40,8 @@ use darkfi::{
|
||||
mint_proof::{create_mint_proof, verify_mint_proof},
|
||||
note::{EncryptedNote, Note},
|
||||
proof::{ProvingKey, VerifyingKey},
|
||||
token_id,
|
||||
types::{
|
||||
DrkCoinBlind, DrkSerial, DrkSpendHook, DrkTokenId, DrkUserData, DrkUserDataBlind,
|
||||
DrkValueBlind,
|
||||
DrkCoinBlind, DrkSerial, DrkSpendHook, DrkUserData, DrkUserDataBlind, DrkValueBlind,
|
||||
},
|
||||
BurnRevealedValues, MintRevealedValues, Proof,
|
||||
},
|
||||
@@ -115,7 +113,7 @@ struct PartialSwapData {
|
||||
/// Value of the coin to be received
|
||||
mint_value: u64,
|
||||
/// Token ID of the coin to be received
|
||||
mint_token: DrkTokenId,
|
||||
mint_token: TokenId,
|
||||
/// Blinding factor for the minted value pedersen commitment
|
||||
mint_value_blind: DrkValueBlind,
|
||||
/// Blinding factor for the minted token ID pedersen commitment
|
||||
@@ -127,7 +125,7 @@ struct PartialSwapData {
|
||||
/// Value of the coin to be sent
|
||||
burn_value: u64,
|
||||
/// Token ID of the coin to be sent
|
||||
burn_token: DrkTokenId,
|
||||
burn_token: TokenId,
|
||||
/// Blinding factor for the burned value pedersen commitment
|
||||
burn_value_blind: DrkValueBlind,
|
||||
/// Blinding factor for the burned token ID pedersen commitment
|
||||
@@ -146,7 +144,7 @@ struct SwapData {
|
||||
|
||||
async fn init_swap(
|
||||
endpoint: Url,
|
||||
token_pair: (String, String),
|
||||
token_pair: (TokenId, TokenId),
|
||||
value_pair: (u64, u64),
|
||||
) -> Result<PartialSwapData> {
|
||||
let rpc_client = match RpcClient::new(endpoint).await {
|
||||
@@ -159,11 +157,10 @@ async fn init_swap(
|
||||
let rpc = Rpc { rpc_client };
|
||||
|
||||
// TODO: Implement metadata for decimals, don't hardcode.
|
||||
let tp = (token_id::parse_b58(&token_pair.0)?, token_id::parse_b58(&token_pair.1)?);
|
||||
let vp = value_pair;
|
||||
|
||||
// Connect to darkfid and see if there's available funds.
|
||||
let balance = rpc.balance_of(&token_pair.0).await?;
|
||||
let balance = rpc.balance_of(token_pair.0).await?;
|
||||
if balance < vp.0 {
|
||||
eprintln!(
|
||||
"Error: There's not enough balance for token \"{}\" in your wallet.",
|
||||
@@ -180,7 +177,7 @@ async fn init_swap(
|
||||
// TODO: Maybe this should be done by the user beforehand?
|
||||
|
||||
// Find a coin to spend. We can find multiple, but we'll pick the first one.
|
||||
let coins = rpc.get_coins_valtok(vp.0, &token_pair.0).await?;
|
||||
let coins = rpc.get_coins_valtok(vp.0, token_pair.0).await?;
|
||||
if coins.is_empty() {
|
||||
eprintln!("Error: Did not manage to find a coin with enough value to spend.");
|
||||
exit(1);
|
||||
@@ -219,7 +216,7 @@ async fn init_swap(
|
||||
let (mint_proof, mint_revealed) = create_mint_proof(
|
||||
&mint_pk,
|
||||
vp.1,
|
||||
tp.1,
|
||||
token_pair.1,
|
||||
recv_value_blind,
|
||||
recv_token_blind,
|
||||
recv_serial,
|
||||
@@ -251,7 +248,7 @@ async fn init_swap(
|
||||
let (burn_proof, burn_revealed) = create_burn_proof(
|
||||
&burn_pk,
|
||||
vp.0,
|
||||
tp.0,
|
||||
token_pair.0,
|
||||
coin.note.value_blind,
|
||||
coin.note.token_blind,
|
||||
coin.note.serial,
|
||||
@@ -270,7 +267,7 @@ async fn init_swap(
|
||||
let note = Note {
|
||||
serial: recv_serial,
|
||||
value: vp.1,
|
||||
token_id: tp.1,
|
||||
token_id: token_pair.1,
|
||||
coin_blind: recv_coin_blind,
|
||||
value_blind: recv_value_blind,
|
||||
token_blind: recv_token_blind,
|
||||
@@ -285,12 +282,12 @@ async fn init_swap(
|
||||
mint_proof,
|
||||
mint_revealed,
|
||||
mint_value: vp.1,
|
||||
mint_token: tp.1,
|
||||
mint_token: token_pair.1,
|
||||
mint_value_blind: recv_value_blind,
|
||||
mint_token_blind: recv_token_blind,
|
||||
burn_proof,
|
||||
burn_value: vp.0,
|
||||
burn_token: tp.0,
|
||||
burn_token: token_pair.0,
|
||||
burn_revealed,
|
||||
burn_value_blind: coin.note.value_blind,
|
||||
burn_token_blind: coin.note.token_blind,
|
||||
@@ -341,13 +338,13 @@ fn inspect_partial(data: &str) -> Result<()> {
|
||||
let burn_value_valid = pedersen_commitment_u64(sd.burn_value, sd.burn_value_blind) ==
|
||||
sd.burn_revealed.value_commit;
|
||||
|
||||
let burn_token_valid = pedersen_commitment_base(sd.burn_token, sd.burn_token_blind) ==
|
||||
let burn_token_valid = pedersen_commitment_base(sd.burn_token.inner(), sd.burn_token_blind) ==
|
||||
sd.burn_revealed.token_commit;
|
||||
|
||||
let mint_value_valid = pedersen_commitment_u64(sd.mint_value, sd.mint_value_blind) ==
|
||||
sd.mint_revealed.value_commit;
|
||||
|
||||
let mint_token_valid = pedersen_commitment_base(sd.mint_token, sd.mint_token_blind) ==
|
||||
let mint_token_valid = pedersen_commitment_base(sd.mint_token.inner(), sd.mint_token_blind) ==
|
||||
sd.mint_revealed.token_commit;
|
||||
|
||||
let mut valid = true;
|
||||
@@ -403,16 +400,8 @@ fn inspect_partial(data: &str) -> Result<()> {
|
||||
|
||||
eprintln!("========================================");
|
||||
|
||||
eprintln!(
|
||||
"Mint: {} {}",
|
||||
encode_base10(sd.mint_value, 8),
|
||||
bs58::encode(sd.mint_token.to_repr()).into_string()
|
||||
);
|
||||
eprintln!(
|
||||
"Burn: {} {}",
|
||||
encode_base10(sd.burn_value, 8),
|
||||
bs58::encode(sd.burn_token.to_repr()).into_string()
|
||||
);
|
||||
eprintln!("Mint: {} {}", encode_base10(sd.mint_value, 8), sd.mint_token);
|
||||
eprintln!("Burn: {} {}", encode_base10(sd.burn_value, 8), sd.burn_token);
|
||||
|
||||
eprint!("\nThe ZK proofs and commitments inspected are ");
|
||||
if !valid {
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
use std::{process::exit, str::FromStr};
|
||||
|
||||
use darkfi_sdk::crypto::{Address, MerkleNode};
|
||||
use darkfi_sdk::crypto::{Address, MerkleNode, TokenId};
|
||||
use darkfi_serial::{deserialize, serialize};
|
||||
use serde_json::json;
|
||||
|
||||
@@ -38,7 +38,7 @@ pub struct Rpc {
|
||||
|
||||
impl Rpc {
|
||||
/// Fetch wallet balance of given token ID and return its u64 representation.
|
||||
pub async fn balance_of(&self, token_id: &str) -> Result<u64> {
|
||||
pub async fn balance_of(&self, token_id: TokenId) -> Result<u64> {
|
||||
let req = JsonRequest::new("wallet.get_balances", json!([]));
|
||||
let rep = self.rpc_client.request(req).await?;
|
||||
|
||||
@@ -48,7 +48,7 @@ impl Rpc {
|
||||
}
|
||||
|
||||
for i in rep.as_object().unwrap().keys() {
|
||||
if i == token_id {
|
||||
if TokenId::try_from(i.as_str()).unwrap() == token_id {
|
||||
if let Some(balance) = rep[i].as_u64() {
|
||||
return Ok(balance)
|
||||
}
|
||||
@@ -84,8 +84,11 @@ impl Rpc {
|
||||
}
|
||||
|
||||
/// Query wallet for unspent coins in wallet matching value and token_id.
|
||||
pub async fn get_coins_valtok(&self, value: u64, token_id: &str) -> Result<Vec<OwnCoin>> {
|
||||
let req = JsonRequest::new("wallet.get_coins_valtok", json!([value, token_id, true]));
|
||||
pub async fn get_coins_valtok(&self, value: u64, token_id: TokenId) -> Result<Vec<OwnCoin>> {
|
||||
let req = JsonRequest::new(
|
||||
"wallet.get_coins_valtok",
|
||||
json!([value, format!("{}", token_id), true]),
|
||||
);
|
||||
let rep = self.rpc_client.request(req).await?;
|
||||
|
||||
if !rep.is_array() {
|
||||
|
||||
@@ -24,7 +24,7 @@ use std::{
|
||||
};
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
use darkfi_sdk::crypto::Address;
|
||||
use darkfi_sdk::crypto::{Address, TokenId};
|
||||
use prettytable::{format, row, Table};
|
||||
use serde_json::json;
|
||||
use simplelog::{ColorChoice, TermLogger, TerminalMode};
|
||||
@@ -32,7 +32,6 @@ use url::Url;
|
||||
|
||||
use darkfi::{
|
||||
cli_desc,
|
||||
crypto::token_id,
|
||||
rpc::{client::RpcClient, jsonrpc::JsonRequest},
|
||||
util::{
|
||||
cli::{get_log_config, get_log_level, progress_bar},
|
||||
@@ -166,7 +165,7 @@ impl Drk {
|
||||
};
|
||||
|
||||
// Check if token ID is valid base58
|
||||
if token_id::parse_b58(&token_id).is_err() {
|
||||
if TokenId::try_from(token_id.as_str()).is_err() {
|
||||
eprintln!("Error: Invalid Token ID passed as argument.");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ use std::{collections::HashMap, str::FromStr};
|
||||
use async_std::sync::{Arc, Mutex};
|
||||
use async_trait::async_trait;
|
||||
use chrono::Utc;
|
||||
use darkfi_sdk::crypto::{Address, PublicKey};
|
||||
use darkfi_sdk::crypto::{Address, PublicKey, TokenId};
|
||||
use darkfi_serial::serialize;
|
||||
use log::{debug, error, info};
|
||||
use serde_json::{json, Value};
|
||||
@@ -36,7 +36,6 @@ use darkfi::{
|
||||
ValidatorState, ValidatorStatePtr, MAINNET_GENESIS_HASH_BYTES, MAINNET_GENESIS_TIMESTAMP,
|
||||
TESTNET_GENESIS_HASH_BYTES, TESTNET_GENESIS_TIMESTAMP,
|
||||
},
|
||||
crypto::token_id,
|
||||
net,
|
||||
net::P2pPtr,
|
||||
node::Client,
|
||||
@@ -236,10 +235,10 @@ impl Faucetd {
|
||||
|
||||
// Here we allow the faucet to mint arbitrary token IDs.
|
||||
// TODO: Revert this to native token when we have contracts for minting tokens.
|
||||
let token_id = match token_id::parse_b58(params[2].as_str().unwrap()) {
|
||||
let token_id = match TokenId::try_from(params[2].as_str().unwrap()) {
|
||||
Ok(v) => v,
|
||||
Err(_) => {
|
||||
error!("airdrop(): Failed parsing token id from string");
|
||||
Err(e) => {
|
||||
error!("airdrop(): Failed parsing TokenID from string: {}", e);
|
||||
return server_error(RpcError::ParseError, id)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -77,7 +77,7 @@ impl Builder {
|
||||
dao_quorum,
|
||||
dao_approval_ratio_quot,
|
||||
dao_approval_ratio_base,
|
||||
self.dao.gov_token_id,
|
||||
self.dao.gov_token_id.inner(),
|
||||
dao_pub_x,
|
||||
dao_pub_y,
|
||||
self.dao.bulla_blind,
|
||||
@@ -88,7 +88,7 @@ impl Builder {
|
||||
proposal_dest_y,
|
||||
proposal_amount,
|
||||
self.proposal.serial,
|
||||
self.proposal.token_id,
|
||||
self.proposal.token_id.inner(),
|
||||
dao_bulla,
|
||||
self.proposal.blind,
|
||||
// @tmp-workaround
|
||||
@@ -99,7 +99,7 @@ impl Builder {
|
||||
proposal_dest_x,
|
||||
proposal_dest_y,
|
||||
proposal_amount,
|
||||
self.proposal.token_id,
|
||||
self.proposal.token_id.inner(),
|
||||
self.proposal.serial,
|
||||
user_spend_hook,
|
||||
user_data,
|
||||
@@ -110,7 +110,7 @@ impl Builder {
|
||||
dao_pub_x,
|
||||
dao_pub_y,
|
||||
change,
|
||||
self.proposal.token_id,
|
||||
self.proposal.token_id.inner(),
|
||||
self.dao_serial,
|
||||
self.hook_dao_exec,
|
||||
dao_bulla,
|
||||
@@ -142,14 +142,14 @@ impl Builder {
|
||||
Witness::Base(Value::known(proposal_dest_y)),
|
||||
Witness::Base(Value::known(proposal_amount)),
|
||||
Witness::Base(Value::known(self.proposal.serial)),
|
||||
Witness::Base(Value::known(self.proposal.token_id)),
|
||||
Witness::Base(Value::known(self.proposal.token_id.inner())),
|
||||
Witness::Base(Value::known(self.proposal.blind)),
|
||||
// DAO params
|
||||
Witness::Base(Value::known(dao_proposer_limit)),
|
||||
Witness::Base(Value::known(dao_quorum)),
|
||||
Witness::Base(Value::known(dao_approval_ratio_quot)),
|
||||
Witness::Base(Value::known(dao_approval_ratio_base)),
|
||||
Witness::Base(Value::known(self.dao.gov_token_id)),
|
||||
Witness::Base(Value::known(self.dao.gov_token_id.inner())),
|
||||
Witness::Base(Value::known(dao_pub_x)),
|
||||
Witness::Base(Value::known(dao_pub_y)),
|
||||
Witness::Base(Value::known(self.dao.bulla_blind)),
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use darkfi_sdk::crypto::{poseidon_hash, PublicKey, SecretKey};
|
||||
use darkfi_sdk::crypto::{poseidon_hash, PublicKey, SecretKey, TokenId};
|
||||
use halo2_proofs::circuit::Value;
|
||||
use pasta_curves::pallas;
|
||||
use rand::rngs::OsRng;
|
||||
@@ -37,7 +37,7 @@ pub struct DaoParams {
|
||||
pub quorum: u64,
|
||||
pub approval_ratio_quot: u64,
|
||||
pub approval_ratio_base: u64,
|
||||
pub gov_token_id: pallas::Base,
|
||||
pub gov_token_id: TokenId,
|
||||
pub public_key: PublicKey,
|
||||
pub bulla_blind: pallas::Base,
|
||||
}
|
||||
@@ -47,7 +47,7 @@ pub struct Builder {
|
||||
pub dao_quorum: u64,
|
||||
pub dao_approval_ratio_quot: u64,
|
||||
pub dao_approval_ratio_base: u64,
|
||||
pub gov_token_id: pallas::Base,
|
||||
pub gov_token_id: TokenId,
|
||||
pub dao_pubkey: PublicKey,
|
||||
pub dao_bulla_blind: pallas::Base,
|
||||
pub _signature_secret: SecretKey,
|
||||
@@ -69,7 +69,7 @@ impl Builder {
|
||||
dao_quorum,
|
||||
dao_approval_ratio_quot,
|
||||
dao_approval_ratio_base,
|
||||
self.gov_token_id,
|
||||
self.gov_token_id.inner(),
|
||||
dao_pub_x,
|
||||
dao_pub_y,
|
||||
self.dao_bulla_blind,
|
||||
@@ -89,7 +89,7 @@ impl Builder {
|
||||
Witness::Base(Value::known(dao_quorum)),
|
||||
Witness::Base(Value::known(dao_approval_ratio_quot)),
|
||||
Witness::Base(Value::known(dao_approval_ratio_base)),
|
||||
Witness::Base(Value::known(self.gov_token_id)),
|
||||
Witness::Base(Value::known(self.gov_token_id.inner())),
|
||||
Witness::Base(Value::known(dao_pub_x)),
|
||||
Witness::Base(Value::known(dao_pub_y)),
|
||||
Witness::Base(Value::known(self.dao_bulla_blind)),
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
use darkfi_sdk::crypto::{
|
||||
pedersen::pedersen_commitment_u64, poseidon_hash, MerkleNode, PublicKey, SecretKey,
|
||||
pedersen::pedersen_commitment_u64, poseidon_hash, MerkleNode, PublicKey, SecretKey, TokenId,
|
||||
};
|
||||
use darkfi_serial::{SerialDecodable, SerialEncodable};
|
||||
use halo2_proofs::circuit::Value;
|
||||
@@ -65,7 +65,7 @@ pub struct Proposal {
|
||||
pub dest: PublicKey,
|
||||
pub amount: u64,
|
||||
pub serial: pallas::Base,
|
||||
pub token_id: pallas::Base,
|
||||
pub token_id: TokenId,
|
||||
pub blind: pallas::Base,
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ impl Builder {
|
||||
Witness::Base(Value::known(pallas::Base::from(0))),
|
||||
Witness::Base(Value::known(pallas::Base::from(0))),
|
||||
Witness::Base(Value::known(pallas::Base::from(note.value))),
|
||||
Witness::Base(Value::known(note.token_id)),
|
||||
Witness::Base(Value::known(note.token_id.inner())),
|
||||
Witness::Base(Value::known(note.coin_blind)),
|
||||
Witness::Scalar(Value::known(funds_blind)),
|
||||
Witness::Base(Value::known(gov_token_blind)),
|
||||
@@ -129,7 +129,7 @@ impl Builder {
|
||||
pub_x,
|
||||
pub_y,
|
||||
pallas::Base::from(note.value),
|
||||
note.token_id,
|
||||
note.token_id.inner(),
|
||||
note.serial,
|
||||
pallas::Base::from(0),
|
||||
pallas::Base::from(0),
|
||||
@@ -150,7 +150,7 @@ impl Builder {
|
||||
current
|
||||
};
|
||||
|
||||
let token_commit = poseidon_hash::<2>([note.token_id, gov_token_blind]);
|
||||
let token_commit = poseidon_hash::<2>([note.token_id.inner(), gov_token_blind]);
|
||||
assert_eq!(self.dao.gov_token_id, note.token_id);
|
||||
|
||||
let value_commit = pedersen_commitment_u64(note.value, funds_blind);
|
||||
@@ -181,7 +181,7 @@ impl Builder {
|
||||
let total_funds_coords = total_funds_commit.to_affine().coordinates().unwrap();
|
||||
let total_funds = pallas::Base::from(total_funds);
|
||||
|
||||
let token_commit = poseidon_hash::<2>([self.dao.gov_token_id, gov_token_blind]);
|
||||
let token_commit = poseidon_hash::<2>([self.dao.gov_token_id.inner(), gov_token_blind]);
|
||||
|
||||
let (proposal_dest_x, proposal_dest_y) = self.proposal.dest.xy();
|
||||
|
||||
@@ -199,7 +199,7 @@ impl Builder {
|
||||
dao_quorum,
|
||||
dao_approval_ratio_quot,
|
||||
dao_approval_ratio_base,
|
||||
self.dao.gov_token_id,
|
||||
self.dao.gov_token_id.inner(),
|
||||
dao_pub_x,
|
||||
dao_pub_y,
|
||||
self.dao.bulla_blind,
|
||||
@@ -212,7 +212,7 @@ impl Builder {
|
||||
proposal_dest_y,
|
||||
proposal_amount,
|
||||
self.proposal.serial,
|
||||
self.proposal.token_id,
|
||||
self.proposal.token_id.inner(),
|
||||
dao_bulla,
|
||||
self.proposal.blind,
|
||||
// @tmp-workaround
|
||||
@@ -237,14 +237,14 @@ impl Builder {
|
||||
Witness::Base(Value::known(proposal_dest_y)),
|
||||
Witness::Base(Value::known(proposal_amount)),
|
||||
Witness::Base(Value::known(self.proposal.serial)),
|
||||
Witness::Base(Value::known(self.proposal.token_id)),
|
||||
Witness::Base(Value::known(self.proposal.token_id.inner())),
|
||||
Witness::Base(Value::known(self.proposal.blind)),
|
||||
// DAO params
|
||||
Witness::Base(Value::known(dao_proposer_limit)),
|
||||
Witness::Base(Value::known(dao_quorum)),
|
||||
Witness::Base(Value::known(dao_approval_ratio_quot)),
|
||||
Witness::Base(Value::known(dao_approval_ratio_base)),
|
||||
Witness::Base(Value::known(self.dao.gov_token_id)),
|
||||
Witness::Base(Value::known(self.dao.gov_token_id.inner())),
|
||||
Witness::Base(Value::known(dao_pub_x)),
|
||||
Witness::Base(Value::known(dao_pub_y)),
|
||||
Witness::Base(Value::known(self.dao.bulla_blind)),
|
||||
|
||||
@@ -119,7 +119,7 @@ impl Builder {
|
||||
Witness::Base(Value::known(pallas::Base::from(0))),
|
||||
Witness::Base(Value::known(pallas::Base::from(0))),
|
||||
Witness::Base(Value::known(pallas::Base::from(note.value))),
|
||||
Witness::Base(Value::known(note.token_id)),
|
||||
Witness::Base(Value::known(note.token_id.inner())),
|
||||
Witness::Base(Value::known(note.coin_blind)),
|
||||
Witness::Scalar(Value::known(vote_value_blind)),
|
||||
Witness::Base(Value::known(gov_token_blind)),
|
||||
@@ -135,7 +135,7 @@ impl Builder {
|
||||
pub_x,
|
||||
pub_y,
|
||||
pallas::Base::from(note.value),
|
||||
note.token_id,
|
||||
note.token_id.inner(),
|
||||
note.serial,
|
||||
pallas::Base::from(0),
|
||||
pallas::Base::from(0),
|
||||
@@ -156,7 +156,7 @@ impl Builder {
|
||||
current
|
||||
};
|
||||
|
||||
let token_commit = poseidon_hash::<2>([note.token_id, gov_token_blind]);
|
||||
let token_commit = poseidon_hash::<2>([note.token_id.inner(), gov_token_blind]);
|
||||
assert_eq!(self.dao.gov_token_id, note.token_id);
|
||||
|
||||
let nullifier = poseidon_hash::<2>([input.secret.inner(), note.serial]);
|
||||
@@ -192,7 +192,7 @@ impl Builder {
|
||||
inputs.push(input);
|
||||
}
|
||||
|
||||
let token_commit = poseidon_hash::<2>([self.dao.gov_token_id, gov_token_blind]);
|
||||
let token_commit = poseidon_hash::<2>([self.dao.gov_token_id.inner(), gov_token_blind]);
|
||||
|
||||
let (proposal_dest_x, proposal_dest_y) = self.proposal.dest.xy();
|
||||
|
||||
@@ -210,7 +210,7 @@ impl Builder {
|
||||
dao_quorum,
|
||||
dao_approval_ratio_quot,
|
||||
dao_approval_ratio_base,
|
||||
self.dao.gov_token_id,
|
||||
self.dao.gov_token_id.inner(),
|
||||
dao_pub_x,
|
||||
dao_pub_y,
|
||||
self.dao.bulla_blind,
|
||||
@@ -221,7 +221,7 @@ impl Builder {
|
||||
proposal_dest_y,
|
||||
proposal_amount,
|
||||
self.proposal.serial,
|
||||
self.proposal.token_id,
|
||||
self.proposal.token_id.inner(),
|
||||
dao_bulla,
|
||||
self.proposal.blind,
|
||||
// @tmp-workaround
|
||||
@@ -252,14 +252,14 @@ impl Builder {
|
||||
Witness::Base(Value::known(proposal_dest_y)),
|
||||
Witness::Base(Value::known(proposal_amount)),
|
||||
Witness::Base(Value::known(self.proposal.serial)),
|
||||
Witness::Base(Value::known(self.proposal.token_id)),
|
||||
Witness::Base(Value::known(self.proposal.token_id.inner())),
|
||||
Witness::Base(Value::known(self.proposal.blind)),
|
||||
// DAO params
|
||||
Witness::Base(Value::known(dao_proposer_limit)),
|
||||
Witness::Base(Value::known(dao_quorum)),
|
||||
Witness::Base(Value::known(dao_approval_ratio_quot)),
|
||||
Witness::Base(Value::known(dao_approval_ratio_base)),
|
||||
Witness::Base(Value::known(self.dao.gov_token_id)),
|
||||
Witness::Base(Value::known(self.dao.gov_token_id.inner())),
|
||||
Witness::Base(Value::known(dao_pub_x)),
|
||||
Witness::Base(Value::known(dao_pub_y)),
|
||||
Witness::Base(Value::known(self.dao.bulla_blind)),
|
||||
|
||||
@@ -20,7 +20,7 @@ use std::any::{Any, TypeId};
|
||||
|
||||
use darkfi_sdk::crypto::{
|
||||
pedersen::{pedersen_commitment_base, pedersen_commitment_u64},
|
||||
MerkleNode, Nullifier, PublicKey,
|
||||
MerkleNode, Nullifier, PublicKey, TokenId,
|
||||
};
|
||||
use darkfi_serial::{Encodable, SerialDecodable, SerialEncodable};
|
||||
use incrementalmerkletree::Tree;
|
||||
@@ -30,7 +30,7 @@ use pasta_curves::{group::Group, pallas};
|
||||
use darkfi::{
|
||||
crypto::{
|
||||
coin::Coin,
|
||||
types::{DrkCircuitField, DrkTokenId, DrkValueBlind, DrkValueCommit},
|
||||
types::{DrkCircuitField, DrkValueBlind, DrkValueCommit},
|
||||
BurnRevealedValues, MintRevealedValues,
|
||||
},
|
||||
Error as DarkFiError,
|
||||
@@ -285,7 +285,8 @@ impl CallData {
|
||||
|
||||
failed = failed ||
|
||||
self.clear_inputs.iter().any(|input| {
|
||||
pedersen_commitment_base(input.token_id, input.token_blind) != token_commit_value
|
||||
pedersen_commitment_base(input.token_id.inner(), input.token_blind) !=
|
||||
token_commit_value
|
||||
});
|
||||
!failed
|
||||
}
|
||||
@@ -297,7 +298,7 @@ pub struct ClearInput {
|
||||
/// Input's value (amount)
|
||||
pub value: u64,
|
||||
/// Input's token ID
|
||||
pub token_id: DrkTokenId,
|
||||
pub token_id: TokenId,
|
||||
/// Blinding factor for `value`
|
||||
pub value_blind: DrkValueBlind,
|
||||
/// Blinding factor for `token_id`
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use darkfi_sdk::crypto::{MerkleNode, PublicKey, SecretKey};
|
||||
use darkfi_sdk::crypto::{MerkleNode, PublicKey, SecretKey, TokenId};
|
||||
use darkfi_serial::{SerialDecodable, SerialEncodable};
|
||||
use pasta_curves::group::ff::Field;
|
||||
use rand::rngs::OsRng;
|
||||
@@ -26,8 +26,7 @@ use darkfi::{
|
||||
burn_proof::create_burn_proof,
|
||||
mint_proof::create_mint_proof,
|
||||
types::{
|
||||
DrkCoinBlind, DrkSerial, DrkSpendHook, DrkTokenId, DrkUserData, DrkUserDataBlind,
|
||||
DrkValueBlind,
|
||||
DrkCoinBlind, DrkSerial, DrkSpendHook, DrkUserData, DrkUserDataBlind, DrkValueBlind,
|
||||
},
|
||||
},
|
||||
Result,
|
||||
@@ -46,7 +45,7 @@ use crate::{
|
||||
pub struct Note {
|
||||
pub serial: DrkSerial,
|
||||
pub value: u64,
|
||||
pub token_id: DrkTokenId,
|
||||
pub token_id: TokenId,
|
||||
pub spend_hook: DrkSpendHook,
|
||||
pub user_data: DrkUserData,
|
||||
pub coin_blind: DrkCoinBlind,
|
||||
@@ -62,7 +61,7 @@ pub struct Builder {
|
||||
|
||||
pub struct BuilderClearInputInfo {
|
||||
pub value: u64,
|
||||
pub token_id: DrkTokenId,
|
||||
pub token_id: TokenId,
|
||||
pub signature_secret: SecretKey,
|
||||
}
|
||||
|
||||
@@ -78,7 +77,7 @@ pub struct BuilderInputInfo {
|
||||
|
||||
pub struct BuilderOutputInfo {
|
||||
pub value: u64,
|
||||
pub token_id: DrkTokenId,
|
||||
pub token_id: TokenId,
|
||||
pub public: PublicKey,
|
||||
pub serial: DrkSerial,
|
||||
pub coin_blind: DrkCoinBlind,
|
||||
|
||||
@@ -23,7 +23,7 @@ use std::{
|
||||
|
||||
use darkfi_sdk::crypto::{
|
||||
constants::MERKLE_DEPTH, pedersen::pedersen_commitment_u64, poseidon_hash, Keypair, MerkleNode,
|
||||
PublicKey, SecretKey,
|
||||
PublicKey, SecretKey, TokenId,
|
||||
};
|
||||
use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
|
||||
use log::debug;
|
||||
@@ -194,11 +194,11 @@ async fn main() -> Result<()> {
|
||||
|
||||
// Money parameters
|
||||
let xdrk_supply = 1_000_000;
|
||||
let xdrk_token_id = pallas::Base::random(&mut OsRng);
|
||||
let xdrk_token_id = TokenId::from(pallas::Base::random(&mut OsRng));
|
||||
|
||||
// Governance token parameters
|
||||
let gdrk_supply = 1_000_000;
|
||||
let gdrk_token_id = pallas::Base::random(&mut OsRng);
|
||||
let gdrk_token_id = TokenId::from(pallas::Base::random(&mut OsRng));
|
||||
|
||||
// DAO parameters
|
||||
let dao_proposer_limit = 110;
|
||||
@@ -462,7 +462,7 @@ async fn main() -> Result<()> {
|
||||
pub_x,
|
||||
pub_y,
|
||||
DrkValue::from(treasury_note.value),
|
||||
treasury_note.token_id,
|
||||
treasury_note.token_id.inner(),
|
||||
treasury_note.serial,
|
||||
treasury_note.spend_hook,
|
||||
treasury_note.user_data,
|
||||
@@ -612,7 +612,7 @@ async fn main() -> Result<()> {
|
||||
pub_x,
|
||||
pub_y,
|
||||
DrkValue::from(note.value),
|
||||
note.token_id,
|
||||
note.token_id.inner(),
|
||||
note.serial,
|
||||
note.spend_hook,
|
||||
note.user_data,
|
||||
@@ -1241,7 +1241,7 @@ async fn main() -> Result<()> {
|
||||
dao_pub_x,
|
||||
dao_pub_y,
|
||||
pallas::Base::from(xdrk_supply - 1000),
|
||||
xdrk_token_id,
|
||||
xdrk_token_id.inner(),
|
||||
dao_serial,
|
||||
*dao::exec::FUNC_ID,
|
||||
dao_bulla.0,
|
||||
|
||||
@@ -79,9 +79,11 @@ impl EncryptedNote2 {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use darkfi::crypto::types::{DrkCoinBlind, DrkSerial, DrkTokenId, DrkValueBlind};
|
||||
use darkfi_sdk::crypto::Keypair;
|
||||
use group::ff::Field;
|
||||
use darkfi::crypto::types::{DrkCoinBlind, DrkSerial, DrkValueBlind};
|
||||
use darkfi_sdk::{
|
||||
crypto::{Keypair, TokenId},
|
||||
pasta::{group::ff::Field, pallas},
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test_note_encdec() {
|
||||
@@ -89,7 +91,7 @@ mod tests {
|
||||
struct MyNote {
|
||||
serial: DrkSerial,
|
||||
value: u64,
|
||||
token_id: DrkTokenId,
|
||||
token_id: TokenId,
|
||||
coin_blind: DrkCoinBlind,
|
||||
value_blind: DrkValueBlind,
|
||||
token_blind: DrkValueBlind,
|
||||
@@ -98,7 +100,7 @@ mod tests {
|
||||
let note = MyNote {
|
||||
serial: DrkSerial::random(&mut OsRng),
|
||||
value: 110,
|
||||
token_id: DrkTokenId::random(&mut OsRng),
|
||||
token_id: TokenId::from(pallas::Base::random(&mut OsRng)),
|
||||
coin_blind: DrkCoinBlind::random(&mut OsRng),
|
||||
value_blind: DrkValueBlind::random(&mut OsRng),
|
||||
token_blind: DrkValueBlind::random(&mut OsRng),
|
||||
|
||||
@@ -77,7 +77,7 @@ impl Builder {
|
||||
dao_quorum,
|
||||
dao_approval_ratio_quot,
|
||||
dao_approval_ratio_base,
|
||||
self.dao.gov_token_id,
|
||||
self.dao.gov_token_id.inner(),
|
||||
dao_pub_x,
|
||||
dao_pub_y,
|
||||
self.dao.bulla_blind,
|
||||
@@ -88,7 +88,7 @@ impl Builder {
|
||||
proposal_dest_y,
|
||||
proposal_amount,
|
||||
self.proposal.serial,
|
||||
self.proposal.token_id,
|
||||
self.proposal.token_id.inner(),
|
||||
dao_bulla,
|
||||
self.proposal.blind,
|
||||
// @tmp-workaround
|
||||
@@ -99,7 +99,7 @@ impl Builder {
|
||||
proposal_dest_x,
|
||||
proposal_dest_y,
|
||||
proposal_amount,
|
||||
self.proposal.token_id,
|
||||
self.proposal.token_id.inner(),
|
||||
self.proposal.serial,
|
||||
user_spend_hook,
|
||||
user_data,
|
||||
@@ -110,7 +110,7 @@ impl Builder {
|
||||
dao_pub_x,
|
||||
dao_pub_y,
|
||||
change,
|
||||
self.proposal.token_id,
|
||||
self.proposal.token_id.inner(),
|
||||
self.dao_serial,
|
||||
self.hook_dao_exec,
|
||||
dao_bulla,
|
||||
@@ -142,14 +142,14 @@ impl Builder {
|
||||
Witness::Base(Value::known(proposal_dest_y)),
|
||||
Witness::Base(Value::known(proposal_amount)),
|
||||
Witness::Base(Value::known(self.proposal.serial)),
|
||||
Witness::Base(Value::known(self.proposal.token_id)),
|
||||
Witness::Base(Value::known(self.proposal.token_id.inner())),
|
||||
Witness::Base(Value::known(self.proposal.blind)),
|
||||
// DAO params
|
||||
Witness::Base(Value::known(dao_proposer_limit)),
|
||||
Witness::Base(Value::known(dao_quorum)),
|
||||
Witness::Base(Value::known(dao_approval_ratio_quot)),
|
||||
Witness::Base(Value::known(dao_approval_ratio_base)),
|
||||
Witness::Base(Value::known(self.dao.gov_token_id)),
|
||||
Witness::Base(Value::known(self.dao.gov_token_id.inner())),
|
||||
Witness::Base(Value::known(dao_pub_x)),
|
||||
Witness::Base(Value::known(dao_pub_y)),
|
||||
Witness::Base(Value::known(self.dao.bulla_blind)),
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use darkfi_sdk::crypto::{poseidon_hash, PublicKey, SecretKey};
|
||||
use darkfi_sdk::crypto::{poseidon_hash, PublicKey, SecretKey, TokenId};
|
||||
use halo2_proofs::circuit::Value;
|
||||
use pasta_curves::{arithmetic::CurveAffine, group::Curve, pallas};
|
||||
use rand::rngs::OsRng;
|
||||
@@ -39,7 +39,7 @@ pub struct DaoParams {
|
||||
pub quorum: u64,
|
||||
pub approval_ratio_quot: u64,
|
||||
pub approval_ratio_base: u64,
|
||||
pub gov_token_id: pallas::Base,
|
||||
pub gov_token_id: TokenId,
|
||||
pub public_key: PublicKey,
|
||||
pub bulla_blind: pallas::Base,
|
||||
}
|
||||
@@ -49,7 +49,7 @@ pub struct Builder {
|
||||
pub dao_quorum: u64,
|
||||
pub dao_approval_ratio_quot: u64,
|
||||
pub dao_approval_ratio_base: u64,
|
||||
pub gov_token_id: pallas::Base,
|
||||
pub gov_token_id: TokenId,
|
||||
pub dao_pubkey: PublicKey,
|
||||
pub dao_bulla_blind: pallas::Base,
|
||||
pub signature_secret: SecretKey,
|
||||
@@ -71,7 +71,7 @@ impl Builder {
|
||||
dao_quorum,
|
||||
dao_approval_ratio_quot,
|
||||
dao_approval_ratio_base,
|
||||
self.gov_token_id,
|
||||
self.gov_token_id.inner(),
|
||||
dao_pub_x,
|
||||
dao_pub_y,
|
||||
self.dao_bulla_blind,
|
||||
@@ -91,7 +91,7 @@ impl Builder {
|
||||
Witness::Base(Value::known(dao_quorum)),
|
||||
Witness::Base(Value::known(dao_approval_ratio_quot)),
|
||||
Witness::Base(Value::known(dao_approval_ratio_base)),
|
||||
Witness::Base(Value::known(self.gov_token_id)),
|
||||
Witness::Base(Value::known(self.gov_token_id.inner())),
|
||||
Witness::Base(Value::known(dao_pub_x)),
|
||||
Witness::Base(Value::known(dao_pub_y)),
|
||||
Witness::Base(Value::known(self.dao_bulla_blind)),
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
use darkfi_sdk::crypto::{
|
||||
pedersen::pedersen_commitment_u64, poseidon_hash, MerkleNode, PublicKey, SecretKey,
|
||||
pedersen::pedersen_commitment_u64, poseidon_hash, MerkleNode, PublicKey, SecretKey, TokenId,
|
||||
};
|
||||
use darkfi_serial::{SerialDecodable, SerialEncodable};
|
||||
use halo2_proofs::circuit::Value;
|
||||
@@ -65,7 +65,7 @@ pub struct Proposal {
|
||||
pub dest: PublicKey,
|
||||
pub amount: u64,
|
||||
pub serial: pallas::Base,
|
||||
pub token_id: pallas::Base,
|
||||
pub token_id: TokenId,
|
||||
pub blind: pallas::Base,
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ impl Builder {
|
||||
Witness::Base(Value::known(pallas::Base::from(0))),
|
||||
Witness::Base(Value::known(pallas::Base::from(0))),
|
||||
Witness::Base(Value::known(pallas::Base::from(note.value))),
|
||||
Witness::Base(Value::known(note.token_id)),
|
||||
Witness::Base(Value::known(note.token_id.inner())),
|
||||
Witness::Base(Value::known(note.coin_blind)),
|
||||
Witness::Scalar(Value::known(funds_blind)),
|
||||
Witness::Base(Value::known(gov_token_blind)),
|
||||
@@ -129,7 +129,7 @@ impl Builder {
|
||||
pub_x,
|
||||
pub_y,
|
||||
pallas::Base::from(note.value),
|
||||
note.token_id,
|
||||
note.token_id.inner(),
|
||||
note.serial,
|
||||
pallas::Base::from(0),
|
||||
pallas::Base::from(0),
|
||||
@@ -150,7 +150,7 @@ impl Builder {
|
||||
current
|
||||
};
|
||||
|
||||
let token_commit = poseidon_hash::<2>([note.token_id, gov_token_blind]);
|
||||
let token_commit = poseidon_hash::<2>([note.token_id.inner(), gov_token_blind]);
|
||||
assert_eq!(self.dao.gov_token_id, note.token_id);
|
||||
|
||||
let value_commit = pedersen_commitment_u64(note.value, funds_blind);
|
||||
@@ -181,7 +181,7 @@ impl Builder {
|
||||
let total_funds_coords = total_funds_commit.to_affine().coordinates().unwrap();
|
||||
let total_funds = pallas::Base::from(total_funds);
|
||||
|
||||
let token_commit = poseidon_hash::<2>([self.dao.gov_token_id, gov_token_blind]);
|
||||
let token_commit = poseidon_hash::<2>([self.dao.gov_token_id.inner(), gov_token_blind]);
|
||||
|
||||
let (proposal_dest_x, proposal_dest_y) = self.proposal.dest.xy();
|
||||
|
||||
@@ -199,7 +199,7 @@ impl Builder {
|
||||
dao_quorum,
|
||||
dao_approval_ratio_quot,
|
||||
dao_approval_ratio_base,
|
||||
self.dao.gov_token_id,
|
||||
self.dao.gov_token_id.inner(),
|
||||
dao_pub_x,
|
||||
dao_pub_y,
|
||||
self.dao.bulla_blind,
|
||||
@@ -212,7 +212,7 @@ impl Builder {
|
||||
proposal_dest_y,
|
||||
proposal_amount,
|
||||
self.proposal.serial,
|
||||
self.proposal.token_id,
|
||||
self.proposal.token_id.inner(),
|
||||
dao_bulla,
|
||||
self.proposal.blind,
|
||||
// @tmp-workaround
|
||||
@@ -237,14 +237,14 @@ impl Builder {
|
||||
Witness::Base(Value::known(proposal_dest_y)),
|
||||
Witness::Base(Value::known(proposal_amount)),
|
||||
Witness::Base(Value::known(self.proposal.serial)),
|
||||
Witness::Base(Value::known(self.proposal.token_id)),
|
||||
Witness::Base(Value::known(self.proposal.token_id.inner())),
|
||||
Witness::Base(Value::known(self.proposal.blind)),
|
||||
// DAO params
|
||||
Witness::Base(Value::known(dao_proposer_limit)),
|
||||
Witness::Base(Value::known(dao_quorum)),
|
||||
Witness::Base(Value::known(dao_approval_ratio_quot)),
|
||||
Witness::Base(Value::known(dao_approval_ratio_base)),
|
||||
Witness::Base(Value::known(self.dao.gov_token_id)),
|
||||
Witness::Base(Value::known(self.dao.gov_token_id.inner())),
|
||||
Witness::Base(Value::known(dao_pub_x)),
|
||||
Witness::Base(Value::known(dao_pub_y)),
|
||||
Witness::Base(Value::known(self.dao.bulla_blind)),
|
||||
|
||||
@@ -119,7 +119,7 @@ impl Builder {
|
||||
Witness::Base(Value::known(pallas::Base::from(0))),
|
||||
Witness::Base(Value::known(pallas::Base::from(0))),
|
||||
Witness::Base(Value::known(pallas::Base::from(note.value))),
|
||||
Witness::Base(Value::known(note.token_id)),
|
||||
Witness::Base(Value::known(note.token_id.inner())),
|
||||
Witness::Base(Value::known(note.coin_blind)),
|
||||
Witness::Scalar(Value::known(vote_value_blind)),
|
||||
Witness::Base(Value::known(gov_token_blind)),
|
||||
@@ -135,7 +135,7 @@ impl Builder {
|
||||
pub_x,
|
||||
pub_y,
|
||||
pallas::Base::from(note.value),
|
||||
note.token_id,
|
||||
note.token_id.inner(),
|
||||
note.serial,
|
||||
pallas::Base::from(0),
|
||||
pallas::Base::from(0),
|
||||
@@ -156,7 +156,7 @@ impl Builder {
|
||||
current
|
||||
};
|
||||
|
||||
let token_commit = poseidon_hash::<2>([note.token_id, gov_token_blind]);
|
||||
let token_commit = poseidon_hash::<2>([note.token_id.inner(), gov_token_blind]);
|
||||
assert_eq!(self.dao.gov_token_id, note.token_id);
|
||||
|
||||
let nullifier = poseidon_hash::<2>([input.secret.inner(), note.serial]);
|
||||
@@ -192,7 +192,7 @@ impl Builder {
|
||||
inputs.push(input);
|
||||
}
|
||||
|
||||
let token_commit = poseidon_hash::<2>([self.dao.gov_token_id, gov_token_blind]);
|
||||
let token_commit = poseidon_hash::<2>([self.dao.gov_token_id.inner(), gov_token_blind]);
|
||||
|
||||
let (proposal_dest_x, proposal_dest_y) = self.proposal.dest.xy();
|
||||
|
||||
@@ -210,7 +210,7 @@ impl Builder {
|
||||
dao_quorum,
|
||||
dao_approval_ratio_quot,
|
||||
dao_approval_ratio_base,
|
||||
self.dao.gov_token_id,
|
||||
self.dao.gov_token_id.inner(),
|
||||
dao_pub_x,
|
||||
dao_pub_y,
|
||||
self.dao.bulla_blind,
|
||||
@@ -221,7 +221,7 @@ impl Builder {
|
||||
proposal_dest_y,
|
||||
proposal_amount,
|
||||
self.proposal.serial,
|
||||
self.proposal.token_id,
|
||||
self.proposal.token_id.inner(),
|
||||
dao_bulla,
|
||||
self.proposal.blind,
|
||||
// @tmp-workaround
|
||||
@@ -252,14 +252,14 @@ impl Builder {
|
||||
Witness::Base(Value::known(proposal_dest_y)),
|
||||
Witness::Base(Value::known(proposal_amount)),
|
||||
Witness::Base(Value::known(self.proposal.serial)),
|
||||
Witness::Base(Value::known(self.proposal.token_id)),
|
||||
Witness::Base(Value::known(self.proposal.token_id.inner())),
|
||||
Witness::Base(Value::known(self.proposal.blind)),
|
||||
// DAO params
|
||||
Witness::Base(Value::known(dao_proposer_limit)),
|
||||
Witness::Base(Value::known(dao_quorum)),
|
||||
Witness::Base(Value::known(dao_approval_ratio_quot)),
|
||||
Witness::Base(Value::known(dao_approval_ratio_base)),
|
||||
Witness::Base(Value::known(self.dao.gov_token_id)),
|
||||
Witness::Base(Value::known(self.dao.gov_token_id.inner())),
|
||||
Witness::Base(Value::known(dao_pub_x)),
|
||||
Witness::Base(Value::known(dao_pub_y)),
|
||||
Witness::Base(Value::known(self.dao.bulla_blind)),
|
||||
|
||||
@@ -20,7 +20,7 @@ use std::any::{Any, TypeId};
|
||||
|
||||
use darkfi_sdk::crypto::{
|
||||
pedersen::{pedersen_commitment_base, pedersen_commitment_u64},
|
||||
MerkleNode, Nullifier, PublicKey,
|
||||
MerkleNode, Nullifier, PublicKey, TokenId,
|
||||
};
|
||||
use darkfi_serial::{Encodable, SerialDecodable, SerialEncodable};
|
||||
use incrementalmerkletree::Tree;
|
||||
@@ -30,7 +30,7 @@ use pasta_curves::{group::Group, pallas};
|
||||
use darkfi::{
|
||||
crypto::{
|
||||
coin::Coin,
|
||||
types::{DrkCircuitField, DrkTokenId, DrkValueBlind, DrkValueCommit},
|
||||
types::{DrkCircuitField, DrkValueBlind, DrkValueCommit},
|
||||
BurnRevealedValues, MintRevealedValues,
|
||||
},
|
||||
Error as DarkFiError,
|
||||
@@ -285,7 +285,8 @@ impl CallData {
|
||||
|
||||
failed = failed ||
|
||||
self.clear_inputs.iter().any(|input| {
|
||||
pedersen_commitment_base(input.token_id, input.token_blind) != token_commit_value
|
||||
pedersen_commitment_base(input.token_id.inner(), input.token_blind) !=
|
||||
token_commit_value
|
||||
});
|
||||
!failed
|
||||
}
|
||||
@@ -297,7 +298,7 @@ pub struct ClearInput {
|
||||
/// Input's value (amount)
|
||||
pub value: u64,
|
||||
/// Input's token ID
|
||||
pub token_id: DrkTokenId,
|
||||
pub token_id: TokenId,
|
||||
/// Blinding factor for `value`
|
||||
pub value_blind: DrkValueBlind,
|
||||
/// Blinding factor for `token_id`
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use darkfi_sdk::crypto::{MerkleNode, PublicKey, SecretKey};
|
||||
use darkfi_sdk::crypto::{MerkleNode, PublicKey, SecretKey, TokenId};
|
||||
use darkfi_serial::{SerialDecodable, SerialEncodable};
|
||||
use pasta_curves::group::ff::Field;
|
||||
use rand::rngs::OsRng;
|
||||
@@ -26,8 +26,7 @@ use darkfi::{
|
||||
burn_proof::create_burn_proof,
|
||||
mint_proof::create_mint_proof,
|
||||
types::{
|
||||
DrkCoinBlind, DrkSerial, DrkSpendHook, DrkTokenId, DrkUserData, DrkUserDataBlind,
|
||||
DrkValueBlind,
|
||||
DrkCoinBlind, DrkSerial, DrkSpendHook, DrkUserData, DrkUserDataBlind, DrkValueBlind,
|
||||
},
|
||||
},
|
||||
Result,
|
||||
@@ -46,7 +45,7 @@ use crate::{
|
||||
pub struct Note {
|
||||
pub serial: DrkSerial,
|
||||
pub value: u64,
|
||||
pub token_id: DrkTokenId,
|
||||
pub token_id: TokenId,
|
||||
pub spend_hook: DrkSpendHook,
|
||||
pub user_data: DrkUserData,
|
||||
pub coin_blind: DrkCoinBlind,
|
||||
@@ -62,7 +61,7 @@ pub struct Builder {
|
||||
|
||||
pub struct BuilderClearInputInfo {
|
||||
pub value: u64,
|
||||
pub token_id: DrkTokenId,
|
||||
pub token_id: TokenId,
|
||||
pub signature_secret: SecretKey,
|
||||
}
|
||||
|
||||
@@ -78,7 +77,7 @@ pub struct BuilderInputInfo {
|
||||
|
||||
pub struct BuilderOutputInfo {
|
||||
pub value: u64,
|
||||
pub token_id: DrkTokenId,
|
||||
pub token_id: TokenId,
|
||||
pub public: PublicKey,
|
||||
pub serial: DrkSerial,
|
||||
pub coin_blind: DrkCoinBlind,
|
||||
|
||||
@@ -14,7 +14,7 @@ use darkfi::{
|
||||
use darkfi_sdk::{
|
||||
crypto::{
|
||||
constants::MERKLE_DEPTH, pedersen::pedersen_commitment_u64, poseidon_hash, ContractId,
|
||||
Keypair, MerkleNode, MerkleTree, PublicKey, SecretKey,
|
||||
Keypair, MerkleNode, MerkleTree, PublicKey, SecretKey, TokenId,
|
||||
},
|
||||
tx::ContractCall,
|
||||
};
|
||||
@@ -177,11 +177,11 @@ async fn main() -> BoxResult<()> {
|
||||
|
||||
// Money parameters
|
||||
let xdrk_supply = 1_000_000;
|
||||
let xdrk_token_id = pallas::Base::random(&mut OsRng);
|
||||
let xdrk_token_id = TokenId::from(pallas::Base::random(&mut OsRng));
|
||||
|
||||
// Governance token parameters
|
||||
let gdrk_supply = 1_000_000;
|
||||
let gdrk_token_id = pallas::Base::random(&mut OsRng);
|
||||
let gdrk_token_id = TokenId::from(pallas::Base::random(&mut OsRng));
|
||||
|
||||
// DAO parameters
|
||||
let dao_proposer_limit = 110;
|
||||
|
||||
@@ -81,9 +81,12 @@ mod tests {
|
||||
use super::*;
|
||||
use darkfi::crypto::{
|
||||
keypair::Keypair,
|
||||
types::{DrkCoinBlind, DrkSerial, DrkTokenId, DrkValueBlind},
|
||||
types::{DrkCoinBlind, DrkSerial, DrkValueBlind},
|
||||
};
|
||||
use darkfi_sdk::{
|
||||
crypto::TokenId,
|
||||
pasta::{group::ff::Field, pallas},
|
||||
};
|
||||
use group::ff::Field;
|
||||
|
||||
#[test]
|
||||
fn test_note_encdec() {
|
||||
@@ -91,7 +94,7 @@ mod tests {
|
||||
struct MyNote {
|
||||
serial: DrkSerial,
|
||||
value: u64,
|
||||
token_id: DrkTokenId,
|
||||
token_id: TokenId,
|
||||
coin_blind: DrkCoinBlind,
|
||||
value_blind: DrkValueBlind,
|
||||
token_blind: DrkValueBlind,
|
||||
@@ -100,7 +103,7 @@ mod tests {
|
||||
let note = MyNote {
|
||||
serial: DrkSerial::random(&mut OsRng),
|
||||
value: 110,
|
||||
token_id: DrkTokenId::random(&mut OsRng),
|
||||
token_id: TokenId::from(pallas::Base::random(&mut OsRng)),
|
||||
coin_blind: DrkCoinBlind::random(&mut OsRng),
|
||||
value_blind: DrkValueBlind::random(&mut OsRng),
|
||||
token_blind: DrkValueBlind::random(&mut OsRng),
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
// Example transaction flow
|
||||
use darkfi_sdk::crypto::{
|
||||
constants::MERKLE_DEPTH, poseidon_hash, Keypair, MerkleNode, Nullifier, PublicKey, SecretKey,
|
||||
TokenId,
|
||||
};
|
||||
use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
|
||||
use pasta_curves::{group::ff::Field, pallas};
|
||||
@@ -158,7 +159,7 @@ fn main() -> Result<()> {
|
||||
secrets: vec![keypair.secret],
|
||||
};
|
||||
|
||||
let token_id = pallas::Base::random(&mut OsRng);
|
||||
let token_id = TokenId::from(pallas::Base::random(&mut OsRng));
|
||||
|
||||
let builder = TransactionBuilder {
|
||||
clear_inputs: vec![TransactionBuilderClearInputInfo {
|
||||
|
||||
@@ -22,7 +22,7 @@ use darkfi_sdk::{
|
||||
pedersen::{pedersen_commitment_base, pedersen_commitment_u64},
|
||||
poseidon_hash,
|
||||
util::mod_r_p,
|
||||
Keypair, MerkleNode, Nullifier, SecretKey,
|
||||
Keypair, MerkleNode, Nullifier, SecretKey, TokenId,
|
||||
},
|
||||
incrementalmerkletree::{bridgetree::BridgeTree, Tree},
|
||||
pasta::{
|
||||
@@ -45,7 +45,7 @@ use crate::{
|
||||
coin::{Coin, OwnCoin},
|
||||
leadcoin::LeadCoin,
|
||||
note::Note,
|
||||
types::{DrkCoinBlind, DrkSerial, DrkTokenId, DrkValueBlind},
|
||||
types::{DrkCoinBlind, DrkSerial, DrkValueBlind},
|
||||
},
|
||||
wallet::walletdb::WalletDb,
|
||||
Result,
|
||||
@@ -404,7 +404,7 @@ pub fn is_leader(slot: u64, epoch_coins: &Vec<Vec<LeadCoin>>) -> (bool, usize) {
|
||||
/// Generate staking coins for provided wallet.
|
||||
pub async fn generate_staking_coins(wallet: &WalletDb) -> Result<Vec<OwnCoin>> {
|
||||
let keypair = wallet.get_default_keypair().await?;
|
||||
let token_id = DrkTokenId::random(&mut OsRng);
|
||||
let token_id = TokenId::from(pallas::Base::random(&mut OsRng));
|
||||
let value = 420;
|
||||
let serial = DrkSerial::random(&mut OsRng);
|
||||
let note = Note {
|
||||
|
||||
@@ -22,6 +22,7 @@ use async_std::sync::Arc;
|
||||
use darkfi_sdk::{
|
||||
crypto::{
|
||||
constants::MERKLE_DEPTH, schnorr::SchnorrSecret, Address, MerkleNode, PublicKey, SecretKey,
|
||||
TokenId,
|
||||
},
|
||||
incrementalmerkletree::bridgetree::BridgeTree,
|
||||
pasta::{group::ff::PrimeField, pallas},
|
||||
@@ -414,7 +415,7 @@ impl Stakeholder {
|
||||
secrets: vec![keypair.secret],
|
||||
};
|
||||
|
||||
let token_id = pallas::Base::random(&mut OsRng);
|
||||
let token_id = TokenId::from(pallas::Base::random(&mut OsRng));
|
||||
let builder = TransactionBuilder {
|
||||
clear_inputs: vec![TransactionBuilderClearInputInfo {
|
||||
value: coin.value.unwrap(),
|
||||
|
||||
@@ -21,7 +21,7 @@ use std::time::Instant;
|
||||
use darkfi_sdk::{
|
||||
crypto::{
|
||||
pedersen::{pedersen_commitment_base, pedersen_commitment_u64},
|
||||
poseidon_hash, MerkleNode, Nullifier, PublicKey, SecretKey,
|
||||
poseidon_hash, MerkleNode, Nullifier, PublicKey, SecretKey, TokenId,
|
||||
},
|
||||
incrementalmerkletree::Hashable,
|
||||
pasta::{arithmetic::CurveAffine, group::Curve},
|
||||
@@ -34,8 +34,8 @@ use rand::rngs::OsRng;
|
||||
use super::proof::{Proof, ProvingKey, VerifyingKey};
|
||||
use crate::{
|
||||
crypto::types::{
|
||||
DrkCircuitField, DrkCoinBlind, DrkSerial, DrkSpendHook, DrkTokenId, DrkUserData,
|
||||
DrkUserDataBlind, DrkUserDataEnc, DrkValue, DrkValueBlind, DrkValueCommit,
|
||||
DrkCircuitField, DrkCoinBlind, DrkSerial, DrkSpendHook, DrkUserData, DrkUserDataBlind,
|
||||
DrkUserDataEnc, DrkValue, DrkValueBlind, DrkValueCommit,
|
||||
},
|
||||
zk::circuit::burn_contract::BurnContract,
|
||||
Result,
|
||||
@@ -56,7 +56,7 @@ impl BurnRevealedValues {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn compute(
|
||||
value: u64,
|
||||
token_id: DrkTokenId,
|
||||
token_id: TokenId,
|
||||
value_blind: DrkValueBlind,
|
||||
token_blind: DrkValueBlind,
|
||||
serial: DrkSerial,
|
||||
@@ -78,7 +78,7 @@ impl BurnRevealedValues {
|
||||
pub_x,
|
||||
pub_y,
|
||||
DrkValue::from(value),
|
||||
token_id,
|
||||
token_id.inner(),
|
||||
serial,
|
||||
spend_hook,
|
||||
user_data,
|
||||
@@ -102,7 +102,7 @@ impl BurnRevealedValues {
|
||||
let user_data_enc = poseidon_hash::<2>([user_data, user_data_blind]);
|
||||
|
||||
let value_commit = pedersen_commitment_u64(value, value_blind);
|
||||
let token_commit = pedersen_commitment_base(token_id, token_blind);
|
||||
let token_commit = pedersen_commitment_base(token_id.inner(), token_blind);
|
||||
|
||||
BurnRevealedValues {
|
||||
value_commit,
|
||||
@@ -140,7 +140,7 @@ impl BurnRevealedValues {
|
||||
pub fn create_burn_proof(
|
||||
pk: &ProvingKey,
|
||||
value: u64,
|
||||
token_id: DrkTokenId,
|
||||
token_id: TokenId,
|
||||
value_blind: DrkValueBlind,
|
||||
token_blind: DrkValueBlind,
|
||||
serial: DrkSerial,
|
||||
@@ -175,7 +175,7 @@ pub fn create_burn_proof(
|
||||
secret_key: Value::known(secret.inner()),
|
||||
serial: Value::known(serial),
|
||||
value: Value::known(DrkValue::from(value)),
|
||||
token: Value::known(token_id),
|
||||
token: Value::known(token_id.inner()),
|
||||
coin_blind: Value::known(coin_blind),
|
||||
value_blind: Value::known(value_blind),
|
||||
token_blind: Value::known(token_blind),
|
||||
|
||||
@@ -21,7 +21,7 @@ use std::time::Instant;
|
||||
use darkfi_sdk::{
|
||||
crypto::{
|
||||
pedersen::{pedersen_commitment_base, pedersen_commitment_u64},
|
||||
poseidon_hash, PublicKey,
|
||||
poseidon_hash, PublicKey, TokenId,
|
||||
},
|
||||
pasta::{arithmetic::CurveAffine, group::Curve},
|
||||
};
|
||||
@@ -35,8 +35,8 @@ use crate::{
|
||||
coin::Coin,
|
||||
proof::{Proof, ProvingKey, VerifyingKey},
|
||||
types::{
|
||||
DrkCircuitField, DrkCoinBlind, DrkSerial, DrkSpendHook, DrkTokenId, DrkUserData,
|
||||
DrkValue, DrkValueBlind, DrkValueCommit,
|
||||
DrkCircuitField, DrkCoinBlind, DrkSerial, DrkSpendHook, DrkUserData, DrkValue,
|
||||
DrkValueBlind, DrkValueCommit,
|
||||
},
|
||||
},
|
||||
zk::circuit::mint_contract::MintContract,
|
||||
@@ -54,7 +54,7 @@ impl MintRevealedValues {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn compute(
|
||||
value: u64,
|
||||
token_id: DrkTokenId,
|
||||
token_id: TokenId,
|
||||
value_blind: DrkValueBlind,
|
||||
token_blind: DrkValueBlind,
|
||||
serial: DrkSerial,
|
||||
@@ -64,7 +64,7 @@ impl MintRevealedValues {
|
||||
public_key: PublicKey,
|
||||
) -> Self {
|
||||
let value_commit = pedersen_commitment_u64(value, value_blind);
|
||||
let token_commit = pedersen_commitment_base(token_id, token_blind);
|
||||
let token_commit = pedersen_commitment_base(token_id.inner(), token_blind);
|
||||
|
||||
let (pub_x, pub_y) = public_key.xy();
|
||||
|
||||
@@ -72,7 +72,7 @@ impl MintRevealedValues {
|
||||
pub_x,
|
||||
pub_y,
|
||||
DrkValue::from(value),
|
||||
token_id,
|
||||
token_id.inner(),
|
||||
serial,
|
||||
spend_hook,
|
||||
user_data,
|
||||
@@ -100,7 +100,7 @@ impl MintRevealedValues {
|
||||
pub fn create_mint_proof(
|
||||
pk: &ProvingKey,
|
||||
value: u64,
|
||||
token_id: DrkTokenId,
|
||||
token_id: TokenId,
|
||||
value_blind: DrkValueBlind,
|
||||
token_blind: DrkValueBlind,
|
||||
serial: DrkSerial,
|
||||
@@ -127,7 +127,7 @@ pub fn create_mint_proof(
|
||||
pub_x: Value::known(pub_x),
|
||||
pub_y: Value::known(pub_y),
|
||||
value: Value::known(DrkValue::from(value)),
|
||||
token: Value::known(token_id),
|
||||
token: Value::known(token_id.inner()),
|
||||
serial: Value::known(serial),
|
||||
coin_blind: Value::known(coin_blind),
|
||||
spend_hook: Value::known(spend_hook),
|
||||
|
||||
@@ -17,14 +17,14 @@
|
||||
*/
|
||||
|
||||
use chacha20poly1305::{AeadInPlace, ChaCha20Poly1305, KeyInit};
|
||||
use darkfi_sdk::crypto::{PublicKey, SecretKey};
|
||||
use darkfi_sdk::crypto::{PublicKey, SecretKey, TokenId};
|
||||
use darkfi_serial::{Decodable, Encodable, SerialDecodable, SerialEncodable};
|
||||
use rand::rngs::OsRng;
|
||||
|
||||
use crate::{
|
||||
crypto::{
|
||||
diffie_hellman::{kdf_sapling, sapling_ka_agree},
|
||||
types::{DrkCoinBlind, DrkSerial, DrkTokenId, DrkValueBlind},
|
||||
types::{DrkCoinBlind, DrkSerial, DrkValueBlind},
|
||||
},
|
||||
Error, Result,
|
||||
};
|
||||
@@ -35,7 +35,7 @@ pub const AEAD_TAG_SIZE: usize = 16;
|
||||
pub struct Note {
|
||||
pub serial: DrkSerial,
|
||||
pub value: u64,
|
||||
pub token_id: DrkTokenId,
|
||||
pub token_id: TokenId,
|
||||
pub coin_blind: DrkCoinBlind,
|
||||
pub value_blind: DrkValueBlind,
|
||||
pub token_blind: DrkValueBlind,
|
||||
@@ -93,14 +93,17 @@ impl EncryptedNote {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use darkfi_sdk::{crypto::Keypair, pasta::group::ff::Field};
|
||||
use darkfi_sdk::{
|
||||
crypto::{Keypair, TokenId},
|
||||
pasta::{group::ff::Field, pallas},
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test_note_encdec() {
|
||||
let note = Note {
|
||||
serial: DrkSerial::random(&mut OsRng),
|
||||
value: 110,
|
||||
token_id: DrkTokenId::random(&mut OsRng),
|
||||
token_id: TokenId::from(pallas::Base::random(&mut OsRng)),
|
||||
coin_blind: DrkCoinBlind::random(&mut OsRng),
|
||||
value_blind: DrkValueBlind::random(&mut OsRng),
|
||||
token_blind: DrkValueBlind::random(&mut OsRng),
|
||||
|
||||
@@ -114,16 +114,14 @@ mod tests {
|
||||
use crate::{
|
||||
crypto::{
|
||||
mint_proof::create_mint_proof,
|
||||
types::{
|
||||
DrkCoinBlind, DrkSerial, DrkSpendHook, DrkTokenId, DrkUserData, DrkValueBlind,
|
||||
},
|
||||
types::{DrkCoinBlind, DrkSerial, DrkSpendHook, DrkUserData, DrkValueBlind},
|
||||
},
|
||||
zk::circuit::MintContract,
|
||||
Result,
|
||||
};
|
||||
use darkfi_sdk::{
|
||||
crypto::{PublicKey, SecretKey},
|
||||
pasta::group::ff::Field,
|
||||
crypto::{PublicKey, SecretKey, TokenId},
|
||||
pasta::{group::ff::Field, pallas},
|
||||
};
|
||||
use darkfi_serial::{Decodable, Encodable};
|
||||
use rand::rngs::OsRng;
|
||||
@@ -131,7 +129,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_proof_serialization() -> Result<()> {
|
||||
let value = 110_u64;
|
||||
let token_id = DrkTokenId::random(&mut OsRng);
|
||||
let token_id = TokenId::from(pallas::Base::random(&mut OsRng));
|
||||
let value_blind = DrkValueBlind::random(&mut OsRng);
|
||||
let token_blind = DrkValueBlind::random(&mut OsRng);
|
||||
let serial = DrkSerial::random(&mut OsRng);
|
||||
|
||||
@@ -22,7 +22,6 @@ use pasta_curves::pallas;
|
||||
|
||||
pub type DrkCircuitField = pallas::Base;
|
||||
|
||||
pub type DrkTokenId = pallas::Base;
|
||||
pub type DrkValue = pallas::Base;
|
||||
pub type DrkSerial = pallas::Base;
|
||||
|
||||
|
||||
@@ -17,18 +17,18 @@
|
||||
*/
|
||||
|
||||
use async_std::sync::{Arc, Mutex};
|
||||
use darkfi_sdk::crypto::{constants::MERKLE_DEPTH, Address, Keypair, MerkleNode, PublicKey};
|
||||
use darkfi_sdk::crypto::{
|
||||
constants::MERKLE_DEPTH, Address, Keypair, MerkleNode, PublicKey, TokenId,
|
||||
};
|
||||
use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
|
||||
use lazy_init::Lazy;
|
||||
use log::{debug, error, info};
|
||||
use pasta_curves::group::ff::PrimeField;
|
||||
|
||||
use super::state::{state_transition, State};
|
||||
use crate::{
|
||||
crypto::{
|
||||
coin::{Coin, OwnCoin},
|
||||
proof::ProvingKey,
|
||||
types::DrkTokenId,
|
||||
},
|
||||
tx::{
|
||||
builder::{
|
||||
@@ -79,7 +79,7 @@ impl Client {
|
||||
&self,
|
||||
pubkey: PublicKey,
|
||||
value: u64,
|
||||
token_id: DrkTokenId,
|
||||
token_id: TokenId,
|
||||
clear_input: bool,
|
||||
state: Arc<Mutex<State>>,
|
||||
) -> ClientResult<(Transaction, Vec<Coin>)> {
|
||||
@@ -163,15 +163,11 @@ impl Client {
|
||||
&self,
|
||||
pubkey: PublicKey,
|
||||
amount: u64,
|
||||
token_id: DrkTokenId,
|
||||
token_id: TokenId,
|
||||
clear_input: bool,
|
||||
state: Arc<Mutex<State>>,
|
||||
) -> ClientResult<Transaction> {
|
||||
debug!(
|
||||
"send(): Sending {} {} tokens",
|
||||
amount,
|
||||
bs58::encode(token_id.to_repr()).into_string()
|
||||
);
|
||||
debug!("send(): Sending {} {} tokens", amount, token_id);
|
||||
|
||||
if amount == 0 {
|
||||
return Err(ClientFailed::InvalidAmount(0))
|
||||
@@ -230,7 +226,7 @@ impl Client {
|
||||
Ok(Address::from(kp.public))
|
||||
}
|
||||
|
||||
pub async fn get_balance(&self, token_id: DrkTokenId) -> Result<Option<Balance>> {
|
||||
pub async fn get_balance(&self, token_id: TokenId) -> Result<Option<Balance>> {
|
||||
self.wallet.get_balance(token_id).await
|
||||
}
|
||||
|
||||
@@ -241,7 +237,7 @@ impl Client {
|
||||
pub async fn get_coins_valtok(
|
||||
&self,
|
||||
value: u64,
|
||||
token_id: DrkTokenId,
|
||||
token_id: TokenId,
|
||||
unspent: bool,
|
||||
) -> Result<Vec<OwnCoin>> {
|
||||
self.wallet.get_coins_valtok(value, token_id, unspent).await
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use darkfi_sdk::crypto::{schnorr::SchnorrSecret, MerkleNode, PublicKey, SecretKey};
|
||||
use darkfi_sdk::crypto::{schnorr::SchnorrSecret, MerkleNode, PublicKey, SecretKey, TokenId};
|
||||
use darkfi_serial::serialize;
|
||||
use pasta_curves::group::ff::Field;
|
||||
use rand::rngs::OsRng;
|
||||
@@ -32,8 +32,7 @@ use crate::{
|
||||
note::Note,
|
||||
proof::ProvingKey,
|
||||
types::{
|
||||
DrkCoinBlind, DrkSerial, DrkSpendHook, DrkTokenId, DrkUserData, DrkUserDataBlind,
|
||||
DrkValueBlind,
|
||||
DrkCoinBlind, DrkSerial, DrkSpendHook, DrkUserData, DrkUserDataBlind, DrkValueBlind,
|
||||
},
|
||||
},
|
||||
Result,
|
||||
@@ -47,7 +46,7 @@ pub struct TransactionBuilder {
|
||||
|
||||
pub struct TransactionBuilderClearInputInfo {
|
||||
pub value: u64,
|
||||
pub token_id: DrkTokenId,
|
||||
pub token_id: TokenId,
|
||||
pub signature_secret: SecretKey,
|
||||
}
|
||||
|
||||
@@ -60,7 +59,7 @@ pub struct TransactionBuilderInputInfo {
|
||||
|
||||
pub struct TransactionBuilderOutputInfo {
|
||||
pub value: u64,
|
||||
pub token_id: DrkTokenId,
|
||||
pub token_id: TokenId,
|
||||
pub public: PublicKey,
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ use darkfi_sdk::crypto::{
|
||||
pedersen::{pedersen_commitment_base, pedersen_commitment_u64},
|
||||
schnorr,
|
||||
schnorr::SchnorrPublic,
|
||||
PublicKey,
|
||||
PublicKey, TokenId,
|
||||
};
|
||||
use darkfi_serial::{Encodable, SerialDecodable, SerialEncodable, VarInt};
|
||||
use log::error;
|
||||
@@ -34,7 +34,7 @@ use crate::{
|
||||
mint_proof::verify_mint_proof,
|
||||
note::EncryptedNote,
|
||||
proof::VerifyingKey,
|
||||
types::{DrkTokenId, DrkValueBlind, DrkValueCommit},
|
||||
types::{DrkValueBlind, DrkValueCommit},
|
||||
BurnRevealedValues, MintRevealedValues, Proof,
|
||||
},
|
||||
Result, VerifyFailed, VerifyResult,
|
||||
@@ -60,7 +60,7 @@ pub struct TransactionClearInput {
|
||||
/// Input's value (amount)
|
||||
pub value: u64,
|
||||
/// Input's token ID
|
||||
pub token_id: DrkTokenId,
|
||||
pub token_id: TokenId,
|
||||
/// Blinding factor for `value`
|
||||
pub value_blind: DrkValueBlind,
|
||||
/// Blinding factor for `token_id`
|
||||
@@ -192,7 +192,8 @@ impl Transaction {
|
||||
|
||||
failed = failed ||
|
||||
self.clear_inputs.iter().any(|input| {
|
||||
pedersen_commitment_base(input.token_id, input.token_blind) != token_commit_value
|
||||
pedersen_commitment_base(input.token_id.inner(), input.token_blind) !=
|
||||
token_commit_value
|
||||
});
|
||||
!failed
|
||||
}
|
||||
|
||||
@@ -16,14 +16,11 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use darkfi_sdk::crypto::PublicKey;
|
||||
use darkfi_sdk::crypto::{PublicKey, TokenId};
|
||||
use darkfi_serial::{SerialDecodable, SerialEncodable};
|
||||
|
||||
use super::TransactionOutput;
|
||||
use crate::crypto::{
|
||||
types::{DrkTokenId, DrkValueBlind},
|
||||
BurnRevealedValues, Proof,
|
||||
};
|
||||
use crate::crypto::{types::DrkValueBlind, BurnRevealedValues, Proof};
|
||||
|
||||
#[derive(Clone, SerialEncodable, SerialDecodable)]
|
||||
pub struct PartialTransaction {
|
||||
@@ -35,7 +32,7 @@ pub struct PartialTransaction {
|
||||
#[derive(Clone, SerialEncodable, SerialDecodable)]
|
||||
pub struct PartialTransactionClearInput {
|
||||
pub value: u64,
|
||||
pub token_id: DrkTokenId,
|
||||
pub token_id: TokenId,
|
||||
pub value_blind: DrkValueBlind,
|
||||
pub token_blind: DrkValueBlind,
|
||||
pub signature_public: PublicKey,
|
||||
|
||||
@@ -30,7 +30,6 @@ use crate::{
|
||||
crypto::{
|
||||
keypair::{Keypair, PublicKey, SecretKey},
|
||||
merkle_node::MerkleNode,
|
||||
types::DrkTokenId,
|
||||
},
|
||||
util::{
|
||||
serial::{deserialize, serialize},
|
||||
@@ -51,14 +50,14 @@ pub struct TokenKey {
|
||||
pub struct WithdrawToken {
|
||||
pub token_public_key: Vec<u8>,
|
||||
pub network: NetworkName,
|
||||
pub token_id: DrkTokenId,
|
||||
pub token_id: TokenId,
|
||||
pub mint_address: String,
|
||||
}
|
||||
|
||||
pub struct DepositToken {
|
||||
pub drk_public_key: PublicKey,
|
||||
pub token_key: TokenKey,
|
||||
pub token_id: DrkTokenId,
|
||||
pub token_id: TokenId,
|
||||
pub mint_address: String,
|
||||
}
|
||||
|
||||
@@ -212,7 +211,7 @@ impl CashierDb {
|
||||
d_key_public: &PublicKey,
|
||||
d_key_secret: &SecretKey,
|
||||
network: &NetworkName,
|
||||
token_id: &DrkTokenId,
|
||||
token_id: TokenId,
|
||||
mint_address: String,
|
||||
) -> Result<()> {
|
||||
debug!("Writing withdraw keys to database");
|
||||
@@ -250,7 +249,7 @@ impl CashierDb {
|
||||
token_key_secret: &[u8],
|
||||
token_key_public: &[u8],
|
||||
network: &NetworkName,
|
||||
token_id: &DrkTokenId,
|
||||
token_id: TokenId,
|
||||
mint_address: String,
|
||||
) -> Result<()> {
|
||||
debug!("Writing deposit keys to database");
|
||||
@@ -514,7 +513,7 @@ mod tests {
|
||||
let token_addr_public = serialize(&String::from("mxVFsFW5N4mu1HPkxPttorvocvzeZ7KZyk"));
|
||||
|
||||
let keypair = Keypair::random(&mut OsRng);
|
||||
let token_id = DrkTokenId::random(&mut OsRng);
|
||||
let token_id = TokenId::from(pallas::Base::random(&mut OsRng));
|
||||
|
||||
let network = NetworkName::Bitcoin;
|
||||
|
||||
|
||||
@@ -20,12 +20,11 @@ use std::{fs::create_dir_all, path::Path, str::FromStr, time::Duration};
|
||||
|
||||
use async_std::sync::Arc;
|
||||
use darkfi_sdk::crypto::{
|
||||
constants::MERKLE_DEPTH, Address, Keypair, MerkleNode, Nullifier, PublicKey, SecretKey,
|
||||
constants::MERKLE_DEPTH, Address, Keypair, MerkleNode, Nullifier, PublicKey, SecretKey, TokenId,
|
||||
};
|
||||
use darkfi_serial::{deserialize, serialize};
|
||||
use incrementalmerkletree::bridgetree::BridgeTree;
|
||||
use log::{debug, error, info, LevelFilter};
|
||||
use pasta_curves::group::ff::PrimeField;
|
||||
use rand::rngs::OsRng;
|
||||
use sqlx::{
|
||||
sqlite::{SqliteConnectOptions, SqliteJournalMode},
|
||||
@@ -36,7 +35,6 @@ use crate::{
|
||||
crypto::{
|
||||
coin::{Coin, OwnCoin},
|
||||
note::Note,
|
||||
types::DrkTokenId,
|
||||
},
|
||||
util::path::expand_path,
|
||||
Error::{WalletEmptyPassword, WalletTreeExists},
|
||||
@@ -47,7 +45,7 @@ pub type WalletPtr = Arc<WalletDb>;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Balance {
|
||||
pub token_id: DrkTokenId,
|
||||
pub token_id: TokenId,
|
||||
pub value: u64,
|
||||
pub nullifier: Nullifier,
|
||||
}
|
||||
@@ -300,14 +298,10 @@ impl WalletDb {
|
||||
pub async fn get_coins_valtok(
|
||||
&self,
|
||||
value: u64,
|
||||
token_id: DrkTokenId,
|
||||
token_id: TokenId,
|
||||
unspent: bool,
|
||||
) -> Result<Vec<OwnCoin>> {
|
||||
debug!(
|
||||
"Querying for coins with value {} and token_id {}",
|
||||
value,
|
||||
bs58::encode(token_id.to_repr()).into_string()
|
||||
);
|
||||
debug!("Querying for coins with value {} and token_id {}", value, token_id,);
|
||||
|
||||
let mut conn = self.conn.acquire().await?;
|
||||
let rows = match unspent {
|
||||
@@ -436,7 +430,7 @@ impl WalletDb {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_balance(&self, token_id: DrkTokenId) -> Result<Option<Balance>> {
|
||||
pub async fn get_balance(&self, token_id: TokenId) -> Result<Option<Balance>> {
|
||||
debug!("Getting balance of token ID");
|
||||
|
||||
let is_spent = 0;
|
||||
@@ -487,7 +481,7 @@ impl WalletDb {
|
||||
Ok(Balances { list })
|
||||
}
|
||||
|
||||
pub async fn get_token_id(&self) -> Result<Vec<DrkTokenId>> {
|
||||
pub async fn get_token_id(&self) -> Result<Vec<TokenId>> {
|
||||
debug!("Getting token ID");
|
||||
let is_spent = 0;
|
||||
|
||||
@@ -506,7 +500,7 @@ impl WalletDb {
|
||||
Ok(token_ids)
|
||||
}
|
||||
|
||||
pub async fn token_id_exists(&self, token_id: DrkTokenId) -> Result<bool> {
|
||||
pub async fn token_id_exists(&self, token_id: TokenId) -> Result<bool> {
|
||||
debug!("Checking if token ID exists");
|
||||
|
||||
let is_spent = 0;
|
||||
@@ -542,7 +536,7 @@ mod tests {
|
||||
|
||||
const WPASS: &str = "darkfi";
|
||||
|
||||
fn dummy_coin(s: &SecretKey, v: u64, t: &DrkTokenId) -> OwnCoin {
|
||||
fn dummy_coin(s: &SecretKey, v: u64, t: &TokenId) -> OwnCoin {
|
||||
let serial = DrkSerial::random(&mut OsRng);
|
||||
let note = Note {
|
||||
serial,
|
||||
@@ -575,7 +569,7 @@ mod tests {
|
||||
// put_keypair()
|
||||
wallet.put_keypair(&keypair).await?;
|
||||
|
||||
let token_id = DrkTokenId::random(&mut OsRng);
|
||||
let token_id = TokenId::from(pallas::Base::random(&mut OsRng));
|
||||
|
||||
let c0 = dummy_coin(&keypair.secret, 69, &token_id);
|
||||
let c1 = dummy_coin(&keypair.secret, 420, &token_id);
|
||||
|
||||
Reference in New Issue
Block a user