diff --git a/umbral-pre-wasm/Makefile b/umbral-pre-wasm/Makefile index 08cd06dc..b53dc577 100644 --- a/umbral-pre-wasm/Makefile +++ b/umbral-pre-wasm/Makefile @@ -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 diff --git a/umbral-pre-wasm/patches/api-compatibility.js.txt b/umbral-pre-wasm/patches/api-compatibility.js.txt new file mode 100644 index 00000000..43ae43d3 --- /dev/null +++ b/umbral-pre-wasm/patches/api-compatibility.js.txt @@ -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() +} + + diff --git a/umbral-pre-wasm/src/lib.rs b/umbral-pre-wasm/src/lib.rs index cd4d1e9c..bf818eab 100644 --- a/umbral-pre-wasm/src/lib.rs +++ b/umbral-pre-wasm/src/lib.rs @@ -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 { + pub fn verify_with_only_public_key(&self, verifying_pk: &PublicKey) -> Result { self.0 .verify(&verifying_pk.0, None, None) .map(VerifiedKeyFrag)