Skip to content

Make bs wasm32 compatible (merge Comrade + Bestsign chgs) #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 61 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
f8eff73
scaffold comrade & component
DougAnderson444 May 3, 2025
39559f7
add parser
DougAnderson444 May 4, 2025
85d94ba
eval script test passing
DougAnderson444 May 4, 2025
8ae49f0
fix comments
DougAnderson444 May 4, 2025
32f382a
fixup comments
DougAnderson444 May 4, 2025
5a58574
cleanup
DougAnderson444 May 4, 2025
cfa6f97
fix bug in lock/unlock curr/proposed stack push
DougAnderson444 May 4, 2025
6ad18d2
rename crypto to reference
DougAnderson444 May 4, 2025
664a84d
add wasm component
DougAnderson444 May 4, 2025
6fc829c
cleanup
DougAnderson444 May 4, 2025
9ca8903
WIP: Start to scaffold the main API
DougAnderson444 May 8, 2025
aeecb58
nice clean api
DougAnderson444 May 8, 2025
9d2f295
add rustdoc comments
DougAnderson444 May 8, 2025
023bb63
scaffold virtual runtime
DougAnderson444 May 8, 2025
c1b49bf
rename vm -> runtime
DougAnderson444 May 8, 2025
1c8a852
haul in deps for wasm runtime
DougAnderson444 May 8, 2025
5ff10c8
makeruntimes optional and extensible
DougAnderson444 May 9, 2025
a0dbb77
add runtime trait and Runner bounds
DougAnderson444 May 9, 2025
1a7edd0
fix typo
DougAnderson444 May 9, 2025
a35d0b4
scaffold build bytes and justfile recipes
DougAnderson444 May 9, 2025
ddec8dd
set wasmi_runtime_layer to v0.40
DougAnderson444 May 9, 2025
a8b415f
add wasm32 build, test, just recipes
DougAnderson444 May 9, 2025
329359e
random module is for wasm32 only
DougAnderson444 May 9, 2025
d589f0d
add layer definitions
DougAnderson444 May 9, 2025
a1b21a1
use Pairable supertrait
DougAnderson444 May 9, 2025
1ec524e
tested logs
DougAnderson444 May 9, 2025
5440039
impl try_unlock
DougAnderson444 May 9, 2025
05256aa
more tests
DougAnderson444 May 9, 2025
0b6a1f1
test passing!
DougAnderson444 May 9, 2025
0a6cc28
add readme rustdoc tests
DougAnderson444 May 9, 2025
4f0263f
small fixes
DougAnderson444 May 10, 2025
8fae6e5
add direct runtime
DougAnderson444 May 10, 2025
9c04122
switch to direct runtime as default
DougAnderson444 May 10, 2025
cf20a8b
web tests
DougAnderson444 May 10, 2025
1766174
rm dead code
DougAnderson444 May 10, 2025
021e701
use CondSync
DougAnderson444 May 10, 2025
9c619ae
comrade use Pairs only
DougAnderson444 May 12, 2025
006f694
mk comrade worspace dep
DougAnderson444 May 12, 2025
e1cea03
update lifetime
DougAnderson444 May 12, 2025
7e7dee5
fix missing dep (again)
DougAnderson444 May 12, 2025
35dfacd
update trait to incl Error too
DougAnderson444 May 12, 2025
55664cc
update plog and open
DougAnderson444 May 12, 2025
7d6914f
haul in bs-p2p
DougAnderson444 May 12, 2025
4da17d1
use RPITIT instead of async_trait
DougAnderson444 May 12, 2025
fb8a462
use Self::Error assoc type in traits
DougAnderson444 May 12, 2025
3b79da9
add cond_send for wasm32 and native compat
DougAnderson444 May 12, 2025
ccac040
constraint data references by (Cond)Sync bounds
DougAnderson444 May 12, 2025
ad0d902
elide lifetimes where poss, add Panics comments to uncheched fns
DougAnderson444 May 12, 2025
7bd77a8
rm workspace dep with js feat
DougAnderson444 May 13, 2025
b1513a4
trait, associate types, sync and async
DougAnderson444 May 13, 2025
a5f8911
add `with_domain` for non-"/" paths
DougAnderson444 May 13, 2025
7a5a3ff
readme edits
DougAnderson444 May 13, 2025
464d280
add readme
DougAnderson444 May 13, 2025
2c1b3a3
readme
DougAnderson444 May 13, 2025
3df3ccf
use shiny new traits in bs and cli
DougAnderson444 May 14, 2025
a388363
READMEs (plural)
DougAnderson444 May 14, 2025
b1aeac3
README
DougAnderson444 May 14, 2025
f98881a
map_err
DougAnderson444 May 14, 2025
c4767b3
use set_error method
DougAnderson444 May 14, 2025
5649be3
add prev_cid to VerifyIter
DougAnderson444 May 15, 2025
81b2c99
fix comments
DougAnderson444 May 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ members = [
"crates/bs",
"crates/bs-p2p",
"crates/bs-traits",
"crates/comrade",
"crates/comrade-component",
"crates/comrade-reference",
"crates/bs-p2p",
"crates/content-addressable",
"crates/multibase",
"crates/multicid",
Expand All @@ -32,13 +36,15 @@ license = "FSL-1.1 OR Apache-2.0"
unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(feature, values("cargo-clippy"))',
'cfg(fuzzing)',
]}
] }

