[[ ":$PATH:" != *":$HOME/.bky:"* ]] && export PATH="$PATH:$HOME/.bky" ln -sf "$HOME/.bky/bky-as-v0.1.0-beta.13" "$HOME/.bky/bky-as" ## Overview Blocky AS supports more than just performing basic computations. Our WASM environment provides mechanisms for logging, making HTTP calls, verifying attestations, and more. This is done by injecting "host" functions into our WASM runtime. While you can call these directly, it requires adding build tags and memory management code to your functions. For convenience, we have released the [Blocky Web Assembly (BASM) SDK](https://github.com/blocky/basm-go-sdk/tree/main), which contains wrappers for importing and calling our WASM host functions. Below we demonstrate how to use BASM to make an HTTP request. ## Make an HTTP Request 1. Clone the Blocky AS [examples repository](https://github.com/blocky/attestation-service-examples/tree/release/v0.1.0-beta.13) and navigate to the `shipment_tracking_with_dhl` directory: git clone --branch main git@github.com:blocky/attestation-service-examples.git cd attestation-service-examples/shipment_tracking_with_dhl 2. Start by looking at the main WASM function in [main.go](https://github.com/blocky/attestation-service-examples/tree/release/v0.1.0-beta.13/shipment_tracking_with_dhl/main.go). There are four actions taken by our DHL tracking function. First, we use the BASM SDK to read non-sensitive input (i.e., the tracking number) from the host Blocky AS server. Next we read in our secret input (i.e., the API key). Then we use these inputs to make our API call. Finally, we write the response data back to the host Blocky AS server. 3. Now let's look at the function that makes the API call. We construct and make an HTTP request with the BASM SDK. We only need to construct the HTTP request, while BASM handles importing the HTTP host function and writing our request to the Blocky AS server's host memory. Similarly, BASM reads and returns the result of the call from the host to us. 4. Lastly, we use BASM to write our output back to the host Blocky AS server, where it then gets bundled into an attestation and returned to the client. 5. Let's try running the example. The DHL API provides a [Demo key](https://developer.dhl.com/api-reference/shipment-tracking?language_content_entity=en#get-started/) that returns mock responses. Compile and invoke `trackingFunc` with the Demo key: mkdir -p ./tmp bky-c build . ./tmp/x.wasm jq '.secret.api_key = "demo-key"' fn-call.json | bky-as attest-fn-call > out.json 6. Verify the Blocky AS attestations and extract the function claims: jq '{ enclave_attested_application_public_key: .enclave_attested_application_public_key.enclave_attestation, transitive_attested_function_call: .transitive_attested_function_call.transitive_attestation }' out.json | bky-as verify-fn-call > verified.json jq -r ".transitive_attested_function_call.claims" verified.json 7. Verify that the claim values match the function and inputs we specified in our call: openssl dgst -sha3-512 ./tmp/x.wasm jq -rcj '.input' fn-call.json | openssl dgst -sha3-512 jq '.secret.api_key = "demo-key"' fn-call.json | jq -rcj '.secret' | openssl dgst -sha3-512 8. Finally, extract and decode our output: jq -r ".transitive_attested_function_call.claims.output | @base64d | fromjson" verified.json ## Next Steps You can now make HTTP requests from your WASM functions on Blocky AS. Check out our [examples repository](https://github.com/blocky/attestation-service-examples/tree/release/v0.1.0-beta.13) for more HTTP request examples, or read on to learn about bringing your function output [on-chain](/attestation-service/how-tos/on-chain). rm -rf attestation-service-examples