-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathindex.ts
More file actions
36 lines (31 loc) · 868 Bytes
/
index.ts
File metadata and controls
36 lines (31 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
export { sign, signSync } from "./node/sign.js";
import { verifySync } from "./node/verify.js";
export { verify, verifySync } from "./node/verify.js";
export async function verifyWithFallback(
secret: string,
payload: string,
signature: string,
additionalSecrets: undefined | string[],
): Promise<boolean> {
return verifyWithFallbackSync(secret, payload, signature, additionalSecrets);
}
export function verifyWithFallbackSync(
secret: string,
payload: string,
signature: string,
additionalSecrets: undefined | string[],
): boolean {
const firstPass = verifySync(secret, payload, signature);
if (firstPass) {
return true;
}
if (additionalSecrets !== undefined) {
for (const s of additionalSecrets) {
const v: boolean = verifySync(s, payload, signature);
if (v) {
return v;
}
}
}
return false;
}