Add error handling to Bech32
This commit is contained in:
parent
19c9d8c466
commit
659361085c
2 changed files with 27 additions and 3 deletions
|
@ -14,7 +14,7 @@ borsh = "0.10"
|
||||||
bech32 = "0.9.1"
|
bech32 = "0.9.1"
|
||||||
orchard = "0.4.0"
|
orchard = "0.4.0"
|
||||||
zcash_note_encryption = "0.3.0"
|
zcash_note_encryption = "0.3.0"
|
||||||
zcash_primitives = "0.12.0"
|
zcash_primitives = "0.11.0"
|
||||||
zcash_client_backend = "0.9.0"
|
zcash_client_backend = "0.9.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|
|
@ -16,7 +16,10 @@ use haskell_ffi::{
|
||||||
FromHaskell, HaskellSize, ToHaskell
|
FromHaskell, HaskellSize, ToHaskell
|
||||||
};
|
};
|
||||||
|
|
||||||
use zcash_primitives::{sapling::keys::FullViewingKey as SaplingViewingKey, zip32::DiversifiableFullViewingKey};
|
use zcash_primitives:: sapling::{
|
||||||
|
keys::FullViewingKey as SaplingViewingKey,
|
||||||
|
PaymentAddress
|
||||||
|
};
|
||||||
|
|
||||||
use zcash_address::{
|
use zcash_address::{
|
||||||
Network,
|
Network,
|
||||||
|
@ -195,7 +198,6 @@ pub extern "C" fn rust_wrapper_bech32decode(
|
||||||
out_len: &mut usize
|
out_len: &mut usize
|
||||||
) {
|
) {
|
||||||
let input: String = marshall_from_haskell_var(input, input_len, RW);
|
let input: String = marshall_from_haskell_var(input, input_len, RW);
|
||||||
let (hrp, bytes, variant) = bech32::decode(&input).unwrap();
|
|
||||||
let decodedBytes = bech32::decode(&input);
|
let decodedBytes = bech32::decode(&input);
|
||||||
match decodedBytes {
|
match decodedBytes {
|
||||||
Ok((hrp, bytes, variant)) => {
|
Ok((hrp, bytes, variant)) => {
|
||||||
|
@ -227,6 +229,28 @@ pub extern "C" fn rust_wrapper_svk_decode(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn rust_wrapper_svk_check_address(
|
||||||
|
key_input: *const u8,
|
||||||
|
key_input_len: usize,
|
||||||
|
address_input: *const u8,
|
||||||
|
address_input_len: usize
|
||||||
|
) -> bool {
|
||||||
|
let key_input: Vec<u8> = marshall_from_haskell_var(key_input, key_input_len, RW);
|
||||||
|
let address_input: Vec<u8> = marshall_from_haskell_var(address_input, address_input_len, RW);
|
||||||
|
let svk = ExtendedFullViewingKey::read(&*key_input);
|
||||||
|
let sa = PaymentAddress::from_bytes(&to_array(address_input)).unwrap();
|
||||||
|
match svk {
|
||||||
|
Ok(k) => {
|
||||||
|
let (div_index, def_address) = k.default_address();
|
||||||
|
sa == def_address
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn rust_wrapper_ufvk_decode(
|
pub extern "C" fn rust_wrapper_ufvk_decode(
|
||||||
input: *const u8,
|
input: *const u8,
|
||||||
|
|
Loading…
Reference in a new issue