[[ ":$PATH:" != *":$HOME/.bky:"* ]] && export PATH="$PATH:$HOME/.bky"
ln -sf "$HOME/.bky/bky-as-v0.1.0-beta.13" "$HOME/.bky/bky-as"
git clone --branch main git@github.com:blocky/attestation-service-examples.git
cd attestation-service-examples/attest_fn_call
bky-c build --reproducible . ./main.wasm

## Overview

The Blocky AS CLI allows you to send [WebAssembly (WASM)](https://webassembly.org/)
functions for execution on a TEE in a serverless compute model.
The Blocky AS TEE server returns an attestation document, which can be used
to verify the correct execution of your function and its output.

## Attest a WASM Function

Follow the steps below to run the program you compiled from the
[previous section](/attestation-service/tutorials/compile-a-function).

1. The `bky-as attest-fn-call` command expects a JSON object as input. This
object must contain the location of the WASM binary and the name of the function
to invoke.
An example of this can be seen in
[fn-call.json](https://github.com/blocky/attestation-service-examples/tree/release/v0.1.0-beta.13/attest_fn_call/fn-call.json):
jq -r '.' fn-call.json
2. Run our `helloWorld` function and save the resulting output to `out.json`:
cat fn-call.json | bky-as attest-fn-call > out.json
3. There are several objects returned by the Blocky AS server, but for now we
are only going to look at those related to the inputs and outputs of our function:
jq -r '.transitive_attested_function_call.claims' out.json
Notice that `hash_of_code` matches the hash value we calculated for our
WASM binary in the [previous section](/attestation-service/tutorials/compile-a-function)! Thus, we
know the Blocky AS server ran our WASM binary exactly as we compiled it.
Additionally, there are hash values for identifying any inputs and secrets
provided to the function, which we can use to confirm that our inputs and
secrets were unmodified. *If no input or secret is passed, then a hash of an
empty array is used instead.*
4. Extract and decode our function's output:
jq -r '.transitive_attested_function_call.claims.output | @base64d' out.json


## Next Steps

At this point, you can now reproducibly build and run WASM functions on TEEs!
Continue to the next section to learn about verifying your function output
with the attestation information returned by the Blocky AS.

rm -rf attestation-service-examples