Compare commits

..

15 commits

Author SHA1 Message Date
0e6f7503d4 Sapling Extended Spemding Key generation from HDSedd (64 byte array) 2024-03-05 22:10:05 -05:00
dbccb23b45 Merge branch 'dev040' into rvv040
-- Include orchard Spending Key and new types for working with
	-- zcash network and keys
2024-03-05 17:16:27 -05:00
7b65d322e6 Commit 003 - before merging with dev040 - with orchard spending key 2024-03-05 17:01:17 -05:00
815b4f16b4
Merge pull request 'Add Orchard spending key functionality' (#20) from rav001 into dev040
Reviewed-on: #20
2024-03-05 21:13:14 +00:00
c13d321da5
Bump version 2024-03-05 15:09:57 -06:00
3822e9f2ff
Add tests for Orchard spending key 2024-03-05 15:09:35 -06:00
53716685a8
Add new types for constants for Zcash protocol 2024-03-05 14:44:19 -06:00
694ab8fd17
Add new Orchard spending key generation 2024-03-05 14:44:00 -06:00
f09c3c500b
Update versions of Zcash crates 2024-03-05 14:43:33 -06:00
c1507f36e0
Merge pull request 'Implement UA encoding' (#18) from rav001 into dev040
Reviewed-on: #18
2024-03-04 18:01:38 +00:00
0b1d9e0920
Implement UA encoding per ZIP-316 2024-03-04 11:59:07 -06:00
53a5b62b6b
Correct casing on Rust code 2024-03-04 11:58:04 -06:00
2ae18463fc
Increase verbosity of Rust compile 2024-03-03 15:29:50 -06:00
3cc0e96c44
Rust updates for bech32 encode/decode 2024-03-03 08:23:48 -06:00
9a5ad756b8
Add Read implementation to UnifiedAddress 2024-03-02 07:53:48 -06:00
12 changed files with 399 additions and 375 deletions

View file

@ -14,10 +14,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Function to generate a seed phrase - Function to generate a seed phrase
- Implementations of `Read` for types - Implementations of `Read` for types
- Function to make RPC calls to `zebrad` - Function to make RPC calls to `zebrad`
- Function to encode unified addresses from receivers
- Function to generate an Orchard spending key
- Constants for Zcash protocol
### Changed ### Changed
- Update installation to `cabal` - Update installation to `cabal`
- Updated `bech32` Rust crate to 0.11
### Removed ### Removed

View file

@ -55,7 +55,7 @@ rsFolder = "librustzcash-wrapper"
execCargo :: Verbosity -> String -> [String] -> IO () execCargo :: Verbosity -> String -> [String] -> IO ()
execCargo verbosity command args = do execCargo verbosity command args = do
cargoPath <- cargoPath <-
findProgramOnSearchPath Verbosity.silent defaultProgramSearchPath "cargo" findProgramOnSearchPath Verbosity.normal defaultProgramSearchPath "cargo"
dir <- getCurrentDirectory dir <- getCurrentDirectory
let cargoExec = let cargoExec =
case cargoPath of case cargoPath of

View file

@ -58,12 +58,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "base-x"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270"
[[package]] [[package]]
name = "base64" name = "base64"
version = "0.21.2" version = "0.21.2"
@ -88,6 +82,12 @@ version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445"
[[package]]
name = "bech32"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d"
[[package]] [[package]]
name = "bincode" name = "bincode"
version = "1.3.3" version = "1.3.3"
@ -117,6 +117,12 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf"
[[package]] [[package]]
name = "bitvec" name = "bitvec"
version = "1.0.1" version = "1.0.1"
@ -282,10 +288,14 @@ dependencies = [
] ]
[[package]] [[package]]
name = "bumpalo" name = "bs58"
version = "3.13.0" version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" checksum = "f5353f36341f7451062466f0b755b96ac3a9547e4d7f6b70d603fc721a7d7896"
dependencies = [
"sha2 0.10.6",
"tinyvec",
]
[[package]] [[package]]
name = "byteorder" name = "byteorder"
@ -355,12 +365,6 @@ dependencies = [
"zeroize", "zeroize",
] ]
[[package]]
name = "const_fn"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935"
[[package]] [[package]]
name = "constant_time_eq" name = "constant_time_eq"
version = "0.2.5" version = "0.2.5"
@ -435,6 +439,15 @@ dependencies = [
"typenum", "typenum",
] ]
[[package]]
name = "deranged"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4"
dependencies = [
"powerfmt",
]
[[package]] [[package]]
name = "digest" name = "digest"
version = "0.9.0" version = "0.9.0"
@ -455,12 +468,6 @@ dependencies = [
"subtle", "subtle",
] ]
[[package]]
name = "discard"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"
[[package]] [[package]]
name = "either" name = "either"
version = "1.8.1" version = "1.8.1"
@ -704,11 +711,11 @@ dependencies = [
[[package]] [[package]]
name = "incrementalmerkletree" name = "incrementalmerkletree"
version = "0.3.1" version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5ad43a3f5795945459d577f6589cf62a476e92c79b75e70cd954364e14ce17b" checksum = "361c467824d4d9d4f284be4b2608800839419dccc4d4608f28345237fe354623"
dependencies = [ dependencies = [
"serde", "either",
] ]
[[package]] [[package]]
@ -759,12 +766,6 @@ dependencies = [
"either", "either",
] ]
[[package]]
name = "itoa"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6"
[[package]] [[package]]
name = "jubjub" name = "jubjub"
version = "0.10.0" version = "0.10.0"
@ -885,6 +886,12 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "num-conv"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
[[package]] [[package]]
name = "num-integer" name = "num-integer"
version = "0.1.45" version = "0.1.45"
@ -928,9 +935,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]] [[package]]
name = "orchard" name = "orchard"
version = "0.4.0" version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c6f418f2c25573923f81a091f38b4b19bc20f6c92b5070fb8f0711e64a2b998" checksum = "5d31e68534df32024dcc89a8390ec6d7bef65edd87d91b45cfb481a2eb2d77c5"
dependencies = [ dependencies = [
"aes", "aes",
"bitvec", "bitvec",
@ -954,6 +961,36 @@ dependencies = [
"zcash_note_encryption", "zcash_note_encryption",
] ]
[[package]]
name = "orchard"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fb255c3ffdccd3c84fe9ebed72aef64fdc72e6a3e4180dd411002d47abaad42"
dependencies = [
"aes",
"bitvec",
"blake2b_simd",
"ff",
"fpe",
"group",
"halo2_gadgets",
"halo2_proofs",
"hex",
"incrementalmerkletree",
"lazy_static",
"memuse",
"nonempty",
"pasta_curves",
"rand",
"reddsa",
"serde",
"subtle",
"tracing",
"zcash_note_encryption",
"zcash_spec",
"zip32",
]
[[package]] [[package]]
name = "pairing" name = "pairing"
version = "0.23.0" version = "0.23.0"
@ -1032,6 +1069,12 @@ dependencies = [
"universal-hash", "universal-hash",
] ]
[[package]]
name = "powerfmt"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
[[package]] [[package]]
name = "ppv-lite86" name = "ppv-lite86"
version = "0.2.17" version = "0.2.17"
@ -1040,12 +1083,12 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]] [[package]]
name = "prettyplease" name = "prettyplease"
version = "0.1.25" version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c8646e95016a7a6c4adea95bafa8a16baab64b583356217f2c85db4a39d9a86" checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"syn 1.0.109", "syn 2.0.32",
] ]
[[package]] [[package]]
@ -1057,12 +1100,6 @@ dependencies = [
"toml", "toml",
] ]
[[package]]
name = "proc-macro-hack"
version = "0.5.20+deprecated"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.66" version = "1.0.66"
@ -1074,9 +1111,9 @@ dependencies = [
[[package]] [[package]]
name = "prost" name = "prost"
version = "0.11.9" version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b82eaa1d779e9a4bc1c3217db8ffbeabaae1dca241bf70183242128d48681cd" checksum = "146c289cda302b98a28d40c8b3b90498d6e526dd24ac2ecea73e4e491685b94a"
dependencies = [ dependencies = [
"bytes", "bytes",
"prost-derive", "prost-derive",
@ -1084,53 +1121,53 @@ dependencies = [
[[package]] [[package]]
name = "prost-build" name = "prost-build"
version = "0.11.9" version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "119533552c9a7ffacc21e099c24a0ac8bb19c2a2a3f363de84cd9b844feab270" checksum = "c55e02e35260070b6f716a2423c2ff1c3bb1642ddca6f99e1f26d06268a0e2d2"
dependencies = [ dependencies = [
"bytes", "bytes",
"heck", "heck",
"itertools", "itertools",
"lazy_static",
"log", "log",
"multimap", "multimap",
"once_cell",
"petgraph", "petgraph",
"prettyplease", "prettyplease",
"prost", "prost",
"prost-types", "prost-types",
"regex", "regex",
"syn 1.0.109", "syn 2.0.32",
"tempfile", "tempfile",
"which", "which",
] ]
[[package]] [[package]]
name = "prost-derive" name = "prost-derive"
version = "0.11.9" version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4" checksum = "efb6c9a1dd1def8e2124d17e83a20af56f1570d6c2d2bd9e266ccb768df3840e"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"itertools", "itertools",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 1.0.109", "syn 2.0.32",
] ]
[[package]] [[package]]
name = "prost-types" name = "prost-types"
version = "0.11.9" version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "213622a1460818959ac1181aaeb2dc9c7f63df720db7d788b3e24eacd1983e13" checksum = "193898f59edcf43c26227dcd4c8427f00d99d61e95dcde58dabd49fa291d470e"
dependencies = [ dependencies = [
"prost", "prost",
] ]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.26" version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
@ -1217,7 +1254,7 @@ version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29"
dependencies = [ dependencies = [
"bitflags", "bitflags 1.3.2",
] ]
[[package]] [[package]]
@ -1237,7 +1274,7 @@ checksum = "8d2275aab483050ab2a7364c1a46604865ee7d6906684e08db0f090acf74f9e7"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.13", "syn 2.0.32",
] ]
[[package]] [[package]]
@ -1255,22 +1292,13 @@ version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78"
[[package]]
name = "rustc_version"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
dependencies = [
"semver",
]
[[package]] [[package]]
name = "rustix" name = "rustix"
version = "0.37.20" version = "0.37.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b96e891d04aa506a6d1f318d2771bcb1c7dfda84e126660ace067c9b474bb2c0" checksum = "b96e891d04aa506a6d1f318d2771bcb1c7dfda84e126660ace067c9b474bb2c0"
dependencies = [ dependencies = [
"bitflags", "bitflags 1.3.2",
"errno", "errno",
"io-lifetimes", "io-lifetimes",
"libc", "libc",
@ -1282,24 +1310,20 @@ dependencies = [
name = "rustzcash-wrapper" name = "rustzcash-wrapper"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"bech32 0.9.1", "bech32 0.11.0",
"borsh 0.10.3", "borsh 0.10.3",
"f4jumble", "f4jumble",
"haskell-ffi", "haskell-ffi",
"orchard", "nom",
"orchard 0.7.1",
"proc-macro2", "proc-macro2",
"zcash_address", "zcash_address 0.2.0",
"zcash_client_backend", "zcash_client_backend",
"zcash_note_encryption", "zcash_note_encryption",
"zcash_primitives", "zcash_primitives",
"zip32",
] ]
[[package]]
name = "ryu"
version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041"
[[package]] [[package]]
name = "scopeguard" name = "scopeguard"
version = "1.1.0" version = "1.1.0"
@ -1315,67 +1339,26 @@ dependencies = [
"zeroize", "zeroize",
] ]
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
dependencies = [
"semver-parser",
]
[[package]]
name = "semver-parser"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.159" version = "1.0.193"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c04e8343c3daeec41f58990b9d77068df31209f2af111e059e9fe9646693065" checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.159" version = "1.0.193"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585" checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.13", "syn 2.0.32",
] ]
[[package]]
name = "serde_json"
version = "1.0.96"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "sha1"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1da05c97445caa12d05e848c4a4fcbbea29e748ac28f7e80e9b010392063770"
dependencies = [
"sha1_smol",
]
[[package]]
name = "sha1_smol"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012"
[[package]] [[package]]
name = "sha2" name = "sha2"
version = "0.9.9" version = "0.9.9"
@ -1400,76 +1383,30 @@ dependencies = [
"digest 0.10.7", "digest 0.10.7",
] ]
[[package]]
name = "shardtree"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c19f96dde3a8693874f7e7c53d95616569b4009379a903789efbd448f4ea9cc7"
dependencies = [
"bitflags 2.4.2",
"either",
"incrementalmerkletree",
"tracing",
]
[[package]] [[package]]
name = "spin" name = "spin"
version = "0.5.2" version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]]
name = "standback"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff"
dependencies = [
"version_check",
]
[[package]] [[package]]
name = "static_assertions" name = "static_assertions"
version = "1.1.0" version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "stdweb"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5"
dependencies = [
"discard",
"rustc_version",
"stdweb-derive",
"stdweb-internal-macros",
"stdweb-internal-runtime",
"wasm-bindgen",
]
[[package]]
name = "stdweb-derive"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef"
dependencies = [
"proc-macro2",
"quote",
"serde",
"serde_derive",
"syn 1.0.109",
]
[[package]]
name = "stdweb-internal-macros"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11"
dependencies = [
"base-x",
"proc-macro2",
"quote",
"serde",
"serde_derive",
"serde_json",
"sha1",
"syn 1.0.109",
]
[[package]]
name = "stdweb-internal-runtime"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0"
[[package]] [[package]]
name = "subtle" name = "subtle"
version = "2.4.1" version = "2.4.1"
@ -1489,9 +1426,9 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.13" version = "2.0.32"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c9da457c5285ac1f936ebd076af6dac17a61cfe7826f2076b4d015cf47bc8ec" checksum = "239814284fd6f1a4ffe4ca893952cdd93c224b6a1571c9a9eadd670295c0c9e2"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1535,46 +1472,27 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.13", "syn 2.0.32",
] ]
[[package]] [[package]]
name = "time" name = "time"
version = "0.2.27" version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4752a97f8eebd6854ff91f1c1824cd6160626ac4bd44287f7f4ea2035a02a242" checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749"
dependencies = [ dependencies = [
"const_fn", "deranged",
"libc", "num-conv",
"standback", "powerfmt",
"stdweb", "serde",
"time-macros", "time-core",
"version_check",
"winapi",
] ]
[[package]] [[package]]
name = "time-macros" name = "time-core"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1"
dependencies = [
"proc-macro-hack",
"time-macros-impl",
]
[[package]]
name = "time-macros-impl"
version = "0.1.2" version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f" checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
dependencies = [
"proc-macro-hack",
"proc-macro2",
"quote",
"standback",
"syn 1.0.109",
]
[[package]] [[package]]
name = "tinyvec" name = "tinyvec"
@ -1602,15 +1520,15 @@ dependencies = [
[[package]] [[package]]
name = "tonic-build" name = "tonic-build"
version = "0.9.2" version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6fdaae4c2c638bb70fe42803a26fbd6fc6ac8c72f5c59f67ecc2a2dcabf4b07" checksum = "9d021fc044c18582b9a2408cd0dd05b1596e3ecdb5c4df822bb0183545683889"
dependencies = [ dependencies = [
"prettyplease", "prettyplease",
"proc-macro2", "proc-macro2",
"prost-build", "prost-build",
"quote", "quote",
"syn 1.0.109", "syn 2.0.32",
] ]
[[package]] [[package]]
@ -1633,7 +1551,7 @@ checksum = "0f57e3ca2a01450b1a921183a9c9cbfda207fd822cef4ccb00a65402cbba7a74"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.13", "syn 2.0.32",
] ]
[[package]] [[package]]
@ -1700,60 +1618,6 @@ version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd"
dependencies = [
"bumpalo",
"log",
"once_cell",
"proc-macro2",
"quote",
"syn 2.0.13",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.13",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
[[package]] [[package]]
name = "which" name = "which"
version = "4.4.0" version = "4.4.0"
@ -1765,28 +1629,6 @@ dependencies = [
"once_cell", "once_cell",
] ]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.48.0" version = "0.48.0"
@ -1869,36 +1711,51 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "804268e702b664fc09d3e2ce82786d0addf4ae57ba6976469be63e09066bf9f7" checksum = "804268e702b664fc09d3e2ce82786d0addf4ae57ba6976469be63e09066bf9f7"
dependencies = [ dependencies = [
"bech32 0.8.1", "bech32 0.8.1",
"bs58", "bs58 0.4.0",
"f4jumble",
"zcash_encoding",
]
[[package]]
name = "zcash_address"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bce173f1d9ed4f806e310bc3a873301531e7a6dc209928584d6404e3f8228ef4"
dependencies = [
"bech32 0.9.1",
"bs58 0.5.0",
"f4jumble", "f4jumble",
"zcash_encoding", "zcash_encoding",
] ]
[[package]] [[package]]
name = "zcash_client_backend" name = "zcash_client_backend"
version = "0.9.0" version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a55db8d2cb4ca82a71fa66ccd9fa5b211f5ab90c866721311ddd85f8f90d0701" checksum = "d6a382af39be9ee5a3788157145c404b7cd19acc440903f6c34b09fb44f0e991"
dependencies = [ dependencies = [
"base64", "base64",
"bech32 0.9.1", "bech32 0.9.1",
"bls12_381", "bls12_381",
"bs58", "bs58 0.5.0",
"crossbeam-channel", "crossbeam-channel",
"group", "group",
"hex",
"incrementalmerkletree",
"memuse", "memuse",
"nom", "nom",
"orchard", "orchard 0.6.0",
"percent-encoding", "percent-encoding",
"prost", "prost",
"rayon", "rayon",
"secrecy", "secrecy",
"shardtree",
"subtle", "subtle",
"time", "time",
"tonic-build", "tonic-build",
"tracing", "tracing",
"which", "which",
"zcash_address", "zcash_address 0.3.1",
"zcash_encoding", "zcash_encoding",
"zcash_note_encryption", "zcash_note_encryption",
"zcash_primitives", "zcash_primitives",
@ -1916,9 +1773,9 @@ dependencies = [
[[package]] [[package]]
name = "zcash_note_encryption" name = "zcash_note_encryption"
version = "0.3.0" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2eb2149e6cd5fbee36c5b87c601715a8c35554602f7fe84af38b636afa2db318" checksum = "5b4580cd6cee12e44421dac43169be8d23791650816bdb34e6ddfa70ac89c1c5"
dependencies = [ dependencies = [
"chacha20", "chacha20",
"chacha20poly1305", "chacha20poly1305",
@ -1929,9 +1786,9 @@ dependencies = [
[[package]] [[package]]
name = "zcash_primitives" name = "zcash_primitives"
version = "0.11.0" version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "914d2195a478d5b63191584dff126f552751115181857b290211ec88e68acc3e" checksum = "d17e4c94ca8d69d2fcf2be97522da5732a580eb2125cda3b150761952f8df8e6"
dependencies = [ dependencies = [
"aes", "aes",
"bip0039", "bip0039",
@ -1950,16 +1807,25 @@ dependencies = [
"lazy_static", "lazy_static",
"memuse", "memuse",
"nonempty", "nonempty",
"orchard", "orchard 0.6.0",
"rand", "rand",
"rand_core", "rand_core",
"sha2 0.10.6", "sha2 0.10.6",
"subtle", "subtle",
"zcash_address", "zcash_address 0.3.1",
"zcash_encoding", "zcash_encoding",
"zcash_note_encryption", "zcash_note_encryption",
] ]
[[package]]
name = "zcash_spec"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7a3bf58b673cb3dacd8ae09ba345998923a197ab0da70d6239d8e8838949e9b"
dependencies = [
"blake2b_simd",
]
[[package]] [[package]]
name = "zeroize" name = "zeroize"
version = "1.6.0" version = "1.6.0"
@ -1977,5 +1843,16 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.13", "syn 2.0.32",
]
[[package]]
name = "zip32"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d724a63be4dfb50b7f3617e542984e22e4b4a5b8ca5de91f55613152885e6b22"
dependencies = [
"blake2b_simd",
"memuse",
"subtle",
] ]

View file

@ -10,12 +10,14 @@ haskell-ffi.rev = "2bf292e2e56eac8e9fb0fb2e1450cf4a4bd01274"
f4jumble = "0.1" f4jumble = "0.1"
zcash_address = "0.2.0" zcash_address = "0.2.0"
borsh = "0.10" borsh = "0.10"
bech32 = "0.9.1" bech32 = "0.11"
orchard = "0.4.0" orchard = "0.7.0"
zcash_note_encryption = "0.3.0" zcash_note_encryption = "0.4.0"
zcash_primitives = "0.11.0" zcash_primitives = "0.13.0"
zcash_client_backend = "0.9.0" zcash_client_backend = "0.10.0"
zip32 = "0.1.0"
proc-macro2 = "1.0.66" proc-macro2 = "1.0.66"
nom = "7.1.3"
[features] [features]
capi = [] capi = []

View file

@ -8,7 +8,6 @@ use std::{
Write, Write,
Cursor Cursor
}, },
fmt::{Debug, Display, Formatter}
}; };
use f4jumble; use f4jumble;
@ -22,24 +21,19 @@ use haskell_ffi::{
FromHaskell, HaskellSize, ToHaskell FromHaskell, HaskellSize, ToHaskell
}; };
use zip32;
use zcash_primitives::{ use zcash_primitives::{
zip32::Scope as SaplingScope, zip32::Scope as SaplingScope,
zip339::{Count, Mnemonic}, zip339::{Count, Mnemonic},
transaction::components::sapling::{ transaction::components::sapling::{
read_zkproof,
GrothProofBytes, GrothProofBytes,
OutputDescription, OutputDescription,
CompactOutputDescription
}, },
sapling::{ sapling::{
value::ValueCommitment as SaplingValueCommitment,
keys::{
FullViewingKey as SaplingViewingKey,
PreparedIncomingViewingKey as SaplingPreparedIncomingViewingKey
},
note_encryption::SaplingDomain,
PaymentAddress, PaymentAddress,
note::ExtractedNoteCommitment as SaplingExtractedNoteCommitment keys::PreparedIncomingViewingKey as SaplingPreparedIncomingViewingKey,
note_encryption::SaplingDomain
}, },
transaction::Transaction, transaction::Transaction,
consensus::{ consensus::{
@ -55,27 +49,26 @@ use zcash_address::{
ZcashAddress ZcashAddress
}; };
use zcash_client_backend::keys::{sapling, sapling::ExtendedFullViewingKey}; use zcash_client_backend::keys::{
sapling,
sapling::ExtendedFullViewingKey,
sapling::ExtendedSpendingKey};
use zcash_primitives::zip32::AccountId; use zcash_primitives::zip32::AccountId;
use std::slice; use std::slice;
use orchard::{ use orchard::{
Action, Action,
keys::{FullViewingKey, PreparedIncomingViewingKey, Scope}, keys::{SpendingKey, FullViewingKey, PreparedIncomingViewingKey, Scope},
note::{Nullifier, TransmittedNoteCiphertext, ExtractedNoteCommitment}, note::{Nullifier, TransmittedNoteCiphertext, ExtractedNoteCommitment},
note_encryption::OrchardDomain, note_encryption::OrchardDomain,
primitives::redpallas::{VerificationKey, SpendAuth, Signature}, primitives::redpallas::{VerificationKey, SpendAuth, Signature},
value::ValueCommitment value::ValueCommitment
}; };
use zcash_note_encryption::EphemeralKeyBytes;
use bech32::{ use bech32::{
decode, Hrp,
u5, Bech32m
FromBase32,
ToBase32,
Variant
}; };
pub enum RW {} pub enum RW {}
@ -329,10 +322,10 @@ pub extern "C" fn rust_wrapper_bech32decode(
out_len: &mut usize out_len: &mut usize
) { ) {
let input: String = marshall_from_haskell_var(input, input_len, RW); let input: String = marshall_from_haskell_var(input, input_len, RW);
let decodedBytes = bech32::decode(&input); let decoded_bytes = bech32::decode(&input);
match decodedBytes { match decoded_bytes {
Ok((hrp, bytes, variant)) => { Ok((hrp, bytes)) => {
let rd = RawData {hrp: hrp.into(), bytes: Vec::<u8>::from_base32(&bytes).unwrap()}; let rd = RawData {hrp: hrp.as_bytes().to_vec(), bytes};
marshall_to_haskell_var(&rd, out, out_len, RW); marshall_to_haskell_var(&rd, out, out_len, RW);
} }
Err(_e) => { Err(_e) => {
@ -342,6 +335,22 @@ pub extern "C" fn rust_wrapper_bech32decode(
} }
} }
#[no_mangle]
pub extern "C" fn rust_wrapper_bech32_encode(
hr: *const u8,
hr_len: usize,
b: *const u8,
b_len: usize,
out: *mut u8,
out_len: &mut usize
) {
let hr: String = marshall_from_haskell_var(hr, hr_len, RW);
let hrp = Hrp::parse(&hr).unwrap();
let b: Vec<u8> = marshall_from_haskell_var(b, b_len, RW);
let string = bech32::encode::<Bech32m>(hrp, &b).unwrap();
marshall_to_haskell_var(&string, out, out_len, RW);
}
#[no_mangle] #[no_mangle]
pub extern "C" fn rust_wrapper_svk_decode( pub extern "C" fn rust_wrapper_svk_decode(
input: *const u8, input: *const u8,
@ -610,23 +619,46 @@ pub extern "C" fn rust_wrapper_recover_seed(
#[no_mangle] #[no_mangle]
pub extern "C" fn rust_wrapper_sapling_spendingkey( pub extern "C" fn rust_wrapper_sapling_spendingkey(
input: *const u8, iseed: *const u8,
input_len: usize, iseed_len: usize,
coin: u32, coin_type: u32,
acc_id: u32, acc_id: u32,
out: *mut u8, out: *mut u8,
out_len: &mut usize out_len: &mut usize
){ ){
let seed: Vec<u8> = marshall_from_haskell_var(input, input_len, RW); println!("From Rust\n=========");
let fake_response = "It's working"; let seed: Vec<u8> = marshall_from_haskell_var(iseed, iseed_len, RW);
marshall_to_haskell_var(&fake_response.as_bytes().to_vec(), out, out_len, RW); if ( seed.len() <= 0 ) {
// - Retrieve parameters println!("Seed error, returning a null vector...");
marshall_to_haskell_var(&vec![0], out, out_len, RW);
// let extsk = sapling::spending_key(&seed[0..32], } else {
// cointype, println!("Seed in rust : {:?}\n", seed);
// accountid); println!("Coin Type -> {}\nAccount Id -> {}",coin_type,acc_id);
// println!("SpendingKey -> {:?}", extsk); let su8 = &seed;
// let s = extsk.to_bytes(); let seedu8 : &[u8] = &su8;
// let xsk : Vec<u8> = s.iter().cloned().collect(); let extsk: ExtendedSpendingKey = sapling::ExtendedSpendingKey::master(&seedu8);
// marshall_to_haskell_var(&xsk, out, out_len, RW); let extsk_bytes = extsk.to_bytes().to_vec();
marshall_to_haskell_var(&extsk_bytes, out, out_len, RW);
}
}
#[no_mangle]
pub extern "C" fn rust_wrapper_derive_orchard_spending_key(
seed: *const u8,
seed_len: usize,
coin_type: u32,
acc_id: u32,
out: *mut u8,
out_len: &mut usize
){
let s: Vec<u8> = marshall_from_haskell_var(seed, seed_len, RW);
let sk = SpendingKey::from_zip32_seed(&s, coin_type, zip32::AccountId::try_from(acc_id).unwrap());
match sk {
Ok(key) => {
marshall_to_haskell_var(&key.to_bytes().to_vec(), out, out_len, RW);
},
Err(_e) => {
marshall_to_haskell_var(&vec![0], out, out_len, RW);
}
}
} }

View file

@ -38,6 +38,14 @@ import ZcashHaskell.Types
-> `()' -> `()'
#} #}
{# fun unsafe rust_wrapper_bech32_encode as rustWrapperBech32Encode
{ toBorshVar* `BS.ByteString'&
, toBorshVar* `BS.ByteString'&
, getVarBuffer `Buffer (T.Text)'&
}
-> `()'
#}
{# fun unsafe rust_wrapper_f4jumble as rustWrapperF4Jumble {# fun unsafe rust_wrapper_f4jumble as rustWrapperF4Jumble
{ toBorshVar* `BS.ByteString'& { toBorshVar* `BS.ByteString'&
, getVarBuffer `Buffer (BS.ByteString)'& , getVarBuffer `Buffer (BS.ByteString)'&
@ -128,8 +136,17 @@ import ZcashHaskell.Types
{# fun unsafe rust_wrapper_sapling_spendingkey as rustWrapperSaplingSpendingkey {# fun unsafe rust_wrapper_sapling_spendingkey as rustWrapperSaplingSpendingkey
{ toBorshVar* `BS.ByteString'& { toBorshVar* `BS.ByteString'&
, `Int' , `Word32'
, `Int' , `Word32'
, getVarBuffer `Buffer (BS.ByteString)'&
}
-> `()'
#}
{# fun unsafe rust_wrapper_derive_orchard_spending_key as rustWrapperGenOrchardSpendKey
{ toBorshVar* `BS.ByteString'&
, `Word32'
, `Word32'
, getVarBuffer `Buffer (BS.ByteString)'& , getVarBuffer `Buffer (BS.ByteString)'&
} }
-> `()' -> `()'

View file

@ -1,3 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}
-- Copyright 2022-2024 Vergara Technologies LLC -- Copyright 2022-2024 Vergara Technologies LLC
-- --
-- This file is part of Zcash-Haskell. -- This file is part of Zcash-Haskell.
@ -16,14 +18,34 @@
module ZcashHaskell.Orchard where module ZcashHaskell.Orchard where
import C.Zcash import C.Zcash
( rustWrapperOrchardCheck ( rustWrapperGenOrchardSpendKey
, rustWrapperOrchardCheck
, rustWrapperOrchardNoteDecode , rustWrapperOrchardNoteDecode
, rustWrapperUADecode , rustWrapperUADecode
, rustWrapperUfvkDecode , rustWrapperUfvkDecode
) )
import qualified Data.ByteString as BS import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as C
import qualified Data.Text as T
import qualified Data.Text.Encoding as E
import Data.Word
import Foreign.Rust.Marshall.Variable import Foreign.Rust.Marshall.Variable
import ZcashHaskell.Types import ZcashHaskell.Types
import ZcashHaskell.Utils (encodeBech32m, f4Jumble)
-- | Derives an Orchard spending key for the given seed and account ID
genOrchardSpendingKey :: Seed -> CoinType -> AccountId -> Maybe BS.ByteString
genOrchardSpendingKey s coinType accountId =
if BS.length k /= 32
then Nothing
else Just k
where
k =
withPureBorshVarBuffer $
rustWrapperGenOrchardSpendKey
s
(getValue coinType)
(fromIntegral accountId)
-- | 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
@ -49,6 +71,33 @@ isValidUnifiedAddress str =
then Just $ TransparentAddress P2SH whichNet (raw_to x) then Just $ TransparentAddress P2SH whichNet (raw_to x)
else Nothing) else Nothing)
-- | Encode a 'UnifiedAddress' per [ZIP-316](https://zips.z.cash/zip-0316)
encodeUnifiedAddress :: UnifiedAddress -> T.Text
encodeUnifiedAddress ua = encodeBech32m (E.encodeUtf8 hr) b
where
hr =
case ua_net ua of
MainNet -> "u"
TestNet -> "utest"
b = f4Jumble $ tReceiver <> sReceiver <> oReceiver <> padding
tReceiver =
case t_rec ua of
Nothing -> BS.empty
Just t ->
case ta_type t of
P2SH -> packReceiver 0x01 $ ta_bytes t
P2PKH -> packReceiver 0x00 $ ta_bytes t
sReceiver = packReceiver 0x02 $ s_rec ua
oReceiver = packReceiver 0x03 $ o_rec ua
padding = E.encodeUtf8 $ T.justifyLeft 16 '\NUL' hr
packReceiver :: Word8 -> BS.ByteString -> BS.ByteString
packReceiver typeCode receiver =
if BS.length receiver > 1
then BS.singleton typeCode `BS.append`
(BS.singleton . toEnum . BS.length) receiver `BS.append`
receiver
else BS.empty
-- | Attempts to decode the given bytestring into a Unified Full Viewing Key -- | Attempts to decode the given bytestring into a Unified Full Viewing Key
decodeUfvk :: BS.ByteString -> Maybe UnifiedFullViewingKey decodeUfvk :: BS.ByteString -> Maybe UnifiedFullViewingKey
decodeUfvk str = decodeUfvk str =

View file

@ -41,6 +41,8 @@ import ZcashHaskell.Types
, SaplingSKeyParams(..) , SaplingSKeyParams(..)
, ShieldedOutput(..) , ShieldedOutput(..)
, decodeHexText , decodeHexText
, AccountId
, CoinType
) )
import ZcashHaskell.Utils import ZcashHaskell.Utils
@ -88,14 +90,9 @@ instance FromJSON RawTxResponse where
Just o' -> do Just o' -> do
a <- o' .: "actions" a <- o' .: "actions"
pure $ RawTxResponse i h (getShieldedOutputs h) a ht c b pure $ RawTxResponse i h (getShieldedOutputs h) a ht c b
--
-- | Attempts to obtain a sapling SpendinKey using a HDSeed, a Coin Type and an Account ID -- | Attempts to obtain a sapling SpendinKey using a HDSeed, a Coin Type and an Account ID
genSaplingSpendingKey :: BS.ByteString -> Int -> Int -> Maybe BS.ByteString genSaplingSpendingKey :: BS.ByteString -> Word32-> AccountId -> BS.ByteString
genSaplingSpendingKey seed coin_type account_id = do genSaplingSpendingKey seed coin_type account_id = do
if BS.length res > 0 let res = withPureBorshVarBuffer (rustWrapperSaplingSpendingkey seed (fromIntegral coin_type) (fromIntegral account_id) )
then Just res res
else Nothing
where
res =
withPureBorshVarBuffer
(rustWrapperSaplingSpendingkey seed coin_type account_id)

View file

@ -61,6 +61,22 @@ data ZcashNet
| RegTestNet | RegTestNet
deriving (Eq, Prelude.Show, Read) deriving (Eq, Prelude.Show, Read)
type AccountId = Int
-- ** Constants
-- | Types for coin types on the different networks
data CoinType
= MainNetCoin
| TestNetCoin
| RegTestNetCoin
getValue :: CoinType -> Word32
getValue c =
case c of
MainNetCoin -> 133
TestNetCoin -> 1
RegTestNetCoin -> 1
-- * RPC -- * RPC
-- | A type to model Zcash RPC calls -- | A type to model Zcash RPC calls
data RpcCall = RpcCall data RpcCall = RpcCall
@ -186,12 +202,12 @@ data TransparentAddress = TransparentAddress
-- * Sapling -- * Sapling
-- | 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
{ s_cv :: HexString -- ^ Value commitment to the input note { s_cv :: !HexString -- ^ Value commitment to the input note
, s_cmu :: HexString -- ^ The u-coordinate of the note commitment for the output note , s_cmu :: !HexString -- ^ The u-coordinate of the note commitment for the output note
, s_ephKey :: HexString -- ^ Ephemeral Jubjub public key , s_ephKey :: !HexString -- ^ Ephemeral Jubjub public key
, s_encCipherText :: HexString -- ^ The output note encrypted to the recipient , s_encCipherText :: !HexString -- ^ The output note encrypted to the recipient
, s_outCipherText :: HexString -- ^ A ciphertext enabling the sender to recover the output note , s_outCipherText :: !HexString -- ^ A ciphertext enabling the sender to recover the output note
, s_proof :: HexString -- ^ Zero-knowledge proof using the Sapling Output circuit , s_proof :: !HexString -- ^ Zero-knowledge proof using the Sapling Output circuit
} deriving stock (Eq, Prelude.Show, GHC.Generic) } deriving stock (Eq, Prelude.Show, GHC.Generic)
deriving anyclass (SOP.Generic, SOP.HasDatatypeInfo) deriving anyclass (SOP.Generic, SOP.HasDatatypeInfo)
deriving anyclass (Data.Structured.Show) deriving anyclass (Data.Structured.Show)
@ -215,7 +231,7 @@ data UnifiedAddress = UnifiedAddress
, o_rec :: BS.ByteString , o_rec :: BS.ByteString
, s_rec :: BS.ByteString , s_rec :: BS.ByteString
, t_rec :: Maybe TransparentAddress , t_rec :: Maybe TransparentAddress
} deriving (Prelude.Show, Eq) } deriving (Prelude.Show, Eq, Read)
-- | Helper type for marshalling UAs -- | Helper type for marshalling UAs
data RawUA = RawUA data RawUA = RawUA

View file

@ -19,6 +19,7 @@ module ZcashHaskell.Utils where
import C.Zcash import C.Zcash
( rustWrapperBech32Decode ( rustWrapperBech32Decode
, rustWrapperBech32Encode
, rustWrapperF4Jumble , rustWrapperF4Jumble
, rustWrapperF4UnJumble , rustWrapperF4UnJumble
) )
@ -42,6 +43,10 @@ import Data.Word
decodeBech32 :: BS.ByteString -> RawData decodeBech32 :: BS.ByteString -> RawData
decodeBech32 = withPureBorshVarBuffer . rustWrapperBech32Decode decodeBech32 = withPureBorshVarBuffer . rustWrapperBech32Decode
-- | Encode the given Human Readable Part and bytestring as a Bech32m string
encodeBech32m :: BS.ByteString -> BS.ByteString -> T.Text
encodeBech32m h d = withPureBorshVarBuffer $ rustWrapperBech32Encode h d
-- | Apply the F4Jumble transformation to the given bytestring -- | Apply the F4Jumble transformation to the given bytestring
f4Jumble :: BS.ByteString -> BS.ByteString f4Jumble :: BS.ByteString -> BS.ByteString
f4Jumble = withPureBorshVarBuffer . rustWrapperF4Jumble f4Jumble = withPureBorshVarBuffer . rustWrapperF4Jumble

View file

@ -19,6 +19,7 @@
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
import C.Zcash (rustWrapperUADecode) import C.Zcash (rustWrapperUADecode)
import Control.Monad.IO.Class (liftIO)
import Data.Aeson import Data.Aeson
import Data.Bool (Bool(True)) import Data.Bool (Bool(True))
import qualified Data.ByteString as BS import qualified Data.ByteString as BS
@ -47,6 +48,7 @@ import ZcashHaskell.Transparent
--(encodeTransparent) --(encodeTransparent)
import ZcashHaskell.Types import ZcashHaskell.Types
( BlockResponse(..) ( BlockResponse(..)
, CoinType(..)
, DecodedNote(..) , DecodedNote(..)
, OrchardAction(..) , OrchardAction(..)
, RawData(..) , RawData(..)
@ -55,6 +57,9 @@ import ZcashHaskell.Types
, UnifiedAddress(..) , UnifiedAddress(..)
, UnifiedFullViewingKey(..) , UnifiedFullViewingKey(..)
, decodeHexText , decodeHexText
, AccountId
, CoinType
, getValue
) )
import ZcashHaskell.Utils import ZcashHaskell.Utils
@ -62,15 +67,22 @@ import Foreign.C.Types
import Data.Word import Data.Word
import Haskoin.Crypto.Keys.Extended import Haskoin.Crypto.Keys.Extended
m2bs :: Maybe BS.ByteString -> BS.ByteString
m2bs x = fromMaybe "" x
main :: IO () main :: IO ()
main = do main = do
hspec $ do hspec $ do
describe "Bech32" $ do describe "Bech32" $ do
let s = "bech321qqqsyrhqy2a" let s = "abc14w46h2at4w46h2at4w46h2at4w46h2at958ngu"
let decodedString = decodeBech32 s let decodedString = decodeBech32 s
it "hrp matches" $ do hrp decodedString `shouldBe` "bech32" it "hrp matches" $ do hrp decodedString `shouldBe` "abc"
it "data matches" $ do xit "data matches" $ do
bytes decodedString `shouldBe` BS.pack ([0x00, 0x01, 0x02] :: [Word8]) bytes decodedString `shouldBe` BS.pack ([0x00, 0x01, 0x02] :: [Word8])
it "encoding works" $ do
encodeBech32m "abc" (bytes decodedString) `shouldBe`
E.decodeUtf8Lenient s
describe "F4Jumble" $ do describe "F4Jumble" $ do
it "jumble a string" $ do it "jumble a string" $ do
let input = let input =
@ -343,6 +355,11 @@ main = do
let ua = let ua =
"u1salpdyefbreakingtheaddressh0h9v6qjr478k80amtkqkws5pr408lxt2953dpprvu06mahxt99cv65fgsm7sw8hlchplfg5pl89ur" "u1salpdyefbreakingtheaddressh0h9v6qjr478k80amtkqkws5pr408lxt2953dpprvu06mahxt99cv65fgsm7sw8hlchplfg5pl89ur"
isValidUnifiedAddress ua `shouldBe` Nothing isValidUnifiedAddress ua `shouldBe` Nothing
it "encodes UA correctly" $ do
let ua =
"u1salpdyefywvsg2dlmxg9589yznh0h9v6qjr478k80amtkqkws5pr408lxt2953dpprvu06mahxt99cv65fgsm7sw8hlchplfg5pl89ur"
(encodeUnifiedAddress <$> isValidUnifiedAddress ua) `shouldBe`
Just (E.decodeUtf8Lenient ua)
describe "Decode UVK from YWallet" $ do describe "Decode UVK from YWallet" $ do
let uvk = let uvk =
"uview1u833rp8yykd7h4druwht6xp6k8krle45fx8hqsw6vzw63n24atxpcatws82z092kryazuu6d7rayyut8m36wm4wpjy2z8r9hj48fx5pf49gw4sjrq8503qpz3vqj5hg0vg9vsqeasg5qjuyh94uyfm7v76udqcm2m0wfc25hcyqswcn56xxduq3xkgxkr0l73cjy88fdvf90eq5fda9g6x7yv7d0uckpevxg6540wc76xrc4axxvlt03ptaa2a0rektglmdy68656f3uzcdgqqyu0t7wk5cvwghyyvgqc0rp3vgu5ye4nd236ml57rjh083a2755qemf6dk6pw0qrnfm7246s8eg2hhzkzpf9h73chhng7xhmyem2sjh8rs2m9nhfcslsgenm" "uview1u833rp8yykd7h4druwht6xp6k8krle45fx8hqsw6vzw63n24atxpcatws82z092kryazuu6d7rayyut8m36wm4wpjy2z8r9hj48fx5pf49gw4sjrq8503qpz3vqj5hg0vg9vsqeasg5qjuyh94uyfm7v76udqcm2m0wfc25hcyqswcn56xxduq3xkgxkr0l73cjy88fdvf90eq5fda9g6x7yv7d0uckpevxg6540wc76xrc4axxvlt03ptaa2a0rektglmdy68656f3uzcdgqqyu0t7wk5cvwghyyvgqc0rp3vgu5ye4nd236ml57rjh083a2755qemf6dk6pw0qrnfm7246s8eg2hhzkzpf9h73chhng7xhmyem2sjh8rs2m9nhfcslsgenm"
@ -446,12 +463,16 @@ main = do
describe "Wallet seed phrase" $ do describe "Wallet seed phrase" $ do
it "Generate phrase" $ do it "Generate phrase" $ do
p <- generateWalletSeedPhrase p <- generateWalletSeedPhrase
print p
BS.length p `shouldNotBe` 0 BS.length p `shouldNotBe` 0
it "Derive seed" $ do it "Derive seed" $ do
p <- generateWalletSeedPhrase p <- generateWalletSeedPhrase
let s = getWalletSeed p let s = getWalletSeed p
maybe 0 BS.length s `shouldBe` 64 maybe 0 BS.length s `shouldBe` 64
it "Generate Orchard spending key" $ do
p <- generateWalletSeedPhrase
let s = getWalletSeed p
genOrchardSpendingKey (fromMaybe "" s) MainNetCoin 1 `shouldNotBe`
Nothing
describe "Address tests" $ do describe "Address tests" $ do
it "Encode transparent" $ do it "Encode transparent" $ do
let ua = let ua =
@ -510,7 +531,11 @@ main = do
241, 243, 172, 178, 241, 243, 172, 178,
104, 81, 159, 144 104, 81, 159, 144
] :: [Word8] ] :: [Word8]
let coin = 1 :: Word32 let cointype = getValue TestNetCoin
let account = 0 :: Word32 let account = 0 :: AccountId
res <- genSaplingSpendingKey (word8ArrayToByteString hdseed) coin account let msg = genSaplingSpendingKey (word8ArrayToByteString hdseed) cointype account
res `shouldBe` "genSaplingSpendingKey Function called." let msgArr = BS.unpack msg
if (length msgArr) == 169
then True
else False
-- msgArr `shouldBe` "It's working."

View file

@ -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.4.2.3 version: 0.4.3.0
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