Skip to content

Commit

Permalink
Merge pull request #371 from torusresearch/feat/remove-fnd-call
Browse files Browse the repository at this point in the history
Optimises fnd call if node details passed in the constructor
  • Loading branch information
himanshuchawla009 authored Oct 4, 2024
2 parents 6a34bed + 3a30ccf commit a81c023
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 30 deletions.
43 changes: 30 additions & 13 deletions examples/vue-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion examples/vue-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
"@toruslabs/broadcast-channel": "10.0.1",
"@toruslabs/constants": "^14.0.0",
"@toruslabs/customauth": "file:../../",
"@toruslabs/fnd-base": "^14.0.0",
"@toruslabs/openlogin-starkkey": "^3.2.0",
"@toruslabs/torus.js": "^15.0.2",
"@toruslabs/torus.js": "^15.1.0-0",
"@toruslabs/vue-components": "^7.8.3",
"@toruslabs/vue-icons": "^7.6.2",
"@web3auth/base": "^8.12.0",
Expand Down
15 changes: 12 additions & 3 deletions examples/vue-app/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,9 @@
</template>

<script setup lang="ts">
import { TORUS_LEGACY_NETWORK, TORUS_SAPPHIRE_NETWORK } from "@toruslabs/constants";
import { KEY_TYPE, TORUS_LEGACY_NETWORK, TORUS_SAPPHIRE_NETWORK } from "@toruslabs/constants";
import { CustomAuth, LoginWindowResponse, TorusLoginResponse, TorusVerifierResponse, UX_MODE } from "@toruslabs/customauth";
import { fetchLocalConfig } from "@toruslabs/fnd-base";
import { getStarkHDAccount, pedersen, sign, STARKNET_NETWORKS, verify } from "@toruslabs/openlogin-starkkey";
import { TorusKey } from "@toruslabs/torus.js";
import { Button, Card, Select, TextArea, TextField } from "@toruslabs/vue-components";
Expand Down Expand Up @@ -305,28 +306,36 @@ const loadResponse = (privKeyInfo: TorusKey["finalKeyData"], localUserInfo: Toru
const initCustomAuth = async () => {
const { network, uxMode } = formData.value;
switch (uxMode) {
case UX_MODE.REDIRECT:
case UX_MODE.REDIRECT: {
const nodeDetails = fetchLocalConfig(network, KEY_TYPE.SECP256K1);
customAuthSdk.value = new CustomAuth({
baseUrl: `${window.location.origin}`,
redirectPathName: "auth",
enableLogging: true,
network,
uxMode,
web3AuthClientId: WEB3AUTH_CLIENT_ID,
nodeDetails,
checkCommitment: false,
});
await customAuthSdk.value.init({ skipSw: true });
break;
case UX_MODE.POPUP:
}
case UX_MODE.POPUP: {
const nodeDetails = fetchLocalConfig(network, KEY_TYPE.SECP256K1);
customAuthSdk.value = new CustomAuth({
uxMode,
baseUrl: `${window.location.origin}/serviceworker`,
enableLogging: true,
network,
popupFeatures: `titlebar=0,toolbar=0,status=0,location=0,menubar=0,height=500,width=500,top=100,left=100`,
web3AuthClientId: WEB3AUTH_CLIENT_ID,
nodeDetails,
checkCommitment: false,
});
await customAuthSdk.value.init();
break;
}
default:
break;
}
Expand Down
18 changes: 10 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
"@toruslabs/http-helpers": "^7.0.0",
"@toruslabs/metadata-helpers": "^6.0.0",
"@toruslabs/session-manager": "^3.1.0",
"@toruslabs/torus.js": "^15.0.4",
"@toruslabs/torus.js": "^15.1.0-0",
"base64url": "^3.0.1",
"bowser": "^2.11.0",
"deepmerge": "^4.3.1",
"eventemitter3": "^5.0.1",
"loglevel": "^1.9.2"
},
"devDependencies": {
"@sentry/types": "^8.31.0",
"@sentry/types": "^8.33.1",
"@toruslabs/config": "^2.2.0",
"@toruslabs/eslint-config-typescript": "^3.3.3",
"@toruslabs/torus-scripts": "^6.1.2",
Expand Down
11 changes: 10 additions & 1 deletion src/handlers/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TORUS_NETWORK_TYPE } from "@toruslabs/constants";
import { INodeDetails, TORUS_NETWORK_TYPE } from "@toruslabs/constants";
import { KeyType, TorusKey } from "@toruslabs/torus.js";

import { Sentry } from "../sentry";
Expand Down Expand Up @@ -241,6 +241,15 @@ export interface CustomAuthArgs {
* @defaultValue undefined
*/
useDkg?: boolean;

nodeDetails?: INodeDetails;

/**
* Set this flag to false to remove check for commitment calls.
*
* @defaultValue true
*/
checkCommitment?: boolean;
}

export interface InitParams {
Expand Down
16 changes: 14 additions & 2 deletions src/login.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TORUS_NETWORK_TYPE } from "@toruslabs/constants";
import { type INodeDetails, TORUS_NETWORK_TYPE } from "@toruslabs/constants";
import { NodeDetailManager } from "@toruslabs/fetch-node-details";
import { keccak256, Torus, TorusKey } from "@toruslabs/torus.js";
import { keccak256, type KeyType, Torus, TorusKey } from "@toruslabs/torus.js";

import createHandler from "./handlers/HandlerFactory";
import {
Expand Down Expand Up @@ -41,6 +41,9 @@ class CustomAuth {
useDkg?: boolean;
web3AuthClientId: string;
web3AuthNetwork: TORUS_NETWORK_TYPE;
keyType: KeyType;
nodeDetails: INodeDetails;
checkCommitment: boolean;
};

torus: Torus;
Expand Down Expand Up @@ -69,6 +72,8 @@ class CustomAuth {
metadataUrl = "https://metadata.tor.us",
keyType = "secp256k1",
serverTimeOffset = 0,
nodeDetails,
checkCommitment = true,
}: CustomAuthArgs) {
if (!web3AuthClientId) throw new Error("Please provide a valid web3AuthClientId in constructor");
if (!network) throw new Error("Please provide a valid network in constructor");
Expand All @@ -86,6 +91,9 @@ class CustomAuth {
useDkg,
web3AuthClientId,
web3AuthNetwork: network,
keyType,
nodeDetails,
checkCommitment,
};
const torus = new Torus({
network,
Expand Down Expand Up @@ -281,6 +289,9 @@ class CustomAuth {
name: SENTRY_TXNS.FETCH_NODE_DETAILS,
},
async () => {
if (this.config.nodeDetails) {
return this.config.nodeDetails;
}
return this.nodeDetailManager.getNodeDetails({ verifier, verifierId });
}
);
Expand All @@ -303,6 +314,7 @@ class CustomAuth {
...additionalParams,
},
useDkg: this.config.useDkg,
checkCommitment: this.config.checkCommitment,
});
}
);
Expand Down

0 comments on commit a81c023

Please sign in to comment.