update interface, bitcore.KeyModule.Key -> bitcore.Key

It's annoying and easy to forget to type in bitcore.KeyModule.Key. I have
updated this so that now you can just do bitcore.Key. Tests pass in node and
the browser. This is a backwards-incompatible change so all software that
depends on the old style key generation will need to be updated.
This commit is contained in:
Ryan X. Charles 2014-03-13 13:31:02 -04:00
parent 018239757b
commit 05f6e28642
6 changed files with 13 additions and 19 deletions

8
Key.js
View File

@ -2,7 +2,9 @@
if (process.versions) {
// c++ native version
module.exports = require('bindings')('KeyModule');
var KeyModule = require('bindings')('KeyModule');
var Key = KeyModule.Key;
module.exports = Key;
} else {
// pure js version
var ECKey = require('./browser/vendor-bundle.js').ECKey;
@ -97,10 +99,8 @@ if (process.versions) {
return ret;
};
module.exports = kSpec;
module.exports = {
Key: kSpec
};
}

View File

@ -1,6 +1,6 @@
var coinUtil = require('./util/util');
var timeUtil = require('./util/time');
var KeyModule = require('./Key');
var Key = require('./Key');
var SIN = require('./SIN');
function SINKey(cfg) {
@ -12,7 +12,7 @@ function SINKey(cfg) {
};
SINKey.prototype.generate = function() {
this.privKey = KeyModule.Key.generateSync();
this.privKey = Key.generateSync();
this.created = timeUtil.curtime();
};

View File

@ -2,7 +2,7 @@ var imports = require('soop').imports();
var coinUtil = require('./util/util');
var timeUtil = require('./util/time');
var KeyModule = require('./Key');
var Key= require('./Key');
var PrivateKey = require('./PrivateKey');
var Address = require('./Address');
@ -15,7 +15,7 @@ function WalletKey(cfg) {
};
WalletKey.prototype.generate = function() {
this.privKey = KeyModule.Key.generateSync();
this.privKey = Key.generateSync();
this.created = timeUtil.curtime();
};
@ -36,7 +36,7 @@ WalletKey.prototype.storeObj = function() {
WalletKey.prototype.fromObj = function(obj) {
this.created = obj.created;
this.privKey = new KeyModule.Key();
this.privKey = new Key();
if (obj.priv.length==64) {
this.privKey.private = new Buffer(obj.priv,'hex');
this.privKey.compressed = true;

View File

@ -30,7 +30,7 @@ requireWhenAccessed('Peer', './Peer');
requireWhenAccessed('Block', './Block');
requireWhenAccessed('ScriptInterpreter', './ScriptInterpreter');
requireWhenAccessed('Bloom', './Bloom');
requireWhenAccessed('KeyModule', './Key');
requireWhenAccessed('Key', './Key');
requireWhenAccessed('SINKey', './SINKey');
requireWhenAccessed('SIN', './SIN');
requireWhenAccessed('PrivateKey', './PrivateKey');

View File

@ -7,17 +7,11 @@ var buffertools = require('buffertools');
var should = chai.should();
var KeyModule = bitcore.KeyModule;
var Key;
var Key = bitcore.Key;
describe('Key', function() {
it('should initialze the main object', function() {
should.exist(KeyModule);
});
it('should be able to create class', function() {
Key = KeyModule.Key;
should.exist(Key);
});
Key = KeyModule.Key;
it('should be able to create instance', function() {
var k = new Key();
should.exist(k);

View File

@ -9,7 +9,7 @@ var should = chai.should();
var Address = bitcore.Address;
var PrivateKey = bitcore.PrivateKey;
var networks = bitcore.networks;
var KeyModule = bitcore.KeyModule;
var Key = bitcore.Key;
@ -26,7 +26,7 @@ function test_encode_priv(b58, payload, isTestnet, isCompressed) {
} else
buf = buf_pl;
var key = new KeyModule.Key();
var key = new Key();
key.private = buf;
key.compressed = isCompressed;