@dxos/keys 0.8.4-main.ead640a → 0.8.4-main.f466a3d56e

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.
@@ -108,75 +108,13 @@ import { assertArgument, invariant as invariant2 } from "@dxos/invariant";
108
108
  init_inject_globals();
109
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,66 +124,52 @@ 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);
202
- var makeTestPRNG = () => {
203
- const rng = new SimplePRNG();
130
+ this.#factory = monotonicFactory(makeTestPRNG());
131
+ this.#seedTime = (/* @__PURE__ */ new Date("2025-01-01")).getTime();
132
+ }
133
+ static dangerouslySetSeed(time, seed) {
134
+ this.#factory = monotonicFactory(makeTestPRNG(seed));
135
+ this.#seedTime = time;
136
+ }
137
+ };
138
+ var makeTestPRNG = (seed = 0) => {
139
+ const rng = new SimplePRNG(seed);
204
140
  return () => {
205
141
  return rng.next();
206
142
  };
207
143
  };
208
- var _seed = /* @__PURE__ */ new WeakMap();
209
144
  var SimplePRNG = class _SimplePRNG {
145
+ #seed;
146
+ // LCG parameters (from Numerical Recipes)
147
+ static #a = 1664525;
148
+ static #c = 1013904223;
149
+ static #m = Math.pow(2, 32);
150
+ /**
151
+ * Creates a new PRNG instance.
152
+ * @param seed - Initial seed value. If not provided, uses 0.
153
+ */
154
+ constructor(seed = 0) {
155
+ this.#seed = seed;
156
+ }
210
157
  /**
211
158
  * Generates the next pseudo-random number in the range [0, 1).
212
159
  * @returns A pseudo-random number between 0 (inclusive) and 1 (exclusive).
213
160
  */
214
161
  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);
162
+ this.#seed = (_SimplePRNG.#a * this.#seed + _SimplePRNG.#c) % _SimplePRNG.#m;
163
+ return this.#seed / _SimplePRNG.#m;
217
164
  }
218
165
  /**
219
166
  * Resets the generator with a new seed.
220
167
  * @param seed - New seed value.
221
168
  */
222
169
  reset(seed) {
223
- _class_private_field_set(this, _seed, seed);
224
- }
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);
170
+ this.#seed = seed;
235
171
  }
236
172
  };
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
- };
249
173
 
250
174
  // src/space-id.ts
251
175
  init_inject_globals();
@@ -328,133 +252,78 @@ var randomBytes = (length) => {
328
252
  };
329
253
 
330
254
  // 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
255
  var MULTIBASE_PREFIX = "B";
348
256
  var ENCODED_LENGTH = 33;
349
257
  var isValid = (value) => {
350
258
  return typeof value === "string" && value.startsWith(MULTIBASE_PREFIX) && value.length === ENCODED_LENGTH;
351
259
  };
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);
260
+ var SpaceId = class extends Schema2.String.pipe(Schema2.filter(isValid)) {
261
+ static byteLength = 20;
262
+ static encode = (value) => {
263
+ invariant(value instanceof Uint8Array, "Invalid type");
264
+ invariant(value.length === SpaceId.byteLength, "Invalid length");
265
+ return MULTIBASE_PREFIX + base32Encode(value, "RFC4648");
266
+ };
267
+ static decode = (value) => {
268
+ invariant(value.startsWith(MULTIBASE_PREFIX), "Invalid multibase32 encoding");
269
+ return new Uint8Array((0, import_base32_decode.default)(value.slice(1), "RFC4648"));
270
+ };
271
+ static isValid = isValid;
272
+ static random = () => {
273
+ return SpaceId.encode(randomBytes(SpaceId.byteLength));
274
+ };
275
+ };
387
276
 
388
277
  // 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
278
  var LOCAL_SPACE_TAG = "@";
444
279
  var DXN_ECHO_REGEXP = /@(dxn:[a-zA-Z0-p:@]+)/;
