Skip to content

Commit bef9847

Browse files
make it possible to call precompute seperately
1 parent d82f4c1 commit bef9847

File tree

5 files changed

+190
-155
lines changed

5 files changed

+190
-155
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: 41 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,36 @@ 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 = await coreKitInstance.precompute_secp256k1();
401+
const precomputedTssClient2 = await coreKitInstance.precompute_secp256k1();
402+
403+
const msg = Buffer.from("hello signer!");
404+
const sig = await coreKitInstance.sign(msg, false, precomputedTssClient);
405+
const msg2 = Buffer.from("hello signer2!");
401406

407+
const sig2 = await coreKitInstance.sign(msg2, false, precomputedTssClient2);
408+
uiConsole("Sig1: ", sig.toString("hex"), "Sig2: ", sig2.toString("hex"));
409+
} else if (coreKitInstance.keyType === "ed25519") {
410+
const msg = Buffer.from("hello signer!");
411+
const sig = await coreKitInstance.sign(msg);
412+
uiConsole(sig.toString("hex"));
413+
}
414+
};
402415
const switchChainSepolia = async () => {
403416
if (!provider) {
404417
uiConsole("provider not initialized yet");
@@ -689,6 +702,14 @@ function App() {
689702
Sign Message
690703
</button>
691704

705+
<button onClick={signMessageWithPrecomputedTss} className="card">
706+
Sign Msgwith precomputed TSS
707+
</button>
708+
709+
<button onClick={signMultipleMessagesWithPrecomputedTss} className="card">
710+
Sign Multiple MSGs with precomputed TSS
711+
</button>
712+
692713
<button onClick={sendTransaction} className="card">
693714
Send Transaction
694715
</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)