UNPKG

@hicaru/ripemd160.js

Version:

A pure javascript implementation of ripemd160 hash function.

3 lines (2 loc) 4.95 kB
(function(t,e){typeof exports==="object"&&typeof module!=="undefined"?e(exports):typeof define==="function"&&define.amd?define(["exports"],e):(t=typeof globalThis!=="undefined"?globalThis:t||self,e(t.ripemd={}))})(this,(function(t){"use strict";function e(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e==="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)}function r(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e==="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r}function n(t,e,r){const n=r-e;if(n%4!==0){throw new RangeError("the remainder of the division of len should be zero.")}const i=new Array(n/4);for(let r=0,n=e;r<i.length;r++,n+=4){const e=t[n+3]<<24|t[n+2]<<16|t[n+1]<<8|t[n];i[r]=e>>>0}return i}function i(t,e){return t+e>>>0}function s(t,e){return t<<e|t>>>32-e}function f(t,e,r,n){return t+e+r+n>>>0}function o(t,e,r){return t+e+r>>>0}function h(t){const e=new Array(t.length*4);for(let r=0,n=0;r<t.length;r++,n+=4){const i=t[r];e[n+3]=i>>>24;e[n+2]=i>>>16&255;e[n+1]=i>>>8&255;e[n]=i&255}return e}function l(t){if(Array.isArray(t)){return Array.from(t).slice()}if(!t){return[]}const e=[];for(let r=0;r<t.length;r++){e[r]=t[r]|0}return e}var a,u,c,d,w,p,y,g,m,v,b;const k=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13];const A=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11];const M=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6];const W=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11];function E(t){if(t<=15)return 1352829926;else if(t<=31)return 1548603684;else if(t<=47)return 1836072691;else if(t<=63)return 2053994217;else return 0}function T(t){if(t<=15)return 0;else if(t<=31)return 1518500249;else if(t<=47)return 1859775393;else if(t<=63)return 2400959708;else return 2840853838}function j(t,e,r,n){if(t<=15)return e^r^n;else if(t<=31)return e&r|~e&n;else if(t<=47)return(e|~r)^n;else if(t<=63)return e&n|r&~n;else return e^(r|~n)}class P{constructor(){a.add(this);u.set(this,void 0);c.set(this,512);d.set(this,8);w.set(this,0);p.set(this,e(this,c,"f")/8);y.set(this,e(this,c,"f")/32);g.set(this,[1732584193,4023233417,2562383102,271733878,3285377520])}get blockSize(){return e(this,c,"f")}digest(){this.update(e(this,a,"m",b).call(this));if(e(this,u,"f")===null){throw new Error("pending cannot be null")}return e(this,a,"m",v).call(this)}update(t){t=l(t);if(!e(this,u,"f")){r(this,u,t,"f")}else{r(this,u,e(this,u,"f").concat(t),"f")}r(this,w,e(this,w,"f")+t.length,"f");if(e(this,u,"f").length>=e(this,p,"f")){t=e(this,u,"f");const i=t.length%e(this,p,"f");r(this,u,t.slice(t.length-i,t.length),"f");if(e(this,u,"f").length===0){r(this,u,undefined,"f")}t=n(t,0,t.length-i);for(let r=0;r<t.length;r+=e(this,y,"f")){e(this,a,"m",m).call(this,Array.from(t),r)}}return this}}u=new WeakMap,c=new WeakMap,d=new WeakMap,w=new WeakMap,p=new WeakMap,y=new WeakMap,g=new WeakMap,a=new WeakSet,m=function t(r,n){let h=e(this,g,"f")[0];let l=e(this,g,"f")[1];let a=e(this,g,"f")[2];let u=e(this,g,"f")[3];let c=e(this,g,"f")[4];let d=h;let w=l;let p=a;let y=u;let m=c;for(let t=0;t<80;t++){var v=i(s(f(h,j(t,l,a,u),r[k[t]+n],T(t)),M[t]),c);h=c;c=u;u=s(a,10);a=l;l=v;v=i(s(f(d,j(79-t,w,p,y),r[A[t]+n],E(t)),W[t]),m);d=m;m=y;y=s(p,10);p=w;w=v}v=o(e(this,g,"f")[1],a,y);e(this,g,"f")[1]=o(e(this,g,"f")[2],u,m);e(this,g,"f")[2]=o(e(this,g,"f")[3],c,d);e(this,g,"f")[3]=o(e(this,g,"f")[4],h,w);e(this,g,"f")[4]=o(e(this,g,"f")[0],l,p);e(this,g,"f")[0]=v},v=function t(){return h(e(this,g,"f"))},b=function t(){let r=e(this,w,"f");const n=e(this,p,"f");const i=n-(r+e(this,d,"f"))%n;let s=new Array(i+e(this,d,"f"));s[0]=128;for(var f=1;f<i;f++){s[f]=0}r<<=3;s[f++]=r&255;s[f++]=r>>>8&255;s[f++]=r>>>16&255;s[f++]=r>>>24&255;s[f++]=0;s[f++]=0;s[f++]=0;s[f++]=0;for(let t=8;t<e(this,d,"f");t++){s[f++]=0}return s};t["default"]=P;t.join32=n;t.rotl32=s;t.split32=h;t.sum32=i;t.sum32By3=o;t.sum32By4=f;t.toArray=l;Object.defineProperty(t,"__esModule",{value:true})})); //# sourceMappingURL=index.js.map