Certified Assets Library

Rust support for asset certification.

Certified assets can also be served from any Rust canister by including this library.

Adding to a canister

[dependencies] ic-certified-assets = "0.2.2"

The assets are preserved over upgrades by including the corresponding functions in the init/pre_upgrade/upgrade hooks which can be mixed with the other state from the canister:

```

[derive(Clone, Debug, CandidType, Deserialize)]

struct StableState { my_state: MyState, assets: crate::assets::StableState, }

[init]

fn init() { crate::assets::init(); }

[pre_upgrade]

fn preupgrade() { let stablestate = STATE.with(|s| StableState { mystate: s.mystate, assets: crate::assets::preupgrade(), }); iccdk::storage::stablesave((stablestate,)).expect("failed to save stable state"); }

[post_upgrade]

fn postupgrade() { let (StableState { assets, mystate },): (StableState,) = iccdk::storage::stablerestore().expect("failed to restore stable state"); crate::assets::postupgrade(assets); STATE.with(|s| { s.mystate = my_state; }; } ```

Uploading assets

cd assets icx-asset --pem ~/.config/dfx/identity/default/identity.pem --replica https://ic0.app sync <canister_id> .