@dxos/keys 0.8.4-main.dedc0f3 → 0.8.4-main.e00bdcdb52

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,19 +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";
110
- import { ulid } from "ulidx";
109
+ import * as Schema from "effect/Schema";
110
+ import { monotonicFactory } from "ulidx";
111
111
  var ObjectIdSchema = Schema.String.pipe(Schema.pattern(/^[0-7][0-9A-HJKMNP-TV-Z]{25}$/i)).annotations({
112
112
  description: "A Universally Unique Lexicographically Sortable Identifier",
113
113
  pattern: "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
114
114
  });
115
115
  var ObjectId = class extends ObjectIdSchema {
116
+ static #factory = monotonicFactory();
117
+ static #seedTime = void 0;
116
118
  static isValid(id) {
117
119
  try {
118
120
  Schema.decodeSync(ObjectId)(id);
@@ -122,7 +124,46 @@ var ObjectId = class extends ObjectIdSchema {
122
124
  }
123
125
  }
124
126
  static random() {
125
- return ulid();
127
+ return this.#factory(this.#seedTime);
128
+ }
129
+ static dangerouslyDisableRandomness() {
130
+ this.#factory = monotonicFactory(makeTestPRNG());
131
+ this.#seedTime = (/* @__PURE__ */ new Date("2025-01-01")).getTime();
132
+ }
133
+ };
134
+ var makeTestPRNG = () => {
135
+ const rng = new SimplePRNG();
136
+ return () => {
137
+ return rng.next();
138
+ };
139
+ };
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
+ }
153
+ /**
154
+ * Generates the next pseudo-random number in the range [0, 1).
155
+ * @returns A pseudo-random number between 0 (inclusive) and 1 (exclusive).
156
+ */
157
+ next() {
158
+ this.#seed = (_SimplePRNG.#a * this.#seed + _SimplePRNG.#c) % _SimplePRNG.#m;
159
+ return this.#seed / _SimplePRNG.#m;
160
+ }
161
+ /**
162
+ * Resets the generator with a new seed.
163
+ * @param seed - New seed value.
164
+ */
165
+ reset(seed) {
166
+ this.#seed = seed;
126
167
  }
127
168
  };
128
169
 
@@ -194,7 +235,7 @@ function base32Encode(data, variant, options) {
194
235
  }
195
236
 
196
237
  // src/space-id.ts
197
- import { Schema as Schema2 } from "effect";
238
+ import * as Schema2 from "effect/Schema";
198
239
  import { invariant } from "@dxos/invariant";
199
240
 
200
241
  // src/random-bytes.ts
@@ -207,133 +248,78 @@ var randomBytes = (length) => {
207
248
  };
208
249
 
209
250
  // src/space-id.ts
210
- function _define_property(obj, key, value) {
211
- if (key in obj) {
212
- Object.defineProperty(obj, key, {
213
- value,
214
- enumerable: true,
215
- configurable: true,
216
- writable: true
217
- });
218
- } else {
219
- obj[key] = value;
220
- }
221
- return obj;
222
- }
223
- var _Schema_String_pipe;
224
- var _class;
225
- var __dxlog_file = "/__w/dxos/dxos/packages/common/keys/src/space-id.ts";
226
251
  var MULTIBASE_PREFIX = "B";
227
252
  var ENCODED_LENGTH = 33;
228
253
  var isValid = (value) => {
229
254
  return typeof value === "string" && value.startsWith(MULTIBASE_PREFIX) && value.length === ENCODED_LENGTH;
230
255
  };
