Skip to content

Commit

Permalink
use secure pub sub instead of broadcast channel in popup mode
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyapotti committed Nov 1, 2023
1 parent 603e6fc commit 849d531
Show file tree
Hide file tree
Showing 9 changed files with 1,087 additions and 1,696 deletions.
1,708 changes: 445 additions & 1,263 deletions examples/vue-example/package-lock.json

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions examples/vue-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,44 @@
"@toruslabs/openlogin-jrpc": "file:../../packages/openlogin-jrpc/",
"@toruslabs/openlogin-subkey": "file:../../packages/openlogin-subkey/",
"@toruslabs/openlogin-utils": "file:../../packages/openlogin-utils/",
"@toruslabs/tss-client": "^1.6.1-alpha.0",
"@toruslabs/tss-lib": "^1.6.0-alpha.0",
"@web3auth-mpc/ethereum-provider": "^2.1.9",
"@web3auth/ethereum-provider": "^7.0.2",
"@toruslabs/tss-client": "^2.0.0",
"@toruslabs/tss-lib": "^2.0.0",
"@web3auth-mpc/ethereum-provider": "^3.0.0",
"@web3auth/ethereum-provider": "^7.0.4",
"bn.js": "^5.2.1",
"bs58": "^5.0.0",
"core-js": "^3.32.1",
"core-js": "^3.33.2",
"elliptic": "^6.5.4",
"ethereum-cryptography": "^2.1.2",
"ethers": "^6.7.1",
"ethers": "^6.8.0",
"openlogin": "file:../../packages/wrapper/",
"vue": "^3.3.4"
"vue": "^3.3.7"
},
"devDependencies": {
"@toruslabs/constants": "^13.0.1",
"@types/bs58": "^4.0.1",
"@types/elliptic": "^6.4.14",
"@typescript-eslint/eslint-plugin": "^6.4.1",
"@typescript-eslint/parser": "^6.4.1",
"@toruslabs/constants": "^13.0.3",
"@types/bs58": "^4.0.3",
"@types/elliptic": "^6.4.16",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"@vue/cli-plugin-babel": "~5.0.8",
"@vue/cli-plugin-eslint": "~5.0.8",
"@vue/cli-plugin-typescript": "~5.0.8",
"@vue/cli-service": "~5.0.8",
"@vue/eslint-config-prettier": "^8.0.0",
"@vue/eslint-config-typescript": "^11.0.3",
"autoprefixer": "^10.4.15",
"@vue/eslint-config-typescript": "^12.0.0",
"autoprefixer": "^10.4.16",
"babel-eslint": "^10.1.0",
"crypto-browserify": "^3.12.0",
"eslint": "^8.47.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint": "^8.52.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-vue": "^9.17.0",
"eslint-plugin-vue": "^9.18.1",
"https-browserify": "^1.0.0",
"os-browserify": "^0.3.0",
"postcss": "^8.4.28",
"prettier": "^3.0.2",
"tailwindcss": "^3.3.3",
"typescript": "~5.1.6",
"vue-template-compiler": "^2.7.14"
"postcss": "^8.4.31",
"prettier": "^3.0.3",
"tailwindcss": "^3.3.5",
"typescript": "~5.2.2",
"vue-template-compiler": "^2.7.15"
}
}
50 changes: 20 additions & 30 deletions examples/vue-example/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ import { EthereumSigningProvider as EthMpcPrivKeyProvider } from "@web3auth-mpc/
import * as bs58 from "bs58";
import { generatePrivate } from "@toruslabs/eccrypto";
import { defineComponent } from "vue";
import BN from "bn.js"
import { Client, utils as tssUtils } from "@toruslabs/tss-client";
import BN from "bn.js";
import { Client, getDKLSCoeff, setupSockets } from "@toruslabs/tss-client";
import { TORUS_SAPPHIRE_NETWORK_TYPE } from "@toruslabs/constants";
import * as ethWeb3 from "./lib/ethWeb3";
Expand Down Expand Up @@ -161,12 +161,12 @@ export default defineComponent({
login_hint: "",
isWhiteLabelEnabled: false,
UX_MODE: UX_MODE,
selectedUxMode: UX_MODE.REDIRECT as UX_MODE_TYPE,
selectedUxMode: UX_MODE.POPUP as UX_MODE_TYPE,
OPENLOGIN_NETWORK: OPENLOGIN_NETWORK,
BUILD_ENV: BUILD_ENV,
selectedOpenloginNetwork: OPENLOGIN_NETWORK.SAPPHIRE_DEVNET as OPENLOGIN_NETWORK_TYPE,
useMpc: false,
selectedBuildEnv: BUILD_ENV.PRODUCTION,
selectedBuildEnv: BUILD_ENV.DEVELOPMENT,
emailFlowType: EMAIL_FLOW.link,
EMAIL_FLOW: EMAIL_FLOW,
};
Expand Down Expand Up @@ -218,7 +218,7 @@ export default defineComponent({
},
showEmailFlow(): boolean {
return this.selectedLoginProvider === LOGIN_PROVIDER.EMAIL_PASSWORDLESS;
}
},
},
methods: {
async login() {
Expand Down Expand Up @@ -279,7 +279,7 @@ export default defineComponent({
async setProvider(privKey: string) {
if (this.useMpc) {
const { factorKey, tssPubKey, tssShareIndex, userInfo, tssShare, tssNonce, signatures } = this.openloginInstance.state;
const { factorKey, tssPubKey, tssShareIndex, userInfo, tssShare, tssNonce, signatures } = this.openloginInstance.state;
this.ethereumPrivateKeyProvider = new EthMpcPrivKeyProvider({
config: {
chainConfig: {
Expand All @@ -296,54 +296,44 @@ export default defineComponent({
if (!tssPubKey) {
throw new Error("tssPubKey not available");
}
const vid = `${userInfo?.aggregateVerifier || userInfo?.verifier}${DELIMITERS.Delimiter1}${userInfo?.verifierId}`;
const sessionId = `${vid}${DELIMITERS.Delimiter2}default${DELIMITERS.Delimiter3}${tssNonce}${DELIMITERS.Delimiter4}`;
const sign = async (msgHash: Buffer) => {
const parties = 4;
const clientIndex = parties - 1;
const tss = await import("@toruslabs/tss-lib");
// 1. setup
// generate endpoints for servers
const tssNodeEndpoints = getTSSEndpoints(this.selectedOpenloginNetwork as TORUS_SAPPHIRE_NETWORK_TYPE)
const tssNodeEndpoints = getTSSEndpoints(this.selectedOpenloginNetwork as TORUS_SAPPHIRE_NETWORK_TYPE);
const { endpoints, tssWSEndpoints, partyIndexes } = generateTSSEndpoints(tssNodeEndpoints, parties, clientIndex);
const randomSessionNonce = Buffer.from(keccak256(Buffer.from(generatePrivate().toString("hex") + Date.now(), "utf8"))).toString("hex");
const tssImportUrl = `${tssNodeEndpoints[0]}/v1/clientWasm`;
// session is needed for authentication to the web3auth infrastructure holding the factor 1
const currentSession = `${sessionId}${randomSessionNonce}`;
// setup mock shares, sockets and tss wasm files.
const [sockets] = await Promise.all([tssUtils.setupSockets(tssWSEndpoints, randomSessionNonce), tss.default(tssImportUrl)]);
const [sockets] = await Promise.all([setupSockets(tssWSEndpoints, randomSessionNonce), tss.default(tssImportUrl)]);
const participatingServerDKGIndexes = [1, 2, 3];
const dklsCoeff = tssUtils.getDKLSCoeff(true, participatingServerDKGIndexes, tssShareIndex as number);
const denormalisedShare = dklsCoeff.mul(new BN((tssShare as string), "hex")).umod(CURVE.curve.n);
const dklsCoeff = getDKLSCoeff(true, participatingServerDKGIndexes, tssShareIndex as number);
const denormalisedShare = dklsCoeff.mul(new BN(tssShare as string, "hex")).umod(CURVE.curve.n);
const share = Buffer.from(denormalisedShare.toString(16, 64), "hex").toString("base64");
if (!currentSession) {
throw new Error(`sessionAuth does not exist ${currentSession}`);
}
if (!signatures) {
throw new Error(`Signature does not exist ${signatures}`);
}
const client = new Client(
currentSession,
clientIndex,
partyIndexes,
endpoints,
sockets,
share,
tssPubKey,
true,
tssImportUrl
);
const client = new Client(currentSession, clientIndex, partyIndexes, endpoints, sockets, share, tssPubKey, true, tssImportUrl);
const serverCoeffs: Record<number, string> = {};
for (let i = 0; i < participatingServerDKGIndexes.length; i++) {
const serverIndex = participatingServerDKGIndexes[i];
serverCoeffs[serverIndex] = tssUtils.getDKLSCoeff(false, participatingServerDKGIndexes, tssShareIndex as number, serverIndex).toString("hex");
serverCoeffs[serverIndex] = getDKLSCoeff(false, participatingServerDKGIndexes, tssShareIndex as number, serverIndex).toString("hex");
}
client.precompute(tss, { signatures, server_coeffs: serverCoeffs });
await client.ready();
Expand All @@ -354,7 +344,7 @@ export default defineComponent({
await client.cleanup(tss, { signatures, server_coeffs: serverCoeffs });
return { v: recoveryParam, r: r.toArrayLike(Buffer, "be", 64), s: s.toArrayLike(Buffer, "be", 64) };
};
const getPublic: () => Promise<Buffer> = async () => {
return Buffer.from(tssPubKey, "base64");
};
Expand Down
Loading

0 comments on commit 849d531

Please sign in to comment.