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:
commit
33715a994e
|
@ -248,10 +248,10 @@ PublicKey.fromX = function(odd, x) {
|
||||||
* @param {String} [compressed] - If the public key is compressed
|
* @param {String} [compressed] - If the public key is compressed
|
||||||
* @returns {null|Error} An error if exists
|
* @returns {null|Error} An error if exists
|
||||||
*/
|
*/
|
||||||
PublicKey.getValidationError = function(data, compressed) {
|
PublicKey.getValidationError = function(data) {
|
||||||
var error;
|
var error;
|
||||||
try {
|
try {
|
||||||
new PublicKey(data, compressed);
|
new PublicKey(data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
||||||
|
@ -266,8 +266,8 @@ PublicKey.getValidationError = function(data, compressed) {
|
||||||
* @param {String} [compressed] - If the public key is compressed
|
* @param {String} [compressed] - If the public key is compressed
|
||||||
* @returns {Boolean} If the public key would be valid
|
* @returns {Boolean} If the public key would be valid
|
||||||
*/
|
*/
|
||||||
PublicKey.isValid = function(data, compressed) {
|
PublicKey.isValid = function(data) {
|
||||||
return !PublicKey.getValidationError(data, compressed);
|
return !PublicKey.getValidationError(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -79,11 +79,16 @@ describe('PublicKey', function() {
|
||||||
valid.should.equal(false);
|
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');
|
var valid = PublicKey.isValid('041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341');
|
||||||
valid.should.equal(true);
|
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() {
|
describe('#fromPoint', function() {
|
||||||
|
|
Loading…
Reference in New Issue