1#![allow(dead_code)]
16use super::constants::VERIFICATION_KEY_LENGTH;
17use blake2::{Blake2b512, Digest};
18#[cfg(not(feature = "wasm"))]
19use codec::alloc::vec::Vec;
20use codec::{Decode, Encode};
21use scale_info::TypeInfo;
22#[cfg(any(feature = "std", feature = "wasm"))]
23use serde::{Deserialize, Serialize};
24#[cfg(feature = "std")]
25use strum_macros::EnumIter;
26
27pub type X25519PublicKey = [u8; 32];
30
31pub type BlockNumber = u32;
34
35#[cfg_attr(not(feature = "wasm"), derive(sp_runtime::Serialize, sp_runtime::Deserialize))]
37#[derive(Clone, Encode, Decode, Debug, Eq, PartialEq, TypeInfo)]
38pub struct ValidatorInfo {
39 pub x25519_public_key: X25519PublicKey,
40 pub ip_address: codec::alloc::vec::Vec<u8>,
41 pub tss_account: codec::alloc::vec::Vec<u8>,
42}
43
44#[cfg(not(feature = "wasm"))]
46#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
47#[derive(Clone, Encode, Decode, Debug, Eq, PartialEq, TypeInfo)]
48pub struct OcwMessageDkg {
49 pub block_number: BlockNumber,
50 pub validators_info: Vec<ValidatorInfo>,
51}
52
53#[cfg(not(feature = "wasm"))]
55#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
56#[derive(Clone, Encode, Decode, Debug, Eq, PartialEq, TypeInfo)]
57pub struct OcwMessageReshare {
58 pub new_signer: Vec<u8>,
60 pub block_number: BlockNumber,
61}
62
63#[cfg(not(feature = "wasm"))]
65#[derive(
66 Clone,
67 Encode,
68 Decode,
69 Debug,
70 Eq,
71 PartialEq,
72 TypeInfo,
73 sp_runtime::Serialize,
74 sp_runtime::Deserialize,
75)]
76pub struct OcwMessageProactiveRefresh {
77 pub block_number: BlockNumber,
78 pub validators_info: Vec<ValidatorInfo>,
80 pub proactive_refresh_keys: Vec<Vec<u8>>,
82}
83
84#[cfg(not(feature = "wasm"))]
86#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
87#[derive(Clone, Encode, Decode, Debug, Eq, PartialEq, TypeInfo)]
88pub struct OcwMessageAttestationRequest {
89 pub tss_account_ids: Vec<[u8; 32]>,
91}
92
93#[cfg_attr(any(feature = "wasm", feature = "std"), derive(Serialize, Deserialize))]
95#[cfg_attr(feature = "std", derive(EnumIter))]
96#[derive(Clone, Debug, Eq, PartialEq)]
97#[cfg_attr(feature = "std", serde(rename = "hash"))]
98#[cfg_attr(feature = "std", serde(rename_all = "lowercase"))]
99#[non_exhaustive]
100pub enum HashingAlgorithm {
101 Sha1,
102 Sha2,
103 Sha3,
104 Keccak,
105 Blake2_256,
106 Custom(usize),
107}
108
109pub type EncodedVerifyingKey = [u8; VERIFICATION_KEY_LENGTH as usize];
111
112#[cfg(not(feature = "wasm"))]
113pub type BoundedVecEncodedVerifyingKey =
114 sp_runtime::BoundedVec<u8, sp_runtime::traits::ConstU32<VERIFICATION_KEY_LENGTH>>;
115
116pub struct QuoteInputData(pub [u8; 64]);
118
119impl QuoteInputData {
120 pub fn new<T: Encode>(
121 tss_account_id: T,
122 x25519_public_key: X25519PublicKey,
123 nonce: [u8; 32],
124 block_number: u32,
125 ) -> Self {
126 let mut hasher = Blake2b512::new();
127 hasher.update(tss_account_id.encode());
128 hasher.update(x25519_public_key);
129 hasher.update(nonce);
130 hasher.update(block_number.to_be_bytes());
131 Self(hasher.finalize().into())
132 }
133}
134
135pub trait KeyProvider<T> {
140 fn x25519_public_key(account_id: &T) -> Option<X25519PublicKey>;
142
143 fn provisioning_key(account_id: &T) -> Option<EncodedVerifyingKey>;
145}
146
147pub trait AttestationQueue<T> {
149 fn confirm_attestation(account_id: &T);
152
153 fn push_pending_attestation(
155 signer: T,
156 tss_account: T,
157 x25519_public_key: X25519PublicKey,
158 endpoint: Vec<u8>,
159 provisioning_certification_key: EncodedVerifyingKey,
160 );
161
162 fn pending_attestations() -> Vec<T>;
164}