Skip to content

Commit

Permalink
[IRT-1329] fix: Fix import paths accidental code removal
Browse files Browse the repository at this point in the history
refactor: Move errors file to helper folder
  • Loading branch information
huggingbot committed May 2, 2024
1 parent 0a7cd6d commit 0fe0854
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/helper/browserStorage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import BN from "bn.js";

import { FIELD_ELEMENT_HEX_LEN } from "../constants";
import CoreKitError from "../errors";
import { IAsyncStorage, ICoreKit, IStorage, SupportedStorageType, TkeyLocalStoreData } from "../interfaces";
import { storageAvailable } from "../utils";
import CoreKitError from "./errors";

export class MemoryStorage implements IStorage {
private _store: Record<string, string> = {};
Expand Down Expand Up @@ -121,6 +121,7 @@ export class AsyncStorage {
if (!storage) {
throw CoreKitError.noValidStorageOptionFound();
}
this.instance = new this(key, storage);
}
return this.instance;
}
Expand Down
4 changes: 2 additions & 2 deletions src/errors.ts → src/helper/errors.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { CustomError } from "ts-custom-error";

export interface ICoreKitError extends CustomError {
interface ICoreKitError extends CustomError {
name: string;
code: number;
message: string;
toString(): string;
}

export abstract class AbstractCoreKitError extends CustomError implements ICoreKitError {
abstract class AbstractCoreKitError extends CustomError implements ICoreKitError {
code: number;

message: string;
Expand Down
19 changes: 15 additions & 4 deletions src/mpcCoreKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import {
VALID_SHARE_INDICES,
WEB3AUTH_NETWORK,
} from "./constants";
import CoreKitError from "./errors";
import { AsyncStorage, asyncStoreFactor, BrowserStorage, storeWebBrowserFactor } from "./helper/browserStorage";
import CoreKitError from "./helper/errors";
import {
AggregateVerifierLoginParams,
COREKIT_STATUS,
Expand Down Expand Up @@ -480,6 +480,11 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
if (!data) {
throw CoreKitError.invalidTorusLoginResponse();
}
this.updateState({
oAuthKey: this._getOAuthKey(data),
userInfo: data.userInfo,
signatures: this._getSignatures(data.sessionData.sessionTokenData),
});
this.torusSp.verifierType = "normal";
const userInfo = this.getUserInfo();
this.torusSp.verifierName = userInfo.verifier;
Expand Down Expand Up @@ -787,10 +792,16 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
};

async deleteFactor(factorPub: TkeyPoint, factorKey?: BNString): Promise<void> {
if (!this.state.factorKey) throw new Error("No 'factorKey' found in the current state when deleting a factor.");
if (!this.tKey.metadata.factorPubs) throw new Error("Factor pubs not present");
if (!this.state.factorKey) {
throw CoreKitError.factorKeyNotPresent("factorKey not present in state when deleting a factor.");
}
if (!this.tKey.metadata.factorPubs) {
throw CoreKitError.factorPubsMissing();
}
const remainingFactors = this.tKey.metadata.factorPubs[this.tKey.tssTag].length || 0;
if (remainingFactors <= 1) throw new Error("Cannot delete the last remaining factor as at least one factor is required.");
if (remainingFactors <= 1) {
throw CoreKitError.factorInUseCannotBeDeleted();
}
const fpp = Point.fromTkeyPoint(factorPub);
const stateFpp = Point.fromTkeyPoint(getPubKeyPoint(this.state.factorKey));
if (fpp.equals(stateFpp)) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { keccak256 } from "@toruslabs/torus.js";
import BN from "bn.js";

import { SCALAR_LEN, VALID_SHARE_INDICES as VALID_TSS_INDICES } from "./constants";
import CoreKitError from "./errors";
import CoreKitError from "./helper/errors";

export const generateFactorKey = (): { private: BN; pub: TkeyPoint } => {
const factorKey = new BN(generatePrivate());
Expand Down

0 comments on commit 0fe0854

Please sign in to comment.