@dxos/keys 0.8.3 → 0.8.4-main.16b68245aa

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.
@@ -31,9 +31,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
31
31
  mod
32
32
  ));
33
33
 
34
- // node_modules/.pnpm/base32-decode@1.0.0/node_modules/base32-decode/index.js
34
+ // ../../../node_modules/.pnpm/base32-decode@1.0.0/node_modules/base32-decode/index.js
35
35
  var require_base32_decode = __commonJS({
36
- "node_modules/.pnpm/base32-decode@1.0.0/node_modules/base32-decode/index.js"(exports, module) {
36
+ "../../../node_modules/.pnpm/base32-decode@1.0.0/node_modules/base32-decode/index.js"(exports, module) {
37
37
  var RFC46482 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
38
38
  var RFC4648_HEX2 = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
39
39
  var CROCKFORD2 = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
@@ -81,36 +81,77 @@ var require_base32_decode = __commonJS({
81
81
  }
82
82
  });
83
83
 
84
- // packages/common/keys/src/dxn.ts
85
- import { Schema as Schema3 } from "effect";
84
+ // src/dxn.ts
85
+ import * as Schema3 from "effect/Schema";
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
- // packages/common/keys/src/object-id.ts
90
- import { Schema } from "effect";
91
- import { ulid } from "ulidx";
89
+ // src/object-id.ts
90
+ import * as Schema from "effect/Schema";
91
+ import { monotonicFactory } from "ulidx";
92
92
  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",
93
+ description: "A Universally Unique Lexicographically Sortable Identifier",
94
94
  pattern: "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
95
95
  });
96
96
  var ObjectId = class extends ObjectIdSchema {
97
+ static #factory = monotonicFactory();
98
+ static #seedTime = void 0;
97
99
  static isValid(id) {
98
100
  try {
99
101
  Schema.decodeSync(ObjectId)(id);
100
102
  return true;
101
- } catch (err) {
103
+ } catch {
102
104
  return false;
103
105
  }
104
106
  }
105
107
  static random() {
106
- return ulid();
108
+ return this.#factory(this.#seedTime);
109
+ }
110
+ static dangerouslyDisableRandomness() {
111
+ this.#factory = monotonicFactory(makeTestPRNG());
112
+ this.#seedTime = (/* @__PURE__ */ new Date("2025-01-01")).getTime();
113
+ }
114
+ };
115
+ var makeTestPRNG = () => {
116
+ const rng = new SimplePRNG();
117
+ return () => {
118
+ return rng.next();
119
+ };
120
+ };
121
+ var SimplePRNG = class _SimplePRNG {
122
+ #seed;
123
+ // LCG parameters (from Numerical Recipes)
124
+ static #a = 1664525;
125
+ static #c = 1013904223;
126
+ static #m = Math.pow(2, 32);
127
+ /**
128
+ * Creates a new PRNG instance.
129
+ * @param seed - Initial seed value. If not provided, uses 0.
130
+ */
131
+ constructor(seed = 0) {
132
+ this.#seed = seed;
133
+ }
134
+ /**
135
+ * Generates the next pseudo-random number in the range [0, 1).
136
+ * @returns A pseudo-random number between 0 (inclusive) and 1 (exclusive).
137
+ */
138
+ next() {
139
+ this.#seed = (_SimplePRNG.#a * this.#seed + _SimplePRNG.#c) % _SimplePRNG.#m;
140
+ return this.#seed / _SimplePRNG.#m;
141
+ }
142
+ /**
143
+ * Resets the generator with a new seed.
144
+ * @param seed - New seed value.
145
+ */
146
+ reset(seed) {
147
+ this.#seed = seed;
107
148
  }
108
149
  };
109
150
 
110
- // packages/common/keys/src/space-id.ts
151
+ // src/space-id.ts
111
152
  var import_base32_decode = __toESM(require_base32_decode(), 1);
112
153
 
113
- // node_modules/.pnpm/to-data-view@2.0.0/node_modules/to-data-view/index.js
154
+ // ../../../node_modules/.pnpm/to-data-view@2.0.0/node_modules/to-data-view/index.js
114
155
  function toDataView(data) {
115
156
  if (data instanceof Int8Array || data instanceof Uint8Array || data instanceof Uint8ClampedArray) {
116
157
  return new DataView(data.buffer, data.byteOffset, data.byteLength);
@@ -121,7 +162,7 @@ function toDataView(data) {
121
162
  throw new TypeError("Expected `data` to be an ArrayBuffer, Buffer, Int8Array, Uint8Array or Uint8ClampedArray");
122
163
  }
123
164
 
124
- // node_modules/.pnpm/base32-encode@2.0.0/node_modules/base32-encode/index.js
165
+ // ../../../node_modules/.pnpm/base32-encode@2.0.0/node_modules/base32-encode/index.js
125
166
  var RFC4648 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
126
167
  var RFC4648_HEX = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
127
168
  var CROCKFORD = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
@@ -169,11 +210,11 @@ function base32Encode(data, variant, options) {
169
210
  return output;
170
211
  }
171
212
 
172
- // packages/common/keys/src/space-id.ts
173
- import { Schema as Schema2 } from "effect";
213
+ // src/space-id.ts
214
+ import * as Schema2 from "effect/Schema";
174
215
  import { invariant } from "@dxos/invariant";
175
216
 
176
- // packages/common/keys/src/random-bytes.ts
217
+ // src/random-bytes.ts
177
218
  var randomBytes = (length) => {
178
219
  const webCrypto = globalThis.crypto ?? __require("node:crypto").webcrypto;
179
220
  const bytes = new Uint8Array(length);
@@ -181,122 +222,89 @@ var randomBytes = (length) => {
181
222
  return bytes;
182
223
  };
183
224
 
184
- // packages/common/keys/src/space-id.ts
185
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/common/keys/src/space-id.ts";
225
+ // src/space-id.ts
186
226
  var MULTIBASE_PREFIX = "B";
187
227
  var ENCODED_LENGTH = 33;
188
228
  var isValid = (value) => {
189
229
  return typeof value === "string" && value.startsWith(MULTIBASE_PREFIX) && value.length === ENCODED_LENGTH;
190
230
  };
191
231
  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
- };
217
- }
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
- };
231
- }
232
- static {
233
- this.isValid = isValid;
234
- }
235
- static {
236
- this.random = () => {
237
- return SpaceId.encode(randomBytes(SpaceId.byteLength));
238
- };
239
- }
232
+ static byteLength = 20;
233
+ static encode = (value) => {
234
+ invariant(value instanceof Uint8Array, "Invalid type");
235
+ invariant(value.length === SpaceId.byteLength, "Invalid length");
236
+ return MULTIBASE_PREFIX + base32Encode(value, "RFC4648");
237
+ };
238
+ static decode = (value) => {
239
+ invariant(value.startsWith(MULTIBASE_PREFIX), "Invalid multibase32 encoding");
240
+ return new Uint8Array((0, import_base32_decode.default)(value.slice(1), "RFC4648"));
241
+ };
242
+ static isValid = isValid;
243
+ static random = () => {
244
+ return SpaceId.encode(randomBytes(SpaceId.byteLength));
245
+ };
240
246
  };
