PaymentAddress::to_bytes

This commit is contained in:
Jack Grigg 2019-08-23 23:03:16 +01:00
parent 73ee19239c
commit 86142d044c
No known key found for this signature in database
GPG Key ID: 9E8255172BBF9898
3 changed files with 10 additions and 12 deletions

View File

@ -1215,14 +1215,7 @@ pub extern "system" fn librustzcash_zip32_xfvk_address(
let addr_ret = unsafe { &mut *addr_ret };
j_ret.copy_from_slice(&(addr.0).0);
addr_ret
.get_mut(..11)
.unwrap()
.copy_from_slice(&addr.1.diversifier.0);
addr.1
.pk_d
.write(addr_ret.get_mut(11..).unwrap())
.expect("should be able to serialize a PaymentAddress");
addr_ret.copy_from_slice(&addr.1.to_bytes());
true
}

View File

@ -121,10 +121,7 @@ pub fn decode_extended_full_viewing_key(
/// );
/// ```
pub fn encode_payment_address(hrp: &str, addr: &PaymentAddress<Bls12>) -> String {
bech32_encode(hrp, |w| {
w.write_all(&addr.diversifier.0)?;
addr.pk_d.write(w)
})
bech32_encode(hrp, |w| w.write_all(&addr.to_bytes()))
}
/// Decodes a [`PaymentAddress`] from a Bech32-encoded string.

View File

@ -155,6 +155,14 @@ impl<E: JubjubEngine> PaymentAddress<E> {
})
}
/// Returns the byte encoding of this `PaymentAddress`.
pub fn to_bytes(&self) -> [u8; 43] {
let mut bytes = [0; 43];
bytes[0..11].copy_from_slice(&self.diversifier.0);
self.pk_d.write(&mut bytes[11..]).unwrap();
bytes
}
pub fn g_d(&self, params: &E::Params) -> Option<edwards::Point<E, PrimeOrder>> {
self.diversifier.g_d(params)
}