Encrypt sha256 using bun.js

Description

This is a simple example of how to calculate a message hash and output the results formatted as a hex string

Using Truebit to encrypt sha256 using bun.js

To get a verified result, we can use Truebit to execute the sha256 task.

The code

You can find the Encrypt sha256 using bun.js example within the folder truebit-nextgen-examples/function-tasks/js/sha256-bunjs

📄 main.js

Try out

We will use the Truebit CLI to compile and try our source code. Once the code is finished, we will deploy it to the coordination hub so that everyone who knows the namespace and taskname.

Step 1: Create the sha256 source code

You will find a file called main.js in the root folder

Step 2: Build the source code

Execute the build command against Truebit node to get an instrumented Truebit task

truebit build truebit-nextgen-examples/function-tasks/js/sha256-bunjs -l js

Output

Building the function task
Your function task is ready.
Use the following TaskId for execution or deployment:
js_dde5e0b4faa67253fce5efb6d8b7bc87c0662813f00de78ac6128fdee0db9a96

Step 3: Try the code

Execute the start command against the Truebit node to test our Algorithm.

truebit start js_dde5e0b4faa67253fce5efb6d8b7bc87c0662813f00de78ac6128fdee0db9a96 Truebit

Output

Executing the function Task
Execution Id: fa1ec9a7-aa7f-4676-a4fc-fedfa7fbd033
Task executed with status: succeed
Task executed with result: 359030d9e4e3b12d50b0b3bec7a25e9491d6618a4432ced99448f947cfc71d01
Task resource usage:
┌───────────────┬───────────────┬───────────────┬───────┬─────────────┬──────────┐
│ (index)       │ Unit          │ Limits        │ Peak  │ Last status │ Capacity │
├───────────────┼───────────────┼───────────────┼───────┼─────────────┼──────────┤
│ Gas           │ 'Steps'       │ 1099511627776 │ 'N/A' │ 7114147279  │ 155      │
│ Nested calls  │ 'Calls'       │ 65536         │ 15011 │ 14964       │ 4        │
│ Frame memory  │ 'Bytes'       │ 524288        │ 46220 │ 44909       │ 11       │
│ System memory │ '64 Kb pages' │ 2048          │ 160   │ '𝚫 1'       │ 13       │
└───────────────┴───────────────┴───────────────┴───────┴─────────────┴──────────┘

Step 4: Deploy the task

Last, but not least, Execute the deploy command to deploy our task to the coordination hub, so that anyone with the namespace, taskname and the API key can execute it.

truebit deploy <namespace> <taskname> --taskId js_dde5e0b4faa67253fce5efb6d8b7bc87c0662813f00de78ac6128fdee0db9a96

Output

The function task has been deployed successfully.
The Task <taskName> version <version> was registered successfully in namespace <namespace>

Last updated

Was this helpful?