react-native-instantpay-code-push 1.2.4 → 1.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (17) hide show
  1. package/InstantpayCodePush.podspec +2 -1
  2. package/ios/{InstantpayCodePush.mm → IpayCodePush/Private/InstantpayCodePush.mm} +1 -1
  3. package/ios/{IpayCodePushImpl.swift → IpayCodePush/Private/IpayCodePushImpl.swift} +4 -0
  4. package/ios/{SignatureVerifier.swift → IpayCodePush/Private/SignatureVerifier.swift} +69 -1
  5. package/ios/{InstantpayCodePush.h → IpayCodePush/Public/InstantpayCodePush.h} +6 -1
  6. package/package.json +1 -1
  7. /package/ios/{BundleFileStorageService.swift → IpayCodePush/Private/BundleFileStorageService.swift} +0 -0
  8. /package/ios/{BundleMetadata.swift → IpayCodePush/Private/BundleMetadata.swift} +0 -0
  9. /package/ios/{DecompressService.swift → IpayCodePush/Private/DecompressService.swift} +0 -0
  10. /package/ios/{FileManagerService.swift → IpayCodePush/Private/FileManagerService.swift} +0 -0
  11. /package/ios/{HashUtils.swift → IpayCodePush/Private/HashUtils.swift} +0 -0
  12. /package/ios/{InstantpayCodePush-Bridging-Header.h → IpayCodePush/Private/InstantpayCodePush-Bridging-Header.h} +0 -0
  13. /package/ios/{IpayCodePushHelper.swift → IpayCodePush/Private/IpayCodePushHelper.swift} +0 -0
  14. /package/ios/{NotificationExtension.swift → IpayCodePush/Private/NotificationExtension.swift} +0 -0
  15. /package/ios/{URLSessionDownloadService.swift → IpayCodePush/Private/URLSessionDownloadService.swift} +0 -0
  16. /package/ios/{VersionedPreferencesService.swift → IpayCodePush/Private/VersionedPreferencesService.swift} +0 -0
  17. /package/ios/{ZipDecompressionStrategy.swift → IpayCodePush/Private/ZipDecompressionStrategy.swift} +0 -0
@@ -14,8 +14,9 @@ Pod::Spec.new do |s|
14
14
  s.source = { :git => "https://github.com/InstantPay/react-native-instantpay-code-push.git", :tag => "#{s.version}" }
15
15
 
16
16
  s.source_files = "ios/**/*.{h,m,mm,swift,cpp}"
17
- s.public_header_files = "ios/**/*.h"
18
17
  #s.private_header_files = "ios/**/*.h"
18
+ s.public_header_files = "ios/IpayCodePush/Public/*.h"
19
+ s.private_header_files = "ios/IpayCodePush/Private/*.h"
19
20
 
20
21
  s.pod_target_xcconfig = {
21
22
  "DEFINES_MODULE" => "YES",
@@ -328,7 +328,7 @@ RCT_EXPORT_MODULE();
328
328
  .APP_VERSION = [IpayCodePushImpl appVersion],
329
329
  .CHANNEL = [impl getChannel],
330
330
  .FINGERPRINT_HASH = [impl getFingerprintHash],
331
- .KEYSTORE_PUBLIC_KEY = nil
331
+ .KEYSTORE_PUBLIC_KEY = [IpayCodePushImpl getKeyChainPublickey],
332
332
  });
333
333
  }
334
334
 
@@ -94,6 +94,10 @@ import React
94
94
  return "ipaycodepush_\(baseKey)_\(appChannel)_"
95
95
  }
96
96
 
97
+ public static var getKeyChainPublickey: String {
98
+ return SignatureVerifier.getDevicePublicKeyBase64() ?? ""
99
+ }
100
+
97
101
  // MARK: - Channel Management
98
102
 
99
103
  /**
@@ -300,7 +300,7 @@ public class SignatureVerifier {
300
300
  */
