Skip to content
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

wasm lib integration using webview #103

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ def jscFlavor = 'org.webkit:android-jsc-intl:+'
def enableHermes = project.ext.react.get("enableHermes", false);

android {
aaptOptions {
noCompress "wasm"
}

ndkVersion rootProject.ext.ndkVersion

compileSdkVersion rootProject.ext.compileSdkVersion
Expand Down
3 changes: 2 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="auto"
package="com.mojitowallet">
Expand Down Expand Up @@ -67,6 +67,7 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
</intent-filter>
</activity>

Expand Down
Binary file not shown.
21 changes: 21 additions & 0 deletions android/link-assets-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"migIndex": 1,
"data": [
{
"path": "assets/fonts/Montserrat-Bold.ttf",
"sha1": "bf257f6f91f6522eccea6d4f28d57bb118c98729"
},
{
"path": "assets/fonts/Montserrat-Light_0.ttf",
"sha1": "08e510137064a3c9859b71cff5b999fe8c351e67"
},
{
"path": "assets/fonts/Montserrat-SemiBold.ttf",
"sha1": "4ef29a9163b56df34a3486b98b24be3a3d0cdca6"
},
{
"path": "assets/mintlayer/wasm_crypto_bg.wasm",
"sha1": "c146af2a955dff3172aca7585e744b13d58a0f5d"
}
]
}
Binary file added assets/mintlayer/wasm_crypto_bg.wasm
Binary file not shown.
Empty file.
75 changes: 75 additions & 0 deletions blue_modules/mintlayer/@mintlayerlib-js/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
## Basic wasm bindings for cryptography

##### Note: This was tested on x86_64 Linux, and may not work on other platforms. It didn't work on M1 Mac (particularly the build. A pre-built wasm binary works fine on a browser).

### To run in a web browser

Make sure you have wasm-pack and the wasm32-unknown-unknown target installed:

```
rustup target add wasm32-unknown-unknown
cargo install wasm-pack
```

Also make sure you have `clang` installed. It's required.

To build the wasm package from the crate, run (in the wasm Cargo.toml directory):

```
wasm-pack build --target web
```

**Note for mac users**: `llvm` installed by Xcode doesn't support wasm targets, but the homebrew version does, these commands may make it possible to compile to wasm targets. Note that using these commands could have other side effects on your toolchain. Please consider researching the clang toolchain and how it works before using them. We do not recommend copying and pasting commands without fully understanding the side-effects.

```
brew install llvm
AR=/opt/homebrew/opt/llvm/bin/llvm-ar CC=/opt/homebrew/opt/llvm/bin/clang wasm-pack build --target web
```

To test the wasm binary. First, install `http-server` web server (feel free to use any other web-server of your choosing):

```
cargo install http-server
```

Then run the http server, and then choose the file `js-bindings/index.html`:

```
http-server --port 8080 --verbose
```

If you're using a remote server, either tunnel to port 8080, or expose that port and run this (assuming you understand the security risks):

```
http-server --port 8080 --host 0.0.0.0 --verbose
```

The ported wasm functions are exported to the file `js-bindings/index.js` and used in the file `js-bindings/index.html` with a basic test/example in them using JavaScript. Use your browser's console to see the output.

### To run in Node.js

Make sure you have wasm-pack and the wasm32-unknown-unknown target installed:

```
rustup target add wasm32-unknown-unknown
cargo install wasm-pack
```

Also make sure you have `clang` installed. It's required.

To build the wasm package from the crate, run (in the wasm Cargo.toml directory):

```
wasm-pack build --target nodejs
```

Finally, to run the example, run:

```
node js-bindings/node-entry.js
```

### Further documentation

- https://developer.mozilla.org/en-US/docs/WebAssembly/Rust_to_wasm
- https://rustwasm.github.io/wasm-bindgen/introduction.html
15 changes: 15 additions & 0 deletions blue_modules/mintlayer/@mintlayerlib-js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "wasm-crypto",
"version": "0.3.0",
"license": "MIT",
"files": [
"wasm_crypto_bg.wasm",
"wasm_crypto.js",
"wasm_crypto.d.ts"
],
"module": "wasm_crypto.js",
"types": "wasm_crypto.d.ts",
"sideEffects": [
"./snippets/*"
]
}
Loading
Loading