File tree Expand file tree Collapse file tree 1 file changed +7
-20
lines changed Expand file tree Collapse file tree 1 file changed +7
-20
lines changed Original file line number Diff line number Diff line change 1
1
import { createHmac , timingSafeEqual } from "crypto" ;
2
2
3
3
function s2b ( str : string , encoding : string ) : Buffer {
4
- if ( Buffer . from ) {
5
- try {
6
- return Buffer . from ( str , encoding ) ;
7
- } catch ( err ) {
8
- if ( err . name === "TypeError" ) {
9
- return new Buffer ( str , encoding ) ;
10
- }
11
- throw err ;
4
+ try {
5
+ return Buffer . from ( str , encoding ) ;
6
+ } catch ( err ) {
7
+ if ( err . name === "TypeError" ) {
8
+ return new Buffer ( str , encoding ) ;
12
9
}
13
- } else {
14
- return new Buffer ( str , encoding ) ;
10
+ throw err ;
15
11
}
16
12
}
17
13
18
14
function safeCompare ( a : Buffer , b : Buffer ) : boolean {
19
15
if ( a . length !== b . length ) {
20
16
return false ;
21
17
}
22
-
23
- if ( timingSafeEqual ) {
24
- return timingSafeEqual ( a , b ) ;
25
- } else {
26
- let result = 0 ;
27
- for ( let i = 0 ; i < a . length ; i ++ ) {
28
- result |= a [ i ] ^ b [ i ] ;
29
- }
30
- return result === 0 ;
31
- }
18
+ return timingSafeEqual ( a , b ) ;
32
19
}
33
20
34
21
export default function validateSignature (
You can’t perform that action at this time.
0 commit comments