@dxos/keys 0.8.4-main.ef1bc66f44 → 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.
package/LICENSE CHANGED
@@ -1,8 +1,105 @@
1
- MIT License
2
- Copyright (c) 2022 DXOS
1
+ # Functional Source License, Version 1.1, ALv2 Future License
3
2
 
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+ ## Abbreviation
5
4
 
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+ FSL-1.1-Apache-2.0
7
6
 
8
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7
+ ## Notice
8
+
9
+ Copyright 2026 DXOS
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
@@ -130,9 +130,13 @@ var ObjectId = class extends ObjectIdSchema {
130
130
  this.#factory = monotonicFactory(makeTestPRNG());
131
131
  this.#seedTime = (/* @__PURE__ */ new Date("2025-01-01")).getTime();
132
132
  }
133
+ static dangerouslySetSeed(time, seed) {
134
+ this.#factory = monotonicFactory(makeTestPRNG(seed));
135
+ this.#seedTime = time;
136
+ }
133
137
  };
134
- var makeTestPRNG = () => {
135
- const rng = new SimplePRNG();
138
+ var makeTestPRNG = (seed = 0) => {
139
+ const rng = new SimplePRNG(seed);
136
140
  return () => {
137
141
  return rng.next();
138
142
  };
@@ -248,7 +252,6 @@ var randomBytes = (length) => {
248
252
  };
249
253
 
250
254
  // src/space-id.ts
251
- var __dxlog_file = "/__w/dxos/dxos/packages/common/keys/src/space-id.ts";
252
255
  var MULTIBASE_PREFIX = "B";
253
256
  var ENCODED_LENGTH = 33;
254
257
  var isValid = (value) => {
@@ -257,36 +260,12 @@ var isValid = (value) => {
257
260
  var SpaceId = class extends Schema2.String.pipe(Schema2.filter(isValid)) {
258
261
  static byteLength = 20;
259
262
  static encode = (value) => {
260
- invariant(value instanceof Uint8Array, "Invalid type", {
261
- F: __dxlog_file,
262
- L: 43,
263
- S: this,
264
- A: [
265
- "value instanceof Uint8Array",
266
- "'Invalid type'"
267
- ]
268
- });
269
- invariant(value.length === SpaceId.byteLength, "Invalid length", {
270
- F: __dxlog_file,
271
- L: 44,
272
- S: this,
273
- A: [
274
- "value.length === SpaceId.byteLength",
275
- "'Invalid length'"
276
- ]
277
- });
263
+ invariant(value instanceof Uint8Array, "Invalid type");
264
+ invariant(value.length === SpaceId.byteLength, "Invalid length");
278
265
  return MULTIBASE_PREFIX + base32Encode(value, "RFC4648");
279
266
  };
280
267
  static decode = (value) => {
281
- invariant(value.startsWith(MULTIBASE_PREFIX), "Invalid multibase32 encoding", {
282
- F: __dxlog_file,
283
- L: 49,
284
- S: this,
285
- A: [
286
- "value.startsWith(MULTIBASE_PREFIX)",
287
- "'Invalid multibase32 encoding'"
288
- ]
289
- });
268
+ invariant(value.startsWith(MULTIBASE_PREFIX), "Invalid multibase32 encoding");
290
269
  return new Uint8Array((0, import_base32_decode.default)(value.slice(1), "RFC4648"));
291
270
  };
292
271
  static isValid = isValid;
@@ -296,7 +275,6 @@ var SpaceId = class extends Schema2.String.pipe(Schema2.filter(isValid)) {
296
275
  };
297
276
 
298
277
  // src/dxn.ts
299
- var __dxlog_file2 = "/__w/dxos/dxos/packages/common/keys/src/dxn.ts";
300
278
  var LOCAL_SPACE_TAG = "@";
301
279
  var DXN_ECHO_REGEXP = /@(dxn:[a-zA-Z0-p:@]+)/;
302
280
  var QueueSubspaceTags = Object.freeze({
@@ -314,7 +292,7 @@ var DXN = class _DXN {
314
292
  title: "DXN",
315
293
  description: "DXN URI",
316
294
  examples: [
317
- "dxn:type:example.com/type/MyType",
295
+ "dxn:type:com.example.type.my-type",
318
296
  "dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6"
319
297
  ]
320
298
  })
@@ -384,7 +362,7 @@ var DXN = class _DXN {
384
362
  }
385
363
  }
386
364
  /**
387
- * @example `dxn:type:example.com/type/Person`
365
+ * @example `dxn:type:com.example.type.person`
388
366
  */
389
367
  static fromTypename(typename) {
390
368
  return new _DXN(_DXN.kind.TYPE, [
@@ -392,7 +370,7 @@ var DXN = class _DXN {
392
370
  ]);
393
371
  }
394
372
  /**
395
- * @example `dxn:type:example.com/type/Person:0.1.0`
373
+ * @example `dxn:type:com.example.type.person:0.1.0`
396
374
  */
397
375
  // TODO(dmaretskyi): Consider using @ as the version separator.
398
376
  static fromTypenameAndVersion(typename, version) {
@@ -491,15 +469,7 @@ var DXN = class _DXN {
491
469
  }
492
470
  // TODO(burdon): Should getters fail?
493
471
  get typename() {
494
- invariant2(this.#kind === _DXN.kind.TYPE, void 0, {
495
- F: __dxlog_file2,
496
- L: 250,
497
- S: this,
498
- A: [
499
- "this.#kind === DXN.kind.TYPE",
500
- ""
501
- ]
502
- });
472
+ invariant2(this.#kind === _DXN.kind.TYPE);
503
473
  return this.#parts[0];
504
474
  }
505
475
  equals(other) {
@@ -563,40 +533,15 @@ var DXN = class _DXN {
563
533
  init_inject_globals();
564
534
  var import_base32_decode2 = __toESM(require_base32_decode(), 1);
565
535
  import { invariant as invariant3 } from "@dxos/invariant";
566
- var __dxlog_file3 = "/__w/dxos/dxos/packages/common/keys/src/identity-did.ts";
567
536
  var IdentityDid = Object.freeze({
568
537
  byteLength: 20,
569
538
  encode: (value) => {
570
- invariant3(value instanceof Uint8Array, "Invalid type", {
571
- F: __dxlog_file3,
572
- L: 22,
573
- S: void 0,
574
- A: [
575
- "value instanceof Uint8Array",
576
- "'Invalid type'"
577
- ]
578
- });
579
- invariant3(value.length === IdentityDid.byteLength, "Invalid length", {
580
- F: __dxlog_file3,
581
- L: 23,
582
- S: void 0,
583
- A: [
584
- "value.length === IdentityDid.byteLength",
585
- "'Invalid length'"
586
- ]
587
- });
539
+ invariant3(value instanceof Uint8Array, "Invalid type");
540
+ invariant3(value.length === IdentityDid.byteLength, "Invalid length");
588
541
  return DID_PREFIX + MULTIBASE_PREFIX2 + base32Encode(value, "RFC4648");
589
542
  },
590
543
  decode: (value) => {
591
- invariant3(value.startsWith(DID_PREFIX + MULTIBASE_PREFIX2), "Invalid multibase32 encoding", {
592
- F: __dxlog_file3,
593
- L: 28,
594
- S: void 0,
595
- A: [
596
- "value.startsWith(DID_PREFIX + MULTIBASE_PREFIX)",
597
- "'Invalid multibase32 encoding'"
598
- ]
599
- });
544
+ invariant3(value.startsWith(DID_PREFIX + MULTIBASE_PREFIX2), "Invalid multibase32 encoding");
600
545
  return new Uint8Array((0, import_base32_decode2.default)(value.slice(10), "RFC4648"));
601
546
  },
602
547
  isValid: (value) => {
@@ -610,12 +555,38 @@ var MULTIBASE_PREFIX2 = "B";
610
555
  var DID_PREFIX = "did:halo:";
611
556
  var ENCODED_LENGTH2 = 42;
612
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
+
613
585
  // src/public-key.ts
614
586
  init_inject_globals();
615
587
  var import_base32_decode3 = __toESM(require_base32_decode(), 1);
616
588
  import { devtoolsFormatter as devtoolsFormatter2, equalsSymbol, inspectCustom as inspectCustom2, truncateKey } from "@dxos/debug";
617
589
  import { invariant as invariant4 } from "@dxos/invariant";
618
- var __dxlog_file4 = "/__w/dxos/dxos/packages/common/keys/src/public-key.ts";
619
590
  var PUBLIC_KEY_LENGTH = 32;
620
591
  var SECRET_KEY_LENGTH = 64;
621
592
  var isLikeArrayBuffer = (value) => typeof value === "object" && value !== null && Object.getPrototypeOf(value).constructor.name === "ArrayBuffer";
@@ -628,15 +599,7 @@ var PublicKey = class _PublicKey {
628
599
  * @returns PublicKey
629
600
  */
630
601
  static from(source) {
631
- invariant4(source, void 0, {
632
- F: __dxlog_file4,
633
- L: 50,
634
- S: this,
635
- A: [
636
- "source",
637
- ""
638
- ]
639
- });
602
+ invariant4(source);
640
603
  if (source instanceof _PublicKey) {
641
604
  return source;
642
605
  } else if (source instanceof Buffer2) {
@@ -720,15 +683,7 @@ var PublicKey = class _PublicKey {
720
683
  * @deprecated All keys should be represented as instances of PublicKey.
721
684
  */
722
685
  static bufferize(str) {
723
- invariant4(typeof str === "string", "Invalid type", {
724
- F: __dxlog_file4,
725
- L: 153,
726
- S: this,
727
- A: [
728
- "typeof str === 'string'",
729
- "'Invalid type'"
730
- ]
731
- });
686
+ invariant4(typeof str === "string", "Invalid type");
732
687
  const buffer = Buffer2.from(str, "hex");
733
688
  return buffer;
734
689
  }
@@ -743,15 +698,7 @@ var PublicKey = class _PublicKey {
743
698
  } else if (key instanceof Uint8Array) {
744
699
  key = Buffer2.from(key.buffer, key.byteOffset, key.byteLength);
745
700
  }
746
- invariant4(key instanceof Buffer2, "Invalid type", {
747
- F: __dxlog_file4,
748
- L: 172,
749
- S: this,
750
- A: [
751
- "key instanceof Buffer",
752
- "'Invalid type'"
753
- ]
754
- });
701
+ invariant4(key instanceof Buffer2, "Invalid type");
755
702
  return key.toString("hex");
756
703
  }
757
704
  /**
@@ -762,15 +709,7 @@ var PublicKey = class _PublicKey {
762
709
  return key.toHex();
763
710
  }
764
711
  static fromMultibase32(encoded) {
765
- invariant4(encoded.startsWith("B"), "Invalid multibase32 encoding", {
766
- F: __dxlog_file4,
767
- L: 185,
768
- S: this,
769
- A: [
770
- "encoded.startsWith('B')",
771
- "'Invalid multibase32 encoding'"
772
- ]
773
- });
712
+ invariant4(encoded.startsWith("B"), "Invalid multibase32 encoding");
774
713
  return new _PublicKey(new Uint8Array((0, import_base32_decode3.default)(encoded.slice(1), "RFC4648")));
775
714
  }
776
715
  constructor(_value) {
@@ -797,7 +736,7 @@ var PublicKey = class _PublicKey {
797
736
  toMultibase32() {
798
737
  return "B" + base32Encode(this._value, "RFC4648");
799
738
  }
800
- truncate(length = void 0) {
739
+ truncate(length) {
801
740
  return truncateKey(this, length);
802
741
  }
803
742
  asBuffer() {
@@ -904,14 +843,18 @@ var PublicKey = class _PublicKey {
904
843
  export {
905
844
  DXN,
906
845
  DXN_ECHO_REGEXP,
846
+ FQ_ID_LENGTH,
907
847
  IdentityDid,
908
848
  LOCAL_SPACE_TAG,
849
+ OBJECT_ID_LENGTH,
909
850
  ObjectId,
910
851
  PUBLIC_KEY_LENGTH,
911
852
  PublicKey,
912
853
  QueueSubspaceTags,
913
854
  SECRET_KEY_LENGTH,
855
+ SPACE_ID_LENGTH,
914
856
  SimplePRNG,
915
- SpaceId
857
+ SpaceId,
858
+ parseId
916
859
  };
917
860
  //# sourceMappingURL=index.mjs.map