@capgo/capacitor-updater 8.0.0 → 8.1.0

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 (64) hide show
  1. package/CapgoCapacitorUpdater.podspec +7 -5
  2. package/Package.swift +37 -0
  3. package/README.md +1461 -231
  4. package/android/build.gradle +29 -12
  5. package/android/proguard-rules.pro +45 -0
  6. package/android/src/main/AndroidManifest.xml +0 -1
  7. package/android/src/main/java/ee/forgr/capacitor_updater/BundleInfo.java +223 -195
  8. package/android/src/main/java/ee/forgr/capacitor_updater/BundleStatus.java +23 -23
  9. package/android/src/main/java/ee/forgr/capacitor_updater/Callback.java +13 -0
  10. package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +2159 -1234
  11. package/android/src/main/java/ee/forgr/capacitor_updater/CapgoUpdater.java +1507 -0
  12. package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipher.java +330 -121
  13. package/android/src/main/java/ee/forgr/capacitor_updater/DataManager.java +28 -0
  14. package/android/src/main/java/ee/forgr/capacitor_updater/DelayCondition.java +43 -49
  15. package/android/src/main/java/ee/forgr/capacitor_updater/DelayUntilNext.java +4 -4
  16. package/android/src/main/java/ee/forgr/capacitor_updater/DelayUpdateUtils.java +260 -0
  17. package/android/src/main/java/ee/forgr/capacitor_updater/DeviceIdHelper.java +221 -0
  18. package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +808 -117
  19. package/android/src/main/java/ee/forgr/capacitor_updater/DownloadWorkerManager.java +156 -0
  20. package/android/src/main/java/ee/forgr/capacitor_updater/InternalUtils.java +32 -0
  21. package/android/src/main/java/ee/forgr/capacitor_updater/Logger.java +338 -0
  22. package/android/src/main/java/ee/forgr/capacitor_updater/ShakeDetector.java +72 -0
  23. package/android/src/main/java/ee/forgr/capacitor_updater/ShakeMenu.java +169 -0
  24. package/dist/docs.json +2187 -625
  25. package/dist/esm/definitions.d.ts +1286 -249
  26. package/dist/esm/definitions.js.map +1 -1
  27. package/dist/esm/history.d.ts +1 -0
  28. package/dist/esm/history.js +283 -0
  29. package/dist/esm/history.js.map +1 -0
  30. package/dist/esm/index.d.ts +3 -2
  31. package/dist/esm/index.js +5 -4
  32. package/dist/esm/index.js.map +1 -1
  33. package/dist/esm/web.d.ts +36 -41
  34. package/dist/esm/web.js +94 -35
  35. package/dist/esm/web.js.map +1 -1
  36. package/dist/plugin.cjs.js +376 -35
  37. package/dist/plugin.cjs.js.map +1 -1
  38. package/dist/plugin.js +376 -35
  39. package/dist/plugin.js.map +1 -1
  40. package/ios/Sources/CapacitorUpdaterPlugin/AES.swift +69 -0
  41. package/ios/Sources/CapacitorUpdaterPlugin/BigInt.swift +55 -0
  42. package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/BundleInfo.swift +37 -10
  43. package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/BundleStatus.swift +1 -1
  44. package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +1605 -0
  45. package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +1526 -0
  46. package/ios/Sources/CapacitorUpdaterPlugin/CryptoCipher.swift +267 -0
  47. package/ios/Sources/CapacitorUpdaterPlugin/DelayUpdateUtils.swift +220 -0
  48. package/ios/Sources/CapacitorUpdaterPlugin/DeviceIdHelper.swift +120 -0
  49. package/ios/Sources/CapacitorUpdaterPlugin/InternalUtils.swift +311 -0
  50. package/ios/Sources/CapacitorUpdaterPlugin/Logger.swift +310 -0
  51. package/ios/Sources/CapacitorUpdaterPlugin/RSA.swift +274 -0
  52. package/ios/Sources/CapacitorUpdaterPlugin/ShakeMenu.swift +112 -0
  53. package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/UserDefaultsExtension.swift +0 -2
  54. package/package.json +41 -35
  55. package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java +0 -1130
  56. package/ios/Plugin/CapacitorUpdater.swift +0 -858
  57. package/ios/Plugin/CapacitorUpdaterPlugin.h +0 -10
  58. package/ios/Plugin/CapacitorUpdaterPlugin.m +0 -27
  59. package/ios/Plugin/CapacitorUpdaterPlugin.swift +0 -675
  60. package/ios/Plugin/CryptoCipher.swift +0 -240
  61. /package/{LICENCE → LICENSE} +0 -0
  62. /package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/DelayCondition.swift +0 -0
  63. /package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/DelayUntilNext.swift +0 -0
  64. /package/ios/{Plugin → Sources/CapacitorUpdaterPlugin}/Info.plist +0 -0
