Skip to content

Commit 9206669

Browse files
Merge pull request #189 from Web3Auth/feat/separate-precompute
make it possible to call precompute seperately
2 parents a9b5248 + ad5fe3e commit 9206669

File tree

5 files changed

+208
-160
lines changed

5 files changed

+208
-160
lines changed

demo/redirect-flow-example/package-lock.json

Lines changed: 49 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/redirect-flow-example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@types/react-dom": "^18.3.0",
1313
"@vitejs/plugin-react": "^4.3.2",
1414
"@web3auth/base": "^9.0.2",
15-
"@web3auth/ethereum-mpc-provider": "^9.0.2",
15+
"@web3auth/ethereum-mpc-provider": "^9.3.0",
1616
"@web3auth/mpc-core-kit": "file:../..",
1717
"browserify-zlib": "^0.2.0",
1818
"copy-webpack-plugin": "^11.0.0",

demo/redirect-flow-example/src/App.tsx

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -370,26 +370,10 @@ function App() {
370370
return;
371371
}
372372
const fromAddress = (await web3.eth.getAccounts())[0];
373-
const originalMessage = [
374-
{
375-
type: "string",
376-
name: "fullName",
377-
value: "Satoshi Nakamoto",
378-
},
379-
{
380-
type: "uint32",
381-
name: "userId",
382-
value: "1212",
383-
},
384-
];
385-
const params = [originalMessage, fromAddress];
386-
const method = "eth_signTypedData";
387-
const signedMessage = await (web3.currentProvider as any)?.sendAsync({
388-
id: 1,
389-
method,
390-
params,
391-
fromAddress,
392-
});
373+
374+
const message = "hello";
375+
const signedMessage = await web3.eth.personal.sign(message, fromAddress, "");
376+
393377

394378
uiConsole(signedMessage);
395379
} else if (coreKitInstance.keyType === "ed25519") {
@@ -398,7 +382,35 @@ function App() {
398382
uiConsole(sig.toString("hex"));
399383
}
400384
};
385+
const signMessageWithPrecomputedTss = async (): Promise<any> => {
386+
if (coreKitInstance.keyType === "secp256k1") {
387+
const precomputedTssClient = await coreKitInstance.precompute_secp256k1();
388+
const msg = Buffer.from("hello signer!");
389+
const sig = await coreKitInstance.sign(msg, false, precomputedTssClient);
390+
uiConsole(sig.toString("hex"));
391+
} else if (coreKitInstance.keyType === "ed25519") {
392+
const msg = Buffer.from("hello signer!");
393+
const sig = await coreKitInstance.sign(msg);
394+
uiConsole(sig.toString("hex"));
395+
}
396+
};
397+
398+
const signMultipleMessagesWithPrecomputedTss = async (): Promise<any> => {
399+
if (coreKitInstance.keyType === "secp256k1") {
400+
const [precomputedTssClient, precomputedTssClient2] = await Promise.all([coreKitInstance.precompute_secp256k1(), coreKitInstance.precompute_secp256k1()]);
401+
402+
const msg = Buffer.from("hello signer!");
403+
const sig = await coreKitInstance.sign(msg, false, precomputedTssClient);
404+
const msg2 = Buffer.from("hello signer2!");
401405

406+
const sig2 = await coreKitInstance.sign(msg2, false, precomputedTssClient2);
407+
uiConsole("Sig1: ", sig.toString("hex"), "Sig2: ", sig2.toString("hex"));
408+
} else if (coreKitInstance.keyType === "ed25519") {
409+
const msg = Buffer.from("hello signer!");
410+
const sig = await coreKitInstance.sign(msg);
411+
uiConsole(sig.toString("hex"));
412+
}
413+
};
402414
const switchChainSepolia = async () => {
403415
if (!provider) {
404416
uiConsole("provider not initialized yet");
@@ -689,6 +701,14 @@ function App() {
689701
Sign Message
690702
</button>
691703

704+
<button onClick={signMessageWithPrecomputedTss} className="card">
705+
Sign Msgwith precomputed TSS
706+
</button>
707+
708+
<button onClick={signMultipleMessagesWithPrecomputedTss} className="card">
709+
Sign Multiple MSGs with precomputed TSS
710+
</button>
711+
692712
<button onClick={sendTransaction} className="card">
693713
Send Transaction
694714
</button>

src/interfaces.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
TorusVerifierResponse,
1010
UX_MODE_TYPE,
1111
} from "@toruslabs/customauth";
12+
import { Client } from "@toruslabs/tss-client";
1213
// TODO: move the types to a base class for both dkls and frost in future
1314
import type { tssLib as TssDklsLib } from "@toruslabs/tss-dkls-lib";
1415
import type { tssLib as TssFrostLib } from "@toruslabs/tss-frost-lib";
@@ -470,3 +471,8 @@ export interface EthereumSigner {
470471
sign: (msgHash: Buffer) => Promise<EthSig>;
471472
getPublic: () => Promise<Buffer>;
472473
}
474+
475+
export interface Secp256k1PrecomputedClient {
476+
client: Client;
477+
serverCoeffs: Record<string, string>;
478+
}

0 commit comments

Comments
 (0)