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

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.
@@ -82,18 +82,20 @@ var require_base32_decode = __commonJS({
82
82
  });
83
83
 
84
84
  // src/dxn.ts
85
- import { Schema as Schema3 } from "effect";
85
+ import * as Schema3 from "effect/Schema";
86
86
  import { devtoolsFormatter, inspectCustom } from "@dxos/debug";
87
87
  import { assertArgument, invariant as invariant2 } from "@dxos/invariant";
88
88
 
89
89
  // src/object-id.ts
90
- import { Schema } from "effect";
91
- import { ulid } from "ulidx";
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
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);
@@ -103,7 +105,46 @@ var ObjectId = class extends ObjectIdSchema {
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
 
@@ -170,7 +211,7 @@ function base32Encode(data, variant, options) {
170
211
  }
171
212
 
172
213
  // src/space-id.ts
173
- import { Schema as Schema2 } from "effect";
214
+ import * as Schema2 from "effect/Schema";
174
215
  import { invariant } from "@dxos/invariant";
175
216
 
176
217
  // src/random-bytes.ts
@@ -182,133 +223,78 @@ var randomBytes = (length) => {
182
223
  };
183
224
 
184
225
  // src/space-id.ts
185
- function _define_property(obj, key, value) {
186
- if (key in obj) {
187
- Object.defineProperty(obj, key, {
188
- value,
189
- enumerable: true,
190
- configurable: true,
191
- writable: true
192
- });
193
- } else {
194
- obj[key] = value;
195
- }
196
- return obj;
197
- }
198
- var _Schema_String_pipe;
199
- var _class;
200
- var __dxlog_file = "/__w/dxos/dxos/packages/common/keys/src/space-id.ts";
201
226
  var MULTIBASE_PREFIX = "B";
202
227
  var ENCODED_LENGTH = 33;
203
228
  var isValid = (value) => {
204
229
  return typeof value === "string" && value.startsWith(MULTIBASE_PREFIX) && value.length === ENCODED_LENGTH;
205
230
  };
206
- var SpaceId = (_class = class extends (_Schema_String_pipe = Schema2.String.pipe(Schema2.filter(isValid))) {
207
- }, _define_property(_class, "byteLength", 20), _define_property(_class, "encode", (value) => {
208
- invariant(value instanceof Uint8Array, "Invalid type", {
209
- F: __dxlog_file,
210
- L: 43,
211
- S: _class,
212
- A: [
213
- "value instanceof Uint8Array",
214
- "'Invalid type'"
215
- ]
216
- });
217
- invariant(value.length === SpaceId.byteLength, "Invalid length", {
218
- F: __dxlog_file,
219
- L: 44,
220
- S: _class,
221
- A: [
222
- "value.length === SpaceId.byteLength",
223
- "'Invalid length'"
224
- ]
225
- });
226
- return MULTIBASE_PREFIX + base32Encode(value, "RFC4648");
227
- }), _define_property(_class, "decode", (value) => {
228
- invariant(value.startsWith(MULTIBASE_PREFIX), "Invalid multibase32 encoding", {
229
- F: __dxlog_file,
230
- L: 49,
231
- S: _class,
232
- A: [
233
- "value.startsWith(MULTIBASE_PREFIX)",
234
- "'Invalid multibase32 encoding'"
235
- ]
236
- });
237
- return new Uint8Array((0, import_base32_decode.default)(value.slice(1), "RFC4648"));
238
- }), _define_property(_class, "isValid", isValid), _define_property(_class, "random", () => {
239
- return SpaceId.encode(randomBytes(SpaceId.byteLength));
240
- }), _class);
231
+ var SpaceId = class extends Schema2.String.pipe(Schema2.filter(isValid)) {
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
+ };
246
+ };
241
247
 
242
248
  // src/dxn.ts
