winterwallet_client/preimage.rs
1use winterwallet_common::{WINTERWALLET_ADVANCE, WINTERWALLET_INITIALIZE};
2
3/// Build the preimage parts for an Initialize signature.
4///
5/// The program signs over just the domain tag. The wallet ID is *recovered*
6/// from the signature (not committed in the preimage) — the signer's
7/// identity IS the wallet ID.
8pub fn initialize_preimage() -> [&'static [u8]; 1] {
9 [WINTERWALLET_INITIALIZE]
10}
11
12/// Build the preimage parts for an Advance signature.
13///
14/// Must match `program/src/instructions/advance.rs:verify_signature` exactly.
15///
16/// The `account_addresses` MUST be in the same order as the passthrough
17/// accounts in the Advance instruction's account list. Use
18/// [`crate::encode_advance`] to produce both the payload and account list
19/// atomically, then extract addresses from those account metas.
20pub fn advance_preimage<'a>(
21 id: &'a [u8; 32],
22 current_root: &'a [u8; 32],
23 new_root: &'a [u8; 32],
24 account_addresses: &'a [[u8; 32]],
25 payload: &'a [u8],
26) -> Vec<&'a [u8]> {
27 let mut parts = Vec::with_capacity(5 + account_addresses.len());
28 parts.push(WINTERWALLET_ADVANCE as &[u8]);
29 parts.push(id.as_slice());
30 parts.push(current_root.as_slice());
31 parts.push(new_root.as_slice());
32 for addr in account_addresses {
33 parts.push(addr.as_slice());
34 }
35 parts.push(payload);
36 parts
37}