Skip to content

Commit d4ebfbc

Browse files
committed
fix: address comment
fix ed25519 with accountIndex 0 fix useClientGeneratedTSSKey fix typo
1 parent 0415c0e commit d4ebfbc

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

src/mpcCoreKit.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,12 @@ export class Web3AuthMPCCoreKit implements ICoreKit, IMPCContext {
482482
throw CoreKitError.invalidConfig("Cannot import TSS key and register SFA key at the same time.");
483483
}
484484

485-
const fisrtKeyType = this.getSupportedCurveKeyTypes()[0];
485+
const firstKeyType = this.getSupportedCurveKeyTypes()[0];
486486
try {
487487
// prefetch tss pub keys.
488488
const prefetchTssPubs = [];
489489
for (let i = 0; i < prefetchTssPublicKeys; i++) {
490-
prefetchTssPubs.push(this.torusSp.getTSSPubKey(this.tkey.tssTag, i, fisrtKeyType));
490+
prefetchTssPubs.push(this.torusSp.getTSSPubKey(this.tkey.tssTag, i, firstKeyType));
491491
}
492492

493493
// get postbox key.
@@ -519,7 +519,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit, IMPCContext {
519519
const existingSFAKey = loginResponse.finalKeyData.privKey.padStart(64, "0");
520520

521521
await this.setupTkey({
522-
providedImportKey: { [fisrtKeyType]: existingSFAKey },
522+
providedImportKey: { [firstKeyType]: existingSFAKey },
523523
importingSFAKey: true,
524524
sfaLoginResponse: loginResponse,
525525
userInfo: { ...parseToken(idToken), verifier, verifierId },
@@ -778,7 +778,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit, IMPCContext {
778778
}
779779

780780
const tssCurve = getKeyCurve(KeyType.ed25519);
781-
// ed25519 only support account index 0 ?
781+
if (this.state.accountIndex !== 0) throw CoreKitError.default("Ed25519 only support account index 0");
782782
const p = this.getPubKeyPoint(KeyType.ed25519, 0).toEllipticPoint(tssCurve);
783783
return ed25519().keyFromPublic(p).getPublic();
784784
}
@@ -1084,9 +1084,10 @@ export class Web3AuthMPCCoreKit implements ICoreKit, IMPCContext {
10841084
*
10851085
* Exports the private key scalar for the current account index.
10861086
*
1087+
* @param keyType - export final tsskey of designated keyType
1088+
*
10871089
* For signature type ed25519, consider using _UNSAFE_exportTssEd25519Seed.
10881090
*/
1089-
// TODO : should return all keyType final keys?
10901091
public async _UNSAFE_exportTssKey(keyType: KeyType): Promise<string> {
10911092
if (!this.state.factorKey) {
10921093
throw CoreKitError.factorKeyNotPresent("factorKey not present in state when exporting tss key.");
@@ -1170,14 +1171,13 @@ export class Web3AuthMPCCoreKit implements ICoreKit, IMPCContext {
11701171
const existingUser = await this.isMetadataPresent(this.state.postBoxKey);
11711172
const importKey = providedImportKey ?? {};
11721173
if (!existingUser) {
1173-
// if (!importKey && this.useClientGeneratedTSSKey) {
11741174
const keyTypes = this.getSupportedCurveKeyTypes();
11751175
for (const keyType of keyTypes) {
11761176
if (!importKey[keyType]) {
11771177
if (keyType === KeyType.ed25519) {
11781178
const k = generateEd25519Seed();
11791179
importKey.ed25519 = k.toString("hex");
1180-
} else if (keyType === KeyType.secp256k1) {
1180+
} else if (keyType === KeyType.secp256k1 && !!this.options.useClientGeneratedTSSKey) {
11811181
const k = secp256k1.genKeyPair().getPrivate();
11821182
importKey.secp256k1 = scalarBNToBufferSEC1(k).toString("hex");
11831183
} else {

tests/backwardCompatible.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ variable.forEach((testVariable) => {
7575
idToken,
7676
});
7777

78-
// console.log(coreKitInstance.tKey.metadata)
79-
// console.log(coreKitInstance.state);
8078
// get key details
8179
await checkLogin(coreKitInstance);
8280

tests/setup.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ export const newCoreKitLogInInstance = async ({
106106
legacyFlag?: boolean;
107107
}) => {
108108
const localTsslib = tssLib ?? tssLibDKLS;
109-
// console.log("localTssLib", localTsslib)
110-
111109

112110
const instance = new Web3AuthMPCCoreKit({
113111
web3AuthClientId: "torus-key-test",
@@ -124,7 +122,6 @@ export const newCoreKitLogInInstance = async ({
124122
const { idToken, parsedToken } = login ? await login(email) : await mockLogin(email);
125123
await instance.init();
126124

127-
// console.log("legacy Flag", legacyFlag)
128125
if (mockStorageLayer) {
129126
instance.tKey.storageLayer = mockStorageLayer
130127
}

0 commit comments

Comments
 (0)