From 64a8ea5807d356343ae896edcb32d630a49b9277 Mon Sep 17 00:00:00 2001 From: Sergio Chouhy Date: Fri, 1 May 2026 00:49:28 -0300 Subject: [PATCH] add privateaccountkind --- nssa/core/src/encryption/mod.rs | 30 +++++++++++++++++++++++++++++- nssa/core/src/lib.rs | 2 +- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/nssa/core/src/encryption/mod.rs b/nssa/core/src/encryption/mod.rs index 80d62f30..a190d691 100644 --- a/nssa/core/src/encryption/mod.rs +++ b/nssa/core/src/encryption/mod.rs @@ -8,12 +8,40 @@ use serde::{Deserialize, Serialize}; #[cfg(feature = "host")] pub use shared_key_derivation::{EphemeralPublicKey, EphemeralSecretKey, ViewingPublicKey}; -use crate::{Commitment, Identifier, account::Account}; +use crate::{ + Commitment, Identifier, + account::Account, + program::{PdaSeed, ProgramId}, +}; #[cfg(feature = "host")] pub mod shared_key_derivation; pub type Scalar = [u8; 32]; +/// Discriminates the type of private account a ciphertext belongs to, carrying the data needed +/// to reconstruct the account's [`AccountId`] on the receiver side. +/// +/// [`AccountId`]: crate::account::AccountId +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum PrivateAccountKind { + Account(Identifier), + Pda { + program_id: ProgramId, + seed: PdaSeed, + identifier: Identifier, + }, +} + +impl PrivateAccountKind { + #[must_use] + pub fn identifier(&self) -> Identifier { + match self { + Self::Account(identifier) => *identifier, + Self::Pda { identifier, .. } => *identifier, + } + } +} + #[derive(Serialize, Deserialize, Clone, Copy)] pub struct SharedSecretKey(pub [u8; 32]); diff --git a/nssa/core/src/lib.rs b/nssa/core/src/lib.rs index 478d475c..7c585373 100644 --- a/nssa/core/src/lib.rs +++ b/nssa/core/src/lib.rs @@ -8,7 +8,7 @@ pub use commitment::{ Commitment, CommitmentSetDigest, DUMMY_COMMITMENT, DUMMY_COMMITMENT_HASH, MembershipProof, compute_digest_for_path, }; -pub use encryption::{EncryptionScheme, SharedSecretKey}; +pub use encryption::{EncryptionScheme, PrivateAccountKind, SharedSecretKey}; pub use nullifier::{Identifier, Nullifier, NullifierPublicKey, NullifierSecretKey}; pub mod account;