this.me 3.1.1 → 3.1.2
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 +20 -119
- package/dist/me.cjs +1 -1
- package/dist/me.es.js +1000 -604
- package/dist/me.umd.js +1 -1
- package/dist/src/me.d.ts +33 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -15,7 +15,6 @@ import ME from "this.me";
|
|
|
15
15
|
const me = new ME();
|
|
16
16
|
```
|
|
17
17
|
**Other modules formats and runtime targets:** CommonJS (`require`), UMD (global/script), TypeScript types.
|
|
18
|
-
[Read more](/docs/Builds.md)
|
|
19
18
|
|
|
20
19
|
###### **Declare** Your Data.
|
|
21
20
|
```ts
|
|
@@ -63,134 +62,35 @@ me("synth.moog.grandmother.osc1.wave");
|
|
|
63
62
|
Secrets create private branches:
|
|
64
63
|
|
|
65
64
|
```ts
|
|
66
|
-
me.wallet
|
|
67
|
-
me.wallet.
|
|
65
|
+
me.wallet["_"]("ABC"); // declare secret scope at "wallet"
|
|
66
|
+
me.wallet.balance(500);
|
|
67
|
+
me.wallet.transactions.list([1, 2, 3]);
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
Everything under that
|
|
71
|
-
|
|
70
|
+
Everything under that scope is stored in an encrypted branch blob.
|
|
71
|
+
Secret scope roots are stealth by design:
|
|
72
72
|
|
|
73
73
|
```ts
|
|
74
|
-
me
|
|
75
|
-
me("wallet");
|
|
76
|
-
// →
|
|
74
|
+
me("wallet"); // → undefined (stealth root)
|
|
75
|
+
me("wallet.balance"); // → 500
|
|
76
|
+
me("wallet.transactions.list"); // → [1, 2, 3]
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
Secrets can nest infinitely
|
|
79
|
+
Secrets can nest infinitely:
|
|
80
80
|
|
|
81
81
|
```ts
|
|
82
|
-
me.wallet
|
|
83
|
-
me.
|
|
84
|
-
me.
|
|
85
|
-
|
|
86
|
-
// →
|
|
82
|
+
me.wallet["_"]("ABC");
|
|
83
|
+
me.wallet.hidden["_"]("DEEP");
|
|
84
|
+
me.wallet.hidden.note("private");
|
|
85
|
+
|
|
86
|
+
me("wallet.hidden"); // → undefined (stealth root)
|
|
87
|
+
me("wallet.hidden.note"); // → "private"
|
|
87
88
|
```
|
|
88
89
|
|
|
89
90
|
- **A secret belongs to a specific position in the identity tree.**
|
|
90
91
|
- Everything under that position becomes encrypted.
|
|
91
|
-
- If you declare another secret inside, it becomes a deeper encrypted
|
|
92
|
-
-
|
|
93
|
-
|
|
94
|
-
## **🌳 A secret attaches to a position in the tree**
|
|
95
|
-
You do:
|
|
96
|
-
|
|
97
|
-
```
|
|
98
|
-
me.wallet.secret("ABC");
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
**.me** interprets this as:
|
|
102
|
-
> “The subtree starting at wallet is encrypted with ABC.”
|
|
103
|
-
Diagram:
|
|
104
|
-
|
|
105
|
-
```text
|
|
106
|
-
root
|
|
107
|
-
└── wallet (SECRET ABC)
|
|
108
|
-
├── balance
|
|
109
|
-
└── transactions
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
Everything below wallet is encrypted **as one block**.
|
|
113
|
-
|
|
114
|
-
## 🌚 Declaring another secret inside creates a nested universe
|
|
115
|
-
You do:
|
|
116
|
-
```
|
|
117
|
-
me.wallet.private.secret("DEEP");
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
Now **.me** interprets:
|
|
121
|
-
> “Inside wallet/ (encrypted under ABC), private/ will be encrypted under DEEP.”
|
|
122
|
-
Visual:
|
|
123
|
-
|
|
124
|
-
```text
|
|
125
|
-
root
|
|
126
|
-
└── wallet (SECRET ABC)
|
|
127
|
-
├── balance
|
|
128
|
-
├── transactions
|
|
129
|
-
└── private (SECRET DEEP)
|
|
130
|
-
└── ...nodes...
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
## 🔐 Accessing nested secrets requires walking the secret chain
|
|
134
|
-
To read the inner content:
|
|
135
|
-
|
|
136
|
-
```js
|
|
137
|
-
me.secret("ABC"); // unlock wallet universe
|
|
138
|
-
me.secret("DEEP"); // unlock nested private universe
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
Then:
|
|
142
|
-
|
|
143
|
-
```js
|
|
144
|
-
me("wallet.private") // returns decrypted inner structure
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
## **🌌 You can nest as many secrets as you want**
|
|
148
|
-
|
|
149
|
-
```js
|
|
150
|
-
me.x.secret("A");
|
|
151
|
-
me.x.y.secret("B");
|
|
152
|
-
me.x.y.z.secret("C");
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
To access:
|
|
156
|
-
|
|
157
|
-
```js
|
|
158
|
-
me.secret("A");
|
|
159
|
-
me.secret("B");
|
|
160
|
-
me.secret("C");
|
|
161
|
-
me("x.y.z"); // fully decrypted
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
Visual:
|
|
165
|
-
|
|
166
|
-
```
|
|
167
|
-
x (A)
|
|
168
|
-
└── y (B)
|
|
169
|
-
└── z (C)
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
Every deeper secret is a smaller encrypted universe inside a larger encrypted universe.
|
|
173
|
-
This is **fractal encryption**.
|
|
174
|
-
Let’s rewrite your example cleanly:
|
|
175
|
-
|
|
176
|
-
```js
|
|
177
|
-
me.cars.keys.secret("X");
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
> “Does this mean cars.keys is public, but everything *inside* keys (after calling secret) becomes encrypted?”
|
|
181
|
-
##### **✔ YES.**
|
|
182
|
-
- cars → public
|
|
183
|
-
- cars.keys → public *branch*
|
|
184
|
-
|
|
185
|
-
- **everything inside** **cars.keys.\***
|
|
186
|
-
(anything you declare after calling secret)
|
|
187
|
-
→ encrypted under "X"
|
|
188
|
-
|
|
189
|
-
### **🧠 Answer to common questions:**
|
|
190
|
-
##### **✔ Yes — you can declare secrets at specific positions.**
|
|
191
|
-
##### **✔ Yes — everything under that branch becomes encrypted.**
|
|
192
|
-
##### **✔ Yes — you can put another secret deeper.**
|
|
193
|
-
##### **✔ Yes — to access you must follow the entire chain of secrets.**
|
|
92
|
+
- If you declare another secret inside, it becomes a deeper encrypted scope.
|
|
93
|
+
- Reads are path-based; there is no global `me.secret(...)` unlock call.
|
|
194
94
|
|
|
195
95
|
---
|
|
196
96
|
|
|
@@ -246,8 +146,9 @@ me.system.audio.filters.lowpass.cutoff(1200);
|
|
|
246
146
|
me.system.audio.filters.lowpass.resonance(0.7);
|
|
247
147
|
|
|
248
148
|
// Encrypted branch
|
|
249
|
-
me.wallet
|
|
250
|
-
me.wallet.
|
|
149
|
+
me.wallet["_"]("XYZ");
|
|
150
|
+
me.wallet.balance(500);
|
|
151
|
+
me.wallet.transactions.list([1, 2, 3]);
|
|
251
152
|
|
|
252
153
|
// Read values
|
|
253
154
|
console.log(me("name.first")); // "Abella"
|
package/dist/me.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function ve(l){return{__ptr:l}}function N(l){return!!l&&typeof l=="object"&&typeof l.__ptr=="string"&&l.__ptr.length>0}function be(l){return{__id:l}}function Lt(l){return!!l&&typeof l=="object"&&typeof l.__id=="string"&&l.__id.length>0}function me(l){return!!l&&typeof l=="object"&&typeof l.path=="string"&&typeof l.hash=="string"&&typeof l.timestamp=="number"}function C(l){return l.length===0?{scope:[],leaf:null}:{scope:l.slice(0,-1),leaf:l[l.length-1]}}function Gt(l,n){if(n.length>l.length)return!1;for(let e=0;e<n.length;e++)if(l[e]!==n[e])return!1;return!0}function Ht(l){const n=l.trim().toLowerCase();if(n.length<3||n.length>63)throw new Error(`Invalid username length: ${n.length}. Expected 3..63 characters.`);if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$/.test(n))throw new Error(`Invalid username. Use only [a-z0-9-], and start/end with [a-z0-9]. Got: ${l}`);if(n.includes("--"))throw new Error(`Invalid username. "--" is not allowed. Got: ${l}`);return n}function I(l,n){return l[n]?.kind??null}function ke(l,n){if(l.length!==1||l[0]!=="+"||!Array.isArray(n)||n.length<2)return null;const i=String(n[0]??"").trim(),r=String(n[1]??"").trim();return!i||!r||i==="+"?null:{op:i,kind:r}}function Se(l,n,e){if(n.length===0)return null;const{scope:i,leaf:r}=C(n);return!r||I(l,r)!=="secret"||typeof e!="string"?null:{scopeKey:i.join(".")}}function Ae(l,n,e){if(n.length===0)return null;const{scope:i,leaf:r}=C(n);return!r||I(l,r)!=="noise"||typeof e!="string"?null:{scopeKey:i.join(".")}}function Be(l,n,e){if(n.length===0)return null;const{leaf:i}=C(n);if(!i||I(l,i)!=="pointer"||typeof e!="string")return null;const r=e.trim().replace(/^\./,"");return r?{targetPath:r}:null}function _e(l,n,e){if(n.length===1&&I(l,n[0])==="identity")return typeof e!="string"?null:{id:Ht(e),targetPath:[]};const{scope:i,leaf:r}=C(n);return!r||I(l,r)!=="identity"||typeof e!="string"?null:{id:Ht(e),targetPath:i}}function Pe(l,n,e){if(n.length===0)return null;const{scope:i,leaf:r}=C(n);if(!r||I(l,r)!=="eval")return null;if(typeof e=="function")return{mode:"thunk",targetPath:i,thunk:e};if(Array.isArray(e)&&e.length>=2){const u=String(e[0]??"").trim(),f=String(e[1]??"").trim();return!u||!f?null:{mode:"assign",targetPath:i,name:u,expr:f}}return null}function we(l,n,e){if(n.length===0)return null;const{scope:i,leaf:r}=C(n);if(!r||I(l,r)!=="query")return null;let u=null,f;if(Array.isArray(e)&&e.length>0)Array.isArray(e[0])&&(e.length===1||typeof e[1]=="function")?(u=e[0],f=typeof e[1]=="function"?e[1]:void 0):u=e;else return null;if(!Array.isArray(u)||u.length===0)return null;const p=u.map(s=>String(s)).map(s=>s.trim()).filter(s=>s.length>0);return p.length===0?null:{targetPath:i,paths:p,fn:f}}function xe(l,n,e){if(n.length===0)return null;const{scope:i,leaf:r}=C(n);if(!r||I(l,r)!=="remove")return null;if(e==null)return{targetPath:i};if(typeof e=="string"){const u=e.split(".").filter(Boolean);return{targetPath:[...i,...u]}}return null}var Ce=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Oe(l){return l&&l.__esModule&&Object.prototype.hasOwnProperty.call(l,"default")?l.default:l}var Yt={exports:{}};var ae;function Ee(){return ae||(ae=1,(function(l){(function(){var n="input is invalid type",e="finalize already called",i=typeof window=="object",r=i?window:{};r.JS_SHA3_NO_WINDOW&&(i=!1);var u=!i&&typeof self=="object",f=!r.JS_SHA3_NO_NODE_JS&&typeof process=="object"&&process.versions&&process.versions.node;f?r=Ce:u&&(r=self);for(var p=!r.JS_SHA3_NO_COMMON_JS&&!0&&l.exports,s=!r.JS_SHA3_NO_ARRAY_BUFFER&&typeof ArrayBuffer<"u",h="0123456789abcdef".split(""),k=[31,7936,2031616,520093696],m=[4,1024,262144,67108864],S=[1,256,65536,16777216],B=[6,1536,393216,100663296],A=[0,8,16,24],x=[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],O=[224,256,384,512],E=[128,256],M=["hex","buffer","arrayBuffer","array","digest"],te={128:168,256:136},se=r.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return Object.prototype.toString.call(t)==="[object Array]"}:Array.isArray,de=s&&(r.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW||!ArrayBuffer.isView)?function(t){return typeof t=="object"&&t.buffer&&t.buffer.constructor===ArrayBuffer}:ArrayBuffer.isView,Ut=function(t){var o=typeof t;if(o==="string")return[t,!0];if(o!=="object"||t===null)throw new Error(n);if(s&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!se(t)&&!de(t))throw new Error(n);return[t,!1]},ee=function(t){return Ut(t)[0].length===0},Vt=function(t){for(var o=[],c=0;c<t.length;++c)o[c]=t[c];return o},ne=function(t,o,c){return function(a){return new P(t,o,t).update(a)[c]()}},re=function(t,o,c){return function(a,d){return new P(t,o,d).update(a)[c]()}},ie=function(t,o,c){return function(a,d,y,v){return F["cshake"+t].update(a,d,y,v)[c]()}},oe=function(t,o,c){return function(a,d,y,v){return F["kmac"+t].update(a,d,y,v)[c]()}},W=function(t,o,c,a){for(var d=0;d<M.length;++d){var y=M[d];t[y]=o(c,a,y)}return t},le=function(t,o){var c=ne(t,o,"hex");return c.create=function(){return new P(t,o,t)},c.update=function(a){return c.create().update(a)},W(c,ne,t,o)},pe=function(t,o){var c=re(t,o,"hex");return c.create=function(a){return new P(t,o,a)},c.update=function(a,d){return c.create(d).update(a)},W(c,re,t,o)},ye=function(t,o){var c=te[t],a=ie(t,o,"hex");return a.create=function(d,y,v){return ee(y)&&ee(v)?F["shake"+t].create(d):new P(t,o,d).bytepad([y,v],c)},a.update=function(d,y,v,g){return a.create(y,v,g).update(d)},W(a,ie,t,o)},ge=function(t,o){var c=te[t],a=oe(t,o,"hex");return a.create=function(d,y,v){return new $t(t,o,y).bytepad(["KMAC",v],c).bytepad([d],c)},a.update=function(d,y,v,g){return a.create(d,v,g).update(y)},W(a,oe,t,o)},ue=[{name:"keccak",padding:S,bits:O,createMethod:le},{name:"sha3",padding:B,bits:O,createMethod:le},{name:"shake",padding:k,bits:E,createMethod:pe},{name:"cshake",padding:m,bits:E,createMethod:ye},{name:"kmac",padding:m,bits:E,createMethod:ge}],F={},T=[],K=0;K<ue.length;++K)for(var j=ue[K],J=j.bits,D=0;D<J.length;++D){var qt=j.name+"_"+J[D];if(T.push(qt),F[qt]=j.createMethod(J[D],j.padding),j.name!=="sha3"){var ce=j.name+J[D];T.push(ce),F[ce]=F[qt]}}function P(t,o,c){this.blocks=[],this.s=[],this.padding=o,this.outputBits=c,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=c>>5,this.extraBytes=(c&31)>>3;for(var a=0;a<50;++a)this.s[a]=0}P.prototype.update=function(t){if(this.finalized)throw new Error(e);var o=Ut(t);t=o[0];for(var c=o[1],a=this.blocks,d=this.byteCount,y=t.length,v=this.blockCount,g=0,w=this.s,b,_;g<y;){if(this.reset)for(this.reset=!1,a[0]=this.block,b=1;b<v+1;++b)a[b]=0;if(c)for(b=this.start;g<y&&b<d;++g)_=t.charCodeAt(g),_<128?a[b>>2]|=_<<A[b++&3]:_<2048?(a[b>>2]|=(192|_>>6)<<A[b++&3],a[b>>2]|=(128|_&63)<<A[b++&3]):_<55296||_>=57344?(a[b>>2]|=(224|_>>12)<<A[b++&3],a[b>>2]|=(128|_>>6&63)<<A[b++&3],a[b>>2]|=(128|_&63)<<A[b++&3]):(_=65536+((_&1023)<<10|t.charCodeAt(++g)&1023),a[b>>2]|=(240|_>>18)<<A[b++&3],a[b>>2]|=(128|_>>12&63)<<A[b++&3],a[b>>2]|=(128|_>>6&63)<<A[b++&3],a[b>>2]|=(128|_&63)<<A[b++&3]);else for(b=this.start;g<y&&b<d;++g)a[b>>2]|=t[g]<<A[b++&3];if(this.lastByteIndex=b,b>=d){for(this.start=b-d,this.block=a[v],b=0;b<v;++b)w[b]^=a[b];z(w),this.reset=!0}else this.start=b}return this},P.prototype.encode=function(t,o){var c=t&255,a=1,d=[c];for(t=t>>8,c=t&255;c>0;)d.unshift(c),t=t>>8,c=t&255,++a;return o?d.push(a):d.unshift(a),this.update(d),d.length},P.prototype.encodeString=function(t){var o=Ut(t);t=o[0];var c=o[1],a=0,d=t.length;if(c)for(var y=0;y<t.length;++y){var v=t.charCodeAt(y);v<128?a+=1:v<2048?a+=2:v<55296||v>=57344?a+=3:(v=65536+((v&1023)<<10|t.charCodeAt(++y)&1023),a+=4)}else a=d;return a+=this.encode(a*8),this.update(t),a},P.prototype.bytepad=function(t,o){for(var c=this.encode(o),a=0;a<t.length;++a)c+=this.encodeString(t[a]);var d=(o-c%o)%o,y=[];return y.length=d,this.update(y),this},P.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,o=this.lastByteIndex,c=this.blockCount,a=this.s;if(t[o>>2]|=this.padding[o&3],this.lastByteIndex===this.byteCount)for(t[0]=t[c],o=1;o<c+1;++o)t[o]=0;for(t[c-1]|=2147483648,o=0;o<c;++o)a[o]^=t[o];z(a)}},P.prototype.toString=P.prototype.hex=function(){this.finalize();for(var t=this.blockCount,o=this.s,c=this.outputBlocks,a=this.extraBytes,d=0,y=0,v="",g;y<c;){for(d=0;d<t&&y<c;++d,++y)g=o[d],v+=h[g>>4&15]+h[g&15]+h[g>>12&15]+h[g>>8&15]+h[g>>20&15]+h[g>>16&15]+h[g>>28&15]+h[g>>24&15];y%t===0&&(o=Vt(o),z(o),d=0)}return a&&(g=o[d],v+=h[g>>4&15]+h[g&15],a>1&&(v+=h[g>>12&15]+h[g>>8&15]),a>2&&(v+=h[g>>20&15]+h[g>>16&15])),v},P.prototype.arrayBuffer=function(){this.finalize();var t=this.blockCount,o=this.s,c=this.outputBlocks,a=this.extraBytes,d=0,y=0,v=this.outputBits>>3,g;a?g=new ArrayBuffer(c+1<<2):g=new ArrayBuffer(v);for(var w=new Uint32Array(g);y<c;){for(d=0;d<t&&y<c;++d,++y)w[y]=o[d];y%t===0&&(o=Vt(o),z(o))}return a&&(w[y]=o[d],g=g.slice(0,v)),g},P.prototype.buffer=P.prototype.arrayBuffer,P.prototype.digest=P.prototype.array=function(){this.finalize();for(var t=this.blockCount,o=this.s,c=this.outputBlocks,a=this.extraBytes,d=0,y=0,v=[],g,w;y<c;){for(d=0;d<t&&y<c;++d,++y)g=y<<2,w=o[d],v[g]=w&255,v[g+1]=w>>8&255,v[g+2]=w>>16&255,v[g+3]=w>>24&255;y%t===0&&(o=Vt(o),z(o))}return a&&(g=y<<2,w=o[d],v[g]=w&255,a>1&&(v[g+1]=w>>8&255),a>2&&(v[g+2]=w>>16&255)),v};function $t(t,o,c){P.call(this,t,o,c)}$t.prototype=new P,$t.prototype.finalize=function(){return this.encode(this.outputBits,!0),P.prototype.finalize.call(this)};var z=function(t){var o,c,a,d,y,v,g,w,b,_,H,U,V,q,$,L,G,Y,Q,Z,X,tt,et,nt,rt,it,ot,lt,ut,ct,at,ft,ht,st,dt,pt,yt,gt,vt,bt,mt,kt,St,At,Bt,_t,Pt,wt,xt,Ct,Ot,Et,Ft,Kt,It,jt,Nt,Mt,Tt,Dt,zt,Rt,Wt;for(a=0;a<48;a+=2)d=t[0]^t[10]^t[20]^t[30]^t[40],y=t[1]^t[11]^t[21]^t[31]^t[41],v=t[2]^t[12]^t[22]^t[32]^t[42],g=t[3]^t[13]^t[23]^t[33]^t[43],w=t[4]^t[14]^t[24]^t[34]^t[44],b=t[5]^t[15]^t[25]^t[35]^t[45],_=t[6]^t[16]^t[26]^t[36]^t[46],H=t[7]^t[17]^t[27]^t[37]^t[47],U=t[8]^t[18]^t[28]^t[38]^t[48],V=t[9]^t[19]^t[29]^t[39]^t[49],o=U^(v<<1|g>>>31),c=V^(g<<1|v>>>31),t[0]^=o,t[1]^=c,t[10]^=o,t[11]^=c,t[20]^=o,t[21]^=c,t[30]^=o,t[31]^=c,t[40]^=o,t[41]^=c,o=d^(w<<1|b>>>31),c=y^(b<<1|w>>>31),t[2]^=o,t[3]^=c,t[12]^=o,t[13]^=c,t[22]^=o,t[23]^=c,t[32]^=o,t[33]^=c,t[42]^=o,t[43]^=c,o=v^(_<<1|H>>>31),c=g^(H<<1|_>>>31),t[4]^=o,t[5]^=c,t[14]^=o,t[15]^=c,t[24]^=o,t[25]^=c,t[34]^=o,t[35]^=c,t[44]^=o,t[45]^=c,o=w^(U<<1|V>>>31),c=b^(V<<1|U>>>31),t[6]^=o,t[7]^=c,t[16]^=o,t[17]^=c,t[26]^=o,t[27]^=c,t[36]^=o,t[37]^=c,t[46]^=o,t[47]^=c,o=_^(d<<1|y>>>31),c=H^(y<<1|d>>>31),t[8]^=o,t[9]^=c,t[18]^=o,t[19]^=c,t[28]^=o,t[29]^=c,t[38]^=o,t[39]^=c,t[48]^=o,t[49]^=c,q=t[0],$=t[1],_t=t[11]<<4|t[10]>>>28,Pt=t[10]<<4|t[11]>>>28,lt=t[20]<<3|t[21]>>>29,ut=t[21]<<3|t[20]>>>29,Dt=t[31]<<9|t[30]>>>23,zt=t[30]<<9|t[31]>>>23,kt=t[40]<<18|t[41]>>>14,St=t[41]<<18|t[40]>>>14,st=t[2]<<1|t[3]>>>31,dt=t[3]<<1|t[2]>>>31,L=t[13]<<12|t[12]>>>20,G=t[12]<<12|t[13]>>>20,wt=t[22]<<10|t[23]>>>22,xt=t[23]<<10|t[22]>>>22,ct=t[33]<<13|t[32]>>>19,at=t[32]<<13|t[33]>>>19,Rt=t[42]<<2|t[43]>>>30,Wt=t[43]<<2|t[42]>>>30,Kt=t[5]<<30|t[4]>>>2,It=t[4]<<30|t[5]>>>2,pt=t[14]<<6|t[15]>>>26,yt=t[15]<<6|t[14]>>>26,Y=t[25]<<11|t[24]>>>21,Q=t[24]<<11|t[25]>>>21,Ct=t[34]<<15|t[35]>>>17,Ot=t[35]<<15|t[34]>>>17,ft=t[45]<<29|t[44]>>>3,ht=t[44]<<29|t[45]>>>3,nt=t[6]<<28|t[7]>>>4,rt=t[7]<<28|t[6]>>>4,jt=t[17]<<23|t[16]>>>9,Nt=t[16]<<23|t[17]>>>9,gt=t[26]<<25|t[27]>>>7,vt=t[27]<<25|t[26]>>>7,Z=t[36]<<21|t[37]>>>11,X=t[37]<<21|t[36]>>>11,Et=t[47]<<24|t[46]>>>8,Ft=t[46]<<24|t[47]>>>8,At=t[8]<<27|t[9]>>>5,Bt=t[9]<<27|t[8]>>>5,it=t[18]<<20|t[19]>>>12,ot=t[19]<<20|t[18]>>>12,Mt=t[29]<<7|t[28]>>>25,Tt=t[28]<<7|t[29]>>>25,bt=t[38]<<8|t[39]>>>24,mt=t[39]<<8|t[38]>>>24,tt=t[48]<<14|t[49]>>>18,et=t[49]<<14|t[48]>>>18,t[0]=q^~L&Y,t[1]=$^~G&Q,t[10]=nt^~it<,t[11]=rt^~ot&ut,t[20]=st^~pt>,t[21]=dt^~yt&vt,t[30]=At^~_t&wt,t[31]=Bt^~Pt&xt,t[40]=Kt^~jt&Mt,t[41]=It^~Nt&Tt,t[2]=L^~Y&Z,t[3]=G^~Q&X,t[12]=it^~lt&ct,t[13]=ot^~ut&at,t[22]=pt^~gt&bt,t[23]=yt^~vt&mt,t[32]=_t^~wt&Ct,t[33]=Pt^~xt&Ot,t[42]=jt^~Mt&Dt,t[43]=Nt^~Tt&zt,t[4]=Y^~Z&tt,t[5]=Q^~X&et,t[14]=lt^~ct&ft,t[15]=ut^~at&ht,t[24]=gt^~bt&kt,t[25]=vt^~mt&St,t[34]=wt^~Ct&Et,t[35]=xt^~Ot&Ft,t[44]=Mt^~Dt&Rt,t[45]=Tt^~zt&Wt,t[6]=Z^~tt&q,t[7]=X^~et&$,t[16]=ct^~ft&nt,t[17]=at^~ht&rt,t[26]=bt^~kt&st,t[27]=mt^~St&dt,t[36]=Ct^~Et&At,t[37]=Ot^~Ft&Bt,t[46]=Dt^~Rt&Kt,t[47]=zt^~Wt&It,t[8]=tt^~q&L,t[9]=et^~$&G,t[18]=ft^~nt&it,t[19]=ht^~rt&ot,t[28]=kt^~st&pt,t[29]=St^~dt&yt,t[38]=Et^~At&_t,t[39]=Ft^~Bt&Pt,t[48]=Rt^~Kt&jt,t[49]=Wt^~It&Nt,t[0]^=x[a],t[1]^=x[a+1]};if(p)l.exports=F;else for(K=0;K<T.length;++K)r[T[K]]=F[T[K]]})()})(Yt)),Yt.exports}var Fe=Ee();const Ke=Oe(Fe),{keccak256:he}=Ke;function Zt(l){return new TextEncoder().encode(l)}function Ie(l){const n=l.startsWith("0x")?l.slice(2):l,e=new Uint8Array(n.length/2);for(let i=0;i<e.length;i++)e[i]=parseInt(n.substring(i*2,i*2+2),16);return e}function je(l){let n="";for(let e=0;e<l.length;e++)n+=l[e].toString(16).padStart(2,"0");return"0x"+n}function Qt(l,n,e){const i=JSON.stringify(l),r=Zt(i),u=he(n+":"+e.join(".")),f=Zt(u),p=new Uint8Array(r.length);for(let s=0;s<r.length;s++)p[s]=r[s]^f[s%f.length];return je(p)}function Jt(l,n,e){try{const i=Ie(l),r=he(n+":"+e.join(".")),u=Zt(r),f=new Uint8Array(i.length);for(let s=0;s<i.length;s++)f[s]=i[s]^u[s%u.length];const p=new TextDecoder().decode(f);return JSON.parse(p)}catch{return null}}function Ne(l){if(typeof l!="string"||!l.startsWith("0x"))return!1;const n=l.slice(2);return n.length<2||n.length%2!==0?!1:/^[0-9a-fA-F]+$/.test(n)}function Me(l,n,e){if(n.length===0){if(e.length===1&&typeof e[0]=="string"){const k=e[0].trim(),m=k.startsWith("_")||k.startsWith("~")||k.startsWith("@"),S=k.includes("."),B=/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(k);if(S||m||B){const A=k.split(".").filter(Boolean);return l.readPath(A)}}if(e.length===0)return l.createProxy([]);const s=l.normalizeArgs(e),h=l.postulate([],s);return h!==void 0?h:l.createProxy([])}const i=l.normalizeArgs(e),r=l.postulate(n,i),{scope:u,leaf:f}=l.splitPath(n),p=f?l.opKind(f):null;if(l.isThought(r)){const s=p?u:n;return l.createProxy(s)}return r!==void 0?r:l.createProxy(n)}function Te(l,n,e={}){const{path:i,expression:r}=n,u=ke(i,r);if(u)return{kind:"return",value:{define:u}};const f=Se(l,i,r);if(f)return{kind:"commit",instructions:[{path:f.scopeKey?f.scopeKey.split(".").filter(Boolean):[],op:"secret",value:r}]};const p=Ae(l,i,r);if(p)return{kind:"commit",instructions:[{path:p.scopeKey?p.scopeKey.split(".").filter(Boolean):[],op:"noise",value:r}]};const s=Be(l,i,r);if(s){const{scope:B}=C(i);return{kind:"commit",instructions:[{path:B,op:"ptr",value:ve(s.targetPath)}]}}const h=_e(l,i,r);if(h)return{kind:"commit",instructions:[{path:h.targetPath,op:"id",value:be(h.id)}]};const k=xe(l,i,r);if(k)return{kind:"commit",instructions:[{path:k.targetPath,op:"remove",value:"-"}]};const m=Pe(l,i,r);if(m){if(m.mode==="assign")return{kind:"commit",instructions:[{path:[...m.targetPath,m.name],op:"derive",value:{kind:"expr",source:m.expr}}]};if(!e.evaluateThunk)throw new Error('Non-serializable derivation: "=" thunk requires `evaluateThunk` or serializable DNA.');const B=e.evaluateThunk(m.thunk);return m.targetPath.length===0?{kind:"return",value:B}:{kind:"commit",instructions:[{path:m.targetPath,op:"derive",value:B}]}}const S=we(l,i,r);if(S){if(!e.readPath)return{kind:"commit",instructions:[{path:S.targetPath,op:"query",value:{paths:S.paths}}]};const B=S.paths.map(x=>e.readPath(x.split(".").filter(Boolean))),A=S.fn?S.fn(...B):B;return S.targetPath.length===0?{kind:"return",value:A}:{kind:"commit",instructions:[{path:S.targetPath,op:"query",value:A}]}}return{kind:"commit",instructions:[{path:i,op:"set",value:r}]}}const fe="+";function R(l){let n=2166136261;for(let e=0;e<l.length;e++)n^=l.charCodeAt(e),n=Math.imul(n,16777619);return("00000000"+(n>>>0).toString(16)).slice(-8)}class Xt{constructor(n){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=[],n!==void 0&&this.postulate([],n),this.rebuildIndex();const e=this.createProxy([]);return Object.setPrototypeOf(e,Xt.prototype),Object.assign(e,this),e}get shortTermMemory(){return this._shortTermMemory}isRemoveCall(n,e){if(n.length===0)return null;const{scope:i,leaf:r}=C(n);if(!r||this.opKind(r)!=="remove")return null;if(e==null)return{targetPath:i};if(typeof e=="string"){const u=e.split(".").filter(Boolean);return{targetPath:[...i,...u]}}return null}createProxy(n){const e=this,i=(...r)=>Me({createProxy:u=>e.createProxy(u),normalizeArgs:u=>e.normalizeArgs(u),readPath:u=>e.readPath(u),postulate:(u,f)=>e.postulate(u,f),opKind:u=>e.opKind(u),splitPath:C,isThought:me},n,r);return new Proxy(i,{get(r,u){if(typeof u=="symbol")return r[u];if(u in e){const p=e[u];return typeof p=="function"?p.bind(e):p}const f=[...n,String(u)];return e.createProxy(f)},apply(r,u,f){return Reflect.apply(r,void 0,f)}})}normalizeArgs(n){if(n.length!==0)return n.length===1?n[0]:n}opKind(n){return this.operators[n]?.kind??null}isSecretScopeCall(n,e){if(n.length===0)return null;const{scope:i,leaf:r}=C(n);return!r||this.opKind(r)!=="secret"||typeof e!="string"?null:{scopeKey:i.join(".")}}isNoiseScopeCall(n,e){if(n.length===0)return null;const{scope:i,leaf:r}=C(n);return!r||this.opKind(r)!=="noise"||typeof e!="string"?null:{scopeKey:i.join(".")}}isPointerCall(n,e){if(n.length===0)return null;const{leaf:i}=C(n);if(!i||this.opKind(i)!=="pointer"||typeof e!="string")return null;const r=e.trim().replace(/^\./,"");return r?{targetPath:r}:null}isIdentityCall(n,e){if(n.length===1&&this.opKind(n[0])==="identity")return typeof e!="string"?null:{id:Ht(e),targetPath:[]};const{scope:i,leaf:r}=C(n);return!r||this.opKind(r)!=="identity"||typeof e!="string"?null:{id:Ht(e),targetPath:i}}isEvalCall(n,e){if(n.length===0)return null;const{scope:i,leaf:r}=C(n);if(!r||this.opKind(r)!=="eval")return null;if(typeof e=="function")return{mode:"thunk",targetPath:i,thunk:e};if(Array.isArray(e)&&e.length>=2){const u=String(e[0]??"").trim(),f=String(e[1]??"").trim();return!u||!f?null:{mode:"assign",targetPath:i,name:u,expr:f}}return null}isQueryCall(n,e){if(n.length===0)return null;const{scope:i,leaf:r}=C(n);if(!r||this.opKind(r)!=="query")return null;let u=null,f;if(Array.isArray(e)&&e.length>0)Array.isArray(e[0])&&(e.length===1||typeof e[1]=="function")?(u=e[0],f=typeof e[1]=="function"?e[1]:void 0):u=e;else return null;if(!Array.isArray(u)||u.length===0)return null;const p=u.map(s=>String(s)).map(s=>s.trim()).filter(s=>s.length>0);return p.length===0?null:{targetPath:i,paths:p,fn:f}}isDefineOpCall(n,e){if(n.length!==1||n[0]!==fe||!Array.isArray(e)||e.length<2)return null;const r=String(e[0]??"").trim(),u=String(e[1]??"").trim();return!r||!u||r===fe?null:{op:r,kind:u}}commitThoughtOnly(n,e,i,r){const u=n.join("."),f=this.computeEffectiveSecret(n),p=JSON.stringify({path:u,operator:e,expression:i,value:r,effectiveSecret:f}),s=R(p),h=Date.now(),k={path:u,operator:e,expression:i,value:r,effectiveSecret:f,hash:s,timestamp:h};return this._shortTermMemory.push(k),this.rebuildIndex(),k}commitValueMapping(n,e,i=null){let r=e;const u=n.join("."),f=this.computeEffectiveSecret(n),p=this.resolveBranchScope(n);if(p&&p.length===0&&this.localSecrets[""]&&this.localSecrets[u],p&&p.length>0){const s=this.computeEffectiveSecret(p),h=n.slice(p.length),k=this.getBranchBlob(p);let m={};if(k&&s){const S=Jt(k,s,p);S&&typeof S=="object"&&(m=S)}if(h.length===0)(typeof m!="object"||m===null)&&(m={}),m.expression=e;else{let S=m;for(let B=0;B<h.length-1;B++){const A=h[B];(!S[A]||typeof S[A]!="object")&&(S[A]={}),S=S[A]}S[h[h.length-1]]=e}if(s){const S=Qt(m,s,p);this.setBranchBlob(p,S)}r=e}else if(f){const s=i!=="="&&i!=="?";N(e)||Lt(e)||!s?r=e:r=Qt(e,f,n)}else r=e;return this.commitThoughtOnly(n,i,e,r)}commitMapping(n,e=null){switch(n.op){case"set":return this.commitValueMapping(n.path,n.value,e);case"ptr":return this.commitValueMapping(n.path,n.value,"__");case"id":return this.commitValueMapping(n.path,n.value,"@");case"secret":{if(typeof n.value!="string")return;const i=n.path.join(".");return this.localSecrets[i]=n.value,this.commitThoughtOnly(n.path,"_","***","***")}default:return}}postulate(n,e,i=null){let r=n;const u=this.isDefineOpCall(r,e);if(u){this.operators[u.op]={kind:u.kind};return}const{leaf:f}=C(r),p=f?this.opKind(f):null;if(p===null||p==="secret"||p==="pointer"||p==="identity"){const B=Te(this.operators,{path:r,expression:e});if(B.kind==="commit"){const A=new Set(["set","secret","ptr","id"]);if(B.instructions.every(O=>A.has(O.op))){let O;for(const E of B.instructions){const M=this.commitMapping(E,i);M&&(O=M)}if(O)return O}}}const h=this.isEvalCall(r,e);if(h){if(h.mode==="thunk"){const A=h.thunk();return h.targetPath.length===0?A:this.postulate(h.targetPath,A,"=")}const B=[...h.targetPath,h.name];return this.postulate(B,h.expr,"=")}const k=this.isQueryCall(r,e);if(k){const B=k.paths.map(x=>this.readPath(x.split(".").filter(Boolean))),A=k.fn?k.fn(...B):B;return k.targetPath.length===0?A:this.postulate(k.targetPath,A,"?")}const m=this.isRemoveCall(r,e);if(m){this.removeSubtree(m.targetPath);return}const S=this.isNoiseScopeCall(r,e);if(S){this.localNoises[S.scopeKey]=e;const B=S.scopeKey?S.scopeKey.split(".").filter(Boolean):[];return this.commitThoughtOnly(B,"~","***","***")}return this.commitValueMapping(r,e,i)}removeSubtree(n){const e=n.join(".");for(const h of Object.keys(this.localSecrets)){if(e===""){delete this.localSecrets[h];continue}(h===e||h.startsWith(e+"."))&&delete this.localSecrets[h]}for(const h of Object.keys(this.localNoises)){if(e===""){delete this.localNoises[h];continue}(h===e||h.startsWith(e+"."))&&delete this.localNoises[h]}for(const h of Object.keys(this.encryptedBranches)){if(e===""){delete this.encryptedBranches[h];continue}if(h===e||h.startsWith(e+".")){delete this.encryptedBranches[h];continue}const k=h.split(".").filter(Boolean);if(!Gt(n,k)||n.length<=k.length)continue;const m=this.computeEffectiveSecret(k);if(!m)continue;const S=this.getBranchBlob(k);if(!S)continue;const B=Jt(S,m,k);if(!B||typeof B!="object")continue;const A=n.slice(k.length);let x=B;for(let O=0;O<A.length-1;O++){const E=A[O];if(!x||typeof x!="object"||!(E in x)){x=null;break}x=x[E]}if(x&&typeof x=="object"){delete x[A[A.length-1]];const O=Qt(B,m,k);this.setBranchBlob(k,O)}}const i=n.join("."),r=Date.now(),u=this.computeEffectiveSecret(n),f=JSON.stringify({path:i,operator:"-",expression:"-",value:"-",effectiveSecret:u}),p=R(f),s={path:i,operator:"-",expression:"-",value:"-",effectiveSecret:u,hash:p,timestamp:r};this._shortTermMemory.push(s),this.rebuildIndex()}computeEffectiveSecret(n){let e=null,i=null;this.localNoises[""]!==void 0&&(e="",i=this.localNoises[""]);for(let u=1;u<=n.length;u++){const f=n.slice(0,u).join(".");this.localNoises[f]!==void 0&&(e=f,i=this.localNoises[f])}let r="root";i?r=R("noise::"+i):this.localSecrets[""]&&(r=R(r+"::"+this.localSecrets[""])),e===null||e===""||e.split(".").filter(Boolean).length;for(let u=1;u<=n.length;u++){const f=n.slice(0,u).join(".");if(this.localSecrets[f]){if(e!==null&&e!==""){const p=e+".";if(!(f===e||f.startsWith(p)))continue}r=R(r+"::"+this.localSecrets[f])}}return r==="root"?"":r}rebuildIndex(){const n={};for(const e of this._shortTermMemory){const i=e.path,r=i.split(".").filter(Boolean),u=this.resolveBranchScope(r),f=u&&u.length>0&&Gt(r,u);if(e.operator==="-"){if(i===""){for(const s of Object.keys(n))delete n[s];continue}const p=i+".";for(const s of Object.keys(n))(s===i||s.startsWith(p))&&delete n[s];continue}f||(n[i]=e.value)}this.index=n}getIndex(n){return this.index[n.join(".")]}setIndex(n,e){this.index[n.join(".")]=e}resolveIndexPointerPath(n,e=8){let i=n;for(let r=0;r<e;r++){const u=this.getIndex(i);if(N(u)){i=u.__ptr.split(".").filter(Boolean);continue}let f=!1;for(let p=i.length-1;p>=0;p--){const s=i.slice(0,p),h=this.getIndex(s);if(!N(h))continue;const k=h.__ptr.split(".").filter(Boolean),m=i.slice(p);i=[...k,...m],f=!0;break}if(!f)return{path:i,raw:u}}return{path:i,raw:void 0}}setBranchBlob(n,e){const i=n.join(".");this.encryptedBranches[i]=e}getBranchBlob(n){const e=n.join(".");return this.encryptedBranches[e]}resolveBranchScope(n){let e=null;this.localSecrets[""]&&(e=[]);for(let i=1;i<=n.length;i++){const r=n.slice(0,i),u=r.join(".");this.localSecrets[u]&&(e=r)}return e}readPath(n){const e=this.resolveBranchScope(n);if(e&&e.length>0&&Gt(n,e)){if(n.length===e.length)return;const p=this.computeEffectiveSecret(e);if(!p)return null;const s=this.getBranchBlob(e);if(!s)return;const h=Jt(s,p,e);if(!h||typeof h!="object")return;const k=n.slice(e.length);let m=h;for(const S of k){if(!m||typeof m!="object")return;m=m[S]}return N(m)?this.readPath(m.__ptr.split(".").filter(Boolean)):(Lt(m),m)}const i=this.getIndex(n);if(N(i))return i;const r=this.resolveIndexPointerPath(n),u=r.raw;if(u===void 0)return r.path.length===n.length&&r.path.every((s,h)=>s===n[h])?void 0:this.readPath(r.path);if(N(u))return this.readPath(u.__ptr.split(".").filter(Boolean));if(Lt(u)||!Ne(u))return u;const f=this.computeEffectiveSecret(n);return f?Jt(u,f,n):null}}module.exports=Xt;
|
|
1
|
+
"use strict";function ve(f){return{__ptr:f}}function z(f){return!!f&&typeof f=="object"&&typeof f.__ptr=="string"&&f.__ptr.length>0}function me(f){return{__id:f}}function Yt(f){return!!f&&typeof f=="object"&&typeof f.__id=="string"&&f.__id.length>0}function be(f){return!!f&&typeof f=="object"&&typeof f.path=="string"&&typeof f.hash=="string"&&typeof f.timestamp=="number"}function E(f){return f.length===0?{scope:[],leaf:null}:{scope:f.slice(0,-1),leaf:f[f.length-1]}}function Qt(f,r){if(r.length>f.length)return!1;for(let e=0;e<r.length;e++)if(f[e]!==r[e])return!1;return!0}function Ut(f){const r=f.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: ${f}`);if(r.includes("--"))throw new Error(`Invalid username. "--" is not allowed. Got: ${f}`);return r}function T(f,r){return f[r]?.kind??null}function Se(f,r){if(f.length!==1||f[0]!=="+"||!Array.isArray(r)||r.length<2)return null;const n=String(r[0]??"").trim(),i=String(r[1]??"").trim();return!n||!i||n==="+"?null:{op:n,kind:i}}function ke(f,r,e){if(r.length===0)return null;const{scope:n,leaf:i}=E(r);return!i||T(f,i)!=="secret"||typeof e!="string"?null:{scopeKey:n.join(".")}}function Pe(f,r,e){if(r.length===0)return null;const{scope:n,leaf:i}=E(r);return!i||T(f,i)!=="noise"||typeof e!="string"?null:{scopeKey:n.join(".")}}function xe(f,r,e){if(r.length===0)return null;const{leaf:n}=E(r);if(!n||T(f,n)!=="pointer"||typeof e!="string")return null;const i=e.trim().replace(/^\./,"");return i?{targetPath:i}:null}function _e(f,r,e){if(r.length===1&&T(f,r[0])==="identity")return typeof e!="string"?null:{id:Ut(e),targetPath:[]};const{scope:n,leaf:i}=E(r);return!i||T(f,i)!=="identity"||typeof e!="string"?null:{id:Ut(e),targetPath:n}}function Ae(f,r,e){if(r.length===0)return null;const{scope:n,leaf:i}=E(r);if(!i||T(f,i)!=="eval")return null;if(typeof e=="function")return{mode:"thunk",targetPath:n,thunk:e};if(Array.isArray(e)&&e.length>=2){const o=String(e[0]??"").trim(),l=String(e[1]??"").trim();return!o||!l?null:{mode:"assign",targetPath:n,name:o,expr:l}}return null}function Be(f,r,e){if(r.length===0)return null;const{scope:n,leaf:i}=E(r);if(!i||T(f,i)!=="query")return null;let o=null,l;if(Array.isArray(e)&&e.length>0)Array.isArray(e[0])&&(e.length===1||typeof e[1]=="function")?(o=e[0],l=typeof e[1]=="function"?e[1]:void 0):o=e;else return null;if(!Array.isArray(o)||o.length===0)return null;const s=o.map(c=>String(c)).map(c=>c.trim()).filter(c=>c.length>0);return s.length===0?null:{targetPath:n,paths:s,fn:l}}function Fe(f,r,e){if(r.length===0)return null;const{scope:n,leaf:i}=E(r);if(!i||T(f,i)!=="remove")return null;if(e==null)return{targetPath:n};if(typeof e=="string"){const o=e.split(".").filter(Boolean);return{targetPath:[...n,...o]}}return null}var we=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ee(f){return f&&f.__esModule&&Object.prototype.hasOwnProperty.call(f,"default")?f.default:f}var Xt={exports:{}};var fe;function Ce(){return fe||(fe=1,(function(f){(function(){var r="input is invalid type",e="finalize already called",n=typeof window=="object",i=n?window:{};i.JS_SHA3_NO_WINDOW&&(n=!1);var o=!n&&typeof self=="object",l=!i.JS_SHA3_NO_NODE_JS&&typeof process=="object"&&process.versions&&process.versions.node;l?i=we:o&&(i=self);for(var s=!i.JS_SHA3_NO_COMMON_JS&&!0&&f.exports,c=!i.JS_SHA3_NO_ARRAY_BUFFER&&typeof ArrayBuffer<"u",a="0123456789abcdef".split(""),p=[31,7936,2031616,520093696],g=[4,1024,262144,67108864],v=[1,256,65536,16777216],x=[6,1536,393216,100663296],P=[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],B=[224,256,384,512],C=[128,256],O=["hex","buffer","arrayBuffer","array","digest"],I={128:168,256:136},W=i.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return Object.prototype.toString.call(t)==="[object Array]"}:Array.isArray,K=c&&(i.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW||!ArrayBuffer.isView)?function(t){return typeof t=="object"&&t.buffer&&t.buffer.constructor===ArrayBuffer}:ArrayBuffer.isView,M=function(t){var u=typeof t;if(u==="string")return[t,!0];if(u!=="object"||t===null)throw new Error(r);if(c&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!W(t)&&!K(t))throw new Error(r);return[t,!1]},ne=function(t){return M(t)[0].length===0},qt=function(t){for(var u=[],h=0;h<t.length;++h)u[h]=t[h];return u},ie=function(t,u,h){return function(d){return new F(t,u,t).update(d)[h]()}},oe=function(t,u,h){return function(d,y){return new F(t,u,y).update(d)[h]()}},le=function(t,u,h){return function(d,y,m,S){return N["cshake"+t].update(d,y,m,S)[h]()}},se=function(t,u,h){return function(d,y,m,S){return N["kmac"+t].update(d,y,m,S)[h]()}},J=function(t,u,h,d){for(var y=0;y<O.length;++y){var m=O[y];t[m]=u(h,d,m)}return t},ce=function(t,u){var h=ie(t,u,"hex");return h.create=function(){return new F(t,u,t)},h.update=function(d){return h.create().update(d)},J(h,ie,t,u)},pe=function(t,u){var h=oe(t,u,"hex");return h.create=function(d){return new F(t,u,d)},h.update=function(d,y){return h.create(y).update(d)},J(h,oe,t,u)},ge=function(t,u){var h=I[t],d=le(t,u,"hex");return d.create=function(y,m,S){return ne(m)&&ne(S)?N["shake"+t].create(y):new F(t,u,y).bytepad([m,S],h)},d.update=function(y,m,S,b){return d.create(m,S,b).update(y)},J(d,le,t,u)},ye=function(t,u){var h=I[t],d=se(t,u,"hex");return d.create=function(y,m,S){return new Zt(t,u,m).bytepad(["KMAC",S],h).bytepad([y],h)},d.update=function(y,m,S,b){return d.create(y,S,b).update(m)},J(d,se,t,u)},ae=[{name:"keccak",padding:v,bits:B,createMethod:ce},{name:"sha3",padding:x,bits:B,createMethod:ce},{name:"shake",padding:p,bits:C,createMethod:pe},{name:"cshake",padding:g,bits:C,createMethod:ge},{name:"kmac",padding:g,bits:C,createMethod:ye}],N={},D=[],j=0;j<ae.length;++j)for(var R=ae[j],H=R.bits,$=0;$<H.length;++$){var Gt=R.name+"_"+H[$];if(D.push(Gt),N[Gt]=R.createMethod(H[$],R.padding),R.name!=="sha3"){var ue=R.name+H[$];D.push(ue),N[ue]=N[Gt]}}function F(t,u,h){this.blocks=[],this.s=[],this.padding=u,this.outputBits=h,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=h>>5,this.extraBytes=(h&31)>>3;for(var d=0;d<50;++d)this.s[d]=0}F.prototype.update=function(t){if(this.finalized)throw new Error(e);var u=M(t);t=u[0];for(var h=u[1],d=this.blocks,y=this.byteCount,m=t.length,S=this.blockCount,b=0,w=this.s,k,A;b<m;){if(this.reset)for(this.reset=!1,d[0]=this.block,k=1;k<S+1;++k)d[k]=0;if(h)for(k=this.start;b<m&&k<y;++b)A=t.charCodeAt(b),A<128?d[k>>2]|=A<<P[k++&3]:A<2048?(d[k>>2]|=(192|A>>6)<<P[k++&3],d[k>>2]|=(128|A&63)<<P[k++&3]):A<55296||A>=57344?(d[k>>2]|=(224|A>>12)<<P[k++&3],d[k>>2]|=(128|A>>6&63)<<P[k++&3],d[k>>2]|=(128|A&63)<<P[k++&3]):(A=65536+((A&1023)<<10|t.charCodeAt(++b)&1023),d[k>>2]|=(240|A>>18)<<P[k++&3],d[k>>2]|=(128|A>>12&63)<<P[k++&3],d[k>>2]|=(128|A>>6&63)<<P[k++&3],d[k>>2]|=(128|A&63)<<P[k++&3]);else for(k=this.start;b<m&&k<y;++b)d[k>>2]|=t[b]<<P[k++&3];if(this.lastByteIndex=k,k>=y){for(this.start=k-y,this.block=d[S],k=0;k<S;++k)w[k]^=d[k];V(w),this.reset=!0}else this.start=k}return this},F.prototype.encode=function(t,u){var h=t&255,d=1,y=[h];for(t=t>>8,h=t&255;h>0;)y.unshift(h),t=t>>8,h=t&255,++d;return u?y.push(d):y.unshift(d),this.update(y),y.length},F.prototype.encodeString=function(t){var u=M(t);t=u[0];var h=u[1],d=0,y=t.length;if(h)for(var m=0;m<t.length;++m){var S=t.charCodeAt(m);S<128?d+=1:S<2048?d+=2:S<55296||S>=57344?d+=3:(S=65536+((S&1023)<<10|t.charCodeAt(++m)&1023),d+=4)}else d=y;return d+=this.encode(d*8),this.update(t),d},F.prototype.bytepad=function(t,u){for(var h=this.encode(u),d=0;d<t.length;++d)h+=this.encodeString(t[d]);var y=(u-h%u)%u,m=[];return m.length=y,this.update(m),this},F.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,u=this.lastByteIndex,h=this.blockCount,d=this.s;if(t[u>>2]|=this.padding[u&3],this.lastByteIndex===this.byteCount)for(t[0]=t[h],u=1;u<h+1;++u)t[u]=0;for(t[h-1]|=2147483648,u=0;u<h;++u)d[u]^=t[u];V(d)}},F.prototype.toString=F.prototype.hex=function(){this.finalize();for(var t=this.blockCount,u=this.s,h=this.outputBlocks,d=this.extraBytes,y=0,m=0,S="",b;m<h;){for(y=0;y<t&&m<h;++y,++m)b=u[y],S+=a[b>>4&15]+a[b&15]+a[b>>12&15]+a[b>>8&15]+a[b>>20&15]+a[b>>16&15]+a[b>>28&15]+a[b>>24&15];m%t===0&&(u=qt(u),V(u),y=0)}return d&&(b=u[y],S+=a[b>>4&15]+a[b&15],d>1&&(S+=a[b>>12&15]+a[b>>8&15]),d>2&&(S+=a[b>>20&15]+a[b>>16&15])),S},F.prototype.arrayBuffer=function(){this.finalize();var t=this.blockCount,u=this.s,h=this.outputBlocks,d=this.extraBytes,y=0,m=0,S=this.outputBits>>3,b;d?b=new ArrayBuffer(h+1<<2):b=new ArrayBuffer(S);for(var w=new Uint32Array(b);m<h;){for(y=0;y<t&&m<h;++y,++m)w[m]=u[y];m%t===0&&(u=qt(u),V(u))}return d&&(w[m]=u[y],b=b.slice(0,S)),b},F.prototype.buffer=F.prototype.arrayBuffer,F.prototype.digest=F.prototype.array=function(){this.finalize();for(var t=this.blockCount,u=this.s,h=this.outputBlocks,d=this.extraBytes,y=0,m=0,S=[],b,w;m<h;){for(y=0;y<t&&m<h;++y,++m)b=m<<2,w=u[y],S[b]=w&255,S[b+1]=w>>8&255,S[b+2]=w>>16&255,S[b+3]=w>>24&255;m%t===0&&(u=qt(u),V(u))}return d&&(b=m<<2,w=u[y],S[b]=w&255,d>1&&(S[b+1]=w>>8&255),d>2&&(S[b+2]=w>>16&255)),S};function Zt(t,u,h){F.call(this,t,u,h)}Zt.prototype=new F,Zt.prototype.finalize=function(){return this.encode(this.outputBits,!0),F.prototype.finalize.call(this)};var V=function(t){var u,h,d,y,m,S,b,w,k,A,U,q,G,Z,Y,Q,X,tt,et,rt,nt,it,ot,lt,st,ct,at,ut,ft,ht,dt,pt,gt,yt,vt,mt,bt,St,kt,Pt,xt,_t,At,Bt,Ft,wt,Et,Ct,Ot,It,Nt,jt,Tt,Kt,zt,Mt,Rt,Wt,Dt,$t,Vt,Lt,Jt;for(d=0;d<48;d+=2)y=t[0]^t[10]^t[20]^t[30]^t[40],m=t[1]^t[11]^t[21]^t[31]^t[41],S=t[2]^t[12]^t[22]^t[32]^t[42],b=t[3]^t[13]^t[23]^t[33]^t[43],w=t[4]^t[14]^t[24]^t[34]^t[44],k=t[5]^t[15]^t[25]^t[35]^t[45],A=t[6]^t[16]^t[26]^t[36]^t[46],U=t[7]^t[17]^t[27]^t[37]^t[47],q=t[8]^t[18]^t[28]^t[38]^t[48],G=t[9]^t[19]^t[29]^t[39]^t[49],u=q^(S<<1|b>>>31),h=G^(b<<1|S>>>31),t[0]^=u,t[1]^=h,t[10]^=u,t[11]^=h,t[20]^=u,t[21]^=h,t[30]^=u,t[31]^=h,t[40]^=u,t[41]^=h,u=y^(w<<1|k>>>31),h=m^(k<<1|w>>>31),t[2]^=u,t[3]^=h,t[12]^=u,t[13]^=h,t[22]^=u,t[23]^=h,t[32]^=u,t[33]^=h,t[42]^=u,t[43]^=h,u=S^(A<<1|U>>>31),h=b^(U<<1|A>>>31),t[4]^=u,t[5]^=h,t[14]^=u,t[15]^=h,t[24]^=u,t[25]^=h,t[34]^=u,t[35]^=h,t[44]^=u,t[45]^=h,u=w^(q<<1|G>>>31),h=k^(G<<1|q>>>31),t[6]^=u,t[7]^=h,t[16]^=u,t[17]^=h,t[26]^=u,t[27]^=h,t[36]^=u,t[37]^=h,t[46]^=u,t[47]^=h,u=A^(y<<1|m>>>31),h=U^(m<<1|y>>>31),t[8]^=u,t[9]^=h,t[18]^=u,t[19]^=h,t[28]^=u,t[29]^=h,t[38]^=u,t[39]^=h,t[48]^=u,t[49]^=h,Z=t[0],Y=t[1],wt=t[11]<<4|t[10]>>>28,Et=t[10]<<4|t[11]>>>28,ut=t[20]<<3|t[21]>>>29,ft=t[21]<<3|t[20]>>>29,$t=t[31]<<9|t[30]>>>23,Vt=t[30]<<9|t[31]>>>23,_t=t[40]<<18|t[41]>>>14,At=t[41]<<18|t[40]>>>14,yt=t[2]<<1|t[3]>>>31,vt=t[3]<<1|t[2]>>>31,Q=t[13]<<12|t[12]>>>20,X=t[12]<<12|t[13]>>>20,Ct=t[22]<<10|t[23]>>>22,Ot=t[23]<<10|t[22]>>>22,ht=t[33]<<13|t[32]>>>19,dt=t[32]<<13|t[33]>>>19,Lt=t[42]<<2|t[43]>>>30,Jt=t[43]<<2|t[42]>>>30,Kt=t[5]<<30|t[4]>>>2,zt=t[4]<<30|t[5]>>>2,mt=t[14]<<6|t[15]>>>26,bt=t[15]<<6|t[14]>>>26,tt=t[25]<<11|t[24]>>>21,et=t[24]<<11|t[25]>>>21,It=t[34]<<15|t[35]>>>17,Nt=t[35]<<15|t[34]>>>17,pt=t[45]<<29|t[44]>>>3,gt=t[44]<<29|t[45]>>>3,lt=t[6]<<28|t[7]>>>4,st=t[7]<<28|t[6]>>>4,Mt=t[17]<<23|t[16]>>>9,Rt=t[16]<<23|t[17]>>>9,St=t[26]<<25|t[27]>>>7,kt=t[27]<<25|t[26]>>>7,rt=t[36]<<21|t[37]>>>11,nt=t[37]<<21|t[36]>>>11,jt=t[47]<<24|t[46]>>>8,Tt=t[46]<<24|t[47]>>>8,Bt=t[8]<<27|t[9]>>>5,Ft=t[9]<<27|t[8]>>>5,ct=t[18]<<20|t[19]>>>12,at=t[19]<<20|t[18]>>>12,Wt=t[29]<<7|t[28]>>>25,Dt=t[28]<<7|t[29]>>>25,Pt=t[38]<<8|t[39]>>>24,xt=t[39]<<8|t[38]>>>24,it=t[48]<<14|t[49]>>>18,ot=t[49]<<14|t[48]>>>18,t[0]=Z^~Q&tt,t[1]=Y^~X&et,t[10]=lt^~ct&ut,t[11]=st^~at&ft,t[20]=yt^~mt&St,t[21]=vt^~bt&kt,t[30]=Bt^~wt&Ct,t[31]=Ft^~Et&Ot,t[40]=Kt^~Mt&Wt,t[41]=zt^~Rt&Dt,t[2]=Q^~tt&rt,t[3]=X^~et&nt,t[12]=ct^~ut&ht,t[13]=at^~ft&dt,t[22]=mt^~St&Pt,t[23]=bt^~kt&xt,t[32]=wt^~Ct&It,t[33]=Et^~Ot&Nt,t[42]=Mt^~Wt&$t,t[43]=Rt^~Dt&Vt,t[4]=tt^~rt&it,t[5]=et^~nt&ot,t[14]=ut^~ht&pt,t[15]=ft^~dt>,t[24]=St^~Pt&_t,t[25]=kt^~xt&At,t[34]=Ct^~It&jt,t[35]=Ot^~Nt&Tt,t[44]=Wt^~$t&Lt,t[45]=Dt^~Vt&Jt,t[6]=rt^~it&Z,t[7]=nt^~ot&Y,t[16]=ht^~pt<,t[17]=dt^~gt&st,t[26]=Pt^~_t&yt,t[27]=xt^~At&vt,t[36]=It^~jt&Bt,t[37]=Nt^~Tt&Ft,t[46]=$t^~Lt&Kt,t[47]=Vt^~Jt&zt,t[8]=it^~Z&Q,t[9]=ot^~Y&X,t[18]=pt^~lt&ct,t[19]=gt^~st&at,t[28]=_t^~yt&mt,t[29]=At^~vt&bt,t[38]=jt^~Bt&wt,t[39]=Tt^~Ft&Et,t[48]=Lt^~Kt&Mt,t[49]=Jt^~zt&Rt,t[0]^=_[d],t[1]^=_[d+1]};if(s)f.exports=N;else for(j=0;j<D.length;++j)i[D[j]]=N[D[j]]})()})(Xt)),Xt.exports}var Oe=Ce();const Ie=Ee(Oe),{keccak256:de}=Ie;function ee(f){return new TextEncoder().encode(f)}function Ne(f){const r=f.startsWith("0x")?f.slice(2):f,e=new Uint8Array(r.length/2);for(let n=0;n<e.length;n++)e[n]=parseInt(r.substring(n*2,n*2+2),16);return e}function je(f){let r="";for(let e=0;e<f.length;e++)r+=f[e].toString(16).padStart(2,"0");return"0x"+r}function te(f,r,e){const n=JSON.stringify(f),i=ee(n),o=de(r+":"+e.join(".")),l=ee(o),s=new Uint8Array(i.length);for(let c=0;c<i.length;c++)s[c]=i[c]^l[c%l.length];return je(s)}function Ht(f,r,e){try{const n=Ne(f),i=de(r+":"+e.join(".")),o=ee(i),l=new Uint8Array(n.length);for(let c=0;c<n.length;c++)l[c]=n[c]^o[c%o.length];const s=new TextDecoder().decode(l);return JSON.parse(s)}catch{return null}}function Te(f){if(typeof f!="string"||!f.startsWith("0x"))return!1;const r=f.slice(2);return r.length<2||r.length%2!==0?!1:/^[0-9a-fA-F]+$/.test(r)}function Ke(f){const r=[];let e="",n=0,i=null;for(let l=0;l<f.length;l++){const s=f[l];if(i){e+=s,s===i&&(i=null);continue}if(s==='"'||s==="'"){i=s,e+=s;continue}if(s==="["){n++,e+=s;continue}if(s==="]"){n=Math.max(0,n-1),e+=s;continue}if(s==="."&&n===0){const c=e.trim();c&&r.push(c),e="";continue}e+=s}const o=e.trim();return o&&r.push(o),r}function ze(f,r,e){if(r.length===0){if(e.length===1&&typeof e[0]=="string"){const p=e[0].trim(),g=p.startsWith("_")||p.startsWith("~")||p.startsWith("@"),v=p.includes("."),x=/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(p);if(v||g||x){const P=Ke(p);return f.readPath(P)}}if(e.length===0)return f.createProxy([]);const c=f.normalizeArgs(e),a=f.postulate([],c);return a!==void 0?a:f.createProxy([])}const n=f.normalizeArgs(e),i=f.postulate(r,n),{scope:o,leaf:l}=f.splitPath(r),s=l?f.opKind(l):null;if(f.isThought(i)){const c=s?o:r;return f.createProxy(c)}return i!==void 0?i:f.createProxy(r)}function Me(f,r,e={}){const{path:n,expression:i}=r,o=Se(n,i);if(o)return{kind:"return",value:{define:o}};const l=ke(f,n,i);if(l)return{kind:"commit",instructions:[{path:l.scopeKey?l.scopeKey.split(".").filter(Boolean):[],op:"secret",value:i}]};const s=Pe(f,n,i);if(s)return{kind:"commit",instructions:[{path:s.scopeKey?s.scopeKey.split(".").filter(Boolean):[],op:"noise",value:i}]};const c=xe(f,n,i);if(c){const{scope:x}=E(n);return{kind:"commit",instructions:[{path:x,op:"ptr",value:ve(c.targetPath)}]}}const a=_e(f,n,i);if(a)return{kind:"commit",instructions:[{path:a.targetPath,op:"id",value:me(a.id)}]};const p=Fe(f,n,i);if(p)return{kind:"commit",instructions:[{path:p.targetPath,op:"remove",value:"-"}]};const g=Ae(f,n,i);if(g){if(g.mode==="assign")return{kind:"commit",instructions:[{path:[...g.targetPath,g.name],op:"derive",value:{kind:"expr",source:g.expr}}]};if(!e.evaluateThunk)throw new Error('Non-serializable derivation: "=" thunk requires `evaluateThunk` or serializable DNA.');const x=e.evaluateThunk(g.thunk);return g.targetPath.length===0?{kind:"return",value:x}:{kind:"commit",instructions:[{path:g.targetPath,op:"derive",value:x}]}}const v=Be(f,n,i);if(v){if(!e.readPath)return{kind:"commit",instructions:[{path:v.targetPath,op:"query",value:{paths:v.paths}}]};const x=v.paths.map(_=>e.readPath(_.split(".").filter(Boolean))),P=v.fn?v.fn(...x):x;return v.targetPath.length===0?{kind:"return",value:P}:{kind:"commit",instructions:[{path:v.targetPath,op:"query",value:P}]}}return{kind:"commit",instructions:[{path:n,op:"set",value:i}]}}const he="+";function L(f){let r=2166136261;for(let e=0;e<f.length;e++)r^=f.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}inspect(r){const e=r?.last;return{thoughts:typeof e=="number"&&Number.isFinite(e)&&e>0?this._shortTermMemory.slice(-Math.floor(e)):this._shortTermMemory.slice(),index:{...this.index},encryptedScopes:Object.keys(this.encryptedBranches),secretScopes:Object.keys(this.localSecrets),noiseScopes:Object.keys(this.localNoises)}}isRemoveCall(r,e){if(r.length===0)return null;const{scope:n,leaf:i}=E(r);if(!i||this.opKind(i)!=="remove")return null;if(e==null)return{targetPath:n};if(typeof e=="string"){const o=e.split(".").filter(Boolean);return{targetPath:[...n,...o]}}return null}createProxy(r){const e=this,n=(...i)=>ze({createProxy:o=>e.createProxy(o),normalizeArgs:o=>e.normalizeArgs(o),readPath:o=>e.readPath(o),postulate:(o,l)=>e.postulate(o,l),opKind:o=>e.opKind(o),splitPath:E,isThought:be},r,i);return new Proxy(n,{get(i,o){if(typeof o=="symbol")return i[o];if(o in e){const s=e[o];return typeof s=="function"?s.bind(e):s}const l=[...r,String(o)];return e.createProxy(l)},apply(i,o,l){return Reflect.apply(i,void 0,l)}})}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:n,leaf:i}=E(r);return!i||this.opKind(i)!=="secret"||typeof e!="string"?null:{scopeKey:n.join(".")}}isNoiseScopeCall(r,e){if(r.length===0)return null;const{scope:n,leaf:i}=E(r);return!i||this.opKind(i)!=="noise"||typeof e!="string"?null:{scopeKey:n.join(".")}}isPointerCall(r,e){if(r.length===0)return null;const{leaf:n}=E(r);if(!n||this.opKind(n)!=="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:Ut(e),targetPath:[]};const{scope:n,leaf:i}=E(r);return!i||this.opKind(i)!=="identity"||typeof e!="string"?null:{id:Ut(e),targetPath:n}}isEvalCall(r,e){if(r.length===0)return null;const{scope:n,leaf:i}=E(r);if(!i||this.opKind(i)!=="eval")return null;if(typeof e=="function")return{mode:"thunk",targetPath:n,thunk:e};if(Array.isArray(e)&&e.length>=2){const o=String(e[0]??"").trim(),l=String(e[1]??"").trim();return!o||!l?null:{mode:"assign",targetPath:n,name:o,expr:l}}return null}isQueryCall(r,e){if(r.length===0)return null;const{scope:n,leaf:i}=E(r);if(!i||this.opKind(i)!=="query")return null;let o=null,l;if(Array.isArray(e)&&e.length>0)Array.isArray(e[0])&&(e.length===1||typeof e[1]=="function")?(o=e[0],l=typeof e[1]=="function"?e[1]:void 0):o=e;else return null;if(!Array.isArray(o)||o.length===0)return null;const s=o.map(c=>String(c)).map(c=>c.trim()).filter(c=>c.length>0);return s.length===0?null:{targetPath:n,paths:s,fn:l}}isDefineOpCall(r,e){if(r.length!==1||r[0]!==he||!Array.isArray(e)||e.length<2)return null;const i=String(e[0]??"").trim(),o=String(e[1]??"").trim();return!i||!o||i===he?null:{op:i,kind:o}}commitThoughtOnly(r,e,n,i){const o=r.join("."),l=this.computeEffectiveSecret(r),s=JSON.stringify({path:o,operator:e,expression:n,value:i,effectiveSecret:l}),c=L(s),a=Date.now(),p={path:o,operator:e,expression:n,value:i,effectiveSecret:l,hash:c,timestamp:a};return this._shortTermMemory.push(p),this.rebuildIndex(),p}commitValueMapping(r,e,n=null){let i=e;const o=r.join("."),l=this.computeEffectiveSecret(r),s=this.resolveBranchScope(r);if(s&&s.length===0&&this.localSecrets[""]&&this.localSecrets[o],s&&s.length>0){const c=this.computeEffectiveSecret(s),a=r.slice(s.length),p=this.getBranchBlob(s);let g={};if(p&&c){const v=Ht(p,c,s);v&&typeof v=="object"&&(g=v)}if(a.length===0)(typeof g!="object"||g===null)&&(g={}),g.expression=e;else{let v=g;for(let x=0;x<a.length-1;x++){const P=a[x];(!v[P]||typeof v[P]!="object")&&(v[P]={}),v=v[P]}v[a[a.length-1]]=e}if(c){const v=te(g,c,s);this.setBranchBlob(s,v)}i=e}else if(l){const c=n!=="="&&n!=="?";z(e)||Yt(e)||!c?i=e:i=te(e,l,r)}else i=e;return this.commitThoughtOnly(r,n,e,i)}commitMapping(r,e=null){switch(r.op){case"set":return this.commitValueMapping(r.path,r.value,e);case"ptr":return this.commitValueMapping(r.path,r.value,"__");case"id":return this.commitValueMapping(r.path,r.value,"@");case"secret":{if(typeof r.value!="string")return;const n=r.path.join(".");return this.localSecrets[n]=r.value,this.commitThoughtOnly(r.path,"_","***","***")}default:return}}tryResolveEvalToken(r,e){const n=c=>{if(typeof c=="number"&&Number.isFinite(c))return c;if(typeof c=="string"){const a=Number(c);if(Number.isFinite(a))return a}return null};if(r.startsWith("__ptr.")){const c=this.getIndex(e);if(!z(c))return{ok:!1};const a=r.slice(6).split(".").filter(Boolean),p=[...c.__ptr.split(".").filter(Boolean),...a],g=this.readPath(p),v=n(g);return v===null?{ok:!1}:{ok:!0,value:v}}const i=r.split(".").filter(Boolean),o=[...e,...i];let l=this.readPath(o);l==null&&(l=this.readPath(i));const s=n(l);return s===null?{ok:!1}:{ok:!0,value:s}}tryEvaluateAssignExpression(r,e){const n=String(e??"").trim();if(!n)return{ok:!1};if(/['"`]/.test(n))return{ok:!1};if(!/^[\w.\s+\-*/%()[\]<>!=&|]+$/.test(n))return{ok:!1};const i=String.raw`[A-Za-z_][A-Za-z0-9_]*(?:\[(?:"[^"]*"|'[^']*'|[^\]]+)\])*`,o=new RegExp(String.raw`__ptr(?:\.${i})*|${i}(?:\.${i})*`,"g"),l={true:!0,false:!1,null:null,undefined:void 0,NaN:NaN,Infinity:1/0},s=[],c=new Map;let a=!1;const p=n.replace(o,g=>{let v=c.get(g);if(v===void 0)if(Object.prototype.hasOwnProperty.call(l,g))v=s.length,s.push(l[g]),c.set(g,v);else{const x=this.tryResolveEvalToken(g,r);if(!x.ok)return a=!0,g;v=s.length,s.push(x.value),c.set(g,v)}return`__v[${v}]`});if(a)return{ok:!1};if(!/^[\s\d+\-*/%().<>=!&|\[\]_v]+$/.test(p))return{ok:!1};try{const g=Function("__v",`"use strict"; return (${p});`)(s);if(typeof g=="number"&&Number.isFinite(g))return{ok:!0,value:g};if(typeof g=="boolean")return{ok:!0,value:g}}catch{return{ok:!1}}return{ok:!1}}postulate(r,e,n=null){let i=r;const o=this.isDefineOpCall(i,e);if(o){this.operators[o.op]={kind:o.kind};return}const{leaf:l}=E(i),s=l?this.opKind(l):null;if(s===null||s==="secret"||s==="pointer"||s==="identity"){const x=Me(this.operators,{path:i,expression:e});if(x.kind==="commit"){const P=new Set(["set","secret","ptr","id"]);if(x.instructions.every(B=>P.has(B.op))){let B;for(const C of x.instructions){const O=this.commitMapping(C,n);O&&(B=O)}if(B)return B}}}const a=this.isEvalCall(i,e);if(a){if(a.mode==="thunk"){const B=a.thunk();return a.targetPath.length===0?B:this.postulate(a.targetPath,B,"=")}if(this.pathContainsIterator(a.targetPath)){const B=this.collectIteratorIndices(a.targetPath);let C;for(const O of B){const I=this.normalizeSelectorPath(this.substituteIteratorInPath(a.targetPath,O)),W=this.normalizeSelectorPath([...I,a.name]),K=this.substituteIteratorInExpression(a.expr,O),M=this.tryEvaluateAssignExpression(I,K);C=this.postulate(W,M.ok?M.value:K,"=")}return C}if(this.pathContainsFilterSelector(a.targetPath)){const B=this.collectFilteredScopes(a.targetPath);let C;for(const O of B){const I=this.normalizeSelectorPath(O),W=this.normalizeSelectorPath([...I,a.name]),K=this.tryEvaluateAssignExpression(I,a.expr);C=this.postulate(W,K.ok?K.value:a.expr,"=")}return C}const x=this.normalizeSelectorPath([...a.targetPath,a.name]),P=this.normalizeSelectorPath(a.targetPath),_=this.tryEvaluateAssignExpression(P,a.expr);return _.ok?this.postulate(x,_.value,"="):this.postulate(x,a.expr,"=")}const p=this.isQueryCall(i,e);if(p){const x=p.paths.map(_=>this.readPath(_.split(".").filter(Boolean))),P=p.fn?p.fn(...x):x;return p.targetPath.length===0?P:this.postulate(p.targetPath,P,"?")}const g=this.isRemoveCall(i,e);if(g){this.removeSubtree(g.targetPath);return}const v=this.isNoiseScopeCall(i,e);if(v){this.localNoises[v.scopeKey]=e;const x=v.scopeKey?v.scopeKey.split(".").filter(Boolean):[];return this.commitThoughtOnly(x,"~","***","***")}return this.commitValueMapping(i,e,n)}removeSubtree(r){const e=r.join(".");for(const a of Object.keys(this.localSecrets)){if(e===""){delete this.localSecrets[a];continue}(a===e||a.startsWith(e+"."))&&delete this.localSecrets[a]}for(const a of Object.keys(this.localNoises)){if(e===""){delete this.localNoises[a];continue}(a===e||a.startsWith(e+"."))&&delete this.localNoises[a]}for(const a of Object.keys(this.encryptedBranches)){if(e===""){delete this.encryptedBranches[a];continue}if(a===e||a.startsWith(e+".")){delete this.encryptedBranches[a];continue}const p=a.split(".").filter(Boolean);if(!Qt(r,p)||r.length<=p.length)continue;const g=this.computeEffectiveSecret(p);if(!g)continue;const v=this.getBranchBlob(p);if(!v)continue;const x=Ht(v,g,p);if(!x||typeof x!="object")continue;const P=r.slice(p.length);let _=x;for(let B=0;B<P.length-1;B++){const C=P[B];if(!_||typeof _!="object"||!(C in _)){_=null;break}_=_[C]}if(_&&typeof _=="object"){delete _[P[P.length-1]];const B=te(x,g,p);this.setBranchBlob(p,B)}}const n=r.join("."),i=Date.now(),o=this.computeEffectiveSecret(r),l=JSON.stringify({path:n,operator:"-",expression:"-",value:"-",effectiveSecret:o}),s=L(l),c={path:n,operator:"-",expression:"-",value:"-",effectiveSecret:o,hash:s,timestamp:i};this._shortTermMemory.push(c),this.rebuildIndex()}computeEffectiveSecret(r){let e=null,n=null;this.localNoises[""]!==void 0&&(e="",n=this.localNoises[""]);for(let o=1;o<=r.length;o++){const l=r.slice(0,o).join(".");this.localNoises[l]!==void 0&&(e=l,n=this.localNoises[l])}let i="root";n?i=L("noise::"+n):this.localSecrets[""]&&(i=L(i+"::"+this.localSecrets[""])),e===null||e===""||e.split(".").filter(Boolean).length;for(let o=1;o<=r.length;o++){const l=r.slice(0,o).join(".");if(this.localSecrets[l]){if(e!==null&&e!==""){const s=e+".";if(!(l===e||l.startsWith(s)))continue}i=L(i+"::"+this.localSecrets[l])}}return i==="root"?"":i}rebuildIndex(){const r={};for(const e of this._shortTermMemory){const n=e.path,i=n.split(".").filter(Boolean),o=this.resolveBranchScope(i),l=o&&o.length>0&&Qt(i,o);if(e.operator==="-"){if(n===""){for(const c of Object.keys(r))delete r[c];continue}const s=n+".";for(const c of Object.keys(r))(c===n||c.startsWith(s))&&delete r[c];continue}l||(r[n]=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 n=r;for(let i=0;i<e;i++){const o=this.getIndex(n);if(z(o)){n=o.__ptr.split(".").filter(Boolean);continue}let l=!1;for(let s=n.length-1;s>=0;s--){const c=n.slice(0,s),a=this.getIndex(c);if(!z(a))continue;const p=a.__ptr.split(".").filter(Boolean),g=n.slice(s);n=[...p,...g],l=!0;break}if(!l)return{path:n,raw:o}}return{path:n,raw:void 0}}setBranchBlob(r,e){const n=r.join(".");this.encryptedBranches[n]=e}getBranchBlob(r){const e=r.join(".");return this.encryptedBranches[e]}resolveBranchScope(r){let e=null;this.localSecrets[""]&&(e=[]);for(let n=1;n<=r.length;n++){const i=r.slice(0,n),o=i.join(".");this.localSecrets[o]&&(e=i)}return e}normalizeSelectorPath(r){const e=[];for(const n of r){const i=String(n).trim();if(!i)continue;const o=i.indexOf("[");if(o===-1){e.push(i);continue}const l=i.slice(0,o).trim(),s=i.slice(o);l&&e.push(l);const c=Array.from(s.matchAll(/\[([^\]]*)\]/g));if(c.map(p=>p[0]).join("")!==s){e.push(s);continue}for(const p of c){let g=(p[1]??"").trim();(g.startsWith('"')&&g.endsWith('"')||g.startsWith("'")&&g.endsWith("'"))&&(g=g.slice(1,-1)),g&&e.push(g)}}return e}pathContainsIterator(r){return r.some(e=>e.includes("[i]"))}substituteIteratorInPath(r,e){return r.map(n=>n.split("[i]").join(`[${e}]`))}substituteIteratorInExpression(r,e){return String(r??"").split("[i]").join(`[${e}]`)}collectIteratorIndices(r){const e=r.findIndex(o=>o.includes("[i]"));if(e===-1)return[];const n=[];for(let o=0;o<=e;o++){const l=r[o];if(o===e){const s=l.split("[i]").join("").trim();s&&n.push(s)}else n.push(l)}const i=new Set;for(const o of Object.keys(this.index)){const l=o.split(".").filter(Boolean);if(l.length<=n.length)continue;let s=!0;for(let c=0;c<n.length;c++)if(l[c]!==n[c]){s=!1;break}s&&i.add(l[n.length])}return Array.from(i).sort((o,l)=>{const s=Number(o),c=Number(l),a=Number.isFinite(s),p=Number.isFinite(c);return a&&p?s-c:a?-1:p?1:o.localeCompare(l)})}parseFilterExpression(r){const n=String(r??"").trim().match(/^(.+?)\s*(>=|<=|==|!=|>|<)\s*(.+)$/);if(!n)return null;const i=n[1].trim(),o=n[2],l=n[3].trim();return!i||!l?null:{left:i,op:o,right:l}}parseLogicalFilterExpression(r){const e=String(r??"").trim();if(!e)return null;const n=e.split(/\s*(&&|\|\|)\s*/).filter(l=>l.length>0);if(n.length===0)return null;const i=[],o=[];for(let l=0;l<n.length;l++)if(l%2===0){const s=this.parseFilterExpression(n[l]);if(!s)return null;i.push(s)}else{const s=n[l];if(s!=="&&"&&s!=="||")return null;o.push(s)}return i.length===0||o.length!==Math.max(0,i.length-1)?null:{clauses:i,ops:o}}compareValues(r,e,n){switch(e){case">":return r>n;case"<":return r<n;case">=":return r>=n;case"<=":return r<=n;case"==":return r==n;case"!=":return r!=n;default:return!1}}parseLiteralOrPath(r){const e=r.trim();if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return{kind:"literal",value:e.slice(1,-1)};if(e==="true")return{kind:"literal",value:!0};if(e==="false")return{kind:"literal",value:!1};if(e==="null")return{kind:"literal",value:null};const n=Number(e);return Number.isFinite(n)?{kind:"literal",value:n}:{kind:"path",parts:this.normalizeSelectorPath(e.split(".").filter(Boolean))}}resolveRelativeFirst(r,e){const n=this.readPath([...r,...e]);return n??this.readPath(e)}evaluateFilterClauseForScope(r,e){const n=this.normalizeSelectorPath(e.left.split(".").filter(Boolean)),i=this.resolveRelativeFirst(r,n);if(i==null)return!1;const o=this.parseLiteralOrPath(e.right),l=o.kind==="literal"?o.value:this.resolveRelativeFirst(r,o.parts);return l==null?!1:this.compareValues(i,e.op,l)}evaluateLogicalFilterForScope(r,e){const n=this.parseLogicalFilterExpression(e);if(!n)return!1;let i=this.evaluateFilterClauseForScope(r,n.clauses[0]);for(let o=1;o<n.clauses.length;o++){const l=this.evaluateFilterClauseForScope(r,n.clauses[o]);i=n.ops[o-1]==="&&"?i&&l:i||l}return i}collectChildrenForPrefix(r){const e=new Set;for(const n of Object.keys(this.index)){const i=n.split(".").filter(Boolean);if(i.length<=r.length)continue;let o=!0;for(let l=0;l<r.length;l++)if(i[l]!==r[l]){o=!1;break}o&&e.add(i[r.length])}return Array.from(e)}parseSelectorSegment(r){const e=String(r??"").trim(),n=e.indexOf("["),i=e.lastIndexOf("]");if(n<=0||i<=n||i!==e.length-1)return null;const o=e.slice(0,n).trim(),l=e.slice(n+1,i).trim();return!o||!l?null:{base:o,selector:l}}parseSelectorKeys(r){const e=r.trim();if(e.startsWith("[")&&e.endsWith("]")){const i=e.slice(1,-1).trim();return i?i.split(",").map(l=>l.trim()).filter(Boolean).map(l=>l.startsWith('"')&&l.endsWith('"')||l.startsWith("'")&&l.endsWith("'")?l.slice(1,-1):l):[]}const n=e.match(/^(-?\d+)\s*\.\.\s*(-?\d+)$/);if(n){const i=Number(n[1]),o=Number(n[2]);if(!Number.isFinite(i)||!Number.isFinite(o))return null;const l=i<=o?1:-1,s=[];if(Math.abs(o-i)>1e4)return null;for(let a=i;l>0?a<=o:a>=o;a+=l)s.push(String(a));return s}return null}parseTransformSelector(r){const n=r.trim().match(/^([A-Za-z_][A-Za-z0-9_]*)\s*=>\s*(.+)$/);if(!n)return null;const i=n[1].trim(),o=n[2].trim();return!i||!o?null:{varName:i,expr:o}}evaluateTransformPath(r){const e=r.findIndex(a=>{const p=this.parseSelectorSegment(a);return p?this.parseTransformSelector(p.selector)!==null:!1});if(e===-1)return;const n=this.parseSelectorSegment(r[e]);if(!n)return;const i=this.parseTransformSelector(n.selector);if(!i)return;const o=[...r.slice(0,e),n.base];if(r.slice(e+1).length>0)return;const s=this.collectChildrenForPrefix(o),c={};for(const a of s){const p=[...o,a],g=i.expr.replace(new RegExp(String.raw`\b${i.varName}\.`,"g"),""),v=this.tryEvaluateAssignExpression(p,g);v.ok&&(c[a]=v.value)}return c}evaluateSelectionPath(r){const e=r.findIndex(c=>this.parseSelectorSegment(c)!==null);if(e===-1)return;const n=this.parseSelectorSegment(r[e]);if(!n)return;const i=this.parseSelectorKeys(n.selector);if(i===null)return;const o=[...r.slice(0,e),n.base],l=r.slice(e+1),s={};for(const c of i){const a=[...o,c],p=l.length===0?this.buildPublicSubtree(a):this.readPath([...a,...l]);p!==void 0&&(s[c]=p)}return s}buildPublicSubtree(r){const e=r.join("."),n={};let i=!1;for(const[o,l]of Object.entries(this.index)){if(o===e)return l;if(!o.startsWith(e+"."))continue;const s=o.slice(e.length+1).split(".").filter(Boolean);let c=n;for(let a=0;a<s.length-1;a++){const p=s[a];(!c[p]||typeof c[p]!="object")&&(c[p]={}),c=c[p]}c[s[s.length-1]]=l,i=!0}return i?n:void 0}evaluateFilterPath(r){const e=r.findIndex(c=>this.parseLogicalFilterExpression(c)!==null);if(e===-1)return;const n=r[e],i=r.slice(0,e),o=r.slice(e+1);if(i.length===0)return;const l=this.collectChildrenForPrefix(i),s={};for(const c of l){const a=[...i,c];this.evaluateLogicalFilterForScope(a,n)&&(o.length===0?s[c]=this.buildPublicSubtree(a):s[c]=this.readPath([...a,...o]))}return s}pathContainsFilterSelector(r){return r.some(e=>{const n=this.parseSelectorSegment(e);return n?this.parseLogicalFilterExpression(n.selector)!==null:!1})}collectFilteredScopes(r){const e=r.findIndex(c=>{const a=this.parseSelectorSegment(c);return a?this.parseLogicalFilterExpression(a.selector)!==null:!1});if(e===-1)return[];const n=this.parseSelectorSegment(r[e]);if(!n)return[];const i=[...r.slice(0,e),n.base],o=r.slice(e+1),l=this.collectChildrenForPrefix(i),s=[];for(const c of l){const a=[...i,c];this.evaluateLogicalFilterForScope(a,n.selector)&&s.push([...a,...o])}return s}readPath(r){const e=this.evaluateTransformPath(r);if(e!==void 0)return e;const n=this.evaluateSelectionPath(r);if(n!==void 0)return n;r=this.normalizeSelectorPath(r);const i=this.evaluateFilterPath(r);if(i!==void 0)return i;const o=this.resolveBranchScope(r);if(o&&o.length>0&&Qt(r,o)){if(r.length===o.length)return;const p=this.computeEffectiveSecret(o);if(!p)return null;const g=this.getBranchBlob(o);if(!g)return;const v=Ht(g,p,o);if(!v||typeof v!="object")return;const x=r.slice(o.length);let P=v;for(const _ of x){if(!P||typeof P!="object")return;P=P[_]}return z(P)?this.readPath(P.__ptr.split(".").filter(Boolean)):(Yt(P),P)}const l=this.getIndex(r);if(z(l))return l;const s=this.resolveIndexPointerPath(r),c=s.raw;if(c===void 0)return s.path.length===r.length&&s.path.every((g,v)=>g===r[v])?void 0:this.readPath(s.path);if(z(c))return this.readPath(c.__ptr.split(".").filter(Boolean));if(Yt(c)||!Te(c))return c;const a=this.computeEffectiveSecret(r);return a?Ht(c,a,r):null}}module.exports=re;
|