11import assert from "node:assert" ;
22import test from "node:test" ;
33
4- import { EllipticPoint , KeyType , Point , secp256k1 } from "@tkey/common-types" ;
4+ import { EllipticPoint , getPubKeyPoint , KeyType , Point , secp256k1 } from "@tkey/common-types" ;
55import { factorKeyCurve } from "@tkey/tss" ;
66import { tssLib as tssLibDKLS } from "@toruslabs/tss-dkls-lib" ;
77import { tssLib as tssLibFROST } from "@toruslabs/tss-frost-lib" ;
@@ -158,7 +158,7 @@ export const FactorManipulationTest = async (testVariable: FactorTestVariable) =
158158 } ) ;
159159
160160 // enable mfa
161-
161+ let browserFactor : string ;
162162 await t . test ( "enable MFA" , async function ( ) {
163163 const instance = await newInstance ( ) ;
164164 assert . strictEqual ( instance . status , COREKIT_STATUS . LOGGED_IN ) ;
@@ -179,7 +179,7 @@ export const FactorManipulationTest = async (testVariable: FactorTestVariable) =
179179 const instance2 = await newInstance ( ) ;
180180 assert . strictEqual ( instance2 . status , COREKIT_STATUS . REQUIRED_SHARE ) ;
181181
182- const browserFactor = await instance2 . getDeviceFactor ( ) ;
182+ browserFactor = await instance2 . getDeviceFactor ( ) ;
183183
184184 const factorBN = new BN ( recoverFactor , "hex" )
185185
@@ -210,9 +210,32 @@ export const FactorManipulationTest = async (testVariable: FactorTestVariable) =
210210 } else {
211211 await signSecp256k1Data ( { coreKitInstance : instance3 , msg : "hello world" } ) ;
212212 }
213-
214213 } ) ;
215214
215+ // replace factor
216+ await t . test ( "replace factor" , async function ( ) {
217+ const instance = await newInstance ( ) ;
218+
219+ const deviceFactorKeyBN = new BN ( browserFactor , "hex" )
220+ await instance . inputFactorKey ( deviceFactorKeyBN ) ;
221+ assert . strictEqual ( instance . status , COREKIT_STATUS . LOGGED_IN ) ;
222+
223+ const newFactorkey = await instance . createFactor ( { shareType : TssShareType . DEVICE } ) ;
224+ await instance . inputFactorKey ( new BN ( newFactorkey , "hex" ) ) ;
225+
226+ assert . strictEqual ( instance . status , COREKIT_STATUS . LOGGED_IN ) ;
227+
228+
229+ const deviceFactorPub = getPubKeyPoint ( deviceFactorKeyBN ) ;
230+ await instance . deleteFactor ( deviceFactorPub , browserFactor ) ;
231+
232+ try {
233+ await instance . inputFactorKey ( deviceFactorKeyBN ) ;
234+ throw Error ( "should not be able to deleted input factor" ) ;
235+ } catch ( e ) {
236+ assert ( e instanceof Error ) ;
237+ }
238+ } ) ;
216239 } ) ;
217240} ;
218241
0 commit comments