ripemd160-min
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -78,5 +78,13 @@ "use strict"; | ||
} | ||
function createArray(size) { | ||
if (typeof Uint8Array !== 'undefined') { | ||
return new Uint8Array(size); | ||
} | ||
else { | ||
return new Array(size); | ||
} | ||
} | ||
class RIPEMD160 { | ||
constructor() { | ||
this._block = new Array(64); | ||
this._block = createArray(64); | ||
this._blockSize = 64; | ||
@@ -178,12 +186,2 @@ this._blockOffset = 0; | ||
this._finalized = true; | ||
const digest = this._digest(); | ||
// reset state | ||
this._block.fill(0); | ||
this._blockOffset = 0; | ||
for (let i = 0; i < 4; ++i) { | ||
this._length[i] = 0; | ||
} | ||
return digest; | ||
} | ||
_digest() { | ||
// create padding and handle blocks | ||
@@ -201,3 +199,3 @@ this._block[this._blockOffset++] = 0x80; | ||
// produce result | ||
const buffer = new Array(20); | ||
const buffer = createArray(20); | ||
writeInt32LE(buffer, this._a, 0); | ||
@@ -208,2 +206,8 @@ writeInt32LE(buffer, this._b, 4); | ||
writeInt32LE(buffer, this._e, 16); | ||
// reset state | ||
this._block.fill(0); | ||
this._blockOffset = 0; | ||
for (let i = 0; i < 4; ++i) { | ||
this._length[i] = 0; | ||
} | ||
return buffer; | ||
@@ -210,0 +214,0 @@ } |
@@ -76,5 +76,13 @@ // Extracted from https://github.com/crypto-browserify/ripemd160 | ||
} | ||
function createArray(size) { | ||
if (typeof Uint8Array !== 'undefined') { | ||
return new Uint8Array(size); | ||
} | ||
else { | ||
return new Array(size); | ||
} | ||
} | ||
export default class RIPEMD160 { | ||
constructor() { | ||
this._block = new Array(64); | ||
this._block = createArray(64); | ||
this._blockSize = 64; | ||
@@ -176,12 +184,2 @@ this._blockOffset = 0; | ||
this._finalized = true; | ||
const digest = this._digest(); | ||
// reset state | ||
this._block.fill(0); | ||
this._blockOffset = 0; | ||
for (let i = 0; i < 4; ++i) { | ||
this._length[i] = 0; | ||
} | ||
return digest; | ||
} | ||
_digest() { | ||
// create padding and handle blocks | ||
@@ -199,3 +197,3 @@ this._block[this._blockOffset++] = 0x80; | ||
// produce result | ||
const buffer = new Array(20); | ||
const buffer = createArray(20); | ||
writeInt32LE(buffer, this._a, 0); | ||
@@ -206,4 +204,10 @@ writeInt32LE(buffer, this._b, 4); | ||
writeInt32LE(buffer, this._e, 16); | ||
// reset state | ||
this._block.fill(0); | ||
this._blockOffset = 0; | ||
for (let i = 0; i < 4; ++i) { | ||
this._length[i] = 0; | ||
} | ||
return buffer; | ||
} | ||
} |
@@ -0,18 +1,18 @@ | ||
export declare type ByteArray = number[] | Uint8Array; | ||
export default class RIPEMD160 { | ||
_block: number[]; | ||
_blockSize: number; | ||
_blockOffset: number; | ||
_length: number[]; | ||
_finalized: boolean; | ||
_a: number; | ||
_b: number; | ||
_c: number; | ||
_d: number; | ||
_e: number; | ||
private _block; | ||
private _blockSize; | ||
private _blockOffset; | ||
private _length; | ||
private _finalized; | ||
private _a; | ||
private _b; | ||
private _c; | ||
private _d; | ||
private _e; | ||
constructor(); | ||
update(data: number[]): this; | ||
_update(): void; | ||
digest(): number[]; | ||
_digest(): number[]; | ||
update(data: ByteArray): this; | ||
private _update; | ||
digest(): ByteArray; | ||
} | ||
//# sourceMappingURL=index.d.ts.map |
@@ -87,5 +87,13 @@ // Extracted from https://github.com/crypto-browserify/ripemd160 | ||
} | ||
function createArray(size) { | ||
if (typeof Uint8Array !== 'undefined') { | ||
return new Uint8Array(size); | ||
} | ||
else { | ||
return new Array(size); | ||
} | ||
} | ||
var RIPEMD160 = /** @class */ (function () { | ||
function RIPEMD160() { | ||
this._block = new Array(64); | ||
this._block = createArray(64); | ||
this._blockSize = 64; | ||
@@ -187,12 +195,2 @@ this._blockOffset = 0; | ||
this._finalized = true; | ||
var digest = this._digest(); | ||
// reset state | ||
this._block.fill(0); | ||
this._blockOffset = 0; | ||
for (var i = 0; i < 4; ++i) { | ||
this._length[i] = 0; | ||
} | ||
return digest; | ||
}; | ||
RIPEMD160.prototype._digest = function () { | ||
// create padding and handle blocks | ||
@@ -210,3 +208,3 @@ this._block[this._blockOffset++] = 0x80; | ||
// produce result | ||
var buffer = new Array(20); | ||
var buffer = createArray(20); | ||
writeInt32LE(buffer, this._a, 0); | ||
@@ -217,2 +215,8 @@ writeInt32LE(buffer, this._b, 4); | ||
writeInt32LE(buffer, this._e, 16); | ||
// reset state | ||
this._block.fill(0); | ||
this._blockOffset = 0; | ||
for (var i = 0; i < 4; ++i) { | ||
this._length[i] = 0; | ||
} | ||
return buffer; | ||
@@ -219,0 +223,0 @@ }; |
{ | ||
"name": "ripemd160-min", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "A minimal 0 dependency RIPEMD160 hash lib", | ||
@@ -5,0 +5,0 @@ "keywords": ["ripemd160", "ripe160", "rmd160", "ripemd"], |
@@ -74,3 +74,3 @@ // Extracted from https://github.com/crypto-browserify/ripemd160 | ||
function readInt32LE(buffer: number[], offset: number): number { | ||
function readInt32LE(buffer: ByteArray, offset: number): number { | ||
offset >>>= 0 | ||
@@ -83,3 +83,3 @@ return (buffer[offset]) | ||
function writeUInt32LE(buffer: number[], value: number, offset: number): number { | ||
function writeUInt32LE(buffer: ByteArray, value: number, offset: number): number { | ||
value = +value | ||
@@ -94,3 +94,3 @@ offset >>>= 0 | ||
function writeInt32LE(buffer: number[], value: number, offset: number): number { | ||
function writeInt32LE(buffer: ByteArray, value: number, offset: number): number { | ||
value = +value | ||
@@ -105,25 +105,35 @@ offset >>>= 0 | ||
function createArray(size: number): ByteArray { | ||
if (typeof Uint8Array !== 'undefined') { | ||
return new Uint8Array(size) | ||
} else { | ||
return new Array<number>(size) | ||
} | ||
} | ||
export type ByteArray = number[] | Uint8Array | ||
export default class RIPEMD160 { | ||
_block: number[]; | ||
private _block: ByteArray; | ||
_blockSize: number; | ||
private _blockSize: number; | ||
_blockOffset: number; | ||
private _blockOffset: number; | ||
_length: number[]; | ||
private _length: number[]; | ||
_finalized: boolean; | ||
private _finalized: boolean; | ||
_a: number; | ||
private _a: number; | ||
_b: number; | ||
private _b: number; | ||
_c: number; | ||
private _c: number; | ||
_d: number; | ||
private _d: number; | ||
_e: number; | ||
private _e: number; | ||
constructor() { | ||
this._block = new Array<number>(64) | ||
this._block = createArray(64) | ||
this._blockSize = 64 | ||
@@ -141,3 +151,3 @@ this._blockOffset = 0 | ||
update(data: number[]) { | ||
update(data: ByteArray) { | ||
if (this._finalized) throw new Error('Digest already called') | ||
@@ -165,3 +175,3 @@ | ||
_update() { | ||
private _update() { | ||
const words = ARRAY16 | ||
@@ -227,3 +237,3 @@ for (let j = 0; j < 16; ++j) { | ||
digest() { | ||
digest(): ByteArray { | ||
if (this._finalized) { | ||
@@ -235,15 +245,2 @@ throw new Error('Digest already called') | ||
const digest = this._digest() | ||
// reset state | ||
this._block.fill(0) | ||
this._blockOffset = 0 | ||
for (let i = 0; i < 4; ++i) { | ||
this._length[i] = 0 | ||
} | ||
return digest | ||
} | ||
_digest() { | ||
// create padding and handle blocks | ||
@@ -263,3 +260,3 @@ this._block[this._blockOffset++] = 0x80 | ||
// produce result | ||
const buffer = new Array<number>(20) | ||
const buffer = createArray(20) | ||
writeInt32LE(buffer, this._a, 0) | ||
@@ -270,4 +267,14 @@ writeInt32LE(buffer, this._b, 4) | ||
writeInt32LE(buffer, this._e, 16) | ||
// reset state | ||
this._block.fill(0) | ||
this._blockOffset = 0 | ||
for (let i = 0; i < 4; ++i) { | ||
this._length[i] = 0 | ||
} | ||
return buffer | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35233
898