-
Notifications
You must be signed in to change notification settings - Fork 13
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
Conversation
himanshuchawla009
commented
Dec 12, 2023
•
edited
Loading
edited
- Added support for import keys using 2pc approach, please refer to this discord thread to know how it works in backend.
- https://discord.com/channels/514301842281463818/1148500225246375987
- Added support for ed25519 keys.
…stead of calling to all endpoints
…o corresponding nodes using node indexes
There was a problem hiding this 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
anded
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"); |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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
There was a problem hiding this 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!
src/helpers/common.ts
Outdated
address: key.address, | ||
}; | ||
}); | ||
const finalKey = result.keys[0]; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
0deee17
to
12fb612
Compare