I’m just developing the NFT Mint program and I’m going to implement the security for buyer accounts.
This is some of them of my code.
use anchor_lang::prelude::*;
use anchor_spl::{associated_token::AssociatedToken, token::Token};
use ed25519_dalek::{PublicKey, Signature, Verifier};
use serde::{Deserialize, Serialize};
use serde_json;
… … …
pub fn mint(
ctx: Context,
signature: Vec,
message: Vec
) -> Result<()> {
// Deserialize the message into a PurchaseMessage struct
let message_str = String::from_utf8(message).map_err(|| ErrorCode::InvalidMessage)?;
let purchase_message: PurchaseMessage = serde_json::from_str(&message_str).map_err(|| ErrorCode::InvalidMessage)?;
… … …
// Verify the signature
require!(
ed25519_verify(&signature, message_str.as_bytes(), &ctx.accounts.mint_authority.key()),
ErrorCode::InvalidSignature
);
… … …
pub fn ed25519_verify(signature: &[u8], message: &[u8], pubkey: &Pubkey) -> bool {
let pubkey_bytes = pubkey.to_bytes();
let pubkey = match PublicKey::from_bytes(&pubkey_bytes) {
Ok(key) => key,
Err(_) => return false,
};let signature = match Signature::from_bytes(signature) {
Ok(sig) => sig,
Err(_) => return false,
};pubkey.verify(message, &signature).is_ok()
}#[derive(Serialize, Deserialize)]
struct PurchaseMessage {
metadata_title: String,
metadata_symbol: String,
metadata_uri: String,
sale_lamports: u64
}#[error_code]
pub enum ErrorCode {
#[msg(” The provided signature is invalid.”)]
InvalidSignature,
#[msg(” The provided message is invalid.”)]
InvalidMessage,
}
And this is my Carog.tmol file.
[package]
name = “mint-nft”
version = “0.1.0”
description = “Created with Anchor”
edition = “2021”[lib]
crate-type = [“cdylib”, “lib”]
name = “mint_nft”[features]
default =
cpi = [“no-entrypoint”]
no-entrypoint =
no-idl =
no-log-ix-name =
idl-build = [“anchor-lang/idl-build”][dependencies]
anchor-lang = “0.30.0”
anchor-spl = “0.30.0”
base64 = “=0.21.7”
bincode = “1.3.3”
curve25519-dalek = “4.1.2”
ed25519-dalek = “1.0.1”
getrandom = { version = “0.2.15”, features = [“custom”] }
mpl-token-metadata = { version = “4.1.2” }
serde = “1.0.203”
serde_json = “1.0.117”
zeroize = “=1.3.0”
This is the errors:
error: target is not supported, for more information see: getrandom – Rust
–> src/lib.rs:267:9
|
267 | / compile_error!(”
268 | | target is not supported, for more information see:
269 | | getrandom – Rust
270 | | “);
| |__________^error[E0433]: failed to resolve: use of undeclared crate or module
imp
–> src/lib.rs:291:5
|
291 | imp::getrandom_inner(dest)
| ^^^ use of undeclared crate or moduleimp
For more information about this error, try
rustc --explain E0433
.
error: could not compilegetrandom
(lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish…
How can I fix it?
Thank you in advance.
Mullane Benjamin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.