Browse Source

compressed by default with fromRandom

patch-2
Ryan X. Charles 11 years ago
parent
commit
40e8dfec06
  1. 1
      lib/ecdsa.js
  2. 6
      lib/privkey.js
  3. 5
      test/test.key.js
  4. 3
      test/test.privkey.js

1
lib/ecdsa.js

@ -31,6 +31,7 @@ ECDSA.prototype.calci = function() {
}
if (Qprime.point.eq(this.key.pubkey.point)) {
this.sig.compressed = this.key.pubkey.compressed;
return this;
}
}

6
lib/privkey.js

@ -24,7 +24,11 @@ Privkey.prototype.fromRandom = function() {
var bn = BN().fromBuffer(privbuf);
var condition = bn.lt(Point.getN());
} while (!condition);
this.bn = bn;
this.set({
bn: bn,
networkstr: 'mainnet',
compressed: true
});
return this;
};

5
test/test.key.js

@ -32,7 +32,7 @@ describe('Key', function() {
describe("#fromRandom", function() {
it('should make a new priv and pub', function() {
it('should make a new priv and pub, should be compressed, mainnet', function() {
var key = new Key();
key.fromRandom();
should.exist(key.privkey);
@ -40,6 +40,9 @@ describe('Key', function() {
key.privkey.bn.gt(bn(0)).should.equal(true);
key.pubkey.point.getX().gt(bn(0)).should.equal(true);
key.pubkey.point.getY().gt(bn(0)).should.equal(true);
key.privkey.compressed.should.equal(true);
key.privkey.networkstr.should.equal('mainnet');
key.pubkey.compressed.should.equal(true);
});
});

3
test/test.privkey.js

@ -42,10 +42,11 @@ describe('Privkey', function() {
describe('#fromRandom', function() {
it('should set bn gt 0 and lt n', function() {
it('should set bn gt 0 and lt n, and should be compressed', function() {
var privkey = Privkey().fromRandom();
privkey.bn.gt(BN(0)).should.equal(true);
privkey.bn.lt(Point.getN()).should.equal(true);
privkey.compressed.should.equal(true);
});
});

Loading…
Cancel
Save