#57 - Sapling address in Human Readable format #57
5 changed files with 65 additions and 4 deletions
|
@ -5,10 +5,9 @@ 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.3.1]
|
||||
|
||||
### Added
|
||||
## [0.5.4.0]
|
||||
|
||||
- Function to decode Orchard actions with a spending key
|
||||
- Functions for Bech32 encoding
|
||||
- Function to encode a Sapling address
|
||||
|
||||
|
|
|
@ -853,6 +853,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(
|
||||
|
|
|
@ -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]'&
|
||||
|
|
|
@ -22,6 +22,7 @@ import C.Zcash
|
|||
, rustWrapperGenOrchardSpendKey
|
||||
, rustWrapperOrchardCheck
|
||||
, rustWrapperOrchardNoteDecode
|
||||
, rustWrapperOrchardNoteDecodeSK
|
||||
, rustWrapperUADecode
|
||||
, rustWrapperUfvkDecode
|
||||
)
|
||||
|
@ -171,3 +172,15 @@ getSaplingFromUA uadd = do
|
|||
TestNet ->
|
||||
Just $
|
||||
encodeBech32 (C.pack sapTestPaymentAddressHrp) (getBytes sraw)
|
||||
|
||||
-- | 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)
|
||||
|
|
|
@ -5,7 +5,7 @@ cabal-version: 3.0
|
|||
-- see: https://github.com/sol/hpack
|
||||
|
||||
name: zcash-haskell
|
||||
version: 0.5.3.1
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue