diff --git a/README.md b/README.md index 495ea93..2aafb56 100644 --- a/README.md +++ b/README.md @@ -40,11 +40,11 @@ Afterwards in your HTML you can include the `wasm_exec.js` and load the binary: ``` -If you have a top-level function `opensslLoaded()` defined, this will be called in the initialization of the `openssl.wasm`. This serves as a notification you do have now access to the top-level functions `encrypt` and `decrypt`: +If you have a top-level function `opensslLoaded()` defined, this will be called in the initialization of the `openssl.wasm`. This serves as a notification you do have now access to the top-level functions `opensslEncrypt` and `opensslDecrypt`: ```javascript -function decrypt(ciphertext, passphrase, callback) {} -function encrypt(plaintext, passphrase, callback) {} +function opensslDecrypt(ciphertext, passphrase, callback) {} +function opensslEncrypt(plaintext, passphrase, callback) {} ``` The functions will not return anything in the moment as in the current state Go WASM support does not have return values. Instead the callback function you've provided will be called and always have two arguments: `function callback(result, error)` - The `result` will be the plaintext on `decrypt` and the ciphertext on `encrypt`. The `error` will either be `null` or a string containing details about the error. When an error occurred the `result` is `null`. diff --git a/example/index.js b/example/index.js index 8e89b60..9d0b7fa 100644 --- a/example/index.js +++ b/example/index.js @@ -5,12 +5,12 @@ function decryptResponse(plaintext, error) { function encryptResponse(ciphertext, error) { console.log(["encryptResponse", ciphertext, error]) if (error === null) { - decrypt(ciphertext, "password", decryptResponse) + opensslDecrypt(ciphertext, "password", decryptResponse) } } function opensslLoaded() { - encrypt("Knut", "password", encryptResponse) + opensslEncrypt("Knut", "password", encryptResponse) } const go = new Go() diff --git a/main.go b/main.go index 95ec9ba..6773e6b 100644 --- a/main.go +++ b/main.go @@ -8,8 +8,8 @@ import ( ) func main() { - js.Global().Set("decrypt", js.NewCallback(decrypt)) - js.Global().Set("encrypt", js.NewCallback(encrypt)) + js.Global().Set("opensslDecrypt", js.NewCallback(decrypt)) + js.Global().Set("opensslEncrypt", js.NewCallback(encrypt)) // Trigger custom "event" if js.Global().Get("opensslLoaded").Type() == js.TypeFunction {