Skip to content

Commit

Permalink
test: test
Browse files Browse the repository at this point in the history
  • Loading branch information
soralit committed Oct 14, 2024
1 parent 1c24b8a commit a809fdc
Show file tree
Hide file tree
Showing 11 changed files with 277 additions and 32 deletions.
103 changes: 93 additions & 10 deletions rust/apps/zcash/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions rust/apps/zcash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ edition = "2021"
third_party = { path = "../../third_party" }
keystore = { path = "../../keystore", default-features = false }
rust_tools = {path = "../../tools"}
app_utils = { path = "../../apps/utils" }
pczt = {path = "../../pczt"}

[dev-dependencies]
keystore = { path = "../../keystore" }
2 changes: 1 addition & 1 deletion rust/apps/zcash/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2023-06-26
nightly-2023-12-01
10 changes: 9 additions & 1 deletion rust/apps/zcash/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloc::string::String;
use alloc::string::{String, ToString};
use third_party::thiserror;
use thiserror::Error;

Expand All @@ -10,4 +10,12 @@ pub enum ZcashError {
GenerateAddressError(String),
#[error("invalid zcash data: {0}")]
InvalidDataError(String),
#[error("invalid pczt transaction data: {0}")]
InvalidPcztError(String),
}

impl From<pczt::protos::prost::DecodeError> for ZcashError {
fn from(value: pczt::protos::prost::DecodeError) -> Self {
ZcashError::InvalidPcztError(value.to_string())
}
}
12 changes: 11 additions & 1 deletion rust/apps/zcash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ extern crate alloc;

pub mod errors;

mod structs;

use errors::{Result, ZcashError};

use alloc::string::{String, ToString};
use keystore::algorithms::zcash::vendor::{
zcash_keys::keys::{UnifiedAddressRequest, UnifiedFullViewingKey},
zcash_protocol::consensus::MainNetwork,
};
use pczt::protos::{prost::Message, PartiallyCreatedTransaction};

pub fn get_address(ufvk_text: &str) -> Result<String> {
let ufvk = UnifiedFullViewingKey::decode(&MainNetwork, ufvk_text)
Expand All @@ -19,4 +22,11 @@ pub fn get_address(ufvk_text: &str) -> Result<String> {
.default_address(UnifiedAddressRequest::all().unwrap())
.map_err(|e| ZcashError::GenerateAddressError(e.to_string()))?;
Ok(address.encode(&MainNetwork))
}
}

pub fn sign_transaction(tx: &[u8], seed: &[u8]) -> Result<Vec<u8>> {
let mut transaction = tx.clone();
let pczt = PartiallyCreatedTransaction::decode(transaction)?;

}

41 changes: 41 additions & 0 deletions rust/apps/zcash/src/structs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use alloc::vec::Vec;
use app_utils::impl_internal_struct;

impl_internal_struct!(EnhancedPcztTransaction {
global: EnhancedPcztGlobal,
transparent: Option<EnhancedPcztTransparent>,
orchard: Option<EnhancedPcztOrchard>
});

impl_internal_struct!(EnhancedPcztGlobal {
tx_version: u32,
version_group_id: u32,
lock_time: u32,
expiry_height: u32,
consensus_branch_id: u32,
network_id: u32
});

impl_internal_struct!(EnhancedPcztTransparent {
inputs: Vec<EnhancedPcztTransparentInput>,
outputs: Vec<EnhancedPcztTransparentOutput>
});

impl_internal_struct!(EnhancedPcztTransparentInput {
pubkey: Vec<u8>,
coin: EnhancedPcztTransparentCoin,
out_point: EnhancedPcztTransparentOutput,
path: EnhancedPcztDerivationPath
});

impl_internal_struct!(EnhancedPcztTransparentOutput {});

impl_internal_struct!(EnhancedPcztTransparentCoin {});

impl_internal_struct!(EnhancedPcztDerivationPath {});

impl_internal_struct!(EnhancedPathComponent {});

impl_internal_struct!(EnhancedPcztTransparentOutpoint {});

impl_internal_struct!(EnhancedPcztOrchard {});
7 changes: 7 additions & 0 deletions rust/pczt/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions rust/pczt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ edition = "2021"

[dependencies]
prost = { version = "0.13", default-features = false }
prost-types = {version = "0.13", default-features = false}
prost-types = { version = "0.13", default-features = false }
hex = { version = "0.4.3", features = ["alloc"], default-features = false }

[build-dependencies]
prost-build = "0.13"

19 changes: 18 additions & 1 deletion rust/pczt/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
#![no_std]

pub mod protos;
pub mod protos;

