Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name HashBrown 3
- // @author gimmickCellar
- // @description hashing for owot and any secure nwot
- // @match *://*/*
- // ==/UserScript==
- //i am so sorry for the state of this codebase
- var privateKey; //prevent error
- var publicKeyBase64;
- window.hashcache = []; //also prevent error
- async function startCryptoApi() { //mostly lifted from hb2, this is really the only segment that is, because this is kinda the only way to do it
- var storedKeys = localStorage.getItem('hb3'); //ok so this is the local storage. it stores, locally. wow.
- if (storedKeys) {
- var keys = JSON.parse(storedKeys); //Jason
- privateKey = await crypto.subtle.importKey("jwk", keys.priv||keys.jwkpr, {name:"ECDSA",namedCurve:"P-256"},true,["sign"]); //just sign, please!
- publicKeyBase64 = keys.pubBase64;
- } else {
- var pair = await crypto.subtle.generateKey({name:"ECDSA",namedCurve:"P-256"},true,["sign","verify"]); //sign AND verify, please
- privateKey = pair.privateKey;
- var pub = pair.publicKey;
- var jwkpr = await crypto.subtle.exportKey("jwk",privateKey);
- var jwkpu = await crypto.subtle.exportKey("jwk",pub);
- var Pub = await crypto.subtle.exportKey("raw",pub);
- publicKeyBase64 = btoa(String.fromCharCode(...new Uint8Array(Pub)));
- localStorage.setItem('hb3',JSON.stringify({jwkpr,jwkpu,pubBase64:publicKeyBase64})); //local storage
- }
- }
- w.tileToChar=(tileX,tileY,charX,charY)=>{ //helper, available to other scripts but why would you
- var x = tileX * 16 + charX;
- var y = tileY * 8 + charY;
- return {x:x,y:y}; //x is x and y is y!
- };
- w.TemperTantrum=()=>{return new Error("VIGUEGYU8ZVGJHVTJYZVGYJA YOU LIED YOU LIED YOU LIED")}; // literally just uq
- async function url(item){
- if(!item)throw w.TemperTantrum(); // average owot user
- var x=item[0];var y=item[1];var chara=item[2];var d=item[3];var u=item[4];var wd=item[5]; // chara and wd gaster in the same line
- // ok but seriously wd is world, chara is character, d is deco and u is username
- var msg=`${wd},${x},${y},${chara},${d},${u}`;
- var enc=new TextEncoder().encode(msg);
- var sigBuf=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},privateKey,enc);
- var sigArr=new Uint8Array(sigBuf);
- var sigB64=btoa(String.fromCharCode(...sigArr));
- var verifier="https://gimmickcellar.nekoweb.org/verifyhash2.html"; //change this line to use your gerifier
- var ew=encodeURIComponent(wd);
- var eu=encodeURIComponent(u);
- var es=encodeURIComponent(sigB64).replace(/\+/g,'%2B');
- var ep=encodeURIComponent(publicKeyBase64).replace(/\+/g,'%2B');
- return `${verifier}?w=${ew}&x=${x}&y=${y}&c=${chara}&d=${d}&u=${eu}&sig=${es}&pub=${ep}`;
- }
- (()=>{
- w.on("write",e=>{
- if(e.char==="\x08"||e.char===" "||e.char==="\xa0")return;
- var u=state.userModel.username; //you.
- var wd=state.worldModel.name || "Main"; //wd gasters.,,.,,,, (seriously, this is just compat with slopbrown 2 also for world checking)
- var id=nextObjId-1; //write id
- var coords=w.tileToChar(e.tileX,e.tileY,e.charX,e.charY);
- var x=coords.x;
- var y=coords.y;
- var tx=e.tileX;
- var ty=e.tileY;
- var cx=e.charX;
- var cy=e.charY; //just for safe keeping
- var chara=e.char.codePointAt(0);
- var d=0; //todo: proper text deco support, rn is 0 to have compat with the vibecoded slop hb2
- window.hashcache[id]=[x,y,chara,d,u,wd,tx,ty,cx,cy];
- });
- w.on("writeResponse",e=>{
- if((!e.accepted)||window["hashn'tbrown"])return; // hash brown or hashn't brown?
- e.accepted.forEach(async id=>{
- var a=window.hashcache[id]; //hashcache is cache for hashing
- if(!a)return;
- var linkVal=await url(a); //url makes a url
- network.link({tileX:a[6],tileY:a[7],charX:a[8],charY:a[9]},"url",{url:linkVal}); //a is a weirdly arranged array if you didnt see the above
- delete window.hashcache[id];
- });
- });
- menu.addCheckboxOption("Disable HashBrown 3",()=>{window["hashn'tbrown"]=true},()=>{window["hashn'tbrown"]=false}) //todo: make this save
- startCryptoApi(); //starts crypto api
- })()
Add Comment
Please, Sign In to add comment