@shiqianjiang/ceru-plugin-issuer 0.3.15 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/component-policy.d.ts +1 -0
- package/dist/component-policy.js +57 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +368 -260
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -19,7 +19,9 @@ console.log(readArtifact(bytes).signatureStatus)
|
|
|
19
19
|
|
|
20
20
|
签名有效不等于发布者已被信任;未提供可信公钥时结果为 verified-untrusted。静态校验不执行插件,也不替代生产沙箱。个性化文件不得提交到公开社区仓库。
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
v3 静态读取 `exports.manifest` / `exports.package`,并从 `exports.activate`、`exports.surfaces`、`exports.modules` 提取运行入口。完整校验只接受 v3 manifest;`sniffManifestVersion` 可以识别 v2 和注释头,以便宿主分派给冻结 v2 环境或显示迁移提示。维护 v2 项目应使用 `0.3.16` 工具链,不能将版本识别当作 v3 校验通过。
|
|
23
|
+
|
|
24
|
+
组件模块在读取和签名时都执行静态策略检查。`ui.regions` 引用的模块另禁止 `Worker`、`SharedWorker` 与 `WebAssembly`,音频 WASM 仍可在 logic 中通过 `ctx.wasm` 使用。静态策略不执行插件代码,也不是 JavaScript 沙箱。
|
|
23
25
|
|
|
24
26
|
`exports.manifest.config` 是同样可静态读取的 JSON 兼容对象。`createTemplate()` 默认从配置字段和类型生成 `personalization.config` 策略;`PreparedIssuer` 只能覆盖该策略允许的配置。`resolveArtifactConfig()` 递归合并清单默认值与签名交付值,业务代码与后端无需改写 bundle。
|
|
25
27
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function assertComponentPolicy(source: string, region?: boolean): void;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { parse } from 'acorn';
|
|
2
|
+
const restricted = new Set([
|
|
3
|
+
'ipcRenderer',
|
|
4
|
+
'localStorage',
|
|
5
|
+
'sessionStorage',
|
|
6
|
+
'indexedDB',
|
|
7
|
+
'eval',
|
|
8
|
+
'Function',
|
|
9
|
+
]);
|
|
10
|
+
const globals = new Set(['window', 'globalThis', 'self']);
|
|
11
|
+
const regionRestricted = new Set(['Worker', 'SharedWorker', 'WebAssembly']);
|
|
12
|
+
function memberName(node) {
|
|
13
|
+
if (node.type !== 'MemberExpression')
|
|
14
|
+
return undefined;
|
|
15
|
+
return node.computed
|
|
16
|
+
? node.property.type === 'Literal'
|
|
17
|
+
? node.property.value
|
|
18
|
+
: undefined
|
|
19
|
+
: node.property.name;
|
|
20
|
+
}
|
|
21
|
+
export function assertComponentPolicy(source, region = false) {
|
|
22
|
+
const isRestricted = (name) => restricted.has(name) || (region && regionRestricted.has(name));
|
|
23
|
+
const nodes = [parse('(' + source + '\n)', { ecmaVersion: 'latest' })];
|
|
24
|
+
while (nodes.length) {
|
|
25
|
+
const node = nodes.pop();
|
|
26
|
+
const member = memberName(node), owner = node.object?.name;
|
|
27
|
+
const forbidden = node.type === 'ImportExpression'
|
|
28
|
+
? 'dynamic import'
|
|
29
|
+
: node.type === 'Identifier' && isRestricted(node.name)
|
|
30
|
+
? node.name
|
|
31
|
+
: isRestricted(member)
|
|
32
|
+
? member
|
|
33
|
+
: globals.has(owner) && ['api', 'electron'].includes(member)
|
|
34
|
+
? owner + '.' + member
|
|
35
|
+
: owner === 'document' && member === 'cookie'
|
|
36
|
+
? 'document.cookie'
|
|
37
|
+
: ['Element', 'Node'].includes(owner) && member === 'prototype'
|
|
38
|
+
? owner + '.prototype'
|
|
39
|
+
: node.type === 'CallExpression' &&
|
|
40
|
+
node.callee.object?.name === 'Object' &&
|
|
41
|
+
memberName(node.callee) === 'defineProperty' &&
|
|
42
|
+
globals.has(node.arguments[0]?.name)
|
|
43
|
+
? 'Object.defineProperty(window)'
|
|
44
|
+
: undefined;
|
|
45
|
+
if (forbidden)
|
|
46
|
+
throw Error('Component policy rejects ' + forbidden);
|
|
47
|
+
for (const child of Object.values(node)) {
|
|
48
|
+
if (Array.isArray(child)) {
|
|
49
|
+
for (const element of child)
|
|
50
|
+
if (element?.type)
|
|
51
|
+
nodes.push(element);
|
|
52
|
+
}
|
|
53
|
+
else if (child?.type)
|
|
54
|
+
nodes.push(child);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { JsonObject, JsonValue, PluginManifest } from '@shiqianjiang/ceru-p
|
|
|
3
3
|
export declare const FORMAT_VERSION = 2;
|
|
4
4
|
export declare const LIMITS: {
|
|
5
5
|
file: number;
|
|
6
|
+
nativeFile: number;
|
|
6
7
|
header: number;
|
|
7
8
|
delivery: number;
|
|
8
9
|
resources: number;
|
|
@@ -19,6 +20,7 @@ export type Resource = {
|
|
|
19
20
|
type: 'base64';
|
|
20
21
|
value: string;
|
|
21
22
|
mime: string;
|
|
23
|
+
sha256?: string;
|
|
22
24
|
};
|
|
23
25
|
export interface Proof {
|
|
24
26
|
mode: 'single@1' | 'template@1' | 'delivery@1';
|
|
@@ -59,6 +61,8 @@ export interface ValidationOptions {
|
|
|
59
61
|
trustedPublicKeys?: string[];
|
|
60
62
|
now?: Date;
|
|
61
63
|
requireUnexpiredActivation?: boolean;
|
|
64
|
+
/** Defaults to the current Node platform/architecture; used by cross-platform tooling. */
|
|
65
|
+
nativePlatform?: string;
|
|
62
66
|
}
|
|
63
67
|
export declare function canonical(value: unknown): string;
|
|
64
68
|
export declare function parseJsonStrict(text: string): any;
|
|
@@ -87,6 +91,7 @@ export declare function resolveArtifactDisplay(header: ArtifactHeader): {
|
|
|
87
91
|
export declare const DEFAULT_PERSONALIZATION_SCHEMA: JsonObject;
|
|
88
92
|
/** Creates the default delivery policy from a plugin's build-time config shape. */
|
|
89
93
|
export declare function createPersonalizationSchema(config?: JsonObject): JsonObject;
|
|
94
|
+
export declare function sniffManifestVersion(input: Uint8Array | string): 2 | 3 | 'legacy-comment' | null;
|
|
90
95
|
export declare function readArtifact(input: Uint8Array | string, options?: ValidationOptions): Artifact;
|
|
91
96
|
export declare function signArtifact(input: Uint8Array, privateKey: string): Buffer;
|
|
92
97
|
export declare function createTemplate(input: Uint8Array, options: {
|
package/dist/index.js
CHANGED
|
@@ -2,11 +2,14 @@ import { createHash, createPrivateKey, createPublicKey, generateKeyPairSync, ran
|
|
|
2
2
|
import { Readable } from 'node:stream';
|
|
3
3
|
import { pipeline } from 'node:stream/promises';
|
|
4
4
|
import { parse, parseExpressionAt } from 'acorn';
|
|
5
|
+
import { assertComponentPolicy } from './component-policy.js';
|
|
5
6
|
import { Ajv } from 'ajv';
|
|
7
|
+
import { valid, validRange } from 'semver';
|
|
6
8
|
import { HOST_MODULE_NAMES, PERMISSION_NAMES } from '@shiqianjiang/ceru-plugin-sdk/catalog';
|
|
7
9
|
export const FORMAT_VERSION = 2;
|
|
8
10
|
export const LIMITS = {
|
|
9
11
|
file: 10 * 1024 * 1024,
|
|
12
|
+
nativeFile: 50 * 1024 * 1024,
|
|
10
13
|
header: 256 * 1024,
|
|
11
14
|
delivery: 16 * 1024,
|
|
12
15
|
resources: 32 * 1024 * 1024,
|
|
@@ -15,6 +18,14 @@ export const LIMITS = {
|
|
|
15
18
|
const START = '/* @ceru-plugin-v2\n';
|
|
16
19
|
const END = '\n@end-ceru-plugin */\n';
|
|
17
20
|
const ID = '^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$';
|
|
21
|
+
const NATIVE_PLATFORMS = [
|
|
22
|
+
'win32-x64',
|
|
23
|
+
'win32-arm64',
|
|
24
|
+
'darwin-x64',
|
|
25
|
+
'darwin-arm64',
|
|
26
|
+
'linux-x64',
|
|
27
|
+
'linux-arm64',
|
|
28
|
+
];
|
|
18
29
|
const forbidden = new Set(['__proto__', 'prototype', 'constructor']);
|
|
19
30
|
const ajv = new Ajv({ strict: false, allErrors: true, ownProperties: true });
|
|
20
31
|
function ensure(ok, message) {
|
|
@@ -116,8 +127,17 @@ const object = (properties, required = []) => ({
|
|
|
116
127
|
required,
|
|
117
128
|
additionalProperties: false,
|
|
118
129
|
});
|
|
130
|
+
const list = (items) => ({ type: 'array', maxItems: 128, items });
|
|
131
|
+
const choices = (values) => ({ ...list({ enum: values }), uniqueItems: true });
|
|
132
|
+
const entryVisibilityRule = object({ loggedIn: { type: 'boolean' }, selectedSource: id, predicate: id, combine: { enum: ['all', 'any'] } });
|
|
133
|
+
const icon = {
|
|
134
|
+
oneOf: [
|
|
135
|
+
object({ kind: { const: 'host' }, name: string }, ['kind', 'name']),
|
|
136
|
+
object({ kind: { const: 'asset' }, resource: id }, ['kind', 'resource']),
|
|
137
|
+
],
|
|
138
|
+
};
|
|
119
139
|
export const MANIFEST_SCHEMA = object({
|
|
120
|
-
manifestVersion: { const:
|
|
140
|
+
manifestVersion: { const: 3 },
|
|
121
141
|
id: { type: 'string', pattern: '^[a-z0-9][a-z0-9._-]{2,127}$' },
|
|
122
142
|
name: { ...string, maxLength: 120 },
|
|
123
143
|
version: {
|
|
@@ -131,23 +151,20 @@ export const MANIFEST_SCHEMA = object({
|
|
|
131
151
|
homepage: string,
|
|
132
152
|
config: { type: 'object', additionalProperties: true },
|
|
133
153
|
engines: object({
|
|
134
|
-
hostApi:
|
|
154
|
+
hostApi: { const: '^3.0.0' },
|
|
135
155
|
logicRuntime: { const: 'ceru-js@1' },
|
|
136
|
-
uiSchema: string,
|
|
137
156
|
libraries: object({ vue: string, react: string, 'react-dom': string }),
|
|
138
157
|
}, ['hostApi', 'logicRuntime']),
|
|
139
|
-
|
|
140
|
-
logic: object({
|
|
141
|
-
share: object({
|
|
142
|
-
|
|
143
|
-
]),
|
|
144
|
-
surfaces: {
|
|
158
|
+
entry: object({
|
|
159
|
+
logic: object({ module: id, activation: strings }, ['module']),
|
|
160
|
+
share: object({ module: id, configKeys: strings, guestAdapterId: id, guestGlobals: strings }, ['module']),
|
|
161
|
+
views: {
|
|
145
162
|
type: 'array',
|
|
146
163
|
maxItems: 64,
|
|
147
164
|
items: object({
|
|
148
165
|
id,
|
|
149
|
-
kind: { enum: ['
|
|
150
|
-
|
|
166
|
+
kind: { enum: ['component', 'web', 'native'] },
|
|
167
|
+
module: id,
|
|
151
168
|
title: { type: 'string', minLength: 1, maxLength: 100 },
|
|
152
169
|
presentation: object({
|
|
153
170
|
kind: { enum: ['drawer', 'modal'] },
|
|
@@ -155,10 +172,29 @@ export const MANIFEST_SCHEMA = object({
|
|
|
155
172
|
size: { type: 'integer', minimum: 280, maximum: 1200 },
|
|
156
173
|
}, ['kind']),
|
|
157
174
|
lifecycle: object({ openAction: id, closeAction: id }),
|
|
158
|
-
}, ['id', 'kind', '
|
|
175
|
+
}, ['id', 'kind', 'module']),
|
|
159
176
|
},
|
|
177
|
+
server: object({
|
|
178
|
+
module: id,
|
|
179
|
+
runtime: { enum: ['sandbox', 'node'] },
|
|
180
|
+
port: { type: 'integer', minimum: 0, maximum: 65535 },
|
|
181
|
+
lan: { type: 'boolean' },
|
|
182
|
+
}, ['module', 'runtime']),
|
|
183
|
+
native: list(object({
|
|
184
|
+
name: {
|
|
185
|
+
type: 'string',
|
|
186
|
+
pattern: '^[a-zA-Z0-9][a-zA-Z0-9._-]*\\.node$',
|
|
187
|
+
maxLength: 128,
|
|
188
|
+
},
|
|
189
|
+
platforms: {
|
|
190
|
+
type: 'object',
|
|
191
|
+
minProperties: 1,
|
|
192
|
+
propertyNames: { enum: NATIVE_PLATFORMS },
|
|
193
|
+
additionalProperties: id,
|
|
194
|
+
},
|
|
195
|
+
}, ['name', 'platforms'])),
|
|
160
196
|
}),
|
|
161
|
-
|
|
197
|
+
provides: object({
|
|
162
198
|
lyricConverters: {
|
|
163
199
|
type: 'array',
|
|
164
200
|
maxItems: 16,
|
|
@@ -174,6 +210,92 @@ export const MANIFEST_SCHEMA = object({
|
|
|
174
210
|
},
|
|
175
211
|
}, ['id', 'title', 'formats']),
|
|
176
212
|
},
|
|
213
|
+
importers: {
|
|
214
|
+
type: 'array',
|
|
215
|
+
maxItems: 64,
|
|
216
|
+
items: object({
|
|
217
|
+
id,
|
|
218
|
+
title: string,
|
|
219
|
+
description: string,
|
|
220
|
+
placeholder: string,
|
|
221
|
+
providerId: id,
|
|
222
|
+
examples: {
|
|
223
|
+
type: 'array',
|
|
224
|
+
maxItems: 16,
|
|
225
|
+
items: object({ label: string, value: string }, ['label', 'value']),
|
|
226
|
+
},
|
|
227
|
+
instructions: strings,
|
|
228
|
+
}, ['id', 'title']),
|
|
229
|
+
},
|
|
230
|
+
providers: {
|
|
231
|
+
type: 'array',
|
|
232
|
+
maxItems: 64,
|
|
233
|
+
items: object({
|
|
234
|
+
id,
|
|
235
|
+
name: string,
|
|
236
|
+
protocols: strings,
|
|
237
|
+
qualities: strings,
|
|
238
|
+
when: entryVisibilityRule,
|
|
239
|
+
beforeSelect: id,
|
|
240
|
+
connectionMode: { enum: ['none', 'single', 'multiple'] },
|
|
241
|
+
icon,
|
|
242
|
+
}, ['id', 'name', 'protocols']),
|
|
243
|
+
},
|
|
244
|
+
guestAdapters: {
|
|
245
|
+
type: 'array',
|
|
246
|
+
maxItems: 16,
|
|
247
|
+
items: object({
|
|
248
|
+
id,
|
|
249
|
+
format: string,
|
|
250
|
+
compatibilityProfile: string,
|
|
251
|
+
title: string,
|
|
252
|
+
extensions: strings,
|
|
253
|
+
badge: object({
|
|
254
|
+
label: { type: 'string', minLength: 1, maxLength: 24 },
|
|
255
|
+
backgroundColor: {
|
|
256
|
+
type: 'string',
|
|
257
|
+
pattern: '^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$',
|
|
258
|
+
},
|
|
259
|
+
textColor: {
|
|
260
|
+
type: 'string',
|
|
261
|
+
pattern: '^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$',
|
|
262
|
+
},
|
|
263
|
+
}, ['label', 'backgroundColor', 'textColor']),
|
|
264
|
+
bootstrap: id,
|
|
265
|
+
runtime: { const: 'ceru-js@1' },
|
|
266
|
+
projectableProtocols: strings,
|
|
267
|
+
}, ['id', 'format', 'compatibilityProfile', 'bootstrap', 'runtime', 'projectableProtocols']),
|
|
268
|
+
},
|
|
269
|
+
actions: list(object({ id, title: string, description: string, view: id }, ['id', 'title'])),
|
|
270
|
+
services: list(object({ id, version: string, methods: strings, description: string }, [
|
|
271
|
+
'id',
|
|
272
|
+
'version',
|
|
273
|
+
'methods',
|
|
274
|
+
])),
|
|
275
|
+
accounts: list(object({
|
|
276
|
+
id,
|
|
277
|
+
title: string,
|
|
278
|
+
icon,
|
|
279
|
+
multiple: { type: 'boolean' },
|
|
280
|
+
loginMethods: { ...choices(['qrcode', 'browser', 'form', 'oauth']), minItems: 1 },
|
|
281
|
+
capabilities: choices(['profile', 'likes', 'playlists', 'history', 'recommend']),
|
|
282
|
+
providers: strings,
|
|
283
|
+
view: id,
|
|
284
|
+
}, ['id', 'title', 'loginMethods'])),
|
|
285
|
+
}),
|
|
286
|
+
ui: object({
|
|
287
|
+
pages: list(object({
|
|
288
|
+
id,
|
|
289
|
+
title: string,
|
|
290
|
+
mount: { enum: ['sidebar', 'settings', 'home-tab', 'playlist-section'] },
|
|
291
|
+
view: id,
|
|
292
|
+
icon,
|
|
293
|
+
group: { enum: ['discover', 'library', 'tools'] },
|
|
294
|
+
order: { type: 'integer' },
|
|
295
|
+
when: entryVisibilityRule,
|
|
296
|
+
}, ['id', 'title', 'mount', 'view'])),
|
|
297
|
+
regions: list(object({ region: string, view: id }, ['region', 'view'])),
|
|
298
|
+
skins: list(object({ id, title: string, preview: icon, regions: strings, settings: { type: 'object' } }, ['id', 'title', 'regions'])),
|
|
177
299
|
menus: {
|
|
178
300
|
type: 'array',
|
|
179
301
|
maxItems: 64,
|
|
@@ -191,47 +313,26 @@ export const MANIFEST_SCHEMA = object({
|
|
|
191
313
|
'search.tools',
|
|
192
314
|
],
|
|
193
315
|
},
|
|
194
|
-
icon
|
|
195
|
-
oneOf: [
|
|
196
|
-
object({ kind: { const: 'host' }, name: string }, ['kind', 'name']),
|
|
197
|
-
object({ kind: { const: 'asset' }, resource: id }, ['kind', 'resource']),
|
|
198
|
-
],
|
|
199
|
-
},
|
|
316
|
+
icon,
|
|
200
317
|
when: object({
|
|
201
318
|
kinds: { type: 'array', items: { enum: ['track', 'playlist'] } },
|
|
202
319
|
loggedIn: { type: 'boolean' },
|
|
203
320
|
}),
|
|
204
321
|
}, ['id', 'slot', 'title', 'commandId']),
|
|
205
322
|
},
|
|
206
|
-
accountItems: {
|
|
207
|
-
type: 'array',
|
|
208
|
-
maxItems: 16,
|
|
209
|
-
items: object({ id, title: string, view: id, action: id, logoutAction: id }, ['id', 'title', 'view', 'action']),
|
|
210
|
-
},
|
|
211
|
-
playlistSections: {
|
|
212
|
-
type: 'array',
|
|
213
|
-
maxItems: 32,
|
|
214
|
-
items: object({ id, title: string, view: id, order: { type: 'integer', minimum: -1000, maximum: 1000 } }, ['id', 'title', 'view']),
|
|
215
|
-
},
|
|
216
323
|
homeSections: {
|
|
217
324
|
type: 'array',
|
|
218
325
|
maxItems: 32,
|
|
219
326
|
items: object({
|
|
220
327
|
id,
|
|
221
328
|
title: string,
|
|
222
|
-
kind: { enum: ['playlists', 'charts'
|
|
223
|
-
icon
|
|
224
|
-
oneOf: [
|
|
225
|
-
object({ kind: { const: 'host' }, name: string }, ['kind', 'name']),
|
|
226
|
-
object({ kind: { const: 'asset' }, resource: id }, ['kind', 'resource']),
|
|
227
|
-
],
|
|
228
|
-
},
|
|
229
|
-
view: id,
|
|
329
|
+
kind: { enum: ['playlists', 'charts'] },
|
|
330
|
+
icon,
|
|
230
331
|
providerIds: strings,
|
|
231
332
|
order: { type: 'integer', minimum: -1000, maximum: 1000 },
|
|
232
333
|
}, ['id', 'title', 'kind']),
|
|
233
334
|
},
|
|
234
|
-
|
|
335
|
+
slots: {
|
|
235
336
|
type: 'array',
|
|
236
337
|
maxItems: 64,
|
|
237
338
|
items: object({
|
|
@@ -280,97 +381,26 @@ export const MANIFEST_SCHEMA = object({
|
|
|
280
381
|
order: { type: 'integer', minimum: -1000, maximum: 1000 },
|
|
281
382
|
}, ['id', 'resource', 'scope']),
|
|
282
383
|
},
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
providerId: id,
|
|
292
|
-
examples: {
|
|
293
|
-
type: 'array',
|
|
294
|
-
maxItems: 16,
|
|
295
|
-
items: object({ label: string, value: string }, ['label', 'value']),
|
|
296
|
-
},
|
|
297
|
-
instructions: strings,
|
|
298
|
-
}, ['id', 'title']),
|
|
299
|
-
},
|
|
300
|
-
providers: {
|
|
384
|
+
}),
|
|
385
|
+
uses: object({
|
|
386
|
+
plugins: list(object({ pluginId: id, service: id, version: string, optional: { type: 'boolean' } }, [
|
|
387
|
+
'pluginId',
|
|
388
|
+
'service',
|
|
389
|
+
'version',
|
|
390
|
+
])),
|
|
391
|
+
permissions: {
|
|
301
392
|
type: 'array',
|
|
302
393
|
maxItems: 64,
|
|
303
394
|
items: object({
|
|
304
|
-
id,
|
|
305
|
-
name:
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
object({ kind: { const: 'host' }, name: string }, ['kind', 'name']),
|
|
312
|
-
object({ kind: { const: 'asset' }, resource: id }, ['kind', 'resource']),
|
|
313
|
-
],
|
|
314
|
-
},
|
|
315
|
-
}, ['id', 'name', 'protocols']),
|
|
316
|
-
},
|
|
317
|
-
commands: {
|
|
318
|
-
type: 'array',
|
|
319
|
-
maxItems: 128,
|
|
320
|
-
items: object({ id, title: string, description: string, action: id, view: id }, [
|
|
321
|
-
'id',
|
|
322
|
-
'title',
|
|
323
|
-
'action',
|
|
324
|
-
]),
|
|
325
|
-
},
|
|
326
|
-
sidebarItems: {
|
|
327
|
-
type: 'array',
|
|
328
|
-
maxItems: 64,
|
|
329
|
-
items: object({ id, group: id, title: string, view: id }, ['id', 'group', 'title', 'view']),
|
|
330
|
-
},
|
|
331
|
-
settingsPages: {
|
|
332
|
-
type: 'array',
|
|
333
|
-
maxItems: 64,
|
|
334
|
-
items: object({ id, title: string, view: id }, ['id', 'title', 'view']),
|
|
335
|
-
},
|
|
336
|
-
guestAdapters: {
|
|
337
|
-
type: 'array',
|
|
338
|
-
maxItems: 16,
|
|
339
|
-
items: object({
|
|
340
|
-
id,
|
|
341
|
-
format: string,
|
|
342
|
-
compatibilityProfile: string,
|
|
343
|
-
title: string,
|
|
344
|
-
extensions: strings,
|
|
345
|
-
badge: object({
|
|
346
|
-
label: { type: 'string', minLength: 1, maxLength: 24 },
|
|
347
|
-
backgroundColor: {
|
|
348
|
-
type: 'string',
|
|
349
|
-
pattern: '^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$',
|
|
350
|
-
},
|
|
351
|
-
textColor: {
|
|
352
|
-
type: 'string',
|
|
353
|
-
pattern: '^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$',
|
|
354
|
-
},
|
|
355
|
-
}, ['label', 'backgroundColor', 'textColor']),
|
|
356
|
-
bootstrap: id,
|
|
357
|
-
runtime: { const: 'ceru-js@1' },
|
|
358
|
-
projectableProtocols: strings,
|
|
359
|
-
}, ['id', 'format', 'compatibilityProfile', 'bootstrap', 'runtime', 'projectableProtocols']),
|
|
395
|
+
key: id,
|
|
396
|
+
name: { enum: PERMISSION_NAMES },
|
|
397
|
+
scope: { type: 'object' },
|
|
398
|
+
reason: string,
|
|
399
|
+
optional: { type: 'boolean' },
|
|
400
|
+
requiredFor: strings,
|
|
401
|
+
}, ['key', 'name', 'reason']),
|
|
360
402
|
},
|
|
361
403
|
}),
|
|
362
|
-
permissions: {
|
|
363
|
-
type: 'array',
|
|
364
|
-
maxItems: 64,
|
|
365
|
-
items: object({
|
|
366
|
-
key: id,
|
|
367
|
-
name: { enum: PERMISSION_NAMES },
|
|
368
|
-
scope: { type: 'object' },
|
|
369
|
-
reason: string,
|
|
370
|
-
optional: { type: 'boolean' },
|
|
371
|
-
requiredFor: strings,
|
|
372
|
-
}, ['key', 'name', 'reason']),
|
|
373
|
-
},
|
|
374
404
|
guestPolicy: object({
|
|
375
405
|
maxDepth: { const: 1 },
|
|
376
406
|
allowedCapabilities: strings,
|
|
@@ -385,73 +415,122 @@ export const MANIFEST_SCHEMA = object({
|
|
|
385
415
|
'allowRemoteCodeExecution',
|
|
386
416
|
]),
|
|
387
417
|
dataSchemas: object({ config: { type: 'integer', minimum: 1 }, state: { type: 'integer', minimum: 1 } }, ['config', 'state']),
|
|
388
|
-
}, ['manifestVersion', 'id', 'name', 'version', 'engines', '
|
|
418
|
+
}, ['manifestVersion', 'id', 'name', 'version', 'engines', 'entry']);
|
|
389
419
|
const checkManifest = ajv.compile(MANIFEST_SCHEMA);
|
|
390
420
|
export function validateManifest(value) {
|
|
391
421
|
canonical(value);
|
|
392
|
-
|
|
422
|
+
if (!checkManifest(value)) {
|
|
423
|
+
const error = checkManifest.errors?.[0];
|
|
424
|
+
const field = error?.params.additionalProperty ?? error?.params.missingProperty;
|
|
425
|
+
throw new Error('Invalid manifest' +
|
|
426
|
+
(error?.instancePath ?? '') +
|
|
427
|
+
(field ? '/' + field : '') +
|
|
428
|
+
': ' +
|
|
429
|
+
(error?.message ?? 'invalid field'));
|
|
430
|
+
}
|
|
393
431
|
const manifest = value;
|
|
432
|
+
const { entry, provides, uses, ui } = manifest;
|
|
394
433
|
const unique = (values, label) => ensure(new Set(values).size === values.length, 'Duplicate ' + label);
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
const
|
|
402
|
-
|
|
403
|
-
for (const
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
434
|
+
for (const [label, items] of Object.entries({ ...provides, ...ui, views: entry.views })) {
|
|
435
|
+
if (items)
|
|
436
|
+
unique(items.map((item) => item.id ?? item.region), label);
|
|
437
|
+
}
|
|
438
|
+
unique((uses?.permissions ?? []).map((item) => item.key), 'permission key');
|
|
439
|
+
unique((uses?.plugins ?? []).map((item) => JSON.stringify([item.pluginId, item.service])), 'service dependency');
|
|
440
|
+
for (const service of provides?.services ?? [])
|
|
441
|
+
ensure(valid(service.version), 'Invalid provides.services version: ' + service.id);
|
|
442
|
+
for (const dependency of uses?.plugins ?? [])
|
|
443
|
+
ensure(validRange(dependency.version), 'Invalid uses.plugins version: ' + dependency.pluginId);
|
|
444
|
+
const views = new Map(entry.views?.map((view) => [view.id, view]));
|
|
445
|
+
const actions = new Set(provides?.actions?.map((action) => action.id));
|
|
446
|
+
const providers = new Set(provides?.providers?.map((provider) => provider.id));
|
|
447
|
+
for (const view of views.values()) {
|
|
448
|
+
if (view.kind === 'native') {
|
|
449
|
+
ensure(entry.logic, 'Native views require a logic module');
|
|
450
|
+
ensure(actions.has(view.module), 'Missing native render action: ' + view.module);
|
|
407
451
|
}
|
|
408
|
-
for (const action of Object.values(
|
|
452
|
+
for (const action of Object.values(view.lifecycle ?? {}))
|
|
409
453
|
ensure(actions.has(action), 'Unknown surface lifecycle action: ' + action);
|
|
410
454
|
}
|
|
411
|
-
for (const
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
ensure(actions.has(account.logoutAction), 'Unknown account logout action: ' + account.logoutAction);
|
|
417
|
-
}
|
|
418
|
-
for (const section of manifest.contributes?.playlistSections ?? [])
|
|
419
|
-
ensure(manifest.modules.surfaces?.some(surface => surface.id === section.view && surface.kind === 'native'), 'Playlist section requires a declared native view: ' + section.view);
|
|
420
|
-
const share = manifest.modules.share;
|
|
421
|
-
if (share?.guestAdapterId)
|
|
422
|
-
ensure(manifest.contributes?.guestAdapters?.some((adapter) => adapter.id === share.guestAdapterId), 'Unknown share guest adapter: ' + share.guestAdapterId);
|
|
423
|
-
for (const name of share?.guestGlobals ?? [])
|
|
424
|
-
ensure(/^[a-zA-Z_$][\w$]*$/.test(name) && !['globalThis', 'arguments', 'eval'].includes(name), 'Invalid share guest global: ' + name);
|
|
425
|
-
for (const menu of manifest.contributes?.menus ?? [])
|
|
426
|
-
ensure(manifest.contributes?.commands?.some((command) => command.id === menu.commandId), 'Unknown menu command: ' + menu.commandId);
|
|
427
|
-
for (const items of [
|
|
428
|
-
manifest.contributes?.commands,
|
|
429
|
-
manifest.contributes?.sidebarItems,
|
|
430
|
-
manifest.contributes?.settingsPages,
|
|
455
|
+
for (const item of [
|
|
456
|
+
...(provides?.accounts ?? []),
|
|
457
|
+
...(provides?.actions ?? []),
|
|
458
|
+
...(ui?.slots ?? []),
|
|
459
|
+
...(ui?.pages ?? []),
|
|
431
460
|
]) {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
ensure(views.has(item.view), 'Unknown view: ' + item.view);
|
|
461
|
+
if (item.view)
|
|
462
|
+
ensure(views.has(item.view), 'Unknown view: ' + item.view);
|
|
435
463
|
}
|
|
436
|
-
for (const
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
ensure(
|
|
441
|
-
|
|
442
|
-
|
|
464
|
+
for (const menu of ui?.menus ?? [])
|
|
465
|
+
ensure(actions.has(menu.commandId), 'Unknown menu command: ' + menu.commandId);
|
|
466
|
+
for (const item of [...(provides?.providers ?? []), ...(ui?.pages ?? [])]) {
|
|
467
|
+
if (item.when?.predicate) {
|
|
468
|
+
ensure(entry.logic, 'Visibility predicates require a logic module');
|
|
469
|
+
ensure(actions.has(item.when.predicate), 'Unknown visibility predicate: ' + item.when.predicate);
|
|
470
|
+
}
|
|
471
|
+
if (item.when?.combine)
|
|
472
|
+
ensure(item.when.predicate, 'Visibility combine requires a predicate');
|
|
473
|
+
}
|
|
474
|
+
for (const provider of provides?.providers ?? []) {
|
|
475
|
+
if (!provider.beforeSelect)
|
|
476
|
+
continue;
|
|
477
|
+
ensure(entry.logic, 'Provider selection hooks require a logic module');
|
|
478
|
+
ensure(actions.has(provider.beforeSelect), 'Unknown provider selection action: ' + provider.beforeSelect);
|
|
479
|
+
}
|
|
480
|
+
for (const page of ui?.pages ?? []) {
|
|
481
|
+
ensure(!page.group || page.mount === 'sidebar', 'Only sidebar pages may declare group: ' + page.id);
|
|
482
|
+
}
|
|
483
|
+
for (const group of [
|
|
484
|
+
...(ui?.homeSections ?? []).map((section) => section.providerIds),
|
|
485
|
+
...(provides?.accounts ?? []).map((account) => account.providers),
|
|
486
|
+
])
|
|
487
|
+
for (const id of group ?? [])
|
|
488
|
+
ensure(providers.has(id), 'Unknown provider: ' + id);
|
|
489
|
+
const boundProviders = new Set();
|
|
490
|
+
for (const account of provides?.accounts ?? []) {
|
|
491
|
+
for (const provider of account.providers ?? []) {
|
|
492
|
+
ensure(!boundProviders.has(provider), 'Provider is bound to multiple accounts: ' + provider);
|
|
493
|
+
boundProviders.add(provider);
|
|
494
|
+
}
|
|
443
495
|
}
|
|
444
|
-
for (const
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
ensure(
|
|
449
|
-
|
|
496
|
+
for (const region of ui?.regions ?? [])
|
|
497
|
+
ensure(views.get(region.view)?.kind === 'component', 'Region requires component view: ' + region.view);
|
|
498
|
+
for (const skin of ui?.skins ?? [])
|
|
499
|
+
for (const name of skin.regions)
|
|
500
|
+
ensure(ui?.regions?.some((region) => region.region === name), 'Unknown skin region: ' + name);
|
|
501
|
+
const permissions = uses?.permissions ?? [];
|
|
502
|
+
const trusted = permissions.filter((permission) => permission.name === 'runtime.trusted');
|
|
503
|
+
ensure(trusted.length <= 1, 'Duplicate runtime.trusted declaration');
|
|
504
|
+
for (const permission of trusted) {
|
|
505
|
+
ensure(Array.from(permission.reason.trim()).length >= 10 &&
|
|
506
|
+
Array.from(permission.reason).length <= 300, 'runtime.trusted reason must be 10 to 300 characters');
|
|
507
|
+
ensure(!/<\s*\/?\s*[a-z!][^>]*>/i.test(permission.reason), 'runtime.trusted reason must be plain text without HTML tags');
|
|
508
|
+
}
|
|
509
|
+
if (entry.server?.runtime === 'node' || entry.native?.length)
|
|
510
|
+
ensure(trusted.length === 1, 'Node servers and entry.native require runtime.trusted');
|
|
511
|
+
if (entry.server?.runtime === 'sandbox')
|
|
512
|
+
ensure(permissions.some((permission) => permission.name === 'network.serve'), 'Sandbox server requires network.serve');
|
|
513
|
+
if (entry.server?.lan)
|
|
514
|
+
ensure(permissions.some((permission) => permission.name === 'network.serve.lan'), 'LAN server requires network.serve.lan');
|
|
515
|
+
if (entry.native?.length) {
|
|
516
|
+
ensure(entry.server?.runtime === 'node', 'entry.native requires a node server');
|
|
517
|
+
unique(entry.native.map((native) => native.name.toLowerCase()), 'native name');
|
|
518
|
+
for (const native of entry.native) {
|
|
519
|
+
ensure(!/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(native.name), 'Invalid native filename: ' + native.name);
|
|
520
|
+
for (const resource of Object.values(native.platforms))
|
|
521
|
+
ensure(!/^[a-z]:/i.test(resource) && !/^\.{1,2}$/.test(resource), 'Invalid native resource id: ' + resource);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
if (entry.share?.guestAdapterId)
|
|
525
|
+
ensure(provides?.guestAdapters?.some((item) => item.id === entry.share.guestAdapterId), 'Unknown share guest adapter: ' + entry.share.guestAdapterId);
|
|
526
|
+
for (const name of entry.share?.guestGlobals ?? [])
|
|
527
|
+
ensure(/^[a-zA-Z_$][\w$]*$/.test(name) && !['globalThis', 'arguments', 'eval'].includes(name), 'Invalid share guest global: ' + name);
|
|
528
|
+
for (const style of ui?.styles ?? []) {
|
|
450
529
|
ensure(style.scope !== 'slot' || style.slots?.length, 'Slot style requires slots');
|
|
451
530
|
ensure(style.scope !== 'application' ||
|
|
452
|
-
|
|
531
|
+
uses?.permissions?.some((item) => item.name === 'ui.styles.global'), 'Application styles require ui.styles.global');
|
|
453
532
|
}
|
|
454
|
-
if (
|
|
533
|
+
if (provides?.guestAdapters?.length)
|
|
455
534
|
ensure(manifest.guestPolicy, 'guestPolicy is required for a guest adapter');
|
|
456
535
|
}
|
|
457
536
|
export function digest(input) {
|
|
@@ -522,9 +601,12 @@ export function encodeHeader(header) {
|
|
|
522
601
|
}
|
|
523
602
|
export function encodeArtifact(header, body) {
|
|
524
603
|
const result = Buffer.concat([encodeHeader(header), Buffer.from(body)]);
|
|
525
|
-
ensure(result.length <=
|
|
604
|
+
ensure(result.length <= artifactSizeLimit(header.manifest), 'Artifact exceeds size limit');
|
|
526
605
|
return result;
|
|
527
606
|
}
|
|
607
|
+
function artifactSizeLimit(manifest) {
|
|
608
|
+
return manifest.entry.native?.length ? LIMITS.nativeFile : LIMITS.file;
|
|
609
|
+
}
|
|
528
610
|
function mergeConfig(base, override) {
|
|
529
611
|
const result = JSON.parse(canonical(base));
|
|
530
612
|
for (const [key, value] of Object.entries(override)) {
|
|
@@ -800,14 +882,14 @@ function inspectBody(body, manifest) {
|
|
|
800
882
|
for (const [key, node] of astObject(resolveBinding(exported.get('modules'))))
|
|
801
883
|
addModule(key, node);
|
|
802
884
|
if (exported.has('activate')) {
|
|
803
|
-
ensure(manifest.
|
|
804
|
-
addModule(manifest.
|
|
885
|
+
ensure(manifest.entry.logic, 'activate requires entry.logic');
|
|
886
|
+
addModule(manifest.entry.logic.module, exported.get('activate'));
|
|
805
887
|
}
|
|
806
888
|
if (exported.has('surfaces'))
|
|
807
889
|
for (const [id, node] of astObject(resolveBinding(exported.get('surfaces')))) {
|
|
808
|
-
const surface = manifest.
|
|
890
|
+
const surface = manifest.entry.views?.find((item) => item.id === id && item.kind !== 'native');
|
|
809
891
|
ensure(surface, 'Unknown visible surface: ' + id);
|
|
810
|
-
addModule(surface.
|
|
892
|
+
addModule(surface.module, node);
|
|
811
893
|
}
|
|
812
894
|
registry = new Map([
|
|
813
895
|
['modules', { type: 'ObjectExpression', properties }],
|
|
@@ -842,8 +924,10 @@ function inspectBody(body, manifest) {
|
|
|
842
924
|
let resourceBytes = 0;
|
|
843
925
|
for (const [key, resource] of Object.entries(resources)) {
|
|
844
926
|
ensure(new RegExp(ID).test(key), 'Invalid resource id: ' + key);
|
|
845
|
-
exactKeys(resource, ['type', 'value', 'mime'], 'resource');
|
|
927
|
+
exactKeys(resource, ['type', 'value', 'mime', 'sha256'], 'resource');
|
|
846
928
|
ensure(['json', 'text', 'base64'].includes(resource.type), 'Invalid resource type');
|
|
929
|
+
if ('sha256' in resource)
|
|
930
|
+
ensure(resource.type === 'base64', 'Only binary resources may declare sha256');
|
|
847
931
|
if ('mime' in resource && resource.mime !== undefined)
|
|
848
932
|
ensure(typeof resource.mime === 'string' && resource.mime.length <= 128, 'Invalid resource MIME type');
|
|
849
933
|
if (resource.type === 'json')
|
|
@@ -851,37 +935,51 @@ function inspectBody(body, manifest) {
|
|
|
851
935
|
else {
|
|
852
936
|
ensure(typeof resource.value === 'string', 'Text/binary resource must be a string');
|
|
853
937
|
if (resource.type === 'base64') {
|
|
854
|
-
ensure(/^
|
|
855
|
-
|
|
938
|
+
ensure(resource.value.length % 4 === 0 && /^[A-Za-z0-9+/]*={0,2}$/.test(resource.value), 'Invalid base64 resource');
|
|
939
|
+
const decoded = Buffer.from(resource.value, 'base64');
|
|
940
|
+
if ('sha256' in resource) {
|
|
941
|
+
ensure(typeof resource.sha256 === 'string' && /^sha256:[a-f0-9]{64}$/.test(resource.sha256), 'Invalid resource SHA-256: ' + key);
|
|
942
|
+
ensure(resource.sha256 === digest(decoded), 'Resource SHA-256 mismatch: ' + key);
|
|
943
|
+
}
|
|
944
|
+
resourceBytes += decoded.length;
|
|
856
945
|
}
|
|
857
946
|
else
|
|
858
947
|
resourceBytes += Buffer.byteLength(resource.value);
|
|
859
948
|
}
|
|
860
949
|
}
|
|
861
950
|
ensure(resourceBytes <= LIMITS.resources, 'Decoded resources exceed limit');
|
|
951
|
+
for (const native of manifest.entry.native ?? []) {
|
|
952
|
+
for (const resourceId of Object.values(native.platforms)) {
|
|
953
|
+
const resource = resources[resourceId];
|
|
954
|
+
ensure(resource?.type === 'base64' && resource.value.length > 0, 'Native module requires a nonempty base64 resource: ' + resourceId);
|
|
955
|
+
ensure(resource.sha256, 'Native resource requires SHA-256: ' + resourceId);
|
|
956
|
+
ensure(Buffer.from(resource.value, 'base64').toString('base64') === resource.value, 'Native resource must use canonical base64: ' + resourceId);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
862
959
|
const declared = new Set();
|
|
863
960
|
const add = (entry) => {
|
|
864
961
|
ensure(Object.hasOwn(modules, entry), 'Missing module: ' + entry);
|
|
865
962
|
declared.add(entry);
|
|
866
963
|
};
|
|
867
|
-
if (manifest.
|
|
868
|
-
add(manifest.
|
|
869
|
-
if (manifest.
|
|
870
|
-
add(manifest.
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
964
|
+
if (manifest.entry.logic)
|
|
965
|
+
add(manifest.entry.logic.module);
|
|
966
|
+
if (manifest.entry.share)
|
|
967
|
+
add(manifest.entry.share.module);
|
|
968
|
+
if (manifest.entry.server)
|
|
969
|
+
add(manifest.entry.server.module);
|
|
970
|
+
for (const view of manifest.entry.views ?? []) {
|
|
971
|
+
if (view.kind === 'native')
|
|
972
|
+
continue;
|
|
973
|
+
add(view.module);
|
|
974
|
+
if (view.kind === 'component')
|
|
975
|
+
assertComponentPolicy(modules[view.module], manifest.ui?.regions?.some((region) => region.view === view.id) ?? false);
|
|
878
976
|
}
|
|
879
|
-
for (const adapter of manifest.
|
|
977
|
+
for (const adapter of manifest.provides?.guestAdapters ?? [])
|
|
880
978
|
add(adapter.bootstrap);
|
|
881
|
-
for (const provider of manifest.
|
|
979
|
+
for (const provider of manifest.provides?.providers ?? [])
|
|
882
980
|
if (provider.icon?.kind === 'asset')
|
|
883
981
|
ensure(Object.hasOwn(resources, provider.icon.resource), 'Missing icon resource');
|
|
884
|
-
for (const style of manifest.
|
|
982
|
+
for (const style of manifest.ui?.styles ?? []) {
|
|
885
983
|
const resource = resources[style.resource];
|
|
886
984
|
ensure(resource?.type === 'text', 'Style contribution requires a text resource');
|
|
887
985
|
ensure(!/@import\b|url\s*\(\s*(?!["']?data:)|expression\s*\(|behavior\s*:/i.test(resource.value), 'Style contribution cannot load external resources or executable CSS');
|
|
@@ -897,85 +995,95 @@ function inspectBody(body, manifest) {
|
|
|
897
995
|
: [],
|
|
898
996
|
};
|
|
899
997
|
}
|
|
900
|
-
function
|
|
901
|
-
const comment =
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
998
|
+
function legacyComment(text) {
|
|
999
|
+
const comment = /^\s*\/\*!([\s\S]*?)\*\//.exec(text)?.[1];
|
|
1000
|
+
return !!comment && /@name[ \t]+\S/.test(comment) && /@version[ \t]+\S/.test(comment);
|
|
1001
|
+
}
|
|
1002
|
+
function artifactPrefix(text) {
|
|
1003
|
+
if (text.startsWith(START)) {
|
|
1004
|
+
const end = text.indexOf(END, START.length);
|
|
1005
|
+
ensure(end >= 0 && Buffer.byteLength(text.slice(0, end)) <= LIMITS.header, 'Invalid static header boundary');
|
|
1006
|
+
const header = parseJsonStrict(text.slice(START.length, end));
|
|
1007
|
+
return { header, end: end + END.length };
|
|
1008
|
+
}
|
|
1009
|
+
let offset = 0;
|
|
1010
|
+
function assignment(name) {
|
|
1011
|
+
const match = new RegExp('^\\s*exports\\.' + name + '\\s*=\\s*').exec(text.slice(offset));
|
|
1012
|
+
if (!match)
|
|
1013
|
+
return undefined;
|
|
1014
|
+
const node = parseExpressionAt(text, offset + match[0].length, { ecmaVersion: 2022 });
|
|
1015
|
+
const boundary = /^[ \t]*(?:;[ \t]*(?:\r?\n)?|\r?\n|$)/.exec(text.slice(node.end));
|
|
1016
|
+
ensure(boundary, 'Metadata assignments must end at a statement boundary');
|
|
1017
|
+
offset = node.end + boundary[0].length;
|
|
1018
|
+
ensure(Buffer.byteLength(text.slice(0, offset)) <= LIMITS.header, 'Artifact metadata is too large');
|
|
1019
|
+
return node;
|
|
1020
|
+
}
|
|
1021
|
+
const manifestNode = assignment('manifest');
|
|
1022
|
+
if (!manifestNode)
|
|
1023
|
+
return legacyComment(text) ? 'legacy-comment' : null;
|
|
915
1024
|
return {
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
id,
|
|
921
|
-
name,
|
|
922
|
-
version,
|
|
923
|
-
description: value('description'),
|
|
924
|
-
author: value('author'),
|
|
925
|
-
engines: { hostApi: '^2.0.0', logicRuntime: 'legacy-comment@1' },
|
|
926
|
-
modules: {},
|
|
1025
|
+
manifestNode,
|
|
1026
|
+
assignment,
|
|
1027
|
+
get end() {
|
|
1028
|
+
return offset;
|
|
927
1029
|
},
|
|
928
|
-
signature: null,
|
|
929
1030
|
};
|
|
930
1031
|
}
|
|
1032
|
+
export function sniffManifestVersion(input) {
|
|
1033
|
+
try {
|
|
1034
|
+
const limit = LIMITS.header + END.length + 4;
|
|
1035
|
+
const prefix = typeof input === 'string'
|
|
1036
|
+
? input.slice(0, limit)
|
|
1037
|
+
: new TextDecoder('utf-8', { fatal: true }).decode(input.subarray(0, limit), {
|
|
1038
|
+
stream: input.length > limit,
|
|
1039
|
+
});
|
|
1040
|
+
const parsed = artifactPrefix(prefix.replace(/^\uFEFF/, ''));
|
|
1041
|
+
if (!parsed || parsed === 'legacy-comment')
|
|
1042
|
+
return parsed;
|
|
1043
|
+
const node = parsed.manifestNode && astObject(parsed.manifestNode).get('manifestVersion');
|
|
1044
|
+
const version = parsed.manifestNode
|
|
1045
|
+
? node?.type === 'Literal'
|
|
1046
|
+
? node.value
|
|
1047
|
+
: null
|
|
1048
|
+
: parsed.header?.manifest?.manifestVersion;
|
|
1049
|
+
return version === 2 || version === 3 ? version : null;
|
|
1050
|
+
}
|
|
1051
|
+
catch {
|
|
1052
|
+
return null;
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
931
1055
|
export function readArtifact(input, options = {}) {
|
|
932
1056
|
const bytes = typeof input === 'string' ? Buffer.from(input) : input;
|
|
933
|
-
ensure(bytes.byteLength <= LIMITS.
|
|
1057
|
+
ensure(bytes.byteLength <= LIMITS.nativeFile, 'Artifact exceeds size limit');
|
|
934
1058
|
const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
935
1059
|
let header;
|
|
936
1060
|
let body;
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
else {
|
|
944
|
-
// Read only JSON-compatible literal metadata. Never run source to display permissions.
|
|
945
|
-
let offset = 0;
|
|
946
|
-
function assignment(name) {
|
|
947
|
-
const match = new RegExp('^\\s*exports\\.' + name + '\\s*=\\s*').exec(text.slice(offset));
|
|
948
|
-
if (!match)
|
|
949
|
-
return undefined;
|
|
950
|
-
const start = offset + match[0].length;
|
|
951
|
-
const node = parseExpressionAt(text, start, { ecmaVersion: 2022 });
|
|
952
|
-
const tail = text.slice(node.end);
|
|
953
|
-
const terminated = /^[ \t]*;[ \t]*(?:\r?\n)?/.exec(tail);
|
|
954
|
-
const asi = /^[ \t]*\r?\n/.exec(tail);
|
|
955
|
-
ensure(terminated || asi, 'Metadata assignments must end at a statement boundary');
|
|
956
|
-
offset = node.end + (terminated ?? asi)[0].length;
|
|
957
|
-
ensure(Buffer.byteLength(text.slice(0, offset)) <= LIMITS.header, 'Artifact metadata is too large');
|
|
958
|
-
return node;
|
|
959
|
-
}
|
|
960
|
-
const manifestNode = assignment('manifest');
|
|
961
|
-
if (!manifestNode) {
|
|
962
|
-
const legacy = legacyCommentArtifact(text);
|
|
963
|
-
ensure(!legacy, 'Legacy comment-header plugins are recognized for migration metadata only; convert them to exports.manifest/exports.activate before installation.');
|
|
964
|
-
}
|
|
965
|
-
ensure(manifestNode, 'Expected exports.manifest = { ... };');
|
|
966
|
-
const manifest = astJson(manifestNode);
|
|
967
|
-
const packageNode = assignment('package');
|
|
1061
|
+
const prefix = artifactPrefix(text.slice(0, LIMITS.header + END.length + 4));
|
|
1062
|
+
ensure(prefix !== 'legacy-comment', 'Legacy comment-header plugins are recognized for migration metadata only; import through an LX adapter.');
|
|
1063
|
+
ensure(prefix, 'Expected exports.manifest = { ... };');
|
|
1064
|
+
if (prefix.manifestNode) {
|
|
1065
|
+
const manifest = astJson(prefix.manifestNode);
|
|
1066
|
+
const packageNode = prefix.assignment('package');
|
|
968
1067
|
const metadata = packageNode
|
|
969
1068
|
? astJson(packageNode)
|
|
970
1069
|
: { formatVersion: 2, syntax: 'js', signature: null };
|
|
971
1070
|
ensure(plain(metadata) && !Object.hasOwn(metadata, 'manifest'), 'Invalid package metadata');
|
|
972
1071
|
header = { ...metadata, manifest };
|
|
973
|
-
body = text.slice(offset);
|
|
974
1072
|
}
|
|
1073
|
+
else
|
|
1074
|
+
header = prefix.header;
|
|
1075
|
+
body = text.slice(prefix.end);
|
|
975
1076
|
exactKeys(header, ['formatVersion', 'syntax', 'manifest', 'signature', 'template', 'delivery'], 'header');
|
|
976
1077
|
ensure(header.formatVersion === 2 && header.syntax === 'js', 'Unsupported artifact format/syntax');
|
|
977
1078
|
ensure(Object.hasOwn(header, 'signature'), 'Signature field is required');
|
|
978
1079
|
validateManifest(header.manifest);
|
|
1080
|
+
ensure(bytes.byteLength <= artifactSizeLimit(header.manifest), 'Artifact exceeds size limit');
|
|
1081
|
+
if (header.manifest.entry.native?.length) {
|
|
1082
|
+
const platform = options.nativePlatform ?? process.platform + '-' + process.arch;
|
|
1083
|
+
ensure(NATIVE_PLATFORMS.includes(platform), 'Unsupported native platform: ' + platform);
|
|
1084
|
+
for (const native of header.manifest.entry.native)
|
|
1085
|
+
ensure(Object.hasOwn(native.platforms, platform), 'Native module does not support current platform ' + platform + ': ' + native.name);
|
|
1086
|
+
}
|
|
979
1087
|
const codeDigest = digest(body);
|
|
980
1088
|
let signatureStatus = 'unsigned';
|
|
981
1089
|
let templateDigest;
|
|
@@ -1089,7 +1197,7 @@ export class PreparedIssuer {
|
|
|
1089
1197
|
const proof = newProof('delivery@1', this.#key);
|
|
1090
1198
|
proof.value = sign(null, signedBytes('ceru/delivery@1', { payload, signature: { ...proof, value: '' } }), this.#key).toString('base64');
|
|
1091
1199
|
const head = encodeHeader({ ...this.#header, delivery: { payload, signature: proof } });
|
|
1092
|
-
ensure(head.length + this.#core.length <=
|
|
1200
|
+
ensure(head.length + this.#core.length <= artifactSizeLimit(this.#header.manifest), 'Issued file exceeds limit');
|
|
1093
1201
|
return head;
|
|
1094
1202
|
}
|
|
1095
1203
|
issue(personalization, options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shiqianjiang/ceru-plugin-issuer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Static verification, Ed25519 signing and cached personalized issuance of Ceru single-JS plugins",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -23,9 +23,10 @@
|
|
|
23
23
|
"node": ">=22.12.0"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@shiqianjiang/ceru-plugin-sdk": "0.
|
|
26
|
+
"@shiqianjiang/ceru-plugin-sdk": "3.0.0",
|
|
27
27
|
"acorn": "^8.18.0",
|
|
28
|
-
"ajv": "^8.20.0"
|
|
28
|
+
"ajv": "^8.20.0",
|
|
29
|
+
"semver": "^7.7.0"
|
|
29
30
|
},
|
|
30
31
|
"publishConfig": {
|
|
31
32
|
"access": "public",
|