@vanikya/ota-react-native 0.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.
- package/README.md +223 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/otaupdate/OTAUpdateModule.kt +185 -0
- package/android/src/main/java/com/otaupdate/OTAUpdatePackage.kt +16 -0
- package/ios/OTAUpdate.m +61 -0
- package/ios/OTAUpdate.swift +194 -0
- package/lib/commonjs/OTAProvider.js +113 -0
- package/lib/commonjs/OTAProvider.js.map +1 -0
- package/lib/commonjs/hooks/useOTAUpdate.js +272 -0
- package/lib/commonjs/hooks/useOTAUpdate.js.map +1 -0
- package/lib/commonjs/index.js +98 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/utils/api.js +60 -0
- package/lib/commonjs/utils/api.js.map +1 -0
- package/lib/commonjs/utils/storage.js +209 -0
- package/lib/commonjs/utils/storage.js.map +1 -0
- package/lib/commonjs/utils/verification.js +145 -0
- package/lib/commonjs/utils/verification.js.map +1 -0
- package/lib/module/OTAProvider.js +104 -0
- package/lib/module/OTAProvider.js.map +1 -0
- package/lib/module/hooks/useOTAUpdate.js +266 -0
- package/lib/module/hooks/useOTAUpdate.js.map +1 -0
- package/lib/module/index.js +11 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/utils/api.js +52 -0
- package/lib/module/utils/api.js.map +1 -0
- package/lib/module/utils/storage.js +202 -0
- package/lib/module/utils/storage.js.map +1 -0
- package/lib/module/utils/verification.js +137 -0
- package/lib/module/utils/verification.js.map +1 -0
- package/lib/typescript/OTAProvider.d.ts +28 -0
- package/lib/typescript/OTAProvider.d.ts.map +1 -0
- package/lib/typescript/hooks/useOTAUpdate.d.ts +35 -0
- package/lib/typescript/hooks/useOTAUpdate.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +12 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/utils/api.d.ts +47 -0
- package/lib/typescript/utils/api.d.ts.map +1 -0
- package/lib/typescript/utils/storage.d.ts +32 -0
- package/lib/typescript/utils/storage.d.ts.map +1 -0
- package/lib/typescript/utils/verification.d.ts +11 -0
- package/lib/typescript/utils/verification.d.ts.map +1 -0
- package/ota-update.podspec +21 -0
- package/package.json +83 -0
- package/src/OTAProvider.tsx +160 -0
- package/src/hooks/useOTAUpdate.ts +344 -0
- package/src/index.ts +36 -0
- package/src/utils/api.ts +99 -0
- package/src/utils/storage.ts +249 -0
- package/src/utils/verification.ts +167 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "OTAApiClient", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _api.OTAApiClient;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "OTAProvider", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _OTAProvider.OTAProvider;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "UpdateBanner", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _OTAProvider.UpdateBanner;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "UpdateStorage", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _storage.UpdateStorage;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
exports.VERSION = void 0;
|
|
31
|
+
Object.defineProperty(exports, "calculateHash", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () {
|
|
34
|
+
return _verification.calculateHash;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(exports, "getDeviceInfo", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () {
|
|
40
|
+
return _api.getDeviceInfo;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(exports, "getStorageAdapter", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _storage.getStorageAdapter;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(exports, "useOTA", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
get: function () {
|
|
52
|
+
return _OTAProvider.useOTA;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(exports, "useOTAUpdate", {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
get: function () {
|
|
58
|
+
return _useOTAUpdate.useOTAUpdate;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
Object.defineProperty(exports, "verifyBundle", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
get: function () {
|
|
64
|
+
return _verification.verifyBundle;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
Object.defineProperty(exports, "verifyBundleHash", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
get: function () {
|
|
70
|
+
return _verification.verifyBundleHash;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
Object.defineProperty(exports, "verifySignature", {
|
|
74
|
+
enumerable: true,
|
|
75
|
+
get: function () {
|
|
76
|
+
return _verification.verifySignature;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
Object.defineProperty(exports, "withOTA", {
|
|
80
|
+
enumerable: true,
|
|
81
|
+
get: function () {
|
|
82
|
+
return _OTAProvider.withOTA;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
var _OTAProvider = require("./OTAProvider");
|
|
86
|
+
var _useOTAUpdate = require("./hooks/useOTAUpdate");
|
|
87
|
+
var _api = require("./utils/api");
|
|
88
|
+
var _storage = require("./utils/storage");
|
|
89
|
+
var _verification = require("./utils/verification");
|
|
90
|
+
// Main exports
|
|
91
|
+
|
|
92
|
+
// Hook export
|
|
93
|
+
|
|
94
|
+
// Utilities
|
|
95
|
+
|
|
96
|
+
// Version info
|
|
97
|
+
const VERSION = exports.VERSION = '0.1.0';
|
|
98
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_OTAProvider","require","_useOTAUpdate","_api","_storage","_verification","VERSION","exports"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAIA,IAAAC,aAAA,GAAAD,OAAA;AAUA,IAAAE,IAAA,GAAAF,OAAA;AAQA,IAAAG,QAAA,GAAAH,OAAA;AAGA,IAAAI,aAAA,GAAAJ,OAAA;AA1BA;;AAIA;;AAUA;;AAoBA;AACO,MAAMK,OAAO,GAAAC,OAAA,CAAAD,OAAA,GAAG,OAAO","ignoreList":[]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.OTAApiClient = void 0;
|
|
7
|
+
exports.getDeviceInfo = getDeviceInfo;
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
class OTAApiClient {
|
|
10
|
+
constructor(serverUrl) {
|
|
11
|
+
this.serverUrl = serverUrl.replace(/\/$/, ''); // Remove trailing slash
|
|
12
|
+
}
|
|
13
|
+
async checkUpdate(request) {
|
|
14
|
+
const response = await fetch(`${this.serverUrl}/api/v1/check-update`, {
|
|
15
|
+
method: 'POST',
|
|
16
|
+
headers: {
|
|
17
|
+
'Content-Type': 'application/json'
|
|
18
|
+
},
|
|
19
|
+
body: JSON.stringify(request)
|
|
20
|
+
});
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
const error = await response.json().catch(() => ({
|
|
23
|
+
error: 'Unknown error'
|
|
24
|
+
}));
|
|
25
|
+
throw new Error(error.error || `HTTP ${response.status}`);
|
|
26
|
+
}
|
|
27
|
+
return response.json();
|
|
28
|
+
}
|
|
29
|
+
async reportEvent(request) {
|
|
30
|
+
try {
|
|
31
|
+
await fetch(`${this.serverUrl}/api/v1/report-event`, {
|
|
32
|
+
method: 'POST',
|
|
33
|
+
headers: {
|
|
34
|
+
'Content-Type': 'application/json'
|
|
35
|
+
},
|
|
36
|
+
body: JSON.stringify(request)
|
|
37
|
+
});
|
|
38
|
+
} catch (error) {
|
|
39
|
+
// Silently fail analytics - don't block the app
|
|
40
|
+
if (__DEV__) {
|
|
41
|
+
console.warn('[OTAUpdate] Failed to report event:', error);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async downloadBundle(bundleUrl) {
|
|
46
|
+
const response = await fetch(bundleUrl);
|
|
47
|
+
if (!response.ok) {
|
|
48
|
+
throw new Error(`Failed to download bundle: HTTP ${response.status}`);
|
|
49
|
+
}
|
|
50
|
+
return response.arrayBuffer();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.OTAApiClient = OTAApiClient;
|
|
54
|
+
function getDeviceInfo() {
|
|
55
|
+
return {
|
|
56
|
+
os: _reactNative.Platform.OS,
|
|
57
|
+
osVersion: _reactNative.Platform.Version.toString()
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","OTAApiClient","constructor","serverUrl","replace","checkUpdate","request","response","fetch","method","headers","body","JSON","stringify","ok","error","json","catch","Error","status","reportEvent","__DEV__","console","warn","downloadBundle","bundleUrl","arrayBuffer","exports","getDeviceInfo","os","Platform","OS","osVersion","Version","toString"],"sourceRoot":"../../../src","sources":["utils/api.ts"],"mappings":";;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B;IAC5D,MAAMlB,QAAQ,GAAG,MAAMC,KAAK,CAACiB,SAAS,CAAC;IAEvC,IAAI,CAAClB,QAAQ,CAACO,EAAE,EAAE;MAChB,MAAM,IAAII,KAAK,CAAC,mCAAmCX,QAAQ,CAACY,MAAM,EAAE,CAAC;IACvE;IAEA,OAAOZ,QAAQ,CAACmB,WAAW,CAAC,CAAC;EAC/B;AACF;AAACC,OAAA,CAAA1B,YAAA,GAAAA,YAAA;AAEM,SAAS2B,aAAaA,CAAA,EAAsC;EACjE,OAAO;IACLC,EAAE,EAAEC,qBAAQ,CAACC,EAAE;IACfC,SAAS,EAAEF,qBAAQ,CAACG,OAAO,CAACC,QAAQ,CAAC;EACvC,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UpdateStorage = void 0;
|
|
7
|
+
exports.getStorageAdapter = getStorageAdapter;
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
// Types
|
|
10
|
+
|
|
11
|
+
// Try to use Expo FileSystem if available
|
|
12
|
+
let ExpoFileSystem = null;
|
|
13
|
+
try {
|
|
14
|
+
ExpoFileSystem = require('expo-file-system');
|
|
15
|
+
} catch {
|
|
16
|
+
// Expo not available, will use native module
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Native module for bare React Native
|
|
20
|
+
const OTAUpdateNative = _reactNative.NativeModules.OTAUpdate;
|
|
21
|
+
|
|
22
|
+
// Expo implementation
|
|
23
|
+
class ExpoStorageAdapter {
|
|
24
|
+
getDocumentDirectory() {
|
|
25
|
+
return ExpoFileSystem.documentDirectory || '';
|
|
26
|
+
}
|
|
27
|
+
async writeFile(path, data) {
|
|
28
|
+
if (data instanceof ArrayBuffer) {
|
|
29
|
+
// Convert ArrayBuffer to base64
|
|
30
|
+
const bytes = new Uint8Array(data);
|
|
31
|
+
let binary = '';
|
|
32
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
33
|
+
binary += String.fromCharCode(bytes[i]);
|
|
34
|
+
}
|
|
35
|
+
const base64 = btoa(binary);
|
|
36
|
+
await ExpoFileSystem.writeAsStringAsync(path, base64, {
|
|
37
|
+
encoding: ExpoFileSystem.EncodingType.Base64
|
|
38
|
+
});
|
|
39
|
+
} else {
|
|
40
|
+
await ExpoFileSystem.writeAsStringAsync(path, data);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async readFile(path) {
|
|
44
|
+
return ExpoFileSystem.readAsStringAsync(path);
|
|
45
|
+
}
|
|
46
|
+
async readFileAsBuffer(path) {
|
|
47
|
+
const base64 = await ExpoFileSystem.readAsStringAsync(path, {
|
|
48
|
+
encoding: ExpoFileSystem.EncodingType.Base64
|
|
49
|
+
});
|
|
50
|
+
const binary = atob(base64);
|
|
51
|
+
const bytes = new Uint8Array(binary.length);
|
|
52
|
+
for (let i = 0; i < binary.length; i++) {
|
|
53
|
+
bytes[i] = binary.charCodeAt(i);
|
|
54
|
+
}
|
|
55
|
+
return bytes.buffer;
|
|
56
|
+
}
|
|
57
|
+
async deleteFile(path) {
|
|
58
|
+
await ExpoFileSystem.deleteAsync(path, {
|
|
59
|
+
idempotent: true
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async exists(path) {
|
|
63
|
+
const info = await ExpoFileSystem.getInfoAsync(path);
|
|
64
|
+
return info.exists;
|
|
65
|
+
}
|
|
66
|
+
async makeDirectory(path) {
|
|
67
|
+
await ExpoFileSystem.makeDirectoryAsync(path, {
|
|
68
|
+
intermediates: true
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Native implementation for bare React Native
|
|
74
|
+
class NativeStorageAdapter {
|
|
75
|
+
getDocumentDirectory() {
|
|
76
|
+
if (!OTAUpdateNative) {
|
|
77
|
+
throw new Error('OTAUpdate native module not found. Did you link the library?');
|
|
78
|
+
}
|
|
79
|
+
return OTAUpdateNative.getDocumentDirectory();
|
|
80
|
+
}
|
|
81
|
+
async writeFile(path, data) {
|
|
82
|
+
if (!OTAUpdateNative) {
|
|
83
|
+
throw new Error('OTAUpdate native module not found');
|
|
84
|
+
}
|
|
85
|
+
if (data instanceof ArrayBuffer) {
|
|
86
|
+
const bytes = new Uint8Array(data);
|
|
87
|
+
let binary = '';
|
|
88
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
89
|
+
binary += String.fromCharCode(bytes[i]);
|
|
90
|
+
}
|
|
91
|
+
const base64 = btoa(binary);
|
|
92
|
+
await OTAUpdateNative.writeFileBase64(path, base64);
|
|
93
|
+
} else {
|
|
94
|
+
await OTAUpdateNative.writeFile(path, data);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async readFile(path) {
|
|
98
|
+
if (!OTAUpdateNative) {
|
|
99
|
+
throw new Error('OTAUpdate native module not found');
|
|
100
|
+
}
|
|
101
|
+
return OTAUpdateNative.readFile(path);
|
|
102
|
+
}
|
|
103
|
+
async readFileAsBuffer(path) {
|
|
104
|
+
if (!OTAUpdateNative) {
|
|
105
|
+
throw new Error('OTAUpdate native module not found');
|
|
106
|
+
}
|
|
107
|
+
const base64 = await OTAUpdateNative.readFileBase64(path);
|
|
108
|
+
const binary = atob(base64);
|
|
109
|
+
const bytes = new Uint8Array(binary.length);
|
|
110
|
+
for (let i = 0; i < binary.length; i++) {
|
|
111
|
+
bytes[i] = binary.charCodeAt(i);
|
|
112
|
+
}
|
|
113
|
+
return bytes.buffer;
|
|
114
|
+
}
|
|
115
|
+
async deleteFile(path) {
|
|
116
|
+
if (!OTAUpdateNative) {
|
|
117
|
+
throw new Error('OTAUpdate native module not found');
|
|
118
|
+
}
|
|
119
|
+
await OTAUpdateNative.deleteFile(path);
|
|
120
|
+
}
|
|
121
|
+
async exists(path) {
|
|
122
|
+
if (!OTAUpdateNative) {
|
|
123
|
+
throw new Error('OTAUpdate native module not found');
|
|
124
|
+
}
|
|
125
|
+
return OTAUpdateNative.exists(path);
|
|
126
|
+
}
|
|
127
|
+
async makeDirectory(path) {
|
|
128
|
+
if (!OTAUpdateNative) {
|
|
129
|
+
throw new Error('OTAUpdate native module not found');
|
|
130
|
+
}
|
|
131
|
+
await OTAUpdateNative.makeDirectory(path);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Factory function to get the appropriate storage adapter
|
|
136
|
+
function getStorageAdapter() {
|
|
137
|
+
if (ExpoFileSystem) {
|
|
138
|
+
return new ExpoStorageAdapter();
|
|
139
|
+
}
|
|
140
|
+
if (OTAUpdateNative) {
|
|
141
|
+
return new NativeStorageAdapter();
|
|
142
|
+
}
|
|
143
|
+
throw new Error('No storage adapter available. Install expo-file-system or link the OTAUpdate native module.');
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Update storage manager
|
|
147
|
+
class UpdateStorage {
|
|
148
|
+
constructor() {
|
|
149
|
+
this.storage = getStorageAdapter();
|
|
150
|
+
this.baseDir = `${this.storage.getDocumentDirectory()}ota-update/`;
|
|
151
|
+
}
|
|
152
|
+
async ensureDirectory() {
|
|
153
|
+
const exists = await this.storage.exists(this.baseDir);
|
|
154
|
+
if (!exists) {
|
|
155
|
+
await this.storage.makeDirectory(this.baseDir);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
async saveBundle(releaseId, data) {
|
|
159
|
+
await this.ensureDirectory();
|
|
160
|
+
const bundlePath = `${this.baseDir}${releaseId}.bundle`;
|
|
161
|
+
await this.storage.writeFile(bundlePath, data);
|
|
162
|
+
return bundlePath;
|
|
163
|
+
}
|
|
164
|
+
async getBundlePath(releaseId) {
|
|
165
|
+
const bundlePath = `${this.baseDir}${releaseId}.bundle`;
|
|
166
|
+
const exists = await this.storage.exists(bundlePath);
|
|
167
|
+
return exists ? bundlePath : null;
|
|
168
|
+
}
|
|
169
|
+
async readBundle(releaseId) {
|
|
170
|
+
const bundlePath = await this.getBundlePath(releaseId);
|
|
171
|
+
if (!bundlePath) return null;
|
|
172
|
+
return this.storage.readFileAsBuffer(bundlePath);
|
|
173
|
+
}
|
|
174
|
+
async deleteBundle(releaseId) {
|
|
175
|
+
const bundlePath = `${this.baseDir}${releaseId}.bundle`;
|
|
176
|
+
if (await this.storage.exists(bundlePath)) {
|
|
177
|
+
await this.storage.deleteFile(bundlePath);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async saveMetadata(update) {
|
|
181
|
+
await this.ensureDirectory();
|
|
182
|
+
const metadataPath = `${this.baseDir}current.json`;
|
|
183
|
+
await this.storage.writeFile(metadataPath, JSON.stringify(update));
|
|
184
|
+
}
|
|
185
|
+
async getMetadata() {
|
|
186
|
+
const metadataPath = `${this.baseDir}current.json`;
|
|
187
|
+
try {
|
|
188
|
+
if (await this.storage.exists(metadataPath)) {
|
|
189
|
+
const content = await this.storage.readFile(metadataPath);
|
|
190
|
+
return JSON.parse(content);
|
|
191
|
+
}
|
|
192
|
+
} catch {
|
|
193
|
+
// Corrupted metadata, return null
|
|
194
|
+
}
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
async clearMetadata() {
|
|
198
|
+
const metadataPath = `${this.baseDir}current.json`;
|
|
199
|
+
if (await this.storage.exists(metadataPath)) {
|
|
200
|
+
await this.storage.deleteFile(metadataPath);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
async cleanOldBundles(keepReleaseId) {
|
|
204
|
+
// For now, we just keep one bundle at a time
|
|
205
|
+
// In a more advanced implementation, we might keep a few for rollback
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
exports.UpdateStorage = UpdateStorage;
|
|
209
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","ExpoFileSystem","OTAUpdateNative","NativeModules","OTAUpdate","ExpoStorageAdapter","getDocumentDirectory","documentDirectory","writeFile","path","data","ArrayBuffer","bytes","Uint8Array","binary","i","length","String","fromCharCode","base64","btoa","writeAsStringAsync","encoding","EncodingType","Base64","readFile","readAsStringAsync","readFileAsBuffer","atob","charCodeAt","buffer","deleteFile","deleteAsync","idempotent","exists","info","getInfoAsync","makeDirectory","makeDirectoryAsync","intermediates","NativeStorageAdapter","Error","writeFileBase64","readFileBase64","getStorageAdapter","UpdateStorage","constructor","storage","baseDir","ensureDirectory","saveBundle","releaseId","bundlePath","getBundlePath","readBundle","deleteBundle","saveMetadata","update","metadataPath","JSON","stringify","getMetadata","content","parse","clearMetadata","cleanOldBundles","keepReleaseId","exports"],"sourceRoot":"../../../src","sources":["utils/storage.ts"],"mappings":";;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA;;AAmBA;AACA,IAAIC,cAAmB,GAAG,IAAI;AAC9B,IAAI;EACFA,cAAc,GAAGD,OAAO,CAAC,kBAAkB,CAAC;AAC9C,CAAC,CAAC,MAAM;EACN;AAAA;;AAGF;AACA,MAAME,eAAe,GAAGC,0BAAa,CAACC,SAAS;;AAE/C;AACA,MAAMC,kBAAkB,CAA2B;EACjDC,oBAAoBA,CAAA,EAAW;IAC7B,OAAOL,cAAc,CAACM,iBAAiB,IAAI,EAAE;EAC/C;EAEA,MAAMC,SAASA,CAACC,IAAY,EAAEC,IAA0B,EAAiB;IACvE,IAAIA,IAAI,YAAYC,WAAW,EAAE;MAC/B;MACA,MAAMC,KAAK,GAAG,IAAIC,UAAU,CAACH,IAAI,CAAC;MAClC,IAAII,MAAM,GAAG,EAAE;MACf,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,KAAK,CAACI,MAAM,EAAED,CAAC,EAAE,EAAE;QACrCD,MAAM,IAAIG,MAAM,CAACC,YAAY,CAACN,KAAK,CAACG,CAAC,CAAC,CAAC;MACzC;MACA,MAAMI,MAAM,GAAGC,IAAI,CAACN,MAAM,CAAC;MAC3B,MAAMb,cAAc,CAACoB,kBAAkB,CAACZ,IAAI,EAAE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
|
+
});
|
|
6
|
+
exports.calculateHash = calculateHash;
|
|
7
|
+
exports.verifyBundle = verifyBundle;
|
|
8
|
+
exports.verifyBundleHash = verifyBundleHash;
|
|
9
|
+
exports.verifySignature = verifySignature;
|
|
10
|
+
var _reactNative = require("react-native");
|
|
11
|
+
// Try to use Expo Crypto if available
|
|
12
|
+
let ExpoCrypto = null;
|
|
13
|
+
try {
|
|
14
|
+
ExpoCrypto = require('expo-crypto');
|
|
15
|
+
} catch {
|
|
16
|
+
// Expo not available
|
|
17
|
+
}
|
|
18
|
+
const OTAUpdateNative = _reactNative.NativeModules.OTAUpdate;
|
|
19
|
+
|
|
20
|
+
// Convert ArrayBuffer to hex string
|
|
21
|
+
function bufferToHex(buffer) {
|
|
22
|
+
const bytes = new Uint8Array(buffer);
|
|
23
|
+
return Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Convert hex string to Uint8Array
|
|
27
|
+
function hexToBytes(hex) {
|
|
28
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
29
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
30
|
+
bytes[i / 2] = parseInt(hex.substr(i, 2), 16);
|
|
31
|
+
}
|
|
32
|
+
return bytes;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Calculate SHA-256 hash of data
|
|
36
|
+
async function calculateHash(data) {
|
|
37
|
+
if (ExpoCrypto) {
|
|
38
|
+
// Use Expo Crypto
|
|
39
|
+
const hash = await ExpoCrypto.digestStringAsync(ExpoCrypto.CryptoDigestAlgorithm.SHA256, bufferToHex(data), {
|
|
40
|
+
encoding: ExpoCrypto.CryptoEncoding.HEX
|
|
41
|
+
});
|
|
42
|
+
return 'sha256:' + hash;
|
|
43
|
+
}
|
|
44
|
+
if (OTAUpdateNative?.calculateSHA256) {
|
|
45
|
+
// Use native module
|
|
46
|
+
const bytes = new Uint8Array(data);
|
|
47
|
+
let binary = '';
|
|
48
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
49
|
+
binary += String.fromCharCode(bytes[i]);
|
|
50
|
+
}
|
|
51
|
+
const base64 = btoa(binary);
|
|
52
|
+
const hash = await OTAUpdateNative.calculateSHA256(base64);
|
|
53
|
+
return 'sha256:' + hash;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Fallback: Use SubtleCrypto (not available in all RN environments)
|
|
57
|
+
if (typeof crypto !== 'undefined' && crypto.subtle) {
|
|
58
|
+
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
|
|
59
|
+
return 'sha256:' + bufferToHex(hashBuffer);
|
|
60
|
+
}
|
|
61
|
+
throw new Error('No crypto implementation available');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Verify bundle hash
|
|
65
|
+
async function verifyBundleHash(data, expectedHash) {
|
|
66
|
+
const actualHash = await calculateHash(data);
|
|
67
|
+
return actualHash === expectedHash;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Verify Ed25519 signature
|
|
71
|
+
async function verifySignature(data, signatureHex, publicKeyHex) {
|
|
72
|
+
// Ed25519 verification is complex in JS
|
|
73
|
+
// We rely on native modules or skip if not available
|
|
74
|
+
|
|
75
|
+
if (OTAUpdateNative?.verifySignature) {
|
|
76
|
+
const bytes = new Uint8Array(data);
|
|
77
|
+
let binary = '';
|
|
78
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
79
|
+
binary += String.fromCharCode(bytes[i]);
|
|
80
|
+
}
|
|
81
|
+
const base64 = btoa(binary);
|
|
82
|
+
return OTAUpdateNative.verifySignature(base64, signatureHex, publicKeyHex);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// If no native module, we can't verify signature
|
|
86
|
+
// In production, you might want to require this
|
|
87
|
+
if (__DEV__) {
|
|
88
|
+
console.warn('[OTAUpdate] Signature verification skipped: native module not available');
|
|
89
|
+
}
|
|
90
|
+
return true; // Skip verification if not available
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Full bundle verification
|
|
94
|
+
|
|
95
|
+
async function verifyBundle(data, expectedHash, signature, publicKey) {
|
|
96
|
+
// Verify hash
|
|
97
|
+
let hashValid = false;
|
|
98
|
+
try {
|
|
99
|
+
hashValid = await verifyBundleHash(data, expectedHash);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
return {
|
|
102
|
+
valid: false,
|
|
103
|
+
hashValid: false,
|
|
104
|
+
signatureValid: false,
|
|
105
|
+
error: `Hash verification failed: ${error}`
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
if (!hashValid) {
|
|
109
|
+
return {
|
|
110
|
+
valid: false,
|
|
111
|
+
hashValid: false,
|
|
112
|
+
signatureValid: false,
|
|
113
|
+
error: 'Bundle hash mismatch'
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Verify signature if both signature and public key are provided
|
|
118
|
+
let signatureValid = true;
|
|
119
|
+
if (signature && publicKey) {
|
|
120
|
+
try {
|
|
121
|
+
signatureValid = await verifySignature(data, signature, publicKey);
|
|
122
|
+
} catch (error) {
|
|
123
|
+
return {
|
|
124
|
+
valid: false,
|
|
125
|
+
hashValid: true,
|
|
126
|
+
signatureValid: false,
|
|
127
|
+
error: `Signature verification failed: ${error}`
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if (!signatureValid) {
|
|
131
|
+
return {
|
|
132
|
+
valid: false,
|
|
133
|
+
hashValid: true,
|
|
134
|
+
signatureValid: false,
|
|
135
|
+
error: 'Invalid bundle signature'
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
valid: true,
|
|
141
|
+
hashValid: true,
|
|
142
|
+
signatureValid
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=verification.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","ExpoCrypto","OTAUpdateNative","NativeModules","OTAUpdate","bufferToHex","buffer","bytes","Uint8Array","Array","from","map","b","toString","padStart","join","hexToBytes","hex","length","i","parseInt","substr","calculateHash","data","hash","digestStringAsync","CryptoDigestAlgorithm","SHA256","encoding","CryptoEncoding","HEX","calculateSHA256","binary","String","fromCharCode","base64","btoa","crypto","subtle","hashBuffer","digest","Error","verifyBundleHash","expectedHash","actualHash","verifySignature","signatureHex","publicKeyHex","__DEV__","console","warn","verifyBundle","signature","publicKey","hashValid","error","valid","signatureValid"],"sourceRoot":"../../../src","sources":["utils/verification.ts"],"mappings":";;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA;AACA,IAAIC,UAAe,GAAG,IAAI;AAC1B,IAAI;EACFA,UAAU,GAAGD,OAAO,CAAC,aAAa,CAAC;AACrC,CAAC,CAAC,MAAM;EACN;AAAA;AAGF,MAAME,eAAe,GAAGC,0BAAa,CAACC,SAAS;;AAE/C;AACA,SAASC,WAAWA,CAACC,MAAmB,EAAU;EAChD,MAAMC,KAAK,GAAG,IAAIC,UAAU,CAACF,MAAM,CAAC;EACpC,OAAOG,KAAK,CAACC,IAAI,CAACH,KAAK,CAAC,CACrBI,GAAG,CAACC,CAAC,IAAIA,CAAC,CAACC,QAAQ,CAAC,EAAE,CAAC,CAACC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CACzCC,IAAI,CAAC,EAAE,CAAC;AACb;;AAEA;AACA,SAASC,UAAUA,CAACC,GAAW,EAAc;EAC3C,MAAMV,KAAK,GAAG,IAAIC,UAAU,CAACS,GAAG,CAACC,MAAM,GAAG,CAAC,CAAC;EAC5C,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,GAAG,CAACC,MAAM,EAAEC,CAAC,IAAI,CAAC,EAAE;IACtCZ,KAAK,CAACY,CAAC,GAAG,CAAC,CAAC,GAAGC,QAAQ,CAACH,GAAG,CAACI,MAAM,CAACF,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;EAC/C;EACA,OAA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ACA,IAAIE,cAAc,GAAG,IAAI;EACzB,IAAIL,SAAS,IAAIC,SAAS,EAAE;IAC1B,IAAI;MACFI,cAAc,GAAG,MAAMZ,eAAe,CAACtB,IAAI,EAAE6B,SAAS,EAAEC,SAAS,CAAC;IACpE,CAAC,CAAC,OAAOE,KAAK,EAAE;MACd,OAAO;QACLC,KAAK,EAAE,KAAK;QACZF,SAAS,EAAE,IAAI;QACfG,cAAc,EAAE,KAAK;QACrBF,KAAK,EAAE,kCAAkCA,KAAK;MAChD,CAAC;IACH;IAEA,IAAI,CAACE,cAAc,EAAE;MACnB,OAAO;QACLD,KAAK,EAAE,KAAK;QACZF,SAAS,EAAE,IAAI;QACfG,cAAc,EAAE,KAAK;QACrBF,KAAK,EAAE;MACT,CAAC;IACH;EACF;EAEA,OAAO;IACLC,KAAK,EAAE,IAAI;IACXF,SAAS,EAAE,IAAI;IACfG;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
+
import React, { createContext, useContext, useEffect, useState } from 'react';
|
|
3
|
+
import { Alert } from 'react-native';
|
|
4
|
+
import { useOTAUpdate } from './hooks/useOTAUpdate';
|
|
5
|
+
|
|
6
|
+
// Context type
|
|
7
|
+
|
|
8
|
+
const OTAContext = /*#__PURE__*/createContext(null);
|
|
9
|
+
|
|
10
|
+
// Provider props
|
|
11
|
+
|
|
12
|
+
export function OTAProvider({
|
|
13
|
+
children,
|
|
14
|
+
config,
|
|
15
|
+
onUpdateAvailable,
|
|
16
|
+
onUpdateDownloaded,
|
|
17
|
+
onError,
|
|
18
|
+
showMandatoryUpdateAlert = true,
|
|
19
|
+
mandatoryUpdateAlertTitle = 'Update Required',
|
|
20
|
+
mandatoryUpdateAlertMessage = 'A new version is available and must be installed to continue.'
|
|
21
|
+
}) {
|
|
22
|
+
const ota = useOTAUpdate(config);
|
|
23
|
+
const [handledMandatory, setHandledMandatory] = useState(false);
|
|
24
|
+
|
|
25
|
+
// Handle callbacks
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (ota.status === 'available' && ota.updateInfo) {
|
|
28
|
+
onUpdateAvailable?.(ota.updateInfo);
|
|
29
|
+
|
|
30
|
+
// Handle mandatory updates
|
|
31
|
+
if (showMandatoryUpdateAlert && ota.updateInfo.isMandatory && !handledMandatory) {
|
|
32
|
+
setHandledMandatory(true);
|
|
33
|
+
Alert.alert(mandatoryUpdateAlertTitle, mandatoryUpdateAlertMessage, [{
|
|
34
|
+
text: 'Update Now',
|
|
35
|
+
onPress: async () => {
|
|
36
|
+
try {
|
|
37
|
+
await ota.downloadUpdate();
|
|
38
|
+
await ota.applyUpdate(true);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
// Error is handled by the hook
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}]);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}, [ota.status, ota.updateInfo, onUpdateAvailable, showMandatoryUpdateAlert, handledMandatory, mandatoryUpdateAlertTitle, mandatoryUpdateAlertMessage, ota.downloadUpdate, ota.applyUpdate]);
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (ota.status === 'ready') {
|
|
49
|
+
onUpdateDownloaded?.();
|
|
50
|
+
}
|
|
51
|
+
}, [ota.status, onUpdateDownloaded]);
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (ota.error) {
|
|
54
|
+
onError?.(ota.error);
|
|
55
|
+
}
|
|
56
|
+
}, [ota.error, onError]);
|
|
57
|
+
const contextValue = {
|
|
58
|
+
...ota,
|
|
59
|
+
config
|
|
60
|
+
};
|
|
61
|
+
return /*#__PURE__*/React.createElement(OTAContext.Provider, {
|
|
62
|
+
value: contextValue
|
|
63
|
+
}, children);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Hook to use OTA context
|
|
67
|
+
export function useOTA() {
|
|
68
|
+
const context = useContext(OTAContext);
|
|
69
|
+
if (!context) {
|
|
70
|
+
throw new Error('useOTA must be used within an OTAProvider');
|
|
71
|
+
}
|
|
72
|
+
return context;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Higher-order component
|
|
76
|
+
export function withOTA(Component) {
|
|
77
|
+
return function WithOTA(props) {
|
|
78
|
+
const ota = useOTA();
|
|
79
|
+
return /*#__PURE__*/React.createElement(Component, _extends({}, props, {
|
|
80
|
+
ota: ota
|
|
81
|
+
}));
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Utility component for update banner
|
|
86
|
+
|
|
87
|
+
export function UpdateBanner({
|
|
88
|
+
renderAvailable,
|
|
89
|
+
renderDownloading,
|
|
90
|
+
renderReady
|
|
91
|
+
}) {
|
|
92
|
+
const ota = useOTA();
|
|
93
|
+
if (ota.status === 'available' && ota.updateInfo && renderAvailable) {
|
|
94
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, renderAvailable(ota.updateInfo, ota.downloadUpdate));
|
|
95
|
+
}
|
|
96
|
+
if (ota.status === 'downloading' && ota.downloadProgress && renderDownloading) {
|
|
97
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, renderDownloading(ota.downloadProgress.percentage));
|
|
98
|
+
}
|
|
99
|
+
if (ota.status === 'ready' && renderReady) {
|
|
100
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, renderReady(() => ota.applyUpdate(true)));
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=OTAProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","createContext","useContext","useEffect","useState","Alert","useOTAUpdate","OTAContext","OTAProvider","children","config","onUpdateAvailable","onUpdateDownloaded","onError","showMandatoryUpdateAlert","mandatoryUpdateAlertTitle","mandatoryUpdateAlertMessage","ota","handledMandatory","setHandledMandatory","status","updateInfo","isMandatory","alert","text","onPress","downloadUpdate","applyUpdate","error","contextValue","createElement","Provider","value","useOTA","context","Error","withOTA","Component","WithOTA","props","_extends","UpdateBanner","renderAvailable","renderDownloading","renderReady","Fragment","downloadProgress","percentage"],"sourceRoot":"../../src","sources":["OTAProvider.tsx"],"mappings":";AAAA,OAAOA,KAAK,IACVC,aAAa,EACbC,UAAU,EAEVC,SAAS,EACTC,QAAQ,QAEH,OAAO;AACd,SAASC,KAAK,QAAkB,cAAc;AAC9C,SACEC,YAAY,QAKP,sBAAsB;;AAE7B;;AAKA,MAAMC,UAAU,gBAAGN,aAAa,CAAyB,IAAI,CAAC;;AAE9D;;AAYA,OAAO,SAASO,WAAWA,CAAC;EAC1BC,QAAQ;EACRC,MAAM;EACNC,iBAAiB;EACjBC,kBAAkB;EAClBC,OAAO;EACPC,wBAAwB,GAAG,IAAI;EAC/BC,yBAAyB,GAAG,iBAAiB;EAC7CC,2BAA2B,GAAG;AACd,CAAC,EAAE;EACnB,MAAMC,GAAG,GAAGX,YAAY,CAACI,MAAM,CAAC;EAChC,MAAM,CAACQ,gBAAgB,EAAEC,mBAAmB,CAAC,GAAGf,QAAQ,CAAC,KAAK,CAAC;;EAE/D;EACAD,SAAS,CAAC,MAAM;IACd,IAAIc,GAAG,CAACG,MAAM,KAAK,WAAW,IAAIH,GAAG,CAACI,UAAU,EAAE;MAChDV,iBAAiB,GAAGM,GAAG,CAACI,UAAU,CAAC;;MAEnC;MACA,IACEP,wBAAwB,IACxBG,GAAG,CAACI,UAAU,CAACC,WAAW,IAC1B,CAACJ,gBAAgB,EACjB;QACAC,mBAAmB,CAAC,IAAI,CAAC;QAEzBd,KAAK,CAACkB,KAAK,CAACR,yBAAyB,EAAEC,2BAA2B,EAAE,CAClE;UACEQ,IAAI,EAAE,YAAY;UAClBC,OAAO,EAAE,MAAAA,CAAA,KAAY;YACnB,IAAI;cACF,MAAMR,GAAG,CAACS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