231
- var SpaceId = (_class = class extends (_Schema_String_pipe = Schema2.String.pipe(Schema2.filter(isValid))) {
232
- }, _define_property(_class, "byteLength", 20), _define_property(_class, "encode", (value) => {
233
- invariant(value instanceof Uint8Array, "Invalid type", {
234
- F: __dxlog_file,
235
- L: 43,
236
- S: _class,
237
- A: [
238
- "value instanceof Uint8Array",
239
- "'Invalid type'"
240
- ]
241
- });
242
- invariant(value.length === SpaceId.byteLength, "Invalid length", {
243
- F: __dxlog_file,
244
- L: 44,
245
- S: _class,
246
- A: [
247
- "value.length === SpaceId.byteLength",
248
- "'Invalid length'"
249
- ]
250
- });
251
- return MULTIBASE_PREFIX + base32Encode(value, "RFC4648");
252
- }), _define_property(_class, "decode", (value) => {
253
- invariant(value.startsWith(MULTIBASE_PREFIX), "Invalid multibase32 encoding", {
254
- F: __dxlog_file,
255
- L: 49,
256
- S: _class,
257
- A: [
258
- "value.startsWith(MULTIBASE_PREFIX)",
259
- "'Invalid multibase32 encoding'"
260
- ]
261
- });
262
- return new Uint8Array((0, import_base32_decode.default)(value.slice(1), "RFC4648"));
263
- }), _define_property(_class, "isValid", isValid), _define_property(_class, "random", () => {
264
- return SpaceId.encode(randomBytes(SpaceId.byteLength));
265
- }), _class);
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
+ };
266
272
 
267
273
  // src/dxn.ts
268
- function _check_private_redeclaration(obj, privateCollection) {
269
- if (privateCollection.has(obj)) {
270
- throw new TypeError("Cannot initialize the same private elements twice on an object");
271
- }
272
- }
273
- function _class_apply_descriptor_get(receiver, descriptor) {
274
- if (descriptor.get) {
275
- return descriptor.get.call(receiver);
276
- }
277
- return descriptor.value;
278
- }
279
- function _class_apply_descriptor_set(receiver, descriptor, value) {
280
- if (descriptor.set) {
281
- descriptor.set.call(receiver, value);
282
- } else {
283
- if (!descriptor.writable) {
284
- throw new TypeError("attempted to set read only private field");
285
- }
286
- descriptor.value = value;
287
- }
288
- }
289
- function _class_extract_field_descriptor(receiver, privateMap, action) {
290
- if (!privateMap.has(receiver)) {
291
- throw new TypeError("attempted to " + action + " private field on non-instance");
292
- }
293
- return privateMap.get(receiver);
294
- }
295
- function _class_private_field_get(receiver, privateMap) {
296
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
297
- return _class_apply_descriptor_get(receiver, descriptor);
298
- }
299
- function _class_private_field_init(obj, privateMap, value) {
300
- _check_private_redeclaration(obj, privateMap);
301
- privateMap.set(obj, value);
302
- }
303
- function _class_private_field_set(receiver, privateMap, value) {
304
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
305
- _class_apply_descriptor_set(receiver, descriptor, value);
306
- return value;
307
- }
308
- function _define_property2(obj, key, value) {
309
- if (key in obj) {
310
- Object.defineProperty(obj, key, {
311
- value,
312
- enumerable: true,
313
- configurable: true,
314
- writable: true
315
- });
316
- } else {
317
- obj[key] = value;
318
- }
319
- return obj;
320
- }
321
- var __dxlog_file2 = "/__w/dxos/dxos/packages/common/keys/src/dxn.ts";
322
274
  var LOCAL_SPACE_TAG = "@";
323
275
  var DXN_ECHO_REGEXP = /@(dxn:[a-zA-Z0-p:@]+)/;
324
276
  var QueueSubspaceTags = Object.freeze({
325
277
  DATA: "data",
326
278
  TRACE: "trace"
327
279
  });
328
- var _kind = /* @__PURE__ */ new WeakMap();
329
- var _parts = /* @__PURE__ */ new WeakMap();
330
- var _inspectCustom = inspectCustom;
331
- var _devtoolsFormatter = devtoolsFormatter;
332
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
+ );
333
296
  static hash(dxn) {
334
297
  return dxn.toString();
335
298
  }
336
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
+ /**
337
323
  * Exactly equals.
338
324
  */
339
325
  static equals(a, b) {
@@ -372,7 +358,7 @@ var DXN = class _DXN {
372
358
  }
373
359
  }
374
360
  /**
375
- * @example `dxn:type:example.com/type/Contact`
361
+ * @example `dxn:type:com.example.type.person`
376
362
  */
