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

Add support for multiple wasm-pack targets #60

Merged
merged 2 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
fjarri marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 3 additions & 1 deletion umbral-pre-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ 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"]
# wasm-opt = ["-Oz", "--enable-mutable-globals"]
# TODO: wasm-opt fails with error "Error: failed to execute `wasm-opt`: exited with signal: 11"
fjarri marked this conversation as resolved.
Show resolved Hide resolved
wasm-opt = false
30 changes: 20 additions & 10 deletions umbral-pre-wasm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@ 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 -R pkg-template/* pkg/


.PHONY: clean

clean:
rm -rf pkg
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
Loading