@dxos/keys 0.8.4-main.a4bbb77 → 0.8.4-main.abd8ff62ef

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.
@@ -100,83 +100,21 @@ init_inject_globals();
100
100
 
101
101
  // src/dxn.ts
102
102
  init_inject_globals();
103
- import { Schema as Schema3 } from "effect";
103
+ import * as Schema3 from "effect/Schema";
104
104
  import { devtoolsFormatter, inspectCustom } from "@dxos/debug";
105
105
  import { assertArgument, invariant as invariant2 } from "@dxos/invariant";
106
106
 
107
107
  // src/object-id.ts
108
108
  init_inject_globals();
109
- import { Schema } from "effect";
109
+ import * as Schema from "effect/Schema";
110
110
  import { monotonicFactory } from "ulidx";
111
- function _check_private_redeclaration(obj, privateCollection) {
112
- if (privateCollection.has(obj)) {
113
- throw new TypeError("Cannot initialize the same private elements twice on an object");
114
- }
115
- }
116
- function _class_apply_descriptor_get(receiver, descriptor) {
117
- if (descriptor.get) {
118
- return descriptor.get.call(receiver);
119
- }
120
- return descriptor.value;
121
- }
122
- function _class_apply_descriptor_set(receiver, descriptor, value) {
123
- if (descriptor.set) {
124
- descriptor.set.call(receiver, value);
125
- } else {
126
- if (!descriptor.writable) {
127
- throw new TypeError("attempted to set read only private field");
128
- }
129
- descriptor.value = value;
130
- }
131
- }
132
- function _class_check_private_static_field_descriptor(descriptor, action) {
133
- if (descriptor === void 0) {
134
- throw new TypeError("attempted to " + action + " private static field before its declaration");
135
- }
136
- }
137
- function _class_extract_field_descriptor(receiver, privateMap, action) {
138
- if (!privateMap.has(receiver)) {
139
- throw new TypeError("attempted to " + action + " private field on non-instance");
140
- }
141
- return privateMap.get(receiver);
142
- }
143
- function _class_private_field_get(receiver, privateMap) {
144
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
145
- return _class_apply_descriptor_get(receiver, descriptor);
146
- }
147
- function _class_private_field_init(obj, privateMap, value) {
148
- _check_private_redeclaration(obj, privateMap);
149
- privateMap.set(obj, value);
150
- }
151
- function _class_private_field_set(receiver, privateMap, value) {
152
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
153
- _class_apply_descriptor_set(receiver, descriptor, value);
154
- return value;
155
- }
156
- function _class_static_private_field_spec_get(receiver, classConstructor, descriptor) {
157
- _class_check_private_static_access(receiver, classConstructor);
158
- _class_check_private_static_field_descriptor(descriptor, "get");
159
- return _class_apply_descriptor_get(receiver, descriptor);
160
- }
161
- function _class_static_private_field_spec_set(receiver, classConstructor, descriptor, value) {
162
- _class_check_private_static_access(receiver, classConstructor);
163
- _class_check_private_static_field_descriptor(descriptor, "set");
164
- _class_apply_descriptor_set(receiver, descriptor, value);
165
- return value;
166
- }
167
- function _class_check_private_static_access(receiver, classConstructor) {
168
- if (receiver !== classConstructor) {
169
- throw new TypeError("Private static access of wrong provenance");
170
- }
171
- }
172
- var _class;
173
- var _factory;
174
- var _seedTime;
175
111
  var ObjectIdSchema = Schema.String.pipe(Schema.pattern(/^[0-7][0-9A-HJKMNP-TV-Z]{25}$/i)).annotations({
176
112
  description: "A Universally Unique Lexicographically Sortable Identifier",
177
113
  pattern: "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
178
114
  });
