this.me 3.0.26 → 3.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  import { ME } from './src/me.js';
2
2
  export { ME };
3
- export default ME;
package/dist/me.cjs ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var ce=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ae(E){return E&&E.__esModule&&Object.prototype.hasOwnProperty.call(E,"default")?E.default:E}var Ut={exports:{}};/**
2
+ * [js-sha3]{@link https://github.com/emn178/js-sha3}
3
+ *
4
+ * @version 0.9.3
5
+ * @author Chen, Yi-Cyuan [emn178@gmail.com]
6
+ * @copyright Chen, Yi-Cyuan 2015-2023
7
+ * @license MIT
8
+ */var te;function he(){return te||(te=1,(function(E){(function(){var i="input is invalid type",o="finalize already called",l=typeof window=="object",a=l?window:{};a.JS_SHA3_NO_WINDOW&&(l=!1);var y=!l&&typeof self=="object",b=!a.JS_SHA3_NO_NODE_JS&&typeof process=="object"&&process.versions&&process.versions.node;b?a=ce:y&&(a=self);for(var B=!a.JS_SHA3_NO_COMMON_JS&&!0&&E.exports,p=!a.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"],K={128:168,256:136},ee=a.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return Object.prototype.toString.call(t)==="[object Array]"}:Array.isArray,re=p&&(a.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW||!ArrayBuffer.isView)?function(t){return typeof t=="object"&&t.buffer&&t.buffer.constructor===ArrayBuffer}:ArrayBuffer.isView,Vt=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(!ee(t)&&!re(t))throw new Error(i);return[t,!1]},Gt=function(t){return Vt(t)[0].length===0},Jt=function(t){for(var e=[],r=0;r<t.length;++r)e[r]=t[r];return e},Yt=function(t,e,r){return function(n){return new g(t,e,t).update(n)[r]()}},qt=function(t,e,r){return function(n,c){return new g(t,e,c).update(n)[r]()}},$t=function(t,e,r){return function(n,c,h,u){return T["cshake"+t].update(n,c,h,u)[r]()}},Lt=function(t,e,r){return function(n,c,h,u){return T["kmac"+t].update(n,c,h,u)[r]()}},I=function(t,e,r,n){for(var c=0;c<A.length;++c){var h=A[c];t[h]=e(r,n,h)}return t},Xt=function(t,e){var r=Yt(t,e,"hex");return r.create=function(){return new g(t,e,t)},r.update=function(n){return r.create().update(n)},I(r,Yt,t,e)},ne=function(t,e){var r=qt(t,e,"hex");return r.create=function(n){return new g(t,e,n)},r.update=function(n,c){return r.create(c).update(n)},I(r,qt,t,e)},oe=function(t,e){var r=K[t],n=$t(t,e,"hex");return n.create=function(c,h,u){return Gt(h)&&Gt(u)?T["shake"+t].create(c):new g(t,e,c).bytepad([h,u],r)},n.update=function(c,h,u,f){return n.create(h,u,f).update(c)},I(n,$t,t,e)},ie=function(t,e){var r=K[t],n=Lt(t,e,"hex");return n.create=function(c,h,u){return new Wt(t,e,h).bytepad(["KMAC",u],r).bytepad([c],r)},n.update=function(c,h,u,f){return n.create(c,u,f).update(h)},I(n,Lt,t,e)},Zt=[{name:"keccak",padding:F,bits:j,createMethod:Xt},{name:"sha3",padding:w,bits:j,createMethod:Xt},{name:"shake",padding:P,bits:C,createMethod:ne},{name:"cshake",padding:k,bits:C,createMethod:oe},{name:"kmac",padding:k,bits:C,createMethod:ie}],T={},N=[],R=0;R<Zt.length;++R)for(var M=Zt[R],V=M.bits,D=0;D<V.length;++D){var zt=M.name+"_"+V[D];if(N.push(zt),T[zt]=M.createMethod(V[D],M.padding),M.name!=="sha3"){var Qt=M.name+V[D];N.push(Qt),T[Qt]=T[zt]}}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=Vt(t);t=e[0];for(var r=e[1],n=this.blocks,c=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<c;++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<c;++f)n[s>>2]|=t[f]<<v[s++&3];if(this.lastByteIndex=s,s>=c){for(this.start=s-c,this.block=n[u],s=0;s<u;++s)S[s]^=n[s];H(S),this.reset=!0}else this.start=s}return this},g.prototype.encode=function(t,e){var r=t&255,n=1,c=[r];for(t=t>>8,r=t&255;r>0;)c.unshift(r),t=t>>8,r=t&255,++n;return e?c.push(n):c.unshift(n),this.update(c),c.length},g.prototype.encodeString=function(t){var e=Vt(t);t=e[0];var r=e[1],n=0,c=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=c;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 c=(e-r%e)%e,h=[];return h.length=c,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];H(n)}},g.prototype.toString=g.prototype.hex=function(){this.finalize();for(var t=this.blockCount,e=this.s,r=this.outputBlocks,n=this.extraBytes,c=0,h=0,u="",f;h<r;){for(c=0;c<t&&h<r;++c,++h)f=e[c],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=Jt(e),H(e),c=0)}return n&&(f=e[c],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,c=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(c=0;c<t&&h<r;++c,++h)S[h]=e[c];h%t===0&&(e=Jt(e),H(e))}return n&&(S[h]=e[c],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,c=0,h=0,u=[],f,S;h<r;){for(c=0;c<t&&h<r;++c,++h)f=h<<2,S=e[c],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=Jt(e),H(e))}return n&&(f=h<<2,S=e[c],u[f]=S&255,n>1&&(u[f+1]=S>>8&255),n>2&&(u[f+2]=S>>16&255)),u};function Wt(t,e,r){g.call(this,t,e,r)}Wt.prototype=new g,Wt.prototype.finalize=function(){return this.encode(this.outputBits,!0),g.prototype.finalize.call(this)};var H=function(t){var e,r,n,c,h,u,f,S,s,x,J,z,W,U,m,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,Rt,Kt,Mt,Nt,Dt,Ht,It;for(n=0;n<48;n+=2)c=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],J=t[7]^t[17]^t[27]^t[37]^t[47],z=t[8]^t[18]^t[28]^t[38]^t[48],W=t[9]^t[19]^t[29]^t[39]^t[49],e=z^(u<<1|f>>>31),r=W^(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=c^(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|J>>>31),r=f^(J<<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^(z<<1|W>>>31),r=s^(W<<1|z>>>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^(c<<1|h>>>31),r=J^(h<<1|c>>>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,U=t[0],m=t[1],Bt=t[11]<<4|t[10]>>>28,kt=t[10]<<4|t[11]>>>28,ot=t[20]<<3|t[21]>>>29,it=t[21]<<3|t[20]>>>29,Nt=t[31]<<9|t[30]>>>23,Dt=t[30]<<9|t[31]>>>23,xt=t[40]<<18|t[41]>>>14,gt=t[41]<<18|t[40]>>>14,lt=t[2]<<1|t[3]>>>31,ut=t[3]<<1|t[2]>>>31,G=t[13]<<12|t[12]>>>20,Y=t[12]<<12|t[13]>>>20,At=t[22]<<10|t[23]>>>22,Ft=t[23]<<10|t[22]>>>22,ct=t[33]<<13|t[32]>>>19,at=t[32]<<13|t[33]>>>19,Ht=t[42]<<2|t[43]>>>30,It=t[43]<<2|t[42]>>>30,Ot=t[5]<<30|t[4]>>>2,Et=t[4]<<30|t[5]>>>2,st=t[14]<<6|t[15]>>>26,yt=t[15]<<6|t[14]>>>26,q=t[25]<<11|t[24]>>>21,$=t[24]<<11|t[25]>>>21,wt=t[34]<<15|t[35]>>>17,_t=t[35]<<15|t[34]>>>17,ht=t[45]<<29|t[44]>>>3,ft=t[44]<<29|t[45]>>>3,tt=t[6]<<28|t[7]>>>4,et=t[7]<<28|t[6]>>>4,Tt=t[17]<<23|t[16]>>>9,Rt=t[16]<<23|t[17]>>>9,dt=t[26]<<25|t[27]>>>7,bt=t[27]<<25|t[26]>>>7,L=t[36]<<21|t[37]>>>11,X=t[37]<<21|t[36]>>>11,jt=t[47]<<24|t[46]>>>8,Ct=t[46]<<24|t[47]>>>8,St=t[8]<<27|t[9]>>>5,Pt=t[9]<<27|t[8]>>>5,rt=t[18]<<20|t[19]>>>12,nt=t[19]<<20|t[18]>>>12,Kt=t[29]<<7|t[28]>>>25,Mt=t[28]<<7|t[29]>>>25,pt=t[38]<<8|t[39]>>>24,vt=t[39]<<8|t[38]>>>24,Z=t[48]<<14|t[49]>>>18,Q=t[49]<<14|t[48]>>>18,t[0]=U^~G&q,t[1]=m^~Y&$,t[10]=tt^~rt&ot,t[11]=et^~nt&it,t[20]=lt^~st&dt,t[21]=ut^~yt&bt,t[30]=St^~Bt&At,t[31]=Pt^~kt&Ft,t[40]=Ot^~Tt&Kt,t[41]=Et^~Rt&Mt,t[2]=G^~q&L,t[3]=Y^~$&X,t[12]=rt^~ot&ct,t[13]=nt^~it&at,t[22]=st^~dt&pt,t[23]=yt^~bt&vt,t[32]=Bt^~At&wt,t[33]=kt^~Ft&_t,t[42]=Tt^~Kt&Nt,t[43]=Rt^~Mt&Dt,t[4]=q^~L&Z,t[5]=$^~X&Q,t[14]=ot^~ct&ht,t[15]=it^~at&ft,t[24]=dt^~pt&xt,t[25]=bt^~vt&gt,t[34]=At^~wt&jt,t[35]=Ft^~_t&Ct,t[44]=Kt^~Nt&Ht,t[45]=Mt^~Dt&It,t[6]=L^~Z&U,t[7]=X^~Q&m,t[16]=ct^~ht&tt,t[17]=at^~ft&et,t[26]=pt^~xt&lt,t[27]=vt^~gt&ut,t[36]=wt^~jt&St,t[37]=_t^~Ct&Pt,t[46]=Nt^~Ht&Ot,t[47]=Dt^~It&Et,t[8]=Z^~U&G,t[9]=Q^~m&Y,t[18]=ht^~tt&rt,t[19]=ft^~et&nt,t[28]=xt^~lt&st,t[29]=gt^~ut&yt,t[38]=jt^~St&Bt,t[39]=Ct^~Pt&kt,t[48]=Ht^~Ot&Tt,t[49]=It^~Et&Rt,t[0]^=_[n],t[1]^=_[n+1]};if(B)E.exports=T;else for(R=0;R<N.length;++R)a[N[R]]=T[N[R]]})()})(Ut)),Ut.exports}var fe=he();const le=ae(fe),{keccak256:O}=le;class mt{constructor(i,o){this.payload={},this.declarations=[],this.secrets={},this.branchVersions={},this.username=i,this.secret=o,this.identityRoot="0x"+O(o),this.publicKey="0x"+O("public:"+o),this.identityHash="0x"+O(this.publicKey+this.username),this.secrets[""]=o;const l=this.createProxy([]);return Object.setPrototypeOf(l,mt.prototype),Object.assign(l,this),l}createProxy(i){const o=this,l=(...a)=>o.handleCall(i,a);return new Proxy(l,{get(a,y){if(typeof y=="symbol")return a[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(a,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 a=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+a+JSON.stringify(y));return this.declarations.push({key:a,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:a}=this.resolveSecretWithPath(i),y=a.join("."),b=O(l);if(a.length>0){let k={};const F=this.branchVersions[y]?.[b],w=this.getSubPayload(a);if(F){const A=this.decryptForPath(a,F);A&&typeof A=="object"&&(k=A)}else if(typeof w=="string"){const A=this.decryptForPath(a,w);A&&typeof A=="object"&&(k=A)}else w&&typeof w=="object"&&(k=w);const v=i.slice(a.length);let _=k;for(let A=0;A<v.length-1;A++){const K=v[A];(!_[K]||typeof _[K]!="object")&&(_[K]={}),_=_[K]}const j=v[v.length-1];_[j]=o;const C=this.encryptForPath(a,k);this.branchVersions[y]||(this.branchVersions[y]={}),this.branchVersions[y][b]=C,this.writeBranchBlob(a,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 a=i[i.length-1];l[a]=o}findNearestBranchAncestor(i){for(let o=i.length-1;o>=1;o--){const l=i.slice(0,o),a=l.join(".");if(this.branchVersions[a])return{path:l,secret:this.resolveSecret(l)}}return null}writeBranchBlob(i,o){let l=i,a=o;for(;;){const y=this.findNearestBranchAncestor(l);if(!y){this.setSubPayload(l,a);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]]=a;const _=this.encryptForPath(b,F);this.branchVersions[p]||(this.branchVersions[p]={}),this.branchVersions[p][d]=_,l=b,a=_}}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 a=this.decryptForPath(i,o);return a===null?o:a}if(typeof o!="object")return o;const l=Array.isArray(o)?[]:{};for(const a of Object.keys(o)){const y=[...i,a];l[a]=this.decryptTree(y,o[a])}return l}encryptForPath(i,o){const l=this.resolveSecret(i),a=JSON.stringify(o),y=new TextEncoder().encode(a),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 a=this.hexToBytes(o),y=O(l+":"+i.join(".")),b=this.asciiToBytes(y),B=new Uint8Array(a.length);for(let d=0;d<a.length;d++)B[d]=a[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 a=0;a<l.length;a++)l[a]=parseInt(o.substr(a*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("."),a=this.resolveSecret(o),y=O(a),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)}}}exports.ME=mt;
package/dist/me.es.d.ts CHANGED
@@ -1,6 +1,2 @@
1
1
  export * from './index'
2
2
  export {}
3
- import Me from './index'
4
- export default Me
5
- export * from './index'
6
- export {}
package/dist/me.es.js CHANGED
@@ -1,8 +1,8 @@
1
- var ae = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
2
- function ie(v) {
3
- return v && v.__esModule && Object.prototype.hasOwnProperty.call(v, "default") ? v.default : v;
1
+ var ce = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
2
+ function ae(E) {
3
+ return E && E.__esModule && Object.prototype.hasOwnProperty.call(E, "default") ? E.default : E;
4
4
  }
5
- var Pt = { exports: {} };
5
+ var Ut = { exports: {} };
6
6
  /**
7
7
  * [js-sha3]{@link https://github.com/emn178/js-sha3}
8
8
  *
@@ -12,14 +12,14 @@ var Pt = { exports: {} };
12
12
  * @license MIT
13
13
  */
14
14
  var Qt;
15
- function ue() {
16
- return Qt || (Qt = 1, (function(v) {
15
+ function he() {
16
+ return Qt || (Qt = 1, (function(E) {
17
17
  (function() {
18
- var y = "input is invalid type", R = "finalize already called", M = typeof window == "object", b = M ? window : {};
19
- b.JS_SHA3_NO_WINDOW && (M = !1);
20
- var F = !M && typeof self == "object", k = !b.JS_SHA3_NO_NODE_JS && typeof process == "object" && process.versions && process.versions.node;
21
- k ? b = ae : F && (b = self);
22
- for (var g = !b.JS_SHA3_NO_COMMON_JS && !0 && v.exports, w = !b.JS_SHA3_NO_ARRAY_BUFFER && typeof ArrayBuffer < "u", h = "0123456789abcdef".split(""), Dt = [31, 7936, 2031616, 520093696], N = [4, 1024, 262144, 67108864], x = [1, 256, 65536, 16777216], st = [6, 1536, 393216, 100663296], d = [0, 8, 16, 24], Tt = [
18
+ var i = "input is invalid type", o = "finalize already called", l = typeof window == "object", a = l ? window : {};
19
+ a.JS_SHA3_NO_WINDOW && (l = !1);
20
+ var y = !l && typeof self == "object", b = !a.JS_SHA3_NO_NODE_JS && typeof process == "object" && process.versions && process.versions.node;
21
+ b ? a = ce : y && (a = self);
22
+ for (var P = !a.JS_SHA3_NO_COMMON_JS && !0 && E.exports, p = !a.JS_SHA3_NO_ARRAY_BUFFER && typeof ArrayBuffer < "u", d = "0123456789abcdef".split(""), B = [31, 7936, 2031616, 520093696], k = [4, 1024, 262144, 67108864], F = [1, 256, 65536, 16777216], w = [6, 1536, 393216, 100663296], v = [0, 8, 16, 24], _ = [
23
23
  1,
24
24
  0,
25
25
  32898,
@@ -68,145 +68,145 @@ function ue() {
68
68
  0,
69
69
  2147516424,
70
70
  2147483648
71
- ], mt = [224, 256, 384, 512], Ht = [128, 256], Ut = ["hex", "buffer", "arrayBuffer", "array", "digest"], Wt = {
71
+ ], j = [224, 256, 384, 512], C = [128, 256], A = ["hex", "buffer", "arrayBuffer", "array", "digest"], K = {
72
72
  128: 168,
73
73
  256: 136
74
- }, te = b.JS_SHA3_NO_NODE_JS || !Array.isArray ? function(t) {
74
+ }, ee = a.JS_SHA3_NO_NODE_JS || !Array.isArray ? function(t) {
75
75
  return Object.prototype.toString.call(t) === "[object Array]";
76
- } : Array.isArray, ee = w && (b.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView) ? function(t) {
76
+ } : Array.isArray, re = p && (a.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView) ? function(t) {
77
77
  return typeof t == "object" && t.buffer && t.buffer.constructor === ArrayBuffer;
78
- } : ArrayBuffer.isView, Kt = function(t) {
78
+ } : ArrayBuffer.isView, Vt = function(t) {
79
79
  var e = typeof t;
80
80
  if (e === "string")
81
81
  return [t, !0];
82
82
  if (e !== "object" || t === null)
83
- throw new Error(y);
84
- if (w && t.constructor === ArrayBuffer)
83
+ throw new Error(i);
84
+ if (p && t.constructor === ArrayBuffer)
85
85
  return [new Uint8Array(t), !1];
86
- if (!te(t) && !ee(t))
87
- throw new Error(y);
86
+ if (!ee(t) && !re(t))
87
+ throw new Error(i);
88
88
  return [t, !1];
89
- }, Gt = function(t) {
90
- return Kt(t)[0].length === 0;
91
- }, zt = function(t) {
89
+ }, mt = function(t) {
90
+ return Vt(t)[0].length === 0;
91
+ }, Jt = function(t) {
92
92
  for (var e = [], r = 0; r < t.length; ++r)
93
93
  e[r] = t[r];
94
94
  return e;
95
- }, Yt = function(t, e, r) {
95
+ }, Gt = function(t, e, r) {
96
96
  return function(n) {
97
- return new l(t, e, t).update(n)[r]();
97
+ return new g(t, e, t).update(n)[r]();
98
98
  };
99
- }, Vt = function(t, e, r) {
100
- return function(n, o) {
101
- return new l(t, e, o).update(n)[r]();
99
+ }, Yt = function(t, e, r) {
100
+ return function(n, c) {
101
+ return new g(t, e, c).update(n)[r]();
102
102
  };
103
103
  }, qt = function(t, e, r) {
104
- return function(n, o, a, u) {
105
- return _["cshake" + t].update(n, o, a, u)[r]();
104
+ return function(n, c, h, u) {
105
+ return T["cshake" + t].update(n, c, h, u)[r]();
106
106
  };
107
- }, Lt = function(t, e, r) {
108
- return function(n, o, a, u) {
109
- return _["kmac" + t].update(n, o, a, u)[r]();
107
+ }, $t = function(t, e, r) {
108
+ return function(n, c, h, u) {
109
+ return T["kmac" + t].update(n, c, h, u)[r]();
110
110
  };
111
111
  }, I = function(t, e, r, n) {
112
- for (var o = 0; o < Ut.length; ++o) {
113
- var a = Ut[o];
114
- t[a] = e(r, n, a);
112
+ for (var c = 0; c < A.length; ++c) {
113
+ var h = A[c];
114
+ t[h] = e(r, n, h);
115
115
  }
116
116
  return t;
117
- }, Xt = function(t, e) {
118
- var r = Yt(t, e, "hex");
117
+ }, Lt = function(t, e) {
118
+ var r = Gt(t, e, "hex");
119
119
  return r.create = function() {
120
- return new l(t, e, t);
120
+ return new g(t, e, t);
121
121
  }, r.update = function(n) {
122
122
  return r.create().update(n);
123
- }, I(r, Yt, t, e);
124
- }, re = function(t, e) {
125
- var r = Vt(t, e, "hex");
126
- return r.create = function(n) {
127
- return new l(t, e, n);
128
- }, r.update = function(n, o) {
129
- return r.create(o).update(n);
130
- }, I(r, Vt, t, e);
123
+ }, I(r, Gt, t, e);
131
124
  }, ne = function(t, e) {
132
- var r = Wt[t], n = qt(t, e, "hex");
133
- return n.create = function(o, a, u) {
134
- return Gt(a) && Gt(u) ? _["shake" + t].create(o) : new l(t, e, o).bytepad([a, u], r);
135
- }, n.update = function(o, a, u, i) {
136
- return n.create(a, u, i).update(o);
137
- }, I(n, qt, t, e);
125
+ var r = Yt(t, e, "hex");
126
+ return r.create = function(n) {
127
+ return new g(t, e, n);
128
+ }, r.update = function(n, c) {
129
+ return r.create(c).update(n);
130
+ }, I(r, Yt, t, e);
138
131
  }, oe = function(t, e) {
139
- var r = Wt[t], n = Lt(t, e, "hex");
140
- return n.create = function(o, a, u) {
141
- return new jt(t, e, a).bytepad(["KMAC", u], r).bytepad([o], r);
142
- }, n.update = function(o, a, u, i) {
143
- return n.create(o, u, i).update(a);
144
- }, I(n, Lt, t, e);
145
- }, Zt = [
146
- { name: "keccak", padding: x, bits: mt, createMethod: Xt },
147
- { name: "sha3", padding: st, bits: mt, createMethod: Xt },
148
- { name: "shake", padding: Dt, bits: Ht, createMethod: re },
149
- { name: "cshake", padding: N, bits: Ht, createMethod: ne },
150
- { name: "kmac", padding: N, bits: Ht, createMethod: oe }
151
- ], _ = {}, B = [], A = 0; A < Zt.length; ++A)
152
- for (var S = Zt[A], D = S.bits, C = 0; C < D.length; ++C) {
153
- var Jt = S.name + "_" + D[C];
154
- if (B.push(Jt), _[Jt] = S.createMethod(D[C], S.padding), S.name !== "sha3") {
155
- var $t = S.name + D[C];
156
- B.push($t), _[$t] = _[Jt];
132
+ var r = K[t], n = qt(t, e, "hex");
133
+ return n.create = function(c, h, u) {
134
+ return mt(h) && mt(u) ? T["shake" + t].create(c) : new g(t, e, c).bytepad([h, u], r);
135
+ }, n.update = function(c, h, u, f) {
136
+ return n.create(h, u, f).update(c);
137
+ }, I(n, qt, t, e);
138
+ }, ie = function(t, e) {
139
+ var r = K[t], n = $t(t, e, "hex");
140
+ return n.create = function(c, h, u) {
141
+ return new Wt(t, e, h).bytepad(["KMAC", u], r).bytepad([c], r);
142
+ }, n.update = function(c, h, u, f) {
143
+ return n.create(c, u, f).update(h);
144
+ }, I(n, $t, t, e);
145
+ }, Xt = [
146
+ { name: "keccak", padding: F, bits: j, createMethod: Lt },
147
+ { name: "sha3", padding: w, bits: j, createMethod: Lt },
148
+ { name: "shake", padding: B, bits: C, createMethod: ne },
149
+ { name: "cshake", padding: k, bits: C, createMethod: oe },
150
+ { name: "kmac", padding: k, bits: C, createMethod: ie }
151
+ ], T = {}, M = [], R = 0; R < Xt.length; ++R)
152
+ for (var N = Xt[R], V = N.bits, D = 0; D < V.length; ++D) {
153
+ var zt = N.name + "_" + V[D];
154
+ if (M.push(zt), T[zt] = N.createMethod(V[D], N.padding), N.name !== "sha3") {
155
+ var Zt = N.name + V[D];
156
+ M.push(Zt), T[Zt] = T[zt];
157
157
  }
158
158
  }
159
- function l(t, e, r) {
159
+ function g(t, e, r) {
160
160
  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;
161
161
  for (var n = 0; n < 50; ++n)
162
162
  this.s[n] = 0;
163
163
  }
164
- l.prototype.update = function(t) {
164
+ g.prototype.update = function(t) {
165
165
  if (this.finalized)
166
- throw new Error(R);
167
- var e = Kt(t);
166
+ throw new Error(o);
167
+ var e = Vt(t);
168
168
  t = e[0];
169
- for (var r = e[1], n = this.blocks, o = this.byteCount, a = t.length, u = this.blockCount, i = 0, p = this.s, f, c; i < a; ) {
169
+ for (var r = e[1], n = this.blocks, c = this.byteCount, h = t.length, u = this.blockCount, f = 0, S = this.s, s, x; f < h; ) {
170
170
  if (this.reset)
171
- for (this.reset = !1, n[0] = this.block, f = 1; f < u + 1; ++f)
172
- n[f] = 0;
171
+ for (this.reset = !1, n[0] = this.block, s = 1; s < u + 1; ++s)
172
+ n[s] = 0;
173
173
  if (r)
174
- for (f = this.start; i < a && f < o; ++i)
175
- c = t.charCodeAt(i), c < 128 ? n[f >> 2] |= c << d[f++ & 3] : c < 2048 ? (n[f >> 2] |= (192 | c >> 6) << d[f++ & 3], n[f >> 2] |= (128 | c & 63) << d[f++ & 3]) : c < 55296 || c >= 57344 ? (n[f >> 2] |= (224 | c >> 12) << d[f++ & 3], n[f >> 2] |= (128 | c >> 6 & 63) << d[f++ & 3], n[f >> 2] |= (128 | c & 63) << d[f++ & 3]) : (c = 65536 + ((c & 1023) << 10 | t.charCodeAt(++i) & 1023), n[f >> 2] |= (240 | c >> 18) << d[f++ & 3], n[f >> 2] |= (128 | c >> 12 & 63) << d[f++ & 3], n[f >> 2] |= (128 | c >> 6 & 63) << d[f++ & 3], n[f >> 2] |= (128 | c & 63) << d[f++ & 3]);
174
+ for (s = this.start; f < h && s < c; ++f)
175
+ 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]);
176
176
  else
177
- for (f = this.start; i < a && f < o; ++i)
178
- n[f >> 2] |= t[i] << d[f++ & 3];
179
- if (this.lastByteIndex = f, f >= o) {
180
- for (this.start = f - o, this.block = n[u], f = 0; f < u; ++f)
181
- p[f] ^= n[f];
182
- O(p), this.reset = !0;
177
+ for (s = this.start; f < h && s < c; ++f)
178
+ n[s >> 2] |= t[f] << v[s++ & 3];
179
+ if (this.lastByteIndex = s, s >= c) {
180
+ for (this.start = s - c, this.block = n[u], s = 0; s < u; ++s)
181
+ S[s] ^= n[s];
182
+ H(S), this.reset = !0;
183
183
  } else
184
- this.start = f;
184
+ this.start = s;
185
185
  }
186
186
  return this;
187
- }, l.prototype.encode = function(t, e) {
188
- var r = t & 255, n = 1, o = [r];
187
+ }, g.prototype.encode = function(t, e) {
188
+ var r = t & 255, n = 1, c = [r];
189
189
  for (t = t >> 8, r = t & 255; r > 0; )
190
- o.unshift(r), t = t >> 8, r = t & 255, ++n;
191
- return e ? o.push(n) : o.unshift(n), this.update(o), o.length;
192
- }, l.prototype.encodeString = function(t) {
193
- var e = Kt(t);
190
+ c.unshift(r), t = t >> 8, r = t & 255, ++n;
191
+ return e ? c.push(n) : c.unshift(n), this.update(c), c.length;
192
+ }, g.prototype.encodeString = function(t) {
193
+ var e = Vt(t);
194
194
  t = e[0];
195
- var r = e[1], n = 0, o = t.length;
195
+ var r = e[1], n = 0, c = t.length;
196
196
  if (r)
197
- for (var a = 0; a < t.length; ++a) {
198
- var u = t.charCodeAt(a);
199
- u < 128 ? n += 1 : u < 2048 ? n += 2 : u < 55296 || u >= 57344 ? n += 3 : (u = 65536 + ((u & 1023) << 10 | t.charCodeAt(++a) & 1023), n += 4);
197
+ for (var h = 0; h < t.length; ++h) {
198
+ var u = t.charCodeAt(h);
199
+ 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);
200
200
  }
201
201
  else
202
- n = o;
202
+ n = c;
203
203
  return n += this.encode(n * 8), this.update(t), n;
204
- }, l.prototype.bytepad = function(t, e) {
204
+ }, g.prototype.bytepad = function(t, e) {
205
205
  for (var r = this.encode(e), n = 0; n < t.length; ++n)
206
206
  r += this.encodeString(t[n]);
207
- var o = (e - r % e) % e, a = [];
208
- return a.length = o, this.update(a), this;
209
- }, l.prototype.finalize = function() {
207
+ var c = (e - r % e) % e, h = [];
208
+ return h.length = c, this.update(h), this;
209
+ }, g.prototype.finalize = function() {
210
210
  if (!this.finalized) {
211
211
  this.finalized = !0;
212
212
  var t = this.blocks, e = this.lastByteIndex, r = this.blockCount, n = this.s;
@@ -215,98 +215,343 @@ function ue() {
215
215
  t[e] = 0;
216
216
  for (t[r - 1] |= 2147483648, e = 0; e < r; ++e)
217
217
  n[e] ^= t[e];
218
- O(n);
218
+ H(n);
219
219
  }
220
- }, l.prototype.toString = l.prototype.hex = function() {
220
+ }, g.prototype.toString = g.prototype.hex = function() {
221
221
  this.finalize();
222
- for (var t = this.blockCount, e = this.s, r = this.outputBlocks, n = this.extraBytes, o = 0, a = 0, u = "", i; a < r; ) {
223
- for (o = 0; o < t && a < r; ++o, ++a)
224
- i = e[o], u += h[i >> 4 & 15] + h[i & 15] + h[i >> 12 & 15] + h[i >> 8 & 15] + h[i >> 20 & 15] + h[i >> 16 & 15] + h[i >> 28 & 15] + h[i >> 24 & 15];
225
- a % t === 0 && (e = zt(e), O(e), o = 0);
222
+ for (var t = this.blockCount, e = this.s, r = this.outputBlocks, n = this.extraBytes, c = 0, h = 0, u = "", f; h < r; ) {
223
+ for (c = 0; c < t && h < r; ++c, ++h)
224
+ f = e[c], 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];
225
+ h % t === 0 && (e = Jt(e), H(e), c = 0);
226
226
  }
227
- return n && (i = e[o], u += h[i >> 4 & 15] + h[i & 15], n > 1 && (u += h[i >> 12 & 15] + h[i >> 8 & 15]), n > 2 && (u += h[i >> 20 & 15] + h[i >> 16 & 15])), u;
228
- }, l.prototype.arrayBuffer = function() {
227
+ return n && (f = e[c], 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;
228
+ }, g.prototype.arrayBuffer = function() {
229
229
  this.finalize();
230
- var t = this.blockCount, e = this.s, r = this.outputBlocks, n = this.extraBytes, o = 0, a = 0, u = this.outputBits >> 3, i;
231
- n ? i = new ArrayBuffer(r + 1 << 2) : i = new ArrayBuffer(u);
232
- for (var p = new Uint32Array(i); a < r; ) {
233
- for (o = 0; o < t && a < r; ++o, ++a)
234
- p[a] = e[o];
235
- a % t === 0 && (e = zt(e), O(e));
230
+ var t = this.blockCount, e = this.s, r = this.outputBlocks, n = this.extraBytes, c = 0, h = 0, u = this.outputBits >> 3, f;
231
+ n ? f = new ArrayBuffer(r + 1 << 2) : f = new ArrayBuffer(u);
232
+ for (var S = new Uint32Array(f); h < r; ) {
233
+ for (c = 0; c < t && h < r; ++c, ++h)
234
+ S[h] = e[c];
235
+ h % t === 0 && (e = Jt(e), H(e));
236
236
  }
237
- return n && (p[a] = e[o], i = i.slice(0, u)), i;
238
- }, l.prototype.buffer = l.prototype.arrayBuffer, l.prototype.digest = l.prototype.array = function() {
237
+ return n && (S[h] = e[c], f = f.slice(0, u)), f;
238
+ }, g.prototype.buffer = g.prototype.arrayBuffer, g.prototype.digest = g.prototype.array = function() {
239
239
  this.finalize();
240
- for (var t = this.blockCount, e = this.s, r = this.outputBlocks, n = this.extraBytes, o = 0, a = 0, u = [], i, p; a < r; ) {
241
- for (o = 0; o < t && a < r; ++o, ++a)
242
- i = a << 2, p = e[o], u[i] = p & 255, u[i + 1] = p >> 8 & 255, u[i + 2] = p >> 16 & 255, u[i + 3] = p >> 24 & 255;
243
- a % t === 0 && (e = zt(e), O(e));
240
+ for (var t = this.blockCount, e = this.s, r = this.outputBlocks, n = this.extraBytes, c = 0, h = 0, u = [], f, S; h < r; ) {
241
+ for (c = 0; c < t && h < r; ++c, ++h)
242
+ f = h << 2, S = e[c], u[f] = S & 255, u[f + 1] = S >> 8 & 255, u[f + 2] = S >> 16 & 255, u[f + 3] = S >> 24 & 255;
243
+ h % t === 0 && (e = Jt(e), H(e));
244
244
  }
245
- return n && (i = a << 2, p = e[o], u[i] = p & 255, n > 1 && (u[i + 1] = p >> 8 & 255), n > 2 && (u[i + 2] = p >> 16 & 255)), u;
245
+ return n && (f = h << 2, S = e[c], u[f] = S & 255, n > 1 && (u[f + 1] = S >> 8 & 255), n > 2 && (u[f + 2] = S >> 16 & 255)), u;
246
246
  };
247
- function jt(t, e, r) {
248
- l.call(this, t, e, r);
247
+ function Wt(t, e, r) {
248
+ g.call(this, t, e, r);
249
249
  }
250
- jt.prototype = new l(), jt.prototype.finalize = function() {
251
- return this.encode(this.outputBits, !0), l.prototype.finalize.call(this);
250
+ Wt.prototype = new g(), Wt.prototype.finalize = function() {
251
+ return this.encode(this.outputBits, !0), g.prototype.finalize.call(this);
252
252
  };
253
- var O = function(t) {
254
- var e, r, n, o, a, u, i, p, f, c, H, K, z, J, j, P, T, m, U, W, G, Y, V, q, L, X, Z, $, Q, s, tt, et, rt, nt, ot, at, it, ut, ft, ct, ht, lt, pt, bt, dt, yt, vt, xt, _t, At, kt, St, Ft, wt, Bt, Ct, Ot, Et, Rt, Mt, gt, Nt, It;
253
+ var H = function(t) {
254
+ var e, r, n, c, h, u, f, S, s, x, J, z, W, U, m, 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, Bt, Pt, kt, At, Ft, wt, _t, jt, Ct, Ot, Et, Tt, Rt, Kt, Nt, Mt, Dt, Ht, It;
255
255
  for (n = 0; n < 48; n += 2)
256
- o = t[0] ^ t[10] ^ t[20] ^ t[30] ^ t[40], a = t[1] ^ t[11] ^ t[21] ^ t[31] ^ t[41], u = t[2] ^ t[12] ^ t[22] ^ t[32] ^ t[42], i = t[3] ^ t[13] ^ t[23] ^ t[33] ^ t[43], p = t[4] ^ t[14] ^ t[24] ^ t[34] ^ t[44], f = t[5] ^ t[15] ^ t[25] ^ t[35] ^ t[45], c = t[6] ^ t[16] ^ t[26] ^ t[36] ^ t[46], H = t[7] ^ t[17] ^ t[27] ^ t[37] ^ t[47], K = t[8] ^ t[18] ^ t[28] ^ t[38] ^ t[48], z = t[9] ^ t[19] ^ t[29] ^ t[39] ^ t[49], e = K ^ (u << 1 | i >>> 31), r = z ^ (i << 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 = o ^ (p << 1 | f >>> 31), r = a ^ (f << 1 | p >>> 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 ^ (c << 1 | H >>> 31), r = i ^ (H << 1 | c >>> 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 = p ^ (K << 1 | z >>> 31), r = f ^ (z << 1 | K >>> 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 = c ^ (o << 1 | a >>> 31), r = H ^ (a << 1 | o >>> 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, J = t[0], j = t[1], yt = t[11] << 4 | t[10] >>> 28, vt = t[10] << 4 | t[11] >>> 28, $ = t[20] << 3 | t[21] >>> 29, Q = t[21] << 3 | t[20] >>> 29, Mt = t[31] << 9 | t[30] >>> 23, gt = t[30] << 9 | t[31] >>> 23, lt = t[40] << 18 | t[41] >>> 14, pt = t[41] << 18 | t[40] >>> 14, nt = t[2] << 1 | t[3] >>> 31, ot = t[3] << 1 | t[2] >>> 31, P = t[13] << 12 | t[12] >>> 20, T = t[12] << 12 | t[13] >>> 20, xt = t[22] << 10 | t[23] >>> 22, _t = t[23] << 10 | t[22] >>> 22, s = t[33] << 13 | t[32] >>> 19, tt = t[32] << 13 | t[33] >>> 19, Nt = t[42] << 2 | t[43] >>> 30, It = t[43] << 2 | t[42] >>> 30, wt = t[5] << 30 | t[4] >>> 2, Bt = t[4] << 30 | t[5] >>> 2, at = t[14] << 6 | t[15] >>> 26, it = t[15] << 6 | t[14] >>> 26, m = t[25] << 11 | t[24] >>> 21, U = t[24] << 11 | t[25] >>> 21, At = t[34] << 15 | t[35] >>> 17, kt = t[35] << 15 | t[34] >>> 17, et = t[45] << 29 | t[44] >>> 3, rt = t[44] << 29 | t[45] >>> 3, q = t[6] << 28 | t[7] >>> 4, L = t[7] << 28 | t[6] >>> 4, Ct = t[17] << 23 | t[16] >>> 9, Ot = t[16] << 23 | t[17] >>> 9, ut = t[26] << 25 | t[27] >>> 7, ft = t[27] << 25 | t[26] >>> 7, W = t[36] << 21 | t[37] >>> 11, G = t[37] << 21 | t[36] >>> 11, St = t[47] << 24 | t[46] >>> 8, Ft = t[46] << 24 | t[47] >>> 8, bt = t[8] << 27 | t[9] >>> 5, dt = t[9] << 27 | t[8] >>> 5, X = t[18] << 20 | t[19] >>> 12, Z = t[19] << 20 | t[18] >>> 12, Et = t[29] << 7 | t[28] >>> 25, Rt = t[28] << 7 | t[29] >>> 25, ct = t[38] << 8 | t[39] >>> 24, ht = t[39] << 8 | t[38] >>> 24, Y = t[48] << 14 | t[49] >>> 18, V = t[49] << 14 | t[48] >>> 18, t[0] = J ^ ~P & m, t[1] = j ^ ~T & U, t[10] = q ^ ~X & $, t[11] = L ^ ~Z & Q, t[20] = nt ^ ~at & ut, t[21] = ot ^ ~it & ft, t[30] = bt ^ ~yt & xt, t[31] = dt ^ ~vt & _t, t[40] = wt ^ ~Ct & Et, t[41] = Bt ^ ~Ot & Rt, t[2] = P ^ ~m & W, t[3] = T ^ ~U & G, t[12] = X ^ ~$ & s, t[13] = Z ^ ~Q & tt, t[22] = at ^ ~ut & ct, t[23] = it ^ ~ft & ht, t[32] = yt ^ ~xt & At, t[33] = vt ^ ~_t & kt, t[42] = Ct ^ ~Et & Mt, t[43] = Ot ^ ~Rt & gt, t[4] = m ^ ~W & Y, t[5] = U ^ ~G & V, t[14] = $ ^ ~s & et, t[15] = Q ^ ~tt & rt, t[24] = ut ^ ~ct & lt, t[25] = ft ^ ~ht & pt, t[34] = xt ^ ~At & St, t[35] = _t ^ ~kt & Ft, t[44] = Et ^ ~Mt & Nt, t[45] = Rt ^ ~gt & It, t[6] = W ^ ~Y & J, t[7] = G ^ ~V & j, t[16] = s ^ ~et & q, t[17] = tt ^ ~rt & L, t[26] = ct ^ ~lt & nt, t[27] = ht ^ ~pt & ot, t[36] = At ^ ~St & bt, t[37] = kt ^ ~Ft & dt, t[46] = Mt ^ ~Nt & wt, t[47] = gt ^ ~It & Bt, t[8] = Y ^ ~J & P, t[9] = V ^ ~j & T, t[18] = et ^ ~q & X, t[19] = rt ^ ~L & Z, t[28] = lt ^ ~nt & at, t[29] = pt ^ ~ot & it, t[38] = St ^ ~bt & yt, t[39] = Ft ^ ~dt & vt, t[48] = Nt ^ ~wt & Ct, t[49] = It ^ ~Bt & Ot, t[0] ^= Tt[n], t[1] ^= Tt[n + 1];
256
+ c = 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], J = t[7] ^ t[17] ^ t[27] ^ t[37] ^ t[47], z = t[8] ^ t[18] ^ t[28] ^ t[38] ^ t[48], W = t[9] ^ t[19] ^ t[29] ^ t[39] ^ t[49], e = z ^ (u << 1 | f >>> 31), r = W ^ (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 = c ^ (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 | J >>> 31), r = f ^ (J << 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 ^ (z << 1 | W >>> 31), r = s ^ (W << 1 | z >>> 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 ^ (c << 1 | h >>> 31), r = J ^ (h << 1 | c >>> 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, U = t[0], m = t[1], Pt = t[11] << 4 | t[10] >>> 28, kt = t[10] << 4 | t[11] >>> 28, ot = t[20] << 3 | t[21] >>> 29, it = t[21] << 3 | t[20] >>> 29, Mt = t[31] << 9 | t[30] >>> 23, Dt = t[30] << 9 | t[31] >>> 23, xt = t[40] << 18 | t[41] >>> 14, gt = t[41] << 18 | t[40] >>> 14, lt = t[2] << 1 | t[3] >>> 31, ut = t[3] << 1 | t[2] >>> 31, G = t[13] << 12 | t[12] >>> 20, Y = t[12] << 12 | t[13] >>> 20, At = t[22] << 10 | t[23] >>> 22, Ft = t[23] << 10 | t[22] >>> 22, ct = t[33] << 13 | t[32] >>> 19, at = t[32] << 13 | t[33] >>> 19, Ht = t[42] << 2 | t[43] >>> 30, It = t[43] << 2 | t[42] >>> 30, Ot = t[5] << 30 | t[4] >>> 2, Et = t[4] << 30 | t[5] >>> 2, st = t[14] << 6 | t[15] >>> 26, yt = t[15] << 6 | t[14] >>> 26, q = t[25] << 11 | t[24] >>> 21, $ = t[24] << 11 | t[25] >>> 21, wt = t[34] << 15 | t[35] >>> 17, _t = t[35] << 15 | t[34] >>> 17, ht = t[45] << 29 | t[44] >>> 3, ft = t[44] << 29 | t[45] >>> 3, tt = t[6] << 28 | t[7] >>> 4, et = t[7] << 28 | t[6] >>> 4, Tt = t[17] << 23 | t[16] >>> 9, Rt = t[16] << 23 | t[17] >>> 9, dt = t[26] << 25 | t[27] >>> 7, bt = t[27] << 25 | t[26] >>> 7, L = t[36] << 21 | t[37] >>> 11, X = t[37] << 21 | t[36] >>> 11, jt = t[47] << 24 | t[46] >>> 8, Ct = t[46] << 24 | t[47] >>> 8, St = t[8] << 27 | t[9] >>> 5, Bt = t[9] << 27 | t[8] >>> 5, rt = t[18] << 20 | t[19] >>> 12, nt = t[19] << 20 | t[18] >>> 12, Kt = t[29] << 7 | t[28] >>> 25, Nt = t[28] << 7 | t[29] >>> 25, pt = t[38] << 8 | t[39] >>> 24, vt = t[39] << 8 | t[38] >>> 24, Z = t[48] << 14 | t[49] >>> 18, Q = t[49] << 14 | t[48] >>> 18, t[0] = U ^ ~G & q, t[1] = m ^ ~Y & $, t[10] = tt ^ ~rt & ot, t[11] = et ^ ~nt & it, t[20] = lt ^ ~st & dt, t[21] = ut ^ ~yt & bt, t[30] = St ^ ~Pt & At, t[31] = Bt ^ ~kt & Ft, t[40] = Ot ^ ~Tt & Kt, t[41] = Et ^ ~Rt & Nt, t[2] = G ^ ~q & L, t[3] = Y ^ ~$ & X, t[12] = rt ^ ~ot & ct, t[13] = nt ^ ~it & at, t[22] = st ^ ~dt & pt, t[23] = yt ^ ~bt & vt, t[32] = Pt ^ ~At & wt, t[33] = kt ^ ~Ft & _t, t[42] = Tt ^ ~Kt & Mt, t[43] = Rt ^ ~Nt & Dt, t[4] = q ^ ~L & Z, t[5] = $ ^ ~X & Q, t[14] = ot ^ ~ct & ht, t[15] = it ^ ~at & ft, t[24] = dt ^ ~pt & xt, t[25] = bt ^ ~vt & gt, t[34] = At ^ ~wt & jt, t[35] = Ft ^ ~_t & Ct, t[44] = Kt ^ ~Mt & Ht, t[45] = Nt ^ ~Dt & It, t[6] = L ^ ~Z & U, t[7] = X ^ ~Q & m, t[16] = ct ^ ~ht & tt, t[17] = at ^ ~ft & et, t[26] = pt ^ ~xt & lt, t[27] = vt ^ ~gt & ut, t[36] = wt ^ ~jt & St, t[37] = _t ^ ~Ct & Bt, t[46] = Mt ^ ~Ht & Ot, t[47] = Dt ^ ~It & Et, t[8] = Z ^ ~U & G, t[9] = Q ^ ~m & Y, t[18] = ht ^ ~tt & rt, t[19] = ft ^ ~et & nt, t[28] = xt ^ ~lt & st, t[29] = gt ^ ~ut & yt, t[38] = jt ^ ~St & Pt, t[39] = Ct ^ ~Bt & kt, t[48] = Ht ^ ~Ot & Tt, t[49] = It ^ ~Et & Rt, t[0] ^= _[n], t[1] ^= _[n + 1];
257
257
  };
258
- if (g)
259
- v.exports = _;
258
+ if (P)
259
+ E.exports = T;
260
260
  else
261
- for (A = 0; A < B.length; ++A)
262
- b[B[A]] = _[B[A]];
261
+ for (R = 0; R < M.length; ++R)
262
+ a[M[R]] = T[M[R]];
263
263
  })();
264
- })(Pt)), Pt.exports;
264
+ })(Ut)), Ut.exports;
265
265
  }
266
- var fe = ue();
267
- const ce = /* @__PURE__ */ ie(fe), { keccak256: E } = ce;
268
- class he {
269
- constructor(y, R) {
270
- return this.declarations = [], this.secret = y, this.namespace = R, this.identityRoot = "0x" + E(y), this.publicKey = "0x" + E("public:" + y), this.identityHash = "0x" + E(this.publicKey + R), new Proxy(this, {
271
- get: (b, F) => F in b ? b[F] : (...k) => {
272
- const g = String(F), w = (x) => x && typeof x == "object" && "__pointer" in x ? x.__pointer : x;
273
- let h;
274
- k.length === 0 ? h = void 0 : k.length === 1 ? h = w(k[0]) : h = k.map((x) => w(x));
275
- const Dt = "0x" + E(
276
- b.secret + g + JSON.stringify(h) + b.namespace
277
- ), N = {
278
- key: g,
279
- value: h,
280
- signature: Dt,
281
- timestamp: Date.now()
282
- };
283
- return b.declarations.push(N), b;
266
+ var fe = he();
267
+ const le = /* @__PURE__ */ ae(fe), { keccak256: O } = le;
268
+ class te {
269
+ constructor(i, o) {
270
+ this.payload = {}, this.declarations = [], this.secrets = {}, this.branchVersions = {}, this.username = i, this.secret = o, this.identityRoot = "0x" + O(o), this.publicKey = "0x" + O("public:" + o), this.identityHash = "0x" + O(this.publicKey + this.username), this.secrets[""] = o;
271
+ const l = this.createProxy([]);
272
+ return Object.setPrototypeOf(l, te.prototype), Object.assign(l, this), l;
273
+ }
274
+ /**
275
+ * Create a proxy bound to a specific path, e.g. ["wallet", "income"]
276
+ * The proxy itself is callable (function) and also expandable via property access.
277
+ */
278
+ createProxy(i) {
279
+ const o = this, l = (...a) => o.handleCall(i, a);
280
+ return new Proxy(l, {
281
+ get(a, y) {
282
+ if (typeof y == "symbol") return a[y];
283
+ if (y === "secret") return o.createProxy([...i, String(y)]);
284
+ if (y in o) return o[y];
285
+ const b = [...i, String(y)];
286
+ return o.createProxy(b);
287
+ },
288
+ apply(a, y, b) {
289
+ return o.handleCall(i, b);
284
290
  }
285
291
  });
286
292
  }
287
293
  /**
288
- * Firma genérica de mensajes si se necesita fuera de las declaraciones.
294
+ * Handle a call at a given path.
295
+ * Examples:
296
+ * me.wallet.income(200) → set encrypted payload at wallet.income
297
+ * me.wallet.secret("abc123") → set secret for path "wallet"
298
+ * me.wallet.ptr() → return pointer object { __ptr: "wallet" }
289
299
  */
290
- sign(y) {
291
- return "0x" + E(this.secret + y);
300
+ handleCall(i, o) {
301
+ if (i.length === 0) {
302
+ if (o.length === 1 && typeof o[0] == "string") {
303
+ const p = o[0].split(".").filter(Boolean);
304
+ return this.exportBranch(p.join("."));
305
+ }
306
+ return this.createProxy([]);
307
+ }
308
+ const l = i[i.length - 1];
309
+ if (l === "secret") {
310
+ const p = i.slice(0, -1), d = p.join("."), B = String(o[0] ?? "");
311
+ if (!B) return this.createProxy(p);
312
+ this.secrets[d] = B;
313
+ const k = "0x" + O(this.secret + d + "::secret-set");
314
+ return this.declarations.push({
315
+ key: d + ".secret",
316
+ value: "<secret-set>",
317
+ signature: k,
318
+ timestamp: Date.now()
319
+ }), this.createProxy(p);
320
+ }
321
+ if (l === "ptr")
322
+ return { __ptr: i.slice(0, -1).join(".") };
323
+ const a = i.join(".");
324
+ let y;
325
+ o.length === 0 ? y = void 0 : o.length === 1 ? y = o[0] : y = o, this.ensurePath(i, y);
326
+ const b = this.resolveSecret(i), P = "0x" + O(
327
+ b + a + JSON.stringify(y)
328
+ );
329
+ return this.declarations.push({
330
+ key: a,
331
+ value: y,
332
+ signature: P,
333
+ timestamp: Date.now()
334
+ }), this.createProxy(i);
335
+ }
336
+ /**
337
+ * Secret scope resolution with path:
338
+ * - Find the most specific path that has a secret.
339
+ * - Return both the secret and the path at which it was defined.
340
+ * - If none, fall back to root secret with empty path.
341
+ */
342
+ resolveSecretWithPath(i) {
343
+ for (let o = i.length; o >= 0; o--) {
344
+ const l = i.slice(0, o).join(".");
345
+ if (this.secrets[l])
346
+ return { secret: this.secrets[l], secretPath: i.slice(0, o) };
347
+ }
348
+ return { secret: this.secret, secretPath: [] };
349
+ }
350
+ /**
351
+ * Backwards-compatible helper: only return the secret string.
352
+ */
353
+ resolveSecret(i) {
354
+ return this.resolveSecretWithPath(i).secret;
292
355
  }
293
356
  /**
294
- * Exportar el snapshot de ME para mandarlo a Cleaker (ledger, graph, etc.).
357
+ * Encrypt and store the value at the given path inside `payload`.
358
+ *
359
+ * If there is a non-root secret defined for some ancestor path P of `path`,
360
+ * we treat that ancestor path P as the "branch root" and store the ENTIRE
361
+ * subtree under P as ONE encrypted blob at that location.
362
+ *
363
+ * This means that to re-enter that channel you need both:
364
+ * - the full expression for P, and
365
+ * - the secret used at P.
366
+ */
367
+ ensurePath(i, o) {
368
+ const { secret: l, secretPath: a } = this.resolveSecretWithPath(i), y = a.join("."), b = O(l);
369
+ if (a.length > 0) {
370
+ let k = {};
371
+ const F = this.branchVersions[y]?.[b], w = this.getSubPayload(a);
372
+ if (F) {
373
+ const A = this.decryptForPath(a, F);
374
+ A && typeof A == "object" && (k = A);
375
+ } else if (typeof w == "string") {
376
+ const A = this.decryptForPath(a, w);
377
+ A && typeof A == "object" && (k = A);
378
+ } else w && typeof w == "object" && (k = w);
379
+ const v = i.slice(a.length);
380
+ let _ = k;
381
+ for (let A = 0; A < v.length - 1; A++) {
382
+ const K = v[A];
383
+ (!_[K] || typeof _[K] != "object") && (_[K] = {}), _ = _[K];
384
+ }
385
+ const j = v[v.length - 1];
386
+ _[j] = o;
387
+ const C = this.encryptForPath(a, k);
388
+ this.branchVersions[y] || (this.branchVersions[y] = {}), this.branchVersions[y][b] = C, this.writeBranchBlob(a, C);
389
+ return;
390
+ }
391
+ const p = this.encryptForPath(i, o);
392
+ let d = this.payload;
393
+ for (let k = 0; k < i.length - 1; k++) {
394
+ const F = i[k];
395
+ (!d[F] || typeof d[F] != "object") && (d[F] = {}), d = d[F];
396
+ }
397
+ const B = i[i.length - 1];
398
+ d[B] = p;
399
+ }
400
+ /**
401
+ * Set a value at a nested path inside `payload`.
402
+ */
403
+ setSubPayload(i, o) {
404
+ if (i.length === 0) {
405
+ this.payload = o;
406
+ return;
407
+ }
408
+ let l = this.payload;
409
+ for (let y = 0; y < i.length - 1; y++) {
410
+ const b = i[y];
411
+ (!l[b] || typeof l[b] != "object") && (l[b] = {}), l = l[b];
412
+ }
413
+ const a = i[i.length - 1];
414
+ l[a] = o;
415
+ }
416
+ /**
417
+ * Find the nearest ancestor path that represents an encrypted branch blob.
418
+ */
419
+ findNearestBranchAncestor(i) {
420
+ for (let o = i.length - 1; o >= 1; o--) {
421
+ const l = i.slice(0, o), a = l.join(".");
422
+ if (this.branchVersions[a])
423
+ return { path: l, secret: this.resolveSecret(l) };
424
+ }
425
+ return null;
426
+ }
427
+ /**
428
+ * Write an encrypted branch blob while preserving any encrypted ancestor branches.
429
+ */
430
+ writeBranchBlob(i, o) {
431
+ let l = i, a = o;
432
+ for (; ; ) {
433
+ const y = this.findNearestBranchAncestor(l);
434
+ if (!y) {
435
+ this.setSubPayload(l, a);
436
+ return;
437
+ }
438
+ const { path: b, secret: P } = y, p = b.join("."), d = O(P), B = this.getSubPayload(b), k = this.branchVersions[p]?.[d] ?? (typeof B == "string" ? B : void 0);
439
+ let F = {};
440
+ if (k) {
441
+ const j = this.decryptForPath(b, k);
442
+ j && typeof j == "object" && (F = j);
443
+ }
444
+ const w = l.slice(b.length);
445
+ let v = F;
446
+ for (let j = 0; j < w.length - 1; j++) {
447
+ const C = w[j];
448
+ (!v[C] || typeof v[C] != "object") && (v[C] = {}), v = v[C];
449
+ }
450
+ v[w[w.length - 1]] = a;
451
+ const _ = this.encryptForPath(b, F);
452
+ this.branchVersions[p] || (this.branchVersions[p] = {}), this.branchVersions[p][d] = _, l = b, a = _;
453
+ }
454
+ }
455
+ getSubPayload(i) {
456
+ let o = this.payload;
457
+ for (const l of i) {
458
+ if (!o || typeof o != "object") return;
459
+ o = o[l];
460
+ }
461
+ return o;
462
+ }
463
+ /**
464
+ * Recursively decrypt a node of the encrypted payload tree.
465
+ */
466
+ decryptTree(i, o) {
467
+ if (o == null) return o;
468
+ if (typeof o == "string") {
469
+ if (!this.isHexString(o)) return o;
470
+ const a = this.decryptForPath(i, o);
471
+ return a === null ? o : a;
472
+ }
473
+ if (typeof o != "object")
474
+ return o;
475
+ const l = Array.isArray(o) ? [] : {};
476
+ for (const a of Object.keys(o)) {
477
+ const y = [...i, a];
478
+ l[a] = this.decryptTree(y, o[a]);
479
+ }
480
+ return l;
481
+ }
482
+ /**
483
+ * Encrypt a value (object or primitive) using the secret resolved for the given path.
484
+ * Produces a hex string compatible with decryptForPath().
485
+ */
486
+ encryptForPath(i, o) {
487
+ const l = this.resolveSecret(i), a = JSON.stringify(o), y = new TextEncoder().encode(a), b = O(l + ":" + i.join(".")), P = this.asciiToBytes(b), p = new Uint8Array(y.length);
488
+ for (let B = 0; B < y.length; B++)
489
+ p[B] = y[B] ^ P[B % P.length];
490
+ let d = "";
491
+ for (let B = 0; B < p.length; B++)
492
+ d += p[B].toString(16).padStart(2, "0");
493
+ return d;
494
+ }
495
+ /**
496
+ * Decrypt a single encrypted blob using the secret resolved for the given path.
497
+ */
498
+ decryptForPath(i, o) {
499
+ const l = this.resolveSecret(i);
500
+ try {
501
+ const a = this.hexToBytes(o), y = O(l + ":" + i.join(".")), b = this.asciiToBytes(y), P = new Uint8Array(a.length);
502
+ for (let d = 0; d < a.length; d++)
503
+ P[d] = a[d] ^ b[d % b.length];
504
+ const p = new TextDecoder().decode(P);
505
+ return JSON.parse(p);
506
+ } catch {
507
+ return null;
508
+ }
509
+ }
510
+ asciiToBytes(i) {
511
+ return new TextEncoder().encode(i);
512
+ }
513
+ hexToBytes(i) {
514
+ const o = i.startsWith("0x") ? i.slice(2) : i, l = new Uint8Array(o.length / 2);
515
+ for (let a = 0; a < l.length; a++)
516
+ l[a] = parseInt(o.substr(a * 2, 2), 16);
517
+ return l;
518
+ }
519
+ isHexString(i) {
520
+ const o = i.startsWith("0x") ? i.slice(2) : i;
521
+ return o.length > 0 && o.length % 2 === 0 && /^[0-9a-fA-F]+$/.test(o);
522
+ }
523
+ /**
524
+ * Export the encrypted payload and declaration metadata.
295
525
  */
296
526
  export() {
297
527
  return {
298
528
  identityRoot: this.identityRoot,
299
529
  publicKey: this.publicKey,
300
- namespace: this.namespace,
301
530
  identityHash: this.identityHash,
302
- declarations: this.declarations
531
+ declarations: this.declarations,
532
+ payload: this.payload
303
533
  };
304
534
  }
305
- ptr(y) {
306
- return { __pointer: y.signature };
535
+ /**
536
+ * Export and decrypt a specific branch using the currently active secret
537
+ * resolved for that path.
538
+ */
539
+ exportBranch(i) {
540
+ const o = i ? i.split(".").filter(Boolean) : [], l = o.join("."), a = this.resolveSecret(o), y = O(a), b = this.branchVersions[l]?.[y];
541
+ if (b) {
542
+ const p = this.decryptForPath(o, b);
543
+ return this.decryptTree(o, p);
544
+ }
545
+ const P = this.getSubPayload(o);
546
+ if (P !== void 0) {
547
+ if (typeof P == "string") {
548
+ const p = this.decryptForPath(o, P);
549
+ return this.decryptTree(o, p);
550
+ }
551
+ return this.decryptTree(o, P);
552
+ }
307
553
  }
308
554
  }
309
555
  export {
310
- he as ME,
311
- he as default
556
+ te as ME
312
557
  };
package/dist/me.umd.js CHANGED
@@ -1,8 +1,8 @@
1
- (function(k,w){typeof exports=="object"&&typeof module<"u"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(k=typeof globalThis<"u"?globalThis:k||self,w(k.Me={}))})(this,(function(k){"use strict";var w=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function re(v){return v&&v.__esModule&&Object.prototype.hasOwnProperty.call(v,"default")?v.default:v}var Kt={exports:{}};/**
1
+ (function(K,D){typeof exports=="object"&&typeof module<"u"?D(exports):typeof define=="function"&&define.amd?define(["exports"],D):(K=typeof globalThis<"u"?globalThis:K||self,D(K.Me={}))})(this,(function(K){"use strict";var D=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ne(E){return E&&E.__esModule&&Object.prototype.hasOwnProperty.call(E,"default")?E.default:E}var mt={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 Ut;function ne(){return Ut||(Ut=1,(function(v){(function(){var y="input is invalid type",g="finalize already called",N=typeof window=="object",d=N?window:{};d.JS_SHA3_NO_WINDOW&&(N=!1);var C=!N&&typeof self=="object",S=!d.JS_SHA3_NO_NODE_JS&&typeof process=="object"&&process.versions&&process.versions.node;S?d=w:C&&(d=self);for(var I=!d.JS_SHA3_NO_COMMON_JS&&!0&&v.exports,O=!d.JS_SHA3_NO_ARRAY_BUFFER&&typeof ArrayBuffer<"u",h="0123456789abcdef".split(""),zt=[31,7936,2031616,520093696],D=[4,1024,262144,67108864],x=[1,256,65536,16777216],ae=[6,1536,393216,100663296],b=[0,8,16,24],Gt=[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],Yt=[224,256,384,512],Tt=[128,256],Vt=["hex","buffer","arrayBuffer","array","digest"],qt={128:168,256:136},ue=d.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return Object.prototype.toString.call(t)==="[object Array]"}:Array.isArray,fe=O&&(d.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW||!ArrayBuffer.isView)?function(t){return typeof t=="object"&&t.buffer&&t.buffer.constructor===ArrayBuffer}:ArrayBuffer.isView,jt=function(t){var e=typeof t;if(e==="string")return[t,!0];if(e!=="object"||t===null)throw new Error(y);if(O&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!ue(t)&&!fe(t))throw new Error(y);return[t,!1]},Lt=function(t){return jt(t)[0].length===0},mt=function(t){for(var e=[],r=0;r<t.length;++r)e[r]=t[r];return e},Xt=function(t,e,r){return function(n){return new l(t,e,t).update(n)[r]()}},Zt=function(t,e,r){return function(n,o){return new l(t,e,o).update(n)[r]()}},$t=function(t,e,r){return function(n,o,i,u){return _["cshake"+t].update(n,o,i,u)[r]()}},Qt=function(t,e,r){return function(n,o,i,u){return _["kmac"+t].update(n,o,i,u)[r]()}},H=function(t,e,r,n){for(var o=0;o<Vt.length;++o){var i=Vt[o];t[i]=e(r,n,i)}return t},st=function(t,e){var r=Xt(t,e,"hex");return r.create=function(){return new l(t,e,t)},r.update=function(n){return r.create().update(n)},H(r,Xt,t,e)},ce=function(t,e){var r=Zt(t,e,"hex");return r.create=function(n){return new l(t,e,n)},r.update=function(n,o){return r.create(o).update(n)},H(r,Zt,t,e)},he=function(t,e){var r=qt[t],n=$t(t,e,"hex");return n.create=function(o,i,u){return Lt(i)&&Lt(u)?_["shake"+t].create(o):new l(t,e,o).bytepad([i,u],r)},n.update=function(o,i,u,a){return n.create(i,u,a).update(o)},H(n,$t,t,e)},le=function(t,e){var r=qt[t],n=Qt(t,e,"hex");return n.create=function(o,i,u){return new Pt(t,e,i).bytepad(["KMAC",u],r).bytepad([o],r)},n.update=function(o,i,u,a){return n.create(o,u,a).update(i)},H(n,Qt,t,e)},te=[{name:"keccak",padding:x,bits:Yt,createMethod:st},{name:"sha3",padding:ae,bits:Yt,createMethod:st},{name:"shake",padding:zt,bits:Tt,createMethod:ce},{name:"cshake",padding:D,bits:Tt,createMethod:he},{name:"kmac",padding:D,bits:Tt,createMethod:le}],_={},E=[],A=0;A<te.length;++A)for(var F=te[A],K=F.bits,M=0;M<K.length;++M){var Jt=F.name+"_"+K[M];if(E.push(Jt),_[Jt]=F.createMethod(K[M],F.padding),F.name!=="sha3"){var ee=F.name+K[M];E.push(ee),_[ee]=_[Jt]}}function l(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}l.prototype.update=function(t){if(this.finalized)throw new Error(g);var e=jt(t);t=e[0];for(var r=e[1],n=this.blocks,o=this.byteCount,i=t.length,u=this.blockCount,a=0,p=this.s,f,c;a<i;){if(this.reset)for(this.reset=!1,n[0]=this.block,f=1;f<u+1;++f)n[f]=0;if(r)for(f=this.start;a<i&&f<o;++a)c=t.charCodeAt(a),c<128?n[f>>2]|=c<<b[f++&3]:c<2048?(n[f>>2]|=(192|c>>6)<<b[f++&3],n[f>>2]|=(128|c&63)<<b[f++&3]):c<55296||c>=57344?(n[f>>2]|=(224|c>>12)<<b[f++&3],n[f>>2]|=(128|c>>6&63)<<b[f++&3],n[f>>2]|=(128|c&63)<<b[f++&3]):(c=65536+((c&1023)<<10|t.charCodeAt(++a)&1023),n[f>>2]|=(240|c>>18)<<b[f++&3],n[f>>2]|=(128|c>>12&63)<<b[f++&3],n[f>>2]|=(128|c>>6&63)<<b[f++&3],n[f>>2]|=(128|c&63)<<b[f++&3]);else for(f=this.start;a<i&&f<o;++a)n[f>>2]|=t[a]<<b[f++&3];if(this.lastByteIndex=f,f>=o){for(this.start=f-o,this.block=n[u],f=0;f<u;++f)p[f]^=n[f];R(p),this.reset=!0}else this.start=f}return this},l.prototype.encode=function(t,e){var r=t&255,n=1,o=[r];for(t=t>>8,r=t&255;r>0;)o.unshift(r),t=t>>8,r=t&255,++n;return e?o.push(n):o.unshift(n),this.update(o),o.length},l.prototype.encodeString=function(t){var e=jt(t);t=e[0];var r=e[1],n=0,o=t.length;if(r)for(var i=0;i<t.length;++i){var u=t.charCodeAt(i);u<128?n+=1:u<2048?n+=2:u<55296||u>=57344?n+=3:(u=65536+((u&1023)<<10|t.charCodeAt(++i)&1023),n+=4)}else n=o;return n+=this.encode(n*8),this.update(t),n},l.prototype.bytepad=function(t,e){for(var r=this.encode(e),n=0;n<t.length;++n)r+=this.encodeString(t[n]);var o=(e-r%e)%e,i=[];return i.length=o,this.update(i),this},l.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];R(n)}},l.prototype.toString=l.prototype.hex=function(){this.finalize();for(var t=this.blockCount,e=this.s,r=this.outputBlocks,n=this.extraBytes,o=0,i=0,u="",a;i<r;){for(o=0;o<t&&i<r;++o,++i)a=e[o],u+=h[a>>4&15]+h[a&15]+h[a>>12&15]+h[a>>8&15]+h[a>>20&15]+h[a>>16&15]+h[a>>28&15]+h[a>>24&15];i%t===0&&(e=mt(e),R(e),o=0)}return n&&(a=e[o],u+=h[a>>4&15]+h[a&15],n>1&&(u+=h[a>>12&15]+h[a>>8&15]),n>2&&(u+=h[a>>20&15]+h[a>>16&15])),u},l.prototype.arrayBuffer=function(){this.finalize();var t=this.blockCount,e=this.s,r=this.outputBlocks,n=this.extraBytes,o=0,i=0,u=this.outputBits>>3,a;n?a=new ArrayBuffer(r+1<<2):a=new ArrayBuffer(u);for(var p=new Uint32Array(a);i<r;){for(o=0;o<t&&i<r;++o,++i)p[i]=e[o];i%t===0&&(e=mt(e),R(e))}return n&&(p[i]=e[o],a=a.slice(0,u)),a},l.prototype.buffer=l.prototype.arrayBuffer,l.prototype.digest=l.prototype.array=function(){this.finalize();for(var t=this.blockCount,e=this.s,r=this.outputBlocks,n=this.extraBytes,o=0,i=0,u=[],a,p;i<r;){for(o=0;o<t&&i<r;++o,++i)a=i<<2,p=e[o],u[a]=p&255,u[a+1]=p>>8&255,u[a+2]=p>>16&255,u[a+3]=p>>24&255;i%t===0&&(e=mt(e),R(e))}return n&&(a=i<<2,p=e[o],u[a]=p&255,n>1&&(u[a+1]=p>>8&255),n>2&&(u[a+2]=p>>16&255)),u};function Pt(t,e,r){l.call(this,t,e,r)}Pt.prototype=new l,Pt.prototype.finalize=function(){return this.encode(this.outputBits,!0),l.prototype.finalize.call(this)};var R=function(t){var e,r,n,o,i,u,a,p,f,c,z,T,j,m,J,P,U,W,G,Y,V,q,L,X,Z,$,Q,s,tt,et,rt,nt,ot,it,at,ut,ft,ct,ht,lt,pt,dt,bt,yt,vt,xt,_t,At,kt,St,Ft,wt,Bt,Ct,Ot,Et,Mt,Rt,gt,Nt,It,Dt,Ht;for(n=0;n<48;n+=2)o=t[0]^t[10]^t[20]^t[30]^t[40],i=t[1]^t[11]^t[21]^t[31]^t[41],u=t[2]^t[12]^t[22]^t[32]^t[42],a=t[3]^t[13]^t[23]^t[33]^t[43],p=t[4]^t[14]^t[24]^t[34]^t[44],f=t[5]^t[15]^t[25]^t[35]^t[45],c=t[6]^t[16]^t[26]^t[36]^t[46],z=t[7]^t[17]^t[27]^t[37]^t[47],T=t[8]^t[18]^t[28]^t[38]^t[48],j=t[9]^t[19]^t[29]^t[39]^t[49],e=T^(u<<1|a>>>31),r=j^(a<<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=o^(p<<1|f>>>31),r=i^(f<<1|p>>>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^(c<<1|z>>>31),r=a^(z<<1|c>>>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=p^(T<<1|j>>>31),r=f^(j<<1|T>>>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=c^(o<<1|i>>>31),r=z^(i<<1|o>>>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,m=t[0],J=t[1],xt=t[11]<<4|t[10]>>>28,_t=t[10]<<4|t[11]>>>28,s=t[20]<<3|t[21]>>>29,tt=t[21]<<3|t[20]>>>29,Nt=t[31]<<9|t[30]>>>23,It=t[30]<<9|t[31]>>>23,dt=t[40]<<18|t[41]>>>14,bt=t[41]<<18|t[40]>>>14,it=t[2]<<1|t[3]>>>31,at=t[3]<<1|t[2]>>>31,P=t[13]<<12|t[12]>>>20,U=t[12]<<12|t[13]>>>20,At=t[22]<<10|t[23]>>>22,kt=t[23]<<10|t[22]>>>22,et=t[33]<<13|t[32]>>>19,rt=t[32]<<13|t[33]>>>19,Dt=t[42]<<2|t[43]>>>30,Ht=t[43]<<2|t[42]>>>30,Ct=t[5]<<30|t[4]>>>2,Ot=t[4]<<30|t[5]>>>2,ut=t[14]<<6|t[15]>>>26,ft=t[15]<<6|t[14]>>>26,W=t[25]<<11|t[24]>>>21,G=t[24]<<11|t[25]>>>21,St=t[34]<<15|t[35]>>>17,Ft=t[35]<<15|t[34]>>>17,nt=t[45]<<29|t[44]>>>3,ot=t[44]<<29|t[45]>>>3,X=t[6]<<28|t[7]>>>4,Z=t[7]<<28|t[6]>>>4,Et=t[17]<<23|t[16]>>>9,Mt=t[16]<<23|t[17]>>>9,ct=t[26]<<25|t[27]>>>7,ht=t[27]<<25|t[26]>>>7,Y=t[36]<<21|t[37]>>>11,V=t[37]<<21|t[36]>>>11,wt=t[47]<<24|t[46]>>>8,Bt=t[46]<<24|t[47]>>>8,yt=t[8]<<27|t[9]>>>5,vt=t[9]<<27|t[8]>>>5,$=t[18]<<20|t[19]>>>12,Q=t[19]<<20|t[18]>>>12,Rt=t[29]<<7|t[28]>>>25,gt=t[28]<<7|t[29]>>>25,lt=t[38]<<8|t[39]>>>24,pt=t[39]<<8|t[38]>>>24,q=t[48]<<14|t[49]>>>18,L=t[49]<<14|t[48]>>>18,t[0]=m^~P&W,t[1]=J^~U&G,t[10]=X^~$&s,t[11]=Z^~Q&tt,t[20]=it^~ut&ct,t[21]=at^~ft&ht,t[30]=yt^~xt&At,t[31]=vt^~_t&kt,t[40]=Ct^~Et&Rt,t[41]=Ot^~Mt&gt,t[2]=P^~W&Y,t[3]=U^~G&V,t[12]=$^~s&et,t[13]=Q^~tt&rt,t[22]=ut^~ct&lt,t[23]=ft^~ht&pt,t[32]=xt^~At&St,t[33]=_t^~kt&Ft,t[42]=Et^~Rt&Nt,t[43]=Mt^~gt&It,t[4]=W^~Y&q,t[5]=G^~V&L,t[14]=s^~et&nt,t[15]=tt^~rt&ot,t[24]=ct^~lt&dt,t[25]=ht^~pt&bt,t[34]=At^~St&wt,t[35]=kt^~Ft&Bt,t[44]=Rt^~Nt&Dt,t[45]=gt^~It&Ht,t[6]=Y^~q&m,t[7]=V^~L&J,t[16]=et^~nt&X,t[17]=rt^~ot&Z,t[26]=lt^~dt&it,t[27]=pt^~bt&at,t[36]=St^~wt&yt,t[37]=Ft^~Bt&vt,t[46]=Nt^~Dt&Ct,t[47]=It^~Ht&Ot,t[8]=q^~m&P,t[9]=L^~J&U,t[18]=nt^~X&$,t[19]=ot^~Z&Q,t[28]=dt^~it&ut,t[29]=bt^~at&ft,t[38]=wt^~yt&xt,t[39]=Bt^~vt&_t,t[48]=Dt^~Ct&Et,t[49]=Ht^~Ot&Mt,t[0]^=Gt[n],t[1]^=Gt[n+1]};if(I)v.exports=_;else for(A=0;A<E.length;++A)d[E[A]]=_[E[A]]})()})(Kt)),Kt.exports}var oe=ne();const ie=re(oe),{keccak256:B}=ie;class Wt{constructor(y,g){return this.declarations=[],this.secret=y,this.namespace=g,this.identityRoot="0x"+B(y),this.publicKey="0x"+B("public:"+y),this.identityHash="0x"+B(this.publicKey+g),new Proxy(this,{get:(d,C)=>C in d?d[C]:(...S)=>{const I=String(C),O=x=>x&&typeof x=="object"&&"__pointer"in x?x.__pointer:x;let h;S.length===0?h=void 0:S.length===1?h=O(S[0]):h=S.map(x=>O(x));const zt="0x"+B(d.secret+I+JSON.stringify(h)+d.namespace),D={key:I,value:h,signature:zt,timestamp:Date.now()};return d.declarations.push(D),d}})}sign(y){return"0x"+B(this.secret+y)}export(){return{identityRoot:this.identityRoot,publicKey:this.publicKey,namespace:this.namespace,identityHash:this.identityHash,declarations:this.declarations}}ptr(y){return{__pointer:y.signature}}}k.ME=Wt,k.default=Wt,Object.defineProperties(k,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
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",a=l?window:{};a.JS_SHA3_NO_WINDOW&&(l=!1);var y=!l&&typeof self=="object",p=!a.JS_SHA3_NO_NODE_JS&&typeof process=="object"&&process.versions&&process.versions.node;p?a=D:y&&(a=self);for(var B=!a.JS_SHA3_NO_COMMON_JS&&!0&&E.exports,b=!a.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=a.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return Object.prototype.toString.call(t)==="[object Array]"}:Array.isArray,he=b&&(a.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(b&&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,c){return new g(t,e,c).update(n)[r]()}},Zt=function(t,e,r){return function(n,c,h,u){return T["cshake"+t].update(n,c,h,u)[r]()}},Qt=function(t,e,r){return function(n,c,h,u){return T["kmac"+t].update(n,c,h,u)[r]()}},J=function(t,e,r,n){for(var c=0;c<A.length;++c){var h=A[c];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,c){return r.create(c).update(n)},J(r,Xt,t,e)},le=function(t,e){var r=R[t],n=Zt(t,e,"hex");return n.create=function(c,h,u){return $t(h)&&$t(u)?T["shake"+t].create(c):new g(t,e,c).bytepad([h,u],r)},n.update=function(c,h,u,f){return n.create(h,u,f).update(c)},J(n,Zt,t,e)},ue=function(t,e){var r=R[t],n=Qt(t,e,"hex");return n.create=function(c,h,u){return new Yt(t,e,h).bytepad(["KMAC",u],r).bytepad([c],r)},n.update=function(c,h,u,f){return n.create(c,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,c=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<c;++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<c;++f)n[s>>2]|=t[f]<<v[s++&3];if(this.lastByteIndex=s,s>=c){for(this.start=s-c,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,c=[r];for(t=t>>8,r=t&255;r>0;)c.unshift(r),t=t>>8,r=t&255,++n;return e?c.push(n):c.unshift(n),this.update(c),c.length},g.prototype.encodeString=function(t){var e=Wt(t);t=e[0];var r=e[1],n=0,c=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=c;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 c=(e-r%e)%e,h=[];return h.length=c,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,c=0,h=0,u="",f;h<r;){for(c=0;c<t&&h<r;++c,++h)f=e[c],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),c=0)}return n&&(f=e[c],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,c=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(c=0;c<t&&h<r;++c,++h)S[h]=e[c];h%t===0&&(e=Ut(e),V(e))}return n&&(S[h]=e[c],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,c=0,h=0,u=[],f,S;h<r;){for(c=0;c<t&&h<r;++c,++h)f=h<<2,S=e[c],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[c],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,c,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,pt,bt,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)c=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=c^(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^(c<<1|h>>>31),r=z^(h<<1|c>>>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,pt=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,bt=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&bt,t[21]=yt^~pt&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^~bt&xt,t[23]=pt^~vt&gt,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&lt,t[15]=at^~ft&ut,t[24]=bt^~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&pt,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)a[H[M]]=T[H[M]]})()})(mt)),mt.exports}var ie=oe();const ce=ne(ie),{keccak256:O}=ce;class zt{constructor(i,o){this.payload={},this.declarations=[],this.secrets={},this.branchVersions={},this.username=i,this.secret=o,this.identityRoot="0x"+O(o),this.publicKey="0x"+O("public:"+o),this.identityHash="0x"+O(this.publicKey+this.username),this.secrets[""]=o;const l=this.createProxy([]);return Object.setPrototypeOf(l,zt.prototype),Object.assign(l,this),l}createProxy(i){const o=this,l=(...a)=>o.handleCall(i,a);return new Proxy(l,{get(a,y){if(typeof y=="symbol")return a[y];if(y==="secret")return o.createProxy([...i,String(y)]);if(y in o)return o[y];const p=[...i,String(y)];return o.createProxy(p)},apply(a,y,p){return o.handleCall(i,p)}})}handleCall(i,o){if(i.length===0){if(o.length===1&&typeof o[0]=="string"){const b=o[0].split(".").filter(Boolean);return this.exportBranch(b.join("."))}return this.createProxy([])}const l=i[i.length-1];if(l==="secret"){const b=i.slice(0,-1),d=b.join("."),P=String(o[0]??"");if(!P)return this.createProxy(b);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(b)}if(l==="ptr")return{__ptr:i.slice(0,-1).join(".")};const a=i.join(".");let y;o.length===0?y=void 0:o.length===1?y=o[0]:y=o,this.ensurePath(i,y);const p=this.resolveSecret(i),B="0x"+O(p+a+JSON.stringify(y));return this.declarations.push({key:a,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:a}=this.resolveSecretWithPath(i),y=a.join("."),p=O(l);if(a.length>0){let k={};const F=this.branchVersions[y]?.[p],w=this.getSubPayload(a);if(F){const A=this.decryptForPath(a,F);A&&typeof A=="object"&&(k=A)}else if(typeof w=="string"){const A=this.decryptForPath(a,w);A&&typeof A=="object"&&(k=A)}else w&&typeof w=="object"&&(k=w);const v=i.slice(a.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(a,k);this.branchVersions[y]||(this.branchVersions[y]={}),this.branchVersions[y][p]=C,this.writeBranchBlob(a,C);return}const b=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]=b}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 p=i[y];(!l[p]||typeof l[p]!="object")&&(l[p]={}),l=l[p]}const a=i[i.length-1];l[a]=o}findNearestBranchAncestor(i){for(let o=i.length-1;o>=1;o--){const l=i.slice(0,o),a=l.join(".");if(this.branchVersions[a])return{path:l,secret:this.resolveSecret(l)}}return null}writeBranchBlob(i,o){let l=i,a=o;for(;;){const y=this.findNearestBranchAncestor(l);if(!y){this.setSubPayload(l,a);return}const{path:p,secret:B}=y,b=p.join("."),d=O(B),P=this.getSubPayload(p),k=this.branchVersions[b]?.[d]??(typeof P=="string"?P:void 0);let F={};if(k){const j=this.decryptForPath(p,k);j&&typeof j=="object"&&(F=j)}const w=l.slice(p.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]]=a;const _=this.encryptForPath(p,F);this.branchVersions[b]||(this.branchVersions[b]={}),this.branchVersions[b][d]=_,l=p,a=_}}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 a=this.decryptForPath(i,o);return a===null?o:a}if(typeof o!="object")return o;const l=Array.isArray(o)?[]:{};for(const a of Object.keys(o)){const y=[...i,a];l[a]=this.decryptTree(y,o[a])}return l}encryptForPath(i,o){const l=this.resolveSecret(i),a=JSON.stringify(o),y=new TextEncoder().encode(a),p=O(l+":"+i.join(".")),B=this.asciiToBytes(p),b=new Uint8Array(y.length);for(let P=0;P<y.length;P++)b[P]=y[P]^B[P%B.length];let d="";for(let P=0;P<b.length;P++)d+=b[P].toString(16).padStart(2,"0");return d}decryptForPath(i,o){const l=this.resolveSecret(i);try{const a=this.hexToBytes(o),y=O(l+":"+i.join(".")),p=this.asciiToBytes(y),B=new Uint8Array(a.length);for(let d=0;d<a.length;d++)B[d]=a[d]^p[d%p.length];const b=new TextDecoder().decode(B);return JSON.parse(b)}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 a=0;a<l.length;a++)l[a]=parseInt(o.substr(a*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("."),a=this.resolveSecret(o),y=O(a),p=this.branchVersions[l]?.[y];if(p){const b=this.decryptForPath(o,p);return this.decryptTree(o,b)}const B=this.getSubPayload(o);if(B!==void 0){if(typeof B=="string"){const b=this.decryptForPath(o,B);return this.decryptTree(o,b)}return this.decryptTree(o,B)}}}K.ME=zt,Object.defineProperty(K,Symbol.toStringTag,{value:"Module"})}));
package/dist/src/me.d.ts CHANGED
@@ -1,53 +1,104 @@
1
- /**
2
- * me.ts — ME Identity Atom + Declarative Model
3
- * - Pure mathematical identity model for .me
4
- * - Dynamic, user-centric declarative layer (ME Calculus)
5
- */
6
- export interface MeIdentity {
7
- identityRoot: string;
8
- publicKey: string;
9
- namespace: string;
10
- identityHash: string;
11
- }
12
- export interface MeDeclaration {
1
+ interface MeDeclaration {
13
2
  key: string;
14
3
  value: any;
15
4
  signature: string;
16
5
  timestamp: number;
17
6
  }
18
- /**
19
- * ME:
20
- * - Construct with (secret, namespace)
21
- * - Any unknown property access becomes a declarative method:
22
- * me.password("abc")
23
- * me.instrumentos("musicales", "Moog Matriarch")
24
- * - Each call generates a signed declaration pushed into `declarations`.
25
- * - No semántica: only key/value + signature.
26
- */
27
- export declare class ME implements MeIdentity {
28
- identityRoot: string;
7
+ export type MEProxy = ME & {
8
+ [key: string]: any;
9
+ (...args: any[]): MEProxy;
10
+ };
11
+ export declare class ME {
12
+ [key: string]: any;
13
+ username: string;
29
14
  secret: string;
15
+ identityRoot: string;
30
16
  publicKey: string;
31
- namespace: string;
32
17
  identityHash: string;
18
+ payload: any;
33
19
  declarations: MeDeclaration[];
34
- [key: string]: any;
35
- constructor(secret: string, namespace: string);
20
+ private secrets;
21
+ private branchVersions;
22
+ constructor(username: string, secret: string);
23
+ /**
24
+ * Create a proxy bound to a specific path, e.g. ["wallet", "income"]
25
+ * The proxy itself is callable (function) and also expandable via property access.
26
+ */
27
+ private createProxy;
28
+ /**
29
+ * Handle a call at a given path.
30
+ * Examples:
31
+ * me.wallet.income(200) → set encrypted payload at wallet.income
32
+ * me.wallet.secret("abc123") → set secret for path "wallet"
33
+ * me.wallet.ptr() → return pointer object { __ptr: "wallet" }
34
+ */
35
+ private handleCall;
36
+ /**
37
+ * Secret scope resolution with path:
38
+ * - Find the most specific path that has a secret.
39
+ * - Return both the secret and the path at which it was defined.
40
+ * - If none, fall back to root secret with empty path.
41
+ */
42
+ private resolveSecretWithPath;
43
+ /**
44
+ * Backwards-compatible helper: only return the secret string.
45
+ */
46
+ private resolveSecret;
47
+ /**
48
+ * Encrypt and store the value at the given path inside `payload`.
49
+ *
50
+ * If there is a non-root secret defined for some ancestor path P of `path`,
51
+ * we treat that ancestor path P as the "branch root" and store the ENTIRE
52
+ * subtree under P as ONE encrypted blob at that location.
53
+ *
54
+ * This means that to re-enter that channel you need both:
55
+ * - the full expression for P, and
56
+ * - the secret used at P.
57
+ */
58
+ private ensurePath;
59
+ /**
60
+ * Set a value at a nested path inside `payload`.
61
+ */
62
+ private setSubPayload;
63
+ /**
64
+ * Find the nearest ancestor path that represents an encrypted branch blob.
65
+ */
66
+ private findNearestBranchAncestor;
67
+ /**
68
+ * Write an encrypted branch blob while preserving any encrypted ancestor branches.
69
+ */
70
+ private writeBranchBlob;
71
+ private getSubPayload;
72
+ /**
73
+ * Recursively decrypt a node of the encrypted payload tree.
74
+ */
75
+ private decryptTree;
76
+ /**
77
+ * Encrypt a value (object or primitive) using the secret resolved for the given path.
78
+ * Produces a hex string compatible with decryptForPath().
79
+ */
80
+ private encryptForPath;
36
81
  /**
37
- * Firma genérica de mensajes si se necesita fuera de las declaraciones.
82
+ * Decrypt a single encrypted blob using the secret resolved for the given path.
38
83
  */
39
- sign(message: string): string;
84
+ private decryptForPath;
85
+ private asciiToBytes;
86
+ private hexToBytes;
87
+ private isHexString;
40
88
  /**
41
- * Exportar el snapshot de ME para mandarlo a Cleaker (ledger, graph, etc.).
89
+ * Export the encrypted payload and declaration metadata.
42
90
  */
43
91
  export(): {
44
92
  identityRoot: string;
45
93
  publicKey: string;
46
- namespace: string;
47
94
  identityHash: string;
48
95
  declarations: MeDeclaration[];
96
+ payload: any;
49
97
  };
50
- ptr(declaration: MeDeclaration): {
51
- __pointer: string;
52
- };
98
+ /**
99
+ * Export and decrypt a specific branch using the currently active secret
100
+ * resolved for that path.
101
+ */
102
+ exportBranch(path: string): any;
53
103
  }
104
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "this.me",
3
- "version": "3.0.26",
3
+ "version": "3.0.28",
4
4
  "description": ".me is your identity trust through cryptographic signatures.",
5
5
  "main": "dist/me.cjs.js",
6
6
  "module": "dist/me.es.js",
package/dist/me.cjs.js DELETED
@@ -1,8 +0,0 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var ae=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ue(v){return v&&v.__esModule&&Object.prototype.hasOwnProperty.call(v,"default")?v.default:v}var Pt={exports:{}};/**
2
- * [js-sha3]{@link https://github.com/emn178/js-sha3}
3
- *
4
- * @version 0.9.3
5
- * @author Chen, Yi-Cyuan [emn178@gmail.com]
6
- * @copyright Chen, Yi-Cyuan 2015-2023
7
- * @license MIT
8
- */var Qt;function fe(){return Qt||(Qt=1,(function(v){(function(){var y="input is invalid type",M="finalize already called",R=typeof window=="object",b=R?window:{};b.JS_SHA3_NO_WINDOW&&(R=!1);var F=!R&&typeof self=="object",k=!b.JS_SHA3_NO_NODE_JS&&typeof process=="object"&&process.versions&&process.versions.node;k?b=ae:F&&(b=self);for(var g=!b.JS_SHA3_NO_COMMON_JS&&!0&&v.exports,w=!b.JS_SHA3_NO_ARRAY_BUFFER&&typeof ArrayBuffer<"u",h="0123456789abcdef".split(""),Dt=[31,7936,2031616,520093696],N=[4,1024,262144,67108864],x=[1,256,65536,16777216],te=[6,1536,393216,100663296],d=[0,8,16,24],Tt=[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],mt=[224,256,384,512],Ht=[128,256],Ut=["hex","buffer","arrayBuffer","array","digest"],Wt={128:168,256:136},ee=b.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return Object.prototype.toString.call(t)==="[object Array]"}:Array.isArray,re=w&&(b.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW||!ArrayBuffer.isView)?function(t){return typeof t=="object"&&t.buffer&&t.buffer.constructor===ArrayBuffer}:ArrayBuffer.isView,Kt=function(t){var e=typeof t;if(e==="string")return[t,!0];if(e!=="object"||t===null)throw new Error(y);if(w&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!ee(t)&&!re(t))throw new Error(y);return[t,!1]},Gt=function(t){return Kt(t)[0].length===0},zt=function(t){for(var e=[],r=0;r<t.length;++r)e[r]=t[r];return e},Yt=function(t,e,r){return function(n){return new l(t,e,t).update(n)[r]()}},Vt=function(t,e,r){return function(n,o){return new l(t,e,o).update(n)[r]()}},qt=function(t,e,r){return function(n,o,i,u){return _["cshake"+t].update(n,o,i,u)[r]()}},Lt=function(t,e,r){return function(n,o,i,u){return _["kmac"+t].update(n,o,i,u)[r]()}},I=function(t,e,r,n){for(var o=0;o<Ut.length;++o){var i=Ut[o];t[i]=e(r,n,i)}return t},Xt=function(t,e){var r=Yt(t,e,"hex");return r.create=function(){return new l(t,e,t)},r.update=function(n){return r.create().update(n)},I(r,Yt,t,e)},ne=function(t,e){var r=Vt(t,e,"hex");return r.create=function(n){return new l(t,e,n)},r.update=function(n,o){return r.create(o).update(n)},I(r,Vt,t,e)},oe=function(t,e){var r=Wt[t],n=qt(t,e,"hex");return n.create=function(o,i,u){return Gt(i)&&Gt(u)?_["shake"+t].create(o):new l(t,e,o).bytepad([i,u],r)},n.update=function(o,i,u,a){return n.create(i,u,a).update(o)},I(n,qt,t,e)},ie=function(t,e){var r=Wt[t],n=Lt(t,e,"hex");return n.create=function(o,i,u){return new jt(t,e,i).bytepad(["KMAC",u],r).bytepad([o],r)},n.update=function(o,i,u,a){return n.create(o,u,a).update(i)},I(n,Lt,t,e)},Zt=[{name:"keccak",padding:x,bits:mt,createMethod:Xt},{name:"sha3",padding:te,bits:mt,createMethod:Xt},{name:"shake",padding:Dt,bits:Ht,createMethod:ne},{name:"cshake",padding:N,bits:Ht,createMethod:oe},{name:"kmac",padding:N,bits:Ht,createMethod:ie}],_={},B=[],A=0;A<Zt.length;++A)for(var S=Zt[A],D=S.bits,C=0;C<D.length;++C){var Jt=S.name+"_"+D[C];if(B.push(Jt),_[Jt]=S.createMethod(D[C],S.padding),S.name!=="sha3"){var $t=S.name+D[C];B.push($t),_[$t]=_[Jt]}}function l(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}l.prototype.update=function(t){if(this.finalized)throw new Error(M);var e=Kt(t);t=e[0];for(var r=e[1],n=this.blocks,o=this.byteCount,i=t.length,u=this.blockCount,a=0,p=this.s,f,c;a<i;){if(this.reset)for(this.reset=!1,n[0]=this.block,f=1;f<u+1;++f)n[f]=0;if(r)for(f=this.start;a<i&&f<o;++a)c=t.charCodeAt(a),c<128?n[f>>2]|=c<<d[f++&3]:c<2048?(n[f>>2]|=(192|c>>6)<<d[f++&3],n[f>>2]|=(128|c&63)<<d[f++&3]):c<55296||c>=57344?(n[f>>2]|=(224|c>>12)<<d[f++&3],n[f>>2]|=(128|c>>6&63)<<d[f++&3],n[f>>2]|=(128|c&63)<<d[f++&3]):(c=65536+((c&1023)<<10|t.charCodeAt(++a)&1023),n[f>>2]|=(240|c>>18)<<d[f++&3],n[f>>2]|=(128|c>>12&63)<<d[f++&3],n[f>>2]|=(128|c>>6&63)<<d[f++&3],n[f>>2]|=(128|c&63)<<d[f++&3]);else for(f=this.start;a<i&&f<o;++a)n[f>>2]|=t[a]<<d[f++&3];if(this.lastByteIndex=f,f>=o){for(this.start=f-o,this.block=n[u],f=0;f<u;++f)p[f]^=n[f];O(p),this.reset=!0}else this.start=f}return this},l.prototype.encode=function(t,e){var r=t&255,n=1,o=[r];for(t=t>>8,r=t&255;r>0;)o.unshift(r),t=t>>8,r=t&255,++n;return e?o.push(n):o.unshift(n),this.update(o),o.length},l.prototype.encodeString=function(t){var e=Kt(t);t=e[0];var r=e[1],n=0,o=t.length;if(r)for(var i=0;i<t.length;++i){var u=t.charCodeAt(i);u<128?n+=1:u<2048?n+=2:u<55296||u>=57344?n+=3:(u=65536+((u&1023)<<10|t.charCodeAt(++i)&1023),n+=4)}else n=o;return n+=this.encode(n*8),this.update(t),n},l.prototype.bytepad=function(t,e){for(var r=this.encode(e),n=0;n<t.length;++n)r+=this.encodeString(t[n]);var o=(e-r%e)%e,i=[];return i.length=o,this.update(i),this},l.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];O(n)}},l.prototype.toString=l.prototype.hex=function(){this.finalize();for(var t=this.blockCount,e=this.s,r=this.outputBlocks,n=this.extraBytes,o=0,i=0,u="",a;i<r;){for(o=0;o<t&&i<r;++o,++i)a=e[o],u+=h[a>>4&15]+h[a&15]+h[a>>12&15]+h[a>>8&15]+h[a>>20&15]+h[a>>16&15]+h[a>>28&15]+h[a>>24&15];i%t===0&&(e=zt(e),O(e),o=0)}return n&&(a=e[o],u+=h[a>>4&15]+h[a&15],n>1&&(u+=h[a>>12&15]+h[a>>8&15]),n>2&&(u+=h[a>>20&15]+h[a>>16&15])),u},l.prototype.arrayBuffer=function(){this.finalize();var t=this.blockCount,e=this.s,r=this.outputBlocks,n=this.extraBytes,o=0,i=0,u=this.outputBits>>3,a;n?a=new ArrayBuffer(r+1<<2):a=new ArrayBuffer(u);for(var p=new Uint32Array(a);i<r;){for(o=0;o<t&&i<r;++o,++i)p[i]=e[o];i%t===0&&(e=zt(e),O(e))}return n&&(p[i]=e[o],a=a.slice(0,u)),a},l.prototype.buffer=l.prototype.arrayBuffer,l.prototype.digest=l.prototype.array=function(){this.finalize();for(var t=this.blockCount,e=this.s,r=this.outputBlocks,n=this.extraBytes,o=0,i=0,u=[],a,p;i<r;){for(o=0;o<t&&i<r;++o,++i)a=i<<2,p=e[o],u[a]=p&255,u[a+1]=p>>8&255,u[a+2]=p>>16&255,u[a+3]=p>>24&255;i%t===0&&(e=zt(e),O(e))}return n&&(a=i<<2,p=e[o],u[a]=p&255,n>1&&(u[a+1]=p>>8&255),n>2&&(u[a+2]=p>>16&255)),u};function jt(t,e,r){l.call(this,t,e,r)}jt.prototype=new l,jt.prototype.finalize=function(){return this.encode(this.outputBits,!0),l.prototype.finalize.call(this)};var O=function(t){var e,r,n,o,i,u,a,p,f,c,H,K,z,J,j,P,T,m,U,W,G,Y,V,q,L,X,Z,$,Q,s,tt,et,rt,nt,ot,it,at,ut,ft,ct,ht,lt,pt,bt,dt,yt,vt,xt,_t,At,kt,St,Ft,wt,Bt,Ct,Ot,Et,Mt,Rt,gt,Nt,It;for(n=0;n<48;n+=2)o=t[0]^t[10]^t[20]^t[30]^t[40],i=t[1]^t[11]^t[21]^t[31]^t[41],u=t[2]^t[12]^t[22]^t[32]^t[42],a=t[3]^t[13]^t[23]^t[33]^t[43],p=t[4]^t[14]^t[24]^t[34]^t[44],f=t[5]^t[15]^t[25]^t[35]^t[45],c=t[6]^t[16]^t[26]^t[36]^t[46],H=t[7]^t[17]^t[27]^t[37]^t[47],K=t[8]^t[18]^t[28]^t[38]^t[48],z=t[9]^t[19]^t[29]^t[39]^t[49],e=K^(u<<1|a>>>31),r=z^(a<<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=o^(p<<1|f>>>31),r=i^(f<<1|p>>>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^(c<<1|H>>>31),r=a^(H<<1|c>>>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=p^(K<<1|z>>>31),r=f^(z<<1|K>>>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=c^(o<<1|i>>>31),r=H^(i<<1|o>>>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,J=t[0],j=t[1],yt=t[11]<<4|t[10]>>>28,vt=t[10]<<4|t[11]>>>28,$=t[20]<<3|t[21]>>>29,Q=t[21]<<3|t[20]>>>29,Rt=t[31]<<9|t[30]>>>23,gt=t[30]<<9|t[31]>>>23,lt=t[40]<<18|t[41]>>>14,pt=t[41]<<18|t[40]>>>14,nt=t[2]<<1|t[3]>>>31,ot=t[3]<<1|t[2]>>>31,P=t[13]<<12|t[12]>>>20,T=t[12]<<12|t[13]>>>20,xt=t[22]<<10|t[23]>>>22,_t=t[23]<<10|t[22]>>>22,s=t[33]<<13|t[32]>>>19,tt=t[32]<<13|t[33]>>>19,Nt=t[42]<<2|t[43]>>>30,It=t[43]<<2|t[42]>>>30,wt=t[5]<<30|t[4]>>>2,Bt=t[4]<<30|t[5]>>>2,it=t[14]<<6|t[15]>>>26,at=t[15]<<6|t[14]>>>26,m=t[25]<<11|t[24]>>>21,U=t[24]<<11|t[25]>>>21,At=t[34]<<15|t[35]>>>17,kt=t[35]<<15|t[34]>>>17,et=t[45]<<29|t[44]>>>3,rt=t[44]<<29|t[45]>>>3,q=t[6]<<28|t[7]>>>4,L=t[7]<<28|t[6]>>>4,Ct=t[17]<<23|t[16]>>>9,Ot=t[16]<<23|t[17]>>>9,ut=t[26]<<25|t[27]>>>7,ft=t[27]<<25|t[26]>>>7,W=t[36]<<21|t[37]>>>11,G=t[37]<<21|t[36]>>>11,St=t[47]<<24|t[46]>>>8,Ft=t[46]<<24|t[47]>>>8,bt=t[8]<<27|t[9]>>>5,dt=t[9]<<27|t[8]>>>5,X=t[18]<<20|t[19]>>>12,Z=t[19]<<20|t[18]>>>12,Et=t[29]<<7|t[28]>>>25,Mt=t[28]<<7|t[29]>>>25,ct=t[38]<<8|t[39]>>>24,ht=t[39]<<8|t[38]>>>24,Y=t[48]<<14|t[49]>>>18,V=t[49]<<14|t[48]>>>18,t[0]=J^~P&m,t[1]=j^~T&U,t[10]=q^~X&$,t[11]=L^~Z&Q,t[20]=nt^~it&ut,t[21]=ot^~at&ft,t[30]=bt^~yt&xt,t[31]=dt^~vt&_t,t[40]=wt^~Ct&Et,t[41]=Bt^~Ot&Mt,t[2]=P^~m&W,t[3]=T^~U&G,t[12]=X^~$&s,t[13]=Z^~Q&tt,t[22]=it^~ut&ct,t[23]=at^~ft&ht,t[32]=yt^~xt&At,t[33]=vt^~_t&kt,t[42]=Ct^~Et&Rt,t[43]=Ot^~Mt&gt,t[4]=m^~W&Y,t[5]=U^~G&V,t[14]=$^~s&et,t[15]=Q^~tt&rt,t[24]=ut^~ct&lt,t[25]=ft^~ht&pt,t[34]=xt^~At&St,t[35]=_t^~kt&Ft,t[44]=Et^~Rt&Nt,t[45]=Mt^~gt&It,t[6]=W^~Y&J,t[7]=G^~V&j,t[16]=s^~et&q,t[17]=tt^~rt&L,t[26]=ct^~lt&nt,t[27]=ht^~pt&ot,t[36]=At^~St&bt,t[37]=kt^~Ft&dt,t[46]=Rt^~Nt&wt,t[47]=gt^~It&Bt,t[8]=Y^~J&P,t[9]=V^~j&T,t[18]=et^~q&X,t[19]=rt^~L&Z,t[28]=lt^~nt&it,t[29]=pt^~ot&at,t[38]=St^~bt&yt,t[39]=Ft^~dt&vt,t[48]=Nt^~wt&Ct,t[49]=It^~Bt&Ot,t[0]^=Tt[n],t[1]^=Tt[n+1]};if(g)v.exports=_;else for(A=0;A<B.length;++A)b[B[A]]=_[B[A]]})()})(Pt)),Pt.exports}var ce=fe();const he=ue(ce),{keccak256:E}=he;class st{constructor(y,M){return this.declarations=[],this.secret=y,this.namespace=M,this.identityRoot="0x"+E(y),this.publicKey="0x"+E("public:"+y),this.identityHash="0x"+E(this.publicKey+M),new Proxy(this,{get:(b,F)=>F in b?b[F]:(...k)=>{const g=String(F),w=x=>x&&typeof x=="object"&&"__pointer"in x?x.__pointer:x;let h;k.length===0?h=void 0:k.length===1?h=w(k[0]):h=k.map(x=>w(x));const Dt="0x"+E(b.secret+g+JSON.stringify(h)+b.namespace),N={key:g,value:h,signature:Dt,timestamp:Date.now()};return b.declarations.push(N),b}})}sign(y){return"0x"+E(this.secret+y)}export(){return{identityRoot:this.identityRoot,publicKey:this.publicKey,namespace:this.namespace,identityHash:this.identityHash,declarations:this.declarations}}ptr(y){return{__pointer:y.signature}}}exports.ME=st;exports.default=st;
@@ -1 +0,0 @@
1
- export {};