diff --git a/packages/constants/src/constants.ts b/packages/constants/src/constants.ts index 5a98924..1924fae 100644 --- a/packages/constants/src/constants.ts +++ b/packages/constants/src/constants.ts @@ -91,3 +91,9 @@ export const KEY_TYPE = { SECP256K1: "secp256k1", ED25519: "ed25519", } as const; + +export const SIG_TYPE = { + ECDSA_SECP256K1: "ecdsa-secp256k1", + ED25519: "ed25519", + BIP340: "bip340", +} as const; diff --git a/packages/constants/src/interfaces.ts b/packages/constants/src/interfaces.ts index 2682e20..6938dbc 100644 --- a/packages/constants/src/interfaces.ts +++ b/packages/constants/src/interfaces.ts @@ -1,4 +1,4 @@ -import { KEY_TYPE, TORUS_LEGACY_NETWORK, TORUS_SAPPHIRE_NETWORK } from "./constants"; +import { KEY_TYPE, SIG_TYPE, TORUS_LEGACY_NETWORK, TORUS_SAPPHIRE_NETWORK } from "./constants"; export interface JRPCResponse { id: number; @@ -35,6 +35,8 @@ export type TORUS_NETWORK_TYPE = TORUS_LEGACY_NETWORK_TYPE | TORUS_SAPPHIRE_NETW export type WEB3AUTH_KEY_TYPE = (typeof KEY_TYPE)[keyof typeof KEY_TYPE]; +export type WEB3AUTH_SIG_TYPE = (typeof SIG_TYPE)[keyof typeof SIG_TYPE]; + export type NODE = { address: string; node_index: string; diff --git a/packages/fnd-base/src/endpoints.ts b/packages/fnd-base/src/endpoints.ts index c0be9b2..cfad6a3 100644 --- a/packages/fnd-base/src/endpoints.ts +++ b/packages/fnd-base/src/endpoints.ts @@ -1,10 +1,12 @@ import { KEY_TYPE, LEGACY_NETWORKS_ROUTE_MAP, + SIG_TYPE, TORUS_LEGACY_NETWORK_TYPE, TORUS_SAPPHIRE_NETWORK, TORUS_SAPPHIRE_NETWORK_TYPE, WEB3AUTH_KEY_TYPE, + WEB3AUTH_SIG_TYPE, } from "@toruslabs/constants"; export const SAPPHIRE_NETWORK_URLS: Record = { @@ -56,14 +58,42 @@ export const getRSSEndpoints = (sapphireNetwork: TORUS_SAPPHIRE_NETWORK_TYPE, le export const getTSSEndpoints = ( sapphireNetwork: TORUS_SAPPHIRE_NETWORK_TYPE, legacyNetwork?: TORUS_LEGACY_NETWORK_TYPE, - keyType = KEY_TYPE.SECP256K1 as WEB3AUTH_KEY_TYPE + keyType = KEY_TYPE.SECP256K1 as WEB3AUTH_KEY_TYPE, + sigType?: WEB3AUTH_SIG_TYPE ) => { const endpoints = SAPPHIRE_NETWORK_URLS[sapphireNetwork]; if (!endpoints || endpoints.length === 0) { throw new Error(`Unsupported network: ${sapphireNetwork}`); } - const tssPath = keyType === KEY_TYPE.ED25519 ? "tss-frost" : "tss"; + const tssPath = (() => { + const dklsPath = "tss"; + const frostPath = "tss-frost"; + if (sigType) { + if (sigType === SIG_TYPE.ECDSA_SECP256K1) { + if (keyType !== KEY_TYPE.SECP256K1) { + throw new Error("Invalid key type for ecdsa-secp256k1"); + } + return dklsPath; + } else if (sigType === SIG_TYPE.ED25519) { + if (keyType !== KEY_TYPE.ED25519) { + throw new Error("Invalid key type for eddsa"); + } + return frostPath; + } else if (sigType === SIG_TYPE.BIP340) { + if (keyType !== KEY_TYPE.SECP256K1) { + throw new Error("Invalid key type for bip340"); + } + return dklsPath; + } + throw new Error("Invalid sig type"); + } else if (keyType === KEY_TYPE.SECP256K1) { + return dklsPath; + } else if (keyType === KEY_TYPE.ED25519) { + return frostPath; + } + })(); + const routeIdentifier = LEGACY_NETWORKS_ROUTE_MAP[legacyNetwork as TORUS_LEGACY_NETWORK_TYPE]; return endpoints.map((e) => { if (routeIdentifier && routeIdentifier.networkIdentifier) { diff --git a/packages/fnd-base/src/sapphireNetworkConfig.ts b/packages/fnd-base/src/sapphireNetworkConfig.ts index 31dafbb..89108c9 100644 --- a/packages/fnd-base/src/sapphireNetworkConfig.ts +++ b/packages/fnd-base/src/sapphireNetworkConfig.ts @@ -1,4 +1,4 @@ -import { INodeDetails, TORUS_LEGACY_NETWORK_TYPE, TORUS_SAPPHIRE_NETWORK_TYPE, WEB3AUTH_KEY_TYPE } from "@toruslabs/constants"; +import { INodeDetails, TORUS_LEGACY_NETWORK_TYPE, TORUS_SAPPHIRE_NETWORK_TYPE, WEB3AUTH_KEY_TYPE, WEB3AUTH_SIG_TYPE } from "@toruslabs/constants"; import { getRSSEndpoints, getSSSEndpoints, getTSSEndpoints } from "./endpoints"; import { SAPPHIRE_NODE_PUB_KEYS } from "./pubKeys"; @@ -6,7 +6,8 @@ import { SAPPHIRE_NODE_PUB_KEYS } from "./pubKeys"; export const getSapphireNodeDetails = ( sapphireNetwork: TORUS_SAPPHIRE_NETWORK_TYPE, legacyNetwork?: TORUS_LEGACY_NETWORK_TYPE, - keyType?: WEB3AUTH_KEY_TYPE + keyType?: WEB3AUTH_KEY_TYPE, + sigType?: WEB3AUTH_SIG_TYPE ): INodeDetails => { return { currentEpoch: "1", @@ -17,7 +18,7 @@ export const getSapphireNodeDetails = ( torusNodeRSSEndpoints: getRSSEndpoints(sapphireNetwork, legacyNetwork), - torusNodeTSSEndpoints: getTSSEndpoints(sapphireNetwork, legacyNetwork, keyType), + torusNodeTSSEndpoints: getTSSEndpoints(sapphireNetwork, legacyNetwork, keyType, sigType), torusIndexes: [1, 2, 3, 4, 5], torusNodePub: SAPPHIRE_NODE_PUB_KEYS[sapphireNetwork], diff --git a/packages/fnd-base/src/utils.ts b/packages/fnd-base/src/utils.ts index ff92888..a72b729 100644 --- a/packages/fnd-base/src/utils.ts +++ b/packages/fnd-base/src/utils.ts @@ -7,13 +7,14 @@ import { TORUS_SAPPHIRE_NETWORK, TORUS_SAPPHIRE_NETWORK_TYPE, WEB3AUTH_KEY_TYPE, + WEB3AUTH_SIG_TYPE, } from "@toruslabs/constants"; import { getSapphireNodeDetails } from "./sapphireNetworkConfig"; -export function fetchLocalConfig(network: TORUS_NETWORK_TYPE, keyType: WEB3AUTH_KEY_TYPE): INodeDetails | undefined { +export function fetchLocalConfig(network: TORUS_NETWORK_TYPE, keyType: WEB3AUTH_KEY_TYPE, sigType?: WEB3AUTH_SIG_TYPE): INodeDetails | undefined { if (Object.values(TORUS_SAPPHIRE_NETWORK).includes(network as TORUS_SAPPHIRE_NETWORK_TYPE)) { - return getSapphireNodeDetails(network as TORUS_SAPPHIRE_NETWORK_TYPE, undefined, keyType); + return getSapphireNodeDetails(network as TORUS_SAPPHIRE_NETWORK_TYPE, undefined, keyType, sigType); } if (Object.values(TORUS_LEGACY_NETWORK).includes(network as TORUS_LEGACY_NETWORK_TYPE)) {