File tree 3 files changed +4
-7
lines changed
3 files changed +4
-7
lines changed Original file line number Diff line number Diff line change 1
- import crypto from "crypto" ;
2
-
3
- Object . defineProperty ( globalThis , "crypto" , {
4
- value : crypto . webcrypto ,
5
- } ) ;
Original file line number Diff line number Diff line change
1
+ const crypto = typeof window === "undefined" ? require ( "crypto" ) : window . crypto ;
2
+
1
3
export async function sha1 ( source : string ) {
2
4
const sourceBytes = new TextEncoder ( ) . encode ( source ) ;
3
- const digest : ArrayBuffer = await ( globalThis as any ) . crypto . subtle . digest ( "SHA-1" , sourceBytes ) ;
5
+ const digest : ArrayBuffer = await crypto . subtle . digest ( "SHA-1" , sourceBytes ) ;
4
6
const resultBytes = [ ...new Uint8Array ( digest ) ] ;
5
7
return resultBytes . map ( ( x ) => x . toString ( 16 ) . padStart ( 2 , "0" ) ) . join ( "" ) ;
6
8
}
Original file line number Diff line number Diff line change 1
1
{
2
2
"compilerOptions" : {
3
- "lib" : [" es2020" ],
3
+ "lib" : [" es2020" , " DOM " ],
4
4
"baseUrl" : " ./" ,
5
5
"moduleResolution" : " node" ,
6
6
"module" : " commonjs" ,
You can’t perform that action at this time.
0 commit comments