445
280
  var QueueSubspaceTags = Object.freeze({
446
281
  DATA: "data",
447
282
  TRACE: "trace"
448
283
  });
449
- var _kind = /* @__PURE__ */ new WeakMap();
450
- var _parts = /* @__PURE__ */ new WeakMap();
451
- var _inspectCustom = inspectCustom;
452
- var _devtoolsFormatter = devtoolsFormatter;
453
284
  var DXN = class _DXN {
285
+ // TODO(burdon): Rename to DXN (i.e., DXN.DXN).
286
+ // TODO(dmaretskyi): Should this be a transformation into the DXN type?
287
+ static Schema = Schema3.NonEmptyString.pipe(
288
+ Schema3.pattern(/^dxn:([^:]+):(?:[^:]+:?)+[^:]$/),
289
+ // TODO(dmaretskyi): To set the format we need to move the annotation IDs out of the echo-schema package.
290
+ // FormatAnnotation.set(TypeFormat.DXN),
291
+ Schema3.annotations({
292
+ title: "DXN",
293
+ description: "DXN URI",
294
+ examples: [
295
+ "dxn:type:com.example.type.my-type",
296
+ "dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6"
297
+ ]
298
+ })
299
+ );
454
300
  static hash(dxn) {
455
301
  return dxn.toString();
456
302
  }
457
303
  /**
304
+ * Kind constants.
305
+ */
306
+ static kind = Object.freeze({
307
+ /**
308
+ * dxn:type:<type_name>[:<version>]
309
+ */
310
+ TYPE: "type",
311
+ /**
312
+ * dxn:echo:<space_id>:<echo_id>
313
+ * dxn:echo:@:<echo_id>
314
+ */
315
+ // TODO(burdon): Rename to OBJECT? (BREAKING CHANGE to update "echo").
316
+ // TODO(burdon): Add separate Kind for space?
317
+ ECHO: "echo",
318
+ /**
319
+ * The subspace tag enables us to partition queues by usage within the context of a space.
320
+ * dxn:queue:<subspace_tag>:<space_id>:<queue_id>[:object_id]
321
+ * dxn:queue:data:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
322
+ * dxn:queue:trace:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
323
+ */
324
+ QUEUE: "queue"
325
+ });
326
+ /**
458
327
  * Exactly equals.
459
328
  */
460
329
  static equals(a, b) {
@@ -493,7 +362,7 @@ var DXN = class _DXN {
493
362
  }
494
363
  }
495
364
  /**
496
- * @example `dxn:type:example.com/type/Contact`
365
+ * @example `dxn:type:com.example.type.person`
497
366
  */
498
367
  static fromTypename(typename) {
499
368
  return new _DXN(_DXN.kind.TYPE, [
@@ -501,7 +370,7 @@ var DXN = class _DXN {
501
370
  ]);
502
371
  }
503
372
  /**
504
- * @example `dxn:type:example.com/type/Contact:0.1.0`
373
+ * @example `dxn:type:com.example.type.person:0.1.0`
505
374
  */
506
375
  // TODO(dmaretskyi): Consider using @ as the version separator.
507
376
  static fromTypenameAndVersion(typename, version) {
@@ -544,8 +413,28 @@ var DXN = class _DXN {
544
413
  ] : []
545
414
  ]);
546
415
  }
416
+ #kind;
417
+ #parts;
418
+ constructor(kind, parts) {
419
+ assertArgument(parts.length > 0, "parts", `Invalid DXN: ${parts}`);
420
+ assertArgument(parts.every((part) => typeof part === "string" && part.length > 0 && part.indexOf(":") === -1), "parts", `Invalid DXN: ${parts}`);
421
+ switch (kind) {
422
+ case _DXN.kind.TYPE:
423
+ if (parts.length > 2) {
424
+ throw new Error("Invalid DXN.kind.TYPE");
425
+ }
426
+ break;
427
+ case _DXN.kind.ECHO:
428
+ if (parts.length !== 2) {
429
+ throw new Error("Invalid DXN.kind.ECHO");
430
+ }
431
+ break;
432
+ }
433
+ this.#kind = kind;
434
+ this.#parts = parts;
435
+ }
547
436
  toString() {
548
- return `dxn:${_class_private_field_get2(this, _kind)}:${_class_private_field_get2(this, _parts).join(":")}`;
437
+ return `dxn:${this.#kind}:${this.#parts.join(":")}`;
549
438
  }
