@abraca/mcp 2.34.0 → 2.35.1

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