rwadurian/tools/mnemonic-test/node_modules/hash-wasm/dist/hmac.umd.min.js

8 lines
2.0 KiB
JavaScript

/*!
* hash-wasm (https://www.npmjs.com/package/hash-wasm)
* (c) Dani Biro
* @license MIT
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).hashwasm=e.hashwasm||{})}(this,(function(e){"use strict";var t;const n="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:global,r=null!==(t=n.Buffer)&&void 0!==t?t:null,i=n.TextEncoder?new n.TextEncoder:null,f=null!==r?e=>{if("string"==typeof e){const t=r.from(e,"utf8");return new Uint8Array(t.buffer,t.byteOffset,t.length)}if(r.isBuffer(e))return new Uint8Array(e.buffer,e.byteOffset,e.length);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Invalid data type!")}:e=>{if("string"==typeof e)return i.encode(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Invalid data type!")},o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(256);for(let e=0;e<o.length;e++)s[o.charCodeAt(e)]=e;function a(e,t){e.init();const{blockSize:n}=e,r=function(e,t){const{blockSize:n}=e,r=f(t);if(r.length>n){e.update(r);const t=e.digest("binary");return e.init(),t}return new Uint8Array(r.buffer,r.byteOffset,r.length)}(e,t),i=new Uint8Array(n);i.set(r);const o=new Uint8Array(n);for(let e=0;e<n;e++){const t=i[e];o[e]=92^t,i[e]=54^t}e.update(i);const s={init:()=>(e.init(),e.update(i),s),update:t=>(e.update(t),s),digest:t=>{const n=e.digest("binary");return e.init(),e.update(o),e.update(n),e.digest(t)},save:()=>{throw new Error("save() not supported")},load:()=>{throw new Error("load() not supported")},blockSize:e.blockSize,digestSize:e.digestSize};return s}e.createHMAC=function(e,t){if(!e||!e.then)throw new Error('Invalid hash function is provided! Usage: createHMAC(createMD5(), "key").');return e.then((e=>a(e,t)))}}));