Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@toruslabs/torus.js",
"version": "17.2.1",
"version": "17.2.2",
"description": "Handle communication with torus nodes",
"main": "dist/lib.cjs/index.js",
"module": "dist/lib.esm/index.js",
Expand Down
24 changes: 19 additions & 5 deletions src/helpers/citadelUtils.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,47 @@
import { BUILD_ENV_TYPE, CITADEL_SERVER_MAP } from "@toruslabs/constants";
import { get } from "@toruslabs/http-helpers";

import { TorusLoginStatus } from "../interfaces";

export interface CitadelAllowParams {
buildEnv: BUILD_ENV_TYPE;
verifier: string;
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);
url.searchParams.set("clientid", params.clientId);
if (params.source) {
url.searchParams.set("source", params.source);
}
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();
}
6 changes: 4 additions & 2 deletions src/helpers/nodeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
SessionToken,
ShareRequestResult,
TorusKey,
TorusLoginStatus,
UserType,
VerifierLookupResponse,
VerifierLookupResult,
Expand Down Expand Up @@ -363,6 +362,7 @@ export async function retrieveOrImportShare(params: {
overrideExistingKey: boolean;
nodePubkeys: INodePub[];
extraParams: TorusUtilsExtraParams;
recordId: string;
newImportedShares?: ImportedShare[];
checkCommitment?: boolean;
source?: string;
Expand All @@ -388,6 +388,7 @@ export async function retrieveOrImportShare(params: {
serverTimeOffset,
checkCommitment = true,
source,
recordId,
} = params;
await callAllowApi({
buildEnv,
Expand All @@ -396,7 +397,8 @@ export async function retrieveOrImportShare(params: {
network,
clientId,
source,
torusLoginStatus: TorusLoginStatus.INITIATED,
recordId,
torusLoginInitiated: true,
});

// generate temporary private and public key that is used to secure receive shares
Expand Down
6 changes: 0 additions & 6 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ export type v1NonceResultType = { typeOfUser: "v1"; nonce?: string; seed?: strin
export type GetOrSetNonceResult = v2NonceResultType | v1NonceResultType;
export type KeyType = "secp256k1" | "ed25519";

export enum TorusLoginStatus {
INITIATED = "initiated",
SUCCESS = "success",
FAILED = "failed",
}

export interface SetNonceData {
operation: string;
data: string;
Expand Down
9 changes: 6 additions & 3 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 All @@ -32,7 +33,6 @@ import {
RetrieveSharesParams,
TorusCtorOptions,
TorusKey,
TorusLoginStatus,
TorusPublicKey,
} from "./interfaces";
import log from "./loglevel";
Expand Down Expand Up @@ -157,11 +157,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 +186,11 @@ class Torus {
source: this.source,
});
} catch (error) {
this.reportSignerAllow({ ...allowParams, torusLoginStatus: TorusLoginStatus.FAILED });
this.reportSignerAllow({ ...allowParams, torusLoginFailed: true });
throw error;
}

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

Expand Down Expand Up @@ -261,6 +263,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