This task is an example on how to compute a signature verification using the ECDSA algorithm, the one used in EVM blockchains like Ethereum, Polygon, Hyperledger Besu, Avalanche C-Chain and others. It takes several paramaters as an input, all of them contained in an input.txt file provided as example:
Test string that was signed
Signature with the r, s, v components
Address that signed the message
It will return a boolean indicating if the signature validates correctly
Using Truebit to Execute ECDSA verification example
In order to get a verified result, we can use Truebit to execute the sign-verify task.
The code
You can find the ECDSA signature verification example within the folder truebit-nextgen-examples/function-tasks/js/ecdsa-sign-verify
In order to send parameters to the Truebit task, you need to open the "input.txt" file and get the value from there. For now, only one input parameter is allowed.
In order to retrieve the output value from the Truebit task, you need save it in the "output.txt" file.
fs.writeFileSync('output.txt', outputJson);
Try out
Step 1: Create the ecdsa-verify source code
If you are working in JS, remember to run the Rollup command in order to bundle all the code and dependencies within a single main.js file located at /dist folder.
npx rollup -c
You will find a file called main.js within the folder /dist (This is the file generated by the Rollup tool that will be used for testing purposes)
Building the function task
Your function task is ready.
Use the following TaskId for execution or deployment:
js_70f82c303f73ab09ed68dc0fc44829440e8c1838a0b7e0d931dd25e6835be8c2/1.0.0
Step 3: Try the code
In this case, the input parameter is a file containing the address, signature and test data that we want to verify. Please use the file called input.txt located within the root folder.
The function task has been deployed successfully.
The Task <taskName> version <version> was registered successfully in namespace <namespace>
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.
Execute the command against Truebit node to get an instrumented Truebit task
Execute the command against the Truebit node to test our Algorithm. You will need to submit the instrumented task id + the input parameter.
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.