diff --git a/demo/redirect-flow-example/package-lock.json b/demo/redirect-flow-example/package-lock.json index ed42060..817aa92 100644 --- a/demo/redirect-flow-example/package-lock.json +++ b/demo/redirect-flow-example/package-lock.json @@ -8,7 +8,7 @@ "name": "redirect-flow-example", "version": "0.1.0", "dependencies": { - "@tkey/common-types": "^15.1.0", + "@tkey/common-types": "^15.2.1-alpha.0", "@toruslabs/torus.js": "15.2.0-alpha.0", "@toruslabs/tss-dkls-lib": "^5.0.0-alpha.0", "@toruslabs/tss-frost-lib": "^2.0.0-alpha.0", @@ -21,7 +21,7 @@ "@web3auth/base": "^9.0.2", "@web3auth/ethereum-mpc-provider": "^9.3.0", "@web3auth/mpc-core-kit": "file:../..", - "@web3auth/mpc-passkey-plugin": "0.1.15-alpha.0", + "@web3auth/mpc-passkey-plugin": "~0.1.15-alpha.0", "browserify-zlib": "^0.2.0", "copy-webpack-plugin": "^11.0.0", "html-webpack-plugin": "^5.5.3", @@ -57,14 +57,14 @@ }, "../..": { "name": "@web3auth/mpc-core-kit", - "version": "4.1.6-alpha.0", + "version": "4.1.7-alpha.0", "license": "ISC", "dependencies": { - "@tkey/common-types": "^15.1.0", - "@tkey/core": "^15.1.0", + "@tkey/common-types": "file:../tkey/packages/common-types", + "@tkey/core": "file:../tkey/packages/core/tkey-core-15.2.1-alpha.0.tgz", "@tkey/share-serialization": "^15.1.0", - "@tkey/storage-layer-torus": "^15.1.0", - "@tkey/tss": "^15.1.0", + "@tkey/storage-layer-torus": "file:../tkey/packages/storage-layer-torus/tkey-storage-layer-torus-15.2.1-alpha.0.tgz", + "@tkey/tss": "file:../tkey/packages/tss/tkey-tss-15.2.1-alpha.0.tgz", "@toruslabs/constants": "^14.2.0", "@toruslabs/customauth": "^20.3.0", "@toruslabs/elliptic-wrapper": "^0.1.1", @@ -73,7 +73,7 @@ "@toruslabs/metadata-helpers": "^6.0.0", "@toruslabs/openlogin-utils": "^8.2.1", "@toruslabs/session-manager": "^3.1.0", - "@toruslabs/torus.js": "15.2.0-alpha.0", + "@toruslabs/torus.js": "file:../torus.js/toruslabs-torus.js-15.1.1.tgz", "@toruslabs/tss-client": "^3.3.0-alpha.0", "@toruslabs/tss-frost-client": "^1.0.1-alpha.0", "@toruslabs/tss-frost-common": "^1.0.2-alpha.0", @@ -976,9 +976,9 @@ "license": "MIT" }, "node_modules/@tkey/common-types": { - "version": "15.1.0", - "resolved": "https://registry.npmjs.org/@tkey/common-types/-/common-types-15.1.0.tgz", - "integrity": "sha512-oA5gLoyhNNMgCKcjvwLyU31TVS5KMT+lotRrjjoBdDvS0keZwzSLrtHWbXj8jZDlSZaqbd3VlPbCoHcqpk1irA==", + "version": "15.2.1-alpha.0", + "resolved": "https://registry.npmjs.org/@tkey/common-types/-/common-types-15.2.1-alpha.0.tgz", + "integrity": "sha512-0BXtkB2PHNtV+fCmTVhWRqz/0tc975/z2onqCDQyCn0Lk36uhAPbEwCPRJ4vrccICxVizuYagZ+CazaEjk/ICA==", "license": "MIT", "dependencies": { "@toruslabs/customauth": "^20.3.0", diff --git a/demo/redirect-flow-example/package.json b/demo/redirect-flow-example/package.json index 098bf77..b8133db 100644 --- a/demo/redirect-flow-example/package.json +++ b/demo/redirect-flow-example/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "private": true, "dependencies": { - "@tkey/common-types": "^15.1.0", + "@tkey/common-types": "^15.2.1-alpha.0", "@toruslabs/torus.js": "15.2.0-alpha.0", "@toruslabs/tss-dkls-lib": "^5.0.0-alpha.0", "@toruslabs/tss-frost-lib": "^2.0.0-alpha.0", @@ -16,7 +16,7 @@ "@web3auth/base": "^9.0.2", "@web3auth/ethereum-mpc-provider": "^9.3.0", "@web3auth/mpc-core-kit": "file:../..", - "@web3auth/mpc-passkey-plugin": "0.1.15-alpha.0", + "@web3auth/mpc-passkey-plugin": "~0.1.15-alpha.0", "browserify-zlib": "^0.2.0", "copy-webpack-plugin": "^11.0.0", "html-webpack-plugin": "^5.5.3", diff --git a/demo/redirect-flow-example/src/App.tsx b/demo/redirect-flow-example/src/App.tsx index e6a6fb1..e3d5747 100644 --- a/demo/redirect-flow-example/src/App.tsx +++ b/demo/redirect-flow-example/src/App.tsx @@ -104,7 +104,7 @@ function App() { uxMode: "redirect", manualSync: true, storage: window.localStorage, - tssLib: selectedTssLib, + supportedKeyTypes: [KeyType.secp256k1, KeyType.ed25519], useDKG: false, }) ); @@ -118,7 +118,7 @@ function App() { // ) ) async function setupProvider(chainConfig?: CustomChainConfig) { - if (coreKitInstance.current.keyType !== KeyType.secp256k1) { + if (!coreKitInstance.current.getSupportedCurveKeyTypes().includes(KeyType.ed25519)) { console.warn(`Ethereum requires keytype ${KeyType.secp256k1}, skipping provider setup`); return; } @@ -175,7 +175,7 @@ function App() { uxMode: "redirect", manualSync: false, storage: window.localStorage, - tssLib: selectedTssLib, + supportedKeyTypes: [KeyType.ed25519, KeyType.secp256k1], useDKG: false, }) @@ -205,14 +205,11 @@ function App() { if (!coreKitInstance) { throw new Error("coreKitInstance not found"); } - const factorPubs = coreKitInstance.current.tKey.metadata.factorPubs; - if (!factorPubs) { + const factorPubs = coreKitInstance.current.getTssFactorPub(); + if (!factorPubs || factorPubs.length === 0) { throw new Error("factorPubs not found"); } - const pubsHex = factorPubs[coreKitInstance.current.tKey.tssTag].map(pub => { - return pub.toSEC1(factorKeyCurve, true).toString("hex"); - }); - uiConsole(pubsHex); + uiConsole(factorPubs); }; const loginWithMock = async () => { @@ -406,64 +403,85 @@ function App() { return balance; }; - const signMessage = async (): Promise => { - if (coreKitInstance.current.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.current.sigType === SIG_TYPE.ED25519 || coreKitInstance.current.sigType === SIG_TYPE.BIP340) { - const msg = Buffer.from("hello signer!"); - const sig = await coreKitInstance.current.sign(msg); - uiConsole(sig.toString("hex")); + const signMessageEd25519 = async (): Promise => { + + if (!coreKitInstance.current.getSupportedSigTypes().includes(SIG_TYPE.ED25519)) { + coreKitInstance.current.addTssLibs([tssLibFrost]); + } + const msg = Buffer.from("hello signer!"); + const sig = await coreKitInstance.current.signED25519(msg); + uiConsole(sig.toString("hex")); + } + + const signMessage = async (): Promise => { + if (!web3) { + uiConsole("web3 not initialized yet"); + return; } + if (!coreKitInstance.current.getSupportedSigTypes().includes(SIG_TYPE.ECDSA_SECP256K1)) { + coreKitInstance.current.addTssLibs([tssLibDkls]); + } + const fromAddress = (await web3.eth.getAccounts())[0]; + const message = "hello"; + const signedMessage = await web3.eth.personal.sign(message, fromAddress, ""); + uiConsole(signedMessage); }; const signWithKeyTweak = async (): Promise => { - if (coreKitInstance.current.sigType === SIG_TYPE.ECDSA_SECP256K1) { - throw new Error("Not supported for this signature type"); - } else if (coreKitInstance.current.sigType === SIG_TYPE.ED25519 || coreKitInstance.current.sigType === SIG_TYPE.BIP340) { - const msg = Buffer.from("hello signer!"); - const keyTweak = (() => { - const ec = new EC(coreKitInstance.current.keyType); - return ec.genKeyPair().getPrivate(); - })(); - const sig = await coreKitInstance.current.sign(msg, { keyTweak }); - uiConsole(sig.toString("hex")); + if (!coreKitInstance.current.getSupportedCurveKeyTypes().includes(KeyType.secp256k1) ) { + throw new Error("Not supported for this curve type"); } + + if (!coreKitInstance.current.getSupportedSigTypes().includes(SIG_TYPE.BIP340)) { + coreKitInstance.current.addTssLibs([tssLibFrostBip340]) + } + + const msg = Buffer.from("hello signer!"); + const keyTweak = (() => { + const ec = new EC(KeyType.secp256k1); + return ec.genKeyPair().getPrivate(); + })(); + const sig = await coreKitInstance.current.signBIP340(msg ); + uiConsole(sig.toString("hex")); }; const signMessageWithPrecomputedTss = async (): Promise => { - if (coreKitInstance.current.keyType === "secp256k1") { - const precomputedTssClient = await coreKitInstance.current.precompute_secp256k1(); - const msg = Buffer.from("hello signer!"); - const sig = await coreKitInstance.current.sign(msg, { secp256k1Precompute: precomputedTssClient }); - uiConsole(sig.toString("hex")); - } else { - throw new Error("Not supported for this key type"); + + if (!coreKitInstance.current.getSupportedCurveKeyTypes().includes(KeyType.secp256k1) ) { + throw new Error("Not supported for this curve type"); } + if (!coreKitInstance.current.getSupportedSigTypes().includes(SIG_TYPE.ECDSA_SECP256K1)) { + coreKitInstance.current.addTssLibs([tssLibDkls]) + } + + const precomputedTssClient = await coreKitInstance.current.precompute_secp256k1(); + const msg = Buffer.from("hello signer!"); + const sig = await coreKitInstance.current.sign_ECDSA_secp256k1(msg, { secp256k1Precompute: precomputedTssClient }); + uiConsole(sig.toString("hex")); }; const signMultipleMessagesWithPrecomputedTss = async (): Promise => { - if (coreKitInstance.current.keyType === "secp256k1") { - const [precomputedTssClient, precomputedTssClient2] = await Promise.all([coreKitInstance.current.precompute_secp256k1(), coreKitInstance.current.precompute_secp256k1()]); - const msg = Buffer.from("hello signer!"); - const sig = await coreKitInstance.current.sign(msg, { secp256k1Precompute: precomputedTssClient }); - const msg2 = Buffer.from("hello signer2!"); - - const sig2 = await coreKitInstance.current.sign(msg2, { secp256k1Precompute: precomputedTssClient2 }); - uiConsole("Sig1: ", sig.toString("hex"), "Sig2: ", sig2.toString("hex")); - } else { - throw new Error("Not supported for this key type"); + if (!coreKitInstance.current.getSupportedCurveKeyTypes().includes(KeyType.secp256k1) ) { + throw new Error("Not supported for this curve type"); + } + if (!coreKitInstance.current.getSupportedSigTypes().includes(SIG_TYPE.ECDSA_SECP256K1)) { + coreKitInstance.current.addTssLibs([tssLibDkls]) } + + const [precomputedTssClient, precomputedTssClient2] = await Promise.all([coreKitInstance.current.precompute_secp256k1(), coreKitInstance.current.precompute_secp256k1()]); + + const msg = Buffer.from("hello signer!"); + const sig = await coreKitInstance.current.sign_ECDSA_secp256k1(msg, { secp256k1Precompute: precomputedTssClient }); + const msg2 = Buffer.from("hello signer2!"); + + const sig2 = await coreKitInstance.current.sign_ECDSA_secp256k1(msg2, { secp256k1Precompute: precomputedTssClient2 }); + uiConsole("Sig1: ", sig.toString("hex"), "Sig2: ", sig2.toString("hex")); + }; + + const switchChainSepolia = async () => { if (!provider) { uiConsole("provider not initialized yet"); @@ -705,32 +723,6 @@ function App() { await coreKitInstance.current.commitChanges(); }; - const tssLibSelector = ( -
- - -
- ); - const loggedInView = ( <>

Account Details

@@ -739,8 +731,12 @@ function App() { Get User Info - + + - + + + + @@ -872,6 +876,10 @@ function App() { Get Balance + + @@ -909,7 +917,6 @@ function App() { const unloggedInView = ( <> - {tssLibSelector} setMockEmail(e.target.value)}>