mirror of
https://github.com/hanzoai/elliptic.git
synced 2026-09-23 23:51:03 +00:00
key: error when only either x or y are provided
PR-URL: https://github.com/indutny/elliptic/pull/112 Reviewed-By: Fedor Indutny <[email protected]>
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
var BN = require('bn.js');
|
||||
var elliptic = require('../../elliptic');
|
||||
var utils = elliptic.utils;
|
||||
var assert = utils.assert;
|
||||
|
||||
function KeyPair(ec, options) {
|
||||
this.ec = ec;
|
||||
@@ -81,6 +84,15 @@ KeyPair.prototype._importPrivate = function _importPrivate(key, enc) {
|
||||
|
||||
KeyPair.prototype._importPublic = function _importPublic(key, enc) {
|
||||
if (key.x || key.y) {
|
||||
// Montgomery points only have an `x` coordinate.
|
||||
// Weierstrass/Edwards points on the other hand have both `x` and
|
||||
// `y` coordinates.
|
||||
if (this.ec.curve.type === 'mont') {
|
||||
assert(key.x, 'Need x coordinate');
|
||||
} else if (this.ec.curve.type === 'short' ||
|
||||
this.ec.curve.type === 'edwards') {
|
||||
assert(key.x && key.y, 'Need both x and y coordinate');
|
||||
}
|
||||
this.pub = this.ec.curve.point(key.x, key.y);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user