-
-
Notifications
You must be signed in to change notification settings - Fork 11
Feat/get public address keytype #170
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
Conversation
src/helpers/keyUtils.ts
Outdated
| * @returns \{EC\} The elliptic curve. | ||
| * | ||
| */ | ||
| export const getEcCurve = (keyType: KeyType): EC => { |
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.
there's a similar function getKeyCurve that already exists in src/helpers/common.ts
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.
getKeyCurve can also be optimised to be similar to getEcCurve, i.e. to use constant instances:
const secp256k1EC = new EC("secp256k1");
const ed25519EC = new EC("ed25519");based on the elliptic's docs, it's safe to initialise the EC instance once and reuse it:
// Create and initialize EC context
// (better do it once and reuse it)
var ec = new EC('secp256k1');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.
the Torus class constructor and tests should use getKeyCurve to retrieve the EC instance for consistency
// current implementation
this.ec = new EC(this.keyType);
// proposed implementation
this.ec = getEcCurve(this.keyType);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.
fixed
src/torus.ts
Outdated
| enableOneKey: boolean | ||
| ): Promise<TorusPublicKey> { | ||
| const localKeyType = keyType ?? this.keyType; | ||
| const localEc = getEcCurve(localKeyType); |
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.
before retrieving an EC instance, we should probably do this check that is similar in the constructor:
(keyType === KEY_TYPE.ED25519 && LEGACY_NETWORKS_ROUTE_MAP[network as TORUS_LEGACY_NETWORK_TYPE])otherwise, we might pass the incorrect key type into formatLegacyPublicKeyData
would be nice to bake this check into a function that can be reused here and in the constructor
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.
it could make more sense to do this check in formatLegacyPublicKeyData, or simply apply the same check wherever getEcCurve is used
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.
Not going to check for the instance's keyType
this feature is to Allow getPublicAddress to retrieve different keyType based on input params regardless of the instances's keyType
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.
Assume that this.keyType is secp256k1 and this.network is a legacy network when the Torus class is initialised.
In getPublicAddress, if keyType is passed in as ed25519, then it won't be compatible with the legacy network. We need to guard against this potential bug.
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.
Added check on prior GetPubKeyOrKeyAssign
redundance function
src/helpers/common.ts
Outdated
| }; | ||
|
|
||
| const secp256k1EC = new EC("secp256k1"); | ||
| const ed25519EC = new EC("ed25519"); |
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.
this was intentionally not left as a global variable to reduce the build size
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.
would create EC object every time increase memory usage and latency?
src/torus.ts
Outdated
| ): Promise<TorusPublicKey> { | ||
| log.info(torusNodePubs, { verifier, verifierId, extendedVerifierId }); | ||
| return this.getNewPublicAddress(endpoints, { verifier, verifierId, extendedVerifierId }, this.enableOneKey); | ||
| return this.getNewPublicAddress(endpoints, { verifier, verifierId, extendedVerifierId, keyType }, this.enableOneKey); |
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.
can we pass keyType here as const localKeyType = keyType ?? this.keyType for the sake of consistency with other public functions
| }); | ||
| }); | ||
|
|
||
| it("should should fetch public address with keyType", async function () { |
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.
can you use existing test case and user for testcase to validate nothing changes on passing keyType for existing test user
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.
Willa_Funk11@gmail.com is existing testcase's email in the sapphire_devnet_ed25519.test.ts
himanshuchawla009
left a comment
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.
lgtm
Motivation and Context
To support multicurve tss (mpc core-kit) -
Allow getPublicAddress to retrieve different keyType based on input params
Jira Link:
https://toruslabs.atlassian.net/browse/IRT-1680
Description
How has this been tested?
Screenshots (if appropriate):
Types of changes
Checklist: