50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.Sha512 = exports.Sha256 = void 0;
|
|
exports.sha256 = sha256;
|
|
exports.sha512 = sha512;
|
|
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
const utils_1 = require("./utils");
|
|
class Sha256 {
|
|
blockSize = 512 / 8;
|
|
impl = sha2_js_1.sha256.create();
|
|
constructor(firstData) {
|
|
if (firstData) {
|
|
this.update(firstData);
|
|
}
|
|
}
|
|
update(data) {
|
|
this.impl.update((0, utils_1.toRealUint8Array)(data));
|
|
return this;
|
|
}
|
|
digest() {
|
|
return this.impl.digest();
|
|
}
|
|
}
|
|
exports.Sha256 = Sha256;
|
|
/** Convenience function equivalent to `new Sha256(data).digest()` */
|
|
function sha256(data) {
|
|
return new Sha256(data).digest();
|
|
}
|
|
class Sha512 {
|
|
blockSize = 1024 / 8;
|
|
impl = sha2_js_1.sha512.create();
|
|
constructor(firstData) {
|
|
if (firstData) {
|
|
this.update(firstData);
|
|
}
|
|
}
|
|
update(data) {
|
|
this.impl.update((0, utils_1.toRealUint8Array)(data));
|
|
return this;
|
|
}
|
|
digest() {
|
|
return this.impl.digest();
|
|
}
|
|
}
|
|
exports.Sha512 = Sha512;
|
|
/** Convenience function equivalent to `new Sha512(data).digest()` */
|
|
function sha512(data) {
|
|
return new Sha512(data).digest();
|
|
}
|
|
//# sourceMappingURL=sha.js.map
|