@@ -540,6 +540,10 @@ export class Web3AuthMPCCoreKit implements ICoreKit, IMPCContext {
540540 public async inputFactorKey ( factorKey : BNString ) : Promise < void > {
541541 const factorKeyBN = new BN ( factorKey , "hex" ) ;
542542 this . checkReady ( ) ;
543+ const point = Point . fromScalar ( factorKeyBN , secp256k1 ) ;
544+ if ( ! this . getTssFactorPub ( ) . includes ( point . toSEC1 ( secp256k1 , true ) . toString ( "hex" ) ) ) {
545+ throw CoreKitError . providedFactorKeyInvalid ( ) ;
546+ }
543547 try {
544548 // input tkey device share when required share > 0 ( or not reconstructed )
545549 // assumption tkey shares will not changed
@@ -649,9 +653,6 @@ export class Web3AuthMPCCoreKit implements ICoreKit, IMPCContext {
649653
650654 public getTssFactorPub = ( ) : string [ ] => {
651655 this . checkReady ( ) ;
652- if ( ! this . state . factorKey ) {
653- throw CoreKitError . factorKeyNotPresent ( "factorKey not present in state when getting tss factor public key." ) ;
654- }
655656 const factorPubsList = this . tKey . metadata . factorPubs [ this . tKey . tssTag ] ;
656657 return factorPubsList . map ( ( factorPub ) => factorPub . toSEC1 ( factorKeyCurve , true ) . toString ( "hex" ) ) ;
657658 } ;
@@ -1210,7 +1211,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit, IMPCContext {
12101211 }
12111212
12121213 public getMetadataKey ( ) : string {
1213- return this . tkey . secp256k1Key . toString ( "hex" ) ;
1214+ return this . tkey . secp256k1Key . toString ( "hex" ) . padStart ( 64 , "0" ) ;
12141215 }
12151216
12161217 public getMetadataPublicKey ( ) : string {
@@ -1342,22 +1343,25 @@ export class Web3AuthMPCCoreKit implements ICoreKit, IMPCContext {
13421343 }
13431344
13441345 const hashedFactorKey = getHashedPrivateKey ( this . state . postBoxKey , this . options . hashedFactorNonce ) ;
1345- this . state . factorKey = hashedFactorKey ;
1346- if ( await this . checkIfFactorKeyValid ( hashedFactorKey ) ) {
1347- // Initialize tkey with existing hashed share if available.
1348- const factorKeyMetadata : ShareStore = await this . getFactorKeyMetadata ( hashedFactorKey ) ;
1349- try {
1350- await this . tKey . inputShareStoreSafe ( factorKeyMetadata , true ) ;
1351- await this . tKey . reconstructKey ( ) ;
1352- await this . finalizeTkey ( hashedFactorKey ) ;
1353- } catch ( err ) {
1354- log . error ( "error initializing tkey with hashed share" , err ) ;
1355- }
1356- } else {
1357- const factorKeyMetadata = await this . tKey ?. readMetadata < StringifiedType > ( hashedFactorKey ) ;
1358- if ( factorKeyMetadata . message === "SHARE_DELETED" ) {
1359- // throw CoreKitError.hashedFactorDeleted();
1360- log . warn ( "hashed factor deleted" ) ;
1346+ const point = Point . fromScalar ( hashedFactorKey , secp256k1 ) ;
1347+ if ( this . getTssFactorPub ( ) . includes ( point . toSEC1 ( secp256k1 , true ) . toString ( "hex" ) ) ) {
1348+ this . state . factorKey = hashedFactorKey ;
1349+ if ( await this . checkIfFactorKeyValid ( hashedFactorKey ) ) {
1350+ // Initialize tkey with existing hashed share if available.
1351+ const factorKeyMetadata : ShareStore = await this . getFactorKeyMetadata ( hashedFactorKey ) ;
1352+ try {
1353+ await this . tKey . inputShareStoreSafe ( factorKeyMetadata , true ) ;
1354+ await this . tKey . reconstructKey ( ) ;
1355+ await this . finalizeTkey ( hashedFactorKey ) ;
1356+ } catch ( err ) {
1357+ log . error ( "error initializing tkey with hashed share" , err ) ;
1358+ }
1359+ } else {
1360+ const factorKeyMetadata = await this . tKey ?. readMetadata < StringifiedType > ( hashedFactorKey ) ;
1361+ if ( factorKeyMetadata . message === "SHARE_DELETED" ) {
1362+ // throw CoreKitError.hashedFactorDeleted();
1363+ log . warn ( "hashed factor deleted" ) ;
1364+ }
13611365 }
13621366 }
13631367 }
0 commit comments