@abraca/mcp 2.34.0 → 2.35.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.
@@ -4,15 +4,12 @@ import addFormats from "ajv-formats";
4
4
  import { ZodOptional, z } from "zod";
5
5
  import process$1 from "node:process";
6
6
  import * as fs from "node:fs";
7
- import { existsSync, readFileSync } from "node:fs";
7
+ import { readFileSync } from "node:fs";
8
8
  import * as http from "node:http";
9
9
  import * as os from "node:os";
10
- import { homedir } from "node:os";
11
10
  import * as path from "node:path";
12
- import { dirname, join } from "node:path";
13
- import { AbracadabraClient, AbracadabraProvider, Kind, SERVER_ROOT_ID, WebSocketStatus, awarenessStatesToArray, foldRecords, isEncryptedContent, makeEntryMap, patchEntry, reconcileDocCover, recordFromYAny, toPlain } from "@abraca/dabra";
11
+ import { AbracadabraClient, AbracadabraProvider, PAGE_TYPES, SERVER_ROOT_ID, TYPE_ALIASES, WebSocketStatus, awarenessStatesToArray, foldRecords, isEncryptedContent, loadOrCreateKeyFile, loginOrRegisterWithKey, makeChallengeSigner, makeEntryMap, normalizeRootId, openSyncedProvider, patchEntry, pickEntrySpace, readEntries, readEntries as readEntries$1, reconcileDocCover, recordFromYAny, resolvePageType, toPlain, waitForSync } from "@abraca/dabra";
14
12
  import * as Y from "yjs";
15
- import { mkdir, readFile, writeFile } from "node:fs/promises";
16
13
  import { parseFrontmatter, populateYDocFromMarkdown, yjsToMarkdown } from "@abraca/convert";
17
14
 
18
15
  //#region \0rolldown/runtime.js
