mini_program_gizwits_sdk 3.2.30 → 3.2.32
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 +3 -3
- package/dist/src/handler/ble.d.ts +3 -10
- package/dist/src/sdk.d.ts +200 -0
- package/dist/src/wifiConfig/ConfigBase.d.ts +2 -1
- package/dist/src/wifiConfig/ble.d.ts +1 -1
- package/dist/src/wifiConfig/nfc/disposeData.d.ts +2 -0
- package/dist/src/wifiConfig/nfc/formatData.d.ts +3 -0
- package/dist/src/wifiConfig/nfc/formatSSID.d.ts +6 -0
- package/dist/src/wifiConfig/nfc/index.d.ts +22 -0
- package/dist/src/wifiConfig/nfc/isIncludedCH.d.ts +1 -0
- package/dist/src/wifiConfig/nfc/nfcAConnect.d.ts +6 -0
- package/dist/src/wifiConfig/nfc/nfcATransceive.d.ts +5 -0
- package/dist/src/wifiConfig/nfc/ssIDToASC.d.ts +1 -0
- package/dist/src/wifiConfig/nfc/stringToGbk.d.ts +1 -0
- package/dist/src/wifiConfig/nfc/transceive.wx.d.ts +2 -0
- package/dist/src/wifiConfig/nfc/types.d.ts +15 -0
- package/package.json +1 -1
- package/src/handler/ble.ts +24 -15
- package/src/sdk.ts +45 -4
- package/src/wifiConfig/ConfigBase.ts +3 -1
- package/src/wifiConfig/ble.ts +4 -4
- package/src/wifiConfig/nfc/disposeData.ts +63 -0
- package/src/wifiConfig/nfc/formatData.ts +46 -0
- package/src/wifiConfig/nfc/formatSSID.ts +59 -0
- package/src/wifiConfig/nfc/index.ts +136 -0
- package/src/wifiConfig/nfc/isIncludedCH.ts +8 -0
- package/src/wifiConfig/nfc/nfcAConnect.ts +30 -0
- package/src/wifiConfig/nfc/nfcATransceive.ts +29 -0
- package/src/wifiConfig/nfc/ssIDToASC.ts +12 -0
- package/src/wifiConfig/nfc/stringToGbk.ts +51 -0
- package/src/wifiConfig/nfc/transceive.wx.ts +124 -0
- package/src/wifiConfig/nfc/types.ts +18 -0
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
module.exports=function(e){var t={};function i(s){if(t[s])return t[s].exports;var n=t[s]={i:s,l:!1,exports:{}};return e[s].call(n.exports,n,n.exports,i),n.l=!0,n.exports}return i.m=e,i.c=t,i.d=function(e,t,s){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:s})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var s=Object.create(null);if(i.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)i.d(s,n,function(t){return e[t]}.bind(null,n));return s},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=18)}([function(e,t,i){(function(t){var s;e.exports=(s=s||function(e,s){var n;if("undefined"!=typeof window&&window.crypto&&(n=window.crypto),"undefined"!=typeof self&&self.crypto&&(n=self.crypto),"undefined"!=typeof globalThis&&globalThis.crypto&&(n=globalThis.crypto),!n&&"undefined"!=typeof window&&window.msCrypto&&(n=window.msCrypto),!n&&void 0!==t&&t.crypto&&(n=t.crypto),!n)try{n=i(36)}catch(e){}var r=function(){if(n){if("function"==typeof n.getRandomValues)try{return n.getRandomValues(new Uint32Array(1))[0]}catch(e){}if("function"==typeof n.randomBytes)try{return n.randomBytes(4).readInt32LE()}catch(e){}}throw new Error("Native crypto module could not be used to get secure random number.")},a=Object.create||function(){function e(){}return function(t){var i;return e.prototype=t,i=new e,e.prototype=null,i}}(),o={},c=o.lib={},l=c.Base={extend:function(e){var t=a(this);return e&&t.mixIn(e),t.hasOwnProperty("init")&&this.init!==t.init||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},d=c.WordArray=l.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||h).stringify(this)},concat:function(e){var t=this.words,i=e.words,s=this.sigBytes,n=e.sigBytes;if(this.clamp(),s%4)for(var r=0;r<n;r++){var a=i[r>>>2]>>>24-r%4*8&255;t[s+r>>>2]|=a<<24-(s+r)%4*8}else for(var o=0;o<n;o+=4)t[s+o>>>2]=i[o>>>2];return this.sigBytes+=n,this},clamp:function(){var t=this.words,i=this.sigBytes;t[i>>>2]&=4294967295<<32-i%4*8,t.length=e.ceil(i/4)},clone:function(){var e=l.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var t=[],i=0;i<e;i+=4)t.push(r());return new d.init(t,e)}}),u=o.enc={},h=u.Hex={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],n=0;n<i;n++){var r=t[n>>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,i=[],s=0;s<t;s+=2)i[s>>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new d.init(i,t/2)}},f=u.Latin1={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],n=0;n<i;n++){var r=t[n>>>2]>>>24-n%4*8&255;s.push(String.fromCharCode(r))}return s.join("")},parse:function(e){for(var t=e.length,i=[],s=0;s<t;s++)i[s>>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new d.init(i,t)}},p=u.Utf8={stringify:function(e){try{return decodeURIComponent(escape(f.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return f.parse(unescape(encodeURIComponent(e)))}},v=c.BufferedBlockAlgorithm=l.extend({reset:function(){this._data=new d.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=p.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var i,s=this._data,n=s.words,r=s.sigBytes,a=this.blockSize,o=r/(4*a),c=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,l=e.min(4*c,r);if(c){for(var u=0;u<c;u+=a)this._doProcessBlock(n,u);i=n.splice(0,c),s.sigBytes-=l}return new d.init(i,l)},clone:function(){var e=l.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0}),g=(c.Hasher=v.extend({cfg:l.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){v.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,i){return new e.init(i).finalize(t)}},_createHmacHelper:function(e){return function(t,i){return new g.HMAC.init(e,i).finalize(t)}}}),o.algo={});return o}(Math),s)}).call(this,i(35))},function(e,t,i){var s,n,r,a,o,c,l,d,u,h,f,p,v,g,y,_,D,m,b;e.exports=(s=i(0),i(6),void(s.lib.Cipher||(n=s,r=n.lib,a=r.Base,o=r.WordArray,c=r.BufferedBlockAlgorithm,l=n.enc,l.Utf8,d=l.Base64,u=n.algo.EvpKDF,h=r.Cipher=c.extend({cfg:a.extend(),createEncryptor:function(e,t){return this.create(this._ENC_XFORM_MODE,e,t)},createDecryptor:function(e,t){return this.create(this._DEC_XFORM_MODE,e,t)},init:function(e,t,i){this.cfg=this.cfg.extend(i),this._xformMode=e,this._key=t,this.reset()},reset:function(){c.reset.call(this),this._doReset()},process:function(e){return this._append(e),this._process()},finalize:function(e){return e&&this._append(e),this._doFinalize()},keySize:4,ivSize:4,_ENC_XFORM_MODE:1,_DEC_XFORM_MODE:2,_createHelper:function(){function e(e){return"string"==typeof e?b:D}return function(t){return{encrypt:function(i,s,n){return e(s).encrypt(t,i,s,n)},decrypt:function(i,s,n){return e(s).decrypt(t,i,s,n)}}}}()}),r.StreamCipher=h.extend({_doFinalize:function(){return this._process(!0)},blockSize:1}),f=n.mode={},p=r.BlockCipherMode=a.extend({createEncryptor:function(e,t){return this.Encryptor.create(e,t)},createDecryptor:function(e,t){return this.Decryptor.create(e,t)},init:function(e,t){this._cipher=e,this._iv=t}}),v=f.CBC=function(){var e=p.extend();function t(e,t,i){var s,n=this._iv;n?(s=n,this._iv=void 0):s=this._prevBlock;for(var r=0;r<i;r++)e[t+r]^=s[r]}return e.Encryptor=e.extend({processBlock:function(e,i){var s=this._cipher,n=s.blockSize;t.call(this,e,i,n),s.encryptBlock(e,i),this._prevBlock=e.slice(i,i+n)}}),e.Decryptor=e.extend({processBlock:function(e,i){var s=this._cipher,n=s.blockSize,r=e.slice(i,i+n);s.decryptBlock(e,i),t.call(this,e,i,n),this._prevBlock=r}}),e}(),g=(n.pad={}).Pkcs7={pad:function(e,t){for(var i=4*t,s=i-e.sigBytes%i,n=s<<24|s<<16|s<<8|s,r=[],a=0;a<s;a+=4)r.push(n);var c=o.create(r,s);e.concat(c)},unpad:function(e){var t=255&e.words[e.sigBytes-1>>>2];e.sigBytes-=t}},r.BlockCipher=h.extend({cfg:h.cfg.extend({mode:v,padding:g}),reset:function(){var e;h.reset.call(this);var t=this.cfg,i=t.iv,s=t.mode;this._xformMode==this._ENC_XFORM_MODE?e=s.createEncryptor:(e=s.createDecryptor,this._minBufferSize=1),this._mode&&this._mode.__creator==e?this._mode.init(this,i&&i.words):(this._mode=e.call(s,this,i&&i.words),this._mode.__creator=e)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e,t=this.cfg.padding;return this._xformMode==this._ENC_XFORM_MODE?(t.pad(this._data,this.blockSize),e=this._process(!0)):(e=this._process(!0),t.unpad(e)),e},blockSize:4}),y=r.CipherParams=a.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),_=(n.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext,i=e.salt;return(i?o.create([1398893684,1701076831]).concat(i).concat(t):t).toString(d)},parse:function(e){var t,i=d.parse(e),s=i.words;return 1398893684==s[0]&&1701076831==s[1]&&(t=o.create(s.slice(2,4)),s.splice(0,4),i.sigBytes-=16),y.create({ciphertext:i,salt:t})}},D=r.SerializableCipher=a.extend({cfg:a.extend({format:_}),encrypt:function(e,t,i,s){s=this.cfg.extend(s);var n=e.createEncryptor(i,s),r=n.finalize(t),a=n.cfg;return y.create({ciphertext:r,key:i,iv:a.iv,algorithm:e,mode:a.mode,padding:a.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,i,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(i,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}}),m=(n.kdf={}).OpenSSL={execute:function(e,t,i,s){s||(s=o.random(8));var n=u.create({keySize:t+i}).compute(e,s),r=o.create(n.words.slice(t),4*i);return n.sigBytes=4*t,y.create({key:n,iv:r,salt:s})}},b=r.PasswordBasedCipher=D.extend({cfg:D.cfg.extend({kdf:m}),encrypt:function(e,t,i,s){var n=(s=this.cfg.extend(s)).kdf.execute(i,e.keySize,e.ivSize);s.iv=n.iv;var r=D.encrypt.call(this,e,t,n.key,s);return r.mixIn(n),r},decrypt:function(e,t,i,s){s=this.cfg.extend(s),t=this._parse(t,s.format);var n=s.kdf.execute(i,e.keySize,e.ivSize,t.salt);return s.iv=n.iv,D.decrypt.call(this,e,t,n.key,s)}}))))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.arrayToUint8=t.formatCode=t.formatCodesFromStr=t.hexStrint2byte=t.string2Bytes=t.fillString=t.arrayToString=t.getProtocolLen=t.checkHeader=t.completeBlock=void 0;t.checkHeader=e=>{let t=0;return 0===e[0]&&0===e[1]&&0===e[2]&&3===e[3]&&(t=4,4)};t.completeBlock=e=>{const t=s(e,8*Math.ceil(e.length/8)),i=[];for(let e=0;e<t.length;e+=8)i.push(parseInt(t.substring(e,e+8),2));return i};t.getProtocolLen=e=>{let t=0;for(;t<e.length&&"1"===s(e[t].toString(2),8)[0];t++);return t+1},t.arrayToString=function(e){let t="";return e.map(e=>(t+=s(e.toString(16),2),null)),t};const s=(e,t,i=!1)=>{const s=t-e.length,n=new Array(s).fill(0).join("");return i?e+=n:e=n+e,e};t.fillString=s;t.string2Bytes=e=>{const t=[];for(let i=0;i<e.length;i++)t.push(e.charCodeAt(i));return t};t.hexStrint2byte=e=>{e.length%2!=0&&(e=`0${e}`);const t=Math.ceil(e.length/2),i=[];for(let s=0;s<t;s++){const t=2*s,n=t+2,r=e.substring(t,n);i.push(parseInt(r,16))}return i};const n=e=>{const t=encodeURI(e);return-1!==t.indexOf("%")&&"%"!==e?t.split("%").filter(e=>""!==e).map(e=>parseInt(e,16)):[t.charCodeAt(0)]};t.formatCode=n;t.formatCodesFromStr=e=>{const t=[0,0];let i=[];for(let s=0;s<e.length;s++){const r=n(e[s]);t[1]+=r.length,i=i.concat(r)}return[i,t]};t.arrayToUint8=e=>{const t=new ArrayBuffer(e.length),i=new Uint8Array(t);for(let s=0;s<t.byteLength;s++)i[s]=e[s];return i}},function(e,t,i){"use strict";var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const n=s(i(5)),r=s(i(34));t.default=new class{constructor(){this.logMap=[{id:"debug"},{id:"info"},{id:"warn"},{id:"error"}],this.console=console,this.debug=(...e)=>{this.console.debug(...e)},this.info=(...e)=>{this.console.info(...e)},this.log=(...e)=>{this.console.log(...e)},this.warn=(...e)=>{this.console.warn(...e)},this.error=(e,t)=>{this.console.error(e,t),(0,r.default)(t)},this.setLogLevel=e=>{const t=this.logMap.findIndex(t=>t.id===e);return-1!==t?(this.console=Object.assign({},console),this.logMap.map((e,i)=>{i<t&&(this.console[e.id]=()=>{})}),{success:!0,err:null}):{success:!1,err:n.default.GIZ_SDK_LOG_LEVEL_INVALID}}}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(2);class n{constructor(e){this.header="",this.len=0,this.flag=[0],this.cmd="",this.content=[],this.formatP0=e=>{let t=(0,s.checkHeader)(e);if(!1===t)throw new Error("Header Error");this.header=(0,s.arrayToString)(e.slice(0,t));const i=e.slice(t,e.length),r=(0,s.getProtocolLen)(i);this.len=n.decodeLen(i.slice(0,r)),t+=r,this.flag=e.slice(t,t+1),t+=1,this.cmd=(0,s.arrayToString)(e.slice(t,t+2)),t+=2,this.content=e.slice(t,e.length)},e&&e.length>0&&this.formatP0(e)}}n.decodeLen=e=>{let t=1,i=0,s=0,n=0;do{s=e[n],i+=(127&s)*t,t*=128,n+=1}while(0!=(128&s));return i},t.default=n},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default={GIZ_OPENAPI_DEVICE_NOT_BOUND:{errorCode:9017,errorMessage:"not bind"},GIZ_SDK_HTTP_REQUEST_FAILED:{errorCode:8099,errorMessage:"网络请求失败"},GIZ_SDK_SDK_NOT_INITIALIZED:{errorCode:8300,errorMessage:"not init"},CONFIG_TIME_OUT:{errorCode:8023,errorMessage:"Config Timeout"},WECHAT_ERROR:{errorCode:1e4,errorMessage:"wechat error"},GIZ_SDK_ONBOARDING_STOPPED:{errorCode:8318,errorMessage:"配网中断"},GIZ_SDK_DEVICE_CONFIG_IS_RUNNING:{errorCode:8022,errorMessage:"配置正在进行中"},GIZ_OPENAPI_TOKEN_INVALID:{errorCode:9004,errorMessage:"token 失效"},GIZ_SDK_BIND_DEVICE_FAILED:{errorCode:8039,errorMessage:"设备绑定失败"},GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON:{errorCode:8281,errorMessage:"蓝牙未启用"},GIZ_SDK_OTHERWISE:{errorCode:8100,errorMessage:""},GIZ_SDK_DEVICE_NOT_SUBSCRIBED:{errorCode:8029,errorMessage:"设备还未订阅"},GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY:{errorCode:8250,errorMessage:"产品类型不在指定范围内"},GIZ_SDK_LOG_LEVEL_INVALID:{errorCode:8009,errorMessage:"产品类型不在指定范围内"}}},function(e,t,i){var s,n,r,a,o,c,l,d;e.exports=(d=i(0),i(15),i(16),n=(s=d).lib,r=n.Base,a=n.WordArray,o=s.algo,c=o.MD5,l=o.EvpKDF=r.extend({cfg:r.extend({keySize:4,hasher:c,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var i,s=this.cfg,n=s.hasher.create(),r=a.create(),o=r.words,c=s.keySize,l=s.iterations;o.length<c;){i&&n.update(i),i=n.update(e).finalize(t),n.reset();for(var d=1;d<l;d++)i=n.finalize(i),n.reset();r.concat(i)}return r.sigBytes=4*c,r}}),s.EvpKDF=function(e,t,i){return l.create(i).compute(e,t)},d.EvpKDF)},function(e,t,i){var s,n,r;e.exports=(r=i(0),n=(s=r).lib.WordArray,s.enc.Base64={stringify:function(e){var t=e.words,i=e.sigBytes,s=this._map;e.clamp();for(var n=[],r=0;r<i;r+=3)for(var a=(t[r>>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;o<4&&r+.75*o<i;o++)n.push(s.charAt(a>>>6*(3-o)&63));var c=s.charAt(64);if(c)for(;n.length%4;)n.push(c);return n.join("")},parse:function(e){var t=e.length,i=this._map,s=this._reverseMap;if(!s){s=this._reverseMap=[];for(var r=0;r<i.length;r++)s[i.charCodeAt(r)]=r}var a=i.charAt(64);if(a){var o=e.indexOf(a);-1!==o&&(t=o)}return function(e,t,i){for(var s=[],r=0,a=0;a<t;a++)if(a%4){var o=i[e.charCodeAt(a-1)]<<a%4*2,c=i[e.charCodeAt(a)]>>>6-a%4*2,l=o|c;s[r>>>2]|=l<<24-r%4*8,r++}return n.create(s,r)}(e,t,s)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},r.enc.Base64)},function(e,t,i){var s;e.exports=(s=i(0),function(e){var t=s,i=t.lib,n=i.WordArray,r=i.Hasher,a=t.algo,o=[];!function(){for(var t=0;t<64;t++)o[t]=4294967296*e.abs(e.sin(t+1))|0}();var c=a.MD5=r.extend({_doReset:function(){this._hash=new n.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,t){for(var i=0;i<16;i++){var s=t+i,n=e[s];e[s]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8)}var r=this._hash.words,a=e[t+0],c=e[t+1],f=e[t+2],p=e[t+3],v=e[t+4],g=e[t+5],y=e[t+6],_=e[t+7],D=e[t+8],m=e[t+9],b=e[t+10],S=e[t+11],w=e[t+12],B=e[t+13],k=e[t+14],I=e[t+15],C=r[0],A=r[1],x=r[2],T=r[3];C=l(C,A,x,T,a,7,o[0]),T=l(T,C,A,x,c,12,o[1]),x=l(x,T,C,A,f,17,o[2]),A=l(A,x,T,C,p,22,o[3]),C=l(C,A,x,T,v,7,o[4]),T=l(T,C,A,x,g,12,o[5]),x=l(x,T,C,A,y,17,o[6]),A=l(A,x,T,C,_,22,o[7]),C=l(C,A,x,T,D,7,o[8]),T=l(T,C,A,x,m,12,o[9]),x=l(x,T,C,A,b,17,o[10]),A=l(A,x,T,C,S,22,o[11]),C=l(C,A,x,T,w,7,o[12]),T=l(T,C,A,x,B,12,o[13]),x=l(x,T,C,A,k,17,o[14]),C=d(C,A=l(A,x,T,C,I,22,o[15]),x,T,c,5,o[16]),T=d(T,C,A,x,y,9,o[17]),x=d(x,T,C,A,S,14,o[18]),A=d(A,x,T,C,a,20,o[19]),C=d(C,A,x,T,g,5,o[20]),T=d(T,C,A,x,b,9,o[21]),x=d(x,T,C,A,I,14,o[22]),A=d(A,x,T,C,v,20,o[23]),C=d(C,A,x,T,m,5,o[24]),T=d(T,C,A,x,k,9,o[25]),x=d(x,T,C,A,p,14,o[26]),A=d(A,x,T,C,D,20,o[27]),C=d(C,A,x,T,B,5,o[28]),T=d(T,C,A,x,f,9,o[29]),x=d(x,T,C,A,_,14,o[30]),C=u(C,A=d(A,x,T,C,w,20,o[31]),x,T,g,4,o[32]),T=u(T,C,A,x,D,11,o[33]),x=u(x,T,C,A,S,16,o[34]),A=u(A,x,T,C,k,23,o[35]),C=u(C,A,x,T,c,4,o[36]),T=u(T,C,A,x,v,11,o[37]),x=u(x,T,C,A,_,16,o[38]),A=u(A,x,T,C,b,23,o[39]),C=u(C,A,x,T,B,4,o[40]),T=u(T,C,A,x,a,11,o[41]),x=u(x,T,C,A,p,16,o[42]),A=u(A,x,T,C,y,23,o[43]),C=u(C,A,x,T,m,4,o[44]),T=u(T,C,A,x,w,11,o[45]),x=u(x,T,C,A,I,16,o[46]),C=h(C,A=u(A,x,T,C,f,23,o[47]),x,T,a,6,o[48]),T=h(T,C,A,x,_,10,o[49]),x=h(x,T,C,A,k,15,o[50]),A=h(A,x,T,C,g,21,o[51]),C=h(C,A,x,T,w,6,o[52]),T=h(T,C,A,x,p,10,o[53]),x=h(x,T,C,A,b,15,o[54]),A=h(A,x,T,C,c,21,o[55]),C=h(C,A,x,T,D,6,o[56]),T=h(T,C,A,x,I,10,o[57]),x=h(x,T,C,A,y,15,o[58]),A=h(A,x,T,C,B,21,o[59]),C=h(C,A,x,T,v,6,o[60]),T=h(T,C,A,x,S,10,o[61]),x=h(x,T,C,A,f,15,o[62]),A=h(A,x,T,C,m,21,o[63]),r[0]=r[0]+C|0,r[1]=r[1]+A|0,r[2]=r[2]+x|0,r[3]=r[3]+T|0},_doFinalize:function(){var t=this._data,i=t.words,s=8*this._nDataBytes,n=8*t.sigBytes;i[n>>>5]|=128<<24-n%32;var r=e.floor(s/4294967296),a=s;i[15+(n+64>>>9<<4)]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),i[14+(n+64>>>9<<4)]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),t.sigBytes=4*(i.length+1),this._process();for(var o=this._hash,c=o.words,l=0;l<4;l++){var d=c[l];c[l]=16711935&(d<<8|d>>>24)|4278255360&(d<<24|d>>>8)}return o},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});function l(e,t,i,s,n,r,a){var o=e+(t&i|~t&s)+n+a;return(o<<r|o>>>32-r)+t}function d(e,t,i,s,n,r,a){var o=e+(t&s|i&~s)+n+a;return(o<<r|o>>>32-r)+t}function u(e,t,i,s,n,r,a){var o=e+(t^i^s)+n+a;return(o<<r|o>>>32-r)+t}function h(e,t,i,s,n,r,a){var o=e+(i^(t|~s))+n+a;return(o<<r|o>>>32-r)+t}t.MD5=r._createHelper(c),t.HmacMD5=r._createHmacHelper(c)}(Math),s.MD5)},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{c(s.next(e))}catch(e){r(e)}}function o(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=n(i(5)),a=i(14),o=n(i(22));t.default=(e,t,i=!0)=>s(void 0,void 0,void 0,(function*(){const s=Object.assign({},t),n={"Content-Type":"application/json","X-Gizwits-Application-Id":(0,a.getGlobalData)("appID")};i&&(n["X-Gizwits-User-token"]=(0,a.getGlobalData)("token")),s.header=Object.assign(Object.assign({},n),t.headers),delete s.headers;const c=(0,a.getGlobalData)("cloudServiceInfo").openAPIInfo,l=yield(0,o.default)("https://"+c+e,s);if(l.statusCode>=200&&l.statusCode<300)return{success:!0,data:l.data};let d={success:!1,err:{errorCode:r.default.GIZ_SDK_HTTP_REQUEST_FAILED.errorCode,errorMessage:""}};try{d={success:!1,err:{errorCode:l.data.error_code,errorMessage:l.data.error_message}}}catch(e){}return d}))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=e=>new Promise(t=>setTimeout(()=>t(),e))},function(e,t,i){var s;e.exports=(s=i(0),i(13),i(37),i(38),i(7),i(39),i(8),i(15),i(20),i(40),i(21),i(41),i(42),i(43),i(16),i(44),i(6),i(1),i(45),i(46),i(47),i(48),i(49),i(50),i(51),i(52),i(53),i(54),i(55),i(56),i(57),i(58),i(59),i(60),s)},function(e,t,i){"use strict";var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.convertToUuids=t.convertToServiceUuids=t.encrypt=t.ab2numbers=t.parseBroadcastData=t.hex2ab=t.mergeObject=t.getProductInfoThroughPK=t.getFirstConnectType=t.BTDevice2GDevice=t.merageLanLocalDevices=t.merageBleLocalDevices=t.isSameDevice=t.advertisData2PkAndMac=t.numberArray2Uint8Array=t.str2Buf=t.isWXDevicesResult=t.unionBy=t.wrapErrorInfo=t.isError=t.compareWXSDKVersion=t.ab2hex=void 0;const n=s(i(3));function r(e){return Array.prototype.map.call(new Uint8Array(e),(function(e){return("00"+e.toString(16)).slice(-2)})).join("")}t.ab2hex=r,t.compareWXSDKVersion=function(e,t){const i=e.split("."),s=t.split("."),n=Math.max(e.length,t.length);for(;i.length<n;)i.push("0");for(;s.length<n;)s.push("0");for(let i=0;i<n;i++){const s=parseInt(e[i]),n=parseInt(t[i]);if(s>n)return 1;if(s<n)return-1}return 0};t.isError=e=>null!=e&&"symbol"==typeof e.errorCode;t.wrapErrorInfo=e=>({errorCode:e,errorMessage:e});t.unionBy=(e,t)=>e.reduce((e,i)=>{const s=i[t];return e.some(e=>e[t]===s)||e.push(i),e},[]),t.isWXDevicesResult=function(e){return e.success&&"[object Array]"===Object.prototype.toString.call(e.bleDevices)},t.str2Buf=function(e){var t=e.length,i=new ArrayBuffer(t+2),s=new DataView(i);for(let i=0;i<t;i++)s.setUint8(i,parseInt(e[i],16));return i};t.numberArray2Uint8Array=e=>{const t=new ArrayBuffer(e.length),i=new Uint8Array(t);for(let s=0;s<t.byteLength;s++)i[s]=e[s];return i};t.advertisData2PkAndMac=(e,t)=>e&&e.byteLength>=22&&e.byteLength<=24?Object.assign(Object.assign({},((e,t)=>{let i=e.slice(e.byteLength-16),s=e.slice(0,e.byteLength-16),n=r(i);if(t.find(e=>e===n)){const e=r(s);return{productKey:n,mac:e}}{i=e.slice(0,16),s=e.slice(16),n=r(i);const t=r(s);return{productKey:n,mac:t}}})(e,t)),{bleWorkStatus:1}):e&&e.byteLength>24?((e,t)=>{if(!e||0===e.byteLength)return{bleWorkStatus:0,mac:"",productKey:""};let i=0,s="",n="",a=1;const o=new Uint8Array(e);for(;!(i>e.byteLength-1);){const c=o[i];if(c<=0||!c)break;if(e.byteLength<c+i+1)break;const l=e.slice(i+1,i+c+1);if(c>=6&&c<=8&&(s=r(l),16==s.length&&(s=s.substring(0,15))),16==c){const e=r(l).toLowerCase();t.find(t=>t===e)&&(n=e)}1==c&&(a=new Uint8Array(l)[0]),i+=1+c}return{bleWorkStatus:a,mac:s,productKey:n}})(e,t):{mac:"",productKey:"",bleWorkStatus:1};t.isSameDevice=(e,t)=>e.mac===t.mac&&e.productKey===t.productKey;t.merageBleLocalDevices=(e,i)=>(e.map(e=>{e.isBleOnline=!1,e.bleWorkStatus=0}),i.map(i=>{const s=e.find(e=>(0,t.isSameDevice)(e,i));s?(s.isBleOnline=!0,s.bleDeviceID=i.bleDeviceID,s.connectType=i.connectType,s.bleWorkStatus=i.bleWorkStatus):e.push(i)}),e);t.merageLanLocalDevices=(e,i)=>(e.map(e=>{e.isLanOnline=!1}),i.map(i=>{const s=e.find(e=>(0,t.isSameDevice)(e,i));s?s.isLanOnline=!0:e.push(i)}),e);t.BTDevice2GDevice=(e,i)=>{let s={productKey:"",mac:"",bleWorkStatus:0},r={did:"",productKey:"",mac:"",bleWorkStatus:0,connectType:"NONE",isBleOnline:!0,isLanOnline:!1,isOnline:!1,name:e.name,isBind:!1,bleDeviceID:e.deviceId,ctime:(new Date).getTime()};switch(e.communicationType){case"BLE_BROADCAST":try{n.default.log("parse BLE_BROADCAST");const t=a(o(e.advertisData));s.productKey=t.data.join(""),s.mac=t.mac,r.connectType="BLE_BROADCAST"}catch(e){}break;default:s=(0,t.advertisData2PkAndMac)(e.advertisData,i)}return r=Object.assign(Object.assign({},r),s),r};t.getFirstConnectType=(e,t)=>{if(!t)return e.isLanOnline?"LAN":e.isBleOnline?"BLE":"WAN";if("WAN"===t)return"WAN";switch(t){case"BLE":return e.isBleOnline?"BLE":"NONE";case"LAN":return e.isLanOnline?"LAN":"NONE"}return"WAN"};t.getProductInfoThroughPK=(e,t)=>t.find(t=>t.productKey===e);function a(e){if(25!=(e=e.slice(0,25)).length)throw new Error("数据不合法");const t=`${c(e[0])}${c(e[1])}`;if(e[2]!==(255&e.slice(3).reduce((e,t)=>e+t,0)))throw new Error("校验和不合法");const i=c(e[3]),s=e.slice(5,5+e[4]).map(e=>c(e));return{mac:t,cmd:parseInt(i,16),data:s}}function o(e){return Array.prototype.map.call(new Uint8Array(e),(function(e){return e}))}function c(e,t=2){return`${new Array(t).fill(0).join("")}${e.toString(16)}`.slice(-t)}t.mergeObject=(e,t)=>{for(let i in t)null!=t[i]&&""!==t[i]&&(e[i]=t[i]);return e},t.hex2ab=function(e){const t=[];for(let s=0;s<e.length;s+=2){var i=e.slice(s,s+2);t.push(parseInt(i,16))}return new Uint8Array(t)},t.parseBroadcastData=a,t.ab2numbers=o;let l=0;function d(e,t){let i=1,s=t;return e.map(e=>{const t=65535&(e^s);return s=i-t&65535,i<<=1,c(t,4)})}t.encrypt=d;function u(e,t,i){if(i.length>22)throw new Error("最大长度为22");const s=[...i,...new Array(22-i.length).fill(0)],r=255&i.reduce((e,t)=>e+t,0),a=(t>>4<<12)+(r>>4<<8)+((15&t)<<4)+(15&r),o=Array.from({length:11},(e,t)=>(s[2*t]<<8)+s[2*t+1]);return n.default.log("明文",c(e,4),c((t<<8)+r,4),o.map(e=>c(e,4))),[c(e,4),c((t<<8)+r,4),...d(o,a)].map(e=>`${e.slice(2)}${e.slice(0,2)}`)}t.convertToServiceUuids=({len:e=null,data:i=null,index:s=0,mac:n})=>{const r=null==e?Math.round(18*Math.random())+1:e,a=null==i?Array.from({length:r},e=>Math.round(255*Math.random())):i,o=[147,r,...a],c=u(n,(()=>{const e=l;return l=l+1&255,e})(),o);return[...new Set(c)].length!==c.length?(0,t.convertToServiceUuids)({len:r,data:a,index:s++,mac:n}):c},t.convertToUuids=u},function(e,t,i){var s,n,r,a,o,c;e.exports=(c=i(0),n=(s=c).lib,r=n.Base,a=n.WordArray,(o=s.x64={}).Word=r.extend({init:function(e,t){this.high=e,this.low=t}}),o.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:8*e.length},toX32:function(){for(var e=this.words,t=e.length,i=[],s=0;s<t;s++){var n=e[s];i.push(n.high),i.push(n.low)}return a.create(i,this.sigBytes)},clone:function(){for(var e=r.clone.call(this),t=e.words=this.words.slice(0),i=t.length,s=0;s<i;s++)t[s]=t[s].clone();return e}}),c)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getGlobalData=t.setGlobalData=void 0;const s={};t.setGlobalData=function(e,t){s[e]=t},t.getGlobalData=function(e){return s[e]}},function(e,t,i){var s,n,r,a,o,c,l,d;e.exports=(d=i(0),n=(s=d).lib,r=n.WordArray,a=n.Hasher,o=s.algo,c=[],l=o.SHA1=a.extend({_doReset:function(){this._hash=new r.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(e,t){for(var i=this._hash.words,s=i[0],n=i[1],r=i[2],a=i[3],o=i[4],l=0;l<80;l++){if(l<16)c[l]=0|e[t+l];else{var d=c[l-3]^c[l-8]^c[l-14]^c[l-16];c[l]=d<<1|d>>>31}var u=(s<<5|s>>>27)+o+c[l];u+=l<20?1518500249+(n&r|~n&a):l<40?1859775393+(n^r^a):l<60?(n&r|n&a|r&a)-1894007588:(n^r^a)-899497514,o=a,a=r,r=n<<30|n>>>2,n=s,s=u}i[0]=i[0]+s|0,i[1]=i[1]+n|0,i[2]=i[2]+r|0,i[3]=i[3]+a|0,i[4]=i[4]+o|0},_doFinalize:function(){var e=this._data,t=e.words,i=8*this._nDataBytes,s=8*e.sigBytes;return t[s>>>5]|=128<<24-s%32,t[14+(s+64>>>9<<4)]=Math.floor(i/4294967296),t[15+(s+64>>>9<<4)]=i,e.sigBytes=4*t.length,this._process(),this._hash},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),s.SHA1=a._createHelper(l),s.HmacSHA1=a._createHmacHelper(l),d.SHA1)},function(e,t,i){var s,n,r,a;e.exports=(s=i(0),r=(n=s).lib.Base,a=n.enc.Utf8,void(n.algo.HMAC=r.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=a.parse(t));var i=e.blockSize,s=4*i;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var n=this._oKey=t.clone(),r=this._iKey=t.clone(),o=n.words,c=r.words,l=0;l<i;l++)o[l]^=1549556828,c[l]^=909522486;n.sigBytes=r.sigBytes=s,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher,i=t.finalize(e);return t.reset(),t.finalize(this._oKey.clone().concat(i))}})))},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{c(s.next(e))}catch(e){r(e)}}function o(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=n(i(9));const a=new class{constructor(){this.data={},this.key="dataPointConfig",this.init=()=>s(this,void 0,void 0,(function*(){const e=(yield wx.getStorageSync(this.key))||"{}";let t={};try{t=JSON.parse(e)}catch(e){}this.data=t})),this.getConfigFile=e=>s(this,void 0,void 0,(function*(){var t;if(!this.data[e]){const i=`/app/datapoint?product_key=${e}`,s=yield(0,r.default)(`${i}`,{method:"GET"});if(!s.success||!(null===(t=s.data)||void 0===t?void 0:t.entities))return null;this.data[e]=s.data,wx.setStorageSync(this.key,JSON.stringify(this.data))}return this.data[e]})),this.getAttrItem=(e,t)=>s(this,void 0,void 0,(function*(){this.data[e]||(yield this.getConfigFile(e));for(let i in this.data[e].entities[0].attrs){const s=this.data[e].entities[0].attrs[i];if(s.name===t)return s}return null}))}};a.init(),t.default=a},function(e,t,i){"use strict";var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.BleHandle=t.errorCode=void 0,i(32);const n=s(i(33)),r=s(i(5));t.errorCode=r.default;const a=i(19);Object.defineProperty(t,"BleHandle",{enumerable:!0,get:function(){return a.BleHandle}}),t.default=n.default},function(e,t,i){"use strict";var s=this&&this.__decorate||function(e,t,i,s){var n,r=arguments.length,a=r<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,s);else for(var o=e.length-1;o>=0;o--)(n=e[o])&&(a=(r<3?n(a):r>3?n(t,i,a):n(t,i))||a);return r>3&&a&&Object.defineProperty(t,i,a),a},n=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{c(s.next(e))}catch(e){r(e)}}function o(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((s=s.apply(e,t||[])).next())}))},r=this&&this.__rest||function(e,t){var i={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(i[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(e);n<s.length;n++)t.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(e,s[n])&&(i[s[n]]=e[s[n]])}return i},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.BleHandle=void 0;const o=a(i(3)),c=a(i(23)),l=i(24),d=a(i(61)),u=a(i(25)),h=a(i(4)),f=i(2),p=i(62),v=a(i(10)),g=i(12),y=i(27),_=a(i(28));function D(e){return function(t,i,s){const{value:n}=s;s.value=function(...t){return n.apply(this,t).then(i=>{var{_failureType_:s}=i,n=r(i,["_failureType_"]);return(0,p.reportEvent)({device:t[0],eventID:this.__event_id__,eventType:e,success:n.success}),Object.assign(Object.assign({},n),{_failureType_:e})})}}}class m extends _.default{set offlineThreshold(e){this._offlineThreshold=e}get offlineThreshold(){return this._offlineThreshold||1e4}constructor({pks:e=[],bleHandleParams:t={serviceUUIDSuffix:"abf0",characteristicUUIDSuffix:"abf7"},offlineThreshold:i}){super(),this.connectedList=[],this.connectingDevId=null,this.pks=[],this.listenDevOfflineTimer=null,this.boradcastDataCache={},this.baseServices=["ABF8","ABF0","F0AB","F8AB"],this.tmpBleData="",this.tmpDataNum=0,this.disableScanFlag=!1,this.peripheralServer=null,this.isActive=!0,this._offlineThreshold=null,this.scanList=[],this.onBluetoothAdapterStateChange=e=>{o.default.debug("onBluetoothAdapterStateChange",e),e.available||(this.scanList=[],this.notifyDevices())},this.onAppShow=()=>{this.isActive=!0,this.scanList.map(e=>{e.ctime=Date.now()})},this.onAppHide=()=>{this.isActive=!1},this.listenDevOffline=()=>{this.listenDevOfflineTimer=setInterval(()=>{if(!this.isActive)return;const e=(new Date).getTime(),t=this.scanList.filter(t=>{const i=this.connectedList.find(e=>t.bleDeviceID==e.deviceId),s=this.connectingDevId===t.bleDeviceID;return!(!i&&!s)||("BLE_BROADCAST"===t.connectType?e-t.ctime<2*this.offlineThreshold:e-t.ctime<this.offlineThreshold)});t.length!==this.scanList.length&&(this.scanList=t,this.notifyDevices())},500)},this.openBluetoothAdapter=(e="central")=>new Promise((t,i)=>{wx.openBluetoothAdapter({mode:e,success:()=>{t({success:!0}),wx.onBLECharacteristicValueChange(this.handleOnBLECharacteristicValueChange)},fail:e=>{o.default.error("openBluetoothAdapter fail",new Error(JSON.stringify(e))),this.notifyError({errMsg:e.errMsg,errCode:-1}),i({success:!1,err:e})}})}),this.handleOnBLECharacteristicValueChange=e=>n(this,void 0,void 0,(function*(){if(!e.value)return;const t=(0,g.ab2hex)(e.value);try{const i=new h.default((0,f.hexStrint2byte)(t));this.tmpBleData=t,this.tmpDataNum=i.len-e.value.byteLength+4+Math.ceil(i.len.toString(2).length/8)}catch(i){this.tmpBleData&&(this.tmpBleData+=t,this.tmpDataNum-=e.value.byteLength)}this.tmpDataNum>0||!this.tmpBleData||(this.notiDeviceDataToSdk(e,this.tmpBleData),this.tmpBleData="",this.tmpDataNum=0)})),this.notiDeviceDataToSdk=(e,t)=>{this.listenerMap.GizBleDeviceData&&this.listenerMap.GizBleDeviceData.map(i=>{i(e,t)})},this.notifyError=e=>{this.listenerMap.GizBleError&&this.listenerMap.GizBleError.map(t=>{t(e)})},this.notifyDevices=()=>{this.listenerMap.GizBleDeviceList&&this.listenerMap.GizBleDeviceList.map(e=>{e(this.scanList)})},this.listenConnection=()=>{wx.onBLEConnectionStateChange(e=>{if(!1===e.connected){const t=this.connectedList.findIndex(t=>t.deviceId===e.deviceId);-1!==t&&(this.connectedList.splice(t,1),this.notifyDevices())}})},this.init=()=>n(this,void 0,void 0,(function*(){const{platform:e}=wx.getSystemInfoSync();yield this.openBluetoothAdapter(),"ios"===e&&(yield this.openBluetoothAdapter("peripheral"));try{this.peripheralServer=(yield wx.createBLEPeripheralServer()).server,o.default.info("GIZ_SDK: 广播初始化成功",this.peripheralServer)}catch(e){o.default.error("GIZ_SDK: 广播初始化失败",new Error(JSON.stringify(e)))}return yield this.getBluetoothAdapterState()})),this.checkPermission=()=>n(this,void 0,void 0,(function*(){if((yield wx.getSetting()).authSetting["scope.bluetooth"])return yield this.init();try{return yield wx.authorize({scope:"scope.bluetooth"}),yield this.init()}catch(e){o.default.log("授权失败",e),this.openBluetoothAdapter(),this.notifyError({errMsg:e.errMsg,errCode:-1})}})),this.getBluetoothAdapterState=()=>n(this,void 0,void 0,(function*(){o.default.log("getBluetoothAdapterState",yield wx.getBluetoothAdapterState());const e=yield wx.getBluetoothAdapterState(),{errMsg:t,available:i}=e,s=r(e,["errMsg","available"]);return{data:Object.assign({},s),err:(0,g.wrapErrorInfo)(t),success:i}})),this.getDeviceStatus=(e,t,i,s)=>n(this,void 0,void 0,(function*(){const n=yield d.default.pack(t,i,s);return n?yield this.write(e,(0,g.numberArray2Uint8Array)(n).buffer):{success:!1}})),this.updateDevice=e=>{const t=e.bleDeviceID,i=this.scanList.findIndex(e=>t==e.bleDeviceID);-1!==i&&(this.scanList[i]=e)},this.updateCtime=e=>{const t=e.deviceId,i=this.scanList.findIndex(e=>t==e.bleDeviceID);-1!==i&&(this.scanList[i].ctime=Date.now())},this.checkDeviceIsChange=(e,t)=>e.bleWorkStatus!==t.bleWorkStatus||e.name!==t.name||e.isBleOnline!==t.isBleOnline||e.isOnline!==t.isOnline,this.handleBluetoothDeviceFound=(e,t)=>{(0,g.unionBy)(e.devices,"deviceId").map(e=>{const{advertisData:i,deviceId:s,name:n,localName:r}=e,a=(0,g.ab2hex)(i);let o=null;try{o=(0,g.parseBroadcastData)((0,g.ab2numbers)(i))}catch(e){}const c=this.scanList.find(e=>e.bleDeviceID===s);if(o&&148===o.cmd){const t=(0,g.ab2hex)(i);if(this.boradcastDataCache[s]&&this.boradcastDataCache[s]===t)return!1;if(!c)return!1;this.boradcastDataCache[s]=(0,g.ab2hex)(i);const n=(0,l.padBoradcastData)(o.data.map(e=>parseInt(e,16)));return this.updateCtime(e),void this.notiDeviceDataToSdk(e,n)}if(o&&25===o.cmd){this.pks.find(e=>e===o.data.join(""))&&(e.communicationType="BLE_BROADCAST")}if(c){const i=(0,g.BTDevice2GDevice)(e,this.pks);if(i.productKey&&i.mac){const e=this.checkDeviceIsChange(i,c);i.ctime=Date.now(),this.updateDevice(i),e&&t(this.scanList)}}else{if(this.pks.some(e=>a.includes(e))){const i=(0,g.BTDevice2GDevice)(e,this.pks);i.productKey&&i.mac&&(this.scanList.push(i),t(this.scanList))}}})},this.startScan=(e,t=5e3,i)=>n(this,void 0,void 0,(function*(){return this.disableScanFlag?{scanList:[]}:new Promise(s=>n(this,void 0,void 0,(function*(){wx.onBluetoothDeviceFound(t=>{this.handleBluetoothDeviceFound(t,e)}),o.default.debug("GIZ_SDK: start scan",t),yield wx.startBluetoothDevicesDiscovery({services:i||this.baseServices,powerLevel:"high",allowDuplicatesKey:!0,interval:200}),t>0&&setTimeout(()=>{this.stopScan(),s({scanList:this.scanList})},t)})))})),this.stopScan=()=>n(this,void 0,void 0,(function*(){try{return yield wx.stopBluetoothDevicesDiscovery()}catch(e){return e}})),this.disableScan=()=>n(this,void 0,void 0,(function*(){this.disableScanFlag=!0;const e=yield wx.stopBluetoothDevicesDiscovery();return yield(0,v.default)(200),e})),this.enableScan=()=>{this.disableScanFlag=!1},this.connectDevice=e=>n(this,void 0,void 0,(function*(){try{return this.connectingDevId=e.bleDeviceID,this._connectDevice(e)}finally{this.connectingDevId=null}})),this.handleBindReq=e=>new Promise(t=>{const i=(s,n)=>{if(s.deviceId!==e)return;o.default.log("监听蓝牙特征值发生变化");const r=new c.default((0,f.hexStrint2byte)(n));this.removeEventListener("GizBleDeviceData",i),r.passcode?t({success:!0,data:r.passcode}):t({success:!1,data:""})};this.watchBleDevice(e,i)}),this.handleLoginReq=e=>new Promise(t=>{const i=(s,n)=>{if(s.deviceId!==e)return;o.default.log("设备回复LoginReq",n);const r=new u.default((0,f.hexStrint2byte)(n));this.removeEventListener("GizBleDeviceData",i),!0===r.result?t({success:!0,data:r.did}):t({success:!1,data:""})};this.watchBleDevice(e,i)}),this.watchBleDevice=(e,t)=>n(this,void 0,void 0,(function*(){const{serviceId:i,characteristicId:s,errMsg:n}=this.getTargetDevice(e);return n?{success:!1,message:n}:(yield wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:i,characteristicId:s,state:!0,type:"notification"}).catch(e=>this.notifyError(e)),o.default.log(`监听设备 ${e} 成功!`),this.addEventListener("GizBleDeviceData",t),{message:"ok",success:!0})})),this.writeBoradcast=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.scanList.find(t=>t.bleDeviceID===e);if(!i)return{success:!1,message:"not found device"};this.boradcastTimer&&clearTimeout(this.boradcastTimer);try{this.peripheralServer.stopAdvertising({});const e=(0,g.convertToServiceUuids)({mac:i.mac,index:0,data:t,len:t.length});return this.peripheralServer.startAdvertising({advertiseRequest:{connectable:!0,serviceUuids:e},powerLevel:"high",success:e=>{o.default.debug("GIZ_SDK: startAdvertising success",e)},fail:e=>{o.default.error("GIZ_SDK: startAdvertising error",new Error(JSON.stringify(e)))}}),o.default.debug("GIZ_SDK: start adv",e),this.boradcastTimer=setTimeout(()=>{this.peripheralServer.stopAdvertising({}),this.boradcastTimer=null},1e3),{success:!0}}catch(e){return o.default.log("GIZ_SDK:",e),clearTimeout(this.boradcastTimer),{success:!1,message:"send cmd error"}}})),this.write=(e,t)=>n(this,void 0,void 0,(function*(){o.default.log("app => dev:",(0,g.ab2hex)(t));const i=this.getTargetDevice(e);if(i.serviceId&&i.characteristicId){return yield(0,y.unpackWriteBLECharacteristicValue)(e,i.serviceId,i.characteristicId,t)}return{success:!1,message:"send cmd error"}})),this.disConnectDevice=e=>n(this,void 0,void 0,(function*(){this.removeDevById(e);const{errMsg:t}=yield wx.closeBLEConnection({deviceId:e}),i=this.scanList.find(t=>t.bleDeviceID===e);return i&&(i.ctime=Date.now(),this.updateDevice(i)),"closeBLEConnection:ok"===t?{err:t,success:!0}:{err:t,success:!1}})),this.removeDevById=e=>{const t=this.connectedList.findIndex(t=>t.deviceId===e);-1!==t&&this.connectedList.splice(t,1)},this.getTargetDevice=e=>{const t=this.connectedList.find(t=>e===t.deviceId);return t||{errMsg:"Unable get this device,maybe you forgot to connect it."}},this.destory=()=>{this.listenDevOfflineTimer&&clearInterval(this.listenDevOfflineTimer),wx.offAppShow(this.onAppShow),wx.offAppHide(this.onAppHide),wx.offBluetoothAdapterStateChange(this.onBluetoothAdapterStateChange)};const{serviceUUIDSuffix:s}=t;this.serviceUUIDSuffix=s,this.pks=e,this.offlineThreshold=i,this.listenDevOffline(),this.listenConnection(),wx.onAppShow(this.onAppShow),wx.onAppHide(this.onAppHide),wx.onBluetoothAdapterStateChange(this.onBluetoothAdapterStateChange)}connectDeviceBle(e){var t;return n(this,void 0,void 0,(function*(){try{yield this.disableScan();const t=yield(0,y.retryConnect)(e.bleDeviceID);this.enableScan(),o.default.debug("connect res",t)}catch(e){if(o.default.error("GIZ_SDK: createBLEConnection error",new Error(JSON.stringify(e))),"createBLEConnection:fail:already connect"!==(null==e?void 0:e.errMsg))return this.notifyError(e),{success:!1,message:null==e?void 0:e.errMsg}}const i=yield wx.getBLEDeviceServices({deviceId:e.bleDeviceID}).catch(e=>this.notifyError(e)),s=null===(t=null==i?void 0:i.services.find(e=>e.isPrimary&&e.uuid.toLowerCase().includes(this.serviceUUIDSuffix)))||void 0===t?void 0:t.uuid;if(!s)return{message:"can not find valid serviceId",success:!1};const n=yield wx.getBLEDeviceCharacteristics({deviceId:e.bleDeviceID,serviceId:s}).catch(e=>this.notifyError(e));return{success:!0,data:{serviceId:s,characteristicId:null==n?void 0:n.characteristics[0].uuid}}}))}connectDeviceBindRequest(e){return n(this,void 0,void 0,(function*(){this.write(e.bleDeviceID,(0,g.numberArray2Uint8Array)(c.default.pack()).buffer);const t=yield this.handleBindReq(e.bleDeviceID);return o.default.log("handleBindReq",t),t.success||(yield wx.closeBLEConnection({deviceId:e.bleDeviceID})),t}))}connectDeviceLoginRequest(e,t){return n(this,void 0,void 0,(function*(){this.write(e.bleDeviceID,(0,g.numberArray2Uint8Array)(u.default.pack({passcode:t})).buffer);const i=yield this.handleLoginReq(e.bleDeviceID).catch(e=>this.notifyError(e));return{success:!!(null==i?void 0:i.success),message:"ok"}}))}_connectDevice(e){return n(this,void 0,void 0,(function*(){const t=yield this.connectDeviceBle(e);if(!t.success)return t;const{serviceId:i,characteristicId:s}=t.data;this.connectedList.every(t=>t.deviceId!==e.bleDeviceID)&&this.connectedList.push({deviceId:e.bleDeviceID,serviceId:i,characteristicId:s}),yield wx.notifyBLECharacteristicValueChange({deviceId:e.bleDeviceID,serviceId:i,characteristicId:s,state:!0,type:"notification"}).catch(e=>this.notifyError(e));const n=yield this.connectDeviceBindRequest(e);return n.success?yield this.connectDeviceLoginRequest(e,n.data):n}))}}s([D("BleDeviceConnectEnd")],m.prototype,"connectDeviceBle",null),s([D("BleDeviceConnectBind")],m.prototype,"connectDeviceBindRequest",null),s([D("BleDeviceConnectLogin")],m.prototype,"connectDeviceLoginRequest",null),s([function(e,t,i){const{value:s}=i;i.value=function(...e){const t=Object.create(this);return t.__event_id__=function(){let e=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){let i=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?i:3&i|8).toString(16)}))}(),(0,p.reportEvent)({device:e[0],eventID:t.__event_id__,eventType:"BleDeviceConnectStart",success:!0}),s.apply(t,e).then(i=>{var{_failureType_:s}=i,n=r(i,["_failureType_"]);return(0,p.reportEvent)(Object.assign({device:e[0],eventID:t.__event_id__,eventType:"BleDeviceConnectFinish",success:n.success},n.success?{}:{failureType:s})),n})}}],m.prototype,"_connectDevice",null),t.BleHandle=m},function(e,t,i){var s;e.exports=(s=i(0),function(e){var t=s,i=t.lib,n=i.WordArray,r=i.Hasher,a=t.algo,o=[],c=[];!function(){function t(t){for(var i=e.sqrt(t),s=2;s<=i;s++)if(!(t%s))return!1;return!0}function i(e){return 4294967296*(e-(0|e))|0}for(var s=2,n=0;n<64;)t(s)&&(n<8&&(o[n]=i(e.pow(s,.5))),c[n]=i(e.pow(s,1/3)),n++),s++}();var l=[],d=a.SHA256=r.extend({_doReset:function(){this._hash=new n.init(o.slice(0))},_doProcessBlock:function(e,t){for(var i=this._hash.words,s=i[0],n=i[1],r=i[2],a=i[3],o=i[4],d=i[5],u=i[6],h=i[7],f=0;f<64;f++){if(f<16)l[f]=0|e[t+f];else{var p=l[f-15],v=(p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3,g=l[f-2],y=(g<<15|g>>>17)^(g<<13|g>>>19)^g>>>10;l[f]=v+l[f-7]+y+l[f-16]}var _=s&n^s&r^n&r,D=(s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22),m=h+((o<<26|o>>>6)^(o<<21|o>>>11)^(o<<7|o>>>25))+(o&d^~o&u)+c[f]+l[f];h=u,u=d,d=o,o=a+m|0,a=r,r=n,n=s,s=m+(D+_)|0}i[0]=i[0]+s|0,i[1]=i[1]+n|0,i[2]=i[2]+r|0,i[3]=i[3]+a|0,i[4]=i[4]+o|0,i[5]=i[5]+d|0,i[6]=i[6]+u|0,i[7]=i[7]+h|0},_doFinalize:function(){var t=this._data,i=t.words,s=8*this._nDataBytes,n=8*t.sigBytes;return i[n>>>5]|=128<<24-n%32,i[14+(n+64>>>9<<4)]=e.floor(s/4294967296),i[15+(n+64>>>9<<4)]=s,t.sigBytes=4*i.length,this._process(),this._hash},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=r._createHelper(d),t.HmacSHA256=r._createHmacHelper(d)}(Math),s.SHA256)},function(e,t,i){var s;e.exports=(s=i(0),i(13),function(){var e=s,t=e.lib.Hasher,i=e.x64,n=i.Word,r=i.WordArray,a=e.algo;function o(){return n.create.apply(n,arguments)}var c=[o(1116352408,3609767458),o(1899447441,602891725),o(3049323471,3964484399),o(3921009573,2173295548),o(961987163,4081628472),o(1508970993,3053834265),o(2453635748,2937671579),o(2870763221,3664609560),o(3624381080,2734883394),o(310598401,1164996542),o(607225278,1323610764),o(1426881987,3590304994),o(1925078388,4068182383),o(2162078206,991336113),o(2614888103,633803317),o(3248222580,3479774868),o(3835390401,2666613458),o(4022224774,944711139),o(264347078,2341262773),o(604807628,2007800933),o(770255983,1495990901),o(1249150122,1856431235),o(1555081692,3175218132),o(1996064986,2198950837),o(2554220882,3999719339),o(2821834349,766784016),o(2952996808,2566594879),o(3210313671,3203337956),o(3336571891,1034457026),o(3584528711,2466948901),o(113926993,3758326383),o(338241895,168717936),o(666307205,1188179964),o(773529912,1546045734),o(1294757372,1522805485),o(1396182291,2643833823),o(1695183700,2343527390),o(1986661051,1014477480),o(2177026350,1206759142),o(2456956037,344077627),o(2730485921,1290863460),o(2820302411,3158454273),o(3259730800,3505952657),o(3345764771,106217008),o(3516065817,3606008344),o(3600352804,1432725776),o(4094571909,1467031594),o(275423344,851169720),o(430227734,3100823752),o(506948616,1363258195),o(659060556,3750685593),o(883997877,3785050280),o(958139571,3318307427),o(1322822218,3812723403),o(1537002063,2003034995),o(1747873779,3602036899),o(1955562222,1575990012),o(2024104815,1125592928),o(2227730452,2716904306),o(2361852424,442776044),o(2428436474,593698344),o(2756734187,3733110249),o(3204031479,2999351573),o(3329325298,3815920427),o(3391569614,3928383900),o(3515267271,566280711),o(3940187606,3454069534),o(4118630271,4000239992),o(116418474,1914138554),o(174292421,2731055270),o(289380356,3203993006),o(460393269,320620315),o(685471733,587496836),o(852142971,1086792851),o(1017036298,365543100),o(1126000580,2618297676),o(1288033470,3409855158),o(1501505948,4234509866),o(1607167915,987167468),o(1816402316,1246189591)],l=[];!function(){for(var e=0;e<80;e++)l[e]=o()}();var d=a.SHA512=t.extend({_doReset:function(){this._hash=new r.init([new n.init(1779033703,4089235720),new n.init(3144134277,2227873595),new n.init(1013904242,4271175723),new n.init(2773480762,1595750129),new n.init(1359893119,2917565137),new n.init(2600822924,725511199),new n.init(528734635,4215389547),new n.init(1541459225,327033209)])},_doProcessBlock:function(e,t){for(var i=this._hash.words,s=i[0],n=i[1],r=i[2],a=i[3],o=i[4],d=i[5],u=i[6],h=i[7],f=s.high,p=s.low,v=n.high,g=n.low,y=r.high,_=r.low,D=a.high,m=a.low,b=o.high,S=o.low,w=d.high,B=d.low,k=u.high,I=u.low,C=h.high,A=h.low,x=f,T=p,E=v,L=g,O=y,P=_,M=D,H=m,K=b,N=S,G=w,R=B,U=k,z=I,j=C,W=A,Z=0;Z<80;Z++){var F,V,$=l[Z];if(Z<16)V=$.high=0|e[t+2*Z],F=$.low=0|e[t+2*Z+1];else{var X=l[Z-15],q=X.high,J=X.low,Y=(q>>>1|J<<31)^(q>>>8|J<<24)^q>>>7,Q=(J>>>1|q<<31)^(J>>>8|q<<24)^(J>>>7|q<<25),ee=l[Z-2],te=ee.high,ie=ee.low,se=(te>>>19|ie<<13)^(te<<3|ie>>>29)^te>>>6,ne=(ie>>>19|te<<13)^(ie<<3|te>>>29)^(ie>>>6|te<<26),re=l[Z-7],ae=re.high,oe=re.low,ce=l[Z-16],le=ce.high,de=ce.low;V=(V=(V=Y+ae+((F=Q+oe)>>>0<Q>>>0?1:0))+se+((F+=ne)>>>0<ne>>>0?1:0))+le+((F+=de)>>>0<de>>>0?1:0),$.high=V,$.low=F}var ue,he=K&G^~K&U,fe=N&R^~N&z,pe=x&E^x&O^E&O,ve=T&L^T&P^L&P,ge=(x>>>28|T<<4)^(x<<30|T>>>2)^(x<<25|T>>>7),ye=(T>>>28|x<<4)^(T<<30|x>>>2)^(T<<25|x>>>7),_e=(K>>>14|N<<18)^(K>>>18|N<<14)^(K<<23|N>>>9),De=(N>>>14|K<<18)^(N>>>18|K<<14)^(N<<23|K>>>9),me=c[Z],be=me.high,Se=me.low,we=j+_e+((ue=W+De)>>>0<W>>>0?1:0),Be=ye+ve;j=U,W=z,U=G,z=R,G=K,R=N,K=M+(we=(we=(we=we+he+((ue+=fe)>>>0<fe>>>0?1:0))+be+((ue+=Se)>>>0<Se>>>0?1:0))+V+((ue+=F)>>>0<F>>>0?1:0))+((N=H+ue|0)>>>0<H>>>0?1:0)|0,M=O,H=P,O=E,P=L,E=x,L=T,x=we+(ge+pe+(Be>>>0<ye>>>0?1:0))+((T=ue+Be|0)>>>0<ue>>>0?1:0)|0}p=s.low=p+T,s.high=f+x+(p>>>0<T>>>0?1:0),g=n.low=g+L,n.high=v+E+(g>>>0<L>>>0?1:0),_=r.low=_+P,r.high=y+O+(_>>>0<P>>>0?1:0),m=a.low=m+H,a.high=D+M+(m>>>0<H>>>0?1:0),S=o.low=S+N,o.high=b+K+(S>>>0<N>>>0?1:0),B=d.low=B+R,d.high=w+G+(B>>>0<R>>>0?1:0),I=u.low=I+z,u.high=k+U+(I>>>0<z>>>0?1:0),A=h.low=A+W,h.high=C+j+(A>>>0<W>>>0?1:0)},_doFinalize:function(){var e=this._data,t=e.words,i=8*this._nDataBytes,s=8*e.sigBytes;return t[s>>>5]|=128<<24-s%32,t[30+(s+128>>>10<<5)]=Math.floor(i/4294967296),t[31+(s+128>>>10<<5)]=i,e.sigBytes=4*t.length,this._process(),this._hash.toX32()},clone:function(){var e=t.clone.call(this);return e._hash=this._hash.clone(),e},blockSize:32});e.SHA512=t._createHelper(d),e.HmacSHA512=t._createHmacHelper(d)}(),s.SHA512)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){return new Promise((i,s)=>{wx.request(Object.assign(Object.assign({url:e,timeout:3e3},t),{success:e=>{i(e)},fail:e=>{s(e)}}))})}},function(e,t,i){"use strict";var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const n=s(i(4)),r=i(2);class a extends n.default{constructor(e){super(e),this.passcode="";let t=0;const i=parseInt((0,r.arrayToString)(this.content.slice(t,t+2)),16);t+=2;let s="";this.content.slice(t,t+i).map(e=>{s+=String.fromCharCode(e)}),this.passcode=s}}a.pack=()=>[0,0,0,3,3,0,0,6],t.default=a},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{c(s.next(e))}catch(e){r(e)}}function o(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.formatBinary=t.formatEnum=t.padBoradcastData=t.unpack=t.pack=void 0;const r=n(i(17)),a=i(2),o=e=>-1!==e.indexOf("uint")?"number":e,c=(e,t,i)=>{let s="";switch(e){case"bool":s=`${!0===t[i.name]?1:0}`;break;case"enum":{let e=t[i.name];"number"==typeof e&&(e=i.enum[e]);const n=i.enum.findIndex(t=>e===t),r=-1===n?0:n;s=(0,a.fillString)(r.toString(2),i.position.len);break}case"number":{let e=0;null!=t[i.name]&&(e=Math.round((t[i.name]-i.uint_spec.addition)/i.uint_spec.ratio)),s=(0,a.fillString)(e.toString(2),8*i.position.len);break}case"binary":{let e=t[i.name]||"";e instanceof Array&&(e=(0,a.arrayToString)(e));const n=(0,a.fillString)(e,2*i.position.len,!0);for(let e=0;e<n.length/2;e++){const t=2*e,i=n[t]+n[t+1];s+=(0,a.fillString)(parseInt(i,16).toString(2),8)}break}}const n=i.position.len*("byte"===i.position.unit?8:1)-s.length;if(n>0)for(let e=0;e<n;e++)s=`0${s}`;return`${s}`},l=(e,t,i)=>{switch(e){case"bool":return"1"===t;case"enum":return parseInt(t,2);case"binary":{const e=i.position.len;let s="";for(let e=0;e<t.length/8;e++){const i=8*e,n=t.substring(i,i+8);s+=(0,a.fillString)(parseInt(n,2).toString(16),2)}return(0,a.fillString)(s,2*e,!0)}case"number":return parseInt(t,2)/(1/i.uint_spec.ratio)+i.uint_spec.addition;default:return""}},d=({config:e,data:t,isAdaptiveDatapoint:i})=>{let s=e;const n=[0,0,0,3],r=[0],l=[0,147],d=[0,0,0,0];let h=[1],f="";const p=[];i||(s=s.filter(e=>"status_writable"===e.type)),s.map(e=>{void 0!==t[e.name]?(f=`1${f}`,p.push(e)):f=`0${f}`}),i&&(h=[17],s=p),f=(0,a.fillString)(f,8*Math.ceil(f.length/8));for(let e=0;e<f.length/8;e++)h.push(parseInt(f.substring(8*e,8*(e+1)),2));let v,g="";try{v=s[0]}catch(e){}s.map(e=>{"bool"===e.data_type||"enum"===e.data_type?(v.type!==e.type&&(h=h.concat((0,a.completeBlock)(g)),g=""),g=((e,i)=>{const s=o(e.data_type);return i=c(s,t,e)+i})(e,g)):(g.length>0&&(h=h.concat((0,a.completeBlock)(g)),g=""),h=((e,i)=>{const s=o(e.data_type),n=c(s,t,e);return i=i.concat((0,a.completeBlock)(n))})(e,h)),v=e}),g.length>0&&(h=h.concat((0,a.completeBlock)(g)),g="");const y=r.concat(l).concat(d).concat(h),_=u(y);return n.push(..._),{data:n.concat(y),raw:{header:[0,0,0,3],flag:r,len:_,headerCmd:l,sn:d,cmd:h}}};function u(e){const t=e.length.toString(2),i=[];for(let e=t.length;e>0;e-=7){const s=e-7,n=e;let r=t.substring(s,n);r=`${s>0?"1":"0"}${r}`,i.push(parseInt(r,2))}return i}function h(e,t){return e===t||"ALL"===e}function f({attrs:e,activeAttrs:t,flagString:i,cmdData:s,accumulate:n}){let r=0,a={},o=0;return["status_writable","status_readonly","alert","fault"].map(c=>{const l=e.filter(e=>h(c,e.type)).length,{cmd:d,cmdDataLength:u}=p({type:c,attrs:e.slice(o,o+l),activeAttrs:t,flagString:i.substring(o,o+l),cmdData:s.slice(r,s.length),accumulate:n});return r+=u,a=Object.assign(Object.assign({},a),d),o+=l,null}),a}function p({type:e,attrs:t,activeAttrs:i,cmdData:s,flagString:n,accumulate:r}){let c=0,d=0,u=0;return i.map(t=>{if(h(e,t.type)){const e=t.position.len*("bit"===t.position.unit?1:8);"bool"===t.data_type||"enum"===t.data_type?d+=e:u+=e}return null}),c=Math.ceil(u/8)+Math.ceil(d/8),{cmdDataLength:c,cmd:function({attrs:e,flagString:t,boolEnumLength:i,cmdData:s,accumulate:n}){const r={};let c=0;for(let d=0;d<t.length;d++)if(e[d]&&"1"===t[d]){const{data_type:t,position:{len:n}}=e[d];let u="";if("bool"===t||"enum"===t){let e="";s.slice(0,i).map(t=>(e+=(0,a.fillString)(t.toString(2),8),null));const t=e.length-c;u=e.substring(t-n,t),c+=n}else{const e=i,t=i+n;s.slice(e,t).map(e=>(u+=(0,a.fillString)(e.toString(2),8),null)),i+=n}const h=o(t);r[e[d].name]=l(h,u,e[d])}else if(n){const t=e[d]||{position:{len:0}};"byte"===t.position.unit?i+=t.position.len:c+=t.position.len}return r}({attrs:t,flagString:n,boolEnumLength:Math.ceil(d/8),cmdData:s,accumulate:r})}}t.unpack=(e,t)=>s(void 0,void 0,void 0,(function*(){const i=yield r.default.getConfigFile(t);if(i){const s=function({config:e=[],data:t}){let i,s,n="";const r={header:(0,a.arrayToString)(t.slice(0,4)),flag:"",len:"",cmd:"",sn:"",action:"",payload:""},o=e;let c=(0,a.checkHeader)(t);if(!1===c)return;const l=t.slice(c,t.length),d=(0,a.getProtocolLen)(l);if(c+=d,r.len=(0,a.arrayToString)(l.slice(0,d)),c+=1,r.flag=(0,a.arrayToString)(t.slice(c-1,c)),c+=2,r.cmd=(0,a.arrayToString)(t.slice(c-2,c)),r.sn="",("0093"===r.cmd||"0094"===r.cmd)&&(c+=4,r.sn=(0,a.arrayToString)(t.slice(c-4,c)),"01"===r.flag)){c+=2,c+=parseInt((0,a.arrayToString)(t.slice(c-2,c)),16)}c+=1,r.action=(0,a.arrayToString)(t.slice(c-1,c)),i=parseInt(r.action,16),r.payload=(0,a.arrayToString)(t.slice(c,t.length));const u=t.slice(c,t.length);let h=o;1===i&&(h=o.filter(e=>"status_writable"===e.type));const v=JSON.parse(JSON.stringify(h)),g=Math.ceil(h.length/8);let y=u.slice(0,g),_=u.slice(g,u.length);3!==i&&4!==i||(y=new Array(g).fill(255),_=u);let D="";y.map(e=>(D+=(0,a.fillString)(e.toString(2),8),null)),i>=17&&i<=20&&(h=h.filter((e,t)=>{const i=D.length-1-t;return"1"===D[i]})),"0090"===r.cmd||"0093"===r.cmd?(n="App 透传数据到 Dev",s="APP2DEV"):"0091"===r.cmd||"0094"===r.cmd?(n="Dev 收到控制命令后应答到 App",s="DEV2APP"):(n="非法数据",s="UNKNOW");let m={};switch(i){case 1:n="App 下发数据到 Dev",m=f({attrs:v,activeAttrs:h,flagString:D.split("").reverse().join(""),cmdData:_,accumulate:!0});break;case 2:return n="App 下发查询指令到 Dev",{kvData:null,rawData:r,message:n,messageType:s};case 3:n="Dev 回复查询指令到 App",m=f({attrs:v,activeAttrs:h,flagString:D.split("").reverse().join(""),cmdData:_,accumulate:!0});break;case 4:n="Dev 上报状态到 App",m=f({attrs:v,activeAttrs:h,flagString:D.split("").reverse().join(""),cmdData:_,accumulate:!0});break;case 5:return n="App 透传数据到 Dev",{kvData:null,rawData:r,message:n,messageType:s};case 6:return n="Dev 透传数据到 App",{kvData:null,rawData:r,message:n,messageType:s};case 7:return n="App 下发控制子设备",{kvData:null,rawData:r,message:n,messageType:s};case 8:return n="App 读取子设备数据",{kvData:null,rawData:r,message:n,messageType:s};case 9:return n="Dev 中控回复ACK",{kvData:null,rawData:r,message:n,messageType:s};case 10:return n="子设备上报状态到 App",{kvData:null,rawData:r,message:n,messageType:s};case 11:return n="App 下发添加子设备指令",{kvData:null,rawData:r,message:n,messageType:s};case 12:return n="App 下发删除子设备",{kvData:null,rawData:r,message:n,messageType:s};case 13:return n="App 获取中控子设备列表",{kvData:null,rawData:r,message:n,messageType:s};case 14:return n="中控响应字设备查询到 App",{kvData:null,rawData:r,message:n,messageType:s};case 15:return n="子设备列表变更通知到 App",{kvData:null,rawData:r,message:n,messageType:s};case 16:return n="Dev 子设备上下线状态变更通知",{kvData:null,rawData:r,message:n,messageType:s};case 17:n="App 下发变长数据到 Dev",m=p({type:"ALL",attrs:v,activeAttrs:h,flagString:D.split("").reverse().join(""),cmdData:_}).cmd;break;case 18:return n="App 下发变长查询到 Dev",{kvData:null,rawData:r,message:n,messageType:s};case 19:n="Dev 变长回复查询指令到 App",m=p({type:"ALL",attrs:v,activeAttrs:h,flagString:D.split("").reverse().join(""),cmdData:_}).cmd;break;case 20:n="Dev 变长上报状态到 App",m=p({type:"ALL",attrs:v,activeAttrs:h,flagString:D.split("").reverse().join(""),cmdData:_}).cmd;break;case 114:return n="App 向网关发送数据",{kvData:null,rawData:r,message:n,messageType:s};case 115:return n="Dev 网关上报数据到 App",{kvData:null,rawData:r,message:n,messageType:s};case 116:return n="App 通知网关删除子设备",{kvData:null,rawData:r,message:n,messageType:s};default:return{kvData:null,rawData:r,message:n,messageType:s}}return 0===o.length?{kvData:null,rawData:r,message:n,messageType:s}:{kvData:m,rawData:r,message:n,messageType:s}}({config:(yield i).entities[0].attrs,data:e});return s.kvData&&(s.kvData=yield v(null==s?void 0:s.kvData,t,"object")),s}return null}));t.pack=(e,t)=>s(void 0,void 0,void 0,(function*(){const i=yield r.default.getConfigFile(t);if(i){const t="var_len"===i.protocolType;return d({data:e,config:(yield i).entities[0].attrs,isAdaptiveDatapoint:t})}return null}));t.padBoradcastData=e=>{const t=[0].concat([0,147]).concat([0,0,0,0]).concat(e),i=u(t);return(0,a.arrayToString)([0,0,0,3].concat(i).concat(t))};t.formatEnum=(e,t,i)=>s(void 0,void 0,void 0,(function*(){for(let s in e){const n=yield r.default.getAttrItem(t,s);if(n&&"enum"===n.data_type){if("int"===i&&"string"==typeof e[s]){const t=n.enum.findIndex(t=>t===e[s]);e[s]=t||0}"string"===i&&"number"==typeof e[s]&&(e[s]=n.enum[e[s]])}}return e}));const v=(e,t,i)=>s(void 0,void 0,void 0,(function*(){for(let s in e){const n=yield r.default.getAttrItem(t,s);n&&"binary"===n.data_type&&("object"===i&&"string"==typeof e[s]&&(e[s]=(0,a.hexStrint2byte)(e[s])),"string"===i&&"object"==typeof e[s]&&(e[s]=(0,a.arrayToString)(e[s])))}return e}));t.formatBinary=v},function(e,t,i){"use strict";var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const n=s(i(4)),r=i(2);class a extends n.default{constructor(e){super(e),this.result=!1,this.didLength=0,this.did="";let t=0;if(this.result=0===this.content[0],t++,1===this.flag[0]){this.didLength=parseInt((0,r.arrayToString)(this.content.slice(t,t+2)),16),t+=2;let e="";this.content.slice(t,this.content.length).map(t=>{e+=String.fromCharCode(t)}),this.did=e}}}a.pack=({passcode:e})=>{let t=[0];const i=(0,r.hexStrint2byte)((0,r.fillString)(e.length.toString(16),4)),s=(0,r.string2Bytes)(e),n=[0].concat([0,8]).concat(i).concat(s);return t=(0,r.hexStrint2byte)(n.length.toString(16)),[0,0,0,3].concat(t).concat(n)},t.default=a},function(e){e.exports=JSON.parse('{"name":"mini_program_gizwits_sdk","version":"3.2.29","description":"修正flag转换","main":"./dist/index.js","scripts":{"test":"node_modules/mocha/bin/_mocha -r ts-node/register tests/**/*.spec.ts -file ./tests/setup-wx.js -timeout 60s","testBle":"node_modules/mocha/bin/_mocha -r ts-node/register tests/utils/randomCode.spec.ts -file ./tests/setup-wx.js -timeout 60s","build":"rm -rf ./dist && webpack","release":"npm run build && release-it","cover":"istanbul cover node_modules/mocha/bin/_mocha -- -r ts-node/register tests/**/*.spec.ts -file ./tests/setup-wx.js -timeout 60s","coveralls":"npm run cover -- --report lcovonly && cat ./coverage/lcov.info | coveralls"},"repository":{"type":"git","url":"git+https://github.com/gizwits/mini_program_gizwits_sdk.git"},"keywords":["gizwits","miniprogram","sdk"],"devDependencies":{"@babel/plugin-transform-modules-commonjs":"^7.12.1","@release-it/conventional-changelog":"^2.0.0","@types/chai":"^4.2.11","@types/crypto-js":"^4.0.2","@types/mocha":"^7.0.2","@types/node":"^12.12.14","@types/sinon":"^10.0.6","chai":"^4.2.0","coveralls":"^3.0.11","istanbul":"^1.1.0-alpha.1","miniprogram-api-typings":"^3.9.0","mocha":"^7.1.1","release-it":"^14.2.2","sinon":"^9.2.4","ts-loader":"^6.2.2","ts-node":"^8.8.1","typescript":"^4.9.5","uglifyjs-webpack-plugin":"^2.2.0","webpack":"^4.42.1","webpack-bundle-analyzer":"^4.5.0","webpack-cli":"^3.3.11"},"author":"gizwits","license":"ISC","bugs":{"url":"https://github.com/gizwits/mini_program_gizwits_sdk/issues"},"homepage":"https://github.com/gizwits/mini_program_gizwits_sdk#readme","dependencies":{"crypto-js":"^4.1.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{c(s.next(e))}catch(e){r(e)}}function o(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.unpackWriteBLECharacteristicValue=t.writeBLECharacteristicValue=t.notifyBLECharacteristicValueChange=t.getBLEDeviceCharacteristics=t.getBLEDeviceServices=t.createBLEConnection=t.getBluetoothDevices=t.startBluetoothDevicesDiscovery=t.getBluetoothAdapterState=t.closeBluetoothAdapter=t.openBluetoothAdapter=t.retryConnect=void 0;const r=n(i(3)),a=n(i(10));function o(e,t){return new Promise((i,s)=>{wx.createBLEConnection({deviceId:e,timeout:t,success:e=>i(e),fail:e=>{-1===e.errCode?i(e):s(e)}})})}function c(e,t,i,s){return new Promise(n=>{wx.writeBLECharacteristicValue({deviceId:e,serviceId:t,characteristicId:i,value:s,complete:n})})}t.retryConnect=function(e,t=1e4){return s(this,void 0,void 0,(function*(){let i={success:!1};for(let s=0;s<5;s++)try{return console.debug("start createBLEConnection"),yield o(e,t)}catch(e){i=e,console.debug("createBLEConnection error retry"),yield(0,a.default)(1e3)}return i}))},t.openBluetoothAdapter=function(){return new Promise((e,t)=>{wx.openBluetoothAdapter({success:e,fail:t})})},t.closeBluetoothAdapter=function(){return new Promise((e,t)=>{wx.closeBluetoothAdapter({success:e,fail:t})})},t.getBluetoothAdapterState=function(){return new Promise((e,t)=>{wx.getBluetoothAdapterState({success:e,fail:t})})},t.startBluetoothDevicesDiscovery=function(e=!0){return new Promise((t,i)=>{wx.startBluetoothDevicesDiscovery({success:t,fail:i,allowDuplicatesKey:e,powerLevel:"high",interval:200})})},t.getBluetoothDevices=function(){return new Promise((e,t)=>{wx.getBluetoothDevices({success:({devices:t})=>e(t),fail:t})})},t.createBLEConnection=o,t.getBLEDeviceServices=function(e){return new Promise((t,i)=>{wx.getBLEDeviceServices({deviceId:e,success:({services:e})=>t(e),fail:i})})},t.getBLEDeviceCharacteristics=function(e,t){return new Promise((i,s)=>{wx.getBLEDeviceCharacteristics({deviceId:e,serviceId:t,success:({characteristics:e})=>i(e),fail:s})})},t.notifyBLECharacteristicValueChange=function(e,t,i,s=!0){return new Promise((n,r)=>{wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:t,characteristicId:i,state:s,success:n,fail:r})})},t.writeBLECharacteristicValue=c,t.unpackWriteBLECharacteristicValue=function(e,t,i,n){if(!n||0===n.byteLength)throw new Error("value is empty");return new Promise((o,l)=>s(this,void 0,void 0,(function*(){let s,d=0,u=n.byteLength;for(;u>0;){yield(0,a.default)(30);const o=n.slice(d,d+20);if(d+=20,u-=20,s=yield c(e,t,i,o),r.default.log("unpackWriteBLECharacteristicValue",d/20,s),0!==s.errCode)break}0!==s.errCode?l(s):o(s)})))}},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{c(s.next(e))}catch(e){r(e)}}function o(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});t.default=class{constructor(){this.listenerMap={},this.addEventListener=(e,t)=>s(this,void 0,void 0,(function*(){return this.listenerMap[e]||(this.listenerMap[e]=[]),-1===this.listenerMap[e].indexOf(t)&&this.listenerMap[e].push(t),{success:!0}})),this.removeEventListener=(e,t)=>{if(this.listenerMap[e]){const i=this.listenerMap[e].indexOf(t);if(-1!==i)return this.listenerMap[e].splice(i,1),{success:!0}}return{success:!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{c(s.next(e))}catch(e){r(e)}}function o(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.editBindInfo=t.safeRegister=t.checkDeviceRegister=t.unbindDevice=t.bindMac=t.getBindingList=void 0;const r=n(i(9)),a=n(i(68)),o=i(69),c=i(11);t.getBindingList=()=>s(void 0,void 0,void 0,(function*(){const e=yield(0,r.default)("/app/bindings?show_disabled=0&limit=1000&skip=0",{method:"GET"});if(e.success){return{success:!0,data:e.data.devices.map(e=>({productKey:e.product_key,mac:e.mac,did:e.did,host:e.host,port_s:e.port_s,port:e.port,ws_port:e.ws_port,wss_port:e.wss_port,passcode:e.passcode,isBleOnline:!1,isLanOnline:!1,connectType:"NONE",name:e.dev_alias,isBind:!0,isOnline:e.is_online}))}}return{success:!1,err:e.err}})),t.bindMac=function({mac:e,productKey:t,productSecret:i,alias:n,beOwner:a}){return s(this,void 0,void 0,(function*(){const s={mac:e,product_key:t,dev_alias:n,set_owner:a},{Signature:c,timestamp:l}=(0,o.psKeySign)(i);return yield(0,r.default)("/app/bind_mac",{method:"POST",data:s,headers:{"X-Gizwits-Signature":c,"X-Gizwits-Timestamp":l}})}))},t.unbindDevice=function({devices:e}){return s(this,void 0,void 0,(function*(){return yield(0,r.default)("/app/bindings",{method:"DELETE",data:{devices:e.map(e=>({did:e.did}))}})}))},t.checkDeviceRegister=function({SSID:e,password:t,productKeys:i}){return s(this,void 0,void 0,(function*(){const s=(0,a.default)({SSID:e,password:t,pks:i});let n="";return s.map(e=>{n+=`${e},`}),n=n.substring(0,n.length-1),yield(0,r.default)(`/app/device_register?random_codes=${n}`,{method:"get"})}))},t.safeRegister=function({productKey:e,productSecret:t,mac:i,passcode:n,gwDid:a,isReset:o}){return s(this,void 0,void 0,(function*(){let s=`is_reset=${o?1:0}&mac=${i}&passcode=${n}`;a&&(s+=`&gw_did=${a}`);const l=c.enc.Hex.parse(t),d=c.enc.Hex.parse(""),u=c.enc.Utf8.parse(s),h=c.AES.encrypt(u,l,{iv:d,mode:c.mode.ECB,padding:c.pad.Pkcs7}).ciphertext.toString().toUpperCase(),f=yield(0,r.default)(`/dev/${e}/device`,{method:"POST",data:{data:h},headers:{"content-type":"application/x-www-form-urlencoded"}},!1);return f.success?{success:!0,data:{successDevices:[],failedDevices:[]}}:{success:!1,err:f.err}}))},t.editBindInfo=function({name:e,remark:t,did:i}){return s(this,void 0,void 0,(function*(){const s={};return e&&(s.dev_alias=e),t&&(s.remark=t),yield(0,r.default)(`/app/bindings/${i}`,{method:"PUT",data:s},!0)}))}},function(e,t,i){"use strict";var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const n=s(i(4)),r=i(2);class a extends n.default{constructor(e){super(e)}}a.pack=(e,t)=>{const i=[],[s,n]=(0,r.formatCodesFromStr)(e),[a,o]=(0,r.formatCodesFromStr)(t),c=[0].concat([0,1],n,s,o,a);let l=c.length;for(;l>0;)i.push(l),l-=255;const d=[0,0,0,3].concat(i).concat(c),u=new ArrayBuffer(d.length),h=new Uint8Array(u);for(let e=0;e<u.byteLength;e++)h[e]=d[e];return h},t.default=a},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{c(s.next(e))}catch(e){r(e)}}function o(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=n(i(10)),a=n(i(5)),o=i(29),c=n(i(3));t.default=class{constructor(e,t,i,n){this.ssid="",this.password="",this.specialProductKeys=[],this.disableSearchDevice=!1,this.specialProductKeySecrets=[],this.timeoutHandler=null,this.setDeviceOnboardingDeployRej=()=>{},this.cleanTimeout=()=>{this.disableSearchDevice=!0,this.timeoutHandler&&clearTimeout(this.timeoutHandler),this.timeoutHandler=null},this.stopDeviceOnboardingDeploy=()=>{this.setDeviceOnboardingDeployRej&&this.setDeviceOnboardingDeployRej({success:!1,err:a.default.GIZ_SDK_ONBOARDING_STOPPED}),this.cleanTimeout()},this.hasTimeoutHandler=e=>!!this.timeoutHandler&&(e&&e({success:!1,err:a.default.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING}),!0),this.handleTimeout=()=>{this.setDeviceOnboardingDeployRej&&this.setDeviceOnboardingDeployRej({success:!1,err:{errorCode:a.default.CONFIG_TIME_OUT,errorMessage:"time out"}}),this.timeoutHandler=null},this.searchDevice=({ssid:e,password:t})=>new Promise((i,n)=>{c.default.debug("GIZ_SDK: 开始大循环搜索设备");const l=()=>s(this,void 0,void 0,(function*(){var s;if(this.hasTimeoutHandler())try{const d=yield(0,o.checkDeviceRegister)({SSID:e,password:t,productKeys:this.specialProductKeys});if((null===(s=d.err)||void 0===s?void 0:s.errorCode)===a.default.GIZ_OPENAPI_TOKEN_INVALID.errorCode)return void n({success:!1,err:a.default.GIZ_OPENAPI_TOKEN_INVALID});d.err||0===d.data.length?(c.default.debug("GIZ_SDK: 大循环没有发现设备"),yield(0,r.default)(1500),!this.disableSearchDevice&&l()):(c.default.debug("GIZ_SDK: 大循环搜索到设备",d),i({success:!0,data:d.data}))}catch(e){yield(0,r.default)(3e3),!this.disableSearchDevice&&l()}}));l()}),this.initDeviceOnboardingDeploy=(e,t)=>{this.setDeviceOnboardingDeployRej=e,this.disableSearchDevice=!1},this.startTimeoutTimer=e=>{this.timeoutHandler=setTimeout(this.handleTimeout,1e3*e)},this.bindDevices=e=>(c.default.log("GIZ_SDK: start bind device"),new Promise((t,i)=>s(this,void 0,void 0,(function*(){const s=e.map(e=>{const t=this.specialProductKeys.findIndex(t=>e.productKey===t);if(-1===t)return;const i=this.specialProductKeySecrets[t];return(0,o.bindMac)({mac:e.mac,productKey:e.productKey,productSecret:i})});try{const n=yield Promise.all(s),r=e.filter((e,t)=>{const i=n[t];return i&&i.success});r.length>0?(c.default.log("GIZ_SDK: bind device success",r),t({success:!0,data:r})):(c.default.log("GIZ_SDK: bind device error",n),i({success:!1,data:e,err:a.default.GIZ_SDK_BIND_DEVICE_FAILED}))}catch(e){i(e)}})))),this.ssid=e,this.password=t,this.specialProductKeys=i,this.specialProductKeySecrets=n}}},function(e,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{c(s.next(e))}catch(e){r(e)}}function o(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=i(14),a=i(19),o=n(i(63)),c=i(18),l=n(i(26)),d=n(i(3)),u=i(64),h=n(i(17)),f=i(24),p=n(i(66)),v=i(67),g=n(i(4)),y=i(2),_=i(29),D=i(70),m=i(71),b=n(i(10)),S=i(12),w=n(i(72)),B=n(i(73)),k=l.default.version;class I{get deviceList(){return this._deviceList}set deviceList(e){this._deviceList=e,this.notiDeviceList()}get bleDevices(){return this._bleDevices}set bleDevices(e){this._bleDevices=e,this.notiDeviceList()}get lanDevices(){return this._lanDevices}set lanDevices(e){this._lanDevices=e,this.notiDeviceList()}get allDevices(){let e=(0,S.merageBleLocalDevices)([...this.deviceList],this.bleDevices);e=(0,S.merageLanLocalDevices)(e,this.lanDevices),this.bleHandle.connectedList.map(t=>{const i=e.findIndex(e=>e.bleDeviceID===t.deviceId);-1!==i&&(e[i].connectType="BLE")});const t=this.socketHandle._connections;return Object.keys(t).forEach(i=>{const s=t[i];s&&s._subDids.forEach(t=>{const i=e.findIndex(e=>e.did===t);-1!==i&&(e[i].connectType="WAN")})}),this.lanHandle.connectedList.map(t=>{const i=e.findIndex(e=>e.mac===t.mac&&e.productKey===t.productKey);-1!==i&&(e[i].connectType="LAN")}),e}get bleScanDevice(){return this.bleDevices.filter(e=>!0===e.isBleOnline)}constructor(e){this.listenerMap={},this.keepScanTimer=null,this._deviceList=[],this._bleDevices=[],this._lanDevices=[],this.productInfo=[],this.syncDataCallBack=null,this.syncTotalNum=0,this.syncCurrnetNum=0,this.syncDataTimoutTimer=null,this.SYNC_TIMEOUT=24e4,this.init=({appID:e,appSecret:t,productInfo:i,cloudServiceInfo:s,token:n,uid:a,offlineThreshold:o})=>{this.productInfo=i,(0,r.setGlobalData)("appID",e),(0,r.setGlobalData)("appSecret",t),(0,r.setGlobalData)("productInfo",i),(0,r.setGlobalData)("token",n),(0,r.setGlobalData)("uid",a),this.setDomain(s),this.offlineThreshold=o,d.default.debug(`init sdk success, current version: ${I.getVersion().data}`),this.initLan()},this.handleBleError=e=>{this.listenerMap.onBleHandleError&&this.listenerMap.onBleHandleError.map(t=>{t(e)})},this.handleBleDevices=e=>{this.bleDevices=e},this.handleLanDevices=e=>{this.lanDevices=e},this.handleLanDeviceData=(e,t)=>s(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>t.mac===e);if(i){const e=yield(0,f.unpack)((0,y.hexStrint2byte)(t),i.productKey);(null==e?void 0:e.kvData)&&this.listenerMap.GizDeviceAttrsNotifications&&this.listenerMap.GizDeviceAttrsNotifications.map(t=>{t({device:i,data:null==e?void 0:e.kvData})})}})),this.handleBleDeviceData=(e,t)=>s(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>t.bleDeviceID===e.deviceId);if(i){const s=(0,y.hexStrint2byte)(t);switch(new g.default(s).cmd){case"0093":case"0094":case"0090":case"0091":{if(console.debug("handleBleDeviceData",t,i),i.passcode){const e=this.productInfo.find(e=>e.productKey===i.productKey);if(e){const s=parseInt(`${Date.now()/1e3}`,10);(0,m.uploadP0)({device:i,data:[{raw:t,created_at:s}],productSecret:e.productSecret}).then(e=>{d.default.debug("设备上报数据:timestemp",new Date(1e3*s).toLocaleString(),e)})}}const e=yield(0,f.unpack)((0,y.hexStrint2byte)(t),i.productKey);(null==e?void 0:e.kvData)&&this.listenerMap.GizDeviceAttrsNotifications&&this.listenerMap.GizDeviceAttrsNotifications.map(t=>{t({device:i,data:null==e?void 0:e.kvData})});break}case"0052":{const t=new v.RequestSync(s);if(d.default.debug("设备回复是否允许同步, state:",t.state),this.syncDataLengthCallback&&this.syncDataLengthCallback({success:0==t.state,data:t.len}),!this.syncDataCallBack)break;0===t.state?(this.syncCurrnetNum=0,this.syncTotalNum=t.len,this.syncDataCallBack({event:"SYNC_START",totalNum:this.syncTotalNum,currentNum:this.syncCurrnetNum}),d.default.debug("查询第一条离线数据"),yield this.bleHandle.write(e.deviceId,(0,S.numberArray2Uint8Array)(v.SyncPackage.pack(0)).buffer)):(d.default.debug("设备返回状态为1,同步失败"),this.syncDataCallBack({event:"SYNC_FAIL"}));break}case"0054":{if(!this.syncDataCallBack)break;d.default.debug("设备上报离线数据");const t=new v.SyncPackage(s),i=v.DeletePackage.pack(t.id);d.default.debug("设备上报离线数据:payload",t.payload);try{d.default.debug("设备上报离线数据:timestemp",new Date(1e3*t.timestemp).toLocaleString())}catch(e){}const n=this.productInfo.find(e=>e.productKey===this.syncDevice.productKey);if(n){const e=yield(0,m.uploadP0)({device:this.syncDevice,data:[{raw:(0,y.arrayToString)(t.payload),created_at:t.timestemp}],productSecret:n.productSecret});d.default.debug("上传离线数据结果",e)}this.syncCurrnetNum+=1,this.syncDataCallBack({event:"SYNC_PROGRESS",totalNum:this.syncTotalNum,currentNum:this.syncCurrnetNum}),d.default.debug("通知设备删除:",t.id),yield this.bleHandle.write(e.deviceId,(0,S.numberArray2Uint8Array)(i).buffer),yield(0,b.default)(100),t.id<this.syncTotalNum-1?(d.default.debug("查询新数据:",t.id+1),yield this.bleHandle.write(e.deviceId,(0,S.numberArray2Uint8Array)(v.SyncPackage.pack(t.id+1)).buffer)):(d.default.debug("send cancel sync to device"),this.bleHandle.write(e.deviceId,(0,S.numberArray2Uint8Array)(v.CancelSync.pack()).buffer),this.syncDataCallBack({event:"SYNC_END"}),this.cleanSyncDeviceData());break}case"0058":{if(!this.syncDataCallBack)break;const e=new v.CancelSync(s);d.default.debug("设备上报停止同步 state:",e.state),0===e.state?this.syncDataCallBack({event:"SYNC_END"}):this.syncDataCallBack({event:"SYNC_FAIL"}),this.cleanSyncDeviceData();break}}}})),this.handleSocketDeviceData=e=>s(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>t.did===e.did);if(t){if(e.attrs&&null!=e.attrs.is_online){const i=e.attrs.is_online;this.setDeviceMeta(t,"isOnline",i)}this.listenerMap.GizDeviceAttrsNotifications&&(e.attrs&&(e.attrs=yield(0,f.formatEnum)(e.attrs,t.productKey,"int")),this.listenerMap.GizDeviceAttrsNotifications.map(i=>{i(Object.assign({device:t},"attrs"in e?{data:e.attrs}:{raw:e.raw}))}))}})),this.handleSocketStatus=(e,t)=>{const i=this.allDevices.filter(t=>e.includes(t.did)&&"WAN"===t.connectType);d.default.log("handleSocketStatus",e,t),i.forEach(e=>{this.setDeviceMeta(e,"connectType",t?"WAN":"NONE")})},this.notiDeviceList=()=>{var e,t;null===(e=this.listenerMap.GizDeviceListNotifications)||void 0===e||e.map(e=>{e(this.allDevices)}),null===(t=this.listenerMap.onScanListChange)||void 0===t||t.map(e=>{e(this.bleScanDevice)})},this.initLan=()=>{try{this.lanHandle.init(),this.lanHandle.addEventListener("GizLanDeviceList",this.handleLanDevices),this.lanHandle.addEventListener("GizLanDeviceData",this.handleLanDeviceData)}catch(e){d.default.error("init lan error",e)}},this.startAutoScan=e=>{this.keepScanTimer||(this.keepScanTimer=setInterval(()=>s(this,void 0,void 0,(function*(){this.bleHandle.startScan(e=>{this.bleDevices=e},-1,e)})),9e3),this.bleHandle.startScan(e=>{this.bleDevices=e},-1,e))},this.stopAutoScan=()=>{this.keepScanTimer&&clearInterval(this.keepScanTimer),this.bleHandle.stopScan()},this.setDeviceMeta=(e,t,i,s=!1)=>{const n=this.allDevices.find(t=>t.mac===e.mac);n&&0!==this.allDevices.length&&(e[t]!==i||s)&&(n[t]=i,this.notiDeviceList())},this.initBle=()=>s(this,void 0,void 0,(function*(){const e=yield this.bleHandle.checkPermission();return e.success?(this.bleHandle.addEventListener("GizBleDeviceData",this.handleBleDeviceData),this.bleHandle.addEventListener("GizBleDeviceList",this.handleBleDevices),this.bleHandle.addEventListener("GizBleError",this.handleBleError),d.default.debug("init BLE succcess",e),{success:!0}):(d.default.error("init BLE Error",new Error(JSON.stringify(e))),{success:!1,err:c.errorCode.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON})})),this.scanBleDevice=(e,t)=>s(this,void 0,void 0,(function*(){return this.bleHandle.scanList=[],{success:!0,data:(yield this.bleHandle.startScan(e=>{this.bleDevices=e},e,t)).scanList}})),this.write=(e,t)=>s(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>(0,S.isSameDevice)(t,e));if(!i)return{success:!1,message:"target is undefind"};if("NONE"!==i.connectType){const{data:e,raw:s}=yield(0,f.pack)(t,i.productKey);switch(i.connectType){case"BLE_BROADCAST":return yield this.bleHandle.writeBoradcast(i.bleDeviceID,s.cmd);case"BLE":return e?yield this.bleHandle.write(i.bleDeviceID,(0,S.numberArray2Uint8Array)(e).buffer):{success:!1};case"WAN":{const e=yield(0,f.formatEnum)(t,i.productKey,"string");return this.socketHandle.writeData(i,e)}case"LAN":return this.lanHandle.write(i,(0,S.numberArray2Uint8Array)(e).buffer)}}return{success:!1}})),this.writeRaw=(e,t)=>s(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>(0,S.isSameDevice)(t,e));if(!i)return{success:!1,message:"target is undefind"};if("NONE"!==i.connectType)switch(i.connectType){case"BLE_BROADCAST":return yield this.bleHandle.writeBoradcast(i.bleDeviceID,t);case"BLE":return t?yield this.bleHandle.write(i.bleDeviceID,(0,S.numberArray2Uint8Array)(t).buffer):{success:!1};case"WAN":return this.socketHandle.send(i.did,t);case"LAN":return this.lanHandle.write(i,(0,S.numberArray2Uint8Array)(t).buffer)}return{success:!1}})),this.setDeviceTimeStamp=e=>s(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>(0,S.isSameDevice)(t,e));if(!t)return{success:!1,message:"target is undefind"};const i=p.default.pack();switch(t.connectType){case"BLE":return this.bleHandle.write(e.bleDeviceID,(0,S.numberArray2Uint8Array)(i).buffer)}return{success:!1,message:"the connectType not support set timestamp"}})),this.syncDeviceData=(e,t=(()=>{}))=>s(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>(0,S.isSameDevice)(t,e));if(!i)return{success:!1,message:"target is undefind"};if(!i.isBind)return{success:!1,message:"Only the bound devices are supported"};if(this.syncDevice)return{success:!1,message:"Synchronizing"};switch(this.syncDevice=Object.assign({},i),i.connectType){case"BLE":{d.default.debug("start syncDeviceData",e),this.syncDataCallBack=t,this.syncDataTimoutTimer=setTimeout(()=>{this.syncDataCallBack({event:"SYNC_FAIL",message:"sync timeout"}),this.cleanSyncDeviceData()},this.SYNC_TIMEOUT);const i=v.RequestSync.pack();return d.default.debug("sent RequestSync data"),this.bleHandle.write(e.bleDeviceID,(0,S.numberArray2Uint8Array)(i).buffer)}}return{success:!1,message:"the connectType not support sync data"}})),this.queryNeedSyncDataLength=e=>s(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>(0,S.isSameDevice)(t,e));if(!t)return{success:!1,message:"target is undefind"};if(!t.isBind)return{success:!1,message:"Only the bound devices are supported"};switch(t.connectType){case"BLE":{const i=v.RequestSync.pack();return this.syncDevice=Object.assign({},t),d.default.debug("sent RequestSync data len"),this.bleHandle.write(e.bleDeviceID,(0,S.numberArray2Uint8Array)(i).buffer),new Promise(e=>{this.syncDataLengthCallback=e,setTimeout(()=>{try{e({success:!1,message:"timeout"})}catch(e){}},3e3)})}}return{success:!1,message:"the connectType not support sync data"}})),this.cancelSyncDeviceData=()=>s(this,void 0,void 0,(function*(){this.cleanSyncDeviceData()})),this.cleanSyncDeviceData=()=>{this.syncDataCallBack&&(this.syncDataCallBack({event:"SYNC_CANCEL"}),this.syncDataCallBack=null),this.syncCurrnetNum=0,this.syncTotalNum=0,this.syncDevice=null,this.syncDataTimoutTimer&&clearTimeout(this.syncDataTimoutTimer)},this.getProductConfig=e=>s(this,void 0,void 0,(function*(){const t=yield h.default.getConfigFile(e);return t?{success:!0,data:t}:{success:!1}})),this.stopScanBleDevice=()=>{this.bleHandle.stopScan()},this.login=e=>s(this,void 0,void 0,(function*(){var t,i;const s=yield(0,D.AnonymousLogin)({uid:e});return s.success&&((0,r.setGlobalData)("token",null===(t=s.data)||void 0===t?void 0:t.token),(0,r.setGlobalData)("uid",null===(i=s.data)||void 0===i?void 0:i.uid),this.socketHandle.updateToken({token:s.data.token,uid:s.data.uid})),s})),this.getDeviceStatus=(e,t)=>s(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>(0,S.isSameDevice)(t,e));if(!i)return{success:!1,message:"target is undefind"};switch(i.connectType){case"BLE":return yield this.bleHandle.getDeviceStatus(i.bleDeviceID,i.productKey,i.rootDeviceId,t);case"WAN":return this.socketHandle.readStatus(i,t);default:return{success:!1,message:"Device connectType is unsupported"}}})),this.subscribe=(e,t,i=!0)=>s(this,void 0,void 0,(function*(){d.default.debug("subscribe device:",e);let i=this.allDevices.find(t=>(0,S.isSameDevice)(t,e));if(!i)return d.default.warn("Device Target Not Found"),d.default.warn("current devices ",this.allDevices),{success:!1,message:"device not found"};if("BLE_BROADCAST"===i.connectType)return{success:!0};const s=(0,S.getFirstConnectType)(i,t);switch("NONE"!==i.connectType&&i.connectType!==s&&(yield this.unSubscribe(i)),s){case"BLE":{const e=yield this.bleHandle.connectDevice(i);return e.success&&(this.setDeviceMeta(i,"connectType","BLE",!0),setTimeout(()=>{this.setDeviceTimeStamp(i)},250),setTimeout(()=>{this.getDeviceStatus(i)},500)),e}case"WAN":{const t=this.socketHandle.connectDevice(i);return t.success&&this.setDeviceMeta(e,"connectType","WAN",!0),t}case"LAN":{const t=yield this.lanHandle.connectDevice(i);return t.success&&this.setDeviceMeta(e,"connectType","LAN",!0),t}}return{success:!1}})),this.unSubscribe=e=>s(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>(0,S.isSameDevice)(t,e));switch(t.connectType){case"BLE":{const e=yield this.bleHandle.disConnectDevice(t.bleDeviceID);return e.success&&this.setDeviceMeta(t,"connectType","NONE",!0),e}case"WAN":{const e=this.socketHandle.disConnectDevice(t);return e.success&&this.setDeviceMeta(t,"connectType","NONE",!0),e}case"LAN":{const e=this.lanHandle.disConnectDevice(t);return e.success&&this.setDeviceMeta(t,"connectType","NONE",!0),e}}return{success:!1}})),this.bindRemoteDevice=({mac:e,productKey:t,alias:i,beOwner:n})=>s(this,void 0,void 0,(function*(){const s=(0,S.getProductInfoThroughPK)(t,this.productInfo);if(s){const r=yield(0,_.bindMac)({mac:e,productKey:t,productSecret:s.productSecret,alias:i,beOwner:n});return this.getBindingList(),r}return{success:!1,err:c.errorCode.GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY}})),this.unbindDevice=({devices:e})=>s(this,void 0,void 0,(function*(){const t=yield(0,_.unbindDevice)({devices:e});return t.success&&this.getBindingList(),t})),this.deviceSafetyRegister=({mac:e,productKey:t})=>s(this,void 0,void 0,(function*(){return yield this.deviceSafetyApi({mac:e,productKey:t,isReset:!1})})),this.deviceSafetyUnbind=({mac:e,productKey:t})=>s(this,void 0,void 0,(function*(){return yield this.deviceSafetyApi({mac:e,productKey:t,isReset:!0})})),this.setDeviceOnboardingDeploy=({ssid:e,password:t,mode:i=0,timeout:n,isBind:r=!0,softAPSSIDPrefix:a})=>s(this,void 0,void 0,(function*(){if(this.currentWifiConfigHandle)return{success:!1,err:c.errorCode.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING};const s=(new Date).getTime();d.default.debug("GIZ_SDK: 配网开始时间:"+s);try{switch(i){case 0:{this.currentWifiConfigHandle=new w.default(e,t,this.specialProductKeys,this.specialProductKeySecrets);const i=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:n,isBind:r,softAPSSIDPrefix:a});this.currentWifiConfigHandle=null;const o=(new Date).getTime();return d.default.debug("GIZ_SDK: 配网结束时间:"+o),d.default.debug("GIZ_SDK: 配网用时:"+(o-s)),i}case 3:{this.currentWifiConfigHandle=new B.default(e,t,this.specialProductKeys,this.specialProductKeySecrets,this.bleHandle);const i=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:n,isBind:r,softAPSSIDPrefix:a});this.currentWifiConfigHandle=null;const o=(new Date).getTime();return d.default.debug("GIZ_SDK: 配网结束时间:"+o),d.default.debug("GIZ_SDK: 配网用时:"+(o-s)),i}}}catch(e){return d.default.error("GIZ_SDK: setDeviceOnboardingDeploy",new Error(JSON.stringify(e))),e.err&&e.err.errorCode?e:{success:!1,err:c.errorCode.GIZ_SDK_OTHERWISE}}finally{this.currentWifiConfigHandle=null}})),this.setDomain=e=>{const t=e&&e.openAPIInfo||"api.gizwits.com",i=Object.assign(Object.assign({},e||{}),{openAPIInfo:t});(0,r.setGlobalData)("cloudServiceInfo",i)},this.deviceSafetyApi=({mac:e,productKey:t,isReset:i})=>s(this,void 0,void 0,(function*(){const s=(0,S.getProductInfoThroughPK)(t,this.productInfo);return s?yield(0,_.safeRegister)({productKey:t,productSecret:s.productSecret,mac:e,isReset:i,passcode:"1234567890"}):{success:!1,err:c.errorCode.GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY}})),this.getBindingList=()=>s(this,void 0,void 0,(function*(){const e=yield(0,_.getBindingList)();return this.deviceList=e.data||[],this.notiDeviceList(),e})),this.getDevices=()=>s(this,void 0,void 0,(function*(){return yield this.getBindingList(),{success:!0,data:this.allDevices}})),this.stopDeviceOnboardingDeploy=()=>{this.currentWifiConfigHandle&&(this.currentWifiConfigHandle.stopDeviceOnboardingDeploy(),this.currentWifiConfigHandle=null)},this.setLogLevel=e=>d.default.setLogLevel(e),this.renameDevice=(e,t)=>s(this,void 0,void 0,(function*(){return t?e.isBind?yield(0,_.editBindInfo)({did:e.did,name:t}):{success:!1,message:"device not bind"}:{success:!1,message:"please input device name"}})),this.removeEventListener=(e,t)=>{if(this.listenerMap[e]){const i=this.listenerMap[e].indexOf(t);if(-1!==i)return this.listenerMap[e].splice(i,1),{success:!0}}return{success:!1}},this.addEventListener=(e,t)=>s(this,void 0,void 0,(function*(){return this.listenerMap[e]||(this.listenerMap[e]=[]),-1===this.listenerMap[e].indexOf(t)&&this.listenerMap[e].push(t),{success:!0}})),this.destory=()=>{this.bleHandle.destory(),this.lanHandle.destory(),this.socketHandle.destory(),this.keepScanTimer&&clearInterval(this.keepScanTimer)},this.init(e)}get bleHandle(){return this._bleHandle||(this._bleHandle=new a.BleHandle({pks:this.specialProductKeys,offlineThreshold:this.offlineThreshold})),this._bleHandle}get lanHandle(){return this._lanHandle||(this._lanHandle=new u.LanHandle({pks:this.specialProductKeys})),this._lanHandle}get socketHandle(){return this._gizSocket||(this._gizSocket=new o.default({appID:(0,r.getGlobalData)("appID"),token:(0,r.getGlobalData)("token"),uid:(0,r.getGlobalData)("uid")}),this._gizSocket.subscribeDeviceStatus(this.handleSocketDeviceData),this._gizSocket.subscribeBindingChanged(this.getBindingList),this._gizSocket.subscribeSocketStatus(this.handleSocketStatus)),this._gizSocket}reInit(e){this.init(e),this.lanHandle.pks=this.specialProductKeys,this.bleHandle.pks=this.specialProductKeys,this.bleHandle.offlineThreshold=e.offlineThreshold;const{appID:t,token:i,cloudServiceInfo:s={openAPIInfo:""}}=e,n=s&&s.openAPIInfo||"api.gizwits.com";t===(0,r.getGlobalData)("appID")&&i===(0,r.getGlobalData)("token")&&n===(0,r.getGlobalData)("cloudServiceInfo").openAPIInfo||(this.socketHandle.destory(),this._gizSocket=null,this.socketHandle,this.getBindingList())}get specialProductKeys(){return this.productInfo.map(e=>{var t;return null!==(t=e.productKey)&&void 0!==t?t:""})}get specialProductKeySecrets(){return this.productInfo.map(e=>{var t;return null!==(t=e.productSecret)&&void 0!==t?t:""})}}I.getVersion=()=>({success:!0,data:k}),t.default=I},function(e,t,i){"use strict";var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const n=i(11),r=s(i(22));t.default=e=>{const t=wx.getSystemInfoSync(),i={exception:{values:[{type:"Error",value:e.stack,stacktrace:{},mechanism:{type:"generic",handled:!0}}]},level:"error",event_id:(0,n.MD5)(`${(new Date).getTime()}`).toString(),platform:"javascript",sdk:{},timestamp:(new Date).getTime()/1e3,environment:"production",contexts:{device:{},os:{name:t.platform,version:t.version},extra:{}},extra:{message:e.message}};var s={method:"POST",headers:{Connection:"keep-alive","User-Agent":"Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1 wechatdevtools/1.06.2206090 MicroMessenger/8.0.5 Language/zh_CN webview/","content-type":"application/json",Accept:"*/*","Sec-Fetch-Site":"cross-site","Sec-Fetch-Mode":"cors","Sec-Fetch-Dest":"empty",Referer:"https://servicewechat.com/wx6dc8e50cb68bc121/devtools/page-frame.html",Cookie:"__org="},data:JSON.stringify(i)};(0,r.default)("https://appmonitor.gizwits.com/api/21/store/?sentry_key=0b2de791abf548a1bedf0b0ebdd8ecc7&sentry_version=7",s)}},function(e,t){var i;i=function(){return this}();try{i=i||new Function("return this")()}catch(e){"object"==typeof window&&(i=window)}e.exports=i},function(e,t){},function(e,t,i){var s;e.exports=(s=i(0),function(){if("function"==typeof ArrayBuffer){var e=s.lib.WordArray,t=e.init;(e.init=function(e){if(e instanceof ArrayBuffer&&(e=new Uint8Array(e)),(e instanceof Int8Array||"undefined"!=typeof Uint8ClampedArray&&e instanceof Uint8ClampedArray||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array)&&(e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),e instanceof Uint8Array){for(var i=e.byteLength,s=[],n=0;n<i;n++)s[n>>>2]|=e[n]<<24-n%4*8;t.call(this,s,i)}else t.apply(this,arguments)}).prototype=e}}(),s.lib.WordArray)},function(e,t,i){var s;e.exports=(s=i(0),function(){var e=s,t=e.lib.WordArray,i=e.enc;function n(e){return e<<8&4278255360|e>>>8&16711935}i.Utf16=i.Utf16BE={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],n=0;n<i;n+=2){var r=t[n>>>2]>>>16-n%4*8&65535;s.push(String.fromCharCode(r))}return s.join("")},parse:function(e){for(var i=e.length,s=[],n=0;n<i;n++)s[n>>>1]|=e.charCodeAt(n)<<16-n%2*16;return t.create(s,2*i)}},i.Utf16LE={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],r=0;r<i;r+=2){var a=n(t[r>>>2]>>>16-r%4*8&65535);s.push(String.fromCharCode(a))}return s.join("")},parse:function(e){for(var i=e.length,s=[],r=0;r<i;r++)s[r>>>1]|=n(e.charCodeAt(r)<<16-r%2*16);return t.create(s,2*i)}}}(),s.enc.Utf16)},function(e,t,i){var s,n,r;e.exports=(r=i(0),n=(s=r).lib.WordArray,s.enc.Base64url={stringify:function(e,t=!0){var i=e.words,s=e.sigBytes,n=t?this._safe_map:this._map;e.clamp();for(var r=[],a=0;a<s;a+=3)for(var o=(i[a>>>2]>>>24-a%4*8&255)<<16|(i[a+1>>>2]>>>24-(a+1)%4*8&255)<<8|i[a+2>>>2]>>>24-(a+2)%4*8&255,c=0;c<4&&a+.75*c<s;c++)r.push(n.charAt(o>>>6*(3-c)&63));var l=n.charAt(64);if(l)for(;r.length%4;)r.push(l);return r.join("")},parse:function(e,t=!0){var i=e.length,s=t?this._safe_map:this._map,r=this._reverseMap;if(!r){r=this._reverseMap=[];for(var a=0;a<s.length;a++)r[s.charCodeAt(a)]=a}var o=s.charAt(64);if(o){var c=e.indexOf(o);-1!==c&&(i=c)}return function(e,t,i){for(var s=[],r=0,a=0;a<t;a++)if(a%4){var o=i[e.charCodeAt(a-1)]<<a%4*2,c=i[e.charCodeAt(a)]>>>6-a%4*2,l=o|c;s[r>>>2]|=l<<24-r%4*8,r++}return n.create(s,r)}(e,i,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",_safe_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"},r.enc.Base64url)},function(e,t,i){var s,n,r,a,o,c;e.exports=(c=i(0),i(20),n=(s=c).lib.WordArray,r=s.algo,a=r.SHA256,o=r.SHA224=a.extend({_doReset:function(){this._hash=new n.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var e=a._doFinalize.call(this);return e.sigBytes-=4,e}}),s.SHA224=a._createHelper(o),s.HmacSHA224=a._createHmacHelper(o),c.SHA224)},function(e,t,i){var s,n,r,a,o,c,l,d;e.exports=(d=i(0),i(13),i(21),n=(s=d).x64,r=n.Word,a=n.WordArray,o=s.algo,c=o.SHA512,l=o.SHA384=c.extend({_doReset:function(){this._hash=new a.init([new r.init(3418070365,3238371032),new r.init(1654270250,914150663),new r.init(2438529370,812702999),new r.init(355462360,4144912697),new r.init(1731405415,4290775857),new r.init(2394180231,1750603025),new r.init(3675008525,1694076839),new r.init(1203062813,3204075428)])},_doFinalize:function(){var e=c._doFinalize.call(this);return e.sigBytes-=16,e}}),s.SHA384=c._createHelper(l),s.HmacSHA384=c._createHmacHelper(l),d.SHA384)},function(e,t,i){var s;e.exports=(s=i(0),i(13),function(e){var t=s,i=t.lib,n=i.WordArray,r=i.Hasher,a=t.x64.Word,o=t.algo,c=[],l=[],d=[];!function(){for(var e=1,t=0,i=0;i<24;i++){c[e+5*t]=(i+1)*(i+2)/2%64;var s=(2*e+3*t)%5;e=t%5,t=s}for(e=0;e<5;e++)for(t=0;t<5;t++)l[e+5*t]=t+(2*e+3*t)%5*5;for(var n=1,r=0;r<24;r++){for(var o=0,u=0,h=0;h<7;h++){if(1&n){var f=(1<<h)-1;f<32?u^=1<<f:o^=1<<f-32}128&n?n=n<<1^113:n<<=1}d[r]=a.create(o,u)}}();var u=[];!function(){for(var e=0;e<25;e++)u[e]=a.create()}();var h=o.SHA3=r.extend({cfg:r.cfg.extend({outputLength:512}),_doReset:function(){for(var e=this._state=[],t=0;t<25;t++)e[t]=new a.init;this.blockSize=(1600-2*this.cfg.outputLength)/32},_doProcessBlock:function(e,t){for(var i=this._state,s=this.blockSize/2,n=0;n<s;n++){var r=e[t+2*n],a=e[t+2*n+1];r=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),a=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),(A=i[n]).high^=a,A.low^=r}for(var o=0;o<24;o++){for(var h=0;h<5;h++){for(var f=0,p=0,v=0;v<5;v++)f^=(A=i[h+5*v]).high,p^=A.low;var g=u[h];g.high=f,g.low=p}for(h=0;h<5;h++){var y=u[(h+4)%5],_=u[(h+1)%5],D=_.high,m=_.low;for(f=y.high^(D<<1|m>>>31),p=y.low^(m<<1|D>>>31),v=0;v<5;v++)(A=i[h+5*v]).high^=f,A.low^=p}for(var b=1;b<25;b++){var S=(A=i[b]).high,w=A.low,B=c[b];B<32?(f=S<<B|w>>>32-B,p=w<<B|S>>>32-B):(f=w<<B-32|S>>>64-B,p=S<<B-32|w>>>64-B);var k=u[l[b]];k.high=f,k.low=p}var I=u[0],C=i[0];for(I.high=C.high,I.low=C.low,h=0;h<5;h++)for(v=0;v<5;v++){var A=i[b=h+5*v],x=u[b],T=u[(h+1)%5+5*v],E=u[(h+2)%5+5*v];A.high=x.high^~T.high&E.high,A.low=x.low^~T.low&E.low}A=i[0];var L=d[o];A.high^=L.high,A.low^=L.low}},_doFinalize:function(){var t=this._data,i=t.words,s=(this._nDataBytes,8*t.sigBytes),r=32*this.blockSize;i[s>>>5]|=1<<24-s%32,i[(e.ceil((s+1)/r)*r>>>5)-1]|=128,t.sigBytes=4*i.length,this._process();for(var a=this._state,o=this.cfg.outputLength/8,c=o/8,l=[],d=0;d<c;d++){var u=a[d],h=u.high,f=u.low;h=16711935&(h<<8|h>>>24)|4278255360&(h<<24|h>>>8),f=16711935&(f<<8|f>>>24)|4278255360&(f<<24|f>>>8),l.push(f),l.push(h)}return new n.init(l,o)},clone:function(){for(var e=r.clone.call(this),t=e._state=this._state.slice(0),i=0;i<25;i++)t[i]=t[i].clone();return e}});t.SHA3=r._createHelper(h),t.HmacSHA3=r._createHmacHelper(h)}(Math),s.SHA3)},function(e,t,i){var s;e.exports=(s=i(0),
|
|
1
|
+
module.exports=function(e){var t={};function i(s){if(t[s])return t[s].exports;var n=t[s]={i:s,l:!1,exports:{}};return e[s].call(n.exports,n,n.exports,i),n.l=!0,n.exports}return i.m=e,i.c=t,i.d=function(e,t,s){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:s})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var s=Object.create(null);if(i.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)i.d(s,n,function(t){return e[t]}.bind(null,n));return s},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=19)}([function(e,t,i){(function(t){var s;e.exports=(s=s||function(e,s){var n;if("undefined"!=typeof window&&window.crypto&&(n=window.crypto),"undefined"!=typeof self&&self.crypto&&(n=self.crypto),"undefined"!=typeof globalThis&&globalThis.crypto&&(n=globalThis.crypto),!n&&"undefined"!=typeof window&&window.msCrypto&&(n=window.msCrypto),!n&&void 0!==t&&t.crypto&&(n=t.crypto),!n)try{n=i(36)}catch(e){}var r=function(){if(n){if("function"==typeof n.getRandomValues)try{return n.getRandomValues(new Uint32Array(1))[0]}catch(e){}if("function"==typeof n.randomBytes)try{return n.randomBytes(4).readInt32LE()}catch(e){}}throw new Error("Native crypto module could not be used to get secure random number.")},o=Object.create||function(){function e(){}return function(t){var i;return e.prototype=t,i=new e,e.prototype=null,i}}(),a={},c=a.lib={},l=c.Base={extend:function(e){var t=o(this);return e&&t.mixIn(e),t.hasOwnProperty("init")&&this.init!==t.init||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},d=c.WordArray=l.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||h).stringify(this)},concat:function(e){var t=this.words,i=e.words,s=this.sigBytes,n=e.sigBytes;if(this.clamp(),s%4)for(var r=0;r<n;r++){var o=i[r>>>2]>>>24-r%4*8&255;t[s+r>>>2]|=o<<24-(s+r)%4*8}else for(var a=0;a<n;a+=4)t[s+a>>>2]=i[a>>>2];return this.sigBytes+=n,this},clamp:function(){var t=this.words,i=this.sigBytes;t[i>>>2]&=4294967295<<32-i%4*8,t.length=e.ceil(i/4)},clone:function(){var e=l.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var t=[],i=0;i<e;i+=4)t.push(r());return new d.init(t,e)}}),u=a.enc={},h=u.Hex={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],n=0;n<i;n++){var r=t[n>>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,i=[],s=0;s<t;s+=2)i[s>>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new d.init(i,t/2)}},f=u.Latin1={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],n=0;n<i;n++){var r=t[n>>>2]>>>24-n%4*8&255;s.push(String.fromCharCode(r))}return s.join("")},parse:function(e){for(var t=e.length,i=[],s=0;s<t;s++)i[s>>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new d.init(i,t)}},p=u.Utf8={stringify:function(e){try{return decodeURIComponent(escape(f.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return f.parse(unescape(encodeURIComponent(e)))}},v=c.BufferedBlockAlgorithm=l.extend({reset:function(){this._data=new d.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=p.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var i,s=this._data,n=s.words,r=s.sigBytes,o=this.blockSize,a=r/(4*o),c=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,l=e.min(4*c,r);if(c){for(var u=0;u<c;u+=o)this._doProcessBlock(n,u);i=n.splice(0,c),s.sigBytes-=l}return new d.init(i,l)},clone:function(){var e=l.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0}),g=(c.Hasher=v.extend({cfg:l.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){v.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,i){return new e.init(i).finalize(t)}},_createHmacHelper:function(e){return function(t,i){return new g.HMAC.init(e,i).finalize(t)}}}),a.algo={});return a}(Math),s)}).call(this,i(35))},function(e,t,i){var s,n,r,o,a,c,l,d,u,h,f,p,v,g,y,_,D,m,b;e.exports=(s=i(0),i(6),void(s.lib.Cipher||(n=s,r=n.lib,o=r.Base,a=r.WordArray,c=r.BufferedBlockAlgorithm,l=n.enc,l.Utf8,d=l.Base64,u=n.algo.EvpKDF,h=r.Cipher=c.extend({cfg:o.extend(),createEncryptor:function(e,t){return this.create(this._ENC_XFORM_MODE,e,t)},createDecryptor:function(e,t){return this.create(this._DEC_XFORM_MODE,e,t)},init:function(e,t,i){this.cfg=this.cfg.extend(i),this._xformMode=e,this._key=t,this.reset()},reset:function(){c.reset.call(this),this._doReset()},process:function(e){return this._append(e),this._process()},finalize:function(e){return e&&this._append(e),this._doFinalize()},keySize:4,ivSize:4,_ENC_XFORM_MODE:1,_DEC_XFORM_MODE:2,_createHelper:function(){function e(e){return"string"==typeof e?b:D}return function(t){return{encrypt:function(i,s,n){return e(s).encrypt(t,i,s,n)},decrypt:function(i,s,n){return e(s).decrypt(t,i,s,n)}}}}()}),r.StreamCipher=h.extend({_doFinalize:function(){return this._process(!0)},blockSize:1}),f=n.mode={},p=r.BlockCipherMode=o.extend({createEncryptor:function(e,t){return this.Encryptor.create(e,t)},createDecryptor:function(e,t){return this.Decryptor.create(e,t)},init:function(e,t){this._cipher=e,this._iv=t}}),v=f.CBC=function(){var e=p.extend();function t(e,t,i){var s,n=this._iv;n?(s=n,this._iv=void 0):s=this._prevBlock;for(var r=0;r<i;r++)e[t+r]^=s[r]}return e.Encryptor=e.extend({processBlock:function(e,i){var s=this._cipher,n=s.blockSize;t.call(this,e,i,n),s.encryptBlock(e,i),this._prevBlock=e.slice(i,i+n)}}),e.Decryptor=e.extend({processBlock:function(e,i){var s=this._cipher,n=s.blockSize,r=e.slice(i,i+n);s.decryptBlock(e,i),t.call(this,e,i,n),this._prevBlock=r}}),e}(),g=(n.pad={}).Pkcs7={pad:function(e,t){for(var i=4*t,s=i-e.sigBytes%i,n=s<<24|s<<16|s<<8|s,r=[],o=0;o<s;o+=4)r.push(n);var c=a.create(r,s);e.concat(c)},unpad:function(e){var t=255&e.words[e.sigBytes-1>>>2];e.sigBytes-=t}},r.BlockCipher=h.extend({cfg:h.cfg.extend({mode:v,padding:g}),reset:function(){var e;h.reset.call(this);var t=this.cfg,i=t.iv,s=t.mode;this._xformMode==this._ENC_XFORM_MODE?e=s.createEncryptor:(e=s.createDecryptor,this._minBufferSize=1),this._mode&&this._mode.__creator==e?this._mode.init(this,i&&i.words):(this._mode=e.call(s,this,i&&i.words),this._mode.__creator=e)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e,t=this.cfg.padding;return this._xformMode==this._ENC_XFORM_MODE?(t.pad(this._data,this.blockSize),e=this._process(!0)):(e=this._process(!0),t.unpad(e)),e},blockSize:4}),y=r.CipherParams=o.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),_=(n.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext,i=e.salt;return(i?a.create([1398893684,1701076831]).concat(i).concat(t):t).toString(d)},parse:function(e){var t,i=d.parse(e),s=i.words;return 1398893684==s[0]&&1701076831==s[1]&&(t=a.create(s.slice(2,4)),s.splice(0,4),i.sigBytes-=16),y.create({ciphertext:i,salt:t})}},D=r.SerializableCipher=o.extend({cfg:o.extend({format:_}),encrypt:function(e,t,i,s){s=this.cfg.extend(s);var n=e.createEncryptor(i,s),r=n.finalize(t),o=n.cfg;return y.create({ciphertext:r,key:i,iv:o.iv,algorithm:e,mode:o.mode,padding:o.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,i,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(i,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}}),m=(n.kdf={}).OpenSSL={execute:function(e,t,i,s){s||(s=a.random(8));var n=u.create({keySize:t+i}).compute(e,s),r=a.create(n.words.slice(t),4*i);return n.sigBytes=4*t,y.create({key:n,iv:r,salt:s})}},b=r.PasswordBasedCipher=D.extend({cfg:D.cfg.extend({kdf:m}),encrypt:function(e,t,i,s){var n=(s=this.cfg.extend(s)).kdf.execute(i,e.keySize,e.ivSize);s.iv=n.iv;var r=D.encrypt.call(this,e,t,n.key,s);return r.mixIn(n),r},decrypt:function(e,t,i,s){s=this.cfg.extend(s),t=this._parse(t,s.format);var n=s.kdf.execute(i,e.keySize,e.ivSize,t.salt);return s.iv=n.iv,D.decrypt.call(this,e,t,n.key,s)}}))))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.arrayToUint8=t.formatCode=t.formatCodesFromStr=t.hexStrint2byte=t.string2Bytes=t.fillString=t.arrayToString=t.getProtocolLen=t.checkHeader=t.completeBlock=void 0;t.checkHeader=e=>{let t=0;return 0===e[0]&&0===e[1]&&0===e[2]&&3===e[3]&&(t=4,4)};t.completeBlock=e=>{const t=s(e,8*Math.ceil(e.length/8)),i=[];for(let e=0;e<t.length;e+=8)i.push(parseInt(t.substring(e,e+8),2));return i};t.getProtocolLen=e=>{let t=0;for(;t<e.length&&"1"===s(e[t].toString(2),8)[0];t++);return t+1},t.arrayToString=function(e){let t="";return e.map(e=>(t+=s(e.toString(16),2),null)),t};const s=(e,t,i=!1)=>{const s=t-e.length,n=new Array(s).fill(0).join("");return i?e+=n:e=n+e,e};t.fillString=s;t.string2Bytes=e=>{const t=[];for(let i=0;i<e.length;i++)t.push(e.charCodeAt(i));return t};t.hexStrint2byte=e=>{e.length%2!=0&&(e=`0${e}`);const t=Math.ceil(e.length/2),i=[];for(let s=0;s<t;s++){const t=2*s,n=t+2,r=e.substring(t,n);i.push(parseInt(r,16))}return i};const n=e=>{const t=encodeURI(e);return-1!==t.indexOf("%")&&"%"!==e?t.split("%").filter(e=>""!==e).map(e=>parseInt(e,16)):[t.charCodeAt(0)]};t.formatCode=n;t.formatCodesFromStr=e=>{const t=[0,0];let i=[];for(let s=0;s<e.length;s++){const r=n(e[s]);t[1]+=r.length,i=i.concat(r)}return[i,t]};t.arrayToUint8=e=>{const t=new ArrayBuffer(e.length),i=new Uint8Array(t);for(let s=0;s<t.byteLength;s++)i[s]=e[s];return i}},function(e,t,i){"use strict";var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const n=s(i(5)),r=s(i(34));t.default=new class{constructor(){this.logMap=[{id:"debug"},{id:"info"},{id:"warn"},{id:"error"}],this.console=console,this.debug=(...e)=>{this.console.debug(...e)},this.info=(...e)=>{this.console.info(...e)},this.log=(...e)=>{this.console.log(...e)},this.warn=(...e)=>{this.console.warn(...e)},this.error=(e,t)=>{this.console.error(e,t),(0,r.default)(t)},this.setLogLevel=e=>{const t=this.logMap.findIndex(t=>t.id===e);return-1!==t?(this.console=Object.assign({},console),this.logMap.map((e,i)=>{i<t&&(this.console[e.id]=()=>{})}),{success:!0,err:null}):{success:!1,err:n.default.GIZ_SDK_LOG_LEVEL_INVALID}}}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(2);class n{constructor(e){this.header="",this.len=0,this.flag=[0],this.cmd="",this.content=[],this.formatP0=e=>{let t=(0,s.checkHeader)(e);if(!1===t)throw new Error("Header Error");this.header=(0,s.arrayToString)(e.slice(0,t));const i=e.slice(t,e.length),r=(0,s.getProtocolLen)(i);this.len=n.decodeLen(i.slice(0,r)),t+=r,this.flag=e.slice(t,t+1),t+=1,this.cmd=(0,s.arrayToString)(e.slice(t,t+2)),t+=2,this.content=e.slice(t,e.length)},e&&e.length>0&&this.formatP0(e)}}n.decodeLen=e=>{let t=1,i=0,s=0,n=0;do{s=e[n],i+=(127&s)*t,t*=128,n+=1}while(0!=(128&s));return i},t.default=n},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default={GIZ_OPENAPI_DEVICE_NOT_BOUND:{errorCode:9017,errorMessage:"not bind"},GIZ_SDK_HTTP_REQUEST_FAILED:{errorCode:8099,errorMessage:"网络请求失败"},GIZ_SDK_SDK_NOT_INITIALIZED:{errorCode:8300,errorMessage:"not init"},CONFIG_TIME_OUT:{errorCode:8023,errorMessage:"Config Timeout"},WECHAT_ERROR:{errorCode:1e4,errorMessage:"wechat error"},GIZ_SDK_ONBOARDING_STOPPED:{errorCode:8318,errorMessage:"配网中断"},GIZ_SDK_DEVICE_CONFIG_IS_RUNNING:{errorCode:8022,errorMessage:"配置正在进行中"},GIZ_OPENAPI_TOKEN_INVALID:{errorCode:9004,errorMessage:"token 失效"},GIZ_SDK_BIND_DEVICE_FAILED:{errorCode:8039,errorMessage:"设备绑定失败"},GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON:{errorCode:8281,errorMessage:"蓝牙未启用"},GIZ_SDK_OTHERWISE:{errorCode:8100,errorMessage:""},GIZ_SDK_DEVICE_NOT_SUBSCRIBED:{errorCode:8029,errorMessage:"设备还未订阅"},GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY:{errorCode:8250,errorMessage:"产品类型不在指定范围内"},GIZ_SDK_LOG_LEVEL_INVALID:{errorCode:8009,errorMessage:"产品类型不在指定范围内"}}},function(e,t,i){var s,n,r,o,a,c,l,d;e.exports=(d=i(0),i(15),i(16),n=(s=d).lib,r=n.Base,o=n.WordArray,a=s.algo,c=a.MD5,l=a.EvpKDF=r.extend({cfg:r.extend({keySize:4,hasher:c,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var i,s=this.cfg,n=s.hasher.create(),r=o.create(),a=r.words,c=s.keySize,l=s.iterations;a.length<c;){i&&n.update(i),i=n.update(e).finalize(t),n.reset();for(var d=1;d<l;d++)i=n.finalize(i),n.reset();r.concat(i)}return r.sigBytes=4*c,r}}),s.EvpKDF=function(e,t,i){return l.create(i).compute(e,t)},d.EvpKDF)},function(e,t,i){var s,n,r;e.exports=(r=i(0),n=(s=r).lib.WordArray,s.enc.Base64={stringify:function(e){var t=e.words,i=e.sigBytes,s=this._map;e.clamp();for(var n=[],r=0;r<i;r+=3)for(var o=(t[r>>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;a<4&&r+.75*a<i;a++)n.push(s.charAt(o>>>6*(3-a)&63));var c=s.charAt(64);if(c)for(;n.length%4;)n.push(c);return n.join("")},parse:function(e){var t=e.length,i=this._map,s=this._reverseMap;if(!s){s=this._reverseMap=[];for(var r=0;r<i.length;r++)s[i.charCodeAt(r)]=r}var o=i.charAt(64);if(o){var a=e.indexOf(o);-1!==a&&(t=a)}return function(e,t,i){for(var s=[],r=0,o=0;o<t;o++)if(o%4){var a=i[e.charCodeAt(o-1)]<<o%4*2,c=i[e.charCodeAt(o)]>>>6-o%4*2,l=a|c;s[r>>>2]|=l<<24-r%4*8,r++}return n.create(s,r)}(e,t,s)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},r.enc.Base64)},function(e,t,i){var s;e.exports=(s=i(0),function(e){var t=s,i=t.lib,n=i.WordArray,r=i.Hasher,o=t.algo,a=[];!function(){for(var t=0;t<64;t++)a[t]=4294967296*e.abs(e.sin(t+1))|0}();var c=o.MD5=r.extend({_doReset:function(){this._hash=new n.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,t){for(var i=0;i<16;i++){var s=t+i,n=e[s];e[s]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8)}var r=this._hash.words,o=e[t+0],c=e[t+1],f=e[t+2],p=e[t+3],v=e[t+4],g=e[t+5],y=e[t+6],_=e[t+7],D=e[t+8],m=e[t+9],b=e[t+10],S=e[t+11],w=e[t+12],B=e[t+13],k=e[t+14],I=e[t+15],C=r[0],A=r[1],x=r[2],T=r[3];C=l(C,A,x,T,o,7,a[0]),T=l(T,C,A,x,c,12,a[1]),x=l(x,T,C,A,f,17,a[2]),A=l(A,x,T,C,p,22,a[3]),C=l(C,A,x,T,v,7,a[4]),T=l(T,C,A,x,g,12,a[5]),x=l(x,T,C,A,y,17,a[6]),A=l(A,x,T,C,_,22,a[7]),C=l(C,A,x,T,D,7,a[8]),T=l(T,C,A,x,m,12,a[9]),x=l(x,T,C,A,b,17,a[10]),A=l(A,x,T,C,S,22,a[11]),C=l(C,A,x,T,w,7,a[12]),T=l(T,C,A,x,B,12,a[13]),x=l(x,T,C,A,k,17,a[14]),C=d(C,A=l(A,x,T,C,I,22,a[15]),x,T,c,5,a[16]),T=d(T,C,A,x,y,9,a[17]),x=d(x,T,C,A,S,14,a[18]),A=d(A,x,T,C,o,20,a[19]),C=d(C,A,x,T,g,5,a[20]),T=d(T,C,A,x,b,9,a[21]),x=d(x,T,C,A,I,14,a[22]),A=d(A,x,T,C,v,20,a[23]),C=d(C,A,x,T,m,5,a[24]),T=d(T,C,A,x,k,9,a[25]),x=d(x,T,C,A,p,14,a[26]),A=d(A,x,T,C,D,20,a[27]),C=d(C,A,x,T,B,5,a[28]),T=d(T,C,A,x,f,9,a[29]),x=d(x,T,C,A,_,14,a[30]),C=u(C,A=d(A,x,T,C,w,20,a[31]),x,T,g,4,a[32]),T=u(T,C,A,x,D,11,a[33]),x=u(x,T,C,A,S,16,a[34]),A=u(A,x,T,C,k,23,a[35]),C=u(C,A,x,T,c,4,a[36]),T=u(T,C,A,x,v,11,a[37]),x=u(x,T,C,A,_,16,a[38]),A=u(A,x,T,C,b,23,a[39]),C=u(C,A,x,T,B,4,a[40]),T=u(T,C,A,x,o,11,a[41]),x=u(x,T,C,A,p,16,a[42]),A=u(A,x,T,C,y,23,a[43]),C=u(C,A,x,T,m,4,a[44]),T=u(T,C,A,x,w,11,a[45]),x=u(x,T,C,A,I,16,a[46]),C=h(C,A=u(A,x,T,C,f,23,a[47]),x,T,o,6,a[48]),T=h(T,C,A,x,_,10,a[49]),x=h(x,T,C,A,k,15,a[50]),A=h(A,x,T,C,g,21,a[51]),C=h(C,A,x,T,w,6,a[52]),T=h(T,C,A,x,p,10,a[53]),x=h(x,T,C,A,b,15,a[54]),A=h(A,x,T,C,c,21,a[55]),C=h(C,A,x,T,D,6,a[56]),T=h(T,C,A,x,I,10,a[57]),x=h(x,T,C,A,y,15,a[58]),A=h(A,x,T,C,B,21,a[59]),C=h(C,A,x,T,v,6,a[60]),T=h(T,C,A,x,S,10,a[61]),x=h(x,T,C,A,f,15,a[62]),A=h(A,x,T,C,m,21,a[63]),r[0]=r[0]+C|0,r[1]=r[1]+A|0,r[2]=r[2]+x|0,r[3]=r[3]+T|0},_doFinalize:function(){var t=this._data,i=t.words,s=8*this._nDataBytes,n=8*t.sigBytes;i[n>>>5]|=128<<24-n%32;var r=e.floor(s/4294967296),o=s;i[15+(n+64>>>9<<4)]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),i[14+(n+64>>>9<<4)]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8),t.sigBytes=4*(i.length+1),this._process();for(var a=this._hash,c=a.words,l=0;l<4;l++){var d=c[l];c[l]=16711935&(d<<8|d>>>24)|4278255360&(d<<24|d>>>8)}return a},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});function l(e,t,i,s,n,r,o){var a=e+(t&i|~t&s)+n+o;return(a<<r|a>>>32-r)+t}function d(e,t,i,s,n,r,o){var a=e+(t&s|i&~s)+n+o;return(a<<r|a>>>32-r)+t}function u(e,t,i,s,n,r,o){var a=e+(t^i^s)+n+o;return(a<<r|a>>>32-r)+t}function h(e,t,i,s,n,r,o){var a=e+(i^(t|~s))+n+o;return(a<<r|a>>>32-r)+t}t.MD5=r._createHelper(c),t.HmacMD5=r._createHmacHelper(c)}(Math),s.MD5)},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 o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=n(i(5)),o=i(14),a=n(i(23));t.default=(e,t,i=!0)=>s(void 0,void 0,void 0,(function*(){const s=Object.assign({},t),n={"Content-Type":"application/json","X-Gizwits-Application-Id":(0,o.getGlobalData)("appID")};i&&(n["X-Gizwits-User-token"]=(0,o.getGlobalData)("token")),s.header=Object.assign(Object.assign({},n),t.headers),delete s.headers;const c=(0,o.getGlobalData)("cloudServiceInfo").openAPIInfo,l=yield(0,a.default)("https://"+c+e,s);if(l.statusCode>=200&&l.statusCode<300)return{success:!0,data:l.data};let d={success:!1,err:{errorCode:r.default.GIZ_SDK_HTTP_REQUEST_FAILED.errorCode,errorMessage:""}};try{d={success:!1,err:{errorCode:l.data.error_code,errorMessage:l.data.error_message}}}catch(e){}return d}))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=e=>new Promise(t=>setTimeout(()=>t(),e))},function(e,t,i){var s;e.exports=(s=i(0),i(13),i(37),i(38),i(7),i(39),i(8),i(15),i(21),i(40),i(22),i(41),i(42),i(43),i(16),i(44),i(6),i(1),i(45),i(46),i(47),i(48),i(49),i(50),i(51),i(52),i(53),i(54),i(55),i(56),i(57),i(58),i(59),i(60),s)},function(e,t,i){"use strict";var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.convertToUuids=t.convertToServiceUuids=t.encrypt=t.ab2numbers=t.parseBroadcastData=t.hex2ab=t.mergeObject=t.getProductInfoThroughPK=t.getFirstConnectType=t.BTDevice2GDevice=t.merageLanLocalDevices=t.merageBleLocalDevices=t.isSameDevice=t.advertisData2PkAndMac=t.numberArray2Uint8Array=t.str2Buf=t.isWXDevicesResult=t.unionBy=t.wrapErrorInfo=t.isError=t.compareWXSDKVersion=t.ab2hex=void 0;const n=s(i(3));function r(e){return Array.prototype.map.call(new Uint8Array(e),(function(e){return("00"+e.toString(16)).slice(-2)})).join("")}t.ab2hex=r,t.compareWXSDKVersion=function(e,t){const i=e.split("."),s=t.split("."),n=Math.max(e.length,t.length);for(;i.length<n;)i.push("0");for(;s.length<n;)s.push("0");for(let i=0;i<n;i++){const s=parseInt(e[i]),n=parseInt(t[i]);if(s>n)return 1;if(s<n)return-1}return 0};t.isError=e=>null!=e&&"symbol"==typeof e.errorCode;t.wrapErrorInfo=e=>({errorCode:e,errorMessage:e});t.unionBy=(e,t)=>e.reduce((e,i)=>{const s=i[t];return e.some(e=>e[t]===s)||e.push(i),e},[]),t.isWXDevicesResult=function(e){return e.success&&"[object Array]"===Object.prototype.toString.call(e.bleDevices)},t.str2Buf=function(e){var t=e.length,i=new ArrayBuffer(t+2),s=new DataView(i);for(let i=0;i<t;i++)s.setUint8(i,parseInt(e[i],16));return i};t.numberArray2Uint8Array=e=>{const t=new ArrayBuffer(e.length),i=new Uint8Array(t);for(let s=0;s<t.byteLength;s++)i[s]=e[s];return i};t.advertisData2PkAndMac=(e,t)=>e&&e.byteLength>=22&&e.byteLength<=24?Object.assign(Object.assign({},((e,t)=>{let i=e.slice(e.byteLength-16),s=e.slice(0,e.byteLength-16),n=r(i);if(t.find(e=>e===n)){const e=r(s);return{productKey:n,mac:e}}{i=e.slice(0,16),s=e.slice(16),n=r(i);const t=r(s);return{productKey:n,mac:t}}})(e,t)),{bleWorkStatus:1}):e&&e.byteLength>24?((e,t)=>{if(!e||0===e.byteLength)return{bleWorkStatus:0,mac:"",productKey:""};let i=0,s="",n="",o=1;const a=new Uint8Array(e);for(;!(i>e.byteLength-1);){const c=a[i];if(c<=0||!c)break;if(e.byteLength<c+i+1)break;const l=e.slice(i+1,i+c+1);if(c>=6&&c<=8&&(s=r(l),16==s.length&&(s=s.substring(0,15))),16==c){const e=r(l).toLowerCase();t.find(t=>t===e)&&(n=e)}1==c&&(o=new Uint8Array(l)[0]),i+=1+c}return{bleWorkStatus:o,mac:s,productKey:n}})(e,t):{mac:"",productKey:"",bleWorkStatus:1};t.isSameDevice=(e,t)=>e.mac===t.mac&&e.productKey===t.productKey;t.merageBleLocalDevices=(e,i)=>(e.map(e=>{e.isBleOnline=!1,e.bleWorkStatus=0}),i.map(i=>{const s=e.find(e=>(0,t.isSameDevice)(e,i));s?(s.isBleOnline=!0,s.bleDeviceID=i.bleDeviceID,s.connectType=i.connectType,s.bleWorkStatus=i.bleWorkStatus):e.push(i)}),e);t.merageLanLocalDevices=(e,i)=>(e.map(e=>{e.isLanOnline=!1}),i.map(i=>{const s=e.find(e=>(0,t.isSameDevice)(e,i));s?s.isLanOnline=!0:e.push(i)}),e);t.BTDevice2GDevice=(e,i)=>{let s={productKey:"",mac:"",bleWorkStatus:0},r={did:"",productKey:"",mac:"",bleWorkStatus:0,connectType:"NONE",isBleOnline:!0,isLanOnline:!1,isOnline:!1,name:e.name,isBind:!1,bleDeviceID:e.deviceId,ctime:(new Date).getTime()};switch(e.communicationType){case"BLE_BROADCAST":try{n.default.log("parse BLE_BROADCAST");const t=o(a(e.advertisData));s.productKey=t.data.join(""),s.mac=t.mac,r.connectType="BLE_BROADCAST"}catch(e){}break;default:s=(0,t.advertisData2PkAndMac)(e.advertisData,i)}return r=Object.assign(Object.assign({},r),s),r};t.getFirstConnectType=(e,t)=>{if(!t)return e.isLanOnline?"LAN":e.isBleOnline?"BLE":"WAN";if("WAN"===t)return"WAN";switch(t){case"BLE":return e.isBleOnline?"BLE":"NONE";case"LAN":return e.isLanOnline?"LAN":"NONE"}return"WAN"};t.getProductInfoThroughPK=(e,t)=>t.find(t=>t.productKey===e);function o(e){if(25!=(e=e.slice(0,25)).length)throw new Error("数据不合法");const t=`${c(e[0])}${c(e[1])}`;if(e[2]!==(255&e.slice(3).reduce((e,t)=>e+t,0)))throw new Error("校验和不合法");const i=c(e[3]),s=e.slice(5,5+e[4]).map(e=>c(e));return{mac:t,cmd:parseInt(i,16),data:s}}function a(e){return Array.prototype.map.call(new Uint8Array(e),(function(e){return e}))}function c(e,t=2){return`${new Array(t).fill(0).join("")}${e.toString(16)}`.slice(-t)}t.mergeObject=(e,t)=>{for(let i in t)null!=t[i]&&""!==t[i]&&(e[i]=t[i]);return e},t.hex2ab=function(e){const t=[];for(let s=0;s<e.length;s+=2){var i=e.slice(s,s+2);t.push(parseInt(i,16))}return new Uint8Array(t)},t.parseBroadcastData=o,t.ab2numbers=a;let l=0;function d(e,t){let i=1,s=t;return e.map(e=>{const t=65535&(e^s);return s=i-t&65535,i<<=1,c(t,4)})}t.encrypt=d;function u(e,t,i){if(i.length>22)throw new Error("最大长度为22");const s=[...i,...new Array(22-i.length).fill(0)],r=255&i.reduce((e,t)=>e+t,0),o=(t>>4<<12)+(r>>4<<8)+((15&t)<<4)+(15&r),a=Array.from({length:11},(e,t)=>(s[2*t]<<8)+s[2*t+1]);return n.default.log("明文",c(e,4),c((t<<8)+r,4),a.map(e=>c(e,4))),[c(e,4),c((t<<8)+r,4),...d(a,o)].map(e=>`${e.slice(2)}${e.slice(0,2)}`)}t.convertToServiceUuids=({len:e=null,data:i=null,index:s=0,mac:n})=>{const r=null==e?Math.round(18*Math.random())+1:e,o=null==i?Array.from({length:r},e=>Math.round(255*Math.random())):i,a=[147,r,...o],c=u(n,(()=>{const e=l;return l=l+1&255,e})(),a);return[...new Set(c)].length!==c.length?(0,t.convertToServiceUuids)({len:r,data:o,index:s++,mac:n}):c},t.convertToUuids=u},function(e,t,i){var s,n,r,o,a,c;e.exports=(c=i(0),n=(s=c).lib,r=n.Base,o=n.WordArray,(a=s.x64={}).Word=r.extend({init:function(e,t){this.high=e,this.low=t}}),a.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:8*e.length},toX32:function(){for(var e=this.words,t=e.length,i=[],s=0;s<t;s++){var n=e[s];i.push(n.high),i.push(n.low)}return o.create(i,this.sigBytes)},clone:function(){for(var e=r.clone.call(this),t=e.words=this.words.slice(0),i=t.length,s=0;s<i;s++)t[s]=t[s].clone();return e}}),c)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getGlobalData=t.setGlobalData=void 0;const s={};t.setGlobalData=function(e,t){s[e]=t},t.getGlobalData=function(e){return s[e]}},function(e,t,i){var s,n,r,o,a,c,l,d;e.exports=(d=i(0),n=(s=d).lib,r=n.WordArray,o=n.Hasher,a=s.algo,c=[],l=a.SHA1=o.extend({_doReset:function(){this._hash=new r.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(e,t){for(var i=this._hash.words,s=i[0],n=i[1],r=i[2],o=i[3],a=i[4],l=0;l<80;l++){if(l<16)c[l]=0|e[t+l];else{var d=c[l-3]^c[l-8]^c[l-14]^c[l-16];c[l]=d<<1|d>>>31}var u=(s<<5|s>>>27)+a+c[l];u+=l<20?1518500249+(n&r|~n&o):l<40?1859775393+(n^r^o):l<60?(n&r|n&o|r&o)-1894007588:(n^r^o)-899497514,a=o,o=r,r=n<<30|n>>>2,n=s,s=u}i[0]=i[0]+s|0,i[1]=i[1]+n|0,i[2]=i[2]+r|0,i[3]=i[3]+o|0,i[4]=i[4]+a|0},_doFinalize:function(){var e=this._data,t=e.words,i=8*this._nDataBytes,s=8*e.sigBytes;return t[s>>>5]|=128<<24-s%32,t[14+(s+64>>>9<<4)]=Math.floor(i/4294967296),t[15+(s+64>>>9<<4)]=i,e.sigBytes=4*t.length,this._process(),this._hash},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),s.SHA1=o._createHelper(l),s.HmacSHA1=o._createHmacHelper(l),d.SHA1)},function(e,t,i){var s,n,r,o;e.exports=(s=i(0),r=(n=s).lib.Base,o=n.enc.Utf8,void(n.algo.HMAC=r.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=o.parse(t));var i=e.blockSize,s=4*i;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var n=this._oKey=t.clone(),r=this._iKey=t.clone(),a=n.words,c=r.words,l=0;l<i;l++)a[l]^=1549556828,c[l]^=909522486;n.sigBytes=r.sigBytes=s,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher,i=t.finalize(e);return t.reset(),t.finalize(this._oKey.clone().concat(i))}})))},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 o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=n(i(9));const o=new class{constructor(){this.data={},this.key="dataPointConfig",this.init=()=>s(this,void 0,void 0,(function*(){const e=(yield wx.getStorageSync(this.key))||"{}";let t={};try{t=JSON.parse(e)}catch(e){}this.data=t})),this.getConfigFile=e=>s(this,void 0,void 0,(function*(){var t;if(!this.data[e]){const i=`/app/datapoint?product_key=${e}`,s=yield(0,r.default)(`${i}`,{method:"GET"});if(!s.success||!(null===(t=s.data)||void 0===t?void 0:t.entities))return null;this.data[e]=s.data,wx.setStorageSync(this.key,JSON.stringify(this.data))}return this.data[e]})),this.getAttrItem=(e,t)=>s(this,void 0,void 0,(function*(){this.data[e]||(yield this.getConfigFile(e));for(let i in this.data[e].entities[0].attrs){const s=this.data[e].entities[0].attrs[i];if(s.name===t)return s}return null}))}};o.init(),t.default=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 o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=n(i(10)),o=n(i(5)),a=i(30),c=n(i(3));t.default=class{constructor(e,t,i,n,l){this.ssid="",this.bssid="",this.password="",this.specialProductKeys=[],this.disableSearchDevice=!1,this.specialProductKeySecrets=[],this.timeoutHandler=null,this.setDeviceOnboardingDeployRej=()=>{},this.cleanTimeout=()=>{this.disableSearchDevice=!0,this.timeoutHandler&&clearTimeout(this.timeoutHandler),this.timeoutHandler=null},this.stopDeviceOnboardingDeploy=()=>{this.setDeviceOnboardingDeployRej&&this.setDeviceOnboardingDeployRej({success:!1,err:o.default.GIZ_SDK_ONBOARDING_STOPPED}),this.cleanTimeout()},this.hasTimeoutHandler=e=>!!this.timeoutHandler&&(e&&e({success:!1,err:o.default.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING}),!0),this.handleTimeout=()=>{this.setDeviceOnboardingDeployRej&&this.setDeviceOnboardingDeployRej({success:!1,err:{errorCode:o.default.CONFIG_TIME_OUT,errorMessage:"time out"}}),this.timeoutHandler=null},this.searchDevice=({ssid:e,password:t})=>new Promise((i,n)=>{c.default.debug("GIZ_SDK: 开始大循环搜索设备");const l=()=>s(this,void 0,void 0,(function*(){var s;if(this.hasTimeoutHandler())try{const d=yield(0,a.checkDeviceRegister)({SSID:e,password:t,productKeys:this.specialProductKeys});if((null===(s=d.err)||void 0===s?void 0:s.errorCode)===o.default.GIZ_OPENAPI_TOKEN_INVALID.errorCode)return void n({success:!1,err:o.default.GIZ_OPENAPI_TOKEN_INVALID});d.err||0===d.data.length?(c.default.debug("GIZ_SDK: 大循环没有发现设备"),yield(0,r.default)(1500),!this.disableSearchDevice&&l()):(c.default.debug("GIZ_SDK: 大循环搜索到设备",d),i({success:!0,data:d.data}))}catch(e){yield(0,r.default)(3e3),!this.disableSearchDevice&&l()}}));l()}),this.initDeviceOnboardingDeploy=(e,t)=>{this.setDeviceOnboardingDeployRej=e,this.disableSearchDevice=!1},this.startTimeoutTimer=e=>{this.timeoutHandler=setTimeout(this.handleTimeout,1e3*e)},this.bindDevices=e=>(c.default.log("GIZ_SDK: start bind device"),new Promise((t,i)=>s(this,void 0,void 0,(function*(){const s=e.map(e=>{const t=this.specialProductKeys.findIndex(t=>e.productKey===t);if(-1===t)return;const i=this.specialProductKeySecrets[t];return(0,a.bindMac)({mac:e.mac,productKey:e.productKey,productSecret:i})});try{const n=yield Promise.all(s),r=e.filter((e,t)=>{const i=n[t];return i&&i.success});r.length>0?(c.default.log("GIZ_SDK: bind device success",r),t({success:!0,data:r})):(c.default.log("GIZ_SDK: bind device error",n),i({success:!1,data:e,err:o.default.GIZ_SDK_BIND_DEVICE_FAILED}))}catch(e){i(e)}})))),this.ssid=e,this.bssid=t,this.password=i,this.specialProductKeys=n,this.specialProductKeySecrets=l}}},function(e,t,i){"use strict";var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.BleHandle=t.errorCode=void 0,i(32);const n=s(i(33)),r=s(i(5));t.errorCode=r.default;const o=i(20);Object.defineProperty(t,"BleHandle",{enumerable:!0,get:function(){return o.BleHandle}}),t.default=n.default},function(e,t,i){"use strict";var s=this&&this.__decorate||function(e,t,i,s){var n,r=arguments.length,o=r<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(n=e[a])&&(o=(r<3?n(o):r>3?n(t,i,o):n(t,i))||o);return r>3&&o&&Object.defineProperty(t,i,o),o},n=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))},r=this&&this.__rest||function(e,t){var i={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(i[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(e);n<s.length;n++)t.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(e,s[n])&&(i[s[n]]=e[s[n]])}return i},o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.BleHandle=void 0;const a=o(i(3)),c=o(i(24)),l=i(25),d=o(i(61)),u=o(i(26)),h=o(i(4)),f=i(2),p=i(62),v=o(i(10)),g=i(12),y=i(28),_=o(i(29));function D(e){return function(t,i,s){const{value:n}=s;s.value=function(...t){return n.apply(this,t).then(i=>{var{_failureType_:s}=i,n=r(i,["_failureType_"]);return(0,p.reportEvent)({device:t[0],eventID:this.__event_id__,eventType:e,success:n.success}),Object.assign(Object.assign({},n),{_failureType_:e})})}}}class m extends _.default{set offlineThreshold(e){this._offlineThreshold=e}get offlineThreshold(){return this._offlineThreshold||1e4}constructor({pks:e=[],bleHandleParams:t={serviceUUIDSuffix:"abf0",characteristicUUIDSuffix:"abf7"},offlineThreshold:i}){super(),this.connectedList=[],this.connectingDevId=null,this.pks=[],this.listenDevOfflineTimer=null,this.methodQueue=Promise.resolve(),this.boradcastDataCache={},this.baseServices=["ABF8","ABF0","F0AB","F8AB"],this.tmpBleData="",this.tmpDataNum=0,this.disableScanFlag=!1,this.peripheralServer=null,this.isActive=!0,this._offlineThreshold=null,this.scanList=[],this.onBluetoothAdapterStateChange=e=>{a.default.debug("onBluetoothAdapterStateChange",e),e.available||(this.scanList=[],this.notifyDevices())},this.onAppShow=()=>{this.isActive=!0,this.scanList.map(e=>{e.ctime=Date.now()})},this.onAppHide=()=>{this.isActive=!1},this.listenDevOffline=()=>{this.listenDevOfflineTimer=setInterval(()=>{if(!this.isActive)return;const e=(new Date).getTime(),t=this.scanList.filter(t=>{const i=this.connectedList.find(e=>t.bleDeviceID==e.deviceId),s=this.connectingDevId===t.bleDeviceID;return!(!i&&!s)||("BLE_BROADCAST"===t.connectType?e-t.ctime<2*this.offlineThreshold:e-t.ctime<this.offlineThreshold)});t.length!==this.scanList.length&&(this.scanList=t,this.notifyDevices())},500)},this.openBluetoothAdapter=(e="central")=>new Promise((t,i)=>{wx.openBluetoothAdapter({mode:e,success:()=>{t({success:!0}),wx.onBLECharacteristicValueChange(this.handleOnBLECharacteristicValueChange)},fail:e=>{a.default.error("openBluetoothAdapter fail",new Error(JSON.stringify(e))),this.notifyError({errMsg:e.errMsg,errCode:-1}),i({success:!1,err:e})}})}),this.handleOnBLECharacteristicValueChange=e=>n(this,void 0,void 0,(function*(){if(!e.value)return;const t=(0,g.ab2hex)(e.value);try{const i=new h.default((0,f.hexStrint2byte)(t));this.tmpBleData=t,this.tmpDataNum=i.len-e.value.byteLength+4+Math.ceil(i.len.toString(2).length/8)}catch(i){this.tmpBleData&&(this.tmpBleData+=t,this.tmpDataNum-=e.value.byteLength)}this.tmpDataNum>0||!this.tmpBleData||(this.notiDeviceDataToSdk(e,this.tmpBleData),this.tmpBleData="",this.tmpDataNum=0)})),this.notiDeviceDataToSdk=(e,t)=>{this.listenerMap.GizBleDeviceData&&this.listenerMap.GizBleDeviceData.map(i=>{i(e,t)})},this.notifyError=e=>{this.listenerMap.GizBleError&&this.listenerMap.GizBleError.map(t=>{t(e)})},this.notifyDevices=()=>{this.listenerMap.GizBleDeviceList&&this.listenerMap.GizBleDeviceList.map(e=>{e(this.scanList)})},this.listenConnection=()=>{wx.onBLEConnectionStateChange(e=>{if(!1===e.connected){const t=this.connectedList.findIndex(t=>t.deviceId===e.deviceId);-1!==t&&(this.connectedList.splice(t,1),this.notifyDevices())}})},this.init=()=>n(this,void 0,void 0,(function*(){const{platform:e}=wx.getSystemInfoSync();yield this.openBluetoothAdapter(),"ios"===e&&(yield this.openBluetoothAdapter("peripheral"));try{this.peripheralServer=(yield wx.createBLEPeripheralServer()).server,a.default.info("GIZ_SDK: 广播初始化成功",this.peripheralServer)}catch(e){a.default.error("GIZ_SDK: 广播初始化失败",new Error(JSON.stringify(e)))}return yield this.getBluetoothAdapterState()})),this.checkPermission=()=>n(this,void 0,void 0,(function*(){if((yield wx.getSetting()).authSetting["scope.bluetooth"])return yield this.init();try{return yield wx.authorize({scope:"scope.bluetooth"}),yield this.init()}catch(e){a.default.log("授权失败",e),this.openBluetoothAdapter(),this.notifyError({errMsg:e.errMsg,errCode:-1})}})),this.getBluetoothAdapterState=()=>n(this,void 0,void 0,(function*(){a.default.log("getBluetoothAdapterState",yield wx.getBluetoothAdapterState());const e=yield wx.getBluetoothAdapterState(),{errMsg:t,available:i}=e,s=r(e,["errMsg","available"]);return{data:Object.assign({},s),err:(0,g.wrapErrorInfo)(t),success:i}})),this.getDeviceStatus=(e,t,i,s)=>n(this,void 0,void 0,(function*(){const n=yield d.default.pack(t,i,s);return n?yield this.write(e,(0,g.numberArray2Uint8Array)(n).buffer):{success:!1}})),this.updateDevice=e=>{const t=e.bleDeviceID,i=this.scanList.findIndex(e=>t==e.bleDeviceID);-1!==i&&(this.scanList[i]=e)},this.updateCtime=e=>{const t=e.deviceId,i=this.scanList.findIndex(e=>t==e.bleDeviceID);-1!==i&&(this.scanList[i].ctime=Date.now())},this.checkDeviceIsChange=(e,t)=>e.bleWorkStatus!==t.bleWorkStatus||e.name!==t.name||e.isBleOnline!==t.isBleOnline||e.isOnline!==t.isOnline,this.handleBluetoothDeviceFound=(e,t)=>{(0,g.unionBy)(e.devices,"deviceId").map(e=>{const{advertisData:i,deviceId:s,name:n,localName:r}=e,o=(0,g.ab2hex)(i);let a=null;try{a=(0,g.parseBroadcastData)((0,g.ab2numbers)(i))}catch(e){}const c=this.scanList.find(e=>e.bleDeviceID===s);if(a&&148===a.cmd){const t=(0,g.ab2hex)(i);if(this.boradcastDataCache[s]&&this.boradcastDataCache[s]===t)return!1;if(!c)return!1;this.boradcastDataCache[s]=(0,g.ab2hex)(i);const n=(0,l.padBoradcastData)(a.data.map(e=>parseInt(e,16)));return this.updateCtime(e),void this.notiDeviceDataToSdk(e,n)}if(a&&25===a.cmd){this.pks.find(e=>e===a.data.join(""))&&(e.communicationType="BLE_BROADCAST")}if(c){const i=(0,g.BTDevice2GDevice)(e,this.pks);if(i.productKey&&i.mac){const e=this.checkDeviceIsChange(i,c);i.ctime=Date.now(),this.updateDevice(i),e&&t(this.scanList)}}else{if(this.pks.some(e=>o.includes(e))){const i=(0,g.BTDevice2GDevice)(e,this.pks);i.productKey&&i.mac&&(this.scanList.push(i),t(this.scanList))}}})},this.startScan=(e,t=5e3,i)=>n(this,void 0,void 0,(function*(){return this.disableScanFlag?{scanList:[]}:new Promise(s=>n(this,void 0,void 0,(function*(){wx.onBluetoothDeviceFound(t=>{this.handleBluetoothDeviceFound(t,e)}),a.default.debug("GIZ_SDK: start scan",t),yield wx.startBluetoothDevicesDiscovery({services:i||this.baseServices,powerLevel:"high",allowDuplicatesKey:!0,interval:200}),t>0&&setTimeout(()=>{this.stopScan(),s({scanList:this.scanList})},t)})))})),this.stopScan=()=>n(this,void 0,void 0,(function*(){try{return yield wx.stopBluetoothDevicesDiscovery()}catch(e){return e}})),this.disableScan=()=>n(this,void 0,void 0,(function*(){this.disableScanFlag=!0;const e=yield wx.stopBluetoothDevicesDiscovery();return yield(0,v.default)(200),e})),this.enableScan=()=>{this.disableScanFlag=!1},this.connectDevice=e=>n(this,void 0,void 0,(function*(){try{return this.connectingDevId=e.bleDeviceID,this._connectDevice(e)}finally{this.connectingDevId=null}})),this.handleBindReq=e=>new Promise(t=>{const i=(s,n)=>{if(s.deviceId!==e)return;a.default.log("监听蓝牙特征值发生变化");const r=new c.default((0,f.hexStrint2byte)(n));this.removeEventListener("GizBleDeviceData",i),r.passcode?t({success:!0,data:r.passcode}):t({success:!1,data:""})};this.watchBleDevice(e,i)}),this.handleLoginReq=e=>new Promise(t=>{const i=(s,n)=>{if(s.deviceId!==e)return;a.default.log("设备回复LoginReq",n);const r=new u.default((0,f.hexStrint2byte)(n));this.removeEventListener("GizBleDeviceData",i),!0===r.result?t({success:!0,data:r.did}):t({success:!1,data:""})};this.watchBleDevice(e,i)}),this.watchBleDevice=(e,t)=>n(this,void 0,void 0,(function*(){const{serviceId:i,characteristicId:s,errMsg:n}=this.getTargetDevice(e);return n?{success:!1,message:n}:(yield wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:i,characteristicId:s,state:!0,type:"notification"}).catch(e=>this.notifyError(e)),a.default.log(`监听设备 ${e} 成功!`),this.addEventListener("GizBleDeviceData",t),{message:"ok",success:!0})})),this.writeBoradcast=(e,t)=>n(this,void 0,void 0,(function*(){const i=this.scanList.find(t=>t.bleDeviceID===e);if(!i)return{success:!1,message:"not found device"};this.boradcastTimer&&clearTimeout(this.boradcastTimer);try{this.peripheralServer.stopAdvertising({});const e=(0,g.convertToServiceUuids)({mac:i.mac,index:0,data:t,len:t.length});return this.peripheralServer.startAdvertising({advertiseRequest:{connectable:!0,serviceUuids:e},powerLevel:"high",success:e=>{a.default.debug("GIZ_SDK: startAdvertising success",e)},fail:e=>{a.default.error("GIZ_SDK: startAdvertising error",new Error(JSON.stringify(e)))}}),a.default.debug("GIZ_SDK: start adv",e),this.boradcastTimer=setTimeout(()=>{this.peripheralServer.stopAdvertising({}),this.boradcastTimer=null},1e3),{success:!0}}catch(e){return a.default.log("GIZ_SDK:",e),clearTimeout(this.boradcastTimer),{success:!1,message:"send cmd error"}}})),this.write=(e,t)=>n(this,void 0,void 0,(function*(){return this.methodQueue=this.methodQueue.then(()=>n(this,void 0,void 0,(function*(){a.default.log("app => dev:",(0,g.ab2hex)(t));const i=this.getTargetDevice(e);if(i.serviceId&&i.characteristicId){return yield(0,y.unpackWriteBLECharacteristicValue)(e,i.serviceId,i.characteristicId,t)}return{success:!1,message:"send cmd error"}}))),this.methodQueue})),this.disConnectDevice=e=>n(this,void 0,void 0,(function*(){this.removeDevById(e);const{errMsg:t}=yield wx.closeBLEConnection({deviceId:e}),i=this.scanList.find(t=>t.bleDeviceID===e);return i&&(i.ctime=Date.now(),this.updateDevice(i)),"closeBLEConnection:ok"===t?{err:t,success:!0}:{err:t,success:!1}})),this.removeDevById=e=>{const t=this.connectedList.findIndex(t=>t.deviceId===e);-1!==t&&this.connectedList.splice(t,1)},this.getTargetDevice=e=>{const t=this.connectedList.find(t=>e===t.deviceId);return t||{errMsg:"Unable get this device,maybe you forgot to connect it."}},this.destory=()=>{this.listenDevOfflineTimer&&clearInterval(this.listenDevOfflineTimer),wx.offAppShow(this.onAppShow),wx.offAppHide(this.onAppHide),wx.offBluetoothAdapterStateChange(this.onBluetoothAdapterStateChange)};const{serviceUUIDSuffix:s}=t;this.serviceUUIDSuffix=s,this.pks=e,this.offlineThreshold=i,this.listenDevOffline(),this.listenConnection(),wx.onAppShow(this.onAppShow),wx.onAppHide(this.onAppHide),wx.onBluetoothAdapterStateChange(this.onBluetoothAdapterStateChange)}connectDeviceBle(e){var t;return n(this,void 0,void 0,(function*(){try{yield this.disableScan();const t=yield(0,y.retryConnect)(e.bleDeviceID);this.enableScan(),a.default.debug("connect res",t)}catch(e){if(a.default.error("GIZ_SDK: createBLEConnection error",new Error(JSON.stringify(e))),"createBLEConnection:fail:already connect"!==(null==e?void 0:e.errMsg))return this.notifyError(e),{success:!1,message:null==e?void 0:e.errMsg}}const i=yield wx.getBLEDeviceServices({deviceId:e.bleDeviceID}).catch(e=>this.notifyError(e)),s=null===(t=null==i?void 0:i.services.find(e=>e.isPrimary&&e.uuid.toLowerCase().includes(this.serviceUUIDSuffix)))||void 0===t?void 0:t.uuid;if(!s)return{message:"can not find valid serviceId",success:!1};const n=yield wx.getBLEDeviceCharacteristics({deviceId:e.bleDeviceID,serviceId:s}).catch(e=>this.notifyError(e));return{success:!0,data:{serviceId:s,characteristicId:null==n?void 0:n.characteristics[0].uuid}}}))}connectDeviceBindRequest(e){return n(this,void 0,void 0,(function*(){this.write(e.bleDeviceID,(0,g.numberArray2Uint8Array)(c.default.pack()).buffer);const t=yield this.handleBindReq(e.bleDeviceID);return a.default.log("handleBindReq",t),t.success||(yield wx.closeBLEConnection({deviceId:e.bleDeviceID})),t}))}connectDeviceLoginRequest(e,t){return n(this,void 0,void 0,(function*(){this.write(e.bleDeviceID,(0,g.numberArray2Uint8Array)(u.default.pack({passcode:t})).buffer);const i=yield this.handleLoginReq(e.bleDeviceID).catch(e=>this.notifyError(e));return{success:!!(null==i?void 0:i.success),message:"ok"}}))}_connectDevice(e){return n(this,void 0,void 0,(function*(){const t=yield this.connectDeviceBle(e);if(!t.success)return t;const{serviceId:i,characteristicId:s}=t.data;this.connectedList.every(t=>t.deviceId!==e.bleDeviceID)&&this.connectedList.push({deviceId:e.bleDeviceID,serviceId:i,characteristicId:s}),yield wx.notifyBLECharacteristicValueChange({deviceId:e.bleDeviceID,serviceId:i,characteristicId:s,state:!0,type:"notification"}).catch(e=>this.notifyError(e));const n=yield this.connectDeviceBindRequest(e);return n.success?yield this.connectDeviceLoginRequest(e,n.data):n}))}}s([D("BleDeviceConnectEnd")],m.prototype,"connectDeviceBle",null),s([D("BleDeviceConnectBind")],m.prototype,"connectDeviceBindRequest",null),s([D("BleDeviceConnectLogin")],m.prototype,"connectDeviceLoginRequest",null),s([function(e,t,i){const{value:s}=i;i.value=function(...e){const t=Object.create(this);return t.__event_id__=function(){let e=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){let i=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?i:3&i|8).toString(16)}))}(),(0,p.reportEvent)({device:e[0],eventID:t.__event_id__,eventType:"BleDeviceConnectStart",success:!0}),s.apply(t,e).then(i=>{var{_failureType_:s}=i,n=r(i,["_failureType_"]);return(0,p.reportEvent)(Object.assign({device:e[0],eventID:t.__event_id__,eventType:"BleDeviceConnectFinish",success:n.success},n.success?{}:{failureType:s})),n})}}],m.prototype,"_connectDevice",null),t.BleHandle=m},function(e,t,i){var s;e.exports=(s=i(0),function(e){var t=s,i=t.lib,n=i.WordArray,r=i.Hasher,o=t.algo,a=[],c=[];!function(){function t(t){for(var i=e.sqrt(t),s=2;s<=i;s++)if(!(t%s))return!1;return!0}function i(e){return 4294967296*(e-(0|e))|0}for(var s=2,n=0;n<64;)t(s)&&(n<8&&(a[n]=i(e.pow(s,.5))),c[n]=i(e.pow(s,1/3)),n++),s++}();var l=[],d=o.SHA256=r.extend({_doReset:function(){this._hash=new n.init(a.slice(0))},_doProcessBlock:function(e,t){for(var i=this._hash.words,s=i[0],n=i[1],r=i[2],o=i[3],a=i[4],d=i[5],u=i[6],h=i[7],f=0;f<64;f++){if(f<16)l[f]=0|e[t+f];else{var p=l[f-15],v=(p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3,g=l[f-2],y=(g<<15|g>>>17)^(g<<13|g>>>19)^g>>>10;l[f]=v+l[f-7]+y+l[f-16]}var _=s&n^s&r^n&r,D=(s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22),m=h+((a<<26|a>>>6)^(a<<21|a>>>11)^(a<<7|a>>>25))+(a&d^~a&u)+c[f]+l[f];h=u,u=d,d=a,a=o+m|0,o=r,r=n,n=s,s=m+(D+_)|0}i[0]=i[0]+s|0,i[1]=i[1]+n|0,i[2]=i[2]+r|0,i[3]=i[3]+o|0,i[4]=i[4]+a|0,i[5]=i[5]+d|0,i[6]=i[6]+u|0,i[7]=i[7]+h|0},_doFinalize:function(){var t=this._data,i=t.words,s=8*this._nDataBytes,n=8*t.sigBytes;return i[n>>>5]|=128<<24-n%32,i[14+(n+64>>>9<<4)]=e.floor(s/4294967296),i[15+(n+64>>>9<<4)]=s,t.sigBytes=4*i.length,this._process(),this._hash},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=r._createHelper(d),t.HmacSHA256=r._createHmacHelper(d)}(Math),s.SHA256)},function(e,t,i){var s;e.exports=(s=i(0),i(13),function(){var e=s,t=e.lib.Hasher,i=e.x64,n=i.Word,r=i.WordArray,o=e.algo;function a(){return n.create.apply(n,arguments)}var c=[a(1116352408,3609767458),a(1899447441,602891725),a(3049323471,3964484399),a(3921009573,2173295548),a(961987163,4081628472),a(1508970993,3053834265),a(2453635748,2937671579),a(2870763221,3664609560),a(3624381080,2734883394),a(310598401,1164996542),a(607225278,1323610764),a(1426881987,3590304994),a(1925078388,4068182383),a(2162078206,991336113),a(2614888103,633803317),a(3248222580,3479774868),a(3835390401,2666613458),a(4022224774,944711139),a(264347078,2341262773),a(604807628,2007800933),a(770255983,1495990901),a(1249150122,1856431235),a(1555081692,3175218132),a(1996064986,2198950837),a(2554220882,3999719339),a(2821834349,766784016),a(2952996808,2566594879),a(3210313671,3203337956),a(3336571891,1034457026),a(3584528711,2466948901),a(113926993,3758326383),a(338241895,168717936),a(666307205,1188179964),a(773529912,1546045734),a(1294757372,1522805485),a(1396182291,2643833823),a(1695183700,2343527390),a(1986661051,1014477480),a(2177026350,1206759142),a(2456956037,344077627),a(2730485921,1290863460),a(2820302411,3158454273),a(3259730800,3505952657),a(3345764771,106217008),a(3516065817,3606008344),a(3600352804,1432725776),a(4094571909,1467031594),a(275423344,851169720),a(430227734,3100823752),a(506948616,1363258195),a(659060556,3750685593),a(883997877,3785050280),a(958139571,3318307427),a(1322822218,3812723403),a(1537002063,2003034995),a(1747873779,3602036899),a(1955562222,1575990012),a(2024104815,1125592928),a(2227730452,2716904306),a(2361852424,442776044),a(2428436474,593698344),a(2756734187,3733110249),a(3204031479,2999351573),a(3329325298,3815920427),a(3391569614,3928383900),a(3515267271,566280711),a(3940187606,3454069534),a(4118630271,4000239992),a(116418474,1914138554),a(174292421,2731055270),a(289380356,3203993006),a(460393269,320620315),a(685471733,587496836),a(852142971,1086792851),a(1017036298,365543100),a(1126000580,2618297676),a(1288033470,3409855158),a(1501505948,4234509866),a(1607167915,987167468),a(1816402316,1246189591)],l=[];!function(){for(var e=0;e<80;e++)l[e]=a()}();var d=o.SHA512=t.extend({_doReset:function(){this._hash=new r.init([new n.init(1779033703,4089235720),new n.init(3144134277,2227873595),new n.init(1013904242,4271175723),new n.init(2773480762,1595750129),new n.init(1359893119,2917565137),new n.init(2600822924,725511199),new n.init(528734635,4215389547),new n.init(1541459225,327033209)])},_doProcessBlock:function(e,t){for(var i=this._hash.words,s=i[0],n=i[1],r=i[2],o=i[3],a=i[4],d=i[5],u=i[6],h=i[7],f=s.high,p=s.low,v=n.high,g=n.low,y=r.high,_=r.low,D=o.high,m=o.low,b=a.high,S=a.low,w=d.high,B=d.low,k=u.high,I=u.low,C=h.high,A=h.low,x=f,T=p,L=v,E=g,P=y,O=_,M=D,H=m,K=b,N=S,G=w,R=B,U=k,z=I,j=C,W=A,F=0;F<80;F++){var Z,V,$=l[F];if(F<16)V=$.high=0|e[t+2*F],Z=$.low=0|e[t+2*F+1];else{var X=l[F-15],q=X.high,J=X.low,Y=(q>>>1|J<<31)^(q>>>8|J<<24)^q>>>7,Q=(J>>>1|q<<31)^(J>>>8|q<<24)^(J>>>7|q<<25),ee=l[F-2],te=ee.high,ie=ee.low,se=(te>>>19|ie<<13)^(te<<3|ie>>>29)^te>>>6,ne=(ie>>>19|te<<13)^(ie<<3|te>>>29)^(ie>>>6|te<<26),re=l[F-7],oe=re.high,ae=re.low,ce=l[F-16],le=ce.high,de=ce.low;V=(V=(V=Y+oe+((Z=Q+ae)>>>0<Q>>>0?1:0))+se+((Z+=ne)>>>0<ne>>>0?1:0))+le+((Z+=de)>>>0<de>>>0?1:0),$.high=V,$.low=Z}var ue,he=K&G^~K&U,fe=N&R^~N&z,pe=x&L^x&P^L&P,ve=T&E^T&O^E&O,ge=(x>>>28|T<<4)^(x<<30|T>>>2)^(x<<25|T>>>7),ye=(T>>>28|x<<4)^(T<<30|x>>>2)^(T<<25|x>>>7),_e=(K>>>14|N<<18)^(K>>>18|N<<14)^(K<<23|N>>>9),De=(N>>>14|K<<18)^(N>>>18|K<<14)^(N<<23|K>>>9),me=c[F],be=me.high,Se=me.low,we=j+_e+((ue=W+De)>>>0<W>>>0?1:0),Be=ye+ve;j=U,W=z,U=G,z=R,G=K,R=N,K=M+(we=(we=(we=we+he+((ue+=fe)>>>0<fe>>>0?1:0))+be+((ue+=Se)>>>0<Se>>>0?1:0))+V+((ue+=Z)>>>0<Z>>>0?1:0))+((N=H+ue|0)>>>0<H>>>0?1:0)|0,M=P,H=O,P=L,O=E,L=x,E=T,x=we+(ge+pe+(Be>>>0<ye>>>0?1:0))+((T=ue+Be|0)>>>0<ue>>>0?1:0)|0}p=s.low=p+T,s.high=f+x+(p>>>0<T>>>0?1:0),g=n.low=g+E,n.high=v+L+(g>>>0<E>>>0?1:0),_=r.low=_+O,r.high=y+P+(_>>>0<O>>>0?1:0),m=o.low=m+H,o.high=D+M+(m>>>0<H>>>0?1:0),S=a.low=S+N,a.high=b+K+(S>>>0<N>>>0?1:0),B=d.low=B+R,d.high=w+G+(B>>>0<R>>>0?1:0),I=u.low=I+z,u.high=k+U+(I>>>0<z>>>0?1:0),A=h.low=A+W,h.high=C+j+(A>>>0<W>>>0?1:0)},_doFinalize:function(){var e=this._data,t=e.words,i=8*this._nDataBytes,s=8*e.sigBytes;return t[s>>>5]|=128<<24-s%32,t[30+(s+128>>>10<<5)]=Math.floor(i/4294967296),t[31+(s+128>>>10<<5)]=i,e.sigBytes=4*t.length,this._process(),this._hash.toX32()},clone:function(){var e=t.clone.call(this);return e._hash=this._hash.clone(),e},blockSize:32});e.SHA512=t._createHelper(d),e.HmacSHA512=t._createHmacHelper(d)}(),s.SHA512)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){return new Promise((i,s)=>{wx.request(Object.assign(Object.assign({url:e,timeout:3e3},t),{success:e=>{i(e)},fail:e=>{s(e)}}))})}},function(e,t,i){"use strict";var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const n=s(i(4)),r=i(2);class o extends n.default{constructor(e){super(e),this.passcode="";let t=0;const i=parseInt((0,r.arrayToString)(this.content.slice(t,t+2)),16);t+=2;let s="";this.content.slice(t,t+i).map(e=>{s+=String.fromCharCode(e)}),this.passcode=s}}o.pack=()=>[0,0,0,3,3,0,0,6],t.default=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 o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.formatBinary=t.formatEnum=t.padBoradcastData=t.unpack=t.pack=void 0;const r=n(i(17)),o=i(2),a=e=>-1!==e.indexOf("uint")?"number":e,c=(e,t,i)=>{let s="";switch(e){case"bool":s=`${!0===t[i.name]?1:0}`;break;case"enum":{let e=t[i.name];"number"==typeof e&&(e=i.enum[e]);const n=i.enum.findIndex(t=>e===t),r=-1===n?0:n;s=(0,o.fillString)(r.toString(2),i.position.len);break}case"number":{let e=0;null!=t[i.name]&&(e=Math.round((t[i.name]-i.uint_spec.addition)/i.uint_spec.ratio)),s=(0,o.fillString)(e.toString(2),8*i.position.len);break}case"binary":{let e=t[i.name]||"";e instanceof Array&&(e=(0,o.arrayToString)(e));const n=(0,o.fillString)(e,2*i.position.len,!0);for(let e=0;e<n.length/2;e++){const t=2*e,i=n[t]+n[t+1];s+=(0,o.fillString)(parseInt(i,16).toString(2),8)}break}}const n=i.position.len*("byte"===i.position.unit?8:1)-s.length;if(n>0)for(let e=0;e<n;e++)s=`0${s}`;return`${s}`},l=(e,t,i)=>{switch(e){case"bool":return"1"===t;case"enum":return parseInt(t,2);case"binary":{const e=i.position.len;let s="";for(let e=0;e<t.length/8;e++){const i=8*e,n=t.substring(i,i+8);s+=(0,o.fillString)(parseInt(n,2).toString(16),2)}return(0,o.fillString)(s,2*e,!0)}case"number":return parseInt(t,2)/(1/i.uint_spec.ratio)+i.uint_spec.addition;default:return""}},d=({config:e,data:t,isAdaptiveDatapoint:i})=>{let s=e;const n=[0,0,0,3],r=[0],l=[0,147],d=[0,0,0,0];let h=[1],f="";const p=[];i||(s=s.filter(e=>"status_writable"===e.type)),s.map(e=>{void 0!==t[e.name]?(f=`1${f}`,p.push(e)):f=`0${f}`}),i&&(h=[17],s=p),f=(0,o.fillString)(f,8*Math.ceil(f.length/8));for(let e=0;e<f.length/8;e++)h.push(parseInt(f.substring(8*e,8*(e+1)),2));let v,g="";try{v=s[0]}catch(e){}s.map(e=>{"bool"===e.data_type||"enum"===e.data_type?(v.type!==e.type&&(h=h.concat((0,o.completeBlock)(g)),g=""),g=((e,i)=>{const s=a(e.data_type);return i=c(s,t,e)+i})(e,g)):(g.length>0&&(h=h.concat((0,o.completeBlock)(g)),g=""),h=((e,i)=>{const s=a(e.data_type),n=c(s,t,e);return i=i.concat((0,o.completeBlock)(n))})(e,h)),v=e}),g.length>0&&(h=h.concat((0,o.completeBlock)(g)),g="");const y=r.concat(l).concat(d).concat(h),_=u(y);return n.push(..._),{data:n.concat(y),raw:{header:[0,0,0,3],flag:r,len:_,headerCmd:l,sn:d,cmd:h}}};function u(e){const t=e.length.toString(2),i=[];for(let e=t.length;e>0;e-=7){const s=e-7,n=e;let r=t.substring(s,n);r=`${s>0?"1":"0"}${r}`,i.push(parseInt(r,2))}return i}function h(e,t){return e===t||"ALL"===e}function f({attrs:e,activeAttrs:t,flagString:i,cmdData:s,accumulate:n}){let r=0,o={},a=0;return["status_writable","status_readonly","alert","fault"].map(c=>{const l=e.filter(e=>h(c,e.type)).length,{cmd:d,cmdDataLength:u}=p({type:c,attrs:e.slice(a,a+l),activeAttrs:t,flagString:i.substring(a,a+l),cmdData:s.slice(r,s.length),accumulate:n});return r+=u,o=Object.assign(Object.assign({},o),d),a+=l,null}),o}function p({type:e,attrs:t,activeAttrs:i,cmdData:s,flagString:n,accumulate:r}){let c=0,d=0,u=0;return i.map(t=>{if(h(e,t.type)){const e=t.position.len*("bit"===t.position.unit?1:8);"bool"===t.data_type||"enum"===t.data_type?d+=e:u+=e}return null}),c=Math.ceil(u/8)+Math.ceil(d/8),{cmdDataLength:c,cmd:function({attrs:e,flagString:t,boolEnumLength:i,cmdData:s,accumulate:n}){const r={};let c=0;for(let d=0;d<t.length;d++)if(e[d]&&"1"===t[d]){const{data_type:t,position:{len:n}}=e[d];let u="";if("bool"===t||"enum"===t){let e="";s.slice(0,i).map(t=>(e+=(0,o.fillString)(t.toString(2),8),null));const t=e.length-c;u=e.substring(t-n,t),c+=n}else{const e=i,t=i+n;s.slice(e,t).map(e=>(u+=(0,o.fillString)(e.toString(2),8),null)),i+=n}const h=a(t);r[e[d].name]=l(h,u,e[d])}else if(n){const t=e[d]||{position:{len:0}};"byte"===t.position.unit?i+=t.position.len:c+=t.position.len}return r}({attrs:t,flagString:n,boolEnumLength:Math.ceil(d/8),cmdData:s,accumulate:r})}}t.unpack=(e,t)=>s(void 0,void 0,void 0,(function*(){const i=yield r.default.getConfigFile(t);if(i){const s=function({config:e=[],data:t}){let i,s,n="";const r={header:(0,o.arrayToString)(t.slice(0,4)),flag:"",len:"",cmd:"",sn:"",action:"",payload:""},a=e;let c=(0,o.checkHeader)(t);if(!1===c)return;const l=t.slice(c,t.length),d=(0,o.getProtocolLen)(l);if(c+=d,r.len=(0,o.arrayToString)(l.slice(0,d)),c+=1,r.flag=(0,o.arrayToString)(t.slice(c-1,c)),c+=2,r.cmd=(0,o.arrayToString)(t.slice(c-2,c)),r.sn="",("0093"===r.cmd||"0094"===r.cmd)&&(c+=4,r.sn=(0,o.arrayToString)(t.slice(c-4,c)),"01"===r.flag)){c+=2,c+=parseInt((0,o.arrayToString)(t.slice(c-2,c)),16)}c+=1,r.action=(0,o.arrayToString)(t.slice(c-1,c)),i=parseInt(r.action,16),r.payload=(0,o.arrayToString)(t.slice(c,t.length));const u=t.slice(c,t.length);let h=a;1===i&&(h=a.filter(e=>"status_writable"===e.type));const v=JSON.parse(JSON.stringify(h)),g=Math.ceil(h.length/8);let y=u.slice(0,g),_=u.slice(g,u.length);3!==i&&4!==i||(y=new Array(g).fill(255),_=u);let D="";y.map(e=>(D+=(0,o.fillString)(e.toString(2),8),null)),i>=17&&i<=20&&(h=h.filter((e,t)=>{const i=D.length-1-t;return"1"===D[i]})),"0090"===r.cmd||"0093"===r.cmd?(n="App 透传数据到 Dev",s="APP2DEV"):"0091"===r.cmd||"0094"===r.cmd?(n="Dev 收到控制命令后应答到 App",s="DEV2APP"):(n="非法数据",s="UNKNOW");let m={};switch(i){case 1:n="App 下发数据到 Dev",m=f({attrs:v,activeAttrs:h,flagString:D.split("").reverse().join(""),cmdData:_,accumulate:!0});break;case 2:return n="App 下发查询指令到 Dev",{kvData:null,rawData:r,message:n,messageType:s};case 3:n="Dev 回复查询指令到 App",m=f({attrs:v,activeAttrs:h,flagString:D.split("").reverse().join(""),cmdData:_,accumulate:!0});break;case 4:n="Dev 上报状态到 App",m=f({attrs:v,activeAttrs:h,flagString:D.split("").reverse().join(""),cmdData:_,accumulate:!0});break;case 5:return n="App 透传数据到 Dev",{kvData:null,rawData:r,message:n,messageType:s};case 6:return n="Dev 透传数据到 App",{kvData:null,rawData:r,message:n,messageType:s};case 7:return n="App 下发控制子设备",{kvData:null,rawData:r,message:n,messageType:s};case 8:return n="App 读取子设备数据",{kvData:null,rawData:r,message:n,messageType:s};case 9:return n="Dev 中控回复ACK",{kvData:null,rawData:r,message:n,messageType:s};case 10:return n="子设备上报状态到 App",{kvData:null,rawData:r,message:n,messageType:s};case 11:return n="App 下发添加子设备指令",{kvData:null,rawData:r,message:n,messageType:s};case 12:return n="App 下发删除子设备",{kvData:null,rawData:r,message:n,messageType:s};case 13:return n="App 获取中控子设备列表",{kvData:null,rawData:r,message:n,messageType:s};case 14:return n="中控响应字设备查询到 App",{kvData:null,rawData:r,message:n,messageType:s};case 15:return n="子设备列表变更通知到 App",{kvData:null,rawData:r,message:n,messageType:s};case 16:return n="Dev 子设备上下线状态变更通知",{kvData:null,rawData:r,message:n,messageType:s};case 17:n="App 下发变长数据到 Dev",m=p({type:"ALL",attrs:v,activeAttrs:h,flagString:D.split("").reverse().join(""),cmdData:_}).cmd;break;case 18:return n="App 下发变长查询到 Dev",{kvData:null,rawData:r,message:n,messageType:s};case 19:n="Dev 变长回复查询指令到 App",m=p({type:"ALL",attrs:v,activeAttrs:h,flagString:D.split("").reverse().join(""),cmdData:_}).cmd;break;case 20:n="Dev 变长上报状态到 App",m=p({type:"ALL",attrs:v,activeAttrs:h,flagString:D.split("").reverse().join(""),cmdData:_}).cmd;break;case 114:return n="App 向网关发送数据",{kvData:null,rawData:r,message:n,messageType:s};case 115:return n="Dev 网关上报数据到 App",{kvData:null,rawData:r,message:n,messageType:s};case 116:return n="App 通知网关删除子设备",{kvData:null,rawData:r,message:n,messageType:s};default:return{kvData:null,rawData:r,message:n,messageType:s}}return 0===a.length?{kvData:null,rawData:r,message:n,messageType:s}:{kvData:m,rawData:r,message:n,messageType:s}}({config:(yield i).entities[0].attrs,data:e});return s.kvData&&(s.kvData=yield v(null==s?void 0:s.kvData,t,"object")),s}return null}));t.pack=(e,t)=>s(void 0,void 0,void 0,(function*(){const i=yield r.default.getConfigFile(t);if(i){const t="var_len"===i.protocolType;return d({data:e,config:(yield i).entities[0].attrs,isAdaptiveDatapoint:t})}return null}));t.padBoradcastData=e=>{const t=[0].concat([0,147]).concat([0,0,0,0]).concat(e),i=u(t);return(0,o.arrayToString)([0,0,0,3].concat(i).concat(t))};t.formatEnum=(e,t,i)=>s(void 0,void 0,void 0,(function*(){for(let s in e){const n=yield r.default.getAttrItem(t,s);if(n&&"enum"===n.data_type){if("int"===i&&"string"==typeof e[s]){const t=n.enum.findIndex(t=>t===e[s]);e[s]=t||0}"string"===i&&"number"==typeof e[s]&&(e[s]=n.enum[e[s]])}}return e}));const v=(e,t,i)=>s(void 0,void 0,void 0,(function*(){for(let s in e){const n=yield r.default.getAttrItem(t,s);n&&"binary"===n.data_type&&("object"===i&&"string"==typeof e[s]&&(e[s]=(0,o.hexStrint2byte)(e[s])),"string"===i&&"object"==typeof e[s]&&(e[s]=(0,o.arrayToString)(e[s])))}return e}));t.formatBinary=v},function(e,t,i){"use strict";var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const n=s(i(4)),r=i(2);class o extends n.default{constructor(e){super(e),this.result=!1,this.didLength=0,this.did="";let t=0;if(this.result=0===this.content[0],t++,1===this.flag[0]){this.didLength=parseInt((0,r.arrayToString)(this.content.slice(t,t+2)),16),t+=2;let e="";this.content.slice(t,this.content.length).map(t=>{e+=String.fromCharCode(t)}),this.did=e}}}o.pack=({passcode:e})=>{let t=[0];const i=(0,r.hexStrint2byte)((0,r.fillString)(e.length.toString(16),4)),s=(0,r.string2Bytes)(e),n=[0].concat([0,8]).concat(i).concat(s);return t=(0,r.hexStrint2byte)(n.length.toString(16)),[0,0,0,3].concat(t).concat(n)},t.default=o},function(e){e.exports=JSON.parse('{"name":"mini_program_gizwits_sdk","version":"3.2.31","description":"修正flag转换","main":"./dist/index.js","scripts":{"test":"node_modules/mocha/bin/_mocha -r ts-node/register tests/**/*.spec.ts -file ./tests/setup-wx.js -timeout 60s","testBle":"node_modules/mocha/bin/_mocha -r ts-node/register tests/utils/randomCode.spec.ts -file ./tests/setup-wx.js -timeout 60s","build":"rm -rf ./dist && webpack","release":"npm run build && release-it","cover":"istanbul cover node_modules/mocha/bin/_mocha -- -r ts-node/register tests/**/*.spec.ts -file ./tests/setup-wx.js -timeout 60s","coveralls":"npm run cover -- --report lcovonly && cat ./coverage/lcov.info | coveralls"},"repository":{"type":"git","url":"git+https://github.com/gizwits/mini_program_gizwits_sdk.git"},"keywords":["gizwits","miniprogram","sdk"],"devDependencies":{"@babel/plugin-transform-modules-commonjs":"^7.12.1","@release-it/conventional-changelog":"^2.0.0","@types/chai":"^4.2.11","@types/crypto-js":"^4.0.2","@types/mocha":"^7.0.2","@types/node":"^12.12.14","@types/sinon":"^10.0.6","chai":"^4.2.0","coveralls":"^3.0.11","istanbul":"^1.1.0-alpha.1","miniprogram-api-typings":"^3.9.0","mocha":"^7.1.1","release-it":"^14.2.2","sinon":"^9.2.4","ts-loader":"^6.2.2","ts-node":"^8.8.1","typescript":"^4.9.5","uglifyjs-webpack-plugin":"^2.2.0","webpack":"^4.42.1","webpack-bundle-analyzer":"^4.5.0","webpack-cli":"^3.3.11"},"author":"gizwits","license":"ISC","bugs":{"url":"https://github.com/gizwits/mini_program_gizwits_sdk/issues"},"homepage":"https://github.com/gizwits/mini_program_gizwits_sdk#readme","dependencies":{"crypto-js":"^4.1.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 o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.unpackWriteBLECharacteristicValue=t.writeBLECharacteristicValue=t.notifyBLECharacteristicValueChange=t.getBLEDeviceCharacteristics=t.getBLEDeviceServices=t.createBLEConnection=t.getBluetoothDevices=t.startBluetoothDevicesDiscovery=t.getBluetoothAdapterState=t.closeBluetoothAdapter=t.openBluetoothAdapter=t.retryConnect=void 0;const r=n(i(3)),o=n(i(10));function a(e,t){return new Promise((i,s)=>{wx.createBLEConnection({deviceId:e,timeout:t,success:e=>i(e),fail:e=>{-1===e.errCode?i(e):s(e)}})})}function c(e,t,i,s){return new Promise(n=>{wx.writeBLECharacteristicValue({deviceId:e,serviceId:t,characteristicId:i,value:s,complete:n})})}t.retryConnect=function(e,t=1e4){return s(this,void 0,void 0,(function*(){let i={success:!1};for(let s=0;s<5;s++)try{return console.debug("start createBLEConnection"),yield a(e,t)}catch(e){i=e,console.debug("createBLEConnection error retry"),yield(0,o.default)(1e3)}return i}))},t.openBluetoothAdapter=function(){return new Promise((e,t)=>{wx.openBluetoothAdapter({success:e,fail:t})})},t.closeBluetoothAdapter=function(){return new Promise((e,t)=>{wx.closeBluetoothAdapter({success:e,fail:t})})},t.getBluetoothAdapterState=function(){return new Promise((e,t)=>{wx.getBluetoothAdapterState({success:e,fail:t})})},t.startBluetoothDevicesDiscovery=function(e=!0){return new Promise((t,i)=>{wx.startBluetoothDevicesDiscovery({success:t,fail:i,allowDuplicatesKey:e,powerLevel:"high",interval:200})})},t.getBluetoothDevices=function(){return new Promise((e,t)=>{wx.getBluetoothDevices({success:({devices:t})=>e(t),fail:t})})},t.createBLEConnection=a,t.getBLEDeviceServices=function(e){return new Promise((t,i)=>{wx.getBLEDeviceServices({deviceId:e,success:({services:e})=>t(e),fail:i})})},t.getBLEDeviceCharacteristics=function(e,t){return new Promise((i,s)=>{wx.getBLEDeviceCharacteristics({deviceId:e,serviceId:t,success:({characteristics:e})=>i(e),fail:s})})},t.notifyBLECharacteristicValueChange=function(e,t,i,s=!0){return new Promise((n,r)=>{wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:t,characteristicId:i,state:s,success:n,fail:r})})},t.writeBLECharacteristicValue=c,t.unpackWriteBLECharacteristicValue=function(e,t,i,n){if(!n||0===n.byteLength)throw new Error("value is empty");return new Promise((a,l)=>s(this,void 0,void 0,(function*(){let s,d=0,u=n.byteLength;for(;u>0;){yield(0,o.default)(30);const a=n.slice(d,d+20);if(d+=20,u-=20,s=yield c(e,t,i,a),r.default.log("unpackWriteBLECharacteristicValue",d/20,s),0!==s.errCode)break}0!==s.errCode?l(s):a(s)})))}},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 o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});t.default=class{constructor(){this.listenerMap={},this.addEventListener=(e,t)=>s(this,void 0,void 0,(function*(){return this.listenerMap[e]||(this.listenerMap[e]=[]),-1===this.listenerMap[e].indexOf(t)&&this.listenerMap[e].push(t),{success:!0}})),this.removeEventListener=(e,t)=>{if(this.listenerMap[e]){const i=this.listenerMap[e].indexOf(t);if(-1!==i)return this.listenerMap[e].splice(i,1),{success:!0}}return{success:!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 o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.editBindInfo=t.safeRegister=t.checkDeviceRegister=t.unbindDevice=t.bindMac=t.getBindingList=void 0;const r=n(i(9)),o=n(i(68)),a=i(69),c=i(11);t.getBindingList=()=>s(void 0,void 0,void 0,(function*(){const e=yield(0,r.default)("/app/bindings?show_disabled=0&limit=1000&skip=0",{method:"GET"});if(e.success){return{success:!0,data:e.data.devices.map(e=>({productKey:e.product_key,mac:e.mac,did:e.did,host:e.host,port_s:e.port_s,port:e.port,ws_port:e.ws_port,wss_port:e.wss_port,passcode:e.passcode,isBleOnline:!1,isLanOnline:!1,connectType:"NONE",name:e.dev_alias,isBind:!0,isOnline:e.is_online}))}}return{success:!1,err:e.err}})),t.bindMac=function({mac:e,productKey:t,productSecret:i,alias:n,beOwner:o}){return s(this,void 0,void 0,(function*(){const s={mac:e,product_key:t,dev_alias:n,set_owner:o},{Signature:c,timestamp:l}=(0,a.psKeySign)(i);return yield(0,r.default)("/app/bind_mac",{method:"POST",data:s,headers:{"X-Gizwits-Signature":c,"X-Gizwits-Timestamp":l}})}))},t.unbindDevice=function({devices:e}){return s(this,void 0,void 0,(function*(){return yield(0,r.default)("/app/bindings",{method:"DELETE",data:{devices:e.map(e=>({did:e.did}))}})}))},t.checkDeviceRegister=function({SSID:e,password:t,productKeys:i}){return s(this,void 0,void 0,(function*(){const s=(0,o.default)({SSID:e,password:t,pks:i});let n="";return s.map(e=>{n+=`${e},`}),n=n.substring(0,n.length-1),yield(0,r.default)(`/app/device_register?random_codes=${n}`,{method:"get"})}))},t.safeRegister=function({productKey:e,productSecret:t,mac:i,passcode:n,gwDid:o,isReset:a}){return s(this,void 0,void 0,(function*(){let s=`is_reset=${a?1:0}&mac=${i}&passcode=${n}`;o&&(s+=`&gw_did=${o}`);const l=c.enc.Hex.parse(t),d=c.enc.Hex.parse(""),u=c.enc.Utf8.parse(s),h=c.AES.encrypt(u,l,{iv:d,mode:c.mode.ECB,padding:c.pad.Pkcs7}).ciphertext.toString().toUpperCase(),f=yield(0,r.default)(`/dev/${e}/device`,{method:"POST",data:{data:h},headers:{"content-type":"application/x-www-form-urlencoded"}},!1);return f.success?{success:!0,data:{successDevices:[],failedDevices:[]}}:{success:!1,err:f.err}}))},t.editBindInfo=function({name:e,remark:t,did:i}){return s(this,void 0,void 0,(function*(){const s={};return e&&(s.dev_alias=e),t&&(s.remark=t),yield(0,r.default)(`/app/bindings/${i}`,{method:"PUT",data:s},!0)}))}},function(e,t,i){"use strict";var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const n=s(i(4)),r=i(2);class o extends n.default{constructor(e){super(e)}}o.pack=(e,t)=>{const i=[],[s,n]=(0,r.formatCodesFromStr)(e),[o,a]=(0,r.formatCodesFromStr)(t),c=[0].concat([0,1],n,s,a,o);let l=c.length;for(;l>0;)i.push(l),l-=255;const d=[0,0,0,3].concat(i).concat(c),u=new ArrayBuffer(d.length),h=new Uint8Array(u);for(let e=0;e<u.byteLength;e++)h[e]=d[e];return h},t.default=o},function(e,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 o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=i(14),o=i(20),a=n(i(63)),c=i(19),l=n(i(27)),d=n(i(3)),u=i(64),h=n(i(17)),f=i(25),p=n(i(66)),v=i(67),g=n(i(4)),y=i(2),_=i(30),D=i(70),m=i(71),b=n(i(10)),S=i(12),w=n(i(72)),B=n(i(73)),k=n(i(74)),I=l.default.version;class C{get deviceList(){return this._deviceList}set deviceList(e){this._deviceList=e,this.notiDeviceList()}get bleDevices(){return this._bleDevices}set bleDevices(e){this._bleDevices=e,this.notiDeviceList()}get lanDevices(){return this._lanDevices}set lanDevices(e){this._lanDevices=e,this.notiDeviceList()}get allDevices(){let e=(0,S.merageBleLocalDevices)([...this.deviceList],this.bleDevices);e=(0,S.merageLanLocalDevices)(e,this.lanDevices),this.bleHandle.connectedList.map(t=>{const i=e.findIndex(e=>e.bleDeviceID===t.deviceId);-1!==i&&(e[i].connectType="BLE")});const t=this.socketHandle._connections;return Object.keys(t).forEach(i=>{const s=t[i];s&&s._subDids.forEach(t=>{const i=e.findIndex(e=>e.did===t);-1!==i&&(e[i].connectType="WAN")})}),this.lanHandle.connectedList.map(t=>{const i=e.findIndex(e=>e.mac===t.mac&&e.productKey===t.productKey);-1!==i&&(e[i].connectType="LAN")}),e}get bleScanDevice(){return this.bleDevices.filter(e=>!0===e.isBleOnline)}constructor(e){this.listenerMap={},this.keepScanTimer=null,this._deviceList=[],this._bleDevices=[],this._lanDevices=[],this.productInfo=[],this.syncDataCallBack=null,this.syncTotalNum=0,this.syncCurrnetNum=0,this.syncDataTimoutTimer=null,this.SYNC_TIMEOUT=24e4,this.init=({appID:e,appSecret:t,productInfo:i,cloudServiceInfo:s,token:n,uid:o,offlineThreshold:a})=>{this.productInfo=i,(0,r.setGlobalData)("appID",e),(0,r.setGlobalData)("appSecret",t),(0,r.setGlobalData)("productInfo",i),(0,r.setGlobalData)("token",n),(0,r.setGlobalData)("uid",o),this.setDomain(s),this.offlineThreshold=a,d.default.debug(`init sdk success, current version: ${C.getVersion().data}`),this.initLan()},this.handleBleError=e=>{this.listenerMap.onBleHandleError&&this.listenerMap.onBleHandleError.map(t=>{t(e)})},this.handleBleDevices=e=>{this.bleDevices=e},this.handleLanDevices=e=>{this.lanDevices=e},this.handleLanDeviceData=(e,t)=>s(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>t.mac===e);if(i){const e=yield(0,f.unpack)((0,y.hexStrint2byte)(t),i.productKey);(null==e?void 0:e.kvData)&&this.listenerMap.GizDeviceAttrsNotifications&&this.listenerMap.GizDeviceAttrsNotifications.map(t=>{t({device:i,data:null==e?void 0:e.kvData})})}})),this.handleBleDeviceData=(e,t)=>s(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>t.bleDeviceID===e.deviceId);if(i){const s=(0,y.hexStrint2byte)(t);switch(new g.default(s).cmd){case"0093":case"0094":case"0090":case"0091":{if(console.debug("handleBleDeviceData",t,i),i.passcode){const e=this.productInfo.find(e=>e.productKey===i.productKey);if(e){const s=parseInt(`${Date.now()/1e3}`,10);(0,m.uploadP0)({device:i,data:[{raw:t,created_at:s}],productSecret:e.productSecret}).then(e=>{d.default.debug("设备上报数据:timestemp",new Date(1e3*s).toLocaleString(),e)})}}const e=yield(0,f.unpack)((0,y.hexStrint2byte)(t),i.productKey);(null==e?void 0:e.kvData)&&this.listenerMap.GizDeviceAttrsNotifications&&this.listenerMap.GizDeviceAttrsNotifications.map(t=>{t({device:i,data:null==e?void 0:e.kvData})});break}case"0052":{const t=new v.RequestSync(s);if(d.default.debug("设备回复是否允许同步, state:",t.state),this.syncDataLengthCallback&&this.syncDataLengthCallback({success:0==t.state,data:t.len}),!this.syncDataCallBack)break;0===t.state?(this.syncCurrnetNum=0,this.syncTotalNum=t.len,this.syncDataCallBack({event:"SYNC_START",totalNum:this.syncTotalNum,currentNum:this.syncCurrnetNum}),d.default.debug("查询第一条离线数据"),yield this.bleHandle.write(e.deviceId,(0,S.numberArray2Uint8Array)(v.SyncPackage.pack(0)).buffer)):(d.default.debug("设备返回状态为1,同步失败"),this.syncDataCallBack({event:"SYNC_FAIL"}));break}case"0054":{if(!this.syncDataCallBack)break;d.default.debug("设备上报离线数据");const t=new v.SyncPackage(s),i=v.DeletePackage.pack(t.id);d.default.debug("设备上报离线数据:payload",t.payload);try{d.default.debug("设备上报离线数据:timestemp",new Date(1e3*t.timestemp).toLocaleString())}catch(e){}const n=this.productInfo.find(e=>e.productKey===this.syncDevice.productKey);if(n){const e=yield(0,m.uploadP0)({device:this.syncDevice,data:[{raw:(0,y.arrayToString)(t.payload),created_at:t.timestemp}],productSecret:n.productSecret});d.default.debug("上传离线数据结果",e)}this.syncCurrnetNum+=1,this.syncDataCallBack({event:"SYNC_PROGRESS",totalNum:this.syncTotalNum,currentNum:this.syncCurrnetNum}),d.default.debug("通知设备删除:",t.id),yield this.bleHandle.write(e.deviceId,(0,S.numberArray2Uint8Array)(i).buffer),yield(0,b.default)(100),t.id<this.syncTotalNum-1?(d.default.debug("查询新数据:",t.id+1),yield this.bleHandle.write(e.deviceId,(0,S.numberArray2Uint8Array)(v.SyncPackage.pack(t.id+1)).buffer)):(d.default.debug("send cancel sync to device"),this.bleHandle.write(e.deviceId,(0,S.numberArray2Uint8Array)(v.CancelSync.pack()).buffer),this.syncDataCallBack({event:"SYNC_END"}),this.cleanSyncDeviceData());break}case"0058":{if(!this.syncDataCallBack)break;const e=new v.CancelSync(s);d.default.debug("设备上报停止同步 state:",e.state),0===e.state?this.syncDataCallBack({event:"SYNC_END"}):this.syncDataCallBack({event:"SYNC_FAIL"}),this.cleanSyncDeviceData();break}}}})),this.handleSocketDeviceData=e=>s(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>t.did===e.did);if(t){if(e.attrs&&null!=e.attrs.is_online){const i=e.attrs.is_online;this.setDeviceMeta(t,"isOnline",i)}this.listenerMap.GizDeviceAttrsNotifications&&(e.attrs&&(e.attrs=yield(0,f.formatEnum)(e.attrs,t.productKey,"int")),this.listenerMap.GizDeviceAttrsNotifications.map(i=>{i(Object.assign({device:t},"attrs"in e?{data:e.attrs}:{raw:e.raw}))}))}})),this.handleSocketStatus=(e,t)=>{const i=this.allDevices.filter(t=>e.includes(t.did)&&"WAN"===t.connectType);d.default.log("handleSocketStatus",e,t),i.forEach(e=>{this.setDeviceMeta(e,"connectType",t?"WAN":"NONE")})},this.notiDeviceList=()=>{var e,t;null===(e=this.listenerMap.GizDeviceListNotifications)||void 0===e||e.map(e=>{e(this.allDevices)}),null===(t=this.listenerMap.onScanListChange)||void 0===t||t.map(e=>{e(this.bleScanDevice)})},this.initLan=()=>{try{this.lanHandle.init(),this.lanHandle.addEventListener("GizLanDeviceList",this.handleLanDevices),this.lanHandle.addEventListener("GizLanDeviceData",this.handleLanDeviceData)}catch(e){d.default.error("init lan error",e)}},this.startAutoScan=e=>{this.keepScanTimer||(this.keepScanTimer=setInterval(()=>s(this,void 0,void 0,(function*(){this.bleHandle.startScan(e=>{this.bleDevices=e},-1,e)})),9e3),this.bleHandle.startScan(e=>{this.bleDevices=e},-1,e))},this.stopAutoScan=()=>{this.keepScanTimer&&clearInterval(this.keepScanTimer),this.bleHandle.stopScan()},this.setDeviceMeta=(e,t,i,s=!1)=>{const n=this.allDevices.find(t=>t.mac===e.mac);n&&0!==this.allDevices.length&&(e[t]!==i||s)&&(n[t]=i,this.notiDeviceList())},this.initBle=()=>s(this,void 0,void 0,(function*(){const e=yield this.bleHandle.checkPermission();return e.success?(this.bleHandle.addEventListener("GizBleDeviceData",this.handleBleDeviceData),this.bleHandle.addEventListener("GizBleDeviceList",this.handleBleDevices),this.bleHandle.addEventListener("GizBleError",this.handleBleError),d.default.debug("init BLE succcess",e),{success:!0}):(d.default.error("init BLE Error",new Error(JSON.stringify(e))),{success:!1,err:c.errorCode.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON})})),this.scanBleDevice=(e,t)=>s(this,void 0,void 0,(function*(){return this.bleHandle.scanList=[],{success:!0,data:(yield this.bleHandle.startScan(e=>{this.bleDevices=e},e,t)).scanList}})),this.write=(e,t)=>s(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>(0,S.isSameDevice)(t,e));if(!i)return{success:!1,message:"target is undefind"};if("NONE"!==i.connectType){const{data:e,raw:s}=yield(0,f.pack)(t,i.productKey);switch(i.connectType){case"BLE_BROADCAST":return yield this.bleHandle.writeBoradcast(i.bleDeviceID,s.cmd);case"BLE":return e?yield this.bleHandle.write(i.bleDeviceID,(0,S.numberArray2Uint8Array)(e).buffer):{success:!1};case"WAN":{const e=yield(0,f.formatEnum)(t,i.productKey,"string");return this.socketHandle.writeData(i,e)}case"LAN":return this.lanHandle.write(i,(0,S.numberArray2Uint8Array)(e).buffer)}}return{success:!1}})),this.writeRaw=(e,t)=>s(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>(0,S.isSameDevice)(t,e));if(!i)return{success:!1,message:"target is undefind"};if("NONE"!==i.connectType)switch(i.connectType){case"BLE_BROADCAST":return yield this.bleHandle.writeBoradcast(i.bleDeviceID,t);case"BLE":return t?yield this.bleHandle.write(i.bleDeviceID,(0,S.numberArray2Uint8Array)(t).buffer):{success:!1};case"WAN":return this.socketHandle.send(i.did,t);case"LAN":return this.lanHandle.write(i,(0,S.numberArray2Uint8Array)(t).buffer)}return{success:!1}})),this.setDeviceTimeStamp=e=>s(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>(0,S.isSameDevice)(t,e));if(!t)return{success:!1,message:"target is undefind"};const i=p.default.pack();switch(t.connectType){case"BLE":return this.bleHandle.write(e.bleDeviceID,(0,S.numberArray2Uint8Array)(i).buffer)}return{success:!1,message:"the connectType not support set timestamp"}})),this.syncDeviceData=(e,t=(()=>{}))=>s(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>(0,S.isSameDevice)(t,e));if(!i)return{success:!1,message:"target is undefind"};if(!i.isBind)return{success:!1,message:"Only the bound devices are supported"};if(this.syncDevice)return{success:!1,message:"Synchronizing"};switch(this.syncDevice=Object.assign({},i),i.connectType){case"BLE":{d.default.debug("start syncDeviceData",e),this.syncDataCallBack=t,this.syncDataTimoutTimer=setTimeout(()=>{this.syncDataCallBack({event:"SYNC_FAIL",message:"sync timeout"}),this.cleanSyncDeviceData()},this.SYNC_TIMEOUT);const i=v.RequestSync.pack();return d.default.debug("sent RequestSync data"),this.bleHandle.write(e.bleDeviceID,(0,S.numberArray2Uint8Array)(i).buffer)}}return{success:!1,message:"the connectType not support sync data"}})),this.queryNeedSyncDataLength=e=>s(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>(0,S.isSameDevice)(t,e));if(!t)return{success:!1,message:"target is undefind"};if(!t.isBind)return{success:!1,message:"Only the bound devices are supported"};switch(t.connectType){case"BLE":{const i=v.RequestSync.pack();return this.syncDevice=Object.assign({},t),d.default.debug("sent RequestSync data len"),this.bleHandle.write(e.bleDeviceID,(0,S.numberArray2Uint8Array)(i).buffer),new Promise(e=>{this.syncDataLengthCallback=e,setTimeout(()=>{try{e({success:!1,message:"timeout"})}catch(e){}},3e3)})}}return{success:!1,message:"the connectType not support sync data"}})),this.cancelSyncDeviceData=()=>s(this,void 0,void 0,(function*(){this.cleanSyncDeviceData()})),this.cleanSyncDeviceData=()=>{this.syncDataCallBack&&(this.syncDataCallBack({event:"SYNC_CANCEL"}),this.syncDataCallBack=null),this.syncCurrnetNum=0,this.syncTotalNum=0,this.syncDevice=null,this.syncDataTimoutTimer&&clearTimeout(this.syncDataTimoutTimer)},this.getProductConfig=e=>s(this,void 0,void 0,(function*(){const t=yield h.default.getConfigFile(e);return t?{success:!0,data:t}:{success:!1}})),this.stopScanBleDevice=()=>{this.bleHandle.stopScan()},this.login=e=>s(this,void 0,void 0,(function*(){var t,i;const s=yield(0,D.AnonymousLogin)({uid:e});return s.success&&((0,r.setGlobalData)("token",null===(t=s.data)||void 0===t?void 0:t.token),(0,r.setGlobalData)("uid",null===(i=s.data)||void 0===i?void 0:i.uid),this.socketHandle.updateToken({token:s.data.token,uid:s.data.uid})),s})),this.getDeviceStatus=(e,t)=>s(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>(0,S.isSameDevice)(t,e));if(!i)return{success:!1,message:"target is undefind"};switch(i.connectType){case"BLE":return yield this.bleHandle.getDeviceStatus(i.bleDeviceID,i.productKey,i.rootDeviceId,t);case"WAN":return this.socketHandle.readStatus(i,t);default:return{success:!1,message:"Device connectType is unsupported"}}})),this.subscribe=(e,t,i=!0)=>s(this,void 0,void 0,(function*(){d.default.debug("subscribe device:",e);let i=this.allDevices.find(t=>(0,S.isSameDevice)(t,e));if(!i)return d.default.warn("Device Target Not Found"),d.default.warn("current devices ",this.allDevices),{success:!1,message:"device not found"};if("BLE_BROADCAST"===i.connectType)return{success:!0,message:""};const s=(0,S.getFirstConnectType)(i,t);switch("NONE"!==i.connectType&&i.connectType!==s&&(yield this.unSubscribe(i)),s){case"BLE":{const e=yield this.bleHandle.connectDevice(i);return e.success&&(this.setDeviceMeta(i,"connectType","BLE",!0),setTimeout(()=>{this.setDeviceTimeStamp(i)},250),setTimeout(()=>{this.getDeviceStatus(i)},500)),e}case"WAN":{const t=this.socketHandle.connectDevice(i);return t.success&&this.setDeviceMeta(e,"connectType","WAN",!0),t}case"LAN":{const t=yield this.lanHandle.connectDevice(i);return t.success&&this.setDeviceMeta(e,"connectType","LAN",!0),t}}return{success:!1,message:""}})),this.unSubscribe=e=>s(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>(0,S.isSameDevice)(t,e));switch(t.connectType){case"BLE":{const e=yield this.bleHandle.disConnectDevice(t.bleDeviceID);return e.success&&this.setDeviceMeta(t,"connectType","NONE",!0),e}case"WAN":{const e=this.socketHandle.disConnectDevice(t);return e.success&&this.setDeviceMeta(t,"connectType","NONE",!0),e}case"LAN":{const e=this.lanHandle.disConnectDevice(t);return e.success&&this.setDeviceMeta(t,"connectType","NONE",!0),e}}return{success:!1}})),this.bindRemoteDevice=({mac:e,productKey:t,alias:i,beOwner:n})=>s(this,void 0,void 0,(function*(){const s=(0,S.getProductInfoThroughPK)(t,this.productInfo);if(s){const r=yield(0,_.bindMac)({mac:e,productKey:t,productSecret:s.productSecret,alias:i,beOwner:n});return this.getBindingList(),r}return{success:!1,err:c.errorCode.GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY}})),this.unbindDevice=({devices:e})=>s(this,void 0,void 0,(function*(){const t=yield(0,_.unbindDevice)({devices:e});return t.success&&this.getBindingList(),t})),this.deviceSafetyRegister=({mac:e,productKey:t})=>s(this,void 0,void 0,(function*(){return yield this.deviceSafetyApi({mac:e,productKey:t,isReset:!1})})),this.deviceSafetyUnbind=({mac:e,productKey:t})=>s(this,void 0,void 0,(function*(){return yield this.deviceSafetyApi({mac:e,productKey:t,isReset:!0})})),this.setDeviceOnboardingDeploy=({ssid:e,bssid:t="",password:i,mode:n=0,timeout:o,isBind:a=!0,softAPSSIDPrefix:l})=>s(this,void 0,void 0,(function*(){if(this.currentWifiConfigHandle)return{success:!1,err:c.errorCode.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING};const s=(new Date).getTime();d.default.debug("GIZ_SDK: 配网开始时间:"+s,n);try{switch(n){case 0:{this.currentWifiConfigHandle=new w.default(e,t,i,this.specialProductKeys,this.specialProductKeySecrets);const n=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:o,isBind:a,softAPSSIDPrefix:l});this.currentWifiConfigHandle=null;const r=(new Date).getTime();return d.default.debug("GIZ_SDK: 配网结束时间:"+r),d.default.debug("GIZ_SDK: 配网用时:"+(r-s)),n}case 3:{this.currentWifiConfigHandle=new B.default(e,t,i,this.specialProductKeys,this.specialProductKeySecrets,this.bleHandle);const n=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:o,isBind:a,softAPSSIDPrefix:l});this.currentWifiConfigHandle=null;const r=(new Date).getTime();return d.default.debug("GIZ_SDK: 配网结束时间:"+r),d.default.debug("GIZ_SDK: 配网用时:"+(r-s)),n}case 5:{const n=yield wx.getSystemInfoSync();if(console.log("sysInfosysInfo",n),"android"!==n.platform)return{success:!1,message:"只支持安卓"};const c=(0,r.getGlobalData)("cloudServiceInfo");console.log("cloudServiceInfo",c),this.currentWifiConfigHandle=new k.default(e,t,i,this.specialProductKeys,this.specialProductKeySecrets,(null==c?void 0:c.openAPIInfo)||"api.gizwits.com");const u=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:o,isBind:a,softAPSSIDPrefix:l});this.currentWifiConfigHandle=null;const h=(new Date).getTime();return d.default.debug("GIZ_SDK: 配网结束时间:"+h),d.default.debug("GIZ_SDK: 配网用时:"+(h-s)),u}}}catch(e){return d.default.error("GIZ_SDK: setDeviceOnboardingDeploy",e),e.err&&e.err.errorCode?e:{success:!1,err:c.errorCode.GIZ_SDK_OTHERWISE}}finally{this.currentWifiConfigHandle=null}})),this.setDomain=e=>{const t=e&&e.openAPIInfo||"api.gizwits.com",i=Object.assign(Object.assign({},e||{}),{openAPIInfo:t});(0,r.setGlobalData)("cloudServiceInfo",i)},this.deviceSafetyApi=({mac:e,productKey:t,isReset:i})=>s(this,void 0,void 0,(function*(){const s=(0,S.getProductInfoThroughPK)(t,this.productInfo);return s?yield(0,_.safeRegister)({productKey:t,productSecret:s.productSecret,mac:e,isReset:i,passcode:"1234567890"}):{success:!1,err:c.errorCode.GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY}})),this.getBindingList=()=>s(this,void 0,void 0,(function*(){const e=yield(0,_.getBindingList)();return this.deviceList=e.data||[],this.notiDeviceList(),e})),this.getDevices=()=>s(this,void 0,void 0,(function*(){return yield this.getBindingList(),{success:!0,data:this.allDevices}})),this.stopDeviceOnboardingDeploy=()=>{this.currentWifiConfigHandle&&(this.currentWifiConfigHandle.stopDeviceOnboardingDeploy(),this.currentWifiConfigHandle=null)},this.setLogLevel=e=>d.default.setLogLevel(e),this.renameDevice=(e,t)=>s(this,void 0,void 0,(function*(){return t?e.isBind?yield(0,_.editBindInfo)({did:e.did,name:t}):{success:!1,message:"device not bind"}:{success:!1,message:"please input device name"}})),this.removeEventListener=(e,t)=>{if(this.listenerMap[e]){const i=this.listenerMap[e].indexOf(t);if(-1!==i)return this.listenerMap[e].splice(i,1),{success:!0}}return{success:!1}},this.addEventListener=(e,t)=>s(this,void 0,void 0,(function*(){return this.listenerMap[e]||(this.listenerMap[e]=[]),-1===this.listenerMap[e].indexOf(t)&&this.listenerMap[e].push(t),{success:!0}})),this.destory=()=>{this.bleHandle.destory(),this.lanHandle.destory(),this.socketHandle.destory(),this.keepScanTimer&&clearInterval(this.keepScanTimer)},this.init(e)}get bleHandle(){return this._bleHandle||(this._bleHandle=new o.BleHandle({pks:this.specialProductKeys,offlineThreshold:this.offlineThreshold})),this._bleHandle}get lanHandle(){return this._lanHandle||(this._lanHandle=new u.LanHandle({pks:this.specialProductKeys})),this._lanHandle}get socketHandle(){return this._gizSocket||(this._gizSocket=new a.default({appID:(0,r.getGlobalData)("appID"),token:(0,r.getGlobalData)("token"),uid:(0,r.getGlobalData)("uid")}),this._gizSocket.subscribeDeviceStatus(this.handleSocketDeviceData),this._gizSocket.subscribeBindingChanged(this.getBindingList),this._gizSocket.subscribeSocketStatus(this.handleSocketStatus)),this._gizSocket}reInit(e){this.init(e),this.lanHandle.pks=this.specialProductKeys,this.bleHandle.pks=this.specialProductKeys,this.bleHandle.offlineThreshold=e.offlineThreshold;const{appID:t,token:i,cloudServiceInfo:s={openAPIInfo:""}}=e,n=s&&s.openAPIInfo||"api.gizwits.com";t===(0,r.getGlobalData)("appID")&&i===(0,r.getGlobalData)("token")&&n===(0,r.getGlobalData)("cloudServiceInfo").openAPIInfo||(this.socketHandle.destory(),this._gizSocket=null,this.socketHandle,this.getBindingList())}get specialProductKeys(){return this.productInfo.map(e=>{var t;return null!==(t=e.productKey)&&void 0!==t?t:""})}get specialProductKeySecrets(){return this.productInfo.map(e=>{var t;return null!==(t=e.productSecret)&&void 0!==t?t:""})}}C.getVersion=()=>({success:!0,data:I}),t.default=C},function(e,t,i){"use strict";var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const n=i(11),r=s(i(23));t.default=e=>{const t=wx.getSystemInfoSync(),i={exception:{values:[{type:"Error",value:e.stack,stacktrace:{},mechanism:{type:"generic",handled:!0}}]},level:"error",event_id:(0,n.MD5)(`${(new Date).getTime()}`).toString(),platform:"javascript",sdk:{},timestamp:(new Date).getTime()/1e3,environment:"production",contexts:{device:{},os:{name:t.platform,version:t.version},extra:{}},extra:{message:e.message}};var s={method:"POST",headers:{Connection:"keep-alive","User-Agent":"Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1 wechatdevtools/1.06.2206090 MicroMessenger/8.0.5 Language/zh_CN webview/","content-type":"application/json",Accept:"*/*","Sec-Fetch-Site":"cross-site","Sec-Fetch-Mode":"cors","Sec-Fetch-Dest":"empty",Referer:"https://servicewechat.com/wx6dc8e50cb68bc121/devtools/page-frame.html",Cookie:"__org="},data:JSON.stringify(i)};(0,r.default)("https://appmonitor.gizwits.com/api/21/store/?sentry_key=0b2de791abf548a1bedf0b0ebdd8ecc7&sentry_version=7",s)}},function(e,t){var i;i=function(){return this}();try{i=i||new Function("return this")()}catch(e){"object"==typeof window&&(i=window)}e.exports=i},function(e,t){},function(e,t,i){var s;e.exports=(s=i(0),function(){if("function"==typeof ArrayBuffer){var e=s.lib.WordArray,t=e.init;(e.init=function(e){if(e instanceof ArrayBuffer&&(e=new Uint8Array(e)),(e instanceof Int8Array||"undefined"!=typeof Uint8ClampedArray&&e instanceof Uint8ClampedArray||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array)&&(e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),e instanceof Uint8Array){for(var i=e.byteLength,s=[],n=0;n<i;n++)s[n>>>2]|=e[n]<<24-n%4*8;t.call(this,s,i)}else t.apply(this,arguments)}).prototype=e}}(),s.lib.WordArray)},function(e,t,i){var s;e.exports=(s=i(0),function(){var e=s,t=e.lib.WordArray,i=e.enc;function n(e){return e<<8&4278255360|e>>>8&16711935}i.Utf16=i.Utf16BE={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],n=0;n<i;n+=2){var r=t[n>>>2]>>>16-n%4*8&65535;s.push(String.fromCharCode(r))}return s.join("")},parse:function(e){for(var i=e.length,s=[],n=0;n<i;n++)s[n>>>1]|=e.charCodeAt(n)<<16-n%2*16;return t.create(s,2*i)}},i.Utf16LE={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],r=0;r<i;r+=2){var o=n(t[r>>>2]>>>16-r%4*8&65535);s.push(String.fromCharCode(o))}return s.join("")},parse:function(e){for(var i=e.length,s=[],r=0;r<i;r++)s[r>>>1]|=n(e.charCodeAt(r)<<16-r%2*16);return t.create(s,2*i)}}}(),s.enc.Utf16)},function(e,t,i){var s,n,r;e.exports=(r=i(0),n=(s=r).lib.WordArray,s.enc.Base64url={stringify:function(e,t=!0){var i=e.words,s=e.sigBytes,n=t?this._safe_map:this._map;e.clamp();for(var r=[],o=0;o<s;o+=3)for(var a=(i[o>>>2]>>>24-o%4*8&255)<<16|(i[o+1>>>2]>>>24-(o+1)%4*8&255)<<8|i[o+2>>>2]>>>24-(o+2)%4*8&255,c=0;c<4&&o+.75*c<s;c++)r.push(n.charAt(a>>>6*(3-c)&63));var l=n.charAt(64);if(l)for(;r.length%4;)r.push(l);return r.join("")},parse:function(e,t=!0){var i=e.length,s=t?this._safe_map:this._map,r=this._reverseMap;if(!r){r=this._reverseMap=[];for(var o=0;o<s.length;o++)r[s.charCodeAt(o)]=o}var a=s.charAt(64);if(a){var c=e.indexOf(a);-1!==c&&(i=c)}return function(e,t,i){for(var s=[],r=0,o=0;o<t;o++)if(o%4){var a=i[e.charCodeAt(o-1)]<<o%4*2,c=i[e.charCodeAt(o)]>>>6-o%4*2,l=a|c;s[r>>>2]|=l<<24-r%4*8,r++}return n.create(s,r)}(e,i,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",_safe_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"},r.enc.Base64url)},function(e,t,i){var s,n,r,o,a,c;e.exports=(c=i(0),i(21),n=(s=c).lib.WordArray,r=s.algo,o=r.SHA256,a=r.SHA224=o.extend({_doReset:function(){this._hash=new n.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var e=o._doFinalize.call(this);return e.sigBytes-=4,e}}),s.SHA224=o._createHelper(a),s.HmacSHA224=o._createHmacHelper(a),c.SHA224)},function(e,t,i){var s,n,r,o,a,c,l,d;e.exports=(d=i(0),i(13),i(22),n=(s=d).x64,r=n.Word,o=n.WordArray,a=s.algo,c=a.SHA512,l=a.SHA384=c.extend({_doReset:function(){this._hash=new o.init([new r.init(3418070365,3238371032),new r.init(1654270250,914150663),new r.init(2438529370,812702999),new r.init(355462360,4144912697),new r.init(1731405415,4290775857),new r.init(2394180231,1750603025),new r.init(3675008525,1694076839),new r.init(1203062813,3204075428)])},_doFinalize:function(){var e=c._doFinalize.call(this);return e.sigBytes-=16,e}}),s.SHA384=c._createHelper(l),s.HmacSHA384=c._createHmacHelper(l),d.SHA384)},function(e,t,i){var s;e.exports=(s=i(0),i(13),function(e){var t=s,i=t.lib,n=i.WordArray,r=i.Hasher,o=t.x64.Word,a=t.algo,c=[],l=[],d=[];!function(){for(var e=1,t=0,i=0;i<24;i++){c[e+5*t]=(i+1)*(i+2)/2%64;var s=(2*e+3*t)%5;e=t%5,t=s}for(e=0;e<5;e++)for(t=0;t<5;t++)l[e+5*t]=t+(2*e+3*t)%5*5;for(var n=1,r=0;r<24;r++){for(var a=0,u=0,h=0;h<7;h++){if(1&n){var f=(1<<h)-1;f<32?u^=1<<f:a^=1<<f-32}128&n?n=n<<1^113:n<<=1}d[r]=o.create(a,u)}}();var u=[];!function(){for(var e=0;e<25;e++)u[e]=o.create()}();var h=a.SHA3=r.extend({cfg:r.cfg.extend({outputLength:512}),_doReset:function(){for(var e=this._state=[],t=0;t<25;t++)e[t]=new o.init;this.blockSize=(1600-2*this.cfg.outputLength)/32},_doProcessBlock:function(e,t){for(var i=this._state,s=this.blockSize/2,n=0;n<s;n++){var r=e[t+2*n],o=e[t+2*n+1];r=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),o=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8),(A=i[n]).high^=o,A.low^=r}for(var a=0;a<24;a++){for(var h=0;h<5;h++){for(var f=0,p=0,v=0;v<5;v++)f^=(A=i[h+5*v]).high,p^=A.low;var g=u[h];g.high=f,g.low=p}for(h=0;h<5;h++){var y=u[(h+4)%5],_=u[(h+1)%5],D=_.high,m=_.low;for(f=y.high^(D<<1|m>>>31),p=y.low^(m<<1|D>>>31),v=0;v<5;v++)(A=i[h+5*v]).high^=f,A.low^=p}for(var b=1;b<25;b++){var S=(A=i[b]).high,w=A.low,B=c[b];B<32?(f=S<<B|w>>>32-B,p=w<<B|S>>>32-B):(f=w<<B-32|S>>>64-B,p=S<<B-32|w>>>64-B);var k=u[l[b]];k.high=f,k.low=p}var I=u[0],C=i[0];for(I.high=C.high,I.low=C.low,h=0;h<5;h++)for(v=0;v<5;v++){var A=i[b=h+5*v],x=u[b],T=u[(h+1)%5+5*v],L=u[(h+2)%5+5*v];A.high=x.high^~T.high&L.high,A.low=x.low^~T.low&L.low}A=i[0];var E=d[a];A.high^=E.high,A.low^=E.low}},_doFinalize:function(){var t=this._data,i=t.words,s=(this._nDataBytes,8*t.sigBytes),r=32*this.blockSize;i[s>>>5]|=1<<24-s%32,i[(e.ceil((s+1)/r)*r>>>5)-1]|=128,t.sigBytes=4*i.length,this._process();for(var o=this._state,a=this.cfg.outputLength/8,c=a/8,l=[],d=0;d<c;d++){var u=o[d],h=u.high,f=u.low;h=16711935&(h<<8|h>>>24)|4278255360&(h<<24|h>>>8),f=16711935&(f<<8|f>>>24)|4278255360&(f<<24|f>>>8),l.push(f),l.push(h)}return new n.init(l,a)},clone:function(){for(var e=r.clone.call(this),t=e._state=this._state.slice(0),i=0;i<25;i++)t[i]=t[i].clone();return e}});t.SHA3=r._createHelper(h),t.HmacSHA3=r._createHmacHelper(h)}(Math),s.SHA3)},function(e,t,i){var s;e.exports=(s=i(0),
|
|
2
2
|
/** @preserve
|
|
3
3
|
(c) 2012 by Cédric Mesnil. All rights reserved.
|
|
4
4
|
|
|
@@ -9,10 +9,10 @@ module.exports=function(e){var t={};function i(s){if(t[s])return t[s].exports;va
|
|
|
9
9
|
|
|
10
10
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
11
11
|
*/
|
|
12
|
-
function(e){var t=s,i=t.lib,n=i.WordArray,r=i.Hasher,
|
|
12
|
+
function(e){var t=s,i=t.lib,n=i.WordArray,r=i.Hasher,o=t.algo,a=n.create([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13]),c=n.create([5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11]),l=n.create([11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6]),d=n.create([8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]),u=n.create([0,1518500249,1859775393,2400959708,2840853838]),h=n.create([1352829926,1548603684,1836072691,2053994217,0]),f=o.RIPEMD160=r.extend({_doReset:function(){this._hash=n.create([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(e,t){for(var i=0;i<16;i++){var s=t+i,n=e[s];e[s]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8)}var r,o,f,m,b,S,w,B,k,I,C,A=this._hash.words,x=u.words,T=h.words,L=a.words,E=c.words,P=l.words,O=d.words;for(S=r=A[0],w=o=A[1],B=f=A[2],k=m=A[3],I=b=A[4],i=0;i<80;i+=1)C=r+e[t+L[i]]|0,C+=i<16?p(o,f,m)+x[0]:i<32?v(o,f,m)+x[1]:i<48?g(o,f,m)+x[2]:i<64?y(o,f,m)+x[3]:_(o,f,m)+x[4],C=(C=D(C|=0,P[i]))+b|0,r=b,b=m,m=D(f,10),f=o,o=C,C=S+e[t+E[i]]|0,C+=i<16?_(w,B,k)+T[0]:i<32?y(w,B,k)+T[1]:i<48?g(w,B,k)+T[2]:i<64?v(w,B,k)+T[3]:p(w,B,k)+T[4],C=(C=D(C|=0,O[i]))+I|0,S=I,I=k,k=D(B,10),B=w,w=C;C=A[1]+f+k|0,A[1]=A[2]+m+I|0,A[2]=A[3]+b+S|0,A[3]=A[4]+r+w|0,A[4]=A[0]+o+B|0,A[0]=C},_doFinalize:function(){var e=this._data,t=e.words,i=8*this._nDataBytes,s=8*e.sigBytes;t[s>>>5]|=128<<24-s%32,t[14+(s+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),e.sigBytes=4*(t.length+1),this._process();for(var n=this._hash,r=n.words,o=0;o<5;o++){var a=r[o];r[o]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}return n},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});function p(e,t,i){return e^t^i}function v(e,t,i){return e&t|~e&i}function g(e,t,i){return(e|~t)^i}function y(e,t,i){return e&i|t&~i}function _(e,t,i){return e^(t|~i)}function D(e,t){return e<<t|e>>>32-t}t.RIPEMD160=r._createHelper(f),t.HmacRIPEMD160=r._createHmacHelper(f)}(Math),s.RIPEMD160)},function(e,t,i){var s,n,r,o,a,c,l,d,u;e.exports=(u=i(0),i(15),i(16),n=(s=u).lib,r=n.Base,o=n.WordArray,a=s.algo,c=a.SHA1,l=a.HMAC,d=a.PBKDF2=r.extend({cfg:r.extend({keySize:4,hasher:c,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var i=this.cfg,s=l.create(i.hasher,e),n=o.create(),r=o.create([1]),a=n.words,c=r.words,d=i.keySize,u=i.iterations;a.length<d;){var h=s.update(t).finalize(r);s.reset();for(var f=h.words,p=f.length,v=h,g=1;g<u;g++){v=s.finalize(v),s.reset();for(var y=v.words,_=0;_<p;_++)f[_]^=y[_]}n.concat(h),c[0]++}return n.sigBytes=4*d,n}}),s.PBKDF2=function(e,t,i){return d.create(i).compute(e,t)},u.PBKDF2)},function(e,t,i){var s;e.exports=(s=i(0),i(1),s.mode.CFB=function(){var e=s.lib.BlockCipherMode.extend();function t(e,t,i,s){var n,r=this._iv;r?(n=r.slice(0),this._iv=void 0):n=this._prevBlock,s.encryptBlock(n,0);for(var o=0;o<i;o++)e[t+o]^=n[o]}return e.Encryptor=e.extend({processBlock:function(e,i){var s=this._cipher,n=s.blockSize;t.call(this,e,i,n,s),this._prevBlock=e.slice(i,i+n)}}),e.Decryptor=e.extend({processBlock:function(e,i){var s=this._cipher,n=s.blockSize,r=e.slice(i,i+n);t.call(this,e,i,n,s),this._prevBlock=r}}),e}(),s.mode.CFB)},function(e,t,i){var s,n,r;e.exports=(r=i(0),i(1),r.mode.CTR=(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._counter;n&&(r=this._counter=n.slice(0),this._iv=void 0);var o=r.slice(0);i.encryptBlock(o,0),r[s-1]=r[s-1]+1|0;for(var a=0;a<s;a++)e[t+a]^=o[a]}}),s.Decryptor=n,s),r.mode.CTR)},function(e,t,i){var s;e.exports=(s=i(0),i(1),
|
|
13
13
|
/** @preserve
|
|
14
14
|
* Counter block mode compatible with Dr Brian Gladman fileenc.c
|
|
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 o=a.slice(0);s.encryptBlock(o,0);for(var c=0;c<n;c++)e[i+c]^=o[c]}});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=[],o=[],c=[],l=[],d=[],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,o[i]=_<<16|_>>>16,c[i]=_<<8|_>>>24,l[i]=_,_=16843009*y^65537*g^257*v^16843008*i,d[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]:(l=r[a-1],a%i?i>6&&a%i==4&&(l=n[l>>>24]<<24|n[l>>>16&255]<<16|n[l>>>8&255]<<8|n[255&l]):(l=n[(l=l<<8|l>>>24)>>>24]<<24|n[l>>>16&255]<<16|n[l>>>8&255]<<8|n[255&l],l^=p[a/i|0]<<24),r[a]=r[a-i]^l);for(var o=this._invKeySchedule=[],c=0;c<s;c++){if(a=s-c,c%4)var l=r[a];else l=r[a-4];o[c]=c<4||a<=4?l:d[n[l>>>24]]^u[n[l>>>16&255]]^h[n[l>>>8&255]]^f[n[255&l]]}}},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,a,o,c,l,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,d,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,o){for(var c=this._nRounds,l=e[t]^i[0],d=e[t+1]^i[1],u=e[t+2]^i[2],h=e[t+3]^i[3],f=4,p=1;p<c;p++){var v=s[l>>>24]^n[d>>>16&255]^r[u>>>8&255]^a[255&h]^i[f++],g=s[d>>>24]^n[u>>>16&255]^r[h>>>8&255]^a[255&l]^i[f++],y=s[u>>>24]^n[h>>>16&255]^r[l>>>8&255]^a[255&d]^i[f++],_=s[h>>>24]^n[l>>>16&255]^r[d>>>8&255]^a[255&u]^i[f++];l=v,d=g,u=y,h=_}v=(o[l>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&h])^i[f++],g=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[h>>>8&255]<<8|o[255&l])^i[f++],y=(o[u>>>24]<<24|o[h>>>16&255]<<16|o[l>>>8&255]<<8|o[255&d])^i[f++],_=(o[h>>>24]<<24|o[l>>>16&255]<<16|o[d>>>8&255]<<8|o[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],o=[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],c=[1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28],l=[{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}],d=[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 l=n[r]=[],d=c[r];for(i=0;i<24;i++)l[i/6|0]|=t[(o[i]-1+d)%28]<<31-i%6,l[4+(i/6|0)]|=t[28+(o[i+24]-1+d)%28]<<31-i%6;for(l[0]=l[0]<<1|l[0]>>>31,i=1;i<7;i++)l[i]=l[i]>>>4*(i-1)+3;l[7]=l[7]<<5|l[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,o=0,c=0;c<8;c++)o|=l[c][((a^n[c])&d[c])>>>0];this._lBlock=a,this._rBlock=r^o}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,o=t[a>>>2]>>>24-a%4*8&255;r=(r+s[n]+o)%256;var c=s[n];s[n]=s[r],s[r]=c}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=[],o=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++)c.call(this);for(i=0;i<8;i++)n[i]^=s[i+4&7];if(t){var r=t.words,a=r[0],o=r[1],l=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),d=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8),u=l>>>16|4294901760&d,h=d<<16|65535&l;for(n[0]^=l,n[1]^=u,n[2]^=d,n[3]^=h,n[4]^=l,n[5]^=u,n[6]^=d,n[7]^=h,i=0;i<4;i++)c.call(this)}},_doProcessBlock:function(e,t){var i=this._X;c.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 c(){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,o=s>>>16,c=((n*n>>>17)+n*o>>>15)+o*o,l=((4294901760&s)*s|0)+((65535&s)*s|0);a[i]=c^l}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(o)}(),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=[],o=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++)c.call(this);for(n=0;n<8;n++)s[n]^=i[n+4&7];if(t){var r=t.words,a=r[0],o=r[1],l=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),d=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8),u=l>>>16|4294901760&d,h=d<<16|65535&l;for(s[0]^=l,s[1]^=u,s[2]^=d,s[3]^=h,s[4]^=l,s[5]^=u,s[6]^=d,s[7]^=h,n=0;n<4;n++)c.call(this)}},_doProcessBlock:function(e,t){var i=this._X;c.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 c(){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,o=s>>>16,c=((n*n>>>17)+n*o>>>15)+o*o,l=((4294901760&s)*s|0)+((65535&s)*s|0);a[i]=c^l}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(o)}(),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{c(s.next(e))}catch(e){r(e)}}function o(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=n(i(17)),a=n(i(4)),o=i(2);class c extends a.default{}c.pack=(e,t,i)=>s(void 0,void 0,void 0,(function*(){const s=yield r.default.getConfigFile(e);if(s){const e="var_len"===s.protocolType,n=[0,0,0,3],r=[0];let a=[0];const c=[0,147];let l=[0,0,0,0],d=[2];if(t){a=[1];const e=(0,o.fillString)(t.length.toString(16),4),i=(0,o.hexStrint2byte)(e),s=(0,o.string2Bytes)(t);l=l.concat(i).concat(s)}if(e){d=[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=(0,o.fillString)(e,8*Math.ceil(e.length/8)),d=d.concat((0,o.hexStrint2byte)(parseInt(e,2).toString(16)))}const u=a.concat(c).concat(l).concat(d);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{c(s.next(e))}catch(e){r(e)}}function o(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.reportEvent=void 0;const r=i(26),a=i(14),o=n(i(9));const c=new class{constructor(){wx.getSystemInfoAsync({success:e=>{this.app={wxSdkVersion:e.SDKVersion,gizwitsSdkVersion:r.version,appID:"unknown",bluetoothEnabled:e.bluetoothEnabled,locationEnabled:e.locationEnabled,wifiEnabled:e.wifiEnabled},this.mobile={brand:e.brand,model:e.model,pixelRatio:e.pixelRatio,systemVersion:e.system,platform:e.platform}}})}updateAppId(e){this.app.appID=e}};t.reportEvent=function({device:e,eventID:t,eventType:i,success:n,failureType:r}){return s(this,void 0,void 0,(function*(){c.updateAppId((0,a.getGlobalData)("appID")||"unknown");const s=`/v2/products/${e.productKey}/devices/bluetooth-connect-data`,l=new Date,d={origin:"MINI-WX",mobileInfo:c.mobile,userInfo:null,appInfo:c.app,eventID:t,eventType:i,monitorTarget:{device:e,success:n,failureType:r},time:l,timeStamp:Math.floor(l.getTime()/1e3)};return(0,o.default)(s,{data:d,method:"POST"},!0)}))}},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{c(s.next(e))}catch(e){r(e)}}function o(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Connection=void 0;const r=n(i(5)),a=n(i(3)),o=n(i(9)),c=i(12);t.default=class{constructor({appID:e,token:t,uid:i,limitSocketNum:n=!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 r.default.GIZ_SDK_SDK_NOT_INITIALIZED;const t=this._bindingDevices[e];return null==t?r.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((0,c.isError)(t))return t;const i=this._getConnect(t);return null==i?r.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:r.default.MAX_CONNECT};i=new l({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((0,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(0,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(0,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(0,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(0,o.default)(`${s}`,{method:"GET"});if(n)return{err:n};const a=[...i,...(null==r?void 0:r.devices)||[]];return r&&r.devices.length===e?yield this._getBindingList(e,e+t,a):a})),this._getWebsocketConnInfo=e=>e.host?`wss://wx${e.host}`:"wss://wxstage.gizwits.com",this.appID=e,this.token=t,this.uid=i;const a=wx.getSystemInfoSync().SDKVersion;this._maxSocketNum=n?-1===(0,c.compareWXSDKVersion)(a||"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 r.default.GIZ_SDK_OTHERWISE}}))}};class l{constructor({appID:e,token:t,uid:i,wsInfo:n,onDeviceStatusChanged:r,onBindingChanged:o,onSocketStatusChanged:c}){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*(){a.default.log("network change",e)})),this._appShow=()=>s(this,void 0,void 0,(function*(){a.default.log("app show")})),this._addSubDid=e=>{this._subDids.add(e)},this._removeSubDid=e=>{this._subDids.delete(e)},this._connectWS=()=>{a.default.log("GIZ_SDK: start connect ws"),this._websocket=wx.connectSocket({url:this._wsUrl,fail:e=>{a.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)=>(a.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=>{a.default.log("GIZ_SDK: socket send res",e),a.default.log("resres",e);let t=!1;"sendSocketMessage:ok"===e.errMsg&&(t=!0),i({success:t,message:e.errMsg})},fail:e=>{a.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=>{a.default.error("GIZ_SDK: socket close",new Error(JSON.stringify(e))),this.close(),this._stopPing()},this.handleOpen=()=>{a.default.log(" socket open"),this._login()},this.handleMessage=({data:e})=>{a.default.log("GIZ_SDK: message",e);const t=JSON.parse(e),i=this._socketRespHandleMap[t.cmd];i&&i(t.data)},this.handleError=e=>{a.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?(a.default.log("GIZ_SDK: Login failed, will try again, please wait..."),this._tryLoginAgain()):(a.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=>{a.default.log("GIZ_SDK: subscribe_res",e),e&&e.success&&e.success.forEach(e=>this._send({cmd:"c2s_read",data:{did:e.did}})),a.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(),a.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=r,this._onBindingChanged=o,this._onSocketStatusChanged=c,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=l},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{c(s.next(e))}catch(e){r(e)}}function o(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.LanHandle=void 0;const r=n(i(3)),a=n(i(23)),o=n(i(65)),c=n(i(25)),l=n(i(4)),d=i(2),u=n(i(10)),h=i(12),f=n(i(28));class p extends f.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),r.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&&(r.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 v({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=>{r.default.warn("Discover Error",e)},this.isMatchPk=e=>0===this.pks.length||this.pks.includes(e),this.onMessage=e=>{const t=(0,h.ab2numbers)(e.message),i=new o.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*(){r.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:o.default.pack(),port:this.deviceUDPPort}),r.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=p;class v{constructor({ip:e,onClose:t,mac:i,productKey:n,onData:o}){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=a.default.pack();this.tcpHandler.write((0,d.arrayToUint8)(e)),r.default.debug("connect success try login")},i=t=>{e({success:!0,err:t})},s=t=>{switch(new l.default((0,h.ab2numbers)(t.message)).cmd){case"0007":{const e=new a.default((0,h.ab2numbers)(t.message)),i=c.default.pack({passcode:e.passcode});this.tcpHandler.write((0,d.arrayToUint8)(i));break}case"0009":new c.default((0,h.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(0,u.default)(4e3),e({success:!1,err:null})}catch(t){r.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=(0,h.ab2hex)(e.message),i=new l.default((0,d.hexStrint2byte)(t));r.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=n,this.onData=o,this.onCloseListener=t}}},function(e,t,i){"use strict";var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const n=s(i(3)),r=s(i(4)),a=i(2);class o extends r.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((0,a.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+=(0,a.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){n.default.warn("Parse DiscoverUDP error",e)}}}o.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=o},function(e,t,i){"use strict";var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const n=s(i(4)),r=i(2);class a extends n.default{}a.pack=()=>{const e=parseInt(`${Date.now()/1e3}`,10),t=(0,r.fillString)(e.toString(2),40);return[0,0,0,3,8,0,0,89].concat((0,r.completeBlock)(t))},t.default=a},function(e,t,i){"use strict";var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.CancelSync=t.DeletePackage=t.SyncPackage=t.RequestSync=void 0;const n=s(i(4)),r=i(2);class a extends n.default{constructor(e){super(e),this.state=0,this.len=0;let t=0;this.len=parseInt((0,r.arrayToString)(this.content.slice(t,t+2)),16),t+=2,this.state=this.content[t]}}t.RequestSync=a,a.pack=()=>[0,0,0,3,3,0,0,81];class o extends n.default{constructor(e){super(e),this.id=0,this.timestemp=0,this.payloadLen=0,this.payload=[];let t=0;this.id=parseInt((0,r.arrayToString)(this.content.slice(t,t+2)),16),t+=2,this.timestemp=parseInt((0,r.arrayToString)(this.content.slice(t,t+5)),16),t+=5,this.payloadLen=parseInt((0,r.arrayToString)(this.content.slice(t,t+2)),16),t+=2,this.payload=this.content.slice(t,this.content.length)}}t.SyncPackage=o,o.pack=e=>{let t=e.toString(2);return t=(0,r.fillString)(t,16),[0,0,0,3,5].concat([0,0,83]).concat((0,r.completeBlock)(t))};class c extends n.default{}t.DeletePackage=c,c.pack=e=>{let t=e.toString(2);return t=(0,r.fillString)(t,16),[0,0,0,3,5].concat([0,0,85]).concat((0,r.completeBlock)(t))};class l extends n.default{constructor(e){super(e),this.state=0,this.state=this.content[0]}}t.CancelSync=l,l.pack=()=>[0,0,0,3,3,0,0,87]},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=(0,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(0,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}),t.psKeySign=void 0;const s=i(11);t.psKeySign=e=>{const t=Math.round((new Date).getTime()/1e3),i=e+t;return{Signature:(0,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{c(s.next(e))}catch(e){r(e)}}function o(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.AnonymousLogin=void 0;const r=n(i(9));t.AnonymousLogin=function({uid:e}){return s(this,void 0,void 0,(function*(){return(0,r.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{c(s.next(e))}catch(e){r(e)}}function o(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.uploadP0=void 0;const r=n(i(9)),a=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 n=e.passcode;const o=a.enc.Hex.parse(i),c=a.enc.Hex.parse(""),l=a.enc.Utf8.parse(n);return n=a.AES.encrypt(l,o,{iv:c,mode:a.mode.ECB,padding:a.pad.Pkcs7}).ciphertext.toString().toUpperCase(),(0,r.default)(s,{data:{data:t,encoding:"hex"},method:"POST",headers:{"X-Gizwits-Device-Id":e.did,"X-Gizwits-Device-passcode":n}},!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{c(s.next(e))}catch(e){r(e)}}function o(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=n(i(5)),a=n(i(3)),o=n(i(30)),c=n(i(31));class l 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((n,c)=>{a.default.debug("GIZ_SDK: start config device");let l=!1,d=0;const u=o.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=>{d+=1,d>2&&(this.destroy(),c({success:!1,err:{errorCode:r.default.WECHAT_ERROR.errorCode,errorMessage:e.errMsg}}))});const f=()=>s(this,void 0,void 0,(function*(){if(!l){this.UDPSocketHandler.offMessage(),this.UDPSocketHandler.offError(),this.sendMessageInterval&&clearInterval(this.sendMessageInterval),this.disableSendUDP=!0,l=!0;try{const i=yield this.searchDevice({ssid:e,password:t});n(i)}catch(e){c(e)}}}));this.UDPSocketHandler.onMessage(e=>{f()}),wx.onNetworkStatusChange(()=>s(this,void 0,void 0,(function*(){!l&&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,o)=>s(this,void 0,void 0,(function*(){this.destroy(),this.initDeviceOnboardingDeploy(a,o),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){o(e)}else a({success:!0,data:e})}catch(e){o(e)}finally{this.destroy()}})))}}}t.default=l},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{c(s.next(e))}catch(e){r(e)}}function o(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.sendBLEConfigCmd=void 0;const r=n(i(5)),a=i(12),o=n(i(3)),c=n(i(30)),l=n(i(10)),d=i(27),u=n(i(31));function h({bleDeviceId:e,arrayBuffer:t,serviceUUIDSuffix:i="abf0",characteristicUUIDSuffix:n="abf7",bleHandle:r}){let c=null,l=null;const u=()=>null===l&&(c&&clearInterval(c),!0);return new Promise((h,f)=>s(this,void 0,void 0,(function*(){try{o.default.debug("GIZ_SDK: ssid info: ",t),l=setTimeout(()=>{c&&clearInterval(c),l=null,h(!1)},5e3),o.default.debug("GIZ_SDK: createBLEConnection start: ",e),yield r.disableScan();const s=yield(0,d.retryConnect)(e,1e4);r.enableScan(),o.default.debug("GIZ_SDK: createBLEConnection end, res:",s);const f=yield(0,d.getBLEDeviceServices)(e);o.default.debug("GIZ_SDK: getBLEDeviceServices end, res:",f);const p=f.find(e=>e.uuid.split("-")[0].toLowerCase().endsWith(i));if(!p)return o.default.debug("GIZ_SDK: get ble device services fail",e,f),void h(!1);const v=yield(0,d.getBLEDeviceCharacteristics)(e,p.uuid);o.default.debug("GIZ_SDK: getBLEDeviceCharacteristics end, res:",v);const g=v.find(e=>e.uuid.split("-")[0].toLowerCase().endsWith(n));if(!g)return o.default.debug("GIZ_SDK: get ble device characteristics fail",e,v),void h(!1);if(!g.properties.notify&&!g.properties.indicate)return o.default.debug("GIZ_SDK: the ble device characteristic not support notify or indicate",e,g),void h(!1);o.default.debug("GIZ_SDK: check characteristic and service success"),yield(0,d.notifyBLECharacteristicValueChange)(e,p.uuid,g.uuid);const y=e=>{const t=(0,a.ab2hex)(e.value);o.default.debug("GIZ_SDK: 收到设备返回ack",t),"0000000303000002"===t&&(r.removeEventListener("GizBleDeviceData",y),h(!0))};if(r.addEventListener("GizBleDeviceData",y),o.default.debug("GIZ_SDK: on notifyBLECharacteristicValueChange success"),u())return;yield(0,d.unpackWriteBLECharacteristicValue)(e,p.uuid,g.uuid,t),c=setInterval(()=>{u()||(0,d.unpackWriteBLECharacteristicValue)(e,p.uuid,g.uuid,t)},2e3),o.default.debug("GIZ_SDK: unpackWriteBLECharacteristicValue end")}catch(e){f(!1),o.default.debug("GIZ_SDK: sendBLEConfigCmd error",e)}}))).catch(e=>{o.default.debug("GIZ_SDK: sendBLEConfigCmd error",e)}).finally(()=>{l&&clearTimeout(l),c&&clearInterval(c),wx.closeBLEConnection({deviceId:e})})}t.sendBLEConfigCmd=h;class f extends u.default{constructor(e,t,i,n,u){super(e,t,i,n),this.destroy=()=>{this.cleanTimeout()},this.isValidBleDevice=(e,t)=>{if(!e||!e.advertisData)return!1;const{productKey:i,mac:s}=(0,a.advertisData2PkAndMac)(e.advertisData,this.specialProductKeys);return!!this.specialProductKeys.includes(i)&&(o.default.debug(`GIZ_SDK: isValidBleDevice mac: ${s} pk: ${i} name: ${e.name}`),o.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(0,d.getBluetoothAdapterState)()).available?(yield(0,d.startBluetoothDevicesDiscovery)(),{success:!0}):{success:!1,err:{errorCode:r.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;o.default.debug("GIZ_SDK: start enableAndGetBluetoothDevices");const i=(yield(0,d.getBluetoothDevices)()).filter(t=>this.isValidBleDevice(t,e));return o.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((n,u)=>s(this,void 0,void 0,(function*(){o.default.debug("GIZ_SDK: start config ble device");const f=yield this.enableAndGetBluetoothDevices(i).catch(e=>({success:!1,err:{errorCode:r.default.WECHAT_ERROR.errorCode,errorMessage:JSON.stringify(e)}}));if(!(0,a.isWXDevicesResult)(f))return u(f);const{bleDevices:p}=f;o.default.debug("GIZ_SDK: enableAndGetBluetoothDevices success, target devices: ",p);wx.onBluetoothDeviceFound(({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()})));const v=c.default.pack(e,t),g=()=>s(this,void 0,void 0,(function*(){if(o.default.debug("GIZ_SDK: startConfigDevice"),!this.hasTimeoutHandler())return;const e=p.shift();if(e&&o.default.debug("GIZ_SDK: startConfigDevice, target device: ",e),!(e&&(yield h({bleDeviceId:e.deviceId,arrayBuffer:v.buffer,bleHandle:this.bleHandle}))))return yield(0,l.default)(500),yield(0,d.startBluetoothDevicesDiscovery)(),void(yield g());o.default.debug("GIZ_SDK: offBluetoothDeviceFound ready search device"),wx.offBluetoothDeviceFound()}));try{this.searchDevice({ssid:e,password:t}).then(e=>{n(e)})}catch(e){u(e),o.default.error("GIZ_SDK: searchDevice error",new Error(JSON.stringify(e)))}yield g()}))),this.bleHandle=u}}t.default=f}]);
|
|
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,o=this._counter;r&&(o=this._counter=r.slice(0),this._iv=void 0),function(e){0===(e[0]=t(e[0]))&&(e[1]=t(e[1]))}(o);var a=o.slice(0);s.encryptBlock(a,0);for(var c=0;c<n;c++)e[i+c]^=a[c]}});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 o=0;o<s;o++)e[t+o]^=r[o]}}),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,o;e.exports=(o=i(0),i(1),n=(s=o).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})}},o.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=[],o=[],a=[],c=[],l=[],d=[],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;o[i]=_<<24|_>>>8,a[i]=_<<16|_>>>16,c[i]=_<<8|_>>>24,l[i]=_,_=16843009*y^65537*g^257*v^16843008*i,d[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=[],o=0;o<s;o++)o<i?r[o]=t[o]:(l=r[o-1],o%i?i>6&&o%i==4&&(l=n[l>>>24]<<24|n[l>>>16&255]<<16|n[l>>>8&255]<<8|n[255&l]):(l=n[(l=l<<8|l>>>24)>>>24]<<24|n[l>>>16&255]<<16|n[l>>>8&255]<<8|n[255&l],l^=p[o/i|0]<<24),r[o]=r[o-i]^l);for(var a=this._invKeySchedule=[],c=0;c<s;c++){if(o=s-c,c%4)var l=r[o];else l=r[o-4];a[c]=c<4||o<=4?l:d[n[l>>>24]]^u[n[l>>>16&255]]^h[n[l>>>8&255]]^f[n[255&l]]}}},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,o,a,c,l,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,d,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,o,a){for(var c=this._nRounds,l=e[t]^i[0],d=e[t+1]^i[1],u=e[t+2]^i[2],h=e[t+3]^i[3],f=4,p=1;p<c;p++){var v=s[l>>>24]^n[d>>>16&255]^r[u>>>8&255]^o[255&h]^i[f++],g=s[d>>>24]^n[u>>>16&255]^r[h>>>8&255]^o[255&l]^i[f++],y=s[u>>>24]^n[h>>>16&255]^r[l>>>8&255]^o[255&d]^i[f++],_=s[h>>>24]^n[l>>>16&255]^r[d>>>8&255]^o[255&u]^i[f++];l=v,d=g,u=y,h=_}v=(a[l>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&h])^i[f++],g=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[h>>>8&255]<<8|a[255&l])^i[f++],y=(a[u>>>24]<<24|a[h>>>16&255]<<16|a[l>>>8&255]<<8|a[255&d])^i[f++],_=(a[h>>>24]<<24|a[l>>>16&255]<<16|a[d>>>8&255]<<8|a[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,o=[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],a=[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],c=[1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28],l=[{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}],d=[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=o[i]-1;t[i]=e[s>>>5]>>>31-s%32&1}for(var n=this._subKeys=[],r=0;r<16;r++){var l=n[r]=[],d=c[r];for(i=0;i<24;i++)l[i/6|0]|=t[(a[i]-1+d)%28]<<31-i%6,l[4+(i/6|0)]|=t[28+(a[i+24]-1+d)%28]<<31-i%6;for(l[0]=l[0]<<1|l[0]>>>31,i=1;i<7;i++)l[i]=l[i]>>>4*(i-1)+3;l[7]=l[7]<<5|l[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,o=this._rBlock,a=0,c=0;c<8;c++)a|=l[c][((o^n[c])&d[c])>>>0];this._lBlock=o,this._rBlock=r^a}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 o=n%i,a=t[o>>>2]>>>24-o%4*8&255;r=(r+s[n]+a)%256;var c=s[n];s[n]=s[r],s[r]=c}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 o=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(o)}(),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=[],o=[],a=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++)c.call(this);for(i=0;i<8;i++)n[i]^=s[i+4&7];if(t){var r=t.words,o=r[0],a=r[1],l=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8),d=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),u=l>>>16|4294901760&d,h=d<<16|65535&l;for(n[0]^=l,n[1]^=u,n[2]^=d,n[3]^=h,n[4]^=l,n[5]^=u,n[6]^=d,n[7]^=h,i=0;i<4;i++)c.call(this)}},_doProcessBlock:function(e,t){var i=this._X;c.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 c(){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,a=s>>>16,c=((n*n>>>17)+n*a>>>15)+a*a,l=((4294901760&s)*s|0)+((65535&s)*s|0);o[i]=c^l}e[0]=o[0]+(o[7]<<16|o[7]>>>16)+(o[6]<<16|o[6]>>>16)|0,e[1]=o[1]+(o[0]<<8|o[0]>>>24)+o[7]|0,e[2]=o[2]+(o[1]<<16|o[1]>>>16)+(o[0]<<16|o[0]>>>16)|0,e[3]=o[3]+(o[2]<<8|o[2]>>>24)+o[1]|0,e[4]=o[4]+(o[3]<<16|o[3]>>>16)+(o[2]<<16|o[2]>>>16)|0,e[5]=o[5]+(o[4]<<8|o[4]>>>24)+o[3]|0,e[6]=o[6]+(o[5]<<16|o[5]>>>16)+(o[4]<<16|o[4]>>>16)|0,e[7]=o[7]+(o[6]<<8|o[6]>>>24)+o[5]|0}e.Rabbit=t._createHelper(a)}(),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=[],o=[],a=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++)c.call(this);for(n=0;n<8;n++)s[n]^=i[n+4&7];if(t){var r=t.words,o=r[0],a=r[1],l=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8),d=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),u=l>>>16|4294901760&d,h=d<<16|65535&l;for(s[0]^=l,s[1]^=u,s[2]^=d,s[3]^=h,s[4]^=l,s[5]^=u,s[6]^=d,s[7]^=h,n=0;n<4;n++)c.call(this)}},_doProcessBlock:function(e,t){var i=this._X;c.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 c(){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,a=s>>>16,c=((n*n>>>17)+n*a>>>15)+a*a,l=((4294901760&s)*s|0)+((65535&s)*s|0);o[i]=c^l}e[0]=o[0]+(o[7]<<16|o[7]>>>16)+(o[6]<<16|o[6]>>>16)|0,e[1]=o[1]+(o[0]<<8|o[0]>>>24)+o[7]|0,e[2]=o[2]+(o[1]<<16|o[1]>>>16)+(o[0]<<16|o[0]>>>16)|0,e[3]=o[3]+(o[2]<<8|o[2]>>>24)+o[1]|0,e[4]=o[4]+(o[3]<<16|o[3]>>>16)+(o[2]<<16|o[2]>>>16)|0,e[5]=o[5]+(o[4]<<8|o[4]>>>24)+o[3]|0,e[6]=o[6]+(o[5]<<16|o[5]>>>16)+(o[4]<<16|o[4]>>>16)|0,e[7]=o[7]+(o[6]<<8|o[6]>>>24)+o[5]|0}e.RabbitLegacy=t._createHelper(a)}(),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 o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=n(i(17)),o=n(i(4)),a=i(2);class c extends o.default{}c.pack=(e,t,i)=>s(void 0,void 0,void 0,(function*(){const s=yield r.default.getConfigFile(e);if(s){const e="var_len"===s.protocolType,n=[0,0,0,3],r=[0];let o=[0];const c=[0,147];let l=[0,0,0,0],d=[2];if(t){o=[1];const e=(0,a.fillString)(t.length.toString(16),4),i=(0,a.hexStrint2byte)(e),s=(0,a.string2Bytes)(t);l=l.concat(i).concat(s)}if(e){d=[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=(0,a.fillString)(e,8*Math.ceil(e.length/8)),d=d.concat((0,a.hexStrint2byte)(parseInt(e,2).toString(16)))}const u=o.concat(c).concat(l).concat(d);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 o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.reportEvent=void 0;const r=i(27),o=i(14),a=n(i(9));const c=new class{constructor(){wx.getSystemInfoAsync({success:e=>{this.app={wxSdkVersion:e.SDKVersion,gizwitsSdkVersion:r.version,appID:"unknown",bluetoothEnabled:e.bluetoothEnabled,locationEnabled:e.locationEnabled,wifiEnabled:e.wifiEnabled},this.mobile={brand:e.brand,model:e.model,pixelRatio:e.pixelRatio,systemVersion:e.system,platform:e.platform}}})}updateAppId(e){this.app.appID=e}};t.reportEvent=function({device:e,eventID:t,eventType:i,success:n,failureType:r}){return s(this,void 0,void 0,(function*(){c.updateAppId((0,o.getGlobalData)("appID")||"unknown");const s=`/v2/products/${e.productKey}/devices/bluetooth-connect-data`,l=new Date,d={origin:"MINI-WX",mobileInfo:c.mobile,userInfo:null,appInfo:c.app,eventID:t,eventType:i,monitorTarget:{device:e,success:n,failureType:r},time:l,timeStamp:Math.floor(l.getTime()/1e3)};return(0,a.default)(s,{data:d,method:"POST"},!0)}))}},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 o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Connection=void 0;const r=n(i(5)),o=n(i(3)),a=n(i(9)),c=i(12);t.default=class{constructor({appID:e,token:t,uid:i,limitSocketNum:n=!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 r.default.GIZ_SDK_SDK_NOT_INITIALIZED;const t=this._bindingDevices[e];return null==t?r.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((0,c.isError)(t))return t;const i=this._getConnect(t);return null==i?r.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:r.default.MAX_CONNECT};i=new l({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((0,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(0,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(0,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(0,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(0,a.default)(`${s}`,{method:"GET"});if(n)return{err:n};const o=[...i,...(null==r?void 0:r.devices)||[]];return r&&r.devices.length===e?yield this._getBindingList(e,e+t,o):o})),this._getWebsocketConnInfo=e=>e.host?`wss://wx${e.host}`:"wss://wxstage.gizwits.com",this.appID=e,this.token=t,this.uid=i;const o=wx.getSystemInfoSync().SDKVersion;this._maxSocketNum=n?-1===(0,c.compareWXSDKVersion)(o||"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 r.default.GIZ_SDK_OTHERWISE}}))}};class l{constructor({appID:e,token:t,uid:i,wsInfo:n,onDeviceStatusChanged:r,onBindingChanged:a,onSocketStatusChanged:c}){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*(){o.default.log("network change",e)})),this._appShow=()=>s(this,void 0,void 0,(function*(){o.default.log("app show")})),this._addSubDid=e=>{this._subDids.add(e)},this._removeSubDid=e=>{this._subDids.delete(e)},this._connectWS=()=>{o.default.log("GIZ_SDK: start connect ws"),this._websocket=wx.connectSocket({url:this._wsUrl,fail:e=>{o.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)=>(o.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=>{o.default.log("GIZ_SDK: socket send res",e),o.default.log("resres",e);let t=!1;"sendSocketMessage:ok"===e.errMsg&&(t=!0),i({success:t,message:e.errMsg})},fail:e=>{o.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=>{o.default.error("GIZ_SDK: socket close",new Error(JSON.stringify(e))),this.close(),this._stopPing()},this.handleOpen=()=>{o.default.log(" socket open"),this._login()},this.handleMessage=({data:e})=>{o.default.log("GIZ_SDK: message",e);const t=JSON.parse(e),i=this._socketRespHandleMap[t.cmd];i&&i(t.data)},this.handleError=e=>{o.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?(o.default.log("GIZ_SDK: Login failed, will try again, please wait..."),this._tryLoginAgain()):(o.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=>{o.default.log("GIZ_SDK: subscribe_res",e),e&&e.success&&e.success.forEach(e=>this._send({cmd:"c2s_read",data:{did:e.did}})),o.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(),o.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=r,this._onBindingChanged=a,this._onSocketStatusChanged=c,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=l},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 o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.LanHandle=void 0;const r=n(i(3)),o=n(i(24)),a=n(i(65)),c=n(i(26)),l=n(i(4)),d=i(2),u=n(i(10)),h=i(12),f=n(i(29));class p extends f.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),r.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&&(r.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 v({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=>{r.default.warn("Discover Error",e)},this.isMatchPk=e=>0===this.pks.length||this.pks.includes(e),this.onMessage=e=>{const t=(0,h.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*(){r.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}),r.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=p;class v{constructor({ip:e,onClose:t,mac:i,productKey:n,onData:a}){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=o.default.pack();this.tcpHandler.write((0,d.arrayToUint8)(e)),r.default.debug("connect success try login")},i=t=>{e({success:!0,err:t})},s=t=>{switch(new l.default((0,h.ab2numbers)(t.message)).cmd){case"0007":{const e=new o.default((0,h.ab2numbers)(t.message)),i=c.default.pack({passcode:e.passcode});this.tcpHandler.write((0,d.arrayToUint8)(i));break}case"0009":new c.default((0,h.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(0,u.default)(4e3),e({success:!1,err:null})}catch(t){r.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=(0,h.ab2hex)(e.message),i=new l.default((0,d.hexStrint2byte)(t));r.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=n,this.onData=a,this.onCloseListener=t}}},function(e,t,i){"use strict";var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const n=s(i(3)),r=s(i(4)),o=i(2);class a extends r.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((0,o.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+=(0,o.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){n.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";var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const n=s(i(4)),r=i(2);class o extends n.default{}o.pack=()=>{const e=parseInt(`${Date.now()/1e3}`,10),t=(0,r.fillString)(e.toString(2),40);return[0,0,0,3,8,0,0,89].concat((0,r.completeBlock)(t))},t.default=o},function(e,t,i){"use strict";var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.CancelSync=t.DeletePackage=t.SyncPackage=t.RequestSync=void 0;const n=s(i(4)),r=i(2);class o extends n.default{constructor(e){super(e),this.state=0,this.len=0;let t=0;this.len=parseInt((0,r.arrayToString)(this.content.slice(t,t+2)),16),t+=2,this.state=this.content[t]}}t.RequestSync=o,o.pack=()=>[0,0,0,3,3,0,0,81];class a extends n.default{constructor(e){super(e),this.id=0,this.timestemp=0,this.payloadLen=0,this.payload=[];let t=0;this.id=parseInt((0,r.arrayToString)(this.content.slice(t,t+2)),16),t+=2,this.timestemp=parseInt((0,r.arrayToString)(this.content.slice(t,t+5)),16),t+=5,this.payloadLen=parseInt((0,r.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=(0,r.fillString)(t,16),[0,0,0,3,5].concat([0,0,83]).concat((0,r.completeBlock)(t))};class c extends n.default{}t.DeletePackage=c,c.pack=e=>{let t=e.toString(2);return t=(0,r.fillString)(t,16),[0,0,0,3,5].concat([0,0,85]).concat((0,r.completeBlock)(t))};class l extends n.default{constructor(e){super(e),this.state=0,this.state=this.content[0]}}t.CancelSync=l,l.pack=()=>[0,0,0,3,3,0,0,87]},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=(0,s.MD5)(e+t).toString();n=s.enc.Hex.parse(n);let r=s.enc.Utf8.parse(i),o=s.AES.encrypt(r,n,{iv:n,mode:s.mode.ECB,padding:s.pad.ZeroPadding});return(0,s.MD5)(o.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}),t.psKeySign=void 0;const s=i(11);t.psKeySign=e=>{const t=Math.round((new Date).getTime()/1e3),i=e+t;return{Signature:(0,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 o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.AnonymousLogin=void 0;const r=n(i(9));t.AnonymousLogin=function({uid:e}){return s(this,void 0,void 0,(function*(){return(0,r.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 o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.uploadP0=void 0;const r=n(i(9)),o=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 n=e.passcode;const a=o.enc.Hex.parse(i),c=o.enc.Hex.parse(""),l=o.enc.Utf8.parse(n);return n=o.AES.encrypt(l,a,{iv:c,mode:o.mode.ECB,padding:o.pad.Pkcs7}).ciphertext.toString().toUpperCase(),(0,r.default)(s,{data:{data:t,encoding:"hex"},method:"POST",headers:{"X-Gizwits-Device-Id":e.did,"X-Gizwits-Device-passcode":n}},!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 o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=n(i(5)),o=n(i(3)),a=n(i(31)),c=n(i(18));class l 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((n,c)=>{o.default.debug("GIZ_SDK: start config device");let l=!1,d=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=>{d+=1,d>2&&(this.destroy(),c({success:!1,err:{errorCode:r.default.WECHAT_ERROR.errorCode,errorMessage:e.errMsg}}))});const f=()=>s(this,void 0,void 0,(function*(){if(!l){this.UDPSocketHandler.offMessage(),this.UDPSocketHandler.offError(),this.sendMessageInterval&&clearInterval(this.sendMessageInterval),this.disableSendUDP=!0,l=!0;try{const i=yield this.searchDevice({ssid:e,password:t});n(i)}catch(e){c(e)}}}));this.UDPSocketHandler.onMessage(e=>{f()}),wx.onNetworkStatusChange(()=>s(this,void 0,void 0,(function*(){!l&&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((o,a)=>s(this,void 0,void 0,(function*(){this.destroy(),this.initDeviceOnboardingDeploy(o,a),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{o(yield this.bindDevices(e))}catch(e){a(e)}else o({success:!0,data:e})}catch(e){a(e)}finally{this.destroy()}})))}}}t.default=l},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 o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.sendBLEConfigCmd=void 0;const r=n(i(5)),o=i(12),a=n(i(3)),c=n(i(31)),l=n(i(10)),d=i(28),u=n(i(18));function h({bleDeviceId:e,arrayBuffer:t,serviceUUIDSuffix:i="abf0",characteristicUUIDSuffix:n="abf7",bleHandle:r}){let c=null,l=null;const u=()=>null===l&&(c&&clearInterval(c),!0);return new Promise((h,f)=>s(this,void 0,void 0,(function*(){try{a.default.debug("GIZ_SDK: ssid info: ",t),l=setTimeout(()=>{c&&clearInterval(c),l=null,h(!1)},5e3),a.default.debug("GIZ_SDK: createBLEConnection start: ",e),yield r.disableScan();const s=yield(0,d.retryConnect)(e,1e4);r.enableScan(),a.default.debug("GIZ_SDK: createBLEConnection end, res:",s);const f=yield(0,d.getBLEDeviceServices)(e);a.default.debug("GIZ_SDK: getBLEDeviceServices end, res:",f);const p=f.find(e=>e.uuid.split("-")[0].toLowerCase().endsWith(i));if(!p)return a.default.debug("GIZ_SDK: get ble device services fail",e,f),void h(!1);const v=yield(0,d.getBLEDeviceCharacteristics)(e,p.uuid);a.default.debug("GIZ_SDK: getBLEDeviceCharacteristics end, res:",v);const g=v.find(e=>e.uuid.split("-")[0].toLowerCase().endsWith(n));if(!g)return a.default.debug("GIZ_SDK: get ble device characteristics fail",e,v),void h(!1);if(!g.properties.notify&&!g.properties.indicate)return a.default.debug("GIZ_SDK: the ble device characteristic not support notify or indicate",e,g),void h(!1);a.default.debug("GIZ_SDK: check characteristic and service success"),yield(0,d.notifyBLECharacteristicValueChange)(e,p.uuid,g.uuid);const y=e=>{const t=(0,o.ab2hex)(e.value);a.default.debug("GIZ_SDK: 收到设备返回ack",t),"0000000303000002"===t&&(r.removeEventListener("GizBleDeviceData",y),h(!0))};if(r.addEventListener("GizBleDeviceData",y),a.default.debug("GIZ_SDK: on notifyBLECharacteristicValueChange success"),u())return;yield(0,d.unpackWriteBLECharacteristicValue)(e,p.uuid,g.uuid,t),c=setInterval(()=>{u()||(0,d.unpackWriteBLECharacteristicValue)(e,p.uuid,g.uuid,t)},2e3),a.default.debug("GIZ_SDK: unpackWriteBLECharacteristicValue end")}catch(e){f(!1),a.default.debug("GIZ_SDK: sendBLEConfigCmd error",e)}}))).catch(e=>{a.default.debug("GIZ_SDK: sendBLEConfigCmd error",e)}).finally(()=>{l&&clearTimeout(l),c&&clearInterval(c),wx.closeBLEConnection({deviceId:e})})}t.sendBLEConfigCmd=h;class f extends u.default{constructor(e,t,i,n,u,f){super(e,t,i,n,u),this.destroy=()=>{this.cleanTimeout()},this.isValidBleDevice=(e,t)=>{if(!e||!e.advertisData)return!1;const{productKey:i,mac:s}=(0,o.advertisData2PkAndMac)(e.advertisData,this.specialProductKeys);return!!this.specialProductKeys.includes(i)&&(a.default.debug(`GIZ_SDK: isValidBleDevice mac: ${s} pk: ${i} name: ${e.name}`),a.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(0,d.getBluetoothAdapterState)()).available?(yield(0,d.startBluetoothDevicesDiscovery)(),{success:!0}):{success:!1,err:{errorCode:r.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;a.default.debug("GIZ_SDK: start enableAndGetBluetoothDevices");const i=(yield(0,d.getBluetoothDevices)()).filter(t=>this.isValidBleDevice(t,e));return a.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,o=this.password;this.destroy(),this.initDeviceOnboardingDeploy(n,r),this.startTimeoutTimer(e);try{const r=((yield this.configBLEDevice({ssid:s,password:o,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((n,u)=>s(this,void 0,void 0,(function*(){a.default.debug("GIZ_SDK: start config ble device");const f=yield this.enableAndGetBluetoothDevices(i).catch(e=>({success:!1,err:{errorCode:r.default.WECHAT_ERROR.errorCode,errorMessage:JSON.stringify(e)}}));if(!(0,o.isWXDevicesResult)(f))return u(f);const{bleDevices:p}=f;a.default.debug("GIZ_SDK: enableAndGetBluetoothDevices success, target devices: ",p);wx.onBluetoothDeviceFound(({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(()=>{})})));const v=c.default.pack(e,t),g=()=>s(this,void 0,void 0,(function*(){if(a.default.debug("GIZ_SDK: startConfigDevice"),!this.hasTimeoutHandler())return;const e=p.shift();if(e&&a.default.debug("GIZ_SDK: startConfigDevice, target device: ",e),!(e&&(yield h({bleDeviceId:e.deviceId,arrayBuffer:v.buffer,bleHandle:this.bleHandle}))))return yield(0,l.default)(500),yield(0,d.startBluetoothDevicesDiscovery)(),void(yield g());a.default.debug("GIZ_SDK: offBluetoothDeviceFound ready search device"),wx.offBluetoothDeviceFound(()=>{})}));try{this.searchDevice({ssid:e,password:t}).then(e=>{n(e)})}catch(e){u(e),a.default.error("GIZ_SDK: searchDevice error",new Error(JSON.stringify(e)))}yield g()}))),this.bleHandle=f}}t.default=f},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 o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const r=i(75),o=i(76),a=i(77),c=i(79),l=n(i(18));class d extends l.default{constructor(e,t,i,n,l,d){super(e,t,i,n,l),this.address="",this.destroy=()=>{this.cleanTimeout()},this.configDevice=({ssid:e,password:t,bssid:i,address:n})=>s(this,void 0,void 0,(function*(){const{SSIDTLV:s,isSSIDIncludedCH:l}=(0,a.formatSSID)(e),d=(0,o.formatData)(i,"BSSID"),u=(0,o.formatData)(t,"pwd"),h=(0,o.formatData)(n,"address"),f=(0,r.disposeData)(s,l,u,h,d);return console.log(f,"DATA"),(0,c.transceive)(f),yield this.searchDevice({ssid:e,password:t})})),this.setDeviceOnboardingDeploy=({timeout:e,isBind:t=!0})=>{const i=this.ssid,n=this.password;return new Promise((r,o)=>s(this,void 0,void 0,(function*(){console.log("ssid0",i,n,this.bssid,this.address),this.destroy(),this.initDeviceOnboardingDeploy(r,o),this.startTimeoutTimer(e),console.log("ssid",i,n,this.bssid,this.address);try{const e=((yield this.configDevice({ssid:i,password:n,bssid:this.bssid,address:this.address})).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{r(yield this.bindDevices(e))}catch(e){o(e)}else r({success:!0,data:e})}catch(e){o(e)}finally{this.destroy()}})))},this.address=d}}t.default=d},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.disposeData=void 0;t.disposeData=(e,t,i,s,n)=>{const r=(()=>{const e=new ArrayBuffer(1),t=new Uint8Array(e);return t[0]=1,t})(),o=(e=>{const t=new ArrayBuffer(1),i=new Uint8Array(t);return i[0]=0,e&&(i[0]=1),i})(t),a=(()=>{const e=new ArrayBuffer(2),t=new Uint8Array(e);return t[0]=parseInt("0x55",16),t[1]=parseInt("0xaa",16),t})(),c=Uint8Array.from([...r,...o,...a]),l=Uint8Array.from([...e,...i,...s,...n]);return console.log(c.buffer,"uint8Array_sign.buffer",c),console.log(l.buffer,"uint8Array_others.buffer",l),{ArrayBuffer_sign:c.buffer,ArrayBuffer_others:l.buffer}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.formatData=void 0;t.formatData=(e,t)=>{const i=0===e.length,s="BSSID"===t?e.split(":"):e.split("");let n=0,r=null,o=0;switch(t){case"BSSID":n=i?3:s.length+2,r="b",o=i?0:s.length;break;case"pwd":n=e.length+2,r="p",o=e.length;break;case"address":n=i?3:s.length+2,r="i",o=i?0:s.length}const a=new ArrayBuffer(n),c=new Uint8Array(a);return c[0]=r.charCodeAt(0),c[1]=o,i?c[2]=0:s.forEach((e,i)=>{const s="BSSID"===t?parseInt(e,16):e.charCodeAt(0);c[i+2]=s}),console.log(a,c,"formatData",t),c}},function(e,t,i){"use strict";var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.formatSSID=void 0;const n=i(2),r=s(i(78));t.formatSSID=e=>{const t={SSIDTLV:null,isSSIDIncludedCH:(0,r.default)(e)},[i,s]=(0,n.formatCodesFromStr)(e),o=parseInt((0,n.arrayToString)(s),16);if(o<=127){const e=new ArrayBuffer(o+2),s=new Uint8Array(e);s[0]="s".charCodeAt(0),s[1]=o,i.forEach((e,t)=>{s[t+2]=e}),t.SSIDTLV=s}else{const e=parseInt(s/255)+1,n=new ArrayBuffer(o+2+e),r=new Uint8Array(n);if(r[0]="s".charCodeAt(0),r[1]=128+e,1===e)r[2]=o;else{r[e]=255,r[e+1]=o-255*(e-1);for(let t=e;t>=1;t--)0===r[e-t]&&(r[e-t]=255)}i.forEach((t,i)=>{r[i+2+e]=t}),t.SSIDTLV=r}return t}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){return/.*[\u4e00-\u9fa5]+.*$/.test(e)}},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 o(e){try{c(s.next(e))}catch(e){r(e)}}function a(e){try{c(s.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}c((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.transceive=void 0;const n=i(80),r=i(81);t.transceive=e=>{const t=wx.getNFCAdapter();t.startDiscovery(),t.onDiscovered(i=>s(void 0,void 0,void 0,(function*(){console.log(i,"onDiscovered");let s=!0;const{success:o,nfcA:a}=yield(0,n.nfcAConnect)(t);if(o){const t=e.ArrayBuffer_others.byteLength,i=parseInt(t%4),n=parseInt(t/4);let o=n;const c=new Uint8Array(e.ArrayBuffer_others);for(let e=0;e<=4*n-4;e+=4){if(o>0){const t=new ArrayBuffer(6),i=new Uint8Array(t),l=49+n-o;i[0]=parseInt("0xa2",16),i[1]=l,i[2]=c[0+e],i[3]=c[1+e],i[4]=c[2+e],i[5]=c[3+e];const{transceiveSuccess:d}=yield(0,r.nfcATransceive)(a,t);if(o-=1,!d){s=!1,wx.hideLoading(),wx.showToast({title:"NFC写入失败!",icon:"error",duration:2e3});break}}if(0!==i&&s){const e=new ArrayBuffer(6),s=new Uint8Array(e),o=49+n;switch(s[0]=parseInt("0xa2",16),s[1]=o,i){case 1:s[2]=c[t-1];break;case 2:s[2]=c[t-2],s[3]=c[t-1];break;case 3:s[2]=c[t-3],s[3]=c[t-2],s[4]=c[t-1]}const{transceiveSuccess:l}=yield(0,r.nfcATransceive)(a,e);l||(wx.hideLoading(),wx.showToast({title:"NFC写入失败!",icon:"error",duration:2e3}))}}const l=new ArrayBuffer(6),d=new Uint8Array(l),u=new Uint8Array(e.ArrayBuffer_sign);d[0]=parseInt("0xa2",16),d[1]=48,d[2]=u[0],d[3]=u[1],d[4]=u[2],d[5]=u[3];const{transceiveSuccess:h}=yield(0,r.nfcATransceive)(a,l);wx.hideLoading(),wx.showToast(h?{title:"NFC写入成功!",icon:"success",duration:2e3}:{title:"NFC写入失败!",icon:"error",duration:2e3}),a.close()}else wx.hideLoading(),wx.showToast({title:"NFC连接失败!",icon:"error",duration:2e3})})))}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.nfcAConnect=void 0;t.nfcAConnect=e=>new Promise(t=>{const i=e.getNfcA();i.connect({success(){t({success:!0,nfcA:i})},fail(){t({success:!1,nfcA:i})}})})},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.nfcATransceive=void 0;t.nfcATransceive=(e,t)=>new Promise(i=>{e.transceive({data:t,success:e=>{console.log("success",e),i({transceiveSuccess:!0})},fail:e=>{console.log("fail",e),i({transceiveSuccess:!1})}})})}]);
|