Skip to content

Commit

Permalink
fix: update interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ieow committed Nov 8, 2024
1 parent f072898 commit 164f84a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { KeyType, Point as TkeyPoint, ShareDescriptionMap } from "@tkey/common-types";
import { BNString, KeyType, Point as TkeyPoint, ShareDescriptionMap } from "@tkey/common-types";
import { TKeyTSS } from "@tkey/tss";
import type {
AGGREGATE_VERIFIER_TYPE,
Expand Down Expand Up @@ -92,7 +92,7 @@ export interface EnableMFAParams {
/**
* A BN used for encrypting your Device/ Recovery TSS Key Share. You can generate it using `generateFactorKey()` function or use an existing one.
*/
factorKey?: BN;
factorKey?: BNString;
/**
* Setting the Description of Share - Security Questions, Device Share, Seed Phrase, Password Share, Social Share, Other. Default is Other.
*/
Expand Down Expand Up @@ -229,7 +229,7 @@ export interface ICoreKit {
* Share. You can generate it using `generateFactorKey()` function or use an
* existing one.
*/
inputFactorKey(factorKey: BN): Promise<void>;
inputFactorKey(factorKey: BNString): Promise<void>;

/**
* Returns the current Factor Key and TssShareType in MPC Core Kit State
Expand Down
14 changes: 11 additions & 3 deletions src/mpcCoreKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,19 +520,20 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
}
}

public async inputFactorKey(factorKey: BN): Promise<void> {
public async inputFactorKey(factorKey: BNString): Promise<void> {
const factorKeyBN = new BN(factorKey, "hex");
this.checkReady();
try {
// input tkey device share when required share > 0 ( or not reconstructed )
// assumption tkey shares will not changed
if (!this.tKey.secp256k1Key) {
const factorKeyMetadata = await this.getFactorKeyMetadata(factorKey);
const factorKeyMetadata = await this.getFactorKeyMetadata(factorKeyBN);
await this.tKey.inputShareStoreSafe(factorKeyMetadata, true);
}

// Finalize initialization.
await this.tKey.reconstructKey();
await this.finalizeTkey(factorKey);
await this.finalizeTkey(factorKeyBN);
} catch (err: unknown) {
log.error("login error", err);
if (err instanceof CoreError) {
Expand Down Expand Up @@ -637,6 +638,9 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
const { shareType } = createFactorParams;

let { factorKey, shareDescription, additionalMetadata } = createFactorParams;
if (typeof factorKey === "string") {
factorKey = new BN(factorKey, "hex");
}

if (!VALID_SHARE_INDICES.includes(shareType)) {
throw CoreKitError.newShareIndexInvalid(`Invalid share type provided (${shareType}). Valid share types are ${VALID_SHARE_INDICES}.`);
Expand Down Expand Up @@ -994,6 +998,10 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
this.tkey.metadata.setGeneralStoreDomain(domain, value);
}

public getmetadataKey(): string | undefined {
return this.tkey?.secp256k1Key.toString(16);
}

protected async atomicSync<T>(f: () => Promise<T>): Promise<T> {
this.atomicCallStackCounter += 1;

Expand Down

0 comments on commit 164f84a

Please sign in to comment.