</main>
<script type="module">
- const ethers = await import('https://cdn.jsdelivr.net/npm/ethers@6.6.6/+esm');
+ import { keccak256 } from '/keccak256.js';
+
+ function strToArr(str) {
+ return Uint8Array.from(str.substring(2).match(/.{2}/g), v => parseInt(v, 16));
+ }
+
+ function arrToStr(arr) {
+ return `0x${[...arr].map(v => v.toString(16).padStart(2, '0')).join('')}`;
+ }
document.querySelector('form').addEventListener('submit', e => {
e.preventDefault();
const { factory, bytecode, requirement: requirementString, salt: saltString } = Object.fromEntries(new FormData(e.target));
- const hashedBytecode = ethers.keccak256(bytecode); // Hash it once and save for efficiency
+ const hashedBytecode = keccak256(strToArr(bytecode)); // Hash it once and save for efficiency
const requirement = RegExp(requirementString.slice(1, -1));
let salt = BigInt(saltString); // Converted to 0n if blank
while (true) {
const paddedSalt = `0x${salt.toString(16).padStart(64, '0')}`;
- const addr = ethers.getCreate2Address(factory, paddedSalt, hashedBytecode);
+ const addrBytes = new Uint8Array([0xff, ...strToArr(factory), ...strToArr(paddedSalt), ...hashedBytecode]);
+ const addr = `0x${arrToStr(keccak256(addrBytes)).substring(26)}`;
if (requirement.test(addr)) {
document.querySelector('output').innerHTML = `<pre>${JSON.stringify({ factory, paddedSalt, bytecode, addr }, null, 2)}</pre>`;
break;
--- /dev/null
+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<o)throw new Error(`digestInto() expects output buffer of length at least ${o}`)}var V={number:k,bool:F,bytes:m,hash:X,exists:$,output:R},p=V;var w=BigInt(4294967295),L=BigInt(32);function O(t,e=!1){return e?{h:Number(t&w),l:Number(t>>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;r<t.length;r++){let{h:i,l:s}=O(t[r],e);[o[r],n[r]]=[i,s]}return[o,n]}var P=(t,e)=>BigInt(t>>>0)<<L|BigInt(e>>>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<<o|e>>>32-o,Q=(t,e,o)=>e<<o|t>>>32-o,Y=(t,e,o)=>e<<o-32|t>>>64-o,Z=(t,e,o)=>t<<o-32|e>>>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<<l^(e>>dt)*wt)%xt,e&at&&(r^=l<<(l<<BigInt(i))-l);S.push(r)}var[yt,gt]=h.split(S,!0),E=(t,e,o)=>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<r;){let s=Math.min(o-this.pos,r-i);for(let c=0;c<s;c++)n[this.pos++]^=e[i++];this.pos===o&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:o,pos:n,blockLen:r}=this;e[n]^=o,o&128&&n===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){p.exists(this,!1),p.bytes(e),this.finish();let o=this.state,{blockLen:n}=this;for(let r=0,i=e.length;r<i;){this.posOut>=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) *)
+*/