#[cfg(test)]
mod tests {
use prost::{bytes::Bytes, Message};

use crate::protos;

extern crate std;
use std::println;

#[test]
fn test_decode() {
let buf = hex::decode("120d080520eda9a30128b4a1db960c2abe1708031098751a200237d46093546cc9552f3d4f3e1a362ca5ad859e49f774218720e027fe5dfc0322da070a2060a53b866c3f66db19b1e7b47deeb32ff8f4217367ca952fd3b25c7e01aab3091220dbc5ac858534dae14f363018765ce335dcc6cac6b6496cbf0250a0434978431c1a20c9a1696f2637512ff8e1f831e7bd3f063e54dc6b9a86367ffb18daea35bfe6252220899cc12429499093097e733ba747675e8b2c39b05adca9b4cf136c4ccfdc98092ac4048d22d1fbf8613824e11361060c13286c383ecb653d528ea6f608c51a11751b240f4ba0802e025785731fb990e129d2d5d15e8e1c692544538e33ef4a52bef94cf0e5da662596cb46117908afff98919431b96ddae7cbe0163c4f2e688663cb0ad8d9510e109712d2d588c1e534f6ca01e77a41c518d7e895e1c96d4491067d31264478d88bc06805a47cea7a3c3119a203bd90ae76c114ac1f6164fc381b5b4020f8a3f1b804bfc355b8e2b20563e4555c95895e6e08f848accfa87647943030b252343b88b06548c4905e7be609da7d35cc5c517abbd7378293f0c2281314349944f4d74decc906190aec6392e353ee8dc12b82fdeac18c35eb024807b94370b4925b3b8f6c841d0be101517320910d219082821f71c655dbaa8a0a3b7cd5c835dc06d91b775a6c3f4c3b64bb37579c678de6c6ebb517f61ddc4e8a54e5215f31ff393b6d532450868867f0f77fbede6b6e94623c6bcc6874e0f5b58eaad0c6a8323bd70ac3e390183f248ee5f63850605de1540aeaf23e2ec7751485141aba4482c23ebdf5b4b7d4585d85b3025c6a4e9144d5580bf44e5b76dfc23ae96ec235e903595883825c27febc75ca34e111de81789eeedaf71b162ffbb3505917b165eb5bdc549b0cf0211dc4ed2768762b7267b9e057ff03583e4618d21fc80f248a28779def11ba9de2e37bc688b2d9e2198be2a970bd0f402e92ec8501ac7e28b7566dccb1b7c0490f0d9cc56bd62d64662ea0c0d4a7181adf19588780b9fc7432f7e8581339c2815d5f4a086d8af1e08a86a413243d68eeb044d822349bf457fa2c171c3250c70406ba78e69cdcd0b8f760343c2adeb443d0946e76041af3d83dd1fde84f48ca533378b992e96d28aba5ae86660a38202867533fc2314829a439dd5ce21443126f04c65f2f34b8ea32c906d4c455183a20ae9c3d806702f966fbb15e2abfd598e9e6a66d2f5931cebabe257e06025f97a742206fb784ae4a661e16642d4dce88175fe05a386a8dd227b7800a168d9339a0e2194a73dbbe18b58ae8d241d42c87c6f84be0ca02a6c8a4cf8262e60961eaad0dcdcc122f2c0c7919487ee0ff35937de2e5d140274bf4079074bc3690844e4f9941d20199a66f4d2212d15f6b9ddf1d738b41226e3954130fee9e1654409d3eb52a82e0e18f62bb13bab4f37db929204e00000000000022da070a2061fef2fb3b1a55a3652c0c50e0b2652a2931f1df787af0531609948f8aa3ed391220f102970343e72dde8c1515987b6f6d958357d9508af232374c03bd3b3e67a6161a20b1d4b90ada6386ea978e189dba4cba7f09b08dcdb5fc786b1a5e13619ddb3e29222000d0dd19ce40cdf1e37fb1340b013fa4c220cf3d4a69ccd9bb2390ee9c01b02c2ac40447deb5008bc3bb0ec7a8e2fd5ebb2de1ba986c16b9d13ae6b5063b76b0b1cc5e91b2b435a5cd5a2396065da0bc6489d95c1c9dc0336d2738ce9dce56997f4efd466de0bf713613d3ea806b616ce7097ed35c5e8beb9dc0bfa8cbc71300750de6415a587a098733a79f0474fffb3dd5adcb4d1532b6f0b930f7ffa62d71730929258932def7a6de52689690bd4129c81d8c293dc4f2c0335fb3f82a09bdfa5ce9825952afb73931a3f84394b586610673bf8340ff328208006991f88252106dca285433853726d28a7defff808c9e0c077720b3057c4fcf428f4d817423e153f7b63a749dfe230b3bd0b9116cc0a2fbde78331079b06d732cd1db9e37d28f3c5d78a0b5b14a5fa82c5c492f2b0f61296f1783e19d90598dc719c12f02d2684cbe825239756c82b1f030b6a735bb324c39a4b871de58efccee79794f9124e7619aeb882367776db395c72e6956543c76818da88c1f485e6ac736d343a0c12d116550a3c99a3b8d3940cb52fe45f695f35aa6f7100746ef81a9b9b1d92a7739a98e039e3ad3579b8dc7d0bc4f9dc6670b42525c4bb9eb8747f287a12cf897204b9937616c33440e5164d25cb37b65723f0e5fda45700f6aadaf3571f7978f44c33d682413371316fcec5dcbc4a8a66100d4d3b3559c6acba26fb37e53e85ef2f47f49bb69917ffc0677e8d8d3f5a6a106919fd9678b26a89afd31681fc5407deadd373edc94d4ee78518988f56ad2e01a5c423c8869d21ffcacff34b11a6f9f7f8153de7b64cbfb2af42656807e9bf6baf4de49ace62118e9b19e2da896c1b8319520292c9b32502d5973747aec2a33962fb0831f79d1546f4a170a549097ce3f5d55b3ed1dadb97bb0ff2b8607e2aef74c86df94b999e72ced701c8b549c4c4c682787036a1b6667b3235436166844470811a64603f1613a2054b28d4577e5a8752c374dd70a76eaed8e68fa4c0a9b3ed63cd9b18092c7c48342209b30ac0738391bd8436585a345b54ea9624e8bb2f62e1dec4377e5749c333b204a73afa76f5b1c0f16a21383109cde6305b1456b0f989f233b86fdd6b5a39d9f722128a15c70670f0e97787c170485829264ecbf14bddeb68410f423e8849e0ce35c99a66f4d2212d15f6b9ddf1d738b41226e3954130fee9e1654409d3eb52a82e0e18f62bb13bab4f37db929204e00000000000022da070a2085430c5296b8d1b688be3554023a5c3e6cddc6a8784eb55c86cfa5bb72d8b41e12207f3da397c3217c3de9bdf0e85dbcc7c535299bf08df24fadc9805fbc0f1280191a203834818e842500d5df5cbe670773b35337f409eaf4246d1f42c8bfdf3e02ef0a2220882ad15469df27bca590f362d2d4d89e5bddf7515eb94d9dbfb0098954a69e932ac4043dca3887d9aa35df5c984a6c7a6890098aa00ec01ec17cefb4ad8d6faf56ea7f28f6e789f0b377f415a24ae735b014d6b66b3f0032f348dc52e4456c5e240d92c9e92a3d3fb5ec0eda52435f5088ff9cf1b9855b783253294f889efe57f8638156d6aa78e8f9309c31cab25e62ce49ea6a41b71df18e26c88455cd233c850b9c351ce2ab1dae7b4c5818d665dee6d415153179cc88f40dee5cec4e40b2d3d086421f11c5ce5c076238056bbcd4ffec106e33941e8c694b10b014811424bd0b49e28af22a9f5e98aa943443026efa37e5dd2ab94981fbf1f94f9df4beed6f12320a6b75c0c99d1f396c2ddc54c278cfe16c93dade3ece0fa13dafccdd307db401aa0872573ae2d165e3822eefa3f6a506e9e09396e668d4176c47c9692aec3d9dc79b51e20cf515f94b820eda8095014e0e71fd664ae3dfe0dca3acad5f8f6d1c4e0fdf334b6443b585e1fa3c07fd555fdc23f7ac11913400bc293a383353fb36d0f8fdea40c4aee25952e66d583efe587085857caa76daf9f899791a8e4837802d9d1678273e5dc916c7281ac3e02142f780389fe03558edcc3906457513a4dc1637ab530242b18e8276bbf810bc58c3ed9906e143e084b908c4408d2064b8da3ca4389e0649f332fa6771ed56fa41549607f9bbbac92ac4edff1aecece3303a0ae76e020fe10e91b562a69e4b84fcb2da5d20db9cfc795c3712191522035c9a82c20cb12ebd009b8f14418554976fc0de9008732566d4ca7a5fb4209fdce15a3ba4a3ab9dd3e2acf255c57e8200b3c90117a5c6b7197e1125482879b45c5c9532025f0832505148a307de8f211dacefacdc9759246627b71515a031b082eb77b7ce2753fd8ee4b97103c66b45bb8c75f39a658ae9d006348913eda89089d5202f5532a82bc776838228b467f741fb31efa770c278b03a20709e0c6578760b04b66139cb4a41c6b9d19dd863027a1fb4f40b332ef563f38d42203cab605bb688125d15ffb96482a5fa9e25ddc3642cccbd4d00aefee937b9970f4a7379f4a4d193cd9d5186435411c1bb274e3db69ccd8044f6cee4f1744a400e731137f15728e61d1fb2c8c839495e4890528c146d00fe2e1caec31b159fc42dcd7e93ec186ad03090232630c87a945267be26f172ca9e6c9bbdbf7f6da5d92f11135a9a75b1537d8d6544719c00a60e0000000000").unwrap();
let result = protos::PartiallyCreatedTransaction::decode(Bytes::from(buf)).unwrap();
println!("{:?}", result);
}
}
4 changes: 3 additions & 1 deletion rust/pczt/src/protos/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pub mod pczt;
pub use pczt::*;
pub use pczt::*;
pub use prost;
pub use prost_types;
Loading

0 comments on commit a809fdc

Please sign in to comment.