-
Notifications
You must be signed in to change notification settings - Fork 57
Added verifySignature function in PublicAccount class #10
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
Pull Request Test Coverage Report for Build 28
💛 - Coveralls |
Vektrat
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.
hi thanks for the submission, three details I'd like to mention for now:
- I'd the "!" from the errors, we are informing users, not punishing them :)
- There are a few magic numbers related to sizes, it'd be great to use their declarations if they exist declared in some file (and otherwise declare them here for clarity), @aleixmorgadas do you know where can they be found?
- Avoid start naming variables with "_", it is usually a convention for implying no visibility on them, name it something more readable and informative if it collides with the parameter, such as "hexData" or "convertedData"
- Would it be possible to add some tests?
@aleixmorgadas should this function safe-convert from utf8? looks like a precondition thing to me
src/model/account/PublicAccount.ts
Outdated
| * | ||
| * @return {boolean} - True if the signature is valid, false otherwise. | ||
| */ | ||
| static verifySignature(publicKey: string, data: string, signature: string): boolean { |
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.
changing publicKey: string by publicAccount: PublicAccount will remove the next code,
if (publicKey.length !== 64 && publicKey.length !== 66) {
throw new Error('Not a valid public key');
}making the design safer.
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.
signature has some constrains too, I'm thinking in create a class to represent the signature and add there the invariants. It should remove the:
if (signature.length !== 128) {
throw new Error('Signature length is incorrect !');
}
// ...
const _signature = convert.hexToUint8(signature);Also, it hasn't been checked that the signature is an hexadecimal string.
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.
Also, it hasn't been checked that the signature is an hexadecimal string
well, this "if condition" below made sure that the signature must be hexadecimal
if (convert.isHexString(signature)) {
throw new Error('Signature must be hexadecimal only');
}
|
halo @Vektrat, thank you for the input. regarding the test, I will consider it later after I finish this first, because I have another important stuff to do. @aleixmorgadas so what is the next step? should I add some change base on @Vektrat and your input and create another pull request? |
Take the input from @Vektrat, and commit to your branch, this PR will be updated automatically, so we will be able to see the latest changes. |
1. change publicKey parameter to publicAccount 2. omit "_" from variable names 3. remove "!" from error messages
|
@aleixmorgadas I have pushed a new commit, please review it. I changed publicKey to publicAccount but it's a little bit weird because the function it self is inside PublicAccount class. I think we should move the function to an utility class. |
|
The next step should be adding the tests. They should guide the usage and then we find out if it has to belong to another class or not. |
|
@aleixmorgadas I added some test |
No description provided.