Commit d5e70f58 authored by Fabien's avatar Fabien Committed by GitHub

Merge pull request #126 from steemit/update-crypto

Use 'create-hash' and 'create-hmac' instead of 'crypto'
parents cb394e71 7f6855ea
......@@ -12,7 +12,8 @@
"prepublish": "npm run test && npm run build"
},
"browser": {
"ws": false
"ws": false,
"crypto": false
},
"repository": {
"type": "git",
......@@ -33,8 +34,11 @@
"dependencies": {
"bigi": "^1.4.2",
"bluebird": "^3.4.6",
"browserify-aes": "^1.0.6",
"bs58": "^4.0.0",
"bytebuffer": "^5.0.1",
"create-hash": "^1.1.2",
"create-hmac": "^1.1.4",
"debug": "^2.2.0",
"detect-node": "^2.0.3",
"ecurve": "^1.0.5",
......
import secureRandom from 'secure-random'
import ByteBuffer from 'bytebuffer'
const PublicKey = require('./key_public')
const PrivateKey = require('./key_private')
const crypto = require("crypto");
const assert = require("assert");
const hash = require('./hash');
const Long = ByteBuffer.Long
import secureRandom from 'secure-random';
import ByteBuffer from 'bytebuffer';
import crypto from 'browserify-aes';
import assert from 'assert';
import PublicKey from './key_public';
import PrivateKey from './key_private';
import hash from './hash';
const Long = ByteBuffer.Long;
/**
Spec: http://localhost:3002/steem/@dantheman/how-to-encrypt-a-memo-when-transferring-steem
......
var crypto = require('crypto')
import createHash from 'create-hash';
import createHmac from 'create-hmac';
/** @arg {string|Buffer} data
@arg {string} [digest = null] - 'hex', 'binary' or 'base64'
@return {string|Buffer} - Buffer when digest is null, or string
*/
function sha1(data, encoding) {
return crypto.createHash('sha1').update(data).digest(encoding)
return createHash('sha1').update(data).digest(encoding)
}
/** @arg {string|Buffer} data
......@@ -13,7 +14,7 @@ function sha1(data, encoding) {
@return {string|Buffer} - Buffer when digest is null, or string
*/
function sha256(data, encoding) {
return crypto.createHash('sha256').update(data).digest(encoding)
return createHash('sha256').update(data).digest(encoding)
}
/** @arg {string|Buffer} data
......@@ -21,15 +22,15 @@ function sha256(data, encoding) {
@return {string|Buffer} - Buffer when digest is null, or string
*/
function sha512(data, encoding) {
return crypto.createHash('sha512').update(data).digest(encoding)
return createHash('sha512').update(data).digest(encoding)
}
function HmacSHA256(buffer, secret) {
return crypto.createHmac('sha256', secret).update(buffer).digest()
return createHmac('sha256', secret).update(buffer).digest()
}
function ripemd160(data) {
return crypto.createHash('rmd160').update(data).digest()
return createHash('rmd160').update(data).digest()
}
// function hash160(buffer) {
......
var bigi = require('bigi'),
crypto = require('crypto'),
bs58 = require('bs58'),
ecurve = require('ecurve'),
Point = ecurve.Point,
......@@ -8,7 +7,8 @@ var bigi = require('bigi'),
operations = require('./serializer/src/operations'),
Signature = require('./ecc/src/signature'),
KeyPrivate = require('./ecc/src/key_private'),
PublicKey = require('./ecc/src/key_public');
PublicKey = require('./ecc/src/key_public'),
hash = require('./ecc/src/hash');
var Auth = {};
var transaction = operations.transaction;
......@@ -34,12 +34,12 @@ Auth.generateKeys = function (name, password, roles) {
roles.forEach(function (role) {
var seed = name + role + password;
var brainKey = seed.trim().split(/[\t\n\v\f\r ]+/).join(' ');
var hashSha256 = crypto.createHash('sha256').update(brainKey).digest();
var hashSha256 = hash.sha256(brainKey);
var bigInt = bigi.fromBuffer(hashSha256);
var toPubKey = secp256k1.G.multiply(bigInt);
var point = new Point(toPubKey.curve, toPubKey.x, toPubKey.y, toPubKey.z);
var pubBuf = point.getEncoded(toPubKey.compressed);
var checksum = crypto.createHash('rmd160').update(pubBuf).digest();
var checksum = hash.ripemd160(pubBuf);
var addy = Buffer.concat([pubBuf, checksum.slice(0, 4)]);
pubKeys[role] = config.get('address_prefix') + bs58.encode(addy);
});
......@@ -66,8 +66,8 @@ Auth.isWif = function (privWif) {
var bufWif = new Buffer(bs58.decode(privWif));
var privKey = bufWif.slice(0, -4);
var checksum = bufWif.slice(-4);
var newChecksum = crypto.createHash('sha256').update(privKey).digest();
newChecksum = crypto.createHash('sha256').update(newChecksum).digest();
var newChecksum = hash.sha256(privKey);
newChecksum = hash.sha256(newChecksum);
newChecksum = newChecksum.slice(0, 4);
if (checksum.toString() == newChecksum.toString()) {
isWif = true;
......@@ -79,10 +79,10 @@ Auth.isWif = function (privWif) {
Auth.toWif = function (name, password, role) {
var seed = name + role + password;
var brainKey = seed.trim().split(/[\t\n\v\f\r ]+/).join(' ');
var hashSha256 = crypto.createHash('sha256').update(brainKey).digest();
var hashSha256 = hash.sha256(brainKey);
var privKey = Buffer.concat([new Buffer([0x80]), hashSha256]);
var checksum = crypto.createHash('sha256').update(privKey).digest();
checksum = crypto.createHash('sha256').update(checksum).digest();
var checksum = hash.sha256(privKey);
checksum = hash.sha256(checksum);
checksum = checksum.slice(0, 4);
var privWif = Buffer.concat([privKey, checksum]);
return bs58.encode(privWif);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment