mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-08-08 14:03:31 +00:00
lint issues
This commit is contained in:
parent
4fdefd3557
commit
83ef789002
@ -1,6 +1,6 @@
|
|||||||
use std::{net::SocketAddr, path::PathBuf, time::Duration};
|
use std::{net::SocketAddr, path::PathBuf, time::Duration};
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context as _, Result};
|
||||||
use bytesize::ByteSize;
|
use bytesize::ByteSize;
|
||||||
use common::block::{AccountInitialData, CommitmentsInitialData};
|
use common::block::{AccountInitialData, CommitmentsInitialData};
|
||||||
use indexer_service::{BackoffConfig, ChannelId, ClientConfig, IndexerConfig};
|
use indexer_service::{BackoffConfig, ChannelId, ClientConfig, IndexerConfig};
|
||||||
@ -13,6 +13,157 @@ use wallet::config::{
|
|||||||
InitialAccountData, InitialAccountDataPrivate, InitialAccountDataPublic, WalletConfig,
|
InitialAccountData, InitialAccountDataPrivate, InitialAccountDataPublic, WalletConfig,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Sequencer config options available for custom changes in integration tests.
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub struct SequencerPartialConfig {
|
||||||
|
pub max_num_tx_in_block: usize,
|
||||||
|
pub max_block_size: ByteSize,
|
||||||
|
pub mempool_max_size: usize,
|
||||||
|
pub block_create_timeout: Duration,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for SequencerPartialConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
max_num_tx_in_block: 20,
|
||||||
|
max_block_size: ByteSize::mib(1),
|
||||||
|
mempool_max_size: 10_000,
|
||||||
|
block_create_timeout: Duration::from_secs(10),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct InitialData {
|
||||||
|
pub public_accounts: Vec<(PrivateKey, u128)>,
|
||||||
|
pub private_accounts: Vec<(KeyChain, Account)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl InitialData {
|
||||||
|
#[must_use]
|
||||||
|
pub fn with_two_public_and_two_private_initialized_accounts() -> Self {
|
||||||
|
let mut public_alice_private_key = PrivateKey::new_os_random();
|
||||||
|
let mut public_alice_public_key =
|
||||||
|
PublicKey::new_from_private_key(&public_alice_private_key);
|
||||||
|
let mut public_alice_account_id = AccountId::from(&public_alice_public_key);
|
||||||
|
|
||||||
|
let mut public_bob_private_key = PrivateKey::new_os_random();
|
||||||
|
let mut public_bob_public_key = PublicKey::new_from_private_key(&public_bob_private_key);
|
||||||
|
let mut public_bob_account_id = AccountId::from(&public_bob_public_key);
|
||||||
|
|
||||||
|
// Ensure consistent ordering
|
||||||
|
if public_alice_account_id > public_bob_account_id {
|
||||||
|
std::mem::swap(&mut public_alice_private_key, &mut public_bob_private_key);
|
||||||
|
std::mem::swap(&mut public_alice_public_key, &mut public_bob_public_key);
|
||||||
|
std::mem::swap(&mut public_alice_account_id, &mut public_bob_account_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut private_charlie_key_chain = KeyChain::new_os_random();
|
||||||
|
let mut private_charlie_account_id =
|
||||||
|
AccountId::from(&private_charlie_key_chain.nullifier_public_key);
|
||||||
|
|
||||||
|
let mut private_david_key_chain = KeyChain::new_os_random();
|
||||||
|
let mut private_david_account_id =
|
||||||
|
AccountId::from(&private_david_key_chain.nullifier_public_key);
|
||||||
|
|
||||||
|
// Ensure consistent ordering
|
||||||
|
if private_charlie_account_id > private_david_account_id {
|
||||||
|
std::mem::swap(&mut private_charlie_key_chain, &mut private_david_key_chain);
|
||||||
|
std::mem::swap(
|
||||||
|
&mut private_charlie_account_id,
|
||||||
|
&mut private_david_account_id,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Self {
|
||||||
|
public_accounts: vec![
|
||||||
|
(public_alice_private_key, 10_000),
|
||||||
|
(public_bob_private_key, 20_000),
|
||||||
|
],
|
||||||
|
private_accounts: vec![
|
||||||
|
(
|
||||||
|
private_charlie_key_chain,
|
||||||
|
Account {
|
||||||
|
balance: 10_000,
|
||||||
|
data: Data::default(),
|
||||||
|
program_owner: DEFAULT_PROGRAM_ID,
|
||||||
|
nonce: 0_u128.into(),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
private_david_key_chain,
|
||||||
|
Account {
|
||||||
|
balance: 20_000,
|
||||||
|
data: Data::default(),
|
||||||
|
program_owner: DEFAULT_PROGRAM_ID,
|
||||||
|
nonce: 0_u128.into(),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sequencer_initial_accounts(&self) -> Vec<AccountInitialData> {
|
||||||
|
self.public_accounts
|
||||||
|
.iter()
|
||||||
|
.map(|(priv_key, balance)| {
|
||||||
|
let pub_key = PublicKey::new_from_private_key(priv_key);
|
||||||
|
let account_id = AccountId::from(&pub_key);
|
||||||
|
AccountInitialData {
|
||||||
|
account_id,
|
||||||
|
balance: *balance,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sequencer_initial_commitments(&self) -> Vec<CommitmentsInitialData> {
|
||||||
|
self.private_accounts
|
||||||
|
.iter()
|
||||||
|
.map(|(key_chain, account)| CommitmentsInitialData {
|
||||||
|
npk: key_chain.nullifier_public_key.clone(),
|
||||||
|
account: account.clone(),
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn wallet_initial_accounts(&self) -> Vec<InitialAccountData> {
|
||||||
|
self.public_accounts
|
||||||
|
.iter()
|
||||||
|
.map(|(priv_key, _)| {
|
||||||
|
let pub_key = PublicKey::new_from_private_key(priv_key);
|
||||||
|
let account_id = AccountId::from(&pub_key);
|
||||||
|
InitialAccountData::Public(InitialAccountDataPublic {
|
||||||
|
account_id,
|
||||||
|
pub_sign_key: priv_key.clone(),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.chain(self.private_accounts.iter().map(|(key_chain, account)| {
|
||||||
|
let account_id = AccountId::from(&key_chain.nullifier_public_key);
|
||||||
|
InitialAccountData::Private(Box::new(InitialAccountDataPrivate {
|
||||||
|
account_id,
|
||||||
|
account: account.clone(),
|
||||||
|
key_chain: key_chain.clone(),
|
||||||
|
}))
|
||||||
|
}))
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub enum UrlProtocol {
|
||||||
|
Http,
|
||||||
|
Ws,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for UrlProtocol {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::Http => write!(f, "http"),
|
||||||
|
Self::Ws => write!(f, "ws"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn indexer_config(
|
pub fn indexer_config(
|
||||||
bedrock_addr: SocketAddr,
|
bedrock_addr: SocketAddr,
|
||||||
home: PathBuf,
|
home: PathBuf,
|
||||||
@ -37,25 +188,6 @@ pub fn indexer_config(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sequencer config options available for custom changes in integration tests.
|
|
||||||
pub struct SequencerPartialConfig {
|
|
||||||
pub max_num_tx_in_block: usize,
|
|
||||||
pub max_block_size: ByteSize,
|
|
||||||
pub mempool_max_size: usize,
|
|
||||||
pub block_create_timeout: Duration,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for SequencerPartialConfig {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
max_num_tx_in_block: 20,
|
|
||||||
max_block_size: ByteSize::mib(1),
|
|
||||||
mempool_max_size: 10_000,
|
|
||||||
block_create_timeout: Duration::from_secs(10),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn sequencer_config(
|
pub fn sequencer_config(
|
||||||
partial: SequencerPartialConfig,
|
partial: SequencerPartialConfig,
|
||||||
home: PathBuf,
|
home: PathBuf,
|
||||||
@ -116,135 +248,6 @@ pub fn wallet_config(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct InitialData {
|
|
||||||
pub public_accounts: Vec<(PrivateKey, u128)>,
|
|
||||||
pub private_accounts: Vec<(KeyChain, Account)>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl InitialData {
|
|
||||||
pub fn with_two_public_and_two_private_initialized_accounts() -> Self {
|
|
||||||
let mut public_alice_private_key = PrivateKey::new_os_random();
|
|
||||||
let mut public_alice_public_key =
|
|
||||||
PublicKey::new_from_private_key(&public_alice_private_key);
|
|
||||||
let mut public_alice_account_id = AccountId::from(&public_alice_public_key);
|
|
||||||
|
|
||||||
let mut public_bob_private_key = PrivateKey::new_os_random();
|
|
||||||
let mut public_bob_public_key = PublicKey::new_from_private_key(&public_bob_private_key);
|
|
||||||
let mut public_bob_account_id = AccountId::from(&public_bob_public_key);
|
|
||||||
|
|
||||||
// Ensure consistent ordering
|
|
||||||
if public_alice_account_id > public_bob_account_id {
|
|
||||||
std::mem::swap(&mut public_alice_private_key, &mut public_bob_private_key);
|
|
||||||
std::mem::swap(&mut public_alice_public_key, &mut public_bob_public_key);
|
|
||||||
std::mem::swap(&mut public_alice_account_id, &mut public_bob_account_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut private_charlie_key_chain = KeyChain::new_os_random();
|
|
||||||
let mut private_charlie_account_id =
|
|
||||||
AccountId::from(&private_charlie_key_chain.nullifier_public_key);
|
|
||||||
|
|
||||||
let mut private_david_key_chain = KeyChain::new_os_random();
|
|
||||||
let mut private_david_account_id =
|
|
||||||
AccountId::from(&private_david_key_chain.nullifier_public_key);
|
|
||||||
|
|
||||||
// Ensure consistent ordering
|
|
||||||
if private_charlie_account_id > private_david_account_id {
|
|
||||||
std::mem::swap(&mut private_charlie_key_chain, &mut private_david_key_chain);
|
|
||||||
std::mem::swap(
|
|
||||||
&mut private_charlie_account_id,
|
|
||||||
&mut private_david_account_id,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Self {
|
|
||||||
public_accounts: vec![
|
|
||||||
(public_alice_private_key, 10_000),
|
|
||||||
(public_bob_private_key, 20_000),
|
|
||||||
],
|
|
||||||
private_accounts: vec![
|
|
||||||
(
|
|
||||||
private_charlie_key_chain,
|
|
||||||
Account {
|
|
||||||
balance: 10_000,
|
|
||||||
data: Data::default(),
|
|
||||||
program_owner: DEFAULT_PROGRAM_ID,
|
|
||||||
nonce: 0,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
(
|
|
||||||
private_david_key_chain,
|
|
||||||
Account {
|
|
||||||
balance: 20_000,
|
|
||||||
data: Data::default(),
|
|
||||||
program_owner: DEFAULT_PROGRAM_ID,
|
|
||||||
nonce: 0,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn sequencer_initial_accounts(&self) -> Vec<AccountInitialData> {
|
|
||||||
self.public_accounts
|
|
||||||
.iter()
|
|
||||||
.map(|(priv_key, balance)| {
|
|
||||||
let pub_key = PublicKey::new_from_private_key(priv_key);
|
|
||||||
let account_id = AccountId::from(&pub_key);
|
|
||||||
AccountInitialData {
|
|
||||||
account_id,
|
|
||||||
balance: *balance,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn sequencer_initial_commitments(&self) -> Vec<CommitmentsInitialData> {
|
|
||||||
self.private_accounts
|
|
||||||
.iter()
|
|
||||||
.map(|(key_chain, account)| CommitmentsInitialData {
|
|
||||||
npk: key_chain.nullifier_public_key.clone(),
|
|
||||||
account: account.clone(),
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn wallet_initial_accounts(&self) -> Vec<InitialAccountData> {
|
|
||||||
self.public_accounts
|
|
||||||
.iter()
|
|
||||||
.map(|(priv_key, _)| {
|
|
||||||
let pub_key = PublicKey::new_from_private_key(priv_key);
|
|
||||||
let account_id = AccountId::from(&pub_key);
|
|
||||||
InitialAccountData::Public(InitialAccountDataPublic {
|
|
||||||
account_id,
|
|
||||||
pub_sign_key: priv_key.clone(),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.chain(self.private_accounts.iter().map(|(key_chain, account)| {
|
|
||||||
let account_id = AccountId::from(&key_chain.nullifier_public_key);
|
|
||||||
InitialAccountData::Private(InitialAccountDataPrivate {
|
|
||||||
account_id,
|
|
||||||
account: account.clone(),
|
|
||||||
key_chain: key_chain.clone(),
|
|
||||||
})
|
|
||||||
}))
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum UrlProtocol {
|
|
||||||
Http,
|
|
||||||
Ws,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::fmt::Display for UrlProtocol {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
match self {
|
|
||||||
UrlProtocol::Http => write!(f, "http"),
|
|
||||||
UrlProtocol::Ws => write!(f, "ws"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn addr_to_url(protocol: UrlProtocol, addr: SocketAddr) -> Result<Url> {
|
pub fn addr_to_url(protocol: UrlProtocol, addr: SocketAddr) -> Result<Url> {
|
||||||
// Convert 0.0.0.0 to 127.0.0.1 for client connections
|
// Convert 0.0.0.0 to 127.0.0.1 for client connections
|
||||||
// When binding to port 0, the server binds to 0.0.0.0:<random_port>
|
// When binding to port 0, the server binds to 0.0.0.0:<random_port>
|
||||||
@ -259,7 +262,7 @@ pub fn addr_to_url(protocol: UrlProtocol, addr: SocketAddr) -> Result<Url> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn bedrock_channel_id() -> ChannelId {
|
fn bedrock_channel_id() -> ChannelId {
|
||||||
let channel_id: [u8; 32] = [0u8, 1]
|
let channel_id: [u8; 32] = [0_u8, 1]
|
||||||
.repeat(16)
|
.repeat(16)
|
||||||
.try_into()
|
.try_into()
|
||||||
.unwrap_or_else(|_| unreachable!());
|
.unwrap_or_else(|_| unreachable!());
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use k256::{Scalar, elliptic_curve::PrimeField};
|
use k256::{Scalar, elliptic_curve::PrimeField as _};
|
||||||
use nssa_core::{NullifierPublicKey, encryption::ViewingPublicKey};
|
use nssa_core::{NullifierPublicKey, encryption::ViewingPublicKey};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@ -12,7 +12,7 @@ use crate::key_management::{
|
|||||||
pub struct ChildKeysPrivate {
|
pub struct ChildKeysPrivate {
|
||||||
pub value: (KeyChain, nssa::Account),
|
pub value: (KeyChain, nssa::Account),
|
||||||
pub ccc: [u8; 32],
|
pub ccc: [u8; 32],
|
||||||
/// Can be [`None`] if root
|
/// Can be [`None`] if root.
|
||||||
pub cci: Option<u32>,
|
pub cci: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,6 +54,7 @@ impl KeyNode for ChildKeysPrivate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn nth_child(&self, cci: u32) -> Self {
|
fn nth_child(&self, cci: u32) -> Self {
|
||||||
|
#[expect(clippy::arithmetic_side_effects, reason = "TODO: fix later")]
|
||||||
let parent_pt =
|
let parent_pt =
|
||||||
Scalar::from_repr(self.value.0.private_key_holder.nullifier_secret_key.into())
|
Scalar::from_repr(self.value.0.private_key_holder.nullifier_secret_key.into())
|
||||||
.expect("Key generated as scalar, must be valid representation")
|
.expect("Key generated as scalar, must be valid representation")
|
||||||
@ -63,6 +64,7 @@ impl KeyNode for ChildKeysPrivate {
|
|||||||
|
|
||||||
input.extend_from_slice(b"LEE_seed_priv");
|
input.extend_from_slice(b"LEE_seed_priv");
|
||||||
input.extend_from_slice(&parent_pt.to_bytes());
|
input.extend_from_slice(&parent_pt.to_bytes());
|
||||||
|
#[expect(clippy::big_endian_bytes, reason = "BIP-032 uses big endian")]
|
||||||
input.extend_from_slice(&cci.to_be_bytes());
|
input.extend_from_slice(&cci.to_be_bytes());
|
||||||
|
|
||||||
let hash_value = hmac_sha512::HMAC::mac(input, self.ccc);
|
let hash_value = hmac_sha512::HMAC::mac(input, self.ccc);
|
||||||
@ -113,12 +115,20 @@ impl KeyNode for ChildKeysPrivate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[expect(
|
||||||
|
clippy::single_char_lifetime_names,
|
||||||
|
reason = "TODO add meaningful name"
|
||||||
|
)]
|
||||||
impl<'a> From<&'a ChildKeysPrivate> for &'a (KeyChain, nssa::Account) {
|
impl<'a> From<&'a ChildKeysPrivate> for &'a (KeyChain, nssa::Account) {
|
||||||
fn from(value: &'a ChildKeysPrivate) -> Self {
|
fn from(value: &'a ChildKeysPrivate) -> Self {
|
||||||
&value.value
|
&value.value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[expect(
|
||||||
|
clippy::single_char_lifetime_names,
|
||||||
|
reason = "TODO add meaningful name"
|
||||||
|
)]
|
||||||
impl<'a> From<&'a mut ChildKeysPrivate> for &'a mut (KeyChain, nssa::Account) {
|
impl<'a> From<&'a mut ChildKeysPrivate> for &'a mut (KeyChain, nssa::Account) {
|
||||||
fn from(value: &'a mut ChildKeysPrivate) -> Self {
|
fn from(value: &'a mut ChildKeysPrivate) -> Self {
|
||||||
&mut value.value
|
&mut value.value
|
||||||
@ -190,7 +200,7 @@ mod tests {
|
|||||||
];
|
];
|
||||||
|
|
||||||
let root_node = ChildKeysPrivate::root(seed);
|
let root_node = ChildKeysPrivate::root(seed);
|
||||||
let child_node = ChildKeysPrivate::nth_child(&root_node, 42u32);
|
let child_node = ChildKeysPrivate::nth_child(&root_node, 42_u32);
|
||||||
|
|
||||||
let expected_ccc: [u8; 32] = [
|
let expected_ccc: [u8; 32] = [
|
||||||
27, 73, 133, 213, 214, 63, 217, 184, 164, 17, 172, 140, 223, 95, 255, 157, 11, 0, 58,
|
27, 73, 133, 213, 214, 63, 217, 184, 164, 17, 172, 140, 223, 95, 255, 157, 11, 0, 58,
|
||||||
|
|||||||
@ -8,36 +8,32 @@ pub struct ChildKeysPublic {
|
|||||||
pub csk: nssa::PrivateKey,
|
pub csk: nssa::PrivateKey,
|
||||||
pub cpk: nssa::PublicKey,
|
pub cpk: nssa::PublicKey,
|
||||||
pub ccc: [u8; 32],
|
pub ccc: [u8; 32],
|
||||||
/// Can be [`None`] if root
|
/// Can be [`None`] if root.
|
||||||
pub cci: Option<u32>,
|
pub cci: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChildKeysPublic {
|
impl ChildKeysPublic {
|
||||||
|
#[expect(clippy::big_endian_bytes, reason = "BIP-032 uses big endian")]
|
||||||
fn compute_hash_value(&self, cci: u32) -> [u8; 64] {
|
fn compute_hash_value(&self, cci: u32) -> [u8; 64] {
|
||||||
let mut hash_input = vec![];
|
let mut hash_input = vec![];
|
||||||
|
|
||||||
match ((2u32).pow(31)).cmp(&cci) {
|
if ((2_u32).pow(31)).cmp(&cci) == std::cmp::Ordering::Greater {
|
||||||
// Non-harden
|
// Non-harden.
|
||||||
std::cmp::Ordering::Greater => {
|
// BIP-032 compatibility requires 1-byte header from the public_key;
|
||||||
// BIP-032 compatibility requires 1-byte header from the public_key;
|
// Not stored in `self.cpk.value()`.
|
||||||
// Not stored in `self.cpk.value()`
|
let sk = secp256k1::SecretKey::from_byte_array(*self.csk.value())
|
||||||
let sk = secp256k1::SecretKey::from_byte_array(*self.csk.value())
|
.expect("32 bytes, within curve order");
|
||||||
.expect("32 bytes, within curve order");
|
let pk = secp256k1::PublicKey::from_secret_key(&secp256k1::Secp256k1::new(), &sk);
|
||||||
let pk = secp256k1::PublicKey::from_secret_key(&secp256k1::Secp256k1::new(), &sk);
|
hash_input.extend_from_slice(&secp256k1::PublicKey::serialize(&pk));
|
||||||
hash_input.extend_from_slice(&secp256k1::PublicKey::serialize(&pk));
|
} else {
|
||||||
hash_input.extend_from_slice(&cci.to_be_bytes());
|
// Harden.
|
||||||
|
hash_input.extend_from_slice(&[0_u8]);
|
||||||
hmac_sha512::HMAC::mac(hash_input, self.ccc)
|
hash_input.extend_from_slice(self.csk.value());
|
||||||
}
|
|
||||||
// Harden
|
|
||||||
_ => {
|
|
||||||
hash_input.extend_from_slice(&[0u8]);
|
|
||||||
hash_input.extend_from_slice(self.csk.value());
|
|
||||||
hash_input.extend_from_slice(&cci.to_be_bytes());
|
|
||||||
|
|
||||||
hmac_sha512::HMAC::mac(hash_input, self.ccc)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hash_input.extend_from_slice(&cci.to_be_bytes());
|
||||||
|
|
||||||
|
hmac_sha512::HMAC::mac(hash_input, self.ccc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,16 +63,20 @@ impl KeyNode for ChildKeysPublic {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let csk = nssa::PrivateKey::try_new(
|
let csk = nssa::PrivateKey::try_new({
|
||||||
csk.add_tweak(&Scalar::from_be_bytes(*self.csk.value()).unwrap())
|
#[expect(clippy::big_endian_bytes, reason = "BIP-032 uses big endian")]
|
||||||
|
let scalar = Scalar::from_be_bytes(*self.csk.value()).unwrap();
|
||||||
|
|
||||||
|
csk.add_tweak(&scalar)
|
||||||
.expect("Expect a valid Scalar")
|
.expect("Expect a valid Scalar")
|
||||||
.secret_bytes(),
|
.secret_bytes()
|
||||||
)
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
if secp256k1::constants::CURVE_ORDER < *csk.value() {
|
assert!(
|
||||||
panic!("Secret key cannot exceed curve order");
|
secp256k1::constants::CURVE_ORDER >= *csk.value(),
|
||||||
}
|
"Secret key cannot exceed curve order"
|
||||||
|
);
|
||||||
|
|
||||||
let ccc = *hash_value
|
let ccc = *hash_value
|
||||||
.last_chunk::<32>()
|
.last_chunk::<32>()
|
||||||
@ -105,6 +105,10 @@ impl KeyNode for ChildKeysPublic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[expect(
|
||||||
|
clippy::single_char_lifetime_names,
|
||||||
|
reason = "TODO add meaningful name"
|
||||||
|
)]
|
||||||
impl<'a> From<&'a ChildKeysPublic> for &'a nssa::PrivateKey {
|
impl<'a> From<&'a ChildKeysPublic> for &'a nssa::PrivateKey {
|
||||||
fn from(value: &'a ChildKeysPublic) -> Self {
|
fn from(value: &'a ChildKeysPublic) -> Self {
|
||||||
&value.csk
|
&value.csk
|
||||||
@ -158,7 +162,7 @@ mod tests {
|
|||||||
187, 148, 92, 44, 253, 210, 37,
|
187, 148, 92, 44, 253, 210, 37,
|
||||||
];
|
];
|
||||||
let root_keys = ChildKeysPublic::root(seed);
|
let root_keys = ChildKeysPublic::root(seed);
|
||||||
let cci = (2u32).pow(31) + 13;
|
let cci = (2_u32).pow(31) + 13;
|
||||||
let child_keys = ChildKeysPublic::nth_child(&root_keys, cci);
|
let child_keys = ChildKeysPublic::nth_child(&root_keys, cci);
|
||||||
|
|
||||||
let expected_ccc = [
|
let expected_ccc = [
|
||||||
@ -226,7 +230,7 @@ mod tests {
|
|||||||
187, 148, 92, 44, 253, 210, 37,
|
187, 148, 92, 44, 253, 210, 37,
|
||||||
];
|
];
|
||||||
let root_keys = ChildKeysPublic::root(seed);
|
let root_keys = ChildKeysPublic::root(seed);
|
||||||
let cci = (2u32).pow(31); //equivant to 0, thus non-harden.
|
let cci = (2_u32).pow(31); //equivant to 0, thus non-harden.
|
||||||
let child_keys = ChildKeysPublic::nth_child(&root_keys, cci);
|
let child_keys = ChildKeysPublic::nth_child(&root_keys, cci);
|
||||||
|
|
||||||
let expected_ccc = [
|
let expected_ccc = [
|
||||||
|
|||||||
@ -79,6 +79,7 @@ impl SeedHolder {
|
|||||||
|
|
||||||
impl SecretSpendingKey {
|
impl SecretSpendingKey {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
#[expect(clippy::big_endian_bytes, reason = "BIP-032 uses big endian")]
|
||||||
pub fn generate_nullifier_secret_key(&self, index: Option<u32>) -> NullifierSecretKey {
|
pub fn generate_nullifier_secret_key(&self, index: Option<u32>) -> NullifierSecretKey {
|
||||||
const PREFIX: &[u8; 8] = b"LEE/keys";
|
const PREFIX: &[u8; 8] = b"LEE/keys";
|
||||||
const SUFFIX_1: &[u8; 1] = &[1];
|
const SUFFIX_1: &[u8; 1] = &[1];
|
||||||
@ -100,6 +101,7 @@ impl SecretSpendingKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
#[expect(clippy::big_endian_bytes, reason = "BIP-032 uses big endian")]
|
||||||
pub fn generate_viewing_secret_key(&self, index: Option<u32>) -> ViewingSecretKey {
|
pub fn generate_viewing_secret_key(&self, index: Option<u32>) -> ViewingSecretKey {
|
||||||
const PREFIX: &[u8; 8] = b"LEE/keys";
|
const PREFIX: &[u8; 8] = b"LEE/keys";
|
||||||
const SUFFIX_1: &[u8; 1] = &[2];
|
const SUFFIX_1: &[u8; 1] = &[2];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user