Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/wasm-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- run: sudo ../../contrib/bullseye_deps.sh

# Build NPM package into a tgz file (pack internally triggers the build/prepare script)
- run: npm pack --foreground-scripts
- run: npm install && npm pack --foreground-scripts
name: Build & Pack

# Report the SHA256 digest of the final package. This should be deterministic (including generated WASM),
Expand Down
4 changes: 2 additions & 2 deletions contrib/bullseye_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ unzip -qq ${NDK_FILENAME}
rm ${NDK_FILENAME}
git clone https://github.com/emscripten-core/emsdk
cd emsdk
./emsdk install 3.1.20
./emsdk activate 3.1.20
./emsdk install 3.1.27
./emsdk activate 3.1.27
source ./emsdk_env.sh

apt-get remove --purge curl unzip -yqq
Expand Down
1 change: 1 addition & 0 deletions src/wasm_package/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
libwally_wasm
node_modules
15 changes: 15 additions & 0 deletions src/wasm_package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ $ npm install wallycore

## Example use

With ES modules:

```js
import wally from 'wallycore'

Expand All @@ -25,5 +27,18 @@ wally.tx_free(tx)

If you're using CommonJS, the module can be loaded asynchronously using `const wally = await import('wallycore')` or `import('wallycore').then(wally => { ... })`.

For browser use, you may use a bundler like [webpack](https://webpack.js.org/),
or use the pre-bundled [`wallycore.bundle.js`](wallycore.bundle.js) file which exposes a global `WallyInit` promise that resolves to the module. For example:

```html
<script src="wallycore/wallycore.bundle.min.js"></script>
<script>
WallyInit.then(wally => {
console.log(wally.bip39_get_word(null, 10))
})
// or `const wally = await WallyInit`
</script>
```

## License
[BSD/MIT](https://github.com/ElementsProject/libwally-core/blob/master/LICENSE)
7 changes: 7 additions & 0 deletions src/wasm_package/browser/assert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Minimal shim for nodejs's assert module, for the browser
// For some reason, this doesn't work with the https://github.com/browserify/commonjs-assert shim,
// which causes the webpack bundle to hang when attempting to import it.

export default function assert(val, err='assertion failed') {
if (!val) throw err
}
6 changes: 4 additions & 2 deletions src/wasm_package/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ set -xeo pipefail
# Build WASM (Elements is always enabled)
(cd ../.. && ./tools/build_wasm.sh --enable-elements)
mkdir -p libwally_wasm && cp ../../wally_dist/wallycore.{js,wasm} libwally_wasm/
# Rename to force commonjs mode. See https://github.com/emscripten-core/emscripten/pull/17451
mv libwally_wasm/wallycore.js libwally_wasm/wallycore.cjs
touch libwally_wasm/index # necessary for webpack to work (fixes "Can't resolve './' in 'wasm_package/libwally_wasm'")

# Build browser bundle (to dist/wallycore.bundle.js, see webpack.config.js)
webpack --mode production
2 changes: 1 addition & 1 deletion src/wasm_package/core.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from 'assert'
import InitWallyModule from './libwally_wasm/wallycore.cjs'
import InitWallyModule from './libwally_wasm/wallycore.js'
import { WALLY_OK, WALLY_ERROR, WALLY_EINVAL, WALLY_ENOMEM } from './const.js'

// Initialize the underlying WASM module and expose it publicly
Expand Down
Loading