@onekeyfe/react-native-lite-card 6.7.0-21 → 6.7.0-23
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/README.md +9 -1
- package/ReactNativeLiteCard.podspec +25 -2
- package/android/build.gradle +7 -0
- package/android/src/main/cpp/CMakeLists.txt +6 -2
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/ReactNativeLiteCardModule.kt +29 -11
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/nfc/gpchannel/GPChannelNatives.kt +7 -7
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/OnekeyLiteCard.kt +14 -3
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/entitys/SendResponse.kt +6 -3
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/CommandGenerator.kt +5 -1
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/Connection.kt +36 -17
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/GPCAPDUGenerator.kt +2 -2
- package/ios/Classes/OKLiteCommand/OKLiteCommandTool.m +4 -1
- package/ios/Classes/OKNFCBridge.mm +1 -1
- package/ios/Classes/OKNFTLite/OKLiteV1.m +6 -3
- package/ios/Classes/OKNFTLite/OKLiteV2.m +13 -5
- package/ios/Classes/OKNFTLite/OKNFCManager.m +26 -6
- package/ios/ReactNativeLiteCard.mm +16 -7
- package/package.json +8 -8
- package/sdk/CMakeLists.txt +120 -0
- package/sdk/README.md +175 -0
- package/sdk/android/implJni.cpp +177 -0
- package/sdk/deps/jsoncpp/LICENSE +55 -0
- package/sdk/deps/jsoncpp/include/CMakeLists.txt +2 -0
- package/sdk/deps/jsoncpp/include/json/allocator.h +98 -0
- package/sdk/deps/jsoncpp/include/json/assertions.h +54 -0
- package/sdk/deps/jsoncpp/include/json/autolink.h +25 -0
- package/sdk/deps/jsoncpp/include/json/config.h +187 -0
- package/sdk/deps/jsoncpp/include/json/features.h +61 -0
- package/sdk/deps/jsoncpp/include/json/forwards.h +37 -0
- package/sdk/deps/jsoncpp/include/json/json.h +15 -0
- package/sdk/deps/jsoncpp/include/json/reader.h +411 -0
- package/sdk/deps/jsoncpp/include/json/value.h +888 -0
- package/sdk/deps/jsoncpp/include/json/version.h +20 -0
- package/sdk/deps/jsoncpp/include/json/writer.h +357 -0
- package/sdk/deps/jsoncpp/src/lib_json/CMakeLists.txt +117 -0
- package/sdk/deps/jsoncpp/src/lib_json/json_reader.cpp +2060 -0
- package/sdk/deps/jsoncpp/src/lib_json/json_tool.h +114 -0
- package/sdk/deps/jsoncpp/src/lib_json/json_value.cpp +1661 -0
- package/sdk/deps/jsoncpp/src/lib_json/json_valueiterator.inl +167 -0
- package/sdk/deps/jsoncpp/src/lib_json/json_writer.cpp +1233 -0
- package/sdk/deps/jsoncpp/src/lib_json/version.h.in +20 -0
- package/sdk/deps/trezor-crypto/AUTHORS +2 -0
- package/sdk/deps/trezor-crypto/LICENSE +22 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/TrezorCrypto.h +29 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/address.h +44 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/aes.h +224 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/base32.h +49 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/base58.h +58 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/bignum.h +169 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/bip32.h +114 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/bip39.h +66 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/blake256.h +61 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/blake2b.h +50 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/blake2s.h +49 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/cash_addr.h +109 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305/ecrypt-config.h +316 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305/ecrypt-sync.h +289 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305/ecrypt-types.h +53 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305/poly1305-donna.h +28 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305.h +27 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/cmac.h +44 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/curves.h +60 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ecdsa.h +112 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/curve25519-donna-32bit.h +87 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/curve25519-donna-helpers.h +30 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-blake2b.h +21 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna-32bit-tables.h +25 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna-basepoint-table.h +10 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna-impl-base.h +110 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna-portable.h +32 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna.h +60 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-keccak.h +21 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-sha3.h +21 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/modm-donna-32bit.h +87 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna.h +60 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519.h +42 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/endian.h +132 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/groestl.h +104 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/hasher.h +90 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/hmac.h +60 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/memzero.h +16 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/base58.h +42 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/monero.h +13 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/range_proof.h +30 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/serialize.h +15 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/xmr.h +67 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/nano.h +56 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/nem.h +199 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/nist256p1.h +35 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/pbkdf2.h +64 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/rand.h +44 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/rc4.h +37 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/rfc6979.h +40 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ripemd160.h +28 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ripple/base58.h +45 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/schnorr.h +48 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/script.h +30 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/scrypt.h +68 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/secp256k1.h +59 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sha2.h +125 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sha3.h +86 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/keypair.h +20 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/private/ed25519_ref10.h +85 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/private/ed25519_ref10_fe_25_5.h +43 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/private/fe_25_5/constants.h +29 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/private/fe_25_5/fe.h +25 -0
- package/sdk/deps/trezor-crypto/src/address.c +87 -0
- package/sdk/deps/trezor-crypto/src/aes/aes_modes.c +959 -0
- package/sdk/deps/trezor-crypto/src/aes/aescrypt.c +307 -0
- package/sdk/deps/trezor-crypto/src/aes/aeskey.c +560 -0
- package/sdk/deps/trezor-crypto/src/aes/aesopt.h +784 -0
- package/sdk/deps/trezor-crypto/src/aes/aestab.c +418 -0
- package/sdk/deps/trezor-crypto/src/aes/aestab.h +173 -0
- package/sdk/deps/trezor-crypto/src/base32.c +233 -0
- package/sdk/deps/trezor-crypto/src/base58.c +298 -0
- package/sdk/deps/trezor-crypto/src/bignum.c +808 -0
- package/sdk/deps/trezor-crypto/src/bip32.c +852 -0
- package/sdk/deps/trezor-crypto/src/bip39.c +266 -0
- package/sdk/deps/trezor-crypto/src/bip39_english.h +2074 -0
- package/sdk/deps/trezor-crypto/src/blake256.c +235 -0
- package/sdk/deps/trezor-crypto/src/blake2_common.h +39 -0
- package/sdk/deps/trezor-crypto/src/blake2b.c +333 -0
- package/sdk/deps/trezor-crypto/src/blake2s.c +318 -0
- package/sdk/deps/trezor-crypto/src/cash_addr.c +195 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/chacha20poly1305.c +60 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/chacha_merged.c +246 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/ecrypt-machine.h +49 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/ecrypt-portable.h +275 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/poly1305-donna-32.h +219 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/poly1305-donna.c +179 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/rfc7539.c +48 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/rfc7539.h +10 -0
- package/sdk/deps/trezor-crypto/src/check_mem.h +30 -0
- package/sdk/deps/trezor-crypto/src/cmac.c +342 -0
- package/sdk/deps/trezor-crypto/src/curves.c +48 -0
- package/sdk/deps/trezor-crypto/src/ecdsa.c +1355 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/README.md +183 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/curve25519-donna-32bit.c +681 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/curve25519-donna-helpers.c +66 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/curve25519-donna-scalarmult-base.c +67 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/curve25519-donna-scalarmult-base.h +8 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-blake2b.c +8 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-donna-32bit-tables.c +63 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-donna-basepoint-table.c +261 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-donna-impl-base.c +722 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-hash-custom-blake2b.h +23 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-hash-custom-keccak.h +23 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-hash-custom-sha3.h +23 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-hash-custom.h +23 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-keccak.c +8 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-sha3.c +8 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519.c +311 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/modm-donna-32bit.c +517 -0
- package/sdk/deps/trezor-crypto/src/groestl.c +783 -0
- package/sdk/deps/trezor-crypto/src/groestl_internal.h +419 -0
- package/sdk/deps/trezor-crypto/src/hasher.c +186 -0
- package/sdk/deps/trezor-crypto/src/hmac.c +179 -0
- package/sdk/deps/trezor-crypto/src/memzero.c +6 -0
- package/sdk/deps/trezor-crypto/src/monero/base58.c +245 -0
- package/sdk/deps/trezor-crypto/src/monero/int-util.h +77 -0
- package/sdk/deps/trezor-crypto/src/monero/range_proof.c +115 -0
- package/sdk/deps/trezor-crypto/src/monero/serialize.c +54 -0
- package/sdk/deps/trezor-crypto/src/monero/xmr.c +136 -0
- package/sdk/deps/trezor-crypto/src/nano.c +151 -0
- package/sdk/deps/trezor-crypto/src/nem.c +569 -0
- package/sdk/deps/trezor-crypto/src/nist256p1.c +63 -0
- package/sdk/deps/trezor-crypto/src/nist256p1.table +1664 -0
- package/sdk/deps/trezor-crypto/src/options.h +43 -0
- package/sdk/deps/trezor-crypto/src/pbkdf2.c +177 -0
- package/sdk/deps/trezor-crypto/src/rand.c +51 -0
- package/sdk/deps/trezor-crypto/src/rc4.c +56 -0
- package/sdk/deps/trezor-crypto/src/ripemd160.c +343 -0
- package/sdk/deps/trezor-crypto/src/ripple/base58.c +76 -0
- package/sdk/deps/trezor-crypto/src/schnorr.c +208 -0
- package/sdk/deps/trezor-crypto/src/script.c +64 -0
- package/sdk/deps/trezor-crypto/src/scrypt.c +343 -0
- package/sdk/deps/trezor-crypto/src/secp256k1.c +160 -0
- package/sdk/deps/trezor-crypto/src/secp256k1.table +1664 -0
- package/sdk/deps/trezor-crypto/src/setup.py +38 -0
- package/sdk/deps/trezor-crypto/src/sha2.c +1314 -0
- package/sdk/deps/trezor-crypto/src/sha3.c +395 -0
- package/sdk/deps/trezor-crypto/src/shell.nix +6 -0
- package/sdk/deps/trezor-crypto/src/sodium/keypair.c +63 -0
- package/sdk/deps/trezor-crypto/src/sodium/private/ed25519_ref10.c +481 -0
- package/sdk/deps/trezor-crypto/src/sodium/private/ed25519_ref10_fe_25_5.c +885 -0
- package/sdk/deps/trezor-crypto/src/sodium/private/fe_25_5/fe.c +237 -0
- package/sdk/gpc/include/scp03/scp03.hpp +80 -0
- package/sdk/gpc/include/scp11/scp11.hpp +492 -0
- package/sdk/gpc/include/scp11/scp11c.hpp +58 -0
- package/sdk/gpc/include/tag.h +68 -0
- package/sdk/gpc/include/tlv.hpp +94 -0
- package/sdk/gpc/include/tlvparse.hpp +24 -0
- package/sdk/gpc/src/scp03.cpp +243 -0
- package/sdk/gpc/src/scp11.cpp +798 -0
- package/sdk/gpc/src/scp11c.cpp +136 -0
- package/sdk/gpc/src/tlv.cpp +159 -0
- package/sdk/gpc/src/tlvparse.c +174 -0
- package/{framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/Headers → sdk/include}/GPChannelSDK.h +0 -0
- package/sdk/include/GPChannelSDKCore.h +10 -0
- package/sdk/include/context/BaseContext.h +56 -0
- package/sdk/include/device/ApduBuilder.hpp +72 -0
- package/sdk/include/mSIGNA/stdutils/uchar_vector.h +36 -0
- package/sdk/include/utility/Apdu.hpp +172 -0
- package/sdk/include/utility/Debug.hpp +3 -0
- package/sdk/include/utility/util.h +104 -0
- package/sdk/src/ApduBuilder.cpp +332 -0
- package/sdk/src/GPChannelSDK.cpp +252 -0
- package/sdk/src/random.c +25 -0
- package/sdk/src/version.c +2 -0
- package/sdk/tests/android/GPChannelProxy.java +55 -0
- package/sdk/tests/android_verify.py +121 -0
- package/sdk/tests/safety.cpp +603 -0
- package/sdk/tests/verify.py +267 -0
- package/android/src/main/jniLibs/arm64-v8a/libgpchannelNDK.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libgpchannelNDK.so +0 -0
- package/framework/GPChannelSDKCore.xcframework/Info.plist +0 -52
- package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/GPChannelSDKCore +0 -0
- package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/Headers/GPChannelSDKCore.h +0 -19
- package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/Info.plist +0 -0
- package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/Modules/module.modulemap +0 -7
- package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/_CodeSignature/CodeResources +0 -147
- package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/GPChannelSDKCore +0 -0
- package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/Headers/GPChannelSDK.h +0 -315
- package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/Headers/GPChannelSDKCore.h +0 -19
- package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/Info.plist +0 -0
- package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/Modules/module.modulemap +0 -7
- package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/_CodeSignature/CodeResources +0 -147
|
@@ -80,12 +80,20 @@
|
|
|
80
80
|
OKNFCLitePINVerifyResult oldPinVerifyResult = [self verifyPin:pin];
|
|
81
81
|
if (oldPinVerifyResult == OKNFCLitePINVerifyResultPass) {
|
|
82
82
|
[self setPin:pin];
|
|
83
|
-
} else
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
} else {
|
|
84
|
+
if (oldPinVerifyResult == OKNFCLitePINVerifyResultNotMatch) {
|
|
85
|
+
status = OKNFCLiteSetMncStatusPinNotMatch;
|
|
86
|
+
if (self.pinRTL <= 0) {
|
|
87
|
+
BOOL restSeccuss = [self resetSync];
|
|
88
|
+
status = restSeccuss ? OKNFCLiteSetMncStatusWiped : OKNFCLiteSetMncStatusError;
|
|
89
|
+
}
|
|
88
90
|
}
|
|
91
|
+
if (status == OKNFCLiteSetMncStatusWiped) {
|
|
92
|
+
self.status = OKNFCLiteStatusNewCard;
|
|
93
|
+
}
|
|
94
|
+
[self.delegate endNFCSessionWithError:YES];
|
|
95
|
+
callBack(self,status);
|
|
96
|
+
return;
|
|
89
97
|
}
|
|
90
98
|
}
|
|
91
99
|
|
|
@@ -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-
|
|
3
|
+
"version": "6.7.0-23",
|
|
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",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"keys",
|
|
19
19
|
"android",
|
|
20
20
|
"ios",
|
|
21
|
-
"
|
|
21
|
+
"sdk",
|
|
22
22
|
"cpp",
|
|
23
23
|
"*.podspec",
|
|
24
24
|
"react-native.config.js",
|
|
@@ -66,11 +66,11 @@
|
|
|
66
66
|
"@eslint/compat": "^1.3.2",
|
|
67
67
|
"@eslint/eslintrc": "^3.3.1",
|
|
68
68
|
"@eslint/js": "^9.35.0",
|
|
69
|
-
"@react-native/babel-preset": "0.
|
|
70
|
-
"@react-native/eslint-config": "0.
|
|
69
|
+
"@react-native/babel-preset": "0.88.0",
|
|
70
|
+
"@react-native/eslint-config": "0.88.0",
|
|
71
71
|
"@release-it/conventional-changelog": "^10.0.1",
|
|
72
72
|
"@types/jest": "^29.5.14",
|
|
73
|
-
"@types/react": "^19.
|
|
73
|
+
"@types/react": "^19.3.0",
|
|
74
74
|
"commitlint": "^19.8.1",
|
|
75
75
|
"del-cli": "^6.0.0",
|
|
76
76
|
"eslint": "^9.35.0",
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
"jest": "^29.7.0",
|
|
80
80
|
"lefthook": "^2.0.3",
|
|
81
81
|
"prettier": "^2.8.8",
|
|
82
|
-
"react": "19.
|
|
83
|
-
"react-native": "patch:react-native@npm%3A0.
|
|
82
|
+
"react": "19.3.0",
|
|
83
|
+
"react-native": "patch:react-native@npm%3A0.88.0#~/.yarn/patches/react-native-npm-0.88.0-60c6201dd2.patch",
|
|
84
84
|
"react-native-builder-bob": "^0.40.13",
|
|
85
85
|
"release-it": "^19.0.4",
|
|
86
86
|
"turbo": "^2.5.6",
|
|
@@ -129,7 +129,7 @@
|
|
|
129
129
|
"useTabs": false
|
|
130
130
|
},
|
|
131
131
|
"jest": {
|
|
132
|
-
"preset": "react-native",
|
|
132
|
+
"preset": "@react-native/jest-preset",
|
|
133
133
|
"modulePathIgnorePatterns": [
|
|
134
134
|
"<rootDir>/example/node_modules",
|
|
135
135
|
"<rootDir>/lib/"
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.16)
|
|
2
|
+
project(GPChannelSDKCoreRecovered LANGUAGES C CXX)
|
|
3
|
+
set(CMAKE_C_STANDARD 99)
|
|
4
|
+
set(CMAKE_CXX_STANDARD 11)
|
|
5
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
6
|
+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
7
|
+
|
|
8
|
+
# Restore the original source dependencies without linking a vendor binary.
|
|
9
|
+
set(TREZOR_FILES
|
|
10
|
+
deps/trezor-crypto/src/bignum.c
|
|
11
|
+
deps/trezor-crypto/src/ecdsa.c
|
|
12
|
+
deps/trezor-crypto/src/curves.c
|
|
13
|
+
deps/trezor-crypto/src/secp256k1.c
|
|
14
|
+
deps/trezor-crypto/src/hmac.c
|
|
15
|
+
deps/trezor-crypto/src/bip32.c
|
|
16
|
+
deps/trezor-crypto/src/bip39.c
|
|
17
|
+
deps/trezor-crypto/src/pbkdf2.c
|
|
18
|
+
deps/trezor-crypto/src/base58.c
|
|
19
|
+
deps/trezor-crypto/src/base32.c
|
|
20
|
+
deps/trezor-crypto/src/address.c
|
|
21
|
+
deps/trezor-crypto/src/script.c
|
|
22
|
+
deps/trezor-crypto/src/ripemd160.c
|
|
23
|
+
deps/trezor-crypto/src/sha2.c
|
|
24
|
+
deps/trezor-crypto/src/sha3.c
|
|
25
|
+
deps/trezor-crypto/src/hasher.c
|
|
26
|
+
deps/trezor-crypto/src/aes/aescrypt.c
|
|
27
|
+
deps/trezor-crypto/src/aes/aeskey.c
|
|
28
|
+
deps/trezor-crypto/src/aes/aestab.c
|
|
29
|
+
deps/trezor-crypto/src/aes/aes_modes.c
|
|
30
|
+
deps/trezor-crypto/src/ed25519-donna/curve25519-donna-32bit.c
|
|
31
|
+
deps/trezor-crypto/src/ed25519-donna/curve25519-donna-helpers.c
|
|
32
|
+
deps/trezor-crypto/src/ed25519-donna/modm-donna-32bit.c
|
|
33
|
+
deps/trezor-crypto/src/ed25519-donna/ed25519-donna-basepoint-table.c
|
|
34
|
+
deps/trezor-crypto/src/ed25519-donna/ed25519-donna-32bit-tables.c
|
|
35
|
+
deps/trezor-crypto/src/ed25519-donna/ed25519-donna-impl-base.c
|
|
36
|
+
deps/trezor-crypto/src/ed25519-donna/ed25519.c
|
|
37
|
+
deps/trezor-crypto/src/ed25519-donna/curve25519-donna-scalarmult-base.c
|
|
38
|
+
deps/trezor-crypto/src/ed25519-donna/ed25519-sha3.c
|
|
39
|
+
deps/trezor-crypto/src/ed25519-donna/ed25519-keccak.c
|
|
40
|
+
deps/trezor-crypto/src/ed25519-donna/ed25519-blake2b.c
|
|
41
|
+
deps/trezor-crypto/src/sodium/private/fe_25_5/fe.c
|
|
42
|
+
deps/trezor-crypto/src/sodium/private/ed25519_ref10.c
|
|
43
|
+
deps/trezor-crypto/src/sodium/private/ed25519_ref10_fe_25_5.c
|
|
44
|
+
deps/trezor-crypto/src/sodium/keypair.c
|
|
45
|
+
deps/trezor-crypto/src/monero/base58.c
|
|
46
|
+
deps/trezor-crypto/src/monero/serialize.c
|
|
47
|
+
deps/trezor-crypto/src/monero/xmr.c
|
|
48
|
+
deps/trezor-crypto/src/monero/range_proof.c
|
|
49
|
+
deps/trezor-crypto/src/blake256.c
|
|
50
|
+
deps/trezor-crypto/src/blake2b.c
|
|
51
|
+
deps/trezor-crypto/src/blake2s.c
|
|
52
|
+
deps/trezor-crypto/src/chacha20poly1305/chacha20poly1305.c
|
|
53
|
+
deps/trezor-crypto/src/chacha20poly1305/chacha_merged.c
|
|
54
|
+
deps/trezor-crypto/src/chacha20poly1305/poly1305-donna.c
|
|
55
|
+
deps/trezor-crypto/src/chacha20poly1305/rfc7539.c
|
|
56
|
+
deps/trezor-crypto/src/rc4.c
|
|
57
|
+
deps/trezor-crypto/src/nano.c
|
|
58
|
+
deps/trezor-crypto/src/nem.c
|
|
59
|
+
deps/trezor-crypto/src/cash_addr.c
|
|
60
|
+
deps/trezor-crypto/src/memzero.c
|
|
61
|
+
deps/trezor-crypto/src/scrypt.c
|
|
62
|
+
deps/trezor-crypto/src/ripple/base58.c
|
|
63
|
+
deps/trezor-crypto/src/nist256p1.c
|
|
64
|
+
deps/trezor-crypto/src/groestl.c
|
|
65
|
+
deps/trezor-crypto/src/schnorr.c
|
|
66
|
+
deps/trezor-crypto/src/cmac.c
|
|
67
|
+
)
|
|
68
|
+
add_library(gpchannel_core STATIC
|
|
69
|
+
src/GPChannelSDK.cpp src/ApduBuilder.cpp src/random.c
|
|
70
|
+
gpc/src/scp03.cpp gpc/src/scp11.cpp gpc/src/scp11c.cpp gpc/src/tlv.cpp
|
|
71
|
+
${TREZOR_FILES})
|
|
72
|
+
target_include_directories(gpchannel_core PUBLIC include
|
|
73
|
+
PRIVATE gpc/include deps/trezor-crypto/include deps/trezor-crypto/src)
|
|
74
|
+
add_library(GPChannelSDKCore SHARED src/version.c
|
|
75
|
+
include/GPChannelSDK.h include/GPChannelSDKCore.h)
|
|
76
|
+
target_include_directories(GPChannelSDKCore PUBLIC include)
|
|
77
|
+
set_target_properties(GPChannelSDKCore PROPERTIES LINKER_LANGUAGE CXX)
|
|
78
|
+
# Export the complete vendor ABI even when no application links it at build time.
|
|
79
|
+
if(APPLE)
|
|
80
|
+
target_link_libraries(GPChannelSDKCore PRIVATE
|
|
81
|
+
"-Wl,-force_load,$<TARGET_FILE:gpchannel_core>" gpchannel_core)
|
|
82
|
+
else()
|
|
83
|
+
target_link_libraries(GPChannelSDKCore PRIVATE
|
|
84
|
+
"-Wl,--whole-archive" gpchannel_core "-Wl,--no-whole-archive")
|
|
85
|
+
endif()
|
|
86
|
+
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
|
|
87
|
+
set_target_properties(GPChannelSDKCore PROPERTIES FRAMEWORK TRUE
|
|
88
|
+
MACOSX_FRAMEWORK_IDENTIFIER "so.onekey.GPChannelSDKCoreRecovered"
|
|
89
|
+
PUBLIC_HEADER "include/GPChannelSDKCore.h;include/GPChannelSDK.h"
|
|
90
|
+
XCODE_ATTRIBUTE_DEFINES_MODULE YES
|
|
91
|
+
XCODE_ATTRIBUTE_CLANG_ENABLE_MODULES YES
|
|
92
|
+
XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED NO)
|
|
93
|
+
endif()
|
|
94
|
+
|
|
95
|
+
option(GPCHANNEL_HOST_JNI "Build JNI for a host-JVM contract check" OFF)
|
|
96
|
+
if(ANDROID OR GPCHANNEL_HOST_JNI)
|
|
97
|
+
add_library(gpchannelNDK SHARED android/implJni.cpp
|
|
98
|
+
deps/jsoncpp/src/lib_json/json_reader.cpp
|
|
99
|
+
deps/jsoncpp/src/lib_json/json_value.cpp
|
|
100
|
+
deps/jsoncpp/src/lib_json/json_writer.cpp)
|
|
101
|
+
target_include_directories(gpchannelNDK PRIVATE deps/jsoncpp/include)
|
|
102
|
+
target_link_libraries(gpchannelNDK PRIVATE gpchannel_core)
|
|
103
|
+
if(GPCHANNEL_HOST_JNI AND NOT ANDROID)
|
|
104
|
+
find_package(JNI REQUIRED)
|
|
105
|
+
target_include_directories(gpchannelNDK PRIVATE ${JNI_INCLUDE_DIRS})
|
|
106
|
+
endif()
|
|
107
|
+
endif()
|
|
108
|
+
|
|
109
|
+
include(CTest)
|
|
110
|
+
if(BUILD_TESTING AND NOT CMAKE_CROSSCOMPILING)
|
|
111
|
+
add_executable(gpchannel_safety tests/safety.cpp)
|
|
112
|
+
target_include_directories(gpchannel_safety PRIVATE include deps/trezor-crypto/include)
|
|
113
|
+
target_link_libraries(gpchannel_safety PRIVATE GPChannelSDKCore)
|
|
114
|
+
if(GPCHANNEL_HOST_JNI AND NOT ANDROID)
|
|
115
|
+
target_compile_definitions(gpchannel_safety PRIVATE GPCHANNEL_TEST_JNI=1)
|
|
116
|
+
target_include_directories(gpchannel_safety PRIVATE ${JNI_INCLUDE_DIRS})
|
|
117
|
+
target_link_libraries(gpchannel_safety PRIVATE gpchannelNDK)
|
|
118
|
+
endif()
|
|
119
|
+
add_test(NAME gpchannel_safety COMMAND gpchannel_safety)
|
|
120
|
+
endif()
|
package/sdk/README.md
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# OneKey Lite GPChannel SDK source recovery
|
|
2
|
+
|
|
3
|
+
A standalone, buildable reconstruction of the binary GPChannel core used by
|
|
4
|
+
`@onekeyfe/react-native-lite-card`. The native NFC transport and React Native
|
|
5
|
+
wrapper already have source in the parent package. This directory restores the
|
|
6
|
+
missing C++ core, its JNI adapter, source dependencies and documentation.
|
|
7
|
+
|
|
8
|
+
**Status:** source recovery integrated into the package's native builds and
|
|
9
|
+
release file list. CocoaPods compiles the core on iOS; Android CMake builds the
|
|
10
|
+
JNI library. Source, simulator/JNI and cryptographic vector evidence are separate
|
|
11
|
+
from physical-card and wallet-app acceptance.
|
|
12
|
+
|
|
13
|
+
See the package [behavior contract](../docs/SPEC.md).
|
|
14
|
+
|
|
15
|
+
## Build from source
|
|
16
|
+
|
|
17
|
+
Prerequisites: CMake 3.16+, a C/C++ compiler, Xcode for Apple targets and an Android
|
|
18
|
+
NDK for Android targets. All SDK source dependencies are checked in; no vendor
|
|
19
|
+
`.a`, `.so`, framework or network download participates in compilation.
|
|
20
|
+
Run these commands from this directory, with output directories of your choice.
|
|
21
|
+
|
|
22
|
+
Host library and focused native checks:
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
cmake -S . -B build-host -DCMAKE_BUILD_TYPE=Release
|
|
26
|
+
cmake --build build-host -j 4
|
|
27
|
+
ctest --test-dir build-host --output-on-failure
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Android (set `ANDROID_NDK` to your installed NDK directory; repeat for
|
|
31
|
+
`armeabi-v7a` when needed):
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
cmake -S . -B build-android-arm64 \
|
|
35
|
+
-DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \
|
|
36
|
+
-DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-24 \
|
|
37
|
+
-DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF
|
|
38
|
+
cmake --build build-android-arm64 -j 4
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`libgpchannelNDK.so` embeds the recovered core and retains the original JNI class,
|
|
42
|
+
method names, signatures and JSON fields. It does not depend on a second
|
|
43
|
+
`libGPChannelSDKCore.so`. The latter is also produced for standalone core users.
|
|
44
|
+
Strip copies of release artifacts as needed; preserve unstripped files for debug
|
|
45
|
+
symbols. The React Native package builds `keys` and `gpchannelNDK` directly from
|
|
46
|
+
its Android CMake entry point.
|
|
47
|
+
|
|
48
|
+
Apple frameworks (device and both simulator architectures):
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
cmake -S . -B build-ios-device -G Xcode \
|
|
52
|
+
-DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos \
|
|
53
|
+
-DCMAKE_OSX_ARCHITECTURES=arm64 -DCMAKE_OSX_DEPLOYMENT_TARGET=15.0 \
|
|
54
|
+
-DBUILD_TESTING=OFF
|
|
55
|
+
cmake --build build-ios-device --config Release -j 4
|
|
56
|
+
cmake -S . -B build-ios-simulator -G Xcode \
|
|
57
|
+
-DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator \
|
|
58
|
+
'-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64' \
|
|
59
|
+
-DCMAKE_OSX_DEPLOYMENT_TARGET=15.0 -DBUILD_TESTING=OFF
|
|
60
|
+
cmake --build build-ios-simulator --config Release -j 4
|
|
61
|
+
xcodebuild -create-xcframework \
|
|
62
|
+
-framework build-ios-device/Release-iphoneos/GPChannelSDKCore.framework \
|
|
63
|
+
-framework build-ios-simulator/Release-iphonesimulator/GPChannelSDKCore.framework \
|
|
64
|
+
-output build-artifacts/GPChannelSDKCore.xcframework
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Use an output path that does not already exist for `-create-xcframework`.
|
|
68
|
+
`GPChannelSDK.h` retains the vendor ABI, including its C++ reference parameter;
|
|
69
|
+
include it from C++/Objective-C++, not a pure C translation unit.
|
|
70
|
+
|
|
71
|
+
## API and lifecycle
|
|
72
|
+
|
|
73
|
+
| API | Contract |
|
|
74
|
+
| --- | --- |
|
|
75
|
+
| `JUB_GPC_TLVDecode` | Decode one supported vendor TLV; return numeric tag and hex value. |
|
|
76
|
+
| `JUB_GPC_ParseCertificate` | Parse the ASCII serial and hex subject identifier. Parsing does not authenticate a certificate or check its dates. |
|
|
77
|
+
| `JUB_GPC_Initialize` | Configure SCP11c, OCE certificate/key, host/group identifiers; generate a fresh ephemeral key pair. The recovered entry point accepts the existing AES-128 parameters. |
|
|
78
|
+
| `JUB_GPC_BuildMutualAuthData` | Build the mutual-authentication data after initialization. |
|
|
79
|
+
| `JUB_GPC_OpenSecureChannel` | Derive session keys and verify the card receipt; open only on success. |
|
|
80
|
+
| `JUB_GPC_BuildAPDU` / `JUB_GPC_ParseAPDUResponse` | Encode a plain command / separate response data and the status word. |
|
|
81
|
+
| `JUB_GPC_BuildSafeAPDU` / `JUB_GPC_ParseSafeAPDUResponse` | Encrypt/authenticate a command and authenticate/decrypt its response using the session state. |
|
|
82
|
+
| `JUB_GPC_Finalize` | Clear/release the session. Repeated finalization succeeds. |
|
|
83
|
+
| `JUB_FreeMemory` | Release an SDK output exactly once, including empty strings. |
|
|
84
|
+
|
|
85
|
+
Library return code `0` means the SDK operation succeeded. An APDU status word is
|
|
86
|
+
separate: callers must still check `wRet`, including PIN-retry status words.
|
|
87
|
+
All hexadecimal outputs use lowercase. The public header defines the error codes:
|
|
88
|
+
`1` operation error, `3` bad arguments, `5` null pointer, `6` unavailable session,
|
|
89
|
+
`8` invalid allocation pointer, and `10` response buffer too small.
|
|
90
|
+
|
|
91
|
+
The normal operation sequence is:
|
|
92
|
+
|
|
93
|
+
1. Read the card certificate using the existing transport. Parse it and check the
|
|
94
|
+
device serial/identity using the existing caller policy.
|
|
95
|
+
2. Initialize and send the OCE certificate with the existing PSO command.
|
|
96
|
+
3. Build/send the mutual-authentication command; open using the returned receipt.
|
|
97
|
+
4. Call safe command/response functions in pairs. They mutate shared MAC/counter
|
|
98
|
+
state. Serialize entire card sessions, not merely individual SDK calls.
|
|
99
|
+
5. Finalize on completion, NFC disconnect, cancellation or a SELECT command.
|
|
100
|
+
After a failed operation, finalize and reopen before starting a new operation.
|
|
101
|
+
|
|
102
|
+
The native core owns one process-wide session per loaded library instance. It is
|
|
103
|
+
shared underneath separate main/background JS runtimes on iOS and Android.
|
|
104
|
+
The API has per-call locking; it does not support concurrent independent sessions.
|
|
105
|
+
There is no persistent cache. Returned allocations remain caller-owned across
|
|
106
|
+
finalization and must be freed separately.
|
|
107
|
+
|
|
108
|
+
## Preserved platform differences
|
|
109
|
+
|
|
110
|
+
These were observed against the installed binaries and retained explicitly:
|
|
111
|
+
|
|
112
|
+
| Behavior | iOS / host reference | Android |
|
|
113
|
+
| --- | --- | --- |
|
|
114
|
+
| Plain response with 1–5 data bytes plus SW | Rejected by the vendor parser | Accepted |
|
|
115
|
+
| SCP03 ICV counter encoding | Low eight bits in the last byte | Full 32-bit big-endian value in the last four bytes |
|
|
116
|
+
| Non-success protected SW | Advance counter; recovered output is empty | Require valid MAC and decrypt the authenticated payload |
|
|
117
|
+
|
|
118
|
+
The recovery does not silently change the legacy iOS counter behavior. Reference
|
|
119
|
+
checks include exchanges across counter 255/256 to prevent collapsing the two
|
|
120
|
+
platform implementations into an incorrect common behavior. A future protocol
|
|
121
|
+
change requires its own card compatibility and cryptographic review.
|
|
122
|
+
|
|
123
|
+
## Deliberate safety differences
|
|
124
|
+
|
|
125
|
+
These are reconstruction decisions, not claims of byte-for-byte original source:
|
|
126
|
+
|
|
127
|
+
- Missing contexts and null pointers return errors instead of assertion aborts.
|
|
128
|
+
- Hex and TLV lengths are bounded and validated before memory reads. Certificate
|
|
129
|
+
inputs are limited to 1024 bytes, plain command data to 65535 bytes, and safe
|
|
130
|
+
command data to 65511 bytes. Parsed plaintext uses the vendor's 1024-byte buffer.
|
|
131
|
+
- Incomplete certificates/receipts, unsupported public TLV tags and malformed
|
|
132
|
+
protected responses are rejected. A non-success SW is returned only according to the platform authentication rules above.
|
|
133
|
+
- On iOS a safe error-only response returns empty data; the iOS vendor wrapper could
|
|
134
|
+
instead return its entire zero-filled 1024-byte scratch buffer.
|
|
135
|
+
- Empty outputs enter the allocation registry and can be freed. Finalization and
|
|
136
|
+
reinitialization release context objects instead of losing their pointers.
|
|
137
|
+
- JNI UTF strings have scoped ownership; the initialization key-length string
|
|
138
|
+
remains alive for the complete native call.
|
|
139
|
+
- Debug logging is always disabled. Interrupted/short entropy reads are handled;
|
|
140
|
+
entropy failure terminates instead of returning partially initialized bytes.
|
|
141
|
+
|
|
142
|
+
The upstream cryptographic primitives remain unchanged. Existing vendor protocol
|
|
143
|
+
choices, certificate trust policy and sensitive-memory clearing still require a
|
|
144
|
+
separate production security review; passing vectors do not prove those policies.
|
|
145
|
+
|
|
146
|
+
## Verification
|
|
147
|
+
|
|
148
|
+
`tests/verify.py` checks each SDK transcript against an independent implementation
|
|
149
|
+
of P-256 ECDH, SHA-1 preprocessing, KDF2/SHA-256, AES-CMAC and AES-CBC. It compares
|
|
150
|
+
plain APDU/TLV/certificate outputs, fresh sessions, bad receipts, modified response
|
|
151
|
+
MACs, encrypted payload boundaries, response limits and counter rollover. Reference
|
|
152
|
+
and recovery use independent random ephemeral keys; protocol code and entropy
|
|
153
|
+
functions in the reference are not patched.
|
|
154
|
+
|
|
155
|
+
```sh
|
|
156
|
+
python3 -m venv .venv
|
|
157
|
+
.venv/bin/pip install cryptography
|
|
158
|
+
.venv/bin/python tests/verify.py \
|
|
159
|
+
--library build-host/libGPChannelSDKCore.dylib \
|
|
160
|
+
--reference /path/to/disposable-host-reference.dylib \
|
|
161
|
+
--report /path/to/verification.json
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
On Linux use the `.so` filename. Omit `--reference` for oracle-only verification.
|
|
165
|
+
The Python dependency is a test tool, not an application/SDK dependency.
|
|
166
|
+
`tests/safety.cpp` exercises 5000 malformed inputs and allocation/lifecycle checks;
|
|
167
|
+
run it with AddressSanitizer/UBSan compiler and linker flags when supported.
|
|
168
|
+
|
|
169
|
+
`tests/android/GPChannelProxy.java` and `tests/android_verify.py` run the same oracle
|
|
170
|
+
against real Android ART/JNI and a separately loaded original `.so` in an isolated
|
|
171
|
+
emulator.
|
|
172
|
+
|
|
173
|
+
Physical Lite cards, NFC transport, real PIN/backup operations, the React Native
|
|
174
|
+
app flow and Android armv7 runtime remain separate acceptance requirements. No
|
|
175
|
+
production credentials are included or read by these tests.
|