@onekeyfe/react-native-lite-card 6.7.0-alpha.422 → 6.7.0-alpha.424
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/android/src/main/java/com/onekeyfe/reactnativelitecard/ReactNativeLiteCardModule.kt +29 -11
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/OnekeyLiteCard.kt +14 -3
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/Connection.kt +15 -10
- package/ios/Classes/OKNFTLite/OKNFCManager.m +26 -6
- package/ios/ReactNativeLiteCard.mm +16 -7
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ import android.content.Intent
|
|
|
4
4
|
import android.nfc.NfcAdapter
|
|
5
5
|
import android.nfc.Tag
|
|
6
6
|
import android.nfc.tech.IsoDep
|
|
7
|
+
import android.os.SystemClock
|
|
7
8
|
import com.margelo.nitro.nativelogger.OneKeyLog
|
|
8
9
|
import androidx.annotation.IntDef
|
|
9
10
|
import androidx.fragment.app.FragmentActivity
|
|
@@ -67,6 +68,7 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
67
68
|
|
|
68
69
|
private val mNFCConnectedChannel = Channel<IsoDep?>(1)
|
|
69
70
|
private var lastIsoDep: IsoDep? = null
|
|
71
|
+
private val diagnosticSequence = AtomicInteger(0)
|
|
70
72
|
private val mNFCState = AtomicInteger(NFCState.Dead)
|
|
71
73
|
private val mShowDialogNumber = AtomicInteger(0)
|
|
72
74
|
private var mCurrentCardState: CardState? = null
|
|
@@ -94,7 +96,7 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
94
96
|
return
|
|
95
97
|
}
|
|
96
98
|
|
|
97
|
-
OneKeyLog.
|
|
99
|
+
OneKeyLog.info("LiteCard", "stage=tag_received wallTimeMs=${System.currentTimeMillis()}")
|
|
98
100
|
launch(Dispatchers.IO) {
|
|
99
101
|
mNFCConnectedChannel.trySend(isoDep)
|
|
100
102
|
try {
|
|
@@ -114,7 +116,7 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
114
116
|
emitOnNFCActiveConnection(dataMap.copy())
|
|
115
117
|
}
|
|
116
118
|
} catch (e: Exception) {
|
|
117
|
-
OneKeyLog.error("LiteCard", "
|
|
119
|
+
OneKeyLog.error("LiteCard", "stage=connection_failure type=${if (e is NFCExceptions) "nfc" else "other"}")
|
|
118
120
|
// 未知设备或连接失败
|
|
119
121
|
val dataMap = Arguments.createMap().apply {
|
|
120
122
|
putInt("code", -1)
|
|
@@ -156,6 +158,8 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
156
158
|
|
|
157
159
|
@Throws(NFCExceptions::class)
|
|
158
160
|
private suspend fun acquireDevice(): IsoDep? {
|
|
161
|
+
val acquireID = diagnosticSequence.incrementAndGet()
|
|
162
|
+
OneKeyLog.info("LiteCard", "acquireID=$acquireID stage=acquire_begin wallTimeMs=${System.currentTimeMillis()}")
|
|
159
163
|
// 展示连接 ui
|
|
160
164
|
emitOnNFCUIEvent(Arguments.createMap().also {
|
|
161
165
|
it.putInt("code", 1)
|
|
@@ -171,18 +175,22 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
171
175
|
|
|
172
176
|
if (tryReceiveResult.isSuccess) {
|
|
173
177
|
receiveIsoDep = tryReceiveResult.getOrNull()
|
|
178
|
+
OneKeyLog.info("LiteCard", "acquireID=$acquireID stage=acquire_source source=channel connected=${receiveIsoDep.isSafeConnected()}")
|
|
174
179
|
if (!receiveIsoDep.isSafeConnected()) {
|
|
175
180
|
receiveIsoDep = null
|
|
176
181
|
}
|
|
177
182
|
}
|
|
178
183
|
|
|
179
184
|
if (receiveIsoDep == null && lastIsoDep.isSafeConnected()) {
|
|
185
|
+
OneKeyLog.info("LiteCard", "acquireID=$acquireID stage=acquire_source source=last connected=true")
|
|
180
186
|
receiveIsoDep = lastIsoDep
|
|
181
187
|
}
|
|
182
188
|
if (receiveIsoDep == null) {
|
|
189
|
+
OneKeyLog.info("LiteCard", "acquireID=$acquireID stage=acquire_source source=wait")
|
|
183
190
|
receiveIsoDep = mNFCConnectedChannel.receive()
|
|
184
191
|
}
|
|
185
192
|
|
|
193
|
+
OneKeyLog.info("LiteCard", "acquireID=$acquireID stage=acquire_result available=${receiveIsoDep != null} connected=${receiveIsoDep.isSafeConnected()}")
|
|
186
194
|
lastIsoDep = receiveIsoDep
|
|
187
195
|
if (receiveIsoDep == null) {
|
|
188
196
|
// 取消连接
|
|
@@ -191,6 +199,7 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
191
199
|
val initChannelRequest = OneKeyLiteCard.initRequest(receiveIsoDep)
|
|
192
200
|
|
|
193
201
|
mCurrentCardState = initChannelRequest
|
|
202
|
+
OneKeyLog.info("LiteCard", "acquireID=$acquireID stage=card_state isNewCard=${initChannelRequest.isNewCard} hasBackup=${initChannelRequest.hasBackup}")
|
|
194
203
|
|
|
195
204
|
// 展示连接结束 ui
|
|
196
205
|
emitOnNFCUIEvent(Arguments.createMap().also {
|
|
@@ -203,17 +212,25 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
203
212
|
|
|
204
213
|
private suspend fun <T> handleOperation(
|
|
205
214
|
callback: Callback?,
|
|
215
|
+
operation: String,
|
|
206
216
|
execute: (isoDep: IsoDep) -> T
|
|
207
217
|
) {
|
|
208
|
-
val
|
|
218
|
+
val operationID = diagnosticSequence.incrementAndGet()
|
|
219
|
+
val started = SystemClock.elapsedRealtime()
|
|
220
|
+
OneKeyLog.info("LiteCard", "operation=$operation operationID=$operationID stage=entry wallTimeMs=${System.currentTimeMillis()}")
|
|
221
|
+
val topActivity = Utils.getTopActivity() ?: run {
|
|
222
|
+
OneKeyLog.info("LiteCard", "operation=$operation operationID=$operationID stage=no_activity")
|
|
223
|
+
return
|
|
224
|
+
}
|
|
209
225
|
NfcPermissionUtils.checkPermission(topActivity) {
|
|
210
226
|
try {
|
|
211
227
|
OneKeyLog.debug("LiteCard","NFC permission check success")
|
|
212
228
|
val isoDep = acquireDevice() ?: return
|
|
213
229
|
val executeResult = execute(isoDep)
|
|
230
|
+
OneKeyLog.info("LiteCard", "operation=$operation operationID=$operationID stage=callback code=0 elapsedMs=${SystemClock.elapsedRealtime() - started}")
|
|
214
231
|
callback?.invoke(null, executeResult, mCurrentCardState.createArguments())
|
|
215
232
|
} catch (e: NFCExceptions) {
|
|
216
|
-
OneKeyLog.
|
|
233
|
+
OneKeyLog.info("LiteCard", "operation=$operation operationID=$operationID stage=callback code=${e.code} elapsedMs=${SystemClock.elapsedRealtime() - started}")
|
|
217
234
|
callback?.invoke(e.createArguments(), null, mCurrentCardState.createArguments())
|
|
218
235
|
} finally {
|
|
219
236
|
releaseDevice()
|
|
@@ -222,6 +239,7 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
222
239
|
}
|
|
223
240
|
// 没有 NFC 使用权限
|
|
224
241
|
OneKeyLog.debug("LiteCard","NFC device not permission")
|
|
242
|
+
OneKeyLog.info("LiteCard", "operation=$operation operationID=$operationID stage=callback code=${NFCExceptions.NotNFCPermission().code}")
|
|
225
243
|
callback?.invoke(NFCExceptions.NotNFCPermission().createArguments(), null, null)
|
|
226
244
|
}
|
|
227
245
|
|
|
@@ -246,7 +264,7 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
246
264
|
override fun getLiteInfo(callback: Callback?) {
|
|
247
265
|
launch {
|
|
248
266
|
OneKeyLog.debug("LiteCard","getLiteInfo")
|
|
249
|
-
handleOperation<Any>(callback) { isoDep ->
|
|
267
|
+
handleOperation<Any>(callback, "getLiteInfo") { isoDep ->
|
|
250
268
|
OneKeyLog.debug("LiteCard","getLiteInfo Obtain the device")
|
|
251
269
|
val cardInfo = OneKeyLiteCard.getCardInfo(isoDep)
|
|
252
270
|
OneKeyLog.debug("LiteCard","getLiteInfo result obtained")
|
|
@@ -300,7 +318,7 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
300
318
|
return
|
|
301
319
|
}
|
|
302
320
|
launch {
|
|
303
|
-
handleOperation(callback) { isoDep ->
|
|
321
|
+
handleOperation(callback, "setMnemonic") { isoDep ->
|
|
304
322
|
OneKeyLog.debug("LiteCard","setMnemonic Obtain the device")
|
|
305
323
|
val isSuccess =
|
|
306
324
|
OneKeyLiteCard.setMnemonic(
|
|
@@ -327,7 +345,7 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
327
345
|
}
|
|
328
346
|
launch {
|
|
329
347
|
OneKeyLog.debug("LiteCard","getMnemonicWithPin")
|
|
330
|
-
handleOperation(callback) { isoDep ->
|
|
348
|
+
handleOperation(callback, "getMnemonicWithPin") { isoDep ->
|
|
331
349
|
OneKeyLog.debug("LiteCard","getMnemonicWithPin Obtain the device")
|
|
332
350
|
OneKeyLiteCard.getMnemonicWithPin(mCurrentCardState, isoDep, pwd)
|
|
333
351
|
}
|
|
@@ -341,7 +359,7 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
341
359
|
) {
|
|
342
360
|
launch {
|
|
343
361
|
OneKeyLog.debug("LiteCard","changePin")
|
|
344
|
-
handleOperation(callback) { isoDep ->
|
|
362
|
+
handleOperation(callback, "changePin") { isoDep ->
|
|
345
363
|
OneKeyLog.debug("LiteCard","changePin Obtain the device")
|
|
346
364
|
OneKeyLiteCard.changPin(mCurrentCardState, isoDep, oldPin, newPin)
|
|
347
365
|
}
|
|
@@ -351,7 +369,7 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
351
369
|
override fun reset(callback: Callback?) {
|
|
352
370
|
launch {
|
|
353
371
|
OneKeyLog.debug("LiteCard","reset")
|
|
354
|
-
handleOperation(callback) { isoDep ->
|
|
372
|
+
handleOperation(callback, "reset") { isoDep ->
|
|
355
373
|
OneKeyLog.debug("LiteCard","reset Obtain the device")
|
|
356
374
|
val isSuccess = OneKeyLiteCard.reset(isoDep)
|
|
357
375
|
if (!isSuccess) throw NFCExceptions.ExecFailureException()
|
|
@@ -416,7 +434,7 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
416
434
|
OneKeyLog.debug("LiteCard","NFC starting success")
|
|
417
435
|
}
|
|
418
436
|
} catch (e: Exception) {
|
|
419
|
-
OneKeyLog.error("LiteCard", "
|
|
437
|
+
OneKeyLog.error("LiteCard", "stage=start_nfc_failure")
|
|
420
438
|
}
|
|
421
439
|
}
|
|
422
440
|
}
|
|
@@ -430,7 +448,7 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
430
448
|
mNFCState.set(NFCState.Dead)
|
|
431
449
|
OneKeyLog.debug("LiteCard","NFC 已关闭")
|
|
432
450
|
} catch (e: Exception) {
|
|
433
|
-
OneKeyLog.error("LiteCard", "
|
|
451
|
+
OneKeyLog.error("LiteCard", "stage=stop_nfc_failure")
|
|
434
452
|
}
|
|
435
453
|
}
|
|
436
454
|
}
|
|
@@ -111,18 +111,21 @@ object OneKeyLiteCard {
|
|
|
111
111
|
): Boolean {
|
|
112
112
|
if (cardState == null) throw NFCExceptions.ConnectionFailException()
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
OneKeyLog.info("LiteCard", "operation=setMnemonic stage=card_state isNewCard=${cardState.isNewCard} hasBackup=${cardState.hasBackup} overwrite=$overwrite wallTimeMs=${System.currentTimeMillis()}")
|
|
115
115
|
|
|
116
116
|
if (!overwrite) {
|
|
117
117
|
// 不是覆写要验证是否已经已经存有备份
|
|
118
118
|
if (!cardState.isNewCard || cardState.hasBackup) {
|
|
119
|
+
OneKeyLog.info("LiteCard", "operation=setMnemonic stage=already_initialized")
|
|
119
120
|
throw NFCExceptions.InitializedException()
|
|
120
121
|
}
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
if (overwrite && mCardConnection?.getCardType() == AppleCardType.V2) {
|
|
124
125
|
// Verify the password before clearing the card
|
|
126
|
+
OneKeyLog.info("LiteCard", "operation=setMnemonic stage=overwrite_verify_begin")
|
|
125
127
|
val verifyPin = verifyPinBackupRequest(isoDep, pwd)
|
|
128
|
+
OneKeyLog.info("LiteCard", "operation=setMnemonic stage=overwrite_verify_result success=${verifyPin == NfcConstant.VERIFY_SUCCESS}")
|
|
126
129
|
if (verifyPin != NfcConstant.VERIFY_SUCCESS) {
|
|
127
130
|
handlerVerifyPinError(cardState, verifyPin)
|
|
128
131
|
}
|
|
@@ -133,12 +136,17 @@ object OneKeyLiteCard {
|
|
|
133
136
|
|
|
134
137
|
if (cardState.isNewCard) {
|
|
135
138
|
// 如果是新卡设置密码
|
|
136
|
-
|
|
139
|
+
OneKeyLog.info("LiteCard", "operation=setMnemonic stage=set_pin_begin")
|
|
140
|
+
val setupSuccess = setupNewPinRequest(isoDep, pwd)
|
|
141
|
+
OneKeyLog.info("LiteCard", "operation=setMnemonic stage=set_pin_result success=$setupSuccess")
|
|
142
|
+
if (!setupSuccess) {
|
|
137
143
|
throw NFCExceptions.InitPasswordException()
|
|
138
144
|
}
|
|
139
145
|
}
|
|
140
146
|
|
|
147
|
+
OneKeyLog.info("LiteCard", "operation=setMnemonic stage=verify_pin_begin")
|
|
141
148
|
val verifyPin = verifyPinBackupRequest(isoDep, pwd)
|
|
149
|
+
OneKeyLog.info("LiteCard", "operation=setMnemonic stage=verify_pin_result success=${verifyPin == NfcConstant.VERIFY_SUCCESS}")
|
|
142
150
|
if (verifyPin != NfcConstant.VERIFY_SUCCESS) {
|
|
143
151
|
if (overwrite) {
|
|
144
152
|
handlerVerifyPinError(cardState, verifyPin)
|
|
@@ -148,7 +156,10 @@ object OneKeyLiteCard {
|
|
|
148
156
|
}
|
|
149
157
|
|
|
150
158
|
if (mnemonic.isNullOrEmpty()) throw NFCExceptions.ExecFailureException()
|
|
151
|
-
|
|
159
|
+
OneKeyLog.info("LiteCard", "operation=setMnemonic stage=backup_begin")
|
|
160
|
+
val backupSuccess = mCardConnection?.backupData(mnemonic) == true
|
|
161
|
+
OneKeyLog.info("LiteCard", "operation=setMnemonic stage=backup_result success=$backupSuccess")
|
|
162
|
+
return backupSuccess
|
|
152
163
|
}
|
|
153
164
|
|
|
154
165
|
@Throws(NFCExceptions::class)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
package com.onekeyfe.reactnativelitecard.onekeyLite.nfc
|
|
2
2
|
|
|
3
3
|
import android.nfc.TagLostException
|
|
4
|
+
import com.margelo.nitro.nativelogger.OneKeyLog
|
|
4
5
|
import android.nfc.tech.IsoDep
|
|
5
6
|
import org.haobtc.onekey.card.gpchannel.GPChannelNatives
|
|
6
7
|
import org.haobtc.onekey.card.gpchannel.GPChannelNatives.nativeGPCFinalize
|
|
@@ -49,9 +50,11 @@ class Connection(val isoDep: IsoDep, private val mCommandGenerator: CommandGener
|
|
|
49
50
|
|
|
50
51
|
return SendResponse(byteArr2HexStr(response), sw1, sw2, byteArr2HexStr(resp))
|
|
51
52
|
} catch (e: TagLostException) {
|
|
53
|
+
OneKeyLog.info("LiteCard", "stage=transport_failure type=tag_lost")
|
|
52
54
|
// throw NFCExceptions.InterruptException()
|
|
53
55
|
return SendResponse("0xFFFF", 0xFF.toByte(), 0xFF.toByte())
|
|
54
56
|
} catch (e: IOException) {
|
|
57
|
+
OneKeyLog.info("LiteCard", "stage=transport_failure type=io")
|
|
55
58
|
// e.printStackTrace()
|
|
56
59
|
return SendResponse("0xFFFF", 0xFF.toByte(), 0xFF.toByte())
|
|
57
60
|
}
|
|
@@ -84,7 +87,7 @@ class Connection(val isoDep: IsoDep, private val mCommandGenerator: CommandGener
|
|
|
84
87
|
)
|
|
85
88
|
val res = command.send(this)
|
|
86
89
|
printLog(
|
|
87
|
-
TAG, "<--- selectPrimarySafety end: ${res.getCode()}
|
|
90
|
+
TAG, "<--- selectPrimarySafety end: ${res.getCode()} area:${mCommandArea}"
|
|
88
91
|
)
|
|
89
92
|
|
|
90
93
|
if (res.isSuccess() && !res.isEmptyData()) {
|
|
@@ -104,7 +107,7 @@ class Connection(val isoDep: IsoDep, private val mCommandGenerator: CommandGener
|
|
|
104
107
|
)
|
|
105
108
|
val res = command.send(this)
|
|
106
109
|
|
|
107
|
-
printLog(TAG, "<--- selectApplet end: ${res.getCode()}
|
|
110
|
+
printLog(TAG, "<--- selectApplet end: ${res.getCode()} area:${mCommandArea}")
|
|
108
111
|
|
|
109
112
|
if (res.isSuccess()) {
|
|
110
113
|
mCommandArea = CommandArea.BackupApplet
|
|
@@ -121,7 +124,7 @@ class Connection(val isoDep: IsoDep, private val mCommandGenerator: CommandGener
|
|
|
121
124
|
val rawCert = send(isoDep, apdu)
|
|
122
125
|
printLog(
|
|
123
126
|
TAG,
|
|
124
|
-
"<--- getDeviceCertificate end: ${rawCert.getCode()}
|
|
127
|
+
"<--- getDeviceCertificate end: ${rawCert.getCode()} area:${mCommandArea}"
|
|
125
128
|
)
|
|
126
129
|
if (!rawCert.isSuccess() || rawCert.isEmptyData()) {
|
|
127
130
|
return null
|
|
@@ -172,7 +175,7 @@ class Connection(val isoDep: IsoDep, private val mCommandGenerator: CommandGener
|
|
|
172
175
|
val securityRes = command.send(this)
|
|
173
176
|
printLog(
|
|
174
177
|
TAG,
|
|
175
|
-
"2. <--- Perform security operation end: ${securityRes.getCode()}
|
|
178
|
+
"2. <--- Perform security operation end: ${securityRes.getCode()}"
|
|
176
179
|
)
|
|
177
180
|
if (!securityRes.isSuccess()) {
|
|
178
181
|
return false
|
|
@@ -220,7 +223,7 @@ class Connection(val isoDep: IsoDep, private val mCommandGenerator: CommandGener
|
|
|
220
223
|
mCardType, CommandType.GET_BACKUP_STATUS, hasOpenSafeChannel
|
|
221
224
|
)
|
|
222
225
|
val res = command.send(this)
|
|
223
|
-
printLog(TAG, "<--- getBackupStatus end: ${res.getCode()}
|
|
226
|
+
printLog(TAG, "<--- getBackupStatus end: ${res.getCode()} area:${mCommandArea}")
|
|
224
227
|
|
|
225
228
|
if (!res.isSuccess()) {
|
|
226
229
|
return false
|
|
@@ -235,7 +238,7 @@ class Connection(val isoDep: IsoDep, private val mCommandGenerator: CommandGener
|
|
|
235
238
|
mCardType, CommandType.GET_PIN_STATUS, hasOpenSafeChannel, "DFFF028105"
|
|
236
239
|
)
|
|
237
240
|
val res = command.send(this)
|
|
238
|
-
printLog(TAG, "<--- getPinStatus end: ${res.getCode()}
|
|
241
|
+
printLog(TAG, "<--- getPinStatus end: ${res.getCode()} area:${mCommandArea}")
|
|
239
242
|
|
|
240
243
|
if (!res.isSuccess()) {
|
|
241
244
|
return false
|
|
@@ -253,7 +256,7 @@ class Connection(val isoDep: IsoDep, private val mCommandGenerator: CommandGener
|
|
|
253
256
|
)
|
|
254
257
|
val res = command.send(this)
|
|
255
258
|
|
|
256
|
-
printLog(TAG, "<--- getSerialNumber end: ${res.getCode()}
|
|
259
|
+
printLog(TAG, "<--- getSerialNumber end: ${res.getCode()} area:${mCommandArea}")
|
|
257
260
|
if (!res.isSuccess()) {
|
|
258
261
|
return NfcConstant.NOT_MATCH_DEVICE
|
|
259
262
|
}
|
|
@@ -270,7 +273,7 @@ class Connection(val isoDep: IsoDep, private val mCommandGenerator: CommandGener
|
|
|
270
273
|
)
|
|
271
274
|
val res = command.send(this)
|
|
272
275
|
|
|
273
|
-
printLog(TAG, "<--- getRetryNum end: ${res.getCode()}
|
|
276
|
+
printLog(TAG, "<--- getRetryNum end: ${res.getCode()} area:${mCommandArea}")
|
|
274
277
|
|
|
275
278
|
if (res.isEmptyData() || !res.isSuccess()) {
|
|
276
279
|
return NfcConstant.GET_RETRY_NUM_INTERRUPT_STATUS
|
|
@@ -291,7 +294,7 @@ class Connection(val isoDep: IsoDep, private val mCommandGenerator: CommandGener
|
|
|
291
294
|
}
|
|
292
295
|
}
|
|
293
296
|
} catch (e: NFCExceptions) {
|
|
294
|
-
printLog(TAG, "
|
|
297
|
+
printLog(TAG, "stage=init_channel_failure type=nfc")
|
|
295
298
|
}
|
|
296
299
|
|
|
297
300
|
loadPinStatus()
|
|
@@ -398,7 +401,9 @@ class Connection(val isoDep: IsoDep, private val mCommandGenerator: CommandGener
|
|
|
398
401
|
val command = mCommandGenerator.generalCommand(
|
|
399
402
|
mCardType, CommandType.BACKUP_DATA, hasOpenSafeChannel, mnemonic
|
|
400
403
|
)
|
|
404
|
+
OneKeyLog.info("LiteCard", "operation=setMnemonic stage=backup_command_begin wallTimeMs=${System.currentTimeMillis()}")
|
|
401
405
|
val res = command.send(this)
|
|
406
|
+
OneKeyLog.info("LiteCard", "operation=setMnemonic stage=backup_command_result sw1=${res.sw1.toInt() and 0xFF} sw2=${res.sw2.toInt() and 0xFF} parseSuccess=${res.parseSuccess} success=${res.isSuccess()}")
|
|
402
407
|
printLog(TAG, "<--- backupData end: ${res.getCode()} area:${mCommandArea}")
|
|
403
408
|
|
|
404
409
|
if (!res.isSuccess()) {
|
|
@@ -442,7 +447,7 @@ class Connection(val isoDep: IsoDep, private val mCommandGenerator: CommandGener
|
|
|
442
447
|
)
|
|
443
448
|
val res = command.send(this)
|
|
444
449
|
|
|
445
|
-
printLog(TAG, "<--- resetCard end: ${res.getCode()}
|
|
450
|
+
printLog(TAG, "<--- resetCard end: ${res.getCode()} area:${mCommandArea}")
|
|
446
451
|
|
|
447
452
|
return if (!res.isSuccess()) {
|
|
448
453
|
NfcConstant.RESET_INTERRUPT_STATUS
|
|
@@ -32,6 +32,8 @@
|
|
|
32
32
|
|
|
33
33
|
@interface OKNFCManager() <NFCTagReaderSessionDelegate,OKNFCManagerDelegate>
|
|
34
34
|
@property (nonatomic, strong) NFCTagReaderSession *session;
|
|
35
|
+
@property (nonatomic, assign) NSUInteger diagnosticID;
|
|
36
|
+
@property (nonatomic, assign) NSUInteger diagnosticSessionID;
|
|
35
37
|
@property (nonatomic, copy) NSString *pin;
|
|
36
38
|
@property (nonatomic, copy) NSString *neoPin;
|
|
37
39
|
@property (nonatomic, copy) NSString *exportMnemonic;
|
|
@@ -48,6 +50,20 @@
|
|
|
48
50
|
|
|
49
51
|
@implementation OKNFCManager
|
|
50
52
|
|
|
53
|
+
- (instancetype)init {
|
|
54
|
+
self = [super init];
|
|
55
|
+
if (self) {
|
|
56
|
+
static NSUInteger nextID = 0;
|
|
57
|
+
@synchronized (OKNFCManager.class) { _diagnosticID = ++nextID; }
|
|
58
|
+
}
|
|
59
|
+
return self;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
- (void)logSessionStage:(NSString *)stage details:(NSString *)details {
|
|
63
|
+
[LCLogger info:[NSString stringWithFormat:@"managerID=%lu sessionID=%lu operation=%ld stage=%@ wallTimeMs=%.0f %@", (unsigned long)self.diagnosticID, (unsigned long)self.diagnosticSessionID, (long)self.sessionType, stage, NSDate.date.timeIntervalSince1970 * 1000, details]];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
51
67
|
#pragma mark - OKNFCManagerDelegate
|
|
52
68
|
|
|
53
69
|
- (id<NFCISO7816Tag>)getNFCsessionTag {
|
|
@@ -61,6 +77,7 @@
|
|
|
61
77
|
|
|
62
78
|
|
|
63
79
|
- (void)endNFCSessionWithError:(BOOL)isError {
|
|
80
|
+
[self logSessionStage:@"invalidate_request" details:[NSString stringWithFormat:@"isError=%d", isError]];
|
|
64
81
|
self.sessionEndedByApp = YES;
|
|
65
82
|
self.session.alertMessage = @"";
|
|
66
83
|
if (isError) {
|
|
@@ -138,6 +155,8 @@
|
|
|
138
155
|
}
|
|
139
156
|
|
|
140
157
|
- (void)beginNewNFCSession {
|
|
158
|
+
self.diagnosticSessionID += 1;
|
|
159
|
+
[self logSessionStage:@"begin" details:@""];
|
|
141
160
|
self.sessionEndedByApp = NO;
|
|
142
161
|
self.session = [[NFCTagReaderSession alloc] initWithPollingOption:NFCPollingISO14443 delegate:self queue:dispatch_get_global_queue(2, 0)];
|
|
143
162
|
[self.session beginSession];
|
|
@@ -146,26 +165,25 @@
|
|
|
146
165
|
#pragma mark - NFCTagReaderSessionDelegate
|
|
147
166
|
|
|
148
167
|
- (void)tagReaderSession:(NFCTagReaderSession *)session didDetectTags:(NSArray<__kindof id<NFCTag>> *)tags {
|
|
149
|
-
[
|
|
168
|
+
[self logSessionStage:@"detect" details:[NSString stringWithFormat:@"tagCount=%lu currentSession=%d", (unsigned long)tags.count, session == self.session]];
|
|
150
169
|
|
|
151
170
|
id<NFCISO7816Tag> tag = [tags.firstObject asNFCISO7816Tag];
|
|
152
171
|
if (!tag) { return; }
|
|
153
172
|
|
|
154
173
|
[session connectToTag:tag completionHandler:^(NSError * _Nullable error) {
|
|
155
174
|
if (error) {
|
|
156
|
-
|
|
157
|
-
[LCLogger error:errMsg];
|
|
158
|
-
// [kTools debugTipMessage:errMsg];
|
|
175
|
+
[self logSessionStage:@"connect_failure" details:[NSString stringWithFormat:@"code=%ld coreNFCDomain=%d", (long)error.code, [error.domain isEqualToString:NFCErrorDomain]]];
|
|
159
176
|
[self endNFCSessionWithError:YES];
|
|
160
177
|
[self finishPendingRequestAsCancel:NO sessionError:nil];
|
|
161
178
|
return;
|
|
162
179
|
}
|
|
180
|
+
[self logSessionStage:@"connect_success" details:@""];
|
|
163
181
|
[self nfcSessionComplete:session];
|
|
164
182
|
}];
|
|
165
183
|
}
|
|
166
184
|
|
|
167
185
|
- (void)tagReaderSession:(NFCTagReaderSession *)session didInvalidateWithError:(NSError *)error {
|
|
168
|
-
[
|
|
186
|
+
[self logSessionStage:@"invalidated" details:[NSString stringWithFormat:@"code=%ld coreNFCDomain=%d endedByApp=%d currentSession=%d", (long)error.code, [error.domain isEqualToString:NFCErrorDomain], self.sessionEndedByApp, session == self.session]];
|
|
169
187
|
// When the app ended the session, the card operation that ended it reports
|
|
170
188
|
// the real result; treating this as a cancel would race with it.
|
|
171
189
|
if ((error.code == 200 || error.code == 6) && !self.sessionEndedByApp) {
|
|
@@ -175,7 +193,7 @@
|
|
|
175
193
|
}
|
|
176
194
|
|
|
177
195
|
- (void)tagReaderSessionDidBecomeActive:(NFCTagReaderSession *)session {
|
|
178
|
-
[
|
|
196
|
+
[self logSessionStage:@"active" details:[NSString stringWithFormat:@"currentSession=%d", session == self.session]];
|
|
179
197
|
}
|
|
180
198
|
|
|
181
199
|
#pragma mark - Tasks
|
|
@@ -259,6 +277,7 @@
|
|
|
259
277
|
complete:(SetMnemonicCallback)complete {
|
|
260
278
|
|
|
261
279
|
if (pin.length != OKNFC_PIN_LENGTH) {
|
|
280
|
+
[self logSessionStage:@"input_rejected" details:@"operation=setMnemonic"];
|
|
262
281
|
return;
|
|
263
282
|
}
|
|
264
283
|
self.pin = pin;
|
|
@@ -293,6 +312,7 @@
|
|
|
293
312
|
|
|
294
313
|
- (void)getMnemonicWithPin:(NSString *)pin complete:(GetMnemonicCallback)complete {
|
|
295
314
|
if (pin.length != OKNFC_PIN_LENGTH) {
|
|
315
|
+
[self logSessionStage:@"input_rejected" details:@"operation=getMnemonicWithPin"];
|
|
296
316
|
return;
|
|
297
317
|
}
|
|
298
318
|
self.pin = pin;
|
|
@@ -30,14 +30,21 @@ typedef NS_ENUM(NSInteger, NFCLiteExceptions) {
|
|
|
30
30
|
|
|
31
31
|
// React Native aborts the app when a callback runs twice, and NFC results can
|
|
32
32
|
// arrive from more than one CoreNFC thread, so only the first result is sent.
|
|
33
|
-
static RCTResponseSenderBlock OKLiteCallbackOnce(RCTResponseSenderBlock callback)
|
|
33
|
+
static RCTResponseSenderBlock OKLiteCallbackOnce(NSString *operation, RCTResponseSenderBlock callback)
|
|
34
34
|
{
|
|
35
|
+
static std::atomic<unsigned long> nextOperationID{0};
|
|
36
|
+
unsigned long operationID = ++nextOperationID;
|
|
37
|
+
NSTimeInterval started = NSProcessInfo.processInfo.systemUptime;
|
|
38
|
+
[LCLogger info:[NSString stringWithFormat:@"operation=%@ operationID=%lu stage=entry wallTimeMs=%.0f", operation, operationID, NSDate.date.timeIntervalSince1970 * 1000]];
|
|
35
39
|
auto invoked = std::make_shared<std::atomic<bool>>(false);
|
|
36
40
|
return ^(NSArray *response) {
|
|
37
41
|
if (invoked->exchange(true)) {
|
|
38
|
-
[LCLogger warn:@"
|
|
42
|
+
[LCLogger warn:[NSString stringWithFormat:@"operation=%@ operationID=%lu stage=callback_dropped", operation, operationID]];
|
|
39
43
|
return;
|
|
40
44
|
}
|
|
45
|
+
id error = response.firstObject;
|
|
46
|
+
NSNumber *code = [error isKindOfClass:NSDictionary.class] ? error[@"code"] : @0;
|
|
47
|
+
[LCLogger info:[NSString stringWithFormat:@"operation=%@ operationID=%lu stage=callback code=%ld elapsedMs=%.0f wallTimeMs=%.0f", operation, operationID, (long)code.integerValue, (NSProcessInfo.processInfo.systemUptime - started) * 1000, NSDate.date.timeIntervalSince1970 * 1000]];
|
|
41
48
|
callback(response);
|
|
42
49
|
};
|
|
43
50
|
}
|
|
@@ -74,7 +81,7 @@ static RCTResponseSenderBlock OKLiteCallbackOnce(RCTResponseSenderBlock callback
|
|
|
74
81
|
|
|
75
82
|
- (void)getLiteInfo:(RCTResponseSenderBlock)callBack
|
|
76
83
|
{
|
|
77
|
-
callBack = OKLiteCallbackOnce(callBack);
|
|
84
|
+
callBack = OKLiteCallbackOnce(@"getLiteInfo", callBack);
|
|
78
85
|
if ([ReactNativeLiteCard checkSDKVaild:callBack]) {
|
|
79
86
|
__block OKNFCManager *liteManager = [[OKNFCManager alloc] init];
|
|
80
87
|
[liteManager getLiteInfo:^(OKLiteV1 *lite, OKNFCLiteStatus status) {
|
|
@@ -92,7 +99,7 @@ static RCTResponseSenderBlock OKLiteCallbackOnce(RCTResponseSenderBlock callback
|
|
|
92
99
|
|
|
93
100
|
- (void)setMnemonic:(NSString *)mnemonic pwd:(NSString *)pwd overwrite:(BOOL)overwrite callback:(RCTResponseSenderBlock)callBack
|
|
94
101
|
{
|
|
95
|
-
callBack = OKLiteCallbackOnce(callBack);
|
|
102
|
+
callBack = OKLiteCallbackOnce(@"setMnemonic", callBack);
|
|
96
103
|
if ([ReactNativeLiteCard checkSDKVaild:callBack]) {
|
|
97
104
|
__block OKNFCManager *liteManager = [[OKNFCManager alloc] init];
|
|
98
105
|
[liteManager setMnemonic:mnemonic withPin:pwd overwrite:overwrite complete:^(OKLiteV1 *lite, OKNFCLiteSetMncStatus status) {
|
|
@@ -130,7 +137,7 @@ static RCTResponseSenderBlock OKLiteCallbackOnce(RCTResponseSenderBlock callback
|
|
|
130
137
|
|
|
131
138
|
- (void)getMnemonicWithPin:(NSString *)pwd callback:(RCTResponseSenderBlock)callBack
|
|
132
139
|
{
|
|
133
|
-
callBack = OKLiteCallbackOnce(callBack);
|
|
140
|
+
callBack = OKLiteCallbackOnce(@"getMnemonicWithPin", callBack);
|
|
134
141
|
if ([ReactNativeLiteCard checkSDKVaild:callBack]) {
|
|
135
142
|
__block OKNFCManager *liteManager = [[OKNFCManager alloc] init];
|
|
136
143
|
[liteManager getMnemonicWithPin:pwd complete:^(OKLiteV1 *lite, NSString *mnemonic, OKNFCLiteGetMncStatus status) {
|
|
@@ -170,7 +177,7 @@ static RCTResponseSenderBlock OKLiteCallbackOnce(RCTResponseSenderBlock callback
|
|
|
170
177
|
|
|
171
178
|
- (void)changePin:(NSString *)oldPin newPin:(NSString *)newPin callback:(RCTResponseSenderBlock)callBack
|
|
172
179
|
{
|
|
173
|
-
callBack = OKLiteCallbackOnce(callBack);
|
|
180
|
+
callBack = OKLiteCallbackOnce(@"changePin", callBack);
|
|
174
181
|
if ([ReactNativeLiteCard checkSDKVaild:callBack]) {
|
|
175
182
|
__block OKNFCManager *liteManager = [[OKNFCManager alloc] init];
|
|
176
183
|
[liteManager changePin:oldPin to:newPin complete:^(OKLiteV1 *lite, OKNFCLiteChangePinStatus status) {
|
|
@@ -204,7 +211,7 @@ static RCTResponseSenderBlock OKLiteCallbackOnce(RCTResponseSenderBlock callback
|
|
|
204
211
|
|
|
205
212
|
- (void)reset:(RCTResponseSenderBlock)callBack
|
|
206
213
|
{
|
|
207
|
-
callBack = OKLiteCallbackOnce(callBack);
|
|
214
|
+
callBack = OKLiteCallbackOnce(@"reset", callBack);
|
|
208
215
|
if ([ReactNativeLiteCard checkSDKVaild:callBack]) {
|
|
209
216
|
__block OKNFCManager *liteManager = [[OKNFCManager alloc] init];
|
|
210
217
|
[liteManager reset:^(OKLiteV1 *lite, BOOL isSuccess, NSError *error) {
|
|
@@ -232,11 +239,13 @@ static RCTResponseSenderBlock OKLiteCallbackOnce(RCTResponseSenderBlock callback
|
|
|
232
239
|
}
|
|
233
240
|
|
|
234
241
|
+ (BOOL)checkSDKVaild:(RCTResponseSenderBlock)callback {
|
|
242
|
+
[LCLogger info:@"stage=sdk_check"];
|
|
235
243
|
if (![NFCNDEFReaderSession readingAvailable]) {
|
|
236
244
|
callback(@[@{@"code":@(NFCLiteExceptionsNotNFCPermission),@"message":@""},[NSNull null],[NSNull null]]);
|
|
237
245
|
return NO;
|
|
238
246
|
}
|
|
239
247
|
if ([NFCConfig envFor:@"crt"].length > 0 && [NFCConfig envFor:@"sk"].length > 0) {
|
|
248
|
+
[LCLogger info:@"stage=sdk_check_success"];
|
|
240
249
|
return YES;
|
|
241
250
|
}
|
|
242
251
|
callback(@[@{@"code":@(NFCLiteExceptionsInitChannel),@"message":@""},[NSNull null],[NSNull null]]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-lite-card",
|
|
3
|
-
"version": "6.7.0-alpha.
|
|
3
|
+
"version": "6.7.0-alpha.424",
|
|
4
4
|
"description": "OneKey Lite NFC card operations and connection events for React Native",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|