243
- function _check_private_redeclaration(obj, privateCollection) {
244
- if (privateCollection.has(obj)) {
245
- throw new TypeError("Cannot initialize the same private elements twice on an object");
246
- }
247
- }
248
- function _class_apply_descriptor_get(receiver, descriptor) {
249
- if (descriptor.get) {
250
- return descriptor.get.call(receiver);
251
- }
252
- return descriptor.value;
253
- }
254
- function _class_apply_descriptor_set(receiver, descriptor, value) {
255
- if (descriptor.set) {
256
- descriptor.set.call(receiver, value);
257
- } else {
258
- if (!descriptor.writable) {
259
- throw new TypeError("attempted to set read only private field");
260
- }
261
- descriptor.value = value;
262
- }
263
- }
264
- function _class_extract_field_descriptor(receiver, privateMap, action) {
265
- if (!privateMap.has(receiver)) {
266
- throw new TypeError("attempted to " + action + " private field on non-instance");
267
- }
268
- return privateMap.get(receiver);
269
- }
270
- function _class_private_field_get(receiver, privateMap) {
271
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
272
- return _class_apply_descriptor_get(receiver, descriptor);
273
- }
274
- function _class_private_field_init(obj, privateMap, value) {
275
- _check_private_redeclaration(obj, privateMap);
276
- privateMap.set(obj, value);
277
- }
278
- function _class_private_field_set(receiver, privateMap, value) {
279
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
280
- _class_apply_descriptor_set(receiver, descriptor, value);
281
- return value;
282
- }
283
- function _define_property2(obj, key, value) {
284
- if (key in obj) {
285
- Object.defineProperty(obj, key, {
286
- value,
287
- enumerable: true,
288
- configurable: true,
289
- writable: true
290
- });
291
- } else {
292
- obj[key] = value;
293
- }
294
- return obj;
295
- }
296
- var __dxlog_file2 = "/__w/dxos/dxos/packages/common/keys/src/dxn.ts";
297
249
  var LOCAL_SPACE_TAG = "@";
298
250
  var DXN_ECHO_REGEXP = /@(dxn:[a-zA-Z0-p:@]+)/;
299
251
  var QueueSubspaceTags = Object.freeze({
300
252
  DATA: "data",
301
253
  TRACE: "trace"
302
254
  });
303
- var _kind = /* @__PURE__ */ new WeakMap();
304
- var _parts = /* @__PURE__ */ new WeakMap();
305
- var _inspectCustom = inspectCustom;
306
- var _devtoolsFormatter = devtoolsFormatter;
307
255
  var DXN = class _DXN {
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
+ );
308
271
  static hash(dxn) {
309
272
  return dxn.toString();
310
273
  }
