mini_program_gizwits_sdk 3.2.16 → 3.2.17

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 CHANGED
@@ -15,4 +15,4 @@ function(e){var t=s,i=t.lib,n=i.WordArray,r=i.Hasher,a=t.algo,c=n.create([0,1,2,
15
15
  * derived from CryptoJS.mode.CTR
16
16
  * Jan Hruby jhruby.web@gmail.com
17
17
  */
18
- s.mode.CTRGladman=function(){var e=s.lib.BlockCipherMode.extend();function t(e){if(255==(e>>24&255)){var t=e>>16&255,i=e>>8&255,s=255&e;255===t?(t=0,255===i?(i=0,255===s?s=0:++s):++i):++t,e=0,e+=t<<16,e+=i<<8,e+=s}else e+=1<<24;return e}var i=e.Encryptor=e.extend({processBlock:function(e,i){var s=this._cipher,n=s.blockSize,r=this._iv,a=this._counter;r&&(a=this._counter=r.slice(0),this._iv=void 0),function(e){0===(e[0]=t(e[0]))&&(e[1]=t(e[1]))}(a);var c=a.slice(0);s.encryptBlock(c,0);for(var o=0;o<n;o++)e[i+o]^=c[o]}});return e.Decryptor=i,e}(),s.mode.CTRGladman)},function(e,t,i){var s,n,r;e.exports=(r=i(0),i(1),r.mode.OFB=(s=r.lib.BlockCipherMode.extend(),n=s.Encryptor=s.extend({processBlock:function(e,t){var i=this._cipher,s=i.blockSize,n=this._iv,r=this._keystream;n&&(r=this._keystream=n.slice(0),this._iv=void 0),i.encryptBlock(r,0);for(var a=0;a<s;a++)e[t+a]^=r[a]}}),s.Decryptor=n,s),r.mode.OFB)},function(e,t,i){var s,n;e.exports=(n=i(0),i(1),n.mode.ECB=((s=n.lib.BlockCipherMode.extend()).Encryptor=s.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),s.Decryptor=s.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),s),n.mode.ECB)},function(e,t,i){var s;e.exports=(s=i(0),i(1),s.pad.AnsiX923={pad:function(e,t){var i=e.sigBytes,s=4*t,n=s-i%s,r=i+n-1;e.clamp(),e.words[r>>>2]|=n<<24-r%4*8,e.sigBytes+=n},unpad:function(e){var t=255&e.words[e.sigBytes-1>>>2];e.sigBytes-=t}},s.pad.Ansix923)},function(e,t,i){var s;e.exports=(s=i(0),i(1),s.pad.Iso10126={pad:function(e,t){var i=4*t,n=i-e.sigBytes%i;e.concat(s.lib.WordArray.random(n-1)).concat(s.lib.WordArray.create([n<<24],1))},unpad:function(e){var t=255&e.words[e.sigBytes-1>>>2];e.sigBytes-=t}},s.pad.Iso10126)},function(e,t,i){var s;e.exports=(s=i(0),i(1),s.pad.Iso97971={pad:function(e,t){e.concat(s.lib.WordArray.create([2147483648],1)),s.pad.ZeroPadding.pad(e,t)},unpad:function(e){s.pad.ZeroPadding.unpad(e),e.sigBytes--}},s.pad.Iso97971)},function(e,t,i){var s;e.exports=(s=i(0),i(1),s.pad.ZeroPadding={pad:function(e,t){var i=4*t;e.clamp(),e.sigBytes+=i-(e.sigBytes%i||i)},unpad:function(e){var t=e.words,i=e.sigBytes-1;for(i=e.sigBytes-1;i>=0;i--)if(t[i>>>2]>>>24-i%4*8&255){e.sigBytes=i+1;break}}},s.pad.ZeroPadding)},function(e,t,i){var s;e.exports=(s=i(0),i(1),s.pad.NoPadding={pad:function(){},unpad:function(){}},s.pad.NoPadding)},function(e,t,i){var s,n,r,a;e.exports=(a=i(0),i(1),n=(s=a).lib.CipherParams,r=s.enc.Hex,s.format.Hex={stringify:function(e){return e.ciphertext.toString(r)},parse:function(e){var t=r.parse(e);return n.create({ciphertext:t})}},a.format.Hex)},function(e,t,i){var s;e.exports=(s=i(0),i(7),i(8),i(6),i(1),function(){var e=s,t=e.lib.BlockCipher,i=e.algo,n=[],r=[],a=[],c=[],o=[],d=[],l=[],u=[],h=[],f=[];!function(){for(var e=[],t=0;t<256;t++)e[t]=t<128?t<<1:t<<1^283;var i=0,s=0;for(t=0;t<256;t++){var p=s^s<<1^s<<2^s<<3^s<<4;p=p>>>8^255&p^99,n[i]=p,r[p]=i;var v=e[i],g=e[v],y=e[g],_=257*e[p]^16843008*p;a[i]=_<<24|_>>>8,c[i]=_<<16|_>>>16,o[i]=_<<8|_>>>24,d[i]=_,_=16843009*y^65537*g^257*v^16843008*i,l[p]=_<<24|_>>>8,u[p]=_<<16|_>>>16,h[p]=_<<8|_>>>24,f[p]=_,i?(i=v^e[e[e[y^v]]],s^=e[e[s]]):i=s=1}}();var p=[0,1,2,4,8,16,32,64,128,27,54],v=i.AES=t.extend({_doReset:function(){if(!this._nRounds||this._keyPriorReset!==this._key){for(var e=this._keyPriorReset=this._key,t=e.words,i=e.sigBytes/4,s=4*((this._nRounds=i+6)+1),r=this._keySchedule=[],a=0;a<s;a++)a<i?r[a]=t[a]:(d=r[a-1],a%i?i>6&&a%i==4&&(d=n[d>>>24]<<24|n[d>>>16&255]<<16|n[d>>>8&255]<<8|n[255&d]):(d=n[(d=d<<8|d>>>24)>>>24]<<24|n[d>>>16&255]<<16|n[d>>>8&255]<<8|n[255&d],d^=p[a/i|0]<<24),r[a]=r[a-i]^d);for(var c=this._invKeySchedule=[],o=0;o<s;o++){if(a=s-o,o%4)var d=r[a];else d=r[a-4];c[o]=o<4||a<=4?d:l[n[d>>>24]]^u[n[d>>>16&255]]^h[n[d>>>8&255]]^f[n[255&d]]}}},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,a,c,o,d,n)},decryptBlock:function(e,t){var i=e[t+1];e[t+1]=e[t+3],e[t+3]=i,this._doCryptBlock(e,t,this._invKeySchedule,l,u,h,f,r),i=e[t+1],e[t+1]=e[t+3],e[t+3]=i},_doCryptBlock:function(e,t,i,s,n,r,a,c){for(var o=this._nRounds,d=e[t]^i[0],l=e[t+1]^i[1],u=e[t+2]^i[2],h=e[t+3]^i[3],f=4,p=1;p<o;p++){var v=s[d>>>24]^n[l>>>16&255]^r[u>>>8&255]^a[255&h]^i[f++],g=s[l>>>24]^n[u>>>16&255]^r[h>>>8&255]^a[255&d]^i[f++],y=s[u>>>24]^n[h>>>16&255]^r[d>>>8&255]^a[255&l]^i[f++],_=s[h>>>24]^n[d>>>16&255]^r[l>>>8&255]^a[255&u]^i[f++];d=v,l=g,u=y,h=_}v=(c[d>>>24]<<24|c[l>>>16&255]<<16|c[u>>>8&255]<<8|c[255&h])^i[f++],g=(c[l>>>24]<<24|c[u>>>16&255]<<16|c[h>>>8&255]<<8|c[255&d])^i[f++],y=(c[u>>>24]<<24|c[h>>>16&255]<<16|c[d>>>8&255]<<8|c[255&l])^i[f++],_=(c[h>>>24]<<24|c[d>>>16&255]<<16|c[l>>>8&255]<<8|c[255&u])^i[f++],e[t]=v,e[t+1]=g,e[t+2]=y,e[t+3]=_},keySize:8});e.AES=t._createHelper(v)}(),s.AES)},function(e,t,i){var s;e.exports=(s=i(0),i(7),i(8),i(6),i(1),function(){var e=s,t=e.lib,i=t.WordArray,n=t.BlockCipher,r=e.algo,a=[57,49,41,33,25,17,9,1,58,50,42,34,26,18,10,2,59,51,43,35,27,19,11,3,60,52,44,36,63,55,47,39,31,23,15,7,62,54,46,38,30,22,14,6,61,53,45,37,29,21,13,5,28,20,12,4],c=[14,17,11,24,1,5,3,28,15,6,21,10,23,19,12,4,26,8,16,7,27,20,13,2,41,52,31,37,47,55,30,40,51,45,33,48,44,49,39,56,34,53,46,42,50,36,29,32],o=[1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28],d=[{0:8421888,268435456:32768,536870912:8421378,805306368:2,1073741824:512,1342177280:8421890,1610612736:8389122,1879048192:8388608,2147483648:514,2415919104:8389120,2684354560:33280,2952790016:8421376,3221225472:32770,3489660928:8388610,3758096384:0,4026531840:33282,134217728:0,402653184:8421890,671088640:33282,939524096:32768,1207959552:8421888,1476395008:512,1744830464:8421378,2013265920:2,2281701376:8389120,2550136832:33280,2818572288:8421376,3087007744:8389122,3355443200:8388610,3623878656:32770,3892314112:514,4160749568:8388608,1:32768,268435457:2,536870913:8421888,805306369:8388608,1073741825:8421378,1342177281:33280,1610612737:512,1879048193:8389122,2147483649:8421890,2415919105:8421376,2684354561:8388610,2952790017:33282,3221225473:514,3489660929:8389120,3758096385:32770,4026531841:0,134217729:8421890,402653185:8421376,671088641:8388608,939524097:512,1207959553:32768,1476395009:8388610,1744830465:2,2013265921:33282,2281701377:32770,2550136833:8389122,2818572289:514,3087007745:8421888,3355443201:8389120,3623878657:0,3892314113:33280,4160749569:8421378},{0:1074282512,16777216:16384,33554432:524288,50331648:1074266128,67108864:1073741840,83886080:1074282496,100663296:1073758208,117440512:16,134217728:540672,150994944:1073758224,167772160:1073741824,184549376:540688,201326592:524304,218103808:0,234881024:16400,251658240:1074266112,8388608:1073758208,25165824:540688,41943040:16,58720256:1073758224,75497472:1074282512,92274688:1073741824,109051904:524288,125829120:1074266128,142606336:524304,159383552:0,176160768:16384,192937984:1074266112,209715200:1073741840,226492416:540672,243269632:1074282496,260046848:16400,268435456:0,285212672:1074266128,301989888:1073758224,318767104:1074282496,335544320:1074266112,352321536:16,369098752:540688,385875968:16384,402653184:16400,419430400:524288,436207616:524304,452984832:1073741840,469762048:540672,486539264:1073758208,503316480:1073741824,520093696:1074282512,276824064:540688,293601280:524288,310378496:1074266112,327155712:16384,343932928:1073758208,360710144:1074282512,377487360:16,394264576:1073741824,411041792:1074282496,427819008:1073741840,444596224:1073758224,461373440:524304,478150656:0,494927872:16400,511705088:1074266128,528482304:540672},{0:260,1048576:0,2097152:67109120,3145728:65796,4194304:65540,5242880:67108868,6291456:67174660,7340032:67174400,8388608:67108864,9437184:67174656,10485760:65792,11534336:67174404,12582912:67109124,13631488:65536,14680064:4,15728640:256,524288:67174656,1572864:67174404,2621440:0,3670016:67109120,4718592:67108868,5767168:65536,6815744:65540,7864320:260,8912896:4,9961472:256,11010048:67174400,12058624:65796,13107200:65792,14155776:67109124,15204352:67174660,16252928:67108864,16777216:67174656,17825792:65540,18874368:65536,19922944:67109120,20971520:256,22020096:67174660,23068672:67108868,24117248:0,25165824:67109124,26214400:67108864,27262976:4,28311552:65792,29360128:67174400,30408704:260,31457280:65796,32505856:67174404,17301504:67108864,18350080:260,19398656:67174656,20447232:0,21495808:65540,22544384:67109120,23592960:256,24641536:67174404,25690112:65536,26738688:67174660,27787264:65796,28835840:67108868,29884416:67109124,30932992:67174400,31981568:4,33030144:65792},{0:2151682048,65536:2147487808,131072:4198464,196608:2151677952,262144:0,327680:4198400,393216:2147483712,458752:4194368,524288:2147483648,589824:4194304,655360:64,720896:2147487744,786432:2151678016,851968:4160,917504:4096,983040:2151682112,32768:2147487808,98304:64,163840:2151678016,229376:2147487744,294912:4198400,360448:2151682112,425984:0,491520:2151677952,557056:4096,622592:2151682048,688128:4194304,753664:4160,819200:2147483648,884736:4194368,950272:4198464,1015808:2147483712,1048576:4194368,1114112:4198400,1179648:2147483712,1245184:0,1310720:4160,1376256:2151678016,1441792:2151682048,1507328:2147487808,1572864:2151682112,1638400:2147483648,1703936:2151677952,1769472:4198464,1835008:2147487744,1900544:4194304,1966080:64,2031616:4096,1081344:2151677952,1146880:2151682112,1212416:0,1277952:4198400,1343488:4194368,1409024:2147483648,1474560:2147487808,1540096:64,1605632:2147483712,1671168:4096,1736704:2147487744,1802240:2151678016,1867776:4160,1933312:2151682048,1998848:4194304,2064384:4198464},{0:128,4096:17039360,8192:262144,12288:536870912,16384:537133184,20480:16777344,24576:553648256,28672:262272,32768:16777216,36864:537133056,40960:536871040,45056:553910400,49152:553910272,53248:0,57344:17039488,61440:553648128,2048:17039488,6144:553648256,10240:128,14336:17039360,18432:262144,22528:537133184,26624:553910272,30720:536870912,34816:537133056,38912:0,43008:553910400,47104:16777344,51200:536871040,55296:553648128,59392:16777216,63488:262272,65536:262144,69632:128,73728:536870912,77824:553648256,81920:16777344,86016:553910272,90112:537133184,94208:16777216,98304:553910400,102400:553648128,106496:17039360,110592:537133056,114688:262272,118784:536871040,122880:0,126976:17039488,67584:553648256,71680:16777216,75776:17039360,79872:537133184,83968:536870912,88064:17039488,92160:128,96256:553910272,100352:262272,104448:553910400,108544:0,112640:553648128,116736:16777344,120832:262144,124928:537133056,129024:536871040},{0:268435464,256:8192,512:270532608,768:270540808,1024:268443648,1280:2097152,1536:2097160,1792:268435456,2048:0,2304:268443656,2560:2105344,2816:8,3072:270532616,3328:2105352,3584:8200,3840:270540800,128:270532608,384:270540808,640:8,896:2097152,1152:2105352,1408:268435464,1664:268443648,1920:8200,2176:2097160,2432:8192,2688:268443656,2944:270532616,3200:0,3456:270540800,3712:2105344,3968:268435456,4096:268443648,4352:270532616,4608:270540808,4864:8200,5120:2097152,5376:268435456,5632:268435464,5888:2105344,6144:2105352,6400:0,6656:8,6912:270532608,7168:8192,7424:268443656,7680:270540800,7936:2097160,4224:8,4480:2105344,4736:2097152,4992:268435464,5248:268443648,5504:8200,5760:270540808,6016:270532608,6272:270540800,6528:270532616,6784:8192,7040:2105352,7296:2097160,7552:0,7808:268435456,8064:268443656},{0:1048576,16:33555457,32:1024,48:1049601,64:34604033,80:0,96:1,112:34603009,128:33555456,144:1048577,160:33554433,176:34604032,192:34603008,208:1025,224:1049600,240:33554432,8:34603009,24:0,40:33555457,56:34604032,72:1048576,88:33554433,104:33554432,120:1025,136:1049601,152:33555456,168:34603008,184:1048577,200:1024,216:34604033,232:1,248:1049600,256:33554432,272:1048576,288:33555457,304:34603009,320:1048577,336:33555456,352:34604032,368:1049601,384:1025,400:34604033,416:1049600,432:1,448:0,464:34603008,480:33554433,496:1024,264:1049600,280:33555457,296:34603009,312:1,328:33554432,344:1048576,360:1025,376:34604032,392:33554433,408:34603008,424:0,440:34604033,456:1049601,472:1024,488:33555456,504:1048577},{0:134219808,1:131072,2:134217728,3:32,4:131104,5:134350880,6:134350848,7:2048,8:134348800,9:134219776,10:133120,11:134348832,12:2080,13:0,14:134217760,15:133152,2147483648:2048,2147483649:134350880,2147483650:134219808,2147483651:134217728,2147483652:134348800,2147483653:133120,2147483654:133152,2147483655:32,2147483656:134217760,2147483657:2080,2147483658:131104,2147483659:134350848,2147483660:0,2147483661:134348832,2147483662:134219776,2147483663:131072,16:133152,17:134350848,18:32,19:2048,20:134219776,21:134217760,22:134348832,23:131072,24:0,25:131104,26:134348800,27:134219808,28:134350880,29:133120,30:2080,31:134217728,2147483664:131072,2147483665:2048,2147483666:134348832,2147483667:133152,2147483668:32,2147483669:134348800,2147483670:134217728,2147483671:134219808,2147483672:134350880,2147483673:134217760,2147483674:134219776,2147483675:0,2147483676:133120,2147483677:2080,2147483678:131104,2147483679:134350848}],l=[4160749569,528482304,33030144,2064384,129024,8064,504,2147483679],u=r.DES=n.extend({_doReset:function(){for(var e=this._key.words,t=[],i=0;i<56;i++){var s=a[i]-1;t[i]=e[s>>>5]>>>31-s%32&1}for(var n=this._subKeys=[],r=0;r<16;r++){var d=n[r]=[],l=o[r];for(i=0;i<24;i++)d[i/6|0]|=t[(c[i]-1+l)%28]<<31-i%6,d[4+(i/6|0)]|=t[28+(c[i+24]-1+l)%28]<<31-i%6;for(d[0]=d[0]<<1|d[0]>>>31,i=1;i<7;i++)d[i]=d[i]>>>4*(i-1)+3;d[7]=d[7]<<5|d[7]>>>27}var u=this._invSubKeys=[];for(i=0;i<16;i++)u[i]=n[15-i]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._subKeys)},decryptBlock:function(e,t){this._doCryptBlock(e,t,this._invSubKeys)},_doCryptBlock:function(e,t,i){this._lBlock=e[t],this._rBlock=e[t+1],h.call(this,4,252645135),h.call(this,16,65535),f.call(this,2,858993459),f.call(this,8,16711935),h.call(this,1,1431655765);for(var s=0;s<16;s++){for(var n=i[s],r=this._lBlock,a=this._rBlock,c=0,o=0;o<8;o++)c|=d[o][((a^n[o])&l[o])>>>0];this._lBlock=a,this._rBlock=r^c}var u=this._lBlock;this._lBlock=this._rBlock,this._rBlock=u,h.call(this,1,1431655765),f.call(this,8,16711935),f.call(this,2,858993459),h.call(this,16,65535),h.call(this,4,252645135),e[t]=this._lBlock,e[t+1]=this._rBlock},keySize:2,ivSize:2,blockSize:2});function h(e,t){var i=(this._lBlock>>>e^this._rBlock)&t;this._rBlock^=i,this._lBlock^=i<<e}function f(e,t){var i=(this._rBlock>>>e^this._lBlock)&t;this._lBlock^=i,this._rBlock^=i<<e}e.DES=n._createHelper(u);var p=r.TripleDES=n.extend({_doReset:function(){var e=this._key.words;if(2!==e.length&&4!==e.length&&e.length<6)throw new Error("Invalid key length - 3DES requires the key length to be 64, 128, 192 or >192.");var t=e.slice(0,2),s=e.length<4?e.slice(0,2):e.slice(2,4),n=e.length<6?e.slice(0,2):e.slice(4,6);this._des1=u.createEncryptor(i.create(t)),this._des2=u.createEncryptor(i.create(s)),this._des3=u.createEncryptor(i.create(n))},encryptBlock:function(e,t){this._des1.encryptBlock(e,t),this._des2.decryptBlock(e,t),this._des3.encryptBlock(e,t)},decryptBlock:function(e,t){this._des3.decryptBlock(e,t),this._des2.encryptBlock(e,t),this._des1.decryptBlock(e,t)},keySize:6,ivSize:2,blockSize:2});e.TripleDES=n._createHelper(p)}(),s.TripleDES)},function(e,t,i){var s;e.exports=(s=i(0),i(7),i(8),i(6),i(1),function(){var e=s,t=e.lib.StreamCipher,i=e.algo,n=i.RC4=t.extend({_doReset:function(){for(var e=this._key,t=e.words,i=e.sigBytes,s=this._S=[],n=0;n<256;n++)s[n]=n;n=0;for(var r=0;n<256;n++){var a=n%i,c=t[a>>>2]>>>24-a%4*8&255;r=(r+s[n]+c)%256;var o=s[n];s[n]=s[r],s[r]=o}this._i=this._j=0},_doProcessBlock:function(e,t){e[t]^=r.call(this)},keySize:8,ivSize:0});function r(){for(var e=this._S,t=this._i,i=this._j,s=0,n=0;n<4;n++){i=(i+e[t=(t+1)%256])%256;var r=e[t];e[t]=e[i],e[i]=r,s|=e[(e[t]+e[i])%256]<<24-8*n}return this._i=t,this._j=i,s}e.RC4=t._createHelper(n);var a=i.RC4Drop=n.extend({cfg:n.cfg.extend({drop:192}),_doReset:function(){n._doReset.call(this);for(var e=this.cfg.drop;e>0;e--)r.call(this)}});e.RC4Drop=t._createHelper(a)}(),s.RC4)},function(e,t,i){var s;e.exports=(s=i(0),i(7),i(8),i(6),i(1),function(){var e=s,t=e.lib.StreamCipher,i=e.algo,n=[],r=[],a=[],c=i.Rabbit=t.extend({_doReset:function(){for(var e=this._key.words,t=this.cfg.iv,i=0;i<4;i++)e[i]=16711935&(e[i]<<8|e[i]>>>24)|4278255360&(e[i]<<24|e[i]>>>8);var s=this._X=[e[0],e[3]<<16|e[2]>>>16,e[1],e[0]<<16|e[3]>>>16,e[2],e[1]<<16|e[0]>>>16,e[3],e[2]<<16|e[1]>>>16],n=this._C=[e[2]<<16|e[2]>>>16,4294901760&e[0]|65535&e[1],e[3]<<16|e[3]>>>16,4294901760&e[1]|65535&e[2],e[0]<<16|e[0]>>>16,4294901760&e[2]|65535&e[3],e[1]<<16|e[1]>>>16,4294901760&e[3]|65535&e[0]];for(this._b=0,i=0;i<4;i++)o.call(this);for(i=0;i<8;i++)n[i]^=s[i+4&7];if(t){var r=t.words,a=r[0],c=r[1],d=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),l=16711935&(c<<8|c>>>24)|4278255360&(c<<24|c>>>8),u=d>>>16|4294901760&l,h=l<<16|65535&d;for(n[0]^=d,n[1]^=u,n[2]^=l,n[3]^=h,n[4]^=d,n[5]^=u,n[6]^=l,n[7]^=h,i=0;i<4;i++)o.call(this)}},_doProcessBlock:function(e,t){var i=this._X;o.call(this),n[0]=i[0]^i[5]>>>16^i[3]<<16,n[1]=i[2]^i[7]>>>16^i[5]<<16,n[2]=i[4]^i[1]>>>16^i[7]<<16,n[3]=i[6]^i[3]>>>16^i[1]<<16;for(var s=0;s<4;s++)n[s]=16711935&(n[s]<<8|n[s]>>>24)|4278255360&(n[s]<<24|n[s]>>>8),e[t+s]^=n[s]},blockSize:4,ivSize:2});function o(){for(var e=this._X,t=this._C,i=0;i<8;i++)r[i]=t[i];for(t[0]=t[0]+1295307597+this._b|0,t[1]=t[1]+3545052371+(t[0]>>>0<r[0]>>>0?1:0)|0,t[2]=t[2]+886263092+(t[1]>>>0<r[1]>>>0?1:0)|0,t[3]=t[3]+1295307597+(t[2]>>>0<r[2]>>>0?1:0)|0,t[4]=t[4]+3545052371+(t[3]>>>0<r[3]>>>0?1:0)|0,t[5]=t[5]+886263092+(t[4]>>>0<r[4]>>>0?1:0)|0,t[6]=t[6]+1295307597+(t[5]>>>0<r[5]>>>0?1:0)|0,t[7]=t[7]+3545052371+(t[6]>>>0<r[6]>>>0?1:0)|0,this._b=t[7]>>>0<r[7]>>>0?1:0,i=0;i<8;i++){var s=e[i]+t[i],n=65535&s,c=s>>>16,o=((n*n>>>17)+n*c>>>15)+c*c,d=((4294901760&s)*s|0)+((65535&s)*s|0);a[i]=o^d}e[0]=a[0]+(a[7]<<16|a[7]>>>16)+(a[6]<<16|a[6]>>>16)|0,e[1]=a[1]+(a[0]<<8|a[0]>>>24)+a[7]|0,e[2]=a[2]+(a[1]<<16|a[1]>>>16)+(a[0]<<16|a[0]>>>16)|0,e[3]=a[3]+(a[2]<<8|a[2]>>>24)+a[1]|0,e[4]=a[4]+(a[3]<<16|a[3]>>>16)+(a[2]<<16|a[2]>>>16)|0,e[5]=a[5]+(a[4]<<8|a[4]>>>24)+a[3]|0,e[6]=a[6]+(a[5]<<16|a[5]>>>16)+(a[4]<<16|a[4]>>>16)|0,e[7]=a[7]+(a[6]<<8|a[6]>>>24)+a[5]|0}e.Rabbit=t._createHelper(c)}(),s.Rabbit)},function(e,t,i){var s;e.exports=(s=i(0),i(7),i(8),i(6),i(1),function(){var e=s,t=e.lib.StreamCipher,i=e.algo,n=[],r=[],a=[],c=i.RabbitLegacy=t.extend({_doReset:function(){var e=this._key.words,t=this.cfg.iv,i=this._X=[e[0],e[3]<<16|e[2]>>>16,e[1],e[0]<<16|e[3]>>>16,e[2],e[1]<<16|e[0]>>>16,e[3],e[2]<<16|e[1]>>>16],s=this._C=[e[2]<<16|e[2]>>>16,4294901760&e[0]|65535&e[1],e[3]<<16|e[3]>>>16,4294901760&e[1]|65535&e[2],e[0]<<16|e[0]>>>16,4294901760&e[2]|65535&e[3],e[1]<<16|e[1]>>>16,4294901760&e[3]|65535&e[0]];this._b=0;for(var n=0;n<4;n++)o.call(this);for(n=0;n<8;n++)s[n]^=i[n+4&7];if(t){var r=t.words,a=r[0],c=r[1],d=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),l=16711935&(c<<8|c>>>24)|4278255360&(c<<24|c>>>8),u=d>>>16|4294901760&l,h=l<<16|65535&d;for(s[0]^=d,s[1]^=u,s[2]^=l,s[3]^=h,s[4]^=d,s[5]^=u,s[6]^=l,s[7]^=h,n=0;n<4;n++)o.call(this)}},_doProcessBlock:function(e,t){var i=this._X;o.call(this),n[0]=i[0]^i[5]>>>16^i[3]<<16,n[1]=i[2]^i[7]>>>16^i[5]<<16,n[2]=i[4]^i[1]>>>16^i[7]<<16,n[3]=i[6]^i[3]>>>16^i[1]<<16;for(var s=0;s<4;s++)n[s]=16711935&(n[s]<<8|n[s]>>>24)|4278255360&(n[s]<<24|n[s]>>>8),e[t+s]^=n[s]},blockSize:4,ivSize:2});function o(){for(var e=this._X,t=this._C,i=0;i<8;i++)r[i]=t[i];for(t[0]=t[0]+1295307597+this._b|0,t[1]=t[1]+3545052371+(t[0]>>>0<r[0]>>>0?1:0)|0,t[2]=t[2]+886263092+(t[1]>>>0<r[1]>>>0?1:0)|0,t[3]=t[3]+1295307597+(t[2]>>>0<r[2]>>>0?1:0)|0,t[4]=t[4]+3545052371+(t[3]>>>0<r[3]>>>0?1:0)|0,t[5]=t[5]+886263092+(t[4]>>>0<r[4]>>>0?1:0)|0,t[6]=t[6]+1295307597+(t[5]>>>0<r[5]>>>0?1:0)|0,t[7]=t[7]+3545052371+(t[6]>>>0<r[6]>>>0?1:0)|0,this._b=t[7]>>>0<r[7]>>>0?1:0,i=0;i<8;i++){var s=e[i]+t[i],n=65535&s,c=s>>>16,o=((n*n>>>17)+n*c>>>15)+c*c,d=((4294901760&s)*s|0)+((65535&s)*s|0);a[i]=o^d}e[0]=a[0]+(a[7]<<16|a[7]>>>16)+(a[6]<<16|a[6]>>>16)|0,e[1]=a[1]+(a[0]<<8|a[0]>>>24)+a[7]|0,e[2]=a[2]+(a[1]<<16|a[1]>>>16)+(a[0]<<16|a[0]>>>16)|0,e[3]=a[3]+(a[2]<<8|a[2]>>>24)+a[1]|0,e[4]=a[4]+(a[3]<<16|a[3]>>>16)+(a[2]<<16|a[2]>>>16)|0,e[5]=a[5]+(a[4]<<8|a[4]>>>24)+a[3]|0,e[6]=a[6]+(a[5]<<16|a[5]>>>16)+(a[4]<<16|a[4]>>>16)|0,e[7]=a[7]+(a[6]<<8|a[6]>>>24)+a[5]|0}e.RabbitLegacy=t._createHelper(c)}(),s.RabbitLegacy)},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(16),r=i(4),a=i(2);class c extends r.default{}c.pack=(e,t,i)=>s(void 0,void 0,void 0,(function*(){const s=yield n.default.getConfigFile(e);if(s){const e="var_len"===s.protocolType,n=[0,0,0,3],r=[0];let c=[0];const o=[0,147];let d=[0,0,0,0],l=[2];if(t){c=[1];const e=a.fillString(t.length.toString(16),4),i=a.hexStrint2byte(e),s=a.string2Bytes(t);d=d.concat(i).concat(s)}if(e){l=[18];let e="";if(i){const t=i.reduce((e,t)=>Object.assign(Object.assign({},e),{[t]:1}),{});s.entities[0].attrs.map(i=>{e=t[i.name]?`1${e}`:`0${e}`})}else s.entities[0].attrs.map(()=>{e=`1${e}`});e=a.fillString(e,8*Math.ceil(e.length/8)),l=l.concat(a.hexStrint2byte(parseInt(e,2).toString(16)))}const u=c.concat(o).concat(d).concat(l);return r[0]=u.length,n.concat(r).concat(u)}return null})),t.default=c},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(5),r=i(3),a=i(12),c=i(10);t.default=class{constructor({appID:e,token:t,uid:i,limitSocketNum:r=!0}){this._bindingDevices=null,this._connections={},this.updateToken=({token:e,uid:t})=>{this.token=e,this.uid=t},this._getDevice=e=>{if(null===this._bindingDevices)return n.default.GIZ_SDK_SDK_NOT_INITIALIZED;const t=this._bindingDevices[e];return null==t?n.default.GIZ_OPENAPI_DEVICE_NOT_BOUND:t},this._getConnect=e=>{const t=this._getWebsocketConnInfo(e);return this._connections[t]},this._getDeviceAndConnect=e=>{const t=this._getDevice(e);if(c.isError(t))return t;const i=this._getConnect(t);return null==i?n.default.GIZ_SDK_DEVICE_NOT_SUBSCRIBED:[t,i]},this.connectDevice=e=>{const t=this._getWebsocketConnInfo(e);let i=this._connections[t];if(null==i){const e=Object.keys(this._connections).length;if(0!==this._maxSocketNum&&e>=this._maxSocketNum)return{success:!1,errorCode:n.default.MAX_CONNECT};i=new o({appID:this.appID,token:this.token,uid:this.uid,wsInfo:t,onDeviceStatusChanged:this._handleDeviceStatusChanged,onBindingChanged:this._handleBindingChanged,onSocketStatusChanged:this._handleSocketStatusChanged}),this._connections[t]=i}return i._addSubDid(e.did),null==i._websocket?i._connectWS():i.ready&&i._subDevices([e.did]),{success:!0}},this.disConnectDevice=e=>{const t=this._getWebsocketConnInfo(e);let i=this._connections[t];return i&&i._unSubDevices([e.did]),{success:!0}},this.connect=e=>{const t=this._getDevice(e);if(c.isError(t))return t;const i=this.connectDevice(t);return i.success?null:i.errorCode},this.send=(e,t)=>{const i=this._getDeviceAndConnect(e);return c.isError(i)?i:i[1]._send({cmd:"c2s_raw",data:{did:e,raw:t}})},this.writeData=(e,t)=>{const i=this._getConnect(e);return null!=i?i._send({cmd:"c2s_write",data:{did:e.did,attrs:t}}):{success:!1}},this.write=(e,t)=>{const i=this._getDeviceAndConnect(e);return c.isError(i)?i:i[1]._send({cmd:"c2s_write",data:{did:e,attrs:t}})},this.readStatus=(e,t)=>{const i=this._getConnect(e),s=null!=i;return s&&i._send({cmd:"c2s_read",data:{did:e.did,names:t}}),{success:s}},this.read=(e,t)=>{const i=this._getDeviceAndConnect(e);return c.isError(i)?i:i[1]._send({cmd:"c2s_read",data:{did:e,names:t}})},this.destory=()=>{Object.values(this._connections).forEach(e=>e.destory())},this.subscribeDeviceStatus=e=>{this._onDeviceStatusChanged=e},this.subscribeBindingChanged=e=>{this._onBindingChanged=e},this.subscribeSocketStatus=e=>{this._onSocketStatusChanged=e},this._handleDeviceStatusChanged=e=>{this._onDeviceStatusChanged&&this._onDeviceStatusChanged(e)},this._handleBindingChanged=()=>{this._onBindingChanged&&this._onBindingChanged()},this._handleSocketStatusChanged=(...e)=>{this._onSocketStatusChanged&&this._onSocketStatusChanged(...e)},this._getBindingList=(e=20,t=0,i=[])=>s(this,void 0,void 0,(function*(){const s=`/app/bindings?show_disabled=0&limit=${e}&skip=${t}`,{err:n,data:r}=yield a.default(`${s}`,{method:"GET"});if(n)return{err:n};const c=[...i,...(null==r?void 0:r.devices)||[]];return r&&r.devices.length===e?yield this._getBindingList(e,e+t,c):c})),this._getWebsocketConnInfo=e=>e.host?`wss://wx${e.host}`:"wss://wxstage.gizwits.com",this.appID=e,this.token=t,this.uid=i;const d=wx.getSystemInfoSync().SDKVersion;this._maxSocketNum=r?-1===c.compareWXSDKVersion(d||"1.0.0","1.7.0")?1:5:0}init(){var e,t;return s(this,void 0,void 0,(function*(){try{const i=yield this._getBindingList();return(null===(e=i.err)||void 0===e?void 0:e.errorCode)?{errorCode:null===(t=i.err)||void 0===t?void 0:t.errorCode,errorMessage:"getting binding list failed"}:(this._bindingDevices=i.reduce((e,t)=>Object.assign(Object.assign({},e),{[t.did]:t}),{}),null)}catch(e){return n.default.GIZ_SDK_OTHERWISE}}))}};class o{constructor({appID:e,token:t,uid:i,wsInfo:n,onDeviceStatusChanged:a,onBindingChanged:c,onSocketStatusChanged:o}){this.ready=!1,this.commType="attrs_v4",this._heartbeatInterval=60,this._keepaliveTime=180,this._loginIntveral=5e3,this.autoSubscribe=!1,this._websocket=null,this._loginFailedTimes=0,this._subDids=new Set,this._socketRespHandleMap={},this._waitSends=[],this.destory=()=>{this._heartbeatTimerId&&clearInterval(this._heartbeatTimerId),this._checkConnectTimerId&&clearInterval(this._checkConnectTimerId),this.close()},this._networkChange=e=>s(this,void 0,void 0,(function*(){r.default.log("network change",e)})),this._appShow=()=>s(this,void 0,void 0,(function*(){r.default.log("app show")})),this._addSubDid=e=>{this._subDids.add(e)},this._removeSubDid=e=>{this._subDids.delete(e)},this._connectWS=()=>{r.default.log("GIZ_SDK: start connect ws"),this._websocket=wx.connectSocket({url:this._wsUrl,fail:e=>{r.default.error("GIZ_SDK: connectSocket error",new Error(JSON.stringify(e)))}}),this._websocket.onClose(this.handleClose),this._websocket.onOpen(this.handleOpen),this._websocket.onError(this.handleError),this._websocket.onMessage(this.handleMessage),this._checkConnectTimerId||(this._checkConnectTimerId=setInterval(()=>{this._websocket||this._connectWS()},1e3))},this._subDevices=e=>{const t={cmd:"subscribe_req",data:e.map(e=>({did:e}))};this._send(t)},this._unSubDevices=e=>{e.map(e=>this._removeSubDid(e))},this._send=(e,t=!1)=>(r.default.log("GIZ_SDK: Socket send",e,t),new Promise(i=>{t||this._websocket&&this.ready?this._websocket&&(t||this.ready)&&this._websocket.send({data:JSON.stringify(e),complete:e=>{r.default.log("GIZ_SDK: socket send res",e),r.default.log("resres",e);let t=!1;"sendSocketMessage:ok"===e.errMsg&&(t=!0),i({success:t,message:e.errMsg})},fail:e=>{r.default.error("GIZ_SDK: Socket send error",new Error(JSON.stringify(e))),i({success:!1,message:e.errMsg})}}):i({success:!1,message:"Socket not ready"})})),this.close=()=>{this.ready=!1,this._heartbeatTimerId&&clearInterval(this._heartbeatTimerId),this._websocket&&(this._websocket.close({}),this._websocket=null),this._handleSocketStatusChanged(!1)},this.handleClose=e=>{r.default.error("GIZ_SDK: socket close",new Error(JSON.stringify(e))),this.close(),this._stopPing()},this.handleOpen=()=>{r.default.log(" socket open"),this._login()},this.handleMessage=({data:e})=>{r.default.log("GIZ_SDK: message",e);const t=JSON.parse(e),i=this._socketRespHandleMap[t.cmd];i&&i(t.data)},this.handleError=e=>{r.default.error("GIZ_SDK: socket error",new Error(JSON.stringify(e))),this.close(),this._stopPing()},this._login=()=>{const e={cmd:"login_req",data:{appid:this.appID,uid:this.uid,token:this.token,p0_type:this.commType,heartbeat_interval:this._keepaliveTime,auto_subscribe:this.autoSubscribe}};this._send(e,!0)},this._tryLoginAgain=()=>{this._loginFailedTimes+=1,setTimeout(()=>{this._login()},this._loginFailedTimes*this._loginIntveral)},this._startPing=()=>{this._heartbeatTimerId=setInterval(()=>{this._send({cmd:"ping"})},1e3*this._heartbeatInterval)},this._stopPing=()=>{this._heartbeatTimerId&&clearInterval(this._heartbeatTimerId)},this.pongResp=()=>{},this._loginResp=e=>{1==e.success?(this._loginFailedTimes=0,this.ready=!0,this._startPing(),this._subDevices([...this._subDids]),this._handleSocketStatusChanged(!0),this._consumeWaitSends()):this._loginFailedTimes<3?(r.default.log("GIZ_SDK: Login failed, will try again, please wait..."),this._tryLoginAgain()):(r.default.error("GIZ_SDK: Login failed",new Error("m2m socket login failed")),this.close())},this._consumeWaitSends=()=>{let e=this._waitSends.pop();for(;e;)this._send(e),e=this._waitSends.pop()},this._handleSocketStatusChanged=e=>{this._onSocketStatusChanged&&this._onSocketStatusChanged([...this._subDids],e)},this._subscribeResp=e=>{r.default.log("GIZ_SDK: subscribe_res",e),e&&e.success&&e.success.forEach(e=>this._send({cmd:"c2s_read",data:{did:e.did}})),r.default.debug("GIZ_SDK: subscribe_res",e)},this._onlineResp=e=>{this._isSub(e.did)&&this._onDeviceStatusChanged&&this._onDeviceStatusChanged({did:e.did,attrs:Object.assign({is_online:e.online},e)})},this._rawChangedResp=e=>{this._isSub(e.did)&&this._onDeviceStatusChanged&&this._onDeviceStatusChanged(e)},this._statusChangedResp=e=>{this._isSub(e.did)&&this._onDeviceStatusChanged&&this._onDeviceStatusChanged(e)},this._isSub=e=>this._subDids.has(e),this._invalidMsgResp=e=>{1003===e.error_code&&this._login(),r.default.error("GIZ_SDK: s2c_invalid_msg",new Error(JSON.stringify(e)))},this._bindingChangedResp=e=>{!e.bind&&e.did&&this._removeSubDid(e.did),this._onBindingChanged&&this._onBindingChanged()},this.appID=e,this.token=t,this.uid=i,this._wsUrl=`${n}/ws/app/v1`,this._heartbeatTimerId=void 0,this._loginFailedTimes=0,this._onDeviceStatusChanged=a,this._onBindingChanged=c,this._onSocketStatusChanged=o,this._socketRespHandleMap={pong:this.pongResp,login_res:this._loginResp,subscribe_res:this._subscribeResp,s2c_online_status:this._onlineResp,s2c_raw:this._rawChangedResp,s2c_noti:this._statusChangedResp,s2c_invalid_msg:this._invalidMsgResp,s2c_binding_changed:this._bindingChangedResp},wx.onNetworkStatusChange(this._networkChange),wx.onAppShow(this._appShow)}}t.Connection=o},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(5),r=i(3),a=i(28),c=i(29);class o extends c.default{constructor(){super(...arguments),this.disableSendUDP=!1,this.sendMessageInterval=null,this.UDPSocketHandler=null,this.destroy=()=>{this.cleanTimeout(),this.sendMessageInterval&&clearInterval(this.sendMessageInterval),this.sendMessageInterval=null,this.UDPSocketHandler&&(this.UDPSocketHandler.offError(),this.UDPSocketHandler.offMessage(),this.UDPSocketHandler.close())},this.configDevice=({ssid:e,password:t,softAPSSIDPrefix:i})=>new Promise((c,o)=>{r.default.debug("GIZ_SDK: start config device");let d=!1,l=0;const u=a.default.pack(e,t);this.UDPSocketHandler=wx.createUDPSocket(),this.UDPSocketHandler.bind(),this.disableSendUDP=!1;const h=()=>{try{!this.disableSendUDP&&this.UDPSocketHandler.send({address:"10.10.100.254",port:12414,message:u,offset:0,length:u.byteLength})}catch(e){}};this.sendMessageInterval=setInterval(()=>{h()},2e3),this.UDPSocketHandler.onError(e=>{l+=1,l>2&&(this.destroy(),o({success:!1,err:{errorCode:n.default.WECHAT_ERROR.errorCode,errorMessage:e.errMsg}}))});const f=()=>s(this,void 0,void 0,(function*(){if(!d){this.UDPSocketHandler.offMessage(),this.UDPSocketHandler.offError(),this.sendMessageInterval&&clearInterval(this.sendMessageInterval),this.disableSendUDP=!0,d=!0;try{const i=yield this.searchDevice({ssid:e,password:t});c(i)}catch(e){o(e)}}}));this.UDPSocketHandler.onMessage(e=>{f()}),wx.onNetworkStatusChange(()=>s(this,void 0,void 0,(function*(){!d&&wx.getConnectedWifi({success:e=>s(this,void 0,void 0,(function*(){-1===e.wifi.SSID.indexOf(i)&&f()}))})})))}),this.setDeviceOnboardingDeploy=({timeout:e,isBind:t=!0,softAPSSIDPrefix:i})=>{const n=this.ssid,r=this.password;return new Promise((a,c)=>s(this,void 0,void 0,(function*(){this.destroy(),this.initDeviceOnboardingDeploy(a,c),this.startTimeoutTimer(e);try{const e=((yield this.configDevice({ssid:n,password:r,softAPSSIDPrefix:i})).data||[]).map(e=>({mac:e.mac,productKey:e.product_key,did:e.did,name:"",isBind:!1,connectType:"NONE",isBleOnline:!1,isLanOnline:!1,isOnline:!1}));if(t)try{a(yield this.bindDevices(e))}catch(e){c(e)}else a({success:!0,data:e})}catch(e){c(e)}finally{this.destroy()}})))}}}t.default=o},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(11),n=({SSID:e,password:t,pk:i})=>{let n=s.MD5(e+t).toString();n=s.enc.Hex.parse(n);let r=s.enc.Utf8.parse(i),a=s.AES.encrypt(r,n,{iv:n,mode:s.mode.ECB,padding:s.pad.ZeroPadding});return s.MD5(a.ciphertext).toString()};t.default=({SSID:e,password:t,pks:i})=>{const s=[];return i.map(i=>{const r=n({SSID:e,password:t,pk:i});s.push(r)}),s}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(11);t.psKeySign=e=>{const t=Math.round((new Date).getTime()/1e3),i=e+t;return{Signature:s.MD5(i).toString(),timestamp:t}}},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(5),r=i(10),a=i(23),c=i(9),o=i(29),d=i(28),l=i(3);function u({bleDeviceId:e,arrayBuffer:t,serviceUUIDSuffix:i="abf0",characteristicUUIDSuffix:n="abf7",bleHandle:c}){let o=null,d=null;const u=()=>null===d&&(o&&clearInterval(o),!0);return new Promise((h,f)=>s(this,void 0,void 0,(function*(){try{l.default.debug("GIZ_SDK: ssid info: ",t),d=setTimeout(()=>{o&&clearInterval(o),d=null,h(!1)},5e3),l.default.debug("GIZ_SDK: createBLEConnection start: ",e),yield c.disableScan();const s=yield a.retryConnect(e,1e4);c.enableScan(),l.default.debug("GIZ_SDK: createBLEConnection end, res:",s);const f=yield a.getBLEDeviceServices(e);l.default.debug("GIZ_SDK: getBLEDeviceServices end, res:",f);const p=f.find(e=>e.uuid.split("-")[0].toLowerCase().endsWith(i));if(!p)return l.default.debug("GIZ_SDK: get ble device services fail",e,f),void h(!1);const v=yield a.getBLEDeviceCharacteristics(e,p.uuid);l.default.debug("GIZ_SDK: getBLEDeviceCharacteristics end, res:",v);const g=v.find(e=>e.uuid.split("-")[0].toLowerCase().endsWith(n));if(!g)return l.default.debug("GIZ_SDK: get ble device characteristics fail",e,v),void h(!1);if(!g.properties.notify&&!g.properties.indicate)return l.default.debug("GIZ_SDK: the ble device characteristic not support notify or indicate",e,g),void h(!1);l.default.debug("GIZ_SDK: check characteristic and service success"),yield a.notifyBLECharacteristicValueChange(e,p.uuid,g.uuid);const y=e=>{const t=r.ab2hex(e.value);l.default.debug("GIZ_SDK: 收到设备返回ack",t),"0000000303000002"===t&&(c.removeEventListener("GizBleDeviceData",y),h(!0))};if(c.addEventListener("GizBleDeviceData",y),l.default.debug("GIZ_SDK: on notifyBLECharacteristicValueChange success"),u())return;yield a.unpackWriteBLECharacteristicValue(e,p.uuid,g.uuid,t),o=setInterval(()=>{u()||a.unpackWriteBLECharacteristicValue(e,p.uuid,g.uuid,t)},2e3),l.default.debug("GIZ_SDK: unpackWriteBLECharacteristicValue end")}catch(e){f(!1),l.default.debug("GIZ_SDK: sendBLEConfigCmd error",e)}}))).catch(e=>{l.default.debug("GIZ_SDK: sendBLEConfigCmd error",e)}).finally(()=>{d&&clearTimeout(d),o&&clearInterval(o),wx.closeBLEConnection({deviceId:e})})}t.sendBLEConfigCmd=u;class h extends o.default{constructor(e,t,i,o,h){super(e,t,i,o),this.destroy=()=>{this.cleanTimeout()},this.isValidBleDevice=(e,t)=>{if(!e||!e.advertisData)return!1;const{productKey:i,mac:s}=r.advertisData2PkAndMac(e.advertisData,this.specialProductKeys);return!!this.specialProductKeys.includes(i)&&(l.default.debug(`GIZ_SDK: isValidBleDevice mac: ${s} pk: ${i} name: ${e.name}`),l.default.debug(`GIZ_SDK: softAPSSIDPrefix: ${t} ismatch : ${e.name&&e.name.startsWith(t)}`),!t||e.name&&e.name.startsWith(t))},this.enableBluetoothDevicesDescovery=()=>s(this,void 0,void 0,(function*(){return(yield a.getBluetoothAdapterState()).available?(yield a.startBluetoothDevicesDiscovery(),{success:!0}):{success:!1,err:{errorCode:n.default.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON.errorCode,errorMessage:"蓝牙状态不可用"}}})),this.enableAndGetBluetoothDevices=e=>s(this,void 0,void 0,(function*(){const t=yield this.enableBluetoothDevicesDescovery();if(!t.success)return t;l.default.debug("GIZ_SDK: start enableAndGetBluetoothDevices");const i=(yield a.getBluetoothDevices()).filter(t=>this.isValidBleDevice(t,e));return l.default.debug("GIZ_SDK: getBluetoothDevices success",i),{success:!0,bleDevices:i}})),this.setDeviceOnboardingDeploy=({timeout:e,isBind:t=!0,softAPSSIDPrefix:i})=>new Promise((n,r)=>s(this,void 0,void 0,(function*(){const s=this.ssid,a=this.password;this.destroy(),this.initDeviceOnboardingDeploy(n,r),this.startTimeoutTimer(e);try{const r=((yield this.configBLEDevice({ssid:s,password:a,timeout:1e3*e,softAPSSIDPrefix:i})).data||[]).map(e=>({mac:e.mac,productKey:e.product_key,did:e.did,name:"",isBind:!1,connectType:"NONE",isBleOnline:!1,isLanOnline:!1,isOnline:!1}));n(t?yield this.bindDevices(r):{success:!0,data:r})}catch(e){n({success:!1,data:e})}finally{this.destroy()}}))),this.configBLEDevice=({ssid:e,password:t,softAPSSIDPrefix:i})=>new Promise((o,h)=>s(this,void 0,void 0,(function*(){l.default.debug("GIZ_SDK: start config ble device");const f=yield this.enableAndGetBluetoothDevices(i).catch(e=>({success:!1,err:{errorCode:n.default.WECHAT_ERROR.errorCode,errorMessage:JSON.stringify(e)}}));if(!r.isWXDevicesResult(f))return h(f);const{bleDevices:p}=f;l.default.debug("GIZ_SDK: enableAndGetBluetoothDevices success, target devices: ",p);const v=({devices:e})=>s(this,void 0,void 0,(function*(){this.hasTimeoutHandler()?Array.prototype.push.apply(p,e.filter(e=>this.isValidBleDevice(e,i))):wx.offBluetoothDeviceFound(v)}));wx.onBluetoothDeviceFound(v);const g=d.default.pack(e,t),y=()=>s(this,void 0,void 0,(function*(){if(l.default.debug("GIZ_SDK: startConfigDevice"),!this.hasTimeoutHandler())return;const e=p.shift();if(e&&l.default.debug("GIZ_SDK: startConfigDevice, target device: ",e),!(e&&(yield u({bleDeviceId:e.deviceId,arrayBuffer:g.buffer,bleHandle:this.bleHandle}))))return yield c.default(500),yield a.startBluetoothDevicesDiscovery(),void(yield y());l.default.debug("GIZ_SDK: offBluetoothDeviceFound ready search device"),wx.offBluetoothDeviceFound(v)}));try{this.searchDevice({ssid:e,password:t}).then(e=>{o(e)})}catch(e){h(e),l.default.error("GIZ_SDK: searchDevice error",new Error(JSON.stringify(e)))}yield y()}))),this.bleHandle=h}}t.default=h},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(12);t.AnonymousLogin=function({uid:e}){return s(this,void 0,void 0,(function*(){return n.default("/app/users",{data:{phone_id:e},method:"POST"},!1)}))}},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(3),r=i(24),a=i(68),c=i(25),o=i(4),d=i(2),l=i(9),u=i(10),h=i(27);class f extends h.default{constructor({pks:e}){super(),this.connectedList=[],this.pks=[],this.scanList=[],this.deviceUDPPort=12414,this.appUDPPort=2415,this.offlineThreshold=2e4,this.isActive=!0,this.listenDevOfflineTimer=null,this.init=()=>{this.UDPSocket&&(this.UDPSocket=wx.createUDPSocket(),this.UDPSocket.bind(),this.UDPSocket.onMessage(this.onMessage),this.UDPSocket.onError(this.onError),n.default.info("Start UDP Discover"),this.startDiscover(),this.listenDevOffline(this.offlineThreshold),wx.onAppShow(this.onAppShow),wx.onAppHide(this.onAppHide))},this.onAppShow=()=>{this.isActive=!0,this.scanList.map(e=>{e.ctime=Date.now()})},this.onAppHide=()=>{this.isActive=!1},this.listenDevOffline=e=>{this.listenDevOfflineTimer=setInterval(()=>{if(!this.isActive)return;const t=(new Date).getTime(),i=this.scanList.filter(i=>t-i.ctime<e);i.length!==this.scanList.length&&(n.default.debug("remove lan device"),this.scanList=i,this.notifyDevices())},500)},this.notifyDevices=()=>{this.listenerMap.GizLanDeviceList&&this.listenerMap.GizLanDeviceList.map(e=>{e(this.scanList)})},this.notifyDeviceData=(e,t)=>{this.listenerMap.GizLanDeviceData&&this.listenerMap.GizLanDeviceData.map(i=>{i(e,t)})},this.isSameDevice=(e,t)=>e.mac===t.mac&&e.productKey===t.productKey,this.disConnectDevice=e=>{const t=this.connectedList.findIndex(t=>t.productKey===e.productKey&&t.mac===e.mac);try{return-1!==t&&(this.connectedList[t].socketHandle.destory(),this.connectedList.splice(t,1)),{success:!0}}catch(e){return{success:!1,err:e}}},this.onData=(e,t)=>{this.notifyDeviceData(e,t)},this.connectDevice=e=>s(this,void 0,void 0,(function*(){const t=this.scanList.find(t=>this.isSameDevice(e,t));if(!t)return{success:!1};if(this.connectedList.find(t=>this.isSameDevice(e,t)))return{success:!0};{const e=new p({ip:t.ip,mac:t.mac,productKey:t.productKey,onClose:this.onDeviceClose,onData:this.onData}),i=yield e.connect();return i.success?this.connectedList.push({mac:t.mac,productKey:t.productKey,socketHandle:e}):e.destory(),i}})),this.onError=e=>{n.default.warn("Discover Error",e)},this.isMatchPk=e=>0===this.pks.length||this.pks.includes(e),this.onMessage=e=>{const t=u.ab2numbers(e.message),i=new a.default(t);""!==i.mac&&this.isMatchPk(i.productKey)&&this.updateDevice(i,e.remoteInfo.address)},this.onDeviceClose=({productKey:e,mac:t})=>{const i=this.connectedList.findIndex(i=>i.productKey===e&&i.mac===t);-1!==i&&this.connectedList.splice(i,1)},this.write=(e,t)=>s(this,void 0,void 0,(function*(){n.default.debug("send data to device",e,t,this.connectedList);const i=this.connectedList.findIndex(t=>this.isSameDevice(t,e));if(-1!==i){return this.connectedList[i].socketHandle.write(t)}return{success:!1,message:"device not sub"}})),this.updateDevice=(e,t)=>{const i=this.scanList.find(t=>t.mac===e.mac);if(i)i.ctime=Date.now();else{const i={mac:e.mac,ip:t,productKey:e.productKey,did:e.did,expandData:e,name:"",isBind:!1,connectType:"NONE",isOnline:!1,isLanOnline:!0,isBleOnline:!1,ctime:Date.now()};this.scanList.push(i),this.notifyDevices()}},this.sendBoradCast=()=>{this.UDPSocket&&(this.UDPSocket.send({address:"255.255.255.255",message:a.default.pack(),port:this.deviceUDPPort}),n.default.debug("Send UDP Discover"))},this.startDiscover=()=>{this.sendBoradCast(),this.boradcastTimer=setInterval(()=>{this.sendBoradCast()},5e3)},this.destory=()=>{this.boradcastTimer&&clearInterval(this.boradcastTimer),this.UDPSocket&&this.UDPSocket.close(),this.listenDevOfflineTimer&&clearInterval(this.listenDevOfflineTimer),wx.offAppShow(this.onAppShow),wx.offAppHide(this.onAppHide)},this.pks=e}}t.LanHandle=f;class p{constructor({ip:e,onClose:t,mac:i,productKey:a,onData:h}){this.deviceTCPPort=12416,this.ip="",this.productKey="",this.mac="",this.tcpHandler=null,this.onData=(e,t)=>{},this.onCloseListener=({mac:e,productKey:t})=>{},this.connect=()=>s(this,void 0,void 0,(function*(){return new Promise(e=>s(this,void 0,void 0,(function*(){const t=()=>{const e=r.default.pack();this.tcpHandler.write(d.arrayToUint8(e)),n.default.debug("connect success try login")},i=t=>{e({success:!0,err:t})},s=t=>{switch(new o.default(u.ab2numbers(t.message)).cmd){case"0007":{const e=new r.default(u.ab2numbers(t.message)),i=c.default.pack({passcode:e.passcode});this.tcpHandler.write(d.arrayToUint8(i));break}case"0009":new c.default(u.ab2numbers(t.message)).result?(e({success:!0}),this.initListener()):e({success:!1})}};try{this.tcpHandler=wx.createTCPSocket(),this.tcpHandler.onConnect(t),this.tcpHandler.onError(i),this.tcpHandler.onMessage(s),this.tcpHandler.connect({address:this.ip,port:this.deviceTCPPort,timeout:2}),yield l.default(4e3),e({success:!1,err:null})}catch(t){n.default.error("connect lan error",t),e({success:!1,err:null})}finally{this.tcpHandler.offConnect(t),this.tcpHandler.offError(i),this.tcpHandler.offMessage(s)}})))})),this.write=e=>(this.tcpHandler.write(e),{success:!0}),this.onMessage=e=>{try{const t=u.ab2hex(e.message),i=new o.default(d.hexStrint2byte(t));n.default.debug("on tcp message",i),this.onData(this.mac,t)}catch(e){}},this.onError=()=>{},this.onClose=()=>{this.onCloseListener({productKey:this.productKey,mac:this.mac})},this.initListener=()=>{this.tcpHandler.onError(this.onError),this.tcpHandler.onMessage(this.onMessage),this.tcpHandler.onClose(this.onClose)},this.destory=()=>{this.tcpHandler&&this.tcpHandler.close(),this.tcpHandler.offError(this.onError),this.tcpHandler.offMessage(this.onMessage),this.tcpHandler.offClose(this.onClose)},this.ip=e,this.mac=i,this.productKey=a,this.onData=h,this.onCloseListener=t}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(3),n=i(4),r=i(2);class a extends n.default{constructor(e){super(e),this.did="",this.mac="",this.productKey="",this.deviceType=0,this.apiUrl="",this.protocolVersion="",this.mcuVersion="",this.moduleVersion="",this.parseEndChat=(e,t)=>{let i="";const s=this.content.slice(e,this.content.length);for(let t in s){const n=s[t];if(e+=1,0===n)break;i+=String.fromCharCode(n)}return this[t]=i,e},this.baseParse=(e,t,i="ASCII")=>{const s=parseInt(r.arrayToString(this.content.slice(e,e+2)),16);e+=2;let n="";return this.content.slice(e,e+s).map(e=>{if("ASCII"===i)n+=String.fromCharCode(e);else{const t=e.toString(16);n+=r.fillString(t,2)}}),this[t]=n,e+s};let t=0;try{t=this.baseParse(t,"did"),t=this.baseParse(t,"mac","HEX"),t=this.baseParse(t,"moduleVersion"),t=this.baseParse(t,"productKey"),t+=8,t=this.parseEndChat(t,"apiUrl"),t=this.parseEndChat(t,"protocolVersion"),this.mcuVersion="",this.content.slice(t,this.content.length).map(e=>{this.mcuVersion+=String.fromCharCode(e)})}catch(e){s.default.warn("Parse DiscoverUDP error",e)}}}a.pack=()=>{const e=[0,0,0,3,3,0,0,3],t=new ArrayBuffer(e.length),i=new Uint8Array(t);for(let s=0;s<t.byteLength;s++)i[s]=e[s];return i},t.default=a},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(4),n=i(2);class r extends s.default{constructor(e){super(e),this.state=0,this.len=0;let t=0;this.len=parseInt(n.arrayToString(this.content.slice(t,t+2)),16),t+=2,this.state=this.content[t]}}t.RequestSync=r,r.pack=()=>[0,0,0,3,3,0,0,81];class a extends s.default{constructor(e){super(e),this.id=0,this.timestemp=0,this.payloadLen=0,this.payload=[];let t=0;this.id=parseInt(n.arrayToString(this.content.slice(t,t+2)),16),t+=2,this.timestemp=parseInt(n.arrayToString(this.content.slice(t,t+5)),16),t+=5,this.payloadLen=parseInt(n.arrayToString(this.content.slice(t,t+2)),16),t+=2,this.payload=this.content.slice(t,this.content.length)}}t.SyncPackage=a,a.pack=e=>{let t=e.toString(2);return t=n.fillString(t,16),[0,0,0,3,5].concat([0,0,83]).concat(n.completeBlock(t))};class c extends s.default{}t.DeletePackage=c,c.pack=e=>{let t=e.toString(2);return t=n.fillString(t,16),[0,0,0,3,5].concat([0,0,85]).concat(n.completeBlock(t))};class o extends s.default{constructor(e){super(e),this.state=0,this.state=this.content[0]}}t.CancelSync=o,o.pack=()=>[0,0,0,3,3,0,0,87]},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(12),r=i(11);t.uploadP0=function({device:e,data:t,productSecret:i}){return s(this,void 0,void 0,(function*(){const s=`/v2/products/${e.productKey}/devices/offline-data`;let a=e.passcode;const c=r.enc.Hex.parse(i),o=r.enc.Hex.parse(""),d=r.enc.Utf8.parse(a);return a=r.AES.encrypt(d,c,{iv:o,mode:r.mode.ECB,padding:r.pad.Pkcs7}).ciphertext.toString().toUpperCase(),n.default(s,{data:{data:t,encoding:"hex"},method:"POST",headers:{"X-Gizwits-Device-Id":e.did,"X-Gizwits-Device-passcode":a}},!1)}))}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(4),n=i(2);class r extends s.default{}r.pack=()=>{const e=parseInt(`${Date.now()/1e3}`,10),t=n.fillString(e.toString(2),40);return[0,0,0,3,8,0,0,89].concat(n.completeBlock(t))},t.default=r}]);
18
+ s.mode.CTRGladman=function(){var e=s.lib.BlockCipherMode.extend();function t(e){if(255==(e>>24&255)){var t=e>>16&255,i=e>>8&255,s=255&e;255===t?(t=0,255===i?(i=0,255===s?s=0:++s):++i):++t,e=0,e+=t<<16,e+=i<<8,e+=s}else e+=1<<24;return e}var i=e.Encryptor=e.extend({processBlock:function(e,i){var s=this._cipher,n=s.blockSize,r=this._iv,a=this._counter;r&&(a=this._counter=r.slice(0),this._iv=void 0),function(e){0===(e[0]=t(e[0]))&&(e[1]=t(e[1]))}(a);var c=a.slice(0);s.encryptBlock(c,0);for(var o=0;o<n;o++)e[i+o]^=c[o]}});return e.Decryptor=i,e}(),s.mode.CTRGladman)},function(e,t,i){var s,n,r;e.exports=(r=i(0),i(1),r.mode.OFB=(s=r.lib.BlockCipherMode.extend(),n=s.Encryptor=s.extend({processBlock:function(e,t){var i=this._cipher,s=i.blockSize,n=this._iv,r=this._keystream;n&&(r=this._keystream=n.slice(0),this._iv=void 0),i.encryptBlock(r,0);for(var a=0;a<s;a++)e[t+a]^=r[a]}}),s.Decryptor=n,s),r.mode.OFB)},function(e,t,i){var s,n;e.exports=(n=i(0),i(1),n.mode.ECB=((s=n.lib.BlockCipherMode.extend()).Encryptor=s.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),s.Decryptor=s.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),s),n.mode.ECB)},function(e,t,i){var s;e.exports=(s=i(0),i(1),s.pad.AnsiX923={pad:function(e,t){var i=e.sigBytes,s=4*t,n=s-i%s,r=i+n-1;e.clamp(),e.words[r>>>2]|=n<<24-r%4*8,e.sigBytes+=n},unpad:function(e){var t=255&e.words[e.sigBytes-1>>>2];e.sigBytes-=t}},s.pad.Ansix923)},function(e,t,i){var s;e.exports=(s=i(0),i(1),s.pad.Iso10126={pad:function(e,t){var i=4*t,n=i-e.sigBytes%i;e.concat(s.lib.WordArray.random(n-1)).concat(s.lib.WordArray.create([n<<24],1))},unpad:function(e){var t=255&e.words[e.sigBytes-1>>>2];e.sigBytes-=t}},s.pad.Iso10126)},function(e,t,i){var s;e.exports=(s=i(0),i(1),s.pad.Iso97971={pad:function(e,t){e.concat(s.lib.WordArray.create([2147483648],1)),s.pad.ZeroPadding.pad(e,t)},unpad:function(e){s.pad.ZeroPadding.unpad(e),e.sigBytes--}},s.pad.Iso97971)},function(e,t,i){var s;e.exports=(s=i(0),i(1),s.pad.ZeroPadding={pad:function(e,t){var i=4*t;e.clamp(),e.sigBytes+=i-(e.sigBytes%i||i)},unpad:function(e){var t=e.words,i=e.sigBytes-1;for(i=e.sigBytes-1;i>=0;i--)if(t[i>>>2]>>>24-i%4*8&255){e.sigBytes=i+1;break}}},s.pad.ZeroPadding)},function(e,t,i){var s;e.exports=(s=i(0),i(1),s.pad.NoPadding={pad:function(){},unpad:function(){}},s.pad.NoPadding)},function(e,t,i){var s,n,r,a;e.exports=(a=i(0),i(1),n=(s=a).lib.CipherParams,r=s.enc.Hex,s.format.Hex={stringify:function(e){return e.ciphertext.toString(r)},parse:function(e){var t=r.parse(e);return n.create({ciphertext:t})}},a.format.Hex)},function(e,t,i){var s;e.exports=(s=i(0),i(7),i(8),i(6),i(1),function(){var e=s,t=e.lib.BlockCipher,i=e.algo,n=[],r=[],a=[],c=[],o=[],d=[],l=[],u=[],h=[],f=[];!function(){for(var e=[],t=0;t<256;t++)e[t]=t<128?t<<1:t<<1^283;var i=0,s=0;for(t=0;t<256;t++){var p=s^s<<1^s<<2^s<<3^s<<4;p=p>>>8^255&p^99,n[i]=p,r[p]=i;var v=e[i],g=e[v],y=e[g],_=257*e[p]^16843008*p;a[i]=_<<24|_>>>8,c[i]=_<<16|_>>>16,o[i]=_<<8|_>>>24,d[i]=_,_=16843009*y^65537*g^257*v^16843008*i,l[p]=_<<24|_>>>8,u[p]=_<<16|_>>>16,h[p]=_<<8|_>>>24,f[p]=_,i?(i=v^e[e[e[y^v]]],s^=e[e[s]]):i=s=1}}();var p=[0,1,2,4,8,16,32,64,128,27,54],v=i.AES=t.extend({_doReset:function(){if(!this._nRounds||this._keyPriorReset!==this._key){for(var e=this._keyPriorReset=this._key,t=e.words,i=e.sigBytes/4,s=4*((this._nRounds=i+6)+1),r=this._keySchedule=[],a=0;a<s;a++)a<i?r[a]=t[a]:(d=r[a-1],a%i?i>6&&a%i==4&&(d=n[d>>>24]<<24|n[d>>>16&255]<<16|n[d>>>8&255]<<8|n[255&d]):(d=n[(d=d<<8|d>>>24)>>>24]<<24|n[d>>>16&255]<<16|n[d>>>8&255]<<8|n[255&d],d^=p[a/i|0]<<24),r[a]=r[a-i]^d);for(var c=this._invKeySchedule=[],o=0;o<s;o++){if(a=s-o,o%4)var d=r[a];else d=r[a-4];c[o]=o<4||a<=4?d:l[n[d>>>24]]^u[n[d>>>16&255]]^h[n[d>>>8&255]]^f[n[255&d]]}}},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,a,c,o,d,n)},decryptBlock:function(e,t){var i=e[t+1];e[t+1]=e[t+3],e[t+3]=i,this._doCryptBlock(e,t,this._invKeySchedule,l,u,h,f,r),i=e[t+1],e[t+1]=e[t+3],e[t+3]=i},_doCryptBlock:function(e,t,i,s,n,r,a,c){for(var o=this._nRounds,d=e[t]^i[0],l=e[t+1]^i[1],u=e[t+2]^i[2],h=e[t+3]^i[3],f=4,p=1;p<o;p++){var v=s[d>>>24]^n[l>>>16&255]^r[u>>>8&255]^a[255&h]^i[f++],g=s[l>>>24]^n[u>>>16&255]^r[h>>>8&255]^a[255&d]^i[f++],y=s[u>>>24]^n[h>>>16&255]^r[d>>>8&255]^a[255&l]^i[f++],_=s[h>>>24]^n[d>>>16&255]^r[l>>>8&255]^a[255&u]^i[f++];d=v,l=g,u=y,h=_}v=(c[d>>>24]<<24|c[l>>>16&255]<<16|c[u>>>8&255]<<8|c[255&h])^i[f++],g=(c[l>>>24]<<24|c[u>>>16&255]<<16|c[h>>>8&255]<<8|c[255&d])^i[f++],y=(c[u>>>24]<<24|c[h>>>16&255]<<16|c[d>>>8&255]<<8|c[255&l])^i[f++],_=(c[h>>>24]<<24|c[d>>>16&255]<<16|c[l>>>8&255]<<8|c[255&u])^i[f++],e[t]=v,e[t+1]=g,e[t+2]=y,e[t+3]=_},keySize:8});e.AES=t._createHelper(v)}(),s.AES)},function(e,t,i){var s;e.exports=(s=i(0),i(7),i(8),i(6),i(1),function(){var e=s,t=e.lib,i=t.WordArray,n=t.BlockCipher,r=e.algo,a=[57,49,41,33,25,17,9,1,58,50,42,34,26,18,10,2,59,51,43,35,27,19,11,3,60,52,44,36,63,55,47,39,31,23,15,7,62,54,46,38,30,22,14,6,61,53,45,37,29,21,13,5,28,20,12,4],c=[14,17,11,24,1,5,3,28,15,6,21,10,23,19,12,4,26,8,16,7,27,20,13,2,41,52,31,37,47,55,30,40,51,45,33,48,44,49,39,56,34,53,46,42,50,36,29,32],o=[1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28],d=[{0:8421888,268435456:32768,536870912:8421378,805306368:2,1073741824:512,1342177280:8421890,1610612736:8389122,1879048192:8388608,2147483648:514,2415919104:8389120,2684354560:33280,2952790016:8421376,3221225472:32770,3489660928:8388610,3758096384:0,4026531840:33282,134217728:0,402653184:8421890,671088640:33282,939524096:32768,1207959552:8421888,1476395008:512,1744830464:8421378,2013265920:2,2281701376:8389120,2550136832:33280,2818572288:8421376,3087007744:8389122,3355443200:8388610,3623878656:32770,3892314112:514,4160749568:8388608,1:32768,268435457:2,536870913:8421888,805306369:8388608,1073741825:8421378,1342177281:33280,1610612737:512,1879048193:8389122,2147483649:8421890,2415919105:8421376,2684354561:8388610,2952790017:33282,3221225473:514,3489660929:8389120,3758096385:32770,4026531841:0,134217729:8421890,402653185:8421376,671088641:8388608,939524097:512,1207959553:32768,1476395009:8388610,1744830465:2,2013265921:33282,2281701377:32770,2550136833:8389122,2818572289:514,3087007745:8421888,3355443201:8389120,3623878657:0,3892314113:33280,4160749569:8421378},{0:1074282512,16777216:16384,33554432:524288,50331648:1074266128,67108864:1073741840,83886080:1074282496,100663296:1073758208,117440512:16,134217728:540672,150994944:1073758224,167772160:1073741824,184549376:540688,201326592:524304,218103808:0,234881024:16400,251658240:1074266112,8388608:1073758208,25165824:540688,41943040:16,58720256:1073758224,75497472:1074282512,92274688:1073741824,109051904:524288,125829120:1074266128,142606336:524304,159383552:0,176160768:16384,192937984:1074266112,209715200:1073741840,226492416:540672,243269632:1074282496,260046848:16400,268435456:0,285212672:1074266128,301989888:1073758224,318767104:1074282496,335544320:1074266112,352321536:16,369098752:540688,385875968:16384,402653184:16400,419430400:524288,436207616:524304,452984832:1073741840,469762048:540672,486539264:1073758208,503316480:1073741824,520093696:1074282512,276824064:540688,293601280:524288,310378496:1074266112,327155712:16384,343932928:1073758208,360710144:1074282512,377487360:16,394264576:1073741824,411041792:1074282496,427819008:1073741840,444596224:1073758224,461373440:524304,478150656:0,494927872:16400,511705088:1074266128,528482304:540672},{0:260,1048576:0,2097152:67109120,3145728:65796,4194304:65540,5242880:67108868,6291456:67174660,7340032:67174400,8388608:67108864,9437184:67174656,10485760:65792,11534336:67174404,12582912:67109124,13631488:65536,14680064:4,15728640:256,524288:67174656,1572864:67174404,2621440:0,3670016:67109120,4718592:67108868,5767168:65536,6815744:65540,7864320:260,8912896:4,9961472:256,11010048:67174400,12058624:65796,13107200:65792,14155776:67109124,15204352:67174660,16252928:67108864,16777216:67174656,17825792:65540,18874368:65536,19922944:67109120,20971520:256,22020096:67174660,23068672:67108868,24117248:0,25165824:67109124,26214400:67108864,27262976:4,28311552:65792,29360128:67174400,30408704:260,31457280:65796,32505856:67174404,17301504:67108864,18350080:260,19398656:67174656,20447232:0,21495808:65540,22544384:67109120,23592960:256,24641536:67174404,25690112:65536,26738688:67174660,27787264:65796,28835840:67108868,29884416:67109124,30932992:67174400,31981568:4,33030144:65792},{0:2151682048,65536:2147487808,131072:4198464,196608:2151677952,262144:0,327680:4198400,393216:2147483712,458752:4194368,524288:2147483648,589824:4194304,655360:64,720896:2147487744,786432:2151678016,851968:4160,917504:4096,983040:2151682112,32768:2147487808,98304:64,163840:2151678016,229376:2147487744,294912:4198400,360448:2151682112,425984:0,491520:2151677952,557056:4096,622592:2151682048,688128:4194304,753664:4160,819200:2147483648,884736:4194368,950272:4198464,1015808:2147483712,1048576:4194368,1114112:4198400,1179648:2147483712,1245184:0,1310720:4160,1376256:2151678016,1441792:2151682048,1507328:2147487808,1572864:2151682112,1638400:2147483648,1703936:2151677952,1769472:4198464,1835008:2147487744,1900544:4194304,1966080:64,2031616:4096,1081344:2151677952,1146880:2151682112,1212416:0,1277952:4198400,1343488:4194368,1409024:2147483648,1474560:2147487808,1540096:64,1605632:2147483712,1671168:4096,1736704:2147487744,1802240:2151678016,1867776:4160,1933312:2151682048,1998848:4194304,2064384:4198464},{0:128,4096:17039360,8192:262144,12288:536870912,16384:537133184,20480:16777344,24576:553648256,28672:262272,32768:16777216,36864:537133056,40960:536871040,45056:553910400,49152:553910272,53248:0,57344:17039488,61440:553648128,2048:17039488,6144:553648256,10240:128,14336:17039360,18432:262144,22528:537133184,26624:553910272,30720:536870912,34816:537133056,38912:0,43008:553910400,47104:16777344,51200:536871040,55296:553648128,59392:16777216,63488:262272,65536:262144,69632:128,73728:536870912,77824:553648256,81920:16777344,86016:553910272,90112:537133184,94208:16777216,98304:553910400,102400:553648128,106496:17039360,110592:537133056,114688:262272,118784:536871040,122880:0,126976:17039488,67584:553648256,71680:16777216,75776:17039360,79872:537133184,83968:536870912,88064:17039488,92160:128,96256:553910272,100352:262272,104448:553910400,108544:0,112640:553648128,116736:16777344,120832:262144,124928:537133056,129024:536871040},{0:268435464,256:8192,512:270532608,768:270540808,1024:268443648,1280:2097152,1536:2097160,1792:268435456,2048:0,2304:268443656,2560:2105344,2816:8,3072:270532616,3328:2105352,3584:8200,3840:270540800,128:270532608,384:270540808,640:8,896:2097152,1152:2105352,1408:268435464,1664:268443648,1920:8200,2176:2097160,2432:8192,2688:268443656,2944:270532616,3200:0,3456:270540800,3712:2105344,3968:268435456,4096:268443648,4352:270532616,4608:270540808,4864:8200,5120:2097152,5376:268435456,5632:268435464,5888:2105344,6144:2105352,6400:0,6656:8,6912:270532608,7168:8192,7424:268443656,7680:270540800,7936:2097160,4224:8,4480:2105344,4736:2097152,4992:268435464,5248:268443648,5504:8200,5760:270540808,6016:270532608,6272:270540800,6528:270532616,6784:8192,7040:2105352,7296:2097160,7552:0,7808:268435456,8064:268443656},{0:1048576,16:33555457,32:1024,48:1049601,64:34604033,80:0,96:1,112:34603009,128:33555456,144:1048577,160:33554433,176:34604032,192:34603008,208:1025,224:1049600,240:33554432,8:34603009,24:0,40:33555457,56:34604032,72:1048576,88:33554433,104:33554432,120:1025,136:1049601,152:33555456,168:34603008,184:1048577,200:1024,216:34604033,232:1,248:1049600,256:33554432,272:1048576,288:33555457,304:34603009,320:1048577,336:33555456,352:34604032,368:1049601,384:1025,400:34604033,416:1049600,432:1,448:0,464:34603008,480:33554433,496:1024,264:1049600,280:33555457,296:34603009,312:1,328:33554432,344:1048576,360:1025,376:34604032,392:33554433,408:34603008,424:0,440:34604033,456:1049601,472:1024,488:33555456,504:1048577},{0:134219808,1:131072,2:134217728,3:32,4:131104,5:134350880,6:134350848,7:2048,8:134348800,9:134219776,10:133120,11:134348832,12:2080,13:0,14:134217760,15:133152,2147483648:2048,2147483649:134350880,2147483650:134219808,2147483651:134217728,2147483652:134348800,2147483653:133120,2147483654:133152,2147483655:32,2147483656:134217760,2147483657:2080,2147483658:131104,2147483659:134350848,2147483660:0,2147483661:134348832,2147483662:134219776,2147483663:131072,16:133152,17:134350848,18:32,19:2048,20:134219776,21:134217760,22:134348832,23:131072,24:0,25:131104,26:134348800,27:134219808,28:134350880,29:133120,30:2080,31:134217728,2147483664:131072,2147483665:2048,2147483666:134348832,2147483667:133152,2147483668:32,2147483669:134348800,2147483670:134217728,2147483671:134219808,2147483672:134350880,2147483673:134217760,2147483674:134219776,2147483675:0,2147483676:133120,2147483677:2080,2147483678:131104,2147483679:134350848}],l=[4160749569,528482304,33030144,2064384,129024,8064,504,2147483679],u=r.DES=n.extend({_doReset:function(){for(var e=this._key.words,t=[],i=0;i<56;i++){var s=a[i]-1;t[i]=e[s>>>5]>>>31-s%32&1}for(var n=this._subKeys=[],r=0;r<16;r++){var d=n[r]=[],l=o[r];for(i=0;i<24;i++)d[i/6|0]|=t[(c[i]-1+l)%28]<<31-i%6,d[4+(i/6|0)]|=t[28+(c[i+24]-1+l)%28]<<31-i%6;for(d[0]=d[0]<<1|d[0]>>>31,i=1;i<7;i++)d[i]=d[i]>>>4*(i-1)+3;d[7]=d[7]<<5|d[7]>>>27}var u=this._invSubKeys=[];for(i=0;i<16;i++)u[i]=n[15-i]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._subKeys)},decryptBlock:function(e,t){this._doCryptBlock(e,t,this._invSubKeys)},_doCryptBlock:function(e,t,i){this._lBlock=e[t],this._rBlock=e[t+1],h.call(this,4,252645135),h.call(this,16,65535),f.call(this,2,858993459),f.call(this,8,16711935),h.call(this,1,1431655765);for(var s=0;s<16;s++){for(var n=i[s],r=this._lBlock,a=this._rBlock,c=0,o=0;o<8;o++)c|=d[o][((a^n[o])&l[o])>>>0];this._lBlock=a,this._rBlock=r^c}var u=this._lBlock;this._lBlock=this._rBlock,this._rBlock=u,h.call(this,1,1431655765),f.call(this,8,16711935),f.call(this,2,858993459),h.call(this,16,65535),h.call(this,4,252645135),e[t]=this._lBlock,e[t+1]=this._rBlock},keySize:2,ivSize:2,blockSize:2});function h(e,t){var i=(this._lBlock>>>e^this._rBlock)&t;this._rBlock^=i,this._lBlock^=i<<e}function f(e,t){var i=(this._rBlock>>>e^this._lBlock)&t;this._lBlock^=i,this._rBlock^=i<<e}e.DES=n._createHelper(u);var p=r.TripleDES=n.extend({_doReset:function(){var e=this._key.words;if(2!==e.length&&4!==e.length&&e.length<6)throw new Error("Invalid key length - 3DES requires the key length to be 64, 128, 192 or >192.");var t=e.slice(0,2),s=e.length<4?e.slice(0,2):e.slice(2,4),n=e.length<6?e.slice(0,2):e.slice(4,6);this._des1=u.createEncryptor(i.create(t)),this._des2=u.createEncryptor(i.create(s)),this._des3=u.createEncryptor(i.create(n))},encryptBlock:function(e,t){this._des1.encryptBlock(e,t),this._des2.decryptBlock(e,t),this._des3.encryptBlock(e,t)},decryptBlock:function(e,t){this._des3.decryptBlock(e,t),this._des2.encryptBlock(e,t),this._des1.decryptBlock(e,t)},keySize:6,ivSize:2,blockSize:2});e.TripleDES=n._createHelper(p)}(),s.TripleDES)},function(e,t,i){var s;e.exports=(s=i(0),i(7),i(8),i(6),i(1),function(){var e=s,t=e.lib.StreamCipher,i=e.algo,n=i.RC4=t.extend({_doReset:function(){for(var e=this._key,t=e.words,i=e.sigBytes,s=this._S=[],n=0;n<256;n++)s[n]=n;n=0;for(var r=0;n<256;n++){var a=n%i,c=t[a>>>2]>>>24-a%4*8&255;r=(r+s[n]+c)%256;var o=s[n];s[n]=s[r],s[r]=o}this._i=this._j=0},_doProcessBlock:function(e,t){e[t]^=r.call(this)},keySize:8,ivSize:0});function r(){for(var e=this._S,t=this._i,i=this._j,s=0,n=0;n<4;n++){i=(i+e[t=(t+1)%256])%256;var r=e[t];e[t]=e[i],e[i]=r,s|=e[(e[t]+e[i])%256]<<24-8*n}return this._i=t,this._j=i,s}e.RC4=t._createHelper(n);var a=i.RC4Drop=n.extend({cfg:n.cfg.extend({drop:192}),_doReset:function(){n._doReset.call(this);for(var e=this.cfg.drop;e>0;e--)r.call(this)}});e.RC4Drop=t._createHelper(a)}(),s.RC4)},function(e,t,i){var s;e.exports=(s=i(0),i(7),i(8),i(6),i(1),function(){var e=s,t=e.lib.StreamCipher,i=e.algo,n=[],r=[],a=[],c=i.Rabbit=t.extend({_doReset:function(){for(var e=this._key.words,t=this.cfg.iv,i=0;i<4;i++)e[i]=16711935&(e[i]<<8|e[i]>>>24)|4278255360&(e[i]<<24|e[i]>>>8);var s=this._X=[e[0],e[3]<<16|e[2]>>>16,e[1],e[0]<<16|e[3]>>>16,e[2],e[1]<<16|e[0]>>>16,e[3],e[2]<<16|e[1]>>>16],n=this._C=[e[2]<<16|e[2]>>>16,4294901760&e[0]|65535&e[1],e[3]<<16|e[3]>>>16,4294901760&e[1]|65535&e[2],e[0]<<16|e[0]>>>16,4294901760&e[2]|65535&e[3],e[1]<<16|e[1]>>>16,4294901760&e[3]|65535&e[0]];for(this._b=0,i=0;i<4;i++)o.call(this);for(i=0;i<8;i++)n[i]^=s[i+4&7];if(t){var r=t.words,a=r[0],c=r[1],d=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),l=16711935&(c<<8|c>>>24)|4278255360&(c<<24|c>>>8),u=d>>>16|4294901760&l,h=l<<16|65535&d;for(n[0]^=d,n[1]^=u,n[2]^=l,n[3]^=h,n[4]^=d,n[5]^=u,n[6]^=l,n[7]^=h,i=0;i<4;i++)o.call(this)}},_doProcessBlock:function(e,t){var i=this._X;o.call(this),n[0]=i[0]^i[5]>>>16^i[3]<<16,n[1]=i[2]^i[7]>>>16^i[5]<<16,n[2]=i[4]^i[1]>>>16^i[7]<<16,n[3]=i[6]^i[3]>>>16^i[1]<<16;for(var s=0;s<4;s++)n[s]=16711935&(n[s]<<8|n[s]>>>24)|4278255360&(n[s]<<24|n[s]>>>8),e[t+s]^=n[s]},blockSize:4,ivSize:2});function o(){for(var e=this._X,t=this._C,i=0;i<8;i++)r[i]=t[i];for(t[0]=t[0]+1295307597+this._b|0,t[1]=t[1]+3545052371+(t[0]>>>0<r[0]>>>0?1:0)|0,t[2]=t[2]+886263092+(t[1]>>>0<r[1]>>>0?1:0)|0,t[3]=t[3]+1295307597+(t[2]>>>0<r[2]>>>0?1:0)|0,t[4]=t[4]+3545052371+(t[3]>>>0<r[3]>>>0?1:0)|0,t[5]=t[5]+886263092+(t[4]>>>0<r[4]>>>0?1:0)|0,t[6]=t[6]+1295307597+(t[5]>>>0<r[5]>>>0?1:0)|0,t[7]=t[7]+3545052371+(t[6]>>>0<r[6]>>>0?1:0)|0,this._b=t[7]>>>0<r[7]>>>0?1:0,i=0;i<8;i++){var s=e[i]+t[i],n=65535&s,c=s>>>16,o=((n*n>>>17)+n*c>>>15)+c*c,d=((4294901760&s)*s|0)+((65535&s)*s|0);a[i]=o^d}e[0]=a[0]+(a[7]<<16|a[7]>>>16)+(a[6]<<16|a[6]>>>16)|0,e[1]=a[1]+(a[0]<<8|a[0]>>>24)+a[7]|0,e[2]=a[2]+(a[1]<<16|a[1]>>>16)+(a[0]<<16|a[0]>>>16)|0,e[3]=a[3]+(a[2]<<8|a[2]>>>24)+a[1]|0,e[4]=a[4]+(a[3]<<16|a[3]>>>16)+(a[2]<<16|a[2]>>>16)|0,e[5]=a[5]+(a[4]<<8|a[4]>>>24)+a[3]|0,e[6]=a[6]+(a[5]<<16|a[5]>>>16)+(a[4]<<16|a[4]>>>16)|0,e[7]=a[7]+(a[6]<<8|a[6]>>>24)+a[5]|0}e.Rabbit=t._createHelper(c)}(),s.Rabbit)},function(e,t,i){var s;e.exports=(s=i(0),i(7),i(8),i(6),i(1),function(){var e=s,t=e.lib.StreamCipher,i=e.algo,n=[],r=[],a=[],c=i.RabbitLegacy=t.extend({_doReset:function(){var e=this._key.words,t=this.cfg.iv,i=this._X=[e[0],e[3]<<16|e[2]>>>16,e[1],e[0]<<16|e[3]>>>16,e[2],e[1]<<16|e[0]>>>16,e[3],e[2]<<16|e[1]>>>16],s=this._C=[e[2]<<16|e[2]>>>16,4294901760&e[0]|65535&e[1],e[3]<<16|e[3]>>>16,4294901760&e[1]|65535&e[2],e[0]<<16|e[0]>>>16,4294901760&e[2]|65535&e[3],e[1]<<16|e[1]>>>16,4294901760&e[3]|65535&e[0]];this._b=0;for(var n=0;n<4;n++)o.call(this);for(n=0;n<8;n++)s[n]^=i[n+4&7];if(t){var r=t.words,a=r[0],c=r[1],d=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),l=16711935&(c<<8|c>>>24)|4278255360&(c<<24|c>>>8),u=d>>>16|4294901760&l,h=l<<16|65535&d;for(s[0]^=d,s[1]^=u,s[2]^=l,s[3]^=h,s[4]^=d,s[5]^=u,s[6]^=l,s[7]^=h,n=0;n<4;n++)o.call(this)}},_doProcessBlock:function(e,t){var i=this._X;o.call(this),n[0]=i[0]^i[5]>>>16^i[3]<<16,n[1]=i[2]^i[7]>>>16^i[5]<<16,n[2]=i[4]^i[1]>>>16^i[7]<<16,n[3]=i[6]^i[3]>>>16^i[1]<<16;for(var s=0;s<4;s++)n[s]=16711935&(n[s]<<8|n[s]>>>24)|4278255360&(n[s]<<24|n[s]>>>8),e[t+s]^=n[s]},blockSize:4,ivSize:2});function o(){for(var e=this._X,t=this._C,i=0;i<8;i++)r[i]=t[i];for(t[0]=t[0]+1295307597+this._b|0,t[1]=t[1]+3545052371+(t[0]>>>0<r[0]>>>0?1:0)|0,t[2]=t[2]+886263092+(t[1]>>>0<r[1]>>>0?1:0)|0,t[3]=t[3]+1295307597+(t[2]>>>0<r[2]>>>0?1:0)|0,t[4]=t[4]+3545052371+(t[3]>>>0<r[3]>>>0?1:0)|0,t[5]=t[5]+886263092+(t[4]>>>0<r[4]>>>0?1:0)|0,t[6]=t[6]+1295307597+(t[5]>>>0<r[5]>>>0?1:0)|0,t[7]=t[7]+3545052371+(t[6]>>>0<r[6]>>>0?1:0)|0,this._b=t[7]>>>0<r[7]>>>0?1:0,i=0;i<8;i++){var s=e[i]+t[i],n=65535&s,c=s>>>16,o=((n*n>>>17)+n*c>>>15)+c*c,d=((4294901760&s)*s|0)+((65535&s)*s|0);a[i]=o^d}e[0]=a[0]+(a[7]<<16|a[7]>>>16)+(a[6]<<16|a[6]>>>16)|0,e[1]=a[1]+(a[0]<<8|a[0]>>>24)+a[7]|0,e[2]=a[2]+(a[1]<<16|a[1]>>>16)+(a[0]<<16|a[0]>>>16)|0,e[3]=a[3]+(a[2]<<8|a[2]>>>24)+a[1]|0,e[4]=a[4]+(a[3]<<16|a[3]>>>16)+(a[2]<<16|a[2]>>>16)|0,e[5]=a[5]+(a[4]<<8|a[4]>>>24)+a[3]|0,e[6]=a[6]+(a[5]<<16|a[5]>>>16)+(a[4]<<16|a[4]>>>16)|0,e[7]=a[7]+(a[6]<<8|a[6]>>>24)+a[5]|0}e.RabbitLegacy=t._createHelper(c)}(),s.RabbitLegacy)},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(16),r=i(4),a=i(2);class c extends r.default{}c.pack=(e,t,i)=>s(void 0,void 0,void 0,(function*(){const s=yield n.default.getConfigFile(e);if(s){const e="var_len"===s.protocolType,n=[0,0,0,3],r=[0];let c=[0];const o=[0,147];let d=[0,0,0,0],l=[2];if(t){c=[1];const e=a.fillString(t.length.toString(16),4),i=a.hexStrint2byte(e),s=a.string2Bytes(t);d=d.concat(i).concat(s)}if(e){l=[18];let e="";if(i){const t=i.reduce((e,t)=>Object.assign(Object.assign({},e),{[t]:1}),{});s.entities[0].attrs.map(i=>{e=t[i.name]?`1${e}`:`0${e}`})}else s.entities[0].attrs.map(()=>{e=`1${e}`});e=a.fillString(e,8*Math.ceil(e.length/8)),l=l.concat(a.hexStrint2byte(parseInt(e,2).toString(16)))}const u=c.concat(o).concat(d).concat(l);return r[0]=u.length,n.concat(r).concat(u)}return null})),t.default=c},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(5),r=i(3),a=i(12),c=i(10);t.default=class{constructor({appID:e,token:t,uid:i,limitSocketNum:r=!0}){this._bindingDevices=null,this._connections={},this.updateToken=({token:e,uid:t})=>{this.token=e,this.uid=t},this._getDevice=e=>{if(null===this._bindingDevices)return n.default.GIZ_SDK_SDK_NOT_INITIALIZED;const t=this._bindingDevices[e];return null==t?n.default.GIZ_OPENAPI_DEVICE_NOT_BOUND:t},this._getConnect=e=>{const t=this._getWebsocketConnInfo(e);return this._connections[t]},this._getDeviceAndConnect=e=>{const t=this._getDevice(e);if(c.isError(t))return t;const i=this._getConnect(t);return null==i?n.default.GIZ_SDK_DEVICE_NOT_SUBSCRIBED:[t,i]},this.connectDevice=e=>{const t=this._getWebsocketConnInfo(e);let i=this._connections[t];if(null==i){const e=Object.keys(this._connections).length;if(0!==this._maxSocketNum&&e>=this._maxSocketNum)return{success:!1,errorCode:n.default.MAX_CONNECT};i=new o({appID:this.appID,token:this.token,uid:this.uid,wsInfo:t,onDeviceStatusChanged:this._handleDeviceStatusChanged,onBindingChanged:this._handleBindingChanged,onSocketStatusChanged:this._handleSocketStatusChanged}),this._connections[t]=i}return i._addSubDid(e.did),null==i._websocket?i._connectWS():i.ready&&i._subDevices([e.did]),{success:!0}},this.disConnectDevice=e=>{const t=this._getWebsocketConnInfo(e);let i=this._connections[t];return i&&i._unSubDevices([e.did]),{success:!0}},this.connect=e=>{const t=this._getDevice(e);if(c.isError(t))return t;const i=this.connectDevice(t);return i.success?null:i.errorCode},this.send=(e,t)=>{const i=this._getDeviceAndConnect(e);return c.isError(i)?i:i[1]._send({cmd:"c2s_raw",data:{did:e,raw:t}})},this.writeData=(e,t)=>{const i=this._getConnect(e);return null!=i?i._send({cmd:"c2s_write",data:{did:e.did,attrs:t}}):{success:!1}},this.write=(e,t)=>{const i=this._getDeviceAndConnect(e);return c.isError(i)?i:i[1]._send({cmd:"c2s_write",data:{did:e,attrs:t}})},this.readStatus=(e,t)=>{const i=this._getConnect(e),s=null!=i;return s&&i._send({cmd:"c2s_read",data:{did:e.did,names:t}}),{success:s}},this.read=(e,t)=>{const i=this._getDeviceAndConnect(e);return c.isError(i)?i:i[1]._send({cmd:"c2s_read",data:{did:e,names:t}})},this.destory=()=>{Object.values(this._connections).forEach(e=>e.destory())},this.subscribeDeviceStatus=e=>{this._onDeviceStatusChanged=e},this.subscribeBindingChanged=e=>{this._onBindingChanged=e},this.subscribeSocketStatus=e=>{this._onSocketStatusChanged=e},this._handleDeviceStatusChanged=e=>{this._onDeviceStatusChanged&&this._onDeviceStatusChanged(e)},this._handleBindingChanged=()=>{this._onBindingChanged&&this._onBindingChanged()},this._handleSocketStatusChanged=(...e)=>{this._onSocketStatusChanged&&this._onSocketStatusChanged(...e)},this._getBindingList=(e=20,t=0,i=[])=>s(this,void 0,void 0,(function*(){const s=`/app/bindings?show_disabled=0&limit=${e}&skip=${t}`,{err:n,data:r}=yield a.default(`${s}`,{method:"GET"});if(n)return{err:n};const c=[...i,...(null==r?void 0:r.devices)||[]];return r&&r.devices.length===e?yield this._getBindingList(e,e+t,c):c})),this._getWebsocketConnInfo=e=>e.host?`wss://wx${e.host}`:"wss://wxstage.gizwits.com",this.appID=e,this.token=t,this.uid=i;const d=wx.getSystemInfoSync().SDKVersion;this._maxSocketNum=r?-1===c.compareWXSDKVersion(d||"1.0.0","1.7.0")?1:5:0}init(){var e,t;return s(this,void 0,void 0,(function*(){try{const i=yield this._getBindingList();return(null===(e=i.err)||void 0===e?void 0:e.errorCode)?{errorCode:null===(t=i.err)||void 0===t?void 0:t.errorCode,errorMessage:"getting binding list failed"}:(this._bindingDevices=i.reduce((e,t)=>Object.assign(Object.assign({},e),{[t.did]:t}),{}),null)}catch(e){return n.default.GIZ_SDK_OTHERWISE}}))}};class o{constructor({appID:e,token:t,uid:i,wsInfo:n,onDeviceStatusChanged:a,onBindingChanged:c,onSocketStatusChanged:o}){this.ready=!1,this.commType="attrs_v4",this._heartbeatInterval=60,this._keepaliveTime=180,this._loginIntveral=5e3,this.autoSubscribe=!1,this._websocket=null,this._loginFailedTimes=0,this._subDids=new Set,this._socketRespHandleMap={},this._waitSends=[],this.destory=()=>{this._heartbeatTimerId&&clearInterval(this._heartbeatTimerId),this._checkConnectTimerId&&clearInterval(this._checkConnectTimerId),this.close()},this._networkChange=e=>s(this,void 0,void 0,(function*(){r.default.log("network change",e)})),this._appShow=()=>s(this,void 0,void 0,(function*(){r.default.log("app show")})),this._addSubDid=e=>{this._subDids.add(e)},this._removeSubDid=e=>{this._subDids.delete(e)},this._connectWS=()=>{r.default.log("GIZ_SDK: start connect ws"),this._websocket=wx.connectSocket({url:this._wsUrl,fail:e=>{r.default.error("GIZ_SDK: connectSocket error",new Error(JSON.stringify(e)))}}),this._websocket.onClose(this.handleClose),this._websocket.onOpen(this.handleOpen),this._websocket.onError(this.handleError),this._websocket.onMessage(this.handleMessage),this._checkConnectTimerId||(this._checkConnectTimerId=setInterval(()=>{this._websocket||this._connectWS()},1e3))},this._subDevices=e=>{const t={cmd:"subscribe_req",data:e.map(e=>({did:e}))};this._send(t)},this._unSubDevices=e=>{e.map(e=>this._removeSubDid(e))},this._send=(e,t=!1)=>(r.default.log("GIZ_SDK: Socket send",e,t),new Promise(i=>{this._websocket?t||this.ready?this._websocket&&(t||this.ready)&&this._websocket.send({data:JSON.stringify(e),complete:e=>{r.default.log("GIZ_SDK: socket send res",e),r.default.log("resres",e);let t=!1;"sendSocketMessage:ok"===e.errMsg&&(t=!0),i({success:t,message:e.errMsg})},fail:e=>{r.default.error("GIZ_SDK: Socket send error",new Error(JSON.stringify(e))),i({success:!1,message:e.errMsg})}}):i({success:!1,message:"Socket not ready"}):i({success:!1,message:"Socket not init"})})),this.close=()=>{this.ready=!1,this._heartbeatTimerId&&clearInterval(this._heartbeatTimerId),this._websocket&&(this._websocket.close({}),this._websocket=null),this._handleSocketStatusChanged(!1)},this.handleClose=e=>{r.default.error("GIZ_SDK: socket close",new Error(JSON.stringify(e))),this.close(),this._stopPing()},this.handleOpen=()=>{r.default.log(" socket open"),this._login()},this.handleMessage=({data:e})=>{r.default.log("GIZ_SDK: message",e);const t=JSON.parse(e),i=this._socketRespHandleMap[t.cmd];i&&i(t.data)},this.handleError=e=>{r.default.error("GIZ_SDK: socket error",new Error(JSON.stringify(e))),this.close(),this._stopPing()},this._login=()=>{const e={cmd:"login_req",data:{appid:this.appID,uid:this.uid,token:this.token,p0_type:this.commType,heartbeat_interval:this._keepaliveTime,auto_subscribe:this.autoSubscribe}};this._send(e,!0)},this._tryLoginAgain=()=>{this._loginFailedTimes+=1,setTimeout(()=>{this._login()},this._loginFailedTimes*this._loginIntveral)},this._startPing=()=>{this._heartbeatTimerId=setInterval(()=>{this._send({cmd:"ping"})},1e3*this._heartbeatInterval)},this._stopPing=()=>{this._heartbeatTimerId&&clearInterval(this._heartbeatTimerId)},this.pongResp=()=>{},this._loginResp=e=>{1==e.success?(this._loginFailedTimes=0,this.ready=!0,this._startPing(),this._subDevices([...this._subDids]),this._handleSocketStatusChanged(!0),this._consumeWaitSends()):this._loginFailedTimes<3?(r.default.log("GIZ_SDK: Login failed, will try again, please wait..."),this._tryLoginAgain()):(r.default.error("GIZ_SDK: Login failed",new Error("m2m socket login failed")),this.close())},this._consumeWaitSends=()=>{let e=this._waitSends.pop();for(;e;)this._send(e),e=this._waitSends.pop()},this._handleSocketStatusChanged=e=>{this._onSocketStatusChanged&&this._onSocketStatusChanged([...this._subDids],e)},this._subscribeResp=e=>{r.default.log("GIZ_SDK: subscribe_res",e),e&&e.success&&e.success.forEach(e=>this._send({cmd:"c2s_read",data:{did:e.did}})),r.default.debug("GIZ_SDK: subscribe_res",e)},this._onlineResp=e=>{this._isSub(e.did)&&this._onDeviceStatusChanged&&this._onDeviceStatusChanged({did:e.did,attrs:Object.assign({is_online:e.online},e)})},this._rawChangedResp=e=>{this._isSub(e.did)&&this._onDeviceStatusChanged&&this._onDeviceStatusChanged(e)},this._statusChangedResp=e=>{this._isSub(e.did)&&this._onDeviceStatusChanged&&this._onDeviceStatusChanged(e)},this._isSub=e=>this._subDids.has(e),this._invalidMsgResp=e=>{1003===e.error_code&&this._login(),r.default.error("GIZ_SDK: s2c_invalid_msg",new Error(JSON.stringify(e)))},this._bindingChangedResp=e=>{!e.bind&&e.did&&this._removeSubDid(e.did),this._onBindingChanged&&this._onBindingChanged()},this.appID=e,this.token=t,this.uid=i,this._wsUrl=`${n}/ws/app/v1`,this._heartbeatTimerId=void 0,this._loginFailedTimes=0,this._onDeviceStatusChanged=a,this._onBindingChanged=c,this._onSocketStatusChanged=o,this._socketRespHandleMap={pong:this.pongResp,login_res:this._loginResp,subscribe_res:this._subscribeResp,s2c_online_status:this._onlineResp,s2c_raw:this._rawChangedResp,s2c_noti:this._statusChangedResp,s2c_invalid_msg:this._invalidMsgResp,s2c_binding_changed:this._bindingChangedResp},wx.onNetworkStatusChange(this._networkChange),wx.onAppShow(this._appShow)}}t.Connection=o},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(5),r=i(3),a=i(28),c=i(29);class o extends c.default{constructor(){super(...arguments),this.disableSendUDP=!1,this.sendMessageInterval=null,this.UDPSocketHandler=null,this.destroy=()=>{this.cleanTimeout(),this.sendMessageInterval&&clearInterval(this.sendMessageInterval),this.sendMessageInterval=null,this.UDPSocketHandler&&(this.UDPSocketHandler.offError(),this.UDPSocketHandler.offMessage(),this.UDPSocketHandler.close())},this.configDevice=({ssid:e,password:t,softAPSSIDPrefix:i})=>new Promise((c,o)=>{r.default.debug("GIZ_SDK: start config device");let d=!1,l=0;const u=a.default.pack(e,t);this.UDPSocketHandler=wx.createUDPSocket(),this.UDPSocketHandler.bind(),this.disableSendUDP=!1;const h=()=>{try{!this.disableSendUDP&&this.UDPSocketHandler.send({address:"10.10.100.254",port:12414,message:u,offset:0,length:u.byteLength})}catch(e){}};this.sendMessageInterval=setInterval(()=>{h()},2e3),this.UDPSocketHandler.onError(e=>{l+=1,l>2&&(this.destroy(),o({success:!1,err:{errorCode:n.default.WECHAT_ERROR.errorCode,errorMessage:e.errMsg}}))});const f=()=>s(this,void 0,void 0,(function*(){if(!d){this.UDPSocketHandler.offMessage(),this.UDPSocketHandler.offError(),this.sendMessageInterval&&clearInterval(this.sendMessageInterval),this.disableSendUDP=!0,d=!0;try{const i=yield this.searchDevice({ssid:e,password:t});c(i)}catch(e){o(e)}}}));this.UDPSocketHandler.onMessage(e=>{f()}),wx.onNetworkStatusChange(()=>s(this,void 0,void 0,(function*(){!d&&wx.getConnectedWifi({success:e=>s(this,void 0,void 0,(function*(){-1===e.wifi.SSID.indexOf(i)&&f()}))})})))}),this.setDeviceOnboardingDeploy=({timeout:e,isBind:t=!0,softAPSSIDPrefix:i})=>{const n=this.ssid,r=this.password;return new Promise((a,c)=>s(this,void 0,void 0,(function*(){this.destroy(),this.initDeviceOnboardingDeploy(a,c),this.startTimeoutTimer(e);try{const e=((yield this.configDevice({ssid:n,password:r,softAPSSIDPrefix:i})).data||[]).map(e=>({mac:e.mac,productKey:e.product_key,did:e.did,name:"",isBind:!1,connectType:"NONE",isBleOnline:!1,isLanOnline:!1,isOnline:!1}));if(t)try{a(yield this.bindDevices(e))}catch(e){c(e)}else a({success:!0,data:e})}catch(e){c(e)}finally{this.destroy()}})))}}}t.default=o},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(11),n=({SSID:e,password:t,pk:i})=>{let n=s.MD5(e+t).toString();n=s.enc.Hex.parse(n);let r=s.enc.Utf8.parse(i),a=s.AES.encrypt(r,n,{iv:n,mode:s.mode.ECB,padding:s.pad.ZeroPadding});return s.MD5(a.ciphertext).toString()};t.default=({SSID:e,password:t,pks:i})=>{const s=[];return i.map(i=>{const r=n({SSID:e,password:t,pk:i});s.push(r)}),s}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(11);t.psKeySign=e=>{const t=Math.round((new Date).getTime()/1e3),i=e+t;return{Signature:s.MD5(i).toString(),timestamp:t}}},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(5),r=i(10),a=i(23),c=i(9),o=i(29),d=i(28),l=i(3);function u({bleDeviceId:e,arrayBuffer:t,serviceUUIDSuffix:i="abf0",characteristicUUIDSuffix:n="abf7",bleHandle:c}){let o=null,d=null;const u=()=>null===d&&(o&&clearInterval(o),!0);return new Promise((h,f)=>s(this,void 0,void 0,(function*(){try{l.default.debug("GIZ_SDK: ssid info: ",t),d=setTimeout(()=>{o&&clearInterval(o),d=null,h(!1)},5e3),l.default.debug("GIZ_SDK: createBLEConnection start: ",e),yield c.disableScan();const s=yield a.retryConnect(e,1e4);c.enableScan(),l.default.debug("GIZ_SDK: createBLEConnection end, res:",s);const f=yield a.getBLEDeviceServices(e);l.default.debug("GIZ_SDK: getBLEDeviceServices end, res:",f);const p=f.find(e=>e.uuid.split("-")[0].toLowerCase().endsWith(i));if(!p)return l.default.debug("GIZ_SDK: get ble device services fail",e,f),void h(!1);const v=yield a.getBLEDeviceCharacteristics(e,p.uuid);l.default.debug("GIZ_SDK: getBLEDeviceCharacteristics end, res:",v);const g=v.find(e=>e.uuid.split("-")[0].toLowerCase().endsWith(n));if(!g)return l.default.debug("GIZ_SDK: get ble device characteristics fail",e,v),void h(!1);if(!g.properties.notify&&!g.properties.indicate)return l.default.debug("GIZ_SDK: the ble device characteristic not support notify or indicate",e,g),void h(!1);l.default.debug("GIZ_SDK: check characteristic and service success"),yield a.notifyBLECharacteristicValueChange(e,p.uuid,g.uuid);const y=e=>{const t=r.ab2hex(e.value);l.default.debug("GIZ_SDK: 收到设备返回ack",t),"0000000303000002"===t&&(c.removeEventListener("GizBleDeviceData",y),h(!0))};if(c.addEventListener("GizBleDeviceData",y),l.default.debug("GIZ_SDK: on notifyBLECharacteristicValueChange success"),u())return;yield a.unpackWriteBLECharacteristicValue(e,p.uuid,g.uuid,t),o=setInterval(()=>{u()||a.unpackWriteBLECharacteristicValue(e,p.uuid,g.uuid,t)},2e3),l.default.debug("GIZ_SDK: unpackWriteBLECharacteristicValue end")}catch(e){f(!1),l.default.debug("GIZ_SDK: sendBLEConfigCmd error",e)}}))).catch(e=>{l.default.debug("GIZ_SDK: sendBLEConfigCmd error",e)}).finally(()=>{d&&clearTimeout(d),o&&clearInterval(o),wx.closeBLEConnection({deviceId:e})})}t.sendBLEConfigCmd=u;class h extends o.default{constructor(e,t,i,o,h){super(e,t,i,o),this.destroy=()=>{this.cleanTimeout()},this.isValidBleDevice=(e,t)=>{if(!e||!e.advertisData)return!1;const{productKey:i,mac:s}=r.advertisData2PkAndMac(e.advertisData,this.specialProductKeys);return!!this.specialProductKeys.includes(i)&&(l.default.debug(`GIZ_SDK: isValidBleDevice mac: ${s} pk: ${i} name: ${e.name}`),l.default.debug(`GIZ_SDK: softAPSSIDPrefix: ${t} ismatch : ${e.name&&e.name.startsWith(t)}`),!t||e.name&&e.name.startsWith(t))},this.enableBluetoothDevicesDescovery=()=>s(this,void 0,void 0,(function*(){return(yield a.getBluetoothAdapterState()).available?(yield a.startBluetoothDevicesDiscovery(),{success:!0}):{success:!1,err:{errorCode:n.default.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON.errorCode,errorMessage:"蓝牙状态不可用"}}})),this.enableAndGetBluetoothDevices=e=>s(this,void 0,void 0,(function*(){const t=yield this.enableBluetoothDevicesDescovery();if(!t.success)return t;l.default.debug("GIZ_SDK: start enableAndGetBluetoothDevices");const i=(yield a.getBluetoothDevices()).filter(t=>this.isValidBleDevice(t,e));return l.default.debug("GIZ_SDK: getBluetoothDevices success",i),{success:!0,bleDevices:i}})),this.setDeviceOnboardingDeploy=({timeout:e,isBind:t=!0,softAPSSIDPrefix:i})=>new Promise((n,r)=>s(this,void 0,void 0,(function*(){const s=this.ssid,a=this.password;this.destroy(),this.initDeviceOnboardingDeploy(n,r),this.startTimeoutTimer(e);try{const r=((yield this.configBLEDevice({ssid:s,password:a,timeout:1e3*e,softAPSSIDPrefix:i})).data||[]).map(e=>({mac:e.mac,productKey:e.product_key,did:e.did,name:"",isBind:!1,connectType:"NONE",isBleOnline:!1,isLanOnline:!1,isOnline:!1}));n(t?yield this.bindDevices(r):{success:!0,data:r})}catch(e){n({success:!1,data:e})}finally{this.destroy()}}))),this.configBLEDevice=({ssid:e,password:t,softAPSSIDPrefix:i})=>new Promise((o,h)=>s(this,void 0,void 0,(function*(){l.default.debug("GIZ_SDK: start config ble device");const f=yield this.enableAndGetBluetoothDevices(i).catch(e=>({success:!1,err:{errorCode:n.default.WECHAT_ERROR.errorCode,errorMessage:JSON.stringify(e)}}));if(!r.isWXDevicesResult(f))return h(f);const{bleDevices:p}=f;l.default.debug("GIZ_SDK: enableAndGetBluetoothDevices success, target devices: ",p);const v=({devices:e})=>s(this,void 0,void 0,(function*(){this.hasTimeoutHandler()?Array.prototype.push.apply(p,e.filter(e=>this.isValidBleDevice(e,i))):wx.offBluetoothDeviceFound(v)}));wx.onBluetoothDeviceFound(v);const g=d.default.pack(e,t),y=()=>s(this,void 0,void 0,(function*(){if(l.default.debug("GIZ_SDK: startConfigDevice"),!this.hasTimeoutHandler())return;const e=p.shift();if(e&&l.default.debug("GIZ_SDK: startConfigDevice, target device: ",e),!(e&&(yield u({bleDeviceId:e.deviceId,arrayBuffer:g.buffer,bleHandle:this.bleHandle}))))return yield c.default(500),yield a.startBluetoothDevicesDiscovery(),void(yield y());l.default.debug("GIZ_SDK: offBluetoothDeviceFound ready search device"),wx.offBluetoothDeviceFound(v)}));try{this.searchDevice({ssid:e,password:t}).then(e=>{o(e)})}catch(e){h(e),l.default.error("GIZ_SDK: searchDevice error",new Error(JSON.stringify(e)))}yield y()}))),this.bleHandle=h}}t.default=h},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(12);t.AnonymousLogin=function({uid:e}){return s(this,void 0,void 0,(function*(){return n.default("/app/users",{data:{phone_id:e},method:"POST"},!1)}))}},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(3),r=i(24),a=i(68),c=i(25),o=i(4),d=i(2),l=i(9),u=i(10),h=i(27);class f extends h.default{constructor({pks:e}){super(),this.connectedList=[],this.pks=[],this.scanList=[],this.deviceUDPPort=12414,this.appUDPPort=2415,this.offlineThreshold=2e4,this.isActive=!0,this.listenDevOfflineTimer=null,this.init=()=>{this.UDPSocket&&(this.UDPSocket=wx.createUDPSocket(),this.UDPSocket.bind(),this.UDPSocket.onMessage(this.onMessage),this.UDPSocket.onError(this.onError),n.default.info("Start UDP Discover"),this.startDiscover(),this.listenDevOffline(this.offlineThreshold),wx.onAppShow(this.onAppShow),wx.onAppHide(this.onAppHide))},this.onAppShow=()=>{this.isActive=!0,this.scanList.map(e=>{e.ctime=Date.now()})},this.onAppHide=()=>{this.isActive=!1},this.listenDevOffline=e=>{this.listenDevOfflineTimer=setInterval(()=>{if(!this.isActive)return;const t=(new Date).getTime(),i=this.scanList.filter(i=>t-i.ctime<e);i.length!==this.scanList.length&&(n.default.debug("remove lan device"),this.scanList=i,this.notifyDevices())},500)},this.notifyDevices=()=>{this.listenerMap.GizLanDeviceList&&this.listenerMap.GizLanDeviceList.map(e=>{e(this.scanList)})},this.notifyDeviceData=(e,t)=>{this.listenerMap.GizLanDeviceData&&this.listenerMap.GizLanDeviceData.map(i=>{i(e,t)})},this.isSameDevice=(e,t)=>e.mac===t.mac&&e.productKey===t.productKey,this.disConnectDevice=e=>{const t=this.connectedList.findIndex(t=>t.productKey===e.productKey&&t.mac===e.mac);try{return-1!==t&&(this.connectedList[t].socketHandle.destory(),this.connectedList.splice(t,1)),{success:!0}}catch(e){return{success:!1,err:e}}},this.onData=(e,t)=>{this.notifyDeviceData(e,t)},this.connectDevice=e=>s(this,void 0,void 0,(function*(){const t=this.scanList.find(t=>this.isSameDevice(e,t));if(!t)return{success:!1};if(this.connectedList.find(t=>this.isSameDevice(e,t)))return{success:!0};{const e=new p({ip:t.ip,mac:t.mac,productKey:t.productKey,onClose:this.onDeviceClose,onData:this.onData}),i=yield e.connect();return i.success?this.connectedList.push({mac:t.mac,productKey:t.productKey,socketHandle:e}):e.destory(),i}})),this.onError=e=>{n.default.warn("Discover Error",e)},this.isMatchPk=e=>0===this.pks.length||this.pks.includes(e),this.onMessage=e=>{const t=u.ab2numbers(e.message),i=new a.default(t);""!==i.mac&&this.isMatchPk(i.productKey)&&this.updateDevice(i,e.remoteInfo.address)},this.onDeviceClose=({productKey:e,mac:t})=>{const i=this.connectedList.findIndex(i=>i.productKey===e&&i.mac===t);-1!==i&&this.connectedList.splice(i,1)},this.write=(e,t)=>s(this,void 0,void 0,(function*(){n.default.debug("send data to device",e,t,this.connectedList);const i=this.connectedList.findIndex(t=>this.isSameDevice(t,e));if(-1!==i){return this.connectedList[i].socketHandle.write(t)}return{success:!1,message:"device not sub"}})),this.updateDevice=(e,t)=>{const i=this.scanList.find(t=>t.mac===e.mac);if(i)i.ctime=Date.now();else{const i={mac:e.mac,ip:t,productKey:e.productKey,did:e.did,expandData:e,name:"",isBind:!1,connectType:"NONE",isOnline:!1,isLanOnline:!0,isBleOnline:!1,ctime:Date.now()};this.scanList.push(i),this.notifyDevices()}},this.sendBoradCast=()=>{this.UDPSocket&&(this.UDPSocket.send({address:"255.255.255.255",message:a.default.pack(),port:this.deviceUDPPort}),n.default.debug("Send UDP Discover"))},this.startDiscover=()=>{this.sendBoradCast(),this.boradcastTimer=setInterval(()=>{this.sendBoradCast()},5e3)},this.destory=()=>{this.boradcastTimer&&clearInterval(this.boradcastTimer),this.UDPSocket&&this.UDPSocket.close(),this.listenDevOfflineTimer&&clearInterval(this.listenDevOfflineTimer),wx.offAppShow(this.onAppShow),wx.offAppHide(this.onAppHide)},this.pks=e}}t.LanHandle=f;class p{constructor({ip:e,onClose:t,mac:i,productKey:a,onData:h}){this.deviceTCPPort=12416,this.ip="",this.productKey="",this.mac="",this.tcpHandler=null,this.onData=(e,t)=>{},this.onCloseListener=({mac:e,productKey:t})=>{},this.connect=()=>s(this,void 0,void 0,(function*(){return new Promise(e=>s(this,void 0,void 0,(function*(){const t=()=>{const e=r.default.pack();this.tcpHandler.write(d.arrayToUint8(e)),n.default.debug("connect success try login")},i=t=>{e({success:!0,err:t})},s=t=>{switch(new o.default(u.ab2numbers(t.message)).cmd){case"0007":{const e=new r.default(u.ab2numbers(t.message)),i=c.default.pack({passcode:e.passcode});this.tcpHandler.write(d.arrayToUint8(i));break}case"0009":new c.default(u.ab2numbers(t.message)).result?(e({success:!0}),this.initListener()):e({success:!1})}};try{this.tcpHandler=wx.createTCPSocket(),this.tcpHandler.onConnect(t),this.tcpHandler.onError(i),this.tcpHandler.onMessage(s),this.tcpHandler.connect({address:this.ip,port:this.deviceTCPPort,timeout:2}),yield l.default(4e3),e({success:!1,err:null})}catch(t){n.default.error("connect lan error",t),e({success:!1,err:null})}finally{this.tcpHandler.offConnect(t),this.tcpHandler.offError(i),this.tcpHandler.offMessage(s)}})))})),this.write=e=>(this.tcpHandler.write(e),{success:!0}),this.onMessage=e=>{try{const t=u.ab2hex(e.message),i=new o.default(d.hexStrint2byte(t));n.default.debug("on tcp message",i),this.onData(this.mac,t)}catch(e){}},this.onError=()=>{},this.onClose=()=>{this.onCloseListener({productKey:this.productKey,mac:this.mac})},this.initListener=()=>{this.tcpHandler.onError(this.onError),this.tcpHandler.onMessage(this.onMessage),this.tcpHandler.onClose(this.onClose)},this.destory=()=>{this.tcpHandler&&this.tcpHandler.close(),this.tcpHandler.offError(this.onError),this.tcpHandler.offMessage(this.onMessage),this.tcpHandler.offClose(this.onClose)},this.ip=e,this.mac=i,this.productKey=a,this.onData=h,this.onCloseListener=t}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(3),n=i(4),r=i(2);class a extends n.default{constructor(e){super(e),this.did="",this.mac="",this.productKey="",this.deviceType=0,this.apiUrl="",this.protocolVersion="",this.mcuVersion="",this.moduleVersion="",this.parseEndChat=(e,t)=>{let i="";const s=this.content.slice(e,this.content.length);for(let t in s){const n=s[t];if(e+=1,0===n)break;i+=String.fromCharCode(n)}return this[t]=i,e},this.baseParse=(e,t,i="ASCII")=>{const s=parseInt(r.arrayToString(this.content.slice(e,e+2)),16);e+=2;let n="";return this.content.slice(e,e+s).map(e=>{if("ASCII"===i)n+=String.fromCharCode(e);else{const t=e.toString(16);n+=r.fillString(t,2)}}),this[t]=n,e+s};let t=0;try{t=this.baseParse(t,"did"),t=this.baseParse(t,"mac","HEX"),t=this.baseParse(t,"moduleVersion"),t=this.baseParse(t,"productKey"),t+=8,t=this.parseEndChat(t,"apiUrl"),t=this.parseEndChat(t,"protocolVersion"),this.mcuVersion="",this.content.slice(t,this.content.length).map(e=>{this.mcuVersion+=String.fromCharCode(e)})}catch(e){s.default.warn("Parse DiscoverUDP error",e)}}}a.pack=()=>{const e=[0,0,0,3,3,0,0,3],t=new ArrayBuffer(e.length),i=new Uint8Array(t);for(let s=0;s<t.byteLength;s++)i[s]=e[s];return i},t.default=a},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(4),n=i(2);class r extends s.default{constructor(e){super(e),this.state=0,this.len=0;let t=0;this.len=parseInt(n.arrayToString(this.content.slice(t,t+2)),16),t+=2,this.state=this.content[t]}}t.RequestSync=r,r.pack=()=>[0,0,0,3,3,0,0,81];class a extends s.default{constructor(e){super(e),this.id=0,this.timestemp=0,this.payloadLen=0,this.payload=[];let t=0;this.id=parseInt(n.arrayToString(this.content.slice(t,t+2)),16),t+=2,this.timestemp=parseInt(n.arrayToString(this.content.slice(t,t+5)),16),t+=5,this.payloadLen=parseInt(n.arrayToString(this.content.slice(t,t+2)),16),t+=2,this.payload=this.content.slice(t,this.content.length)}}t.SyncPackage=a,a.pack=e=>{let t=e.toString(2);return t=n.fillString(t,16),[0,0,0,3,5].concat([0,0,83]).concat(n.completeBlock(t))};class c extends s.default{}t.DeletePackage=c,c.pack=e=>{let t=e.toString(2);return t=n.fillString(t,16),[0,0,0,3,5].concat([0,0,85]).concat(n.completeBlock(t))};class o extends s.default{constructor(e){super(e),this.state=0,this.state=this.content[0]}}t.CancelSync=o,o.pack=()=>[0,0,0,3,3,0,0,87]},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(12),r=i(11);t.uploadP0=function({device:e,data:t,productSecret:i}){return s(this,void 0,void 0,(function*(){const s=`/v2/products/${e.productKey}/devices/offline-data`;let a=e.passcode;const c=r.enc.Hex.parse(i),o=r.enc.Hex.parse(""),d=r.enc.Utf8.parse(a);return a=r.AES.encrypt(d,c,{iv:o,mode:r.mode.ECB,padding:r.pad.Pkcs7}).ciphertext.toString().toUpperCase(),n.default(s,{data:{data:t,encoding:"hex"},method:"POST",headers:{"X-Gizwits-Device-Id":e.did,"X-Gizwits-Device-passcode":a}},!1)}))}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(4),n=i(2);class r extends s.default{}r.pack=()=>{const e=parseInt(`${Date.now()/1e3}`,10),t=n.fillString(e.toString(2),40);return[0,0,0,3,8,0,0,89].concat(n.completeBlock(t))},t.default=r}]);
@@ -33,7 +33,7 @@ export default class GizwitsWS {
33
33
  token: any;
34
34
  uid: any;
35
35
  }) => void;
36
- _getDevice: (did: string) => IDevice | IError;
36
+ _getDevice: (did: string) => IError | IDevice;
37
37
  _getConnect: (device: IDevice) => Connection;
38
38
  _getDeviceAndConnect: (did: string) => IError | [IDevice, Connection];
39
39
  connectDevice: (device: IDevice) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mini_program_gizwits_sdk",
3
- "version": "3.2.16",
3
+ "version": "3.2.17",
4
4
  "description": "修正socket的返回机制",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
@@ -412,7 +412,14 @@ export class Connection {
412
412
  _send = (data: object, forced: boolean = false) => {
413
413
  GizLog.log('GIZ_SDK: Socket send', data, forced);
414
414
  return new Promise<IWriteRes>((resolve) => {
415
- if (!forced && (!this._websocket || !this.ready)) {
415
+ if (!this._websocket) {
416
+ resolve({
417
+ success: false,
418
+ message: 'Socket not init'
419
+ })
420
+ return;
421
+ }
422
+ if (!forced && !this.ready) {
416
423
  resolve({
417
424
  success: false,
418
425
  message: 'Socket not ready'