Merge pull request #666 from braydonf/bug/public-key-validation

PublicKey: Add test to verify that both uncompressed an compressed keys validate.
This commit is contained in:
Manuel Aráoz 2014-12-05 10:31:10 -03:00
commit 33715a994e
2 changed files with 10 additions and 5 deletions

View File

@ -248,10 +248,10 @@ PublicKey.fromX = function(odd, x) {
* @param {String} [compressed] - If the public key is compressed
* @returns {null|Error} An error if exists
*/
PublicKey.getValidationError = function(data, compressed) {
PublicKey.getValidationError = function(data) {
var error;
try {
new PublicKey(data, compressed);
new PublicKey(data);
} catch (e) {
error = e;
}
@ -266,8 +266,8 @@ PublicKey.getValidationError = function(data, compressed) {
* @param {String} [compressed] - If the public key is compressed
* @returns {Boolean} If the public key would be valid
*/
PublicKey.isValid = function(data, compressed) {
return !PublicKey.getValidationError(data, compressed);
PublicKey.isValid = function(data) {
return !PublicKey.getValidationError(data);
};
/**

View File

@ -79,11 +79,16 @@ describe('PublicKey', function() {
valid.should.equal(false);
});
it('should recieve a boolean as true', function() {
it('should recieve a boolean as true for uncompressed', function() {
var valid = PublicKey.isValid('041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341');
valid.should.equal(true);
});
it('should recieve a boolean as true for compressed', function() {
var valid = PublicKey.isValid('031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a');
valid.should.equal(true);
});
});
describe('#fromPoint', function() {