Add util func for privkey to pubkey
@@ -81,31 +81,31 @@ fn read_signing_key(private_key: &[u8]) -> PrivateKey<Engine> {
PrivateKey::<Engine>(Fs::from_repr(fs_repr).expect("couldn't read private key from repr"))
}
-#[wasm_bindgen]
-pub fn private_key_to_pubkey_hash(private_key: &[u8]) -> Vec<u8> {
+fn privkey_to_pubkey_internal(private_key: &[u8])-> PublicKey<Engine>{
let p_g = FixedGenerators::SpendingKeyGenerator;
let sk = read_signing_key(private_key);
- let pubkey = JUBJUB_PARAMS.with(|params| PublicKey::from_private(&sk, p_g, params));
- pub_key_hash(&pubkey)
+ JUBJUB_PARAMS.with(|params| PublicKey::from_private(&sk, p_g, params))
}
#[wasm_bindgen]
-pub fn private_key_to_pubkey(private_key: &[u8]) -> Vec<u8> {
- let p_g = FixedGenerators::SpendingKeyGenerator;
+pub fn private_key_to_pubkey_hash(private_key: &[u8]) -> Vec<u8> {
- let sk = read_signing_key(private_key);
+ pub_key_hash(&privkey_to_pubkey_internal(private_key))
+}
- let mut public_key_buf = Vec::with_capacity(PACKED_POINT_SIZE);
+#[wasm_bindgen]
+pub fn private_key_to_pubkey(private_key: &[u8]) -> Vec<u8> {
+ let mut pubkey_buf = Vec::with_capacity(PACKED_POINT_SIZE);
- let public_key = JUBJUB_PARAMS.with(|params| PublicKey::from_private(&sk, p_g, params));
+ let pubkey = privkey_to_pubkey_internal(private_key);
- public_key
- .write(&mut public_key_buf)
+ pubkey
+ .write(&mut pubkey_buf)
.expect("failed to write pubkey to buffer");
- public_key_buf
+ pubkey_buf
}
#[wasm_bindgen]
