Merge pull request 'Add Orchard action decryption with spendig key' (#56) from rav001 into dev040

Reviewed-on: #56
This commit is contained in:
pitmutt 2024-04-09 18:09:46 +00:00 committed by Vergara Technologies LLC
commit ea937f8e51
Signed by: Vergara Technologies LLC
GPG Key ID: 99DB473BB4715618
5 changed files with 67 additions and 1 deletions

View File

@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.5.4.0]
- Function to decode Orchard actions with a spending key
## [0.5.3.0]
### Added

View File

@ -852,6 +852,47 @@ pub extern "C" fn rust_wrapper_orchard_note_decrypt(
}
}
#[no_mangle]
pub extern "C" fn rust_wrapper_orchard_note_decrypt_sk(
key: *const u8,
key_len: usize,
note: *const u8,
note_len: usize,
external: bool,
out: *mut u8,
out_len: &mut usize
){
let sk_input: Vec<u8> = marshall_from_haskell_var(key, key_len, RW);
let note_input: Haction = marshall_from_haskell_var(note, note_len, RW);
let action: Action<Signature<SpendAuth>> = Action::from_parts(
Nullifier::from_bytes(&to_array(note_input.nf.bytes)).unwrap(),
VerificationKey::try_from(to_array(note_input.rk.bytes)).unwrap(),
ExtractedNoteCommitment::from_bytes(&to_array(note_input.cmx.bytes)).unwrap(),
TransmittedNoteCiphertext {epk_bytes: to_array(note_input.eph_key.bytes), enc_ciphertext: to_array(note_input.enc_txt.bytes), out_ciphertext: to_array(note_input.out_txt.bytes)},
ValueCommitment::from_bytes(&to_array(note_input.cv.bytes)).unwrap(),
Signature::from(to_array(note_input.auth.bytes)));
let sk_array = to_array(sk_input);
let domain = OrchardDomain::for_nullifier(*action.nullifier());
let dec_sk = SpendingKey::from_bytes(sk_array).unwrap();
let fvk = FullViewingKey::from(&dec_sk);
let ivk = if external {
fvk.to_ivk(Scope::External)
} else {
fvk.to_ivk(Scope::Internal)
};
let pivk = PreparedIncomingViewingKey::new(&ivk);
let result = zcash_note_encryption::try_note_decryption(&domain, &pivk, &action);
match result {
Some((n, r, m)) => {
let hn = Hnote {note: n.value().inner(), recipient: r.to_raw_address_bytes().to_vec(), memo: m.to_vec()};
marshall_to_haskell_var(&hn, out, out_len, RW);
}
None => {
let hn0 = Hnote { note: 0, recipient: vec![0], memo: vec![0]};
marshall_to_haskell_var(&hn0, out, out_len, RW);
}
}
}
#[no_mangle]
pub extern "C" fn rust_wrapper_tx_read(

View File

@ -126,6 +126,14 @@ import ZcashHaskell.Types
-> `()'
#}
{# fun unsafe rust_wrapper_orchard_note_decrypt_sk as rustWrapperOrchardNoteDecodeSK
{ toBorshVar* `BS.ByteString'&
, toBorshVar* `OrchardAction'&
, `Bool'
, getVarBuffer `Buffer DecodedNote'&
}
-> `()'
#}
{# fun unsafe rust_wrapper_tx_parse as rustWrapperTxParse
{ toBorshVar* `BS.ByteString'&
, getVarBuffer `Buffer [BS.ByteString]'&

View File

@ -22,6 +22,7 @@ import C.Zcash
, rustWrapperGenOrchardSpendKey
, rustWrapperOrchardCheck
, rustWrapperOrchardNoteDecode
, rustWrapperOrchardNoteDecodeSK
, rustWrapperUADecode
, rustWrapperUfvkDecode
)
@ -153,3 +154,15 @@ decryptOrchardAction key encAction =
decodedAction =
withPureBorshVarBuffer $
rustWrapperOrchardNoteDecode (o_key key) encAction
-- | Attemtps to decode the given @OrchardAction@ using the given @OrchardSpendingKey@
decryptOrchardActionSK ::
OrchardSpendingKey -> Scope -> OrchardAction -> Maybe DecodedNote
decryptOrchardActionSK sk scope oa =
case a_value decodedAction of
0 -> Nothing
_ -> Just decodedAction
where
decodedAction =
withPureBorshVarBuffer $
rustWrapperOrchardNoteDecodeSK (getBytes sk) oa (scope == External)

View File

@ -5,7 +5,7 @@ cabal-version: 3.0
-- see: https://github.com/sol/hpack
name: zcash-haskell
version: 0.5.3.0
version: 0.5.4.0
synopsis: Utilities to interact with the Zcash blockchain
description: Please see the README on the repo at <https://git.vergara.tech/Vergara_Tech/zcash-haskell#readme>
category: Blockchain