@shiqianjiang/ceru-plugin-issuer 0.1.0 → 0.2.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/LICENSE +21 -21
- package/README.md +4 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +323 -25
- package/package.json +49 -49
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Ceru Music contributors
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
THE SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ceru Music contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Node.js / TypeScript 静态验证、Ed25519 签名与缓存模板发放。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
```ts
|
|
6
6
|
import { readFile } from 'node:fs/promises'
|
|
7
7
|
import { PreparedIssuer, readArtifact } from '@shiqianjiang/ceru-plugin-issuer'
|
|
8
8
|
|
|
@@ -13,10 +13,12 @@ const issuer = new PreparedIssuer(await readFile('template.js'), {
|
|
|
13
13
|
|
|
14
14
|
const bytes = issuer.issue({ display: { name: '我的音源' } })
|
|
15
15
|
console.log(readArtifact(bytes).signatureStatus)
|
|
16
|
-
|
|
16
|
+
```
|
|
17
17
|
|
|
18
18
|
准备一次后,重复 issue 不重新构建或扫描核心代码。writeTo 支持背压与共享主体流式输出,调用者负责结束流、下载鉴权和缓存策略。
|
|
19
19
|
|
|
20
20
|
签名有效不等于发布者已被信任;未提供可信公钥时结果为 verified-untrusted。静态校验不执行插件,也不替代生产沙箱。个性化文件不得提交到公开社区仓库。
|
|
21
21
|
|
|
22
|
+
0.2.0 静态读取 `exports.manifest` / `exports.package`,并从 `exports.activate`、`exports.surfaces`、`exports.modules` 提取运行入口。旧 `CeruPlugin.define()` v2 容器仍可验证,但会返回迁移提示;v1 注释头只用于识别迁移来源,不能绕过 v2 Manifest 和权限模型直接运行。
|
|
23
|
+
|
|
22
24
|
[完整协议与命令](https://github.com/CeruMusic/CeruMusic-Plugin-Cli#readme)
|
package/dist/index.d.ts
CHANGED
|
@@ -52,6 +52,8 @@ export interface Artifact {
|
|
|
52
52
|
codeDigest: string;
|
|
53
53
|
templateDigest?: string;
|
|
54
54
|
signatureStatus: 'unsigned' | 'verified-untrusted' | 'verified-trusted';
|
|
55
|
+
sourceFormat: 'exports-v2' | 'ceru-plugin-define-v2';
|
|
56
|
+
migrationWarnings: string[];
|
|
55
57
|
}
|
|
56
58
|
export interface ValidationOptions {
|
|
57
59
|
trustedPublicKeys?: string[];
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Readable } from 'node:stream';
|
|
|
3
3
|
import { pipeline } from 'node:stream/promises';
|
|
4
4
|
import { parse, parseExpressionAt } from 'acorn';
|
|
5
5
|
import { Ajv } from 'ajv';
|
|
6
|
-
import { PERMISSION_NAMES } from '@shiqianjiang/ceru-plugin-sdk/catalog';
|
|
6
|
+
import { HOST_MODULE_NAMES, PERMISSION_NAMES } from '@shiqianjiang/ceru-plugin-sdk/catalog';
|
|
7
7
|
export const FORMAT_VERSION = 2;
|
|
8
8
|
export const LIMITS = {
|
|
9
9
|
file: 10 * 1024 * 1024,
|
|
@@ -147,6 +147,109 @@ export const MANIFEST_SCHEMA = object({
|
|
|
147
147
|
},
|
|
148
148
|
}),
|
|
149
149
|
contributes: object({
|
|
150
|
+
menus: {
|
|
151
|
+
type: 'array',
|
|
152
|
+
maxItems: 64,
|
|
153
|
+
items: object({
|
|
154
|
+
id,
|
|
155
|
+
title: string,
|
|
156
|
+
commandId: id,
|
|
157
|
+
slot: {
|
|
158
|
+
enum: [
|
|
159
|
+
'playlist.import',
|
|
160
|
+
'playlist.actions',
|
|
161
|
+
'track.actions',
|
|
162
|
+
'player.actions',
|
|
163
|
+
'search.tools',
|
|
164
|
+
],
|
|
165
|
+
},
|
|
166
|
+
icon: {
|
|
167
|
+
oneOf: [
|
|
168
|
+
object({ kind: { const: 'host' }, name: string }, ['kind', 'name']),
|
|
169
|
+
object({ kind: { const: 'asset' }, resource: id }, ['kind', 'resource']),
|
|
170
|
+
],
|
|
171
|
+
},
|
|
172
|
+
when: object({
|
|
173
|
+
kinds: { type: 'array', items: { enum: ['track', 'playlist'] } },
|
|
174
|
+
loggedIn: { type: 'boolean' },
|
|
175
|
+
}),
|
|
176
|
+
}, ['id', 'slot', 'title', 'commandId']),
|
|
177
|
+
},
|
|
178
|
+
homeSections: {
|
|
179
|
+
type: 'array',
|
|
180
|
+
maxItems: 32,
|
|
181
|
+
items: object({
|
|
182
|
+
id,
|
|
183
|
+
title: string,
|
|
184
|
+
kind: { enum: ['playlists', 'charts', 'custom'] },
|
|
185
|
+
icon: {
|
|
186
|
+
oneOf: [
|
|
187
|
+
object({ kind: { const: 'host' }, name: string }, ['kind', 'name']),
|
|
188
|
+
object({ kind: { const: 'asset' }, resource: id }, ['kind', 'resource']),
|
|
189
|
+
],
|
|
190
|
+
},
|
|
191
|
+
view: id,
|
|
192
|
+
providerIds: strings,
|
|
193
|
+
order: { type: 'integer', minimum: -1000, maximum: 1000 },
|
|
194
|
+
}, ['id', 'title', 'kind']),
|
|
195
|
+
},
|
|
196
|
+
uiExtensions: {
|
|
197
|
+
type: 'array',
|
|
198
|
+
maxItems: 64,
|
|
199
|
+
items: object({
|
|
200
|
+
id,
|
|
201
|
+
slot: {
|
|
202
|
+
enum: [
|
|
203
|
+
'home.header',
|
|
204
|
+
'home.content.before',
|
|
205
|
+
'home.content.after',
|
|
206
|
+
'search.source-selector.after',
|
|
207
|
+
'playlist.header.actions',
|
|
208
|
+
'playlist.item.actions',
|
|
209
|
+
'player.actions',
|
|
210
|
+
'settings.sections',
|
|
211
|
+
],
|
|
212
|
+
},
|
|
213
|
+
mode: { enum: ['append', 'prepend', 'wrap', 'replace'] },
|
|
214
|
+
view: id,
|
|
215
|
+
order: { type: 'integer', minimum: -1000, maximum: 1000 },
|
|
216
|
+
when: object({ loggedIn: { type: 'boolean' }, route: string }),
|
|
217
|
+
}, ['id', 'slot', 'mode', 'view']),
|
|
218
|
+
},
|
|
219
|
+
styles: {
|
|
220
|
+
type: 'array',
|
|
221
|
+
maxItems: 64,
|
|
222
|
+
items: object({
|
|
223
|
+
id,
|
|
224
|
+
resource: id,
|
|
225
|
+
scope: { enum: ['surface', 'slot', 'application'] },
|
|
226
|
+
slots: {
|
|
227
|
+
type: 'array',
|
|
228
|
+
maxItems: 16,
|
|
229
|
+
items: {
|
|
230
|
+
enum: [
|
|
231
|
+
'home.header',
|
|
232
|
+
'home.content.before',
|
|
233
|
+
'home.content.after',
|
|
234
|
+
'search.source-selector.after',
|
|
235
|
+
'playlist.header.actions',
|
|
236
|
+
'playlist.item.actions',
|
|
237
|
+
'player.actions',
|
|
238
|
+
'settings.sections',
|
|
239
|
+
],
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
order: { type: 'integer', minimum: -1000, maximum: 1000 },
|
|
243
|
+
}, ['id', 'resource', 'scope']),
|
|
244
|
+
},
|
|
245
|
+
playlistImporters: {
|
|
246
|
+
type: 'array',
|
|
247
|
+
maxItems: 64,
|
|
248
|
+
items: object({ id, title: string, description: string, placeholder: string }, [
|
|
249
|
+
'id',
|
|
250
|
+
'title',
|
|
251
|
+
]),
|
|
252
|
+
},
|
|
150
253
|
providers: {
|
|
151
254
|
type: 'array',
|
|
152
255
|
maxItems: 64,
|
|
@@ -226,6 +329,8 @@ export function validateManifest(value) {
|
|
|
226
329
|
const unique = (values, label) => ensure(new Set(values).size === values.length, 'Duplicate ' + label);
|
|
227
330
|
unique(manifest.permissions?.map((p) => p.key) ?? [], 'permission key');
|
|
228
331
|
unique(manifest.modules.surfaces?.map((p) => p.id) ?? [], 'surface id');
|
|
332
|
+
for (const menu of manifest.contributes?.menus ?? [])
|
|
333
|
+
ensure(manifest.contributes?.commands?.some((command) => command.id === menu.commandId), 'Unknown menu command: ' + menu.commandId);
|
|
229
334
|
for (const items of Object.values(manifest.contributes ?? {}))
|
|
230
335
|
unique(items.map((p) => p.id), 'contribution id');
|
|
231
336
|
const views = new Set(manifest.modules.surfaces?.map((p) => p.id));
|
|
@@ -238,6 +343,24 @@ export function validateManifest(value) {
|
|
|
238
343
|
if (item.view)
|
|
239
344
|
ensure(views.has(item.view), 'Unknown view: ' + item.view);
|
|
240
345
|
}
|
|
346
|
+
for (const section of manifest.contributes?.homeSections ?? []) {
|
|
347
|
+
if (section.kind === 'custom')
|
|
348
|
+
ensure(section.view && views.has(section.view), 'Custom home section requires a valid view');
|
|
349
|
+
else
|
|
350
|
+
ensure(!section.view, 'Built-in home sections cannot replace the Host view');
|
|
351
|
+
for (const providerId of section.providerIds ?? [])
|
|
352
|
+
ensure(manifest.contributes?.providers?.some((provider) => provider.id === providerId), 'Unknown home section provider: ' + providerId);
|
|
353
|
+
}
|
|
354
|
+
for (const extension of manifest.contributes?.uiExtensions ?? [])
|
|
355
|
+
if (extension.mode === 'wrap')
|
|
356
|
+
ensure(manifest.modules.surfaces?.some((surface) => surface.id === extension.view && surface.kind === 'schema'), 'Wrap UI extensions require a schema view with a host-content node');
|
|
357
|
+
else
|
|
358
|
+
ensure(views.has(extension.view), 'Unknown UI extension view: ' + extension.view);
|
|
359
|
+
for (const style of manifest.contributes?.styles ?? []) {
|
|
360
|
+
ensure(style.scope !== 'slot' || style.slots?.length, 'Slot style requires slots');
|
|
361
|
+
ensure(style.scope !== 'application' ||
|
|
362
|
+
manifest.permissions?.some((permission) => permission.name === 'ui.styles.global'), 'Application styles require ui.styles.global');
|
|
363
|
+
}
|
|
241
364
|
if (manifest.contributes?.guestAdapters?.length)
|
|
242
365
|
ensure(manifest.guestPolicy, 'guestPolicy is required for a guest adapter');
|
|
243
366
|
}
|
|
@@ -296,9 +419,13 @@ function checkProof(proof, data) {
|
|
|
296
419
|
ensure(verify(null, data, key, Buffer.from(proof.value, 'base64')), 'Signature verification failed');
|
|
297
420
|
}
|
|
298
421
|
export function encodeHeader(header) {
|
|
299
|
-
const
|
|
300
|
-
const head = Buffer.from(
|
|
301
|
-
|
|
422
|
+
const { manifest, ...metadata } = header;
|
|
423
|
+
const head = Buffer.from('exports.manifest = ' +
|
|
424
|
+
JSON.stringify(manifest, null, 2) +
|
|
425
|
+
';\nexports.package = ' +
|
|
426
|
+
JSON.stringify(metadata, null, 2) +
|
|
427
|
+
';\n');
|
|
428
|
+
ensure(head.length <= LIMITS.header, 'Artifact metadata is too large');
|
|
302
429
|
return head;
|
|
303
430
|
}
|
|
304
431
|
export function encodeArtifact(header, body) {
|
|
@@ -386,6 +513,15 @@ function inspectBody(body, manifest) {
|
|
|
386
513
|
const node = pending.pop();
|
|
387
514
|
ensure(++count <= LIMITS.nodes, 'Too many AST nodes');
|
|
388
515
|
ensure(node.type !== 'ImportExpression', 'External/dynamic import is not allowed in the final single-file artifact');
|
|
516
|
+
if (node.type === 'CallExpression' &&
|
|
517
|
+
node.callee?.type === 'Identifier' &&
|
|
518
|
+
node.callee.name === 'require') {
|
|
519
|
+
ensure(node.arguments.length === 1 &&
|
|
520
|
+
node.arguments[0].type === 'Literal' &&
|
|
521
|
+
typeof node.arguments[0].value === 'string', 'require() must use one literal Host module name');
|
|
522
|
+
ensure(HOST_MODULE_NAMES.includes(node.arguments[0].value), 'Hand-written artifacts may require only documented Host modules: ' +
|
|
523
|
+
node.arguments[0].value);
|
|
524
|
+
}
|
|
389
525
|
for (const value of Object.values(node)) {
|
|
390
526
|
if (Array.isArray(value))
|
|
391
527
|
for (const child of value) {
|
|
@@ -396,24 +532,108 @@ function inspectBody(body, manifest) {
|
|
|
396
532
|
pending.push(value);
|
|
397
533
|
}
|
|
398
534
|
}
|
|
399
|
-
|
|
400
|
-
const
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
535
|
+
let registry;
|
|
536
|
+
const preamble = [];
|
|
537
|
+
const functions = new Map();
|
|
538
|
+
let sourceFormat = 'exports-v2';
|
|
539
|
+
if (tree.body.length === 1 &&
|
|
540
|
+
tree.body[0].type === 'ExpressionStatement' &&
|
|
541
|
+
tree.body[0].expression.type === 'CallExpression') {
|
|
542
|
+
// Compatibility with the original v2 registration container.
|
|
543
|
+
sourceFormat = 'ceru-plugin-define-v2';
|
|
544
|
+
const call = tree.body[0].expression;
|
|
545
|
+
ensure(call.arguments.length === 1 &&
|
|
546
|
+
call.callee.type === 'MemberExpression' &&
|
|
547
|
+
!call.callee.computed &&
|
|
548
|
+
!call.callee.optional &&
|
|
549
|
+
call.callee.object.name === 'CeruPlugin' &&
|
|
550
|
+
call.callee.property.name === 'define', 'Expected CeruPlugin.define');
|
|
551
|
+
registry = astObject(call.arguments[0]);
|
|
552
|
+
ensure(registry.size === 2 && registry.has('modules') && registry.has('resources'), 'Registration requires only modules and resources');
|
|
553
|
+
}
|
|
554
|
+
else {
|
|
555
|
+
const exported = new Map();
|
|
556
|
+
for (const statement of tree.body) {
|
|
557
|
+
if (statement.type === 'FunctionDeclaration') {
|
|
558
|
+
ensure(statement.id?.name && !statement.generator, 'Invalid helper function');
|
|
559
|
+
functions.set(statement.id.name, statement);
|
|
560
|
+
preamble.push(body.slice(statement.start, statement.end));
|
|
561
|
+
continue;
|
|
562
|
+
}
|
|
563
|
+
if (statement.type === 'VariableDeclaration') {
|
|
564
|
+
for (const declaration of statement.declarations) {
|
|
565
|
+
const init = declaration.init;
|
|
566
|
+
const isFunction = init && ['FunctionExpression', 'ArrowFunctionExpression'].includes(init.type);
|
|
567
|
+
const isRequire = init?.type === 'CallExpression' &&
|
|
568
|
+
init.callee?.name === 'require' &&
|
|
569
|
+
init.arguments.length === 1 &&
|
|
570
|
+
typeof init.arguments[0]?.value === 'string';
|
|
571
|
+
const isStatic = init && ['Literal', 'ObjectExpression', 'ArrayExpression'].includes(init.type);
|
|
572
|
+
ensure(isFunction || isRequire || isStatic, 'Top-level variables must be static data, functions, or require() imports');
|
|
573
|
+
if (isStatic)
|
|
574
|
+
astJson(init);
|
|
575
|
+
if (declaration.id.type === 'Identifier' && isFunction)
|
|
576
|
+
functions.set(declaration.id.name, init);
|
|
577
|
+
}
|
|
578
|
+
preamble.push(body.slice(statement.start, statement.end));
|
|
579
|
+
continue;
|
|
580
|
+
}
|
|
581
|
+
ensure(statement.type === 'ExpressionStatement', 'Invalid top-level statement');
|
|
582
|
+
const expression = statement.expression;
|
|
583
|
+
const left = expression.left;
|
|
584
|
+
ensure(expression.type === 'AssignmentExpression' &&
|
|
585
|
+
expression.operator === '=' &&
|
|
586
|
+
left.type === 'MemberExpression' &&
|
|
587
|
+
!left.computed &&
|
|
588
|
+
left.object.name === 'exports', 'Expected exports assignment');
|
|
589
|
+
const key = left.property.name;
|
|
590
|
+
ensure(['modules', 'activate', 'surfaces', 'resources'].includes(key) && !exported.has(key), 'Unknown or duplicate export: ' + key);
|
|
591
|
+
exported.set(key, expression.right);
|
|
592
|
+
}
|
|
593
|
+
const properties = [];
|
|
594
|
+
const addModule = (key, node) => properties.push({
|
|
595
|
+
type: 'Property',
|
|
596
|
+
kind: 'init',
|
|
597
|
+
computed: false,
|
|
598
|
+
method: false,
|
|
599
|
+
shorthand: false,
|
|
600
|
+
key: { type: 'Literal', value: key },
|
|
601
|
+
value: node,
|
|
602
|
+
});
|
|
603
|
+
if (exported.has('modules'))
|
|
604
|
+
for (const [key, node] of astObject(exported.get('modules')))
|
|
605
|
+
addModule(key, node);
|
|
606
|
+
if (exported.has('activate')) {
|
|
607
|
+
ensure(manifest.modules.logic, 'activate requires modules.logic');
|
|
608
|
+
addModule(manifest.modules.logic.entry, exported.get('activate'));
|
|
609
|
+
}
|
|
610
|
+
if (exported.has('surfaces'))
|
|
611
|
+
for (const [id, node] of astObject(exported.get('surfaces'))) {
|
|
612
|
+
const surface = manifest.modules.surfaces?.find((item) => item.id === id && item.kind === 'web');
|
|
613
|
+
ensure(surface, 'Unknown visible surface: ' + id);
|
|
614
|
+
addModule(surface.entry, node);
|
|
615
|
+
}
|
|
616
|
+
registry = new Map([
|
|
617
|
+
['modules', { type: 'ObjectExpression', properties }],
|
|
618
|
+
['resources', exported.get('resources') ?? { type: 'ObjectExpression', properties: [] }],
|
|
619
|
+
]);
|
|
620
|
+
}
|
|
409
621
|
const modules = Object.create(null);
|
|
410
|
-
for (const [key,
|
|
622
|
+
for (const [key, exportedNode] of astObject(registry.get('modules'))) {
|
|
623
|
+
const node = exportedNode.type === 'Identifier' ? functions.get(exportedNode.name) : exportedNode;
|
|
624
|
+
ensure(node, 'Export references an unknown function');
|
|
411
625
|
ensure(new RegExp(ID).test(key), 'Invalid module id: ' + key);
|
|
412
|
-
ensure(
|
|
626
|
+
ensure(['FunctionExpression', 'FunctionDeclaration', 'ArrowFunctionExpression'].includes(node.type) &&
|
|
413
627
|
!node.generator &&
|
|
414
|
-
node.params.length
|
|
415
|
-
node.params[0].type === 'Identifier', 'Module must be a function with one context parameter');
|
|
416
|
-
modules[key] =
|
|
628
|
+
node.params.length <= 1 &&
|
|
629
|
+
(!node.params.length || node.params[0].type === 'Identifier'), 'Module must be a function with one context parameter');
|
|
630
|
+
modules[key] = preamble.length
|
|
631
|
+
? 'async function(ctx) {\n' +
|
|
632
|
+
preamble.join('\n') +
|
|
633
|
+
'\nreturn (' +
|
|
634
|
+
body.slice(exportedNode.start, exportedNode.end) +
|
|
635
|
+
')(ctx);\n}'
|
|
636
|
+
: body.slice(node.start, node.end);
|
|
417
637
|
}
|
|
418
638
|
ensure(Object.keys(modules).length <= 128, 'Too many modules');
|
|
419
639
|
const resources = astJson(registry.get('resources'));
|
|
@@ -456,23 +676,101 @@ function inspectBody(body, manifest) {
|
|
|
456
676
|
for (const provider of manifest.contributes?.providers ?? [])
|
|
457
677
|
if (provider.icon?.kind === 'asset')
|
|
458
678
|
ensure(Object.hasOwn(resources, provider.icon.resource), 'Missing icon resource');
|
|
679
|
+
for (const style of manifest.contributes?.styles ?? []) {
|
|
680
|
+
const resource = resources[style.resource];
|
|
681
|
+
ensure(resource?.type === 'text', 'Style contribution requires a text resource');
|
|
682
|
+
ensure(!/@import\b|url\s*\(\s*(?!["']?data:)|expression\s*\(|behavior\s*:/i.test(resource.value), 'Style contribution cannot load external resources or executable CSS');
|
|
683
|
+
}
|
|
459
684
|
for (const entry of Object.keys(modules))
|
|
460
685
|
ensure(declared.has(entry), 'Undeclared module: ' + entry);
|
|
461
|
-
return {
|
|
686
|
+
return {
|
|
687
|
+
modules,
|
|
688
|
+
resources,
|
|
689
|
+
sourceFormat,
|
|
690
|
+
migrationWarnings: sourceFormat === 'ceru-plugin-define-v2'
|
|
691
|
+
? ['This plugin uses the legacy CeruPlugin.define container; rebuild it as exports.*.']
|
|
692
|
+
: [],
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
function legacyCommentArtifact(text) {
|
|
696
|
+
const comment = /^\/\*!([\s\S]*?)\*\//.exec(text)?.[1];
|
|
697
|
+
if (!comment || !/@name\s+(.+)/.test(comment) || !/@version\s+(.+)/.test(comment))
|
|
698
|
+
return;
|
|
699
|
+
const value = (name) => new RegExp('@' + name + '\\s+([^\\r\\n*]+)').exec(comment)?.[1]?.trim() ?? '';
|
|
700
|
+
const name = value('name');
|
|
701
|
+
const version = value('version').replace(/^v/, '');
|
|
702
|
+
const id = value('id') ||
|
|
703
|
+
'legacy.' +
|
|
704
|
+
name
|
|
705
|
+
.toLowerCase()
|
|
706
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
707
|
+
.replace(/^-|-$/g, '');
|
|
708
|
+
if (!id || !/^\d+\.\d+\.\d+/.test(version))
|
|
709
|
+
return;
|
|
710
|
+
return {
|
|
711
|
+
formatVersion: 2,
|
|
712
|
+
syntax: 'js',
|
|
713
|
+
manifest: {
|
|
714
|
+
manifestVersion: 2,
|
|
715
|
+
id,
|
|
716
|
+
name,
|
|
717
|
+
version,
|
|
718
|
+
description: value('description'),
|
|
719
|
+
author: value('author'),
|
|
720
|
+
engines: { hostApi: '^2.0.0', logicRuntime: 'legacy-comment@1' },
|
|
721
|
+
modules: {},
|
|
722
|
+
},
|
|
723
|
+
signature: null,
|
|
724
|
+
};
|
|
462
725
|
}
|
|
463
726
|
export function readArtifact(input, options = {}) {
|
|
464
727
|
const bytes = typeof input === 'string' ? Buffer.from(input) : input;
|
|
465
728
|
ensure(bytes.byteLength <= LIMITS.file, 'Artifact exceeds size limit');
|
|
466
729
|
const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
730
|
+
let header;
|
|
731
|
+
let body;
|
|
732
|
+
if (text.startsWith(START)) {
|
|
733
|
+
const end = text.indexOf(END, START.length);
|
|
734
|
+
ensure(end > 0 && Buffer.byteLength(text.slice(0, end)) <= LIMITS.header, 'Invalid static header boundary');
|
|
735
|
+
header = parseJsonStrict(text.slice(START.length, end));
|
|
736
|
+
body = text.slice(end + END.length);
|
|
737
|
+
}
|
|
738
|
+
else {
|
|
739
|
+
// Read only JSON-compatible literal metadata. Never run source to display permissions.
|
|
740
|
+
let offset = 0;
|
|
741
|
+
function assignment(name) {
|
|
742
|
+
const match = new RegExp('^\\s*exports\\.' + name + '\\s*=\\s*').exec(text.slice(offset));
|
|
743
|
+
if (!match)
|
|
744
|
+
return undefined;
|
|
745
|
+
const start = offset + match[0].length;
|
|
746
|
+
const node = parseExpressionAt(text, start, { ecmaVersion: 2022 });
|
|
747
|
+
const tail = text.slice(node.end);
|
|
748
|
+
const terminated = /^[ \t]*;[ \t]*(?:\r?\n)?/.exec(tail);
|
|
749
|
+
const asi = /^[ \t]*\r?\n/.exec(tail);
|
|
750
|
+
ensure(terminated || asi, 'Metadata assignments must end at a statement boundary');
|
|
751
|
+
offset = node.end + (terminated ?? asi)[0].length;
|
|
752
|
+
ensure(Buffer.byteLength(text.slice(0, offset)) <= LIMITS.header, 'Artifact metadata is too large');
|
|
753
|
+
return node;
|
|
754
|
+
}
|
|
755
|
+
const manifestNode = assignment('manifest');
|
|
756
|
+
if (!manifestNode) {
|
|
757
|
+
const legacy = legacyCommentArtifact(text);
|
|
758
|
+
ensure(!legacy, 'Legacy comment-header plugins are recognized for migration metadata only; convert them to exports.manifest/exports.activate before installation.');
|
|
759
|
+
}
|
|
760
|
+
ensure(manifestNode, 'Expected exports.manifest = { ... };');
|
|
761
|
+
const manifest = astJson(manifestNode);
|
|
762
|
+
const packageNode = assignment('package');
|
|
763
|
+
const metadata = packageNode
|
|
764
|
+
? astJson(packageNode)
|
|
765
|
+
: { formatVersion: 2, syntax: 'js', signature: null };
|
|
766
|
+
ensure(plain(metadata) && !Object.hasOwn(metadata, 'manifest'), 'Invalid package metadata');
|
|
767
|
+
header = { ...metadata, manifest };
|
|
768
|
+
body = text.slice(offset);
|
|
769
|
+
}
|
|
471
770
|
exactKeys(header, ['formatVersion', 'syntax', 'manifest', 'signature', 'template', 'delivery'], 'header');
|
|
472
771
|
ensure(header.formatVersion === 2 && header.syntax === 'js', 'Unsupported artifact format/syntax');
|
|
473
772
|
ensure(Object.hasOwn(header, 'signature'), 'Signature field is required');
|
|
474
773
|
validateManifest(header.manifest);
|
|
475
|
-
const body = text.slice(end + END.length);
|
|
476
774
|
const codeDigest = digest(body);
|
|
477
775
|
let signatureStatus = 'unsigned';
|
|
478
776
|
let templateDigest;
|
package/package.json
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@shiqianjiang/ceru-plugin-issuer",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Static verification, Ed25519 signing and cached personalized issuance of Ceru single-JS plugins",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "./dist/index.js",
|
|
7
|
-
"types": "./dist/index.d.ts",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"types": "./dist/index.d.ts",
|
|
11
|
-
"import": "./dist/index.js",
|
|
12
|
-
"default": "./dist/index.js"
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
"files": [
|
|
16
|
-
"dist",
|
|
17
|
-
"README.md",
|
|
18
|
-
"LICENSE"
|
|
19
|
-
],
|
|
20
|
-
"license": "MIT",
|
|
21
|
-
"author": "澜音团队",
|
|
22
|
-
"engines": {
|
|
23
|
-
"node": ">=22.12.0"
|
|
24
|
-
},
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"@shiqianjiang/ceru-plugin-sdk": "0.
|
|
27
|
-
"acorn": "^8.18.0",
|
|
28
|
-
"ajv": "^8.20.0"
|
|
29
|
-
},
|
|
30
|
-
"publishConfig": {
|
|
31
|
-
"access": "public",
|
|
32
|
-
"registry": "https://registry.npmjs.org/"
|
|
33
|
-
},
|
|
34
|
-
"repository": {
|
|
35
|
-
"type": "git",
|
|
36
|
-
"url": "git+https://github.com/CeruMusic/CeruMusic-Plugin-Cli.git",
|
|
37
|
-
"directory": "packages/issuer"
|
|
38
|
-
},
|
|
39
|
-
"bugs": {
|
|
40
|
-
"url": "https://github.com/CeruMusic/CeruMusic-Plugin-Cli/issues"
|
|
41
|
-
},
|
|
42
|
-
"homepage": "https://github.com/CeruMusic/CeruMusic-Plugin-Cli#readme",
|
|
43
|
-
"keywords": [
|
|
44
|
-
"ceru-music",
|
|
45
|
-
"plugin",
|
|
46
|
-
"typescript",
|
|
47
|
-
"electron"
|
|
48
|
-
]
|
|
49
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@shiqianjiang/ceru-plugin-issuer",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Static verification, Ed25519 signing and cached personalized issuance of Ceru single-JS plugins",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": "澜音团队",
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=22.12.0"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@shiqianjiang/ceru-plugin-sdk": "0.2.0",
|
|
27
|
+
"acorn": "^8.18.0",
|
|
28
|
+
"ajv": "^8.20.0"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public",
|
|
32
|
+
"registry": "https://registry.npmjs.org/"
|
|
33
|
+
},
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/CeruMusic/CeruMusic-Plugin-Cli.git",
|
|
37
|
+
"directory": "packages/issuer"
|
|
38
|
+
},
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/CeruMusic/CeruMusic-Plugin-Cli/issues"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/CeruMusic/CeruMusic-Plugin-Cli#readme",
|
|
43
|
+
"keywords": [
|
|
44
|
+
"ceru-music",
|
|
45
|
+
"plugin",
|
|
46
|
+
"typescript",
|
|
47
|
+
"electron"
|
|
48
|
+
]
|
|
49
|
+
}
|