Skip to content

Commit

Permalink
Add public key to mint
Browse files Browse the repository at this point in the history
This turns the mint into a handy way to generate public keys
without throwing the private key away.
  • Loading branch information
garious committed Mar 8, 2018
1 parent e759bd1 commit d500bbf
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ use untrusted::Input;
#[derive(Serialize, Deserialize, Debug)]
pub struct Mint {
pub pkcs8: Vec<u8>,
pubkey: PublicKey,
pub tokens: i64,
}

impl Mint {
pub fn new(tokens: i64) -> Self {
let rnd = SystemRandom::new();
let pkcs8 = KeyPair::generate_pkcs8(&rnd).unwrap().to_vec();
Mint { pkcs8, tokens }
let keypair = KeyPair::from_pkcs8(Input::from(&pkcs8)).unwrap();
let pubkey = keypair.pubkey();
Mint {
pkcs8,
pubkey,
tokens,
}
}

pub fn seed(&self) -> Hash {
Expand All @@ -31,7 +38,7 @@ impl Mint {
}

pub fn pubkey(&self) -> PublicKey {
self.keypair().pubkey()
self.pubkey
}

pub fn create_events(&self) -> Vec<Event> {
Expand Down

0 comments on commit d500bbf

Please sign in to comment.