2014-12-13 19:56:14 +01:00
|
|
|
/**
|
2015-01-03 11:29:22 +01:00
|
|
|
* Isomorphic Bitmessage crypto module. Reexports platform-dependent
|
|
|
|
* implementations and and also some common routines.
|
2014-12-18 17:47:18 +01:00
|
|
|
* @module bitmessage/crypto
|
2014-12-13 19:56:14 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2014-12-27 16:17:41 +01:00
|
|
|
var eccrypto = require("eccrypto");
|
2015-01-03 11:29:22 +01:00
|
|
|
var platform = require("./platform");
|
2014-12-26 18:17:01 +01:00
|
|
|
|
2015-01-03 11:29:22 +01:00
|
|
|
/**
|
2015-01-16 16:35:40 +01:00
|
|
|
* Calculate SHA-1 hash.
|
2015-01-03 11:29:22 +01:00
|
|
|
* @param {Buffer} buf - Input data
|
2015-01-03 15:52:27 +01:00
|
|
|
* @return {Buffer} Resulting hash.
|
2015-01-03 11:29:22 +01:00
|
|
|
* @function
|
|
|
|
*/
|
2015-01-16 16:35:40 +01:00
|
|
|
exports.sha1 = platform.sha1;
|
2015-01-03 11:29:22 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate SHA-256 hash.
|
|
|
|
* @param {Buffer} buf - Input data
|
2015-01-03 15:52:27 +01:00
|
|
|
* @return {Buffer} Resulting hash.
|
2015-01-03 11:29:22 +01:00
|
|
|
* @function
|
|
|
|
*/
|
|
|
|
exports.sha256 = platform.sha256;
|
|
|
|
|
2015-01-16 16:35:40 +01:00
|
|
|
/**
|
|
|
|
* Calculate SHA-512 hash.
|
|
|
|
* @param {Buffer} buf - Input data
|
|
|
|
* @return {Buffer} Resulting hash.
|
|
|
|
* @function
|
|
|
|
*/
|
|
|
|
exports.sha512 = platform.sha512;
|
|
|
|
|
2015-01-03 11:29:22 +01:00
|
|
|
/**
|
|
|
|
* Calculate RIPEMD-160 hash.
|
|
|
|
* @param {Buffer} buf - Input data
|
2015-01-03 15:52:27 +01:00
|
|
|
* @return {Buffer} Resulting hash.
|
2015-01-03 11:29:22 +01:00
|
|
|
* @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;
|
2014-12-27 16:17:41 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate new random private key.
|
|
|
|
* @return {Buffer} New private key.
|
|
|
|
*/
|
|
|
|
exports.getPrivate = function() {
|
2015-01-03 11:29:22 +01:00
|
|
|
return platform.randomBytes(32);
|
2014-12-27 16:17:41 +01:00
|
|
|
};
|
|
|
|
|
2014-12-30 18:00:28 +01:00
|
|
|
/**
|
2015-01-15 23:43:15 +01:00
|
|
|
* Generate public key for the given private key.
|
|
|
|
* @param {Buffer} privateKey - A 32-byte private key
|
|
|
|
* @return {Buffer} A 65-byte (uncompressed) public key.
|
2014-12-30 18:00:28 +01:00
|
|
|
* @function
|
|
|
|
*/
|
2014-12-27 16:17:41 +01:00
|
|
|
exports.getPublic = eccrypto.getPublic;
|