UNPKG

1.09 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const bcrypto_1 = require("bcrypto");
4class HashAlgorithms {
5 static ripemd160(buffer) {
6 return bcrypto_1.RIPEMD160.digest(this.bufferize(buffer));
7 }
8 static sha1(buffer) {
9 return bcrypto_1.SHA1.digest(this.bufferize(buffer));
10 }
11 static sha256(buffer) {
12 if (Array.isArray(buffer)) {
13 let sha256 = bcrypto_1.SHA256.ctx;
14 sha256.init();
15 for (const element of buffer) {
16 sha256 = sha256.update(element);
17 }
18 return sha256.final();
19 }
20 return bcrypto_1.SHA256.digest(this.bufferize(buffer));
21 }
22 static hash160(buffer) {
23 return bcrypto_1.Hash160.digest(this.bufferize(buffer));
24 }
25 static hash256(buffer) {
26 return bcrypto_1.Hash256.digest(this.bufferize(buffer));
27 }
28 static bufferize(buffer) {
29 return buffer instanceof Buffer ? buffer : Buffer.from(buffer);
30 }
31}
32exports.HashAlgorithms = HashAlgorithms;
33//# sourceMappingURL=hash-algorithms.js.map
\No newline at end of file