# How can I fix it?

**URL:** <https://forum.dfinity.org/t/how-can-i-fix-it/31307>\
**Category:** Rust\
**Created:** [May 29, 2024, 12:39pm UTC](https://forum.dfinity.org/t/how-can-i-fix-it/31307 "2024-05-29T12:39:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benjamin1](https://avatars.discourse-cdn.com/v4/letter/b/96bed5/32.png) [@Benjamin1](https://forum.dfinity.org/u/Benjamin1)\
**Post date:** [May 29, 2024, 12:39pm UTC](https://forum.dfinity.org/t/how-can-i-fix-it/31307/1 "2024-05-29T12:39:38Z")

</div>

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 anchor\_lang::solana\_program::ed25519\_program;
> 
> 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)?;
> 
> ````auto
> // 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](https://docs.rs/getrandom/#unsupported-targets)  
> → src/lib.rs:267:9  
> |  
> 267 | / compile\_error!("  
> 268 | | target is not supported, for more information see:  
> 269 | | [getrandom - Rust](https://docs.rs/getrandom/#unsupported-targets%5C)  
> 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 module `imp`
> 
> For more information about this error, try `rustc --explain E0433`.  
> error: could not compile `getrandom` (lib) due to 2 previous errors  
> warning: build failed, waiting for other jobs to finish…

How can I fix it?  
Thank you in advance.

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [May 29, 2024, 12:49pm UTC](https://forum.dfinity.org/t/how-can-i-fix-it/31307/2 "2024-05-29T12:49:06Z")

</div>

Have a look here:

> [@Rust Wasm \_\_getrandom\_custom](https://forum.dfinity.org/t/rust-wasm-getrandom-custom/6351):
>
> I am trying to get proptest, a property-testing library in Rust, to compile and run from within a canister. It has a dependency on getrandom, and I assume that because getrandom is being compiled for a Wasm environment, it expects a \_\_getrandom\_custom import from the host environment. I get the following error when trying to deploy a canister with that uses proptest: Installing canisters... Upgrading code for canister graphql, with canister\_id rrkah-fqaaa-aaaaa-aaaaq-cai The invocation to the w…

> [@Issue about generate random string Panicked at 'could not initialize thread\_rng: getrandom: this target is not supported'](https://forum.dfinity.org/t/issue-about-generate-random-string-panicked-at-could-not-initialize-thread-rng-getrandom-this-target-is-not-supported/15198):
>
> Reject text: Canister ryjl3-tyaaa-aaaaa-abbba-cai trapped explicitly: Panicked at ‘could not initialize thread\_rng: getrandom: this target is not supported’, /Users/xxxx/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.7.3/src/rngs/thread.rs:65:17 dependencies: rand = “0.7.3” getrandom = { version = “0.2.6”, features = [“js”]} “dfx”: “0.9.3”, I refered to previous solution, it doesn’t work. Does anyone know how to solve it?

---

<div class="post-metadata">

**Author:** ![Benjamin1](https://avatars.discourse-cdn.com/v4/letter/b/96bed5/32.png) [@Benjamin1](https://forum.dfinity.org/u/Benjamin1)\
**Post date:** [May 29, 2024, 1:01pm UTC](https://forum.dfinity.org/t/how-can-i-fix-it/31307/3 "2024-05-29T13:01:03Z")

</div>

Thank you for your kind attention and your help.

But is it the same as my program?

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [May 29, 2024, 1:01pm UTC](https://forum.dfinity.org/t/how-can-i-fix-it/31307/4 "2024-05-29T13:01:35Z")

</div>

It’s the same error cause so the same solution should work

---

<div class="post-metadata">

**Author:** ![Benjamin1](https://avatars.discourse-cdn.com/v4/letter/b/96bed5/32.png) [@Benjamin1](https://forum.dfinity.org/u/Benjamin1)\
**Post date:** [May 29, 2024, 1:44pm UTC](https://forum.dfinity.org/t/how-can-i-fix-it/31307/5 "2024-05-29T13:44:04Z")

</div>

I don’t know well yet.  
Could you offer the sample code based on my code?
