Skip to content

refactor: validates key type and sig type for TSS Endpoints #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: feat/override-keytype-sigtype
Choose a base branch
from

Conversation

lwin-kyaw
Copy link

@lwin-kyaw lwin-kyaw commented Feb 25, 2025

Motivation and Context

Jira Link:

Description

Note: This PR is to address the comments in the another PR, #110

Do client-side validation to quickly catch errors before sending a network request.

  • Refactor sigType and keyType validation to fetch TSS Endpoints
  • Validates sigType and keyType in NodeDetailsManager getNodeDetails method before fetching endpoints from fnd-server

How has this been tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project. (run lint)
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My code requires a db migration.

@lwin-kyaw lwin-kyaw mentioned this pull request Feb 25, 2025
9 tasks
@@ -59,41 +61,25 @@ export const getTSSEndpoints = (
sapphireNetwork: TORUS_SAPPHIRE_NETWORK_TYPE,
legacyNetwork?: TORUS_LEGACY_NETWORK_TYPE,
keyType = KEY_TYPE.SECP256K1 as WEB3AUTH_KEY_TYPE,
sigType?: WEB3AUTH_SIG_TYPE
sigType = SIG_TYPE.ECDSA_SECP256K1 as WEB3AUTH_SIG_TYPE

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the previous implementation, if sigType is not provided and keyType is provided as KEY_TYPE.ED25519, then tssPath would be tss-frost. However, in this updated code given the same scenario, tssPath would be tss instead since there is a default for sigType

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in here, a29b786

Copy link
Member

@matthiasgeihs matthiasgeihs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well done

export * from "./endpoints";
export * from "./sapphireNetworkConfig";
export * from "./utils";

export function fetchLocalConfig(network: TORUS_NETWORK_TYPE, keyType: WEB3AUTH_KEY_TYPE, sigType?: WEB3AUTH_SIG_TYPE): INodeDetails | undefined {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to move this function here from utils file?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I moved the function, fetchLocalConfig, to prevent circular import, because ~
fetchLocalConfig needs import from /endpoints and getTSSEndpoints function in /endpoints also needs to import /utils to use validation function.

@@ -100,6 +100,9 @@ class NodeDetailManager {
const finalKeyType = keyType ?? this._keyType;
const finalSigType = sigType ?? this._sigType;

// validate key type and sig type to fetch TSS endpoints
validateKeyTypeAndSigTypeForTSS(finalKeyType, finalSigType);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should do validation on server side only specifically to maintain forward compatibility specially for fnd sdk. Its a good practice to fail fast in general but in this case we want server to be source of truth to ensure older client sdks will remain compatible to future changes in endpoints. I dont know any specific reason to do that for now but its just from past experience we want this sdk to remain future compatible

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok.
But in the same method, https://github.com/torusresearch/fetch-node-details/blob/feat/key-sig-type-validation/packages/fetch-node-details/src/nodeDetailManager.ts#L117, we are also directly calling the fetchLocalConfig from fnd-base when it's failed to fetch from the server.
I think it'll still do validation on the client side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants