@ukeyfe/react-native-nfc-litecard 1.0.5 → 1.0.6

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.
Files changed (2) hide show
  1. package/dist/nfc-core.js +8 -9
  2. package/package.json +1 -1
package/dist/nfc-core.js CHANGED
@@ -189,27 +189,26 @@ async function transceive(command, _timeoutMs = 2000, retryCount = 0) {
189
189
  const result = react_native_1.Platform.OS === 'ios'
190
190
  ? await react_native_nfc_manager_1.default.sendMifareCommandIOS(cmdToSend)
191
191
  : await react_native_nfc_manager_1.default.nfcAHandler.transceive(cmdToSend);
192
+ if (cmacSessionKey) {
193
+ // CmdCtr increments between command and response (datasheet §8.8.3)
194
+ cmacCmdCtr++;
195
+ }
192
196
  if (cmacSessionKey && result && result.length >= 8) {
193
197
  // Response has CMAC appended: split data and MAC
194
198
  const dataLen = result.length - 8;
195
199
  const responseData = result.slice(0, dataLen);
196
200
  const responseMac = result.slice(dataLen);
197
- // Verify response CMAC (constant-time comparison)
201
+ // Verify response CMAC with incremented CmdCtr
198
202
  const expectedMac = computeResponseCmac(cmacSessionKey, cmacCmdCtr, responseData);
199
- let macValid = true;
203
+ let diff = 0;
200
204
  for (let i = 0; i < 8; i++) {
201
- macValid = macValid && (responseMac[i] === expectedMac[i]);
205
+ diff |= responseMac[i] ^ expectedMac[i];
202
206
  }
203
- if (!macValid) {
207
+ if (diff !== 0) {
204
208
  throw new Error('CMAC_VERIFY_FAILED');
205
209
  }
206
- cmacCmdCtr++;
207
210
  return responseData;
208
211
  }
209
- if (cmacSessionKey) {
210
- // ACK-only response (e.g. WRITE command) — MAC replaces ACK
211
- cmacCmdCtr++;
212
- }
213
212
  return result;
214
213
  }
215
214
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukeyfe/react-native-nfc-litecard",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "NFC read/write for MIFARE Ultralight AES (LiteCard mnemonic storage)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",