Crates publish setup (#17)

* Added config.toml to waku crate

* Update gitignore

* Update readme

* Remove private items docs

* Fix docs links

* Refactor waku to waku-bindings crate
Added badges

* Fix links

* Add usage
This commit is contained in:
Daniel Sanchez 2022-11-02 16:21:15 +01:00 committed by GitHub
parent c3ced48966
commit d006ef4ecd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 181 additions and 64 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/target
/Cargo.lock
/.idea
/.fleet

View File

@ -1,7 +1,7 @@
[workspace]
members = [
"waku",
"waku-bindings",
"waku-sys",
"examples/toy-chat"
]

View File

@ -1,3 +1,35 @@
# Waku Rust binding
# Waku Rust bindings
Rust layer on top of `go-waku` c ffi bindings.
Rust layer on top of [`go-waku`](https://github.com/status-im/go-waku) [c ffi bindings](https://github.com/status-im/go-waku/blob/v0.2.2/library/README.md).
## About [Waku](https://waku.org/)
Waku is the communication layer for Web3. Decentralized communication that scales.
Private. Secure. Runs anywhere.
### What is Waku?
Waku is a suite of privacy-preserving, peer-to-peer messaging protocols.
Waku removes centralized third parties from messaging, enabling private, secure, censorship-free communication with no single point of failure.
Waku provides privacy-preserving capabilities, such as sender anonymity,metadata protection and unlinkability to personally identifiable information.
Waku is designed for generalized messaging, enabling human-to-human, machine-to-machine or hybrid communication.
Waku runs everywhere: desktop, server, including resource-restricted devices, such as mobile devices and browsers.
How does it work?
The first version of Waku had its origins in the Whisper protocol, with optimizations for scalability and usability. Waku v2 is a complete rewrite. Its relay protocol implements pub/sub over libp2p, and also introduces additional capabilities:
1. Retrieving historical messages for mostly-offline devices.
2. Adaptive nodes, allowing for heterogeneous nodes to contribute.
3. Bandwidth preservation for light nodes.
This makes it ideal for running a p2p protocol on mobile, or in other similarly resource-restricted environments.
Read the [Waku docs](https://docs.wakuconnect.dev/)

View File

@ -8,7 +8,7 @@ authors = [
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
waku = { path = "../../waku" }
waku = { path = "../../waku-bindings" }
tui = "0.19"
crossterm = "0.25"
unicode-width = "0.1"

View File

@ -0,0 +1,4 @@
[target.'cfg(target_os = "macos")']
# when using osx, we need to link against some golang libraries, it did just work with this missing flags
# from: https://github.com/golang/go/issues/42459
rustflags = ["-C", "link-args=-framework CoreFoundation -framework Security"]

50
waku-bindings/README.md Normal file
View File

@ -0,0 +1,50 @@
# Waku Rust bindings
[<img alt="github" src="https://img.shields.io/badge/github-waku-org/waku-rust-bindings-8da0cb?style=for-the-badge&labelColor=555555&logo=github" height="20">](https://github.com/waku-org/waku-rust-bindings)
[<img alt="crates.io" src="https://img.shields.io/crates/v/waku-bindings.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/waku-rust-bindings)
[<img alt="docs.rs" src="https://img.shields.io/badge/doc/waku-bindings-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs" height="20">](https://docs.rs/waku-rust-bindings)
[<img alt="build status" src="https://img.shields.io/github/workflow/status/waku-org/waku-rust-bindings/CI/master?style=for-the-badge" height="20">](https://github.com/waku-org/waku-rust-bindings/actions?query=branch%3Amaster)
Rust api on top of [`waku-sys`](https://crates.io/crates/waku-sys) bindgen bindings to [c ffi bindings](https://github.com/status-im/go-waku/blob/v0.2.2/library/README.md).
## Usage
Add this to your `Cargo.toml`:
```toml
[dependencies]
waku-bindings = "0.1.0"
```
## About [Waku](https://waku.org/)
Waku is the communication layer for Web3. Decentralized communication that scales.
Private. Secure. Runs anywhere.
### What is Waku?
Waku is a suite of privacy-preserving, peer-to-peer messaging protocols.
Waku removes centralized third parties from messaging, enabling private, secure, censorship-free communication with no single point of failure.
Waku provides privacy-preserving capabilities, such as sender anonymity,metadata protection and unlinkability to personally identifiable information.
Waku is designed for generalized messaging, enabling human-to-human, machine-to-machine or hybrid communication.
Waku runs everywhere: desktop, server, including resource-restricted devices, such as mobile devices and browsers.
How does it work?
The first version of Waku had its origins in the Whisper protocol, with optimizations for scalability and usability. Waku v2 is a complete rewrite. Its relay protocol implements pub/sub over libp2p, and also introduces additional capabilities:
1. Retrieving historical messages for mostly-offline devices.
2. Adaptive nodes, allowing for heterogeneous nodes to contribute.
3. Bandwidth preservation for light nodes.
This makes it ideal for running a p2p protocol on mobile, or in other similarly resource-restricted environments.
Read the [Waku docs](https://docs.wakuconnect.dev/)

View File

@ -38,7 +38,7 @@ pub fn waku_decode_symmetric(
/// Decrypt a message using a symmetric key
///
/// As per the [specification](extern char* waku_decode_asymmetric(char* messageJson, char* privateKey))
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_decode_asymmetricchar-messagejson-char-privatekey)
pub fn waku_decode_asymmetric(
message: &WakuMessage,
asymmetric_key: &SecretKey,

View File

@ -58,9 +58,9 @@ pub(crate) enum JsonResponse<T> {
}
/// Waku response, just a `Result` with an `String` error.
/// Convenient we can transform a [`JsonResponse`] into a [`std::result::Result`]
pub type Result<T> = std::result::Result<T, String>;
/// Convenient we can transform a [`JsonResponse`] into a [`std::result::Result`]
impl<T> From<JsonResponse<T>> for Result<T> {
fn from(response: JsonResponse<T>) -> Self {
match response {
@ -127,14 +127,14 @@ impl WakuMessage {
/// Try decode the message with an expected symmetric key
///
/// wrapper around [`crate::decrypt::waku_decode_symmetric`]
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_decode_symmetricchar-messagejson-char-symmetrickey)
pub fn try_decode_symmetric(&self, symmetric_key: &Key<Aes256Gcm>) -> Result<DecodedPayload> {
waku_decode_symmetric(self, symmetric_key)
}
/// Try decode the message with an expected asymmetric key
///
/// wrapper around [`crate::decrypt::waku_decode_asymmetric`]
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_decode_asymmetricchar-messagejson-char-privatekey)
pub fn try_decode_asymmetric(&self, asymmetric_key: &SecretKey) -> Result<DecodedPayload> {
waku_decode_asymmetric(self, asymmetric_key)
}

View File

@ -61,22 +61,19 @@ unsafe impl<State: WakuNodeState> Sync for WakuNodeHandle<State> {}
impl<State: WakuNodeState> WakuNodeHandle<State> {
/// If the execution is successful, the result is the peer ID as a string (base58 encoded)
///
/// wrapper around [`management::waku_peer_id`]
/// as per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_stop)
pub fn peer_id(&self) -> Result<PeerId> {
management::waku_peer_id()
}
/// Get the multiaddresses the Waku node is listening to
///
/// wrapper around [`management::waku_listen_addresses`]
/// as per [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_listen_addresses)
pub fn listen_addresses(&self) -> Result<Vec<Multiaddr>> {
management::waku_listen_addresses()
}
/// Add a node multiaddress and protocol to the waku nodes peerstore
///
/// wrapper around [`peers::waku_add_peers`]
/// Add a node multiaddress and protocol to the waku nodes peerstore.
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_add_peerchar-address-char-protocolid)
pub fn add_peer(&self, address: &Multiaddr, protocol_id: ProtocolId) -> Result<PeerId> {
peers::waku_add_peers(address, protocol_id)
}
@ -91,16 +88,14 @@ fn stop_node() -> Result<()> {
}
impl WakuNodeHandle<Initialized> {
/// Start a Waku node mounting all the protocols that were enabled during the Waku node instantiation
///
/// wrapper around [`management::waku_start`]
/// Start a Waku node mounting all the protocols that were enabled during the Waku node instantiation.
/// as per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_start)
pub fn start(self) -> Result<WakuNodeHandle<Running>> {
management::waku_start().map(|_| WakuNodeHandle(Default::default()))
}
/// Stops a Waku node
///
/// internally uses [`management::waku_stop`]
/// as per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_stop)
pub fn stop(self) -> Result<()> {
stop_node()
}
@ -108,8 +103,7 @@ impl WakuNodeHandle<Initialized> {
impl WakuNodeHandle<Running> {
/// Stops a Waku node
///
/// internally uses [`management::waku_stop`]
/// as per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_stop)
pub fn stop(self) -> Result<()> {
stop_node()
}
@ -118,8 +112,7 @@ impl WakuNodeHandle<Running> {
/// If `timeout` as milliseconds doesn't fit into a `i32` it is clamped to [`i32::MAX`]
/// If the function execution takes longer than `timeout` value, the execution will be canceled and an error returned.
/// Use 0 for no timeout
///
/// wrapper around [`peers::waku_connect_peer_with_address`]
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_connect_peerchar-address-int-timeoutms)
pub fn connect_peer_with_address(
&self,
address: &Multiaddr,
@ -128,37 +121,35 @@ impl WakuNodeHandle<Running> {
peers::waku_connect_peer_with_address(address, timeout)
}
/// Dial peer using its peer ID
///
/// wrapper around [`peers::waku_connect_peer_with_id`]
/// Dial peer using a peer id
/// If `timeout` as milliseconds doesn't fit into a `i32` it is clamped to [`i32::MAX`]
/// The peer must be already known.
/// It must have been added before with [`WakuNodeHandle::add_peer`] or previously dialed with [`WakuNodeHandle::connect_peer_with_address`]
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_connect_peeridchar-peerid-int-timeoutms)
pub fn connect_peer_with_id(&self, peer_id: PeerId, timeout: Option<Duration>) -> Result<()> {
peers::waku_connect_peer_with_id(peer_id, timeout)
}
/// Disconnect a peer using its peerID
///
/// wrapper around [`peers::waku_disconnect_peer_with_id`]
/// Disconnect a peer using its peer id
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_disconnect_peerchar-peerid)
pub fn disconnect_peer_with_id(&self, peer_id: &PeerId) -> Result<()> {
peers::waku_disconnect_peer_with_id(peer_id)
}
/// Get number of connected peers
///
/// wrapper around [`peers::waku_peer_count`]
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_peer_count)
pub fn peer_count(&self) -> Result<usize> {
peers::waku_peer_count()
}
/// Retrieve the list of peers known by the Waku node
///
/// wrapper around [`peers::waku_peers`]
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_peers)
pub fn peers(&self) -> Result<WakuPeers> {
peers::waku_peers()
}
/// Publish a message using Waku Relay
///
/// wrapper around [`relay::waku_relay_publish_message`]
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_relay_publishchar-messagejson-char-pubsubtopic-int-timeoutms)
pub fn relay_publish_message(
&self,
message: &WakuMessage,
@ -169,8 +160,7 @@ impl WakuNodeHandle<Running> {
}
/// Optionally sign, encrypt using asymmetric encryption and publish a message using Waku Relay
///
/// wrapper around [`relay::waku_relay_publish_encrypt_asymmetric`]
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_relay_publish_enc_asymmetricchar-messagejson-char-pubsubtopic-char-publickey-char-optionalsigningkey-int-timeoutms)
pub fn relay_publish_encrypt_asymmetric(
&self,
message: &WakuMessage,
@ -189,8 +179,7 @@ impl WakuNodeHandle<Running> {
}
/// Optionally sign, encrypt using symmetric encryption and publish a message using Waku Relay
///
/// wrapper around [`relay::waku_relay_publish_encrypt_symmetric`]
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_relay_publish_enc_symmetricchar-messagejson-char-pubsubtopic-char-symmetrickey-char-optionalsigningkey-int-timeoutms)
pub fn relay_publish_encrypt_symmetric(
&self,
message: &WakuMessage,
@ -209,29 +198,24 @@ impl WakuNodeHandle<Running> {
}
/// Determine if there are enough peers to publish a message on a given pubsub topic
///
/// wrapper around [`relay::waku_enough_peers`]
pub fn relay_enough_peers(&self, pubsub_topic: Option<WakuPubSubTopic>) -> Result<bool> {
relay::waku_enough_peers(pubsub_topic)
}
/// Subscribe to a Waku Relay pubsub topic to receive messages
///
/// wrapper around [`relay::waku_relay_subscribe`]
pub fn relay_subscribe(&self, pubsub_topic: Option<WakuPubSubTopic>) -> Result<()> {
relay::waku_relay_subscribe(pubsub_topic)
}
/// Closes the pubsub subscription to a pubsub topic. No more messages will be received from this pubsub topic
///
/// wrapper around [`relay::waku_relay_unsubscribe`]
pub fn relay_unsubscribe(&self, pubsub_topic: Option<WakuPubSubTopic>) -> Result<()> {
relay::waku_relay_unsubscribe(pubsub_topic)
}
/// Retrieves historical messages on specific content topics
///
/// wrapper around [`store::waku_store_query`]
/// Retrieves historical messages on specific content topics. This method may be called with [`PagingOptions`](`crate::general::PagingOptions`),
/// to retrieve historical messages on a per-page basis. If the request included [`PagingOptions`](`crate::general::PagingOptions`),
/// the node must return messages on a per-page basis and include [`PagingOptions`](`crate::general::PagingOptions`) in the response.
/// These [`PagingOptions`](`crate::general::PagingOptions`) must contain a cursor pointing to the Index from which a new page can be requested
pub fn store_query(
&self,
query: &StoreQuery,
@ -242,8 +226,7 @@ impl WakuNodeHandle<Running> {
}
/// Publish a message using Waku Lightpush
///
/// wrapper around [`lightpush::waku_lightpush_publish`]
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_lightpush_publishchar-messagejson-char-topic-char-peerid-int-timeoutms)
pub fn lightpush_publish(
&self,
message: &WakuMessage,
@ -255,8 +238,7 @@ impl WakuNodeHandle<Running> {
}
/// Optionally sign, encrypt using asymmetric encryption and publish a message using Waku Lightpush
///
/// wrapper around [`lightpush::waku_lightpush_publish_encrypt_asymmetric`]
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_lightpush_publish_enc_asymmetricchar-messagejson-char-pubsubtopic-char-peerid-char-publickey-char-optionalsigningkey-int-timeoutms)
pub fn lightpush_publish_encrypt_asymmetric(
&self,
message: &WakuMessage,
@ -277,8 +259,7 @@ impl WakuNodeHandle<Running> {
}
/// Optionally sign, encrypt using symmetric encryption and publish a message using Waku Lightpush
///
/// wrapper around [`lightpush::waku_lightpush_publish_encrypt_symmetric`]
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_lightpush_publish_enc_symmetricchar-messagejson-char-pubsubtopic-char-peerid-char-symmetrickey-char-optionalsigningkey-int-timeoutms)
pub fn lightpush_publish_encrypt_symmetric(
&self,
message: &WakuMessage,
@ -299,8 +280,7 @@ impl WakuNodeHandle<Running> {
}
/// Creates a subscription in a lightnode for messages that matches a content filter and optionally a [`WakuPubSubTopic`](`crate::general::WakuPubSubTopic`)
///
/// wrapper around [`filter::waku_filter_subscribe`]
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_filter_subscribechar-filterjson-char-peerid-int-timeoutms)
pub fn filter_subscribe(
&self,
filter_subscription: &FilterSubscription,
@ -311,8 +291,7 @@ impl WakuNodeHandle<Running> {
}
/// Removes subscriptions in a light node matching a content filter and, optionally, a [`WakuPubSubTopic`](`crate::general::WakuPubSubTopic`)
///
/// wrapper around [`filter::waku_filter_unsubscribe`]
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_filter_unsubscribechar-filterjson-int-timeoutms)
pub fn filter_unsubscribe(
&self,
filter_subscription: &FilterSubscription,
@ -331,8 +310,8 @@ impl WakuNodeHandle<Running> {
}
}
/// Spawn a new Waku node with the givent configuration (default configuration if `None` provided)
/// Internally uses [`management::waku_new`]
/// Spawn a new Waku node with the given configuration (default configuration if `None` provided)
/// as per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_newchar-jsonconfig)
pub fn waku_new(config: Option<WakuNodeConfig>) -> Result<WakuNodeHandle<Initialized>> {
let mut node_initialized = WAKU_NODE_INITIALIZED
.lock()

View File

@ -158,7 +158,7 @@ impl WakuPeerData {
}
}
/// List of [`WakuPeerData`], return value from [`waku_peers`] funtion
/// List of [`WakuPeerData`]
pub type WakuPeers = Vec<WakuPeerData>;
/// Retrieve the list of peers known by the Waku node

View File

@ -28,7 +28,7 @@ pub fn waku_create_content_topic(
.try_into()
.expect("Version should fit within an u32"),
CString::new(content_topic_name)
.expect("Conmtent topic should always transform to CString")
.expect("Content topic should always transform to CString")
.into_raw(),
CString::new(encoding.to_string())
.expect("Encoding should always transform to CString")

51
waku-sys/README.md Normal file
View File

@ -0,0 +1,51 @@
# Waku rust bindgen bindings
[<img alt="github" src="https://img.shields.io/badge/github-waku-org/waku-sys-8da0cb?style=for-the-badge&labelColor=555555&logo=github" height="20">](https://github.com/waku-org/waku-rust-bindings)
[<img alt="crates.io" src="https://img.shields.io/crates/v/waku-sys.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/waku-rust-bindings)
[<img alt="docs.rs" src="https://img.shields.io/badge/doc/waku-sys-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs" height="20">](https://docs.rs/waku-rust-bindings)
[<img alt="build status" src="https://img.shields.io/github/workflow/status/waku-org/waku-rust-bindings/CI/master?style=for-the-badge" height="20">](https://github.com/waku-org/waku-rust-bindings/actions?query=branch%3Amaster)
Rust layer on top of [`go-waku`](https://github.com/status-im/go-waku) [c ffi bindings](https://github.com/status-im/go-waku/blob/v0.2.2/library/README.md).
## Usage
This are autogenerated, if you are looking for a proper Rust API version check on [`waku-bindings`](https://crates.io/crates/waku-bindings)
Add this to your `Cargo.toml`:
```toml
[dependencies]
waku-sys = "0.1.0"
```
## About [Waku](https://waku.org/)
Waku is the communication layer for Web3. Decentralized communication that scales.
Private. Secure. Runs anywhere.
### What is Waku?
Waku is a suite of privacy-preserving, peer-to-peer messaging protocols.
Waku removes centralized third parties from messaging, enabling private, secure, censorship-free communication with no single point of failure.
Waku provides privacy-preserving capabilities, such as sender anonymity,metadata protection and unlinkability to personally identifiable information.
Waku is designed for generalized messaging, enabling human-to-human, machine-to-machine or hybrid communication.
Waku runs everywhere: desktop, server, including resource-restricted devices, such as mobile devices and browsers.
How does it work?
The first version of Waku had its origins in the Whisper protocol, with optimizations for scalability and usability. Waku v2 is a complete rewrite. Its relay protocol implements pub/sub over libp2p, and also introduces additional capabilities:
1. Retrieving historical messages for mostly-offline devices.
2. Adaptive nodes, allowing for heterogeneous nodes to contribute.
3. Bandwidth preservation for light nodes.
This makes it ideal for running a p2p protocol on mobile, or in other similarly resource-restricted environments.
Read the [Waku docs](https://docs.wakuconnect.dev/)