Skip to content
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

Feat/override keytype sigtype #110

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions packages/fetch-node-details/src/nodeDetailManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,26 @@ class NodeDetailManager {
};
}

async getNodeDetails({ verifier, verifierId }: { verifier: string; verifierId: string }): Promise<INodeDetails> {
async getNodeDetails({
verifier,
verifierId,
keyType,
sigType,
}: {
verifier: string;
verifierId: string;
keyType?: WEB3AUTH_KEY_TYPE;
sigType?: WEB3AUTH_SIG_TYPE;
}): Promise<INodeDetails> {
try {
if (this.updated && !MULTI_CLUSTER_NETWORKS.includes(this.network as TORUS_LEGACY_NETWORK_TYPE)) return this._nodeDetails;

const finalKeyType = keyType ?? this._keyType;
const finalSigType = sigType ?? this._sigType;
Copy link

@lwin-kyaw lwin-kyaw Feb 23, 2025

Choose a reason for hiding this comment

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

I think we should validate keyType and sigType before sending the request to fndServer to avoid unnecessary processing.

Even though the server performs the same validation, implementing client-side validation allows us to fail fast

Choose a reason for hiding this comment

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

I've addressed this and added the validation in the PR, #112

Choose a reason for hiding this comment

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

@ieow can I merge the PR, #112, into this?


try {
const { nodeDetails } = await get<{ nodeDetails: INodeDetails }>(
`${this.fndServerEndpoint}?network=${this.network}&verifier=${verifier}&verifierId=${verifierId}&keyType=${this._keyType}&sigType=${this._sigType}`
`${this.fndServerEndpoint}?network=${this.network}&verifier=${verifier}&verifierId=${verifierId}&keyType=${finalKeyType}&sigType=${finalSigType}`
);
this.setNodeDetails(nodeDetails);

Expand All @@ -98,7 +111,7 @@ class NodeDetailManager {
log.error("Failed to fetch node details from server, using local.", error);
}

const nodeDetails = fetchLocalConfig(this.network as TORUS_NETWORK_TYPE, this._keyType, this._sigType);
const nodeDetails = fetchLocalConfig(this.network as TORUS_NETWORK_TYPE, finalKeyType, finalSigType);
if (!nodeDetails) throw new Error("Failed to fetch node details");
this.setNodeDetails(nodeDetails);
return this._nodeDetails;
Expand Down
24 changes: 24 additions & 0 deletions packages/fetch-node-details/test/nodeDetail.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,28 @@ describe("Fetch Node Details", function () {
delete details.updated;
deepStrictEqual(details, getSapphireNodeDetails(TORUS_SAPPHIRE_NETWORK.SAPPHIRE_MAINNET));
});

it("#should use override keytype and signType if provided", async function () {
const nodeDetailManager = new NodeDetailManager({
fndServerEndpoint,
enableLogging: true,
});
const details = await nodeDetailManager.getNodeDetails({
verifier: "google",
verifierId: "[email protected]",
keyType: "ed25519",
sigType: "ed25519",
});
delete details.updated;
deepStrictEqual(details, getSapphireNodeDetails(TORUS_SAPPHIRE_NETWORK.SAPPHIRE_MAINNET, undefined, "ed25519", "ed25519"));

const details2 = await nodeDetailManager.getNodeDetails({
verifier: "google",
verifierId: "[email protected]",
keyType: "secp256k1",
sigType: "bip340",
});
delete details2.updated;
deepStrictEqual(details2, getSapphireNodeDetails(TORUS_SAPPHIRE_NETWORK.SAPPHIRE_MAINNET, undefined, "secp256k1", "bip340"));
});
});
Loading