darkfi_money_contract/client/
token_mint_v1.rsuse darkfi::{
zk::{halo2::Value, Proof, ProvingKey, Witness, ZkCircuit},
zkas::ZkBinary,
Result,
};
use darkfi_sdk::pasta::pallas;
use log::debug;
use rand::rngs::OsRng;
use crate::model::{CoinAttributes, MoneyTokenMintParamsV1, TokenAttributes};
pub struct TokenMintCallDebris {
pub params: MoneyTokenMintParamsV1,
pub proofs: Vec<Proof>,
}
pub struct TokenMintCallBuilder {
pub coin_attrs: CoinAttributes,
pub token_attrs: TokenAttributes,
pub mint_zkbin: ZkBinary,
pub mint_pk: ProvingKey,
}
impl TokenMintCallBuilder {
pub fn build(&self) -> Result<TokenMintCallDebris> {
debug!(target: "contract::money::client::token_mint", "Building Money::TokenMintV1 contract call");
let (public_x, public_y) = self.coin_attrs.public_key.xy();
let prover_witnesses = vec![
Witness::Base(Value::known(public_x)),
Witness::Base(Value::known(public_y)),
Witness::Base(Value::known(pallas::Base::from(self.coin_attrs.value))),
Witness::Base(Value::known(self.coin_attrs.spend_hook.inner())),
Witness::Base(Value::known(self.coin_attrs.user_data)),
Witness::Base(Value::known(self.coin_attrs.blind.inner())),
Witness::Base(Value::known(self.token_attrs.auth_parent.inner())),
Witness::Base(Value::known(self.token_attrs.user_data)),
Witness::Base(Value::known(self.token_attrs.blind.inner())),
];
let coin = self.coin_attrs.to_coin();
let public_inputs = vec![self.token_attrs.auth_parent.inner(), coin.inner()];
let circuit = ZkCircuit::new(prover_witnesses, &self.mint_zkbin);
let proof = Proof::create(&self.mint_pk, &[circuit], &public_inputs, &mut OsRng)?;
let params = MoneyTokenMintParamsV1 { coin };
let debris = TokenMintCallDebris { params, proofs: vec![proof] };
Ok(debris)
}
}