mirror of
https://github.com/stakwork/sphinx-key.git
synced 2025-12-19 16:24:29 +01:00
Update to sphinx-key-1.2
Add network parameter to broker Implement StartingTimeFactory
This commit is contained in:
@@ -6,10 +6,10 @@ default-run = "sphinx-key-broker"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
vls-protocol = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "sphinx-key-1.1" }
|
vls-protocol = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "sphinx-key-1.2" }
|
||||||
vls-proxy = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "sphinx-key-1.1" }
|
vls-proxy = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "sphinx-key-1.2" }
|
||||||
vls-frontend = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "sphinx-key-1.1" }
|
vls-frontend = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "sphinx-key-1.2" }
|
||||||
vls-protocol-client = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "sphinx-key-1.1" }
|
vls-protocol-client = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "sphinx-key-1.2" }
|
||||||
rumqttd = { git = "https://github.com/Evanfeenstra/rumqtt", branch = "metrics" }
|
rumqttd = { git = "https://github.com/Evanfeenstra/rumqtt", branch = "metrics" }
|
||||||
pretty_env_logger = "0.4.0"
|
pretty_env_logger = "0.4.0"
|
||||||
confy = "0.4.0"
|
confy = "0.4.0"
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ 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 clap::{App, AppSettings, Arg};
|
||||||
|
use bitcoin::Network;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::{mpsc, oneshot};
|
use tokio::sync::{mpsc, oneshot};
|
||||||
@@ -50,6 +51,12 @@ fn main() -> anyhow::Result<()> {
|
|||||||
.long("dev-disconnect")
|
.long("dev-disconnect")
|
||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("network")
|
||||||
|
.about("Bitcoin network the broker will run on")
|
||||||
|
.long("network")
|
||||||
|
.default_value("regtest"),
|
||||||
|
)
|
||||||
.arg(Arg::from("--log-io ignored dev flag"))
|
.arg(Arg::from("--log-io ignored dev flag"))
|
||||||
.arg(Arg::from("--version show a dummy version"))
|
.arg(Arg::from("--version show a dummy version"))
|
||||||
.arg(Arg::from("--test run a test against the embedded device"));
|
.arg(Arg::from("--test run a test against the embedded device"));
|
||||||
@@ -69,9 +76,20 @@ fn main() -> anyhow::Result<()> {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut network = Network::Regtest;
|
||||||
|
if let Some(network_arg) = matches.value_of("network") {
|
||||||
|
network = match network_arg {
|
||||||
|
"bitcoin" => Network::Bitcoin,
|
||||||
|
"mainnet" => Network::Bitcoin,
|
||||||
|
"testnet" => Network::Testnet,
|
||||||
|
"signet" => Network::Signet,
|
||||||
|
_ => Network::Regtest,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
let (tx, rx) = mpsc::channel(1000);
|
let (tx, rx) = mpsc::channel(1000);
|
||||||
let (status_tx, mut status_rx) = mpsc::channel(1000);
|
let (status_tx, mut status_rx) = mpsc::channel(1000);
|
||||||
log::info!("=> start broker");
|
log::info!("=> start broker on network: {}", network);
|
||||||
let runtime = start_broker(rx, status_tx, "sphinx-1");
|
let runtime = start_broker(rx, status_tx, "sphinx-1");
|
||||||
log::info!("=> wait for connected status");
|
log::info!("=> wait for connected status");
|
||||||
// wait for connection = true
|
// wait for connection = true
|
||||||
@@ -85,6 +103,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
let frontend = Frontend::new(
|
let frontend = Frontend::new(
|
||||||
Arc::new(SignerPortFront {
|
Arc::new(SignerPortFront {
|
||||||
signer_port: Box::new(signer_port),
|
signer_port: Box::new(signer_port),
|
||||||
|
network,
|
||||||
}),
|
}),
|
||||||
Url::parse(&btc_url).expect("malformed btc rpc url"),
|
Url::parse(&btc_url).expect("malformed btc rpc url"),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# vls-protocol = { path = "../../../evanf/validating-lightning-signer/vls-protocol" }
|
# vls-protocol = { path = "../../../evanf/validating-lightning-signer/vls-protocol" }
|
||||||
vls-protocol = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "sphinx-key-1.1" }
|
vls-protocol = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "sphinx-key-1.2" }
|
||||||
serde = { version = "1.0", default-features = false }
|
serde = { version = "1.0", default-features = false }
|
||||||
serde_bolt = { version = "0.2", default-features = false }
|
serde_bolt = { version = "0.2", default-features = false }
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lightning-signer-core = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "sphinx-key-1.1", default-features = false, features = ["std", "secp-lowmemory"] }
|
lightning-signer-core = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "sphinx-key-1.2", default-features = false, features = ["std", "secp-lowmemory"] }
|
||||||
lightning-signer-server = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "sphinx-key-1.1", default-features = false, features = ["persist", "secp-lowmemory"] }
|
lightning-signer-server = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "sphinx-key-1.2", default-features = false, features = ["persist", "secp-lowmemory"] }
|
||||||
serde = { version = "1.0.105" }
|
serde = { version = "1.0.105" }
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
fsdb = "0.1.11"
|
fsdb = "0.1.11"
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ sphinx-key-parser = { path = "../parser" }
|
|||||||
sphinx-key-persister = { path = "../persister" }
|
sphinx-key-persister = { path = "../persister" }
|
||||||
# vls-protocol-signer = { path = "../../../evanf/validating-lightning-signer/vls-protocol-signer", default-features = false, features = ["std", "secp-lowmemory"] }
|
# vls-protocol-signer = { path = "../../../evanf/validating-lightning-signer/vls-protocol-signer", default-features = false, features = ["std", "secp-lowmemory"] }
|
||||||
# vls-protocol-signer = { git = "https://gitlab.com/lightning-signer/validating-lightning-signer", default-features = false, features = ["secp-lowmemory"] }
|
# vls-protocol-signer = { git = "https://gitlab.com/lightning-signer/validating-lightning-signer", default-features = false, features = ["secp-lowmemory"] }
|
||||||
vls-protocol-signer = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "sphinx-key-1.1", default-features = false, features = ["std", "secp-lowmemory"] }
|
lightning-signer-core = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "sphinx-key-1.2" }
|
||||||
|
vls-protocol-signer = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "sphinx-key-1.2", default-features = false, features = ["std", "secp-lowmemory"] }
|
||||||
anyhow = {version = "1", features = ["backtrace"]}
|
anyhow = {version = "1", features = ["backtrace"]}
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
rand = { version = "0.8" }
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
|
mod randomstartingtime;
|
||||||
|
|
||||||
use lightning_signer::persist::Persist;
|
use lightning_signer::persist::Persist;
|
||||||
|
use randomstartingtime::RandomStartingTimeFactory;
|
||||||
// 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;
|
||||||
@@ -35,8 +38,16 @@ pub fn init(bytes: Vec<u8>, network: Network) -> anyhow::Result<InitResponse> {
|
|||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
log::info!("allowlist {:?}", allowlist);
|
log::info!("allowlist {:?}", allowlist);
|
||||||
let seed = init.dev_seed.as_ref().map(|s| s.0).expect("no seed");
|
let seed = init.dev_seed.as_ref().map(|s| s.0).expect("no seed");
|
||||||
|
let starting_time_factory = RandomStartingTimeFactory::new();
|
||||||
log::info!("create root handler now");
|
log::info!("create root handler now");
|
||||||
let root_handler = RootHandler::new(network, 0, Some(seed), persister, allowlist);
|
let root_handler = RootHandler::new(
|
||||||
|
network,
|
||||||
|
0,
|
||||||
|
Some(seed),
|
||||||
|
persister,
|
||||||
|
allowlist,
|
||||||
|
&starting_time_factory,
|
||||||
|
);
|
||||||
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))
|
||||||
|
|||||||
17
signer/src/randomstartingtime.rs
Normal file
17
signer/src/randomstartingtime.rs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
use lightning_signer::signer::StartingTimeFactory;
|
||||||
|
use rand::{rngs::OsRng, RngCore};
|
||||||
|
|
||||||
|
/// A starting time factory which uses entropy from the RNG
|
||||||
|
pub(crate) struct RandomStartingTimeFactory {}
|
||||||
|
|
||||||
|
impl StartingTimeFactory for RandomStartingTimeFactory {
|
||||||
|
fn starting_time(&self) -> (u64, u32) {
|
||||||
|
(OsRng.next_u64(), OsRng.next_u32())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RandomStartingTimeFactory {
|
||||||
|
pub(crate) fn new() -> Box<dyn StartingTimeFactory> {
|
||||||
|
Box::new(RandomStartingTimeFactory {})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ pingpong = []
|
|||||||
no_persist = []
|
no_persist = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
libc = "=0.2.127"
|
||||||
bitflags = "1.3.2"
|
bitflags = "1.3.2"
|
||||||
esp-idf-sys = { version = "0.31.6", features = ["binstart"] }
|
esp-idf-sys = { version = "0.31.6", features = ["binstart"] }
|
||||||
sphinx-key-signer = { path = "../signer", optional = true }
|
sphinx-key-signer = { path = "../signer", optional = true }
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ edition = "2018"
|
|||||||
sphinx-key-signer = { path = "../signer" }
|
sphinx-key-signer = { path = "../signer" }
|
||||||
sphinx-key-parser = { path = "../parser" }
|
sphinx-key-parser = { path = "../parser" }
|
||||||
sphinx-key-crypter = { path = "../crypter" }
|
sphinx-key-crypter = { path = "../crypter" }
|
||||||
vls-protocol = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "sphinx-key-1.1" }
|
vls-protocol = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "sphinx-key-1.2" }
|
||||||
vls-protocol-signer = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "sphinx-key-1.1", default-features = false, features = ["std", "secp-lowmemory"] }
|
vls-protocol-signer = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "sphinx-key-1.2", default-features = false, features = ["std", "secp-lowmemory"] }
|
||||||
# vls-protocol = { path = "../../../evanf/validating-lightning-signer/vls-protocol" }
|
# vls-protocol = { path = "../../../evanf/validating-lightning-signer/vls-protocol" }
|
||||||
# vls-protocol-signer = { path = "../../../evanf/validating-lightning-signer/vls-protocol-signer", default-features = false, features = ["std", "secp-lowmemory"] }
|
# vls-protocol-signer = { path = "../../../evanf/validating-lightning-signer/vls-protocol-signer", default-features = false, features = ["std", "secp-lowmemory"] }
|
||||||
anyhow = {version = "1", features = ["backtrace"]}
|
anyhow = {version = "1", features = ["backtrace"]}
|
||||||
|
|||||||
Reference in New Issue
Block a user