native-update 3.4.2 → 4.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.
Files changed (47) hide show
  1. package/AI-INTEGRATION-GUIDE.md +26 -16
  2. package/NativeUpdate.podspec +2 -2
  3. package/README.md +23 -20
  4. package/android/build.gradle +37 -33
  5. package/android/gradle/wrapper/gradle-wrapper.properties +2 -2
  6. package/android/proguard-rules.pro +0 -3
  7. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundNotificationManager.kt +45 -49
  8. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateManager.kt +12 -10
  9. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdatePlugin.kt +12 -21
  10. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateWorker.kt +3 -34
  11. package/android/src/main/java/com/aoneahsan/nativeupdate/LiveUpdatePlugin.kt +206 -72
  12. package/android/src/main/java/com/aoneahsan/nativeupdate/NativeUpdatePlugin.kt +74 -37
  13. package/android/src/main/java/com/aoneahsan/nativeupdate/SecurityManager.kt +169 -179
  14. package/android/variables.gradle +2 -2
  15. package/cli/.yarn/install-state.gz +0 -0
  16. package/cli/commands/bundle-verify.js +4 -1
  17. package/cli/commands/keys-generate.js +12 -46
  18. package/cli/index.js +4 -7
  19. package/cli/package.json +2 -1
  20. package/dist/esm/core/config.d.ts +3 -0
  21. package/dist/esm/core/config.js +17 -0
  22. package/dist/esm/core/plugin-manager.js +4 -2
  23. package/dist/esm/core/security.js +2 -5
  24. package/dist/esm/core/update-check.d.ts +2 -0
  25. package/dist/esm/core/update-check.js +5 -3
  26. package/dist/esm/definitions.d.ts +43 -2
  27. package/dist/esm/live-update/delta-processor.d.ts +6 -20
  28. package/dist/esm/live-update/delta-processor.js +75 -119
  29. package/dist/esm/plugin.d.ts +0 -3
  30. package/dist/esm/plugin.js +172 -12
  31. package/dist/esm/security/crypto.js +2 -5
  32. package/dist/esm/web.d.ts +1 -9
  33. package/dist/esm/web.js +4 -56
  34. package/dist/plugin.cjs +1 -1
  35. package/dist/plugin.esm.js +1 -1
  36. package/dist/plugin.js +2 -2
  37. package/docs/CHANGELOG.md +42 -0
  38. package/docs/KNOWN_LIMITATIONS.md +4 -3
  39. package/docs/MIGRATION.md +32 -3
  40. package/docs/server-requirements.md +40 -29
  41. package/ios/Plugin/BackgroundUpdate/BackgroundNotificationManager.swift +6 -2
  42. package/ios/Plugin/BackgroundUpdate/BackgroundUpdatePlugin.swift +21 -30
  43. package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +269 -61
  44. package/ios/Plugin/NativeUpdatePlugin.m +8 -1
  45. package/ios/Plugin/NativeUpdatePlugin.swift +71 -34
  46. package/ios/Plugin/Security/SecurityManager.swift +100 -99
  47. package/package.json +25 -14
@@ -2,10 +2,9 @@
2
2
  * Delta Processor
3
3
  *
4
4
  * Handles delta/patch-based updates for reduced download sizes.
5
- * Uses a simple file-level patching strategy that works in JavaScript.
6
- *
7
- * For production, a WASM-based bsdiff/bspatch implementation can be added
8
- * for better performance on binary files.
5
+ * Applies the bounded, deterministic NUDELTA/1 copy/literal format emitted by
6
+ * the canonical backend. Unknown legacy patch formats fail closed and trigger
7
+ * the normal full-bundle fallback.
9
8
  */
10
9
  import { Logger } from '../core/logger';
11
10
  import { ConfigManager } from '../core/config';
