#forge.js availability

11 messages · Page 1 of 1 (latest)

wet coral
#

is forge.js is available in worker?

cunning bramble
#

Unsure, what are you trying to do?

wet coral
#

i wast trying to implement api 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

urban tendon
#

Hey, very shortly, if not already, you should be able to access the node:crypto and node:buffer modules in your worker, you just need to add a compatibility flag of nodejs_compat to your wrangler.toml

wet coral
wet coral
#

name = "cloudflare-workers"
main = "src/index.js"
compatibility_date = "2023-07-31"
compatibility_flags = [ "nodejs_compat" ]

urban tendon
#

I mean node's crypto, it should be here soon

wet coral
urban tendon
#

If you've tried it, and it;s not working, then it will soon

wet coral
#

ok