1// Copyright (C) 2023 Entropy Cryptography Inc.
2// This program is free software: you can redistribute it and/or modify
3// it under the terms of the GNU Affero General Public License as published by
4// the Free Software Foundation, either version 3 of the License, or
5// (at your option) any later version.
6//
7// This program is distributed in the hope that it will be useful,
8// but WITHOUT ANY WARRANTY; without even the implied warranty of
9// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10// GNU Affero General Public License for more details.
11//
12// You should have received a copy of the GNU Affero General Public License
13// along with this program. If not, see <https://www.gnu.org/licenses/>.
1415use super::constants::VERIFICATION_KEY_LENGTH;
16#[cfg(not(feature = "wasm"))]
17use codec::alloc::vec::Vec;
18use codec::{Decode, Encode};
19use scale_info::TypeInfo;
20#[cfg(any(feature = "std", feature = "wasm", feature = "user-native"))]
21use serde::{Deserialize, Serialize};
22#[cfg(feature = "std")]
23use strum_macros::EnumIter;
2425/// X25519 public key used by the client in non-interactive ECDH to authenticate/encrypt
26/// interactions with the threshold server (eg distributing threshold shares).
27pub type X25519PublicKey = [u8; 32];
2829/// This should match the type found in `entropy-runtime`. We define it ourselves manually here
30/// since we don't want to pull that whole crate it just for a `u32`.
31pub type BlockNumber = u32;
3233/// Information from the validators in signing party
34#[cfg_attr(not(feature = "wasm"), derive(sp_runtime::Serialize, sp_runtime::Deserialize))]
35#[derive(Clone, Encode, Decode, Debug, Eq, PartialEq, TypeInfo)]
36pub struct ValidatorInfo {
37pub x25519_public_key: X25519PublicKey,
38pub ip_address: Vec<u8>,
39pub tss_account: Vec<u8>,
40}
4142/// Offchain worker message for initiating the initial jumpstart DKG
43#[cfg(not(feature = "wasm"))]
44#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
45#[derive(Clone, Encode, Decode, Debug, Eq, PartialEq, TypeInfo)]
46pub struct OcwMessageDkg {
47pub block_number: BlockNumber,
48pub validators_info: Vec<ValidatorInfo>,
49}
5051/// Offchain worker message for initiating a refresh
52#[cfg(not(feature = "wasm"))]
53#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
54#[derive(Clone, Encode, Decode, Debug, Eq, PartialEq, TypeInfo)]
55pub struct OcwMessageReshare {
56// Stash addresses of new signers
57pub new_signers: Vec<Vec<u8>>,
58pub block_number: BlockNumber,
59}
6061/// Offchain worker message for initiating a proactive refresh
62#[cfg(not(feature = "wasm"))]
63#[derive(
64 Clone,
65 Encode,
66 Decode,
67 Debug,
68 Eq,
69 PartialEq,
70 TypeInfo,
71 sp_runtime::Serialize,
72 sp_runtime::Deserialize,
73)]
74pub struct OcwMessageProactiveRefresh {
75pub block_number: BlockNumber,
76/// Information of the validators to participate
77pub validators_info: Vec<ValidatorInfo>,
78/// Accounts to take part in the proactive refresh
79pub proactive_refresh_keys: Vec<Vec<u8>>,
80}
8182/// 256-bit hashing algorithms for deriving the point to be signed.
83#[cfg_attr(any(feature = "wasm", feature = "std"), derive(Serialize, Deserialize))]
84#[cfg_attr(feature = "std", derive(EnumIter))]
85#[derive(Clone, Debug, Eq, PartialEq)]
86#[cfg_attr(feature = "std", serde(rename = "hash"))]
87#[cfg_attr(feature = "std", serde(rename_all = "lowercase"))]
88#[non_exhaustive]
89pub enum HashingAlgorithm {
90 Sha1,
91 Sha2,
92 Sha3,
93 Keccak,
94 Blake2_256,
95/// An algorithm which produces the same output as its input.
96Identity,
97 Custom(u32),
98}
99100/// A compressed, serialized [synedrion::ecdsa::VerifyingKey<k256::Secp256k1>]
101pub type EncodedVerifyingKey = [u8; VERIFICATION_KEY_LENGTH as usize];
102103#[cfg(not(feature = "wasm"))]
104pub type BoundedVecEncodedVerifyingKey =
105 sp_runtime::BoundedVec<u8, sp_runtime::traits::ConstU32<VERIFICATION_KEY_LENGTH>>;
106107/// Public signing and encryption keys associated with a TS server
108/// This is the output from the TSS `/info` HTTP route
109#[cfg(feature = "wasm-no-std")]
110#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, Eq, PartialEq)]
111pub struct TssPublicKeys {
112/// Indicates that all prerequisite checks have passed
113pub ready: bool,
114/// The TSS account ID
115pub tss_account: sp_runtime::AccountId32,
116/// The public encryption key
117pub x25519_public_key: X25519PublicKey,
118/// The Provisioning Certification Key used in TDX quotes
119pub provisioning_certification_key: BoundedVecEncodedVerifyingKey,
120}