File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -512,6 +512,12 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
512512 // input tkey device share when required share > 0 ( or not reconstructed )
513513 // assumption tkey shares will not changed
514514 if ( ! this . tKey . secp256k1Key ) {
515+ const factorKeyPrivate = factorKeyCurve . keyFromPrivate ( factorKey . toBuffer ( ) ) ;
516+ const factorPubX = factorKeyPrivate . getPublic ( ) . getX ( ) . toString ( "hex" ) . padStart ( 64 , "0" ) ;
517+ const factorEncExist = this . tkey . metadata . factorEncs ?. [ this . tkey . tssTag ] ?. [ factorPubX ] ;
518+ if ( ! factorEncExist ) {
519+ throw CoreKitError . providedFactorKeyInvalid ( "Invalid FactorKey provided. Failed to input factor key." ) ;
520+ }
515521 const factorKeyMetadata = await this . getFactorKeyMetadata ( factorKey ) ;
516522 await this . tKey . inputShareStoreSafe ( factorKeyMetadata , true ) ;
517523 }
Original file line number Diff line number Diff line change @@ -158,6 +158,8 @@ export const FactorManipulationTest = async (testVariable: FactorTestVariable) =
158158
159159 const browserFactor = await instance2 . getDeviceFactor ( ) ;
160160
161+ const factorBN = new BN ( recoverFactor , "hex" )
162+
161163 // login with mfa factor
162164 await instance2 . inputFactorKey ( new BN ( recoverFactor , "hex" ) ) ;
163165 assert . strictEqual ( instance2 . status , COREKIT_STATUS . LOGGED_IN ) ;
@@ -167,6 +169,15 @@ export const FactorManipulationTest = async (testVariable: FactorTestVariable) =
167169 const instance3 = await newInstance ( ) ;
168170 assert . strictEqual ( instance3 . status , COREKIT_STATUS . REQUIRED_SHARE ) ;
169171
172+
173+
174+ try {
175+ await instance3 . inputFactorKey ( factorBN . subn ( 1 ) ) ;
176+ throw Error ( "should not be able to input factor" ) ;
177+ } catch ( e ) {
178+ assert ( e instanceof Error ) ;
179+ }
180+
170181 await instance3 . inputFactorKey ( new BN ( browserFactor , "hex" ) ) ;
171182 assert . strictEqual ( instance3 . status , COREKIT_STATUS . LOGGED_IN ) ;
172183 } ) ;
You can’t perform that action at this time.
0 commit comments