Type safety improvements #33
3 changed files with 16 additions and 8 deletions
|
@ -82,7 +82,7 @@ isValidUnifiedAddress str =
|
||||||
then Just (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 (raw_s x)
|
then Just (SaplingReceiver $ 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)
|
||||||
|
@ -106,7 +106,7 @@ 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 $ s_rec ua
|
sReceiver = packReceiver 0x02 $ getBytes <$> s_rec ua
|
||||||
oReceiver = packReceiver 0x03 $ 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
|
||||||
|
|
|
@ -41,10 +41,11 @@ import ZcashHaskell.Types
|
||||||
, RawData(..)
|
, RawData(..)
|
||||||
, RawTxResponse(..)
|
, RawTxResponse(..)
|
||||||
, SaplingInternalReceiver
|
, SaplingInternalReceiver
|
||||||
, SaplingReceiver
|
, SaplingReceiver(..)
|
||||||
, SaplingSpendingKey(..)
|
, SaplingSpendingKey(..)
|
||||||
, Seed(..)
|
, Seed(..)
|
||||||
, ShieldedOutput(..)
|
, ShieldedOutput(..)
|
||||||
|
, ToBytes(..)
|
||||||
, decodeHexText
|
, decodeHexText
|
||||||
, getValue
|
, getValue
|
||||||
)
|
)
|
||||||
|
@ -99,13 +100,13 @@ instance FromJSON RawTxResponse where
|
||||||
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 res
|
then Just $ SaplingSpendingKey res
|
||||||
else Nothing
|
else Nothing
|
||||||
where
|
where
|
||||||
res =
|
res =
|
||||||
withPureBorshVarBuffer
|
withPureBorshVarBuffer
|
||||||
(rustWrapperSaplingSpendingkey
|
(rustWrapperSaplingSpendingkey
|
||||||
seed
|
(getBytes seed)
|
||||||
(fromIntegral $ getValue c)
|
(fromIntegral $ getValue c)
|
||||||
(fromIntegral i))
|
(fromIntegral i))
|
||||||
|
|
||||||
|
@ -113,12 +114,14 @@ 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 res
|
then Just $ SaplingReceiver res
|
||||||
else Nothing
|
else Nothing
|
||||||
where
|
where
|
||||||
res =
|
res =
|
||||||
withPureBorshVarBuffer
|
withPureBorshVarBuffer
|
||||||
(rustWrapperSaplingPaymentAddress extspk (fromIntegral (i * 111)))
|
(rustWrapperSaplingPaymentAddress
|
||||||
|
(getBytes extspk)
|
||||||
|
(fromIntegral (i * 111)))
|
||||||
|
|
||||||
-- | Generate an internal Sapling address
|
-- | Generate an internal Sapling address
|
||||||
genSaplingInternalAddress :: SaplingSpendingKey -> Maybe SaplingInternalReceiver
|
genSaplingInternalAddress :: SaplingSpendingKey -> Maybe SaplingInternalReceiver
|
||||||
|
|
|
@ -272,7 +272,12 @@ instance ToBytes SaplingSpendingKey where
|
||||||
getBytes (SaplingSpendingKey s) = s
|
getBytes (SaplingSpendingKey s) = s
|
||||||
|
|
||||||
-- | A Sapling receiver
|
-- | A Sapling receiver
|
||||||
type SaplingReceiver = BS.ByteString
|
newtype SaplingReceiver =
|
||||||
|
SaplingReceiver BS.ByteString
|
||||||
|
deriving stock (Eq, Prelude.Show, Read)
|
||||||
|
|
||||||
|
instance ToBytes SaplingReceiver where
|
||||||
|
getBytes (SaplingReceiver s) = s
|
||||||
|
|
||||||
-- | A Sapling internal receiver
|
-- | A Sapling internal receiver
|
||||||
type SaplingInternalReceiver = BS.ByteString
|
type SaplingInternalReceiver = BS.ByteString
|
||||||
|
|
Loading…
Reference in a new issue