Skip to content

Conversation

@mohd-kashif
Copy link
Contributor

TICKET: WIN-7770

@mohd-kashif mohd-kashif self-assigned this Nov 12, 2025

/** @inheritdoc */
validateKey({ key }: BaseKey): void {
if (!new KeyPair({ prv: key })) {

Check warning

Code scanning / CodeQL

Useless conditional Warning

This negation always evaluates to false.

Copilot Autofix

AI 3 days ago

To fix the problem, we must ensure that validateKey meaningfully checks whether the provided key is valid. If the KeyPair constructor throws for an invalid key, then simply instantiating it suffices (no conditional or negation required); any error thrown will propagate or can be caught for custom error messages. If an additional method (like .isValid() or similar) must be called to check validity, we should use that in the conditional.

The best fix (without changing existing interface or behavior and with minimal assumptions) is to remove the useless conditional and instead instantiate KeyPair for its validation side-effects (i.e., for any validation performed in the constructor). If the constructor does not throw but exposes a method for checking validity, use that. Since we're restricted to given code, the first approach will be to remove the conditional and just try to instantiate, catching errors if needed for error context.

Edit only the code shown: remove the conditional and unnecessary negation in validateKey, so that the function only creates KeyPair({prv: key }). Optionally, wrap it with a try-catch to provide a custom error if the constructor throws.


Suggested changeset 1
modules/sdk-coin-flrp/src/lib/atomicTransactionBuilder.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/modules/sdk-coin-flrp/src/lib/atomicTransactionBuilder.ts b/modules/sdk-coin-flrp/src/lib/atomicTransactionBuilder.ts
--- a/modules/sdk-coin-flrp/src/lib/atomicTransactionBuilder.ts
+++ b/modules/sdk-coin-flrp/src/lib/atomicTransactionBuilder.ts
@@ -435,7 +435,9 @@
 
   /** @inheritdoc */
   validateKey({ key }: BaseKey): void {
-    if (!new KeyPair({ prv: key })) {
+    try {
+      new KeyPair({ prv: key });
+    } catch (e) {
       throw new BuildTransactionError('Invalid key');
     }
   }
EOF
@@ -435,7 +435,9 @@

/** @inheritdoc */
validateKey({ key }: BaseKey): void {
if (!new KeyPair({ prv: key })) {
try {
new KeyPair({ prv: key });
} catch (e) {
throw new BuildTransactionError('Invalid key');
}
}
Copilot is powered by AI and may make mistakes. Always verify output.
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.

2 participants