|
|
@ -12,10 +12,10 @@ var Address = require('./address'); |
|
|
|
* |
|
|
|
* // instantiate from a private key
|
|
|
|
* var key = PublicKey(privateKey, true); |
|
|
|
* |
|
|
|
* // export to as a DER hex encoded string
|
|
|
|
* |
|
|
|
* // export to as a DER hex encoded string
|
|
|
|
* var exported = key.toString(); |
|
|
|
* |
|
|
|
* |
|
|
|
* // import the public key
|
|
|
|
* var imported = PublicKey.fromString(exported); |
|
|
|
* |
|
|
@ -45,7 +45,7 @@ var PublicKey = function PublicKey(data, compressed) { |
|
|
|
info = PublicKey._transformDER(new Buffer(data, 'hex' )); |
|
|
|
} else if (data instanceof Buffer || data instanceof Uint8Array){ |
|
|
|
info = PublicKey._transformDER(data); |
|
|
|
} else if (data.constructor && (data.constructor.name && |
|
|
|
} else if (data.constructor && (data.constructor.name && |
|
|
|
data.constructor.name === 'PrivateKey')) { |
|
|
|
info = PublicKey._transformPrivateKey(data); |
|
|
|
} else { |
|
|
@ -55,8 +55,15 @@ var PublicKey = function PublicKey(data, compressed) { |
|
|
|
// validation
|
|
|
|
info.point.validate(); |
|
|
|
|
|
|
|
this.point = info.point; |
|
|
|
this.compressed = info.compressed; |
|
|
|
Object.defineProperty(this, 'point', { |
|
|
|
configurable: false, |
|
|
|
value: info.point |
|
|
|
}); |
|
|
|
|
|
|
|
Object.defineProperty(this, 'compressed', { |
|
|
|
configurable: false, |
|
|
|
value: info.compressed |
|
|
|
}); |
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
|
@ -71,7 +78,7 @@ var PublicKey = function PublicKey(data, compressed) { |
|
|
|
*/ |
|
|
|
PublicKey._transformPrivateKey = function(privkey) { |
|
|
|
var info = {}; |
|
|
|
if (!privkey.constructor || |
|
|
|
if (!privkey.constructor || |
|
|
|
(privkey.constructor.name && privkey.constructor.name !== 'PrivateKey')) { |
|
|
|
throw new TypeError('Must be an instance of PrivateKey'); |
|
|
|
} |
|
|
|