Skip to content

Commit

Permalink
close #23, close #25, add post Make patches
Browse files Browse the repository at this point in the history
  • Loading branch information
vepkenez committed Jul 20, 2021
1 parent 283dbf5 commit c534baa
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
3 changes: 3 additions & 0 deletions umbral-pre-wasm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ pkg: src
cp package.template.json pkg/package.json
cp LICENSE README.md pkg/

# add patches
cat ./patches/api-compatibility.js.txt >> pkg/pkg-bundler/umbral_pre_wasm.js


.PHONY: clean

Expand Down
48 changes: 48 additions & 0 deletions umbral-pre-wasm/patches/api-compatibility.js.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

/*
contents added by umbral-pre-wasm makefile/build script
*/

import { KeyFrag, encryptPlaintext } from "./umbral_pre_wasm_bg.js";

export const decrypt_reencrypted = (
receiving_sk,//: SecretKey,
delegating_pk,//: PublicKey,
capsule,//: Capsule,
verified_cfrags,//: Sequence[VerifiedCapsuleFrag],
ciphertext//: bytes,) => (
) => {
const capsuleWithCFrags = verified_cfrags.reduce((value, cfrag) => {
return value.withCFrag(cfrag)
}, capsule)
return capsuleWithCFrags.decryptReencrypted(receiving_sk, delegating_pk, ciphertext);
}

export function encrypt(delegating_pk, plaintext) {
const encryptionResult = encryptPlaintext(delegating_pk, plaintext)
return {
capsule: encryptionResult.capsule,
ciphertext: encryptionResult.ciphertext
}
}

KeyFrag.prototype.verify = (verifying_pk, optional = {delegating_pk, receiving_pk} = {}) => {
const delegating_pk = optional.delegating_pk
const receiving_pk = optional.receiving_pk

if (receiving_pk && delegating_pk) {
return this.verifyWithDelegatingAndReceivingKeys(verifying_pk, delegating_pk, receiving_pk)
}

if (receiving_pk){
return this.verifyWithReceivingKey(verifying_pk, receiving_pk)
}

if (delegating_pk){
return this.verifyWithDelegatingKey(verifying_pk, delegating_pk)
}

return this.verify_with_only_public_key()
}


2 changes: 1 addition & 1 deletion umbral-pre-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ impl KeyFrag {
// So we have to use 4 functions instead of 1. Yikes.

#[wasm_bindgen]
pub fn verify(&self, verifying_pk: &PublicKey) -> Result<VerifiedKeyFrag, JsValue> {
pub fn verify_with_only_public_key(&self, verifying_pk: &PublicKey) -> Result<VerifiedKeyFrag, JsValue> {
self.0
.verify(&verifying_pk.0, None, None)
.map(VerifiedKeyFrag)
Expand Down

0 comments on commit c534baa

Please sign in to comment.