Skip to content

Commit 8c24cbc

Browse files
feat(async): Add async signers (#22)
* add async for open and update plog, keeps sync as legacy options under flag
1 parent d3d5818 commit 8c24cbc

File tree

29 files changed

+1855
-215
lines changed

29 files changed

+1855
-215
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ bs-traits = { path = "crates/bs-traits" }
5353
bs-wallets = { path = "crates/bs-wallets" }
5454
comrade = { path = "crates/comrade" }
5555
comrade-reference = { path = "crates/comrade-reference" }
56+
futures = "0.3.30"
5657
multibase = { path = "crates/multibase" }
5758
multicid = { path = "crates/multicid" }
5859
multicodec = { path = "crates/multicodec" }

cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ default = ["serde"]
1919
anyhow = "1.0"
2020
async-trait = "0.1"
2121
best-practices.workspace = true
22-
bs.workspace = true
22+
bs = { workspace = true, features = ["sync"] }
2323
bs-traits.workspace = true
2424
clap = { version = "4.5.36", features = ["cargo"] }
2525
colored = "3.0.0"

cli/src/subcmds/plog.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ impl SyncPrepareEphemeralSigning for KeyManager {
8181
) -> Result<
8282
(
8383
<Self as EphemeralKey>::PubKey,
84-
Box<dyn FnOnce(&[u8]) -> Result<<Self as Signer>::Signature, <Self as Signer>::Error>>,
84+
Box<
85+
dyn FnOnce(&[u8]) -> Result<<Self as Signer>::Signature, <Self as Signer>::Error>
86+
+ Send,
87+
>,
8588
),
8689
<Self as Signer>::Error,
8790
> {
@@ -101,7 +104,10 @@ impl SyncPrepareEphemeralSigning for KeyManager {
101104
let public_key = secret_key.conv_view()?.to_public_key()?;
102105

103106
// Create the signing closure that owns the secret key
104-
let sign_once = Box::new(
107+
let sign_once: Box<
108+
dyn FnOnce(&[u8]) -> Result<<Self as Signer>::Signature, <Self as Signer>::Error>
109+
+ Send,
110+
> = Box::new(
105111
move |data: &[u8]| -> Result<<Self as Signer>::Signature, <Self as Signer>::Error> {
106112
debug!("Signing data with ephemeral key");
107113
let signature = secret_key.sign_view()?.sign(data, false, None)?;
@@ -196,7 +202,7 @@ pub async fn go(cmd: Command, _config: &Config) -> Result<(), Error> {
196202
let key_manager = KeyManager::default();
197203

198204
// open the p.log
199-
let plog = open::open_plog(&cfg, &key_manager, &key_manager)?;
205+
let plog = open::open_plog_sync(&cfg, &key_manager, &key_manager)?;
200206

201207
println!("Created p.log {}", writer_name(&output)?.to_string_lossy());
202208
print_plog(&plog)?;
@@ -257,7 +263,7 @@ pub async fn go(cmd: Command, _config: &Config) -> Result<(), Error> {
257263
};
258264

259265
let cfg = update::Config::builder()
260-
.add_entry_lock_scripts(vec![lock_script.clone()])
266+
.with_entry_lock_scripts(vec![lock_script.clone()])
261267
.unlock(unlock_script)
262268
.entry_signing_key(entry_signing_key)
263269
.additional_ops(entry_ops)
@@ -266,7 +272,7 @@ pub async fn go(cmd: Command, _config: &Config) -> Result<(), Error> {
266272
let key_manager = KeyManager::default();
267273

268274
// update the p.log
269-
update::update_plog::<Error>(&mut plog, &cfg, &key_manager, &key_manager)?;
275+
update::update_plog_sync::<Error>(&mut plog, &cfg, &key_manager, &key_manager)?;
270276

271277
println!("Writing p.log {}", writer_name(&output)?.to_string_lossy());
272278
print_plog(&plog)?;

crates/bs-peer/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pkg/

0 commit comments

Comments
 (0)