@@ -39,6 +38,10 @@ export class DeltaProcessor {
39
38
  onProgress === null || onProgress === void 0 ? void 0 : onProgress(10);
40
39
  // Download delta patch
41
40
  const patchData = await this.downloadPatch(updateInfo.delta.patchUrl);
41
+ if (updateInfo.delta.patchChecksum &&
42
+ !await this.verifyChecksum(patchData, updateInfo.delta.patchChecksum)) {
43
+ throw new ValidationError(ErrorCode.CHECKSUM_MISMATCH, 'Delta patch checksum mismatch');
44
+ }
42
45
  onProgress === null || onProgress === void 0 ? void 0 : onProgress(50);
43
46
  // Apply delta patch
44
47
  const patchedBundle = await this.applyPatch(currentBundleData, patchData, updateInfo.delta.targetChecksum || updateInfo.checksum);
@@ -98,7 +101,16 @@ export class DeltaProcessor {
98
101
  if (!response.ok) {
99
102
  throw new DownloadError(ErrorCode.DOWNLOAD_FAILED, `Failed to download delta patch: ${response.status}`);
100
103
  }
101
- return response.arrayBuffer();
104
+ const maxSize = this.configManager.get('maxBundleSize');
105
+ const declaredSize = Number(response.headers.get('content-length') || 0);
106
+ if (declaredSize > maxSize) {
107
+ throw new DownloadError(ErrorCode.BUNDLE_TOO_LARGE, 'Delta patch exceeds the bundle size limit');
108
+ }
109
+ const data = await response.arrayBuffer();
110
+ if (data.byteLength > maxSize) {
111
+ throw new DownloadError(ErrorCode.BUNDLE_TOO_LARGE, 'Delta patch exceeds the bundle size limit');
112
+ }
113
+ return data;
102
114
  }
103
115
  /**
104
116
  * Download full bundle
@@ -112,6 +124,10 @@ export class DeltaProcessor {
112
124
  // If we can track progress
113
125
  const contentLength = response.headers.get('content-length');
114
126
  const totalBytes = contentLength ? parseInt(contentLength, 10) : 0;
127
+ const maxSize = this.configManager.get('maxBundleSize');
128
+ if (totalBytes > maxSize) {
129
+ throw new DownloadError(ErrorCode.BUNDLE_TOO_LARGE, 'Bundle exceeds the configured size limit');
130
+ }
115
131
  if (totalBytes && response.body) {
116
132
  const reader = response.body.getReader();
117
133
  const chunks = [];
@@ -122,6 +138,10 @@ export class DeltaProcessor {
122
138
  break;
123
139
  chunks.push(value);
124
140
  receivedBytes += value.length;
141
+ if (receivedBytes > maxSize) {
142
+ await reader.cancel();
143
+ throw new DownloadError(ErrorCode.BUNDLE_TOO_LARGE, 'Bundle exceeds the configured size limit');
144
+ }
125
145
  if (onProgress) {
126
146
  const percent = Math.round((receivedBytes / totalBytes) * 90) + 10;
127
147
  onProgress(Math.min(percent, 99));
@@ -139,137 +159,73 @@ export class DeltaProcessor {
139
159
  }
140
160
  // Simple download without progress
141
161
  const data = await response.arrayBuffer();
162
+ if (data.byteLength > maxSize) {
163
+ throw new DownloadError(ErrorCode.BUNDLE_TOO_LARGE, 'Bundle exceeds the configured size limit');
164
+ }
142
165
  onProgress === null || onProgress === void 0 ? void 0 : onProgress(100);
143
166
  return data;
144
167
  }
145
168
  /**
146
169
  * Apply a delta patch to create new bundle
147
170
  *
148
- * This is a simplified patch format using JSON metadata + file-level changes.
149
- * For production binary patching, a WASM bspatch implementation would be used.
171
+ * Only NUDELTA/1 is accepted. Target checksum verification still runs after
172
+ * reconstruction, providing an independent integrity boundary.
150
173
  */
151
- async applyPatch(currentBundle, patchData, _expectedChecksum) {
152
- try {
153
- // Try to parse as JSON patch (file-level patching)
154
- const patchText = new TextDecoder().decode(patchData);
155
- const patch = JSON.parse(patchText);
156
- if (patch.type === 'file-level') {
157
- return this.applyFileLevelPatch(currentBundle, patch);
158
- }
159
- // Binary patch format
160
- return this.applyBinaryPatch(currentBundle, patchData);
161
- }
162
- catch (_a) {
163
- // Treat as binary patch
164
- return this.applyBinaryPatch(currentBundle, patchData);
174
+ async applyPatch(currentBundle, patchData, expectedChecksum) {
175
+ const patchText = new TextDecoder().decode(patchData);
176
+ const patch = JSON.parse(patchText);
177
+ if (patch.format !== 'NUDELTA/1' || patch.targetChecksum !== expectedChecksum) {
178
+ throw new Error('Unsupported or inconsistent delta patch');
165
179
  }
180
+ const baseChecksum = await this.calculateChecksum(currentBundle);
181
+ if (patch.baseChecksum !== baseChecksum)
182
+ throw new Error('NUDELTA base checksum mismatch');
183
+ return this.applyNuDelta(currentBundle, patch);
166
184
  }
167
- /**
168
- * Apply file-level patch (JSON format)
169
- * Supports adding, modifying, and removing files from the bundle
170
- */
171
- async applyFileLevelPatch(currentBundle, patch) {
172
- this.logger.debug('Applying file-level patch', {
173
- fromVersion: patch.fromVersion,
174
- toVersion: patch.toVersion,
175
- added: patch.changes.added.length,
176
- modified: patch.changes.modified.length,
177
- removed: patch.changes.removed.length,
178
- });
179
- // Parse current bundle as a simple file map (JSON-based bundle format)
180
- // This is a lightweight implementation that works without heavy dependencies
181
- let bundleData;
182
- try {
183
- const bundleText = new TextDecoder().decode(currentBundle);
184
- bundleData = JSON.parse(bundleText);
185
- }
186
- catch (_a) {
187
- // If current bundle is not JSON, treat it as a single-file bundle
188
- bundleData = { 'bundle.js': new TextDecoder().decode(currentBundle) };
189
- }
190
- // Apply removals
191
- for (const path of patch.changes.removed) {
192
- delete bundleData[path];
193
- this.logger.debug(`Removed file: ${path}`);
185
+ applyNuDelta(currentBundle, patch) {
186
+ const maxSize = this.configManager.get('maxBundleSize');
187
+ if (!Number.isSafeInteger(patch.targetSize) || patch.targetSize <= 0 || patch.targetSize > maxSize) {
188
+ throw new Error('NUDELTA target size is invalid');
194
189
  }
195
- // Apply additions
196
- for (const file of patch.changes.added) {
197
- // Decode base64 data
198
- const content = this.decodeBase64(file.data);
199
- bundleData[file.path] = content;
200
- this.logger.debug(`Added file: ${file.path}`);
190
+ if (!Array.isArray(patch.operations) || patch.operations.length === 0 || patch.operations.length > 100000) {
191
+ throw new Error('NUDELTA operation count is invalid');
201
192
  }
202
- // Apply modifications
203
- for (const file of patch.changes.modified) {
204
- // Decode base64 data
205
- const content = this.decodeBase64(file.data);
206
- bundleData[file.path] = content;
207
- this.logger.debug(`Modified file: ${file.path}`);
208
- }
209
- // Convert back to ArrayBuffer
210
- const resultText = JSON.stringify(bundleData);
211
- return new TextEncoder().encode(resultText).buffer;
212
- }
213
- /**
214
- * Apply binary patch using a simplified approach
215
- * For production with large files, consider integrating a WASM bsdiff library
216
- */
217
- async applyBinaryPatch(currentBundle, patchData) {
218
- this.logger.debug('Applying binary patch', {
219
- currentSize: currentBundle.byteLength,
220
- patchSize: patchData.byteLength,
221
- });
222
- // Parse patch as JSON instructions (simplified binary diff format)
223
- try {
224
- const patchText = new TextDecoder().decode(patchData);
225
- const patchInstructions = JSON.parse(patchText);
226
- if (patchInstructions.type !== 'binary-diff') {
227
- throw new Error('Invalid binary patch format');
228
- }
229
- const currentView = new Uint8Array(currentBundle);
230
- const resultChunks = [];
231
- // Apply patch operations
232
- for (const op of patchInstructions.operations) {
233
- if (op.type === 'copy' && op.sourceOffset !== undefined && op.length !== undefined) {
234
- // Copy from original bundle
235
- const chunk = currentView.slice(op.sourceOffset, op.sourceOffset + op.length);
236
- resultChunks.push(chunk);
193
+ const base = new Uint8Array(currentBundle);
194
+ const chunks = [];
195
+ let resultSize = 0;
196
+ for (const operation of patch.operations) {
197
+ let chunk;
198
+ if (operation.op === 'copy') {
199
+ if (!Number.isSafeInteger(operation.offset) || !Number.isSafeInteger(operation.length) ||
200
+ operation.offset < 0 || operation.length <= 0 || operation.offset + operation.length > base.length) {
201
+ throw new Error('NUDELTA copy operation is out of bounds');
237
202
  }
238
- else if (op.type === 'insert' && op.data) {
239
- // Insert new data (base64 encoded)
240
- const decoded = Uint8Array.from(atob(op.data), c => c.charCodeAt(0));
241
- resultChunks.push(decoded);
203
+ chunk = base.slice(operation.offset, operation.offset + operation.length);
204
+ }
205
+ else if (operation.op === 'literal' && typeof operation.data === 'string') {
206
+ if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(operation.data)) {
207
+ throw new Error('NUDELTA literal is not valid base64');
242
208
  }
209
+ const binary = atob(operation.data);
210
+ chunk = Uint8Array.from(binary, character => character.charCodeAt(0));
243
211
  }
244
- // Combine all chunks
245
- const totalLength = resultChunks.reduce((sum, chunk) => sum + chunk.length, 0);
246
- const result = new Uint8Array(totalLength);
247
- let offset = 0;
248
- for (const chunk of resultChunks) {
249
- result.set(chunk, offset);
250
- offset += chunk.length;
212
+ else {
213
+ throw new Error('NUDELTA operation is invalid');
251
214
  }
252
- this.logger.debug('Binary patch applied successfully', {
253
- resultSize: result.byteLength,
254
- });
255
- return result.buffer;
256
- }
257
- catch (error) {
258
- this.logger.warn('Binary patch parsing failed, falling back to full download', { error });
259
- throw new Error('Binary patch format not recognized');
260
- }
261
- }
262
- /**
263
- * Decode base64 string to UTF-8 string
264
- */
265
- decodeBase64(base64) {
266
- try {
267
- return atob(base64);
215
+ resultSize += chunk.length;
216
+ if (resultSize > patch.targetSize)
217
+ throw new Error('NUDELTA output exceeds declared size');
218
+ chunks.push(chunk);
268
219
  }
269
- catch (_a) {
270
- // If not valid base64, return as-is
271
- return base64;
220
+ if (resultSize !== patch.targetSize)
221
+ throw new Error('NUDELTA output size mismatch');
222
+ const result = new Uint8Array(resultSize);
223
+ let offset = 0;
224
+ for (const chunk of chunks) {
225
+ result.set(chunk, offset);
226
+ offset += chunk.length;
272
227
  }
228
+ return result.buffer;
273
229
  }
274
230
  /**
275
231
  * Calculate SHA-256 checksum
@@ -1,6 +1,3 @@
1
1
  import type { NativeUpdatePlugin } from './definitions';
2
- /**
3
- * Register the plugin
4
- */
5
2
  declare const NativeUpdate: NativeUpdatePlugin;
6
3
  export { NativeUpdate };
@@ -3,6 +3,7 @@ import { SyncStatus, BundleStatus, UpdateErrorCode } from './definitions';
3
3
  import { PluginManager } from './core/plugin-manager';
4
4
  import { NativeUpdateError, ErrorCode } from './core/errors';
5
5
  import { checkForUpdate } from './core/update-check';
6
+ import { DeltaProcessor } from './live-update/delta-processor';
6
7
  /**
7
8
  * Web implementation of the Native Update Plugin
8
9
  */
@@ -19,11 +20,12 @@ class NativeUpdatePluginWeb {
19
20
  // Setup window event bridge for AppUpdateNotifier events
20
21
  this.setupWindowEventBridge();
21
22
  }
22
- isInitialized() {
23
+ async isInitialized() {
23
24
  return this.initialized && this.pluginManager.isInitialized();
24
25
  }
25
26
  async reset() {
26
27
  await this.pluginManager.reset();
28
+ this.initialized = false;
27
29
  }
28
30
  async cleanup() {
29
31
  await this.pluginManager.cleanup();
@@ -52,6 +54,11 @@ class NativeUpdatePluginWeb {
52
54
  updateStrategy: liveUpdate === null || liveUpdate === void 0 ? void 0 : liveUpdate.updateStrategy,
53
55
  publicKey: liveUpdate === null || liveUpdate === void 0 ? void 0 : liveUpdate.publicKey,
54
56
  requireSignature: liveUpdate === null || liveUpdate === void 0 ? void 0 : liveUpdate.requireSignature,
57
+ allowUnsignedDevelopmentUpdates: liveUpdate === null || liveUpdate === void 0 ? void 0 : liveUpdate.allowUnsignedDevelopmentUpdates,
58
+ maxBundleSize: liveUpdate === null || liveUpdate === void 0 ? void 0 : liveUpdate.maxBundleSize,
59
+ maxUncompressedBundleSize: liveUpdate === null || liveUpdate === void 0 ? void 0 : liveUpdate.maxUncompressedBundleSize,
60
+ allowedHosts: liveUpdate === null || liveUpdate === void 0 ? void 0 : liveUpdate.allowedHosts,
61
+ enableDeltaUpdates: liveUpdate === null || liveUpdate === void 0 ? void 0 : liveUpdate.enableDeltaUpdates,
55
62
  checksumAlgorithm: liveUpdate === null || liveUpdate === void 0 ? void 0 : liveUpdate.checksumAlgorithm,
56
63
  checkInterval: liveUpdate === null || liveUpdate === void 0 ? void 0 : liveUpdate.checkInterval,
57
64
  security: config.security,
@@ -65,9 +72,7 @@ class NativeUpdatePluginWeb {
65
72
  await this.initialize(initConfig);
66
73
  }
67
74
  else {
68
- // Apply plugin configuration
69
- const configManager = this.pluginManager.getConfigManager();
70
- configManager.configure(initConfig);
75
+ throw new NativeUpdateError(ErrorCode.INVALID_CONFIG, 'Configuration is locked after initialization. Call reset() before configuring again.');
71
76
  }
72
77
  }
73
78
  async getSecurityInfo() {
@@ -97,6 +102,8 @@ class NativeUpdatePluginWeb {
97
102
  version: updateInfo.latestVersion,
98
103
  checksum: updateInfo.checksum,
99
104
  signature: updateInfo.signature,
105
+ signatureAlgorithm: updateInfo.signatureAlgorithm,
106
+ delta: updateInfo.delta,
100
107
  });
101
108
  await this.applyUpdate(bundle.bundleId);
102
109
  return {
@@ -126,7 +133,29 @@ class NativeUpdatePluginWeb {
126
133
  async download(options) {
127
134
  const downloadManager = this.pluginManager.getDownloadManager();
128
135
  const bundleManager = this.pluginManager.getBundleManager();
129
- const blob = await downloadManager.downloadWithRetry(options.url, options.version);
136
+ let blob;
137
+ const activeBundle = await bundleManager.getActiveBundle();
138
+ if (options.delta && (activeBundle === null || activeBundle === void 0 ? void 0 : activeBundle.version) === options.delta.fromVersion) {
139
+ const activeBlob = await downloadManager.loadBlob(activeBundle.bundleId);
140
+ const result = await new DeltaProcessor().downloadWithDelta({
141
+ updateAvailable: true,
142
+ version: options.version,
143
+ bundleUrl: options.url,
144
+ checksum: options.checksum,
145
+ size: undefined,
146
+ delta: {
147
+ available: true,
148
+ patchUrl: options.delta.patchUrl,
149
+ patchSize: options.delta.patchSize,
150
+ patchChecksum: options.delta.patchChecksum,
151
+ targetChecksum: options.delta.targetChecksum,
152
+ },
153
+ }, activeBlob ? await activeBlob.arrayBuffer() : null);
154
+ blob = new Blob([result.bundleData], { type: 'application/zip' });
155
+ }
156
+ else {
157
+ blob = await downloadManager.downloadWithRetry(options.url, options.version);
158
+ }
130
159
  // Verify checksum/signature against ACTUAL downloaded bytes before
131
160
  // persisting. Without this, an attacker who swaps the URL or proxies
132
161
  // a tampered bundle can plant arbitrary code and the next set() will
@@ -144,6 +173,7 @@ class NativeUpdatePluginWeb {
144
173
  status: BundleStatus.READY,
145
174
  checksum: options.checksum,
146
175
  signature: options.signature,
176
+ signatureAlgorithm: options.signatureAlgorithm,
147
177
  verified: true,
148
178
  };
149
179
  await bundleManager.saveBundleInfo(bundleInfo);
@@ -214,9 +244,13 @@ class NativeUpdatePluginWeb {
214
244
  notes: result.notes,
215
245
  size: result.size,
216
246
  checksum: result.checksum,
247
+ signature: result.signature,
248
+ signatureAlgorithm: result.signatureAlgorithm,
249
+ delta: result.delta,
217
250
  };
218
251
  }
219
252
  async setChannel(channel) {
253
+ const channelName = typeof channel === 'string' ? channel : channel.channel;
220
254
  // Store the channel preference
221
255
  const preferences = this.pluginManager
222
256
  .getConfigManager()
@@ -224,7 +258,7 @@ class NativeUpdatePluginWeb {
224
258
  if (preferences) {
225
259
  await preferences.set({
226
260
  key: 'update_channel',
227
- value: channel,
261
+ value: channelName,
228
262
  });
229
263
  }
230
264
  }
@@ -233,13 +267,14 @@ class NativeUpdatePluginWeb {
233
267
  * time and cannot be mutated at runtime. Runtime mutation is an XSS
234
268
  * attack vector — a compromised WebView could repoint updates to a
235
269
  * malicious host. Call `initialize()` again with the new config if you
236
- * legitimately need to switch servers.
270
+ * legitimately need to switch servers, call reset() and initialize()
271
+ * again.
237
272
  */
238
273
  async setUpdateUrl(url) {
239
274
  void url;
240
275
  const logger = this.pluginManager.getLogger();
241
276
  logger.warn('setUpdateUrl() is deprecated and ignored. Update URL is locked after initialize(). ' +
242
- 'Call initialize() again with an updated serverUrl to switch servers.');
277
+ 'Call reset(), then initialize() with an updated serverUrl to switch servers.');
243
278
  }
244
279
  async validateUpdate(options) {
245
280
  const securityValidator = this.pluginManager.getSecurityValidator();
@@ -312,7 +347,7 @@ class NativeUpdatePluginWeb {
312
347
  * Check for available updates (convenience wrapper around getLatest + current version)
313
348
  */
314
349
  async checkForUpdate() {
315
- var _a, _b;
350
+ var _a, _b, _c;
316
351
  const bundleManager = this.pluginManager.getBundleManager();
317
352
  const configManager = this.pluginManager.getConfigManager();
318
353
  try {
@@ -363,6 +398,8 @@ class NativeUpdatePluginWeb {
363
398
  size: data.size,
364
399
  checksum: data.checksum,
365
400
  signature: (_b = data.signature) !== null && _b !== void 0 ? _b : undefined,
401
+ signatureAlgorithm: data.signature ? 'RSA-SHA256' : undefined,
402
+ delta: (_c = data.delta) !== null && _c !== void 0 ? _c : undefined,
366
403
  };
367
404
  }
368
405
  catch (error) {
@@ -388,6 +425,8 @@ class NativeUpdatePluginWeb {
388
425
  const version = (options === null || options === void 0 ? void 0 : options.version) || (updateInfo === null || updateInfo === void 0 ? void 0 : updateInfo.latestVersion) || '';
389
426
  const checksum = (options === null || options === void 0 ? void 0 : options.checksum) || (updateInfo === null || updateInfo === void 0 ? void 0 : updateInfo.checksum) || '';
390
427
  const signature = (options === null || options === void 0 ? void 0 : options.signature) || (updateInfo === null || updateInfo === void 0 ? void 0 : updateInfo.signature) || '';
428
+ const signatureAlgorithm = (options === null || options === void 0 ? void 0 : options.signatureAlgorithm) || (updateInfo === null || updateInfo === void 0 ? void 0 : updateInfo.signatureAlgorithm);
429
+ const delta = (options === null || options === void 0 ? void 0 : options.delta) || (updateInfo === null || updateInfo === void 0 ? void 0 : updateInfo.delta);
391
430
  if (!url || !version) {
392
431
  throw new NativeUpdateError(ErrorCode.INVALID_CONFIG, 'URL and version are required for download');
393
432
  }
@@ -416,6 +455,9 @@ class NativeUpdatePluginWeb {
416
455
  size: validatedBlob.size,
417
456
  status: BundleStatus.READY,
418
457
  checksum,
458
+ signature: signature || undefined,
459
+ signatureAlgorithm,
460
+ metadata: delta ? { delta } : undefined,
419
461
  verified: true, // Validated before saving
420
462
  };
421
463
  // Save bundle info
@@ -453,7 +495,7 @@ class NativeUpdatePluginWeb {
453
495
  */
454
496
  async cancelDownload(bundleId) {
455
497
  const downloadManager = this.pluginManager.getDownloadManager();
456
- downloadManager.cancelDownload(bundleId);
498
+ downloadManager.cancelDownload(typeof bundleId === 'string' ? bundleId : bundleId.bundleId);
457
499
  }
458
500
  /**
459
501
  * Cancel all active downloads
@@ -467,7 +509,7 @@ class NativeUpdatePluginWeb {
467
509
  */
468
510
  async isDownloading(bundleId) {
469
511
  const downloadManager = this.pluginManager.getDownloadManager();
470
- return downloadManager.isDownloading(bundleId);
512
+ return downloadManager.isDownloading(typeof bundleId === 'string' ? bundleId : bundleId.bundleId);
471
513
  }
472
514
  /**
473
515
  * Get the count of active downloads
@@ -677,7 +719,125 @@ class NativeUpdatePluginWeb {
677
719
  /**
678
720
  * Register the plugin
679
721
  */
680
- const NativeUpdate = registerPlugin('NativeUpdate', {
722
+ const NativeUpdateBridge = registerPlugin('NativeUpdate', {
681
723
  web: () => new NativeUpdatePluginWeb(),
682
724
  });
725
+ const NativeUpdate = new Proxy(NativeUpdateBridge, {
726
+ get(target, property, receiver) {
727
+ if (property === 'isInitialized') {
728
+ return async () => {
729
+ const result = await target.isInitialized();
730
+ return typeof result === 'boolean'
731
+ ? result
732
+ : !!(result && typeof result === 'object' && 'initialized' in result && result.initialized);
733
+ };
734
+ }
735
+ if (property === 'list') {
736
+ return async () => {
737
+ const result = await target.list();
738
+ if (Array.isArray(result))
739
+ return result;
740
+ if (result && typeof result === 'object' && 'bundles' in result && Array.isArray(result.bundles)) {
741
+ return result.bundles;
742
+ }
743
+ return [];
744
+ };
745
+ }
746
+ if (property === 'setChannel') {
747
+ return (channel) => target.setChannel({ channel });
748
+ }
749
+ if (property === 'setUpdateUrl') {
750
+ return (url) => target.setUpdateUrl({ url });
751
+ }
752
+ if (property === 'scheduleBackgroundCheck') {
753
+ return (interval) => target.scheduleBackgroundCheck({ interval });
754
+ }
755
+ if (property === 'requestNotificationPermissions') {
756
+ return async () => {
757
+ const result = await target.requestNotificationPermissions();
758
+ return typeof result === 'boolean'
759
+ ? result
760
+ : !!(result && typeof result === 'object' && 'granted' in result && result.granted);
761
+ };
762
+ }
763
+ if (property === 'checkForUpdate') {
764
+ return async () => {
765
+ const [latest, current] = await Promise.all([target.getLatest(), target.current()]);
766
+ return {
767
+ available: latest.available,
768
+ latestVersion: latest.version,
769
+ currentVersion: current.version,
770
+ url: latest.url,
771
+ mandatory: latest.mandatory,
772
+ notes: latest.notes,
773
+ size: latest.size,
774
+ checksum: latest.checksum,
775
+ signature: latest.signature,
776
+ signatureAlgorithm: latest.signatureAlgorithm,
777
+ delta: latest.delta,
778
+ };
779
+ };
780
+ }
781
+ if (property === 'downloadUpdate') {
782
+ return async (options = {}) => {
783
+ var _a, _b, _c, _d, _e, _f;
784
+ const latest = options.url && options.version && options.checksum
785
+ ? undefined
786
+ : await target.getLatest();
787
+ const url = (_a = options.url) !== null && _a !== void 0 ? _a : latest === null || latest === void 0 ? void 0 : latest.url;
788
+ const version = (_b = options.version) !== null && _b !== void 0 ? _b : latest === null || latest === void 0 ? void 0 : latest.version;
789
+ const checksum = (_c = options.checksum) !== null && _c !== void 0 ? _c : latest === null || latest === void 0 ? void 0 : latest.checksum;
790
+ if (!url || !version || !checksum) {
791
+ throw new NativeUpdateError(ErrorCode.UPDATE_NOT_AVAILABLE, 'No downloadable update is available');
792
+ }
793
+ return target.download({
794
+ url,
795
+ version,
796
+ checksum,
797
+ signature: (_d = options.signature) !== null && _d !== void 0 ? _d : latest === null || latest === void 0 ? void 0 : latest.signature,
798
+ signatureAlgorithm: (_e = options.signatureAlgorithm) !== null && _e !== void 0 ? _e : latest === null || latest === void 0 ? void 0 : latest.signatureAlgorithm,
799
+ delta: (_f = options.delta) !== null && _f !== void 0 ? _f : latest === null || latest === void 0 ? void 0 : latest.delta,
800
+ });
801
+ };
802
+ }
803
+ if (property === 'applyUpdate') {
804
+ return async (bundleId) => {
805
+ const bundles = await NativeUpdate.list();
806
+ const bundle = bundleId
807
+ ? bundles.find(candidate => candidate.bundleId === bundleId)
808
+ : bundles
809
+ .filter(candidate => candidate.status === BundleStatus.READY)
810
+ .sort((left, right) => right.downloadTime - left.downloadTime)[0];
811
+ if (!bundle) {
812
+ throw new NativeUpdateError(ErrorCode.FILE_NOT_FOUND, 'No ready bundle found to apply');
813
+ }
814
+ await target.set(bundle);
815
+ await target.reload();
816
+ };
817
+ }
818
+ if (property === 'cancelDownload') {
819
+ return (bundleId) => target.cancelDownload({ bundleId });
820
+ }
821
+ if (property === 'isDownloading') {
822
+ return async (bundleId) => {
823
+ const result = await target.isDownloading({ bundleId });
824
+ return typeof result === 'boolean'
825
+ ? result
826
+ : !!(result && typeof result === 'object' && 'isDownloading' in result && result.isDownloading);
827
+ };
828
+ }
829
+ if (property === 'getActiveDownloadCount') {
830
+ return async () => {
831
+ const result = await target.getActiveDownloadCount();
832
+ return typeof result === 'number'
833
+ ? result
834
+ : result && typeof result === 'object' && 'count' in result && typeof result.count === 'number'
835
+ ? result.count
836
+ : 0;
837
+ };
838
+ }
839
+ const value = Reflect.get(target, property, receiver);
840
+ return typeof value === 'function' ? value.bind(target) : value;
841
+ },
842
+ });
683
843
  export { NativeUpdate };
@@ -36,15 +36,12 @@ export class CryptoUtils {
36
36
  const signatureBuffer = this.base64ToArrayBuffer(signature);
37
37
  const publicKeyBuffer = this.base64ToArrayBuffer(pemBody);
38
38
  const key = await crypto.subtle.importKey('spki', publicKeyBuffer, {
39
- name: 'RSA-PSS',
39
+ name: 'RSASSA-PKCS1-v1_5',
40
40
  hash: 'SHA-256',
41
41
  }, false, ['verify']);
42
42
  const encoder = new TextEncoder();
43
43
  const dataBuffer = typeof data === 'string' ? encoder.encode(data) : data;
44
- return await crypto.subtle.verify({
45
- name: 'RSA-PSS',
46
- saltLength: 32,
47
- }, key, signatureBuffer, dataBuffer);
44
+ return await crypto.subtle.verify({ name: 'RSASSA-PKCS1-v1_5' }, key, signatureBuffer, dataBuffer);
48
45
  }
49
46
  catch (error) {
50
47
  // Verification failure must NOT throw — we want a clean false so
package/dist/esm/web.d.ts CHANGED
@@ -88,7 +88,7 @@ export declare class NativeUpdateWeb extends WebPlugin implements NativeUpdateCo
88
88
  */
89
89
  private validateChecksum;
90
90
  /**
91
- * Validate digital signature using RSA-PSS or ECDSA.
91
+ * Validate the backend's RSA-SHA256 (PKCS#1 v1.5) signature.
92
92
  *
93
93
  * Fails closed: if the host app configured a public key or
94
94
  * requireSignature, a missing signature throws. Silent-pass was a P0 gap.
@@ -97,18 +97,10 @@ export declare class NativeUpdateWeb extends WebPlugin implements NativeUpdateCo
97
97
  * @param signature - The signature to verify (base64 encoded)
98
98
  */
99
99
  private validateSignature;
100
- /**
101
- * Fallback signature validation using ECDSA
102
- */
103
- private validateSignatureECDSA;
104
100
  /**
105
101
  * Import RSA public key from PEM format
106
102
  */
107
103
  private importPublicKey;
108
- /**
109
- * Import ECDSA public key from PEM format
110
- */
111
- private importPublicKeyECDSA;
112
104
  /**
113
105
  * Safe localStorage accessor. Returns `null` in environments where
114
106
  * `localStorage` isn't available — SSR, Node-only test runners that