Skip to content

Commit 57ac0ce

Browse files
committed
bip340 key tweaking
1 parent c3fc225 commit 57ac0ce

File tree

10 files changed

+3062
-4843
lines changed

10 files changed

+3062
-4843
lines changed

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

Lines changed: 203 additions & 3304 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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"private": true,
55
"dependencies": {
66
"@tkey/common-types": "^15.1.0",
7+
"@toruslabs/torus.js": "15.2.0-alpha.0",
78
"@toruslabs/tss-dkls-lib": "^5.0.0-alpha.0",
89
"@toruslabs/tss-frost-lib": "^2.0.0-alpha.0",
910
"@toruslabs/tss-frost-lib-bip340": "^0.1.0-alpha.0",
@@ -14,9 +15,8 @@
1415
"@vitejs/plugin-react": "^4.3.2",
1516
"@web3auth/base": "^9.0.2",
1617
"@web3auth/ethereum-mpc-provider": "^9.3.0",
17-
"@web3auth/mpc-core-kit": "4.1.6-alpha.0",
18+
"@web3auth/mpc-core-kit": "file:../..",
1819
"@web3auth/mpc-passkey-plugin": "0.1.15-alpha.0",
19-
"@toruslabs/torus.js": "15.2.0-alpha.0",
2020
"browserify-zlib": "^0.2.0",
2121
"copy-webpack-plugin": "^11.0.0",
2222
"html-webpack-plugin": "^5.5.3",

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

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import{ tssLib as tssLibFrostBip340 } from "@toruslabs/tss-frost-lib-bip340";
3030
import "./App.css";
3131
import jwt, { Algorithm } from "jsonwebtoken";
3232
import { flow } from "./flow";
33+
import { ec as EC } from "elliptic";
3334

3435
type TssLib = typeof tssLibDkls | typeof tssLibFrost | typeof tssLibFrostBip340;
3536

@@ -423,16 +424,29 @@ function App() {
423424
uiConsole(sig.toString("hex"));
424425
}
425426
};
427+
428+
const signWithKeyTweak = async (): Promise<any> => {
429+
if (coreKitInstance.current.sigType === SIG_TYPE.ECDSA_SECP256K1) {
430+
throw new Error("Not supported for this signature type");
431+
} else if (coreKitInstance.current.sigType === SIG_TYPE.ED25519 || coreKitInstance.current.sigType === SIG_TYPE.BIP340) {
432+
const msg = Buffer.from("hello signer!");
433+
const keyTweak = (() => {
434+
const ec = new EC(coreKitInstance.current.keyType);
435+
return ec.genKeyPair().getPrivate();
436+
})();
437+
const sig = await coreKitInstance.current.sign(msg, { keyTweak });
438+
uiConsole(sig.toString("hex"));
439+
}
440+
};
441+
426442
const signMessageWithPrecomputedTss = async (): Promise<any> => {
427443
if (coreKitInstance.current.keyType === "secp256k1") {
428444
const precomputedTssClient = await coreKitInstance.current.precompute_secp256k1();
429445
const msg = Buffer.from("hello signer!");
430-
const sig = await coreKitInstance.current.sign(msg, false, precomputedTssClient);
431-
uiConsole(sig.toString("hex"));
432-
} else if (coreKitInstance.current.keyType === "ed25519") {
433-
const msg = Buffer.from("hello signer!");
434-
const sig = await coreKitInstance.current.sign(msg);
446+
const sig = await coreKitInstance.current.sign(msg, { secp256k1Precompute: precomputedTssClient });
435447
uiConsole(sig.toString("hex"));
448+
} else {
449+
throw new Error("Not supported for this key type");
436450
}
437451
};
438452

@@ -441,15 +455,13 @@ function App() {
441455
const [precomputedTssClient, precomputedTssClient2] = await Promise.all([coreKitInstance.current.precompute_secp256k1(), coreKitInstance.current.precompute_secp256k1()]);
442456

443457
const msg = Buffer.from("hello signer!");
444-
const sig = await coreKitInstance.current.sign(msg, false, precomputedTssClient);
458+
const sig = await coreKitInstance.current.sign(msg, { secp256k1Precompute: precomputedTssClient });
445459
const msg2 = Buffer.from("hello signer2!");
446460

447-
const sig2 = await coreKitInstance.current.sign(msg2, false, precomputedTssClient2);
461+
const sig2 = await coreKitInstance.current.sign(msg2, { secp256k1Precompute: precomputedTssClient2 });
448462
uiConsole("Sig1: ", sig.toString("hex"), "Sig2: ", sig2.toString("hex"));
449-
} else if (coreKitInstance.current.keyType === "ed25519") {
450-
const msg = Buffer.from("hello signer!");
451-
const sig = await coreKitInstance.current.sign(msg);
452-
uiConsole(sig.toString("hex"));
463+
} else {
464+
throw new Error("Not supported for this key type");
453465
}
454466
};
455467
const switchChainSepolia = async () => {
@@ -864,8 +876,12 @@ function App() {
864876
Sign Message
865877
</button>
866878

879+
<button onClick={signWithKeyTweak} className="card">
880+
Sign with Key Tweak
881+
</button>
882+
867883
<button onClick={signMessageWithPrecomputedTss} className="card">
868-
Sign Msgwith precomputed TSS
884+
Sign with precomputed TSS
869885
</button>
870886

871887
<button onClick={signMultipleMessagesWithPrecomputedTss} className="card">

0 commit comments

Comments
 (0)