File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -372,7 +372,7 @@ let validateString = (string) => {
372372
373373// hash string
374374let hashCode = ( string ) => {
375- var hash = 0 , i , chr ;
375+ let hash = 0 , i , chr ;
376376 if ( string . length === 0 ) return hash ;
377377 for ( i = 0 ; i < string . length ; i ++ ) {
378378 chr = string . charCodeAt ( i ) ;
@@ -383,6 +383,17 @@ let hashCode = (string) => {
383383}
384384
385385
386+ // generate SHA
387+ let generateSHA = ( len ) => {
388+ let dec2hex = ( dec ) => {
389+ return dec . toString ( 16 ) . padStart ( 2 , '0' ) ;
390+ }
391+ const arr = new Uint8Array ( ( len || 40 ) / 2 ) ;
392+ window . crypto . getRandomValues ( arr ) ;
393+ return Array . from ( arr , dec2hex ) . join ( '' ) ;
394+ }
395+
396+
386397// asynchronous thread
387398
388399let asyncThread = ( callback , time ) => {
You can’t perform that action at this time.
0 commit comments