diff --git a/src/ZcashHaskell/Orchard.hs b/src/ZcashHaskell/Orchard.hs index af68603..3021234 100644 --- a/src/ZcashHaskell/Orchard.hs +++ b/src/ZcashHaskell/Orchard.hs @@ -41,7 +41,7 @@ genOrchardSpendingKey :: genOrchardSpendingKey s coinType accountId = if BS.length k /= 32 then Nothing - else Just k + else Just $ OrchardSpendingKey k where k = withPureBorshVarBuffer $ @@ -56,11 +56,14 @@ genOrchardReceiver :: genOrchardReceiver i scope osk = if BS.length k /= 43 then Nothing - else Just k + else Just $ OrchardReceiver k where k = withPureBorshVarBuffer $ - rustWrapperGenOrchardReceiver osk (fromIntegral i) (scope == External) + rustWrapperGenOrchardReceiver + (getBytes osk) + (fromIntegral i) + (scope == External) -- | Checks if given bytestring is a valid encoded unified address isValidUnifiedAddress :: BS.ByteString -> Maybe UnifiedAddress @@ -79,10 +82,10 @@ isValidUnifiedAddress str = UnifiedAddress whichNet (if BS.length (raw_o x) == 43 - then Just (raw_o x) + then Just $ OrchardReceiver (raw_o x) else Nothing) (if BS.length (raw_s x) == 43 - then Just (SaplingReceiver $ raw_s x) + then Just $ SaplingReceiver (raw_s x) else Nothing) (if not (BS.null (raw_t x)) then Just $ TransparentAddress P2PKH (fromRawBytes $ raw_t x) @@ -107,7 +110,7 @@ encodeUnifiedAddress ua = encodeBech32m (E.encodeUtf8 hr) b P2SH -> packReceiver 0x01 $ Just $ toBytes $ ta_bytes t P2PKH -> packReceiver 0x00 $ Just $ toBytes $ ta_bytes t sReceiver = packReceiver 0x02 $ getBytes <$> s_rec ua - oReceiver = packReceiver 0x03 $ o_rec ua + oReceiver = packReceiver 0x03 $ getBytes <$> o_rec ua padding = E.encodeUtf8 $ T.justifyLeft 16 '\NUL' hr packReceiver :: Word8 -> Maybe BS.ByteString -> BS.ByteString packReceiver typeCode receiver' = diff --git a/src/ZcashHaskell/Sapling.hs b/src/ZcashHaskell/Sapling.hs index d788195..d1904ad 100644 --- a/src/ZcashHaskell/Sapling.hs +++ b/src/ZcashHaskell/Sapling.hs @@ -40,7 +40,6 @@ import ZcashHaskell.Types , DecodedNote(..) , RawData(..) , RawTxResponse(..) - , SaplingInternalReceiver , SaplingReceiver(..) , SaplingSpendingKey(..) , Seed(..) @@ -124,5 +123,5 @@ genSaplingPaymentAddress i extspk = (fromIntegral (i * 111))) -- | Generate an internal Sapling address -genSaplingInternalAddress :: SaplingSpendingKey -> Maybe SaplingInternalReceiver +genSaplingInternalAddress :: SaplingSpendingKey -> Maybe SaplingReceiver genSaplingInternalAddress sk = undefined diff --git a/src/ZcashHaskell/Types.hs b/src/ZcashHaskell/Types.hs index af12cb0..7a16ff7 100644 --- a/src/ZcashHaskell/Types.hs +++ b/src/ZcashHaskell/Types.hs @@ -279,9 +279,6 @@ newtype SaplingReceiver = instance ToBytes SaplingReceiver where getBytes (SaplingReceiver s) = s --- | A Sapling internal receiver -type SaplingInternalReceiver = BS.ByteString - -- | Type to represent a Sapling Shielded Output as provided by the @getrawtransaction@ RPC method of @zcashd@. data ShieldedOutput = ShieldedOutput { s_cv :: !HexString -- ^ Value commitment to the input note @@ -308,10 +305,20 @@ instance FromJSON ShieldedOutput where -- * Orchard -- | A spending key for Orchard -type OrchardSpendingKey = BS.ByteString +newtype OrchardSpendingKey = + OrchardSpendingKey BS.ByteString + deriving stock (Eq, Prelude.Show, Read) + +instance ToBytes OrchardSpendingKey where + getBytes (OrchardSpendingKey o) = o -- | An Orchard receiver -type OrchardReceiver = BS.ByteString +newtype OrchardReceiver = + OrchardReceiver BS.ByteString + deriving stock (Eq, Prelude.Show, Read) + +instance ToBytes OrchardReceiver where + getBytes (OrchardReceiver o) = o -- | Type to represent a Unified Address data UnifiedAddress = UnifiedAddress diff --git a/test/Spec.hs b/test/Spec.hs index ff3a2c3..23e67a8 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -57,6 +57,7 @@ import ZcashHaskell.Types , CoinType , DecodedNote(..) , OrchardAction(..) + , OrchardSpendingKey(..) , Phrase(..) , RawData(..) , RawTxResponse(..) @@ -565,7 +566,10 @@ prop_OrchardSpendingKey s c (NonNegative i) = prop_OrchardReceiver :: Seed -> CoinType -> NonNegative Int -> NonNegative Int -> Scope -> Property prop_OrchardReceiver s c (NonNegative i) (NonNegative j) scope = - genOrchardReceiver j scope (fromMaybe "" $ genOrchardSpendingKey s c i) =/= + genOrchardReceiver + j + scope + (fromMaybe (OrchardSpendingKey "") $ genOrchardSpendingKey s c i) =/= Nothing prop_SaplingSpendingKey :: Seed -> CoinType -> NonNegative Int -> Property @@ -592,8 +596,14 @@ prop_SaplingRecRepeated s c (NonNegative i) = prop_OrchardRecRepeated :: Seed -> CoinType -> NonNegative Int -> NonNegative Int -> Scope -> Property prop_OrchardRecRepeated s c (NonNegative i) (NonNegative j) scope = - genOrchardReceiver j scope (fromMaybe "" $ genOrchardSpendingKey s c i) =/= - genOrchardReceiver (j + 1) scope (fromMaybe "" $ genOrchardSpendingKey s c i) + genOrchardReceiver + j + scope + (fromMaybe (OrchardSpendingKey "") $ genOrchardSpendingKey s c i) =/= + genOrchardReceiver + (j + 1) + scope + (fromMaybe (OrchardSpendingKey "") $ genOrchardSpendingKey s c i) prop_TransparentSpendingKey :: Seed -> NonNegative Int -> Property prop_TransparentSpendingKey s (NonNegative i) =