Implement generation of Orchard receiver #22
3 changed files with 39 additions and 2 deletions
|
@ -632,3 +632,19 @@ pub extern "C" fn rust_wrapper_derive_orchard_spending_key(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn rust_wrapper_derive_orchard_receiver(
|
||||
spend_key: *const u8,
|
||||
spend_key_len: usize,
|
||||
add_id: u32,
|
||||
out: *mut u8,
|
||||
out_len: &mut usize
|
||||
){
|
||||
let sk_in: Vec<u8> = marshall_from_haskell_var(spend_key, spend_key_len, RW);
|
||||
let sk = SpendingKey::from_bytes(sk_in[0..32].try_into().unwrap()).unwrap();
|
||||
let fvk = FullViewingKey::from(&sk);
|
||||
let o_rec = fvk.address_at(add_id, Scope::External);
|
||||
marshall_to_haskell_var(&o_rec.to_raw_address_bytes().to_vec(), out, out_len, RW);
|
||||
|
||||
}
|
||||
|
|
|
@ -142,3 +142,11 @@ import ZcashHaskell.Types
|
|||
}
|
||||
-> `()'
|
||||
#}
|
||||
|
||||
{# fun unsafe rust_wrapper_derive_orchard_receiver as rustWrapperGenOrchardReceiver
|
||||
{ toBorshVar* `BS.ByteString'&
|
||||
, `Word32'
|
||||
, getVarBuffer `Buffer (BS.ByteString)'&
|
||||
}
|
||||
-> `()'
|
||||
#}
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
module ZcashHaskell.Orchard where
|
||||
|
||||
import C.Zcash
|
||||
( rustWrapperGenOrchardSpendKey
|
||||
( rustWrapperGenOrchardReceiver
|
||||
, rustWrapperGenOrchardSpendKey
|
||||
, rustWrapperOrchardCheck
|
||||
, rustWrapperOrchardNoteDecode
|
||||
, rustWrapperUADecode
|
||||
|
@ -34,7 +35,8 @@ import ZcashHaskell.Types
|
|||
import ZcashHaskell.Utils (encodeBech32m, f4Jumble)
|
||||
|
||||
-- | Derives an Orchard spending key for the given seed and account ID
|
||||
genOrchardSpendingKey :: Seed -> CoinType -> AccountId -> Maybe BS.ByteString
|
||||
genOrchardSpendingKey ::
|
||||
Seed -> CoinType -> AccountId -> Maybe OrchardSpendingKey
|
||||
genOrchardSpendingKey s coinType accountId =
|
||||
if BS.length k /= 32
|
||||
then Nothing
|
||||
|
@ -47,6 +49,17 @@ genOrchardSpendingKey s coinType accountId =
|
|||
(getValue coinType)
|
||||
(fromIntegral accountId)
|
||||
|
||||
-- | Derives an Orchard receiver for the given spending key and index
|
||||
genOrchardReceiver :: Int -> OrchardSpendingKey -> Maybe OrchardReceiver
|
||||
genOrchardReceiver i osk =
|
||||
if BS.length k /= 43
|
||||
then Nothing
|
||||
else Just k
|
||||
where
|
||||
k =
|
||||
withPureBorshVarBuffer $
|
||||
rustWrapperGenOrchardReceiver osk (fromIntegral i)
|
||||
|
||||
-- | Checks if given bytestring is a valid encoded unified address
|
||||
isValidUnifiedAddress :: BS.ByteString -> Maybe UnifiedAddress
|
||||
isValidUnifiedAddress str =
|
||||
|
|
Loading…
Reference in a new issue