|
|
@ -1,9 +1,11 @@ |
|
|
|
'use strict'; |
|
|
|
|
|
|
|
var should = require('chai').should(); |
|
|
|
var bn = require('../lib/bn'); |
|
|
|
var point = require('../lib/point'); |
|
|
|
var Privkey = require('../lib/privkey'); |
|
|
|
var Pubkey = require('../lib/pubkey'); |
|
|
|
var Keypair = require('../lib/keypair'); |
|
|
|
var bitcore = require('..'); |
|
|
|
var bn = bitcore.BN; |
|
|
|
var Privkey = bitcore.Privkey; |
|
|
|
var Pubkey = bitcore.Pubkey; |
|
|
|
var Keypair = bitcore.Keypair; |
|
|
|
|
|
|
|
describe('Keypair', function() { |
|
|
|
|
|
|
@ -15,16 +17,21 @@ describe('Keypair', function() { |
|
|
|
it('should make a key with a priv and pub', function() { |
|
|
|
var priv = new Privkey(); |
|
|
|
var pub = new Pubkey(); |
|
|
|
var key = new Keypair({privkey: priv, pubkey: pub}); |
|
|
|
var key = new Keypair({ |
|
|
|
privkey: priv, |
|
|
|
pubkey: pub |
|
|
|
}); |
|
|
|
should.exist(key); |
|
|
|
should.exist(key.privkey); |
|
|
|
should.exist(key.pubkey); |
|
|
|
}); |
|
|
|
|
|
|
|
describe("#set", function() { |
|
|
|
describe('#set', function() { |
|
|
|
|
|
|
|
it('should make a new priv and pub', function() { |
|
|
|
should.exist(Keypair().set({privkey: Privkey()}).privkey); |
|
|
|
should.exist(new Keypair().set({ |
|
|
|
privkey: new Privkey() |
|
|
|
}).privkey); |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
@ -127,7 +134,9 @@ describe('Keypair', function() { |
|
|
|
var privhex = '906977a061af29276e40bf377042ffbde414e496ae2260bbf1fa9d085637bfff'; |
|
|
|
var pubhex = '02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc'; |
|
|
|
var key = new Keypair(); |
|
|
|
key.privkey = new Privkey({bn: bn(new Buffer(privhex, 'hex'))}); |
|
|
|
key.privkey = new Privkey({ |
|
|
|
bn: bn(new Buffer(privhex, 'hex')) |
|
|
|
}); |
|
|
|
key.privkey2pubkey(); |
|
|
|
key.pubkey.toString().should.equal(pubhex); |
|
|
|
}); |
|
|
@ -135,7 +144,9 @@ describe('Keypair', function() { |
|
|
|
it('should convert this known Privkey to known Pubkey and preserve compressed=true', function() { |
|
|
|
var privhex = '906977a061af29276e40bf377042ffbde414e496ae2260bbf1fa9d085637bfff'; |
|
|
|
var key = new Keypair(); |
|
|
|
key.privkey = new Privkey({bn: bn(new Buffer(privhex, 'hex'))}); |
|
|
|
key.privkey = new Privkey({ |
|
|
|
bn: bn(new Buffer(privhex, 'hex')) |
|
|
|
}); |
|
|
|
key.privkey.compressed = true; |
|
|
|
key.privkey2pubkey(); |
|
|
|
key.pubkey.compressed.should.equal(true); |
|
|
@ -144,7 +155,9 @@ describe('Keypair', function() { |
|
|
|
it('should convert this known Privkey to known Pubkey and preserve compressed=true', function() { |
|
|
|
var privhex = '906977a061af29276e40bf377042ffbde414e496ae2260bbf1fa9d085637bfff'; |
|
|
|
var key = new Keypair(); |
|
|
|
key.privkey = new Privkey({bn: bn(new Buffer(privhex, 'hex'))}); |
|
|
|
key.privkey = new Privkey({ |
|
|
|
bn: bn(new Buffer(privhex, 'hex')) |
|
|
|
}); |
|
|
|
key.privkey.compressed = false; |
|
|
|
key.privkey2pubkey(); |
|
|
|
key.pubkey.compressed.should.equal(false); |
|
|
|