179
- var ObjectId = (_class = class extends ObjectIdSchema {
115
+ var ObjectId = class extends ObjectIdSchema {
116
+ static #factory = monotonicFactory();
117
+ static #seedTime = void 0;
180
118
  static isValid(id) {
181
119
  try {
182
120
  Schema.decodeSync(ObjectId)(id);
@@ -186,65 +124,47 @@ var ObjectId = (_class = class extends ObjectIdSchema {
186
124
  }
187
125
  }
188
126
  static random() {
189
- return _class_static_private_field_spec_get(this, _class, _factory).call(_class, _class_static_private_field_spec_get(this, _class, _seedTime));
127
+ return this.#factory(this.#seedTime);
190
128
  }
191
129
  static dangerouslyDisableRandomness() {
192
- _class_static_private_field_spec_set(this, _class, _factory, monotonicFactory(makeTestPRNG()));
193
- _class_static_private_field_spec_set(this, _class, _seedTime, (/* @__PURE__ */ new Date("2025-01-01")).getTime());
194
- }
195
- }, _factory = {
196
- writable: true,
197
- value: monotonicFactory()
198
- }, _seedTime = {
199
- writable: true,
200
- value: void 0
201
- }, _class);
130
+ this.#factory = monotonicFactory(makeTestPRNG());
131
+ this.#seedTime = (/* @__PURE__ */ new Date("2025-01-01")).getTime();
132
+ }
133
+ };
202
134
  var makeTestPRNG = () => {
203
135
  const rng = new SimplePRNG();
204
136
  return () => {
205
137
  return rng.next();
206
138
  };
207
139
  };
208
- var _seed = /* @__PURE__ */ new WeakMap();
209
140
  var SimplePRNG = class _SimplePRNG {
141
+ #seed;
142
+ // LCG parameters (from Numerical Recipes)
143
+ static #a = 1664525;
144
+ static #c = 1013904223;
145
+ static #m = Math.pow(2, 32);
146
+ /**
147
+ * Creates a new PRNG instance.
148
+ * @param seed - Initial seed value. If not provided, uses 0.
149
+ */
150
+ constructor(seed = 0) {
151
+ this.#seed = seed;
152
+ }
210
153
  /**
211
154
  * Generates the next pseudo-random number in the range [0, 1).
212
155
  * @returns A pseudo-random number between 0 (inclusive) and 1 (exclusive).
213
156
  */
214
157
  next() {
215
- _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));
216
- return _class_private_field_get(this, _seed) / _class_static_private_field_spec_get(_SimplePRNG, _SimplePRNG, _m);
158
+ this.#seed = (_SimplePRNG.#a * this.#seed + _SimplePRNG.#c) % _SimplePRNG.#m;
159
+ return this.#seed / _SimplePRNG.#m;
217
160
  }
218
161
  /**
219
162
  * Resets the generator with a new seed.
220
163
  * @param seed - New seed value.
221
164
  */
222
165
  reset(seed) {
223
- _class_private_field_set(this, _seed, seed);
166
+ this.#seed = seed;
224
167
  }
225
- /**
226
- * Creates a new PRNG instance.
227
- * @param seed - Initial seed value. If not provided, uses 0.
228
- */
229
- constructor(seed = 0) {
230
- _class_private_field_init(this, _seed, {
231
- writable: true,
232
- value: void 0
233
- });
234
- _class_private_field_set(this, _seed, seed);
235
- }
236
- };
237
- var _a = {
238
- writable: true,
239
- value: 1664525
240
- };
241
- var _c = {
242
- writable: true,
243
- value: 1013904223
244
- };
245
- var _m = {
246
- writable: true,
247
- value: Math.pow(2, 32)
248
168
  };
249
169
 
250
170
  // src/space-id.ts
@@ -315,7 +235,7 @@ function base32Encode(data, variant, options) {
315
235
  }
316
236
 
317
237
  // src/space-id.ts
318
- import { Schema as Schema2 } from "effect";
238
+ import * as Schema2 from "effect/Schema";
319
239
  import { invariant } from "@dxos/invariant";
320
240
 
321
241
  // src/random-bytes.ts
@@ -328,133 +248,78 @@ var randomBytes = (length) => {
328
248
  };
329
249
 
330
250
  // src/space-id.ts
331
- function _define_property(obj, key, value) {
332
- if (key in obj) {
333
- Object.defineProperty(obj, key, {
334
- value,
335
- enumerable: true,
336
- configurable: true,
337
- writable: true
338
- });
339
- } else {
340
- obj[key] = value;
341
- }
342
- return obj;
343
- }
344
- var _Schema_String_pipe;
345
- var _class2;
346
- var __dxlog_file = "/__w/dxos/dxos/packages/common/keys/src/space-id.ts";
347
251
  var MULTIBASE_PREFIX = "B";
