worker crypto

i wast trying to implement api to in cloudflare worker to generate deviceId but my function uses crypto library and i don't find the same function in cloudflare crypto:

using nodejs crypto lib.

function getDeviceI() {
  let id = crypto.randomBytes(20).toString("binary");
  let hmac = crypto.createHmac(
    "sha1",
    Buffer.from(
      "E7309ECC0953C6FA60005B2765F99DBBC965C8E9",
      "hex"
    )
  );
  hmac.update(Buffer.from(Buffer.from("19", "hex") + id, "binary"));
  return "19" + Buffer.from(id, "binary").toString("hex") + hmac.digest("hex");
}
correct deviceId:19CEB4EB9340402020E054720BEBAF280A8CEA373CC6E00629C9CEB1B3CB14FD5ABC0D4F5896DBAD4E

can anyone help
Was this page helpful?