Skip to content
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

Add guard check for signing algorithm #2278

Merged
merged 7 commits into from
May 16, 2023
Merged

Add guard check for signing algorithm #2278

merged 7 commits into from
May 16, 2023

Conversation

wojake
Copy link
Contributor

@wojake wojake commented Apr 20, 2023

High Level Overview of Change

Context of Change

You could put in a random string and it'll still work, we should be able to tell that the function generated a seed according to the right algorithm. Feel free to make changes to this PR since I have no clue if this works.

Type of Change

  • 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)
  • Refactor (non-breaking change that only restructures code)
  • Tests (You added tests for code that already exists, or your new feature included in this PR)
  • Documentation Updates
  • Release

Before / After

Test Plan

@justinr1234 justinr1234 requested a review from khancode April 20, 2023 15:56
Copy link
Collaborator

@khancode khancode left a comment

Choose a reason for hiding this comment

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

Can you write unit tests for this and also change it to the correct value ecdsa-secp256k1

packages/xrpl/src/Wallet/index.ts Outdated Show resolved Hide resolved
@ckniffen
Copy link
Collaborator

Can you add a test where you pass the wrong value and check that it throws an exception?

@mvadari
Copy link
Collaborator

mvadari commented Apr 20, 2023

Please update the changelog.

@justinr1234 justinr1234 requested a review from mvadari April 24, 2023 19:34
it('generates a new wallet using an invalid/unknown algorithm', function () {
const algorithm = "test"

assert.throws(() => { Wallet.generate(algorithm) }, /Invalid cryptographic signing algorithm/)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You'll need to ignore the TypeScript check here for tests to pass

it('generates a new wallet using an invalid/unknown algorithm', function () {
const algorithm = "test"

assert.throws(() => { Wallet.generate(algorithm) }, /Invalid cryptographic signing algorithm/)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need to add //@ts-expect-error. This will allow the test to compile even though the type is wrong to simulate how it might work if using js.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or just cast it via as unknown as ExpectedType

@intelliot
Copy link
Collaborator

note: awaiting response from @wojake

ckniffen added 3 commits May 8, 2023 18:36
Added `//@ts-expect-error` to allow a test to check a bad parameter.
@ckniffen ckniffen merged commit 6b1ac0b into XRPLF:main May 16, 2023
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.

7 participants