Skip to content

Commit

Permalink
pass Buffer instance to create-hash; refs browserify/hash-base#15
Browse files Browse the repository at this point in the history
  • Loading branch information
jordaaash committed Jun 2, 2020
1 parent 57541e5 commit 37fa37e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import createHash from 'create-hash';
* @returns hashed bytes
*/
export function sha256 (bytes: Bytes): Bytes {
const buffer = createHash('sha256').update(bytes).digest();
const buffer1 = (bytes instanceof Buffer) ? bytes : Buffer.from(bytes);
const buffer2 = createHash('sha256').update(buffer1).digest();

return bufferToBytes(buffer);
return bufferToBytes(buffer2);
}

/**
Expand All @@ -23,7 +24,8 @@ export function sha256 (bytes: Bytes): Bytes {
* @returns hashed bytes
*/
export function ripemd160 (bytes: Bytes): Bytes {
const buffer = createHash('ripemd160').update(bytes).digest();
const buffer1 = (bytes instanceof Buffer) ? bytes : Buffer.from(bytes);
const buffer2 = createHash('ripemd160').update(buffer1).digest();

return bufferToBytes(buffer);
return bufferToBytes(buffer2);
}

0 comments on commit 37fa37e

Please sign in to comment.