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

fix sn to int parsing to use base 16 #216

Merged
merged 3 commits into from
Feb 14, 2024

Conversation

lenkan
Copy link
Collaborator

@lenkan lenkan commented Feb 14, 2024

The sequence number is expected to be a hex string without the preceeding 0x. So for example sequence number 10 is simply a. This causes issues with previous implementation because Number("a") => NaN this fixes the issue by specifying the base when parsing.

Another potential fix could have been to add a 0x prefix server side... But that probably has more implications that I am not aware of.

It would be good to add some unit tests that verifies the behaviour with a sequence number > 10.

There is a related issue where I wrote about this a few months ago: #138. Though I think the issue is broader than this particular fix. I simply searched the codebase for usage of the Number constructor and replaced them where it looked like it needed replacing.

Copy link

codecov bot commented Feb 14, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (cedee3a) 82.86% compared to head (9bae76d) 82.85%.

Files Patch % Lines
src/keri/core/number.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff               @@
##           development     #216      +/-   ##
===============================================
- Coverage        82.86%   82.85%   -0.01%     
===============================================
  Files               47       47              
  Lines             4190     4189       -1     
  Branches          1044     1043       -1     
===============================================
- Hits              3472     3471       -1     
  Misses             689      689              
  Partials            29       29              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kentbull
Copy link
Contributor

I'm thinking this Number(sn) call likely also needs to be using parseInt(sn, 16).

@@ -40,7 +40,7 @@ export class CesrNumber extends Matter {
// make huge version of code
code = code = NumDex.Huge;
} else {
throw new Error('Invalid num = {num}, too large to encode.');
throw new Error(`Invalid num = ${num}, too large to encode.`);
Copy link
Member

Choose a reason for hiding this comment

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

Good catch!

Copy link
Member

@pfeairheller pfeairheller left a comment

Choose a reason for hiding this comment

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

Thanks for the new tests

@pfeairheller pfeairheller merged commit aadfce0 into WebOfTrust:development Feb 14, 2024
8 checks passed
@lenkan lenkan deleted the fix-int-parsing branch April 13, 2024 08:55
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.

3 participants