mirror of
https://github.com/stakwork/sphinx-key.git
synced 2025-12-21 17:24:23 +01:00
cargo fmt
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
use crate::ChannelRequest;
|
use crate::ChannelRequest;
|
||||||
|
use bitcoin::Network;
|
||||||
use sphinx_key_parser as parser;
|
use sphinx_key_parser as parser;
|
||||||
use sphinx_key_parser::MsgDriver;
|
use sphinx_key_parser::MsgDriver;
|
||||||
use tokio::sync::{mpsc, oneshot};
|
use tokio::sync::{mpsc, oneshot};
|
||||||
use vls_protocol::model::Secret;
|
use vls_protocol::model::Secret;
|
||||||
use vls_protocol::{msgs, serde_bolt::WireString};
|
use vls_protocol::{msgs, serde_bolt::WireString};
|
||||||
use vls_proxy::util::{read_allowlist, read_integration_test_seed};
|
use vls_proxy::util::{read_allowlist, read_integration_test_seed};
|
||||||
use bitcoin::Network;
|
|
||||||
|
|
||||||
pub fn blocking_connect(tx: mpsc::Sender<ChannelRequest>, network: Network) {
|
pub fn blocking_connect(tx: mpsc::Sender<ChannelRequest>, network: Network) {
|
||||||
let init_msg_2 = crate::init::make_init_msg(network).expect("couldnt make init msg");
|
let init_msg_2 = crate::init::make_init_msg(network).expect("couldnt make init msg");
|
||||||
@@ -40,8 +40,12 @@ pub fn make_init_msg(network: Network) -> anyhow::Result<Vec<u8>> {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|s| WireString(s.as_bytes().to_vec()))
|
.map(|s| WireString(s.as_bytes().to_vec()))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let seed = if network==Network::Bitcoin {
|
let seed = if network == Network::Bitcoin {
|
||||||
Some(Secret([0x8c, 0xe8, 0x62, 0xab, 0xd5, 0x6b, 0xb4, 0x6a, 0x61, 0x7f, 0xaf, 0x13, 0x50, 0xc1, 0xca, 0xf5, 0xb1, 0xee, 0x02, 0x97, 0xbf, 0xf3, 0xb8, 0xc9, 0x56, 0x63, 0x58, 0x9f, 0xec, 0x8c, 0x45, 0x79]))
|
Some(Secret([
|
||||||
|
0x8c, 0xe8, 0x62, 0xab, 0xd5, 0x6b, 0xb4, 0x6a, 0x61, 0x7f, 0xaf, 0x13, 0x50, 0xc1,
|
||||||
|
0xca, 0xf5, 0xb1, 0xee, 0x02, 0x97, 0xbf, 0xf3, 0xb8, 0xc9, 0x56, 0x63, 0x58, 0x9f,
|
||||||
|
0xec, 0x8c, 0x45, 0x79,
|
||||||
|
]))
|
||||||
} else {
|
} else {
|
||||||
read_integration_test_seed()
|
read_integration_test_seed()
|
||||||
.map(|s| Secret(s))
|
.map(|s| Secret(s))
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ mod util;
|
|||||||
use crate::chain_tracker::MqttSignerPort;
|
use crate::chain_tracker::MqttSignerPort;
|
||||||
use crate::mqtt::start_broker;
|
use crate::mqtt::start_broker;
|
||||||
use crate::unix_fd::SignerLoop;
|
use crate::unix_fd::SignerLoop;
|
||||||
use clap::{App, AppSettings, Arg};
|
|
||||||
use bitcoin::Network;
|
use bitcoin::Network;
|
||||||
|
use clap::{App, AppSettings, Arg};
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::{mpsc, oneshot};
|
use tokio::sync::{mpsc, oneshot};
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ use librumqttd::{
|
|||||||
Config,
|
Config,
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::sync::{LazyLock, Mutex};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::sync::{LazyLock, Mutex};
|
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use tokio::time::timeout;
|
use tokio::time::timeout;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
use fsdb::{Bucket, DoubleBucket, Fsdb};
|
use fsdb::{Bucket, DoubleBucket, Fsdb};
|
||||||
use lightning_signer_server::lightning_signer;
|
|
||||||
use lightning_signer::bitcoin::secp256k1::PublicKey;
|
use lightning_signer::bitcoin::secp256k1::PublicKey;
|
||||||
use lightning_signer::chain::tracker::ChainTracker;
|
use lightning_signer::chain::tracker::ChainTracker;
|
||||||
use lightning_signer::channel::{Channel, ChannelId, ChannelStub};
|
use lightning_signer::channel::{Channel, ChannelId, ChannelStub};
|
||||||
@@ -7,6 +6,7 @@ use lightning_signer::monitor::ChainMonitor;
|
|||||||
use lightning_signer::node::{NodeConfig, NodeState as CoreNodeState};
|
use lightning_signer::node::{NodeConfig, NodeState as CoreNodeState};
|
||||||
use lightning_signer::persist::Persist;
|
use lightning_signer::persist::Persist;
|
||||||
use lightning_signer::policy::validator::EnforcementState;
|
use lightning_signer::policy::validator::EnforcementState;
|
||||||
|
use lightning_signer_server::lightning_signer;
|
||||||
use lightning_signer_server::persist::model::{
|
use lightning_signer_server::persist::model::{
|
||||||
AllowlistItemEntry, ChainTrackerEntry, ChannelEntry, NodeEntry, NodeStateEntry,
|
AllowlistItemEntry, ChainTrackerEntry, ChannelEntry, NodeEntry, NodeStateEntry,
|
||||||
};
|
};
|
||||||
@@ -48,7 +48,13 @@ fn get_channel_key(channel_id: &[u8]) -> &[u8] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Persist for FsPersister {
|
impl Persist for FsPersister {
|
||||||
fn new_node(&self, node_id: &PublicKey, config: &NodeConfig, state: &CoreNodeState, seed: &[u8]) {
|
fn new_node(
|
||||||
|
&self,
|
||||||
|
node_id: &PublicKey,
|
||||||
|
config: &NodeConfig,
|
||||||
|
state: &CoreNodeState,
|
||||||
|
seed: &[u8],
|
||||||
|
) {
|
||||||
let pk = hex::encode(node_id.serialize());
|
let pk = hex::encode(node_id.serialize());
|
||||||
let state_entry = state.into();
|
let state_entry = state.into();
|
||||||
let _ = self.states.put(&pk, state_entry);
|
let _ = self.states.put(&pk, state_entry);
|
||||||
@@ -198,7 +204,6 @@ impl Persist for FsPersister {
|
|||||||
excess_amount: 0,
|
excess_amount: 0,
|
||||||
log_prefix: "".to_string(),
|
log_prefix: "".to_string(),
|
||||||
velocity_control: state_entry.velocity_control.into(),
|
velocity_control: state_entry.velocity_control.into(),
|
||||||
|
|
||||||
};
|
};
|
||||||
let entry = CoreNodeEntry {
|
let entry = CoreNodeEntry {
|
||||||
seed: node.seed,
|
seed: node.seed,
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
mod randomstartingtime;
|
mod randomstartingtime;
|
||||||
|
|
||||||
pub use vls_protocol_signer::lightning_signer;
|
|
||||||
pub use vls_protocol_signer::vls_protocol;
|
|
||||||
use lightning_signer::persist::Persist;
|
|
||||||
use lightning_signer::policy::simple_validator::{make_simple_policy, SimpleValidatorFactory};
|
|
||||||
use lightning_signer::policy::filter::PolicyFilter;
|
|
||||||
use lightning_signer::node::NodeServices;
|
use lightning_signer::node::NodeServices;
|
||||||
|
use lightning_signer::persist::Persist;
|
||||||
|
use lightning_signer::policy::filter::PolicyFilter;
|
||||||
|
use lightning_signer::policy::simple_validator::{make_simple_policy, SimpleValidatorFactory};
|
||||||
use lightning_signer::util::clock::StandardClock;
|
use lightning_signer::util::clock::StandardClock;
|
||||||
use lightning_signer::util::velocity::{VelocityControlIntervalType, VelocityControlSpec};
|
use lightning_signer::util::velocity::{VelocityControlIntervalType, VelocityControlSpec};
|
||||||
use randomstartingtime::RandomStartingTimeFactory;
|
use randomstartingtime::RandomStartingTimeFactory;
|
||||||
|
pub use vls_protocol_signer::lightning_signer;
|
||||||
|
pub use vls_protocol_signer::vls_protocol;
|
||||||
// use lightning_signer::persist::DummyPersister;
|
// use lightning_signer::persist::DummyPersister;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use vls_protocol::model::PubKey;
|
use vls_protocol::model::PubKey;
|
||||||
@@ -62,13 +62,7 @@ pub fn init(bytes: Vec<u8>, network: Network) -> anyhow::Result<InitResponse> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
log::info!("create root handler now");
|
log::info!("create root handler now");
|
||||||
let root_handler = RootHandler::new(
|
let root_handler = RootHandler::new(network, 0, Some(seed), allowlist, services);
|
||||||
network,
|
|
||||||
0,
|
|
||||||
Some(seed),
|
|
||||||
allowlist,
|
|
||||||
services,
|
|
||||||
);
|
|
||||||
log::info!("root_handler created");
|
log::info!("root_handler created");
|
||||||
let init_reply = root_handler
|
let init_reply = root_handler
|
||||||
.handle(Message::HsmdInit2(init))
|
.handle(Message::HsmdInit2(init))
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use vls_protocol_signer::lightning_signer;
|
|
||||||
use lightning_signer::signer::StartingTimeFactory;
|
use lightning_signer::signer::StartingTimeFactory;
|
||||||
use rand::{rngs::OsRng, RngCore};
|
use rand::{rngs::OsRng, RngCore};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use vls_protocol_signer::lightning_signer;
|
||||||
|
|
||||||
/// A starting time factory which uses entropy from the RNG
|
/// A starting time factory which uses entropy from the RNG
|
||||||
pub(crate) struct RandomStartingTimeFactory {}
|
pub(crate) struct RandomStartingTimeFactory {}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::conn::html;
|
use crate::conn::html;
|
||||||
use crate::core::config::{Config, ConfigDTO, ecdh_keypair, decrypt_seed};
|
use crate::core::config::{decrypt_seed, ecdh_keypair, Config, ConfigDTO};
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::sync::{Arc, Condvar, Mutex};
|
use std::sync::{Arc, Condvar, Mutex};
|
||||||
@@ -19,14 +19,19 @@ pub struct Params {
|
|||||||
|
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
pub fn config_server(mutex: Arc<(Mutex<Option<Config>>, Condvar)>) -> Result<idf::Server> {
|
pub fn config_server(mutex: Arc<(Mutex<Option<Config>>, Condvar)>) -> Result<idf::Server> {
|
||||||
|
|
||||||
let (sk1, pk1) = ecdh_keypair();
|
let (sk1, pk1) = ecdh_keypair();
|
||||||
|
|
||||||
let server = idf::ServerRegistry::new()
|
let server = idf::ServerRegistry::new()
|
||||||
.at("/")
|
.at("/")
|
||||||
.get(|_| Ok(html::HTML.into()))?
|
.get(|_| Ok(html::HTML.into()))?
|
||||||
.at("/ecdh")
|
.at("/ecdh")
|
||||||
.get(move |_| Ok(format!("{{\"pubkey\":\"{}\"}}", hex::encode(pk1.serialize())).to_owned().into()))?
|
.get(move |_| {
|
||||||
|
Ok(
|
||||||
|
format!("{{\"pubkey\":\"{}\"}}", hex::encode(pk1.serialize()))
|
||||||
|
.to_owned()
|
||||||
|
.into(),
|
||||||
|
)
|
||||||
|
})?
|
||||||
.at("/config")
|
.at("/config")
|
||||||
.post(move |request| {
|
.post(move |request| {
|
||||||
let bod = &request
|
let bod = &request
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
pub mod wifi;
|
mod html;
|
||||||
pub mod http;
|
pub mod http;
|
||||||
pub mod mqtt;
|
pub mod mqtt;
|
||||||
pub mod sntp;
|
pub mod sntp;
|
||||||
mod html;
|
pub mod wifi;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use esp_idf_svc::sntp::EspSntp;
|
use esp_idf_svc::sntp::EspSntp;
|
||||||
use esp_idf_svc::sntp::SyncStatus::Completed;
|
use esp_idf_svc::sntp::SyncStatus::Completed;
|
||||||
use std::time::Duration;
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
pub fn sync_time() {
|
pub fn sync_time() {
|
||||||
let sntp = EspSntp::new_default().unwrap();
|
let sntp = EspSntp::new_default().unwrap();
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ use crate::conn;
|
|||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::convert::TryInto;
|
||||||
use std::sync::{Arc, Condvar, Mutex};
|
use std::sync::{Arc, Condvar, Mutex};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::convert::TryInto;
|
|
||||||
|
|
||||||
use embedded_svc::wifi::*;
|
use embedded_svc::wifi::*;
|
||||||
use esp_idf_svc::nvs::*;
|
use esp_idf_svc::nvs::*;
|
||||||
@@ -13,7 +13,7 @@ use esp_idf_svc::wifi::*;
|
|||||||
use sphinx_crypter::chacha::{decrypt, PAYLOAD_LEN};
|
use sphinx_crypter::chacha::{decrypt, PAYLOAD_LEN};
|
||||||
use sphinx_crypter::ecdh::{derive_shared_secret_from_slice, PUBLIC_KEY_LEN};
|
use sphinx_crypter::ecdh::{derive_shared_secret_from_slice, PUBLIC_KEY_LEN};
|
||||||
use sphinx_crypter::secp256k1::rand::thread_rng;
|
use sphinx_crypter::secp256k1::rand::thread_rng;
|
||||||
use sphinx_crypter::secp256k1::{Secp256k1, SecretKey, PublicKey};
|
use sphinx_crypter::secp256k1::{PublicKey, Secp256k1, SecretKey};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
@@ -52,8 +52,7 @@ pub fn ecdh_keypair() -> (SecretKey, PublicKey) {
|
|||||||
pub fn decrypt_seed(dto: ConfigDTO, sk1: SecretKey) -> Result<Config> {
|
pub fn decrypt_seed(dto: ConfigDTO, sk1: SecretKey) -> Result<Config> {
|
||||||
let their_pk = hex::decode(dto.pubkey)?;
|
let their_pk = hex::decode(dto.pubkey)?;
|
||||||
let their_pk_bytes: [u8; PUBLIC_KEY_LEN] = their_pk[..PUBLIC_KEY_LEN].try_into()?;
|
let their_pk_bytes: [u8; PUBLIC_KEY_LEN] = their_pk[..PUBLIC_KEY_LEN].try_into()?;
|
||||||
let shared_secret =
|
let shared_secret = derive_shared_secret_from_slice(their_pk_bytes, sk1.secret_bytes())?;
|
||||||
derive_shared_secret_from_slice(their_pk_bytes, sk1.secret_bytes())?;
|
|
||||||
// decrypt seed
|
// decrypt seed
|
||||||
let cipher_seed = hex::decode(dto.seed)?;
|
let cipher_seed = hex::decode(dto.seed)?;
|
||||||
let cipher: [u8; PAYLOAD_LEN] = cipher_seed[..PAYLOAD_LEN].try_into()?;
|
let cipher: [u8; PAYLOAD_LEN] = cipher_seed[..PAYLOAD_LEN].try_into()?;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::conn::mqtt::{QOS, RETURN_TOPIC, TOPIC};
|
use crate::conn::mqtt::{QOS, RETURN_TOPIC, TOPIC};
|
||||||
use crate::core::init::make_init_msg;
|
|
||||||
use crate::core::config::Config;
|
use crate::core::config::Config;
|
||||||
|
use crate::core::init::make_init_msg;
|
||||||
|
|
||||||
use sphinx_key_signer::lightning_signer::bitcoin::Network;
|
use sphinx_key_signer::lightning_signer::bitcoin::Network;
|
||||||
use sphinx_key_signer::vls_protocol::model::PubKey;
|
use sphinx_key_signer::vls_protocol::model::PubKey;
|
||||||
@@ -43,7 +43,7 @@ pub fn make_event_loop(
|
|||||||
network: Network,
|
network: Network,
|
||||||
do_log: bool,
|
do_log: bool,
|
||||||
led_tx: mpsc::Sender<Status>,
|
led_tx: mpsc::Sender<Status>,
|
||||||
config: Config
|
config: Config,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
while let Ok(event) = rx.recv() {
|
while let Ok(event) = rx.recv() {
|
||||||
log::info!("BROKER IP AND PORT: {}", config.broker);
|
log::info!("BROKER IP AND PORT: {}", config.broker);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use sphinx_key_signer::MsgDriver;
|
use sphinx_key_signer::lightning_signer::bitcoin::Network;
|
||||||
use sphinx_key_signer::vls_protocol::model::Secret;
|
use sphinx_key_signer::vls_protocol::model::Secret;
|
||||||
use sphinx_key_signer::vls_protocol::{msgs, serde_bolt::WireString};
|
use sphinx_key_signer::vls_protocol::{msgs, serde_bolt::WireString};
|
||||||
use sphinx_key_signer::lightning_signer::bitcoin::Network;
|
use sphinx_key_signer::MsgDriver;
|
||||||
|
|
||||||
pub fn make_init_msg(network: Network, seed: [u8; 32]) -> anyhow::Result<Vec<u8>> {
|
pub fn make_init_msg(network: Network, seed: [u8; 32]) -> anyhow::Result<Vec<u8>> {
|
||||||
let allowlist = Vec::new();
|
let allowlist = Vec::new();
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
pub mod events;
|
|
||||||
pub mod config;
|
pub mod config;
|
||||||
|
pub mod events;
|
||||||
pub mod init;
|
pub mod init;
|
||||||
@@ -106,7 +106,7 @@ fn main() -> Result<()> {
|
|||||||
.put_raw("config", &conf[..])
|
.put_raw("config", &conf[..])
|
||||||
.expect("could not store config");
|
.expect("could not store config");
|
||||||
println!("CONFIG SAVED");
|
println!("CONFIG SAVED");
|
||||||
loop {};
|
loop {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
use crate::core::events::Status;
|
use crate::core::events::Status;
|
||||||
use embedded_hal::delay::blocking::DelayUs;
|
use embedded_hal::delay::blocking::DelayUs;
|
||||||
use esp_idf_hal::delay::Ets;
|
use esp_idf_hal::delay::Ets;
|
||||||
use esp_idf_hal::{gpio, rmt};
|
|
||||||
use esp_idf_hal::rmt::config::TransmitConfig;
|
use esp_idf_hal::rmt::config::TransmitConfig;
|
||||||
use esp_idf_hal::rmt::{FixedLengthSignal, PinState, Pulse, Transmit};
|
use esp_idf_hal::rmt::{FixedLengthSignal, PinState, Pulse, Transmit};
|
||||||
|
use esp_idf_hal::{gpio, rmt};
|
||||||
|
use std::collections::BTreeMap;
|
||||||
use std::sync::{mpsc, Arc, Mutex};
|
use std::sync::{mpsc, Arc, Mutex};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::collections::BTreeMap;
|
|
||||||
|
|
||||||
type Color = u32;
|
type Color = u32;
|
||||||
type Time = u32;
|
type Time = u32;
|
||||||
@@ -34,7 +34,7 @@ fn states() -> BTreeMap<Status, (Color, Time)> {
|
|||||||
pub fn led_control_loop(
|
pub fn led_control_loop(
|
||||||
gpio8: gpio::Gpio8<gpio::Unknown>,
|
gpio8: gpio::Gpio8<gpio::Unknown>,
|
||||||
channel0: rmt::CHANNEL0,
|
channel0: rmt::CHANNEL0,
|
||||||
rx: mpsc::Receiver<Status>
|
rx: mpsc::Receiver<Status>,
|
||||||
) {
|
) {
|
||||||
let led = gpio8.into_output().unwrap();
|
let led = gpio8.into_output().unwrap();
|
||||||
let config = TransmitConfig::new().clock_divider(1);
|
let config = TransmitConfig::new().clock_divider(1);
|
||||||
@@ -68,7 +68,10 @@ impl Led {
|
|||||||
self.blink_length = blink_length;
|
self.blink_length = blink_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn blink(&mut self, transmit: Arc<Mutex<Transmit<gpio::Gpio8<gpio::Output>, rmt::CHANNEL0>>>) {
|
pub fn blink(
|
||||||
|
&mut self,
|
||||||
|
transmit: Arc<Mutex<Transmit<gpio::Gpio8<gpio::Output>, rmt::CHANNEL0>>>,
|
||||||
|
) {
|
||||||
// Prepare signal
|
// Prepare signal
|
||||||
let mut tx = transmit.lock().unwrap();
|
let mut tx = transmit.lock().unwrap();
|
||||||
let ticks_hz = tx.counter_clock().unwrap();
|
let ticks_hz = tx.counter_clock().unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user