我想在 chainlink 函数中使用 crypto.hash

问题描述 投票:0回答:1

我想使用 crypto 包在 chainlink 函数的 1-简单计算中使用 source.js 中的

crypto.getRandomNumbers
crypto.createHash()
。 这是我的代码:

// calculate geometric mean off-chain by a DON then return the result
// valures provided in args array4
//console.log(`calculate geometric mean of ${args}`)/
// args = getRandomJeton();

const crypto = require("crypto");
function getRandomJeton(Choix_Vote, N_V) {
  // Avoir deux nombre completement aleatoire
  let randomAnonymeNumber1 = crypto.getRandomValues(new Uint32Array(1))[0];
  let randomAnonymeNumber2 = crypto.getRandomValues(new Uint32Array(1))[0];
  // Avoir un nombre unique a chaque citoyen
  let uniqueNumber = "12345678910";
  // Mettre ensemble le nombre aleatoire et unique pour cree un nombre 100% aleatoire et unique
  let uniqueRandomValue = `${uniqueNumber}${randomAnonymeNumber2}${randomAnonymeNumber1}`;
  // Mettre ensemble les donne necessaire pour avoir le jeton
  let unhashedJeton = `${Choix_Vote}${uniqueRandomValue}${N_V}`;
  const Jeton = crypto.createHash("sha256").update(unhashedJeton).digest("hex");
  return Jeton;
}
const Jeton = getRandomJeton();
return Jeton;

``` I know that in the documentation it is written that i cannot use modules. But I really need a secure way to get 100% randomNumbers (not with math.random) and I need to get a hash function as well. Is there anyway around this? I would really appricate the help :)
Thank you for taking your time.

When i use crypto ```const crypto = require("crypto") ``` I can call the request.js but it will not give me a response and get me the error ```❌ Error during simulation:  require is not defined```. So I tried to use the import statement as such ```import crypto from "crypto"``` but i get that this error trying to ``` node source.js```  ``` SyntaxError: Cannot use import statement outside a module``` 
function import require chainlink
1个回答
0
投票

对于 Functions,目前您只能使用普通 JavaScript。

© www.soinside.com 2019 - 2024. All rights reserved.