550
439
  toJSON() {
551
440
  return this.toString();
@@ -553,13 +442,13 @@ var DXN = class _DXN {
553
442
  /**
554
443
  * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
555
444
  */
556
- [_inspectCustom](depth, options, inspectFn) {
445
+ [inspectCustom](depth, options, inspectFn) {
557
446
  const printControlCode = (code) => {
558
447
  return `\x1B[${code}m`;
559
448
  };
560
449
  return printControlCode(inspectFn.colors.blueBright[0]) + this.toString() + printControlCode(inspectFn.colors.reset[0]);
561
450
  }
562
- get [_devtoolsFormatter]() {
451
+ get [devtoolsFormatter]() {
563
452
  return {
564
453
  header: () => {
565
454
  return [
@@ -573,38 +462,30 @@ var DXN = class _DXN {
573
462
  };
574
463
  }
575
464
  get kind() {
576
- return _class_private_field_get2(this, _kind);
465
+ return this.#kind;
577
466
  }
578
467
  get parts() {
579
- return _class_private_field_get2(this, _parts);
468
+ return this.#parts;
580
469
  }
581
470
  // TODO(burdon): Should getters fail?
582
471
  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];
472
+ invariant2(this.#kind === _DXN.kind.TYPE);
473
+ return this.#parts[0];
593
474
  }
594
475
  equals(other) {
595
476
  return _DXN.equals(this, other);
596
477
  }
597
478
  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;
479
+ return this.#kind === _DXN.kind.TYPE && this.#parts.length === 1 && this.#parts[0] === typename;
599
480
  }
600
481
  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;
482
+ return this.#kind === _DXN.kind.ECHO && this.#parts[0] === LOCAL_SPACE_TAG && this.#parts.length === 2;
602
483
  }
603
484
  asTypeDXN() {
604
485
  if (this.kind !== _DXN.kind.TYPE) {
605
486
  return void 0;
606
487
  }
607
- const [type, version] = _class_private_field_get2(this, _parts);
488
+ const [type, version] = this.#parts;
608
489
  return {
609
490
  // TODO(wittjosiah): Should be `typename` for consistency.
610
491
  type,
@@ -615,7 +496,7 @@ var DXN = class _DXN {
615
496
  if (this.kind !== _DXN.kind.ECHO) {
616
497
  return void 0;
617
498
  }
618
- const [spaceId, echoId] = _class_private_field_get2(this, _parts);
499
+ const [spaceId, echoId] = this.#parts;
619
500
  return {
620
501
  spaceId: spaceId === LOCAL_SPACE_TAG ? void 0 : spaceId,
621
502
  // TODO(burdon): objectId.
@@ -626,7 +507,7 @@ var DXN = class _DXN {
626
507
  if (this.kind !== _DXN.kind.QUEUE) {
627
508
  return void 0;
628
509
  }
629
- const [subspaceTag, spaceId, queueId, objectId] = _class_private_field_get2(this, _parts);
510
+ const [subspaceTag, spaceId, queueId, objectId] = this.#parts;
630
511
  if (typeof queueId !== "string") {
631
512
  return void 0;
632
513
  }
@@ -641,110 +522,26 @@ var DXN = class _DXN {
641
522
  * Produces a new DXN with the given parts appended.
642
523
  */
643
524
  extend(parts) {
644
- return new _DXN(_class_private_field_get2(this, _kind), [
645
- ..._class_private_field_get2(this, _parts),
525
+ return new _DXN(this.#kind, [
526
+ ...this.#parts,
646
527
  ...parts
647
528
  ]);
648
529
  }
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
530
  };
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
531
 
710
532
  // src/identity-did.ts
711
533
  init_inject_globals();
712
534
  var import_base32_decode2 = __toESM(require_base32_decode(), 1);
713
535
  import { invariant as invariant3 } from "@dxos/invariant";
714
- var __dxlog_file3 = "/__w/dxos/dxos/packages/common/keys/src/identity-did.ts";
715
536
  var IdentityDid = Object.freeze({
716
537
  byteLength: 20,
717
538
  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
- });
539
+ invariant3(value instanceof Uint8Array, "Invalid type");
540
+ invariant3(value.length === IdentityDid.byteLength, "Invalid length");
736
541
  return DID_PREFIX + MULTIBASE_PREFIX2 + base32Encode(value, "RFC4648");
737
542
  },
738
543
  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
- });
544
+ invariant3(value.startsWith(DID_PREFIX + MULTIBASE_PREFIX2), "Invalid multibase32 encoding");
748
545
  return new Uint8Array((0, import_base32_decode2.default)(value.slice(10), "RFC4648"));
749
546
  },
750
547
  isValid: (value) => {
@@ -758,47 +555,51 @@ var MULTIBASE_PREFIX2 = "B";
758
555
  var DID_PREFIX = "did:halo:";
759
556
  var ENCODED_LENGTH2 = 42;
760
557
 
558
+ // src/parse-id.ts
559
+ init_inject_globals();
560
+ var SPACE_ID_LENGTH = 33;
561
+ var OBJECT_ID_LENGTH = 26;
562
+ var FQ_ID_LENGTH = SPACE_ID_LENGTH + OBJECT_ID_LENGTH + 1;
563
+ var parseId = (id) => {
564
+ if (!id) {
565
+ return {};
566
+ } else if (id.length === SPACE_ID_LENGTH) {
567
+ return {
568
+ spaceId: id
569
+ };
570
+ } else if (id.length === OBJECT_ID_LENGTH) {
571
+ return {
572
+ objectId: id
573
+ };
574
+ } else if (id.length === FQ_ID_LENGTH && id.indexOf(":") === SPACE_ID_LENGTH) {
575
+ const [spaceId, objectId] = id.split(":");
576
+ return {
577
+ spaceId,
578
+ objectId
579
+ };
580
+ } else {
581
+ return {};
582
+ }
583
+ };
584
+
761
585
  // src/public-key.ts
762
586
  init_inject_globals();
763
587
  var import_base32_decode3 = __toESM(require_base32_decode(), 1);
764
588
  import { devtoolsFormatter as devtoolsFormatter2, equalsSymbol, inspectCustom as inspectCustom2, truncateKey } from "@dxos/debug";
765
589
  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
590
  var PUBLIC_KEY_LENGTH = 32;
781
591
  var SECRET_KEY_LENGTH = 64;
782
592
  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
593
  var PublicKey = class _PublicKey {
594
+ _value;
595
+ static ZERO = _PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH));
787
596
  /**
788
597
  * Creates new instance of PublicKey automatically determining the input format.
789
598
  * @param source A Buffer, or Uint8Array, or hex encoded string, or something with an `asUint8Array` method on it
790
599
  * @returns PublicKey
791
600
  */
792
601
  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
- });
602
+ invariant4(source);
802
603
  if (source instanceof _PublicKey) {
803
604
  return source;
804
605
  } else if (source instanceof Buffer2) {
@@ -882,15 +683,7 @@ var PublicKey = class _PublicKey {
882
683
  * @deprecated All keys should be represented as instances of PublicKey.
883
684
  */
884
685
  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
- });
686
+ invariant4(typeof str === "string", "Invalid type");
894
687
  const buffer = Buffer2.from(str, "hex");
895
688
  return buffer;
896
689
  }
@@ -905,15 +698,7 @@ var PublicKey = class _PublicKey {
905
698
  } else if (key instanceof Uint8Array) {
906
699
  key = Buffer2.from(key.buffer, key.byteOffset, key.byteLength);
907
700
  }
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
- });
701
+ invariant4(key instanceof Buffer2, "Invalid type");
917
702
  return key.toString("hex");
918
703
  }
