Skip to content

Commit a5cc6a4

Browse files
mv deps to wit/deps, create example crates
tests passing
1 parent 2cf773d commit a5cc6a4

File tree

21 files changed

+88
-140
lines changed

21 files changed

+88
-140
lines changed

crates/seed-keeper-wit-ui/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ package = "seed-keeper:wit-ui"
1818
[package.metadata.component.dependencies]
1919

2020
[package.metadata.component.target.dependencies]
21-
"seed-keeper:wallet" = { path = "../seed-keeper-wit/wit" } # directory containing the WIT package
21+
"component:wallet" = { path = "../seed-keeper-wit/wit/deps/wallet" }

crates/seed-keeper-wit-ui/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use page::Page;
1212

1313
use std::ops::Deref;
1414

15-
use bindings::seed_keeper::wallet::{
15+
use bindings::component::wallet::{
1616
config::{set_config, Credentials},
1717
encrypted::get_encrypted,
1818
};

crates/seed-keeper-wit-ui/wit/index.wit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package seed-keeper:[email protected];
22

33
/// An example world for the component to target.
44
world seedworld {
5-
import seed-keeper:wallet/encrypted@0.1.0;
6-
import seed-keeper:wallet/config@0.1.0;
5+
import component:wallet/encrypted@0.1.0;
6+
import component:wallet/config@0.1.0;
77

88
import wurbo-in;
99
export wurbo-out;

crates/seed-keeper-wit/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ crate-type = ["cdylib"]
2323
package = "component:seed-keeper-wit"
2424

2525
[package.metadata.component.dependencies]
26+
27+
[package.metadata.component.target.dependencies]
28+
"component:wallet" = { path = "wit/deps/wallet" }

crates/seed-keeper-wit/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
cargo_component_bindings::generate!();
44

5-
use crate::bindings::exports::seed_keeper::wallet::{
5+
use crate::bindings::exports::component::wallet::{
66
config::Guest as ConfigGuest, encrypted::Guest as SaverGuest, seed_getter::Guest as KeeperGuest,
77
};
8-
use bindings::seed_keeper::wallet::types::Credentials;
8+
use bindings::component::wallet::types::Credentials;
99

1010
use seed_keeper_core::seed::rand_seed;
1111
use seed_keeper_core::wrap::{decrypt, encrypt};

crates/seed-keeper-wit/tests/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ mod bindgen {
22
wasmtime::component::bindgen!("keeper"); // name of the world in the .wit file
33
}
44

5-
use bindgen::exports::seed_keeper::wallet::config;
5+
use bindgen::exports::component::wallet::config;
66

77
use serde::{Deserialize, Serialize};
88
use std::sync::OnceLock;
@@ -42,7 +42,7 @@ impl WasiView for MyCtx {
4242
static ENCRYPTED_KEY: OnceLock<Vec<u8>> = OnceLock::new();
4343

4444
/// Implementing this trait gives us th ability to add_to_linker using SeedKeeper::add_to_linker
45-
impl bindgen::seed_keeper::wallet::types::Host for MyCtx {}
45+
impl bindgen::component::wallet::types::Host for MyCtx {}
4646

4747
#[derive(Error, Debug)]
4848
pub enum TestError {
@@ -132,14 +132,14 @@ mod wit_tests {
132132
};
133133

134134
bindings
135-
.seed_keeper_wallet_config()
135+
.component_wallet_config()
136136
.call_set_config(&mut store, &config)?
137137
.unwrap();
138138

139139
// Now let's call the functions!
140140
// First, generate the seed by keeping the Credentials encrypted field as None
141141
let seed = bindings
142-
.seed_keeper_wallet_seed_getter()
142+
.component_wallet_seed_getter()
143143
.call_get_seed(&mut store)?
144144
.unwrap();
145145

@@ -150,7 +150,7 @@ mod wit_tests {
150150

151151
// Now get the encrypted seed
152152
let encrypted = bindings
153-
.seed_keeper_wallet_encrypted()
153+
.component_wallet_encrypted()
154154
.call_get_encrypted(&mut store)?
155155
.unwrap();
156156

@@ -208,12 +208,12 @@ mod wit_tests {
208208
};
209209

210210
bindings
211-
.seed_keeper_wallet_config()
211+
.component_wallet_config()
212212
.call_set_config(&mut store, &config)?
213213
.unwrap();
214214

215215
let seed = bindings
216-
.seed_keeper_wallet_seed_getter()
216+
.component_wallet_seed_getter()
217217
.call_get_seed(&mut store)?
218218
.unwrap();
219219

@@ -223,7 +223,7 @@ mod wit_tests {
223223
// Now let's call the functions!
224224
// First, generate the seed by keeping the Credentials encrypted field as None
225225
let encrypted = bindings
226-
.seed_keeper_wallet_encrypted()
226+
.component_wallet_encrypted()
227227
.call_get_encrypted(&mut store)?
228228
.unwrap();
229229

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package component:wallet@0.1.0;
2+
3+
interface config {
4+
/// Import the types interface
5+
use types.{credentials};
6+
7+
/// Load into the component from an encrypted seed, password, and salt (username)
8+
/// Returns the encrypted seed or an error
9+
set-config: func(config: credentials) -> result<_, string>;
10+
}
11+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package component:wallet@0.1.0;
2+
3+
interface encrypted {
4+
/// Returns the encrypted seed or None if it doesn't exist
5+
get-encrypted: func() -> result<list<u8>, string>;
6+
}
7+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package component:wallet@0.1.0;
2+
3+
/// Exported interfaces of dependencies like seed keeper are not exported by the primary component
4+
/// This keeps out seed safely out of the public API
5+
interface seed-getter {
6+
/// Get the plaintext seed
7+
get-seed: func() -> result<list<u8>, string>;
8+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package component:wallet@0.1.0;
2+
3+
interface types {
4+
/// The confuration of the seed keeper
5+
record credentials {
6+
/// The username to use for the seed keeper
7+
username: list<u8>,
8+
9+
/// The password to use for the seed keeper
10+
password: list<u8>,
11+
12+
/// Optional prevously generated encrypted seed to use for the seed keeper
13+
encrypted: option<list<u8>>
14+
}
15+
}
16+

0 commit comments

Comments
 (0)