GPT: сгенерено и не проверено (смена ключей пользователя)

This commit is contained in:
AidarKC
2026-09-27 15:50:27 +03:00
parent 13693a0a53
commit 151a2c1754
94 changed files with 5327 additions and 815 deletions
@@ -90,6 +90,7 @@ enum ShineUsersError {
CannotCloseCurrentFormat = 37,
RootChangeRequiresRoot = 38,
AmbiguousAuthorityRotation = 39,
RootModeRequiresFullRotation = 40,
}
impl From<ShineUsersError> for ProgramError {
@@ -619,15 +620,20 @@ fn process_update_user_pda(program_id: &Pubkey, accounts: &[AccountInfo], args:
require!(args.auth_mode == AUTH_MODE_BLOCKCHAIN || args.auth_mode == AUTH_MODE_ROOT, ShineUsersError::InvalidInstruction);
let root_changed = args.root_key != old_record.root_key;
if args.auth_mode == AUTH_MODE_BLOCKCHAIN {
require!(!root_changed, ShineUsersError::RootChangeRequiresRoot);
}
if root_changed && args.new_blockchain_key.is_some() {
return Err(ProgramError::from(ShineUsersError::AmbiguousAuthorityRotation));
let client_changed = args.client_key != old_record.client_key;
let full_key_rotation = root_changed && client_changed && args.new_blockchain_key.is_some();
// root/client меняются только вместе с созданием нового blockchain fork.
// Обычные update и обычный fork всегда авторизуются текущим blockchain key.
if root_changed || client_changed {
require!(full_key_rotation, ShineUsersError::AmbiguousAuthorityRotation);
require!(args.auth_mode == AUTH_MODE_ROOT, ShineUsersError::RootChangeRequiresRoot);
} else {
require!(args.auth_mode == AUTH_MODE_BLOCKCHAIN, ShineUsersError::RootModeRequiresFullRotation);
}
let old_active_key = old_record.active_fork()?.blockchain_key;
let old_authority = if args.auth_mode == AUTH_MODE_ROOT { old_record.root_key } else { old_active_key };
let old_authority = if full_key_rotation { old_record.root_key } else { old_active_key };
let mut forks = old_record.forks.clone();
let additional_limit_u32 = u32::try_from(args.additional_limit).map_err(|_| ProgramError::from(ShineUsersError::PaidLimitTooLarge))?;
@@ -636,7 +642,7 @@ fn process_update_user_pda(program_id: &Pubkey, accounts: &[AccountInfo], args:
for fork in &forks {
require!(fork.blockchain_key != new_key, ShineUsersError::DuplicateBlockchainKey);
}
if args.auth_mode == AUTH_MODE_BLOCKCHAIN {
if !full_key_rotation {
enforce_fork_cooldown(old_record.active_fork()?.created_at_ms, args.updated_at_ms)?;
}
@@ -664,12 +670,8 @@ fn process_update_user_pda(program_id: &Pubkey, accounts: &[AccountInfo], args:
signature: [0; 64],
};
let record_signer = if root_changed {
new_record.root_key
} else if let Some(new_key) = appended_key {
let record_signer = if let Some(new_key) = appended_key {
new_key
} else if args.auth_mode == AUTH_MODE_ROOT {
new_record.root_key
} else {
new_record.active_fork()?.blockchain_key
};