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

Bindings simplification #103

Merged
merged 18 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from 14 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
12 changes: 3 additions & 9 deletions umbral-pre-wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let plaintext_bytes = enc.encode(plaintext);
// The API here slightly differs from that in Rust.
// Since wasm-pack does not support returning tuples, we return an object containing
// the ciphertext and the capsule.
let result = umbral.encrypt(alice_pk, plaintext_bytes);
let {capsule, ciphertext} = umbral.encrypt(alice_pk, plaintext_bytes);
let ciphertext = result.ciphertext;
let capsule = result.capsule;

Expand Down Expand Up @@ -75,14 +75,8 @@ let cfrag1 = umbral.reencrypt(capsule, kfrags[1]);

// Finally, Bob opens the capsule by using at least `threshold` cfrags,
// and then decrypts the re-encrypted ciphertext.

// Another deviation from the Rust API.
// wasm-pack does not support taking arrays as arguments,
// so we build a capsule+cfrags object before decryption.
let plaintext_bob = capsule
.withCFrag(cfrag0)
.withCFrag(cfrag1)
.decryptReencrypted(bob_sk, alice_pk, ciphertext);
let plaintext_bob = umbral.decryptReencrypted(
bob_sk, alice_pk, capsule, [cfrag0, cfrag1], ciphertext);

console.assert(dec.decode(plaintext_bob) === plaintext, "decryptReencrypted() failed");
```
Expand Down
10 changes: 3 additions & 7 deletions umbral-pre-wasm/examples/bundler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ let plaintext_bytes = enc.encode(plaintext);
// The API here slightly differs from that in Rust.
// Since wasm-pack does not support returning tuples, we return an object containing
// the ciphertext and the capsule.
let result = umbral.encrypt(alice_pk, plaintext_bytes);
let ciphertext = result.ciphertext;
let capsule = result.capsule;
let {capsule, ciphertext} = umbral.encrypt(alice_pk, plaintext_bytes);

// Since data was encrypted with Alice's public key, Alice can open the capsule
// and decrypt the ciphertext with her private key.
Expand Down Expand Up @@ -73,10 +71,8 @@ let cfrag1 = umbral.reencrypt(capsule, kfrags[1]);
// Another deviation from the Rust API.
// wasm-pack does not support taking arrays as arguments,
// so we build a capsule+cfrags object before decryption.
let plaintext_bob = capsule
.withCFrag(cfrag0)
.withCFrag(cfrag1)
.decryptReencrypted(bob_sk, alice_pk, ciphertext);
let plaintext_bob = umbral.decryptReencrypted(
bob_sk, alice_pk, capsule, [cfrag0, cfrag1], ciphertext);

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

Expand Down
10 changes: 3 additions & 7 deletions umbral-pre-wasm/examples/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ let plaintext_bytes = enc.encode(plaintext);
// The API here slightly differs from that in Rust.
// Since wasm-pack does not support returning tuples, we return an object containing
// the ciphertext and the capsule.
let result = umbral.encrypt(alice_pk, plaintext_bytes);
let ciphertext = result.ciphertext;
let capsule = result.capsule;
let {capsule, ciphertext} = umbral.encrypt(alice_pk, plaintext_bytes);

// Since data was encrypted with Alice's public key, Alice can open the capsule
// and decrypt the ciphertext with her private key.
Expand Down Expand Up @@ -73,10 +71,8 @@ let cfrag1 = umbral.reencrypt(capsule, kfrags[1]);
// Another deviation from the Rust API.
// wasm-pack does not support taking arrays as arguments,
// so we build a capsule+cfrags object before decryption.
let plaintext_bob = capsule
.withCFrag(cfrag0)
.withCFrag(cfrag1)
.decryptReencrypted(bob_sk, alice_pk, ciphertext);
let plaintext_bob = umbral.decryptReencrypted(
bob_sk, alice_pk, capsule, [cfrag0, cfrag1], ciphertext);

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

Expand Down
10 changes: 3 additions & 7 deletions umbral-pre-wasm/examples/react/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ function App() {
// The API here slightly differs from that in Rust.
// Since wasm-pack does not support returning tuples, we return an object containing
// the ciphertext and the capsule.
let result = umbral.encrypt(alice_pk, plaintext_bytes);
let ciphertext = result.ciphertext;
let capsule = result.capsule;
let {capsule, ciphertext} = umbral.encrypt(alice_pk, plaintext_bytes);

// Since data was encrypted with Alice's public key, Alice can open the capsule
// and decrypt the ciphertext with her private key.
Expand Down Expand Up @@ -106,10 +104,8 @@ function App() {
// Another deviation from the Rust API.
// wasm-pack does not support taking arrays as arguments,
// so we build a capsule+cfrags object before decryption.
let plaintext_bob = capsule
.withCFrag(cfrag0)
.withCFrag(cfrag1)
.decryptReencrypted(bob_sk, alice_pk, ciphertext);
let plaintext_bob = umbral.decryptReencrypted(
bob_sk, alice_pk, capsule, [cfrag0, cfrag1], ciphertext);

console.assert(
dec.decode(plaintext_bob) === plaintext,
Expand Down
8 changes: 3 additions & 5 deletions umbral-pre-wasm/examples/webpack-5-experiments/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let plaintext_bytes = enc.encode(plaintext);
// The API here slightly differs from that in Rust.
// Since wasm-pack does not support returning tuples, we return an object containing
// the ciphertext and the capsule.
let result = umbral.encrypt(alice_pk, plaintext_bytes);
let {capsule, ciphertext} = umbral.encrypt(alice_pk, plaintext_bytes);
let ciphertext = result.ciphertext;
let capsule = result.capsule;

Expand Down Expand Up @@ -73,10 +73,8 @@ let cfrag1 = umbral.reencrypt(capsule, kfrags[1]);
// Another deviation from the Rust API.
// wasm-pack does not support taking arrays as arguments,
// so we build a capsule+cfrags object before decryption.
let plaintext_bob = capsule
.withCFrag(cfrag0)
.withCFrag(cfrag1)
.decryptReencrypted(bob_sk, alice_pk, ciphertext);
let plaintext_bob = umbral.decryptReencrypted(
bob_sk, alice_pk, capsule, [cfrag0, cfrag1], ciphertext);

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

Expand Down
8 changes: 5 additions & 3 deletions umbral-pre/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ serde = { version = "1", default-features = false, features = ["derive"], option
base64 = { version = "0.13", default-features = false, features = ["alloc"] }
pyo3 = { version = "0.16", optional = true }
js-sys = { version = "0.3", optional = true }
wasm-bindgen = {version = "0.2.74", optional = true }
wasm-bindgen = { version = "0.2.74", optional = true }
derive_more = { version = "0.99", optional = true, default_features = false, features = ["as_ref", "from", "into"] }
wasm-bindgen-derive = { version = "0.1", optional = true }

# These packages are among the dependencies of the packages above.
# Their versions should be updated when the main packages above are updated.
Expand All @@ -43,8 +45,8 @@ rmp-serde = "0.15"
[features]
default = ["default-rng"]
bench-internals = ["default-rng"]
bindings-python = ["pyo3", "std"]
bindings-wasm = [ "serde-support", "js-sys", "wasm-bindgen"]
bindings-python = ["pyo3", "std", "derive_more"]
bindings-wasm = ["js-sys", "wasm-bindgen", "derive_more", "wasm-bindgen-derive"]
default-rng = ["getrandom", "rand_core/getrandom"]
serde-support = ["serde"]
std = []
Expand Down
Loading