Skip to content

Conversation

@ieow
Copy link
Contributor

@ieow ieow commented Feb 10, 2025

integrate multicurve tkey
tests passed

Motivation and Context

Jira Link:

Description

How has this been tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project. (run lint)
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My code requires a db migration.

@ieow ieow changed the title feat: initial commit feat: multi curve support Feb 10, 2025
fix tests
add multicurve tests
@ieow ieow marked this pull request as ready for review February 12, 2025 02:45
@matthiasgeihs matthiasgeihs self-requested a review February 25, 2025 17:45
Comment on lines +50 to +54
"@tkey/common-types": "file:../tkey/packages/common-types",
"@tkey/core": "file:../tkey/packages/core/tkey-core-15.2.1-alpha.0.tgz",
"@tkey/share-serialization": "^15.1.0",
"@tkey/storage-layer-torus": "^15.1.0",
"@tkey/tss": "^15.1.0",
"@tkey/storage-layer-torus": "file:../tkey/packages/storage-layer-torus/tkey-storage-layer-torus-15.2.1-alpha.0.tgz",
"@tkey/tss": "file:../tkey/packages/tss/tkey-tss-15.2.1-alpha.0.tgz",
Copy link
Contributor

Choose a reason for hiding this comment

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

fix this

"@toruslabs/openlogin-utils": "^8.2.1",
"@toruslabs/torus.js": "15.2.0-alpha.0",
"@toruslabs/session-manager": "^3.1.0",
"@toruslabs/torus.js": "file:../torus.js/toruslabs-torus.js-15.1.1.tgz",
Copy link
Contributor

Choose a reason for hiding this comment

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

fix

Comment on lines +73 to +74
// console.log(coreKitInstance.tKey.metadata)
// console.log(coreKitInstance.state);
Copy link
Contributor

Choose a reason for hiding this comment

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

remove

@matthiasgeihs matthiasgeihs self-requested a review February 25, 2025 17:48
Copy link
Contributor

@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.

as mentioned in the other PR, I think it would be better to merge the refactors into this one here, before we do further reviews.

also, i think it would be great to have an intro session with @ieow and the reviewers to get an overview of the changes, since all changes together make for a relatively large PR.

Comment on lines +341 to +347
/**
* @defaultValue `false`
* Set this flag to true to use the legacy flag for signing
* legacy flag do not support multicurve mode
* legacy ed25519 customAuth is only supported in legacy mode
* Note: This option is set to false by default.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/**
* @defaultValue `false`
* Set this flag to true to use the legacy flag for signing
* legacy flag do not support multicurve mode
* legacy ed25519 customAuth is only supported in legacy mode
* Note: This option is set to false by default.
*/
/**
* @defaultValue `false`
* Set this flag to true to use the legacy mode.
* Legacy mode does not support multi-curve.
* CustomAuth with key type ed25519 is only supported in legacy mode.
* Note: This option is set to false by default.
*/

I like that this has a comment, but it's a bit raw. could add some punctuation and revise language.

Comment on lines +243 to +247
public setTkeyType(tkeyType: KeyType) {
// check tkeyType is supported by tssLib
if (!this.supportedCurveKeyTypes.has(tkeyType)) throw CoreError.default("KeyType not supported, please provide valid tssLib");
this._keyType = tkeyType;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need this. Key type can be derived from sig type.

}
): Promise<Buffer> {
this.wasmLib = await this.loadTssWasm();
// this.wasmLib = await this.loadTssWasm();
Copy link
Contributor

Choose a reason for hiding this comment

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

remove

const tkeyDetails = this.tKey.getKeyDetails();
const tssPubKey = this.state.tssPubKey ? Point.fromSEC1(this.tkey.tssCurve, this.state.tssPubKey.toString("hex")) : undefined;
const tssCurve = getKeyCurve(this.keyType);
// TODO: fix me, should remove tssPubKey from state
Copy link
Contributor

Choose a reason for hiding this comment

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

address and remove

Comment on lines +1176 to +1186
// private async importTssKey(tssKey: string, factorPub: Point, newTSSIndex: TssShareType = TssShareType.DEVICE): Promise<void> {
// if (!this.state.signatures) {
// throw CoreKitError.signaturesNotPresent("Signatures not present in state when importing tss key.");
// }

await this.tKey.importTssKey(
{ tag: this.tKey.tssTag, importKey: Buffer.from(tssKey, "hex"), factorPub, newTSSIndex },
{ authSignatures: this.state.signatures }
);
}
// const keyType = this._keyType
// await this.tKey.importTssKey(
// { tssTag: this.tKey.tssTag, importKey: Buffer.from(tssKey, "hex"), factorPubs: [factorPub], newTSSIndexes: [newTSSIndex], tssKeyType: keyType },
// { authSignatures: this.state.signatures }
// );
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