241
247
 
242
- // packages/common/keys/src/dxn.ts
243
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/common/keys/src/dxn.ts";
248
+ // src/dxn.ts
244
249
  var LOCAL_SPACE_TAG = "@";
250
+ var DXN_ECHO_REGEXP = /@(dxn:[a-zA-Z0-p:@]+)/;
245
251
  var QueueSubspaceTags = Object.freeze({
246
252
  DATA: "data",
247
253
  TRACE: "trace"
248
254
  });
249
255
  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
- }
256
+ // TODO(burdon): Rename to DXN (i.e., DXN.DXN).
257
+ // TODO(dmaretskyi): Should this be a transformation into the DXN type?
258
+ static Schema = Schema3.NonEmptyString.pipe(
259
+ Schema3.pattern(/^dxn:([^:]+):(?:[^:]+:?)+[^:]$/),
260
+ // TODO(dmaretskyi): To set the format we need to move the annotation IDs out of the echo-schema package.
261
+ // FormatAnnotation.set(TypeFormat.DXN),
262
+ Schema3.annotations({
263
+ title: "DXN",
264
+ description: "DXN URI",
265
+ examples: [
266
+ "dxn:type:com.example.type.my-type",
267
+ "dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6"
268
+ ]
269
+ })
270
+ );
266
271
  static hash(dxn) {
267
272
  return dxn.toString();
268
273
  }
269
- static {
274
+ /**
275
+ * Kind constants.
276
+ */
277
+ static kind = Object.freeze({
270
278
  /**
271
- * Kind constants.
279
+ * dxn:type:<type_name>[:<version>]
272
280
  */
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
- }
281
+ TYPE: "type",
282
+ /**
283
+ * dxn:echo:<space_id>:<echo_id>
284
+ * dxn:echo:@:<echo_id>
285
+ */
286
+ // TODO(burdon): Rename to OBJECT? (BREAKING CHANGE to update "echo").
287
+ // TODO(burdon): Add separate Kind for space?
288
+ ECHO: "echo",
289
+ /**
290
+ * The subspace tag enables us to partition queues by usage within the context of a space.
291
+ * dxn:queue:<subspace_tag>:<space_id>:<queue_id>[:object_id]
292
+ * dxn:queue:data:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
293
+ * dxn:queue:trace:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
294
+ */
295
+ QUEUE: "queue"
296
+ });
297
+ /**
298
+ * Exactly equals.
299
+ */
297
300
  static equals(a, b) {
298
301
  return a.kind === b.kind && a.parts.length === b.parts.length && a.parts.every((part, i) => part === b.parts[i]);
299
302
  }
303
+ static equalsEchoId(a, b) {
304
+ const a1 = a.asEchoDXN();
305
+ const b1 = b.asEchoDXN();
306
+ return !!a1 && !!b1 && a1.echoId === b1.echoId;
307
+ }
300
308
  // TODO(burdon): Rename isValid.
301
309
  static isDXNString(dxn) {
302
310
  return dxn.startsWith("dxn:");
@@ -320,12 +328,12 @@ var DXN = class _DXN {
320
328
  static tryParse(dxn) {
321
329
  try {
322
330
  return _DXN.parse(dxn);
323
- } catch (error) {
331
+ } catch {
324
332
  return void 0;
325
333
  }
326
334
  }
327
335
  /**
328
- * @example `dxn:type:example.com/type/Contact`
336
+ * @example `dxn:type:com.example.type.person`
329
337
  */
330
338
  static fromTypename(typename) {
331
339
  return new _DXN(_DXN.kind.TYPE, [
@@ -333,7 +341,7 @@ var DXN = class _DXN {
333
341
  ]);
334
342
  }
335
343
  /**
336
- * @example `dxn:type:example.com/type/Contact:0.1.0`
344
+ * @example `dxn:type:com.example.type.person:0.1.0`
337
345
  */
338
346
  // TODO(dmaretskyi): Consider using @ as the version separator.
339
347
  static fromTypenameAndVersion(typename, version) {
@@ -343,42 +351,30 @@ var DXN = class _DXN {
343
351
  ]);
344
352
  }
345
353
  /**
354
+ * @example `dxn:echo:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6`
355
+ */
356
+ static fromSpaceAndObjectId(spaceId, objectId) {
357
+ assertArgument(SpaceId.isValid(spaceId), `Invalid space ID: ${spaceId}`);
358
+ assertArgument(ObjectId.isValid(objectId), "objectId", `Invalid object ID: ${objectId}`);
359
+ return new _DXN(_DXN.kind.ECHO, [
360
+ spaceId,
361
+ objectId
362
+ ]);
363
+ }
364
+ /**
346
365
  * @example `dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6`
347
366
  */
348
367
  static fromLocalObjectId(id) {
368
+ assertArgument(ObjectId.isValid(id), "id", `Invalid object ID: ${id}`);
349
369
  return new _DXN(_DXN.kind.ECHO, [
350
370
  LOCAL_SPACE_TAG,
351
371
  id
352
372
  ]);
353
373
  }
354
374
  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
- });
375
+ assertArgument(SpaceId.isValid(spaceId), `Invalid space ID: ${spaceId}`);
376
+ assertArgument(ObjectId.isValid(queueId), "queueId", `Invalid queue ID: ${queueId}`);
377
+ assertArgument(!objectId || ObjectId.isValid(objectId), "objectId", `Invalid object ID: ${objectId}`);
382
378
  return new _DXN(_DXN.kind.QUEUE, [
383
379
  subspaceTag,
384
380
  spaceId,
@@ -391,55 +387,65 @@ var DXN = class _DXN {
391
387
  #kind;
392
388
  #parts;
393
389
  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
- });
390
+ assertArgument(parts.length > 0, "parts", `Invalid DXN: ${parts}`);
391
+ assertArgument(parts.every((part) => typeof part === "string" && part.length > 0 && part.indexOf(":") === -1), "parts", `Invalid DXN: ${parts}`);
412
392
  switch (kind) {
413
393
  case _DXN.kind.TYPE:
414
394
  if (parts.length > 2) {
415
- throw new Error('Invalid "type" DXN');
395
+ throw new Error("Invalid DXN.kind.TYPE");
416
396
  }
417
397
  break;
418
398
  case _DXN.kind.ECHO:
419
399
  if (parts.length !== 2) {
420
- throw new Error('Invalid "echo" DXN');
400
+ throw new Error("Invalid DXN.kind.ECHO");
421
401
  }
422
402
  break;
423
403
  }
424
404
  this.#kind = kind;
425
405
  this.#parts = parts;
426
406
  }
