-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcitadelUtils.ts
More file actions
47 lines (43 loc) · 1.69 KB
/
Copy pathcitadelUtils.ts
File metadata and controls
47 lines (43 loc) · 1.69 KB
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
37
38
39
40
41
42
43
44
45
46
47
import { BUILD_ENV_TYPE, CITADEL_SERVER_MAP } from "@toruslabs/constants";
import { get } from "@toruslabs/http-helpers";
export interface CitadelAllowParams {
buildEnv: BUILD_ENV_TYPE;
verifier: string;
verifierId: string;
network: string;
clientId: string;
recordId: string;
source?: string;
torusLoginInitiated?: boolean;
torusLoginSuccess?: boolean;
torusLoginFailed?: boolean;
}
export function buildAllowUrl(params: CitadelAllowParams): string {
const url = new URL(`${CITADEL_SERVER_MAP[params.buildEnv]}/v1/signer/allow`);
url.searchParams.set("recordid", params.recordId);
url.searchParams.set("verifier", params.verifier);
url.searchParams.set("verifierid", params.verifierId);
url.searchParams.set("network", params.network);
url.searchParams.set("clientid", params.clientId);
if (params.source) {
url.searchParams.set("source", params.source);
}
if (typeof params.torusLoginInitiated !== "undefined") {
url.searchParams.set("toruslogininitiated", params.torusLoginInitiated.toString());
}
if (typeof params.torusLoginSuccess !== "undefined") {
url.searchParams.set("torusloginsuccess", params.torusLoginSuccess.toString());
}
if (typeof params.torusLoginFailed !== "undefined") {
url.searchParams.set("torusloginfailed", params.torusLoginFailed.toString());
}
return url.toString();
}
export async function callAllowApi(params: CitadelAllowParams): Promise<void> {
await get<void>(buildAllowUrl(params));
}
export function generateRecordId(): string {
const cr = typeof globalThis === "object" ? globalThis.crypto : null;
if (typeof cr?.randomUUID !== "function") throw new Error("crypto.randomUUID must be defined");
return cr.randomUUID();
}