|
|
@ -39,7 +39,7 @@ var PublicKey = function PublicKey(data, extra) { |
|
|
|
return new PublicKey(data, extra); |
|
|
|
} |
|
|
|
|
|
|
|
$.checkArgument(data, new TypeError('First argument is required, please include public key data.')); |
|
|
|
$.checkArgument(data, 'First argument is required, please include public key data.'); |
|
|
|
|
|
|
|
if (data instanceof PublicKey) { |
|
|
|
// Return copy, but as it's an immutable object, return same argument
|
|
|
@ -134,8 +134,7 @@ PublicKey._isJSON = function(json) { |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
PublicKey._transformPrivateKey = function(privkey) { |
|
|
|
$.checkArgument(PublicKey._isPrivateKey(privkey), |
|
|
|
new TypeError('Must be an instance of PrivateKey')); |
|
|
|
$.checkArgument(PublicKey._isPrivateKey(privkey), 'Must be an instance of PrivateKey'); |
|
|
|
var info = {}; |
|
|
|
info.point = Point.getG().mul(privkey.bn); |
|
|
|
info.compressed = privkey.compressed; |
|
|
@ -154,7 +153,7 @@ PublicKey._transformPrivateKey = function(privkey) { |
|
|
|
PublicKey._transformDER = function(buf, strict) { |
|
|
|
/* jshint maxstatements: 30 */ |
|
|
|
/* jshint maxcomplexity: 12 */ |
|
|
|
$.checkArgument(PublicKey._isBuffer(buf), new TypeError('Must be a hex buffer of DER encoded public key')); |
|
|
|
$.checkArgument(PublicKey._isBuffer(buf), 'Must be a hex buffer of DER encoded public key'); |
|
|
|
var info = {}; |
|
|
|
|
|
|
|
strict = _.isUndefined(strict) ? true : strict; |
|
|
@ -199,8 +198,7 @@ PublicKey._transformDER = function(buf, strict) { |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
PublicKey._transformX = function(odd, x) { |
|
|
|
$.checkArgument(typeof odd === 'boolean', |
|
|
|
new TypeError('Must specify whether y is odd or not (true or false)')); |
|
|
|
$.checkArgument(typeof odd === 'boolean', 'Must specify whether y is odd or not (true or false)'); |
|
|
|
var info = {}; |
|
|
|
info.point = Point.fromX(odd, x); |
|
|
|
return info; |
|
|
@ -213,8 +211,7 @@ PublicKey._transformX = function(odd, x) { |
|
|
|
* @returns {PublicKey} A new valid instance of PublicKey |
|
|
|
*/ |
|
|
|
PublicKey.fromJSON = function(json) { |
|
|
|
$.checkArgument(PublicKey._isJSON(json), |
|
|
|
new TypeError('Must be a valid JSON string or plain object')); |
|
|
|
$.checkArgument(PublicKey._isJSON(json), 'Must be a valid JSON string or plain object'); |
|
|
|
return new PublicKey(json); |
|
|
|
}; |
|
|
|
|
|
|
@ -244,7 +241,7 @@ PublicKey._transformJSON = function(json) { |
|
|
|
* @returns {PublicKey} A new valid instance of PublicKey |
|
|
|
*/ |
|
|
|
PublicKey.fromPrivateKey = function(privkey) { |
|
|
|
$.checkArgument(PublicKey._isPrivateKey(privkey), new TypeError('Must be an instance of PrivateKey')); |
|
|
|
$.checkArgument(PublicKey._isPrivateKey(privkey), 'Must be an instance of PrivateKey'); |
|
|
|
var info = PublicKey._transformPrivateKey(privkey); |
|
|
|
return new PublicKey(info.point, { |
|
|
|
compressed: info.compressed, |
|
|
@ -259,8 +256,7 @@ PublicKey.fromPrivateKey = function(privkey) { |
|
|
|
* @returns {PublicKey} A new valid instance of PublicKey |
|
|
|
*/ |
|
|
|
PublicKey.fromDER = PublicKey.fromBuffer = function(buf, strict) { |
|
|
|
$.checkArgument(PublicKey._isBuffer(buf), |
|
|
|
new TypeError('Must be a hex buffer of DER encoded public key')); |
|
|
|
$.checkArgument(PublicKey._isBuffer(buf), 'Must be a hex buffer of DER encoded public key'); |
|
|
|
var info = PublicKey._transformDER(buf, strict); |
|
|
|
return new PublicKey(info.point, { |
|
|
|
compressed: info.compressed |
|
|
@ -275,8 +271,7 @@ PublicKey.fromDER = PublicKey.fromBuffer = function(buf, strict) { |
|
|
|
* @returns {PublicKey} A new valid instance of PublicKey |
|
|
|
*/ |
|
|
|
PublicKey.fromPoint = function(point, compressed) { |
|
|
|
$.checkArgument(point instanceof Point, |
|
|
|
new TypeError('First argument must be an instance of Point.')); |
|
|
|
$.checkArgument(point instanceof Point, 'First argument must be an instance of Point.'); |
|
|
|
return new PublicKey(point, { |
|
|
|
compressed: compressed |
|
|
|
}); |
|
|
|