-
Notifications
You must be signed in to change notification settings - Fork 11
feat: multi curve support #216
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
integrate multicurve tkey tests passed
fix tests add multicurve tests
| "@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", |
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.
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", |
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.
fix
| // console.log(coreKitInstance.tKey.metadata) | ||
| // console.log(coreKitInstance.state); |
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.
remove
matthiasgeihs
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.
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.
| /** | ||
| * @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. | ||
| */ |
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.
| /** | |
| * @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.
| 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; | ||
| } |
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.
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(); |
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.
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 |
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.
address and remove
| // 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 } | ||
| // ); | ||
| // } |
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.
remove?
| await coreKitInstance.tKey.getTSSShare(new BN(factorkey.factorKey, "hex"), { | ||
| accountIndex, | ||
| }); | ||
| await coreKitInstance.getTssShare(new BN(factorkey.factorKey, "hex") ,accountIndex); |
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.
nit: formatting ,accountIndex
| } | ||
| }); | ||
|
|
||
| console.log(coreKitInstance.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.
console log to be removed
|
|
||
|
|
||
| const recoverFactor = await instance.enableMFA({}) | ||
| console.log(recoverFactor); |
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.
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"; |
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.
nit: formatting
| storage?: IAsyncStorage | IStorage; | ||
| email: string; | ||
| tssLib?: TssLibType; | ||
| resetAccount? : false |
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.
nit: formatting
| async function beforeTest() { | ||
| if (testVariable.resetAccount === false) { | ||
| log.debug("skipping reset account"); | ||
| return ; |
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.
nit: formatting
| if (!kit.supportsAccountIndex) { | ||
| indices = indices.filter((i) => i === 0); | ||
| } | ||
| const tssCurve = getKeyCurve(kit.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.
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()) ) ) |
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.
nit: formatting
|
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; | ||
| } |
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.
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"); |
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.
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"); |
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.
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; |
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 these only storing a single key type and sig type?
|
Sorry for the confusion. |
integrate multicurve tkey
tests passed
Motivation and Context
Jira Link:
Description
How has this been tested?
Screenshots (if appropriate):
Types of changes
Checklist: