67 lines
1.4 KiB
JavaScript
67 lines
1.4 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-1 hash.
|
|
* @param {Buffer} buf - Input data
|
|
* @return {Buffer} Resulting hash.
|
|
* @function
|
|
*/
|
|
exports.sha1 = platform.sha1;
|
|
|
|
/**
|
|
* Calculate SHA-256 hash.
|
|
* @param {Buffer} buf - Input data
|
|
* @return {Buffer} Resulting hash.
|
|
* @function
|
|
*/
|
|
exports.sha256 = platform.sha256;
|
|
|
|
/**
|
|
* Calculate SHA-512 hash.
|
|
* @param {Buffer} buf - Input data
|
|
* @return {Buffer} Resulting hash.
|
|
* @function
|
|
*/
|
|
exports.sha512 = platform.sha512;
|
|
|
|
/**
|
|
* 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 the given private key.
|
|
* @param {Buffer} privateKey - A 32-byte private key
|
|
* @return {Buffer} A 65-byte (uncompressed) public key.
|
|
* @function
|
|
*/
|
|
exports.getPublic = eccrypto.getPublic;
|