glyph-server 0.7.0 → 0.8.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.
@@ -114,6 +114,7 @@ const VARS={
114
114
  RATE_LIMIT_PER_MIN:{help:'anonymous requests per minute and IP (default 60)',check:v=>/^\d{1,6}$/.test(v)},
115
115
  YOUTUBE_DAILY_BUDGET_UNITS:{help:'YouTube Data API units per day (default 9000)',check:v=>/^\d{1,9}$/.test(v)},
116
116
  REQUIRE_ACCOUNT:{help:'true = only signed-in apps may use the API',check:v=>/^(true|false)$/.test(v)},
117
+ YOUTUBE_REQUIRE_ACCOUNT:{help:'true = YouTube audio and downloads only for signed-in accounts',check:v=>/^(true|false)$/.test(v)},
117
118
  PUBLIC_ORIGIN:{help:'HTTPS origin of this Worker; accounts and passkeys are bound to it',check:v=>httpsOrigin(v)},
118
119
  SHARE_ORIGIN:{help:'origin of short /p/ links (its domain must route /p/* here)',check:v=>httpsOrigin(v)},
119
120
  YTDLP_SERVICE_URL:{help:'HTTPS URL of your companion (YouTube); pair with secret YTDLP_SERVICE_TOKEN',check:v=>httpsOrigin(v)},
@@ -126,7 +127,10 @@ const SECRETS={
126
127
  SPOTIFY_CLIENT_ID:'Spotify client ID (playlist import)',
127
128
  SPOTIFY_CLIENT_SECRET:'Spotify client secret',
128
129
  LASTFM_API_KEY:'Last.fm API key (radio, similar artists)',
129
- YTDLP_SERVICE_TOKEN:'companion token, 32+ characters',
130
+ YTDLP_SERVICE_TOKEN:'companion token for search and audio, 32+ characters (the Worker signs requests with it)',
131
+ COMPANION_ADMIN_TOKEN:'second companion token for status and updates, 32+ characters',
132
+ COMPANION_ACCESS_CLIENT_ID:'Cloudflare Access service token ID in front of the companion (optional)',
133
+ COMPANION_ACCESS_CLIENT_SECRET:'Cloudflare Access service token secret (optional)',
130
134
  GLYPH_SERVER_BEARER:'shared bearer every app must send (private server)',
131
135
  };
132
136
  function httpsOrigin(v) {
package/lib/install.cjs CHANGED
@@ -7,6 +7,30 @@ const crypto = require('node:crypto');
7
7
  const { spawnSync } = require('node:child_process');
8
8
  const pkg = require('../package.json');
9
9
  const MAX = 128 * 1024 * 1024;
10
+ // Glyph release key (minisign); the same list as glyph_protocol::release.
11
+ const RELEASE_KEYS = ['RWQ2xWZMYa2l251YUhrekvWRC+kaD698lXz0itKGjvNYAauLRTWCzg9o'];
12
+ const ED25519_SPKI = Buffer.from('302a300506032b6570032100','hex');
13
+
14
+ // Checks a minisign signature of `data` against `keys` and the expected
15
+ // trusted comment. Throws with a reason; returns nothing when it passes.
16
+ function verifySignature(data, minisig, keys, comment) {
17
+ const lines = minisig.toString().split(/\r?\n/);
18
+ if (lines.length < 4 || !lines[0].startsWith('untrusted comment:') || !lines[2].startsWith('trusted comment: ')) throw new Error('Release signature cannot be read');
19
+ const sig = Buffer.from(lines[1],'base64');
20
+ const trusted = lines[2].slice('trusted comment: '.length);
21
+ const global = Buffer.from(lines[3],'base64');
22
+ if (trusted !== comment) throw new Error(`Release signature is for "${trusted}", not "${comment}"`);
23
+ const alg = sig.subarray(0,2).toString('latin1');
24
+ if (sig.length !== 74 || global.length !== 64 || (alg !== 'ED' && alg !== 'Ed')) throw new Error('Release signature cannot be read');
25
+ const message = alg === 'ED' ? crypto.createHash('blake2b512').update(data).digest() : data;
26
+ for (const k of keys) {
27
+ const pk = Buffer.from(k,'base64');
28
+ if (pk.length !== 42 || !pk.subarray(2,10).equals(sig.subarray(2,10))) continue;
29
+ const key = crypto.createPublicKey({key:Buffer.concat([ED25519_SPKI,pk.subarray(10)]),format:'der',type:'spki'});
30
+ if (crypto.verify(null,message,key,sig.subarray(10)) && crypto.verify(null,Buffer.concat([sig.subarray(10),Buffer.from(trusted)]),key,global)) return;
31
+ }
32
+ throw new Error('Checksum list is not signed by the Glyph release key; installation aborted');
33
+ }
10
34
 
11
35
  function target(platform = process.platform, arch = process.arch) {
12
36
  const targets = { 'win32-x64': 'x86_64-pc-windows-msvc', 'linux-x64': 'x86_64-unknown-linux-gnu',
@@ -84,12 +108,13 @@ function verify(file, expected = pkg.version) {
84
108
  const result = spawnSync(file,['--version'],{encoding:'utf8',timeout:10000,windowsHide:true});
85
109
  return result.status === 0 && result.stdout.trim() === `glyph ${expected}`;
86
110
  }
87
- async function install() {
111
+ async function install({keys = RELEASE_KEYS} = {}) {
88
112
  const file = executable();
89
113
  if (fs.existsSync(file) && verify(file)) return file;
90
114
  const name = `glyph-server-${pkg.version}-${target()}.${process.platform === 'win32' ? 'zip' : 'tar.gz'}`;
91
115
  const base = `https://github.com/glyphmusic/server/releases/download/v${pkg.version}`;
92
- const [archive, manifest] = await Promise.all([download(`${base}/${name}`),download(`${base}/SHA256SUMS.txt`,65536)]);
116
+ const [archive, manifest, signature] = await Promise.all([download(`${base}/${name}`),download(`${base}/SHA256SUMS.txt`,65536),download(`${base}/SHA256SUMS.txt.minisig`,4096)]);
117
+ verifySignature(manifest,signature,keys,`glyph-release repo=glyphmusic/server tag=v${pkg.version}`);
93
118
  const hash = crypto.createHash('sha256').update(archive).digest('hex');
94
119
  if (hash !== checksum(manifest.toString(),name)) throw new Error('SHA-256 mismatch; installation aborted');
95
120
  const binary = unpack(archive,process.platform === 'win32',['glyph','glyph.exe','glyph-server','glyph-server.exe']);
@@ -102,4 +127,4 @@ async function install() {
102
127
  } finally { fs.rmSync(staged,{force:true}); }
103
128
  return file;
104
129
  }
105
- module.exports = {target,checksum,unpack,download,executable,verify,install};
130
+ module.exports = {target,checksum,unpack,download,executable,verify,verifySignature,install,RELEASE_KEYS};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glyph-server",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Glyph CLI: install, diagnose and manage Glyph servers and companions",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "repository": { "type": "git", "url": "git+https://github.com/glyphmusic/server.git" },
Binary file