Javascript
To execute Function Tasks, you may need to perform additional steps before creating them. Please refer to the following instructions to create a Function Task in Javascript.
Last updated
Was this helpful?
Was this helpful?
npm i rollup
npm inpx rollup -cimport nodeResolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
export default [
{
input: 'src/main.js',
output: {
file: 'dist/main.js',
format: 'es',
name: 'fibonacci',
},
plugins: [nodeResolve(), commonjs()],
},
];import crypto from 'crypto';import crypto from 'crypto';
function main() {
const message = 'truebit'.repeat(5000);
let i = 100;
while (i--) {
const hash = crypto.createHash('sha256');
const result = hash.update(message).digest('hex');
console.log(result);
}
}
main();import crypto from 'webcrypto';import crypto from 'webcrypto';
import TextEncoder from 'encoding';
function buf2hex(buffer) {
return [...new Uint8Array(buffer)]
.map(x => x.toString(16).padStart(2, '0'))
.join('');
}
async function main() {
const message = 'truebit'.repeat(5000);
const encoder = new TextEncoder('ascii');
const data = encoder.encode(message).buffer;
let i = 100;
while (i--) {
const hash = await crypto.subtle.digest('sha-256', data);
const result = buf2hex(hash);
console.log(result);
}
}
main();