wapod_types/
lib.rs

1//! Types that third-party softwares can use to talk to a wapod worker.
2
3#![cfg_attr(not(feature = "std"), no_std)]
4#![deny(missing_docs)]
5
6extern crate alloc;
7
8use alloc::vec::Vec;
9use core::fmt::Debug;
10
11pub use primitives::{Address, Bytes32, Hash, WorkerPubkey};
12pub use scale;
13
14pub mod bench_app;
15pub mod crypto;
16pub mod metrics;
17pub mod primitives;
18pub mod session;
19pub mod ticket;
20pub mod worker;
21
22mod helpers;
23
24/// The content type of a signed message.
25#[derive(Clone, Copy, Debug)]
26#[repr(u8)]
27pub enum ContentType {
28    /// A response to an RPC request.
29    RpcResponse = 1,
30    /// An endpoint info message.
31    EndpointInfo = 2,
32    // A gap to avoid conflicts with pruntime v2
33    /// Metrics of applications.
34    Metrics = 100,
35    /// App requested worker signed data.
36    AppData = 101,
37    /// Worker attestation.
38    WorkerAttestation = 102,
39    /// Worker description.
40    WorkerDescription = 103,
41    /// Worker session update.
42    SessionUpdate = 104,
43}
44
45impl ContentType {
46    /// Wrap a message with the content type to create a signed message.
47    pub fn wrap_message(&self, message: impl AsRef<[u8]>) -> Vec<u8> {
48        self.wrap_message_iter(message.as_ref().iter().copied())
49    }
50
51    /// Wrap a message with the content type to create a signed message.
52    pub fn wrap_message_iter(&self, message: impl IntoIterator<Item = u8>) -> Vec<u8> {
53        [0xff_u8, *self as u8].into_iter().chain(message).collect()
54    }
55}