Created
January 20, 2022 02:51
-
-
Save ronanyeah/f216399d32bcb15d00a6245a1fac89df to your computer and use it in GitHub Desktop.
ED25519 Solana
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use solana_sdk::{signature::Signer, signer::keypair::Keypair, transaction::Transaction}; | |
#[derive(serde::Deserialize)] | |
struct Env { | |
cluster: String, | |
admin_wallet: String, | |
} | |
//pubkey: E61KAqVnsEq3N6ApArVoYp1FMBqJKDDBcijDe6tmEHte, | |
//let signature: [u8; 64] = [ | |
//183, 243, 166, 77, 40, 177, 227, 74, 121, 142, 66, 162, 164, 140, 246, 27, 245, 166, 147, | |
//141, 179, 246, 154, 208, 152, 196, 146, 42, 22, 194, 167, 178, 182, 215, 93, 191, 108, 126, | |
//82, 163, 163, 38, 229, 67, 187, 232, 241, 192, 15, 217, 24, 180, 133, 139, 47, 244, 147, | |
//136, 75, 114, 168, 184, 11, 4, | |
//]; | |
fn main() { | |
let env = envy::from_env::<Env>().expect("env fail"); | |
let cluster = str::parse::<anchor_client::Cluster>(&env.cluster).expect("bad cluster"); | |
let keypair = Keypair::from_base58_string(&env.admin_wallet); | |
let privkey = ed25519_dalek::Keypair::from_bytes(&keypair.to_bytes()).unwrap(); | |
let message: [u8; 32] = [ | |
33, 223, 82, 242, 68, 22, 57, 121, 178, 245, 112, 226, 196, 129, 57, 76, 201, 213, 7, 99, | |
237, 134, 23, 54, 145, 250, 21, 141, 151, 240, 203, 77, | |
]; | |
let instruction = solana_sdk::ed25519_instruction::new_ed25519_instruction(&privkey, &message); | |
let client = | |
anchor_client::solana_client::rpc_client::RpcClient::new(cluster.url().to_string()); | |
let recent_hash = client.get_latest_blockhash().unwrap(); | |
let tx = Transaction::new_signed_with_payer( | |
&[instruction.clone()], | |
Some(&keypair.pubkey()), | |
&[&keypair], | |
recent_hash, | |
); | |
let res = client | |
//.send_and_confirm_transaction_with_spinner( | |
.simulate_transaction(&tx); | |
println!("{:?}", res); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment