@gfean/react-native-bundle-drop 0.4.6 → 0.6.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 (102) hide show
  1. package/README.md +168 -4
  2. package/android/build.gradle +1 -0
  3. package/android/src/main/java/com/bundledrop/BundleDropBoundedDownloader.kt +86 -0
  4. package/android/src/main/java/com/bundledrop/BundleDropModule.kt +69 -0
  5. package/android/src/main/java/com/bundledrop/BundleDropRuntimeCrypto.kt +81 -0
  6. package/ios/BundleDropBridge.m +18 -0
  7. package/ios/BundleDropLocator.swift +48 -2
  8. package/ios/BundleDropModule.swift +75 -0
  9. package/ios/BundleDropRuntimeCrypto.swift +45 -0
  10. package/lib/CLI/cli.d.ts +1 -0
  11. package/lib/CLI/cli.js +166 -79
  12. package/lib/CLI/scripts/aipowered/apply-setup-plan.js +7 -17
  13. package/lib/CLI/scripts/aipowered/backend-client.js +29 -4
  14. package/lib/CLI/scripts/aipowered/code-push-residue.d.ts +5 -0
  15. package/lib/CLI/scripts/aipowered/code-push-residue.js +126 -0
  16. package/lib/CLI/scripts/aipowered/credential-safety.d.ts +1 -0
  17. package/lib/CLI/scripts/aipowered/credential-safety.js +14 -0
  18. package/lib/CLI/scripts/aipowered/diff-preview.js +12 -4
  19. package/lib/CLI/scripts/aipowered/init-project-config.d.ts +4 -0
  20. package/lib/CLI/scripts/aipowered/init-project-config.js +228 -43
  21. package/lib/CLI/scripts/aipowered/scanner.d.ts +1 -0
  22. package/lib/CLI/scripts/aipowered/scanner.js +164 -32
  23. package/lib/CLI/scripts/aipowered/terminal-safety.d.ts +4 -0
  24. package/lib/CLI/scripts/aipowered/terminal-safety.js +124 -0
  25. package/lib/CLI/scripts/aipowered/validate-plan.d.ts +3 -0
  26. package/lib/CLI/scripts/aipowered/validate-plan.js +1080 -19
  27. package/lib/CLI/scripts/bare-metro-config.d.ts +1 -1
  28. package/lib/CLI/scripts/bare-metro-config.js +24 -32
  29. package/lib/CLI/scripts/doctor.js +143 -22
  30. package/lib/CLI/scripts/expo/configure-expo.js +51 -60
  31. package/lib/CLI/scripts/expo/package-manager.d.ts +2 -0
  32. package/lib/CLI/scripts/expo/package-manager.js +63 -25
  33. package/lib/CLI/scripts/init-config.d.ts +7 -7
  34. package/lib/CLI/scripts/init-config.js +246 -32
  35. package/lib/CLI/scripts/login-cli.js +35 -10
  36. package/lib/CLI/scripts/metro-config-authority.d.ts +8 -0
  37. package/lib/CLI/scripts/metro-config-authority.js +303 -0
  38. package/lib/CLI/scripts/native-entrypoint-authority.d.ts +2 -0
  39. package/lib/CLI/scripts/native-entrypoint-authority.js +378 -0
  40. package/lib/CLI/scripts/native-setup-contract.d.ts +2 -2
  41. package/lib/CLI/scripts/native-setup-contract.js +63 -33
  42. package/lib/CLI/scripts/native-startup-validator.d.ts +3 -0
  43. package/lib/CLI/scripts/native-startup-validator.js +964 -0
  44. package/lib/CLI/scripts/safe-file-transaction.d.ts +12 -0
  45. package/lib/CLI/scripts/safe-file-transaction.js +159 -0
  46. package/lib/CLI/scripts/sight-artifacts.d.ts +17 -0
  47. package/lib/CLI/scripts/sight-artifacts.js +204 -0
  48. package/lib/CLI/scripts/sight-cli.d.ts +10 -0
  49. package/lib/CLI/scripts/sight-cli.js +127 -0
  50. package/lib/CLI/scripts/sight-session.d.ts +14 -0
  51. package/lib/CLI/scripts/sight-session.js +192 -0
  52. package/lib/api/clientApi.d.ts +3 -1
  53. package/lib/api/clientApi.js +14 -0
  54. package/lib/api/types.d.ts +39 -0
  55. package/lib/context.d.ts +1 -1
  56. package/lib/index.d.ts +2 -0
  57. package/lib/index.js +3 -1
  58. package/lib/install/installFromZip.d.ts +3 -0
  59. package/lib/install/installFromZip.js +10 -1
  60. package/lib/loadConfig.d.ts +17 -1
  61. package/lib/loadConfig.js +16 -0
  62. package/lib/manager/downloadAndInstall.d.ts +3 -2
  63. package/lib/manager/downloadAndInstall.js +111 -46
  64. package/lib/manager/rollbackState.d.ts +3 -1
  65. package/lib/manager/rollbackState.js +2 -2
  66. package/lib/manager/updateCheck.d.ts +1 -0
  67. package/lib/manager/updateCheck.js +218 -78
  68. package/lib/metro.d.ts +8 -1
  69. package/lib/metro.js +68 -19
  70. package/lib/native/bundleDropNative.js +2 -1
  71. package/lib/native/fs.d.ts +6 -0
  72. package/lib/native/fs.js +24 -0
  73. package/lib/patch-engine/installFromPatchSet.d.ts +2 -0
  74. package/lib/patch-engine/installFromPatchSet.js +14 -3
  75. package/lib/patch-engine/patchTransport.d.ts +2 -0
  76. package/lib/patch-engine/patchTransport.js +9 -0
  77. package/lib/runtime/initState.d.ts +5 -0
  78. package/lib/runtime/initState.js +4 -0
  79. package/lib/runtime/service.js +60 -3
  80. package/lib/runtime-delivery/artifactCapability.d.ts +1 -0
  81. package/lib/runtime-delivery/artifactCapability.js +32 -0
  82. package/lib/runtime-delivery/authorityLeaseVerifier.d.ts +3 -0
  83. package/lib/runtime-delivery/authorityLeaseVerifier.js +106 -0
  84. package/lib/runtime-delivery/bootstrapConfig.d.ts +50 -0
  85. package/lib/runtime-delivery/bootstrapConfig.js +217 -0
  86. package/lib/runtime-delivery/diagnostics.d.ts +17 -0
  87. package/lib/runtime-delivery/diagnostics.js +58 -0
  88. package/lib/runtime-delivery/encoding.d.ts +5 -0
  89. package/lib/runtime-delivery/encoding.js +132 -0
  90. package/lib/runtime-delivery/heartbeat.d.ts +3 -0
  91. package/lib/runtime-delivery/heartbeat.js +88 -0
  92. package/lib/runtime-delivery/localResolver.d.ts +23 -0
  93. package/lib/runtime-delivery/localResolver.js +81 -0
  94. package/lib/runtime-delivery/manifestState.d.ts +9 -0
  95. package/lib/runtime-delivery/manifestState.js +102 -0
  96. package/lib/runtime-delivery/manifestVerifier.d.ts +13 -0
  97. package/lib/runtime-delivery/manifestVerifier.js +329 -0
  98. package/lib/runtime-delivery/runtimeDelivery.d.ts +19 -0
  99. package/lib/runtime-delivery/runtimeDelivery.js +375 -0
  100. package/lib/runtime-delivery/types.d.ts +87 -0
  101. package/lib/runtime-delivery/types.js +6 -0
  102. package/package.json +2 -2
@@ -0,0 +1,329 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.RuntimeDeliveryManifestError = exports.MAX_RUNTIME_MANIFEST_BYTES = void 0;
7
+ exports.verifyRuntimeDeliveryManifest = verifyRuntimeDeliveryManifest;
8
+ exports.verifyRuntimeDeliverySignedPayload = verifyRuntimeDeliverySignedPayload;
9
+ const fs_1 = __importDefault(require("../native/fs"));
10
+ const encoding_1 = require("./encoding");
11
+ const manifestState_1 = require("./manifestState");
12
+ const types_1 = require("./types");
13
+ exports.MAX_RUNTIME_MANIFEST_BYTES = 1024 * 1024;
14
+ const SHA256_PATTERN = /^[a-f0-9]{64}$/;
15
+ class RuntimeDeliveryManifestError extends Error {
16
+ constructor(code, message, options) {
17
+ super(message);
18
+ this.code = code;
19
+ this.name = 'RuntimeDeliveryManifestError';
20
+ this.status = options?.status;
21
+ if (options && 'cause' in options) {
22
+ this.cause = options.cause;
23
+ }
24
+ }
25
+ }
26
+ exports.RuntimeDeliveryManifestError = RuntimeDeliveryManifestError;
27
+ function requireRecord(value, name) {
28
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
29
+ throw new Error(`${name} must be an object`);
30
+ }
31
+ return value;
32
+ }
33
+ function requireExactKeys(value, allowedKeys, name) {
34
+ const allowed = new Set(allowedKeys);
35
+ const unsupported = Object.keys(value).find(key => !allowed.has(key));
36
+ if (unsupported)
37
+ throw new Error(`${name} contains unsupported field ${unsupported}`);
38
+ }
39
+ function requireString(value, name) {
40
+ if (typeof value !== 'string' || !value)
41
+ throw new Error(`${name} must be a non-empty string`);
42
+ return value;
43
+ }
44
+ function requireHash(value, name) {
45
+ const hash = requireString(value, name);
46
+ if (!SHA256_PATTERN.test(hash))
47
+ throw new Error(`${name} must be a lowercase SHA-256 hash`);
48
+ return hash;
49
+ }
50
+ function requireInteger(value, name) {
51
+ if (!Number.isSafeInteger(value) || value < 0) {
52
+ throw new Error(`${name} must be a non-negative safe integer`);
53
+ }
54
+ return value;
55
+ }
56
+ function requirePositiveInteger(value, name) {
57
+ const integer = requireInteger(value, name);
58
+ if (integer < 1)
59
+ throw new Error(`${name} must be at least 1`);
60
+ return integer;
61
+ }
62
+ function requireFiniteNumber(value, name) {
63
+ if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) {
64
+ throw new Error(`${name} must be a non-negative finite number`);
65
+ }
66
+ return value;
67
+ }
68
+ function requireTimestamp(value, name) {
69
+ const timestamp = requireString(value, name);
70
+ if (!Number.isFinite(Date.parse(timestamp)))
71
+ throw new Error(`${name} must be an ISO timestamp`);
72
+ return timestamp;
73
+ }
74
+ function optionalTimestamp(value, name) {
75
+ if (value === null)
76
+ return null;
77
+ if (value === undefined)
78
+ return undefined;
79
+ return requireTimestamp(value, name);
80
+ }
81
+ function parseLaneManifest(payload) {
82
+ const lane = requireRecord(payload, 'Manifest payload');
83
+ requireExactKeys(lane, [
84
+ 'schemaVersion', 'type', 'projectSlug', 'channelName', 'platform', 'runtimeVersion',
85
+ 'generation', 'generatedAt', 'resolutionMode', 'dynamicReason',
86
+ 'publishingMode', 'rolloutAlgorithm', 'revokedHashes', 'releases',
87
+ 'publishedRollouts', 'patchPolicy', 'patchEdges', 'candidateSetComplete',
88
+ ], 'Manifest payload');
89
+ if (lane.schemaVersion !== 3 || lane.type !== 'lane') {
90
+ throw new Error('Unsupported runtime manifest schema or type');
91
+ }
92
+ const resolutionMode = lane.resolutionMode;
93
+ if (resolutionMode !== 'local' && resolutionMode !== 'dynamic') {
94
+ throw new Error('resolutionMode must be local or dynamic');
95
+ }
96
+ const publishingMode = lane.publishingMode;
97
+ if (publishingMode !== 'automatic' && publishingMode !== 'managed') {
98
+ throw new Error('publishingMode must be automatic or managed');
99
+ }
100
+ if (lane.rolloutAlgorithm !== types_1.RUNTIME_DELIVERY_ROLLOUT_ALGORITHM) {
101
+ throw new Error('Unsupported rollout algorithm');
102
+ }
103
+ if (typeof lane.candidateSetComplete !== 'boolean') {
104
+ throw new Error('candidateSetComplete must be boolean');
105
+ }
106
+ const releaseValues = Array.isArray(lane.releases) ? lane.releases : null;
107
+ const rolloutValues = Array.isArray(lane.publishedRollouts) ? lane.publishedRollouts : null;
108
+ const patchValues = Array.isArray(lane.patchEdges) ? lane.patchEdges : null;
109
+ const revokedValues = Array.isArray(lane.revokedHashes) ? lane.revokedHashes : null;
110
+ if (!releaseValues || !rolloutValues || !patchValues || !revokedValues) {
111
+ throw new Error('Manifest candidate arrays are required');
112
+ }
113
+ if (releaseValues.length > 21) {
114
+ throw new Error('Runtime manifest may contain at most 21 releases');
115
+ }
116
+ const releases = releaseValues.map((value, index) => {
117
+ const release = requireRecord(value, `releases[${index}]`);
118
+ requireExactKeys(release, [
119
+ 'releaseRef', 'bundleHash', 'bundleVersion', 'version', 'runtimeVersion',
120
+ 'manifestHash', 'jsBundleHash', 'fullBundleHash', 'fullBundleSizeBytes',
121
+ 'available', 'expiresAt',
122
+ ], `releases[${index}]`);
123
+ if (typeof release.available !== 'boolean') {
124
+ throw new Error(`releases[${index}].available must be boolean`);
125
+ }
126
+ return {
127
+ releaseRef: requireString(release.releaseRef, `releases[${index}].releaseRef`),
128
+ bundleHash: requireHash(release.bundleHash, `releases[${index}].bundleHash`),
129
+ bundleVersion: requireInteger(release.bundleVersion, `releases[${index}].bundleVersion`),
130
+ version: release.version === undefined
131
+ ? undefined
132
+ : requireString(release.version, `releases[${index}].version`),
133
+ runtimeVersion: requireString(release.runtimeVersion, `releases[${index}].runtimeVersion`),
134
+ manifestHash: requireHash(release.manifestHash, `releases[${index}].manifestHash`),
135
+ jsBundleHash: requireHash(release.jsBundleHash, `releases[${index}].jsBundleHash`),
136
+ fullBundleHash: requireHash(release.fullBundleHash, `releases[${index}].fullBundleHash`),
137
+ fullBundleSizeBytes: requirePositiveInteger(release.fullBundleSizeBytes, `releases[${index}].fullBundleSizeBytes`),
138
+ available: release.available,
139
+ expiresAt: optionalTimestamp(release.expiresAt, `releases[${index}].expiresAt`),
140
+ };
141
+ });
142
+ const publishedRollouts = rolloutValues.map((value, index) => {
143
+ const rollout = requireRecord(value, `publishedRollouts[${index}]`);
144
+ requireExactKeys(rollout, ['releaseRef', 'rolloutPercentage', 'status'], `publishedRollouts[${index}]`);
145
+ const percentage = requireFiniteNumber(rollout.rolloutPercentage, `publishedRollouts[${index}].rolloutPercentage`);
146
+ if (percentage > 100)
147
+ throw new Error('rolloutPercentage must be at most 100');
148
+ if (rollout.status !== 'active' && rollout.status !== 'completed') {
149
+ throw new Error(`publishedRollouts[${index}].status is invalid`);
150
+ }
151
+ const status = rollout.status;
152
+ return {
153
+ releaseRef: requireString(rollout.releaseRef, `publishedRollouts[${index}].releaseRef`),
154
+ rolloutPercentage: percentage,
155
+ status,
156
+ };
157
+ });
158
+ const patchPolicy = requireRecord(lane.patchPolicy, 'patchPolicy');
159
+ requireExactKeys(patchPolicy, ['enabled', 'maxPatchToFullRatio'], 'patchPolicy');
160
+ if (typeof patchPolicy.enabled !== 'boolean')
161
+ throw new Error('patchPolicy.enabled must be boolean');
162
+ const maxPatchToFullRatio = requireFiniteNumber(patchPolicy.maxPatchToFullRatio, 'patchPolicy.maxPatchToFullRatio');
163
+ if (maxPatchToFullRatio > 1)
164
+ throw new Error('maxPatchToFullRatio must be at most 1');
165
+ const patchEdges = patchValues.map((value, index) => {
166
+ const edge = requireRecord(value, `patchEdges[${index}]`);
167
+ requireExactKeys(edge, [
168
+ 'baseHash', 'targetHash', 'algorithm', 'patchSetHash', 'patchArtifactRef',
169
+ 'patchSizeBytes', 'fullBundleSizeBytes', 'missingAssetsHash', 'expiresAt',
170
+ ], `patchEdges[${index}]`);
171
+ const missingAssetsHash = edge.missingAssetsHash === null
172
+ ? null
173
+ : edge.missingAssetsHash === undefined
174
+ ? undefined
175
+ : requireHash(edge.missingAssetsHash, `patchEdges[${index}].missingAssetsHash`);
176
+ return {
177
+ baseHash: requireHash(edge.baseHash, `patchEdges[${index}].baseHash`),
178
+ targetHash: requireHash(edge.targetHash, `patchEdges[${index}].targetHash`),
179
+ algorithm: requireString(edge.algorithm, `patchEdges[${index}].algorithm`),
180
+ patchSetHash: requireHash(edge.patchSetHash, `patchEdges[${index}].patchSetHash`),
181
+ patchArtifactRef: requireString(edge.patchArtifactRef, `patchEdges[${index}].patchArtifactRef`),
182
+ patchSizeBytes: requirePositiveInteger(edge.patchSizeBytes, `patchEdges[${index}].patchSizeBytes`),
183
+ fullBundleSizeBytes: requirePositiveInteger(edge.fullBundleSizeBytes, `patchEdges[${index}].fullBundleSizeBytes`),
184
+ missingAssetsHash,
185
+ expiresAt: optionalTimestamp(edge.expiresAt, `patchEdges[${index}].expiresAt`),
186
+ };
187
+ });
188
+ const generation = requireInteger(lane.generation, 'generation');
189
+ if (generation < 1)
190
+ throw new Error('generation must be at least 1');
191
+ const manifest = {
192
+ schemaVersion: 3,
193
+ type: 'lane',
194
+ projectSlug: requireString(lane.projectSlug, 'projectSlug'),
195
+ channelName: requireString(lane.channelName, 'channelName'),
196
+ platform: requireString(lane.platform, 'platform'),
197
+ runtimeVersion: requireString(lane.runtimeVersion, 'runtimeVersion'),
198
+ generation,
199
+ generatedAt: requireTimestamp(lane.generatedAt, 'generatedAt'),
200
+ resolutionMode,
201
+ dynamicReason: lane.dynamicReason === undefined
202
+ ? undefined
203
+ : requireString(lane.dynamicReason, 'dynamicReason'),
204
+ publishingMode,
205
+ rolloutAlgorithm: types_1.RUNTIME_DELIVERY_ROLLOUT_ALGORITHM,
206
+ revokedHashes: revokedValues.map((hash, index) => requireHash(hash, `revokedHashes[${index}]`)),
207
+ releases,
208
+ publishedRollouts,
209
+ patchPolicy: { enabled: patchPolicy.enabled, maxPatchToFullRatio },
210
+ patchEdges,
211
+ candidateSetComplete: lane.candidateSetComplete,
212
+ };
213
+ if (new Set(manifest.revokedHashes).size !== manifest.revokedHashes.length) {
214
+ throw new Error('revokedHashes must contain unique values');
215
+ }
216
+ if (manifest.resolutionMode === 'local') {
217
+ if (!manifest.candidateSetComplete) {
218
+ throw new Error('Local runtime manifests require a complete candidate set');
219
+ }
220
+ if (manifest.releases.some(release => !release.available)) {
221
+ throw new Error('Local runtime manifests require available releases');
222
+ }
223
+ }
224
+ else if (!manifest.dynamicReason ||
225
+ manifest.candidateSetComplete ||
226
+ manifest.releases.length ||
227
+ manifest.publishedRollouts.length ||
228
+ manifest.patchEdges.length) {
229
+ throw new Error('Dynamic runtime manifests require a reason and the safe empty candidate shape');
230
+ }
231
+ validateCandidateConsistency(manifest);
232
+ return manifest;
233
+ }
234
+ function validateCandidateConsistency(manifest) {
235
+ const releaseRefs = new Set();
236
+ const releaseHashes = new Set();
237
+ const releaseByHash = new Map(manifest.releases.map(release => [release.bundleHash, release]));
238
+ for (const release of manifest.releases) {
239
+ if (release.runtimeVersion !== manifest.runtimeVersion)
240
+ throw new Error('Release runtime identity mismatch');
241
+ if (releaseRefs.has(release.releaseRef) || releaseHashes.has(release.bundleHash)) {
242
+ throw new Error('Manifest contains duplicate release identity');
243
+ }
244
+ releaseRefs.add(release.releaseRef);
245
+ releaseHashes.add(release.bundleHash);
246
+ }
247
+ const rolloutRefs = new Set();
248
+ for (const rollout of manifest.publishedRollouts) {
249
+ if (!releaseRefs.has(rollout.releaseRef) || rolloutRefs.has(rollout.releaseRef)) {
250
+ throw new Error('Published rollout references an unknown or duplicate release');
251
+ }
252
+ rolloutRefs.add(rollout.releaseRef);
253
+ }
254
+ const patchEdgeIdentities = new Set();
255
+ for (const edge of manifest.patchEdges) {
256
+ const target = releaseByHash.get(edge.targetHash);
257
+ if (!target || edge.fullBundleSizeBytes !== target.fullBundleSizeBytes) {
258
+ throw new Error('Patch edge is inconsistent with its target release');
259
+ }
260
+ const identity = `${edge.baseHash}\0${edge.targetHash}\0${edge.algorithm}`;
261
+ if (patchEdgeIdentities.has(identity)) {
262
+ throw new Error('Manifest contains duplicate patch edge identity');
263
+ }
264
+ patchEdgeIdentities.add(identity);
265
+ }
266
+ }
267
+ function assertLaneIdentity(manifest, expected) {
268
+ for (const field of ['projectSlug', 'channelName', 'platform', 'runtimeVersion']) {
269
+ if (manifest[field] !== expected[field]) {
270
+ throw new RuntimeDeliveryManifestError('lane_mismatch', `Manifest ${field} identity mismatch`);
271
+ }
272
+ }
273
+ }
274
+ function assertPublicKey(key) {
275
+ if (!key || key.kty !== 'EC' || key.crv !== 'P-256') {
276
+ throw new RuntimeDeliveryManifestError('unknown_key', 'Unknown or invalid manifest signing key');
277
+ }
278
+ if ((0, encoding_1.decodeBase64UrlBytes)(key.x).length !== 32 || (0, encoding_1.decodeBase64UrlBytes)(key.y).length !== 32) {
279
+ throw new RuntimeDeliveryManifestError('unknown_key', 'Manifest signing key coordinates must be 32 bytes');
280
+ }
281
+ }
282
+ async function verifyRuntimeDeliveryManifest(serializedJws, expectedIdentity, publicKeys) {
283
+ const payloadValue = await verifyRuntimeDeliverySignedPayload(serializedJws, types_1.RUNTIME_DELIVERY_MANIFEST_JWS_TYPE, publicKeys);
284
+ const manifest = parseLaneManifest(JSON.parse((0, encoding_1.decodeBase64UrlUtf8)(payloadValue)));
285
+ assertLaneIdentity(manifest, expectedIdentity);
286
+ const payloadSha256 = await fs_1.default.sha256String(payloadValue);
287
+ const previousState = await (0, manifestState_1.readVerifiedLaneState)(expectedIdentity);
288
+ if (previousState && manifest.generation < previousState.highestGeneration) {
289
+ throw new RuntimeDeliveryManifestError('generation_regression', 'Runtime manifest generation regressed');
290
+ }
291
+ if (previousState &&
292
+ manifest.generation === previousState.highestGeneration &&
293
+ previousState.payloadSha256 !== payloadSha256) {
294
+ throw new RuntimeDeliveryManifestError('generation_equivocation', 'Runtime manifest generation equivocation detected');
295
+ }
296
+ await (0, manifestState_1.recordVerifiedLaneManifest)(manifest, payloadSha256);
297
+ return manifest;
298
+ }
299
+ async function verifyRuntimeDeliverySignedPayload(serializedJws, expectedType, publicKeys) {
300
+ if ((0, encoding_1.utf8ByteLength)(serializedJws) > exports.MAX_RUNTIME_MANIFEST_BYTES) {
301
+ throw new RuntimeDeliveryManifestError('body_too_large', 'Runtime manifest exceeds the 1 MB safety limit');
302
+ }
303
+ const envelope = requireRecord(JSON.parse(serializedJws), 'JWS envelope');
304
+ if (Object.keys(envelope).sort().join(',') !== 'payload,protected,signature') {
305
+ throw new Error('JWS envelope contains unsupported fields');
306
+ }
307
+ const protectedValue = requireString(envelope.protected, 'JWS protected');
308
+ const payloadValue = requireString(envelope.payload, 'JWS payload');
309
+ const signatureValue = requireString(envelope.signature, 'JWS signature');
310
+ if ((0, encoding_1.decodeBase64UrlBytes)(signatureValue).length !== 64) {
311
+ throw new RuntimeDeliveryManifestError('invalid_signature', 'ES256 JWS signature must be 64-byte JOSE R||S');
312
+ }
313
+ const protectedHeader = requireRecord(JSON.parse((0, encoding_1.decodeBase64UrlUtf8)(protectedValue)), 'JWS protected header');
314
+ if (Object.keys(protectedHeader).sort().join(',') !== 'alg,kid,typ') {
315
+ throw new Error('JWS protected header contains unsupported fields');
316
+ }
317
+ if (protectedHeader.alg !== 'ES256' ||
318
+ protectedHeader.typ !== expectedType ||
319
+ typeof protectedHeader.kid !== 'string' || !protectedHeader.kid) {
320
+ throw new Error('Unsupported JWS protected header');
321
+ }
322
+ const publicKey = publicKeys[protectedHeader.kid];
323
+ assertPublicKey(publicKey);
324
+ const verified = await fs_1.default.verifyEs256Signature(`${protectedValue}.${payloadValue}`, signatureValue, publicKey.x, publicKey.y);
325
+ if (!verified) {
326
+ throw new RuntimeDeliveryManifestError('invalid_signature', 'Runtime manifest signature verification failed');
327
+ }
328
+ return payloadValue;
329
+ }
@@ -0,0 +1,19 @@
1
+ import type { UpdateCheckResponse } from '../api/types';
2
+ import type { UserProperties } from '../fs/userProperties';
3
+ import type { RuntimeDeliveryLaneIdentity, RuntimeDeliveryLaneManifest } from './types';
4
+ export type RuntimeDeliveryResolveContext = {
5
+ channelName: string;
6
+ currentHash: string | null;
7
+ rejectedHashes: string[];
8
+ installId: string;
9
+ patchAlgorithms: string[];
10
+ supportsContentAddressedAssets: boolean;
11
+ environment: string | null;
12
+ userProperties: UserProperties;
13
+ };
14
+ export declare function runtimeDeliveryManifestUrl(identity: RuntimeDeliveryLaneIdentity): string;
15
+ export declare function runtimeDeliveryAuthorityLeaseUrl(): string;
16
+ export declare function fetchRuntimeDeliveryManifest(channelName: string): Promise<RuntimeDeliveryLaneManifest>;
17
+ export declare function resolveFromRuntimeDeliveryManifest(manifest: RuntimeDeliveryLaneManifest, context: RuntimeDeliveryResolveContext): Promise<UpdateCheckResponse>;
18
+ export declare function reportActiveInstall(context: RuntimeDeliveryResolveContext): void;
19
+ export declare function shouldRollbackFromLastKnownRevocations(channelName: string, currentHash: string | null): Promise<boolean>;