ledger_namada_rs/
params.rs

1/*******************************************************************************
2*   (c) 2018 - 2023 ZondaX AG
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********************************************************************************/
16#![deny(warnings, trivial_casts, trivial_numeric_casts)]
17#![deny(unused_import_braces, unused_qualifications)]
18#![deny(missing_docs)]
19
20use crate::utils::{ResponseProofGenKey, ResponsePubAddress, ResponseViewKey};
21
22/// App identifier
23pub const CLA: u8 = 0x57;
24
25/// MASP keys len
26pub const KEY_LEN: usize = 32;
27/// MASP payment address len
28pub const PAYMENT_ADDR_LEN: usize = 43;
29/// MASP tag length
30pub const TAG_LEN: usize = 4;
31/// MASP extended full viewing key length
32pub const XFVK_LEN: usize = 1 + 2 * TAG_LEN + 5 * KEY_LEN;
33/// Public Key Length
34pub const ED25519_PUBKEY_LEN: usize = 32;
35/// Public Key + Tag Length
36pub const PK_LEN_PLUS_TAG: usize = ED25519_PUBKEY_LEN + 1;
37/// Address array size
38pub const ADDRESS_LEN: usize = 45; // 45 --> Testnet | 42 --> Mainnet
39/// ED25519 signature Length
40pub const ED25519_SIGNATURE_LEN: usize = 64;
41/// ED25519 signature + Tag Length
42pub const SIG_LEN_PLUS_TAG: usize = ED25519_SIGNATURE_LEN + 1;
43/// Salt Length
44pub const SALT_LEN: usize = 8;
45/// Hash Length
46// pub const HASH_LEN: usize = 32;
47/// Available instructions to interact with the Ledger device
48#[repr(u8)]
49pub enum InstructionCode {
50    /// Instruction to retrieve Pubkey and Address
51    GetAddressAndPubkey = 1,
52    /// Instruction to sign a transaction
53    Sign = 2,
54    /// Instruction to retrieve MASP keys
55    GetKeys = 3,
56    /// Instruction to generate spend randomness values
57    GetSpendRandomness = 4,
58    /// Instruction to generate output randomness values
59    GetOutputRandomness = 5,
60    /// Instruction to generate spend convert values
61    GetConvertRandomness = 6,
62    /// Instruction to sign masp
63    SignMaspSpends = 7,
64    /// Instruction to retrieve spend signatures
65    ExtractSpendSignature = 8,
66    /// Instruction to clean Buffers
67    CleanBuffers = 0x09,
68
69    /// Instruction to retrieve a signed section
70    GetSignature = 0x0a,
71}
72
73#[derive(Clone, Debug)]
74/// Masp keys return types
75pub enum NamadaKeys {
76    /// Public address key
77    PublicAddress = 0x00,
78    /// View key
79    ViewKey = 0x01,
80    /// Proof generation key
81    ProofGenerationKey = 0x02,
82}
83
84/// Types of Keys Response
85pub enum KeyResponse {
86    /// Address response
87    Address(ResponsePubAddress),
88    /// View key response
89    ViewKey(ResponseViewKey),
90    /// Proof generation key response
91    ProofGenKey(ResponseProofGenKey),
92}