Compare commits

..

No commits in common. "e98ca654093041063911d00003d9d76e6b4dd9c4" and "a56a4b1e15b0ff355dd691fb5a44d2ecd2dc960b" have entirely different histories.

6 changed files with 22 additions and 176 deletions

View file

@ -5,31 +5,6 @@ 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.5.2]
### Added
- Added unction to encode a Sappling Address in Human Readable Format Using a SaplingReceiver
`encodeSaplingAddress` a zcash sapling address is returned or Nothing if the function fails
- Added decoding and encoding test
## [0.5.5.1]
### Added
- Added unction to decode a Sappling Address in Human Readable Format
`decodeSaplingAddress` returns 43 byte array containing
- Added a new Datatype `SaplingAddress`
- Added a new FFI function `rust_wrapper_decode_sapling_address` to haskell-rust interface
### Changed
- `TransparentAddress` type refactored
- `TransparentReceiver` added to replace old `TransparentAddress`
- `sha256` Function moved outside of `encodeTransparentReceiver`
## [0.5.5.0]
### Added
@ -41,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `TransparentAddress` type refactored
- `TransparentReceiver` added to replace old `TransparentAddress`
- `sha256` Function moved outside of `encodeTransparentReceiver`
## [0.5.4.1]
### Added

View file

@ -90,7 +90,6 @@ use zcash_address::{
ZcashAddress
};
use zcash_client_backend::encoding::decode_payment_address;
use zcash_client_backend::keys::sapling::{
spending_key,
ExtendedFullViewingKey,
@ -1347,48 +1346,3 @@ pub extern "C" fn rust_wrapper_read_orchard_position(
}
}
}
pub extern "C" fn rust_wrapper_decode_sapling_address(
sapling: *const u8,
sapling_len: usize,
out: *mut u8,
out_len: &mut usize){
let sapling_address_from_haskell : Vec<u8> = marshall_from_haskell_var(sapling, sapling_len, RW);
let sapling_address = std::str::from_utf8(&sapling_address_from_haskell).unwrap();
let mut netid = 0;
match sapling_address.find("1") {
Some(ix) => {
let netstr = &sapling_address[0..ix];
if netstr == "zs" {
netid = 1
} else {
if netstr == "ztestsapling" {
netid = 2
}
}
match decode_payment_address(netstr, sapling_address) {
Ok( t )=> {
let address_to_bytes = t.to_bytes();
let mut out_bytes_temp : [u8;44] = [0;44];
out_bytes_temp[0] = netid;
let mut iy = 1;
for ix in 0..43 {
out_bytes_temp[iy] = address_to_bytes[ix];
iy += 1;
}
let out_bytes: Vec<u8> = out_bytes_temp.to_vec();
marshall_to_haskell_var(&out_bytes, out, out_len, RW);
}
Err(e) => {
let h = vec![0];
marshall_to_haskell_var(&h, out, out_len, RW);
}
}
}
None => {
let h = vec![0];
marshall_to_haskell_var(&h, out, out_len, RW);
}
}
}

View file

