This repository was archived by the owner on Jun 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathadd_authenticator.rs
More file actions
72 lines (58 loc) · 2.13 KB
/
add_authenticator.rs
File metadata and controls
72 lines (58 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use anchor_lang::{prelude::*, solana_program::sysvar::instructions::ID as IX_ID};
use crate::{constants::SMART_WALLET_SEED, verify_authority, PasskeyExt as _, PasskeyPubkey, SmartWalletAuthority, SmartWalletData, VerifyParam, ID};
pub fn add_authenticator(ctx: Context<AddAuthenticator>, verify_param: VerifyParam, new_passkey: PasskeyPubkey) -> Result<()> {
let smart_wallet_authority = &mut ctx.accounts.smart_wallet_authority;
verify_authority(
0,
&ctx.accounts.ix_sysvar,
&verify_param,
smart_wallet_authority.nonce,
smart_wallet_authority.pubkey,
)?;
// assert_eq!(new_passkey_pubkey, new_passkey.data);
ctx.accounts.new_wallet_authority.set_inner(SmartWalletAuthority {
pubkey: PasskeyPubkey { data: new_passkey.data },
smart_wallet_pubkey: ctx.accounts.smart_wallet.key(),
nonce: 0,
});
Ok(())
}
#[derive(Accounts)]
#[instruction(verify_param: VerifyParam, new_passkey: PasskeyPubkey)]
pub struct AddAuthenticator<'info> {
#[account(mut)]
pub payer: Signer<'info>,
#[account(address = IX_ID)]
/// CHECK:
pub ix_sysvar: AccountInfo<'info>,
#[account(
mut,
seeds = [SMART_WALLET_SEED, &smart_wallet_data.id.to_le_bytes()],
bump = smart_wallet_data.bump,
owner = ID,
)]
/// CHECK:
pub smart_wallet: UncheckedAccount<'info>,
#[account(
seeds = [SmartWalletData::PREFIX_SEED, smart_wallet.key().as_ref()],
bump,
owner = ID
)]
pub smart_wallet_data: Account<'info, SmartWalletData>,
#[account(
mut,
seeds = [&verify_param.pubkey.to_hashed_bytes(smart_wallet.key())],
bump,
owner = ID,
)]
pub smart_wallet_authority: Account<'info, SmartWalletAuthority>,
#[account(
init,
payer = payer,
space = SmartWalletAuthority::DISCRIMINATOR.len() + SmartWalletAuthority::INIT_SPACE,
seeds = [&new_passkey.to_hashed_bytes(smart_wallet.key())],
bump
)]
pub new_wallet_authority: Account<'info, SmartWalletAuthority>,
pub system_program: Program<'info, System>,
}