forked from solana-foundation/anchor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
68 lines (59 loc) · 1.89 KB
/
lib.rs
File metadata and controls
68 lines (59 loc) · 1.89 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
use anchor_lang::prelude::*;
use anchor_lang::signature_verification::{
load_instruction, verify_ed25519_ix_with_instruction_index,
verify_secp256k1_ix_with_instruction_index,
};
declare_id!("9P8zSbNRQkwDrjCmqsHHcU1GTk5npaKYgKHroAkupbLG");
#[program]
pub mod signature_verification_test {
use super::*;
pub fn verify_ed25519_signature(
ctx: Context<VerifyEd25519Signature>,
message: Vec<u8>,
signature: [u8; 64],
) -> Result<()> {
let ix = load_instruction(0, &ctx.accounts.ix_sysvar)?;
verify_ed25519_ix_with_instruction_index(
&ix,
u16::MAX,
&ctx.accounts.signer.key().to_bytes(),
&message,
&signature,
)?;
msg!("Ed25519 signature verified successfully using custom helper!");
Ok(())
}
pub fn verify_secp(
ctx: Context<VerifySecp256k1Signature>,
message: Vec<u8>,
signature: [u8; 64],
recovery_id: u8,
eth_address: [u8; 20],
) -> Result<()> {
let ix = load_instruction(0, &ctx.accounts.ix_sysvar)?;
verify_secp256k1_ix_with_instruction_index(
&ix,
0,
ð_address,
&message,
&signature,
recovery_id,
)?;
msg!("Secp256k1 signature verified successfully using custom helper!");
Ok(())
}
}
#[derive(Accounts)]
pub struct VerifyEd25519Signature<'info> {
/// CHECK: Signer account
pub signer: AccountInfo<'info>,
/// CHECK: Instructions sysvar account
#[account(address = anchor_lang::solana_program::sysvar::instructions::ID)]
pub ix_sysvar: AccountInfo<'info>,
}
#[derive(Accounts)]
pub struct VerifySecp256k1Signature<'info> {
/// CHECK: Instructions sysvar account
#[account(address = anchor_lang::solana_program::sysvar::instructions::ID)]
pub ix_sysvar: AccountInfo<'info>,
}