@@ -6,23 +6,27 @@ import { UX_MODE_TYPE } from "@toruslabs/customauth";
66import { tssLib } from "@toruslabs/tss-frost-lib" ;
77import BN from "bn.js" ;
88
9- import { AsyncStorage , COREKIT_STATUS , ed25519 , MemoryStorage , WEB3AUTH_NETWORK , WEB3AUTH_NETWORK_TYPE , Web3AuthMPCCoreKit } from "../src" ;
9+ import { AsyncStorage , COREKIT_STATUS , ed25519 , MemoryStorage , TssShareType , WEB3AUTH_NETWORK , WEB3AUTH_NETWORK_TYPE , Web3AuthMPCCoreKit } from "../src" ;
1010import { bufferToElliptic , criticalResetAccount , mockLogin , mockLogin2 } from "./setup" ;
1111
1212type TestVariable = {
1313 web3AuthNetwork : WEB3AUTH_NETWORK_TYPE ;
1414 uxMode : UX_MODE_TYPE | "nodejs" ;
1515 manualSync ?: boolean ;
1616 email : string ;
17+ importedEmail : string
1718} ;
1819
19- const defaultTestEmail = "testEmailForLoginEd25519" ;
20+ const defaultTestEmail = "testEmailForLoginEd25519-01" ;
21+ const importedEmail = "testEmailImportEd25519-01"
22+
2023const variable : TestVariable [ ] = [
21- { web3AuthNetwork : WEB3AUTH_NETWORK . DEVNET , uxMode : "nodejs" , email : defaultTestEmail } ,
24+ { web3AuthNetwork : WEB3AUTH_NETWORK . DEVNET , uxMode : "nodejs" , email : defaultTestEmail , importedEmail } ,
2225 // { web3AuthNetwork: WEB3AUTH_NETWORK.MAINNET, uxMode: UX_MODE.REDIRECT, email: defaultTestEmail },
2326
24- { web3AuthNetwork : WEB3AUTH_NETWORK . DEVNET , uxMode : "nodejs" , manualSync : true , email : defaultTestEmail } ,
27+ { web3AuthNetwork : WEB3AUTH_NETWORK . DEVNET , uxMode : "nodejs" , manualSync : true , email : defaultTestEmail , importedEmail } ,
2528 // { web3AuthNetwork: WEB3AUTH_NETWORK.MAINNET, uxMode: UX_MODE.REDIRECT, manualSync: true, email: defaultTestEmail },
29+
2630] ;
2731
2832const checkLogin = async ( coreKitInstance : Web3AuthMPCCoreKit , accountIndex = 0 ) => {
@@ -39,7 +43,7 @@ const storageInstance = new MemoryStorage();
3943
4044variable . forEach ( ( testVariable ) => {
4145 const { web3AuthNetwork, uxMode, manualSync, email } = testVariable ;
42- const newCoreKitInstance = ( ) =>
46+ const newCoreKitInstance = ( params : { disableSessionManager : boolean } = { disableSessionManager : true } ) =>
4347 new Web3AuthMPCCoreKit ( {
4448 web3AuthClientId : "torus-key-test" ,
4549 web3AuthNetwork,
@@ -48,11 +52,12 @@ variable.forEach((testVariable) => {
4852 tssLib,
4953 storage : storageInstance ,
5054 manualSync,
55+ disableSessionManager : params . disableSessionManager
5156 } ) ;
5257
53- async function resetAccount ( ) {
58+ async function resetAccount ( resetEmail : string ) {
5459 const resetInstance = newCoreKitInstance ( ) ;
55- const { idToken, parsedToken } = await mockLogin ( email ) ;
60+ const { idToken, parsedToken } = await mockLogin ( resetEmail ) ;
5661 await resetInstance . init ( { handleRedirectResult : false , rehydrate : false } ) ;
5762 await resetInstance . loginWithJWT ( {
5863 verifier : "torus-test-health" ,
@@ -69,9 +74,11 @@ variable.forEach((testVariable) => {
6974 let checkTssShare : BN ;
7075
7176 test ( `#Login Test with JWT + logout: ${ testNameSuffix } ` , async ( t ) => {
72- await resetAccount ( ) ;
77+ await resetAccount ( email ) ;
78+ await resetAccount ( importedEmail ) ;
79+
7380 await t . test ( "#Login" , async function ( ) {
74- const coreKitInstance = newCoreKitInstance ( ) ;
81+ const coreKitInstance = newCoreKitInstance ( { disableSessionManager : false } ) ;
7582
7683 // mocklogin
7784 const { idToken, parsedToken } = await mockLogin ( email ) ;
@@ -98,7 +105,7 @@ variable.forEach((testVariable) => {
98105 } ) ;
99106
100107 await t . test ( "#relogin " , async function ( ) {
101- const coreKitInstance = newCoreKitInstance ( ) ;
108+ const coreKitInstance = newCoreKitInstance ( { disableSessionManager : false } ) ;
102109 // rehydrate
103110 await coreKitInstance . init ( { handleRedirectResult : false } ) ;
104111 await checkLogin ( coreKitInstance ) ;
@@ -147,5 +154,39 @@ variable.forEach((testVariable) => {
147154 const valid = ed25519 ( ) . verify ( msgBuffer , signature , coreKitInstance . getPubKeyEd25519 ( ) ) ;
148155 assert ( valid ) ;
149156 } ) ;
157+
158+ await t . test ( "#able to export import" , async function ( ) {
159+ const coreKitInstance = newCoreKitInstance ( ) ;
160+ await coreKitInstance . init ( { handleRedirectResult : false , rehydrate : false } ) ;
161+ const localToken = await mockLogin2 ( email ) ;
162+ await coreKitInstance . loginWithJWT ( {
163+ verifier : "torus-test-health" ,
164+ verifierId : email ,
165+ idToken : localToken . idToken ,
166+ } ) ;
167+
168+ await coreKitInstance . enableMFA ( { } ) ;
169+ if ( manualSync ) {
170+ await coreKitInstance . commitChanges ( ) ;
171+ }
172+ const exportedSeed = await coreKitInstance . _UNSAFE_exportTssEd25519Seed ( ) ;
173+
174+ const coreKitInstance2 = newCoreKitInstance ( ) ;
175+ await coreKitInstance2 . init ( { handleRedirectResult : false , rehydrate : false } ) ;
176+ const localToken2 = await mockLogin2 ( importedEmail ) ;
177+ await coreKitInstance2 . loginWithJWT ( {
178+ verifier : "torus-test-health" ,
179+ verifierId : importedEmail ,
180+ idToken : localToken2 . idToken ,
181+ importTssKey : exportedSeed . toString ( "hex" ) ,
182+ } ) ;
183+
184+ const exportedSeed2 = await coreKitInstance2 . _UNSAFE_exportTssEd25519Seed ( ) ;
185+
186+ assert ( exportedSeed . toString ( "hex" ) === ( exportedSeed2 . toString ( "hex" ) ) ) ;
187+ } ) ;
188+
189+
190+
150191 } ) ;
151192} ) ;
0 commit comments