native-update 4.0.1 → 4.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 +4 -3
- package/android/src/main/java/com/aoneahsan/nativeupdate/LiveUpdatePlugin.kt +1 -1
- package/cli/commands/bundle-sign.js +8 -2
- package/cli/commands/remote.js +97 -0
- package/cli/index.js +1 -0
- package/dist/esm/plugin.js +5 -1
- package/dist/plugin.cjs +1 -1
- package/dist/plugin.esm.js +1 -1
- package/dist/plugin.js +2 -2
- package/docs/CHANGELOG.md +42 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,11 +29,11 @@ are available as an HTTP API for CI and coding agents.
|
|
|
29
29
|
|
|
30
30
|
| | |
|
|
31
31
|
|---|---|
|
|
32
|
-
| **Version** | `4.0.
|
|
32
|
+
| **Version** | `4.0.2` |
|
|
33
33
|
| **License** | MIT |
|
|
34
34
|
| **Node** | `>=24.16.0` (install + CLI toolchain) |
|
|
35
35
|
| **Platforms** | iOS 14+ · Android 8.0+ (API 26) · Web |
|
|
36
|
-
| **Package size** |
|
|
36
|
+
| **Package size** | 281 kB tarball · ~1.14 MB unpacked · 136 files |
|
|
37
37
|
| **Types** | Bundled `.d.ts` · ESM + CommonJS entry points |
|
|
38
38
|
| **Status** | Stable · actively maintained |
|
|
39
39
|
|
|
@@ -499,7 +499,8 @@ indexed at [`/raw/manifest.json`](https://nativeupdate-docs.aoneahsan.com/raw/ma
|
|
|
499
499
|
<a id="changelog"></a>
|
|
500
500
|
## 🔄 Changelog [#](#changelog)
|
|
501
501
|
|
|
502
|
-
Latest release: **`4.0.
|
|
502
|
+
Latest release: **`4.0.2`** — prevents downgrade offers and reports the real Android binary version
|
|
503
|
+
before the first OTA, while retaining verified delta delivery with automatic signed-full-bundle fallback,
|
|
503
504
|
standardizes every signer and verifier on RSA-SHA256, hardens native storage and URL validation, and raises
|
|
504
505
|
the supported baseline to Capacitor 8, Node.js 24.16+, and Android API 26+. The patch release also removes
|
|
505
506
|
local Yarn install state from the npm tarball and makes npm-normalized metadata explicit.
|
|
@@ -906,7 +906,7 @@ class LiveUpdatePlugin(
|
|
|
906
906
|
// Return default bundle
|
|
907
907
|
return JSObject().apply {
|
|
908
908
|
put("bundleId", "default")
|
|
909
|
-
put("version", "1.0.0")
|
|
909
|
+
put("version", getBinaryVersion() ?: "1.0.0")
|
|
910
910
|
put("path", "/")
|
|
911
911
|
put("downloadTime", System.currentTimeMillis())
|
|
912
912
|
put("size", 0)
|
|
@@ -27,6 +27,11 @@ export async function signBundle(bundlePath, options) {
|
|
|
27
27
|
// Create signed bundle metadata
|
|
28
28
|
const signedMetadata = {
|
|
29
29
|
originalBundle: path.basename(bundlePath),
|
|
30
|
+
// The bytes this signature actually covers. `deploy` refuses to upload a
|
|
31
|
+
// signature whose checksum does not match the bundle being sent — without
|
|
32
|
+
// it, a stale .sig ships happily and every device rejects the release
|
|
33
|
+
// with nothing visible server-side. See ISSUE-08.
|
|
34
|
+
bundleSha256: crypto.createHash('sha256').update(bundleData).digest('hex'),
|
|
30
35
|
signature,
|
|
31
36
|
signedAt: new Date().toISOString(),
|
|
32
37
|
algorithm: 'RSA-SHA256'
|
|
@@ -48,8 +53,9 @@ export async function signBundle(bundlePath, options) {
|
|
|
48
53
|
console.log(chalk.gray(` Signature: ${sigPath}`));
|
|
49
54
|
console.log('');
|
|
50
55
|
console.log(chalk.yellow('Next steps:'));
|
|
51
|
-
console.log(chalk.gray(
|
|
52
|
-
console.log(chalk.gray('
|
|
56
|
+
console.log(chalk.gray(` npx native-update deploy ${outputPath} --app <your-app> --wait`));
|
|
57
|
+
console.log(chalk.gray(' The .sig beside the bundle is picked up automatically and'));
|
|
58
|
+
console.log(chalk.gray(' uploaded with it, so requireSignature: true is satisfied.'));
|
|
53
59
|
|
|
54
60
|
} catch (error) {
|
|
55
61
|
console.error(chalk.red('❌ Failed to sign bundle:'), error.message);
|
package/cli/commands/remote.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
+
import { createHash } from 'crypto';
|
|
2
3
|
import fs from 'fs/promises';
|
|
3
4
|
import path from 'path';
|
|
4
5
|
import { apiClient, printTable, resolveBundle, waitForJob } from './remote-shared.js';
|
|
@@ -90,12 +91,22 @@ export async function deploy(target, options) {
|
|
|
90
91
|
console.log(chalk.gray(` Channel: ${options.channel}`));
|
|
91
92
|
console.log(chalk.gray(` Bundle: ${(stat.size / 1024 / 1024).toFixed(2)} MB`));
|
|
92
93
|
|
|
94
|
+
// A detached signature from `native-update bundle sign`, if the consumer
|
|
95
|
+
// keeps their own private key. Explicit --signature wins; otherwise the
|
|
96
|
+
// sibling .sig that `bundle sign` writes is picked up automatically, so the
|
|
97
|
+
// documented local-signing flow works without a new flag to remember.
|
|
98
|
+
const signature = await resolveSignature(target, bundle.path, options.signature);
|
|
99
|
+
if (signature) {
|
|
100
|
+
console.log(chalk.gray(` Signed: yes (${signature.source})`));
|
|
101
|
+
}
|
|
102
|
+
|
|
93
103
|
const { data } = await client.upload(`/apps/${options.app}/builds`, bundle.path, {
|
|
94
104
|
version,
|
|
95
105
|
channel: options.channel,
|
|
96
106
|
release_notes: options.notes,
|
|
97
107
|
rollout_percentage: options.rollout,
|
|
98
108
|
min_native_version: options.minNative,
|
|
109
|
+
signature: signature?.value,
|
|
99
110
|
});
|
|
100
111
|
|
|
101
112
|
console.log(chalk.green(`\n✓ Bundle accepted — build #${data.build.id} is processing.`));
|
|
@@ -123,6 +134,92 @@ export async function deploy(target, options) {
|
|
|
123
134
|
}
|
|
124
135
|
}
|
|
125
136
|
|
|
137
|
+
/**
|
|
138
|
+
* Resolve the detached bundle signature to upload, or null.
|
|
139
|
+
*
|
|
140
|
+
* Looks at --signature first, then the `<bundle>.sig` that `bundle sign` writes
|
|
141
|
+
* beside its output. Accepts either the JSON metadata that command produces or
|
|
142
|
+
* a file containing the bare base64 signature.
|
|
143
|
+
*
|
|
144
|
+
* 🔴 When the metadata carries `bundleSha256`, the bundle being uploaded is
|
|
145
|
+
* hashed and compared. A stale or mismatched .sig is REFUSED here rather than
|
|
146
|
+
* uploaded: the server cannot detect it (it has no public key to check
|
|
147
|
+
* against), so the failure would otherwise surface only on a device, as a
|
|
148
|
+
* release that silently never applies. That is ISSUE-08's failure mode and this
|
|
149
|
+
* guard exists so it cannot come back through the front door.
|
|
150
|
+
*/
|
|
151
|
+
async function resolveSignature(target, bundlePath, explicitPath) {
|
|
152
|
+
const candidates = [];
|
|
153
|
+
if (explicitPath) {
|
|
154
|
+
candidates.push(explicitPath);
|
|
155
|
+
} else {
|
|
156
|
+
// `bundle sign` writes <out>.sig next to <out>.zip; deploying either the
|
|
157
|
+
// signed zip or the original picks up the same file.
|
|
158
|
+
candidates.push(bundlePath.replace(/\.zip$/, '.sig'));
|
|
159
|
+
if (typeof target === 'string' && target.endsWith('.zip')) {
|
|
160
|
+
candidates.push(target.replace(/\.zip$/, '.sig'));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
for (const candidate of candidates) {
|
|
165
|
+
const raw = await fs.readFile(candidate, 'utf-8').catch(() => null);
|
|
166
|
+
if (raw === null) continue;
|
|
167
|
+
|
|
168
|
+
let value = raw.trim();
|
|
169
|
+
let expected = null;
|
|
170
|
+
if (value.startsWith('{')) {
|
|
171
|
+
let meta;
|
|
172
|
+
try {
|
|
173
|
+
meta = JSON.parse(value);
|
|
174
|
+
} catch {
|
|
175
|
+
console.error(chalk.red(`Error: ${candidate} is not valid JSON and not a bare signature.`));
|
|
176
|
+
process.exit(1);
|
|
177
|
+
}
|
|
178
|
+
if (!meta.signature) {
|
|
179
|
+
console.error(chalk.red(`Error: ${candidate} has no "signature" field.`));
|
|
180
|
+
process.exit(1);
|
|
181
|
+
}
|
|
182
|
+
if (meta.algorithm && meta.algorithm !== 'RSA-SHA256') {
|
|
183
|
+
console.error(
|
|
184
|
+
chalk.red(`Error: ${candidate} is ${meta.algorithm}; the device verifies RSA-SHA256 only.`)
|
|
185
|
+
);
|
|
186
|
+
process.exit(1);
|
|
187
|
+
}
|
|
188
|
+
value = String(meta.signature).trim();
|
|
189
|
+
expected = meta.bundleSha256 ?? null;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (expected) {
|
|
193
|
+
const actual = createHash('sha256').update(await fs.readFile(bundlePath)).digest('hex');
|
|
194
|
+
if (actual !== expected) {
|
|
195
|
+
console.error(chalk.red('\nError: that signature does not cover this bundle.'));
|
|
196
|
+
console.error(chalk.gray(` signature file: ${candidate}`));
|
|
197
|
+
console.error(chalk.gray(` signed sha256: ${expected}`));
|
|
198
|
+
console.error(chalk.gray(` bundle sha256: ${actual}`));
|
|
199
|
+
console.error(
|
|
200
|
+
chalk.gray(' Re-run `native-update bundle sign` on the bundle you are deploying.')
|
|
201
|
+
);
|
|
202
|
+
console.error(
|
|
203
|
+
chalk.gray(' Uploading it anyway would publish a release every device rejects.')
|
|
204
|
+
);
|
|
205
|
+
process.exit(1);
|
|
206
|
+
}
|
|
207
|
+
} else if (!explicitPath) {
|
|
208
|
+
console.log(
|
|
209
|
+
chalk.yellow(` Note: ${candidate} predates checksum recording — cannot confirm it matches.`)
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return { value, source: explicitPath ? candidate : `auto-detected ${candidate}` };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (explicitPath) {
|
|
217
|
+
console.error(chalk.red(`Error: signature file not found: ${explicitPath}`));
|
|
218
|
+
process.exit(1);
|
|
219
|
+
}
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
|
|
126
223
|
/** `native-update builds promote <app> <build> --to <channel>` */
|
|
127
224
|
export async function buildsPromote(app, build, options) {
|
|
128
225
|
const client = apiClient(options);
|
package/cli/index.js
CHANGED
|
@@ -234,6 +234,7 @@ ${chalk.bold('Examples:')}
|
|
|
234
234
|
.option('-n, --notes <text>', 'Release notes')
|
|
235
235
|
.option('-r, --rollout <percent>', 'Initial rollout percentage (1-100)')
|
|
236
236
|
.option('--min-native <version>', 'Minimum native app version required')
|
|
237
|
+
.option('--signature <file>', 'Detached signature from `bundle sign` (auto-detects a sibling .sig)')
|
|
237
238
|
.option('-w, --wait', 'Wait for processing to finish (exit non-zero if it fails)', false)
|
|
238
239
|
).action(async (target, options) => {
|
|
239
240
|
const { deploy } = await import('./commands/remote.js');
|
package/dist/esm/plugin.js
CHANGED
|
@@ -4,6 +4,7 @@ import { PluginManager } from './core/plugin-manager';
|
|
|
4
4
|
import { NativeUpdateError, ErrorCode } from './core/errors';
|
|
5
5
|
import { checkForUpdate } from './core/update-check';
|
|
6
6
|
import { DeltaProcessor } from './live-update/delta-processor';
|
|
7
|
+
import { VersionManager } from './live-update/version-manager';
|
|
7
8
|
/**
|
|
8
9
|
* Web implementation of the Native Update Plugin
|
|
9
10
|
*/
|
|
@@ -763,8 +764,11 @@ const NativeUpdate = new Proxy(NativeUpdateBridge, {
|
|
|
763
764
|
if (property === 'checkForUpdate') {
|
|
764
765
|
return async () => {
|
|
765
766
|
const [latest, current] = await Promise.all([target.getLatest(), target.current()]);
|
|
767
|
+
const available = latest.available === true
|
|
768
|
+
&& typeof latest.version === 'string'
|
|
769
|
+
&& VersionManager.compareVersions(latest.version, current.version) > 0;
|
|
766
770
|
return {
|
|
767
|
-
available
|
|
771
|
+
available,
|
|
768
772
|
latestVersion: latest.version,
|
|
769
773
|
currentVersion: current.version,
|
|
770
774
|
url: latest.url,
|