replace jssha with sjcl - remove jssha dependency
This commit is contained in:
parent
af9fdff3a9
commit
a242112e66
|
@ -12,7 +12,7 @@ var puts = function(error, stdout, stderr) {
|
|||
};
|
||||
|
||||
//compile sjcl
|
||||
exec('cd node_modules/sjcl && ./configure --without-all --with-aes --with-convenience --with-cbc --with-codecHex --with-codecBase64 && make && cd ../..;', puts);
|
||||
exec('cd node_modules/sjcl && ./configure --without-all --with-aes --with-convenience --with-cbc --with-codecHex --with-codecBase64 --with-sha512 --with-hmac && make && cd ../..;', puts);
|
||||
|
||||
var pack = function (params) {
|
||||
var file = require.resolve('soop');
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -53,7 +53,6 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"sjcl": "=1.0.1",
|
||||
"jssha": "=1.5.0",
|
||||
"soop": "=0.1.5",
|
||||
"bindings": "=1.1.1",
|
||||
"bufferput": "git://github.com/bitpay/node-bufferput.git",
|
||||
|
|
22
util/util.js
22
util/util.js
|
@ -3,7 +3,7 @@ var bignum = require('bignum');
|
|||
var Binary = require('binary');
|
||||
var Put = require('bufferput');
|
||||
var buffertools = require('buffertools');
|
||||
var jssha = require('jssha');
|
||||
var sjcl = require('sjcl');
|
||||
var browser;
|
||||
var inBrowser = !process.versions;
|
||||
if (inBrowser) {
|
||||
|
@ -16,19 +16,25 @@ var sha256 = exports.sha256 = function(data) {
|
|||
|
||||
var sha512 = exports.sha512 = function(data) {
|
||||
if (inBrowser) {
|
||||
var j = new jssha(data.toString('hex'), 'HEX');
|
||||
var hashhex = j.getHash('SHA-512', 'HEX');
|
||||
return new Buffer(hashhex, 'hex');
|
||||
var datahex = data.toString('hex');
|
||||
var databits = sjcl.codec.hex.toBits(datahex);
|
||||
var hashbits = sjcl.hash.sha512.hash(databits);
|
||||
var hashhex = sjcl.codec.hex.fromBits(hashbits);
|
||||
var hash = new Buffer(hashhex, 'hex');
|
||||
return hash;
|
||||
};
|
||||
return new Buffer(crypto.createHash('sha512').update(data).digest('binary'), 'binary');
|
||||
};
|
||||
|
||||
var sha512hmac = exports.sha512hmac = function (data, key) {
|
||||
if (inBrowser) {
|
||||
var j = new jssha(data.toString('hex'), 'HEX');
|
||||
var hash = j.getHMAC(key.toString('hex'), "HEX", "SHA-512", "HEX");
|
||||
hash = new Buffer(hash, 'hex');
|
||||
return hash;
|
||||
var skey = sjcl.codec.hex.toBits(key.toString('hex'));
|
||||
var sdata = sjcl.codec.hex.toBits(data.toString('hex'));
|
||||
var hmac = new sjcl.misc.hmac(skey, sjcl.hash.sha512);
|
||||
var encrypted = hmac.encrypt(sdata);
|
||||
var enchex = sjcl.codec.hex.fromBits(encrypted);
|
||||
var encbuf = new Buffer(enchex, 'hex');
|
||||
return encbuf;
|
||||
};
|
||||
var hmac = crypto.createHmac('sha512', key);
|
||||
var hash = hmac.update(data).digest();
|
||||
|
|
Loading…
Reference in New Issue