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