Truebit Verify
  • Getting Started
    • 📄What is Truebit Verify?
      • How does Truebit work?
      • System Actors
    • ⏱️Get Started
    • ⚙️Architecture
      • Truebit Verify Hub
      • Truebit Verify Nodes
      • What is a transcript?
        • Transcript example
        • API Transcript example
    • Key Concepts
      • What is verification?
      • Determinism
      • WebAssembly
      • Task instrumentation
  • Developing Truebit Tasks
    • Introduction
    • Writing Function Tasks
      • Supported languages
        • Javascript
        • Python
        • Rust
    • Writing API Tasks
    • Task examples
      • Function Task examples
        • Fibonacci
        • Reverse Alphabet
        • Encrypt sha256 using bun.js
        • Encrypt sha256 using Deno
        • ECDSA signature verification
        • NumPy example
      • API Task examples
        • Pet Store CRUD
        • API-Auth examples
    • Namespace management
    • Task Authorization
    • Truebit CLI
      • secret.json
  • Executing Truebit tasks
    • Introduction
    • Task Execution API
      • Execute Function Tasks
      • Execute API Tasks
      • Get Task Status
    • Transcript API
      • Get Transcript
      • Get Invoice
  • Community
    • Truebit Unchained Protocol
    • Support
Powered by GitBook
On this page
  • Description
  • Using Truebit to encrypt sha256 using Deno
  • The code
  • Try out
  • Step 1: Create the sha256 source code
  • Step 2: Build the source code
  • Step 3: Try the code
  • Step 4: Deploy the task

Was this helpful?

  1. Developing Truebit Tasks
  2. Task examples
  3. Function Task examples

Encrypt sha256 using Deno

PreviousEncrypt sha256 using bun.jsNextECDSA signature verification

Last updated 8 days ago

Was this helpful?

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 Deno

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

The code

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

📄 main.js

Try out

We will use the to and our source code. Once the code is finished, we will 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

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

Output

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

Step 3: Try the code

truebit start js_62b57f45a4f6c5f0f1032fad9db66e2db67bed3b2c781c4f9fdf1b151bf7153b Truebit

Output

Executing the function Task
Execution Id: f8881ca9-3d20-41da-9de8-5e789f59f12f
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' │ 2287576597  │ 481      │
│ Nested calls  │ 'Calls'       │ 65536         │ 7255  │ 7216        │ 9        │
│ Frame memory  │ 'Bytes'       │ 524288        │ 22735 │ 21665       │ 23       │
│ System memory │ '64 Kb pages' │ 2048          │ 93    │ '𝚫 1'       │ 22       │
└───────────────┴───────────────┴───────────────┴───────┴─────────────┴──────────┘

Step 4: Deploy the task

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

Output

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

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

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

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

Truebit CLI
compile
try
deploy
API key
build
start
deploy