From d500bbff047193b162d64a1850610d91889e4f05 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Thu, 8 Mar 2018 08:32:57 -0700 Subject: [PATCH] Add public key to mint This turns the mint into a handy way to generate public keys without throwing the private key away. --- src/mint.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/mint.rs b/src/mint.rs index f357737771..5a7d297d82 100644 --- a/src/mint.rs +++ b/src/mint.rs @@ -12,6 +12,7 @@ use untrusted::Input; #[derive(Serialize, Deserialize, Debug)] pub struct Mint { pub pkcs8: Vec, + pubkey: PublicKey, pub tokens: i64, } @@ -19,7 +20,13 @@ 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 { @@ -31,7 +38,7 @@ impl Mint { } pub fn pubkey(&self) -> PublicKey { - self.keypair().pubkey() + self.pubkey } pub fn create_events(&self) -> Vec {