This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
40 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
import sha256digest from '@zap/utils/sha256' | ||
import { sha256digest } from '@zap/utils/sha256' | ||
|
||
describe('sha256digest', () => { | ||
it('should produce correct sha256 hashes of a string', () => { | ||
expect(sha256digest('chancellor on the brink of second bailout for banks')).toEqual( | ||
it('should produce correct sha256 hashes of a string (bytes)', () => { | ||
expect(sha256digest('chancellor on the brink of second bailout for banks', 'hex')).toEqual( | ||
'9fed463e7c26c0a742b137234e9bbea5fd7beacfa959ca5d54a57e7f41fa2255' | ||
) | ||
}) | ||
|
||
it('should produce correct sha256 hashes of a string (hex)', () => { | ||
expect(sha256digest('chancellor on the brink of second bailout for banks')).toEqual( | ||
Buffer.from('9fed463e7c26c0a742b137234e9bbea5fd7beacfa959ca5d54a57e7f41fa2255', 'hex') | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import crypto from 'crypto' | ||
import { createHash } from 'crypto' | ||
|
||
/** | ||
* sha256digest - Generates a digest of the `message` | ||
* sha256digest - Generates a digest of the `message`(hex) | ||
* | ||
* @param {string} message message to hash | ||
* @returns {string} sha256 hex hash of a `message` | ||
* @param {string} encoding Endoding to output | ||
* @returns {string|Buffer} sha256 hash of a message`. If encoding is provided a string will be returned; | ||
* otherwise a Buffer is returned. | ||
*/ | ||
export default function sha256digest(message) { | ||
return crypto | ||
.createHash('sha256') | ||
export const sha256digest = (message, encoding) => | ||
createHash('sha256') | ||
.update(message) | ||
.digest('hex') | ||
} | ||
.digest(encoding) |