@volumio/plugin-sdk 0.3.1 → 0.3.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @volumio/plugin-sdk
2
2
 
3
- The Volumio plugin manifest v2 (`volumio-plugin.json`), its JSON Schema, and the `volumio-plugin` CLI.
3
+ The Volumio plugin manifest (`volumio-plugin.json`), its JSON Schema, and the `volumio-plugin` CLI.
4
4
 
5
5
  ## A new plugin
6
6
 
@@ -19,7 +19,7 @@ Every new plugin carries instructions for coding agents, so that someone who doe
19
19
 
20
20
  `AGENTS.md` stays the same across plugin APIs. `VOLUMIO_API.md` is the one file that changes with the API: a test fails when the schema's `engines.api` and the file's title disagree.
21
21
 
22
- The developer edits only `volumio-plugin.json`: `package` writes `name`, `version`, `description`, `license`, `engines.volumio` and `volumio_info` into the `package.json` that ships, which is what Volumio reads today. `engines.api` is `"1"`: the code follows the plugin API Volumio runs today; `"2"` is kept for framework v2.
22
+ The developer edits only `volumio-plugin.json`: `package` writes `name`, `version`, `description`, `license`, `engines.volumio` and `volumio_info` into the `package.json` that ships, which is what Volumio reads today. `engines.api` is `"1"`, the plugin API Volumio runs. Here a v1 plugin has only a `package.json` and a v2 plugin has a `volumio-plugin.json`: both run on that same API.
23
23
 
24
24
  ## Checks
25
25
 
@@ -82,7 +82,7 @@ A plugin repository builds its release with the reusable workflow:
82
82
  ```yaml
83
83
  jobs:
84
84
  build:
85
- uses: VolumioTeam/volumio-plugin-sdk/.github/workflows/build.yml@v0.3.1
85
+ uses: volumio/volumio-plugin-sdk/.github/workflows/build.yml@v0.3.2
86
86
  with:
87
87
  path: . # plugin folder inside the repository
88
88
  ```
