Skip to content

Commit

Permalink
add sig type in server and fnd package
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshuchawla009 committed Nov 25, 2024
1 parent 01f6978 commit 5e0dea3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/fetch-node-details/src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { TORUS_NETWORK_TYPE, WEB3AUTH_KEY_TYPE } from "@toruslabs/constants";
import { TORUS_NETWORK_TYPE, WEB3AUTH_KEY_TYPE, WEB3AUTH_SIG_TYPE } from "@toruslabs/constants";

export type NodeDetailManagerParams = {
network?: TORUS_NETWORK_TYPE;
keyType?: WEB3AUTH_KEY_TYPE;
sigType?: WEB3AUTH_SIG_TYPE;
fndServerEndpoint?: string;
enableLogging?: boolean;
};
10 changes: 8 additions & 2 deletions packages/fetch-node-details/src/nodeDetailManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import {
KEY_TYPE,
METADATA_MAP,
MULTI_CLUSTER_NETWORKS,
SIG_TYPE,
TORUS_LEGACY_NETWORK,
TORUS_LEGACY_NETWORK_TYPE,
TORUS_NETWORK_TYPE,
TORUS_SAPPHIRE_NETWORK,
WEB3AUTH_KEY_TYPE,
WEB3AUTH_SIG_TYPE,
} from "@toruslabs/constants";
import { fetchLocalConfig } from "@toruslabs/fnd-base";
import { get } from "@toruslabs/http-helpers";
Expand All @@ -26,6 +28,8 @@ class NodeDetailManager {

private _keyType: WEB3AUTH_KEY_TYPE;

private _sigType: WEB3AUTH_SIG_TYPE;

private _torusNodeEndpoints: string[] = [];

private _torusNodeRSSEndpoints: string[] = [];
Expand All @@ -45,6 +49,7 @@ class NodeDetailManager {
constructor({
network = TORUS_SAPPHIRE_NETWORK.SAPPHIRE_MAINNET,
keyType = KEY_TYPE.SECP256K1,
sigType = SIG_TYPE.ECDSA_SECP256K1,
fndServerEndpoint,
enableLogging = false,
}: NodeDetailManagerParams = {}) {
Expand All @@ -53,6 +58,7 @@ class NodeDetailManager {
}
this.network = network;
this._keyType = keyType;
this._sigType = sigType;
this.updated = false;
if (fndServerEndpoint) {
this.fndServerEndpoint = fndServerEndpoint;
Expand Down Expand Up @@ -83,7 +89,7 @@ class NodeDetailManager {

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

Expand All @@ -92,7 +98,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);
const nodeDetails = fetchLocalConfig(this.network as TORUS_NETWORK_TYPE, this._keyType, this._sigType);
if (!nodeDetails) throw new Error("Failed to fetch node details");
this.setNodeDetails(nodeDetails);
return this._nodeDetails;
Expand Down
17 changes: 14 additions & 3 deletions packages/fnd-server/src/router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { KEY_TYPE, TORUS_LEGACY_NETWORK, TORUS_NETWORK_TYPE, TORUS_SAPPHIRE_NETWORK, WEB3AUTH_KEY_TYPE } from "@toruslabs/constants";
import {
KEY_TYPE,
SIG_TYPE,
TORUS_LEGACY_NETWORK,
TORUS_NETWORK_TYPE,
TORUS_SAPPHIRE_NETWORK,
WEB3AUTH_KEY_TYPE,
WEB3AUTH_SIG_TYPE,
} from "@toruslabs/constants";
import { fetchLocalConfig } from "@toruslabs/fnd-base";
import { celebrate, Joi } from "celebrate";
import express, { Request, Response } from "express";
Expand Down Expand Up @@ -27,16 +35,19 @@ router.get(
keyType: Joi.string()
.optional()
.allow(...Object.values(KEY_TYPE)),
sigType: Joi.string()
.optional()
.allow(...Object.values(SIG_TYPE)),
}),
},
{ allowUnknown: true }
),
async (req: Request, res: Response) => {
try {
const { network, keyType = "secp256k1" } = req.query as Record<string, string>;
const { network, keyType = KEY_TYPE.SECP256K1, sigType = SIG_TYPE.ECDSA_SECP256K1 } = req.query as Record<string, string>;
const finalNetwork = network.toLowerCase();
// use static details for sapphire mainnet and testnet
const nodeDetails = fetchLocalConfig(finalNetwork as TORUS_NETWORK_TYPE, keyType as WEB3AUTH_KEY_TYPE);
const nodeDetails = fetchLocalConfig(finalNetwork as TORUS_NETWORK_TYPE, keyType as WEB3AUTH_KEY_TYPE, sigType as WEB3AUTH_SIG_TYPE);

return res.status(200).json({
nodeDetails,
Expand Down

0 comments on commit 5e0dea3

Please sign in to comment.