From 1b3825ed73772b7b9696cdced0ac933514b6673d Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Fri, 18 Aug 2023 23:15:01 -0700 Subject: [PATCH] Initial commit --- README.md | 3 +++ index.html | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ keccak256.js | 6 ++++++ 3 files changed, 69 insertions(+) create mode 100644 README.md create mode 100644 index.html create mode 100644 keccak256.js diff --git a/README.md b/README.md new file mode 100644 index 0000000..366004c --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# ERC-165 Calculator + +Minimal web app to calculate [ERC-165](https://eips.ethereum.org/EIPS/eip-165) interface IDs from Solidity functions. diff --git a/index.html b/index.html new file mode 100644 index 0000000..8862a43 --- /dev/null +++ b/index.html @@ -0,0 +1,60 @@ + + + + + + + + ERC-165 Calculator + + + + +

ERC-165 Calculator

+ +
+ + + + + + +
+ + + + + \ No newline at end of file diff --git a/keccak256.js b/keccak256.js new file mode 100644 index 0000000..0918a76 --- /dev/null +++ b/keccak256.js @@ -0,0 +1,6 @@ +function k(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function F(t){if(typeof t!="boolean")throw new Error(`Expected boolean, not ${t}`)}function m(t,...e){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function X(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");k(t.outputLen),k(t.blockLen)}function $(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function R(t,e){m(t);let o=e.outputLen;if(t.length>L&w)}:{h:Number(t>>L&w)|0,l:Number(t&w)|0}}function M(t,e=!1){let o=new Uint32Array(t.length),n=new Uint32Array(t.length);for(let r=0;rBigInt(t>>>0)<>>0),W=(t,e,o)=>t>>>o,v=(t,e,o)=>t<<32-o|e>>>o,C=(t,e,o)=>t>>>o|e<<32-o,D=(t,e,o)=>t<<32-o|e>>>o,q=(t,e,o)=>t<<64-o|e>>>o-32,z=(t,e,o)=>t>>>o-32|e<<64-o,G=(t,e)=>e,J=(t,e)=>t,K=(t,e,o)=>t<>>32-o,Q=(t,e,o)=>e<>>32-o,Y=(t,e,o)=>e<>>64-o,Z=(t,e,o)=>t<>>64-o;function tt(t,e,o,n){let r=(e>>>0)+(n>>>0);return{h:t+o+(r/2**32|0)|0,l:r|0}}var et=(t,e,o)=>(t>>>0)+(e>>>0)+(o>>>0),ot=(t,e,o,n)=>e+o+n+(t/2**32|0)|0,nt=(t,e,o,n)=>(t>>>0)+(e>>>0)+(o>>>0)+(n>>>0),rt=(t,e,o,n,r)=>e+o+n+r+(t/2**32|0)|0,st=(t,e,o,n,r)=>(t>>>0)+(e>>>0)+(o>>>0)+(n>>>0)+(r>>>0),it=(t,e,o,n,r,i)=>e+o+n+r+i+(t/2**32|0)|0,ct={fromBig:O,split:M,toBig:P,shrSH:W,shrSL:v,rotrSH:C,rotrSL:D,rotrBH:q,rotrBL:z,rotr32H:G,rotr32L:J,rotlSH:K,rotlSL:Q,rotlBH:Y,rotlBL:Z,add:tt,add3L:et,add3H:ot,add4L:nt,add4H:rt,add5H:it,add5L:st},h=ct;var ft=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var ut=t=>t instanceof Uint8Array;var A=t=>new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4));var pt=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!pt)throw new Error("Non little-endian hardware is not supported");var Bt=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function ht(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function g(t){if(typeof t=="string"&&(t=ht(t)),!ut(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}var y=class{clone(){return this._cloneInto()}};function B(t){let e=n=>t().update(g(n)).digest(),o=t();return e.outputLen=o.outputLen,e.blockLen=o.blockLen,e.create=()=>t(),e}function I(t){let e=(n,r)=>t(r).update(g(n)).digest(),o=t({});return e.outputLen=o.outputLen,e.blockLen=o.blockLen,e.create=n=>t(n),e}var[H,U,S]=[[],[],[]],lt=BigInt(0),l=BigInt(1),at=BigInt(2),dt=BigInt(7),xt=BigInt(256),wt=BigInt(113);for(let t=0,e=l,o=1,n=0;t<24;t++){[o,n]=[n,(2*o+3*n)%5],H.push(2*(5*n+o)),U.push((t+1)*(t+2)/2%64);let r=lt;for(let i=0;i<7;i++)e=(e<>dt)*wt)%xt,e&at&&(r^=l<<(l<o>32?h.rotlBH(t,e,o):h.rotlSH(t,e,o),_=(t,e,o)=>o>32?h.rotlBL(t,e,o):h.rotlSL(t,e,o);function bt(t,e=24){let o=new Uint32Array(10);for(let n=24-e;n<24;n++){for(let s=0;s<10;s++)o[s]=t[s]^t[s+10]^t[s+20]^t[s+30]^t[s+40];for(let s=0;s<10;s+=2){let c=(s+8)%10,a=(s+2)%10,d=o[a],u=o[a+1],j=E(d,u,1)^o[c],N=_(d,u,1)^o[c+1];for(let x=0;x<50;x+=10)t[s+x]^=j,t[s+x+1]^=N}let r=t[2],i=t[3];for(let s=0;s<24;s++){let c=U[s],a=E(r,i,c),d=_(r,i,c),u=H[s];r=t[u],i=t[u+1],t[u]=a,t[u+1]=d}for(let s=0;s<50;s+=10){for(let c=0;c<10;c++)o[c]=t[s+c];for(let c=0;c<10;c++)t[s+c]^=~o[(c+2)%10]&o[(c+4)%10]}t[0]^=yt[n],t[1]^=gt[n]}o.fill(0)}var b=class t extends y{constructor(e,o,n,r=!1,i=24){if(super(),this.blockLen=e,this.suffix=o,this.outputLen=n,this.enableXOF=r,this.rounds=i,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,p.number(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=A(this.state)}keccak(){bt(this.state32,this.rounds),this.posOut=0,this.pos=0}update(e){p.exists(this);let{blockLen:o,state:n}=this;e=g(e);let r=e.length;for(let i=0;i=n&&this.keccak();let s=Math.min(n-this.posOut,i-r);e.set(o.subarray(this.posOut,this.posOut+s),r),this.posOut+=s,r+=s}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return p.number(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(p.output(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){let{blockLen:o,suffix:n,outputLen:r,rounds:i,enableXOF:s}=this;return e||(e=new t(o,n,r,s,i)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=i,e.suffix=n,e.outputLen=r,e.enableXOF=s,e.destroyed=this.destroyed,e}},f=(t,e,o)=>B(()=>new b(e,t,o)),Ut=f(6,144,224/8),St=f(6,136,256/8),Tt=f(6,104,384/8),jt=f(6,72,512/8),Nt=f(1,144,224/8),kt=f(1,136,256/8),Ft=f(1,104,384/8),Xt=f(1,72,512/8),T=(t,e,o)=>I((n={})=>new b(e,t,n.dkLen===void 0?o:n.dkLen,!0)),$t=T(31,168,128/8),Rt=T(31,136,256/8);export{kt as keccak256}; +/*! Bundled license information: + +@noble/hashes/esm/utils.js: + (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *) +*/ -- 2.47.3