Skip to content

Experimental: add ComputeEpochID to WASM #570

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all 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
16 changes: 16 additions & 0 deletions rolling-shutter/shcryptowasm/shutter_crypto_wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func main() {

jsRegistry.Set("encrypt", encrypt)
jsRegistry.Set("decrypt", decrypt)
jsRegistry.Set("computeEpochID", computeEpochID)
jsRegistry.Set("verifyDecryptionKey", verifyDecryptionKey)

// Tell JS we're loaded
Expand Down Expand Up @@ -116,6 +117,21 @@ var verifyDecryptionKey = js.FuncOf(func(this js.Value, args []js.Value) interfa
return ok
})

var computeEpochID = js.FuncOf(func(this js.Value, args []js.Value) interface{} {
if len(args) != 1 {
return encodeResult(nil, fmt.Errorf("expected 1 argument, got %d", len(args)))
}
b, err := decodeBytesArg(args[0], "epochIDBytes")
if err != nil {
return encodeResult(nil, err)
}
e, err := shcrypto.ComputeEpochID(b)
if err != nil {
return encodeResult(nil, err)
}
return encodeResult(e, nil)
}

func encodeResult(encryptedMessage []byte, err error) string {
if err != nil {
return "Error: " + err.Error()
Expand Down