@@ -108,19 +108,12 @@ It prints the findings, the zip and its sha256 on stdout (npm's output goes to s
108
108
  | `G3.native-arch` | Every package with `.node` modules has one built for the target architecture, and its `build/` ones all are |
109
109
  | `G3.lockfile` | `package-lock.json` is committed; a warning for v1 plugins |
110
110
 
111
- ## Signing
112
-
113
- The store signs each release it accepts: `<zip>.sig` is a [DSSE](https://github.com/secure-systems-lab/dsse) envelope whose payload (`volumio.plugin.release/v1`) binds the zip's sha256 to the plugin id, version, architecture and source commit, signed with Ed25519. The device trusts two keys, the active one and the next, so rotating the key needs no device update. `src/sign.js` (`@volumio/plugin-sdk/sign`) uses only Node's `crypto`; the device verifier follows it and is tested against envelopes it signs. Key ids use letters, digits, dot, dash and underscore.
114
-
115
- ```bash
116
- volumio-plugin sign <zip> --key <private.pem> --key-id <id> # development key; the store signs with its KMS key
117
- volumio-plugin verify <zip> --key <id>=<public.pem> [--key ...]
118
- ```
119
-
120
111
  ## Releasing
121
112
 
122
113
  Bump `version` in `package.json` and the `sdk-ref` default in `.github/workflows/build.yml` together (a test fails otherwise), merge, then tag `v<version>` on `main`. Release tags cannot be moved or deleted. Plugin repositories call the workflow at a tag, never at `main`; actions are pinned by commit and the build image by digest.
123
114
 
115
+ Publishing the GitHub release publishes the same version to npm (`.github/workflows/publish.yml`), after the tests and a check that the tag is `v` plus the package version. It uses npm trusted publishing: no npm token is stored, the package on npmjs.com trusts this repository's `publish.yml`, and every version carries a provenance attestation. The first version was published by hand, because npm sets a trusted publisher only on a package that already exists.
116
+
124
117
  ```bash
125
118
  npm test
126
119
  ```
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { spawnSync } from 'node:child_process';
3
- import { createHash } from 'node:crypto';
4
- import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { mkdtempSync, rmSync } from 'node:fs';
5
4
  import { tmpdir } from 'node:os';
6
5
  import { join } from 'node:path';
7
6
  import { setTimeout as sleep } from 'node:timers/promises';
@@ -10,7 +9,6 @@ import { check, load } from '../src/check.js';
10
9
  import { deploy, followLog } from '../src/deploy.js';
11
10
  import { initPlugin } from '../src/init.js';
12
11
  import { declaredArches, packagePlugin } from '../src/package.js';
13
- import { localSigner, releaseStatement, signRelease, verifyRelease } from '../src/sign.js';
14
12
 
15
13
  const USAGE = `Usage:
16
14
  volumio-plugin init <dir> --id <id> --type <type> --function <function> --title <title> --description <text> [--author <name>] [--skip-install]
@@ -19,8 +17,6 @@ const USAGE = `Usage:
19
17
  volumio-plugin arch [plugin-dir]
20
18
  volumio-plugin deploy <device> [plugin-dir] [--zip <zip>]
21
19
  volumio-plugin logs <device> [--seconds <n>]
22
- volumio-plugin sign <zip> --key <private.pem> --key-id <id>
23
- volumio-plugin verify <zip> --key <id>=<public.pem> [--key ...]
24
20
  `;
25
21
 
26
22
  const print = (result) => {
@@ -39,13 +35,6 @@ const usage = () => {
39
35
  process.stderr.write(USAGE);
40
36
  return 2;
41
37
  };
42
- const sha256Of = (file) => createHash('sha256').update(readFileSync(file)).digest('hex');
43
- // <id>=<public.pem>
44
- const trustedKey = (arg) => {
45
- const i = arg.indexOf('=');
46
- if (i < 1) throw new Error(`--key takes <key-id>=<public-key.pem>, got ${arg}`);
47
- return [arg.slice(0, i), readFileSync(arg.slice(i + 1), 'utf8')];
48
- };
49
38
 
50
39
  // The commit time keeps the zip reproducible; CI may set SOURCE_DATE_EPOCH instead.
51
40
  const epochOf = (dir) => {
@@ -154,27 +143,6 @@ const commands = {
154
143
  process.stdout.write(`${JSON.stringify(declaredArches(parse(args).positionals[0] ?? '.'))}\n`);
155
144
  return 0;
156
145
  },
157
- // A development key: the store signs releases with its KMS key.
158
- sign(args) {
159
- const { values, positionals: [zip] } = parse(args, { key: { type: 'string' }, 'key-id': { type: 'string' } });
160
- const { key, 'key-id': keyId } = values;
161
- if (!zip || !key || !keyId) return usage();
162
- const provenance = JSON.parse(readFileSync(zip.replace(/\.zip$/, '.provenance.json'), 'utf8'));
163
- const statement = releaseStatement({ ...provenance, sha256: sha256Of(zip) });
164
- const envelope = signRelease(statement, { keyId, sign: localSigner(readFileSync(key, 'utf8')) });
165
- writeFileSync(`${zip}.sig`, `${JSON.stringify(envelope, null, 2)}\n`);
166
- process.stdout.write(`${zip}.sig\n`);
167
- return 0;
168
- },
169
- verify(args) {
170
- const { values, positionals: [zip] } = parse(args, { key: { type: 'string', multiple: true, default: [] } });
171
- const keys = Object.fromEntries(values.key.map(trustedKey));
172
- if (!zip || !Object.keys(keys).length) return usage();
173
- const envelope = JSON.parse(readFileSync(`${zip}.sig`, 'utf8'));
174
- const statement = verifyRelease(envelope, { keys, sha256: sha256Of(zip) });
175
- process.stdout.write(`✔ ${statement.id} ${statement.version} ${statement.arch} signed by a trusted key\n`);
176
- return 0;
177
- },
178
146
  };
179
147
 
180
148
  const [command, ...args] = process.argv.slice(2);
package/package.json CHANGED
@@ -1,15 +1,14 @@
1
1
  {
2
2
  "name": "@volumio/plugin-sdk",
3
- "version": "0.3.1",
4
- "description": "Volumio plugin manifest v2: schema, v1 shim and the volumio-plugin CLI",
3
+ "version": "0.3.2",
4
+ "description": "Volumio plugin manifest (volumio-plugin.json): schema, v1 shim and the volumio-plugin CLI",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "volumio-plugin": "bin/volumio-plugin.js"
8
8
  },
9
9
  "exports": {
10
10
  ".": "./src/index.js",
11
- "./schema": "./schema/manifest.schema.json",
12
- "./sign": "./src/sign.js"
11
+ "./schema": "./schema/manifest.schema.json"
13
12
  },
14
13
  "files": [
15
14
  "bin",
@@ -25,6 +24,13 @@
25
24
  "node": ">=20"
26
25
  },
27
26
  "license": "MIT",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/volumio/volumio-plugin-sdk.git"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
28
34
  "dependencies": {
29
35
  "ajv": "^8.20.0",
30
36
  "eslint": "^9.39.5",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "https://volumio.com/schemas/plugin/manifest-v2.json",
4
- "title": "Volumio plugin manifest v2 (volumio-plugin.json)",
4
+ "title": "Volumio plugin manifest (volumio-plugin.json)",
5
5
  "type": "object",
6
6
  "additionalProperties": false,
7
7
  "required": ["id", "version", "type", "function", "title", "description", "engines", "arch", "permissions", "license"],
@@ -35,7 +35,7 @@
35
35
  "required": ["volumio", "api"],
36
36
  "properties": {
37
37
  "volumio": { "description": "semver range", "type": "string", "minLength": 1 },
38
- "api": { "description": "The plugin API the code is written for. 1: the one Volumio runs today (kew promises, commandRouter). 2 is kept for framework v2", "const": "1" }
38
+ "api": { "description": "The plugin API the code is written for: 1, the one Volumio runs (kew promises, commandRouter)", "const": "1" }
39
39
  }
40
40
  },
41
41
  "arch": {
package/src/sign.js DELETED
@@ -1,59 +0,0 @@
1
- // Signed plugin releases: a DSSE envelope (github.com/secure-systems-lab/dsse) around a statement
2
- // that binds the zip's sha256 to the plugin, version, architecture and source. Ed25519 keys.
3
- // Node's crypto only, so the device verifies with this same file.
4
- import { sign as cryptoSign, verify as cryptoVerify } from 'node:crypto';
5
-
6
- export const PAYLOAD_TYPE = 'application/vnd.volumio.plugin-release+json';
7
- const STATEMENT_TYPE = 'volumio.plugin.release/v1';
8
- // A key id is written in the envelope and named on the command line as <id>=<public.pem>.
9
- const KEY_ID = /^[A-Za-z0-9._-]{1,64}$/;
10
-
11
- /** @param {{ id: string, version: string, arch: string, sha256: string, source?: { repository?: string, commit?: string } }} provenance */
12
- export const releaseStatement = ({ id, version, arch, sha256, source = {} }) => ({
13
- _type: STATEMENT_TYPE,
14
- id,
15
- version,
16
- arch,
17
- sha256,
18
- source: { repository: source.repository, commit: source.commit },
19
- });
20
-
21
- /** DSSE v1 pre-authentication encoding: what the signature covers. */
22
- export const pae = (type, body) =>
23
- Buffer.concat([Buffer.from(`DSSEv1 ${Buffer.byteLength(type)} ${type} ${body.length} `), body]);
24
-
25
- /** @param {(bytes: Buffer) => Buffer} sign an Ed25519 signer: a local key in development, the KMS in the store */
26
- export function signRelease(statement, { keyId, sign }) {
27
- if (!KEY_ID.test(keyId ?? '')) throw new Error(`Invalid key id ${JSON.stringify(keyId)}: use letters, digits, dot, dash, underscore`);
28
- const body = Buffer.from(JSON.stringify(statement));
29
- return {
30
- payloadType: PAYLOAD_TYPE,
31
- payload: body.toString('base64'),
32
- signatures: [{ keyid: keyId, sig: sign(pae(PAYLOAD_TYPE, body)).toString('base64') }],
33
- };
34
- }
35
-
36
- /** @param {string} privateKeyPem PKCS#8 Ed25519 key */
37
- export const localSigner = (privateKeyPem) => (bytes) => cryptoSign(null, bytes, privateKeyPem);
38
-
39
- /**
40
- * Returns the signed statement when a trusted key signed it and it covers this zip; throws otherwise.
41
- * @param {{ payloadType?: string, payload?: string, signatures?: Array<{ keyid?: string, sig?: string }> }} envelope
42
- * @param {{ keys: Record<string, string>, sha256: string }} options keys: key id -> SPKI PEM public key
43
- */
44
- export function verifyRelease(envelope, { keys, sha256 }) {
45
- if (envelope?.payloadType !== PAYLOAD_TYPE) {
46
- throw new Error(`Not a Volumio plugin release: payload type ${envelope?.payloadType}`);
47
- }
48
- const body = Buffer.from(String(envelope.payload ?? ''), 'base64');
49
- const signed = pae(PAYLOAD_TYPE, body);
50
- const signatures = Array.isArray(envelope.signatures) ? envelope.signatures : [];
51
- const trusted = signatures.some((s) =>
52
- Object.hasOwn(keys, s?.keyid) && cryptoVerify(null, signed, keys[s.keyid], Buffer.from(String(s.sig), 'base64')));
53
- if (!trusted) throw new Error('No valid signature from a trusted Volumio key');
54
-
55
- const statement = JSON.parse(body.toString('utf8'));
56
- if (statement._type !== STATEMENT_TYPE) throw new Error(`Unknown release statement: ${statement._type}`);
57
- if (statement.sha256 !== sha256) throw new Error('The package sha256 does not match the signed release');
58
- return statement;
59
- }