Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request — Runtime APIs “nodejs_compat” breaks when needing crypto.createSign #3172

Open
adueck opened this issue Nov 26, 2024 · 2 comments
Labels
crypto feature request Request for Workers team to add a feature nodejs compat

Comments

@adueck
Copy link

adueck commented Nov 26, 2024

The nodejs_compat does not work with crypto.createSign beause the version of unenv has not implemented it yet.

I am trying to use the google sheets api. While this worked just fine with Firebase Functions on Node, it fails to work with Cloudflare Workers while using the "nodejs_compat" flag.

As you can see from this error message the problem is that it is relying on unenv for compatability, and this version library has not yet implemented crypto.createSign

Using googleapis v. 144.0.0 and hono v. 4.6.12 on MacOS

import { Hono } from "hono";
import { google } from "googleapis";

const app = new Hono();

app.get("/", async (c) => {
  const auth = new google.auth.GoogleAuth({
    credentials: {
      // @ts-expect-error
      private_key: c.env.SERVICE_ACCOUNT_KEY,
      // @ts-expect-error
      client_email: c.env.SERVICE_ACCOUNT_EMAIL,
    },
    scopes: [
      "https://www.googleapis.com/auth/spreadsheets",
      "https://www.googleapis.com/auth/drive.file",
    ],
  });
  const { spreadsheets } = google.sheets({
    version: "v4",
    auth,
  });
  const { data } = await spreadsheets.values.get({
    // @ts-expect-error
    spreadsheetId: c.env.SPREADSHEET_ID,
    range: "A3:AI3",
  });
  c.text("Errors before this");
});

Results in the following error:

✘ [ERROR] Error: [unenv] crypto.createSign is not implemented yet!

      at createNotImplementedError
  (file:///Users/me/my-project/new-functions/node_modules/unenv/runtime/_internal/utils.mjs:22:10)
      at Object.fn [as createSign]
  (file:///Users/me/my-project/new-functions/node_modules/unenv/runtime/_internal/utils.mjs:26:11)
      at Object.sign
  (file:///Users/me/my-project/new-functions/node_modules/jwa/index.js:151:25)
      at Object.jwsSign [as sign]
  (file:///Users/me/my-project/new-functions/node_modules/jws/lib/sign-stream.js:32:24)
      at GoogleToken._GoogleToken_requestToken
  (file:///Users/me/my-project/new-functions/node_modules/gtoken/build/src/index.js:235:27)
      at GoogleToken._GoogleToken_getTokenAsyncInner
  (file:///Users/me/my-project/new-functions/node_modules/gtoken/build/src/index.js:180:97)
      at GoogleToken._GoogleToken_getTokenAsync
  (file:///Users/me/my-project/new-functions/node_modules/gtoken/build/src/index.js:160:173)
      at GoogleToken.getToken
  (file:///Users/me/my-project/new-functions/node_modules/gtoken/build/src/index.js:110:102)
      at JWT.refreshTokenNoCache
  (file:///Users/me/my-project/new-functions/node_modules/google-auth-library/build/src/auth/jwtclient.js:173:36)
      at JWT.refreshToken
  (file:///Users/me/my-project/new-functions/node_modules/google-auth-library/build/src/auth/oauth2client.js:187:24)
@jasnell
Copy link
Member

jasnell commented Nov 28, 2024

This is not a bug as the current behavior is intentional. node:crypto support is still a work in progress. Will change this to a feature request.

@jasnell jasnell added the feature request Request for Workers team to add a feature label Nov 28, 2024
@jasnell jasnell changed the title 🐛 Bug Report — Runtime APIs “nodejs_compat” breaks when needing crypto.createSign Feature request — Runtime APIs “nodejs_compat” breaks when needing crypto.createSign Nov 28, 2024
@adueck
Copy link
Author

adueck commented Nov 29, 2024

Ok great, I imagine this would be a very useful feature. 👍 I was really loving the Cloudflare Workers DX (soo good and smooth) but unfortunately had to switch over to AWS Lambda for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crypto feature request Request for Workers team to add a feature nodejs compat
Projects
None yet
Development

No branches or pull requests

3 participants