Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions src/helpers/citadelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ export interface CitadelAllowParams {
verifierId: string;
network: string;
clientId: string;
recordId: string;
source?: string;
torusLoginStatus?: TorusLoginStatus;
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);
Expand All @@ -25,9 +30,24 @@ export function buildAllowUrl(params: CitadelAllowParams): string {
if (params.torusLoginStatus) {
url.searchParams.set("torusloginstatus", params.torusLoginStatus);
}
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();
}
4 changes: 4 additions & 0 deletions src/helpers/nodeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ export async function retrieveOrImportShare(params: {
overrideExistingKey: boolean;
nodePubkeys: INodePub[];
extraParams: TorusUtilsExtraParams;
recordId: string;
newImportedShares?: ImportedShare[];
checkCommitment?: boolean;
source?: string;
Expand All @@ -388,6 +389,7 @@ export async function retrieveOrImportShare(params: {
serverTimeOffset,
checkCommitment = true,
source,
recordId,
} = params;
await callAllowApi({
buildEnv,
Expand All @@ -397,6 +399,8 @@ export async function retrieveOrImportShare(params: {
clientId,
source,
torusLoginStatus: TorusLoginStatus.INITIATED,
recordId,
torusLoginInitiated: true,
});

// generate temporary private and public key that is used to secure receive shares
Expand Down
8 changes: 6 additions & 2 deletions src/torus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Curve,
encodeEd25519Point,
generateAddressFromPubKey,
generateRecordId,
generateShares,
getEd25519ExtendedPublicKey,
getKeyCurve,
Expand Down Expand Up @@ -157,11 +158,13 @@ class Torus {
network: this.network,
clientId: this.clientId,
source: this.source,
recordId: generateRecordId(),
};

let result: TorusKey;
try {
result = await retrieveOrImportShare({
recordId: allowParams.recordId,
legacyMetadataHost: this.legacyMetadataHost,
serverTimeOffset: this.serverTimeOffset,
enableOneKey: this.enableOneKey,
Expand All @@ -184,11 +187,11 @@ class Torus {
source: this.source,
});
} catch (error) {
this.reportSignerAllow({ ...allowParams, torusLoginStatus: TorusLoginStatus.FAILED });
this.reportSignerAllow({ ...allowParams, torusLoginStatus: TorusLoginStatus.FAILED, torusLoginFailed: true });
throw error;
}

this.reportSignerAllow({ ...allowParams, torusLoginStatus: TorusLoginStatus.SUCCESS });
this.reportSignerAllow({ ...allowParams, torusLoginStatus: TorusLoginStatus.SUCCESS, torusLoginSuccess: true });
return result;
}

Expand Down Expand Up @@ -261,6 +264,7 @@ class Torus {
}

return retrieveOrImportShare({
recordId: generateRecordId(),
Comment thread
chaitanyapotti marked this conversation as resolved.
legacyMetadataHost: this.legacyMetadataHost,
serverTimeOffset: this.serverTimeOffset,
enableOneKey: this.enableOneKey,
Expand Down
Loading