Skip to content

Commit

Permalink
feat: use PublicKey from KeyManager for genesis dbc owner
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-da authored and dirvine committed Feb 17, 2022
1 parent 289b242 commit 29dd342
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/dbc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// permissions and limitations relating to use of the SAFE Network Software.

use crate::{
DbcContent, Error, KeyManager, PublicKey, Result
DbcContent, Error, KeyManager, Result, dbc_content::OwnerPublicKey,
};

// use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -38,7 +38,7 @@ impl Dbc {
// }

/// Read the DBC owner
pub fn owner(&self) -> PublicKey {
pub fn owner(&self) -> OwnerPublicKey {
self.content.owner
}

Expand Down
16 changes: 10 additions & 6 deletions src/dbc_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
// KIND, either express or implied. Please review the Licences for the specific language governing
// permissions and limitations relating to use of the SAFE Network Software.

use blsttc::PublicKey;
// use blsttc::PublicKey;
use serde::{Deserialize, Serialize};
use blstrs::G1Affine;
use blstrs::group::GroupEncoding;
// use tiny_keccak::{Hasher, Sha3};

use crate::Hash;
Expand All @@ -16,6 +18,7 @@ use crate::Hash;
// (or else blst_ringct::RevealedCommitment should be made generic over Amount type)

pub type Amount = u64;
pub type OwnerPublicKey = G1Affine;

// const AMT_SIZE: usize = 8; // Amount size: 8 bytes (u64)
// const BF_SIZE: usize = 32; // Blinding factor size: 32 bytes (Scalar)
Expand Down Expand Up @@ -158,24 +161,25 @@ pub type Amount = u64;
// }
// }

#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub struct DbcContent {
pub owner: PublicKey,
// pub owner: PublicKey,
pub owner: OwnerPublicKey, // Todo: what should this type be?
}

/// Represents the content of a DBC.
impl From<PublicKey> for DbcContent {
impl From<OwnerPublicKey> for DbcContent {

// Create a new DbcContent for signing.
fn from(owner: PublicKey) -> Self {
fn from(owner: OwnerPublicKey) -> Self {
Self { owner }
}
}

impl DbcContent {

pub fn hash(&self) -> Hash {
Hash::hash(&self.owner.to_bytes())
Hash::hash(self.owner.to_bytes().as_ref())
}

}
19 changes: 8 additions & 11 deletions src/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::{
use blst_ringct::ringct::{RingCtMaterial, RingCtTransaction};
use blst_ringct::mlsag::{MlsagMaterial, TrueInput};
use blst_ringct::{Output, RevealedCommitment};
use blstrs::group::{ff::Field, Group, Curve};
use blstrs::group::{ff::Field, Curve};
use blstrs::{Scalar, G1Projective};
use bulletproofs::{PedersenGens};
use rand_core::OsRng;
Expand All @@ -37,11 +37,7 @@ pub type MintNodeSignatures = BTreeMap<KeyImage, (PublicKeySet, NodeSignature)>;
pub fn genesis_dbc_input() -> KeyImage {
use blsttc::group::CurveProjective;
let gen_bytes = blsttc::convert::g1_to_be_bytes(blsttc::G1::one());

gen_bytes

// fixme: unwrap
// G1Projective::from_compressed(&gen_bytes).unwrap().to_affine().
}

#[derive(Debug, Clone)]
Expand All @@ -50,7 +46,6 @@ pub struct GenesisDbcShare {
pub transaction: RingCtTransaction,
pub revealed_commitments: Vec<RevealedCommitment>,
pub public_key_set: PublicKeySet,
// pub transaction_sig: NodeSignature,
}

// replace ReissueTransaction with RingCtTransaction
Expand Down Expand Up @@ -178,13 +173,16 @@ impl<K: KeyManager> MintNode<K> {
.public_key_set()
.map_err(|e| Error::Signing(e.to_string()))?;

// let secret_key = self.key_manager.secret_key;
// converts blsttc::PublicKey to blstrs::G1Affine.
// todo: revisit blsttc/blstrs usage.
let pk_bytes = public_key_set.public_key().to_bytes();
let pk = G1Projective::from_compressed(&pk_bytes).unwrap();

// let parents = BTreeSet::from_iter([genesis_dbc_input()]);
let dbc_content = DbcContent::from(public_key_set.public_key());
let dbc_content = DbcContent::from(pk.to_affine());

let true_input = TrueInput {
secret_key: Scalar::random(&mut rng), // fixme: where to get this from?
secret_key: Scalar::random(&mut rng), // fixme: where to get this from? We only have SecretKeyShare available.
revealed_commitment: RevealedCommitment {
value: amount,
blinding: 5.into(), // todo: choose Genesis blinding factor.
Expand All @@ -200,8 +198,7 @@ impl<K: KeyManager> MintNode<K> {
&mut rng,
)],
outputs: vec![Output {
public_key: G1Projective::random(&mut rng).to_affine(),
// public_key: dbc_content.owner.into(), // Dbc owner. todo.
public_key: dbc_content.owner,
amount,
}],
};
Expand Down

0 comments on commit 29dd342

Please sign in to comment.