407
+ toString() {
408
+ return `dxn:${this.#kind}:${this.#parts.join(":")}`;
409
+ }
410
+ toJSON() {
411
+ return this.toString();
412
+ }
413
+ /**
414
+ * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
415
+ */
416
+ [inspectCustom](depth, options, inspectFn) {
417
+ const printControlCode = (code) => {
418
+ return `\x1B[${code}m`;
419
+ };
420
+ return printControlCode(inspectFn.colors.blueBright[0]) + this.toString() + printControlCode(inspectFn.colors.reset[0]);
421
+ }
422
+ get [devtoolsFormatter]() {
423
+ return {
424
+ header: () => {
425
+ return [
426
+ "span",
427
+ {
428
+ style: "font-weight: bold;"
429
+ },
430
+ this.toString()
431
+ ];
432
+ }
433
+ };
434
+ }
435
+ get kind() {
436
+ return this.#kind;
437
+ }
427
438
  get parts() {
428
439
  return this.#parts;
429
440
  }
430
441
  // TODO(burdon): Should getters fail?
431
442
  get typename() {
432
- invariant2(this.#kind === _DXN.kind.TYPE, void 0, {
433
- F: __dxlog_file2,
434
- L: 188,
435
- S: this,
436
- A: [
437
- "this.#kind === DXN.kind.TYPE",
438
- ""
439
- ]
440
- });
443
+ invariant2(this.#kind === _DXN.kind.TYPE);
441
444
  return this.#parts[0];
442
445
  }
446
+ equals(other) {
447
+ return _DXN.equals(this, other);
448
+ }
443
449
  hasTypenameOf(typename) {
444
450
  return this.#kind === _DXN.kind.TYPE && this.#parts.length === 1 && this.#parts[0] === typename;
445
451
  }
@@ -452,6 +458,7 @@ var DXN = class _DXN {
452
458
  }
453
459
  const [type, version] = this.#parts;
454
460
  return {
461
+ // TODO(wittjosiah): Should be `typename` for consistency.
455
462
  type,
456
463
  version
457
464
  };
@@ -463,6 +470,7 @@ var DXN = class _DXN {
463
470
  const [spaceId, echoId] = this.#parts;
464
471
  return {
465
472
  spaceId: spaceId === LOCAL_SPACE_TAG ? void 0 : spaceId,
473
+ // TODO(burdon): objectId.
466
474
  echoId
467
475
  };
468
476
  }
