I am implementing IBE encryption getting error while using system_api

Error: Failed while trying to deploy canisters.
Caused by: Failed while trying to install all canisters.
Caused by: Failed to install wasm module to canister ‘system_api’.
Caused by: Failed during wasm installation call
Caused by: The replica returned a rejection error: reject code CanisterError, reject message Error from Canister gf4a7-g4aaa-aaaaa-qaarq-cai: Canister’s Wasm module is not valid: Wasm module has an invalid import section. Module imports function ‘__wbindgen_describe’ from ‘wbindgen_placeholder’ that is not exported by the runtime…
This is likely an error with the compiler/CDK toolchain being used to build the canister. Please report the error to IC devs on the forum: https://forum.dfinity.org and include which language/CDK was used to create the canister., error code None

Got the fix , Use below in cargo.toml in place of
getrandom = { version = "0.2", features = ["js"] }

as

getrandom = { version = "0.2", features = ["custom"] }
1 Like

“custom” also means you need to implement this custom method.

If “getrandom” is a child dependency that is never actually invoked, you can implement it as a method that will always fail as seen here cdk-rs/examples/chess/src/chess_rs/getrandom_fail.rs at 0b14facb80e161de79264c8f88b1a0c8e18ffcb6 · dfinity/cdk-rs · GitHub

In case “getrandom” needs to actually return random data instead of throwing an error you have two options:

  1. See if the library that depends on “getrandom” allows you to implement your own source of random bytes and pass it in as argument, in which case you can asynchronously call the system canister to get random bytes. In this case the “getrandom” library will never get invoked and above fail implementation can be used to make things compile.

  2. Use a synchronous PRNG implementation to write the custom “getrandom” method. Keep in mind this significantly less secure since it relies on a random seed (thats passed to PRNG) and the PRNG state to be stored in the canister state.

Overall, both implementation options do not work for query methods since either you can’t make inter canister calls (option 1) or update state (option 2). So make sure to implement an update method for either approach.

Make sure to test your canister, to be truly certain your implementation is using random bytes correctly and is secure!

Maybe this topic should be documented somewhere in the Rust SDK docs since it seems a recurring question on the forums :sweat_smile: