We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0b5bdf3 commit e8e535dCopy full SHA for e8e535d
src/token.ts
@@ -19,17 +19,20 @@ async function sign(
19
encodedHeader: string,
20
encodedPayload: string
21
): Promise<string> {
22
+ // missing crypto global for Node.js 18
23
+ const localCrypto = crypto ?? (await import('node:crypto')).webcrypto
24
+
25
const textEncoder = new TextEncoder()
26
- const cryptoKey = await crypto.subtle.importKey(
27
+ const cryptoKey = await localCrypto.subtle.importKey(
28
'raw',
29
textEncoder.encode(apiKey),
30
{ name: 'HMAC', hash: 'SHA-256' },
31
false,
32
['sign']
33
)
34
- const signature = await crypto.subtle.sign(
35
+ const signature = await localCrypto.subtle.sign(
36
'HMAC',
37
cryptoKey,
38
textEncoder.encode(`${encodedHeader}.${encodedPayload}`)
0 commit comments