winterwallet_common/lib.rs
1#![cfg_attr(any(target_os = "solana", target_arch = "bpf"), no_std)]
2
3//! Shared constants, discriminators, domain tags, and account state layout
4//! for the WinterWallet program. Used by both the on-chain program and
5//! off-chain clients to eliminate constant drift.
6
7use solana_address::declare_id;
8
9declare_id!("winter5vMwvf51xrSVPTxbAAD6qiSTmPeRTSizMCQCa");
10
11// ── Winternitz parameters ────────────────────────────────────────────
12
13/// Number of Winternitz message scalars (N). Total scalars = N + 2.
14pub const WINTERNITZ_SCALARS: usize = 22;
15
16/// Total scalars including the two checksum scalars.
17pub const TOTAL_SCALARS: usize = WINTERNITZ_SCALARS + 2;
18
19/// Signature byte length: `(N + 2) * 32`.
20pub const SIGNATURE_LEN: usize = TOTAL_SCALARS * 32;
21
22// ── Domain tags ──────────────────────────────────────────────────────
23
24/// Domain tag for the Initialize preimage.
25pub const WINTERWALLET_INITIALIZE: &[u8] = b"WINTERWALLET_INITIALIZE";
26
27/// Domain tag for the Advance preimage.
28pub const WINTERWALLET_ADVANCE: &[u8] = b"WINTERWALLET_ADVANCE";
29
30// ── PDA ──────────────────────────────────────────────────────────────
31
32/// PDA seed prefix.
33pub const WINTERWALLET_SEED: &[u8] = b"winterwallet";
34
35// ── Instruction discriminators ───────────────────────────────────────
36
37/// Instruction discriminator bytes matching the on-chain `match` arms.
38pub mod discriminator {
39 /// Initialize a new WinterWallet.
40 pub const INITIALIZE: u8 = 0;
41 /// Advance the wallet root and execute inner CPIs.
42 pub const ADVANCE: u8 = 1;
43 /// Withdraw lamports (inner CPI via Advance).
44 pub const WITHDRAW: u8 = 2;
45 /// Close the wallet, sweeping all lamports to a receiver (inner CPI via Advance).
46 pub const CLOSE: u8 = 3;
47}
48
49// ── Advance limits ───────────────────────────────────────────────────
50
51/// Upper bound on trailing accounts an Advance instruction can commit to.
52/// Sizes the stack-allocated signature-preimage buffer used during recovery.
53pub const MAX_PASSTHROUGH_ACCOUNTS: usize = 128;
54
55/// Upper bound on account metas per inner CPI'd instruction inside Advance.
56pub const MAX_CPI_INSTRUCTION_ACCOUNTS: usize = 16;
57
58// ── Account state layout ─────────────────────────────────────────────
59
60/// On-chain WinterWallet account data length: `id(32) + root(32) + bump(1)`.
61pub const WALLET_ACCOUNT_LEN: usize = 65;
62
63/// Byte offset of the `id` field in the WinterWallet account.
64pub const WALLET_ID_OFFSET: usize = 0;
65/// Byte offset of the `root` field in the WinterWallet account.
66pub const WALLET_ROOT_OFFSET: usize = 32;
67/// Byte offset of the `bump` field in the WinterWallet account.
68pub const WALLET_BUMP_OFFSET: usize = 64;