Skip to content

Commit 460db61

Browse files
committed
rename to SignerContext
1 parent b255655 commit 460db61

9 files changed

Lines changed: 89 additions & 101 deletions

File tree

client/src/instruction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use {
77
};
88

99
/// Creates an `Initialize` instruction.
10-
pub fn initialize(signer_nonce_account: &Address, authority: &Address) -> SolanaInstruction {
10+
pub fn initialize(signer_context: &Address, authority: &Address) -> SolanaInstruction {
1111
SolanaInstruction {
1212
program_id: spl_ed25519_programmatic_signer_interface::id(),
1313
accounts: vec![
14-
AccountMeta::new(*signer_nonce_account, false),
14+
AccountMeta::new(*signer_context, false),
1515
AccountMeta::new_readonly(*authority, false),
1616
AccountMeta::new_readonly(slot_hashes::id(), false),
1717
],

interface/src/instruction.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use {
99
#[derive(Clone, Copy, Debug, PartialEq, Eq, SchemaRead, SchemaWrite)]
1010
#[wincode(tag_encoding = "u8")]
1111
pub enum Instruction {
12-
/// Initializes a signer nonce account for an authority.
12+
/// Initializes a signer context account for an authority.
1313
///
1414
/// The caller must first create and fund the account. Recommended to include
1515
/// `solana_system_interface::instruction::create_account` and `Initialize` in the same
@@ -18,14 +18,14 @@ pub enum Instruction {
1818
/// On success, the program:
1919
/// 1. Verifies the account is uninitialized, rent-exempt, and owned by this program.
2020
/// 2. Derives the initial `nonce` as
21-
/// `sha256("spl-ed25519-programmatic-signer::init-v1" ‖ signer_nonce_account_address ‖ slot_hashes[0])`.
22-
/// 3. Writes `SignerNonceAccount { nonce, authority }` into the account data.
21+
/// `sha256("spl-ed25519-programmatic-signer::init-v1" ‖ signer_context_address ‖ slot_hashes[0])`.
22+
/// 3. Writes `SignerContext { nonce, authority }` into the account data.
2323
///
2424
/// Instruction data: instruction discriminator only
2525
///
2626
/// Accounts required:
27-
/// - `[writable]` Signer nonce account
28-
/// - `[]` Authority to store in the signer nonce account
27+
/// - `[writable]` Signer context account
28+
/// - `[]` Authority to store in the signer context account
2929
/// - `[]` `SlotHashes` sysvar
3030
Initialize,
3131

@@ -42,8 +42,8 @@ pub enum Instruction {
4242
///
4343
/// On success, the program:
4444
/// 1. Deserializes the transaction and sanitizes the wrapped message.
45-
/// 2. Reads the authority stored in the signer nonce account.
46-
/// 3. Checks the passed signer nonce account's authority signed the wrapped message.
45+
/// 2. Reads the authority stored in the signer context account.
46+
/// 3. Checks the passed signer context account's authority signed the wrapped message.
4747
/// 4. Checks the wrapped message's lifetime / recent blockhash field equals the account's
4848
/// `nonce`.
4949
/// 5. Verifies the outer transaction's only top-level instruction is `Submit`.
@@ -53,18 +53,18 @@ pub enum Instruction {
5353
/// 7. Executes each `message.instructions` entry by CPI, using `invoke_signed` to promote
5454
/// each authorized signer's corresponding `ProgrammaticSigner`.
5555
/// 8. Derives and stores the next nonce as
56-
/// `sha256("spl-ed25519-programmatic-signer::v1" ‖ signer_nonce_account ‖ old_nonce ‖ slot_hashes[0] ‖ sha256(signed_message_bytes))`
56+
/// `sha256("spl-ed25519-programmatic-signer::v1" ‖ signer_context ‖ old_nonce ‖ slot_hashes[0] ‖ sha256(signed_message_bytes))`
5757
///
5858
/// Accounts required:
59-
/// - `[writable]` Signer nonce account whose nonce is consumed and advanced
59+
/// - `[writable]` Signer context account whose nonce is consumed and advanced
6060
/// - `[]` `SlotHashes` sysvar
6161
/// - `[]` `Instructions` sysvar
6262
/// - Authority addresses, ordered to match the wrapped message's required signers.
6363
/// - Remaining accounts referenced by the wrapped message, in order. Writable flags
6464
/// must match the wrapped message.
6565
Submit,
6666

67-
/// Closes a signer nonce account and refunds its lamports.
67+
/// Closes a signer context account and refunds its lamports.
6868
///
6969
/// Instruction data: instruction discriminator followed by [`CloseData`].
7070
///
@@ -73,15 +73,15 @@ pub enum Instruction {
7373
///
7474
/// Accounts required:
7575
/// - `[signer]` `ProgrammaticSigner`
76-
/// - `[writable]` Signer nonce account
76+
/// - `[writable]` Signer context account
7777
/// - `[writable]` Lamport recipient
7878
Close,
7979
}
8080

8181
/// Data for [`Instruction::Close`].
8282
#[derive(Clone, Debug, PartialEq, Eq, SchemaRead, SchemaWrite)]
8383
pub struct CloseData {
84-
/// Address that receives all lamports from the closed signer nonce account.
84+
/// Address that receives all lamports from the closed signer context account.
8585
pub recipient: Address,
8686
}
8787

interface/src/state.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ use {
1212
/// Tag for the initial nonce derivation.
1313
pub const INIT_NONCE_DERIVATION_TAG: &[u8] = b"spl-ed25519-programmatic-signer::init-v1";
1414

15-
/// On-chain data for a caller-created signer nonce account.
15+
/// On-chain data for a caller-created signer context account.
1616
///
17-
/// One authority can control any number of independent signer nonce accounts. This is useful for
17+
/// One authority can control any number of independent signer context accounts. This is useful for
1818
/// when that authority wants to prepare or submit more than one transaction concurrently. Each
1919
/// account carries its own nonce, so consuming one nonce does not advance or invalidate
20-
/// transactions prepared against another signer nonce account.
20+
/// transactions prepared against another signer context account.
2121
#[derive(Clone, Debug, PartialEq, Eq, SchemaRead, SchemaWrite)]
22-
pub struct SignerNonceAccount {
22+
pub struct SignerContext {
2323
/// Single-use value that prevents a signed message from being replayed. `Submit` requires this
2424
/// to match the wrapped message's lifetime field: `lifetime_specifier` for `v1` messages or
2525
/// `recent_blockhash` for `legacy` and `v0` messages. On success, `Submit` advances it to a
@@ -31,7 +31,7 @@ pub struct SignerNonceAccount {
3131
pub authority: Address,
3232
}
3333

34-
impl SignerNonceAccount {
34+
impl SignerContext {
3535
/// Serialized account size: a 32-byte nonce followed by a 32-byte authority address.
3636
pub const LEN: usize = HASH_BYTES + ADDRESS_BYTES;
3737
}
@@ -71,18 +71,18 @@ unsafe impl<'de, C: Config> SchemaRead<'de, C> for HashBytes {
7171

7272
#[cfg(test)]
7373
mod tests {
74-
use super::{Address, Hash, SignerNonceAccount};
74+
use super::{Address, Hash, SignerContext};
7575

7676
#[test]
7777
fn len_matches_wincode_serialized_size() {
78-
let account = SignerNonceAccount {
78+
let account = SignerContext {
7979
nonce: Hash::new_from_array([1; 32]),
8080
authority: Address::new_from_array([2; 32]),
8181
};
8282

8383
assert_eq!(
8484
wincode::serialized_size(&account).unwrap() as usize,
85-
SignerNonceAccount::LEN
85+
SignerContext::LEN
8686
);
8787
}
8888
}

program/src/initialize.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,36 @@ use {
44
error::ProgramError,
55
sysvars::{Sysvar, rent::Rent, slot_hashes::SlotHashes},
66
},
7-
spl_ed25519_programmatic_signer_interface::state::{
8-
INIT_NONCE_DERIVATION_TAG, SignerNonceAccount,
9-
},
7+
spl_ed25519_programmatic_signer_interface::state::{INIT_NONCE_DERIVATION_TAG, SignerContext},
108
};
119

12-
/// Turns a caller-created, program-owned account into a [`SignerNonceAccount`]
10+
/// Turns a caller-created, program-owned account into a [`SignerContext`]
1311
/// bound to `authority` with a fresh nonce.
1412
#[inline(always)]
1513
pub fn process_initialize(program_id: &Address, accounts: &mut [AccountView]) -> ProgramResult {
16-
let [signer_nonce_account, authority, slot_hashes_account, ..] = accounts else {
14+
let [signer_context, authority, slot_hashes_account, ..] = accounts else {
1715
return Err(ProgramError::NotEnoughAccountKeys);
1816
};
1917

2018
// Caller must ensure account is pre-created with authority set to the program
21-
if !signer_nonce_account.owned_by(program_id) {
19+
if !signer_context.owned_by(program_id) {
2220
return Err(ProgramError::IllegalOwner);
2321
}
2422

2523
// Ensure's the precise length matches the layout
26-
if signer_nonce_account.data_len() != SignerNonceAccount::LEN {
24+
if signer_context.data_len() != SignerContext::LEN {
2725
return Err(ProgramError::InvalidAccountData);
2826
}
2927

3028
// A fresh account is zero-filled. Any nonzero byte means it is already initialized.
31-
let data = signer_nonce_account.try_borrow()?;
29+
let data = signer_context.try_borrow()?;
3230
if data.iter().any(|byte| *byte != 0) {
3331
return Err(ProgramError::AccountAlreadyInitialized);
3432
}
3533
drop(data);
3634

37-
let rent_required = Rent::get()?.try_minimum_balance(SignerNonceAccount::LEN)?;
38-
if signer_nonce_account.lamports() < rent_required {
35+
let rent_required = Rent::get()?.try_minimum_balance(SignerContext::LEN)?;
36+
if signer_context.lamports() < rent_required {
3937
return Err(ProgramError::AccountNotRentExempt);
4038
}
4139

@@ -50,18 +48,18 @@ pub fn process_initialize(program_id: &Address, accounts: &mut [AccountView]) ->
5048
// can never equal an advanced one.
5149
INIT_NONCE_DERIVATION_TAG,
5250
// so multiple accounts initialized in the same slot don't share the same nonce
53-
signer_nonce_account.address().as_ref(),
51+
signer_context.address().as_ref(),
5452
// chain entropy the caller can't choose
5553
&recent_entry.hash,
5654
]);
5755

58-
let state = SignerNonceAccount {
56+
let state = SignerContext {
5957
nonce: initial_nonce,
6058
authority: Address::from(authority.address()),
6159
};
6260

6361
// Write data into the account
64-
let mut data = signer_nonce_account.try_borrow_mut()?;
62+
let mut data = signer_context.try_borrow_mut()?;
6563
wincode::serialize_into(&mut *data, &state)
6664
.map_err(|_| ProgramError::InvalidInstructionData)?;
6765

program/tests/helpers/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use {
22
mollusk_svm::Mollusk, solana_account::Account,
3-
spl_ed25519_programmatic_signer_interface::state::SignerNonceAccount,
3+
spl_ed25519_programmatic_signer_interface::state::SignerContext,
44
};
55

66
pub fn init_mollusk() -> Mollusk {
@@ -10,6 +10,6 @@ pub fn init_mollusk() -> Mollusk {
1010
)
1111
}
1212

13-
pub fn decode_state(account: &Account) -> SignerNonceAccount {
13+
pub fn decode_state(account: &Account) -> SignerContext {
1414
wincode::deserialize_exact(&account.data).unwrap()
1515
}

program/tests/helpers/initialize_builder.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use {
2-
crate::helpers::{common::init_mollusk, signer_account_builder::SignerNonceAccountBuilder},
2+
crate::helpers::{common::init_mollusk, signer_context_builder::SignerContextBuilder},
33
mollusk_svm::{
44
Mollusk,
55
result::{Check, InstructionResult},
@@ -11,7 +11,7 @@ use {
1111

1212
pub struct InitializeBuilder<'a> {
1313
mollusk: Mollusk,
14-
signer_nonce_account: Option<(Address, Account)>,
14+
signer_context: Option<(Address, Account)>,
1515
authority_address: Option<Address>,
1616
instruction_data: Option<Vec<u8>>,
1717
checks: Vec<Check<'a>>,
@@ -21,7 +21,7 @@ impl Default for InitializeBuilder<'_> {
2121
fn default() -> Self {
2222
Self {
2323
mollusk: init_mollusk(),
24-
signer_nonce_account: None,
24+
signer_context: None,
2525
authority_address: None,
2626
instruction_data: None,
2727
checks: vec![],
@@ -30,8 +30,8 @@ impl Default for InitializeBuilder<'_> {
3030
}
3131

3232
impl<'a> InitializeBuilder<'a> {
33-
pub fn signer_nonce_account(mut self, signer_nonce_account: (Address, Account)) -> Self {
34-
self.signer_nonce_account = Some(signer_nonce_account);
33+
pub fn signer_context(mut self, signer_context: (Address, Account)) -> Self {
34+
self.signer_context = Some(signer_context);
3535
self
3636
}
3737

@@ -51,21 +51,21 @@ impl<'a> InitializeBuilder<'a> {
5151
}
5252

5353
pub fn execute(mut self) -> InstructionResult {
54-
let signer_nonce_account = self
55-
.signer_nonce_account
56-
.unwrap_or_else(|| SignerNonceAccountBuilder::default().build());
54+
let signer_context = self
55+
.signer_context
56+
.unwrap_or_else(|| SignerContextBuilder::default().build());
5757
let authority_address = self
5858
.authority_address
5959
.unwrap_or_else(|| Address::from([2; 32]));
6060
let slot_hashes = self.mollusk.sysvars.keyed_account_for_slot_hashes_sysvar();
6161

62-
let mut instruction = initialize(&signer_nonce_account.0, &authority_address);
62+
let mut instruction = initialize(&signer_context.0, &authority_address);
6363
if let Some(instruction_data) = self.instruction_data {
6464
instruction.data = instruction_data;
6565
}
6666

6767
let accounts = vec![
68-
signer_nonce_account,
68+
signer_context,
6969
(authority_address, Account::default()),
7070
slot_hashes,
7171
];

program/tests/helpers/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pub mod common;
22
pub mod initialize_builder;
3-
pub mod signer_account_builder;
3+
pub mod signer_context_builder;

program/tests/helpers/signer_account_builder.rs renamed to program/tests/helpers/signer_context_builder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use {
22
solana_account::Account, solana_address::Address, solana_rent::Rent,
3-
spl_ed25519_programmatic_signer_interface::state::SignerNonceAccount,
3+
spl_ed25519_programmatic_signer_interface::state::SignerContext,
44
};
55

6-
pub struct SignerNonceAccountBuilder {
6+
pub struct SignerContextBuilder {
77
key: Address,
88
owner: Address,
99
lamports: Option<u64>,
1010
data: Option<Vec<u8>>,
1111
}
1212

13-
impl Default for SignerNonceAccountBuilder {
13+
impl Default for SignerContextBuilder {
1414
fn default() -> Self {
1515
Self {
1616
key: Address::from([1; 32]),
@@ -21,7 +21,7 @@ impl Default for SignerNonceAccountBuilder {
2121
}
2222
}
2323

24-
impl SignerNonceAccountBuilder {
24+
impl SignerContextBuilder {
2525
pub fn new() -> Self {
2626
Self::default()
2727
}
@@ -50,7 +50,7 @@ impl SignerNonceAccountBuilder {
5050
let data = self
5151
.data
5252
// Default to program-owned, zero-filled account (waiting to be initialized)
53-
.unwrap_or_else(|| vec![0; SignerNonceAccount::LEN]);
53+
.unwrap_or_else(|| vec![0; SignerContext::LEN]);
5454
let lamports = self
5555
.lamports
5656
.unwrap_or_else(|| Rent::default().minimum_balance(data.len()));

0 commit comments

Comments
 (0)