Skip to content

Commit 63d1e37

Browse files
authored
Merge pull request #74 from kinode-dao/develop
Develop 0.7.1
2 parents b7c0abe + fa88aa5 commit 63d1e37

File tree

17 files changed

+140
-42
lines changed

17 files changed

+140
-42
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
# # published.
4545
# #
4646
# # We *could* pass through `--no-verify` so `cargo` doesn't build the crate before publishing,
47-
# # which is reasonable, since this job only runs after the Linux, Windows, and WASM builds
47+
# # which is reasonable, since this job only runs after the Linux, Windows, and Wasm builds
4848
# # have passed.
4949
# - name: "cargo release publish"
5050
# run: |-

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "kinode_process_lib"
33
description = "A library for writing Kinode processes in Rust."
4-
version = "0.7.0"
4+
version = "0.7.1"
55
edition = "2021"
66
license-file = "LICENSE"
77
homepage = "https://kinode.org"

src/homepage.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use crate::Request;
2+
3+
/// Add a new icon and/or widget to the Kinode homepage. Note that the process calling this
4+
/// function must have the `homepage:homepage:sys` messaging capability.
5+
///
6+
/// An icon must be a base64 encoded SVG.
7+
///
8+
/// A path will be automatically placed underneath the namespace of the process. For example,
9+
/// if the process is named `my:process:pkg`, and the path given is `/mypath`, the full path
10+
/// will be `my:process:pkg/mypath`.
11+
///
12+
/// A widget should be HTML: it will be displayed in an iframe.
13+
pub fn add_to_homepage(label: &str, icon: Option<&str>, path: Option<&str>, widget: Option<&str>) {
14+
Request::to(("our", "homepage", "homepage", "sys"))
15+
.body(
16+
serde_json::json!({
17+
"Add": {
18+
"label": label,
19+
"icon": icon,
20+
"path": path,
21+
"widget": widget
22+
}
23+
})
24+
.to_string(),
25+
)
26+
.send()
27+
.unwrap();
28+
}

src/http.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use thiserror::Error;
1515
// these types are a copy of the types used in http module of runtime.
1616
//
1717

