-
Notifications
You must be signed in to change notification settings - Fork 11
fix: checkIfFactorKeyValid, check in factorEncs #225
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
base: fix/disableHashedFactorkey
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import assert from "node:assert"; | ||
| import test from "node:test"; | ||
|
|
||
| import { EllipticPoint, KeyType, Point, secp256k1 } from "@tkey/common-types"; | ||
| import { EllipticPoint, getPubKeyPoint, KeyType, Point, secp256k1 } from "@tkey/common-types"; | ||
| import { factorKeyCurve } from "@tkey/tss"; | ||
| import { tssLib as tssLibDKLS } from "@toruslabs/tss-dkls-lib"; | ||
| import { tssLib as tssLibFROST } from "@toruslabs/tss-frost-lib"; | ||
|
|
@@ -158,7 +158,7 @@ export const FactorManipulationTest = async (testVariable: FactorTestVariable) = | |
| }); | ||
|
|
||
| // enable mfa | ||
|
|
||
| let browserFactor: string; | ||
| await t.test("enable MFA", async function () { | ||
| const instance = await newInstance(); | ||
| assert.strictEqual(instance.status, COREKIT_STATUS.LOGGED_IN); | ||
|
|
@@ -179,7 +179,7 @@ export const FactorManipulationTest = async (testVariable: FactorTestVariable) = | |
| const instance2 = await newInstance(); | ||
| assert.strictEqual(instance2.status, COREKIT_STATUS.REQUIRED_SHARE); | ||
|
|
||
| const browserFactor = await instance2.getDeviceFactor(); | ||
| browserFactor = await instance2.getDeviceFactor(); | ||
|
|
||
| const factorBN = new BN(recoverFactor, "hex") | ||
|
|
||
|
|
@@ -210,9 +210,32 @@ export const FactorManipulationTest = async (testVariable: FactorTestVariable) = | |
| } else { | ||
| await signSecp256k1Data({ coreKitInstance: instance3, msg: "hello world" }); | ||
| } | ||
|
|
||
| }); | ||
|
|
||
| // replace factor | ||
| await t.test("replace factor", async function () { | ||
| const instance = await newInstance(); | ||
|
|
||
| const deviceFactorKeyBN = new BN(browserFactor, "hex") | ||
| await instance.inputFactorKey(deviceFactorKeyBN); | ||
| assert.strictEqual(instance.status, COREKIT_STATUS.LOGGED_IN); | ||
|
|
||
| const newFactorkey = await instance.createFactor({ shareType: TssShareType.DEVICE }); | ||
| await instance.inputFactorKey(new BN(newFactorkey, "hex")); | ||
|
|
||
| assert.strictEqual(instance.status, COREKIT_STATUS.LOGGED_IN); | ||
|
|
||
|
|
||
| const deviceFactorPub = getPubKeyPoint(deviceFactorKeyBN); | ||
| await instance.deleteFactor(deviceFactorPub, browserFactor); | ||
|
|
||
| try { | ||
| await instance.inputFactorKey(deviceFactorKeyBN); | ||
| throw Error("should not be able to deleted input factor"); | ||
| } catch (e) { | ||
| assert(e instanceof Error); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Test assertion passes even when test should failThe test's catch block uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Test fails silently when expected error not thrownThe test's error handling logic is flawed. The catch block checks |
||
| }); | ||
| }); | ||
| }; | ||
|
|
||
|
|
||
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.
Bug: Test uses wrong import and missing curve parameter
The test imports
getPubKeyPointfrom@tkey/common-typesbut all source code imports it from@tkey/tssand calls it with two arguments: the key andfactorKeyCurve. The test callgetPubKeyPoint(deviceFactorKeyBN)only passes one argument. When this Point is passed todeleteFactor, it's compared against Points created usingfactorKeyCurve. Using a different function or missing the curve parameter will cause incorrect Point comparisons, making the test unreliable. ThefactorKeyCurveis already imported in the test file but not used withgetPubKeyPoint.Additional Locations (1)
tests/factors.spec.ts#L3-L4