Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,5 @@ dist

.env.test
**/*.DS_Store

.npmrc
21 changes: 20 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 62 additions & 12 deletions src/helpers/citadelUtils.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
import { BUILD_ENV_TYPE, CITADEL_SERVER_MAP } from "@toruslabs/constants";
import { get } from "@toruslabs/http-helpers";
import { BUILD_ENV_TYPE, CITADEL_SERVER_MAP, TORUS_NETWORK_TYPE } from "@toruslabs/constants";
import { get, put } from "@toruslabs/http-helpers";
Comment thread
arch1995 marked this conversation as resolved.

export interface CitadelAllowParams {
import { RetrieveSharesParams } from "../interfaces";

export interface CitadelAuthFlowAuditParams {
oauthInitiated?: boolean;
oauthVerified?: boolean;
oauthCompleted?: boolean;
oauthVerificationFailed?: boolean;
oauthFailed?: boolean;
}

export interface CitadelAllowParams extends CitadelAuthFlowAuditParams {
buildEnv: BUILD_ENV_TYPE;
verifier: string;
verifierId: string;
network: string;
clientId: string;
recordId: string;
source?: string;
torusLoginInitiated?: boolean;
torusLoginSuccess?: boolean;
torusLoginFailed?: boolean;
}

export interface CitadelAuditParams extends CitadelAuthFlowAuditParams {
recordId: string;
authConnection: string;
authConnectionId: string;
groupedAuthConnectionId: string;
oAuthUserId: string;
web3AuthNetwork: string;
web3AuthClientId: string;
}

export function buildAllowUrl(params: CitadelAllowParams): string {
Expand All @@ -24,22 +41,55 @@ export function buildAllowUrl(params: CitadelAllowParams): string {
if (params.source) {
url.searchParams.set("source", params.source);
}
if (typeof params.torusLoginInitiated !== "undefined") {
url.searchParams.set("toruslogininitiated", params.torusLoginInitiated.toString());
if (params.oauthInitiated) {
Comment thread
lwin-kyaw marked this conversation as resolved.
Outdated
url.searchParams.set("oauthinitiated", params.oauthInitiated.toString());
}
if (params.oauthVerified) {
url.searchParams.set("oauthverified", params.oauthVerified.toString());
Comment thread
lwin-kyaw marked this conversation as resolved.
Outdated
}
if (typeof params.torusLoginSuccess !== "undefined") {
url.searchParams.set("torusloginsuccess", params.torusLoginSuccess.toString());
if (params.oauthCompleted) {
url.searchParams.set("oauthcompleted", params.oauthCompleted.toString());
}
if (typeof params.torusLoginFailed !== "undefined") {
url.searchParams.set("torusloginfailed", params.torusLoginFailed.toString());
if (params.oauthVerificationFailed) {
url.searchParams.set("oauthverificationfailed", params.oauthVerificationFailed.toString());
}
if (params.oauthFailed) {
url.searchParams.set("oauthfailed", params.oauthFailed.toString());
}
return url.toString();
}

export function buildAuditPayload(
network: TORUS_NETWORK_TYPE,
clientId: string,
params: RetrieveSharesParams,
authFlowAuditParams: CitadelAuthFlowAuditParams
): CitadelAuditParams {
if (!params.recordId) {
params.recordId = generateRecordId();
}
Comment thread
lwin-kyaw marked this conversation as resolved.

return {
...authFlowAuditParams,
recordId: params.recordId,
Comment thread
cursor[bot] marked this conversation as resolved.
authConnection: params.authConnection || "",
authConnectionId: params.verifierParams.sub_verifier_ids?.[0] || "",
groupedAuthConnectionId: params.verifier || "",
oAuthUserId: params.verifierParams.verifier_id || "",
web3AuthNetwork: network,
web3AuthClientId: clientId,
};
}

export async function callAllowApi(params: CitadelAllowParams): Promise<void> {
await get<void>(buildAllowUrl(params));
}

export async function callAuditApi(buildEnv: BUILD_ENV_TYPE, params: CitadelAuditParams): Promise<void> {
const url = new URL(`${CITADEL_SERVER_MAP[buildEnv]}/v1/auth/audit`);
await put<void>(url.toString(), 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");
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/nodeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ export async function retrieveOrImportShare(params: {
source,
recordId,
} = params;
// call feature-gating check before share retrieval
await callAllowApi({
buildEnv,
verifier,
Expand All @@ -398,7 +399,6 @@ export async function retrieveOrImportShare(params: {
clientId,
source,
recordId,
torusLoginInitiated: true,
});

// generate temporary private and public key that is used to secure receive shares
Expand Down
17 changes: 17 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export interface VerifierParams {
[key: string]: unknown;
verifier_id: string;
extended_verifier_id?: string;
sub_verifier_ids?: string[];
}

export type StringifiedType = Record<string, unknown>;
Expand Down Expand Up @@ -283,6 +284,11 @@ export interface ImportKeyParams {
newPrivateKey: string;
extraParams?: TorusUtilsExtraParams;
checkCommitment?: boolean;

/**
* Optional recordId to used for the analytics tracking.
*/
recordId?: string;
}

export interface RetrieveSharesParams {
Expand All @@ -295,4 +301,15 @@ export interface RetrieveSharesParams {
extraParams?: TorusUtilsExtraParams;
useDkg?: boolean;
checkCommitment?: boolean;

/**
* User social login provider name.
* This is used for the analytics tracking.
*/
authConnection?: string;

/**
* Optional recordId to used for the analytics tracking.
*/
recordId?: string;
}
Loading
Loading