377
363
  static fromTypename(typename) {
378
364
  return new _DXN(_DXN.kind.TYPE, [
@@ -380,7 +366,7 @@ var DXN = class _DXN {
380
366
  ]);
381
367
  }
382
368
  /**
383
- * @example `dxn:type:example.com/type/Contact:0.1.0`
369
+ * @example `dxn:type:com.example.type.person:0.1.0`
384
370
  */
385
371
  // TODO(dmaretskyi): Consider using @ as the version separator.
386
372
  static fromTypenameAndVersion(typename, version) {
@@ -423,8 +409,28 @@ var DXN = class _DXN {
423
409
  ] : []
424
410
  ]);
425
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
+ }
426
432
  toString() {
427
- return `dxn:${_class_private_field_get(this, _kind)}:${_class_private_field_get(this, _parts).join(":")}`;
433
+ return `dxn:${this.#kind}:${this.#parts.join(":")}`;
428
434
  }
429
435
  toJSON() {
430
436
  return this.toString();
@@ -432,13 +438,13 @@ var DXN = class _DXN {
432
438
  /**
433
439
  * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
434
440
  */
435
- [_inspectCustom](depth, options, inspectFn) {
441
+ [inspectCustom](depth, options, inspectFn) {
436
442
  const printControlCode = (code) => {
437
443
  return `\x1B[${code}m`;
438
444
  };
439
445
  return printControlCode(inspectFn.colors.blueBright[0]) + this.toString() + printControlCode(inspectFn.colors.reset[0]);
440
446
  }
441
- get [_devtoolsFormatter]() {
447
+ get [devtoolsFormatter]() {
442
448
  return {
443
449
  header: () => {
444
450
  return [
@@ -452,38 +458,30 @@ var DXN = class _DXN {
452
458
  };
453
459
  }
454
460
  get kind() {
455
- return _class_private_field_get(this, _kind);
461
+ return this.#kind;
456
462
  }
457
463
  get parts() {
458
- return _class_private_field_get(this, _parts);
464
+ return this.#parts;
459
465
  }
460
466
  // TODO(burdon): Should getters fail?
461
467
  get typename() {
462
- invariant2(_class_private_field_get(this, _kind) === _DXN.kind.TYPE, void 0, {
463
- F: __dxlog_file2,
464
- L: 250,
465
- S: this,
466
- A: [
467
- "this.#kind === DXN.kind.TYPE",
468
- ""
469
- ]
470
- });
471
- return _class_private_field_get(this, _parts)[0];
468
+ invariant2(this.#kind === _DXN.kind.TYPE);
469
+ return this.#parts[0];
472
470
  }
473
471
  equals(other) {
474
472
  return _DXN.equals(this, other);
475
473
  }
476
474
  hasTypenameOf(typename) {
477
- return _class_private_field_get(this, _kind) === _DXN.kind.TYPE && _class_private_field_get(this, _parts).length === 1 && _class_private_field_get(this, _parts)[0] === typename;
475
+ return this.#kind === _DXN.kind.TYPE && this.#parts.length === 1 && this.#parts[0] === typename;
478
476
  }
479
477
  isLocalObjectId() {
480
- return _class_private_field_get(this, _kind) === _DXN.kind.ECHO && _class_private_field_get(this, _parts)[0] === LOCAL_SPACE_TAG && _class_private_field_get(this, _parts).length === 2;
478
+ return this.#kind === _DXN.kind.ECHO && this.#parts[0] === LOCAL_SPACE_TAG && this.#parts.length === 2;
481
479
  }
482
480
  asTypeDXN() {
483
481
  if (this.kind !== _DXN.kind.TYPE) {
484
482
  return void 0;
485
483
  }
486
- const [type, version] = _class_private_field_get(this, _parts);
484
+ const [type, version] = this.#parts;
487
485
  return {
488
486
  // TODO(wittjosiah): Should be `typename` for consistency.
489
487
  type,
@@ -494,7 +492,7 @@ var DXN = class _DXN {
494
492
  if (this.kind !== _DXN.kind.ECHO) {
495
493
  return void 0;
496
494
  }
497
- const [spaceId, echoId] = _class_private_field_get(this, _parts);
495
+ const [spaceId, echoId] = this.#parts;
498
496
  return {
499
497
  spaceId: spaceId === LOCAL_SPACE_TAG ? void 0 : spaceId,
500
498
  // TODO(burdon): objectId.
@@ -505,7 +503,7 @@ var DXN = class _DXN {
505
503
  if (this.kind !== _DXN.kind.QUEUE) {
506
504
  return void 0;
507
505
  }
508
- const [subspaceTag, spaceId, queueId, objectId] = _class_private_field_get(this, _parts);
506
+ const [subspaceTag, spaceId, queueId, objectId] = this.#parts;
509
507
  if (typeof queueId !== "string") {
510
508
  return void 0;
511
509
  }
@@ -520,110 +518,26 @@ var DXN = class _DXN {
520
518
  * Produces a new DXN with the given parts appended.
521
519
  */
522
520
  extend(parts) {
523
- return new _DXN(_class_private_field_get(this, _kind), [
524
- ..._class_private_field_get(this, _parts),
521
+ return new _DXN(this.#kind, [
522
+ ...this.#parts,
525
523
  ...parts
526
524
  ]);
527
525
  }
528
- constructor(kind, parts) {
529
- _class_private_field_init(this, _kind, {
530
- writable: true,
531
- value: void 0
532
- });
533
- _class_private_field_init(this, _parts, {
534
- writable: true,
535
- value: void 0
536
- });
537
- assertArgument(parts.length > 0, "parts", `Invalid DXN: ${parts}`);
538
- assertArgument(parts.every((part) => typeof part === "string" && part.length > 0 && part.indexOf(":") === -1), "parts", `Invalid DXN: ${parts}`);
539
- switch (kind) {
540
- case _DXN.kind.TYPE:
541
- if (parts.length > 2) {
542
- throw new Error("Invalid DXN.kind.TYPE");
543
- }
544
- break;
545
- case _DXN.kind.ECHO:
546
- if (parts.length !== 2) {
547
- throw new Error("Invalid DXN.kind.ECHO");
548
- }
549
- break;
550
- }
551
- _class_private_field_set(this, _kind, kind);
552
- _class_private_field_set(this, _parts, parts);
553
- }
554
526
  };
555
- _define_property2(DXN, "Schema", Schema3.NonEmptyString.pipe(
556
- Schema3.pattern(/^dxn:([^:]+):(?:[^:]+:?)+[^:]$/),
557
- // TODO(dmaretskyi): To set the format we need to move the annotation IDs out of the echo-schema package.
558
- // FormatAnnotation.set(FormatEnum.DXN),
559
- Schema3.annotations({
560
- title: "DXN",
561
- description: "DXN URI",
562
- examples: [
563
- "dxn:type:example.com/type/MyType",
564
- "dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6"
565
- ]
566
- })
567
- ));
568
- _define_property2(DXN, "kind", Object.freeze({
569
- /**
570
- * dxn:type:<type_name>[:<version>]
571
- */
572
- TYPE: "type",
573
- /**
574
- * dxn:echo:<space_id>:<echo_id>
575
- * dxn:echo:@:<echo_id>
576
- */
577
- // TODO(burdon): Rename to OBJECT? (BREAKING CHANGE to update "echo").
578
- // TODO(burdon): Add separate Kind for space?
579
- ECHO: "echo",
580
- /**
581
- * The subspace tag enables us to partition queues by usage within the context of a space.
582
- * dxn:queue:<subspace_tag>:<space_id>:<queue_id>[:object_id]
583
- * dxn:queue:data:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
584
- * dxn:queue:trace:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
585
- */
586
- QUEUE: "queue"
587
- }));
588
527
 
589
528
  // src/identity-did.ts
590
529
  init_inject_globals();
591
530
  var import_base32_decode2 = __toESM(require_base32_decode(), 1);
592
531
  import { invariant as invariant3 } from "@dxos/invariant";
593
- var __dxlog_file3 = "/__w/dxos/dxos/packages/common/keys/src/identity-did.ts";
594
532
  var IdentityDid = Object.freeze({
595
533
  byteLength: 20,
596
534
  encode: (value) => {
597
- invariant3(value instanceof Uint8Array, "Invalid type", {
598
- F: __dxlog_file3,
599
- L: 22,
600
- S: void 0,
601
- A: [
602
- "value instanceof Uint8Array",
603
- "'Invalid type'"
604
- ]
605
- });
606
- invariant3(value.length === IdentityDid.byteLength, "Invalid length", {
607
- F: __dxlog_file3,
608
- L: 23,
609
- S: void 0,
610
- A: [
611
- "value.length === IdentityDid.byteLength",
612
- "'Invalid length'"
613
- ]
614
- });
535
+ invariant3(value instanceof Uint8Array, "Invalid type");
536
+ invariant3(value.length === IdentityDid.byteLength, "Invalid length");
615
537
  return DID_PREFIX + MULTIBASE_PREFIX2 + base32Encode(value, "RFC4648");
616
538
  },
617
539
  decode: (value) => {
618
- invariant3(value.startsWith(DID_PREFIX + MULTIBASE_PREFIX2), "Invalid multibase32 encoding", {
619
- F: __dxlog_file3,
620
- L: 28,
621
- S: void 0,
622
- A: [
623
- "value.startsWith(DID_PREFIX + MULTIBASE_PREFIX)",
624
- "'Invalid multibase32 encoding'"
625
- ]
626
- });
540
+ invariant3(value.startsWith(DID_PREFIX + MULTIBASE_PREFIX2), "Invalid multibase32 encoding");
627
541
  return new Uint8Array((0, import_base32_decode2.default)(value.slice(10), "RFC4648"));
628
542
  },
629
543
  isValid: (value) => {
@@ -642,42 +556,19 @@ init_inject_globals();
642
556
  var import_base32_decode3 = __toESM(require_base32_decode(), 1);
643
557
  import { devtoolsFormatter as devtoolsFormatter2, equalsSymbol, inspectCustom as inspectCustom2, truncateKey } from "@dxos/debug";
644
558
  import { invariant as invariant4 } from "@dxos/invariant";
645
- function _define_property3(obj, key, value) {
646
- if (key in obj) {
647
- Object.defineProperty(obj, key, {
648
- value,
649
- enumerable: true,
650
- configurable: true,
651
- writable: true
652
- });
653
- } else {
654
- obj[key] = value;
655
- }
656
- return obj;
657
- }
658
- var __dxlog_file4 = "/__w/dxos/dxos/packages/common/keys/src/public-key.ts";
659
559
  var PUBLIC_KEY_LENGTH = 32;
660
560
  var SECRET_KEY_LENGTH = 64;
661
561
  var isLikeArrayBuffer = (value) => typeof value === "object" && value !== null && Object.getPrototypeOf(value).constructor.name === "ArrayBuffer";
662
- var _inspectCustom2 = inspectCustom2;
663
- var _devtoolsFormatter2 = devtoolsFormatter2;
664
- var _equalsSymbol = equalsSymbol;
665
562
  var PublicKey = class _PublicKey {
563
+ _value;
564
+ static ZERO = _PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH));
666
565
  /**
667
566
  * Creates new instance of PublicKey automatically determining the input format.
668
567
  * @param source A Buffer, or Uint8Array, or hex encoded string, or something with an `asUint8Array` method on it
669
568
  * @returns PublicKey
670
569
  */
671
570
  static from(source) {
672
- invariant4(source, void 0, {
673
- F: __dxlog_file4,
674
- L: 50,
675
- S: this,
676
- A: [
677
- "source",
678
- ""
679
- ]
680
- });
571
+ invariant4(source);
681
572
  if (source instanceof _PublicKey) {
682
573
  return source;
683
574
  } else if (source instanceof Buffer2) {
@@ -761,15 +652,7 @@ var PublicKey = class _PublicKey {
761
652
  * @deprecated All keys should be represented as instances of PublicKey.
762
653
  */
763
654
  static bufferize(str) {
764
- invariant4(typeof str === "string", "Invalid type", {
765
- F: __dxlog_file4,
766
- L: 153,
767
- S: this,
768
- A: [
769
- "typeof str === 'string'",
770
- "'Invalid type'"
771
- ]
772
- });
655
+ invariant4(typeof str === "string", "Invalid type");
773
656
  const buffer = Buffer2.from(str, "hex");
774
657
  return buffer;
775
658
  }
@@ -784,15 +667,7 @@ var PublicKey = class _PublicKey {
784
667
  } else if (key instanceof Uint8Array) {
785
668
  key = Buffer2.from(key.buffer, key.byteOffset, key.byteLength);
786
669
  }
787
- invariant4(key instanceof Buffer2, "Invalid type", {
788
- F: __dxlog_file4,
789
- L: 172,
790
- S: this,
791
- A: [
792
- "key instanceof Buffer",
793
- "'Invalid type'"
794
- ]
795
- });
670
+ invariant4(key instanceof Buffer2, "Invalid type");
796
671
  return key.toString("hex");
797
672
  }
798
673
  /**
@@ -803,17 +678,15 @@ var PublicKey = class _PublicKey {
803
678
  return key.toHex();
804
679
  }
805
680
  static fromMultibase32(encoded) {
806
- invariant4(encoded.startsWith("B"), "Invalid multibase32 encoding", {
807
- F: __dxlog_file4,
808
- L: 185,
809
- S: this,
810
- A: [
811
- "encoded.startsWith('B')",
812
- "'Invalid multibase32 encoding'"
813
- ]
814
- });
681
+ invariant4(encoded.startsWith("B"), "Invalid multibase32 encoding");
815
682
  return new _PublicKey(new Uint8Array((0, import_base32_decode3.default)(encoded.slice(1), "RFC4648")));
816
683
  }
684
+ constructor(_value) {
685
+ this._value = _value;
686
+ if (!(_value instanceof Uint8Array)) {
687
+ throw new TypeError(`Expected Uint8Array, got: ${_value}`);
688
+ }
689
+ }
817
690
  toString() {
818
691
  return this.toHex();
819
692
  }
@@ -832,7 +705,7 @@ var PublicKey = class _PublicKey {
832
705
  toMultibase32() {
833
706
  return "B" + base32Encode(this._value, "RFC4648");
834
707
  }
835
- truncate(length = void 0) {
708
+ truncate(length) {
836
709
  return truncateKey(this, length);
837
710
  }
838
711
  asBuffer() {
@@ -847,7 +720,7 @@ var PublicKey = class _PublicKey {
847
720
  /**
848
721
  * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
849
722
  */
850
- [_inspectCustom2](depth, options, inspectFn) {
723
+ [inspectCustom2](depth, options, inspectFn) {
851
724
  if (!options.colors || typeof process.stdout.hasColors !== "function" || !process.stdout.hasColors()) {
852
725
  return `<PublicKey ${this.truncate()}>`;
853
726
  }
@@ -872,7 +745,7 @@ var PublicKey = class _PublicKey {
872
745
  const color = colors[this.getInsecureHash(colors.length)];
873
746
  return `PublicKey(${printControlCode(inspectFn.colors[color][0])}${this.truncate()}${printControlCode(inspectFn.colors.reset[0])})`;
874
747
  }
875
- get [_devtoolsFormatter2]() {
748
+ get [devtoolsFormatter2]() {
876
749
  return {
877
750
  header: () => {
878
751
  const colors = [
@@ -925,25 +798,17 @@ var PublicKey = class _PublicKey {
925
798
  }
926
799
  let equal = true;
927
800
  for (let i = 0; i < this._value.length; i++) {
928
- equal && (equal = this._value[i] === otherConverted._value[i]);
801
+ equal &&= this._value[i] === otherConverted._value[i];
929
802
  }
930
803
  return equal;
931
804
  }
932
- [_equalsSymbol](other) {
805
+ [equalsSymbol](other) {
933
806
  if (!_PublicKey.isPublicKey(other)) {
934
807
  return false;
935
808
  }
936
809
  return this.equals(other);
937
810
  }
938
- constructor(_value) {
939
- _define_property3(this, "_value", void 0);
940
- this._value = _value;
941
- if (!(_value instanceof Uint8Array)) {
942
- throw new TypeError(`Expected Uint8Array, got: ${_value}`);
943
- }
944
- }
945
811
  };
946
- _define_property3(PublicKey, "ZERO", PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH)));
947
812
  export {
948
813
  DXN,
949
814
  DXN_ECHO_REGEXP,
@@ -954,6 +819,7 @@ export {
954
819
  PublicKey,
955
820
  QueueSubspaceTags,
956
821
  SECRET_KEY_LENGTH,
822
+ SimplePRNG,
957
823
  SpaceId
958
824
  };
959
825
  //# sourceMappingURL=index.mjs.map