311
274
  /**
275
+ * Kind constants.
276
+ */
277
+ static kind = Object.freeze({
278
+ /**
279
+ * dxn:type:<type_name>[:<version>]
280
+ */
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
+ /**
312
298
  * Exactly equals.
313
299
  */
314
300
  static equals(a, b) {
@@ -347,7 +333,7 @@ var DXN = class _DXN {
347
333
  }
348
334
  }
349
335
  /**
350
- * @example `dxn:type:example.com/type/Contact`
336
+ * @example `dxn:type:com.example.type.person`
351
337
  */
352
338
  static fromTypename(typename) {
353
339
  return new _DXN(_DXN.kind.TYPE, [
@@ -355,7 +341,7 @@ var DXN = class _DXN {
355
341
  ]);
356
342
  }
357
343
  /**
358
- * @example `dxn:type:example.com/type/Contact:0.1.0`
344
+ * @example `dxn:type:com.example.type.person:0.1.0`
359
345
  */
360
346
  // TODO(dmaretskyi): Consider using @ as the version separator.
361
347
  static fromTypenameAndVersion(typename, version) {
@@ -398,8 +384,28 @@ var DXN = class _DXN {
398
384
  ] : []
399
385
  ]);
400
386
  }
387
+ #kind;
388
+ #parts;
389
+ constructor(kind, parts) {
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}`);
392
+ switch (kind) {
393
+ case _DXN.kind.TYPE:
394
+ if (parts.length > 2) {
395
+ throw new Error("Invalid DXN.kind.TYPE");
396
+ }
397
+ break;
398
+ case _DXN.kind.ECHO:
399
+ if (parts.length !== 2) {
400
+ throw new Error("Invalid DXN.kind.ECHO");
401
+ }
402
+ break;
403
+ }
404
+ this.#kind = kind;
405
+ this.#parts = parts;
406
+ }
401
407
  toString() {
402
- return `dxn:${_class_private_field_get(this, _kind)}:${_class_private_field_get(this, _parts).join(":")}`;
408
+ return `dxn:${this.#kind}:${this.#parts.join(":")}`;
403
409
  }
404
410
  toJSON() {
405
411
  return this.toString();
@@ -407,13 +413,13 @@ var DXN = class _DXN {
407
413
  /**
408
414
  * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
409
415
  */
410
- [_inspectCustom](depth, options, inspectFn) {
416
+ [inspectCustom](depth, options, inspectFn) {
411
417
  const printControlCode = (code) => {
412
418
  return `\x1B[${code}m`;
413
419
  };
414
420
  return printControlCode(inspectFn.colors.blueBright[0]) + this.toString() + printControlCode(inspectFn.colors.reset[0]);
415
421
  }
416
- get [_devtoolsFormatter]() {
422
+ get [devtoolsFormatter]() {
417
423
  return {
418
424
  header: () => {
419
425
  return [
@@ -427,38 +433,30 @@ var DXN = class _DXN {
427
433
  };
428
434
  }
429
435
  get kind() {
430
- return _class_private_field_get(this, _kind);
436
+ return this.#kind;
431
437
  }
432
438
  get parts() {
433
- return _class_private_field_get(this, _parts);
439
+ return this.#parts;
434
440
  }
435
441
  // TODO(burdon): Should getters fail?
436
442
  get typename() {
437
- invariant2(_class_private_field_get(this, _kind) === _DXN.kind.TYPE, void 0, {
438
- F: __dxlog_file2,
439
- L: 250,
440
- S: this,
441
- A: [
442
- "this.#kind === DXN.kind.TYPE",
443
- ""
444
- ]
445
- });
446
- return _class_private_field_get(this, _parts)[0];
443
+ invariant2(this.#kind === _DXN.kind.TYPE);
444
+ return this.#parts[0];
447
445
  }
448
446
  equals(other) {
449
447
  return _DXN.equals(this, other);
450
448
  }
451
449
  hasTypenameOf(typename) {
452
- 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;
450
+ return this.#kind === _DXN.kind.TYPE && this.#parts.length === 1 && this.#parts[0] === typename;
453
451
  }
454
452
  isLocalObjectId() {
455
- 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;
453
+ return this.#kind === _DXN.kind.ECHO && this.#parts[0] === LOCAL_SPACE_TAG && this.#parts.length === 2;
456
454
  }
457
455
  asTypeDXN() {
458
456
  if (this.kind !== _DXN.kind.TYPE) {
459
457
  return void 0;
460
458
  }
461
- const [type, version] = _class_private_field_get(this, _parts);
459
+ const [type, version] = this.#parts;
462
460
  return {
463
461
  // TODO(wittjosiah): Should be `typename` for consistency.
464
462
  type,
@@ -469,7 +467,7 @@ var DXN = class _DXN {
469
467
  if (this.kind !== _DXN.kind.ECHO) {
470
468
  return void 0;
471
469
  }
472
- const [spaceId, echoId] = _class_private_field_get(this, _parts);
470
+ const [spaceId, echoId] = this.#parts;
473
471
  return {
474
472
  spaceId: spaceId === LOCAL_SPACE_TAG ? void 0 : spaceId,
475
473
  // TODO(burdon): objectId.
@@ -480,7 +478,7 @@ var DXN = class _DXN {
480
478
  if (this.kind !== _DXN.kind.QUEUE) {
481
479
  return void 0;
482
480
  }
483
- const [subspaceTag, spaceId, queueId, objectId] = _class_private_field_get(this, _parts);
481
+ const [subspaceTag, spaceId, queueId, objectId] = this.#parts;
484
482
  if (typeof queueId !== "string") {
485
483
  return void 0;
486
484
  }
@@ -495,109 +493,25 @@ var DXN = class _DXN {
495
493
  * Produces a new DXN with the given parts appended.
496
494
  */
497
495
  extend(parts) {
498
- return new _DXN(_class_private_field_get(this, _kind), [
499
- ..._class_private_field_get(this, _parts),
496
+ return new _DXN(this.#kind, [
497
+ ...this.#parts,
500
498
  ...parts
501
499
  ]);
502
500
  }
503
- constructor(kind, parts) {
504
- _class_private_field_init(this, _kind, {
505
- writable: true,
506
- value: void 0
507
- });
508
- _class_private_field_init(this, _parts, {
509
- writable: true,
510
- value: void 0
511
- });
512
- assertArgument(parts.length > 0, "parts", `Invalid DXN: ${parts}`);
513
- assertArgument(parts.every((part) => typeof part === "string" && part.length > 0 && part.indexOf(":") === -1), "parts", `Invalid DXN: ${parts}`);
514
- switch (kind) {
515
- case _DXN.kind.TYPE:
516
- if (parts.length > 2) {
517
- throw new Error("Invalid DXN.kind.TYPE");
518
- }
519
- break;
520
- case _DXN.kind.ECHO:
521
- if (parts.length !== 2) {
522
- throw new Error("Invalid DXN.kind.ECHO");
523
- }
524
- break;
525
- }
526
- _class_private_field_set(this, _kind, kind);
527
- _class_private_field_set(this, _parts, parts);
528
- }
529
501
  };
530
- _define_property2(DXN, "Schema", Schema3.NonEmptyString.pipe(
531
- Schema3.pattern(/^dxn:([^:]+):(?:[^:]+:?)+[^:]$/),
532
- // TODO(dmaretskyi): To set the format we need to move the annotation IDs out of the echo-schema package.
533
- // FormatAnnotation.set(FormatEnum.DXN),
534
- Schema3.annotations({
535
- title: "DXN",
536
- description: "DXN URI",
537
- examples: [
538
- "dxn:type:example.com/type/MyType",
539
- "dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6"
540
- ]
541
- })
542
- ));
543
- _define_property2(DXN, "kind", Object.freeze({
544
- /**
545
- * dxn:type:<type_name>[:<version>]
546
- */
547
- TYPE: "type",
548
- /**
549
- * dxn:echo:<space_id>:<echo_id>
550
- * dxn:echo:@:<echo_id>
551
- */
552
- // TODO(burdon): Rename to OBJECT? (BREAKING CHANGE to update "echo").
553
- // TODO(burdon): Add separate Kind for space?
554
- ECHO: "echo",
555
- /**
556
- * The subspace tag enables us to partition queues by usage within the context of a space.
557
- * dxn:queue:<subspace_tag>:<space_id>:<queue_id>[:object_id]
558
- * dxn:queue:data:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
559
- * dxn:queue:trace:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
560
- */
561
- QUEUE: "queue"
562
- }));
563
502
 
564
503
  // src/identity-did.ts
565
504
  var import_base32_decode2 = __toESM(require_base32_decode(), 1);
566
505
  import { invariant as invariant3 } from "@dxos/invariant";
567
- var __dxlog_file3 = "/__w/dxos/dxos/packages/common/keys/src/identity-did.ts";
568
506
  var IdentityDid = Object.freeze({
569
507
  byteLength: 20,
570
508
  encode: (value) => {
571
- invariant3(value instanceof Uint8Array, "Invalid type", {
572
- F: __dxlog_file3,
573
- L: 22,
574
- S: void 0,
575
- A: [
576
- "value instanceof Uint8Array",
577
- "'Invalid type'"
578
- ]
579
- });
580
- invariant3(value.length === IdentityDid.byteLength, "Invalid length", {
581
- F: __dxlog_file3,
582
- L: 23,
583
- S: void 0,
584
- A: [
585
- "value.length === IdentityDid.byteLength",
586
- "'Invalid length'"
587
- ]
588
- });
509
+ invariant3(value instanceof Uint8Array, "Invalid type");
510
+ invariant3(value.length === IdentityDid.byteLength, "Invalid length");
589
511
  return DID_PREFIX + MULTIBASE_PREFIX2 + base32Encode(value, "RFC4648");
590
512
  },
591
513
  decode: (value) => {
592
- invariant3(value.startsWith(DID_PREFIX + MULTIBASE_PREFIX2), "Invalid multibase32 encoding", {
593
- F: __dxlog_file3,
594
- L: 28,
595
- S: void 0,
596
- A: [
597
- "value.startsWith(DID_PREFIX + MULTIBASE_PREFIX)",
598
- "'Invalid multibase32 encoding'"
599
- ]
600
- });
514
+ invariant3(value.startsWith(DID_PREFIX + MULTIBASE_PREFIX2), "Invalid multibase32 encoding");
601
515
  return new Uint8Array((0, import_base32_decode2.default)(value.slice(10), "RFC4648"));
602
516
  },
603
517
  isValid: (value) => {
@@ -615,42 +529,19 @@ var ENCODED_LENGTH2 = 42;
615
529
  var import_base32_decode3 = __toESM(require_base32_decode(), 1);
616
530
  import { devtoolsFormatter as devtoolsFormatter2, equalsSymbol, inspectCustom as inspectCustom2, truncateKey } from "@dxos/debug";
617
531
  import { invariant as invariant4 } from "@dxos/invariant";
618
- function _define_property3(obj, key, value) {
619
- if (key in obj) {
620
- Object.defineProperty(obj, key, {
621
- value,
622
- enumerable: true,
623
- configurable: true,
624
- writable: true
625
- });
626
- } else {
627
- obj[key] = value;
628
- }
629
- return obj;
630
- }
631
- var __dxlog_file4 = "/__w/dxos/dxos/packages/common/keys/src/public-key.ts";
632
532
  var PUBLIC_KEY_LENGTH = 32;
633
533
  var SECRET_KEY_LENGTH = 64;
634
534
  var isLikeArrayBuffer = (value) => typeof value === "object" && value !== null && Object.getPrototypeOf(value).constructor.name === "ArrayBuffer";
635
- var _inspectCustom2 = inspectCustom2;
636
- var _devtoolsFormatter2 = devtoolsFormatter2;
637
- var _equalsSymbol = equalsSymbol;
638
535
  var PublicKey = class _PublicKey {
536
+ _value;
537
+ static ZERO = _PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH));
639
538
  /**
640
539
  * Creates new instance of PublicKey automatically determining the input format.
641
540
  * @param source A Buffer, or Uint8Array, or hex encoded string, or something with an `asUint8Array` method on it
642
541
  * @returns PublicKey
643
542
  */
644
543
  static from(source) {
645
- invariant4(source, void 0, {
646
- F: __dxlog_file4,
647
- L: 50,
648
- S: this,
649
- A: [
650
- "source",
651
- ""
652
- ]
653
- });
544
+ invariant4(source);
654
545
  if (source instanceof _PublicKey) {
655
546
  return source;
656
547
  } else if (source instanceof Buffer) {
@@ -734,15 +625,7 @@ var PublicKey = class _PublicKey {
734
625
  * @deprecated All keys should be represented as instances of PublicKey.
735
626
  */
736
627
  static bufferize(str) {
737
- invariant4(typeof str === "string", "Invalid type", {
738
- F: __dxlog_file4,
739
- L: 153,
740
- S: this,
741
- A: [
742
- "typeof str === 'string'",
743
- "'Invalid type'"
744
- ]
745
- });
628
+ invariant4(typeof str === "string", "Invalid type");
746
629
  const buffer = Buffer.from(str, "hex");
747
630
  return buffer;
748
631
  }
@@ -757,15 +640,7 @@ var PublicKey = class _PublicKey {
757
640
  } else if (key instanceof Uint8Array) {
758
641
  key = Buffer.from(key.buffer, key.byteOffset, key.byteLength);
759
642
  }
760
- invariant4(key instanceof Buffer, "Invalid type", {
761
- F: __dxlog_file4,
762
- L: 172,
763
- S: this,
764
- A: [
765
- "key instanceof Buffer",
766
- "'Invalid type'"
767
- ]
768
- });
643
+ invariant4(key instanceof Buffer, "Invalid type");
769
644
  return key.toString("hex");
770
645
  }
771
646
  /**
@@ -776,17 +651,15 @@ var PublicKey = class _PublicKey {
776
651
  return key.toHex();
777
652
  }
778
653
  static fromMultibase32(encoded) {
779
- invariant4(encoded.startsWith("B"), "Invalid multibase32 encoding", {
780
- F: __dxlog_file4,
781
- L: 185,
782
- S: this,
783
- A: [
784
- "encoded.startsWith('B')",
785
- "'Invalid multibase32 encoding'"
786
- ]
787
- });
654
+ invariant4(encoded.startsWith("B"), "Invalid multibase32 encoding");
788
655
  return new _PublicKey(new Uint8Array((0, import_base32_decode3.default)(encoded.slice(1), "RFC4648")));
789
656
  }
657
+ constructor(_value) {
658
+ this._value = _value;
659
+ if (!(_value instanceof Uint8Array)) {
660
+ throw new TypeError(`Expected Uint8Array, got: ${_value}`);
661
+ }
662
+ }
790
663
  toString() {
791
664
  return this.toHex();
792
665
  }
@@ -805,7 +678,7 @@ var PublicKey = class _PublicKey {
805
678
  toMultibase32() {
806
679
  return "B" + base32Encode(this._value, "RFC4648");
807
680
  }
808
- truncate(length = void 0) {
681
+ truncate(length) {
809
682
  return truncateKey(this, length);
810
683
  }
811
684
  asBuffer() {
@@ -820,7 +693,7 @@ var PublicKey = class _PublicKey {
820
693
  /**
821
694
  * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
822
695
  */
823
- [_inspectCustom2](depth, options, inspectFn) {
696
+ [inspectCustom2](depth, options, inspectFn) {
824
697
  if (!options.colors || typeof process.stdout.hasColors !== "function" || !process.stdout.hasColors()) {
825
698
  return `<PublicKey ${this.truncate()}>`;
826
699
  }
@@ -845,7 +718,7 @@ var PublicKey = class _PublicKey {
845
718
  const color = colors[this.getInsecureHash(colors.length)];
846
719
  return `PublicKey(${printControlCode(inspectFn.colors[color][0])}${this.truncate()}${printControlCode(inspectFn.colors.reset[0])})`;
847
720
  }
848
- get [_devtoolsFormatter2]() {
721
+ get [devtoolsFormatter2]() {
849
722
  return {
850
723
  header: () => {
851
724
  const colors = [
@@ -898,25 +771,17 @@ var PublicKey = class _PublicKey {
898
771
  }
899
772
  let equal = true;
900
773
  for (let i = 0; i < this._value.length; i++) {
901
- equal && (equal = this._value[i] === otherConverted._value[i]);
774
+ equal &&= this._value[i] === otherConverted._value[i];
902
775
  }
903
776
  return equal;
904
777
  }
905
- [_equalsSymbol](other) {
778
+ [equalsSymbol](other) {
906
779
  if (!_PublicKey.isPublicKey(other)) {
907
780
  return false;
908
781
  }
909
782
  return this.equals(other);
910
783
  }
911
- constructor(_value) {
912
- _define_property3(this, "_value", void 0);
913
- this._value = _value;
914
- if (!(_value instanceof Uint8Array)) {
915
- throw new TypeError(`Expected Uint8Array, got: ${_value}`);
916
- }
917
- }
918
784
  };
919
- _define_property3(PublicKey, "ZERO", PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH)));
920
785
  export {
921
786
  DXN,
922
787
  DXN_ECHO_REGEXP,
@@ -927,6 +792,7 @@ export {
927
792
  PublicKey,
928
793
  QueueSubspaceTags,
929
794
  SECRET_KEY_LENGTH,
795
+ SimplePRNG,
930
796
  SpaceId
931
797
  };
932
798
  //# sourceMappingURL=index.mjs.map