Skip to main content

zombienet_orchestrator/generators/
jam_blobs.rs

1//! The PVM blobs zombienet embeds to build a JAM genesis without any external file.
2
3use jam_std_common::hash_raw;
4use jam_types::{AuthConfig, Authorizer, AuthorizerHash};
5
6// With the `jam` feature, the bootstrap service (`BOOTSTRAP_SERVICE_BLOB`,
7// `BOOTSTRAP_SERVICE_HASH` and `BOOTSTRAP_SERVICE_SOURCE`), built by `build.rs` from the
8// `jam-bootstrap-service` crate. It is installed as service 0 unless the genesis names another
9// blob.
10include!(concat!(env!("OUT_DIR"), "/jam_blobs.rs"));
11
12/// The embedded bootstrap service and where it comes from, if zombienet was built with the `jam`
13/// feature.
14pub fn embedded_bootstrap_service() -> Option<(&'static [u8], &'static str)> {
15    #[cfg(feature = "jam")]
16    return Some((BOOTSTRAP_SERVICE_BLOB, BOOTSTRAP_SERVICE_SOURCE));
17    #[cfg(not(feature = "jam"))]
18    None
19}
20
21/// The null authorizer, which always authorizes.
22pub const NULL_AUTHORIZER_BLOB: &[u8] = jam_null_authorizer_bin::BLOB;
23
24/// The code hash of [`NULL_AUTHORIZER_BLOB`].
25pub const NULL_AUTHORIZER_HASH: [u8; 32] = jam_null_authorizer_bin::HASH;
26
27/// The hash a work package names to be authorized by the parameterless authorizer `code`.
28pub fn authorizer_hash(code: &[u8], config: &[u8]) -> AuthorizerHash {
29    Authorizer {
30        code_hash: hash_raw(code).into(),
31        config: AuthConfig(config.to_vec()),
32    }
33    .hash(hash_raw)
34}
35
36/// The hash a work package names to be authorized by the null authorizer.
37pub fn null_authorizer_hash() -> AuthorizerHash {
38    authorizer_hash(NULL_AUTHORIZER_BLOB, &[])
39}
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44
45    #[test]
46    fn the_embedded_hashes_match_the_blobs() {
47        #[cfg(feature = "jam")]
48        assert_eq!(hash_raw(BOOTSTRAP_SERVICE_BLOB), BOOTSTRAP_SERVICE_HASH);
49        assert_eq!(hash_raw(NULL_AUTHORIZER_BLOB), NULL_AUTHORIZER_HASH);
50    }
51}