File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -15,8 +15,8 @@ function encodeToBase64(data: unknown): string {
1515// TODO: Improve error handling?
1616const compatCrypto =
1717 typeof crypto === "undefined"
18- ? ( await import ( "node:crypto" ) ) . webcrypto
19- : crypto ;
18+ ? import ( "node:crypto" ) . then ( ( v ) => v . webcrypto )
19+ : Promise . resolve ( crypto ) ;
2020
2121const textEncoder = new TextEncoder ( ) ;
2222
@@ -33,15 +33,17 @@ async function sign(
3333 encodedHeader : string ,
3434 encodedPayload : string ,
3535) : Promise < string > {
36- const cryptoKey = await compatCrypto . subtle . importKey (
36+ const crypto = await compatCrypto ;
37+
38+ const cryptoKey = await crypto . subtle . importKey (
3739 "raw" ,
3840 textEncoder . encode ( apiKey ) ,
3941 { name : "HMAC" , hash : "SHA-256" } ,
4042 false ,
4143 [ "sign" ] ,
4244 ) ;
4345
44- const signature = await compatCrypto . subtle . sign (
46+ const signature = await crypto . subtle . sign (
4547 "HMAC" ,
4648 cryptoKey ,
4749 textEncoder . encode ( `${ encodedHeader } .${ encodedPayload } ` ) ,
You can’t perform that action at this time.
0 commit comments