919
704
  /**
@@ -924,17 +709,15 @@ var PublicKey = class _PublicKey {
924
709
  return key.toHex();
925
710
  }
926
711
  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
- });
712
+ invariant4(encoded.startsWith("B"), "Invalid multibase32 encoding");
936
713
  return new _PublicKey(new Uint8Array((0, import_base32_decode3.default)(encoded.slice(1), "RFC4648")));
937
714
  }
715
+ constructor(_value) {
716
+ this._value = _value;
717
+ if (!(_value instanceof Uint8Array)) {
718
+ throw new TypeError(`Expected Uint8Array, got: ${_value}`);
719
+ }
720
+ }
938
721
  toString() {
939
722
  return this.toHex();
940
723
  }
@@ -953,7 +736,7 @@ var PublicKey = class _PublicKey {
953
736
  toMultibase32() {
954
737
  return "B" + base32Encode(this._value, "RFC4648");
955
738
  }
956
- truncate(length = void 0) {
739
+ truncate(length) {
957
740
  return truncateKey(this, length);
958
741
  }
959
742
  asBuffer() {
@@ -968,7 +751,7 @@ var PublicKey = class _PublicKey {
968
751
  /**
969
752
  * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
970
753
  */
971
- [_inspectCustom2](depth, options, inspectFn) {
754
+ [inspectCustom2](depth, options, inspectFn) {
972
755
  if (!options.colors || typeof process.stdout.hasColors !== "function" || !process.stdout.hasColors()) {
973
756
  return `<PublicKey ${this.truncate()}>`;
974
757
  }
@@ -993,7 +776,7 @@ var PublicKey = class _PublicKey {
993
776
  const color = colors[this.getInsecureHash(colors.length)];
994
777
  return `PublicKey(${printControlCode(inspectFn.colors[color][0])}${this.truncate()}${printControlCode(inspectFn.colors.reset[0])})`;
995
778
  }
996
- get [_devtoolsFormatter2]() {
779
+ get [devtoolsFormatter2]() {
997
780
  return {
998
781
  header: () => {
999
782
  const colors = [
@@ -1046,36 +829,32 @@ var PublicKey = class _PublicKey {
1046
829
  }
1047
830
  let equal = true;
1048
831
  for (let i = 0; i < this._value.length; i++) {
1049
- equal && (equal = this._value[i] === otherConverted._value[i]);
832
+ equal &&= this._value[i] === otherConverted._value[i];
1050
833
  }
1051
834
  return equal;
1052
835
  }
1053
- [_equalsSymbol](other) {
836
+ [equalsSymbol](other) {
1054
837
  if (!_PublicKey.isPublicKey(other)) {
1055
838
  return false;
1056
839
  }
1057
840
  return this.equals(other);
1058
841
  }
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
842
  };
1067
- _define_property3(PublicKey, "ZERO", PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH)));
1068
843
  export {
1069
844
  DXN,
1070
845
  DXN_ECHO_REGEXP,
846
+ FQ_ID_LENGTH,
1071
847
  IdentityDid,
1072
848
  LOCAL_SPACE_TAG,
849
+ OBJECT_ID_LENGTH,
1073
850
  ObjectId,
1074
851
  PUBLIC_KEY_LENGTH,
1075
852
  PublicKey,
1076
853
  QueueSubspaceTags,
1077
854
  SECRET_KEY_LENGTH,
855
+ SPACE_ID_LENGTH,
1078
856
  SimplePRNG,
1079
- SpaceId
857
+ SpaceId,
858
+ parseId
1080
859
  };
1081
860
  //# sourceMappingURL=index.mjs.map