bitmessage-js/lib/crypto.js
Kagami Hiiragi bf8b663c5d Do not use promises in crypto
Because sha.js is faster than WebCryptoAPI for POW.
2015-01-03 17:52:27 +03:00

59 lines
1.2 KiB
JavaScript

/**
* Isomorphic Bitmessage crypto module. Reexports platform-dependent
* implementations and and also some common routines.
* @module bitmessage/crypto
*/
"use strict";
var eccrypto = require("eccrypto");
var platform = require("./platform");
/**
* Calculate SHA-512 hash.
* @param {Buffer} buf - Input data
* @return {Buffer} Resulting hash.
* @function
*/
exports.sha512 = platform.sha512;
/**
* Calculate SHA-256 hash.
* @param {Buffer} buf - Input data
* @return {Buffer} Resulting hash.
* @function
*/
exports.sha256 = platform.sha256;
/**
* Calculate RIPEMD-160 hash.
* @param {Buffer} buf - Input data
* @return {Buffer} Resulting hash.
* @function
*/
exports.ripemd160 = platform.ripemd160;
/**
* Generate cryptographically strong pseudo-random data.
* @param {number} size - Number of bytes
* @return {Buffer} Buffer with random data.
* @function
*/
exports.randomBytes = platform.randomBytes;
/**
* Generate new random private key.
* @return {Buffer} New private key.
*/
exports.getPrivate = function() {
return platform.randomBytes(32);
};
/**
* Generate public key for a given private key.
* @param {Buffer} privateKey - Private key
* @return {Buffer} Public key.
* @function
*/
exports.getPublic = eccrypto.getPublic;