Give the esp32 a random seed, and log the network the ESP32 is on

This commit is contained in:
decentclock
2022-06-24 13:04:51 -06:00
parent e344166a97
commit e1012c620d
2 changed files with 30 additions and 2 deletions

View File

@@ -7,7 +7,8 @@ use vls_protocol::{msgs, serde_bolt::WireString};
use vls_proxy::util::{read_allowlist, read_integration_test_seed};
pub fn blocking_connect(tx: mpsc::Sender<ChannelRequest>) {
let init_msg_2 = crate::init::make_init_msg().expect("could make init msg");
// let init_msg_2 = crate::init::make_init_msg().expect("could make init msg");
let init_msg_2 = crate::init::make_mainnet_init_msg().expect("could make init msg");
let (reply_tx, reply_rx) = oneshot::channel();
// Send a request to the MQTT handler to send to signer
let request = ChannelRequest {
@@ -21,7 +22,8 @@ pub fn blocking_connect(tx: mpsc::Sender<ChannelRequest>) {
}
pub async fn _connect(tx: mpsc::Sender<ChannelRequest>) {
let init_msg_2 = crate::init::make_init_msg().expect("could make init msg");
// let init_msg_2 = crate::init::make_init_msg().expect("could make init msg");
let init_msg_2 = crate::init::make_mainnet_init_msg().expect("could make init msg");
let (reply_tx, reply_rx) = oneshot::channel();
// Send a request to the MQTT handler to send to signer
let request = ChannelRequest {
@@ -60,3 +62,28 @@ pub fn make_init_msg() -> anyhow::Result<Vec<u8>> {
// log::info!("init reply {:?}", init_reply);
// Ok(())
}
pub fn make_mainnet_init_msg() -> anyhow::Result<Vec<u8>> {
let allowlist = read_allowlist()
.into_iter()
.map(|s| WireString(s.as_bytes().to_vec()))
.collect::<Vec<_>>();
let seed = 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]));
// FIXME remove this
log::info!("allowlist {:?} seed {:?}", allowlist, seed);
let init = msgs::HsmdInit2 {
derivation_style: 0,
network_name: WireString("bitcoin".as_bytes().to_vec()),
dev_seed: seed,
dev_allowlist: allowlist,
};
let sequence = 0;
let mut md = MsgDriver::new_empty();
msgs::write_serial_request_header(&mut md, sequence, 0)?;
msgs::write(&mut md, init)?;
Ok(md.bytes())
// msgs::read_serial_response_header(&mut serial, sequence)?;
// let init_reply: msgs::HsmdInit2Reply = msgs::read_message(&mut serial)?;
// log::info!("init reply {:?}", init_reply);
// Ok(())
}

View File

@@ -49,6 +49,7 @@ fn main() -> Result<()> {
esp_idf_svc::log::EspLogger::initialize_default();
thread::sleep(Duration::from_secs(1));
log::info!("Network set to {:?}", network);
let default_nvs = Arc::new(EspDefaultNvs::new()?);
let mut store = EspNvsStorage::new_default(default_nvs.clone(), "sphinx", true).expect("no storage");