Merge pull request #1659 from zcash/zcash_transparent_no_std

Implement `no_std` support for `zcash_transparent`
This commit is contained in:
Jack Grigg 2024-12-16 20:27:47 +13:00 committed by GitHub
commit efd8176b7c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 41 additions and 17 deletions

1
Cargo.lock generated
View File

@ -6452,6 +6452,7 @@ dependencies = [
"blake2b_simd",
"bs58",
"byteorder",
"core2",
"document-features",
"getset",
"hex",

View File

@ -18,6 +18,7 @@ zcash_address.workspace = true
zcash_encoding.workspace = true
zcash_protocol.workspace = true
zip32.workspace = true
core2.workspace = true
# Dependencies exposed in a public API:
# (Breaking upgrades to these require a breaking upgrade to this crate.)

View File

@ -1,12 +1,14 @@
//! Support for legacy transparent addresses and scripts.
use byteorder::{ReadBytesExt, WriteBytesExt};
use alloc::string::String;
use alloc::vec::Vec;
use core::fmt;
use core::ops::Shl;
use core2::io::{self, Read, Write};
use zcash_address::TryFromRawAddress;
use std::fmt;
use std::io::{self, Read, Write};
use std::ops::Shl;
use zcash_encoding::Vector;
/// Defined script opcodes.

View File

@ -1,7 +1,8 @@
//! Types and functions for building transparent transaction components.
use std::collections::BTreeMap;
use std::fmt;
use alloc::collections::BTreeMap;
use alloc::vec::Vec;
use core::fmt;
use zcash_protocol::value::{BalanceError, ZatBalance as Amount, Zatoshis as NonNegativeAmount};
@ -287,7 +288,7 @@ impl TxIn<Unauthorized> {
TxIn {
prevout,
script_sig: (),
sequence: std::u32::MAX,
sequence: u32::MAX,
}
}
}
@ -362,7 +363,7 @@ impl Bundle<Unauthorized> {
});
#[cfg(not(feature = "transparent-inputs"))]
let script_sigs = std::iter::empty::<Result<Script, Error>>();
let script_sigs = core::iter::empty::<Result<Script, Error>>();
Ok(Bundle {
vin: self

View File

@ -1,12 +1,15 @@
//! Structs representing the components within Zcash transactions.
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use zcash_protocol::TxId;
use std::fmt::Debug;
use std::io::{self, Read, Write};
use alloc::vec::Vec;
use core::fmt::Debug;
use core2::io::{self, Read, Write};
use zcash_protocol::value::{BalanceError, ZatBalance as Amount, Zatoshis as NonNegativeAmount};
use zcash_protocol::{
value::{BalanceError, ZatBalance as Amount, Zatoshis as NonNegativeAmount},
TxId,
};
use crate::{
address::{Script, TransparentAddress},

View File

@ -1,5 +1,7 @@
//! Transparent key components.
use alloc::string::ToString;
use alloc::vec::Vec;
use bip32::{
ChildNumber, ExtendedKey, ExtendedKeyAttrs, ExtendedPrivateKey, ExtendedPublicKey, Prefix,
};
@ -341,7 +343,7 @@ pub(crate) mod private {
///
/// [BIP32]: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
/// [BIP44]: https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
pub trait IncomingViewingKey: private::SealedChangeLevelKey + std::marker::Sized {
pub trait IncomingViewingKey: private::SealedChangeLevelKey + core::marker::Sized {
/// Derives a transparent address at the provided child index.
#[allow(deprecated)]
fn derive_address(

View File

@ -1,5 +1,7 @@
//! # Zcash transparent protocol
#![no_std]
pub mod address;
pub mod builder;
pub mod bundle;
@ -8,3 +10,6 @@ pub mod sighash;
#[cfg(feature = "transparent-inputs")]
pub mod keys;
#[macro_use]
extern crate alloc;

View File

@ -1,6 +1,8 @@
//! PCZT support for transparent Zcash.
use std::collections::BTreeMap;
use alloc::collections::BTreeMap;
use alloc::string::String;
use alloc::vec::Vec;
use bip32::ChildNumber;
use getset::Getters;

View File

@ -1,4 +1,6 @@
use std::collections::BTreeMap;
use alloc::collections::BTreeMap;
use alloc::string::String;
use alloc::vec::Vec;
use bip32::ChildNumber;
use zcash_protocol::{value::Zatoshis, TxId};

View File

@ -1,4 +1,5 @@
use crate::sighash::SignableInput;
use alloc::vec::Vec;
impl super::Input {
/// Signs the transparent spend with the given spend authorizing key.

View File

@ -1,3 +1,4 @@
use alloc::vec::Vec;
use zcash_protocol::value::Zatoshis;
use crate::{
@ -57,7 +58,7 @@ impl super::Bundle {
Ok(TxIn {
prevout,
script_sig: script_sig(input)?,
sequence: input.sequence.unwrap_or(std::u32::MAX),
sequence: input.sequence.unwrap_or(u32::MAX),
})
})
.collect::<Result<Vec<_>, E>>()?;

View File

@ -1,3 +1,5 @@
use alloc::string::String;
use alloc::vec::Vec;
use ripemd::Ripemd160;
use sha2::{Digest, Sha256};

View File

@ -1,3 +1,4 @@
use alloc::vec::Vec;
use getset::Getters;
use zcash_protocol::value::Zatoshis;