348
252
  var ENCODED_LENGTH = 33;
349
253
  var isValid = (value) => {
350
254
  return typeof value === "string" && value.startsWith(MULTIBASE_PREFIX) && value.length === ENCODED_LENGTH;
351
255
  };
352
- var SpaceId = (_class2 = class extends (_Schema_String_pipe = Schema2.String.pipe(Schema2.filter(isValid))) {
353
- }, _define_property(_class2, "byteLength", 20), _define_property(_class2, "encode", (value) => {
354
- invariant(value instanceof Uint8Array, "Invalid type", {
355
- F: __dxlog_file,
356
- L: 43,
357
- S: _class2,
358
- A: [
359
- "value instanceof Uint8Array",
360
- "'Invalid type'"
361
- ]
362
- });
363
- invariant(value.length === SpaceId.byteLength, "Invalid length", {
364
- F: __dxlog_file,
365
- L: 44,
366
- S: _class2,
367
- A: [
368
- "value.length === SpaceId.byteLength",
369
- "'Invalid length'"
370
- ]
371
- });
372
- return MULTIBASE_PREFIX + base32Encode(value, "RFC4648");
373
- }), _define_property(_class2, "decode", (value) => {
374
- invariant(value.startsWith(MULTIBASE_PREFIX), "Invalid multibase32 encoding", {
375
- F: __dxlog_file,
376
- L: 49,
377
- S: _class2,
378
- A: [
379
- "value.startsWith(MULTIBASE_PREFIX)",
380
- "'Invalid multibase32 encoding'"
381
- ]
382
- });
383
- return new Uint8Array((0, import_base32_decode.default)(value.slice(1), "RFC4648"));
384
- }), _define_property(_class2, "isValid", isValid), _define_property(_class2, "random", () => {
385
- return SpaceId.encode(randomBytes(SpaceId.byteLength));
386
- }), _class2);
256
+ var SpaceId = class extends Schema2.String.pipe(Schema2.filter(isValid)) {
257
+ static byteLength = 20;
258
+ static encode = (value) => {
259
+ invariant(value instanceof Uint8Array, "Invalid type");
260
+ invariant(value.length === SpaceId.byteLength, "Invalid length");
261
+ return MULTIBASE_PREFIX + base32Encode(value, "RFC4648");
262
+ };
263
+ static decode = (value) => {
264
+ invariant(value.startsWith(MULTIBASE_PREFIX), "Invalid multibase32 encoding");
265
+ return new Uint8Array((0, import_base32_decode.default)(value.slice(1), "RFC4648"));
266
+ };
267
+ static isValid = isValid;
268
+ static random = () => {
269
+ return SpaceId.encode(randomBytes(SpaceId.byteLength));
270
+ };
271
+ };
387
272
 
388
273
  // src/dxn.ts
389
- function _check_private_redeclaration2(obj, privateCollection) {
390
- if (privateCollection.has(obj)) {
391
- throw new TypeError("Cannot initialize the same private elements twice on an object");
392
- }
393
- }
394
- function _class_apply_descriptor_get2(receiver, descriptor) {
395
- if (descriptor.get) {
396
- return descriptor.get.call(receiver);
397
- }
398
- return descriptor.value;
399
- }
400
- function _class_apply_descriptor_set2(receiver, descriptor, value) {
401
- if (descriptor.set) {
402
- descriptor.set.call(receiver, value);
403
- } else {
404
- if (!descriptor.writable) {
405
- throw new TypeError("attempted to set read only private field");
406
- }
407
- descriptor.value = value;
408
- }
409
- }
410
- function _class_extract_field_descriptor2(receiver, privateMap, action) {
411
- if (!privateMap.has(receiver)) {
412
- throw new TypeError("attempted to " + action + " private field on non-instance");
413
- }
414
- return privateMap.get(receiver);
415
- }
416
- function _class_private_field_get2(receiver, privateMap) {
417
- var descriptor = _class_extract_field_descriptor2(receiver, privateMap, "get");
418
- return _class_apply_descriptor_get2(receiver, descriptor);
419
- }
420
- function _class_private_field_init2(obj, privateMap, value) {
421
- _check_private_redeclaration2(obj, privateMap);
422
- privateMap.set(obj, value);
423
- }
424
- function _class_private_field_set2(receiver, privateMap, value) {
425
- var descriptor = _class_extract_field_descriptor2(receiver, privateMap, "set");
426
- _class_apply_descriptor_set2(receiver, descriptor, value);
427
- return value;
428
- }
429
- function _define_property2(obj, key, value) {
430
- if (key in obj) {
431
- Object.defineProperty(obj, key, {
432
- value,
433
- enumerable: true,
434
- configurable: true,
435
- writable: true
436
- });
437
- } else {
438
- obj[key] = value;
439
- }
440
- return obj;
441
- }
442
- var __dxlog_file2 = "/__w/dxos/dxos/packages/common/keys/src/dxn.ts";
443
274
  var LOCAL_SPACE_TAG = "@";
