snarkvm_console_account/compute_key/mod.rs
1// Copyright 2024 Aleo Network Foundation
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16mod bitwise;
17mod bytes;
18mod from_bits;
19mod serialize;
20mod size_in_bits;
21mod size_in_bytes;
22mod to_address;
23mod to_bits;
24mod to_fields;
25mod try_from;
26
27#[cfg(feature = "private_key")]
28use crate::PrivateKey;
29
30use snarkvm_console_network::prelude::*;
31use snarkvm_console_types::{Address, Boolean, Field, Group, Scalar};
32
33static _COMPUTE_KEY_PREFIX: [u8; 10] = [109, 249, 98, 224, 36, 15, 213, 187, 79, 190]; // AComputeKey1
34
35#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
36pub struct ComputeKey<N: Network> {
37 /// The signature public key `pk_sig` := G^sk_sig.
38 pk_sig: Group<N>,
39 /// The signature public randomizer `pr_sig` := G^r_sig.
40 pr_sig: Group<N>,
41 /// The PRF secret key `sk_prf` := HashToScalar(pk_sig || pr_sig).
42 sk_prf: Scalar<N>,
43}
44
45impl<N: Network> ComputeKey<N> {
46 /// Returns the signature public key.
47 pub const fn pk_sig(&self) -> Group<N> {
48 self.pk_sig
49 }
50
51 /// Returns the signature public randomizer.
52 pub const fn pr_sig(&self) -> Group<N> {
53 self.pr_sig
54 }
55
56 /// Returns a reference to the PRF secret key.
57 pub const fn sk_prf(&self) -> Scalar<N> {
58 self.sk_prf
59 }
60}