From 3a9992ed2ee6eb5c40478131ad50399c79e938d2 Mon Sep 17 00:00:00 2001 From: Christopher Koch Date: Fri, 7 Nov 2025 17:50:12 +0100 Subject: [PATCH 1/4] refactor: update dependencies to use local paths for mtrust packages --- lib/src/sec_reader.dart | 249 ++++------------------------------------ pubspec.yaml | 12 +- 2 files changed, 29 insertions(+), 232 deletions(-) diff --git a/lib/src/sec_reader.dart b/lib/src/sec_reader.dart index f3e10d2..ad6026e 100644 --- a/lib/src/sec_reader.dart +++ b/lib/src/sec_reader.dart @@ -97,236 +97,29 @@ class SECReader extends CmdWrapper { return SECReader(connectionStrategy: connectionStrategy); } - Future _addCommandToQueue({ - UrpCoreCommand? coreCommand, - UrpSecDeviceCommand? deviceCommand, - }) async { + @override + Future addCoreCmdToQueue( + UrpCoreCommand coreCommand, + ) async { return connectionStrategy.addQueue( UrpSecCommandWrapper( coreCommand: coreCommand, - deviceCommand: deviceCommand, ).writeToBuffer(), target, origin, ); } - /// Pings the device. - @override - Future ping() async { - final cmd = UrpCoreCommand( - command: UrpCommand.urpPing, - ); - await _addCommandToQueue(coreCommand: cmd); - } - - /// Returns the device info. Throws an error if failed. - @override - Future info() async { - final cmd = UrpCoreCommand( - command: UrpCommand.urpGetInfo, - ); - final res = await _addCommandToQueue(coreCommand: cmd); - - if (!res.hasPayload()) { - throw SecReaderException(message: 'Failed to get info'); - } - return UrpDeviceInfo.fromBuffer(res.payload); - } - - /// Returns the power state of the device. Throws an error if failed. - @override - Future getPower() async { - final cmd = UrpCoreCommand( - command: UrpCommand.urpGetPower, - ); - final res = await _addCommandToQueue(coreCommand: cmd); - - if (!res.hasPayload()) { - throw SecReaderException(message: 'Failed to get power state'); - } - return UrpPowerState.fromBuffer(res.payload); - } - - /// Sets the name of the device. - @override - Future setName(String? name) async { - final cmd = UrpCoreCommand( - command: UrpCommand.urpSetName, - setNameParameters: UrpSetNameParameters(name: name), - ); - await _addCommandToQueue(coreCommand: cmd); - } - - /// Returns the devic name. Throws an error if failed. - @override - Future getName() async { - final cmd = UrpCoreCommand( - command: UrpCommand.urpGetName, - ); - final res = await _addCommandToQueue(coreCommand: cmd); - - if (!res.hasPayload()) { - throw SecReaderException(message: 'Failed to get name'); - } - return UrpDeviceName.fromBuffer(res.payload); - } - - /// Pair the device. - @override - Future pair() async { - final cmd = UrpCoreCommand( - command: UrpCommand.urpPair, - ); - await _addCommandToQueue(coreCommand: cmd); - } - - /// Unpair the device. - @override - Future unpair() async { - final cmd = UrpCoreCommand( - command: UrpCommand.urpUnpair, - ); - await _addCommandToQueue(coreCommand: cmd); - } - - /// Starts the DFU mode of the device. - @override - Future startDFU() async { - final cmd = UrpCoreCommand( - command: UrpCommand.urpStartDfu, - ); - await _addCommandToQueue(coreCommand: cmd); - } - - /// Stops the DFU mode of the device. - @override - Future stopDFU() async { - final cmd = UrpCoreCommand( - command: UrpCommand.urpStopDfu, - ); - await _addCommandToQueue(coreCommand: cmd); - } - - /// Puts the device to sleep mode. This will disconnect the device. - @override - Future sleep() async { - final cmd = UrpCoreCommand( - command: UrpCommand.urpSleep, - ); - await _addCommandToQueue(coreCommand: cmd); - } - - /// Turns the device off. This will disconnect the device. - @override - Future off() async { - final cmd = UrpCoreCommand( - command: UrpCommand.urpOff, - ); - await _addCommandToQueue(coreCommand: cmd); - } - - /// Reboots the device. This will disconnect the device. - @override - Future reboot() async { - final cmd = UrpCoreCommand( - command: UrpCommand.urpReboot, - ); - await _addCommandToQueue(coreCommand: cmd); - } - - /// Prevents the device from going to sleep mode. - @override - Future stayAwake() async { - final cmd = UrpCoreCommand( - command: UrpCommand.urpStayAwake, - ); - await _addCommandToQueue(coreCommand: cmd); - } - - /// Returns the public key of the device. Throws an error if failed. - @override - Future getPublicKey() async { - final cmd = UrpCoreCommand( - command: UrpCommand.urpGetPublicKey, - ); - final res = await _addCommandToQueue(coreCommand: cmd); - - if (!res.hasPayload()) { - throw SecReaderException(message: 'Failed to get public key'); - } - return UrpPublicKey.fromBuffer(res.payload); - } - - /// Return the device id. Throws an error if failed. - @override - Future getDeviceId() async { - final cmd = UrpCoreCommand( - command: UrpCommand.urpGetDeviceId, - ); - final res = await _addCommandToQueue(coreCommand: cmd); - - if (!res.hasPayload()) { - throw SecReaderException(message: 'Failed to get public key'); - } - return UrpDeviceId.fromBuffer(res.payload); - } - - /// Identify reader. Triggers the LED to identify the device. - @override - Future identify() async { - final cmd = UrpCoreCommand( - command: UrpCommand.urpIdentify, - ); - await _addCommandToQueue(coreCommand: cmd); - } - - /// Connect AP. Throws an error if failed. - @override - Future connectAP(String ssid, String apk) async { - final cmd = UrpCoreCommand( - command: UrpCommand.urpConnectAp, - apParameters: UrpApParamters(ssid: ssid, password: apk), - ); - final res = await _addCommandToQueue(coreCommand: cmd); - - if (!res.hasPayload()) { - throw SecReaderException(message: 'Failed to connect to AP'); - } - return UrpWifiState.fromBuffer(res.payload); - } - - /// Disconnect AP. - @override - Future disconnectAP() async { - final cmd = UrpCoreCommand( - command: UrpCommand.urpDisconnectAp, - ); - await _addCommandToQueue(coreCommand: cmd); - } - - /// Start AP. Throws an error if failed. - @override - Future startAP(String ssid, String apk) async { - final cmd = UrpCoreCommand( - command: UrpCommand.urpStartAp, - apParameters: UrpApParamters(ssid: ssid, password: apk), - ); - final res = await _addCommandToQueue(coreCommand: cmd); - - if (!res.hasPayload()) { - throw SecReaderException(message: 'Failed to start AP'); - } - return UrpWifiState.fromBuffer(res.payload); - } - - /// Stop AP. - @override - Future stopAP() async { - final cmd = UrpCoreCommand( - command: UrpCommand.urpStopAp, + Future _addDeviceCmdToQueue({ + UrpSecDeviceCommand? deviceCommand, + }) async { + return connectionStrategy.addQueue( + UrpSecCommandWrapper( + deviceCommand: deviceCommand, + ).writeToBuffer(), + target, + origin, ); - await _addCommandToQueue(coreCommand: cmd); } /// Prepares (primes) a measurement for the given [payload]. @@ -336,7 +129,7 @@ class SECReader extends CmdWrapper { primeParameters: UrpSecPrimeParameters(payload: payload), ); try { - final res = await _addCommandToQueue(deviceCommand: cmd); + final res = await _addDeviceCmdToQueue(deviceCommand: cmd); return UrpSecPrimeResponse.fromBuffer(res.payload); } catch (e) { if (e is DeviceError) { @@ -372,7 +165,7 @@ class SECReader extends CmdWrapper { amount: _requestTokenAmount, ), ); - final res = await _addCommandToQueue( + final res = await _addDeviceCmdToQueue( deviceCommand: cmd, ); @@ -391,7 +184,7 @@ class SECReader extends CmdWrapper { command: UrpSecCommand.urpSecSetToken, secureToken: token, ); - await _addCommandToQueue(deviceCommand: cmd); + await _addDeviceCmdToQueue(deviceCommand: cmd); } /// Request the currently installed token from the device @@ -399,7 +192,7 @@ class SECReader extends CmdWrapper { final cmd = UrpSecDeviceCommand( command: UrpSecCommand.urpSecGetToken, ); - final res = await _addCommandToQueue( + final res = await _addDeviceCmdToQueue( deviceCommand: cmd, ); @@ -417,7 +210,7 @@ class SECReader extends CmdWrapper { final cmd = UrpSecDeviceCommand( command: UrpSecCommand.urpSecUnprime, ); - await _addCommandToQueue(deviceCommand: cmd); + await _addDeviceCmdToQueue(deviceCommand: cmd); } /// Measures until detection. Returns the result if successful. @@ -426,7 +219,7 @@ class SECReader extends CmdWrapper { final cmd = UrpSecDeviceCommand( command: UrpSecCommand.urpSecStartMeasurement, ); - final res = await _addCommandToQueue(deviceCommand: cmd); + final res = await _addDeviceCmdToQueue(deviceCommand: cmd); if (!res.hasPayload()) { throw SecReaderException( @@ -449,7 +242,7 @@ class SECReader extends CmdWrapper { final cmd = UrpSecDeviceCommand( command: UrpSecCommand.urpSecStopMeasurement, ); - await _addCommandToQueue(deviceCommand: cmd); + await _addDeviceCmdToQueue(deviceCommand: cmd); } /// Get model info. Returns the result if successful. @@ -458,7 +251,7 @@ class SECReader extends CmdWrapper { final cmd = UrpSecDeviceCommand( command: UrpSecCommand.urpSecGetModelInfo, ); - final res = await _addCommandToQueue(deviceCommand: cmd); + final res = await _addDeviceCmdToQueue(deviceCommand: cmd); if (!res.hasPayload()) { throw Exception('Failed to get model info'); diff --git a/pubspec.yaml b/pubspec.yaml index d1e3d5c..96f2f55 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -13,14 +13,18 @@ dependencies: sdk: flutter intl: ^0.20.2 liquid_flutter: ^22.0.4 - mtrust_urp_core: ^9.1.0-12 - mtrust_urp_types: ^6.2.0 - mtrust_urp_ui: ^9.1.0-12 + mtrust_urp_core: + path: ../mtrust-urp/mtrust_urp_core + mtrust_urp_types: + path: ../mtrust-urp-types/packages/urp_types_dart + mtrust_urp_ui: + path: ../mtrust-urp/mtrust_urp_ui dev_dependencies: flutter_test: sdk: flutter golden_toolkit: ^0.15.0 - mtrust_urp_virtual_strategy: ^9.1.0-12 + mtrust_urp_virtual_strategy: + path: ../mtrust-urp/mtrust_urp_virtual_strategy very_good_analysis: ^5.1.0 flutter: uses-material-design: true From c844466f39ec85ffff8c6693259c887320a399c9 Mon Sep 17 00:00:00 2001 From: Christopher Koch Date: Tue, 18 Nov 2025 14:21:15 +0100 Subject: [PATCH 2/4] refactor: improve error handling and simplify measurement response in SECReader --- lib/src/sec_reader.dart | 18 +++--------------- pubspec.yaml | 3 +-- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/lib/src/sec_reader.dart b/lib/src/sec_reader.dart index ad6026e..3b07f49 100644 --- a/lib/src/sec_reader.dart +++ b/lib/src/sec_reader.dart @@ -133,7 +133,8 @@ class SECReader extends CmdWrapper { return UrpSecPrimeResponse.fromBuffer(res.payload); } catch (e) { if (e is DeviceError) { - if (e.errorCode != 4) { + if (e.errorCode.value != 4) { + // urpLeaseError rethrow; } final publicKey = await getPublicKey(); @@ -221,20 +222,7 @@ class SECReader extends CmdWrapper { ); final res = await _addDeviceCmdToQueue(deviceCommand: cmd); - if (!res.hasPayload()) { - throw SecReaderException( - message: 'Failed to measure!', - type: SecReaderExceptionType.measurementFailed, - ); - } - try { - return UrpSecSecureMeasurement.fromBuffer(res.payload); - } catch (e) { - throw SecReaderException( - message: 'Incompatible device firmware version. Please update!', - type: SecReaderExceptionType.incompatibleFirmware, - ); - } + return UrpSecSecureMeasurement.fromBuffer(res.payload); } /// Stop measurement diff --git a/pubspec.yaml b/pubspec.yaml index 96f2f55..dee96b7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,8 +15,7 @@ dependencies: liquid_flutter: ^22.0.4 mtrust_urp_core: path: ../mtrust-urp/mtrust_urp_core - mtrust_urp_types: - path: ../mtrust-urp-types/packages/urp_types_dart + mtrust_urp_types: ^6.2.1 mtrust_urp_ui: path: ../mtrust-urp/mtrust_urp_ui dev_dependencies: From f6f34d3adc354d287f20074be1f56b18cea36f5e Mon Sep 17 00:00:00 2001 From: Christopher Koch Date: Thu, 20 Nov 2025 17:46:40 +0100 Subject: [PATCH 3/4] refactor: update dependencies to latest versions and improve command handling in SECReader --- example/pubspec.yaml | 8 ++++---- lib/src/sec_reader.dart | 3 ++- pubspec.yaml | 9 +++------ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 5376a90..8d3e5ce 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -11,10 +11,10 @@ dependencies: sdk: flutter mtrust_sec_kit: path: ../ - mtrust_urp_types: ^6.0.0 - mtrust_urp_ble_strategy: ^9.1.0-12 - mtrust_urp_virtual_strategy: ^9.1.0-12 - mtrust_urp_ui: ^9.1.0-12 + mtrust_urp_types: ^6.2.1 + mtrust_urp_ble_strategy: ^9.1.0-13 + mtrust_urp_virtual_strategy: ^9.1.0-13 + mtrust_urp_ui: ^9.1.0-13 liquid_flutter: ^22.0.2 dev_dependencies: diff --git a/lib/src/sec_reader.dart b/lib/src/sec_reader.dart index 3b07f49..0aa72b0 100644 --- a/lib/src/sec_reader.dart +++ b/lib/src/sec_reader.dart @@ -230,7 +230,8 @@ class SECReader extends CmdWrapper { final cmd = UrpSecDeviceCommand( command: UrpSecCommand.urpSecStopMeasurement, ); - await _addDeviceCmdToQueue(deviceCommand: cmd); + final res = await _addDeviceCmdToQueue(deviceCommand: cmd); + print(res); } /// Get model info. Returns the result if successful. diff --git a/pubspec.yaml b/pubspec.yaml index dee96b7..3eda5ba 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -13,17 +13,14 @@ dependencies: sdk: flutter intl: ^0.20.2 liquid_flutter: ^22.0.4 - mtrust_urp_core: - path: ../mtrust-urp/mtrust_urp_core + mtrust_urp_core: ^9.1.0-13 mtrust_urp_types: ^6.2.1 - mtrust_urp_ui: - path: ../mtrust-urp/mtrust_urp_ui + mtrust_urp_ui: ^9.1.0-13 dev_dependencies: flutter_test: sdk: flutter golden_toolkit: ^0.15.0 - mtrust_urp_virtual_strategy: - path: ../mtrust-urp/mtrust_urp_virtual_strategy + mtrust_urp_virtual_strategy: ^9.1.0-13 very_good_analysis: ^5.1.0 flutter: uses-material-design: true From 79d22cf171a5889dff8de3b2ccd921725586231e Mon Sep 17 00:00:00 2001 From: Christopher Koch Date: Thu, 20 Nov 2025 17:52:16 +0100 Subject: [PATCH 4/4] fix: remove print statement --- lib/src/sec_reader.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/src/sec_reader.dart b/lib/src/sec_reader.dart index 0aa72b0..3b07f49 100644 --- a/lib/src/sec_reader.dart +++ b/lib/src/sec_reader.dart @@ -230,8 +230,7 @@ class SECReader extends CmdWrapper { final cmd = UrpSecDeviceCommand( command: UrpSecCommand.urpSecStopMeasurement, ); - final res = await _addDeviceCmdToQueue(deviceCommand: cmd); - print(res); + await _addDeviceCmdToQueue(deviceCommand: cmd); } /// Get model info. Returns the result if successful.