Skip to content

Commit

Permalink
Merge pull request #60 from piotr-roslaniec/packaging
Browse files Browse the repository at this point in the history
Add support for multiple wasm-pack targets
  • Loading branch information
fjarri authored Jul 7, 2021
2 parents e2267b5 + 72b8d0a commit eba7e7f
Show file tree
Hide file tree
Showing 14 changed files with 3,994 additions and 25 deletions.
1 change: 1 addition & 0 deletions umbral-pre-wasm/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
package-lock.json
pkg
5 changes: 0 additions & 5 deletions umbral-pre-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,3 @@ umbral-pre = { path = "../umbral-pre" }
wasm-bindgen = "0.2.74"
js-sys = "0.3.51"
wee_alloc = "0.4"

[package.metadata.wasm-pack.profile.release]
# See https://github.com/rustwasm/wasm-pack/issues/886
# Maybe at some point in time this won't be necessary.
wasm-opt = ["-Oz", "--enable-mutable-globals"]
31 changes: 21 additions & 10 deletions umbral-pre-wasm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,24 @@ SHELL = /bin/bash
build: pkg

pkg: src
wasm-pack build
# temporary fix for https://github.com/rustwasm/wasm-pack/issues/427
# (setting a custom package name)
sed -i ".bak" -e 's/"name": "umbral-pre-wasm"/"name": "umbral-pre"/g' pkg/package.json
# Temporary fix for https://github.com/rustwasm/wasm-pack/issues/922
# (adding missing package files to the manifest)
sed -i ".bak" -e 's/"umbral_pre_wasm_bg.wasm"/"umbral_pre_wasm_bg.wasm", "umbral_pre_wasm_bg.js", "umbral_pre_wasm_bg.wasm.d.ts"/g' pkg/package.json
# Add keywords
sed -i ".bak" -e 's/"sideEffects": false/"sideEffects": false, "keywords": ["umbral", "nucypher"]/g' pkg/package.json
rm pkg/package.json.bak
# Build for both targets
wasm-pack build -t bundler -d pkg/pkg-bundler
wasm-pack build -t nodejs -d pkg/pkg-node

# Clean-up non-essential files
(cd pkg/pkg-bundler && rm package.json README.md .gitignore LICENSE)
(cd pkg/pkg-node && rm package.json README.md .gitignore LICENSE)

# Types are duplicated, clean them up to avoid confusion
mv pkg/pkg-node/umbral_pre_wasm.d.ts pkg/
rm pkg/pkg-bundler/umbral_pre_wasm.d.ts

# Copy template
cp package.template.json pkg/package.json
cp LICENSE README.md pkg/


.PHONY: clean

clean:
rm -rf pkg
27 changes: 21 additions & 6 deletions umbral-pre-wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,32 @@ console.assert(dec.decode(plaintext_bob) == plaintext, "decrypt_reencrypted() fa
## Build

The package is built using [`wasm-pack`](https://github.com/rustwasm/wasm-pack).
Instead of running `wasm-build` directly, use the included `Makefile`, since it has to do some additional actions that `wasm-build` currently does not support.
Instead of running `wasm-build` directly, use the included `Makefile`, since it has to do some additional actions that `wasm-build` currently does not support:

## Running the example

After you have successfully built the WASM package, in the `example` folder run
```bash
$ make
```
$ npm install
$ npm run start

## Running the examples

After you have successfully built the WASM package, run one of the example projects:

### `umbral-pre` in the browser
```bash
$ cd example-bundler
$ yarn install
$ yarn start
```
Go to [localhost:8080](http://localhost:8080/) in your browser and look in the JS console.

### `umbral-pre` in Node.js:
```bash
$ cd example-node
$ yarn install
$ yarn start
```
Inspect console output for results.

[js-npm-image]: https://img.shields.io/npm/v/umbral-pre
[js-npm-link]: https://www.npmjs.com/package/umbral-pre
[js-license-image]: https://img.shields.io/npm/l/umbral-pre
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ let dec = new TextDecoder("utf-8");

// Key Generation (on Alice's side)
let alice_sk = umbral.SecretKey.random();
let alice_pk = umbral.PublicKey.fromSecretKey(alice_sk);
let alice_pk = alice_sk.publicKey();
let signing_sk = umbral.SecretKey.random();
let signer = new umbral.Signer(signing_sk);
let verifying_pk = umbral.PublicKey.fromSecretKey(signing_sk);

// Key Generation (on Bob's side)
let bob_sk = umbral.SecretKey.random();
let bob_pk = umbral.PublicKey.fromSecretKey(bob_sk);
let bob_pk = bob_sk.publicKey();

// Now let's encrypt data with Alice's public key.
// Invocation of `encrypt()` returns both the ciphertext and a capsule.
Expand Down Expand Up @@ -80,3 +79,5 @@ let plaintext_bob = capsule
.decryptReencrypted(bob_sk, alice_pk, ciphertext);

console.assert(dec.decode(plaintext_bob) == plaintext, "decrypt_reencrypted() failed");

console.log("Success!");
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "umbral-pre-example",
"name": "umbral-pre-example-bundler",
"version": "0.1.0",
"description": "A usage example for umbral-pre",
"main": "index.js",
Expand Down
File renamed without changes.
Loading

0 comments on commit eba7e7f

Please sign in to comment.