[workspace.dependencies]
# Crate ependencies
bs = { path = "crates/bs" }
bs-p2p = { path = "crates/bs-p2p" }
bs-traits = { path = "crates/bs-traits" }
comrade = { path = "crates/comrade" }
comrade-reference = { path = "crates/comrade-reference" }
multibase = { path = "crates/multibase" }
multicid = { path = "crates/multicid" }
multicodec = { path = "crates/multicodec" }
Expand All @@ -60,14 +66,23 @@ rand = { version = "0.9.0", features = ["os_rng"] }
rand_core = "0.9.3"
rand_6 = { version = "0.6.4", package = "rand" }
rand_core_6 = { version = "0.6.4", package = "rand_core" }
serde = { version = "1.0.219", default-features = false, features = ["alloc", "derive"]}
serde_cbor = { version = "0.11.2", features = ["tags"]}
serde_json = { version = "1.0.104"}
serde_test = { version = "1.0.104"}
serde = { version = "1.0.219", default-features = false, features = [
"alloc",
"derive",
] }
serde_cbor = { version = "0.11.2", features = ["tags"] }
serde_json = { version = "1.0.104" }
serde_test = { version = "1.0.104" }
sha3 = "0.10.8"
test-log = { version = "0.2.17", features = ["trace", "color"] }
thiserror = "2.0.12"
tokio = { version = "1.44.2", features = ["fs", "io-util", "macros", "rt", "test-util"] }
tokio = { version = "1.44.2", features = [
"fs",
"io-util",
"macros",
"rt",
"test-util",
] }
tracing = "0.1.41"
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
unsigned-varint = { version = "0.8.0", features = ["std"] }
Expand Down
5 changes: 3 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ anyhow = "1.0"
async-trait = "0.1"
best-practices.workspace = true
bs.workspace = true
bs-traits.workspace = true
clap = { version = "4.5.36", features = ["cargo"] }
colored = "3.0.0"
csv = "1.3.1"
Expand All @@ -42,15 +43,15 @@ rustyline = { version = "15.0.0", features = ["derive"] }
serde = { workspace = true, optional = true }
serde_cbor.workspace = true
serde_json.workspace = true
ssh-key = { version = "0.6.2", features = ["crypto", "ed25519"]}
ssh-key = { version = "0.6.2", features = ["crypto", "ed25519"] }
ssh-agent-client-rs = "1.0.0"
structopt = "0.3.26"
thiserror.workspace = true
tokio = { version = "1.44.2", features = ["full"] }
toml = "0.8.20"
tracing.workspace = true
tracing-subscriber.workspace = true
wacc.workspace = true
comrade.workspace = true

