Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions src/issuance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ use crate::issuance::Error::{
use crate::keys::{IssuanceAuthorizingKey, IssuanceValidatingKey};
use crate::note::asset_id::is_asset_desc_of_valid_size;
use crate::note::{AssetId, Nullifier};
use crate::primitives::redpallas::Signature;
use crate::value::NoteValue;
use crate::{
primitives::redpallas::{self, SpendAuth},
Address, Note,
};

/// A bundle of actions to be applied to the ledger.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct IssueBundle<T: IssueAuth> {
/// The issuer key for the note being created.
ik: IssuanceValidatingKey,
Expand Down Expand Up @@ -106,20 +107,20 @@ impl IssueAction {
}

/// Defines the authorization type of an Issue bundle.
pub trait IssueAuth: fmt::Debug {}
pub trait IssueAuth: fmt::Debug + Clone {}

/// Marker for an unauthorized bundle with no proofs or signatures.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Unauthorized;

/// Marker for an unauthorized bundle with injected sighash.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Prepared {
sighash: [u8; 32],
}

/// Marker for an authorized bundle.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Signed {
signature: redpallas::Signature<SpendAuth>,
}
Expand All @@ -129,6 +130,11 @@ impl Signed {
pub fn signature(&self) -> &redpallas::Signature<SpendAuth> {
&self.signature
}

/// Constructs an `Signed` from its constituent parts.
pub fn from_parts(signature: Signature<SpendAuth>) -> Self {
Signed { signature }
}
}

impl IssueAuth for Unauthorized {}
Expand Down Expand Up @@ -176,6 +182,19 @@ impl<T: IssueAuth> IssueBundle<T> {
pub fn commitment(&self) -> IssueBundleCommitment {
IssueBundleCommitment(hash_issue_bundle_txid_data(self))
}

/// Constructs an `IssueBundle` from its constituent parts.
pub fn from_parts(
ik: IssuanceValidatingKey,
actions: Vec<IssueAction>,
authorization: T,
) -> Self {
IssueBundle {
ik,
actions,
authorization,
}
}
}

impl IssueBundle<Unauthorized> {
Expand Down
2 changes: 1 addition & 1 deletion src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl Eq for IssuanceValidatingKey {}
impl IssuanceValidatingKey {
/// Converts this spend validating key to its serialized form,
/// I2LEOSP_256(ik).
pub(crate) fn to_bytes(&self) -> [u8; 32] {
pub fn to_bytes(&self) -> [u8; 32] {
// This is correct because the wrapped point must have ỹ = 0, and
// so the point repr is the same as I2LEOSP of its x-coordinate.
<[u8; 32]>::from(&self.0)
Expand Down