@swiftpatch/react-native 2.0.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.
- package/README.md +430 -0
- package/android/build.gradle +105 -0
- package/android/src/main/AndroidManifest.xml +6 -0
- package/android/src/main/java/com/swiftpatch/BundleManager.kt +107 -0
- package/android/src/main/java/com/swiftpatch/CrashDetector.kt +79 -0
- package/android/src/main/java/com/swiftpatch/CryptoVerifier.kt +69 -0
- package/android/src/main/java/com/swiftpatch/DownloadManager.kt +120 -0
- package/android/src/main/java/com/swiftpatch/EventQueue.kt +86 -0
- package/android/src/main/java/com/swiftpatch/FileUtils.kt +60 -0
- package/android/src/main/java/com/swiftpatch/PatchApplier.kt +60 -0
- package/android/src/main/java/com/swiftpatch/SignalCrashHandler.kt +84 -0
- package/android/src/main/java/com/swiftpatch/SlotManager.kt +299 -0
- package/android/src/main/java/com/swiftpatch/SwiftPatchModule.kt +630 -0
- package/android/src/main/java/com/swiftpatch/SwiftPatchPackage.kt +21 -0
- package/android/src/main/jni/CMakeLists.txt +12 -0
- package/android/src/main/jni/bspatch.c +188 -0
- package/android/src/main/jni/bspatch.h +57 -0
- package/android/src/main/jni/bspatch_jni.c +28 -0
- package/ios/Libraries/bspatch/bspatch.c +188 -0
- package/ios/Libraries/bspatch/bspatch.h +50 -0
- package/ios/Libraries/bspatch/module.modulemap +4 -0
- package/ios/SwiftPatch/BundleManager.swift +113 -0
- package/ios/SwiftPatch/CrashDetector.swift +71 -0
- package/ios/SwiftPatch/CryptoVerifier.swift +70 -0
- package/ios/SwiftPatch/DownloadManager.swift +125 -0
- package/ios/SwiftPatch/EventQueue.swift +116 -0
- package/ios/SwiftPatch/FileUtils.swift +38 -0
- package/ios/SwiftPatch/PatchApplier.swift +41 -0
- package/ios/SwiftPatch/SignalCrashHandler.swift +129 -0
- package/ios/SwiftPatch/SlotManager.swift +360 -0
- package/ios/SwiftPatch/SwiftPatchModule.m +56 -0
- package/ios/SwiftPatch/SwiftPatchModule.swift +621 -0
- package/lib/commonjs/SwiftPatchCore.js +140 -0
- package/lib/commonjs/SwiftPatchCore.js.map +1 -0
- package/lib/commonjs/SwiftPatchProvider.js +617 -0
- package/lib/commonjs/SwiftPatchProvider.js.map +1 -0
- package/lib/commonjs/constants.js +50 -0
- package/lib/commonjs/constants.js.map +1 -0
- package/lib/commonjs/core/Downloader.js +63 -0
- package/lib/commonjs/core/Downloader.js.map +1 -0
- package/lib/commonjs/core/Installer.js +46 -0
- package/lib/commonjs/core/Installer.js.map +1 -0
- package/lib/commonjs/core/Rollback.js +36 -0
- package/lib/commonjs/core/Rollback.js.map +1 -0
- package/lib/commonjs/core/UpdateChecker.js +57 -0
- package/lib/commonjs/core/UpdateChecker.js.map +1 -0
- package/lib/commonjs/core/Verifier.js +82 -0
- package/lib/commonjs/core/Verifier.js.map +1 -0
- package/lib/commonjs/core/index.js +41 -0
- package/lib/commonjs/core/index.js.map +1 -0
- package/lib/commonjs/index.js +154 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/modal/SwiftPatchModal.js +667 -0
- package/lib/commonjs/modal/SwiftPatchModal.js.map +1 -0
- package/lib/commonjs/modal/useSwiftPatchModal.js +26 -0
- package/lib/commonjs/modal/useSwiftPatchModal.js.map +1 -0
- package/lib/commonjs/native/NativeSwiftPatch.js +85 -0
- package/lib/commonjs/native/NativeSwiftPatch.js.map +1 -0
- package/lib/commonjs/native/NativeSwiftPatchSpec.js +15 -0
- package/lib/commonjs/native/NativeSwiftPatchSpec.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/types.js +126 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/useSwiftPatch.js +31 -0
- package/lib/commonjs/useSwiftPatch.js.map +1 -0
- package/lib/commonjs/utils/api.js +206 -0
- package/lib/commonjs/utils/api.js.map +1 -0
- package/lib/commonjs/utils/device.js +23 -0
- package/lib/commonjs/utils/device.js.map +1 -0
- package/lib/commonjs/utils/logger.js +30 -0
- package/lib/commonjs/utils/logger.js.map +1 -0
- package/lib/commonjs/utils/storage.js +31 -0
- package/lib/commonjs/utils/storage.js.map +1 -0
- package/lib/commonjs/withSwiftPatch.js +42 -0
- package/lib/commonjs/withSwiftPatch.js.map +1 -0
- package/lib/module/SwiftPatchCore.js +135 -0
- package/lib/module/SwiftPatchCore.js.map +1 -0
- package/lib/module/SwiftPatchProvider.js +611 -0
- package/lib/module/SwiftPatchProvider.js.map +1 -0
- package/lib/module/constants.js +46 -0
- package/lib/module/constants.js.map +1 -0
- package/lib/module/core/Downloader.js +57 -0
- package/lib/module/core/Downloader.js.map +1 -0
- package/lib/module/core/Installer.js +41 -0
- package/lib/module/core/Installer.js.map +1 -0
- package/lib/module/core/Rollback.js +31 -0
- package/lib/module/core/Rollback.js.map +1 -0
- package/lib/module/core/UpdateChecker.js +51 -0
- package/lib/module/core/UpdateChecker.js.map +1 -0
- package/lib/module/core/Verifier.js +76 -0
- package/lib/module/core/Verifier.js.map +1 -0
- package/lib/module/core/index.js +8 -0
- package/lib/module/core/index.js.map +1 -0
- package/lib/module/index.js +34 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/modal/SwiftPatchModal.js +661 -0
- package/lib/module/modal/SwiftPatchModal.js.map +1 -0
- package/lib/module/modal/useSwiftPatchModal.js +22 -0
- package/lib/module/modal/useSwiftPatchModal.js.map +1 -0
- package/lib/module/native/NativeSwiftPatch.js +78 -0
- package/lib/module/native/NativeSwiftPatch.js.map +1 -0
- package/lib/module/native/NativeSwiftPatchSpec.js +12 -0
- package/lib/module/native/NativeSwiftPatchSpec.js.map +1 -0
- package/lib/module/types.js +139 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/useSwiftPatch.js +26 -0
- package/lib/module/useSwiftPatch.js.map +1 -0
- package/lib/module/utils/api.js +197 -0
- package/lib/module/utils/api.js.map +1 -0
- package/lib/module/utils/device.js +18 -0
- package/lib/module/utils/device.js.map +1 -0
- package/lib/module/utils/logger.js +26 -0
- package/lib/module/utils/logger.js.map +1 -0
- package/lib/module/utils/storage.js +24 -0
- package/lib/module/utils/storage.js.map +1 -0
- package/lib/module/withSwiftPatch.js +37 -0
- package/lib/module/withSwiftPatch.js.map +1 -0
- package/lib/typescript/SwiftPatchCore.d.ts +64 -0
- package/lib/typescript/SwiftPatchCore.d.ts.map +1 -0
- package/lib/typescript/SwiftPatchProvider.d.ts +22 -0
- package/lib/typescript/SwiftPatchProvider.d.ts.map +1 -0
- package/lib/typescript/constants.d.ts +33 -0
- package/lib/typescript/constants.d.ts.map +1 -0
- package/lib/typescript/core/Downloader.d.ts +34 -0
- package/lib/typescript/core/Downloader.d.ts.map +1 -0
- package/lib/typescript/core/Installer.d.ts +25 -0
- package/lib/typescript/core/Installer.d.ts.map +1 -0
- package/lib/typescript/core/Rollback.d.ts +18 -0
- package/lib/typescript/core/Rollback.d.ts.map +1 -0
- package/lib/typescript/core/UpdateChecker.d.ts +27 -0
- package/lib/typescript/core/UpdateChecker.d.ts.map +1 -0
- package/lib/typescript/core/Verifier.d.ts +31 -0
- package/lib/typescript/core/Verifier.d.ts.map +1 -0
- package/lib/typescript/core/index.d.ts +8 -0
- package/lib/typescript/core/index.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +13 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/modal/SwiftPatchModal.d.ts +11 -0
- package/lib/typescript/modal/SwiftPatchModal.d.ts.map +1 -0
- package/lib/typescript/modal/useSwiftPatchModal.d.ts +7 -0
- package/lib/typescript/modal/useSwiftPatchModal.d.ts.map +1 -0
- package/lib/typescript/native/NativeSwiftPatch.d.ts +61 -0
- package/lib/typescript/native/NativeSwiftPatch.d.ts.map +1 -0
- package/lib/typescript/native/NativeSwiftPatchSpec.d.ts +67 -0
- package/lib/typescript/native/NativeSwiftPatchSpec.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +266 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/lib/typescript/useSwiftPatch.d.ts +12 -0
- package/lib/typescript/useSwiftPatch.d.ts.map +1 -0
- package/lib/typescript/utils/api.d.ts +87 -0
- package/lib/typescript/utils/api.d.ts.map +1 -0
- package/lib/typescript/utils/device.d.ts +9 -0
- package/lib/typescript/utils/device.d.ts.map +1 -0
- package/lib/typescript/utils/logger.d.ts +8 -0
- package/lib/typescript/utils/logger.d.ts.map +1 -0
- package/lib/typescript/utils/storage.d.ts +14 -0
- package/lib/typescript/utils/storage.d.ts.map +1 -0
- package/lib/typescript/withSwiftPatch.d.ts +12 -0
- package/lib/typescript/withSwiftPatch.d.ts.map +1 -0
- package/package.json +99 -0
- package/react-native-swiftpatch.podspec +50 -0
- package/src/SwiftPatchCore.ts +148 -0
- package/src/SwiftPatchProvider.tsx +514 -0
- package/src/constants.ts +49 -0
- package/src/core/Downloader.ts +74 -0
- package/src/core/Installer.ts +38 -0
- package/src/core/Rollback.ts +28 -0
- package/src/core/UpdateChecker.ts +70 -0
- package/src/core/Verifier.ts +92 -0
- package/src/core/index.ts +11 -0
- package/src/index.ts +64 -0
- package/src/modal/SwiftPatchModal.tsx +657 -0
- package/src/modal/useSwiftPatchModal.ts +24 -0
- package/src/native/NativeSwiftPatch.ts +205 -0
- package/src/native/NativeSwiftPatchSpec.ts +139 -0
- package/src/types.ts +336 -0
- package/src/useSwiftPatch.ts +29 -0
- package/src/utils/api.ts +244 -0
- package/src/utils/device.ts +15 -0
- package/src/utils/logger.ts +29 -0
- package/src/utils/storage.ts +23 -0
- package/src/withSwiftPatch.tsx +41 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import NativeSwiftPatch, { onDownloadProgress } from '../native/NativeSwiftPatch';
|
|
4
|
+
import { logger } from '../utils/logger';
|
|
5
|
+
/**
|
|
6
|
+
* Core module responsible for downloading OTA bundles or patches.
|
|
7
|
+
*
|
|
8
|
+
* Delegates to the native module for actual download + disk I/O.
|
|
9
|
+
* Provides progress tracking and cancellation.
|
|
10
|
+
*/
|
|
11
|
+
export class Downloader {
|
|
12
|
+
unsubscribeProgress = null;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Download a bundle or patch from the given options.
|
|
16
|
+
*/
|
|
17
|
+
async download(options) {
|
|
18
|
+
logger.info(`Downloading ${options.isPatch ? 'patch' : 'full bundle'}: ${options.expectedHash}`);
|
|
19
|
+
await NativeSwiftPatch.downloadUpdate(options.url, options.expectedHash, options.isPatch, options.signature);
|
|
20
|
+
logger.info('Download complete');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Convenience: download a release (extracts fields from ReleaseInfo).
|
|
25
|
+
*/
|
|
26
|
+
async downloadRelease(release) {
|
|
27
|
+
await this.download({
|
|
28
|
+
url: release.downloadUrl,
|
|
29
|
+
expectedHash: release.bundleHash,
|
|
30
|
+
isPatch: release.isPatch,
|
|
31
|
+
signature: release.signature || null
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Register a callback for download progress events.
|
|
37
|
+
* Returns an unsubscribe function.
|
|
38
|
+
*/
|
|
39
|
+
onProgress(callback) {
|
|
40
|
+
this.unsubscribeProgress = onDownloadProgress(callback);
|
|
41
|
+
return () => {
|
|
42
|
+
if (this.unsubscribeProgress) {
|
|
43
|
+
this.unsubscribeProgress();
|
|
44
|
+
this.unsubscribeProgress = null;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Cancel an in-progress download.
|
|
51
|
+
*/
|
|
52
|
+
async cancel() {
|
|
53
|
+
logger.info('Cancelling download');
|
|
54
|
+
await NativeSwiftPatch.cancelDownload();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=Downloader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NativeSwiftPatch","onDownloadProgress","logger","Downloader","unsubscribeProgress","download","options","info","isPatch","expectedHash","downloadUpdate","url","signature","downloadRelease","release","downloadUrl","bundleHash","onProgress","callback","cancel","cancelDownload"],"sourceRoot":"../../../src","sources":["core/Downloader.ts"],"mappings":";;AAAA,OAAOA,gBAAgB,IACrBC,kBAAkB,QACb,4BAA4B;AACnC,SAASC,MAAM,QAAQ,iBAAiB;AAUxC;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,UAAU,CAAC;EACdC,mBAAmB,GAAwB,IAAI;;EAEvD;AACF;AACA;EACE,MAAMC,QAAQA,CAACC,OAAwB,EAAiB;IACtDJ,MAAM,CAACK,IAAI,CACT,eAAeD,OAAO,CAACE,OAAO,GAAG,OAAO,GAAG,aAAa,KAAKF,OAAO,CAACG,YAAY,EACnF,CAAC;IAED,MAAMT,gBAAgB,CAACU,cAAc,CACnCJ,OAAO,CAACK,GAAG,EACXL,OAAO,CAACG,YAAY,EACpBH,OAAO,CAACE,OAAO,EACfF,OAAO,CAACM,SACV,CAAC;IAEDV,MAAM,CAACK,IAAI,CAAC,mBAAmB,CAAC;EAClC;;EAEA;AACF;AACA;EACE,MAAMM,eAAeA,CAACC,OAAoB,EAAiB;IACzD,MAAM,IAAI,CAACT,QAAQ,CAAC;MAClBM,GAAG,EAAEG,OAAO,CAACC,WAAW;MACxBN,YAAY,EAAEK,OAAO,CAACE,UAAU;MAChCR,OAAO,EAAEM,OAAO,CAACN,OAAO;MACxBI,SAAS,EAAEE,OAAO,CAACF,SAAS,IAAI;IAClC,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;EACEK,UAAUA,CAACC,QAA8C,EAAc;IACrE,IAAI,CAACd,mBAAmB,GAAGH,kBAAkB,CAACiB,QAAQ,CAAC;IACvD,OAAO,MAAM;MACX,IAAI,IAAI,CAACd,mBAAmB,EAAE;QAC5B,IAAI,CAACA,mBAAmB,CAAC,CAAC;QAC1B,IAAI,CAACA,mBAAmB,GAAG,IAAI;MACjC;IACF,CAAC;EACH;;EAEA;AACF;AACA;EACE,MAAMe,MAAMA,CAAA,EAAkB;IAC5BjB,MAAM,CAACK,IAAI,CAAC,qBAAqB,CAAC;IAClC,MAAMP,gBAAgB,CAACoB,cAAc,CAAC,CAAC;EACzC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import NativeSwiftPatch from '../native/NativeSwiftPatch';
|
|
4
|
+
import { logger } from '../utils/logger';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Core module responsible for installing verified bundles.
|
|
8
|
+
*
|
|
9
|
+
* Delegates to the native module for atomic file operations
|
|
10
|
+
* and pending install tracking.
|
|
11
|
+
*/
|
|
12
|
+
export class Installer {
|
|
13
|
+
/**
|
|
14
|
+
* Install a downloaded and verified bundle by its hash.
|
|
15
|
+
* The native module handles moving the file to the correct location
|
|
16
|
+
* and setting it as the pending bundle.
|
|
17
|
+
*/
|
|
18
|
+
async install(bundleHash) {
|
|
19
|
+
logger.info(`Installing bundle: ${bundleHash}`);
|
|
20
|
+
await NativeSwiftPatch.installUpdate(bundleHash);
|
|
21
|
+
logger.info('Bundle installed, restart required to activate');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Confirm the current installation as stable.
|
|
26
|
+
* Call this after the app has been running without crashes
|
|
27
|
+
* for the crash detection window period.
|
|
28
|
+
*/
|
|
29
|
+
async confirm() {
|
|
30
|
+
logger.info('Confirming installation as stable');
|
|
31
|
+
await NativeSwiftPatch.confirmInstall();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Check if there is a pending installation awaiting restart.
|
|
36
|
+
*/
|
|
37
|
+
async hasPending() {
|
|
38
|
+
return NativeSwiftPatch.hasPendingInstall();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=Installer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NativeSwiftPatch","logger","Installer","install","bundleHash","info","installUpdate","confirm","confirmInstall","hasPending","hasPendingInstall"],"sourceRoot":"../../../src","sources":["core/Installer.ts"],"mappings":";;AAAA,OAAOA,gBAAgB,MAAM,4BAA4B;AACzD,SAASC,MAAM,QAAQ,iBAAiB;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,SAAS,CAAC;EACrB;AACF;AACA;AACA;AACA;EACE,MAAMC,OAAOA,CAACC,UAAkB,EAAiB;IAC/CH,MAAM,CAACI,IAAI,CAAC,sBAAsBD,UAAU,EAAE,CAAC;IAC/C,MAAMJ,gBAAgB,CAACM,aAAa,CAACF,UAAU,CAAC;IAChDH,MAAM,CAACI,IAAI,CAAC,gDAAgD,CAAC;EAC/D;;EAEA;AACF;AACA;AACA;AACA;EACE,MAAME,OAAOA,CAAA,EAAkB;IAC7BN,MAAM,CAACI,IAAI,CAAC,mCAAmC,CAAC;IAChD,MAAML,gBAAgB,CAACQ,cAAc,CAAC,CAAC;EACzC;;EAEA;AACF;AACA;EACE,MAAMC,UAAUA,CAAA,EAAqB;IACnC,OAAOT,gBAAgB,CAACU,iBAAiB,CAAC,CAAC;EAC7C;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import NativeSwiftPatch from '../native/NativeSwiftPatch';
|
|
4
|
+
import { logger } from '../utils/logger';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Core module responsible for rollback operations.
|
|
8
|
+
*
|
|
9
|
+
* Delegates to the native module for reverting to the
|
|
10
|
+
* previous bundle version and clearing pending updates.
|
|
11
|
+
*/
|
|
12
|
+
export class Rollback {
|
|
13
|
+
/**
|
|
14
|
+
* Rollback to the previous bundle version.
|
|
15
|
+
* The native module restores the prior known-good bundle.
|
|
16
|
+
*/
|
|
17
|
+
async rollback() {
|
|
18
|
+
logger.info('Rolling back to previous bundle');
|
|
19
|
+
await NativeSwiftPatch.rollback();
|
|
20
|
+
logger.info('Rollback complete');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Clear any pending update that has not yet been activated.
|
|
25
|
+
*/
|
|
26
|
+
async clearPending() {
|
|
27
|
+
logger.info('Clearing pending update');
|
|
28
|
+
await NativeSwiftPatch.clearPendingUpdate();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=Rollback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NativeSwiftPatch","logger","Rollback","rollback","info","clearPending","clearPendingUpdate"],"sourceRoot":"../../../src","sources":["core/Rollback.ts"],"mappings":";;AAAA,OAAOA,gBAAgB,MAAM,4BAA4B;AACzD,SAASC,MAAM,QAAQ,iBAAiB;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,QAAQ,CAAC;EACpB;AACF;AACA;AACA;EACE,MAAMC,QAAQA,CAAA,EAAkB;IAC9BF,MAAM,CAACG,IAAI,CAAC,iCAAiC,CAAC;IAC9C,MAAMJ,gBAAgB,CAACG,QAAQ,CAAC,CAAC;IACjCF,MAAM,CAACG,IAAI,CAAC,mBAAmB,CAAC;EAClC;;EAEA;AACF;AACA;EACE,MAAMC,YAAYA,CAAA,EAAkB;IAClCJ,MAAM,CAACG,IAAI,CAAC,yBAAyB,CAAC;IACtC,MAAMJ,gBAAgB,CAACM,kBAAkB,CAAC,CAAC;EAC7C;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { Platform } from 'react-native';
|
|
4
|
+
import NativeSwiftPatch from '../native/NativeSwiftPatch';
|
|
5
|
+
import { checkForUpdateAPI } from '../utils/api';
|
|
6
|
+
import { logger } from '../utils/logger';
|
|
7
|
+
import { SDK_VERSION } from '../constants';
|
|
8
|
+
/**
|
|
9
|
+
* Core module responsible for checking for available OTA updates.
|
|
10
|
+
*
|
|
11
|
+
* Gathers device info from the native module and calls the
|
|
12
|
+
* server's check-update endpoint.
|
|
13
|
+
*/
|
|
14
|
+
export class UpdateChecker {
|
|
15
|
+
constructor(options) {
|
|
16
|
+
this.options = options;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Check the server for an available update.
|
|
21
|
+
* Gathers appVersion, currentBundleHash, deviceId from native module.
|
|
22
|
+
*/
|
|
23
|
+
async check() {
|
|
24
|
+
const appVersion = await NativeSwiftPatch.getAppVersion();
|
|
25
|
+
const currentBundle = await NativeSwiftPatch.getCurrentBundle();
|
|
26
|
+
const deviceId = await NativeSwiftPatch.getDeviceId();
|
|
27
|
+
logger.debug(`Checking for update: appVersion=${appVersion}, platform=${Platform.OS}, sdkVersion=${SDK_VERSION}`);
|
|
28
|
+
const result = await checkForUpdateAPI({
|
|
29
|
+
serverUrl: this.options.serverUrl,
|
|
30
|
+
deploymentKey: this.options.deploymentKey,
|
|
31
|
+
appVersion,
|
|
32
|
+
currentBundleHash: currentBundle?.hash || null,
|
|
33
|
+
platform: Platform.OS,
|
|
34
|
+
deviceId,
|
|
35
|
+
customHeaders: this.options.customHeaders
|
|
36
|
+
});
|
|
37
|
+
if (result.updateAvailable && result.release) {
|
|
38
|
+
logger.info(`Update available: ${result.release.version}`);
|
|
39
|
+
return {
|
|
40
|
+
updateAvailable: true,
|
|
41
|
+
release: result.release
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
logger.debug('No update available');
|
|
45
|
+
return {
|
|
46
|
+
updateAvailable: false,
|
|
47
|
+
reason: result.reason || 'NO_UPDATE'
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=UpdateChecker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Platform","NativeSwiftPatch","checkForUpdateAPI","logger","SDK_VERSION","UpdateChecker","constructor","options","check","appVersion","getAppVersion","currentBundle","getCurrentBundle","deviceId","getDeviceId","debug","OS","result","serverUrl","deploymentKey","currentBundleHash","hash","platform","customHeaders","updateAvailable","release","info","version","reason"],"sourceRoot":"../../../src","sources":["core/UpdateChecker.ts"],"mappings":";;AAAA,SAASA,QAAQ,QAAQ,cAAc;AACvC,OAAOC,gBAAgB,MAAM,4BAA4B;AACzD,SAASC,iBAAiB,QAAQ,cAAc;AAChD,SAASC,MAAM,QAAQ,iBAAiB;AACxC,SAASC,WAAW,QAAQ,cAAc;AAe1C;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,aAAa,CAAC;EAGzBC,WAAWA,CAACC,OAA2B,EAAE;IACvC,IAAI,CAACA,OAAO,GAAGA,OAAO;EACxB;;EAEA;AACF;AACA;AACA;EACE,MAAMC,KAAKA,CAAA,EAA+B;IACxC,MAAMC,UAAU,GAAG,MAAMR,gBAAgB,CAACS,aAAa,CAAC,CAAC;IACzD,MAAMC,aAAa,GAAG,MAAMV,gBAAgB,CAACW,gBAAgB,CAAC,CAAC;IAC/D,MAAMC,QAAQ,GAAG,MAAMZ,gBAAgB,CAACa,WAAW,CAAC,CAAC;IAErDX,MAAM,CAACY,KAAK,CACV,mCAAmCN,UAAU,cAAcT,QAAQ,CAACgB,EAAE,gBAAgBZ,WAAW,EACnG,CAAC;IAED,MAAMa,MAAM,GAAG,MAAMf,iBAAiB,CAAC;MACrCgB,SAAS,EAAE,IAAI,CAACX,OAAO,CAACW,SAAS;MACjCC,aAAa,EAAE,IAAI,CAACZ,OAAO,CAACY,aAAa;MACzCV,UAAU;MACVW,iBAAiB,EAAET,aAAa,EAAEU,IAAI,IAAI,IAAI;MAC9CC,QAAQ,EAAEtB,QAAQ,CAACgB,EAAuB;MAC1CH,QAAQ;MACRU,aAAa,EAAE,IAAI,CAAChB,OAAO,CAACgB;IAC9B,CAAC,CAAC;IAEF,IAAIN,MAAM,CAACO,eAAe,IAAIP,MAAM,CAACQ,OAAO,EAAE;MAC5CtB,MAAM,CAACuB,IAAI,CAAC,qBAAqBT,MAAM,CAACQ,OAAO,CAACE,OAAO,EAAE,CAAC;MAC1D,OAAO;QACLH,eAAe,EAAE,IAAI;QACrBC,OAAO,EAAER,MAAM,CAACQ;MAClB,CAAC;IACH;IAEAtB,MAAM,CAACY,KAAK,CAAC,qBAAqB,CAAC;IACnC,OAAO;MACLS,eAAe,EAAE,KAAK;MACtBI,MAAM,EAAGX,MAAM,CAASW,MAAM,IAAI;IACpC,CAAC;EACH;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import NativeSwiftPatch from '../native/NativeSwiftPatch';
|
|
4
|
+
import { logger } from '../utils/logger';
|
|
5
|
+
/**
|
|
6
|
+
* Core module responsible for verifying downloaded bundles.
|
|
7
|
+
*
|
|
8
|
+
* 4-step verification pipeline:
|
|
9
|
+
* 1. Apply patch if isPatch (via native bspatch)
|
|
10
|
+
* 2. Compute SHA-256 hash of the resulting bundle (via native)
|
|
11
|
+
* 3. Verify hash matches release.bundleHash
|
|
12
|
+
* 4. Verify RSA signature if provided (via native)
|
|
13
|
+
*/
|
|
14
|
+
export class Verifier {
|
|
15
|
+
publicKey = null;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Set the RSA public key for signature verification.
|
|
19
|
+
*/
|
|
20
|
+
setPublicKey(key) {
|
|
21
|
+
this.publicKey = key;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Run the full verification pipeline on a downloaded bundle/patch.
|
|
26
|
+
*
|
|
27
|
+
* @param downloadedPath Path to the downloaded file on disk
|
|
28
|
+
* @param release Release metadata from the server
|
|
29
|
+
* @param currentBundlePath Path to the current bundle (needed if isPatch)
|
|
30
|
+
* @returns The path to the final verified bundle
|
|
31
|
+
*/
|
|
32
|
+
async verify(downloadedPath, release, currentBundlePath) {
|
|
33
|
+
let bundlePath = downloadedPath;
|
|
34
|
+
|
|
35
|
+
// Step 1: Apply patch if this is a diff patch
|
|
36
|
+
if (release.isPatch) {
|
|
37
|
+
if (!currentBundlePath) {
|
|
38
|
+
throw new Error('Current bundle path required to apply patch');
|
|
39
|
+
}
|
|
40
|
+
logger.info('Applying binary patch...');
|
|
41
|
+
const outputPath = `${downloadedPath}.patched`;
|
|
42
|
+
bundlePath = await NativeSwiftPatch.applyPatch(currentBundlePath, downloadedPath, outputPath);
|
|
43
|
+
logger.info('Patch applied successfully');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Step 2: Compute SHA-256 hash
|
|
47
|
+
logger.debug('Computing bundle hash...');
|
|
48
|
+
const computedHash = await NativeSwiftPatch.computeHash(bundlePath);
|
|
49
|
+
|
|
50
|
+
// Step 3: Verify hash matches expected
|
|
51
|
+
if (computedHash !== release.bundleHash) {
|
|
52
|
+
throw new Error(`Hash mismatch: expected ${release.bundleHash}, got ${computedHash}`);
|
|
53
|
+
}
|
|
54
|
+
logger.info('Hash verified successfully');
|
|
55
|
+
|
|
56
|
+
// Step 4: Verify RSA signature if provided
|
|
57
|
+
if (release.signature && this.publicKey) {
|
|
58
|
+
logger.debug('Verifying RSA signature...');
|
|
59
|
+
const isValid = await NativeSwiftPatch.verifySignature(computedHash, release.signature, this.publicKey);
|
|
60
|
+
if (!isValid) {
|
|
61
|
+
throw new Error('RSA signature verification failed');
|
|
62
|
+
}
|
|
63
|
+
logger.info('Signature verified successfully');
|
|
64
|
+
}
|
|
65
|
+
return bundlePath;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Quick hash-only verification.
|
|
70
|
+
*/
|
|
71
|
+
async verifyHash(bundlePath, expectedHash) {
|
|
72
|
+
const hash = await NativeSwiftPatch.computeHash(bundlePath);
|
|
73
|
+
return hash === expectedHash;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=Verifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NativeSwiftPatch","logger","Verifier","publicKey","setPublicKey","key","verify","downloadedPath","release","currentBundlePath","bundlePath","isPatch","Error","info","outputPath","applyPatch","debug","computedHash","computeHash","bundleHash","signature","isValid","verifySignature","verifyHash","expectedHash","hash"],"sourceRoot":"../../../src","sources":["core/Verifier.ts"],"mappings":";;AAAA,OAAOA,gBAAgB,MAAM,4BAA4B;AACzD,SAASC,MAAM,QAAQ,iBAAiB;AAGxC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,QAAQ,CAAC;EACZC,SAAS,GAAkB,IAAI;;EAEvC;AACF;AACA;EACEC,YAAYA,CAACC,GAAkB,EAAQ;IACrC,IAAI,CAACF,SAAS,GAAGE,GAAG;EACtB;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE,MAAMC,MAAMA,CACVC,cAAsB,EACtBC,OAAoB,EACpBC,iBAA0B,EACT;IACjB,IAAIC,UAAU,GAAGH,cAAc;;IAE/B;IACA,IAAIC,OAAO,CAACG,OAAO,EAAE;MACnB,IAAI,CAACF,iBAAiB,EAAE;QACtB,MAAM,IAAIG,KAAK,CAAC,6CAA6C,CAAC;MAChE;MAEAX,MAAM,CAACY,IAAI,CAAC,0BAA0B,CAAC;MACvC,MAAMC,UAAU,GAAG,GAAGP,cAAc,UAAU;MAC9CG,UAAU,GAAG,MAAMV,gBAAgB,CAACe,UAAU,CAC5CN,iBAAiB,EACjBF,cAAc,EACdO,UACF,CAAC;MACDb,MAAM,CAACY,IAAI,CAAC,4BAA4B,CAAC;IAC3C;;IAEA;IACAZ,MAAM,CAACe,KAAK,CAAC,0BAA0B,CAAC;IACxC,MAAMC,YAAY,GAAG,MAAMjB,gBAAgB,CAACkB,WAAW,CAACR,UAAU,CAAC;;IAEnE;IACA,IAAIO,YAAY,KAAKT,OAAO,CAACW,UAAU,EAAE;MACvC,MAAM,IAAIP,KAAK,CACb,2BAA2BJ,OAAO,CAACW,UAAU,SAASF,YAAY,EACpE,CAAC;IACH;IACAhB,MAAM,CAACY,IAAI,CAAC,4BAA4B,CAAC;;IAEzC;IACA,IAAIL,OAAO,CAACY,SAAS,IAAI,IAAI,CAACjB,SAAS,EAAE;MACvCF,MAAM,CAACe,KAAK,CAAC,4BAA4B,CAAC;MAC1C,MAAMK,OAAO,GAAG,MAAMrB,gBAAgB,CAACsB,eAAe,CACpDL,YAAY,EACZT,OAAO,CAACY,SAAS,EACjB,IAAI,CAACjB,SACP,CAAC;MAED,IAAI,CAACkB,OAAO,EAAE;QACZ,MAAM,IAAIT,KAAK,CAAC,mCAAmC,CAAC;MACtD;MACAX,MAAM,CAACY,IAAI,CAAC,iCAAiC,CAAC;IAChD;IAEA,OAAOH,UAAU;EACnB;;EAEA;AACF;AACA;EACE,MAAMa,UAAUA,CAACb,UAAkB,EAAEc,YAAoB,EAAoB;IAC3E,MAAMC,IAAI,GAAG,MAAMzB,gBAAgB,CAACkB,WAAW,CAACR,UAAU,CAAC;IAC3D,OAAOe,IAAI,KAAKD,YAAY;EAC9B;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
export { UpdateChecker } from './UpdateChecker';
|
|
4
|
+
export { Downloader } from './Downloader';
|
|
5
|
+
export { Verifier } from './Verifier';
|
|
6
|
+
export { Installer } from './Installer';
|
|
7
|
+
export { Rollback } from './Rollback';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["UpdateChecker","Downloader","Verifier","Installer","Rollback"],"sourceRoot":"../../../src","sources":["core/index.ts"],"mappings":";;AAAA,SAASA,aAAa,QAAQ,iBAAiB;AAG/C,SAASC,UAAU,QAAQ,cAAc;AAGzC,SAASC,QAAQ,QAAQ,YAAY;AAErC,SAASC,SAAS,QAAQ,aAAa;AAEvC,SAASC,QAAQ,QAAQ,YAAY","ignoreList":[]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Provider
|
|
4
|
+
export { SwiftPatchProvider } from './SwiftPatchProvider';
|
|
5
|
+
|
|
6
|
+
// Hooks
|
|
7
|
+
export { useSwiftPatch, useSwiftPatchUpdate } from './useSwiftPatch';
|
|
8
|
+
export { useSwiftPatchModal } from './modal/useSwiftPatchModal';
|
|
9
|
+
|
|
10
|
+
// HOC
|
|
11
|
+
export { withSwiftPatch } from './withSwiftPatch';
|
|
12
|
+
|
|
13
|
+
// Imperative API (for non-React usage)
|
|
14
|
+
export { SwiftPatch } from './SwiftPatchCore';
|
|
15
|
+
|
|
16
|
+
// Modal component
|
|
17
|
+
export { SwiftPatchModal } from './modal/SwiftPatchModal';
|
|
18
|
+
|
|
19
|
+
// Types
|
|
20
|
+
|
|
21
|
+
// Enums
|
|
22
|
+
export { UpdateStatus, InstallMode, SwiftPatchErrorCode, SlotState, EnvironmentMode, SwiftPatchEventType } from './types';
|
|
23
|
+
|
|
24
|
+
// Native module (for advanced usage)
|
|
25
|
+
export { default as NativeSwiftPatch } from './native/NativeSwiftPatch';
|
|
26
|
+
|
|
27
|
+
// Core modules (for advanced/custom usage)
|
|
28
|
+
export { UpdateChecker, Downloader, Verifier, Installer, Rollback } from './core';
|
|
29
|
+
// Utility: restart the app
|
|
30
|
+
export function restart() {
|
|
31
|
+
const NativeModule = require('./native/NativeSwiftPatch').default;
|
|
32
|
+
NativeModule.restart();
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["SwiftPatchProvider","useSwiftPatch","useSwiftPatchUpdate","useSwiftPatchModal","withSwiftPatch","SwiftPatch","SwiftPatchModal","UpdateStatus","InstallMode","SwiftPatchErrorCode","SlotState","EnvironmentMode","SwiftPatchEventType","default","NativeSwiftPatch","UpdateChecker","Downloader","Verifier","Installer","Rollback","restart","NativeModule","require"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA;AACA,SAASA,kBAAkB,QAAQ,sBAAsB;;AAEzD;AACA,SAASC,aAAa,EAAEC,mBAAmB,QAAQ,iBAAiB;AACpE,SAASC,kBAAkB,QAAQ,4BAA4B;;AAE/D;AACA,SAASC,cAAc,QAAQ,kBAAkB;;AAEjD;AACA,SAASC,UAAU,QAAQ,kBAAkB;;AAE7C;AACA,SAASC,eAAe,QAAQ,yBAAyB;;AAEzD;;AAgBA;AACA,SACEC,YAAY,EACZC,WAAW,EACXC,mBAAmB,EACnBC,SAAS,EACTC,eAAe,EACfC,mBAAmB,QACd,SAAS;;AAEhB;AACA,SAASC,OAAO,IAAIC,gBAAgB,QAAQ,2BAA2B;;AAEvE;AACA,SACEC,aAAa,EACbC,UAAU,EACVC,QAAQ,EACRC,SAAS,EACTC,QAAQ,QACH,QAAQ;AAOf;AACA,OAAO,SAASC,OAAOA,CAAA,EAAS;EAC9B,MAAMC,YAAY,GAAGC,OAAO,CAAC,2BAA2B,CAAC,CAACT,OAAO;EACjEQ,YAAY,CAACD,OAAO,CAAC,CAAC;AACxB","ignoreList":[]}
|