Implement UA encoding #18

Merged
pitmutt merged 5 commits from rav001 into dev040 2024-03-04 18:01:39 +00:00
4 changed files with 30 additions and 8 deletions
Showing only changes of commit 3cc0e96c44 - Show all commits

View File

@ -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

View File

@ -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",

View File

@ -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"

View File

@ -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::<u8>::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<u8> = marshall_from_haskell_var(b, b_len, RW);
let string = bech32::encode::<Bech32m>(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,