[dev-dependencies]
tokio-test = "0.4.4"
9 changes: 9 additions & 0 deletions cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ pub enum Error {
/// Bs errors
#[error(transparent)]
Bs(#[from] bs::Error),

/// Error opening a provenance log
#[error(transparent)]
Open(#[from] bs::error::OpenError),

/// Error updating a provenance log
#[error(transparent)]
Update(#[from] bs::error::UpdateError),

/// Multicid error
#[error(transparent)]
Multicid(#[from] multicid::Error),
Expand Down
108 changes: 59 additions & 49 deletions cli/src/subcmds/plog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/// Plog command
pub mod command;
use bs_traits::{GetKey, Signer, SyncGetKey, SyncSigner};
pub use command::Command;

use crate::{error::PlogError, Config, Error};
Expand All @@ -11,6 +12,7 @@ use bs::{
ops::{open, update},
update::OpParams,
};
use comrade::Pairs;
use multibase::Base;
use multicid::{Cid, EncodedCid, EncodedVlad, Vlad};
use multicodec::Codec;
Expand All @@ -22,7 +24,54 @@ use provenance_log::{Key, Log, Script};
use rng::StdRng;
use std::{collections::VecDeque, convert::TryFrom, path::PathBuf};
use tracing::debug;
use wacc::Pairs;

/// Cli KeyManager
struct KeyManager;

impl GetKey for KeyManager {
type Key = Multikey;

type KeyPath = Key;

type Codec = Codec;

type Error = Error;
}

impl SyncGetKey for KeyManager {
fn get_key(
&self,
key_path: &Self::KeyPath,
codec: &Self::Codec,
threshold: usize,
limit: usize,
) -> Result<Self::Key, Self::Error> {
debug!("Generating {} key ({} of {})...", codec, threshold, limit);
let mut rng = StdRng::from_os_rng();
let mk = mk::Builder::new_from_random_bytes(*codec, &mut rng)?.try_build()?;
let fingerprint = mk.fingerprint_view()?.fingerprint(Codec::Blake3)?;

let ef = EncodedMultihash::new(Base::Base32Z, fingerprint);
debug!("Writing {} key fingerprint: {}", key_path, ef);
let w = writer(&Some(format!("{}.multikey", ef).into()))?;
serde_cbor::to_writer(w, &mk)?;
Ok(mk)
}
}

impl Signer for KeyManager {
type Key = Multikey;

type Signature = Multisig;

type Error = Error;
}

impl SyncSigner for KeyManager {
fn try_sign(&self, key: &Self::Key, data: &[u8]) -> Result<Self::Signature, Self::Error> {
Ok(key.sign_view()?.sign(data, false, None)?)
}
}

/// processes plog subcommands
pub async fn go(cmd: Command, _config: &Config) -> Result<(), Error> {
Expand All @@ -49,29 +98,10 @@ pub async fn go(cmd: Command, _config: &Config) -> Result<(), Error> {
.with_entry_lock_script(&lock_script_path)
.with_entry_unlock_script(&unlock_script_path);

let key_manager = KeyManager;

// open the p.log
let plog = open::open_plog(
cfg,
|key: &Key,
codec: Codec,
threshold: usize,
limit: usize|
-> Result<Multikey, bs::Error> {
debug!("Generating {} key ({} of {})...", codec, threshold, limit);
let mut rng = StdRng::from_os_rng();
let mk = mk::Builder::new_from_random_bytes(codec, &mut rng)?.try_build()?;
let fingerprint = mk.fingerprint_view()?.fingerprint(Codec::Blake3)?;
let ef = EncodedMultihash::new(Base::Base32Z, fingerprint);
debug!("Writing {} key fingerprint: {}", key, ef);
let w = writer(&Some(format!("{}.multikey", ef).into()))?;
serde_cbor::to_writer(w, &mk)?;
Ok(mk)
},
|mk: &Multikey, data: &[u8]| -> Result<Multisig, bs::Error> {
debug!("Signing the first entry");
Ok(mk.sign_view()?.sign(data, false, None)?)
},
)?;
let plog = open::open_plog(cfg, &key_manager, &key_manager)?;

println!("Created p.log {}", writer_name(&output)?.to_string_lossy());
print_plog(&plog)?;
Expand Down Expand Up @@ -122,30 +152,10 @@ pub async fn go(cmd: Command, _config: &Config) -> Result<(), Error> {
.with_entry_signing_key(&entry_signing_key)
.with_entry_unlock_script(&unlock_script_path);

let key_manager = KeyManager;

// update the p.log
update::update_plog(
&mut plog,
cfg,
|key: &Key,
codec: Codec,
threshold: usize,
limit: usize|
-> Result<Multikey, bs::Error> {
debug!("Generating {} key ({} of {})...", codec, threshold, limit);
let mut rng = StdRng::from_os_rng();
let mk = mk::Builder::new_from_random_bytes(codec, &mut rng)?.try_build()?;
let fingerprint = mk.fingerprint_view()?.fingerprint(Codec::Blake3)?;
let ef = EncodedMultihash::new(Base::Base32Z, fingerprint);
debug!("Writing {} key fingerprint: {}", key, ef);
let w = writer(&Some(format!("{}.multikey", ef).into()))?;
serde_cbor::to_writer(w, &mk)?;
Ok(mk)
},
|mk: &Multikey, data: &[u8]| -> Result<Multisig, bs::Error> {
debug!("Signing the first entry");
Ok(mk.sign_view()?.sign(data, false, None)?)
},
)?;
update::update_plog(&mut plog, cfg, &key_manager, &key_manager)?;

println!("Writing p.log {}", writer_name(&output)?.to_string_lossy());
print_plog(&plog)?;
Expand Down Expand Up @@ -298,17 +308,17 @@ where
}
*/

fn get_from_wacc_value<'a, T>(value: &'a wacc::Value) -> Option<T>
fn get_from_wacc_value<'a, T>(value: &'a comrade::Value) -> Option<T>
where
T: TryFrom<&'a [u8]> + EncodingInfo,
BaseEncoded<T, DetectedEncoder>: TryFrom<&'a str>,
{
match value {
wacc::Value::Bin {
comrade::Value::Bin {
hint: _,
data: ref v,
} => T::try_from(v.as_slice()).ok(),
wacc::Value::Str {
comrade::Value::Str {
hint: _,
data: ref s,
} => match BaseEncoded::<T, DetectedEncoder>::try_from(s.as_str()) {
Expand Down
1 change: 0 additions & 1 deletion crates/bs-traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ readme = "README.md"
license = "Functional Source License 1.1"

[dependencies]
async-trait = "0.1"
thiserror.workspace = true

[dev-dependencies]
Expand Down
Loading