Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more grindKey logging #1894

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/x-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@ethersproject/wallet": "^5.7.0",
"@imtbl/config": "0.0.0",
"@imtbl/generated-clients": "0.0.0",
"@imtbl/metrics": "0.0.0",
"axios": "^1.6.5",
"bn.js": "^5.2.1",
"elliptic": "^6.5.4",
Expand Down
11 changes: 11 additions & 0 deletions packages/x-client/src/utils/stark/starkCurve.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable spaced-comment */
import { track } from '@imtbl/metrics';
import { Signer } from '@ethersproject/abstract-signer';
import { splitSignature } from '@ethersproject/bytes';
import hash from 'hash.js';
Expand Down Expand Up @@ -191,11 +192,17 @@ async function getKeyFromPath(
if (!checkIfHashedKeyIsAboveLimit(privateKeySeed)) {
return starkPrivateKey;
}
// eslint-disable-next-line no-else-return
console.log('checkIfHashedKeyIsAboveLimit', true);
track('starkCurve', 'checkIfHashedKeyIsAboveLimit', { checkIfHashedKeyIsAboveLimit: true });

// Check if the generated stark public key matches with the existing account value for that user.
// We are only validating for Production environment.
// For Sandbox account/key mismatch, solution is to discard the old account and create a new one.
const imxResponse = await getStarkPublicKeyFromImx(ethAddress);
// eslint-disable-next-line no-console
console.log('imxResponse', imxResponse);
track('starkCurve', 'getStarkPublicKeyFromImx', { imxResponse: JSON.stringify(imxResponse) });
// If the account is not found or account matches we just return the key pair at the end of this method.
// Only need to so alternative method if the account is found but the stark public key does not match.

Expand Down Expand Up @@ -234,6 +241,8 @@ async function getKeyFromPath(
starkPrivateKeyV201Compatible,
).getAddress();

track('starkCurve', 'grindKeyV201', { starkPublicKey });

if (
registeredStarkPublicKeyBN.eq(
new BN(encUtils.removeHexPrefix(starkPublicKey), 16),
Expand All @@ -249,6 +258,8 @@ async function getKeyFromPath(
const starkPrivateKeyLegacy = legacy.grindKey(privateKeyString);
starkPublicKey = await createStarkSigner(starkPrivateKeyLegacy).getAddress();

track('starkCurve', 'legacy.grindKey', { starkPublicKey });

if (
registeredStarkPublicKeyBN.eq(
new BN(encUtils.removeHexPrefix(starkPublicKey), 16),
Expand Down
Loading