From 995fe187d30371b4525031deb5c3b03c189ea864 Mon Sep 17 00:00:00 2001 From: Lwin Date: Tue, 30 Jan 2024 15:06:21 +0800 Subject: [PATCH] cleanup debug logs and replace 'debug' with 'error' log levels in catch blocks --- src/helpers/keyUtils.ts | 4 ---- src/helpers/nodeUtils.ts | 9 ++++----- src/torus.ts | 10 +--------- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/src/helpers/keyUtils.ts b/src/helpers/keyUtils.ts index 6807359..cfd01af 100644 --- a/src/helpers/keyUtils.ts +++ b/src/helpers/keyUtils.ts @@ -2,8 +2,6 @@ import BN from "bn.js"; import { ec } from "elliptic"; import { keccak256 as keccakHash } from "ethereum-cryptography/keccak"; -import log from "../loglevel"; - export function keccak256(a: Buffer): string { const hash = Buffer.from(keccakHash(a)).toString("hex"); return `0x${hash}`; @@ -34,7 +32,6 @@ export function toChecksumAddress(hexAddress: string): string { export function generateAddressFromPrivKey(ecCurve: ec, privateKey: BN): string { const key = ecCurve.keyFromPrivate(privateKey.toString("hex", 64), "hex"); const publicKey = key.getPublic().encode("hex", false).slice(2); - log.info(publicKey, "public key"); const evmAddressLower = `0x${keccak256(Buffer.from(publicKey, "hex")).slice(64 - 38)}`; return toChecksumAddress(evmAddressLower); } @@ -42,7 +39,6 @@ export function generateAddressFromPrivKey(ecCurve: ec, privateKey: BN): string export function generateAddressFromPubKey(ecCurve: ec, publicKeyX: BN, publicKeyY: BN): string { const key = ecCurve.keyFromPublic({ x: publicKeyX.toString("hex", 64), y: publicKeyY.toString("hex", 64) }); const publicKey = key.getPublic().encode("hex", false).slice(2); - log.info(key.getPublic().encode("hex", false), "public key"); const evmAddressLower = `0x${keccak256(Buffer.from(publicKey, "hex")).slice(64 - 38)}`; return toChecksumAddress(evmAddressLower); } diff --git a/src/helpers/nodeUtils.ts b/src/helpers/nodeUtils.ts index 1deaa17..b6534ac 100644 --- a/src/helpers/nodeUtils.ts +++ b/src/helpers/nodeUtils.ts @@ -396,7 +396,7 @@ export async function retrieveOrImportShare(params: { if (sessionTokenSigMetadata && sessionTokenSigMetadata[0]?.ephemPublicKey) { sessionTokenSigPromises.push( decryptNodeData(sessionTokenSigMetadata[0], sessionTokenSigs[0], sessionAuthKey).catch((err) => - log.debug("session sig decryption", err) + log.error("session sig decryption", err) ) ); } else { @@ -411,7 +411,7 @@ export async function retrieveOrImportShare(params: { if (sessionTokenMetadata && sessionTokenMetadata[0]?.ephemPublicKey) { sessionTokenPromises.push( decryptNodeData(sessionTokenMetadata[0], sessionTokens[0], sessionAuthKey).catch((err) => - log.debug("session token sig decryption", err) + log.error("session token sig decryption", err) ) ); } else { @@ -431,7 +431,7 @@ export async function retrieveOrImportShare(params: { latestKey.share_metadata, Buffer.from(latestKey.share, "base64").toString("binary").padStart(64, "0"), sessionAuthKey - ).catch((err) => log.debug("share decryption", err)) + ).catch((err) => log.error("share decryption", err)) ); } } else { @@ -585,7 +585,7 @@ export async function retrieveOrImportShare(params: { // deriving address from pub key coz pubkey is always available // but finalPrivKey won't be available for v2 user upgraded to 2/n const finalEvmAddress = generateAddressFromPubKey(ecCurve, finalPubKey.getX(), finalPubKey.getY()); - log.debug("> torus.js/retrieveShares", { finalEvmAddress }); + let finalPrivKey = ""; // it is empty for v2 user upgraded to 2/n if (typeOfUser === "v1" || (typeOfUser === "v2" && metadataNonce.gt(new BN(0)))) { const privateKeyWithNonce = oAuthKey.add(metadataNonce).umod(ecCurve.curve.n); @@ -672,7 +672,6 @@ export const legacyKeyAssign = async ({ if (lastPoint === undefined) { nodeNum = Math.floor(Math.random() * endpoints.length); // nodeNum = endpoints.indexOf("https://torus-node.binancex.dev/jrpc"); - log.info("keyassign", nodeNum, endpoints[nodeNum]); initialPoint = nodeNum; } else { nodeNum = lastPoint % endpoints.length; diff --git a/src/torus.ts b/src/torus.ts index 44a9156..65c9d8a 100644 --- a/src/torus.ts +++ b/src/torus.ts @@ -395,7 +395,7 @@ class Torus { decrypt(tmpKey, { ...metadata, ciphertext: Buffer.from(Buffer.from(firstKey.Share, "base64").toString("binary").padStart(64, "0"), "hex"), - }).catch((err) => log.debug("share decryption", err)) + }).catch((err) => log.error("share decryption", err)) ); } else { sharePromises.push(Promise.resolve(Buffer.from(firstKey.Share.padStart(64, "0"), "hex"))); @@ -501,7 +501,6 @@ class Torus { let finalEvmAddress = ""; if (finalPubKey) { finalEvmAddress = generateAddressFromPubKey(this.ec, finalPubKey.getX(), finalPubKey.getY()); - log.debug("> torus.js/retrieveShares", { finalEvmAddress }); } else { throw new Error("Invalid public key, this might be a bug, please report this to web3auth team"); } @@ -542,8 +541,6 @@ class Torus { { verifier, verifierId }: { verifier: string; verifierId: string }, enableOneKey: boolean ): Promise { - log.debug("> torus.js/getPublicAddress", { endpoints, torusNodePubs, verifier, verifierId }); - let finalKeyResult: LegacyVerifierLookupResponse | undefined; let isNewKey = false; @@ -573,7 +570,6 @@ class Torus { } else { throw new Error(`node results do not match at first lookup ${JSON.stringify(keyResult || {})}, ${JSON.stringify(errorResult || {})}`); } - log.debug("> torus.js/getPublicAddress", { finalKeyResult, isNewKey }); if (finalKeyResult) { return this.formatLegacyPublicKeyData({ @@ -609,7 +605,6 @@ class Torus { { verifier, verifierId, extendedVerifierId }: { verifier: string; verifierId: string; extendedVerifierId?: string }, enableOneKey: boolean ): Promise { - log.debug("> torus.js/getPublicAddress", { endpoints, verifier, verifierId }); const keyAssignResult = await GetPubKeyOrKeyAssign({ endpoints, network: this.network, @@ -628,7 +623,6 @@ class Torus { if (errorResult) { throw new Error(`node results do not match at first lookup ${JSON.stringify(keyResult || {})}, ${JSON.stringify(errorResult || {})}`); } - log.debug("> torus.js/getPublicAddress", { keyResult }); if (!keyResult?.keys) { throw new Error(`node results do not match at final lookup ${JSON.stringify(keyResult || {})}, ${JSON.stringify(errorResult || {})}`); } @@ -671,7 +665,6 @@ class Torus { const oAuthX = oAuthPubKey.getX().toString(16, 64); const oAuthY = oAuthPubKey.getY().toString(16, 64); const oAuthAddress = generateAddressFromPubKey(this.ec, oAuthPubKey.getX(), oAuthPubKey.getY()); - log.debug("> torus.js/getPublicAddress, oAuthKeyData", { X: oAuthX, Y: oAuthY, oAuthAddress, nonce: nonce?.toString(16), pubNonce }); if (!finalPubKey) { throw new Error("Unable to derive finalPubKey"); @@ -755,7 +748,6 @@ class Torus { const oAuthX = oAuthPubKey.getX().toString(16, 64); const oAuthY = oAuthPubKey.getY().toString(16, 64); const oAuthAddress = generateAddressFromPubKey(this.ec, oAuthPubKey.getX(), oAuthPubKey.getY()); - log.debug("> torus.js/getPublicAddress, oAuthKeyData", { X: oAuthX, Y: oAuthY, oAuthAddress, nonce: nonce?.toString(16), pubNonce }); if (typeOfUser === "v2" && !finalPubKey) { throw new Error("Unable to derive finalPubKey");