UNPKG

@etherna/sdk-js

Version:

Etherna SDKs for operations on the network

44 lines (43 loc) 1.68 kB
import { H as c, h as u, t as H, e as o, b as l } from "./utils-nt_aP_dH.mjs"; class r extends c { constructor(t, i) { super(), this.finished = !1, this.destroyed = !1, u(t); const h = H(i); if (this.iHash = t.create(), typeof this.iHash.update != "function") throw new Error("Expected instance of class which extends utils.Hash"); this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen; const a = this.blockLen, s = new Uint8Array(a); s.set(h.length > a ? t.create().update(h).digest() : h); for (let e = 0; e < s.length; e++) s[e] ^= 54; this.iHash.update(s), this.oHash = t.create(); for (let e = 0; e < s.length; e++) s[e] ^= 106; this.oHash.update(s), s.fill(0); } update(t) { return o(this), this.iHash.update(t), this; } digestInto(t) { o(this), l(t, this.outputLen), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy(); } digest() { const t = new Uint8Array(this.oHash.outputLen); return this.digestInto(t), t; } _cloneInto(t) { t || (t = Object.create(Object.getPrototypeOf(this), {})); const { oHash: i, iHash: h, finished: a, destroyed: s, blockLen: e, outputLen: d } = this; return t = t, t.finished = a, t.destroyed = s, t.blockLen = e, t.outputLen = d, t.oHash = i._cloneInto(t.oHash), t.iHash = h._cloneInto(t.iHash), t; } destroy() { this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy(); } } const p = (n, t, i) => new r(n, t).update(i).digest(); p.create = (n, t) => new r(n, t); export { r as HMAC, p as hmac }; //# sourceMappingURL=hmac-CrI8fGKH.mjs.map