UNPKG

wowok_agent

Version:

Create, collaborate, and transact on your own terms with the AI-driven web3 collaboration protocol.

2 lines 15 kB
/*! For license information please see 57.f28a91a8d8cd7f88eafb.js.LICENSE.txt */ "use strict";(this.webpackChunkwowok_agent=this.webpackChunkwowok_agent||[]).push([[57],{1057:(t,e,n)=>{n.d(e,{n:()=>E});var r=n(8030),o=n(8293);const i=BigInt(0),s=BigInt(1);function a(t,e){const n=e.negate();return t?n:e}function u(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function c(t,e){return u(t,e),{windows:Math.ceil(e/t)+1,windowSize:2**(t-1)}}const f=new WeakMap,l=new WeakMap;function d(t){return l.get(t)||1}const h=BigInt(0),w=BigInt(1),g=BigInt(2),p=BigInt(8),y={zip215:!0};function E(t){const e=function(t){const e=function(t){return(0,r.jr)(t.Fp),(0,o.Q5)(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...(0,r.LH)(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}(t);return o.Q5(t,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}(t),{Fp:n,n:E,prehash:m,hash:x,randomBytes:B,nByteLength:b,h:v}=e,A=g<<BigInt(8*b)-w,q=n.create,S=(0,r.D0)(e.n,e.nBitLength),I=e.uvRatio||((t,e)=>{try{return{isValid:!0,value:n.sqrt(t*n.inv(e))}}catch(t){return{isValid:!1,value:h}}}),z=e.adjustScalarBytes||(t=>t),O=e.domain||((t,e,n)=>{if((0,o.e8)("phflag",n),e.length||n)throw new Error("Contexts/pre-hash are not supported");return t});function R(t,e){o.aK("coordinate "+t,e,h,A)}function N(t){if(!(t instanceof C))throw new Error("ExtendedPoint expected")}const j=(0,o.x)(((t,e)=>{const{ex:r,ey:o,ez:i}=t,s=t.is0();null==e&&(e=s?p:n.inv(i));const a=q(r*e),u=q(o*e),c=q(i*e);if(s)return{x:h,y:w};if(c!==w)throw new Error("invZ was invalid");return{x:a,y:u}})),U=(0,o.x)((t=>{const{a:n,d:r}=e;if(t.is0())throw new Error("bad point: ZERO");const{ex:o,ey:i,ez:s,et:a}=t,u=q(o*o),c=q(i*i),f=q(s*s),l=q(f*f),d=q(u*n);if(q(f*q(d+c))!==q(l+q(r*q(u*c))))throw new Error("bad point: equation left != right (1)");if(q(o*i)!==q(s*a))throw new Error("bad point: equation left != right (2)");return!0}));class C{constructor(t,e,n,r){this.ex=t,this.ey=e,this.ez=n,this.et=r,R("x",t),R("y",e),R("z",n),R("t",r),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(t){if(t instanceof C)throw new Error("extended point not allowed");const{x:e,y:n}=t||{};return R("x",e),R("y",n),new C(e,n,w,q(e*n))}static normalizeZ(t){const e=n.invertBatch(t.map((t=>t.ez)));return t.map(((t,n)=>t.toAffine(e[n]))).map(C.fromAffine)}static msm(t,e){return function(t,e,n,r){if(function(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach(((t,n)=>{if(!(t instanceof e))throw new Error("invalid point at index "+n)}))}(n,t),function(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach(((t,n)=>{if(!e.isValid(t))throw new Error("invalid scalar at index "+n)}))}(r,e),n.length!==r.length)throw new Error("arrays of points and scalars must have equal length");const i=t.ZERO,s=(0,o.dJ)(BigInt(n.length)),a=s>12?s-3:s>4?s-2:s?2:1,u=(1<<a)-1,c=new Array(u+1).fill(i);let f=i;for(let t=Math.floor((e.BITS-1)/a)*a;t>=0;t-=a){c.fill(i);for(let e=0;e<r.length;e++){const o=r[e],i=Number(o>>BigInt(t)&BigInt(u));c[i]=c[i].add(n[e])}let e=i;for(let t=c.length-1,n=i;t>0;t--)n=n.add(c[t]),e=e.add(n);if(f=f.add(e),0!==t)for(let t=0;t<a;t++)f=f.double()}return f}(C,S,t,e)}_setWindowSize(t){L.setWindowSize(this,t)}assertValidity(){U(this)}equals(t){N(t);const{ex:e,ey:n,ez:r}=this,{ex:o,ey:i,ez:s}=t,a=q(e*s),u=q(o*r),c=q(n*s),f=q(i*r);return a===u&&c===f}is0(){return this.equals(C.ZERO)}negate(){return new C(q(-this.ex),this.ey,this.ez,q(-this.et))}double(){const{a:t}=e,{ex:n,ey:r,ez:o}=this,i=q(n*n),s=q(r*r),a=q(g*q(o*o)),u=q(t*i),c=n+r,f=q(q(c*c)-i-s),l=u+s,d=l-a,h=u-s,w=q(f*d),p=q(l*h),y=q(f*h),E=q(d*l);return new C(w,p,E,y)}add(t){N(t);const{a:n,d:r}=e,{ex:o,ey:i,ez:s,et:a}=this,{ex:u,ey:c,ez:f,et:l}=t;if(n===BigInt(-1)){const t=q((i-o)*(c+u)),e=q((i+o)*(c-u)),n=q(e-t);if(n===h)return this.double();const r=q(s*g*l),d=q(a*g*f),w=d+r,p=e+t,y=d-r,E=q(w*n),m=q(p*y),x=q(w*y),B=q(n*p);return new C(E,m,B,x)}const d=q(o*u),w=q(i*c),p=q(a*r*l),y=q(s*f),E=q((o+i)*(u+c)-d-w),m=y-p,x=y+p,B=q(w-n*d),b=q(E*m),v=q(x*B),A=q(E*B),S=q(m*x);return new C(b,v,S,A)}subtract(t){return this.add(t.negate())}wNAF(t){return L.wNAFCached(this,t,C.normalizeZ)}multiply(t){const e=t;o.aK("scalar",e,w,E);const{p:n,f:r}=this.wNAF(e);return C.normalizeZ([n,r])[0]}multiplyUnsafe(t,e=C.ZERO){const n=t;return o.aK("scalar",n,h,E),n===h?Z:this.is0()||n===w?this:L.wNAFCachedUnsafe(this,n,C.normalizeZ,e)}isSmallOrder(){return this.multiplyUnsafe(v).is0()}isTorsionFree(){return L.unsafeLadder(this,E).is0()}toAffine(t){return j(this,t)}clearCofactor(){const{h:t}=e;return t===w?this:this.multiplyUnsafe(t)}static fromHex(t,r=!1){const{d:i,a:s}=e,a=n.BYTES;t=(0,o.qj)("pointHex",t,a),(0,o.e8)("zip215",r);const u=t.slice(),c=t[a-1];u[a-1]=-129&c;const f=o.lX(u),l=r?A:n.ORDER;o.aK("pointHex.y",f,h,l);const d=q(f*f),g=q(d-w),p=q(i*d-s);let{isValid:y,value:E}=I(g,p);if(!y)throw new Error("Point.fromHex: invalid y coordinate");const m=(E&w)===w,x=!!(128&c);if(!r&&E===h&&x)throw new Error("Point.fromHex: x=0 and x_0=1");return x!==m&&(E=q(-E)),C.fromAffine({x:E,y:f})}static fromPrivateKey(t){return M(t).point}toRawBytes(){const{x:t,y:e}=this.toAffine(),r=o.z(e,n.BYTES);return r[r.length-1]|=t&w?128:0,r}toHex(){return o.My(this.toRawBytes())}}C.BASE=new C(e.Gx,e.Gy,w,q(e.Gx*e.Gy)),C.ZERO=new C(h,w,w,h);const{BASE:F,ZERO:Z}=C,L=(P=C,T=8*b,{constTimeNegate:a,hasPrecomputes:t=>1!==d(t),unsafeLadder(t,e,n=P.ZERO){let r=t;for(;e>i;)e&s&&(n=n.add(r)),r=r.double(),e>>=s;return n},precomputeWindow(t,e){const{windows:n,windowSize:r}=c(e,T),o=[];let i=t,s=i;for(let t=0;t<n;t++){s=i,o.push(s);for(let t=1;t<r;t++)s=s.add(i),o.push(s);i=s.double()}return o},wNAF(t,e,n){const{windows:r,windowSize:o}=c(t,T);let i=P.ZERO,u=P.BASE;const f=BigInt(2**t-1),l=2**t,d=BigInt(t);for(let t=0;t<r;t++){const r=t*o;let c=Number(n&f);n>>=d,c>o&&(c-=l,n+=s);const h=r,w=r+Math.abs(c)-1,g=t%2!=0,p=c<0;0===c?u=u.add(a(g,e[h])):i=i.add(a(p,e[w]))}return{p:i,f:u}},wNAFUnsafe(t,e,n,r=P.ZERO){const{windows:o,windowSize:a}=c(t,T),u=BigInt(2**t-1),f=2**t,l=BigInt(t);for(let t=0;t<o;t++){const o=t*a;if(n===i)break;let c=Number(n&u);if(n>>=l,c>a&&(c-=f,n+=s),0===c)continue;let d=e[o+Math.abs(c)-1];c<0&&(d=d.negate()),r=r.add(d)}return r},getPrecomputes(t,e,n){let r=f.get(e);return r||(r=this.precomputeWindow(e,t),1!==t&&f.set(e,n(r))),r},wNAFCached(t,e,n){const r=d(t);return this.wNAF(r,this.getPrecomputes(r,t,n),e)},wNAFCachedUnsafe(t,e,n,r){const o=d(t);return 1===o?this.unsafeLadder(t,e,r):this.wNAFUnsafe(o,this.getPrecomputes(o,t,n),e,r)},setWindowSize(t,e){u(e,T),l.set(t,e),f.delete(t)}});var P,T;function k(t){return(0,r.zi)(t,E)}function K(t){return k(o.lX(t))}function M(t){const e=n.BYTES;t=(0,o.qj)("private key",t,e);const r=(0,o.qj)("hashed private key",x(t),2*e),i=z(r.slice(0,e)),s=r.slice(e,2*e),a=K(i),u=F.multiply(a),c=u.toRawBytes();return{head:i,prefix:s,scalar:a,point:u,pointBytes:c}}function H(t=new Uint8Array,...e){const n=o.Id(...e);return K(x(O(n,(0,o.qj)("context",t),!!m)))}const W=y;return F._setWindowSize(8),{CURVE:e,getPublicKey:function(t){return M(t).pointBytes},sign:function(t,e,r={}){t=(0,o.qj)("message",t),m&&(t=m(t));const{prefix:i,scalar:s,pointBytes:a}=M(e),u=H(r.context,i,t),c=F.multiply(u).toRawBytes(),f=k(u+H(r.context,c,a,t)*s);o.aK("signature.s",f,h,E);const l=o.Id(c,o.z(f,n.BYTES));return(0,o.qj)("result",l,2*n.BYTES)},verify:function(t,e,r,i=W){const{context:s,zip215:a}=i,u=n.BYTES;t=(0,o.qj)("signature",t,2*u),e=(0,o.qj)("message",e),r=(0,o.qj)("publicKey",r,u),void 0!==a&&(0,o.e8)("zip215",a),m&&(e=m(e));const c=o.lX(t.slice(u,2*u));let f,l,d;try{f=C.fromHex(r,a),l=C.fromHex(t.slice(0,u),a),d=F.multiplyUnsafe(c)}catch(t){return!1}if(!a&&f.isSmallOrder())return!1;const h=H(s,l.toRawBytes(),f.toRawBytes(),e);return l.add(f.multiplyUnsafe(h)).subtract(d).clearCofactor().equals(C.ZERO)},ExtendedPoint:C,utils:{getExtendedPublicKey:M,randomPrivateKey:()=>B(n.BYTES),precompute:(t=8,e=C.BASE)=>(e._setWindowSize(t),e.multiply(BigInt(3)),e)}}}},8030:(t,e,n)=>{n.d(e,{D0:()=>m,LH:()=>E,dQ:()=>g,jr:()=>y,zH:()=>h,zi:()=>l});var r=n(8293);const o=BigInt(0),i=BigInt(1),s=BigInt(2),a=BigInt(3),u=BigInt(4),c=BigInt(5),f=BigInt(8);function l(t,e){const n=t%e;return n>=o?n:e+n}function d(t,e,n){if(e<o)throw new Error("invalid exponent, negatives unsupported");if(n<=o)throw new Error("invalid modulus");if(n===i)return o;let r=i;for(;e>o;)e&i&&(r=r*t%n),t=t*t%n,e>>=i;return r}function h(t,e,n){let r=t;for(;e-- >o;)r*=r,r%=n;return r}function w(t,e){if(t===o)throw new Error("invert: expected non-zero number");if(e<=o)throw new Error("invert: expected positive modulus, got "+e);let n=l(t,e),r=e,s=o,a=i,u=i,c=o;for(;n!==o;){const t=r/n,e=r%n,o=s-u*t,i=a-c*t;r=n,n=e,s=u,a=c,u=o,c=i}if(r!==i)throw new Error("invert: does not exist");return l(s,e)}const g=(t,e)=>(l(t,e)&i)===i,p=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function y(t){const e=p.reduce(((t,e)=>(t[e]="function",t)),{ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"});return(0,r.Q5)(t,e)}function E(t,e){const n=void 0!==e?e:t.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function m(t,e,n=!1,h={}){if(t<=o)throw new Error("invalid field: expected ORDER > 0, got "+t);const{nBitLength:g,nByteLength:p}=E(t,e);if(p>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let y;const m=Object.freeze({ORDER:t,isLE:n,BITS:g,BYTES:p,MASK:(0,r.OG)(g),ZERO:o,ONE:i,create:e=>l(e,t),isValid:e=>{if("bigint"!=typeof e)throw new Error("invalid field element: expected bigint, got "+typeof e);return o<=e&&e<t},is0:t=>t===o,isOdd:t=>(t&i)===i,neg:e=>l(-e,t),eql:(t,e)=>t===e,sqr:e=>l(e*e,t),add:(e,n)=>l(e+n,t),sub:(e,n)=>l(e-n,t),mul:(e,n)=>l(e*n,t),pow:(t,e)=>function(t,e,n){if(n<o)throw new Error("invalid exponent, negatives unsupported");if(n===o)return t.ONE;if(n===i)return e;let r=t.ONE,s=e;for(;n>o;)n&i&&(r=t.mul(r,s)),s=t.sqr(s),n>>=i;return r}(m,t,e),div:(e,n)=>l(e*w(n,t),t),sqrN:t=>t*t,addN:(t,e)=>t+e,subN:(t,e)=>t-e,mulN:(t,e)=>t*e,inv:e=>w(e,t),sqrt:h.sqrt||(e=>(y||(y=function(t){if(t%u===a){const e=(t+i)/u;return function(t,n){const r=t.pow(n,e);if(!t.eql(t.sqr(r),n))throw new Error("Cannot find square root");return r}}if(t%f===c){const e=(t-c)/f;return function(t,n){const r=t.mul(n,s),o=t.pow(r,e),i=t.mul(n,o),a=t.mul(t.mul(i,s),o),u=t.mul(i,t.sub(a,t.ONE));if(!t.eql(t.sqr(u),n))throw new Error("Cannot find square root");return u}}return function(t){const e=(t-i)/s;let n,r,a;for(n=t-i,r=0;n%s===o;n/=s,r++);for(a=s;a<t&&d(a,e,t)!==t-i;a++)if(a>1e3)throw new Error("Cannot find square root: likely non-prime P");if(1===r){const e=(t+i)/u;return function(t,n){const r=t.pow(n,e);if(!t.eql(t.sqr(r),n))throw new Error("Cannot find square root");return r}}const c=(n+i)/s;return function(t,o){if(t.pow(o,e)===t.neg(t.ONE))throw new Error("Cannot find square root");let s=r,u=t.pow(t.mul(t.ONE,a),n),f=t.pow(o,c),l=t.pow(o,n);for(;!t.eql(l,t.ONE);){if(t.eql(l,t.ZERO))return t.ZERO;let e=1;for(let n=t.sqr(l);e<s&&!t.eql(n,t.ONE);e++)n=t.sqr(n);const n=t.pow(u,i<<BigInt(s-e-1));u=t.sqr(n),f=t.mul(f,n),l=t.mul(l,u),s=e}return f}}(t)}(t)),y(m,e))),invertBatch:t=>function(t,e){const n=new Array(e.length),r=e.reduce(((e,r,o)=>t.is0(r)?e:(n[o]=e,t.mul(e,r))),t.ONE),o=t.inv(r);return e.reduceRight(((e,r,o)=>t.is0(r)?e:(n[o]=t.mul(e,n[o]),t.mul(e,r))),o),n}(m,t),cmov:(t,e,n)=>n?e:t,toBytes:t=>n?(0,r.z)(t,p):(0,r.lq)(t,p),fromBytes:t=>{if(t.length!==p)throw new Error("Field.fromBytes: expected "+p+" bytes, got "+t.length);return n?(0,r.lX)(t):(0,r.Ph)(t)}});return Object.freeze(m)}},8293:(t,e,n)=>{n.d(e,{Id:()=>x,My:()=>f,OG:()=>A,Ph:()=>g,Q5:()=>S,aK:()=>b,dJ:()=>v,e8:()=>u,lX:()=>p,lq:()=>y,qj:()=>m,x:()=>I,z:()=>E});const r=BigInt(0),o=BigInt(1),i=BigInt(2);function s(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&"Uint8Array"===t.constructor.name}function a(t){if(!s(t))throw new Error("Uint8Array expected")}function u(t,e){if("boolean"!=typeof e)throw new Error(t+" boolean expected, got "+e)}const c=Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0")));function f(t){a(t);let e="";for(let n=0;n<t.length;n++)e+=c[t[n]];return e}function l(t){if("string"!=typeof t)throw new Error("hex string expected, got "+typeof t);return""===t?r:BigInt("0x"+t)}const d={_0:48,_9:57,A:65,F:70,a:97,f:102};function h(t){return t>=d._0&&t<=d._9?t-d._0:t>=d.A&&t<=d.F?t-(d.A-10):t>=d.a&&t<=d.f?t-(d.a-10):void 0}function w(t){if("string"!=typeof t)throw new Error("hex string expected, got "+typeof t);const e=t.length,n=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(n);for(let e=0,o=0;e<n;e++,o+=2){const n=h(t.charCodeAt(o)),i=h(t.charCodeAt(o+1));if(void 0===n||void 0===i){const e=t[o]+t[o+1];throw new Error('hex string expected, got non-hex character "'+e+'" at index '+o)}r[e]=16*n+i}return r}function g(t){return l(f(t))}function p(t){return a(t),l(f(Uint8Array.from(t).reverse()))}function y(t,e){return w(t.toString(16).padStart(2*e,"0"))}function E(t,e){return y(t,e).reverse()}function m(t,e,n){let r;if("string"==typeof e)try{r=w(e)}catch(e){throw new Error(t+" must be hex string or Uint8Array, cause: "+e)}else{if(!s(e))throw new Error(t+" must be hex string or Uint8Array");r=Uint8Array.from(e)}const o=r.length;if("number"==typeof n&&o!==n)throw new Error(t+" of length "+n+" expected, got "+o);return r}function x(...t){let e=0;for(let n=0;n<t.length;n++){const r=t[n];a(r),e+=r.length}const n=new Uint8Array(e);for(let e=0,r=0;e<t.length;e++){const o=t[e];n.set(o,r),r+=o.length}return n}const B=t=>"bigint"==typeof t&&r<=t;function b(t,e,n,r){if(!function(t,e,n){return B(t)&&B(e)&&B(n)&&e<=t&&t<n}(e,n,r))throw new Error("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function v(t){let e;for(e=0;t>r;t>>=o,e+=1);return e}const A=t=>(i<<BigInt(t-1))-o,q={bigint:t=>"bigint"==typeof t,function:t=>"function"==typeof t,boolean:t=>"boolean"==typeof t,string:t=>"string"==typeof t,stringOrUint8Array:t=>"string"==typeof t||s(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>"function"==typeof t&&Number.isSafeInteger(t.outputLen)};function S(t,e,n={}){const r=(e,n,r)=>{const o=q[n];if("function"!=typeof o)throw new Error("invalid validator function");const i=t[e];if(!(r&&void 0===i||o(i,t)))throw new Error("param "+String(e)+" is invalid. Expected "+n+", got "+i)};for(const[t,n]of Object.entries(e))r(t,n,!1);for(const[t,e]of Object.entries(n))r(t,e,!0);return t}function I(t){const e=new WeakMap;return(n,...r)=>{const o=e.get(n);if(void 0!==o)return o;const i=t(n,...r);return e.set(n,i),i}}}}]);