@ibgib/space-gib 0.0.13 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/bootstrap.mjs +25 -23
- package/dist/client/bootstrap.mjs.map +2 -2
- package/dist/client/{chunk-ROJZUPPE.mjs → chunk-AOGR25NW.mjs} +9 -9
- package/dist/client/{chunk-ROJZUPPE.mjs.map → chunk-AOGR25NW.mjs.map} +3 -3
- package/dist/client/{chunk-WJHRARK6.mjs → chunk-SXMTWH6R.mjs} +77 -49
- package/dist/client/{chunk-WJHRARK6.mjs.map → chunk-SXMTWH6R.mjs.map} +3 -3
- package/dist/client/index.mjs +14 -15
- package/dist/client/index.mjs.map +4 -4
- package/dist/client/script.mjs +1 -1
- package/dist/server/server.mjs +2129 -1208
- package/dist/server/server.mjs.map +4 -4
- package/package.json +4 -4
- package/src/client/AUTO-GENERATED-version.mts +1 -1
- package/src/client/bootstrap.mts +4 -0
- package/src/client/ui/shell/space-gib-shell-service.mts +17 -16
- package/src/server/server.mts +6 -0
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
var Ai=Object.defineProperty;var f=(r,t)=>Ai(r,"name",{value:t,configurable:!0});var z=/^[a-zA-Z0-9_\-.]{1,256}$/,Ve=/^[a-zA-Z0-9_]{1,255}$/,qn=/^(\[.+\])?\s?(\(UNEXPECTED\)|\(unexpected\))?(.+)(\([EIWeiw]: [a-fA-F\d]{32}\))(\(UNEXPECTED\)|\(unexpected\))?$/,Hn=/^(\[.+\]).+$/,Xn=/^[0-9a-fA-F]{32}$/,Kn=/^[0-9a-fA-F]{64}$/;var yt="/",Yn="_nonalphanumerics_";var It=!1,Vn=globalThis.crypto,{subtle:Si}=Vn,we={sha_256:"SHA-256",sha_512:"SHA-512"};function v(r){return JSON.parse(JSON.stringify(r))}f(v,"clone");function xe(r){return(r??new Date).toUTCString()}f(xe,"getTimestamp");async function ce({s:r,algorithm:t="SHA-256"}){if(!r)return"";try{let e=Object.values(we);if(!e.includes(t))throw new Error(`Only ${e} implemented (E: 73cb52cd4d7f70c3415fdf695ba6ba23)`);let o=new TextEncoder().encode(r),n=await Si.digest(t,o);return Array.from(new Uint8Array(n)).map(a=>a.toString(16).padStart(2,"0")).join("")}catch(e){throw console.error(m(e.message)),e}}f(ce,"hash");async function F(r=64){let t="";if(r<32)throw new Error("Seed size must be at least 32");if(!globalThis.crypto)throw new Error("Cannot create UUID, as unknown crypto library version. If using node.js, v19+ is required. (E: c02cee3fd8a94f678d3f4ebe9dc49797)");let e=Vn.getRandomValues(new Uint8Array(16));if(t=await ce({s:e.join("")}),!t)throw new Error("Did not create UUID...hmm...");return t}f(F,"getUUID");function H(r){return JSON.stringify(r,null,2)}f(H,"pretty");async function le(r){return new Promise(t=>{setTimeout(()=>{t()},r)})}f(le,"delay");function m(r){return!r&&r!==0?"[error is falsy]":typeof r=="string"?r:typeof r.message=="string"?r.message:typeof r=="number"?JSON.stringify(r):r.error?(console.warn(`[${m.name}] this fn takes the raw error object. no destructure required. change your call from extractErrorMsg({error}) to extractErrorMsg(error). (W: ea49af5fd76d4b80a55a108d73a3e9b4)`),m(r.error)):`[error is not a string and error.message is not a string. typeof error: ${typeof r} (E: d5a7723ca59646838308bc9e53a43134)]`}f(m,"extractErrorMsg");function po({items:r,keyFn:t}){let e=`[${po.name}]`;try{let o={};for(let n=0;n<r.length;n++){let s=r[n],a=t(s);o[a]=[...o[a]??[],s]}return o}catch(o){throw console.error(`${e} ${o.message}`),o}}f(po,"groupBy");function cr({min:r,max:t,chars:e,noSpaces:o}){return r=r??1,t=t??999999999999,e=e??"",o?new RegExp(`^[\\w${e}]{${r},${t}}$`):new RegExp(`^[\\w\\s${e}]{${r},${t}}$`)}f(cr,"getRegExp");function ge(r){let t;if(r){if(t=new Date(r),t.toString()==="Invalid Date")throw new Error(`invalid date created by timestamp (${r}) (E: cbd6aeefe00708184e276ea3c2532b22)`)}else t=new Date;return t.getTime().toString()}f(ge,"getTimestampInTicks");function ho({startDate:r,years:t,months:e,days:o,hours:n,seconds:s}){let a=`[${ho.name}]`;try{return it({startDate:r,years:t,months:e,days:o,hours:n,seconds:s}).toUTCString()}catch(i){throw console.log(`${a} ${i.message}`),i}}f(ho,"getExpirationUTCString");function it({startDate:r,years:t,months:e,days:o,hours:n,seconds:s}){let a=`[${it.name}]`;try{if(!r&&!t&&!e&&!o&&!n&&!s)throw new Error("either startDate or a time interval required. (E: 30248f8b306f443ab036fa8c313c50d8)");r=r?new Date(r):new Date;let i,c;return t?(i=r.getFullYear()+t,c=r.setFullYear(i),it({startDate:new Date(c),months:e,days:o,hours:n,seconds:s})):e?(i=r.getMonth()+e,c=r.setMonth(i),it({startDate:new Date(c),years:t,days:o,hours:n,seconds:s})):o?(i=r.getDate()+o,c=r.setDate(i),it({startDate:new Date(c),years:t,months:e,hours:n,seconds:s})):n?(i=r.getHours()+n,c=r.setHours(i),it({startDate:new Date(c),years:t,months:e,days:o,seconds:s})):s?(i=r.getSeconds()+s,c=r.setSeconds(i),it({startDate:new Date(c),years:t,months:e,days:o,hours:n})):r}catch(i){throw console.log(`${a} ${i.message}`),i}}f(it,"addTimeToDate");function go({expirationTimestampUTC:r}){let t=`[${go.name}]`;try{if(!r)throw new Error("expirationTimestampUTC required (E: 5eeb1e29f93d64f70c71a8112080a222)");let e=new Date(r);if(e.toUTCString()==="Invalid Date")throw new Error(`invalid expirationTimestampUTC: ${r} (E: 66a1a165bcf1f9336fe78856ab777822)`);return e<new Date}catch(e){throw console.error(`${t} ${e.message}`),e}}f(go,"isExpired");function lr(r){return Array.from(new Set(r))}f(lr,"unique");function Eo({obj:r,value:t,path:e,pathDelimiter:o,logalot:n}){let s=`[${Eo.name}]`;try{if(n&&console.log(`${s} starting...`),!r)throw new Error("obj required (E: 6a9dd32a361476e80b1bf7b91ec50522)");if(typeof r!="object")throw new Error("obj must be type 'object' (E: 66fdc289b32c06492bd95f5d266e6a22)");if(!e)throw new Error("path required (at the very least should be the key in the root obj.) (E: fc779e7794ead8a0b44e5f2e776b0e22)");o=o||yt;let a=r,i=e.split(o).filter(l=>!!l),c=i.pop();i.forEach(l=>{let d=a[l];if(d){if(typeof d!="object")throw new Error(`invalid path into object. Each step along the path must be typeof === 'object', but typeof targetObj["${l}"] === ${typeof d}. (value: ${d}) (E: 38cf29c5f624a40b4b56502c2ec39d22)`)}else a[l]={};a=a[l]}),a[c]=t}catch(a){throw console.error(`${s} ${a.message}`),a}finally{n&&console.log(`${s} complete.`)}}f(Eo,"patchObject");async function Ct({n:r}){let t=`[${Ct.name}]`;try{It&&console.log(`${t} starting...`);let e=[];for(let o=0;o<r;o++){let n=await F();e.push(n.substring(0,16))}return e}catch(e){throw console.error(`${t} ${e.message}`),e}finally{It&&console.log(`${t} complete.`)}}f(Ct,"getIdPool");function xi({text:r,length:t,keepLiterals:e=["-"],replaceMap:o}){let n=`[${xi.name}]`;try{if(It&&console.log(`${n} starting... (I: 27437e312e5aa621adfebb84e059c822)`),!r)throw new Error("text required (E: 87e0493613c8b30dfade83e1d2862a22)");let s=r,a={};e=e??[];for(let c=0;c<e.length;c++){let l=e[c],d;do d=Wn({count:10});while(d.includes(l)||l.includes(d)||r.includes(d));if(s.includes(l))for(a[d]=l;s.includes(l);)s=s.replace(l,d)}if(o&&Object.keys(o).length>0)for(let c=0;c<Object.keys(o).length;c++){let l=Object.keys(o)[c],d=o[l];for(;s.includes(l);)s=s.replace(l,d)}s=s.replace(/\W/g,"");let i=Object.keys(a);for(let c=0;c<i.length;c++){let l=i[c];for(;s.includes(l);)s=s.replace(l,a[l])}return t&&t>0&&s.length>t&&(It&&console.log(`${n} curtailing length (I: d7a28e05daa5979c7686b4c1cf519b23)`),s=s.substring(0,t)),s.length===0&&(s=Yn),s}catch(s){throw console.error(`${n} ${s.message}`),s}finally{It&&console.log(`${n} complete.`)}}f(xi,"getSaferSubstring");function Oi({x:r}){if((r??[]).length===0)return;let t=Math.floor(Math.random()*r.length);return r[t]}f(Oi,"pickRandom");function Wn({count:r}){let t=`${Wn.name}]`;try{if(!Number.isInteger(r))throw new Error("count required to be a number. (E: c0a21d884ebd9afc4b2e8025207e0522)");let e="";for(let o=0;o<r;o++)e+=Oi({x:"a b c d e f g h i j k l m n o p q r s t u v w x y z".split(" ")});if(e.length!==r)throw new Error(`${t} (UNEXPECTED) result.length !== count ? (E: 9bec4ec8f78610d8055e565415392a22)`);return e}catch(e){throw console.error(`${t} ${e.message}`),e}finally{It&&console.log(`${t} complete.`)}}f(Wn,"pickRandom_Letters");function _t({dominant:r,recessive:t}){let e=`[${_t.name}]`;try{if(Array.isArray(r)&&Array.isArray(t)){let o=v(r),n=!1;return t.forEach(s=>{if(typeof s=="string")o.includes(s)||o.push(s);else{n||(console.warn(`${e} merging arrays of non-string elements. (W: d8ab113064834abc8eb5fe6c4cf87ba3)`),n=!0);let a=JSON.stringify(s);o.some(i=>JSON.stringify(i)===a)||o.push(s)}}),o}else if(typeof r=="object"&&typeof t=="object"){let o={...t},n=Object.keys(r),s=Object.keys(t);return n.forEach(a=>{s.includes(a)?Array.isArray(r[a])&&Array.isArray(t[a])?o[a]=_t({dominant:r[a],recessive:t[a]}):r[a]&&!Array.isArray(r[a])&&typeof r[a]=="object"&&t[a]&&!Array.isArray(t[a])&&typeof t[a]=="object"?o[a]=_t({dominant:r[a],recessive:t[a]}):o[a]=r[a]:o[a]=r[a]}),o}else return console.warn(`${e} unknown values or value types do not match. Both should either be an array or map. Dominant one wins categorically without any merging. (W: 3690ea19b81a4b89b98c1940637df62c)`),r}catch(o){throw console.error(`${e} ${o.message}`),o}}f(_t,"mergeMapsOrArrays_Naive");var Di=globalThis.crypto,{subtle:Zn}=Di,Qn=new Array(256);for(let r=0;r<256;++r)Qn[r]=r.toString(16).padStart(2,"0");function es(r){let t=new Uint8Array(r),e="";for(let o=0;o<t.length;o++)e+=Qn[t[o]];return e}f(es,"bufToHex");function Mt(r){if(r===null||typeof r!="object")return r;if(Array.isArray(r))return r.map(o=>Mt(o));let t={},e=Object.keys(r).sort();for(let o of e){let n=r[o];n!==void 0&&(t[o]=Mt(n))}return t}f(Mt,"toNormalizedForHashing");async function Ut(r){if(!r)return"";let t=new TextEncoder().encode(r),e=await Zn.digest("SHA-256",t);return es(e)}f(Ut,"hashToHex");async function vi(r,t){let e;if(r){let n=new TextEncoder().encode(r);e=new Uint8Array(n.length+t.length),e.set(n),e.set(t,n.length)}else e=t;let o=await Zn.digest("SHA-256",e);return es(o)}f(vi,"hashToHex_Uint8Array");var Ni=!1,dr=0,zn=0;async function Jn(r,t=""){let e=t||"",o=r.ib,n=r.data,s=r.rel8ns,a=Object.keys(s||{}).length>0&&Object.keys(s||{}).some(u=>s[u]&&s[u].length>0),i=!!n;i&&(typeof n=="string"?i=n.length>0:n instanceof Uint8Array?i=!0:typeof n=="object"?i=Object.keys(n||{}).length>0:i=!0);let c=(await Ut(e?e+o:o)).toUpperCase(),l="";if(a){let u=Mt(s),p=JSON.stringify(u);l=(await Ut(e?e+p:p)).toUpperCase()}let d="";if(i)if(n instanceof Uint8Array)d=(await vi(e,n)).toUpperCase();else{let u=Mt(n),p=JSON.stringify(u);d=(await Ut(e?e+p:p)).toUpperCase()}let b;if(a||i){let u=c+l+d;b=(await Ut(e?e+u:u)).toUpperCase()}else b=(await Ut(e?e+c:c)).toUpperCase();return b}f(Jn,"sha256v1_Internal");async function We(r,t=""){if(Ni){let e=globalThis.performance?globalThis.performance.now():Date.now(),o=await Jn(r,t),n=(globalThis.performance?globalThis.performance.now():Date.now())-e;return dr++,zn+=n,dr%1e3===0&&console.log(`[sha256v1 Profile] Total Runs: ${dr} | Average Duration: ${(zn/dr).toFixed(4)} ms`),o}return Jn(r,t)}f(We,"sha256v1");function y({ib:r,gib:t,ibGib:e,delimiter:o="^"}){return r=r||e?.ib||"",t=t||e?.gib||"",r+o+t}f(y,"getIbGibAddr");function P({ibGib:r,ibGibAddr:t,delimiter:e="^"}){let o="[getIbAndGib]";if(!t)if(r)t=y({ibGib:r});else throw new Error(`${o} We need either an address or an ibGib object`);if(!t)throw new Error(`${o} Couldn't get ibGibAddr. ibGib invalid?`);e||(e="^");let n=t.split(e);return n.length===2?{ib:n[0],gib:n[1]}:n.length===1&&t.endsWith(e)?{ib:n[0],gib:""}:n.length===1&&t.startsWith(e)?{ib:"",gib:n[0]}:n.length===2&&n[0]===""&&n[1]===""?{ib:e,gib:""}:(console.warn(`${o} multiple delimiters found in ibGibAddr. Considering last delimiter as the demarcation of gib hash`),{ib:n.slice(0,n.length-1).join(e),gib:n.slice(n.length-1)[0]})}f(P,"getIbAndGib");var K;(function(r){r.past="past",r.ancestor="ancestor",r.dna="dna",r.identity="identity",r.tjp="tjp",r.secret="secret",r.encryption="encryption"})(K||(K={}));var Tt="ib",L="gib",V={ib:Tt,gib:L},J="^",Oe=".",ts="ib^gib",ct=["past","ancestor","dna","tjp"],Li=155,rs=new RegExp(`^[\\w\\t\\-|=+.&%$#@!~\` \\[\\]\\(\\)\\{\\}]{1,${Li}}$`);async function lt(r){let t=v(r),e=`[${lt.name}]`;t.srcAddr&&delete t.srcAddr,delete t.src;let o={ib:t.type,data:t,rel8ns:{ancestor:[`${t.type.toString()}${J}${L}`]}};return o.gib=await We(o),o}f(lt,"buildDna");function Pi({ibGib:r}){let t=`[${Pi.name}]`;try{if(!r)throw new Error("ibGib required.");let e=["fork","mut8","rel8","plan"].map(n=>`${n}^${L}`);return r.rel8ns&&r.rel8ns.ancestor&&Array.isArray(r.rel8ns.ancestor)&&r.rel8ns.ancestor.some(n=>e.includes(n))||!1}catch(e){throw console.error(`${t} ${m(e)}`),e}}f(Pi,"isDna");function Z({ibGib:r,gib:t}){return r?Z({gib:r.gib}):t?t===L:!0}f(Z,"isPrimitive");async function X({ibGib:r,hasTjp:t,tjpAddr:e,gibDelimiter:o,isPrimitive:n,hashAlgorithm:s}){let a=`[${X.name}]`;try{if(!r)throw new Error("ibGib required. (E: 17d073226b9d42fd841e5a94b065ef21)");if(n)return L;let i=await We(r,""),c=r.rel8ns??{},l=r.data??{};if(o=o||Oe,t||(t=(c.tjp??[]).length>0||l.isTjp||!1),t){let d;if(c.tjp)if(c.tjp.length===1)if(c.tjp[0])e=c.tjp[0];else throw new Error("rel8ns.tjp[0] is falsy. (E: ed879d2b039543f8b1902e8b7b5a5a7b)");else if(c.tjp.length>1)if(c.tjp[c.tjp.length-1])console.warn(`${a} found more than one tjp addr...only expecting 1 ATOW. (W: 10ed43f716e743e0afd1954f1ab46789)`),e=c.tjp[c.tjp.length-1];else throw new Error("multiple tjp addrs, and the last (most recent) one is falsy. (E: bc835dc89be24075bba8b2b6616ea069)");else throw new Error("hasTjp is true but rel8ns.tjp is empty array. (E: d08b2f9e86494814b5e7d7b4602b2ab7)");else if(l.isTjp)e=y({ib:r.ib,gib:i});else throw new Error("hasTjp is true, but both ibGib.rel8ns.tjp and ibGib.data.isTjp are falsy. (E: 4e246897e52044789594d853bb5b66ee)");if(d=e?P({ibGibAddr:e}).gib:void 0,d)return l.isTjp?i:`${i}${Oe}${d}`;throw new Error("hasTjp is true but could not find tjpAddrGib. (E: 1863df626b754744a1d431a683cb0ba0)")}else return i}catch(i){throw console.error(`${a} ${m(i)}`),i}}f(X,"getGib");function re({ibGibAddr:r,gib:t,gibDelimiter:e}){let o=`[${re.name}]`;try{if(!r&&!t)throw new Error("Either ibGibAddr or gib required. (E: 25e3dcbe63cd44909032df12af9df75e)");if(t=t||P({ibGibAddr:r}).gib,t===L)return{isPrimitive:!0};if(e=e??Oe,t.includes(e)){let n=t.split(e);if(n.some(i=>i===""))throw new Error(`unexpected gib that contains gibDelimiter (${e}) but has at least one piece with empty string. (E: 75a94280045541009ee68182d12d3449)`);let s=n.length;return s>2&&console.warn(`${o} gib only expected to have two pieces ATOW. re-examine please. (W: aa4283ac5a5747a386a69966ecdad39d)`),{punctiliarHash:n.splice(0,1)[0],tjpGib:n.join(e),piecesCount:s,delimiter:e}}else return{punctiliarHash:t,piecesCount:1,delimiter:e}}catch(n){throw console.error(`${o} ${m(n)}`),n}}f(re,"getGibInfo");async function fr(r){let{noTimestamp:t,dna:e,linkedRel8ns:o,destIb:n,uuid:s,tjp:a,cloneRel8ns:i,cloneData:c,type:l="fork"}=r,d=r.src,b="[fork_v1]";if(l!=="fork")throw new Error(`${b} not a fork transform.`);if(r.type||(r.type="fork"),!d)throw new Error(`${b} src required to fork.`);if(!d.ib)throw new Error(`${b} src.ib required.`);if(n&&n.includes(J))throw new Error(`${b} destIb can't contain (hardcoded) delimiter right now.`);if(!d.gib)throw new Error(`${b} src.gib required.`);let u={ib:d.ib,gib:d.gib};d.data&&Object.keys(d.data).length>0&&(u.data=d.data),d.rel8ns&&Object.keys(d.rel8ns).length>0&&(u.rel8ns=d.rel8ns),d=u;let p=y({ib:d.ib,gib:d.gib});r.srcAddr=p;let g=i&&d.rel8ns&&Object.keys(d.rel8ns).length>0?v(d.rel8ns):{};delete g.past;let h=c&&d?.data?v(d.data):{};r.nCounter&&(h.n=0);let E=o?.includes(K.ancestor)?[p]:(g.ancestor||[]).concat([p]);g.ancestor=E,g.tjp&&delete g.tjp;let $=v(d);if(t&&a?.timestamp)throw new Error(`${b} both noTimestamp and tjp.timestamp selected.`);if(!t||a?.timestamp){let w=new Date;h.timestamp=xe(w),h.timestampMs=w.getMilliseconds()}(a?.uuid||s)&&(h.uuid=await F()),a?.uuid||a?.timestamp?h.isTjp=!0:h.isTjp&&delete h.isTjp,$.ib=n||"ib",p!==ts&&($.rel8ns=g),Object.keys(h).length>0&&($.data=h);let I=null;if(e){I=await lt(r);let w=y({ibGib:I});g.dna=o?.includes(K.dna)?g.dna=[w]:g.dna=(g.dna||[]).concat(w)}$.gib=await We($,"");let A={newIbGib:$};return I&&(A.dnas=[I]),A}f(fr,"fork");async function Me(r){let{noTimestamp:t,dna:e,linkedRel8ns:o,dataToRename:n,dataToRemove:s,dataToAddOrPatch:a,mut8Ib:i,type:c="mut8"}=r,l=r.src,d="[mut8_v1]";if(c!=="mut8")throw new Error(`${d} not a mut8 transform.`);if(r.type||(r.type="mut8"),!l)throw new Error(`${d} src required to mut8.`);if(!l.ib)throw new Error(`${d} src.ib required.`);if(l.ib.includes(J))throw new Error(`${d} ib can't contain hardcoded delimiter (${J}) right now.`);if(!l.gib)throw new Error(`${d} src.gib required.`);if(!i&&!n&&!s&&!a)throw new Error(`${d} gotta provide either a mut8Ib or some data to change.`);let b=y({ib:l.ib,gib:l.gib});if(r.srcAddr&&b!==r.srcAddr)throw new Error(`${d} srcAddr from src does not equal opts.srcAddr`);if(r.srcAddr=b,Z({ibGib:l}))throw new Error(`${d} cannot mutate primitive ibgib`);let u={ib:l.ib,gib:l.gib};l.data&&Object.keys(l.data).length>0&&(u.data=l.data),l.rel8ns&&Object.keys(l.rel8ns).length>0&&(u.rel8ns=l.rel8ns),l=u;let p=v(l),g=l.rel8ns?l.rel8ns:{},h=v(g);h.past=o?.includes(K.past)?[b]:(h.past||[]).concat([b]);let E=l?.data?v(l.data):{};if(n&&(E=mo(E,n,"rename")),s&&(E=mo(E,s,"remove")),a&&(E=os(E,a)),!t){let _=new Date;E.timestamp=xe(_),E.timestampMs=_.getMilliseconds()}if(r.nCounter||Object.keys(E).includes("n"))if(Object.keys(E).includes("n"))if(Number.isInteger(E.n))E.n>=0?E.n=E.n+1:(console.warn(`${d} data.n is less than 0, which is unexpected. Resetting data.n to 0.`),E.n=0);else throw new Error("cannot increment nCounter because data.n is not a number.");else E.n=0;if(E.isTjp){let _=h.tjp??[];_.push(b),h.tjp=_,delete E.isTjp}let I=null;if(e){I=await lt(r);let _=y({ibGib:I});h.dna=o?.includes(K.dna)?h.dna=[_]:h.dna=(h.dna||[]).concat(_)}p.ib=i||p.ib,p.rel8ns=h,Object.keys(E).length>0?p.data=E:delete p.data;let A=(h.tjp?.length??0)>0;p.gib=await X({ibGib:p,hasTjp:A});let w={newIbGib:p};return I&&(w.dnas=[I]),w}f(Me,"mut8");function mo(r,t,e){let o="[renameOrRemove]",n=["timestamp"];return Object.keys(t).forEach(s=>{if(n.includes(s))throw new Error(`${o} Cannot rename to ${s}.`);if(Object.keys(r).includes(s)){let a=t[s];if(typeof a=="string"){if(n.includes(a))throw new Error(`${o} Cannot rename to ${a}.`);e==="rename"&&(r[a]=r[s]),delete r[s]}else r[s]=mo(r[s],a,e)}else console.log(`${o} key to ${e} does not exist`)}),r}f(mo,"renameOrRemove");function os(r,t){return Object.keys(t).forEach(e=>{let o=t[e],n=r[e];n?Array.isArray(o)||Array.isArray(n)?r[e]=o:typeof o=="object"&&typeof n=="object"?r[e]=os(n,o):r[e]=o:r[e]=o}),r}f(os,"patch");async function Ie(r){let{noTimestamp:t,dna:e,linkedRel8ns:o,rel8nsToAddByAddr:n,rel8nsToRemoveByAddr:s,type:a="rel8"}=r,i=r.src,c="[rel8_v1]";if(a!=="rel8")throw new Error(`${c} not a rel8 transform.`);if(r.type||(r.type="rel8"),a!=="rel8")throw new Error(`${c} not a rel8 transform.`);if(r.type||(r.type="rel8"),!i)throw new Error(`${c} src required.`);if(!i.ib)throw new Error(`${c} src.ib required.`);if(i.ib.includes(J))throw new Error(`${c} ib can't contain hardcoded delimiter (${J}) right now.`);if(!i.gib)throw new Error(`${c} src.gib required.`);if(Z({ibGib:i}))throw new Error(`${c} cannot relate/unrelate primitive ibgib`);let l=n&&Object.keys(n).length>0,d=s&&Object.keys(s).length>0;if(!(l||d))throw new Error(`${c} gotta provide relations to either add or remove.`);let b=y({ib:i.ib,gib:i.gib});if(r.srcAddr&&b!==r.srcAddr)throw new Error(`${c} srcAddr from src does not equal opts.srcAddr`);r.srcAddr=b;let u=f(w=>w&&typeof w=="string"&&w.length>=2&&w.includes("^")&&w.split("^")[0].length>=1,"fnValidIbGibAddr");Object.keys(n||{}).map(w=>(n||{})[w]).forEach(w=>{if(!(w&&w.every(_=>u(_))))throw new Error(`${c} Invalid rel8n attempt. Must be valid ibGibs. Did you include a delimiter (^)?`)}),Object.keys(s||{}).map(w=>(s||{})[w]).forEach(w=>{if(!(w&&w.every(_=>u(_))))throw new Error(`${c} Invalid remove rel8n attempt. Must be valid ibGibs. Did you include a delimiter (^)?`)});let p={ib:i.ib,gib:i.gib};i.data&&Object.keys(i.data).length>0&&(p.data=i.data),i.rel8ns&&Object.keys(i.rel8ns).length>0&&(p.rel8ns=i.rel8ns),i=p;let g=v(i),h=v(i.data||{});if(r.nCounter||Object.keys(h).includes("n"))if(Object.keys(h).includes("n"))if(Number.isInteger(h.n))h.n>=0?h.n=h.n+1:(console.warn(`${c} data.n is less than 0, which is unexpected. Resetting data.n to 0.`),h.n=0);else throw new Error("cannot increment nCounter because data.n is not a number.");else h.n=0;if(!t){let w=new Date;h.timestamp=xe(w),h.timestampMs=w.getMilliseconds()}let E=v(i.rel8ns||{});if(Object.keys(n||{}).forEach(w=>{if(ct.includes(w))throw new Error(`${c} Cannot manually add relationship: ${w}.`);let _=E[w]||[],G=n[w].filter(O=>!_.includes(O));E[w]=_.concat(G)}),Object.keys(s||{}).forEach(w=>{if(ct.includes(w))throw new Error(`${c} Cannot manually remove relationship: ${w}.`);let _=E[w]||[],S=s[w]||[],G=_.filter(O=>!S.includes(O));G.length>0?E[w]=G:delete E[w]}),E.past=(E.past||[]).concat([b]),(o||[]).filter(w=>Object.keys(E).includes(w)).filter(w=>(E[w]||[]).length>1).forEach(w=>{let _=E[w].length;E[w]=[E[w][_-1]]}),h.isTjp){let w=E.tjp||[];w.push(b),E.tjp=w,delete h.isTjp}g.data=h,g.rel8ns=E;let $=(E.tjp?.length??0)>0,I=null;if(e){I=await lt(r);let w=y({ibGib:I});E.dna=o?.includes(K.dna)?E.dna=[w]:E.dna=(E.dna||[]).concat(w)}g.gib=await X({ibGib:g,hasTjp:$});let A={newIbGib:g};return I&&(A.dnas=[I]),A}f(Ie,"rel8");function br({ibGib:r}){let t=`[${br.name}]`;if(!r)return console.warn(`${t} ibGib falsy. (W: 884178562f5b4f15933ac4d98db74cc6)`),!1;if(r.data?.isTjp||r.rel8ns?.tjp?.length>0)return!0;let e=["fork^gib","mut8^gib","rel8^gib"];return(r.rel8ns?.ancestor??[]).some(n=>e.includes(n))?!1:r.gib?r.gib.includes(Oe)?!0:r.gib===L?!1:!!re({ibGibAddr:y({ibGib:r})}).tjpGib:(console.warn(`${t} ibGib.gib falsy. (W: 6400d780822b44d992846f1196509be3)`),!1)}f(br,"hasTjp");function ur({ibGib:r}){let t=`[${ur.name}]`;r.ib||console.warn(`${t} ibGib.ib is falsy. (W: e60e41c2a1fc48268379d88ce13cb77b)`),r.gib||console.warn(`${t} ibGib.gib is falsy. (W: fb3889cbf0684ae4ac51e48f28570377)`);let e={ib:(r.ib||"").slice()};return r.gib&&(e.gib=r.gib.slice()),r.data&&(e.data=r.data instanceof Uint8Array?r.data:v(r.data)),r.rel8ns&&(e.rel8ns=v(r.rel8ns)),e}f(ur,"toDto");var wo=!1;async function oe({ibGib:r}){let t=`[${oe.name}]`;try{let e=[];if(r){let o=y({ibGib:r});if(e=kt({addr:o})??[],e.length>0)return console.error(`${t} errors found in addr: ${o}`),e;if(Z({gib:r.gib}))return null;let n=await X({ibGib:ur({ibGib:r}),hasTjp:br({ibGib:r})});return n!==r.gib&&(r.data?.src&&r.data.srcAddr&&r.ib==="rel8"?(delete r.data.src,delete r.data.srcAddr,n=await X({ibGib:ur({ibGib:r}),hasTjp:br({ibGib:r})}),n!==r.gib&&e.push(`Ibgib invalid intrinsically - gottenGib (${n}) does not equal ibGib.gib (${r.gib}). (E: 020b71479e944b2198fe436e7e137786)`)):e.push(`Ibgib invalid intrinsically - gottenGib (${n}) does not equal ibGib.gib (${r.gib}). (E: 7416db016878430ca3c5b20697f164ed)`)),e.length>0?e:null}else return e.push("ibGib is itself falsy. (E: 4fb98caf6ed24ef7b35a19cef56e2d7e)"),e}catch(e){throw console.error(`${t} ${m(e)}`),e}}f(oe,"validateIbGibIntrinsically");function kt({addr:r,delimiter:t,version:e}){let o=`[${kt.name}]`;try{let n=[];if(e&&console.warn(`${o} version not implemented yet. Ignoring. (W: 2d19db16ec0c4766b5d35248787671f3)`),!r)return n.push("addr required. (E: e9a54041aa0b41c1bb2324d9d2d42c7f)"),n;t=t||J,r.includes(t)||n.push(`No delimiter (${t}) found. (E: 05e28dcb70ff44019edc53ed508bd1e8)`),r.startsWith(t)&&n.push("addr starts with delim. (E: d29f808c5a47452f9bb3ea684694c6eb)");let{ib:s,gib:a}=P({ibGibAddr:r,delimiter:t}),i=Gt({ib:s,ibGibAddrDelimiter:t,version:e});i&&(n=n.concat(i));let c=At({gib:a,ibGibAddrDelimiter:t,version:e});return c&&(n=n.concat(c)),n.length>0&&wo&&console.log(`${o} errors.length > 0. errors: ${n.join("|")} (I: 9c18f993e138f15613e4c6a340d41722)`),n.length>0?n:null}catch(n){throw console.error(`${o} ${m(n)}`),n}}f(kt,"validateIbGibAddr");function Gt({ib:r,ibGibAddrDelimiter:t,version:e}){let o=`[${Gt.name}]`;try{let n=[];return e&&console.warn(`${o} version not implemented yet. Ignoring. (W: 71228ba4ed994aaa8149910e295ab087)`),r?r===Tt?null:(t=t||J,r.includes(t)&&n.push(`ib contains ibGibAddrDelimiter (${t}) (E: 09e61b46c3e84874bc02b6918f1f2c39)`),n.length>0?n:null):(n.push("ib required. (E: a76d06c7b9c24db3a731a91dbe46acd5)"),n)}catch(n){throw console.error(`${o} ${m(n)}`),n}}f(Gt,"validateIb");function At({gib:r,gibDelimiter:t,ibGibAddrDelimiter:e,version:o}){let n=`[${At.name}]`;try{let s=[];if(o&&console.warn(`${n} version not implemented yet. Ignoring. (E: 90ced1db69774702b92acb261bdaee23)`),!r)return s.push("gib required. (E: e217de4035b04086827199f4bace189c)"),s;e=e||J;let a=[e],i=[];a.forEach(p=>{r.includes(p)&&i.push(p)}),i.length>0&&s.push(`gib (${r}}) contains invalid characters: (${JSON.stringify(i.join(","))}) (E: 1e584258d9e049ba9ce7e516f3ab97f1)`);let{punctiliarHash:c,tjpGib:l,isPrimitive:d}=re({gib:r,gibDelimiter:t||Oe});if(d)return null;if(!c)throw new Error(`${n} punctiliarHash is falsy on a non-primitive gib. (E: 72835394918241bdb2632bf0510bdae5)`);let b=c.match(Xn),u=c.match(Kn);if(!b&&!u&&s.push("gib punctiliar hash is neither a 32- or 64-char hash string. (E: d47ff6d6e14b4c02a62107090c8dad39)"),l){let p=At({gib:l});(p??[]).length>0&&s.push(`tjpGib has errors (E: d6b79228d4a64c0b967cdb0efcea4d0d). tjpGibValidationErrors: ${p.join(". ")}`)}return s.length>0?s:null}catch(s){throw console.error(`${n} ${m(s)}`),s}}f(At,"validateGib");function $o({rel8ns:r}){let t=`[${$o.name}]`;try{wo&&console.log(`${t} starting... (I: 62b4722599798dd8ab95fcebf42c0e23)`);let e=[],o=Object.keys(r);for(let n=0;n<o.length;n++){let s=Object.keys(r)[n];typeof s!="string"&&e.push("non-string rel8nName found. all keys of rel8ns must be of type string. (E: 3b2e4582b638421681951f5475c85178)");let a=r[s]??[];for(let i=0;i<a.length;i++){let c=a[i],l=kt({addr:c})??[];l.length>0&&e.push(`invalid addr found for rel8nName (${s}). addr errors: ${l.join("|")} (E: 56809a746c4f462db426e90395b80364)`)}}return e.length>0?e:null}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{wo&&console.log(`${t} complete.`)}}f($o,"validateRel8nsIntrinsically");var ns=!1,M=class r{static{f(this,"Factory_V1")}static root(){return r.primitive({ib:Tt})}static primitive({ib:t}){return{ib:t,gib:L}}static primitives({ibs:t}){return t.map(e=>r.primitive({ib:e}))}static async firstGen({ib:t=Tt,parentIbGib:e=r.root(),data:o,rel8ns:n,dna:s,tjp:a,linkedRel8ns:i,noTimestamp:c,nCounter:l,squash:d}){let b=`[${r.name}][${r.firstGen.name}]`;try{if(ns&&console.log(`${b} starting... (I: b7152fbd94382516d9f7c591bcf4c326)`),s&&d)throw new Error("both dna and squash cannot be true. Squash requires that no dna exist. (E: abfc58b4a4c8654924aa5428d0831826)");let u=[],p=e||V,g=await fr({src:p,destIb:t,tjp:a,dna:s,linkedRel8ns:i,noTimestamp:c,nCounter:l});if(u.push(g),p=g.newIbGib,o){let h=await Me({src:p,dataToAddOrPatch:o,dna:s,linkedRel8ns:i,noTimestamp:c,nCounter:l});u.push(h),p=h.newIbGib}if(n){let h=await Ie({src:p,rel8nsToAddByAddr:n,dna:s,linkedRel8ns:i,noTimestamp:c,nCounter:l});u.push(h)}if(u.length>1){let h=u.slice(u.length-1)[0].newIbGib,E={newIbGib:h,intermediateIbGibs:u.slice(0,u.length-1).map($=>$.newIbGib)};if(s){d&&`${b}`;let $=[];return u.forEach(I=>{$=$.concat(I.dnas)}),E.dnas=$,E}else if(d){if(!h.rel8ns)throw new Error("(UNEXPECTED) newIbGib.rel8ns is falsy? (E: 6b09e8057fc5b00c6cfd13be60e97f26)");return delete h.rel8ns.past,h.rel8ns.tjp&&(delete h.rel8ns.tjp,h.data??={},h.data.isTjp=!0),l&&(h.data??={},h.data.n=0),h.gib=await X({ibGib:h}),{newIbGib:h}}else return E}else{if(u.length===1)return u[0];throw new Error("(UNEXPECTED) interimResults.length is not 1 and not greater than 1? 0? But we had to fork? (E: a256c88c56916a46a888796f76ef4826)")}}catch(u){throw console.error(`${b} ${m(u)}`),u}finally{ns&&console.log(`${b} complete.`)}}static async stone({parentPrimitiveIb:t,ib:e,ibRegExpPattern:o,data:n,rel8ns:s,noTimestamp:a,uuid:i}){let c=`[${r.name}][${r.stone.name}]`;try{if(!t)throw new Error("parentPrimitiveIb required. (E: genuuid)");if(Gt({ib:t})!==null)throw new Error(`Invalid parentPrimitiveIb: ${t}. (E: genuuid)`);if(!e)throw new Error("ib required. (E: genuuid)");let l=o?new RegExp(o):rs;if(!e.match(l))throw new Error(`invalid ib. does not match regexp (${l}) (E: genuuid)`);let d=Object.keys(s??{}),b=[...ct,"tjp"];if(d.some(h=>b.includes(h)))throw new Error(`Invalid rel8ns. forbiddenRel8nNames: ${b}. rel8ns keys: ${Object.keys(s??{})}. (E: genuuid)`);let g=(await r.firstGen({ib:e,parentIbGib:r.primitive({ib:t}),data:n,rel8ns:s,dna:!1,noTimestamp:a,nCounter:!1})).newIbGib;return i&&(g.data||(g.data={}),g.data.uuid=await F()),g.rel8ns?.past&&delete g.rel8ns.past,g.rel8ns?.tjp&&delete g.rel8ns.tjp,g.gib=await X({ibGib:{ib:g.ib,data:g.data,rel8ns:g.rel8ns},hasTjp:!1}),g}catch(l){throw console.error(`${c} ${l.message}`),l}}static async constant({parentPrimitiveIb:t,ib:e,ibRegExpPattern:o,data:n,rel8ns:s}){let a=`[${r.name}][${r.constant.name}]`;try{return await r.stone({parentPrimitiveIb:t,ib:e,ibRegExpPattern:o,data:n,rel8ns:s,noTimestamp:!0,uuid:!1})}catch(i){throw console.error(`${a} ${i.message}`),i}}};var Gd="[core^gib timer]";var yo=`.'",!?-`;var ss=new RegExp("^[\\w\\t\\-|=+.&%$#@!~` \\[\\]\\(\\)\\{\\}]{1,155}$");var Sd=/^[a-zA-Z0-9_\-.]{1,255}$/,xd=/^[a-zA-Z0-9_\-.\s👀🤖:;&]{1,64}$/;var pr={tags:"tags",aliases:"aliases",roots:"roots",outerspaces:"outerspaces",secrets:"secrets",encryptions:"encryptions",autosyncs:"autosyncs",robbots:"robbots",apps:"apps",history:"history"};var Ri="robbot";var as="zero",is="zerospace";var Hd=!1,Xd="This is a local space. There are many like it, but this one is mine.";var Kd=/^[a-zA-Z][\w\-]{0,62}[a-zA-Z]$/,Ci="syncSpace";var Yd=3e4;var hr="space";var cs="space_lock",ls=100,ds=100,Vd=60*2,gr=30;var Io="root",_o="x",fs="root",To="analytics-outline",Ao='This is a root ibgib, which is basically like a root folder that is primarily responsible for "containing" other ibgibs.';var Go="tag",Ui="target";var bs="pricetag-outline",us="This is a tag used for organizing data.";var rf="always",ps="archive",hs="trash";var So=/^\w{1,32}$/,Er="Invalid Date";var xo={ib:"true",gib:L};var gs={ib:"false",gib:L};var Es="config_key";var jt=/^[a-zA-Z0-9_\-.]{1,32}$/,mr="app";var ze=`bootstrap^${L}`,_e="defaultSpaceId",wr="spaceIds";var De={prependPerHash:"prependPerHash",appendPerHash:"appendPerHash",initialPrepend:"initialPrepend",initialAppend:"initialAppend"},Je=Object.values(De),Ee={sha_256:"SHA-256",sha_512:"SHA-512"},df=Object.values(Ee),Mi={indexOf:"indexOf",lastIndexOf:"lastIndexOf"},ke=Object.values(Mi);function Bt(r){let t=`[${Bt.name}]`;return new Promise((e,o)=>{try{let n=ms(r),s=ws(n);e(s)}catch(n){console.error(`${t} ${m(n)}`),o(n)}})}f(Bt,"encodeStringToHexString");function ms(r){let t=`[${ms.name}]`;try{return new TextEncoder().encode(r)}catch(e){throw console.error(`${t} ${m(e)}`),e}}f(ms,"stringToUTF8Bytes");function ws(r){let t=`[${ws.name}]`;try{return Array.from(r,e=>e.toString(16).padStart(2,"0")).join("")}catch(e){throw console.error(`${t} ${m(e)}`),e}}f(ws,"bytesToHexString");function je(r){let t=`[${je.name}]`;return new Promise((e,o)=>{try{let n=$s(r),s=ys(n);e(s)}catch(n){console.error(`${t} ${m(n)}`),o(n)}})}f(je,"decodeHexStringToString");function $s(r){let t=`[${$s.name}]`;try{if(r.length%2!==0)throw new Error("invalid hex string. length %2 !== 0");let e=r.length/2,o=new Uint8Array(e);for(let n=0;n<e;n++)o[n]=parseInt(r.substr(n*2,2),16);return o}catch(e){throw console.error(`${t} ${m(e)}`),e}}f($s,"hexStringToBytes");function ys(r){let t=`[${ys.name}]`;try{return new TextDecoder().decode(r)}catch(e){throw console.error(`${t} ${m(e)}`),e}}f(ys,"utf8BytesToString");var Be=De.appendPerHash,Fe="SHA-512",qe=1024,ve=2e4,He=1,Is="indexOf",$r="lastIndexOf",yr=5e6,Ir=4,Ze=",";function ki({secret:r,prevHash:t,salt:e,saltStrategy:o}){if(!(t||r))throw new Error("Either secret or prevHash is required, but both are falsy (E: bee2849729ff410081d963777dcedb49))");switch(o){case De.prependPerHash:return e+(t||r);case De.appendPerHash:return(t||r)+e;case De.initialPrepend:return t||e+r;case De.initialAppend:return t||r+e;default:throw new Error(`Unknown saltStrategy: ${o} (E: 235136af1a6c40eb9c17b2ca41c08a01)`)}}f(ki,"getPreHash");async function $e({secret:r,prevHash:t,count:e,salt:o,saltStrategy:n,hashAlgorithm:s}){let a=`[${$e.name}]`;try{let i=t||void 0;for(let c=0;c<e;c++){let l=ki({secret:r,prevHash:i,salt:o,saltStrategy:n});i=await ce({s:l,algorithm:s})}if(!i)throw new Error("hash was not created (E: 09dfdfd644734727a34a1bc0bd8e93b9)");return i}catch(i){throw console.error(`${a} ${m(i)}`),i}}f($e,"execRound_getNextHash");async function Xe({secret:r,initialRecursions:t,salt:e,saltStrategy:o,hashAlgorithm:n}){let s=`[${Xe.name}]`;try{return await $e({secret:r,count:t,salt:e,saltStrategy:o,hashAlgorithm:n})}catch(a){throw console.error(`${s} ${m(a)}`),a}}f(Xe,"doInitialRecursions_keystretch");async function Oo({hexEncodedData:r,initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,secret:s,hashAlgorithm:a,encryptedDataDelimiter:i,indexingMode:c}){let l=`[${Oo.name}]`;try{let d=await Xe({secret:s,initialRecursions:t,salt:o,saltStrategy:n,hashAlgorithm:a}),b=c==="indexOf"?(g,h)=>g.indexOf(h):(g,h)=>g.lastIndexOf(h),u=[];for(let g=0;g<r.length;g++){let h=r[g],E="",$;for(;!E.includes(h);)$=await $e({count:e,prevHash:d,salt:o,saltStrategy:n,hashAlgorithm:a}),E+=$,d=$;let I=b(E,h);u.push(I)}return u.join(i)}catch(d){throw console.error(`${l} ${m(d)}`),d}}f(Oo,"encryptFromHex_stream");async function Do({encryptedData:r,initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,secret:s,hashAlgorithm:a,encryptedDataDelimiter:i}){let c=`[${Do.name}]`;try{let l=await Xe({secret:s,initialRecursions:t,salt:o,saltStrategy:n,hashAlgorithm:a}),d=r.split(i).map(p=>parseInt(p)),b=[];for(let p=0;p<d.length;p++){let g=d[p],h="",E;for(;g>=h.length;)E=await $e({count:e,prevHash:l,salt:o,saltStrategy:n,hashAlgorithm:a}),h+=E,l=E;let $=h[g];b.push($)}return b.join("")}catch(l){throw console.error(`${c} ${m(l)}`),l}}f(Do,"decryptToHex_stream");async function Ft({encryptedData:r,initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,secret:s,hashAlgorithm:a,encryptedDataDelimiter:i}){let c=`[${Ft.name}]`,l=[],d=[];t=t||ve,e=e||He,n=n||Be,a=a||Fe,o=o||await F(qe),i=i||Ze;let b="[validation]";if(!t||t<1){let g=`${b} initialRecursions required, and greater than 0`;console.error(g),l.push(g)}if(!e||e<1){let g=`${b} recursionsPerHash required, and greater than 0`;console.error(g),l.push(g)}if(!r){let g=`${b} encryptedData required`;console.error(g),l.push(g)}if(!o){let g=`${b} salt required`;console.error(g),l.push(g)}if(!n){let g=`${b} saltStrategy required`;console.error(g),l.push(g)}if(!s){let g=`${b} secret required`;console.error(g),l.push(g)}if(!i){let g=`${b} encryptedDataDelimiter required`;console.error(g),l.push(g)}if(!Object.values(Ee).includes(a)){let g=`${b} only ${Object.values(Ee)} hash algorithms implemented`;console.error(g),l.push(g)}if(n&&!Je.includes(n)){let g=`${b} unknown saltStrategy: ${n}`;console.error(g),l.push(g)}if(l.length>0)return{errors:l,initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,hashAlgorithm:a,encryptedDataDelimiter:i};let u=await Do({encryptedData:r,initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,secret:s,hashAlgorithm:a,encryptedDataDelimiter:i});return{decryptedData:await je(u),initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,hashAlgorithm:a,encryptedDataDelimiter:i,warnings:d.length>0?d:void 0}}f(Ft,"decryptImpl_stream");async function vo({dataToEncrypt:r,initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,secret:s,hashAlgorithm:a,encryptedDataDelimiter:i,confirm:c,indexingMode:l}){let d=`[${vo.name}]`,b=[],u=[];t||(console.warn(`${d} initial recursions required. defaulting to ${ve}`),t=ve),e=e||He,n=n||Be,a=a||Fe,o=o||await F(qe),i=i||Ze,l=l||Is;let p="[validation]";if(!t||t<1){let E=`${p} initialRecursions required, and greater than 0`;console.error(E),b.push(E)}if(!e||e<1){let E=`${p} recursionsPerHash required, and greater than 0`;console.error(E),b.push(E)}if(!r){let E=`${p} dataToEncrypt required`;console.error(E),b.push(E)}if(!o){let E=`${p} salt required`;console.error(E),b.push(E)}if(!n){let E=`${p} saltStrategy required`;console.error(E),b.push(E)}if(!s){let E=`${p} secret required`;console.error(E),b.push(E)}if(!i){let E=`${p} encryptedDataDelimiter required`;console.error(E),b.push(E)}if(!ke.includes(l)){let E=`${p} invalid indexingMode (${l}). Must be one of ${ke} (E: 5955c46755434982982823c97adcf076)`;console.error(E),b.push(E)}if(!Object.values(Ee).includes(a)){let E=`${p} only ${Object.values(Ee)} hash algorithms implemented`;console.error(E),b.push(E)}if(n&&!Je.includes(n)){let E=`${p} unknown saltStrategy: ${n}`;console.error(E),b.push(E)}if(b.length>0)return{errors:b,initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,hashAlgorithm:a,encryptedDataDelimiter:i};let g=await Bt(r);if(c&&await je(g)!==r)throw new Error("decoding encoded hex failed for this data: The encoded hex did not reverse to the original data.");let h=await Oo({hexEncodedData:g,initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,secret:s,hashAlgorithm:a,encryptedDataDelimiter:i,indexingMode:"indexOf"});if(c){let E=await Ft({encryptedData:h,initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,secret:s,hashAlgorithm:a,encryptedDataDelimiter:i});if((E.errors||[]).length>0)return{errors:["Confirm check found that decrypt had errors.",...E.errors],initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,hashAlgorithm:a,encryptedDataDelimiter:i};if(E.decryptedData){if(E.decryptedData!==r)throw new Error("The ENCRYPTED data did not decrypt back to the original data.")}else throw new Error("Confirm check call to decrypt produced falsy decryptedData");(E.warnings||[]).length>0&&(u=u.concat(["Confirm check call to decrypt had warnings.",...E.warnings]))}return{encryptedData:h,initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,hashAlgorithm:a,encryptedDataDelimiter:i,warnings:u.length>0?u:void 0}}f(vo,"encryptImpl_stream");async function No({hexEncodedData:r,initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,secret:s,hashAlgorithm:a,encryptedDataDelimiter:i,indexingMode:c,maxBlockSize:l,numOfPasses:d}){let b=`[${No.name}]`;try{let u=await Xe({secret:s,initialRecursions:t,salt:o,saltStrategy:n,hashAlgorithm:a}),p=c==="indexOf"?(_,S)=>_.indexOf(S):(_,S)=>_.lastIndexOf(S),g=[],h=r.length,E=l;E>h&&(E=h);let $=Math.ceil(h/E),I=h%E||E,A=0;for(let _=0;_<$;_++){_===$-1&&(E=I);let G=await _s({blockSize:E,indexHexEncodedDataAtStartOfPass:A,numOfPasses:d,hexEncodedData:r,recursionsPerHash:e,salt:o,saltStrategy:n,prevHash:u,hashAlgorithm:a}),O=G.alphabetsThisBlock;u=G.prevHash;let U=await Ts({alphabetsThisBlock:O,blockSize:E,indexHexEncodedDataAtStartOfPass:A,hexEncodedData:r,getIndexOfCharInAlphabet:p});g=g.concat(U),A+=E}return g.join(i)}catch(u){throw console.error(`${b} ${m(u)}`),u}}f(No,"encryptFromHex_blockMode");async function _s({blockSize:r,numOfPasses:t,indexHexEncodedDataAtStartOfPass:e,hexEncodedData:o,recursionsPerHash:n,salt:s,saltStrategy:a,prevHash:i,hashAlgorithm:c}){let l=`[${_s.name}]`;try{let d=[],b,u;for(let p=0;p<t;p++)for(let g=0;g<r;g++){b=e+g;let h=d[g]??"";u=await $e({count:n,prevHash:i,salt:s,saltStrategy:a,hashAlgorithm:c}),h+=u,i=u,d[g]=h}for(let p=0;p<r;p++){b=e+p;let g=o[b],h=d[p];for(;!h.includes(g);)u=await $e({count:n,prevHash:i,salt:s,saltStrategy:a,hashAlgorithm:c}),h+=u,i=u;d[p]=h}return{alphabetsThisBlock:d,prevHash:i}}catch(d){throw console.error(`${l} error: ${m(d)}`),d}}f(_s,"getAlphabetsThisBlock");async function Ts({alphabetsThisBlock:r,blockSize:t,indexHexEncodedDataAtStartOfPass:e,hexEncodedData:o,getIndexOfCharInAlphabet:n}){let s=`[${Ts.name}]`;try{let a=[];for(let i=0;i<t;i++){let c=e+i,l=r[i],d=n(l,o[c]);a.push(d)}return a}catch(a){throw console.error(`${s} ${m(a)}`),a}}f(Ts,"getEncryptedIndexesThisBlock");async function Lo({encryptedData:r,initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,secret:s,hashAlgorithm:a,encryptedDataDelimiter:i,maxBlockSize:c,numOfPasses:l}){let d=`[${Lo.name}]`;try{let b=await Xe({secret:s,initialRecursions:t,salt:o,saltStrategy:n,hashAlgorithm:a}),u=r.split(i).map(w=>parseInt(w)),p=[],g=u.length,h=c;h>g&&(h=g);let E=Math.ceil(g/h),$=g%h||h,I=0;for(let w=0;w<E;w++){w===E-1&&(h=$);let S=await As({blockSize:h,indexEncryptedDataIndexesAtStartOfPass:I,numOfPasses:l,encryptedDataIndexes:u,recursionsPerHash:e,salt:o,saltStrategy:n,prevHash:b,hashAlgorithm:a}),G=S.alphabetsThisBlock;b=S.prevHash;let O=await Gs({alphabetsThisBlock:G,blockSize:h,indexEncryptedDataIndexesAtStartOfPass:I,encryptedDataIndexes:u});p=p.concat(O),I+=h}return p.join("")}catch(b){throw console.error(`${d} ${m(b)}`),b}}f(Lo,"decryptToHex_blockMode");async function As({blockSize:r,numOfPasses:t,indexEncryptedDataIndexesAtStartOfPass:e,encryptedDataIndexes:o,recursionsPerHash:n,salt:s,saltStrategy:a,prevHash:i,hashAlgorithm:c}){let l=`[${As.name}]`;try{let d=[],b,u;for(let p=0;p<t;p++)for(let g=0;g<r;g++){b=e+g;let h=d[g]??"";u=await $e({count:n,prevHash:i,salt:s,saltStrategy:a,hashAlgorithm:c}),h+=u,i=u,d[g]=h}for(let p=0;p<r;p++){b=e+p;let g=o[b],h=d[p];for(;h.at(g)===void 0;)u=await $e({count:n,prevHash:i,salt:s,saltStrategy:a,hashAlgorithm:c}),h+=u,i=u;d[p]=h}return{alphabetsThisBlock:d,prevHash:i}}catch(d){throw console.error(`${l} error: ${m(d)}`),d}}f(As,"getAlphabetsThisBlock");async function Gs({alphabetsThisBlock:r,blockSize:t,indexEncryptedDataIndexesAtStartOfPass:e,encryptedDataIndexes:o}){let n=`[${Gs.name}]`;try{let s=[];for(let a=0;a<t;a++){let i=e+a,c=o[i],d=r[a][c];s.push(d)}return s}catch(s){throw console.error(`${n} ${m(s)}`),s}}f(Gs,"getDecryptedDataArrayThisBlock");async function qt(r){let t=`[${qt.name}]`,{encryptedData:e,initialRecursions:o,recursionsPerHash:n,salt:s,saltStrategy:a,secret:i,hashAlgorithm:c,encryptedDataDelimiter:l,indexingMode:d,blockMode:b,multipass:u}=r,p=[],g=[];if(b&&u)throw new Error("blockMode and multipass set. blockMode was a refactored name of multipass, so these should not both be present. multipass is deprecated. (E: b9b3cd1f701c700835c0419260278223)");if(!b&&u&&(console.warn(`${t}[WARNING] "multipass" option is deprecated. this has been refactored to "blockMode". This will use multipass as blockMode. (W: b77c9773e30549cbb389ce61f31eb6d3)`),b=u),!b)throw new Error("(UNEXPECTED) blockMode required. This should be truthy in order to get to this impl fn. (E: 306bce36afd64b7182ca2b46ac04a261)");o=o||ve,n=n||He,a=a||Be,c=c||Fe,s=s||await F(qe),l=l||Ze,d=d||$r;let{maxBlockSize:h,maxPassSectionLength:E,numOfPasses:$}=b;!h&&E&&(console.warn(`${t}[WARNING] "maxPassSectionLength" option is deprecated. this has been refactored to "maxBlockSize". This will use maxPassSectioLength as maxBlockSize. (W: e2c83d78a3464704a6067e0f767f20b0)`),h=E),h=h||yr,$=$||Ir;let I="[validation]";if(!o||o<1){let S=`${I} initialRecursions required, and greater than 0`;console.error(S),p.push(S)}if(!n||n<1){let S=`${I} recursionsPerHash required, and greater than 0`;console.error(S),p.push(S)}if(!e){let S=`${I} encryptedData required`;console.error(S),p.push(S)}if(!s){let S=`${I} salt required`;console.error(S),p.push(S)}if(!a){let S=`${I} saltStrategy required`;console.error(S),p.push(S)}if(!i){let S=`${I} secret required`;console.error(S),p.push(S)}if(!l){let S=`${I} encryptedDataDelimiter required`;console.error(S),p.push(S)}if(!d){let S=`${I} indexingMode required (E: a6fe15f8ba414e21b5355d23e808b976)`;console.error(S),p.push(S)}if(!ke.includes(d)){let S=`${I} invalid indexingMode (${d}). Must be one of ${ke} (E: 17435268651444e0b7a594135635fc58)`;console.error(S),p.push(S)}if(h<1){let S=`${I} maxBlockSize must be greater than 0 (E: 0870831aa86b4bfa939aeee9f252326a)`;console.error(S),p.push(S)}if($<1){let S=`${I} numOfPasses must be greater than 0 (E: 691d3c3765584c6f8c9aba1ee378df00)`;console.error(S),p.push(S)}if(!Object.values(Ee).includes(c)){let S=`${I} only ${Object.values(Ee)} hash algorithms implemented`;console.error(S),p.push(S)}if(a&&!Je.includes(a)){let S=`${I} unknown saltStrategy: ${a}`;console.error(S),p.push(S)}if(p.length>0){let S={...r,errors:p};return delete S.encryptedData,delete S.secret,S}let A=await Lo({encryptedData:e,initialRecursions:o,recursionsPerHash:n,salt:s,saltStrategy:a,secret:i,hashAlgorithm:c,encryptedDataDelimiter:l,maxBlockSize:h,numOfPasses:$}),w=await je(A),_={...r,decryptedData:w,warnings:g.length>0?g:void 0};return delete _.encryptedData,delete _.secret,_}f(qt,"decryptImpl_blockMode");async function Po(r){let t=`[${Po.name}]`,{dataToEncrypt:e,initialRecursions:o,recursionsPerHash:n,salt:s,saltStrategy:a,secret:i,hashAlgorithm:c,encryptedDataDelimiter:l,confirm:d,indexingMode:b,blockMode:u,multipass:p}=r,g=[],h=[];if(u&&p)throw new Error("blockMode and multipass set. blockMode was a refactored name of multipass, so these should not both be present. multipass is deprecated. (E: bde5efd1a3e449dca549c5bff147f09b)");if(!u&&p&&(console.warn(`${t}[WARNING] "multipass" option is deprecated. this has been refactored to "blockMode". This will use multipass as blockMode. (W: 046b55a6d1304155b2e5352a9e6140b0)`),u=p),!u)throw new Error("(UNEXPECTED) blockMode required. This should be truthy in order to get to this impl fn. (E: 0b87871f81d849ef8f0263b7775bd3e3)");o||(console.warn(`${t} initial recursions required. defaulting to ${ve}`),o=ve),l=l||Ze,b=b||$r;let{maxBlockSize:E,maxPassSectionLength:$,numOfPasses:I}=u;!E&&$&&(console.warn(`${t}[WARNING] "maxPassSectionLength" option is deprecated. this has been refactored to "maxBlockSize". This will use maxPassSectioLength as maxBlockSize. (W: c28fe476105643e184d0ddd5d2aa8a5d)`),E=$),E=E||yr,I=I||Ir;let A="[validation]";if(!o||o<1){let G=`${A} initialRecursions required, and greater than 0 (E: dd96a75f0c504f34b1f9f2f32e011c50)`;console.error(G),g.push(G)}if(!n||n<1){let G=`${A} recursionsPerHash required, and greater than 0 (E: 64cf53e0bf9f4963be6b165ca4e6566d)`;console.error(G),g.push(G)}if(!s){let G=`${A} salt required (E: 136a5d237e0f4b1d89f8c87ac12a1507)`;console.error(G),g.push(G)}if(!a){let G=`${A} saltStrategy required (E: 457ed117bf224b9f86fe81ab6bc35381)`;console.error(G),g.push(G)}if(!i){let G=`${A} secret required (E: 5c363255055a45cfb07656e2f4854ed7)`;console.error(G),g.push(G)}if(!l){let G=`${A} encryptedDataDelimiter required (E: 1bbeb4dce19e4ac2bbe7d1e373739298)`;console.error(G),g.push(G)}if(!b){let G=`${A} indexingMode required (E: 693ebd2be64a438aa3b075d0cb0d92bf)`;console.error(G),g.push(G)}if(!ke.includes(b)){let G=`${A} invalid indexingMode (${b}). Must be one of ${ke} (E: 17435268651444e0b7a594135635fc58)`;console.error(G),g.push(G)}if(E<1){let G=`${A} maxBlockSize must be greater than 0 (E: 9f268207ae274b958fb91855331be259)`;console.error(G),g.push(G)}if(I<1){let G=`${A} numOfPasses must be greater than 0 (E: c3bcab79bb024d65b84947806290a7d4)`;console.error(G),g.push(G)}if(!Object.values(Ee).includes(c)){let G=`${A} only ${Object.values(Ee)} hash algorithms implemented`;console.error(G),g.push(G)}if(a&&!Je.includes(a)){let G=`${A} unknown saltStrategy: ${a}`;console.error(G),g.push(G)}if(g.length>0){let G={...r,errors:g};return delete G.dataToEncrypt,delete G.secret,G}let w=await Bt(e);if(d&&await je(w)!==e)throw new Error("decoding encoded hex failed for this data: The encoded hex did not reverse to the original data.");let _=await No({hexEncodedData:w,initialRecursions:o,recursionsPerHash:n,salt:s,saltStrategy:a,secret:i,hashAlgorithm:c,encryptedDataDelimiter:l,indexingMode:b,maxBlockSize:E,numOfPasses:I});if(d)try{let G=await qt({encryptedData:_,initialRecursions:o,recursionsPerHash:n,salt:s,saltStrategy:a,secret:i,hashAlgorithm:c,encryptedDataDelimiter:l,indexingMode:b,blockMode:u});if(G.decryptedData){if(G.decryptedData!==e)throw new Error("The ENCRYPTED data did not decrypt back to the original data. (E: 16b5f1a11e4f438ab38a7f124178a7b8)")}else throw new Error("Confirm check call to decrypt produced falsy decryptedData (E: a4fe82dee61f497e9dea188ea9c287a4)");(G.warnings||[]).length>0&&(h=h.concat(["Confirm check call to decrypt had warnings.",...G.warnings]))}catch(G){throw new Error(`${t} confirm failed. decrypt error: ${m(G)} (E: 782a84d9dc294ce9a6a325e3ab293adf)`)}let S={...r,encryptedData:_,warnings:h.length>0?h:void 0};return delete S.dataToEncrypt,delete S.secret,S}f(Po,"encryptImpl_blockMode");async function ji(r){let t=`[${ji.name}]`;try{if(!r)throw new Error("args required (E: 22e58e03c78f4c27bf18295b8d2cdd3a)");if(!r.dataToEncrypt)throw new Error("dataToEncrypt required (E: 168c9076e5434c83ba81e3485ee6f3e4)");r.salt=r.salt||await F(qe),r.saltStrategy=r.saltStrategy||Be,r.hashAlgorithm=r.hashAlgorithm||Fe,r.recursionsPerHash=r.recursionsPerHash||He;let e;return r.blockMode?e=await Po(r):e=await vo(r),(e.errors??[]).length>0&&e.errors.forEach(o=>console.warn(`${t} ${o}`)),(e.warnings??[]).length>0&&e.warnings.forEach(o=>console.warn(`${t} ${o}`)),e}catch(e){throw console.error(`${t}${e.message}`),e}}f(ji,"encrypt");async function Bi(r){let t=`[${Bi.name}]`;try{if(!r)throw new Error("args required (E: fcd9b4aad85c4deba5fe5fde0b9ecb30)");if(!r.encryptedData)throw new Error("encryptedData required (E: f879f612428b4283bae089acee929a58)");r.salt=r.salt||await F(qe),r.saltStrategy=r.saltStrategy||Be,r.hashAlgorithm=r.hashAlgorithm||Fe,r.recursionsPerHash=r.recursionsPerHash||He;let e;return r.blockMode||r.multipass?e=await qt(r):e=await Ft(r),(e.warnings??[]).length>0&&e.warnings.forEach(o=>console.warn(`${t} ${o}`)),(e.errors??[]).length>0&&e.errors.forEach(o=>console.warn(`${t} ${o}`)),e}catch(e){throw console.error(`${t}${e.message}`),e}}f(Bi,"decrypt");var yb=5e4;var Ib=De.appendPerHash,_b=10,Tb="SHA-256";var Ab="encryption",Gb="ciphertext";var Fi={local:"local",outerspace:"outerspace",innerspace:"innerspace"},Db=Object.values(Fi).concat(),qi={user:"user",sync:"sync"},Ro=Object.values(qi).concat(),Hi={node_filesystem:"node-filesystem"},Xi={aws_dynamodb:"aws-dynamodb"},Ki={...Hi,...Xi},Co=Object.values(Ki).concat(),Yi={get:"get",put:"put",delete:"delete"},Vi={can:"can",addrs:"addrs",latest:"latest",watch:"watch",unwatch:"unwatch",tjps:"tjps",dependencyGraph:"dependency-graph"};var Wi=!1,Tr=class r{static{f(this,"DynamicFormBuilder")}lc=`[${r.name}]`;items=[];what="";idPool=[];getNewId(){let t=`${this.lc}[${this.getNewId.name}]`;if(this.idPool?.length>0)return this.idPool.pop()??"";{let e=[],o="ABCDEFGHIJKLMNOPQRSTUVWXYZ",n=o.length;for(let a=0;a<32;a++){let i=Math.floor(Math.random()*n);e.push(o[i])}let s=e.join("");return Wi&&console.log(`${t} id: ${s} (I: c6591ffee6d5bbea79ed19cfa6630422)`),s}}forA({what:t}){return this.what=t||"thingy",this}addItem(t){t.uuid||(t.uuid=this.getNewId()),this.items.push(t)}with({idPool:t}){return t&&(this.idPool=t),this}and(){return this}name({of:t,required:e=!0,defaultValue:o}){return this.addItem({name:"name",description:`What to call this ${this.what}. Doesn't have to be unique, no spaces, up to 32 alphanumerics/underscores in length.`,label:"Name",placeholder:'e.g. "bob_the_cool"',regexp:cr({min:1,max:32,noSpaces:!0}),regexpErrorMsg:"1 to 32 characters, no spaces, underscores allowed.",required:e,dataType:"text",value:t,defaultValue:o}),this}description({of:t,required:e,defaultValue:o}){return this.addItem({name:"description",description:`Description/notes for this ${this.what}.`,label:"Description",placeholder:`Describe these ${this.what} settings here...`,regexp:cr({min:0,max:155,chars:yo}),regexpErrorMsg:`0 to 155 alphanumerics or any of ${yo}`,dataType:"textarea",required:e,value:t,defaultValue:o}),this}classname({of:t,required:e=!0}){return this.addItem({name:"classname",description:`Technical setting that is the name of the ${this.what}'s class in computer code.`,label:"Classname",regexp:cr({min:1,max:128,noSpaces:!0}),regexpErrorMsg:"1 to 128 alphanumerics or underscores without spaces",dataType:"text",value:t,readonly:!0,required:e}),this}uuid({of:t,label:e,required:o}){return this.addItem({name:"uuid",description:`Unique(ish) id of the ${this.what}.`,label:e??"ID",dataType:"text",value:t,regexp:z,regexpErrorMsg:"1 to 256 alphanumerics, underscores, dots, hyphens allowed.",readonly:!0,required:o}),this}version({of:t,required:e}){return this.addItem({name:"version",description:`Technical setting indicating the version of the ${this.what}.`,label:"Version",dataType:"text",value:t||"",readonly:!0,required:e}),this}customItem(t){return this.addItem(t),this}outputItems(){return this.items}outputForm({formName:t,label:e}){return{name:t,description:`This is a form for a ${this.what}`,label:e??this.what,items:this.items}}};var Qe=class r extends Tr{static{f(this,"WitnessFormBuilder")}lc=`[${r.name}]`;allowPrimitiveArgs({of:t,required:e=!0}){return this.addItem({name:"allowPrimitiveArgs",description:`Technical setting on if this ${this.what} accepts primitive incoming ibgibs`,label:"Allow Primitive Args",dataType:"toggle",value:t??!0,readonly:!0,required:e}),this}catchAllErrors({of:t,required:e=!0}){return this.addItem({name:"catchAllErrors",description:`Technical setting on what the ${this.what} does when it encounters an internal error.`,label:"Catch All Errors",dataType:"toggle",value:t??!0,readonly:!0,required:e}),this}persistOptsAndResultIbGibs({of:t,required:e=!0}){return this.addItem({name:"persistOptsAndResultIbGibs",description:`Technical setting on if the ${this.what} maintains an audit trail of all of its inputs/outputs.`,label:"Persist Opts and Result IbGibs",dataType:"toggle",value:t??!1,readonly:!0,required:e}),this}trace({of:t,required:e}){return this.addItem({name:"trace",description:`Technical setting on if the ${this.what}'s activity should be traced (logged to the console).`,label:"Trace",dataType:"toggle",value:t??!1,readonly:!0,required:e}),this}commonWitnessFields({data:t,allowPrimitiveArgs:e=!0,catchAllErrors:o=!0,persistOptsAndResultIbGibs:n=!0,trace:s=!0,version:a=!0}){return e&&this.allowPrimitiveArgs({of:t.allowPrimitiveArgs}),o&&this.catchAllErrors({of:t.catchAllErrors}),n&&this.persistOptsAndResultIbGibs({of:t.persistOptsAndResultIbGibs}),s&&this.trace({of:t.trace}),a&&this.version({of:t.version}),this}};var Ar=!1;function Ss({appData:r}){let t=`[${Ss.name}]`;try{if(Ar&&console.log(`${t} starting...`),!r)throw new Error("appData required (E: 3df782b29bc4406a87e4895cfcea28ed)");let e=[],{name:o,uuid:n,classname:s}=r;return o?o.match(jt)||e.push(`name must match regexp: ${jt}`):e.push("name required."),n?n.match(z)||e.push(`uuid must match regexp: ${z}`):e.push("uuid required."),s&&(s.match(jt)||e.push(`classname must match regexp: ${jt}`)),e}catch(e){throw console.error(`${t} ${e.message}`),e}finally{Ar&&console.log(`${t} complete.`)}}f(Ss,"validateCommonAppData");function Uo({appData:r,classname:t}){let e=`[${Uo.name}]`;try{let o=Ss({appData:r});if(o.length>0)throw new Error(`invalid appData: ${o} (E: 9aff04f0cfc54a5188ca8bc40764160d)`);if(t){if(r.classname&&r.classname!==t)throw new Error("classname does not match appData.classname (E: 66f1447eef97485fba521c40980f5eb5)")}else if(t=r.classname,!t)throw new Error("classname required (E: 5f6ffb4317044125b94f662070e1f40b)");let{name:n,uuid:s}=r;return`app ${t} ${n} ${s}`}catch(o){throw console.error(`${e} ${o.message}`),o}}f(Uo,"getAppIb");function zi({appIb:r}){let t=`[${zi.name}]`;try{if(!r)throw new Error("appIb required (E: 6b065aee67e641ba9f9c6db367ebb0fb)");let e=r.split(" ");return{appClassname:e[1],appName:e[2],appId:e[3]}}catch(e){throw console.error(`${t} ${e.message}`),e}}f(zi,"getInfoFromAppIb");async function Ji({fnPromptApp:r,ibgibs:t,space:e}){let o=`[${Ji.name}]`;try{if(Ar&&console.log(`${o} starting...`),!t)throw new Error("ibgibs all powerful service required. (E: b24e78de0d204dc78909022bee296b30)");e=e??await t.getLocalUserSpace({lock:!0});let n=await r(e,null);if(!n)throw new Error("resApp falsy after prompt for app. (E: 2225a567abcd680a5e957e81fbb64123)");let s=n.newIbGib,a=[];a.push(s),n.intermediateIbGibs?.forEach(d=>a.push(d)),n.dnas?.forEach(d=>a.push(d));for(let d=0;d<a.length;d++){let b=a[d],u=await oe({ibGib:b});if((u??[]).length>0)throw new Error(`(UNEXPECTED) invalid app ibgib created. validationErrors: ${u}. app: ${H(s.toIbGibDto())} (E: 54cfc2f6bc284ed79be91d2da5e4bd2f)`)}await ee({resTransform:n,space:e});let{zeroSpace:i,fnBroadcast:c,fnUpdateBootstrap:l}=t;return await Ne({ibGib:s,space:e,fnBroadcast:f(d=>c(d),"fnBroadcast")}),await St({type:"apps",rel8nName:mr,ibGibsToRel8:[s],space:e,zeroSpace:i,fnUpdateBootstrap:l,fnBroadcast:c}),s}catch(n){debugger;console.error(`${o} ${n.message}`);return}finally{Ar&&console.log(`${o} complete.`)}}f(Ji,"createNewApp");var Zi="0",Qi="chat_gib",ec="A chat app done ibgib style, enabling infinitely nesting comments, pics and links. It's ibgibs all the way down...",xs={version:"1",uuid:Zi,name:Qi,description:ec,classname:"ChatApp_V1",icon:"chatbubbles",persistOptsAndResultIbGibs:!1,allowPrimitiveArgs:!0,catchAllErrors:!0,trace:!1},Os=void 0;var tc="0",rc="raw_gib",oc="Explorer app for navigating raw ibgib data.",Ds={version:"1",uuid:tc,name:rc,description:oc,classname:"RawApp_V1",icon:"paper-plane",persistOptsAndResultIbGibs:!1,allowPrimitiveArgs:!0,catchAllErrors:!0,trace:!1},vs=void 0;var Mo="0",nc="todo_gib",sc="Todo app for viewing and interacting with ibgibs like they're checklists.",Ns={version:"1",uuid:Mo,name:nc,description:sc,classname:"TodoApp_V1",icon:"checkbox",persistOptsAndResultIbGibs:!1,allowPrimitiveArgs:!0,catchAllErrors:!0,trace:!1},Ls=void 0;async function ko(r){let t=`[${ko.name}]`,e=[];try{y({ibGib:r})!==ze&&e.push(`invalid bootstrapSpace addr. Should equal "${ze}" (E: ecfdbed719284db7a1aa3f867f706fe9)`);let n=await oe({ibGib:r});(n?.length??!1)&&n.forEach(i=>e.push(i));let s=r.data,a=r.rel8ns;return Object.keys(s||{}).length===0&&e.push("invalid bootstrapSpace data. data required (E: 5a9bd15dd0644f9b93cafbbba660cfdf)"),(s.spaceIds??[]).length===0&&e.push("invalid bootstrapSpace, data.spaceIds required. (E: 6b91ddc12cfd41e59ded7d7502c1909f)"),Object.keys(r.rel8ns||{}).length===0&&e.push("invalid bootstrapSpace rel8ns (empty). Should have at least one rel8n, with rel8nName corresponding to the spaceId (E: b188ce4ae25e49f794f35e141bc2ecde)"),s.spaceIds.forEach(i=>{(a[i]??[]).length===0&&e.push(`invalid bootstrap. Each spaceId listed in data should have a corresponding address in rel8ns. spaceId (${i}) missing. (E: 62dd0d76e29a415a98b4b27deb8db17e)`)}),s[_e]?(a[s[_e]]??[]).length===0&&e.push(`invalid bootstrap. data.${_e} (${s[_e]}) not found in rel8ns. (E: 44d0799d232f4a51a0b0019ebebe019f)`):e.push(`invalid bootstrap. data.${_e} required. (E: f763af2e275f445cbf1db5801bacafad)`),e.length===0?!0:(console.error(`${t} errors: ${e.join("|")}`),!1)}catch(o){return console.error(`${t} ${o.message}`),!1}}f(ko,"validateBootstrapIbGib");var xt="meta_stone";var jo="undefined",Ht="target",Gr="targetTjp";var ye=!1;function Rs({ib:r}){let t=`[${Rs.name}]`;try{ye&&console.log(`${t} starting...`);let e=[],o=r.split(" ");o[0]!==xt&&e.push(`${t} invalid ib. atom is expected to be META_STONE_ATOM: ${xt} (E: a9812bffc18f44418aa091fb0ed260bd)`);let s=o[1],a=At({gib:s})??[];a.length>0&&e.push(`invalid ib. pieces[1] should be a valid tjpGib. validation errors: ${a} (E: 233db2babfbe4d28a80f98261f1c0e01)`);let i=o[2],c=Number.parseInt(i);isNaN(c)&&e.push("invalid ib. space-delimited pieces[2] should be valid integer (E: 71df0d6abd7b4cf4b11621e6bfb556cd)");let l=o[3];if(l!=="undefined"){let d=Xt({timestamp:l});d.valid||e.push(`invalid ib. pieces[3] should be valid timestampInTicks. emsg: (${d.emsg}) (E: 06dae01d66f54f54b71d9c920c730840)`)}return e}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{ye&&console.log(`${t} complete.`)}}f(Rs,"validateCommonMetaStoneIb");function Bo({data:r}){let t=`[${Bo.name}]`;try{if(ye&&console.log(`${t} starting...`),!r)throw new Error("data required (E: c50ac422af4501b72af12481fbd4961e)");let e=[],{targetData:o,timestamp:n}=r;Xt({timestamp:n}).valid||e.push("invalid timestampInTicks. should be valid ticks number. (E: 7e381ed5b0c8486b90cfd37676da3626)");let{tjpGib:a,n:i,timestamp:c}=o;if(a&&a!=="undefined"){let d=At({gib:a})??[];d.length>0&&e.push(`invalid data (targetTjpGib). validation errors: ${d} (E: d216b12eb75544ef8c5ffb27cd132e2e)`)}if(typeof i!="number"&&e.push("invalid n. should be valid integer. if target.data.n is falsy, targetN should be -1 (E: 8f234967b388ad80776c8054d71fbc23)"),c&&c!=="undefined"){let d=Xt({timestamp:c});d.valid||e.push(`invalid targetTimestamp. emsg: ${d.emsg} (E: c15d4fd2a2b74a0fab3223e83d954379)`)}let l=new Date(n);return e}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{ye&&console.log(`${t} complete.`)}}f(Bo,"validateCommonMetaStoneData");function Cs({rel8ns:r}){let t=`[${Cs.name}]`;try{if(ye&&console.log(`${t} starting...`),!r)throw new Error("rel8ns required (E: 7737ae550e2347e68c67b715c1221393)");let e=[],o=$o({rel8ns:r??{}})??[];o.length>0&&e.push(`invalid rel8ns intrinsically. errors: ${o.join("|")}. (E: abc91753f0f946afa0a3ea2c1917960f)`);let n=r[Ht]??[];n.length===0?e.push(`invalid metastone rel8ns. should have exactly 1 rel8nName ${Ht}. has 0. (E: 8181652da9e89613e204d245db12d723)`):n.length>1&&e.push(`invalid metastone rel8ns. should have exactly 1 rel8nName ${Ht}. has ${n.length}. (E: 2318047c6fea482d9f53febe02cf8912)`);let s=r[Gr]??[];return s.length>1&&e.push(`invalid metastone rel8ns. should have 0 or 1 rel8nName ${Gr}. has ${s.length}. (E: 34a8ae53825f46caa7ad024a64400db2)`),e}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{ye&&console.log(`${t} complete.`)}}f(Cs,"validateCommonMetaStoneRel8ns");async function ac({ibGib:r}){let t=`[${ac.name}]`;try{ye&&console.log(`${t} starting... (I: f32249d08105b997871a06cdee006311)`);let e=await oe({ibGib:r})??[];if(!r.data)throw new Error("MetaStoneIbGib.data required (E: 96432cf4f919d339277d9a1c61ea4264)");let o=[];try{let{atom:i,tjpGib:c,n:l,timestampInTicks:d}=Ms({ib:r.ib})}catch(i){o.push(m(i))}let n=Bo({data:r.data}),s=Cs({rel8ns:r.rel8ns}),a=[...e??[],...o??[],...n??[],...s??[]];return a.length>0?a:void 0}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{ye&&console.log(`${t} complete.`)}}f(ac,"validateCommonMetaStoneIbGib");function Us({data:r,classname:t}){let e=`[${Us.name}]`;try{let o=Bo({data:r});if(o.length>0)throw new Error(`invalid MetaStone data: ${o} (E: ac642cc5915f0fc0508cb2fb728c86fa)`);t&&ye&&console.log(`${e} classname not required. no big deal that it is provided here. (I: db4d41471cb976795afd3fa89f8cb823)`);let n=r.targetData.timestamp,s=n&&n!=="undefined"?ge(n):jo;return`${xt} ${r.targetData.tjpGib} ${r.targetData.n} ${s}`}catch(o){throw console.error(`${e} ${m(o)}`),o}}f(Us,"getMetaStoneIb");function Ms({ib:r}){let t=`[${Ms.name}]`;try{if(!r)throw new Error("MetaStone ib required (E: 8e74e098d7aeef52d3952e35150d83ed)");let e=Rs({ib:r});if(e.length>0)throw new Error(`invalid ib. validationErrors: ${e} (E: a6107f62200eb943e523f70f51300623)`);let o=r.split(" ");return{atom:o[0],tjpGib:o[1],n:Number.parseInt(o[2]),timestampInTicks:o[3]}}catch(e){throw console.error(`${t} ${m(e)}`),e}}f(Ms,"parseMetaStoneIb");function uu({addr:r,ibGib:t}){if(r||=y({ibGib:t}),!r)throw new Error("either addr or ibGib required. (E: 372b2574d5a9fac298119beed9f6e223)");return r.startsWith(`${xt} `)}f(uu,"isMetaStone");async function Fo({targetIbGib:r}){let t=`[${Fo.name}]`;try{ye&&console.log(`${t} starting... (I: d846313065c89c89e4b5afa2df2b7123)`);let e=y({ibGib:r}),o=be({ibGib:r,defaultIfNone:"incomingAddr"}),n,s={[Ht]:[e],[Gr]:[o]};if(!r.gib)throw new Error("(UNEXPECTED) targetIbGib.gib falsy? (E: 28eaa8a799021dadd87b043711aee826)");let a=r.data?.isTjp?r.gib:re({ibGibAddr:e}).tjpGib??r.gib;if(a===L)throw new Error("cannot create metastone for primitive ibgib (E: 2887e8ef83381a0698256b7bc7531826)");let i=new Date,c=xe(i),l=i.getMilliseconds();r.data?Kt({ibGib:r})?n={targetData:{n:-1,tjpGib:a},timestamp:c,timestampMs:l}:(n={targetData:{n:r.data.n??-1,tjpGib:a,timestamp:r.data.timestamp??jo},timestamp:c,timestampMs:l},r.data?.isTjp&&(n.targetData.isTjp=!0)):n={targetData:{n:-1,tjpGib:a},timestamp:c,timestampMs:l};let d=Us({data:n}),b=await Te({parentPrimitiveIb:xt,ib:d,data:n,rel8ns:s});return ye&&(console.log(`${t} metaStoneIbGib... (I: 2b16197478488b329246d22d2dc41423)`),console.dir(b)),b}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{ye&&console.log(`${t} complete.`)}}f(Fo,"newUpMetaStone");var Sr="witness",Yt="witness_arg",xr="witness_result",gu="context";var T=!1;async function ne({addr:r,addrs:t,isDna:e,space:o,force:n}){let s=`[${ne.name}]`;try{if(T&&console.log(`${s} starting...`),!o)throw new Error("space required. (E: 4d188d6c863246f28aa575753a052304)");if(!r&&(t??[]).length===0)throw new Error("addr or addrs required. (E: 1a0b92564ba942f1ba91a089ac1a2125)");r&&(t?.length??0)>0&&(console.warn(`${s} both addr and addrs provided, but supposed to be used one or the other. (W: 87226c2ac50e4ea28211334a7b58782f)`),t.includes(r)||t.push(r)),t=(t??[]).length>0?t:[r];let a=await o.argy({ibMetadata:Ge({space:o}),argData:{cmd:"get",ibGibAddrs:t,isDna:e}}),i=await o.witness(a);return i?.data?.success?(T&&console.log(`${s} got.`),{success:!0,ibGibs:i.ibGibs,rawResultIbGib:i}):(T&&console.log(`${s} didn't get.`),{success:!1,errorMsg:i.data?.errors?.join("|")||`${s} something went wrong. addrs: ${t.join(`
|
|
1
|
+
var Gi=Object.defineProperty;var f=(r,t)=>Gi(r,"name",{value:t,configurable:!0});var z=/^[a-zA-Z0-9_\-.]{1,256}$/,Ye=/^[a-zA-Z0-9_]{1,255}$/,qn=/^(\[.+\])?\s?(\(UNEXPECTED\)|\(unexpected\))?(.+)(\([EIWeiw]: [a-fA-F\d]{32}\))(\(UNEXPECTED\)|\(unexpected\))?$/,Hn=/^(\[.+\]).+$/,Xn=/^[0-9a-fA-F]{32}$/,Kn=/^[0-9a-fA-F]{64}$/;var yt="/",Vn="_nonalphanumerics_";var It=!1,Yn=globalThis.crypto,{subtle:xi}=Yn,we={sha_256:"SHA-256",sha_512:"SHA-512"};function v(r){return JSON.parse(JSON.stringify(r))}f(v,"clone");function xe(r){return(r??new Date).toUTCString()}f(xe,"getTimestamp");async function ce({s:r,algorithm:t="SHA-256"}){if(!r)return"";try{let e=Object.values(we);if(!e.includes(t))throw new Error(`Only ${e} implemented (E: 73cb52cd4d7f70c3415fdf695ba6ba23)`);let o=new TextEncoder().encode(r),n=await xi.digest(t,o);return Array.from(new Uint8Array(n)).map(a=>a.toString(16).padStart(2,"0")).join("")}catch(e){throw console.error(m(e.message)),e}}f(ce,"hash");async function F(r=64){let t="";if(r<32)throw new Error("Seed size must be at least 32");if(!globalThis.crypto)throw new Error("Cannot create UUID, as unknown crypto library version. If using node.js, v19+ is required. (E: c02cee3fd8a94f678d3f4ebe9dc49797)");let e=Yn.getRandomValues(new Uint8Array(16));if(t=await ce({s:e.join("")}),!t)throw new Error("Did not create UUID...hmm...");return t}f(F,"getUUID");function H(r){return JSON.stringify(r,null,2)}f(H,"pretty");async function le(r){return new Promise(t=>{setTimeout(()=>{t()},r)})}f(le,"delay");function m(r){return!r&&r!==0?"[error is falsy]":typeof r=="string"?r:typeof r.message=="string"?r.message:typeof r=="number"?JSON.stringify(r):r.error?(console.warn(`[${m.name}] this fn takes the raw error object. no destructure required. change your call from extractErrorMsg({error}) to extractErrorMsg(error). (W: ea49af5fd76d4b80a55a108d73a3e9b4)`),m(r.error)):`[error is not a string and error.message is not a string. typeof error: ${typeof r} (E: d5a7723ca59646838308bc9e53a43134)]`}f(m,"extractErrorMsg");function po({items:r,keyFn:t}){let e=`[${po.name}]`;try{let o={};for(let n=0;n<r.length;n++){let s=r[n],a=t(s);o[a]=[...o[a]??[],s]}return o}catch(o){throw console.error(`${e} ${o.message}`),o}}f(po,"groupBy");function cr({min:r,max:t,chars:e,noSpaces:o}){return r=r??1,t=t??999999999999,e=e??"",o?new RegExp(`^[\\w${e}]{${r},${t}}$`):new RegExp(`^[\\w\\s${e}]{${r},${t}}$`)}f(cr,"getRegExp");function ge(r){let t;if(r){if(t=new Date(r),t.toString()==="Invalid Date")throw new Error(`invalid date created by timestamp (${r}) (E: cbd6aeefe00708184e276ea3c2532b22)`)}else t=new Date;return t.getTime().toString()}f(ge,"getTimestampInTicks");function ho({startDate:r,years:t,months:e,days:o,hours:n,seconds:s}){let a=`[${ho.name}]`;try{return ct({startDate:r,years:t,months:e,days:o,hours:n,seconds:s}).toUTCString()}catch(i){throw console.log(`${a} ${i.message}`),i}}f(ho,"getExpirationUTCString");function ct({startDate:r,years:t,months:e,days:o,hours:n,seconds:s}){let a=`[${ct.name}]`;try{if(!r&&!t&&!e&&!o&&!n&&!s)throw new Error("either startDate or a time interval required. (E: 30248f8b306f443ab036fa8c313c50d8)");r=r?new Date(r):new Date;let i,c;return t?(i=r.getFullYear()+t,c=r.setFullYear(i),ct({startDate:new Date(c),months:e,days:o,hours:n,seconds:s})):e?(i=r.getMonth()+e,c=r.setMonth(i),ct({startDate:new Date(c),years:t,days:o,hours:n,seconds:s})):o?(i=r.getDate()+o,c=r.setDate(i),ct({startDate:new Date(c),years:t,months:e,hours:n,seconds:s})):n?(i=r.getHours()+n,c=r.setHours(i),ct({startDate:new Date(c),years:t,months:e,days:o,seconds:s})):s?(i=r.getSeconds()+s,c=r.setSeconds(i),ct({startDate:new Date(c),years:t,months:e,days:o,hours:n})):r}catch(i){throw console.log(`${a} ${i.message}`),i}}f(ct,"addTimeToDate");function go({expirationTimestampUTC:r}){let t=`[${go.name}]`;try{if(!r)throw new Error("expirationTimestampUTC required (E: 5eeb1e29f93d64f70c71a8112080a222)");let e=new Date(r);if(e.toUTCString()==="Invalid Date")throw new Error(`invalid expirationTimestampUTC: ${r} (E: 66a1a165bcf1f9336fe78856ab777822)`);return e<new Date}catch(e){throw console.error(`${t} ${e.message}`),e}}f(go,"isExpired");function lr(r){return Array.from(new Set(r))}f(lr,"unique");function Eo({obj:r,value:t,path:e,pathDelimiter:o,logalot:n}){let s=`[${Eo.name}]`;try{if(n&&console.log(`${s} starting...`),!r)throw new Error("obj required (E: 6a9dd32a361476e80b1bf7b91ec50522)");if(typeof r!="object")throw new Error("obj must be type 'object' (E: 66fdc289b32c06492bd95f5d266e6a22)");if(!e)throw new Error("path required (at the very least should be the key in the root obj.) (E: fc779e7794ead8a0b44e5f2e776b0e22)");o=o||yt;let a=r,i=e.split(o).filter(l=>!!l),c=i.pop();i.forEach(l=>{let d=a[l];if(d){if(typeof d!="object")throw new Error(`invalid path into object. Each step along the path must be typeof === 'object', but typeof targetObj["${l}"] === ${typeof d}. (value: ${d}) (E: 38cf29c5f624a40b4b56502c2ec39d22)`)}else a[l]={};a=a[l]}),a[c]=t}catch(a){throw console.error(`${s} ${a.message}`),a}finally{n&&console.log(`${s} complete.`)}}f(Eo,"patchObject");async function Rt({n:r}){let t=`[${Rt.name}]`;try{It&&console.log(`${t} starting...`);let e=[];for(let o=0;o<r;o++){let n=await F();e.push(n.substring(0,16))}return e}catch(e){throw console.error(`${t} ${e.message}`),e}finally{It&&console.log(`${t} complete.`)}}f(Rt,"getIdPool");function Oi({text:r,length:t,keepLiterals:e=["-"],replaceMap:o}){let n=`[${Oi.name}]`;try{if(It&&console.log(`${n} starting... (I: 27437e312e5aa621adfebb84e059c822)`),!r)throw new Error("text required (E: 87e0493613c8b30dfade83e1d2862a22)");let s=r,a={};e=e??[];for(let c=0;c<e.length;c++){let l=e[c],d;do d=Wn({count:10});while(d.includes(l)||l.includes(d)||r.includes(d));if(s.includes(l))for(a[d]=l;s.includes(l);)s=s.replace(l,d)}if(o&&Object.keys(o).length>0)for(let c=0;c<Object.keys(o).length;c++){let l=Object.keys(o)[c],d=o[l];for(;s.includes(l);)s=s.replace(l,d)}s=s.replace(/\W/g,"");let i=Object.keys(a);for(let c=0;c<i.length;c++){let l=i[c];for(;s.includes(l);)s=s.replace(l,a[l])}return t&&t>0&&s.length>t&&(It&&console.log(`${n} curtailing length (I: d7a28e05daa5979c7686b4c1cf519b23)`),s=s.substring(0,t)),s.length===0&&(s=Vn),s}catch(s){throw console.error(`${n} ${s.message}`),s}finally{It&&console.log(`${n} complete.`)}}f(Oi,"getSaferSubstring");function Di({x:r}){if((r??[]).length===0)return;let t=Math.floor(Math.random()*r.length);return r[t]}f(Di,"pickRandom");function Wn({count:r}){let t=`${Wn.name}]`;try{if(!Number.isInteger(r))throw new Error("count required to be a number. (E: c0a21d884ebd9afc4b2e8025207e0522)");let e="";for(let o=0;o<r;o++)e+=Di({x:"a b c d e f g h i j k l m n o p q r s t u v w x y z".split(" ")});if(e.length!==r)throw new Error(`${t} (UNEXPECTED) result.length !== count ? (E: 9bec4ec8f78610d8055e565415392a22)`);return e}catch(e){throw console.error(`${t} ${e.message}`),e}finally{It&&console.log(`${t} complete.`)}}f(Wn,"pickRandom_Letters");function _t({dominant:r,recessive:t}){let e=`[${_t.name}]`;try{if(Array.isArray(r)&&Array.isArray(t)){let o=v(r),n=!1;return t.forEach(s=>{if(typeof s=="string")o.includes(s)||o.push(s);else{n||(console.warn(`${e} merging arrays of non-string elements. (W: d8ab113064834abc8eb5fe6c4cf87ba3)`),n=!0);let a=JSON.stringify(s);o.some(i=>JSON.stringify(i)===a)||o.push(s)}}),o}else if(typeof r=="object"&&typeof t=="object"){let o={...t},n=Object.keys(r),s=Object.keys(t);return n.forEach(a=>{s.includes(a)?Array.isArray(r[a])&&Array.isArray(t[a])?o[a]=_t({dominant:r[a],recessive:t[a]}):r[a]&&!Array.isArray(r[a])&&typeof r[a]=="object"&&t[a]&&!Array.isArray(t[a])&&typeof t[a]=="object"?o[a]=_t({dominant:r[a],recessive:t[a]}):o[a]=r[a]:o[a]=r[a]}),o}else return console.warn(`${e} unknown values or value types do not match. Both should either be an array or map. Dominant one wins categorically without any merging. (W: 3690ea19b81a4b89b98c1940637df62c)`),r}catch(o){throw console.error(`${e} ${o.message}`),o}}f(_t,"mergeMapsOrArrays_Naive");var vi=globalThis.crypto,{subtle:Zn}=vi,Qn=new Array(256);for(let r=0;r<256;++r)Qn[r]=r.toString(16).padStart(2,"0");function es(r){let t=new Uint8Array(r),e="";for(let o=0;o<t.length;o++)e+=Qn[t[o]];return e}f(es,"bufToHex");function Mt(r){if(r===null||typeof r!="object")return r;if(Array.isArray(r))return r.map(o=>Mt(o));let t={},e=Object.keys(r).sort();for(let o of e){let n=r[o];n!==void 0&&(t[o]=Mt(n))}return t}f(Mt,"toNormalizedForHashing");async function Ut(r){if(!r)return"";let t=new TextEncoder().encode(r),e=await Zn.digest("SHA-256",t);return es(e)}f(Ut,"hashToHex");async function Ni(r,t){let e;if(r){let n=new TextEncoder().encode(r);e=new Uint8Array(n.length+t.length),e.set(n),e.set(t,n.length)}else e=t;let o=await Zn.digest("SHA-256",e);return es(o)}f(Ni,"hashToHex_Uint8Array");var Li=!1,dr=0,zn=0;async function Jn(r,t=""){let e=t||"",o=r.ib,n=r.data,s=r.rel8ns,a=Object.keys(s||{}).length>0&&Object.keys(s||{}).some(u=>s[u]&&s[u].length>0),i=!!n;i&&(typeof n=="string"?i=n.length>0:n instanceof Uint8Array?i=!0:typeof n=="object"?i=Object.keys(n||{}).length>0:i=!0);let c=(await Ut(e?e+o:o)).toUpperCase(),l="";if(a){let u=Mt(s),p=JSON.stringify(u);l=(await Ut(e?e+p:p)).toUpperCase()}let d="";if(i)if(n instanceof Uint8Array)d=(await Ni(e,n)).toUpperCase();else{let u=Mt(n),p=JSON.stringify(u);d=(await Ut(e?e+p:p)).toUpperCase()}let b;if(a||i){let u=c+l+d;b=(await Ut(e?e+u:u)).toUpperCase()}else b=(await Ut(e?e+c:c)).toUpperCase();return b}f(Jn,"sha256v1_Internal");async function We(r,t=""){if(Li){let e=globalThis.performance?globalThis.performance.now():Date.now(),o=await Jn(r,t),n=(globalThis.performance?globalThis.performance.now():Date.now())-e;return dr++,zn+=n,dr%1e3===0&&console.log(`[sha256v1 Profile] Total Runs: ${dr} | Average Duration: ${(zn/dr).toFixed(4)} ms`),o}return Jn(r,t)}f(We,"sha256v1");function y({ib:r,gib:t,ibGib:e,delimiter:o="^"}){return r=r||e?.ib||"",t=t||e?.gib||"",r+o+t}f(y,"getIbGibAddr");function C({ibGib:r,ibGibAddr:t,delimiter:e="^"}){let o="[getIbAndGib]";if(!t)if(r)t=y({ibGib:r});else throw new Error(`${o} We need either an address or an ibGib object`);if(!t)throw new Error(`${o} Couldn't get ibGibAddr. ibGib invalid?`);e||(e="^");let n=t.split(e);return n.length===2?{ib:n[0],gib:n[1]}:n.length===1&&t.endsWith(e)?{ib:n[0],gib:""}:n.length===1&&t.startsWith(e)?{ib:"",gib:n[0]}:n.length===2&&n[0]===""&&n[1]===""?{ib:e,gib:""}:(console.warn(`${o} multiple delimiters found in ibGibAddr. Considering last delimiter as the demarcation of gib hash`),{ib:n.slice(0,n.length-1).join(e),gib:n.slice(n.length-1)[0]})}f(C,"getIbAndGib");var K;(function(r){r.past="past",r.ancestor="ancestor",r.dna="dna",r.identity="identity",r.tjp="tjp",r.secret="secret",r.encryption="encryption"})(K||(K={}));var Tt="ib",L="gib",Y={ib:Tt,gib:L},J="^",Oe=".",ts="ib^gib",lt=["past","ancestor","dna","tjp"],Ci=155,rs=new RegExp(`^[\\w\\t\\-|=+.&%$#@!~\` \\[\\]\\(\\)\\{\\}]{1,${Ci}}$`);async function dt(r){let t=v(r),e=`[${dt.name}]`;t.srcAddr&&delete t.srcAddr,delete t.src;let o={ib:t.type,data:t,rel8ns:{ancestor:[`${t.type.toString()}${J}${L}`]}};return o.gib=await We(o),o}f(dt,"buildDna");function Pi({ibGib:r}){let t=`[${Pi.name}]`;try{if(!r)throw new Error("ibGib required.");let e=["fork","mut8","rel8","plan"].map(n=>`${n}^${L}`);return r.rel8ns&&r.rel8ns.ancestor&&Array.isArray(r.rel8ns.ancestor)&&r.rel8ns.ancestor.some(n=>e.includes(n))||!1}catch(e){throw console.error(`${t} ${m(e)}`),e}}f(Pi,"isDna");function Z({ibGib:r,gib:t}){return r?Z({gib:r.gib}):t?t===L:!0}f(Z,"isPrimitive");async function X({ibGib:r,hasTjp:t,tjpAddr:e,gibDelimiter:o,isPrimitive:n,hashAlgorithm:s}){let a=`[${X.name}]`;try{if(!r)throw new Error("ibGib required. (E: 17d073226b9d42fd841e5a94b065ef21)");if(n)return L;let i=await We(r,""),c=r.rel8ns??{},l=r.data??{};if(o=o||Oe,t||(t=(c.tjp??[]).length>0||l.isTjp||!1),t){let d;if(c.tjp)if(c.tjp.length===1)if(c.tjp[0])e=c.tjp[0];else throw new Error("rel8ns.tjp[0] is falsy. (E: ed879d2b039543f8b1902e8b7b5a5a7b)");else if(c.tjp.length>1)if(c.tjp[c.tjp.length-1])console.warn(`${a} found more than one tjp addr...only expecting 1 ATOW. (W: 10ed43f716e743e0afd1954f1ab46789)`),e=c.tjp[c.tjp.length-1];else throw new Error("multiple tjp addrs, and the last (most recent) one is falsy. (E: bc835dc89be24075bba8b2b6616ea069)");else throw new Error("hasTjp is true but rel8ns.tjp is empty array. (E: d08b2f9e86494814b5e7d7b4602b2ab7)");else if(l.isTjp)e=y({ib:r.ib,gib:i});else throw new Error("hasTjp is true, but both ibGib.rel8ns.tjp and ibGib.data.isTjp are falsy. (E: 4e246897e52044789594d853bb5b66ee)");if(d=e?C({ibGibAddr:e}).gib:void 0,d)return l.isTjp?i:`${i}${Oe}${d}`;throw new Error("hasTjp is true but could not find tjpAddrGib. (E: 1863df626b754744a1d431a683cb0ba0)")}else return i}catch(i){throw console.error(`${a} ${m(i)}`),i}}f(X,"getGib");function re({ibGibAddr:r,gib:t,gibDelimiter:e}){let o=`[${re.name}]`;try{if(!r&&!t)throw new Error("Either ibGibAddr or gib required. (E: 25e3dcbe63cd44909032df12af9df75e)");if(t=t||C({ibGibAddr:r}).gib,t===L)return{isPrimitive:!0};if(e=e??Oe,t.includes(e)){let n=t.split(e);if(n.some(i=>i===""))throw new Error(`unexpected gib that contains gibDelimiter (${e}) but has at least one piece with empty string. (E: 75a94280045541009ee68182d12d3449)`);let s=n.length;return s>2&&console.warn(`${o} gib only expected to have two pieces ATOW. re-examine please. (W: aa4283ac5a5747a386a69966ecdad39d)`),{punctiliarHash:n.splice(0,1)[0],tjpGib:n.join(e),piecesCount:s,delimiter:e}}else return{punctiliarHash:t,piecesCount:1,delimiter:e}}catch(n){throw console.error(`${o} ${m(n)}`),n}}f(re,"getGibInfo");async function fr(r){let{noTimestamp:t,dna:e,linkedRel8ns:o,destIb:n,uuid:s,tjp:a,cloneRel8ns:i,cloneData:c,type:l="fork"}=r,d=r.src,b="[fork_v1]";if(l!=="fork")throw new Error(`${b} not a fork transform.`);if(r.type||(r.type="fork"),!d)throw new Error(`${b} src required to fork.`);if(!d.ib)throw new Error(`${b} src.ib required.`);if(n&&n.includes(J))throw new Error(`${b} destIb can't contain (hardcoded) delimiter right now.`);if(!d.gib)throw new Error(`${b} src.gib required.`);let u={ib:d.ib,gib:d.gib};d.data&&Object.keys(d.data).length>0&&(u.data=d.data),d.rel8ns&&Object.keys(d.rel8ns).length>0&&(u.rel8ns=d.rel8ns),d=u;let p=y({ib:d.ib,gib:d.gib});r.srcAddr=p;let g=i&&d.rel8ns&&Object.keys(d.rel8ns).length>0?v(d.rel8ns):{};delete g.past;let h=c&&d?.data?v(d.data):{};r.nCounter&&(h.n=0);let E=o?.includes(K.ancestor)?[p]:(g.ancestor||[]).concat([p]);g.ancestor=E,g.tjp&&delete g.tjp;let $=v(d);if(t&&a?.timestamp)throw new Error(`${b} both noTimestamp and tjp.timestamp selected.`);if(!t||a?.timestamp){let w=new Date;h.timestamp=xe(w),h.timestampMs=w.getMilliseconds()}(a?.uuid||s)&&(h.uuid=await F()),a?.uuid||a?.timestamp?h.isTjp=!0:h.isTjp&&delete h.isTjp,$.ib=n||"ib",p!==ts&&($.rel8ns=g),Object.keys(h).length>0&&($.data=h);let I=null;if(e){I=await dt(r);let w=y({ibGib:I});g.dna=o?.includes(K.dna)?g.dna=[w]:g.dna=(g.dna||[]).concat(w)}$.gib=await We($,"");let A={newIbGib:$};return I&&(A.dnas=[I]),A}f(fr,"fork");async function Me(r){let{noTimestamp:t,dna:e,linkedRel8ns:o,dataToRename:n,dataToRemove:s,dataToAddOrPatch:a,mut8Ib:i,type:c="mut8"}=r,l=r.src,d="[mut8_v1]";if(c!=="mut8")throw new Error(`${d} not a mut8 transform.`);if(r.type||(r.type="mut8"),!l)throw new Error(`${d} src required to mut8.`);if(!l.ib)throw new Error(`${d} src.ib required.`);if(l.ib.includes(J))throw new Error(`${d} ib can't contain hardcoded delimiter (${J}) right now.`);if(!l.gib)throw new Error(`${d} src.gib required.`);if(!i&&!n&&!s&&!a)throw new Error(`${d} gotta provide either a mut8Ib or some data to change.`);let b=y({ib:l.ib,gib:l.gib});if(r.srcAddr&&b!==r.srcAddr)throw new Error(`${d} srcAddr from src does not equal opts.srcAddr`);if(r.srcAddr=b,Z({ibGib:l}))throw new Error(`${d} cannot mutate primitive ibgib`);let u={ib:l.ib,gib:l.gib};l.data&&Object.keys(l.data).length>0&&(u.data=l.data),l.rel8ns&&Object.keys(l.rel8ns).length>0&&(u.rel8ns=l.rel8ns),l=u;let p=v(l),g=l.rel8ns?l.rel8ns:{},h=v(g);h.past=o?.includes(K.past)?[b]:(h.past||[]).concat([b]);let E=l?.data?v(l.data):{};if(n&&(E=mo(E,n,"rename")),s&&(E=mo(E,s,"remove")),a&&(E=os(E,a)),!t){let _=new Date;E.timestamp=xe(_),E.timestampMs=_.getMilliseconds()}if(r.nCounter||Object.keys(E).includes("n"))if(Object.keys(E).includes("n"))if(Number.isInteger(E.n))E.n>=0?E.n=E.n+1:(console.warn(`${d} data.n is less than 0, which is unexpected. Resetting data.n to 0.`),E.n=0);else throw new Error("cannot increment nCounter because data.n is not a number.");else E.n=0;if(E.isTjp){let _=h.tjp??[];_.push(b),h.tjp=_,delete E.isTjp}let I=null;if(e){I=await dt(r);let _=y({ibGib:I});h.dna=o?.includes(K.dna)?h.dna=[_]:h.dna=(h.dna||[]).concat(_)}p.ib=i||p.ib,p.rel8ns=h,Object.keys(E).length>0?p.data=E:delete p.data;let A=(h.tjp?.length??0)>0;p.gib=await X({ibGib:p,hasTjp:A});let w={newIbGib:p};return I&&(w.dnas=[I]),w}f(Me,"mut8");function mo(r,t,e){let o="[renameOrRemove]",n=["timestamp"];return Object.keys(t).forEach(s=>{if(n.includes(s))throw new Error(`${o} Cannot rename to ${s}.`);if(Object.keys(r).includes(s)){let a=t[s];if(typeof a=="string"){if(n.includes(a))throw new Error(`${o} Cannot rename to ${a}.`);e==="rename"&&(r[a]=r[s]),delete r[s]}else r[s]=mo(r[s],a,e)}else console.log(`${o} key to ${e} does not exist`)}),r}f(mo,"renameOrRemove");function os(r,t){return Object.keys(t).forEach(e=>{let o=t[e],n=r[e];n?Array.isArray(o)||Array.isArray(n)?r[e]=o:typeof o=="object"&&typeof n=="object"?r[e]=os(n,o):r[e]=o:r[e]=o}),r}f(os,"patch");async function Ie(r){let{noTimestamp:t,dna:e,linkedRel8ns:o,rel8nsToAddByAddr:n,rel8nsToRemoveByAddr:s,type:a="rel8"}=r,i=r.src,c="[rel8_v1]";if(a!=="rel8")throw new Error(`${c} not a rel8 transform.`);if(r.type||(r.type="rel8"),a!=="rel8")throw new Error(`${c} not a rel8 transform.`);if(r.type||(r.type="rel8"),!i)throw new Error(`${c} src required.`);if(!i.ib)throw new Error(`${c} src.ib required.`);if(i.ib.includes(J))throw new Error(`${c} ib can't contain hardcoded delimiter (${J}) right now.`);if(!i.gib)throw new Error(`${c} src.gib required.`);if(Z({ibGib:i}))throw new Error(`${c} cannot relate/unrelate primitive ibgib`);let l=n&&Object.keys(n).length>0,d=s&&Object.keys(s).length>0;if(!(l||d))throw new Error(`${c} gotta provide relations to either add or remove.`);let b=y({ib:i.ib,gib:i.gib});if(r.srcAddr&&b!==r.srcAddr)throw new Error(`${c} srcAddr from src does not equal opts.srcAddr`);r.srcAddr=b;let u=f(w=>w&&typeof w=="string"&&w.length>=2&&w.includes("^")&&w.split("^")[0].length>=1,"fnValidIbGibAddr");Object.keys(n||{}).map(w=>(n||{})[w]).forEach(w=>{if(!(w&&w.every(_=>u(_))))throw new Error(`${c} Invalid rel8n attempt. Must be valid ibGibs. Did you include a delimiter (^)?`)}),Object.keys(s||{}).map(w=>(s||{})[w]).forEach(w=>{if(!(w&&w.every(_=>u(_))))throw new Error(`${c} Invalid remove rel8n attempt. Must be valid ibGibs. Did you include a delimiter (^)?`)});let p={ib:i.ib,gib:i.gib};i.data&&Object.keys(i.data).length>0&&(p.data=i.data),i.rel8ns&&Object.keys(i.rel8ns).length>0&&(p.rel8ns=i.rel8ns),i=p;let g=v(i),h=v(i.data||{});if(r.nCounter||Object.keys(h).includes("n"))if(Object.keys(h).includes("n"))if(Number.isInteger(h.n))h.n>=0?h.n=h.n+1:(console.warn(`${c} data.n is less than 0, which is unexpected. Resetting data.n to 0.`),h.n=0);else throw new Error("cannot increment nCounter because data.n is not a number.");else h.n=0;if(!t){let w=new Date;h.timestamp=xe(w),h.timestampMs=w.getMilliseconds()}let E=v(i.rel8ns||{});if(Object.keys(n||{}).forEach(w=>{if(lt.includes(w))throw new Error(`${c} Cannot manually add relationship: ${w}.`);let _=E[w]||[],G=n[w].filter(O=>!_.includes(O));E[w]=_.concat(G)}),Object.keys(s||{}).forEach(w=>{if(lt.includes(w))throw new Error(`${c} Cannot manually remove relationship: ${w}.`);let _=E[w]||[],S=s[w]||[],G=_.filter(O=>!S.includes(O));G.length>0?E[w]=G:delete E[w]}),E.past=(E.past||[]).concat([b]),(o||[]).filter(w=>Object.keys(E).includes(w)).filter(w=>(E[w]||[]).length>1).forEach(w=>{let _=E[w].length;E[w]=[E[w][_-1]]}),h.isTjp){let w=E.tjp||[];w.push(b),E.tjp=w,delete h.isTjp}g.data=h,g.rel8ns=E;let $=(E.tjp?.length??0)>0,I=null;if(e){I=await dt(r);let w=y({ibGib:I});E.dna=o?.includes(K.dna)?E.dna=[w]:E.dna=(E.dna||[]).concat(w)}g.gib=await X({ibGib:g,hasTjp:$});let A={newIbGib:g};return I&&(A.dnas=[I]),A}f(Ie,"rel8");function br({ibGib:r}){let t=`[${br.name}]`;if(!r)return console.warn(`${t} ibGib falsy. (W: 884178562f5b4f15933ac4d98db74cc6)`),!1;if(r.data?.isTjp||r.rel8ns?.tjp?.length>0)return!0;let e=["fork^gib","mut8^gib","rel8^gib"];return(r.rel8ns?.ancestor??[]).some(n=>e.includes(n))?!1:r.gib?r.gib.includes(Oe)?!0:r.gib===L?!1:!!re({ibGibAddr:y({ibGib:r})}).tjpGib:(console.warn(`${t} ibGib.gib falsy. (W: 6400d780822b44d992846f1196509be3)`),!1)}f(br,"hasTjp");function ur({ibGib:r}){let t=`[${ur.name}]`;r.ib||console.warn(`${t} ibGib.ib is falsy. (W: e60e41c2a1fc48268379d88ce13cb77b)`),r.gib||console.warn(`${t} ibGib.gib is falsy. (W: fb3889cbf0684ae4ac51e48f28570377)`);let e={ib:(r.ib||"").slice()};return r.gib&&(e.gib=r.gib.slice()),r.data&&(e.data=r.data instanceof Uint8Array?r.data:v(r.data)),r.rel8ns&&(e.rel8ns=v(r.rel8ns)),e}f(ur,"toDto");var wo=!1;async function oe({ibGib:r}){let t=`[${oe.name}]`;try{let e=[];if(r){let o=y({ibGib:r});if(e=kt({addr:o})??[],e.length>0)return console.error(`${t} errors found in addr: ${o}`),e;if(Z({gib:r.gib}))return null;let n=await X({ibGib:ur({ibGib:r}),hasTjp:br({ibGib:r})});return n!==r.gib&&(r.data?.src&&r.data.srcAddr&&r.ib==="rel8"?(delete r.data.src,delete r.data.srcAddr,n=await X({ibGib:ur({ibGib:r}),hasTjp:br({ibGib:r})}),n!==r.gib&&e.push(`Ibgib invalid intrinsically - gottenGib (${n}) does not equal ibGib.gib (${r.gib}). (E: 020b71479e944b2198fe436e7e137786)`)):e.push(`Ibgib invalid intrinsically - gottenGib (${n}) does not equal ibGib.gib (${r.gib}). (E: 7416db016878430ca3c5b20697f164ed)`)),e.length>0?e:null}else return e.push("ibGib is itself falsy. (E: 4fb98caf6ed24ef7b35a19cef56e2d7e)"),e}catch(e){throw console.error(`${t} ${m(e)}`),e}}f(oe,"validateIbGibIntrinsically");function kt({addr:r,delimiter:t,version:e}){let o=`[${kt.name}]`;try{let n=[];if(e&&console.warn(`${o} version not implemented yet. Ignoring. (W: 2d19db16ec0c4766b5d35248787671f3)`),!r)return n.push("addr required. (E: e9a54041aa0b41c1bb2324d9d2d42c7f)"),n;t=t||J,r.includes(t)||n.push(`No delimiter (${t}) found. (E: 05e28dcb70ff44019edc53ed508bd1e8)`),r.startsWith(t)&&n.push("addr starts with delim. (E: d29f808c5a47452f9bb3ea684694c6eb)");let{ib:s,gib:a}=C({ibGibAddr:r,delimiter:t}),i=Gt({ib:s,ibGibAddrDelimiter:t,version:e});i&&(n=n.concat(i));let c=At({gib:a,ibGibAddrDelimiter:t,version:e});return c&&(n=n.concat(c)),n.length>0&&wo&&console.log(`${o} errors.length > 0. errors: ${n.join("|")} (I: 9c18f993e138f15613e4c6a340d41722)`),n.length>0?n:null}catch(n){throw console.error(`${o} ${m(n)}`),n}}f(kt,"validateIbGibAddr");function Gt({ib:r,ibGibAddrDelimiter:t,version:e}){let o=`[${Gt.name}]`;try{let n=[];return e&&console.warn(`${o} version not implemented yet. Ignoring. (W: 71228ba4ed994aaa8149910e295ab087)`),r?r===Tt?null:(t=t||J,r.includes(t)&&n.push(`ib contains ibGibAddrDelimiter (${t}) (E: 09e61b46c3e84874bc02b6918f1f2c39)`),n.length>0?n:null):(n.push("ib required. (E: a76d06c7b9c24db3a731a91dbe46acd5)"),n)}catch(n){throw console.error(`${o} ${m(n)}`),n}}f(Gt,"validateIb");function At({gib:r,gibDelimiter:t,ibGibAddrDelimiter:e,version:o}){let n=`[${At.name}]`;try{let s=[];if(o&&console.warn(`${n} version not implemented yet. Ignoring. (E: 90ced1db69774702b92acb261bdaee23)`),!r)return s.push("gib required. (E: e217de4035b04086827199f4bace189c)"),s;e=e||J;let a=[e],i=[];a.forEach(p=>{r.includes(p)&&i.push(p)}),i.length>0&&s.push(`gib (${r}}) contains invalid characters: (${JSON.stringify(i.join(","))}) (E: 1e584258d9e049ba9ce7e516f3ab97f1)`);let{punctiliarHash:c,tjpGib:l,isPrimitive:d}=re({gib:r,gibDelimiter:t||Oe});if(d)return null;if(!c)throw new Error(`${n} punctiliarHash is falsy on a non-primitive gib. (E: 72835394918241bdb2632bf0510bdae5)`);let b=c.match(Xn),u=c.match(Kn);if(!b&&!u&&s.push("gib punctiliar hash is neither a 32- or 64-char hash string. (E: d47ff6d6e14b4c02a62107090c8dad39)"),l){let p=At({gib:l});(p??[]).length>0&&s.push(`tjpGib has errors (E: d6b79228d4a64c0b967cdb0efcea4d0d). tjpGibValidationErrors: ${p.join(". ")}`)}return s.length>0?s:null}catch(s){throw console.error(`${n} ${m(s)}`),s}}f(At,"validateGib");function $o({rel8ns:r}){let t=`[${$o.name}]`;try{wo&&console.log(`${t} starting... (I: 62b4722599798dd8ab95fcebf42c0e23)`);let e=[],o=Object.keys(r);for(let n=0;n<o.length;n++){let s=Object.keys(r)[n];typeof s!="string"&&e.push("non-string rel8nName found. all keys of rel8ns must be of type string. (E: 3b2e4582b638421681951f5475c85178)");let a=r[s]??[];for(let i=0;i<a.length;i++){let c=a[i],l=kt({addr:c})??[];l.length>0&&e.push(`invalid addr found for rel8nName (${s}). addr errors: ${l.join("|")} (E: 56809a746c4f462db426e90395b80364)`)}}return e.length>0?e:null}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{wo&&console.log(`${t} complete.`)}}f($o,"validateRel8nsIntrinsically");var ns=!1,M=class r{static{f(this,"Factory_V1")}static root(){return r.primitive({ib:Tt})}static primitive({ib:t}){return{ib:t,gib:L}}static primitives({ibs:t}){return t.map(e=>r.primitive({ib:e}))}static async firstGen({ib:t=Tt,parentIbGib:e=r.root(),data:o,rel8ns:n,dna:s,tjp:a,linkedRel8ns:i,noTimestamp:c,nCounter:l,squash:d}){let b=`[${r.name}][${r.firstGen.name}]`;try{if(ns&&console.log(`${b} starting... (I: b7152fbd94382516d9f7c591bcf4c326)`),s&&d)throw new Error("both dna and squash cannot be true. Squash requires that no dna exist. (E: abfc58b4a4c8654924aa5428d0831826)");let u=[],p=e||Y,g=await fr({src:p,destIb:t,tjp:a,dna:s,linkedRel8ns:i,noTimestamp:c,nCounter:l});if(u.push(g),p=g.newIbGib,o){let h=await Me({src:p,dataToAddOrPatch:o,dna:s,linkedRel8ns:i,noTimestamp:c,nCounter:l});u.push(h),p=h.newIbGib}if(n){let h=await Ie({src:p,rel8nsToAddByAddr:n,dna:s,linkedRel8ns:i,noTimestamp:c,nCounter:l});u.push(h)}if(u.length>1){let h=u.slice(u.length-1)[0].newIbGib,E={newIbGib:h,intermediateIbGibs:u.slice(0,u.length-1).map($=>$.newIbGib)};if(s){d&&`${b}`;let $=[];return u.forEach(I=>{$=$.concat(I.dnas)}),E.dnas=$,E}else if(d){if(!h.rel8ns)throw new Error("(UNEXPECTED) newIbGib.rel8ns is falsy? (E: 6b09e8057fc5b00c6cfd13be60e97f26)");return delete h.rel8ns.past,h.rel8ns.tjp&&(delete h.rel8ns.tjp,h.data??={},h.data.isTjp=!0),l&&(h.data??={},h.data.n=0),h.gib=await X({ibGib:h}),{newIbGib:h}}else return E}else{if(u.length===1)return u[0];throw new Error("(UNEXPECTED) interimResults.length is not 1 and not greater than 1? 0? But we had to fork? (E: a256c88c56916a46a888796f76ef4826)")}}catch(u){throw console.error(`${b} ${m(u)}`),u}finally{ns&&console.log(`${b} complete.`)}}static async stone({parentPrimitiveIb:t,ib:e,ibRegExpPattern:o,data:n,rel8ns:s,noTimestamp:a,uuid:i}){let c=`[${r.name}][${r.stone.name}]`;try{if(!t)throw new Error("parentPrimitiveIb required. (E: genuuid)");if(Gt({ib:t})!==null)throw new Error(`Invalid parentPrimitiveIb: ${t}. (E: genuuid)`);if(!e)throw new Error("ib required. (E: genuuid)");let l=o?new RegExp(o):rs;if(!e.match(l))throw new Error(`invalid ib. does not match regexp (${l}) (E: genuuid)`);let d=Object.keys(s??{}),b=[...lt,"tjp"];if(d.some(h=>b.includes(h)))throw new Error(`Invalid rel8ns. forbiddenRel8nNames: ${b}. rel8ns keys: ${Object.keys(s??{})}. (E: genuuid)`);let g=(await r.firstGen({ib:e,parentIbGib:r.primitive({ib:t}),data:n,rel8ns:s,dna:!1,noTimestamp:a,nCounter:!1})).newIbGib;return i&&(g.data||(g.data={}),g.data.uuid=await F()),g.rel8ns?.past&&delete g.rel8ns.past,g.rel8ns?.tjp&&delete g.rel8ns.tjp,g.gib=await X({ibGib:{ib:g.ib,data:g.data,rel8ns:g.rel8ns},hasTjp:!1}),g}catch(l){throw console.error(`${c} ${l.message}`),l}}static async constant({parentPrimitiveIb:t,ib:e,ibRegExpPattern:o,data:n,rel8ns:s}){let a=`[${r.name}][${r.constant.name}]`;try{return await r.stone({parentPrimitiveIb:t,ib:e,ibRegExpPattern:o,data:n,rel8ns:s,noTimestamp:!0,uuid:!1})}catch(i){throw console.error(`${a} ${i.message}`),i}}};var Sd="[core^gib timer]";var yo=`.'",!?-`;var ss=new RegExp("^[\\w\\t\\-|=+.&%$#@!~` \\[\\]\\(\\)\\{\\}]{1,155}$");var xd=/^[a-zA-Z0-9_\-.]{1,255}$/,Od=/^[a-zA-Z0-9_\-.\s👀🤖:;&]{1,64}$/;var pr={tags:"tags",aliases:"aliases",roots:"roots",outerspaces:"outerspaces",secrets:"secrets",encryptions:"encryptions",autosyncs:"autosyncs",robbots:"robbots",apps:"apps",history:"history"};var Ri="robbot";var as="zero",is="zerospace";var Xd=!1,Kd="This is a local space. There are many like it, but this one is mine.";var Vd=/^[a-zA-Z][\w\-]{0,62}[a-zA-Z]$/,Ui="syncSpace";var Yd=3e4;var hr="space";var cs="space_lock",ls=100,ds=100,Wd=60*2,gr=30;var Io="root",_o="x",fs="root",To="analytics-outline",Ao='This is a root ibgib, which is basically like a root folder that is primarily responsible for "containing" other ibgibs.';var Go="tag",Mi="target";var bs="pricetag-outline",us="This is a tag used for organizing data.";var of="always",ps="archive",hs="trash";var So=/^\w{1,32}$/,Er="Invalid Date";var xo={ib:"true",gib:L};var gs={ib:"false",gib:L};var Es="config_key";var jt=/^[a-zA-Z0-9_\-.]{1,32}$/,mr="app";var ze=`bootstrap^${L}`,_e="defaultSpaceId",wr="spaceIds";var De={prependPerHash:"prependPerHash",appendPerHash:"appendPerHash",initialPrepend:"initialPrepend",initialAppend:"initialAppend"},Je=Object.values(De),Ee={sha_256:"SHA-256",sha_512:"SHA-512"},ff=Object.values(Ee),ki={indexOf:"indexOf",lastIndexOf:"lastIndexOf"},ke=Object.values(ki);function Bt(r){let t=`[${Bt.name}]`;return new Promise((e,o)=>{try{let n=ms(r),s=ws(n);e(s)}catch(n){console.error(`${t} ${m(n)}`),o(n)}})}f(Bt,"encodeStringToHexString");function ms(r){let t=`[${ms.name}]`;try{return new TextEncoder().encode(r)}catch(e){throw console.error(`${t} ${m(e)}`),e}}f(ms,"stringToUTF8Bytes");function ws(r){let t=`[${ws.name}]`;try{return Array.from(r,e=>e.toString(16).padStart(2,"0")).join("")}catch(e){throw console.error(`${t} ${m(e)}`),e}}f(ws,"bytesToHexString");function je(r){let t=`[${je.name}]`;return new Promise((e,o)=>{try{let n=$s(r),s=ys(n);e(s)}catch(n){console.error(`${t} ${m(n)}`),o(n)}})}f(je,"decodeHexStringToString");function $s(r){let t=`[${$s.name}]`;try{if(r.length%2!==0)throw new Error("invalid hex string. length %2 !== 0");let e=r.length/2,o=new Uint8Array(e);for(let n=0;n<e;n++)o[n]=parseInt(r.substr(n*2,2),16);return o}catch(e){throw console.error(`${t} ${m(e)}`),e}}f($s,"hexStringToBytes");function ys(r){let t=`[${ys.name}]`;try{return new TextDecoder().decode(r)}catch(e){throw console.error(`${t} ${m(e)}`),e}}f(ys,"utf8BytesToString");var Be=De.appendPerHash,Fe="SHA-512",qe=1024,ve=2e4,He=1,Is="indexOf",$r="lastIndexOf",yr=5e6,Ir=4,Ze=",";function ji({secret:r,prevHash:t,salt:e,saltStrategy:o}){if(!(t||r))throw new Error("Either secret or prevHash is required, but both are falsy (E: bee2849729ff410081d963777dcedb49))");switch(o){case De.prependPerHash:return e+(t||r);case De.appendPerHash:return(t||r)+e;case De.initialPrepend:return t||e+r;case De.initialAppend:return t||r+e;default:throw new Error(`Unknown saltStrategy: ${o} (E: 235136af1a6c40eb9c17b2ca41c08a01)`)}}f(ji,"getPreHash");async function $e({secret:r,prevHash:t,count:e,salt:o,saltStrategy:n,hashAlgorithm:s}){let a=`[${$e.name}]`;try{let i=t||void 0;for(let c=0;c<e;c++){let l=ji({secret:r,prevHash:i,salt:o,saltStrategy:n});i=await ce({s:l,algorithm:s})}if(!i)throw new Error("hash was not created (E: 09dfdfd644734727a34a1bc0bd8e93b9)");return i}catch(i){throw console.error(`${a} ${m(i)}`),i}}f($e,"execRound_getNextHash");async function Xe({secret:r,initialRecursions:t,salt:e,saltStrategy:o,hashAlgorithm:n}){let s=`[${Xe.name}]`;try{return await $e({secret:r,count:t,salt:e,saltStrategy:o,hashAlgorithm:n})}catch(a){throw console.error(`${s} ${m(a)}`),a}}f(Xe,"doInitialRecursions_keystretch");async function Oo({hexEncodedData:r,initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,secret:s,hashAlgorithm:a,encryptedDataDelimiter:i,indexingMode:c}){let l=`[${Oo.name}]`;try{let d=await Xe({secret:s,initialRecursions:t,salt:o,saltStrategy:n,hashAlgorithm:a}),b=c==="indexOf"?(g,h)=>g.indexOf(h):(g,h)=>g.lastIndexOf(h),u=[];for(let g=0;g<r.length;g++){let h=r[g],E="",$;for(;!E.includes(h);)$=await $e({count:e,prevHash:d,salt:o,saltStrategy:n,hashAlgorithm:a}),E+=$,d=$;let I=b(E,h);u.push(I)}return u.join(i)}catch(d){throw console.error(`${l} ${m(d)}`),d}}f(Oo,"encryptFromHex_stream");async function Do({encryptedData:r,initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,secret:s,hashAlgorithm:a,encryptedDataDelimiter:i}){let c=`[${Do.name}]`;try{let l=await Xe({secret:s,initialRecursions:t,salt:o,saltStrategy:n,hashAlgorithm:a}),d=r.split(i).map(p=>parseInt(p)),b=[];for(let p=0;p<d.length;p++){let g=d[p],h="",E;for(;g>=h.length;)E=await $e({count:e,prevHash:l,salt:o,saltStrategy:n,hashAlgorithm:a}),h+=E,l=E;let $=h[g];b.push($)}return b.join("")}catch(l){throw console.error(`${c} ${m(l)}`),l}}f(Do,"decryptToHex_stream");async function Ft({encryptedData:r,initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,secret:s,hashAlgorithm:a,encryptedDataDelimiter:i}){let c=`[${Ft.name}]`,l=[],d=[];t=t||ve,e=e||He,n=n||Be,a=a||Fe,o=o||await F(qe),i=i||Ze;let b="[validation]";if(!t||t<1){let g=`${b} initialRecursions required, and greater than 0`;console.error(g),l.push(g)}if(!e||e<1){let g=`${b} recursionsPerHash required, and greater than 0`;console.error(g),l.push(g)}if(!r){let g=`${b} encryptedData required`;console.error(g),l.push(g)}if(!o){let g=`${b} salt required`;console.error(g),l.push(g)}if(!n){let g=`${b} saltStrategy required`;console.error(g),l.push(g)}if(!s){let g=`${b} secret required`;console.error(g),l.push(g)}if(!i){let g=`${b} encryptedDataDelimiter required`;console.error(g),l.push(g)}if(!Object.values(Ee).includes(a)){let g=`${b} only ${Object.values(Ee)} hash algorithms implemented`;console.error(g),l.push(g)}if(n&&!Je.includes(n)){let g=`${b} unknown saltStrategy: ${n}`;console.error(g),l.push(g)}if(l.length>0)return{errors:l,initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,hashAlgorithm:a,encryptedDataDelimiter:i};let u=await Do({encryptedData:r,initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,secret:s,hashAlgorithm:a,encryptedDataDelimiter:i});return{decryptedData:await je(u),initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,hashAlgorithm:a,encryptedDataDelimiter:i,warnings:d.length>0?d:void 0}}f(Ft,"decryptImpl_stream");async function vo({dataToEncrypt:r,initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,secret:s,hashAlgorithm:a,encryptedDataDelimiter:i,confirm:c,indexingMode:l}){let d=`[${vo.name}]`,b=[],u=[];t||(console.warn(`${d} initial recursions required. defaulting to ${ve}`),t=ve),e=e||He,n=n||Be,a=a||Fe,o=o||await F(qe),i=i||Ze,l=l||Is;let p="[validation]";if(!t||t<1){let E=`${p} initialRecursions required, and greater than 0`;console.error(E),b.push(E)}if(!e||e<1){let E=`${p} recursionsPerHash required, and greater than 0`;console.error(E),b.push(E)}if(!r){let E=`${p} dataToEncrypt required`;console.error(E),b.push(E)}if(!o){let E=`${p} salt required`;console.error(E),b.push(E)}if(!n){let E=`${p} saltStrategy required`;console.error(E),b.push(E)}if(!s){let E=`${p} secret required`;console.error(E),b.push(E)}if(!i){let E=`${p} encryptedDataDelimiter required`;console.error(E),b.push(E)}if(!ke.includes(l)){let E=`${p} invalid indexingMode (${l}). Must be one of ${ke} (E: 5955c46755434982982823c97adcf076)`;console.error(E),b.push(E)}if(!Object.values(Ee).includes(a)){let E=`${p} only ${Object.values(Ee)} hash algorithms implemented`;console.error(E),b.push(E)}if(n&&!Je.includes(n)){let E=`${p} unknown saltStrategy: ${n}`;console.error(E),b.push(E)}if(b.length>0)return{errors:b,initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,hashAlgorithm:a,encryptedDataDelimiter:i};let g=await Bt(r);if(c&&await je(g)!==r)throw new Error("decoding encoded hex failed for this data: The encoded hex did not reverse to the original data.");let h=await Oo({hexEncodedData:g,initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,secret:s,hashAlgorithm:a,encryptedDataDelimiter:i,indexingMode:"indexOf"});if(c){let E=await Ft({encryptedData:h,initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,secret:s,hashAlgorithm:a,encryptedDataDelimiter:i});if((E.errors||[]).length>0)return{errors:["Confirm check found that decrypt had errors.",...E.errors],initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,hashAlgorithm:a,encryptedDataDelimiter:i};if(E.decryptedData){if(E.decryptedData!==r)throw new Error("The ENCRYPTED data did not decrypt back to the original data.")}else throw new Error("Confirm check call to decrypt produced falsy decryptedData");(E.warnings||[]).length>0&&(u=u.concat(["Confirm check call to decrypt had warnings.",...E.warnings]))}return{encryptedData:h,initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,hashAlgorithm:a,encryptedDataDelimiter:i,warnings:u.length>0?u:void 0}}f(vo,"encryptImpl_stream");async function No({hexEncodedData:r,initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,secret:s,hashAlgorithm:a,encryptedDataDelimiter:i,indexingMode:c,maxBlockSize:l,numOfPasses:d}){let b=`[${No.name}]`;try{let u=await Xe({secret:s,initialRecursions:t,salt:o,saltStrategy:n,hashAlgorithm:a}),p=c==="indexOf"?(_,S)=>_.indexOf(S):(_,S)=>_.lastIndexOf(S),g=[],h=r.length,E=l;E>h&&(E=h);let $=Math.ceil(h/E),I=h%E||E,A=0;for(let _=0;_<$;_++){_===$-1&&(E=I);let G=await _s({blockSize:E,indexHexEncodedDataAtStartOfPass:A,numOfPasses:d,hexEncodedData:r,recursionsPerHash:e,salt:o,saltStrategy:n,prevHash:u,hashAlgorithm:a}),O=G.alphabetsThisBlock;u=G.prevHash;let U=await Ts({alphabetsThisBlock:O,blockSize:E,indexHexEncodedDataAtStartOfPass:A,hexEncodedData:r,getIndexOfCharInAlphabet:p});g=g.concat(U),A+=E}return g.join(i)}catch(u){throw console.error(`${b} ${m(u)}`),u}}f(No,"encryptFromHex_blockMode");async function _s({blockSize:r,numOfPasses:t,indexHexEncodedDataAtStartOfPass:e,hexEncodedData:o,recursionsPerHash:n,salt:s,saltStrategy:a,prevHash:i,hashAlgorithm:c}){let l=`[${_s.name}]`;try{let d=[],b,u;for(let p=0;p<t;p++)for(let g=0;g<r;g++){b=e+g;let h=d[g]??"";u=await $e({count:n,prevHash:i,salt:s,saltStrategy:a,hashAlgorithm:c}),h+=u,i=u,d[g]=h}for(let p=0;p<r;p++){b=e+p;let g=o[b],h=d[p];for(;!h.includes(g);)u=await $e({count:n,prevHash:i,salt:s,saltStrategy:a,hashAlgorithm:c}),h+=u,i=u;d[p]=h}return{alphabetsThisBlock:d,prevHash:i}}catch(d){throw console.error(`${l} error: ${m(d)}`),d}}f(_s,"getAlphabetsThisBlock");async function Ts({alphabetsThisBlock:r,blockSize:t,indexHexEncodedDataAtStartOfPass:e,hexEncodedData:o,getIndexOfCharInAlphabet:n}){let s=`[${Ts.name}]`;try{let a=[];for(let i=0;i<t;i++){let c=e+i,l=r[i],d=n(l,o[c]);a.push(d)}return a}catch(a){throw console.error(`${s} ${m(a)}`),a}}f(Ts,"getEncryptedIndexesThisBlock");async function Lo({encryptedData:r,initialRecursions:t,recursionsPerHash:e,salt:o,saltStrategy:n,secret:s,hashAlgorithm:a,encryptedDataDelimiter:i,maxBlockSize:c,numOfPasses:l}){let d=`[${Lo.name}]`;try{let b=await Xe({secret:s,initialRecursions:t,salt:o,saltStrategy:n,hashAlgorithm:a}),u=r.split(i).map(w=>parseInt(w)),p=[],g=u.length,h=c;h>g&&(h=g);let E=Math.ceil(g/h),$=g%h||h,I=0;for(let w=0;w<E;w++){w===E-1&&(h=$);let S=await As({blockSize:h,indexEncryptedDataIndexesAtStartOfPass:I,numOfPasses:l,encryptedDataIndexes:u,recursionsPerHash:e,salt:o,saltStrategy:n,prevHash:b,hashAlgorithm:a}),G=S.alphabetsThisBlock;b=S.prevHash;let O=await Gs({alphabetsThisBlock:G,blockSize:h,indexEncryptedDataIndexesAtStartOfPass:I,encryptedDataIndexes:u});p=p.concat(O),I+=h}return p.join("")}catch(b){throw console.error(`${d} ${m(b)}`),b}}f(Lo,"decryptToHex_blockMode");async function As({blockSize:r,numOfPasses:t,indexEncryptedDataIndexesAtStartOfPass:e,encryptedDataIndexes:o,recursionsPerHash:n,salt:s,saltStrategy:a,prevHash:i,hashAlgorithm:c}){let l=`[${As.name}]`;try{let d=[],b,u;for(let p=0;p<t;p++)for(let g=0;g<r;g++){b=e+g;let h=d[g]??"";u=await $e({count:n,prevHash:i,salt:s,saltStrategy:a,hashAlgorithm:c}),h+=u,i=u,d[g]=h}for(let p=0;p<r;p++){b=e+p;let g=o[b],h=d[p];for(;h.at(g)===void 0;)u=await $e({count:n,prevHash:i,salt:s,saltStrategy:a,hashAlgorithm:c}),h+=u,i=u;d[p]=h}return{alphabetsThisBlock:d,prevHash:i}}catch(d){throw console.error(`${l} error: ${m(d)}`),d}}f(As,"getAlphabetsThisBlock");async function Gs({alphabetsThisBlock:r,blockSize:t,indexEncryptedDataIndexesAtStartOfPass:e,encryptedDataIndexes:o}){let n=`[${Gs.name}]`;try{let s=[];for(let a=0;a<t;a++){let i=e+a,c=o[i],d=r[a][c];s.push(d)}return s}catch(s){throw console.error(`${n} ${m(s)}`),s}}f(Gs,"getDecryptedDataArrayThisBlock");async function qt(r){let t=`[${qt.name}]`,{encryptedData:e,initialRecursions:o,recursionsPerHash:n,salt:s,saltStrategy:a,secret:i,hashAlgorithm:c,encryptedDataDelimiter:l,indexingMode:d,blockMode:b,multipass:u}=r,p=[],g=[];if(b&&u)throw new Error("blockMode and multipass set. blockMode was a refactored name of multipass, so these should not both be present. multipass is deprecated. (E: b9b3cd1f701c700835c0419260278223)");if(!b&&u&&(console.warn(`${t}[WARNING] "multipass" option is deprecated. this has been refactored to "blockMode". This will use multipass as blockMode. (W: b77c9773e30549cbb389ce61f31eb6d3)`),b=u),!b)throw new Error("(UNEXPECTED) blockMode required. This should be truthy in order to get to this impl fn. (E: 306bce36afd64b7182ca2b46ac04a261)");o=o||ve,n=n||He,a=a||Be,c=c||Fe,s=s||await F(qe),l=l||Ze,d=d||$r;let{maxBlockSize:h,maxPassSectionLength:E,numOfPasses:$}=b;!h&&E&&(console.warn(`${t}[WARNING] "maxPassSectionLength" option is deprecated. this has been refactored to "maxBlockSize". This will use maxPassSectioLength as maxBlockSize. (W: e2c83d78a3464704a6067e0f767f20b0)`),h=E),h=h||yr,$=$||Ir;let I="[validation]";if(!o||o<1){let S=`${I} initialRecursions required, and greater than 0`;console.error(S),p.push(S)}if(!n||n<1){let S=`${I} recursionsPerHash required, and greater than 0`;console.error(S),p.push(S)}if(!e){let S=`${I} encryptedData required`;console.error(S),p.push(S)}if(!s){let S=`${I} salt required`;console.error(S),p.push(S)}if(!a){let S=`${I} saltStrategy required`;console.error(S),p.push(S)}if(!i){let S=`${I} secret required`;console.error(S),p.push(S)}if(!l){let S=`${I} encryptedDataDelimiter required`;console.error(S),p.push(S)}if(!d){let S=`${I} indexingMode required (E: a6fe15f8ba414e21b5355d23e808b976)`;console.error(S),p.push(S)}if(!ke.includes(d)){let S=`${I} invalid indexingMode (${d}). Must be one of ${ke} (E: 17435268651444e0b7a594135635fc58)`;console.error(S),p.push(S)}if(h<1){let S=`${I} maxBlockSize must be greater than 0 (E: 0870831aa86b4bfa939aeee9f252326a)`;console.error(S),p.push(S)}if($<1){let S=`${I} numOfPasses must be greater than 0 (E: 691d3c3765584c6f8c9aba1ee378df00)`;console.error(S),p.push(S)}if(!Object.values(Ee).includes(c)){let S=`${I} only ${Object.values(Ee)} hash algorithms implemented`;console.error(S),p.push(S)}if(a&&!Je.includes(a)){let S=`${I} unknown saltStrategy: ${a}`;console.error(S),p.push(S)}if(p.length>0){let S={...r,errors:p};return delete S.encryptedData,delete S.secret,S}let A=await Lo({encryptedData:e,initialRecursions:o,recursionsPerHash:n,salt:s,saltStrategy:a,secret:i,hashAlgorithm:c,encryptedDataDelimiter:l,maxBlockSize:h,numOfPasses:$}),w=await je(A),_={...r,decryptedData:w,warnings:g.length>0?g:void 0};return delete _.encryptedData,delete _.secret,_}f(qt,"decryptImpl_blockMode");async function Co(r){let t=`[${Co.name}]`,{dataToEncrypt:e,initialRecursions:o,recursionsPerHash:n,salt:s,saltStrategy:a,secret:i,hashAlgorithm:c,encryptedDataDelimiter:l,confirm:d,indexingMode:b,blockMode:u,multipass:p}=r,g=[],h=[];if(u&&p)throw new Error("blockMode and multipass set. blockMode was a refactored name of multipass, so these should not both be present. multipass is deprecated. (E: bde5efd1a3e449dca549c5bff147f09b)");if(!u&&p&&(console.warn(`${t}[WARNING] "multipass" option is deprecated. this has been refactored to "blockMode". This will use multipass as blockMode. (W: 046b55a6d1304155b2e5352a9e6140b0)`),u=p),!u)throw new Error("(UNEXPECTED) blockMode required. This should be truthy in order to get to this impl fn. (E: 0b87871f81d849ef8f0263b7775bd3e3)");o||(console.warn(`${t} initial recursions required. defaulting to ${ve}`),o=ve),l=l||Ze,b=b||$r;let{maxBlockSize:E,maxPassSectionLength:$,numOfPasses:I}=u;!E&&$&&(console.warn(`${t}[WARNING] "maxPassSectionLength" option is deprecated. this has been refactored to "maxBlockSize". This will use maxPassSectioLength as maxBlockSize. (W: c28fe476105643e184d0ddd5d2aa8a5d)`),E=$),E=E||yr,I=I||Ir;let A="[validation]";if(!o||o<1){let G=`${A} initialRecursions required, and greater than 0 (E: dd96a75f0c504f34b1f9f2f32e011c50)`;console.error(G),g.push(G)}if(!n||n<1){let G=`${A} recursionsPerHash required, and greater than 0 (E: 64cf53e0bf9f4963be6b165ca4e6566d)`;console.error(G),g.push(G)}if(!s){let G=`${A} salt required (E: 136a5d237e0f4b1d89f8c87ac12a1507)`;console.error(G),g.push(G)}if(!a){let G=`${A} saltStrategy required (E: 457ed117bf224b9f86fe81ab6bc35381)`;console.error(G),g.push(G)}if(!i){let G=`${A} secret required (E: 5c363255055a45cfb07656e2f4854ed7)`;console.error(G),g.push(G)}if(!l){let G=`${A} encryptedDataDelimiter required (E: 1bbeb4dce19e4ac2bbe7d1e373739298)`;console.error(G),g.push(G)}if(!b){let G=`${A} indexingMode required (E: 693ebd2be64a438aa3b075d0cb0d92bf)`;console.error(G),g.push(G)}if(!ke.includes(b)){let G=`${A} invalid indexingMode (${b}). Must be one of ${ke} (E: 17435268651444e0b7a594135635fc58)`;console.error(G),g.push(G)}if(E<1){let G=`${A} maxBlockSize must be greater than 0 (E: 9f268207ae274b958fb91855331be259)`;console.error(G),g.push(G)}if(I<1){let G=`${A} numOfPasses must be greater than 0 (E: c3bcab79bb024d65b84947806290a7d4)`;console.error(G),g.push(G)}if(!Object.values(Ee).includes(c)){let G=`${A} only ${Object.values(Ee)} hash algorithms implemented`;console.error(G),g.push(G)}if(a&&!Je.includes(a)){let G=`${A} unknown saltStrategy: ${a}`;console.error(G),g.push(G)}if(g.length>0){let G={...r,errors:g};return delete G.dataToEncrypt,delete G.secret,G}let w=await Bt(e);if(d&&await je(w)!==e)throw new Error("decoding encoded hex failed for this data: The encoded hex did not reverse to the original data.");let _=await No({hexEncodedData:w,initialRecursions:o,recursionsPerHash:n,salt:s,saltStrategy:a,secret:i,hashAlgorithm:c,encryptedDataDelimiter:l,indexingMode:b,maxBlockSize:E,numOfPasses:I});if(d)try{let G=await qt({encryptedData:_,initialRecursions:o,recursionsPerHash:n,salt:s,saltStrategy:a,secret:i,hashAlgorithm:c,encryptedDataDelimiter:l,indexingMode:b,blockMode:u});if(G.decryptedData){if(G.decryptedData!==e)throw new Error("The ENCRYPTED data did not decrypt back to the original data. (E: 16b5f1a11e4f438ab38a7f124178a7b8)")}else throw new Error("Confirm check call to decrypt produced falsy decryptedData (E: a4fe82dee61f497e9dea188ea9c287a4)");(G.warnings||[]).length>0&&(h=h.concat(["Confirm check call to decrypt had warnings.",...G.warnings]))}catch(G){throw new Error(`${t} confirm failed. decrypt error: ${m(G)} (E: 782a84d9dc294ce9a6a325e3ab293adf)`)}let S={...r,encryptedData:_,warnings:h.length>0?h:void 0};return delete S.dataToEncrypt,delete S.secret,S}f(Co,"encryptImpl_blockMode");async function Bi(r){let t=`[${Bi.name}]`;try{if(!r)throw new Error("args required (E: 22e58e03c78f4c27bf18295b8d2cdd3a)");if(!r.dataToEncrypt)throw new Error("dataToEncrypt required (E: 168c9076e5434c83ba81e3485ee6f3e4)");r.salt=r.salt||await F(qe),r.saltStrategy=r.saltStrategy||Be,r.hashAlgorithm=r.hashAlgorithm||Fe,r.recursionsPerHash=r.recursionsPerHash||He;let e;return r.blockMode?e=await Co(r):e=await vo(r),(e.errors??[]).length>0&&e.errors.forEach(o=>console.warn(`${t} ${o}`)),(e.warnings??[]).length>0&&e.warnings.forEach(o=>console.warn(`${t} ${o}`)),e}catch(e){throw console.error(`${t}${e.message}`),e}}f(Bi,"encrypt");async function Fi(r){let t=`[${Fi.name}]`;try{if(!r)throw new Error("args required (E: fcd9b4aad85c4deba5fe5fde0b9ecb30)");if(!r.encryptedData)throw new Error("encryptedData required (E: f879f612428b4283bae089acee929a58)");r.salt=r.salt||await F(qe),r.saltStrategy=r.saltStrategy||Be,r.hashAlgorithm=r.hashAlgorithm||Fe,r.recursionsPerHash=r.recursionsPerHash||He;let e;return r.blockMode||r.multipass?e=await qt(r):e=await Ft(r),(e.warnings??[]).length>0&&e.warnings.forEach(o=>console.warn(`${t} ${o}`)),(e.errors??[]).length>0&&e.errors.forEach(o=>console.warn(`${t} ${o}`)),e}catch(e){throw console.error(`${t}${e.message}`),e}}f(Fi,"decrypt");var Ib=5e4;var _b=De.appendPerHash,Tb=10,Ab="SHA-256";var Gb="encryption",Sb="ciphertext";var qi={local:"local",outerspace:"outerspace",innerspace:"innerspace"},vb=Object.values(qi).concat(),Hi={user:"user",sync:"sync"},Po=Object.values(Hi).concat(),Xi={node_filesystem:"node-filesystem"},Ki={aws_dynamodb:"aws-dynamodb"},Vi={...Xi,...Ki},Ro=Object.values(Vi).concat(),Yi={get:"get",put:"put",delete:"delete"},Wi={can:"can",addrs:"addrs",latest:"latest",watch:"watch",unwatch:"unwatch",tjps:"tjps",dependencyGraph:"dependency-graph"};var zi=!1,Tr=class r{static{f(this,"DynamicFormBuilder")}lc=`[${r.name}]`;items=[];what="";idPool=[];getNewId(){let t=`${this.lc}[${this.getNewId.name}]`;if(this.idPool?.length>0)return this.idPool.pop()??"";{let e=[],o="ABCDEFGHIJKLMNOPQRSTUVWXYZ",n=o.length;for(let a=0;a<32;a++){let i=Math.floor(Math.random()*n);e.push(o[i])}let s=e.join("");return zi&&console.log(`${t} id: ${s} (I: c6591ffee6d5bbea79ed19cfa6630422)`),s}}forA({what:t}){return this.what=t||"thingy",this}addItem(t){t.uuid||(t.uuid=this.getNewId()),this.items.push(t)}with({idPool:t}){return t&&(this.idPool=t),this}and(){return this}name({of:t,required:e=!0,defaultValue:o}){return this.addItem({name:"name",description:`What to call this ${this.what}. Doesn't have to be unique, no spaces, up to 32 alphanumerics/underscores in length.`,label:"Name",placeholder:'e.g. "bob_the_cool"',regexp:cr({min:1,max:32,noSpaces:!0}),regexpErrorMsg:"1 to 32 characters, no spaces, underscores allowed.",required:e,dataType:"text",value:t,defaultValue:o}),this}description({of:t,required:e,defaultValue:o}){return this.addItem({name:"description",description:`Description/notes for this ${this.what}.`,label:"Description",placeholder:`Describe these ${this.what} settings here...`,regexp:cr({min:0,max:155,chars:yo}),regexpErrorMsg:`0 to 155 alphanumerics or any of ${yo}`,dataType:"textarea",required:e,value:t,defaultValue:o}),this}classname({of:t,required:e=!0}){return this.addItem({name:"classname",description:`Technical setting that is the name of the ${this.what}'s class in computer code.`,label:"Classname",regexp:cr({min:1,max:128,noSpaces:!0}),regexpErrorMsg:"1 to 128 alphanumerics or underscores without spaces",dataType:"text",value:t,readonly:!0,required:e}),this}uuid({of:t,label:e,required:o}){return this.addItem({name:"uuid",description:`Unique(ish) id of the ${this.what}.`,label:e??"ID",dataType:"text",value:t,regexp:z,regexpErrorMsg:"1 to 256 alphanumerics, underscores, dots, hyphens allowed.",readonly:!0,required:o}),this}version({of:t,required:e}){return this.addItem({name:"version",description:`Technical setting indicating the version of the ${this.what}.`,label:"Version",dataType:"text",value:t||"",readonly:!0,required:e}),this}customItem(t){return this.addItem(t),this}outputItems(){return this.items}outputForm({formName:t,label:e}){return{name:t,description:`This is a form for a ${this.what}`,label:e??this.what,items:this.items}}};var Qe=class r extends Tr{static{f(this,"WitnessFormBuilder")}lc=`[${r.name}]`;allowPrimitiveArgs({of:t,required:e=!0}){return this.addItem({name:"allowPrimitiveArgs",description:`Technical setting on if this ${this.what} accepts primitive incoming ibgibs`,label:"Allow Primitive Args",dataType:"toggle",value:t??!0,readonly:!0,required:e}),this}catchAllErrors({of:t,required:e=!0}){return this.addItem({name:"catchAllErrors",description:`Technical setting on what the ${this.what} does when it encounters an internal error.`,label:"Catch All Errors",dataType:"toggle",value:t??!0,readonly:!0,required:e}),this}persistOptsAndResultIbGibs({of:t,required:e=!0}){return this.addItem({name:"persistOptsAndResultIbGibs",description:`Technical setting on if the ${this.what} maintains an audit trail of all of its inputs/outputs.`,label:"Persist Opts and Result IbGibs",dataType:"toggle",value:t??!1,readonly:!0,required:e}),this}trace({of:t,required:e}){return this.addItem({name:"trace",description:`Technical setting on if the ${this.what}'s activity should be traced (logged to the console).`,label:"Trace",dataType:"toggle",value:t??!1,readonly:!0,required:e}),this}commonWitnessFields({data:t,allowPrimitiveArgs:e=!0,catchAllErrors:o=!0,persistOptsAndResultIbGibs:n=!0,trace:s=!0,version:a=!0}){return e&&this.allowPrimitiveArgs({of:t.allowPrimitiveArgs}),o&&this.catchAllErrors({of:t.catchAllErrors}),n&&this.persistOptsAndResultIbGibs({of:t.persistOptsAndResultIbGibs}),s&&this.trace({of:t.trace}),a&&this.version({of:t.version}),this}};var Ar=!1;function Ss({appData:r}){let t=`[${Ss.name}]`;try{if(Ar&&console.log(`${t} starting...`),!r)throw new Error("appData required (E: 3df782b29bc4406a87e4895cfcea28ed)");let e=[],{name:o,uuid:n,classname:s}=r;return o?o.match(jt)||e.push(`name must match regexp: ${jt}`):e.push("name required."),n?n.match(z)||e.push(`uuid must match regexp: ${z}`):e.push("uuid required."),s&&(s.match(jt)||e.push(`classname must match regexp: ${jt}`)),e}catch(e){throw console.error(`${t} ${e.message}`),e}finally{Ar&&console.log(`${t} complete.`)}}f(Ss,"validateCommonAppData");function Uo({appData:r,classname:t}){let e=`[${Uo.name}]`;try{let o=Ss({appData:r});if(o.length>0)throw new Error(`invalid appData: ${o} (E: 9aff04f0cfc54a5188ca8bc40764160d)`);if(t){if(r.classname&&r.classname!==t)throw new Error("classname does not match appData.classname (E: 66f1447eef97485fba521c40980f5eb5)")}else if(t=r.classname,!t)throw new Error("classname required (E: 5f6ffb4317044125b94f662070e1f40b)");let{name:n,uuid:s}=r;return`app ${t} ${n} ${s}`}catch(o){throw console.error(`${e} ${o.message}`),o}}f(Uo,"getAppIb");function Ji({appIb:r}){let t=`[${Ji.name}]`;try{if(!r)throw new Error("appIb required (E: 6b065aee67e641ba9f9c6db367ebb0fb)");let e=r.split(" ");return{appClassname:e[1],appName:e[2],appId:e[3]}}catch(e){throw console.error(`${t} ${e.message}`),e}}f(Ji,"getInfoFromAppIb");async function Zi({fnPromptApp:r,ibgibs:t,space:e}){let o=`[${Zi.name}]`;try{if(Ar&&console.log(`${o} starting...`),!t)throw new Error("ibgibs all powerful service required. (E: b24e78de0d204dc78909022bee296b30)");e=e??await t.getLocalUserSpace({lock:!0});let n=await r(e,null);if(!n)throw new Error("resApp falsy after prompt for app. (E: 2225a567abcd680a5e957e81fbb64123)");let s=n.newIbGib,a=[];a.push(s),n.intermediateIbGibs?.forEach(d=>a.push(d)),n.dnas?.forEach(d=>a.push(d));for(let d=0;d<a.length;d++){let b=a[d],u=await oe({ibGib:b});if((u??[]).length>0)throw new Error(`(UNEXPECTED) invalid app ibgib created. validationErrors: ${u}. app: ${H(s.toIbGibDto())} (E: 54cfc2f6bc284ed79be91d2da5e4bd2f)`)}await ee({resTransform:n,space:e});let{zeroSpace:i,fnBroadcast:c,fnUpdateBootstrap:l}=t;return await Ne({ibGib:s,space:e,fnBroadcast:f(d=>c(d),"fnBroadcast")}),await St({type:"apps",rel8nName:mr,ibGibsToRel8:[s],space:e,zeroSpace:i,fnUpdateBootstrap:l,fnBroadcast:c}),s}catch(n){debugger;console.error(`${o} ${n.message}`);return}finally{Ar&&console.log(`${o} complete.`)}}f(Zi,"createNewApp");var Qi="0",ec="chat_gib",tc="A chat app done ibgib style, enabling infinitely nesting comments, pics and links. It's ibgibs all the way down...",xs={version:"1",uuid:Qi,name:ec,description:tc,classname:"ChatApp_V1",icon:"chatbubbles",persistOptsAndResultIbGibs:!1,allowPrimitiveArgs:!0,catchAllErrors:!0,trace:!1},Os=void 0;var rc="0",oc="raw_gib",nc="Explorer app for navigating raw ibgib data.",Ds={version:"1",uuid:rc,name:oc,description:nc,classname:"RawApp_V1",icon:"paper-plane",persistOptsAndResultIbGibs:!1,allowPrimitiveArgs:!0,catchAllErrors:!0,trace:!1},vs=void 0;var Mo="0",sc="todo_gib",ac="Todo app for viewing and interacting with ibgibs like they're checklists.",Ns={version:"1",uuid:Mo,name:sc,description:ac,classname:"TodoApp_V1",icon:"checkbox",persistOptsAndResultIbGibs:!1,allowPrimitiveArgs:!0,catchAllErrors:!0,trace:!1},Ls=void 0;async function ko(r){let t=`[${ko.name}]`,e=[];try{y({ibGib:r})!==ze&&e.push(`invalid bootstrapSpace addr. Should equal "${ze}" (E: ecfdbed719284db7a1aa3f867f706fe9)`);let n=await oe({ibGib:r});(n?.length??!1)&&n.forEach(i=>e.push(i));let s=r.data,a=r.rel8ns;return Object.keys(s||{}).length===0&&e.push("invalid bootstrapSpace data. data required (E: 5a9bd15dd0644f9b93cafbbba660cfdf)"),(s.spaceIds??[]).length===0&&e.push("invalid bootstrapSpace, data.spaceIds required. (E: 6b91ddc12cfd41e59ded7d7502c1909f)"),Object.keys(r.rel8ns||{}).length===0&&e.push("invalid bootstrapSpace rel8ns (empty). Should have at least one rel8n, with rel8nName corresponding to the spaceId (E: b188ce4ae25e49f794f35e141bc2ecde)"),s.spaceIds.forEach(i=>{(a[i]??[]).length===0&&e.push(`invalid bootstrap. Each spaceId listed in data should have a corresponding address in rel8ns. spaceId (${i}) missing. (E: 62dd0d76e29a415a98b4b27deb8db17e)`)}),s[_e]?(a[s[_e]]??[]).length===0&&e.push(`invalid bootstrap. data.${_e} (${s[_e]}) not found in rel8ns. (E: 44d0799d232f4a51a0b0019ebebe019f)`):e.push(`invalid bootstrap. data.${_e} required. (E: f763af2e275f445cbf1db5801bacafad)`),e.length===0?!0:(console.error(`${t} errors: ${e.join("|")}`),!1)}catch(o){return console.error(`${t} ${o.message}`),!1}}f(ko,"validateBootstrapIbGib");var xt="meta_stone";var jo="undefined",Ht="target",Gr="targetTjp";var ye=!1;function Ps({ib:r}){let t=`[${Ps.name}]`;try{ye&&console.log(`${t} starting...`);let e=[],o=r.split(" ");o[0]!==xt&&e.push(`${t} invalid ib. atom is expected to be META_STONE_ATOM: ${xt} (E: a9812bffc18f44418aa091fb0ed260bd)`);let s=o[1],a=At({gib:s})??[];a.length>0&&e.push(`invalid ib. pieces[1] should be a valid tjpGib. validation errors: ${a} (E: 233db2babfbe4d28a80f98261f1c0e01)`);let i=o[2],c=Number.parseInt(i);isNaN(c)&&e.push("invalid ib. space-delimited pieces[2] should be valid integer (E: 71df0d6abd7b4cf4b11621e6bfb556cd)");let l=o[3];if(l!=="undefined"){let d=Xt({timestamp:l});d.valid||e.push(`invalid ib. pieces[3] should be valid timestampInTicks. emsg: (${d.emsg}) (E: 06dae01d66f54f54b71d9c920c730840)`)}return e}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{ye&&console.log(`${t} complete.`)}}f(Ps,"validateCommonMetaStoneIb");function Bo({data:r}){let t=`[${Bo.name}]`;try{if(ye&&console.log(`${t} starting...`),!r)throw new Error("data required (E: c50ac422af4501b72af12481fbd4961e)");let e=[],{targetData:o,timestamp:n}=r;Xt({timestamp:n}).valid||e.push("invalid timestampInTicks. should be valid ticks number. (E: 7e381ed5b0c8486b90cfd37676da3626)");let{tjpGib:a,n:i,timestamp:c}=o;if(a&&a!=="undefined"){let d=At({gib:a})??[];d.length>0&&e.push(`invalid data (targetTjpGib). validation errors: ${d} (E: d216b12eb75544ef8c5ffb27cd132e2e)`)}if(typeof i!="number"&&e.push("invalid n. should be valid integer. if target.data.n is falsy, targetN should be -1 (E: 8f234967b388ad80776c8054d71fbc23)"),c&&c!=="undefined"){let d=Xt({timestamp:c});d.valid||e.push(`invalid targetTimestamp. emsg: ${d.emsg} (E: c15d4fd2a2b74a0fab3223e83d954379)`)}let l=new Date(n);return e}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{ye&&console.log(`${t} complete.`)}}f(Bo,"validateCommonMetaStoneData");function Rs({rel8ns:r}){let t=`[${Rs.name}]`;try{if(ye&&console.log(`${t} starting...`),!r)throw new Error("rel8ns required (E: 7737ae550e2347e68c67b715c1221393)");let e=[],o=$o({rel8ns:r??{}})??[];o.length>0&&e.push(`invalid rel8ns intrinsically. errors: ${o.join("|")}. (E: abc91753f0f946afa0a3ea2c1917960f)`);let n=r[Ht]??[];n.length===0?e.push(`invalid metastone rel8ns. should have exactly 1 rel8nName ${Ht}. has 0. (E: 8181652da9e89613e204d245db12d723)`):n.length>1&&e.push(`invalid metastone rel8ns. should have exactly 1 rel8nName ${Ht}. has ${n.length}. (E: 2318047c6fea482d9f53febe02cf8912)`);let s=r[Gr]??[];return s.length>1&&e.push(`invalid metastone rel8ns. should have 0 or 1 rel8nName ${Gr}. has ${s.length}. (E: 34a8ae53825f46caa7ad024a64400db2)`),e}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{ye&&console.log(`${t} complete.`)}}f(Rs,"validateCommonMetaStoneRel8ns");async function ic({ibGib:r}){let t=`[${ic.name}]`;try{ye&&console.log(`${t} starting... (I: f32249d08105b997871a06cdee006311)`);let e=await oe({ibGib:r})??[];if(!r.data)throw new Error("MetaStoneIbGib.data required (E: 96432cf4f919d339277d9a1c61ea4264)");let o=[];try{let{atom:i,tjpGib:c,n:l,timestampInTicks:d}=Ms({ib:r.ib})}catch(i){o.push(m(i))}let n=Bo({data:r.data}),s=Rs({rel8ns:r.rel8ns}),a=[...e??[],...o??[],...n??[],...s??[]];return a.length>0?a:void 0}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{ye&&console.log(`${t} complete.`)}}f(ic,"validateCommonMetaStoneIbGib");function Us({data:r,classname:t}){let e=`[${Us.name}]`;try{let o=Bo({data:r});if(o.length>0)throw new Error(`invalid MetaStone data: ${o} (E: ac642cc5915f0fc0508cb2fb728c86fa)`);t&&ye&&console.log(`${e} classname not required. no big deal that it is provided here. (I: db4d41471cb976795afd3fa89f8cb823)`);let n=r.targetData.timestamp,s=n&&n!=="undefined"?ge(n):jo;return`${xt} ${r.targetData.tjpGib} ${r.targetData.n} ${s}`}catch(o){throw console.error(`${e} ${m(o)}`),o}}f(Us,"getMetaStoneIb");function Ms({ib:r}){let t=`[${Ms.name}]`;try{if(!r)throw new Error("MetaStone ib required (E: 8e74e098d7aeef52d3952e35150d83ed)");let e=Ps({ib:r});if(e.length>0)throw new Error(`invalid ib. validationErrors: ${e} (E: a6107f62200eb943e523f70f51300623)`);let o=r.split(" ");return{atom:o[0],tjpGib:o[1],n:Number.parseInt(o[2]),timestampInTicks:o[3]}}catch(e){throw console.error(`${t} ${m(e)}`),e}}f(Ms,"parseMetaStoneIb");function pu({addr:r,ibGib:t}){if(r||=y({ibGib:t}),!r)throw new Error("either addr or ibGib required. (E: 372b2574d5a9fac298119beed9f6e223)");return r.startsWith(`${xt} `)}f(pu,"isMetaStone");async function Fo({targetIbGib:r}){let t=`[${Fo.name}]`;try{ye&&console.log(`${t} starting... (I: d846313065c89c89e4b5afa2df2b7123)`);let e=y({ibGib:r}),o=ue({ibGib:r,defaultIfNone:"incomingAddr"}),n,s={[Ht]:[e],[Gr]:[o]};if(!r.gib)throw new Error("(UNEXPECTED) targetIbGib.gib falsy? (E: 28eaa8a799021dadd87b043711aee826)");let a=r.data?.isTjp?r.gib:re({ibGibAddr:e}).tjpGib??r.gib;if(a===L)throw new Error("cannot create metastone for primitive ibgib (E: 2887e8ef83381a0698256b7bc7531826)");let i=new Date,c=xe(i),l=i.getMilliseconds();r.data?Kt({ibGib:r})?n={targetData:{n:-1,tjpGib:a},timestamp:c,timestampMs:l}:(n={targetData:{n:r.data.n??-1,tjpGib:a,timestamp:r.data.timestamp??jo},timestamp:c,timestampMs:l},r.data?.isTjp&&(n.targetData.isTjp=!0)):n={targetData:{n:-1,tjpGib:a},timestamp:c,timestampMs:l};let d=Us({data:n}),b=await Te({parentPrimitiveIb:xt,ib:d,data:n,rel8ns:s});return ye&&(console.log(`${t} metaStoneIbGib... (I: 2b16197478488b329246d22d2dc41423)`),console.dir(b)),b}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{ye&&console.log(`${t} complete.`)}}f(Fo,"newUpMetaStone");var Sr="witness",Vt="witness_arg",xr="witness_result",Eu="context";var T=!1;async function ne({addr:r,addrs:t,isDna:e,space:o,force:n}){let s=`[${ne.name}]`;try{if(T&&console.log(`${s} starting...`),!o)throw new Error("space required. (E: 4d188d6c863246f28aa575753a052304)");if(!r&&(t??[]).length===0)throw new Error("addr or addrs required. (E: 1a0b92564ba942f1ba91a089ac1a2125)");r&&(t?.length??0)>0&&(console.warn(`${s} both addr and addrs provided, but supposed to be used one or the other. (W: 87226c2ac50e4ea28211334a7b58782f)`),t.includes(r)||t.push(r)),t=(t??[]).length>0?t:[r];let a=await o.argy({ibMetadata:Ge({space:o}),argData:{cmd:"get",ibGibAddrs:t,isDna:e}}),i=await o.witness(a);return i?.data?.success?(T&&console.log(`${s} got.`),{success:!0,ibGibs:i.ibGibs,rawResultIbGib:i}):(T&&console.log(`${s} didn't get.`),{success:!1,errorMsg:i.data?.errors?.join("|")||`${s} something went wrong. addrs: ${t.join(`
|
|
2
2
|
`)} (E: b9e9d5ce0cde4122bfb74f7688db85e0)`,rawResultIbGib:i})}catch(a){return console.error(`${s} ${a.message}`),{errorMsg:a.message}}}f(ne,"getFromSpace");async function Xo({ibGib:r,ibGibs:t,isDna:e,force:o,space:n}){let s=`[${Xo.name}]`;try{if(!r&&(t??[]).length===0)throw new Error("ibGib or ibGibs required. (E: e59c4de3695f4dd28c8fe82dbb9c4e90)");if(!n)throw new Error("space required. (E: dd0b7189c67c43c586b905a8ed6f51c9)");r&&(t??[]).length>0&&(console.warn(`${s} Both ibGib and ibGibs is assigned, whereas this is intended to be exclusive one or the other. (W: 4c797835b620445f88e4cba6b5aa3460)`),t.some(c=>c.gib===r.gib)||(t=t.concat([r]))),t=t??[r],T&&console.log(`${s} ibGibs.length: ${t.length}`);let a=await n.argy({ibMetadata:Ge({space:n}),argData:{cmd:"put",force:o,isDna:e,ibGibAddrs:t.map(c=>y({ibGib:c}))},ibGibs:t.concat()}),i=await n.witness(a);if(i.data?.success)return(i.data.warnings??[]).length>0&&i.data.warnings.forEach(c=>console.warn(`${s} ${c}`)),{success:!0};{let c=i?.data?.errors?.length>0?`Error(s) putting in local space:
|
|
3
3
|
${i.data.errors.join(`
|
|
4
4
|
`)}`:"(UNEXPECTED) unknown error putting ibGibs (E: 3d7426d4527243b79c5e55eb25f3fa73)";throw new Error(c)}}catch(a){return console.error(`${s} ${a.message}`),{errorMsg:a.message}}}f(Xo,"putInSpace");async function Ko({addr:r,isDna:t,space:e}){let o=`[${Ko.name}]`;try{if(!e)throw new Error("space required. (E: 40ab3b51e91c4b5eb4f215baeefbcef0)");if(!e.data)throw new Error("space.data required. (E: 0d02c8e85ee143b8bd6a1a1db0d9af1b)");o=`${o}[${e.data.name||"noname?"}][${e.data.uuid||"nouuid?"}]`;let n=await e.argy({ibMetadata:Ge({space:e}),argData:{cmd:"delete",ibGibAddrs:[r],isDna:t}}),s=await e.witness(n);if(s.data?.success)return{success:!0};{s.data?.warnings?.length>0&&console.warn(`${o} warnings with delete (${r}): ${s.data.warnings.join("|")}`),s.data?.addrs?.length>0&&console.warn(`${o} partial addrs deleted: ${s.data.addrs.join("|")}`);let a=s.data?.errors?.join("|")||`${o} something went wrong (E: e397fd09b4a746a3ba3305d6ea0893cb)`;return a.includes("File does not exist")&&T&&console.log(`${o} tried to delete file that does not exist. (I: cb5d1348ccbc58bf0bfc95f3006f1e22)`),{errorMsg:a}}}catch(n){return console.error(`${o} ${n.message}`),{errorMsg:n.message}}}f(Ko,"deleteFromSpace");async function ee({resTransform:r,space:t,force:e}){let o=`[${ee.name}]`;try{if(T&&console.log(`${o} starting... (I: dc6835614ff1a1b82b179225023ae823)`),!t)throw new Error("space required. (E: cf94f1d74f1c4561bb88025a2095965b)");let{newIbGib:n,intermediateIbGibs:s,dnas:a}=r,i=[n,...s||[]],c=await t.argy({ibMetadata:Ge({space:t}),argData:{cmd:"put",force:e,ibGibAddrs:i.map(d=>y({ibGib:d}))},ibGibs:i.concat()}),l=await t.witness(c);if(l.data?.success)l.data.warnings?.length>0&&l.data.warnings.forEach(d=>console.warn(`${o} ${d}`));else{let d=l?.data?.errors?.length>0?l.data.errors.join(`
|
|
5
5
|
`):"unknown error putting ibGibs";throw new Error(d)}if(a?.length??!1){let d=await t.argy({ibMetadata:Ge({space:t}),argData:{cmd:"put",isDna:!0,force:e,ibGibAddrs:a.map(u=>y({ibGib:u}))},ibGibs:a.concat()}),b=await t.witness(d);if(b.data?.success)b.data.warnings?.length>0&&b.data.warnings.forEach(u=>console.warn(`${o} ${u}`));else{let u=b?.data?.errors?.length>0?b.data.errors.join(`
|
|
6
|
-
`):"unknown error putting dna ibGibs";throw new Error(u)}}}catch(n){throw console.error(`${o} ${n.message}`),n}finally{T&&console.log(`${o} complete. (I: dc6835614ff1a1b82b179225023ae823)`)}}f(ee,"persistTransformResult");async function
|
|
6
|
+
`):"unknown error putting dna ibGibs";throw new Error(u)}}}catch(n){throw console.error(`${o} ${n.message}`),n}finally{T&&console.log(`${o} complete. (I: dc6835614ff1a1b82b179225023ae823)`)}}f(ee,"persistTransformResult");async function cc({type:r,rel8nName:t,space:e}){let o=`[${cc.name}]`;try{if(!e)throw new Error("space required. (E: f73868a952ac4181a4f90ee6d86cacf3)");let n=await Dr({type:r,space:e});if(!n)throw new Error(`couldn't get special (${r}) (E: a65bef190416479697605be486846731)`);let s=n.rel8ns?n.rel8ns[t]||[]:[],a=[];for(let i=0;i<s.length;i++){let c=s[i],l=await ne({addr:c,space:e});if(l.success&&l.ibGibs?.length===1)a.push(l.ibGibs[0]);else throw new Error(`couldn't get addr: ${c} (E: 76ef256ee80149ab860c5786484b0e89)`)}return a}catch(n){throw console.error(`${o} ${n.message}`),n}}f(cc,"getSpecialRel8dIbGibs");async function Dr({type:r,initialize:t,space:e,zeroSpace:o,fnUpdateBootstrap:n,fnBroadcast:s,fnGetInitializing:a,fnSetInitializing:i,dontWarnIfNotExist:c}){let l=`[${Dr.name}]`;try{if(!e)throw new Error("space required. (E: d454b31d58764a9bb9c4e47fb5ef38b5)");let d=Q({type:r}),b=await vr({key:d,space:e,dontWarn:c||!!t});if(!b){if(t&&(!a||!i))throw new Error("if initialize, you must provide fnGetInitializeLock & fnSetInitializeLock. (E: 8eb322625d0c4538be089800882487de)");if(t&&!a()){i(!0);try{if(!o)throw new Error("zeroSpace required when 'initialize' truthy (E: 8582c92c637f90c9b2dbe0ec8355b523)");b=await Bs({type:r,space:e,zeroSpace:o,fnBroadcast:s,fnUpdateBootstrap:n})??void 0}catch(h){console.error(`${l} error initializing: ${h.message}`)}finally{i(!1)}}if(!b){if(a&&a())return console.warn(`${l} couldn't get addr, but we're still initializing...`),null;throw new Error("Special address not in config and couldn't initialize it either. (E: d8ebdc9eaaa640b99cd206f132962c93)")}}T&&console.log(`${l} getting addr: ${b}`);let u=await ne({addr:b,space:e});if(u.success||(u=await ne({addr:b,space:e}),u.success&&(console.warn(`${l} special ibgib was not stored in meta folder...putting in meta folder now for the future (W: e6f5571fd98c449bb2809359be5057cc)`),(await Xo({ibGib:u.ibGibs[0],space:e})).success||console.warn(`${l} (UNEXPECTED) tried to put special in meta but success was false? (W: b934b53571c24057af172c790e6a7240)`))),!u.success)throw new Error(u.errorMsg);if(u.ibGibs?.length!==1)throw new Error("no ibGib in result (E: 3a42abdddc3648e292d63dc45c560064)");let p=u.ibGibs[0],g=await Ce({ibGibs:[p],space:e});if(g?.data?.success&&g.data.addrs?.length===1){let h=y({ibGib:p}),E=g.data.addrs[0];E!==h&&console.warn(`${l} latest addr is not the one associated with the local space.
|
|
7
7
|
specialAddr: ${h}
|
|
8
|
-
latestAddr: ${E} (W: 141b69dc3c414efc9645bb76fcf12df9)`)}return p}catch(d){let b=`${l} ${d.message}`;return b.includes("d8ebdc9eaaa640b99cd206f132962c93")&&c||console.error(b),null}}f(Dr,"getSpecialIbGib");async function vr({key:r,space:t,dontWarn:e}){let o=`[${vr.name}](${r})`;try{if(T&&console.log(`${o} getting... (I: 43e7bfc2515d45e5af8767b9a85b248e)`),!t)throw new Error("space required. (E: 4f135d4276e64054ba21aeb9c304ecec)");if(!t.rel8ns){(T||!e)&&console.warn(`${o} space.rel8ns falsy. (W: 7c642259fbf547dbaa1b2fdf0115f6ef)`);return}if(!t.rel8ns[r]){(T||!e)&&console.warn(`${o} space.rel8ns[${r}] falsy. (W: 3c1c49b9987b45cc96dd78b808f98e91)`);return}if(t.rel8ns[r].length===1)return T&&console.log(`${o} got (I: f13e71b693d5404c9535bda8ff0cc6a9)`),t.rel8ns[r][0];if(t.rel8ns[r].length>1)return(T||!e)&&console.warn(`${o} more than one config addr with ${r} rel8n. (W: 102f63eb74904bcfaac2eaf778043205)`),t.rel8ns[r][0];T&&console.log(`${o} didn't find (I: 1163e6ac60194d25b3f24881650edfad)`);return}catch(n){console.error(`${o} ${n.message}`);return}}f(vr,"getConfigAddr");async function de({key:r,addr:t,space:e,zeroSpace:o,fnUpdateBootstrap:n}){let s=`[${de.name}]`;try{if(!e)throw new Error("space required. (E: c28b663c991d44419aef1026cc689636)");if(!o)throw new Error("zeroSpace required. (E: d3707ae5265d464891ad216f64be6184)");let a={[r]:[t]},i=await Ie({src:e.toIbGibDto(),dna:!1,linkedRel8ns:["past","ancestor",r],rel8nsToAddByAddr:a,nCounter:!0});if(!i.newIbGib)throw new Error("create new space failed.");await ee({resTransform:i,space:o}),await ee({resTransform:i,space:e});let c=i.newIbGib;return await e.loadIbGibDto(c),n?await n(c):console.warn(`${s} fnUpdateBootstrap is falsy. (W: 9fb874de2b19454dac18645e61ac463f)`),c}catch(a){throw console.error(`${s} ${a.message}`),a}}f(de,"setConfigAddr");async function ks({space:r}){let t=`[${ks.name}]`;try{if(!r)throw new Error("space required. (E: f0d546101fba4c169256158114ab3c56)");let e=await Dr({type:"roots",space:r});if(!e)throw new Error("Roots not initialized. (E: 89b1ba12ed12416aac41cef9fdaf1fc2)");if(!e.rel8ns)throw new Error("Roots not initialized properly. No rel8ns. (E: 8513a07cf530484db9521a2a3a27b7f6)");if(!e.rel8ns.current)throw new Error("Roots not initialized properly. No current root. (E: 459c3a007a30486d96fb8d83f696e239)");if(e.rel8ns.current.length===0)throw new Error("Invalid Roots: empty current root rel8n. (E: bede5864090440bca01ea7ab7fd107d6)");if(e.rel8ns.current.length>1)throw new Error("Invalid Roots: multiple current roots selected. (E: 97561acbf63a48ecaa037697bd26555a)");let o=e.rel8ns.current[0],n=await ne({addr:o,space:r});if(n.ibGibs?.length===1)return n.ibGibs[0];throw new Error(`could not get current root. addr: ${o}`)}catch(e){console.error(`${t} ${e.message}`);return}}f(ks,"getCurrentRoot");async function Yo({root:r,space:t,zeroSpace:e,fnUpdateBootstrap:o,fnBroadcast:n}){let s=`[${Yo.name}]`;try{if(T&&console.log(`${s} starting... (I: 7f16e845a80fe95d28923e4170f0c825)`),!r)throw new Error("root required.");if(!t)throw new Error("space required. (E: 186af2731c5342a78b063a0a4346f3db)");let a=y({ibGib:r}),i=await Dr({type:"roots",space:t});if(!i)throw new Error("Roots not initialized. (E: a8232b9afac89d0d189534480b7a9825)");let l=await Ie({src:i,dna:!1,linkedRel8ns:["past","ancestor","current"],rel8nsToAddByAddr:{current:[a]},nCounter:!0});await ee({resTransform:l,space:t});let d=Q({type:"roots"}),b=l.newIbGib,u=y({ibGib:b});await de({key:d,addr:u,space:t,zeroSpace:e,fnUpdateBootstrap:o}),await Ne({ibGib:b,space:t,fnBroadcast:n})}catch(a){throw console.error(`${s} ${a.message}`),a}finally{T&&console.log(`${s} complete. (I: 7f16e845a80fe95d28923e4170f0c825)`)}}f(Yo,"setCurrentRoot");async function js({ibGib:r,linked:t,rel8nName:e,space:o,fnBroadcast:n,zeroSpace:s,fnUpdateBootstrap:a}){let i=`[${js.name}]`;try{if(!o)throw new Error("space required. (E: f2758eab3bb844d2b749515672d9e392)");if(!r)throw new Error("ibGib required (E: f1bfd67754a7271553f4af544d30bc22)");let c=await ks({space:o});if(!c)throw new Error("currentRoot undefined (E: 5c2d84dafc664808866008f6eb535750");let l=be({ibGib:r,defaultIfNone:"incomingAddr"}),d=y({ibGib:r});if(e&&l&&c.rel8ns&&c.rel8ns[e]&&c.rel8ns[e].includes(l))return;e=e||_o;let b=await Ie({src:c,dna:!1,linkedRel8ns:t?["past","ancestor",e]:["past","ancestor"],rel8nsToAddByAddr:{[e]:[d]},nCounter:!0});await ee({resTransform:b,space:o});let u=b.newIbGib,p=y({ibGib:u});T&&console.log(`${i} updating _currentRoot root. newRootAddr: ${p}`),await Ne({ibGib:u,space:o,fnBroadcast:n}),await Yo({root:u,space:o,zeroSpace:s,fnUpdateBootstrap:a,fnBroadcast:n})}catch(c){console.error(`${i} ${c.message}`);return}}f(js,"rel8ToCurrentRoot");async function qo({targetIbGib:r,space:t}){let e=`[${qo.name}]`;try{T&&console.log(`${e} starting... (I: 291638372117dbc983b4b7cbd8f52123)`);let o=await Fo({targetIbGib:r}),n=await Xo({ibGib:o,space:t});if(!n.success)throw new Error(`error putting metaStone in space. error: ${n.errorMsg??"[unknown error (E: 45f700f4f1ff463ca8f5353c8e796ac7)]"} (E: 4c25379e66365055e3e423561a7d6123)`)}catch(o){throw console.error(`${e} ${m(o)}`),o}finally{T&&console.log(`${e} complete.`)}}f(qo,"createAndSaveNewMetaStone");async function Ne({ibGib:r,space:t,fnBroadcast:e}){let o=`[${Ne.name}]`,n=T;try{let s=y({ibGib:r});if(o=`${o}[${s}]`,!t)throw new Error("space required. (E: ea0c03256f8a4062b460aa4de11f1e3e)");if(T&&console.log(`${o} starting...`),!re({ibGibAddr:s}).tjpGib&&!r.data?.isTjp){T&&console.log(`${o} incoming ibGib has no timeline, so no broadcast. still going to create a metastone for it and return early. (I: 649752e3b1be0e0ceb078e0ec2a84f23)`),await qo({targetIbGib:r,space:t});return}let i=be({ibGib:r,defaultIfNone:"undefined"});if(!i){let g=r.data?.isTjp?r:await Ho({ibGib:r,space:t});g||(console.warn(`${o} tjp not found for ${s}? Should at least just be the ibGib's address itself. (W: d9b570e5bf6d4312bc7d9249ed3bbaad)`),g=r),i=y({ibGib:g})}if(!i)throw new Error("(UNEXPECTED) tjpAddr falsy? should be guaranteed at this point. (E: 39aafb70bc3c6d70b6d2cf8882311223)");let c=f(async()=>{T&&console.log(`${o} adding/replacing latest. tjp: ${i} (I: 7f848da003a2436089fd6f044d96bb42)`),await qo({targetIbGib:r,space:t}),e&&(T&&console.log(`${o} fnBroadcast is true...(I: 0e3b561fb5474a0598b5c6d698df5e1f)`),setTimeout(()=>{T&&console.log(`${o} broadcasting... (I: 61785937be0346f0959d476d7267ab24)`),e({ib:"IbGibTimelineUpdateInfo",tjpAddr:i,latestAddr:s,latestIbGib:r})}))},"replaceLatest");if(r.data?.isTjp){T&&console.log(`${o} ibGib.data?.isTjp true. replacingLatest and returning early. (I: 02c626e006668291550e278b461bcb23)`),await c();return}T&&console.log(`${o} ibGib.data?.isTjp is falsy. (I: 84940e3a9eff869c9474b7b92b864b23)`);let l=await Pe({ibGibs:[r],space:t});if(!l.data)throw new Error("(UNEXPECTED) resLatest.data falsy? (E: af3d3914d96adcc5525e4db83cc5d223)");let{success:d,latestAddrsMap:b}=l.data;if(!d){let{errors:g}=l.data;throw g??=["[unknown error (E: 344857f1853641aa842cea3931f90428)]"],new Error(`resLatest.success falsy. errors: ${H(g)}. addr: ${s} (E: b66721da6e1ef9ac4f4089e86c059323)`)}if(!b)throw new Error("(UNEXPECTED) latestAddrsMap falsy but success truthy? (E: c34caff7a256503575ff3ff491dec823)");let u=Object.keys(b);if(u.length!==1)throw new Error("(UNEXPECTED) latestAddrsMap size isn't 1? (E: e11ffc2c18d473745b5bbfc3fe5e3a23)");if(u[0]!==s)throw new Error(`(UNEXPECTED) latestAddrsMap has 1 key (correct) but the key isn't the incoming ibGibAddr? (incorrect). incoming ibGibAddr: ${s}. key found: ${u[0]} (E: 82d79a95d2d7de90eae9db571a360f23)`);T&&(console.log(`${o} valid latestAddrsMap. console.dir(latestAddrsMap)... (I: e24de41622cabbef375172c3017cfd23)`),console.dir(b));let p=b[s];if(p)if(p===s){T&&console.log(`${o} no other found. possible idempotent replacement. addr: ${s} (I: 7f5bd5d3391be95919240f0e97976e22)`),await c();return}else{T&&console.log(`${o} different addr found. incoming ibgib addr is newer. existingLatestAddr: ${p}. incoming addr: ${s} (I: 6cadf13f82aabeb71d76babf1813e623)`);let g=await ne({addr:p,space:t});if(!g.success||g.ibGibs?.length!==1){console.error(`Didn't find existing latest ibGib (${p}). I haven't implemented more robust multi-node/distributed strategies for this scenario yet. so we are going ahead with setting the incoming ibgib as the latest in the timeline. (E: 10f6cca6e5ef45bfacbfe48f652e2102)`),await c();return}let h=g.ibGibs[0];if(typeof r.data?.n=="number"&&r.data.n>=0){T&&console.log(`found ibGib.data.n (version counter), using this to determine latest ibGib: ${r.data.n}`);let $=r.data.n;if(typeof h.data?.n=="number"&&h.data.n>=0){let A=h.data.n;if($>A)T&&console.log(`${o} is newer (I: 040d05ac2032f08c7fd0c4d8b2887323)`),await c();else{T&&console.log("is not newer, so we don't need to do anything else. (I: 14c25dc3314748dc909d61b77eb64354)"),console.warn(`${o} incoming ibGib (${s}) is NOT NEWER than existing latest (${p}). multiple branches for the same timeline? ignoring incoming ibGibAddr. n_ibGib: ${$}. n_existingLatest: ${A}. space.ib: ${t.ib} (W: 057baadca494473dabb26fb4fb879774)`);return}}else h.data?.isTjp&&r.data.n===0?await c():(console.warn(`${o} (UNEXPECTED) only existingLatestIbGib (isTjp: ${h.data?.isTjp}) has a data.n counter? ibGib.data.n: ${r.data.n}. usually this only happens when existing latest is a tjp and the new ibGib we are registering is n === 0. This is falsy in this instance though. We will go ahead and replace the latest with the new one, but this is an anomalous state. (W: 73d08aea17ad4e1481a5f97e2556a878)`),console.log(`${o} console.dir(existingLatestIbGib)... (I: 9ef7962d9cc74f1eb0409e5caf98e915)`),console.dir(h),console.log(`${o} console.dir(ibGib)... (I: 9ef7962d9cc74f1eb0409e5caf98e915)`),console.dir(r),await c())}else if(T&&console.log(`${o} no nCounter found. Trying brute force method.`),await Qs({ibGib:r,ibGibAddr:s,existingLatest:h,existingLatestAddr:p,tjpAddr:i,space:t})===s)await c();else return}else if(p===null){T&&console.log(`${o} no existing tjp mapping so incoming ibgib is considered new to this space. ibGib addr: ${s} (I: 4f2bbc32b31e4fa982d95b3a785db82f)`),await c();return}else throw new Error("(UNEXPECTED) latestAddr is falsy but not null? the getLatestAddrs impl in the space should be guaranteed to provide either the incoming ibgib addr, the latest addr (if exists), or null if not found. (E: 3159dd531c0bc0efc1ece116adf28923)")}catch(s){throw console.error(`${o} ${s.message}`),s}finally{T&&console.log(`${o} complete.`),T=n}}f(Ne,"registerNewIbGib");async function St({type:r,rel8nName:t,ibGibsToRel8:e,ibGibsToUnRel8:o,addrsToUnRel8:n,linked:s,severPast:a,deletePreviousSpecialIbGib:i,space:c,zeroSpace:l,fnUpdateBootstrap:d,fnBroadcast:b}){let u=`[${St.name}](type:${r},rel8nName:${t})`;try{if(!c)throw new Error("space required. (E: 956192eea28047eba6dad81620bb96fb)");if((e??[]).length===0&&(o??[]).length===0&&(n??[]).length===0)throw new Error("either ibGibsToRel8 or ibGibsToUnRel8 required. (E: 5add49c8e46a54e2c6b057c22646a822)");if((o??[]).length>0&&(n??[]).length>0)throw new Error("can't provide both ibGibsToUnRel8 and addrsToUnRel8. There isn't a technical reason but I'm too tired right now to implement the overhead to enable this atow (05/2025). (E: 31ef66be26349cfe1b1f352389b99425)");let p=e?.map(S=>y({ibGib:S}));n??=o?.map(S=>y({ibGib:S}));let g=Q({type:r}),h=await vr({key:g,space:c});if(!h)throw new Error("specialAddr not found (E: 680dfd1caa3e4d7cb0f593b893a10f0d)");let E=await ne({addr:h,space:c});if(!E.success)throw new Error("couldn't get special (E: 897f7671d2184515866c5a675d33b3dc)");if(!E.ibGibs)throw new Error("resGetSpecial.ibGibs falsy (E: 2405dd295b2444d88503f7731796a5a0)");if(E.ibGibs.length!==1)throw new Error(`resGetSpecial.ibGibs count is not 1 (${E.ibGibs.length}) (E: b4547789016a4729af30cd972a4ca4ab)`);let $=E.ibGibs[0],I=await Ie({src:$,rel8nsToAddByAddr:p?{[t]:p}:void 0,rel8nsToRemoveByAddr:n?{[t]:n}:void 0,dna:!1,linkedRel8ns:s?[K.past,t]:[K.past],nCounter:!0}),A=I.newIbGib;if(a){if(I.intermediateIbGibs)throw new Error("new special creates intermediate ibgibs. so severing past is harder. (E: b580c0c56253494192e9c62212ee187d)");A.rel8ns.past=[],A.gib=await X({ibGib:A})}await ee({resTransform:I,space:c});let w=y({ibGib:A}),_=be({ibGib:A});return await de({key:g,addr:w,space:c,zeroSpace:l,fnUpdateBootstrap:d}),i&&await Ko({addr:h,space:c}),await Ne({ibGib:A,fnBroadcast:b,space:c}),w}catch(p){throw console.error(`${u} ${p.message}`),p}}f(St,"rel8ToSpecialIbGib");async function Ho({ibGib:r,naive:t=!0,space:e}){let o=`[${Ho.name}]`;try{if(!e)throw new Error("space required. (E: 941f973d50e84415b58724af173f52c2)");if(!r)throw new Error("ibGib required.");let n=y({ibGib:r}),{gib:s}=P({ibGibAddr:n});if(s===L||await Qo({ibGib:r,naive:t}))return r;if(!r.rel8ns){T&&console.log(`${o} ibgib not tjp in data, and rel8ns is falsy. so tjp is undefined (I: acdadb76a7568807db7a68f6f866de22)`);return}if(r.rel8ns.tjp&&r.rel8ns.tjp.length>0){let b=r.rel8ns.tjp[0],u=await ne({addr:b,space:e});if(u.success&&u.ibGibs?.length===1)return u.ibGibs[0];{let p=u.errorMsg??"[unspecified error in get result]";throw new Error(`ibGib references tjp but could not retrieve from space. res error: ${p} (E: 94f0340706ad48c794c6a62c1b235a22)`)}}let i=r.rel8ns.past||[];if(i.length===0){console.warn(`${o} past.length === 0, so there is no tjp.`),T&&console.log(`${o} ibgib is not tjp in data, not in tjp rel8n, and past is empty. so tjp is undefined (I: bf06f664917dcf4492fb9c4c106a6222)`);return}let c=i[i.length-1],l=await ne({addr:c,space:e});if(!l.success||l.ibGibs?.length!==1)throw new Error(`get past failed. addr: ${c}`);let d=l.ibGibs[0];return await Ho({ibGib:d,naive:t,space:e})}catch(n){throw console.error(`${o} ${n.message}`),n}}f(Ho,"getTjpIbGib");async function Bs({type:r,space:t,zeroSpace:e,fnUpdateBootstrap:o,fnBroadcast:n}){let s=`[${Bs.name}]`;try{if(!t)throw new Error("space falsy and localUserSpace not initialized. (E: 66e7d3ff098248f0a5ddda51853c92e6)");switch(r){case"roots":return Hs({space:t,zeroSpace:e,fnBroadcast:n,fnUpdateBootstrap:o});case"tags":return Fs({space:t,zeroSpace:e,fnBroadcast:n,fnUpdateBootstrap:o});case"secrets":return Ks({space:t,zeroSpace:e,fnBroadcast:n,fnUpdateBootstrap:o});case"encryptions":return Ys({space:t,zeroSpace:e,fnBroadcast:n,fnUpdateBootstrap:o});case"outerspaces":return Vs({space:t,zeroSpace:e,fnBroadcast:n,fnUpdateBootstrap:o});case"autosyncs":return Ws({space:t,zeroSpace:e,fnBroadcast:n,fnUpdateBootstrap:o});case"robbots":return zs({space:t,zeroSpace:e,fnBroadcast:n,fnUpdateBootstrap:o});case"apps":return Js({space:t,zeroSpace:e,fnBroadcast:n,fnUpdateBootstrap:o});default:return Zs({type:r,space:t,zeroSpace:e,fnBroadcast:n,fnUpdateBootstrap:o})}}catch(a){throw console.error(`${s} ${a.message}`),a}}f(Bs,"createSpecial");async function Le({type:r,skipRel8ToRoot:t,space:e,zeroSpace:o,fnUpdateBootstrap:n,fnBroadcast:s}){let a=`[${Le.name}][${r||"falsy type?"}]`;try{T&&console.log(`${a} starting...`);let i=Jo({type:r}),c=M.primitive({ib:i}),l=await fr({src:c,destIb:i,linkedRel8ns:[K.past,K.ancestor],tjp:{uuid:!0,timestamp:!0},dna:!0,nCounter:!0});return await ee({resTransform:l,space:e}),r!=="roots"&&r!=="latest"&&!t&&await js({ibGib:l.newIbGib,linked:!0,space:e,zeroSpace:o,fnBroadcast:s,fnUpdateBootstrap:n}),T&&console.log(`${a} complete.`),l.newIbGib}catch(i){throw console.error(`${a} ${i.message}`),i}}f(Le,"createSpecialIbGib");async function Fs({space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o}){let n=`[${Fs.name}]`;try{if(!r)throw new Error("space required. (E: 9c05b9bd355943a39ca47afef67a50eb)");let s=Q({type:"tags"}),a=await Le({type:"tags",space:r,zeroSpace:t,fnBroadcast:o,fnUpdateBootstrap:e}),i=y({ibGib:a});await de({key:s,addr:i,space:r,zeroSpace:t,fnUpdateBootstrap:e});let c=[{text:"home",icon:"home-outline"},{text:"favorite",icon:"heart-outline"}];for(let l of c)i=(await qs({...l,space:r,zeroSpace:t,fnBroadcast:o,fnUpdateBootstrap:e})).newTagsAddr,await de({key:s,addr:i,space:r,zeroSpace:t,fnUpdateBootstrap:e});return i}catch(s){return console.error(`${n} ${s.message}`),null}}f(Fs,"createSpecial_Tags");async function qs({text:r,icon:t,description:e,space:o,zeroSpace:n,fnUpdateBootstrap:s,fnBroadcast:a}){let i=`[${qs.name}]`;try{if(T&&console.log(`${i} starting...`),!o)throw new Error("space required. (E: 5def0b1afab74b0c9286e3ac5060cb8f)");if(!r)throw new Error(`${i} text required`);t=t||bs,e=e||us;let c=dt(r),l=M.primitive({ib:"tag"}),d=await M.firstGen({parentIbGib:l,ib:c,data:{text:r,icon:t,description:e},tjp:{uuid:!0,timestamp:!0},dna:!0,nCounter:!0}),b=d.newIbGib;await ee({resTransform:d,space:o}),await Ne({ibGib:b,space:o,fnBroadcast:a});let u=await cc({tagIbGib:b,space:o,zeroSpace:n,fnUpdateBootstrap:s,fnBroadcast:a});return{newTagIbGib:b,newTagsAddr:u}}catch(c){throw console.error(`${i} ${c.message}`),c}finally{T&&console.log(`${i} complete.`)}}f(qs,"createTagIbGibAndSundry");async function Hs({space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o}){let n=`[${Hs.name}]`;try{if(!r)throw new Error("space required. (E: d12a8ea31163429fb6e53ff8e7579c57)");let s=Q({type:"roots"}),a=await Le({type:"roots",space:r,zeroSpace:t,fnBroadcast:o,fnUpdateBootstrap:e}),i=y({ibGib:a});await de({key:s,addr:i,space:r,zeroSpace:t,fnUpdateBootstrap:e});let l=["A","B","C","D","E","F","G"].map(b=>({text:`${b}root`,icon:To,description:Ao})),d;for(let b=0;b<l.length;b++){let u=l[b],p=await Xs({...u,space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o});if(d||(d=p.newRootIbGib),!p.newRootIbGib)throw new Error("(UNEXPECTED) resCreate.newRootIbGib falsy? (E: c9fb2c94a9c1d762c1699b41a4d5ad23)");i=p.newRootsAddr,await de({key:s,addr:i,space:r,zeroSpace:t,fnUpdateBootstrap:e})}if(!d)throw new Error("(UNEXPECTED) firstRoot still falsy? (E: b2e2c926d242966e7ed7159e4b129e23)");if(await Yo({root:d,space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o}),i=await vr({key:s,space:r}),!i)throw new Error("(UNEXPECTED) no roots address in config? (E: 76345340699a4738a195e48803ef0d31)");return i}catch(s){return console.error(`${n} ${s.message}`),null}}f(Hs,"createSpecial_Roots");async function Xs({text:r,icon:t,description:e,space:o,zeroSpace:n,fnUpdateBootstrap:s,fnBroadcast:a}){let i=`[${Xs.name}]`;try{if(!o)throw new Error("space required. (E: cfa876e5c8c64a53a463ca7a645571c8)");r=r||fs,t=t||To,e=e||Ao;let c=Zo(r),l=M.primitive({ib:"root"}),d=await M.firstGen({parentIbGib:l,ib:c,data:{text:r,icon:t,description:e},linkedRel8ns:[K.past,K.ancestor],tjp:{uuid:!0,timestamp:!0},dna:!0,nCounter:!0}),{newIbGib:b}=d;await ee({resTransform:d,space:o});let u=await St({type:"roots",rel8nName:Io,ibGibsToRel8:[b],space:o,zeroSpace:n,fnUpdateBootstrap:s,fnBroadcast:a});return{newRootIbGib:b,newRootsAddr:u}}catch(c){throw console.error(`${i} ${c.message}`),c}}f(Xs,"createRootIbGib");async function Ks({space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o}){let n=`[${Ks.name}]`;try{if(!r)throw new Error("space required. (E: 340960cd5ad24addb300b23d9722e30a)");let s,a=Q({type:"secrets"}),i=await Le({type:"secrets",space:r,zeroSpace:t,fnBroadcast:o,fnUpdateBootstrap:e});return s=y({ibGib:i}),await de({key:a,addr:s,space:r,zeroSpace:t,fnUpdateBootstrap:e}),s}catch(s){return console.error(`${n} ${s.message}`),null}}f(Ks,"createSpecial_Secrets");async function Ys({space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o}){let n=`[${Ys.name}]`;try{if(!r)throw new Error("space required. (E: 5084e698b6924e7090697ca50075ca59)");let s,a=Q({type:"encryptions"}),i=await Le({type:"encryptions",space:r,zeroSpace:t,fnBroadcast:o,fnUpdateBootstrap:e});return s=y({ibGib:i}),await de({key:a,addr:s,space:r,zeroSpace:t,fnUpdateBootstrap:e}),s}catch(s){return console.error(`${n} ${s.message}`),null}}f(Ys,"createSpecial_Encryptions");async function Vs({space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o}){let n=`[${Vs.name}]`;try{if(!r)throw new Error("space required. (E: 99dd9e92535c470482eb9f6625a33831)");let s,a=Q({type:"outerspaces"}),i=await Le({type:"outerspaces",space:r,zeroSpace:t,fnBroadcast:o,fnUpdateBootstrap:e});return s=y({ibGib:i}),await de({key:a,addr:s,space:r,zeroSpace:t,fnUpdateBootstrap:e}),s}catch(s){return console.error(`${n} ${s.message}`),null}}f(Vs,"createSpecial_OuterSpaces");async function Ws({space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o}){let n=`[${Ws.name}]`;try{if(!r)throw new Error("space required. (E: f01cf6a4a460486796e16d505d629522)");let s,a=Q({type:"autosyncs"}),i=await Le({type:"autosyncs",space:r,zeroSpace:t,fnBroadcast:o,fnUpdateBootstrap:e});return s=y({ibGib:i}),await de({key:a,addr:s,space:r,zeroSpace:t,fnUpdateBootstrap:e}),s}catch(s){return console.error(`${n} ${s.message}`),null}}f(Ws,"createSpecial_Autosyncs");async function zs({space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o}){let n=`[${zs.name}]`;try{if(!r)throw new Error("space required. (E: f01cf6a4a460486796e16d505d629522)");let s,a=Q({type:"robbots"}),i=await Le({type:"robbots",space:r,zeroSpace:t,fnBroadcast:o,fnUpdateBootstrap:e});return s=y({ibGib:i}),await de({key:a,addr:s,space:r,zeroSpace:t,fnUpdateBootstrap:e}),s}catch(s){return console.error(`${n} ${s.message}`),null}}f(zs,"createSpecial_Robbots");async function Js({space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o}){let n=`[${Js.name}]`;try{if(!r)throw new Error("space required. (E: f01cf6a4a460486796e16d505d629522)");let s,a=Q({type:"apps"}),i=await Le({type:"apps",space:r,zeroSpace:t,fnBroadcast:o,fnUpdateBootstrap:e});return s=y({ibGib:i}),await de({key:a,addr:s,space:r,zeroSpace:t,fnUpdateBootstrap:e}),s=await Or({defaultAppData:xs,defaultAppRel8ns:Os,space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o}),s=await Or({defaultAppData:Ds,defaultAppRel8ns:vs,space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o}),s=await Or({defaultAppData:Ns,defaultAppRel8ns:Ls,space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o}),s}catch(s){return console.error(`${n} ${s.message}`),null}}f(Js,"createSpecial_Apps");async function Or({defaultAppData:r,defaultAppRel8ns:t,space:e,zeroSpace:o,fnUpdateBootstrap:n,fnBroadcast:s}){let a=`[${Or.name}]`;try{T&&console.log(`${a} starting... (I: 677f68789abdc7316887e8f38c764e22)`),T&&console.log(`${a} starting...`);let i=v(r),c=t?v(t):void 0;i.uuid=!i.uuid||i.uuid===Mo?await F():i.uuid;let{classname:l}=i,d=Uo({appData:i,classname:l}),b=await M.firstGen({ib:d,parentIbGib:M.primitive({ib:`app ${l}`}),data:i,rel8ns:c,dna:!0,linkedRel8ns:[K.ancestor,K.past],nCounter:!0,tjp:{timestamp:!0}});return await ee({resTransform:b,space:e}),await Ne({ibGib:b.newIbGib,fnBroadcast:s,space:e}),await St({type:"apps",rel8nName:mr,ibGibsToRel8:[b.newIbGib],fnBroadcast:s,fnUpdateBootstrap:n,space:e,zeroSpace:o})}catch(i){throw console.error(`${a} ${i.message}`),i}finally{T&&console.log(`${a} complete.`)}}f(Or,"createApp");async function Zs({type:r,space:t,zeroSpace:e,fnUpdateBootstrap:o,fnBroadcast:n}){let s=`[${Zs.name}]`;try{if(!t)throw new Error("space required. (E: c7bbafcbe901418db4c6048f17f53091)");T&&console.log(`${s} creating special of type: ${r} (I: 283c8bb30ed6f9698b74b886c6078622)`);let a,i=Q({type:r}),c=await Le({type:r,space:t,zeroSpace:e,fnBroadcast:n,fnUpdateBootstrap:o});return a=y({ibGib:c}),await de({key:i,addr:a,space:t,zeroSpace:e,fnUpdateBootstrap:o}),a}catch(a){return console.error(`${s} ${a.message}`),null}}f(Zs,"createSpecial_Default");async function Qs({ibGib:r,ibGibAddr:t,existingLatest:e,existingLatestAddr:o,tjpAddr:n,space:s}){let a=`[${Qs.name}][${t}]`;try{if(T&&console.log(`${a} starting...`),!s)throw new Error("space required. (E: 64eb9a271f5d43deadec30b9638746c8)");let i=r.rel8ns?.past||[],c=e.rel8ns?.past||[];if(i.length===1&&c.length===0)return T&&console.log(`prospective has a past, so it "must" be newer. (won't quote "must" anymore)`),t;if(c.length===1&&i.length===0)return T&&console.log("existing has a past, so it must be newer."),o;if(c.length===0&&i.length===0)return console.warn(`${a} neither existing latest nor prospective new ibGib has a past, so keeping existing.`),o;if(c.includes(t))return T&&console.log("existing by definition is newer"),o;if(i.includes(o))return T&&console.log("ibGib by definition is newer"),t;if(o===t)return T&&console.log("they're the same!"),o;if(o===n&&e.rel8ns?.tjp?.length===1)return T&&console.log("ibGib must be newer because the existingLatestAddr is the tjp, which is by definition first in unique past."),t;if(t===n&&r.rel8ns?.tjp?.length===1)return T&&console.log("existing must be newer because the ibGibAddr is the tjp, which is by definition first in unique past."),o;T&&console.log(`${a} brute forcing through iterating the pasts.`);let l,d=-1,b=f(async(g,h,E)=>{let $=g.rel8ns?.past||[];if($.includes(E))return l=y({ibGib:g}),-1;if($.length===0)return h;let I=h+$.length;if(d!==-1&&I>d)return l=y({ibGib:g}),-1;let A=await ne({addr:$[0],space:s});if(!A.success||A.ibGibs?.length!==1)throw new Error(`Couldn't load past addr (xPast[0]): ${$[0]}`);return b(A.ibGibs[0],h+$.length,E)},"getPastCount");T&&console.log(`${a} doing ibGibPastCount`);let u=await b(r,0,o);if(l)return l;T&&console.log(`${a} Doing existingPastCount`),d=u;let p=await b(e,0,t);return l||(u>p?(T&&console.log(`${a} ibGibPastCount (${u}) is longer than existingPastCount (${p}), so ibGib is newer.`),l=t):(T&&console.log(`${a} existingPastCount (${p}) is longer than ibGibPastCount (${u}), so ibGib is newer.`),l=o),l)}catch(i){throw console.error(`${a} ${i.message}`),i}finally{T&&console.log(`${a} complete.`)}}f(Qs,"getLatestAddr_Brute");function cc({tagIbGib:r,space:t,zeroSpace:e,fnUpdateBootstrap:o,fnBroadcast:n}){return St({type:"tags",rel8nName:Go,ibGibsToRel8:[r],space:t,zeroSpace:e,fnUpdateBootstrap:o,fnBroadcast:n})}f(cc,"rel8TagToTagsIbGib");function Vo({space:r,scope:t}){let e=`[${Vo.name}]`;try{if(T&&console.log(`${e} starting...`),!r)throw new Error("space required. (E: 3ba16e6c3e5e47948b0e63448da11752)");if(!r.data?.uuid)throw new Error("invalid space (space.data.uuid falsy) (E: 273262b32f2ef27b2e690bc699f33822)");if(!t)throw new Error("scope required. (E: f47801d6c45e2247b42a53d9b604b522)");for(;t.includes(J);)T&&console.log(`${e} scope contains ibgib delimiter...replacing... (I: 0f456fd7cc6552a799673a0c5b4a7d22)`),t=t.replace(J,"_");let o=r.data.uuid,n=`${cs} ${o} ${t}`;return y({ib:n,gib:L})}catch(o){throw console.error(`${e} ${o.message}`),o}finally{T&&console.log(`${e} complete.`)}}f(Vo,"getSpaceLockAddr");async function Ae({space:r,scope:t,secondsValid:e,maxDelayMs:o,fn:n,callerInstanceId:s,maxLockAttempts:a}){let i=`[${Ae.name}]`;try{if(T&&console.log(`${i} starting...`),!r)throw new Error("space required. (E: 66fd8f21a5b2b572d18cdeb9472a7722)");if(!e)throw new Error("secondsValid required. (E: 92c5610e57ceede5ce83cff86d5c2a22)");if(e<0)throw new Error("secondsValid must be positive. (E: 970a7510c517235d7a355a843d18d222)");if(!n)throw new Error("fn required (E: 7022e280252ec2faf756b6db05c56e22)");let c;T&&console.log(`${i} attempting to acquire lock with scope ${t} (I: fed36d42a975b1c52897a4df804ac722)`);let l;o=(o??0)>0?o:ls;let d=0;a=a??!1?a:ds;do{if(l=await ea({space:r,scope:t,secondsValid:e,instanceId:s}),l?.data?.success)break;let u=Math.ceil(Math.random()*o);await le(u),d++}while(d<a);if(l?.data?.success)T&&console.log(`${i} lock acquired. (I: d847fa953ee131a57e1a89c537342722)`);else throw new Error(`could not acquire lock after ${d} attempts with intermittent delays of ${o} ms (E: 898c559dbd0c9bf20c14cf87a8f1e222)`);let b=`${i}[fn]`;try{T&&console.log(`${b} starting... (I: c2f7bedf95d3f1dd1f76de34a68d3f22)`),c=await n()}catch(u){throw console.error(`${b} ${u.message}`),u}finally{T&&console.log(`${b} unlocking space with scope: ${t} (I: 21034d9c3395499756e9000e40417d22)`),await ta({space:r,scope:t,instanceId:s}),T&&console.log(`${b} complete. (I: 79d8ac03714a4d429c7e6c2ac6e18d22)`)}return c}catch(c){throw console.error(`${i} ${c.message}`),c}finally{T&&console.log(`${i} complete.`)}}f(Ae,"execInSpaceWithLocking");async function Vt({zeroSpace:r}){let t=`[${Vt.name}]`;try{if(T&&console.log(`${t} starting...`),!r)throw new Error("zeroSpace required. (E: 66fd8f21a5b2b572d18cdeb9472a7722)");let e=ze;T&&console.log(`${t} getting from zeroSpace...`);let o=await r.argy({ibMetadata:Ge({space:r}),argData:{cmd:"get",ibGibAddrs:[e]}}),n=await r.witness(o);if(n?.data?.success&&n.ibGibs?.length===1){let s=n.ibGibs[0];return T&&console.log(`${t} bootstrapibGib found: ${H(s)}`),await ko(s)?s:(T&&console.log(`${t} bootstrapIbGib was invalid. (I: cce66b26805404fc85525d565e1f8b22)`),null)}else return T&&console.log(`${t} bootstrapIbGib NOT found. (I: 421562993bf3464eb507d2967d311e22)`),null}catch(e){throw console.error(`${t} ${e.message}`),e}finally{T&&console.log(`${t} complete.`)}}f(Vt,"getValidatedBootstrapIbGib");async function lc({zeroSpace:r,bootstrapIbGib:t,localSpaceId:e,lock:o,callerInstanceId:n,fnDtoToSpace:s,localSpaceCacheSvc:a}){let i=`[${lc.name}]`;try{if(!r)throw new Error("zeroSpace required. (E: 0793781a98c456a666cfa9eb960bcd22)");if(!t)if(T&&console.log(`${i} bootstrap falsy, so loading it... (I: f2366e38283495a38b5501297aa34422)`),o){let d=ze;T&&console.log(`${i} using locked version of loading bootstrap... (I: 52b9b11999674e586d051c2b23f59b22)`),t=await Ae({space:r,scope:d,fn:f(async()=>{let b=await Vt({zeroSpace:r});if(b)return b;throw new Error("(UNEXPECTED) unable to get bootstrap ibgib? (E: c111dc7627acbfb992134ddf4064ea23)")},"fn"),callerInstanceId:n,secondsValid:gr})}else T&&console.log(`${i} lock is false, so just getting the bootstrap ibgib (I: 49d55e5a824510bb3ee0ccd9f5ec3322)`),t=await Vt({zeroSpace:r})??void 0;if(!t)throw new Error("bootstrapIbGib falsy. not initialized? (E: 91f5c82b5e124178d958701ebcb09822)");if(!t.data)throw new Error("(UNEXPECTED) bootstrapIbGib.data required. invalid bootstrap? (E: 568c6b837c1a39f7a25d188a90167423)");e=e??t.data[_e];let c=t.rel8ns[e][0],l=f(async()=>{let d=await r.argy({ibMetadata:Ge({space:r}),argData:{cmd:"get",ibGibAddrs:[c]}}),b=await r.witness(d);if(b?.data?.success&&b.ibGibs?.length===1){let u=b.ibGibs[0],p=await s(u);return a&&(p.cacheSvc=a),p}else throw new Error(`Could not get local space addr (${c}) specified in bootstrap space (${y({ibGib:t})}). (E: 6d6b45e7eae4472697ddc971438e4922)`)},"fnGet");return o?(T&&console.log(`${i} getting localSpaceId (${e}) WITH locking (I: c48a0e4ac5971cdbc57273dd35f8a522)`),await Ae({space:r,scope:e,fn:f(()=>l(),"fn"),callerInstanceId:n,secondsValid:gr})):(T&&console.log(`${i} getting localSpaceId (${e}) WITHOUT locking (I: 48e504835dee4006839df8820d860b22)`),l())}catch(c){throw console.error(`${i} ${c.message}`),c}}f(lc,"getLocalSpace");async function ea({space:r,scope:t,secondsValid:e,instanceId:o}){let n=`[${ea.name}]`;try{if(T&&console.log(`${n} starting...`),!r)throw new Error("space required. (E: 5c0a7197a75f483a82d74e5eea60df37)");if(!t)throw new Error("scope required. (E: c7f1dde9570f4df3b450faa2c2f85122)");if(!e)throw new Error("secondsValid required and positive (E: b42b6733638b46c06c9aff59a6c49822)");if(e<0)throw new Error("secondsValid must be positive (E: bbe3b6d567583bfb35a1c0825eb29622)");let s,a=Vo({space:r,scope:t}),i,c=await ne({addr:a,space:r,force:!0});if(c.success&&c.ibGibs?.length===1?(i=c.ibGibs[0],i?.data?.expirationUTC?go({expirationTimestampUTC:i.data.expirationUTC})&&(console.warn(`${n} ignoring expired existing lock in space at ${a}. Should be overwritten (W: 7421c5b051724b189f88cecbbd449b22)`),i=void 0):(console.error(`${n} (UNEXPECTED) exisingLock.data.expirationUTC falsy? (E: 218dc0e935534a149d0be153c532cf25)`),i=void 0)):T&&console.log(`${n} existing lock not found for ${a} (I: 191af56ec4e2db3d19084e46bf949222)`),i){if(!i.data)throw new Error("(UNEXPECTED) existingLock.data falsy? (E: 00069b4662e5566d971760d15e293723)");s=v(i),s.data.alreadyLocked=!0,s.data.success=!1}else{let{ib:l,gib:d}=P({ibGibAddr:a});s={ib:l,gib:d,data:{scope:t,secondsValid:e,instanceId:o,expirationUTC:ho({seconds:e})}};let b=await r.argy({ibMetadata:Ge({space:r}),argData:{cmd:"put",force:!0,ibGibAddrs:[a]},ibGibs:[s]}),u=await r.witness(b);if(u.data?.success)if((u.data.addrsAlreadyHave??[]).includes(a)){T&&console.log(`${n} racelost! addrsAlreadyHave includes spaceLockAddr (${a}) (I: 2e8a1562947c40698110b64251141753)`);let p=await ne({addr:a,space:r,force:!0});if(p.success&&p.ibGibs?.length===1){let g=p.ibGibs[0];s=v(g),s.data.alreadyLocked=!0,s.data.success=!1}else{let g=`${n} (UNEXPECTED) addrsAlreadyHave true, but couldn't get lock? (E: 8374a2b6628b49369363bc5843105763)`;console.error(g),s.data.success=!1,s.data.errorMsg=g}}else s.data.success=!0;else{let p=`${n} there was an error putting the lock in the space: ${u.data?.errors?.join("|")}`;s.data.success=!1,s.data.errorMsg=p,console.error(p)}}return s}catch(s){throw console.error(`${n} ${s.message}`),s}finally{T&&console.log(`${n} complete.`)}}f(ea,"lockSpace");async function ta({space:r,scope:t,instanceId:e}){let o=`[${ta.name}]`;try{if(T&&console.log(`${o} starting...`),!r)throw new Error("space required. (E: 5c0a7197a75f483a82d74e5eea60df37)");if(!t)throw new Error("scope required. (E: c7f1dde9570f4df3b450faa2c2f85122)");let n=Vo({space:r,scope:t}),s=await Ko({addr:n,space:r,force:!0});if(s.success){let{ib:a,gib:i}=P({ibGibAddr:n});return{ib:a,gib:i,data:{success:!0,instanceId:e,scope:t}}}else{let a=`Delete lock in space failed. delete errorMsg: ${s.errorMsg}`;if(a.includes("not implemented"))throw new Error(a);if(a.toLowerCase().includes("does not exist")||a.toLowerCase().includes("doesn't exist")||a.toLowerCase().includes("not found")){T&&console.log(`${o} ${a} (I: b647916fd0f3e5366e9387131be21c22)`);let{ib:i,gib:c}=P({ibGibAddr:n});return{ib:i,gib:c,data:{action:"unlock",success:!0,instanceId:e,scope:t}}}else console.warn(`${o} ${a} (W: 14c84fcac15944bd9a417099964d5d9d)`)}}catch(n){throw console.error(`${o} ${n.message}`),n}finally{T&&console.log(`${o} complete.`)}}f(ta,"unlockSpace");async function dc({space:r,zeroSpace:t,setSpaceAsDefault:e,createIfNotFound:o}){let n=`[${dc.name}]`;try{if(T&&console.log(`${n} starting...`),!r)throw new Error("space required. (E: 6fc19548fa7d1d5219e19871f280a322)");if(!r.data?.uuid)throw new Error("space.data.uuid required (E: 6483188ca6f2ed2085fd355595f3ab22)");if(!t)throw new Error("zeroSpace required. (E: abbf156e18b1018d96273e22a260f122)");let s=r.data.uuid,a=y({ibGib:r}),i=await Vt({zeroSpace:t});if(i){if(T&&console.log(`${n} updating existing bootstrap (I: 977d4aa7ed47bef73b35743c05ce0722)`),i.data.spaceIds.includes(s)){T&&console.log(`${n} space already rel8d to bootstrap, possibly updating its addr (I: b5e2c515ef732d4bbcf02625a9e7c722)`);let c=i.rel8ns[s][0];c===a?T&&console.log(`${n} bootstrap already rel8d to space (I: c1be027b23e7350c64790a631cae2822)`):(T&&console.log(`${n} updating rel8ns[${s}] with newSpaceAddr (${a}). (Old address: ${c})(I: 297a9b0061fd471b8d28a06e04a6ad22)`),i.rel8ns[s]=[a])}else T&&console.log(`${n} new space being rel8d. adding spaceId to data.spaceIds and amending rel8ns (I: 40903d71719aa1d56e498299f5699a22)`),i.data.spaceIds.push(s),i.rel8ns[s]=[a];e&&(T&&console.log(`${n} setting spaceId (${s}) as default space (I: f85eda6c6ad2b0bec9750ce3c7795b22)`),i.data[_e]=s)}else{if(!o){T&&console.log(`${n} bootstrapIbGib not found but createIfNotFound falsy, so returning early. (I: 5c67d85a8599a5ba4a6780f26a66ea22)`);return}T&&console.log(`${n} creating new bootstrap ibgib for spaceId (${s}) with address of (${a}) (I: 651959c27bf2ebc5be1f7f44e2b9e422)`);let{ib:c,gib:l}=P({ibGibAddr:ze});i=M.primitive({ib:c}),i.gib=l,i.data={[_e]:s,[wr]:[s]},i.rel8ns={[s]:[a]}}if(!i)throw new Error("(UNEXPECTED) bootstrapIbGib still falsy? (E: cf21d7f1756710a66aa0e6a28d762723)");T&&console.log(`${n} saving bootstrapIbGib: ${H(i)} (I: 3cceca0b98dde90e4a58a734be252322)`),await Wo({zeroSpace:t,bootstrapIbGib:i}),T&&console.log(`${n} complete.`)}catch(s){throw console.error(`${n} ${s.message}`),s}}f(dc,"updateBootstrapIbGib");async function Wo({zeroSpace:r,bootstrapIbGib:t}){let e=`[${Wo.name}]`;if(!r)throw new Error("zeroSpace required. (E: 818fa8430b8040dca1917f9db0972b22)");if(!t)throw new Error("bootstrapIbGib required. (E: cf21d7f1756710a66aa0e6a28d762723)");let o=await r.argy({ibMetadata:t.ib,argData:{cmd:"put",force:!0,ibGibAddrs:[y({ibGib:t})]},ibGibs:[t]});T&&console.log(`${e} zeroSpace will witness/put... (I: 1be9aca22ffc4951b6690965a7aeae5b)`);let n=await r.witness(o);if(n?.data?.success)T&&console.log(`${e} zero space put complete. (I: ac3056d655e841f1a3c442bcc64942f9)`);else throw new Error(`${n?.data?.errors?.join("|")||"There was a problem with zeroSpace witnessing the bootstrap^gib primitive."}`)}f(Wo,"persistBootstrapIbGibInZeroSpace");async function fc({spaceId:r,zeroSpace:t}){let e=`[${fc.name}]`;if(!r)throw new Error("spaceId required. (E: 52f9c31405e24c2999e5a1b32d201a23)");if(!t)throw new Error("zeroSpace required. (E: a115f4007b2c4819a58cf093d5823b23)");await Ae({space:t,scope:ze,fn:f(async()=>{let n=await Vt({zeroSpace:t});if(!n)throw new Error("bootstrapIbGib falsy in zeroSpace (E: e36a512781b0467ba1bf1d927a7c1d23)");if(!n.data)throw new Error("bootstrapIbGib.data falsy in zeroSpace (E: 8f92104192b44d71891b092481029ab0)");let s=n.data,a=s[wr]??[];if(a.length<=1)throw new Error(`Cannot delete space (${r}). It is the only remaining local space. (E: 9c27f71120014b08b5e9f89993380e23)`);if(r===s[_e])throw new Error(`Cannot delete space (${r}). It is the default local space. Please select a new default space before deleting. (E: f3c30a5170d14b4fb2478d102e3b2e23)`);if(!a.includes(r))throw new Error(`Space (${r}) not found in bootstrap spaceIds. (E: 61fa940e79124430a618e470bc551d23)`);s[wr]=a.filter(i=>i!==r),n.rel8ns&&delete n.rel8ns[r],await Wo({zeroSpace:t,bootstrapIbGib:n})},"fn"),secondsValid:gr})}f(fc,"deregisterLocalSpaceFromBootstrap");async function bc({spaceId:r,zeroSpace:t}){let e=`[${bc.name}]`;if(!r)throw new Error("spaceId required. (E: 7c2a10529a1b412a8069e22e5190b623)");if(!t)throw new Error("zeroSpace required. (E: f112a512019c41a590b512a8e0915623)");let o=await t.argy({ibMetadata:Ge({space:t}),argData:{cmd:"get",ibGibAddrs:[r]}}),n=await t.witness(o);if(n?.data?.success&&(n.ibGibs?.length??0)>0){let s=y({ibGib:n.ibGibs[0]}),a=await t.argy({ibMetadata:Ge({space:t}),argData:{cmd:"delete",ibGibAddrs:[s]}});await t.witness(a)}}f(bc,"deleteSpaceRecordFromZeroSpace");function Ge({space:r}){return`${r.ib} ${ge()}`}f(Ge,"getSpaceArgMetadata");function qu({space:r}){return`${r.ib} ${ge()}`}f(qu,"getSpaceResultMetadata");function uc({space:r,spaceData:t,classname:e}){let o=`[${uc.name}]`;try{if(!r&&!t)throw new Error("either space or spaceData required (E: 4dabec34ee77d67c9cc30ee3c3049622)");if(r&&!r.data)throw new Error("(UNEXPECTED) given space has falsy space.data? (E: 058d298876ebbeada7bbddb9e3da2f23)");if(r&&t){if(r.data.uuid!==t.uuid)throw new Error("(UNEXPECTED) both space and spaceData given, but uuid don't match? (E: efdd4603cba93a17340a76811fe56b24)");if(r.data.n!==t.n)throw new Error("(UNEXPECTED) both space and spaceData given, but n don't match? (E: e51278a707c9bccc57a08a4b86524524)")}if(t??=r.data,!t)throw new Error("(UNEXPECTED) spaceData falsy? (thought this was a compiler problem that this was even possible.) (E: b3c7ffedcae4b1f45b263b3825930b24)");if(e&&t.classname&&e!==t.classname)throw new Error(`both classname arg (${e}) and spaceData.classname (${t.classname}) are different truthy values. (E: f98f012ee876eb8fbe7403f7b53e4624)`);if(e||=t.classname,!e)throw new Error("classname required (E: fa3af4613ad56742dab51d1b0d839322)");if(e.includes(" "))throw new Error(`invalid classname (${e}). cannot contain spaces (E: 243adbf720dcce7904e2665933208b22)`);let n=t?.name||is;if(n.includes(" "))throw new Error("invalid space name. cannot contain spaces (E: a8450e1651081412c8ac018520182422)");let s=t?.uuid||void 0;if(!s)throw new Error("invalid space, spaceData.uuid falsy (E: 50ae723a9ab24f4fc7132613e65faf23)");if(s.includes(" "))throw new Error("invalid space id. cannot contain spaces (E: 8696830fe7f54bfa85e670a063f3e089)");let a=t.type??void 0,i=t.subtype??void 0;if(a&&!i)throw new Error(`spaceType (${a}) is set but spaceSubtype is falsy. (E: 878ab960d7987ae2331103b4a00d0d24)`);return`${Sr} ${hr} ${e} ${n} ${s} ${a} ${i}`}catch(n){throw console.error(`${o} ${n.message}`),n}}f(uc,"getSpaceIb");function pc({ib:r}){let t=`[${pc.name}]`;if(!r){let e=`${t} ib required (E: dd5244f62f964359a86e59bb08ee47e6)`;throw console.error(e),new Error(e)}return r.startsWith(`${Sr} ${hr} `)}f(pc,"isSpaceIb");function Nr({spaceIb:r}){let t=`[${Nr.name}]`;try{if(!r)throw new Error("spaceIb required (E: fa5424cfb7e846e2851562f2f417944f)");let[e,o,n,s,a,i,c]=r.split(" ");if(e!==Sr)throw new Error(`invalid spaceIb (${r}). witnessAtom !== WITNESS_ATOM (E: 5ae1ca12cf8f30ae341f3e582b025224)`);if(o!==hr)throw new Error(`invalid spaceIb (${r}). spaceAtom !== SPACE_ATOM (E: 9cc6b6f30e13455eb29748148a94fa0f)`);if(!n)throw new Error(`invalid spaceIb (${r}). spaceClassname falsy (E: 00d3392da007ca8b2840b16b199d9a24)`);if(!s)throw new Error(`invalid spaceIb (${r}). spaceName falsy (E: b957d8e74ef34d889fa64c60c7a5ea0b)`);if(!a)throw new Error(`invalid spaceIb (${r}). spaceId falsy (E: 7a1773722d8e46a0866d683130b65b89)`);let l;if(i&&i!=="undefined")if(Ro.includes(i))l=i;else throw new Error(`invalid spaceIb (${r}). spaceType (${i}) is set but not a valid type. valid types: ${Ro.join(", ")} (E: 838f4638a88cfbf3545a3a3a38b6dd24)`);let d;if(c&&c!=="undefined")if(Co.includes(c))d=c;else throw new Error(`invalid spaceIb (${r}). spaceSubtype (${c}) is set but not a valid subtype. valid subtypes: ${Co.join(", ")} (E: 5bdcf23027f94e73860e4340313b04ab)`);return{spaceClassname:n,spaceName:s,spaceId:a,spaceType:l,spaceSubtype:d}}catch(e){throw console.error(`${t} ${e.message}`),e}}f(Nr,"parseSpaceIb");async function Pe({ibGibs:r,addrs:t,tjps:e,tjpAddrs:o,space:n}){let s=`[${Pe.name}]`;try{if(T&&console.log(`${s} starting...`),!n)throw new Error("space required. (E: 4d188d6c863246f28aa575753a052304)");if(r=r??[],t=t??[],e=e??[],o=o??[],t.length===0&&r.length===0&&e.length===0&&o.length===0)throw new Error("Either addrs, ibGibs, tjps, or tjpAddrs required. (E: 7c6ebfbab98d4d21a431b144457fd991)");let a=new Set(o.concat(e.map(l=>y({ibGib:l})))),i=Array.from(a).map(l=>P({ibGibAddr:l}).gib);r.map(l=>y({ibGib:l})).concat(t).forEach(l=>{let{gib:d}=P({ibGibAddr:l});i.some(u=>d.includes(u))||a.add(l)}),T&&console.log(`${s}[testing] ${n.data?.name||n.ib} (${n.data?.uuid||"[space.data.uuid falsy]"}) addrsToQuery: ${Array.from(a)} (I: 8a2202912c364238b6d6eb09577bc246)`);let c=await n.argy({ibMetadata:Ge({space:n}),argData:{cmd:"get",cmdModifiers:["latest","addrs"],ibGibAddrs:Array.from(a)}});return await n.witness(c)}catch(a){throw console.error(`${s} ${a.message}`),a}}f(Pe,"getLatestAddrs");function zo({ibGib_Context:r}){let t=`[${zo.name}]`;try{if(T&&console.log(`${t} starting... (I: 5f583fd94d27731a65d514e731b8aa22)`),!Wt({ibGib:r}))return;if(["roots","autosyncs"].some(o=>r.ib.includes(o)))throw new Error("cannot perform a modification of this type on this special ibgib (E: b8fb718a7323fc54454464b973412722)")}catch(e){throw console.error(`${t} ${e.message}`),e}finally{T&&console.log(`${t} complete.`)}}f(zo,"throwIfContextIsSpecial");async function hc({ibGib_Context:r,rel8nName_Context:t,addr:e,space:o,zeroSpace:n,fnUpdateBootstrap:s,fnBroadcast:a}){let i=`[${hc.name}]`;try{if(T&&console.log(`${i} starting... (I: 2dc486bb2d516e4534f437aaf5ec7f22)`),!r)throw new Error("ibGib_Context required (E: 75f7bfa93145d6dffe85d488443ca722)");if(!t)throw new Error("rel8nName_Context required (E: 12aaa43de9e34b68b25dc9a2a68ad6b9)");if(!e)throw new Error("addr required (E: e27df3bdc5a2554697cc9597afc4e422)");if(!o)throw new Error("space required (E: 2e3562486ed2956a770ed9e8d77a3f22)");let c=Wt({ibGib:r});c&&zo({ibGib_Context:r});let l=await Ie({src:r,rel8nsToAddByAddr:{[hs]:[e]},rel8nsToRemoveByAddr:{[t]:[e]},dna:!0,nCounter:!0});if(await ee({resTransform:l,space:o}),c){let d=y({ibGib:l.newIbGib}),b=Lr({ib:r.ib}),u=Q({type:b});await de({key:u,addr:d,space:o,zeroSpace:n,fnUpdateBootstrap:s})}await Ne({ibGib:l.newIbGib,fnBroadcast:a,space:o})}catch(c){throw console.error(`${i} ${c.message}`),c}finally{T&&console.log(`${i} complete.`)}}f(hc,"trash");async function gc({ibGib_Context:r,rel8nName_Context:t,addr:e,space:o,zeroSpace:n,fnUpdateBootstrap:s,fnBroadcast:a}){let i=`[${gc.name}]`;try{if(T&&console.log(`${i} starting... (I: 38098552b830495187299bb24fcddff0)`),!r)throw new Error("ibGib_Context required (E: d819e8c4db5b4c0bb721300ba434cd40)");if(!t)throw new Error("rel8nName_Context required (E: de061adff8c04429a211aa09116a532d)");if(!e)throw new Error("addr required (E: 7059ebb8ef6149ea94e22f961d6b5c81)");if(!o)throw new Error("space required (E: e19566f2d42347798621447edcae312e)");let c=Wt({ibGib:r});c&&zo({ibGib_Context:r});let l=await Ie({src:r,rel8nsToAddByAddr:{[ps]:[e]},rel8nsToRemoveByAddr:{[t]:[e]},dna:!0,nCounter:!0});if(await ee({resTransform:l,space:o}),c){let d=y({ibGib:l.newIbGib}),b=Lr({ib:r.ib}),u=Q({type:b});await de({key:u,addr:d,space:o,zeroSpace:n,fnUpdateBootstrap:s})}await Ne({ibGib:l.newIbGib,fnBroadcast:a,space:o})}catch(c){throw console.error(`${i} ${c.message}`),c}finally{T&&console.log(`${i} complete.`)}}f(gc,"archive");function Ec(r){let t=`[${Ec.name}]`;try{if(!r)return console.error(`${t} name is falsy`),!1;let e=/[\w-]+/,o=r.match(e);if(o?.length!==1||o[0].length!==r.length)return console.error(`${t} name can only contain letters, numbers, underscores, hyphens`),!1;let n=/[a-zA-Z\d]/;return r[0].match(n)?!0:(console.error(`${t} name must start with a letter or number`),!1)}catch(e){return console.error(`${t} ${e.message}`),!1}}f(Ec,"spaceNameIsValid");var se=!1;async function mc({ibGib:r,rel8nNames:t,space:e}){let o=`[${mc.name}]`;try{if(!r)throw new Error("ibGib required (E: a3c1b2d4e5f6a7b8c9d0e1f2a3b4c5d6)");if(!e)throw new Error("space required (E: b4d2c3e4f5a6b7c8d9e0f1a2b3c4d5e6)");t||(t=Object.keys(r.rel8ns||{}));let n={};for(let s of t){let a=r.rel8ns?.[s]||[];if(a.length>0){let i=await ne({addrs:a,space:e});if(i.success&&i.ibGibs?.length===a.length)n[s]=i.ibGibs.concat();else throw new Error(`Problem getting rel8d ibgibs for rel8nName: ${s}. ${i.errorMsg||"Unknown error"} (E: c5e3d4f5a6b7c8d9e0f1a2b3c4d5e6)`)}else n[s]=[]}return n}catch(n){throw console.error(`${o} ${m(n)}`),n}}f(mc,"getRel8dIbGibs");async function Te({parentPrimitiveIb:r,ib:t,ibRegExpPattern:e,data:o,rel8ns:n}){let s=`[${Te.name}]`;try{if(!r)throw new Error("parentPrimitiveIb required. (E: 88ddf188cc5a4340b597abefba1481e2)");if(Gt({ib:r})!==null)throw new Error(`Invalid parentPrimitiveIb: ${r}. (E:5aec0320956d492ebeeaca41eb1fe1c6)`);if(!t)throw new Error("ib required. (E: 7bbc88f4f2e842d6b00126e55b1783e4)");let a=e?new RegExp(e):ss;if(!t.match(a))throw new Error(`invalid ib. does not match regexp (${a})`);let i=Object.keys(n??{}),c=[...ct,"tjp"];if(i.some(u=>c.includes(u)))throw new Error(`Invalid rel8ns. forbiddenRel8nNames: ${c}. rel8ns keys: ${Object.keys(n??{})}. (E: 837a993c265c4362b6aa0b1a234ea5f8)`);let b=(await M.firstGen({ib:t,parentIbGib:M.primitive({ib:r}),data:o,rel8ns:n,dna:!1,noTimestamp:!0,nCounter:!1})).newIbGib;return b?.rel8ns?.past&&delete b.rel8ns.past,b?.rel8ns?.tjp&&delete b.rel8ns.tjp,b?.rel8ns?.identity&&delete b.rel8ns.identity,b.gib=await X({ibGib:{ib:b.ib,data:b.data,rel8ns:b.rel8ns},hasTjp:!1}),b}catch(a){throw console.error(`${s} ${a.message}`),a}}f(Te,"constantIbGib");function np({addr:r}){return ra({addr:r})}f(np,"getBinHashAndExt");function ra({addr:r}){let t=`[${ra.name}]`;try{if(!Kt({addr:r}))throw new Error("not a bin address (E: df0804d129bc4888bd6939cb76c5e0f6)");let{ib:e}=P({ibGibAddr:r}),o=e.split(" ");if(o.length===2)return{binHash:o[1],binExt:""};if(o.length===3)return o[2].startsWith("enc=")?{binHash:o[1],binExt:"",binEncoding:o[2].substring(4)}:{binHash:o[1],binExt:o[2]};if(o.length===4){if(!o[3].startsWith("enc="))throw new Error(`bin ib (${e}) has 4 space-delimited pieces. we expect therefore the form to be bin \${binHash} \${binExt} enc=\${binEncoding}. but ibPieces[3] doesn't start with "enc=". (E: 87196d7cdd7c12d982cc8204a1163524)`);return{binHash:o[1],binExt:o[2],binEncoding:o[3].substring(4)}}else throw new Error('(UNEXPECTED) ibPieces.length not 2, 3, or 4? atow (01/2024) the only components of a bin ib are: atom, binHash, binExt, binEncoding. binExt and binEncoding are optional, with binEncoding being prefixed with "enc=". (E: b05df3c1b3949f76464a83c9fd1c4f24)')}catch(e){throw console.error(`${t} ${e.message}`),e}}f(ra,"parseBinIb");function Kt({ibGib:r,addr:t}){let e=`[${Kt.name}]`;try{if(!r&&!t)throw new Error("either ibGib or addr required. (E: c935b51e773f41a2a547c556e9dc16c6)");if(r&&!r.data)return!1;t=t||y({ibGib:r});let{ib:o,gib:n}=P({ibGibAddr:t});if(!o||!n||!o.startsWith("bin "))return!1;if(n.length!==64)throw new Error('ib starts with "bin " but gib length is not 64, so return false. Two things: 1) bin ibgibs are expected to be stones, i.e., have no temporal junction point and only a single punctiliar hash for the gib. the default hash used atow (01/2024) is sha-256, so the length should be 64. But this may not be true if using another hash algorithm. need to change this function when this becomes the case. (W: 60725d65d13c4b4fbb7b96d7feb19d67)');let s=o.split(" ");if(s.length===2){if(!s[1].match(z))throw new Error('(UNEXPECTED) ib starts with "bin " but space-delimited !ibPieces[1].match(UUID_REGEXP)? (E: f6baca2ff155f1017b278a5d7597a224)')}else if(s.length===3){if(!s[1].match(z))throw new Error('(UNEXPECTED) ib starts with "bin " but space-delimited !ibPieces[1].match(UUID_REGEXP)? (E: 8d0443d6cada4b50be79a8390a7a426c)')}else if(s.length===4){if(!s[1].match(z))throw new Error('(UNEXPECTED) ib starts with "bin " but space-delimited !ibPieces[1].match(UUID_REGEXP)? (E: 3209eacc0a3848a59593d4c3ee956191)');if(!s[3].startsWith("enc="))throw new Error('(UNEXPECTED) ib starts with "bin " but space-delimited !ibPieces[3].startsWith("enc=")? (E: 4c8a0c3b07a90d30e3d1a4373d57d824)')}else throw new Error('(UNEXPECTED) ib starts with "bin " but space-delimited ibPieces length is not 2, 3 or 4? (E: c7eccf88518304997c7e42b32e08d224)');return!0}catch(o){throw console.error(`${e} ${o.message}`),o}}f(Kt,"isBinary");function Jo({type:r}){if(!r.match(So))throw new Error(`special ibgib type must not have spaces and just be alphanumerics. regexp: ${So.source} (E: 6c1c92521b7f076cc4666e4915593723)`);return`meta special ${r}`}f(Jo,"getSpecialIbGibIb");function Lr({ib:r}){let t=`[${Lr.name}]`;try{if(se&&console.log(`${t} starting... (I: c82ba222bd345ee6b695df4d63a23322)`),!r)throw new Error("ib required (E: 08897145f7138e644fe01c4a59353322)");if(!Wt({ib:r}))throw new Error("ib is not special (E: 174aff63b992adff3ac2394643735922)");let e=r.split(" ");if(e.length<3)throw new Error('invalid ib. should be space-delimited in form of "meta special [type]" (E: ffd89e2cbe63427f98634ab897aab222)');let o=e[2];return Object.values(pr).some(n=>n===o)||console.warn(`unknown special type (${o}). This may be expected, but atow I am adding special types to the SpecialIbGibType enum-like. (W: f4e26c3ebb57fe49d69014a4ba32a922)`),o}catch(e){throw console.error(`${t} ${e.message}`),e}finally{se&&console.log(`${t} complete.`)}}f(Lr,"getSpecialTypeFromIb");function wc({type:r}){return`${Jo({type:r})}^${L}`}f(wc,"getSpecialIbGibAddr");function Q({type:r}){return`${Es} ${wc({type:r})}`}f(Q,"getSpecialConfigKey");function Wt({ib:r,ibGib:t}){if(!r&&!t?.ib)throw new Error("either ib or ibGib.ib required (E: b4cf539638d7966c2e351987f55e1a23)");return(r??t?.ib)?.startsWith("meta special")}f(Wt,"isSpecial");function Zo(r){let t=`[${Zo.name}]`;if(!r)throw new Error(`${t} text required.`);return`root ${r}`}f(Zo,"getRootIb");function dt(r){let t=`[${dt.name}]`;if(!r)throw new Error(`${t} tag required.`);return`tag ${r}`}f(dt,"tagTextToIb");function Pr({ibGibs:r,filterPrimitives:t}){let e=`[${Pr.name}]`;try{let o={},n={},s={};return(t?r.filter(i=>i.gib??i.gib!==L):r).forEach(i=>{oa({ibGib:i})?(i.rel8ns?.dna??[]).length>0?o[i.gib]=i:n[i.gib]=i:s[i.gib]=i}),{mapWithTjp_YesDna:o,mapWithTjp_NoDna:n,mapWithoutTjps:s}}catch(o){throw console.error(`${e} ${o.message}`),o}}f(Pr,"splitPerTjpAndOrDna");function zt({ibGibs:r}){let t=`[${zt.name}]`;try{se&&console.log(`${t} starting...`);let{mapWithTjp_YesDna:e,mapWithTjp_NoDna:o}=Pr({ibGibs:r,filterPrimitives:!0}),n={...e,...o},s=Object.values(n),a=po({items:s,keyFn:f(i=>i.data?.isTjp?y({ibGib:i}):i.rel8ns?.tjp?i.rel8ns?.tjp[0]??"":(se&&console.log(`${t} neither isTjp nor x.rel8ns.tjp truthy (I: ec9a5597bf53dec1bd3d83350abbf823)`),""),"keyFn")});return se&&console.log(`${t} sorting (ascending) ibGibsWithTjpGroupedByTjpAddr: ${H(a)} (I: 9b9fff5ce61444a6cb06d62db9a99422)`),Object.entries(a).forEach(([i,c])=>{c.some(l=>l.data?.n===void 0)&&console.warn(`${t} timeline includes ibgibs with ibGib.data?.n === undefined (W: cab9a6b64a38c4279fe82c3569bbab22)`),c.sort((l,d)=>(l.data?.n??-1)>(d.data?.n??-1)?1:-1)}),se&&console.log(`${t} after sort ibGibsWithTjpGroupedByTjpAddr: ${H(a)} (I: 9b9fff5ce61444a6cb06d62db9a99422)`),a}catch(e){throw console.error(`${t} ${e.message}`),e}finally{se&&console.log(`${t} complete.`)}}f(zt,"getTimelinesGroupedByTjp");function oa({ibGib:r}){let t=`[${oa.name}]`;if(!r)throw new Error("(UNEXPECTED) ibGib falsy? (E: ce3a59f9db14e6158bb2c438ca1a3823)");if((r.rel8ns?.tjp?.length??0)>0||r.data?.isTjp)return!0;let e=["fork^gib","mut8^gib","rel8^gib"];return(r.rel8ns?.ancestor??[]).some(n=>e.includes(n))?!1:r.gib?r.gib.includes(Oe)?!0:r.gib===L?!1:!!re({ibGibAddr:y({ibGib:r})}).tjpGib:(console.warn(`${t} ibGib.gib falsy. (W: 6400d780822b44d992846f1196509be3)`),!1)}f(oa,"hasTjp");function be({ibGib:r,defaultIfNone:t="undefined"}){let e=`[${be.name}]`;try{let o=na({ibGibs:[r],defaultIfNone:t});return o&&Object.keys(o).length===1?Object.values(o)[0]:void 0}catch(o){throw console.error(`${e} ${o.message}`),o}}f(be,"getTjpAddr");function na({ibGibs:r,defaultIfNone:t="undefined"}){let e=`[${na.name}]`;try{let o={};return r.forEach(n=>{let s=y({ibGib:n}),a;n.rel8ns?.tjp?.length??!1?a=n.rel8ns.tjp[n.rel8ns.tjp.length-1]:n.data?.isTjp||t==="incomingAddr"?a=s:a=void 0,o[s]=a}),o}catch(o){throw console.error(`${e} ${o.message}`),o}}f(na,"getTjpAddrs");async function Qo({ibGib:r,naive:t=!0}){let e=`[${Qo.name}]`;try{if(!r)throw new Error("ibGib required.");if(t){if(r.data)return r.data.isTjp?!0:r.rel8ns?r.rel8ns.past&&r.rel8ns.past.length>0?!1:!!(r.rel8ns.past&&r.rel8ns.past.length===0):(se&&console.log(`${e} ibGib.rel8ns falsy (I: c69c9e78b34845311ce7c674d7195622)`),!1);throw new Error("loaded ibGib required (data).")}else throw new Error("only naive implemented right now.")}catch(o){throw console.error(`${e} ${o.message}`),o}}f(Qo,"isTjp_Naive");function Re({ibGib:r}){let t=`[${Re.name}]`;r.ib||console.warn(`${t} ibGib.ib is falsy. (W: e60e41c2a1fc48268379d88ce13cb77b)`),r.gib||console.warn(`${t} ibGib.gib is falsy. (W: fb3889cbf0684ae4ac51e48f28570377)`);let e={ib:(r.ib||"").slice()};return r.gib&&(e.gib=r.gib.slice()),r.data&&(Kt({ibGib:r})?e.data=r.data.slice():e.data=v(r.data)),r.rel8ns&&(e.rel8ns=v(r.rel8ns)),e}f(Re,"toDto");function en(r){let t=`[${en.name}]`;try{return se&&console.log(`${t} starting... (I: 57aef93fc6cc2309523b5c72a6b11823)`),!!r&&typeof r.ib=="string"}catch(e){throw console.error(`${t} ${e.message}`),e}finally{se&&console.log(`${t} complete.`)}}f(en,"isIbGib");function Xt({ibGib:r,data:t,timestamp:e}){let o=`[${Xt.name}]`;try{se&&console.log(`${o} starting... (I: 35cb68744bcf6139d78e37de644fad23)`),e=e||t?.timestamp||r?.data?.timestamp;let n=r?.data?.timestampMs||t?.timestampMs;if(!e){let s=`${o} timestamp is falsy. (W: 5f1f1182c8804807b886a3d922ac3dcf)`;return console.warn(s),{valid:!1,emsg:s}}if(typeof e=="string")if(Number.isInteger(Number.parseInt(e))){let s=Number.parseInt(e),a=new Date;if(a.setTime(s),a.toString()!==Er)return se&&console.log(`${o} valid timestampInTicks string (I: 7069a1c3047f3bbc92b78674b20f5b23)`),{valid:!0,date:a,utc:a.toUTCString(),ticks:a.getTime().toString(),ms:n};{let i=`${o} data.timestamp (${e}) is an integer string but not a valid timestampInTicks string. (produces invalid date) (E: f49fbb600fe1426c8805dfc8afbe5cf3)`;return console.error(i),{valid:!1,emsg:i}}}else{let s=new Date(e);if(s.toString()!==Er)return{valid:!0,date:s,utc:s.toUTCString(),ticks:s.getTime().toString(),ms:n};{let a=`${o} data.timestamp is a non-integer string but not a valid date timestamp string (new date instantiated produces invalid date). (W: c6c90f7f3bfb49838d2081ba84fdb5fb)`;return console.warn(a),{valid:!1,emsg:a}}}else if(typeof e=="number")if(Number.isInteger(e)){console.warn(`${o} expected data.timestamp to be a string but is a number (W: 9d786f4d4e8d4279b5af7bee19bf721b)`);let s=new Date;if(s.setTime(e),s.toString()!==Er)return{valid:!0,date:s,utc:s.toUTCString(),ticks:s.getTime().toString(),ms:n};{let a=`${o} timestamp (${e}) is an integer number but not a valid timestampInTicks (new date setTime produces invalid date). (W: c6c90f7f3bfb49838d2081ba84fdb5fb)`;return console.warn(a),{valid:!1,emsg:a}}}else{let s=`${o} timestamp (${e}) is a non-integer number (supposed to be a string either timestamp string or ticks). (E: 2963d95f8d3b464c992b0bff948b4479)`;return console.error(s),{valid:!1,emsg:s}}else{let s=`${o} unknown typeof timestamp (${typeof e}). (E: 12458a9c16c84e4f859b5771a30dd2ef)`;return console.error(s),{valid:!1,emsg:s}}}catch(n){throw console.error(`${o} ${m(n)}`),n}finally{se&&console.log(`${o} complete.`)}}f(Xt,"getTimestampInfo");async function tn({addrs:r,readCache_graph:t,readCache_array:e,space:o}){let n=`[${tn.name}]`;try{se&&console.log(`${n} starting... (I: 5db66871239dfa05182277f886a20926)`),t??={},e??=[];let s={...t};e.forEach(l=>s[y({ibGib:l})]=l);let a=Object.keys(t),i=r.filter(l=>!a.includes(l));if(i.length>0){se&&console.log(`${n} ${i.length} addrsNotFoundInCache: ${i} (I: fccbd18116ffb849f813aaebfc6c0826)`);let l=[o],d=i.concat();for(let b of l){let u=await ne({addrs:d,space:b});if(u.success&&u.ibGibs&&u.ibGibs.length===d.length)u.ibGibs.forEach(p=>s[y({ibGib:p})]=p),d=[];else if(u.ibGibs&&u.ibGibs.length>0){if(d=d.filter(p=>!u.ibGibs.some(g=>y({ibGib:g})===p)),d.length===0)break}else se&&console.log(`${n} no addrs found in space (${b.ib}). trying next space. (I: 4f99d8bacbb10ab3f8737a752564b326)`)}if(d.length>0)throw new Error(`could not get all addrs from cache or spaces. addrsStillNotFound: ${d}. spaces: ${l.map(b=>b.ib).join("|")} (E: 0c6418f83dd85bda886e56f5b98f3126)`)}let c=[];for(let l of r){let d=s[l];if(!d)throw new Error(`(UNEXPECTED) allIbGibs_graph doesn't have addr? We're expecting logic to preclude this at this point. addr: ${l} (E: f68e1d236ae5e3eb08da9933c8230626)`);c.push(d)}return c}catch(s){throw console.error(`${n} ${m(s)}`),s}finally{se&&console.log(`${n} complete.`)}}f(tn,"getIbGibsFromCache_fallbackToSpaces");var sa=!1,$c="space_gib_db",yc="space_gib_store",Ic="space_gib_api_key";var _c="agent";var lp=dt(_c);var dp={dbName:$c,storeName:yc,additionalStoreNames:[as],apiKeyName:Ic};var aa="0.0.13";var et=!1,pp="[web^gib timer]",rn="ibgib";var Tc="agent",hp="body-outline",gp="This tag tracks the active agents for the current local user space.",Ep=dt(Tc),ia="#78f87e88",ca="#78f87e10",la="#ffffff";var mp="AUTOMATED_TEXT";var Se=!1;function da(r){return new Promise((t,e)=>{let o=new Blob([r],{type:"application/octet-stream"}),n=new FileReader;n.onload=()=>{let a=n.result.split(",")[1];t(a)},n.onerror=s=>e(s),n.readAsDataURL(o)})}f(da,"uint8ArrayToBase64");async function fa(r){let t=`data:application/octet-stream;base64,${r}`,n=await(await(await fetch(t)).blob()).arrayBuffer();return new Uint8Array(n)}f(fa,"base64ToUint8Array");async function Rr({graph:r}){let t=`[${Rr.name}]`;try{Se&&console.log(`${t} starting... (I: 4ddb8803cf68e1d3d35f60680cb69825)`);let e=JSON.parse(JSON.stringify(r));for(let n in e)r[n].data instanceof Uint8Array&&(e[n].data={_dataType:"Uint8Array_Base64",value:await da(r[n].data)});let o=JSON.stringify(e);return Se&&console.log(`${t} jsonString.length: ${o.length} (I: 56dec8ad0931ab8ba9b5ca3d4e66be25)`),o}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{Se&&console.log(`${t} complete.`)}}f(Rr,"serializeGraphToString");async function Cr({jsonString:r}){let t=`[${Cr.name}]`;try{Se&&console.log(`${t} starting... (I: 52e1a1fb1adcc75168fbc6d819868825)`);let o=JSON.parse(r,f((n,s)=>(s&&s._dataType==="Uint8Array_Base64",s),"reviver"));for(let n in o){let s=o[n].data;s&&s._dataType==="Uint8Array_Base64"&&(o[n].data=await fa(s.value))}return o}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{Se&&console.log(`${t} complete.`)}}f(Cr,"deserializeStringToGraph");async function ba(r){let t=`[${ba.name}]`;try{Se&&console.log(`${t} starting... (I: 8d306868b718596fe8f562bd5118d825)`);let e=await Rr({graph:r}),o=new TextEncoder().encode(e),s=new Response(o).body.pipeThrough(new CompressionStream("gzip"));return await new Response(s).blob()}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{Se&&console.log(`${t} complete.`)}}f(ba,"compressIbGibToBlob");async function Ac(r){let t=r.stream().pipeThrough(new DecompressionStream("gzip")),e=await new Response(t).text();return await Cr({jsonString:e})}f(Ac,"decompressIbGibFromBlob");async function on({graph:r}){let t=`[${on.name}]`;try{Se&&console.log(`${t} starting... (I: 1352f8540c08f0b725952df8f18c4825)`);let o=await(await ba(r)).arrayBuffer(),n=new Uint8Array(o);return await da(n)}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{Se&&console.log(`${t} complete.`)}}f(on,"compressIbGibGraphToString");async function nn({compressedBase64:r}){let t=`[${nn.name}]`;try{Se&&console.log(`${t} starting... (I: 5f3fa940a2c8f8d7b877978ae7f87825)`);let e=await fa(r),o=new Blob([e],{type:"application/gzip"});return await Ac(o)}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{Se&&console.log(`${t} complete.`)}}f(nn,"decompressIbGibGraphFromString");var ua="export";var Jt=!1;function pa({data:r}){let t=`[${pa.name}]`;try{Jt&&console.log(`${t} starting... (I: 158dfaeb9613a1531be71a9735184624)`);let{graphSize:e,dependencyGraphAsString:o,timestamp:n}=r,s=o.length,a=ge(n),i=r.compression==="gzip"?"gzip":"raw";if(!r.timestamp)throw new Error("(UNEXPECTED) data.timestamp falsy? (E: 2f5bc88488cbf260634239a8a8396825)");let c=new Date(r.timestamp),{ib:l,gib:d}=P({ibGibAddr:r.contextIbGibAddr}),u=re({gib:d}).tjpGib??d,p=c.toISOString().slice(0,19).replace("T","_").replace(/:/g,"").replace(/ /g,"_");return`${ua} ${p} ${i} ${e} ${s} ${u}`}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{Jt&&console.log(`${t} complete.`)}}f(pa,"getRawExportIb");async function sn({ibGib:r,metaspace:t,space:e,compress:o,live:n,ignoreErrors:s}){let a=`[${sn.name}]`;try{if(Jt&&console.log(`${a} starting... (I: 0b6ba8608ba8bde0682a0936b9a01825)`),!r)throw new Error("(UNEXPECTED) ibGib falsy? (E: d2898eea744360865f0da5fb91baae22)");let i=y({ibGib:r}),c=[],l=await oe({ibGib:r})??[];if(l.length>0){let $=`ibGib had validation errors: ${l} (E: 84890bbc0598192498178a98ae299825)`;if(s)c.push({errorMsg:$,ibGibAddr:i});else throw new Error($)}let d=await t.getDependencyGraph({ibGib:r,live:n,space:e}),b=o?await on({graph:d}):await Rr({graph:d}),u=be({ibGib:r,defaultIfNone:"incomingAddr"})??i,p=new Date,g={contextIbGibAddr:i,tjpAddr:u,dependencyGraphAsString:b,graphSize:Object.keys(d).length,timestamp:xe(p),timestampMs:p.getMilliseconds()};o&&(g.compression="gzip");let h={ib:pa({data:g}),data:g},E=await X({ibGib:h,hasTjp:!1});return h.gib=E,console.log(`${a} JSON.stringify(exportIbGib).length: ${JSON.stringify(h).length} (I: db3a8d913a91d8fc5d6e45981e034822)`),{rawExportIbGib:h,manifest:Object.keys(d),errors:c.length>0?c:void 0}}catch(i){throw console.error(`${a} ${m(i)}`),i}finally{Jt&&console.log(`${a} complete.`)}}f(sn,"getRawExportIbGib");var Rp="ibgib-shell-ready",Cp="ibgib-ui-busy",Up="ibgib-ui-message",Mp="ibgib-identity-request-change",kp="ibgib-identity-changed",jp="ibgib-identity-update-available";var ha=et;async function Ot({title:r,msg:t,prompt:e,showInput:o,defaultValue:n,okButtonTitle:s,cancelButtonTitle:a,isPassword:i,isBusy:c,animationEmoji:l}){let d=`[${Ot.name}]`;try{ha&&console.log(`${d} starting... (I: 037b228a2568181cd3eb25dba4e03225)`);let b=document.getElementById("fullscreen-dialog"),u=document.getElementById("fullscreen-dialog-body"),p=document.getElementById("fullscreen-dialog-title"),g=document.getElementById("fullscreen-dialog-message"),h=document.getElementById("fullscreen-dialog-prompt-input"),E=document.getElementById("fullscreen-dialog-ok-button"),$=document.getElementById("fullscreen-dialog-cancel-button");if(!b||!u||!p||!g||!h||!E||!$)throw new Error("(UNEXPECTED) One or more dialog elements not found in DOM (E: 578e37c0271cc57a99e95e780ad18a25)");if(p.textContent=r||"",[...g.childNodes].forEach(w=>g.removeChild(w)),(t||"").split(`
|
|
8
|
+
latestAddr: ${E} (W: 141b69dc3c414efc9645bb76fcf12df9)`)}return p}catch(d){let b=`${l} ${d.message}`;return b.includes("d8ebdc9eaaa640b99cd206f132962c93")&&c||console.error(b),null}}f(Dr,"getSpecialIbGib");async function vr({key:r,space:t,dontWarn:e}){let o=`[${vr.name}](${r})`;try{if(T&&console.log(`${o} getting... (I: 43e7bfc2515d45e5af8767b9a85b248e)`),!t)throw new Error("space required. (E: 4f135d4276e64054ba21aeb9c304ecec)");if(!t.rel8ns){(T||!e)&&console.warn(`${o} space.rel8ns falsy. (W: 7c642259fbf547dbaa1b2fdf0115f6ef)`);return}if(!t.rel8ns[r]){(T||!e)&&console.warn(`${o} space.rel8ns[${r}] falsy. (W: 3c1c49b9987b45cc96dd78b808f98e91)`);return}if(t.rel8ns[r].length===1)return T&&console.log(`${o} got (I: f13e71b693d5404c9535bda8ff0cc6a9)`),t.rel8ns[r][0];if(t.rel8ns[r].length>1)return(T||!e)&&console.warn(`${o} more than one config addr with ${r} rel8n. (W: 102f63eb74904bcfaac2eaf778043205)`),t.rel8ns[r][0];T&&console.log(`${o} didn't find (I: 1163e6ac60194d25b3f24881650edfad)`);return}catch(n){console.error(`${o} ${n.message}`);return}}f(vr,"getConfigAddr");async function de({key:r,addr:t,space:e,zeroSpace:o,fnUpdateBootstrap:n}){let s=`[${de.name}]`;try{if(!e)throw new Error("space required. (E: c28b663c991d44419aef1026cc689636)");if(!o)throw new Error("zeroSpace required. (E: d3707ae5265d464891ad216f64be6184)");let a={[r]:[t]},i=await Ie({src:e.toIbGibDto(),dna:!1,linkedRel8ns:["past","ancestor",r],rel8nsToAddByAddr:a,nCounter:!0});if(!i.newIbGib)throw new Error("create new space failed.");await ee({resTransform:i,space:o}),await ee({resTransform:i,space:e});let c=i.newIbGib;return await e.loadIbGibDto(c),n?await n(c):console.warn(`${s} fnUpdateBootstrap is falsy. (W: 9fb874de2b19454dac18645e61ac463f)`),c}catch(a){throw console.error(`${s} ${a.message}`),a}}f(de,"setConfigAddr");async function ks({space:r}){let t=`[${ks.name}]`;try{if(!r)throw new Error("space required. (E: f0d546101fba4c169256158114ab3c56)");let e=await Dr({type:"roots",space:r});if(!e)throw new Error("Roots not initialized. (E: 89b1ba12ed12416aac41cef9fdaf1fc2)");if(!e.rel8ns)throw new Error("Roots not initialized properly. No rel8ns. (E: 8513a07cf530484db9521a2a3a27b7f6)");if(!e.rel8ns.current)throw new Error("Roots not initialized properly. No current root. (E: 459c3a007a30486d96fb8d83f696e239)");if(e.rel8ns.current.length===0)throw new Error("Invalid Roots: empty current root rel8n. (E: bede5864090440bca01ea7ab7fd107d6)");if(e.rel8ns.current.length>1)throw new Error("Invalid Roots: multiple current roots selected. (E: 97561acbf63a48ecaa037697bd26555a)");let o=e.rel8ns.current[0],n=await ne({addr:o,space:r});if(n.ibGibs?.length===1)return n.ibGibs[0];throw new Error(`could not get current root. addr: ${o}`)}catch(e){console.error(`${t} ${e.message}`);return}}f(ks,"getCurrentRoot");async function Vo({root:r,space:t,zeroSpace:e,fnUpdateBootstrap:o,fnBroadcast:n}){let s=`[${Vo.name}]`;try{if(T&&console.log(`${s} starting... (I: 7f16e845a80fe95d28923e4170f0c825)`),!r)throw new Error("root required.");if(!t)throw new Error("space required. (E: 186af2731c5342a78b063a0a4346f3db)");let a=y({ibGib:r}),i=await Dr({type:"roots",space:t});if(!i)throw new Error("Roots not initialized. (E: a8232b9afac89d0d189534480b7a9825)");let l=await Ie({src:i,dna:!1,linkedRel8ns:["past","ancestor","current"],rel8nsToAddByAddr:{current:[a]},nCounter:!0});await ee({resTransform:l,space:t});let d=Q({type:"roots"}),b=l.newIbGib,u=y({ibGib:b});await de({key:d,addr:u,space:t,zeroSpace:e,fnUpdateBootstrap:o}),await Ne({ibGib:b,space:t,fnBroadcast:n})}catch(a){throw console.error(`${s} ${a.message}`),a}finally{T&&console.log(`${s} complete. (I: 7f16e845a80fe95d28923e4170f0c825)`)}}f(Vo,"setCurrentRoot");async function js({ibGib:r,linked:t,rel8nName:e,space:o,fnBroadcast:n,zeroSpace:s,fnUpdateBootstrap:a}){let i=`[${js.name}]`;try{if(!o)throw new Error("space required. (E: f2758eab3bb844d2b749515672d9e392)");if(!r)throw new Error("ibGib required (E: f1bfd67754a7271553f4af544d30bc22)");let c=await ks({space:o});if(!c)throw new Error("currentRoot undefined (E: 5c2d84dafc664808866008f6eb535750");let l=ue({ibGib:r,defaultIfNone:"incomingAddr"}),d=y({ibGib:r});if(e&&l&&c.rel8ns&&c.rel8ns[e]&&c.rel8ns[e].includes(l))return;e=e||_o;let b=await Ie({src:c,dna:!1,linkedRel8ns:t?["past","ancestor",e]:["past","ancestor"],rel8nsToAddByAddr:{[e]:[d]},nCounter:!0});await ee({resTransform:b,space:o});let u=b.newIbGib,p=y({ibGib:u});T&&console.log(`${i} updating _currentRoot root. newRootAddr: ${p}`),await Ne({ibGib:u,space:o,fnBroadcast:n}),await Vo({root:u,space:o,zeroSpace:s,fnUpdateBootstrap:a,fnBroadcast:n})}catch(c){console.error(`${i} ${c.message}`);return}}f(js,"rel8ToCurrentRoot");async function qo({targetIbGib:r,space:t}){let e=`[${qo.name}]`;try{T&&console.log(`${e} starting... (I: 291638372117dbc983b4b7cbd8f52123)`);let o=await Fo({targetIbGib:r}),n=await Xo({ibGib:o,space:t});if(!n.success)throw new Error(`error putting metaStone in space. error: ${n.errorMsg??"[unknown error (E: 45f700f4f1ff463ca8f5353c8e796ac7)]"} (E: 4c25379e66365055e3e423561a7d6123)`)}catch(o){throw console.error(`${e} ${m(o)}`),o}finally{T&&console.log(`${e} complete.`)}}f(qo,"createAndSaveNewMetaStone");async function Ne({ibGib:r,space:t,fnBroadcast:e}){let o=`[${Ne.name}]`,n=T;try{let s=y({ibGib:r});if(o=`${o}[${s}]`,!t)throw new Error("space required. (E: ea0c03256f8a4062b460aa4de11f1e3e)");if(T&&console.log(`${o} starting...`),!re({ibGibAddr:s}).tjpGib&&!r.data?.isTjp){T&&console.log(`${o} incoming ibGib has no timeline, so no broadcast. still going to create a metastone for it and return early. (I: 649752e3b1be0e0ceb078e0ec2a84f23)`),await qo({targetIbGib:r,space:t});return}let i=ue({ibGib:r,defaultIfNone:"undefined"});if(!i){let g=r.data?.isTjp?r:await Ho({ibGib:r,space:t});g||(console.warn(`${o} tjp not found for ${s}? Should at least just be the ibGib's address itself. (W: d9b570e5bf6d4312bc7d9249ed3bbaad)`),g=r),i=y({ibGib:g})}if(!i)throw new Error("(UNEXPECTED) tjpAddr falsy? should be guaranteed at this point. (E: 39aafb70bc3c6d70b6d2cf8882311223)");let c=f(async()=>{T&&console.log(`${o} adding/replacing latest. tjp: ${i} (I: 7f848da003a2436089fd6f044d96bb42)`),await qo({targetIbGib:r,space:t}),e&&(T&&console.log(`${o} fnBroadcast is true...(I: 0e3b561fb5474a0598b5c6d698df5e1f)`),setTimeout(()=>{T&&console.log(`${o} broadcasting... (I: 61785937be0346f0959d476d7267ab24)`),e({ib:"IbGibTimelineUpdateInfo",tjpAddr:i,latestAddr:s,latestIbGib:r})}))},"replaceLatest");if(r.data?.isTjp){T&&console.log(`${o} ibGib.data?.isTjp true. replacingLatest and returning early. (I: 02c626e006668291550e278b461bcb23)`),await c();return}T&&console.log(`${o} ibGib.data?.isTjp is falsy. (I: 84940e3a9eff869c9474b7b92b864b23)`);let l=await Ce({ibGibs:[r],space:t});if(!l.data)throw new Error("(UNEXPECTED) resLatest.data falsy? (E: af3d3914d96adcc5525e4db83cc5d223)");let{success:d,latestAddrsMap:b}=l.data;if(!d){let{errors:g}=l.data;throw g??=["[unknown error (E: 344857f1853641aa842cea3931f90428)]"],new Error(`resLatest.success falsy. errors: ${H(g)}. addr: ${s} (E: b66721da6e1ef9ac4f4089e86c059323)`)}if(!b)throw new Error("(UNEXPECTED) latestAddrsMap falsy but success truthy? (E: c34caff7a256503575ff3ff491dec823)");let u=Object.keys(b);if(u.length!==1)throw new Error("(UNEXPECTED) latestAddrsMap size isn't 1? (E: e11ffc2c18d473745b5bbfc3fe5e3a23)");if(u[0]!==s)throw new Error(`(UNEXPECTED) latestAddrsMap has 1 key (correct) but the key isn't the incoming ibGibAddr? (incorrect). incoming ibGibAddr: ${s}. key found: ${u[0]} (E: 82d79a95d2d7de90eae9db571a360f23)`);T&&(console.log(`${o} valid latestAddrsMap. console.dir(latestAddrsMap)... (I: e24de41622cabbef375172c3017cfd23)`),console.dir(b));let p=b[s];if(p)if(p===s){T&&console.log(`${o} no other found. possible idempotent replacement. addr: ${s} (I: 7f5bd5d3391be95919240f0e97976e22)`),await c();return}else{T&&console.log(`${o} different addr found. incoming ibgib addr is newer. existingLatestAddr: ${p}. incoming addr: ${s} (I: 6cadf13f82aabeb71d76babf1813e623)`);let g=await ne({addr:p,space:t});if(!g.success||g.ibGibs?.length!==1){console.error(`Didn't find existing latest ibGib (${p}). I haven't implemented more robust multi-node/distributed strategies for this scenario yet. so we are going ahead with setting the incoming ibgib as the latest in the timeline. (E: 10f6cca6e5ef45bfacbfe48f652e2102)`),await c();return}let h=g.ibGibs[0];if(typeof r.data?.n=="number"&&r.data.n>=0){T&&console.log(`found ibGib.data.n (version counter), using this to determine latest ibGib: ${r.data.n}`);let $=r.data.n;if(typeof h.data?.n=="number"&&h.data.n>=0){let A=h.data.n;if($>A)T&&console.log(`${o} is newer (I: 040d05ac2032f08c7fd0c4d8b2887323)`),await c();else{T&&console.log("is not newer, so we don't need to do anything else. (I: 14c25dc3314748dc909d61b77eb64354)"),console.warn(`${o} incoming ibGib (${s}) is NOT NEWER than existing latest (${p}). multiple branches for the same timeline? ignoring incoming ibGibAddr. n_ibGib: ${$}. n_existingLatest: ${A}. space.ib: ${t.ib} (W: 057baadca494473dabb26fb4fb879774)`);return}}else h.data?.isTjp&&r.data.n===0?await c():(console.warn(`${o} (UNEXPECTED) only existingLatestIbGib (isTjp: ${h.data?.isTjp}) has a data.n counter? ibGib.data.n: ${r.data.n}. usually this only happens when existing latest is a tjp and the new ibGib we are registering is n === 0. This is falsy in this instance though. We will go ahead and replace the latest with the new one, but this is an anomalous state. (W: 73d08aea17ad4e1481a5f97e2556a878)`),console.log(`${o} console.dir(existingLatestIbGib)... (I: 9ef7962d9cc74f1eb0409e5caf98e915)`),console.dir(h),console.log(`${o} console.dir(ibGib)... (I: 9ef7962d9cc74f1eb0409e5caf98e915)`),console.dir(r),await c())}else if(T&&console.log(`${o} no nCounter found. Trying brute force method.`),await Qs({ibGib:r,ibGibAddr:s,existingLatest:h,existingLatestAddr:p,tjpAddr:i,space:t})===s)await c();else return}else if(p===null){T&&console.log(`${o} no existing tjp mapping so incoming ibgib is considered new to this space. ibGib addr: ${s} (I: 4f2bbc32b31e4fa982d95b3a785db82f)`),await c();return}else throw new Error("(UNEXPECTED) latestAddr is falsy but not null? the getLatestAddrs impl in the space should be guaranteed to provide either the incoming ibgib addr, the latest addr (if exists), or null if not found. (E: 3159dd531c0bc0efc1ece116adf28923)")}catch(s){throw console.error(`${o} ${s.message}`),s}finally{T&&console.log(`${o} complete.`),T=n}}f(Ne,"registerNewIbGib");async function St({type:r,rel8nName:t,ibGibsToRel8:e,ibGibsToUnRel8:o,addrsToUnRel8:n,linked:s,severPast:a,deletePreviousSpecialIbGib:i,space:c,zeroSpace:l,fnUpdateBootstrap:d,fnBroadcast:b}){let u=`[${St.name}](type:${r},rel8nName:${t})`;try{if(!c)throw new Error("space required. (E: 956192eea28047eba6dad81620bb96fb)");if((e??[]).length===0&&(o??[]).length===0&&(n??[]).length===0)throw new Error("either ibGibsToRel8 or ibGibsToUnRel8 required. (E: 5add49c8e46a54e2c6b057c22646a822)");if((o??[]).length>0&&(n??[]).length>0)throw new Error("can't provide both ibGibsToUnRel8 and addrsToUnRel8. There isn't a technical reason but I'm too tired right now to implement the overhead to enable this atow (05/2025). (E: 31ef66be26349cfe1b1f352389b99425)");let p=e?.map(S=>y({ibGib:S}));n??=o?.map(S=>y({ibGib:S}));let g=Q({type:r}),h=await vr({key:g,space:c});if(!h)throw new Error("specialAddr not found (E: 680dfd1caa3e4d7cb0f593b893a10f0d)");let E=await ne({addr:h,space:c});if(!E.success)throw new Error("couldn't get special (E: 897f7671d2184515866c5a675d33b3dc)");if(!E.ibGibs)throw new Error("resGetSpecial.ibGibs falsy (E: 2405dd295b2444d88503f7731796a5a0)");if(E.ibGibs.length!==1)throw new Error(`resGetSpecial.ibGibs count is not 1 (${E.ibGibs.length}) (E: b4547789016a4729af30cd972a4ca4ab)`);let $=E.ibGibs[0],I=await Ie({src:$,rel8nsToAddByAddr:p?{[t]:p}:void 0,rel8nsToRemoveByAddr:n?{[t]:n}:void 0,dna:!1,linkedRel8ns:s?[K.past,t]:[K.past],nCounter:!0}),A=I.newIbGib;if(a){if(I.intermediateIbGibs)throw new Error("new special creates intermediate ibgibs. so severing past is harder. (E: b580c0c56253494192e9c62212ee187d)");A.rel8ns.past=[],A.gib=await X({ibGib:A})}await ee({resTransform:I,space:c});let w=y({ibGib:A}),_=ue({ibGib:A});return await de({key:g,addr:w,space:c,zeroSpace:l,fnUpdateBootstrap:d}),i&&await Ko({addr:h,space:c}),await Ne({ibGib:A,fnBroadcast:b,space:c}),w}catch(p){throw console.error(`${u} ${p.message}`),p}}f(St,"rel8ToSpecialIbGib");async function Ho({ibGib:r,naive:t=!0,space:e}){let o=`[${Ho.name}]`;try{if(!e)throw new Error("space required. (E: 941f973d50e84415b58724af173f52c2)");if(!r)throw new Error("ibGib required.");let n=y({ibGib:r}),{gib:s}=C({ibGibAddr:n});if(s===L||await Qo({ibGib:r,naive:t}))return r;if(!r.rel8ns){T&&console.log(`${o} ibgib not tjp in data, and rel8ns is falsy. so tjp is undefined (I: acdadb76a7568807db7a68f6f866de22)`);return}if(r.rel8ns.tjp&&r.rel8ns.tjp.length>0){let b=r.rel8ns.tjp[0],u=await ne({addr:b,space:e});if(u.success&&u.ibGibs?.length===1)return u.ibGibs[0];{let p=u.errorMsg??"[unspecified error in get result]";throw new Error(`ibGib references tjp but could not retrieve from space. res error: ${p} (E: 94f0340706ad48c794c6a62c1b235a22)`)}}let i=r.rel8ns.past||[];if(i.length===0){console.warn(`${o} past.length === 0, so there is no tjp.`),T&&console.log(`${o} ibgib is not tjp in data, not in tjp rel8n, and past is empty. so tjp is undefined (I: bf06f664917dcf4492fb9c4c106a6222)`);return}let c=i[i.length-1],l=await ne({addr:c,space:e});if(!l.success||l.ibGibs?.length!==1)throw new Error(`get past failed. addr: ${c}`);let d=l.ibGibs[0];return await Ho({ibGib:d,naive:t,space:e})}catch(n){throw console.error(`${o} ${n.message}`),n}}f(Ho,"getTjpIbGib");async function Bs({type:r,space:t,zeroSpace:e,fnUpdateBootstrap:o,fnBroadcast:n}){let s=`[${Bs.name}]`;try{if(!t)throw new Error("space falsy and localUserSpace not initialized. (E: 66e7d3ff098248f0a5ddda51853c92e6)");switch(r){case"roots":return Hs({space:t,zeroSpace:e,fnBroadcast:n,fnUpdateBootstrap:o});case"tags":return Fs({space:t,zeroSpace:e,fnBroadcast:n,fnUpdateBootstrap:o});case"secrets":return Ks({space:t,zeroSpace:e,fnBroadcast:n,fnUpdateBootstrap:o});case"encryptions":return Vs({space:t,zeroSpace:e,fnBroadcast:n,fnUpdateBootstrap:o});case"outerspaces":return Ys({space:t,zeroSpace:e,fnBroadcast:n,fnUpdateBootstrap:o});case"autosyncs":return Ws({space:t,zeroSpace:e,fnBroadcast:n,fnUpdateBootstrap:o});case"robbots":return zs({space:t,zeroSpace:e,fnBroadcast:n,fnUpdateBootstrap:o});case"apps":return Js({space:t,zeroSpace:e,fnBroadcast:n,fnUpdateBootstrap:o});default:return Zs({type:r,space:t,zeroSpace:e,fnBroadcast:n,fnUpdateBootstrap:o})}}catch(a){throw console.error(`${s} ${a.message}`),a}}f(Bs,"createSpecial");async function Le({type:r,skipRel8ToRoot:t,space:e,zeroSpace:o,fnUpdateBootstrap:n,fnBroadcast:s}){let a=`[${Le.name}][${r||"falsy type?"}]`;try{T&&console.log(`${a} starting...`);let i=Jo({type:r}),c=M.primitive({ib:i}),l=await fr({src:c,destIb:i,linkedRel8ns:[K.past,K.ancestor],tjp:{uuid:!0,timestamp:!0},dna:!0,nCounter:!0});return await ee({resTransform:l,space:e}),r!=="roots"&&r!=="latest"&&!t&&await js({ibGib:l.newIbGib,linked:!0,space:e,zeroSpace:o,fnBroadcast:s,fnUpdateBootstrap:n}),T&&console.log(`${a} complete.`),l.newIbGib}catch(i){throw console.error(`${a} ${i.message}`),i}}f(Le,"createSpecialIbGib");async function Fs({space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o}){let n=`[${Fs.name}]`;try{if(!r)throw new Error("space required. (E: 9c05b9bd355943a39ca47afef67a50eb)");let s=Q({type:"tags"}),a=await Le({type:"tags",space:r,zeroSpace:t,fnBroadcast:o,fnUpdateBootstrap:e}),i=y({ibGib:a});await de({key:s,addr:i,space:r,zeroSpace:t,fnUpdateBootstrap:e});let c=[{text:"home",icon:"home-outline"},{text:"favorite",icon:"heart-outline"}];for(let l of c)i=(await qs({...l,space:r,zeroSpace:t,fnBroadcast:o,fnUpdateBootstrap:e})).newTagsAddr,await de({key:s,addr:i,space:r,zeroSpace:t,fnUpdateBootstrap:e});return i}catch(s){return console.error(`${n} ${s.message}`),null}}f(Fs,"createSpecial_Tags");async function qs({text:r,icon:t,description:e,space:o,zeroSpace:n,fnUpdateBootstrap:s,fnBroadcast:a}){let i=`[${qs.name}]`;try{if(T&&console.log(`${i} starting...`),!o)throw new Error("space required. (E: 5def0b1afab74b0c9286e3ac5060cb8f)");if(!r)throw new Error(`${i} text required`);t=t||bs,e=e||us;let c=ft(r),l=M.primitive({ib:"tag"}),d=await M.firstGen({parentIbGib:l,ib:c,data:{text:r,icon:t,description:e},tjp:{uuid:!0,timestamp:!0},dna:!0,nCounter:!0}),b=d.newIbGib;await ee({resTransform:d,space:o}),await Ne({ibGib:b,space:o,fnBroadcast:a});let u=await lc({tagIbGib:b,space:o,zeroSpace:n,fnUpdateBootstrap:s,fnBroadcast:a});return{newTagIbGib:b,newTagsAddr:u}}catch(c){throw console.error(`${i} ${c.message}`),c}finally{T&&console.log(`${i} complete.`)}}f(qs,"createTagIbGibAndSundry");async function Hs({space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o}){let n=`[${Hs.name}]`;try{if(!r)throw new Error("space required. (E: d12a8ea31163429fb6e53ff8e7579c57)");let s=Q({type:"roots"}),a=await Le({type:"roots",space:r,zeroSpace:t,fnBroadcast:o,fnUpdateBootstrap:e}),i=y({ibGib:a});await de({key:s,addr:i,space:r,zeroSpace:t,fnUpdateBootstrap:e});let l=["A","B","C","D","E","F","G"].map(b=>({text:`${b}root`,icon:To,description:Ao})),d;for(let b=0;b<l.length;b++){let u=l[b],p=await Xs({...u,space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o});if(d||(d=p.newRootIbGib),!p.newRootIbGib)throw new Error("(UNEXPECTED) resCreate.newRootIbGib falsy? (E: c9fb2c94a9c1d762c1699b41a4d5ad23)");i=p.newRootsAddr,await de({key:s,addr:i,space:r,zeroSpace:t,fnUpdateBootstrap:e})}if(!d)throw new Error("(UNEXPECTED) firstRoot still falsy? (E: b2e2c926d242966e7ed7159e4b129e23)");if(await Vo({root:d,space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o}),i=await vr({key:s,space:r}),!i)throw new Error("(UNEXPECTED) no roots address in config? (E: 76345340699a4738a195e48803ef0d31)");return i}catch(s){return console.error(`${n} ${s.message}`),null}}f(Hs,"createSpecial_Roots");async function Xs({text:r,icon:t,description:e,space:o,zeroSpace:n,fnUpdateBootstrap:s,fnBroadcast:a}){let i=`[${Xs.name}]`;try{if(!o)throw new Error("space required. (E: cfa876e5c8c64a53a463ca7a645571c8)");r=r||fs,t=t||To,e=e||Ao;let c=Zo(r),l=M.primitive({ib:"root"}),d=await M.firstGen({parentIbGib:l,ib:c,data:{text:r,icon:t,description:e},linkedRel8ns:[K.past,K.ancestor],tjp:{uuid:!0,timestamp:!0},dna:!0,nCounter:!0}),{newIbGib:b}=d;await ee({resTransform:d,space:o});let u=await St({type:"roots",rel8nName:Io,ibGibsToRel8:[b],space:o,zeroSpace:n,fnUpdateBootstrap:s,fnBroadcast:a});return{newRootIbGib:b,newRootsAddr:u}}catch(c){throw console.error(`${i} ${c.message}`),c}}f(Xs,"createRootIbGib");async function Ks({space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o}){let n=`[${Ks.name}]`;try{if(!r)throw new Error("space required. (E: 340960cd5ad24addb300b23d9722e30a)");let s,a=Q({type:"secrets"}),i=await Le({type:"secrets",space:r,zeroSpace:t,fnBroadcast:o,fnUpdateBootstrap:e});return s=y({ibGib:i}),await de({key:a,addr:s,space:r,zeroSpace:t,fnUpdateBootstrap:e}),s}catch(s){return console.error(`${n} ${s.message}`),null}}f(Ks,"createSpecial_Secrets");async function Vs({space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o}){let n=`[${Vs.name}]`;try{if(!r)throw new Error("space required. (E: 5084e698b6924e7090697ca50075ca59)");let s,a=Q({type:"encryptions"}),i=await Le({type:"encryptions",space:r,zeroSpace:t,fnBroadcast:o,fnUpdateBootstrap:e});return s=y({ibGib:i}),await de({key:a,addr:s,space:r,zeroSpace:t,fnUpdateBootstrap:e}),s}catch(s){return console.error(`${n} ${s.message}`),null}}f(Vs,"createSpecial_Encryptions");async function Ys({space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o}){let n=`[${Ys.name}]`;try{if(!r)throw new Error("space required. (E: 99dd9e92535c470482eb9f6625a33831)");let s,a=Q({type:"outerspaces"}),i=await Le({type:"outerspaces",space:r,zeroSpace:t,fnBroadcast:o,fnUpdateBootstrap:e});return s=y({ibGib:i}),await de({key:a,addr:s,space:r,zeroSpace:t,fnUpdateBootstrap:e}),s}catch(s){return console.error(`${n} ${s.message}`),null}}f(Ys,"createSpecial_OuterSpaces");async function Ws({space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o}){let n=`[${Ws.name}]`;try{if(!r)throw new Error("space required. (E: f01cf6a4a460486796e16d505d629522)");let s,a=Q({type:"autosyncs"}),i=await Le({type:"autosyncs",space:r,zeroSpace:t,fnBroadcast:o,fnUpdateBootstrap:e});return s=y({ibGib:i}),await de({key:a,addr:s,space:r,zeroSpace:t,fnUpdateBootstrap:e}),s}catch(s){return console.error(`${n} ${s.message}`),null}}f(Ws,"createSpecial_Autosyncs");async function zs({space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o}){let n=`[${zs.name}]`;try{if(!r)throw new Error("space required. (E: f01cf6a4a460486796e16d505d629522)");let s,a=Q({type:"robbots"}),i=await Le({type:"robbots",space:r,zeroSpace:t,fnBroadcast:o,fnUpdateBootstrap:e});return s=y({ibGib:i}),await de({key:a,addr:s,space:r,zeroSpace:t,fnUpdateBootstrap:e}),s}catch(s){return console.error(`${n} ${s.message}`),null}}f(zs,"createSpecial_Robbots");async function Js({space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o}){let n=`[${Js.name}]`;try{if(!r)throw new Error("space required. (E: f01cf6a4a460486796e16d505d629522)");let s,a=Q({type:"apps"}),i=await Le({type:"apps",space:r,zeroSpace:t,fnBroadcast:o,fnUpdateBootstrap:e});return s=y({ibGib:i}),await de({key:a,addr:s,space:r,zeroSpace:t,fnUpdateBootstrap:e}),s=await Or({defaultAppData:xs,defaultAppRel8ns:Os,space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o}),s=await Or({defaultAppData:Ds,defaultAppRel8ns:vs,space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o}),s=await Or({defaultAppData:Ns,defaultAppRel8ns:Ls,space:r,zeroSpace:t,fnUpdateBootstrap:e,fnBroadcast:o}),s}catch(s){return console.error(`${n} ${s.message}`),null}}f(Js,"createSpecial_Apps");async function Or({defaultAppData:r,defaultAppRel8ns:t,space:e,zeroSpace:o,fnUpdateBootstrap:n,fnBroadcast:s}){let a=`[${Or.name}]`;try{T&&console.log(`${a} starting... (I: 677f68789abdc7316887e8f38c764e22)`),T&&console.log(`${a} starting...`);let i=v(r),c=t?v(t):void 0;i.uuid=!i.uuid||i.uuid===Mo?await F():i.uuid;let{classname:l}=i,d=Uo({appData:i,classname:l}),b=await M.firstGen({ib:d,parentIbGib:M.primitive({ib:`app ${l}`}),data:i,rel8ns:c,dna:!0,linkedRel8ns:[K.ancestor,K.past],nCounter:!0,tjp:{timestamp:!0}});return await ee({resTransform:b,space:e}),await Ne({ibGib:b.newIbGib,fnBroadcast:s,space:e}),await St({type:"apps",rel8nName:mr,ibGibsToRel8:[b.newIbGib],fnBroadcast:s,fnUpdateBootstrap:n,space:e,zeroSpace:o})}catch(i){throw console.error(`${a} ${i.message}`),i}finally{T&&console.log(`${a} complete.`)}}f(Or,"createApp");async function Zs({type:r,space:t,zeroSpace:e,fnUpdateBootstrap:o,fnBroadcast:n}){let s=`[${Zs.name}]`;try{if(!t)throw new Error("space required. (E: c7bbafcbe901418db4c6048f17f53091)");T&&console.log(`${s} creating special of type: ${r} (I: 283c8bb30ed6f9698b74b886c6078622)`);let a,i=Q({type:r}),c=await Le({type:r,space:t,zeroSpace:e,fnBroadcast:n,fnUpdateBootstrap:o});return a=y({ibGib:c}),await de({key:i,addr:a,space:t,zeroSpace:e,fnUpdateBootstrap:o}),a}catch(a){return console.error(`${s} ${a.message}`),null}}f(Zs,"createSpecial_Default");async function Qs({ibGib:r,ibGibAddr:t,existingLatest:e,existingLatestAddr:o,tjpAddr:n,space:s}){let a=`[${Qs.name}][${t}]`;try{if(T&&console.log(`${a} starting...`),!s)throw new Error("space required. (E: 64eb9a271f5d43deadec30b9638746c8)");let i=r.rel8ns?.past||[],c=e.rel8ns?.past||[];if(i.length===1&&c.length===0)return T&&console.log(`prospective has a past, so it "must" be newer. (won't quote "must" anymore)`),t;if(c.length===1&&i.length===0)return T&&console.log("existing has a past, so it must be newer."),o;if(c.length===0&&i.length===0)return console.warn(`${a} neither existing latest nor prospective new ibGib has a past, so keeping existing.`),o;if(c.includes(t))return T&&console.log("existing by definition is newer"),o;if(i.includes(o))return T&&console.log("ibGib by definition is newer"),t;if(o===t)return T&&console.log("they're the same!"),o;if(o===n&&e.rel8ns?.tjp?.length===1)return T&&console.log("ibGib must be newer because the existingLatestAddr is the tjp, which is by definition first in unique past."),t;if(t===n&&r.rel8ns?.tjp?.length===1)return T&&console.log("existing must be newer because the ibGibAddr is the tjp, which is by definition first in unique past."),o;T&&console.log(`${a} brute forcing through iterating the pasts.`);let l,d=-1,b=f(async(g,h,E)=>{let $=g.rel8ns?.past||[];if($.includes(E))return l=y({ibGib:g}),-1;if($.length===0)return h;let I=h+$.length;if(d!==-1&&I>d)return l=y({ibGib:g}),-1;let A=await ne({addr:$[0],space:s});if(!A.success||A.ibGibs?.length!==1)throw new Error(`Couldn't load past addr (xPast[0]): ${$[0]}`);return b(A.ibGibs[0],h+$.length,E)},"getPastCount");T&&console.log(`${a} doing ibGibPastCount`);let u=await b(r,0,o);if(l)return l;T&&console.log(`${a} Doing existingPastCount`),d=u;let p=await b(e,0,t);return l||(u>p?(T&&console.log(`${a} ibGibPastCount (${u}) is longer than existingPastCount (${p}), so ibGib is newer.`),l=t):(T&&console.log(`${a} existingPastCount (${p}) is longer than ibGibPastCount (${u}), so ibGib is newer.`),l=o),l)}catch(i){throw console.error(`${a} ${i.message}`),i}finally{T&&console.log(`${a} complete.`)}}f(Qs,"getLatestAddr_Brute");function lc({tagIbGib:r,space:t,zeroSpace:e,fnUpdateBootstrap:o,fnBroadcast:n}){return St({type:"tags",rel8nName:Go,ibGibsToRel8:[r],space:t,zeroSpace:e,fnUpdateBootstrap:o,fnBroadcast:n})}f(lc,"rel8TagToTagsIbGib");function Yo({space:r,scope:t}){let e=`[${Yo.name}]`;try{if(T&&console.log(`${e} starting...`),!r)throw new Error("space required. (E: 3ba16e6c3e5e47948b0e63448da11752)");if(!r.data?.uuid)throw new Error("invalid space (space.data.uuid falsy) (E: 273262b32f2ef27b2e690bc699f33822)");if(!t)throw new Error("scope required. (E: f47801d6c45e2247b42a53d9b604b522)");for(;t.includes(J);)T&&console.log(`${e} scope contains ibgib delimiter...replacing... (I: 0f456fd7cc6552a799673a0c5b4a7d22)`),t=t.replace(J,"_");let o=r.data.uuid,n=`${cs} ${o} ${t}`;return y({ib:n,gib:L})}catch(o){throw console.error(`${e} ${o.message}`),o}finally{T&&console.log(`${e} complete.`)}}f(Yo,"getSpaceLockAddr");async function Ae({space:r,scope:t,secondsValid:e,maxDelayMs:o,fn:n,callerInstanceId:s,maxLockAttempts:a}){let i=`[${Ae.name}]`;try{if(T&&console.log(`${i} starting...`),!r)throw new Error("space required. (E: 66fd8f21a5b2b572d18cdeb9472a7722)");if(!e)throw new Error("secondsValid required. (E: 92c5610e57ceede5ce83cff86d5c2a22)");if(e<0)throw new Error("secondsValid must be positive. (E: 970a7510c517235d7a355a843d18d222)");if(!n)throw new Error("fn required (E: 7022e280252ec2faf756b6db05c56e22)");let c;T&&console.log(`${i} attempting to acquire lock with scope ${t} (I: fed36d42a975b1c52897a4df804ac722)`);let l;o=(o??0)>0?o:ls;let d=0;a=a??!1?a:ds;do{if(l=await ea({space:r,scope:t,secondsValid:e,instanceId:s}),l?.data?.success)break;let u=Math.ceil(Math.random()*o);await le(u),d++}while(d<a);if(l?.data?.success)T&&console.log(`${i} lock acquired. (I: d847fa953ee131a57e1a89c537342722)`);else throw new Error(`could not acquire lock after ${d} attempts with intermittent delays of ${o} ms (E: 898c559dbd0c9bf20c14cf87a8f1e222)`);let b=`${i}[fn]`;try{T&&console.log(`${b} starting... (I: c2f7bedf95d3f1dd1f76de34a68d3f22)`),c=await n()}catch(u){throw console.error(`${b} ${u.message}`),u}finally{T&&console.log(`${b} unlocking space with scope: ${t} (I: 21034d9c3395499756e9000e40417d22)`),await ta({space:r,scope:t,instanceId:s}),T&&console.log(`${b} complete. (I: 79d8ac03714a4d429c7e6c2ac6e18d22)`)}return c}catch(c){throw console.error(`${i} ${c.message}`),c}finally{T&&console.log(`${i} complete.`)}}f(Ae,"execInSpaceWithLocking");async function Yt({zeroSpace:r}){let t=`[${Yt.name}]`;try{if(T&&console.log(`${t} starting...`),!r)throw new Error("zeroSpace required. (E: 66fd8f21a5b2b572d18cdeb9472a7722)");let e=ze;T&&console.log(`${t} getting from zeroSpace...`);let o=await r.argy({ibMetadata:Ge({space:r}),argData:{cmd:"get",ibGibAddrs:[e]}}),n=await r.witness(o);if(n?.data?.success&&n.ibGibs?.length===1){let s=n.ibGibs[0];return T&&console.log(`${t} bootstrapibGib found: ${H(s)}`),await ko(s)?s:(T&&console.log(`${t} bootstrapIbGib was invalid. (I: cce66b26805404fc85525d565e1f8b22)`),null)}else return T&&console.log(`${t} bootstrapIbGib NOT found. (I: 421562993bf3464eb507d2967d311e22)`),null}catch(e){throw console.error(`${t} ${e.message}`),e}finally{T&&console.log(`${t} complete.`)}}f(Yt,"getValidatedBootstrapIbGib");async function dc({zeroSpace:r,bootstrapIbGib:t,localSpaceId:e,lock:o,callerInstanceId:n,fnDtoToSpace:s,localSpaceCacheSvc:a}){let i=`[${dc.name}]`;try{if(!r)throw new Error("zeroSpace required. (E: 0793781a98c456a666cfa9eb960bcd22)");if(!t)if(T&&console.log(`${i} bootstrap falsy, so loading it... (I: f2366e38283495a38b5501297aa34422)`),o){let d=ze;T&&console.log(`${i} using locked version of loading bootstrap... (I: 52b9b11999674e586d051c2b23f59b22)`),t=await Ae({space:r,scope:d,fn:f(async()=>{let b=await Yt({zeroSpace:r});if(b)return b;throw new Error("(UNEXPECTED) unable to get bootstrap ibgib? (E: c111dc7627acbfb992134ddf4064ea23)")},"fn"),callerInstanceId:n,secondsValid:gr})}else T&&console.log(`${i} lock is false, so just getting the bootstrap ibgib (I: 49d55e5a824510bb3ee0ccd9f5ec3322)`),t=await Yt({zeroSpace:r})??void 0;if(!t)throw new Error("bootstrapIbGib falsy. not initialized? (E: 91f5c82b5e124178d958701ebcb09822)");if(!t.data)throw new Error("(UNEXPECTED) bootstrapIbGib.data required. invalid bootstrap? (E: 568c6b837c1a39f7a25d188a90167423)");e=e??t.data[_e];let c=t.rel8ns[e][0],l=f(async()=>{let d=await r.argy({ibMetadata:Ge({space:r}),argData:{cmd:"get",ibGibAddrs:[c]}}),b=await r.witness(d);if(b?.data?.success&&b.ibGibs?.length===1){let u=b.ibGibs[0],p=await s(u);return a&&(p.cacheSvc=a),p}else throw new Error(`Could not get local space addr (${c}) specified in bootstrap space (${y({ibGib:t})}). (E: 6d6b45e7eae4472697ddc971438e4922)`)},"fnGet");return o?(T&&console.log(`${i} getting localSpaceId (${e}) WITH locking (I: c48a0e4ac5971cdbc57273dd35f8a522)`),await Ae({space:r,scope:e,fn:f(()=>l(),"fn"),callerInstanceId:n,secondsValid:gr})):(T&&console.log(`${i} getting localSpaceId (${e}) WITHOUT locking (I: 48e504835dee4006839df8820d860b22)`),l())}catch(c){throw console.error(`${i} ${c.message}`),c}}f(dc,"getLocalSpace");async function ea({space:r,scope:t,secondsValid:e,instanceId:o}){let n=`[${ea.name}]`;try{if(T&&console.log(`${n} starting...`),!r)throw new Error("space required. (E: 5c0a7197a75f483a82d74e5eea60df37)");if(!t)throw new Error("scope required. (E: c7f1dde9570f4df3b450faa2c2f85122)");if(!e)throw new Error("secondsValid required and positive (E: b42b6733638b46c06c9aff59a6c49822)");if(e<0)throw new Error("secondsValid must be positive (E: bbe3b6d567583bfb35a1c0825eb29622)");let s,a=Yo({space:r,scope:t}),i,c=await ne({addr:a,space:r,force:!0});if(c.success&&c.ibGibs?.length===1?(i=c.ibGibs[0],i?.data?.expirationUTC?go({expirationTimestampUTC:i.data.expirationUTC})&&(console.warn(`${n} ignoring expired existing lock in space at ${a}. Should be overwritten (W: 7421c5b051724b189f88cecbbd449b22)`),i=void 0):(console.error(`${n} (UNEXPECTED) exisingLock.data.expirationUTC falsy? (E: 218dc0e935534a149d0be153c532cf25)`),i=void 0)):T&&console.log(`${n} existing lock not found for ${a} (I: 191af56ec4e2db3d19084e46bf949222)`),i){if(!i.data)throw new Error("(UNEXPECTED) existingLock.data falsy? (E: 00069b4662e5566d971760d15e293723)");s=v(i),s.data.alreadyLocked=!0,s.data.success=!1}else{let{ib:l,gib:d}=C({ibGibAddr:a});s={ib:l,gib:d,data:{scope:t,secondsValid:e,instanceId:o,expirationUTC:ho({seconds:e})}};let b=await r.argy({ibMetadata:Ge({space:r}),argData:{cmd:"put",force:!0,ibGibAddrs:[a]},ibGibs:[s]}),u=await r.witness(b);if(u.data?.success)if((u.data.addrsAlreadyHave??[]).includes(a)){T&&console.log(`${n} racelost! addrsAlreadyHave includes spaceLockAddr (${a}) (I: 2e8a1562947c40698110b64251141753)`);let p=await ne({addr:a,space:r,force:!0});if(p.success&&p.ibGibs?.length===1){let g=p.ibGibs[0];s=v(g),s.data.alreadyLocked=!0,s.data.success=!1}else{let g=`${n} (UNEXPECTED) addrsAlreadyHave true, but couldn't get lock? (E: 8374a2b6628b49369363bc5843105763)`;console.error(g),s.data.success=!1,s.data.errorMsg=g}}else s.data.success=!0;else{let p=`${n} there was an error putting the lock in the space: ${u.data?.errors?.join("|")}`;s.data.success=!1,s.data.errorMsg=p,console.error(p)}}return s}catch(s){throw console.error(`${n} ${s.message}`),s}finally{T&&console.log(`${n} complete.`)}}f(ea,"lockSpace");async function ta({space:r,scope:t,instanceId:e}){let o=`[${ta.name}]`;try{if(T&&console.log(`${o} starting...`),!r)throw new Error("space required. (E: 5c0a7197a75f483a82d74e5eea60df37)");if(!t)throw new Error("scope required. (E: c7f1dde9570f4df3b450faa2c2f85122)");let n=Yo({space:r,scope:t}),s=await Ko({addr:n,space:r,force:!0});if(s.success){let{ib:a,gib:i}=C({ibGibAddr:n});return{ib:a,gib:i,data:{success:!0,instanceId:e,scope:t}}}else{let a=`Delete lock in space failed. delete errorMsg: ${s.errorMsg}`;if(a.includes("not implemented"))throw new Error(a);if(a.toLowerCase().includes("does not exist")||a.toLowerCase().includes("doesn't exist")||a.toLowerCase().includes("not found")){T&&console.log(`${o} ${a} (I: b647916fd0f3e5366e9387131be21c22)`);let{ib:i,gib:c}=C({ibGibAddr:n});return{ib:i,gib:c,data:{action:"unlock",success:!0,instanceId:e,scope:t}}}else console.warn(`${o} ${a} (W: 14c84fcac15944bd9a417099964d5d9d)`)}}catch(n){throw console.error(`${o} ${n.message}`),n}finally{T&&console.log(`${o} complete.`)}}f(ta,"unlockSpace");async function fc({space:r,zeroSpace:t,setSpaceAsDefault:e,createIfNotFound:o}){let n=`[${fc.name}]`;try{if(T&&console.log(`${n} starting...`),!r)throw new Error("space required. (E: 6fc19548fa7d1d5219e19871f280a322)");if(!r.data?.uuid)throw new Error("space.data.uuid required (E: 6483188ca6f2ed2085fd355595f3ab22)");if(!t)throw new Error("zeroSpace required. (E: abbf156e18b1018d96273e22a260f122)");let s=r.data.uuid,a=y({ibGib:r}),i=await Yt({zeroSpace:t});if(i){if(T&&console.log(`${n} updating existing bootstrap (I: 977d4aa7ed47bef73b35743c05ce0722)`),i.data.spaceIds.includes(s)){T&&console.log(`${n} space already rel8d to bootstrap, possibly updating its addr (I: b5e2c515ef732d4bbcf02625a9e7c722)`);let c=i.rel8ns[s][0];c===a?T&&console.log(`${n} bootstrap already rel8d to space (I: c1be027b23e7350c64790a631cae2822)`):(T&&console.log(`${n} updating rel8ns[${s}] with newSpaceAddr (${a}). (Old address: ${c})(I: 297a9b0061fd471b8d28a06e04a6ad22)`),i.rel8ns[s]=[a])}else T&&console.log(`${n} new space being rel8d. adding spaceId to data.spaceIds and amending rel8ns (I: 40903d71719aa1d56e498299f5699a22)`),i.data.spaceIds.push(s),i.rel8ns[s]=[a];e&&(T&&console.log(`${n} setting spaceId (${s}) as default space (I: f85eda6c6ad2b0bec9750ce3c7795b22)`),i.data[_e]=s)}else{if(!o){T&&console.log(`${n} bootstrapIbGib not found but createIfNotFound falsy, so returning early. (I: 5c67d85a8599a5ba4a6780f26a66ea22)`);return}T&&console.log(`${n} creating new bootstrap ibgib for spaceId (${s}) with address of (${a}) (I: 651959c27bf2ebc5be1f7f44e2b9e422)`);let{ib:c,gib:l}=C({ibGibAddr:ze});i=M.primitive({ib:c}),i.gib=l,i.data={[_e]:s,[wr]:[s]},i.rel8ns={[s]:[a]}}if(!i)throw new Error("(UNEXPECTED) bootstrapIbGib still falsy? (E: cf21d7f1756710a66aa0e6a28d762723)");T&&console.log(`${n} saving bootstrapIbGib: ${H(i)} (I: 3cceca0b98dde90e4a58a734be252322)`),await Wo({zeroSpace:t,bootstrapIbGib:i}),T&&console.log(`${n} complete.`)}catch(s){throw console.error(`${n} ${s.message}`),s}}f(fc,"updateBootstrapIbGib");async function Wo({zeroSpace:r,bootstrapIbGib:t}){let e=`[${Wo.name}]`;if(!r)throw new Error("zeroSpace required. (E: 818fa8430b8040dca1917f9db0972b22)");if(!t)throw new Error("bootstrapIbGib required. (E: cf21d7f1756710a66aa0e6a28d762723)");let o=await r.argy({ibMetadata:t.ib,argData:{cmd:"put",force:!0,ibGibAddrs:[y({ibGib:t})]},ibGibs:[t]});T&&console.log(`${e} zeroSpace will witness/put... (I: 1be9aca22ffc4951b6690965a7aeae5b)`);let n=await r.witness(o);if(n?.data?.success)T&&console.log(`${e} zero space put complete. (I: ac3056d655e841f1a3c442bcc64942f9)`);else throw new Error(`${n?.data?.errors?.join("|")||"There was a problem with zeroSpace witnessing the bootstrap^gib primitive."}`)}f(Wo,"persistBootstrapIbGibInZeroSpace");async function bc({spaceId:r,zeroSpace:t}){let e=`[${bc.name}]`;if(!r)throw new Error("spaceId required. (E: 52f9c31405e24c2999e5a1b32d201a23)");if(!t)throw new Error("zeroSpace required. (E: a115f4007b2c4819a58cf093d5823b23)");await Ae({space:t,scope:ze,fn:f(async()=>{let n=await Yt({zeroSpace:t});if(!n)throw new Error("bootstrapIbGib falsy in zeroSpace (E: e36a512781b0467ba1bf1d927a7c1d23)");if(!n.data)throw new Error("bootstrapIbGib.data falsy in zeroSpace (E: 8f92104192b44d71891b092481029ab0)");let s=n.data,a=s[wr]??[];if(a.length<=1)throw new Error(`Cannot delete space (${r}). It is the only remaining local space. (E: 9c27f71120014b08b5e9f89993380e23)`);if(r===s[_e])throw new Error(`Cannot delete space (${r}). It is the default local space. Please select a new default space before deleting. (E: f3c30a5170d14b4fb2478d102e3b2e23)`);if(!a.includes(r))throw new Error(`Space (${r}) not found in bootstrap spaceIds. (E: 61fa940e79124430a618e470bc551d23)`);s[wr]=a.filter(i=>i!==r),n.rel8ns&&delete n.rel8ns[r],await Wo({zeroSpace:t,bootstrapIbGib:n})},"fn"),secondsValid:gr})}f(bc,"deregisterLocalSpaceFromBootstrap");async function uc({spaceId:r,zeroSpace:t}){let e=`[${uc.name}]`;if(!r)throw new Error("spaceId required. (E: 7c2a10529a1b412a8069e22e5190b623)");if(!t)throw new Error("zeroSpace required. (E: f112a512019c41a590b512a8e0915623)");let o=await t.argy({ibMetadata:Ge({space:t}),argData:{cmd:"get",ibGibAddrs:[r]}}),n=await t.witness(o);if(n?.data?.success&&(n.ibGibs?.length??0)>0){let s=y({ibGib:n.ibGibs[0]}),a=await t.argy({ibMetadata:Ge({space:t}),argData:{cmd:"delete",ibGibAddrs:[s]}});await t.witness(a)}}f(uc,"deleteSpaceRecordFromZeroSpace");function Ge({space:r}){return`${r.ib} ${ge()}`}f(Ge,"getSpaceArgMetadata");function Hu({space:r}){return`${r.ib} ${ge()}`}f(Hu,"getSpaceResultMetadata");function pc({space:r,spaceData:t,classname:e}){let o=`[${pc.name}]`;try{if(!r&&!t)throw new Error("either space or spaceData required (E: 4dabec34ee77d67c9cc30ee3c3049622)");if(r&&!r.data)throw new Error("(UNEXPECTED) given space has falsy space.data? (E: 058d298876ebbeada7bbddb9e3da2f23)");if(r&&t){if(r.data.uuid!==t.uuid)throw new Error("(UNEXPECTED) both space and spaceData given, but uuid don't match? (E: efdd4603cba93a17340a76811fe56b24)");if(r.data.n!==t.n)throw new Error("(UNEXPECTED) both space and spaceData given, but n don't match? (E: e51278a707c9bccc57a08a4b86524524)")}if(t??=r.data,!t)throw new Error("(UNEXPECTED) spaceData falsy? (thought this was a compiler problem that this was even possible.) (E: b3c7ffedcae4b1f45b263b3825930b24)");if(e&&t.classname&&e!==t.classname)throw new Error(`both classname arg (${e}) and spaceData.classname (${t.classname}) are different truthy values. (E: f98f012ee876eb8fbe7403f7b53e4624)`);if(e||=t.classname,!e)throw new Error("classname required (E: fa3af4613ad56742dab51d1b0d839322)");if(e.includes(" "))throw new Error(`invalid classname (${e}). cannot contain spaces (E: 243adbf720dcce7904e2665933208b22)`);let n=t?.name||is;if(n.includes(" "))throw new Error("invalid space name. cannot contain spaces (E: a8450e1651081412c8ac018520182422)");let s=t?.uuid||void 0;if(!s)throw new Error("invalid space, spaceData.uuid falsy (E: 50ae723a9ab24f4fc7132613e65faf23)");if(s.includes(" "))throw new Error("invalid space id. cannot contain spaces (E: 8696830fe7f54bfa85e670a063f3e089)");let a=t.type??void 0,i=t.subtype??void 0;if(a&&!i)throw new Error(`spaceType (${a}) is set but spaceSubtype is falsy. (E: 878ab960d7987ae2331103b4a00d0d24)`);return`${Sr} ${hr} ${e} ${n} ${s} ${a} ${i}`}catch(n){throw console.error(`${o} ${n.message}`),n}}f(pc,"getSpaceIb");function hc({ib:r}){let t=`[${hc.name}]`;if(!r){let e=`${t} ib required (E: dd5244f62f964359a86e59bb08ee47e6)`;throw console.error(e),new Error(e)}return r.startsWith(`${Sr} ${hr} `)}f(hc,"isSpaceIb");function Nr({spaceIb:r}){let t=`[${Nr.name}]`;try{if(!r)throw new Error("spaceIb required (E: fa5424cfb7e846e2851562f2f417944f)");let[e,o,n,s,a,i,c]=r.split(" ");if(e!==Sr)throw new Error(`invalid spaceIb (${r}). witnessAtom !== WITNESS_ATOM (E: 5ae1ca12cf8f30ae341f3e582b025224)`);if(o!==hr)throw new Error(`invalid spaceIb (${r}). spaceAtom !== SPACE_ATOM (E: 9cc6b6f30e13455eb29748148a94fa0f)`);if(!n)throw new Error(`invalid spaceIb (${r}). spaceClassname falsy (E: 00d3392da007ca8b2840b16b199d9a24)`);if(!s)throw new Error(`invalid spaceIb (${r}). spaceName falsy (E: b957d8e74ef34d889fa64c60c7a5ea0b)`);if(!a)throw new Error(`invalid spaceIb (${r}). spaceId falsy (E: 7a1773722d8e46a0866d683130b65b89)`);let l;if(i&&i!=="undefined")if(Po.includes(i))l=i;else throw new Error(`invalid spaceIb (${r}). spaceType (${i}) is set but not a valid type. valid types: ${Po.join(", ")} (E: 838f4638a88cfbf3545a3a3a38b6dd24)`);let d;if(c&&c!=="undefined")if(Ro.includes(c))d=c;else throw new Error(`invalid spaceIb (${r}). spaceSubtype (${c}) is set but not a valid subtype. valid subtypes: ${Ro.join(", ")} (E: 5bdcf23027f94e73860e4340313b04ab)`);return{spaceClassname:n,spaceName:s,spaceId:a,spaceType:l,spaceSubtype:d}}catch(e){throw console.error(`${t} ${e.message}`),e}}f(Nr,"parseSpaceIb");async function Ce({ibGibs:r,addrs:t,tjps:e,tjpAddrs:o,space:n}){let s=`[${Ce.name}]`;try{if(T&&console.log(`${s} starting...`),!n)throw new Error("space required. (E: 4d188d6c863246f28aa575753a052304)");if(r=r??[],t=t??[],e=e??[],o=o??[],t.length===0&&r.length===0&&e.length===0&&o.length===0)throw new Error("Either addrs, ibGibs, tjps, or tjpAddrs required. (E: 7c6ebfbab98d4d21a431b144457fd991)");let a=new Set(o.concat(e.map(l=>y({ibGib:l})))),i=Array.from(a).map(l=>C({ibGibAddr:l}).gib);r.map(l=>y({ibGib:l})).concat(t).forEach(l=>{let{gib:d}=C({ibGibAddr:l});i.some(u=>d.includes(u))||a.add(l)}),T&&console.log(`${s}[testing] ${n.data?.name||n.ib} (${n.data?.uuid||"[space.data.uuid falsy]"}) addrsToQuery: ${Array.from(a)} (I: 8a2202912c364238b6d6eb09577bc246)`);let c=await n.argy({ibMetadata:Ge({space:n}),argData:{cmd:"get",cmdModifiers:["latest","addrs"],ibGibAddrs:Array.from(a)}});return await n.witness(c)}catch(a){throw console.error(`${s} ${a.message}`),a}}f(Ce,"getLatestAddrs");function zo({ibGib_Context:r}){let t=`[${zo.name}]`;try{if(T&&console.log(`${t} starting... (I: 5f583fd94d27731a65d514e731b8aa22)`),!Wt({ibGib:r}))return;if(["roots","autosyncs"].some(o=>r.ib.includes(o)))throw new Error("cannot perform a modification of this type on this special ibgib (E: b8fb718a7323fc54454464b973412722)")}catch(e){throw console.error(`${t} ${e.message}`),e}finally{T&&console.log(`${t} complete.`)}}f(zo,"throwIfContextIsSpecial");async function gc({ibGib_Context:r,rel8nName_Context:t,addr:e,space:o,zeroSpace:n,fnUpdateBootstrap:s,fnBroadcast:a}){let i=`[${gc.name}]`;try{if(T&&console.log(`${i} starting... (I: 2dc486bb2d516e4534f437aaf5ec7f22)`),!r)throw new Error("ibGib_Context required (E: 75f7bfa93145d6dffe85d488443ca722)");if(!t)throw new Error("rel8nName_Context required (E: 12aaa43de9e34b68b25dc9a2a68ad6b9)");if(!e)throw new Error("addr required (E: e27df3bdc5a2554697cc9597afc4e422)");if(!o)throw new Error("space required (E: 2e3562486ed2956a770ed9e8d77a3f22)");let c=Wt({ibGib:r});c&&zo({ibGib_Context:r});let l=await Ie({src:r,rel8nsToAddByAddr:{[hs]:[e]},rel8nsToRemoveByAddr:{[t]:[e]},dna:!0,nCounter:!0});if(await ee({resTransform:l,space:o}),c){let d=y({ibGib:l.newIbGib}),b=Lr({ib:r.ib}),u=Q({type:b});await de({key:u,addr:d,space:o,zeroSpace:n,fnUpdateBootstrap:s})}await Ne({ibGib:l.newIbGib,fnBroadcast:a,space:o})}catch(c){throw console.error(`${i} ${c.message}`),c}finally{T&&console.log(`${i} complete.`)}}f(gc,"trash");async function Ec({ibGib_Context:r,rel8nName_Context:t,addr:e,space:o,zeroSpace:n,fnUpdateBootstrap:s,fnBroadcast:a}){let i=`[${Ec.name}]`;try{if(T&&console.log(`${i} starting... (I: 38098552b830495187299bb24fcddff0)`),!r)throw new Error("ibGib_Context required (E: d819e8c4db5b4c0bb721300ba434cd40)");if(!t)throw new Error("rel8nName_Context required (E: de061adff8c04429a211aa09116a532d)");if(!e)throw new Error("addr required (E: 7059ebb8ef6149ea94e22f961d6b5c81)");if(!o)throw new Error("space required (E: e19566f2d42347798621447edcae312e)");let c=Wt({ibGib:r});c&&zo({ibGib_Context:r});let l=await Ie({src:r,rel8nsToAddByAddr:{[ps]:[e]},rel8nsToRemoveByAddr:{[t]:[e]},dna:!0,nCounter:!0});if(await ee({resTransform:l,space:o}),c){let d=y({ibGib:l.newIbGib}),b=Lr({ib:r.ib}),u=Q({type:b});await de({key:u,addr:d,space:o,zeroSpace:n,fnUpdateBootstrap:s})}await Ne({ibGib:l.newIbGib,fnBroadcast:a,space:o})}catch(c){throw console.error(`${i} ${c.message}`),c}finally{T&&console.log(`${i} complete.`)}}f(Ec,"archive");function mc(r){let t=`[${mc.name}]`;try{if(!r)return console.error(`${t} name is falsy`),!1;let e=/[\w-]+/,o=r.match(e);if(o?.length!==1||o[0].length!==r.length)return console.error(`${t} name can only contain letters, numbers, underscores, hyphens`),!1;let n=/[a-zA-Z\d]/;return r[0].match(n)?!0:(console.error(`${t} name must start with a letter or number`),!1)}catch(e){return console.error(`${t} ${e.message}`),!1}}f(mc,"spaceNameIsValid");var se=!1;async function wc({ibGib:r,rel8nNames:t,space:e}){let o=`[${wc.name}]`;try{if(!r)throw new Error("ibGib required (E: a3c1b2d4e5f6a7b8c9d0e1f2a3b4c5d6)");if(!e)throw new Error("space required (E: b4d2c3e4f5a6b7c8d9e0f1a2b3c4d5e6)");t||(t=Object.keys(r.rel8ns||{}));let n={};for(let s of t){let a=r.rel8ns?.[s]||[];if(a.length>0){let i=await ne({addrs:a,space:e});if(i.success&&i.ibGibs?.length===a.length)n[s]=i.ibGibs.concat();else throw new Error(`Problem getting rel8d ibgibs for rel8nName: ${s}. ${i.errorMsg||"Unknown error"} (E: c5e3d4f5a6b7c8d9e0f1a2b3c4d5e6)`)}else n[s]=[]}return n}catch(n){throw console.error(`${o} ${m(n)}`),n}}f(wc,"getRel8dIbGibs");async function Te({parentPrimitiveIb:r,ib:t,ibRegExpPattern:e,data:o,rel8ns:n}){let s=`[${Te.name}]`;try{if(!r)throw new Error("parentPrimitiveIb required. (E: 88ddf188cc5a4340b597abefba1481e2)");if(Gt({ib:r})!==null)throw new Error(`Invalid parentPrimitiveIb: ${r}. (E:5aec0320956d492ebeeaca41eb1fe1c6)`);if(!t)throw new Error("ib required. (E: 7bbc88f4f2e842d6b00126e55b1783e4)");let a=e?new RegExp(e):ss;if(!t.match(a))throw new Error(`invalid ib. does not match regexp (${a})`);let i=Object.keys(n??{}),c=[...lt,"tjp"];if(i.some(u=>c.includes(u)))throw new Error(`Invalid rel8ns. forbiddenRel8nNames: ${c}. rel8ns keys: ${Object.keys(n??{})}. (E: 837a993c265c4362b6aa0b1a234ea5f8)`);let b=(await M.firstGen({ib:t,parentIbGib:M.primitive({ib:r}),data:o,rel8ns:n,dna:!1,noTimestamp:!0,nCounter:!1})).newIbGib;return b?.rel8ns?.past&&delete b.rel8ns.past,b?.rel8ns?.tjp&&delete b.rel8ns.tjp,b?.rel8ns?.identity&&delete b.rel8ns.identity,b.gib=await X({ibGib:{ib:b.ib,data:b.data,rel8ns:b.rel8ns},hasTjp:!1}),b}catch(a){throw console.error(`${s} ${a.message}`),a}}f(Te,"constantIbGib");function sp({addr:r}){return ra({addr:r})}f(sp,"getBinHashAndExt");function ra({addr:r}){let t=`[${ra.name}]`;try{if(!Kt({addr:r}))throw new Error("not a bin address (E: df0804d129bc4888bd6939cb76c5e0f6)");let{ib:e}=C({ibGibAddr:r}),o=e.split(" ");if(o.length===2)return{binHash:o[1],binExt:""};if(o.length===3)return o[2].startsWith("enc=")?{binHash:o[1],binExt:"",binEncoding:o[2].substring(4)}:{binHash:o[1],binExt:o[2]};if(o.length===4){if(!o[3].startsWith("enc="))throw new Error(`bin ib (${e}) has 4 space-delimited pieces. we expect therefore the form to be bin \${binHash} \${binExt} enc=\${binEncoding}. but ibPieces[3] doesn't start with "enc=". (E: 87196d7cdd7c12d982cc8204a1163524)`);return{binHash:o[1],binExt:o[2],binEncoding:o[3].substring(4)}}else throw new Error('(UNEXPECTED) ibPieces.length not 2, 3, or 4? atow (01/2024) the only components of a bin ib are: atom, binHash, binExt, binEncoding. binExt and binEncoding are optional, with binEncoding being prefixed with "enc=". (E: b05df3c1b3949f76464a83c9fd1c4f24)')}catch(e){throw console.error(`${t} ${e.message}`),e}}f(ra,"parseBinIb");function Kt({ibGib:r,addr:t}){let e=`[${Kt.name}]`;try{if(!r&&!t)throw new Error("either ibGib or addr required. (E: c935b51e773f41a2a547c556e9dc16c6)");if(r&&!r.data)return!1;t=t||y({ibGib:r});let{ib:o,gib:n}=C({ibGibAddr:t});if(!o||!n||!o.startsWith("bin "))return!1;if(n.length!==64)throw new Error('ib starts with "bin " but gib length is not 64, so return false. Two things: 1) bin ibgibs are expected to be stones, i.e., have no temporal junction point and only a single punctiliar hash for the gib. the default hash used atow (01/2024) is sha-256, so the length should be 64. But this may not be true if using another hash algorithm. need to change this function when this becomes the case. (W: 60725d65d13c4b4fbb7b96d7feb19d67)');let s=o.split(" ");if(s.length===2){if(!s[1].match(z))throw new Error('(UNEXPECTED) ib starts with "bin " but space-delimited !ibPieces[1].match(UUID_REGEXP)? (E: f6baca2ff155f1017b278a5d7597a224)')}else if(s.length===3){if(!s[1].match(z))throw new Error('(UNEXPECTED) ib starts with "bin " but space-delimited !ibPieces[1].match(UUID_REGEXP)? (E: 8d0443d6cada4b50be79a8390a7a426c)')}else if(s.length===4){if(!s[1].match(z))throw new Error('(UNEXPECTED) ib starts with "bin " but space-delimited !ibPieces[1].match(UUID_REGEXP)? (E: 3209eacc0a3848a59593d4c3ee956191)');if(!s[3].startsWith("enc="))throw new Error('(UNEXPECTED) ib starts with "bin " but space-delimited !ibPieces[3].startsWith("enc=")? (E: 4c8a0c3b07a90d30e3d1a4373d57d824)')}else throw new Error('(UNEXPECTED) ib starts with "bin " but space-delimited ibPieces length is not 2, 3 or 4? (E: c7eccf88518304997c7e42b32e08d224)');return!0}catch(o){throw console.error(`${e} ${o.message}`),o}}f(Kt,"isBinary");function Jo({type:r}){if(!r.match(So))throw new Error(`special ibgib type must not have spaces and just be alphanumerics. regexp: ${So.source} (E: 6c1c92521b7f076cc4666e4915593723)`);return`meta special ${r}`}f(Jo,"getSpecialIbGibIb");function Lr({ib:r}){let t=`[${Lr.name}]`;try{if(se&&console.log(`${t} starting... (I: c82ba222bd345ee6b695df4d63a23322)`),!r)throw new Error("ib required (E: 08897145f7138e644fe01c4a59353322)");if(!Wt({ib:r}))throw new Error("ib is not special (E: 174aff63b992adff3ac2394643735922)");let e=r.split(" ");if(e.length<3)throw new Error('invalid ib. should be space-delimited in form of "meta special [type]" (E: ffd89e2cbe63427f98634ab897aab222)');let o=e[2];return Object.values(pr).some(n=>n===o)||console.warn(`unknown special type (${o}). This may be expected, but atow I am adding special types to the SpecialIbGibType enum-like. (W: f4e26c3ebb57fe49d69014a4ba32a922)`),o}catch(e){throw console.error(`${t} ${e.message}`),e}finally{se&&console.log(`${t} complete.`)}}f(Lr,"getSpecialTypeFromIb");function $c({type:r}){return`${Jo({type:r})}^${L}`}f($c,"getSpecialIbGibAddr");function Q({type:r}){return`${Es} ${$c({type:r})}`}f(Q,"getSpecialConfigKey");function Wt({ib:r,ibGib:t}){if(!r&&!t?.ib)throw new Error("either ib or ibGib.ib required (E: b4cf539638d7966c2e351987f55e1a23)");return(r??t?.ib)?.startsWith("meta special")}f(Wt,"isSpecial");function Zo(r){let t=`[${Zo.name}]`;if(!r)throw new Error(`${t} text required.`);return`root ${r}`}f(Zo,"getRootIb");function ft(r){let t=`[${ft.name}]`;if(!r)throw new Error(`${t} tag required.`);return`tag ${r}`}f(ft,"tagTextToIb");function Cr({ibGibs:r,filterPrimitives:t}){let e=`[${Cr.name}]`;try{let o={},n={},s={};return(t?r.filter(i=>i.gib??i.gib!==L):r).forEach(i=>{oa({ibGib:i})?(i.rel8ns?.dna??[]).length>0?o[i.gib]=i:n[i.gib]=i:s[i.gib]=i}),{mapWithTjp_YesDna:o,mapWithTjp_NoDna:n,mapWithoutTjps:s}}catch(o){throw console.error(`${e} ${o.message}`),o}}f(Cr,"splitPerTjpAndOrDna");function zt({ibGibs:r}){let t=`[${zt.name}]`;try{se&&console.log(`${t} starting...`);let{mapWithTjp_YesDna:e,mapWithTjp_NoDna:o}=Cr({ibGibs:r,filterPrimitives:!0}),n={...e,...o},s=Object.values(n),a=po({items:s,keyFn:f(i=>i.data?.isTjp?y({ibGib:i}):i.rel8ns?.tjp?i.rel8ns?.tjp[0]??"":(se&&console.log(`${t} neither isTjp nor x.rel8ns.tjp truthy (I: ec9a5597bf53dec1bd3d83350abbf823)`),""),"keyFn")});return se&&console.log(`${t} sorting (ascending) ibGibsWithTjpGroupedByTjpAddr: ${H(a)} (I: 9b9fff5ce61444a6cb06d62db9a99422)`),Object.entries(a).forEach(([i,c])=>{c.some(l=>l.data?.n===void 0)&&console.warn(`${t} timeline includes ibgibs with ibGib.data?.n === undefined (W: cab9a6b64a38c4279fe82c3569bbab22)`),c.sort((l,d)=>(l.data?.n??-1)>(d.data?.n??-1)?1:-1)}),se&&console.log(`${t} after sort ibGibsWithTjpGroupedByTjpAddr: ${H(a)} (I: 9b9fff5ce61444a6cb06d62db9a99422)`),a}catch(e){throw console.error(`${t} ${e.message}`),e}finally{se&&console.log(`${t} complete.`)}}f(zt,"getTimelinesGroupedByTjp");function oa({ibGib:r}){let t=`[${oa.name}]`;if(!r)throw new Error("(UNEXPECTED) ibGib falsy? (E: ce3a59f9db14e6158bb2c438ca1a3823)");if((r.rel8ns?.tjp?.length??0)>0||r.data?.isTjp)return!0;let e=["fork^gib","mut8^gib","rel8^gib"];return(r.rel8ns?.ancestor??[]).some(n=>e.includes(n))?!1:r.gib?r.gib.includes(Oe)?!0:r.gib===L?!1:!!re({ibGibAddr:y({ibGib:r})}).tjpGib:(console.warn(`${t} ibGib.gib falsy. (W: 6400d780822b44d992846f1196509be3)`),!1)}f(oa,"hasTjp");function ue({ibGib:r,defaultIfNone:t="undefined"}){let e=`[${ue.name}]`;try{let o=na({ibGibs:[r],defaultIfNone:t});return o&&Object.keys(o).length===1?Object.values(o)[0]:void 0}catch(o){throw console.error(`${e} ${o.message}`),o}}f(ue,"getTjpAddr");function na({ibGibs:r,defaultIfNone:t="undefined"}){let e=`[${na.name}]`;try{let o={};return r.forEach(n=>{let s=y({ibGib:n}),a;n.rel8ns?.tjp?.length??!1?a=n.rel8ns.tjp[n.rel8ns.tjp.length-1]:n.data?.isTjp||t==="incomingAddr"?a=s:a=void 0,o[s]=a}),o}catch(o){throw console.error(`${e} ${o.message}`),o}}f(na,"getTjpAddrs");async function Qo({ibGib:r,naive:t=!0}){let e=`[${Qo.name}]`;try{if(!r)throw new Error("ibGib required.");if(t){if(r.data)return r.data.isTjp?!0:r.rel8ns?r.rel8ns.past&&r.rel8ns.past.length>0?!1:!!(r.rel8ns.past&&r.rel8ns.past.length===0):(se&&console.log(`${e} ibGib.rel8ns falsy (I: c69c9e78b34845311ce7c674d7195622)`),!1);throw new Error("loaded ibGib required (data).")}else throw new Error("only naive implemented right now.")}catch(o){throw console.error(`${e} ${o.message}`),o}}f(Qo,"isTjp_Naive");function Pe({ibGib:r}){let t=`[${Pe.name}]`;r.ib||console.warn(`${t} ibGib.ib is falsy. (W: e60e41c2a1fc48268379d88ce13cb77b)`),r.gib||console.warn(`${t} ibGib.gib is falsy. (W: fb3889cbf0684ae4ac51e48f28570377)`);let e={ib:(r.ib||"").slice()};return r.gib&&(e.gib=r.gib.slice()),r.data&&(Kt({ibGib:r})?e.data=r.data.slice():e.data=v(r.data)),r.rel8ns&&(e.rel8ns=v(r.rel8ns)),e}f(Pe,"toDto");function en(r){let t=`[${en.name}]`;try{return se&&console.log(`${t} starting... (I: 57aef93fc6cc2309523b5c72a6b11823)`),!!r&&typeof r.ib=="string"}catch(e){throw console.error(`${t} ${e.message}`),e}finally{se&&console.log(`${t} complete.`)}}f(en,"isIbGib");function Xt({ibGib:r,data:t,timestamp:e}){let o=`[${Xt.name}]`;try{se&&console.log(`${o} starting... (I: 35cb68744bcf6139d78e37de644fad23)`),e=e||t?.timestamp||r?.data?.timestamp;let n=r?.data?.timestampMs||t?.timestampMs;if(!e){let s=`${o} timestamp is falsy. (W: 5f1f1182c8804807b886a3d922ac3dcf)`;return console.warn(s),{valid:!1,emsg:s}}if(typeof e=="string")if(Number.isInteger(Number.parseInt(e))){let s=Number.parseInt(e),a=new Date;if(a.setTime(s),a.toString()!==Er)return se&&console.log(`${o} valid timestampInTicks string (I: 7069a1c3047f3bbc92b78674b20f5b23)`),{valid:!0,date:a,utc:a.toUTCString(),ticks:a.getTime().toString(),ms:n};{let i=`${o} data.timestamp (${e}) is an integer string but not a valid timestampInTicks string. (produces invalid date) (E: f49fbb600fe1426c8805dfc8afbe5cf3)`;return console.error(i),{valid:!1,emsg:i}}}else{let s=new Date(e);if(s.toString()!==Er)return{valid:!0,date:s,utc:s.toUTCString(),ticks:s.getTime().toString(),ms:n};{let a=`${o} data.timestamp is a non-integer string but not a valid date timestamp string (new date instantiated produces invalid date). (W: c6c90f7f3bfb49838d2081ba84fdb5fb)`;return console.warn(a),{valid:!1,emsg:a}}}else if(typeof e=="number")if(Number.isInteger(e)){console.warn(`${o} expected data.timestamp to be a string but is a number (W: 9d786f4d4e8d4279b5af7bee19bf721b)`);let s=new Date;if(s.setTime(e),s.toString()!==Er)return{valid:!0,date:s,utc:s.toUTCString(),ticks:s.getTime().toString(),ms:n};{let a=`${o} timestamp (${e}) is an integer number but not a valid timestampInTicks (new date setTime produces invalid date). (W: c6c90f7f3bfb49838d2081ba84fdb5fb)`;return console.warn(a),{valid:!1,emsg:a}}}else{let s=`${o} timestamp (${e}) is a non-integer number (supposed to be a string either timestamp string or ticks). (E: 2963d95f8d3b464c992b0bff948b4479)`;return console.error(s),{valid:!1,emsg:s}}else{let s=`${o} unknown typeof timestamp (${typeof e}). (E: 12458a9c16c84e4f859b5771a30dd2ef)`;return console.error(s),{valid:!1,emsg:s}}}catch(n){throw console.error(`${o} ${m(n)}`),n}finally{se&&console.log(`${o} complete.`)}}f(Xt,"getTimestampInfo");async function tn({addrs:r,readCache_graph:t,readCache_array:e,space:o}){let n=`[${tn.name}]`;try{se&&console.log(`${n} starting... (I: 5db66871239dfa05182277f886a20926)`),t??={},e??=[];let s={...t};e.forEach(l=>s[y({ibGib:l})]=l);let a=Object.keys(t),i=r.filter(l=>!a.includes(l));if(i.length>0){se&&console.log(`${n} ${i.length} addrsNotFoundInCache: ${i} (I: fccbd18116ffb849f813aaebfc6c0826)`);let l=[o],d=i.concat();for(let b of l){let u=await ne({addrs:d,space:b});if(u.success&&u.ibGibs&&u.ibGibs.length===d.length)u.ibGibs.forEach(p=>s[y({ibGib:p})]=p),d=[];else if(u.ibGibs&&u.ibGibs.length>0){if(d=d.filter(p=>!u.ibGibs.some(g=>y({ibGib:g})===p)),d.length===0)break}else se&&console.log(`${n} no addrs found in space (${b.ib}). trying next space. (I: 4f99d8bacbb10ab3f8737a752564b326)`)}if(d.length>0)throw new Error(`could not get all addrs from cache or spaces. addrsStillNotFound: ${d}. spaces: ${l.map(b=>b.ib).join("|")} (E: 0c6418f83dd85bda886e56f5b98f3126)`)}let c=[];for(let l of r){let d=s[l];if(!d)throw new Error(`(UNEXPECTED) allIbGibs_graph doesn't have addr? We're expecting logic to preclude this at this point. addr: ${l} (E: f68e1d236ae5e3eb08da9933c8230626)`);c.push(d)}return c}catch(s){throw console.error(`${n} ${m(s)}`),s}finally{se&&console.log(`${n} complete.`)}}f(tn,"getIbGibsFromCache_fallbackToSpaces");var sa=!1,yc="space_gib_db",Ic="space_gib_store",_c="space_gib_api_key";var Tc="agent";var dp=ft(Tc);var fp={dbName:yc,storeName:Ic,additionalStoreNames:[as],apiKeyName:_c};var aa="0.0.14";var et=!1,hp="[web^gib timer]",rn="ibgib";var Ac="agent",gp="body-outline",Ep="This tag tracks the active agents for the current local user space.",mp=ft(Ac),ia="#78f87e88",ca="#78f87e10",la="#ffffff";var wp="AUTOMATED_TEXT";var Se=!1;function da(r){return new Promise((t,e)=>{let o=new Blob([r],{type:"application/octet-stream"}),n=new FileReader;n.onload=()=>{let a=n.result.split(",")[1];t(a)},n.onerror=s=>e(s),n.readAsDataURL(o)})}f(da,"uint8ArrayToBase64");async function fa(r){let t=`data:application/octet-stream;base64,${r}`,n=await(await(await fetch(t)).blob()).arrayBuffer();return new Uint8Array(n)}f(fa,"base64ToUint8Array");async function Pr({graph:r}){let t=`[${Pr.name}]`;try{Se&&console.log(`${t} starting... (I: 4ddb8803cf68e1d3d35f60680cb69825)`);let e=JSON.parse(JSON.stringify(r));for(let n in e)r[n].data instanceof Uint8Array&&(e[n].data={_dataType:"Uint8Array_Base64",value:await da(r[n].data)});let o=JSON.stringify(e);return Se&&console.log(`${t} jsonString.length: ${o.length} (I: 56dec8ad0931ab8ba9b5ca3d4e66be25)`),o}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{Se&&console.log(`${t} complete.`)}}f(Pr,"serializeGraphToString");async function Rr({jsonString:r}){let t=`[${Rr.name}]`;try{Se&&console.log(`${t} starting... (I: 52e1a1fb1adcc75168fbc6d819868825)`);let o=JSON.parse(r,f((n,s)=>(s&&s._dataType==="Uint8Array_Base64",s),"reviver"));for(let n in o){let s=o[n].data;s&&s._dataType==="Uint8Array_Base64"&&(o[n].data=await fa(s.value))}return o}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{Se&&console.log(`${t} complete.`)}}f(Rr,"deserializeStringToGraph");async function ba(r){let t=`[${ba.name}]`;try{Se&&console.log(`${t} starting... (I: 8d306868b718596fe8f562bd5118d825)`);let e=await Pr({graph:r}),o=new TextEncoder().encode(e),s=new Response(o).body.pipeThrough(new CompressionStream("gzip"));return await new Response(s).blob()}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{Se&&console.log(`${t} complete.`)}}f(ba,"compressIbGibToBlob");async function Gc(r){let t=r.stream().pipeThrough(new DecompressionStream("gzip")),e=await new Response(t).text();return await Rr({jsonString:e})}f(Gc,"decompressIbGibFromBlob");async function on({graph:r}){let t=`[${on.name}]`;try{Se&&console.log(`${t} starting... (I: 1352f8540c08f0b725952df8f18c4825)`);let o=await(await ba(r)).arrayBuffer(),n=new Uint8Array(o);return await da(n)}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{Se&&console.log(`${t} complete.`)}}f(on,"compressIbGibGraphToString");async function nn({compressedBase64:r}){let t=`[${nn.name}]`;try{Se&&console.log(`${t} starting... (I: 5f3fa940a2c8f8d7b877978ae7f87825)`);let e=await fa(r),o=new Blob([e],{type:"application/gzip"});return await Gc(o)}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{Se&&console.log(`${t} complete.`)}}f(nn,"decompressIbGibGraphFromString");var ua="export";var Jt=!1;function pa({data:r}){let t=`[${pa.name}]`;try{Jt&&console.log(`${t} starting... (I: 158dfaeb9613a1531be71a9735184624)`);let{graphSize:e,dependencyGraphAsString:o,timestamp:n}=r,s=o.length,a=ge(n),i=r.compression==="gzip"?"gzip":"raw";if(!r.timestamp)throw new Error("(UNEXPECTED) data.timestamp falsy? (E: 2f5bc88488cbf260634239a8a8396825)");let c=new Date(r.timestamp),{ib:l,gib:d}=C({ibGibAddr:r.contextIbGibAddr}),u=re({gib:d}).tjpGib??d,p=c.toISOString().slice(0,19).replace("T","_").replace(/:/g,"").replace(/ /g,"_");return`${ua} ${p} ${i} ${e} ${s} ${u}`}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{Jt&&console.log(`${t} complete.`)}}f(pa,"getRawExportIb");async function sn({ibGib:r,metaspace:t,space:e,compress:o,live:n,ignoreErrors:s}){let a=`[${sn.name}]`;try{if(Jt&&console.log(`${a} starting... (I: 0b6ba8608ba8bde0682a0936b9a01825)`),!r)throw new Error("(UNEXPECTED) ibGib falsy? (E: d2898eea744360865f0da5fb91baae22)");let i=y({ibGib:r}),c=[],l=await oe({ibGib:r})??[];if(l.length>0){let $=`ibGib had validation errors: ${l} (E: 84890bbc0598192498178a98ae299825)`;if(s)c.push({errorMsg:$,ibGibAddr:i});else throw new Error($)}let d=await t.getDependencyGraph({ibGib:r,live:n,space:e}),b=o?await on({graph:d}):await Pr({graph:d}),u=ue({ibGib:r,defaultIfNone:"incomingAddr"})??i,p=new Date,g={contextIbGibAddr:i,tjpAddr:u,dependencyGraphAsString:b,graphSize:Object.keys(d).length,timestamp:xe(p),timestampMs:p.getMilliseconds()};o&&(g.compression="gzip");let h={ib:pa({data:g}),data:g},E=await X({ibGib:h,hasTjp:!1});return h.gib=E,console.log(`${a} JSON.stringify(exportIbGib).length: ${JSON.stringify(h).length} (I: db3a8d913a91d8fc5d6e45981e034822)`),{rawExportIbGib:h,manifest:Object.keys(d),errors:c.length>0?c:void 0}}catch(i){throw console.error(`${a} ${m(i)}`),i}finally{Jt&&console.log(`${a} complete.`)}}f(sn,"getRawExportIbGib");var Rp="ibgib-shell-ready",Up="ibgib-ui-busy",Mp="ibgib-ui-message",kp="ibgib-identity-request-change",jp="ibgib-identity-changed",Bp="ibgib-identity-update-available";var ha=et;async function Ot({title:r,msg:t,prompt:e,showInput:o,defaultValue:n,okButtonTitle:s,cancelButtonTitle:a,isPassword:i,isBusy:c,animationEmoji:l}){let d=`[${Ot.name}]`;try{ha&&console.log(`${d} starting... (I: 037b228a2568181cd3eb25dba4e03225)`);let b=document.getElementById("fullscreen-dialog"),u=document.getElementById("fullscreen-dialog-body"),p=document.getElementById("fullscreen-dialog-title"),g=document.getElementById("fullscreen-dialog-message"),h=document.getElementById("fullscreen-dialog-prompt-input"),E=document.getElementById("fullscreen-dialog-ok-button"),$=document.getElementById("fullscreen-dialog-cancel-button");if(!b||!u||!p||!g||!h||!E||!$)throw new Error("(UNEXPECTED) One or more dialog elements not found in DOM (E: 578e37c0271cc57a99e95e780ad18a25)");if(p.textContent=r||"",[...g.childNodes].forEach(w=>g.removeChild(w)),(t||"").split(`
|
|
9
9
|
`).forEach(w=>{let _=document.createElement("p");_.textContent=w,g.appendChild(_)}),l){let w=document.createElement("div");w.id="fullscreen-dialog-animation-emoji",w.textContent=l,w.style.fontSize="3.5rem",w.style.textAlign="center",w.style.margin="1.5rem 0",w.style.animation="spin-bounce 5s infinite ease-in-out",g.appendChild(w)}h.classList.remove("collapsed"),$.classList.remove("collapsed"),$.style.display="inline-block",E.style.display="inline-block",E.textContent=s||"OK";let A=f(w=>{(w.key==="Enter"||w.key===`
|
|
10
10
|
`)&&w.ctrlKey&&E.click()},"onKeypress");return c?(h.classList.add("collapsed"),$.style.display="none",E.style.display="none"):e||o?(h.addEventListener("keypress",A),o?(h.autofocus=!0,h.value=n??"",h.addEventListener("keypress",w=>{w.key==="Enter"&&E.click()}),i?(h.type="password",h.autocomplete="off",h.required=!0):(h.type="text",h.autocomplete="on",h.required=!1,h.attributes["auto-complete"]="on")):(h.autofocus=!1,h.classList.add("collapsed")),$.textContent=a||"Cancel"):(h.classList.add("collapsed"),$.style.display="none"),new Promise(w=>{if(c){let U=f(k=>{k.preventDefault()},"onCancelEvent");b.addEventListener("cancel",U);let x=f(()=>{b.removeEventListener("cancel",U),b.close()},"close"),N=f(({title:k,msg:ae,animationEmoji:ie})=>{if(k!==void 0&&(p.textContent=k),ae!==void 0){[...g.childNodes].forEach(Ue=>{Ue.id!=="fullscreen-dialog-animation-emoji"&&g.removeChild(Ue)});let q=ae.split(`
|
|
11
|
-
`),uo=document.getElementById("fullscreen-dialog-animation-emoji");q.forEach(Ue=>{let Rt=document.createElement("p");Rt.textContent=Ue,uo?g.insertBefore(Rt,uo):g.appendChild(Rt)})}if(ie!==void 0){let q=document.getElementById("fullscreen-dialog-animation-emoji");ie?(q||(q=document.createElement("div"),q.id="fullscreen-dialog-animation-emoji",q.style.fontSize="3.5rem",q.style.textAlign="center",q.style.margin="1.5rem 0",q.style.animation="spin-bounce 5s infinite ease-in-out",g.appendChild(q)),q.textContent=ie):q&&q.remove()}},"update");b.open||b.showModal(),le(1e3).then(()=>{u.scrollTo({top:0,behavior:"smooth"})}),w({close:x,update:N});return}let _=f(()=>{(e||o)&&h.removeEventListener("keypress",A),E.removeEventListener("click",S),$.removeEventListener("click",G),b.removeEventListener("close",O)},"removeEventListeners"),S=f(()=>{_();let U=o?h.value??"":"true";h&&(h.value=""),b.close(U),w(U)},"onOK"),G=f(()=>{_(),h&&(h.value=""),b.close(void 0),w(void 0)},"onCancel"),O=f(()=>{_(),h&&(h.value=""),b.close(void 0),w(void 0)},"onClose");E.addEventListener("click",S),$.addEventListener("click",G),b.addEventListener("close",O),b.open||b.showModal(),le(1e3).then(()=>{u.scrollTo({top:0,behavior:"smooth"})})})}catch(b){throw console.error(`${d} ${m(b)}`),b}finally{ha&&console.log(`${d} complete.`)}}f(Ot,"showFullscreenDialog");var te=et;async function Gc({metaspace:r,space:t}){let e=`[${Gc.name}]`;try{te&&console.log(`${e} starting... (I: 2ccb79537a75e7896bace84e6c710d25)`);let o=await r.getSpecialIbGib({type:pr.tags,space:t});if(!o)throw new Error(`tagsIbGib not found in metaspace. space: ${t?t.ib:"default local user space"} (E: 4734c510a411274315c0add8f70e1925)`);return o}catch(o){throw console.error(`${e} ${m(o)}`),o}finally{te&&console.log(`${e} complete.`)}}f(Gc,"getTagsIbGib");function cn({scope:r,ibGib:t,ibGibAddr:e,defaultNameIfError:o}){let n=`[${cn.name}]`;try{if(!t&&!e)throw new Error(`${n} Must provide either ibGib or ibGibAddr. (E: genuuid)`);r.includes(" ")&&(console.warn(`${n} scope includes one or more spaces. These will be converted to double underscores. (W: 1554a81454e8ae0a6858ea5dd17f8925)`),r=r.replace(/ /g,"__"));let s,a,i;if(t){if(!t.data)throw new Error("(UNEXPECTED) ibGib.data falsy? (E: genuuid)");if(!t.rel8ns)throw new Error("(UNEXPECTED) ibGib.rel8ns falsy? (E: genuuid)");if(!t.rel8ns.ancestor)throw new Error("(UNEXPECTED) ibGib.rel8ns.ancestor falsy? (E: genuuid)");if(t.rel8ns.ancestor.length===0)throw new Error("(UNEXPECTED) ibGib.rel8ns.ancestor.length === 0? there should be at least one ancestor (E: genuuid)");if(t&&e&&y({ibGib:t})!==e)throw new Error("(UNEXPECTED) both ibGib and ibGibAddr provided, but addr of ibGib doesn't equal ibGibAddr? (E: genuuid)");let d=t.rel8ns.ancestor.filter(u=>Z({gib:P({ibGibAddr:u}).gib}));if(d.length===0){debugger;console.error(`${n} ibGib has no primitive ancestor addrs? Still going to work off of the ib then, which should have the atom as the first space-delimited term. (E: genuuid)`)}let b=d.at(-1);s=P({ibGibAddr:b}).ib,i=s}e??=y({ibGib:t});let{ib:c}=P({ibGibAddr:e});if(a=c.split(" ").at(0)??"",a=a.replace(/\W/g,"_"),s??=a,s=s.replace(/\W/g,"_"),!s&&!a)throw new Error("(UNEXPECTED) both primitiveAncestorIb and atom falsy? one should be truthy at this point. (E: genuuid)");i=a.toLowerCase(),te&&console.log(`${n} ancestorIbOrAtom: ${i} (I: genuuid)`);let l=`${i}_${r}index`;return te&&console.log(`${n} indexName: ${l} (I: genuuid)`),l}catch(s){if(o)return console.warn(`${n} error happened but defaultNameIfError (${o}) provided. So will return this value. error that was thrown: ${m(s)}`),o;throw console.error(`${n} ${m(s)}`),s}}f(cn,"getIndexNameFromIbGib");async function Sc({scope:r,ibGib:t,metaspace:e,space:o,skipGetLatest:n}){let s=`[${Sc.name}]`;try{if(te&&console.log(`${s} starting... (I: f19dc86aab380fe809aef27ccc7a7425)`),!r)throw new Error("scope required to be a non-empty string (E: 73e702495c38c7d8747d1cf8850af825)");if(!t)throw new Error("ibGib required (E: genuuid)");let a=cn({scope:r,ibGib:t}),i=be({ibGib:t,defaultIfNone:"incomingAddr"}),c=f(async()=>{let d=await e.getSpecialIbGib({type:a,space:o,initialize:!1,dontWarnIfNotExist:!0,lock:!0});if(!d||!d.data){te&&console.log(`${s} special ${r} index ibGib not found for indexSpecialIbGibType (${a}). No coupled ibgib registered, returning undefined. (I: genuuid)`);return}let u=(d.data.coupleMap??d.data.agentMap??{})[i];if(!u){te&&console.log(`${s} No coupled ${r} ibgib address found for domain ${i} in the coupled index map. indexSpecialIbGibType: ${a}. returning undefined. (I: genuuid)`);return}let p=n?u:await e.getLatestAddr({addr:u,space:o})??u,g=await e.get({addrs:[p],space:o});if(g.errorMsg||(g.ibGibs??[]).length!==1)throw new Error(`couldn't get latest coupled ibgib (${p}) for domain ${i}. (E: 8aa7b25f5cd4ebadd8bf2f8807dfe825)`);return g.ibGibs[0]},"fn");return await Ae({scope:a,secondsValid:180,maxDelayMs:100,maxLockAttempts:1800,space:o,callerInstanceId:s+ge(),fn:c})}catch(a){throw console.error(`${s} ${m(a)}`),a}finally{te&&console.log(`${s} complete.`)}}f(Sc,"getLocalCoupledIbGibForDomainIbGib");async function xc({scope:r,domainIbGib:t,localIbGib:e,metaspace:o,space:n}){let s=`[${xc.name}]`;try{te&&console.log(`${s} starting... (I: 217ae68e0c820e48f4c00409f7f14325)`);let a=cn({scope:r,ibGib:t}),i=be({ibGib:t}),c=y({ibGib:e});if(!i)throw new Error(`${s} Could not get TJP address for domain ibGib. (E: 35a4e8ac291b0b85cb958e28dd812f25)`);if(!c)throw new Error(`${s} Could not get address for agent ibGib. (E: 2fce1187630b45934c4155a23204d125)`);await Ae({scope:a,secondsValid:60,maxDelayMs:100,maxLockAttempts:600,space:n,fn:f(async()=>{let d=await o.getSpecialIbGib({type:a,space:n,initialize:!0,dontWarnIfNotExist:!0,lock:!1});if(!d)throw new Error(`${s} Could not get or create agent index ibGib.`);if(!d.data)throw new Error("(UNEXPECTED) agentSpecialIndex.data falsy? (E: 74299eed147debf6398ca37e7b8d5c25)");let b=d.data.coupleMap??d.data.agentMap,u=b?v(b):{},p=u[i];if(p)if(p===c){te&&console.log(`${s} domain ibGib (${i}) already mapped to agent (${c}). returning early (I: cb5d4dcef8cf14de7336120fb8ffef25)`);return}else console.warn(`${s} domainTjpAddr (${i}) already assigned to existingMappedAgentAddr (${p}). We will be changing to new localAddr (${c}). (W: eb993e33f7731e570fa76f24a2d80625)`);u[i]=c;let g=await Me({src:d,dataToAddOrPatch:{coupleMap:u},dna:!1,linkedRel8ns:[K.past],nCounter:!0}),h=g.newIbGib;await ee({resTransform:g,space:n});let E=Q({type:a});await o.setConfigAddr({key:E,addr:y({ibGib:h}),space:n}),await o.registerNewIbGib({ibGib:h,space:n})},"fn")}),te&&console.log(`${s} Registered domain ${i} with agent ${c}`)}catch(a){throw console.error(`${s} ${m(a)}`),a}finally{te&&console.log(`${s} complete.`)}}f(xc,"coupleDomainIbGibWithLocalIbGibViaIndex");function ft(){let r=`[${ft.name}]`;try{te&&console.log(`${r} starting... (I: 890f53e984d69461d9f4ded8741fcc25)`);let t=globalThis[rn];return t||(console.log(`${r} initializing globalThis.${rn}... (I: 9d9ff1813448d9a1b82b0e5790a74825)`),t={}),t}catch(t){throw console.error(`${r} ${m(t)}`),t}finally{te&&console.log(`${r} complete.`)}}f(ft,"getIbGibGlobalThis_IbGib");async function Ea({delayIntervalMs:r=50}={delayIntervalMs:50}){let t=`[${Ea.name}]`;try{te&&console.log(`${t} starting... (I: 4acc22d08dd1100503f9b0423f302925)`);let e;for(;!e;)ft().metaspace&&(e=ft().metaspace),e||(console.log(`${t} metaspace still not initialized. delayIntervalMs: ${r} until next retry... (I: 490f77ac4ded1d7d3c0340e460404125)`),await le(r));return e}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{te&&console.log(`${t} complete.`)}}f(Ea,"getGlobalMetaspace_waitIfNeeded");function Oc({ibGibAddr:r,gib:t,ibGib:e,translucentAlpha:o=10}){let n=`[${Oc.name}]`;try{te&&console.log(`${n} starting... (I: 3b70af42d1c4f6ae91870f3a15c6c625)`),!r&&!t&&!e&&(t=L),t??=e?.gib??P({ibGibAddr:r}).gib;let s=re({gib:t});o??=10;let a="";if(s.isPrimitive)return{gib:t,gibInfo:s,punctiliarColor:ia,punctiliarColorTranslucent:ca,punctiliarColorContrast:la};a=s.tjpGib??s.punctiliarHash??t;let[i,c,l]=ga(o,s.punctiliarHash??t),[d,b,u]=s.tjpGib?ga(o,s.tjpGib):[void 0,void 0,void 0];return{gib:t,gibInfo:s,punctiliarColor:i,punctiliarColorTranslucent:c,punctiliarColorContrast:l,tjpColor:d,tjpColorTranslucent:b,tjpColorContrast:u}}catch(s){let a=`${n} ${m(s)}`;return console.error(a),{gib:t??L,gibInfo:{isPrimitive:!0},punctiliarColor:"#ff0000",punctiliarColorTranslucent:"#ff000010",punctiliarColorContrast:"#ffffff",errorMsg:a}}finally{te&&console.log(`${n} complete.`)}}f(Oc,"getDeterministicColorInfo");function Dc(r,t,e){e/=100;let o=t*Math.min(e,1-e)/100,n=f(s=>{let a=(s+r/30)%12,i=e-o*Math.max(Math.min(a-3,9-a,1),-1);return Math.round(255*i).toString(16).padStart(2,"0")},"f");return`#${n(0)}${n(8)}${n(4)}`}f(Dc,"hslToHex");function ga(r,t){let o=(parseInt(t.substring(0,8),16)||0)%360,n=Dc(o,65,62),s=parseInt(n.substring(1,3),16),a=parseInt(n.substring(3,5),16),i=parseInt(n.substring(5,7),16),l=(s*299+a*587+i*114)/1e3>=128?"#11111b":"#ffffff",d=Math.min(100,Math.max(0,r)),b=Math.round(d/100*255).toString(16).padStart(2,"0"),u=`${n}${b}`;return[n,u,l]}f(ga,"getColorStrings");var ue=et;function wa(r){return new TextDecoder().decode(r)}f(wa,"uint8ArrayToString");var ma=class r{static{f(this,"PathUtilsHelper")}lc=`[${r.name}]`;constructor(){}isAbsolute(t){if(!t)throw new Error("(UNEXPECTED) path falsy? (E: dcb92e11770ba06205c0afe3e6560b24)");return t.startsWith("/")}isRelative(t){return!this.isAbsolute(t)}join(...t){let e=`${this.lc}[${this.join.name}]`;if(t.length===0)return console.log(`${e} paths.length === 0. returning '.' per node convention. (I: 153da80765ff6160675fae895ebac225)`),".";if(t.length===1&&t[0]==="..")return console.log(`${e} paths.length === 1 && paths[0] === '..'. returning '..' per node convention. (I: 9af242b7615430a8c6899b1a332e9925)`),"..";let o="";for(let n=0;n<t.length;n++){let s=t[n];s===".."?o=o.split("/").slice(0,-1).join("/"):(s.startsWith("/")&&(s=s.slice(1)),s.endsWith("/")&&(s=s.slice(0,-1)),o+=(n>0?"/":"")+s)}return o}dirname(t){return t.split("/").slice(0,-1).join("/")}basename(t,e){return t.split("/").pop()??""}};async function vc({msg:r,title:t,confirm:e,noNewLine:o,rl:n,defaultValue:s,dontCloseRl:a,cancelable:i}){let c=`[${vc.name}]`;try{if(!r)throw new Error("msg required (E: 7f4d67bca4cf98ea95fa110aabc98924)");let l,d=0,b=5;do{if(d++,d>=b)throw new Error("max attempts reached (E: 1ef20ae955622d4b39479f3da91a1d25)");await le(50),l=await Ot({title:t||"Prompt for Info",msg:r,prompt:!0,showInput:!0,isPassword:!1,defaultValue:s})}while(l===void 0&&!i);return l??""}catch(l){debugger;throw console.error(`${c} ${m(l)}`),l}}f(vc,"promptForText");async function Nc({msg:r,confirm:t}){let e=`[${Nc.name}]`;try{ue&&console.log(`${e} starting... (I: 795a4ce348ddb9a5119770f4c572ac24)`);let o,n=!0,s=0,a=5;do{if(s++,s>=a)throw new Error("max attempts reached (E: d4166b4bf37aff0c6d44567792e9ad25)");if(await le(50),o=await Ot({title:n?"Shh...":"Secrets didn't match, try again...",msg:r||"Enter Your Secret...",prompt:!0,showInput:!0,isPassword:!0,defaultValue:void 0}),o===void 0)throw new Error("user cancelled (E: 91519d04378e84106f3df8eb36d99725)");if(t){await le(250);let i=await Ot({title:"Shh...",msg:"Confirm...",prompt:!0,showInput:!0,isPassword:!0,defaultValue:void 0});i===void 0&&(o=void 0),o!==i&&(o=void 0,n=!1,await le(250))}}while(o===void 0);return o}catch(o){throw console.error(`${e} ${m(o)}`),o}finally{ue&&console.log(`${e} complete.`)}}f(Nc,"promptForSecret");async function Lc({msg:r,title:t,skipHitEnterToContinue:e}){let o=`[${Lc.name}]`;try{if(!r)throw new Error("msg required (E: ffcf7dd00324df7cea2792223d229524)");try{t??="",await le(50),await Ot({title:t,msg:r})}catch(n){throw n}}catch(n){throw console.error(`${o} ${m(n)}`),n}}f(Lc,"alertUser");async function Pc({exportIbGibJsonString:r,metaspace:t}){let e=`[${Pc.name}]`;try{debugger;if(ue&&console.log(`${e} starting... (I: genuuid)`),!t)throw new Error("(UNEXPECTED) metaspace falsy? (E: genuuid)");if(!await t.getLocalUserSpace({lock:!1}))throw new Error("(UNEXPECTED) couldn't get default local user space? (E: genuuid)");let n,s;try{n=JSON.parse(r)}catch(l){let d=`Error during parse JSON. error: ${m(l)} (E: genuuid)`,b=new Error(d);throw b.cause=l,b}try{let l=await oe({ibGib:n})??[];if(l.length>0)throw new Error(`validation errors when validating the parsed ibgib that should be a RawExportIbGib_V1: ${l} (E: 8ba178d3b26e8eca28a67c182fe16825)`);if(s=n,!s.data)throw new Error("(UNEXPECTED) rawExportIbGib.data falsy? (E: ef1824d1cca5584ab8e34288346e9825)")}catch(l){let d=`Error during parse JSON. error: ${m(l)} (E: genuuid)`,b=new Error(d);throw b.cause=l,b}let a;if(s.data.compression)switch(s.data.compression){case"gzip":a=await nn({compressedBase64:s.data.dependencyGraphAsString});break;default:throw new Error(`unknown value of rawExportIbGib.data.compression: ${s.data.compression} (E: 784672fae568312d887ddbb841199925)`)}else a=await Cr({jsonString:s.data.dependencyGraphAsString});let i={};for(let[l,d]of Object.entries(a)){let b=await oe({ibGib:d})??[];b.length>0&&(i[l]=b)}if(Object.keys(i).length>0)throw new Error(`there were validation errors for the RawExportIbGib_V1.data payload (contained in data.dependencyGraphAsString). Here is the validationErrorMap:
|
|
12
|
-
${H({validationErrorMap:i})} (E: e63f38b182a84122d83a55befb369825)`);return[s,a]}catch(o){throw console.error(`${e} ${m(o)}`),o}finally{ue&&console.log(`${e} complete.`)}}f(Pc,"getRawExportIbGibAndGraphFromJsonString");async function Rc({ibGib:r,compress:t,metaspace:e,space:o}){let n=`[${Rc.name}]`;try{if(ue&&console.log(`${n} starting... (I: 623d9463d919683be81f749821a95825)`),Z({ibGib:r}))throw new Error("ibGib is primitive. Can't export primitive. (E: dd42c42e9fda0707e81c692af1a2a225)");let s=await sn({ibGib:r,live:!0,compress:t,metaspace:e,space:o}),{rawExportIbGib:a,errors:i}=s;if((i??[]).length>0)throw new Error(`Export had errors: ${i} (E: 05faf83f25d3449ab809dfd24eeaf825)`);let c=JSON.stringify(a),l="data:text/json;charset=utf-8,"+encodeURIComponent(c),b=`${y({ibGib:a})}.json`,u=document.createElement("a");u.setAttribute("style","none"),u.setAttribute("href",l),u.setAttribute("download",b);let p=document.getElementsByTagName("div")[0];p.appendChild(u),u.click(),p.removeChild(u)}catch(s){throw console.error(`${n} ${m(s)}`),s}finally{ue&&console.log(`${n} complete.`)}}f(Rc,"exportIbGib");function Cc(){let r=`[${Cc.name}]`;try{ue&&console.log(`${r} starting... (I: 62a29f9982b4b5ecd91ff58ca4dd6825)`);let t=ft();if(!t.storeName_hack)throw new Error("(UNEXPECTED) global store name falsy? (E: 3b9b680f6a980debbb877c9a13fb2625)");return t.storeName_hack}catch(t){throw console.error(`${r} ${m(t)}`),t}finally{ue&&console.log(`${r} complete.`)}}f(Cc,"getGlobalStoreName");function Uc(){let r=`[${Uc.name}]`;try{ue&&console.log(`${r} starting... (I: 8c8f08728fc7384f87697377358cc825)`);let t=ft();if(!t.dbName_hack)throw new Error("(UNEXPECTED) global db name falsy? (E: 3aa028d5e4088f3f3841aae94ac02825)");return t.dbName_hack}catch(t){throw console.error(`${r} ${m(t)}`),t}finally{ue&&console.log(`${r} complete.`)}}f(Uc,"getGlobalDbName");function Mc(){let r=`[${Mc.name}]`;try{ue&&console.log(`${r} starting... (I: 59a2510a85051f97ed15fbc8825b6825)`);let t=ft();if(!t.apiKeyName_hack)throw new Error("(UNEXPECTED) global api key name falsy? (E: 1782e812f0c87f54b8059468a5b60125)");return t.apiKeyName_hack}catch(t){throw console.error(`${r} ${m(t)}`),t}finally{ue&&console.log(`${r} complete.`)}}f(Mc,"getGlobalIndexedDbKey_APIKey");async function ln({infos:r}){let t=`[${ln.name}]`;try{ue&&console.log(`${t} starting... (I: 4d41880fb748ee2302a624a255665825)`);for(let e of r){let{dbName:o,storeNames:n}=e;await fn({dbName:o})||await Mr({dbName:o});for(let a of n)await dn({dbName:o,storeName:a})}}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{ue&&console.log(`${t} complete.`)}}f(ln,"initAppStorage");var pe=et,$a=0;async function Mr({dbName:r,storeName:t,version:e,logalot:o=!1}){let n=`[${Mr.name}][${r}][${t??"no store name"}]`,s=crypto.randomUUID();o&&console.time(n+s);let a;try{o&&console.log(`${n} starting... (I: f35d4e1ba37252f14c8532fb861b1125)`),await new Promise((c,l)=>{try{o&&console.log(`${n} starting... (I: 0aeddd9376daa0a044677ce4cf8a4c24)`),o&&console.timeLog(n+s,"opening... (I: e748b4ddb445d77cb10a7ba158b49125)");let d=indexedDB.open(r,e);$a++,console.log(`${n} initRequestCount: ${$a} (I: 294d5f0b12ffe5512bacebe891824d25)`);let b;d.onupgradeneeded=u=>{try{a=u.target.result,o&&console.timeLog(n+s,"onupgradeneeded... (I: e748b4ddb445d77cb10a7ba158b49125)"),t&&(a.objectStoreNames.contains(t)?b=!0:(b=!1,a.createObjectStore(t,{keyPath:"key"})))}catch(p){console.error(`${n}[openDBRequest.onupgradeneeded] ${m(p)} (E: 4a5fa1b0850be47e28bee653da287325)`),l(p)}},d.onblocked=u=>{console.log(`${n}[openDBRequest.onblocked] openDBRequest blocked...time wasted a bit here. version change event (old -> new): ${u.oldVersion} -> ${u.newVersion} (I: 9074ebf4afdba54d6f9d41b360b96a25)`),console.dir(u)},d.onsuccess=u=>{try{o&&console.log("init success (I: 297a5a71e405a0b56413af813f248d24)"),o&&console.timeLog(n+s,"onupgradeneeded... (I: e748b4ddb445d77cb10a7ba158b49125)"),a=u.target.result,t&&(b??=a.objectStoreNames.contains(t),o&&console.log(`${n} ${r} store "${t}" ${b?"already exists":"does not exist"}. (I: db64712bc69c5287b1cf77af1fc13d24)`)),c()}catch(p){console.error(`${n}[openDBRequest.onsuccess] ${m(p)}`),l(p)}},d.onerror=u=>{debugger;console.error(`${n}[initRequest.onerror] ${m(d.error)} (E: 74cf09e9fba2dd9e41225e943c331124)`),l(d.error)}}catch(d){console.error(`${n} ${m(d)}`);debugger;l(d)}finally{o&&console.log(`${n} complete.`)}})}catch(i){throw console.error(`${n} ${m(i)}`),i}finally{a&&(o&&console.log(`${n} closing db ${r}... (I: 3f1c18eec567ea63f3927eef0f038925)`),a.close(),o&&(console.log(`${n} closing db ${r} complete. (I: bc3b2f504245d6203dbba6bd65d30325)`),console.timeLog(n+s,"db closed. (I: e748b4ddb445d77cb10a7ba158b49125)"))),o&&(console.log(`${n} complete.`),console.timeEnd(n+s))}}f(Mr,"initializeStorage");async function ya({dbName:r,logalot:t=!1}){let e=`[${ya.name}]`,o=crypto.randomUUID();t&&console.time(e+o);try{return t&&console.log(`${e} starting... (I: 8516795b20529d19eb6923defd7a0f24)`),(await indexedDB.databases()).filter(s=>s.name===r).at(0)}catch(n){console.error(`${e} ${m(n)}`)}finally{t&&console.timeEnd(e+o),t&&console.log(`${e} complete.`)}}f(ya,"storageGetDBInfo");async function dn({dbName:r,storeName:t,logalot:e=!1}){let o=`[${dn.name}]`,n=crypto.randomUUID();e&&console.time(o+n);let s;try{if(e&&console.log(`${o} starting... (I: 029f7caa8ea5ea08a865f3924c82b624)`),!(await indexedDB.databases()).filter(b=>b.name===r).at(0))throw new Error(`db (${r}) does not exist. can't create store (${t}) (E: 5b15f7aed6f7068d077b2c7ebcbe8524)`);let i=!1;if(e&&console.timeLog(o+n),await new Promise((b,u)=>{let p=indexedDB.open(r);p.onsuccess=g=>{s=g.target.result,i=s.objectStoreNames?.contains(t),e&&console.timeLog(o+n,"open db request"),b()},p.onerror=g=>{debugger;console.error(`${o}[openDBRequest.onerror] ${m(p.error)} (E: 63695744e9e59ff8019e04ceeb8e2524)`),u(p.error)}}),e&&console.timeLog(o+n),i){e&&console.log(`${o} store ${t} already existed. (I: a2263b510c18240fc59fca54e3892324)`);return}let c=await ya({dbName:r,logalot:e});if(e&&console.timeLog(o+n,"storageGetDBInfo complete"),!c)throw new Error(`db (${r}) does not exist. can't create store (${t}) (E: c771db13fa28f67079aad45e1ab7e624)`);let l=c.version;if(!l)throw new Error(`db (${r}) has no version. can't create store (${t}) (E: 3d2ec52853ad99f92b19ac5aa7fbfe24)`);let d=l+1;if(e&&console.log(`${o} creating store ${t} with version ${d} (I: 312b79f28243c650cf38935114f21e24)`),s)s.close(),s=void 0;else throw new Error("(UNEXPECTED) how did we get here with db falsy? (E: b561784879e19bac54b1c4936aff0c25)");await Mr({dbName:r,storeName:t,version:d,logalot:e})}catch(a){throw console.error(`${o} ${m(a)}`),a}finally{s&&(e&&console.log(`${o} closing db ${r}... (I: 3f1c18eec567ea63f3927eef0f038925)`),s.close(),e&&console.log(`${o} closing db ${r} complete. (I: bc3b2f504245d6203dbba6bd65d30325)`)),e&&console.timeLog(o+n),e&&console.log(`${o} complete.`)}}f(dn,"storageCreateStoreIfNotExist");async function an({dbName:r,version:t,storeName:e,key:o,value:n,logalot:s=!1}){let a=`[${an.name}]`,i;try{s&&console.log(`${a} starting... (I: bf7316c244888cb8ead2d3aac1d9f625)`),await new Promise((l,d)=>{try{s&&console.log(`${a} starting... (I: 81df59e3961d711ce5d8f2ae3e2f3824)`);let b=indexedDB.open(r,t);b.onsuccess=u=>{i=u.target.result;try{let p=i.transaction(e,"readwrite").objectStore(e),g={key:o,value:n};p.put(g),l()}catch(p){console.error(`${a}[putRequest.onsuccess] ${m(p)}`),d(p)}},b.onerror=u=>{debugger;console.error(`${a}[putRequest.onerror] ${m(b.error)} (E: 7a946d99ede2b248df4dcfea4ac99724)`),d(b.error)}}catch(b){console.error(`${a} ${m(b)}`),d(b)}finally{s&&console.log(`${a} complete.`)}})}catch(c){throw console.error(`${a} ${m(c)}`),c}finally{i&&(s&&console.log(`${a} closing db ${r}... (I: 438c6edced94b83a3478c71b08c6c325)`),i.close(),s&&console.log(`${a} closing db ${r} complete. (I: 0d081553b1eb53c65ade2cedb802cf25)`)),s&&console.log(`${a} complete.`)}}f(an,"storagePut");async function Ur({dbName:r,version:t,storeName:e,key:o,logalot:n=!1}){let s=`[${Ur.name}]`,a;try{return n&&console.log(`${s} starting... (I: f8ba7cd5801918a8580e91b7c90aa525)`),await new Promise((l,d)=>{try{n&&console.log(`${s} starting... (I: 24163c4a11c8712097db45febaf9c724)`);let b=indexedDB.open(r,t);b.onsuccess=u=>{a=u.target.result;let p;try{p=a.transaction(e).objectStore(e)}catch(h){debugger;console.error(`${s}[openDBRequest.onsuccess][objectStore] ${m(h)}`),d(h);return}let g=p.get(o);g.onsuccess=h=>{try{let E=h.target?.result?.value??void 0;if(!E){l(E);return}if(n&&console.log("Retrieved value:",E),E instanceof Uint8Array)l(wa(E));else{if(typeof E!="string")throw new Error("(UNEXPECTED) truthy, non-Uint8Array value is not a string? (E: 6a4ec24e2e5d9848f8b542bc2661dc24)");l(E)}}catch(E){d(E)}},g.onerror=h=>{debugger;let E=g.error;console.error(`${s}[openDBRequest.onsuccess][getRequest.onerror] ${m(E)}`),d(E)}},b.onerror=u=>{debugger;console.error(`${s}[openDBRequest.onerror] ${m(b.error)} (E: 074963a908fa9a075f01c73cae829224)`),d(b.error)}}catch(b){console.error(`${s} ${m(b)}`),d(b)}finally{n&&console.log(`${s} complete.`)}})}catch(i){throw console.error(`${s} ${m(i)}`),i}finally{a&&(n&&console.log(`${s} closing db ${r}... (I: a938fc22dfdc76b15f6926bc4d458225)`),a.close(),n&&console.log(`${s} closing db ${r} complete. (I: 18f2ec1557bc83ec4e2c5d5e72264525)`)),n&&console.log(`${s} complete.`)}}f(Ur,"storageGet");async function fn({dbName:r,store:t}){let e=`[${fn.name}]`,o;try{return pe&&console.log(`${e} starting... (I: 2b4373affa3841220f0b7ca690406624)`),(await window.indexedDB.databases()).some(a=>a.name===r)?t?await new Promise((a,i)=>{let c=indexedDB.open(r);c.onsuccess=l=>{o=l.target.result;let d=o.objectStoreNames.contains(t);a(d)},c.onerror=l=>{debugger;o=c.result;let{error:d}=l.target;console.error(`${e}[openDBRequest.onerror] ${m(c.error)} (E: c783fe607451e46c1feae3a81e0f7924)`),i(d)}}):!0:!1}catch(n){throw console.error(`${e} ${m(n)}`),n}finally{o&&(pe&&console.log(`${e} closing db ${r}... (I: 8782d9eea285cf9eb638d493a421a625)`),o.close(),pe&&console.log(`${e} closing db ${r} complete. (I: 76a0c5dea2643e2bb84c82c8446a8125)`)),pe&&console.log(`${e} complete.`)}}f(fn,"storageDBExists");async function kc({dbName:r,storeName:t,pathToRm:e}){let o=`[${kc.name}]`,n=pe;pe&&console.log(`${o} starting... (I: c7e4cb759789ece0a8189d7dfb4d2a24)`);let s;return new Promise((a,i)=>{try{if(!r)throw new Error("(UNEXPECTED) dbName falsy? (E: ed336d88c9c4e8d4916b29356dc58324)");if(!t)throw new Error("(UNEXPECTED) storeName falsy? (E: ad493bb79b63a192524b14c59a706524)");if(!e)throw new Error("(UNEXPECTED) pathToRm falsy? (E: 88c9631d93467e17996946882254af24)");let c=indexedDB.open(r);c.onerror=()=>{debugger;c.result&&c.result.close(),console.error(`${o}[openDBRequest.onerror] ${m(c.error)} (E: 4c5ab71a765e61b4292008fd4fafe324)`),i(c.error)},c.onsuccess=()=>{s=c.result;let d=s.transaction(t,"readwrite").objectStore(t),b=IDBKeyRange.lowerBound(e),u=d.openCursor(b);u.onerror=()=>{debugger;console.error(`${o}[openCursorRequest.onerror] ${m(u.error)} (E: caefdda2bb95f92e9fb8d89ee412b524)`),i(u.error)},u.onsuccess=()=>{try{let p=0,g=u.result;if(g)if(g.key.toString().startsWith(e)){let h=g.delete();p++,h.onerror=()=>{debugger;console.error(`${o}[deleteRequest.onerror] ${m(h.error)} (E: abc031c53e5387322cd8909b3ada9b24)`),i(h.error)},g.continue()}else pe&&console.log(`${o} rmCount: ${p} (I: e4bc613a5514c0942484b79267e16724)`),a();else pe&&console.log(`${o} cursor is falsy, so either we have no more records or had no records to begin with. (I: 9ff3aec6274416501a7baf6dcc5f2624)`),a()}catch(p){console.error(`${o}[openCursorRequest.onsuccess] ${m(p)}`),i(p)}}}}catch(c){debugger;console.error(`${o} ${m(c)}`),i(c)}}).finally(()=>{s&&(pe&&console.log(`${o} closing db ${r}... (I: 39b4ba83de4bdfd541e3384ebab27425)`),s.close(),pe&&console.log(`${o} closing db ${r} complete. (I: e4015b9436c4b2bc0ccf0e11e2037925)`)),pe&&console.log(`${o} complete.`),pe=n})}f(kc,"storageRmRF");async function jc({dbName:r,storeName:t,dirPath:e,withFileTypes:o=!1}){let n=`[${jc.name}]`,s;try{return await new Promise((c,l)=>{let d=indexedDB.open(r);d.onerror=()=>{debugger;l(d.error)},d.onsuccess=()=>{s=d.result;let u=s.transaction(t,"readonly").objectStore(t),p=e.endsWith("/")?e:e+"/",g=IDBKeyRange.lowerBound(p),h=u.openCursor(g),E=new Set,$=[];h.onerror=()=>{debugger;console.error(`${n}[openCursorRequest.onerror] ${m(h.error)}`),l(h.error)},h.onsuccess=()=>{try{let I=h.result;if(I){let A=I.key.toString();if(A.startsWith(p)&&A!==p){let w=A.substring(p.length),_=w.split("/")[0];if(o){let S=w.substring(_.length).startsWith("/");$.push({name:_,isDirectory:f(()=>S,"isDirectory"),isFile:f(()=>!S,"isFile"),isBlockDevice:f(()=>!1,"isBlockDevice"),isCharacterDevice:f(()=>!1,"isCharacterDevice"),isSymbolicLink:f(()=>!1,"isSymbolicLink"),isFIFO:f(()=>!1,"isFIFO"),isSocket:f(()=>!1,"isSocket")})}else E.add(_);I.continue()}else A.startsWith(p)?I.continue():c(o?$:Array.from(E))}else c(o?$:Array.from(E))}catch(I){console.error(`${n}[openCursorRequest.onsuccess] ${m(I)}`),l(I)}}}})}catch(a){throw console.error(`${n} ${m(a)}`),a}finally{s&&(pe&&console.log(`${n} closing db ${r}... (I: 39b4ba83de4bdfd541e3384ebab27425)`),s.close(),pe&&console.log(`${n} closing db ${r} complete. (I: e4015b9436c4b2bc0ccf0e11e2037925)`))}}f(jc,"storageReaddir");var Dt=sa;async function Bc(r){let t=`[${Bc.name}]`;try{Dt&&console.log(`${t} starting... (I: 1905af1827a34ca8a5507fe0c5085b01)`),await ln({infos:[{dbName:r.dbName,storeNames:[r.storeName,...r.additionalStoreNames??[]]}]})}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{Dt&&console.log(`${t} complete.`)}}f(Bc,"initIbGibStorage");function Ia(r){let t=`[${Ia.name}]`;try{Dt&&console.log(`${t} starting... (I: 7be20d161bb14a498c44a42d3193bec1)`),globalThis.ibgib||(globalThis.ibgib={dbName_hack:r.dbName,apiKeyName_hack:r.apiKeyName,storeName_hack:r.storeName}),globalThis.ibgib.spaceGib||(globalThis.ibgib.spaceGib={version:aa,spaceShim:{},fnDefaultGetAPIKey:f(async()=>await Ur({dbName:r.dbName,storeName:r.storeName,key:r.apiKeyName})??"","fnDefaultGetAPIKey"),dbName_hack:r.dbName,apiKeyName_hack:r.apiKeyName,storeName_hack:r.storeName})}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{Dt&&console.log(`${t} complete.`)}}f(Ia,"initIbGibGlobalThis");function Lh(r){if(!globalThis.ibgib?.spaceGib){if(!r)throw new Error("Global context not initialized and config not provided.");Ia(r)}return globalThis.ibgib.spaceGib}f(Lh,"getIbGibGlobalThis_SpaceGib");async function Fc(r){let t=`[${Fc.name}]`;try{Dt&&console.log(`${t} starting... (I: 3123b18eb29b480bad056a9a029b9ad4)`),await(await import(r)).bootstrapSpaceGibApp()}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{Dt&&console.log(`${t} complete.`)}}f(Fc,"dynamicallyLoadBootstrapScript");var j=!1;async function Zt({ibGib:r,ibGibs:t,ibGibAddr:e,ibGibAddrs:o,live:n,gotten:s,tjpAddrsAlreadyAnalyzed:a,skipAddrs:i,skipRel8nNames:c,onlyRel8nNames:l,maxRetries:d,msBetweenRetries:b,space:u,spaces:p,timeLogName:g,mapTjpAddrToLatestAddrsInSpace:h}){let E=`[${Zt.name}]`;try{j&&console.log(`${E} starting... (I: c2a4426c22e849611ca0cedabe683a22)`);let $=await Qt({ibGib:r,ibGibs:t,ibGibAddr:e,ibGibAddrs:o,live:n,gotten:s,tjpAddrsAlreadyAnalyzed:a,skipAddrs:i,skipRel8nNames:c,onlyRel8nNames:l,maxRetries:d,msBetweenRetries:b,space:u,spaces:p,timeLogName:g,mapTjpAddrToLatestAddrsInSpace:h});if(Object.values($).filter(I=>I.ib.startsWith("comment ")).forEach(I=>{console.table(I)}),j){console.log(`${E} graph size: ${Object.keys($).length} (I: c6cb5e7e1e2611d35b9006fac6503d22)`);let I=Object.values($).filter(A=>A.ib.startsWith("comment ")||A.ib.startsWith("pic ")).map(A=>A.ib);lr(I).forEach(A=>console.log(A))}return $}catch($){throw console.error(`${E} ${$.message}`),$}finally{j&&console.log(`${E} complete.`)}}f(Zt,"getDependencyGraph");async function _a({ibGib:r,ibGibs:t,ibGibAddr:e,ibGibAddrs:o,live:n,gotten:s,tjpAddrsAlreadyAnalyzed:a,skipAddrs:i,skipRel8nNames:c,onlyRel8nNames:l,maxRetries:d,msBetweenRetries:b,space:u,spaces:p,timeLogName:g,mapTjpAddrToLatestAddrsInSpace:h}){let E=`[${_a.name}]`;try{if(j&&console.log(`${E} starting... (I: bd6807477f679345df9dddefe0b4e922)`),u&&(p??[]).length>0)throw new Error("space and spaces parameters are mutually exclusive. Pass either space or spaces, not both. (E: 994a5323e4214f4e95d5bb2b89f89090)");let $=u?[u]:(p??[]).filter(I=>!!I);if($.length===0)throw new Error("space or spaces required. (E: 9f38166ab70340cb919174f8d26af909)");if(!r&&!e&&(t??[]).length===0&&(o??[]).length===0)throw new Error("either ibGib/s or ibGibAddr/s required. (E: b6d08699651f455697f0d05a41edb039)");return c=c||[],i=i||[],s=s||{},a=a||[],o=(o??[]).filter(I=>!Z({gib:P({ibGibAddr:I}).gib})).filter(I=>!i.includes(I)),t=(t??[]).filter(I=>!Z({ibGib:I})).filter(I=>!i.includes(y({ibGib:I}))),r&&!Z({ibGib:r})&&!t.some(I=>I.gib===r.gib)&&!i.includes(y({ibGib:r}))&&t.push(r),e&&!Z({gib:P({ibGibAddr:e}).gib})&&!o.includes(e)&&!i.includes(e)&&o.push(e),{ibGib:r,ibGibs:t,ibGibAddr:e,ibGibAddrs:o,live:n,gotten:s,tjpAddrsAlreadyAnalyzed:a,skipAddrs:i,skipRel8nNames:c,onlyRel8nNames:l,maxRetries:d,msBetweenRetries:b,space:void 0,spaces:$,timeLogName:g,mapTjpAddrToLatestAddrsInSpace:h}}catch($){throw console.error(`${E} ${$.message}`),$}finally{j&&console.log(`${E} complete.`)}}f(_a,"getGraphProjection_initializeOpts");async function bn({ibGibs:r,ibGibAddrs:t,gotten:e,skipAddrs:o,maxRetries:n,msBetweenRetries:s,timeLogName:a,space:i,spaces:c}){let l=`[${bn.name}]`;try{j&&console.log(`${l} starting... (I: 67b2be37ff24393fff56e229304da122)`);let d=c??(i?[i]:[]);if(d.length===0)throw new Error("(UNEXPECTED) spaces empty? (E: aa9f657695717034b3581066932d7d23)");let b=[];r??=[],t??=[],o??=[],e??={};let u=[],p=Object.keys(e??{}),g=r.map(h=>y({ibGib:h}));for(let h=0;h<t.length;h++){let E=t[h];o.includes(E)||g.includes(E)||(p.includes(E)?b.push(e[E]):u.push(t[h]))}if(j&&console.log(`${l}[analyze debugging] addrsToGetFromSpace (${u.length}):
|
|
11
|
+
`),uo=document.getElementById("fullscreen-dialog-animation-emoji");q.forEach(Ue=>{let Pt=document.createElement("p");Pt.textContent=Ue,uo?g.insertBefore(Pt,uo):g.appendChild(Pt)})}if(ie!==void 0){let q=document.getElementById("fullscreen-dialog-animation-emoji");ie?(q||(q=document.createElement("div"),q.id="fullscreen-dialog-animation-emoji",q.style.fontSize="3.5rem",q.style.textAlign="center",q.style.margin="1.5rem 0",q.style.animation="spin-bounce 5s infinite ease-in-out",g.appendChild(q)),q.textContent=ie):q&&q.remove()}},"update");b.open||b.showModal(),le(1e3).then(()=>{u.scrollTo({top:0,behavior:"smooth"})}),w({close:x,update:N});return}let _=f(()=>{(e||o)&&h.removeEventListener("keypress",A),E.removeEventListener("click",S),$.removeEventListener("click",G),b.removeEventListener("close",O)},"removeEventListeners"),S=f(()=>{_();let U=o?h.value??"":"true";h&&(h.value=""),b.close(U),w(U)},"onOK"),G=f(()=>{_(),h&&(h.value=""),b.close(void 0),w(void 0)},"onCancel"),O=f(()=>{_(),h&&(h.value=""),b.close(void 0),w(void 0)},"onClose");E.addEventListener("click",S),$.addEventListener("click",G),b.addEventListener("close",O),b.open||b.showModal(),le(1e3).then(()=>{u.scrollTo({top:0,behavior:"smooth"})})})}catch(b){throw console.error(`${d} ${m(b)}`),b}finally{ha&&console.log(`${d} complete.`)}}f(Ot,"showFullscreenDialog");var te=et;async function Sc({metaspace:r,space:t}){let e=`[${Sc.name}]`;try{te&&console.log(`${e} starting... (I: 2ccb79537a75e7896bace84e6c710d25)`);let o=await r.getSpecialIbGib({type:pr.tags,space:t});if(!o)throw new Error(`tagsIbGib not found in metaspace. space: ${t?t.ib:"default local user space"} (E: 4734c510a411274315c0add8f70e1925)`);return o}catch(o){throw console.error(`${e} ${m(o)}`),o}finally{te&&console.log(`${e} complete.`)}}f(Sc,"getTagsIbGib");function cn({scope:r,ibGib:t,ibGibAddr:e,defaultNameIfError:o}){let n=`[${cn.name}]`;try{if(!t&&!e)throw new Error(`${n} Must provide either ibGib or ibGibAddr. (E: genuuid)`);r.includes(" ")&&(console.warn(`${n} scope includes one or more spaces. These will be converted to double underscores. (W: 1554a81454e8ae0a6858ea5dd17f8925)`),r=r.replace(/ /g,"__"));let s,a,i;if(t){if(!t.data)throw new Error("(UNEXPECTED) ibGib.data falsy? (E: genuuid)");if(!t.rel8ns)throw new Error("(UNEXPECTED) ibGib.rel8ns falsy? (E: genuuid)");if(!t.rel8ns.ancestor)throw new Error("(UNEXPECTED) ibGib.rel8ns.ancestor falsy? (E: genuuid)");if(t.rel8ns.ancestor.length===0)throw new Error("(UNEXPECTED) ibGib.rel8ns.ancestor.length === 0? there should be at least one ancestor (E: genuuid)");if(t&&e&&y({ibGib:t})!==e)throw new Error("(UNEXPECTED) both ibGib and ibGibAddr provided, but addr of ibGib doesn't equal ibGibAddr? (E: genuuid)");let d=t.rel8ns.ancestor.filter(u=>Z({gib:C({ibGibAddr:u}).gib}));if(d.length===0){debugger;console.error(`${n} ibGib has no primitive ancestor addrs? Still going to work off of the ib then, which should have the atom as the first space-delimited term. (E: genuuid)`)}let b=d.at(-1);s=C({ibGibAddr:b}).ib,i=s}e??=y({ibGib:t});let{ib:c}=C({ibGibAddr:e});if(a=c.split(" ").at(0)??"",a=a.replace(/\W/g,"_"),s??=a,s=s.replace(/\W/g,"_"),!s&&!a)throw new Error("(UNEXPECTED) both primitiveAncestorIb and atom falsy? one should be truthy at this point. (E: genuuid)");i=a.toLowerCase(),te&&console.log(`${n} ancestorIbOrAtom: ${i} (I: genuuid)`);let l=`${i}_${r}index`;return te&&console.log(`${n} indexName: ${l} (I: genuuid)`),l}catch(s){if(o)return console.warn(`${n} error happened but defaultNameIfError (${o}) provided. So will return this value. error that was thrown: ${m(s)}`),o;throw console.error(`${n} ${m(s)}`),s}}f(cn,"getIndexNameFromIbGib");async function xc({scope:r,ibGib:t,metaspace:e,space:o,skipGetLatest:n}){let s=`[${xc.name}]`;try{if(te&&console.log(`${s} starting... (I: f19dc86aab380fe809aef27ccc7a7425)`),!r)throw new Error("scope required to be a non-empty string (E: 73e702495c38c7d8747d1cf8850af825)");if(!t)throw new Error("ibGib required (E: genuuid)");let a=cn({scope:r,ibGib:t}),i=ue({ibGib:t,defaultIfNone:"incomingAddr"}),c=f(async()=>{let d=await e.getSpecialIbGib({type:a,space:o,initialize:!1,dontWarnIfNotExist:!0,lock:!0});if(!d||!d.data){te&&console.log(`${s} special ${r} index ibGib not found for indexSpecialIbGibType (${a}). No coupled ibgib registered, returning undefined. (I: genuuid)`);return}let u=(d.data.coupleMap??d.data.agentMap??{})[i];if(!u){te&&console.log(`${s} No coupled ${r} ibgib address found for domain ${i} in the coupled index map. indexSpecialIbGibType: ${a}. returning undefined. (I: genuuid)`);return}let p=n?u:await e.getLatestAddr({addr:u,space:o})??u,g=await e.get({addrs:[p],space:o});if(g.errorMsg||(g.ibGibs??[]).length!==1)throw new Error(`couldn't get latest coupled ibgib (${p}) for domain ${i}. (E: 8aa7b25f5cd4ebadd8bf2f8807dfe825)`);return g.ibGibs[0]},"fn");return await Ae({scope:a,secondsValid:180,maxDelayMs:100,maxLockAttempts:1800,space:o,callerInstanceId:s+ge(),fn:c})}catch(a){throw console.error(`${s} ${m(a)}`),a}finally{te&&console.log(`${s} complete.`)}}f(xc,"getLocalCoupledIbGibForDomainIbGib");async function Oc({scope:r,domainIbGib:t,localIbGib:e,metaspace:o,space:n}){let s=`[${Oc.name}]`;try{te&&console.log(`${s} starting... (I: 217ae68e0c820e48f4c00409f7f14325)`);let a=cn({scope:r,ibGib:t}),i=ue({ibGib:t}),c=y({ibGib:e});if(!i)throw new Error(`${s} Could not get TJP address for domain ibGib. (E: 35a4e8ac291b0b85cb958e28dd812f25)`);if(!c)throw new Error(`${s} Could not get address for agent ibGib. (E: 2fce1187630b45934c4155a23204d125)`);await Ae({scope:a,secondsValid:60,maxDelayMs:100,maxLockAttempts:600,space:n,fn:f(async()=>{let d=await o.getSpecialIbGib({type:a,space:n,initialize:!0,dontWarnIfNotExist:!0,lock:!1});if(!d)throw new Error(`${s} Could not get or create agent index ibGib.`);if(!d.data)throw new Error("(UNEXPECTED) agentSpecialIndex.data falsy? (E: 74299eed147debf6398ca37e7b8d5c25)");let b=d.data.coupleMap??d.data.agentMap,u=b?v(b):{},p=u[i];if(p)if(p===c){te&&console.log(`${s} domain ibGib (${i}) already mapped to agent (${c}). returning early (I: cb5d4dcef8cf14de7336120fb8ffef25)`);return}else console.warn(`${s} domainTjpAddr (${i}) already assigned to existingMappedAgentAddr (${p}). We will be changing to new localAddr (${c}). (W: eb993e33f7731e570fa76f24a2d80625)`);u[i]=c;let g=await Me({src:d,dataToAddOrPatch:{coupleMap:u},dna:!1,linkedRel8ns:[K.past],nCounter:!0}),h=g.newIbGib;await ee({resTransform:g,space:n});let E=Q({type:a});await o.setConfigAddr({key:E,addr:y({ibGib:h}),space:n}),await o.registerNewIbGib({ibGib:h,space:n})},"fn")}),te&&console.log(`${s} Registered domain ${i} with agent ${c}`)}catch(a){throw console.error(`${s} ${m(a)}`),a}finally{te&&console.log(`${s} complete.`)}}f(Oc,"coupleDomainIbGibWithLocalIbGibViaIndex");function bt(){let r=`[${bt.name}]`;try{te&&console.log(`${r} starting... (I: 890f53e984d69461d9f4ded8741fcc25)`);let t=globalThis[rn];return t||(console.log(`${r} initializing globalThis.${rn}... (I: 9d9ff1813448d9a1b82b0e5790a74825)`),t={}),t}catch(t){throw console.error(`${r} ${m(t)}`),t}finally{te&&console.log(`${r} complete.`)}}f(bt,"getIbGibGlobalThis_IbGib");async function Ea({delayIntervalMs:r=50}={delayIntervalMs:50}){let t=`[${Ea.name}]`;try{te&&console.log(`${t} starting... (I: 4acc22d08dd1100503f9b0423f302925)`);let e;for(;!e;)bt().metaspace&&(e=bt().metaspace),e||(console.log(`${t} metaspace still not initialized. delayIntervalMs: ${r} until next retry... (I: 490f77ac4ded1d7d3c0340e460404125)`),await le(r));return e}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{te&&console.log(`${t} complete.`)}}f(Ea,"getGlobalMetaspace_waitIfNeeded");function Dc({ibGibAddr:r,gib:t,ibGib:e,translucentAlpha:o=10}){let n=`[${Dc.name}]`;try{te&&console.log(`${n} starting... (I: 3b70af42d1c4f6ae91870f3a15c6c625)`),!r&&!t&&!e&&(t=L),t??=e?.gib??C({ibGibAddr:r}).gib;let s=re({gib:t});o??=10;let a="";if(s.isPrimitive)return{gib:t,gibInfo:s,punctiliarColor:ia,punctiliarColorTranslucent:ca,punctiliarColorContrast:la};a=s.tjpGib??s.punctiliarHash??t;let[i,c,l]=ga(o,s.punctiliarHash??t),[d,b,u]=s.tjpGib?ga(o,s.tjpGib):[void 0,void 0,void 0];return{gib:t,gibInfo:s,punctiliarColor:i,punctiliarColorTranslucent:c,punctiliarColorContrast:l,tjpColor:d,tjpColorTranslucent:b,tjpColorContrast:u}}catch(s){let a=`${n} ${m(s)}`;return console.error(a),{gib:t??L,gibInfo:{isPrimitive:!0},punctiliarColor:"#ff0000",punctiliarColorTranslucent:"#ff000010",punctiliarColorContrast:"#ffffff",errorMsg:a}}finally{te&&console.log(`${n} complete.`)}}f(Dc,"getDeterministicColorInfo");function vc(r,t,e){e/=100;let o=t*Math.min(e,1-e)/100,n=f(s=>{let a=(s+r/30)%12,i=e-o*Math.max(Math.min(a-3,9-a,1),-1);return Math.round(255*i).toString(16).padStart(2,"0")},"f");return`#${n(0)}${n(8)}${n(4)}`}f(vc,"hslToHex");function ga(r,t){let o=(parseInt(t.substring(0,8),16)||0)%360,n=vc(o,65,62),s=parseInt(n.substring(1,3),16),a=parseInt(n.substring(3,5),16),i=parseInt(n.substring(5,7),16),l=(s*299+a*587+i*114)/1e3>=128?"#11111b":"#ffffff",d=Math.min(100,Math.max(0,r)),b=Math.round(d/100*255).toString(16).padStart(2,"0"),u=`${n}${b}`;return[n,u,l]}f(ga,"getColorStrings");var fe=et;function wa(r){return new TextDecoder().decode(r)}f(wa,"uint8ArrayToString");var ma=class r{static{f(this,"PathUtilsHelper")}lc=`[${r.name}]`;constructor(){}isAbsolute(t){if(!t)throw new Error("(UNEXPECTED) path falsy? (E: dcb92e11770ba06205c0afe3e6560b24)");return t.startsWith("/")}isRelative(t){return!this.isAbsolute(t)}join(...t){let e=`${this.lc}[${this.join.name}]`;if(t.length===0)return console.log(`${e} paths.length === 0. returning '.' per node convention. (I: 153da80765ff6160675fae895ebac225)`),".";if(t.length===1&&t[0]==="..")return console.log(`${e} paths.length === 1 && paths[0] === '..'. returning '..' per node convention. (I: 9af242b7615430a8c6899b1a332e9925)`),"..";let o="";for(let n=0;n<t.length;n++){let s=t[n];s===".."?o=o.split("/").slice(0,-1).join("/"):(s.startsWith("/")&&(s=s.slice(1)),s.endsWith("/")&&(s=s.slice(0,-1)),o+=(n>0?"/":"")+s)}return o}dirname(t){return t.split("/").slice(0,-1).join("/")}basename(t,e){return t.split("/").pop()??""}};async function Nc({msg:r,title:t,confirm:e,noNewLine:o,rl:n,defaultValue:s,dontCloseRl:a,cancelable:i}){let c=`[${Nc.name}]`;try{if(!r)throw new Error("msg required (E: 7f4d67bca4cf98ea95fa110aabc98924)");let l,d=0,b=5;do{if(d++,d>=b)throw new Error("max attempts reached (E: 1ef20ae955622d4b39479f3da91a1d25)");await le(50),l=await Ot({title:t||"Prompt for Info",msg:r,prompt:!0,showInput:!0,isPassword:!1,defaultValue:s})}while(l===void 0&&!i);return l??""}catch(l){debugger;throw console.error(`${c} ${m(l)}`),l}}f(Nc,"promptForText");async function Lc({msg:r,confirm:t}){let e=`[${Lc.name}]`;try{fe&&console.log(`${e} starting... (I: 795a4ce348ddb9a5119770f4c572ac24)`);let o,n=!0,s=0,a=5;do{if(s++,s>=a)throw new Error("max attempts reached (E: d4166b4bf37aff0c6d44567792e9ad25)");if(await le(50),o=await Ot({title:n?"Shh...":"Secrets didn't match, try again...",msg:r||"Enter Your Secret...",prompt:!0,showInput:!0,isPassword:!0,defaultValue:void 0}),o===void 0)throw new Error("user cancelled (E: 91519d04378e84106f3df8eb36d99725)");if(t){await le(250);let i=await Ot({title:"Shh...",msg:"Confirm...",prompt:!0,showInput:!0,isPassword:!0,defaultValue:void 0});i===void 0&&(o=void 0),o!==i&&(o=void 0,n=!1,await le(250))}}while(o===void 0);return o}catch(o){throw console.error(`${e} ${m(o)}`),o}finally{fe&&console.log(`${e} complete.`)}}f(Lc,"promptForSecret");async function Cc({msg:r,title:t,skipHitEnterToContinue:e}){let o=`[${Cc.name}]`;try{if(!r)throw new Error("msg required (E: ffcf7dd00324df7cea2792223d229524)");try{t??="",await le(50),await Ot({title:t,msg:r})}catch(n){throw n}}catch(n){throw console.error(`${o} ${m(n)}`),n}}f(Cc,"alertUser");async function Pc({exportIbGibJsonString:r,metaspace:t}){let e=`[${Pc.name}]`;try{debugger;if(fe&&console.log(`${e} starting... (I: genuuid)`),!t)throw new Error("(UNEXPECTED) metaspace falsy? (E: genuuid)");if(!await t.getLocalUserSpace({lock:!1}))throw new Error("(UNEXPECTED) couldn't get default local user space? (E: genuuid)");let n,s;try{n=JSON.parse(r)}catch(l){let d=`Error during parse JSON. error: ${m(l)} (E: genuuid)`,b=new Error(d);throw b.cause=l,b}try{let l=await oe({ibGib:n})??[];if(l.length>0)throw new Error(`validation errors when validating the parsed ibgib that should be a RawExportIbGib_V1: ${l} (E: 8ba178d3b26e8eca28a67c182fe16825)`);if(s=n,!s.data)throw new Error("(UNEXPECTED) rawExportIbGib.data falsy? (E: ef1824d1cca5584ab8e34288346e9825)")}catch(l){let d=`Error during parse JSON. error: ${m(l)} (E: genuuid)`,b=new Error(d);throw b.cause=l,b}let a;if(s.data.compression)switch(s.data.compression){case"gzip":a=await nn({compressedBase64:s.data.dependencyGraphAsString});break;default:throw new Error(`unknown value of rawExportIbGib.data.compression: ${s.data.compression} (E: 784672fae568312d887ddbb841199925)`)}else a=await Rr({jsonString:s.data.dependencyGraphAsString});let i={};for(let[l,d]of Object.entries(a)){let b=await oe({ibGib:d})??[];b.length>0&&(i[l]=b)}if(Object.keys(i).length>0)throw new Error(`there were validation errors for the RawExportIbGib_V1.data payload (contained in data.dependencyGraphAsString). Here is the validationErrorMap:
|
|
12
|
+
${H({validationErrorMap:i})} (E: e63f38b182a84122d83a55befb369825)`);return[s,a]}catch(o){throw console.error(`${e} ${m(o)}`),o}finally{fe&&console.log(`${e} complete.`)}}f(Pc,"getRawExportIbGibAndGraphFromJsonString");async function Rc({ibGib:r,compress:t,metaspace:e,space:o}){let n=`[${Rc.name}]`;try{if(fe&&console.log(`${n} starting... (I: 623d9463d919683be81f749821a95825)`),Z({ibGib:r}))throw new Error("ibGib is primitive. Can't export primitive. (E: dd42c42e9fda0707e81c692af1a2a225)");let s=await sn({ibGib:r,live:!0,compress:t,metaspace:e,space:o}),{rawExportIbGib:a,errors:i}=s;if((i??[]).length>0)throw new Error(`Export had errors: ${i} (E: 05faf83f25d3449ab809dfd24eeaf825)`);let c=JSON.stringify(a),l="data:text/json;charset=utf-8,"+encodeURIComponent(c),b=`${y({ibGib:a})}.json`,u=document.createElement("a");u.setAttribute("style","none"),u.setAttribute("href",l),u.setAttribute("download",b);let p=document.getElementsByTagName("div")[0];p.appendChild(u),u.click(),p.removeChild(u)}catch(s){throw console.error(`${n} ${m(s)}`),s}finally{fe&&console.log(`${n} complete.`)}}f(Rc,"exportIbGib");function $a({id:r,shadowRoot:t}){let e=`[${$a.name}]`;try{fe&&console.log(`${e} starting... (I: 18a338c6dab8690c72b8759b8d952925)`);let o=t?t.getElementById(r):document.getElementById(r);if(o)return o;throw new Error(`${t?"shadowRoot":"document"}.getElementById(${r}) returned null. So...Element was not found. (E: 5e501f6835cc74cd4c2faf0d9e387825)`)}catch(o){throw console.error(`${e} ${m(o)}`),o}finally{fe&&console.log(`${e} complete.`)}}f($a,"getElementById_throwsIfFalsy");function $h(r,t){return $a({id:t,shadowRoot:r})}f($h,"shadowRoot_getElementById");function Uc(){let r=`[${Uc.name}]`;try{fe&&console.log(`${r} starting... (I: 62a29f9982b4b5ecd91ff58ca4dd6825)`);let t=bt();if(!t.storeName_hack)throw new Error("(UNEXPECTED) global store name falsy? (E: 3b9b680f6a980debbb877c9a13fb2625)");return t.storeName_hack}catch(t){throw console.error(`${r} ${m(t)}`),t}finally{fe&&console.log(`${r} complete.`)}}f(Uc,"getGlobalStoreName");function Mc(){let r=`[${Mc.name}]`;try{fe&&console.log(`${r} starting... (I: 8c8f08728fc7384f87697377358cc825)`);let t=bt();if(!t.dbName_hack)throw new Error("(UNEXPECTED) global db name falsy? (E: 3aa028d5e4088f3f3841aae94ac02825)");return t.dbName_hack}catch(t){throw console.error(`${r} ${m(t)}`),t}finally{fe&&console.log(`${r} complete.`)}}f(Mc,"getGlobalDbName");function kc(){let r=`[${kc.name}]`;try{fe&&console.log(`${r} starting... (I: 59a2510a85051f97ed15fbc8825b6825)`);let t=bt();if(!t.apiKeyName_hack)throw new Error("(UNEXPECTED) global api key name falsy? (E: 1782e812f0c87f54b8059468a5b60125)");return t.apiKeyName_hack}catch(t){throw console.error(`${r} ${m(t)}`),t}finally{fe&&console.log(`${r} complete.`)}}f(kc,"getGlobalIndexedDbKey_APIKey");async function ln({infos:r}){let t=`[${ln.name}]`;try{fe&&console.log(`${t} starting... (I: 4d41880fb748ee2302a624a255665825)`);for(let e of r){let{dbName:o,storeNames:n}=e;await fn({dbName:o})||await Mr({dbName:o});for(let a of n)await dn({dbName:o,storeName:a})}}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{fe&&console.log(`${t} complete.`)}}f(ln,"initAppStorage");var pe=et,ya=0;async function Mr({dbName:r,storeName:t,version:e,logalot:o=!1}){let n=`[${Mr.name}][${r}][${t??"no store name"}]`,s=crypto.randomUUID();o&&console.time(n+s);let a;try{o&&console.log(`${n} starting... (I: f35d4e1ba37252f14c8532fb861b1125)`),await new Promise((c,l)=>{try{o&&console.log(`${n} starting... (I: 0aeddd9376daa0a044677ce4cf8a4c24)`),o&&console.timeLog(n+s,"opening... (I: e748b4ddb445d77cb10a7ba158b49125)");let d=indexedDB.open(r,e);ya++,console.log(`${n} initRequestCount: ${ya} (I: 294d5f0b12ffe5512bacebe891824d25)`);let b;d.onupgradeneeded=u=>{try{a=u.target.result,o&&console.timeLog(n+s,"onupgradeneeded... (I: e748b4ddb445d77cb10a7ba158b49125)"),t&&(a.objectStoreNames.contains(t)?b=!0:(b=!1,a.createObjectStore(t,{keyPath:"key"})))}catch(p){console.error(`${n}[openDBRequest.onupgradeneeded] ${m(p)} (E: 4a5fa1b0850be47e28bee653da287325)`),l(p)}},d.onblocked=u=>{console.log(`${n}[openDBRequest.onblocked] openDBRequest blocked...time wasted a bit here. version change event (old -> new): ${u.oldVersion} -> ${u.newVersion} (I: 9074ebf4afdba54d6f9d41b360b96a25)`),console.dir(u)},d.onsuccess=u=>{try{o&&console.log("init success (I: 297a5a71e405a0b56413af813f248d24)"),o&&console.timeLog(n+s,"onupgradeneeded... (I: e748b4ddb445d77cb10a7ba158b49125)"),a=u.target.result,t&&(b??=a.objectStoreNames.contains(t),o&&console.log(`${n} ${r} store "${t}" ${b?"already exists":"does not exist"}. (I: db64712bc69c5287b1cf77af1fc13d24)`)),c()}catch(p){console.error(`${n}[openDBRequest.onsuccess] ${m(p)}`),l(p)}},d.onerror=u=>{debugger;console.error(`${n}[initRequest.onerror] ${m(d.error)} (E: 74cf09e9fba2dd9e41225e943c331124)`),l(d.error)}}catch(d){console.error(`${n} ${m(d)}`);debugger;l(d)}finally{o&&console.log(`${n} complete.`)}})}catch(i){throw console.error(`${n} ${m(i)}`),i}finally{a&&(o&&console.log(`${n} closing db ${r}... (I: 3f1c18eec567ea63f3927eef0f038925)`),a.close(),o&&(console.log(`${n} closing db ${r} complete. (I: bc3b2f504245d6203dbba6bd65d30325)`),console.timeLog(n+s,"db closed. (I: e748b4ddb445d77cb10a7ba158b49125)"))),o&&(console.log(`${n} complete.`),console.timeEnd(n+s))}}f(Mr,"initializeStorage");async function Ia({dbName:r,logalot:t=!1}){let e=`[${Ia.name}]`,o=crypto.randomUUID();t&&console.time(e+o);try{return t&&console.log(`${e} starting... (I: 8516795b20529d19eb6923defd7a0f24)`),(await indexedDB.databases()).filter(s=>s.name===r).at(0)}catch(n){console.error(`${e} ${m(n)}`)}finally{t&&console.timeEnd(e+o),t&&console.log(`${e} complete.`)}}f(Ia,"storageGetDBInfo");async function dn({dbName:r,storeName:t,logalot:e=!1}){let o=`[${dn.name}]`,n=crypto.randomUUID();e&&console.time(o+n);let s;try{if(e&&console.log(`${o} starting... (I: 029f7caa8ea5ea08a865f3924c82b624)`),!(await indexedDB.databases()).filter(b=>b.name===r).at(0))throw new Error(`db (${r}) does not exist. can't create store (${t}) (E: 5b15f7aed6f7068d077b2c7ebcbe8524)`);let i=!1;if(e&&console.timeLog(o+n),await new Promise((b,u)=>{let p=indexedDB.open(r);p.onsuccess=g=>{s=g.target.result,i=s.objectStoreNames?.contains(t),e&&console.timeLog(o+n,"open db request"),b()},p.onerror=g=>{debugger;console.error(`${o}[openDBRequest.onerror] ${m(p.error)} (E: 63695744e9e59ff8019e04ceeb8e2524)`),u(p.error)}}),e&&console.timeLog(o+n),i){e&&console.log(`${o} store ${t} already existed. (I: a2263b510c18240fc59fca54e3892324)`);return}let c=await Ia({dbName:r,logalot:e});if(e&&console.timeLog(o+n,"storageGetDBInfo complete"),!c)throw new Error(`db (${r}) does not exist. can't create store (${t}) (E: c771db13fa28f67079aad45e1ab7e624)`);let l=c.version;if(!l)throw new Error(`db (${r}) has no version. can't create store (${t}) (E: 3d2ec52853ad99f92b19ac5aa7fbfe24)`);let d=l+1;if(e&&console.log(`${o} creating store ${t} with version ${d} (I: 312b79f28243c650cf38935114f21e24)`),s)s.close(),s=void 0;else throw new Error("(UNEXPECTED) how did we get here with db falsy? (E: b561784879e19bac54b1c4936aff0c25)");await Mr({dbName:r,storeName:t,version:d,logalot:e})}catch(a){throw console.error(`${o} ${m(a)}`),a}finally{s&&(e&&console.log(`${o} closing db ${r}... (I: 3f1c18eec567ea63f3927eef0f038925)`),s.close(),e&&console.log(`${o} closing db ${r} complete. (I: bc3b2f504245d6203dbba6bd65d30325)`)),e&&console.timeLog(o+n),e&&console.log(`${o} complete.`)}}f(dn,"storageCreateStoreIfNotExist");async function an({dbName:r,version:t,storeName:e,key:o,value:n,logalot:s=!1}){let a=`[${an.name}]`,i;try{s&&console.log(`${a} starting... (I: bf7316c244888cb8ead2d3aac1d9f625)`),await new Promise((l,d)=>{try{s&&console.log(`${a} starting... (I: 81df59e3961d711ce5d8f2ae3e2f3824)`);let b=indexedDB.open(r,t);b.onsuccess=u=>{i=u.target.result;try{let p=i.transaction(e,"readwrite").objectStore(e),g={key:o,value:n};p.put(g),l()}catch(p){console.error(`${a}[putRequest.onsuccess] ${m(p)}`),d(p)}},b.onerror=u=>{debugger;console.error(`${a}[putRequest.onerror] ${m(b.error)} (E: 7a946d99ede2b248df4dcfea4ac99724)`),d(b.error)}}catch(b){console.error(`${a} ${m(b)}`),d(b)}finally{s&&console.log(`${a} complete.`)}})}catch(c){throw console.error(`${a} ${m(c)}`),c}finally{i&&(s&&console.log(`${a} closing db ${r}... (I: 438c6edced94b83a3478c71b08c6c325)`),i.close(),s&&console.log(`${a} closing db ${r} complete. (I: 0d081553b1eb53c65ade2cedb802cf25)`)),s&&console.log(`${a} complete.`)}}f(an,"storagePut");async function Ur({dbName:r,version:t,storeName:e,key:o,logalot:n=!1}){let s=`[${Ur.name}]`,a;try{return n&&console.log(`${s} starting... (I: f8ba7cd5801918a8580e91b7c90aa525)`),await new Promise((l,d)=>{try{n&&console.log(`${s} starting... (I: 24163c4a11c8712097db45febaf9c724)`);let b=indexedDB.open(r,t);b.onsuccess=u=>{a=u.target.result;let p;try{p=a.transaction(e).objectStore(e)}catch(h){debugger;console.error(`${s}[openDBRequest.onsuccess][objectStore] ${m(h)}`),d(h);return}let g=p.get(o);g.onsuccess=h=>{try{let E=h.target?.result?.value??void 0;if(!E){l(E);return}if(n&&console.log("Retrieved value:",E),E instanceof Uint8Array)l(wa(E));else{if(typeof E!="string")throw new Error("(UNEXPECTED) truthy, non-Uint8Array value is not a string? (E: 6a4ec24e2e5d9848f8b542bc2661dc24)");l(E)}}catch(E){d(E)}},g.onerror=h=>{debugger;let E=g.error;console.error(`${s}[openDBRequest.onsuccess][getRequest.onerror] ${m(E)}`),d(E)}},b.onerror=u=>{debugger;console.error(`${s}[openDBRequest.onerror] ${m(b.error)} (E: 074963a908fa9a075f01c73cae829224)`),d(b.error)}}catch(b){console.error(`${s} ${m(b)}`),d(b)}finally{n&&console.log(`${s} complete.`)}})}catch(i){throw console.error(`${s} ${m(i)}`),i}finally{a&&(n&&console.log(`${s} closing db ${r}... (I: a938fc22dfdc76b15f6926bc4d458225)`),a.close(),n&&console.log(`${s} closing db ${r} complete. (I: 18f2ec1557bc83ec4e2c5d5e72264525)`)),n&&console.log(`${s} complete.`)}}f(Ur,"storageGet");async function fn({dbName:r,store:t}){let e=`[${fn.name}]`,o;try{return pe&&console.log(`${e} starting... (I: 2b4373affa3841220f0b7ca690406624)`),(await window.indexedDB.databases()).some(a=>a.name===r)?t?await new Promise((a,i)=>{let c=indexedDB.open(r);c.onsuccess=l=>{o=l.target.result;let d=o.objectStoreNames.contains(t);a(d)},c.onerror=l=>{debugger;o=c.result;let{error:d}=l.target;console.error(`${e}[openDBRequest.onerror] ${m(c.error)} (E: c783fe607451e46c1feae3a81e0f7924)`),i(d)}}):!0:!1}catch(n){throw console.error(`${e} ${m(n)}`),n}finally{o&&(pe&&console.log(`${e} closing db ${r}... (I: 8782d9eea285cf9eb638d493a421a625)`),o.close(),pe&&console.log(`${e} closing db ${r} complete. (I: 76a0c5dea2643e2bb84c82c8446a8125)`)),pe&&console.log(`${e} complete.`)}}f(fn,"storageDBExists");async function jc({dbName:r,storeName:t,pathToRm:e}){let o=`[${jc.name}]`,n=pe;pe&&console.log(`${o} starting... (I: c7e4cb759789ece0a8189d7dfb4d2a24)`);let s;return new Promise((a,i)=>{try{if(!r)throw new Error("(UNEXPECTED) dbName falsy? (E: ed336d88c9c4e8d4916b29356dc58324)");if(!t)throw new Error("(UNEXPECTED) storeName falsy? (E: ad493bb79b63a192524b14c59a706524)");if(!e)throw new Error("(UNEXPECTED) pathToRm falsy? (E: 88c9631d93467e17996946882254af24)");let c=indexedDB.open(r);c.onerror=()=>{debugger;c.result&&c.result.close(),console.error(`${o}[openDBRequest.onerror] ${m(c.error)} (E: 4c5ab71a765e61b4292008fd4fafe324)`),i(c.error)},c.onsuccess=()=>{s=c.result;let d=s.transaction(t,"readwrite").objectStore(t),b=IDBKeyRange.lowerBound(e),u=d.openCursor(b);u.onerror=()=>{debugger;console.error(`${o}[openCursorRequest.onerror] ${m(u.error)} (E: caefdda2bb95f92e9fb8d89ee412b524)`),i(u.error)},u.onsuccess=()=>{try{let p=0,g=u.result;if(g)if(g.key.toString().startsWith(e)){let h=g.delete();p++,h.onerror=()=>{debugger;console.error(`${o}[deleteRequest.onerror] ${m(h.error)} (E: abc031c53e5387322cd8909b3ada9b24)`),i(h.error)},g.continue()}else pe&&console.log(`${o} rmCount: ${p} (I: e4bc613a5514c0942484b79267e16724)`),a();else pe&&console.log(`${o} cursor is falsy, so either we have no more records or had no records to begin with. (I: 9ff3aec6274416501a7baf6dcc5f2624)`),a()}catch(p){console.error(`${o}[openCursorRequest.onsuccess] ${m(p)}`),i(p)}}}}catch(c){debugger;console.error(`${o} ${m(c)}`),i(c)}}).finally(()=>{s&&(pe&&console.log(`${o} closing db ${r}... (I: 39b4ba83de4bdfd541e3384ebab27425)`),s.close(),pe&&console.log(`${o} closing db ${r} complete. (I: e4015b9436c4b2bc0ccf0e11e2037925)`)),pe&&console.log(`${o} complete.`),pe=n})}f(jc,"storageRmRF");async function Bc({dbName:r,storeName:t,dirPath:e,withFileTypes:o=!1}){let n=`[${Bc.name}]`,s;try{return await new Promise((c,l)=>{let d=indexedDB.open(r);d.onerror=()=>{debugger;l(d.error)},d.onsuccess=()=>{s=d.result;let u=s.transaction(t,"readonly").objectStore(t),p=e.endsWith("/")?e:e+"/",g=IDBKeyRange.lowerBound(p),h=u.openCursor(g),E=new Set,$=[];h.onerror=()=>{debugger;console.error(`${n}[openCursorRequest.onerror] ${m(h.error)}`),l(h.error)},h.onsuccess=()=>{try{let I=h.result;if(I){let A=I.key.toString();if(A.startsWith(p)&&A!==p){let w=A.substring(p.length),_=w.split("/")[0];if(o){let S=w.substring(_.length).startsWith("/");$.push({name:_,isDirectory:f(()=>S,"isDirectory"),isFile:f(()=>!S,"isFile"),isBlockDevice:f(()=>!1,"isBlockDevice"),isCharacterDevice:f(()=>!1,"isCharacterDevice"),isSymbolicLink:f(()=>!1,"isSymbolicLink"),isFIFO:f(()=>!1,"isFIFO"),isSocket:f(()=>!1,"isSocket")})}else E.add(_);I.continue()}else A.startsWith(p)?I.continue():c(o?$:Array.from(E))}else c(o?$:Array.from(E))}catch(I){console.error(`${n}[openCursorRequest.onsuccess] ${m(I)}`),l(I)}}}})}catch(a){throw console.error(`${n} ${m(a)}`),a}finally{s&&(pe&&console.log(`${n} closing db ${r}... (I: 39b4ba83de4bdfd541e3384ebab27425)`),s.close(),pe&&console.log(`${n} closing db ${r} complete. (I: e4015b9436c4b2bc0ccf0e11e2037925)`))}}f(Bc,"storageReaddir");var Dt=sa;async function Fc(r){let t=`[${Fc.name}]`;try{Dt&&console.log(`${t} starting... (I: 1905af1827a34ca8a5507fe0c5085b01)`),await ln({infos:[{dbName:r.dbName,storeNames:[r.storeName,...r.additionalStoreNames??[]]}]})}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{Dt&&console.log(`${t} complete.`)}}f(Fc,"initIbGibStorage");function _a(r){let t=`[${_a.name}]`;try{Dt&&console.log(`${t} starting... (I: 7be20d161bb14a498c44a42d3193bec1)`),globalThis.ibgib||(globalThis.ibgib={dbName_hack:r.dbName,apiKeyName_hack:r.apiKeyName,storeName_hack:r.storeName}),globalThis.ibgib.spaceGib||(globalThis.ibgib.spaceGib={version:aa,spaceShim:{},fnDefaultGetAPIKey:f(async()=>await Ur({dbName:r.dbName,storeName:r.storeName,key:r.apiKeyName})??"","fnDefaultGetAPIKey"),dbName_hack:r.dbName,apiKeyName_hack:r.apiKeyName,storeName_hack:r.storeName})}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{Dt&&console.log(`${t} complete.`)}}f(_a,"initIbGibGlobalThis");function Ph(r){if(!globalThis.ibgib?.spaceGib){if(!r)throw new Error("Global context not initialized and config not provided.");_a(r)}return globalThis.ibgib.spaceGib}f(Ph,"getIbGibGlobalThis_SpaceGib");async function qc(r){let t=`[${qc.name}]`;try{Dt&&console.log(`${t} starting... (I: 3123b18eb29b480bad056a9a029b9ad4)`),await(await import(r)).bootstrapSpaceGibApp()}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{Dt&&console.log(`${t} complete.`)}}f(qc,"dynamicallyLoadBootstrapScript");var j=!1;async function Zt({ibGib:r,ibGibs:t,ibGibAddr:e,ibGibAddrs:o,live:n,gotten:s,tjpAddrsAlreadyAnalyzed:a,skipAddrs:i,skipRel8nNames:c,onlyRel8nNames:l,maxRetries:d,msBetweenRetries:b,space:u,spaces:p,timeLogName:g,mapTjpAddrToLatestAddrsInSpace:h}){let E=`[${Zt.name}]`;try{j&&console.log(`${E} starting... (I: c2a4426c22e849611ca0cedabe683a22)`);let $=await Qt({ibGib:r,ibGibs:t,ibGibAddr:e,ibGibAddrs:o,live:n,gotten:s,tjpAddrsAlreadyAnalyzed:a,skipAddrs:i,skipRel8nNames:c,onlyRel8nNames:l,maxRetries:d,msBetweenRetries:b,space:u,spaces:p,timeLogName:g,mapTjpAddrToLatestAddrsInSpace:h});if(Object.values($).filter(I=>I.ib.startsWith("comment ")).forEach(I=>{console.table(I)}),j){console.log(`${E} graph size: ${Object.keys($).length} (I: c6cb5e7e1e2611d35b9006fac6503d22)`);let I=Object.values($).filter(A=>A.ib.startsWith("comment ")||A.ib.startsWith("pic ")).map(A=>A.ib);lr(I).forEach(A=>console.log(A))}return $}catch($){throw console.error(`${E} ${$.message}`),$}finally{j&&console.log(`${E} complete.`)}}f(Zt,"getDependencyGraph");async function Ta({ibGib:r,ibGibs:t,ibGibAddr:e,ibGibAddrs:o,live:n,gotten:s,tjpAddrsAlreadyAnalyzed:a,skipAddrs:i,skipRel8nNames:c,onlyRel8nNames:l,maxRetries:d,msBetweenRetries:b,space:u,spaces:p,timeLogName:g,mapTjpAddrToLatestAddrsInSpace:h}){let E=`[${Ta.name}]`;try{if(j&&console.log(`${E} starting... (I: bd6807477f679345df9dddefe0b4e922)`),u&&(p??[]).length>0)throw new Error("space and spaces parameters are mutually exclusive. Pass either space or spaces, not both. (E: 994a5323e4214f4e95d5bb2b89f89090)");let $=u?[u]:(p??[]).filter(I=>!!I);if($.length===0)throw new Error("space or spaces required. (E: 9f38166ab70340cb919174f8d26af909)");if(!r&&!e&&(t??[]).length===0&&(o??[]).length===0)throw new Error("either ibGib/s or ibGibAddr/s required. (E: b6d08699651f455697f0d05a41edb039)");return c=c||[],i=i||[],s=s||{},a=a||[],o=(o??[]).filter(I=>!Z({gib:C({ibGibAddr:I}).gib})).filter(I=>!i.includes(I)),t=(t??[]).filter(I=>!Z({ibGib:I})).filter(I=>!i.includes(y({ibGib:I}))),r&&!Z({ibGib:r})&&!t.some(I=>I.gib===r.gib)&&!i.includes(y({ibGib:r}))&&t.push(r),e&&!Z({gib:C({ibGibAddr:e}).gib})&&!o.includes(e)&&!i.includes(e)&&o.push(e),{ibGib:r,ibGibs:t,ibGibAddr:e,ibGibAddrs:o,live:n,gotten:s,tjpAddrsAlreadyAnalyzed:a,skipAddrs:i,skipRel8nNames:c,onlyRel8nNames:l,maxRetries:d,msBetweenRetries:b,space:void 0,spaces:$,timeLogName:g,mapTjpAddrToLatestAddrsInSpace:h}}catch($){throw console.error(`${E} ${$.message}`),$}finally{j&&console.log(`${E} complete.`)}}f(Ta,"getGraphProjection_initializeOpts");async function bn({ibGibs:r,ibGibAddrs:t,gotten:e,skipAddrs:o,maxRetries:n,msBetweenRetries:s,timeLogName:a,space:i,spaces:c}){let l=`[${bn.name}]`;try{j&&console.log(`${l} starting... (I: 67b2be37ff24393fff56e229304da122)`);let d=c??(i?[i]:[]);if(d.length===0)throw new Error("(UNEXPECTED) spaces empty? (E: aa9f657695717034b3581066932d7d23)");let b=[];r??=[],t??=[],o??=[],e??={};let u=[],p=Object.keys(e??{}),g=r.map(h=>y({ibGib:h}));for(let h=0;h<t.length;h++){let E=t[h];o.includes(E)||g.includes(E)||(p.includes(E)?b.push(e[E]):u.push(t[h]))}if(j&&console.log(`${l}[analyze debugging] addrsToGetFromSpace (${u.length}):
|
|
13
13
|
${u.join(`
|
|
14
14
|
`)} (I: b45a2614184b48b694becfd377c789f5)`),u.length>0){let h=u.concat(),E=0;for(n=n??0;E<=n&&h.length>0;){a&&E===0&&console.timeLog(a,`${l} FIRST try starting...`),a&&E>0&&console.timeLog(a,`${l} RETRY starting...`),E>0&&s&&(a&&console.timeLog(a,`${l} delaying ${s}ms for retry`),j&&console.log(`${l} retrying. addrsToGet (${h.length}): ${h} (I: 8460694cdd5518472680784c3b96a822)`),await le(s));for(let $ of d){if(h.length===0)break;a&&console.timeLog(a,`${l} getFromSpace (${h.length}) starting...`);let I=await ne({addrs:h,space:$});if(a&&console.timeLog(a,`${l} getFromSpace complete.`),I.success&&(I.ibGibs?.length??0)>0){I.ibGibs.forEach(w=>b.push(w));let A=I.ibGibs.map(w=>y({ibGib:w}));h=h.filter(w=>!A.includes(w))}else{let A=I.rawResultIbGib?.ibGibs??[];if(A.length>0){A.forEach(_=>b.push(_));let w=A.map(_=>y({ibGib:_}));h=h.filter(_=>!w.includes(_))}}}E++}if(h.length>0){let $=d.map(I=>I?.ib).join(", ");throw new Error(`unable to retrieve dependency ibgibs from space/s (ib/s: ${$}). addrsToGet: ${h.join(`
|
|
15
|
-
`)} (E: 8413594b6c1b447988781cf3f3e1729d)`)}}return b}catch(d){throw console.error(`${l} ${d.message}`),d}finally{j&&console.log(`${l} complete.`)}}f(bn,"getGraphProjection_getIbGibsInIbGibAddrs");async function Qt(r){let t=`[${Qt.name}]`;try{if(j&&console.log(`${t} starting... (I: 70508d7a5c63eae1f22ae851b32b3d22)`),!r.ibGib&&!r.ibGibAddr&&(r.ibGibs??[]).length===0&&(r.ibGibAddrs??[]).length===0)return{};let{ibGibs:e,ibGibAddrs:o,live:n,gotten:s,tjpAddrsAlreadyAnalyzed:a,skipAddrs:i,skipRel8nNames:c,onlyRel8nNames:l,maxRetries:d,msBetweenRetries:b,space:u,spaces:p,timeLogName:g,mapTjpAddrToLatestAddrsInSpace:h}=await
|
|
16
|
-
`)} (I: c89dc951315f746954f9bddbe8941122)`),n?Ta({ibGibs:e,ibGibAddrs:o,gotten:s,tjpAddrsAlreadyAnalyzed:a,skipAddrs:i,skipRel8nNames:c,onlyRel8nNames:l,maxRetries:d,msBetweenRetries:b,space:u,spaces:p,timeLogName:g,mapTjpAddrToLatestAddrsInSpace:h}):Aa({ibGibs:e,ibGibAddrs:o,gotten:s,skipAddrs:i,skipRel8nNames:c,onlyRel8nNames:l,maxRetries:d,msBetweenRetries:b,space:u,spaces:p,timeLogName:g})}catch(e){throw console.error(`${t} ${e.message}`),e}finally{j&&console.log(`${t} complete.`)}}f(Qt,"getGraphProjection");async function qc({ibGibAddr:r,latestCommonFrameAddr:t,live:e,space:o,spaces:n}){let s=`[${qc.name}]`;try{if(j&&console.log(`${s} starting... (I: 5d225e56dc11e62cd83c5366ea288826)`),r===t)return console.warn(`${s} ibGibAddr === latestCommonFrameAddr. So the delta graph is empty. what are we doing here? (W: e0c8287ae6de8152bf36b6c73ca59a26)`),{};let a=await Zt({ibGibAddr:t,live:!1,space:o,spaces:n});return await Zt({ibGibAddr:r,live:e,skipAddrs:Object.keys(a),space:o,spaces:n})}catch(a){throw console.error(`${s} ${m(a)}`),a}finally{j&&console.log(`${s} complete.`)}}f(qc,"getDeltaDependencyGraph");async function Ta({ibGibs:r,ibGibAddrs:t,gotten:e,tjpAddrsAlreadyAnalyzed:o,mapTjpAddrToLatestAddrsInSpace:n,skipAddrs:s,skipRel8nNames:a,onlyRel8nNames:i,maxRetries:c,msBetweenRetries:l,space:d,spaces:b,timeLogName:u}){let p=`[${Ta.name}]`;try{let g=b??(d?[d]:[]);n=n??{},o=o??[];let h={...e};(r??[]).forEach(_=>h[y({ibGib:_})]=_);let E=zt({ibGibs:Object.values(h)});j&&console.log(`${p}[analyze debugging] timeline tjps(${Object.keys(E).length}): ${Object.keys(E)} (I: 509f04ac15ca08c5a3f0777b48934622)`);let $={};Object.keys(E).forEach(_=>{o.includes(_)||($[_]=E[_])}),j&&console.log(`${p}[analyze debugging] timelinesNotAnalyzed: ${H($)} (I: a4b67d95fdd6b98d3241c0a7d0a93c22)`);let I={},A={};Object.keys(E).filter(_=>!o.includes(_)).forEach(_=>{let S=E[_],G=S[S.length-1];I[_]=G;let O=y({ibGib:G});A[O]=_});let w=Object.keys(I).length;if(w>0){let _={};Object.keys(n).filter(N=>!o.includes(N)).forEach(N=>{let k=I[N];if(k){let ae=y({ibGib:k});_[ae]=n[N]}else console.error(`${p} latestIbGibCorrespondingToTjpAddr is falsy (E: 8a5d3f2e1c4b90876543210fe89abcdf)`)}),j&&console.log(`${p} latestAddrsMap *before* getLatestAddrs: ${H(_)} (I: 427b4bb78595e9e521ecf2c5e5c80722)`);let S=Object.values(I),G={};if(S.length>0){if(g.length===0)throw new Error("(UNEXPECTED) space/s falsy? (E: 8e878975e3561df9a8dc4c628b0abc23)");for(let N of g){let k=await Pe({ibGibs:S,space:N});if(!k?.data?.latestAddrsMap)throw new Error("(UNEXPECTED) getLatestAddrs result latestAddrsMap falsy (E: 088caa1fc95fd3b079108ab63ef33422)");let ae=k.data.latestAddrsMap;Object.keys(ae).forEach(ie=>{let q=ae[ie];q?G[ie]=q:G[ie]||(G[ie]=null)})}if(S.forEach(N=>{let k=y({ibGib:N});G[k]||(G[k]=k)}),Object.keys(G).length!==w)throw new Error("(UNEXPECTED) latestAddrsMap is not the same size as the incoming map (E: 666af512bbd44534983bb28ee8d43fed)");j&&console.log(`${p} queriedLatestAddrsMap: ${H(G)} (I: 7b39a5f7ce9e9d9fabae4be98ed44522)`),_={...G,..._}}j&&console.log(`${p} combined latestAddrsMap: ${H(_)} (I: e3aedea63f29c5b06a79632f691aa522)`);let O=[],U={};Object.values(I).forEach(N=>{let k=y({ibGib:N}),ae=A[k],ie=_[k];if(!ie)throw new Error("(UNEXPECTED) latestAddrInSpace not found in latestAddrsMap (E: 095d2b3f88e3e8a2c3e7d3de4c6d5622)");ie===k?(j&&console.log(`${p} analyzed ${ae} (I: afb7960900f04b8a87538f4c7bd903b7)`),o.push(ae)):(O.push(ie),U[ie]=ae)});let x=[];for(let N=0;N<(r??[]).length;N++){let ae=r[N].rel8ns??{};Object.keys(ae).filter(q=>!(a??[]).includes(q)).filter(q=>i?i.includes(q):!0).forEach(q=>{(ae[q]??[]).forEach(Ue=>{!x.includes(Ue)&&!r.some(Rt=>y({ibGib:Rt})===Ue)&&!Z({gib:P({ibGibAddr:Ue}).gib})&&x.push(Ue)})})}return t=lr([...t??[],...x,...O]),await Qt({ibGibs:r,ibGibAddrs:t,gotten:e,tjpAddrsAlreadyAnalyzed:o,skipAddrs:s,skipRel8nNames:a,onlyRel8nNames:i,maxRetries:c,msBetweenRetries:l,space:d,spaces:g,timeLogName:u,live:!0,mapTjpAddrToLatestAddrsInSpace:n})}else return r||(r=[]),Object.values(e??{}).forEach(_=>{let S=y({ibGib:_});r.some(G=>y({ibGib:_})===S)||r.push(_)}),await Qt({ibGibs:r,ibGibAddrs:t,gotten:e,skipAddrs:s,skipRel8nNames:a,onlyRel8nNames:i,maxRetries:c,msBetweenRetries:l,space:d,spaces:g,timeLogName:u,live:!1})}catch(g){let h=`${p} ${g.message}`;throw console.error(h),u&&console.timeLog(u,`${p} error: ${h}`),g}finally{u&&console.timeLog(u,`${p} complete.`)}}f(Ta,"getGraphProjection_Live");async function Aa({ibGibs:r,ibGibAddrs:t,gotten:e,skipAddrs:o,skipRel8nNames:n,onlyRel8nNames:s,maxRetries:a,msBetweenRetries:i,space:c,spaces:l,timeLogName:d}){let b=`[${Aa.name}]`;try{let u=[];r??=[],e??={},o??=[],n??=[],d&&console.timeLog(d,`${b} analyzing next step starting...`);for(let p=0;p<r.length;p++){let g=r[p],h=y({ibGib:g}),{gib:E}=P({ibGib:g});if(E===L)throw new Error("cannot get dependency graph of primitive. (E: 5493b8908d134bdf887e91122a6a57e3)");Object.keys(e).includes(h)||(e[h]=g);let $={},I=g.rel8ns||{},A=(Object.keys(I)||[]).filter(_=>!n.includes(_));s&&(A=A.filter(_=>s.includes(_)));let w=Object.keys(e);for(let _=0;_<A.length;_++){let S=A[_],G=I[S]??[],O=G.filter(x=>x===""||x===void 0||x===null||!x.includes(J));O.length>0&&console.warn(`${b} (UNEXPECTED) has falsyAddrs: ${O} (W: da9505cb0a4db68a4aff7f279ad2d322)`),G.filter(x=>!!x).filter(x=>!w.includes(x)).filter(x=>!o.includes(x)).filter(x=>P({ibGibAddr:x}).gib!==L).filter(x=>!u.includes(x)).forEach(x=>{let N=kt({addr:x});(N||[]).length===0?u.push(x):$[x]=N})}if(Object.keys($).length>0)throw new Error(`invalid addresses found in dependency graph. Errors (clipped to 1kB): ${JSON.stringify($).substring(0,1024)} (E: d2416b9b23fa4d178e6c7104b40ee78c)`)}if(d&&console.timeLog(d,`${b} analyzing next step complete.`),u.length>0){d&&console.timeLog(d,`${b} get addrsWeDontHaveAlready_Rel8dAddrs starting...`);let p=await bn({ibGibAddrs:u,gotten:e,skipAddrs:o,maxRetries:a,msBetweenRetries:i,timeLogName:d,space:c,spaces:l});p.forEach(h=>e[y({ibGib:h})]=h),d&&console.timeLog(d,`${b} call getGraphProjection recursively starting...`);let g=await Qt({ibGibs:p,live:!1,gotten:e,skipAddrs:o,skipRel8nNames:n,onlyRel8nNames:s,maxRetries:a,msBetweenRetries:i,space:c,spaces:l});return d&&console.timeLog(d,`${b} call getGraphProjection recursively complete.`),g}else return e}catch(u){let p=`${b} ${u.message}`;throw console.error(`${p} (E: 8a42e56616014e7a8848aa6bb6f2722b)`),d&&console.timeLog(d,`${b} error: ${p}`),new Error(`${p} (E: a21b0682121746a480572b83413cf2d0)`)}finally{d&&console.timeLog(d,`${b} complete.`)}}f(Aa,"getGraphProjection_NonLive");function kr({ibGibs:r}){let t=`[${kr.name}]`;try{if(j&&console.log(`${t} starting... (I: 6019a812cff8597f79c12088e45cc226)`),r){let e={};return r.forEach(o=>{e[y({ibGib:o})]=o}),e}else return}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{j&&console.log(`${t} complete.`)}}f(kr,"toFlatGraph");function Hc({graphA:r,graphB:t,slowButThorough:e}){let o=`[${Hc.name}]`;try{if(j&&console.log(`${o} starting... (I: e50a98b659189dece8b4ef581e4ad826)`),!(Object.keys(r).length===Object.keys(t).length))return j&&console.log(`${o} not the same size. false. (I: e1044e52421dbf7e067e0fe850ac6826)`),!1;for(let s of Object.keys(r))if(!t[s])return j&&console.log(`${o} addr (${s}) in graphA not found in graphB (I: 264c68408378ce30b8f6a978f8b86926)`),!1;if(e)for(let s of Object.keys(r)){let a=Re({ibGib:r[s]}),i=JSON.stringify(a),c=Re({ibGib:t[s]}),l=JSON.stringify(c);if(i!==l)return j&&console.log(`${o} jsonA !== jsonB for addr (${s}) (I: 98ed9f58ac88dabba83f96582f725926)`),!1}return!0}catch(n){throw console.error(`${o} ${m(n)}`),n}finally{j&&console.log(`${o} complete.`)}}f(Hc,"graphsAreEquivalent");var fe=!1;async function un({timeline:r}){let t=`[${un.name}]`;try{if(fe&&console.log(`${t} starting...`),Z({ibGib:r}))return console.warn(`${t} getting lock scope on a primitive ibgib can grossly impact performance. (W: 55203e415ae2ac7ddb19c21772b28925)`),y({ibGib:r});{let e=re({gib:r.gib}),o=e.tjpGib??e.punctiliarHash;if(!o)throw new Error(`${t} (UNEXPECTED) Could not determine tjpGib or punctiliarHash from ibGib. (E: eb3b6472e9b335991a1b0869f772f7d3)`);return o}}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{fe&&console.log(`${t} complete.`)}}f(un,"getLockScope");async function Xc({timeline:r,rel8nInfos:t,rel8nRemovalInfos:e,timelineIndexInfo:o,metaspace:n,space:s,skipLock:a,noDna:i}){let c=`[${Xc.name}]`;try{if(fe&&console.log(`${c} starting... (I: fcdff10832215068019355265f4cbc25)`),s??=await n.getLocalUserSpace({lock:!1}),!s)throw new Error("(UNEXPECTED) space falsy? couldn't even get default local user space? (E: 2051b44a052d6a2984b9a22f680e4625)");let l=await un({timeline:r}),d=f(async()=>{if(!s)throw new Error("(UNEXPECTED) space falsy? couldn't even get default local user space? (E: 845c4181c8c15d7219166ceb3c4dca25)");let u=y({ibGib:r}),p=await n.getLatestAddr({addr:u,space:s});if(!p)throw new Error(`${c} (UNEXPECTED) Could not get latest address for timeline ${y({ibGib:r})}. (E: a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9)`);let g=Re({ibGib:r});if(u!==p){let A=await n.get({addrs:[p],space:s});if(A.errorMsg||(A.ibGibs??[]).length!==1)throw new Error(`${c} (UNEXPECTED) couldn't get latest timeline ibgib (${p}) from space (${s.ib}). errorMsg: ${A.errorMsg??"[unknown error]"} (E: b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0)`);g=A.ibGibs.at(0)}let h;if(e&&e.length>0){h={};for(let A of e){let{rel8nName:w,ibGibAddrs:_}=A;if(_.length===0){console.warn(`${c} tried to remove 0 ibGibAddrs in rel8nName ${w}? skipping... (W: 93aeb601be66d680989e72ec70e4c826)`);continue}h[w]||(h[w]=[]),h[w]=h[w].concat(_)}}let E={};for(let A of t){let{rel8nName:w,ibGibs:_}=A;if(_.length===0){console.warn(`${c} tried to add 0 ibGibs to rel8nName ${w}? skipping... (W: 708252dfdeb60757fee4554e769aaa25)`);continue}E[w]||(E[w]=[]),E[w].push(..._.map(S=>y({ibGib:S})))}let $=await Ie({src:g,rel8nsToRemoveByAddr:h,rel8nsToAddByAddr:E,dna:!i,nCounter:!0}),I=$.newIbGib;return await n.persistTransformResult({resTransform:$,space:s}),o&&await pn({type:o.type,rel8nInfos:[{rel8nName:o.rel8nName,ibGibs:[I]}],metaspace:n,space:s,skipLock:a}),await n.registerNewIbGib({ibGib:I,space:s}),I},"fn");return a?await d():await Ae({scope:l,secondsValid:180,maxDelayMs:100,maxLockAttempts:1800,space:s,callerInstanceId:ge(),fn:d})}catch(l){throw console.error(`${c} ${m(l)}`),l}finally{fe&&console.log(`${c} complete.`)}}f(Xc,"appendToTimeline");async function pn({type:r,rel8nInfos:t,dataToAddOrPatch:e,metaspace:o,space:n,skipLock:s}){let a=`[${pn.name}]`;try{if(fe&&console.log(`${a} starting... (I: 6e7d05fe916d813b71766e2eaa747c25)`),r==="latest")throw new Error('cannot update the "latest" special index by this function. The registerNewIbGib will do this automatically. (E: 231eb78a221ccdbcf56cd1899260a425)');if(n??=await o.getLocalUserSpace({lock:!1}),!n)throw new Error("(UNEXPECTED) space falsy? couldn't even get default local user space? (E: 43067821a4749a7648fe2612d25d7f25)");let i=f(async()=>{let c=f(async()=>{let l=await o.getSpecialIbGib({type:r,space:n,initialize:!0});if(!l)throw new Error(`(UNEXPECTED) couldn't initialize/get special ibgib index of type ${r}. (E: a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6)`);return l.rel8ns||console.warn(`${a} not sure if this ever hits, but is there ever a scenario where specialIndex.rel8ns is falsy? (W: 06161c366bc7ec858b9b5aa7ee9b6d25)`),l},"fnGetSpecialIndex");for(let l of t??[]){let{rel8nName:d,ibGibs:b}=l;b.length===0&&console.error(`${a} ibGibs empty. skipping rel8nName (${d}). (E: 150d74f73f97aea1b97d173d92c77125)`);let p=(await c()).rel8ns??{},g,h=p[d]??[];if(h.length>0){let E=new Set;b.forEach($=>{let I=y({ibGib:$}),A=$.rel8ns?.past??[];h.filter(w=>[...A,I].includes(w)).forEach(w=>E.add(w))}),E.size>0&&(g=Array.from(E))}await o.rel8ToSpecialIbGib({type:r,rel8nName:d,ibGibsToRel8:b,addrsToUnRel8:g,space:n,linked:!1,severPast:!1,deletePreviousSpecialIbGib:!1})}if(Object.keys(e??{}).length>0){let l=await c(),d=await Me({src:l,dataToAddOrPatch:e,dna:!1,linkedRel8ns:[K.past],nCounter:!0}),b=d.newIbGib;await ee({resTransform:d,space:n});let u=Q({type:r});await o.setConfigAddr({key:u,addr:y({ibGib:b}),space:n}),await o.registerNewIbGib({ibGib:b,space:n})}},"fn");s?await i():await Ae({scope:r,secondsValid:60,maxDelayMs:100,maxLockAttempts:600,space:n,fn:i})}catch(i){throw console.error(`${a} ${m(i)}`),i}finally{fe&&console.log(`${a} complete.`)}}f(pn,"updateSpecialIndex");async function hn({timeline:r,timelineAddr:t,metaspace:e,space:o}){let n=`[${hn.name}]`;try{if(fe&&console.log(`${n} starting... (I: f2b605361368e1956f6db878dbfeb825)`),!r&&!t)throw new Error("either timeline or timelineAddr required. (E: 97551b2b18ecd22a18185a783f9a0825)");t??=y({ibGib:r});let s=await e.getLatestAddr({addr:t,space:o})??t;if(!s)throw new Error(`${n} (UNEXPECTED) Could not get latest address for timeline ${y({ibGib:r})}. (E: a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9)`);let a;if(t===s){if(!r){let i=await e.get({addrs:[s],space:o});if(i.errorMsg||(i.ibGibs??[]).length!==1)throw new Error(`${n} (UNEXPECTED) couldn't get latest timeline ibgib (${s}) from space (${o.ib}). errorMsg: ${i.errorMsg??"[unknown error]"} (E: 3fc767a594788a43a4ba18c87491a825)`);r=i.ibGibs.at(0)}a=Re({ibGib:r})}else{let i=await e.get({addrs:[s],space:o});if(i.errorMsg||(i.ibGibs??[]).length!==1)throw new Error(`${n} (UNEXPECTED) couldn't get latest timeline ibgib (${s}) from space (${o.ib}). errorMsg: ${i.errorMsg??"[unknown error]"} (E: b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0)`);a=i.ibGibs.at(0)}return a}catch(s){throw console.error(`${n} ${m(s)}`),s}finally{fe&&console.log(`${n} complete.`)}}f(hn,"getLatestTimelineIbGibDto_nonLocking");async function Kc({timeline:r,timelineAddr:t,mut8Opts:e,metaspace:o,space:n,skipLock:s,timelineIndexInfo:a,noDna:i}){let c=`[${Kc.name}]`;try{if(fe&&console.log(`${c} starting... (I: genuuid)`),!r&&!t)throw new Error("(UNEXPECTED) both timeline and timelineAddr falsy? either one is required. (E: a19d98c6acb87af3b876c1484f6ac825)");if(n??=await o.getLocalUserSpace({lock:!1}),!n)throw new Error("(UNEXPECTED) space falsy? couldn't even get default local user space? (E: genuuid)");if(!r){let u=await o.get({addrs:[t],space:n});if(!u.success||u.ibGibs?.length!==1)throw new Error(`couldn't get timeline ibGib from timelineAddr (${t}) in space (${n?.ib??"undefined"}) (E: genuuid)`);r=u.ibGibs.at(0)}let l=await un({timeline:r}),d=f(async()=>{if(!n)throw new Error("(UNEXPECTED) space falsy? couldn't even get default local user space? (E: 845c4181c8c15d7219166ceb3c4dca25)");if(!r)throw new Error("(UNEXPECTED) timeline falsy? we should be ensured that it's truthy at this point. (E: 2e1758b2cc3820531f7ac7f5f6b3a825)");let u=await hn({timeline:r,metaspace:o,space:n}),p=await Me({...e,src:u,dna:!i,nCounter:!0}),g=p.newIbGib;return await o.persistTransformResult({resTransform:p,space:n}),a&&await pn({type:a.type,rel8nInfos:[{rel8nName:a.rel8nName,ibGibs:[g]}],metaspace:o,space:n,skipLock:s}),await o.registerNewIbGib({ibGib:g,space:n}),g},"fn");return s?await d():await Ae({scope:l,secondsValid:180,maxDelayMs:100,maxLockAttempts:1800,space:n,callerInstanceId:ge(),fn:d})}catch(l){throw console.error(`${c} ${m(l)}`),l}finally{fe&&console.log(`${c} complete.`)}}f(Kc,"mut8Timeline");async function Yc({ib:r,data:t,rel8ns:e,noDna:o,parentIb:n,parentIbGib:s,metaspace:a,space:i}){let c=`[${Yc.name}]`;try{if(fe&&console.log(`${c} starting...`),i??=await a.getLocalUserSpace({lock:!1}),!i)throw new Error("(UNEXPECTED) space is required, but is falsy. (E: 252994a554224b17aa9816c7a765c925)");s??=n?s=M.primitive({ib:n}):s=V;let l=await M.firstGen({parentIbGib:s,ib:r,data:t,rel8ns:e,dna:!o,nCounter:!0,squash:!!o,tjp:{timestamp:!0,uuid:!t?.uuid}});return await a.persistTransformResult({resTransform:l,space:i}),await a.registerNewIbGib({ibGib:l.newIbGib,space:i}),l}catch(l){throw console.error(`${c} ${m(l)}`),l}}f(Yc,"createTimeline");async function Ga({ibGib:r,metaspace:t,space:e}){let o=`[${Ga.name}]`;try{if(fe&&console.log(`${o} starting...`),e??=await t.getLocalUserSpace({lock:!1}),!e)throw new Error("(UNEXPECTED) space is required. (E: c1b9a9b8c7d6e5f4a3b2a1a0b9c8d7e6)");let n=r.rel8ns?.dna??[];if(n.length===0)return[];let s=await t.get({addrs:n,space:e});if(!s.success||(s.ibGibs??[]).length!==n.length){let a=n.filter(i=>!s.ibGibs?.some(c=>y({ibGib:c})===i));throw new Error(`Could not get all dna ibGibs for ${y({ibGib:r})}. Addrs not found: ${a.join(", ")}. Errors: ${s.errorMsg??"[unknown error (E: 92cf95774828d8a978331da859098625)]"} (E: d2c0b1a9a8b7c6d5e4f3a2b1a0b9c8d7)`)}return s.ibGibs}catch(n){throw console.error(`${o} ${m(n)}`),n}}f(Ga,"getDna");async function Sa({timeline:r,getLatest:t,includeDna:e,metaspace:o,space:n}){let s=`[${Sa.name}]`;try{if(fe&&console.log(`${s} starting... (I: 7fbc442a27e8f9fda8ac4228ded84825)`),n??=await o.getLocalUserSpace({lock:!1}),!n)throw new Error("(UNEXPECTED) space is required. (E: e3d1c0b1a9a8b7c6d5e4f3a2b1a0b9c8)");let a=t?await hn({timeline:r,metaspace:o,space:n}):Re({ibGib:r}),i=y({ibGib:a}),c={},l=e?kr({ibGibs:await Ga({ibGib:a,metaspace:o,space:n})}):void 0,d=r.rel8ns?.past??[];if(d.length===0)return{headIbGib:a,orderedPastIbGibs:[],pastIbGibMap:c,dnaMap:l};let b=await o.get({addrs:d,space:n});if(!b.success||(b.ibGibs??[]).length!==d.length){let p=d.filter(g=>!b.ibGibs?.some(h=>y({ibGib:h})===g));throw new Error(`Could not get all dna ibGibs for ${i}. Addrs not found: ${p.join(", ")}. Errors: ${b.errorMsg??"[unknown error (E: 887339d8b5580ed1ac9892a554255525)]"} (E: 4ab7a8a58adff4e238171f7c110c6825)`)}c=kr({ibGibs:b.ibGibs})??{};let u=[];for(let p of d){let g=c[p];if(!g)throw new Error("(UNEXPECTED) pastIbGib falsy? due to our logic, the pastIbGibMap should be complete. (E: 6010d8c14184124008631928e1265525)");u.push(g)}return{headIbGib:a,orderedPastIbGibs:u,pastIbGibMap:c,dnaMap:l}}catch(a){throw console.error(`${s} ${m(a)}`),a}finally{fe&&console.log(`${s} complete.`)}}f(Sa,"getHistory");async function Vc({timeline:r,getLatest:t,metaspace:e,space:o}){let n=`[${Vc.name}]`;try{return fe&&console.log(`${n} starting... (I: c7a328b14018642138ebb47870c15626)`),(await Sa({timeline:r,getLatest:t,includeDna:!1,metaspace:e,space:o})).orderedPastIbGibs.map(i=>y({ibGib:i}))}catch(s){throw console.error(`${n} ${m(s)}`),s}finally{fe&&console.log(`${n} complete.`)}}f(Vc,"getHistoryAddrs");var bt=!1,gn=class r{static{f(this,"IbGibApiBridge")}lc=`[${r.name}]`;async parseResponseJson(t,e){let o=t.headers.get("content-type")||"";if(!o.includes("application/json")){let n=await t.text();throw n.trim().toLowerCase().startsWith("<!doctype html")||n.includes("<html")?new Error(`API request to '${e}' failed (${t.status} ${t.statusText}): Received HTML fallback instead of JSON. Check API route matching and parameters.`):new Error(`API request to '${e}' failed (${t.status} ${t.statusText}): Returned non-JSON content type '${o}': ${n.slice(0,150)}`)}return await t.json()}async postGenesisKeystone(t){let e=`${this.lc}[${this.postGenesisKeystone.name}]`;try{bt&&console.log(`${e} starting... (I: eecd082fc4a4381c8857928e8b090826)`);let o="/api/keystone/genesis",n=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({keystoneIbGib:t})}),s=await this.parseResponseJson(n,o);if(!n.ok){let a=s.message||s.error||"Unknown error";return console.error(`${e} server rejected genesis keystone: ${a}`),{success:!1,message:a,addr:s.addr}}return bt&&console.log(`${e} genesis keystone posted successfully.`),{success:!0,addr:s.addr}}catch(o){let n=m(o);return console.error(`${e} error: ${n}`),{success:!1,message:n}}}async putEvolveKeystone({domainAddr:t,keystoneIbGib:e,relatedKeystoneIbGibs:o=[],revokeTokens:n}){let s=`${this.lc}[${this.putEvolveKeystone.name}]`;try{bt&&console.log(`${s} posting evolved keystone...`);let a=`/api/keystone/evolve/${encodeURIComponent(t)}`,i=await fetch(a,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({keystoneIbGib:e,relatedKeystoneIbGibs:o,revokeTokens:n})}),c=await this.parseResponseJson(i,a);if(!i.ok){let l=c.message||c.error||"Unknown error";return console.error(`${s} server rejected keystone evolution: ${l}`),{success:!1,message:l}}return bt&&console.log(`${s} keystone evolution accepted by server.`),{success:!0}}catch(a){let i=m(a);return console.error(`${s} fetch error: ${i}`),{success:!1,message:i}}}async lookupPrimaryKeystone({identifier:t}){let e=`${this.lc}[${this.lookupPrimaryKeystone.name}]`;try{let o="/api/keystone/lookup",n=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({identifier:t})}),s=await this.parseResponseJson(n,o);if(!n.ok){let a=s.message||s.error||"Identity not found";return console.error(`${e} server lookup failed: ${a}`),{success:!1,message:a}}return{success:!0,tjpAddr:s.tjpAddr,primaryKeystoneIbGib:s.primaryKeystoneIbGib}}catch(o){let n=m(o);return console.error(`${e} lookup fetch error: ${n}`),{success:!1,message:n}}}async checkEmailAvailability({email:t}){let e=`${this.lc}[${this.checkEmailAvailability.name}]`;try{let o=`/api/keystone/check-email?email=${encodeURIComponent(t)}`,n=await fetch(o,{method:"GET",headers:{"Content-Type":"application/json"}}),s=await this.parseResponseJson(n,o);if(!n.ok){let a=s.message||s.error||"Server check failed";return console.error(`${e} email check failed: ${a}`),{available:!1,message:a}}return{available:s.available??!0,message:s.message}}catch(o){let n=m(o);return console.error(`${e} check email error: ${n}`),{available:!0}}}async getKeystoneGraph(t){let e=`${this.lc}[${this.getKeystoneGraph.name}]`;try{bt&&console.log(`${e} fetching keystone graph...`);let o=`/api/keystone/${encodeURIComponent(t)}?getLatest=true&getGraph=true`,n=await fetch(o,{method:"GET",headers:{Accept:"application/json"}}),s=await this.parseResponseJson(n,o);if(!n.ok){let a=s.message||s.error||"Unknown error";return console.error(`${e} server rejected keystone graph get: ${a}`),{success:!1,message:a}}return{success:!0,graph:s.domainGraph}}catch(o){let n=m(o);return console.error(`${e} fetch error: ${n}`),{success:!1,message:n}}}async getIbGib(t,e,o=!1){let n=`${this.lc}[${this.getIbGib.name}]`;try{bt&&console.log(`${n} fetching single ibGib frame...`);let s=`/api/ibgib/${encodeURIComponent(t)}/${encodeURIComponent(e)}?getLatest=${o}&getGraph=false`,a=await fetch(s,{method:"GET",headers:{Accept:"application/json"}}),i=await this.parseResponseJson(a,s);if(!a.ok){let c=i.message||i.error||"Unknown error";return console.error(`${n} server rejected ibGib get: ${c}`),{success:!1,message:c}}return{success:!0,ibGib:i}}catch(s){let a=m(s);return console.error(`${n} fetch error: ${a}`),{success:!1,message:a}}}async getIbGibGraph(t,e,o=!1){let n=`${this.lc}[${this.getIbGibGraph.name}]`;try{bt&&console.log(`${n} fetching ibGib graph...`);let s=`/api/ibgib/${encodeURIComponent(t)}/${encodeURIComponent(e)}?getLatest=${o}&getGraph=true`,a=await fetch(s,{method:"GET",headers:{Accept:"application/json"}}),i=await a.json();if(!a.ok){let c=i.message||i.error||"Unknown error";return console.error(`${n} server rejected ibGib graph get: ${c}`),{success:!1,message:c}}return{success:!0,graph:i.graph,addr:i.addr}}catch(s){let a=m(s);return console.error(`${n} fetch error: ${a}`),{success:!1,message:a}}}},jr;function ag(){return jr||(jr=new gn),jr}f(ag,"getApiBridge");function ig(r){jr=r}f(ig,"setApiBridge");var xa=/^error (\w+) ([a-fA-F\d]{32}|undefined)$/;var tt=!1;function Da({rawMsg:r}){let t=`[${Da.name}]`;try{tt&&console.log(`${t} starting...`);let e=En({rawMsg:r}),o=e.body.replace(/\s/g,"_").replace(/\W/g,""),n;if(o.length>20)n=o.substring(0,20);else if(o.length>0)n=o;else throw new Error("(UNEXPECTED) error msg should have characters/alphanumerics... (E: a3b9cd11a44cc7892a748819c2885422)");return`error ${n} ${e.uuid??"undefined"}`}catch(e){throw console.error(`${t} ${e.message}`),e}finally{tt&&console.log(`${t} complete.`)}}f(Da,"getErrorIb");function En({rawMsg:r}){let t=`[${En.name}]`;try{if(tt&&console.log(`${t} starting...`),!r)throw new Error("(UNEXPECTED) rawMsg required (E: e5bd3b433a1781ebe885534cd2495622)");let e,o=r.match(qn);if(o){let[n,s,a,i,c,l]=o;if(!i)throw new Error("invalid error msg body (E: a675e6855cca96519d33d44ea5400922)");e={success:!1,raw:r,body:i?.trim(),uuid:c.slice(4,36)},s&&(e.location=s),(a||l)&&(e.unexpected=!0)}else{e={success:!1,raw:r,body:r};let n=r.match(Hn);if(n){let[s,a]=n;e.location=a}r.toLowerCase().includes("(unexpected)")&&(e.unexpected=!0)}return e}catch(e){throw console.error(`${t} ${e.message}`),e}finally{tt&&console.log(`${t} complete.`)}}f(En,"parseRawErrorMsg");function ut({rawMsg:r}){let t=`[${ut.name}]`;try{return tt&&console.log(`${t} starting...`),Te({parentPrimitiveIb:"error",ib:Da({rawMsg:r}),data:En({rawMsg:r}),ibRegExpPattern:xa.source})}catch(e){throw console.error(`${t} ${e.message}`),e}finally{tt&&console.log(`${t} complete.`)}}f(ut,"getErrorIbGib");function Ke({ibGib:r}){let t=`[${Ke.name}]`;try{if(tt&&console.log(`${t} starting...`),!r)throw new Error("ibGib required (E: 1d756fbbd96f1734b97ba013537ed522)");return r.ib.startsWith("error ")}catch(e){throw console.error(`${t} ${e.message}`),e}finally{tt&&console.log(`${t} complete.`)}}f(Ke,"isError");var rt=!1;function va(r){let t=`[${va.name}]`;try{let e=r?`${Yt} ${r}`:Yt;return rt&&console.log(`${t} ${e}`),e}catch(e){throw console.error(`${t} ${e.message}`),e}}f(va,"getArgIb");function Wc({ib:r,ibGib:t}){let e=`[${Wc.name}]`;try{if(rt&&console.log(`${e} starting...`),!r)if(t)r=t.ib;else throw new Error("either ib or ibGib required (E: c052a9d76df867626f9ba17141cdce22)");return r.startsWith(Yt)}catch(o){throw console.error(`${e} ${o.message}`),o}finally{rt&&console.log(`${e} complete.`)}}f(Wc,"isArg");function Na(r){let t=`[${Na.name}]`;try{let e=r?`${xr} ${r}`:xr;return rt&&console.log(`${t} ${e}`),e}catch(e){throw console.error(`${t} ${e.message}`),e}}f(Na,"getResultIb");async function pt({argData:r,ibMetadata:t,noTimestamp:e}){let o=`[${pt.name}]`;try{let n=await M.firstGen({ib:va(t),parentIbGib:M.primitive({ib:Yt}),data:r,dna:!1,noTimestamp:e});if(n.newIbGib){let{newIbGib:s}=n;return s.rel8ns.past=[],s.gib=await We(s),s}else throw new Error("create ibGib failed")}catch(n){throw console.error(`${o} ${n.message}`),n}}f(pt,"argy_");async function ht({resultData:r,ibMetadata:t,noTimestamp:e}){let o=`[${ht.name}]`;try{let n=await M.firstGen({ib:Na(t),parentIbGib:M.primitive({ib:xr}),data:r,dna:!1,noTimestamp:e});if(n?.newIbGib){let{newIbGib:s}=n;return s.rel8ns.past=[],s.gib=await We(s),s}else throw new Error("create ibGib failed")}catch(n){throw console.error(`${o} ${n.message}`),n}}f(ht,"resulty_");function mn({ibGib:r}){let t=`[${mn.name}]`;try{if(rt&&console.log(`${t} starting...`),!r)throw new Error("ibGib required (E: e11cee2a6c59a5e7a4d39ea55751c423)");if(!r.data)return!1;let e=r.data;return e.cmd&&typeof e.cmd=="string"}catch(e){throw console.error(`${t} ${e.message}`),e}finally{rt&&console.log(`${t} complete.`)}}f(mn,"isCommand");function wn({ibGib:r}){let t=`[${wn.name}]`;try{return rt&&console.log(`${t} starting... (I: aad0a14f4d62061424fc92da4d53d823)`),typeof r.witness=="function"}catch(e){throw console.error(`${t} ${e.message}`),e}finally{rt&&console.log(`${t} complete.`)}}f(wn,"isWitness");var Br="subject",$n=/^[a-zA-Z0-9_\-.]{1,255}$/,La="subject",Pa="",Fr="subject is a cool ibgib witness that has seriously fascinating behavior.";var Ra="observable";var ot={subscribe:"subscribe"},Ca=Object.values(ot);var Ua={next:"next",error:"error",complete:"complete"};var nt={...ot,...Ua};var er={version:"1",uuid:Pa,name:La,description:Fr,classname:"Subject_V1",persistOptsAndResultIbGibs:!1,allowPrimitiveArgs:!0,catchAllErrors:!0,trace:!1},yn=void 0;var qr=class r{static{f(this,"WitnessFactoryBase")}lc=`[${r.name}]`};var In=!1,vt=class r extends qr{static{f(this,"DynamicFormFactoryBase")}lc=`[${r.name}]`;patchDataFromItems({data:t,contextPath:e,items:o,pathDelimiter:n}){let s=`${this.lc}[${this.patchDataFromItems.name}]`;try{if(In&&console.log(`${s} starting...`),!n)throw new Error("pathDelimiter required (E: 958d472a15fb71e45cd2925883f2ec22)");for(let a=0;a<o.length;a++){let i=o[a],c=e?e+n+i.name:i.name;if(!i.items)Eo({obj:t,value:i.value,path:c,logalot:In,pathDelimiter:n});else if(i.items.length>0)this.patchDataFromItems({data:t,contextPath:c,items:i.items,pathDelimiter:n});else throw new Error("invalid item. items is truthy but with a length of 0. items should either be falsy or have at least one child. (E: ee2765e0b920477f919fcb09e9d951b4)")}}catch(a){throw console.error(`${s} ${a.message}`),a}finally{In&&console.log(`${s} complete.`)}}};var Ma=!1,Nt=class r{static{f(this,"LightWitnessBase_V1")}lc=`[${r.name}]`;instanceId="";ib="";gib;data;rel8ns;initialized;_isInitialized=!1;constructor(t,e){t&&(this.data=t),e&&(this.rel8ns=e),this.initialized=this.initialize().then(()=>{this._isInitialized=!0})}async initialize(){this.instanceId=await F(),this.gib=await X({ibGib:this.toIbGibDto()})}toIbGibDto(){return Re({ibGib:this})}loadIbGibDto(t){let e=`${this.lc}[${this.loadIbGibDto.name}]`;try{return Ma&&console.log(`${e} starting...`),t.ib||console.warn(`${e} dto.ib is falsy.`),t.gib||console.warn(`${e} dto.gib is falsy.`),this.ib=v(t.ib),this.gib=v(t.gib),t.data?this.data=v(t.data):delete this.data,t.rel8ns?this.rel8ns=v(t.rel8ns):delete this.rel8ns,Promise.resolve()}catch(o){throw console.error(`${e} ${o.message}`),o}finally{Ma&&console.log(`${e} complete.`)}}async validateThis(){let t=`${this.lc}[${this.validateThis.name}]`,e=[];try{this.ib||e.push("this.ib is falsy."),this.gib||e.push("this.gib is falsy.")}catch(o){throw console.error(`${t} ${o.message}`),o}return e}};var ka="subscription",_n=/^[a-zA-Z0-9_\-.]{1,255}$/,ja="",Ba="subscription",Hr="subscription is a cool ibgib witness that has seriously fascinating behavior.";var tr={unsubscribe:"unsubscribe",unsubscribed:"unsubscribed"};var Tn={version:"1",uuid:ja,name:Ba,description:Hr,classname:"Subscription_V1",persistOptsAndResultIbGibs:!1,allowPrimitiveArgs:!0,catchAllErrors:!1,trace:!1},An=void 0;var Fa=!1;function Gn({ibGib:r}){let t=`[${Gn.name}]`;try{Fa&&console.log(`${t} starting... (I: 3aadb634377acbe42984b61c91975323)`);let{ib:e}=r;return[Ra,Br].some(n=>e.includes(n))}catch(e){throw console.error(`${t} ${e.message}`),e}finally{Fa&&console.log(`${t} complete.`)}}f(Gn,"isObservable");var R=!1,Xr=class r extends Nt{static{f(this,"Subscription_V1")}lc=`[${r.name}]`;metaspace;_subscribed;_unsubscribed;_srcObservable;constructor(t,e){super(t,e)}async initialize(){let t=`${this.lc}[${this.initialize.name}]`;try{if(R&&console.log(`${t} starting... (I: 8097612cda5f43e5b38249d057b65b1e)`),await super.initialize(),!this.data)throw new Error("this.data required (E: 1af73af2d17a48ada42596ad395fd99c)");this.data.uuid=this.instanceId,this.ib=Yr({data:this.data,classname:"Subscription_V1"}),this.gib=await X({ibGib:this})}catch(e){throw console.error(`${t} ${e.message}`),e}finally{R&&console.log(`${t} complete.`)}}async witness(t){let e=`${this.lc}[${this.witness.name}]`;try{this._isInitialized||await this.initialized;let{ib:o}=t;if(!o)throw new Error("arg.ib required (E: 1fd9aebef07b4bdaacc0cd323c8ddf76)");if(R&&console.log(`${e} ib: ${o} (I: 4de7771f477dc5b36933343b694ce223)`),o===tr.unsubscribe)return R&&console.log(`${e} routing unsubscribe cmd (I: 5633b86d467af2aa67388abf559a3c23)`),this.witness_unsubscribe();if(o===tr.unsubscribed)return R&&console.log(`${e} routing unsubscribed query (I: 6e0ae61d90f1974d76bcdbb47970e723)`),this.witness_unsubscribed();if(Gn({ibGib:t}))return R&&console.log(`${e} routing observerable (I: 165b422cda9ec3052312243dc965cf23)`),this.witness_observable({ibGib:t});throw new Error("unknown arg. expect unsubscribe/unsubscribed primitive ibgib or Observable ibgib. (E: 132dc7cd8f7c4afc9ec4651e2c559c74)")}catch(o){throw console.error(`${e} ${m(o)??"unknown error (E: b0bbaab21833404a9420c3d273df7f21)"}`),o}}async witness_unsubscribe(){let t=`${this.lc}[${this.witness_unsubscribe.name}]`;try{if(R&&console.log(`${t} starting... (I: a3d549220ef24604956aaa2c66fff09b)`),!this._subscribed)return console.warn(`${t} tried to unsubscribe but this._subscribed is ${this._subscribed} (W: cdc94f59447d4011b4b4cc12ef9ec074)`),V;if(this._unsubscribed)return console.warn("{lc} this._unsubscribed already true. (W: fa287d76cec040e0978a8add5c758093)"),V;if(!this._srcObservable)throw new Error("(UNEXPECTED) this._subscribed but this._srcObservable falsy? (E: 83687993b7bea299b4ba2438b530a123)");return R&&(console.log(`${t} inspecting srcObservable before src.witness... (I: f15a33d10f1cae3cec6fdbdb32596823)`),console.dir(this._srcObservable)),await this._srcObservable.witness(this),R&&(console.log(`${t} inspecting srcObservable after src.witness... (I: f15a33d10f1cae3cec6fdbdb32596823)`),console.dir(this._srcObservable)),this._subscribed=!1,this._unsubscribed=!0,delete this._srcObservable,R&&console.log(`${t} this._ (I: 7b1bc418a3d32757772391cad7a49523)`),V}catch(e){throw console.error(`${t} ${e.message}`),e}finally{R&&console.log(`${t} complete.`)}}async witness_observable({ibGib:t}){let e=`${this.lc}[${this.witness_observable.name}]`;try{if(R&&console.log(`${e} starting... (I: faf248f372fc44a7bb0e70492e8284f9)`),this._subscribed!==void 0)throw new Error(`(UNEXPECTED) this._subscribed (${this._subscribed} is not undefined? (E: 09a0e926357676c2c93a173ccbe93923)`);if(this._srcObservable)throw new Error("(UNEXPECTED) this subscription isn't subscribed but this._observable is truthy? (E: acdf5198fb2ff3c8b2db95450bd55b23)");return this._srcObservable=t,R&&console.log(`${e} this._srcObservable set to ibgib with ib: ${t.ib} (I: 4b81d17243f60dfdcc2163fbb55e9223)`),this._subscribed=!0,V}catch(o){throw console.error(`${e} ${o.message}`),o}finally{R&&console.log(`${e} complete.`)}}async witness_unsubscribed(){let t=`${this.lc}[${this.witness_unsubscribed.name}]`;try{if(R&&console.log(`${t} starting... (I: 1beac551253e4c5694b63e0d36d5d5c0)`),this._subscribed==null)throw new Error("subscription never subscribed in the first place (this._subscribed === undefined) (E: b2c1b21a0e876a4908339a976924b923)");if(this._subscribed&&this._unsubscribed)throw new Error("(UNEXPECTED) both this._subscribed and this._unsubscribed true (E: a967e49de657a43929a74703c656ad23)");let e=this._unsubscribed===!0?xo:gs;return R&&console.log(`${t} result: ${H(e)} (I: b488cf36ce39e006a81d3ad3db5b4a23)`),e}catch(e){throw console.error(`${t} ${e.message}`),e}finally{R&&console.log(`${t} complete.`)}}async unsubscribe(){let t=`${this.lc}[${this.unsubscribe.name}]`;try{R&&console.log(`${t} starting... (I: ef7f3f4787a74fcca65d761880f44594)`);let e=await this.witness(M.primitive({ib:tr.unsubscribe}));if(!e)throw new Error("(UNEXPECTED) unsubscribe returned undefined? (E: 7013193490b94b6880f1049c36577d6f)");if(Ke({ibGib:e})){let o=e;throw new Error(`${o.data.raw} (E: fca1200dccb14f84968b2462f1b4c29e)`)}}catch(e){throw console.error(`${t} ${e.message}`),e}finally{R&&console.log(`${t} complete.`)}}async unsubscribed(){let t=`${this.lc}[${this.unsubscribed.name}]`;try{R&&console.log(`${t} starting... (I: 8ee9a93be61647d6aef6a4fa03e96dad)`);let e=await this.witness(M.primitive({ib:tr.unsubscribed}));if(!e)throw new Error("(UNEXPECTED) unsubscribe returned undefined? (E: 5051d7ff4a4d4bf7864c520b53f028d5)");let o=e.ib===xo.ib;return R&&console.log(`${t} resUnsubscribed: ${o} (I: b4800166c58d5ba2ca1dccaa53de2323)`),o}catch(e){throw console.error(`${t} ${e.message}`),e}finally{R&&console.log(`${t} complete.`)}}async validateThis(){let t=`${this.lc}[${this.validateThis.name}]`;try{return R&&console.log(`${t} starting...`),this.data,[]}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{R&&console.log(`${t} complete.`)}}async argy({argData:t,ibMetadata:e,noTimestamp:o,ibGibs:n}){let s=await pt({argData:t,ibMetadata:e,noTimestamp:o});return n&&(s.ibGibs=n),s}async resulty({resultData:t,ibGibs:e}){let o=await ht({resultData:t});return e&&(o.ibGibs=e),o}},Kr=class r extends vt{static{f(this,"Subscription_V1_Factory")}lc=`[${r.name}]`;getName(){return Xr.name}async newUp({data:t,rel8ns:e}){let o=`${this.lc}[${this.newUp.name}]`;try{R&&console.log(`${o} starting...`),t??=v(Tn),t=t,e=e??An?v(An):void 0,t.uuid||=await F();let{classname:n}=t,s=Yr({data:t}),a=await Te({parentPrimitiveIb:`witness ${n}`,ib:s,data:t,rel8ns:e}),i=new Xr(void 0,void 0);return await i.loadIbGibDto(a),R&&console.log(`${o} witnessDto: ${H(a)} (I: 5e41337176d1441f9a5c7b43664d43ef)`),{newIbGib:i}}catch(n){throw console.error(`${o} ${m({error:n})}`),n}finally{R&&console.log(`${o} complete.`)}}async witnessToForm({witness:t}){let e=`${this.lc}[${this.witnessToForm.name}]`;try{R&&console.log(`${e} starting...`);let{data:o}=t;if(!o)throw new Error("(UNEXPECTED) witness.data falsy? (E: ef44497ff97a4e5bac004d52c4ff40eb)");R&&console.log(`${e} data: ${H(o)} (I: c3f4c3d85386461aaefbe33524ff9cbd)`);let n=await Ct({n:100}),s=new Vr().with({idPool:n}).name({of:o.name,required:!1}).description({of:o.description??Hr}).and().and().uuid({of:o.uuid,required:!0}).classname({of:o.classname}).and().commonWitnessFields({data:o}).outputForm({formName:"form",label:"subscription"});return Promise.resolve(s)}catch(o){throw console.error(`${e} ${m({error:o})}`),o}finally{R&&console.log(`${e} complete.`)}}async formToWitness({form:t}){let e=v(Tn);return this.patchDataFromItems({data:e,items:t.items,pathDelimiter:yt}),await this.newUp({data:e})}};var Wr=!1;function qa({data:r}){let t=`[${qa.name}]`;try{if(Wr&&console.log(`${t} starting...`),!r)throw new Error("Subscription Data required (E: 6d1c97931dcab8ea9f3e9b32c794b90c)");let e=[],{name:o,uuid:n,classname:s}=r;return o?o.match(_n)||e.push(`name must match regexp: ${_n} (E: 21bf77e398d47e9d035376510505eda2)`):e.push("name required."),n?n.match(z)||e.push(`uuid must match regexp: ${z} (E: e53fd08ae69e945b37ed895b864b6bd7)`):e.push("uuid required."),s&&(s.match(Ve)||e.push(`classname must match regexp: ${Ve}`)),e}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{Wr&&console.log(`${t} complete.`)}}f(qa,"validateCommonSubscriptionData");function Yr({data:r,classname:t}){let e=`[${Yr.name}]`;try{let o=qa({data:r});if(o.length>0)throw new Error(`invalid Subscription data: ${o} (E: fd6b0b32d8f6c4b97eebd489cdb07a4a)`);if(t){if(r.classname&&r.classname!==t)throw new Error("classname does not match data.classname (E: 354285a56a20b9b65b06abfcd9f2e621)")}else if(t=r.classname,!t)throw new Error("classname required (E: 040c1fd71853fa7874146999afb355c3)");let{uuid:n}=r;return`witness ${ka} ${t} ${n}`}catch(o){throw console.error(`${e} ${m(o)}`),o}}f(Yr,"getSubscriptionIb");var Vr=class r extends Qe{static{f(this,"SubscriptionFormBuilder")}lc=`[${r.name}]`;constructor(){super(),this.what="subscription"}};function zr({ibGib:r}){let t=`[${zr.name}]`;try{if(Wr&&console.log(`${t} starting... (I: 43df7e7f61f25e65662ce8aa5a105a23)`),!r)return!1;let e=r;return typeof e.witness=="function"&&typeof e.unsubscribe=="function"&&typeof e.unsubscribed=="function"}catch(e){throw console.error(`${t} ${e.message}`),e}finally{Wr&&console.log(`${t} complete.`)}}f(zr,"isSubscription");async function Ha(){return(await new Kr().newUp({})).newIbGib}f(Ha,"newupSubscription");var Sn="observable_event";var Xa=!1;async function xn({eventType:r,srcObservable:t,payload:e}){let o=`[${xn.name}]`;try{if(Xa&&console.log(`${o} starting... (I: e2290f2f46d1993d6893a24c19100823)`),!t)throw new Error("srcObservable required (E: 3470a97bbf3802cbc8dd64339f5ef623)");if(!t.data)throw new Error("srcObservable.data required (E: df1786585ba849c08e7f4f1fddd30a31)");if(!t.data.uuid)throw new Error("srcObservable.data.uuid required (E: 173a1a53f274bc1cef879bad2288ca23)");if(!t.data.uuid.match(z))throw new Error(`valid srcObservable.data.uuid required. must pass UUID_REGEXP: ${z.source} (E: 10f4bd1863f18250cc79cd65221da223)`);let n={uuid:await F(),eventType:r,srcObservableId:t.data.uuid,"@srcObservableAddr":y({ibGib:t}),"@payloadAddr":y({ibGib:e})};return await Te({parentPrimitiveIb:Sn,ib:Ka({data:n}),data:n})}catch(n){throw console.error(`${o} ${n.message}`),n}finally{Xa&&console.log(`${o} complete.`)}}f(xn,"getObservableEventIbGib");function Ka({data:r,classname:t}){let e=`[${Ka.name}]`;try{if(t){if(r.classname&&r.classname!==t)throw new Error("classname does not match data.classname (E: 523aabc53fb944789202a5f468abd338)")}else if(t=r.classname,!t)throw new Error("classname required (E: d4401ea682894c5fa824b38d4989aa76)");if(!r.uuid)throw new Error("data.uuid required (E: 204cc7c20efd8a55263cdea8b1223e23)");return`${Sn} ${t} ${r.uuid}`}catch(o){throw console.error(`${e} ${m(o)}`),o}}f(Ka,"getObservableEventIb");var Y=!1,Jr=class r extends Nt{static{f(this,"ObservableBase_V1")}lc=`[${r.name}]`;metaspace;_subscribers={};_isComplete=!1;_pastPayloads=[];_pastError;get isCompleteOrErrored(){return this._isComplete||!!this._pastError}get isComplete(){return this._isComplete}get isErrored(){return!!this._pastError}constructor(t,e){super(t,e)}async witness(t){let e=`${this.lc}[${this.witness.name}]`;try{this._isInitialized||await this.initialized;let{ib:o}=t;if(!o)throw new Error("arg.ib required (E: 87659d093b82436ce2f7a87e402a5423)");if(mn({ibGib:t}))return this.witness_cmd({arg:t});if(wn({ibGib:t}))return this.witness_otherWitness({arg:t});throw new Error("unknown arg. expect observable cmd or ibgib witness (E: dc2667cffac5b8d7b1bf2ea737c81a23)")}catch(o){throw console.error(`${e} ${m(o)??"unknown error (E: 3e22bea4c7fb4668bf13d7146b927869)"}`),o}}async witness_cmd({arg:t}){let e=`${this.lc}[${this.witness_cmd.name}]`;try{if(Y&&console.log(`${e} starting... (I: 69257fac8328b9de9755fdd237b92723)`),t.data.cmd===ot.subscribe)return this.witness_subscribe_cmd({ibGib:t});throw new Error(`unknown command. must be of type ObservableCmd (${Ca}) (E: 5910e5cbafead25ea2917a65a3fc4123)`)}catch(o){throw console.error(`${e} ${o.message}`),o}finally{Y&&console.log(`${e} complete.`)}}async witness_otherWitness({arg:t}){let e=`${this.lc}[${this.witness_otherWitness.name}]`;try{return Y&&console.log(`${e} starting... (I: 871d0b7a2bef4596bad430f1cbacde02)`),zr({ibGib:t})?this.witness_subscriptionIbGib({arg:t}):this.witness_subscribe_nonCmdWitness({arg:t})}catch(o){throw console.error(`${e} ${o.message}`),o}finally{Y&&console.log(`${e} complete.`)}}async witness_subscriptionIbGib({arg:t}){let e=`${this.lc}[${this.witness_subscriptionIbGib.name}]`;try{if(Y&&console.log(`${e} starting... (I: 4ac764776ef7e3f9074eb95a999ba423)`),!t.data)throw new Error("arg.data required (E: 764ae772727ceba95a18140fdd938323)");let o=this.getSubscriberKey({subscription:t}),[n,s]=this._subscribers[o];if(t===n)delete this._subscribers[o];else throw new Error("(UNEXPECTED) arg and subscription are two different instances? (E: aab5ef9bdc92abb9e816e2c443ab5723)");return V}catch(o){throw console.error(`${e} ${o.message}`),o}finally{Y&&console.log(`${e} complete.`)}}async replayPastPayloads({observer:t,subscription:e}){let o=`${this.lc}[${this.replayPastPayloads.name}]`;try{Y&&console.log(`${o} starting... (I: b3c8f9c76a4af030cf52fdcf01c3fd23)`);let n=this.getSubscriberKey({subscription:e}),s=f(()=>!!this._subscribers[n],"fnStillSubscribed"),a=-1,i=!0;do if(a++,a<this._pastPayloads.length){if(!s()){Y&&console.log(`${o} subscription canceled before past payloads dispatch completed. (I: f1778f868446a518030d1cf7800c8a23)`);return}try{let c=this._pastPayloads[a];await t.next(c)}catch{console.error(`${o} observer errored on payload (i: ${a}). aborting replay (E: 1d7efc7c48e1491da4317ef333031077)`);return}}else i=!1;while(i);if(this.isErrored&&t.error&&s())try{await t.error(this._pastError)}catch{console.error(`${o} observer.error(this._pastError) errored itself (E: 18310e5e032345e7bdc3f2479807866c)`)}else if(this.isComplete&&t.complete&&s())try{await t.complete()}catch{console.error(`${o} observer.complete errored (E: d9d027f5520f4d7eadfc669d66b5b550)`)}}catch(n){throw console.error(`${o} ${n.message}`),n}finally{Y&&console.log(`${o} complete.`)}}async witness_subscribe_cmd({ibGib:t}){let e=`${this.lc}[${this.witness_subscribe_cmd.name}]`;try{if(Y&&console.log(`${e} starting... (I: 0c4c75c3fae297af6449c1048ce55423)`),(t.ibGibs??[]).length!==1)throw new Error("ibGib.ibGibs required. should contain one ObserverWitness (E: 3ed99b32e22284573c497df788a9f923)");let o=t.ibGibs[0],n=await Ha();return Y&&console.log(`${e} subscription created (I: 89ccd97803c66292f9d7334e1e2de523)`),await n.witness(this),await n.initialized,Y&&console.log(`${e} subscription initialized (after witnessing this observable as its src). (I: 3021483402b21c4df64a9173bd223a23)`),this._subscribers[this.getSubscriberKey({subscription:n})]=[n,o],Y&&console.log(`${e} stored subscriber (subscription, observer) (I: fb09660d885e33b80188dd0386ffc723)`),this.data.replay&&this._pastPayloads.length>0&&this.replayPastPayloads({observer:o,subscription:n}),n}catch(o){throw console.error(`${e} ${o.message}`),o}finally{Y&&console.log(`${e} complete.`)}}async witness_subscribe_nonCmdWitness({arg:t}){let e=`${this.lc}[${this.witness_subscribe_nonCmdWitness.name}]`;try{throw Y&&console.log(`${e} starting... (I: d9571dfcab4247d594c838233971886a)`),new Error("not impl (E: 76219cf238ba4f849480bd7c82eefab9)")}catch(o){throw console.error(`${e} ${o.message}`),o}finally{Y&&console.log(`${e} complete.`)}}async subscribe(t){let e=`${this.lc}[${this.subscribe.name}]`;try{Y&&console.log(`${e} starting... (I: 0dec9a06c562711e19482d45a7075e23)`);let o;if(gt({ibGib:t})){let n=await this.argy({argData:{cmd:ot.subscribe,ibGibAddrs:[y({ibGib:t})]},ibGibs:[t]});o=await this.witness(n)}else o=await this.witness(t);if(!zr({ibGib:o}))throw new Error("(UNEXPECTED) resSubscription is not a SubscriptionWitness? (E: c29bec4e3a48d6f1299143399ac55a23)");return o}catch(o){throw console.error(`${e} ${o.message}`),o}finally{Y&&console.log(`${e} complete.`)}}getSubscriberKey({subscription:t}){if(t.data?.uuid)return t.data.uuid;throw new Error("(UNEXPECTED) subscription.data.uuid falsy? (E: 8d078e6f8155f7567fd9378557e91823)")}async dispatchToEachSubscriber({payload:t,fnForObserver:e,observableEventType:o}){let n=`${this.lc}[${this.dispatchToEachSubscriber.name}]`;try{Y&&console.log(`${n} starting... (I: 0b990ce892f689d14458565717e66a23)`);let s=Object.values(this._subscribers);for(let a=0;a<s.length;a++){let[i,c]=s[a];if(gt({ibGib:c})){let l=c;await e(l,t),l.complete?await i.unsubscribed()?console.warn(`${n} (UNEXPECTED) subscriber reference still held but is unsubscribed? skipping for now (i.e. won't remove subscriber) in case that code is in yielded execution and just hasn't gotten around to it with event loop (but that would be weird). (W: 1d98f35d2fdd4345954c947265d9fb85)`):await l.complete():Y&&console.log(`${n} no error handler for observer. skipping. (I: 6a8a52c2012c464790eb406d2ae0383f)`)}else{let l=await xn({eventType:o,srcObservable:this,payload:t});await c.witness(l)}}}catch(s){throw console.error(`${n} ${s.message}`),s}finally{Y&&console.log(`${n} complete.`)}}async validateThis(){let t=`${this.lc}[${this.validateThis.name}]`;try{return Y&&console.log(`${t} starting...`),this.data,[]}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{Y&&console.log(`${t} complete.`)}}async argy({argData:t,ibMetadata:e,noTimestamp:o,ibGibs:n}){let s=await pt({argData:t,ibMetadata:e,noTimestamp:o});return n&&(s.ibGibs=n),s}async resulty({resultData:t,ibGibs:e}){let o=await ht({resultData:t});return e&&(o.ibGibs=e),o}};var C=!1,Zr=class r extends Jr{static{f(this,"Subject_V1")}lc=`[${r.name}]`;constructor(t,e){super(t,e)}asObservable(){return this}async subscribe(t){let e=`${this.lc}[${this.subscribe.name}]`;try{C&&console.log(`${e} starting... (I: 8e47b752314870ec78eb14342621f723)`);let o=await this.argy({argData:{cmd:nt.subscribe,ibGibAddrs:[y({ibGib:t})]},ibGibs:[t]});return await this.witness(o)}catch(o){throw console.error(`${e} ${o.message}`),o}finally{C&&console.log(`${e} complete.`)}}async next(t){let e=`${this.lc}[${this.next.name}]`;try{C&&console.log(`${e} starting... (I: b30363827c56450ca918c69aa15b0046)`);let o=await this.argy({argData:{cmd:nt.next,ibGibAddrs:[y({ibGib:t})]},ibGibs:[t]});await this.witness(o)}catch(o){throw console.error(`${e} ${o.message}`),o}finally{C&&console.log(`${e} complete.`)}}async error(t){let e=`${this.lc}[${this.error.name}]`;try{C&&console.log(`${e} starting... (I: 7fcc30e3763c429ea8b212491ad9455a)`);let o;if(typeof t=="string")o=await ut({rawMsg:t});else if(t instanceof Error||typeof t.message=="string")o=await ut({rawMsg:m(t)});else if(t.ib&&Ke({ibGib:t}))o=t;else throw new Error("unknown error type. shold either be ErrorIbGib_V1 or an Error instance or have error.message string property. (E: 2cfcab85439c3c845bfe18e8ecde3523)");let n=await this.argy({argData:{cmd:nt.error,ibGibAddrs:[y({ibGib:o})]},ibGibs:[o]});await this.witness(n)}catch(o){throw console.error(`${e} ${o.message}`),o}finally{C&&console.log(`${e} complete.`)}}async complete(){let t=`${this.lc}[${this.complete.name}]`;try{C&&console.log(`${t} starting... (I: 5faaf13c6b0543d399815c03b9cdf80c)`);let e=await this.argy({argData:{cmd:nt.complete}});await this.witness(e)}catch(e){throw console.error(`${t} ${e.message}`),e}finally{C&&console.log(`${t} complete.`)}}async witness_cmd({arg:t}){let e=`${this.lc}[${this.witness_cmd.name}]`;try{C&&console.log(`${e} starting... (I: 2bf7cbcadba446fa92cb649906b2b260)`);let{cmd:o}=t.data;switch(o){case nt.next:return this.witness_next({ibGib:t});case nt.error:return this.witness_error({ibGib:t});case nt.complete:return this.witness_complete({ibGib:t});default:return super.witness_cmd({arg:t})}}catch(o){throw console.error(`${e} ${o.message}`),o}finally{C&&console.log(`${e} complete.`)}}async witness_next({ibGib:t}){let e=`${this.lc}[${this.witness_next.name}]`;try{if(C&&console.log(`${e} starting... (I: 600da780f13f5137a2f76aad344b2923)`),this.isCompleteOrErrored)return C&&console.log(`${e} this.isCompleteOrErrored is true. returning early without producing. (I: aa823831853b134b19657c8673838c23)`),V;if((t.ibGibs??[]).length!==1)throw new Error("ibGib.ibGibs required. should contain one payload ibgib (E: 4046802ff96d4adfafcee7a74d96af5e)");let o=t.ibGibs[0];this.data.replay&&this._pastPayloads.push(o);let n=Object.values(this._subscribers);for(let s=0;s<n.length;s++){let[a,i]=n[s];if(C&&console.log(`${e} ensuring subscription not unsubscribed (I: ade3fd6d6ff2b5ec69eb8143e32ce223)`),!await a.unsubscribed())C&&console.log(`${e} subscription still active (I: b9ab83b28acecf0d823fdba46a81dc23)`),await i.next(o);else{debugger;console.warn(`${e} (UNEXPECTED) subscriber reference still held but is unsubscribed? skipping for now (i.e. won't remove subscriber) in case that code is in yielded execution and just hasn't gotten around to it with event loop (but that would be weird). (W: c116e799f6b9483c97fd030eb0dd09ea)`)}}return V}catch(o){throw console.error(`${e} ${o.message}`),o}finally{C&&console.log(`${e} complete.`)}}async witness_error({ibGib:t}){let e=`${this.lc}[${this.witness_error.name}]`;try{if(C&&console.log(`${e} starting... (I: 3367a73bc83c47f98d9ecfe426dc300e)`),(t.ibGibs??[]).length!==1)throw new Error("ibGib.ibGibs required. should contain one error ibgib (E: 905474b45bcb4f0abe7bd4618f08f32c)");let o=t.ibGibs[0];this._pastError=o;let n=Object.values(this._subscribers);for(let s=0;s<n.length;s++){let[a,i]=n[s];if(gt({ibGib:i})){let c=i;c.error?await a.unsubscribed()?console.warn(`${e} (UNEXPECTED) subscriber reference still held but is unsubscribed? skipping for now (i.e. won't remove subscriber) in case that code is in yielded execution and just hasn't gotten around to it with event loop (but that would be weird). (W: 8946e97f00fd4146a470064b490a4c29)`):await c.error(o):C&&console.log(`${e} no error handler for observer. skipping. (I: 59f4a1ee59a3a27d523d60cd761be923)`)}else await i.witness(o)}return V}catch(o){throw console.error(`${e} ${o.message}`),o}finally{C&&console.log(`${e} complete.`)}}async witness_complete({ibGib:t}){let e=`${this.lc}[${this.witness_complete.name}]`;try{C&&console.log(`${e} starting... (I: 4db180f465e24df9a4ded37fbd235558)`),this._isComplete=!0;let o=Object.values(this._subscribers);for(let n=0;n<o.length;n++){let[s,a]=o[n];if(gt({ibGib:a})){let i=a;i.complete?await s.unsubscribed()?console.warn(`${e} (UNEXPECTED) subscriber reference still held but is unsubscribed? skipping for now (i.e. won't remove subscriber) in case that code is in yielded execution and just hasn't gotten around to it with event loop (but that would be weird). (W: 1d98f35d2fdd4345954c947265d9fb85)`):await i.complete():C&&console.log(`${e} no error handler for observer. skipping. (I: 6a8a52c2012c464790eb406d2ae0383f)`)}else await a.witness(t)}return V}catch(o){throw console.error(`${e} ${o.message}`),o}finally{C&&console.log(`${e} complete.`)}}async validateThis(){let t=`${this.lc}[${this.validateThis.name}]`;try{return C&&console.log(`${t} starting...`),this.data,[]}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{C&&console.log(`${t} complete.`)}}async argy({argData:t,ibMetadata:e,noTimestamp:o,ibGibs:n}){if(t.cmd===ot.subscribe)return super.argy({argData:t,ibMetadata:e,noTimestamp:o,ibGibs:n});{let s=await pt({argData:t,ibMetadata:e,noTimestamp:o});return n&&(s.ibGibs=n),s}}async resulty({resultData:t,ibGibs:e}){let o=await ht({resultData:t});return e&&(o.ibGibs=e),o}},Qr=class r extends vt{static{f(this,"Subject_V1_Factory")}lc=`[${r.name}]`;getName(){return Zr.name}async newUp({data:t,rel8ns:e}){let o=`${this.lc}[${this.newUp.name}]`;try{C&&console.log(`${o} starting...`),t??=v(er),t=t,e=e??yn?v(yn):void 0,t.uuid||=await F();let{classname:n}=t,s=On({data:t}),a=await Te({parentPrimitiveIb:`witness ${n}`,ib:s,data:t,rel8ns:e}),i=new Zr(void 0,void 0);return await i.loadIbGibDto(a),C&&console.log(`${o} witnessDto: ${H(a)} (I: 6736d2b2ddf44fef9a1eb27078dfbf23)`),{newIbGib:i}}catch(n){throw console.error(`${o} ${m({error:n})}`),n}finally{C&&console.log(`${o} complete.`)}}async witnessToForm({witness:t}){let e=`${this.lc}[${this.witnessToForm.name}]`;try{C&&console.log(`${e} starting...`);let{data:o}=t;if(!o)throw new Error("(UNEXPECTED) witness.data falsy? (E: 7b70c96e982d4f81b6ffda54da16b3b8)");C&&console.log(`${e} data: ${H(o)} (I: 75abef56f5004a94b2113e3b1461ac25)`);let n=await Ct({n:100}),s=new eo().with({idPool:n}).name({of:o.name,required:!1}).description({of:o.description??Fr}).and().and().uuid({of:o.uuid,required:!0}).classname({of:o.classname}).and().commonWitnessFields({data:o}).outputForm({formName:"form",label:"observable"});return Promise.resolve(s)}catch(o){throw console.error(`${e} ${m({error:o})}`),o}finally{C&&console.log(`${e} complete.`)}}async formToWitness({form:t}){let e=v(er);return this.patchDataFromItems({data:e,items:t.items,pathDelimiter:yt}),await this.newUp({data:e})}};var to=!1;function Ya({data:r}){let t=`[${Ya.name}]`;try{if(to&&console.log(`${t} starting...`),!r)throw new Error("Subject Data required (E: 207a82725648e2ef234c8bd3fa1a5312)");let e=[],{name:o,uuid:n,classname:s}=r;return o?o.match($n)||e.push(`name must match regexp: ${$n} (E: de987eb8fea0b6232f60abf31815095c)`):e.push("name required."),n?n.match(z)||e.push(`uuid must match regexp: ${z} (E: 1a6dfda91ad51696f7456bc84dfea60e)`):e.push("uuid required."),s&&(s.match(Ve)||e.push(`classname must match regexp: ${Ve}`)),e}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{to&&console.log(`${t} complete.`)}}f(Ya,"validateCommonSubjectData");function On({data:r,classname:t}){let e=`[${On.name}]`;try{let o=Ya({data:r});if(o.length>0)throw new Error(`invalid Subject data: ${o} (E: 55620ac1f17e30a30a92850219f894ac)`);if(t){if(r.classname&&r.classname!==t)throw new Error("classname does not match data.classname (E: 20e86cca70130839a49ad011c9a7aafa)")}else if(t=r.classname,!t)throw new Error("classname required (E: 74e29ae0f618fee7e7ef72a30c654a6c)");let{name:n,uuid:s}=r;return`witness ${Br} ${t} ${n} ${s}`}catch(o){throw console.error(`${e} ${m(o)}`),o}}f(On,"getSubjectIb");var eo=class r extends Qe{static{f(this,"SubjectFormBuilder")}lc=`[${r.name}]`;constructor(){super(),this.what="subject"}};function gt({ibGib:r}){let t=`[${gt.name}]`;try{return to&&console.log(`${t} starting... (I: b54c252104f710c12951aa43b6ead323)`),typeof r.next=="function"}catch(e){throw console.error(`${t} ${e.message}`),e}finally{to&&console.log(`${t} complete.`)}}f(gt,"isObserver");async function Gm({data:r,replay:t}={}){let e=new Qr;return r??=v(er),t&&(r.replay=!0),(await e.newUp({data:r})).newIbGib}f(Gm,"newupSubject");var zc="hash-reveal-v1",Ce={hash_reveal_v1:zc},Va=Object.values(Ce);var Jc="top-up",Zc="replace-all",Qc="consume",el="delete-all",me={topUp:Jc,replaceAll:Zc,consume:Qc,deleteAll:el},Wa=Object.values(me);var tl="add-pool",rl="remove-pool",ol="replace-pool",nl="change-password",Lt={add_pool:tl,remove_pool:rl,replace_pool:ol,change_password:nl},Om=Object.values(Lt);var rr="keystone",Dn=/^\w[\w\-.]*$/,vn=/^[a-zA-Z0-9\-_]{1,64}$/,Nn=/^[a-zA-Z0-9_\-.]{1,63}$/,Ln=/^[a-zA-Z0-9\s.,!?:;'"\-()[\]_+=@#$%&*\/]{0,128}$/,za=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,Pn=1e3,Pt="revoke",he="manage",sl="sign",ro="sync",Ja="connect",Rn={REVOKE:Pt,MANAGE:he,SIGN:sl,SYNC:ro,CONNECT:Ja},Pm=Object.values(Rn);var Ye=he;var al=Ja,il=ro;var Za=200,Qa=2,ei=2,ti=5,ri=me.topUp,oi=we.sha_256,ni=1,si=2e3,ai=5,ii=5,ci=16,li=me.replaceAll,di=we.sha_512,fi=10,Et=50;var oo=class{static{f(this,"KeystoneStrategy")}config;constructor(t){this.config=t}};var cl="recursive-salt-wrap",Cn={recursive_salt_wrap:cl},bi=Object.values(Cn);var no=!1;async function ll({masterSecret:r,kdfOpts:t}){let e=`[${ll.name}]`;try{no&&console.log(`${e} starting... (I: 268e87ec311874ee6822bf459c5a5426)`);let o=t.strategy;switch(o){case Cn.recursive_salt_wrap:return await or({masterSecret:r,salt:t.salt,rounds:t.rounds,algorithm:t.algorithm});default:throw new Error(`Unknown KDF strategy: ${o}. valid values: ${bi.join(", ")} (E: c81258e9d9481eb0f88385a825193226)`)}}catch(o){throw console.error(`${e} ${m(o)}`),o}finally{no&&console.log(`${e} complete.`)}}f(ll,"deriveKey");async function or({masterSecret:r,salt:t,rounds:e,algorithm:o=we.sha_256}){let n=`[${or.name}]`;try{no&&console.log(`${n} starting... (I: 850868e50aba82ff28c77da8169e4c26)`);let s=r;for(let a=0;a<e;a++)s=await ce({s:`${t}${s}${t}`,algorithm:o});return s}catch(s){throw console.error(`${n} ${m(s)}`),s}finally{no&&console.log(`${n} complete.`)}}f(or,"kdf_recursiveSaltWrap");var so=class r extends oo{static{f(this,"KeystoneStrategy_HashRevealV1")}async derivePoolSecret({masterSecret:t}){let e=`[${r.name}.${this.derivePoolSecret.name}]`;try{let{salt:o,rounds:n,algo:s}=this.config;return await or({masterSecret:t,salt:o,rounds:n,algorithm:s})}catch(o){throw console.error(`${e} Error deriving pool secret: ${o.message}`),o}}async generateSolution({poolSecret:t,poolId:e,challengeId:o}){let n=`[${r.name}.${this.generateSolution.name}]`;try{let{rounds:s,algo:a}=this.config,i=o,c=t;for(let l=0;l<s;l++)c=await ce({s:`${i}${c}${i}`,algorithm:a});return{type:"hash-reveal-v1",poolId:e,challengeId:o,value:c}}catch(s){throw console.error(`${n} ${s.message}`),s}}async generateChallenge({solution:t}){let e=`[${r.name}.${this.generateChallenge.name}]`;try{let{rounds:o,algo:n}=this.config,{challengeId:s,value:a}=t,i=s,c=a;for(let l=0;l<o;l++)c=await ce({s:`${i}${c}${i}`,algorithm:n});return{id:s,type:"hash-reveal-v1",hash:c}}catch(o){throw console.error(`${e} ${o.message}`),o}}async validateSolution({solution:t,challenge:e}){let o=`[${r.name}.${this.validateSolution.name}]`;try{return t.type!=="hash-reveal-v1"||e.type!=="hash-reveal-v1"?(console.warn(`${o} Mismatched types provided.`),!1):(await this.generateChallenge({solution:t})).hash===e.hash}catch(n){return console.error(`${o} ${n.message}`),!1}}};async function Un({masterSecret:r}){let t=await ce({s:r,algorithm:we.sha_512});return await or({masterSecret:r,salt:t,rounds:1e3,algorithm:we.sha_512})}f(Un,"deriveDelegateSecret");var mt=class r{static{f(this,"KeystoneStrategyFactory")}static create({config:t}){let e=`[${r.name}.create]`;try{switch(t.type){case"hash-reveal-v1":return new so(t);default:throw new Error(`Unknown strategy type: ${t.type} (E: 4e3c2f7129a241c1b687555e678c1065)`)}}catch(o){throw console.error(`${e} ${o.message}`),o}}};var W=!1;async function ui({keystoneData:r}){let t=`[${ui.name}]`;try{return W&&console.log(`${t} starting... (I: c3022a146faac9730154f34d1439a225)`),[rr].join(" ")}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{W&&console.log(`${t} complete.`)}}f(ui,"getKeystoneIb");async function pi({ib:r}){let t=`[${pi.name}]`;try{W&&console.log(`${t} starting... (I: 73cb6832984255ed48b2f44db6a21e25)`);let[e]=r.split(" ");if(e!==rr)throw new Error(`invalid keystone ib. atom found in ib (${e}) does not match keystone atom (${rr}) (E: 79b3d587824c4271b6e60acc76e0c825)`);return{atom:e}}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{W&&console.log(`${t} complete.`)}}f(pi,"parseKeystoneIb");async function nr({ib:r}){try{return await pi({ib:r}),!0}catch{return!1}}f(nr,"validateKeystoneIb");function uw(r){if(!r||typeof r!="string")return!1;let t=r.trim();return t.length<3||t.length>254?!1:za.test(t)}f(uw,"validateEmail");async function hi({pool:r,requiredChallengeIds:t,targetAddr:e}){let o=r.config.behavior,n=new Set,s=Object.keys(r.challenges);if(t&&t.length>0){for(let a of t){if(!r.challenges[a])throw new Error(`(UNEXPECTED) Required challenge ID not found in pool: ${a} (E: 10c5619d80d8cf6cc84ffbf8be0dbc25)`);s.includes(a)&&n.add(a)}s=s.filter(a=>!n.has(a))}if(o.targetBindingCount>0&&e){let a=[...s].sort(),i=await ce({s:e});for(let c=0;c<o.targetBindingCount;c++){if(a.length===0)throw new Error("Entropy Exhaustion. Cannot satisfy target binding. Sorted available pool is empty. (E: 341b95dc3a58be3e083d1d9c4a0c4925)");let l=BigInt("0x"+i),d=Number(l%BigInt(a.length)),b=a[d];n.add(b),a.splice(d,1),s=s.filter(u=>u!==b),i=await ce({s:i})}}if(o.selectSequentially>0){if(s.length<o.selectSequentially)throw console.error(`[getDeterministicRequirements] Entropy Exhaustion! AvailableCount: ${s.length}, Required Seq: ${o.selectSequentially}. Available IDs: ${s.join(",")}`),new Error("Entropy Exhaustion. Insufficient challenges for FIFO requirement. (E: 9efa88003e1d5eccb837c85154ee5625)");s.slice(0,o.selectSequentially).forEach(i=>n.add(i)),s=s.slice(o.selectSequentially)}return{mandatoryIds:n,availableIds:s}}f(hi,"getDeterministicRequirements");function sr({pools:r,poolId:t,poolFilter:e,verb:o}){let n="[resolveTargetPool]";try{let s;if(t){if(s=r.find(a=>a.id===t),!s)throw new Error(`Pool not found with ID: ${t} (E: 4a2b17428515c1e82813158581898125)`)}else if(e){let a=r.filter(e);if(a.length===0)throw new Error("No pool matched the provided filter. (E: 5b3c27428515c1e82813158581898125)");s=a[0]}else{if(!o)throw new Error("Cannot auto-resolve pool without a verb. (E: 6c4d37428515c1e82813158581898125)");if(s=r.find(a=>a.config.allowedVerbs&&a.config.allowedVerbs.includes(o)),s||(s=r.find(a=>!a.config.allowedVerbs||a.config.allowedVerbs.length===0)),!s)throw new Error(`No suitable pool found for verb: ${o} (E: 7d5e47428515c1e82813158581898125)`)}if(o&&s.config.allowedVerbs&&s.config.allowedVerbs.length>0&&!s.config.allowedVerbs.includes(o))throw new Error(`Pool ${s.id} is not authorized for verb: ${o} (E: 8e6f57428515c1e82813158581898125)`);return s}catch(s){throw console.error(`${n} ${m(s)}`),s}}f(sr,"resolveTargetPool");async function wt({pool:r,targetAddr:t,requiredChallengeIds:e}){let o="[selectChallengeIds]";try{let{mandatoryIds:n,availableIds:s}=await hi({pool:r,requiredChallengeIds:e,targetAddr:t}),a=r.config.behavior.selectRandomly,i=[];if(a>0){if(s.length<a)throw new Error(`Insufficient challenges for random requirement. Need ${a}, have ${s.length} (E: 9f7a67428515c1e82813158581898125)`);let c=[...s].sort(()=>.5-Math.random());i.push(...c.slice(0,a))}return[...n,...i]}catch(n){throw console.error(`${o} ${m(n)}`),n}}f(wt,"selectChallengeIds");async function gi({salt:r,timestamp:t,index:e}){return(await ce({s:`${r}${t}${e}`})).substring(0,16)}f(gi,"generateOpaqueChallengeId");async function dl({prevPools:r,targetPoolId:t,consumedIds:e,masterSecret:o,strategy:n,config:s,verb:a}){let i="[applyReplenishmentStrategy]";try{let c=JSON.parse(JSON.stringify(r)),l=c.findIndex(g=>g.id===t);if(l===-1)throw new Error(`Target pool ${t} not found in keystone data. (E: 75200388d22744838634524233772545)`);let d=c[l],b=await n.derivePoolSecret({masterSecret:o}),u=Date.now().toString(),p=s.behavior.replenish;if(a===Pt&&(p=me.deleteAll),p===me.topUp){e.forEach(g=>delete d.challenges[g]);for(let g=0;g<e.length;g++){let h=await gi({salt:s.salt,timestamp:u,index:g}),E=await n.generateSolution({poolSecret:b,poolId:d.id,challengeId:h});d.challenges[h]=await n.generateChallenge({solution:E})}}else if(p===me.replaceAll)d.challenges=await co({config:s,masterSecret:o});else if(p===me.consume)e.forEach(g=>delete d.challenges[g]);else if(p===me.deleteAll)d.challenges={};else throw new Error(`Unknown replenish strategy: ${p}. Valid list: ${H(Wa)} (E: 0acf56f1e1486240080e11e8046d0825)`);return c}catch(c){throw console.error(`${i} ${m(c)}`),c}}f(dl,"applyReplenishmentStrategy");async function $t({targetPoolId:r,prevPools:t,masterSecret:e,challengeIds:o,claim:n,requiredChallengeIds:s}){let a="[solveAndReplenish]";try{W&&console.log(`${a} starting... poolId: ${r}, ids: ${o.length}`);let i=t.find(g=>g.id===r);if(!i)throw new Error(`Target pool not found: ${r} (E: a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6)`);let c=mt.create({config:i.config}),l=await c.derivePoolSecret({masterSecret:e});if(!await kn({pool:i,signingSecret:e}))throw new Error(`Crypto Violation: Invalid signing secret for pool: ${i.id} (E: 8a4c2b1d3e5f6a7b8c9d0e1f2a3b4c5f)`);let b=[];for(let g of o){let h=await c.generateSolution({poolSecret:l,poolId:i.id,challengeId:g});b.push(h)}let u={claim:n,solutions:b,requiredChallengeIds:s&&s.length>0?s:void 0},p=await dl({prevPools:t,targetPoolId:i.id,consumedIds:o,masterSecret:e,strategy:c,config:i.config,verb:n.verb});return{proof:u,nextPools:p}}catch(i){throw console.error(`${a} ${m(i)}`),i}}f($t,"solveAndReplenish");async function Ei({pool:r}){let t=`[${Ei.name}]`;try{if(W&&console.log(`${t} starting... (I: e2ffd568b698cc12d8c5e838d73ae726)`),!r.config)throw new Error("(UNEXPECTED) pool.configy falsy? (E: fcde88fe20e8004a58d7e445436bf526)");if(r.config.type!==Ce.hash_reveal_v1)throw new Error("(UNEXPECTED) pool.config.type !== KeystoneChallengeType.hash_reveal_v1? (E: e205f8872909c37168a624a9df778c26)");let e=[],{algo:o,rounds:n,salt:s}=r.config,a=[we.sha_256,we.sha_512];return o?a.includes(o)||e.push(`${t} invalid hash algorithm (${o}). Must be one of ${a}. (E: a22399ca3a68e63ffcc7507699be5826)`):e.push(`${t} algorithm required. (E: 8cd6bfb0590862b9bae24d98d2cf3826)`),n&&typeof n=="number"&&Number.isInteger(n)?n>Pn&&e.push(`${t} rounds too high. max rounds: ${Pn} (E: 31ce082f7fd88d6b58ef08a816458826)`):e.push(`${t} invalid rounds (${n}). must be positive integer. (E: 73c643ccda78afaf28d52a6871a9e826)`),s&&typeof s=="string"?vn.test(s)||e.push(`${t} invalid salt (${s.substring(0,99)}). Must match regexp ${vn}`):e.push(`${t} invalid salt (${s}). must be truthy string value. (E: 564a4844ec88fc1988197ce89c381426)`),e}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{W&&console.log(`${t} complete.`)}}f(Ei,"validateChallengePool_typeHashRevealV1");async function mi({pool:r}){let t=`[${mi.name}]`;try{W&&console.log(`${t} starting... (I: 1a0eafc158a83d1ba8fc019d5c979a26)`);let e=[];if(r.config){if(r.config.id?Dn.test(r.config.id)||e.push(`${t} pool.config.id is not formatted correctly. must pass regexp: ${Dn.source}`):e.push(`${t} pool.config.id falsy (E: 31d7943d95f877326d5f4ea14463d626)`),r.config.behavior){let{size:n,selectSequentially:s,selectRandomly:a,targetBindingCount:i}=r.config.behavior;(!n||n===0)&&e.push(`${t} invalid pool.config.behavior.size (${n}). Must be positive integer. (E: b221e36ec102bdc944552248ce8fe626)`);let c=(s||0)+(a||0)+(i||0);c>=n&&e.push(`${t} Total requested challenges (${c}) cannot equal or exceed pool size (${n}) to prevent full pool exposure and selection exhaustion. (E: 81cb834f826315264bca81c15fca58f1)`)}else e.push(`${t} pool.config.behavior falsy (E: bede081c066c39732eefe2f92e296326)`);let o=r.config.type;switch(o){case Ce.hash_reveal_v1:(await Ei({pool:r})).forEach(s=>e.push(s));break;default:throw new Error(`(UNEXPECTED) unknown pool.config.type (${o})? We only implement the following at this time: ${Va} (E: cce5285cf7580b8bc82172488eba2826)`)}}else e.push(`${t} pool.config falsy. (E: 8d05c875a1d2c58018a5eaf803977d26)`);return e}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{W&&console.log(`${t} complete.`)}}f(mi,"validateChallengePool");function wi({data:r}){let t="[validateKeystoneMetadata]",e=[],o=f((n,s)=>{n&&(n.username!==void 0&&(typeof n.username!="string"||!Nn.test(n.username))&&e.push(`${t} invalid username in ${s} (${n.username}). Must match ${Nn}`),n.description!==void 0&&(typeof n.description!="string"||!Ln.test(n.description))&&e.push(`${t} invalid description in ${s} (${n.description}). Must match ${Ln}`))},"checkDetails");return o(r.frameDetails,"frameDetails"),o(r.checkpointDetails,"checkpointDetails"),e}f(wi,"validateKeystoneMetadata");async function ao({keystoneIbGib:r}){let t=`[${ao.name}]`;try{W&&console.log(`${t} starting... (I: ec6ba82ec848b5ac3d8953e89d8d9826)`);let e=[],{data:o,rel8ns:n}=r;await nr({ib:r.ib})||e.push(`${t} invalid keystone ib (${r.ib}). (E: ad7a88bc38c290a184dfbd42be48f526)`),wi({data:o}).forEach(i=>e.push(i)),o.proofs&&o.proofs.length>0&&e.push(`${t} proofs already exist on genesis keystone. (E: 7a5e15f20918f1bbd8ffb62857dcd526)`);for(let i of o.challengePools)(await mi({pool:i})).forEach(l=>e.push(l)),(!i.challenges||Object.keys(i.challenges).length===0)&&e.push(`${t} invalid pool (${i.id}). pool.challenges is falsy/empty. (E: 8cd16a5416ae62a058342828be465b26)`);return o.revocationInfo&&e.push(`${t} genesis keystone already has revocationInfo. (E: e11408d0c558d0fa948efbce611ec826)`),e}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{W&&console.log(`${t} complete.`)}}f(ao,"validateGenesisKeystone");function fl({currDelegates:r,prevDelegates:t}){let e=r||{},o=t||{},n=Object.keys(e),s=Object.keys(o);if(n.length!==s.length)return!0;for(let a of n){let i=e[a],c=o[a];if(!c||i.delegateTjpAddr!==c.delegateTjpAddr||i.delegateAddr!==c.delegateAddr||i.thisAddr!==c.thisAddr)return!0}return!1}f(fl,"isDelegatesChanged");async function bl({currDelegates:r,prevIbGib:t,lc:e,errors:o}){let n=Object.keys(r),s=y({ibGib:t});for(let a of n){let i=r[a];a!==i.delegateTjpAddr&&o.push(`${e} Invalid delegate mapping: Key '${a}' does not match delegateTjpAddr '${i.delegateTjpAddr}'. (E: 9c8da8bc38c290a184dfbd42be48f526)`);let[c,l,d]=await Promise.all([nr({ib:i.delegateTjpAddr.split("^")[0]}),nr({ib:i.delegateAddr.split("^")[0]}),nr({ib:i.thisAddr.split("^")[0]})]);c||o.push(`${e} Delegate delegateTjpAddr '${i.delegateTjpAddr}' is not a valid keystone address. (E: 10d8a8bc38c290a184dfbd42be48f526)`),l||o.push(`${e} Delegate delegateAddr '${i.delegateAddr}' is not a valid keystone address. (E: 20d8a8bc38c290a184dfbd42be48f526)`),d||o.push(`${e} Delegate thisAddr '${i.thisAddr}' is not a valid keystone address. (E: 30d8a8bc38c290a184dfbd42be48f526)`),i.thisAddr===s||(t.rel8ns?.past||[]).includes(i.thisAddr)||o.push(`${e} Delegate thisAddr '${i.thisAddr}' is not a valid historical address in the parent keystone timeline. (E: 40d8a8bc38c290a184dfbd42be48f526)`);let u=i.allowedVerbs||[];(i.role==="sync-delegate"||u.includes("sync")||u.includes(ro))&&!i.spaceId&&o.push(`${e} Sync delegate '${i.delegateTjpAddr}' missing required spaceId. (E: 50d8a8bc38c290a184dfbd42be48f526)`)}}f(bl,"validateDelegates");async function ar({currentIbGib:r,prevIbGib:t}){let e=`[${ar.name}]`,o=[];try{if(!r)throw new Error("(UNEXPECTED) currentIbGib falsy? (E: 3c0f02655fa8279e386a079ebb604b25)");if(!t)throw new Error("(UNEXPECTED) prevIbGib falsy? (E: 0d07c812634d839c784f31b8848ba825)");let n=await oe({ibGib:r});n&&n.length>0&&o.push(...n);let s=r.data,a=t.data;await nr({ib:r.ib})||o.push(`${e} invalid keystone ib (${r.ib}). (E: a98dc8bc38c290a184dfbd42be48f526)`),wi({data:s}).forEach(h=>o.push(h));let l=s.delegates||{},d=a.delegates||{};fl({currDelegates:l,prevDelegates:d})&&(s.proofs?.some(E=>E.claim?.verb===he)||o.push(`${e} Policy Violation: Delegates map was mutated but no proof for manage verb ('${he}') is present. (E: 819fa8cb28c9b60e68994511a5825)`)),await bl({currDelegates:l,prevIbGib:t,lc:e,errors:o});let u=s.n??-2,p=a.n??-2;u<0&&o.push("invalid keystone.currData.n is undefined or null. (E: 9fbe38704b68829d18ea1d0940d0aa26)"),p<0&&o.push("invalid keystone.prevData.n is undefined or null. (E: 6dc5aa9c87017db6080ed4268b07af26)"),u!==p+1&&o.push(`keystone data.n values are not sequential. prevData.n: ${p}, currData.n: ${u}. (E: 5ae12809f2c67216d38d8ba8d6c42826)`);for(let h of s.proofs){if(h.solutions.length===0){o.push(`Proof ${h.id||"unknown"} has no solutions. (E: e2b4683ce0ce30f798ec77841e88c826)`);continue}let E=h.solutions[0].poolId,$=a.challengePools.find(I=>I.id===E);if(!$){o.push(`Proof references unknown pool: ${E}`);continue}await $i({proof:h,pool:$,errors:o})}if(s.revocationInfo){let h=s.revocationInfo.proof.claim.target,E=y({ibGib:t});h!==E&&o.push(`Revocation target mismatch. Expected ${E}, got ${h}`)}let g=new Set(s.proofs.map(h=>h.solutions?.[0]?.poolId).filter(Boolean));for(let h of s.proofs){let E=h.claim;if(E?.details){let $=E.details,I=$.type,A=$.info;if(I==="add-pool"){let w=A;if(!w||!Array.isArray(w.add)||w.add.length===0){o.push(`details type is '${I}' but payload is invalid. (E: 1fa2a8cb28c9b60e68994511a5825)`);continue}let _=new Set(a.challengePools.map(G=>G.id)),S=new Set(s.challengePools.map(G=>G.id));for(let G of w.add)S.has(G)||o.push(`ClaimDetails_AddPool lists pool ${G} but it is missing in the evolved keystone. (E: 2fa2a8cb28c9b60e68994511a5825)`),_.has(G)&&o.push(`ClaimDetails_AddPool attempts to add existing pool ${G}. (E: 3fa2a8cb28c9b60e68994511a5825)`);s.challengePools.length!==a.challengePools.length+w.add.length&&o.push(`Structural mismatch: expected ${a.challengePools.length+w.add.length} pools, found ${s.challengePools.length}. (E: 4fa2a8cb28c9b60e68994511a5825)`);for(let G of a.challengePools){let O=s.challengePools.find(U=>U.id===G.id);if(!O){o.push(`Existing pool ${G.id} was removed during add-pool transition. (E: 5fa2a8cb28c9b60e68994511a5825)`);continue}JSON.stringify(G.config)!==JSON.stringify(O.config)&&o.push(`Existing pool config ${G.id} was mutated during add-pool transition. (E: 6fa2a8cb28c9b60e68994511a5825)`),!g.has(G.id)&&JSON.stringify(G.challenges)!==JSON.stringify(O.challenges)&&o.push(`Existing pool challenges ${G.id} were mutated during add-pool transition. (E: 7fa2a8cb28c9b60e68994511a5825)`)}}else if(I==="replace-pool"){let w=A;if(!w||typeof w.replace!="string"||!w.replace){o.push(`details type is '${I}' but payload is invalid. (E: 8fa2a8cb28c9b60e68994511a5825)`);continue}let _=w.replace,S=a.challengePools.map(x=>x.id).sort(),G=s.challengePools.map(x=>x.id).sort();JSON.stringify(S)!==JSON.stringify(G)&&o.push("replace-pool transition mutated the pool IDs set. (E: 9fa2a8cb28c9b60e68994511a5825)");let O=a.challengePools.find(x=>x.id===_),U=s.challengePools.find(x=>x.id===_);(!O||!U)&&o.push(`Replaced pool ${_} not found in keystone challenge pools. (E: afa2a8cb28c9b60e68994511a5825)`);for(let x of a.challengePools){if(x.id===_)continue;let N=s.challengePools.find(k=>k.id===x.id);N&&(JSON.stringify(x.config)!==JSON.stringify(N.config)&&o.push(`Unrelated pool config ${x.id} was mutated during replace-pool. (E: bfa2a8cb28c9b60e68994511a5825)`),!g.has(x.id)&&JSON.stringify(x.challenges)!==JSON.stringify(N.challenges)&&o.push(`Unrelated pool challenges ${x.id} were mutated during replace-pool. (E: cfa2a8cb28c9b60e68994511a5825)`))}}else if(I==="remove-pool"){let w=A;if(!w||!Array.isArray(w.remove)||w.remove.length===0){o.push(`details type is '${I}' but payload is invalid. (E: b7a2a8cb28c9b60e68994511a5825)`);continue}let _=new Set(w.remove),S=new Set(a.challengePools.map(O=>O.id)),G=new Set(s.challengePools.map(O=>O.id));for(let O of w.remove)S.has(O)||o.push(`ClaimDetails_RemovePool lists pool ${O} but it is missing in the previous keystone. (E: c7a2a8cb28c9b60e68994511a5825)`),G.has(O)&&o.push(`ClaimDetails_RemovePool lists pool ${O} but it is still present in the evolved keystone. (E: d7a2a8cb28c9b60e68994511a5825)`);s.challengePools.length!==a.challengePools.length-w.remove.length&&o.push(`Structural mismatch: expected ${a.challengePools.length-w.remove.length} pools, found ${s.challengePools.length}. (E: e7a2a8cb28c9b60e68994511a5825)`);for(let O of a.challengePools){if(_.has(O.id))continue;let U=s.challengePools.find(x=>x.id===O.id);if(!U){o.push(`Pool ${O.id} was unexpectedly removed. (E: f7a2a8cb28c9b60e68994511a5825)`);continue}JSON.stringify(O.config)!==JSON.stringify(U.config)&&o.push(`Remaining pool config ${O.id} was mutated during remove-pool. (E: 07a2a8cb28c9b60e68994511a5825)`),!g.has(O.id)&&JSON.stringify(O.challenges)!==JSON.stringify(U.challenges)&&o.push(`Remaining pool challenges ${O.id} were mutated during remove-pool. (E: 17a2a8cb28c9b60e68994511a5825)`)}}else if(I==="change-password"){let w=A;if(!w||!Array.isArray(w.change)||w.change.length===0){o.push(`details type is '${I}' but payload is invalid. (E: dfa2a8cb28c9b60e68994511a5825)`);continue}let _=a.challengePools.map(O=>O.id).sort(),S=s.challengePools.map(O=>O.id).sort();JSON.stringify(_)!==JSON.stringify(S)&&o.push("change-password transition mutated the pool IDs set. (E: efa2a8cb28c9b60e68994511a5825)");let G=new Set(w.change);for(let O of a.challengePools){let U=s.challengePools.find(x=>x.id===O.id);if(U)if(G.has(O.id)){O.isForeign&&o.push(`Security Violation: Password rotation attempted on foreign pool ${O.id}. (E: ffa2a8cb28c9b60e68994511a5825)`);let x={...O.config,salt:""},N={...U.config,salt:""};JSON.stringify(x)!==JSON.stringify(N)&&o.push(`Pool config metadata for rotated pool ${O.id} was mutated. (E: 00b2a8cb28c9b60e68994511a5825)`),O.config.salt===U.config.salt&&o.push(`Pool salt for rotated pool ${O.id} was not rotated. (E: 01b2a8cb28c9b60e68994511a5825)`)}else JSON.stringify(O.config)!==JSON.stringify(U.config)&&o.push(`Unrelated pool config ${O.id} was mutated during change-password. (E: 02b2a8cb28c9b60e68994511a5825)`),!g.has(O.id)&&JSON.stringify(O.challenges)!==JSON.stringify(U.challenges)&&o.push(`Unrelated pool challenges ${O.id} were mutated during change-password. (E: 03b2a8cb28c9b60e68994511a5825)`)}}else o.push(`Unknown claim details type: ${I}`)}}return o}catch(n){throw console.error(`${e} ${m(n)}`),n}finally{W&&console.log(`${e} complete.`)}}f(ar,"validateKeystoneTransition");async function $i({proof:r,pool:t,errors:e}){let o=`[${$i.name}]`;try{W&&console.log(`${o} starting... (I: b8f9b6085888eea2258bf579ecd5e825)`),t.config.allowedVerbs&&t.config.allowedVerbs.length>0&&(!r.claim.verb||!t.config.allowedVerbs.includes(r.claim.verb))&&e.push(`Policy Violation: Pool ${t.id} used for unauthorized verb ${r.claim.verb}`);let{mandatoryIds:n,availableIds:s}=await hi({pool:t,requiredChallengeIds:r.requiredChallengeIds,targetAddr:r.claim.target}),a=new Set(r.solutions.map(d=>d.challengeId));for(let d of n)a.has(d)||e.push(`Policy Violation: Missing mandatory challenge ${d}`);let i=[...a].filter(d=>!n.has(d)),c=t.config.behavior.selectRandomly;i.length<c&&e.push(`Policy Violation: Insufficient random count. Need ${c}, got ${i.length}`);for(let d of i)s.includes(d)||e.push(`Policy Violation: ID ${d} is invalid or double-dipped.`);let l=mt.create({config:t.config});for(let d of r.solutions){let b=t.challenges[d.challengeId];b?await l.validateSolution({solution:d,challenge:b})||e.push(`Crypto Violation: Solution for ${d.challengeId} is invalid.`):e.push(`Crypto Violation: Challenge ${d.challengeId} not found in pool.`)}}catch(n){throw console.error(`${o} ${m(n)}`),n}finally{W&&console.log(`${o} complete.`)}}f($i,"verifyProofAgainstPool");async function st({prevIbGib:r,newData:t,metaspace:e,space:o}){let n=`[${st.name}]`;try{if(W&&console.log(`${n} starting... (I: 8b10e8920f08b7842803665834cf8925)`),!r.data)throw new Error("(UNEXPECTED) prevIbGib.data falsy? (E: 5e84875bf992c585b979e6c8ed5bf225)");if(r.data.revocationInfo)throw new Error(`Keystone has already been revoked (prevIbGib.data.revocationInfo truthy), so we cannot evolve the keystone. Keystone addr: ${y({ibGib:r})} (E: 45d7f846556829de6b2a701838c3f825)`);let s=r.data,a={};s.proofs&&(a.proofs=[]),s.challengePools&&(a.challengePools=[]),s.frameDetails&&(a.frameDetails={}),s.checkpointDetails&&(a.checkpointDetails={}),s.delegates&&(a.delegates="remove"),Object.keys(a).length===0&&(a=void 0);let i=await Me({src:r,dataToRemove:a,dataToAddOrPatch:t,nCounter:!0});if(i.intermediateIbGibs)throw new Error("(UNEXPECTED) resMut8.intermediateIbGibs truthy? I'm not sure if we expect there to be intermediateIbGibs, but I feel like we shouldn't. Pretty sure we shouldn't, definitely don't *want* them. (E: ba40d55d7c2d36d438c413886f148625)");if(i.dnas)throw new Error("(UNEXPECTED) resMut8.dnas truthy? We do not want dnas with keystones. (E: 49470513d018f97d28024f4e82da3b25)");let c=i.newIbGib,l=await ar({currentIbGib:c,prevIbGib:r});if(l.length>0)throw console.error(`${n} Validation Failed:
|
|
15
|
+
`)} (E: 8413594b6c1b447988781cf3f3e1729d)`)}}return b}catch(d){throw console.error(`${l} ${d.message}`),d}finally{j&&console.log(`${l} complete.`)}}f(bn,"getGraphProjection_getIbGibsInIbGibAddrs");async function Qt(r){let t=`[${Qt.name}]`;try{if(j&&console.log(`${t} starting... (I: 70508d7a5c63eae1f22ae851b32b3d22)`),!r.ibGib&&!r.ibGibAddr&&(r.ibGibs??[]).length===0&&(r.ibGibAddrs??[]).length===0)return{};let{ibGibs:e,ibGibAddrs:o,live:n,gotten:s,tjpAddrsAlreadyAnalyzed:a,skipAddrs:i,skipRel8nNames:c,onlyRel8nNames:l,maxRetries:d,msBetweenRetries:b,space:u,spaces:p,timeLogName:g,mapTjpAddrToLatestAddrsInSpace:h}=await Ta(r);if(g&&console.timeLog(g,`${t} starting...`),o?.length??!1){let $=await bn({ibGibs:e,ibGibAddrs:o,gotten:s,skipAddrs:i,maxRetries:d,msBetweenRetries:b,timeLogName:g,space:u,spaces:p});e=e?[...e,...$]:[...$]}o=e.map($=>y({ibGib:$}));let E=lr(e.map($=>$.ib).filter($=>$.startsWith("comment ")));return j&&console.log(`${t}[analyze debugging] ibGibs commentIbs: ${E.join(`
|
|
16
|
+
`)} (I: c89dc951315f746954f9bddbe8941122)`),n?Aa({ibGibs:e,ibGibAddrs:o,gotten:s,tjpAddrsAlreadyAnalyzed:a,skipAddrs:i,skipRel8nNames:c,onlyRel8nNames:l,maxRetries:d,msBetweenRetries:b,space:u,spaces:p,timeLogName:g,mapTjpAddrToLatestAddrsInSpace:h}):Ga({ibGibs:e,ibGibAddrs:o,gotten:s,skipAddrs:i,skipRel8nNames:c,onlyRel8nNames:l,maxRetries:d,msBetweenRetries:b,space:u,spaces:p,timeLogName:g})}catch(e){throw console.error(`${t} ${e.message}`),e}finally{j&&console.log(`${t} complete.`)}}f(Qt,"getGraphProjection");async function Hc({ibGibAddr:r,latestCommonFrameAddr:t,live:e,space:o,spaces:n}){let s=`[${Hc.name}]`;try{if(j&&console.log(`${s} starting... (I: 5d225e56dc11e62cd83c5366ea288826)`),r===t)return console.warn(`${s} ibGibAddr === latestCommonFrameAddr. So the delta graph is empty. what are we doing here? (W: e0c8287ae6de8152bf36b6c73ca59a26)`),{};let a=await Zt({ibGibAddr:t,live:!1,space:o,spaces:n});return await Zt({ibGibAddr:r,live:e,skipAddrs:Object.keys(a),space:o,spaces:n})}catch(a){throw console.error(`${s} ${m(a)}`),a}finally{j&&console.log(`${s} complete.`)}}f(Hc,"getDeltaDependencyGraph");async function Aa({ibGibs:r,ibGibAddrs:t,gotten:e,tjpAddrsAlreadyAnalyzed:o,mapTjpAddrToLatestAddrsInSpace:n,skipAddrs:s,skipRel8nNames:a,onlyRel8nNames:i,maxRetries:c,msBetweenRetries:l,space:d,spaces:b,timeLogName:u}){let p=`[${Aa.name}]`;try{let g=b??(d?[d]:[]);n=n??{},o=o??[];let h={...e};(r??[]).forEach(_=>h[y({ibGib:_})]=_);let E=zt({ibGibs:Object.values(h)});j&&console.log(`${p}[analyze debugging] timeline tjps(${Object.keys(E).length}): ${Object.keys(E)} (I: 509f04ac15ca08c5a3f0777b48934622)`);let $={};Object.keys(E).forEach(_=>{o.includes(_)||($[_]=E[_])}),j&&console.log(`${p}[analyze debugging] timelinesNotAnalyzed: ${H($)} (I: a4b67d95fdd6b98d3241c0a7d0a93c22)`);let I={},A={};Object.keys(E).filter(_=>!o.includes(_)).forEach(_=>{let S=E[_],G=S[S.length-1];I[_]=G;let O=y({ibGib:G});A[O]=_});let w=Object.keys(I).length;if(w>0){let _={};Object.keys(n).filter(N=>!o.includes(N)).forEach(N=>{let k=I[N];if(k){let ae=y({ibGib:k});_[ae]=n[N]}else console.error(`${p} latestIbGibCorrespondingToTjpAddr is falsy (E: 8a5d3f2e1c4b90876543210fe89abcdf)`)}),j&&console.log(`${p} latestAddrsMap *before* getLatestAddrs: ${H(_)} (I: 427b4bb78595e9e521ecf2c5e5c80722)`);let S=Object.values(I),G={};if(S.length>0){if(g.length===0)throw new Error("(UNEXPECTED) space/s falsy? (E: 8e878975e3561df9a8dc4c628b0abc23)");for(let N of g){let k=await Ce({ibGibs:S,space:N});if(!k?.data?.latestAddrsMap)throw new Error("(UNEXPECTED) getLatestAddrs result latestAddrsMap falsy (E: 088caa1fc95fd3b079108ab63ef33422)");let ae=k.data.latestAddrsMap;Object.keys(ae).forEach(ie=>{let q=ae[ie];q?G[ie]=q:G[ie]||(G[ie]=null)})}if(S.forEach(N=>{let k=y({ibGib:N});G[k]||(G[k]=k)}),Object.keys(G).length!==w)throw new Error("(UNEXPECTED) latestAddrsMap is not the same size as the incoming map (E: 666af512bbd44534983bb28ee8d43fed)");j&&console.log(`${p} queriedLatestAddrsMap: ${H(G)} (I: 7b39a5f7ce9e9d9fabae4be98ed44522)`),_={...G,..._}}j&&console.log(`${p} combined latestAddrsMap: ${H(_)} (I: e3aedea63f29c5b06a79632f691aa522)`);let O=[],U={};Object.values(I).forEach(N=>{let k=y({ibGib:N}),ae=A[k],ie=_[k];if(!ie)throw new Error("(UNEXPECTED) latestAddrInSpace not found in latestAddrsMap (E: 095d2b3f88e3e8a2c3e7d3de4c6d5622)");ie===k?(j&&console.log(`${p} analyzed ${ae} (I: afb7960900f04b8a87538f4c7bd903b7)`),o.push(ae)):(O.push(ie),U[ie]=ae)});let x=[];for(let N=0;N<(r??[]).length;N++){let ae=r[N].rel8ns??{};Object.keys(ae).filter(q=>!(a??[]).includes(q)).filter(q=>i?i.includes(q):!0).forEach(q=>{(ae[q]??[]).forEach(Ue=>{!x.includes(Ue)&&!r.some(Pt=>y({ibGib:Pt})===Ue)&&!Z({gib:C({ibGibAddr:Ue}).gib})&&x.push(Ue)})})}return t=lr([...t??[],...x,...O]),await Qt({ibGibs:r,ibGibAddrs:t,gotten:e,tjpAddrsAlreadyAnalyzed:o,skipAddrs:s,skipRel8nNames:a,onlyRel8nNames:i,maxRetries:c,msBetweenRetries:l,space:d,spaces:g,timeLogName:u,live:!0,mapTjpAddrToLatestAddrsInSpace:n})}else return r||(r=[]),Object.values(e??{}).forEach(_=>{let S=y({ibGib:_});r.some(G=>y({ibGib:_})===S)||r.push(_)}),await Qt({ibGibs:r,ibGibAddrs:t,gotten:e,skipAddrs:s,skipRel8nNames:a,onlyRel8nNames:i,maxRetries:c,msBetweenRetries:l,space:d,spaces:g,timeLogName:u,live:!1})}catch(g){let h=`${p} ${g.message}`;throw console.error(h),u&&console.timeLog(u,`${p} error: ${h}`),g}finally{u&&console.timeLog(u,`${p} complete.`)}}f(Aa,"getGraphProjection_Live");async function Ga({ibGibs:r,ibGibAddrs:t,gotten:e,skipAddrs:o,skipRel8nNames:n,onlyRel8nNames:s,maxRetries:a,msBetweenRetries:i,space:c,spaces:l,timeLogName:d}){let b=`[${Ga.name}]`;try{let u=[];r??=[],e??={},o??=[],n??=[],d&&console.timeLog(d,`${b} analyzing next step starting...`);for(let p=0;p<r.length;p++){let g=r[p],h=y({ibGib:g}),{gib:E}=C({ibGib:g});if(E===L)throw new Error("cannot get dependency graph of primitive. (E: 5493b8908d134bdf887e91122a6a57e3)");Object.keys(e).includes(h)||(e[h]=g);let $={},I=g.rel8ns||{},A=(Object.keys(I)||[]).filter(_=>!n.includes(_));s&&(A=A.filter(_=>s.includes(_)));let w=Object.keys(e);for(let _=0;_<A.length;_++){let S=A[_],G=I[S]??[],O=G.filter(x=>x===""||x===void 0||x===null||!x.includes(J));O.length>0&&console.warn(`${b} (UNEXPECTED) has falsyAddrs: ${O} (W: da9505cb0a4db68a4aff7f279ad2d322)`),G.filter(x=>!!x).filter(x=>!w.includes(x)).filter(x=>!o.includes(x)).filter(x=>C({ibGibAddr:x}).gib!==L).filter(x=>!u.includes(x)).forEach(x=>{let N=kt({addr:x});(N||[]).length===0?u.push(x):$[x]=N})}if(Object.keys($).length>0)throw new Error(`invalid addresses found in dependency graph. Errors (clipped to 1kB): ${JSON.stringify($).substring(0,1024)} (E: d2416b9b23fa4d178e6c7104b40ee78c)`)}if(d&&console.timeLog(d,`${b} analyzing next step complete.`),u.length>0){d&&console.timeLog(d,`${b} get addrsWeDontHaveAlready_Rel8dAddrs starting...`);let p=await bn({ibGibAddrs:u,gotten:e,skipAddrs:o,maxRetries:a,msBetweenRetries:i,timeLogName:d,space:c,spaces:l});p.forEach(h=>e[y({ibGib:h})]=h),d&&console.timeLog(d,`${b} call getGraphProjection recursively starting...`);let g=await Qt({ibGibs:p,live:!1,gotten:e,skipAddrs:o,skipRel8nNames:n,onlyRel8nNames:s,maxRetries:a,msBetweenRetries:i,space:c,spaces:l});return d&&console.timeLog(d,`${b} call getGraphProjection recursively complete.`),g}else return e}catch(u){let p=`${b} ${u.message}`;throw console.error(`${p} (E: 8a42e56616014e7a8848aa6bb6f2722b)`),d&&console.timeLog(d,`${b} error: ${p}`),new Error(`${p} (E: a21b0682121746a480572b83413cf2d0)`)}finally{d&&console.timeLog(d,`${b} complete.`)}}f(Ga,"getGraphProjection_NonLive");function kr({ibGibs:r}){let t=`[${kr.name}]`;try{if(j&&console.log(`${t} starting... (I: 6019a812cff8597f79c12088e45cc226)`),r){let e={};return r.forEach(o=>{e[y({ibGib:o})]=o}),e}else return}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{j&&console.log(`${t} complete.`)}}f(kr,"toFlatGraph");function Xc({graphA:r,graphB:t,slowButThorough:e}){let o=`[${Xc.name}]`;try{if(j&&console.log(`${o} starting... (I: e50a98b659189dece8b4ef581e4ad826)`),!(Object.keys(r).length===Object.keys(t).length))return j&&console.log(`${o} not the same size. false. (I: e1044e52421dbf7e067e0fe850ac6826)`),!1;for(let s of Object.keys(r))if(!t[s])return j&&console.log(`${o} addr (${s}) in graphA not found in graphB (I: 264c68408378ce30b8f6a978f8b86926)`),!1;if(e)for(let s of Object.keys(r)){let a=Pe({ibGib:r[s]}),i=JSON.stringify(a),c=Pe({ibGib:t[s]}),l=JSON.stringify(c);if(i!==l)return j&&console.log(`${o} jsonA !== jsonB for addr (${s}) (I: 98ed9f58ac88dabba83f96582f725926)`),!1}return!0}catch(n){throw console.error(`${o} ${m(n)}`),n}finally{j&&console.log(`${o} complete.`)}}f(Xc,"graphsAreEquivalent");var be=!1;async function un({timeline:r}){let t=`[${un.name}]`;try{if(be&&console.log(`${t} starting...`),Z({ibGib:r}))return console.warn(`${t} getting lock scope on a primitive ibgib can grossly impact performance. (W: 55203e415ae2ac7ddb19c21772b28925)`),y({ibGib:r});{let e=re({gib:r.gib}),o=e.tjpGib??e.punctiliarHash;if(!o)throw new Error(`${t} (UNEXPECTED) Could not determine tjpGib or punctiliarHash from ibGib. (E: eb3b6472e9b335991a1b0869f772f7d3)`);return o}}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{be&&console.log(`${t} complete.`)}}f(un,"getLockScope");async function Kc({timeline:r,rel8nInfos:t,rel8nRemovalInfos:e,timelineIndexInfo:o,metaspace:n,space:s,skipLock:a,noDna:i}){let c=`[${Kc.name}]`;try{if(be&&console.log(`${c} starting... (I: fcdff10832215068019355265f4cbc25)`),s??=await n.getLocalUserSpace({lock:!1}),!s)throw new Error("(UNEXPECTED) space falsy? couldn't even get default local user space? (E: 2051b44a052d6a2984b9a22f680e4625)");let l=await un({timeline:r}),d=f(async()=>{if(!s)throw new Error("(UNEXPECTED) space falsy? couldn't even get default local user space? (E: 845c4181c8c15d7219166ceb3c4dca25)");let u=y({ibGib:r}),p=await n.getLatestAddr({addr:u,space:s});if(!p)throw new Error(`${c} (UNEXPECTED) Could not get latest address for timeline ${y({ibGib:r})}. (E: a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9)`);let g=Pe({ibGib:r});if(u!==p){let A=await n.get({addrs:[p],space:s});if(A.errorMsg||(A.ibGibs??[]).length!==1)throw new Error(`${c} (UNEXPECTED) couldn't get latest timeline ibgib (${p}) from space (${s.ib}). errorMsg: ${A.errorMsg??"[unknown error]"} (E: b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0)`);g=A.ibGibs.at(0)}let h;if(e&&e.length>0){h={};for(let A of e){let{rel8nName:w,ibGibAddrs:_}=A;if(_.length===0){console.warn(`${c} tried to remove 0 ibGibAddrs in rel8nName ${w}? skipping... (W: 93aeb601be66d680989e72ec70e4c826)`);continue}h[w]||(h[w]=[]),h[w]=h[w].concat(_)}}let E={};for(let A of t){let{rel8nName:w,ibGibs:_}=A;if(_.length===0){console.warn(`${c} tried to add 0 ibGibs to rel8nName ${w}? skipping... (W: 708252dfdeb60757fee4554e769aaa25)`);continue}E[w]||(E[w]=[]),E[w].push(..._.map(S=>y({ibGib:S})))}let $=await Ie({src:g,rel8nsToRemoveByAddr:h,rel8nsToAddByAddr:E,dna:!i,nCounter:!0}),I=$.newIbGib;return await n.persistTransformResult({resTransform:$,space:s}),o&&await pn({type:o.type,rel8nInfos:[{rel8nName:o.rel8nName,ibGibs:[I]}],metaspace:n,space:s,skipLock:a}),await n.registerNewIbGib({ibGib:I,space:s}),I},"fn");return a?await d():await Ae({scope:l,secondsValid:180,maxDelayMs:100,maxLockAttempts:1800,space:s,callerInstanceId:ge(),fn:d})}catch(l){throw console.error(`${c} ${m(l)}`),l}finally{be&&console.log(`${c} complete.`)}}f(Kc,"appendToTimeline");async function pn({type:r,rel8nInfos:t,dataToAddOrPatch:e,metaspace:o,space:n,skipLock:s}){let a=`[${pn.name}]`;try{if(be&&console.log(`${a} starting... (I: 6e7d05fe916d813b71766e2eaa747c25)`),r==="latest")throw new Error('cannot update the "latest" special index by this function. The registerNewIbGib will do this automatically. (E: 231eb78a221ccdbcf56cd1899260a425)');if(n??=await o.getLocalUserSpace({lock:!1}),!n)throw new Error("(UNEXPECTED) space falsy? couldn't even get default local user space? (E: 43067821a4749a7648fe2612d25d7f25)");let i=f(async()=>{let c=f(async()=>{let l=await o.getSpecialIbGib({type:r,space:n,initialize:!0});if(!l)throw new Error(`(UNEXPECTED) couldn't initialize/get special ibgib index of type ${r}. (E: a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6)`);return l.rel8ns||console.warn(`${a} not sure if this ever hits, but is there ever a scenario where specialIndex.rel8ns is falsy? (W: 06161c366bc7ec858b9b5aa7ee9b6d25)`),l},"fnGetSpecialIndex");for(let l of t??[]){let{rel8nName:d,ibGibs:b}=l;b.length===0&&console.error(`${a} ibGibs empty. skipping rel8nName (${d}). (E: 150d74f73f97aea1b97d173d92c77125)`);let p=(await c()).rel8ns??{},g,h=p[d]??[];if(h.length>0){let E=new Set;b.forEach($=>{let I=y({ibGib:$}),A=$.rel8ns?.past??[];h.filter(w=>[...A,I].includes(w)).forEach(w=>E.add(w))}),E.size>0&&(g=Array.from(E))}await o.rel8ToSpecialIbGib({type:r,rel8nName:d,ibGibsToRel8:b,addrsToUnRel8:g,space:n,linked:!1,severPast:!1,deletePreviousSpecialIbGib:!1})}if(Object.keys(e??{}).length>0){let l=await c(),d=await Me({src:l,dataToAddOrPatch:e,dna:!1,linkedRel8ns:[K.past],nCounter:!0}),b=d.newIbGib;await ee({resTransform:d,space:n});let u=Q({type:r});await o.setConfigAddr({key:u,addr:y({ibGib:b}),space:n}),await o.registerNewIbGib({ibGib:b,space:n})}},"fn");s?await i():await Ae({scope:r,secondsValid:60,maxDelayMs:100,maxLockAttempts:600,space:n,fn:i})}catch(i){throw console.error(`${a} ${m(i)}`),i}finally{be&&console.log(`${a} complete.`)}}f(pn,"updateSpecialIndex");async function hn({timeline:r,timelineAddr:t,metaspace:e,space:o}){let n=`[${hn.name}]`;try{if(be&&console.log(`${n} starting... (I: f2b605361368e1956f6db878dbfeb825)`),!r&&!t)throw new Error("either timeline or timelineAddr required. (E: 97551b2b18ecd22a18185a783f9a0825)");t??=y({ibGib:r});let s=await e.getLatestAddr({addr:t,space:o})??t;if(!s)throw new Error(`${n} (UNEXPECTED) Could not get latest address for timeline ${y({ibGib:r})}. (E: a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9)`);let a;if(t===s){if(!r){let i=await e.get({addrs:[s],space:o});if(i.errorMsg||(i.ibGibs??[]).length!==1)throw new Error(`${n} (UNEXPECTED) couldn't get latest timeline ibgib (${s}) from space (${o.ib}). errorMsg: ${i.errorMsg??"[unknown error]"} (E: 3fc767a594788a43a4ba18c87491a825)`);r=i.ibGibs.at(0)}a=Pe({ibGib:r})}else{let i=await e.get({addrs:[s],space:o});if(i.errorMsg||(i.ibGibs??[]).length!==1)throw new Error(`${n} (UNEXPECTED) couldn't get latest timeline ibgib (${s}) from space (${o.ib}). errorMsg: ${i.errorMsg??"[unknown error]"} (E: b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0)`);a=i.ibGibs.at(0)}return a}catch(s){throw console.error(`${n} ${m(s)}`),s}finally{be&&console.log(`${n} complete.`)}}f(hn,"getLatestTimelineIbGibDto_nonLocking");async function Vc({timeline:r,timelineAddr:t,mut8Opts:e,metaspace:o,space:n,skipLock:s,timelineIndexInfo:a,noDna:i}){let c=`[${Vc.name}]`;try{if(be&&console.log(`${c} starting... (I: genuuid)`),!r&&!t)throw new Error("(UNEXPECTED) both timeline and timelineAddr falsy? either one is required. (E: a19d98c6acb87af3b876c1484f6ac825)");if(n??=await o.getLocalUserSpace({lock:!1}),!n)throw new Error("(UNEXPECTED) space falsy? couldn't even get default local user space? (E: genuuid)");if(!r){let u=await o.get({addrs:[t],space:n});if(!u.success||u.ibGibs?.length!==1)throw new Error(`couldn't get timeline ibGib from timelineAddr (${t}) in space (${n?.ib??"undefined"}) (E: genuuid)`);r=u.ibGibs.at(0)}let l=await un({timeline:r}),d=f(async()=>{if(!n)throw new Error("(UNEXPECTED) space falsy? couldn't even get default local user space? (E: 845c4181c8c15d7219166ceb3c4dca25)");if(!r)throw new Error("(UNEXPECTED) timeline falsy? we should be ensured that it's truthy at this point. (E: 2e1758b2cc3820531f7ac7f5f6b3a825)");let u=await hn({timeline:r,metaspace:o,space:n}),p=await Me({...e,src:u,dna:!i,nCounter:!0}),g=p.newIbGib;return await o.persistTransformResult({resTransform:p,space:n}),a&&await pn({type:a.type,rel8nInfos:[{rel8nName:a.rel8nName,ibGibs:[g]}],metaspace:o,space:n,skipLock:s}),await o.registerNewIbGib({ibGib:g,space:n}),g},"fn");return s?await d():await Ae({scope:l,secondsValid:180,maxDelayMs:100,maxLockAttempts:1800,space:n,callerInstanceId:ge(),fn:d})}catch(l){throw console.error(`${c} ${m(l)}`),l}finally{be&&console.log(`${c} complete.`)}}f(Vc,"mut8Timeline");async function Yc({ib:r,data:t,rel8ns:e,noDna:o,parentIb:n,parentIbGib:s,metaspace:a,space:i}){let c=`[${Yc.name}]`;try{if(be&&console.log(`${c} starting...`),i??=await a.getLocalUserSpace({lock:!1}),!i)throw new Error("(UNEXPECTED) space is required, but is falsy. (E: 252994a554224b17aa9816c7a765c925)");s??=n?s=M.primitive({ib:n}):s=Y;let l=await M.firstGen({parentIbGib:s,ib:r,data:t,rel8ns:e,dna:!o,nCounter:!0,squash:!!o,tjp:{timestamp:!0,uuid:!t?.uuid}});return await a.persistTransformResult({resTransform:l,space:i}),await a.registerNewIbGib({ibGib:l.newIbGib,space:i}),l}catch(l){throw console.error(`${c} ${m(l)}`),l}}f(Yc,"createTimeline");async function Sa({ibGib:r,metaspace:t,space:e}){let o=`[${Sa.name}]`;try{if(be&&console.log(`${o} starting...`),e??=await t.getLocalUserSpace({lock:!1}),!e)throw new Error("(UNEXPECTED) space is required. (E: c1b9a9b8c7d6e5f4a3b2a1a0b9c8d7e6)");let n=r.rel8ns?.dna??[];if(n.length===0)return[];let s=await t.get({addrs:n,space:e});if(!s.success||(s.ibGibs??[]).length!==n.length){let a=n.filter(i=>!s.ibGibs?.some(c=>y({ibGib:c})===i));throw new Error(`Could not get all dna ibGibs for ${y({ibGib:r})}. Addrs not found: ${a.join(", ")}. Errors: ${s.errorMsg??"[unknown error (E: 92cf95774828d8a978331da859098625)]"} (E: d2c0b1a9a8b7c6d5e4f3a2b1a0b9c8d7)`)}return s.ibGibs}catch(n){throw console.error(`${o} ${m(n)}`),n}}f(Sa,"getDna");async function xa({timeline:r,getLatest:t,includeDna:e,metaspace:o,space:n}){let s=`[${xa.name}]`;try{if(be&&console.log(`${s} starting... (I: 7fbc442a27e8f9fda8ac4228ded84825)`),n??=await o.getLocalUserSpace({lock:!1}),!n)throw new Error("(UNEXPECTED) space is required. (E: e3d1c0b1a9a8b7c6d5e4f3a2b1a0b9c8)");let a=t?await hn({timeline:r,metaspace:o,space:n}):Pe({ibGib:r}),i=y({ibGib:a}),c={},l=e?kr({ibGibs:await Sa({ibGib:a,metaspace:o,space:n})}):void 0,d=r.rel8ns?.past??[];if(d.length===0)return{headIbGib:a,orderedPastIbGibs:[],pastIbGibMap:c,dnaMap:l};let b=await o.get({addrs:d,space:n});if(!b.success||(b.ibGibs??[]).length!==d.length){let p=d.filter(g=>!b.ibGibs?.some(h=>y({ibGib:h})===g));throw new Error(`Could not get all dna ibGibs for ${i}. Addrs not found: ${p.join(", ")}. Errors: ${b.errorMsg??"[unknown error (E: 887339d8b5580ed1ac9892a554255525)]"} (E: 4ab7a8a58adff4e238171f7c110c6825)`)}c=kr({ibGibs:b.ibGibs})??{};let u=[];for(let p of d){let g=c[p];if(!g)throw new Error("(UNEXPECTED) pastIbGib falsy? due to our logic, the pastIbGibMap should be complete. (E: 6010d8c14184124008631928e1265525)");u.push(g)}return{headIbGib:a,orderedPastIbGibs:u,pastIbGibMap:c,dnaMap:l}}catch(a){throw console.error(`${s} ${m(a)}`),a}finally{be&&console.log(`${s} complete.`)}}f(xa,"getHistory");async function Wc({timeline:r,getLatest:t,metaspace:e,space:o}){let n=`[${Wc.name}]`;try{return be&&console.log(`${n} starting... (I: c7a328b14018642138ebb47870c15626)`),(await xa({timeline:r,getLatest:t,includeDna:!1,metaspace:e,space:o})).orderedPastIbGibs.map(i=>y({ibGib:i}))}catch(s){throw console.error(`${n} ${m(s)}`),s}finally{be&&console.log(`${n} complete.`)}}f(Wc,"getHistoryAddrs");var tt=!1,gn=class r{static{f(this,"IbGibApiBridge")}lc=`[${r.name}]`;async parseResponseJson(t,e){let o=t.headers.get("content-type")||"";if(!o.includes("application/json")){let n=await t.text();throw n.trim().toLowerCase().startsWith("<!doctype html")||n.includes("<html")?new Error(`API request to '${e}' failed (${t.status} ${t.statusText}): Received HTML fallback instead of JSON. Check API route matching and parameters.`):new Error(`API request to '${e}' failed (${t.status} ${t.statusText}): Returned non-JSON content type '${o}': ${n.slice(0,150)}`)}return await t.json()}async postGenesisKeystone(t){let e=`${this.lc}[${this.postGenesisKeystone.name}]`;try{tt&&console.log(`${e} starting... (I: eecd082fc4a4381c8857928e8b090826)`);let o="/api/keystone/genesis",n=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({keystoneIbGib:t})}),s=await this.parseResponseJson(n,o);if(!n.ok){let a=s.message||s.error||"Unknown error";return console.error(`${e} server rejected genesis keystone: ${a}`),{success:!1,message:a,addr:s.addr,statusCode:n.status}}return tt&&console.log(`${e} genesis keystone posted successfully. pending: ${s.pending}`),{success:!0,pending:!!s.pending,statusCode:n.status,addr:s.addr,message:s.message}}catch(o){let n=m(o);return console.error(`${e} error: ${n}`),{success:!1,message:n}}}async putEvolveKeystone({domainAddr:t,keystoneIbGib:e,relatedKeystoneIbGibs:o=[],revokeTokens:n}){let s=`${this.lc}[${this.putEvolveKeystone.name}]`;try{tt&&console.log(`${s} posting evolved keystone...`);let a=`/api/keystone/evolve/${encodeURIComponent(t)}`,i=await fetch(a,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({keystoneIbGib:e,relatedKeystoneIbGibs:o,revokeTokens:n})}),c=await this.parseResponseJson(i,a);if(!i.ok){let l=c.message||c.error||"Unknown error";return console.error(`${s} server rejected keystone evolution: ${l}`),{success:!1,message:l}}return tt&&console.log(`${s} keystone evolution accepted by server.`),{success:!0}}catch(a){let i=m(a);return console.error(`${s} fetch error: ${i}`),{success:!1,message:i}}}async lookupPrimaryKeystone({identifier:t}){let e=`${this.lc}[${this.lookupPrimaryKeystone.name}]`;try{let o="/api/keystone/lookup",n=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({identifier:t})}),s=await this.parseResponseJson(n,o);if(!n.ok){let a=s.message||s.error||"Identity not found";return console.error(`${e} server lookup failed: ${a}`),{success:!1,message:a}}return{success:!0,tjpAddr:s.tjpAddr,primaryKeystoneIbGib:s.primaryKeystoneIbGib}}catch(o){let n=m(o);return console.error(`${e} lookup fetch error: ${n}`),{success:!1,message:n}}}async checkEmailAvailability({email:t}){let e=`${this.lc}[${this.checkEmailAvailability.name}]`;try{let o=`/api/keystone/check-email?email=${encodeURIComponent(t)}`,n=await fetch(o,{method:"GET",headers:{"Content-Type":"application/json"}}),s=await this.parseResponseJson(n,o);if(!n.ok){let a=s.message||s.error||"Server check failed";return console.error(`${e} email check failed: ${a}`),{available:!1,message:a}}return{available:s.available??!0,message:s.message}}catch(o){let n=m(o);return console.error(`${e} check email error: ${n}`),{available:!0}}}async getKeystoneGraph(t){let e=`${this.lc}[${this.getKeystoneGraph.name}]`;try{tt&&console.log(`${e} fetching keystone graph...`);let o=`/api/keystone/${encodeURIComponent(t)}?getLatest=true&getGraph=true`,n=await fetch(o,{method:"GET",headers:{Accept:"application/json"}}),s=await this.parseResponseJson(n,o);if(!n.ok){let a=s.message||s.error||"Unknown error";return console.error(`${e} server rejected keystone graph get: ${a}`),{success:!1,message:a}}return{success:!0,graph:s.domainGraph}}catch(o){let n=m(o);return console.error(`${e} fetch error: ${n}`),{success:!1,message:n}}}async getIbGib(t,e,o=!1){let n=`${this.lc}[${this.getIbGib.name}]`;try{tt&&console.log(`${n} fetching single ibGib frame...`);let s=`/api/ibgib/${encodeURIComponent(t)}/${encodeURIComponent(e)}?getLatest=${o}&getGraph=false`,a=await fetch(s,{method:"GET",headers:{Accept:"application/json"}}),i=await this.parseResponseJson(a,s);if(!a.ok){let c=i.message||i.error||"Unknown error";return console.error(`${n} server rejected ibGib get: ${c}`),{success:!1,message:c}}return{success:!0,ibGib:i}}catch(s){let a=m(s);return console.error(`${n} fetch error: ${a}`),{success:!1,message:a}}}async getIbGibGraph(t,e,o=!1){let n=`${this.lc}[${this.getIbGibGraph.name}]`;try{tt&&console.log(`${n} fetching ibGib graph...`);let s=`/api/ibgib/${encodeURIComponent(t)}/${encodeURIComponent(e)}?getLatest=${o}&getGraph=true`,a=await fetch(s,{method:"GET",headers:{Accept:"application/json"}}),i=await a.json();if(!a.ok){let c=i.message||i.error||"Unknown error";return console.error(`${n} server rejected ibGib graph get: ${c}`),{success:!1,message:c}}return{success:!0,graph:i.graph,addr:i.addr}}catch(s){let a=m(s);return console.error(`${n} fetch error: ${a}`),{success:!1,message:a}}}async postVerificationCode({email:t,primaryTjpAddr:e}){let o=`${this.lc}[${this.postVerificationCode.name}]`;try{let n="/api/email/verification-code",s=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:t,primaryTjpAddr:e})}),a=await this.parseResponseJson(s,n);if(!s.ok){let i=a.message||a.error||"Verification code request failed";return console.error(`${o} server verification code post failed: ${i}`),{success:!1,message:i}}return{success:!0,message:a.message}}catch(n){let s=m(n);return console.error(`${o} post verification code error: ${s}`),{success:!1,message:s}}}async postMagicLink(t){return this.postVerificationCode(t)}async postVerifyCode({email:t,primaryTjpAddr:e,code:o}){let n=`${this.lc}[${this.postVerifyCode.name}]`;try{let s="/api/email/verify-code",a=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:t,primaryTjpAddr:e,code:o})}),i=await this.parseResponseJson(a,s);if(!a.ok){let c=i.message||i.error||"Code verification failed";return console.error(`${n} server verify-code failed: ${c}`),{success:!1,message:c}}return tt&&console.log(`${n} verification code accepted.`),{success:!0,message:i.message}}catch(s){let a=m(s);return console.error(`${n} fetch error: ${a}`),{success:!1,message:a}}}},jr;function cg(){return jr||(jr=new gn),jr}f(cg,"getApiBridge");function lg(r){jr=r}f(lg,"setApiBridge");var Oa=/^error (\w+) ([a-fA-F\d]{32}|undefined)$/;var rt=!1;function va({rawMsg:r}){let t=`[${va.name}]`;try{rt&&console.log(`${t} starting...`);let e=En({rawMsg:r}),o=e.body.replace(/\s/g,"_").replace(/\W/g,""),n;if(o.length>20)n=o.substring(0,20);else if(o.length>0)n=o;else throw new Error("(UNEXPECTED) error msg should have characters/alphanumerics... (E: a3b9cd11a44cc7892a748819c2885422)");return`error ${n} ${e.uuid??"undefined"}`}catch(e){throw console.error(`${t} ${e.message}`),e}finally{rt&&console.log(`${t} complete.`)}}f(va,"getErrorIb");function En({rawMsg:r}){let t=`[${En.name}]`;try{if(rt&&console.log(`${t} starting...`),!r)throw new Error("(UNEXPECTED) rawMsg required (E: e5bd3b433a1781ebe885534cd2495622)");let e,o=r.match(qn);if(o){let[n,s,a,i,c,l]=o;if(!i)throw new Error("invalid error msg body (E: a675e6855cca96519d33d44ea5400922)");e={success:!1,raw:r,body:i?.trim(),uuid:c.slice(4,36)},s&&(e.location=s),(a||l)&&(e.unexpected=!0)}else{e={success:!1,raw:r,body:r};let n=r.match(Hn);if(n){let[s,a]=n;e.location=a}r.toLowerCase().includes("(unexpected)")&&(e.unexpected=!0)}return e}catch(e){throw console.error(`${t} ${e.message}`),e}finally{rt&&console.log(`${t} complete.`)}}f(En,"parseRawErrorMsg");function ut({rawMsg:r}){let t=`[${ut.name}]`;try{return rt&&console.log(`${t} starting...`),Te({parentPrimitiveIb:"error",ib:va({rawMsg:r}),data:En({rawMsg:r}),ibRegExpPattern:Oa.source})}catch(e){throw console.error(`${t} ${e.message}`),e}finally{rt&&console.log(`${t} complete.`)}}f(ut,"getErrorIbGib");function Ke({ibGib:r}){let t=`[${Ke.name}]`;try{if(rt&&console.log(`${t} starting...`),!r)throw new Error("ibGib required (E: 1d756fbbd96f1734b97ba013537ed522)");return r.ib.startsWith("error ")}catch(e){throw console.error(`${t} ${e.message}`),e}finally{rt&&console.log(`${t} complete.`)}}f(Ke,"isError");var ot=!1;function Na(r){let t=`[${Na.name}]`;try{let e=r?`${Vt} ${r}`:Vt;return ot&&console.log(`${t} ${e}`),e}catch(e){throw console.error(`${t} ${e.message}`),e}}f(Na,"getArgIb");function zc({ib:r,ibGib:t}){let e=`[${zc.name}]`;try{if(ot&&console.log(`${e} starting...`),!r)if(t)r=t.ib;else throw new Error("either ib or ibGib required (E: c052a9d76df867626f9ba17141cdce22)");return r.startsWith(Vt)}catch(o){throw console.error(`${e} ${o.message}`),o}finally{ot&&console.log(`${e} complete.`)}}f(zc,"isArg");function La(r){let t=`[${La.name}]`;try{let e=r?`${xr} ${r}`:xr;return ot&&console.log(`${t} ${e}`),e}catch(e){throw console.error(`${t} ${e.message}`),e}}f(La,"getResultIb");async function pt({argData:r,ibMetadata:t,noTimestamp:e}){let o=`[${pt.name}]`;try{let n=await M.firstGen({ib:Na(t),parentIbGib:M.primitive({ib:Vt}),data:r,dna:!1,noTimestamp:e});if(n.newIbGib){let{newIbGib:s}=n;return s.rel8ns.past=[],s.gib=await We(s),s}else throw new Error("create ibGib failed")}catch(n){throw console.error(`${o} ${n.message}`),n}}f(pt,"argy_");async function ht({resultData:r,ibMetadata:t,noTimestamp:e}){let o=`[${ht.name}]`;try{let n=await M.firstGen({ib:La(t),parentIbGib:M.primitive({ib:xr}),data:r,dna:!1,noTimestamp:e});if(n?.newIbGib){let{newIbGib:s}=n;return s.rel8ns.past=[],s.gib=await We(s),s}else throw new Error("create ibGib failed")}catch(n){throw console.error(`${o} ${n.message}`),n}}f(ht,"resulty_");function mn({ibGib:r}){let t=`[${mn.name}]`;try{if(ot&&console.log(`${t} starting...`),!r)throw new Error("ibGib required (E: e11cee2a6c59a5e7a4d39ea55751c423)");if(!r.data)return!1;let e=r.data;return e.cmd&&typeof e.cmd=="string"}catch(e){throw console.error(`${t} ${e.message}`),e}finally{ot&&console.log(`${t} complete.`)}}f(mn,"isCommand");function wn({ibGib:r}){let t=`[${wn.name}]`;try{return ot&&console.log(`${t} starting... (I: aad0a14f4d62061424fc92da4d53d823)`),typeof r.witness=="function"}catch(e){throw console.error(`${t} ${e.message}`),e}finally{ot&&console.log(`${t} complete.`)}}f(wn,"isWitness");var Br="subject",$n=/^[a-zA-Z0-9_\-.]{1,255}$/,Ca="subject",Pa="",Fr="subject is a cool ibgib witness that has seriously fascinating behavior.";var Ra="observable";var nt={subscribe:"subscribe"},Ua=Object.values(nt);var Ma={next:"next",error:"error",complete:"complete"};var st={...nt,...Ma};var er={version:"1",uuid:Pa,name:Ca,description:Fr,classname:"Subject_V1",persistOptsAndResultIbGibs:!1,allowPrimitiveArgs:!0,catchAllErrors:!0,trace:!1},yn=void 0;var qr=class r{static{f(this,"WitnessFactoryBase")}lc=`[${r.name}]`};var In=!1,vt=class r extends qr{static{f(this,"DynamicFormFactoryBase")}lc=`[${r.name}]`;patchDataFromItems({data:t,contextPath:e,items:o,pathDelimiter:n}){let s=`${this.lc}[${this.patchDataFromItems.name}]`;try{if(In&&console.log(`${s} starting...`),!n)throw new Error("pathDelimiter required (E: 958d472a15fb71e45cd2925883f2ec22)");for(let a=0;a<o.length;a++){let i=o[a],c=e?e+n+i.name:i.name;if(!i.items)Eo({obj:t,value:i.value,path:c,logalot:In,pathDelimiter:n});else if(i.items.length>0)this.patchDataFromItems({data:t,contextPath:c,items:i.items,pathDelimiter:n});else throw new Error("invalid item. items is truthy but with a length of 0. items should either be falsy or have at least one child. (E: ee2765e0b920477f919fcb09e9d951b4)")}}catch(a){throw console.error(`${s} ${a.message}`),a}finally{In&&console.log(`${s} complete.`)}}};var ka=!1,Nt=class r{static{f(this,"LightWitnessBase_V1")}lc=`[${r.name}]`;instanceId="";ib="";gib;data;rel8ns;initialized;_isInitialized=!1;constructor(t,e){t&&(this.data=t),e&&(this.rel8ns=e),this.initialized=this.initialize().then(()=>{this._isInitialized=!0})}async initialize(){this.instanceId=await F(),this.gib=await X({ibGib:this.toIbGibDto()})}toIbGibDto(){return Pe({ibGib:this})}loadIbGibDto(t){let e=`${this.lc}[${this.loadIbGibDto.name}]`;try{return ka&&console.log(`${e} starting...`),t.ib||console.warn(`${e} dto.ib is falsy.`),t.gib||console.warn(`${e} dto.gib is falsy.`),this.ib=v(t.ib),this.gib=v(t.gib),t.data?this.data=v(t.data):delete this.data,t.rel8ns?this.rel8ns=v(t.rel8ns):delete this.rel8ns,Promise.resolve()}catch(o){throw console.error(`${e} ${o.message}`),o}finally{ka&&console.log(`${e} complete.`)}}async validateThis(){let t=`${this.lc}[${this.validateThis.name}]`,e=[];try{this.ib||e.push("this.ib is falsy."),this.gib||e.push("this.gib is falsy.")}catch(o){throw console.error(`${t} ${o.message}`),o}return e}};var ja="subscription",_n=/^[a-zA-Z0-9_\-.]{1,255}$/,Ba="",Fa="subscription",Hr="subscription is a cool ibgib witness that has seriously fascinating behavior.";var tr={unsubscribe:"unsubscribe",unsubscribed:"unsubscribed"};var Tn={version:"1",uuid:Ba,name:Fa,description:Hr,classname:"Subscription_V1",persistOptsAndResultIbGibs:!1,allowPrimitiveArgs:!0,catchAllErrors:!1,trace:!1},An=void 0;var qa=!1;function Gn({ibGib:r}){let t=`[${Gn.name}]`;try{qa&&console.log(`${t} starting... (I: 3aadb634377acbe42984b61c91975323)`);let{ib:e}=r;return[Ra,Br].some(n=>e.includes(n))}catch(e){throw console.error(`${t} ${e.message}`),e}finally{qa&&console.log(`${t} complete.`)}}f(Gn,"isObservable");var P=!1,Xr=class r extends Nt{static{f(this,"Subscription_V1")}lc=`[${r.name}]`;metaspace;_subscribed;_unsubscribed;_srcObservable;constructor(t,e){super(t,e)}async initialize(){let t=`${this.lc}[${this.initialize.name}]`;try{if(P&&console.log(`${t} starting... (I: 8097612cda5f43e5b38249d057b65b1e)`),await super.initialize(),!this.data)throw new Error("this.data required (E: 1af73af2d17a48ada42596ad395fd99c)");this.data.uuid=this.instanceId,this.ib=Vr({data:this.data,classname:"Subscription_V1"}),this.gib=await X({ibGib:this})}catch(e){throw console.error(`${t} ${e.message}`),e}finally{P&&console.log(`${t} complete.`)}}async witness(t){let e=`${this.lc}[${this.witness.name}]`;try{this._isInitialized||await this.initialized;let{ib:o}=t;if(!o)throw new Error("arg.ib required (E: 1fd9aebef07b4bdaacc0cd323c8ddf76)");if(P&&console.log(`${e} ib: ${o} (I: 4de7771f477dc5b36933343b694ce223)`),o===tr.unsubscribe)return P&&console.log(`${e} routing unsubscribe cmd (I: 5633b86d467af2aa67388abf559a3c23)`),this.witness_unsubscribe();if(o===tr.unsubscribed)return P&&console.log(`${e} routing unsubscribed query (I: 6e0ae61d90f1974d76bcdbb47970e723)`),this.witness_unsubscribed();if(Gn({ibGib:t}))return P&&console.log(`${e} routing observerable (I: 165b422cda9ec3052312243dc965cf23)`),this.witness_observable({ibGib:t});throw new Error("unknown arg. expect unsubscribe/unsubscribed primitive ibgib or Observable ibgib. (E: 132dc7cd8f7c4afc9ec4651e2c559c74)")}catch(o){throw console.error(`${e} ${m(o)??"unknown error (E: b0bbaab21833404a9420c3d273df7f21)"}`),o}}async witness_unsubscribe(){let t=`${this.lc}[${this.witness_unsubscribe.name}]`;try{if(P&&console.log(`${t} starting... (I: a3d549220ef24604956aaa2c66fff09b)`),!this._subscribed)return console.warn(`${t} tried to unsubscribe but this._subscribed is ${this._subscribed} (W: cdc94f59447d4011b4b4cc12ef9ec074)`),Y;if(this._unsubscribed)return console.warn("{lc} this._unsubscribed already true. (W: fa287d76cec040e0978a8add5c758093)"),Y;if(!this._srcObservable)throw new Error("(UNEXPECTED) this._subscribed but this._srcObservable falsy? (E: 83687993b7bea299b4ba2438b530a123)");return P&&(console.log(`${t} inspecting srcObservable before src.witness... (I: f15a33d10f1cae3cec6fdbdb32596823)`),console.dir(this._srcObservable)),await this._srcObservable.witness(this),P&&(console.log(`${t} inspecting srcObservable after src.witness... (I: f15a33d10f1cae3cec6fdbdb32596823)`),console.dir(this._srcObservable)),this._subscribed=!1,this._unsubscribed=!0,delete this._srcObservable,P&&console.log(`${t} this._ (I: 7b1bc418a3d32757772391cad7a49523)`),Y}catch(e){throw console.error(`${t} ${e.message}`),e}finally{P&&console.log(`${t} complete.`)}}async witness_observable({ibGib:t}){let e=`${this.lc}[${this.witness_observable.name}]`;try{if(P&&console.log(`${e} starting... (I: faf248f372fc44a7bb0e70492e8284f9)`),this._subscribed!==void 0)throw new Error(`(UNEXPECTED) this._subscribed (${this._subscribed} is not undefined? (E: 09a0e926357676c2c93a173ccbe93923)`);if(this._srcObservable)throw new Error("(UNEXPECTED) this subscription isn't subscribed but this._observable is truthy? (E: acdf5198fb2ff3c8b2db95450bd55b23)");return this._srcObservable=t,P&&console.log(`${e} this._srcObservable set to ibgib with ib: ${t.ib} (I: 4b81d17243f60dfdcc2163fbb55e9223)`),this._subscribed=!0,Y}catch(o){throw console.error(`${e} ${o.message}`),o}finally{P&&console.log(`${e} complete.`)}}async witness_unsubscribed(){let t=`${this.lc}[${this.witness_unsubscribed.name}]`;try{if(P&&console.log(`${t} starting... (I: 1beac551253e4c5694b63e0d36d5d5c0)`),this._subscribed==null)throw new Error("subscription never subscribed in the first place (this._subscribed === undefined) (E: b2c1b21a0e876a4908339a976924b923)");if(this._subscribed&&this._unsubscribed)throw new Error("(UNEXPECTED) both this._subscribed and this._unsubscribed true (E: a967e49de657a43929a74703c656ad23)");let e=this._unsubscribed===!0?xo:gs;return P&&console.log(`${t} result: ${H(e)} (I: b488cf36ce39e006a81d3ad3db5b4a23)`),e}catch(e){throw console.error(`${t} ${e.message}`),e}finally{P&&console.log(`${t} complete.`)}}async unsubscribe(){let t=`${this.lc}[${this.unsubscribe.name}]`;try{P&&console.log(`${t} starting... (I: ef7f3f4787a74fcca65d761880f44594)`);let e=await this.witness(M.primitive({ib:tr.unsubscribe}));if(!e)throw new Error("(UNEXPECTED) unsubscribe returned undefined? (E: 7013193490b94b6880f1049c36577d6f)");if(Ke({ibGib:e})){let o=e;throw new Error(`${o.data.raw} (E: fca1200dccb14f84968b2462f1b4c29e)`)}}catch(e){throw console.error(`${t} ${e.message}`),e}finally{P&&console.log(`${t} complete.`)}}async unsubscribed(){let t=`${this.lc}[${this.unsubscribed.name}]`;try{P&&console.log(`${t} starting... (I: 8ee9a93be61647d6aef6a4fa03e96dad)`);let e=await this.witness(M.primitive({ib:tr.unsubscribed}));if(!e)throw new Error("(UNEXPECTED) unsubscribe returned undefined? (E: 5051d7ff4a4d4bf7864c520b53f028d5)");let o=e.ib===xo.ib;return P&&console.log(`${t} resUnsubscribed: ${o} (I: b4800166c58d5ba2ca1dccaa53de2323)`),o}catch(e){throw console.error(`${t} ${e.message}`),e}finally{P&&console.log(`${t} complete.`)}}async validateThis(){let t=`${this.lc}[${this.validateThis.name}]`;try{return P&&console.log(`${t} starting...`),this.data,[]}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{P&&console.log(`${t} complete.`)}}async argy({argData:t,ibMetadata:e,noTimestamp:o,ibGibs:n}){let s=await pt({argData:t,ibMetadata:e,noTimestamp:o});return n&&(s.ibGibs=n),s}async resulty({resultData:t,ibGibs:e}){let o=await ht({resultData:t});return e&&(o.ibGibs=e),o}},Kr=class r extends vt{static{f(this,"Subscription_V1_Factory")}lc=`[${r.name}]`;getName(){return Xr.name}async newUp({data:t,rel8ns:e}){let o=`${this.lc}[${this.newUp.name}]`;try{P&&console.log(`${o} starting...`),t??=v(Tn),t=t,e=e??An?v(An):void 0,t.uuid||=await F();let{classname:n}=t,s=Vr({data:t}),a=await Te({parentPrimitiveIb:`witness ${n}`,ib:s,data:t,rel8ns:e}),i=new Xr(void 0,void 0);return await i.loadIbGibDto(a),P&&console.log(`${o} witnessDto: ${H(a)} (I: 5e41337176d1441f9a5c7b43664d43ef)`),{newIbGib:i}}catch(n){throw console.error(`${o} ${m({error:n})}`),n}finally{P&&console.log(`${o} complete.`)}}async witnessToForm({witness:t}){let e=`${this.lc}[${this.witnessToForm.name}]`;try{P&&console.log(`${e} starting...`);let{data:o}=t;if(!o)throw new Error("(UNEXPECTED) witness.data falsy? (E: ef44497ff97a4e5bac004d52c4ff40eb)");P&&console.log(`${e} data: ${H(o)} (I: c3f4c3d85386461aaefbe33524ff9cbd)`);let n=await Rt({n:100}),s=new Yr().with({idPool:n}).name({of:o.name,required:!1}).description({of:o.description??Hr}).and().and().uuid({of:o.uuid,required:!0}).classname({of:o.classname}).and().commonWitnessFields({data:o}).outputForm({formName:"form",label:"subscription"});return Promise.resolve(s)}catch(o){throw console.error(`${e} ${m({error:o})}`),o}finally{P&&console.log(`${e} complete.`)}}async formToWitness({form:t}){let e=v(Tn);return this.patchDataFromItems({data:e,items:t.items,pathDelimiter:yt}),await this.newUp({data:e})}};var Wr=!1;function Ha({data:r}){let t=`[${Ha.name}]`;try{if(Wr&&console.log(`${t} starting...`),!r)throw new Error("Subscription Data required (E: 6d1c97931dcab8ea9f3e9b32c794b90c)");let e=[],{name:o,uuid:n,classname:s}=r;return o?o.match(_n)||e.push(`name must match regexp: ${_n} (E: 21bf77e398d47e9d035376510505eda2)`):e.push("name required."),n?n.match(z)||e.push(`uuid must match regexp: ${z} (E: e53fd08ae69e945b37ed895b864b6bd7)`):e.push("uuid required."),s&&(s.match(Ye)||e.push(`classname must match regexp: ${Ye}`)),e}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{Wr&&console.log(`${t} complete.`)}}f(Ha,"validateCommonSubscriptionData");function Vr({data:r,classname:t}){let e=`[${Vr.name}]`;try{let o=Ha({data:r});if(o.length>0)throw new Error(`invalid Subscription data: ${o} (E: fd6b0b32d8f6c4b97eebd489cdb07a4a)`);if(t){if(r.classname&&r.classname!==t)throw new Error("classname does not match data.classname (E: 354285a56a20b9b65b06abfcd9f2e621)")}else if(t=r.classname,!t)throw new Error("classname required (E: 040c1fd71853fa7874146999afb355c3)");let{uuid:n}=r;return`witness ${ja} ${t} ${n}`}catch(o){throw console.error(`${e} ${m(o)}`),o}}f(Vr,"getSubscriptionIb");var Yr=class r extends Qe{static{f(this,"SubscriptionFormBuilder")}lc=`[${r.name}]`;constructor(){super(),this.what="subscription"}};function zr({ibGib:r}){let t=`[${zr.name}]`;try{if(Wr&&console.log(`${t} starting... (I: 43df7e7f61f25e65662ce8aa5a105a23)`),!r)return!1;let e=r;return typeof e.witness=="function"&&typeof e.unsubscribe=="function"&&typeof e.unsubscribed=="function"}catch(e){throw console.error(`${t} ${e.message}`),e}finally{Wr&&console.log(`${t} complete.`)}}f(zr,"isSubscription");async function Xa(){return(await new Kr().newUp({})).newIbGib}f(Xa,"newupSubscription");var Sn="observable_event";var Ka=!1;async function xn({eventType:r,srcObservable:t,payload:e}){let o=`[${xn.name}]`;try{if(Ka&&console.log(`${o} starting... (I: e2290f2f46d1993d6893a24c19100823)`),!t)throw new Error("srcObservable required (E: 3470a97bbf3802cbc8dd64339f5ef623)");if(!t.data)throw new Error("srcObservable.data required (E: df1786585ba849c08e7f4f1fddd30a31)");if(!t.data.uuid)throw new Error("srcObservable.data.uuid required (E: 173a1a53f274bc1cef879bad2288ca23)");if(!t.data.uuid.match(z))throw new Error(`valid srcObservable.data.uuid required. must pass UUID_REGEXP: ${z.source} (E: 10f4bd1863f18250cc79cd65221da223)`);let n={uuid:await F(),eventType:r,srcObservableId:t.data.uuid,"@srcObservableAddr":y({ibGib:t}),"@payloadAddr":y({ibGib:e})};return await Te({parentPrimitiveIb:Sn,ib:Va({data:n}),data:n})}catch(n){throw console.error(`${o} ${n.message}`),n}finally{Ka&&console.log(`${o} complete.`)}}f(xn,"getObservableEventIbGib");function Va({data:r,classname:t}){let e=`[${Va.name}]`;try{if(t){if(r.classname&&r.classname!==t)throw new Error("classname does not match data.classname (E: 523aabc53fb944789202a5f468abd338)")}else if(t=r.classname,!t)throw new Error("classname required (E: d4401ea682894c5fa824b38d4989aa76)");if(!r.uuid)throw new Error("data.uuid required (E: 204cc7c20efd8a55263cdea8b1223e23)");return`${Sn} ${t} ${r.uuid}`}catch(o){throw console.error(`${e} ${m(o)}`),o}}f(Va,"getObservableEventIb");var V=!1,Jr=class r extends Nt{static{f(this,"ObservableBase_V1")}lc=`[${r.name}]`;metaspace;_subscribers={};_isComplete=!1;_pastPayloads=[];_pastError;get isCompleteOrErrored(){return this._isComplete||!!this._pastError}get isComplete(){return this._isComplete}get isErrored(){return!!this._pastError}constructor(t,e){super(t,e)}async witness(t){let e=`${this.lc}[${this.witness.name}]`;try{this._isInitialized||await this.initialized;let{ib:o}=t;if(!o)throw new Error("arg.ib required (E: 87659d093b82436ce2f7a87e402a5423)");if(mn({ibGib:t}))return this.witness_cmd({arg:t});if(wn({ibGib:t}))return this.witness_otherWitness({arg:t});throw new Error("unknown arg. expect observable cmd or ibgib witness (E: dc2667cffac5b8d7b1bf2ea737c81a23)")}catch(o){throw console.error(`${e} ${m(o)??"unknown error (E: 3e22bea4c7fb4668bf13d7146b927869)"}`),o}}async witness_cmd({arg:t}){let e=`${this.lc}[${this.witness_cmd.name}]`;try{if(V&&console.log(`${e} starting... (I: 69257fac8328b9de9755fdd237b92723)`),t.data.cmd===nt.subscribe)return this.witness_subscribe_cmd({ibGib:t});throw new Error(`unknown command. must be of type ObservableCmd (${Ua}) (E: 5910e5cbafead25ea2917a65a3fc4123)`)}catch(o){throw console.error(`${e} ${o.message}`),o}finally{V&&console.log(`${e} complete.`)}}async witness_otherWitness({arg:t}){let e=`${this.lc}[${this.witness_otherWitness.name}]`;try{return V&&console.log(`${e} starting... (I: 871d0b7a2bef4596bad430f1cbacde02)`),zr({ibGib:t})?this.witness_subscriptionIbGib({arg:t}):this.witness_subscribe_nonCmdWitness({arg:t})}catch(o){throw console.error(`${e} ${o.message}`),o}finally{V&&console.log(`${e} complete.`)}}async witness_subscriptionIbGib({arg:t}){let e=`${this.lc}[${this.witness_subscriptionIbGib.name}]`;try{if(V&&console.log(`${e} starting... (I: 4ac764776ef7e3f9074eb95a999ba423)`),!t.data)throw new Error("arg.data required (E: 764ae772727ceba95a18140fdd938323)");let o=this.getSubscriberKey({subscription:t}),[n,s]=this._subscribers[o];if(t===n)delete this._subscribers[o];else throw new Error("(UNEXPECTED) arg and subscription are two different instances? (E: aab5ef9bdc92abb9e816e2c443ab5723)");return Y}catch(o){throw console.error(`${e} ${o.message}`),o}finally{V&&console.log(`${e} complete.`)}}async replayPastPayloads({observer:t,subscription:e}){let o=`${this.lc}[${this.replayPastPayloads.name}]`;try{V&&console.log(`${o} starting... (I: b3c8f9c76a4af030cf52fdcf01c3fd23)`);let n=this.getSubscriberKey({subscription:e}),s=f(()=>!!this._subscribers[n],"fnStillSubscribed"),a=-1,i=!0;do if(a++,a<this._pastPayloads.length){if(!s()){V&&console.log(`${o} subscription canceled before past payloads dispatch completed. (I: f1778f868446a518030d1cf7800c8a23)`);return}try{let c=this._pastPayloads[a];await t.next(c)}catch{console.error(`${o} observer errored on payload (i: ${a}). aborting replay (E: 1d7efc7c48e1491da4317ef333031077)`);return}}else i=!1;while(i);if(this.isErrored&&t.error&&s())try{await t.error(this._pastError)}catch{console.error(`${o} observer.error(this._pastError) errored itself (E: 18310e5e032345e7bdc3f2479807866c)`)}else if(this.isComplete&&t.complete&&s())try{await t.complete()}catch{console.error(`${o} observer.complete errored (E: d9d027f5520f4d7eadfc669d66b5b550)`)}}catch(n){throw console.error(`${o} ${n.message}`),n}finally{V&&console.log(`${o} complete.`)}}async witness_subscribe_cmd({ibGib:t}){let e=`${this.lc}[${this.witness_subscribe_cmd.name}]`;try{if(V&&console.log(`${e} starting... (I: 0c4c75c3fae297af6449c1048ce55423)`),(t.ibGibs??[]).length!==1)throw new Error("ibGib.ibGibs required. should contain one ObserverWitness (E: 3ed99b32e22284573c497df788a9f923)");let o=t.ibGibs[0],n=await Xa();return V&&console.log(`${e} subscription created (I: 89ccd97803c66292f9d7334e1e2de523)`),await n.witness(this),await n.initialized,V&&console.log(`${e} subscription initialized (after witnessing this observable as its src). (I: 3021483402b21c4df64a9173bd223a23)`),this._subscribers[this.getSubscriberKey({subscription:n})]=[n,o],V&&console.log(`${e} stored subscriber (subscription, observer) (I: fb09660d885e33b80188dd0386ffc723)`),this.data.replay&&this._pastPayloads.length>0&&this.replayPastPayloads({observer:o,subscription:n}),n}catch(o){throw console.error(`${e} ${o.message}`),o}finally{V&&console.log(`${e} complete.`)}}async witness_subscribe_nonCmdWitness({arg:t}){let e=`${this.lc}[${this.witness_subscribe_nonCmdWitness.name}]`;try{throw V&&console.log(`${e} starting... (I: d9571dfcab4247d594c838233971886a)`),new Error("not impl (E: 76219cf238ba4f849480bd7c82eefab9)")}catch(o){throw console.error(`${e} ${o.message}`),o}finally{V&&console.log(`${e} complete.`)}}async subscribe(t){let e=`${this.lc}[${this.subscribe.name}]`;try{V&&console.log(`${e} starting... (I: 0dec9a06c562711e19482d45a7075e23)`);let o;if(gt({ibGib:t})){let n=await this.argy({argData:{cmd:nt.subscribe,ibGibAddrs:[y({ibGib:t})]},ibGibs:[t]});o=await this.witness(n)}else o=await this.witness(t);if(!zr({ibGib:o}))throw new Error("(UNEXPECTED) resSubscription is not a SubscriptionWitness? (E: c29bec4e3a48d6f1299143399ac55a23)");return o}catch(o){throw console.error(`${e} ${o.message}`),o}finally{V&&console.log(`${e} complete.`)}}getSubscriberKey({subscription:t}){if(t.data?.uuid)return t.data.uuid;throw new Error("(UNEXPECTED) subscription.data.uuid falsy? (E: 8d078e6f8155f7567fd9378557e91823)")}async dispatchToEachSubscriber({payload:t,fnForObserver:e,observableEventType:o}){let n=`${this.lc}[${this.dispatchToEachSubscriber.name}]`;try{V&&console.log(`${n} starting... (I: 0b990ce892f689d14458565717e66a23)`);let s=Object.values(this._subscribers);for(let a=0;a<s.length;a++){let[i,c]=s[a];if(gt({ibGib:c})){let l=c;await e(l,t),l.complete?await i.unsubscribed()?console.warn(`${n} (UNEXPECTED) subscriber reference still held but is unsubscribed? skipping for now (i.e. won't remove subscriber) in case that code is in yielded execution and just hasn't gotten around to it with event loop (but that would be weird). (W: 1d98f35d2fdd4345954c947265d9fb85)`):await l.complete():V&&console.log(`${n} no error handler for observer. skipping. (I: 6a8a52c2012c464790eb406d2ae0383f)`)}else{let l=await xn({eventType:o,srcObservable:this,payload:t});await c.witness(l)}}}catch(s){throw console.error(`${n} ${s.message}`),s}finally{V&&console.log(`${n} complete.`)}}async validateThis(){let t=`${this.lc}[${this.validateThis.name}]`;try{return V&&console.log(`${t} starting...`),this.data,[]}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{V&&console.log(`${t} complete.`)}}async argy({argData:t,ibMetadata:e,noTimestamp:o,ibGibs:n}){let s=await pt({argData:t,ibMetadata:e,noTimestamp:o});return n&&(s.ibGibs=n),s}async resulty({resultData:t,ibGibs:e}){let o=await ht({resultData:t});return e&&(o.ibGibs=e),o}};var R=!1,Zr=class r extends Jr{static{f(this,"Subject_V1")}lc=`[${r.name}]`;constructor(t,e){super(t,e)}asObservable(){return this}async subscribe(t){let e=`${this.lc}[${this.subscribe.name}]`;try{R&&console.log(`${e} starting... (I: 8e47b752314870ec78eb14342621f723)`);let o=await this.argy({argData:{cmd:st.subscribe,ibGibAddrs:[y({ibGib:t})]},ibGibs:[t]});return await this.witness(o)}catch(o){throw console.error(`${e} ${o.message}`),o}finally{R&&console.log(`${e} complete.`)}}async next(t){let e=`${this.lc}[${this.next.name}]`;try{R&&console.log(`${e} starting... (I: b30363827c56450ca918c69aa15b0046)`);let o=await this.argy({argData:{cmd:st.next,ibGibAddrs:[y({ibGib:t})]},ibGibs:[t]});await this.witness(o)}catch(o){throw console.error(`${e} ${o.message}`),o}finally{R&&console.log(`${e} complete.`)}}async error(t){let e=`${this.lc}[${this.error.name}]`;try{R&&console.log(`${e} starting... (I: 7fcc30e3763c429ea8b212491ad9455a)`);let o;if(typeof t=="string")o=await ut({rawMsg:t});else if(t instanceof Error||typeof t.message=="string")o=await ut({rawMsg:m(t)});else if(t.ib&&Ke({ibGib:t}))o=t;else throw new Error("unknown error type. shold either be ErrorIbGib_V1 or an Error instance or have error.message string property. (E: 2cfcab85439c3c845bfe18e8ecde3523)");let n=await this.argy({argData:{cmd:st.error,ibGibAddrs:[y({ibGib:o})]},ibGibs:[o]});await this.witness(n)}catch(o){throw console.error(`${e} ${o.message}`),o}finally{R&&console.log(`${e} complete.`)}}async complete(){let t=`${this.lc}[${this.complete.name}]`;try{R&&console.log(`${t} starting... (I: 5faaf13c6b0543d399815c03b9cdf80c)`);let e=await this.argy({argData:{cmd:st.complete}});await this.witness(e)}catch(e){throw console.error(`${t} ${e.message}`),e}finally{R&&console.log(`${t} complete.`)}}async witness_cmd({arg:t}){let e=`${this.lc}[${this.witness_cmd.name}]`;try{R&&console.log(`${e} starting... (I: 2bf7cbcadba446fa92cb649906b2b260)`);let{cmd:o}=t.data;switch(o){case st.next:return this.witness_next({ibGib:t});case st.error:return this.witness_error({ibGib:t});case st.complete:return this.witness_complete({ibGib:t});default:return super.witness_cmd({arg:t})}}catch(o){throw console.error(`${e} ${o.message}`),o}finally{R&&console.log(`${e} complete.`)}}async witness_next({ibGib:t}){let e=`${this.lc}[${this.witness_next.name}]`;try{if(R&&console.log(`${e} starting... (I: 600da780f13f5137a2f76aad344b2923)`),this.isCompleteOrErrored)return R&&console.log(`${e} this.isCompleteOrErrored is true. returning early without producing. (I: aa823831853b134b19657c8673838c23)`),Y;if((t.ibGibs??[]).length!==1)throw new Error("ibGib.ibGibs required. should contain one payload ibgib (E: 4046802ff96d4adfafcee7a74d96af5e)");let o=t.ibGibs[0];this.data.replay&&this._pastPayloads.push(o);let n=Object.values(this._subscribers);for(let s=0;s<n.length;s++){let[a,i]=n[s];if(R&&console.log(`${e} ensuring subscription not unsubscribed (I: ade3fd6d6ff2b5ec69eb8143e32ce223)`),!await a.unsubscribed())R&&console.log(`${e} subscription still active (I: b9ab83b28acecf0d823fdba46a81dc23)`),await i.next(o);else{debugger;console.warn(`${e} (UNEXPECTED) subscriber reference still held but is unsubscribed? skipping for now (i.e. won't remove subscriber) in case that code is in yielded execution and just hasn't gotten around to it with event loop (but that would be weird). (W: c116e799f6b9483c97fd030eb0dd09ea)`)}}return Y}catch(o){throw console.error(`${e} ${o.message}`),o}finally{R&&console.log(`${e} complete.`)}}async witness_error({ibGib:t}){let e=`${this.lc}[${this.witness_error.name}]`;try{if(R&&console.log(`${e} starting... (I: 3367a73bc83c47f98d9ecfe426dc300e)`),(t.ibGibs??[]).length!==1)throw new Error("ibGib.ibGibs required. should contain one error ibgib (E: 905474b45bcb4f0abe7bd4618f08f32c)");let o=t.ibGibs[0];this._pastError=o;let n=Object.values(this._subscribers);for(let s=0;s<n.length;s++){let[a,i]=n[s];if(gt({ibGib:i})){let c=i;c.error?await a.unsubscribed()?console.warn(`${e} (UNEXPECTED) subscriber reference still held but is unsubscribed? skipping for now (i.e. won't remove subscriber) in case that code is in yielded execution and just hasn't gotten around to it with event loop (but that would be weird). (W: 8946e97f00fd4146a470064b490a4c29)`):await c.error(o):R&&console.log(`${e} no error handler for observer. skipping. (I: 59f4a1ee59a3a27d523d60cd761be923)`)}else await i.witness(o)}return Y}catch(o){throw console.error(`${e} ${o.message}`),o}finally{R&&console.log(`${e} complete.`)}}async witness_complete({ibGib:t}){let e=`${this.lc}[${this.witness_complete.name}]`;try{R&&console.log(`${e} starting... (I: 4db180f465e24df9a4ded37fbd235558)`),this._isComplete=!0;let o=Object.values(this._subscribers);for(let n=0;n<o.length;n++){let[s,a]=o[n];if(gt({ibGib:a})){let i=a;i.complete?await s.unsubscribed()?console.warn(`${e} (UNEXPECTED) subscriber reference still held but is unsubscribed? skipping for now (i.e. won't remove subscriber) in case that code is in yielded execution and just hasn't gotten around to it with event loop (but that would be weird). (W: 1d98f35d2fdd4345954c947265d9fb85)`):await i.complete():R&&console.log(`${e} no error handler for observer. skipping. (I: 6a8a52c2012c464790eb406d2ae0383f)`)}else await a.witness(t)}return Y}catch(o){throw console.error(`${e} ${o.message}`),o}finally{R&&console.log(`${e} complete.`)}}async validateThis(){let t=`${this.lc}[${this.validateThis.name}]`;try{return R&&console.log(`${t} starting...`),this.data,[]}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{R&&console.log(`${t} complete.`)}}async argy({argData:t,ibMetadata:e,noTimestamp:o,ibGibs:n}){if(t.cmd===nt.subscribe)return super.argy({argData:t,ibMetadata:e,noTimestamp:o,ibGibs:n});{let s=await pt({argData:t,ibMetadata:e,noTimestamp:o});return n&&(s.ibGibs=n),s}}async resulty({resultData:t,ibGibs:e}){let o=await ht({resultData:t});return e&&(o.ibGibs=e),o}},Qr=class r extends vt{static{f(this,"Subject_V1_Factory")}lc=`[${r.name}]`;getName(){return Zr.name}async newUp({data:t,rel8ns:e}){let o=`${this.lc}[${this.newUp.name}]`;try{R&&console.log(`${o} starting...`),t??=v(er),t=t,e=e??yn?v(yn):void 0,t.uuid||=await F();let{classname:n}=t,s=On({data:t}),a=await Te({parentPrimitiveIb:`witness ${n}`,ib:s,data:t,rel8ns:e}),i=new Zr(void 0,void 0);return await i.loadIbGibDto(a),R&&console.log(`${o} witnessDto: ${H(a)} (I: 6736d2b2ddf44fef9a1eb27078dfbf23)`),{newIbGib:i}}catch(n){throw console.error(`${o} ${m({error:n})}`),n}finally{R&&console.log(`${o} complete.`)}}async witnessToForm({witness:t}){let e=`${this.lc}[${this.witnessToForm.name}]`;try{R&&console.log(`${e} starting...`);let{data:o}=t;if(!o)throw new Error("(UNEXPECTED) witness.data falsy? (E: 7b70c96e982d4f81b6ffda54da16b3b8)");R&&console.log(`${e} data: ${H(o)} (I: 75abef56f5004a94b2113e3b1461ac25)`);let n=await Rt({n:100}),s=new eo().with({idPool:n}).name({of:o.name,required:!1}).description({of:o.description??Fr}).and().and().uuid({of:o.uuid,required:!0}).classname({of:o.classname}).and().commonWitnessFields({data:o}).outputForm({formName:"form",label:"observable"});return Promise.resolve(s)}catch(o){throw console.error(`${e} ${m({error:o})}`),o}finally{R&&console.log(`${e} complete.`)}}async formToWitness({form:t}){let e=v(er);return this.patchDataFromItems({data:e,items:t.items,pathDelimiter:yt}),await this.newUp({data:e})}};var to=!1;function Ya({data:r}){let t=`[${Ya.name}]`;try{if(to&&console.log(`${t} starting...`),!r)throw new Error("Subject Data required (E: 207a82725648e2ef234c8bd3fa1a5312)");let e=[],{name:o,uuid:n,classname:s}=r;return o?o.match($n)||e.push(`name must match regexp: ${$n} (E: de987eb8fea0b6232f60abf31815095c)`):e.push("name required."),n?n.match(z)||e.push(`uuid must match regexp: ${z} (E: 1a6dfda91ad51696f7456bc84dfea60e)`):e.push("uuid required."),s&&(s.match(Ye)||e.push(`classname must match regexp: ${Ye}`)),e}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{to&&console.log(`${t} complete.`)}}f(Ya,"validateCommonSubjectData");function On({data:r,classname:t}){let e=`[${On.name}]`;try{let o=Ya({data:r});if(o.length>0)throw new Error(`invalid Subject data: ${o} (E: 55620ac1f17e30a30a92850219f894ac)`);if(t){if(r.classname&&r.classname!==t)throw new Error("classname does not match data.classname (E: 20e86cca70130839a49ad011c9a7aafa)")}else if(t=r.classname,!t)throw new Error("classname required (E: 74e29ae0f618fee7e7ef72a30c654a6c)");let{name:n,uuid:s}=r;return`witness ${Br} ${t} ${n} ${s}`}catch(o){throw console.error(`${e} ${m(o)}`),o}}f(On,"getSubjectIb");var eo=class r extends Qe{static{f(this,"SubjectFormBuilder")}lc=`[${r.name}]`;constructor(){super(),this.what="subject"}};function gt({ibGib:r}){let t=`[${gt.name}]`;try{return to&&console.log(`${t} starting... (I: b54c252104f710c12951aa43b6ead323)`),typeof r.next=="function"}catch(e){throw console.error(`${t} ${e.message}`),e}finally{to&&console.log(`${t} complete.`)}}f(gt,"isObserver");async function xm({data:r,replay:t}={}){let e=new Qr;return r??=v(er),t&&(r.replay=!0),(await e.newUp({data:r})).newIbGib}f(xm,"newupSubject");var Jc="hash-reveal-v1",Re={hash_reveal_v1:Jc},Wa=Object.values(Re);var Zc="top-up",Qc="replace-all",el="consume",tl="delete-all",me={topUp:Zc,replaceAll:Qc,consume:el,deleteAll:tl},za=Object.values(me);var rl="add-pool",ol="remove-pool",nl="replace-pool",sl="change-password",Lt={add_pool:rl,remove_pool:ol,replace_pool:nl,change_password:sl},vm=Object.values(Lt);var rr="keystone",Dn=/^\w[\w\-.]*$/,vn=/^[a-zA-Z0-9\-_]{1,64}$/,Nn=/^[a-zA-Z0-9_\-.]{1,63}$/,Ln=/^[a-zA-Z0-9\s.,!?:;'"\-()[\]_+=@#$%&*\/]{0,128}$/,Ja=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,Cn=1e3,Ct="revoke",he="manage",al="sign",ro="sync",Za="connect",Pn={REVOKE:Ct,MANAGE:he,SIGN:al,SYNC:ro,CONNECT:Za},Rm=Object.values(Pn);var Ve=he;var il=Za,cl=ro;var Qa=200,ei=2,ti=2,ri=5,oi=me.topUp,ni=we.sha_256,si=1,ai=2e3,ii=5,ci=5,li=16,di=me.replaceAll,fi=we.sha_512,bi=10,Et=50;var oo=class{static{f(this,"KeystoneStrategy")}config;constructor(t){this.config=t}};var ll="recursive-salt-wrap",Rn={recursive_salt_wrap:ll},ui=Object.values(Rn);var no=!1;async function dl({masterSecret:r,kdfOpts:t}){let e=`[${dl.name}]`;try{no&&console.log(`${e} starting... (I: 268e87ec311874ee6822bf459c5a5426)`);let o=t.strategy;switch(o){case Rn.recursive_salt_wrap:return await or({masterSecret:r,salt:t.salt,rounds:t.rounds,algorithm:t.algorithm});default:throw new Error(`Unknown KDF strategy: ${o}. valid values: ${ui.join(", ")} (E: c81258e9d9481eb0f88385a825193226)`)}}catch(o){throw console.error(`${e} ${m(o)}`),o}finally{no&&console.log(`${e} complete.`)}}f(dl,"deriveKey");async function or({masterSecret:r,salt:t,rounds:e,algorithm:o=we.sha_256}){let n=`[${or.name}]`;try{no&&console.log(`${n} starting... (I: 850868e50aba82ff28c77da8169e4c26)`);let s=r;for(let a=0;a<e;a++)s=await ce({s:`${t}${s}${t}`,algorithm:o});return s}catch(s){throw console.error(`${n} ${m(s)}`),s}finally{no&&console.log(`${n} complete.`)}}f(or,"kdf_recursiveSaltWrap");var so=class r extends oo{static{f(this,"KeystoneStrategy_HashRevealV1")}async derivePoolSecret({masterSecret:t}){let e=`[${r.name}.${this.derivePoolSecret.name}]`;try{let{salt:o,rounds:n,algo:s}=this.config;return await or({masterSecret:t,salt:o,rounds:n,algorithm:s})}catch(o){throw console.error(`${e} Error deriving pool secret: ${o.message}`),o}}async generateSolution({poolSecret:t,poolId:e,challengeId:o}){let n=`[${r.name}.${this.generateSolution.name}]`;try{let{rounds:s,algo:a}=this.config,i=o,c=t;for(let l=0;l<s;l++)c=await ce({s:`${i}${c}${i}`,algorithm:a});return{type:"hash-reveal-v1",poolId:e,challengeId:o,value:c}}catch(s){throw console.error(`${n} ${s.message}`),s}}async generateChallenge({solution:t}){let e=`[${r.name}.${this.generateChallenge.name}]`;try{let{rounds:o,algo:n}=this.config,{challengeId:s,value:a}=t,i=s,c=a;for(let l=0;l<o;l++)c=await ce({s:`${i}${c}${i}`,algorithm:n});return{id:s,type:"hash-reveal-v1",hash:c}}catch(o){throw console.error(`${e} ${o.message}`),o}}async validateSolution({solution:t,challenge:e}){let o=`[${r.name}.${this.validateSolution.name}]`;try{return t.type!=="hash-reveal-v1"||e.type!=="hash-reveal-v1"?(console.warn(`${o} Mismatched types provided.`),!1):(await this.generateChallenge({solution:t})).hash===e.hash}catch(n){return console.error(`${o} ${n.message}`),!1}}};async function Un({masterSecret:r}){let t=await ce({s:r,algorithm:we.sha_512});return await or({masterSecret:r,salt:t,rounds:1e3,algorithm:we.sha_512})}f(Un,"deriveDelegateSecret");var mt=class r{static{f(this,"KeystoneStrategyFactory")}static create({config:t}){let e=`[${r.name}.create]`;try{switch(t.type){case"hash-reveal-v1":return new so(t);default:throw new Error(`Unknown strategy type: ${t.type} (E: 4e3c2f7129a241c1b687555e678c1065)`)}}catch(o){throw console.error(`${e} ${o.message}`),o}}};var W=!1;async function pi({keystoneData:r}){let t=`[${pi.name}]`;try{return W&&console.log(`${t} starting... (I: c3022a146faac9730154f34d1439a225)`),[rr].join(" ")}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{W&&console.log(`${t} complete.`)}}f(pi,"getKeystoneIb");async function hi({ib:r}){let t=`[${hi.name}]`;try{W&&console.log(`${t} starting... (I: 73cb6832984255ed48b2f44db6a21e25)`);let[e]=r.split(" ");if(e!==rr)throw new Error(`invalid keystone ib. atom found in ib (${e}) does not match keystone atom (${rr}) (E: 79b3d587824c4271b6e60acc76e0c825)`);return{atom:e}}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{W&&console.log(`${t} complete.`)}}f(hi,"parseKeystoneIb");async function nr({ib:r}){try{return await hi({ib:r}),!0}catch{return!1}}f(nr,"validateKeystoneIb");function hw(r){if(!r||typeof r!="string")return!1;let t=r.trim();return t.length<3||t.length>254?!1:Ja.test(t)}f(hw,"validateEmail");async function gi({pool:r,requiredChallengeIds:t,targetAddr:e}){let o=r.config.behavior,n=new Set,s=Object.keys(r.challenges);if(t&&t.length>0){for(let a of t){if(!r.challenges[a])throw new Error(`(UNEXPECTED) Required challenge ID not found in pool: ${a} (E: 10c5619d80d8cf6cc84ffbf8be0dbc25)`);s.includes(a)&&n.add(a)}s=s.filter(a=>!n.has(a))}if(o.targetBindingCount>0&&e){let a=[...s].sort(),i=await ce({s:e});for(let c=0;c<o.targetBindingCount;c++){if(a.length===0)throw new Error("Entropy Exhaustion. Cannot satisfy target binding. Sorted available pool is empty. (E: 341b95dc3a58be3e083d1d9c4a0c4925)");let l=BigInt("0x"+i),d=Number(l%BigInt(a.length)),b=a[d];n.add(b),a.splice(d,1),s=s.filter(u=>u!==b),i=await ce({s:i})}}if(o.selectSequentially>0){if(s.length<o.selectSequentially)throw console.error(`[getDeterministicRequirements] Entropy Exhaustion! AvailableCount: ${s.length}, Required Seq: ${o.selectSequentially}. Available IDs: ${s.join(",")}`),new Error("Entropy Exhaustion. Insufficient challenges for FIFO requirement. (E: 9efa88003e1d5eccb837c85154ee5625)");s.slice(0,o.selectSequentially).forEach(i=>n.add(i)),s=s.slice(o.selectSequentially)}return{mandatoryIds:n,availableIds:s}}f(gi,"getDeterministicRequirements");function sr({pools:r,poolId:t,poolFilter:e,verb:o}){let n="[resolveTargetPool]";try{let s;if(t){if(s=r.find(a=>a.id===t),!s)throw new Error(`Pool not found with ID: ${t} (E: 4a2b17428515c1e82813158581898125)`)}else if(e){let a=r.filter(e);if(a.length===0)throw new Error("No pool matched the provided filter. (E: 5b3c27428515c1e82813158581898125)");s=a[0]}else{if(!o)throw new Error("Cannot auto-resolve pool without a verb. (E: 6c4d37428515c1e82813158581898125)");if(s=r.find(a=>a.config.allowedVerbs&&a.config.allowedVerbs.includes(o)),s||(s=r.find(a=>!a.config.allowedVerbs||a.config.allowedVerbs.length===0)),!s)throw new Error(`No suitable pool found for verb: ${o} (E: 7d5e47428515c1e82813158581898125)`)}if(o&&s.config.allowedVerbs&&s.config.allowedVerbs.length>0&&!s.config.allowedVerbs.includes(o))throw new Error(`Pool ${s.id} is not authorized for verb: ${o} (E: 8e6f57428515c1e82813158581898125)`);return s}catch(s){throw console.error(`${n} ${m(s)}`),s}}f(sr,"resolveTargetPool");async function wt({pool:r,targetAddr:t,requiredChallengeIds:e}){let o="[selectChallengeIds]";try{let{mandatoryIds:n,availableIds:s}=await gi({pool:r,requiredChallengeIds:e,targetAddr:t}),a=r.config.behavior.selectRandomly,i=[];if(a>0){if(s.length<a)throw new Error(`Insufficient challenges for random requirement. Need ${a}, have ${s.length} (E: 9f7a67428515c1e82813158581898125)`);let c=[...s].sort(()=>.5-Math.random());i.push(...c.slice(0,a))}return[...n,...i]}catch(n){throw console.error(`${o} ${m(n)}`),n}}f(wt,"selectChallengeIds");async function Ei({salt:r,timestamp:t,index:e}){return(await ce({s:`${r}${t}${e}`})).substring(0,16)}f(Ei,"generateOpaqueChallengeId");async function fl({prevPools:r,targetPoolId:t,consumedIds:e,masterSecret:o,strategy:n,config:s,verb:a}){let i="[applyReplenishmentStrategy]";try{let c=JSON.parse(JSON.stringify(r)),l=c.findIndex(g=>g.id===t);if(l===-1)throw new Error(`Target pool ${t} not found in keystone data. (E: 75200388d22744838634524233772545)`);let d=c[l],b=await n.derivePoolSecret({masterSecret:o}),u=Date.now().toString(),p=s.behavior.replenish;if(a===Ct&&(p=me.deleteAll),p===me.topUp){e.forEach(g=>delete d.challenges[g]);for(let g=0;g<e.length;g++){let h=await Ei({salt:s.salt,timestamp:u,index:g}),E=await n.generateSolution({poolSecret:b,poolId:d.id,challengeId:h});d.challenges[h]=await n.generateChallenge({solution:E})}}else if(p===me.replaceAll)d.challenges=await co({config:s,masterSecret:o});else if(p===me.consume)e.forEach(g=>delete d.challenges[g]);else if(p===me.deleteAll)d.challenges={};else throw new Error(`Unknown replenish strategy: ${p}. Valid list: ${H(za)} (E: 0acf56f1e1486240080e11e8046d0825)`);return c}catch(c){throw console.error(`${i} ${m(c)}`),c}}f(fl,"applyReplenishmentStrategy");async function $t({targetPoolId:r,prevPools:t,masterSecret:e,challengeIds:o,claim:n,requiredChallengeIds:s}){let a="[solveAndReplenish]";try{W&&console.log(`${a} starting... poolId: ${r}, ids: ${o.length}`);let i=t.find(g=>g.id===r);if(!i)throw new Error(`Target pool not found: ${r} (E: a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6)`);let c=mt.create({config:i.config}),l=await c.derivePoolSecret({masterSecret:e});if(!await kn({pool:i,signingSecret:e}))throw new Error(`Crypto Violation: Invalid signing secret for pool: ${i.id} (E: 8a4c2b1d3e5f6a7b8c9d0e1f2a3b4c5f)`);let b=[];for(let g of o){let h=await c.generateSolution({poolSecret:l,poolId:i.id,challengeId:g});b.push(h)}let u={claim:n,solutions:b,requiredChallengeIds:s&&s.length>0?s:void 0},p=await fl({prevPools:t,targetPoolId:i.id,consumedIds:o,masterSecret:e,strategy:c,config:i.config,verb:n.verb});return{proof:u,nextPools:p}}catch(i){throw console.error(`${a} ${m(i)}`),i}}f($t,"solveAndReplenish");async function mi({pool:r}){let t=`[${mi.name}]`;try{if(W&&console.log(`${t} starting... (I: e2ffd568b698cc12d8c5e838d73ae726)`),!r.config)throw new Error("(UNEXPECTED) pool.configy falsy? (E: fcde88fe20e8004a58d7e445436bf526)");if(r.config.type!==Re.hash_reveal_v1)throw new Error("(UNEXPECTED) pool.config.type !== KeystoneChallengeType.hash_reveal_v1? (E: e205f8872909c37168a624a9df778c26)");let e=[],{algo:o,rounds:n,salt:s}=r.config,a=[we.sha_256,we.sha_512];return o?a.includes(o)||e.push(`${t} invalid hash algorithm (${o}). Must be one of ${a}. (E: a22399ca3a68e63ffcc7507699be5826)`):e.push(`${t} algorithm required. (E: 8cd6bfb0590862b9bae24d98d2cf3826)`),n&&typeof n=="number"&&Number.isInteger(n)?n>Cn&&e.push(`${t} rounds too high. max rounds: ${Cn} (E: 31ce082f7fd88d6b58ef08a816458826)`):e.push(`${t} invalid rounds (${n}). must be positive integer. (E: 73c643ccda78afaf28d52a6871a9e826)`),s&&typeof s=="string"?vn.test(s)||e.push(`${t} invalid salt (${s.substring(0,99)}). Must match regexp ${vn}`):e.push(`${t} invalid salt (${s}). must be truthy string value. (E: 564a4844ec88fc1988197ce89c381426)`),e}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{W&&console.log(`${t} complete.`)}}f(mi,"validateChallengePool_typeHashRevealV1");async function wi({pool:r}){let t=`[${wi.name}]`;try{W&&console.log(`${t} starting... (I: 1a0eafc158a83d1ba8fc019d5c979a26)`);let e=[];if(r.config){if(r.config.id?Dn.test(r.config.id)||e.push(`${t} pool.config.id is not formatted correctly. must pass regexp: ${Dn.source}`):e.push(`${t} pool.config.id falsy (E: 31d7943d95f877326d5f4ea14463d626)`),r.config.behavior){let{size:n,selectSequentially:s,selectRandomly:a,targetBindingCount:i}=r.config.behavior;(!n||n===0)&&e.push(`${t} invalid pool.config.behavior.size (${n}). Must be positive integer. (E: b221e36ec102bdc944552248ce8fe626)`);let c=(s||0)+(a||0)+(i||0);c>=n&&e.push(`${t} Total requested challenges (${c}) cannot equal or exceed pool size (${n}) to prevent full pool exposure and selection exhaustion. (E: 81cb834f826315264bca81c15fca58f1)`)}else e.push(`${t} pool.config.behavior falsy (E: bede081c066c39732eefe2f92e296326)`);let o=r.config.type;switch(o){case Re.hash_reveal_v1:(await mi({pool:r})).forEach(s=>e.push(s));break;default:throw new Error(`(UNEXPECTED) unknown pool.config.type (${o})? We only implement the following at this time: ${Wa} (E: cce5285cf7580b8bc82172488eba2826)`)}}else e.push(`${t} pool.config falsy. (E: 8d05c875a1d2c58018a5eaf803977d26)`);return e}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{W&&console.log(`${t} complete.`)}}f(wi,"validateChallengePool");function $i({data:r}){let t="[validateKeystoneMetadata]",e=[],o=f((n,s)=>{n&&(n.username!==void 0&&(typeof n.username!="string"||!Nn.test(n.username))&&e.push(`${t} invalid username in ${s} (${n.username}). Must match ${Nn}`),n.description!==void 0&&(typeof n.description!="string"||!Ln.test(n.description))&&e.push(`${t} invalid description in ${s} (${n.description}). Must match ${Ln}`))},"checkDetails");return o(r.frameDetails,"frameDetails"),o(r.checkpointDetails,"checkpointDetails"),e}f($i,"validateKeystoneMetadata");async function ao({keystoneIbGib:r}){let t=`[${ao.name}]`;try{W&&console.log(`${t} starting... (I: ec6ba82ec848b5ac3d8953e89d8d9826)`);let e=[],{data:o,rel8ns:n}=r;await nr({ib:r.ib})||e.push(`${t} invalid keystone ib (${r.ib}). (E: ad7a88bc38c290a184dfbd42be48f526)`),$i({data:o}).forEach(i=>e.push(i)),o.proofs&&o.proofs.length>0&&e.push(`${t} proofs already exist on genesis keystone. (E: 7a5e15f20918f1bbd8ffb62857dcd526)`);for(let i of o.challengePools)(await wi({pool:i})).forEach(l=>e.push(l)),(!i.challenges||Object.keys(i.challenges).length===0)&&e.push(`${t} invalid pool (${i.id}). pool.challenges is falsy/empty. (E: 8cd16a5416ae62a058342828be465b26)`);return o.revocationInfo&&e.push(`${t} genesis keystone already has revocationInfo. (E: e11408d0c558d0fa948efbce611ec826)`),e}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{W&&console.log(`${t} complete.`)}}f(ao,"validateGenesisKeystone");function bl({currDelegates:r,prevDelegates:t}){let e=r||{},o=t||{},n=Object.keys(e),s=Object.keys(o);if(n.length!==s.length)return!0;for(let a of n){let i=e[a],c=o[a];if(!c||i.delegateTjpAddr!==c.delegateTjpAddr||i.delegateAddr!==c.delegateAddr||i.thisAddr!==c.thisAddr)return!0}return!1}f(bl,"isDelegatesChanged");async function ul({currDelegates:r,prevIbGib:t,lc:e,errors:o}){let n=Object.keys(r),s=y({ibGib:t});for(let a of n){let i=r[a];a!==i.delegateTjpAddr&&o.push(`${e} Invalid delegate mapping: Key '${a}' does not match delegateTjpAddr '${i.delegateTjpAddr}'. (E: 9c8da8bc38c290a184dfbd42be48f526)`);let[c,l,d]=await Promise.all([nr({ib:i.delegateTjpAddr.split("^")[0]}),nr({ib:i.delegateAddr.split("^")[0]}),nr({ib:i.thisAddr.split("^")[0]})]);c||o.push(`${e} Delegate delegateTjpAddr '${i.delegateTjpAddr}' is not a valid keystone address. (E: 10d8a8bc38c290a184dfbd42be48f526)`),l||o.push(`${e} Delegate delegateAddr '${i.delegateAddr}' is not a valid keystone address. (E: 20d8a8bc38c290a184dfbd42be48f526)`),d||o.push(`${e} Delegate thisAddr '${i.thisAddr}' is not a valid keystone address. (E: 30d8a8bc38c290a184dfbd42be48f526)`),i.thisAddr===s||(t.rel8ns?.past||[]).includes(i.thisAddr)||o.push(`${e} Delegate thisAddr '${i.thisAddr}' is not a valid historical address in the parent keystone timeline. (E: 40d8a8bc38c290a184dfbd42be48f526)`);let u=i.allowedVerbs||[];(i.role==="sync-delegate"||u.includes("sync")||u.includes(ro))&&!i.spaceId&&o.push(`${e} Sync delegate '${i.delegateTjpAddr}' missing required spaceId. (E: 50d8a8bc38c290a184dfbd42be48f526)`)}}f(ul,"validateDelegates");async function ar({currentIbGib:r,prevIbGib:t}){let e=`[${ar.name}]`,o=[];try{if(!r)throw new Error("(UNEXPECTED) currentIbGib falsy? (E: 3c0f02655fa8279e386a079ebb604b25)");if(!t)throw new Error("(UNEXPECTED) prevIbGib falsy? (E: 0d07c812634d839c784f31b8848ba825)");let n=await oe({ibGib:r});n&&n.length>0&&o.push(...n);let s=r.data,a=t.data;await nr({ib:r.ib})||o.push(`${e} invalid keystone ib (${r.ib}). (E: a98dc8bc38c290a184dfbd42be48f526)`),$i({data:s}).forEach(h=>o.push(h));let l=s.delegates||{},d=a.delegates||{};bl({currDelegates:l,prevDelegates:d})&&(s.proofs?.some(E=>E.claim?.verb===he)||o.push(`${e} Policy Violation: Delegates map was mutated but no proof for manage verb ('${he}') is present. (E: 819fa8cb28c9b60e68994511a5825)`)),await ul({currDelegates:l,prevIbGib:t,lc:e,errors:o});let u=s.n??-2,p=a.n??-2;u<0&&o.push("invalid keystone.currData.n is undefined or null. (E: 9fbe38704b68829d18ea1d0940d0aa26)"),p<0&&o.push("invalid keystone.prevData.n is undefined or null. (E: 6dc5aa9c87017db6080ed4268b07af26)"),u!==p+1&&o.push(`keystone data.n values are not sequential. prevData.n: ${p}, currData.n: ${u}. (E: 5ae12809f2c67216d38d8ba8d6c42826)`);for(let h of s.proofs){if(h.solutions.length===0){o.push(`Proof ${h.id||"unknown"} has no solutions. (E: e2b4683ce0ce30f798ec77841e88c826)`);continue}let E=h.solutions[0].poolId,$=a.challengePools.find(I=>I.id===E);if(!$){o.push(`Proof references unknown pool: ${E}`);continue}await yi({proof:h,pool:$,errors:o})}if(s.revocationInfo){let h=s.revocationInfo.proof.claim.target,E=y({ibGib:t});h!==E&&o.push(`Revocation target mismatch. Expected ${E}, got ${h}`)}let g=new Set(s.proofs.map(h=>h.solutions?.[0]?.poolId).filter(Boolean));for(let h of s.proofs){let E=h.claim;if(E?.details){let $=E.details,I=$.type,A=$.info;if(I==="add-pool"){let w=A;if(!w||!Array.isArray(w.add)||w.add.length===0){o.push(`details type is '${I}' but payload is invalid. (E: 1fa2a8cb28c9b60e68994511a5825)`);continue}let _=new Set(a.challengePools.map(G=>G.id)),S=new Set(s.challengePools.map(G=>G.id));for(let G of w.add)S.has(G)||o.push(`ClaimDetails_AddPool lists pool ${G} but it is missing in the evolved keystone. (E: 2fa2a8cb28c9b60e68994511a5825)`),_.has(G)&&o.push(`ClaimDetails_AddPool attempts to add existing pool ${G}. (E: 3fa2a8cb28c9b60e68994511a5825)`);s.challengePools.length!==a.challengePools.length+w.add.length&&o.push(`Structural mismatch: expected ${a.challengePools.length+w.add.length} pools, found ${s.challengePools.length}. (E: 4fa2a8cb28c9b60e68994511a5825)`);for(let G of a.challengePools){let O=s.challengePools.find(U=>U.id===G.id);if(!O){o.push(`Existing pool ${G.id} was removed during add-pool transition. (E: 5fa2a8cb28c9b60e68994511a5825)`);continue}JSON.stringify(G.config)!==JSON.stringify(O.config)&&o.push(`Existing pool config ${G.id} was mutated during add-pool transition. (E: 6fa2a8cb28c9b60e68994511a5825)`),!g.has(G.id)&&JSON.stringify(G.challenges)!==JSON.stringify(O.challenges)&&o.push(`Existing pool challenges ${G.id} were mutated during add-pool transition. (E: 7fa2a8cb28c9b60e68994511a5825)`)}}else if(I==="replace-pool"){let w=A;if(!w||typeof w.replace!="string"||!w.replace){o.push(`details type is '${I}' but payload is invalid. (E: 8fa2a8cb28c9b60e68994511a5825)`);continue}let _=w.replace,S=a.challengePools.map(x=>x.id).sort(),G=s.challengePools.map(x=>x.id).sort();JSON.stringify(S)!==JSON.stringify(G)&&o.push("replace-pool transition mutated the pool IDs set. (E: 9fa2a8cb28c9b60e68994511a5825)");let O=a.challengePools.find(x=>x.id===_),U=s.challengePools.find(x=>x.id===_);(!O||!U)&&o.push(`Replaced pool ${_} not found in keystone challenge pools. (E: afa2a8cb28c9b60e68994511a5825)`);for(let x of a.challengePools){if(x.id===_)continue;let N=s.challengePools.find(k=>k.id===x.id);N&&(JSON.stringify(x.config)!==JSON.stringify(N.config)&&o.push(`Unrelated pool config ${x.id} was mutated during replace-pool. (E: bfa2a8cb28c9b60e68994511a5825)`),!g.has(x.id)&&JSON.stringify(x.challenges)!==JSON.stringify(N.challenges)&&o.push(`Unrelated pool challenges ${x.id} were mutated during replace-pool. (E: cfa2a8cb28c9b60e68994511a5825)`))}}else if(I==="remove-pool"){let w=A;if(!w||!Array.isArray(w.remove)||w.remove.length===0){o.push(`details type is '${I}' but payload is invalid. (E: b7a2a8cb28c9b60e68994511a5825)`);continue}let _=new Set(w.remove),S=new Set(a.challengePools.map(O=>O.id)),G=new Set(s.challengePools.map(O=>O.id));for(let O of w.remove)S.has(O)||o.push(`ClaimDetails_RemovePool lists pool ${O} but it is missing in the previous keystone. (E: c7a2a8cb28c9b60e68994511a5825)`),G.has(O)&&o.push(`ClaimDetails_RemovePool lists pool ${O} but it is still present in the evolved keystone. (E: d7a2a8cb28c9b60e68994511a5825)`);s.challengePools.length!==a.challengePools.length-w.remove.length&&o.push(`Structural mismatch: expected ${a.challengePools.length-w.remove.length} pools, found ${s.challengePools.length}. (E: e7a2a8cb28c9b60e68994511a5825)`);for(let O of a.challengePools){if(_.has(O.id))continue;let U=s.challengePools.find(x=>x.id===O.id);if(!U){o.push(`Pool ${O.id} was unexpectedly removed. (E: f7a2a8cb28c9b60e68994511a5825)`);continue}JSON.stringify(O.config)!==JSON.stringify(U.config)&&o.push(`Remaining pool config ${O.id} was mutated during remove-pool. (E: 07a2a8cb28c9b60e68994511a5825)`),!g.has(O.id)&&JSON.stringify(O.challenges)!==JSON.stringify(U.challenges)&&o.push(`Remaining pool challenges ${O.id} were mutated during remove-pool. (E: 17a2a8cb28c9b60e68994511a5825)`)}}else if(I==="change-password"){let w=A;if(!w||!Array.isArray(w.change)||w.change.length===0){o.push(`details type is '${I}' but payload is invalid. (E: dfa2a8cb28c9b60e68994511a5825)`);continue}let _=a.challengePools.map(O=>O.id).sort(),S=s.challengePools.map(O=>O.id).sort();JSON.stringify(_)!==JSON.stringify(S)&&o.push("change-password transition mutated the pool IDs set. (E: efa2a8cb28c9b60e68994511a5825)");let G=new Set(w.change);for(let O of a.challengePools){let U=s.challengePools.find(x=>x.id===O.id);if(U)if(G.has(O.id)){O.isForeign&&o.push(`Security Violation: Password rotation attempted on foreign pool ${O.id}. (E: ffa2a8cb28c9b60e68994511a5825)`);let x={...O.config,salt:""},N={...U.config,salt:""};JSON.stringify(x)!==JSON.stringify(N)&&o.push(`Pool config metadata for rotated pool ${O.id} was mutated. (E: 00b2a8cb28c9b60e68994511a5825)`),O.config.salt===U.config.salt&&o.push(`Pool salt for rotated pool ${O.id} was not rotated. (E: 01b2a8cb28c9b60e68994511a5825)`)}else JSON.stringify(O.config)!==JSON.stringify(U.config)&&o.push(`Unrelated pool config ${O.id} was mutated during change-password. (E: 02b2a8cb28c9b60e68994511a5825)`),!g.has(O.id)&&JSON.stringify(O.challenges)!==JSON.stringify(U.challenges)&&o.push(`Unrelated pool challenges ${O.id} were mutated during change-password. (E: 03b2a8cb28c9b60e68994511a5825)`)}}else o.push(`Unknown claim details type: ${I}`)}}return o}catch(n){throw console.error(`${e} ${m(n)}`),n}finally{W&&console.log(`${e} complete.`)}}f(ar,"validateKeystoneTransition");async function yi({proof:r,pool:t,errors:e}){let o=`[${yi.name}]`;try{W&&console.log(`${o} starting... (I: b8f9b6085888eea2258bf579ecd5e825)`),t.config.allowedVerbs&&t.config.allowedVerbs.length>0&&(!r.claim.verb||!t.config.allowedVerbs.includes(r.claim.verb))&&e.push(`Policy Violation: Pool ${t.id} used for unauthorized verb ${r.claim.verb}`);let{mandatoryIds:n,availableIds:s}=await gi({pool:t,requiredChallengeIds:r.requiredChallengeIds,targetAddr:r.claim.target}),a=new Set(r.solutions.map(d=>d.challengeId));for(let d of n)a.has(d)||e.push(`Policy Violation: Missing mandatory challenge ${d}`);let i=[...a].filter(d=>!n.has(d)),c=t.config.behavior.selectRandomly;i.length<c&&e.push(`Policy Violation: Insufficient random count. Need ${c}, got ${i.length}`);for(let d of i)s.includes(d)||e.push(`Policy Violation: ID ${d} is invalid or double-dipped.`);let l=mt.create({config:t.config});for(let d of r.solutions){let b=t.challenges[d.challengeId];b?await l.validateSolution({solution:d,challenge:b})||e.push(`Crypto Violation: Solution for ${d.challengeId} is invalid.`):e.push(`Crypto Violation: Challenge ${d.challengeId} not found in pool.`)}}catch(n){throw console.error(`${o} ${m(n)}`),n}finally{W&&console.log(`${o} complete.`)}}f(yi,"verifyProofAgainstPool");async function at({prevIbGib:r,newData:t,metaspace:e,space:o}){let n=`[${at.name}]`;try{if(W&&console.log(`${n} starting... (I: 8b10e8920f08b7842803665834cf8925)`),!r.data)throw new Error("(UNEXPECTED) prevIbGib.data falsy? (E: 5e84875bf992c585b979e6c8ed5bf225)");if(r.data.revocationInfo)throw new Error(`Keystone has already been revoked (prevIbGib.data.revocationInfo truthy), so we cannot evolve the keystone. Keystone addr: ${y({ibGib:r})} (E: 45d7f846556829de6b2a701838c3f825)`);let s=r.data,a={};s.proofs&&(a.proofs=[]),s.challengePools&&(a.challengePools=[]),s.frameDetails&&(a.frameDetails={}),s.checkpointDetails&&(a.checkpointDetails={}),s.delegates&&(a.delegates="remove"),Object.keys(a).length===0&&(a=void 0);let i=await Me({src:r,dataToRemove:a,dataToAddOrPatch:t,nCounter:!0});if(i.intermediateIbGibs)throw new Error("(UNEXPECTED) resMut8.intermediateIbGibs truthy? I'm not sure if we expect there to be intermediateIbGibs, but I feel like we shouldn't. Pretty sure we shouldn't, definitely don't *want* them. (E: ba40d55d7c2d36d438c413886f148625)");if(i.dnas)throw new Error("(UNEXPECTED) resMut8.dnas truthy? We do not want dnas with keystones. (E: 49470513d018f97d28024f4e82da3b25)");let c=i.newIbGib,l=await ar({currentIbGib:c,prevIbGib:r});if(l.length>0)throw console.error(`${n} Validation Failed:
|
|
17
17
|
${l.join(`
|
|
18
|
-
`)}`),new Error(`(UNEXPECTED) invalid keystone after we just evolved it? Errors: ${l.join("; ")} (E: ae2c58406c1db7687879dfb89fc1f825)`);return await e.put({ibGib:c,space:o}),await e.registerNewIbGib({ibGib:c,space:o}),c}catch(s){throw console.error(`${n} ${m(s)}`),s}finally{W&&console.log(`${n} complete.`)}}f(st,"evolvePersistAndRegisterKeystone");async function Mn({data:r,metaspace:t,space:e}){let o=`[${Mn.name}]`;try{if(W&&console.log(`${o} starting... (I: 5e32389700e9899e788cbefacef7c825)`),e??=await t.getLocalUserSpace({lock:!1}),!e)throw new Error("(UNEXPECTED) space was falsy and we couldn't get default local user space from metaspace? (E: 9a6498cf16a8801f19ec376749742225)");let s=(await M.firstGen({parentIbGib:M.primitive({ib:rr}),ib:await ui({keystoneData:r}),data:r,dna:!1,nCounter:!0,tjp:{timestamp:!0,uuid:!0}})).newIbGib;if(!s.data)throw new Error("(UNEXPECTED) keystoneIbGib.data falsy? We expect the data to be populated with real keystone data. (E: 38a358facdb89d16d81d48c8520d3d25)");if(!s.rel8ns)throw new Error("(UNEXPECTED) keystoneIbGib.rel8ns falsy? we expect the rel8ns to have ancestor and past. (E: 20cb7723dc33ae1ef808fe76d1bf4b25)");if(!s.rel8ns.past||s.rel8ns.past.length===0)throw new Error("(UNEXPECTED) keystoneIbGib.rel8ns.past falsy or empty? we expect the firstGen call to generate an interstitial ibgib that we will splice out. (E: 0fd8388d045ab9f37834c27d67e78825)");return s.data.n=0,s.data.isTjp=!0,delete s.rel8ns.tjp,delete s.rel8ns.past,s.gib=await X({ibGib:s}),await t.put({ibGib:s,space:e}),await t.registerNewIbGib({ibGib:s,space:e}),s}catch(n){throw console.error(`${o} ${m(n)}`),n}finally{W&&console.log(`${o} complete.`)}}f(Mn,"createKeystoneIbGibImpl");async function io({keystoneIbGib:r,dependencyGraph:t,getLatest:e,invalidIfMoreRecentKeystoneFoundInSpace:o,space:n}){let s=`[${io.name}]`;try{if(W&&console.log(`${s} starting... (I: 22e1ca1d5a08a3f90b7fe9da95df7b26)`),!r)throw new Error("(UNEXPECTED) keystoneIbGib falsy? (E: 26482871d529fff6e8899c5d8a6c3826)");let a=[];if(e){let b=y({ibGib:r}),u=await Pe({ibGibs:[r],space:n});if(!u.data)throw new Error("(UNEXPECTED) resGetLatestAddrs.data falsy? (E: 3a23b3b420a8da1928219ca8d47b2126)");if(!u.data.latestAddrsMap)throw new Error("(UNEXPECTED) resGetLatestAddrs.data.latestAddrsMap falsy? (E: 93f1180598fb65a4b8d36e08d6c50426)");let{latestAddrsMap:p}=u.data;if(Object.keys(p).length===0)throw new Error("(UNEXPECTED) latestAddrsMap truthy but empty? (E: 7142f8f7625b9186281d08251e407826)");let g=p[b];if(g)if(g!==b)if(o)a.push(`${s} more recent keystone (${g}) found than the one passed in (${b}) in space (${n.ib}). (E: 64bf48de9448ee5c7528bf03bed2a826)`);else{let[h]=await tn({addrs:[g],space:n});r=h}else W&&console.log(`${s} incoming keystone (${b}) is the latest in the space (${n.ib}) (I: 8ffbd8d6cbc8a461e5e7f1084bd22a26)`);else console.warn(`${s} keystoneIbGib (${b}) not found in space (${n.ib}). I don't know what the implications of this are. (W: 258c88742448db34a585669484771826)`)}t??=await Zt({ibGib:r,space:n});let i=Object.values(t),{mapWithTjp_NoDna:c,mapWithTjp_YesDna:l,mapWithoutTjps:d}=Pr({ibGibs:i});if(Object.keys(l).length>0&&a.push(`${s} DNA found. Keystones should NOT have DNA. (E: a3ec7827c4284cdea61c2372c0615826)`),Object.keys(d).length>0&&a.push(`${s} Non-tjp ibgibs found? Keystones are expected to have tjps. (E: a3ec7827c4284cdea61c2372c0615826)`),Object.keys(c).length>0){let b=Object.values(c),u=zt({ibGibs:b}),p=Object.keys(u);if(p.length===0)throw new Error("(UNEXPECTED) orderedKeystonesMap empty? (E: d437b80bef58e83a034b28af46278726)");if(p.length>1)throw new Error("(UNEXPECTED) more than one timeline in keystone graph? ATOW (02/19/2026) we are expecting only a single timeline. (E: 66085b14e3887a59c872afd240511f26)");let g=p[0],h=u[g];if(h.length===0)throw new Error("(UNEXPECTED) empty keystoneIbGibs_ordered? (E: 4a6b085aa8a76828a8d65367e7e56526)");if((await ao({keystoneIbGib:h[0]})).forEach($=>a.push($)),h.length!==1)for(let $=0;$<h.length-1;$++){let I=h[$],A=h[$+1],w=await ar({prevIbGib:I,currentIbGib:A});w.length>0&&(a.push(`${s} keystone has ${w.length} transition errors. i: ${$}. prevIbGib addr: ${y({ibGib:I})}. currentIbGib addr: ${y({ibGib:A})}. (E: 3ac17be916141d0c286ca5a87bb1b426)`),w.forEach(_=>a.push(_)));break}}else if(a.length===0)throw new Error("(UNEXPECTED) mapWithTjp_NoDna empty (which is an error) but errors.length === 0? If we get here, we expect one of the other errors to have been populated. (E: 7bca2866b6f8fca318923de8c88e8826)");return a}catch(a){throw console.error(`${s} ${m(a)}`),a}finally{W&&console.log(`${s} complete.`)}}f(io,"validateKeystoneGraph");async function co({config:r,masterSecret:t}){let e=mt.create({config:r}),o=await e.derivePoolSecret({masterSecret:t}),n={},s=r.behavior.size,a=Date.now().toString();for(let i=0;i<s;i++){let c=await gi({salt:r.salt,timestamp:a,index:i}),l=await e.generateSolution({poolSecret:o,poolId:r.id,challengeId:c});n[c]=await e.generateChallenge({solution:l})}return n}f(co,"generatePoolChallenges");async function yi({prevPool:r,newMasterSecret:t}){let e=r.config,o=(await F()).substring(0,16),n={...e,salt:o},s=await co({config:n,masterSecret:t});return{id:r.id,config:n,challenges:s,...r.isForeign!==void 0?{isForeign:r.isForeign}:{},...r.metadata?{metadata:r.metadata}:{}}}f(yi,"rotatePoolChallenges");async function kn({pool:r,signingSecret:t}){let e=Object.keys(r.challenges);if(e.length===0)return!1;try{let o=e[0],n=r.challenges[o],s=mt.create({config:r.config}),a=await s.derivePoolSecret({masterSecret:t}),i=await s.generateSolution({poolSecret:a,poolId:r.id,challengeId:o});return await s.validateSolution({solution:i,challenge:n})}catch{return!1}}f(kn,"verifyPoolSecret");var B=!1,Ii=class r{static{f(this,"KeystoneService_V1")}lc=`[${r.name}]`;async genesis({masterSecret:t,emails:e,frameDetails:o,configs:n,metaspace:s,space:a,isPrimary:i}){let c=`${this.lc}[${this.genesis.name}]`;try{B&&console.log(`${c} starting... (I: c98ae8adbc5888dbf84c5aced7610b25)`);let l=[];for(let u of n){let p=await co({config:u,masterSecret:t});l.push({id:u.id,config:u,challenges:p})}if(l.length===0)throw new Error("No challenge pools created. (E: 38e538530996940e1f16a8b199995825)");let d={challengePools:l,proofs:[]};return e&&e.length>0&&(d.emails=[...e]),(o||i!==void 0)&&(d.frameDetails={...o||{}},i!==void 0&&(d.frameDetails.isPrimary=i)),await Mn({data:d,metaspace:s,space:a})}catch(l){throw console.error(`${c} ${m(l)}`),l}finally{B&&console.log(`${c} complete.`)}}async sign({latestKeystone:t,masterSecret:e,claim:o,poolId:n,poolFilter:s,requiredChallengeIds:a=[],frameDetails:i,metaspace:c,space:l,dataToPatch:d}){let b=`${this.lc}[${this.sign.name}]`;try{B&&console.log(`${b} starting...`);let u=t.data;if(u.revocationInfo)throw new Error("Keystone has been revoked. Cannot sign. (E: 4f2198c39116d15c48ba191940316825)");let p=sr({pools:u.challengePools,poolId:n,poolFilter:s,verb:o.verb});B&&console.log(`${b} Selected pool: ${p.id} (size: ${Object.keys(p.challenges).length}) (I: 6b26d6f4aad18380f2b3a0989b592826)`);let g=await wt({pool:p,targetAddr:o.target,requiredChallengeIds:a}),{proof:h,nextPools:E}=await $t({targetPoolId:p.id,prevPools:u.challengePools,masterSecret:e,challengeIds:g,claim:o,requiredChallengeIds:a}),$=(u.n??0)+1,I;if($%Et===0){let _={...t,data:{...u,frameDetails:i}};I=await this.getAggregateDetails({latestKeystone:_,metaspace:c,space:l})}let A={challengePools:E,proofs:[h],frameDetails:i,checkpointDetails:I,...u.delegates?{delegates:u.delegates}:{},...d};return await st({prevIbGib:t,newData:A,metaspace:c,space:l})}catch(u){throw console.error(`${b} ${m(u)}`),u}finally{B&&console.log(`${b} complete.`)}}async validate({currentIbGib:t,prevIbGib:e}){return await ar({currentIbGib:t,prevIbGib:e})}async registerDelegate({parentKeystone:t,delegateKeystone:e,masterSecret:o,frameDetails:n,metaspace:s,space:a,allowedVerbs:i,deviceName:c}){let l=`${this.lc}[${this.registerDelegate.name}]`;try{B&&console.log(`${l} starting...`);let d=await io({keystoneIbGib:e,getLatest:!0,invalidIfMoreRecentKeystoneFoundInSpace:!1,space:a});if(d.length>0)throw new Error(`Delegate keystone validation failed: ${d.join(", ")} (E: 88fa8ab28c9b60e68994511a5825)`);let b=t.data;if(!b.challengePools.some(I=>I.id===Ye))throw new Error("Parent keystone does not support delegation. Manage pool is required. (E: 818fa8ab28c9b60e68994511a5825)");let p=be({ibGib:e});if(!p)throw new Error("(UNEXPECTED) delegateTjpAddr falsy? (E: d4d6e8ad03c8925d4838b9a87b8f2826)");let g={target:p,verb:he},h=b.delegates?{...b.delegates}:{},E=Nr({spaceIb:a.ib}).spaceId;return h[p]={delegateTjpAddr:p,delegateAddr:y({ibGib:e}),thisAddr:y({ibGib:t}),deviceName:c,allowedVerbs:i,spaceId:E},await this.sign({latestKeystone:t,masterSecret:o,claim:g,poolId:Ye,frameDetails:n,metaspace:s,space:a,dataToPatch:{delegates:h}})}catch(d){throw console.error(`${l} ${m(d)}`),d}finally{B&&console.log(`${l} complete.`)}}async unregisterDelegate({parentKeystone:t,delegateTjpAddr:e,masterSecret:o,frameDetails:n,metaspace:s,space:a}){let i=`${this.lc}[${this.unregisterDelegate.name}]`;try{B&&console.log(`${i} starting...`);let c=t.data;if(!c.challengePools.some(p=>p.id===Ye))throw new Error("Parent keystone does not support delegation. Manage pool is required. (E: 3889f8ab28c9b60e68994511a5825)");let d={target:e,verb:he},b=c.delegates?{...c.delegates}:{};if(!b[e])throw new Error(`Delegate ${e} is not registered on this parent. (E: 81d9f8ab28c9b60e68994511a5825)`);return delete b[e],await this.sign({latestKeystone:t,masterSecret:o,claim:d,poolId:Ye,frameDetails:n,metaspace:s,space:a,dataToPatch:{delegates:b}})}catch(c){throw console.error(`${i} ${m(c)}`),c}finally{B&&console.log(`${i} complete.`)}}async getDelegateStatus({parentTjpAddr:t,delegateTjpAddr:e,metaspace:o,space:n}){let s=`${this.lc}[${this.getDelegateStatus.name}]`;try{B&&console.log(`${s} starting...`);let{ib:a,gib:i}=P({ibGibAddr:t}),l=await Pe({ibGibs:[{ib:a,gib:i}],space:n});if(!l.data?.latestAddrsMap)return{registered:!1};let d=l.data.latestAddrsMap[t];if(!d)return{registered:!1};let u=(await o.get({addr:d,space:n})).ibGibs?.at(0);if(!u||!u.data)return{registered:!1};let g=(u.data.delegates||{})[e];return{registered:!!g,delegateInfo:g}}catch(a){throw console.error(`${s} ${m(a)}`),a}finally{B&&console.log(`${s} complete.`)}}async validateGenesisKeystone({keystoneIbGib:t}){return await ao({keystoneIbGib:t})}async getLatestKeystone({addr:t,metaspace:e,space:o}){let n=`${this.lc}[${this.getLatestKeystone.name}]`;try{B&&console.log(`${n} starting...`);let s=await e.getLatestAddr({tjpAddr:t,space:o});if(!s)throw new Error(`could not find latest addr for ${t}`);let a=await e.get({addr:s,space:o});if(a.success&&a.ibGibs&&a.ibGibs.length>0)return a.ibGibs[0];{let c=a.rawResultIbGib?.data?.addrsNotFound??"unknown";throw new Error(`couldn't find latest keystone at ${s}. addrsNotFound: ${c}? resGet.errorMsg: ${a.errorMsg}`)}}catch(s){throw console.error(`${n} ${m(s)}`),s}finally{B&&console.log(`${n} complete.`)}}async validateKeystoneGraph({keystoneIbGib:t,dependencyGraph:e,getLatest:o,invalidIfMoreRecentKeystoneFoundInSpace:n,space:s}){let a=`${this.lc}[${this.validateKeystoneGraph.name}]`;try{return B&&console.log(`${a} starting... (I: 01c5cd455038c270cbf1effc1704af26)`),await io({keystoneIbGib:t,dependencyGraph:e,getLatest:o,invalidIfMoreRecentKeystoneFoundInSpace:n,space:s})}catch(i){throw console.error(`${a} ${m(i)}`),i}finally{B&&console.log(`${a} complete.`)}}async revoke({latestKeystone:t,masterSecret:e,reason:o="User initiated revocation",frameDetails:n,metaspace:s,space:a}){let i=`${this.lc}[${this.revoke.name}]`;try{B&&console.log(`${i} starting...`);let c=t.data,l=sr({pools:c.challengePools,verb:Pt}),d={verb:Pt,target:y({ibGib:t})},b=await wt({pool:l,targetAddr:d.target,requiredChallengeIds:[]});if(b.length===0)throw new Error(`Revocation policy selected 0 challenges? Check config for pool ${l.id}. Revocation requires proof. (E: 97e5a8356d241ae7b882db791cb1f825)`);let{proof:u,nextPools:p}=await $t({targetPoolId:l.id,prevPools:c.challengePools,masterSecret:e,challengeIds:b,claim:d,requiredChallengeIds:[]});p.find(A=>A.id===l.id&&Object.keys(A.challenges).length>0)&&console.warn(`${i} revocation pool ${l.id} is not empty after revocation. Is the revocation pool replenish strategy set to ${me.deleteAll}? (W: 300c28bc8b98fc3e3c0b0d988344f825)`);let g={reason:o,proof:u},h=(c.n??0)+1,E;if(h%Et===0){let A={...t,data:{...c,frameDetails:n,revocationInfo:g}};E=await this.getAggregateDetails({latestKeystone:A,metaspace:s,space:a})}let $={challengePools:p,proofs:[u],revocationInfo:g,frameDetails:n,checkpointDetails:E,...c.delegates?{delegates:c.delegates}:{}};return await st({prevIbGib:t,newData:$,metaspace:s,space:a})}catch(c){throw console.error(`${i} ${m(c)}`),c}finally{B&&console.log(`${i} complete.`)}}async addPools({latestKeystone:t,masterSecret:e,newPools:o,metaspace:n,space:s}){let a=`${this.lc}[${this.addPools.name}]`;try{if(B&&console.log(`${a} starting...`),!t.data)throw new Error("(UNEXPECTED) latestKeystone.data falsy? (E: 7334c8faed128166a999d428c7805b25)");let i=t.data;if(i.revocationInfo)throw new Error("Keystone has been revoked. Cannot add pools. (E: 8599f8f51c78d722252ddb2894fdbe25)");if(o.length===0)throw new Error("No new pools provided to add. (E: 6599f8f51c78d722252ddb2894fdbe25)");let c=sr({pools:i.challengePools,verb:he});B&&console.log(`${a} Authorized via pool: ${c.id}`);let l=y({ibGib:t}),d={verb:he,target:l,details:{type:Lt.add_pool,info:{add:o.map(w=>w.id)}}},b=await wt({pool:c,targetAddr:l}),{proof:u,nextPools:p}=await $t({targetPoolId:c.id,prevPools:i.challengePools,masterSecret:e,challengeIds:b,claim:d}),g=new Set(p.map(w=>w.id));for(let w of o)if(g.has(w.id))throw new Error(`Cannot add pool. ID collision: ${w.id} (E: 8a4c2b1d3e5f6a7b8c9d0e1f2a3b4c5d)`);let h=[...p,...o],E=(i.n??0)+1,$;if(E%Et===0){let w={...t,data:{...i,challengePools:h}};$=await this.getAggregateDetails({latestKeystone:w,metaspace:n,space:s})}let I={challengePools:h,proofs:[u],checkpointDetails:$,...i.delegates?{delegates:i.delegates}:{}};return await st({prevIbGib:t,newData:I,metaspace:n,space:s})}catch(i){throw console.error(`${a} ${m(i)}`),i}finally{B&&console.log(`${a} complete.`)}}async removePools({latestKeystone:t,masterSecret:e,poolIds:o,metaspace:n,space:s}){let a=`${this.lc}[${this.removePools.name}]`;try{if(B&&console.log(`${a} starting...`),!t.data)throw new Error("(UNEXPECTED) latestKeystone.data falsy? (E: 8334c8faed128166a999d428c7805b25)");let i=t.data;if(i.revocationInfo)throw new Error("Keystone has been revoked. Cannot remove pools. (E: 9599f8f51c78d722252ddb2894fdbe25)");if(o.length===0)throw new Error("No pool IDs provided to remove. (E: 7599f8f51c78d722252ddb2894fdbe25)");let c=sr({pools:i.challengePools,verb:he});B&&console.log(`${a} Authorized via pool: ${c.id}`);let l=y({ibGib:t}),d={verb:he,target:l,details:{type:Lt.remove_pool,info:{remove:o}}},b=await wt({pool:c,targetAddr:l}),{proof:u,nextPools:p}=await $t({targetPoolId:c.id,prevPools:i.challengePools,masterSecret:e,challengeIds:b,claim:d}),g=new Set(o),h=p.filter(w=>!g.has(w.id));if(h.length!==p.length-o.length){let w=o.filter(_=>!p.some(S=>S.id===_));throw new Error(`Cannot remove pool. Pool IDs not found in keystone: ${w.join(", ")} (E: 8a4c2b1d3e5f6a7b8c9d0e1f2a3b4c5e)`)}let E=(i.n??0)+1,$;if(E%Et===0){let w={...t,data:{...i,challengePools:h}};$=await this.getAggregateDetails({latestKeystone:w,metaspace:n,space:s})}let I={challengePools:h,proofs:[u],checkpointDetails:$,...i.delegates?{delegates:i.delegates}:{}};return await st({prevIbGib:t,newData:I,metaspace:n,space:s})}catch(i){throw console.error(`${a} ${m(i)}`),i}finally{B&&console.log(`${a} complete.`)}}async getAggregateDetails({latestKeystone:t,metaspace:e,space:o}){let n=`${this.lc}[${this.getAggregateDetails.name}]`;try{let s={},a=t;for(;a;){let i=a.data;if(i.checkpointDetails){s=_t({dominant:s,recessive:i.checkpointDetails});break}if(i.frameDetails&&(s=_t({dominant:s,recessive:i.frameDetails})),i.n===0)break;let c=a.rel8ns?.past,l=c&&c.length>0?c[c.length-1]:void 0;if(!l)break;let d=await e.get({addr:l,space:o});if(!d.success||!d.ibGibs||d.ibGibs.length===0)throw new Error(`Could not find previous keystone frame at ${l} (E: e3d069b22e11e550e58844889ddb5325)`);a=d.ibGibs[0]}return s}catch(s){throw console.error(`${n} ${m(s)}`),s}}async getKeystoneCommonInfo({addr:t,ibGib:e,metaspace:o,space:n}){let s=`${this.lc}[getKeystoneCommonInfo]`;try{let a=t,i=e;if(!a){if(!i)return null;a=y({ibGib:i})}if(!i){let{ib:w,gib:_}=P({ibGibAddr:a});i={ib:w,gib:_}}let c=await Pe({ibGibs:[i],space:n});if(!c.data?.latestAddrsMap)return null;let l=c.data.latestAddrsMap[a]||Object.values(c.data.latestAddrsMap)[0];if(!l)return null;let b=(await o.get({addr:l,space:n})).ibGibs?.at(0);if(!b||!b.data)return null;let u=b.data.frameDetails||{},p=await this.getAggregateDetails({latestKeystone:b,metaspace:o,space:n}),g=p?.username||p?.name||p?.profile?.name||u?.username||u?.name||"",h=p?.description||p?.profile?.description||u?.description||"",E=!!p?.isPrimary||!!p?.profile?.isPrimary||!!u?.isPrimary,$=b.data.n??0,I=u?.timestamp||p?.timestamp||"",A=u?.timestampMs||p?.timestampMs||void 0;return{name:g,description:h,isPrimary:E,aggregateDetails:p,latestFrameDetails:u,n:$,timestamp:I,timestampMs:A}}catch(a){return console.error(`${s} ${m(a)}`),null}}async replacePool({latestKeystone:t,newPool:e,signingSecret:o,signingPoolId:n=Ye,frameDetails:s,metaspace:a,space:i}){let c=`${this.lc}[${this.replacePool.name}]`;try{if(B&&console.log(`${c} starting... replacing pool: ${e.id}`),!t.data)throw new Error("(UNEXPECTED) latestKeystone.data falsy? (E: 1334c8faed128166a999d428c7805b25)");let l=t.data;if(l.revocationInfo)throw new Error("Keystone has been revoked. Cannot replace pool. (E: 2599f8f51c78d722252ddb2894fdbe25)");let d=l.challengePools,b=d.find(S=>S.id===n);if(!b)throw new Error(`Signing pool not found: ${n} (E: 3599f8f51c78d722252ddb2894fdbe25)`);let u=y({ibGib:t}),p={verb:he,target:u,details:{type:Lt.replace_pool,info:{replace:e.id}}},g=await wt({pool:b,targetAddr:u}),{proof:h,nextPools:E}=await $t({targetPoolId:n,prevPools:d,masterSecret:o,challengeIds:g,claim:p}),$=E.findIndex(S=>S.id===e.id);if($===-1)throw new Error(`Target pool to replace '${e.id}' not found in keystone challenge pools.`);E[$]=e;let I=(l.n??0)+1,A;if(I%Et===0){let S={...t,data:{...l,frameDetails:s}};A=await this.getAggregateDetails({latestKeystone:S,metaspace:a,space:i})}let w={challengePools:E,proofs:[h],frameDetails:s,checkpointDetails:A,...l.delegates?{delegates:l.delegates}:{}};return await st({prevIbGib:t,newData:w,metaspace:a,space:i})}catch(l){throw console.error(`${c} ${m(l)}`),l}finally{B&&console.log(`${c} complete.`)}}async changePassword({keystoneIbGib:t,keystoneAddr:e,newMasterSecret:o,signingSecret:n,signingPoolId:s=Ye,poolIds:a,frameDetails:i,metaspace:c,space:l}){let d=`${this.lc}[${this.changePassword.name}]`;try{if(B&&console.log(`${d} starting... (I: 9e3ff83ebd74511f9dad784a1020d926)`),!t&&!e)throw new Error("Either keystoneIbGib or keystoneAddr required. (E: d1b8c8cb75f2c022284e69b8c30af826)");if(t&&e){let x=y({ibGib:t});if(x!==e)throw new Error(`(UNEXPECTED) both keystoneIbGib (addr: ${x}) and keystoneAddr (${e}) provided, but the addrs are unequal? Note that only one is required for this function, but if both are provided the addrs must match exactly. (E: c5574f7e353a48b0bba94a1862af4e26)`)}e??=y({ibGib:t});let b=await this.getLatestKeystone({addr:e,metaspace:c,space:l});if(!b.data)throw new Error("latestKeystone.data falsy (E: 22e498eb8308a33e68b812d8d3905826)");if(b.data.revocationInfo)throw new Error("Keystone has been revoked. Cannot change password. (E: 726298617e8508b3c83b5e985a03e826)");let u=b.data.challengePools,p=u.find(x=>x.id===s);if(!p)throw new Error(`Signing pool not found: ${s} (E: 3599f8f51c78d722252ddb2894fdbe25)`);let g=[];if(a&&a.length>0)for(let x of a){let N=u.find(k=>k.id===x);if(!N)throw new Error(`Target pool to rotate not found: ${x} (E: 4599f8f51c78d722252ddb2894fdbe25)`);g.push(N)}else if(g=u.filter(x=>!x.isForeign),g.length===0)throw new Error("No non-foreign pools found to rotate. (E: 5599f8f51c78d722252ddb2894fdbe25)");let h=[];for(let x of g){let N=await yi({prevPool:x,newMasterSecret:o});h.push(N)}let E=y({ibGib:b}),$={verb:he,target:E,details:{type:Lt.change_password,info:{change:h.map(x=>x.id)}}},I=await wt({pool:p,targetAddr:E}),{proof:A,nextPools:w}=await $t({targetPoolId:s,prevPools:u,masterSecret:n,challengeIds:I,claim:$});for(let x of h){let N=w.findIndex(k=>k.id===x.id);if(N===-1)throw new Error(`Rotated pool ${x.id} not found in next pools list. (E: 6599f8f51c78d722252ddb2894fdbe25)`);w[N]=x}let _=(b.data.n??0)+1,S;if(_%Et===0){let x={...b,data:{...b.data,challengePools:w}};S=await this.getAggregateDetails({latestKeystone:x,metaspace:c,space:l})}let G={challengePools:w,proofs:[A],frameDetails:i,checkpointDetails:S,...b.data.delegates?{delegates:b.data.delegates}:void 0},O=await st({prevIbGib:b,newData:G,metaspace:c,space:l}),U=[];if((a??[]).length===0){let x=await Un({masterSecret:n}),N=await Un({masterSecret:o}),k=Object.keys(b.data.delegates??{});for(let ae of k){let{newKeystone:ie,newDelegates:q}=await this.changePassword({keystoneAddr:ae,metaspace:c,space:l,newMasterSecret:N,signingSecret:x,signingPoolId:s,poolIds:void 0,frameDetails:i});if(q&&q.length>0)throw new Error("(UNEXPECTED) Delegate keystone has its own delegate(s)? ATOW (07/20/2026) second order delegates are not supported. (E: de45a7b7d9b8f61f6e58158269acba26)");U.push(ie)}}return{newKeystone:O,newDelegates:U.length>0?U:void 0}}catch(b){throw console.error(`${d} ${m(b)}`),b}finally{B&&console.log(`${d} complete.`)}}async verifySigningSecret({keystoneIbGib:t,signingSecret:e,poolId:o}){let n=`${this.lc}[${this.verifySigningSecret.name}]`;try{if(!t.data)return!1;let s=t.data.challengePools.find(a=>a.id===o);return s?await kn({pool:s,signingSecret:e}):!1}catch(s){return console.warn(`${n} Exception during verification: ${m(s)}`),!1}}};var lo=!1,jn=class{static{f(this,"KeystoneConfigBuilderBase")}_id;_salt;_size;_replenish;_seq;_rand;_verbs=[];_targetBinding;withId(t){return this._id=t,this}withSalt(t){return this._salt=t,this}withSize(t){return this._size=t,this}withTargetBinding(t){return this._targetBinding=t,this}withFIFO(t){return this._seq=t,this._rand=0,this}withRandom(t){return this._seq=0,this._rand=t,this}withHybrid({seqCount:t,randCount:e}){return this._seq=t,this._rand=e,this}withReplenishStrategy(t){return this._replenish=t,this}buildBehavior(){if(this._size===void 0)throw new Error("size required (E: 68320865d9adb8477836485b20b08826)");if(this._replenish===void 0)throw new Error("replenish strategy required (E: 9f8798d1a568763a282e53c89185b826)");if(this._seq===void 0)throw new Error("sequential required (E: e0da08a24e9790d0a8c1a9322f8eb826)");if(this._rand===void 0)throw new Error("selectRandomly required (E: 7721d84d1a8b7d020d0ab33c3f811426)");if(this._targetBinding===void 0)throw new Error("targetBinding required (E: 9add64d7e8e8cba01d901727a8e9b826)");return{size:this._size,replenish:this._replenish,selectSequentially:this._seq,selectRandomly:this._rand,targetBindingCount:this._targetBinding}}forVerbs(t){return this._verbs=t,this}},Bn=class r extends jn{static{f(this,"KeystoneConfigBuilder_HashV1")}lc=`[${r}]`;_algo;_rounds;withHash({algo:t,rounds:e}){let o=`${this.lc}[${this.withHash.name}]`;try{return lo&&console.log(`${o} starting... (I: 15d1b3bd2e98bba33fc6c78228755826)`),this._algo=t,this._rounds=e,this}catch(n){throw console.error(`${o} ${m(n)}`),n}finally{lo&&console.log(`${o} complete.`)}}build(){let t=`${this.lc}[${this.build.name}]`;try{if(lo&&console.log(`${t} starting... (I: 5df568c63c4993bb98df0a319ee16826)`),!this._id)throw new Error("id required (E: b50d082adf38bcbf463552f80d2c3226)");if(!this._salt)throw new Error("salt required (E: b0f1926657b8d7d3a88fb9385ead5826)");if(!this._algo)throw new Error("algorithm required (E: cff228f9898fd6383ef752088dae6826)");if(this._rounds===void 0)throw new Error("rounds required (E: eb72580f3b014cda18cba3e399683c26)");return{id:this._id,type:Ce.hash_reveal_v1,salt:this._salt,allowedVerbs:this._verbs,behavior:this.buildBehavior(),algo:this._algo,rounds:this._rounds}}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{lo&&console.log(`${t} complete.`)}}},ir=class{static{f(this,"KeystoneConfig")}static hash(){return new Bn}};function Nw(r){if(r.type&&r.type!==Ce.hash_reveal_v1)throw new Error(`invalid type (${r.type}). Only ${Ce.hash_reveal_v1} currently implemented. (E: c38616cd7a459149f670418f88766526)`);let{salt:t,id:e,size:o,sequential:n,random:s,targetBinding:a,replenishStrategy:i,verbs:c,hashAlgorithm:l,hashRounds:d}=r;return ir.hash().withId(e).withSalt(t).withSize(o??Za).withHybrid({seqCount:n??Qa,randCount:s??ei}).withTargetBinding(a??ti).withReplenishStrategy(i??ri).withHash({algo:l??oi,rounds:d??ni}).forVerbs(c??[]).build()}f(Nw,"createStandardPoolConfig");function ul(r){if(r.type&&r.type!==Ce.hash_reveal_v1)throw new Error(`invalid type (${r.type}). Only ${Ce.hash_reveal_v1} currently implemented. (E: 09c1f7772bd2a7910f5562b4934d3826)`);let{salt:t,id:e,size:o,sequential:n,random:s,targetBinding:a,replenishStrategy:i,verbs:c,hashAlgorithm:l,hashRounds:d}=r;return ir.hash().withId(e).withSalt(t).withSize(o??si).withHybrid({seqCount:n??ai,randCount:s??ii}).withTargetBinding(a??ci).withReplenishStrategy(i??li).withHash({algo:l??di,rounds:d??fi}).forVerbs(c??[]).build()}f(ul,"createHighSecurityPoolConfig");function Lw(r){return ul({...r,id:r.id??Ye,verbs:r.verbs??[Rn.MANAGE]})}f(Lw,"createManagePoolConfig");function Pw({template:r,salt:t}){let e=r.behavior;return ir.hash().withId(r.id).withSalt(t).withSize(e.size).withHybrid({seqCount:e.selectSequentially,randCount:e.selectRandomly}).withTargetBinding(e.targetBindingCount).withReplenishStrategy(e.replenish).withHash({algo:r.algo,rounds:r.rounds}).forVerbs(r.allowedVerbs).build()}f(Pw,"createPoolConfigFromJson");var fo="anon_fn",_i={fnHash:""};var Ti=!1;function Fn({data:r}){let t=`[${Fn.name}]`;try{if(Ti&&console.log(`${t} starting... (I: 37bb06e0390c5bcadf04501727d64923)`),!r?.fnHash)throw new Error("data.fnHash required (E: 2e560f2c59822bc5ba024d4a8e99d323)");return`witness ${fo} ${r.fnHash}`}catch(e){throw console.error(`${t} ${e.message}`),e}finally{Ti&&console.log(`${t} complete.`)}}f(Fn,"getAnonymousFnIb");var at=class{static{f(this,"AnonymousFnWitness_V1")}fn;ib=fo.concat();gib=L;data=v(_i);rel8ns;constructor(t){if(this.fn=t,!t)throw new Error("fn required (E: b1e1478f466a2a347b75e7c336f8d323)")}async witness(t){return this.data.fnHash=await ce({s:this.fn.toString()}),this.ib=Fn({data:this.data}),this.gib=await X({ibGib:this}),this.fn(t)}};var bo=!1;function pl({err:r}){let t=`[${pl.name}]`;try{if(bo&&console.log(`${t} starting... (I: 96f8b767c50f24768ced7beebb291723)`),en(r)){let e=r;if(!r.data)throw new Error("err isIbGib but err.data is false. (E: 151a6bab647c638c454fd277ac468f23)");if(Ke({ibGib:r}))return r.data.raw;throw new Error("(UNEXPECTED) err isIbGib but not ErrorIbGib_V1? (E: 81c2283fad5db3485c6e9acedbda9723)")}else return m(r)}catch(e){throw console.error(`${t} ${e.message}`),e}finally{bo&&console.log(`${t} complete.`)}}f(pl,"extractObsErrMsg");function hl(r){let t=`[${hl.name}]`;try{bo&&console.log(`${t} starting... (I: 3d2c3658a0fda83ece1f2b095a365823)`);let e;if(typeof r=="function"?e={next:r}:e=r,!e.next)throw new Error("observer.next required (typeof observerOrFn !== 'function') (E: da944e93b32ab5918f11751bcd651823)");let o=f(async d=>(await e.next(d),V),"fnNext"),n=f(async d=>(d.ib==="complete"?e.complete&&await e.complete():Ke({ibGib:d})?e.error&&await e.error(d):await e.next(d),V),"fnWitness"),s=new at(o),a=new at(n),i={ib:"observer",witness:f(async d=>await a.witness(d),"witness"),next:f(async d=>{await s.witness(d)},"next")},c=e.error??(async d=>{let b;if(typeof d=="string")b=m(d);else if(d.ib)if(Ke({ibGib:d}))b=m(d.data.raw);else throw new Error(`${t} (UNEXPECTED) first off, observer.error is falsy. secondly, error came down pipeline and has an "ib" property but is not an ErrorIbGib_V1? (E: 0a2a46b9620b4a6a84c7ba1100da537b)`);else d instanceof Error?b=m(d):typeof d.message=="string"?b=m(d.message):b="[unknown thing came down pipe that ain't an error]";console.error(`Error occurred but observer.error is falsy. error: ${b} (E: 822c60c7c4d542efacd5c2dea7e88062)`)}),l=new at(async d=>(c(d),V));if(i.error=async d=>{typeof d=="string"?d=await ut({rawMsg:d}):d instanceof Error&&(d=await ut({rawMsg:d.message}));try{await l.witness(d)}catch{e.error?console.error(`${t} there was another error when executing errorAnonFnWitness.witness (wrapper of caller's observer.error) trapping this. (E: 8fa3c4e633df4491a82951e3b677d9a9)`):console.error(`${t} there was another error when executing errorAnonFnWitness.witness (caller's observer.error was falsy). trapping this. (E: f5ff2db0d762487287139a4175eb7689)`)}},e.complete){let d=e.complete,b=new at(async u=>(await d(),V));i.complete=async()=>{try{await b.witness(V)}catch(u){console.error(`${t} there was an error when executing completeAnonFnWitness (wrapper for observer.complete fn) error: ${m(u)} (E: c9e61b08429e42c1b85d2215f735ba2f)`)}}}return i}catch(e){throw console.error(`${t} ${e.message}`),e}finally{bo&&console.log(`${t} complete.`)}}f(hl,"fnObs");export{f as a,z as b,we as c,v as d,xe as e,ce as f,F as g,H as h,le as i,m as j,po as k,ge as l,lr as m,xi as n,Wn as o,Tt as p,L as q,V as r,J as s,Oe as t,ts as u,We as v,y as w,P as x,K as y,Pi as z,Z as A,X as B,re as C,Me as D,Ie as E,oe as F,kt as G,Gt as H,At as I,M as J,Gd as K,Sd as L,xd as M,pr as N,Ri as O,as as P,is as Q,Hd as R,Xd as S,Kd as T,Ci as U,Yd as V,gr as W,Go as X,Ui as Y,rf as Z,mr as _,ze as $,wr as aa,Is as ba,$r as ca,ji as da,Bi as ea,yb as fa,Ib as ga,_b as ha,Tb as ia,Ab as ja,Gb as ka,Yi as la,Vi as ma,Ss as na,Uo as oa,zi as pa,Ji as qa,xt as ra,Ht as sa,Rs as ta,ac as ua,Ms as va,uu as wa,gu as xa,ne as ya,Xo as za,Ko as Aa,ee as Ba,ic as Ca,Dr as Da,vr as Ea,de as Fa,Yo as Ga,js as Ha,Ne as Ia,St as Ja,Ho as Ka,qs as La,Ae as Ma,Vt as Na,lc as Oa,dc as Pa,fc as Qa,bc as Ra,Ge as Sa,qu as Ta,uc as Ua,pc as Va,Nr as Wa,Pe as Xa,hc as Ya,gc as Za,Ec as _a,mc as $a,Te as ab,np as bb,ra as cb,Kt as db,Pr as eb,zt as fb,oa as gb,be as hb,Re as ib,en as jb,Xt as kb,tn as lb,et as mb,pp as nb,Tc as ob,hp as pb,gp as qb,Ep as rb,mp as sb,sa as tb,dp as ub,Rp as vb,Cp as wb,Up as xb,Mp as yb,kp as zb,jp as Ab,Ot as Bb,Gc as Cb,Sc as Db,xc as Eb,ft as Fb,Ea as Gb,Oc as Hb,wa as Ib,ma as Jb,vc as Kb,Nc as Lb,Lc as Mb,Pc as Nb,Rc as Ob,Cc as Pb,Uc as Qb,Mc as Rb,dn as Sb,an as Tb,Ur as Ub,kc as Vb,jc as Wb,aa as Xb,Bc as Yb,Ia as Zb,Lh as _b,Fc as $b,Zt as ac,qc as bc,Hc as cc,Xc as dc,pn as ec,Kc as fc,Yc as gc,Sa as hc,Vc as ic,gn as jc,ag as kc,ig as lc,ut as mc,pl as nc,hl as oc,Wc as pc,pt as qc,ht as rc,mn as sc,Nt as tc,Gm as uc,Ce as vc,me as wc,rr as xc,Nn as yc,Ln as zc,ro as Ac,Ja as Bc,al as Cc,il as Dc,Cn as Ec,ll as Fc,Un as Gc,mt as Hc,uw as Ic,Ii as Jc,Nw as Kc,Lw as Lc,Pw as Mc};
|
|
19
|
-
//# sourceMappingURL=chunk-
|
|
18
|
+
`)}`),new Error(`(UNEXPECTED) invalid keystone after we just evolved it? Errors: ${l.join("; ")} (E: ae2c58406c1db7687879dfb89fc1f825)`);return await e.put({ibGib:c,space:o}),await e.registerNewIbGib({ibGib:c,space:o}),c}catch(s){throw console.error(`${n} ${m(s)}`),s}finally{W&&console.log(`${n} complete.`)}}f(at,"evolvePersistAndRegisterKeystone");async function Mn({data:r,metaspace:t,space:e}){let o=`[${Mn.name}]`;try{if(W&&console.log(`${o} starting... (I: 5e32389700e9899e788cbefacef7c825)`),e??=await t.getLocalUserSpace({lock:!1}),!e)throw new Error("(UNEXPECTED) space was falsy and we couldn't get default local user space from metaspace? (E: 9a6498cf16a8801f19ec376749742225)");let s=(await M.firstGen({parentIbGib:M.primitive({ib:rr}),ib:await pi({keystoneData:r}),data:r,dna:!1,nCounter:!0,tjp:{timestamp:!0,uuid:!0}})).newIbGib;if(!s.data)throw new Error("(UNEXPECTED) keystoneIbGib.data falsy? We expect the data to be populated with real keystone data. (E: 38a358facdb89d16d81d48c8520d3d25)");if(!s.rel8ns)throw new Error("(UNEXPECTED) keystoneIbGib.rel8ns falsy? we expect the rel8ns to have ancestor and past. (E: 20cb7723dc33ae1ef808fe76d1bf4b25)");if(!s.rel8ns.past||s.rel8ns.past.length===0)throw new Error("(UNEXPECTED) keystoneIbGib.rel8ns.past falsy or empty? we expect the firstGen call to generate an interstitial ibgib that we will splice out. (E: 0fd8388d045ab9f37834c27d67e78825)");return s.data.n=0,s.data.isTjp=!0,delete s.rel8ns.tjp,delete s.rel8ns.past,s.gib=await X({ibGib:s}),await t.put({ibGib:s,space:e}),await t.registerNewIbGib({ibGib:s,space:e}),s}catch(n){throw console.error(`${o} ${m(n)}`),n}finally{W&&console.log(`${o} complete.`)}}f(Mn,"createKeystoneIbGibImpl");async function io({keystoneIbGib:r,dependencyGraph:t,getLatest:e,invalidIfMoreRecentKeystoneFoundInSpace:o,space:n}){let s=`[${io.name}]`;try{if(W&&console.log(`${s} starting... (I: 22e1ca1d5a08a3f90b7fe9da95df7b26)`),!r)throw new Error("(UNEXPECTED) keystoneIbGib falsy? (E: 26482871d529fff6e8899c5d8a6c3826)");let a=[];if(e){let b=y({ibGib:r}),u=await Ce({ibGibs:[r],space:n});if(!u.data)throw new Error("(UNEXPECTED) resGetLatestAddrs.data falsy? (E: 3a23b3b420a8da1928219ca8d47b2126)");if(!u.data.latestAddrsMap)throw new Error("(UNEXPECTED) resGetLatestAddrs.data.latestAddrsMap falsy? (E: 93f1180598fb65a4b8d36e08d6c50426)");let{latestAddrsMap:p}=u.data;if(Object.keys(p).length===0)throw new Error("(UNEXPECTED) latestAddrsMap truthy but empty? (E: 7142f8f7625b9186281d08251e407826)");let g=p[b];if(g)if(g!==b)if(o)a.push(`${s} more recent keystone (${g}) found than the one passed in (${b}) in space (${n.ib}). (E: 64bf48de9448ee5c7528bf03bed2a826)`);else{let[h]=await tn({addrs:[g],space:n});r=h}else W&&console.log(`${s} incoming keystone (${b}) is the latest in the space (${n.ib}) (I: 8ffbd8d6cbc8a461e5e7f1084bd22a26)`);else console.warn(`${s} keystoneIbGib (${b}) not found in space (${n.ib}). I don't know what the implications of this are. (W: 258c88742448db34a585669484771826)`)}t??=await Zt({ibGib:r,space:n});let i=Object.values(t),{mapWithTjp_NoDna:c,mapWithTjp_YesDna:l,mapWithoutTjps:d}=Cr({ibGibs:i});if(Object.keys(l).length>0&&a.push(`${s} DNA found. Keystones should NOT have DNA. (E: a3ec7827c4284cdea61c2372c0615826)`),Object.keys(d).length>0&&a.push(`${s} Non-tjp ibgibs found? Keystones are expected to have tjps. (E: a3ec7827c4284cdea61c2372c0615826)`),Object.keys(c).length>0){let b=Object.values(c),u=zt({ibGibs:b}),p=Object.keys(u);if(p.length===0)throw new Error("(UNEXPECTED) orderedKeystonesMap empty? (E: d437b80bef58e83a034b28af46278726)");if(p.length>1)throw new Error("(UNEXPECTED) more than one timeline in keystone graph? ATOW (02/19/2026) we are expecting only a single timeline. (E: 66085b14e3887a59c872afd240511f26)");let g=p[0],h=u[g];if(h.length===0)throw new Error("(UNEXPECTED) empty keystoneIbGibs_ordered? (E: 4a6b085aa8a76828a8d65367e7e56526)");if((await ao({keystoneIbGib:h[0]})).forEach($=>a.push($)),h.length!==1)for(let $=0;$<h.length-1;$++){let I=h[$],A=h[$+1],w=await ar({prevIbGib:I,currentIbGib:A});w.length>0&&(a.push(`${s} keystone has ${w.length} transition errors. i: ${$}. prevIbGib addr: ${y({ibGib:I})}. currentIbGib addr: ${y({ibGib:A})}. (E: 3ac17be916141d0c286ca5a87bb1b426)`),w.forEach(_=>a.push(_)));break}}else if(a.length===0)throw new Error("(UNEXPECTED) mapWithTjp_NoDna empty (which is an error) but errors.length === 0? If we get here, we expect one of the other errors to have been populated. (E: 7bca2866b6f8fca318923de8c88e8826)");return a}catch(a){throw console.error(`${s} ${m(a)}`),a}finally{W&&console.log(`${s} complete.`)}}f(io,"validateKeystoneGraph");async function co({config:r,masterSecret:t}){let e=mt.create({config:r}),o=await e.derivePoolSecret({masterSecret:t}),n={},s=r.behavior.size,a=Date.now().toString();for(let i=0;i<s;i++){let c=await Ei({salt:r.salt,timestamp:a,index:i}),l=await e.generateSolution({poolSecret:o,poolId:r.id,challengeId:c});n[c]=await e.generateChallenge({solution:l})}return n}f(co,"generatePoolChallenges");async function Ii({prevPool:r,newMasterSecret:t}){let e=r.config,o=(await F()).substring(0,16),n={...e,salt:o},s=await co({config:n,masterSecret:t});return{id:r.id,config:n,challenges:s,...r.isForeign!==void 0?{isForeign:r.isForeign}:{},...r.metadata?{metadata:r.metadata}:{}}}f(Ii,"rotatePoolChallenges");async function kn({pool:r,signingSecret:t}){let e=Object.keys(r.challenges);if(e.length===0)return!1;try{let o=e[0],n=r.challenges[o],s=mt.create({config:r.config}),a=await s.derivePoolSecret({masterSecret:t}),i=await s.generateSolution({poolSecret:a,poolId:r.id,challengeId:o});return await s.validateSolution({solution:i,challenge:n})}catch{return!1}}f(kn,"verifyPoolSecret");var B=!1,_i=class r{static{f(this,"KeystoneService_V1")}lc=`[${r.name}]`;async genesis({masterSecret:t,emails:e,frameDetails:o,configs:n,metaspace:s,space:a,isPrimary:i}){let c=`${this.lc}[${this.genesis.name}]`;try{B&&console.log(`${c} starting... (I: c98ae8adbc5888dbf84c5aced7610b25)`);let l=[];for(let u of n){let p=await co({config:u,masterSecret:t});l.push({id:u.id,config:u,challenges:p})}if(l.length===0)throw new Error("No challenge pools created. (E: 38e538530996940e1f16a8b199995825)");let d={challengePools:l,proofs:[]};return e&&e.length>0&&(d.emails=[...e]),(o||i!==void 0)&&(d.frameDetails={...o||{}},i!==void 0&&(d.frameDetails.isPrimary=i)),await Mn({data:d,metaspace:s,space:a})}catch(l){throw console.error(`${c} ${m(l)}`),l}finally{B&&console.log(`${c} complete.`)}}async sign({latestKeystone:t,masterSecret:e,claim:o,poolId:n,poolFilter:s,requiredChallengeIds:a=[],frameDetails:i,metaspace:c,space:l,dataToPatch:d}){let b=`${this.lc}[${this.sign.name}]`;try{B&&console.log(`${b} starting...`);let u=t.data;if(u.revocationInfo)throw new Error("Keystone has been revoked. Cannot sign. (E: 4f2198c39116d15c48ba191940316825)");let p=sr({pools:u.challengePools,poolId:n,poolFilter:s,verb:o.verb});B&&console.log(`${b} Selected pool: ${p.id} (size: ${Object.keys(p.challenges).length}) (I: 6b26d6f4aad18380f2b3a0989b592826)`);let g=await wt({pool:p,targetAddr:o.target,requiredChallengeIds:a}),{proof:h,nextPools:E}=await $t({targetPoolId:p.id,prevPools:u.challengePools,masterSecret:e,challengeIds:g,claim:o,requiredChallengeIds:a}),$=(u.n??0)+1,I;if($%Et===0){let _={...t,data:{...u,frameDetails:i}};I=await this.getAggregateDetails({latestKeystone:_,metaspace:c,space:l})}let A={challengePools:E,proofs:[h],frameDetails:i,checkpointDetails:I,...u.delegates?{delegates:u.delegates}:{},...d};return await at({prevIbGib:t,newData:A,metaspace:c,space:l})}catch(u){throw console.error(`${b} ${m(u)}`),u}finally{B&&console.log(`${b} complete.`)}}async validate({currentIbGib:t,prevIbGib:e}){return await ar({currentIbGib:t,prevIbGib:e})}async registerDelegate({parentKeystone:t,delegateKeystone:e,masterSecret:o,frameDetails:n,metaspace:s,space:a,allowedVerbs:i,deviceName:c}){let l=`${this.lc}[${this.registerDelegate.name}]`;try{B&&console.log(`${l} starting...`);let d=await io({keystoneIbGib:e,getLatest:!0,invalidIfMoreRecentKeystoneFoundInSpace:!1,space:a});if(d.length>0)throw new Error(`Delegate keystone validation failed: ${d.join(", ")} (E: 88fa8ab28c9b60e68994511a5825)`);let b=t.data;if(!b.challengePools.some(I=>I.id===Ve))throw new Error("Parent keystone does not support delegation. Manage pool is required. (E: 818fa8ab28c9b60e68994511a5825)");let p=ue({ibGib:e});if(!p)throw new Error("(UNEXPECTED) delegateTjpAddr falsy? (E: d4d6e8ad03c8925d4838b9a87b8f2826)");let g={target:p,verb:he},h=b.delegates?{...b.delegates}:{},E=Nr({spaceIb:a.ib}).spaceId;return h[p]={delegateTjpAddr:p,delegateAddr:y({ibGib:e}),thisAddr:y({ibGib:t}),deviceName:c,allowedVerbs:i,spaceId:E},await this.sign({latestKeystone:t,masterSecret:o,claim:g,poolId:Ve,frameDetails:n,metaspace:s,space:a,dataToPatch:{delegates:h}})}catch(d){throw console.error(`${l} ${m(d)}`),d}finally{B&&console.log(`${l} complete.`)}}async unregisterDelegate({parentKeystone:t,delegateTjpAddr:e,masterSecret:o,frameDetails:n,metaspace:s,space:a}){let i=`${this.lc}[${this.unregisterDelegate.name}]`;try{B&&console.log(`${i} starting...`);let c=t.data;if(!c.challengePools.some(p=>p.id===Ve))throw new Error("Parent keystone does not support delegation. Manage pool is required. (E: 3889f8ab28c9b60e68994511a5825)");let d={target:e,verb:he},b=c.delegates?{...c.delegates}:{};if(!b[e])throw new Error(`Delegate ${e} is not registered on this parent. (E: 81d9f8ab28c9b60e68994511a5825)`);return delete b[e],await this.sign({latestKeystone:t,masterSecret:o,claim:d,poolId:Ve,frameDetails:n,metaspace:s,space:a,dataToPatch:{delegates:b}})}catch(c){throw console.error(`${i} ${m(c)}`),c}finally{B&&console.log(`${i} complete.`)}}async getDelegateStatus({parentTjpAddr:t,delegateTjpAddr:e,metaspace:o,space:n}){let s=`${this.lc}[${this.getDelegateStatus.name}]`;try{B&&console.log(`${s} starting...`);let{ib:a,gib:i}=C({ibGibAddr:t}),l=await Ce({ibGibs:[{ib:a,gib:i}],space:n});if(!l.data?.latestAddrsMap)return{registered:!1};let d=l.data.latestAddrsMap[t];if(!d)return{registered:!1};let u=(await o.get({addr:d,space:n})).ibGibs?.at(0);if(!u||!u.data)return{registered:!1};let g=(u.data.delegates||{})[e];return{registered:!!g,delegateInfo:g}}catch(a){throw console.error(`${s} ${m(a)}`),a}finally{B&&console.log(`${s} complete.`)}}async validateGenesisKeystone({keystoneIbGib:t}){return await ao({keystoneIbGib:t})}async getLatestKeystone({addr:t,metaspace:e,space:o}){let n=`${this.lc}[${this.getLatestKeystone.name}]`;try{B&&console.log(`${n} starting...`);let s=await e.getLatestAddr({tjpAddr:t,space:o});if(!s)throw new Error(`could not find latest addr for ${t}`);let a=await e.get({addr:s,space:o});if(a.success&&a.ibGibs&&a.ibGibs.length>0)return a.ibGibs[0];{let c=a.rawResultIbGib?.data?.addrsNotFound??"unknown";throw new Error(`couldn't find latest keystone at ${s}. addrsNotFound: ${c}? resGet.errorMsg: ${a.errorMsg}`)}}catch(s){throw console.error(`${n} ${m(s)}`),s}finally{B&&console.log(`${n} complete.`)}}async validateKeystoneGraph({keystoneIbGib:t,dependencyGraph:e,getLatest:o,invalidIfMoreRecentKeystoneFoundInSpace:n,space:s}){let a=`${this.lc}[${this.validateKeystoneGraph.name}]`;try{return B&&console.log(`${a} starting... (I: 01c5cd455038c270cbf1effc1704af26)`),await io({keystoneIbGib:t,dependencyGraph:e,getLatest:o,invalidIfMoreRecentKeystoneFoundInSpace:n,space:s})}catch(i){throw console.error(`${a} ${m(i)}`),i}finally{B&&console.log(`${a} complete.`)}}async revoke({latestKeystone:t,masterSecret:e,reason:o="User initiated revocation",frameDetails:n,metaspace:s,space:a}){let i=`${this.lc}[${this.revoke.name}]`;try{B&&console.log(`${i} starting...`);let c=t.data,l=sr({pools:c.challengePools,verb:Ct}),d={verb:Ct,target:y({ibGib:t})},b=await wt({pool:l,targetAddr:d.target,requiredChallengeIds:[]});if(b.length===0)throw new Error(`Revocation policy selected 0 challenges? Check config for pool ${l.id}. Revocation requires proof. (E: 97e5a8356d241ae7b882db791cb1f825)`);let{proof:u,nextPools:p}=await $t({targetPoolId:l.id,prevPools:c.challengePools,masterSecret:e,challengeIds:b,claim:d,requiredChallengeIds:[]});p.find(A=>A.id===l.id&&Object.keys(A.challenges).length>0)&&console.warn(`${i} revocation pool ${l.id} is not empty after revocation. Is the revocation pool replenish strategy set to ${me.deleteAll}? (W: 300c28bc8b98fc3e3c0b0d988344f825)`);let g={reason:o,proof:u},h=(c.n??0)+1,E;if(h%Et===0){let A={...t,data:{...c,frameDetails:n,revocationInfo:g}};E=await this.getAggregateDetails({latestKeystone:A,metaspace:s,space:a})}let $={challengePools:p,proofs:[u],revocationInfo:g,frameDetails:n,checkpointDetails:E,...c.delegates?{delegates:c.delegates}:{}};return await at({prevIbGib:t,newData:$,metaspace:s,space:a})}catch(c){throw console.error(`${i} ${m(c)}`),c}finally{B&&console.log(`${i} complete.`)}}async addPools({latestKeystone:t,masterSecret:e,newPools:o,metaspace:n,space:s}){let a=`${this.lc}[${this.addPools.name}]`;try{if(B&&console.log(`${a} starting...`),!t.data)throw new Error("(UNEXPECTED) latestKeystone.data falsy? (E: 7334c8faed128166a999d428c7805b25)");let i=t.data;if(i.revocationInfo)throw new Error("Keystone has been revoked. Cannot add pools. (E: 8599f8f51c78d722252ddb2894fdbe25)");if(o.length===0)throw new Error("No new pools provided to add. (E: 6599f8f51c78d722252ddb2894fdbe25)");let c=sr({pools:i.challengePools,verb:he});B&&console.log(`${a} Authorized via pool: ${c.id}`);let l=y({ibGib:t}),d={verb:he,target:l,details:{type:Lt.add_pool,info:{add:o.map(w=>w.id)}}},b=await wt({pool:c,targetAddr:l}),{proof:u,nextPools:p}=await $t({targetPoolId:c.id,prevPools:i.challengePools,masterSecret:e,challengeIds:b,claim:d}),g=new Set(p.map(w=>w.id));for(let w of o)if(g.has(w.id))throw new Error(`Cannot add pool. ID collision: ${w.id} (E: 8a4c2b1d3e5f6a7b8c9d0e1f2a3b4c5d)`);let h=[...p,...o],E=(i.n??0)+1,$;if(E%Et===0){let w={...t,data:{...i,challengePools:h}};$=await this.getAggregateDetails({latestKeystone:w,metaspace:n,space:s})}let I={challengePools:h,proofs:[u],checkpointDetails:$,...i.delegates?{delegates:i.delegates}:{}};return await at({prevIbGib:t,newData:I,metaspace:n,space:s})}catch(i){throw console.error(`${a} ${m(i)}`),i}finally{B&&console.log(`${a} complete.`)}}async removePools({latestKeystone:t,masterSecret:e,poolIds:o,metaspace:n,space:s}){let a=`${this.lc}[${this.removePools.name}]`;try{if(B&&console.log(`${a} starting...`),!t.data)throw new Error("(UNEXPECTED) latestKeystone.data falsy? (E: 8334c8faed128166a999d428c7805b25)");let i=t.data;if(i.revocationInfo)throw new Error("Keystone has been revoked. Cannot remove pools. (E: 9599f8f51c78d722252ddb2894fdbe25)");if(o.length===0)throw new Error("No pool IDs provided to remove. (E: 7599f8f51c78d722252ddb2894fdbe25)");let c=sr({pools:i.challengePools,verb:he});B&&console.log(`${a} Authorized via pool: ${c.id}`);let l=y({ibGib:t}),d={verb:he,target:l,details:{type:Lt.remove_pool,info:{remove:o}}},b=await wt({pool:c,targetAddr:l}),{proof:u,nextPools:p}=await $t({targetPoolId:c.id,prevPools:i.challengePools,masterSecret:e,challengeIds:b,claim:d}),g=new Set(o),h=p.filter(w=>!g.has(w.id));if(h.length!==p.length-o.length){let w=o.filter(_=>!p.some(S=>S.id===_));throw new Error(`Cannot remove pool. Pool IDs not found in keystone: ${w.join(", ")} (E: 8a4c2b1d3e5f6a7b8c9d0e1f2a3b4c5e)`)}let E=(i.n??0)+1,$;if(E%Et===0){let w={...t,data:{...i,challengePools:h}};$=await this.getAggregateDetails({latestKeystone:w,metaspace:n,space:s})}let I={challengePools:h,proofs:[u],checkpointDetails:$,...i.delegates?{delegates:i.delegates}:{}};return await at({prevIbGib:t,newData:I,metaspace:n,space:s})}catch(i){throw console.error(`${a} ${m(i)}`),i}finally{B&&console.log(`${a} complete.`)}}async getAggregateDetails({latestKeystone:t,metaspace:e,space:o}){let n=`${this.lc}[${this.getAggregateDetails.name}]`;try{let s={},a=t;for(;a;){let i=a.data;if(i.checkpointDetails){s=_t({dominant:s,recessive:i.checkpointDetails});break}if(i.frameDetails&&(s=_t({dominant:s,recessive:i.frameDetails})),i.n===0)break;let c=a.rel8ns?.past,l=c&&c.length>0?c[c.length-1]:void 0;if(!l)break;let d=await e.get({addr:l,space:o});if(!d.success||!d.ibGibs||d.ibGibs.length===0)throw new Error(`Could not find previous keystone frame at ${l} (E: e3d069b22e11e550e58844889ddb5325)`);a=d.ibGibs[0]}return s}catch(s){throw console.error(`${n} ${m(s)}`),s}}async getKeystoneCommonInfo({addr:t,ibGib:e,metaspace:o,space:n}){let s=`${this.lc}[getKeystoneCommonInfo]`;try{let a=t,i=e;if(!a){if(!i)return null;a=y({ibGib:i})}if(!i){let{ib:w,gib:_}=C({ibGibAddr:a});i={ib:w,gib:_}}let c=await Ce({ibGibs:[i],space:n});if(!c.data?.latestAddrsMap)return null;let l=c.data.latestAddrsMap[a]||Object.values(c.data.latestAddrsMap)[0];if(!l)return null;let b=(await o.get({addr:l,space:n})).ibGibs?.at(0);if(!b||!b.data)return null;let u=b.data.frameDetails||{},p=await this.getAggregateDetails({latestKeystone:b,metaspace:o,space:n}),g=p?.username||p?.name||p?.profile?.name||u?.username||u?.name||"",h=p?.description||p?.profile?.description||u?.description||"",E=!!p?.isPrimary||!!p?.profile?.isPrimary||!!u?.isPrimary,$=b.data.n??0,I=u?.timestamp||p?.timestamp||"",A=u?.timestampMs||p?.timestampMs||void 0;return{name:g,description:h,isPrimary:E,aggregateDetails:p,latestFrameDetails:u,n:$,timestamp:I,timestampMs:A}}catch(a){return console.error(`${s} ${m(a)}`),null}}async replacePool({latestKeystone:t,newPool:e,signingSecret:o,signingPoolId:n=Ve,frameDetails:s,metaspace:a,space:i}){let c=`${this.lc}[${this.replacePool.name}]`;try{if(B&&console.log(`${c} starting... replacing pool: ${e.id}`),!t.data)throw new Error("(UNEXPECTED) latestKeystone.data falsy? (E: 1334c8faed128166a999d428c7805b25)");let l=t.data;if(l.revocationInfo)throw new Error("Keystone has been revoked. Cannot replace pool. (E: 2599f8f51c78d722252ddb2894fdbe25)");let d=l.challengePools,b=d.find(S=>S.id===n);if(!b)throw new Error(`Signing pool not found: ${n} (E: 3599f8f51c78d722252ddb2894fdbe25)`);let u=y({ibGib:t}),p={verb:he,target:u,details:{type:Lt.replace_pool,info:{replace:e.id}}},g=await wt({pool:b,targetAddr:u}),{proof:h,nextPools:E}=await $t({targetPoolId:n,prevPools:d,masterSecret:o,challengeIds:g,claim:p}),$=E.findIndex(S=>S.id===e.id);if($===-1)throw new Error(`Target pool to replace '${e.id}' not found in keystone challenge pools.`);E[$]=e;let I=(l.n??0)+1,A;if(I%Et===0){let S={...t,data:{...l,frameDetails:s}};A=await this.getAggregateDetails({latestKeystone:S,metaspace:a,space:i})}let w={challengePools:E,proofs:[h],frameDetails:s,checkpointDetails:A,...l.delegates?{delegates:l.delegates}:{}};return await at({prevIbGib:t,newData:w,metaspace:a,space:i})}catch(l){throw console.error(`${c} ${m(l)}`),l}finally{B&&console.log(`${c} complete.`)}}async changePassword({keystoneIbGib:t,keystoneAddr:e,newMasterSecret:o,signingSecret:n,signingPoolId:s=Ve,poolIds:a,frameDetails:i,metaspace:c,space:l}){let d=`${this.lc}[${this.changePassword.name}]`;try{if(B&&console.log(`${d} starting... (I: 9e3ff83ebd74511f9dad784a1020d926)`),!t&&!e)throw new Error("Either keystoneIbGib or keystoneAddr required. (E: d1b8c8cb75f2c022284e69b8c30af826)");if(t&&e){let x=y({ibGib:t});if(x!==e)throw new Error(`(UNEXPECTED) both keystoneIbGib (addr: ${x}) and keystoneAddr (${e}) provided, but the addrs are unequal? Note that only one is required for this function, but if both are provided the addrs must match exactly. (E: c5574f7e353a48b0bba94a1862af4e26)`)}e??=y({ibGib:t});let b=await this.getLatestKeystone({addr:e,metaspace:c,space:l});if(!b.data)throw new Error("latestKeystone.data falsy (E: 22e498eb8308a33e68b812d8d3905826)");if(b.data.revocationInfo)throw new Error("Keystone has been revoked. Cannot change password. (E: 726298617e8508b3c83b5e985a03e826)");let u=b.data.challengePools,p=u.find(x=>x.id===s);if(!p)throw new Error(`Signing pool not found: ${s} (E: 3599f8f51c78d722252ddb2894fdbe25)`);let g=[];if(a&&a.length>0)for(let x of a){let N=u.find(k=>k.id===x);if(!N)throw new Error(`Target pool to rotate not found: ${x} (E: 4599f8f51c78d722252ddb2894fdbe25)`);g.push(N)}else if(g=u.filter(x=>!x.isForeign),g.length===0)throw new Error("No non-foreign pools found to rotate. (E: 5599f8f51c78d722252ddb2894fdbe25)");let h=[];for(let x of g){let N=await Ii({prevPool:x,newMasterSecret:o});h.push(N)}let E=y({ibGib:b}),$={verb:he,target:E,details:{type:Lt.change_password,info:{change:h.map(x=>x.id)}}},I=await wt({pool:p,targetAddr:E}),{proof:A,nextPools:w}=await $t({targetPoolId:s,prevPools:u,masterSecret:n,challengeIds:I,claim:$});for(let x of h){let N=w.findIndex(k=>k.id===x.id);if(N===-1)throw new Error(`Rotated pool ${x.id} not found in next pools list. (E: 6599f8f51c78d722252ddb2894fdbe25)`);w[N]=x}let _=(b.data.n??0)+1,S;if(_%Et===0){let x={...b,data:{...b.data,challengePools:w}};S=await this.getAggregateDetails({latestKeystone:x,metaspace:c,space:l})}let G={challengePools:w,proofs:[A],frameDetails:i,checkpointDetails:S,...b.data.delegates?{delegates:b.data.delegates}:void 0},O=await at({prevIbGib:b,newData:G,metaspace:c,space:l}),U=[];if((a??[]).length===0){let x=await Un({masterSecret:n}),N=await Un({masterSecret:o}),k=Object.keys(b.data.delegates??{});for(let ae of k){let{newKeystone:ie,newDelegates:q}=await this.changePassword({keystoneAddr:ae,metaspace:c,space:l,newMasterSecret:N,signingSecret:x,signingPoolId:s,poolIds:void 0,frameDetails:i});if(q&&q.length>0)throw new Error("(UNEXPECTED) Delegate keystone has its own delegate(s)? ATOW (07/20/2026) second order delegates are not supported. (E: de45a7b7d9b8f61f6e58158269acba26)");U.push(ie)}}return{newKeystone:O,newDelegates:U.length>0?U:void 0}}catch(b){throw console.error(`${d} ${m(b)}`),b}finally{B&&console.log(`${d} complete.`)}}async verifySigningSecret({keystoneIbGib:t,signingSecret:e,poolId:o}){let n=`${this.lc}[${this.verifySigningSecret.name}]`;try{if(!t.data)return!1;let s=t.data.challengePools.find(a=>a.id===o);return s?await kn({pool:s,signingSecret:e}):!1}catch(s){return console.warn(`${n} Exception during verification: ${m(s)}`),!1}}};var lo=!1,jn=class{static{f(this,"KeystoneConfigBuilderBase")}_id;_salt;_size;_replenish;_seq;_rand;_verbs=[];_targetBinding;withId(t){return this._id=t,this}withSalt(t){return this._salt=t,this}withSize(t){return this._size=t,this}withTargetBinding(t){return this._targetBinding=t,this}withFIFO(t){return this._seq=t,this._rand=0,this}withRandom(t){return this._seq=0,this._rand=t,this}withHybrid({seqCount:t,randCount:e}){return this._seq=t,this._rand=e,this}withReplenishStrategy(t){return this._replenish=t,this}buildBehavior(){if(this._size===void 0)throw new Error("size required (E: 68320865d9adb8477836485b20b08826)");if(this._replenish===void 0)throw new Error("replenish strategy required (E: 9f8798d1a568763a282e53c89185b826)");if(this._seq===void 0)throw new Error("sequential required (E: e0da08a24e9790d0a8c1a9322f8eb826)");if(this._rand===void 0)throw new Error("selectRandomly required (E: 7721d84d1a8b7d020d0ab33c3f811426)");if(this._targetBinding===void 0)throw new Error("targetBinding required (E: 9add64d7e8e8cba01d901727a8e9b826)");return{size:this._size,replenish:this._replenish,selectSequentially:this._seq,selectRandomly:this._rand,targetBindingCount:this._targetBinding}}forVerbs(t){return this._verbs=t,this}},Bn=class r extends jn{static{f(this,"KeystoneConfigBuilder_HashV1")}lc=`[${r}]`;_algo;_rounds;withHash({algo:t,rounds:e}){let o=`${this.lc}[${this.withHash.name}]`;try{return lo&&console.log(`${o} starting... (I: 15d1b3bd2e98bba33fc6c78228755826)`),this._algo=t,this._rounds=e,this}catch(n){throw console.error(`${o} ${m(n)}`),n}finally{lo&&console.log(`${o} complete.`)}}build(){let t=`${this.lc}[${this.build.name}]`;try{if(lo&&console.log(`${t} starting... (I: 5df568c63c4993bb98df0a319ee16826)`),!this._id)throw new Error("id required (E: b50d082adf38bcbf463552f80d2c3226)");if(!this._salt)throw new Error("salt required (E: b0f1926657b8d7d3a88fb9385ead5826)");if(!this._algo)throw new Error("algorithm required (E: cff228f9898fd6383ef752088dae6826)");if(this._rounds===void 0)throw new Error("rounds required (E: eb72580f3b014cda18cba3e399683c26)");return{id:this._id,type:Re.hash_reveal_v1,salt:this._salt,allowedVerbs:this._verbs,behavior:this.buildBehavior(),algo:this._algo,rounds:this._rounds}}catch(e){throw console.error(`${t} ${m(e)}`),e}finally{lo&&console.log(`${t} complete.`)}}},ir=class{static{f(this,"KeystoneConfig")}static hash(){return new Bn}};function Cw(r){if(r.type&&r.type!==Re.hash_reveal_v1)throw new Error(`invalid type (${r.type}). Only ${Re.hash_reveal_v1} currently implemented. (E: c38616cd7a459149f670418f88766526)`);let{salt:t,id:e,size:o,sequential:n,random:s,targetBinding:a,replenishStrategy:i,verbs:c,hashAlgorithm:l,hashRounds:d}=r;return ir.hash().withId(e).withSalt(t).withSize(o??Qa).withHybrid({seqCount:n??ei,randCount:s??ti}).withTargetBinding(a??ri).withReplenishStrategy(i??oi).withHash({algo:l??ni,rounds:d??si}).forVerbs(c??[]).build()}f(Cw,"createStandardPoolConfig");function pl(r){if(r.type&&r.type!==Re.hash_reveal_v1)throw new Error(`invalid type (${r.type}). Only ${Re.hash_reveal_v1} currently implemented. (E: 09c1f7772bd2a7910f5562b4934d3826)`);let{salt:t,id:e,size:o,sequential:n,random:s,targetBinding:a,replenishStrategy:i,verbs:c,hashAlgorithm:l,hashRounds:d}=r;return ir.hash().withId(e).withSalt(t).withSize(o??ai).withHybrid({seqCount:n??ii,randCount:s??ci}).withTargetBinding(a??li).withReplenishStrategy(i??di).withHash({algo:l??fi,rounds:d??bi}).forVerbs(c??[]).build()}f(pl,"createHighSecurityPoolConfig");function Pw(r){return pl({...r,id:r.id??Ve,verbs:r.verbs??[Pn.MANAGE]})}f(Pw,"createManagePoolConfig");function Rw({template:r,salt:t}){let e=r.behavior;return ir.hash().withId(r.id).withSalt(t).withSize(e.size).withHybrid({seqCount:e.selectSequentially,randCount:e.selectRandomly}).withTargetBinding(e.targetBindingCount).withReplenishStrategy(e.replenish).withHash({algo:r.algo,rounds:r.rounds}).forVerbs(r.allowedVerbs).build()}f(Rw,"createPoolConfigFromJson");var fo="anon_fn",Ti={fnHash:""};var Ai=!1;function Fn({data:r}){let t=`[${Fn.name}]`;try{if(Ai&&console.log(`${t} starting... (I: 37bb06e0390c5bcadf04501727d64923)`),!r?.fnHash)throw new Error("data.fnHash required (E: 2e560f2c59822bc5ba024d4a8e99d323)");return`witness ${fo} ${r.fnHash}`}catch(e){throw console.error(`${t} ${e.message}`),e}finally{Ai&&console.log(`${t} complete.`)}}f(Fn,"getAnonymousFnIb");var it=class{static{f(this,"AnonymousFnWitness_V1")}fn;ib=fo.concat();gib=L;data=v(Ti);rel8ns;constructor(t){if(this.fn=t,!t)throw new Error("fn required (E: b1e1478f466a2a347b75e7c336f8d323)")}async witness(t){return this.data.fnHash=await ce({s:this.fn.toString()}),this.ib=Fn({data:this.data}),this.gib=await X({ibGib:this}),this.fn(t)}};var bo=!1;function hl({err:r}){let t=`[${hl.name}]`;try{if(bo&&console.log(`${t} starting... (I: 96f8b767c50f24768ced7beebb291723)`),en(r)){let e=r;if(!r.data)throw new Error("err isIbGib but err.data is false. (E: 151a6bab647c638c454fd277ac468f23)");if(Ke({ibGib:r}))return r.data.raw;throw new Error("(UNEXPECTED) err isIbGib but not ErrorIbGib_V1? (E: 81c2283fad5db3485c6e9acedbda9723)")}else return m(r)}catch(e){throw console.error(`${t} ${e.message}`),e}finally{bo&&console.log(`${t} complete.`)}}f(hl,"extractObsErrMsg");function gl(r){let t=`[${gl.name}]`;try{bo&&console.log(`${t} starting... (I: 3d2c3658a0fda83ece1f2b095a365823)`);let e;if(typeof r=="function"?e={next:r}:e=r,!e.next)throw new Error("observer.next required (typeof observerOrFn !== 'function') (E: da944e93b32ab5918f11751bcd651823)");let o=f(async d=>(await e.next(d),Y),"fnNext"),n=f(async d=>(d.ib==="complete"?e.complete&&await e.complete():Ke({ibGib:d})?e.error&&await e.error(d):await e.next(d),Y),"fnWitness"),s=new it(o),a=new it(n),i={ib:"observer",witness:f(async d=>await a.witness(d),"witness"),next:f(async d=>{await s.witness(d)},"next")},c=e.error??(async d=>{let b;if(typeof d=="string")b=m(d);else if(d.ib)if(Ke({ibGib:d}))b=m(d.data.raw);else throw new Error(`${t} (UNEXPECTED) first off, observer.error is falsy. secondly, error came down pipeline and has an "ib" property but is not an ErrorIbGib_V1? (E: 0a2a46b9620b4a6a84c7ba1100da537b)`);else d instanceof Error?b=m(d):typeof d.message=="string"?b=m(d.message):b="[unknown thing came down pipe that ain't an error]";console.error(`Error occurred but observer.error is falsy. error: ${b} (E: 822c60c7c4d542efacd5c2dea7e88062)`)}),l=new it(async d=>(c(d),Y));if(i.error=async d=>{typeof d=="string"?d=await ut({rawMsg:d}):d instanceof Error&&(d=await ut({rawMsg:d.message}));try{await l.witness(d)}catch{e.error?console.error(`${t} there was another error when executing errorAnonFnWitness.witness (wrapper of caller's observer.error) trapping this. (E: 8fa3c4e633df4491a82951e3b677d9a9)`):console.error(`${t} there was another error when executing errorAnonFnWitness.witness (caller's observer.error was falsy). trapping this. (E: f5ff2db0d762487287139a4175eb7689)`)}},e.complete){let d=e.complete,b=new it(async u=>(await d(),Y));i.complete=async()=>{try{await b.witness(Y)}catch(u){console.error(`${t} there was an error when executing completeAnonFnWitness (wrapper for observer.complete fn) error: ${m(u)} (E: c9e61b08429e42c1b85d2215f735ba2f)`)}}}return i}catch(e){throw console.error(`${t} ${e.message}`),e}finally{bo&&console.log(`${t} complete.`)}}f(gl,"fnObs");export{f as a,z as b,we as c,v as d,xe as e,ce as f,F as g,H as h,le as i,m as j,po as k,ge as l,lr as m,Oi as n,Wn as o,Tt as p,L as q,Y as r,J as s,Oe as t,ts as u,We as v,y as w,C as x,K as y,Pi as z,Z as A,X as B,re as C,Me as D,Ie as E,oe as F,kt as G,Gt as H,At as I,M as J,Sd as K,xd as L,Od as M,pr as N,Ri as O,as as P,is as Q,Xd as R,Kd as S,Vd as T,Ui as U,Yd as V,gr as W,Go as X,Mi as Y,of as Z,mr as _,ze as $,wr as aa,Is as ba,$r as ca,Bi as da,Fi as ea,Ib as fa,_b as ga,Tb as ha,Ab as ia,Gb as ja,Sb as ka,Yi as la,Wi as ma,Ss as na,Uo as oa,Ji as pa,Zi as qa,xt as ra,Ht as sa,Ps as ta,ic as ua,Ms as va,pu as wa,Eu as xa,ne as ya,Xo as za,Ko as Aa,ee as Ba,cc as Ca,Dr as Da,vr as Ea,de as Fa,Vo as Ga,js as Ha,Ne as Ia,St as Ja,Ho as Ka,qs as La,Ae as Ma,Yt as Na,dc as Oa,fc as Pa,bc as Qa,uc as Ra,Ge as Sa,Hu as Ta,pc as Ua,hc as Va,Nr as Wa,Ce as Xa,gc as Ya,Ec as Za,mc as _a,wc as $a,Te as ab,sp as bb,ra as cb,Kt as db,Cr as eb,zt as fb,oa as gb,ue as hb,Pe as ib,en as jb,Xt as kb,tn as lb,et as mb,hp as nb,Ac as ob,gp as pb,Ep as qb,mp as rb,wp as sb,sa as tb,fp as ub,Rp as vb,Up as wb,Mp as xb,kp as yb,jp as zb,Bp as Ab,Ot as Bb,Sc as Cb,xc as Db,Oc as Eb,bt as Fb,Ea as Gb,Dc as Hb,wa as Ib,ma as Jb,Nc as Kb,Lc as Lb,Cc as Mb,Pc as Nb,Rc as Ob,$h as Pb,Uc as Qb,Mc as Rb,kc as Sb,dn as Tb,an as Ub,Ur as Vb,jc as Wb,Bc as Xb,aa as Yb,Fc as Zb,_a as _b,Ph as $b,qc as ac,Zt as bc,Hc as cc,Xc as dc,Kc as ec,pn as fc,Vc as gc,Yc as hc,xa as ic,Wc as jc,gn as kc,cg as lc,lg as mc,ut as nc,hl as oc,gl as pc,zc as qc,pt as rc,ht as sc,mn as tc,Nt as uc,xm as vc,Re as wc,me as xc,rr as yc,Nn as zc,Ln as Ac,ro as Bc,Za as Cc,il as Dc,cl as Ec,Rn as Fc,dl as Gc,Un as Hc,mt as Ic,hw as Jc,_i as Kc,Cw as Lc,Pw as Mc,Rw as Nc};
|
|
19
|
+
//# sourceMappingURL=chunk-AOGR25NW.mjs.map
|