@coinmeca/wallet-sdk
Version:
5 lines (4 loc) • 27.6 kB
JavaScript
import{random as t,parse as e,format as s}from"./utils.js";import"ethereum-cryptography/utils";import"./constants-BBbo8WQE.js";
/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */function r(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&"Uint8Array"===t.constructor.name}function n(t,...e){if(!r(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function o(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function i(t,e){n(t);const s=e.outputLen;if(t.length<s)throw new Error("digestInto() expects output buffer of length at least "+s)}function h(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function c(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function a(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}const u=(()=>68===new Uint8Array(new Uint32Array([287454020]).buffer)[0])();function f(t){if("string"==typeof t)t=function(t){if("string"!=typeof t)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(t))}(t);else{if(!r(t))throw new Error("Uint8Array expected, got "+typeof t);t=g(t)}return t}const p=(t,e)=>{function s(s,...r){if(n(s),!u)throw new Error("Non little-endian hardware is not yet supported");if(void 0!==t.nonceLength){const e=r[0];if(!e)throw new Error("nonce / iv required");t.varSizeNonce?n(e):n(e,t.nonceLength)}const o=t.tagLength;o&&void 0!==r[1]&&n(r[1]);const i=e(s,...r),h=(t,e)=>{if(void 0!==e){if(2!==t)throw new Error("cipher output not supported");n(e)}};let c=!1;return{encrypt(t,e){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,n(t),h(i.encrypt.length,e),i.encrypt(t,e)},decrypt(t,e){if(n(t),o&&t.length<o)throw new Error("invalid ciphertext length: smaller than tagLength="+o);return h(i.decrypt.length,e),i.decrypt(t,e)}}}return Object.assign(s,t),s};function d(t,e,s,r){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,s,r);const n=BigInt(32),o=BigInt(4294967295),i=Number(s>>n&o),h=Number(s&o);t.setUint32(e+0,i,r),t.setUint32(e+4,h,r)}function l(t){return t.byteOffset%4==0}function g(t){return Uint8Array.from(t)}const y=16,w=new Uint8Array(16),b=h(w),v=(t,e,s,r)=>({s3:s<<31|r>>>1,s2:e<<31|s>>>1,s1:t<<31|e>>>1,s0:t>>>1^225<<24&-(1&(1&r))}),m=t=>(t>>>0&255)<<24|(t>>>8&255)<<16|(t>>>16&255)<<8|t>>>24&255;class U{constructor(t,e){this.blockLen=y,this.outputLen=y,this.s0=0,this.s1=0,this.s2=0,this.s3=0,this.finished=!1,n(t=f(t),16);const s=a(t);let r=s.getUint32(0,!1),o=s.getUint32(4,!1),i=s.getUint32(8,!1),h=s.getUint32(12,!1);const c=[];for(let t=0;t<128;t++)c.push({s0:m(r),s1:m(o),s2:m(i),s3:m(h)}),({s0:r,s1:o,s2:i,s3:h}=v(r,o,i,h));const u=(t=>t>65536?8:t>1024?4:2)(e||1024);if(![1,2,4,8].includes(u))throw new Error("ghash: invalid window size, expected 2, 4 or 8");this.W=u;const p=128/u,d=this.windowSize=2**u,l=[];for(let t=0;t<p;t++)for(let e=0;e<d;e++){let s=0,r=0,n=0,o=0;for(let i=0;i<u;i++){if(!(e>>>u-i-1&1))continue;const{s0:h,s1:a,s2:f,s3:p}=c[u*t+i];s^=h,r^=a,n^=f,o^=p}l.push({s0:s,s1:r,s2:n,s3:o})}this.t=l}_updateBlock(t,e,s,r){t^=this.s0,e^=this.s1,s^=this.s2,r^=this.s3;const{W:n,t:o,windowSize:i}=this;let h=0,c=0,a=0,u=0;const f=(1<<n)-1;let p=0;for(const d of[t,e,s,r])for(let t=0;t<4;t++){const e=d>>>8*t&255;for(let t=8/n-1;t>=0;t--){const s=e>>>n*t&f,{s0:r,s1:d,s2:l,s3:g}=o[p*i+s];h^=r,c^=d,a^=l,u^=g,p+=1}}this.s0=h,this.s1=c,this.s2=a,this.s3=u}update(t){o(this),n(t=f(t));const e=h(t),s=Math.floor(t.length/y),r=t.length%y;for(let t=0;t<s;t++)this._updateBlock(e[4*t+0],e[4*t+1],e[4*t+2],e[4*t+3]);return r&&(w.set(t.subarray(s*y)),this._updateBlock(b[0],b[1],b[2],b[3]),c(b)),this}destroy(){const{t:t}=this;for(const e of t)e.s0=0,e.s1=0,e.s2=0,e.s3=0}digestInto(t){o(this),i(t,this),this.finished=!0;const{s0:e,s1:s,s2:r,s3:n}=this,c=h(t);return c[0]=e,c[1]=s,c[2]=r,c[3]=n,t}digest(){const t=new Uint8Array(y);return this.digestInto(t),this.destroy(),t}}class A extends U{constructor(t,e){n(t=f(t));const s=function(t){t.reverse();const e=1&t[15];let s=0;for(let e=0;e<t.length;e++){const r=t[e];t[e]=r>>>1|s,s=(1&r)<<7}return t[0]^=225&-e,t}(g(t));super(s,e),c(s)}update(t){t=f(t),o(this);const e=h(t),s=t.length%y,r=Math.floor(t.length/y);for(let t=0;t<r;t++)this._updateBlock(m(e[4*t+3]),m(e[4*t+2]),m(e[4*t+1]),m(e[4*t+0]));return s&&(w.set(t.subarray(r*y)),this._updateBlock(m(b[3]),m(b[2]),m(b[1]),m(b[0])),c(b)),this}digestInto(t){o(this),i(t,this),this.finished=!0;const{s0:e,s1:s,s2:r,s3:n}=this,c=h(t);return c[0]=e,c[1]=s,c[2]=r,c[3]=n,t.reverse()}}function k(t){const e=(e,s)=>t(s,e.length).update(f(e)).digest(),s=t(new Uint8Array(16),0);return e.outputLen=s.outputLen,e.blockLen=s.blockLen,e.create=(e,s)=>t(e,s),e}const L=k((t,e)=>new U(t,e));k((t,e)=>new A(t,e));const I=new Uint8Array(16);function E(t){return t<<1^283&-(t>>7)}function S(t,e){let s=0;for(;e>0;e>>=1)s^=t&-(1&e),t=E(t);return s}const x=t=>t<<24|t>>>8,H=t=>t<<8|t>>>24;function _(t,e){if(256!==t.length)throw new Error("Wrong sbox length");const s=new Uint32Array(256).map((s,r)=>e(t[r])),r=s.map(H),n=r.map(H),o=n.map(H),i=new Uint32Array(65536),h=new Uint32Array(65536),c=new Uint16Array(65536);for(let e=0;e<256;e++)for(let a=0;a<256;a++){const u=256*e+a;i[u]=s[e]^r[a],h[u]=n[e]^o[a],c[u]=t[e]<<8|t[a]}return{sbox:t,sbox2:c,T0:s,T1:r,T2:n,T3:o,T01:i,T23:h}}const B=_((()=>{const t=new Uint8Array(256);for(let e=0,s=1;e<256;e++,s^=E(s))t[e]=s;const e=new Uint8Array(256);e[0]=99;for(let s=0;s<255;s++){let r=t[255-s];r|=r<<8,e[t[s]]=255&(r^r>>4^r>>5^r>>6^r>>7^99)}return c(t),e})(),t=>S(t,3)<<24|t<<16|t<<8|S(t,2)),O=(()=>{const t=new Uint8Array(16);for(let e=0,s=1;e<16;e++,s=E(s))t[e]=s;return t})();function j(t,e,s,r,n,o){return t[s<<8&65280|r>>>8&255]^e[n>>>8&65280|o>>>24&255]}function C(t,e,s,r,n){return t[255&e|65280&s]|t[r>>>16&255|n>>>16&65280]<<16}function D(t,e,s,r,n){const{sbox2:o,T01:i,T23:h}=B;let c=0;e^=t[c++],s^=t[c++],r^=t[c++],n^=t[c++];const a=t.length/4-2;for(let o=0;o<a;o++){const o=t[c++]^j(i,h,e,s,r,n),a=t[c++]^j(i,h,s,r,n,e),u=t[c++]^j(i,h,r,n,e,s),f=t[c++]^j(i,h,n,e,s,r);e=o,s=a,r=u,n=f}return{s0:t[c++]^C(o,e,s,r,n),s1:t[c++]^C(o,s,r,n,e),s2:t[c++]^C(o,r,n,e,s),s3:t[c++]^C(o,n,e,s,r)}}function N(t,e,s,r,o){n(s,16),n(r),o=function(t,e,s=!0){if(void 0===e)return new Uint8Array(t);if(e.length!==t)throw new Error("invalid output length, expected "+t+", got: "+e.length);if(s&&!l(e))throw new Error("invalid output, must be aligned");return e}(r.length,o);const i=s,u=h(i),f=a(i),p=h(r),d=h(o),g=e?0:12,y=r.length;let w=f.getUint32(g,e),{s0:b,s1:v,s2:m,s3:U}=D(t,u[0],u[1],u[2],u[3]);for(let s=0;s+4<=p.length;s+=4)d[s+0]=p[s+0]^b,d[s+1]=p[s+1]^v,d[s+2]=p[s+2]^m,d[s+3]=p[s+3]^U,w=w+1>>>0,f.setUint32(g,w,e),({s0:b,s1:v,s2:m,s3:U}=D(t,u[0],u[1],u[2],u[3]));const A=16*Math.floor(p.length/4);if(A<y){const t=new Uint32Array([b,v,m,U]),e=(k=t,new Uint8Array(k.buffer,k.byteOffset,k.byteLength));for(let t=A,s=0;t<y;t++,s++)o[t]=r[t]^e[s];c(t)}var k;return o}function T(t,e,s,r,n){const o=n?n.length:0,i=t.create(s,r.length+o);n&&i.update(n);const h=function(t,e,s){const r=new Uint8Array(16),n=a(r);return d(n,0,BigInt(e),s),d(n,8,BigInt(t),s),r}(8*r.length,8*o,e);i.update(r),i.update(h);const u=i.digest();return c(h),u}const M=p({blockSize:16,nonceLength:12,tagLength:16,varSizeNonce:!0},function(t,e,s){if(e.length<8)throw new Error("aes/gcm: invalid nonce length");function r(t,e,r){const n=T(L,!1,t,r,s);for(let t=0;t<e.length;t++)n[t]^=e[t];return n}function o(){const s=function(t){n(t);const e=t.length;if(![16,24,32].includes(e))throw new Error("aes: invalid key size, should be 16, 24 or 32, got "+e);const{sbox2:s}=B,r=[];l(t)||r.push(t=g(t));const o=h(t),i=o.length,a=t=>C(s,t,t,t,t),u=new Uint32Array(e+28);u.set(o);for(let t=i;t<u.length;t++){let e=u[t-1];t%i===0?e=a(x(e))^O[t/i-1]:i>6&&t%i===4&&(e=a(e)),u[t]=u[t-i]^e}return c(...r),u}(t),r=I.slice(),o=I.slice();if(N(s,!1,o,o,r),12===e.length)o.set(e);else{const t=I.slice();d(a(t),8,BigInt(8*e.length),!1);const s=L.create(r).update(e).update(t);s.digestInto(o),s.destroy()}return{xk:s,authKey:r,counter:o,tagMask:N(s,!1,o,I)}}return{encrypt(t){const{xk:e,authKey:s,counter:n,tagMask:i}=o(),h=new Uint8Array(t.length+16),a=[e,s,n,i];l(t)||a.push(t=g(t)),N(e,!1,n,t,h.subarray(0,t.length));const u=r(s,i,h.subarray(0,h.length-16));return a.push(u),h.set(u,t.length),c(...a),h},decrypt(t){const{xk:e,authKey:s,counter:n,tagMask:i}=o(),h=[e,s,i,n];l(t)||h.push(t=g(t));const a=t.subarray(0,-16),u=t.subarray(-16),f=r(s,i,a);if(h.push(f),!function(t,e){if(t.length!==e.length)return!1;let s=0;for(let r=0;r<t.length;r++)s|=t[r]^e[r];return 0===s}(f,u))throw new Error("aes/gcm: invalid ghash tag");const p=N(e,!1,n,a);return c(...h),p}}});
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function P(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function z(t,...e){if(!((s=t)instanceof Uint8Array||ArrayBuffer.isView(s)&&"Uint8Array"===s.constructor.name))throw new Error("Uint8Array expected");var s;if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function G(t){if("function"!=typeof t||"function"!=typeof t.create)throw new Error("Hash should be wrapped by utils.createHasher");P(t.outputLen),P(t.blockLen)}function F(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function V(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function R(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function W(t,e){return t<<32-e|t>>>e}function q(t){return"string"==typeof t&&(t=function(t){if("string"!=typeof t)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(t))}(t)),z(t),t}class K{}function J(t){const e=e=>t().update(q(e)).digest(),s=t();return e.outputLen=s.outputLen,e.blockLen=s.blockLen,e.create=()=>t(),e}class X extends K{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,G(t);const s=q(e);if(this.iHash=t.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,n=new Uint8Array(r);n.set(s.length>r?t.create().update(s).digest():s);for(let t=0;t<n.length;t++)n[t]^=54;this.iHash.update(n),this.oHash=t.create();for(let t=0;t<n.length;t++)n[t]^=106;this.oHash.update(n),V(n)}update(t){return F(this),this.iHash.update(t),this}digestInto(t){F(this),z(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:e,iHash:s,finished:r,destroyed:n,blockLen:o,outputLen:i}=this;return t.finished=r,t.destroyed=n,t.blockLen=o,t.outputLen=i,t.oHash=e._cloneInto(t.oHash),t.iHash=s._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const Y=(t,e,s)=>new X(t,e).update(s).digest();Y.create=(t,e)=>new X(t,e);const Z=Uint8Array.from([0]),$=Uint8Array.of();const Q=(t,e,s,r,n)=>function(t,e,s,r=32){G(t),P(r);const n=t.outputLen;if(r>255*n)throw new Error("Length should be <= 255*HashLen");const o=Math.ceil(r/n);void 0===s&&(s=$);const i=new Uint8Array(o*n),h=Y.create(t,e),c=h._cloneInto(),a=new Uint8Array(h.outputLen);for(let t=0;t<o;t++)Z[0]=t+1,c.update(0===t?$:a).update(s).update(Z).digestInto(a),i.set(a,n*t),h._cloneInto(c);return h.destroy(),c.destroy(),V(a,Z),i.slice(0,r)}(t,function(t,e,s){return G(t),void 0===s&&(s=new Uint8Array(t.outputLen)),Y(t,q(s),q(e))}(t,e,s),r,n);function tt(t,e,s){return t&e^~t&s}function et(t,e,s){return t&e^t&s^e&s}class st extends K{constructor(t,e,s,r){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=s,this.isLE=r,this.buffer=new Uint8Array(t),this.view=R(this.buffer)}update(t){F(this),z(t=q(t));const{view:e,buffer:s,blockLen:r}=this,n=t.length;for(let o=0;o<n;){const i=Math.min(r-this.pos,n-o);if(i===r){const e=R(t);for(;r<=n-o;o+=r)this.process(e,o);continue}s.set(t.subarray(o,o+i),this.pos),this.pos+=i,o+=i,this.pos===r&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){F(this),function(t,e){z(t);const s=e.outputLen;if(t.length<s)throw new Error("digestInto() expects output buffer of length at least "+s)}(t,this),this.finished=!0;const{buffer:e,view:s,blockLen:r,isLE:n}=this;let{pos:o}=this;e[o++]=128,V(this.buffer.subarray(o)),this.padOffset>r-o&&(this.process(s,0),o=0);for(let t=o;t<r;t++)e[t]=0;!function(t,e,s,r){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,s,r);const n=BigInt(32),o=BigInt(4294967295),i=Number(s>>n&o),h=Number(s&o),c=r?4:0,a=r?0:4;t.setUint32(e+c,i,r),t.setUint32(e+a,h,r)}(s,r-8,BigInt(8*this.length),n),this.process(s,0);const i=R(t),h=this.outputLen;if(h%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=h/4,a=this.get();if(c>a.length)throw new Error("_sha2: outputLen bigger than state");for(let t=0;t<c;t++)i.setUint32(4*t,a[t],n)}digest(){const{buffer:t,outputLen:e}=this;this.digestInto(t);const s=t.slice(0,e);return this.destroy(),s}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:e,buffer:s,length:r,finished:n,destroyed:o,pos:i}=this;return t.destroyed=o,t.finished=n,t.length=r,t.pos=i,r%e&&t.buffer.set(s),t}clone(){return this._cloneInto()}}const rt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),nt=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ot=new Uint32Array(64);class it extends st{constructor(t=32){super(64,t,8,!1),this.A=0|rt[0],this.B=0|rt[1],this.C=0|rt[2],this.D=0|rt[3],this.E=0|rt[4],this.F=0|rt[5],this.G=0|rt[6],this.H=0|rt[7]}get(){const{A:t,B:e,C:s,D:r,E:n,F:o,G:i,H:h}=this;return[t,e,s,r,n,o,i,h]}set(t,e,s,r,n,o,i,h){this.A=0|t,this.B=0|e,this.C=0|s,this.D=0|r,this.E=0|n,this.F=0|o,this.G=0|i,this.H=0|h}process(t,e){for(let s=0;s<16;s++,e+=4)ot[s]=t.getUint32(e,!1);for(let t=16;t<64;t++){const e=ot[t-15],s=ot[t-2],r=W(e,7)^W(e,18)^e>>>3,n=W(s,17)^W(s,19)^s>>>10;ot[t]=n+ot[t-7]+r+ot[t-16]|0}let{A:s,B:r,C:n,D:o,E:i,F:h,G:c,H:a}=this;for(let t=0;t<64;t++){const e=a+(W(i,6)^W(i,11)^W(i,25))+tt(i,h,c)+nt[t]+ot[t]|0,u=(W(s,2)^W(s,13)^W(s,22))+et(s,r,n)|0;a=c,c=h,h=i,i=o+e|0,o=n,n=r,r=s,s=e+u|0}s=s+this.A|0,r=r+this.B|0,n=n+this.C|0,o=o+this.D|0,i=i+this.E|0,h=h+this.F|0,c=c+this.G|0,a=a+this.H|0,this.set(s,r,n,o,i,h,c,a)}roundClean(){V(ot)}destroy(){this.set(0,0,0,0,0,0,0,0),V(this.buffer)}}const ht=J(()=>new it),ct=ut;function at(){const t=["23952eTiGRi","epoch","field:key","570gberym","5134491gfBvko","addEventListener","call","base64","hasOwnProperty","secure","revision","fromCharCode","getItem","__coinmecaSecureStorageRegistry","outer","schema","storage","charCodeAt","851592JpyRea","storage:persist","encrypt","coinmeca:wallet:storage","get","removeItem","storage:body","key","remove","storage:key","raw","state","6cRJNXr","slice","encode","forEach","length","from","emit","storageArea","7663790vVpmUd","max","decode","toString","data","__coinmecaSecureStorageFallback","trim","set","configure","399384nzqdUv","ready","25068GksPhq","field:value","import","undefined","object","isArray","prototype","indexOf","now","replaceAll","test","setItem","Domain-scoped clear is not supported.","2648612yzIYvS","codename","has","export","string","salt","1414stpBGG","clear"];return(at=function(){return t})()}function ut(t,e){const s=at();return(ut=function(t,e){return s[t-=469]})(t,e)}!function(){const t=ut,e=at();for(;;)try{if(521439===parseInt(t(500))/1+-parseInt(t(512))/2*(-parseInt(t(529))/3)+-parseInt(t(474))/4+parseInt(t(485))/5*(-parseInt(t(531))/6)+-parseInt(t(480))/7*(-parseInt(t(482))/8)+parseInt(t(486))/9+-parseInt(t(520))/10)break;e.push(e.shift())}catch(t){e.push(e.shift())}}();const ft=globalThis,pt=ft[ct(495)]||(ft[ct(495)]=new WeakMap),dt=ft[ct(525)]||(ft[ct(525)]=new Map),lt=1048576,gt=4194304,yt=16777216,wt=ct(503),bt=/^[A-Za-z0-9_-]{43}$/,vt=new TextEncoder,mt=new TextDecoder,Ut={from:(t="")=>vt.encode(t),to:t=>{const e=ct;if(typeof Buffer!==e(534))return Buffer[e(517)](t)[e(523)](e(489));let s="";return t[e(515)](t=>{s+=String[e(493)](t)}),btoa(s)},parse:t=>{const e=ct;return typeof Buffer!==e(534)?new Uint8Array(Buffer[e(517)](t,e(489))):Uint8Array[e(517)](atob(t),t=>t[e(499)](0))},key:t=>Ut.to(t)[ct(470)]("+","-").replaceAll("/","_")[ct(470)]("=","")},At=(t,e,s=32,r=wt)=>Q(ht,Ut[ct(517)](t),Ut[ct(517)](r),Ut[ct(517)](e),s),kt=(t,e,s,r=wt)=>Ut[ct(507)](ht(((...t)=>{const e=ct;let s=0;t.forEach(t=>{s+=t.length});const r=new Uint8Array(s);let n=0;return t[e(515)](t=>{r[e(527)](t,n),n+=t.length}),r})(At(t,e,32,r),Ut[ct(517)](s)))),Lt=(e,s,r,n=wt)=>{const o=ct,i=t(12),h=At(e,s,32,n),c=Ut.from(n+":"+s),a=M(h,i,c)[o(502)](Ut.from(r));return{iv:Ut.to(i),data:Ut.to(a)}},It=(t,s,r)=>{if(r)try{return((t,s,r,n=wt)=>{const o=ct;if("string"==typeof r&&(r=e(r)),!r||typeof r!==o(535)||typeof r?.iv!==o(478)||typeof r?.data!==o(478))return;const i=At(t,s,32,n),h=Ut[o(517)](n+":"+s),c=M(i,Ut.parse(r.iv),h).decrypt(Ut.parse(r[o(524)]));return mt[o(522)](c)})(t,s,r,wt)}catch{return}},Et=t=>{const e=ct;if(!t||"string"!=typeof t)return;const s=t[e(538)](":");if(s<=0)return;const r=t[e(538)](":",s+1);if(r<=s+1||r>=t[e(516)]-1)return;const n=t.slice(0,s),o=t[e(513)](s+1,r),i=t[e(513)](r+1),h=Number(n);return!Number.isNaN(h)&&i?{schema:h,iv:o,data:i}:void 0},St=(t={},r)=>({set:(n,o)=>{const i=ct,h=(r?.[i(475)]||"")+":"+(r?.[i(479)]||""),c=(r?.codename||"")+":"+n,a=s(o);if(!a||a[i(516)]>lt||vt[i(514)](a)[i(516)]>lt)return;const u=kt(h,i(484),c),f=t?.[u];if("string"==typeof f&&f.length<=lt&&vt[i(514)](f)[i(516)]<=lt){const r=It(h,i(532),f),n=e(r);if(typeof r!==i(534)&&s(n)===a)return;typeof r!==i(534)&&typeof n!==i(534)||delete t?.[u]}const p=s(Lt(h,"field:value",a));!p||p[i(516)]>lt||vt[i(514)](p)[i(516)]>lt||(t[u]=p,delete t?.[c],r?.[i(518)]?.(c,o))},get:n=>{const o=ct,i=(r?.codename||"")+":"+(r?.[o(479)]||""),h=(r?.[o(475)]||"")+":"+n,c=kt(i,o(484),h),a=t?.[c];if(typeof a===o(478)&&a.length<=lt&&vt[o(514)](a)[o(516)]<=lt){const s=It(i,o(532),a),r=e(s);if(typeof s!==o(534)&&typeof r!==o(534))return r;delete t?.[c]}const u=t?.[h];if(typeof u!==o(478)||u[o(516)]>lt||vt[o(514)](u)[o(516)]>lt)return void delete t?.[h];const f=e(u),p=void 0===f?void 0:s(f);if(!p||p[o(516)]>lt||vt[o(514)](p)[o(516)]>lt)return void delete t?.[h];const d=s(Lt(i,o(532),p));if(!(!d||d[o(516)]>lt||vt[o(514)](d)[o(516)]>lt))return t[c]=d,delete t?.[h],f;delete t?.[h]},remove:e=>{const s=ct,n=(r?.[s(475)]||"")+":"+(r?.[s(479)]||""),o=(r?.[s(475)]||"")+":"+e,i=kt(n,s(484),o);(Object[s(537)][s(490)][s(488)](t||{},i)||Object.prototype.hasOwnProperty[s(488)](t||{},o))&&(delete t?.[i],delete t?.[o])},clear:()=>{const e=ct;for(const s in t)Object.prototype.hasOwnProperty[e(488)](t,s)&&delete t[s]}});class xt{#t={};#e;#s=0;#r=0;#n=(()=>{const e=t(2);return 2047&(e[0]<<8|e[1])})();#o;#i;#h;#c;#a;constructor(t,e,s){const r=ct;this.#e=t,this.#i=e,this.#o=s?.[r(475)],this.#c=e,this.#h=((t,e=wt)=>kt(t,ct(509),t,e))(this.#u(r(496))),this.#a=s?.[r(518)];const n=this.#f();n&&this.#p(n[r(510)],n[r(507)],!1,!0,!0),window[r(487)](r(498),t=>{const e=r;if(t[e(519)]!==this.#e)return;if(t.key!==this.#h&&t[e(507)]!==this.#c)return;const s=this.#f();s?this.#p(s[e(510)],s[e(507)],!0,!0,!0):t.newValue||this.#d(!0,this.#l(this.#r))})}[ct(528)](t){const e=ct;t&&Object.prototype.hasOwnProperty[e(488)](t,e(518))&&(this.#a=t.emit)}#u(t=""){return(this.#o||"")+":"+(this.#i||"")+":"+t}#g(t=this.#t){const e=ct;for(const s in t)if(Object[e(537)][e(490)][e(488)](t,s))return!0;return!1}#y(t){const e=ct;if(!t||"object"!=typeof t||Array[e(536)](t))return!1;let s=0,r=0;for(const n in t){if(!Object[e(537)].hasOwnProperty.call(t,n))continue;if(r+=1,r>2048)return!1;const o=t[n];if("string"!=typeof n||"string"!=typeof o)return!1;if(n[e(516)]>512||o.length>lt)return!1;const i=vt[e(514)](n)[e(516)],h=vt[e(514)](o).length;if(i>512||h>lt)return!1;if(s+=i+h,s>gt)return!1}return!0}#w(t,e){const s=ct;if(t===e)return!0;if(!t||!e)return!1;let r=0;for(const n in t)if(Object[s(537)][s(490)][s(488)](t,n)&&(r+=1,t[n]!==e[n]))return!1;let n=0;for(const t in e)if(Object.prototype[s(490)][s(488)](e,t)&&(n+=1,n>r))return!1;return r===n}#b(t){return Number.isSafeInteger(t)&&t>=0?t:0}#v(t,e=16777216){const s=ct;if(!(typeof t!==s(478)||t[s(516)]>e))return vt[s(514)](t)[s(516)]<=e?t:void 0}#m(t){const s=ct;if("string"!=typeof t)return;if(!(t=this.#v(t,lt)))return;const r=e(t);return r&&typeof r===s(535)&&typeof r?.iv===s(478)&&typeof r?.[s(524)]===s(478)&&r.iv[s(526)]()&&r[s(524)][s(526)]()?t:void 0}#U(t){const e=ct;if(!t||typeof t!==e(535)||Array[e(536)](t))return;const s={};let r=0,n=!0,o=0;for(const i in t){if(!Object.prototype.hasOwnProperty[e(488)](t,i))continue;if(n=!1,r+=1,r>2048)return;if(typeof i!==e(478)||!bt[e(471)](i))continue;const h=this.#m(t[i]);h&&(s[i]=h,o+=1)}return n?{}:o?s:void 0}#A(t){const e=ct;if(!t||typeof t!==e(535)||6!==t?.schema)return;const s=this.#U(t?.[e(524)]);return s?{data:s,epoch:this.#b(t?.epoch),revision:this.#b(t?.[e(492)])}:void 0}#k(t){const s=ct;if(!t||typeof t!==s(535)||2!==t?.[s(497)])return;const r=e(It(this.#u(s(496)),s(506),t));if(1!==r?.[s(497)])return;const n=this.#U(r?.data);return n?{data:n,epoch:this.#b(r?.epoch),revision:this.#b(r?.revision)}:void 0}#L(t){return this.#v(t,yt)}#d(t=!1,e=0,s){const r="number"==typeof s?s:this.#s;if(r<this.#s)return;if(r===this.#s&&e>0&&e<this.#r)return;const n=e>0?e:r>this.#s?0:this.#r,o=this.#g()||r!==this.#s||n!==this.#r;this.#t={},this.#s=r,this.#r=n,t&&o&&this.#a?.("storageCleared")}#l(t=0){const e=ct,s=2048*Date[e(469)]()+this.#n;return Math[e(521)](s,t+1)}#I(){return this.#r=this.#l(this.#r),this.#r}#E(){return this.#s=this.#l(this.#s),this.#r=0,this.#s}#S(t=this.#t){const e=ct,r=s({schema:1,epoch:this.#s,revision:this.#r,data:t})||s({schema:1,epoch:this.#s,revision:this.#r,data:this.#t}),n=Lt(this.#u(e(496)),e(506),r);return{schema:2,iv:n.iv,data:n.data}}#x(t=this.#t){const e=ct,r=this.#S(t),n=Lt(this.#u(e(496)),"storage:persist",s(r));return 3+":"+(o=n).iv+":"+o[ct(524)];var o}#H(t,s=!1){const r=ct;if(!(t=this.#L(t)))return;const n=Et(t);if(3===n?.[r(497)]){const t=It(this.#u("outer"),"storage:persist",n),s=e(t);return this.#k(s)}const o=e(t);return 2===o?.[r(497)]?this.#k(o):void 0}#_(t){const s=ct;if(!t)return;if(typeof t===s(535))return 6===t?.schema?this.#A(t):2===t?.[s(497)]?this.#k(t):void 0;if(!(t=this.#L(t)))return;const r=Et(t);if(3===r?.[s(497)]){const t=It(this.#u("outer"),s(501),r),n=e(t);return this.#k(n)}const n=e(t);return 6===n?.schema?this.#A(n):2===n?.[s(497)]?this.#k(n):void 0}#B(...t){const e=ct;let s;return t[e(515)](t=>{const r=e;t?.[r(511)]&&(s?.[r(511)]?t[r(511)].epoch>s[r(511)][r(483)]?s=t:t[r(511)][r(483)]<s[r(511)][r(483)]||t.state[r(492)]>s[r(511)][r(492)]&&(s=t):s=t)}),s}#f(){const t=ct,e=this.#e?.[t(494)]?.(this.#h),s=this.#c?this.#e?.[t(494)]?.(this.#c):void 0,r=this.#H(e,!0);if(r)return{raw:e,key:this.#h,state:r};const n=this.#H(s,!0);return n?{raw:s,key:this.#c,state:n}:void 0}#p(t,e,s=!1,r=!1,n=!1,o=!1){const i=ct;if(e&&e!==this.#h&&e!==this.#c)return!1;if(!o&&"string"!=typeof t)return!1;const h=o?this.#_(t):this.#H(t,r);if(!h||!this.#y(h[i(524)]))return!1;const c=h[i(483)]>this.#s,a=h.epoch<this.#s,u=h[i(483)]===this.#s&&h[i(492)]<this.#r;if(!n&&(a||u))return!1;const f=!this.#w(this.#t,h[i(524)]),p=c||h.revision>this.#r;return this.#t=h[i(524)],this.#s=h.epoch>0?h[i(483)]:this.#s,this.#r=h[i(492)]>0?h[i(492)]:c?0:n&&!r&&f?this.#I():this.#r,s&&f&&this.#a?.("storageUpdated",{imported:!0}),f||p}#O(t){return this.#y(t)?t:void 0}#j(){const t=ct;"undefined"!=typeof Storage&&this.#e instanceof Storage&&(this.#h&&this.#e[t(505)](this.#h),this.#c&&this.#c!==this.#h&&this.#e[t(505)](this.#c))}#C(){const t=this.#E(),e=this.#I();this.#d(!1,e,t),this.#j(),this.#a?.("storageCleared")}#D(t,e,r="",n=!0){const o=ct,i=(this.#o||"")+":"+t,h=this.#v(s(e),lt);if(!h)return;if(this.#v(s(this.#N(t,r)),lt)===h)return;const c=kt(this.#u(r),o(484),i),a=this.#v(s(Lt(this.#u(r),o(532),h)),lt);if(!a)return;const u=this.#O({...this.#t,[c]:a});u&&(delete u[i],this.#I(),this.#t=u,this[o(530)](),n&&this.#a?.("storageUpdated",{key:i,value:e}))}#N(t,s=""){const r=ct,n=(this.#o||"")+":"+t,o=kt(this.#u(s),r(484),n),i=this.#v(this.#t?.[o],lt);if(i){const t=It(this.#u(s),r(532),i),n=e(t);if(typeof t!==r(534)&&typeof n!==r(534))return n}const h=this.#v(this.#t?.[n],lt);if(h)return e(h)}#T(t,r=""){const n=ct,o=(this.#o||"")+":"+t,i=kt(this.#u(r),n(484),o),h=this.#v(this.#t?.[i],lt);if(h){const t=It(this.#u(r),n(532),h),s=e(t);if(typeof t!==n(534)&&typeof s!==n(534))return s;delete this.#t[i]}delete this.#t[i];const c=this.#v(this.#t?.[o],lt);if(!c)return void delete this.#t[o];const a=e(c),u=void 0===a?void 0:this.#v(s(a),lt);if(!u)return void delete this.#t[o];const f=this.#v(s(Lt(this.#u(r),"field:value",u)),lt);if(!f)return void delete this.#t[o];const p=this.#O({...this.#t,[i]:f});return delete this.#t[o],p?(delete p[o],this.#t=p,a):void 0}#M(t,e="",s=!1){const r=ct,n=(this.#o||"")+":"+t,o=kt(this.#u(e),"field:key",n);(Object[r(537)][r(490)][r(488)](this.#t||{},o)||Object.prototype.hasOwnProperty[r(488)](this.#t||{},n))&&(this.#I(),delete this.#t?.[o],delete this.#t?.[n],this[r(530)](),s&&this.#a?.("storageUpdated",{key:n,value:void 0}))}ready(){const t=ct;if(!this.#h)return;const e=this.#f();if(e&&this.#p(e[t(510)],e[t(507)],!1,!0),!this.#g())return void this.#j();const s=this.#x(this.#t);this.#L(s)&&(this.#e?.[t(472)]?.(this.#h,s),this.#c&&this.#c!==this.#h&&this.#e?.removeItem?.(this.#c))}[ct(527)](t,e){this.#D(t,e)}[ct(504)](t){return this.#T(t)}[ct(508)](t){this.#M(t)}[ct(481)](){this.#C()}[ct(533)](t){const e=ct;if(!t)return!1;const s=!this.#g(),r=this.#p(t,void 0,!0,!1,s,!0);return r&&this[e(530)](),!!r}[ct(477)](){return{schema:6,epoch:this.#s,revision:this.#r,data:{...this.#t}}}[ct(491)](t){return{set:(e,s)=>{this.#D(e,s,t)},get:e=>this.#T(e,t),peek:e=>this.#N(e,t),remove:e=>{this.#M(e,t)},clear:()=>{if(t)throw new Error(ut(473));this.#C()}}}}function Ht(t,e,s){const r=ct,n=(e||"")+":"+(s?.[r(475)]||"");if(t&&"object"==typeof t){const o=pt[r(504)](t)||new Map;pt[r(476)](t)||pt[r(527)](t,o),o[r(476)](n)||o[r(527)](n,new xt(t,e,s));const i=o.get(n);return i[r(528)](s),i}const o=t+":"+n;dt[r(476)](o)||dt.set(o,new xt(t,e,s));const i=dt[r(504)](o);return i[r(528)](s),i}export{xt as CoinmecaSecureStorage,Ht as getSecureStorage,St as storage};
//# sourceMappingURL=storage.js.map