Skip to content

Commit

Permalink
feat: add shared SDK lib to SDK package
Browse files Browse the repository at this point in the history
  • Loading branch information
jurevans committed Dec 18, 2024
1 parent 15f5fa5 commit 11539e9
Show file tree
Hide file tree
Showing 35 changed files with 12,101 additions and 17 deletions.
6,271 changes: 6,271 additions & 0 deletions packages/sdk/lib/Cargo.lock

Large diffs are not rendered by default.

91 changes: 91 additions & 0 deletions packages/sdk/lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
[package]
name = "namada-sdk-wasm"
authors = ["Heliax AG <[email protected]>"]
version = "1.0.0"
edition = "2021"
repository = "https://github.com/anoma/namada-interface/"
description = "Shared functionality from Namada protocol"
license = "MIT"

[lib]
crate-type = ["cdylib", "rlib"]

[features]
default = []
dev = []
multicore = ["rayon", "wasm-bindgen-rayon", "namada_sdk/multicore"]
nodejs = []
web = []

[build-dependencies]
namada_tx = { git = "https://github.com/anoma/namada", rev = "49a4a5d3260423df19ead14df82d18a51fa9b157" }

[dependencies]
async-trait = {version = "0.1.51"}
tiny-bip39 = "0.8.2"
chrono = "0.4.22"
getrandom = { version = "0.2.7", features = ["js"] }
gloo-utils = { version = "0.1.5", features = ["serde"] }
js-sys = "0.3.60"
namada_sdk = { git = "https://github.com/anoma/namada", rev="49a4a5d3260423df19ead14df82d18a51fa9b157", default-features = false }
rand = "0.8.5"
rayon = { version = "1.5.3", optional = true }
rexie = "0.5"
serde = "^1.0.181"
serde_json = "1.0"
tendermint-config = "0.34.0"
tokio = {version = "1.8.2", features = ["rt"]}
thiserror = "^1"
wasm-bindgen = "0.2.86"
wasm-bindgen-futures = "0.4.33"
wasm-bindgen-rayon = { version = "1.0", optional = true }
console_error_panic_hook = "0.1.6"
zeroize = "1.6.0"
hex = "0.4.3"
reqwest = "0.11.25"
subtle-encoding = "0.5.1"

[dependencies.web-sys]
version = "0.3.4"
features = [
'console',
'Document',
'Event',
'EventTarget',
'CustomEvent',
'CustomEventInit',
'Headers',
'Request',
'RequestInit',
'RequestMode',
'Response',
'Window',
'WorkerGlobalScope'
]

[dev-dependencies]
wasm-bindgen-test = "0.3.13"

# https://doc.rust-lang.org/cargo/reference/profiles.html
[profile.release]
lto = true

[profile.dev]
opt-level = 3
lto = true

# wasm-pack specific configuration
[package.metadata.wasm-pack.profile.release]
# https://docs.rs/wasm-opt/latest/wasm_opt/
wasm-opt = ['-O4']

[package.metadata.wasm-pack.profile.dev]
wasm-opt = false

[package.metadata.wasm-pack.profile.dev.wasm-bindgen]
omit-default-module-path = true
# We set it to false as it checks if return type from setTimout is a number which is not true in the nodejs environment
debug-js-glue = false

[package.metadata.wasm-pack.profile.release.wasm-bindgen]
omit-default-module-path = true
25 changes: 25 additions & 0 deletions packages/sdk/lib/LICENSE_MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright (c) 2018 Heliax Dev <[email protected]>

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
25 changes: 25 additions & 0 deletions packages/sdk/lib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# shared lib

Rust library for wrapping Namada types and functionality and compiling to wasm, as used by Namada Interface and the wallet extension.

## Usage

```bash
# Install wasm-bindgen-cli
cargo install -f wasm-bindgen-cli

# Build wasm
../scripts/build.sh

# Build wasm to a NodeJS target (for testing)
../scripts/build-test.sh
```

## Testing

```bash
cargo test

# Test wasm-specific features
wasm-pack test --node
```
4 changes: 4 additions & 0 deletions packages/sdk/lib/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[toolchain]
channel = "nightly-2024-09-08"
components = ["rustc", "cargo", "rust-std", "rust-docs", "rls", "rust-src", "rust-analysis"]
targets = ['wasm32-unknown-unknown']
22 changes: 22 additions & 0 deletions packages/sdk/lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//! # shared
//!
//! A library of functions to integrate shared functionality from the Namada ecosystem
pub mod query;
pub mod rpc_client;
pub mod sdk;
pub mod types;
mod utils;

#[cfg(feature = "multicore")]
pub use wasm_bindgen_rayon::init_thread_pool;

// Empty function for non-multicore builds
// Simplifies imports in js code
#[cfg(not(feature = "multicore"))]
use wasm_bindgen::prelude::wasm_bindgen;

#[cfg(not(feature = "multicore"))]
#[allow(non_snake_case)]
#[wasm_bindgen]
pub async fn initThreadPool(_threads: u8) {}
Loading

0 comments on commit 11539e9

Please sign in to comment.