@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.
- package/dist/nfc-core.js +8 -9
- 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
|
|
201
|
+
// Verify response CMAC with incremented CmdCtr
|
|
198
202
|
const expectedMac = computeResponseCmac(cmacSessionKey, cmacCmdCtr, responseData);
|
|
199
|
-
let
|
|
203
|
+
let diff = 0;
|
|
200
204
|
for (let i = 0; i < 8; i++) {
|
|
201
|
-
|
|
205
|
+
diff |= responseMac[i] ^ expectedMac[i];
|
|
202
206
|
}
|
|
203
|
-
if (
|
|
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) {
|