Skip to content

Commit ef1f803

Browse files
authored
Merge pull request #6 from solana-program/entity-name-updates
Entity name update follow ups
2 parents 0a6bdb0 + 460db61 commit ef1f803

11 files changed

Lines changed: 117 additions & 149 deletions

File tree

client/src/instruction.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
use {
22
alloc::vec,
33
solana_address::Address,
4-
solana_instruction::{AccountMeta, Instruction},
4+
solana_instruction::{AccountMeta, Instruction as SolanaInstruction},
55
solana_sdk_ids::sysvar::slot_hashes,
6-
spl_ed25519_programmatic_signer_interface::instruction::ProgrammaticSignerInstruction,
6+
spl_ed25519_programmatic_signer_interface::instruction::Instruction,
77
};
88

99
/// Creates an `Initialize` instruction.
10-
pub fn initialize(programmatic_signer_account: &Address, authority: &Address) -> Instruction {
11-
Instruction {
10+
pub fn initialize(signer_context: &Address, authority: &Address) -> SolanaInstruction {
11+
SolanaInstruction {
1212
program_id: spl_ed25519_programmatic_signer_interface::id(),
1313
accounts: vec![
14-
AccountMeta::new(*programmatic_signer_account, false),
14+
AccountMeta::new(*signer_context, false),
1515
AccountMeta::new_readonly(*authority, false),
1616
AccountMeta::new_readonly(slot_hashes::id(), false),
1717
],
18-
data: vec![ProgrammaticSignerInstruction::Initialize as u8],
18+
data: vec![Instruction::Initialize as u8],
1919
}
2020
}

interface/src/instruction.rs

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use {
88
#[repr(u8)]
99
#[derive(Clone, Copy, Debug, PartialEq, Eq, SchemaRead, SchemaWrite)]
1010
#[wincode(tag_encoding = "u8")]
11-
pub enum ProgrammaticSignerInstruction {
12-
/// Initializes a programmatic signer account for an authority.
11+
pub enum Instruction {
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,74 +18,74 @@ pub enum ProgrammaticSignerInstruction {
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" ‖ programmatic_signer_account_address ‖ slot_hashes[0])`.
22-
/// 3. Writes `ProgrammaticSignerAccount { 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]` Programmatic signer account
28-
/// - `[]` Authority to store in the programmatic signer account
27+
/// - `[writable]` Signer context account
28+
/// - `[]` Authority to store in the signer context account
2929
/// - `[]` `SlotHashes` sysvar
3030
Initialize,
3131

3232
/// Authorizes and executes a wrapped Solana transaction whose required signers are
33-
/// `ProgrammaticSignerPda` accounts.
33+
/// `ProgrammaticSigner` accounts.
3434
///
3535
/// Instruction data: instruction discriminator followed by a serialized
3636
/// `solana_transaction::versioned::VersionedTransaction`.
3737
/// All message variants supported by `VersionedTransaction` are accepted.
3838
///
3939
/// Wrapped required signers are paired by index:
40-
/// - `message.account_keys[i]`: `ProgrammaticSignerPda` promoted during CPI.
40+
/// - `message.account_keys[i]`: `ProgrammaticSigner` promoted during CPI.
4141
/// - `tx.signatures[i]`: wrapped-message signature from the matching authority address.
4242
///
4343
/// On success, the program:
4444
/// 1. Deserializes the transaction and sanitizes the wrapped message.
45-
/// 2. Reads the authority stored in the programmatic signer account.
46-
/// 3. Checks the passed programmatic signer 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`.
5050
/// 6. Iterates over the outer authority accounts in order. For each `authority_i`, requires
51-
/// `ProgrammaticSignerPda(authority_i) == message.account_keys[i]` and verifies
51+
/// `ProgrammaticSigner(authority_i) == message.account_keys[i]` and verifies
5252
/// `tx.signatures[i]` over the wrapped message with `authority_i`.
5353
/// 7. Executes each `message.instructions` entry by CPI, using `invoke_signed` to promote
54-
/// each authorized signer's corresponding `ProgrammaticSignerPda`.
54+
/// each authorized signer's corresponding `ProgrammaticSigner`.
5555
/// 8. Derives and stores the next nonce as
56-
/// `sha256("spl-ed25519-programmatic-signer::v1" ‖ programmatic_signer_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]` Programmatic signer 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 programmatic signer 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
///
7171
/// Runs only as an inner instruction of a wrapped transaction submitted through `Submit`
72-
/// because nothing outside this program can sign for `ProgrammaticSignerPda`.
72+
/// because nothing outside this program can sign for `ProgrammaticSigner`.
7373
///
7474
/// Accounts required:
75-
/// - `[signer]` `ProgrammaticSignerPda`
76-
/// - `[writable]` Programmatic signer account
75+
/// - `[signer]` `ProgrammaticSigner`
76+
/// - `[writable]` Signer context account
7777
/// - `[writable]` Lamport recipient
7878
Close,
7979
}
8080

81-
/// Data for [`ProgrammaticSignerInstruction::Close`].
81+
/// 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 programmatic signer account.
84+
/// Address that receives all lamports from the closed signer context account.
8585
pub recipient: Address,
8686
}
8787

88-
impl ProgrammaticSignerInstruction {
88+
impl Instruction {
8989
#[inline(always)]
9090
pub fn try_from_bytes(instruction_data: &[u8]) -> Result<Self, ProgramError> {
9191
wincode::deserialize_exact(instruction_data)
@@ -95,30 +95,24 @@ impl ProgrammaticSignerInstruction {
9595

9696
#[cfg(test)]
9797
mod tests {
98-
use super::ProgrammaticSignerInstruction;
98+
use super::Instruction;
9999

100-
fn instruction_bytes(instruction: ProgrammaticSignerInstruction) -> [u8; 1] {
100+
fn instruction_bytes(instruction: Instruction) -> [u8; 1] {
101101
let mut bytes = [0];
102102
wincode::serialize_into(bytes.as_mut_slice(), &instruction).unwrap();
103103
bytes
104104
}
105105

106106
#[test]
107107
fn instruction_tags_match_wire_format() {
108-
assert_eq!(
109-
instruction_bytes(ProgrammaticSignerInstruction::Initialize),
110-
[0]
111-
);
112-
assert_eq!(
113-
instruction_bytes(ProgrammaticSignerInstruction::Submit),
114-
[1]
115-
);
116-
assert_eq!(instruction_bytes(ProgrammaticSignerInstruction::Close), [2]);
108+
assert_eq!(instruction_bytes(Instruction::Initialize), [0]);
109+
assert_eq!(instruction_bytes(Instruction::Submit), [1]);
110+
assert_eq!(instruction_bytes(Instruction::Close), [2]);
117111
}
118112

119113
#[test]
120114
fn try_from_bytes_rejects_unknown() {
121-
assert!(ProgrammaticSignerInstruction::try_from_bytes(&[4]).is_err());
122-
assert!(ProgrammaticSignerInstruction::try_from_bytes(&[255]).is_err());
115+
assert!(Instruction::try_from_bytes(&[4]).is_err());
116+
assert!(Instruction::try_from_bytes(&[255]).is_err());
123117
}
124118
}

interface/src/pda.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
use solana_address::Address;
22

3-
/// Programmatic signer PDA.
3+
/// Programmatic signer.
44
///
55
/// Program-owned runtime signer for an authority. `Submit` promotes it to `is_signer=true`
66
/// via `invoke_signed` wherever a wrapped instruction references it after the corresponding
77
/// authority has signed the wrapped message.
88
///
99
/// Seeds: `["programmatic-signer", authority, bump]`
10-
pub struct ProgrammaticSignerPda;
10+
pub struct ProgrammaticSigner;
1111

12-
impl ProgrammaticSignerPda {
12+
impl ProgrammaticSigner {
1313
pub const SEED_PREFIX: &[u8] = b"programmatic-signer";
1414

1515
#[inline(always)]
1616
pub fn derive_address_and_bump(program_id: &Address, authority: &Address) -> (Address, u8) {
1717
Address::derive_program_address(&[Self::SEED_PREFIX, authority.as_ref()], program_id)
18-
.expect("failed to derive ProgrammaticSignerPda from authority")
18+
.expect("failed to derive ProgrammaticSigner from authority")
1919
}
2020

2121
#[inline(always)]

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 programmatic signer account.
15+
/// On-chain data for a caller-created signer context account.
1616
///
17-
/// One authority can control any number of independent programmatic signer 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 programmatic signer account.
20+
/// transactions prepared against another signer context account.
2121
#[derive(Clone, Debug, PartialEq, Eq, SchemaRead, SchemaWrite)]
22-
pub struct ProgrammaticSignerAccount {
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 ProgrammaticSignerAccount {
3131
pub authority: Address,
3232
}
3333

34-
impl ProgrammaticSignerAccount {
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, ProgrammaticSignerAccount};
74+
use super::{Address, Hash, SignerContext};
7575

7676
#[test]
7777
fn len_matches_wincode_serialized_size() {
78-
let account = ProgrammaticSignerAccount {
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-
ProgrammaticSignerAccount::LEN
85+
SignerContext::LEN
8686
);
8787
}
8888
}

program/src/initialize.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +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, ProgrammaticSignerAccount,
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 [`ProgrammaticSignerAccount`]
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 [
17-
programmatic_signer_account,
18-
authority,
19-
slot_hashes_account,
20-
..,
21-
] = accounts
22-
else {
14+
let [signer_context, authority, slot_hashes_account, ..] = accounts else {
2315
return Err(ProgramError::NotEnoughAccountKeys);
2416
};
2517

2618
// Caller must ensure account is pre-created with authority set to the program
27-
if !programmatic_signer_account.owned_by(program_id) {
19+
if !signer_context.owned_by(program_id) {
2820
return Err(ProgramError::IllegalOwner);
2921
}
3022

3123
// Ensure's the precise length matches the layout
32-
if programmatic_signer_account.data_len() != ProgrammaticSignerAccount::LEN {
24+
if signer_context.data_len() != SignerContext::LEN {
3325
return Err(ProgramError::InvalidAccountData);
3426
}
3527

3628
// A fresh account is zero-filled. Any nonzero byte means it is already initialized.
37-
let data = programmatic_signer_account.try_borrow()?;
29+
let data = signer_context.try_borrow()?;
3830
if data.iter().any(|byte| *byte != 0) {
3931
return Err(ProgramError::AccountAlreadyInitialized);
4032
}
4133
drop(data);
4234

43-
let rent_required = Rent::get()?.try_minimum_balance(ProgrammaticSignerAccount::LEN)?;
44-
if programmatic_signer_account.lamports() < rent_required {
35+
let rent_required = Rent::get()?.try_minimum_balance(SignerContext::LEN)?;
36+
if signer_context.lamports() < rent_required {
4537
return Err(ProgramError::AccountNotRentExempt);
4638
}
4739

@@ -56,18 +48,18 @@ pub fn process_initialize(program_id: &Address, accounts: &mut [AccountView]) ->
5648
// can never equal an advanced one.
5749
INIT_NONCE_DERIVATION_TAG,
5850
// so multiple accounts initialized in the same slot don't share the same nonce
59-
programmatic_signer_account.address().as_ref(),
51+
signer_context.address().as_ref(),
6052
// chain entropy the caller can't choose
6153
&recent_entry.hash,
6254
]);
6355

64-
let state = ProgrammaticSignerAccount {
56+
let state = SignerContext {
6557
nonce: initial_nonce,
6658
authority: Address::from(authority.address()),
6759
};
6860

6961
// Write data into the account
70-
let mut data = programmatic_signer_account.try_borrow_mut()?;
62+
let mut data = signer_context.try_borrow_mut()?;
7163
wincode::serialize_into(&mut *data, &state)
7264
.map_err(|_| ProgramError::InvalidInstructionData)?;
7365

program/src/processor.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use {
22
crate::initialize::process_initialize,
33
pinocchio::{AccountView, Address, ProgramResult},
4-
spl_ed25519_programmatic_signer_interface::instruction::ProgrammaticSignerInstruction,
4+
spl_ed25519_programmatic_signer_interface::instruction::Instruction,
55
};
66

77
#[inline(always)]
@@ -10,10 +10,8 @@ pub fn process_instruction(
1010
accounts: &mut [AccountView],
1111
instruction_data: &[u8],
1212
) -> ProgramResult {
13-
match ProgrammaticSignerInstruction::try_from_bytes(instruction_data)? {
14-
ProgrammaticSignerInstruction::Initialize => process_initialize(program_id, accounts),
15-
ProgrammaticSignerInstruction::Submit | ProgrammaticSignerInstruction::Close => {
16-
unimplemented!()
17-
}
13+
match Instruction::try_from_bytes(instruction_data)? {
14+
Instruction::Initialize => process_initialize(program_id, accounts),
15+
Instruction::Submit | Instruction::Close => unimplemented!(),
1816
}
1917
}

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::ProgrammaticSignerAccount,
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) -> ProgrammaticSignerAccount {
13+
pub fn decode_state(account: &Account) -> SignerContext {
1414
wincode::deserialize_exact(&account.data).unwrap()
1515
}

0 commit comments

Comments
 (0)