|
|
@@ -2,14 +2,15 @@
|
|
|
|
|
|
use crate::{build_solidity, Account, AccountState, BorshToken};
|
|
|
use base58::FromBase58;
|
|
|
-use ed25519_dalek::{Keypair, Signature, Signer};
|
|
|
+use ed25519_dalek::{Signature, Signer, SigningKey};
|
|
|
+use rand::rngs::OsRng;
|
|
|
use serde_derive::Serialize;
|
|
|
use std::convert::TryInto;
|
|
|
use std::mem::size_of;
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
#[repr(C)]
|
|
|
-struct instructions {
|
|
|
+struct Instructions {
|
|
|
num_instructions: u16,
|
|
|
instruction_offset: u16,
|
|
|
num_accounts: u16,
|
|
|
@@ -56,8 +57,8 @@ fn verify() {
|
|
|
vm.account_data
|
|
|
.insert(instructions_account, AccountState::default());
|
|
|
|
|
|
- let mut csprng = rand_07::thread_rng();
|
|
|
- let keypair: Keypair = Keypair::generate(&mut csprng);
|
|
|
+ let mut csprng = OsRng;
|
|
|
+ let keypair: SigningKey = SigningKey::generate(&mut csprng);
|
|
|
|
|
|
let message: &[u8] =
|
|
|
b"This is a test of the ed25519 sig check for the ed25519 signature check program";
|
|
|
@@ -66,14 +67,17 @@ fn verify() {
|
|
|
|
|
|
let signature_bs = signature.to_bytes().to_vec();
|
|
|
|
|
|
- println!("T: PUB: {}", hex::encode(keypair.public.to_bytes()));
|
|
|
+ println!(
|
|
|
+ "T: PUB: {}",
|
|
|
+ hex::encode(keypair.verifying_key().to_bytes())
|
|
|
+ );
|
|
|
println!("T: SIG: {}", hex::encode(&signature_bs));
|
|
|
println!("T: MES: {}", hex::encode(message));
|
|
|
|
|
|
let returns = vm
|
|
|
.function("verify")
|
|
|
.arguments(&[
|
|
|
- BorshToken::Address(keypair.public.to_bytes()),
|
|
|
+ BorshToken::Address(keypair.verifying_key().to_bytes()),
|
|
|
BorshToken::Bytes(message.to_vec()),
|
|
|
BorshToken::Bytes(signature_bs.clone()),
|
|
|
])
|
|
|
@@ -91,7 +95,8 @@ fn verify() {
|
|
|
.unwrap()
|
|
|
.try_into()
|
|
|
.unwrap();
|
|
|
- let instructions = encode_instructions(&keypair.public.to_bytes(), &signature_bs, message);
|
|
|
+ let instructions =
|
|
|
+ encode_instructions(&keypair.verifying_key().to_bytes(), &signature_bs, message);
|
|
|
|
|
|
vm.account_data.insert(
|
|
|
instructions_account,
|
|
|
@@ -107,7 +112,7 @@ fn verify() {
|
|
|
let returns = vm
|
|
|
.function("verify")
|
|
|
.arguments(&[
|
|
|
- BorshToken::Address(keypair.public.to_bytes()),
|
|
|
+ BorshToken::Address(keypair.verifying_key().to_bytes()),
|
|
|
BorshToken::Bytes(message.to_vec()),
|
|
|
BorshToken::Bytes(signature_bs.clone()),
|
|
|
])
|
|
|
@@ -126,7 +131,11 @@ fn verify() {
|
|
|
let mut signature_copy = signature_bs.clone();
|
|
|
signature_copy[2] ^= 0x80;
|
|
|
|
|
|
- let instructions = encode_instructions(&keypair.public.to_bytes(), &signature_copy, message);
|
|
|
+ let instructions = encode_instructions(
|
|
|
+ &keypair.verifying_key().to_bytes(),
|
|
|
+ &signature_copy,
|
|
|
+ message,
|
|
|
+ );
|
|
|
|
|
|
vm.account_data.insert(
|
|
|
instructions_account,
|
|
|
@@ -140,7 +149,7 @@ fn verify() {
|
|
|
let returns = vm
|
|
|
.function("verify")
|
|
|
.arguments(&[
|
|
|
- BorshToken::Address(keypair.public.to_bytes()),
|
|
|
+ BorshToken::Address(keypair.verifying_key().to_bytes()),
|
|
|
BorshToken::Bytes(message.to_vec()),
|
|
|
BorshToken::Bytes(signature_bs),
|
|
|
])
|
|
|
@@ -174,7 +183,7 @@ fn encode_instructions(public_key: &[u8], signature: &[u8], message: &[u8]) -> V
|
|
|
ed25519_instruction.extend_from_slice(public_key);
|
|
|
ed25519_instruction.extend_from_slice(message);
|
|
|
|
|
|
- let instr = instructions {
|
|
|
+ let instr = Instructions {
|
|
|
num_instructions: 1,
|
|
|
instruction_offset: 4,
|
|
|
num_accounts: 0,
|