This commit is contained in:
Christopher Jeffrey 2016-07-21 05:37:58 -07:00
parent 9cc05a488a
commit bb0149e603
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -230,230 +230,155 @@ utils.isBase58 = function isBase58(obj) {
}; };
/** /**
* Hash with chosen algorithm.
* @function * @function
* @param {String} alg * @see crypto.hash
* @param {Buffer} data
* @returns {Buffer}
*/ */
utils.hash = crypto.hash; utils.hash = crypto.hash;
/** /**
* Hash with ripemd160.
* @function * @function
* @param {Buffer} data * @see crypto.ripemd160
* @returns {Buffer}
*/ */
utils.ripemd160 = crypto.ripemd160; utils.ripemd160 = crypto.ripemd160;
/** /**
* Hash with sha1.
* @function * @function
* @param {Buffer} data * @see crypto.ripemd160
* @returns {Buffer}
*/ */
utils.sha1 = crypto.sha1; utils.sha1 = crypto.sha1;
/** /**
* Hash with sha256.
* @function * @function
* @param {Buffer} data * @see crypto.sha256
* @returns {Buffer}
*/ */
utils.sha256 = crypto.sha256; utils.sha256 = crypto.sha256;
/** /**
* Hash with sha256 and ripemd160 (OP_HASH160).
* @function * @function
* @param {Buffer} data * @see crypto.hash160
* @returns {Buffer}
*/ */
utils.hash160 = crypto.hash160; utils.hash160 = crypto.hash160;
/** /**
* Hash with sha256 twice (OP_HASH256).
* @function * @function
* @param {Buffer} data * @see crypto.hash256
* @returns {Buffer}
*/ */
utils.hash256 = crypto.hash256; utils.hash256 = crypto.hash256;
/** /**
* Create a sha256 checksum (common in bitcoin).
* @function * @function
* @param {Buffer} data * @see crypto.checksum
* @returns {Buffer}
*/ */
utils.checksum = crypto.checksum; utils.checksum = crypto.checksum;
/** /**
* Create an HMAC.
* @function * @function
* @param {String} alg * @see crypto.hmac
* @param {Buffer} data
* @param {Buffer} salt
* @returns {Buffer} HMAC
*/ */
utils.hmac = crypto.hmac; utils.hmac = crypto.hmac;
/** /**
* Perform key stretching using PBKDF2.
* @function * @function
* @param {Buffer} key * @see crypto.pbkdf2Sync
* @param {Buffer} salt
* @param {Number} iter
* @param {Number} len
* @param {String} alg
* @returns {Buffer}
*/ */
utils.pbkdf2Sync = crypto.pbkdf2Sync; utils.pbkdf2Sync = crypto.pbkdf2Sync;
/** /**
* Execute pbkdf2 asynchronously.
* @function * @function
* @param {Buffer} key * @see crypto.pbkdf2
* @param {Buffer} salt
* @param {Number} iter
* @param {Number} len
* @param {String} alg
* @param {Function} callback
*/ */
utils.pbkdf2 = crypto.pbkdf2; utils.pbkdf2 = crypto.pbkdf2;
/** /**
* Derive a key using pbkdf2 with 50,000 iterations.
* @function * @function
* @param {Buffer|String} passphrase * @see crypto.derive
* @param {Function} callback
*/ */
utils.derive = crypto.derive; utils.derive = crypto.derive;
/** /**
* Encrypt with aes-256-cbc. Derives key with {@link utils.derive}.
* @function * @function
* @param {Buffer} data * @see crypto.encrypt
* @param {Buffer|String} passphrase
* @param {Buffer} iv - 128 bit initialization vector.
* @param {Function} callback
*/ */
utils.encrypt = crypto.encrypt; utils.encrypt = crypto.encrypt;
/** /**
* Encrypt with aes-256-cbc.
* @function * @function
* @param {Buffer} data * @see crypto.encipher
* @param {Buffer} key - 256 bit key.
* @param {Buffer} iv - 128 bit initialization vector.
* @returns {Buffer}
*/ */
utils.encipher = crypto.encipher; utils.encipher = crypto.encipher;
/** /**
* Decrypt with aes-256-cbc. Derives key with {@link utils.derive}.
* @function * @function
* @param {Buffer} data * @see crypto.decrypt
* @param {Buffer|String} passphrase
* @param {Buffer} iv - 128 bit initialization vector.
* @param {Function} callback
*/ */
utils.decrypt = crypto.decrypt; utils.decrypt = crypto.decrypt;
/** /**
* Decrypt with aes-256-cbc.
* @function * @function
* @param {Buffer} data * @see crypto.decipher
* @param {Buffer} key - 256 bit key.
* @param {Buffer} iv - 128 bit initialization vector.
* @returns {Buffer}
*/ */
utils.decipher = crypto.decipher; utils.decipher = crypto.decipher;
/** /**
* Perform hkdf extraction.
* @function * @function
* @param {Buffer} ikm * @see crypto.hkdfExtract
* @param {Buffer} salt
* @param {String} alg
* @returns {Buffer}
*/ */
utils.hkdfExtract = crypto.hkdfExtract; utils.hkdfExtract = crypto.hkdfExtract;
/** /**
* Perform hkdf expansion.
* @function * @function
* @param {Buffer} prk * @see crypto.hkdfExpand
* @param {Buffer} info
* @param {Number} len
* @param {String} alg
* @returns {Buffer}
*/ */
utils.hkdfExpand = crypto.hkdfExpand; utils.hkdfExpand = crypto.hkdfExpand;
/** /**
* memcmp in constant time (can only return true or false). * @function
* This protects us against timing attacks when * @see crypto.ccmp
* comparing an input against a secret string.
* @see https://cryptocoding.net/index.php/Coding_rules
* @see `$ man 3 memcmp` (NetBSD's consttime_memequal)
* @param {Buffer} a
* @param {Buffer} b
* @returns {Boolean}
*/ */
utils.ccmp = crypto.ccmp; utils.ccmp = crypto.ccmp;
/** /**
* Build a merkle tree from leaves.
* @function * @function
* @param {Buffer[]} leaves * @see crypto.buildMerkleTree
* @returns {Buffer[]} Tree (in rare cases this may return null).
*/ */
utils.buildMerkleTree = crypto.buildMerkleTree; utils.buildMerkleTree = crypto.buildMerkleTree;
/** /**
* Calculate merkle root from leaves.
* @function * @function
* @param {Buffer[]} leaves * @see crypto.getMerkleRoot
* @returns {Buffer?} Merkle root.
*/ */
utils.getMerkleRoot = crypto.getMerkleRoot; utils.getMerkleRoot = crypto.getMerkleRoot;
/** /**
* Collect a merkle branch at vector index.
* @function * @function
* @param {Number} index * @see crypto.getMerkleBranch
* @param {Buffer[]} leaves
* @returns {Buffer[]} branch
*/ */
utils.getMerkleBranch = crypto.getMerkleBranch; utils.getMerkleBranch = crypto.getMerkleBranch;
/** /**
* Check a merkle branch at vector index.
* @function * @function
* @param {Buffer} hash * @see crypto.checkMerkleBranch
* @param {Buffer[]} branch
* @param {Number} index
* @returns {Buffer} Hash.
*/ */
utils.checkMerkleBranch = crypto.checkMerkleBranch; utils.checkMerkleBranch = crypto.checkMerkleBranch;