444
275
  var DXN_ECHO_REGEXP = /@(dxn:[a-zA-Z0-p:@]+)/;
445
276
  var QueueSubspaceTags = Object.freeze({
446
277
  DATA: "data",
447
278
  TRACE: "trace"
448
279
  });
449
- var _kind = /* @__PURE__ */ new WeakMap();
450
- var _parts = /* @__PURE__ */ new WeakMap();
451
- var _inspectCustom = inspectCustom;
452
- var _devtoolsFormatter = devtoolsFormatter;
453
280
  var DXN = class _DXN {
281
+ // TODO(burdon): Rename to DXN (i.e., DXN.DXN).
282
+ // TODO(dmaretskyi): Should this be a transformation into the DXN type?
283
+ static Schema = Schema3.NonEmptyString.pipe(
284
+ Schema3.pattern(/^dxn:([^:]+):(?:[^:]+:?)+[^:]$/),
285
+ // TODO(dmaretskyi): To set the format we need to move the annotation IDs out of the echo-schema package.
286
+ // FormatAnnotation.set(TypeFormat.DXN),
287
+ Schema3.annotations({
288
+ title: "DXN",
289
+ description: "DXN URI",
290
+ examples: [
291
+ "dxn:type:com.example.type.my-type",
292
+ "dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6"
293
+ ]
294
+ })
295
+ );
454
296
  static hash(dxn) {
455
297
  return dxn.toString();
456
298
  }
457
299
  /**
300
+ * Kind constants.
301
+ */
302
+ static kind = Object.freeze({
303
+ /**
304
+ * dxn:type:<type_name>[:<version>]
305
+ */
306
+ TYPE: "type",
307
+ /**
308
+ * dxn:echo:<space_id>:<echo_id>
309
+ * dxn:echo:@:<echo_id>
310
+ */
311
+ // TODO(burdon): Rename to OBJECT? (BREAKING CHANGE to update "echo").
312
+ // TODO(burdon): Add separate Kind for space?
313
+ ECHO: "echo",
314
+ /**
315
+ * The subspace tag enables us to partition queues by usage within the context of a space.
316
+ * dxn:queue:<subspace_tag>:<space_id>:<queue_id>[:object_id]
317
+ * dxn:queue:data:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
318
+ * dxn:queue:trace:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
319
+ */
320
+ QUEUE: "queue"
321
+ });
322
+ /**
458
323
  * Exactly equals.
459
324
  */
460
325
  static equals(a, b) {
@@ -493,7 +358,7 @@ var DXN = class _DXN {
493
358
  }
494
359
  }
495
360
  /**
496
- * @example `dxn:type:example.com/type/Contact`
361
+ * @example `dxn:type:com.example.type.person`
497
362
  */
498
363
  static fromTypename(typename) {
499
364
  return new _DXN(_DXN.kind.TYPE, [
@@ -501,7 +366,7 @@ var DXN = class _DXN {
501
366
  ]);
502
367
  }
503
368
  /**
504
- * @example `dxn:type:example.com/type/Contact:0.1.0`
369
+ * @example `dxn:type:com.example.type.person:0.1.0`
505
370
  */
506
371
  // TODO(dmaretskyi): Consider using @ as the version separator.
507
372
  static fromTypenameAndVersion(typename, version) {
@@ -544,8 +409,28 @@ var DXN = class _DXN {
544
409
  ] : []
545
410
  ]);
546
411
  }
