@dxos/keys 0.8.4-main.84f28bd → 0.8.4-main.a4bbb77

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.
@@ -84,27 +84,148 @@ var require_base32_decode = __commonJS({
84
84
  // src/dxn.ts
85
85
  import { Schema as Schema3 } from "effect";
86
86
  import { devtoolsFormatter, inspectCustom } from "@dxos/debug";
87
- import { invariant as invariant2 } from "@dxos/invariant";
87
+ import { assertArgument, invariant as invariant2 } from "@dxos/invariant";
88
88
 
89
89
  // src/object-id.ts
90
90
  import { Schema } from "effect";
91
- import { ulid } from "ulidx";
91
+ import { monotonicFactory } from "ulidx";
92
+ function _check_private_redeclaration(obj, privateCollection) {
93
+ if (privateCollection.has(obj)) {
94
+ throw new TypeError("Cannot initialize the same private elements twice on an object");
95
+ }
96
+ }
97
+ function _class_apply_descriptor_get(receiver, descriptor) {
98
+ if (descriptor.get) {
99
+ return descriptor.get.call(receiver);
100
+ }
101
+ return descriptor.value;
102
+ }
103
+ function _class_apply_descriptor_set(receiver, descriptor, value) {
104
+ if (descriptor.set) {
105
+ descriptor.set.call(receiver, value);
106
+ } else {
107
+ if (!descriptor.writable) {
108
+ throw new TypeError("attempted to set read only private field");
109
+ }
110
+ descriptor.value = value;
111
+ }
112
+ }
113
+ function _class_check_private_static_field_descriptor(descriptor, action) {
114
+ if (descriptor === void 0) {
115
+ throw new TypeError("attempted to " + action + " private static field before its declaration");
116
+ }
117
+ }
118
+ function _class_extract_field_descriptor(receiver, privateMap, action) {
119
+ if (!privateMap.has(receiver)) {
120
+ throw new TypeError("attempted to " + action + " private field on non-instance");
121
+ }
122
+ return privateMap.get(receiver);
123
+ }
124
+ function _class_private_field_get(receiver, privateMap) {
125
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
126
+ return _class_apply_descriptor_get(receiver, descriptor);
127
+ }
128
+ function _class_private_field_init(obj, privateMap, value) {
129
+ _check_private_redeclaration(obj, privateMap);
130
+ privateMap.set(obj, value);
131
+ }
132
+ function _class_private_field_set(receiver, privateMap, value) {
133
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
134
+ _class_apply_descriptor_set(receiver, descriptor, value);
135
+ return value;
136
+ }
137
+ function _class_static_private_field_spec_get(receiver, classConstructor, descriptor) {
138
+ _class_check_private_static_access(receiver, classConstructor);
139
+ _class_check_private_static_field_descriptor(descriptor, "get");
140
+ return _class_apply_descriptor_get(receiver, descriptor);
141
+ }
142
+ function _class_static_private_field_spec_set(receiver, classConstructor, descriptor, value) {
143
+ _class_check_private_static_access(receiver, classConstructor);
144
+ _class_check_private_static_field_descriptor(descriptor, "set");
145
+ _class_apply_descriptor_set(receiver, descriptor, value);
146
+ return value;
147
+ }
148
+ function _class_check_private_static_access(receiver, classConstructor) {
149
+ if (receiver !== classConstructor) {
150
+ throw new TypeError("Private static access of wrong provenance");
151
+ }
152
+ }
153
+ var _class;
154
+ var _factory;
155
+ var _seedTime;
92
156
  var ObjectIdSchema = Schema.String.pipe(Schema.pattern(/^[0-7][0-9A-HJKMNP-TV-Z]{25}$/i)).annotations({
93
- description: "a Universally Unique Lexicographically Sortable Identifier",
157
+ description: "A Universally Unique Lexicographically Sortable Identifier",
94
158
  pattern: "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
95
159
  });
96
- var ObjectId = class extends ObjectIdSchema {
160
+ var ObjectId = (_class = class extends ObjectIdSchema {
97
161
  static isValid(id) {
98
162
  try {
99
163
  Schema.decodeSync(ObjectId)(id);
100
164
  return true;
101
- } catch (err) {
165
+ } catch {
102
166
  return false;
103
167
  }
104
168
  }
105
169
  static random() {
106
- return ulid();
170
+ return _class_static_private_field_spec_get(this, _class, _factory).call(_class, _class_static_private_field_spec_get(this, _class, _seedTime));
171
+ }
172
+ static dangerouslyDisableRandomness() {
173
+ _class_static_private_field_spec_set(this, _class, _factory, monotonicFactory(makeTestPRNG()));
174
+ _class_static_private_field_spec_set(this, _class, _seedTime, (/* @__PURE__ */ new Date("2025-01-01")).getTime());
175
+ }
176
+ }, _factory = {
177
+ writable: true,
178
+ value: monotonicFactory()
179
+ }, _seedTime = {
180
+ writable: true,
181
+ value: void 0
182
+ }, _class);
183
+ var makeTestPRNG = () => {
184
+ const rng = new SimplePRNG();
185
+ return () => {
186
+ return rng.next();
187
+ };
188
+ };
189
+ var _seed = /* @__PURE__ */ new WeakMap();
190
+ var SimplePRNG = class _SimplePRNG {
191
+ /**
192
+ * Generates the next pseudo-random number in the range [0, 1).
193
+ * @returns A pseudo-random number between 0 (inclusive) and 1 (exclusive).
194
+ */
195
+ next() {
196
+ _class_private_field_set(this, _seed, (_class_static_private_field_spec_get(_SimplePRNG, _SimplePRNG, _a) * _class_private_field_get(this, _seed) + _class_static_private_field_spec_get(_SimplePRNG, _SimplePRNG, _c)) % _class_static_private_field_spec_get(_SimplePRNG, _SimplePRNG, _m));
197
+ return _class_private_field_get(this, _seed) / _class_static_private_field_spec_get(_SimplePRNG, _SimplePRNG, _m);
198
+ }
199
+ /**
200
+ * Resets the generator with a new seed.
201
+ * @param seed - New seed value.
202
+ */
203
+ reset(seed) {
204
+ _class_private_field_set(this, _seed, seed);
107
205
  }
206
+ /**
207
+ * Creates a new PRNG instance.
208
+ * @param seed - Initial seed value. If not provided, uses 0.
209
+ */
210
+ constructor(seed = 0) {
211
+ _class_private_field_init(this, _seed, {
212
+ writable: true,
213
+ value: void 0
214
+ });
215
+ _class_private_field_set(this, _seed, seed);
216
+ }
217
+ };
218
+ var _a = {
219
+ writable: true,
220
+ value: 1664525
221
+ };
222
+ var _c = {
223
+ writable: true,
224
+ value: 1013904223
225
+ };
226
+ var _m = {
227
+ writable: true,
228
+ value: Math.pow(2, 32)
108
229
  };
109
230
 
110
231
  // src/space-id.ts
@@ -182,121 +303,143 @@ var randomBytes = (length) => {
182
303
  };
183
304
 
184
305
  // src/space-id.ts
306
+ function _define_property(obj, key, value) {
307
+ if (key in obj) {
308
+ Object.defineProperty(obj, key, {
309
+ value,
310
+ enumerable: true,
311
+ configurable: true,
312
+ writable: true
313
+ });
314
+ } else {
315
+ obj[key] = value;
316
+ }
317
+ return obj;
318
+ }
319
+ var _Schema_String_pipe;
320
+ var _class2;
185
321
  var __dxlog_file = "/__w/dxos/dxos/packages/common/keys/src/space-id.ts";
186
322
  var MULTIBASE_PREFIX = "B";
187
323
  var ENCODED_LENGTH = 33;
188
324
  var isValid = (value) => {
189
325
  return typeof value === "string" && value.startsWith(MULTIBASE_PREFIX) && value.length === ENCODED_LENGTH;
190
326
  };
191
- var SpaceId = class extends Schema2.String.pipe(Schema2.filter(isValid)) {
192
- static {
193
- this.byteLength = 20;
194
- }
195
- static {
196
- this.encode = (value) => {
197
- invariant(value instanceof Uint8Array, "Invalid type", {
198
- F: __dxlog_file,
199
- L: 43,
200
- S: this,
201
- A: [
202
- "value instanceof Uint8Array",
203
- "'Invalid type'"
204
- ]
205
- });
206
- invariant(value.length === SpaceId.byteLength, "Invalid length", {
207
- F: __dxlog_file,
208
- L: 44,
209
- S: this,
210
- A: [
211
- "value.length === SpaceId.byteLength",
212
- "'Invalid length'"
213
- ]
214
- });
215
- return MULTIBASE_PREFIX + base32Encode(value, "RFC4648");
216
- };
327
+ var SpaceId = (_class2 = class extends (_Schema_String_pipe = Schema2.String.pipe(Schema2.filter(isValid))) {
328
+ }, _define_property(_class2, "byteLength", 20), _define_property(_class2, "encode", (value) => {
329
+ invariant(value instanceof Uint8Array, "Invalid type", {
330
+ F: __dxlog_file,
331
+ L: 43,
332
+ S: _class2,
333
+ A: [
334
+ "value instanceof Uint8Array",
335
+ "'Invalid type'"
336
+ ]
337
+ });
338
+ invariant(value.length === SpaceId.byteLength, "Invalid length", {
339
+ F: __dxlog_file,
340
+ L: 44,
341
+ S: _class2,
342
+ A: [
343
+ "value.length === SpaceId.byteLength",
344
+ "'Invalid length'"
345
+ ]
346
+ });
347
+ return MULTIBASE_PREFIX + base32Encode(value, "RFC4648");
348
+ }), _define_property(_class2, "decode", (value) => {
349
+ invariant(value.startsWith(MULTIBASE_PREFIX), "Invalid multibase32 encoding", {
350
+ F: __dxlog_file,
351
+ L: 49,
352
+ S: _class2,
353
+ A: [
354
+ "value.startsWith(MULTIBASE_PREFIX)",
355
+ "'Invalid multibase32 encoding'"
356
+ ]
357
+ });
358
+ return new Uint8Array((0, import_base32_decode.default)(value.slice(1), "RFC4648"));
359
+ }), _define_property(_class2, "isValid", isValid), _define_property(_class2, "random", () => {
360
+ return SpaceId.encode(randomBytes(SpaceId.byteLength));
361
+ }), _class2);
362
+
363
+ // src/dxn.ts
364
+ function _check_private_redeclaration2(obj, privateCollection) {
365
+ if (privateCollection.has(obj)) {
366
+ throw new TypeError("Cannot initialize the same private elements twice on an object");
217
367
  }
218
- static {
219
- this.decode = (value) => {
220
- invariant(value.startsWith(MULTIBASE_PREFIX), "Invalid multibase32 encoding", {
221
- F: __dxlog_file,
222
- L: 49,
223
- S: this,
224
- A: [
225
- "value.startsWith(MULTIBASE_PREFIX)",
226
- "'Invalid multibase32 encoding'"
227
- ]
228
- });
229
- return new Uint8Array((0, import_base32_decode.default)(value.slice(1), "RFC4648"));
230
- };
368
+ }
369
+ function _class_apply_descriptor_get2(receiver, descriptor) {
370
+ if (descriptor.get) {
371
+ return descriptor.get.call(receiver);
231
372
  }
232
- static {
233
- this.isValid = isValid;
373
+ return descriptor.value;
374
+ }
375
+ function _class_apply_descriptor_set2(receiver, descriptor, value) {
376
+ if (descriptor.set) {
377
+ descriptor.set.call(receiver, value);
378
+ } else {
379
+ if (!descriptor.writable) {
380
+ throw new TypeError("attempted to set read only private field");
381
+ }
382
+ descriptor.value = value;
234
383
  }
235
- static {
236
- this.random = () => {
237
- return SpaceId.encode(randomBytes(SpaceId.byteLength));
238
- };
384
+ }
385
+ function _class_extract_field_descriptor2(receiver, privateMap, action) {
386
+ if (!privateMap.has(receiver)) {
387
+ throw new TypeError("attempted to " + action + " private field on non-instance");
239
388
  }
240
- };
241
-
242
- // src/dxn.ts
389
+ return privateMap.get(receiver);
390
+ }
391
+ function _class_private_field_get2(receiver, privateMap) {
392
+ var descriptor = _class_extract_field_descriptor2(receiver, privateMap, "get");
393
+ return _class_apply_descriptor_get2(receiver, descriptor);
394
+ }
395
+ function _class_private_field_init2(obj, privateMap, value) {
396
+ _check_private_redeclaration2(obj, privateMap);
397
+ privateMap.set(obj, value);
398
+ }
399
+ function _class_private_field_set2(receiver, privateMap, value) {
400
+ var descriptor = _class_extract_field_descriptor2(receiver, privateMap, "set");
401
+ _class_apply_descriptor_set2(receiver, descriptor, value);
402
+ return value;
403
+ }
404
+ function _define_property2(obj, key, value) {
405
+ if (key in obj) {
406
+ Object.defineProperty(obj, key, {
407
+ value,
408
+ enumerable: true,
409
+ configurable: true,
410
+ writable: true
411
+ });
412
+ } else {
413
+ obj[key] = value;
414
+ }
415
+ return obj;
416
+ }
243
417
  var __dxlog_file2 = "/__w/dxos/dxos/packages/common/keys/src/dxn.ts";
244
418
  var LOCAL_SPACE_TAG = "@";
419
+ var DXN_ECHO_REGEXP = /@(dxn:[a-zA-Z0-p:@]+)/;
245
420
  var QueueSubspaceTags = Object.freeze({
246
421
  DATA: "data",
247
422
  TRACE: "trace"
248
423
  });
424
+ var _kind = /* @__PURE__ */ new WeakMap();
425
+ var _parts = /* @__PURE__ */ new WeakMap();
426
+ var _inspectCustom = inspectCustom;
427
+ var _devtoolsFormatter = devtoolsFormatter;
249
428
  var DXN = class _DXN {
250
- static {
251
- // TODO(dmaretskyi): Should this be a transformation into the DXN type?
252
- this.Schema = Schema3.NonEmptyString.pipe(
253
- Schema3.pattern(/^dxn:([^:]+):(?:[^:]+:?)+[^:]$/),
254
- // TODO(dmaretskyi): To set the format we need to move the annotation IDs out of the echo-schema package.
255
- // FormatAnnotation.set(FormatEnum.DXN),
256
- Schema3.annotations({
257
- title: "DXN",
258
- description: "DXN URI",
259
- examples: [
260
- "dxn:type:example.com/type/MyType",
261
- "dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6"
262
- ]
263
- })
264
- );
265
- }
266
429
  static hash(dxn) {
267
430
  return dxn.toString();
268
431
  }
269
- static {
270
- /**
271
- * Kind constants.
272
- */
273
- this.kind = Object.freeze({
274
- /**
275
- * dxn:type:<type name>[:<version>]
276
- */
277
- TYPE: "type",
278
- /**
279
- * dxn:echo:<space id>:<echo id>
280
- * dxn:echo:@:<echo id>
281
- */
282
- // TODO(burdon): Rename to OBJECT? (BREAKING CHANGE).
283
- // TODO(burdon): Add separate Kind for space.
284
- ECHO: "echo",
285
- /**
286
- * The subspace tag enables us to partition queues by usage within the context of a space.
287
- * dxn:queue:<subspace_tag>:<space_id>:<queue_id>[:object_id]
288
- * dxn:queue:data:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
289
- * dxn:queue:trace:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
290
- */
291
- QUEUE: "queue"
292
- });
293
- }
294
- get kind() {
295
- return this.#kind;
296
- }
432
+ /**
433
+ * Exactly equals.
434
+ */
297
435
  static equals(a, b) {
298
436
  return a.kind === b.kind && a.parts.length === b.parts.length && a.parts.every((part, i) => part === b.parts[i]);
299
437
  }
438
+ static equalsEchoId(a, b) {
439
+ const a1 = a.asEchoDXN();
440
+ const b1 = b.asEchoDXN();
441
+ return !!a1 && !!b1 && a1.echoId === b1.echoId;
442
+ }
300
443
  // TODO(burdon): Rename isValid.
301
444
  static isDXNString(dxn) {
302
445
  return dxn.startsWith("dxn:");
@@ -320,7 +463,7 @@ var DXN = class _DXN {
320
463
  static tryParse(dxn) {
321
464
  try {
322
465
  return _DXN.parse(dxn);
323
- } catch (error) {
466
+ } catch {
324
467
  return void 0;
325
468
  }
326
469
  }
@@ -343,42 +486,30 @@ var DXN = class _DXN {
343
486
  ]);
344
487
  }
345
488
  /**
489
+ * @example `dxn:echo:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6`
490
+ */
491
+ static fromSpaceAndObjectId(spaceId, objectId) {
492
+ assertArgument(SpaceId.isValid(spaceId), `Invalid space ID: ${spaceId}`);
493
+ assertArgument(ObjectId.isValid(objectId), "objectId", `Invalid object ID: ${objectId}`);
494
+ return new _DXN(_DXN.kind.ECHO, [
495
+ spaceId,
496
+ objectId
497
+ ]);
498
+ }
499
+ /**
346
500
  * @example `dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6`
347
501
  */
348
502
  static fromLocalObjectId(id) {
503
+ assertArgument(ObjectId.isValid(id), "id", `Invalid object ID: ${id}`);
349
504
  return new _DXN(_DXN.kind.ECHO, [
350
505
  LOCAL_SPACE_TAG,
351
506
  id
352
507
  ]);
353
508
  }
354
509
  static fromQueue(subspaceTag, spaceId, queueId, objectId) {
355
- invariant2(SpaceId.isValid(spaceId), void 0, {
356
- F: __dxlog_file2,
357
- L: 150,
358
- S: this,
359
- A: [
360
- "SpaceId.isValid(spaceId)",
361
- ""
362
- ]
363
- });
364
- invariant2(ObjectId.isValid(queueId), void 0, {
365
- F: __dxlog_file2,
366
- L: 151,
367
- S: this,
368
- A: [
369
- "ObjectId.isValid(queueId)",
370
- ""
371
- ]
372
- });
373
- invariant2(!objectId || ObjectId.isValid(objectId), void 0, {
374
- F: __dxlog_file2,
375
- L: 152,
376
- S: this,
377
- A: [
378
- "!objectId || ObjectId.isValid(objectId)",
379
- ""
380
- ]
381
- });
510
+ assertArgument(SpaceId.isValid(spaceId), `Invalid space ID: ${spaceId}`);
511
+ assertArgument(ObjectId.isValid(queueId), "queueId", `Invalid queue ID: ${queueId}`);
512
+ assertArgument(!objectId || ObjectId.isValid(objectId), "objectId", `Invalid object ID: ${objectId}`);
382
513
  return new _DXN(_DXN.kind.QUEUE, [
383
514
  subspaceTag,
384
515
  spaceId,
@@ -388,44 +519,8 @@ var DXN = class _DXN {
388
519
  ] : []
389
520
  ]);
390
521
  }
391
- #kind;
392
- #parts;
393
- constructor(kind, parts) {
394
- invariant2(parts.length > 0, void 0, {
395
- F: __dxlog_file2,
396
- L: 161,
397
- S: this,
398
- A: [
399
- "parts.length > 0",
400
- ""
401
- ]
402
- });
403
- invariant2(parts.every((part) => typeof part === "string" && part.length > 0 && part.indexOf(":") === -1), void 0, {
404
- F: __dxlog_file2,
405
- L: 162,
406
- S: this,
407
- A: [
408
- "parts.every((part) => typeof part === 'string' && part.length > 0 && part.indexOf(':') === -1)",
409
- ""
410
- ]
411
- });
412
- switch (kind) {
413
- case _DXN.kind.TYPE:
414
- if (parts.length > 2) {
415
- throw new Error('Invalid "type" DXN');
416
- }
417
- break;
418
- case _DXN.kind.ECHO:
419
- if (parts.length !== 2) {
420
- throw new Error('Invalid "echo" DXN');
421
- }
422
- break;
423
- }
424
- this.#kind = kind;
425
- this.#parts = parts;
426
- }
427
522
  toString() {
428
- return `dxn:${this.#kind}:${this.#parts.join(":")}`;
523
+ return `dxn:${_class_private_field_get2(this, _kind)}:${_class_private_field_get2(this, _parts).join(":")}`;
429
524
  }
430
525
  toJSON() {
431
526
  return this.toString();
@@ -433,13 +528,13 @@ var DXN = class _DXN {
433
528
  /**
434
529
  * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
435
530
  */
436
- [inspectCustom](depth, options, inspectFn) {
531
+ [_inspectCustom](depth, options, inspectFn) {
437
532
  const printControlCode = (code) => {
438
533
  return `\x1B[${code}m`;
439
534
  };
440
535
  return printControlCode(inspectFn.colors.blueBright[0]) + this.toString() + printControlCode(inspectFn.colors.reset[0]);
441
536
  }
442
- get [devtoolsFormatter]() {
537
+ get [_devtoolsFormatter]() {
443
538
  return {
444
539
  header: () => {
445
540
  return [
@@ -452,34 +547,41 @@ var DXN = class _DXN {
452
547
  }
453
548
  };
454
549
  }
550
+ get kind() {
551
+ return _class_private_field_get2(this, _kind);
552
+ }
455
553
  get parts() {
456
- return this.#parts;
554
+ return _class_private_field_get2(this, _parts);
457
555
  }
458
556
  // TODO(burdon): Should getters fail?
459
557
  get typename() {
460
- invariant2(this.#kind === _DXN.kind.TYPE, void 0, {
558
+ invariant2(_class_private_field_get2(this, _kind) === _DXN.kind.TYPE, void 0, {
461
559
  F: __dxlog_file2,
462
- L: 217,
560
+ L: 250,
463
561
  S: this,
464
562
  A: [
465
563
  "this.#kind === DXN.kind.TYPE",
466
564
  ""
467
565
  ]
468
566
  });
469
- return this.#parts[0];
567
+ return _class_private_field_get2(this, _parts)[0];
568
+ }
569
+ equals(other) {
570
+ return _DXN.equals(this, other);
470
571
  }
471
572
  hasTypenameOf(typename) {
472
- return this.#kind === _DXN.kind.TYPE && this.#parts.length === 1 && this.#parts[0] === typename;
573
+ return _class_private_field_get2(this, _kind) === _DXN.kind.TYPE && _class_private_field_get2(this, _parts).length === 1 && _class_private_field_get2(this, _parts)[0] === typename;
473
574
  }
474
575
  isLocalObjectId() {
475
- return this.#kind === _DXN.kind.ECHO && this.#parts[0] === LOCAL_SPACE_TAG && this.#parts.length === 2;
576
+ return _class_private_field_get2(this, _kind) === _DXN.kind.ECHO && _class_private_field_get2(this, _parts)[0] === LOCAL_SPACE_TAG && _class_private_field_get2(this, _parts).length === 2;
476
577
  }
477
578
  asTypeDXN() {
478
579
  if (this.kind !== _DXN.kind.TYPE) {
479
580
  return void 0;
480
581
  }
481
- const [type, version] = this.#parts;
582
+ const [type, version] = _class_private_field_get2(this, _parts);
482
583
  return {
584
+ // TODO(wittjosiah): Should be `typename` for consistency.
483
585
  type,
484
586
  version
485
587
  };
@@ -488,9 +590,10 @@ var DXN = class _DXN {
488
590
  if (this.kind !== _DXN.kind.ECHO) {
489
591
  return void 0;
490
592
  }
491
- const [spaceId, echoId] = this.#parts;
593
+ const [spaceId, echoId] = _class_private_field_get2(this, _parts);
492
594
  return {
493
595
  spaceId: spaceId === LOCAL_SPACE_TAG ? void 0 : spaceId,
596
+ // TODO(burdon): objectId.
494
597
  echoId
495
598
  };
496
599
  }
@@ -498,7 +601,7 @@ var DXN = class _DXN {
498
601
  if (this.kind !== _DXN.kind.QUEUE) {
499
602
  return void 0;
500
603
  }
501
- const [subspaceTag, spaceId, queueId, objectId] = this.#parts;
604
+ const [subspaceTag, spaceId, queueId, objectId] = _class_private_field_get2(this, _parts);
502
605
  if (typeof queueId !== "string") {
503
606
  return void 0;
504
607
  }
@@ -509,7 +612,75 @@ var DXN = class _DXN {
509
612
  objectId
510
613
  };
511
614
  }
615
+ /**
616
+ * Produces a new DXN with the given parts appended.
617
+ */
618
+ extend(parts) {
619
+ return new _DXN(_class_private_field_get2(this, _kind), [
620
+ ..._class_private_field_get2(this, _parts),
621
+ ...parts
622
+ ]);
623
+ }
624
+ constructor(kind, parts) {
625
+ _class_private_field_init2(this, _kind, {
626
+ writable: true,
627
+ value: void 0
628
+ });
629
+ _class_private_field_init2(this, _parts, {
630
+ writable: true,
631
+ value: void 0
632
+ });
633
+ assertArgument(parts.length > 0, "parts", `Invalid DXN: ${parts}`);
634
+ assertArgument(parts.every((part) => typeof part === "string" && part.length > 0 && part.indexOf(":") === -1), "parts", `Invalid DXN: ${parts}`);
635
+ switch (kind) {
636
+ case _DXN.kind.TYPE:
637
+ if (parts.length > 2) {
638
+ throw new Error("Invalid DXN.kind.TYPE");
639
+ }
640
+ break;
641
+ case _DXN.kind.ECHO:
642
+ if (parts.length !== 2) {
643
+ throw new Error("Invalid DXN.kind.ECHO");
644
+ }
645
+ break;
646
+ }
647
+ _class_private_field_set2(this, _kind, kind);
648
+ _class_private_field_set2(this, _parts, parts);
649
+ }
512
650
  };
651
+ _define_property2(DXN, "Schema", Schema3.NonEmptyString.pipe(
652
+ Schema3.pattern(/^dxn:([^:]+):(?:[^:]+:?)+[^:]$/),
653
+ // TODO(dmaretskyi): To set the format we need to move the annotation IDs out of the echo-schema package.
654
+ // FormatAnnotation.set(FormatEnum.DXN),
655
+ Schema3.annotations({
656
+ title: "DXN",
657
+ description: "DXN URI",
658
+ examples: [
659
+ "dxn:type:example.com/type/MyType",
660
+ "dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6"
661
+ ]
662
+ })
663
+ ));
664
+ _define_property2(DXN, "kind", Object.freeze({
665
+ /**
666
+ * dxn:type:<type_name>[:<version>]
667
+ */
668
+ TYPE: "type",
669
+ /**
670
+ * dxn:echo:<space_id>:<echo_id>
671
+ * dxn:echo:@:<echo_id>
672
+ */
673
+ // TODO(burdon): Rename to OBJECT? (BREAKING CHANGE to update "echo").
674
+ // TODO(burdon): Add separate Kind for space?
675
+ ECHO: "echo",
676
+ /**
677
+ * The subspace tag enables us to partition queues by usage within the context of a space.
678
+ * dxn:queue:<subspace_tag>:<space_id>:<queue_id>[:object_id]
679
+ * dxn:queue:data:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
680
+ * dxn:queue:trace:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
681
+ */
682
+ QUEUE: "queue"
683
+ }));
513
684
 
514
685
  // src/identity-did.ts
515
686
  var import_base32_decode2 = __toESM(require_base32_decode(), 1);
@@ -565,14 +736,27 @@ var ENCODED_LENGTH2 = 42;
565
736
  var import_base32_decode3 = __toESM(require_base32_decode(), 1);
566
737
  import { devtoolsFormatter as devtoolsFormatter2, equalsSymbol, inspectCustom as inspectCustom2, truncateKey } from "@dxos/debug";
567
738
  import { invariant as invariant4 } from "@dxos/invariant";
739
+ function _define_property3(obj, key, value) {
740
+ if (key in obj) {
741
+ Object.defineProperty(obj, key, {
742
+ value,
743
+ enumerable: true,
744
+ configurable: true,
745
+ writable: true
746
+ });
747
+ } else {
748
+ obj[key] = value;
749
+ }
750
+ return obj;
751
+ }
568
752
  var __dxlog_file4 = "/__w/dxos/dxos/packages/common/keys/src/public-key.ts";
569
753
  var PUBLIC_KEY_LENGTH = 32;
570
754
  var SECRET_KEY_LENGTH = 64;
571
755
  var isLikeArrayBuffer = (value) => typeof value === "object" && value !== null && Object.getPrototypeOf(value).constructor.name === "ArrayBuffer";
756
+ var _inspectCustom2 = inspectCustom2;
757
+ var _devtoolsFormatter2 = devtoolsFormatter2;
758
+ var _equalsSymbol = equalsSymbol;
572
759
  var PublicKey = class _PublicKey {
573
- static {
574
- this.ZERO = _PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH));
575
- }
576
760
  /**
577
761
  * Creates new instance of PublicKey automatically determining the input format.
578
762
  * @param source A Buffer, or Uint8Array, or hex encoded string, or something with an `asUint8Array` method on it
@@ -581,7 +765,7 @@ var PublicKey = class _PublicKey {
581
765
  static from(source) {
582
766
  invariant4(source, void 0, {
583
767
  F: __dxlog_file4,
584
- L: 49,
768
+ L: 50,
585
769
  S: this,
586
770
  A: [
587
771
  "source",
@@ -673,7 +857,7 @@ var PublicKey = class _PublicKey {
673
857
  static bufferize(str) {
674
858
  invariant4(typeof str === "string", "Invalid type", {
675
859
  F: __dxlog_file4,
676
- L: 152,
860
+ L: 153,
677
861
  S: this,
678
862
  A: [
679
863
  "typeof str === 'string'",
@@ -696,7 +880,7 @@ var PublicKey = class _PublicKey {
696
880
  }
697
881
  invariant4(key instanceof Buffer, "Invalid type", {
698
882
  F: __dxlog_file4,
699
- L: 171,
883
+ L: 172,
700
884
  S: this,
701
885
  A: [
702
886
  "key instanceof Buffer",
@@ -715,7 +899,7 @@ var PublicKey = class _PublicKey {
715
899
  static fromMultibase32(encoded) {
716
900
  invariant4(encoded.startsWith("B"), "Invalid multibase32 encoding", {
717
901
  F: __dxlog_file4,
718
- L: 184,
902
+ L: 185,
719
903
  S: this,
720
904
  A: [
721
905
  "encoded.startsWith('B')",
@@ -724,12 +908,6 @@ var PublicKey = class _PublicKey {
724
908
  });
725
909
  return new _PublicKey(new Uint8Array((0, import_base32_decode3.default)(encoded.slice(1), "RFC4648")));
726
910
  }
727
- constructor(_value) {
728
- this._value = _value;
729
- if (!(_value instanceof Uint8Array)) {
730
- throw new TypeError(`Expected Uint8Array, got: ${_value}`);
731
- }
732
- }
733
911
  toString() {
734
912
  return this.toHex();
735
913
  }
@@ -763,7 +941,7 @@ var PublicKey = class _PublicKey {
763
941
  /**
764
942
  * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
765
943
  */
766
- [inspectCustom2](depth, options, inspectFn) {
944
+ [_inspectCustom2](depth, options, inspectFn) {
767
945
  if (!options.colors || typeof process.stdout.hasColors !== "function" || !process.stdout.hasColors()) {
768
946
  return `<PublicKey ${this.truncate()}>`;
769
947
  }
@@ -788,7 +966,7 @@ var PublicKey = class _PublicKey {
788
966
  const color = colors[this.getInsecureHash(colors.length)];
789
967
  return `PublicKey(${printControlCode(inspectFn.colors[color][0])}${this.truncate()}${printControlCode(inspectFn.colors.reset[0])})`;
790
968
  }
791
- get [devtoolsFormatter2]() {
969
+ get [_devtoolsFormatter2]() {
792
970
  return {
793
971
  header: () => {
794
972
  const colors = [
@@ -841,19 +1019,28 @@ var PublicKey = class _PublicKey {
841
1019
  }
842
1020
  let equal = true;
843
1021
  for (let i = 0; i < this._value.length; i++) {
844
- equal &&= this._value[i] === otherConverted._value[i];
1022
+ equal && (equal = this._value[i] === otherConverted._value[i]);
845
1023
  }
846
1024
  return equal;
847
1025
  }
848
- [equalsSymbol](other) {
1026
+ [_equalsSymbol](other) {
849
1027
  if (!_PublicKey.isPublicKey(other)) {
850
1028
  return false;
851
1029
  }
852
1030
  return this.equals(other);
853
1031
  }
1032
+ constructor(_value) {
1033
+ _define_property3(this, "_value", void 0);
1034
+ this._value = _value;
1035
+ if (!(_value instanceof Uint8Array)) {
1036
+ throw new TypeError(`Expected Uint8Array, got: ${_value}`);
1037
+ }
1038
+ }
854
1039
  };
1040
+ _define_property3(PublicKey, "ZERO", PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH)));
855
1041
  export {
856
1042
  DXN,
1043
+ DXN_ECHO_REGEXP,
857
1044
  IdentityDid,
858
1045
  LOCAL_SPACE_TAG,
859
1046
  ObjectId,
@@ -861,6 +1048,7 @@ export {
861
1048
  PublicKey,
862
1049
  QueueSubspaceTags,
863
1050
  SECRET_KEY_LENGTH,
1051
+ SimplePRNG,
864
1052
  SpaceId
865
1053
  };
866
1054
  //# sourceMappingURL=index.mjs.map