@dxos/keys 0.8.4-main.72ec0f3 → 0.8.4-main.765dc60934

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.
@@ -248,7 +248,6 @@ var randomBytes = (length) => {
248
248
  };
249
249
 
250
250
  // src/space-id.ts
251
- var __dxlog_file = "/__w/dxos/dxos/packages/common/keys/src/space-id.ts";
252
251
  var MULTIBASE_PREFIX = "B";
253
252
  var ENCODED_LENGTH = 33;
254
253
  var isValid = (value) => {
@@ -257,36 +256,12 @@ var isValid = (value) => {
257
256
  var SpaceId = class extends Schema2.String.pipe(Schema2.filter(isValid)) {
258
257
  static byteLength = 20;
259
258
  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
- });
259
+ invariant(value instanceof Uint8Array, "Invalid type");
260
+ invariant(value.length === SpaceId.byteLength, "Invalid length");
278
261
  return MULTIBASE_PREFIX + base32Encode(value, "RFC4648");
279
262
  };
280
263
  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
- });
264
+ invariant(value.startsWith(MULTIBASE_PREFIX), "Invalid multibase32 encoding");
290
265
  return new Uint8Array((0, import_base32_decode.default)(value.slice(1), "RFC4648"));
291
266
  };
292
267
  static isValid = isValid;
@@ -296,7 +271,6 @@ var SpaceId = class extends Schema2.String.pipe(Schema2.filter(isValid)) {
296
271
  };
297
272
 
298
273
  // src/dxn.ts
299
- var __dxlog_file2 = "/__w/dxos/dxos/packages/common/keys/src/dxn.ts";
300
274
  var LOCAL_SPACE_TAG = "@";
301
275
  var DXN_ECHO_REGEXP = /@(dxn:[a-zA-Z0-p:@]+)/;
302
276
  var QueueSubspaceTags = Object.freeze({
@@ -309,12 +283,12 @@ var DXN = class _DXN {
309
283
  static Schema = Schema3.NonEmptyString.pipe(
310
284
  Schema3.pattern(/^dxn:([^:]+):(?:[^:]+:?)+[^:]$/),
311
285
  // TODO(dmaretskyi): To set the format we need to move the annotation IDs out of the echo-schema package.
312
- // FormatAnnotation.set(FormatEnum.DXN),
286
+ // FormatAnnotation.set(TypeFormat.DXN),
313
287
  Schema3.annotations({
314
288
  title: "DXN",
315
289
  description: "DXN URI",
316
290
  examples: [
317
- "dxn:type:example.com/type/MyType",
291
+ "dxn:type:com.example.type.my-type",
318
292
  "dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6"
319
293
  ]
320
294
  })
@@ -384,7 +358,7 @@ var DXN = class _DXN {
384
358
  }
385
359
  }
386
360
  /**
387
- * @example `dxn:type:example.com/type/Person`
361
+ * @example `dxn:type:com.example.type.person`
388
362
  */
389
363
  static fromTypename(typename) {
390
364
  return new _DXN(_DXN.kind.TYPE, [
@@ -392,7 +366,7 @@ var DXN = class _DXN {
392
366
  ]);
393
367
  }
394
368
  /**
395
- * @example `dxn:type:example.com/type/Person:0.1.0`
369
+ * @example `dxn:type:com.example.type.person:0.1.0`
396
370
  */
397
371
  // TODO(dmaretskyi): Consider using @ as the version separator.
398
372
  static fromTypenameAndVersion(typename, version) {
@@ -491,15 +465,7 @@ var DXN = class _DXN {
491
465
  }
492
466
  // TODO(burdon): Should getters fail?
493
467
  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
- });
468
+ invariant2(this.#kind === _DXN.kind.TYPE);
503
469
  return this.#parts[0];
504
470
  }
505
471
  equals(other) {
@@ -563,40 +529,15 @@ var DXN = class _DXN {
563
529
  init_inject_globals();
564
530
  var import_base32_decode2 = __toESM(require_base32_decode(), 1);
565
531
  import { invariant as invariant3 } from "@dxos/invariant";
566
- var __dxlog_file3 = "/__w/dxos/dxos/packages/common/keys/src/identity-did.ts";
567
532
  var IdentityDid = Object.freeze({
568
533
  byteLength: 20,
569
534
  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
- });
535
+ invariant3(value instanceof Uint8Array, "Invalid type");
536
+ invariant3(value.length === IdentityDid.byteLength, "Invalid length");
588
537
  return DID_PREFIX + MULTIBASE_PREFIX2 + base32Encode(value, "RFC4648");
589
538
  },
590
539
  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
- });
540
+ invariant3(value.startsWith(DID_PREFIX + MULTIBASE_PREFIX2), "Invalid multibase32 encoding");
600
541
  return new Uint8Array((0, import_base32_decode2.default)(value.slice(10), "RFC4648"));
601
542
  },
602
543
  isValid: (value) => {
@@ -610,12 +551,38 @@ var MULTIBASE_PREFIX2 = "B";
610
551
  var DID_PREFIX = "did:halo:";
611
552
  var ENCODED_LENGTH2 = 42;
612
553
 
554
+ // src/parse-id.ts
555
+ init_inject_globals();
556
+ var SPACE_ID_LENGTH = 33;
557
+ var OBJECT_ID_LENGTH = 26;
558
+ var FQ_ID_LENGTH = SPACE_ID_LENGTH + OBJECT_ID_LENGTH + 1;
559
+ var parseId = (id) => {
560
+ if (!id) {
561
+ return {};
562
+ } else if (id.length === SPACE_ID_LENGTH) {
563
+ return {
564
+ spaceId: id
565
+ };
566
+ } else if (id.length === OBJECT_ID_LENGTH) {
567
+ return {
568
+ objectId: id
569
+ };
570
+ } else if (id.length === FQ_ID_LENGTH && id.indexOf(":") === SPACE_ID_LENGTH) {
571
+ const [spaceId, objectId] = id.split(":");
572
+ return {
573
+ spaceId,
574
+ objectId
575
+ };
576
+ } else {
577
+ return {};
578
+ }
579
+ };
580
+
613
581
  // src/public-key.ts
614
582
  init_inject_globals();
615
583
  var import_base32_decode3 = __toESM(require_base32_decode(), 1);
616
584
  import { devtoolsFormatter as devtoolsFormatter2, equalsSymbol, inspectCustom as inspectCustom2, truncateKey } from "@dxos/debug";
617
585
  import { invariant as invariant4 } from "@dxos/invariant";
618
- var __dxlog_file4 = "/__w/dxos/dxos/packages/common/keys/src/public-key.ts";
619
586
  var PUBLIC_KEY_LENGTH = 32;
620
587
  var SECRET_KEY_LENGTH = 64;
621
588
  var isLikeArrayBuffer = (value) => typeof value === "object" && value !== null && Object.getPrototypeOf(value).constructor.name === "ArrayBuffer";
@@ -628,15 +595,7 @@ var PublicKey = class _PublicKey {
628
595
  * @returns PublicKey
629
596
  */
630
597
  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
- });
598
+ invariant4(source);
640
599
  if (source instanceof _PublicKey) {
641
600
  return source;
642
601
  } else if (source instanceof Buffer2) {
@@ -720,15 +679,7 @@ var PublicKey = class _PublicKey {
720
679
  * @deprecated All keys should be represented as instances of PublicKey.
721
680
  */
722
681
  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
- });
682
+ invariant4(typeof str === "string", "Invalid type");
732
683
  const buffer = Buffer2.from(str, "hex");
733
684
  return buffer;
734
685
  }
