Skip to content

Commit

Permalink
cleanup debug logs and replace 'debug' with 'error' log levels in cat…
Browse files Browse the repository at this point in the history
…ch blocks
  • Loading branch information
lwin-kyaw committed Jan 30, 2024
1 parent c8954c9 commit 995fe18
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 18 deletions.
4 changes: 0 additions & 4 deletions src/helpers/keyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down Expand Up @@ -34,15 +32,13 @@ 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);
}

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);
}
Expand Down
9 changes: 4 additions & 5 deletions src/helpers/nodeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 1 addition & 9 deletions src/torus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -542,8 +541,6 @@ class Torus {
{ verifier, verifierId }: { verifier: string; verifierId: string },
enableOneKey: boolean
): Promise<TorusPublicKey> {
log.debug("> torus.js/getPublicAddress", { endpoints, torusNodePubs, verifier, verifierId });

let finalKeyResult: LegacyVerifierLookupResponse | undefined;
let isNewKey = false;

Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -609,7 +605,6 @@ class Torus {
{ verifier, verifierId, extendedVerifierId }: { verifier: string; verifierId: string; extendedVerifierId?: string },
enableOneKey: boolean
): Promise<TorusPublicKey> {
log.debug("> torus.js/getPublicAddress", { endpoints, verifier, verifierId });
const keyAssignResult = await GetPubKeyOrKeyAssign({
endpoints,
network: this.network,
Expand All @@ -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 || {})}`);
}
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 995fe18

Please sign in to comment.