Skip to content

Commit

Permalink
fix: comment
Browse files Browse the repository at this point in the history
redundance function
  • Loading branch information
ieow committed Feb 25, 2025
1 parent e1431dc commit 270a36c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 27 deletions.
11 changes: 7 additions & 4 deletions src/helpers/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ export const generatePrivateKey = (ecCurve: EC, buf: typeof Buffer): Buffer => {
return ecCurve.genKeyPair().getPrivate().toArrayLike(buf);
};

const secp256k1EC = new EC("secp256k1");
const ed25519EC = new EC("ed25519");

export const getKeyCurve = (keyType: KeyType) => {
if (keyType === KEY_TYPE.ED25519) {
return new EC(KEY_TYPE.ED25519);
} else if (keyType === KEY_TYPE.SECP256K1) {
return new EC(KEY_TYPE.SECP256K1);
if (keyType === KEY_TYPE.SECP256K1) {
return secp256k1EC;
} else if (keyType === KEY_TYPE.ED25519) {
return ed25519EC;
}
throw new Error(`Invalid keyType: ${keyType}`);
};
Expand Down
20 changes: 0 additions & 20 deletions src/helpers/keyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,6 @@ import { encParamsBufToHex, generatePrivateKey, getKeyCurve, keccak256 } from ".
import { generateRandomPolynomial } from "./langrangeInterpolatePoly";
import { generateNonceMetadataParams, getSecpKeyFromEd25519 } from "./metadataUtils";

const secp256k1EC = new EC("secp256k1");
const ed25519EC = new EC("ed25519");

/**
* Returns the correct elliptic curve for the given keyType.
*
* @param keyType - The key type to get the curve for.
* @throws \{Error\} If the keyType is not valid.
* @returns \{EC\} The elliptic curve.
*
*/
export const getEcCurve = (keyType: KeyType): EC => {
if (keyType === KEY_TYPE.SECP256K1) {
return secp256k1EC;
} else if (keyType === KEY_TYPE.ED25519) {
return ed25519EC;
}
throw new Error(`Invalid keyType: ${keyType}`);
};

export function stripHexPrefix(str: string): string {
return str.startsWith("0x") ? str.slice(2) : str;
}
Expand Down
6 changes: 3 additions & 3 deletions src/torus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
encodeEd25519Point,
generateAddressFromPubKey,
generateShares,
getEcCurve,
getEd25519ExtendedPublicKey,
getKeyCurve,
getMetadata,
getOrSetNonce,
GetOrSetNonceError,
Expand Down Expand Up @@ -269,7 +269,7 @@ class Torus {
enableOneKey: boolean
): Promise<TorusPublicKey> {
const localKeyType = keyType ?? this.keyType;
const localEc = getEcCurve(localKeyType);
const localEc = getKeyCurve(localKeyType);

const keyAssignResult = await GetPubKeyOrKeyAssign({
endpoints,
Expand Down Expand Up @@ -375,7 +375,7 @@ class Torus {
}): Promise<TorusPublicKey> {
const { finalKeyResult, enableOneKey, isNewKey, serverTimeOffset, keyType } = params;
const localKeyType = keyType ?? this.keyType;
const localEc = getEcCurve(localKeyType);
const localEc = getKeyCurve(localKeyType);

const { pub_key_X: X, pub_key_Y: Y } = finalKeyResult.keys[0];
let nonceResult: GetOrSetNonceResult;
Expand Down

0 comments on commit 270a36c

Please sign in to comment.