412
+ #kind;
413
+ #parts;
414
+ constructor(kind, parts) {
415
+ assertArgument(parts.length > 0, "parts", `Invalid DXN: ${parts}`);
416
+ assertArgument(parts.every((part) => typeof part === "string" && part.length > 0 && part.indexOf(":") === -1), "parts", `Invalid DXN: ${parts}`);
417
+ switch (kind) {
418
+ case _DXN.kind.TYPE:
419
+ if (parts.length > 2) {
420
+ throw new Error("Invalid DXN.kind.TYPE");
421
+ }
422
+ break;
423
+ case _DXN.kind.ECHO:
424
+ if (parts.length !== 2) {
425
+ throw new Error("Invalid DXN.kind.ECHO");
426
+ }
427
+ break;
428
+ }
429
+ this.#kind = kind;
430
+ this.#parts = parts;
431
+ }
547
432
  toString() {
548
- return `dxn:${_class_private_field_get2(this, _kind)}:${_class_private_field_get2(this, _parts).join(":")}`;
433
+ return `dxn:${this.#kind}:${this.#parts.join(":")}`;
549
434
  }
550
435
  toJSON() {
551
436
  return this.toString();
@@ -553,13 +438,13 @@ var DXN = class _DXN {
553
438
  /**
554
439
  * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
555
440
  */
556
- [_inspectCustom](depth, options, inspectFn) {
441
+ [inspectCustom](depth, options, inspectFn) {
557
442
  const printControlCode = (code) => {
558
443
  return `\x1B[${code}m`;
559
444
  };
560
445
  return printControlCode(inspectFn.colors.blueBright[0]) + this.toString() + printControlCode(inspectFn.colors.reset[0]);
561
446
  }
562
- get [_devtoolsFormatter]() {
447
+ get [devtoolsFormatter]() {
563
448
  return {
564
449
  header: () => {
565
450
  return [
@@ -573,38 +458,30 @@ var DXN = class _DXN {
573
458
  };
574
459
  }
575
460
  get kind() {
576
- return _class_private_field_get2(this, _kind);
461
+ return this.#kind;
577
462
  }
578
463
  get parts() {
579
- return _class_private_field_get2(this, _parts);
464
+ return this.#parts;
580
465
  }
581
466
  // TODO(burdon): Should getters fail?
582
467
  get typename() {
583
- invariant2(_class_private_field_get2(this, _kind) === _DXN.kind.TYPE, void 0, {
584
- F: __dxlog_file2,
585
- L: 250,
586
- S: this,
587
- A: [
588
- "this.#kind === DXN.kind.TYPE",
589
- ""
590
- ]
591
- });
592
- return _class_private_field_get2(this, _parts)[0];
468
+ invariant2(this.#kind === _DXN.kind.TYPE);
469
+ return this.#parts[0];
593
470
  }
594
471
  equals(other) {
595
472
  return _DXN.equals(this, other);
596
473
  }
597
474
  hasTypenameOf(typename) {
598
- 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;
475
+ return this.#kind === _DXN.kind.TYPE && this.#parts.length === 1 && this.#parts[0] === typename;
599
476
  }
600
477
  isLocalObjectId() {
601
- 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;
478
+ return this.#kind === _DXN.kind.ECHO && this.#parts[0] === LOCAL_SPACE_TAG && this.#parts.length === 2;
602
479
  }
603
480
  asTypeDXN() {
604
481
  if (this.kind !== _DXN.kind.TYPE) {
605
482
  return void 0;
606
483
  }
607
- const [type, version] = _class_private_field_get2(this, _parts);
484
+ const [type, version] = this.#parts;
608
485
  return {
609
486
  // TODO(wittjosiah): Should be `typename` for consistency.
610
487
  type,
@@ -615,7 +492,7 @@ var DXN = class _DXN {
615
492
  if (this.kind !== _DXN.kind.ECHO) {
616
493
  return void 0;
617
494
  }
618
- const [spaceId, echoId] = _class_private_field_get2(this, _parts);
495
+ const [spaceId, echoId] = this.#parts;
619
496
  return {
620
497
  spaceId: spaceId === LOCAL_SPACE_TAG ? void 0 : spaceId,
621
498
  // TODO(burdon): objectId.
@@ -626,7 +503,7 @@ var DXN = class _DXN {
626
503
  if (this.kind !== _DXN.kind.QUEUE) {
627
504
  return void 0;
628
505
  }
629
- const [subspaceTag, spaceId, queueId, objectId] = _class_private_field_get2(this, _parts);
506
+ const [subspaceTag, spaceId, queueId, objectId] = this.#parts;
630
507
  if (typeof queueId !== "string") {
631
508
  return void 0;
632
509
  }
@@ -641,110 +518,26 @@ var DXN = class _DXN {
641
518
  * Produces a new DXN with the given parts appended.
642
519
  */
643
520
  extend(parts) {
644
- return new _DXN(_class_private_field_get2(this, _kind), [
645
- ..._class_private_field_get2(this, _parts),
521
+ return new _DXN(this.#kind, [
522
+ ...this.#parts,
646
523
  ...parts
647
524
  ]);
648
525
  }
649
- constructor(kind, parts) {
650
- _class_private_field_init2(this, _kind, {
651
- writable: true,
652
- value: void 0
653
- });
654
- _class_private_field_init2(this, _parts, {
655
- writable: true,
656
- value: void 0
657
- });
658
- assertArgument(parts.length > 0, "parts", `Invalid DXN: ${parts}`);
659
- assertArgument(parts.every((part) => typeof part === "string" && part.length > 0 && part.indexOf(":") === -1), "parts", `Invalid DXN: ${parts}`);
660
- switch (kind) {
661
- case _DXN.kind.TYPE:
662
- if (parts.length > 2) {
663
- throw new Error("Invalid DXN.kind.TYPE");
664
- }
665
- break;
666
- case _DXN.kind.ECHO:
667
- if (parts.length !== 2) {
668
- throw new Error("Invalid DXN.kind.ECHO");
669
- }
670
- break;
671
- }
672
- _class_private_field_set2(this, _kind, kind);
673
- _class_private_field_set2(this, _parts, parts);
674
- }
675
526
  };
676
- _define_property2(DXN, "Schema", Schema3.NonEmptyString.pipe(
677
- Schema3.pattern(/^dxn:([^:]+):(?:[^:]+:?)+[^:]$/),
678
- // TODO(dmaretskyi): To set the format we need to move the annotation IDs out of the echo-schema package.
679
- // FormatAnnotation.set(FormatEnum.DXN),
680
- Schema3.annotations({
681
- title: "DXN",
682
- description: "DXN URI",
683
- examples: [
684
- "dxn:type:example.com/type/MyType",
685
- "dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6"
686
- ]
687
- })
688
- ));
689
- _define_property2(DXN, "kind", Object.freeze({
690
- /**
691
- * dxn:type:<type_name>[:<version>]
692
- */
693
- TYPE: "type",
694
- /**
695
- * dxn:echo:<space_id>:<echo_id>
696
- * dxn:echo:@:<echo_id>
697
- */
698
- // TODO(burdon): Rename to OBJECT? (BREAKING CHANGE to update "echo").
699
- // TODO(burdon): Add separate Kind for space?
700
- ECHO: "echo",
701
- /**
702
- * The subspace tag enables us to partition queues by usage within the context of a space.
703
- * dxn:queue:<subspace_tag>:<space_id>:<queue_id>[:object_id]
704
- * dxn:queue:data:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
705
- * dxn:queue:trace:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
706
- */
707
- QUEUE: "queue"
708
- }));
709
527
 
710
528
  // src/identity-did.ts
711
529
  init_inject_globals();
712
530
  var import_base32_decode2 = __toESM(require_base32_decode(), 1);
713
531
  import { invariant as invariant3 } from "@dxos/invariant";
714
- var __dxlog_file3 = "/__w/dxos/dxos/packages/common/keys/src/identity-did.ts";
715
532
  var IdentityDid = Object.freeze({
716
533
  byteLength: 20,
717
534
  encode: (value) => {
718
- invariant3(value instanceof Uint8Array, "Invalid type", {
719
- F: __dxlog_file3,
720
- L: 22,
721
- S: void 0,
722
- A: [
723
- "value instanceof Uint8Array",
724
- "'Invalid type'"
725
- ]
726
- });
727
- invariant3(value.length === IdentityDid.byteLength, "Invalid length", {
728
- F: __dxlog_file3,
729
- L: 23,
730
- S: void 0,
731
- A: [
732
- "value.length === IdentityDid.byteLength",
733
- "'Invalid length'"
734
- ]
735
- });
535
+ invariant3(value instanceof Uint8Array, "Invalid type");
536
+ invariant3(value.length === IdentityDid.byteLength, "Invalid length");
736
537
  return DID_PREFIX + MULTIBASE_PREFIX2 + base32Encode(value, "RFC4648");
737
538
  },
738
539
  decode: (value) => {
739
- invariant3(value.startsWith(DID_PREFIX + MULTIBASE_PREFIX2), "Invalid multibase32 encoding", {
740
- F: __dxlog_file3,
741
- L: 28,
742
- S: void 0,
743
- A: [
744
- "value.startsWith(DID_PREFIX + MULTIBASE_PREFIX)",
745
- "'Invalid multibase32 encoding'"
746
- ]
747
- });
540
+ invariant3(value.startsWith(DID_PREFIX + MULTIBASE_PREFIX2), "Invalid multibase32 encoding");
748
541
  return new Uint8Array((0, import_base32_decode2.default)(value.slice(10), "RFC4648"));
749
542
  },
750
543
  isValid: (value) => {
@@ -763,42 +556,19 @@ init_inject_globals();
763
556
  var import_base32_decode3 = __toESM(require_base32_decode(), 1);
764
557
  import { devtoolsFormatter as devtoolsFormatter2, equalsSymbol, inspectCustom as inspectCustom2, truncateKey } from "@dxos/debug";
765
558
  import { invariant as invariant4 } from "@dxos/invariant";
766
- function _define_property3(obj, key, value) {
767
- if (key in obj) {
768
- Object.defineProperty(obj, key, {
769
- value,
770
- enumerable: true,
771
- configurable: true,
772
- writable: true
773
- });
774
- } else {
775
- obj[key] = value;
776
- }
777
- return obj;
778
- }
779
- var __dxlog_file4 = "/__w/dxos/dxos/packages/common/keys/src/public-key.ts";
780
559
  var PUBLIC_KEY_LENGTH = 32;
781
560
  var SECRET_KEY_LENGTH = 64;
782
561
  var isLikeArrayBuffer = (value) => typeof value === "object" && value !== null && Object.getPrototypeOf(value).constructor.name === "ArrayBuffer";
783
- var _inspectCustom2 = inspectCustom2;
784
- var _devtoolsFormatter2 = devtoolsFormatter2;
785
- var _equalsSymbol = equalsSymbol;
786
562
  var PublicKey = class _PublicKey {
563
+ _value;
564
+ static ZERO = _PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH));
787
565
  /**
788
566
  * Creates new instance of PublicKey automatically determining the input format.
789
567
  * @param source A Buffer, or Uint8Array, or hex encoded string, or something with an `asUint8Array` method on it
790
568
  * @returns PublicKey
791
569
  */
792
570
  static from(source) {
793
- invariant4(source, void 0, {
794
- F: __dxlog_file4,
795
- L: 50,
796
- S: this,
797
- A: [
798
- "source",
799
- ""
800
- ]
801
- });
571
+ invariant4(source);
802
572
  if (source instanceof _PublicKey) {
803
573
  return source;
804
574
  } else if (source instanceof Buffer2) {
@@ -882,15 +652,7 @@ var PublicKey = class _PublicKey {
882
652
  * @deprecated All keys should be represented as instances of PublicKey.
883
653
  */
884
654
  static bufferize(str) {
885
- invariant4(typeof str === "string", "Invalid type", {
886
- F: __dxlog_file4,
887
- L: 153,
888
- S: this,
889
- A: [
890
- "typeof str === 'string'",
891
- "'Invalid type'"
892
- ]
893
- });
655
+ invariant4(typeof str === "string", "Invalid type");
894
656
  const buffer = Buffer2.from(str, "hex");
895
657
  return buffer;
896
658
  }
@@ -905,15 +667,7 @@ var PublicKey = class _PublicKey {
905
667
  } else if (key instanceof Uint8Array) {
906
668
  key = Buffer2.from(key.buffer, key.byteOffset, key.byteLength);
907
669
  }
908
- invariant4(key instanceof Buffer2, "Invalid type", {
909
- F: __dxlog_file4,
910
- L: 172,
911
- S: this,
912
- A: [
913
- "key instanceof Buffer",
914
- "'Invalid type'"
915
- ]
916
- });
670
+ invariant4(key instanceof Buffer2, "Invalid type");
917
671
  return key.toString("hex");
918
672
  }
919
673
  /**
@@ -924,17 +678,15 @@ var PublicKey = class _PublicKey {
924
678
  return key.toHex();
925
679
  }
926
680
  static fromMultibase32(encoded) {
927
- invariant4(encoded.startsWith("B"), "Invalid multibase32 encoding", {
928
- F: __dxlog_file4,
929
- L: 185,
930
- S: this,
931
- A: [
932
- "encoded.startsWith('B')",
933
- "'Invalid multibase32 encoding'"
934
- ]
935
- });
681
+ invariant4(encoded.startsWith("B"), "Invalid multibase32 encoding");
936
682
  return new _PublicKey(new Uint8Array((0, import_base32_decode3.default)(encoded.slice(1), "RFC4648")));
937
683
  }
684
+ constructor(_value) {
685
+ this._value = _value;
686
+ if (!(_value instanceof Uint8Array)) {
687
+ throw new TypeError(`Expected Uint8Array, got: ${_value}`);
688
+ }
689
+ }
938
690
  toString() {
939
691
  return this.toHex();
940
692
  }
@@ -953,7 +705,7 @@ var PublicKey = class _PublicKey {
953
705
  toMultibase32() {
954
706
  return "B" + base32Encode(this._value, "RFC4648");
955
707
  }
956
- truncate(length = void 0) {
708
+ truncate(length) {
957
709
  return truncateKey(this, length);
958
710
  }
959
711
  asBuffer() {
@@ -968,7 +720,7 @@ var PublicKey = class _PublicKey {
968
720
  /**
969
721
  * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
970
722
  */
971
- [_inspectCustom2](depth, options, inspectFn) {
723
+ [inspectCustom2](depth, options, inspectFn) {
972
724
  if (!options.colors || typeof process.stdout.hasColors !== "function" || !process.stdout.hasColors()) {
973
725
  return `<PublicKey ${this.truncate()}>`;
974
726
  }
@@ -993,7 +745,7 @@ var PublicKey = class _PublicKey {
993
745
  const color = colors[this.getInsecureHash(colors.length)];
994
746
  return `PublicKey(${printControlCode(inspectFn.colors[color][0])}${this.truncate()}${printControlCode(inspectFn.colors.reset[0])})`;
995
747
  }
996
- get [_devtoolsFormatter2]() {
748
+ get [devtoolsFormatter2]() {
997
749
  return {
998
750
  header: () => {
999
751
  const colors = [
@@ -1046,25 +798,17 @@ var PublicKey = class _PublicKey {
1046
798
  }
1047
799
  let equal = true;
1048
800
  for (let i = 0; i < this._value.length; i++) {
1049
- equal && (equal = this._value[i] === otherConverted._value[i]);
801
+ equal &&= this._value[i] === otherConverted._value[i];
1050
802
  }
1051
803
  return equal;
1052
804
  }
1053
- [_equalsSymbol](other) {
805
+ [equalsSymbol](other) {
1054
806
  if (!_PublicKey.isPublicKey(other)) {
1055
807
  return false;
1056
808
  }
1057
809
  return this.equals(other);
1058
810
  }
1059
- constructor(_value) {
1060
- _define_property3(this, "_value", void 0);
1061
- this._value = _value;
1062
- if (!(_value instanceof Uint8Array)) {
1063
- throw new TypeError(`Expected Uint8Array, got: ${_value}`);
1064
- }
1065
- }
1066
811
  };
1067
- _define_property3(PublicKey, "ZERO", PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH)));
1068
812
  export {
1069
813
  DXN,
1070
814
  DXN_ECHO_REGEXP,