@secux/transport-webble
Advanced tools
Comparing version 3.2.6 to 3.3.0
@@ -18,2 +18,2 @@ "use strict"; | ||
limitations under the License. | ||
*/var _SecuxWebBLE_instances,_SecuxWebBLE_device,_SecuxWebBLE_mcuVersion,_SecuxWebBLE_seVersion,_SecuxWebBLE_model,_SecuxWebBLE_deviceId,_SecuxWebBLE_customerId,_SecuxWebBLE_reader,_SecuxWebBLE_writer,_SecuxWebBLE_type,_SecuxWebBLE_connected,_SecuxWebBLE_OnConnected,_SecuxWebBLE_OnDisconnected,_SecuxWebBLE_handleNotifications,_SecuxWebBLE_checkPairing,_SecuxWebBLE_identify,_SecuxWebBLE_setDeviceInfo,__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(receiver,state,value,kind,f){if("m"===kind)throw new TypeError("Private method is not writable");if("a"===kind&&!f)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof state?receiver!==state||!f:!state.has(receiver))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===kind?f.call(receiver,value):f?f.value=value:state.set(receiver,value),value},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(receiver,state,kind,f){if("a"===kind&&!f)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof state?receiver!==state||!f:!state.has(receiver))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===kind?f:"a"===kind?f.call(receiver):f?f.value:state.get(receiver)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SecuxWebBLE=void 0;const transport_1=require("@secux/transport"),interface_1=require("@secux/transport/lib/interface"),communication_1=require("@secux/utility/lib/communication"),protocol_device_1=require("@secux/protocol-device"),interface_2=require("./interface"),callback=()=>{};class SecuxWebBLE extends transport_1.ITransport{constructor(device,OnConnected,OnDisconnected){super(),_SecuxWebBLE_instances.add(this),_SecuxWebBLE_device.set(this,void 0),_SecuxWebBLE_mcuVersion.set(this,""),_SecuxWebBLE_seVersion.set(this,""),_SecuxWebBLE_model.set(this,""),_SecuxWebBLE_deviceId.set(this,""),_SecuxWebBLE_customerId.set(this,""),_SecuxWebBLE_reader.set(this,void 0),_SecuxWebBLE_writer.set(this,void 0),_SecuxWebBLE_type.set(this,void 0),_SecuxWebBLE_connected.set(this,!1),_SecuxWebBLE_OnConnected.set(this,void 0),_SecuxWebBLE_OnDisconnected.set(this,void 0),_SecuxWebBLE_handleNotifications.set(this,(event=>{var _a;const value=null===(_a=event.target)||void 0===_a?void 0:_a.value;value.buffer&&this.ReceiveData(Buffer.from(value.buffer))})),__classPrivateFieldSet(this,_SecuxWebBLE_device,device,"f"),__classPrivateFieldSet(this,_SecuxWebBLE_OnConnected,null!=OnConnected?OnConnected:callback,"f"),__classPrivateFieldSet(this,_SecuxWebBLE_OnDisconnected,null!=OnDisconnected?OnDisconnected:callback,"f"),__classPrivateFieldGet(this,_SecuxWebBLE_device,"f").addEventListener("gattserverdisconnected",(()=>{__classPrivateFieldGet(this,_SecuxWebBLE_reader,"f").removeEventListener("characteristicvaluechanged",__classPrivateFieldGet(this,_SecuxWebBLE_handleNotifications,"f")),__classPrivateFieldSet(this,_SecuxWebBLE_reader,void 0,"f"),__classPrivateFieldSet(this,_SecuxWebBLE_writer,void 0,"f"),__classPrivateFieldGet(this,_SecuxWebBLE_connected,"f")&&__classPrivateFieldGet(this,_SecuxWebBLE_OnDisconnected,"f").call(this)}))}static async Create(OnConnected,OnDisconnected,devices){const filters=(null!=devices?devices:[interface_1.DeviceType.crypto]).map((x=>({services:[interface_2.Devices[x].SERVICE]}))),device=await navigator.bluetooth.requestDevice({filters,optionalServices:[...Object.values(interface_2.Devices).map((x=>x.PRIMARY))]});return new SecuxWebBLE(device,null!=OnConnected?OnConnected:callback,null!=OnDisconnected?OnDisconnected:callback)}async Connect(){const server=await __classPrivateFieldGet(this,_SecuxWebBLE_device,"f").gatt.connect();if(!server)throw Error("Cannot connect to device: BluetoothDevice.gatt is undefined");const services=await server.getPrimaryServices(),{service,uuid}=__classPrivateFieldGet(this,_SecuxWebBLE_instances,"m",_SecuxWebBLE_identify).call(this,services);__classPrivateFieldSet(this,_SecuxWebBLE_reader,await service.getCharacteristic(uuid.TX),"f"),__classPrivateFieldSet(this,_SecuxWebBLE_writer,await service.getCharacteristic(uuid.RX),"f"),__classPrivateFieldSet(this,_SecuxWebBLE_type,uuid.TYPE,"f"),this.version=uuid.PROTOCOL,this.packetSize=uuid.PACKET,transport_1.ITransport.deviceType=__classPrivateFieldGet(this,_SecuxWebBLE_type,"f"),await __classPrivateFieldGet(this,_SecuxWebBLE_reader,"f").startNotifications(),__classPrivateFieldGet(this,_SecuxWebBLE_reader,"f").addEventListener("characteristicvaluechanged",__classPrivateFieldGet(this,_SecuxWebBLE_handleNotifications,"f")),__classPrivateFieldGet(this,_SecuxWebBLE_type,"f")===interface_1.DeviceType.nifty&&(await __classPrivateFieldGet(this,_SecuxWebBLE_instances,"m",_SecuxWebBLE_checkPairing).call(this),await __classPrivateFieldGet(this,_SecuxWebBLE_instances,"m",_SecuxWebBLE_setDeviceInfo).call(this)),__classPrivateFieldSet(this,_SecuxWebBLE_connected,!0,"f"),__classPrivateFieldGet(this,_SecuxWebBLE_OnConnected,"f").call(this)}async Disconnect(){__classPrivateFieldGet(this,_SecuxWebBLE_device,"f").gatt.disconnect(),__classPrivateFieldSet(this,_SecuxWebBLE_reader,void 0,"f"),__classPrivateFieldSet(this,_SecuxWebBLE_writer,void 0,"f"),__classPrivateFieldSet(this,_SecuxWebBLE_connected,!1,"f")}async Write(data){await __classPrivateFieldGet(this,_SecuxWebBLE_writer,"f").writeValueWithoutResponse(data),await new Promise((resolve=>setTimeout(resolve,1)))}async SendOTP(otp){const recv=await this.Exchange(Buffer.from(otp)),dataLength=recv.readUInt16LE(0),status=recv.readUInt16BE(2+dataLength);if(status!==communication_1.StatusCode.SUCCESS)throw new communication_1.TransportStatusError(status);return await __classPrivateFieldGet(this,_SecuxWebBLE_instances,"m",_SecuxWebBLE_setDeviceInfo).call(this),!0}get CustomerId(){return __classPrivateFieldGet(this,_SecuxWebBLE_customerId,"f")}get DeviceName(){return __classPrivateFieldGet(this,_SecuxWebBLE_device,"f").name}get DeviceType(){var _a;return null!==(_a=__classPrivateFieldGet(this,_SecuxWebBLE_type,"f"))&&void 0!==_a?_a:""}get DeviceId(){return __classPrivateFieldGet(this,_SecuxWebBLE_deviceId,"f")}get Model(){return __classPrivateFieldGet(this,_SecuxWebBLE_model,"f")}get MCU(){return __classPrivateFieldGet(this,_SecuxWebBLE_mcuVersion,"f")}get SE(){return __classPrivateFieldGet(this,_SecuxWebBLE_seVersion,"f")}}exports.SecuxWebBLE=SecuxWebBLE,_SecuxWebBLE_device=new WeakMap,_SecuxWebBLE_mcuVersion=new WeakMap,_SecuxWebBLE_seVersion=new WeakMap,_SecuxWebBLE_model=new WeakMap,_SecuxWebBLE_deviceId=new WeakMap,_SecuxWebBLE_customerId=new WeakMap,_SecuxWebBLE_reader=new WeakMap,_SecuxWebBLE_writer=new WeakMap,_SecuxWebBLE_type=new WeakMap,_SecuxWebBLE_connected=new WeakMap,_SecuxWebBLE_OnConnected=new WeakMap,_SecuxWebBLE_OnDisconnected=new WeakMap,_SecuxWebBLE_handleNotifications=new WeakMap,_SecuxWebBLE_instances=new WeakSet,_SecuxWebBLE_checkPairing=async function(){const echoTest=async()=>{const payload=Buffer.from([112,97,105,114,105,110,103]),data=Buffer.from([130+payload.length,248,8,...payload]);await this.Write(data);let rsp=await this.Read();for(;!rsp;)rsp=await this.Read(),await new Promise((resolve=>setTimeout(resolve,1)));return data[1]=0,!!data.equals(rsp.slice(0,data.length))};for(let i=0;i<24;i++){if(!__classPrivateFieldGet(this,_SecuxWebBLE_reader,"f")||!__classPrivateFieldGet(this,_SecuxWebBLE_writer,"f")){const server=await __classPrivateFieldGet(this,_SecuxWebBLE_device,"f").gatt.connect();if(!server)throw Error("Cannot connect to device: BluetoothDevice.gatt is undefined");const info=interface_2.Devices[interface_1.DeviceType.nifty],service=await server.getPrimaryService(info.PRIMARY);__classPrivateFieldSet(this,_SecuxWebBLE_reader,await service.getCharacteristic(info.TX),"f"),__classPrivateFieldSet(this,_SecuxWebBLE_writer,await service.getCharacteristic(info.RX),"f"),await __classPrivateFieldGet(this,_SecuxWebBLE_reader,"f").startNotifications(),__classPrivateFieldGet(this,_SecuxWebBLE_reader,"f").addEventListener("characteristicvaluechanged",__classPrivateFieldGet(this,_SecuxWebBLE_handleNotifications,"f"))}try{if(await Promise.race([echoTest(),new Promise((resolve=>setTimeout(resolve,5e3)))]))return}catch(e){}}throw Error("bluetooth pairing error")},_SecuxWebBLE_identify=function(services){for(const uuid of Object.values(interface_2.Devices)){const service=services.find((x=>x.uuid===uuid.PRIMARY));if(service)return{service,uuid}}throw Error("Cannot find related GATTService")},_SecuxWebBLE_setDeviceInfo=async function(){const data=protocol_device_1.SecuxDevice.prepareGetVersion(),rsp=await this.Exchange((0,communication_1.getBuffer)(data)),{mcuFwVersion,seFwVersion,model,deviceId,customerId}=protocol_device_1.SecuxDevice.resolveVersion(rsp);__classPrivateFieldSet(this,_SecuxWebBLE_mcuVersion,mcuFwVersion,"f"),__classPrivateFieldSet(this,_SecuxWebBLE_seVersion,seFwVersion,"f"),model&&__classPrivateFieldSet(this,_SecuxWebBLE_model,model,"f"),deviceId&&__classPrivateFieldSet(this,_SecuxWebBLE_deviceId,deviceId,"f"),__classPrivateFieldSet(this,_SecuxWebBLE_customerId,customerId||await this.getCustomerId(),"f"),transport_1.ITransport.mcuVersion=mcuFwVersion,transport_1.ITransport.seVersion=seFwVersion}; | ||
*/var _SecuxWebBLE_instances,_SecuxWebBLE_device,_SecuxWebBLE_mcuVersion,_SecuxWebBLE_seVersion,_SecuxWebBLE_model,_SecuxWebBLE_deviceId,_SecuxWebBLE_customerId,_SecuxWebBLE_reader,_SecuxWebBLE_writer,_SecuxWebBLE_type,_SecuxWebBLE_connected,_SecuxWebBLE_OnConnected,_SecuxWebBLE_OnDisconnected,_SecuxWebBLE_handleNotifications,_SecuxWebBLE_checkPairing,_SecuxWebBLE_identify,_SecuxWebBLE_setDeviceInfo,__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(receiver,state,value,kind,f){if("m"===kind)throw new TypeError("Private method is not writable");if("a"===kind&&!f)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof state?receiver!==state||!f:!state.has(receiver))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===kind?f.call(receiver,value):f?f.value=value:state.set(receiver,value),value},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(receiver,state,kind,f){if("a"===kind&&!f)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof state?receiver!==state||!f:!state.has(receiver))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===kind?f:"a"===kind?f.call(receiver):f?f.value:state.get(receiver)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SecuxWebBLE=void 0;const transport_1=require("@secux/transport"),interface_1=require("@secux/transport/lib/interface"),communication_1=require("@secux/utility/lib/communication"),protocol_device_1=require("@secux/protocol-device"),interface_2=require("./interface"),callback=()=>{};class SecuxWebBLE extends transport_1.ITransport{constructor(device,OnConnected,OnDisconnected){super(),_SecuxWebBLE_instances.add(this),_SecuxWebBLE_device.set(this,void 0),_SecuxWebBLE_mcuVersion.set(this,""),_SecuxWebBLE_seVersion.set(this,""),_SecuxWebBLE_model.set(this,""),_SecuxWebBLE_deviceId.set(this,""),_SecuxWebBLE_customerId.set(this,""),_SecuxWebBLE_reader.set(this,void 0),_SecuxWebBLE_writer.set(this,void 0),_SecuxWebBLE_type.set(this,void 0),_SecuxWebBLE_connected.set(this,!1),_SecuxWebBLE_OnConnected.set(this,void 0),_SecuxWebBLE_OnDisconnected.set(this,void 0),_SecuxWebBLE_handleNotifications.set(this,(event=>{var _a;const value=null===(_a=event.target)||void 0===_a?void 0:_a.value;value.buffer&&this.ReceiveData(Buffer.from(value.buffer))})),__classPrivateFieldSet(this,_SecuxWebBLE_device,device,"f"),__classPrivateFieldSet(this,_SecuxWebBLE_OnConnected,null!=OnConnected?OnConnected:callback,"f"),__classPrivateFieldSet(this,_SecuxWebBLE_OnDisconnected,null!=OnDisconnected?OnDisconnected:callback,"f"),__classPrivateFieldGet(this,_SecuxWebBLE_device,"f").addEventListener("gattserverdisconnected",(()=>{__classPrivateFieldGet(this,_SecuxWebBLE_reader,"f").removeEventListener("characteristicvaluechanged",__classPrivateFieldGet(this,_SecuxWebBLE_handleNotifications,"f")),__classPrivateFieldSet(this,_SecuxWebBLE_reader,void 0,"f"),__classPrivateFieldSet(this,_SecuxWebBLE_writer,void 0,"f"),__classPrivateFieldGet(this,_SecuxWebBLE_connected,"f")&&__classPrivateFieldGet(this,_SecuxWebBLE_OnDisconnected,"f").call(this)}))}static async Create(OnConnected,OnDisconnected,devices){const filters=(null!=devices?devices:[interface_1.DeviceType.crypto]).map((x=>({services:[interface_2.Devices[x].SERVICE]}))),device=await navigator.bluetooth.requestDevice({filters,optionalServices:[...Object.values(interface_2.Devices).map((x=>x.PRIMARY))]});return new SecuxWebBLE(device,null!=OnConnected?OnConnected:callback,null!=OnDisconnected?OnDisconnected:callback)}async Connect(){const server=await __classPrivateFieldGet(this,_SecuxWebBLE_device,"f").gatt.connect();if(!server)throw Error("Cannot connect to device: BluetoothDevice.gatt is undefined");const services=await server.getPrimaryServices(),{service,uuid}=__classPrivateFieldGet(this,_SecuxWebBLE_instances,"m",_SecuxWebBLE_identify).call(this,services);__classPrivateFieldSet(this,_SecuxWebBLE_reader,await service.getCharacteristic(uuid.TX),"f"),__classPrivateFieldSet(this,_SecuxWebBLE_writer,await service.getCharacteristic(uuid.RX),"f"),__classPrivateFieldSet(this,_SecuxWebBLE_type,uuid.TYPE,"f"),this.version=uuid.PROTOCOL,this.packetSize=uuid.PACKET,transport_1.ITransport.deviceType=__classPrivateFieldGet(this,_SecuxWebBLE_type,"f"),await __classPrivateFieldGet(this,_SecuxWebBLE_reader,"f").startNotifications(),__classPrivateFieldGet(this,_SecuxWebBLE_reader,"f").addEventListener("characteristicvaluechanged",__classPrivateFieldGet(this,_SecuxWebBLE_handleNotifications,"f")),__classPrivateFieldGet(this,_SecuxWebBLE_type,"f")===interface_1.DeviceType.nifty&&(await __classPrivateFieldGet(this,_SecuxWebBLE_instances,"m",_SecuxWebBLE_checkPairing).call(this),await __classPrivateFieldGet(this,_SecuxWebBLE_instances,"m",_SecuxWebBLE_setDeviceInfo).call(this)),__classPrivateFieldSet(this,_SecuxWebBLE_connected,!0,"f"),__classPrivateFieldGet(this,_SecuxWebBLE_OnConnected,"f").call(this)}async Disconnect(){__classPrivateFieldGet(this,_SecuxWebBLE_device,"f").gatt.disconnect(),__classPrivateFieldSet(this,_SecuxWebBLE_reader,void 0,"f"),__classPrivateFieldSet(this,_SecuxWebBLE_writer,void 0,"f"),__classPrivateFieldSet(this,_SecuxWebBLE_connected,!1,"f")}async Write(data){await __classPrivateFieldGet(this,_SecuxWebBLE_writer,"f").writeValueWithoutResponse(data),await new Promise((resolve=>setTimeout(resolve,1)))}async SendOTP(otp){const recv=await this.Exchange(Buffer.from(otp)),dataLength=recv.readUInt16LE(0),status=recv.readUInt16BE(2+dataLength);if(status!==communication_1.StatusCode.SUCCESS)throw new communication_1.TransportStatusError(status);return await __classPrivateFieldGet(this,_SecuxWebBLE_instances,"m",_SecuxWebBLE_setDeviceInfo).call(this),!0}get CustomerId(){return __classPrivateFieldGet(this,_SecuxWebBLE_customerId,"f")}get DeviceName(){return __classPrivateFieldGet(this,_SecuxWebBLE_device,"f").name}get DeviceType(){var _a;return null!==(_a=__classPrivateFieldGet(this,_SecuxWebBLE_type,"f"))&&void 0!==_a?_a:""}get DeviceId(){return __classPrivateFieldGet(this,_SecuxWebBLE_deviceId,"f")}get Model(){return __classPrivateFieldGet(this,_SecuxWebBLE_model,"f")}get MCU(){return __classPrivateFieldGet(this,_SecuxWebBLE_mcuVersion,"f")}get SE(){return __classPrivateFieldGet(this,_SecuxWebBLE_seVersion,"f")}}exports.SecuxWebBLE=SecuxWebBLE,_SecuxWebBLE_device=new WeakMap,_SecuxWebBLE_mcuVersion=new WeakMap,_SecuxWebBLE_seVersion=new WeakMap,_SecuxWebBLE_model=new WeakMap,_SecuxWebBLE_deviceId=new WeakMap,_SecuxWebBLE_customerId=new WeakMap,_SecuxWebBLE_reader=new WeakMap,_SecuxWebBLE_writer=new WeakMap,_SecuxWebBLE_type=new WeakMap,_SecuxWebBLE_connected=new WeakMap,_SecuxWebBLE_OnConnected=new WeakMap,_SecuxWebBLE_OnDisconnected=new WeakMap,_SecuxWebBLE_handleNotifications=new WeakMap,_SecuxWebBLE_instances=new WeakSet,_SecuxWebBLE_checkPairing=async function(){const echoTest=async()=>{const payload=Buffer.from([112,97,105,114,105,110,103]),data=Buffer.from([130+payload.length,248,8,...payload]);await this.Write(data);let rsp=await this.Read();for(;!rsp;)rsp=await this.Read(),await new Promise((resolve=>setTimeout(resolve,1)));return data[1]=0,!!data.equals(rsp.slice(0,data.length))};for(let i=0;i<24;i++){if(!__classPrivateFieldGet(this,_SecuxWebBLE_reader,"f")||!__classPrivateFieldGet(this,_SecuxWebBLE_writer,"f")){const server=await __classPrivateFieldGet(this,_SecuxWebBLE_device,"f").gatt.connect();if(!server)throw Error("Cannot connect to device: BluetoothDevice.gatt is undefined");const info=interface_2.Devices[interface_1.DeviceType.nifty],service=await server.getPrimaryService(info.PRIMARY);__classPrivateFieldSet(this,_SecuxWebBLE_reader,await service.getCharacteristic(info.TX),"f"),__classPrivateFieldSet(this,_SecuxWebBLE_writer,await service.getCharacteristic(info.RX),"f"),await __classPrivateFieldGet(this,_SecuxWebBLE_reader,"f").startNotifications(),__classPrivateFieldGet(this,_SecuxWebBLE_reader,"f").addEventListener("characteristicvaluechanged",__classPrivateFieldGet(this,_SecuxWebBLE_handleNotifications,"f"))}try{if(await Promise.race([echoTest(),new Promise((resolve=>setTimeout(resolve,5e3)))]))return}catch(e){}}throw Error("bluetooth pairing error")},_SecuxWebBLE_identify=function(services){for(const uuid of Object.values(interface_2.Devices)){const service=services.find((x=>x.uuid===uuid.PRIMARY));if(service)return{service,uuid}}throw Error("Cannot find related GATTService")},_SecuxWebBLE_setDeviceInfo=async function(){const data=protocol_device_1.SecuxDevice.prepareGetVersion(),rsp=await this.Exchange((0,communication_1.getBuffer)(data)),{mcuFwVersion,seFwVersion,model,deviceId,customerId}=protocol_device_1.SecuxDevice.resolveVersion(rsp);__classPrivateFieldSet(this,_SecuxWebBLE_mcuVersion,mcuFwVersion,"f"),__classPrivateFieldSet(this,_SecuxWebBLE_seVersion,seFwVersion,"f"),model&&__classPrivateFieldSet(this,_SecuxWebBLE_model,model,"f"),deviceId&&__classPrivateFieldSet(this,_SecuxWebBLE_deviceId,deviceId,"f"),__classPrivateFieldSet(this,_SecuxWebBLE_customerId,customerId||await this.getCustomerId(),"f"),["C20"].includes(__classPrivateFieldGet(this,_SecuxWebBLE_model,"f"))&&(__classPrivateFieldSet(this,_SecuxWebBLE_type,interface_1.DeviceType.shield,"f"),transport_1.ITransport.deviceType=interface_1.DeviceType.shield),transport_1.ITransport.mcuVersion=mcuFwVersion,transport_1.ITransport.seVersion=seFwVersion}; |
{ | ||
"name": "@secux/transport-webble", | ||
"version": "3.2.6", | ||
"version": "3.3.0", | ||
"description": "Secux Hardware Wallet webBLE API for communication layer", | ||
@@ -33,3 +33,3 @@ "keywords": [ | ||
"@secux/protocol-device": "^3.6.0", | ||
"@secux/transport": "^3.3.6" | ||
"@secux/transport": "^3.3.11" | ||
}, | ||
@@ -36,0 +36,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27283
Updated@secux/transport@^3.3.11