@@ -481,70 +489,29 @@ var DXN = class _DXN {
481
489
  objectId
482
490
  };
483
491
  }
484
- toString() {
485
- return `dxn:${this.#kind}:${this.#parts.join(":")}`;
486
- }
487
492
  /**
488
- * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
493
+ * Produces a new DXN with the given parts appended.
489
494
  */
490
- [inspectCustom](depth, options, inspectFn) {
491
- const printControlCode = (code) => {
492
- return `\x1B[${code}m`;
493
- };
494
- return printControlCode(inspectFn.colors.blueBright[0]) + this.toString() + printControlCode(inspectFn.colors.reset[0]);
495
- }
496
- get [devtoolsFormatter]() {
497
- return {
498
- header: () => {
499
- return [
500
- "span",
501
- {
502
- style: "font-weight: bold;"
503
- },
504
- this.toString()
505
- ];
506
- }
507
- };
495
+ extend(parts) {
496
+ return new _DXN(this.#kind, [
497
+ ...this.#parts,
498
+ ...parts
499
+ ]);
508
500
  }
509
501
  };
510
502
 
511
- // packages/common/keys/src/identity-did.ts
503
+ // src/identity-did.ts
512
504
  var import_base32_decode2 = __toESM(require_base32_decode(), 1);
513
505
  import { invariant as invariant3 } from "@dxos/invariant";
514
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/common/keys/src/identity-did.ts";
515
506
  var IdentityDid = Object.freeze({
516
507
  byteLength: 20,
517
508
  encode: (value) => {
518
- invariant3(value instanceof Uint8Array, "Invalid type", {
519
- F: __dxlog_file3,
520
- L: 22,
521
- S: void 0,
522
- A: [
523
- "value instanceof Uint8Array",
524
- "'Invalid type'"
525
- ]
526
- });
527
- invariant3(value.length === IdentityDid.byteLength, "Invalid length", {
528
- F: __dxlog_file3,
529
- L: 23,
530
- S: void 0,
531
- A: [
532
- "value.length === IdentityDid.byteLength",
533
- "'Invalid length'"
534
- ]
535
- });
509
+ invariant3(value instanceof Uint8Array, "Invalid type");
510
+ invariant3(value.length === IdentityDid.byteLength, "Invalid length");
536
511
  return DID_PREFIX + MULTIBASE_PREFIX2 + base32Encode(value, "RFC4648");
537
512
  },
538
513
  decode: (value) => {
539
- invariant3(value.startsWith(DID_PREFIX + MULTIBASE_PREFIX2), "Invalid multibase32 encoding", {
540
- F: __dxlog_file3,
541
- L: 28,
542
- S: void 0,
543
- A: [
544
- "value.startsWith(DID_PREFIX + MULTIBASE_PREFIX)",
545
- "'Invalid multibase32 encoding'"
546
- ]
547
- });
514
+ invariant3(value.startsWith(DID_PREFIX + MULTIBASE_PREFIX2), "Invalid multibase32 encoding");
548
515
  return new Uint8Array((0, import_base32_decode2.default)(value.slice(10), "RFC4648"));
549
516
  },
550
517
  isValid: (value) => {
@@ -558,33 +525,23 @@ var MULTIBASE_PREFIX2 = "B";
558
525
  var DID_PREFIX = "did:halo:";
559
526
  var ENCODED_LENGTH2 = 42;
560
527
 
561
- // packages/common/keys/src/public-key.ts
528
+ // src/public-key.ts
562
529
  var import_base32_decode3 = __toESM(require_base32_decode(), 1);
563
530
  import { devtoolsFormatter as devtoolsFormatter2, equalsSymbol, inspectCustom as inspectCustom2, truncateKey } from "@dxos/debug";
564
531
  import { invariant as invariant4 } from "@dxos/invariant";
565
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/common/keys/src/public-key.ts";
566
532
  var PUBLIC_KEY_LENGTH = 32;
567
533
  var SECRET_KEY_LENGTH = 64;
568
534
  var isLikeArrayBuffer = (value) => typeof value === "object" && value !== null && Object.getPrototypeOf(value).constructor.name === "ArrayBuffer";
569
535
  var PublicKey = class _PublicKey {
570
- static {
571
- this.ZERO = _PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH));
572
- }
536
+ _value;
537
+ static ZERO = _PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH));
573
538
  /**
574
539
  * Creates new instance of PublicKey automatically determining the input format.
575
540
  * @param source A Buffer, or Uint8Array, or hex encoded string, or something with an `asUint8Array` method on it
576
541
  * @returns PublicKey
577
542
  */
