Skip to main content

molpha_verifier/
state.rs

1//! Plain, framework-agnostic inputs to signer resolution.
2//!
3//! The canonical Molpha registry **account** types (`RegistryState`, `Node`) live in the
4//! downstream program — they are framework-specific (Anchor `#[account]`, Pinocchio, …). This crate
5//! only needs the handful of plain fields the resolver reads, so callers pass a [`RegistryView`] and
6//! a slice of already-parsed [`NodeEntry`]s.
7
8/// Sentinel index for a removed/virtual registry slot (mirrors the program constant).
9pub const VIRTUAL_INDEX: u32 = u32::MAX;
10
11/// The kind of the registry's most recent membership transition.
12///
13/// Used by signer resolution to remap previous-version node indices during the grace window.
14#[derive(Clone, Copy, PartialEq, Eq, Debug)]
15pub enum RegistryTransitionType {
16    None,
17    Add,
18    RemoveTail,
19    RemoveSwap,
20}
21
22/// Plain view of the registry fields needed to resolve and order signers.
23///
24/// The caller builds this from its own registry account (whatever framework it uses).
25#[derive(Clone, Copy, Debug)]
26pub struct RegistryView {
27    pub current_version: u32,
28    pub previous_version: u32,
29    pub previous_expires_at: i64,
30    pub current_node_count: u32,
31    pub previous_node_count: u32,
32    pub last_transition_type: RegistryTransitionType,
33    pub removed_old_index: u32,
34    pub moved_old_index: u32,
35}
36
37impl RegistryView {
38    /// Whether the last transition removed a node (tail removal or swap removal).
39    pub fn is_remove_transition(&self) -> bool {
40        matches!(
41            self.last_transition_type,
42            RegistryTransitionType::RemoveTail | RegistryTransitionType::RemoveSwap
43        )
44    }
45}
46
47/// A single signer's registry entry, already parsed and owner-checked by the caller.
48///
49/// `x` / `y` are the node's secp256k1 public-key affine coordinates (big-endian), as stored in the
50/// program's `Node` account.
51#[derive(Clone, Copy, Debug)]
52pub struct NodeEntry {
53    pub index: u32,
54    pub x: [u8; 32],
55    pub y: [u8; 32],
56}