Browse Source

Fixed public key calculation by returning the elliptic ec.curve.g

patch-2
Braydon Fuller 10 years ago
parent
commit
bc4e62ecd4
  1. 13
      lib/crypto/point.js

13
lib/crypto/point.js

@ -2,9 +2,8 @@
var BN = require('./bn');
var bufferUtil = require('../util/buffer');
var ec = require('elliptic').curves.secp256k1;
var ecPoint = ec.curve.point.bind(ec.curve);
var ecPointFromX = ec.curve.pointFromX.bind(ec.curve);
var EC = require('elliptic').ec;
var ec = new EC('secp256k1');
/**
*
@ -19,7 +18,7 @@ var ecPointFromX = ec.curve.pointFromX.bind(ec.curve);
* @constructor
*/
var Point = function Point(x, y, isRed) {
var point = ecPoint(x, y, isRed);
var point = ec.curve.point(x, y, isRed);
point.validate();
return point;
};
@ -36,7 +35,7 @@ Point.prototype = Object.getPrototypeOf(ec.curve.point());
* @returns {Point} An instance of Point
*/
Point.fromX = function fromX(odd, x){
var point = ecPointFromX(odd, x);
var point = ec.curve.pointFromX(odd, x);
point.validate();
return point;
};
@ -49,7 +48,7 @@ Point.fromX = function fromX(odd, x){
* @returns {Point} An instance of the base point.
*/
Point.getG = function getG() {
return Point(ec.curve.g.getX(), ec.curve.g.getY());
return ec.curve.g;
};
/**
@ -106,7 +105,7 @@ Point.prototype.validate = function validate() {
throw new Error('Invalid x,y value for curve, cannot equal 0.');
}
var p2 = ecPointFromX(this.getY().isOdd(), this.getX());
var p2 = ec.curve.pointFromX(this.getY().isOdd(), this.getX());
if (p2.y.cmp(this.y) !== 0) {
throw new Error('Invalid y value for curve.');

Loading…
Cancel
Save