Compare commits
No commits in common. "f0995441628381fee14ae1c655c3c4f8d96162e5" and "0a98246855c13ba13605453a9c21283aecb56e64" have entirely different histories.
f099544162
...
0a98246855
11 changed files with 411 additions and 484 deletions
13
CHANGELOG.md
13
CHANGELOG.md
|
@ -5,18 +5,8 @@ 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/),
|
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).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [0.5.1.0]
|
|
||||||
|
|
||||||
### Added
|
## [Unreleased]
|
||||||
|
|
||||||
- Functionality to capture Sapling Spends
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
- Modified the `makeZebraCall` function to handle errors explicitly
|
|
||||||
- Modified the RPC response to handle missing `result` field
|
|
||||||
|
|
||||||
## [0.5.0.1]
|
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
@ -30,7 +20,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- Types for Spending Keys and Receivers for Sapling and Orchard
|
- Types for Spending Keys and Receivers for Sapling and Orchard
|
||||||
- Function to generate an Orchard receiver
|
- Function to generate an Orchard receiver
|
||||||
- Function to generate a Sapling receiver
|
- Function to generate a Sapling receiver
|
||||||
- Function to generate a Transparent receiver
|
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|
|
@ -684,19 +684,26 @@ pub extern "C" fn rust_wrapper_sapling_chgpaymentaddress(
|
||||||
out: *mut u8,
|
out: *mut u8,
|
||||||
out_len: &mut usize
|
out_len: &mut usize
|
||||||
){
|
){
|
||||||
|
println!("Entering ChangeAddress generation....");
|
||||||
let vexspk: Vec<u8> = marshall_from_haskell_var(extspk, extspk_len, RW);
|
let vexspk: Vec<u8> = marshall_from_haskell_var(extspk, extspk_len, RW);
|
||||||
let vexspkp = &vexspk;
|
let vexspkp = &vexspk;
|
||||||
let extspku8 : &[u8] = &vexspkp;
|
let extspku8 : &[u8] = &vexspkp;
|
||||||
|
println!("Received ExtendedSpendingKey in Bytes...\n{:?}\n",extspku8);
|
||||||
let extspk = match ExtendedSpendingKey::from_bytes(&extspku8) {
|
let extspk = match ExtendedSpendingKey::from_bytes(&extspku8) {
|
||||||
Ok( k ) => k,
|
Ok( k ) => k,
|
||||||
Err( e ) => {
|
Err( e ) => {
|
||||||
// error recovering ExtendedSpendingKey
|
// error recovering ExtendedSpendingKey
|
||||||
|
println!("\n>>>> Error generating ExtendedSpendingKey");
|
||||||
marshall_to_haskell_var(&vec![0], out, out_len, RW);
|
marshall_to_haskell_var(&vec![0], out, out_len, RW);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
println!("ExtendedSpendingKey -> {:?}",extspk);
|
||||||
let dfvk = extspk.to_diversifiable_full_viewing_key();
|
let dfvk = extspk.to_diversifiable_full_viewing_key();
|
||||||
let ( divIx, cPmtAddress ) = dfvk.change_address();
|
let ( divIx, cPmtAddress ) = dfvk.change_address();
|
||||||
|
println!("\nDiversifierIndex > {:?}\n\nChange Payment Address -> {:?}\n ",
|
||||||
|
divIx, cPmtAddress);
|
||||||
|
println!("Change Payment Address in bytes : \n{:?}",cPmtAddress.to_bytes());
|
||||||
marshall_to_haskell_var(&cPmtAddress.to_bytes().to_vec(), out, out_len, RW);
|
marshall_to_haskell_var(&cPmtAddress.to_bytes().to_vec(), out, out_len, RW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -726,17 +733,13 @@ pub extern "C" fn rust_wrapper_derive_orchard_receiver(
|
||||||
spend_key: *const u8,
|
spend_key: *const u8,
|
||||||
spend_key_len: usize,
|
spend_key_len: usize,
|
||||||
add_id: u32,
|
add_id: u32,
|
||||||
scope: bool,
|
|
||||||
out: *mut u8,
|
out: *mut u8,
|
||||||
out_len: &mut usize
|
out_len: &mut usize
|
||||||
){
|
){
|
||||||
let sk_in: Vec<u8> = marshall_from_haskell_var(spend_key, spend_key_len, RW);
|
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 sk = SpendingKey::from_bytes(sk_in[0..32].try_into().unwrap()).unwrap();
|
||||||
let fvk = FullViewingKey::from(&sk);
|
let fvk = FullViewingKey::from(&sk);
|
||||||
let sc = if scope {
|
let o_rec = fvk.address_at(add_id, Scope::External);
|
||||||
Scope::External
|
|
||||||
} else {Scope::Internal};
|
|
||||||
let o_rec = fvk.address_at(add_id, sc);
|
|
||||||
marshall_to_haskell_var(&o_rec.to_raw_address_bytes().to_vec(), out, out_len, RW);
|
marshall_to_haskell_var(&o_rec.to_raw_address_bytes().to_vec(), out, out_len, RW);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,7 +170,6 @@ import ZcashHaskell.Types
|
||||||
{# fun unsafe rust_wrapper_derive_orchard_receiver as rustWrapperGenOrchardReceiver
|
{# fun unsafe rust_wrapper_derive_orchard_receiver as rustWrapperGenOrchardReceiver
|
||||||
{ toBorshVar* `BS.ByteString'&
|
{ toBorshVar* `BS.ByteString'&
|
||||||
, `Word32'
|
, `Word32'
|
||||||
, `Bool'
|
|
||||||
, getVarBuffer `Buffer (BS.ByteString)'&
|
, getVarBuffer `Buffer (BS.ByteString)'&
|
||||||
}
|
}
|
||||||
-> `()'
|
-> `()'
|
||||||
|
|
|
@ -21,7 +21,7 @@ import Foreign.Rust.Marshall.Variable
|
||||||
( withBorshVarBuffer
|
( withBorshVarBuffer
|
||||||
, withPureBorshVarBuffer
|
, withPureBorshVarBuffer
|
||||||
)
|
)
|
||||||
import ZcashHaskell.Types (Phrase, Seed(..), ToBytes(..))
|
import ZcashHaskell.Types (Phrase, Seed)
|
||||||
|
|
||||||
-- | Generate a random seed that can be used to generate private keys for shielded addresses and transparent addresses.
|
-- | Generate a random seed that can be used to generate private keys for shielded addresses and transparent addresses.
|
||||||
generateWalletSeedPhrase :: IO Phrase
|
generateWalletSeedPhrase :: IO Phrase
|
||||||
|
@ -30,7 +30,7 @@ generateWalletSeedPhrase = withBorshVarBuffer rustWrapperGenSeedPhrase
|
||||||
-- | Derive a cryptographic seed from the given seed phrase.
|
-- | Derive a cryptographic seed from the given seed phrase.
|
||||||
getWalletSeed :: Phrase -> Maybe Seed
|
getWalletSeed :: Phrase -> Maybe Seed
|
||||||
getWalletSeed p =
|
getWalletSeed p =
|
||||||
if BS.length (getBytes result) > 0
|
if BS.length result > 0
|
||||||
then Just result
|
then Just result
|
||||||
else Nothing
|
else Nothing
|
||||||
where
|
where
|
||||||
|
|
|
@ -37,39 +37,29 @@ import ZcashHaskell.Utils (encodeBech32m, f4Jumble)
|
||||||
|
|
||||||
-- | Derives an Orchard spending key for the given seed and account ID
|
-- | Derives an Orchard spending key for the given seed and account ID
|
||||||
genOrchardSpendingKey ::
|
genOrchardSpendingKey ::
|
||||||
Seed -- ^ The cryptographic seed for the wallet
|
Seed -> CoinType -> AccountId -> Maybe OrchardSpendingKey
|
||||||
-> CoinType -- ^ The coin type constant
|
|
||||||
-> AccountId -- ^ The index of the account to be used
|
|
||||||
-> Maybe OrchardSpendingKey
|
|
||||||
genOrchardSpendingKey s coinType accountId =
|
genOrchardSpendingKey s coinType accountId =
|
||||||
if BS.length k /= 32
|
if BS.length k /= 32
|
||||||
then Nothing
|
then Nothing
|
||||||
else Just $ OrchardSpendingKey k
|
else Just k
|
||||||
where
|
where
|
||||||
k =
|
k =
|
||||||
withPureBorshVarBuffer $
|
withPureBorshVarBuffer $
|
||||||
rustWrapperGenOrchardSpendKey
|
rustWrapperGenOrchardSpendKey
|
||||||
(getBytes s)
|
s
|
||||||
(getValue coinType)
|
(getValue coinType)
|
||||||
(fromIntegral accountId)
|
(fromIntegral accountId)
|
||||||
|
|
||||||
-- | Derives an Orchard receiver for the given spending key and index
|
-- | Derives an Orchard receiver for the given spending key and index
|
||||||
genOrchardReceiver ::
|
genOrchardReceiver :: Int -> OrchardSpendingKey -> Maybe OrchardReceiver
|
||||||
Int -- ^ The index of the address to be created
|
genOrchardReceiver i osk =
|
||||||
-> Scope -- ^ `External` for wallet addresses, `Internal` for change addresses
|
|
||||||
-> OrchardSpendingKey -- ^ The spending key
|
|
||||||
-> Maybe OrchardReceiver
|
|
||||||
genOrchardReceiver i scope osk =
|
|
||||||
if BS.length k /= 43
|
if BS.length k /= 43
|
||||||
then Nothing
|
then Nothing
|
||||||
else Just $ OrchardReceiver k
|
else Just k
|
||||||
where
|
where
|
||||||
k =
|
k =
|
||||||
withPureBorshVarBuffer $
|
withPureBorshVarBuffer $
|
||||||
rustWrapperGenOrchardReceiver
|
rustWrapperGenOrchardReceiver osk (fromIntegral i)
|
||||||
(getBytes osk)
|
|
||||||
(fromIntegral i)
|
|
||||||
(scope == External)
|
|
||||||
|
|
||||||
-- | Checks if given bytestring is a valid encoded unified address
|
-- | Checks if given bytestring is a valid encoded unified address
|
||||||
isValidUnifiedAddress :: BS.ByteString -> Maybe UnifiedAddress
|
isValidUnifiedAddress :: BS.ByteString -> Maybe UnifiedAddress
|
||||||
|
@ -88,10 +78,10 @@ isValidUnifiedAddress str =
|
||||||
UnifiedAddress
|
UnifiedAddress
|
||||||
whichNet
|
whichNet
|
||||||
(if BS.length (raw_o x) == 43
|
(if BS.length (raw_o x) == 43
|
||||||
then Just $ OrchardReceiver (raw_o x)
|
then Just (raw_o x)
|
||||||
else Nothing)
|
else Nothing)
|
||||||
(if BS.length (raw_s x) == 43
|
(if BS.length (raw_s x) == 43
|
||||||
then Just $ SaplingReceiver (raw_s x)
|
then Just (raw_s x)
|
||||||
else Nothing)
|
else Nothing)
|
||||||
(if not (BS.null (raw_t x))
|
(if not (BS.null (raw_t x))
|
||||||
then Just $ TransparentAddress P2PKH (fromRawBytes $ raw_t x)
|
then Just $ TransparentAddress P2PKH (fromRawBytes $ raw_t x)
|
||||||
|
@ -115,8 +105,8 @@ encodeUnifiedAddress ua = encodeBech32m (E.encodeUtf8 hr) b
|
||||||
case ta_type t of
|
case ta_type t of
|
||||||
P2SH -> packReceiver 0x01 $ Just $ toBytes $ ta_bytes t
|
P2SH -> packReceiver 0x01 $ Just $ toBytes $ ta_bytes t
|
||||||
P2PKH -> packReceiver 0x00 $ Just $ toBytes $ ta_bytes t
|
P2PKH -> packReceiver 0x00 $ Just $ toBytes $ ta_bytes t
|
||||||
sReceiver = packReceiver 0x02 $ getBytes <$> s_rec ua
|
sReceiver = packReceiver 0x02 $ s_rec ua
|
||||||
oReceiver = packReceiver 0x03 $ getBytes <$> o_rec ua
|
oReceiver = packReceiver 0x03 $ o_rec ua
|
||||||
padding = E.encodeUtf8 $ T.justifyLeft 16 '\NUL' hr
|
padding = E.encodeUtf8 $ T.justifyLeft 16 '\NUL' hr
|
||||||
packReceiver :: Word8 -> Maybe BS.ByteString -> BS.ByteString
|
packReceiver :: Word8 -> Maybe BS.ByteString -> BS.ByteString
|
||||||
packReceiver typeCode receiver' =
|
packReceiver typeCode receiver' =
|
||||||
|
|
|
@ -20,9 +20,9 @@ module ZcashHaskell.Sapling where
|
||||||
import C.Zcash
|
import C.Zcash
|
||||||
( rustWrapperIsShielded
|
( rustWrapperIsShielded
|
||||||
, rustWrapperSaplingCheck
|
, rustWrapperSaplingCheck
|
||||||
, rustWrapperSaplingChgPaymentAddress
|
|
||||||
, rustWrapperSaplingNoteDecode
|
, rustWrapperSaplingNoteDecode
|
||||||
, rustWrapperSaplingPaymentAddress
|
, rustWrapperSaplingPaymentAddress
|
||||||
|
, rustWrapperSaplingChgPaymentAddress
|
||||||
, rustWrapperSaplingSpendingkey
|
, rustWrapperSaplingSpendingkey
|
||||||
, rustWrapperSaplingVkDecode
|
, rustWrapperSaplingVkDecode
|
||||||
, rustWrapperTxParse
|
, rustWrapperTxParse
|
||||||
|
@ -41,11 +41,11 @@ import ZcashHaskell.Types
|
||||||
, DecodedNote(..)
|
, DecodedNote(..)
|
||||||
, RawData(..)
|
, RawData(..)
|
||||||
, RawTxResponse(..)
|
, RawTxResponse(..)
|
||||||
, SaplingReceiver(..)
|
, SaplingInternalReceiver
|
||||||
|
, SaplingReceiver
|
||||||
, SaplingSpendingKey(..)
|
, SaplingSpendingKey(..)
|
||||||
, Seed(..)
|
, Seed(..)
|
||||||
, ShieldedOutput(..)
|
, ShieldedOutput(..)
|
||||||
, ToBytes(..)
|
|
||||||
, decodeHexText
|
, decodeHexText
|
||||||
, getValue
|
, getValue
|
||||||
)
|
)
|
||||||
|
@ -90,25 +90,23 @@ instance FromJSON RawTxResponse where
|
||||||
ht <- obj .: "height"
|
ht <- obj .: "height"
|
||||||
c <- obj .: "confirmations"
|
c <- obj .: "confirmations"
|
||||||
b <- obj .: "blocktime"
|
b <- obj .: "blocktime"
|
||||||
sSpend <- obj .: "vShieldedSpend"
|
|
||||||
case o of
|
case o of
|
||||||
Nothing ->
|
Nothing -> pure $ RawTxResponse i h (getShieldedOutputs h) [] ht c b
|
||||||
pure $ RawTxResponse i h sSpend (getShieldedOutputs h) [] ht c b
|
|
||||||
Just o' -> do
|
Just o' -> do
|
||||||
a <- o' .: "actions"
|
a <- o' .: "actions"
|
||||||
pure $ RawTxResponse i h sSpend (getShieldedOutputs h) a ht c b
|
pure $ RawTxResponse i h (getShieldedOutputs h) a ht c b
|
||||||
|
|
||||||
-- | Attempts to obtain a sapling SpendingKey using a HDSeed
|
-- | Attempts to obtain a sapling SpendingKey using a HDSeed
|
||||||
genSaplingSpendingKey :: Seed -> CoinType -> Int -> Maybe SaplingSpendingKey
|
genSaplingSpendingKey :: Seed -> CoinType -> Int -> Maybe SaplingSpendingKey
|
||||||
genSaplingSpendingKey seed c i = do
|
genSaplingSpendingKey seed c i = do
|
||||||
if BS.length res == 169
|
if BS.length res == 169
|
||||||
then Just $ SaplingSpendingKey res
|
then Just res
|
||||||
else Nothing
|
else Nothing
|
||||||
where
|
where
|
||||||
res =
|
res =
|
||||||
withPureBorshVarBuffer
|
withPureBorshVarBuffer
|
||||||
(rustWrapperSaplingSpendingkey
|
(rustWrapperSaplingSpendingkey
|
||||||
(getBytes seed)
|
seed
|
||||||
(fromIntegral $ getValue c)
|
(fromIntegral $ getValue c)
|
||||||
(fromIntegral i))
|
(fromIntegral i))
|
||||||
|
|
||||||
|
@ -116,21 +114,20 @@ genSaplingSpendingKey seed c i = do
|
||||||
genSaplingPaymentAddress :: Int -> SaplingSpendingKey -> Maybe SaplingReceiver
|
genSaplingPaymentAddress :: Int -> SaplingSpendingKey -> Maybe SaplingReceiver
|
||||||
genSaplingPaymentAddress i extspk =
|
genSaplingPaymentAddress i extspk =
|
||||||
if BS.length res == 43
|
if BS.length res == 43
|
||||||
then Just $ SaplingReceiver res
|
then Just res
|
||||||
else Nothing
|
else Nothing
|
||||||
where
|
where
|
||||||
res =
|
res =
|
||||||
withPureBorshVarBuffer
|
withPureBorshVarBuffer
|
||||||
(rustWrapperSaplingPaymentAddress
|
(rustWrapperSaplingPaymentAddress extspk (fromIntegral (i * 111)))
|
||||||
(getBytes extspk)
|
|
||||||
(fromIntegral (i * 111)))
|
|
||||||
|
|
||||||
-- | Generate an internal Sapling address
|
-- | Generate an internal Sapling address
|
||||||
genSaplingInternalAddress :: SaplingSpendingKey -> Maybe SaplingReceiver
|
genSaplingInternalAddress :: SaplingSpendingKey -> Maybe SaplingInternalReceiver
|
||||||
genSaplingInternalAddress sk =
|
genSaplingInternalAddress sk =
|
||||||
if BS.length res == 43
|
if (BS.length res) > 0
|
||||||
then Just $ SaplingReceiver res
|
then Just res
|
||||||
else Nothing
|
else Nothing
|
||||||
where
|
where
|
||||||
res =
|
res =
|
||||||
withPureBorshVarBuffer (rustWrapperSaplingChgPaymentAddress $ getBytes sk)
|
withPureBorshVarBuffer (rustWrapperSaplingChgPaymentAddress sk)
|
||||||
|
|
|
@ -17,36 +17,30 @@ module ZcashHaskell.Transparent where
|
||||||
|
|
||||||
import Control.Exception (throwIO)
|
import Control.Exception (throwIO)
|
||||||
import Crypto.Hash
|
import Crypto.Hash
|
||||||
import Crypto.Secp256k1
|
|
||||||
import qualified Data.ByteArray as BA
|
import qualified Data.ByteArray as BA
|
||||||
import qualified Data.ByteString as BS
|
import qualified Data.ByteString as BS
|
||||||
import Data.ByteString.Base58 (bitcoinAlphabet, encodeBase58)
|
import Data.ByteString.Base58 (bitcoinAlphabet, encodeBase58)
|
||||||
import Data.HexString
|
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Data.Text.Encoding as E
|
import qualified Data.Text.Encoding as E
|
||||||
import Data.Word
|
|
||||||
import Haskoin.Address (Address(..))
|
|
||||||
import qualified Haskoin.Crypto.Hash as H
|
|
||||||
import Haskoin.Crypto.Keys.Extended
|
|
||||||
import ZcashHaskell.Types
|
import ZcashHaskell.Types
|
||||||
( AccountId
|
( AccountId
|
||||||
, CoinType(..)
|
, Seed
|
||||||
, Scope(..)
|
|
||||||
, Seed(..)
|
|
||||||
, ToBytes(..)
|
|
||||||
, TransparentAddress(..)
|
, TransparentAddress(..)
|
||||||
, TransparentSpendingKey(..)
|
|
||||||
, TransparentType(..)
|
, TransparentType(..)
|
||||||
, ZcashNet(..)
|
, ZcashNet(..)
|
||||||
|
, CoinType(..)
|
||||||
, getTransparentPrefix
|
, getTransparentPrefix
|
||||||
, getValue
|
, getValue
|
||||||
)
|
)
|
||||||
|
|
||||||
-- | Encodes a `TransparentAddress` into the human-readable format per the Zcash Protocol section 5.6.1.1
|
import Crypto.Secp256k1
|
||||||
encodeTransparent ::
|
import Haskoin.Crypto.Keys.Extended
|
||||||
ZcashNet -- ^ The network, `MainNet` or `TestNet`
|
import Data.HexString
|
||||||
-> TransparentAddress -- ^ The address to encode
|
import Data.Word
|
||||||
-> T.Text
|
import Haskoin.Address (Address(..))
|
||||||
|
import qualified Haskoin.Crypto.Hash as H
|
||||||
|
|
||||||
|
encodeTransparent :: ZcashNet -> TransparentAddress -> T.Text
|
||||||
encodeTransparent zNet t =
|
encodeTransparent zNet t =
|
||||||
encodeTransparent' (getTransparentPrefix zNet (ta_type t)) $
|
encodeTransparent' (getTransparentPrefix zNet (ta_type t)) $
|
||||||
toBytes $ ta_bytes t
|
toBytes $ ta_bytes t
|
||||||
|
@ -60,34 +54,31 @@ encodeTransparent zNet t =
|
||||||
digest = BS.pack [a, b] <> h
|
digest = BS.pack [a, b] <> h
|
||||||
checksum = sha256 $ sha256 digest
|
checksum = sha256 $ sha256 digest
|
||||||
|
|
||||||
-- | Generate an Extended Private Key from a known HDSeed.
|
-- | Attempts to generate an Extended Private Key from a known HDSeed.
|
||||||
genTransparentPrvKey ::
|
genTransparentPrvKey :: Seed -> CoinType -> AccountId -> IO XPrvKey
|
||||||
Seed -- ^ The cryptographic seed of the wallet
|
|
||||||
-> CoinType -- ^ The coin type constant to be used
|
|
||||||
-> AccountId -- ^ The index of the account to be used
|
|
||||||
-> IO TransparentSpendingKey
|
|
||||||
genTransparentPrvKey hdseed ctype accid = do
|
genTransparentPrvKey hdseed ctype accid = do
|
||||||
let coin = getValue ctype
|
let coin = getValue ctype
|
||||||
ioCtx <- createContext
|
ioCtx <- createContext
|
||||||
let path = Deriv :| 44 :| coin :| fromIntegral accid :: DerivPath
|
let path = Deriv :| 44 :| coin :| AccounId :/ 0 :/ 0 :: DerivPath
|
||||||
let prvKey = makeXPrvKey $ getBytes hdseed
|
let prvKey = makeXPrvKey hdseed
|
||||||
return $ derivePath ioCtx path prvKey
|
return $ derivePath ioCtx path prvKey
|
||||||
|
|
||||||
-- | Generate a transparent receiver
|
genTransparentPubKey :: XPrvKey -> IO XPubKey
|
||||||
genTransparentReceiver ::
|
genTransparentPubKey xPrvKey = do
|
||||||
Int -- ^ The index of the address to be created
|
|
||||||
-> Scope -- ^ `External` for wallet addresses or `Internal` for change addresses
|
|
||||||
-> XPrvKey -- ^ The transparent private key
|
|
||||||
-> IO TransparentAddress
|
|
||||||
genTransparentReceiver i scope xprvk = do
|
|
||||||
ioCtx <- createContext
|
ioCtx <- createContext
|
||||||
let s =
|
return $ deriveXPubKey ioCtx xPrvKey
|
||||||
case scope of
|
|
||||||
External -> 0
|
genTransparentPubAddress :: XPubKey -> IO Address
|
||||||
Internal -> 1
|
genTransparentPubAddress xPubKey = do
|
||||||
let path = Deriv :/ s :/ fromIntegral i :: DerivPath
|
ioCtx <- createContext
|
||||||
let childPrvKey = derivePath ioCtx path xprvk
|
return $ xPubAddr ioCtx xPubKey
|
||||||
let childPubKey = deriveXPubKey ioCtx childPrvKey
|
|
||||||
|
-- | Generate a transparent receiver
|
||||||
|
genTransparentReceiver :: Int -> XPrvKey -> IO TransparentAddress
|
||||||
|
genTransparentReceiver i xprvk = do
|
||||||
|
ioCtx <- createContext
|
||||||
|
let rootPubKey = deriveXPubKey ioCtx xprvk
|
||||||
|
let childPubKey = pubSubKey ioCtx rootPubKey (fromIntegral i)
|
||||||
let x = xPubAddr ioCtx childPubKey
|
let x = xPubAddr ioCtx childPubKey
|
||||||
case x of
|
case x of
|
||||||
PubKeyAddress k -> return $ TransparentAddress P2PKH $ fromBinary k
|
PubKeyAddress k -> return $ TransparentAddress P2PKH $ fromBinary k
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
-- Copyright : 2022-2024 Vergara Technologies
|
-- Copyright : 2022-2024 Vergara Technologies
|
||||||
-- License : MIT
|
-- License : MIT
|
||||||
--
|
--
|
||||||
-- Maintainer : pitmutt@vergara.tech
|
-- Maintainer : pitmut@vergara.tech
|
||||||
-- Stability : experimental
|
-- Stability : experimental
|
||||||
-- Portability : unknown
|
-- Portability : unknown
|
||||||
--
|
--
|
||||||
|
@ -15,7 +15,6 @@
|
||||||
--
|
--
|
||||||
{-# LANGUAGE DeriveGeneric #-}
|
{-# LANGUAGE DeriveGeneric #-}
|
||||||
{-# LANGUAGE DuplicateRecordFields #-}
|
{-# LANGUAGE DuplicateRecordFields #-}
|
||||||
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
|
|
||||||
{-# LANGUAGE DeriveAnyClass #-}
|
{-# LANGUAGE DeriveAnyClass #-}
|
||||||
{-# LANGUAGE DerivingVia #-}
|
{-# LANGUAGE DerivingVia #-}
|
||||||
{-# LANGUAGE UndecidableInstances #-}
|
{-# LANGUAGE UndecidableInstances #-}
|
||||||
|
@ -31,7 +30,6 @@ import qualified Data.ByteString as BS
|
||||||
import qualified Data.ByteString.Char8 as C
|
import qualified Data.ByteString.Char8 as C
|
||||||
import Data.HexString
|
import Data.HexString
|
||||||
import Data.Int
|
import Data.Int
|
||||||
import Data.Maybe (fromMaybe)
|
|
||||||
import Data.Structured
|
import Data.Structured
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Data.Text.Encoding as E
|
import qualified Data.Text.Encoding as E
|
||||||
|
@ -39,37 +37,14 @@ import Data.Word
|
||||||
import qualified GHC.Generics as GHC
|
import qualified GHC.Generics as GHC
|
||||||
import qualified Generics.SOP as SOP
|
import qualified Generics.SOP as SOP
|
||||||
import Haskoin.Address (Address)
|
import Haskoin.Address (Address)
|
||||||
import Haskoin.Crypto.Keys.Extended (XPrvKey)
|
|
||||||
|
|
||||||
-- * General
|
-- * General
|
||||||
--
|
--
|
||||||
-- | A seed for generating private keys
|
-- | A seed for generating private keys
|
||||||
newtype Seed =
|
type Seed = C.ByteString
|
||||||
Seed BS.ByteString
|
|
||||||
deriving stock (Eq, Prelude.Show, GHC.Generic)
|
|
||||||
deriving anyclass (SOP.Generic, SOP.HasDatatypeInfo)
|
|
||||||
deriving anyclass (Data.Structured.Show)
|
|
||||||
deriving (BorshSize, ToBorsh, FromBorsh) via AsStruct Seed
|
|
||||||
|
|
||||||
instance ToBytes Seed where
|
|
||||||
getBytes (Seed x) = x
|
|
||||||
|
|
||||||
-- | A mnemonic phrase used to derive seeds
|
-- | A mnemonic phrase used to derive seeds
|
||||||
newtype Phrase =
|
type Phrase = BS.ByteString
|
||||||
Phrase C.ByteString
|
|
||||||
deriving stock (Eq, Prelude.Show, GHC.Generic, Read)
|
|
||||||
deriving anyclass (SOP.Generic, SOP.HasDatatypeInfo)
|
|
||||||
deriving anyclass (Data.Structured.Show)
|
|
||||||
deriving (BorshSize, ToBorsh, FromBorsh) via AsStruct Phrase
|
|
||||||
|
|
||||||
instance ToBytes Phrase where
|
|
||||||
getBytes (Phrase x) = x
|
|
||||||
|
|
||||||
-- | Scope for addresses/receivers
|
|
||||||
data Scope
|
|
||||||
= External -- ^ Addresses used publically to receive payments
|
|
||||||
| Internal -- ^ Addresses used internally by wallets for change and shielding
|
|
||||||
deriving (Eq, Prelude.Show, Read)
|
|
||||||
|
|
||||||
-- | Type to represent data after Bech32 decoding
|
-- | Type to represent data after Bech32 decoding
|
||||||
data RawData = RawData
|
data RawData = RawData
|
||||||
|
@ -169,7 +144,7 @@ instance (FromJSON r) => FromJSON (RpcResponse r) where
|
||||||
withObject "RpcResponse" $ \obj -> do
|
withObject "RpcResponse" $ \obj -> do
|
||||||
e <- obj .:? "error"
|
e <- obj .:? "error"
|
||||||
i <- obj .: "id"
|
i <- obj .: "id"
|
||||||
r <- obj .:? "result"
|
r <- obj .: "result"
|
||||||
pure $ MakeRpcResponse e i r
|
pure $ MakeRpcResponse e i r
|
||||||
|
|
||||||
-- | A type to model the errors from the Zcash RPC
|
-- | A type to model the errors from the Zcash RPC
|
||||||
|
@ -192,7 +167,7 @@ data BlockResponse = BlockResponse
|
||||||
{ bl_confirmations :: !Integer -- ^ Block confirmations
|
{ bl_confirmations :: !Integer -- ^ Block confirmations
|
||||||
, bl_height :: !Integer -- ^ Block height
|
, bl_height :: !Integer -- ^ Block height
|
||||||
, bl_time :: !Integer -- ^ Block time
|
, bl_time :: !Integer -- ^ Block time
|
||||||
, bl_txs :: ![HexString] -- ^ List of transaction IDs in the block
|
, bl_txs :: ![T.Text] -- ^ List of transaction IDs in the block
|
||||||
} deriving (Prelude.Show, Eq)
|
} deriving (Prelude.Show, Eq)
|
||||||
|
|
||||||
instance FromJSON BlockResponse where
|
instance FromJSON BlockResponse where
|
||||||
|
@ -200,15 +175,14 @@ instance FromJSON BlockResponse where
|
||||||
withObject "BlockResponse" $ \obj -> do
|
withObject "BlockResponse" $ \obj -> do
|
||||||
c <- obj .: "confirmations"
|
c <- obj .: "confirmations"
|
||||||
h <- obj .: "height"
|
h <- obj .: "height"
|
||||||
t <- obj .:? "time"
|
t <- obj .: "time"
|
||||||
txs <- obj .: "tx"
|
txs <- obj .: "tx"
|
||||||
pure $ BlockResponse c h (fromMaybe 0 t) txs
|
pure $ BlockResponse c h t txs
|
||||||
|
|
||||||
-- | Type to represent response from the `zcashd` RPC `getrawtransaction`
|
-- | Type to represent response from the `zcashd` RPC `getrawtransaction`
|
||||||
data RawTxResponse = RawTxResponse
|
data RawTxResponse = RawTxResponse
|
||||||
{ rt_id :: !HexString
|
{ rt_id :: !HexString
|
||||||
, rt_hex :: !HexString
|
, rt_hex :: !HexString
|
||||||
, rt_shieldedSpends :: ![ShieldedSpend]
|
|
||||||
, rt_shieldedOutputs :: ![BS.ByteString]
|
, rt_shieldedOutputs :: ![BS.ByteString]
|
||||||
, rt_orchardActions :: ![OrchardAction]
|
, rt_orchardActions :: ![OrchardAction]
|
||||||
, rt_blockheight :: !Integer
|
, rt_blockheight :: !Integer
|
||||||
|
@ -259,9 +233,6 @@ data TransparentType
|
||||||
| P2PKH
|
| P2PKH
|
||||||
deriving (Eq, Prelude.Show, Read)
|
deriving (Eq, Prelude.Show, Read)
|
||||||
|
|
||||||
-- | Type for transparent spending key
|
|
||||||
type TransparentSpendingKey = XPrvKey
|
|
||||||
|
|
||||||
-- | Type to represent a transparent Zcash addresses
|
-- | Type to represent a transparent Zcash addresses
|
||||||
data TransparentAddress = TransparentAddress
|
data TransparentAddress = TransparentAddress
|
||||||
{ ta_type :: !TransparentType
|
{ ta_type :: !TransparentType
|
||||||
|
@ -270,44 +241,13 @@ data TransparentAddress = TransparentAddress
|
||||||
|
|
||||||
-- * Sapling
|
-- * Sapling
|
||||||
-- | A spending key for Sapling
|
-- | A spending key for Sapling
|
||||||
newtype SaplingSpendingKey =
|
type SaplingSpendingKey = BS.ByteString
|
||||||
SaplingSpendingKey BS.ByteString
|
|
||||||
deriving stock (Eq, Prelude.Show, Read)
|
|
||||||
|
|
||||||
instance ToBytes SaplingSpendingKey where
|
|
||||||
getBytes (SaplingSpendingKey s) = s
|
|
||||||
|
|
||||||
-- | A Sapling receiver
|
-- | A Sapling receiver
|
||||||
newtype SaplingReceiver =
|
type SaplingReceiver = BS.ByteString
|
||||||
SaplingReceiver BS.ByteString
|
|
||||||
deriving stock (Eq, Prelude.Show, Read)
|
|
||||||
|
|
||||||
instance ToBytes SaplingReceiver where
|
-- | A Sapling internal receiver
|
||||||
getBytes (SaplingReceiver s) = s
|
type SaplingInternalReceiver = BS.ByteString
|
||||||
|
|
||||||
-- | Type to represent a Sapling Shielded Spend as provided by the @getrawtransaction@ RPC method
|
|
||||||
data ShieldedSpend = ShieldedSpend
|
|
||||||
{ sp_cv :: !HexString
|
|
||||||
, sp_anchor :: !HexString
|
|
||||||
, sp_nullifier :: !HexString
|
|
||||||
, sp_rk :: !HexString
|
|
||||||
, sp_proof :: !HexString
|
|
||||||
, sp_auth :: !HexString
|
|
||||||
} deriving stock (Eq, Prelude.Show, GHC.Generic, Read)
|
|
||||||
deriving anyclass (SOP.Generic, SOP.HasDatatypeInfo)
|
|
||||||
deriving anyclass (Data.Structured.Show)
|
|
||||||
deriving (BorshSize, ToBorsh, FromBorsh) via AsStruct ShieldedSpend
|
|
||||||
|
|
||||||
instance FromJSON ShieldedSpend where
|
|
||||||
parseJSON =
|
|
||||||
withObject "ShieldedSpend" $ \obj -> do
|
|
||||||
cv <- obj .: "cv"
|
|
||||||
anchor <- obj .: "anchor"
|
|
||||||
nullifier <- obj .: "nullifier"
|
|
||||||
rk <- obj .: "rk"
|
|
||||||
p <- obj .: "proof"
|
|
||||||
sig <- obj .: "spendAuthSig"
|
|
||||||
pure $ ShieldedSpend cv anchor nullifier rk p sig
|
|
||||||
|
|
||||||
-- | Type to represent a Sapling Shielded Output as provided by the @getrawtransaction@ RPC method of @zcashd@.
|
-- | Type to represent a Sapling Shielded Output as provided by the @getrawtransaction@ RPC method of @zcashd@.
|
||||||
data ShieldedOutput = ShieldedOutput
|
data ShieldedOutput = ShieldedOutput
|
||||||
|
@ -335,20 +275,10 @@ instance FromJSON ShieldedOutput where
|
||||||
|
|
||||||
-- * Orchard
|
-- * Orchard
|
||||||
-- | A spending key for Orchard
|
-- | A spending key for Orchard
|
||||||
newtype OrchardSpendingKey =
|
type OrchardSpendingKey = BS.ByteString
|
||||||
OrchardSpendingKey BS.ByteString
|
|
||||||
deriving stock (Eq, Prelude.Show, Read)
|
|
||||||
|
|
||||||
instance ToBytes OrchardSpendingKey where
|
|
||||||
getBytes (OrchardSpendingKey o) = o
|
|
||||||
|
|
||||||
-- | An Orchard receiver
|
-- | An Orchard receiver
|
||||||
newtype OrchardReceiver =
|
type OrchardReceiver = BS.ByteString
|
||||||
OrchardReceiver BS.ByteString
|
|
||||||
deriving stock (Eq, Prelude.Show, Read)
|
|
||||||
|
|
||||||
instance ToBytes OrchardReceiver where
|
|
||||||
getBytes (OrchardReceiver o) = o
|
|
||||||
|
|
||||||
-- | Type to represent a Unified Address
|
-- | Type to represent a Unified Address
|
||||||
data UnifiedAddress = UnifiedAddress
|
data UnifiedAddress = UnifiedAddress
|
||||||
|
@ -419,11 +349,6 @@ data DecodedNote = DecodedNote
|
||||||
deriving anyclass (Data.Structured.Show)
|
deriving anyclass (Data.Structured.Show)
|
||||||
deriving (BorshSize, ToBorsh, FromBorsh) via AsStruct DecodedNote
|
deriving (BorshSize, ToBorsh, FromBorsh) via AsStruct DecodedNote
|
||||||
|
|
||||||
-- * Classes
|
|
||||||
-- | Class to represent types with a bytestring representation
|
|
||||||
class ToBytes a where
|
|
||||||
getBytes :: a -> BS.ByteString
|
|
||||||
|
|
||||||
-- * Helpers
|
-- * Helpers
|
||||||
-- | Helper function to turn a hex-encoded string to bytestring
|
-- | Helper function to turn a hex-encoded string to bytestring
|
||||||
decodeHexText :: String -> BS.ByteString
|
decodeHexText :: String -> BS.ByteString
|
||||||
|
|
|
@ -23,14 +23,12 @@ import C.Zcash
|
||||||
, rustWrapperF4Jumble
|
, rustWrapperF4Jumble
|
||||||
, rustWrapperF4UnJumble
|
, rustWrapperF4UnJumble
|
||||||
)
|
)
|
||||||
import Control.Exception (SomeException(..), try)
|
|
||||||
import Control.Monad.IO.Class
|
import Control.Monad.IO.Class
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
import qualified Data.ByteString as BS
|
import qualified Data.ByteString as BS
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Data.Text.Encoding as E
|
import qualified Data.Text.Encoding as E
|
||||||
import Foreign.Rust.Marshall.Variable
|
import Foreign.Rust.Marshall.Variable
|
||||||
import Network.HTTP.Client (HttpException(..))
|
|
||||||
import Network.HTTP.Simple
|
import Network.HTTP.Simple
|
||||||
import ZcashHaskell.Types
|
import ZcashHaskell.Types
|
||||||
|
|
||||||
|
@ -76,12 +74,12 @@ makeZcashCall username password m p = do
|
||||||
|
|
||||||
-- | Make a Zebra RPC call
|
-- | Make a Zebra RPC call
|
||||||
makeZebraCall ::
|
makeZebraCall ::
|
||||||
FromJSON a
|
(MonadIO m, FromJSON a)
|
||||||
=> T.Text -- ^ Hostname for `zebrad`
|
=> T.Text -- ^ Hostname for `zebrad`
|
||||||
-> Int -- ^ Port for `zebrad`
|
-> Int -- ^ Port for `zebrad`
|
||||||
-> T.Text -- ^ RPC method to call
|
-> T.Text -- ^ RPC method to call
|
||||||
-> [Data.Aeson.Value] -- ^ List of parameters
|
-> [Data.Aeson.Value] -- ^ List of parameters
|
||||||
-> IO (Either String a)
|
-> m (Response a)
|
||||||
makeZebraCall host port m params = do
|
makeZebraCall host port m params = do
|
||||||
let payload = RpcCall "2.0" "zh" m params
|
let payload = RpcCall "2.0" "zh" m params
|
||||||
let myRequest =
|
let myRequest =
|
||||||
|
@ -89,16 +87,4 @@ makeZebraCall host port m params = do
|
||||||
setRequestPort port $
|
setRequestPort port $
|
||||||
setRequestHost (E.encodeUtf8 host) $
|
setRequestHost (E.encodeUtf8 host) $
|
||||||
setRequestMethod "POST" defaultRequest
|
setRequestMethod "POST" defaultRequest
|
||||||
r <-
|
httpJSON myRequest
|
||||||
try $ httpJSON myRequest :: FromJSON a1 =>
|
|
||||||
IO (Either SomeException (Response (RpcResponse a1)))
|
|
||||||
case r of
|
|
||||||
Left ex -> return $ Left $ show ex
|
|
||||||
Right res -> do
|
|
||||||
let zebraResp = getResponseBody res
|
|
||||||
case err zebraResp of
|
|
||||||
Just zErr -> return $ Left $ T.unpack $ emessage zErr
|
|
||||||
Nothing ->
|
|
||||||
case result zebraResp of
|
|
||||||
Nothing -> return $ Left "Empty response from Zebra"
|
|
||||||
Just zR -> return $ Right zR
|
|
||||||
|
|
326
test/Spec.hs
326
test/Spec.hs
|
@ -33,6 +33,7 @@ import qualified Data.Text as T
|
||||||
import qualified Data.Text.Encoding as E
|
import qualified Data.Text.Encoding as E
|
||||||
import qualified Data.Text.Lazy.Encoding as LE
|
import qualified Data.Text.Lazy.Encoding as LE
|
||||||
import qualified Data.Text.Lazy.IO as LTIO
|
import qualified Data.Text.Lazy.IO as LTIO
|
||||||
|
|
||||||
import GHC.Float.RealFracMethods (properFractionDoubleInteger)
|
import GHC.Float.RealFracMethods (properFractionDoubleInteger)
|
||||||
import Test.Hspec
|
import Test.Hspec
|
||||||
import Test.Hspec.QuickCheck
|
import Test.Hspec.QuickCheck
|
||||||
|
@ -41,8 +42,8 @@ import ZcashHaskell.Keys (generateWalletSeedPhrase, getWalletSeed)
|
||||||
import ZcashHaskell.Orchard
|
import ZcashHaskell.Orchard
|
||||||
import ZcashHaskell.Sapling
|
import ZcashHaskell.Sapling
|
||||||
( decodeSaplingOutput
|
( decodeSaplingOutput
|
||||||
, genSaplingInternalAddress
|
|
||||||
, genSaplingPaymentAddress
|
, genSaplingPaymentAddress
|
||||||
|
, genSaplingInternalAddress
|
||||||
, genSaplingSpendingKey
|
, genSaplingSpendingKey
|
||||||
, getShieldedOutputs
|
, getShieldedOutputs
|
||||||
, isValidSaplingViewingKey
|
, isValidSaplingViewingKey
|
||||||
|
@ -54,18 +55,14 @@ import ZcashHaskell.Types
|
||||||
( AccountId
|
( AccountId
|
||||||
, BlockResponse(..)
|
, BlockResponse(..)
|
||||||
, CoinType(..)
|
, CoinType(..)
|
||||||
|
, CoinType
|
||||||
, DecodedNote(..)
|
, DecodedNote(..)
|
||||||
, OrchardAction(..)
|
, OrchardAction(..)
|
||||||
, OrchardSpendingKey(..)
|
|
||||||
, Phrase(..)
|
, Phrase(..)
|
||||||
, RawData(..)
|
, RawData(..)
|
||||||
, RawTxResponse(..)
|
, RawTxResponse(..)
|
||||||
, SaplingReceiver(..)
|
|
||||||
, SaplingSpendingKey(..)
|
|
||||||
, Scope(..)
|
|
||||||
, Seed(..)
|
, Seed(..)
|
||||||
, ShieldedOutput(..)
|
, ShieldedOutput(..)
|
||||||
, ToBytes(..)
|
|
||||||
, TransparentAddress(..)
|
, TransparentAddress(..)
|
||||||
, TransparentType(..)
|
, TransparentType(..)
|
||||||
, UnifiedAddress(..)
|
, UnifiedAddress(..)
|
||||||
|
@ -318,7 +315,7 @@ main = do
|
||||||
describe "Seeds" $ do
|
describe "Seeds" $ do
|
||||||
it "generate seed phrase" $ do
|
it "generate seed phrase" $ do
|
||||||
s <- generateWalletSeedPhrase
|
s <- generateWalletSeedPhrase
|
||||||
BS.length (getBytes s) `shouldNotBe` 0
|
BS.length s `shouldNotBe` 0
|
||||||
it "get seed from phrase" $ do
|
it "get seed from phrase" $ do
|
||||||
s <- generateWalletSeedPhrase
|
s <- generateWalletSeedPhrase
|
||||||
let x = getWalletSeed s
|
let x = getWalletSeed s
|
||||||
|
@ -472,11 +469,11 @@ main = do
|
||||||
let msg = maybe "" a_memo decryptedNote2
|
let msg = maybe "" a_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ed phrase" $ do
|
||||||
prop "Generated phrases are valid" $ again prop_PhraseLength
|
prop "Generated phrases are valid" $ again prop_PhraseLength
|
||||||
prop "Derived seeds are valid" $ again prop_SeedLength
|
prop "Derived seeds are valid" $ again prop_SeedLength
|
||||||
before getSeed $
|
before getSeed $
|
||||||
describe "Optimized spending key tests:" $ do
|
describe "Optimized spending key tests" $ do
|
||||||
it "Transparent spending keys are valid" $ \s ->
|
it "Transparent spending keys are valid" $ \s ->
|
||||||
property $ prop_TransparentSpendingKey s
|
property $ prop_TransparentSpendingKey s
|
||||||
it "Transparent receivers are valid" $ \s ->
|
it "Transparent receivers are valid" $ \s ->
|
||||||
|
@ -493,7 +490,7 @@ main = do
|
||||||
property $ prop_OrchardReceiver s
|
property $ prop_OrchardReceiver s
|
||||||
it "Orchard receivers are distinct" $ \s ->
|
it "Orchard receivers are distinct" $ \s ->
|
||||||
property $ prop_OrchardRecRepeated s
|
property $ prop_OrchardRecRepeated s
|
||||||
describe "Address tests:" $ do
|
describe "Address tests" $ do
|
||||||
it "Encode transparent" $ do
|
it "Encode transparent" $ do
|
||||||
let ua =
|
let ua =
|
||||||
"u17n7hpwaujyq7ux8f9jpyymtnk5urw7pyrf60smp5mawy7jgz325hfvz3jn3zsfya8yxryf9q7ldk8nu8df0emra5wne28zq9d9nm2pu4x6qwjha565av9aze0xgujgslz74ufkj0c0cylqwjyrh9msjfh7jzal6d3qzrnhkkqy3pqm8j63y07jxj7txqeac982778rmt64f32aum94x"
|
"u17n7hpwaujyq7ux8f9jpyymtnk5urw7pyrf60smp5mawy7jgz325hfvz3jn3zsfya8yxryf9q7ldk8nu8df0emra5wne28zq9d9nm2pu4x6qwjha565av9aze0xgujgslz74ufkj0c0cylqwjyrh9msjfh7jzal6d3qzrnhkkqy3pqm8j63y07jxj7txqeac982778rmt64f32aum94x"
|
||||||
|
@ -504,50 +501,117 @@ main = do
|
||||||
maybe "No transparent" (encodeTransparent (ua_net u)) $
|
maybe "No transparent" (encodeTransparent (ua_net u)) $
|
||||||
t_rec u
|
t_rec u
|
||||||
msg `shouldBe` "t1LPWuQnjCRH7JAeEErSXKixcUteLJRJjKD"
|
msg `shouldBe` "t1LPWuQnjCRH7JAeEErSXKixcUteLJRJjKD"
|
||||||
it "Recover UA from YWallet" $
|
describe "Transparent Private and Public Key Generation" $ do
|
||||||
ioProperty $ do
|
it "Obtain a transparent extended private key from HDSeed" $ do
|
||||||
let p =
|
let hdseed =
|
||||||
Phrase
|
[ 206
|
||||||
"security expect junk hour people bind law hub between topic wink cliff spirit scissors auction idle figure option wide useful swift prison cushion round"
|
, 61
|
||||||
let targetUA =
|
, 120
|
||||||
isValidUnifiedAddress
|
, 38
|
||||||
"u1qsylqauvnhw8tsfe3cldcsj3mjrfqzgaf3mt8yzlkjuvsf5wzj223yvrt8q66qukfqcc80x3z0mk6ym6pm2f0hukzkp6t4wj78h85t6kfr2u9mqsfhdd73g3sc7ezy2ut3rtq5jmejatwv4xqqd6l8tt9fycer8kdw0gz6e607nkssqsc7kd7nk2yfz2hpvpqhdg39wxalpjzhe34j7"
|
, 206
|
||||||
|
, 40
|
||||||
|
, 201
|
||||||
|
, 62
|
||||||
|
, 83
|
||||||
|
, 175
|
||||||
|
, 151
|
||||||
|
, 131
|
||||||
|
, 218
|
||||||
|
, 141
|
||||||
|
, 206
|
||||||
|
, 254
|
||||||
|
, 28
|
||||||
|
, 244
|
||||||
|
, 172
|
||||||
|
, 213
|
||||||
|
, 128
|
||||||
|
, 248
|
||||||
|
, 156
|
||||||
|
, 45
|
||||||
|
, 204
|
||||||
|
, 44
|
||||||
|
, 169
|
||||||
|
, 3
|
||||||
|
, 162
|
||||||
|
, 188
|
||||||
|
, 16
|
||||||
|
, 173
|
||||||
|
, 192
|
||||||
|
, 164
|
||||||
|
, 96
|
||||||
|
, 148
|
||||||
|
, 91
|
||||||
|
, 52
|
||||||
|
, 244
|
||||||
|
, 83
|
||||||
|
, 149
|
||||||
|
, 169
|
||||||
|
, 82
|
||||||
|
, 196
|
||||||
|
, 199
|
||||||
|
, 53
|
||||||
|
, 177
|
||||||
|
, 170
|
||||||
|
, 1
|
||||||
|
, 6
|
||||||
|
, 0
|
||||||
|
, 120
|
||||||
|
, 170
|
||||||
|
, 2
|
||||||
|
, 238
|
||||||
|
, 219
|
||||||
|
, 241
|
||||||
|
, 243
|
||||||
|
, 172
|
||||||
|
, 178
|
||||||
|
, 104
|
||||||
|
, 81
|
||||||
|
, 159
|
||||||
|
, 144
|
||||||
|
] :: [Word8]
|
||||||
|
xtpvk <- genTransparentPrvKey (BS.pack hdseed) MainNetCoin 0
|
||||||
|
let testpvk =
|
||||||
|
XPrvKey
|
||||||
|
0
|
||||||
|
"0000000000"
|
||||||
|
0
|
||||||
|
"fb5b9b89d3e9dfdebeaabd15de8fbc7e9a140b7f2de2b4034c2573425d39aceb"
|
||||||
|
"46aa0cd24a6e05709591426a4e682dd5406de4e75a39c0f410ee790403880943"
|
||||||
|
xtpvk `shouldBe` testpvk
|
||||||
|
it "Obtain a transparent extended public key from private key" $ do
|
||||||
|
let testpvk =
|
||||||
|
XPrvKey
|
||||||
|
0
|
||||||
|
"0000000000"
|
||||||
|
0
|
||||||
|
"fb5b9b89d3e9dfdebeaabd15de8fbc7e9a140b7f2de2b4034c2573425d39aceb"
|
||||||
|
"46aa0cd24a6e05709591426a4e682dd5406de4e75a39c0f410ee790403880943"
|
||||||
|
let testpbk =
|
||||||
|
XPubKey
|
||||||
|
0
|
||||||
|
"00000000"
|
||||||
|
0
|
||||||
|
"fb5b9b89d3e9dfdebeaabd15de8fbc7e9a140b7f2de2b4034c2573425d39aceb"
|
||||||
|
"279bda9c704f6da479cedb12c7cf773b3a348569dc1cfa6002526bad67674fd737b84a2bdb1199ecab1c9fed1b9a38aba5ba19259c1510d733a2376118515cd8"
|
||||||
|
let xtpubkIO = genTransparentPubKey testpvk
|
||||||
|
xtpubk <- xtpubkIO
|
||||||
|
---print $ show xtpubk
|
||||||
|
xtpubk `shouldBe` testpbk
|
||||||
|
-- describe "Sapling SpendingKey test" $ do
|
||||||
|
-- it "Generate Sapling spending key" $ do
|
||||||
|
-- p <- generateWalletSeedPhrase
|
||||||
|
-- let s = getWalletSeed p
|
||||||
|
-- genSaplingSpendingKey <$> s `shouldNotBe` Nothing
|
||||||
|
describe "Sapling Payment Address generation test" $ do
|
||||||
|
it "Call genSaplingPaymentAddress" $ do
|
||||||
|
p <- generateWalletSeedPhrase
|
||||||
let s = getWalletSeed p
|
let s = getWalletSeed p
|
||||||
case s of
|
genSaplingPaymentAddress 0 (fromMaybe "" s) `shouldNotBe` Nothing
|
||||||
Nothing -> return $ expectationFailure "Failed to generate seed"
|
-- prop "Sapling receivers are valid" $
|
||||||
Just s' -> do
|
-- forAll genSapArgs $ \s -> prop_SaplingReceiver s
|
||||||
let oK = genOrchardSpendingKey s' MainNetCoin 0
|
|
||||||
let sK = genSaplingSpendingKey s' MainNetCoin 0
|
|
||||||
let tK = genTransparentPrvKey s' MainNetCoin 0
|
|
||||||
let oR = genOrchardReceiver 0 External =<< oK
|
|
||||||
let sR = genSaplingPaymentAddress 0 =<< sK
|
|
||||||
tR <- genTransparentReceiver 0 External =<< tK
|
|
||||||
let newUA = UnifiedAddress MainNet oR sR $ Just tR
|
|
||||||
return $ Just newUA `shouldBe` targetUA
|
|
||||||
it "Recover UA from Zingo:" $
|
|
||||||
ioProperty $ do
|
|
||||||
let p =
|
|
||||||
Phrase
|
|
||||||
"cloth swing left trap random tornado have great onion element until make shy dad success art tuition canvas thunder apple decade elegant struggle invest"
|
|
||||||
let targetUA =
|
|
||||||
isValidUnifiedAddress
|
|
||||||
"u1trd8cvc6265ywwj4mmvuznsye5ghe2dhhn3zy8kcuyg4vx3svskw9r2dedp5hu6m740vylkqc34t4w9eqkl9fyu5uyzn3af72jg235440ke6tu5cf994eq85n97x69x9824hqejmwz3d8qqthtesrd6gerjupdymldhl9xccejjwfj0dhh9mt4rw4kytp325twlutsxd20rfqhzxu3m"
|
|
||||||
let s = getWalletSeed p
|
|
||||||
case s of
|
|
||||||
Nothing -> return $ expectationFailure "Failed to generate seed"
|
|
||||||
Just s' -> do
|
|
||||||
let oK = genOrchardSpendingKey s' MainNetCoin 0
|
|
||||||
let sK = genSaplingSpendingKey s' MainNetCoin 0
|
|
||||||
let tK = genTransparentPrvKey s' MainNetCoin 0
|
|
||||||
let oR = genOrchardReceiver 0 External =<< oK
|
|
||||||
let sR = genSaplingPaymentAddress 0 =<< sK
|
|
||||||
tR <- genTransparentReceiver 0 External =<< tK
|
|
||||||
let newUA = UnifiedAddress MainNet oR sR $ Just tR
|
|
||||||
return $ Just newUA `shouldBe` targetUA
|
|
||||||
describe "Sapling Change Payment Address generation test" $ do
|
describe "Sapling Change Payment Address generation test" $ do
|
||||||
it "Call genSaplingInternalAddress" $ do
|
it "Call genSaplingInternalAddress" $ do
|
||||||
let sk =
|
let sk = [ 3
|
||||||
[ 3
|
|
||||||
, 183
|
, 183
|
||||||
, 26
|
, 26
|
||||||
, 151
|
, 151
|
||||||
|
@ -715,83 +779,82 @@ main = do
|
||||||
, 29
|
, 29
|
||||||
, 216
|
, 216
|
||||||
, 48
|
, 48
|
||||||
, 201
|
, 201] :: [Word8]
|
||||||
] :: [Word8]
|
let cAdr = [31, 232, 31, 17, 196,
|
||||||
let cAdr =
|
178, 208, 227, 206,
|
||||||
[ 31
|
199, 105, 55, 147,
|
||||||
, 232
|
23, 151, 206, 117,
|
||||||
, 31
|
59, 249, 162, 218,
|
||||||
, 17
|
140, 189, 17, 60,
|
||||||
, 196
|
116, 106, 56, 64,
|
||||||
, 178
|
203, 152, 52, 155,
|
||||||
, 208
|
133, 179, 118, 47,
|
||||||
, 227
|
161, 70, 155, 21,
|
||||||
, 206
|
22, 41] :: [Word8]
|
||||||
, 199
|
let bscAdr = BS.pack cAdr
|
||||||
, 105
|
let ca = genSaplingInternalAddress (BS.pack sk)
|
||||||
, 55
|
(fromMaybe "" ca) `shouldBe` bscAdr
|
||||||
, 147
|
it "Recover UA from YWallet" $
|
||||||
, 23
|
ioProperty $ do
|
||||||
, 151
|
let p =
|
||||||
, 206
|
"security expect junk hour people bind law hub between topic wink cliff spirit scissors auction idle figure option wide useful swift prison cushion round"
|
||||||
, 117
|
let targetUA =
|
||||||
, 59
|
isValidUnifiedAddress
|
||||||
, 249
|
"u1qsylqauvnhw8tsfe3cldcsj3mjrfqzgaf3mt8yzlkjuvsf5wzj223yvrt8q66qukfqcc80x3z0mk6ym6pm2f0hukzkp6t4wj78h85t6kfr2u9mqsfhdd73g3sc7ezy2ut3rtq5jmejatwv4xqqd6l8tt9fycer8kdw0gz6e607nkssqsc7kd7nk2yfz2hpvpqhdg39wxalpjzhe34j7"
|
||||||
, 162
|
let s = getWalletSeed p
|
||||||
, 218
|
case s of
|
||||||
, 140
|
Nothing -> return $ expectationFailure "Failed to generate seed"
|
||||||
, 189
|
Just s' -> do
|
||||||
, 17
|
let oK = genOrchardSpendingKey s' MainNetCoin 0
|
||||||
, 60
|
let sK = genSaplingSpendingKey s' MainNetCoin 0
|
||||||
, 116
|
let tK = genTransparentPrvKey s' MainNetCoin 0
|
||||||
, 106
|
let oR = genOrchardReceiver 0 =<< oK
|
||||||
, 56
|
let sR = genSaplingPaymentAddress 0 =<< sK
|
||||||
, 64
|
tR <- genTransparentReceiver 0 =<< tK
|
||||||
, 203
|
let newUA = UnifiedAddress MainNet oR sR $ Just tR
|
||||||
, 152
|
return $ Just newUA `shouldBe` targetUA
|
||||||
, 52
|
it "Recover UA from Zingo" $
|
||||||
, 155
|
ioProperty $ do
|
||||||
, 133
|
let p =
|
||||||
, 179
|
"cloth swing left trap random tornado have great onion element until make shy dad success art tuition canvas thunder apple decade elegant struggle invest"
|
||||||
, 118
|
let targetUA =
|
||||||
, 47
|
isValidUnifiedAddress
|
||||||
, 161
|
"u1trd8cvc6265ywwj4mmvuznsye5ghe2dhhn3zy8kcuyg4vx3svskw9r2dedp5hu6m740vylkqc34t4w9eqkl9fyu5uyzn3af72jg235440ke6tu5cf994eq85n97x69x9824hqejmwz3d8qqthtesrd6gerjupdymldhl9xccejjwfj0dhh9mt4rw4kytp325twlutsxd20rfqhzxu3m"
|
||||||
, 70
|
let s = getWalletSeed p
|
||||||
, 155
|
case s of
|
||||||
, 21
|
Nothing -> return $ expectationFailure "Failed to generate seed"
|
||||||
, 22
|
Just s' -> do
|
||||||
, 41
|
let oK = genOrchardSpendingKey s' MainNetCoin 0
|
||||||
] :: [Word8]
|
let sK = genSaplingSpendingKey s' MainNetCoin 0
|
||||||
let bscAdr = SaplingReceiver $ BS.pack cAdr
|
let tK = genTransparentPrvKey s' MainNetCoin 0
|
||||||
let ca = genSaplingInternalAddress (SaplingSpendingKey $ BS.pack sk)
|
let oR = genOrchardReceiver 0 =<< oK
|
||||||
fromMaybe (SaplingReceiver "") ca `shouldBe` bscAdr
|
let sR = genSaplingPaymentAddress 0 =<< sK
|
||||||
|
tR <- genTransparentReceiver 0 =<< tK
|
||||||
|
let newUA = UnifiedAddress MainNet oR sR $ Just tR
|
||||||
|
return $ Just newUA `shouldBe` targetUA
|
||||||
|
|
||||||
-- | Properties
|
-- | Properties
|
||||||
prop_PhraseLength :: Property
|
prop_PhraseLength :: Property
|
||||||
prop_PhraseLength =
|
prop_PhraseLength =
|
||||||
ioProperty $ do
|
ioProperty $ do
|
||||||
p <- generateWalletSeedPhrase
|
p <- generateWalletSeedPhrase
|
||||||
return $ BS.length (getBytes p) >= 95
|
return $ BS.length p >= 95
|
||||||
|
|
||||||
prop_SeedLength :: Property
|
prop_SeedLength :: Property
|
||||||
prop_SeedLength =
|
prop_SeedLength =
|
||||||
ioProperty $ do
|
ioProperty $ do
|
||||||
p <- generateWalletSeedPhrase
|
p <- generateWalletSeedPhrase
|
||||||
let s = getWalletSeed p
|
let s = getWalletSeed p
|
||||||
return $ maybe 0 (BS.length . getBytes) s === 64
|
return $ maybe 0 BS.length s === 64
|
||||||
|
|
||||||
prop_OrchardSpendingKey :: Seed -> CoinType -> NonNegative Int -> Property
|
prop_OrchardSpendingKey :: Seed -> CoinType -> NonNegative Int -> Property
|
||||||
prop_OrchardSpendingKey s c (NonNegative i) =
|
prop_OrchardSpendingKey s c (NonNegative i) =
|
||||||
genOrchardSpendingKey s c i =/= Nothing
|
genOrchardSpendingKey s c i =/= Nothing
|
||||||
|
|
||||||
prop_OrchardReceiver ::
|
prop_OrchardReceiver ::
|
||||||
Seed -> CoinType -> NonNegative Int -> NonNegative Int -> Scope -> Property
|
Seed -> CoinType -> NonNegative Int -> NonNegative Int -> Property
|
||||||
prop_OrchardReceiver s c (NonNegative i) (NonNegative j) scope =
|
prop_OrchardReceiver s c (NonNegative i) (NonNegative j) =
|
||||||
genOrchardReceiver
|
genOrchardReceiver j (fromMaybe "" $ genOrchardSpendingKey s c i) =/= Nothing
|
||||||
j
|
|
||||||
scope
|
|
||||||
(fromMaybe (OrchardSpendingKey "") $ genOrchardSpendingKey s c i) =/=
|
|
||||||
Nothing
|
|
||||||
|
|
||||||
prop_SaplingSpendingKey :: Seed -> CoinType -> NonNegative Int -> Property
|
prop_SaplingSpendingKey :: Seed -> CoinType -> NonNegative Int -> Property
|
||||||
prop_SaplingSpendingKey s c (NonNegative i) =
|
prop_SaplingSpendingKey s c (NonNegative i) =
|
||||||
|
@ -800,44 +863,32 @@ prop_SaplingSpendingKey s c (NonNegative i) =
|
||||||
prop_SaplingReceiver ::
|
prop_SaplingReceiver ::
|
||||||
Seed -> CoinType -> NonNegative Int -> NonNegative Int -> Property
|
Seed -> CoinType -> NonNegative Int -> NonNegative Int -> Property
|
||||||
prop_SaplingReceiver s c (NonNegative i) (NonNegative j) =
|
prop_SaplingReceiver s c (NonNegative i) (NonNegative j) =
|
||||||
genSaplingPaymentAddress
|
genSaplingPaymentAddress i (fromMaybe "" $ genSaplingSpendingKey s c j) =/=
|
||||||
i
|
|
||||||
(fromMaybe (SaplingSpendingKey "") $ genSaplingSpendingKey s c j) =/=
|
|
||||||
Nothing
|
Nothing
|
||||||
|
|
||||||
prop_SaplingRecRepeated :: Seed -> CoinType -> NonNegative Int -> Property
|
prop_SaplingRecRepeated :: Seed -> CoinType -> NonNegative Int -> Property
|
||||||
prop_SaplingRecRepeated s c (NonNegative i) =
|
prop_SaplingRecRepeated s c (NonNegative i) =
|
||||||
genSaplingPaymentAddress
|
genSaplingPaymentAddress i (fromMaybe "" $ genSaplingSpendingKey s c 1) =/=
|
||||||
i
|
genSaplingPaymentAddress (i + 1) (fromMaybe "" $ genSaplingSpendingKey s c 1)
|
||||||
(fromMaybe (SaplingSpendingKey "") $ genSaplingSpendingKey s c 1) =/=
|
|
||||||
genSaplingPaymentAddress
|
|
||||||
(i + 1)
|
|
||||||
(fromMaybe (SaplingSpendingKey "") $ genSaplingSpendingKey s c 1)
|
|
||||||
|
|
||||||
prop_OrchardRecRepeated ::
|
prop_OrchardRecRepeated ::
|
||||||
Seed -> CoinType -> NonNegative Int -> NonNegative Int -> Scope -> Property
|
Seed -> CoinType -> NonNegative Int -> NonNegative Int -> Property
|
||||||
prop_OrchardRecRepeated s c (NonNegative i) (NonNegative j) scope =
|
prop_OrchardRecRepeated s c (NonNegative i) (NonNegative j) =
|
||||||
genOrchardReceiver
|
genOrchardReceiver j (fromMaybe "" $ genOrchardSpendingKey s c i) =/=
|
||||||
j
|
genOrchardReceiver (j + 1) (fromMaybe "" $ genOrchardSpendingKey s c i)
|
||||||
scope
|
|
||||||
(fromMaybe (OrchardSpendingKey "") $ genOrchardSpendingKey s c i) =/=
|
|
||||||
genOrchardReceiver
|
|
||||||
(j + 1)
|
|
||||||
scope
|
|
||||||
(fromMaybe (OrchardSpendingKey "") $ genOrchardSpendingKey s c i)
|
|
||||||
|
|
||||||
prop_TransparentSpendingKey :: Seed -> CoinType -> NonNegative Int -> Property
|
prop_TransparentSpendingKey :: Seed -> NonNegative Int -> Property
|
||||||
prop_TransparentSpendingKey s coinType (NonNegative i) =
|
prop_TransparentSpendingKey s (NonNegative i) =
|
||||||
ioProperty $ do
|
ioProperty $ do
|
||||||
k <- genTransparentPrvKey s coinType i
|
k <- genTransparentPrvKey s MainNetCoin 0
|
||||||
return $ xPrvChild k == fromIntegral i
|
return $ xPrvChild k == fromIntegral i
|
||||||
|
|
||||||
prop_TransparentReceiver ::
|
prop_TransparentReceiver ::
|
||||||
Seed -> CoinType -> Scope -> NonNegative Int -> NonNegative Int -> Property
|
Seed -> NonNegative Int -> NonNegative Int -> Property
|
||||||
prop_TransparentReceiver s coinType scope (NonNegative i) (NonNegative j) =
|
prop_TransparentReceiver s (NonNegative i) (NonNegative j) =
|
||||||
ioProperty $ do
|
ioProperty $ do
|
||||||
k <- genTransparentPrvKey s coinType i
|
k <- genTransparentPrvKey s MainCoinNet i
|
||||||
r <- genTransparentReceiver j scope k
|
r <- genTransparentReceiver j k
|
||||||
return $ ta_type r == P2PKH
|
return $ ta_type r == P2PKH
|
||||||
|
|
||||||
-- | Generators
|
-- | Generators
|
||||||
|
@ -862,6 +913,3 @@ getSeed = do
|
||||||
-- | Arbitrary instances
|
-- | Arbitrary instances
|
||||||
instance Arbitrary CoinType where
|
instance Arbitrary CoinType where
|
||||||
arbitrary = elements [MainNetCoin, TestNetCoin, RegTestNetCoin]
|
arbitrary = elements [MainNetCoin, TestNetCoin, RegTestNetCoin]
|
||||||
|
|
||||||
instance Arbitrary Scope where
|
|
||||||
arbitrary = elements [External, Internal]
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ cabal-version: 3.0
|
||||||
-- see: https://github.com/sol/hpack
|
-- see: https://github.com/sol/hpack
|
||||||
|
|
||||||
name: zcash-haskell
|
name: zcash-haskell
|
||||||
version: 0.5.1.0
|
version: 0.4.4.2
|
||||||
synopsis: Utilities to interact with the Zcash blockchain
|
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>
|
description: Please see the README on the repo at <https://git.vergara.tech/Vergara_Tech/zcash-haskell#readme>
|
||||||
category: Blockchain
|
category: Blockchain
|
||||||
|
@ -53,7 +53,6 @@ library
|
||||||
, generics-sop
|
, generics-sop
|
||||||
, hexstring >=0.12.1
|
, hexstring >=0.12.1
|
||||||
, http-conduit
|
, http-conduit
|
||||||
, http-client
|
|
||||||
, memory
|
, memory
|
||||||
, text
|
, text
|
||||||
, haskoin-core
|
, haskoin-core
|
||||||
|
|
Loading…
Reference in a new issue