@@ -743,15 +694,7 @@ var PublicKey = class _PublicKey {
743
694
  } else if (key instanceof Uint8Array) {
744
695
  key = Buffer2.from(key.buffer, key.byteOffset, key.byteLength);
745
696
  }
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
- });
697
+ invariant4(key instanceof Buffer2, "Invalid type");
755
698
  return key.toString("hex");
756
699
  }
757
700
  /**
@@ -762,15 +705,7 @@ var PublicKey = class _PublicKey {
762
705
  return key.toHex();
763
706
  }
764
707
  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
- });
708
+ invariant4(encoded.startsWith("B"), "Invalid multibase32 encoding");
774
709
  return new _PublicKey(new Uint8Array((0, import_base32_decode3.default)(encoded.slice(1), "RFC4648")));
775
710
  }
776
711
  constructor(_value) {
@@ -797,7 +732,7 @@ var PublicKey = class _PublicKey {
797
732
  toMultibase32() {
798
733
  return "B" + base32Encode(this._value, "RFC4648");
799
734
  }
800
- truncate(length = void 0) {
735
+ truncate(length) {
801
736
  return truncateKey(this, length);
802
737
  }
803
738
  asBuffer() {
@@ -904,14 +839,18 @@ var PublicKey = class _PublicKey {
904
839
  export {
905
840
  DXN,
906
841
  DXN_ECHO_REGEXP,
842
+ FQ_ID_LENGTH,
907
843
  IdentityDid,
908
844
  LOCAL_SPACE_TAG,
845
+ OBJECT_ID_LENGTH,
909
846
  ObjectId,
910
847
  PUBLIC_KEY_LENGTH,
911
848
  PublicKey,
912
849
  QueueSubspaceTags,
913
850
  SECRET_KEY_LENGTH,
851
+ SPACE_ID_LENGTH,
914
852
  SimplePRNG,
915
- SpaceId
853
+ SpaceId,
854
+ parseId
916
855
  };
917
856
  //# sourceMappingURL=index.mjs.map