diff --git a/CHANGELOG.md b/CHANGELOG.md index a2fed36..bbea7b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,10 +14,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Function to generate a seed phrase - Implementations of `Read` for types - Function to make RPC calls to `zebrad` +- Function to encode unified addresses from receivers ### Changed - Update installation to `cabal` +- Updated `bech32` Rust crate to 0.11 ### Removed diff --git a/librustzcash-wrapper/Cargo.lock b/librustzcash-wrapper/Cargo.lock index a77c068..2672c97 100644 --- a/librustzcash-wrapper/Cargo.lock +++ b/librustzcash-wrapper/Cargo.lock @@ -88,6 +88,12 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" +[[package]] +name = "bech32" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" + [[package]] name = "bincode" version = "1.3.3" @@ -1282,7 +1288,7 @@ dependencies = [ name = "rustzcash-wrapper" version = "0.1.0" dependencies = [ - "bech32 0.9.1", + "bech32 0.11.0", "borsh 0.10.3", "f4jumble", "haskell-ffi", diff --git a/librustzcash-wrapper/Cargo.toml b/librustzcash-wrapper/Cargo.toml index fa4fb55..49fbb9a 100644 --- a/librustzcash-wrapper/Cargo.toml +++ b/librustzcash-wrapper/Cargo.toml @@ -10,7 +10,7 @@ haskell-ffi.rev = "2bf292e2e56eac8e9fb0fb2e1450cf4a4bd01274" f4jumble = "0.1" zcash_address = "0.2.0" borsh = "0.10" -bech32 = "0.9.1" +bech32 = "0.11" orchard = "0.4.0" zcash_note_encryption = "0.3.0" zcash_primitives = "0.11.0" diff --git a/librustzcash-wrapper/src/lib.rs b/librustzcash-wrapper/src/lib.rs index ff83321..4b9e27a 100644 --- a/librustzcash-wrapper/src/lib.rs +++ b/librustzcash-wrapper/src/lib.rs @@ -71,10 +71,8 @@ use zcash_note_encryption::EphemeralKeyBytes; use bech32::{ decode, - u5, - FromBase32, - ToBase32, - Variant + Hrp, + Bech32m }; pub enum RW {} @@ -330,8 +328,8 @@ pub extern "C" fn rust_wrapper_bech32decode( let input: String = marshall_from_haskell_var(input, input_len, RW); let decodedBytes = bech32::decode(&input); match decodedBytes { - Ok((hrp, bytes, variant)) => { - let rd = RawData {hrp: hrp.into(), bytes: Vec::::from_base32(&bytes).unwrap()}; + Ok((hrp, bytes)) => { + let rd = RawData {hrp: hrp.as_bytes().to_vec(), bytes}; marshall_to_haskell_var(&rd, out, out_len, RW); } Err(_e) => { @@ -341,6 +339,22 @@ pub extern "C" fn rust_wrapper_bech32decode( } } +#[no_mangle] +pub extern "C" fn rust_wrapper_bech32_encode( + hr: *const u8, + hr_len: usize, + b: *const u8, + b_len: usize, + out: *mut u8, + out_len: &mut usize + ) { + let hr: String = marshall_from_haskell_var(hr, hr_len, RW); + let hrp = Hrp::parse(&hr).unwrap(); + let b: Vec = marshall_from_haskell_var(b, b_len, RW); + let string = bech32::encode::(hrp, &b).unwrap(); + marshall_to_haskell_var(&string, out, out_len, RW); +} + #[no_mangle] pub extern "C" fn rust_wrapper_svk_decode( input: *const u8,