@orderly.network/core 0.0.50 → 0.0.52
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.js +4744 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4719 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4747 @@
|
|
|
1
|
-
"use strict";var wn=Object.create;var ve=Object.defineProperty;var bn=Object.getOwnPropertyDescriptor;var An=Object.getOwnPropertyNames;var In=Object.getPrototypeOf,En=Object.prototype.hasOwnProperty;var ge=(o,n)=>()=>(o&&(n=o(o=0)),n);var ut=(o,n)=>()=>(n||o((n={exports:{}}).exports,n),n.exports),Tn=(o,n)=>{for(var a in n)ve(o,a,{get:n[a],enumerable:!0})},lt=(o,n,a,u)=>{if(n&&typeof n=="object"||typeof n=="function")for(let d of An(n))!En.call(o,d)&&d!==a&&ve(o,d,{get:()=>n[d],enumerable:!(u=bn(n,d))||u.enumerable});return o};var Re=(o,n,a)=>(a=o!=null?wn(In(o)):{},lt(n||!o||!o.__esModule?ve(a,"default",{value:o,enumerable:!0}):a,o)),vn=o=>lt(ve({},"__esModule",{value:!0}),o);var E=ge(()=>{"use strict"});function Bn(o,n){this.fun=o,this.array=n}function dt(o){var n=Math.floor((Date.now()-ne.now())*.001),a=ne.now()*.001,u=Math.floor(a)+n,d=Math.floor(a%1*1e9);return o&&(u=u-o[0],d=d-o[1],d<0&&(u--,d+=Fe)),[u,d]}var zn,ne,De,Fe,pt=ge(()=>{"use strict";E();v();T();Bn.prototype.run=function(){this.fun.apply(null,this.array)};zn={PATH:"/usr/bin",LANG:navigator.language+".UTF-8",PWD:"/",HOME:"/home",TMP:"/tmp"},ne={now:typeof performance<"u"?performance.now.bind(performance):void 0,timing:typeof performance<"u"?performance.timing:void 0};ne.now===void 0&&(De=Date.now(),ne.timing&&ne.timing.navigationStart&&(De=ne.timing.navigationStart),ne.now=()=>Date.now()-De);Fe=1e9;dt.bigint=function(o){var n=dt(o);return typeof BigInt>"u"?n[0]*Fe+n[1]:BigInt(n[0]*Fe)+BigInt(n[1])}});var T=ge(()=>{"use strict";pt()});function xn(){if(yt)return me;yt=!0,me.byteLength=f,me.toByteArray=I,me.fromByteArray=_;for(var o=[],n=[],a=typeof Uint8Array<"u"?Uint8Array:Array,u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",d=0,p=u.length;d<p;++d)o[d]=u[d],n[u.charCodeAt(d)]=d;n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63;function s(h){var m=h.length;if(m%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var B=h.indexOf("=");B===-1&&(B=m);var x=B===m?0:4-B%4;return[B,x]}function f(h){var m=s(h),B=m[0],x=m[1];return(B+x)*3/4-x}function w(h,m,B){return(m+B)*3/4-B}function I(h){var m,B=s(h),x=B[0],k=B[1],C=new a(w(h,x,k)),U=0,M=k>0?x-4:x,K;for(K=0;K<M;K+=4)m=n[h.charCodeAt(K)]<<18|n[h.charCodeAt(K+1)]<<12|n[h.charCodeAt(K+2)]<<6|n[h.charCodeAt(K+3)],C[U++]=m>>16&255,C[U++]=m>>8&255,C[U++]=m&255;return k===2&&(m=n[h.charCodeAt(K)]<<2|n[h.charCodeAt(K+1)]>>4,C[U++]=m&255),k===1&&(m=n[h.charCodeAt(K)]<<10|n[h.charCodeAt(K+1)]<<4|n[h.charCodeAt(K+2)]>>2,C[U++]=m>>8&255,C[U++]=m&255),C}function g(h){return o[h>>18&63]+o[h>>12&63]+o[h>>6&63]+o[h&63]}function A(h,m,B){for(var x,k=[],C=m;C<B;C+=3)x=(h[C]<<16&16711680)+(h[C+1]<<8&65280)+(h[C+2]&255),k.push(g(x));return k.join("")}function _(h){for(var m,B=h.length,x=B%3,k=[],C=16383,U=0,M=B-x;U<M;U+=C)k.push(A(h,U,U+C>M?M:U+C));return x===1?(m=h[B-1],k.push(o[m>>2]+o[m<<4&63]+"==")):x===2&&(m=(h[B-2]<<8)+h[B-1],k.push(o[m>>10]+o[m>>4&63]+o[m<<2&63]+"=")),k.join("")}return me}function Sn(){if(ht)return Be;ht=!0;return Be.read=function(o,n,a,u,d){var p,s,f=d*8-u-1,w=(1<<f)-1,I=w>>1,g=-7,A=a?d-1:0,_=a?-1:1,h=o[n+A];for(A+=_,p=h&(1<<-g)-1,h>>=-g,g+=f;g>0;p=p*256+o[n+A],A+=_,g-=8);for(s=p&(1<<-g)-1,p>>=-g,g+=u;g>0;s=s*256+o[n+A],A+=_,g-=8);if(p===0)p=1-I;else{if(p===w)return s?NaN:(h?-1:1)*(1/0);s=s+Math.pow(2,u),p=p-I}return(h?-1:1)*s*Math.pow(2,p-u)},Be.write=function(o,n,a,u,d,p){var s,f,w,I=p*8-d-1,g=(1<<I)-1,A=g>>1,_=d===23?Math.pow(2,-24)-Math.pow(2,-77):0,h=u?0:p-1,m=u?1:-1,B=n<0||n===0&&1/n<0?1:0;for(n=Math.abs(n),isNaN(n)||n===1/0?(f=isNaN(n)?1:0,s=g):(s=Math.floor(Math.log(n)/Math.LN2),n*(w=Math.pow(2,-s))<1&&(s--,w*=2),s+A>=1?n+=_/w:n+=_*Math.pow(2,1-A),n*w>=2&&(s++,w/=2),s+A>=g?(f=0,s=g):s+A>=1?(f=(n*w-1)*Math.pow(2,d),s=s+A):(f=n*Math.pow(2,A-1)*Math.pow(2,d),s=0));d>=8;o[a+h]=f&255,h+=m,f/=256,d-=8);for(s=s<<d|f,I+=d;I>0;o[a+h]=s&255,h+=m,s/=256,I-=8);o[a+h-m]|=B*128},Be}function Cn(){if(ft)return re;ft=!0;let o=xn(),n=Sn(),a=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;re.Buffer=s,re.SlowBuffer=k,re.INSPECT_MAX_BYTES=50;let u=2147483647;re.kMaxLength=u,s.TYPED_ARRAY_SUPPORT=d(),!s.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function d(){try{let r=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(r,e),r.foo()===42}catch{return!1}}Object.defineProperty(s.prototype,"parent",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.buffer}}),Object.defineProperty(s.prototype,"offset",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.byteOffset}});function p(r){if(r>u)throw new RangeError('The value "'+r+'" is invalid for option "size"');let e=new Uint8Array(r);return Object.setPrototypeOf(e,s.prototype),e}function s(r,e,t){if(typeof r=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return g(r)}return f(r,e,t)}s.poolSize=8192;function f(r,e,t){if(typeof r=="string")return A(r,e);if(ArrayBuffer.isView(r))return h(r);if(r==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r);if(Y(r,ArrayBuffer)||r&&Y(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Y(r,SharedArrayBuffer)||r&&Y(r.buffer,SharedArrayBuffer)))return m(r,e,t);if(typeof r=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let i=r.valueOf&&r.valueOf();if(i!=null&&i!==r)return s.from(i,e,t);let c=B(r);if(c)return c;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof r[Symbol.toPrimitive]=="function")return s.from(r[Symbol.toPrimitive]("string"),e,t);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r)}s.from=function(r,e,t){return f(r,e,t)},Object.setPrototypeOf(s.prototype,Uint8Array.prototype),Object.setPrototypeOf(s,Uint8Array);function w(r){if(typeof r!="number")throw new TypeError('"size" argument must be of type number');if(r<0)throw new RangeError('The value "'+r+'" is invalid for option "size"')}function I(r,e,t){return w(r),r<=0?p(r):e!==void 0?typeof t=="string"?p(r).fill(e,t):p(r).fill(e):p(r)}s.alloc=function(r,e,t){return I(r,e,t)};function g(r){return w(r),p(r<0?0:x(r)|0)}s.allocUnsafe=function(r){return g(r)},s.allocUnsafeSlow=function(r){return g(r)};function A(r,e){if((typeof e!="string"||e==="")&&(e="utf8"),!s.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let t=C(r,e)|0,i=p(t),c=i.write(r,e);return c!==t&&(i=i.slice(0,c)),i}function _(r){let e=r.length<0?0:x(r.length)|0,t=p(e);for(let i=0;i<e;i+=1)t[i]=r[i]&255;return t}function h(r){if(Y(r,Uint8Array)){let e=new Uint8Array(r);return m(e.buffer,e.byteOffset,e.byteLength)}return _(r)}function m(r,e,t){if(e<0||r.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(r.byteLength<e+(t||0))throw new RangeError('"length" is outside of buffer bounds');let i;return e===void 0&&t===void 0?i=new Uint8Array(r):t===void 0?i=new Uint8Array(r,e):i=new Uint8Array(r,e,t),Object.setPrototypeOf(i,s.prototype),i}function B(r){if(s.isBuffer(r)){let e=x(r.length)|0,t=p(e);return t.length===0||r.copy(t,0,0,e),t}if(r.length!==void 0)return typeof r.length!="number"||Oe(r.length)?p(0):_(r);if(r.type==="Buffer"&&Array.isArray(r.data))return _(r.data)}function x(r){if(r>=u)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+u.toString(16)+" bytes");return r|0}function k(r){return+r!=r&&(r=0),s.alloc(+r)}s.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==s.prototype},s.compare=function(e,t){if(Y(e,Uint8Array)&&(e=s.from(e,e.offset,e.byteLength)),Y(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),!s.isBuffer(e)||!s.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let i=e.length,c=t.length;for(let l=0,y=Math.min(i,c);l<y;++l)if(e[l]!==t[l]){i=e[l],c=t[l];break}return i<c?-1:c<i?1:0},s.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},s.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return s.alloc(0);let i;if(t===void 0)for(t=0,i=0;i<e.length;++i)t+=e[i].length;let c=s.allocUnsafe(t),l=0;for(i=0;i<e.length;++i){let y=e[i];if(Y(y,Uint8Array))l+y.length>c.length?(s.isBuffer(y)||(y=s.from(y)),y.copy(c,l)):Uint8Array.prototype.set.call(c,y,l);else if(s.isBuffer(y))y.copy(c,l);else throw new TypeError('"list" argument must be an Array of Buffers');l+=y.length}return c};function C(r,e){if(s.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||Y(r,ArrayBuffer))return r.byteLength;if(typeof r!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof r);let t=r.length,i=arguments.length>2&&arguments[2]===!0;if(!i&&t===0)return 0;let c=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return Ne(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return ct(r).length;default:if(c)return i?-1:Ne(r).length;e=(""+e).toLowerCase(),c=!0}}s.byteLength=C;function U(r,e,t){let i=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((t===void 0||t>this.length)&&(t=this.length),t<=0)||(t>>>=0,e>>>=0,t<=e))return"";for(r||(r="utf8");;)switch(r){case"hex":return un(this,e,t);case"utf8":case"utf-8":return Qe(this,e,t);case"ascii":return on(this,e,t);case"latin1":case"binary":return cn(this,e,t);case"base64":return sn(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ln(this,e,t);default:if(i)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),i=!0}}s.prototype._isBuffer=!0;function M(r,e,t){let i=r[e];r[e]=r[t],r[t]=i}s.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)M(this,t,t+1);return this},s.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)M(this,t,t+3),M(this,t+1,t+2);return this},s.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)M(this,t,t+7),M(this,t+1,t+6),M(this,t+2,t+5),M(this,t+3,t+4);return this},s.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?Qe(this,0,e):U.apply(this,arguments)},s.prototype.toLocaleString=s.prototype.toString,s.prototype.equals=function(e){if(!s.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:s.compare(this,e)===0},s.prototype.inspect=function(){let e="",t=re.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"},a&&(s.prototype[a]=s.prototype.inspect),s.prototype.compare=function(e,t,i,c,l){if(Y(e,Uint8Array)&&(e=s.from(e,e.offset,e.byteLength)),!s.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(t===void 0&&(t=0),i===void 0&&(i=e?e.length:0),c===void 0&&(c=0),l===void 0&&(l=this.length),t<0||i>e.length||c<0||l>this.length)throw new RangeError("out of range index");if(c>=l&&t>=i)return 0;if(c>=l)return-1;if(t>=i)return 1;if(t>>>=0,i>>>=0,c>>>=0,l>>>=0,this===e)return 0;let y=l-c,S=i-t,R=Math.min(y,S),N=this.slice(c,l),D=e.slice(t,i);for(let P=0;P<R;++P)if(N[P]!==D[P]){y=N[P],S=D[P];break}return y<S?-1:S<y?1:0};function K(r,e,t,i,c){if(r.length===0)return-1;if(typeof t=="string"?(i=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,Oe(t)&&(t=c?0:r.length-1),t<0&&(t=r.length+t),t>=r.length){if(c)return-1;t=r.length-1}else if(t<0)if(c)t=0;else return-1;if(typeof e=="string"&&(e=s.from(e,i)),s.isBuffer(e))return e.length===0?-1:H(r,e,t,i,c);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?c?Uint8Array.prototype.indexOf.call(r,e,t):Uint8Array.prototype.lastIndexOf.call(r,e,t):H(r,[e],t,i,c);throw new TypeError("val must be string, number or Buffer")}function H(r,e,t,i,c){let l=1,y=r.length,S=e.length;if(i!==void 0&&(i=String(i).toLowerCase(),i==="ucs2"||i==="ucs-2"||i==="utf16le"||i==="utf-16le")){if(r.length<2||e.length<2)return-1;l=2,y/=2,S/=2,t/=2}function R(D,P){return l===1?D[P]:D.readUInt16BE(P*l)}let N;if(c){let D=-1;for(N=t;N<y;N++)if(R(r,N)===R(e,D===-1?0:N-D)){if(D===-1&&(D=N),N-D+1===S)return D*l}else D!==-1&&(N-=N-D),D=-1}else for(t+S>y&&(t=y-S),N=t;N>=0;N--){let D=!0;for(let P=0;P<S;P++)if(R(r,N+P)!==R(e,P)){D=!1;break}if(D)return N}return-1}s.prototype.includes=function(e,t,i){return this.indexOf(e,t,i)!==-1},s.prototype.indexOf=function(e,t,i){return K(this,e,t,i,!0)},s.prototype.lastIndexOf=function(e,t,i){return K(this,e,t,i,!1)};function q(r,e,t,i){t=Number(t)||0;let c=r.length-t;i?(i=Number(i),i>c&&(i=c)):i=c;let l=e.length;i>l/2&&(i=l/2);let y;for(y=0;y<i;++y){let S=parseInt(e.substr(y*2,2),16);if(Oe(S))return y;r[t+y]=S}return y}function oe(r,e,t,i){return Te(Ne(e,r.length-t),r,t,i)}function tn(r,e,t,i){return Te(hn(e),r,t,i)}function nn(r,e,t,i){return Te(ct(e),r,t,i)}function rn(r,e,t,i){return Te(fn(e,r.length-t),r,t,i)}s.prototype.write=function(e,t,i,c){if(t===void 0)c="utf8",i=this.length,t=0;else if(i===void 0&&typeof t=="string")c=t,i=this.length,t=0;else if(isFinite(t))t=t>>>0,isFinite(i)?(i=i>>>0,c===void 0&&(c="utf8")):(c=i,i=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let l=this.length-t;if((i===void 0||i>l)&&(i=l),e.length>0&&(i<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");c||(c="utf8");let y=!1;for(;;)switch(c){case"hex":return q(this,e,t,i);case"utf8":case"utf-8":return oe(this,e,t,i);case"ascii":case"latin1":case"binary":return tn(this,e,t,i);case"base64":return nn(this,e,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return rn(this,e,t,i);default:if(y)throw new TypeError("Unknown encoding: "+c);c=(""+c).toLowerCase(),y=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function sn(r,e,t){return e===0&&t===r.length?o.fromByteArray(r):o.fromByteArray(r.slice(e,t))}function Qe(r,e,t){t=Math.min(r.length,t);let i=[],c=e;for(;c<t;){let l=r[c],y=null,S=l>239?4:l>223?3:l>191?2:1;if(c+S<=t){let R,N,D,P;switch(S){case 1:l<128&&(y=l);break;case 2:R=r[c+1],(R&192)===128&&(P=(l&31)<<6|R&63,P>127&&(y=P));break;case 3:R=r[c+1],N=r[c+2],(R&192)===128&&(N&192)===128&&(P=(l&15)<<12|(R&63)<<6|N&63,P>2047&&(P<55296||P>57343)&&(y=P));break;case 4:R=r[c+1],N=r[c+2],D=r[c+3],(R&192)===128&&(N&192)===128&&(D&192)===128&&(P=(l&15)<<18|(R&63)<<12|(N&63)<<6|D&63,P>65535&&P<1114112&&(y=P))}}y===null?(y=65533,S=1):y>65535&&(y-=65536,i.push(y>>>10&1023|55296),y=56320|y&1023),i.push(y),c+=S}return an(i)}let et=4096;function an(r){let e=r.length;if(e<=et)return String.fromCharCode.apply(String,r);let t="",i=0;for(;i<e;)t+=String.fromCharCode.apply(String,r.slice(i,i+=et));return t}function on(r,e,t){let i="";t=Math.min(r.length,t);for(let c=e;c<t;++c)i+=String.fromCharCode(r[c]&127);return i}function cn(r,e,t){let i="";t=Math.min(r.length,t);for(let c=e;c<t;++c)i+=String.fromCharCode(r[c]);return i}function un(r,e,t){let i=r.length;(!e||e<0)&&(e=0),(!t||t<0||t>i)&&(t=i);let c="";for(let l=e;l<t;++l)c+=gn[r[l]];return c}function ln(r,e,t){let i=r.slice(e,t),c="";for(let l=0;l<i.length-1;l+=2)c+=String.fromCharCode(i[l]+i[l+1]*256);return c}s.prototype.slice=function(e,t){let i=this.length;e=~~e,t=t===void 0?i:~~t,e<0?(e+=i,e<0&&(e=0)):e>i&&(e=i),t<0?(t+=i,t<0&&(t=0)):t>i&&(t=i),t<e&&(t=e);let c=this.subarray(e,t);return Object.setPrototypeOf(c,s.prototype),c};function V(r,e,t){if(r%1!==0||r<0)throw new RangeError("offset is not uint");if(r+e>t)throw new RangeError("Trying to access beyond buffer length")}s.prototype.readUintLE=s.prototype.readUIntLE=function(e,t,i){e=e>>>0,t=t>>>0,i||V(e,t,this.length);let c=this[e],l=1,y=0;for(;++y<t&&(l*=256);)c+=this[e+y]*l;return c},s.prototype.readUintBE=s.prototype.readUIntBE=function(e,t,i){e=e>>>0,t=t>>>0,i||V(e,t,this.length);let c=this[e+--t],l=1;for(;t>0&&(l*=256);)c+=this[e+--t]*l;return c},s.prototype.readUint8=s.prototype.readUInt8=function(e,t){return e=e>>>0,t||V(e,1,this.length),this[e]},s.prototype.readUint16LE=s.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||V(e,2,this.length),this[e]|this[e+1]<<8},s.prototype.readUint16BE=s.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||V(e,2,this.length),this[e]<<8|this[e+1]},s.prototype.readUint32LE=s.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||V(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216},s.prototype.readUint32BE=s.prototype.readUInt32BE=function(e,t){return e=e>>>0,t||V(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])},s.prototype.readBigUInt64LE=Q(function(e){e=e>>>0,ue(e,"offset");let t=this[e],i=this[e+7];(t===void 0||i===void 0)&&fe(e,this.length-8);let c=t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,l=this[++e]+this[++e]*2**8+this[++e]*2**16+i*2**24;return BigInt(c)+(BigInt(l)<<BigInt(32))}),s.prototype.readBigUInt64BE=Q(function(e){e=e>>>0,ue(e,"offset");let t=this[e],i=this[e+7];(t===void 0||i===void 0)&&fe(e,this.length-8);let c=t*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],l=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+i;return(BigInt(c)<<BigInt(32))+BigInt(l)}),s.prototype.readIntLE=function(e,t,i){e=e>>>0,t=t>>>0,i||V(e,t,this.length);let c=this[e],l=1,y=0;for(;++y<t&&(l*=256);)c+=this[e+y]*l;return l*=128,c>=l&&(c-=Math.pow(2,8*t)),c},s.prototype.readIntBE=function(e,t,i){e=e>>>0,t=t>>>0,i||V(e,t,this.length);let c=t,l=1,y=this[e+--c];for(;c>0&&(l*=256);)y+=this[e+--c]*l;return l*=128,y>=l&&(y-=Math.pow(2,8*t)),y},s.prototype.readInt8=function(e,t){return e=e>>>0,t||V(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]},s.prototype.readInt16LE=function(e,t){e=e>>>0,t||V(e,2,this.length);let i=this[e]|this[e+1]<<8;return i&32768?i|4294901760:i},s.prototype.readInt16BE=function(e,t){e=e>>>0,t||V(e,2,this.length);let i=this[e+1]|this[e]<<8;return i&32768?i|4294901760:i},s.prototype.readInt32LE=function(e,t){return e=e>>>0,t||V(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},s.prototype.readInt32BE=function(e,t){return e=e>>>0,t||V(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},s.prototype.readBigInt64LE=Q(function(e){e=e>>>0,ue(e,"offset");let t=this[e],i=this[e+7];(t===void 0||i===void 0)&&fe(e,this.length-8);let c=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(i<<24);return(BigInt(c)<<BigInt(32))+BigInt(t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)}),s.prototype.readBigInt64BE=Q(function(e){e=e>>>0,ue(e,"offset");let t=this[e],i=this[e+7];(t===void 0||i===void 0)&&fe(e,this.length-8);let c=(t<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(c)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+i)}),s.prototype.readFloatLE=function(e,t){return e=e>>>0,t||V(e,4,this.length),n.read(this,e,!0,23,4)},s.prototype.readFloatBE=function(e,t){return e=e>>>0,t||V(e,4,this.length),n.read(this,e,!1,23,4)},s.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||V(e,8,this.length),n.read(this,e,!0,52,8)},s.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||V(e,8,this.length),n.read(this,e,!1,52,8)};function z(r,e,t,i,c,l){if(!s.isBuffer(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>c||e<l)throw new RangeError('"value" argument is out of bounds');if(t+i>r.length)throw new RangeError("Index out of range")}s.prototype.writeUintLE=s.prototype.writeUIntLE=function(e,t,i,c){if(e=+e,t=t>>>0,i=i>>>0,!c){let S=Math.pow(2,8*i)-1;z(this,e,t,i,S,0)}let l=1,y=0;for(this[t]=e&255;++y<i&&(l*=256);)this[t+y]=e/l&255;return t+i},s.prototype.writeUintBE=s.prototype.writeUIntBE=function(e,t,i,c){if(e=+e,t=t>>>0,i=i>>>0,!c){let S=Math.pow(2,8*i)-1;z(this,e,t,i,S,0)}let l=i-1,y=1;for(this[t+l]=e&255;--l>=0&&(y*=256);)this[t+l]=e/y&255;return t+i},s.prototype.writeUint8=s.prototype.writeUInt8=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,1,255,0),this[t]=e&255,t+1},s.prototype.writeUint16LE=s.prototype.writeUInt16LE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2},s.prototype.writeUint16BE=s.prototype.writeUInt16BE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2},s.prototype.writeUint32LE=s.prototype.writeUInt32LE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e&255,t+4},s.prototype.writeUint32BE=s.prototype.writeUInt32BE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};function tt(r,e,t,i,c){ot(e,i,c,r,t,7);let l=Number(e&BigInt(4294967295));r[t++]=l,l=l>>8,r[t++]=l,l=l>>8,r[t++]=l,l=l>>8,r[t++]=l;let y=Number(e>>BigInt(32)&BigInt(4294967295));return r[t++]=y,y=y>>8,r[t++]=y,y=y>>8,r[t++]=y,y=y>>8,r[t++]=y,t}function nt(r,e,t,i,c){ot(e,i,c,r,t,7);let l=Number(e&BigInt(4294967295));r[t+7]=l,l=l>>8,r[t+6]=l,l=l>>8,r[t+5]=l,l=l>>8,r[t+4]=l;let y=Number(e>>BigInt(32)&BigInt(4294967295));return r[t+3]=y,y=y>>8,r[t+2]=y,y=y>>8,r[t+1]=y,y=y>>8,r[t]=y,t+8}s.prototype.writeBigUInt64LE=Q(function(e,t=0){return tt(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),s.prototype.writeBigUInt64BE=Q(function(e,t=0){return nt(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),s.prototype.writeIntLE=function(e,t,i,c){if(e=+e,t=t>>>0,!c){let R=Math.pow(2,8*i-1);z(this,e,t,i,R-1,-R)}let l=0,y=1,S=0;for(this[t]=e&255;++l<i&&(y*=256);)e<0&&S===0&&this[t+l-1]!==0&&(S=1),this[t+l]=(e/y>>0)-S&255;return t+i},s.prototype.writeIntBE=function(e,t,i,c){if(e=+e,t=t>>>0,!c){let R=Math.pow(2,8*i-1);z(this,e,t,i,R-1,-R)}let l=i-1,y=1,S=0;for(this[t+l]=e&255;--l>=0&&(y*=256);)e<0&&S===0&&this[t+l+1]!==0&&(S=1),this[t+l]=(e/y>>0)-S&255;return t+i},s.prototype.writeInt8=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1},s.prototype.writeInt16LE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2},s.prototype.writeInt16BE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2},s.prototype.writeInt32LE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,4,2147483647,-2147483648),this[t]=e&255,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},s.prototype.writeInt32BE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4},s.prototype.writeBigInt64LE=Q(function(e,t=0){return tt(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),s.prototype.writeBigInt64BE=Q(function(e,t=0){return nt(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function rt(r,e,t,i,c,l){if(t+i>r.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function it(r,e,t,i,c){return e=+e,t=t>>>0,c||rt(r,e,t,4),n.write(r,e,t,i,23,4),t+4}s.prototype.writeFloatLE=function(e,t,i){return it(this,e,t,!0,i)},s.prototype.writeFloatBE=function(e,t,i){return it(this,e,t,!1,i)};function st(r,e,t,i,c){return e=+e,t=t>>>0,c||rt(r,e,t,8),n.write(r,e,t,i,52,8),t+8}s.prototype.writeDoubleLE=function(e,t,i){return st(this,e,t,!0,i)},s.prototype.writeDoubleBE=function(e,t,i){return st(this,e,t,!1,i)},s.prototype.copy=function(e,t,i,c){if(!s.isBuffer(e))throw new TypeError("argument should be a Buffer");if(i||(i=0),!c&&c!==0&&(c=this.length),t>=e.length&&(t=e.length),t||(t=0),c>0&&c<i&&(c=i),c===i||e.length===0||this.length===0)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("Index out of range");if(c<0)throw new RangeError("sourceEnd out of bounds");c>this.length&&(c=this.length),e.length-t<c-i&&(c=e.length-t+i);let l=c-i;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(t,i,c):Uint8Array.prototype.set.call(e,this.subarray(i,c),t),l},s.prototype.fill=function(e,t,i,c){if(typeof e=="string"){if(typeof t=="string"?(c=t,t=0,i=this.length):typeof i=="string"&&(c=i,i=this.length),c!==void 0&&typeof c!="string")throw new TypeError("encoding must be a string");if(typeof c=="string"&&!s.isEncoding(c))throw new TypeError("Unknown encoding: "+c);if(e.length===1){let y=e.charCodeAt(0);(c==="utf8"&&y<128||c==="latin1")&&(e=y)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(t<0||this.length<t||this.length<i)throw new RangeError("Out of range index");if(i<=t)return this;t=t>>>0,i=i===void 0?this.length:i>>>0,e||(e=0);let l;if(typeof e=="number")for(l=t;l<i;++l)this[l]=e;else{let y=s.isBuffer(e)?e:s.from(e,c),S=y.length;if(S===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(l=0;l<i-t;++l)this[l+t]=y[l%S]}return this};let ce={};function Ke(r,e,t){ce[r]=class extends t{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${r}]`,this.stack,delete this.name}get code(){return r}set code(c){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:c,writable:!0})}toString(){return`${this.name} [${r}]: ${this.message}`}}}Ke("ERR_BUFFER_OUT_OF_BOUNDS",function(r){return r?`${r} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),Ke("ERR_INVALID_ARG_TYPE",function(r,e){return`The "${r}" argument must be of type number. Received type ${typeof e}`},TypeError),Ke("ERR_OUT_OF_RANGE",function(r,e,t){let i=`The value of "${r}" is out of range.`,c=t;return Number.isInteger(t)&&Math.abs(t)>2**32?c=at(String(t)):typeof t=="bigint"&&(c=String(t),(t>BigInt(2)**BigInt(32)||t<-(BigInt(2)**BigInt(32)))&&(c=at(c)),c+="n"),i+=` It must be ${e}. Received ${c}`,i},RangeError);function at(r){let e="",t=r.length,i=r[0]==="-"?1:0;for(;t>=i+4;t-=3)e=`_${r.slice(t-3,t)}${e}`;return`${r.slice(0,t)}${e}`}function dn(r,e,t){ue(e,"offset"),(r[e]===void 0||r[e+t]===void 0)&&fe(e,r.length-(t+1))}function ot(r,e,t,i,c,l){if(r>t||r<e){let y=typeof e=="bigint"?"n":"",S;throw l>3?e===0||e===BigInt(0)?S=`>= 0${y} and < 2${y} ** ${(l+1)*8}${y}`:S=`>= -(2${y} ** ${(l+1)*8-1}${y}) and < 2 ** ${(l+1)*8-1}${y}`:S=`>= ${e}${y} and <= ${t}${y}`,new ce.ERR_OUT_OF_RANGE("value",S,r)}dn(i,c,l)}function ue(r,e){if(typeof r!="number")throw new ce.ERR_INVALID_ARG_TYPE(e,"number",r)}function fe(r,e,t){throw Math.floor(r)!==r?(ue(r,t),new ce.ERR_OUT_OF_RANGE(t||"offset","an integer",r)):e<0?new ce.ERR_BUFFER_OUT_OF_BOUNDS:new ce.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${e}`,r)}let pn=/[^+/0-9A-Za-z-_]/g;function yn(r){if(r=r.split("=")[0],r=r.trim().replace(pn,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function Ne(r,e){e=e||1/0;let t,i=r.length,c=null,l=[];for(let y=0;y<i;++y){if(t=r.charCodeAt(y),t>55295&&t<57344){if(!c){if(t>56319){(e-=3)>-1&&l.push(239,191,189);continue}else if(y+1===i){(e-=3)>-1&&l.push(239,191,189);continue}c=t;continue}if(t<56320){(e-=3)>-1&&l.push(239,191,189),c=t;continue}t=(c-55296<<10|t-56320)+65536}else c&&(e-=3)>-1&&l.push(239,191,189);if(c=null,t<128){if((e-=1)<0)break;l.push(t)}else if(t<2048){if((e-=2)<0)break;l.push(t>>6|192,t&63|128)}else if(t<65536){if((e-=3)<0)break;l.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((e-=4)<0)break;l.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else throw new Error("Invalid code point")}return l}function hn(r){let e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t)&255);return e}function fn(r,e){let t,i,c,l=[];for(let y=0;y<r.length&&!((e-=2)<0);++y)t=r.charCodeAt(y),i=t>>8,c=t%256,l.push(c),l.push(i);return l}function ct(r){return o.toByteArray(yn(r))}function Te(r,e,t,i){let c;for(c=0;c<i&&!(c+t>=e.length||c>=r.length);++c)e[c+t]=r[c];return c}function Y(r,e){return r instanceof e||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===e.name}function Oe(r){return r!==r}let gn=function(){let r="0123456789abcdef",e=new Array(256);for(let t=0;t<16;++t){let i=t*16;for(let c=0;c<16;++c)e[i+c]=r[t]+r[c]}return e}();function Q(r){return typeof BigInt>"u"?mn:r}function mn(){throw new Error("BigInt not supported")}return re}var me,yt,Be,ht,re,ft,ie,O,Jn,Qn,Le=ge(()=>{"use strict";E();v();T();me={},yt=!1;Be={},ht=!1;re={},ft=!1;ie=Cn();ie.Buffer;ie.SlowBuffer;ie.INSPECT_MAX_BYTES;ie.kMaxLength;O=ie.Buffer,Jn=ie.INSPECT_MAX_BYTES,Qn=ie.kMaxLength});var v=ge(()=>{"use strict";Le()});var mt=ut((ar,gt)=>{"use strict";E();v();T();function _n(o){if(o.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),a=0;a<n.length;a++)n[a]=255;for(var u=0;u<o.length;u++){var d=o.charAt(u),p=d.charCodeAt(0);if(n[p]!==255)throw new TypeError(d+" is ambiguous");n[p]=u}var s=o.length,f=o.charAt(0),w=Math.log(s)/Math.log(256),I=Math.log(256)/Math.log(s);function g(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var m=0,B=0,x=0,k=h.length;x!==k&&h[x]===0;)x++,m++;for(var C=(k-x)*I+1>>>0,U=new Uint8Array(C);x!==k;){for(var M=h[x],K=0,H=C-1;(M!==0||K<B)&&H!==-1;H--,K++)M+=256*U[H]>>>0,U[H]=M%s>>>0,M=M/s>>>0;if(M!==0)throw new Error("Non-zero carry");B=K,x++}for(var q=C-B;q!==C&&U[q]===0;)q++;for(var oe=f.repeat(m);q<C;++q)oe+=o.charAt(U[q]);return oe}function A(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;for(var m=0,B=0,x=0;h[m]===f;)B++,m++;for(var k=(h.length-m)*w+1>>>0,C=new Uint8Array(k);h[m];){var U=n[h.charCodeAt(m)];if(U===255)return;for(var M=0,K=k-1;(U!==0||M<x)&&K!==-1;K--,M++)U+=s*C[K]>>>0,C[K]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");x=M,m++}for(var H=k-x;H!==k&&C[H]===0;)H++;for(var q=new Uint8Array(B+(k-H)),oe=B;H!==k;)q[oe++]=C[H++];return q}function _(h){var m=A(h);if(m)return m;throw new Error("Non-base"+s+" character")}return{encode:g,decodeUnsafe:A,decode:_}}gt.exports=_n});var bt=ut((lr,wt)=>{"use strict";E();v();T();var kn=mt(),Un="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";wt.exports=kn(Un)});var Hn={};Tn(Hn,{Account:()=>Ee,BaseConfigStore:()=>Xe,BaseContractManager:()=>Ue,BaseKeyStore:()=>Ae,BaseOrderlyKeyPair:()=>Z,BaseSigner:()=>J,EtherAdapter:()=>Me,EventEmitter:()=>en.default,LocalStorageStore:()=>pe,MemoryConfigStore:()=>Ie,MockKeyStore:()=>ye,SimpleDI:()=>Xt,getDefaultSigner:()=>zt,getMockSigner:()=>jt});module.exports=vn(Hn);E();v();T();E();v();T();E();v();T();var be=Re(bt());E();v();T();var $=2n**255n-19n,le=2n**252n+27742317777372353535851937790883648493n,Ve=0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,$e=0x6666666666666666666666666666666666666666666666666666666666666658n,xe={a:-1n,d:37095705934669439343138083508754565189542113879843219016388785533085940283555n,p:$,n:le,h:8,Gx:Ve,Gy:$e},j=(o="")=>{throw new Error(o)},vt=o=>typeof o=="string",_e=(o,n)=>!(o instanceof Uint8Array)||typeof n=="number"&&n>0&&o.length!==n?j("Uint8Array expected"):o,de=o=>new Uint8Array(o),ke=(o,n)=>_e(vt(o)?je(o):de(o),n),b=(o,n=$)=>{let a=o%n;return a>=0n?a:n+a},At=o=>o instanceof ee?o:j("Point expected"),It,ee=class o{constructor(n,a,u,d){this.ex=n,this.ey=a,this.ez=u,this.et=d}static fromAffine(n){return new o(n.x,n.y,1n,b(n.x*n.y))}static fromHex(n,a=!0){let{d:u}=xe;n=ke(n,32);let d=n.slice();d[31]=n[31]&-129;let p=St(d);p===0n||(a&&!(0n<p&&p<$)&&j("bad y coord 1"),!a&&!(0n<p&&p<2n**256n)&&j("bad y coord 2"));let s=b(p*p),f=b(s-1n),w=b(u*s+1n),{isValid:I,value:g}=Mn(f,w);I||j("bad y coordinate 3");let A=(g&1n)===1n;return(n[31]&128)!==0!==A&&(g=b(-g)),new o(g,p,1n,b(g*p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}equals(n){let{ex:a,ey:u,ez:d}=this,{ex:p,ey:s,ez:f}=At(n),w=b(a*f),I=b(p*d),g=b(u*f),A=b(s*d);return w===I&&g===A}is0(){return this.equals(Se)}negate(){return new o(b(-this.ex),this.ey,this.ez,b(-this.et))}double(){let{ex:n,ey:a,ez:u}=this,{a:d}=xe,p=b(n*n),s=b(a*a),f=b(2n*b(u*u)),w=b(d*p),I=n+a,g=b(b(I*I)-p-s),A=w+s,_=A-f,h=w-s,m=b(g*_),B=b(A*h),x=b(g*h),k=b(_*A);return new o(m,B,k,x)}add(n){let{ex:a,ey:u,ez:d,et:p}=this,{ex:s,ey:f,ez:w,et:I}=At(n),{a:g,d:A}=xe,_=b(a*s),h=b(u*f),m=b(p*A*I),B=b(d*w),x=b((a+u)*(s+f)-_-h),k=b(B-m),C=b(B+m),U=b(h-g*_),M=b(x*k),K=b(C*U),H=b(x*U),q=b(k*C);return new o(M,K,q,H)}mul(n,a=!0){if(n===0n)return a===!0?j("cannot multiply by 0"):Se;if(typeof n=="bigint"&&0n<n&&n<le||j("invalid scalar, must be < L"),!a&&this.is0()||n===1n)return this;if(this.equals(ae))return Dn(n).p;let u=Se,d=ae;for(let p=this;n>0n;p=p.double(),n>>=1n)n&1n?u=u.add(p):a&&(d=d.add(p));return u}multiply(n){return this.mul(n)}clearCofactor(){return this.mul(BigInt(xe.h),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let n=this.mul(le/2n,!1).double();return le%2n&&(n=n.add(this)),n.is0()}toAffine(){let{ex:n,ey:a,ez:u}=this;if(this.is0())return{x:0n,y:0n};let d=Ct(u);return b(u*d)!==1n&&j("invalid inverse"),{x:b(n*d),y:b(a*d)}}toRawBytes(){let{x:n,y:a}=this.toAffine(),u=xt(a);return u[31]|=n&1n?128:0,u}toHex(){return We(this.toRawBytes())}};ee.BASE=new ee(Ve,$e,1n,b(Ve*$e));ee.ZERO=new ee(0n,1n,1n,0n);var{BASE:ae,ZERO:Se}=ee,Bt=(o,n)=>o.toString(16).padStart(n,"0"),We=o=>Array.from(o).map(n=>Bt(n,2)).join(""),je=o=>{let n=o.length;(!vt(o)||n%2)&&j("hex invalid 1");let a=de(n/2);for(let u=0;u<a.length;u++){let d=u*2,p=o.slice(d,d+2),s=Number.parseInt(p,16);(Number.isNaN(s)||s<0)&&j("hex invalid 2"),a[u]=s}return a},xt=o=>je(Bt(o,32*2)).reverse(),St=o=>BigInt("0x"+We(de(_e(o)).reverse())),Ce=(...o)=>{let n=de(o.reduce((u,d)=>u+_e(d).length,0)),a=0;return o.forEach(u=>{n.set(u,a),a+=u.length}),n},Ct=(o,n=$)=>{(o===0n||n<=0n)&&j("no inverse n="+o+" mod="+n);let a=b(o,n),u=n,d=0n,p=1n,s=1n,f=0n;for(;a!==0n;){let w=u/a,I=u%a,g=d-s*w,A=p-f*w;u=a,a=I,d=s,p=f,s=g,f=A}return u===1n?b(d,n):j("no inverse")},G=(o,n)=>{let a=o;for(;n-- >0n;)a*=a,a%=$;return a},Pn=o=>{let a=o*o%$*o%$,u=G(a,2n)*a%$,d=G(u,1n)*o%$,p=G(d,5n)*d%$,s=G(p,10n)*p%$,f=G(s,20n)*s%$,w=G(f,40n)*f%$,I=G(w,80n)*w%$,g=G(I,80n)*w%$,A=G(g,10n)*p%$;return{pow_p_5_8:G(A,2n)*o%$,b2:a}},Et=19681161376707505956807079304988542015446066515923890162744021073123829784752n,Mn=(o,n)=>{let a=b(n*n*n),u=b(a*a*n),d=Pn(o*u).pow_p_5_8,p=b(o*a*d),s=b(n*p*p),f=p,w=b(p*Et),I=s===o,g=s===b(-o),A=s===b(-o*Et);return I&&(p=f),(g||A)&&(p=w),(b(p)&1n)===1n&&(p=b(-p)),{isValid:I||g,value:p}},He=o=>b(St(o),le),we,ze=(...o)=>Ye.sha512Async(...o),_t=(...o)=>typeof we=="function"?we(...o):j("etc.sha512Sync not set"),kt=o=>{let n=o.slice(0,32);n[0]&=248,n[31]&=127,n[31]|=64;let a=o.slice(32,64),u=He(n),d=ae.mul(u),p=d.toRawBytes();return{head:n,prefix:a,scalar:u,point:d,pointBytes:p}},qe=o=>ze(ke(o,32)).then(kt),Kn=o=>kt(_t(ke(o,32))),Ut=o=>qe(o).then(n=>n.pointBytes);function Nn(o,n){return o?ze(n.hashable).then(n.finish):n.finish(_t(n.hashable))}var On=(o,n,a)=>{let{pointBytes:u,scalar:d}=o,p=He(n),s=ae.mul(p).toRawBytes();return{hashable:Ce(s,u,a),finish:I=>{let g=b(p+He(I)*d,le);return _e(Ce(s,xt(g)),64)}}},Pt=async(o,n)=>{let a=ke(o),u=await qe(n),d=await ze(u.prefix,a);return Nn(!0,On(u,d,a))};var Tt=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,Ye={bytesToHex:We,hexToBytes:je,concatBytes:Ce,mod:b,invert:Ct,randomBytes:o=>{let n=Tt();return n||j("crypto.getRandomValues must be defined"),n.getRandomValues(de(o))},sha512Async:async(...o)=>{let n=Tt();n||j("crypto.subtle or etc.sha512Async must be defined");let a=Ce(...o);return de(await n.subtle.digest("SHA-512",a.buffer))},sha512Sync:void 0};Object.defineProperties(Ye,{sha512Sync:{configurable:!1,get(){return we},set(o){we||(we=o)}}});var Mt={getExtendedPublicKeyAsync:qe,getExtendedPublicKey:Kn,randomPrivateKey:()=>Ye.randomBytes(32),precompute(o=8,n=ae){return n.multiply(3n),n}},se=8,Rn=()=>{let o=[],n=256/se+1,a=ae,u=a;for(let d=0;d<n;d++){u=a,o.push(u);for(let p=1;p<2**(se-1);p++)u=u.add(a),o.push(u);a=u.double()}return o},Dn=o=>{let n=It||(It=Rn()),a=(g,A)=>{let _=A.negate();return g?_:A},u=Se,d=ae,p=1+256/se,s=2**(se-1),f=BigInt(2**se-1),w=2**se,I=BigInt(se);for(let g=0;g<p;g++){let A=g*s,_=Number(o&f);o>>=I,_>s&&(_-=w,o+=1n);let h=A,m=A+Math.abs(_)-1,B=g%2!==0,x=_<0;_===0?d=d.add(a(B,n[h])):u=u.add(a(x,n[m]))}return{p:u,f:d}};var Z=class o{static generateKey(){let n,a;do n=Mt.randomPrivateKey(),a=(0,be.encode)(n);while(a.length!==44);return new o(a)}constructor(n){this.secretKey=n;let a=(0,be.decode)(n);this.privateKey=O.from(a).toString("hex")}async sign(n){return await Pt(n,this.privateKey)}async getPublicKey(){let n=await Ut(this.privateKey);return`ed25519:${(0,be.encode)(n)}`}toString(){return this.privateKey}};var Ae=class{constructor(n="testnet"){this.networkId=n}get keyPrefix(){return`orderly_${this.networkId}_`}},pe=class extends Ae{getOrderlyKey(n){let a;if(n)a=this.getItem(n,"orderlyKey");else{let u=this.getAddress();if(!u)return null;a=this.getItem(u,"orderlyKey")}return a?new Z(a):null}getAccountId(n){return this.getItem(n,"accountId")}setAccountId(n,a){this.setItem(n,{accountId:a})}getAddress(){return localStorage.getItem(`${this.keyPrefix}address`)}setAddress(n){localStorage.setItem(`${this.keyPrefix}address`,n)}generateKey(){return Z.generateKey()}setKey(n,a){this.setItem(n,{orderlyKey:a.secretKey})}cleanAllKey(n){localStorage.removeItem(`${this.keyPrefix}${n}`),localStorage.removeItem(`${this.keyPrefix}address`)}cleanKey(n,a){let u=this.getItem(n);delete u[a],localStorage.setItem(`${this.keyPrefix}${n}`,JSON.stringify(u))}setItem(n,a){let u=`${this.keyPrefix}${n}`,d=localStorage.getItem(u);d?d=JSON.parse(d):d={},localStorage.setItem(u,JSON.stringify({...d,...a}))}getItem(n,a){let u=`${this.keyPrefix}${n}`,d=localStorage.getItem(u);return d?d=JSON.parse(d):d={},typeof a>"u"?d:d[a]}},ye=class{constructor(n){this.secretKey=n}generateKey(){return new Z(this.secretKey)}getOrderlyKey(){return new Z(this.secretKey)}getAccountId(){return""}setAccountId(n){}getAddress(){return""}setAddress(n){}setKey(n,a){}cleanAllKey(){}cleanKey(n){}};E();v();T();E();v();T();E();v();T();var X={EIP712Domain:[{name:"name",type:"string"},{name:"version",type:"string"},{name:"chainId",type:"uint256"},{name:"verifyingContract",type:"address"}],Registration:[{name:"brokerId",type:"string"},{name:"chainId",type:"uint256"},{name:"timestamp",type:"uint64"},{name:"registrationNonce",type:"uint256"}],Withdraw:[{name:"brokerId",type:"string"},{name:"chainId",type:"uint256"},{name:"receiver",type:"address"},{name:"token",type:"string"},{name:"amount",type:"uint256"},{name:"withdrawNonce",type:"uint64"},{name:"timestamp",type:"uint64"}],AddOrderlyKey:[{name:"brokerId",type:"string"},{name:"chainId",type:"uint256"},{name:"orderlyKey",type:"string"},{name:"scope",type:"string"},{name:"timestamp",type:"uint64"},{name:"expiration",type:"uint64"}],SettlePnl:[{name:"brokerId",type:"string"},{name:"chainId",type:"uint256"},{name:"settleNonce",type:"uint64"},{name:"timestamp",type:"uint64"}]},Kt="0x6aAd876244E7A1Ad44Ec4824Ce813729E5B6C291",Nt="0xd64AeB281f3E8cd70e668b6cb24De7e532dC214D",Ot="0x1826B75e2ef249173FC735149AE4B8e9ea10abff";var he=require("ethers"),Rt=function(o){return o.replace(/\+/g,"-").replace(/\//g,"_")};function Ln(){return"0x8794E7260517B1766fc7b55cAfcd56e6bf08600e"}function Dt(o,n){return{name:"Orderly",version:"1",chainId:o,verifyingContract:n?Ln():"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"}}function Ft(o){let{chainId:n,registrationNonce:a,brokerId:u}=o,d=Date.now(),p="Registration",s={brokerId:u,chainId:n,timestamp:d,registrationNonce:a},f={EIP712Domain:X.EIP712Domain,[p]:X[p]};return[s,{domain:Dt(n),message:s,primaryType:p,types:f}]}function Lt(o){let{publicKey:n,chainId:a,primaryType:u,brokerId:d,expiration:p=365}=o,s=Date.now(),f={brokerId:d,orderlyKey:n,scope:"read,trading",chainId:a,timestamp:s,expiration:s+1e3*60*60*24*p},w={EIP712Domain:X.EIP712Domain,[u]:X[u]},I={domain:Dt(a),message:f,primaryType:u,types:w};return[f,I]}function Vt(o){let{chainId:n,settlePnlNonce:a,domain:u,brokerId:d}=o,p="SettlePnl",s=new Date().getTime(),f={EIP712Domain:X.EIP712Domain,[p]:X[p]},w={brokerId:d,chainId:n,timestamp:s,settleNonce:a};return[w,{domain:u,message:w,primaryType:p,types:f}]}function Ge(o){return Wt(o)}function $t(o,n){let a=he.AbiCoder.defaultAbiCoder();return(0,he.keccak256)(a.encode(["address","bytes32"],[o,Ge(n)]))}function Ht(o){return Wt(o)}function Wt(o){return(0,he.solidityPackedKeccak256)(["string"],[o])}Le();var J=class{constructor(n){this.keyStore=n}async sign(n){let a=Date.now().toString(),u=[a,n.method.toUpperCase(),n.url].join("");n.data&&Object.keys(n.data).length&&(u+=JSON.stringify(n.data));let{signature:d,publicKey:p}=await this.signText(u);return{"orderly-key":p,"orderly-timestamp":a,"orderly-signature":d}}async signText(n){let a=this.keyStore.getOrderlyKey();if(!a)throw new Error("orderlyKeyPair is not defined");let u=O.from(n),d=await a.sign(u),p=O.from(d).toString("base64");return{signature:Rt(p),publicKey:await a.getPublicKey()}}};var en=Re(require("eventemitter3"));E();v();T();E();v();T();var Ie=class{constructor(){this._restore()}_restore(){this.map=new Map([["apiBaseUrl","https://qa-api-evm.orderly.org"],["klineDataUrl","https://testnet-api-evm.orderly.org"],["publicWsUrl","wss://dev-ws-v2.orderly.org"],["publicWebsocketKey","OqdphuyCtYWxwzhxyLLjOWNdFP7sQt8RPWzmb5xY"],["privateWsUrl","wss://dev-ws-private-v2.orderly.org"],["operatorUrl","https://testnet-operator-evm.orderly.org"],["brokerId","woofi_dex"],["env","dev-evm"]])}get(n){return this.map.get(n)}set(n,a){this.map.set(n,a)}clear(){}},Xe=class extends Ie{constructor(a){super();this.configMap=a}_restore(){let a=Object.entries(this.configMap);this.map=new Map(a)}};var jt=o=>{let n=new ye(o||"AFmQSju4FhDwG93cMdKogcnKx7SWmViDtDv5PVzfvRDF");return new J(n)},zt=()=>{if(typeof window>"u")throw new Error("the default signer only supports browsers.");let o=new pe("");return new J(o)};E();v();T();var qt=[{inputs:[{internalType:"string",name:"name_",type:"string"},{internalType:"string",name:"symbol_",type:"string"},{internalType:"uint8",name:"decimals_",type:"uint8"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"subtractedValue",type:"uint256"}],name:"decreaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"addedValue",type:"uint256"}],name:"increaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"amount",type:"uint256"}],name:"issue",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"_to",type:"address"},{internalType:"uint256",name:"_amount",type:"uint256"}],name:"mint",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bool",name:"_paused",type:"bool"}],name:"pauseTransfers",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}];var Yt=[{inputs:[],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"AccountIdInvalid",type:"error"},{inputs:[{internalType:"uint256",name:"balance",type:"uint256"},{internalType:"uint128",name:"amount",type:"uint128"}],name:"BalanceNotEnough",type:"error"},{inputs:[],name:"BrokerNotAllowed",type:"error"},{inputs:[],name:"OnlyCrossChainManagerCanCall",type:"error"},{inputs:[],name:"TokenNotAllowed",type:"error"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"accountId",type:"bytes32"},{indexed:!0,internalType:"address",name:"userAddress",type:"address"},{indexed:!0,internalType:"uint64",name:"depositNonce",type:"uint64"},{indexed:!1,internalType:"bytes32",name:"tokenHash",type:"bytes32"},{indexed:!1,internalType:"uint128",name:"tokenAmount",type:"uint128"}],name:"AccountDeposit",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"accountId",type:"bytes32"},{indexed:!0,internalType:"address",name:"userAddress",type:"address"},{indexed:!0,internalType:"uint64",name:"depositNonce",type:"uint64"},{indexed:!1,internalType:"bytes32",name:"tokenHash",type:"bytes32"},{indexed:!1,internalType:"uint128",name:"tokenAmount",type:"uint128"}],name:"AccountDepositTo",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"accountId",type:"bytes32"},{indexed:!0,internalType:"uint64",name:"withdrawNonce",type:"uint64"},{indexed:!1,internalType:"bytes32",name:"brokerHash",type:"bytes32"},{indexed:!1,internalType:"address",name:"sender",type:"address"},{indexed:!1,internalType:"address",name:"receiver",type:"address"},{indexed:!1,internalType:"bytes32",name:"tokenHash",type:"bytes32"},{indexed:!1,internalType:"uint128",name:"tokenAmount",type:"uint128"},{indexed:!1,internalType:"uint128",name:"fee",type:"uint128"},{indexed:!1,internalType:"uint256",name:"blocktime",type:"uint256"}],name:"AccountWithdraw",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"_tokenHash",type:"bytes32"},{indexed:!1,internalType:"address",name:"_tokenAddress",type:"address"}],name:"ChangeTokenAddressAndAllow",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint8",name:"version",type:"uint8"}],name:"Initialized",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"previousOwner",type:"address"},{indexed:!0,internalType:"address",name:"newOwner",type:"address"}],name:"OwnershipTransferred",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Paused",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"_brokerHash",type:"bytes32"},{indexed:!1,internalType:"bool",name:"_allowed",type:"bool"}],name:"SetAllowedBroker",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"_tokenHash",type:"bytes32"},{indexed:!1,internalType:"bool",name:"_allowed",type:"bool"}],name:"SetAllowedToken",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Unpaused",type:"event"},{inputs:[{internalType:"bytes32",name:"",type:"bytes32"}],name:"allowedToken",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"_tokenHash",type:"bytes32"},{internalType:"address",name:"_tokenAddress",type:"address"}],name:"changeTokenAddressAndAllow",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"crossChainManagerAddress",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{components:[{internalType:"bytes32",name:"accountId",type:"bytes32"},{internalType:"bytes32",name:"brokerHash",type:"bytes32"},{internalType:"bytes32",name:"tokenHash",type:"bytes32"},{internalType:"uint128",name:"tokenAmount",type:"uint128"}],internalType:"struct VaultTypes.VaultDepositFE",name:"data",type:"tuple"}],name:"deposit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"depositId",outputs:[{internalType:"uint64",name:"",type:"uint64"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"receiver",type:"address"},{components:[{internalType:"bytes32",name:"accountId",type:"bytes32"},{internalType:"bytes32",name:"brokerHash",type:"bytes32"},{internalType:"bytes32",name:"tokenHash",type:"bytes32"},{internalType:"uint128",name:"tokenAmount",type:"uint128"}],internalType:"struct VaultTypes.VaultDepositFE",name:"data",type:"tuple"}],name:"depositTo",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"emergencyPause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"emergencyUnpause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"getAllAllowedBroker",outputs:[{internalType:"bytes32[]",name:"",type:"bytes32[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"getAllAllowedToken",outputs:[{internalType:"bytes32[]",name:"",type:"bytes32[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"_brokerHash",type:"bytes32"}],name:"getAllowedBroker",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"_tokenHash",type:"bytes32"}],name:"getAllowedToken",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"initialize",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"owner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"paused",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"renounceOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"_brokerHash",type:"bytes32"},{internalType:"bool",name:"_allowed",type:"bool"}],name:"setAllowedBroker",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"_tokenHash",type:"bytes32"},{internalType:"bool",name:"_allowed",type:"bool"}],name:"setAllowedToken",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"_crossChainManagerAddress",type:"address"}],name:"setCrossChainManager",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newOwner",type:"address"}],name:"transferOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"bytes32",name:"accountId",type:"bytes32"},{internalType:"bytes32",name:"brokerHash",type:"bytes32"},{internalType:"bytes32",name:"tokenHash",type:"bytes32"},{internalType:"uint128",name:"tokenAmount",type:"uint128"},{internalType:"uint128",name:"fee",type:"uint128"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"receiver",type:"address"},{internalType:"uint64",name:"withdrawNonce",type:"uint64"}],internalType:"struct VaultTypes.VaultWithdraw",name:"data",type:"tuple"}],name:"withdraw",outputs:[],stateMutability:"nonpayable",type:"function"}];var Ue=class{constructor(n){this.configStore=n}getContractInfoByEnv(){return{usdcAddress:Kt,usdcAbi:qt,vaultAddress:Nt,vaultAbi:Yt,verifyContractAddress:Ot}}};E();v();T();E();v();T();var Ze=class{constructor(n=[],a={}){this.providers=n;this.services=a;this.injectProperties={}}register(...n){this.providers.push(...n),n.forEach(a=>{let u=a;u instanceof Function&&(u=new a),this.add(u)})}registerByName(n,a){let u=a;u instanceof Function&&(u=new a),this.addByName(n,u)}get(n){return this.services[n]}getAll(){return Object.assign({},this.services)}add(n){return this.addByName(n.constructor.name,n)}addByName(n,a){return this.services[n]=a,this.services[n.toLowerCase()]=a,this.injectIntoProperties(a,n),this.get(n)}inject(n,a,u){n&&u&&(n[a]=u)}injectIntoProperties(n,a=n.constructor.name){this.getInjectProperty(a.toLowerCase()).forEach(u=>{this.inject(u.target,u.propertyKey,n)})}getInjectProperty(n){return this.injectProperties[n]||(this.injectProperties[n]=[]),this.injectProperties[n]}},Gt=Ze;var Je=class o{static getContainer(){return o.container||(o.container=new Gt),o.container}static register(...n){this.getContainer().register(...n)}static registerByName(n,a){this.getContainer().registerByName(n,a)}static get(n){return this.getContainer().get(n)}static getAll(){return this.getContainer().getAll()}constructor(){}},Xt=Je;E();v();T();var W=require("@orderly.network/types");var Jt=Re(require("eventemitter3"));E();v();T();var Zt=require("ethers");var Pe=class{constructor(n,a,u){this.configStore=n;this.contractManger=a;this.account=u}async withdraw(n){if(!this.account.walletClient)throw new Error("walletClient is undefined");if(!this.account.stateValue.address)throw new Error("account address is rqeuired");let{chainId:a,token:u,amount:d}=n,p="/v1/withdraw_request",s=await this.getWithdrawalNonce(),f=this.account.getDomain(!0),[w,I]=this._generateWithdrawMessage({chainId:a,receiver:this.account.stateValue.address,token:u,amount:this.account.walletClient.parseUnits(d.toString()),nonce:s,domain:f}),A={signature:await this.account.signTypedData(I),message:w,userAddress:this.account.stateValue.address,verifyingContract:f.verifyingContract},_={method:"POST",url:p,data:A},h=await this.account.signer.sign(_);return await this._simpleFetch(p,{method:"POST",body:JSON.stringify(A),headers:{"Content-Type":"application/json","orderly-account-id":this.account.stateValue.accountId,...h}})}_generateWithdrawMessage(n){let{chainId:a,receiver:u,token:d,amount:p,domain:s,nonce:f}=n,w="Withdraw",I=Date.now(),g={EIP712Domain:X.EIP712Domain,[w]:X[w]},A={brokerId:this.configStore.get("brokerId"),chainId:a,receiver:u,token:d,amount:p,timestamp:I,withdrawNonce:f};return[A,{domain:s,message:A,primaryType:w,types:g}]}async getWithdrawalNonce(){let n=Date.now().toString(),a="/v1/withdraw_nonce",u=[n,"GET",a].join(""),d=this.account.signer,{publicKey:p,signature:s}=await d.signText(u),f=await this._simpleFetch(a,{headers:{"orderly-account-id":this.account.stateValue.accountId,"orderly-key":p,"orderly-timestamp":n,"orderly-signature":s}});if(f.success)return f.data?.withdraw_nonce;throw new Error(f.message)}async getBalance(){if(!this.account.walletClient)return"0";let n=this.contractManger.getContractInfoByEnv(),a=await this.account.walletClient?.call(n.usdcAddress,"balanceOf",[this.account.stateValue.address],{abi:n.usdcAbi});return this.account.walletClient?.fromUnits(a)}async getAllowance(){if(!this.account.walletClient)return"0";let n=this.contractManger.getContractInfoByEnv(),a=await this.account.walletClient?.call(n.usdcAddress,"allowance",[this.account.stateValue.address,n.vaultAddress],{abi:n.usdcAbi});return this.account.walletClient?.fromUnits(a)}async approve(n){if(!this.account.walletClient)throw new Error("walletClient is undefined");let a=this.contractManger.getContractInfoByEnv(),u=typeof n<"u"&&n!==""?this.account.walletClient.parseUnits(n):Zt.ethers.MaxUint256.toString(),d=await this.account.walletClient?.call(a.usdcAddress,"approve",[a.vaultAddress,u],{abi:a.usdcAbi});return console.log("-----*****-----",d),d}async deposit(n){console.log("deposit amount:",n);let a=this.configStore.get("brokerId");if(!a)throw new Error("brokerId is required");let u=this.contractManger.getContractInfoByEnv(),d={accountId:$t(this.account.stateValue.address,a),brokerHash:Ge(a),tokenHash:Ht("USDC"),tokenAmount:this.account.walletClient?.parseUnits(n)};return await this.account.walletClient?.call(u.vaultAddress,"deposit",[d],{abi:u.vaultAbi})}async _simpleFetch(n,a={}){let u=`${this.configStore.get("apiBaseUrl")}${n}`;return fetch(u,a).then(d=>d.json())}};var Ee=class{constructor(n,a,u,d){this.configStore=n;this.keyStore=a;this.contractManger=u;this.getWalletAdapter=d;this._ee=new Jt.default;this._state={status:W.AccountStatusEnum.NotConnected,balance:"",checking:!1,leverage:Number.NaN};this.assetsManager=new Pe(n,u,this),this._bindEvents()}login(n){if(!n)throw new Error("address is required")}logout(){}async setAddress(n,a){if(!n)throw new Error("address is required");this.keyStore.setAddress(n);let u={...this.stateValue,status:W.AccountStatusEnum.Connected,address:n,connectWallet:a?.wallet};return this._ee.emit("change:status",u),a&&(this.walletClient=this.getWalletAdapter({...a,address:n})),await this._checkAccount(n)}get stateValue(){return this._state}get accountId(){return this.stateValue.accountId}get address(){return this.stateValue.address}get chainId(){return this.walletClient?.chainId}set position(n){let a={...this.stateValue,positon:n};this._ee.emit("change:status",a)}set orders(n){let a={...this.stateValue,orders:n};this._ee.emit("change:status",a)}_bindEvents(){this._ee.addListener("change:status",n=>{console.log("change:status",n),this._state=n})}async _checkAccount(n){console.log("check account is esist",n);let a;try{let u=await this._checkAccountExist(n);if(console.log("accountInfo:",u),u&&u.account_id)console.log("account is exist"),this.keyStore.setAccountId(n,u.account_id),a={...this.stateValue,status:W.AccountStatusEnum.SignedIn,accountId:u.account_id,userId:u.user_id},this._ee.emit("change:status",a);else return a={...this.stateValue,status:W.AccountStatusEnum.NotSignedIn},this._ee.emit("change:status",a),W.AccountStatusEnum.NotSignedIn;let d=this.keyStore.getOrderlyKey();if(console.log("orderlyKey:::::::",d),a={...this.stateValue,status:W.AccountStatusEnum.DisabledTrading},!d)return console.log("orderlyKey is null"),this._ee.emit("change:status",a),W.AccountStatusEnum.DisabledTrading;let p=await d.getPublicKey(),s=await this._checkOrderlyKeyState(u.account_id,p);if(console.log("orderlyKeyStatus:",s),s&&s.orderly_key&&s.key_status==="ACTIVE"){let f=Date.now(),w=s.expiration;if(f>w)return this.keyStore.cleanKey(n,"orderlyKey"),W.AccountStatusEnum.DisabledTrading;let I={...this.stateValue,status:W.AccountStatusEnum.EnableTrading};return this._ee.emit("change:status",I),W.AccountStatusEnum.EnableTrading}return this.keyStore.cleanKey(n,"orderlyKey"),W.AccountStatusEnum.NotConnected}catch(u){console.log("\u68C0\u67E5\u8D26\u6237\u72B6\u6001\u9519\u8BEF:",u)}return W.AccountStatusEnum.NotSignedIn}async _checkAccountExist(n){let a=await this._simpleFetch(`/v1/get_account?address=${n}&broker_id=woofi_dex`);return a.success?a.data:null}async createAccount(){if(!this.walletClient)return Promise.reject("walletClient is undefined");let n=await this._getRegisterationNonce(),a=this.stateValue.address;if(!a)throw new Error("address is undefined");let[u,d]=Ft({registrationNonce:n,chainId:this.walletClient.chainId,brokerId:this.configStore.get("brokerId")}),p=await this.signTypedData(d),s=await this._simpleFetch("/v1/register_account",{method:"POST",body:JSON.stringify({signature:p,message:u,userAddress:a}),headers:{"Content-Type":"application/json"}});if(s.success){this.keyStore.setAccountId(a,s.data.account_id);let f={...this.stateValue,status:W.AccountStatusEnum.DisabledTrading,accountId:s.data.account_id,userId:s.data.user_id};return this._ee.emit("change:status",f),s}}async signTypedData(n){return this.walletClient?await this.walletClient.signTypedData(this.stateValue.address,JSON.stringify(n)):Promise.reject("walletClient is undefined")}async createOrderlyKey(n){if(this.stateValue.accountId===void 0)throw new Error("account id is undefined");if(!this.walletClient)throw new Error("walletClient is undefined");let a="AddOrderlyKey",u=this.keyStore.generateKey(),d=await u.getPublicKey(),[p,s]=Lt({publicKey:d,chainId:this.walletClient.chainId,primaryType:a,expiration:n,brokerId:this.configStore.get("brokerId")}),f=this.stateValue.address;if(!f)throw new Error("address is undefined");let w=await this.signTypedData(s),I=await this._simpleFetch("/v1/orderly_key",{method:"POST",body:JSON.stringify({signature:w,message:p,userAddress:f}),headers:{"X-Account-Id":this.stateValue.accountId,"Content-Type":"application/json"}});if(I.success){this.keyStore.setKey(f,u);let g={...this.stateValue,status:W.AccountStatusEnum.EnableTrading};return this._ee.emit("change:status",g),I}else throw new Error(I.message)}async settle(){if(!this.walletClient)return Promise.reject("walletClient is undefined");let n=await this._getSettleNonce(),a=this.stateValue.address,u=this.getDomain(!0),d="/v1/settle_pnl",[p,s]=Vt({settlePnlNonce:n,chainId:this.walletClient.chainId,brokerId:this.configStore.get("brokerId"),domain:u}),w={signature:await this.signTypedData(s),message:p,userAddress:a,verifyingContract:u.verifyingContract},I={method:"POST",url:d,data:w},g=await this.signer.sign(I),A=await this._simpleFetch(d,{method:"POST",body:JSON.stringify(w),headers:{"Content-Type":"application/json","orderly-account-id":this.stateValue.accountId,...g}});if(A.success)return A;throw new Error(A.message)}async disconnect(){let n={...this.stateValue,status:W.AccountStatusEnum.NotConnected,accountId:void 0,userId:void 0,address:void 0};this._ee.emit("change:status",n)}async _checkOrderlyKeyState(n,a){let u=await this._simpleFetch(`/v1/get_orderly_key?account_id=${n}&orderly_key=${a}`);if(u.success)return u.data;throw new Error(u.message)}get signer(){return this._singer||(this._singer=new J(this.keyStore)),this._singer}get wallet(){return this.walletClient}async _getRegisterationNonce(){let n=await this._simpleFetch("/v1/registration_nonce",{headers:{"orderly-account-id":this.stateValue.accountId}});if(console.log("getRegisterationNonce:",n),n.success)return n.data?.registration_nonce;throw new Error(n.message)}async _getSettleNonce(){let n=Date.now().toString(),u=[n,"GET","/v1/settle_nonce"].join(""),d=this.signer,{publicKey:p,signature:s}=await d.signText(u),f=await this._simpleFetch("/v1/settle_nonce",{headers:{"orderly-account-id":this.stateValue.accountId,"orderly-key":p,"orderly-timestamp":n,"orderly-signature":s}});if(f.success)return f.data?.settle_nonce;throw new Error(f.message)}async _simpleFetch(n,a={}){let u=`${this.configStore.get("apiBaseUrl")}${n}`;return fetch(u,a).then(d=>d.json())}getDomain(n){if(!this.walletClient)throw new Error("walletClient is undefined");return{name:"Orderly",version:"1",chainId:this.walletClient.chainId,verifyingContract:n?this.contractManger.getContractInfoByEnv().verifyContractAddress:"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"}}get on(){return this._ee.on.bind(this._ee)}get once(){return this._ee.once.bind(this._ee)}get off(){return this._ee.off.bind(this._ee)}};Ee.instanceName="account";E();v();T();E();v();T();var te=require("ethers"),Qt=require("@enzoferey/ethers-error-parser"),Me=class{constructor(n){console.log("EtherAdapter constructor",n),this._chainId=parseInt(n.chain.id,16),this.provider=new te.BrowserProvider(n.provider,"any"),this._address=n.address}parseUnits(n){return te.ethers.parseUnits(n,6).toString()}fromUnits(n){return te.ethers.formatUnits(n,6)}getBalance(n,a,u){return new te.ethers.Contract(n,u.abi,this.provider).balanceOf(a)}deposit(n,a,u){throw new Error("Method not implemented.")}async call(n,a,u,d){let p=await this.provider?.getSigner();return new te.ethers.Contract(n,d.abi,p)[a].apply(null,u).catch(f=>{throw(0,Qt.getParsedEthersError)(f)})}get chainId(){return this._chainId}get addresses(){return this._address}async send(n,a){return await this.provider?.send(n,a)}async signTypedData(n,a){return await this.provider?.send("eth_signTypedData_v4",[n,a])}async verify(n,a){let{domain:u,types:d,message:p}=n,s=te.ethers.verifyTypedData(u,d,p,a);console.log("recovered",s)}};0&&(module.exports={Account,BaseConfigStore,BaseContractManager,BaseKeyStore,BaseOrderlyKeyPair,BaseSigner,EtherAdapter,EventEmitter,LocalStorageStore,MemoryConfigStore,MockKeyStore,SimpleDI,getDefaultSigner,getMockSigner});
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
11
|
+
var __commonJS = (cb, mod2) => function __require() {
|
|
12
|
+
return mod2 || (0, cb[__getOwnPropNames(cb)[0]])((mod2 = { exports: {} }).exports, mod2), mod2.exports;
|
|
13
|
+
};
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
|
|
27
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
28
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
29
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
30
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
31
|
+
isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
|
|
32
|
+
mod2
|
|
33
|
+
));
|
|
34
|
+
var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
|
|
35
|
+
|
|
36
|
+
// ../../node_modules/.pnpm/esbuild-plugin-polyfill-node@0.3.0_esbuild@0.19.2/node_modules/esbuild-plugin-polyfill-node/polyfills/__dirname.js
|
|
37
|
+
var init_dirname = __esm({
|
|
38
|
+
"../../node_modules/.pnpm/esbuild-plugin-polyfill-node@0.3.0_esbuild@0.19.2/node_modules/esbuild-plugin-polyfill-node/polyfills/__dirname.js"() {
|
|
39
|
+
"use strict";
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// ../../node_modules/.pnpm/@jspm+core@2.0.1/node_modules/@jspm/core/nodelibs/browser/process.js
|
|
44
|
+
function Item(fun, array) {
|
|
45
|
+
this.fun = fun;
|
|
46
|
+
this.array = array;
|
|
47
|
+
}
|
|
48
|
+
function hrtime(previousTimestamp) {
|
|
49
|
+
var baseNow = Math.floor((Date.now() - _performance.now()) * 1e-3);
|
|
50
|
+
var clocktime = _performance.now() * 1e-3;
|
|
51
|
+
var seconds = Math.floor(clocktime) + baseNow;
|
|
52
|
+
var nanoseconds = Math.floor(clocktime % 1 * 1e9);
|
|
53
|
+
if (previousTimestamp) {
|
|
54
|
+
seconds = seconds - previousTimestamp[0];
|
|
55
|
+
nanoseconds = nanoseconds - previousTimestamp[1];
|
|
56
|
+
if (nanoseconds < 0) {
|
|
57
|
+
seconds--;
|
|
58
|
+
nanoseconds += nanoPerSec;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return [seconds, nanoseconds];
|
|
62
|
+
}
|
|
63
|
+
var env, _performance, nowOffset, nanoPerSec;
|
|
64
|
+
var init_process = __esm({
|
|
65
|
+
"../../node_modules/.pnpm/@jspm+core@2.0.1/node_modules/@jspm/core/nodelibs/browser/process.js"() {
|
|
66
|
+
"use strict";
|
|
67
|
+
init_dirname();
|
|
68
|
+
init_buffer2();
|
|
69
|
+
init_process2();
|
|
70
|
+
Item.prototype.run = function() {
|
|
71
|
+
this.fun.apply(null, this.array);
|
|
72
|
+
};
|
|
73
|
+
env = {
|
|
74
|
+
PATH: "/usr/bin",
|
|
75
|
+
LANG: navigator.language + ".UTF-8",
|
|
76
|
+
PWD: "/",
|
|
77
|
+
HOME: "/home",
|
|
78
|
+
TMP: "/tmp"
|
|
79
|
+
};
|
|
80
|
+
_performance = {
|
|
81
|
+
now: typeof performance !== "undefined" ? performance.now.bind(performance) : void 0,
|
|
82
|
+
timing: typeof performance !== "undefined" ? performance.timing : void 0
|
|
83
|
+
};
|
|
84
|
+
if (_performance.now === void 0) {
|
|
85
|
+
nowOffset = Date.now();
|
|
86
|
+
if (_performance.timing && _performance.timing.navigationStart) {
|
|
87
|
+
nowOffset = _performance.timing.navigationStart;
|
|
88
|
+
}
|
|
89
|
+
_performance.now = () => Date.now() - nowOffset;
|
|
90
|
+
}
|
|
91
|
+
nanoPerSec = 1e9;
|
|
92
|
+
hrtime.bigint = function(time) {
|
|
93
|
+
var diff = hrtime(time);
|
|
94
|
+
if (typeof BigInt === "undefined") {
|
|
95
|
+
return diff[0] * nanoPerSec + diff[1];
|
|
96
|
+
}
|
|
97
|
+
return BigInt(diff[0] * nanoPerSec) + BigInt(diff[1]);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// ../../node_modules/.pnpm/esbuild-plugin-polyfill-node@0.3.0_esbuild@0.19.2/node_modules/esbuild-plugin-polyfill-node/polyfills/process.js
|
|
103
|
+
var init_process2 = __esm({
|
|
104
|
+
"../../node_modules/.pnpm/esbuild-plugin-polyfill-node@0.3.0_esbuild@0.19.2/node_modules/esbuild-plugin-polyfill-node/polyfills/process.js"() {
|
|
105
|
+
"use strict";
|
|
106
|
+
init_process();
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// ../../node_modules/.pnpm/@jspm+core@2.0.1/node_modules/@jspm/core/nodelibs/browser/buffer.js
|
|
111
|
+
function dew$2() {
|
|
112
|
+
if (_dewExec$2)
|
|
113
|
+
return exports$3;
|
|
114
|
+
_dewExec$2 = true;
|
|
115
|
+
exports$3.byteLength = byteLength;
|
|
116
|
+
exports$3.toByteArray = toByteArray;
|
|
117
|
+
exports$3.fromByteArray = fromByteArray;
|
|
118
|
+
var lookup = [];
|
|
119
|
+
var revLookup = [];
|
|
120
|
+
var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
|
|
121
|
+
var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
122
|
+
for (var i = 0, len = code.length; i < len; ++i) {
|
|
123
|
+
lookup[i] = code[i];
|
|
124
|
+
revLookup[code.charCodeAt(i)] = i;
|
|
125
|
+
}
|
|
126
|
+
revLookup["-".charCodeAt(0)] = 62;
|
|
127
|
+
revLookup["_".charCodeAt(0)] = 63;
|
|
128
|
+
function getLens(b64) {
|
|
129
|
+
var len2 = b64.length;
|
|
130
|
+
if (len2 % 4 > 0) {
|
|
131
|
+
throw new Error("Invalid string. Length must be a multiple of 4");
|
|
132
|
+
}
|
|
133
|
+
var validLen = b64.indexOf("=");
|
|
134
|
+
if (validLen === -1)
|
|
135
|
+
validLen = len2;
|
|
136
|
+
var placeHoldersLen = validLen === len2 ? 0 : 4 - validLen % 4;
|
|
137
|
+
return [validLen, placeHoldersLen];
|
|
138
|
+
}
|
|
139
|
+
function byteLength(b64) {
|
|
140
|
+
var lens = getLens(b64);
|
|
141
|
+
var validLen = lens[0];
|
|
142
|
+
var placeHoldersLen = lens[1];
|
|
143
|
+
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
144
|
+
}
|
|
145
|
+
function _byteLength(b64, validLen, placeHoldersLen) {
|
|
146
|
+
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
147
|
+
}
|
|
148
|
+
function toByteArray(b64) {
|
|
149
|
+
var tmp;
|
|
150
|
+
var lens = getLens(b64);
|
|
151
|
+
var validLen = lens[0];
|
|
152
|
+
var placeHoldersLen = lens[1];
|
|
153
|
+
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
|
|
154
|
+
var curByte = 0;
|
|
155
|
+
var len2 = placeHoldersLen > 0 ? validLen - 4 : validLen;
|
|
156
|
+
var i2;
|
|
157
|
+
for (i2 = 0; i2 < len2; i2 += 4) {
|
|
158
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 18 | revLookup[b64.charCodeAt(i2 + 1)] << 12 | revLookup[b64.charCodeAt(i2 + 2)] << 6 | revLookup[b64.charCodeAt(i2 + 3)];
|
|
159
|
+
arr[curByte++] = tmp >> 16 & 255;
|
|
160
|
+
arr[curByte++] = tmp >> 8 & 255;
|
|
161
|
+
arr[curByte++] = tmp & 255;
|
|
162
|
+
}
|
|
163
|
+
if (placeHoldersLen === 2) {
|
|
164
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 2 | revLookup[b64.charCodeAt(i2 + 1)] >> 4;
|
|
165
|
+
arr[curByte++] = tmp & 255;
|
|
166
|
+
}
|
|
167
|
+
if (placeHoldersLen === 1) {
|
|
168
|
+
tmp = revLookup[b64.charCodeAt(i2)] << 10 | revLookup[b64.charCodeAt(i2 + 1)] << 4 | revLookup[b64.charCodeAt(i2 + 2)] >> 2;
|
|
169
|
+
arr[curByte++] = tmp >> 8 & 255;
|
|
170
|
+
arr[curByte++] = tmp & 255;
|
|
171
|
+
}
|
|
172
|
+
return arr;
|
|
173
|
+
}
|
|
174
|
+
function tripletToBase64(num) {
|
|
175
|
+
return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
|
|
176
|
+
}
|
|
177
|
+
function encodeChunk(uint8, start, end) {
|
|
178
|
+
var tmp;
|
|
179
|
+
var output = [];
|
|
180
|
+
for (var i2 = start; i2 < end; i2 += 3) {
|
|
181
|
+
tmp = (uint8[i2] << 16 & 16711680) + (uint8[i2 + 1] << 8 & 65280) + (uint8[i2 + 2] & 255);
|
|
182
|
+
output.push(tripletToBase64(tmp));
|
|
183
|
+
}
|
|
184
|
+
return output.join("");
|
|
185
|
+
}
|
|
186
|
+
function fromByteArray(uint8) {
|
|
187
|
+
var tmp;
|
|
188
|
+
var len2 = uint8.length;
|
|
189
|
+
var extraBytes = len2 % 3;
|
|
190
|
+
var parts = [];
|
|
191
|
+
var maxChunkLength = 16383;
|
|
192
|
+
for (var i2 = 0, len22 = len2 - extraBytes; i2 < len22; i2 += maxChunkLength) {
|
|
193
|
+
parts.push(encodeChunk(uint8, i2, i2 + maxChunkLength > len22 ? len22 : i2 + maxChunkLength));
|
|
194
|
+
}
|
|
195
|
+
if (extraBytes === 1) {
|
|
196
|
+
tmp = uint8[len2 - 1];
|
|
197
|
+
parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "==");
|
|
198
|
+
} else if (extraBytes === 2) {
|
|
199
|
+
tmp = (uint8[len2 - 2] << 8) + uint8[len2 - 1];
|
|
200
|
+
parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "=");
|
|
201
|
+
}
|
|
202
|
+
return parts.join("");
|
|
203
|
+
}
|
|
204
|
+
return exports$3;
|
|
205
|
+
}
|
|
206
|
+
function dew$1() {
|
|
207
|
+
if (_dewExec$1)
|
|
208
|
+
return exports$2;
|
|
209
|
+
_dewExec$1 = true;
|
|
210
|
+
exports$2.read = function(buffer, offset, isLE, mLen, nBytes) {
|
|
211
|
+
var e, m;
|
|
212
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
213
|
+
var eMax = (1 << eLen) - 1;
|
|
214
|
+
var eBias = eMax >> 1;
|
|
215
|
+
var nBits = -7;
|
|
216
|
+
var i = isLE ? nBytes - 1 : 0;
|
|
217
|
+
var d = isLE ? -1 : 1;
|
|
218
|
+
var s = buffer[offset + i];
|
|
219
|
+
i += d;
|
|
220
|
+
e = s & (1 << -nBits) - 1;
|
|
221
|
+
s >>= -nBits;
|
|
222
|
+
nBits += eLen;
|
|
223
|
+
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {
|
|
224
|
+
}
|
|
225
|
+
m = e & (1 << -nBits) - 1;
|
|
226
|
+
e >>= -nBits;
|
|
227
|
+
nBits += mLen;
|
|
228
|
+
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {
|
|
229
|
+
}
|
|
230
|
+
if (e === 0) {
|
|
231
|
+
e = 1 - eBias;
|
|
232
|
+
} else if (e === eMax) {
|
|
233
|
+
return m ? NaN : (s ? -1 : 1) * Infinity;
|
|
234
|
+
} else {
|
|
235
|
+
m = m + Math.pow(2, mLen);
|
|
236
|
+
e = e - eBias;
|
|
237
|
+
}
|
|
238
|
+
return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
|
239
|
+
};
|
|
240
|
+
exports$2.write = function(buffer, value, offset, isLE, mLen, nBytes) {
|
|
241
|
+
var e, m, c;
|
|
242
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
243
|
+
var eMax = (1 << eLen) - 1;
|
|
244
|
+
var eBias = eMax >> 1;
|
|
245
|
+
var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
|
|
246
|
+
var i = isLE ? 0 : nBytes - 1;
|
|
247
|
+
var d = isLE ? 1 : -1;
|
|
248
|
+
var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
|
|
249
|
+
value = Math.abs(value);
|
|
250
|
+
if (isNaN(value) || value === Infinity) {
|
|
251
|
+
m = isNaN(value) ? 1 : 0;
|
|
252
|
+
e = eMax;
|
|
253
|
+
} else {
|
|
254
|
+
e = Math.floor(Math.log(value) / Math.LN2);
|
|
255
|
+
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
256
|
+
e--;
|
|
257
|
+
c *= 2;
|
|
258
|
+
}
|
|
259
|
+
if (e + eBias >= 1) {
|
|
260
|
+
value += rt / c;
|
|
261
|
+
} else {
|
|
262
|
+
value += rt * Math.pow(2, 1 - eBias);
|
|
263
|
+
}
|
|
264
|
+
if (value * c >= 2) {
|
|
265
|
+
e++;
|
|
266
|
+
c /= 2;
|
|
267
|
+
}
|
|
268
|
+
if (e + eBias >= eMax) {
|
|
269
|
+
m = 0;
|
|
270
|
+
e = eMax;
|
|
271
|
+
} else if (e + eBias >= 1) {
|
|
272
|
+
m = (value * c - 1) * Math.pow(2, mLen);
|
|
273
|
+
e = e + eBias;
|
|
274
|
+
} else {
|
|
275
|
+
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
276
|
+
e = 0;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
for (; mLen >= 8; buffer[offset + i] = m & 255, i += d, m /= 256, mLen -= 8) {
|
|
280
|
+
}
|
|
281
|
+
e = e << mLen | m;
|
|
282
|
+
eLen += mLen;
|
|
283
|
+
for (; eLen > 0; buffer[offset + i] = e & 255, i += d, e /= 256, eLen -= 8) {
|
|
284
|
+
}
|
|
285
|
+
buffer[offset + i - d] |= s * 128;
|
|
286
|
+
};
|
|
287
|
+
return exports$2;
|
|
288
|
+
}
|
|
289
|
+
function dew() {
|
|
290
|
+
if (_dewExec)
|
|
291
|
+
return exports$1;
|
|
292
|
+
_dewExec = true;
|
|
293
|
+
const base64 = dew$2();
|
|
294
|
+
const ieee754 = dew$1();
|
|
295
|
+
const customInspectSymbol = typeof Symbol === "function" && typeof Symbol["for"] === "function" ? Symbol["for"]("nodejs.util.inspect.custom") : null;
|
|
296
|
+
exports$1.Buffer = Buffer3;
|
|
297
|
+
exports$1.SlowBuffer = SlowBuffer;
|
|
298
|
+
exports$1.INSPECT_MAX_BYTES = 50;
|
|
299
|
+
const K_MAX_LENGTH = 2147483647;
|
|
300
|
+
exports$1.kMaxLength = K_MAX_LENGTH;
|
|
301
|
+
Buffer3.TYPED_ARRAY_SUPPORT = typedArraySupport();
|
|
302
|
+
if (!Buffer3.TYPED_ARRAY_SUPPORT && typeof console !== "undefined" && typeof console.error === "function") {
|
|
303
|
+
console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");
|
|
304
|
+
}
|
|
305
|
+
function typedArraySupport() {
|
|
306
|
+
try {
|
|
307
|
+
const arr = new Uint8Array(1);
|
|
308
|
+
const proto = {
|
|
309
|
+
foo: function() {
|
|
310
|
+
return 42;
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
Object.setPrototypeOf(proto, Uint8Array.prototype);
|
|
314
|
+
Object.setPrototypeOf(arr, proto);
|
|
315
|
+
return arr.foo() === 42;
|
|
316
|
+
} catch (e) {
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
Object.defineProperty(Buffer3.prototype, "parent", {
|
|
321
|
+
enumerable: true,
|
|
322
|
+
get: function() {
|
|
323
|
+
if (!Buffer3.isBuffer(this))
|
|
324
|
+
return void 0;
|
|
325
|
+
return this.buffer;
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
Object.defineProperty(Buffer3.prototype, "offset", {
|
|
329
|
+
enumerable: true,
|
|
330
|
+
get: function() {
|
|
331
|
+
if (!Buffer3.isBuffer(this))
|
|
332
|
+
return void 0;
|
|
333
|
+
return this.byteOffset;
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
function createBuffer(length) {
|
|
337
|
+
if (length > K_MAX_LENGTH) {
|
|
338
|
+
throw new RangeError('The value "' + length + '" is invalid for option "size"');
|
|
339
|
+
}
|
|
340
|
+
const buf = new Uint8Array(length);
|
|
341
|
+
Object.setPrototypeOf(buf, Buffer3.prototype);
|
|
342
|
+
return buf;
|
|
343
|
+
}
|
|
344
|
+
function Buffer3(arg, encodingOrOffset, length) {
|
|
345
|
+
if (typeof arg === "number") {
|
|
346
|
+
if (typeof encodingOrOffset === "string") {
|
|
347
|
+
throw new TypeError('The "string" argument must be of type string. Received type number');
|
|
348
|
+
}
|
|
349
|
+
return allocUnsafe(arg);
|
|
350
|
+
}
|
|
351
|
+
return from(arg, encodingOrOffset, length);
|
|
352
|
+
}
|
|
353
|
+
Buffer3.poolSize = 8192;
|
|
354
|
+
function from(value, encodingOrOffset, length) {
|
|
355
|
+
if (typeof value === "string") {
|
|
356
|
+
return fromString(value, encodingOrOffset);
|
|
357
|
+
}
|
|
358
|
+
if (ArrayBuffer.isView(value)) {
|
|
359
|
+
return fromArrayView(value);
|
|
360
|
+
}
|
|
361
|
+
if (value == null) {
|
|
362
|
+
throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value);
|
|
363
|
+
}
|
|
364
|
+
if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) {
|
|
365
|
+
return fromArrayBuffer(value, encodingOrOffset, length);
|
|
366
|
+
}
|
|
367
|
+
if (typeof SharedArrayBuffer !== "undefined" && (isInstance(value, SharedArrayBuffer) || value && isInstance(value.buffer, SharedArrayBuffer))) {
|
|
368
|
+
return fromArrayBuffer(value, encodingOrOffset, length);
|
|
369
|
+
}
|
|
370
|
+
if (typeof value === "number") {
|
|
371
|
+
throw new TypeError('The "value" argument must not be of type number. Received type number');
|
|
372
|
+
}
|
|
373
|
+
const valueOf = value.valueOf && value.valueOf();
|
|
374
|
+
if (valueOf != null && valueOf !== value) {
|
|
375
|
+
return Buffer3.from(valueOf, encodingOrOffset, length);
|
|
376
|
+
}
|
|
377
|
+
const b = fromObject(value);
|
|
378
|
+
if (b)
|
|
379
|
+
return b;
|
|
380
|
+
if (typeof Symbol !== "undefined" && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === "function") {
|
|
381
|
+
return Buffer3.from(value[Symbol.toPrimitive]("string"), encodingOrOffset, length);
|
|
382
|
+
}
|
|
383
|
+
throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value);
|
|
384
|
+
}
|
|
385
|
+
Buffer3.from = function(value, encodingOrOffset, length) {
|
|
386
|
+
return from(value, encodingOrOffset, length);
|
|
387
|
+
};
|
|
388
|
+
Object.setPrototypeOf(Buffer3.prototype, Uint8Array.prototype);
|
|
389
|
+
Object.setPrototypeOf(Buffer3, Uint8Array);
|
|
390
|
+
function assertSize(size) {
|
|
391
|
+
if (typeof size !== "number") {
|
|
392
|
+
throw new TypeError('"size" argument must be of type number');
|
|
393
|
+
} else if (size < 0) {
|
|
394
|
+
throw new RangeError('The value "' + size + '" is invalid for option "size"');
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
function alloc(size, fill, encoding) {
|
|
398
|
+
assertSize(size);
|
|
399
|
+
if (size <= 0) {
|
|
400
|
+
return createBuffer(size);
|
|
401
|
+
}
|
|
402
|
+
if (fill !== void 0) {
|
|
403
|
+
return typeof encoding === "string" ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill);
|
|
404
|
+
}
|
|
405
|
+
return createBuffer(size);
|
|
406
|
+
}
|
|
407
|
+
Buffer3.alloc = function(size, fill, encoding) {
|
|
408
|
+
return alloc(size, fill, encoding);
|
|
409
|
+
};
|
|
410
|
+
function allocUnsafe(size) {
|
|
411
|
+
assertSize(size);
|
|
412
|
+
return createBuffer(size < 0 ? 0 : checked(size) | 0);
|
|
413
|
+
}
|
|
414
|
+
Buffer3.allocUnsafe = function(size) {
|
|
415
|
+
return allocUnsafe(size);
|
|
416
|
+
};
|
|
417
|
+
Buffer3.allocUnsafeSlow = function(size) {
|
|
418
|
+
return allocUnsafe(size);
|
|
419
|
+
};
|
|
420
|
+
function fromString(string, encoding) {
|
|
421
|
+
if (typeof encoding !== "string" || encoding === "") {
|
|
422
|
+
encoding = "utf8";
|
|
423
|
+
}
|
|
424
|
+
if (!Buffer3.isEncoding(encoding)) {
|
|
425
|
+
throw new TypeError("Unknown encoding: " + encoding);
|
|
426
|
+
}
|
|
427
|
+
const length = byteLength(string, encoding) | 0;
|
|
428
|
+
let buf = createBuffer(length);
|
|
429
|
+
const actual = buf.write(string, encoding);
|
|
430
|
+
if (actual !== length) {
|
|
431
|
+
buf = buf.slice(0, actual);
|
|
432
|
+
}
|
|
433
|
+
return buf;
|
|
434
|
+
}
|
|
435
|
+
function fromArrayLike(array) {
|
|
436
|
+
const length = array.length < 0 ? 0 : checked(array.length) | 0;
|
|
437
|
+
const buf = createBuffer(length);
|
|
438
|
+
for (let i = 0; i < length; i += 1) {
|
|
439
|
+
buf[i] = array[i] & 255;
|
|
440
|
+
}
|
|
441
|
+
return buf;
|
|
442
|
+
}
|
|
443
|
+
function fromArrayView(arrayView) {
|
|
444
|
+
if (isInstance(arrayView, Uint8Array)) {
|
|
445
|
+
const copy = new Uint8Array(arrayView);
|
|
446
|
+
return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength);
|
|
447
|
+
}
|
|
448
|
+
return fromArrayLike(arrayView);
|
|
449
|
+
}
|
|
450
|
+
function fromArrayBuffer(array, byteOffset, length) {
|
|
451
|
+
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
|
452
|
+
throw new RangeError('"offset" is outside of buffer bounds');
|
|
453
|
+
}
|
|
454
|
+
if (array.byteLength < byteOffset + (length || 0)) {
|
|
455
|
+
throw new RangeError('"length" is outside of buffer bounds');
|
|
456
|
+
}
|
|
457
|
+
let buf;
|
|
458
|
+
if (byteOffset === void 0 && length === void 0) {
|
|
459
|
+
buf = new Uint8Array(array);
|
|
460
|
+
} else if (length === void 0) {
|
|
461
|
+
buf = new Uint8Array(array, byteOffset);
|
|
462
|
+
} else {
|
|
463
|
+
buf = new Uint8Array(array, byteOffset, length);
|
|
464
|
+
}
|
|
465
|
+
Object.setPrototypeOf(buf, Buffer3.prototype);
|
|
466
|
+
return buf;
|
|
467
|
+
}
|
|
468
|
+
function fromObject(obj) {
|
|
469
|
+
if (Buffer3.isBuffer(obj)) {
|
|
470
|
+
const len = checked(obj.length) | 0;
|
|
471
|
+
const buf = createBuffer(len);
|
|
472
|
+
if (buf.length === 0) {
|
|
473
|
+
return buf;
|
|
474
|
+
}
|
|
475
|
+
obj.copy(buf, 0, 0, len);
|
|
476
|
+
return buf;
|
|
477
|
+
}
|
|
478
|
+
if (obj.length !== void 0) {
|
|
479
|
+
if (typeof obj.length !== "number" || numberIsNaN(obj.length)) {
|
|
480
|
+
return createBuffer(0);
|
|
481
|
+
}
|
|
482
|
+
return fromArrayLike(obj);
|
|
483
|
+
}
|
|
484
|
+
if (obj.type === "Buffer" && Array.isArray(obj.data)) {
|
|
485
|
+
return fromArrayLike(obj.data);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
function checked(length) {
|
|
489
|
+
if (length >= K_MAX_LENGTH) {
|
|
490
|
+
throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + K_MAX_LENGTH.toString(16) + " bytes");
|
|
491
|
+
}
|
|
492
|
+
return length | 0;
|
|
493
|
+
}
|
|
494
|
+
function SlowBuffer(length) {
|
|
495
|
+
if (+length != length) {
|
|
496
|
+
length = 0;
|
|
497
|
+
}
|
|
498
|
+
return Buffer3.alloc(+length);
|
|
499
|
+
}
|
|
500
|
+
Buffer3.isBuffer = function isBuffer(b) {
|
|
501
|
+
return b != null && b._isBuffer === true && b !== Buffer3.prototype;
|
|
502
|
+
};
|
|
503
|
+
Buffer3.compare = function compare(a, b) {
|
|
504
|
+
if (isInstance(a, Uint8Array))
|
|
505
|
+
a = Buffer3.from(a, a.offset, a.byteLength);
|
|
506
|
+
if (isInstance(b, Uint8Array))
|
|
507
|
+
b = Buffer3.from(b, b.offset, b.byteLength);
|
|
508
|
+
if (!Buffer3.isBuffer(a) || !Buffer3.isBuffer(b)) {
|
|
509
|
+
throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');
|
|
510
|
+
}
|
|
511
|
+
if (a === b)
|
|
512
|
+
return 0;
|
|
513
|
+
let x = a.length;
|
|
514
|
+
let y = b.length;
|
|
515
|
+
for (let i = 0, len = Math.min(x, y); i < len; ++i) {
|
|
516
|
+
if (a[i] !== b[i]) {
|
|
517
|
+
x = a[i];
|
|
518
|
+
y = b[i];
|
|
519
|
+
break;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
if (x < y)
|
|
523
|
+
return -1;
|
|
524
|
+
if (y < x)
|
|
525
|
+
return 1;
|
|
526
|
+
return 0;
|
|
527
|
+
};
|
|
528
|
+
Buffer3.isEncoding = function isEncoding(encoding) {
|
|
529
|
+
switch (String(encoding).toLowerCase()) {
|
|
530
|
+
case "hex":
|
|
531
|
+
case "utf8":
|
|
532
|
+
case "utf-8":
|
|
533
|
+
case "ascii":
|
|
534
|
+
case "latin1":
|
|
535
|
+
case "binary":
|
|
536
|
+
case "base64":
|
|
537
|
+
case "ucs2":
|
|
538
|
+
case "ucs-2":
|
|
539
|
+
case "utf16le":
|
|
540
|
+
case "utf-16le":
|
|
541
|
+
return true;
|
|
542
|
+
default:
|
|
543
|
+
return false;
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
Buffer3.concat = function concat(list, length) {
|
|
547
|
+
if (!Array.isArray(list)) {
|
|
548
|
+
throw new TypeError('"list" argument must be an Array of Buffers');
|
|
549
|
+
}
|
|
550
|
+
if (list.length === 0) {
|
|
551
|
+
return Buffer3.alloc(0);
|
|
552
|
+
}
|
|
553
|
+
let i;
|
|
554
|
+
if (length === void 0) {
|
|
555
|
+
length = 0;
|
|
556
|
+
for (i = 0; i < list.length; ++i) {
|
|
557
|
+
length += list[i].length;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
const buffer = Buffer3.allocUnsafe(length);
|
|
561
|
+
let pos = 0;
|
|
562
|
+
for (i = 0; i < list.length; ++i) {
|
|
563
|
+
let buf = list[i];
|
|
564
|
+
if (isInstance(buf, Uint8Array)) {
|
|
565
|
+
if (pos + buf.length > buffer.length) {
|
|
566
|
+
if (!Buffer3.isBuffer(buf))
|
|
567
|
+
buf = Buffer3.from(buf);
|
|
568
|
+
buf.copy(buffer, pos);
|
|
569
|
+
} else {
|
|
570
|
+
Uint8Array.prototype.set.call(buffer, buf, pos);
|
|
571
|
+
}
|
|
572
|
+
} else if (!Buffer3.isBuffer(buf)) {
|
|
573
|
+
throw new TypeError('"list" argument must be an Array of Buffers');
|
|
574
|
+
} else {
|
|
575
|
+
buf.copy(buffer, pos);
|
|
576
|
+
}
|
|
577
|
+
pos += buf.length;
|
|
578
|
+
}
|
|
579
|
+
return buffer;
|
|
580
|
+
};
|
|
581
|
+
function byteLength(string, encoding) {
|
|
582
|
+
if (Buffer3.isBuffer(string)) {
|
|
583
|
+
return string.length;
|
|
584
|
+
}
|
|
585
|
+
if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
|
|
586
|
+
return string.byteLength;
|
|
587
|
+
}
|
|
588
|
+
if (typeof string !== "string") {
|
|
589
|
+
throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type ' + typeof string);
|
|
590
|
+
}
|
|
591
|
+
const len = string.length;
|
|
592
|
+
const mustMatch = arguments.length > 2 && arguments[2] === true;
|
|
593
|
+
if (!mustMatch && len === 0)
|
|
594
|
+
return 0;
|
|
595
|
+
let loweredCase = false;
|
|
596
|
+
for (; ; ) {
|
|
597
|
+
switch (encoding) {
|
|
598
|
+
case "ascii":
|
|
599
|
+
case "latin1":
|
|
600
|
+
case "binary":
|
|
601
|
+
return len;
|
|
602
|
+
case "utf8":
|
|
603
|
+
case "utf-8":
|
|
604
|
+
return utf8ToBytes(string).length;
|
|
605
|
+
case "ucs2":
|
|
606
|
+
case "ucs-2":
|
|
607
|
+
case "utf16le":
|
|
608
|
+
case "utf-16le":
|
|
609
|
+
return len * 2;
|
|
610
|
+
case "hex":
|
|
611
|
+
return len >>> 1;
|
|
612
|
+
case "base64":
|
|
613
|
+
return base64ToBytes(string).length;
|
|
614
|
+
default:
|
|
615
|
+
if (loweredCase) {
|
|
616
|
+
return mustMatch ? -1 : utf8ToBytes(string).length;
|
|
617
|
+
}
|
|
618
|
+
encoding = ("" + encoding).toLowerCase();
|
|
619
|
+
loweredCase = true;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
Buffer3.byteLength = byteLength;
|
|
624
|
+
function slowToString(encoding, start, end) {
|
|
625
|
+
let loweredCase = false;
|
|
626
|
+
if (start === void 0 || start < 0) {
|
|
627
|
+
start = 0;
|
|
628
|
+
}
|
|
629
|
+
if (start > this.length) {
|
|
630
|
+
return "";
|
|
631
|
+
}
|
|
632
|
+
if (end === void 0 || end > this.length) {
|
|
633
|
+
end = this.length;
|
|
634
|
+
}
|
|
635
|
+
if (end <= 0) {
|
|
636
|
+
return "";
|
|
637
|
+
}
|
|
638
|
+
end >>>= 0;
|
|
639
|
+
start >>>= 0;
|
|
640
|
+
if (end <= start) {
|
|
641
|
+
return "";
|
|
642
|
+
}
|
|
643
|
+
if (!encoding)
|
|
644
|
+
encoding = "utf8";
|
|
645
|
+
while (true) {
|
|
646
|
+
switch (encoding) {
|
|
647
|
+
case "hex":
|
|
648
|
+
return hexSlice(this, start, end);
|
|
649
|
+
case "utf8":
|
|
650
|
+
case "utf-8":
|
|
651
|
+
return utf8Slice(this, start, end);
|
|
652
|
+
case "ascii":
|
|
653
|
+
return asciiSlice(this, start, end);
|
|
654
|
+
case "latin1":
|
|
655
|
+
case "binary":
|
|
656
|
+
return latin1Slice(this, start, end);
|
|
657
|
+
case "base64":
|
|
658
|
+
return base64Slice(this, start, end);
|
|
659
|
+
case "ucs2":
|
|
660
|
+
case "ucs-2":
|
|
661
|
+
case "utf16le":
|
|
662
|
+
case "utf-16le":
|
|
663
|
+
return utf16leSlice(this, start, end);
|
|
664
|
+
default:
|
|
665
|
+
if (loweredCase)
|
|
666
|
+
throw new TypeError("Unknown encoding: " + encoding);
|
|
667
|
+
encoding = (encoding + "").toLowerCase();
|
|
668
|
+
loweredCase = true;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
Buffer3.prototype._isBuffer = true;
|
|
673
|
+
function swap(b, n, m) {
|
|
674
|
+
const i = b[n];
|
|
675
|
+
b[n] = b[m];
|
|
676
|
+
b[m] = i;
|
|
677
|
+
}
|
|
678
|
+
Buffer3.prototype.swap16 = function swap16() {
|
|
679
|
+
const len = this.length;
|
|
680
|
+
if (len % 2 !== 0) {
|
|
681
|
+
throw new RangeError("Buffer size must be a multiple of 16-bits");
|
|
682
|
+
}
|
|
683
|
+
for (let i = 0; i < len; i += 2) {
|
|
684
|
+
swap(this, i, i + 1);
|
|
685
|
+
}
|
|
686
|
+
return this;
|
|
687
|
+
};
|
|
688
|
+
Buffer3.prototype.swap32 = function swap32() {
|
|
689
|
+
const len = this.length;
|
|
690
|
+
if (len % 4 !== 0) {
|
|
691
|
+
throw new RangeError("Buffer size must be a multiple of 32-bits");
|
|
692
|
+
}
|
|
693
|
+
for (let i = 0; i < len; i += 4) {
|
|
694
|
+
swap(this, i, i + 3);
|
|
695
|
+
swap(this, i + 1, i + 2);
|
|
696
|
+
}
|
|
697
|
+
return this;
|
|
698
|
+
};
|
|
699
|
+
Buffer3.prototype.swap64 = function swap64() {
|
|
700
|
+
const len = this.length;
|
|
701
|
+
if (len % 8 !== 0) {
|
|
702
|
+
throw new RangeError("Buffer size must be a multiple of 64-bits");
|
|
703
|
+
}
|
|
704
|
+
for (let i = 0; i < len; i += 8) {
|
|
705
|
+
swap(this, i, i + 7);
|
|
706
|
+
swap(this, i + 1, i + 6);
|
|
707
|
+
swap(this, i + 2, i + 5);
|
|
708
|
+
swap(this, i + 3, i + 4);
|
|
709
|
+
}
|
|
710
|
+
return this;
|
|
711
|
+
};
|
|
712
|
+
Buffer3.prototype.toString = function toString() {
|
|
713
|
+
const length = this.length;
|
|
714
|
+
if (length === 0)
|
|
715
|
+
return "";
|
|
716
|
+
if (arguments.length === 0)
|
|
717
|
+
return utf8Slice(this, 0, length);
|
|
718
|
+
return slowToString.apply(this, arguments);
|
|
719
|
+
};
|
|
720
|
+
Buffer3.prototype.toLocaleString = Buffer3.prototype.toString;
|
|
721
|
+
Buffer3.prototype.equals = function equals(b) {
|
|
722
|
+
if (!Buffer3.isBuffer(b))
|
|
723
|
+
throw new TypeError("Argument must be a Buffer");
|
|
724
|
+
if (this === b)
|
|
725
|
+
return true;
|
|
726
|
+
return Buffer3.compare(this, b) === 0;
|
|
727
|
+
};
|
|
728
|
+
Buffer3.prototype.inspect = function inspect() {
|
|
729
|
+
let str2 = "";
|
|
730
|
+
const max = exports$1.INSPECT_MAX_BYTES;
|
|
731
|
+
str2 = this.toString("hex", 0, max).replace(/(.{2})/g, "$1 ").trim();
|
|
732
|
+
if (this.length > max)
|
|
733
|
+
str2 += " ... ";
|
|
734
|
+
return "<Buffer " + str2 + ">";
|
|
735
|
+
};
|
|
736
|
+
if (customInspectSymbol) {
|
|
737
|
+
Buffer3.prototype[customInspectSymbol] = Buffer3.prototype.inspect;
|
|
738
|
+
}
|
|
739
|
+
Buffer3.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {
|
|
740
|
+
if (isInstance(target, Uint8Array)) {
|
|
741
|
+
target = Buffer3.from(target, target.offset, target.byteLength);
|
|
742
|
+
}
|
|
743
|
+
if (!Buffer3.isBuffer(target)) {
|
|
744
|
+
throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type ' + typeof target);
|
|
745
|
+
}
|
|
746
|
+
if (start === void 0) {
|
|
747
|
+
start = 0;
|
|
748
|
+
}
|
|
749
|
+
if (end === void 0) {
|
|
750
|
+
end = target ? target.length : 0;
|
|
751
|
+
}
|
|
752
|
+
if (thisStart === void 0) {
|
|
753
|
+
thisStart = 0;
|
|
754
|
+
}
|
|
755
|
+
if (thisEnd === void 0) {
|
|
756
|
+
thisEnd = this.length;
|
|
757
|
+
}
|
|
758
|
+
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
|
759
|
+
throw new RangeError("out of range index");
|
|
760
|
+
}
|
|
761
|
+
if (thisStart >= thisEnd && start >= end) {
|
|
762
|
+
return 0;
|
|
763
|
+
}
|
|
764
|
+
if (thisStart >= thisEnd) {
|
|
765
|
+
return -1;
|
|
766
|
+
}
|
|
767
|
+
if (start >= end) {
|
|
768
|
+
return 1;
|
|
769
|
+
}
|
|
770
|
+
start >>>= 0;
|
|
771
|
+
end >>>= 0;
|
|
772
|
+
thisStart >>>= 0;
|
|
773
|
+
thisEnd >>>= 0;
|
|
774
|
+
if (this === target)
|
|
775
|
+
return 0;
|
|
776
|
+
let x = thisEnd - thisStart;
|
|
777
|
+
let y = end - start;
|
|
778
|
+
const len = Math.min(x, y);
|
|
779
|
+
const thisCopy = this.slice(thisStart, thisEnd);
|
|
780
|
+
const targetCopy = target.slice(start, end);
|
|
781
|
+
for (let i = 0; i < len; ++i) {
|
|
782
|
+
if (thisCopy[i] !== targetCopy[i]) {
|
|
783
|
+
x = thisCopy[i];
|
|
784
|
+
y = targetCopy[i];
|
|
785
|
+
break;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
if (x < y)
|
|
789
|
+
return -1;
|
|
790
|
+
if (y < x)
|
|
791
|
+
return 1;
|
|
792
|
+
return 0;
|
|
793
|
+
};
|
|
794
|
+
function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
|
|
795
|
+
if (buffer.length === 0)
|
|
796
|
+
return -1;
|
|
797
|
+
if (typeof byteOffset === "string") {
|
|
798
|
+
encoding = byteOffset;
|
|
799
|
+
byteOffset = 0;
|
|
800
|
+
} else if (byteOffset > 2147483647) {
|
|
801
|
+
byteOffset = 2147483647;
|
|
802
|
+
} else if (byteOffset < -2147483648) {
|
|
803
|
+
byteOffset = -2147483648;
|
|
804
|
+
}
|
|
805
|
+
byteOffset = +byteOffset;
|
|
806
|
+
if (numberIsNaN(byteOffset)) {
|
|
807
|
+
byteOffset = dir ? 0 : buffer.length - 1;
|
|
808
|
+
}
|
|
809
|
+
if (byteOffset < 0)
|
|
810
|
+
byteOffset = buffer.length + byteOffset;
|
|
811
|
+
if (byteOffset >= buffer.length) {
|
|
812
|
+
if (dir)
|
|
813
|
+
return -1;
|
|
814
|
+
else
|
|
815
|
+
byteOffset = buffer.length - 1;
|
|
816
|
+
} else if (byteOffset < 0) {
|
|
817
|
+
if (dir)
|
|
818
|
+
byteOffset = 0;
|
|
819
|
+
else
|
|
820
|
+
return -1;
|
|
821
|
+
}
|
|
822
|
+
if (typeof val === "string") {
|
|
823
|
+
val = Buffer3.from(val, encoding);
|
|
824
|
+
}
|
|
825
|
+
if (Buffer3.isBuffer(val)) {
|
|
826
|
+
if (val.length === 0) {
|
|
827
|
+
return -1;
|
|
828
|
+
}
|
|
829
|
+
return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
|
|
830
|
+
} else if (typeof val === "number") {
|
|
831
|
+
val = val & 255;
|
|
832
|
+
if (typeof Uint8Array.prototype.indexOf === "function") {
|
|
833
|
+
if (dir) {
|
|
834
|
+
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
|
|
835
|
+
} else {
|
|
836
|
+
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
|
|
840
|
+
}
|
|
841
|
+
throw new TypeError("val must be string, number or Buffer");
|
|
842
|
+
}
|
|
843
|
+
function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
|
|
844
|
+
let indexSize = 1;
|
|
845
|
+
let arrLength = arr.length;
|
|
846
|
+
let valLength = val.length;
|
|
847
|
+
if (encoding !== void 0) {
|
|
848
|
+
encoding = String(encoding).toLowerCase();
|
|
849
|
+
if (encoding === "ucs2" || encoding === "ucs-2" || encoding === "utf16le" || encoding === "utf-16le") {
|
|
850
|
+
if (arr.length < 2 || val.length < 2) {
|
|
851
|
+
return -1;
|
|
852
|
+
}
|
|
853
|
+
indexSize = 2;
|
|
854
|
+
arrLength /= 2;
|
|
855
|
+
valLength /= 2;
|
|
856
|
+
byteOffset /= 2;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
function read(buf, i2) {
|
|
860
|
+
if (indexSize === 1) {
|
|
861
|
+
return buf[i2];
|
|
862
|
+
} else {
|
|
863
|
+
return buf.readUInt16BE(i2 * indexSize);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
let i;
|
|
867
|
+
if (dir) {
|
|
868
|
+
let foundIndex = -1;
|
|
869
|
+
for (i = byteOffset; i < arrLength; i++) {
|
|
870
|
+
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
|
871
|
+
if (foundIndex === -1)
|
|
872
|
+
foundIndex = i;
|
|
873
|
+
if (i - foundIndex + 1 === valLength)
|
|
874
|
+
return foundIndex * indexSize;
|
|
875
|
+
} else {
|
|
876
|
+
if (foundIndex !== -1)
|
|
877
|
+
i -= i - foundIndex;
|
|
878
|
+
foundIndex = -1;
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
} else {
|
|
882
|
+
if (byteOffset + valLength > arrLength)
|
|
883
|
+
byteOffset = arrLength - valLength;
|
|
884
|
+
for (i = byteOffset; i >= 0; i--) {
|
|
885
|
+
let found = true;
|
|
886
|
+
for (let j = 0; j < valLength; j++) {
|
|
887
|
+
if (read(arr, i + j) !== read(val, j)) {
|
|
888
|
+
found = false;
|
|
889
|
+
break;
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
if (found)
|
|
893
|
+
return i;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
return -1;
|
|
897
|
+
}
|
|
898
|
+
Buffer3.prototype.includes = function includes(val, byteOffset, encoding) {
|
|
899
|
+
return this.indexOf(val, byteOffset, encoding) !== -1;
|
|
900
|
+
};
|
|
901
|
+
Buffer3.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
|
|
902
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
|
|
903
|
+
};
|
|
904
|
+
Buffer3.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
|
|
905
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
|
|
906
|
+
};
|
|
907
|
+
function hexWrite(buf, string, offset, length) {
|
|
908
|
+
offset = Number(offset) || 0;
|
|
909
|
+
const remaining = buf.length - offset;
|
|
910
|
+
if (!length) {
|
|
911
|
+
length = remaining;
|
|
912
|
+
} else {
|
|
913
|
+
length = Number(length);
|
|
914
|
+
if (length > remaining) {
|
|
915
|
+
length = remaining;
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
const strLen = string.length;
|
|
919
|
+
if (length > strLen / 2) {
|
|
920
|
+
length = strLen / 2;
|
|
921
|
+
}
|
|
922
|
+
let i;
|
|
923
|
+
for (i = 0; i < length; ++i) {
|
|
924
|
+
const parsed = parseInt(string.substr(i * 2, 2), 16);
|
|
925
|
+
if (numberIsNaN(parsed))
|
|
926
|
+
return i;
|
|
927
|
+
buf[offset + i] = parsed;
|
|
928
|
+
}
|
|
929
|
+
return i;
|
|
930
|
+
}
|
|
931
|
+
function utf8Write(buf, string, offset, length) {
|
|
932
|
+
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
|
|
933
|
+
}
|
|
934
|
+
function asciiWrite(buf, string, offset, length) {
|
|
935
|
+
return blitBuffer(asciiToBytes(string), buf, offset, length);
|
|
936
|
+
}
|
|
937
|
+
function base64Write(buf, string, offset, length) {
|
|
938
|
+
return blitBuffer(base64ToBytes(string), buf, offset, length);
|
|
939
|
+
}
|
|
940
|
+
function ucs2Write(buf, string, offset, length) {
|
|
941
|
+
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);
|
|
942
|
+
}
|
|
943
|
+
Buffer3.prototype.write = function write(string, offset, length, encoding) {
|
|
944
|
+
if (offset === void 0) {
|
|
945
|
+
encoding = "utf8";
|
|
946
|
+
length = this.length;
|
|
947
|
+
offset = 0;
|
|
948
|
+
} else if (length === void 0 && typeof offset === "string") {
|
|
949
|
+
encoding = offset;
|
|
950
|
+
length = this.length;
|
|
951
|
+
offset = 0;
|
|
952
|
+
} else if (isFinite(offset)) {
|
|
953
|
+
offset = offset >>> 0;
|
|
954
|
+
if (isFinite(length)) {
|
|
955
|
+
length = length >>> 0;
|
|
956
|
+
if (encoding === void 0)
|
|
957
|
+
encoding = "utf8";
|
|
958
|
+
} else {
|
|
959
|
+
encoding = length;
|
|
960
|
+
length = void 0;
|
|
961
|
+
}
|
|
962
|
+
} else {
|
|
963
|
+
throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");
|
|
964
|
+
}
|
|
965
|
+
const remaining = this.length - offset;
|
|
966
|
+
if (length === void 0 || length > remaining)
|
|
967
|
+
length = remaining;
|
|
968
|
+
if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) {
|
|
969
|
+
throw new RangeError("Attempt to write outside buffer bounds");
|
|
970
|
+
}
|
|
971
|
+
if (!encoding)
|
|
972
|
+
encoding = "utf8";
|
|
973
|
+
let loweredCase = false;
|
|
974
|
+
for (; ; ) {
|
|
975
|
+
switch (encoding) {
|
|
976
|
+
case "hex":
|
|
977
|
+
return hexWrite(this, string, offset, length);
|
|
978
|
+
case "utf8":
|
|
979
|
+
case "utf-8":
|
|
980
|
+
return utf8Write(this, string, offset, length);
|
|
981
|
+
case "ascii":
|
|
982
|
+
case "latin1":
|
|
983
|
+
case "binary":
|
|
984
|
+
return asciiWrite(this, string, offset, length);
|
|
985
|
+
case "base64":
|
|
986
|
+
return base64Write(this, string, offset, length);
|
|
987
|
+
case "ucs2":
|
|
988
|
+
case "ucs-2":
|
|
989
|
+
case "utf16le":
|
|
990
|
+
case "utf-16le":
|
|
991
|
+
return ucs2Write(this, string, offset, length);
|
|
992
|
+
default:
|
|
993
|
+
if (loweredCase)
|
|
994
|
+
throw new TypeError("Unknown encoding: " + encoding);
|
|
995
|
+
encoding = ("" + encoding).toLowerCase();
|
|
996
|
+
loweredCase = true;
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
};
|
|
1000
|
+
Buffer3.prototype.toJSON = function toJSON() {
|
|
1001
|
+
return {
|
|
1002
|
+
type: "Buffer",
|
|
1003
|
+
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
1004
|
+
};
|
|
1005
|
+
};
|
|
1006
|
+
function base64Slice(buf, start, end) {
|
|
1007
|
+
if (start === 0 && end === buf.length) {
|
|
1008
|
+
return base64.fromByteArray(buf);
|
|
1009
|
+
} else {
|
|
1010
|
+
return base64.fromByteArray(buf.slice(start, end));
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
function utf8Slice(buf, start, end) {
|
|
1014
|
+
end = Math.min(buf.length, end);
|
|
1015
|
+
const res = [];
|
|
1016
|
+
let i = start;
|
|
1017
|
+
while (i < end) {
|
|
1018
|
+
const firstByte = buf[i];
|
|
1019
|
+
let codePoint = null;
|
|
1020
|
+
let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;
|
|
1021
|
+
if (i + bytesPerSequence <= end) {
|
|
1022
|
+
let secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
1023
|
+
switch (bytesPerSequence) {
|
|
1024
|
+
case 1:
|
|
1025
|
+
if (firstByte < 128) {
|
|
1026
|
+
codePoint = firstByte;
|
|
1027
|
+
}
|
|
1028
|
+
break;
|
|
1029
|
+
case 2:
|
|
1030
|
+
secondByte = buf[i + 1];
|
|
1031
|
+
if ((secondByte & 192) === 128) {
|
|
1032
|
+
tempCodePoint = (firstByte & 31) << 6 | secondByte & 63;
|
|
1033
|
+
if (tempCodePoint > 127) {
|
|
1034
|
+
codePoint = tempCodePoint;
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
break;
|
|
1038
|
+
case 3:
|
|
1039
|
+
secondByte = buf[i + 1];
|
|
1040
|
+
thirdByte = buf[i + 2];
|
|
1041
|
+
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) {
|
|
1042
|
+
tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63;
|
|
1043
|
+
if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) {
|
|
1044
|
+
codePoint = tempCodePoint;
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
break;
|
|
1048
|
+
case 4:
|
|
1049
|
+
secondByte = buf[i + 1];
|
|
1050
|
+
thirdByte = buf[i + 2];
|
|
1051
|
+
fourthByte = buf[i + 3];
|
|
1052
|
+
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {
|
|
1053
|
+
tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63;
|
|
1054
|
+
if (tempCodePoint > 65535 && tempCodePoint < 1114112) {
|
|
1055
|
+
codePoint = tempCodePoint;
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
if (codePoint === null) {
|
|
1061
|
+
codePoint = 65533;
|
|
1062
|
+
bytesPerSequence = 1;
|
|
1063
|
+
} else if (codePoint > 65535) {
|
|
1064
|
+
codePoint -= 65536;
|
|
1065
|
+
res.push(codePoint >>> 10 & 1023 | 55296);
|
|
1066
|
+
codePoint = 56320 | codePoint & 1023;
|
|
1067
|
+
}
|
|
1068
|
+
res.push(codePoint);
|
|
1069
|
+
i += bytesPerSequence;
|
|
1070
|
+
}
|
|
1071
|
+
return decodeCodePointsArray(res);
|
|
1072
|
+
}
|
|
1073
|
+
const MAX_ARGUMENTS_LENGTH = 4096;
|
|
1074
|
+
function decodeCodePointsArray(codePoints) {
|
|
1075
|
+
const len = codePoints.length;
|
|
1076
|
+
if (len <= MAX_ARGUMENTS_LENGTH) {
|
|
1077
|
+
return String.fromCharCode.apply(String, codePoints);
|
|
1078
|
+
}
|
|
1079
|
+
let res = "";
|
|
1080
|
+
let i = 0;
|
|
1081
|
+
while (i < len) {
|
|
1082
|
+
res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH));
|
|
1083
|
+
}
|
|
1084
|
+
return res;
|
|
1085
|
+
}
|
|
1086
|
+
function asciiSlice(buf, start, end) {
|
|
1087
|
+
let ret = "";
|
|
1088
|
+
end = Math.min(buf.length, end);
|
|
1089
|
+
for (let i = start; i < end; ++i) {
|
|
1090
|
+
ret += String.fromCharCode(buf[i] & 127);
|
|
1091
|
+
}
|
|
1092
|
+
return ret;
|
|
1093
|
+
}
|
|
1094
|
+
function latin1Slice(buf, start, end) {
|
|
1095
|
+
let ret = "";
|
|
1096
|
+
end = Math.min(buf.length, end);
|
|
1097
|
+
for (let i = start; i < end; ++i) {
|
|
1098
|
+
ret += String.fromCharCode(buf[i]);
|
|
1099
|
+
}
|
|
1100
|
+
return ret;
|
|
1101
|
+
}
|
|
1102
|
+
function hexSlice(buf, start, end) {
|
|
1103
|
+
const len = buf.length;
|
|
1104
|
+
if (!start || start < 0)
|
|
1105
|
+
start = 0;
|
|
1106
|
+
if (!end || end < 0 || end > len)
|
|
1107
|
+
end = len;
|
|
1108
|
+
let out = "";
|
|
1109
|
+
for (let i = start; i < end; ++i) {
|
|
1110
|
+
out += hexSliceLookupTable[buf[i]];
|
|
1111
|
+
}
|
|
1112
|
+
return out;
|
|
1113
|
+
}
|
|
1114
|
+
function utf16leSlice(buf, start, end) {
|
|
1115
|
+
const bytes = buf.slice(start, end);
|
|
1116
|
+
let res = "";
|
|
1117
|
+
for (let i = 0; i < bytes.length - 1; i += 2) {
|
|
1118
|
+
res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
|
|
1119
|
+
}
|
|
1120
|
+
return res;
|
|
1121
|
+
}
|
|
1122
|
+
Buffer3.prototype.slice = function slice(start, end) {
|
|
1123
|
+
const len = this.length;
|
|
1124
|
+
start = ~~start;
|
|
1125
|
+
end = end === void 0 ? len : ~~end;
|
|
1126
|
+
if (start < 0) {
|
|
1127
|
+
start += len;
|
|
1128
|
+
if (start < 0)
|
|
1129
|
+
start = 0;
|
|
1130
|
+
} else if (start > len) {
|
|
1131
|
+
start = len;
|
|
1132
|
+
}
|
|
1133
|
+
if (end < 0) {
|
|
1134
|
+
end += len;
|
|
1135
|
+
if (end < 0)
|
|
1136
|
+
end = 0;
|
|
1137
|
+
} else if (end > len) {
|
|
1138
|
+
end = len;
|
|
1139
|
+
}
|
|
1140
|
+
if (end < start)
|
|
1141
|
+
end = start;
|
|
1142
|
+
const newBuf = this.subarray(start, end);
|
|
1143
|
+
Object.setPrototypeOf(newBuf, Buffer3.prototype);
|
|
1144
|
+
return newBuf;
|
|
1145
|
+
};
|
|
1146
|
+
function checkOffset(offset, ext, length) {
|
|
1147
|
+
if (offset % 1 !== 0 || offset < 0)
|
|
1148
|
+
throw new RangeError("offset is not uint");
|
|
1149
|
+
if (offset + ext > length)
|
|
1150
|
+
throw new RangeError("Trying to access beyond buffer length");
|
|
1151
|
+
}
|
|
1152
|
+
Buffer3.prototype.readUintLE = Buffer3.prototype.readUIntLE = function readUIntLE(offset, byteLength2, noAssert) {
|
|
1153
|
+
offset = offset >>> 0;
|
|
1154
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1155
|
+
if (!noAssert)
|
|
1156
|
+
checkOffset(offset, byteLength2, this.length);
|
|
1157
|
+
let val = this[offset];
|
|
1158
|
+
let mul = 1;
|
|
1159
|
+
let i = 0;
|
|
1160
|
+
while (++i < byteLength2 && (mul *= 256)) {
|
|
1161
|
+
val += this[offset + i] * mul;
|
|
1162
|
+
}
|
|
1163
|
+
return val;
|
|
1164
|
+
};
|
|
1165
|
+
Buffer3.prototype.readUintBE = Buffer3.prototype.readUIntBE = function readUIntBE(offset, byteLength2, noAssert) {
|
|
1166
|
+
offset = offset >>> 0;
|
|
1167
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1168
|
+
if (!noAssert) {
|
|
1169
|
+
checkOffset(offset, byteLength2, this.length);
|
|
1170
|
+
}
|
|
1171
|
+
let val = this[offset + --byteLength2];
|
|
1172
|
+
let mul = 1;
|
|
1173
|
+
while (byteLength2 > 0 && (mul *= 256)) {
|
|
1174
|
+
val += this[offset + --byteLength2] * mul;
|
|
1175
|
+
}
|
|
1176
|
+
return val;
|
|
1177
|
+
};
|
|
1178
|
+
Buffer3.prototype.readUint8 = Buffer3.prototype.readUInt8 = function readUInt8(offset, noAssert) {
|
|
1179
|
+
offset = offset >>> 0;
|
|
1180
|
+
if (!noAssert)
|
|
1181
|
+
checkOffset(offset, 1, this.length);
|
|
1182
|
+
return this[offset];
|
|
1183
|
+
};
|
|
1184
|
+
Buffer3.prototype.readUint16LE = Buffer3.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
|
|
1185
|
+
offset = offset >>> 0;
|
|
1186
|
+
if (!noAssert)
|
|
1187
|
+
checkOffset(offset, 2, this.length);
|
|
1188
|
+
return this[offset] | this[offset + 1] << 8;
|
|
1189
|
+
};
|
|
1190
|
+
Buffer3.prototype.readUint16BE = Buffer3.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
|
|
1191
|
+
offset = offset >>> 0;
|
|
1192
|
+
if (!noAssert)
|
|
1193
|
+
checkOffset(offset, 2, this.length);
|
|
1194
|
+
return this[offset] << 8 | this[offset + 1];
|
|
1195
|
+
};
|
|
1196
|
+
Buffer3.prototype.readUint32LE = Buffer3.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
|
|
1197
|
+
offset = offset >>> 0;
|
|
1198
|
+
if (!noAssert)
|
|
1199
|
+
checkOffset(offset, 4, this.length);
|
|
1200
|
+
return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 16777216;
|
|
1201
|
+
};
|
|
1202
|
+
Buffer3.prototype.readUint32BE = Buffer3.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
|
|
1203
|
+
offset = offset >>> 0;
|
|
1204
|
+
if (!noAssert)
|
|
1205
|
+
checkOffset(offset, 4, this.length);
|
|
1206
|
+
return this[offset] * 16777216 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
|
|
1207
|
+
};
|
|
1208
|
+
Buffer3.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE(offset) {
|
|
1209
|
+
offset = offset >>> 0;
|
|
1210
|
+
validateNumber(offset, "offset");
|
|
1211
|
+
const first = this[offset];
|
|
1212
|
+
const last = this[offset + 7];
|
|
1213
|
+
if (first === void 0 || last === void 0) {
|
|
1214
|
+
boundsError(offset, this.length - 8);
|
|
1215
|
+
}
|
|
1216
|
+
const lo = first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24;
|
|
1217
|
+
const hi = this[++offset] + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + last * 2 ** 24;
|
|
1218
|
+
return BigInt(lo) + (BigInt(hi) << BigInt(32));
|
|
1219
|
+
});
|
|
1220
|
+
Buffer3.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE(offset) {
|
|
1221
|
+
offset = offset >>> 0;
|
|
1222
|
+
validateNumber(offset, "offset");
|
|
1223
|
+
const first = this[offset];
|
|
1224
|
+
const last = this[offset + 7];
|
|
1225
|
+
if (first === void 0 || last === void 0) {
|
|
1226
|
+
boundsError(offset, this.length - 8);
|
|
1227
|
+
}
|
|
1228
|
+
const hi = first * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset];
|
|
1229
|
+
const lo = this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last;
|
|
1230
|
+
return (BigInt(hi) << BigInt(32)) + BigInt(lo);
|
|
1231
|
+
});
|
|
1232
|
+
Buffer3.prototype.readIntLE = function readIntLE(offset, byteLength2, noAssert) {
|
|
1233
|
+
offset = offset >>> 0;
|
|
1234
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1235
|
+
if (!noAssert)
|
|
1236
|
+
checkOffset(offset, byteLength2, this.length);
|
|
1237
|
+
let val = this[offset];
|
|
1238
|
+
let mul = 1;
|
|
1239
|
+
let i = 0;
|
|
1240
|
+
while (++i < byteLength2 && (mul *= 256)) {
|
|
1241
|
+
val += this[offset + i] * mul;
|
|
1242
|
+
}
|
|
1243
|
+
mul *= 128;
|
|
1244
|
+
if (val >= mul)
|
|
1245
|
+
val -= Math.pow(2, 8 * byteLength2);
|
|
1246
|
+
return val;
|
|
1247
|
+
};
|
|
1248
|
+
Buffer3.prototype.readIntBE = function readIntBE(offset, byteLength2, noAssert) {
|
|
1249
|
+
offset = offset >>> 0;
|
|
1250
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1251
|
+
if (!noAssert)
|
|
1252
|
+
checkOffset(offset, byteLength2, this.length);
|
|
1253
|
+
let i = byteLength2;
|
|
1254
|
+
let mul = 1;
|
|
1255
|
+
let val = this[offset + --i];
|
|
1256
|
+
while (i > 0 && (mul *= 256)) {
|
|
1257
|
+
val += this[offset + --i] * mul;
|
|
1258
|
+
}
|
|
1259
|
+
mul *= 128;
|
|
1260
|
+
if (val >= mul)
|
|
1261
|
+
val -= Math.pow(2, 8 * byteLength2);
|
|
1262
|
+
return val;
|
|
1263
|
+
};
|
|
1264
|
+
Buffer3.prototype.readInt8 = function readInt8(offset, noAssert) {
|
|
1265
|
+
offset = offset >>> 0;
|
|
1266
|
+
if (!noAssert)
|
|
1267
|
+
checkOffset(offset, 1, this.length);
|
|
1268
|
+
if (!(this[offset] & 128))
|
|
1269
|
+
return this[offset];
|
|
1270
|
+
return (255 - this[offset] + 1) * -1;
|
|
1271
|
+
};
|
|
1272
|
+
Buffer3.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
|
|
1273
|
+
offset = offset >>> 0;
|
|
1274
|
+
if (!noAssert)
|
|
1275
|
+
checkOffset(offset, 2, this.length);
|
|
1276
|
+
const val = this[offset] | this[offset + 1] << 8;
|
|
1277
|
+
return val & 32768 ? val | 4294901760 : val;
|
|
1278
|
+
};
|
|
1279
|
+
Buffer3.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
|
|
1280
|
+
offset = offset >>> 0;
|
|
1281
|
+
if (!noAssert)
|
|
1282
|
+
checkOffset(offset, 2, this.length);
|
|
1283
|
+
const val = this[offset + 1] | this[offset] << 8;
|
|
1284
|
+
return val & 32768 ? val | 4294901760 : val;
|
|
1285
|
+
};
|
|
1286
|
+
Buffer3.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
|
|
1287
|
+
offset = offset >>> 0;
|
|
1288
|
+
if (!noAssert)
|
|
1289
|
+
checkOffset(offset, 4, this.length);
|
|
1290
|
+
return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
|
|
1291
|
+
};
|
|
1292
|
+
Buffer3.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
|
|
1293
|
+
offset = offset >>> 0;
|
|
1294
|
+
if (!noAssert)
|
|
1295
|
+
checkOffset(offset, 4, this.length);
|
|
1296
|
+
return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
|
|
1297
|
+
};
|
|
1298
|
+
Buffer3.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE(offset) {
|
|
1299
|
+
offset = offset >>> 0;
|
|
1300
|
+
validateNumber(offset, "offset");
|
|
1301
|
+
const first = this[offset];
|
|
1302
|
+
const last = this[offset + 7];
|
|
1303
|
+
if (first === void 0 || last === void 0) {
|
|
1304
|
+
boundsError(offset, this.length - 8);
|
|
1305
|
+
}
|
|
1306
|
+
const val = this[offset + 4] + this[offset + 5] * 2 ** 8 + this[offset + 6] * 2 ** 16 + (last << 24);
|
|
1307
|
+
return (BigInt(val) << BigInt(32)) + BigInt(first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24);
|
|
1308
|
+
});
|
|
1309
|
+
Buffer3.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE(offset) {
|
|
1310
|
+
offset = offset >>> 0;
|
|
1311
|
+
validateNumber(offset, "offset");
|
|
1312
|
+
const first = this[offset];
|
|
1313
|
+
const last = this[offset + 7];
|
|
1314
|
+
if (first === void 0 || last === void 0) {
|
|
1315
|
+
boundsError(offset, this.length - 8);
|
|
1316
|
+
}
|
|
1317
|
+
const val = (first << 24) + // Overflow
|
|
1318
|
+
this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset];
|
|
1319
|
+
return (BigInt(val) << BigInt(32)) + BigInt(this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last);
|
|
1320
|
+
});
|
|
1321
|
+
Buffer3.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
|
|
1322
|
+
offset = offset >>> 0;
|
|
1323
|
+
if (!noAssert)
|
|
1324
|
+
checkOffset(offset, 4, this.length);
|
|
1325
|
+
return ieee754.read(this, offset, true, 23, 4);
|
|
1326
|
+
};
|
|
1327
|
+
Buffer3.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
|
|
1328
|
+
offset = offset >>> 0;
|
|
1329
|
+
if (!noAssert)
|
|
1330
|
+
checkOffset(offset, 4, this.length);
|
|
1331
|
+
return ieee754.read(this, offset, false, 23, 4);
|
|
1332
|
+
};
|
|
1333
|
+
Buffer3.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
|
|
1334
|
+
offset = offset >>> 0;
|
|
1335
|
+
if (!noAssert)
|
|
1336
|
+
checkOffset(offset, 8, this.length);
|
|
1337
|
+
return ieee754.read(this, offset, true, 52, 8);
|
|
1338
|
+
};
|
|
1339
|
+
Buffer3.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
|
|
1340
|
+
offset = offset >>> 0;
|
|
1341
|
+
if (!noAssert)
|
|
1342
|
+
checkOffset(offset, 8, this.length);
|
|
1343
|
+
return ieee754.read(this, offset, false, 52, 8);
|
|
1344
|
+
};
|
|
1345
|
+
function checkInt(buf, value, offset, ext, max, min) {
|
|
1346
|
+
if (!Buffer3.isBuffer(buf))
|
|
1347
|
+
throw new TypeError('"buffer" argument must be a Buffer instance');
|
|
1348
|
+
if (value > max || value < min)
|
|
1349
|
+
throw new RangeError('"value" argument is out of bounds');
|
|
1350
|
+
if (offset + ext > buf.length)
|
|
1351
|
+
throw new RangeError("Index out of range");
|
|
1352
|
+
}
|
|
1353
|
+
Buffer3.prototype.writeUintLE = Buffer3.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength2, noAssert) {
|
|
1354
|
+
value = +value;
|
|
1355
|
+
offset = offset >>> 0;
|
|
1356
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1357
|
+
if (!noAssert) {
|
|
1358
|
+
const maxBytes = Math.pow(2, 8 * byteLength2) - 1;
|
|
1359
|
+
checkInt(this, value, offset, byteLength2, maxBytes, 0);
|
|
1360
|
+
}
|
|
1361
|
+
let mul = 1;
|
|
1362
|
+
let i = 0;
|
|
1363
|
+
this[offset] = value & 255;
|
|
1364
|
+
while (++i < byteLength2 && (mul *= 256)) {
|
|
1365
|
+
this[offset + i] = value / mul & 255;
|
|
1366
|
+
}
|
|
1367
|
+
return offset + byteLength2;
|
|
1368
|
+
};
|
|
1369
|
+
Buffer3.prototype.writeUintBE = Buffer3.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength2, noAssert) {
|
|
1370
|
+
value = +value;
|
|
1371
|
+
offset = offset >>> 0;
|
|
1372
|
+
byteLength2 = byteLength2 >>> 0;
|
|
1373
|
+
if (!noAssert) {
|
|
1374
|
+
const maxBytes = Math.pow(2, 8 * byteLength2) - 1;
|
|
1375
|
+
checkInt(this, value, offset, byteLength2, maxBytes, 0);
|
|
1376
|
+
}
|
|
1377
|
+
let i = byteLength2 - 1;
|
|
1378
|
+
let mul = 1;
|
|
1379
|
+
this[offset + i] = value & 255;
|
|
1380
|
+
while (--i >= 0 && (mul *= 256)) {
|
|
1381
|
+
this[offset + i] = value / mul & 255;
|
|
1382
|
+
}
|
|
1383
|
+
return offset + byteLength2;
|
|
1384
|
+
};
|
|
1385
|
+
Buffer3.prototype.writeUint8 = Buffer3.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
|
|
1386
|
+
value = +value;
|
|
1387
|
+
offset = offset >>> 0;
|
|
1388
|
+
if (!noAssert)
|
|
1389
|
+
checkInt(this, value, offset, 1, 255, 0);
|
|
1390
|
+
this[offset] = value & 255;
|
|
1391
|
+
return offset + 1;
|
|
1392
|
+
};
|
|
1393
|
+
Buffer3.prototype.writeUint16LE = Buffer3.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
|
|
1394
|
+
value = +value;
|
|
1395
|
+
offset = offset >>> 0;
|
|
1396
|
+
if (!noAssert)
|
|
1397
|
+
checkInt(this, value, offset, 2, 65535, 0);
|
|
1398
|
+
this[offset] = value & 255;
|
|
1399
|
+
this[offset + 1] = value >>> 8;
|
|
1400
|
+
return offset + 2;
|
|
1401
|
+
};
|
|
1402
|
+
Buffer3.prototype.writeUint16BE = Buffer3.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
|
|
1403
|
+
value = +value;
|
|
1404
|
+
offset = offset >>> 0;
|
|
1405
|
+
if (!noAssert)
|
|
1406
|
+
checkInt(this, value, offset, 2, 65535, 0);
|
|
1407
|
+
this[offset] = value >>> 8;
|
|
1408
|
+
this[offset + 1] = value & 255;
|
|
1409
|
+
return offset + 2;
|
|
1410
|
+
};
|
|
1411
|
+
Buffer3.prototype.writeUint32LE = Buffer3.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
|
|
1412
|
+
value = +value;
|
|
1413
|
+
offset = offset >>> 0;
|
|
1414
|
+
if (!noAssert)
|
|
1415
|
+
checkInt(this, value, offset, 4, 4294967295, 0);
|
|
1416
|
+
this[offset + 3] = value >>> 24;
|
|
1417
|
+
this[offset + 2] = value >>> 16;
|
|
1418
|
+
this[offset + 1] = value >>> 8;
|
|
1419
|
+
this[offset] = value & 255;
|
|
1420
|
+
return offset + 4;
|
|
1421
|
+
};
|
|
1422
|
+
Buffer3.prototype.writeUint32BE = Buffer3.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
|
|
1423
|
+
value = +value;
|
|
1424
|
+
offset = offset >>> 0;
|
|
1425
|
+
if (!noAssert)
|
|
1426
|
+
checkInt(this, value, offset, 4, 4294967295, 0);
|
|
1427
|
+
this[offset] = value >>> 24;
|
|
1428
|
+
this[offset + 1] = value >>> 16;
|
|
1429
|
+
this[offset + 2] = value >>> 8;
|
|
1430
|
+
this[offset + 3] = value & 255;
|
|
1431
|
+
return offset + 4;
|
|
1432
|
+
};
|
|
1433
|
+
function wrtBigUInt64LE(buf, value, offset, min, max) {
|
|
1434
|
+
checkIntBI(value, min, max, buf, offset, 7);
|
|
1435
|
+
let lo = Number(value & BigInt(4294967295));
|
|
1436
|
+
buf[offset++] = lo;
|
|
1437
|
+
lo = lo >> 8;
|
|
1438
|
+
buf[offset++] = lo;
|
|
1439
|
+
lo = lo >> 8;
|
|
1440
|
+
buf[offset++] = lo;
|
|
1441
|
+
lo = lo >> 8;
|
|
1442
|
+
buf[offset++] = lo;
|
|
1443
|
+
let hi = Number(value >> BigInt(32) & BigInt(4294967295));
|
|
1444
|
+
buf[offset++] = hi;
|
|
1445
|
+
hi = hi >> 8;
|
|
1446
|
+
buf[offset++] = hi;
|
|
1447
|
+
hi = hi >> 8;
|
|
1448
|
+
buf[offset++] = hi;
|
|
1449
|
+
hi = hi >> 8;
|
|
1450
|
+
buf[offset++] = hi;
|
|
1451
|
+
return offset;
|
|
1452
|
+
}
|
|
1453
|
+
function wrtBigUInt64BE(buf, value, offset, min, max) {
|
|
1454
|
+
checkIntBI(value, min, max, buf, offset, 7);
|
|
1455
|
+
let lo = Number(value & BigInt(4294967295));
|
|
1456
|
+
buf[offset + 7] = lo;
|
|
1457
|
+
lo = lo >> 8;
|
|
1458
|
+
buf[offset + 6] = lo;
|
|
1459
|
+
lo = lo >> 8;
|
|
1460
|
+
buf[offset + 5] = lo;
|
|
1461
|
+
lo = lo >> 8;
|
|
1462
|
+
buf[offset + 4] = lo;
|
|
1463
|
+
let hi = Number(value >> BigInt(32) & BigInt(4294967295));
|
|
1464
|
+
buf[offset + 3] = hi;
|
|
1465
|
+
hi = hi >> 8;
|
|
1466
|
+
buf[offset + 2] = hi;
|
|
1467
|
+
hi = hi >> 8;
|
|
1468
|
+
buf[offset + 1] = hi;
|
|
1469
|
+
hi = hi >> 8;
|
|
1470
|
+
buf[offset] = hi;
|
|
1471
|
+
return offset + 8;
|
|
1472
|
+
}
|
|
1473
|
+
Buffer3.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE(value, offset = 0) {
|
|
1474
|
+
return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
1475
|
+
});
|
|
1476
|
+
Buffer3.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE(value, offset = 0) {
|
|
1477
|
+
return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff"));
|
|
1478
|
+
});
|
|
1479
|
+
Buffer3.prototype.writeIntLE = function writeIntLE(value, offset, byteLength2, noAssert) {
|
|
1480
|
+
value = +value;
|
|
1481
|
+
offset = offset >>> 0;
|
|
1482
|
+
if (!noAssert) {
|
|
1483
|
+
const limit = Math.pow(2, 8 * byteLength2 - 1);
|
|
1484
|
+
checkInt(this, value, offset, byteLength2, limit - 1, -limit);
|
|
1485
|
+
}
|
|
1486
|
+
let i = 0;
|
|
1487
|
+
let mul = 1;
|
|
1488
|
+
let sub = 0;
|
|
1489
|
+
this[offset] = value & 255;
|
|
1490
|
+
while (++i < byteLength2 && (mul *= 256)) {
|
|
1491
|
+
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
|
1492
|
+
sub = 1;
|
|
1493
|
+
}
|
|
1494
|
+
this[offset + i] = (value / mul >> 0) - sub & 255;
|
|
1495
|
+
}
|
|
1496
|
+
return offset + byteLength2;
|
|
1497
|
+
};
|
|
1498
|
+
Buffer3.prototype.writeIntBE = function writeIntBE(value, offset, byteLength2, noAssert) {
|
|
1499
|
+
value = +value;
|
|
1500
|
+
offset = offset >>> 0;
|
|
1501
|
+
if (!noAssert) {
|
|
1502
|
+
const limit = Math.pow(2, 8 * byteLength2 - 1);
|
|
1503
|
+
checkInt(this, value, offset, byteLength2, limit - 1, -limit);
|
|
1504
|
+
}
|
|
1505
|
+
let i = byteLength2 - 1;
|
|
1506
|
+
let mul = 1;
|
|
1507
|
+
let sub = 0;
|
|
1508
|
+
this[offset + i] = value & 255;
|
|
1509
|
+
while (--i >= 0 && (mul *= 256)) {
|
|
1510
|
+
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
|
1511
|
+
sub = 1;
|
|
1512
|
+
}
|
|
1513
|
+
this[offset + i] = (value / mul >> 0) - sub & 255;
|
|
1514
|
+
}
|
|
1515
|
+
return offset + byteLength2;
|
|
1516
|
+
};
|
|
1517
|
+
Buffer3.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
|
|
1518
|
+
value = +value;
|
|
1519
|
+
offset = offset >>> 0;
|
|
1520
|
+
if (!noAssert)
|
|
1521
|
+
checkInt(this, value, offset, 1, 127, -128);
|
|
1522
|
+
if (value < 0)
|
|
1523
|
+
value = 255 + value + 1;
|
|
1524
|
+
this[offset] = value & 255;
|
|
1525
|
+
return offset + 1;
|
|
1526
|
+
};
|
|
1527
|
+
Buffer3.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
|
|
1528
|
+
value = +value;
|
|
1529
|
+
offset = offset >>> 0;
|
|
1530
|
+
if (!noAssert)
|
|
1531
|
+
checkInt(this, value, offset, 2, 32767, -32768);
|
|
1532
|
+
this[offset] = value & 255;
|
|
1533
|
+
this[offset + 1] = value >>> 8;
|
|
1534
|
+
return offset + 2;
|
|
1535
|
+
};
|
|
1536
|
+
Buffer3.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
|
|
1537
|
+
value = +value;
|
|
1538
|
+
offset = offset >>> 0;
|
|
1539
|
+
if (!noAssert)
|
|
1540
|
+
checkInt(this, value, offset, 2, 32767, -32768);
|
|
1541
|
+
this[offset] = value >>> 8;
|
|
1542
|
+
this[offset + 1] = value & 255;
|
|
1543
|
+
return offset + 2;
|
|
1544
|
+
};
|
|
1545
|
+
Buffer3.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
|
|
1546
|
+
value = +value;
|
|
1547
|
+
offset = offset >>> 0;
|
|
1548
|
+
if (!noAssert)
|
|
1549
|
+
checkInt(this, value, offset, 4, 2147483647, -2147483648);
|
|
1550
|
+
this[offset] = value & 255;
|
|
1551
|
+
this[offset + 1] = value >>> 8;
|
|
1552
|
+
this[offset + 2] = value >>> 16;
|
|
1553
|
+
this[offset + 3] = value >>> 24;
|
|
1554
|
+
return offset + 4;
|
|
1555
|
+
};
|
|
1556
|
+
Buffer3.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
|
|
1557
|
+
value = +value;
|
|
1558
|
+
offset = offset >>> 0;
|
|
1559
|
+
if (!noAssert)
|
|
1560
|
+
checkInt(this, value, offset, 4, 2147483647, -2147483648);
|
|
1561
|
+
if (value < 0)
|
|
1562
|
+
value = 4294967295 + value + 1;
|
|
1563
|
+
this[offset] = value >>> 24;
|
|
1564
|
+
this[offset + 1] = value >>> 16;
|
|
1565
|
+
this[offset + 2] = value >>> 8;
|
|
1566
|
+
this[offset + 3] = value & 255;
|
|
1567
|
+
return offset + 4;
|
|
1568
|
+
};
|
|
1569
|
+
Buffer3.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE(value, offset = 0) {
|
|
1570
|
+
return wrtBigUInt64LE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
1571
|
+
});
|
|
1572
|
+
Buffer3.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE(value, offset = 0) {
|
|
1573
|
+
return wrtBigUInt64BE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
1574
|
+
});
|
|
1575
|
+
function checkIEEE754(buf, value, offset, ext, max, min) {
|
|
1576
|
+
if (offset + ext > buf.length)
|
|
1577
|
+
throw new RangeError("Index out of range");
|
|
1578
|
+
if (offset < 0)
|
|
1579
|
+
throw new RangeError("Index out of range");
|
|
1580
|
+
}
|
|
1581
|
+
function writeFloat(buf, value, offset, littleEndian, noAssert) {
|
|
1582
|
+
value = +value;
|
|
1583
|
+
offset = offset >>> 0;
|
|
1584
|
+
if (!noAssert) {
|
|
1585
|
+
checkIEEE754(buf, value, offset, 4);
|
|
1586
|
+
}
|
|
1587
|
+
ieee754.write(buf, value, offset, littleEndian, 23, 4);
|
|
1588
|
+
return offset + 4;
|
|
1589
|
+
}
|
|
1590
|
+
Buffer3.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
|
|
1591
|
+
return writeFloat(this, value, offset, true, noAssert);
|
|
1592
|
+
};
|
|
1593
|
+
Buffer3.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
|
|
1594
|
+
return writeFloat(this, value, offset, false, noAssert);
|
|
1595
|
+
};
|
|
1596
|
+
function writeDouble(buf, value, offset, littleEndian, noAssert) {
|
|
1597
|
+
value = +value;
|
|
1598
|
+
offset = offset >>> 0;
|
|
1599
|
+
if (!noAssert) {
|
|
1600
|
+
checkIEEE754(buf, value, offset, 8);
|
|
1601
|
+
}
|
|
1602
|
+
ieee754.write(buf, value, offset, littleEndian, 52, 8);
|
|
1603
|
+
return offset + 8;
|
|
1604
|
+
}
|
|
1605
|
+
Buffer3.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
|
|
1606
|
+
return writeDouble(this, value, offset, true, noAssert);
|
|
1607
|
+
};
|
|
1608
|
+
Buffer3.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
|
|
1609
|
+
return writeDouble(this, value, offset, false, noAssert);
|
|
1610
|
+
};
|
|
1611
|
+
Buffer3.prototype.copy = function copy(target, targetStart, start, end) {
|
|
1612
|
+
if (!Buffer3.isBuffer(target))
|
|
1613
|
+
throw new TypeError("argument should be a Buffer");
|
|
1614
|
+
if (!start)
|
|
1615
|
+
start = 0;
|
|
1616
|
+
if (!end && end !== 0)
|
|
1617
|
+
end = this.length;
|
|
1618
|
+
if (targetStart >= target.length)
|
|
1619
|
+
targetStart = target.length;
|
|
1620
|
+
if (!targetStart)
|
|
1621
|
+
targetStart = 0;
|
|
1622
|
+
if (end > 0 && end < start)
|
|
1623
|
+
end = start;
|
|
1624
|
+
if (end === start)
|
|
1625
|
+
return 0;
|
|
1626
|
+
if (target.length === 0 || this.length === 0)
|
|
1627
|
+
return 0;
|
|
1628
|
+
if (targetStart < 0) {
|
|
1629
|
+
throw new RangeError("targetStart out of bounds");
|
|
1630
|
+
}
|
|
1631
|
+
if (start < 0 || start >= this.length)
|
|
1632
|
+
throw new RangeError("Index out of range");
|
|
1633
|
+
if (end < 0)
|
|
1634
|
+
throw new RangeError("sourceEnd out of bounds");
|
|
1635
|
+
if (end > this.length)
|
|
1636
|
+
end = this.length;
|
|
1637
|
+
if (target.length - targetStart < end - start) {
|
|
1638
|
+
end = target.length - targetStart + start;
|
|
1639
|
+
}
|
|
1640
|
+
const len = end - start;
|
|
1641
|
+
if (this === target && typeof Uint8Array.prototype.copyWithin === "function") {
|
|
1642
|
+
this.copyWithin(targetStart, start, end);
|
|
1643
|
+
} else {
|
|
1644
|
+
Uint8Array.prototype.set.call(target, this.subarray(start, end), targetStart);
|
|
1645
|
+
}
|
|
1646
|
+
return len;
|
|
1647
|
+
};
|
|
1648
|
+
Buffer3.prototype.fill = function fill(val, start, end, encoding) {
|
|
1649
|
+
if (typeof val === "string") {
|
|
1650
|
+
if (typeof start === "string") {
|
|
1651
|
+
encoding = start;
|
|
1652
|
+
start = 0;
|
|
1653
|
+
end = this.length;
|
|
1654
|
+
} else if (typeof end === "string") {
|
|
1655
|
+
encoding = end;
|
|
1656
|
+
end = this.length;
|
|
1657
|
+
}
|
|
1658
|
+
if (encoding !== void 0 && typeof encoding !== "string") {
|
|
1659
|
+
throw new TypeError("encoding must be a string");
|
|
1660
|
+
}
|
|
1661
|
+
if (typeof encoding === "string" && !Buffer3.isEncoding(encoding)) {
|
|
1662
|
+
throw new TypeError("Unknown encoding: " + encoding);
|
|
1663
|
+
}
|
|
1664
|
+
if (val.length === 1) {
|
|
1665
|
+
const code = val.charCodeAt(0);
|
|
1666
|
+
if (encoding === "utf8" && code < 128 || encoding === "latin1") {
|
|
1667
|
+
val = code;
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
} else if (typeof val === "number") {
|
|
1671
|
+
val = val & 255;
|
|
1672
|
+
} else if (typeof val === "boolean") {
|
|
1673
|
+
val = Number(val);
|
|
1674
|
+
}
|
|
1675
|
+
if (start < 0 || this.length < start || this.length < end) {
|
|
1676
|
+
throw new RangeError("Out of range index");
|
|
1677
|
+
}
|
|
1678
|
+
if (end <= start) {
|
|
1679
|
+
return this;
|
|
1680
|
+
}
|
|
1681
|
+
start = start >>> 0;
|
|
1682
|
+
end = end === void 0 ? this.length : end >>> 0;
|
|
1683
|
+
if (!val)
|
|
1684
|
+
val = 0;
|
|
1685
|
+
let i;
|
|
1686
|
+
if (typeof val === "number") {
|
|
1687
|
+
for (i = start; i < end; ++i) {
|
|
1688
|
+
this[i] = val;
|
|
1689
|
+
}
|
|
1690
|
+
} else {
|
|
1691
|
+
const bytes = Buffer3.isBuffer(val) ? val : Buffer3.from(val, encoding);
|
|
1692
|
+
const len = bytes.length;
|
|
1693
|
+
if (len === 0) {
|
|
1694
|
+
throw new TypeError('The value "' + val + '" is invalid for argument "value"');
|
|
1695
|
+
}
|
|
1696
|
+
for (i = 0; i < end - start; ++i) {
|
|
1697
|
+
this[i + start] = bytes[i % len];
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
return this;
|
|
1701
|
+
};
|
|
1702
|
+
const errors = {};
|
|
1703
|
+
function E(sym, getMessage, Base) {
|
|
1704
|
+
errors[sym] = class NodeError extends Base {
|
|
1705
|
+
constructor() {
|
|
1706
|
+
super();
|
|
1707
|
+
Object.defineProperty(this, "message", {
|
|
1708
|
+
value: getMessage.apply(this, arguments),
|
|
1709
|
+
writable: true,
|
|
1710
|
+
configurable: true
|
|
1711
|
+
});
|
|
1712
|
+
this.name = `${this.name} [${sym}]`;
|
|
1713
|
+
this.stack;
|
|
1714
|
+
delete this.name;
|
|
1715
|
+
}
|
|
1716
|
+
get code() {
|
|
1717
|
+
return sym;
|
|
1718
|
+
}
|
|
1719
|
+
set code(value) {
|
|
1720
|
+
Object.defineProperty(this, "code", {
|
|
1721
|
+
configurable: true,
|
|
1722
|
+
enumerable: true,
|
|
1723
|
+
value,
|
|
1724
|
+
writable: true
|
|
1725
|
+
});
|
|
1726
|
+
}
|
|
1727
|
+
toString() {
|
|
1728
|
+
return `${this.name} [${sym}]: ${this.message}`;
|
|
1729
|
+
}
|
|
1730
|
+
};
|
|
1731
|
+
}
|
|
1732
|
+
E("ERR_BUFFER_OUT_OF_BOUNDS", function(name) {
|
|
1733
|
+
if (name) {
|
|
1734
|
+
return `${name} is outside of buffer bounds`;
|
|
1735
|
+
}
|
|
1736
|
+
return "Attempt to access memory outside buffer bounds";
|
|
1737
|
+
}, RangeError);
|
|
1738
|
+
E("ERR_INVALID_ARG_TYPE", function(name, actual) {
|
|
1739
|
+
return `The "${name}" argument must be of type number. Received type ${typeof actual}`;
|
|
1740
|
+
}, TypeError);
|
|
1741
|
+
E("ERR_OUT_OF_RANGE", function(str2, range, input) {
|
|
1742
|
+
let msg = `The value of "${str2}" is out of range.`;
|
|
1743
|
+
let received = input;
|
|
1744
|
+
if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
|
|
1745
|
+
received = addNumericalSeparator(String(input));
|
|
1746
|
+
} else if (typeof input === "bigint") {
|
|
1747
|
+
received = String(input);
|
|
1748
|
+
if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
|
|
1749
|
+
received = addNumericalSeparator(received);
|
|
1750
|
+
}
|
|
1751
|
+
received += "n";
|
|
1752
|
+
}
|
|
1753
|
+
msg += ` It must be ${range}. Received ${received}`;
|
|
1754
|
+
return msg;
|
|
1755
|
+
}, RangeError);
|
|
1756
|
+
function addNumericalSeparator(val) {
|
|
1757
|
+
let res = "";
|
|
1758
|
+
let i = val.length;
|
|
1759
|
+
const start = val[0] === "-" ? 1 : 0;
|
|
1760
|
+
for (; i >= start + 4; i -= 3) {
|
|
1761
|
+
res = `_${val.slice(i - 3, i)}${res}`;
|
|
1762
|
+
}
|
|
1763
|
+
return `${val.slice(0, i)}${res}`;
|
|
1764
|
+
}
|
|
1765
|
+
function checkBounds(buf, offset, byteLength2) {
|
|
1766
|
+
validateNumber(offset, "offset");
|
|
1767
|
+
if (buf[offset] === void 0 || buf[offset + byteLength2] === void 0) {
|
|
1768
|
+
boundsError(offset, buf.length - (byteLength2 + 1));
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
function checkIntBI(value, min, max, buf, offset, byteLength2) {
|
|
1772
|
+
if (value > max || value < min) {
|
|
1773
|
+
const n = typeof min === "bigint" ? "n" : "";
|
|
1774
|
+
let range;
|
|
1775
|
+
if (byteLength2 > 3) {
|
|
1776
|
+
if (min === 0 || min === BigInt(0)) {
|
|
1777
|
+
range = `>= 0${n} and < 2${n} ** ${(byteLength2 + 1) * 8}${n}`;
|
|
1778
|
+
} else {
|
|
1779
|
+
range = `>= -(2${n} ** ${(byteLength2 + 1) * 8 - 1}${n}) and < 2 ** ${(byteLength2 + 1) * 8 - 1}${n}`;
|
|
1780
|
+
}
|
|
1781
|
+
} else {
|
|
1782
|
+
range = `>= ${min}${n} and <= ${max}${n}`;
|
|
1783
|
+
}
|
|
1784
|
+
throw new errors.ERR_OUT_OF_RANGE("value", range, value);
|
|
1785
|
+
}
|
|
1786
|
+
checkBounds(buf, offset, byteLength2);
|
|
1787
|
+
}
|
|
1788
|
+
function validateNumber(value, name) {
|
|
1789
|
+
if (typeof value !== "number") {
|
|
1790
|
+
throw new errors.ERR_INVALID_ARG_TYPE(name, "number", value);
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
function boundsError(value, length, type) {
|
|
1794
|
+
if (Math.floor(value) !== value) {
|
|
1795
|
+
validateNumber(value, type);
|
|
1796
|
+
throw new errors.ERR_OUT_OF_RANGE(type || "offset", "an integer", value);
|
|
1797
|
+
}
|
|
1798
|
+
if (length < 0) {
|
|
1799
|
+
throw new errors.ERR_BUFFER_OUT_OF_BOUNDS();
|
|
1800
|
+
}
|
|
1801
|
+
throw new errors.ERR_OUT_OF_RANGE(type || "offset", `>= ${type ? 1 : 0} and <= ${length}`, value);
|
|
1802
|
+
}
|
|
1803
|
+
const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
|
|
1804
|
+
function base64clean(str2) {
|
|
1805
|
+
str2 = str2.split("=")[0];
|
|
1806
|
+
str2 = str2.trim().replace(INVALID_BASE64_RE, "");
|
|
1807
|
+
if (str2.length < 2)
|
|
1808
|
+
return "";
|
|
1809
|
+
while (str2.length % 4 !== 0) {
|
|
1810
|
+
str2 = str2 + "=";
|
|
1811
|
+
}
|
|
1812
|
+
return str2;
|
|
1813
|
+
}
|
|
1814
|
+
function utf8ToBytes(string, units) {
|
|
1815
|
+
units = units || Infinity;
|
|
1816
|
+
let codePoint;
|
|
1817
|
+
const length = string.length;
|
|
1818
|
+
let leadSurrogate = null;
|
|
1819
|
+
const bytes = [];
|
|
1820
|
+
for (let i = 0; i < length; ++i) {
|
|
1821
|
+
codePoint = string.charCodeAt(i);
|
|
1822
|
+
if (codePoint > 55295 && codePoint < 57344) {
|
|
1823
|
+
if (!leadSurrogate) {
|
|
1824
|
+
if (codePoint > 56319) {
|
|
1825
|
+
if ((units -= 3) > -1)
|
|
1826
|
+
bytes.push(239, 191, 189);
|
|
1827
|
+
continue;
|
|
1828
|
+
} else if (i + 1 === length) {
|
|
1829
|
+
if ((units -= 3) > -1)
|
|
1830
|
+
bytes.push(239, 191, 189);
|
|
1831
|
+
continue;
|
|
1832
|
+
}
|
|
1833
|
+
leadSurrogate = codePoint;
|
|
1834
|
+
continue;
|
|
1835
|
+
}
|
|
1836
|
+
if (codePoint < 56320) {
|
|
1837
|
+
if ((units -= 3) > -1)
|
|
1838
|
+
bytes.push(239, 191, 189);
|
|
1839
|
+
leadSurrogate = codePoint;
|
|
1840
|
+
continue;
|
|
1841
|
+
}
|
|
1842
|
+
codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536;
|
|
1843
|
+
} else if (leadSurrogate) {
|
|
1844
|
+
if ((units -= 3) > -1)
|
|
1845
|
+
bytes.push(239, 191, 189);
|
|
1846
|
+
}
|
|
1847
|
+
leadSurrogate = null;
|
|
1848
|
+
if (codePoint < 128) {
|
|
1849
|
+
if ((units -= 1) < 0)
|
|
1850
|
+
break;
|
|
1851
|
+
bytes.push(codePoint);
|
|
1852
|
+
} else if (codePoint < 2048) {
|
|
1853
|
+
if ((units -= 2) < 0)
|
|
1854
|
+
break;
|
|
1855
|
+
bytes.push(codePoint >> 6 | 192, codePoint & 63 | 128);
|
|
1856
|
+
} else if (codePoint < 65536) {
|
|
1857
|
+
if ((units -= 3) < 0)
|
|
1858
|
+
break;
|
|
1859
|
+
bytes.push(codePoint >> 12 | 224, codePoint >> 6 & 63 | 128, codePoint & 63 | 128);
|
|
1860
|
+
} else if (codePoint < 1114112) {
|
|
1861
|
+
if ((units -= 4) < 0)
|
|
1862
|
+
break;
|
|
1863
|
+
bytes.push(codePoint >> 18 | 240, codePoint >> 12 & 63 | 128, codePoint >> 6 & 63 | 128, codePoint & 63 | 128);
|
|
1864
|
+
} else {
|
|
1865
|
+
throw new Error("Invalid code point");
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
return bytes;
|
|
1869
|
+
}
|
|
1870
|
+
function asciiToBytes(str2) {
|
|
1871
|
+
const byteArray = [];
|
|
1872
|
+
for (let i = 0; i < str2.length; ++i) {
|
|
1873
|
+
byteArray.push(str2.charCodeAt(i) & 255);
|
|
1874
|
+
}
|
|
1875
|
+
return byteArray;
|
|
1876
|
+
}
|
|
1877
|
+
function utf16leToBytes(str2, units) {
|
|
1878
|
+
let c, hi, lo;
|
|
1879
|
+
const byteArray = [];
|
|
1880
|
+
for (let i = 0; i < str2.length; ++i) {
|
|
1881
|
+
if ((units -= 2) < 0)
|
|
1882
|
+
break;
|
|
1883
|
+
c = str2.charCodeAt(i);
|
|
1884
|
+
hi = c >> 8;
|
|
1885
|
+
lo = c % 256;
|
|
1886
|
+
byteArray.push(lo);
|
|
1887
|
+
byteArray.push(hi);
|
|
1888
|
+
}
|
|
1889
|
+
return byteArray;
|
|
1890
|
+
}
|
|
1891
|
+
function base64ToBytes(str2) {
|
|
1892
|
+
return base64.toByteArray(base64clean(str2));
|
|
1893
|
+
}
|
|
1894
|
+
function blitBuffer(src, dst, offset, length) {
|
|
1895
|
+
let i;
|
|
1896
|
+
for (i = 0; i < length; ++i) {
|
|
1897
|
+
if (i + offset >= dst.length || i >= src.length)
|
|
1898
|
+
break;
|
|
1899
|
+
dst[i + offset] = src[i];
|
|
1900
|
+
}
|
|
1901
|
+
return i;
|
|
1902
|
+
}
|
|
1903
|
+
function isInstance(obj, type) {
|
|
1904
|
+
return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name;
|
|
1905
|
+
}
|
|
1906
|
+
function numberIsNaN(obj) {
|
|
1907
|
+
return obj !== obj;
|
|
1908
|
+
}
|
|
1909
|
+
const hexSliceLookupTable = function() {
|
|
1910
|
+
const alphabet = "0123456789abcdef";
|
|
1911
|
+
const table = new Array(256);
|
|
1912
|
+
for (let i = 0; i < 16; ++i) {
|
|
1913
|
+
const i16 = i * 16;
|
|
1914
|
+
for (let j = 0; j < 16; ++j) {
|
|
1915
|
+
table[i16 + j] = alphabet[i] + alphabet[j];
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
return table;
|
|
1919
|
+
}();
|
|
1920
|
+
function defineBigIntMethod(fn) {
|
|
1921
|
+
return typeof BigInt === "undefined" ? BufferBigIntNotDefined : fn;
|
|
1922
|
+
}
|
|
1923
|
+
function BufferBigIntNotDefined() {
|
|
1924
|
+
throw new Error("BigInt not supported");
|
|
1925
|
+
}
|
|
1926
|
+
return exports$1;
|
|
1927
|
+
}
|
|
1928
|
+
var exports$3, _dewExec$2, exports$2, _dewExec$1, exports$1, _dewExec, exports, Buffer2, INSPECT_MAX_BYTES, kMaxLength;
|
|
1929
|
+
var init_buffer = __esm({
|
|
1930
|
+
"../../node_modules/.pnpm/@jspm+core@2.0.1/node_modules/@jspm/core/nodelibs/browser/buffer.js"() {
|
|
1931
|
+
"use strict";
|
|
1932
|
+
init_dirname();
|
|
1933
|
+
init_buffer2();
|
|
1934
|
+
init_process2();
|
|
1935
|
+
exports$3 = {};
|
|
1936
|
+
_dewExec$2 = false;
|
|
1937
|
+
exports$2 = {};
|
|
1938
|
+
_dewExec$1 = false;
|
|
1939
|
+
exports$1 = {};
|
|
1940
|
+
_dewExec = false;
|
|
1941
|
+
exports = dew();
|
|
1942
|
+
exports["Buffer"];
|
|
1943
|
+
exports["SlowBuffer"];
|
|
1944
|
+
exports["INSPECT_MAX_BYTES"];
|
|
1945
|
+
exports["kMaxLength"];
|
|
1946
|
+
Buffer2 = exports.Buffer;
|
|
1947
|
+
INSPECT_MAX_BYTES = exports.INSPECT_MAX_BYTES;
|
|
1948
|
+
kMaxLength = exports.kMaxLength;
|
|
1949
|
+
}
|
|
1950
|
+
});
|
|
1951
|
+
|
|
1952
|
+
// ../../node_modules/.pnpm/esbuild-plugin-polyfill-node@0.3.0_esbuild@0.19.2/node_modules/esbuild-plugin-polyfill-node/polyfills/buffer.js
|
|
1953
|
+
var init_buffer2 = __esm({
|
|
1954
|
+
"../../node_modules/.pnpm/esbuild-plugin-polyfill-node@0.3.0_esbuild@0.19.2/node_modules/esbuild-plugin-polyfill-node/polyfills/buffer.js"() {
|
|
1955
|
+
"use strict";
|
|
1956
|
+
init_buffer();
|
|
1957
|
+
}
|
|
1958
|
+
});
|
|
1959
|
+
|
|
1960
|
+
// ../../node_modules/.pnpm/base-x@4.0.0/node_modules/base-x/src/index.js
|
|
1961
|
+
var require_src = __commonJS({
|
|
1962
|
+
"../../node_modules/.pnpm/base-x@4.0.0/node_modules/base-x/src/index.js"(exports2, module2) {
|
|
1963
|
+
"use strict";
|
|
1964
|
+
init_dirname();
|
|
1965
|
+
init_buffer2();
|
|
1966
|
+
init_process2();
|
|
1967
|
+
function base(ALPHABET) {
|
|
1968
|
+
if (ALPHABET.length >= 255) {
|
|
1969
|
+
throw new TypeError("Alphabet too long");
|
|
1970
|
+
}
|
|
1971
|
+
var BASE_MAP = new Uint8Array(256);
|
|
1972
|
+
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
1973
|
+
BASE_MAP[j] = 255;
|
|
1974
|
+
}
|
|
1975
|
+
for (var i = 0; i < ALPHABET.length; i++) {
|
|
1976
|
+
var x = ALPHABET.charAt(i);
|
|
1977
|
+
var xc = x.charCodeAt(0);
|
|
1978
|
+
if (BASE_MAP[xc] !== 255) {
|
|
1979
|
+
throw new TypeError(x + " is ambiguous");
|
|
1980
|
+
}
|
|
1981
|
+
BASE_MAP[xc] = i;
|
|
1982
|
+
}
|
|
1983
|
+
var BASE = ALPHABET.length;
|
|
1984
|
+
var LEADER = ALPHABET.charAt(0);
|
|
1985
|
+
var FACTOR = Math.log(BASE) / Math.log(256);
|
|
1986
|
+
var iFACTOR = Math.log(256) / Math.log(BASE);
|
|
1987
|
+
function encode(source) {
|
|
1988
|
+
if (source instanceof Uint8Array) {
|
|
1989
|
+
} else if (ArrayBuffer.isView(source)) {
|
|
1990
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
1991
|
+
} else if (Array.isArray(source)) {
|
|
1992
|
+
source = Uint8Array.from(source);
|
|
1993
|
+
}
|
|
1994
|
+
if (!(source instanceof Uint8Array)) {
|
|
1995
|
+
throw new TypeError("Expected Uint8Array");
|
|
1996
|
+
}
|
|
1997
|
+
if (source.length === 0) {
|
|
1998
|
+
return "";
|
|
1999
|
+
}
|
|
2000
|
+
var zeroes = 0;
|
|
2001
|
+
var length = 0;
|
|
2002
|
+
var pbegin = 0;
|
|
2003
|
+
var pend = source.length;
|
|
2004
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
2005
|
+
pbegin++;
|
|
2006
|
+
zeroes++;
|
|
2007
|
+
}
|
|
2008
|
+
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
2009
|
+
var b58 = new Uint8Array(size);
|
|
2010
|
+
while (pbegin !== pend) {
|
|
2011
|
+
var carry = source[pbegin];
|
|
2012
|
+
var i2 = 0;
|
|
2013
|
+
for (var it1 = size - 1; (carry !== 0 || i2 < length) && it1 !== -1; it1--, i2++) {
|
|
2014
|
+
carry += 256 * b58[it1] >>> 0;
|
|
2015
|
+
b58[it1] = carry % BASE >>> 0;
|
|
2016
|
+
carry = carry / BASE >>> 0;
|
|
2017
|
+
}
|
|
2018
|
+
if (carry !== 0) {
|
|
2019
|
+
throw new Error("Non-zero carry");
|
|
2020
|
+
}
|
|
2021
|
+
length = i2;
|
|
2022
|
+
pbegin++;
|
|
2023
|
+
}
|
|
2024
|
+
var it2 = size - length;
|
|
2025
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
2026
|
+
it2++;
|
|
2027
|
+
}
|
|
2028
|
+
var str2 = LEADER.repeat(zeroes);
|
|
2029
|
+
for (; it2 < size; ++it2) {
|
|
2030
|
+
str2 += ALPHABET.charAt(b58[it2]);
|
|
2031
|
+
}
|
|
2032
|
+
return str2;
|
|
2033
|
+
}
|
|
2034
|
+
function decodeUnsafe(source) {
|
|
2035
|
+
if (typeof source !== "string") {
|
|
2036
|
+
throw new TypeError("Expected String");
|
|
2037
|
+
}
|
|
2038
|
+
if (source.length === 0) {
|
|
2039
|
+
return new Uint8Array();
|
|
2040
|
+
}
|
|
2041
|
+
var psz = 0;
|
|
2042
|
+
var zeroes = 0;
|
|
2043
|
+
var length = 0;
|
|
2044
|
+
while (source[psz] === LEADER) {
|
|
2045
|
+
zeroes++;
|
|
2046
|
+
psz++;
|
|
2047
|
+
}
|
|
2048
|
+
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
2049
|
+
var b256 = new Uint8Array(size);
|
|
2050
|
+
while (source[psz]) {
|
|
2051
|
+
var carry = BASE_MAP[source.charCodeAt(psz)];
|
|
2052
|
+
if (carry === 255) {
|
|
2053
|
+
return;
|
|
2054
|
+
}
|
|
2055
|
+
var i2 = 0;
|
|
2056
|
+
for (var it3 = size - 1; (carry !== 0 || i2 < length) && it3 !== -1; it3--, i2++) {
|
|
2057
|
+
carry += BASE * b256[it3] >>> 0;
|
|
2058
|
+
b256[it3] = carry % 256 >>> 0;
|
|
2059
|
+
carry = carry / 256 >>> 0;
|
|
2060
|
+
}
|
|
2061
|
+
if (carry !== 0) {
|
|
2062
|
+
throw new Error("Non-zero carry");
|
|
2063
|
+
}
|
|
2064
|
+
length = i2;
|
|
2065
|
+
psz++;
|
|
2066
|
+
}
|
|
2067
|
+
var it4 = size - length;
|
|
2068
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
2069
|
+
it4++;
|
|
2070
|
+
}
|
|
2071
|
+
var vch = new Uint8Array(zeroes + (size - it4));
|
|
2072
|
+
var j2 = zeroes;
|
|
2073
|
+
while (it4 !== size) {
|
|
2074
|
+
vch[j2++] = b256[it4++];
|
|
2075
|
+
}
|
|
2076
|
+
return vch;
|
|
2077
|
+
}
|
|
2078
|
+
function decode(string) {
|
|
2079
|
+
var buffer = decodeUnsafe(string);
|
|
2080
|
+
if (buffer) {
|
|
2081
|
+
return buffer;
|
|
2082
|
+
}
|
|
2083
|
+
throw new Error("Non-base" + BASE + " character");
|
|
2084
|
+
}
|
|
2085
|
+
return {
|
|
2086
|
+
encode,
|
|
2087
|
+
decodeUnsafe,
|
|
2088
|
+
decode
|
|
2089
|
+
};
|
|
2090
|
+
}
|
|
2091
|
+
module2.exports = base;
|
|
2092
|
+
}
|
|
2093
|
+
});
|
|
2094
|
+
|
|
2095
|
+
// ../../node_modules/.pnpm/bs58@5.0.0/node_modules/bs58/index.js
|
|
2096
|
+
var require_bs58 = __commonJS({
|
|
2097
|
+
"../../node_modules/.pnpm/bs58@5.0.0/node_modules/bs58/index.js"(exports2, module2) {
|
|
2098
|
+
"use strict";
|
|
2099
|
+
init_dirname();
|
|
2100
|
+
init_buffer2();
|
|
2101
|
+
init_process2();
|
|
2102
|
+
var basex = require_src();
|
|
2103
|
+
var ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
2104
|
+
module2.exports = basex(ALPHABET);
|
|
2105
|
+
}
|
|
2106
|
+
});
|
|
2107
|
+
|
|
2108
|
+
// src/index.ts
|
|
2109
|
+
var src_exports = {};
|
|
2110
|
+
__export(src_exports, {
|
|
2111
|
+
Account: () => Account,
|
|
2112
|
+
BaseConfigStore: () => BaseConfigStore,
|
|
2113
|
+
BaseContractManager: () => BaseContract,
|
|
2114
|
+
BaseKeyStore: () => BaseKeyStore,
|
|
2115
|
+
BaseOrderlyKeyPair: () => BaseOrderlyKeyPair,
|
|
2116
|
+
BaseSigner: () => BaseSigner,
|
|
2117
|
+
EtherAdapter: () => EtherAdapter,
|
|
2118
|
+
EventEmitter: () => import_eventemitter32.default,
|
|
2119
|
+
LocalStorageStore: () => LocalStorageStore,
|
|
2120
|
+
MemoryConfigStore: () => MemoryConfigStore,
|
|
2121
|
+
MockKeyStore: () => MockKeyStore,
|
|
2122
|
+
SimpleDI: () => simpleDI_default,
|
|
2123
|
+
getDefaultSigner: () => getDefaultSigner,
|
|
2124
|
+
getMockSigner: () => getMockSigner
|
|
2125
|
+
});
|
|
2126
|
+
module.exports = __toCommonJS(src_exports);
|
|
2127
|
+
init_dirname();
|
|
2128
|
+
init_buffer2();
|
|
2129
|
+
init_process2();
|
|
2130
|
+
|
|
2131
|
+
// src/keyStore.ts
|
|
2132
|
+
init_dirname();
|
|
2133
|
+
init_buffer2();
|
|
2134
|
+
init_process2();
|
|
2135
|
+
|
|
2136
|
+
// src/keyPair.ts
|
|
2137
|
+
init_dirname();
|
|
2138
|
+
init_buffer2();
|
|
2139
|
+
init_process2();
|
|
2140
|
+
var import_bs58 = __toESM(require_bs58());
|
|
2141
|
+
|
|
2142
|
+
// ../../node_modules/.pnpm/@noble+ed25519@2.0.0/node_modules/@noble/ed25519/index.js
|
|
2143
|
+
init_dirname();
|
|
2144
|
+
init_buffer2();
|
|
2145
|
+
init_process2();
|
|
2146
|
+
var P = 2n ** 255n - 19n;
|
|
2147
|
+
var N = 2n ** 252n + 27742317777372353535851937790883648493n;
|
|
2148
|
+
var Gx = 0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an;
|
|
2149
|
+
var Gy = 0x6666666666666666666666666666666666666666666666666666666666666658n;
|
|
2150
|
+
var CURVE = {
|
|
2151
|
+
a: -1n,
|
|
2152
|
+
d: 37095705934669439343138083508754565189542113879843219016388785533085940283555n,
|
|
2153
|
+
p: P,
|
|
2154
|
+
n: N,
|
|
2155
|
+
h: 8,
|
|
2156
|
+
Gx,
|
|
2157
|
+
Gy
|
|
2158
|
+
// field prime, curve (group) order, cofactor
|
|
2159
|
+
};
|
|
2160
|
+
var err = (m = "") => {
|
|
2161
|
+
throw new Error(m);
|
|
2162
|
+
};
|
|
2163
|
+
var str = (s) => typeof s === "string";
|
|
2164
|
+
var au8 = (a, l) => (
|
|
2165
|
+
// is Uint8Array (of specific length)
|
|
2166
|
+
!(a instanceof Uint8Array) || typeof l === "number" && l > 0 && a.length !== l ? err("Uint8Array expected") : a
|
|
2167
|
+
);
|
|
2168
|
+
var u8n = (data) => new Uint8Array(data);
|
|
2169
|
+
var toU8 = (a, len) => au8(str(a) ? h2b(a) : u8n(a), len);
|
|
2170
|
+
var mod = (a, b = P) => {
|
|
2171
|
+
let r = a % b;
|
|
2172
|
+
return r >= 0n ? r : b + r;
|
|
2173
|
+
};
|
|
2174
|
+
var isPoint = (p) => p instanceof Point ? p : err("Point expected");
|
|
2175
|
+
var Gpows = void 0;
|
|
2176
|
+
var Point = class _Point {
|
|
2177
|
+
constructor(ex, ey, ez, et) {
|
|
2178
|
+
this.ex = ex;
|
|
2179
|
+
this.ey = ey;
|
|
2180
|
+
this.ez = ez;
|
|
2181
|
+
this.et = et;
|
|
2182
|
+
}
|
|
2183
|
+
static fromAffine(p) {
|
|
2184
|
+
return new _Point(p.x, p.y, 1n, mod(p.x * p.y));
|
|
2185
|
+
}
|
|
2186
|
+
static fromHex(hex, strict = true) {
|
|
2187
|
+
const { d } = CURVE;
|
|
2188
|
+
hex = toU8(hex, 32);
|
|
2189
|
+
const normed = hex.slice();
|
|
2190
|
+
normed[31] = hex[31] & ~128;
|
|
2191
|
+
const y = b2n_LE(normed);
|
|
2192
|
+
if (y === 0n) {
|
|
2193
|
+
} else {
|
|
2194
|
+
if (strict && !(0n < y && y < P))
|
|
2195
|
+
err("bad y coord 1");
|
|
2196
|
+
if (!strict && !(0n < y && y < 2n ** 256n))
|
|
2197
|
+
err("bad y coord 2");
|
|
2198
|
+
}
|
|
2199
|
+
const y2 = mod(y * y);
|
|
2200
|
+
const u = mod(y2 - 1n);
|
|
2201
|
+
const v = mod(d * y2 + 1n);
|
|
2202
|
+
let { isValid, value: x } = uvRatio(u, v);
|
|
2203
|
+
if (!isValid)
|
|
2204
|
+
err("bad y coordinate 3");
|
|
2205
|
+
const isXOdd = (x & 1n) === 1n;
|
|
2206
|
+
const isHeadOdd = (hex[31] & 128) !== 0;
|
|
2207
|
+
if (isHeadOdd !== isXOdd)
|
|
2208
|
+
x = mod(-x);
|
|
2209
|
+
return new _Point(x, y, 1n, mod(x * y));
|
|
2210
|
+
}
|
|
2211
|
+
get x() {
|
|
2212
|
+
return this.toAffine().x;
|
|
2213
|
+
}
|
|
2214
|
+
// .x, .y will call expensive toAffine.
|
|
2215
|
+
get y() {
|
|
2216
|
+
return this.toAffine().y;
|
|
2217
|
+
}
|
|
2218
|
+
// Should be used with care.
|
|
2219
|
+
equals(other) {
|
|
2220
|
+
const { ex: X1, ey: Y1, ez: Z1 } = this;
|
|
2221
|
+
const { ex: X2, ey: Y2, ez: Z2 } = isPoint(other);
|
|
2222
|
+
const X1Z2 = mod(X1 * Z2), X2Z1 = mod(X2 * Z1);
|
|
2223
|
+
const Y1Z2 = mod(Y1 * Z2), Y2Z1 = mod(Y2 * Z1);
|
|
2224
|
+
return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
|
|
2225
|
+
}
|
|
2226
|
+
is0() {
|
|
2227
|
+
return this.equals(I);
|
|
2228
|
+
}
|
|
2229
|
+
negate() {
|
|
2230
|
+
return new _Point(mod(-this.ex), this.ey, this.ez, mod(-this.et));
|
|
2231
|
+
}
|
|
2232
|
+
double() {
|
|
2233
|
+
const { ex: X1, ey: Y1, ez: Z1 } = this;
|
|
2234
|
+
const { a } = CURVE;
|
|
2235
|
+
const A = mod(X1 * X1);
|
|
2236
|
+
const B = mod(Y1 * Y1);
|
|
2237
|
+
const C = mod(2n * mod(Z1 * Z1));
|
|
2238
|
+
const D = mod(a * A);
|
|
2239
|
+
const x1y1 = X1 + Y1;
|
|
2240
|
+
const E = mod(mod(x1y1 * x1y1) - A - B);
|
|
2241
|
+
const G2 = D + B;
|
|
2242
|
+
const F = G2 - C;
|
|
2243
|
+
const H = D - B;
|
|
2244
|
+
const X3 = mod(E * F);
|
|
2245
|
+
const Y3 = mod(G2 * H);
|
|
2246
|
+
const T3 = mod(E * H);
|
|
2247
|
+
const Z3 = mod(F * G2);
|
|
2248
|
+
return new _Point(X3, Y3, Z3, T3);
|
|
2249
|
+
}
|
|
2250
|
+
add(other) {
|
|
2251
|
+
const { ex: X1, ey: Y1, ez: Z1, et: T1 } = this;
|
|
2252
|
+
const { ex: X2, ey: Y2, ez: Z2, et: T2 } = isPoint(other);
|
|
2253
|
+
const { a, d } = CURVE;
|
|
2254
|
+
const A = mod(X1 * X2);
|
|
2255
|
+
const B = mod(Y1 * Y2);
|
|
2256
|
+
const C = mod(T1 * d * T2);
|
|
2257
|
+
const D = mod(Z1 * Z2);
|
|
2258
|
+
const E = mod((X1 + Y1) * (X2 + Y2) - A - B);
|
|
2259
|
+
const F = mod(D - C);
|
|
2260
|
+
const G2 = mod(D + C);
|
|
2261
|
+
const H = mod(B - a * A);
|
|
2262
|
+
const X3 = mod(E * F);
|
|
2263
|
+
const Y3 = mod(G2 * H);
|
|
2264
|
+
const T3 = mod(E * H);
|
|
2265
|
+
const Z3 = mod(F * G2);
|
|
2266
|
+
return new _Point(X3, Y3, Z3, T3);
|
|
2267
|
+
}
|
|
2268
|
+
mul(n, safe = true) {
|
|
2269
|
+
if (n === 0n)
|
|
2270
|
+
return safe === true ? err("cannot multiply by 0") : I;
|
|
2271
|
+
if (!(typeof n === "bigint" && 0n < n && n < N))
|
|
2272
|
+
err("invalid scalar, must be < L");
|
|
2273
|
+
if (!safe && this.is0() || n === 1n)
|
|
2274
|
+
return this;
|
|
2275
|
+
if (this.equals(G))
|
|
2276
|
+
return wNAF(n).p;
|
|
2277
|
+
let p = I, f = G;
|
|
2278
|
+
for (let d = this; n > 0n; d = d.double(), n >>= 1n) {
|
|
2279
|
+
if (n & 1n)
|
|
2280
|
+
p = p.add(d);
|
|
2281
|
+
else if (safe)
|
|
2282
|
+
f = f.add(d);
|
|
2283
|
+
}
|
|
2284
|
+
return p;
|
|
2285
|
+
}
|
|
2286
|
+
multiply(scalar) {
|
|
2287
|
+
return this.mul(scalar);
|
|
2288
|
+
}
|
|
2289
|
+
// Aliases for compatibilty
|
|
2290
|
+
clearCofactor() {
|
|
2291
|
+
return this.mul(BigInt(CURVE.h), false);
|
|
2292
|
+
}
|
|
2293
|
+
// multiply by cofactor
|
|
2294
|
+
isSmallOrder() {
|
|
2295
|
+
return this.clearCofactor().is0();
|
|
2296
|
+
}
|
|
2297
|
+
// check if P is small order
|
|
2298
|
+
isTorsionFree() {
|
|
2299
|
+
let p = this.mul(N / 2n, false).double();
|
|
2300
|
+
if (N % 2n)
|
|
2301
|
+
p = p.add(this);
|
|
2302
|
+
return p.is0();
|
|
2303
|
+
}
|
|
2304
|
+
toAffine() {
|
|
2305
|
+
const { ex: x, ey: y, ez: z } = this;
|
|
2306
|
+
if (this.is0())
|
|
2307
|
+
return { x: 0n, y: 0n };
|
|
2308
|
+
const iz = invert(z);
|
|
2309
|
+
if (mod(z * iz) !== 1n)
|
|
2310
|
+
err("invalid inverse");
|
|
2311
|
+
return { x: mod(x * iz), y: mod(y * iz) };
|
|
2312
|
+
}
|
|
2313
|
+
toRawBytes() {
|
|
2314
|
+
const { x, y } = this.toAffine();
|
|
2315
|
+
const b = n2b_32LE(y);
|
|
2316
|
+
b[31] |= x & 1n ? 128 : 0;
|
|
2317
|
+
return b;
|
|
2318
|
+
}
|
|
2319
|
+
toHex() {
|
|
2320
|
+
return b2h(this.toRawBytes());
|
|
2321
|
+
}
|
|
2322
|
+
// encode to hex string
|
|
2323
|
+
};
|
|
2324
|
+
Point.BASE = new Point(Gx, Gy, 1n, mod(Gx * Gy));
|
|
2325
|
+
Point.ZERO = new Point(0n, 1n, 1n, 0n);
|
|
2326
|
+
var { BASE: G, ZERO: I } = Point;
|
|
2327
|
+
var padh = (num, pad) => num.toString(16).padStart(pad, "0");
|
|
2328
|
+
var b2h = (b) => Array.from(b).map((e) => padh(e, 2)).join("");
|
|
2329
|
+
var h2b = (hex) => {
|
|
2330
|
+
const l = hex.length;
|
|
2331
|
+
if (!str(hex) || l % 2)
|
|
2332
|
+
err("hex invalid 1");
|
|
2333
|
+
const arr = u8n(l / 2);
|
|
2334
|
+
for (let i = 0; i < arr.length; i++) {
|
|
2335
|
+
const j = i * 2;
|
|
2336
|
+
const h = hex.slice(j, j + 2);
|
|
2337
|
+
const b = Number.parseInt(h, 16);
|
|
2338
|
+
if (Number.isNaN(b) || b < 0)
|
|
2339
|
+
err("hex invalid 2");
|
|
2340
|
+
arr[i] = b;
|
|
2341
|
+
}
|
|
2342
|
+
return arr;
|
|
2343
|
+
};
|
|
2344
|
+
var n2b_32LE = (num) => h2b(padh(num, 32 * 2)).reverse();
|
|
2345
|
+
var b2n_LE = (b) => BigInt("0x" + b2h(u8n(au8(b)).reverse()));
|
|
2346
|
+
var concatB = (...arrs) => {
|
|
2347
|
+
const r = u8n(arrs.reduce((sum, a) => sum + au8(a).length, 0));
|
|
2348
|
+
let pad = 0;
|
|
2349
|
+
arrs.forEach((a) => {
|
|
2350
|
+
r.set(a, pad);
|
|
2351
|
+
pad += a.length;
|
|
2352
|
+
});
|
|
2353
|
+
return r;
|
|
2354
|
+
};
|
|
2355
|
+
var invert = (num, md = P) => {
|
|
2356
|
+
if (num === 0n || md <= 0n)
|
|
2357
|
+
err("no inverse n=" + num + " mod=" + md);
|
|
2358
|
+
let a = mod(num, md), b = md, x = 0n, y = 1n, u = 1n, v = 0n;
|
|
2359
|
+
while (a !== 0n) {
|
|
2360
|
+
const q = b / a, r = b % a;
|
|
2361
|
+
const m = x - u * q, n = y - v * q;
|
|
2362
|
+
b = a, a = r, x = u, y = v, u = m, v = n;
|
|
2363
|
+
}
|
|
2364
|
+
return b === 1n ? mod(x, md) : err("no inverse");
|
|
2365
|
+
};
|
|
2366
|
+
var pow2 = (x, power) => {
|
|
2367
|
+
let r = x;
|
|
2368
|
+
while (power-- > 0n) {
|
|
2369
|
+
r *= r;
|
|
2370
|
+
r %= P;
|
|
2371
|
+
}
|
|
2372
|
+
return r;
|
|
2373
|
+
};
|
|
2374
|
+
var pow_2_252_3 = (x) => {
|
|
2375
|
+
const x2 = x * x % P;
|
|
2376
|
+
const b2 = x2 * x % P;
|
|
2377
|
+
const b4 = pow2(b2, 2n) * b2 % P;
|
|
2378
|
+
const b5 = pow2(b4, 1n) * x % P;
|
|
2379
|
+
const b10 = pow2(b5, 5n) * b5 % P;
|
|
2380
|
+
const b20 = pow2(b10, 10n) * b10 % P;
|
|
2381
|
+
const b40 = pow2(b20, 20n) * b20 % P;
|
|
2382
|
+
const b80 = pow2(b40, 40n) * b40 % P;
|
|
2383
|
+
const b160 = pow2(b80, 80n) * b80 % P;
|
|
2384
|
+
const b240 = pow2(b160, 80n) * b80 % P;
|
|
2385
|
+
const b250 = pow2(b240, 10n) * b10 % P;
|
|
2386
|
+
const pow_p_5_8 = pow2(b250, 2n) * x % P;
|
|
2387
|
+
return { pow_p_5_8, b2 };
|
|
2388
|
+
};
|
|
2389
|
+
var RM1 = 19681161376707505956807079304988542015446066515923890162744021073123829784752n;
|
|
2390
|
+
var uvRatio = (u, v) => {
|
|
2391
|
+
const v3 = mod(v * v * v);
|
|
2392
|
+
const v7 = mod(v3 * v3 * v);
|
|
2393
|
+
const pow = pow_2_252_3(u * v7).pow_p_5_8;
|
|
2394
|
+
let x = mod(u * v3 * pow);
|
|
2395
|
+
const vx2 = mod(v * x * x);
|
|
2396
|
+
const root1 = x;
|
|
2397
|
+
const root2 = mod(x * RM1);
|
|
2398
|
+
const useRoot1 = vx2 === u;
|
|
2399
|
+
const useRoot2 = vx2 === mod(-u);
|
|
2400
|
+
const noRoot = vx2 === mod(-u * RM1);
|
|
2401
|
+
if (useRoot1)
|
|
2402
|
+
x = root1;
|
|
2403
|
+
if (useRoot2 || noRoot)
|
|
2404
|
+
x = root2;
|
|
2405
|
+
if ((mod(x) & 1n) === 1n)
|
|
2406
|
+
x = mod(-x);
|
|
2407
|
+
return { isValid: useRoot1 || useRoot2, value: x };
|
|
2408
|
+
};
|
|
2409
|
+
var modL_LE = (hash) => mod(b2n_LE(hash), N);
|
|
2410
|
+
var _shaS;
|
|
2411
|
+
var sha512a = (...m) => etc.sha512Async(...m);
|
|
2412
|
+
var sha512s = (...m) => (
|
|
2413
|
+
// Sync SHA512, not set by default
|
|
2414
|
+
typeof _shaS === "function" ? _shaS(...m) : err("etc.sha512Sync not set")
|
|
2415
|
+
);
|
|
2416
|
+
var hash2extK = (hashed) => {
|
|
2417
|
+
const head = hashed.slice(0, 32);
|
|
2418
|
+
head[0] &= 248;
|
|
2419
|
+
head[31] &= 127;
|
|
2420
|
+
head[31] |= 64;
|
|
2421
|
+
const prefix = hashed.slice(32, 64);
|
|
2422
|
+
const scalar = modL_LE(head);
|
|
2423
|
+
const point = G.mul(scalar);
|
|
2424
|
+
const pointBytes = point.toRawBytes();
|
|
2425
|
+
return { head, prefix, scalar, point, pointBytes };
|
|
2426
|
+
};
|
|
2427
|
+
var getExtendedPublicKeyAsync = (priv) => sha512a(toU8(priv, 32)).then(hash2extK);
|
|
2428
|
+
var getExtendedPublicKey = (priv) => hash2extK(sha512s(toU8(priv, 32)));
|
|
2429
|
+
var getPublicKeyAsync = (priv) => getExtendedPublicKeyAsync(priv).then((p) => p.pointBytes);
|
|
2430
|
+
function hashFinish(asynchronous, res) {
|
|
2431
|
+
if (asynchronous)
|
|
2432
|
+
return sha512a(res.hashable).then(res.finish);
|
|
2433
|
+
return res.finish(sha512s(res.hashable));
|
|
2434
|
+
}
|
|
2435
|
+
var _sign = (e, rBytes, msg) => {
|
|
2436
|
+
const { pointBytes: P2, scalar: s } = e;
|
|
2437
|
+
const r = modL_LE(rBytes);
|
|
2438
|
+
const R = G.mul(r).toRawBytes();
|
|
2439
|
+
const hashable = concatB(R, P2, msg);
|
|
2440
|
+
const finish = (hashed) => {
|
|
2441
|
+
const S = mod(r + modL_LE(hashed) * s, N);
|
|
2442
|
+
return au8(concatB(R, n2b_32LE(S)), 64);
|
|
2443
|
+
};
|
|
2444
|
+
return { hashable, finish };
|
|
2445
|
+
};
|
|
2446
|
+
var signAsync = async (msg, privKey) => {
|
|
2447
|
+
const m = toU8(msg);
|
|
2448
|
+
const e = await getExtendedPublicKeyAsync(privKey);
|
|
2449
|
+
const rBytes = await sha512a(e.prefix, m);
|
|
2450
|
+
return hashFinish(true, _sign(e, rBytes, m));
|
|
2451
|
+
};
|
|
2452
|
+
var cr = () => (
|
|
2453
|
+
// We support: 1) browsers 2) node.js 19+
|
|
2454
|
+
typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : void 0
|
|
2455
|
+
);
|
|
2456
|
+
var etc = {
|
|
2457
|
+
bytesToHex: b2h,
|
|
2458
|
+
hexToBytes: h2b,
|
|
2459
|
+
concatBytes: concatB,
|
|
2460
|
+
mod,
|
|
2461
|
+
invert,
|
|
2462
|
+
randomBytes: (len) => {
|
|
2463
|
+
const crypto = cr();
|
|
2464
|
+
if (!crypto)
|
|
2465
|
+
err("crypto.getRandomValues must be defined");
|
|
2466
|
+
return crypto.getRandomValues(u8n(len));
|
|
2467
|
+
},
|
|
2468
|
+
sha512Async: async (...messages) => {
|
|
2469
|
+
const crypto = cr();
|
|
2470
|
+
if (!crypto)
|
|
2471
|
+
err("crypto.subtle or etc.sha512Async must be defined");
|
|
2472
|
+
const m = concatB(...messages);
|
|
2473
|
+
return u8n(await crypto.subtle.digest("SHA-512", m.buffer));
|
|
2474
|
+
},
|
|
2475
|
+
sha512Sync: void 0
|
|
2476
|
+
// Actual logic below
|
|
2477
|
+
};
|
|
2478
|
+
Object.defineProperties(etc, { sha512Sync: {
|
|
2479
|
+
configurable: false,
|
|
2480
|
+
get() {
|
|
2481
|
+
return _shaS;
|
|
2482
|
+
},
|
|
2483
|
+
set(f) {
|
|
2484
|
+
if (!_shaS)
|
|
2485
|
+
_shaS = f;
|
|
2486
|
+
}
|
|
2487
|
+
} });
|
|
2488
|
+
var utils = {
|
|
2489
|
+
getExtendedPublicKeyAsync,
|
|
2490
|
+
getExtendedPublicKey,
|
|
2491
|
+
randomPrivateKey: () => etc.randomBytes(32),
|
|
2492
|
+
precompute(w = 8, p = G) {
|
|
2493
|
+
p.multiply(3n);
|
|
2494
|
+
return p;
|
|
2495
|
+
}
|
|
2496
|
+
// no-op
|
|
2497
|
+
};
|
|
2498
|
+
var W = 8;
|
|
2499
|
+
var precompute = () => {
|
|
2500
|
+
const points = [];
|
|
2501
|
+
const windows = 256 / W + 1;
|
|
2502
|
+
let p = G, b = p;
|
|
2503
|
+
for (let w = 0; w < windows; w++) {
|
|
2504
|
+
b = p;
|
|
2505
|
+
points.push(b);
|
|
2506
|
+
for (let i = 1; i < 2 ** (W - 1); i++) {
|
|
2507
|
+
b = b.add(p);
|
|
2508
|
+
points.push(b);
|
|
2509
|
+
}
|
|
2510
|
+
p = b.double();
|
|
2511
|
+
}
|
|
2512
|
+
return points;
|
|
2513
|
+
};
|
|
2514
|
+
var wNAF = (n) => {
|
|
2515
|
+
const comp = Gpows || (Gpows = precompute());
|
|
2516
|
+
const neg = (cnd, p2) => {
|
|
2517
|
+
let n2 = p2.negate();
|
|
2518
|
+
return cnd ? n2 : p2;
|
|
2519
|
+
};
|
|
2520
|
+
let p = I, f = G;
|
|
2521
|
+
const windows = 1 + 256 / W;
|
|
2522
|
+
const wsize = 2 ** (W - 1);
|
|
2523
|
+
const mask = BigInt(2 ** W - 1);
|
|
2524
|
+
const maxNum = 2 ** W;
|
|
2525
|
+
const shiftBy = BigInt(W);
|
|
2526
|
+
for (let w = 0; w < windows; w++) {
|
|
2527
|
+
const off = w * wsize;
|
|
2528
|
+
let wbits = Number(n & mask);
|
|
2529
|
+
n >>= shiftBy;
|
|
2530
|
+
if (wbits > wsize) {
|
|
2531
|
+
wbits -= maxNum;
|
|
2532
|
+
n += 1n;
|
|
2533
|
+
}
|
|
2534
|
+
const off1 = off, off2 = off + Math.abs(wbits) - 1;
|
|
2535
|
+
const cnd1 = w % 2 !== 0, cnd2 = wbits < 0;
|
|
2536
|
+
if (wbits === 0) {
|
|
2537
|
+
f = f.add(neg(cnd1, comp[off1]));
|
|
2538
|
+
} else {
|
|
2539
|
+
p = p.add(neg(cnd2, comp[off2]));
|
|
2540
|
+
}
|
|
2541
|
+
}
|
|
2542
|
+
return { p, f };
|
|
2543
|
+
};
|
|
2544
|
+
|
|
2545
|
+
// src/keyPair.ts
|
|
2546
|
+
var BaseOrderlyKeyPair = class _BaseOrderlyKeyPair {
|
|
2547
|
+
static generateKey() {
|
|
2548
|
+
let privKey, secretKey;
|
|
2549
|
+
do {
|
|
2550
|
+
privKey = utils.randomPrivateKey();
|
|
2551
|
+
secretKey = (0, import_bs58.encode)(privKey);
|
|
2552
|
+
} while (secretKey.length !== 44);
|
|
2553
|
+
return new _BaseOrderlyKeyPair(secretKey);
|
|
2554
|
+
}
|
|
2555
|
+
constructor(secretKey) {
|
|
2556
|
+
this.secretKey = secretKey;
|
|
2557
|
+
const bytes = (0, import_bs58.decode)(secretKey);
|
|
2558
|
+
this.privateKey = Buffer2.from(bytes).toString("hex");
|
|
2559
|
+
}
|
|
2560
|
+
async sign(message) {
|
|
2561
|
+
return await signAsync(message, this.privateKey);
|
|
2562
|
+
}
|
|
2563
|
+
async getPublicKey() {
|
|
2564
|
+
const pubKey = await getPublicKeyAsync(this.privateKey);
|
|
2565
|
+
const publicKey = `ed25519:${(0, import_bs58.encode)(pubKey)}`;
|
|
2566
|
+
return publicKey;
|
|
2567
|
+
}
|
|
2568
|
+
toString() {
|
|
2569
|
+
return this.privateKey;
|
|
2570
|
+
}
|
|
2571
|
+
};
|
|
2572
|
+
|
|
2573
|
+
// src/keyStore.ts
|
|
2574
|
+
var BaseKeyStore = class {
|
|
2575
|
+
constructor(networkId = "testnet") {
|
|
2576
|
+
this.networkId = networkId;
|
|
2577
|
+
}
|
|
2578
|
+
get keyPrefix() {
|
|
2579
|
+
return `orderly_${this.networkId}_`;
|
|
2580
|
+
}
|
|
2581
|
+
};
|
|
2582
|
+
var LocalStorageStore = class extends BaseKeyStore {
|
|
2583
|
+
getOrderlyKey(address) {
|
|
2584
|
+
let orderlyKey;
|
|
2585
|
+
if (address) {
|
|
2586
|
+
orderlyKey = this.getItem(address, "orderlyKey");
|
|
2587
|
+
} else {
|
|
2588
|
+
const address2 = this.getAddress();
|
|
2589
|
+
if (!address2)
|
|
2590
|
+
return null;
|
|
2591
|
+
orderlyKey = this.getItem(address2, "orderlyKey");
|
|
2592
|
+
}
|
|
2593
|
+
if (!orderlyKey) {
|
|
2594
|
+
return null;
|
|
2595
|
+
}
|
|
2596
|
+
return new BaseOrderlyKeyPair(orderlyKey);
|
|
2597
|
+
}
|
|
2598
|
+
getAccountId(address) {
|
|
2599
|
+
return this.getItem(address, "accountId");
|
|
2600
|
+
}
|
|
2601
|
+
setAccountId(address, accountId) {
|
|
2602
|
+
this.setItem(address, { accountId });
|
|
2603
|
+
}
|
|
2604
|
+
getAddress() {
|
|
2605
|
+
return localStorage.getItem(`${this.keyPrefix}address`);
|
|
2606
|
+
}
|
|
2607
|
+
setAddress(address) {
|
|
2608
|
+
localStorage.setItem(`${this.keyPrefix}address`, address);
|
|
2609
|
+
}
|
|
2610
|
+
generateKey() {
|
|
2611
|
+
return BaseOrderlyKeyPair.generateKey();
|
|
2612
|
+
}
|
|
2613
|
+
setKey(address, orderlyKey) {
|
|
2614
|
+
this.setItem(address, { orderlyKey: orderlyKey.secretKey });
|
|
2615
|
+
}
|
|
2616
|
+
cleanAllKey(address) {
|
|
2617
|
+
localStorage.removeItem(`${this.keyPrefix}${address}`);
|
|
2618
|
+
localStorage.removeItem(`${this.keyPrefix}address`);
|
|
2619
|
+
}
|
|
2620
|
+
cleanKey(address, key) {
|
|
2621
|
+
const data = this.getItem(address);
|
|
2622
|
+
delete data[key];
|
|
2623
|
+
localStorage.setItem(`${this.keyPrefix}${address}`, JSON.stringify(data));
|
|
2624
|
+
}
|
|
2625
|
+
setItem(address, value) {
|
|
2626
|
+
const key = `${this.keyPrefix}${address}`;
|
|
2627
|
+
let oldValue = localStorage.getItem(key);
|
|
2628
|
+
if (oldValue) {
|
|
2629
|
+
oldValue = JSON.parse(oldValue);
|
|
2630
|
+
} else {
|
|
2631
|
+
oldValue = {};
|
|
2632
|
+
}
|
|
2633
|
+
localStorage.setItem(
|
|
2634
|
+
key,
|
|
2635
|
+
JSON.stringify({
|
|
2636
|
+
...oldValue,
|
|
2637
|
+
...value
|
|
2638
|
+
})
|
|
2639
|
+
);
|
|
2640
|
+
}
|
|
2641
|
+
getItem(address, name) {
|
|
2642
|
+
const key = `${this.keyPrefix}${address}`;
|
|
2643
|
+
let value = localStorage.getItem(key);
|
|
2644
|
+
if (value) {
|
|
2645
|
+
value = JSON.parse(value);
|
|
2646
|
+
} else {
|
|
2647
|
+
value = {};
|
|
2648
|
+
}
|
|
2649
|
+
if (typeof name === "undefined") {
|
|
2650
|
+
return value;
|
|
2651
|
+
}
|
|
2652
|
+
return value[name];
|
|
2653
|
+
}
|
|
2654
|
+
};
|
|
2655
|
+
var MockKeyStore = class {
|
|
2656
|
+
constructor(secretKey) {
|
|
2657
|
+
this.secretKey = secretKey;
|
|
2658
|
+
}
|
|
2659
|
+
generateKey() {
|
|
2660
|
+
return new BaseOrderlyKeyPair(this.secretKey);
|
|
2661
|
+
}
|
|
2662
|
+
getOrderlyKey() {
|
|
2663
|
+
return new BaseOrderlyKeyPair(this.secretKey);
|
|
2664
|
+
}
|
|
2665
|
+
getAccountId() {
|
|
2666
|
+
return "";
|
|
2667
|
+
}
|
|
2668
|
+
setAccountId(accountId) {
|
|
2669
|
+
}
|
|
2670
|
+
getAddress() {
|
|
2671
|
+
return "";
|
|
2672
|
+
}
|
|
2673
|
+
setAddress(address) {
|
|
2674
|
+
}
|
|
2675
|
+
setKey(orderlyKey, secretKey) {
|
|
2676
|
+
}
|
|
2677
|
+
cleanAllKey() {
|
|
2678
|
+
}
|
|
2679
|
+
cleanKey(key) {
|
|
2680
|
+
}
|
|
2681
|
+
};
|
|
2682
|
+
|
|
2683
|
+
// src/signer.ts
|
|
2684
|
+
init_dirname();
|
|
2685
|
+
init_buffer2();
|
|
2686
|
+
init_process2();
|
|
2687
|
+
|
|
2688
|
+
// src/utils.ts
|
|
2689
|
+
init_dirname();
|
|
2690
|
+
init_buffer2();
|
|
2691
|
+
init_process2();
|
|
2692
|
+
|
|
2693
|
+
// src/constants.ts
|
|
2694
|
+
init_dirname();
|
|
2695
|
+
init_buffer2();
|
|
2696
|
+
init_process2();
|
|
2697
|
+
var definedTypes = {
|
|
2698
|
+
EIP712Domain: [
|
|
2699
|
+
{ name: "name", type: "string" },
|
|
2700
|
+
{ name: "version", type: "string" },
|
|
2701
|
+
{ name: "chainId", type: "uint256" },
|
|
2702
|
+
{ name: "verifyingContract", type: "address" }
|
|
2703
|
+
],
|
|
2704
|
+
Registration: [
|
|
2705
|
+
{ name: "brokerId", type: "string" },
|
|
2706
|
+
{ name: "chainId", type: "uint256" },
|
|
2707
|
+
{ name: "timestamp", type: "uint64" },
|
|
2708
|
+
{ name: "registrationNonce", type: "uint256" }
|
|
2709
|
+
],
|
|
2710
|
+
Withdraw: [
|
|
2711
|
+
{ name: "brokerId", type: "string" },
|
|
2712
|
+
{ name: "chainId", type: "uint256" },
|
|
2713
|
+
{ name: "receiver", type: "address" },
|
|
2714
|
+
{ name: "token", type: "string" },
|
|
2715
|
+
{ name: "amount", type: "uint256" },
|
|
2716
|
+
{ name: "withdrawNonce", type: "uint64" },
|
|
2717
|
+
{ name: "timestamp", type: "uint64" }
|
|
2718
|
+
],
|
|
2719
|
+
AddOrderlyKey: [
|
|
2720
|
+
{ name: "brokerId", type: "string" },
|
|
2721
|
+
{ name: "chainId", type: "uint256" },
|
|
2722
|
+
{ name: "orderlyKey", type: "string" },
|
|
2723
|
+
{ name: "scope", type: "string" },
|
|
2724
|
+
{ name: "timestamp", type: "uint64" },
|
|
2725
|
+
{ name: "expiration", type: "uint64" }
|
|
2726
|
+
],
|
|
2727
|
+
SettlePnl: [
|
|
2728
|
+
{ name: "brokerId", type: "string" },
|
|
2729
|
+
{ name: "chainId", type: "uint256" },
|
|
2730
|
+
{ name: "settleNonce", type: "uint64" },
|
|
2731
|
+
{ name: "timestamp", type: "uint64" }
|
|
2732
|
+
]
|
|
2733
|
+
};
|
|
2734
|
+
var stagingUSDCAddressOnArbitrumTestnet = "0x6aAd876244E7A1Ad44Ec4824Ce813729E5B6C291";
|
|
2735
|
+
var stagingVaultAddressOnArbitrumTestnet = "0xd64AeB281f3E8cd70e668b6cb24De7e532dC214D";
|
|
2736
|
+
var stagingVerifyAddressOnArbitrumTestnet = "0x1826B75e2ef249173FC735149AE4B8e9ea10abff";
|
|
2737
|
+
|
|
2738
|
+
// src/utils.ts
|
|
2739
|
+
var import_ethers = require("ethers");
|
|
2740
|
+
var base64url = function(aStr) {
|
|
2741
|
+
return aStr.replace(/\+/g, "-").replace(/\//g, "_");
|
|
2742
|
+
};
|
|
2743
|
+
function getVerifyingContract() {
|
|
2744
|
+
return "0x8794E7260517B1766fc7b55cAfcd56e6bf08600e";
|
|
2745
|
+
}
|
|
2746
|
+
function getDomain(chainId, onChainDomain) {
|
|
2747
|
+
return {
|
|
2748
|
+
name: "Orderly",
|
|
2749
|
+
version: "1",
|
|
2750
|
+
chainId,
|
|
2751
|
+
verifyingContract: onChainDomain ? getVerifyingContract() : "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"
|
|
2752
|
+
};
|
|
2753
|
+
}
|
|
2754
|
+
function generateRegisterAccountMessage(inputs) {
|
|
2755
|
+
const { chainId, registrationNonce, brokerId } = inputs;
|
|
2756
|
+
const now = Date.now();
|
|
2757
|
+
const primaryType = "Registration";
|
|
2758
|
+
const message = {
|
|
2759
|
+
brokerId,
|
|
2760
|
+
chainId,
|
|
2761
|
+
timestamp: now,
|
|
2762
|
+
registrationNonce
|
|
2763
|
+
};
|
|
2764
|
+
const typeDefinition = {
|
|
2765
|
+
EIP712Domain: definedTypes.EIP712Domain,
|
|
2766
|
+
[primaryType]: definedTypes[primaryType]
|
|
2767
|
+
};
|
|
2768
|
+
return [
|
|
2769
|
+
message,
|
|
2770
|
+
{
|
|
2771
|
+
domain: getDomain(chainId),
|
|
2772
|
+
message,
|
|
2773
|
+
primaryType,
|
|
2774
|
+
types: typeDefinition
|
|
2775
|
+
}
|
|
2776
|
+
];
|
|
2777
|
+
}
|
|
2778
|
+
function generateAddOrderlyKeyMessage(inputs) {
|
|
2779
|
+
const {
|
|
2780
|
+
publicKey,
|
|
2781
|
+
chainId,
|
|
2782
|
+
primaryType,
|
|
2783
|
+
brokerId,
|
|
2784
|
+
expiration = 365
|
|
2785
|
+
} = inputs;
|
|
2786
|
+
const now = Date.now();
|
|
2787
|
+
const message = {
|
|
2788
|
+
brokerId,
|
|
2789
|
+
orderlyKey: publicKey,
|
|
2790
|
+
scope: "read,trading",
|
|
2791
|
+
chainId,
|
|
2792
|
+
timestamp: now,
|
|
2793
|
+
expiration: now + 1e3 * 60 * 60 * 24 * expiration
|
|
2794
|
+
};
|
|
2795
|
+
const typeDefinition = {
|
|
2796
|
+
EIP712Domain: definedTypes.EIP712Domain,
|
|
2797
|
+
[primaryType]: definedTypes[primaryType]
|
|
2798
|
+
};
|
|
2799
|
+
const toSignatureMessage = {
|
|
2800
|
+
domain: getDomain(chainId),
|
|
2801
|
+
message,
|
|
2802
|
+
primaryType,
|
|
2803
|
+
types: typeDefinition
|
|
2804
|
+
};
|
|
2805
|
+
return [message, toSignatureMessage];
|
|
2806
|
+
}
|
|
2807
|
+
function generateSettleMessage(inputs) {
|
|
2808
|
+
const { chainId, settlePnlNonce, domain, brokerId } = inputs;
|
|
2809
|
+
const primaryType = "SettlePnl";
|
|
2810
|
+
const timestamp = (/* @__PURE__ */ new Date()).getTime();
|
|
2811
|
+
const typeDefinition = {
|
|
2812
|
+
EIP712Domain: definedTypes.EIP712Domain,
|
|
2813
|
+
[primaryType]: definedTypes[primaryType]
|
|
2814
|
+
};
|
|
2815
|
+
const message = {
|
|
2816
|
+
brokerId,
|
|
2817
|
+
chainId,
|
|
2818
|
+
timestamp,
|
|
2819
|
+
settleNonce: settlePnlNonce
|
|
2820
|
+
};
|
|
2821
|
+
const toSignatureMessage = {
|
|
2822
|
+
domain,
|
|
2823
|
+
message,
|
|
2824
|
+
primaryType,
|
|
2825
|
+
types: typeDefinition
|
|
2826
|
+
};
|
|
2827
|
+
return [message, toSignatureMessage];
|
|
2828
|
+
}
|
|
2829
|
+
function parseBrokerHash(brokerId) {
|
|
2830
|
+
return calculateStringHash(brokerId);
|
|
2831
|
+
}
|
|
2832
|
+
function parseAccountId(userAddress, brokerId) {
|
|
2833
|
+
const abicoder = import_ethers.AbiCoder.defaultAbiCoder();
|
|
2834
|
+
return (0, import_ethers.keccak256)(
|
|
2835
|
+
abicoder.encode(
|
|
2836
|
+
["address", "bytes32"],
|
|
2837
|
+
[userAddress, parseBrokerHash(brokerId)]
|
|
2838
|
+
)
|
|
2839
|
+
);
|
|
2840
|
+
}
|
|
2841
|
+
function parseTokenHash(tokenSymbol) {
|
|
2842
|
+
return calculateStringHash(tokenSymbol);
|
|
2843
|
+
}
|
|
2844
|
+
function calculateStringHash(input) {
|
|
2845
|
+
return (0, import_ethers.solidityPackedKeccak256)(["string"], [input]);
|
|
2846
|
+
}
|
|
2847
|
+
|
|
2848
|
+
// src/signer.ts
|
|
2849
|
+
init_buffer();
|
|
2850
|
+
var BaseSigner = class {
|
|
2851
|
+
constructor(keyStore) {
|
|
2852
|
+
this.keyStore = keyStore;
|
|
2853
|
+
}
|
|
2854
|
+
async sign(message) {
|
|
2855
|
+
const timestamp = Date.now().toString();
|
|
2856
|
+
let msgStr = [timestamp, message.method.toUpperCase(), message.url].join(
|
|
2857
|
+
""
|
|
2858
|
+
);
|
|
2859
|
+
if (message.data && Object.keys(message.data).length) {
|
|
2860
|
+
msgStr += JSON.stringify(message.data);
|
|
2861
|
+
}
|
|
2862
|
+
const { signature, publicKey } = await this.signText(msgStr);
|
|
2863
|
+
return {
|
|
2864
|
+
"orderly-key": publicKey,
|
|
2865
|
+
"orderly-timestamp": timestamp,
|
|
2866
|
+
"orderly-signature": signature
|
|
2867
|
+
};
|
|
2868
|
+
}
|
|
2869
|
+
async signText(text) {
|
|
2870
|
+
const orderlyKeyPair = this.keyStore.getOrderlyKey();
|
|
2871
|
+
if (!orderlyKeyPair) {
|
|
2872
|
+
throw new Error("orderlyKeyPair is not defined");
|
|
2873
|
+
}
|
|
2874
|
+
const u8 = Buffer2.from(text);
|
|
2875
|
+
const signature = await orderlyKeyPair.sign(u8);
|
|
2876
|
+
const signHex = Buffer2.from(signature).toString("base64");
|
|
2877
|
+
const b64 = base64url(signHex);
|
|
2878
|
+
return {
|
|
2879
|
+
signature: b64,
|
|
2880
|
+
publicKey: await orderlyKeyPair.getPublicKey()
|
|
2881
|
+
};
|
|
2882
|
+
}
|
|
2883
|
+
};
|
|
2884
|
+
|
|
2885
|
+
// src/index.ts
|
|
2886
|
+
var import_eventemitter32 = __toESM(require("eventemitter3"));
|
|
2887
|
+
|
|
2888
|
+
// src/helper.ts
|
|
2889
|
+
init_dirname();
|
|
2890
|
+
init_buffer2();
|
|
2891
|
+
init_process2();
|
|
2892
|
+
|
|
2893
|
+
// src/configStore.ts
|
|
2894
|
+
init_dirname();
|
|
2895
|
+
init_buffer2();
|
|
2896
|
+
init_process2();
|
|
2897
|
+
var MemoryConfigStore = class {
|
|
2898
|
+
constructor() {
|
|
2899
|
+
this._restore();
|
|
2900
|
+
}
|
|
2901
|
+
_restore() {
|
|
2902
|
+
this.map = /* @__PURE__ */ new Map([
|
|
2903
|
+
// ["apiBaseUrl", "https://testnet-api-evm.orderly.org"],
|
|
2904
|
+
["apiBaseUrl", "https://dev-api-iap-v2.orderly.org"],
|
|
2905
|
+
// ["apiBaseUrl", "https://qa-api-evm.orderly.org"],
|
|
2906
|
+
["klineDataUrl", "https://testnet-api-evm.orderly.org"],
|
|
2907
|
+
// ["publicWsUrl", "wss://testnet-ws-evm.orderly.org"],
|
|
2908
|
+
["publicWsUrl", "wss://dev-ws-v2.orderly.org"],
|
|
2909
|
+
["publicWebsocketKey", "OqdphuyCtYWxwzhxyLLjOWNdFP7sQt8RPWzmb5xY"],
|
|
2910
|
+
["privateWsUrl", "wss://dev-ws-private-v2.orderly.org"],
|
|
2911
|
+
// ["privateWsUrl", "wss://testnet-ws-private-evm.orderly.org"],
|
|
2912
|
+
["operatorUrl", "https://testnet-operator-evm.orderly.org"],
|
|
2913
|
+
["swapSupportApiUrl", "https://woofi-api.mer1in.com"],
|
|
2914
|
+
["brokerId", "woofi_dex"],
|
|
2915
|
+
["env", "dev-evm"]
|
|
2916
|
+
]);
|
|
2917
|
+
}
|
|
2918
|
+
get(key) {
|
|
2919
|
+
return this.map.get(key);
|
|
2920
|
+
}
|
|
2921
|
+
set(key, value) {
|
|
2922
|
+
this.map.set(key, value);
|
|
2923
|
+
}
|
|
2924
|
+
clear() {
|
|
2925
|
+
}
|
|
2926
|
+
};
|
|
2927
|
+
var BaseConfigStore = class extends MemoryConfigStore {
|
|
2928
|
+
constructor(configMap) {
|
|
2929
|
+
super();
|
|
2930
|
+
this.configMap = configMap;
|
|
2931
|
+
}
|
|
2932
|
+
_restore() {
|
|
2933
|
+
const arr = Object.entries(this.configMap);
|
|
2934
|
+
this.map = new Map(arr);
|
|
2935
|
+
}
|
|
2936
|
+
};
|
|
2937
|
+
|
|
2938
|
+
// src/helper.ts
|
|
2939
|
+
var getMockSigner = (secretKey) => {
|
|
2940
|
+
const mockKeyStore = new MockKeyStore(
|
|
2941
|
+
secretKey || "AFmQSju4FhDwG93cMdKogcnKx7SWmViDtDv5PVzfvRDF"
|
|
2942
|
+
// "c24fe227663f5a73493cad3f4049514f70623177272d57fffa8cb895fa1f92de"
|
|
2943
|
+
);
|
|
2944
|
+
return new BaseSigner(mockKeyStore);
|
|
2945
|
+
};
|
|
2946
|
+
var getDefaultSigner = () => {
|
|
2947
|
+
if (typeof window === "undefined") {
|
|
2948
|
+
throw new Error("the default signer only supports browsers.");
|
|
2949
|
+
}
|
|
2950
|
+
const localStorageStore = new LocalStorageStore("");
|
|
2951
|
+
return new BaseSigner(localStorageStore);
|
|
2952
|
+
};
|
|
2953
|
+
|
|
2954
|
+
// src/contract.ts
|
|
2955
|
+
init_dirname();
|
|
2956
|
+
init_buffer2();
|
|
2957
|
+
init_process2();
|
|
2958
|
+
|
|
2959
|
+
// src/wallet/abis/stagingUSDCAbi.json
|
|
2960
|
+
var stagingUSDCAbi_default = [
|
|
2961
|
+
{
|
|
2962
|
+
inputs: [
|
|
2963
|
+
{
|
|
2964
|
+
internalType: "string",
|
|
2965
|
+
name: "name_",
|
|
2966
|
+
type: "string"
|
|
2967
|
+
},
|
|
2968
|
+
{
|
|
2969
|
+
internalType: "string",
|
|
2970
|
+
name: "symbol_",
|
|
2971
|
+
type: "string"
|
|
2972
|
+
},
|
|
2973
|
+
{
|
|
2974
|
+
internalType: "uint8",
|
|
2975
|
+
name: "decimals_",
|
|
2976
|
+
type: "uint8"
|
|
2977
|
+
}
|
|
2978
|
+
],
|
|
2979
|
+
stateMutability: "nonpayable",
|
|
2980
|
+
type: "constructor"
|
|
2981
|
+
},
|
|
2982
|
+
{
|
|
2983
|
+
anonymous: false,
|
|
2984
|
+
inputs: [
|
|
2985
|
+
{
|
|
2986
|
+
indexed: true,
|
|
2987
|
+
internalType: "address",
|
|
2988
|
+
name: "owner",
|
|
2989
|
+
type: "address"
|
|
2990
|
+
},
|
|
2991
|
+
{
|
|
2992
|
+
indexed: true,
|
|
2993
|
+
internalType: "address",
|
|
2994
|
+
name: "spender",
|
|
2995
|
+
type: "address"
|
|
2996
|
+
},
|
|
2997
|
+
{
|
|
2998
|
+
indexed: false,
|
|
2999
|
+
internalType: "uint256",
|
|
3000
|
+
name: "value",
|
|
3001
|
+
type: "uint256"
|
|
3002
|
+
}
|
|
3003
|
+
],
|
|
3004
|
+
name: "Approval",
|
|
3005
|
+
type: "event"
|
|
3006
|
+
},
|
|
3007
|
+
{
|
|
3008
|
+
anonymous: false,
|
|
3009
|
+
inputs: [
|
|
3010
|
+
{
|
|
3011
|
+
indexed: true,
|
|
3012
|
+
internalType: "address",
|
|
3013
|
+
name: "from",
|
|
3014
|
+
type: "address"
|
|
3015
|
+
},
|
|
3016
|
+
{
|
|
3017
|
+
indexed: true,
|
|
3018
|
+
internalType: "address",
|
|
3019
|
+
name: "to",
|
|
3020
|
+
type: "address"
|
|
3021
|
+
},
|
|
3022
|
+
{
|
|
3023
|
+
indexed: false,
|
|
3024
|
+
internalType: "uint256",
|
|
3025
|
+
name: "value",
|
|
3026
|
+
type: "uint256"
|
|
3027
|
+
}
|
|
3028
|
+
],
|
|
3029
|
+
name: "Transfer",
|
|
3030
|
+
type: "event"
|
|
3031
|
+
},
|
|
3032
|
+
{
|
|
3033
|
+
inputs: [
|
|
3034
|
+
{
|
|
3035
|
+
internalType: "address",
|
|
3036
|
+
name: "owner",
|
|
3037
|
+
type: "address"
|
|
3038
|
+
},
|
|
3039
|
+
{
|
|
3040
|
+
internalType: "address",
|
|
3041
|
+
name: "spender",
|
|
3042
|
+
type: "address"
|
|
3043
|
+
}
|
|
3044
|
+
],
|
|
3045
|
+
name: "allowance",
|
|
3046
|
+
outputs: [
|
|
3047
|
+
{
|
|
3048
|
+
internalType: "uint256",
|
|
3049
|
+
name: "",
|
|
3050
|
+
type: "uint256"
|
|
3051
|
+
}
|
|
3052
|
+
],
|
|
3053
|
+
stateMutability: "view",
|
|
3054
|
+
type: "function"
|
|
3055
|
+
},
|
|
3056
|
+
{
|
|
3057
|
+
inputs: [
|
|
3058
|
+
{
|
|
3059
|
+
internalType: "address",
|
|
3060
|
+
name: "spender",
|
|
3061
|
+
type: "address"
|
|
3062
|
+
},
|
|
3063
|
+
{
|
|
3064
|
+
internalType: "uint256",
|
|
3065
|
+
name: "amount",
|
|
3066
|
+
type: "uint256"
|
|
3067
|
+
}
|
|
3068
|
+
],
|
|
3069
|
+
name: "approve",
|
|
3070
|
+
outputs: [
|
|
3071
|
+
{
|
|
3072
|
+
internalType: "bool",
|
|
3073
|
+
name: "",
|
|
3074
|
+
type: "bool"
|
|
3075
|
+
}
|
|
3076
|
+
],
|
|
3077
|
+
stateMutability: "nonpayable",
|
|
3078
|
+
type: "function"
|
|
3079
|
+
},
|
|
3080
|
+
{
|
|
3081
|
+
inputs: [
|
|
3082
|
+
{
|
|
3083
|
+
internalType: "address",
|
|
3084
|
+
name: "account",
|
|
3085
|
+
type: "address"
|
|
3086
|
+
}
|
|
3087
|
+
],
|
|
3088
|
+
name: "balanceOf",
|
|
3089
|
+
outputs: [
|
|
3090
|
+
{
|
|
3091
|
+
internalType: "uint256",
|
|
3092
|
+
name: "",
|
|
3093
|
+
type: "uint256"
|
|
3094
|
+
}
|
|
3095
|
+
],
|
|
3096
|
+
stateMutability: "view",
|
|
3097
|
+
type: "function"
|
|
3098
|
+
},
|
|
3099
|
+
{
|
|
3100
|
+
inputs: [],
|
|
3101
|
+
name: "decimals",
|
|
3102
|
+
outputs: [
|
|
3103
|
+
{
|
|
3104
|
+
internalType: "uint8",
|
|
3105
|
+
name: "",
|
|
3106
|
+
type: "uint8"
|
|
3107
|
+
}
|
|
3108
|
+
],
|
|
3109
|
+
stateMutability: "view",
|
|
3110
|
+
type: "function"
|
|
3111
|
+
},
|
|
3112
|
+
{
|
|
3113
|
+
inputs: [
|
|
3114
|
+
{
|
|
3115
|
+
internalType: "address",
|
|
3116
|
+
name: "spender",
|
|
3117
|
+
type: "address"
|
|
3118
|
+
},
|
|
3119
|
+
{
|
|
3120
|
+
internalType: "uint256",
|
|
3121
|
+
name: "subtractedValue",
|
|
3122
|
+
type: "uint256"
|
|
3123
|
+
}
|
|
3124
|
+
],
|
|
3125
|
+
name: "decreaseAllowance",
|
|
3126
|
+
outputs: [
|
|
3127
|
+
{
|
|
3128
|
+
internalType: "bool",
|
|
3129
|
+
name: "",
|
|
3130
|
+
type: "bool"
|
|
3131
|
+
}
|
|
3132
|
+
],
|
|
3133
|
+
stateMutability: "nonpayable",
|
|
3134
|
+
type: "function"
|
|
3135
|
+
},
|
|
3136
|
+
{
|
|
3137
|
+
inputs: [
|
|
3138
|
+
{
|
|
3139
|
+
internalType: "address",
|
|
3140
|
+
name: "spender",
|
|
3141
|
+
type: "address"
|
|
3142
|
+
},
|
|
3143
|
+
{
|
|
3144
|
+
internalType: "uint256",
|
|
3145
|
+
name: "addedValue",
|
|
3146
|
+
type: "uint256"
|
|
3147
|
+
}
|
|
3148
|
+
],
|
|
3149
|
+
name: "increaseAllowance",
|
|
3150
|
+
outputs: [
|
|
3151
|
+
{
|
|
3152
|
+
internalType: "bool",
|
|
3153
|
+
name: "",
|
|
3154
|
+
type: "bool"
|
|
3155
|
+
}
|
|
3156
|
+
],
|
|
3157
|
+
stateMutability: "nonpayable",
|
|
3158
|
+
type: "function"
|
|
3159
|
+
},
|
|
3160
|
+
{
|
|
3161
|
+
inputs: [
|
|
3162
|
+
{
|
|
3163
|
+
internalType: "uint256",
|
|
3164
|
+
name: "amount",
|
|
3165
|
+
type: "uint256"
|
|
3166
|
+
}
|
|
3167
|
+
],
|
|
3168
|
+
name: "issue",
|
|
3169
|
+
outputs: [],
|
|
3170
|
+
stateMutability: "nonpayable",
|
|
3171
|
+
type: "function"
|
|
3172
|
+
},
|
|
3173
|
+
{
|
|
3174
|
+
inputs: [
|
|
3175
|
+
{
|
|
3176
|
+
internalType: "address",
|
|
3177
|
+
name: "_to",
|
|
3178
|
+
type: "address"
|
|
3179
|
+
},
|
|
3180
|
+
{
|
|
3181
|
+
internalType: "uint256",
|
|
3182
|
+
name: "_amount",
|
|
3183
|
+
type: "uint256"
|
|
3184
|
+
}
|
|
3185
|
+
],
|
|
3186
|
+
name: "mint",
|
|
3187
|
+
outputs: [],
|
|
3188
|
+
stateMutability: "nonpayable",
|
|
3189
|
+
type: "function"
|
|
3190
|
+
},
|
|
3191
|
+
{
|
|
3192
|
+
inputs: [],
|
|
3193
|
+
name: "name",
|
|
3194
|
+
outputs: [
|
|
3195
|
+
{
|
|
3196
|
+
internalType: "string",
|
|
3197
|
+
name: "",
|
|
3198
|
+
type: "string"
|
|
3199
|
+
}
|
|
3200
|
+
],
|
|
3201
|
+
stateMutability: "view",
|
|
3202
|
+
type: "function"
|
|
3203
|
+
},
|
|
3204
|
+
{
|
|
3205
|
+
inputs: [
|
|
3206
|
+
{
|
|
3207
|
+
internalType: "bool",
|
|
3208
|
+
name: "_paused",
|
|
3209
|
+
type: "bool"
|
|
3210
|
+
}
|
|
3211
|
+
],
|
|
3212
|
+
name: "pauseTransfers",
|
|
3213
|
+
outputs: [],
|
|
3214
|
+
stateMutability: "nonpayable",
|
|
3215
|
+
type: "function"
|
|
3216
|
+
},
|
|
3217
|
+
{
|
|
3218
|
+
inputs: [],
|
|
3219
|
+
name: "symbol",
|
|
3220
|
+
outputs: [
|
|
3221
|
+
{
|
|
3222
|
+
internalType: "string",
|
|
3223
|
+
name: "",
|
|
3224
|
+
type: "string"
|
|
3225
|
+
}
|
|
3226
|
+
],
|
|
3227
|
+
stateMutability: "view",
|
|
3228
|
+
type: "function"
|
|
3229
|
+
},
|
|
3230
|
+
{
|
|
3231
|
+
inputs: [],
|
|
3232
|
+
name: "totalSupply",
|
|
3233
|
+
outputs: [
|
|
3234
|
+
{
|
|
3235
|
+
internalType: "uint256",
|
|
3236
|
+
name: "",
|
|
3237
|
+
type: "uint256"
|
|
3238
|
+
}
|
|
3239
|
+
],
|
|
3240
|
+
stateMutability: "view",
|
|
3241
|
+
type: "function"
|
|
3242
|
+
},
|
|
3243
|
+
{
|
|
3244
|
+
inputs: [
|
|
3245
|
+
{
|
|
3246
|
+
internalType: "address",
|
|
3247
|
+
name: "recipient",
|
|
3248
|
+
type: "address"
|
|
3249
|
+
},
|
|
3250
|
+
{
|
|
3251
|
+
internalType: "uint256",
|
|
3252
|
+
name: "amount",
|
|
3253
|
+
type: "uint256"
|
|
3254
|
+
}
|
|
3255
|
+
],
|
|
3256
|
+
name: "transfer",
|
|
3257
|
+
outputs: [
|
|
3258
|
+
{
|
|
3259
|
+
internalType: "bool",
|
|
3260
|
+
name: "",
|
|
3261
|
+
type: "bool"
|
|
3262
|
+
}
|
|
3263
|
+
],
|
|
3264
|
+
stateMutability: "nonpayable",
|
|
3265
|
+
type: "function"
|
|
3266
|
+
},
|
|
3267
|
+
{
|
|
3268
|
+
inputs: [
|
|
3269
|
+
{
|
|
3270
|
+
internalType: "address",
|
|
3271
|
+
name: "sender",
|
|
3272
|
+
type: "address"
|
|
3273
|
+
},
|
|
3274
|
+
{
|
|
3275
|
+
internalType: "address",
|
|
3276
|
+
name: "recipient",
|
|
3277
|
+
type: "address"
|
|
3278
|
+
},
|
|
3279
|
+
{
|
|
3280
|
+
internalType: "uint256",
|
|
3281
|
+
name: "amount",
|
|
3282
|
+
type: "uint256"
|
|
3283
|
+
}
|
|
3284
|
+
],
|
|
3285
|
+
name: "transferFrom",
|
|
3286
|
+
outputs: [
|
|
3287
|
+
{
|
|
3288
|
+
internalType: "bool",
|
|
3289
|
+
name: "",
|
|
3290
|
+
type: "bool"
|
|
3291
|
+
}
|
|
3292
|
+
],
|
|
3293
|
+
stateMutability: "nonpayable",
|
|
3294
|
+
type: "function"
|
|
3295
|
+
}
|
|
3296
|
+
];
|
|
3297
|
+
|
|
3298
|
+
// src/wallet/abis/stagingVaultAbi.json
|
|
3299
|
+
var stagingVaultAbi_default = [
|
|
3300
|
+
{
|
|
3301
|
+
inputs: [],
|
|
3302
|
+
stateMutability: "nonpayable",
|
|
3303
|
+
type: "constructor"
|
|
3304
|
+
},
|
|
3305
|
+
{
|
|
3306
|
+
inputs: [],
|
|
3307
|
+
name: "AccountIdInvalid",
|
|
3308
|
+
type: "error"
|
|
3309
|
+
},
|
|
3310
|
+
{
|
|
3311
|
+
inputs: [
|
|
3312
|
+
{
|
|
3313
|
+
internalType: "uint256",
|
|
3314
|
+
name: "balance",
|
|
3315
|
+
type: "uint256"
|
|
3316
|
+
},
|
|
3317
|
+
{
|
|
3318
|
+
internalType: "uint128",
|
|
3319
|
+
name: "amount",
|
|
3320
|
+
type: "uint128"
|
|
3321
|
+
}
|
|
3322
|
+
],
|
|
3323
|
+
name: "BalanceNotEnough",
|
|
3324
|
+
type: "error"
|
|
3325
|
+
},
|
|
3326
|
+
{
|
|
3327
|
+
inputs: [],
|
|
3328
|
+
name: "BrokerNotAllowed",
|
|
3329
|
+
type: "error"
|
|
3330
|
+
},
|
|
3331
|
+
{
|
|
3332
|
+
inputs: [],
|
|
3333
|
+
name: "OnlyCrossChainManagerCanCall",
|
|
3334
|
+
type: "error"
|
|
3335
|
+
},
|
|
3336
|
+
{
|
|
3337
|
+
inputs: [],
|
|
3338
|
+
name: "TokenNotAllowed",
|
|
3339
|
+
type: "error"
|
|
3340
|
+
},
|
|
3341
|
+
{
|
|
3342
|
+
anonymous: false,
|
|
3343
|
+
inputs: [
|
|
3344
|
+
{
|
|
3345
|
+
indexed: true,
|
|
3346
|
+
internalType: "bytes32",
|
|
3347
|
+
name: "accountId",
|
|
3348
|
+
type: "bytes32"
|
|
3349
|
+
},
|
|
3350
|
+
{
|
|
3351
|
+
indexed: true,
|
|
3352
|
+
internalType: "address",
|
|
3353
|
+
name: "userAddress",
|
|
3354
|
+
type: "address"
|
|
3355
|
+
},
|
|
3356
|
+
{
|
|
3357
|
+
indexed: true,
|
|
3358
|
+
internalType: "uint64",
|
|
3359
|
+
name: "depositNonce",
|
|
3360
|
+
type: "uint64"
|
|
3361
|
+
},
|
|
3362
|
+
{
|
|
3363
|
+
indexed: false,
|
|
3364
|
+
internalType: "bytes32",
|
|
3365
|
+
name: "tokenHash",
|
|
3366
|
+
type: "bytes32"
|
|
3367
|
+
},
|
|
3368
|
+
{
|
|
3369
|
+
indexed: false,
|
|
3370
|
+
internalType: "uint128",
|
|
3371
|
+
name: "tokenAmount",
|
|
3372
|
+
type: "uint128"
|
|
3373
|
+
}
|
|
3374
|
+
],
|
|
3375
|
+
name: "AccountDeposit",
|
|
3376
|
+
type: "event"
|
|
3377
|
+
},
|
|
3378
|
+
{
|
|
3379
|
+
anonymous: false,
|
|
3380
|
+
inputs: [
|
|
3381
|
+
{
|
|
3382
|
+
indexed: true,
|
|
3383
|
+
internalType: "bytes32",
|
|
3384
|
+
name: "accountId",
|
|
3385
|
+
type: "bytes32"
|
|
3386
|
+
},
|
|
3387
|
+
{
|
|
3388
|
+
indexed: true,
|
|
3389
|
+
internalType: "address",
|
|
3390
|
+
name: "userAddress",
|
|
3391
|
+
type: "address"
|
|
3392
|
+
},
|
|
3393
|
+
{
|
|
3394
|
+
indexed: true,
|
|
3395
|
+
internalType: "uint64",
|
|
3396
|
+
name: "depositNonce",
|
|
3397
|
+
type: "uint64"
|
|
3398
|
+
},
|
|
3399
|
+
{
|
|
3400
|
+
indexed: false,
|
|
3401
|
+
internalType: "bytes32",
|
|
3402
|
+
name: "tokenHash",
|
|
3403
|
+
type: "bytes32"
|
|
3404
|
+
},
|
|
3405
|
+
{
|
|
3406
|
+
indexed: false,
|
|
3407
|
+
internalType: "uint128",
|
|
3408
|
+
name: "tokenAmount",
|
|
3409
|
+
type: "uint128"
|
|
3410
|
+
}
|
|
3411
|
+
],
|
|
3412
|
+
name: "AccountDepositTo",
|
|
3413
|
+
type: "event"
|
|
3414
|
+
},
|
|
3415
|
+
{
|
|
3416
|
+
anonymous: false,
|
|
3417
|
+
inputs: [
|
|
3418
|
+
{
|
|
3419
|
+
indexed: true,
|
|
3420
|
+
internalType: "bytes32",
|
|
3421
|
+
name: "accountId",
|
|
3422
|
+
type: "bytes32"
|
|
3423
|
+
},
|
|
3424
|
+
{
|
|
3425
|
+
indexed: true,
|
|
3426
|
+
internalType: "uint64",
|
|
3427
|
+
name: "withdrawNonce",
|
|
3428
|
+
type: "uint64"
|
|
3429
|
+
},
|
|
3430
|
+
{
|
|
3431
|
+
indexed: false,
|
|
3432
|
+
internalType: "bytes32",
|
|
3433
|
+
name: "brokerHash",
|
|
3434
|
+
type: "bytes32"
|
|
3435
|
+
},
|
|
3436
|
+
{
|
|
3437
|
+
indexed: false,
|
|
3438
|
+
internalType: "address",
|
|
3439
|
+
name: "sender",
|
|
3440
|
+
type: "address"
|
|
3441
|
+
},
|
|
3442
|
+
{
|
|
3443
|
+
indexed: false,
|
|
3444
|
+
internalType: "address",
|
|
3445
|
+
name: "receiver",
|
|
3446
|
+
type: "address"
|
|
3447
|
+
},
|
|
3448
|
+
{
|
|
3449
|
+
indexed: false,
|
|
3450
|
+
internalType: "bytes32",
|
|
3451
|
+
name: "tokenHash",
|
|
3452
|
+
type: "bytes32"
|
|
3453
|
+
},
|
|
3454
|
+
{
|
|
3455
|
+
indexed: false,
|
|
3456
|
+
internalType: "uint128",
|
|
3457
|
+
name: "tokenAmount",
|
|
3458
|
+
type: "uint128"
|
|
3459
|
+
},
|
|
3460
|
+
{
|
|
3461
|
+
indexed: false,
|
|
3462
|
+
internalType: "uint128",
|
|
3463
|
+
name: "fee",
|
|
3464
|
+
type: "uint128"
|
|
3465
|
+
},
|
|
3466
|
+
{
|
|
3467
|
+
indexed: false,
|
|
3468
|
+
internalType: "uint256",
|
|
3469
|
+
name: "blocktime",
|
|
3470
|
+
type: "uint256"
|
|
3471
|
+
}
|
|
3472
|
+
],
|
|
3473
|
+
name: "AccountWithdraw",
|
|
3474
|
+
type: "event"
|
|
3475
|
+
},
|
|
3476
|
+
{
|
|
3477
|
+
anonymous: false,
|
|
3478
|
+
inputs: [
|
|
3479
|
+
{
|
|
3480
|
+
indexed: true,
|
|
3481
|
+
internalType: "bytes32",
|
|
3482
|
+
name: "_tokenHash",
|
|
3483
|
+
type: "bytes32"
|
|
3484
|
+
},
|
|
3485
|
+
{
|
|
3486
|
+
indexed: false,
|
|
3487
|
+
internalType: "address",
|
|
3488
|
+
name: "_tokenAddress",
|
|
3489
|
+
type: "address"
|
|
3490
|
+
}
|
|
3491
|
+
],
|
|
3492
|
+
name: "ChangeTokenAddressAndAllow",
|
|
3493
|
+
type: "event"
|
|
3494
|
+
},
|
|
3495
|
+
{
|
|
3496
|
+
anonymous: false,
|
|
3497
|
+
inputs: [
|
|
3498
|
+
{
|
|
3499
|
+
indexed: false,
|
|
3500
|
+
internalType: "uint8",
|
|
3501
|
+
name: "version",
|
|
3502
|
+
type: "uint8"
|
|
3503
|
+
}
|
|
3504
|
+
],
|
|
3505
|
+
name: "Initialized",
|
|
3506
|
+
type: "event"
|
|
3507
|
+
},
|
|
3508
|
+
{
|
|
3509
|
+
anonymous: false,
|
|
3510
|
+
inputs: [
|
|
3511
|
+
{
|
|
3512
|
+
indexed: true,
|
|
3513
|
+
internalType: "address",
|
|
3514
|
+
name: "previousOwner",
|
|
3515
|
+
type: "address"
|
|
3516
|
+
},
|
|
3517
|
+
{
|
|
3518
|
+
indexed: true,
|
|
3519
|
+
internalType: "address",
|
|
3520
|
+
name: "newOwner",
|
|
3521
|
+
type: "address"
|
|
3522
|
+
}
|
|
3523
|
+
],
|
|
3524
|
+
name: "OwnershipTransferred",
|
|
3525
|
+
type: "event"
|
|
3526
|
+
},
|
|
3527
|
+
{
|
|
3528
|
+
anonymous: false,
|
|
3529
|
+
inputs: [
|
|
3530
|
+
{
|
|
3531
|
+
indexed: false,
|
|
3532
|
+
internalType: "address",
|
|
3533
|
+
name: "account",
|
|
3534
|
+
type: "address"
|
|
3535
|
+
}
|
|
3536
|
+
],
|
|
3537
|
+
name: "Paused",
|
|
3538
|
+
type: "event"
|
|
3539
|
+
},
|
|
3540
|
+
{
|
|
3541
|
+
anonymous: false,
|
|
3542
|
+
inputs: [
|
|
3543
|
+
{
|
|
3544
|
+
indexed: true,
|
|
3545
|
+
internalType: "bytes32",
|
|
3546
|
+
name: "_brokerHash",
|
|
3547
|
+
type: "bytes32"
|
|
3548
|
+
},
|
|
3549
|
+
{
|
|
3550
|
+
indexed: false,
|
|
3551
|
+
internalType: "bool",
|
|
3552
|
+
name: "_allowed",
|
|
3553
|
+
type: "bool"
|
|
3554
|
+
}
|
|
3555
|
+
],
|
|
3556
|
+
name: "SetAllowedBroker",
|
|
3557
|
+
type: "event"
|
|
3558
|
+
},
|
|
3559
|
+
{
|
|
3560
|
+
anonymous: false,
|
|
3561
|
+
inputs: [
|
|
3562
|
+
{
|
|
3563
|
+
indexed: true,
|
|
3564
|
+
internalType: "bytes32",
|
|
3565
|
+
name: "_tokenHash",
|
|
3566
|
+
type: "bytes32"
|
|
3567
|
+
},
|
|
3568
|
+
{
|
|
3569
|
+
indexed: false,
|
|
3570
|
+
internalType: "bool",
|
|
3571
|
+
name: "_allowed",
|
|
3572
|
+
type: "bool"
|
|
3573
|
+
}
|
|
3574
|
+
],
|
|
3575
|
+
name: "SetAllowedToken",
|
|
3576
|
+
type: "event"
|
|
3577
|
+
},
|
|
3578
|
+
{
|
|
3579
|
+
anonymous: false,
|
|
3580
|
+
inputs: [
|
|
3581
|
+
{
|
|
3582
|
+
indexed: false,
|
|
3583
|
+
internalType: "address",
|
|
3584
|
+
name: "account",
|
|
3585
|
+
type: "address"
|
|
3586
|
+
}
|
|
3587
|
+
],
|
|
3588
|
+
name: "Unpaused",
|
|
3589
|
+
type: "event"
|
|
3590
|
+
},
|
|
3591
|
+
{
|
|
3592
|
+
inputs: [
|
|
3593
|
+
{
|
|
3594
|
+
internalType: "bytes32",
|
|
3595
|
+
name: "",
|
|
3596
|
+
type: "bytes32"
|
|
3597
|
+
}
|
|
3598
|
+
],
|
|
3599
|
+
name: "allowedToken",
|
|
3600
|
+
outputs: [
|
|
3601
|
+
{
|
|
3602
|
+
internalType: "address",
|
|
3603
|
+
name: "",
|
|
3604
|
+
type: "address"
|
|
3605
|
+
}
|
|
3606
|
+
],
|
|
3607
|
+
stateMutability: "view",
|
|
3608
|
+
type: "function"
|
|
3609
|
+
},
|
|
3610
|
+
{
|
|
3611
|
+
inputs: [
|
|
3612
|
+
{
|
|
3613
|
+
internalType: "bytes32",
|
|
3614
|
+
name: "_tokenHash",
|
|
3615
|
+
type: "bytes32"
|
|
3616
|
+
},
|
|
3617
|
+
{
|
|
3618
|
+
internalType: "address",
|
|
3619
|
+
name: "_tokenAddress",
|
|
3620
|
+
type: "address"
|
|
3621
|
+
}
|
|
3622
|
+
],
|
|
3623
|
+
name: "changeTokenAddressAndAllow",
|
|
3624
|
+
outputs: [],
|
|
3625
|
+
stateMutability: "nonpayable",
|
|
3626
|
+
type: "function"
|
|
3627
|
+
},
|
|
3628
|
+
{
|
|
3629
|
+
inputs: [],
|
|
3630
|
+
name: "crossChainManagerAddress",
|
|
3631
|
+
outputs: [
|
|
3632
|
+
{
|
|
3633
|
+
internalType: "address",
|
|
3634
|
+
name: "",
|
|
3635
|
+
type: "address"
|
|
3636
|
+
}
|
|
3637
|
+
],
|
|
3638
|
+
stateMutability: "view",
|
|
3639
|
+
type: "function"
|
|
3640
|
+
},
|
|
3641
|
+
{
|
|
3642
|
+
inputs: [
|
|
3643
|
+
{
|
|
3644
|
+
components: [
|
|
3645
|
+
{
|
|
3646
|
+
internalType: "bytes32",
|
|
3647
|
+
name: "accountId",
|
|
3648
|
+
type: "bytes32"
|
|
3649
|
+
},
|
|
3650
|
+
{
|
|
3651
|
+
internalType: "bytes32",
|
|
3652
|
+
name: "brokerHash",
|
|
3653
|
+
type: "bytes32"
|
|
3654
|
+
},
|
|
3655
|
+
{
|
|
3656
|
+
internalType: "bytes32",
|
|
3657
|
+
name: "tokenHash",
|
|
3658
|
+
type: "bytes32"
|
|
3659
|
+
},
|
|
3660
|
+
{
|
|
3661
|
+
internalType: "uint128",
|
|
3662
|
+
name: "tokenAmount",
|
|
3663
|
+
type: "uint128"
|
|
3664
|
+
}
|
|
3665
|
+
],
|
|
3666
|
+
internalType: "struct VaultTypes.VaultDepositFE",
|
|
3667
|
+
name: "data",
|
|
3668
|
+
type: "tuple"
|
|
3669
|
+
}
|
|
3670
|
+
],
|
|
3671
|
+
name: "deposit",
|
|
3672
|
+
outputs: [],
|
|
3673
|
+
stateMutability: "nonpayable",
|
|
3674
|
+
type: "function"
|
|
3675
|
+
},
|
|
3676
|
+
{
|
|
3677
|
+
inputs: [],
|
|
3678
|
+
name: "depositId",
|
|
3679
|
+
outputs: [
|
|
3680
|
+
{
|
|
3681
|
+
internalType: "uint64",
|
|
3682
|
+
name: "",
|
|
3683
|
+
type: "uint64"
|
|
3684
|
+
}
|
|
3685
|
+
],
|
|
3686
|
+
stateMutability: "view",
|
|
3687
|
+
type: "function"
|
|
3688
|
+
},
|
|
3689
|
+
{
|
|
3690
|
+
inputs: [
|
|
3691
|
+
{
|
|
3692
|
+
internalType: "address",
|
|
3693
|
+
name: "receiver",
|
|
3694
|
+
type: "address"
|
|
3695
|
+
},
|
|
3696
|
+
{
|
|
3697
|
+
components: [
|
|
3698
|
+
{
|
|
3699
|
+
internalType: "bytes32",
|
|
3700
|
+
name: "accountId",
|
|
3701
|
+
type: "bytes32"
|
|
3702
|
+
},
|
|
3703
|
+
{
|
|
3704
|
+
internalType: "bytes32",
|
|
3705
|
+
name: "brokerHash",
|
|
3706
|
+
type: "bytes32"
|
|
3707
|
+
},
|
|
3708
|
+
{
|
|
3709
|
+
internalType: "bytes32",
|
|
3710
|
+
name: "tokenHash",
|
|
3711
|
+
type: "bytes32"
|
|
3712
|
+
},
|
|
3713
|
+
{
|
|
3714
|
+
internalType: "uint128",
|
|
3715
|
+
name: "tokenAmount",
|
|
3716
|
+
type: "uint128"
|
|
3717
|
+
}
|
|
3718
|
+
],
|
|
3719
|
+
internalType: "struct VaultTypes.VaultDepositFE",
|
|
3720
|
+
name: "data",
|
|
3721
|
+
type: "tuple"
|
|
3722
|
+
}
|
|
3723
|
+
],
|
|
3724
|
+
name: "depositTo",
|
|
3725
|
+
outputs: [],
|
|
3726
|
+
stateMutability: "nonpayable",
|
|
3727
|
+
type: "function"
|
|
3728
|
+
},
|
|
3729
|
+
{
|
|
3730
|
+
inputs: [],
|
|
3731
|
+
name: "emergencyPause",
|
|
3732
|
+
outputs: [],
|
|
3733
|
+
stateMutability: "nonpayable",
|
|
3734
|
+
type: "function"
|
|
3735
|
+
},
|
|
3736
|
+
{
|
|
3737
|
+
inputs: [],
|
|
3738
|
+
name: "emergencyUnpause",
|
|
3739
|
+
outputs: [],
|
|
3740
|
+
stateMutability: "nonpayable",
|
|
3741
|
+
type: "function"
|
|
3742
|
+
},
|
|
3743
|
+
{
|
|
3744
|
+
inputs: [],
|
|
3745
|
+
name: "getAllAllowedBroker",
|
|
3746
|
+
outputs: [
|
|
3747
|
+
{
|
|
3748
|
+
internalType: "bytes32[]",
|
|
3749
|
+
name: "",
|
|
3750
|
+
type: "bytes32[]"
|
|
3751
|
+
}
|
|
3752
|
+
],
|
|
3753
|
+
stateMutability: "view",
|
|
3754
|
+
type: "function"
|
|
3755
|
+
},
|
|
3756
|
+
{
|
|
3757
|
+
inputs: [],
|
|
3758
|
+
name: "getAllAllowedToken",
|
|
3759
|
+
outputs: [
|
|
3760
|
+
{
|
|
3761
|
+
internalType: "bytes32[]",
|
|
3762
|
+
name: "",
|
|
3763
|
+
type: "bytes32[]"
|
|
3764
|
+
}
|
|
3765
|
+
],
|
|
3766
|
+
stateMutability: "view",
|
|
3767
|
+
type: "function"
|
|
3768
|
+
},
|
|
3769
|
+
{
|
|
3770
|
+
inputs: [
|
|
3771
|
+
{
|
|
3772
|
+
internalType: "bytes32",
|
|
3773
|
+
name: "_brokerHash",
|
|
3774
|
+
type: "bytes32"
|
|
3775
|
+
}
|
|
3776
|
+
],
|
|
3777
|
+
name: "getAllowedBroker",
|
|
3778
|
+
outputs: [
|
|
3779
|
+
{
|
|
3780
|
+
internalType: "bool",
|
|
3781
|
+
name: "",
|
|
3782
|
+
type: "bool"
|
|
3783
|
+
}
|
|
3784
|
+
],
|
|
3785
|
+
stateMutability: "view",
|
|
3786
|
+
type: "function"
|
|
3787
|
+
},
|
|
3788
|
+
{
|
|
3789
|
+
inputs: [
|
|
3790
|
+
{
|
|
3791
|
+
internalType: "bytes32",
|
|
3792
|
+
name: "_tokenHash",
|
|
3793
|
+
type: "bytes32"
|
|
3794
|
+
}
|
|
3795
|
+
],
|
|
3796
|
+
name: "getAllowedToken",
|
|
3797
|
+
outputs: [
|
|
3798
|
+
{
|
|
3799
|
+
internalType: "address",
|
|
3800
|
+
name: "",
|
|
3801
|
+
type: "address"
|
|
3802
|
+
}
|
|
3803
|
+
],
|
|
3804
|
+
stateMutability: "view",
|
|
3805
|
+
type: "function"
|
|
3806
|
+
},
|
|
3807
|
+
{
|
|
3808
|
+
inputs: [],
|
|
3809
|
+
name: "initialize",
|
|
3810
|
+
outputs: [],
|
|
3811
|
+
stateMutability: "nonpayable",
|
|
3812
|
+
type: "function"
|
|
3813
|
+
},
|
|
3814
|
+
{
|
|
3815
|
+
inputs: [],
|
|
3816
|
+
name: "owner",
|
|
3817
|
+
outputs: [
|
|
3818
|
+
{
|
|
3819
|
+
internalType: "address",
|
|
3820
|
+
name: "",
|
|
3821
|
+
type: "address"
|
|
3822
|
+
}
|
|
3823
|
+
],
|
|
3824
|
+
stateMutability: "view",
|
|
3825
|
+
type: "function"
|
|
3826
|
+
},
|
|
3827
|
+
{
|
|
3828
|
+
inputs: [],
|
|
3829
|
+
name: "paused",
|
|
3830
|
+
outputs: [
|
|
3831
|
+
{
|
|
3832
|
+
internalType: "bool",
|
|
3833
|
+
name: "",
|
|
3834
|
+
type: "bool"
|
|
3835
|
+
}
|
|
3836
|
+
],
|
|
3837
|
+
stateMutability: "view",
|
|
3838
|
+
type: "function"
|
|
3839
|
+
},
|
|
3840
|
+
{
|
|
3841
|
+
inputs: [],
|
|
3842
|
+
name: "renounceOwnership",
|
|
3843
|
+
outputs: [],
|
|
3844
|
+
stateMutability: "nonpayable",
|
|
3845
|
+
type: "function"
|
|
3846
|
+
},
|
|
3847
|
+
{
|
|
3848
|
+
inputs: [
|
|
3849
|
+
{
|
|
3850
|
+
internalType: "bytes32",
|
|
3851
|
+
name: "_brokerHash",
|
|
3852
|
+
type: "bytes32"
|
|
3853
|
+
},
|
|
3854
|
+
{
|
|
3855
|
+
internalType: "bool",
|
|
3856
|
+
name: "_allowed",
|
|
3857
|
+
type: "bool"
|
|
3858
|
+
}
|
|
3859
|
+
],
|
|
3860
|
+
name: "setAllowedBroker",
|
|
3861
|
+
outputs: [],
|
|
3862
|
+
stateMutability: "nonpayable",
|
|
3863
|
+
type: "function"
|
|
3864
|
+
},
|
|
3865
|
+
{
|
|
3866
|
+
inputs: [
|
|
3867
|
+
{
|
|
3868
|
+
internalType: "bytes32",
|
|
3869
|
+
name: "_tokenHash",
|
|
3870
|
+
type: "bytes32"
|
|
3871
|
+
},
|
|
3872
|
+
{
|
|
3873
|
+
internalType: "bool",
|
|
3874
|
+
name: "_allowed",
|
|
3875
|
+
type: "bool"
|
|
3876
|
+
}
|
|
3877
|
+
],
|
|
3878
|
+
name: "setAllowedToken",
|
|
3879
|
+
outputs: [],
|
|
3880
|
+
stateMutability: "nonpayable",
|
|
3881
|
+
type: "function"
|
|
3882
|
+
},
|
|
3883
|
+
{
|
|
3884
|
+
inputs: [
|
|
3885
|
+
{
|
|
3886
|
+
internalType: "address",
|
|
3887
|
+
name: "_crossChainManagerAddress",
|
|
3888
|
+
type: "address"
|
|
3889
|
+
}
|
|
3890
|
+
],
|
|
3891
|
+
name: "setCrossChainManager",
|
|
3892
|
+
outputs: [],
|
|
3893
|
+
stateMutability: "nonpayable",
|
|
3894
|
+
type: "function"
|
|
3895
|
+
},
|
|
3896
|
+
{
|
|
3897
|
+
inputs: [
|
|
3898
|
+
{
|
|
3899
|
+
internalType: "address",
|
|
3900
|
+
name: "newOwner",
|
|
3901
|
+
type: "address"
|
|
3902
|
+
}
|
|
3903
|
+
],
|
|
3904
|
+
name: "transferOwnership",
|
|
3905
|
+
outputs: [],
|
|
3906
|
+
stateMutability: "nonpayable",
|
|
3907
|
+
type: "function"
|
|
3908
|
+
},
|
|
3909
|
+
{
|
|
3910
|
+
inputs: [
|
|
3911
|
+
{
|
|
3912
|
+
components: [
|
|
3913
|
+
{
|
|
3914
|
+
internalType: "bytes32",
|
|
3915
|
+
name: "accountId",
|
|
3916
|
+
type: "bytes32"
|
|
3917
|
+
},
|
|
3918
|
+
{
|
|
3919
|
+
internalType: "bytes32",
|
|
3920
|
+
name: "brokerHash",
|
|
3921
|
+
type: "bytes32"
|
|
3922
|
+
},
|
|
3923
|
+
{
|
|
3924
|
+
internalType: "bytes32",
|
|
3925
|
+
name: "tokenHash",
|
|
3926
|
+
type: "bytes32"
|
|
3927
|
+
},
|
|
3928
|
+
{
|
|
3929
|
+
internalType: "uint128",
|
|
3930
|
+
name: "tokenAmount",
|
|
3931
|
+
type: "uint128"
|
|
3932
|
+
},
|
|
3933
|
+
{
|
|
3934
|
+
internalType: "uint128",
|
|
3935
|
+
name: "fee",
|
|
3936
|
+
type: "uint128"
|
|
3937
|
+
},
|
|
3938
|
+
{
|
|
3939
|
+
internalType: "address",
|
|
3940
|
+
name: "sender",
|
|
3941
|
+
type: "address"
|
|
3942
|
+
},
|
|
3943
|
+
{
|
|
3944
|
+
internalType: "address",
|
|
3945
|
+
name: "receiver",
|
|
3946
|
+
type: "address"
|
|
3947
|
+
},
|
|
3948
|
+
{
|
|
3949
|
+
internalType: "uint64",
|
|
3950
|
+
name: "withdrawNonce",
|
|
3951
|
+
type: "uint64"
|
|
3952
|
+
}
|
|
3953
|
+
],
|
|
3954
|
+
internalType: "struct VaultTypes.VaultWithdraw",
|
|
3955
|
+
name: "data",
|
|
3956
|
+
type: "tuple"
|
|
3957
|
+
}
|
|
3958
|
+
],
|
|
3959
|
+
name: "withdraw",
|
|
3960
|
+
outputs: [],
|
|
3961
|
+
stateMutability: "nonpayable",
|
|
3962
|
+
type: "function"
|
|
3963
|
+
}
|
|
3964
|
+
];
|
|
3965
|
+
|
|
3966
|
+
// src/contract.ts
|
|
3967
|
+
var BaseContract = class {
|
|
3968
|
+
constructor(configStore) {
|
|
3969
|
+
this.configStore = configStore;
|
|
3970
|
+
}
|
|
3971
|
+
getContractInfoByEnv() {
|
|
3972
|
+
return {
|
|
3973
|
+
usdcAddress: stagingUSDCAddressOnArbitrumTestnet,
|
|
3974
|
+
usdcAbi: stagingUSDCAbi_default,
|
|
3975
|
+
vaultAddress: stagingVaultAddressOnArbitrumTestnet,
|
|
3976
|
+
vaultAbi: stagingVaultAbi_default,
|
|
3977
|
+
verifyContractAddress: stagingVerifyAddressOnArbitrumTestnet
|
|
3978
|
+
};
|
|
3979
|
+
}
|
|
3980
|
+
};
|
|
3981
|
+
|
|
3982
|
+
// src/di/simpleDI.ts
|
|
3983
|
+
init_dirname();
|
|
3984
|
+
init_buffer2();
|
|
3985
|
+
init_process2();
|
|
3986
|
+
|
|
3987
|
+
// src/di/container.ts
|
|
3988
|
+
init_dirname();
|
|
3989
|
+
init_buffer2();
|
|
3990
|
+
init_process2();
|
|
3991
|
+
var Container = class {
|
|
3992
|
+
constructor(providers = [], services = {}) {
|
|
3993
|
+
this.providers = providers;
|
|
3994
|
+
this.services = services;
|
|
3995
|
+
this.injectProperties = {};
|
|
3996
|
+
}
|
|
3997
|
+
register(...serviceClasses) {
|
|
3998
|
+
this.providers.push(...serviceClasses);
|
|
3999
|
+
serviceClasses.forEach((serviceClass) => {
|
|
4000
|
+
let service = serviceClass;
|
|
4001
|
+
if (service instanceof Function) {
|
|
4002
|
+
service = new serviceClass();
|
|
4003
|
+
}
|
|
4004
|
+
this.add(service);
|
|
4005
|
+
});
|
|
4006
|
+
}
|
|
4007
|
+
registerByName(name, serviceClass) {
|
|
4008
|
+
let service = serviceClass;
|
|
4009
|
+
if (service instanceof Function) {
|
|
4010
|
+
service = new serviceClass();
|
|
4011
|
+
}
|
|
4012
|
+
this.addByName(name, service);
|
|
4013
|
+
}
|
|
4014
|
+
get(name) {
|
|
4015
|
+
return this.services[name];
|
|
4016
|
+
}
|
|
4017
|
+
//
|
|
4018
|
+
// getByType<T>(c: new (...args: any[]) => T): T {
|
|
4019
|
+
// return this.get<T>(c.name.toLowerCase());
|
|
4020
|
+
// }
|
|
4021
|
+
getAll() {
|
|
4022
|
+
return Object.assign({}, this.services);
|
|
4023
|
+
}
|
|
4024
|
+
// addInjectProperty(target: any, propertyKey: string, serviceName: string = propertyKey): void {
|
|
4025
|
+
// if (target) {
|
|
4026
|
+
// this.getInjectProperty(serviceName.toLowerCase()).push({ target, propertyKey, serviceName });
|
|
4027
|
+
// this.inject(target, propertyKey, this.services[serviceName.toLowerCase()]);
|
|
4028
|
+
// }
|
|
4029
|
+
// }
|
|
4030
|
+
add(service) {
|
|
4031
|
+
return this.addByName(service.constructor.name, service);
|
|
4032
|
+
}
|
|
4033
|
+
// //
|
|
4034
|
+
addByName(name, service) {
|
|
4035
|
+
this.services[name] = service;
|
|
4036
|
+
this.services[name.toLowerCase()] = service;
|
|
4037
|
+
this.injectIntoProperties(service, name);
|
|
4038
|
+
return this.get(name);
|
|
4039
|
+
}
|
|
4040
|
+
inject(target, propertyKey, service) {
|
|
4041
|
+
if (target && service) {
|
|
4042
|
+
target[propertyKey] = service;
|
|
4043
|
+
}
|
|
4044
|
+
}
|
|
4045
|
+
injectIntoProperties(service, name = service.constructor.name) {
|
|
4046
|
+
this.getInjectProperty(name.toLowerCase()).forEach((property) => {
|
|
4047
|
+
this.inject(property.target, property.propertyKey, service);
|
|
4048
|
+
});
|
|
4049
|
+
}
|
|
4050
|
+
//
|
|
4051
|
+
getInjectProperty(key) {
|
|
4052
|
+
if (!this.injectProperties[key]) {
|
|
4053
|
+
this.injectProperties[key] = [];
|
|
4054
|
+
}
|
|
4055
|
+
return this.injectProperties[key];
|
|
4056
|
+
}
|
|
4057
|
+
};
|
|
4058
|
+
var container_default = Container;
|
|
4059
|
+
|
|
4060
|
+
// src/di/simpleDI.ts
|
|
4061
|
+
var SimpleDI = class _SimpleDI {
|
|
4062
|
+
static getContainer() {
|
|
4063
|
+
if (!_SimpleDI.container) {
|
|
4064
|
+
_SimpleDI.container = new container_default();
|
|
4065
|
+
}
|
|
4066
|
+
return _SimpleDI.container;
|
|
4067
|
+
}
|
|
4068
|
+
static register(...serviceClasses) {
|
|
4069
|
+
this.getContainer().register(...serviceClasses);
|
|
4070
|
+
}
|
|
4071
|
+
static registerByName(name, serviceClass) {
|
|
4072
|
+
this.getContainer().registerByName(name, serviceClass);
|
|
4073
|
+
}
|
|
4074
|
+
// static addInjectProperty(target: any, propertyKey: string, serviceName: string = propertyKey): void {
|
|
4075
|
+
// this.getContainer().addInjectProperty(target, propertyKey, serviceName);
|
|
4076
|
+
// }
|
|
4077
|
+
static get(name) {
|
|
4078
|
+
return this.getContainer().get(name);
|
|
4079
|
+
}
|
|
4080
|
+
// static getByType<T>(c: new (...args: any[]) => T): T {
|
|
4081
|
+
// return this.getContainer().getByType(c);
|
|
4082
|
+
// }
|
|
4083
|
+
static getAll() {
|
|
4084
|
+
return this.getContainer().getAll();
|
|
4085
|
+
}
|
|
4086
|
+
constructor() {
|
|
4087
|
+
}
|
|
4088
|
+
};
|
|
4089
|
+
var simpleDI_default = SimpleDI;
|
|
4090
|
+
|
|
4091
|
+
// src/account.ts
|
|
4092
|
+
init_dirname();
|
|
4093
|
+
init_buffer2();
|
|
4094
|
+
init_process2();
|
|
4095
|
+
var import_types = require("@orderly.network/types");
|
|
4096
|
+
var import_eventemitter3 = __toESM(require("eventemitter3"));
|
|
4097
|
+
|
|
4098
|
+
// src/assets.ts
|
|
4099
|
+
init_dirname();
|
|
4100
|
+
init_buffer2();
|
|
4101
|
+
init_process2();
|
|
4102
|
+
var import_ethers2 = require("ethers");
|
|
4103
|
+
var Assets = class {
|
|
4104
|
+
constructor(configStore, contractManger, account) {
|
|
4105
|
+
this.configStore = configStore;
|
|
4106
|
+
this.contractManger = contractManger;
|
|
4107
|
+
this.account = account;
|
|
4108
|
+
}
|
|
4109
|
+
async withdraw(inputs) {
|
|
4110
|
+
if (!this.account.walletClient) {
|
|
4111
|
+
throw new Error("walletClient is undefined");
|
|
4112
|
+
}
|
|
4113
|
+
if (!this.account.stateValue.address)
|
|
4114
|
+
throw new Error("account address is rqeuired");
|
|
4115
|
+
const { chainId, token, amount } = inputs;
|
|
4116
|
+
const url = "/v1/withdraw_request";
|
|
4117
|
+
const nonce = await this.getWithdrawalNonce();
|
|
4118
|
+
const domain = this.account.getDomain(true);
|
|
4119
|
+
const [message, toSignatureMessage] = this._generateWithdrawMessage({
|
|
4120
|
+
chainId,
|
|
4121
|
+
receiver: this.account.stateValue.address,
|
|
4122
|
+
token,
|
|
4123
|
+
amount: this.account.walletClient.parseUnits(amount.toString()),
|
|
4124
|
+
nonce,
|
|
4125
|
+
domain
|
|
4126
|
+
});
|
|
4127
|
+
const EIP_712signatured = await this.account.signTypedData(
|
|
4128
|
+
toSignatureMessage
|
|
4129
|
+
);
|
|
4130
|
+
const data = {
|
|
4131
|
+
signature: EIP_712signatured,
|
|
4132
|
+
message,
|
|
4133
|
+
userAddress: this.account.stateValue.address,
|
|
4134
|
+
verifyingContract: domain.verifyingContract
|
|
4135
|
+
};
|
|
4136
|
+
const payload = {
|
|
4137
|
+
method: "POST",
|
|
4138
|
+
url,
|
|
4139
|
+
data
|
|
4140
|
+
};
|
|
4141
|
+
const signature = await this.account.signer.sign(payload);
|
|
4142
|
+
const res = await this._simpleFetch(url, {
|
|
4143
|
+
method: "POST",
|
|
4144
|
+
body: JSON.stringify(data),
|
|
4145
|
+
headers: {
|
|
4146
|
+
"Content-Type": "application/json",
|
|
4147
|
+
"orderly-account-id": this.account.stateValue.accountId,
|
|
4148
|
+
...signature
|
|
4149
|
+
}
|
|
4150
|
+
});
|
|
4151
|
+
return res;
|
|
4152
|
+
}
|
|
4153
|
+
_generateWithdrawMessage(inputs) {
|
|
4154
|
+
const { chainId, receiver, token, amount, domain, nonce } = inputs;
|
|
4155
|
+
const primaryType = "Withdraw";
|
|
4156
|
+
const timestamp = Date.now();
|
|
4157
|
+
const typeDefinition = {
|
|
4158
|
+
EIP712Domain: definedTypes.EIP712Domain,
|
|
4159
|
+
[primaryType]: definedTypes[primaryType]
|
|
4160
|
+
};
|
|
4161
|
+
const message = {
|
|
4162
|
+
brokerId: this.configStore.get("brokerId"),
|
|
4163
|
+
chainId,
|
|
4164
|
+
receiver,
|
|
4165
|
+
token,
|
|
4166
|
+
amount,
|
|
4167
|
+
timestamp,
|
|
4168
|
+
withdrawNonce: nonce
|
|
4169
|
+
};
|
|
4170
|
+
const toSignatureMessage = {
|
|
4171
|
+
domain,
|
|
4172
|
+
message,
|
|
4173
|
+
primaryType,
|
|
4174
|
+
types: typeDefinition
|
|
4175
|
+
};
|
|
4176
|
+
return [message, toSignatureMessage];
|
|
4177
|
+
}
|
|
4178
|
+
async getWithdrawalNonce() {
|
|
4179
|
+
const timestamp = Date.now().toString();
|
|
4180
|
+
const url = "/v1/withdraw_nonce";
|
|
4181
|
+
const message = [timestamp, "GET", url].join("");
|
|
4182
|
+
const signer = this.account.signer;
|
|
4183
|
+
const { publicKey, signature } = await signer.signText(message);
|
|
4184
|
+
const res = await this._simpleFetch(url, {
|
|
4185
|
+
headers: {
|
|
4186
|
+
"orderly-account-id": this.account.stateValue.accountId,
|
|
4187
|
+
"orderly-key": publicKey,
|
|
4188
|
+
"orderly-timestamp": timestamp,
|
|
4189
|
+
"orderly-signature": signature
|
|
4190
|
+
}
|
|
4191
|
+
});
|
|
4192
|
+
if (res.success) {
|
|
4193
|
+
return res.data?.withdraw_nonce;
|
|
4194
|
+
} else {
|
|
4195
|
+
throw new Error(res.message);
|
|
4196
|
+
}
|
|
4197
|
+
}
|
|
4198
|
+
async getBalance() {
|
|
4199
|
+
if (!this.account.walletClient) {
|
|
4200
|
+
return "0";
|
|
4201
|
+
}
|
|
4202
|
+
const contractAddress = this.contractManger.getContractInfoByEnv();
|
|
4203
|
+
const result = await this.account.walletClient?.call(
|
|
4204
|
+
contractAddress.usdcAddress,
|
|
4205
|
+
"balanceOf",
|
|
4206
|
+
[this.account.stateValue.address],
|
|
4207
|
+
{
|
|
4208
|
+
abi: contractAddress.usdcAbi
|
|
4209
|
+
}
|
|
4210
|
+
);
|
|
4211
|
+
return this.account.walletClient?.fromUnits(result);
|
|
4212
|
+
}
|
|
4213
|
+
async getAllowance() {
|
|
4214
|
+
if (!this.account.walletClient) {
|
|
4215
|
+
return "0";
|
|
4216
|
+
}
|
|
4217
|
+
const contractAddress = this.contractManger.getContractInfoByEnv();
|
|
4218
|
+
const result = await this.account.walletClient?.call(
|
|
4219
|
+
contractAddress.usdcAddress,
|
|
4220
|
+
"allowance",
|
|
4221
|
+
[this.account.stateValue.address, contractAddress.vaultAddress],
|
|
4222
|
+
{
|
|
4223
|
+
abi: contractAddress.usdcAbi
|
|
4224
|
+
}
|
|
4225
|
+
);
|
|
4226
|
+
return this.account.walletClient?.fromUnits(result);
|
|
4227
|
+
}
|
|
4228
|
+
async approve(amount) {
|
|
4229
|
+
if (!this.account.walletClient) {
|
|
4230
|
+
throw new Error("walletClient is undefined");
|
|
4231
|
+
}
|
|
4232
|
+
const contractAddress = this.contractManger.getContractInfoByEnv();
|
|
4233
|
+
const parsedAmount = typeof amount !== "undefined" && amount !== "" ? this.account.walletClient.parseUnits(amount) : import_ethers2.ethers.MaxUint256.toString();
|
|
4234
|
+
const result = await this.account.walletClient?.call(
|
|
4235
|
+
contractAddress.usdcAddress,
|
|
4236
|
+
"approve",
|
|
4237
|
+
[contractAddress.vaultAddress, parsedAmount],
|
|
4238
|
+
{
|
|
4239
|
+
abi: contractAddress.usdcAbi
|
|
4240
|
+
}
|
|
4241
|
+
);
|
|
4242
|
+
console.log("-----*****-----", result);
|
|
4243
|
+
return result;
|
|
4244
|
+
}
|
|
4245
|
+
async deposit(amount) {
|
|
4246
|
+
console.log("deposit amount:", amount);
|
|
4247
|
+
const brokerId = this.configStore.get("brokerId");
|
|
4248
|
+
if (!brokerId)
|
|
4249
|
+
throw new Error("brokerId is required");
|
|
4250
|
+
const contractAddress = this.contractManger.getContractInfoByEnv();
|
|
4251
|
+
const depositData = {
|
|
4252
|
+
accountId: parseAccountId(this.account.stateValue.address, brokerId),
|
|
4253
|
+
brokerHash: parseBrokerHash(brokerId),
|
|
4254
|
+
tokenHash: parseTokenHash("USDC"),
|
|
4255
|
+
tokenAmount: this.account.walletClient?.parseUnits(amount)
|
|
4256
|
+
};
|
|
4257
|
+
const result = await this.account.walletClient?.call(
|
|
4258
|
+
contractAddress.vaultAddress,
|
|
4259
|
+
"deposit",
|
|
4260
|
+
[depositData],
|
|
4261
|
+
{
|
|
4262
|
+
abi: contractAddress.vaultAbi
|
|
4263
|
+
}
|
|
4264
|
+
);
|
|
4265
|
+
return result;
|
|
4266
|
+
}
|
|
4267
|
+
async _simpleFetch(url, init = {}) {
|
|
4268
|
+
const requestUrl = `${this.configStore.get("apiBaseUrl")}${url}`;
|
|
4269
|
+
return fetch(requestUrl, init).then((res) => res.json());
|
|
4270
|
+
}
|
|
4271
|
+
};
|
|
4272
|
+
|
|
4273
|
+
// src/account.ts
|
|
4274
|
+
var Account = class {
|
|
4275
|
+
// private config =
|
|
4276
|
+
constructor(configStore, keyStore, contractManger, getWalletAdapter) {
|
|
4277
|
+
this.configStore = configStore;
|
|
4278
|
+
this.keyStore = keyStore;
|
|
4279
|
+
this.contractManger = contractManger;
|
|
4280
|
+
this.getWalletAdapter = getWalletAdapter;
|
|
4281
|
+
// private _state$ = new BehaviorSubject<AccountState>({
|
|
4282
|
+
// status: AccountStatusEnum.NotConnected,
|
|
4283
|
+
// balance: "",
|
|
4284
|
+
// leverage: Number.NaN,
|
|
4285
|
+
// });
|
|
4286
|
+
this._ee = new import_eventemitter3.default();
|
|
4287
|
+
this._state = {
|
|
4288
|
+
status: import_types.AccountStatusEnum.NotConnected,
|
|
4289
|
+
balance: "",
|
|
4290
|
+
checking: false,
|
|
4291
|
+
leverage: Number.NaN
|
|
4292
|
+
};
|
|
4293
|
+
this.assetsManager = new Assets(configStore, contractManger, this);
|
|
4294
|
+
this._bindEvents();
|
|
4295
|
+
}
|
|
4296
|
+
/**
|
|
4297
|
+
* 登录
|
|
4298
|
+
* @param address 钱包地址
|
|
4299
|
+
*/
|
|
4300
|
+
login(address) {
|
|
4301
|
+
if (!address)
|
|
4302
|
+
throw new Error("address is required");
|
|
4303
|
+
}
|
|
4304
|
+
logout() {
|
|
4305
|
+
}
|
|
4306
|
+
/**
|
|
4307
|
+
* 连接钱包先用第三方的React版本,不用自己实现
|
|
4308
|
+
*/
|
|
4309
|
+
// connectWallet() {
|
|
4310
|
+
// // this.wallet.connect();
|
|
4311
|
+
// }
|
|
4312
|
+
async setAddress(address, wallet) {
|
|
4313
|
+
if (!address)
|
|
4314
|
+
throw new Error("address is required");
|
|
4315
|
+
this.keyStore.setAddress(address);
|
|
4316
|
+
const nextState = {
|
|
4317
|
+
...this.stateValue,
|
|
4318
|
+
status: import_types.AccountStatusEnum.Connected,
|
|
4319
|
+
address,
|
|
4320
|
+
connectWallet: wallet?.wallet
|
|
4321
|
+
};
|
|
4322
|
+
this._ee.emit("change:status", nextState);
|
|
4323
|
+
if (wallet) {
|
|
4324
|
+
this.walletClient = this.getWalletAdapter({ ...wallet, address });
|
|
4325
|
+
}
|
|
4326
|
+
return await this._checkAccount(address);
|
|
4327
|
+
}
|
|
4328
|
+
// subscribe the account state change
|
|
4329
|
+
// get state$(): BehaviorSubject<AccountState> {
|
|
4330
|
+
// return this._state$;
|
|
4331
|
+
// }
|
|
4332
|
+
// public get select(): EventEmitter {
|
|
4333
|
+
// return this._ee;
|
|
4334
|
+
// }
|
|
4335
|
+
get stateValue() {
|
|
4336
|
+
return this._state;
|
|
4337
|
+
}
|
|
4338
|
+
get accountId() {
|
|
4339
|
+
const state = this.stateValue;
|
|
4340
|
+
return state.accountId;
|
|
4341
|
+
}
|
|
4342
|
+
get address() {
|
|
4343
|
+
return this.stateValue.address;
|
|
4344
|
+
}
|
|
4345
|
+
get chainId() {
|
|
4346
|
+
return this.walletClient?.chainId;
|
|
4347
|
+
}
|
|
4348
|
+
/**
|
|
4349
|
+
* set user positions count
|
|
4350
|
+
*/
|
|
4351
|
+
set position(position) {
|
|
4352
|
+
const nextState = {
|
|
4353
|
+
...this.stateValue,
|
|
4354
|
+
positon: position
|
|
4355
|
+
};
|
|
4356
|
+
this._ee.emit("change:status", nextState);
|
|
4357
|
+
}
|
|
4358
|
+
set orders(orders) {
|
|
4359
|
+
const nextState = {
|
|
4360
|
+
...this.stateValue,
|
|
4361
|
+
orders
|
|
4362
|
+
};
|
|
4363
|
+
this._ee.emit("change:status", nextState);
|
|
4364
|
+
}
|
|
4365
|
+
_bindEvents() {
|
|
4366
|
+
this._ee.addListener("change:status", (state) => {
|
|
4367
|
+
console.log("change:status", state);
|
|
4368
|
+
this._state = state;
|
|
4369
|
+
});
|
|
4370
|
+
}
|
|
4371
|
+
// 检查账户状态
|
|
4372
|
+
async _checkAccount(address) {
|
|
4373
|
+
let nextState;
|
|
4374
|
+
try {
|
|
4375
|
+
const accountInfo = await this._checkAccountExist(address);
|
|
4376
|
+
if (accountInfo && accountInfo.account_id) {
|
|
4377
|
+
console.log("account is exist");
|
|
4378
|
+
this.keyStore.setAccountId(address, accountInfo.account_id);
|
|
4379
|
+
nextState = {
|
|
4380
|
+
...this.stateValue,
|
|
4381
|
+
status: import_types.AccountStatusEnum.SignedIn,
|
|
4382
|
+
accountId: accountInfo.account_id,
|
|
4383
|
+
userId: accountInfo.user_id
|
|
4384
|
+
};
|
|
4385
|
+
this._ee.emit("change:status", nextState);
|
|
4386
|
+
} else {
|
|
4387
|
+
nextState = {
|
|
4388
|
+
...this.stateValue,
|
|
4389
|
+
status: import_types.AccountStatusEnum.NotSignedIn
|
|
4390
|
+
};
|
|
4391
|
+
this._ee.emit("change:status", nextState);
|
|
4392
|
+
return import_types.AccountStatusEnum.NotSignedIn;
|
|
4393
|
+
}
|
|
4394
|
+
const orderlyKey = this.keyStore.getOrderlyKey();
|
|
4395
|
+
nextState = {
|
|
4396
|
+
...this.stateValue,
|
|
4397
|
+
status: import_types.AccountStatusEnum.DisabledTrading
|
|
4398
|
+
};
|
|
4399
|
+
if (!orderlyKey) {
|
|
4400
|
+
console.log("orderlyKey is null");
|
|
4401
|
+
this._ee.emit("change:status", nextState);
|
|
4402
|
+
return import_types.AccountStatusEnum.DisabledTrading;
|
|
4403
|
+
}
|
|
4404
|
+
const publicKey = await orderlyKey.getPublicKey();
|
|
4405
|
+
const orderlyKeyStatus = await this._checkOrderlyKeyState(
|
|
4406
|
+
accountInfo.account_id,
|
|
4407
|
+
publicKey
|
|
4408
|
+
);
|
|
4409
|
+
if (orderlyKeyStatus && orderlyKeyStatus.orderly_key && orderlyKeyStatus.key_status === "ACTIVE") {
|
|
4410
|
+
const now = Date.now();
|
|
4411
|
+
const expiration = orderlyKeyStatus.expiration;
|
|
4412
|
+
if (now > expiration) {
|
|
4413
|
+
this.keyStore.cleanKey(address, "orderlyKey");
|
|
4414
|
+
return import_types.AccountStatusEnum.DisabledTrading;
|
|
4415
|
+
}
|
|
4416
|
+
const nextState2 = {
|
|
4417
|
+
...this.stateValue,
|
|
4418
|
+
status: import_types.AccountStatusEnum.EnableTrading
|
|
4419
|
+
};
|
|
4420
|
+
this._ee.emit("change:status", nextState2);
|
|
4421
|
+
return import_types.AccountStatusEnum.EnableTrading;
|
|
4422
|
+
}
|
|
4423
|
+
this.keyStore.cleanKey(address, "orderlyKey");
|
|
4424
|
+
return import_types.AccountStatusEnum.NotConnected;
|
|
4425
|
+
} catch (err2) {
|
|
4426
|
+
console.log("\u68C0\u67E5\u8D26\u6237\u72B6\u6001\u9519\u8BEF:", err2);
|
|
4427
|
+
}
|
|
4428
|
+
return import_types.AccountStatusEnum.NotSignedIn;
|
|
4429
|
+
}
|
|
4430
|
+
async _checkAccountExist(address) {
|
|
4431
|
+
const res = await this._simpleFetch(
|
|
4432
|
+
`/v1/get_account?address=${address}&broker_id=woofi_dex`
|
|
4433
|
+
);
|
|
4434
|
+
if (res.success) {
|
|
4435
|
+
return res.data;
|
|
4436
|
+
} else {
|
|
4437
|
+
return null;
|
|
4438
|
+
}
|
|
4439
|
+
}
|
|
4440
|
+
async createAccount() {
|
|
4441
|
+
if (!this.walletClient) {
|
|
4442
|
+
return Promise.reject("walletClient is undefined");
|
|
4443
|
+
}
|
|
4444
|
+
const nonce = await this._getRegisterationNonce();
|
|
4445
|
+
const address = this.stateValue.address;
|
|
4446
|
+
if (!address) {
|
|
4447
|
+
throw new Error("address is undefined");
|
|
4448
|
+
}
|
|
4449
|
+
const [message, toSignatureMessage] = generateRegisterAccountMessage({
|
|
4450
|
+
registrationNonce: nonce,
|
|
4451
|
+
chainId: this.walletClient.chainId,
|
|
4452
|
+
brokerId: this.configStore.get("brokerId")
|
|
4453
|
+
});
|
|
4454
|
+
const signatured = await this.signTypedData(toSignatureMessage);
|
|
4455
|
+
const res = await this._simpleFetch("/v1/register_account", {
|
|
4456
|
+
method: "POST",
|
|
4457
|
+
body: JSON.stringify({
|
|
4458
|
+
signature: signatured,
|
|
4459
|
+
message,
|
|
4460
|
+
userAddress: address
|
|
4461
|
+
}),
|
|
4462
|
+
headers: {
|
|
4463
|
+
"Content-Type": "application/json"
|
|
4464
|
+
}
|
|
4465
|
+
});
|
|
4466
|
+
if (res.success) {
|
|
4467
|
+
this.keyStore.setAccountId(address, res.data.account_id);
|
|
4468
|
+
const nextState = {
|
|
4469
|
+
...this.stateValue,
|
|
4470
|
+
status: import_types.AccountStatusEnum.DisabledTrading,
|
|
4471
|
+
accountId: res.data.account_id,
|
|
4472
|
+
userId: res.data.user_id
|
|
4473
|
+
};
|
|
4474
|
+
this._ee.emit("change:status", nextState);
|
|
4475
|
+
return res;
|
|
4476
|
+
}
|
|
4477
|
+
}
|
|
4478
|
+
async signTypedData(toSignatureMessage) {
|
|
4479
|
+
if (!this.walletClient) {
|
|
4480
|
+
return Promise.reject("walletClient is undefined");
|
|
4481
|
+
}
|
|
4482
|
+
return await this.walletClient.signTypedData(
|
|
4483
|
+
// address,
|
|
4484
|
+
this.stateValue.address,
|
|
4485
|
+
JSON.stringify(toSignatureMessage)
|
|
4486
|
+
);
|
|
4487
|
+
}
|
|
4488
|
+
async createOrderlyKey(expiration) {
|
|
4489
|
+
if (this.stateValue.accountId === void 0) {
|
|
4490
|
+
throw new Error("account id is undefined");
|
|
4491
|
+
}
|
|
4492
|
+
if (!this.walletClient) {
|
|
4493
|
+
throw new Error("walletClient is undefined");
|
|
4494
|
+
}
|
|
4495
|
+
const primaryType = "AddOrderlyKey";
|
|
4496
|
+
const keyPair = this.keyStore.generateKey();
|
|
4497
|
+
const publicKey = await keyPair.getPublicKey();
|
|
4498
|
+
const [message, toSignatureMessage] = generateAddOrderlyKeyMessage({
|
|
4499
|
+
publicKey,
|
|
4500
|
+
chainId: this.walletClient.chainId,
|
|
4501
|
+
primaryType,
|
|
4502
|
+
expiration,
|
|
4503
|
+
brokerId: this.configStore.get("brokerId")
|
|
4504
|
+
});
|
|
4505
|
+
const address = this.stateValue.address;
|
|
4506
|
+
if (!address) {
|
|
4507
|
+
throw new Error("address is undefined");
|
|
4508
|
+
}
|
|
4509
|
+
const signatured = await this.signTypedData(toSignatureMessage);
|
|
4510
|
+
const res = await this._simpleFetch("/v1/orderly_key", {
|
|
4511
|
+
method: "POST",
|
|
4512
|
+
body: JSON.stringify({
|
|
4513
|
+
signature: signatured,
|
|
4514
|
+
message,
|
|
4515
|
+
userAddress: address
|
|
4516
|
+
}),
|
|
4517
|
+
headers: {
|
|
4518
|
+
"X-Account-Id": this.stateValue.accountId,
|
|
4519
|
+
"Content-Type": "application/json"
|
|
4520
|
+
}
|
|
4521
|
+
});
|
|
4522
|
+
if (res.success) {
|
|
4523
|
+
this.keyStore.setKey(address, keyPair);
|
|
4524
|
+
const nextState = {
|
|
4525
|
+
...this.stateValue,
|
|
4526
|
+
status: import_types.AccountStatusEnum.EnableTrading
|
|
4527
|
+
// accountId: res.data.account_id,
|
|
4528
|
+
// userId: res.data.user_id,
|
|
4529
|
+
};
|
|
4530
|
+
this._ee.emit("change:status", nextState);
|
|
4531
|
+
return res;
|
|
4532
|
+
} else {
|
|
4533
|
+
throw new Error(res.message);
|
|
4534
|
+
}
|
|
4535
|
+
}
|
|
4536
|
+
async settle() {
|
|
4537
|
+
if (!this.walletClient) {
|
|
4538
|
+
return Promise.reject("walletClient is undefined");
|
|
4539
|
+
}
|
|
4540
|
+
const nonce = await this._getSettleNonce();
|
|
4541
|
+
const address = this.stateValue.address;
|
|
4542
|
+
const domain = this.getDomain(true);
|
|
4543
|
+
const url = "/v1/settle_pnl";
|
|
4544
|
+
const [message, toSignatureMessage] = generateSettleMessage({
|
|
4545
|
+
settlePnlNonce: nonce,
|
|
4546
|
+
chainId: this.walletClient.chainId,
|
|
4547
|
+
brokerId: this.configStore.get("brokerId"),
|
|
4548
|
+
domain
|
|
4549
|
+
});
|
|
4550
|
+
const EIP_712signatured = await this.signTypedData(toSignatureMessage);
|
|
4551
|
+
const data = {
|
|
4552
|
+
signature: EIP_712signatured,
|
|
4553
|
+
message,
|
|
4554
|
+
userAddress: address,
|
|
4555
|
+
verifyingContract: domain.verifyingContract
|
|
4556
|
+
};
|
|
4557
|
+
const payload = {
|
|
4558
|
+
method: "POST",
|
|
4559
|
+
url,
|
|
4560
|
+
data
|
|
4561
|
+
};
|
|
4562
|
+
const signature = await this.signer.sign(payload);
|
|
4563
|
+
const res = await this._simpleFetch(url, {
|
|
4564
|
+
method: "POST",
|
|
4565
|
+
body: JSON.stringify(data),
|
|
4566
|
+
headers: {
|
|
4567
|
+
"Content-Type": "application/json",
|
|
4568
|
+
"orderly-account-id": this.stateValue.accountId,
|
|
4569
|
+
...signature
|
|
4570
|
+
}
|
|
4571
|
+
});
|
|
4572
|
+
if (res.success) {
|
|
4573
|
+
return res;
|
|
4574
|
+
} else {
|
|
4575
|
+
throw new Error(res.message);
|
|
4576
|
+
}
|
|
4577
|
+
}
|
|
4578
|
+
async disconnect() {
|
|
4579
|
+
const nextState = {
|
|
4580
|
+
...this.stateValue,
|
|
4581
|
+
status: import_types.AccountStatusEnum.NotConnected,
|
|
4582
|
+
accountId: void 0,
|
|
4583
|
+
userId: void 0,
|
|
4584
|
+
address: void 0
|
|
4585
|
+
};
|
|
4586
|
+
this._ee.emit("change:status", nextState);
|
|
4587
|
+
}
|
|
4588
|
+
async _checkOrderlyKeyState(accountId, orderlyKey) {
|
|
4589
|
+
const res = await this._simpleFetch(
|
|
4590
|
+
`/v1/get_orderly_key?account_id=${accountId}&orderly_key=${orderlyKey}`
|
|
4591
|
+
);
|
|
4592
|
+
if (res.success) {
|
|
4593
|
+
return res.data;
|
|
4594
|
+
} else {
|
|
4595
|
+
throw new Error(res.message);
|
|
4596
|
+
}
|
|
4597
|
+
}
|
|
4598
|
+
get signer() {
|
|
4599
|
+
if (!this._singer) {
|
|
4600
|
+
this._singer = new BaseSigner(this.keyStore);
|
|
4601
|
+
}
|
|
4602
|
+
return this._singer;
|
|
4603
|
+
}
|
|
4604
|
+
get wallet() {
|
|
4605
|
+
return this.walletClient;
|
|
4606
|
+
}
|
|
4607
|
+
async _getRegisterationNonce() {
|
|
4608
|
+
const res = await this._simpleFetch("/v1/registration_nonce", {
|
|
4609
|
+
headers: {
|
|
4610
|
+
"orderly-account-id": this.stateValue.accountId
|
|
4611
|
+
}
|
|
4612
|
+
});
|
|
4613
|
+
if (res.success) {
|
|
4614
|
+
return res.data?.registration_nonce;
|
|
4615
|
+
} else {
|
|
4616
|
+
throw new Error(res.message);
|
|
4617
|
+
}
|
|
4618
|
+
}
|
|
4619
|
+
async _getSettleNonce() {
|
|
4620
|
+
const timestamp = Date.now().toString();
|
|
4621
|
+
const url = "/v1/settle_nonce";
|
|
4622
|
+
const message = [timestamp, "GET", url].join("");
|
|
4623
|
+
const signer = this.signer;
|
|
4624
|
+
const { publicKey, signature } = await signer.signText(message);
|
|
4625
|
+
const res = await this._simpleFetch("/v1/settle_nonce", {
|
|
4626
|
+
headers: {
|
|
4627
|
+
"orderly-account-id": this.stateValue.accountId,
|
|
4628
|
+
"orderly-key": publicKey,
|
|
4629
|
+
"orderly-timestamp": timestamp,
|
|
4630
|
+
"orderly-signature": signature
|
|
4631
|
+
}
|
|
4632
|
+
});
|
|
4633
|
+
if (res.success) {
|
|
4634
|
+
return res.data?.settle_nonce;
|
|
4635
|
+
} else {
|
|
4636
|
+
throw new Error(res.message);
|
|
4637
|
+
}
|
|
4638
|
+
}
|
|
4639
|
+
async _simpleFetch(url, init = {}) {
|
|
4640
|
+
const requestUrl = `${this.configStore.get("apiBaseUrl")}${url}`;
|
|
4641
|
+
return fetch(requestUrl, init).then((res) => res.json());
|
|
4642
|
+
}
|
|
4643
|
+
getDomain(onChainDomain) {
|
|
4644
|
+
if (!this.walletClient) {
|
|
4645
|
+
throw new Error("walletClient is undefined");
|
|
4646
|
+
}
|
|
4647
|
+
const chainId = this.walletClient.chainId;
|
|
4648
|
+
return {
|
|
4649
|
+
name: "Orderly",
|
|
4650
|
+
version: "1",
|
|
4651
|
+
chainId,
|
|
4652
|
+
verifyingContract: onChainDomain ? this.contractManger.getContractInfoByEnv().verifyContractAddress : "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"
|
|
4653
|
+
};
|
|
4654
|
+
}
|
|
4655
|
+
get on() {
|
|
4656
|
+
return this._ee.on.bind(this._ee);
|
|
4657
|
+
}
|
|
4658
|
+
get once() {
|
|
4659
|
+
return this._ee.once.bind(this._ee);
|
|
4660
|
+
}
|
|
4661
|
+
get off() {
|
|
4662
|
+
return this._ee.off.bind(this._ee);
|
|
4663
|
+
}
|
|
4664
|
+
};
|
|
4665
|
+
Account.instanceName = "account";
|
|
4666
|
+
|
|
4667
|
+
// src/wallet/index.ts
|
|
4668
|
+
init_dirname();
|
|
4669
|
+
init_buffer2();
|
|
4670
|
+
init_process2();
|
|
4671
|
+
|
|
4672
|
+
// src/wallet/etherAdapter.ts
|
|
4673
|
+
init_dirname();
|
|
4674
|
+
init_buffer2();
|
|
4675
|
+
init_process2();
|
|
4676
|
+
var import_ethers3 = require("ethers");
|
|
4677
|
+
var import_ethers_error_parser = require("@enzoferey/ethers-error-parser");
|
|
4678
|
+
var EtherAdapter = class {
|
|
4679
|
+
constructor(options) {
|
|
4680
|
+
console.log("EtherAdapter constructor", options);
|
|
4681
|
+
this._chainId = parseInt(options.chain.id, 16);
|
|
4682
|
+
this.provider = new import_ethers3.BrowserProvider(options.provider, "any");
|
|
4683
|
+
this._address = options.address;
|
|
4684
|
+
}
|
|
4685
|
+
parseUnits(amount) {
|
|
4686
|
+
return import_ethers3.ethers.parseUnits(amount, 6).toString();
|
|
4687
|
+
}
|
|
4688
|
+
fromUnits(amount) {
|
|
4689
|
+
return import_ethers3.ethers.formatUnits(amount, 6);
|
|
4690
|
+
}
|
|
4691
|
+
getBalance(contractId, userAddress, options) {
|
|
4692
|
+
const contract = new import_ethers3.ethers.Contract(
|
|
4693
|
+
contractId,
|
|
4694
|
+
options.abi,
|
|
4695
|
+
this.provider
|
|
4696
|
+
);
|
|
4697
|
+
return contract.balanceOf(userAddress);
|
|
4698
|
+
}
|
|
4699
|
+
deposit(from, to, amount) {
|
|
4700
|
+
throw new Error("Method not implemented.");
|
|
4701
|
+
}
|
|
4702
|
+
async call(address, method, params, options) {
|
|
4703
|
+
const singer = await this.provider?.getSigner();
|
|
4704
|
+
const contract = new import_ethers3.ethers.Contract(address, options.abi, singer);
|
|
4705
|
+
return contract[method].apply(null, params).catch((error) => {
|
|
4706
|
+
const parsedEthersError = (0, import_ethers_error_parser.getParsedEthersError)(error);
|
|
4707
|
+
throw parsedEthersError;
|
|
4708
|
+
});
|
|
4709
|
+
}
|
|
4710
|
+
get chainId() {
|
|
4711
|
+
return this._chainId;
|
|
4712
|
+
}
|
|
4713
|
+
get addresses() {
|
|
4714
|
+
return this._address;
|
|
4715
|
+
}
|
|
4716
|
+
async send(method, params) {
|
|
4717
|
+
return await this.provider?.send(method, params);
|
|
4718
|
+
}
|
|
4719
|
+
async signTypedData(address, data) {
|
|
4720
|
+
return await this.provider?.send("eth_signTypedData_v4", [address, data]);
|
|
4721
|
+
}
|
|
4722
|
+
async verify(data, signature) {
|
|
4723
|
+
const { domain, types, message } = data;
|
|
4724
|
+
const recovered = import_ethers3.ethers.verifyTypedData(domain, types, message, signature);
|
|
4725
|
+
console.log("recovered", recovered);
|
|
4726
|
+
}
|
|
4727
|
+
};
|
|
4728
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
4729
|
+
0 && (module.exports = {
|
|
4730
|
+
Account,
|
|
4731
|
+
BaseConfigStore,
|
|
4732
|
+
BaseContractManager,
|
|
4733
|
+
BaseKeyStore,
|
|
4734
|
+
BaseOrderlyKeyPair,
|
|
4735
|
+
BaseSigner,
|
|
4736
|
+
EtherAdapter,
|
|
4737
|
+
EventEmitter,
|
|
4738
|
+
LocalStorageStore,
|
|
4739
|
+
MemoryConfigStore,
|
|
4740
|
+
MockKeyStore,
|
|
4741
|
+
SimpleDI,
|
|
4742
|
+
getDefaultSigner,
|
|
4743
|
+
getMockSigner
|
|
4744
|
+
});
|
|
2
4745
|
/*! Bundled license information:
|
|
3
4746
|
|
|
4
4747
|
@jspm/core/nodelibs/browser/buffer.js:
|