aboutsummaryrefslogtreecommitdiff
path: root/node_modules/hash-base
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-05-24 15:10:37 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-05-24 15:11:17 +0200
commit7a3df06eb573d36142bd1a8e03c5ce8752d300b3 (patch)
tree70bfaea8884c374876f607774850a3a51c0cb381 /node_modules/hash-base
parentaca1143cb9eed16cf37f04e475e4257418dd18ac (diff)
downloadwallet-core-7a3df06eb573d36142bd1a8e03c5ce8752d300b3.tar.xz
fix build issues and add typedoc
Diffstat (limited to 'node_modules/hash-base')
-rw-r--r--node_modules/hash-base/README.md38
-rw-r--r--node_modules/hash-base/index.js83
-rw-r--r--node_modules/hash-base/package.json37
3 files changed, 158 insertions, 0 deletions
diff --git a/node_modules/hash-base/README.md b/node_modules/hash-base/README.md
new file mode 100644
index 000000000..2fa8f1d23
--- /dev/null
+++ b/node_modules/hash-base/README.md
@@ -0,0 +1,38 @@
+# hash-base
+
+[![NPM Package](https://img.shields.io/npm/v/hash-base.svg?style=flat-square)](https://www.npmjs.org/package/hash-base)
+[![Build Status](https://img.shields.io/travis/crypto-browserify/hash-base.svg?branch=master&style=flat-square)](https://travis-ci.org/crypto-browserify/hash-base)
+[![Dependency status](https://img.shields.io/david/crypto-browserify/hash-base.svg?style=flat-square)](https://david-dm.org/crypto-browserify/hash-base#info=dependencies)
+
+[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
+
+Abstract base class to inherit from if you want to create streams implementing the same API as node crypto [Hash][1] (for [Cipher][2] / [Decipher][3] check [crypto-browserify/cipher-base][4]).
+
+## Example
+
+```js
+function MyHash () {
+ HashBase.call(64) // in bytes
+}
+
+inherti(MyHash, HashBase)
+
+MyHash.prototype._update = function () {
+ // hashing one block with buffer this._block
+}
+
+MyHash.prototype._digest = function () {
+ // create padding and produce result
+}
+```
+You also can check [source code](index.js) or [crypto-browserify/md5.js][5]
+
+## LICENSE
+
+MIT
+
+[1]: https://nodejs.org/api/crypto.html#crypto_class_hash
+[2]: https://nodejs.org/api/crypto.html#crypto_class_cipher
+[3]: https://nodejs.org/api/crypto.html#crypto_class_decipher
+[4]: https://github.com/crypto-browserify/cipher-base
+[5]: https://github.com/crypto-browserify/md5.js
diff --git a/node_modules/hash-base/index.js b/node_modules/hash-base/index.js
new file mode 100644
index 000000000..9cd6a7005
--- /dev/null
+++ b/node_modules/hash-base/index.js
@@ -0,0 +1,83 @@
+'use strict'
+var Transform = require('stream').Transform
+var inherits = require('inherits')
+
+function HashBase (blockSize) {
+ Transform.call(this)
+
+ this._block = new Buffer(blockSize)
+ this._blockSize = blockSize
+ this._blockOffset = 0
+ this._length = [0, 0, 0, 0]
+
+ this._finalized = false
+}
+
+inherits(HashBase, Transform)
+
+HashBase.prototype._transform = function (chunk, encoding, callback) {
+ var error = null
+ try {
+ if (encoding !== 'buffer') chunk = new Buffer(chunk, encoding)
+ this.update(chunk)
+ } catch (err) {
+ error = err
+ }
+
+ callback(error)
+}
+
+HashBase.prototype._flush = function (callback) {
+ var error = null
+ try {
+ this.push(this._digest())
+ } catch (err) {
+ error = err
+ }
+
+ callback(error)
+}
+
+HashBase.prototype.update = function (data, encoding) {
+ if (!Buffer.isBuffer(data) && typeof data !== 'string') throw new TypeError('Data must be a string or a buffer')
+ if (this._finalized) throw new Error('Digest already called')
+ if (!Buffer.isBuffer(data)) data = new Buffer(data, encoding || 'binary')
+
+ // consume data
+ var block = this._block
+ var offset = 0
+ while (this._blockOffset + data.length - offset >= this._blockSize) {
+ for (var i = this._blockOffset; i < this._blockSize;) block[i++] = data[offset++]
+ this._update()
+ this._blockOffset = 0
+ }
+ while (offset < data.length) block[this._blockOffset++] = data[offset++]
+
+ // update length
+ for (var j = 0, carry = data.length * 8; carry > 0; ++j) {
+ this._length[j] += carry
+ carry = (this._length[j] / 0x0100000000) | 0
+ if (carry > 0) this._length[j] -= 0x0100000000 * carry
+ }
+
+ return this
+}
+
+HashBase.prototype._update = function (data) {
+ throw new Error('_update is not implemented')
+}
+
+HashBase.prototype.digest = function (encoding) {
+ if (this._finalized) throw new Error('Digest already called')
+ this._finalized = true
+
+ var digest = this._digest()
+ if (encoding !== undefined) digest = digest.toString(encoding)
+ return digest
+}
+
+HashBase.prototype._digest = function () {
+ throw new Error('_digest is not implemented')
+}
+
+module.exports = HashBase
diff --git a/node_modules/hash-base/package.json b/node_modules/hash-base/package.json
new file mode 100644
index 000000000..3f009c6c2
--- /dev/null
+++ b/node_modules/hash-base/package.json
@@ -0,0 +1,37 @@
+{
+ "name": "hash-base",
+ "version": "2.0.2",
+ "description": "abstract base class for hash-streams",
+ "keywords": [
+ "hash",
+ "stream"
+ ],
+ "homepage": "https://github.com/crypto-browserify/hash-base",
+ "bugs": {
+ "url": "https://github.com/crypto-browserify/hash-base/issues"
+ },
+ "license": "MIT",
+ "author": "Kirill Fomichev <fanatid@ya.ru> (https://github.com/fanatid)",
+ "files": [
+ "index.js"
+ ],
+ "main": "index.js",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/crypto-browserify/hash-base.git"
+ },
+ "scripts": {
+ "coverage": "nyc node test/*.js",
+ "lint": "standard",
+ "test": "npm run lint && npm run unit",
+ "unit": "node test/*.js"
+ },
+ "dependencies": {
+ "inherits": "^2.0.1"
+ },
+ "devDependencies": {
+ "nyc": "^6.1.1",
+ "standard": "^6.0.8",
+ "tape": "^4.2.0"
+ }
+}