@@ -1,240 +0,0 @@
1
- /*
2
- * This Source Code Form is subject to the terms of the Mozilla Public
3
- * License, v. 2.0. If a copy of the MPL was not distributed with this
4
- * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
- */
6
-
7
- import Foundation
8
- import CommonCrypto
9
-
10
- ///
11
- /// Constants
12
- ///
13
- private enum CryptoCipherConstants {
14
- static let rsaKeySizeInBits: NSNumber = 2048
15
- static let aesAlgorithm: CCAlgorithm = CCAlgorithm(kCCAlgorithmAES)
16
- static let aesOptions: CCOptions = CCOptions(kCCOptionPKCS7Padding)
17
- static let rsaAlgorithm: SecKeyAlgorithm = .rsaEncryptionOAEPSHA256
18
- }
19
- ///
20
- /// The AES key. Contains both the initialization vector and secret key.
21
- ///
22
- public struct AES128Key {
23
- /// Initialization vector
24
- private let iv: Data
25
- private let aes128Key: Data
26
- #if DEBUG
27
- public var __debug_iv: Data { iv }
28
- public var __debug_aes128Key: Data { aes128Key }
29
- #endif
30
- init(iv: Data, aes128Key: Data) {
31
- self.iv = iv
32
- self.aes128Key = aes128Key
33
- }
34
- ///
35
- /// Takes the data and uses the private key to decrypt it. Will call `CCCrypt` in CommonCrypto
36
- /// and provide it `ivData` for the initialization vector. Will use cipher block chaining (CBC) as
37
- /// the mode of operation.
38
- ///
39
- /// Returns the decrypted data.
40
- ///
41
- public func decrypt(data: Data) -> Data? {
42
- let encryptedData: UnsafePointer<UInt8> = (data as NSData).bytes.bindMemory(to: UInt8.self, capacity: data.count)
43
- let encryptedDataLength: Int = data.count
44
-
45
- if let result: NSMutableData = NSMutableData(length: encryptedDataLength) {
46
- let keyData: UnsafePointer<UInt8> = (self.aes128Key as NSData).bytes.bindMemory(to: UInt8.self, capacity: self.aes128Key.count)
47
- let keyLength: size_t = size_t(self.aes128Key.count)
48
- let ivData: UnsafePointer<UInt8> = (iv as NSData).bytes.bindMemory(to: UInt8.self, capacity: self.iv.count)
49
-
50
- let decryptedData: UnsafeMutablePointer<UInt8> = UnsafeMutablePointer<UInt8>(result.mutableBytes.assumingMemoryBound(to: UInt8.self))
51
- let decryptedDataLength: size_t = size_t(result.length)
52
-
53
- var decryptedLength: size_t = 0
54
-
55
- let status: CCCryptorStatus = CCCrypt(CCOperation(kCCDecrypt), CryptoCipherConstants.aesAlgorithm, CryptoCipherConstants.aesOptions, keyData, keyLength, ivData, encryptedData, encryptedDataLength, decryptedData, decryptedDataLength, &decryptedLength)
56
-
57
- if UInt32(status) == UInt32(kCCSuccess) {
58
- result.length = Int(decryptedLength)
59
- return result as Data
60
- } else {
61
- return nil
62
- }
63
- } else {
64
- return nil
65
- }
66
- }
67
- }
68
-
69
- ///
70
- /// The RSA keypair. Includes both private and public key.
71
- ///
72
- public struct RSAKeyPair {
73
- private let privateKey: SecKey
74
- private let publicKey: SecKey
75
-
76
- #if DEBUG
77
- public var __debug_privateKey: SecKey { self.privateKey }
78
- public var __debug_publicKey: SecKey { self.publicKey }
79
- #endif
80
-
81
- fileprivate init(privateKey: SecKey, publicKey: SecKey) {
82
- self.privateKey = privateKey
83
- self.publicKey = publicKey
84
- }
85
-
86
- public func extractPublicKey() -> RSAPublicKey {
87
- RSAPublicKey(publicKey: publicKey)
88
- }
89
-
90
- ///
91
- /// Takes the data and uses the private key to decrypt it.
92
- /// Returns the decrypted data.
93
- ///
94
- public func decrypt(data: Data) -> Data? {
95
- var error: Unmanaged<CFError>?
96
- if let decryptedData: CFData = SecKeyCreateDecryptedData(self.privateKey, CryptoCipherConstants.rsaAlgorithm, data as CFData, &error) {
97
- if error != nil {
98
- return nil
99
- } else {
100
- return decryptedData as Data
101
- }
102
- } else {
103
- return nil
104
- }
105
- }
106
- }
107
-
108
- ///
109
- /// The RSA public key.
110
- ///
111
- public struct RSAPublicKey {
112
- private let publicKey: SecKey
113
-
114
- #if DEBUG
115
- public var __debug_publicKey: SecKey { self.publicKey }
116
- #endif
117
-
118
- fileprivate init(publicKey: SecKey) {
119
- self.publicKey = publicKey
120
- }
121
- ///
122
- /// Takes the data and uses the public key to encrypt it.
123
- /// Returns the encrypted data.
124
- ///
125
- public func encrypt(data: Data) -> Data? {
126
- var error: Unmanaged<CFError>?
127
- if let encryptedData: CFData = SecKeyCreateEncryptedData(self.publicKey, CryptoCipherConstants.rsaAlgorithm, data as CFData, &error) {
128
- if error != nil {
129
- return nil
130
- } else {
131
- return encryptedData as Data
132
- }
133
- } else {
134
- return nil
135
- }
136
- }
137
- ///
138
- /// Allows you to export the RSA public key to a format (so you can send over the net).
139
- ///
140
- public func export() -> Data? {
141
- return publicKey.exportToData()
142
- }
143
- //
144
-
145
- ///
146
- /// Allows you to load an RSA public key (i.e. one downloaded from the net).
147
- ///
148
- public static func load(rsaPublicKeyData: Data) -> RSAPublicKey? {
149
- if let publicKey: SecKey = .loadPublicFromData(rsaPublicKeyData) {
150
- return RSAPublicKey(publicKey: publicKey)
151
- } else {
152
- return nil
153
- }
154
- }
155
- }
156
- ///
157
- /// The RSA public key.
158
- ///
159
- public struct RSAPrivateKey {
160
- private let privateKey: SecKey
161
-
162
- #if DEBUG
163
- public var __debug_privateKey: SecKey { self.privateKey }
164
- #endif
165
-
166
- fileprivate init(privateKey: SecKey) {
167
- self.privateKey = privateKey
168
- }
169
- ///
170
- /// Takes the data and uses the private key to decrypt it.
171
- /// Returns the decrypted data.
172
- ///
173
- public func decrypt(data: Data) -> Data? {
174
- var error: Unmanaged<CFError>?
175
- if let decryptedData: CFData = SecKeyCreateDecryptedData(self.privateKey, CryptoCipherConstants.rsaAlgorithm, data as CFData, &error) {
176
- if error != nil {
177
- return nil
178
- } else {
179
- return decryptedData as Data
180
- }
181
- } else {
182
- return nil
183
- }
184
- }
185
-
186
- ///
187
- /// Allows you to export the RSA public key to a format (so you can send over the net).
188
- ///
189
- public func export() -> Data? {
190
- return privateKey.exportToData()
191
- }
192
-
193
- ///
194
- /// Allows you to load an RSA public key (i.e. one downloaded from the net).
195
- ///
196
- public static func load(rsaPrivateKey: String) -> RSAPrivateKey? {
197
- var privKey: String = rsaPrivateKey
198
- privKey = privKey.replacingOccurrences(of: "-----BEGIN RSA PRIVATE KEY-----", with: "")
199
- privKey = privKey.replacingOccurrences(of: "-----END RSA PRIVATE KEY-----", with: "")
200
- privKey = privKey.replacingOccurrences(of: "\\n+", with: "", options: .regularExpression)
201
- privKey = privKey.trimmingCharacters(in: .whitespacesAndNewlines)
202
- let rsaPrivateKeyData: Data = Data(base64Encoded: privKey)!
203
- if let privateKey: SecKey = .loadPrivateFromData(rsaPrivateKeyData) {
204
- return RSAPrivateKey(privateKey: privateKey)
205
- } else {
206
- return nil
207
- }
208
- }
209
- }
210
-
211
- fileprivate extension SecKey {
212
- func exportToData() -> Data? {
213
- var error: Unmanaged<CFError>?
214
- if let cfData: CFData = SecKeyCopyExternalRepresentation(self, &error) {
215
- if error != nil {
216
- return nil
217
- } else {
218
- return cfData as Data
219
- }
220
- } else {
221
- return nil
222
- }
223
- }
224
- static func loadPublicFromData(_ data: Data) -> SecKey? {
225
- let keyDict: [NSObject: NSObject] = [
226
- kSecAttrKeyType: kSecAttrKeyTypeRSA,
227
- kSecAttrKeyClass: kSecAttrKeyClassPublic,
228
- kSecAttrKeySizeInBits: CryptoCipherConstants.rsaKeySizeInBits
229
- ]
230
- return SecKeyCreateWithData(data as CFData, keyDict as CFDictionary, nil)
231
- }
232
- static func loadPrivateFromData(_ data: Data) -> SecKey? {
233
- let keyDict: [NSObject: NSObject] = [
234
- kSecAttrKeyType: kSecAttrKeyTypeRSA,
235
- kSecAttrKeyClass: kSecAttrKeyClassPrivate,
236
- kSecAttrKeySizeInBits: CryptoCipherConstants.rsaKeySizeInBits
237
- ]
238
- return SecKeyCreateWithData(data as CFData, keyDict as CFDictionary, nil)
239
- }
240
- }
File without changes