From 90596a941fdeb5803d11c91da362db1a79b7fd37 Mon Sep 17 00:00:00 2001 From: soralit Date: Wed, 9 Oct 2024 16:48:37 +0800 Subject: [PATCH] feat: add pczt build --- rust/pczt/build.rs | 4 + rust/pczt/src/lib.rs | 15 +-- rust/pczt/src/pb/pczt.rs | 167 ++++++++++++++++++++++++++++++++ rust/pczt/src/protos/pczt.proto | 2 + rust/rust_c/Cargo.lock | 4 +- 5 files changed, 178 insertions(+), 14 deletions(-) create mode 100644 rust/pczt/build.rs create mode 100644 rust/pczt/src/pb/pczt.rs diff --git a/rust/pczt/build.rs b/rust/pczt/build.rs new file mode 100644 index 000000000..257ea8d40 --- /dev/null +++ b/rust/pczt/build.rs @@ -0,0 +1,4 @@ +fn main() -> Result<(), std::io::Error> { + prost_build::Config::new().out_dir("src/pb").compile_protos(&["src/protos/pczt.proto"], &["src/"])?; + Ok(()) +} diff --git a/rust/pczt/src/lib.rs b/rust/pczt/src/lib.rs index 7d12d9af8..f73d222b4 100644 --- a/rust/pczt/src/lib.rs +++ b/rust/pczt/src/lib.rs @@ -1,14 +1,5 @@ -pub fn add(left: usize, right: usize) -> usize { - left + right -} - -#[cfg(test)] -mod tests { - use super::*; +#![no_std] - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } +pub mod protos { + include!("pb/pczt.rs"); } diff --git a/rust/pczt/src/pb/pczt.rs b/rust/pczt/src/pb/pczt.rs new file mode 100644 index 000000000..04180369c --- /dev/null +++ b/rust/pczt/src/pb/pczt.rs @@ -0,0 +1,167 @@ +// This file is @generated by prost-build. +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PartiallyCreatedTransaction { + /// The version of this wire format, for storage. + #[prost(uint32, tag = "1")] + pub proto_version: u32, + #[prost(message, optional, tag = "2")] + pub global: ::core::option::Option, + #[prost(message, optional, tag = "3")] + pub transparent: ::core::option::Option, + #[prost(message, optional, tag = "4")] + pub sapling: ::core::option::Option, + #[prost(message, optional, tag = "5")] + pub orchard: ::core::option::Option, +} +#[derive(Clone, Copy, PartialEq, ::prost::Message)] +pub struct PcztGlobal { + #[prost(uint32, tag = "1")] + pub tx_version: u32, + /// is versionGroupId still needed? + #[prost(fixed32, tag = "2")] + pub version_group_id: u32, + #[prost(uint32, tag = "3")] + pub lock_time: u32, + #[prost(uint32, tag = "4")] + pub expiry_height: u32, + #[prost(uint32, tag = "5")] + pub consensus_branch_id: u32, + #[prost(uint32, tag = "6")] + pub network_id: u32, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PcztTransparent { + #[prost(message, repeated, tag = "1")] + pub inputs: ::prost::alloc::vec::Vec, + #[prost(message, repeated, tag = "2")] + pub outputs: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PcztTransparentInput { + #[prost(bytes = "vec", tag = "1")] + pub pubkey: ::prost::alloc::vec::Vec, + #[prost(message, optional, tag = "2")] + pub previous_coin: ::core::option::Option, + #[prost(message, optional, tag = "3")] + pub previous_outpoint: ::core::option::Option, + #[prost(message, optional, tag = "4")] + pub path: ::core::option::Option, + #[prost(bytes = "vec", repeated, tag = "5")] + pub signatures: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec>, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PcztTransparentCoin { + #[prost(uint64, tag = "1")] + pub value: u64, + #[prost(bytes = "vec", tag = "2")] + pub script_pubkey: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PcztTransparentOutput { + #[prost(message, optional, tag = "1")] + pub coin: ::core::option::Option, + /// if an output has path, it is a change output + #[prost(message, optional, tag = "2")] + pub path: ::core::option::Option, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PcztTransparentOutpoint { + #[prost(bytes = "vec", tag = "1")] + pub tx_hash: ::prost::alloc::vec::Vec, + #[prost(uint32, tag = "2")] + pub index: u32, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PcztDerivationPath { + /// the 32 bytes seed fingerprint; + #[prost(bytes = "vec", tag = "1")] + pub seed_fingerprint: ::prost::alloc::vec::Vec, + /// for orchard it should be pk_d(DiversifiedTransmissionKey) + /// hardware wallet should check this with the derived key from it self. + #[prost(bytes = "vec", tag = "2")] + pub pubkey: ::prost::alloc::vec::Vec, + #[prost(message, repeated, tag = "3")] + pub path_components: ::prost::alloc::vec::Vec, +} +#[derive(Clone, Copy, PartialEq, ::prost::Message)] +pub struct PathComponent { + #[prost(uint32, tag = "1")] + pub value: u32, + #[prost(bool, tag = "2")] + pub harden: bool, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PcztOrchard { + #[prost(uint32, tag = "1")] + pub flag: u32, + #[prost(int64, tag = "2")] + pub value_balance: i64, + #[prost(bytes = "vec", tag = "3")] + pub anchor: ::prost::alloc::vec::Vec, + #[prost(message, repeated, tag = "4")] + pub actions: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PcztOrchardAction { + #[prost(bytes = "vec", tag = "1")] + pub nf: ::prost::alloc::vec::Vec, + #[prost(bytes = "vec", tag = "2")] + pub rk: ::prost::alloc::vec::Vec, + #[prost(bytes = "vec", tag = "3")] + pub cmx: ::prost::alloc::vec::Vec, + /// (epk, enc_ciphertext, out_ciphertext) + #[prost(bytes = "vec", tag = "4")] + pub encrypted_note: ::prost::alloc::vec::Vec, + #[prost(bytes = "vec", tag = "5")] + pub cv_net: ::prost::alloc::vec::Vec, + #[prost(bytes = "vec", tag = "6")] + pub alpha: ::prost::alloc::vec::Vec, + /// the serilized spend note(rho, rseed, value, receipent) of this action, to verify the nf and cmx in this action. + #[prost(bytes = "vec", tag = "7")] + pub spend_note: ::prost::alloc::vec::Vec, + #[prost(message, optional, tag = "8")] + pub path: ::core::option::Option, + #[prost(bytes = "vec", repeated, tag = "9")] + pub signatures: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec>, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PcztSapling { + #[prost(int64, tag = "1")] + pub value_balance: i64, + #[prost(message, repeated, tag = "2")] + pub spends: ::prost::alloc::vec::Vec, + #[prost(message, repeated, tag = "3")] + pub outputs: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PcztSaplingSpend { + #[prost(bytes = "vec", tag = "1")] + pub nf: ::prost::alloc::vec::Vec, + #[prost(bytes = "vec", tag = "2")] + pub cv: ::prost::alloc::vec::Vec, + #[prost(bytes = "vec", tag = "3")] + pub rk: ::prost::alloc::vec::Vec, + #[prost(bytes = "vec", tag = "4")] + pub proof: ::prost::alloc::vec::Vec, + #[prost(bytes = "vec", tag = "5")] + pub anchor: ::prost::alloc::vec::Vec, + #[prost(bytes = "vec", tag = "6")] + pub alpha: ::prost::alloc::vec::Vec, + #[prost(message, optional, tag = "7")] + pub path: ::core::option::Option, + #[prost(bytes = "vec", repeated, tag = "8")] + pub signatures: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec>, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PcztSaplingOutput { + #[prost(bytes = "vec", tag = "1")] + pub cv: ::prost::alloc::vec::Vec, + #[prost(bytes = "vec", tag = "2")] + pub cmu: ::prost::alloc::vec::Vec, + /// (epk, enc_ciphertext, out_ciphertext) + #[prost(bytes = "vec", tag = "3")] + pub encrypted_note: ::prost::alloc::vec::Vec, + /// if an output has path, it is a change output + #[prost(message, optional, tag = "4")] + pub path: ::core::option::Option, +} diff --git a/rust/pczt/src/protos/pczt.proto b/rust/pczt/src/protos/pczt.proto index cb6914aea..ca0b48a76 100644 --- a/rust/pczt/src/protos/pczt.proto +++ b/rust/pczt/src/protos/pczt.proto @@ -1,5 +1,7 @@ syntax = "proto3"; +package pczt; + message PartiallyCreatedTransaction { // The version of this wire format, for storage. uint32 protoVersion = 1; diff --git a/rust/rust_c/Cargo.lock b/rust/rust_c/Cargo.lock index 05084e7f5..c8f12d27d 100644 --- a/rust/rust_c/Cargo.lock +++ b/rust/rust_c/Cargo.lock @@ -3278,7 +3278,7 @@ dependencies = [ [[package]] name = "ur-parse-lib" version = "0.2.0" -source = "git+https://git@github.com/KeystoneHQ/keystone-sdk-rust.git?tag=0.0.36-alpha0#2996f57ad2fce0132cfc0258a3981749d1bf9969" +source = "git+https://git@github.com/KeystoneHQ/keystone-sdk-rust.git?tag=zcash-alpha.0#2996f57ad2fce0132cfc0258a3981749d1bf9969" dependencies = [ "hex", "ur", @@ -3288,7 +3288,7 @@ dependencies = [ [[package]] name = "ur-registry" version = "0.1.0" -source = "git+https://git@github.com/KeystoneHQ/keystone-sdk-rust.git?tag=0.0.36-alpha0#2996f57ad2fce0132cfc0258a3981749d1bf9969" +source = "git+https://git@github.com/KeystoneHQ/keystone-sdk-rust.git?tag=zcash-alpha.0#2996f57ad2fce0132cfc0258a3981749d1bf9969" dependencies = [ "bs58 0.4.0", "core2",