this.me 3.0.30 → 3.0.33
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/README.md +44 -3
- package/dist/index.d.ts +1 -2
- package/dist/me.cjs +2 -2
- package/dist/me.es.js +636 -417
- package/dist/me.umd.js +2 -2
- package/dist/src/crypto.d.ts +6 -0
- package/dist/src/handleCall.d.ts +29 -0
- package/dist/src/me.d.ts +36 -96
- package/dist/src/operators.d.ts +77 -0
- package/dist/src/postulate.d.ts +46 -0
- package/dist/src/types.d.ts +245 -0
- package/package.json +26 -26
- package/dist/me.es.d.ts +0 -2
package/dist/me.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(V,j){typeof exports=="object"&&typeof module<"u"?module.exports=j():typeof define=="function"&&define.amd?define(j):(V=typeof globalThis<"u"?globalThis:V||self,V.Me=j())})(this,(function(){"use strict";function V(c){return{__ptr:c}}function j(c){return!!c&&typeof c=="object"&&typeof c.__ptr=="string"&&c.__ptr.length>0}function pe(c){return{__id:c}}function Qt(c){return!!c&&typeof c=="object"&&typeof c.__id=="string"&&c.__id.length>0}function ye(c){return!!c&&typeof c=="object"&&typeof c.path=="string"&&typeof c.hash=="string"&&typeof c.timestamp=="number"}function N(c){return c.length===0?{scope:[],leaf:null}:{scope:c.slice(0,-1),leaf:c[c.length-1]}}function le(c,r){if(r.length>c.length)return!1;for(let e=0;e<r.length;e++)if(c[e]!==r[e])return!1;return!0}function ce(c){const r=c.trim().toLowerCase();if(r.length<3||r.length>63)throw new Error(`Invalid username length: ${r.length}. Expected 3..63 characters.`);if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$/.test(r))throw new Error(`Invalid username. Use only [a-z0-9-], and start/end with [a-z0-9]. Got: ${c}`);if(r.includes("--"))throw new Error(`Invalid username. "--" is not allowed. Got: ${c}`);return r}var ve=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ge(c){return c&&c.__esModule&&Object.prototype.hasOwnProperty.call(c,"default")?c.default:c}var Xt={exports:{}};/**
|
|
2
2
|
* [js-sha3]{@link https://github.com/emn178/js-sha3}
|
|
3
3
|
*
|
|
4
4
|
* @version 0.9.3
|
|
5
5
|
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
6
6
|
* @copyright Chen, Yi-Cyuan 2015-2023
|
|
7
7
|
* @license MIT
|
|
8
|
-
*/var qt;function oe(){return qt||(qt=1,(function(E){(function(){var i="input is invalid type",o="finalize already called",l=typeof window=="object",c=l?window:{};c.JS_SHA3_NO_WINDOW&&(l=!1);var y=!l&&typeof self=="object",b=!c.JS_SHA3_NO_NODE_JS&&typeof process=="object"&&process.versions&&process.versions.node;b?c=D:y&&(c=self);for(var B=!c.JS_SHA3_NO_COMMON_JS&&!0&&E.exports,p=!c.JS_SHA3_NO_ARRAY_BUFFER&&typeof ArrayBuffer<"u",d="0123456789abcdef".split(""),P=[31,7936,2031616,520093696],k=[4,1024,262144,67108864],F=[1,256,65536,16777216],w=[6,1536,393216,100663296],v=[0,8,16,24],_=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],j=[224,256,384,512],C=[128,256],A=["hex","buffer","arrayBuffer","array","digest"],R={128:168,256:136},ae=c.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return Object.prototype.toString.call(t)==="[object Array]"}:Array.isArray,he=p&&(c.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW||!ArrayBuffer.isView)?function(t){return typeof t=="object"&&t.buffer&&t.buffer.constructor===ArrayBuffer}:ArrayBuffer.isView,Wt=function(t){var e=typeof t;if(e==="string")return[t,!0];if(e!=="object"||t===null)throw new Error(i);if(p&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!ae(t)&&!he(t))throw new Error(i);return[t,!1]},$t=function(t){return Wt(t)[0].length===0},Ut=function(t){for(var e=[],r=0;r<t.length;++r)e[r]=t[r];return e},Lt=function(t,e,r){return function(n){return new g(t,e,t).update(n)[r]()}},Xt=function(t,e,r){return function(n,a){return new g(t,e,a).update(n)[r]()}},Zt=function(t,e,r){return function(n,a,h,u){return T["cshake"+t].update(n,a,h,u)[r]()}},Qt=function(t,e,r){return function(n,a,h,u){return T["kmac"+t].update(n,a,h,u)[r]()}},J=function(t,e,r,n){for(var a=0;a<A.length;++a){var h=A[a];t[h]=e(r,n,h)}return t},te=function(t,e){var r=Lt(t,e,"hex");return r.create=function(){return new g(t,e,t)},r.update=function(n){return r.create().update(n)},J(r,Lt,t,e)},fe=function(t,e){var r=Xt(t,e,"hex");return r.create=function(n){return new g(t,e,n)},r.update=function(n,a){return r.create(a).update(n)},J(r,Xt,t,e)},le=function(t,e){var r=R[t],n=Zt(t,e,"hex");return n.create=function(a,h,u){return $t(h)&&$t(u)?T["shake"+t].create(a):new g(t,e,a).bytepad([h,u],r)},n.update=function(a,h,u,f){return n.create(h,u,f).update(a)},J(n,Zt,t,e)},ue=function(t,e){var r=R[t],n=Qt(t,e,"hex");return n.create=function(a,h,u){return new Yt(t,e,h).bytepad(["KMAC",u],r).bytepad([a],r)},n.update=function(a,h,u,f){return n.create(a,u,f).update(h)},J(n,Qt,t,e)},ee=[{name:"keccak",padding:F,bits:j,createMethod:te},{name:"sha3",padding:w,bits:j,createMethod:te},{name:"shake",padding:P,bits:C,createMethod:fe},{name:"cshake",padding:k,bits:C,createMethod:le},{name:"kmac",padding:k,bits:C,createMethod:ue}],T={},H=[],M=0;M<ee.length;++M)for(var N=ee[M],m=N.bits,I=0;I<m.length;++I){var Gt=N.name+"_"+m[I];if(H.push(Gt),T[Gt]=N.createMethod(m[I],N.padding),N.name!=="sha3"){var re=N.name+m[I];H.push(re),T[re]=T[Gt]}}function g(t,e,r){this.blocks=[],this.s=[],this.padding=e,this.outputBits=r,this.reset=!0,this.finalized=!1,this.block=0,this.start=0,this.blockCount=1600-(t<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=r>>5,this.extraBytes=(r&31)>>3;for(var n=0;n<50;++n)this.s[n]=0}g.prototype.update=function(t){if(this.finalized)throw new Error(o);var e=Wt(t);t=e[0];for(var r=e[1],n=this.blocks,a=this.byteCount,h=t.length,u=this.blockCount,f=0,S=this.s,s,x;f<h;){if(this.reset)for(this.reset=!1,n[0]=this.block,s=1;s<u+1;++s)n[s]=0;if(r)for(s=this.start;f<h&&s<a;++f)x=t.charCodeAt(f),x<128?n[s>>2]|=x<<v[s++&3]:x<2048?(n[s>>2]|=(192|x>>6)<<v[s++&3],n[s>>2]|=(128|x&63)<<v[s++&3]):x<55296||x>=57344?(n[s>>2]|=(224|x>>12)<<v[s++&3],n[s>>2]|=(128|x>>6&63)<<v[s++&3],n[s>>2]|=(128|x&63)<<v[s++&3]):(x=65536+((x&1023)<<10|t.charCodeAt(++f)&1023),n[s>>2]|=(240|x>>18)<<v[s++&3],n[s>>2]|=(128|x>>12&63)<<v[s++&3],n[s>>2]|=(128|x>>6&63)<<v[s++&3],n[s>>2]|=(128|x&63)<<v[s++&3]);else for(s=this.start;f<h&&s<a;++f)n[s>>2]|=t[f]<<v[s++&3];if(this.lastByteIndex=s,s>=a){for(this.start=s-a,this.block=n[u],s=0;s<u;++s)S[s]^=n[s];V(S),this.reset=!0}else this.start=s}return this},g.prototype.encode=function(t,e){var r=t&255,n=1,a=[r];for(t=t>>8,r=t&255;r>0;)a.unshift(r),t=t>>8,r=t&255,++n;return e?a.push(n):a.unshift(n),this.update(a),a.length},g.prototype.encodeString=function(t){var e=Wt(t);t=e[0];var r=e[1],n=0,a=t.length;if(r)for(var h=0;h<t.length;++h){var u=t.charCodeAt(h);u<128?n+=1:u<2048?n+=2:u<55296||u>=57344?n+=3:(u=65536+((u&1023)<<10|t.charCodeAt(++h)&1023),n+=4)}else n=a;return n+=this.encode(n*8),this.update(t),n},g.prototype.bytepad=function(t,e){for(var r=this.encode(e),n=0;n<t.length;++n)r+=this.encodeString(t[n]);var a=(e-r%e)%e,h=[];return h.length=a,this.update(h),this},g.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,e=this.lastByteIndex,r=this.blockCount,n=this.s;if(t[e>>2]|=this.padding[e&3],this.lastByteIndex===this.byteCount)for(t[0]=t[r],e=1;e<r+1;++e)t[e]=0;for(t[r-1]|=2147483648,e=0;e<r;++e)n[e]^=t[e];V(n)}},g.prototype.toString=g.prototype.hex=function(){this.finalize();for(var t=this.blockCount,e=this.s,r=this.outputBlocks,n=this.extraBytes,a=0,h=0,u="",f;h<r;){for(a=0;a<t&&h<r;++a,++h)f=e[a],u+=d[f>>4&15]+d[f&15]+d[f>>12&15]+d[f>>8&15]+d[f>>20&15]+d[f>>16&15]+d[f>>28&15]+d[f>>24&15];h%t===0&&(e=Ut(e),V(e),a=0)}return n&&(f=e[a],u+=d[f>>4&15]+d[f&15],n>1&&(u+=d[f>>12&15]+d[f>>8&15]),n>2&&(u+=d[f>>20&15]+d[f>>16&15])),u},g.prototype.arrayBuffer=function(){this.finalize();var t=this.blockCount,e=this.s,r=this.outputBlocks,n=this.extraBytes,a=0,h=0,u=this.outputBits>>3,f;n?f=new ArrayBuffer(r+1<<2):f=new ArrayBuffer(u);for(var S=new Uint32Array(f);h<r;){for(a=0;a<t&&h<r;++a,++h)S[h]=e[a];h%t===0&&(e=Ut(e),V(e))}return n&&(S[h]=e[a],f=f.slice(0,u)),f},g.prototype.buffer=g.prototype.arrayBuffer,g.prototype.digest=g.prototype.array=function(){this.finalize();for(var t=this.blockCount,e=this.s,r=this.outputBlocks,n=this.extraBytes,a=0,h=0,u=[],f,S;h<r;){for(a=0;a<t&&h<r;++a,++h)f=h<<2,S=e[a],u[f]=S&255,u[f+1]=S>>8&255,u[f+2]=S>>16&255,u[f+3]=S>>24&255;h%t===0&&(e=Ut(e),V(e))}return n&&(f=h<<2,S=e[a],u[f]=S&255,n>1&&(u[f+1]=S>>8&255),n>2&&(u[f+2]=S>>16&255)),u};function Yt(t,e,r){g.call(this,t,e,r)}Yt.prototype=new g,Yt.prototype.finalize=function(){return this.encode(this.outputBits,!0),g.prototype.finalize.call(this)};var V=function(t){var e,r,n,a,h,u,f,S,s,x,z,W,U,G,Y,q,$,L,X,Z,Q,tt,et,rt,nt,ot,it,ct,at,ht,ft,lt,ut,st,yt,dt,bt,pt,vt,xt,gt,St,Pt,Bt,kt,At,Ft,wt,_t,jt,Ct,Ot,Et,Tt,Mt,Rt,Kt,Nt,Dt,Ht,It,Vt,Jt;for(n=0;n<48;n+=2)a=t[0]^t[10]^t[20]^t[30]^t[40],h=t[1]^t[11]^t[21]^t[31]^t[41],u=t[2]^t[12]^t[22]^t[32]^t[42],f=t[3]^t[13]^t[23]^t[33]^t[43],S=t[4]^t[14]^t[24]^t[34]^t[44],s=t[5]^t[15]^t[25]^t[35]^t[45],x=t[6]^t[16]^t[26]^t[36]^t[46],z=t[7]^t[17]^t[27]^t[37]^t[47],W=t[8]^t[18]^t[28]^t[38]^t[48],U=t[9]^t[19]^t[29]^t[39]^t[49],e=W^(u<<1|f>>>31),r=U^(f<<1|u>>>31),t[0]^=e,t[1]^=r,t[10]^=e,t[11]^=r,t[20]^=e,t[21]^=r,t[30]^=e,t[31]^=r,t[40]^=e,t[41]^=r,e=a^(S<<1|s>>>31),r=h^(s<<1|S>>>31),t[2]^=e,t[3]^=r,t[12]^=e,t[13]^=r,t[22]^=e,t[23]^=r,t[32]^=e,t[33]^=r,t[42]^=e,t[43]^=r,e=u^(x<<1|z>>>31),r=f^(z<<1|x>>>31),t[4]^=e,t[5]^=r,t[14]^=e,t[15]^=r,t[24]^=e,t[25]^=r,t[34]^=e,t[35]^=r,t[44]^=e,t[45]^=r,e=S^(W<<1|U>>>31),r=s^(U<<1|W>>>31),t[6]^=e,t[7]^=r,t[16]^=e,t[17]^=r,t[26]^=e,t[27]^=r,t[36]^=e,t[37]^=r,t[46]^=e,t[47]^=r,e=x^(a<<1|h>>>31),r=z^(h<<1|a>>>31),t[8]^=e,t[9]^=r,t[18]^=e,t[19]^=r,t[28]^=e,t[29]^=r,t[38]^=e,t[39]^=r,t[48]^=e,t[49]^=r,G=t[0],Y=t[1],At=t[11]<<4|t[10]>>>28,Ft=t[10]<<4|t[11]>>>28,ct=t[20]<<3|t[21]>>>29,at=t[21]<<3|t[20]>>>29,Ht=t[31]<<9|t[30]>>>23,It=t[30]<<9|t[31]>>>23,St=t[40]<<18|t[41]>>>14,Pt=t[41]<<18|t[40]>>>14,st=t[2]<<1|t[3]>>>31,yt=t[3]<<1|t[2]>>>31,q=t[13]<<12|t[12]>>>20,$=t[12]<<12|t[13]>>>20,wt=t[22]<<10|t[23]>>>22,_t=t[23]<<10|t[22]>>>22,ht=t[33]<<13|t[32]>>>19,ft=t[32]<<13|t[33]>>>19,Vt=t[42]<<2|t[43]>>>30,Jt=t[43]<<2|t[42]>>>30,Tt=t[5]<<30|t[4]>>>2,Mt=t[4]<<30|t[5]>>>2,dt=t[14]<<6|t[15]>>>26,bt=t[15]<<6|t[14]>>>26,L=t[25]<<11|t[24]>>>21,X=t[24]<<11|t[25]>>>21,jt=t[34]<<15|t[35]>>>17,Ct=t[35]<<15|t[34]>>>17,lt=t[45]<<29|t[44]>>>3,ut=t[44]<<29|t[45]>>>3,rt=t[6]<<28|t[7]>>>4,nt=t[7]<<28|t[6]>>>4,Rt=t[17]<<23|t[16]>>>9,Kt=t[16]<<23|t[17]>>>9,pt=t[26]<<25|t[27]>>>7,vt=t[27]<<25|t[26]>>>7,Z=t[36]<<21|t[37]>>>11,Q=t[37]<<21|t[36]>>>11,Ot=t[47]<<24|t[46]>>>8,Et=t[46]<<24|t[47]>>>8,Bt=t[8]<<27|t[9]>>>5,kt=t[9]<<27|t[8]>>>5,ot=t[18]<<20|t[19]>>>12,it=t[19]<<20|t[18]>>>12,Nt=t[29]<<7|t[28]>>>25,Dt=t[28]<<7|t[29]>>>25,xt=t[38]<<8|t[39]>>>24,gt=t[39]<<8|t[38]>>>24,tt=t[48]<<14|t[49]>>>18,et=t[49]<<14|t[48]>>>18,t[0]=G^~q&L,t[1]=Y^~$&X,t[10]=rt^~ot&ct,t[11]=nt^~it&at,t[20]=st^~dt&pt,t[21]=yt^~bt&vt,t[30]=Bt^~At&wt,t[31]=kt^~Ft&_t,t[40]=Tt^~Rt&Nt,t[41]=Mt^~Kt&Dt,t[2]=q^~L&Z,t[3]=$^~X&Q,t[12]=ot^~ct&ht,t[13]=it^~at&ft,t[22]=dt^~pt&xt,t[23]=bt^~vt>,t[32]=At^~wt&jt,t[33]=Ft^~_t&Ct,t[42]=Rt^~Nt&Ht,t[43]=Kt^~Dt&It,t[4]=L^~Z&tt,t[5]=X^~Q&et,t[14]=ct^~ht<,t[15]=at^~ft&ut,t[24]=pt^~xt&St,t[25]=vt^~gt&Pt,t[34]=wt^~jt&Ot,t[35]=_t^~Ct&Et,t[44]=Nt^~Ht&Vt,t[45]=Dt^~It&Jt,t[6]=Z^~tt&G,t[7]=Q^~et&Y,t[16]=ht^~lt&rt,t[17]=ft^~ut&nt,t[26]=xt^~St&st,t[27]=gt^~Pt&yt,t[36]=jt^~Ot&Bt,t[37]=Ct^~Et&kt,t[46]=Ht^~Vt&Tt,t[47]=It^~Jt&Mt,t[8]=tt^~G&q,t[9]=et^~Y&$,t[18]=lt^~rt&ot,t[19]=ut^~nt&it,t[28]=St^~st&dt,t[29]=Pt^~yt&bt,t[38]=Ot^~Bt&At,t[39]=Et^~kt&Ft,t[48]=Vt^~Tt&Rt,t[49]=Jt^~Mt&Kt,t[0]^=_[n],t[1]^=_[n+1]};if(B)E.exports=T;else for(M=0;M<H.length;++M)c[H[M]]=T[H[M]]})()})(mt)),mt.exports}var ie=oe();const ce=ne(ie),{keccak256:O}=ce;class zt{constructor(i,o,l){this.payload={},this.declarations=[],this.secrets={},this.branchVersions={},this.username=i,this.secret=o,this.blockchain=l,this.identityRoot="0x"+O(o),this.publicKey="0x"+O("public:"+o),this.identityHash="0x"+O(this.publicKey+this.username),this.secrets[""]=o;const c=this.createProxy([]);return Object.setPrototypeOf(c,zt.prototype),Object.assign(c,this),c}createProxy(i){const o=this,l=(...c)=>o.handleCall(i,c);return new Proxy(l,{get(c,y){if(typeof y=="symbol")return c[y];if(y==="secret")return o.createProxy([...i,String(y)]);if(y in o)return o[y];const b=[...i,String(y)];return o.createProxy(b)},apply(c,y,b){return o.handleCall(i,b)}})}handleCall(i,o){if(i.length===0){if(o.length===1&&typeof o[0]=="string"){const p=o[0].split(".").filter(Boolean);return this.exportBranch(p.join("."))}return this.createProxy([])}const l=i[i.length-1];if(l==="secret"){const p=i.slice(0,-1),d=p.join("."),P=String(o[0]??"");if(!P)return this.createProxy(p);this.secrets[d]=P;const k="0x"+O(this.secret+d+"::secret-set");return this.declarations.push({key:d+".secret",value:"<secret-set>",signature:k,timestamp:Date.now()}),this.createProxy(p)}if(l==="ptr")return{__ptr:i.slice(0,-1).join(".")};const c=i.join(".");let y;o.length===0?y=void 0:o.length===1?y=o[0]:y=o,this.ensurePath(i,y);const b=this.resolveSecret(i),B="0x"+O(b+c+JSON.stringify(y));return this.declarations.push({key:c,value:y,signature:B,timestamp:Date.now()}),this.createProxy(i)}resolveSecretWithPath(i){for(let o=i.length;o>=0;o--){const l=i.slice(0,o).join(".");if(this.secrets[l])return{secret:this.secrets[l],secretPath:i.slice(0,o)}}return{secret:this.secret,secretPath:[]}}resolveSecret(i){return this.resolveSecretWithPath(i).secret}ensurePath(i,o){const{secret:l,secretPath:c}=this.resolveSecretWithPath(i),y=c.join("."),b=O(l);if(c.length>0){let k={};const F=this.branchVersions[y]?.[b],w=this.getSubPayload(c);if(F){const A=this.decryptForPath(c,F);A&&typeof A=="object"&&(k=A)}else if(typeof w=="string"){const A=this.decryptForPath(c,w);A&&typeof A=="object"&&(k=A)}else w&&typeof w=="object"&&(k=w);const v=i.slice(c.length);let _=k;for(let A=0;A<v.length-1;A++){const R=v[A];(!_[R]||typeof _[R]!="object")&&(_[R]={}),_=_[R]}const j=v[v.length-1];_[j]=o;const C=this.encryptForPath(c,k);this.branchVersions[y]||(this.branchVersions[y]={}),this.branchVersions[y][b]=C,this.writeBranchBlob(c,C);return}const p=this.encryptForPath(i,o);let d=this.payload;for(let k=0;k<i.length-1;k++){const F=i[k];(!d[F]||typeof d[F]!="object")&&(d[F]={}),d=d[F]}const P=i[i.length-1];d[P]=p}setSubPayload(i,o){if(i.length===0){this.payload=o;return}let l=this.payload;for(let y=0;y<i.length-1;y++){const b=i[y];(!l[b]||typeof l[b]!="object")&&(l[b]={}),l=l[b]}const c=i[i.length-1];l[c]=o}findNearestBranchAncestor(i){for(let o=i.length-1;o>=1;o--){const l=i.slice(0,o),c=l.join(".");if(this.branchVersions[c])return{path:l,secret:this.resolveSecret(l)}}return null}writeBranchBlob(i,o){let l=i,c=o;for(;;){const y=this.findNearestBranchAncestor(l);if(!y){this.setSubPayload(l,c);return}const{path:b,secret:B}=y,p=b.join("."),d=O(B),P=this.getSubPayload(b),k=this.branchVersions[p]?.[d]??(typeof P=="string"?P:void 0);let F={};if(k){const j=this.decryptForPath(b,k);j&&typeof j=="object"&&(F=j)}const w=l.slice(b.length);let v=F;for(let j=0;j<w.length-1;j++){const C=w[j];(!v[C]||typeof v[C]!="object")&&(v[C]={}),v=v[C]}v[w[w.length-1]]=c;const _=this.encryptForPath(b,F);this.branchVersions[p]||(this.branchVersions[p]={}),this.branchVersions[p][d]=_,l=b,c=_}}getSubPayload(i){let o=this.payload;for(const l of i){if(!o||typeof o!="object")return;o=o[l]}return o}decryptTree(i,o){if(o==null)return o;if(typeof o=="string"){if(!this.isHexString(o))return o;const c=this.decryptForPath(i,o);return c===null?o:c}if(typeof o!="object")return o;const l=Array.isArray(o)?[]:{};for(const c of Object.keys(o)){const y=[...i,c];l[c]=this.decryptTree(y,o[c])}return l}encryptForPath(i,o){const l=this.resolveSecret(i),c=JSON.stringify(o),y=new TextEncoder().encode(c),b=O(l+":"+i.join(".")),B=this.asciiToBytes(b),p=new Uint8Array(y.length);for(let P=0;P<y.length;P++)p[P]=y[P]^B[P%B.length];let d="";for(let P=0;P<p.length;P++)d+=p[P].toString(16).padStart(2,"0");return d}decryptForPath(i,o){const l=this.resolveSecret(i);try{const c=this.hexToBytes(o),y=O(l+":"+i.join(".")),b=this.asciiToBytes(y),B=new Uint8Array(c.length);for(let d=0;d<c.length;d++)B[d]=c[d]^b[d%b.length];const p=new TextDecoder().decode(B);return JSON.parse(p)}catch{return null}}asciiToBytes(i){return new TextEncoder().encode(i)}hexToBytes(i){const o=i.startsWith("0x")?i.slice(2):i,l=new Uint8Array(o.length/2);for(let c=0;c<l.length;c++)l[c]=parseInt(o.substr(c*2,2),16);return l}isHexString(i){const o=i.startsWith("0x")?i.slice(2):i;return o.length>0&&o.length%2===0&&/^[0-9a-fA-F]+$/.test(o)}export(){return{identityRoot:this.identityRoot,publicKey:this.publicKey,identityHash:this.identityHash,declarations:this.declarations,payload:this.payload}}exportBranch(i){const o=i?i.split(".").filter(Boolean):[],l=o.join("."),c=this.resolveSecret(o),y=O(c),b=this.branchVersions[l]?.[y];if(b){const p=this.decryptForPath(o,b);return this.decryptTree(o,p)}const B=this.getSubPayload(o);if(B!==void 0){if(typeof B=="string"){const p=this.decryptForPath(o,B);return this.decryptTree(o,p)}return this.decryptTree(o,B)}}}K.ME=zt,Object.defineProperty(K,Symbol.toStringTag,{value:"Module"})}));
|
|
8
|
+
*/var ae;function be(){return ae||(ae=1,(function(c){(function(){var r="input is invalid type",e="finalize already called",a=typeof window=="object",i=a?window:{};i.JS_SHA3_NO_WINDOW&&(a=!1);var f=!a&&typeof self=="object",p=!i.JS_SHA3_NO_NODE_JS&&typeof process=="object"&&process.versions&&process.versions.node;p?i=ve:f&&(i=self);for(var b=!i.JS_SHA3_NO_COMMON_JS&&!0&&c.exports,y=!i.JS_SHA3_NO_ARRAY_BUFFER&&typeof ArrayBuffer<"u",g="0123456789abcdef".split(""),S=[31,7936,2031616,520093696],O=[4,1024,262144,67108864],J=[1,256,65536,16777216],R=[6,1536,393216,100663296],P=[0,8,16,24],W=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],E=[224,256,384,512],H=[128,256],L=["hex","buffer","arrayBuffer","array","digest"],Y={128:168,256:136},ne=i.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return Object.prototype.toString.call(t)==="[object Array]"}:Array.isArray,Z=y&&(i.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW||!ArrayBuffer.isView)?function(t){return typeof t=="object"&&t.buffer&&t.buffer.constructor===ArrayBuffer}:ArrayBuffer.isView,k=function(t){var n=typeof t;if(n==="string")return[t,!0];if(n!=="object"||t===null)throw new Error(r);if(y&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!ne(t)&&!Z(t))throw new Error(r);return[t,!1]},x=function(t){return k(t)[0].length===0},C=function(t){for(var n=[],o=0;o<t.length;++o)n[o]=t[o];return n},w=function(t,n,o){return function(l){return new B(t,n,t).update(l)[o]()}},_=function(t,n,o){return function(l,u){return new B(t,n,u).update(l)[o]()}},F=function(t,n,o){return function(l,u,h,d){return T["cshake"+t].update(l,u,h,d)[o]()}},I=function(t,n,o){return function(l,u,h,d){return T["kmac"+t].update(l,u,h,d)[o]()}},K=function(t,n,o,l){for(var u=0;u<L.length;++u){var h=L[u];t[h]=n(o,l,h)}return t},M=function(t,n){var o=w(t,n,"hex");return o.create=function(){return new B(t,n,t)},o.update=function(l){return o.create().update(l)},K(o,w,t,n)},Ae=function(t,n){var o=_(t,n,"hex");return o.create=function(l){return new B(t,n,l)},o.update=function(l,u){return o.create(u).update(l)},K(o,_,t,n)},Pe=function(t,n){var o=Y[t],l=F(t,n,"hex");return l.create=function(u,h,d){return x(h)&&x(d)?T["shake"+t].create(u):new B(t,n,u).bytepad([h,d],o)},l.update=function(u,h,d,s){return l.create(h,d,s).update(u)},K(l,F,t,n)},we=function(t,n){var o=Y[t],l=I(t,n,"hex");return l.create=function(u,h,d){return new oe(t,n,h).bytepad(["KMAC",d],o).bytepad([u],o)},l.update=function(u,h,d,s){return l.create(u,d,s).update(h)},K(l,I,t,n)},se=[{name:"keccak",padding:J,bits:E,createMethod:M},{name:"sha3",padding:R,bits:E,createMethod:M},{name:"shake",padding:S,bits:H,createMethod:Ae},{name:"cshake",padding:O,bits:H,createMethod:Pe},{name:"kmac",padding:O,bits:H,createMethod:we}],T={},G=[],z=0;z<se.length;++z)for(var U=se[z],Q=U.bits,$=0;$<Q.length;++$){var ie=U.name+"_"+Q[$];if(G.push(ie),T[ie]=U.createMethod(Q[$],U.padding),U.name!=="sha3"){var de=U.name+Q[$];G.push(de),T[de]=T[ie]}}function B(t,n,o){this.blocks=[],this.s=[],this.padding=n,this.outputBits=o,this.reset=!0,this.finalized=!1,this.block=0,this.start=0,this.blockCount=1600-(t<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=o>>5,this.extraBytes=(o&31)>>3;for(var l=0;l<50;++l)this.s[l]=0}B.prototype.update=function(t){if(this.finalized)throw new Error(e);var n=k(t);t=n[0];for(var o=n[1],l=this.blocks,u=this.byteCount,h=t.length,d=this.blockCount,s=0,A=this.s,v,m;s<h;){if(this.reset)for(this.reset=!1,l[0]=this.block,v=1;v<d+1;++v)l[v]=0;if(o)for(v=this.start;s<h&&v<u;++s)m=t.charCodeAt(s),m<128?l[v>>2]|=m<<P[v++&3]:m<2048?(l[v>>2]|=(192|m>>6)<<P[v++&3],l[v>>2]|=(128|m&63)<<P[v++&3]):m<55296||m>=57344?(l[v>>2]|=(224|m>>12)<<P[v++&3],l[v>>2]|=(128|m>>6&63)<<P[v++&3],l[v>>2]|=(128|m&63)<<P[v++&3]):(m=65536+((m&1023)<<10|t.charCodeAt(++s)&1023),l[v>>2]|=(240|m>>18)<<P[v++&3],l[v>>2]|=(128|m>>12&63)<<P[v++&3],l[v>>2]|=(128|m>>6&63)<<P[v++&3],l[v>>2]|=(128|m&63)<<P[v++&3]);else for(v=this.start;s<h&&v<u;++s)l[v>>2]|=t[s]<<P[v++&3];if(this.lastByteIndex=v,v>=u){for(this.start=v-u,this.block=l[d],v=0;v<d;++v)A[v]^=l[v];q(A),this.reset=!0}else this.start=v}return this},B.prototype.encode=function(t,n){var o=t&255,l=1,u=[o];for(t=t>>8,o=t&255;o>0;)u.unshift(o),t=t>>8,o=t&255,++l;return n?u.push(l):u.unshift(l),this.update(u),u.length},B.prototype.encodeString=function(t){var n=k(t);t=n[0];var o=n[1],l=0,u=t.length;if(o)for(var h=0;h<t.length;++h){var d=t.charCodeAt(h);d<128?l+=1:d<2048?l+=2:d<55296||d>=57344?l+=3:(d=65536+((d&1023)<<10|t.charCodeAt(++h)&1023),l+=4)}else l=u;return l+=this.encode(l*8),this.update(t),l},B.prototype.bytepad=function(t,n){for(var o=this.encode(n),l=0;l<t.length;++l)o+=this.encodeString(t[l]);var u=(n-o%n)%n,h=[];return h.length=u,this.update(h),this},B.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,n=this.lastByteIndex,o=this.blockCount,l=this.s;if(t[n>>2]|=this.padding[n&3],this.lastByteIndex===this.byteCount)for(t[0]=t[o],n=1;n<o+1;++n)t[n]=0;for(t[o-1]|=2147483648,n=0;n<o;++n)l[n]^=t[n];q(l)}},B.prototype.toString=B.prototype.hex=function(){this.finalize();for(var t=this.blockCount,n=this.s,o=this.outputBlocks,l=this.extraBytes,u=0,h=0,d="",s;h<o;){for(u=0;u<t&&h<o;++u,++h)s=n[u],d+=g[s>>4&15]+g[s&15]+g[s>>12&15]+g[s>>8&15]+g[s>>20&15]+g[s>>16&15]+g[s>>28&15]+g[s>>24&15];h%t===0&&(n=C(n),q(n),u=0)}return l&&(s=n[u],d+=g[s>>4&15]+g[s&15],l>1&&(d+=g[s>>12&15]+g[s>>8&15]),l>2&&(d+=g[s>>20&15]+g[s>>16&15])),d},B.prototype.arrayBuffer=function(){this.finalize();var t=this.blockCount,n=this.s,o=this.outputBlocks,l=this.extraBytes,u=0,h=0,d=this.outputBits>>3,s;l?s=new ArrayBuffer(o+1<<2):s=new ArrayBuffer(d);for(var A=new Uint32Array(s);h<o;){for(u=0;u<t&&h<o;++u,++h)A[h]=n[u];h%t===0&&(n=C(n),q(n))}return l&&(A[h]=n[u],s=s.slice(0,d)),s},B.prototype.buffer=B.prototype.arrayBuffer,B.prototype.digest=B.prototype.array=function(){this.finalize();for(var t=this.blockCount,n=this.s,o=this.outputBlocks,l=this.extraBytes,u=0,h=0,d=[],s,A;h<o;){for(u=0;u<t&&h<o;++u,++h)s=h<<2,A=n[u],d[s]=A&255,d[s+1]=A>>8&255,d[s+2]=A>>16&255,d[s+3]=A>>24&255;h%t===0&&(n=C(n),q(n))}return l&&(s=h<<2,A=n[u],d[s]=A&255,l>1&&(d[s+1]=A>>8&255),l>2&&(d[s+2]=A>>16&255)),d};function oe(t,n,o){B.call(this,t,n,o)}oe.prototype=new B,oe.prototype.finalize=function(){return this.encode(this.outputBits,!0),B.prototype.finalize.call(this)};var q=function(t){var n,o,l,u,h,d,s,A,v,m,X,tt,et,rt,nt,it,ot,lt,ct,at,ft,ut,ht,st,dt,pt,yt,vt,gt,bt,St,kt,mt,_t,xt,Bt,At,Pt,wt,Ct,Et,Ot,It,Ft,Nt,jt,Kt,Mt,Tt,zt,Dt,Rt,Wt,Jt,Ht,Ut,Vt,Gt,$t,qt,Lt,Yt,Zt;for(l=0;l<48;l+=2)u=t[0]^t[10]^t[20]^t[30]^t[40],h=t[1]^t[11]^t[21]^t[31]^t[41],d=t[2]^t[12]^t[22]^t[32]^t[42],s=t[3]^t[13]^t[23]^t[33]^t[43],A=t[4]^t[14]^t[24]^t[34]^t[44],v=t[5]^t[15]^t[25]^t[35]^t[45],m=t[6]^t[16]^t[26]^t[36]^t[46],X=t[7]^t[17]^t[27]^t[37]^t[47],tt=t[8]^t[18]^t[28]^t[38]^t[48],et=t[9]^t[19]^t[29]^t[39]^t[49],n=tt^(d<<1|s>>>31),o=et^(s<<1|d>>>31),t[0]^=n,t[1]^=o,t[10]^=n,t[11]^=o,t[20]^=n,t[21]^=o,t[30]^=n,t[31]^=o,t[40]^=n,t[41]^=o,n=u^(A<<1|v>>>31),o=h^(v<<1|A>>>31),t[2]^=n,t[3]^=o,t[12]^=n,t[13]^=o,t[22]^=n,t[23]^=o,t[32]^=n,t[33]^=o,t[42]^=n,t[43]^=o,n=d^(m<<1|X>>>31),o=s^(X<<1|m>>>31),t[4]^=n,t[5]^=o,t[14]^=n,t[15]^=o,t[24]^=n,t[25]^=o,t[34]^=n,t[35]^=o,t[44]^=n,t[45]^=o,n=A^(tt<<1|et>>>31),o=v^(et<<1|tt>>>31),t[6]^=n,t[7]^=o,t[16]^=n,t[17]^=o,t[26]^=n,t[27]^=o,t[36]^=n,t[37]^=o,t[46]^=n,t[47]^=o,n=m^(u<<1|h>>>31),o=X^(h<<1|u>>>31),t[8]^=n,t[9]^=o,t[18]^=n,t[19]^=o,t[28]^=n,t[29]^=o,t[38]^=n,t[39]^=o,t[48]^=n,t[49]^=o,rt=t[0],nt=t[1],jt=t[11]<<4|t[10]>>>28,Kt=t[10]<<4|t[11]>>>28,vt=t[20]<<3|t[21]>>>29,gt=t[21]<<3|t[20]>>>29,qt=t[31]<<9|t[30]>>>23,Lt=t[30]<<9|t[31]>>>23,Ot=t[40]<<18|t[41]>>>14,It=t[41]<<18|t[40]>>>14,_t=t[2]<<1|t[3]>>>31,xt=t[3]<<1|t[2]>>>31,it=t[13]<<12|t[12]>>>20,ot=t[12]<<12|t[13]>>>20,Mt=t[22]<<10|t[23]>>>22,Tt=t[23]<<10|t[22]>>>22,bt=t[33]<<13|t[32]>>>19,St=t[32]<<13|t[33]>>>19,Yt=t[42]<<2|t[43]>>>30,Zt=t[43]<<2|t[42]>>>30,Jt=t[5]<<30|t[4]>>>2,Ht=t[4]<<30|t[5]>>>2,Bt=t[14]<<6|t[15]>>>26,At=t[15]<<6|t[14]>>>26,lt=t[25]<<11|t[24]>>>21,ct=t[24]<<11|t[25]>>>21,zt=t[34]<<15|t[35]>>>17,Dt=t[35]<<15|t[34]>>>17,kt=t[45]<<29|t[44]>>>3,mt=t[44]<<29|t[45]>>>3,st=t[6]<<28|t[7]>>>4,dt=t[7]<<28|t[6]>>>4,Ut=t[17]<<23|t[16]>>>9,Vt=t[16]<<23|t[17]>>>9,Pt=t[26]<<25|t[27]>>>7,wt=t[27]<<25|t[26]>>>7,at=t[36]<<21|t[37]>>>11,ft=t[37]<<21|t[36]>>>11,Rt=t[47]<<24|t[46]>>>8,Wt=t[46]<<24|t[47]>>>8,Ft=t[8]<<27|t[9]>>>5,Nt=t[9]<<27|t[8]>>>5,pt=t[18]<<20|t[19]>>>12,yt=t[19]<<20|t[18]>>>12,Gt=t[29]<<7|t[28]>>>25,$t=t[28]<<7|t[29]>>>25,Ct=t[38]<<8|t[39]>>>24,Et=t[39]<<8|t[38]>>>24,ut=t[48]<<14|t[49]>>>18,ht=t[49]<<14|t[48]>>>18,t[0]=rt^~it<,t[1]=nt^~ot&ct,t[10]=st^~pt&vt,t[11]=dt^~yt>,t[20]=_t^~Bt&Pt,t[21]=xt^~At&wt,t[30]=Ft^~jt&Mt,t[31]=Nt^~Kt&Tt,t[40]=Jt^~Ut&Gt,t[41]=Ht^~Vt&$t,t[2]=it^~lt&at,t[3]=ot^~ct&ft,t[12]=pt^~vt&bt,t[13]=yt^~gt&St,t[22]=Bt^~Pt&Ct,t[23]=At^~wt&Et,t[32]=jt^~Mt&zt,t[33]=Kt^~Tt&Dt,t[42]=Ut^~Gt&qt,t[43]=Vt^~$t&Lt,t[4]=lt^~at&ut,t[5]=ct^~ft&ht,t[14]=vt^~bt&kt,t[15]=gt^~St&mt,t[24]=Pt^~Ct&Ot,t[25]=wt^~Et&It,t[34]=Mt^~zt&Rt,t[35]=Tt^~Dt&Wt,t[44]=Gt^~qt&Yt,t[45]=$t^~Lt&Zt,t[6]=at^~ut&rt,t[7]=ft^~ht&nt,t[16]=bt^~kt&st,t[17]=St^~mt&dt,t[26]=Ct^~Ot&_t,t[27]=Et^~It&xt,t[36]=zt^~Rt&Ft,t[37]=Dt^~Wt&Nt,t[46]=qt^~Yt&Jt,t[47]=Lt^~Zt&Ht,t[8]=ut^~rt&it,t[9]=ht^~nt&ot,t[18]=kt^~st&pt,t[19]=mt^~dt&yt,t[28]=Ot^~_t&Bt,t[29]=It^~xt&At,t[38]=Rt^~Ft&jt,t[39]=Wt^~Nt&Kt,t[48]=Yt^~Jt&Ut,t[49]=Zt^~Ht&Vt,t[0]^=W[l],t[1]^=W[l+1]};if(b)c.exports=T;else for(z=0;z<G.length;++z)i[G[z]]=T[G[z]]})()})(Xt)),Xt.exports}var Se=be();const ke=ge(Se),{keccak256:fe}=ke;function te(c){return new TextEncoder().encode(c)}function me(c){const r=c.startsWith("0x")?c.slice(2):c,e=new Uint8Array(r.length/2);for(let a=0;a<e.length;a++)e[a]=parseInt(r.substring(a*2,a*2+2),16);return e}function _e(c){let r="";for(let e=0;e<c.length;e++)r+=c[e].toString(16).padStart(2,"0");return"0x"+r}function ue(c,r,e){const a=JSON.stringify(c),i=te(a),f=fe(r+":"+e.join(".")),p=te(f),b=new Uint8Array(i.length);for(let y=0;y<i.length;y++)b[y]=i[y]^p[y%p.length];return _e(b)}function ee(c,r,e){try{const a=me(c),i=fe(r+":"+e.join(".")),f=te(i),p=new Uint8Array(a.length);for(let y=0;y<a.length;y++)p[y]=a[y]^f[y%f.length];const b=new TextDecoder().decode(p);return JSON.parse(b)}catch{return null}}function xe(c){if(typeof c!="string"||!c.startsWith("0x"))return!1;const r=c.slice(2);return r.length<2||r.length%2!==0?!1:/^[0-9a-fA-F]+$/.test(r)}function Be(c,r,e){if(r.length===0){if(e.length===1&&typeof e[0]=="string"){const S=e[0].trim(),O=S.startsWith("_")||S.startsWith("~")||S.startsWith("@"),J=S.includes("."),R=/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(S);if(J||O||R){const P=S.split(".").filter(Boolean);return c.readPath(P)}}if(e.length===0)return c.createProxy([]);const y=c.normalizeArgs(e),g=c.postulate([],y);return g!==void 0?g:c.createProxy([])}const a=c.normalizeArgs(e),i=c.postulate(r,a),{scope:f,leaf:p}=c.splitPath(r),b=p?c.opKind(p):null;if(c.isThought(i)){const y=b?f:r;return c.createProxy(y)}return i!==void 0?i:c.createProxy(r)}const he="+";function D(c){let r=2166136261;for(let e=0;e<c.length;e++)r^=c.charCodeAt(e),r=Math.imul(r,16777619);return("00000000"+(r>>>0).toString(16)).slice(-8)}class re{constructor(r){this.localSecrets={},this.localNoises={},this.encryptedBranches={},this.index={},this._shortTermMemory=[],this.operators={_:{kind:"secret"},"~":{kind:"noise"},__:{kind:"pointer"},"->":{kind:"pointer"},"@":{kind:"identity"},"=":{kind:"eval"},"?":{kind:"query"},"-":{kind:"remove"}},this.localSecrets={},this.localNoises={},this.encryptedBranches={},this.index={},this.operators={_:{kind:"secret"},"~":{kind:"noise"},__:{kind:"pointer"},"->":{kind:"pointer"},"@":{kind:"identity"},"=":{kind:"eval"},"?":{kind:"query"},"-":{kind:"remove"}},this._shortTermMemory=[],r!==void 0&&this.postulate([],r),this.rebuildIndex();const e=this.createProxy([]);return Object.setPrototypeOf(e,re.prototype),Object.assign(e,this),e}get shortTermMemory(){return this._shortTermMemory}isRemoveCall(r,e){if(r.length===0)return null;const{scope:a,leaf:i}=N(r);if(!i||this.opKind(i)!=="remove")return null;if(e==null)return{targetPath:a};if(typeof e=="string"){const f=e.split(".").filter(Boolean);return{targetPath:[...a,...f]}}return null}createProxy(r){const e=this,a=(...i)=>Be({createProxy:f=>e.createProxy(f),normalizeArgs:f=>e.normalizeArgs(f),readPath:f=>e.readPath(f),postulate:(f,p)=>e.postulate(f,p),opKind:f=>e.opKind(f),splitPath:N,isThought:ye},r,i);return new Proxy(a,{get(i,f){if(typeof f=="symbol")return i[f];if(f in e){const b=e[f];return typeof b=="function"?b.bind(e):b}const p=[...r,String(f)];return e.createProxy(p)},apply(i,f,p){return Reflect.apply(i,void 0,p)}})}normalizeArgs(r){if(r.length!==0)return r.length===1?r[0]:r}opKind(r){return this.operators[r]?.kind??null}isSecretScopeCall(r,e){if(r.length===0)return null;const{scope:a,leaf:i}=N(r);return!i||this.opKind(i)!=="secret"||typeof e!="string"?null:{scopeKey:a.join(".")}}isNoiseScopeCall(r,e){if(r.length===0)return null;const{scope:a,leaf:i}=N(r);return!i||this.opKind(i)!=="noise"||typeof e!="string"?null:{scopeKey:a.join(".")}}isPointerCall(r,e){if(r.length===0)return null;const{leaf:a}=N(r);if(!a||this.opKind(a)!=="pointer"||typeof e!="string")return null;const i=e.trim().replace(/^\./,"");return i?{targetPath:i}:null}isIdentityCall(r,e){if(r.length===1&&this.opKind(r[0])==="identity")return typeof e!="string"?null:{id:ce(e),targetPath:[]};const{scope:a,leaf:i}=N(r);return!i||this.opKind(i)!=="identity"||typeof e!="string"?null:{id:ce(e),targetPath:a}}isEvalCall(r,e){if(r.length===0)return null;const{scope:a,leaf:i}=N(r);if(!i||this.opKind(i)!=="eval")return null;if(typeof e=="function")return{mode:"thunk",targetPath:a,thunk:e};if(Array.isArray(e)&&e.length>=2){const f=String(e[0]??"").trim(),p=String(e[1]??"").trim();return!f||!p?null:{mode:"assign",targetPath:a,name:f,expr:p}}return null}isQueryCall(r,e){if(r.length===0)return null;const{scope:a,leaf:i}=N(r);if(!i||this.opKind(i)!=="query")return null;let f=null,p;if(Array.isArray(e)&&e.length>0)Array.isArray(e[0])&&(e.length===1||typeof e[1]=="function")?(f=e[0],p=typeof e[1]=="function"?e[1]:void 0):f=e;else return null;if(!Array.isArray(f)||f.length===0)return null;const b=f.map(y=>String(y)).map(y=>y.trim()).filter(y=>y.length>0);return b.length===0?null:{targetPath:a,paths:b,fn:p}}isDefineOpCall(r,e){if(r.length!==1||r[0]!==he||!Array.isArray(e)||e.length<2)return null;const i=String(e[0]??"").trim(),f=String(e[1]??"").trim();return!i||!f||i===he?null:{op:i,kind:f}}postulate(r,e,a=null){let i=r,f=e;const p=this.isDefineOpCall(i,e);if(p){this.operators[p.op]={kind:p.kind};return}const b=this.isEvalCall(i,e);if(b){if(b.mode==="thunk"){const x=b.thunk();return b.targetPath.length===0?x:this.postulate(b.targetPath,x,"=")}const k=[...b.targetPath,b.name];return this.postulate(k,b.expr,"=")}const y=this.isQueryCall(i,e);if(y){const k=y.paths.map(C=>this.readPath(C.split(".").filter(Boolean))),x=y.fn?y.fn(...k):k;return y.targetPath.length===0?x:this.postulate(y.targetPath,x,"?")}const g=this.isRemoveCall(i,e);if(g){this.removeSubtree(g.targetPath);return}const S=this.isSecretScopeCall(i,e);if(S){this.localSecrets[S.scopeKey]=e;const k=S.scopeKey?S.scopeKey.split(".").filter(Boolean):[],x=k.join("."),C=this.computeEffectiveSecret(k),w="***",_="***",F=JSON.stringify({path:x,operator:"_",expression:w,value:_,effectiveSecret:C}),I=D(F),K=Date.now(),M={path:x,operator:"_",expression:w,value:_,effectiveSecret:C,hash:I,timestamp:K};return this._shortTermMemory.push(M),this.rebuildIndex(),M}const O=this.isNoiseScopeCall(i,e);if(O){this.localNoises[O.scopeKey]=e;const k=O.scopeKey?O.scopeKey.split(".").filter(Boolean):[],x=k.join("."),C=this.computeEffectiveSecret(k),w="***",_="***",F=JSON.stringify({path:x,operator:"~",expression:w,value:_,effectiveSecret:C}),I=D(F),K=Date.now(),M={path:x,operator:"~",expression:w,value:_,effectiveSecret:C,hash:I,timestamp:K};return this._shortTermMemory.push(M),this.rebuildIndex(),M}const J=this.isPointerCall(i,e);if(J){const{scope:k}=N(i);i=k,e=V(J.targetPath),f=e,a===null&&(a="__")}const R=this.isIdentityCall(i,e);R&&(i=R.targetPath,e=pe(R.id),f=e,a===null&&(a="@"));const P=i.join("."),W=this.computeEffectiveSecret(i),E=this.resolveBranchScope(i);if(E&&E.length===0&&this.localSecrets[""]&&this.localSecrets[P],E&&E.length>0){const k=this.computeEffectiveSecret(E),x=i.slice(E.length),C=this.getBranchBlob(E);let w={};if(C&&k){const _=ee(C,k,E);_&&typeof _=="object"&&(w=_)}if(x.length===0)(typeof w!="object"||w===null)&&(w={}),w.expression=e;else{let _=w;for(let F=0;F<x.length-1;F++){const I=x[F];(!_[I]||typeof _[I]!="object")&&(_[I]={}),_=_[I]}_[x[x.length-1]]=e}if(k){const _=ue(w,k,E);this.setBranchBlob(E,_)}f=e}else if(W){const k=a!=="="&&a!=="?";j(e)||Qt(e)||!k?f=e:f=ue(e,W,i)}else f=e;const H=f,L=JSON.stringify({path:P,operator:a,expression:e,value:H,effectiveSecret:W}),Y=D(L),ne=Date.now(),Z={path:P,operator:a,expression:e,value:H,effectiveSecret:W,hash:Y,timestamp:ne};return this._shortTermMemory.push(Z),this.rebuildIndex(),Z}removeSubtree(r){const e=r.join(".");for(const g of Object.keys(this.localSecrets)){if(e===""){delete this.localSecrets[g];continue}(g===e||g.startsWith(e+"."))&&delete this.localSecrets[g]}for(const g of Object.keys(this.localNoises)){if(e===""){delete this.localNoises[g];continue}(g===e||g.startsWith(e+"."))&&delete this.localNoises[g]}for(const g of Object.keys(this.encryptedBranches)){if(e===""){delete this.encryptedBranches[g];continue}(g===e||g.startsWith(e+"."))&&delete this.encryptedBranches[g]}const a=r.join("."),i=Date.now(),f=this.computeEffectiveSecret(r),p=JSON.stringify({path:a,operator:"-",expression:"-",value:"-",effectiveSecret:f}),b=D(p),y={path:a,operator:"-",expression:"-",value:"-",effectiveSecret:f,hash:b,timestamp:i};this._shortTermMemory.push(y),this.rebuildIndex()}computeEffectiveSecret(r){let e=null,a=null;this.localNoises[""]!==void 0&&(e="",a=this.localNoises[""]);for(let f=1;f<=r.length;f++){const p=r.slice(0,f).join(".");this.localNoises[p]!==void 0&&(e=p,a=this.localNoises[p])}let i="root";a?i=D("noise::"+a):this.localSecrets[""]&&(i=D(i+"::"+this.localSecrets[""])),e===null||e===""||e.split(".").filter(Boolean).length;for(let f=1;f<=r.length;f++){const p=r.slice(0,f).join(".");if(this.localSecrets[p]){if(e!==null&&e!==""){const b=e+".";if(!(p===e||p.startsWith(b)))continue}i=D(i+"::"+this.localSecrets[p])}}return i==="root"?"":i}rebuildIndex(){const r={};for(const e of this._shortTermMemory){const a=e.path,i=a.split(".").filter(Boolean),f=this.resolveBranchScope(i),p=f&&f.length>0&&le(i,f);if(e.operator==="-"){if(a===""){for(const y of Object.keys(r))delete r[y];continue}const b=a+".";for(const y of Object.keys(r))(y===a||y.startsWith(b))&&delete r[y];continue}p||(r[a]=e.value)}this.index=r}getIndex(r){return this.index[r.join(".")]}setIndex(r,e){this.index[r.join(".")]=e}resolveIndexPointerPath(r,e=8){let a=r;for(let i=0;i<e;i++){const f=this.getIndex(a);if(!j(f))return{path:a,raw:f};a=f.__ptr.split(".").filter(Boolean)}return{path:a,raw:void 0}}setBranchBlob(r,e){const a=r.join(".");this.encryptedBranches[a]=e}getBranchBlob(r){const e=r.join(".");return this.encryptedBranches[e]}resolveBranchScope(r){let e=null;this.localSecrets[""]&&(e=[]);for(let a=1;a<=r.length;a++){const i=r.slice(0,a),f=i.join(".");this.localSecrets[f]&&(e=i)}return e}readPath(r){const e=this.resolveBranchScope(r);if(e&&e.length>0&&le(r,e)){if(r.length===e.length)return;const p=this.computeEffectiveSecret(e);if(!p)return null;const b=this.getBranchBlob(e);if(!b)return;const y=ee(b,p,e);if(!y||typeof y!="object")return;const g=r.slice(e.length);let S=y;for(const O of g){if(!S||typeof S!="object")return;S=S[O]}return j(S)?this.readPath(S.__ptr.split(".").filter(Boolean)):(Qt(S),S)}const i=this.resolveIndexPointerPath(r).raw;if(i===void 0)return;if(j(i))return this.readPath(i.__ptr.split(".").filter(Boolean));if(Qt(i)||!xe(i))return i;const f=this.computeEffectiveSecret(r);return f?ee(i,f,r):null}}return re}));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function asciiToBytes(str: string): Uint8Array;
|
|
2
|
+
export declare function hexToBytes(hex: string): Uint8Array;
|
|
3
|
+
export declare function bytesToHex(buf: Uint8Array): `0x${string}`;
|
|
4
|
+
export declare function xorEncrypt(value: any, secret: string, path: string[]): `0x${string}`;
|
|
5
|
+
export declare function xorDecrypt(hex: string, secret: string, path: string[]): any;
|
|
6
|
+
export declare function isEncryptedBlob(v: any): v is `0x${string}`;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { SemanticPath, Thought } from './types.js';
|
|
2
|
+
export type MEProxy = any;
|
|
3
|
+
export interface HandleCallDeps {
|
|
4
|
+
/** Create (or reuse) a proxy for a semantic path. */
|
|
5
|
+
createProxy(path: SemanticPath): MEProxy;
|
|
6
|
+
/** Normalize call args into an expression (0 args -> undefined, 1 -> arg, 2+ -> array). */
|
|
7
|
+
normalizeArgs(args: any[]): any;
|
|
8
|
+
/** Read a semantic path (used by root GET bias). */
|
|
9
|
+
readPath(path: SemanticPath): any;
|
|
10
|
+
/** Perform a semantic write/claim at a path. May return a thought, a value, or undefined. */
|
|
11
|
+
postulate(path: SemanticPath, expression: any): any;
|
|
12
|
+
/** Resolve operator kinds (used only to decide chaining path when a thought was produced). */
|
|
13
|
+
opKind(op: string): string | null;
|
|
14
|
+
splitPath(path: SemanticPath): {
|
|
15
|
+
scope: SemanticPath;
|
|
16
|
+
leaf: string | null;
|
|
17
|
+
};
|
|
18
|
+
isThought(obj: any): obj is Thought;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Extracted `handleCall` logic from `me.ts`.
|
|
22
|
+
*
|
|
23
|
+
* IMPORTANT: This module is intentionally dumb about internals.
|
|
24
|
+
* It only performs:
|
|
25
|
+
* - root GET bias routing
|
|
26
|
+
* - invoking postulate
|
|
27
|
+
* - deciding what to return for chaining
|
|
28
|
+
*/
|
|
29
|
+
export declare function handleCall(deps: HandleCallDeps, path: SemanticPath, args: any[]): MEProxy | any;
|
package/dist/src/me.d.ts
CHANGED
|
@@ -1,105 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
key: string;
|
|
3
|
-
value: any;
|
|
4
|
-
signature: string;
|
|
5
|
-
timestamp: number;
|
|
6
|
-
}
|
|
1
|
+
import { Thought } from './types.js';
|
|
7
2
|
export type MEProxy = ME & {
|
|
8
3
|
[key: string]: any;
|
|
9
4
|
(...args: any[]): MEProxy;
|
|
10
5
|
};
|
|
11
6
|
export declare class ME {
|
|
12
7
|
[key: string]: any;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
constructor(username: string, secret: string, blockchain: string);
|
|
24
|
-
/**
|
|
25
|
-
* Create a proxy bound to a specific path, e.g. ["wallet", "income"]
|
|
26
|
-
* The proxy itself is callable (function) and also expandable via property access.
|
|
27
|
-
*/
|
|
28
|
-
private createProxy;
|
|
29
|
-
/**
|
|
30
|
-
* Handle a call at a given path.
|
|
31
|
-
* Examples:
|
|
32
|
-
* me.wallet.income(200) → set encrypted payload at wallet.income
|
|
33
|
-
* me.wallet.secret("abc123") → set secret for path "wallet"
|
|
34
|
-
* me.wallet.ptr() → return pointer object { __ptr: "wallet" }
|
|
35
|
-
*/
|
|
36
|
-
private handleCall;
|
|
37
|
-
/**
|
|
38
|
-
* Secret scope resolution with path:
|
|
39
|
-
* - Find the most specific path that has a secret.
|
|
40
|
-
* - Return both the secret and the path at which it was defined.
|
|
41
|
-
* - If none, fall back to root secret with empty path.
|
|
42
|
-
*/
|
|
43
|
-
private resolveSecretWithPath;
|
|
44
|
-
/**
|
|
45
|
-
* Backwards-compatible helper: only return the secret string.
|
|
46
|
-
*/
|
|
47
|
-
private resolveSecret;
|
|
48
|
-
/**
|
|
49
|
-
* Encrypt and store the value at the given path inside `payload`.
|
|
50
|
-
*
|
|
51
|
-
* If there is a non-root secret defined for some ancestor path P of `path`,
|
|
52
|
-
* we treat that ancestor path P as the "branch root" and store the ENTIRE
|
|
53
|
-
* subtree under P as ONE encrypted blob at that location.
|
|
8
|
+
private localSecrets;
|
|
9
|
+
private localNoises;
|
|
10
|
+
private encryptedBranches;
|
|
11
|
+
private index;
|
|
12
|
+
private _shortTermMemory;
|
|
13
|
+
get shortTermMemory(): Thought[];
|
|
14
|
+
private operators;
|
|
15
|
+
/**
|
|
16
|
+
* Constructor base:
|
|
17
|
+
* me = new ME(expression?)
|
|
54
18
|
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* - the secret used at P.
|
|
19
|
+
* Esto es equivalente a llamar:
|
|
20
|
+
* me(expression) en la raíz.
|
|
58
21
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
private
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
private
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
private
|
|
72
|
-
private
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
private
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
private
|
|
82
|
-
/**
|
|
83
|
-
* Decrypt a single encrypted blob using the secret resolved for the given path.
|
|
84
|
-
*/
|
|
85
|
-
private decryptForPath;
|
|
86
|
-
private asciiToBytes;
|
|
87
|
-
private hexToBytes;
|
|
88
|
-
private isHexString;
|
|
89
|
-
/**
|
|
90
|
-
* Export the encrypted payload and declaration metadata.
|
|
91
|
-
*/
|
|
92
|
-
export(): {
|
|
93
|
-
identityRoot: string;
|
|
94
|
-
publicKey: string;
|
|
95
|
-
identityHash: string;
|
|
96
|
-
declarations: MeDeclaration[];
|
|
97
|
-
payload: any;
|
|
98
|
-
};
|
|
99
|
-
/**
|
|
100
|
-
* Export and decrypt a specific branch using the currently active secret
|
|
101
|
-
* resolved for that path.
|
|
102
|
-
*/
|
|
103
|
-
exportBranch(path: string): any;
|
|
22
|
+
constructor(expression?: any);
|
|
23
|
+
private isRemoveCall;
|
|
24
|
+
private createProxy;
|
|
25
|
+
private normalizeArgs;
|
|
26
|
+
private opKind;
|
|
27
|
+
private isSecretScopeCall;
|
|
28
|
+
private isNoiseScopeCall;
|
|
29
|
+
private isPointerCall;
|
|
30
|
+
private isIdentityCall;
|
|
31
|
+
private isEvalCall;
|
|
32
|
+
private isQueryCall;
|
|
33
|
+
private isDefineOpCall;
|
|
34
|
+
private postulate;
|
|
35
|
+
private removeSubtree;
|
|
36
|
+
private computeEffectiveSecret;
|
|
37
|
+
private rebuildIndex;
|
|
38
|
+
private getIndex;
|
|
39
|
+
private setIndex;
|
|
40
|
+
private resolveIndexPointerPath;
|
|
41
|
+
private setBranchBlob;
|
|
42
|
+
private getBranchBlob;
|
|
43
|
+
private resolveBranchScope;
|
|
44
|
+
private readPath;
|
|
104
45
|
}
|
|
105
|
-
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { OperatorKind, OperatorRegistry, OperatorToken, SemanticPath, MePointer, MeIdentityRef, Thought } from './types.js';
|
|
2
|
+
export declare const OP_DEFINE: OperatorToken;
|
|
3
|
+
export declare function makePointer(path: string): MePointer;
|
|
4
|
+
export declare function isPointer(obj: any): obj is MePointer;
|
|
5
|
+
export declare function makeIdentityRef(id: string): MeIdentityRef;
|
|
6
|
+
export declare function isIdentityRef(obj: any): obj is MeIdentityRef;
|
|
7
|
+
export declare function isThought(obj: any): obj is Thought;
|
|
8
|
+
export declare function splitPath(path: SemanticPath): {
|
|
9
|
+
scope: SemanticPath;
|
|
10
|
+
leaf: string | null;
|
|
11
|
+
};
|
|
12
|
+
export declare function pathStartsWith(path: SemanticPath, prefix: SemanticPath): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Domain-safe label rules (DNS-like):
|
|
15
|
+
* - 3..63 chars
|
|
16
|
+
* - a-z, 0-9, hyphen
|
|
17
|
+
* - must start/end with alphanumeric
|
|
18
|
+
* - disallow consecutive hyphens "--" (hygiene)
|
|
19
|
+
*/
|
|
20
|
+
export declare function normalizeAndValidateUsername(input: string): string;
|
|
21
|
+
export declare function opKind(operators: OperatorRegistry, op: string): OperatorKind | null;
|
|
22
|
+
export declare function isDefineOpCall(path: SemanticPath, expression: any): {
|
|
23
|
+
op: string;
|
|
24
|
+
kind: string;
|
|
25
|
+
} | null;
|
|
26
|
+
export declare function isSecretScopeCall(operators: OperatorRegistry, path: SemanticPath, expression: any): {
|
|
27
|
+
scopeKey: string;
|
|
28
|
+
} | null;
|
|
29
|
+
export declare function isNoiseScopeCall(operators: OperatorRegistry, path: SemanticPath, expression: any): {
|
|
30
|
+
scopeKey: string;
|
|
31
|
+
} | null;
|
|
32
|
+
export declare function isPointerCall(operators: OperatorRegistry, path: SemanticPath, expression: any): {
|
|
33
|
+
targetPath: string;
|
|
34
|
+
} | null;
|
|
35
|
+
export declare function isIdentityCall(operators: OperatorRegistry, path: SemanticPath, expression: any): {
|
|
36
|
+
id: string;
|
|
37
|
+
targetPath: SemanticPath;
|
|
38
|
+
} | null;
|
|
39
|
+
export type EvalCallMatch = {
|
|
40
|
+
mode: "thunk";
|
|
41
|
+
targetPath: SemanticPath;
|
|
42
|
+
thunk: Function;
|
|
43
|
+
} | {
|
|
44
|
+
mode: "assign";
|
|
45
|
+
targetPath: SemanticPath;
|
|
46
|
+
name: string;
|
|
47
|
+
expr: string;
|
|
48
|
+
};
|
|
49
|
+
export declare function isEvalCall(operators: OperatorRegistry, path: SemanticPath, expression: any): EvalCallMatch | null;
|
|
50
|
+
export declare function isQueryCall(operators: OperatorRegistry, path: SemanticPath, expression: any): {
|
|
51
|
+
targetPath: SemanticPath;
|
|
52
|
+
paths: string[];
|
|
53
|
+
fn?: Function;
|
|
54
|
+
} | null;
|
|
55
|
+
export declare function isRemoveCall(operators: OperatorRegistry, path: SemanticPath, expression: any): {
|
|
56
|
+
targetPath: SemanticPath;
|
|
57
|
+
} | null;
|
|
58
|
+
export declare const Operators: {
|
|
59
|
+
readonly OP_DEFINE: string;
|
|
60
|
+
readonly opKind: typeof opKind;
|
|
61
|
+
readonly splitPath: typeof splitPath;
|
|
62
|
+
readonly pathStartsWith: typeof pathStartsWith;
|
|
63
|
+
readonly makePointer: typeof makePointer;
|
|
64
|
+
readonly isPointer: typeof isPointer;
|
|
65
|
+
readonly makeIdentityRef: typeof makeIdentityRef;
|
|
66
|
+
readonly isIdentityRef: typeof isIdentityRef;
|
|
67
|
+
readonly isThought: typeof isThought;
|
|
68
|
+
readonly normalizeAndValidateUsername: typeof normalizeAndValidateUsername;
|
|
69
|
+
readonly isDefineOpCall: typeof isDefineOpCall;
|
|
70
|
+
readonly isSecretScopeCall: typeof isSecretScopeCall;
|
|
71
|
+
readonly isNoiseScopeCall: typeof isNoiseScopeCall;
|
|
72
|
+
readonly isPointerCall: typeof isPointerCall;
|
|
73
|
+
readonly isIdentityCall: typeof isIdentityCall;
|
|
74
|
+
readonly isEvalCall: typeof isEvalCall;
|
|
75
|
+
readonly isQueryCall: typeof isQueryCall;
|
|
76
|
+
readonly isRemoveCall: typeof isRemoveCall;
|
|
77
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Thought } from './types.js';
|
|
2
|
+
export type MEProxy = ME & {
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
(...args: any[]): MEProxy;
|
|
5
|
+
};
|
|
6
|
+
export declare function hashFn(input: string): string;
|
|
7
|
+
export declare class ME {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
private localSecrets;
|
|
10
|
+
private localNoises;
|
|
11
|
+
private encryptedBranches;
|
|
12
|
+
private index;
|
|
13
|
+
private _shortTermMemory;
|
|
14
|
+
get shortTermMemory(): Thought[];
|
|
15
|
+
private operators;
|
|
16
|
+
/**
|
|
17
|
+
* Constructor base:
|
|
18
|
+
* me = new ME(expression?)
|
|
19
|
+
*
|
|
20
|
+
* Esto es equivalente a llamar:
|
|
21
|
+
* me(expression) en la raíz.
|
|
22
|
+
*/
|
|
23
|
+
constructor(expression?: any);
|
|
24
|
+
private isRemoveCall;
|
|
25
|
+
private createProxy;
|
|
26
|
+
private handleCall;
|
|
27
|
+
private normalizeArgs;
|
|
28
|
+
private opKind;
|
|
29
|
+
private isSecretScopeCall;
|
|
30
|
+
private isNoiseScopeCall;
|
|
31
|
+
private isPointerCall;
|
|
32
|
+
private isIdentityCall;
|
|
33
|
+
private isEvalCall;
|
|
34
|
+
private isQueryCall;
|
|
35
|
+
private isDefineOpCall;
|
|
36
|
+
private postulate;
|
|
37
|
+
private removeSubtree;
|
|
38
|
+
private computeEffectiveSecret;
|
|
39
|
+
private rebuildIndex;
|
|
40
|
+
private getIndex;
|
|
41
|
+
private resolveIndexPointerPath;
|
|
42
|
+
private setBranchBlob;
|
|
43
|
+
private getBranchBlob;
|
|
44
|
+
private resolveBranchScope;
|
|
45
|
+
private readPath;
|
|
46
|
+
}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
export type OperatorToken = "_" | "~" | "__" | "->" | "@" | "=" | "?" | "-" | "+" | string;
|
|
2
|
+
export type OperatorKind = "secret" | "noise" | "pointer" | "identity" | "eval" | "query" | "remove" | "custom";
|
|
3
|
+
export interface OperatorRegistryEntry {
|
|
4
|
+
kind: OperatorKind;
|
|
5
|
+
}
|
|
6
|
+
export type OperatorRegistry = Record<OperatorToken, OperatorRegistryEntry>;
|
|
7
|
+
/**
|
|
8
|
+
* Canonical semantic log item in ME.
|
|
9
|
+
* This mirrors the shape in `me.ts` exactly.
|
|
10
|
+
*/
|
|
11
|
+
export interface Thought {
|
|
12
|
+
/** semantic destination path (where the write/claim lands). root is "" */
|
|
13
|
+
path: string;
|
|
14
|
+
/** operator used to produce this thought (null for normal writes) */
|
|
15
|
+
operator: string | null;
|
|
16
|
+
/** expression as provided by the user (pre-eval / pre-resolve). */
|
|
17
|
+
expression: any;
|
|
18
|
+
/** value that was actually committed at `path` (post-eval / post-collect; may be encrypted) */
|
|
19
|
+
value: any;
|
|
20
|
+
/** computed by ME kernel (fractal secret chaining + noise override) */
|
|
21
|
+
effectiveSecret: string;
|
|
22
|
+
/** portable hash (FNV-1a 32-bit in me.ts) */
|
|
23
|
+
hash: string;
|
|
24
|
+
timestamp: number;
|
|
25
|
+
}
|
|
26
|
+
export type MePointer = {
|
|
27
|
+
__ptr: string;
|
|
28
|
+
};
|
|
29
|
+
export type MeIdentityRef = {
|
|
30
|
+
__id: string;
|
|
31
|
+
};
|
|
32
|
+
export type MeMarker = MePointer | MeIdentityRef;
|
|
33
|
+
export type EncryptedBlob = `0x${string}`;
|
|
34
|
+
export type SemanticPath = string[];
|
|
35
|
+
export type MEInstance = Record<string, any>;
|
|
36
|
+
export type MEProxy = {
|
|
37
|
+
[key: string]: any;
|
|
38
|
+
(...args: any[]): MEProxy;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* What ME routing produces when a Proxy chain is invoked.
|
|
42
|
+
*/
|
|
43
|
+
export interface OperatorCall {
|
|
44
|
+
/** Raw path array for the call site, including operator leaf if present. */
|
|
45
|
+
path: SemanticPath;
|
|
46
|
+
/**
|
|
47
|
+
* The normalized expression passed into postulate.
|
|
48
|
+
* - 0 args -> undefined
|
|
49
|
+
* - 1 arg -> that arg
|
|
50
|
+
* - 2+ args -> packed array
|
|
51
|
+
*/
|
|
52
|
+
expression: any;
|
|
53
|
+
/**
|
|
54
|
+
* When called at root path.length===0 and expression is a string that looks like a path,
|
|
55
|
+
* ME biases to GET. Operators should not override that routing.
|
|
56
|
+
*/
|
|
57
|
+
isRoot: boolean;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Operator recognition can either match (and then execute) or pass.
|
|
61
|
+
*/
|
|
62
|
+
export type OperatorMatch = {
|
|
63
|
+
matched: false;
|
|
64
|
+
} | {
|
|
65
|
+
matched: true;
|
|
66
|
+
/** The operator token that matched (e.g. "_", "=") */
|
|
67
|
+
token: OperatorToken;
|
|
68
|
+
/** The operator kind from the registry */
|
|
69
|
+
kind: OperatorKind;
|
|
70
|
+
/**
|
|
71
|
+
* The destination path that should receive the semantic write (operator leaf removed
|
|
72
|
+
* or otherwise transformed). In me.ts this is typically `scope`.
|
|
73
|
+
*/
|
|
74
|
+
targetPath: SemanticPath;
|
|
75
|
+
/**
|
|
76
|
+
* The expression to write after the operator transforms it.
|
|
77
|
+
* e.g. pointer operator turns expression:string into {__ptr:string}
|
|
78
|
+
*/
|
|
79
|
+
rewrittenExpression?: any;
|
|
80
|
+
/**
|
|
81
|
+
* If operator is producing a semantic thought, what should be recorded as `operator`.
|
|
82
|
+
* (me.ts uses "__" for both "__" and "->" pointer calls).
|
|
83
|
+
*/
|
|
84
|
+
thoughtOperator?: string;
|
|
85
|
+
/**
|
|
86
|
+
* Some operators return a value instead of writing when invoked at root.
|
|
87
|
+
* - root "=" thunk returns computed value
|
|
88
|
+
* - root "?" returns collected/transformed output
|
|
89
|
+
*/
|
|
90
|
+
returnsValueAtRoot?: boolean;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* A minimal “kernel facade” for operator modules.
|
|
94
|
+
* These are *capabilities* the ME kernel must expose so ops can behave exactly like me.ts.
|
|
95
|
+
*/
|
|
96
|
+
export interface OperatorKernel {
|
|
97
|
+
opKind(op: string): OperatorKind | null;
|
|
98
|
+
operators?: OperatorRegistry;
|
|
99
|
+
splitPath(path: SemanticPath): {
|
|
100
|
+
scope: SemanticPath;
|
|
101
|
+
leaf: string | null;
|
|
102
|
+
};
|
|
103
|
+
localSecrets?: Record<string, string>;
|
|
104
|
+
localNoises?: Record<string, string>;
|
|
105
|
+
encryptedBranches?: Record<string, EncryptedBlob>;
|
|
106
|
+
shortTermMemory?: Thought[];
|
|
107
|
+
rebuildIndex(): void;
|
|
108
|
+
computeEffectiveSecret(path: SemanticPath): string;
|
|
109
|
+
xorEncrypt(value: any, secret: string, path: SemanticPath): EncryptedBlob;
|
|
110
|
+
xorDecrypt(blob: EncryptedBlob, secret: string, path: SemanticPath): any;
|
|
111
|
+
isEncryptedBlob(v: any): v is EncryptedBlob;
|
|
112
|
+
makePointer(targetPath: string): MePointer;
|
|
113
|
+
isPointer(v: any): v is MePointer;
|
|
114
|
+
makeIdentityRef(id: string): MeIdentityRef;
|
|
115
|
+
isIdentityRef(v: any): v is MeIdentityRef;
|
|
116
|
+
/**
|
|
117
|
+
* Read semantic data using the same rules as me.ts:
|
|
118
|
+
* - Secret scope roots return undefined (stealth)
|
|
119
|
+
* - Secret interior reads decrypt from encryptedBranches
|
|
120
|
+
* - Public reads come from index and decrypt value-level blobs
|
|
121
|
+
*/
|
|
122
|
+
readPath(path: SemanticPath): any;
|
|
123
|
+
/**
|
|
124
|
+
* Append a thought to shortTermMemory and rebuild index.
|
|
125
|
+
* Operators that are “kernel-only” should avoid emitting thoughts.
|
|
126
|
+
*/
|
|
127
|
+
commitThought?(t: Thought): void;
|
|
128
|
+
/**
|
|
129
|
+
* Remove a subtree: deletes matching localSecrets/localNoises/encryptedBranches and emits a "-" thought.
|
|
130
|
+
*/
|
|
131
|
+
removeSubtree(targetPath: SemanticPath): void;
|
|
132
|
+
/**
|
|
133
|
+
* For ops that need username normalization.
|
|
134
|
+
*/
|
|
135
|
+
normalizeAndValidateUsername(input: string): string;
|
|
136
|
+
/**
|
|
137
|
+
* Portable hash function used to populate Thought.hash
|
|
138
|
+
*/
|
|
139
|
+
hashFn(input: string): string;
|
|
140
|
+
/**
|
|
141
|
+
* Current time. me.ts uses Date.now().
|
|
142
|
+
*/
|
|
143
|
+
now(): number;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Operators in me.ts can yield:
|
|
147
|
+
* - a Thought (most writes)
|
|
148
|
+
* - undefined (kernel-only or removals)
|
|
149
|
+
* - a returned value for root "=" thunk and root "?" query
|
|
150
|
+
*/
|
|
151
|
+
export type OperatorResult = Thought | any | undefined;
|
|
152
|
+
export interface OperatorHandler {
|
|
153
|
+
/**
|
|
154
|
+
* Return a match if this operator applies to the call.
|
|
155
|
+
* IMPORTANT: matching depends on:
|
|
156
|
+
* - operator token at leaf
|
|
157
|
+
* - operator registry kind
|
|
158
|
+
* - argument shape (string / function / array)
|
|
159
|
+
* - whether called at root vs non-root
|
|
160
|
+
*/
|
|
161
|
+
match(call: OperatorCall, kernel: OperatorKernel): OperatorMatch;
|
|
162
|
+
/**
|
|
163
|
+
* Execute behavior.
|
|
164
|
+
* This function may:
|
|
165
|
+
* - mutate kernel config (define operator)
|
|
166
|
+
* - write thoughts / encrypt branches / update secrets/noises
|
|
167
|
+
* - return a value (root eval/query) or a Thought
|
|
168
|
+
*/
|
|
169
|
+
execute(match: Extract<OperatorMatch, {
|
|
170
|
+
matched: true;
|
|
171
|
+
}>, call: OperatorCall, kernel: OperatorKernel): OperatorResult;
|
|
172
|
+
}
|
|
173
|
+
export interface OperatorModule {
|
|
174
|
+
/**
|
|
175
|
+
* The operator tokens this module is responsible for.
|
|
176
|
+
* (e.g. ["_"] or ["__", "->"]).
|
|
177
|
+
*/
|
|
178
|
+
tokens: OperatorToken[];
|
|
179
|
+
/**
|
|
180
|
+
* Optional: kind(s) this module expects.
|
|
181
|
+
*/
|
|
182
|
+
kinds?: OperatorKind[];
|
|
183
|
+
handler: OperatorHandler;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Invariants that MUST hold for an extracted-ops architecture to remain compatible with current me.ts.
|
|
187
|
+
*/
|
|
188
|
+
export declare const OperatorInvariants: {
|
|
189
|
+
/**
|
|
190
|
+
* Root GET bias:
|
|
191
|
+
* - me("a.b") is always readPath
|
|
192
|
+
* - me("username") is always readPath
|
|
193
|
+
* - me("@foo") / me("_secret") / me("~noise") are always readPath-style routing
|
|
194
|
+
*/
|
|
195
|
+
readonly rootGetBias: true;
|
|
196
|
+
/**
|
|
197
|
+
* Secret scopes are structural and stealth:
|
|
198
|
+
* - A non-root secret scope root (e.g. "wallet") must NOT appear in the public index.
|
|
199
|
+
* - Reading the scope root returns undefined.
|
|
200
|
+
* - Values under the scope are stored only inside encryptedBranches blob at the scope root.
|
|
201
|
+
*/
|
|
202
|
+
readonly secretScopesAreStealth: true;
|
|
203
|
+
/**
|
|
204
|
+
* Secret/noise declarations must not leak their raw string in Thought.
|
|
205
|
+
* me.ts records expression/value as "***" for those operator thoughts.
|
|
206
|
+
*/
|
|
207
|
+
readonly scopeDeclarationRedaction: true;
|
|
208
|
+
/**
|
|
209
|
+
* Pointer/identity markers are structural and must not be encrypted.
|
|
210
|
+
*/
|
|
211
|
+
readonly markersAreNeverEncrypted: true;
|
|
212
|
+
/**
|
|
213
|
+
* "=" thunk:
|
|
214
|
+
* - If invoked at root: returns computed value (no write)
|
|
215
|
+
* - Else: assigns evaluated value into targetPath (operator "=")
|
|
216
|
+
* "=" assign-string form stores expression string in <targetPath>.<name>
|
|
217
|
+
*/
|
|
218
|
+
readonly evalReturningAtRoot: true;
|
|
219
|
+
/**
|
|
220
|
+
* "?" collect:
|
|
221
|
+
* - Root returns output (no write)
|
|
222
|
+
* - Else assigns output at targetPath (operator "?")
|
|
223
|
+
*/
|
|
224
|
+
readonly queryReturningAtRoot: true;
|
|
225
|
+
/**
|
|
226
|
+
* "-" remove deletes:
|
|
227
|
+
* - localSecrets entries at/under subtree
|
|
228
|
+
* - localNoises entries at/under subtree
|
|
229
|
+
* - encryptedBranches blobs at/under subtree
|
|
230
|
+
* And emits a "-" thought.
|
|
231
|
+
*/
|
|
232
|
+
readonly removeIsDeep: true;
|
|
233
|
+
/**
|
|
234
|
+
* Operator define ("+") is kernel-only:
|
|
235
|
+
* - Only at root
|
|
236
|
+
* - Updates operator registry
|
|
237
|
+
* - Emits NO thought
|
|
238
|
+
*/
|
|
239
|
+
readonly defineIsKernelOnly: true;
|
|
240
|
+
};
|
|
241
|
+
export type BuiltinOperatorModules = "define" | "secret" | "noise" | "pointer" | "identity" | "eval" | "query" | "remove";
|
|
242
|
+
export interface OperatorSystemSpec {
|
|
243
|
+
registry: OperatorRegistry;
|
|
244
|
+
modules: OperatorModule[];
|
|
245
|
+
}
|