diff --git a/src/ZcashHaskell/Sapling.hs b/src/ZcashHaskell/Sapling.hs index d4eaa71..fd898f0 100644 --- a/src/ZcashHaskell/Sapling.hs +++ b/src/ZcashHaskell/Sapling.hs @@ -103,7 +103,7 @@ genSaplingSpendingKey seed i = do where res = withPureBorshVarBuffer - (rustWrapperSaplingSpendingkey seed (fromIntegral i)) + (rustWrapperSaplingSpendingkey seed (fromIntegral (i + 2 ^ 31))) -- | Attempts to generate a sapling Payment Address using an ExtendedSpendingKey and a Diversifier Index genSaplingPaymentAddress :: SaplingSpendingKey -> Int -> Maybe SaplingReceiver @@ -114,7 +114,7 @@ genSaplingPaymentAddress extspk i = where res = withPureBorshVarBuffer - (rustWrapperSaplingPaymentAddress extspk (fromIntegral i)) + (rustWrapperSaplingPaymentAddress extspk (fromIntegral (i * 111))) -- | Generate an internal Sapling address genSaplingInternalAddress :: SaplingSpendingKey -> Maybe SaplingInternalReceiver diff --git a/test/Spec.hs b/test/Spec.hs index 6e815b3..65470b2 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -476,12 +476,14 @@ main = do property $ prop_SaplingSpendingKey s it "Sapling receivers are valid" $ \s -> property $ prop_SaplingReceiver s - it "Sapling receivers are not the same" $ \s -> + it "Sapling receivers are distinct" $ \s -> property $ prop_SaplingRecRepeated s it "Orchard spending keys are valid" $ \s -> property $ prop_OrchardSpendingKey s it "Orchard receivers are valid" $ \s -> property $ prop_OrchardReceiver s + it "Orchard receivers are distinct" $ \s -> + property $ prop_OrchardRecRepeated s describe "Address tests" $ do it "Encode transparent" $ do let ua = @@ -625,6 +627,12 @@ prop_SaplingRecRepeated s (NonNegative i) = genSaplingPaymentAddress (fromMaybe "" $ genSaplingSpendingKey s 1) i =/= genSaplingPaymentAddress (fromMaybe "" $ genSaplingSpendingKey s 1) (i + 1) +prop_OrchardRecRepeated :: + Seed -> CoinType -> NonNegative Int -> NonNegative Int -> Property +prop_OrchardRecRepeated s c (NonNegative i) (NonNegative j) = + genOrchardReceiver j (fromMaybe "" $ genOrchardSpendingKey s c i) =/= + genOrchardReceiver (j + 1) (fromMaybe "" $ genOrchardSpendingKey s c i) + -- | Generators genOrcArgs :: Gen (CoinType, Int, Int) genOrcArgs = do