@ -232,13 +232,6 @@ import ZcashHaskell.Types
-> `()'
#}
{# fun unsafe rust_wrapper_decode_sapling_address as rustWrapperDecodeSaplingAddress
{ toBorshVar* `BS.ByteString'&
, getVarBuffer `Buffer (BS.ByteString)'&
}
-> `()'
#}
{# fun unsafe rust_wrapper_read_orchard_commitment_tree as rustWrapperReadOrchardCommitmentTree
{ toBorshVar* `BS.ByteString'&
, toBorshVar* `BS.ByteString'&
@ -259,3 +252,4 @@ import ZcashHaskell.Types
}
-> `Word64'
#}

View file

@ -22,7 +22,6 @@ import C.Zcash
, rustWrapperReadSaplingCommitmentTree
, rustWrapperReadSaplingPosition
, rustWrapperReadSaplingWitness
, rustWrapperDecodeSaplingAddress
, rustWrapperSaplingCheck
, rustWrapperSaplingChgPaymentAddress
, rustWrapperSaplingDecodeEsk
@ -34,8 +33,6 @@ import C.Zcash
)
import Data.Aeson
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as C
import qualified Data.Text as T
import Data.HexString (HexString(..), fromText, hexString, toBytes, toText)
import Data.Word
import Foreign.Rust.Marshall.Variable
@ -43,26 +40,24 @@ import Foreign.Rust.Marshall.Variable
, withPureBorshVarBuffer
)
import ZcashHaskell.Types
--import ZcashHaskell.Types
-- ( AccountId
-- , CoinType
-- , DecodedNote(..)
-- , RawData(..)
-- , RawTxResponse(..)
-- , SaplingAddress(..)
-- , SaplingCommitmentTree(..)
-- , SaplingReceiver(..)
-- , SaplingSpendingKey(..)
-- , SaplingWitness(..)
-- , Scope(..)
-- , Seed(..)
-- , ShieldedOutput(..)
-- , ToBytes(..)
-- , ZcashNet(..)
-- , decodeHexText
-- , getValue
-- )
import ZcashHaskell.Utils (decodeBech32, encodeBech32, encodeBech32m)
( AccountId
, CoinType
, DecodedNote(..)
, RawData(..)
, RawTxResponse(..)
, SaplingCommitmentTree(..)
, SaplingReceiver(..)
, SaplingSpendingKey(..)
, SaplingWitness(..)
, Scope(..)
, Seed(..)
, ShieldedOutput(..)
, ToBytes(..)
, ZcashNet(..)
, decodeHexText
, getValue
)
import ZcashHaskell.Utils (decodeBech32)
-- | Check if given bytesting is a valid encoded shielded address
isValidShieldedAddress :: BS.ByteString -> Bool
@ -210,33 +205,3 @@ getSaplingWitness tree =
getSaplingNotePosition :: SaplingWitness -> Integer
getSaplingNotePosition =
fromIntegral . rustWrapperReadSaplingPosition . hexBytes . sapWit
-- | Encode a SaplingReceiver into HRF text
encodeSaplingAddress :: ZcashNet -> SaplingReceiver -> Maybe T.Text
encodeSaplingAddress net sr = do
case net of
MainNet ->
Just $ encodeBech32 (C.pack sapPaymentAddressHrp) (getBytes sr)
TestNet ->
Just $ encodeBech32 (C.pack sapTestPaymentAddressHrp) (getBytes sr)
-- | Helper to get de Nework Id from FFI response
getNetId:: [Word8] -> ZcashNet
getNetId [x] = do
case x of
1 -> MainNet
2 -> TestNet
-- | decode a Sapling address
decodeSaplingAddress :: BS.ByteString -> Maybe SaplingAddress
decodeSaplingAddress sapling_address = do
if BS.length sa > 1
then do
let sa0 = BS.unpack sa
Just $ SaplingAddress (getNetId (take 1 sa0))
$ SaplingReceiver (BS.pack (drop 1 sa0))
else Nothing
where
sa =
withPureBorshVarBuffer $
rustWrapperDecodeSaplingAddress sapling_address

View file

@ -477,12 +477,6 @@ newtype SaplingReceiver =
instance ToBytes SaplingReceiver where
getBytes (SaplingReceiver s) = s
data SaplingAddress = SaplingAddress
{
net_type :: !ZcashNet
, sa_receiver :: !SaplingReceiver
} deriving (Eq, Prelude.Show, Read)
-- | Type to represent a Sapling Shielded Spend as provided by the @getrawtransaction@ RPC method
data ShieldedSpend = ShieldedSpend
{ sp_cv :: !HexString

View file

@ -46,10 +46,8 @@ import Test.QuickCheck
import ZcashHaskell.Keys (generateWalletSeedPhrase, getWalletSeed)
import ZcashHaskell.Orchard
import ZcashHaskell.Sapling
( decodeSaplingAddress
, decodeSaplingOutput
( decodeSaplingOutput
, decodeSaplingOutputEsk
, encodeSaplingAddress
, genSaplingInternalAddress
, genSaplingPaymentAddress
, genSaplingSpendingKey
@ -79,7 +77,6 @@ import ZcashHaskell.Types
, RawTxOut(..)
, RawTxResponse(..)
, RawZebraTx(..)
, SaplingAddress(..)
, SaplingBundle(..)
, SaplingCommitmentTree(..)
, SaplingReceiver(..)
@ -939,40 +936,6 @@ main = do
t_rec u
(ta_receiver <$> decodeTransparentAddress (E.encodeUtf8 tAdd)) `shouldBe`
t_rec u
describe "Decode a Sapling Address (MainNet)" $ do
let sa =
decodeSaplingAddress
"zs1waxrpde36rlrjdwfhnvw030sn29lzwmvmeupd8x2uuqgypaafx7mqcy0ep8yf2xtg30n5424t60"
it "Try to decode a valid MainNet Sapling Address" $ do
case sa of
Nothing -> assertFailure "Failed to decode MainNet SaplingAddress"
Just s -- Sapling address decoded succesfully
-> do
let sh = encodeSaplingAddress (net_type s) (sa_receiver s)
case sh of
Nothing ->
assertFailure "Failed to encode MainNet SaplingAddress"
Just zsh -> do
print zsh
zsh `shouldBe`
"zs1waxrpde36rlrjdwfhnvw030sn29lzwmvmeupd8x2uuqgypaafx7mqcy0ep8yf2xtg30n5424t60"
describe "Decode a Sapling Address (TestNet)" $ do
let sa =
decodeSaplingAddress
"ztestsapling188csdsvhdny25am8ume03qr2026hdy03zpg5pq7jmmfxtxtct0e93p0rg80yfxvynqd4gwlwft5"
it "Try to decode a valid TestNet Sapling Address " $ do
case sa of
Nothing -> assertFailure "Failed to decode TestNet SaplingAddress"
Just s -- Sapling address decoded succesfully
-> do
let sh = encodeSaplingAddress (net_type s) (sa_receiver s)
case sh of
Nothing ->
assertFailure "Failed to encode TestNet SaplingAddress"
Just zsh -> do
print zsh
zsh `shouldBe`
"ztestsapling188csdsvhdny25am8ume03qr2026hdy03zpg5pq7jmmfxtxtct0e93p0rg80yfxvynqd4gwlwft5"
describe "Decode Sapling Output with spending key" $ do
let p =
Phrase