18-
/// HTTP Request type that can be shared over WASM boundary to apps.
18+
/// HTTP Request type that can be shared over Wasm boundary to apps.
1919
/// This is the one you receive from the `http_server:distro:sys` service.
2020
#[derive(Debug, Serialize, Deserialize)]
2121
pub enum HttpServerRequest {
@@ -51,7 +51,7 @@ pub struct IncomingHttpRequest {
5151
// BODY is stored in the lazy_load_blob, as bytes
5252
}
5353

54-
/// HTTP Response type that can be shared over WASM boundary to apps.
54+
/// HTTP Response type that can be shared over Wasm boundary to apps.
5555
/// Respond to [`IncomingHttpRequest`] with this type.
5656
#[derive(Debug, Serialize, Deserialize)]
5757
pub struct HttpResponse {
@@ -287,7 +287,7 @@ impl IncomingHttpRequest {
287287
}
288288
}
289289

290-
/// Request type that can be shared over WASM boundary to apps.
290+
/// Request type that can be shared over Wasm boundary to apps.
291291
/// This is the one you send to the `http_client:distro:sys` service.
292292
#[derive(Debug, Serialize, Deserialize)]
293293
pub enum HttpClientAction {
@@ -306,7 +306,7 @@ pub enum HttpClientAction {
306306
},
307307
}
308308

309-
/// HTTP Request type that can be shared over WASM boundary to apps.
309+
/// HTTP Request type that can be shared over Wasm boundary to apps.
310310
/// This is the one you send to the `http_client:distro:sys` service.
311311
#[derive(Debug, Serialize, Deserialize)]
312312
pub struct OutgoingHttpRequest {
@@ -318,7 +318,7 @@ pub struct OutgoingHttpRequest {
318318
// TIMEOUT is stored in the message expect_response
319319
}
320320

321-
/// WebSocket Client Request type that can be shared over WASM boundary to apps.
321+
/// WebSocket Client Request type that can be shared over Wasm boundary to apps.
322322
/// This comes from an open websocket client connection in the `http_client:distro:sys` service.
323323
#[derive(Debug, Serialize, Deserialize)]
324324
pub enum HttpClientRequest {
@@ -331,7 +331,7 @@ pub enum HttpClientRequest {
331331
},
332332
}
333333

334-
/// HTTP Client Response type that can be shared over WASM boundary to apps.
334+
/// HTTP Client Response type that can be shared over Wasm boundary to apps.
335335
/// This is the one you receive from the `http_client:distro:sys` service.
336336
#[derive(Debug, Serialize, Deserialize)]
337337
pub enum HttpClientResponse {

src/lib.rs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! kinode process standard library for Rust compiled to WASM
1+
//! Kinode process standard library for Rust compiled to Wasm
22
//! Must be used in context of bindings generated by `kinode.wit`.
33
//!
44
//! This library provides a set of functions for interacting with the kinode
@@ -24,6 +24,11 @@ wit_bindgen::generate!({
2424

2525
/// Interact with the eth provider module.
2626
pub mod eth;
27+
/// Interact with the system homepage.
28+
///
29+
/// Note that your process must have the capability to message
30+
/// `homepage:homepage:sys` to use this module.
31+
pub mod homepage;
2732
/// Interact with the HTTP server and client modules.
2833
/// Contains types from the `http` crate to use as well.
2934
pub mod http;
@@ -43,27 +48,19 @@ pub mod timer;
4348
/// Interact with the virtual filesystem
4449
pub mod vfs;
4550

46-
// Types
47-
48-
mod package_id;
49-
pub use package_id::PackageId;
50-
mod process_id;
51-
pub use process_id::{ProcessId, ProcessIdParseError};
52-
mod address;
53-
pub use address::{Address, AddressParseError};
54-
mod request;
55-
pub use request::Request;
56-
mod response;
57-
pub use response::Response;
58-
mod message;
59-
use message::wit_message_to_message;
60-
pub use message::{Message, SendError, SendErrorKind};
61-
mod on_exit;
62-
pub use on_exit::OnExit;
63-
mod capability;
64-
pub use capability::Capability;
65-
mod lazy_load_blob;
66-
pub use lazy_load_blob::LazyLoadBlob;
51+
mod types;
52+
pub use types::{
53+
address::{Address, AddressParseError},
54+
capability::Capability,
55+
lazy_load_blob::LazyLoadBlob,
56+
message::wit_message_to_message,
57+
message::{Message, SendError, SendErrorKind},
58+
on_exit::OnExit,
59+
package_id::PackageId,
60+
process_id::{ProcessId, ProcessIdParseError},
61+
request::Request,
62+
response::Response,
63+
};
6764

6865
/// Implement the wit-bindgen specific code that the kernel uses to hook into
6966
/// a process. Write an `init(our: Address)` function and call it with this.
@@ -221,7 +218,7 @@ pub fn get_capability(our: &Address, params: &str) -> Option<Capability> {
221218
.cloned()
222219
}
223220

224-
/// get the next message body from the message queue, or propagate the error
221+
/// Get the next message body from the message queue, or propagate the error
225222
pub fn await_next_message_body() -> Result<Vec<u8>, SendError> {
226223
match await_message() {
227224
Ok(msg) => Ok(msg.body().to_vec()),

src/net.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,50 @@ where
122122
valid
123123
})
124124
}
125+
126+
/// take a DNSwire-formatted node ID from chain and convert it to a String
127+
pub fn dnswire_decode(wire_format_bytes: &[u8]) -> Result<String, DnsDecodeError> {
128+
let mut i = 0;
129+
let mut result = Vec::new();
130+
131+
while i < wire_format_bytes.len() {
132+
let len = wire_format_bytes[i] as usize;
133+
if len == 0 {
134+
break;
135+
}
136+
let end = i + len + 1;
137+
let mut span = match wire_format_bytes.get(i + 1..end) {
138+
Some(span) => span.to_vec(),
139+
None => return Err(DnsDecodeError::FormatError),
140+
};
141+
span.push('.' as u8);
142+
result.push(span);
143+
i = end;
144+
}
145+
146+
let flat: Vec<_> = result.into_iter().flatten().collect();
147+
148+
let name = String::from_utf8(flat).map_err(|e| DnsDecodeError::Utf8Error(e))?;
149+
150+
// Remove the trailing '.' if it exists (it should always exist)
151+
if name.ends_with('.') {
152+
Ok(name[0..name.len() - 1].to_string())
153+
} else {
154+
Ok(name)
155+
}
156+
}
157+
158+
#[derive(Clone, Debug, thiserror::Error)]
159+
pub enum DnsDecodeError {
160+
Utf8Error(std::string::FromUtf8Error),
161+
FormatError,
162+
}
163+
164+
impl std::fmt::Display for DnsDecodeError {
165+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
166+
match self {
167+
DnsDecodeError::Utf8Error(e) => write!(f, "UTF-8 error: {}", e),
168+
DnsDecodeError::FormatError => write!(f, "Format error"),
169+
}
170+
}
171+
}
File renamed without changes.

0 commit comments

Comments
 (0)