You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
3.8 KiB
97 lines
3.8 KiB
11 years ago
|
var should = require('chai').should();
|
||
|
var pubkey = require('../lib/pubkey');
|
||
|
var point = require('../lib/point');
|
||
|
var bn = require('../lib/bn');
|
||
|
|
||
|
describe('pubkey', function() {
|
||
|
|
||
|
it('should create a blank public key', function() {
|
||
|
var pk = new pubkey();
|
||
|
should.exist(pk);
|
||
|
});
|
||
|
|
||
|
it('should create a public key with a point', function() {
|
||
|
var p = point();
|
||
|
var pk = new pubkey(p);
|
||
|
should.exist(pk.p);
|
||
|
});
|
||
|
|
||
|
describe('#fromDER', function() {
|
||
|
|
||
|
it('should parse this uncompressed public key', function() {
|
||
|
var pk = new pubkey();
|
||
|
pk.fromDER(new Buffer('041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341', 'hex'));
|
||
|
pk.p.getX().toString(16).should.equal('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a');
|
||
|
pk.p.getY().toString(16).should.equal('7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341');
|
||
|
});
|
||
|
|
||
|
it('should parse this compressed public key', function() {
|
||
|
var pk = new pubkey();
|
||
|
pk.fromDER(new Buffer('031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
|
||
|
pk.p.getX().toString(16).should.equal('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a');
|
||
|
pk.p.getY().toString(16).should.equal('7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341');
|
||
|
});
|
||
|
|
||
|
it('should throw an error on this invalid public key', function() {
|
||
|
var pk = new pubkey();
|
||
|
(function() {
|
||
|
pk.fromDER(new Buffer('091ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
|
||
|
}).should.throw();
|
||
|
});
|
||
|
|
||
|
});
|
||
|
|
||
|
describe('#fromString', function() {
|
||
|
|
||
|
it('should parse this known valid public key', function() {
|
||
|
pk = new pubkey();
|
||
|
pk.fromString('041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341');
|
||
|
pk.p.getX().toString(16).should.equal('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a');
|
||
|
pk.p.getY().toString(16).should.equal('7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341');
|
||
|
});
|
||
|
|
||
|
});
|
||
|
|
||
|
describe('#fromX', function() {
|
||
|
|
||
|
it('should create this known public key', function() {
|
||
|
var x = bn.fromBuffer(new Buffer('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
|
||
|
var pk = new pubkey();
|
||
|
pk.fromX(true, x);
|
||
|
pk.p.getX().toString(16).should.equal('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a');
|
||
|
pk.p.getY().toString(16).should.equal('7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341');
|
||
|
});
|
||
|
|
||
|
});
|
||
|
|
||
|
describe('#toDER', function() {
|
||
|
|
||
|
it('should return this compressed DER format', function() {
|
||
|
var x = bn.fromBuffer(new Buffer('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
|
||
|
var pk = new pubkey();
|
||
|
pk.fromX(true, x);
|
||
|
pk.toDER(true).toString('hex').should.equal('031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a');
|
||
|
});
|
||
|
|
||
|
it('should return this uncompressed DER format', function() {
|
||
|
var x = bn.fromBuffer(new Buffer('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
|
||
|
var pk = new pubkey();
|
||
|
pk.fromX(true, x);
|
||
|
pk.toDER(false).toString('hex').should.equal('041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341');
|
||
|
});
|
||
|
|
||
|
});
|
||
|
|
||
|
describe('#toString', function() {
|
||
|
|
||
|
it('should print this known public key', function() {
|
||
|
var hex = '031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a';
|
||
|
var pk = new pubkey();
|
||
|
pk.fromString(hex);
|
||
|
pk.toString().should.equal(hex);
|
||
|
});
|
||
|
|
||
|
});
|
||
|
|
||
|
});
|