578
543
  static from(source) {
579
- invariant4(source, void 0, {
580
- F: __dxlog_file4,
581
- L: 49,
582
- S: this,
583
- A: [
584
- "source",
585
- ""
586
- ]
587
- });
544
+ invariant4(source);
588
545
  if (source instanceof _PublicKey) {
589
546
  return source;
590
547
  } else if (source instanceof Buffer) {
@@ -668,15 +625,7 @@ var PublicKey = class _PublicKey {
668
625
  * @deprecated All keys should be represented as instances of PublicKey.
669
626
  */
670
627
  static bufferize(str) {
671
- invariant4(typeof str === "string", "Invalid type", {
672
- F: __dxlog_file4,
673
- L: 152,
674
- S: this,
675
- A: [
676
- "typeof str === 'string'",
677
- "'Invalid type'"
678
- ]
679
- });
628
+ invariant4(typeof str === "string", "Invalid type");
680
629
  const buffer = Buffer.from(str, "hex");
681
630
  return buffer;
682
631
  }
@@ -691,15 +640,7 @@ var PublicKey = class _PublicKey {
691
640
  } else if (key instanceof Uint8Array) {
692
641
  key = Buffer.from(key.buffer, key.byteOffset, key.byteLength);
693
642
  }
694
- invariant4(key instanceof Buffer, "Invalid type", {
695
- F: __dxlog_file4,
696
- L: 171,
697
- S: this,
698
- A: [
699
- "key instanceof Buffer",
700
- "'Invalid type'"
701
- ]
702
- });
643
+ invariant4(key instanceof Buffer, "Invalid type");
703
644
  return key.toString("hex");
704
645
  }
705
646
  /**
@@ -710,15 +651,7 @@ var PublicKey = class _PublicKey {
710
651
  return key.toHex();
711
652
  }
712
653
  static fromMultibase32(encoded) {
713
- invariant4(encoded.startsWith("B"), "Invalid multibase32 encoding", {
714
- F: __dxlog_file4,
715
- L: 184,
716
- S: this,
717
- A: [
718
- "encoded.startsWith('B')",
719
- "'Invalid multibase32 encoding'"
720
- ]
721
- });
654
+ invariant4(encoded.startsWith("B"), "Invalid multibase32 encoding");
722
655
  return new _PublicKey(new Uint8Array((0, import_base32_decode3.default)(encoded.slice(1), "RFC4648")));
723
656
  }
724
657
  constructor(_value) {
@@ -745,7 +678,7 @@ var PublicKey = class _PublicKey {
745
678
  toMultibase32() {
746
679
  return "B" + base32Encode(this._value, "RFC4648");
747
680
  }
748
- truncate(length = void 0) {
681
+ truncate(length) {
749
682
  return truncateKey(this, length);
750
683
  }
751
684
  asBuffer() {
@@ -851,6 +784,7 @@ var PublicKey = class _PublicKey {
851
784
  };
852
785
  export {
853
786
  DXN,
787
+ DXN_ECHO_REGEXP,
854
788
  IdentityDid,
855
789
  LOCAL_SPACE_TAG,
856
790
  ObjectId,
@@ -858,6 +792,7 @@ export {
858
792
  PublicKey,
859
793
  QueueSubspaceTags,
860
794
  SECRET_KEY_LENGTH,
795
+ SimplePRNG,
861
796
  SpaceId
862
797
  };
863
798
  //# sourceMappingURL=index.mjs.map