@@ -5803,7 +5800,7 @@ function handleRefineResult(result, payload, input, inst) {
5803
5800
 
5804
5801
  //#endregion
5805
5802
  //#region node_modules/zod/v4/core/registries.js
5806
- var _a$1;
5803
+ var _a;
5807
5804
  var $ZodRegistry = class {
5808
5805
  constructor() {
5809
5806
  this._map = /* @__PURE__ */ new WeakMap();
@@ -5846,7 +5843,7 @@ var $ZodRegistry = class {
5846
5843
  function registry() {
5847
5844
  return new $ZodRegistry();
5848
5845
  }
5849
- (_a$1 = globalThis).__zod_globalRegistry ?? (_a$1.__zod_globalRegistry = registry());
5846
+ (_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
5850
5847
  const globalRegistry = globalThis.__zod_globalRegistry;
5851
5848
 
5852
5849
  //#endregion
@@ -13623,22 +13620,6 @@ function registerServerInfoResource(mcp, server) {
13623
13620
  /**
13624
13621
  * Dynamic resource: document tree as navigable JSON.
13625
13622
  */
13626
- function readEntries$1(treeMap) {
13627
- const entries = [];
13628
- treeMap.forEach((raw, id) => {
13629
- const value = toPlain(raw);
13630
- if (typeof value !== "object" || value === null) return;
13631
- entries.push({
13632
- id,
13633
- label: value.label || "Untitled",
13634
- parentId: value.parentId ?? null,
13635
- order: value.order ?? 0,
13636
- type: value.type,
13637
- meta: value.meta
13638
- });
13639
- });
13640
- return entries;
13641
- }
13642
13623
  function childrenOf$1(entries, parentId) {
13643
13624
  return entries.filter((e) => e.parentId === parentId).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
13644
13625
  }
@@ -13662,7 +13643,7 @@ function registerTreeResource(mcp, server) {
13662
13643
  text: "{\"error\": \"Not connected\"}",
13663
13644
  mimeType: "application/json"
13664
13645
  }] };
13665
- const tree = buildTree$1(readEntries$1(treeMap), null, 10);
13646
+ const tree = buildTree$1(readEntries(treeMap), null, 10);
13666
13647
  return { contents: [{
13667
13648
  uri: "abracadabra://tree",
13668
13649
  text: JSON.stringify(tree, null, 2),
@@ -20151,1229 +20132,6 @@ function loadSchemaBundle(path) {
20151
20132
  };
20152
20133
  }
20153
20134
 
20154
- //#endregion
20155
- //#region node_modules/@noble/ed25519/index.js
20156
- /*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
20157
- /**
20158
- * 5KB JS implementation of ed25519 EdDSA signatures.
20159
- * Targets RFC8032, FIPS 186-5, and ZIP215 behavior.
20160
- * @module
20161
- * @example
20162
- * ```js
20163
- import * as ed from '@noble/ed25519';
20164
- (async () => {
20165
- const secretKey = ed.utils.randomSecretKey();
20166
- const message = Uint8Array.from([0xab, 0xbc, 0xcd, 0xde]);
20167
- const pubKey = await ed.getPublicKeyAsync(secretKey); // Sync methods are also present
20168
- const signature = await ed.signAsync(message, secretKey);
20169
- const isValid = await ed.verifyAsync(signature, message, pubKey);
20170
- })();
20171
- ```
20172
- */
20173
- /**
20174
- * Curve params. edwards25519 uses the RFC equation `-x² + y² = 1 + dx²y²`.
20175
- * The stored `a` literal below is `p - 1`, i.e. the field-element encoding of RFC `a = -1`.
20176
- * * P = `2n**255n - 19n` // field over which calculations are done
20177
- * * N = `2n**252n + 27742317777372353535851937790883648493n` // prime-order subgroup order
20178
- * * h = 8 // cofactor
20179
- * * a = `Fp.create(BigInt(-1))` // equation param, stored here as `p - 1`
20180
- * * d = -121665/121666 a.k.a. `Fp.neg(121665 * Fp.inv(121666))` // equation param
20181
- * * Gx, Gy are coordinates of Generator / base point
20182
- *
20183
- * Mirror noble-curves: Point.CURVE() exposes shared params, but callers must not be able to mutate
20184
- * that shared view and desynchronize it from the arithmetic constants captured below.
20185
- */
20186
- const ed25519_CURVE = Object.freeze({
20187
- p: 57896044618658097711785492504343953926634992332820282019728792003956564819949n,
20188
- n: 7237005577332262213973186563042994240857116359379907606001950938285454250989n,
20189
- h: 8n,
20190
- a: 57896044618658097711785492504343953926634992332820282019728792003956564819948n,
20191
- d: 37095705934669439343138083508754565189542113879843219016388785533085940283555n,
20192
- Gx: 15112221349535400772501151409588531511454012693041857206046113283949847762202n,
20193
- Gy: 46316835694926478169428394003475163141307993866256225615783033603165251855960n
20194
- });
20195
- const { p: P, n: N, Gx, Gy, a: _a, d: _d, h } = ed25519_CURVE;
20196
- const L = 32;
20197
- const captureTrace = (...args) => {
20198
- if ("captureStackTrace" in Error && typeof Error.captureStackTrace === "function") Error.captureStackTrace(...args);
20199
- };
20200
- const err = (message = "") => {
20201
- const e = new Error(message);
20202
- captureTrace(e, err);
20203
- throw e;
20204
- };
20205
- const isBig = (n) => typeof n === "bigint";
20206
- const isStr = (s) => typeof s === "string";
20207
- const isBytes$1 = (a) => a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
20208
- /**
20209
- * Asserts something is Bytes, optionally enforces exact length,
20210
- * and returns the same reference.
20211
- */
20212
- const abytes$1 = (value, length, title = "") => {
20213
- const bytes = isBytes$1(value);
20214
- const len = value?.length;
20215
- const needsLen = length !== void 0;
20216
- if (!bytes || needsLen && len !== length) {
20217
- const prefix = title && `"${title}" `;
20218
- const ofLen = needsLen ? ` of length ${length}` : "";
20219
- const got = bytes ? `length=${len}` : `type=${typeof value}`;
20220
- const msg = prefix + "expected Uint8Array" + ofLen + ", got " + got;
20221
- throw bytes ? new RangeError(msg) : new TypeError(msg);
20222
- }
20223
- return value;
20224
- };
20225
- /** create Uint8Array */
20226
- const u8n = (len) => new Uint8Array(len);
20227
- const u8fr = (buf) => Uint8Array.from(buf);
20228
- const padh = (n, pad) => n.toString(16).padStart(pad, "0");
20229
- const bytesToHex = (b) => Array.from(abytes$1(b)).map((e) => padh(e, 2)).join("");
20230
- const C = {
20231
- _0: 48,
20232
- _9: 57,
20233
- A: 65,
20234
- F: 70,
20235
- a: 97,
20236
- f: 102
20237
- };
20238
- const _ch = (ch) => {
20239
- if (ch >= C._0 && ch <= C._9) return ch - C._0;
20240
- if (ch >= C.A && ch <= C.F) return ch - (C.A - 10);
20241
- if (ch >= C.a && ch <= C.f) return ch - (C.a - 10);
20242
- };
20243
- const hexToBytes = (hex) => {
20244
- const e = "hex invalid";
20245
- if (!isStr(hex)) return err(e);
20246
- const hl = hex.length;
20247
- const al = hl / 2;
20248
- if (hl % 2) return err(e);
20249
- const array = u8n(al);
20250
- for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
20251
- const n1 = _ch(hex.charCodeAt(hi));
20252
- const n2 = _ch(hex.charCodeAt(hi + 1));
20253
- if (n1 === void 0 || n2 === void 0) return err(e);
20254
- array[ai] = n1 * 16 + n2;
20255
- }
20256
- return array;
20257
- };
20258
- const cr = () => globalThis?.crypto;
20259
- const subtle = () => cr()?.subtle ?? err("crypto.subtle must be defined, consider polyfill");
20260
- const concatBytes = (...arrs) => {
20261
- let len = 0;
20262
- for (const a of arrs) len += abytes$1(a).length;
20263
- const r = u8n(len);
20264
- let pad = 0;
20265
- arrs.forEach((a) => {
20266
- r.set(a, pad);
20267
- pad += a.length;
20268
- });
20269
- return r;
20270
- };
20271
- /** WebCrypto OS-level CSPRNG (random number generator). Absence still fails later via `cr()`. */
20272
- const randomBytes = (len = L) => {
20273
- return cr().getRandomValues(u8n(len));
20274
- };
20275
- const big = BigInt;
20276
- /** Inclusive-lower, exclusive-upper bigint range assertion. */
20277
- const assertRange = (n, min, max, msg = "bad number: out of range") => {
20278
- if (!isBig(n)) throw new TypeError(msg);
20279
- if (min <= n && n < max) return n;
20280
- throw new RangeError(msg);
20281
- };
20282
- /** Canonical modular reduction into `[0, b)`. */
20283
- const M = (a, b = P) => {
20284
- const r = a % b;
20285
- return r >= 0n ? r : b + r;
20286
- };
20287
- const P_MASK = (1n << 255n) - 1n;
20288
- const modP = (num) => {
20289
- if (num < 0n) err("negative coordinate");
20290
- let r = (num >> 255n) * 19n + (num & P_MASK);
20291
- r = (r >> 255n) * 19n + (r & P_MASK);
20292
- return r % P;
20293
- };
20294
- const modN = (a) => M(a, N);
20295
- /** Modular inversion using Euclidean GCD (non-CT) instead of the RFC's `x^(p-2)` formulation.
20296
- * This still sits on secret-dependent paths like point normalization during keygen/signing. */
20297
- const invert = (num, md) => {
20298
- if (num === 0n || md <= 0n) err("no inverse n=" + num + " mod=" + md);
20299
- let a = M(num, md), b = md, x = 0n, y = 1n, u = 1n, v = 0n;
20300
- while (a !== 0n) {
20301
- const q = b / a, r = b % a;
20302
- const m = x - u * q, n = y - v * q;
20303
- b = a, a = r, x = u, y = v, u = m, v = n;
20304
- }
20305
- return b === 1n ? M(x, md) : err("no inverse");
20306
- };
20307
- const callHash = (name) => {
20308
- const fn = hashes[name];
20309
- if (typeof fn !== "function") err("hashes." + name + " not set");
20310
- return fn;
20311
- };
20312
- const checkDigest = (value) => abytes$1(value, 64, "digest");
20313
- const apoint = (p) => p instanceof Point ? p : err("Point expected");
20314
- const B256 = 2n ** 256n;
20315
- /**
20316
- * Point in XYZT extended coordinates.
20317
- * @param X - X coordinate.
20318
- * @param Y - Y coordinate.
20319
- * @param Z - Projective Z coordinate.
20320
- * @param T - Cached cross-product term.
20321
- * @example
20322
- * Do point arithmetic with the built-in base point and encode the result as hex.
20323
- *
20324
- * ```ts
20325
- * const hex = Point.BASE.double().toHex();
20326
- * ```
20327
- */
20328
- var Point = class Point {
20329
- static BASE;
20330
- static ZERO;
20331
- X;
20332
- Y;
20333
- Z;
20334
- T;
20335
- constructor(X, Y, Z, T) {
20336
- const max = B256;
20337
- this.X = assertRange(X, 0n, max);
20338
- this.Y = assertRange(Y, 0n, max);
20339
- this.Z = assertRange(Z, 1n, max);
20340
- this.T = assertRange(T, 0n, max);
20341
- Object.freeze(this);
20342
- }
20343
- static CURVE() {
20344
- return ed25519_CURVE;
20345
- }
20346
- static fromAffine(p) {
20347
- return new Point(p.x, p.y, 1n, modP(p.x * p.y));
20348
- }
20349
- /** RFC8032 5.1.3: Bytes to Point. */
20350
- static fromBytes(hex, zip215 = false) {
20351
- const d = _d;
20352
- const normed = u8fr(abytes$1(hex, L));
20353
- const lastByte = hex[31];
20354
- normed[31] = lastByte & -129;
20355
- const y = bytesToNumberLE(normed);
20356
- assertRange(y, 0n, zip215 ? B256 : P);
20357
- const y2 = modP(y * y);
20358
- let { isValid, value: x } = uvRatio(M(y2 - 1n), modP(d * y2 + 1n));
20359
- if (!isValid) err("bad point: y not sqrt");
20360
- const isXOdd = (x & 1n) === 1n;
20361
- const isLastByteOdd = (lastByte & 128) !== 0;
20362
- if (!zip215 && x === 0n && isLastByteOdd) err("bad point: x==0, isLastByteOdd");
20363
- if (isLastByteOdd !== isXOdd) x = M(-x);
20364
- return new Point(x, y, 1n, modP(x * y));
20365
- }
20366
- static fromHex(hex, zip215) {
20367
- return Point.fromBytes(hexToBytes(hex), zip215);
20368
- }
20369
- get x() {
20370
- return this.toAffine().x;
20371
- }
20372
- get y() {
20373
- return this.toAffine().y;
20374
- }
20375
- /** Checks if the point is valid and on-curve. */
20376
- assertValidity() {
20377
- const a = _a;
20378
- const d = _d;
20379
- const p = this;
20380
- if (p.is0()) return err("bad point: ZERO");
20381
- const { X, Y, Z, T } = p;
20382
- const X2 = modP(X * X);
20383
- const Y2 = modP(Y * Y);
20384
- const Z2 = modP(Z * Z);
20385
- const Z4 = modP(Z2 * Z2);
20386
- if (modP(Z2 * (modP(X2 * a) + Y2)) !== M(Z4 + modP(d * modP(X2 * Y2)))) return err("bad point: equation left != right (1)");
20387
- if (modP(X * Y) !== modP(Z * T)) return err("bad point: equation left != right (2)");
20388
- return this;
20389
- }
20390
- /** Equality check: compare points P&Q. */
20391
- equals(other) {
20392
- const { X: X1, Y: Y1, Z: Z1 } = this;
20393
- const { X: X2, Y: Y2, Z: Z2 } = apoint(other);
20394
- const X1Z2 = modP(X1 * Z2);
20395
- const X2Z1 = modP(X2 * Z1);
20396
- const Y1Z2 = modP(Y1 * Z2);
20397
- const Y2Z1 = modP(Y2 * Z1);
20398
- return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
20399
- }
20400
- is0() {
20401
- return this.equals(I);
20402
- }
20403
- /** Flip point over y coordinate. */
20404
- negate() {
20405
- return new Point(M(-this.X), this.Y, this.Z, M(-this.T));
20406
- }
20407
- /** Point doubling. Complete formula. Cost: `4M + 4S + 1*a + 6add + 1*2`. */
20408
- double() {
20409
- const { X: X1, Y: Y1, Z: Z1 } = this;
20410
- const a = _a;
20411
- const A = modP(X1 * X1);
20412
- const B = modP(Y1 * Y1);
20413
- const C = modP(2n * Z1 * Z1);
20414
- const D = modP(a * A);
20415
- const x1y1 = M(X1 + Y1);
20416
- const E = M(modP(x1y1 * x1y1) - A - B);
20417
- const G = M(D + B);
20418
- const F = M(G - C);
20419
- const H = M(D - B);
20420
- const X3 = modP(E * F);
20421
- const Y3 = modP(G * H);
20422
- const T3 = modP(E * H);
20423
- return new Point(X3, Y3, modP(F * G), T3);
20424
- }
20425
- /** Point addition. Complete formula. Cost: `8M + 1*k + 8add + 1*2`. */
20426
- add(other) {
20427
- const { X: X1, Y: Y1, Z: Z1, T: T1 } = this;
20428
- const { X: X2, Y: Y2, Z: Z2, T: T2 } = apoint(other);
20429
- const a = _a;
20430
- const d = _d;
20431
- const A = modP(X1 * X2);
20432
- const B = modP(Y1 * Y2);
20433
- const C = modP(modP(T1 * d) * T2);
20434
- const D = modP(Z1 * Z2);
20435
- const E = M(modP(M(X1 + Y1) * M(X2 + Y2)) - A - B);
20436
- const F = M(D - C);
20437
- const G = M(D + C);
20438
- const H = M(B - modP(a * A));
20439
- const X3 = modP(E * F);
20440
- const Y3 = modP(G * H);
20441
- const T3 = modP(E * H);
20442
- return new Point(X3, Y3, modP(F * G), T3);
20443
- }
20444
- subtract(other) {
20445
- return this.add(apoint(other).negate());
20446
- }
20447
- /**
20448
- * Point-by-scalar multiplication. Safe mode requires `1 <= n < CURVE.n`.
20449
- * Unsafe mode additionally permits `n = 0` and returns the identity point for that case.
20450
- * Uses {@link wNAF} for base point.
20451
- * Uses fake point to mitigate side-channel leakage.
20452
- * @param n - scalar by which point is multiplied
20453
- * @param safe - safe mode guards against timing attacks; unsafe mode is faster
20454
- */
20455
- multiply(n, safe = true) {
20456
- if (!safe && n === 0n) return I;
20457
- assertRange(n, 1n, N);
20458
- if (!safe && this.is0()) return I;
20459
- if (n === 1n) return this;
20460
- if (this.equals(G)) return wNAF(n).p;
20461
- let p = I;
20462
- let f = G;
20463
- for (let d = this; n > 0n; d = d.double(), n >>= 1n) if (n & 1n) p = p.add(d);
20464
- else if (safe) f = f.add(d);
20465
- return p;
20466
- }
20467
- multiplyUnsafe(scalar) {
20468
- return this.multiply(scalar, false);
20469
- }
20470
- /** Convert point to 2d xy affine point. (X, Y, Z) ∋ (x=X/Z, y=Y/Z) */
20471
- toAffine() {
20472
- const { X, Y, Z } = this;
20473
- if (this.equals(I)) return {
20474
- x: 0n,
20475
- y: 1n
20476
- };
20477
- const iz = invert(Z, P);
20478
- if (modP(Z * iz) !== 1n) err("invalid inverse");
20479
- return {
20480
- x: modP(X * iz),
20481
- y: modP(Y * iz)
20482
- };
20483
- }
20484
- toBytes() {
20485
- const { x, y } = this.toAffine();
20486
- const b = numTo32bLE(y);
20487
- b[31] |= x & 1n ? 128 : 0;
20488
- return b;
20489
- }
20490
- toHex() {
20491
- return bytesToHex(this.toBytes());
20492
- }
20493
- clearCofactor() {
20494
- return this.multiply(big(h), false);
20495
- }
20496
- isSmallOrder() {
20497
- return this.clearCofactor().is0();
20498
- }
20499
- isTorsionFree() {
20500
- let p = this.multiply(N / 2n, false).double();
20501
- if (N % 2n) p = p.add(this);
20502
- return p.is0();
20503
- }
20504
- };
20505
- /** Generator / base point */
20506
- const G = new Point(Gx, Gy, 1n, M(Gx * Gy));
20507
- /** Identity / zero point */
20508
- const I = new Point(0n, 1n, 1n, 0n);
20509
- Point.BASE = G;
20510
- Point.ZERO = I;
20511
- const numTo32bLE = (num) => hexToBytes(padh(assertRange(num, 0n, B256), 64)).reverse();
20512
- const bytesToNumberLE = (b) => big("0x" + bytesToHex(u8fr(abytes$1(b)).reverse()));
20513
- const pow2 = (x, power) => {
20514
- let r = x;
20515
- while (power-- > 0n) r = modP(r * r);
20516
- return r;
20517
- };
20518
- const pow_2_252_3 = (x) => {
20519
- const b2 = modP(modP(x * x) * x);
20520
- const b5 = modP(pow2(modP(pow2(b2, 2n) * b2), 1n) * x);
20521
- const b10 = modP(pow2(b5, 5n) * b5);
20522
- const b20 = modP(pow2(b10, 10n) * b10);
20523
- const b40 = modP(pow2(b20, 20n) * b20);
20524
- const b80 = modP(pow2(b40, 40n) * b40);
20525
- return {
20526
- pow_p_5_8: modP(pow2(modP(pow2(modP(pow2(modP(pow2(b80, 80n) * b80), 80n) * b80), 10n) * b10), 2n) * x),
20527
- b2
20528
- };
20529
- };
20530
- const RM1 = 19681161376707505956807079304988542015446066515923890162744021073123829784752n;
20531
- const uvRatio = (u, v) => {
20532
- const v3 = modP(v * modP(v * v));
20533
- const pow = pow_2_252_3(modP(u * modP(modP(v3 * v3) * v))).pow_p_5_8;
20534
- let x = modP(u * modP(v3 * pow));
20535
- const vx2 = modP(v * modP(x * x));
20536
- const root1 = x;
20537
- const root2 = modP(x * RM1);
20538
- const useRoot1 = vx2 === u;
20539
- const useRoot2 = vx2 === M(-u);
20540
- const noRoot = vx2 === M(-u * RM1);
20541
- if (useRoot1) x = root1;
20542
- if (useRoot2 || noRoot) x = root2;
20543
- if ((M(x) & 1n) === 1n) x = M(-x);
20544
- return {
20545
- isValid: useRoot1 || useRoot2,
20546
- value: x
20547
- };
20548
- };
20549
- const modL_LE = (hash) => modN(bytesToNumberLE(hash));
20550
- const sha512a = (...m) => Promise.resolve(callHash("sha512Async")(concatBytes(...m))).then(checkDigest);
20551
- const sha512s = (...m) => checkDigest(callHash("sha512")(concatBytes(...m)));
20552
- const hash2extK = (hashed) => {
20553
- const copy = u8fr(hashed);
20554
- const head = copy.slice(0, 32);
20555
- head[0] &= 248;
20556
- head[31] &= 127;
20557
- head[31] |= 64;
20558
- const prefix = copy.slice(32, 64);
20559
- const scalar = modL_LE(head);
20560
- const point = G.multiply(scalar);
20561
- return {
20562
- head,
20563
- prefix,
20564
- scalar,
20565
- point,
20566
- pointBytes: point.toBytes()
20567
- };
20568
- };
20569
- const getExtendedPublicKeyAsync = (secretKey) => sha512a(abytes$1(secretKey, L)).then(hash2extK);
20570
- const getExtendedPublicKey = (secretKey) => hash2extK(sha512s(abytes$1(secretKey, L)));
20571
- /**
20572
- * Creates a 32-byte Ed25519 public key from the RFC 8032 32-byte secret-key seed.
20573
- * To use, set `hashes.sha512` first.
20574
- * @param priv - 32-byte RFC 8032 secret-key seed, not a 64-byte expanded secret key.
20575
- * @returns 32-byte public key.
20576
- * @throws If synchronous SHA-512 has not been configured in `hashes`. {@link Error}
20577
- * @throws On wrong argument types. {@link TypeError}
20578
- * @throws On wrong argument ranges or values. {@link RangeError}
20579
- * @example
20580
- * Derive the public key entirely through the synchronous API.
20581
- *
20582
- * ```ts
20583
- * import * as ed from '@noble/ed25519';
20584
- * import { sha512 } from '@noble/hashes/sha2.js';
20585
- *
20586
- * ed.hashes.sha512 = sha512;
20587
- * const secretKey = ed.utils.randomSecretKey();
20588
- * const publicKey = ed.getPublicKey(secretKey);
20589
- * ```
20590
- */
20591
- const getPublicKey = (priv) => getExtendedPublicKey(priv).pointBytes;
20592
- const hashFinishS = (res) => res.finish(sha512s(res.hashable));
20593
- const _sign = (e, rBytes, msg) => {
20594
- const { pointBytes: P, scalar: s } = e;
20595
- const r = modL_LE(rBytes);
20596
- const R = G.multiply(r).toBytes();
20597
- const hashable = concatBytes(R, P, msg);
20598
- const finish = (hashed) => {
20599
- return abytes$1(concatBytes(R, numTo32bLE(modN(r + modL_LE(hashed) * s))), 64);
20600
- };
20601
- return {
20602
- hashable,
20603
- finish
20604
- };
20605
- };
20606
- /**
20607
- * Signs message using secret key. To use, set `hashes.sha512` first.
20608
- * Follows RFC8032 5.1.6.
20609
- * @param message - Message bytes to sign.
20610
- * @param secretKey - 32-byte RFC 8032 secret-key seed, not a 64-byte expanded secret key.
20611
- * @returns 64-byte Ed25519 signature.
20612
- * @throws If synchronous SHA-512 has not been configured in `hashes`. {@link Error}
20613
- * @throws On wrong argument types. {@link TypeError}
20614
- * @throws On wrong argument ranges or values. {@link RangeError}
20615
- * @example
20616
- * Use the sync API when you've wired a SHA-512 implementation yourself.
20617
- *
20618
- * ```ts
20619
- * import * as ed from '@noble/ed25519';
20620
- * import { sha512 } from '@noble/hashes/sha2.js';
20621
- *
20622
- * ed.hashes.sha512 = sha512;
20623
- * const secretKey = ed.utils.randomSecretKey();
20624
- * const signature = ed.sign(new Uint8Array([1, 2, 3]), secretKey);
20625
- * ```
20626
- */
20627
- const sign = (message, secretKey) => {
20628
- const m = abytes$1(message);
20629
- const e = getExtendedPublicKey(secretKey);
20630
- return hashFinishS(_sign(e, sha512s(e.prefix, m), m));
20631
- };
20632
- /**
20633
- * Hash implementations used by the synchronous API plus the default async WebCrypto provider.
20634
- * Both slots are configurable API surface; wrapper helpers revalidate that providers still return
20635
- * 64-byte SHA-512 digests.
20636
- * @example
20637
- * Provide a SHA-512 implementation before calling synchronous helpers.
20638
- *
20639
- * ```ts
20640
- * import * as ed from '@noble/ed25519';
20641
- * import { sha512 } from '@noble/hashes/sha2.js';
20642
- *
20643
- * ed.hashes.sha512 = sha512;
20644
- * const { publicKey } = ed.keygen();
20645
- * ```
20646
- */
20647
- const hashes = {
20648
- sha512Async: async (message) => {
20649
- const s = subtle();
20650
- const m = concatBytes(message);
20651
- return u8n(await s.digest("SHA-512", m.buffer));
20652
- },
20653
- sha512: void 0
20654
- };
20655
- const randomSecretKey = (seed) => {
20656
- seed = seed === void 0 ? randomBytes(L) : seed;
20657
- return abytes$1(seed, L);
20658
- };
20659
- /**
20660
- * Ed25519-specific key utilities.
20661
- * `utils.getExtendedPublicKey*` expose secret-derived internals (`head`, `prefix`, `scalar`, and
20662
- * point objects), not just public-key bytes.
20663
- * @example
20664
- * Generate a new Ed25519 secret key and derive the matching public key.
20665
- *
20666
- * ```ts
20667
- * import * as ed from '@noble/ed25519';
20668
- *
20669
- * const secretKey = ed.utils.randomSecretKey();
20670
- * const publicKey = await ed.getPublicKeyAsync(secretKey);
20671
- * ```
20672
- */
20673
- const utils = /* @__PURE__ */ Object.freeze({
20674
- getExtendedPublicKeyAsync,
20675
- getExtendedPublicKey,
20676
- randomSecretKey
20677
- });
20678
- const W = 8;
20679
- const pwindows = Math.ceil(256 / W) + 1;
20680
- const pwindowSize = 2 ** (W - 1);
20681
- const precompute = () => {
20682
- const points = [];
20683
- let p = G;
20684
- let b = p;
20685
- for (let w = 0; w < pwindows; w++) {
20686
- b = p;
20687
- points.push(b);
20688
- for (let i = 1; i < pwindowSize; i++) {
20689
- b = b.add(p);
20690
- points.push(b);
20691
- }
20692
- p = b.double();
20693
- }
20694
- return points;
20695
- };
20696
- let Gpows = void 0;
20697
- const ctneg = (cnd, p) => {
20698
- const n = p.negate();
20699
- return cnd ? n : p;
20700
- };
20701
- /**
20702
- * Precomputes give 12x faster getPublicKey(), 10x sign(), 2x verify() by
20703
- * caching multiples of G (base point). Cache is stored in 32MB of RAM.
20704
- * Any time `G.multiply` is done, precomputes are used.
20705
- * Not used for getSharedSecret, which instead multiplies random pubkey `P.multiply`.
20706
- *
20707
- * w-ary non-adjacent form (wNAF) precomputation method is 10% slower than windowed method,
20708
- * but takes 2x less RAM. RAM reduction is possible by utilizing `.subtract`.
20709
- * Returns the real accumulator `p` plus a fake accumulator `f`; callers only care about `p`, while
20710
- * `f` exists to keep similar work in zero-digit branches as a JS/JIT side-channel mitigation.
20711
- *
20712
- * !! Precomputes can be disabled by commenting-out call of the wNAF() inside Point#multiply().
20713
- */
20714
- const wNAF = (n) => {
20715
- const comp = Gpows || (Gpows = precompute());
20716
- let p = I;
20717
- let f = G;
20718
- const pow_2_w = 2 ** W;
20719
- const maxNum = pow_2_w;
20720
- const mask = big(pow_2_w - 1);
20721
- const shiftBy = big(W);
20722
- for (let w = 0; w < pwindows; w++) {
20723
- let wbits = Number(n & mask);
20724
- n >>= shiftBy;
20725
- if (wbits > pwindowSize) {
20726
- wbits -= maxNum;
20727
- n += 1n;
20728
- }
20729
- const off = w * pwindowSize;
20730
- const offF = off;
20731
- const offP = off + Math.abs(wbits) - 1;
20732
- const isEven = w % 2 !== 0;
20733
- const isNeg = wbits < 0;
20734
- if (wbits === 0) f = f.add(ctneg(isEven, comp[offF]));
20735
- else p = p.add(ctneg(isNeg, comp[offP]));
20736
- }
20737
- if (n !== 0n) err("invalid wnaf");
20738
- return {
20739
- p,
20740
- f
20741
- };
20742
- };
20743
-
20744
- //#endregion
20745
- //#region node_modules/@noble/hashes/utils.js
20746
- /**
20747
- * Checks if something is Uint8Array. Be careful: nodejs Buffer will return true.
20748
- * @param a - value to test
20749
- * @returns `true` when the value is a Uint8Array-compatible view.
20750
- * @example
20751
- * Check whether a value is a Uint8Array-compatible view.
20752
- * ```ts
20753
- * isBytes(new Uint8Array([1, 2, 3]));
20754
- * ```
20755
- */
20756
- function isBytes(a) {
20757
- return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
20758
- }
20759
- /**
20760
- * Asserts something is Uint8Array.
20761
- * @param value - value to validate
20762
- * @param length - optional exact length constraint
20763
- * @param title - label included in thrown errors
20764
- * @returns The validated byte array.
20765
- * @throws On wrong argument types. {@link TypeError}
20766
- * @throws On wrong argument ranges or values. {@link RangeError}
20767
- * @example
20768
- * Validate that a value is a byte array.
20769
- * ```ts
20770
- * abytes(new Uint8Array([1, 2, 3]));
20771
- * ```
20772
- */
20773
- function abytes(value, length, title = "") {
20774
- const bytes = isBytes(value);
20775
- const len = value?.length;
20776
- const needsLen = length !== void 0;
20777
- if (!bytes || needsLen && len !== length) {
20778
- const prefix = title && `"${title}" `;
20779
- const ofLen = needsLen ? ` of length ${length}` : "";
20780
- const got = bytes ? `length=${len}` : `type=${typeof value}`;
20781
- const message = prefix + "expected Uint8Array" + ofLen + ", got " + got;
20782
- if (!bytes) throw new TypeError(message);
20783
- throw new RangeError(message);
20784
- }
20785
- return value;
20786
- }
20787
- /**
20788
- * Asserts a hash instance has not been destroyed or finished.
20789
- * @param instance - hash instance to validate
20790
- * @param checkFinished - whether to reject finalized instances
20791
- * @throws If the hash instance has already been destroyed or finalized. {@link Error}
20792
- * @example
20793
- * Validate that a hash instance is still usable.
20794
- * ```ts
20795
- * import { aexists } from '@noble/hashes/utils.js';
20796
- * import { sha256 } from '@noble/hashes/sha2.js';
20797
- * const hash = sha256.create();
20798
- * aexists(hash);
20799
- * ```
20800
- */
20801
- function aexists(instance, checkFinished = true) {
20802
- if (instance.destroyed) throw new Error("Hash instance has been destroyed");
20803
- if (checkFinished && instance.finished) throw new Error("Hash#digest() has already been called");
20804
- }
20805
- /**
20806
- * Asserts output is a sufficiently-sized byte array.
20807
- * @param out - destination buffer
20808
- * @param instance - hash instance providing output length
20809
- * Oversized buffers are allowed; downstream code only promises to fill the first `outputLen` bytes.
20810
- * @throws On wrong argument types. {@link TypeError}
20811
- * @throws On wrong argument ranges or values. {@link RangeError}
20812
- * @example
20813
- * Validate a caller-provided digest buffer.
20814
- * ```ts
20815
- * import { aoutput } from '@noble/hashes/utils.js';
20816
- * import { sha256 } from '@noble/hashes/sha2.js';
20817
- * const hash = sha256.create();
20818
- * aoutput(new Uint8Array(hash.outputLen), hash);
20819
- * ```
20820
- */
20821
- function aoutput(out, instance) {
20822
- abytes(out, void 0, "digestInto() output");
20823
- const min = instance.outputLen;
20824
- if (out.length < min) throw new RangeError("\"digestInto() output\" expected to be of length >=" + min);
20825
- }
20826
- /**
20827
- * Zeroizes typed arrays in place. Warning: JS provides no guarantees.
20828
- * @param arrays - arrays to overwrite with zeros
20829
- * @example
20830
- * Zeroize sensitive buffers in place.
20831
- * ```ts
20832
- * clean(new Uint8Array([1, 2, 3]));
20833
- * ```
20834
- */
20835
- function clean(...arrays) {
20836
- for (let i = 0; i < arrays.length; i++) arrays[i].fill(0);
20837
- }
20838
- /**
20839
- * Creates a DataView for byte-level manipulation.
20840
- * @param arr - source typed array
20841
- * @returns DataView over the same buffer region.
20842
- * @example
20843
- * Create a DataView over an existing buffer.
20844
- * ```ts
20845
- * createView(new Uint8Array(4));
20846
- * ```
20847
- */
20848
- function createView(arr) {
20849
- return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
20850
- }
20851
- /** Whether the current platform is little-endian. */
20852
- const isLE = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
20853
- const hasHexBuiltin = typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function";
20854
- /**
20855
- * Creates a callable hash function from a stateful class constructor.
20856
- * @param hashCons - hash constructor or factory
20857
- * @param info - optional metadata such as DER OID
20858
- * @returns Frozen callable hash wrapper with `.create()`.
20859
- * Wrapper construction eagerly calls `hashCons(undefined)` once to read
20860
- * `outputLen` / `blockLen`, so constructor side effects happen at module
20861
- * init time.
20862
- * @example
20863
- * Wrap a stateful hash constructor into a callable helper.
20864
- * ```ts
20865
- * import { createHasher } from '@noble/hashes/utils.js';
20866
- * import { sha256 } from '@noble/hashes/sha2.js';
20867
- * const wrapped = createHasher(sha256.create, { oid: sha256.oid });
20868
- * wrapped(new Uint8Array([1]));
20869
- * ```
20870
- */
20871
- function createHasher(hashCons, info = {}) {
20872
- const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
20873
- const tmp = hashCons(void 0);
20874
- hashC.outputLen = tmp.outputLen;
20875
- hashC.blockLen = tmp.blockLen;
20876
- hashC.canXOF = tmp.canXOF;
20877
- hashC.create = (opts) => hashCons(opts);
20878
- Object.assign(hashC, info);
20879
- return Object.freeze(hashC);
20880
- }
20881
- /**
20882
- * Creates OID metadata for NIST hashes with prefix `06 09 60 86 48 01 65 03 04 02`.
20883
- * @param suffix - final OID byte for the selected hash.
20884
- * The helper accepts any byte even though only the documented NIST hash
20885
- * suffixes are meaningful downstream.
20886
- * @returns Object containing the DER-encoded OID.
20887
- * @example
20888
- * Build OID metadata for a NIST hash.
20889
- * ```ts
20890
- * oidNist(0x01);
20891
- * ```
20892
- */
20893
- const oidNist = (suffix) => ({ oid: Uint8Array.from([
20894
- 6,
20895
- 9,
20896
- 96,
20897
- 134,
20898
- 72,
20899
- 1,
20900
- 101,
20901
- 3,
20902
- 4,
20903
- 2,
20904
- suffix
20905
- ]) });
20906
-
20907
- //#endregion
20908
- //#region node_modules/@noble/hashes/_md.js
20909
- /**
20910
- * Internal Merkle-Damgard hash utils.
20911
- * @module
20912
- */
20913
- /**
20914
- * Merkle-Damgard hash construction base class.
20915
- * Could be used to create MD5, RIPEMD, SHA1, SHA2.
20916
- * Accepts only byte-aligned `Uint8Array` input, even when the underlying spec describes bit
20917
- * strings with partial-byte tails.
20918
- * @param blockLen - internal block size in bytes
20919
- * @param outputLen - digest size in bytes
20920
- * @param padOffset - trailing length field size in bytes
20921
- * @param isLE - whether length and state words are encoded in little-endian
20922
- * @example
20923
- * Use a concrete subclass to get the shared Merkle-Damgard update/digest flow.
20924
- * ```ts
20925
- * import { _SHA1 } from '@noble/hashes/legacy.js';
20926
- * const hash = new _SHA1();
20927
- * hash.update(new Uint8Array([97, 98, 99]));
20928
- * hash.digest();
20929
- * ```
20930
- */
20931
- var HashMD = class {
20932
- blockLen;
20933
- outputLen;
20934
- canXOF = false;
20935
- padOffset;
20936
- isLE;
20937
- buffer;
20938
- view;
20939
- finished = false;
20940
- length = 0;
20941
- pos = 0;
20942
- destroyed = false;
20943
- constructor(blockLen, outputLen, padOffset, isLE) {
20944
- this.blockLen = blockLen;
20945
- this.outputLen = outputLen;
20946
- this.padOffset = padOffset;
20947
- this.isLE = isLE;
20948
- this.buffer = new Uint8Array(blockLen);
20949
- this.view = createView(this.buffer);
20950
- }
20951
- update(data) {
20952
- aexists(this);
20953
- abytes(data);
20954
- const { view, buffer, blockLen } = this;
20955
- const len = data.length;
20956
- for (let pos = 0; pos < len;) {
20957
- const take = Math.min(blockLen - this.pos, len - pos);
20958
- if (take === blockLen) {
20959
- const dataView = createView(data);
20960
- for (; blockLen <= len - pos; pos += blockLen) this.process(dataView, pos);
20961
- continue;
20962
- }
20963
- buffer.set(data.subarray(pos, pos + take), this.pos);
20964
- this.pos += take;
20965
- pos += take;
20966
- if (this.pos === blockLen) {
20967
- this.process(view, 0);
20968
- this.pos = 0;
20969
- }
20970
- }
20971
- this.length += data.length;
20972
- this.roundClean();
20973
- return this;
20974
- }
20975
- digestInto(out) {
20976
- aexists(this);
20977
- aoutput(out, this);
20978
- this.finished = true;
20979
- const { buffer, view, blockLen, isLE } = this;
20980
- let { pos } = this;
20981
- buffer[pos++] = 128;
20982
- clean(this.buffer.subarray(pos));
20983
- if (this.padOffset > blockLen - pos) {
20984
- this.process(view, 0);
20985
- pos = 0;
20986
- }
20987
- for (let i = pos; i < blockLen; i++) buffer[i] = 0;
20988
- view.setBigUint64(blockLen - 8, BigInt(this.length * 8), isLE);
20989
- this.process(view, 0);
20990
- const oview = createView(out);
20991
- const len = this.outputLen;
20992
- if (len % 4) throw new Error("_sha2: outputLen must be aligned to 32bit");
20993
- const outLen = len / 4;
20994
- const state = this.get();
20995
- if (outLen > state.length) throw new Error("_sha2: outputLen bigger than state");
20996
- for (let i = 0; i < outLen; i++) oview.setUint32(4 * i, state[i], isLE);
20997
- }
20998
- digest() {
20999
- const { buffer, outputLen } = this;
21000
- this.digestInto(buffer);
21001
- const res = buffer.slice(0, outputLen);
21002
- this.destroy();
21003
- return res;
21004
- }
21005
- _cloneInto(to) {
21006
- to ||= new this.constructor();
21007
- to.set(...this.get());
21008
- const { blockLen, buffer, length, finished, destroyed, pos } = this;
21009
- to.destroyed = destroyed;
21010
- to.finished = finished;
21011
- to.length = length;
21012
- to.pos = pos;
21013
- if (length % blockLen) to.buffer.set(buffer);
21014
- return to;
21015
- }
21016
- clone() {
21017
- return this._cloneInto();
21018
- }
21019
- };
21020
- /** Initial SHA512 state from RFC 6234 §6.3: eight RFC 64-bit `H(0)` words stored as sixteen
21021
- * big-endian 32-bit halves. Derived from the fractional parts of the square roots of the first
21022
- * eight prime numbers. Exported as a shared table; callers must treat it as read-only because
21023
- * constructors copy halves from it by index. */
21024
- const SHA512_IV = /* @__PURE__ */ Uint32Array.from([
21025
- 1779033703,
21026
- 4089235720,
21027
- 3144134277,
21028
- 2227873595,
21029
- 1013904242,
21030
- 4271175723,
21031
- 2773480762,
21032
- 1595750129,
21033
- 1359893119,
21034
- 2917565137,
21035
- 2600822924,
21036
- 725511199,
21037
- 528734635,
21038
- 4215389547,
21039
- 1541459225,
21040
- 327033209
21041
- ]);
21042
-
21043
- //#endregion
21044
- //#region node_modules/@noble/hashes/_u64.js
21045
- const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
21046
- const _32n = /* @__PURE__ */ BigInt(32);
21047
- function fromBig(n, le = false) {
21048
- if (le) return {
21049
- h: Number(n & U32_MASK64),
21050
- l: Number(n >> _32n & U32_MASK64)
21051
- };
21052
- return {
21053
- h: Number(n >> _32n & U32_MASK64) | 0,
21054
- l: Number(n & U32_MASK64) | 0
21055
- };
21056
- }
21057
- function split(lst, le = false) {
21058
- const len = lst.length;
21059
- let Ah = new Uint32Array(len);
21060
- let Al = new Uint32Array(len);
21061
- for (let i = 0; i < len; i++) {
21062
- const { h, l } = fromBig(lst[i], le);
21063
- [Ah[i], Al[i]] = [h, l];
21064
- }
21065
- return [Ah, Al];
21066
- }
21067
- const shrSH = (h, _l, s) => h >>> s;
21068
- const shrSL = (h, l, s) => h << 32 - s | l >>> s;
21069
- const rotrSH = (h, l, s) => h >>> s | l << 32 - s;
21070
- const rotrSL = (h, l, s) => h << 32 - s | l >>> s;
21071
- const rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
21072
- const rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
21073
- function add(Ah, Al, Bh, Bl) {
21074
- const l = (Al >>> 0) + (Bl >>> 0);
21075
- return {
21076
- h: Ah + Bh + (l / 2 ** 32 | 0) | 0,
21077
- l: l | 0
21078
- };
21079
- }
21080
- const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
21081
- const add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
21082
- const add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
21083
- const add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
21084
- const add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
21085
- const add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
21086
-
21087
- //#endregion
21088
- //#region node_modules/@noble/hashes/sha2.js
21089
- /**
21090
- * SHA2 hash function. A.k.a. sha256, sha384, sha512, sha512_224, sha512_256.
21091
- * SHA256 is the fastest hash implementable in JS, even faster than Blake3.
21092
- * Check out {@link https://www.rfc-editor.org/rfc/rfc4634 | RFC 4634} and
21093
- * {@link https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf | FIPS 180-4}.
21094
- * @module
21095
- */
21096
- const K512 = split([
21097
- "0x428a2f98d728ae22",
21098
- "0x7137449123ef65cd",
21099
- "0xb5c0fbcfec4d3b2f",
21100
- "0xe9b5dba58189dbbc",
21101
- "0x3956c25bf348b538",
21102
- "0x59f111f1b605d019",
21103
- "0x923f82a4af194f9b",
21104
- "0xab1c5ed5da6d8118",
21105
- "0xd807aa98a3030242",
21106
- "0x12835b0145706fbe",
21107
- "0x243185be4ee4b28c",
21108
- "0x550c7dc3d5ffb4e2",
21109
- "0x72be5d74f27b896f",
21110
- "0x80deb1fe3b1696b1",
21111
- "0x9bdc06a725c71235",
21112
- "0xc19bf174cf692694",
21113
- "0xe49b69c19ef14ad2",
21114
- "0xefbe4786384f25e3",
21115
- "0x0fc19dc68b8cd5b5",
21116
- "0x240ca1cc77ac9c65",
21117
- "0x2de92c6f592b0275",
21118
- "0x4a7484aa6ea6e483",
21119
- "0x5cb0a9dcbd41fbd4",
21120
- "0x76f988da831153b5",
21121
- "0x983e5152ee66dfab",
21122
- "0xa831c66d2db43210",
21123
- "0xb00327c898fb213f",
21124
- "0xbf597fc7beef0ee4",
21125
- "0xc6e00bf33da88fc2",
21126
- "0xd5a79147930aa725",
21127
- "0x06ca6351e003826f",
21128
- "0x142929670a0e6e70",
21129
- "0x27b70a8546d22ffc",
21130
- "0x2e1b21385c26c926",
21131
- "0x4d2c6dfc5ac42aed",
21132
- "0x53380d139d95b3df",
21133
- "0x650a73548baf63de",
21134
- "0x766a0abb3c77b2a8",
21135
- "0x81c2c92e47edaee6",
21136
- "0x92722c851482353b",
21137
- "0xa2bfe8a14cf10364",
21138
- "0xa81a664bbc423001",
21139
- "0xc24b8b70d0f89791",
21140
- "0xc76c51a30654be30",
21141
- "0xd192e819d6ef5218",
21142
- "0xd69906245565a910",
21143
- "0xf40e35855771202a",
21144
- "0x106aa07032bbd1b8",
21145
- "0x19a4c116b8d2d0c8",
21146
- "0x1e376c085141ab53",
21147
- "0x2748774cdf8eeb99",
21148
- "0x34b0bcb5e19b48a8",
21149
- "0x391c0cb3c5c95a63",
21150
- "0x4ed8aa4ae3418acb",
21151
- "0x5b9cca4f7763e373",
21152
- "0x682e6ff3d6b2b8a3",
21153
- "0x748f82ee5defb2fc",
21154
- "0x78a5636f43172f60",
21155
- "0x84c87814a1f0ab72",
21156
- "0x8cc702081a6439ec",
21157
- "0x90befffa23631e28",
21158
- "0xa4506cebde82bde9",
21159
- "0xbef9a3f7b2c67915",
21160
- "0xc67178f2e372532b",
21161
- "0xca273eceea26619c",
21162
- "0xd186b8c721c0c207",
21163
- "0xeada7dd6cde0eb1e",
21164
- "0xf57d4f7fee6ed178",
21165
- "0x06f067aa72176fba",
21166
- "0x0a637dc5a2c898a6",
21167
- "0x113f9804bef90dae",
21168
- "0x1b710b35131c471b",
21169
- "0x28db77f523047d84",
21170
- "0x32caab7b40c72493",
21171
- "0x3c9ebe0a15c9bebc",
21172
- "0x431d67c49c100d4c",
21173
- "0x4cc5d4becb3e42b6",
21174
- "0x597f299cfc657e2a",
21175
- "0x5fcb6fab3ad6faec",
21176
- "0x6c44198c4a475817"
21177
- ].map((n) => BigInt(n)));
21178
- const SHA512_Kh = K512[0];
21179
- const SHA512_Kl = K512[1];
21180
- const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
21181
- const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
21182
- /** Internal SHA-384 / SHA-512 compression engine from RFC 6234 §6.4. */
21183
- var SHA2_64B = class extends HashMD {
21184
- constructor(outputLen) {
21185
- super(128, outputLen, 16, false);
21186
- }
21187
- get() {
21188
- const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
21189
- return [
21190
- Ah,
21191
- Al,
21192
- Bh,
21193
- Bl,
21194
- Ch,
21195
- Cl,
21196
- Dh,
21197
- Dl,
21198
- Eh,
21199
- El,
21200
- Fh,
21201
- Fl,
21202
- Gh,
21203
- Gl,
21204
- Hh,
21205
- Hl
21206
- ];
21207
- }
21208
- set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
21209
- this.Ah = Ah | 0;
21210
- this.Al = Al | 0;
21211
- this.Bh = Bh | 0;
21212
- this.Bl = Bl | 0;
21213
- this.Ch = Ch | 0;
21214
- this.Cl = Cl | 0;
21215
- this.Dh = Dh | 0;
21216
- this.Dl = Dl | 0;
21217
- this.Eh = Eh | 0;
21218
- this.El = El | 0;
21219
- this.Fh = Fh | 0;
21220
- this.Fl = Fl | 0;
21221
- this.Gh = Gh | 0;
21222
- this.Gl = Gl | 0;
21223
- this.Hh = Hh | 0;
21224
- this.Hl = Hl | 0;
21225
- }
21226
- process(view, offset) {
21227
- for (let i = 0; i < 16; i++, offset += 4) {
21228
- SHA512_W_H[i] = view.getUint32(offset);
21229
- SHA512_W_L[i] = view.getUint32(offset += 4);
21230
- }
21231
- for (let i = 16; i < 80; i++) {
21232
- const W15h = SHA512_W_H[i - 15] | 0;
21233
- const W15l = SHA512_W_L[i - 15] | 0;
21234
- const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
21235
- const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
21236
- const W2h = SHA512_W_H[i - 2] | 0;
21237
- const W2l = SHA512_W_L[i - 2] | 0;
21238
- const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
21239
- const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
21240
- const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
21241
- SHA512_W_H[i] = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]) | 0;
21242
- SHA512_W_L[i] = SUMl | 0;
21243
- }
21244
- let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
21245
- for (let i = 0; i < 80; i++) {
21246
- const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
21247
- const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
21248
- const CHIh = Eh & Fh ^ ~Eh & Gh;
21249
- const CHIl = El & Fl ^ ~El & Gl;
21250
- const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
21251
- const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
21252
- const T1l = T1ll | 0;
21253
- const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
21254
- const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
21255
- const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
21256
- const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
21257
- Hh = Gh | 0;
21258
- Hl = Gl | 0;
21259
- Gh = Fh | 0;
21260
- Gl = Fl | 0;
21261
- Fh = Eh | 0;
21262
- Fl = El | 0;
21263
- ({h: Eh, l: El} = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
21264
- Dh = Ch | 0;
21265
- Dl = Cl | 0;
21266
- Ch = Bh | 0;
21267
- Cl = Bl | 0;
21268
- Bh = Ah | 0;
21269
- Bl = Al | 0;
21270
- const All = add3L(T1l, sigma0l, MAJl);
21271
- Ah = add3H(All, T1h, sigma0h, MAJh);
21272
- Al = All | 0;
21273
- }
21274
- ({h: Ah, l: Al} = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
21275
- ({h: Bh, l: Bl} = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
21276
- ({h: Ch, l: Cl} = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
21277
- ({h: Dh, l: Dl} = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
21278
- ({h: Eh, l: El} = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
21279
- ({h: Fh, l: Fl} = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
21280
- ({h: Gh, l: Gl} = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
21281
- ({h: Hh, l: Hl} = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
21282
- this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
21283
- }
21284
- roundClean() {
21285
- clean(SHA512_W_H, SHA512_W_L);
21286
- }
21287
- destroy() {
21288
- this.destroyed = true;
21289
- clean(this.buffer);
21290
- this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
21291
- }
21292
- };
21293
- /** Internal SHA-512 hash class grounded in RFC 6234 §6.3 and §6.4. */
21294
- var _SHA512 = class extends SHA2_64B {
21295
- Ah = SHA512_IV[0] | 0;
21296
- Al = SHA512_IV[1] | 0;
21297
- Bh = SHA512_IV[2] | 0;
21298
- Bl = SHA512_IV[3] | 0;
21299
- Ch = SHA512_IV[4] | 0;
21300
- Cl = SHA512_IV[5] | 0;
21301
- Dh = SHA512_IV[6] | 0;
21302
- Dl = SHA512_IV[7] | 0;
21303
- Eh = SHA512_IV[8] | 0;
21304
- El = SHA512_IV[9] | 0;
21305
- Fh = SHA512_IV[10] | 0;
21306
- Fl = SHA512_IV[11] | 0;
21307
- Gh = SHA512_IV[12] | 0;
21308
- Gl = SHA512_IV[13] | 0;
21309
- Hh = SHA512_IV[14] | 0;
21310
- Hl = SHA512_IV[15] | 0;
21311
- constructor() {
21312
- super(64);
21313
- }
21314
- };
21315
- /**
21316
- * SHA2-512 hash function from RFC 4634.
21317
- * @param msg - message bytes to hash
21318
- * @returns Digest bytes.
21319
- * @example
21320
- * Hash a message with SHA2-512.
21321
- * ```ts
21322
- * sha512(new Uint8Array([97, 98, 99]));
21323
- * ```
21324
- */
21325
- const sha512 = /* @__PURE__ */ createHasher(() => new _SHA512(), /* @__PURE__ */ oidNist(3));
21326
-
21327
- //#endregion
21328
- //#region packages/mcp/src/crypto.ts
21329
- /**
21330
- * Ed25519 key generation, persistence, and challenge signing for MCP agent auth.
21331
- */
21332
- hashes.sha512 = sha512;
21333
- hashes.sha512Async = (m) => Promise.resolve(sha512(m));
21334
- const DEFAULT_KEY_PATH = join(homedir(), ".abracadabra", "agent.key");
21335
- function toBase64url(bytes) {
21336
- return Buffer.from(bytes).toString("base64url");
21337
- }
21338
- function fromBase64url(b64) {
21339
- return new Uint8Array(Buffer.from(b64, "base64url"));
21340
- }
21341
- /**
21342
- * Load an existing Ed25519 keypair from disk, or generate and persist a new one.
21343
- * The file stores the raw 32-byte private key seed.
21344
- */
21345
- async function loadOrCreateKeypair(keyPath) {
21346
- const path = keyPath || DEFAULT_KEY_PATH;
21347
- if (existsSync(path)) {
21348
- const seed = await readFile(path);
21349
- if (seed.length !== 32) throw new Error(`Invalid key file at ${path}: expected 32 bytes, got ${seed.length}`);
21350
- const privateKey = new Uint8Array(seed);
21351
- return {
21352
- privateKey,
21353
- publicKeyB64: toBase64url(getPublicKey(privateKey))
21354
- };
21355
- }
21356
- const privateKey = utils.randomSecretKey();
21357
- const publicKey = getPublicKey(privateKey);
21358
- const dir = dirname(path);
21359
- if (!existsSync(dir)) await mkdir(dir, {
21360
- recursive: true,
21361
- mode: 448
21362
- });
21363
- await writeFile(path, Buffer.from(privateKey), { mode: 384 });
21364
- console.error(`[abracadabra-mcp] Generated new agent keypair at ${path}`);
21365
- console.error(`[abracadabra-mcp] Public key: ${toBase64url(publicKey)}`);
21366
- return {
21367
- privateKey,
21368
- publicKeyB64: toBase64url(publicKey)
21369
- };
21370
- }
21371
- /** Sign a base64url challenge with the agent's private key; returns base64url signature. */
21372
- function signChallenge(challengeB64, privateKey) {
21373
- const challenge = fromBase64url(challengeB64);
21374
- return toBase64url(sign(challenge, privateKey));
21375
- }
21376
-
21377
20135
  //#endregion
21378
20136
  //#region packages/mcp/src/mentions.ts
21379
20137
  /**
@@ -21415,34 +20173,6 @@ function stripMention(text, aliases) {
21415
20173
  return text.replace(re, (_m, lead) => lead ? " " : "").replace(/\s{2,}/g, " ").trim();
21416
20174
  }
21417
20175
 
21418
- //#endregion
21419
- //#region packages/mcp/src/utils.ts
21420
- /**
21421
- * Wait for a provider's `synced` event with a timeout.
21422
- *
21423
- * Mirrors `@abraca/dabra`'s `DocUtils.waitForSync`: the `isSynced` short-circuit
21424
- * is load-bearing. `synced` is emitted once per sync transition (and deferred a
21425
- * microtask), so a provider that has ALREADY synced — e.g. the cached child
21426
- * provider that `loadChild` returns on a repeat read/write of the same doc —
21427
- * will never re-emit. Without this guard those callers block for the full
21428
- * `timeoutMs` ("works once, then every later op on that doc times out at 15s").
21429
- */
21430
- function waitForSync(provider, timeoutMs = 15e3) {
21431
- if (provider.isSynced) return Promise.resolve();
21432
- return new Promise((resolve, reject) => {
21433
- const timer = setTimeout(() => {
21434
- provider.off("synced", handler);
21435
- reject(/* @__PURE__ */ new Error(`Sync timed out after ${timeoutMs}ms`));
21436
- }, timeoutMs);
21437
- function handler() {
21438
- clearTimeout(timer);
21439
- provider.off("synced", handler);
21440
- resolve();
21441
- }
21442
- provider.on("synced", handler);
21443
- });
21444
- }
21445
-
21446
20176
  //#endregion
21447
20177
  //#region packages/mcp/src/server.ts
21448
20178
  const IDLE_TIMEOUT_MS = 300 * 1e3;
@@ -21525,32 +20255,25 @@ var AbracadabraMCPServer = class AbracadabraMCPServer {
21525
20255
  }
21526
20256
  /** Start the server: authenticate with Ed25519 key, discover spaces/root doc, connect provider. */
21527
20257
  async connect() {
21528
- const keypair = await loadOrCreateKeypair(this.config.keyFile);
20258
+ const keypair = await loadOrCreateKeyFile(this.config.keyFile, {
20259
+ defaultFileName: "agent.key",
20260
+ onCreate: ({ path, publicKeyB64 }) => {
20261
+ console.error(`[abracadabra-mcp] Generated new agent keypair at ${path}`);
20262
+ console.error(`[abracadabra-mcp] Public key: ${publicKeyB64}`);
20263
+ }
20264
+ });
21529
20265
  this._userId = keypair.publicKeyB64;
21530
- const signFn = (challenge) => Promise.resolve(signChallenge(challenge, keypair.privateKey));
21531
- this._signFn = signFn;
21532
- try {
21533
- await this.client.loginWithKey(keypair.publicKeyB64, signFn);
21534
- } catch (err) {
21535
- const status = err?.status ?? err?.response?.status;
21536
- const msg = String(err?.message ?? "").toLowerCase();
21537
- if (status === 404 || status === 422 || status === 401 && /not registered|user not found|no such user/.test(msg)) {
21538
- console.error("[abracadabra-mcp] Key not registered, creating new account...");
21539
- await this.client.registerWithKey({
21540
- publicKey: keypair.publicKeyB64,
21541
- username: this.agentName.replace(/\s+/g, "-").toLowerCase(),
21542
- displayName: this.agentName,
21543
- deviceName: "MCP Agent",
21544
- inviteCode: this.config.inviteCode
21545
- });
21546
- await this.client.loginWithKey(keypair.publicKeyB64, signFn);
21547
- } else throw err;
21548
- }
20266
+ this._signFn = makeChallengeSigner(keypair);
20267
+ await loginOrRegisterWithKey(this.client, keypair, {
20268
+ displayName: this.agentName,
20269
+ deviceName: "MCP Agent",
20270
+ inviteCode: this.config.inviteCode,
20271
+ onRegister: () => console.error("[abracadabra-mcp] Key not registered, creating new account...")
20272
+ });
21549
20273
  console.error(`[abracadabra-mcp] Authenticated as ${this.agentName} (pubkey=${keypair.publicKeyB64})`);
21550
20274
  this._serverInfo = await this.client.serverInfo();
21551
- const roots = await this.client.listChildren();
21552
- this._spaces = roots.filter((d) => d.kind === Kind.Space);
21553
- const first = this._spaces[0] ?? roots[0];
20275
+ const { entry: first, spaces } = pickEntrySpace(await this.client.listChildren());
20276
+ this._spaces = spaces;
21554
20277
  const initialDocId = first?.id ?? null;
21555
20278
  if (first) console.error(`[abracadabra-mcp] Active space: ${first.label ?? first.id} (${first.id})`);
21556
20279
  if (!initialDocId) throw new Error(`No entry point found: server has no top-level documents under ${SERVER_ROOT_ID}. Create a Space first.`);
@@ -21576,15 +20299,10 @@ var AbracadabraMCPServer = class AbracadabraMCPServer {
21576
20299
  await this.client.loginWithKey(this._userId, this._signFn);
21577
20300
  console.error("[abracadabra-mcp] Re-authenticated successfully");
21578
20301
  }
21579
- const doc = new Y.Doc({ guid: docId });
21580
- const provider = new AbracadabraProvider({
21581
- name: docId,
21582
- document: doc,
20302
+ const { doc, provider } = await openSyncedProvider({
21583
20303
  client: this.client,
21584
- disableOfflineStore: true,
21585
- subdocLoading: "lazy"
20304
+ docId
21586
20305
  });
21587
- await waitForSync(provider);
21588
20306
  provider.awareness.setLocalStateField("user", {
21589
20307
  name: this.agentName,
21590
20308
  color: this.agentColor,
@@ -23201,782 +21919,16 @@ function registerSvgTools(mcp, server) {
23201
21919
  });
23202
21920
  }
23203
21921
 
23204
- //#endregion
23205
- //#region packages/mcp/src/converters/page-types.ts
23206
- const PAGE_TYPES = {
23207
- doc: {
23208
- key: "doc",
23209
- label: "Document",
23210
- icon: "file-text",
23211
- description: "Rich text document with real-time collaboration",
23212
- core: true,
23213
- supportsChildren: true
23214
- },
23215
- prose: {
23216
- key: "prose",
23217
- label: "Prose",
23218
- icon: "pen-tool",
23219
- description: "Long-form prose with serif typography and a narrow readable measure",
23220
- core: true,
23221
- supportsChildren: true,
23222
- childLabel: "Item",
23223
- defaultDepth: -1
23224
- },
23225
- kanban: {
23226
- key: "kanban",
23227
- label: "Kanban",
23228
- icon: "kanban",
23229
- description: "Drag-and-drop task board with columns and cards",
23230
- core: true,
23231
- supportsChildren: true,
23232
- childLabel: "Column",
23233
- grandchildLabel: "Card",
23234
- defaultMetaFields: [{
23235
- type: "select",
23236
- key: "kanbanColumnWidth",
23237
- options: [
23238
- "narrow",
23239
- "default",
23240
- "wide"
23241
- ],
23242
- label: "Column Width"
23243
- }]
23244
- },
23245
- gallery: {
23246
- key: "gallery",
23247
- label: "Gallery",
23248
- icon: "images",
23249
- description: "Visual grid of items with rich content",
23250
- core: true,
23251
- supportsChildren: true,
23252
- childLabel: "Item",
23253
- metaSchema: [
23254
- {
23255
- type: "location",
23256
- latKey: "geoLat",
23257
- lngKey: "geoLng",
23258
- label: "Location"
23259
- },
23260
- {
23261
- type: "datetime",
23262
- key: "datetimeStart",
23263
- label: "Date"
23264
- },
23265
- {
23266
- type: "tags",
23267
- key: "tags",
23268
- label: "Tags"
23269
- },
23270
- {
23271
- type: "rating",
23272
- key: "rating",
23273
- max: 5,
23274
- label: "Rating"
23275
- },
23276
- {
23277
- type: "icon",
23278
- key: "icon",
23279
- label: "Icon"
23280
- },
23281
- {
23282
- type: "colorPreset",
23283
- key: "color",
23284
- presets: [
23285
- "#6366f1",
23286
- "#ec4899",
23287
- "#f97316",
23288
- "#22c55e",
23289
- "#3b82f6",
23290
- "#a855f7"
23291
- ],
23292
- label: "Color"
23293
- }
23294
- ],
23295
- defaultMetaFields: [
23296
- {
23297
- type: "number",
23298
- key: "galleryColumns",
23299
- min: 1,
23300
- max: 6,
23301
- step: 1,
23302
- label: "Columns"
23303
- },
23304
- {
23305
- type: "select",
23306
- key: "galleryAspect",
23307
- options: [
23308
- "square",
23309
- "4:3",
23310
- "3:2",
23311
- "16:9",
23312
- "free"
23313
- ],
23314
- label: "Aspect Ratio"
23315
- },
23316
- {
23317
- type: "select",
23318
- key: "galleryCardStyle",
23319
- options: [
23320
- "default",
23321
- "compact",
23322
- "detailed"
23323
- ],
23324
- label: "Card Style"
23325
- },
23326
- {
23327
- type: "toggle",
23328
- key: "galleryShowLabels",
23329
- label: "Show Labels"
23330
- },
23331
- {
23332
- type: "select",
23333
- key: "gallerySortBy",
23334
- options: [
23335
- "manual",
23336
- "date",
23337
- "name",
23338
- "rating"
23339
- ],
23340
- label: "Sort"
23341
- }
23342
- ]
23343
- },
23344
- table: {
23345
- key: "table",
23346
- label: "Table",
23347
- icon: "table",
23348
- description: "Collaborative spreadsheet with custom fields",
23349
- core: true,
23350
- supportsChildren: true,
23351
- childLabel: "Column",
23352
- grandchildLabel: "Row",
23353
- defaultMetaFields: [{
23354
- type: "select",
23355
- key: "tableMode",
23356
- options: ["hierarchy", "flat"],
23357
- label: "Mode"
23358
- }, {
23359
- type: "select",
23360
- key: "tableSortDir",
23361
- options: ["asc", "desc"],
23362
- label: "Sort Direction"
23363
- }]
23364
- },
23365
- outline: {
23366
- key: "outline",
23367
- label: "Outline",
23368
- icon: "list-tree",
23369
- description: "Hierarchical outline with keyboard navigation",
23370
- core: true,
23371
- supportsChildren: true,
23372
- childLabel: "Item",
23373
- defaultDepth: -1
23374
- },
23375
- checklist: {
23376
- key: "checklist",
23377
- label: "Checklist",
23378
- icon: "check-square",
23379
- description: "Collaborative checklist with sub-tasks, drag-and-drop, and due dates",
23380
- core: true,
23381
- supportsChildren: true,
23382
- childLabel: "Task",
23383
- defaultDepth: -1,
23384
- metaSchema: [
23385
- {
23386
- type: "toggle",
23387
- key: "checked",
23388
- label: "Done"
23389
- },
23390
- {
23391
- type: "select",
23392
- key: "priority",
23393
- options: [
23394
- "none",
23395
- "low",
23396
- "medium",
23397
- "high"
23398
- ],
23399
- label: "Priority"
23400
- },
23401
- {
23402
- type: "date",
23403
- key: "dateEnd",
23404
- label: "Due date"
23405
- }
23406
- ],
23407
- defaultMetaFields: [{
23408
- type: "select",
23409
- key: "checklistFilter",
23410
- options: [
23411
- "all",
23412
- "active",
23413
- "completed"
23414
- ],
23415
- label: "Filter"
23416
- }, {
23417
- type: "select",
23418
- key: "checklistSort",
23419
- options: [
23420
- "manual",
23421
- "priority",
23422
- "due"
23423
- ],
23424
- label: "Sort"
23425
- }]
23426
- },
23427
- graph: {
23428
- key: "graph",
23429
- label: "Graph",
23430
- icon: "git-fork",
23431
- description: "Force-directed knowledge graph — full document tree as nodes & edges",
23432
- core: true,
23433
- supportsChildren: true,
23434
- childLabel: "Node",
23435
- defaultMetaFields: [{
23436
- type: "toggle",
23437
- key: "showRefEdges",
23438
- label: "Show Ref Edges",
23439
- default: true
23440
- }]
23441
- },
23442
- timeline: {
23443
- key: "timeline",
23444
- label: "Timeline",
23445
- icon: "gantt-chart",
23446
- description: "Gantt-style project timeline with epics and tasks",
23447
- core: true,
23448
- supportsChildren: true,
23449
- childLabel: "Epic",
23450
- grandchildLabel: "Task",
23451
- metaSchema: [
23452
- {
23453
- type: "daterange",
23454
- startKey: "dateStart",
23455
- endKey: "dateEnd"
23456
- },
23457
- {
23458
- type: "slider",
23459
- key: "taskProgress",
23460
- min: 0,
23461
- max: 100,
23462
- label: "Progress"
23463
- },
23464
- {
23465
- type: "colorPreset",
23466
- key: "color",
23467
- presets: [
23468
- "#6366f1",
23469
- "#818cf8",
23470
- "#f97316",
23471
- "#22c55e",
23472
- "#3b82f6",
23473
- "#a855f7"
23474
- ],
23475
- label: "Color"
23476
- }
23477
- ]
23478
- },
23479
- calendar: {
23480
- key: "calendar",
23481
- label: "Calendar",
23482
- icon: "calendar",
23483
- description: "Event calendar with month, week, and day views",
23484
- core: true,
23485
- supportsChildren: true,
23486
- childLabel: "Event",
23487
- metaSchema: [
23488
- {
23489
- type: "datetimerange",
23490
- startKey: "datetimeStart",
23491
- endKey: "datetimeEnd",
23492
- allDayKey: "allDay"
23493
- },
23494
- {
23495
- type: "colorPreset",
23496
- key: "color",
23497
- presets: [
23498
- "#6366f1",
23499
- "#ec4899",
23500
- "#f97316",
23501
- "#22c55e",
23502
- "#3b82f6",
23503
- "#a855f7"
23504
- ],
23505
- label: "Color"
23506
- },
23507
- {
23508
- type: "icon",
23509
- key: "icon",
23510
- label: "Icon"
23511
- }
23512
- ],
23513
- defaultMetaFields: [
23514
- {
23515
- type: "select",
23516
- key: "calendarWeekStart",
23517
- options: ["sun", "mon"],
23518
- label: "Week Starts"
23519
- },
23520
- {
23521
- type: "select",
23522
- key: "calendarView",
23523
- options: [
23524
- "month",
23525
- "week",
23526
- "day"
23527
- ],
23528
- label: "Default View"
23529
- },
23530
- {
23531
- type: "toggle",
23532
- key: "calendarShowWeekNumbers",
23533
- label: "Show Week Numbers"
23534
- }
23535
- ]
23536
- },
23537
- map: {
23538
- key: "map",
23539
- label: "Map",
23540
- icon: "map",
23541
- description: "Collaborative world map with shared markers",
23542
- core: true,
23543
- supportsChildren: true,
23544
- childLabel: "Location",
23545
- defaultMetaFields: [{
23546
- type: "toggle",
23547
- key: "mapShowLabels",
23548
- label: "Show Labels",
23549
- default: true
23550
- }]
23551
- },
23552
- dashboard: {
23553
- key: "dashboard",
23554
- label: "Dashboard",
23555
- icon: "layout-dashboard",
23556
- description: "Arrange documents as draggable icons with optional widget views",
23557
- core: true,
23558
- supportsChildren: true,
23559
- childLabel: "Item"
23560
- },
23561
- call: {
23562
- key: "call",
23563
- label: "Call",
23564
- icon: "phone",
23565
- description: "Video call room with live audio and screen sharing",
23566
- core: true,
23567
- supportsChildren: false
23568
- },
23569
- chart: {
23570
- key: "chart",
23571
- label: "Chart",
23572
- icon: "bar-chart-3",
23573
- description: "Charts — manual data points or aggregation over document trees",
23574
- core: true,
23575
- supportsChildren: true,
23576
- childLabel: "Data Point",
23577
- grandchildLabel: "Data Point",
23578
- metaSchema: [
23579
- {
23580
- type: "number",
23581
- key: "number",
23582
- step: .01,
23583
- label: "Value"
23584
- },
23585
- {
23586
- type: "colorPreset",
23587
- key: "color",
23588
- presets: [
23589
- "#6366f1",
23590
- "#ec4899",
23591
- "#f97316",
23592
- "#22c55e",
23593
- "#3b82f6",
23594
- "#a855f7",
23595
- "#14b8a6",
23596
- "#eab308"
23597
- ],
23598
- label: "Color"
23599
- },
23600
- {
23601
- type: "tags",
23602
- key: "tags",
23603
- label: "Tags"
23604
- }
23605
- ],
23606
- defaultMetaFields: [
23607
- {
23608
- type: "select",
23609
- key: "chartType",
23610
- options: [
23611
- "bar",
23612
- "stacked bar",
23613
- "line",
23614
- "donut",
23615
- "treemap"
23616
- ],
23617
- label: "Chart Type"
23618
- },
23619
- {
23620
- type: "select",
23621
- key: "chartMetric",
23622
- options: [
23623
- "value",
23624
- "type",
23625
- "tag",
23626
- "status",
23627
- "priority",
23628
- "activity",
23629
- "completion"
23630
- ],
23631
- label: "Metric"
23632
- },
23633
- {
23634
- type: "select",
23635
- key: "chartColorScheme",
23636
- options: [
23637
- "default",
23638
- "warm",
23639
- "cool",
23640
- "mono"
23641
- ],
23642
- label: "Colors"
23643
- },
23644
- {
23645
- type: "number",
23646
- key: "chartLimit",
23647
- min: 3,
23648
- max: 30,
23649
- step: 1,
23650
- label: "Max Items"
23651
- },
23652
- {
23653
- type: "toggle",
23654
- key: "chartShowLegend",
23655
- label: "Show Legend",
23656
- default: true
23657
- },
23658
- {
23659
- type: "toggle",
23660
- key: "chartShowValues",
23661
- label: "Show Values"
23662
- }
23663
- ]
23664
- },
23665
- sheets: {
23666
- key: "sheets",
23667
- label: "Sheets",
23668
- icon: "grid-3x3",
23669
- description: "Spreadsheet — cells, formulas, and formatting in a collaborative grid",
23670
- core: true,
23671
- supportsChildren: true,
23672
- childLabel: "Column",
23673
- grandchildLabel: "Cell",
23674
- defaultMetaFields: [
23675
- {
23676
- type: "number",
23677
- key: "sheetsDefaultColWidth",
23678
- min: 40,
23679
- max: 500,
23680
- step: 10,
23681
- label: "Column Width"
23682
- },
23683
- {
23684
- type: "number",
23685
- key: "sheetsDefaultRowHeight",
23686
- min: 20,
23687
- max: 100,
23688
- step: 2,
23689
- label: "Row Height"
23690
- },
23691
- {
23692
- type: "toggle",
23693
- key: "sheetsShowGridlines",
23694
- label: "Gridlines"
23695
- }
23696
- ]
23697
- },
23698
- slides: {
23699
- key: "slides",
23700
- label: "Slides",
23701
- icon: "presentation",
23702
- description: "Presentation slides with two-axis navigation",
23703
- core: true,
23704
- supportsChildren: true,
23705
- childLabel: "Slide",
23706
- grandchildLabel: "Sub-slide",
23707
- metaSchema: [{
23708
- type: "select",
23709
- key: "slidesTransition",
23710
- options: [
23711
- "none",
23712
- "fade",
23713
- "slide"
23714
- ],
23715
- label: "Transition"
23716
- }, {
23717
- type: "colorPreset",
23718
- key: "color",
23719
- presets: [
23720
- "#6366f1",
23721
- "#ec4899",
23722
- "#f97316",
23723
- "#22c55e",
23724
- "#3b82f6",
23725
- "#a855f7"
23726
- ],
23727
- label: "Accent"
23728
- }],
23729
- defaultMetaFields: [{
23730
- type: "select",
23731
- key: "slidesTheme",
23732
- options: ["dark", "light"],
23733
- label: "Theme"
23734
- }]
23735
- },
23736
- overview: {
23737
- key: "overview",
23738
- label: "Overview",
23739
- icon: "radar",
23740
- description: "Space home — activity, people, stats, and health at a glance",
23741
- core: true,
23742
- supportsChildren: true,
23743
- childLabel: "Page"
23744
- },
23745
- spatial: {
23746
- key: "spatial",
23747
- label: "Spatial",
23748
- icon: "box",
23749
- description: "3D scene with collaborative objects and real-time presence",
23750
- core: false,
23751
- plugin: "spatial",
23752
- supportsChildren: true,
23753
- childLabel: "Object",
23754
- grandchildLabel: "Part",
23755
- defaultDepth: -1,
23756
- metaSchema: [
23757
- {
23758
- type: "select",
23759
- key: "spShape",
23760
- options: [
23761
- "box",
23762
- "sphere",
23763
- "cylinder",
23764
- "cone",
23765
- "plane",
23766
- "torus",
23767
- "glb"
23768
- ],
23769
- label: "Shape"
23770
- },
23771
- {
23772
- type: "colorPreset",
23773
- key: "color",
23774
- presets: [
23775
- "#6366f1",
23776
- "#ef4444",
23777
- "#22c55e",
23778
- "#3b82f6",
23779
- "#f97316",
23780
- "#a855f7",
23781
- "#ec4899",
23782
- "#14b8a6"
23783
- ],
23784
- label: "Color"
23785
- },
23786
- {
23787
- type: "slider",
23788
- key: "spOpacity",
23789
- min: 0,
23790
- max: 100,
23791
- label: "Opacity"
23792
- },
23793
- {
23794
- type: "number",
23795
- key: "spX",
23796
- step: .1,
23797
- label: "X"
23798
- },
23799
- {
23800
- type: "number",
23801
- key: "spY",
23802
- step: .1,
23803
- label: "Y"
23804
- },
23805
- {
23806
- type: "number",
23807
- key: "spZ",
23808
- step: .1,
23809
- label: "Z"
23810
- },
23811
- {
23812
- type: "number",
23813
- key: "spRX",
23814
- min: -180,
23815
- max: 180,
23816
- step: 1,
23817
- label: "Rot X"
23818
- },
23819
- {
23820
- type: "number",
23821
- key: "spRY",
23822
- min: -180,
23823
- max: 180,
23824
- step: 1,
23825
- label: "Rot Y"
23826
- },
23827
- {
23828
- type: "number",
23829
- key: "spRZ",
23830
- min: -180,
23831
- max: 180,
23832
- step: 1,
23833
- label: "Rot Z"
23834
- },
23835
- {
23836
- type: "number",
23837
- key: "spSX",
23838
- min: .01,
23839
- max: 100,
23840
- step: .1,
23841
- label: "Scale X"
23842
- },
23843
- {
23844
- type: "number",
23845
- key: "spSY",
23846
- min: .01,
23847
- max: 100,
23848
- step: .1,
23849
- label: "Scale Y"
23850
- },
23851
- {
23852
- type: "number",
23853
- key: "spSZ",
23854
- min: .01,
23855
- max: 100,
23856
- step: .1,
23857
- label: "Scale Z"
23858
- }
23859
- ],
23860
- defaultMetaFields: [{
23861
- type: "toggle",
23862
- key: "spatialGridVisible",
23863
- label: "Show Grid",
23864
- default: true
23865
- }]
23866
- },
23867
- media: {
23868
- key: "media",
23869
- label: "Media",
23870
- icon: "disc-3",
23871
- description: "Media player with synced listening and playlists",
23872
- core: false,
23873
- plugin: "media",
23874
- supportsChildren: true,
23875
- childLabel: "Track",
23876
- defaultDepth: -1,
23877
- metaSchema: [{
23878
- type: "tags",
23879
- key: "tags",
23880
- label: "Tags"
23881
- }],
23882
- defaultMetaFields: [{
23883
- type: "select",
23884
- key: "mediaRepeat",
23885
- options: [
23886
- "off",
23887
- "all",
23888
- "one"
23889
- ],
23890
- label: "Repeat"
23891
- }, {
23892
- type: "toggle",
23893
- key: "mediaShuffle",
23894
- label: "Shuffle"
23895
- }]
23896
- },
23897
- coder: {
23898
- key: "coder",
23899
- label: "Coder",
23900
- icon: "code-2",
23901
- description: "Collaborative multi-file coding environment",
23902
- core: false,
23903
- plugin: "coder",
23904
- supportsChildren: true,
23905
- childLabel: "File",
23906
- defaultDepth: -1,
23907
- metaSchema: [{
23908
- type: "select",
23909
- key: "fileType",
23910
- options: [
23911
- "vue",
23912
- "ts",
23913
- "js",
23914
- "css",
23915
- "json",
23916
- "folder"
23917
- ],
23918
- label: "Type"
23919
- }, {
23920
- type: "toggle",
23921
- key: "entry",
23922
- label: "Entry Point"
23923
- }]
23924
- }
23925
- };
23926
- const TYPE_ALIASES = { desktop: "dashboard" };
23927
- function resolvePageType(key) {
23928
- if (!key) return void 0;
23929
- return PAGE_TYPES[TYPE_ALIASES[key] ?? key];
23930
- }
23931
-
23932
21922
  //#endregion
23933
21923
  //#region packages/mcp/src/tools/tree.ts
23934
21924
  /**
23935
- * Document tree tools — operate on the root Y.Doc's "doc-tree" Y.Map.
23936
- */
23937
- /**
23938
- * Normalize a document ID so the hub/root doc ID is treated as the tree root (null).
23939
- * This lets callers pass the hub doc_id from list_spaces as parentId/rootId
23940
- * and get the expected root-level results instead of an empty set.
23941
- */
23942
- function normalizeRootId(id, server) {
23943
- if (id == null) return null;
23944
- return id === server.rootDocId ? null : id;
23945
- }
23946
- /** Safely read a tree map value, converting Y.Map to plain object if needed. */
23947
- function toPlain$1(val) {
23948
- return val instanceof Y.Map ? val.toJSON() : val;
23949
- }
23950
- /**
23951
- * Read every doc-tree entry, optionally skipping the space's self-descriptor.
23952
- *
23953
- * A space's own `doc-tree` Y.Map holds an entry keyed by the space's OWN id
23954
- * (the connected root doc), with `parentId: null` and `order: -1`. It stores
23955
- * the space root's own icon/color/type/label — it is NOT a child document.
23956
- * Because its `parentId` is null it otherwise shows up alongside real
23957
- * top-level docs, making the space render as a phantom first child of itself
23958
- * ("Health space's first document is 'Development'"). Pass `selfId =
23959
- * server.rootDocId` to drop it. cou-sh's DocumentTree applies the same guard
23960
- * (`if (id === spaceDocId) continue`).
21925
+ * Normalize a document ID so the hub/root doc ID is treated as the tree root
21926
+ * (null). This lets callers pass the hub doc_id from list_spaces as
21927
+ * parentId/rootId and get the expected root-level results instead of an empty
21928
+ * set. Thin adapter over `@abraca/dabra`'s `normalizeRootId`.
23961
21929
  */
23962
- function readEntries(treeMap, selfId) {
23963
- const entries = [];
23964
- treeMap.forEach((raw, id) => {
23965
- if (selfId && id === selfId) return;
23966
- const value = toPlain$1(raw);
23967
- if (typeof value !== "object" || value === null) return;
23968
- entries.push({
23969
- id,
23970
- label: value.label || "Untitled",
23971
- parentId: value.parentId ?? null,
23972
- order: value.order ?? 0,
23973
- type: value.type,
23974
- meta: value.meta,
23975
- createdAt: value.createdAt,
23976
- updatedAt: value.updatedAt
23977
- });
23978
- });
23979
- return entries;
21930
+ function normalizeRootId$1(id, server) {
21931
+ return normalizeRootId(id, server.rootDocId);
23980
21932
  }
23981
21933
  function childrenOf(entries, parentId) {
23982
21934
  return entries.filter((e) => e.parentId === parentId).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
@@ -24020,8 +21972,8 @@ function registerTreeTools(mcp, server, validator = null) {
24020
21972
  type: "text",
24021
21973
  text: "Not connected"
24022
21974
  }] };
24023
- const targetId = normalizeRootId(parentId, server);
24024
- const children = childrenOf(readEntries(treeMap, server.rootDocId), targetId);
21975
+ const targetId = normalizeRootId$1(parentId, server);
21976
+ const children = childrenOf(readEntries$1(treeMap, server.rootDocId), targetId);
24025
21977
  return { content: [{
24026
21978
  type: "text",
24027
21979
  text: JSON.stringify(children, null, 2)
@@ -24039,9 +21991,9 @@ function registerTreeTools(mcp, server, validator = null) {
24039
21991
  type: "text",
24040
21992
  text: "Not connected"
24041
21993
  }] };
24042
- const targetId = normalizeRootId(rootId, server);
21994
+ const targetId = normalizeRootId$1(rootId, server);
24043
21995
  const maxDepth = depth ?? 3;
24044
- const tree = buildTree(readEntries(treeMap, server.rootDocId), targetId, maxDepth);
21996
+ const tree = buildTree(readEntries$1(treeMap, server.rootDocId), targetId, maxDepth);
24045
21997
  return { content: [{
24046
21998
  type: "text",
24047
21999
  text: JSON.stringify(tree, null, 2)
@@ -24062,9 +22014,9 @@ function registerTreeTools(mcp, server, validator = null) {
24062
22014
  type: "text",
24063
22015
  text: "Not connected"
24064
22016
  }] };
24065
- const entries = readEntries(treeMap, server.rootDocId);
22017
+ const entries = readEntries$1(treeMap, server.rootDocId);
24066
22018
  const lowerQuery = query.toLowerCase();
24067
- const normalizedRoot = normalizeRootId(rootId, server);
22019
+ const normalizedRoot = normalizeRootId$1(rootId, server);
24068
22020
  const matches = (normalizedRoot ? descendantsOf(entries, normalizedRoot) : entries).filter((e) => e.label.toLowerCase().includes(lowerQuery));
24069
22021
  const byId = new Map(entries.map((e) => [e.id, e]));
24070
22022
  const results = matches.map((entry) => {
@@ -24161,7 +22113,7 @@ function registerTreeTools(mcp, server, validator = null) {
24161
22113
  };
24162
22114
  }
24163
22115
  const id = crypto.randomUUID();
24164
- const normalizedParent = normalizeRootId(parentId, server);
22116
+ const normalizedParent = normalizeRootId$1(parentId, server);
24165
22117
  const now = Date.now();
24166
22118
  if (normalizedParent && !treeMap.has(normalizedParent)) return {
24167
22119
  content: [{
@@ -24263,7 +22215,7 @@ function registerTreeTools(mcp, server, validator = null) {
24263
22215
  type: "text",
24264
22216
  text: `Document ${id} not found`
24265
22217
  }] };
24266
- const normalizedParent = normalizeRootId(newParentId, server);
22218
+ const normalizedParent = normalizeRootId$1(newParentId, server);
24267
22219
  if (normalizedParent && !treeMap.has(normalizedParent)) return {
24268
22220
  content: [{
24269
22221
  type: "text",
@@ -24302,13 +22254,13 @@ function registerTreeTools(mcp, server, validator = null) {
24302
22254
  type: "text",
24303
22255
  text: "Not connected"
24304
22256
  }] };
24305
- const toDelete = [id, ...descendantsOf(readEntries(treeMap, server.rootDocId), id).map((e) => e.id)];
22257
+ const toDelete = [id, ...descendantsOf(readEntries$1(treeMap, server.rootDocId), id).map((e) => e.id)];
24306
22258
  const now = Date.now();
24307
22259
  rootDoc.transact(() => {
24308
22260
  for (const nid of toDelete) {
24309
22261
  const raw = treeMap.get(nid);
24310
22262
  if (!raw) continue;
24311
- const entry = toPlain$1(raw);
22263
+ const entry = toPlain(raw);
24312
22264
  trashMap.set(nid, {
24313
22265
  label: entry.label || "Untitled",
24314
22266
  parentId: entry.parentId ?? null,
@@ -24403,7 +22355,7 @@ function registerTreeTools(mcp, server, validator = null) {
24403
22355
  type: "text",
24404
22356
  text: `Document ${id} not found`
24405
22357
  }] };
24406
- const entry = toPlain$1(raw);
22358
+ const entry = toPlain(raw);
24407
22359
  const newId = crypto.randomUUID();
24408
22360
  treeMap.set(newId, makeEntryMap({
24409
22361
  ...entry,