Hello ICP builders
Nathan here from the Trust team Today I’m happy to announce the HTTP certification library for Rust!
Background
As a quick reminder, HTTP certification is a procedure that we follow in canisters to serve HTTP responses through query calls in a secure way.
Query calls are executed by a single replica node and do not go through consensus. This makes them fast, but insecure. Update calls are executed by all replica nodes on a subnet and go through consensus. This makes them slow, but secure.
Certification involves pre-calculating responses, putting them through consensus, and generating a certificate to prove that they have gone through consensus. These certificates are served alongside the pre-calculated responses, allowing clients to verify that the responding replica node has not maliciously altered the response.
HTTP certification is a more advanced version of this procedure that is used specifically for HTTP responses that will be received by HTTP clients, such as a browser. You can find out more about this in my previous post about response verification v2.
The library
The most common usage of HTTP certification today is through the beloved asset canister. To bring this functionality into their own canisters, developers previously had to copy/paste and maintain a lot of complex code from the asset canister. Now developers can leverage this code in a reusable way and build more flexibly using the HTTP certification library.
With this library, developers will be able to:
- Serve certified assets from the same canister as their primary “backend” canister
- Embed assets directly into a canister’s WASM, instead of uploading them at runtime
- Create custom routing logic, such as:
- Serving 404 pages in multi-page apps
- Serving multiple frontends from the same canister
- Certify more complex caching or streaming scenarios
As part of this release, we’ve published a user guide for the library along with example projects and guides demonstrating how to use the library to create an HTTP-compatible JSON API or serve static assets.
The library is available on crates.io, with the docs available on docs.rs and the source code available on github.
What’s next?
If the static asset example is too low-level, don’t worry. There’s another library in the works - the asset certification library will expose a higher-level interface purpose built for certifying and serving static assets in the simplest way possible. Stay tuned and you can expect to see the asset certification library in the coming months.
Feel free to reach out if you have any questions, suggestions, or issues with the library, I’ll be happy to help and I look forward to seeing the cool things that will be built with these libraries