301
301
  private static func createPublicKey(from publicKeyPEM: String) -> Result<SecKey, SignatureVerificationError> {
302
302
  // Remove PEM headers/footers and whitespace
303
- var keyString = publicKeyPEM
303
+ let keyString = publicKeyPEM
304
304
  .replacingOccurrences(of: "-----BEGIN PUBLIC KEY-----", with: "")
305
305
  .replacingOccurrences(of: "-----END PUBLIC KEY-----", with: "")
306
306
  .replacingOccurrences(of: "\\n", with: "")
@@ -354,5 +354,73 @@ public class SignatureVerifier {
354
354
  return data
355
355
  }
356
356
 
357
+ private static let KEY_ALIAS = "com.ipaycodepush.security.rsa"
358
+
359
+ /**
360
+ * Get Device Public Key of generated KeyChain
361
+ */
362
+ public static func getDevicePublicKeyBase64() -> String? {
363
+
364
+ if let existingKey = getPrivateKey() {
365
+ return exportPublicKeyBase64(from: existingKey)
366
+ }
367
+
368
+ // If not exists → generate
369
+ generateKeyChain()
370
+ guard let newKey = getPrivateKey() else { return nil }
371
+ return exportPublicKeyBase64(from: newKey)
372
+ }
373
+
374
+ /**
375
+ * Generate a new EC key pair entry in the Ios Keychain by
376
+ * using the KeyPairGenerator API.
377
+ */
378
+
379
+ private static func generateKeyChain() -> Void {
380
+
381
+ let tagData = KEY_ALIAS.data(using: .utf8)!
382
+
383
+ let attributes: [String: Any] = [
384
+ kSecAttrKeyType as String: kSecAttrKeyTypeRSA,
385
+ kSecAttrKeySizeInBits as String: 2048,
386
+ kSecAttrTokenID as String: kSecAttrTokenIDSecureEnclave,
387
+ kSecPrivateKeyAttrs as String: [
388
+ kSecAttrIsPermanent as String: true,
389
+ kSecAttrApplicationTag as String: tagData
390
+ ]
391
+ ]
392
+
393
+ SecKeyCreateRandomKey(attributes as CFDictionary, nil)
394
+ }
395
+
396
+ /**
397
+ * Get Private Key of device keychain
398
+ */
399
+ private static func getPrivateKey() -> SecKey? {
400
+
401
+ let tagData = KEY_ALIAS.data(using: .utf8)!
402
+
403
+ let query: [String: Any] = [
404
+ kSecClass as String: kSecClassKey,
405
+ kSecAttrApplicationTag as String: tagData,
406
+ kSecAttrKeyType as String: kSecAttrKeyTypeRSA,
407
+ kSecReturnRef as String: true
408
+ ]
409
+
410
+ var item: CFTypeRef?
411
+ SecItemCopyMatching(query as CFDictionary, &item)
412
+ return (item as! SecKey?)
413
+ }
414
+
415
+ /**
416
+ * Get Public key of generated Private Key
417
+ */
418
+ private static func exportPublicKeyBase64(from privateKey: SecKey) -> String? {
419
+
420
+ guard let publicKey = SecKeyCopyPublicKey(privateKey) else { return nil }
421
+ guard let data = SecKeyCopyExternalRepresentation(publicKey, nil) as Data? else { return nil }
422
+
423
+ return data.base64EncodedString()
424
+ }
357
425
 
358
426
  }
@@ -1,8 +1,13 @@
1
- #import <InstantpayCodePushSpec/InstantpayCodePushSpec.h>
2
1
  #import <React/RCTEventEmitter.h>
3
2
  #import <React/RCTBundleURLProvider.h>
4
3
 
4
+ #ifdef RCT_NEW_ARCH_ENABLED
5
+ #import <InstantpayCodePushSpec/InstantpayCodePushSpec.h>
5
6
  @interface InstantpayCodePush : RCTEventEmitter <NativeInstantpayCodePushSpec>
7
+ #else
8
+ #import <React/RCTBridgeModule.h>
9
+ @interface InstantpayCodePush : RCTEventEmitter <RCTBridgeModule>
10
+ #endif
6
11
 
7
12
  /**
8
13
  * Returns the currently active bundle URL from the default (static) instance.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-instantpay-code-push",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "description": "React Native plugin for the CodePush service",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",