remove?

await coreKitInstance.tKey.getTSSShare(new BN(factorkey.factorKey, "hex"), {
accountIndex,
});
await coreKitInstance.getTssShare(new BN(factorkey.factorKey, "hex") ,accountIndex);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: formatting ,accountIndex

}
});

console.log(coreKitInstance.keyType)
Copy link
Contributor

Choose a reason for hiding this comment

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

console log to be removed



const recoverFactor = await instance.enableMFA({})
console.log(recoverFactor);
Copy link
Contributor

Choose a reason for hiding this comment

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

console log to be removed

import { AsyncMemoryStorage, criticalResetAccount, mockLogin } from "./setup";
import { getKeyCurve } from "@toruslabs/torus.js";
import { randomId } from "@toruslabs/customauth";
import log from "loglevel";
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: formatting

storage?: IAsyncStorage | IStorage;
email: string;
tssLib?: TssLibType;
resetAccount? : false
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: formatting

async function beforeTest() {
if (testVariable.resetAccount === false) {
log.debug("skipping reset account");
return ;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: formatting

if (!kit.supportsAccountIndex) {
indices = indices.filter((i) => i === 0);
}
const tssCurve = getKeyCurve(kit.keyType)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: formatting ;

instance.setSigType("ed25519")
instance.setTkeyType(KeyType.ed25519)
const result3 = await instance.sign(Buffer.from(message), { hashed: false })
const valided25519 = ed25519.verify(bytesToHex(result3), bytesToHex(Buffer.from(message)), bytesToHex( new Uint8Array(instance.getPubKeyEd25519()) ) )
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: formatting

@huggingbot
Copy link
Contributor

huggingbot commented Feb 26, 2025

adding this comment to highlight the formatting issues as there are too many of them to be mentioned individually

// check tkeyType is supported by tssLib
if (!this.supportedSigTypes.has(sigType)) throw CoreError.default("SigType not supported, please provide valid tssLib");
this._sigType = sigType;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

keyType should be updated with sigType for consistency

if (this.options.legacyFlag) {
// Check for existing curve in tssData for legacy mode
const tssData = this.getTssData({ skipThrow: true });
if (!tssData) throw CoreKitError.default("Legacy mode only support single curve, please congfiure with correct keyType");
Copy link
Contributor

@huggingbot huggingbot Feb 26, 2025

Choose a reason for hiding this comment

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

shouldn't we also check for tssData's existence in non-legacy mode?

if (this.options.legacyFlag) {
// Check for existing curve in tssData for legacy mode
const tssData = this.getTssData({ skipThrow: true });
if (!tssData) throw CoreKitError.default("Legacy mode only support single curve, please congfiure with correct keyType");
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't we check for tssData's existence in non-legacy mode?

this.supportedSigTypes.add(tssLibItem.sigType as SigType);
});
this._keyType = options.tssLibs[0].keyType as KeyType;
this._sigType = options.tssLibs[0].sigType as SigType;
Copy link
Contributor

Choose a reason for hiding this comment

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

why are these only storing a single key type and sig type?

@ieow
Copy link
Contributor Author

ieow commented Feb 26, 2025

Sorry for the confusion.
It was previous decided to go with the direction of pr #217
need to close this pr

@ieow ieow closed this Feb 26, 2025
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