fromBuffer convenience function for pubkey
This commit is contained in:
parent
385edbcc92
commit
543762bc67
|
@ -29,6 +29,10 @@ Pubkey.prototype.fromPrivkey = function(privkey) {
|
|||
return this;
|
||||
};
|
||||
|
||||
Pubkey.prototype.fromBuffer = function(buf) {
|
||||
return this.fromDER(buf);
|
||||
};
|
||||
|
||||
Pubkey.prototype.fromDER = function(buf) {
|
||||
if (buf[0] == 0x04) {
|
||||
var xbuf = buf.slice(1, 33);
|
||||
|
|
|
@ -40,6 +40,31 @@ describe('Pubkey', function() {
|
|||
|
||||
});
|
||||
|
||||
describe('#fromBuffer', function() {
|
||||
|
||||
it('should parse this uncompressed public key', function() {
|
||||
var pk = new Pubkey();
|
||||
pk.fromBuffer(new Buffer('041ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341', 'hex'));
|
||||
pk.point.getX().toString(16).should.equal('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a');
|
||||
pk.point.getY().toString(16).should.equal('7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341');
|
||||
});
|
||||
|
||||
it('should parse this compressed public key', function() {
|
||||
var pk = new Pubkey();
|
||||
pk.fromBuffer(new Buffer('031ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
|
||||
pk.point.getX().toString(16).should.equal('1ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a');
|
||||
pk.point.getY().toString(16).should.equal('7baad41d04514751e6851f5304fd243751703bed21b914f6be218c0fa354a341');
|
||||
});
|
||||
|
||||
it('should throw an error on this invalid public key', function() {
|
||||
var pk = new Pubkey();
|
||||
(function() {
|
||||
pk.fromBuffer(new Buffer('091ff0fe0f7b15ffaa85ff9f4744d539139c252a49710fb053bb9f2b933173ff9a', 'hex'));
|
||||
}).should.throw();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#fromDER', function() {
|
||||
|
||||
it('should parse this uncompressed public key', function() {
|
||||
|
|
Loading…
Reference in New Issue