| var crypto = require('crypto'); | ||
| // Node.js has its own Crypto function that can handle this natively | ||
| var sha256 = module.exports = function(message, options) { | ||
| var c = crypto.createHash('sha256'); | ||
| if (Buffer.isBuffer(message)) { | ||
| c.update(message); | ||
| } else if (Array.isArray(message)) { | ||
| // Array of byte values | ||
| c.update(new Buffer(message)); | ||
| } else { | ||
| // Otherwise, treat as a binary string | ||
| c.update(new Buffer(message, 'binary')); | ||
| } | ||
| var buf = c.digest(); | ||
| if (options && options.asBytes) { | ||
| // Array of bytes as decimal integers | ||
| var a = []; | ||
| for(var i = 0; i < buf.length; i++) { | ||
| a.push(buf[i]); | ||
| } | ||
| return a; | ||
| } else if (options && options.asString) { | ||
| // Binary string | ||
| return buf.toString('binary'); | ||
| } else { | ||
| // String of hex characters | ||
| return buf.toString('hex'); | ||
| } | ||
| } | ||
| sha256.x2 = function(message, options) { | ||
| return sha256(sha256(message, { asBytes:true }), options) | ||
| } |
+11
-1
@@ -0,4 +1,14 @@ | ||
| 0.2.0 / 2015-03-18 | ||
| ------------------ | ||
| - browserify fix https://github.com/cryptocoinjs/sha256/pull/4 | ||
| - removed `component.json` and `bower.json` | ||
| - added **deprecation** notice | ||
| 0.1.1 / ??????? | ||
| --------------- | ||
| - (changelog wasn't updated, by viewing commit history, it looks like node specific) | ||
| 0.1.0 / 2013-11-20 | ||
| ------------------ | ||
| * changed package name | ||
| * changed package name | ||
| * removed AMD support | ||
@@ -5,0 +15,0 @@ |
+4
-45
@@ -7,10 +7,5 @@ !function(globals) { | ||
| if (typeof module !== 'undefined' && module.exports) { //CommonJS | ||
| if (typeof process !== 'undefined' && process.pid) { | ||
| // Node.js | ||
| module.exports = sha256_node; | ||
| } else { | ||
| _imports.bytesToHex = require('convert-hex').bytesToHex | ||
| _imports.convertString = require('convert-string') | ||
| module.exports = sha256 | ||
| } | ||
| _imports.bytesToHex = require('convert-hex').bytesToHex | ||
| _imports.convertString = require('convert-string') | ||
| module.exports = sha256 | ||
| } else { | ||
@@ -22,38 +17,2 @@ _imports.bytesToHex = globals.convertHex.bytesToHex | ||
| // Node.js has its own Crypto function that can handle this natively | ||
| function sha256_node(message, options) { | ||
| var crypto = require('crypto'); | ||
| var c = crypto.createHash('sha256'); | ||
| if (Buffer.isBuffer(message)) { | ||
| c.update(message); | ||
| } else if (Array.isArray(message)) { | ||
| // Array of byte values | ||
| c.update(new Buffer(message)); | ||
| } else { | ||
| // Otherwise, treat as a binary string | ||
| c.update(new Buffer(message, 'binary')); | ||
| } | ||
| var buf = c.digest(); | ||
| if (options && options.asBytes) { | ||
| // Array of bytes as decimal integers | ||
| var a = []; | ||
| for(var i = 0; i < buf.length; i++) { | ||
| a.push(buf[i]); | ||
| } | ||
| return a; | ||
| } else if (options && options.asString) { | ||
| // Binary string | ||
| return buf.toString('binary'); | ||
| } else { | ||
| // String of hex characters | ||
| return buf.toString('hex'); | ||
| } | ||
| } | ||
| sha256_node.x2 = function(message, options) { | ||
| return sha256_node(sha256_node(message, { asBytes:true }), options) | ||
| } | ||
| /* | ||
@@ -196,2 +155,2 @@ CryptoJS v3.1.2 | ||
| }(this); | ||
| }(this); |
+6
-2
| { | ||
| "name": "sha256", | ||
| "version": "0.1.1", | ||
| "version": "0.2.0", | ||
| "description": "Compute SHA256 of bytes or strings.", | ||
@@ -20,7 +20,11 @@ "keywords": [ | ||
| }, | ||
| "main": "./lib/sha256.js", | ||
| "main": "./lib/nodecrypto.js", | ||
| "browser": "./lib/sha256.js", | ||
| "dependencies": { | ||
| "convert-hex": "~0.1.0", | ||
| "convert-string": "~0.1.0" | ||
| }, | ||
| "scripts": { | ||
| "test": "mocha" | ||
| } | ||
| } |
+10
-13
@@ -5,2 +5,11 @@ # sha256 | ||
| ## DEPRECATION NOTICE | ||
| This library is deprecated. If you think it's important to maintain this library, please submit an issue and the case will be consider or the repo / ownership will be transferred to you. Viable alternatives: | ||
| 1. Use Browserify | ||
| 2. https://www.npmjs.com/package/sha.js (used by Browserify) | ||
| 3. https://github.com/indutny/hash.js | ||
| ## Install | ||
@@ -14,16 +23,4 @@ | ||
| ### Component | ||
| component install cryptocoinjs/sha256 | ||
| ### Bower | ||
| bower install sha256 | ||
| ### Script | ||
| ```html | ||
| <script src="/path/to/sha256.js"></script> | ||
| ``` | ||
| ## Usage | ||
@@ -54,3 +51,3 @@ | ||
| $ npm install --dev | ||
| $ ./node_modules/mocha/bin/mocha | ||
| $ npm test | ||
| ``` | ||
@@ -57,0 +54,0 @@ |
-23
| { | ||
| "name": "sha256", | ||
| "version": "0.1.0", | ||
| "description": "Compute SHA256 of bytes or strings", | ||
| "keywords": [ | ||
| "string", | ||
| "strings", | ||
| "sha256", | ||
| "bytes", | ||
| "cryptography" | ||
| ], | ||
| "ignore": [ | ||
| "node_modules", | ||
| ".DS_Store", | ||
| "references" | ||
| ], | ||
| "dependencies": { | ||
| "convert-hex": "0.1.x", | ||
| "convert-string": "0.1.x" | ||
| }, | ||
| "repo": "https://github.com/cryptocoinjs/sha256", | ||
| "main": "./lib/sha256.js" | ||
| } |
| { | ||
| "name": "sha256", | ||
| "version": "0.1.0", | ||
| "description": "Compute SHA256 of bytes or strings.", | ||
| "keywords": [ | ||
| "string", | ||
| "strings", | ||
| "sha256", | ||
| "bytes", | ||
| "cryptography" | ||
| ], | ||
| "repo": "cryptocoinjs/sha256", | ||
| "scripts": [ | ||
| "./lib/sha256.js" | ||
| ], | ||
| "main": "./lib/sha256.js", | ||
| "dependencies": { | ||
| "cryptocoinjs/convert-hex": "0.1.x", | ||
| "cryptocoinjs/convert-string": "0.1.x" | ||
| } | ||
| } |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
7763
-5.16%6
-14.29%156
-22.77%60
-4.76%