-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
mpc-core-kit-react-native/mpc-core-kit-expo-ed25519/app/(off-network-recovery)/evm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { ScrollView } from "react-native"; | ||
|
||
import { OffNetworkRecoveryView } from "@/components/mpc/OffNetworkRecoveryView"; | ||
import { useMPCCoreKitStore } from "@/hooks/useMPCCoreKit"; | ||
|
||
export default function Index() { | ||
const { coreKitInstance, coreKitStatus, setCoreKitStatus } = useMPCCoreKitStore(); | ||
return ( | ||
<ScrollView> | ||
<OffNetworkRecoveryView coreKitInstance={coreKitInstance} coreKitStatus={coreKitStatus} setCoreKitStatus={setCoreKitStatus} /> | ||
</ScrollView> | ||
); | ||
} |
17 changes: 17 additions & 0 deletions
17
mpc-core-kit-react-native/mpc-core-kit-expo-ed25519/app/(off-network-recovery)/solana.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { ScrollView } from "react-native"; | ||
|
||
import { OffNetworkRecoveryView } from "@/components/mpc/OffNetworkRecoveryView"; | ||
import { useMPCCoreKitStore } from "@/hooks/useMPCCoreKit"; | ||
|
||
export default function Index() { | ||
const { coreKitEd25519Instance, coreKitEd25519Status, setCoreKitEd25519Status } = useMPCCoreKitStore(); | ||
return ( | ||
<ScrollView> | ||
<OffNetworkRecoveryView | ||
coreKitInstance={coreKitEd25519Instance} | ||
coreKitStatus={coreKitEd25519Status} | ||
setCoreKitStatus={setCoreKitEd25519Status} | ||
/> | ||
</ScrollView> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...core-kit-react-native/mpc-core-kit-expo-ed25519/components/mpc/OffNetworkRecoveryView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { COREKIT_STATUS, mnemonicToKey } from "@web3auth/react-native-mpc-core-kit"; | ||
import { Web3AuthMPCCoreKitRN } from "@web3auth/react-native-mpc-core-kit/dist/mpclib"; | ||
import BN from "bn.js"; | ||
import { useState } from "react"; | ||
import { Button, Text, TextInput, View } from "react-native"; | ||
|
||
import { useConsoleUI } from "@/hooks/useConsoleUI"; | ||
|
||
import { ConsoleUI } from "./ConsoleUI"; | ||
import { mpcViewStyles as styles } from "./styles"; | ||
|
||
export const OffNetworkRecoveryView = (props: { | ||
coreKitInstance: Web3AuthMPCCoreKitRN; | ||
coreKitStatus: COREKIT_STATUS; | ||
setCoreKitStatus: (status: COREKIT_STATUS) => void; | ||
}) => { | ||
const { consoleUI, loading, setLoading, uiConsole } = useConsoleUI(); | ||
const { coreKitInstance, coreKitStatus } = props; | ||
|
||
const [deviceFactor, setDeviceFactor] = useState(""); | ||
const [recoveryFactor, setRecoveryFactor] = useState(""); | ||
|
||
const recoverTss = async () => { | ||
uiConsole("Recovering TSS..."); | ||
if (!coreKitInstance) { | ||
throw new Error("coreKitInstance is not set"); | ||
} | ||
if (!deviceFactor || !recoveryFactor) { | ||
throw new Error("deviceFactor or recoveryFactor is not set"); | ||
} | ||
console.log(deviceFactor, recoveryFactor); | ||
try { | ||
const factorKey = mnemonicToKey(deviceFactor.trim()); | ||
const factorKey2 = mnemonicToKey(recoveryFactor.trim()); | ||
// console.log("factorKey2: ", factorKey2); | ||
setLoading(true); | ||
const result = await coreKitInstance._UNSAFE_recoverTssKey([factorKey, factorKey2]); | ||
uiConsole("Recovery Result: ", result); | ||
} catch (e) { | ||
console.log(e); | ||
console.log("error"); | ||
} | ||
setLoading(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
<View> | ||
<View style={styles.section}> | ||
<Text>Key In Device Factor</Text> | ||
<TextInput style={styles.input} onChangeText={setDeviceFactor} value={deviceFactor} /> | ||
<Text>Key In Recovery Factor</Text> | ||
<TextInput style={styles.input} onChangeText={setRecoveryFactor} value={recoveryFactor} /> | ||
{coreKitStatus !== COREKIT_STATUS.INITIALIZED && <Text>Corekit is not initialized</Text>} | ||
<Button disabled={coreKitStatus !== COREKIT_STATUS.INITIALIZED} title="Recover TSS" onPress={() => recoverTss()} /> | ||
</View> | ||
</View> | ||
<ConsoleUI consoleUI={consoleUI} loading={loading} /> | ||
</> | ||
); | ||
}; |