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

ed25519 keys support and import keys new flow #126

Merged
merged 26 commits into from
Mar 20, 2024

Conversation

himanshuchawla009
Copy link
Member

@himanshuchawla009 himanshuchawla009 commented Dec 12, 2023

Copy link
Member

@matthiasgeihs matthiasgeihs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From ed25519 standpoint, looks mostly good to me. Can't comment much on whether flows are correct beyond that, but generally looks good.
Left some minor comments.
Some general comments:

  • Tests could be made more modular. Currently, a lot of code is duplicated between secp and ed tests, if I see that correctly.
  • Tests are currently failing. Not sure if that's an issue with this PR, or was already an issue before.

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);
}

export function getPostboxKeyFrom1OutOf1(ecCurve: ec, privKey: string, nonce: string): string {
export function getPostboxKeyFrom1OutOf1(ecCurve: EC, privKey: string, nonce: string): string {
const privKeyBN = new BN(privKey, 16);
const nonceBN = new BN(nonce, 16);
return privKeyBN.sub(nonceBN).umod(ecCurve.curve.n).toString("hex");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some users / libraries may expect the hex to be 32 bytes long (64 characters). ideally should use a global function to encode to bytes / hex, so that we don't have to do and check this manually every time. (even better might be to create a package that can be used across libraries.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will address these suggestions to make test cases modular in other PRs, thanks for suggesting these improvement

@matthiasgeihs matthiasgeihs self-requested a review January 2, 2024 11:47
Copy link
Member

@matthiasgeihs matthiasgeihs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double checked the usage of generatePrivate from @toruslabs/eccrypto (only used with encrypt/decrypt) vs the new curve-parameterized generatePrivateKey (used everywhere else). looks good now!

address: key.address,
};
});
const finalKey = result.keys[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we using only the first key?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there are cases where it is possible that a user can have multiple keys but all the nodes might not have all those shares/pub keys for ex i have seen these cases when a node is temp down but key was assigned successfully by other threshold number of nodes.

and as a result we should only check threshold for first key rather than checking older keys which are not even being used on frontend and can have mismatch in threshold when some nodes have more keys assigned for a user than others.

@himanshuchawla009 himanshuchawla009 changed the base branch from master to alpha March 20, 2024 03:45
@himanshuchawla009 himanshuchawla009 marked this pull request as ready for review March 20, 2024 06:02
@himanshuchawla009 himanshuchawla009 merged commit 60824d3 into alpha Mar 20, 2024
1 check passed
@himanshuchawla009 himanshuchawla009 deleted the fix/ed25519-keys branch March 20, 2024 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants