Skip to content

Commit 24c3422

Browse files
committed
use sig type from @toruslabs/constants
1 parent 952df91 commit 24c3422

File tree

2 files changed

+12
-30
lines changed

2 files changed

+12
-30
lines changed

src/interfaces.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { KeyType, Point as TkeyPoint, ShareDescriptionMap } from "@tkey/common-types";
22
import { TKeyTSS } from "@tkey/tss";
3+
import { WEB3AUTH_SIG_TYPE } from "@toruslabs/constants";
34
import type {
45
AGGREGATE_VERIFIER_TYPE,
56
ExtraParams,
@@ -458,11 +459,7 @@ export interface TkeyLocalStoreData {
458459
factorKey: string;
459460
}
460461

461-
export enum SigType {
462-
ecdsa_secp256k1 = "ecdsa-secp256k1",
463-
ed25519 = "ed25519",
464-
bip340 = "bip340",
465-
}
462+
export type SigType = WEB3AUTH_SIG_TYPE;
466463

467464
export interface CoreKitSigner {
468465
keyType: KeyType;

src/mpcCoreKit.ts

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
110110

111111
this._tssLib = options.tssLib;
112112
this._keyType = options.tssLib.keyType as KeyType;
113-
this._sigType = (() => {
114-
if (!(options.tssLib as V4TSSLibType).sigType) {
115-
if (this._keyType === "secp256k1") {
116-
return SigType.ecdsa_secp256k1;
117-
} else if (this._keyType === "ed25519") {
118-
return SigType.ed25519;
119-
}
120-
throw CoreKitError.invalidKeyType();
121-
}
122-
const sigType = (options.tssLib as V4TSSLibType).sigType as SigType;
123-
// Check if sigType is valid SigType.
124-
if (!Object.values(SigType).includes(sigType)) {
125-
throw CoreKitError.invalidSigType();
126-
}
127-
return sigType;
128-
})();
113+
this._sigType = options.tssLib.sigType as SigType;
129114

130115
const isNodejsOrRN = this.isNodejsOrRN(options.uxMode);
131116

@@ -199,7 +184,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
199184
}
200185

201186
get supportsAccountIndex(): boolean {
202-
return this._sigType !== SigType.ed25519;
187+
return this._sigType !== "ed25519";
203188
}
204189

205190
private get verifier(): string {
@@ -218,7 +203,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
218203
}
219204

220205
private get useClientGeneratedTSSKey(): boolean {
221-
return this._sigType === SigType.ed25519 && this.options.useClientGeneratedTSSKey === undefined ? true : !!this.options.useClientGeneratedTSSKey;
206+
return this._sigType === "ed25519" && this.options.useClientGeneratedTSSKey === undefined ? true : !!this.options.useClientGeneratedTSSKey;
222207
}
223208

224209
// RecoverTssKey only valid for user that enable MFA where user has 2 type shares :
@@ -257,7 +242,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
257242

258243
const nodeDetails = fetchLocalConfig(this.options.web3AuthNetwork, this.keyType);
259244

260-
if (this._sigType === SigType.ed25519 && this.options.useDKG) {
245+
if (this._sigType === "ed25519" && this.options.useDKG) {
261246
throw CoreKitError.invalidConfig("DKG is not supported for ed25519 signature type");
262247
}
263248

@@ -675,7 +660,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
675660
* Throws an error if signature type is not ed25519.
676661
*/
677662
public getPubKeyEd25519(): Buffer {
678-
if (this._sigType !== SigType.ed25519) {
663+
if (this._sigType !== "ed25519") {
679664
throw CoreKitError.default(`getPubKeyEd25519 not supported for signature type ${this.sigType}`);
680665
}
681666

@@ -689,7 +674,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
689674
* Throws an error if signature type is not bip340.
690675
*/
691676
public getPubKeyBip340(): Buffer {
692-
if (this._sigType !== SigType.bip340) {
677+
if (this._sigType !== "bip340") {
693678
throw CoreKitError.default(`getPubKeyBip340 not supported for signature type ${this.sigType}`);
694679
}
695680

@@ -787,10 +772,10 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
787772

788773
public async sign(data: Buffer, hashed: boolean = false, secp256k1Precompute?: Secp256k1PrecomputedClient): Promise<Buffer> {
789774
this.wasmLib = await this.loadTssWasm();
790-
if (this._sigType === SigType.ecdsa_secp256k1) {
775+
if (this._sigType === "ecdsa-secp256k1") {
791776
const sig = await this.sign_ECDSA_secp256k1(data, hashed, secp256k1Precompute);
792777
return Buffer.concat([sig.r, sig.s, Buffer.from([sig.v])]);
793-
} else if (this._sigType === SigType.ed25519 || this._sigType === SigType.bip340) {
778+
} else if (this._sigType === "ed25519" || this._sigType === "bip340") {
794779
return this.sign_frost(data, hashed);
795780
}
796781
throw CoreKitError.default(`sign not supported for key type ${this.keyType}`);
@@ -960,7 +945,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
960945
* flow has been used.
961946
*/
962947
public async _UNSAFE_exportTssEd25519Seed(): Promise<Buffer> {
963-
if (this._sigType !== SigType.ed25519) {
948+
if (this._sigType !== "ed25519") {
964949
throw CoreKitError.default("Wrong signature type. Method can only be used when signature type is ed25519.");
965950
}
966951
if (!this.state.factorKey) throw CoreKitError.factorKeyNotPresent("factorKey not present in state when exporting tss ed25519 seed.");
@@ -1031,7 +1016,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
10311016
let importTssKey = providedImportTssKey;
10321017
if (!existingUser) {
10331018
if (!importTssKey && this.useClientGeneratedTSSKey) {
1034-
if (this._sigType === SigType.ed25519) {
1019+
if (this._sigType === "ed25519") {
10351020
const k = generateEd25519Seed();
10361021
importTssKey = k.toString("hex");
10371022
} else if (this.keyType === KeyType.secp256k1) {

0 commit comments

Comments
 (0)