diff --git a/demo/redirect-flow-example/package-lock.json b/demo/redirect-flow-example/package-lock.json index 28b6448d..4db21182 100644 --- a/demo/redirect-flow-example/package-lock.json +++ b/demo/redirect-flow-example/package-lock.json @@ -9,8 +9,9 @@ "version": "0.1.0", "dependencies": { "@tkey/common-types": "^15.1.0", - "@toruslabs/tss-dkls-lib": "^4.0.0", - "@toruslabs/tss-frost-lib": "^1.0.0", + "@toruslabs/tss-dkls-lib": "^5.0.0-alpha.0", + "@toruslabs/tss-frost-lib": "^2.0.0-alpha.0", + "@toruslabs/tss-frost-lib-bip340": "^0.1.0-alpha.0", "@types/jest": "^27.5.2", "@types/node": "^16.18.48", "@types/react": "^18.3.11", @@ -55,7 +56,7 @@ }, "../..": { "name": "@web3auth/mpc-core-kit", - "version": "3.2.6", + "version": "4.0.0-alpha.0", "license": "ISC", "dependencies": { "@tkey/common-types": "^15.1.0", @@ -63,17 +64,17 @@ "@tkey/share-serialization": "^15.1.0", "@tkey/storage-layer-torus": "^15.1.0", "@tkey/tss": "^15.1.0", - "@toruslabs/constants": "^14.0.0", + "@toruslabs/constants": "^14.2.0", "@toruslabs/customauth": "^20.3.0", - "@toruslabs/elliptic-wrapper": "^0.1.0", - "@toruslabs/fetch-node-details": "^14.0.1", - "@toruslabs/fnd-base": "^14.0.0", + "@toruslabs/elliptic-wrapper": "^0.1.1", + "@toruslabs/fetch-node-details": "^14.2.0", + "@toruslabs/fnd-base": "^14.2.0", "@toruslabs/metadata-helpers": "^6.0.0", "@toruslabs/openlogin-utils": "^8.2.1", "@toruslabs/session-manager": "^3.1.0", - "@toruslabs/torus.js": "file:./toruslabs-torus.js-15.1.2.tgz", - "@toruslabs/tss-client": "^3.1.0", - "@toruslabs/tss-frost-client": "0.3.1", + "@toruslabs/torus.js": "15.2.0-alpha.0", + "@toruslabs/tss-client": "^3.3.0-alpha.0", + "@toruslabs/tss-frost-client": "^1.0.0-alpha.0", "@toruslabs/tss-frost-common": "^1.0.1", "bn.js": "^5.2.1", "bowser": "^2.11.0", @@ -82,11 +83,12 @@ }, "devDependencies": { "@babel/register": "^7.25.7", + "@noble/curves": "^1.6.0", "@toruslabs/config": "^2.2.0", "@toruslabs/eslint-config-typescript": "^3.3.3", "@toruslabs/torus-scripts": "^6.1.2", - "@toruslabs/tss-dkls-lib": "^4.0.0", - "@toruslabs/tss-frost-lib": "^1.0.0", + "@toruslabs/tss-dkls-lib": "^5.0.0-alpha.0", + "@toruslabs/tss-frost-lib": "^2.0.0-alpha.0", "@types/chai": "^4.3.16", "@types/elliptic": "^6.4.18", "@types/jsonwebtoken": "^9.0.7", @@ -115,8 +117,9 @@ }, "peerDependencies": { "@babel/runtime": "^7.x", - "@toruslabs/tss-dkls-lib": "^4.0.0", - "@toruslabs/tss-frost-lib": "^1.0.0" + "@toruslabs/tss-dkls-lib": "^5.0.0-alpha.0", + "@toruslabs/tss-frost-lib": "^2.0.0-alpha.0", + "@toruslabs/tss-frost-lib-bip340": "^0.1.0-alpha.0" }, "peerDependenciesMeta": { "@toruslabs/tss-dkls-lib": { @@ -124,6 +127,9 @@ }, "@toruslabs/tss-frost-lib": { "optional": true + }, + "@toruslabs/tss-frost-lib-bip340": { + "optional": true } } }, @@ -1666,14 +1672,19 @@ } }, "node_modules/@toruslabs/tss-dkls-lib": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/@toruslabs/tss-dkls-lib/-/tss-dkls-lib-4.1.0.tgz", - "integrity": "sha512-Iirs3uNigaYFSek/AqwSzsQovRzJaLVnmoGU5wC3/gpMTU9ZM4hLIconztRlSgfFmqcvxZWj+0JX1DnXyMmdXw==" + "version": "5.0.0-alpha.0", + "resolved": "https://registry.npmjs.org/@toruslabs/tss-dkls-lib/-/tss-dkls-lib-5.0.0-alpha.0.tgz", + "integrity": "sha512-htUWzL2JZoKTtw++WLdQ1AK3wPTe0yezv/twWjpQIzLFkkfoO9Urnl5n9S6jFx98Z1dDRJRBWSED9PSuqY/x7w==" }, "node_modules/@toruslabs/tss-frost-lib": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@toruslabs/tss-frost-lib/-/tss-frost-lib-1.0.0.tgz", - "integrity": "sha512-uDsM7f6NiVvNKVOfTUK+CucZUy1TjvTSYvk5LL8t2i/izWzNbBg4NO9qAFws3Kp9Kt1hG0xo8FkWzh3+oJ82xA==" + "version": "2.0.0-alpha.0", + "resolved": "https://registry.npmjs.org/@toruslabs/tss-frost-lib/-/tss-frost-lib-2.0.0-alpha.0.tgz", + "integrity": "sha512-oZy99HiES3OR8t6rrV6ccxwbrq38kxzz1C/5UIdqUVd2IRSWZzrcD+J4Q2/yR5bDMoK1HrucLShK96uMoXyv/A==" + }, + "node_modules/@toruslabs/tss-frost-lib-bip340": { + "version": "0.1.0-alpha.0", + "resolved": "https://registry.npmjs.org/@toruslabs/tss-frost-lib-bip340/-/tss-frost-lib-bip340-0.1.0-alpha.0.tgz", + "integrity": "sha512-2dK/fhIfkxdbI/WPCRc1nJlL81nu70VMJyj313eJbO6oU13S92YjzoIhiCvBn6G/F3XpftD44wqNkr+S3QbAuA==" }, "node_modules/@toruslabs/tweetnacl-js": { "version": "1.0.4", diff --git a/demo/redirect-flow-example/package.json b/demo/redirect-flow-example/package.json index 6dc37cc1..16615cf9 100644 --- a/demo/redirect-flow-example/package.json +++ b/demo/redirect-flow-example/package.json @@ -4,8 +4,9 @@ "private": true, "dependencies": { "@tkey/common-types": "^15.1.0", - "@toruslabs/tss-dkls-lib": "^4.0.0", - "@toruslabs/tss-frost-lib": "^1.0.0", + "@toruslabs/tss-dkls-lib": "^5.0.0-alpha.0", + "@toruslabs/tss-frost-lib": "^2.0.0-alpha.0", + "@toruslabs/tss-frost-lib-bip340": "^0.1.0-alpha.0", "@types/jest": "^27.5.2", "@types/node": "^16.18.48", "@types/react": "^18.3.11", diff --git a/demo/redirect-flow-example/src/App.tsx b/demo/redirect-flow-example/src/App.tsx index 38537668..d6890402 100644 --- a/demo/redirect-flow-example/src/App.tsx +++ b/demo/redirect-flow-example/src/App.tsx @@ -12,6 +12,7 @@ import { parseToken, factorKeyCurve, makeEthereumSigner, + SIG_TYPE, } from "@web3auth/mpc-core-kit"; import { PasskeysPlugin } from "@web3auth/mpc-passkey-plugin"; import Web3 from "web3"; @@ -19,13 +20,16 @@ import { CHAIN_NAMESPACES, CustomChainConfig, IProvider } from "@web3auth/base"; import { EthereumSigningProvider } from "@web3auth/ethereum-mpc-provider"; import { BN } from "bn.js"; import { KeyType, Point } from "@tkey/common-types"; -import { tssLib } from "@toruslabs/tss-dkls-lib"; -// import{ tssLib } from "@toruslabs/tss-frost-lib"; +import { tssLib as tssLibDkls } from "@toruslabs/tss-dkls-lib"; +import{ tssLib as tssLibFrost } from "@toruslabs/tss-frost-lib"; +import{ tssLib as tssLibFrostBip340 } from "@toruslabs/tss-frost-lib-bip340"; import "./App.css"; import jwt, { Algorithm } from "jsonwebtoken"; import { flow } from "./flow"; +type TssLib = typeof tssLibDkls | typeof tssLibFrost | typeof tssLibFrostBip340; + const uiConsole = (...args: any[]): void => { const el = document.querySelector("#console>p"); if (el) { @@ -47,16 +51,6 @@ const DEFAULT_CHAIN_CONFIG: CustomChainConfig = { decimals: 18, }; -const coreKitInstance = new Web3AuthMPCCoreKit({ - web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ", - web3AuthNetwork: selectedNetwork, - uxMode: "redirect", - manualSync: true, - storage: window.localStorage, - // sessionTime: 3600, // <== can provide variable session time based on user subscribed plan - tssLib, - useDKG: false, -}); const passkeyPlugin = new PasskeysPlugin(); @@ -100,7 +94,18 @@ function App() { const [question, setQuestion] = useState(undefined); const [newQuestion, setNewQuestion] = useState(undefined); const securityQuestion = useMemo(() => new TssSecurityQuestion(), []); - + const [selectedTssLib, setSelectedTssLib] = useState(tssLibDkls); + const [coreKitInstance, setCoreKitInstance] = useState( + new Web3AuthMPCCoreKit({ + web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ", + web3AuthNetwork: selectedNetwork, + uxMode: "redirect", + manualSync: true, + storage: window.localStorage, + tssLib: selectedTssLib, + useDKG: false, + }) + ); async function setupProvider(chainConfig?: CustomChainConfig) { if (coreKitInstance.keyType !== KeyType.secp256k1) { console.warn(`Ethereum requires keytype ${KeyType.secp256k1}, skipping provider setup`); @@ -113,45 +118,55 @@ function App() { // decide whether to rehydrate session const rehydrate = true; - const initialized = useRef(false); - useEffect(() => { - const init = async () => { - // Example config to handle redirect result manually - if (coreKitInstance.status === COREKIT_STATUS.NOT_INITIALIZED) { - await coreKitInstance.init({ handleRedirectResult: false, rehydrate }); - await passkeyPlugin.initWithMpcCoreKit(coreKitInstance as any); - if (window.location.hash.includes("#state")) { - await coreKitInstance.handleRedirectResult(); - } - } - if (coreKitInstance.status === COREKIT_STATUS.LOGGED_IN) { - await setupProvider(); + const init = async (newCoreKitInstance: Web3AuthMPCCoreKit) => { + // Example config to handle redirect result manually + if (newCoreKitInstance.status === COREKIT_STATUS.NOT_INITIALIZED) { + await newCoreKitInstance.init({ handleRedirectResult: false, rehydrate }); + if (window.location.hash.includes("#state")) { + await newCoreKitInstance.handleRedirectResult(); } + } + if (newCoreKitInstance.status === COREKIT_STATUS.LOGGED_IN) { + await setupProvider(); + } - if (coreKitInstance.status === COREKIT_STATUS.REQUIRED_SHARE) { - uiConsole( - "required more shares, please enter your backup/ device factor key, or reset account unrecoverable once reset, please use it with caution]" - ); - } + if (newCoreKitInstance.status === COREKIT_STATUS.REQUIRED_SHARE) { + uiConsole( + "required more shares, please enter your backup/ device factor key, or reset account unrecoverable once reset, please use it with caution]" + ); + } - console.log("coreKitInstance.status", coreKitInstance.status); - setCoreKitStatus(coreKitInstance.status); + console.log("newCoreKitInstance.status", newCoreKitInstance.status); + setCoreKitStatus(newCoreKitInstance.status); - try { - let result = securityQuestion.getQuestion(coreKitInstance!); - setQuestion(result); - uiConsole("security question set"); - } catch (e) { - uiConsole("security question not set"); - } - }; - if (!initialized.current) + try { + let result = securityQuestion.getQuestion(newCoreKitInstance!); + setQuestion(result); + uiConsole("security question set"); + } catch (e) { + uiConsole("security question not set"); + } + }; + + useEffect(() => { + const instance = new Web3AuthMPCCoreKit({ + web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ", + web3AuthNetwork: selectedNetwork, + uxMode: "redirect", + manualSync: true, + storage: window.localStorage, + tssLib: selectedTssLib, + useDKG: false, + }) + setCoreKitInstance( + instance + ) + if (instance.status === COREKIT_STATUS.NOT_INITIALIZED) { - init(); - initialized.current = true; + init(instance); } - }, []); + }, [selectedTssLib]); useEffect(() => { if (provider) { @@ -175,7 +190,7 @@ function App() { if (!factorPubs) { throw new Error("factorPubs not found"); } - const pubsHex = factorPubs[coreKitInstance.tKey.tssTag].map((pub) => { + const pubsHex = factorPubs[coreKitInstance.tKey.tssTag].map(pub => { return pub.toSEC1(factorKeyCurve, true).toString("hex"); }); uiConsole(pubsHex); @@ -361,8 +376,7 @@ function App() { } const address = (await web3.eth.getAccounts())[0]; const balance = web3.utils.fromWei( - await web3.eth.getBalance(address), - // Balance is in wei + await web3.eth.getBalance(address), // Balance is in wei "ether" ); uiConsole(balance); @@ -370,19 +384,18 @@ function App() { }; const signMessage = async (): Promise => { - if (coreKitInstance.keyType === "secp256k1") { + if (coreKitInstance.sigType === SIG_TYPE.ECDSA_SECP256K1) { if (!web3) { uiConsole("web3 not initialized yet"); return; } const fromAddress = (await web3.eth.getAccounts())[0]; - const message = "hello"; const signedMessage = await web3.eth.personal.sign(message, fromAddress, ""); uiConsole(signedMessage); - } else if (coreKitInstance.keyType === "ed25519") { + } else if (coreKitInstance.sigType === SIG_TYPE.ED25519 || coreKitInstance.sigType === SIG_TYPE.BIP340) { const msg = Buffer.from("hello signer!"); const sig = await coreKitInstance.sign(msg); uiConsole(sig.toString("hex")); @@ -630,6 +643,32 @@ function App() { await coreKitInstance.commitChanges(); }; + const tssLibSelector = ( +
+ + +
+ ); + const loggedInView = ( <>

Account Details

@@ -804,6 +843,7 @@ function App() { const unloggedInView = ( <> + {tssLibSelector} setMockEmail(e.target.value)}>