Mr Void
Mr Void6mo ago

Error: Not implemented: crypto.Sign

Error: Not implemented: crypto.Sign
at notImplemented (https://deno.land/std@0.177.1/node/_utils.ts:6:11)
at new Sign (https://deno.land/std@0.177.1/node/internal/crypto/sig.ts:10:9)
at Object.createSign (https://deno.land/std@0.177.1/node/crypto.ts:41:12)
at Object.sign (https://esm.sh/v135/jwa@2.0.0/deno/jwa.mjs:10:1429)
at Object.B [as sign] (https://esm.sh/v135/jws@4.0.0/deno/jws.mjs:16:2178)
at T.requestToken (https://esm.sh/v135/gtoken@7.0.1/deno/gtoken.mjs:8:4404)
at T.getTokenAsyncInner (https://esm.sh/v135/gtoken@7.0.1/deno/gtoken.mjs:8:3391)
at T.getTokenAsync (https://esm.sh/v135/gtoken@7.0.1/deno/gtoken.mjs:8:2968)
at T.getToken (https://esm.sh/v135/gtoken@7.0.1/deno/gtoken.mjs:8:2117)
at i.refreshTokenNoCache (https://esm.sh/v135/google-auth-library@9.4.1/deno/google-auth-library.mjs:37:23973)
Error: Not implemented: crypto.Sign
at notImplemented (https://deno.land/std@0.177.1/node/_utils.ts:6:11)
at new Sign (https://deno.land/std@0.177.1/node/internal/crypto/sig.ts:10:9)
at Object.createSign (https://deno.land/std@0.177.1/node/crypto.ts:41:12)
at Object.sign (https://esm.sh/v135/jwa@2.0.0/deno/jwa.mjs:10:1429)
at Object.B [as sign] (https://esm.sh/v135/jws@4.0.0/deno/jws.mjs:16:2178)
at T.requestToken (https://esm.sh/v135/gtoken@7.0.1/deno/gtoken.mjs:8:4404)
at T.getTokenAsyncInner (https://esm.sh/v135/gtoken@7.0.1/deno/gtoken.mjs:8:3391)
at T.getTokenAsync (https://esm.sh/v135/gtoken@7.0.1/deno/gtoken.mjs:8:2968)
at T.getToken (https://esm.sh/v135/gtoken@7.0.1/deno/gtoken.mjs:8:2117)
at i.refreshTokenNoCache (https://esm.sh/v135/google-auth-library@9.4.1/deno/google-auth-library.mjs:37:23973)
The following is a supabase edge-function that is meant to send a post request to Firebase Cloud Messaging. However, it throws the error above and I am not sure why this is happening or how to solve it. This is the guide that I follow: https://supabase.com/docs/guides/functions/examples/push-notifications?platform=fcm
Sending Push Notifications | Supabase Docs
Send Push Notifications to your React Native iOS and Android apps using Expo.
2 Replies
Mr Void
Mr Void6mo ago
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';
import { JWT } from 'https://esm.sh/google-auth-library@9.4.1';
import serviceAccount from '../service-account.json' assert { type: "json" };


const supabase = createClient(
Deno.env.get('SUPABASE_URL')!,
Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!
)

Deno.serve(async (req) => {
const payload: WebhookPayload = await req.json()

const accessToken = await getAccessToken({
clientEmail: serviceAccount.client_email,
privateKey: serviceAccount.private_key,
})

//...
})

const getAccessToken = ({
clientEmail,
privateKey,
}: {
clientEmail: string
privateKey: string
}): Promise<string> => {
return new Promise((resolve, reject) => {
const jwtClient = new JWT({
email: clientEmail,
key: privateKey,
scopes: ['https://www.googleapis.com/auth/firebase.messaging'],
})
jwtClient.authorize((err, tokens) => {
if (err) {
reject(err)
return
}
resolve(tokens!.access_token!)
})
})
}
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2';
import { JWT } from 'https://esm.sh/google-auth-library@9.4.1';
import serviceAccount from '../service-account.json' assert { type: "json" };


const supabase = createClient(
Deno.env.get('SUPABASE_URL')!,
Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!
)

Deno.serve(async (req) => {
const payload: WebhookPayload = await req.json()

const accessToken = await getAccessToken({
clientEmail: serviceAccount.client_email,
privateKey: serviceAccount.private_key,
})

//...
})

const getAccessToken = ({
clientEmail,
privateKey,
}: {
clientEmail: string
privateKey: string
}): Promise<string> => {
return new Promise((resolve, reject) => {
const jwtClient = new JWT({
email: clientEmail,
key: privateKey,
scopes: ['https://www.googleapis.com/auth/firebase.messaging'],
})
jwtClient.authorize((err, tokens) => {
if (err) {
reject(err)
return
}
resolve(tokens!.access_token!)
})
})
}
Deno AI Helper
Deno AI Helper6mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the error message you've provided, it seems that the crypto.Sign functionality you're trying to use is not implemented in the Deno standard library's Node compatibility layer. The error message indicates that the Sign class from Node's crypto module is not available in Deno's standard library. This is likely because Deno has its own set of cryptographic functions and does not fully support Node's crypto module. As the advice is not based on the Deno documentation, please double-check the accuracy of the advice given. One possible solution might be to look for a Deno-native module that provides the cryptographic functionality you need, or to use Deno's built-in Web Crypto API if it suits your use case. Since you are working with Supabase edge functions and Firebase Cloud Messaging, you might need to find an alternative way to implement the signing process that is compatible with Deno's available APIs or third-party modules designed for Deno.