@dxos/keys 0.8.4-main.8360d9e660 → 0.8.4-main.8baae0fced
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 +102 -5
- package/dist/lib/browser/index.mjs +50 -107
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +49 -107
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/dxn.d.ts +1 -1
- package/dist/types/src/dxn.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/object-id.d.ts +17 -0
- package/dist/types/src/object-id.d.ts.map +1 -1
- package/dist/types/src/parse-id.d.ts +10 -0
- package/dist/types/src/parse-id.d.ts.map +1 -0
- package/dist/types/src/parse-id.test.d.ts +2 -0
- package/dist/types/src/parse-id.test.d.ts.map +1 -0
- package/dist/types/src/prng.d.ts.map +1 -1
- package/dist/types/src/public-key.d.ts +1 -1
- package/dist/types/src/public-key.d.ts.map +1 -1
- package/dist/types/src/random-bytes.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -10
- package/src/dxn.ts +1 -2
- package/src/index.ts +1 -0
- package/src/object-id.ts +25 -2
- package/src/parse-id.test.ts +32 -0
- package/src/parse-id.ts +32 -0
- package/src/public-key.ts +2 -3
package/LICENSE
CHANGED
|
@@ -1,8 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
Copyright (c) 2022 DXOS
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
## Abbreviation
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
7
6
|
|
|
8
|
-
|
|
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
|
-
|
|
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({
|
|
@@ -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
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["inject-globals:@inject-globals", "../../../../../../node_modules/.pnpm/base32-decode@1.0.0/node_modules/base32-decode/index.js", "../../../src/index.ts", "../../../src/dxn.ts", "../../../src/object-id.ts", "../../../src/space-id.ts", "../../../../../../node_modules/.pnpm/base32-encode@2.0.0/node_modules/base32-encode/index.js", "../../../../../../node_modules/.pnpm/to-data-view@2.0.0/node_modules/to-data-view/index.js", "../../../src/random-bytes.ts", "../../../src/identity-did.ts", "../../../src/public-key.ts"],
|
|
4
|
-
"sourcesContent": ["\n export {\n global,\nBuffer,\nprocess\n } from '@dxos/node-std/inject-globals';\n // Empty source map so that esbuild does not inject virtual source file names.\n //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==\n ", "var RFC4648 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'\nvar RFC4648_HEX = '0123456789ABCDEFGHIJKLMNOPQRSTUV'\nvar CROCKFORD = '0123456789ABCDEFGHJKMNPQRSTVWXYZ'\n\nfunction readChar (alphabet, char) {\n var idx = alphabet.indexOf(char)\n\n if (idx === -1) {\n throw new Error('Invalid character found: ' + char)\n }\n\n return idx\n}\n\nmodule.exports = function base32Decode (input, variant) {\n var alphabet\n\n switch (variant) {\n case 'RFC3548':\n case 'RFC4648':\n alphabet = RFC4648\n input = input.replace(/=+$/, '')\n break\n case 'RFC4648-HEX':\n alphabet = RFC4648_HEX\n input = input.replace(/=+$/, '')\n break\n case 'Crockford':\n alphabet = CROCKFORD\n input = input.toUpperCase().replace(/O/g, '0').replace(/[IL]/g, '1')\n break\n default:\n throw new Error('Unknown base32 variant: ' + variant)\n }\n\n var length = input.length\n\n var bits = 0\n var value = 0\n\n var index = 0\n var output = new Uint8Array((length * 5 / 8) | 0)\n\n for (var i = 0; i < length; i++) {\n value = (value << 5) | readChar(alphabet, input[i])\n bits += 5\n\n if (bits >= 8) {\n output[index++] = (value >>> (bits - 8)) & 255\n bits -= 8\n }\n }\n\n return output.buffer\n}\n", "//\n// Copyright 2020 DXOS.org\n//\n\nexport * from './dxn';\nexport * from './identity-did';\nexport * from './object-id';\nexport * from './public-key';\nexport * from './space-id';\nexport type * from './types';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { InspectOptionsStylized, inspect } from 'node:util';\n\nimport * as Schema from 'effect/Schema';\n\nimport { type DevtoolsFormatter, devtoolsFormatter, inspectCustom } from '@dxos/debug';\nimport { assertArgument, invariant } from '@dxos/invariant';\n\nimport { ObjectId } from './object-id';\nimport { SpaceId } from './space-id';\n\n/**\n * Tags for ECHO DXNs that should resolve the object ID in the local space.\n */\n// TODO(dmaretskyi): Rebrand this as \"unknown location\" to specify objects in the same space or queue. Essentially making the DXN it a URI not URL\n// TODO(dmaretskyi): \"@\" is a separator character in the URI spec.\nexport const LOCAL_SPACE_TAG = '@';\n\nexport const DXN_ECHO_REGEXP = /@(dxn:[a-zA-Z0-p:@]+)/;\n\n// TODO(burdon): Namespace for.\nexport const QueueSubspaceTags = Object.freeze({\n DATA: 'data',\n TRACE: 'trace',\n});\n\nexport type QueueSubspaceTag = (typeof QueueSubspaceTags)[keyof typeof QueueSubspaceTags];\n\n// TODO(burdon): Refactor.\n// Consider: https://github.com/multiformats/multiaddr\n// dxn:echo:[<space-id>:[<queue-id>:]]<object-id>\n// dxn:echo:[S/<space-id>:[Q/<queue-id>:]]<object-id>\n// dxn:type:org.dxos.markdown.contact\n\n/**\n * DXN unambiguously names a resource like an ECHO object, schema definition, plugin, etc.\n * Each DXN starts with a dxn prefix, followed by a resource kind.\n * Colon Symbol : is used a delimiter between parts.\n * DXNs may contain slashes.\n * '@' in the place of the space id is used to denote that the DXN should be resolved in the local space.\n *\n * @example\n * ```\n * dxn:echo:<space key>:<echo id>\n * dxn:echo:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6\n * dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6\n * dxn:type:org.dxos.type.calendar\n * dxn:plugin:org.dxos.agent.plugin.functions\n * ```\n */\nexport class DXN {\n // TODO(burdon): Rename to DXN (i.e., DXN.DXN).\n // TODO(dmaretskyi): Should this be a transformation into the DXN type?\n static Schema = Schema.NonEmptyString.pipe(\n Schema.pattern(/^dxn:([^:]+):(?:[^:]+:?)+[^:]$/),\n // TODO(dmaretskyi): To set the format we need to move the annotation IDs out of the echo-schema package.\n // FormatAnnotation.set(TypeFormat.DXN),\n Schema.annotations({\n title: 'DXN',\n description: 'DXN URI',\n examples: ['dxn:type:com.example.type.my-type', 'dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6'],\n }),\n );\n\n static hash(dxn: DXN): string {\n return dxn.toString();\n }\n\n /**\n * Kind constants.\n */\n static kind = Object.freeze({\n /**\n * dxn:type:<type_name>[:<version>]\n */\n TYPE: 'type',\n\n /**\n * dxn:echo:<space_id>:<echo_id>\n * dxn:echo:@:<echo_id>\n */\n // TODO(burdon): Rename to OBJECT? (BREAKING CHANGE to update \"echo\").\n // TODO(burdon): Add separate Kind for space?\n ECHO: 'echo',\n\n /**\n * The subspace tag enables us to partition queues by usage within the context of a space.\n * dxn:queue:<subspace_tag>:<space_id>:<queue_id>[:object_id]\n * dxn:queue:data:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6\n * dxn:queue:trace:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6\n */\n QUEUE: 'queue',\n });\n\n /**\n * Exactly equals.\n */\n static equals(a: DXN, b: DXN): boolean {\n return a.kind === b.kind && a.parts.length === b.parts.length && a.parts.every((part, i) => part === b.parts[i]);\n }\n\n static equalsEchoId(a: DXN, b: DXN): boolean {\n const a1 = a.asEchoDXN();\n const b1 = b.asEchoDXN();\n return !!a1 && !!b1 && a1.echoId === b1.echoId;\n }\n\n // TODO(burdon): Rename isValid.\n static isDXNString(dxn: string): boolean {\n return dxn.startsWith('dxn:');\n }\n\n static parse(dxn: string): DXN {\n if (typeof dxn !== 'string') {\n throw new Error(`Invalid DXN: ${dxn}`);\n }\n const [prefix, kind, ...parts] = dxn.split(':');\n if (!(prefix === 'dxn')) {\n throw new Error(`Invalid DXN: ${dxn}`);\n }\n if (!(typeof kind === 'string' && kind.length > 0)) {\n throw new Error(`Invalid DXN: ${dxn}`);\n }\n if (!(parts.length > 0)) {\n throw new Error(`Invalid DXN: ${dxn}`);\n }\n\n return new DXN(kind, parts);\n }\n\n static tryParse(dxn: string): DXN | undefined {\n try {\n return DXN.parse(dxn);\n } catch {\n return undefined;\n }\n }\n\n /**\n * @example `dxn:type:com.example.type.person`\n */\n static fromTypename(typename: string): DXN {\n return new DXN(DXN.kind.TYPE, [typename]);\n }\n\n /**\n * @example `dxn:type:com.example.type.person:0.1.0`\n */\n // TODO(dmaretskyi): Consider using @ as the version separator.\n static fromTypenameAndVersion(typename: string, version: string): DXN {\n return new DXN(DXN.kind.TYPE, [typename, version]);\n }\n\n /**\n * @example `dxn:echo:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6`\n */\n static fromSpaceAndObjectId(spaceId: SpaceId, objectId: ObjectId): DXN {\n assertArgument(SpaceId.isValid(spaceId), `Invalid space ID: ${spaceId}`);\n assertArgument(ObjectId.isValid(objectId), 'objectId', `Invalid object ID: ${objectId}`);\n return new DXN(DXN.kind.ECHO, [spaceId, objectId]);\n }\n\n /**\n * @example `dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6`\n */\n static fromLocalObjectId(id: string): DXN {\n assertArgument(ObjectId.isValid(id), 'id', `Invalid object ID: ${id}`);\n return new DXN(DXN.kind.ECHO, [LOCAL_SPACE_TAG, id]);\n }\n\n static fromQueue(subspaceTag: QueueSubspaceTag, spaceId: SpaceId, queueId: ObjectId, objectId?: ObjectId) {\n assertArgument(SpaceId.isValid(spaceId), `Invalid space ID: ${spaceId}`);\n assertArgument(ObjectId.isValid(queueId), 'queueId', `Invalid queue ID: ${queueId}`);\n assertArgument(!objectId || ObjectId.isValid(objectId), 'objectId', `Invalid object ID: ${objectId}`);\n\n return new DXN(DXN.kind.QUEUE, [subspaceTag, spaceId, queueId, ...(objectId ? [objectId] : [])]);\n }\n\n #kind: string;\n #parts: string[];\n\n constructor(kind: string, parts: string[]) {\n assertArgument(parts.length > 0, 'parts', `Invalid DXN: ${parts}`);\n assertArgument(\n parts.every((part) => typeof part === 'string' && part.length > 0 && part.indexOf(':') === -1),\n 'parts',\n `Invalid DXN: ${parts}`,\n );\n\n // Per-type validation.\n switch (kind) {\n case DXN.kind.TYPE:\n if (parts.length > 2) {\n throw new Error('Invalid DXN.kind.TYPE');\n }\n break;\n case DXN.kind.ECHO:\n if (parts.length !== 2) {\n throw new Error('Invalid DXN.kind.ECHO');\n }\n break;\n }\n\n this.#kind = kind;\n this.#parts = parts;\n }\n\n toString(): DXN.String {\n return `dxn:${this.#kind}:${this.#parts.join(':')}` as DXN.String;\n }\n\n toJSON(): string {\n return this.toString();\n }\n\n /**\n * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.\n */\n [inspectCustom](depth: number, options: InspectOptionsStylized, inspectFn: typeof inspect): string {\n const printControlCode = (code: number) => {\n return `\\x1b[${code}m`;\n };\n\n return (\n printControlCode(inspectFn.colors.blueBright![0]) + this.toString() + printControlCode(inspectFn.colors.reset![0])\n );\n }\n\n get [devtoolsFormatter](): DevtoolsFormatter {\n return {\n header: () => {\n return ['span', { style: 'font-weight: bold;' }, this.toString()];\n },\n };\n }\n\n get kind() {\n return this.#kind;\n }\n\n get parts() {\n return this.#parts;\n }\n\n // TODO(burdon): Should getters fail?\n get typename() {\n invariant(this.#kind === DXN.kind.TYPE);\n return this.#parts[0];\n }\n\n equals(other: DXN): boolean {\n return DXN.equals(this, other);\n }\n\n hasTypenameOf(typename: string): boolean {\n return this.#kind === DXN.kind.TYPE && this.#parts.length === 1 && this.#parts[0] === typename;\n }\n\n isLocalObjectId(): boolean {\n return this.#kind === DXN.kind.ECHO && this.#parts[0] === LOCAL_SPACE_TAG && this.#parts.length === 2;\n }\n\n asTypeDXN(): DXN.TypeDXN | undefined {\n if (this.kind !== DXN.kind.TYPE) {\n return undefined;\n }\n\n const [type, version] = this.#parts;\n return {\n // TODO(wittjosiah): Should be `typename` for consistency.\n type,\n version: version as string | undefined,\n };\n }\n\n asEchoDXN(): DXN.EchoDXN | undefined {\n if (this.kind !== DXN.kind.ECHO) {\n return undefined;\n }\n\n const [spaceId, echoId] = this.#parts;\n return {\n spaceId: spaceId === LOCAL_SPACE_TAG ? undefined : (spaceId as SpaceId | undefined),\n // TODO(burdon): objectId.\n echoId,\n };\n }\n\n asQueueDXN(): DXN.QueueDXN | undefined {\n if (this.kind !== DXN.kind.QUEUE) {\n return undefined;\n }\n\n const [subspaceTag, spaceId, queueId, objectId] = this.#parts;\n if (typeof queueId !== 'string') {\n return undefined;\n }\n\n return {\n subspaceTag: subspaceTag as QueueSubspaceTag,\n spaceId: spaceId as SpaceId,\n queueId,\n objectId: objectId as string | undefined,\n };\n }\n\n /**\n * Produces a new DXN with the given parts appended.\n */\n extend(parts: string[]): DXN {\n return new DXN(this.#kind, [...this.#parts, ...parts]);\n }\n}\n\n/**\n * API namespace.\n */\nexport declare namespace DXN {\n /**\n * DXN represented as a javascript string.\n */\n // TODO(burdon): Use Effect branded string?\n // export const String = S.String.pipe(S.brand('DXN'));\n // export type String = S.To(typoeof String);\n export type String = string & { __DXNString: never };\n\n export type TypeDXN = {\n type: string;\n version?: string;\n };\n\n export type EchoDXN = {\n spaceId?: SpaceId;\n echoId: string; // TODO(dmaretskyi): Rename to `objectId` and use `ObjectId` for the type.\n };\n\n export type QueueDXN = {\n subspaceTag: QueueSubspaceTag;\n spaceId: SpaceId;\n queueId: string; // TODO(dmaretskyi): ObjectId.\n objectId?: string; // TODO(dmaretskyi): ObjectId.\n };\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\nimport { type PRNG, type ULIDFactory, monotonicFactory } from 'ulidx';\n\n// TODO(dmaretskyi): Make brand.\n// export const ObjectIdBrand: unique symbol = Symbol('@dxos/echo/ObjectId');\n// export const ObjectIdSchema = Schema.ULID.pipe(S.brand(ObjectIdBrand));\nconst ObjectIdSchema = Schema.String.pipe(Schema.pattern(/^[0-7][0-9A-HJKMNP-TV-Z]{25}$/i)).annotations({\n description: 'A Universally Unique Lexicographically Sortable Identifier',\n pattern: '^[0-7][0-9A-HJKMNP-TV-Z]{25}$',\n});\n\nexport type ObjectId = typeof ObjectIdSchema.Type;\n\nexport interface ObjectIdClass extends Schema.SchemaClass<ObjectId, string> {\n /**\n * @returns true if the string is a valid ObjectId.\n */\n isValid(id: string): id is ObjectId;\n\n /**\n * Creates an ObjectId from a string validating the format.\n */\n make(id: string): ObjectId;\n\n /**\n * Generates a random ObjectId.\n */\n random(): ObjectId;\n\n /**\n * WARNING: To be used only within tests.\n *\n * Disables randomness in ObjectId generation, causing the same sequence of IDs to be generated.\n * Do not use in production code as this will cause data collisions.\n * Place this at the top of the test file to ensure that the same sequence of IDs is generated.\n *\n * ```ts\n * ObjectId.dangerouslyDisableRandomness();\n *\n * describe('suite', () => {\n * // ...\n * });\n * ```\n *\n * NOTE: The generated IDs depend on the order of ObjectId.random() calls, which might be affected by test order, scheduling, etc.\n */\n dangerouslyDisableRandomness(): void;\n}\n\n/**\n * Randomly generated unique identifier for an object.\n *\n * Follows ULID spec.\n */\nexport const ObjectId: ObjectIdClass = class extends ObjectIdSchema {\n static #factory: ULIDFactory = monotonicFactory();\n static #seedTime: number | undefined = undefined;\n\n static isValid(id: string): id is ObjectId {\n try {\n Schema.decodeSync(ObjectId)(id);\n return true;\n } catch {\n return false;\n }\n }\n\n static random(): ObjectId {\n return this.#factory(this.#seedTime) as ObjectId;\n }\n\n static dangerouslyDisableRandomness() {\n this.#factory = monotonicFactory(makeTestPRNG());\n this.#seedTime = new Date('2025-01-01').getTime();\n }\n};\n\n/**\n * Test PRNG that always starts with the same seed and produces the same sequence.\n */\nconst makeTestPRNG = (): PRNG => {\n const rng = new SimplePRNG();\n return () => {\n return rng.next();\n };\n};\n\n/**\n * Simple Linear Congruential Generator (LCG) for pseudo-random number generation.\n * Returns numbers in the range [0, 1) (0 inclusive, 1 exclusive).\n */\nexport class SimplePRNG {\n #seed: number;\n\n // LCG parameters (from Numerical Recipes)\n static readonly #a = 1664525;\n static readonly #c = 1013904223;\n static readonly #m = Math.pow(2, 32);\n\n /**\n * Creates a new PRNG instance.\n * @param seed - Initial seed value. If not provided, uses 0.\n */\n constructor(seed: number = 0) {\n this.#seed = seed;\n }\n\n /**\n * Generates the next pseudo-random number in the range [0, 1).\n * @returns A pseudo-random number between 0 (inclusive) and 1 (exclusive).\n */\n next(): number {\n // Update seed using LCG formula: (a * seed + c) mod m\n this.#seed = (SimplePRNG.#a * this.#seed + SimplePRNG.#c) % SimplePRNG.#m;\n\n // Normalize to [0, 1) range\n return this.#seed / SimplePRNG.#m;\n }\n\n /**\n * Resets the generator with a new seed.\n * @param seed - New seed value.\n */\n reset(seed: number): void {\n this.#seed = seed;\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport base32Decode from 'base32-decode';\nimport base32Encode from 'base32-encode';\nimport * as Schema from 'effect/Schema';\n\nimport { invariant } from '@dxos/invariant';\n\nimport { randomBytes } from './random-bytes';\n\n/**\n * Denotes RFC4648 base-32 format.\n */\nconst MULTIBASE_PREFIX = 'B';\n\nconst ENCODED_LENGTH = 33;\n\nconst isValid = (value: unknown): value is SpaceId => {\n return typeof value === 'string' && value.startsWith(MULTIBASE_PREFIX) && value.length === ENCODED_LENGTH;\n};\n\n/**\n * A unique identifier for a space.\n * Space keys are generated by creating a keypair, and then taking the first 20 bytes of the SHA-256 hash of the public key and encoding them to multibase RFC4648 base-32 format (prefixed with B, see Multibase Table).\n * @example BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE\n */\n// TODO(burdon): Use effect branded type?\nexport type SpaceId = string & { __SpaceId: true };\n\nexport const SpaceId: Schema.Schema<SpaceId, string> & {\n byteLength: number;\n encode: (value: Uint8Array) => SpaceId;\n decode: (value: SpaceId) => Uint8Array;\n isValid: (value: unknown) => value is SpaceId;\n make: (value: string) => SpaceId;\n random: () => SpaceId;\n} = class extends Schema.String.pipe(Schema.filter(isValid)) {\n static byteLength = 20;\n\n static encode = (value: Uint8Array): SpaceId => {\n invariant(value instanceof Uint8Array, 'Invalid type');\n invariant(value.length === SpaceId.byteLength, 'Invalid length');\n return (MULTIBASE_PREFIX + base32Encode(value, 'RFC4648')) as SpaceId;\n };\n\n static decode = (value: SpaceId): Uint8Array => {\n invariant(value.startsWith(MULTIBASE_PREFIX), 'Invalid multibase32 encoding');\n return new Uint8Array(base32Decode(value.slice(1), 'RFC4648'));\n };\n\n static isValid = isValid;\n\n static random = (): SpaceId => {\n return SpaceId.encode(randomBytes(SpaceId.byteLength));\n };\n};\n", "import toDataView from 'to-data-view'\n\nconst RFC4648 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'\nconst RFC4648_HEX = '0123456789ABCDEFGHIJKLMNOPQRSTUV'\nconst CROCKFORD = '0123456789ABCDEFGHJKMNPQRSTVWXYZ'\n\nexport default function base32Encode (data, variant, options) {\n options = options || {}\n let alphabet, defaultPadding\n\n switch (variant) {\n case 'RFC3548':\n case 'RFC4648':\n alphabet = RFC4648\n defaultPadding = true\n break\n case 'RFC4648-HEX':\n alphabet = RFC4648_HEX\n defaultPadding = true\n break\n case 'Crockford':\n alphabet = CROCKFORD\n defaultPadding = false\n break\n default:\n throw new Error('Unknown base32 variant: ' + variant)\n }\n\n const padding = (options.padding !== undefined ? options.padding : defaultPadding)\n const view = toDataView(data)\n\n let bits = 0\n let value = 0\n let output = ''\n\n for (let i = 0; i < view.byteLength; i++) {\n value = (value << 8) | view.getUint8(i)\n bits += 8\n\n while (bits >= 5) {\n output += alphabet[(value >>> (bits - 5)) & 31]\n bits -= 5\n }\n }\n\n if (bits > 0) {\n output += alphabet[(value << (5 - bits)) & 31]\n }\n\n if (padding) {\n while ((output.length % 8) !== 0) {\n output += '='\n }\n }\n\n return output\n}\n", "export default function toDataView (data) {\n if (data instanceof Int8Array || data instanceof Uint8Array || data instanceof Uint8ClampedArray) {\n return new DataView(data.buffer, data.byteOffset, data.byteLength)\n }\n\n if (data instanceof ArrayBuffer) {\n return new DataView(data)\n }\n\n throw new TypeError('Expected `data` to be an ArrayBuffer, Buffer, Int8Array, Uint8Array or Uint8ClampedArray')\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nexport const randomBytes = (length: number) => {\n // globalThis.crypto is not available in Node.js when running in vitest even though the documentation says it should be.\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const webCrypto = globalThis.crypto ?? require('node:crypto').webcrypto;\n\n const bytes = new Uint8Array(length);\n webCrypto.getRandomValues(bytes);\n return bytes;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport base32Decode from 'base32-decode';\nimport base32Encode from 'base32-encode';\n\nimport { invariant } from '@dxos/invariant';\n\nimport { randomBytes } from './random-bytes';\n\n/**\n * A unique identifier for an identity.\n * Identity DIDs are generated by creating a keypair, and then taking the first 20 bytes of the SHA-256 hash of the public key and encoding them to multibase RFC4648 base-32 format (prefixed with B, see Multibase Table).\n * @example did:halo:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE\n */\nexport type IdentityDid = string & { __IdentityDid: never };\n\nexport const IdentityDid = Object.freeze({\n byteLength: 20,\n encode: (value: Uint8Array): IdentityDid => {\n invariant(value instanceof Uint8Array, 'Invalid type');\n invariant(value.length === IdentityDid.byteLength, 'Invalid length');\n\n return (DID_PREFIX + MULTIBASE_PREFIX + base32Encode(value, 'RFC4648')) as IdentityDid;\n },\n decode: (value: IdentityDid): Uint8Array => {\n invariant(value.startsWith(DID_PREFIX + MULTIBASE_PREFIX), 'Invalid multibase32 encoding');\n\n return new Uint8Array(base32Decode(value.slice(10), 'RFC4648'));\n },\n isValid: (value: string): value is IdentityDid => {\n return (\n typeof value === 'string' && value.startsWith(DID_PREFIX + MULTIBASE_PREFIX) && value.length === ENCODED_LENGTH\n );\n },\n random: (): IdentityDid => {\n return IdentityDid.encode(randomBytes(IdentityDid.byteLength));\n },\n});\n\n/**\n * Denotes RFC4648 base-32 format.\n */\nconst MULTIBASE_PREFIX = 'B';\n\nconst DID_PREFIX = 'did:halo:';\n\nconst ENCODED_LENGTH = 42;\n", "//\n// Copyright 2020 DXOS.org\n//\n\nimport { type InspectOptionsStylized, type inspect } from 'node:util';\n\nimport base32Decode from 'base32-decode';\nimport base32Encode from 'base32-encode';\n\nimport {\n type DevtoolsFormatter,\n type Equatable,\n devtoolsFormatter,\n equalsSymbol,\n inspectCustom,\n truncateKey,\n} from '@dxos/debug';\nimport { invariant } from '@dxos/invariant';\n\nimport { randomBytes } from './random-bytes';\n\nexport const PUBLIC_KEY_LENGTH = 32;\nexport const SECRET_KEY_LENGTH = 64;\n\n/**\n * All representations that can be converted to a PublicKey.\n */\nexport type PublicKeyLike = PublicKey | Buffer | Uint8Array | ArrayBuffer | string;\n\n/**\n * Vitest with JSDom causes instanceof ArrayBuffer check to fail\n */\nconst isLikeArrayBuffer = (value: any): value is ArrayBuffer =>\n typeof value === 'object' && value !== null && Object.getPrototypeOf(value).constructor.name === 'ArrayBuffer';\n\n/**\n * The purpose of this class is to assure consistent use of keys throughout the project.\n * Keys should be maintained as buffers in objects and proto definitions, and converted to hex\n * strings as late as possible (eg, to log/display).\n */\nexport class PublicKey implements Equatable {\n static ZERO = PublicKey.from('00'.repeat(PUBLIC_KEY_LENGTH));\n\n /**\n * Creates new instance of PublicKey automatically determining the input format.\n * @param source A Buffer, or Uint8Array, or hex encoded string, or something with an `asUint8Array` method on it\n * @returns PublicKey\n */\n static from(source: PublicKeyLike): PublicKey {\n invariant(source);\n if (source instanceof PublicKey) {\n return source;\n } else if (source instanceof Buffer) {\n return new PublicKey(new Uint8Array(source.buffer, source.byteOffset, source.byteLength));\n } else if (source instanceof Uint8Array) {\n return new PublicKey(source);\n } else if (source instanceof ArrayBuffer || isLikeArrayBuffer(source)) {\n return new PublicKey(new Uint8Array(source));\n } else if (typeof source === 'string') {\n // TODO(burdon): Check length.\n return PublicKey.fromHex(source);\n } else if ((<any>source).asUint8Array) {\n return new PublicKey((<any>source).asUint8Array());\n } else {\n throw new TypeError(`Unable to create PublicKey from ${source}`);\n }\n }\n\n /**\n * Same as `PublicKey.from` but does not throw and instead returns a `{ key: PublicKey }` or `{ error: Error }`\n * @param source Same PublicKeyLike argument as for `PublicKey.from`\n * @returns PublicKey\n */\n static safeFrom(source?: PublicKeyLike): PublicKey | undefined {\n if (!source) {\n return undefined;\n }\n\n try {\n const key = PublicKey.from(source);\n // TODO(wittjosiah): Space keys don't pass this check.\n // if (key.length !== PUBLIC_KEY_LENGTH && key.length !== SECRET_KEY_LENGTH) {\n // return undefined;\n // }\n return key;\n } catch (err: any) {\n return undefined;\n }\n }\n\n /**\n * Creates new instance of PublicKey from hex string.\n */\n static fromHex(hex: string): PublicKey {\n if (hex.startsWith('0x')) {\n hex = hex.slice(2);\n }\n\n const buf = Buffer.from(hex, 'hex');\n // TODO(burdon): Test if key.\n return new PublicKey(new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength));\n }\n\n /**\n * Creates a new key.\n */\n static random(): PublicKey {\n // TODO(burdon): Enable seed for debugging.\n return PublicKey.from(randomBytes(PUBLIC_KEY_LENGTH));\n }\n\n static randomOfLength(length: number): PublicKey {\n return PublicKey.from(randomBytes(length));\n }\n\n static *randomSequence(): Generator<PublicKey> {\n for (let i = 0; i < 1_0000; i++) {\n // Counter just to protect against infinite loops.\n yield PublicKey.random();\n }\n throw new Error('Too many keys requested');\n }\n\n /**\n * Tests if provided values is an instance of PublicKey.\n */\n static isPublicKey(value: any): value is PublicKey {\n return value instanceof PublicKey;\n }\n\n /**\n * Asserts that provided values is an instance of PublicKey.\n */\n static assertValidPublicKey(value: any): asserts value is PublicKey {\n if (!this.isPublicKey(value)) {\n throw new TypeError('Invalid PublicKey');\n }\n }\n\n /**\n * Tests two keys for equality.\n */\n static equals(left: PublicKeyLike, right: PublicKeyLike): boolean {\n return PublicKey.from(left).equals(right);\n }\n\n /**\n * @param str string representation of key.\n * @return Key buffer.\n * @deprecated All keys should be represented as instances of PublicKey.\n */\n static bufferize(str: string): Buffer {\n invariant(typeof str === 'string', 'Invalid type');\n const buffer = Buffer.from(str, 'hex');\n // invariant(buffer.length === PUBLIC_KEY_LENGTH || buffer.length === SECRET_KEY_LENGTH,\n // `Invalid key length: ${buffer.length}`);\n return buffer;\n }\n\n /**\n * @param key key like data structure (but not PublicKey which should use toString).\n * @return Hex string representation of key.\n * @deprecated All keys should be represented as instances of PublicKey.\n */\n static stringify(key: Buffer | Uint8Array | ArrayBuffer): string {\n if (key instanceof PublicKey) {\n key = key.asBuffer();\n } else if (key instanceof Uint8Array) {\n key = Buffer.from(key.buffer, key.byteOffset, key.byteLength);\n }\n\n invariant(key instanceof Buffer, 'Invalid type');\n return key.toString('hex');\n }\n\n /**\n * To be used with ComplexMap and ComplexSet.\n * Returns a scalar representation for this key.\n */\n static hash(key: PublicKey): string {\n return key.toHex();\n }\n\n static fromMultibase32(encoded: string): PublicKey {\n invariant(encoded.startsWith('B'), 'Invalid multibase32 encoding');\n\n return new PublicKey(new Uint8Array(base32Decode(encoded.slice(1), 'RFC4648')));\n }\n\n constructor(private readonly _value: Uint8Array) {\n if (!(_value instanceof Uint8Array)) {\n throw new TypeError(`Expected Uint8Array, got: ${_value}`);\n }\n }\n\n toString(): string {\n return this.toHex();\n }\n\n toJSON(): string {\n return this.toHex();\n }\n\n toJSONL(): string {\n return this.truncate();\n }\n\n get length() {\n return this._value.length;\n }\n\n toHex(): string {\n return this.asBuffer().toString('hex');\n }\n\n toMultibase32(): string {\n return 'B' + base32Encode(this._value, 'RFC4648');\n }\n\n truncate(length = undefined): string {\n return truncateKey(this, length);\n }\n\n asBuffer(): Buffer {\n return Buffer.from(this._value.buffer, this._value.byteOffset, this._value.byteLength);\n }\n\n asUint8Array(): Uint8Array {\n return this._value;\n }\n\n getInsecureHash(modulo: number): number {\n return Math.abs(this._value.reduce((acc, val) => (acc ^ val) | 0, 0)) % modulo;\n }\n\n /**\n * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.\n */\n [inspectCustom](depth: number, options: InspectOptionsStylized, inspectFn: typeof inspect): string {\n if (!options.colors || typeof process.stdout.hasColors !== 'function' || !process.stdout.hasColors()) {\n return `<PublicKey ${this.truncate()}>`;\n }\n\n const printControlCode = (code: number) => {\n return `\\x1b[${code}m`;\n };\n\n // NOTE: Keep in sync with formatter colors.\n const colors = [\n 'red',\n 'green',\n 'yellow',\n 'blue',\n 'magenta',\n 'cyan',\n 'redBright',\n 'greenBright',\n 'yellowBright',\n 'blueBright',\n 'magentaBright',\n 'cyanBright',\n 'whiteBright',\n ];\n const color = colors[this.getInsecureHash(colors.length)];\n\n return `PublicKey(${printControlCode(inspectFn.colors[color]![0])}${this.truncate()}${printControlCode(\n inspectFn.colors.reset![0],\n )})`;\n }\n\n get [devtoolsFormatter](): DevtoolsFormatter {\n return {\n header: () => {\n // NOTE: Keep in sync with inspect colors.\n const colors = [\n 'darkred',\n 'green',\n 'orange',\n 'blue',\n 'darkmagenta',\n 'darkcyan',\n 'red',\n 'green',\n 'orange',\n 'blue',\n 'magenta',\n 'darkcyan',\n 'black',\n ];\n const color = colors[this.getInsecureHash(colors.length)];\n\n return [\n 'span',\n {},\n ['span', {}, 'PublicKey('],\n ['span', { style: `color: ${color};` }, this.truncate()],\n ['span', {}, ')'],\n ];\n },\n };\n }\n\n /**\n * Test this key for equality with some other key.\n */\n equals(other: PublicKeyLike): boolean {\n const otherConverted = PublicKey.from(other);\n if (this._value.length !== otherConverted._value.length) {\n return false;\n }\n\n let equal = true;\n for (let i = 0; i < this._value.length; i++) {\n equal &&= this._value[i] === otherConverted._value[i];\n }\n\n return equal;\n }\n\n [equalsSymbol](other: any): boolean {\n if (!PublicKey.isPublicKey(other)) {\n return false;\n }\n\n return this.equals(other);\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACU;AAAA,EACE;AAAA,EACZ,UAAAA;AAAA,EACA;AAAA,OACiB;AALjB;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA,QAAIC,WAAU;AACd,QAAIC,eAAc;AAClB,QAAIC,aAAY;AAEhB,aAAS,SAAU,UAAU,MAAM;AACjC,UAAI,MAAM,SAAS,QAAQ,IAAI;AAE/B,UAAI,QAAQ,IAAI;AACd,cAAM,IAAI,MAAM,8BAA8B,IAAI;AAAA,MACpD;AAEA,aAAO;AAAA,IACT;AAEA,WAAO,UAAU,SAASC,cAAc,OAAO,SAAS;AACtD,UAAI;AAEJ,cAAQ,SAAS;AAAA,QACf,KAAK;AAAA,QACL,KAAK;AACH,qBAAWH;AACX,kBAAQ,MAAM,QAAQ,OAAO,EAAE;AAC/B;AAAA,QACF,KAAK;AACH,qBAAWC;AACX,kBAAQ,MAAM,QAAQ,OAAO,EAAE;A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spectCustom", "assertArgument", "invariant", "Schema", "monotonicFactory", "ObjectIdSchema", "String", "pipe", "pattern", "annotations", "description", "ObjectId", "
|
|
3
|
+
"sources": ["inject-globals:@inject-globals", "../../../../../../node_modules/.pnpm/base32-decode@1.0.0/node_modules/base32-decode/index.js", "../../../src/index.ts", "../../../src/dxn.ts", "../../../src/object-id.ts", "../../../src/space-id.ts", "../../../../../../node_modules/.pnpm/base32-encode@2.0.0/node_modules/base32-encode/index.js", "../../../../../../node_modules/.pnpm/to-data-view@2.0.0/node_modules/to-data-view/index.js", "../../../src/random-bytes.ts", "../../../src/identity-did.ts", "../../../src/parse-id.ts", "../../../src/public-key.ts"],
|
|
4
|
+
"sourcesContent": ["\n export {\n global,\nBuffer,\nprocess\n } from '@dxos/node-std/inject-globals';\n // Empty source map so that esbuild does not inject virtual source file names.\n //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==\n ", "var RFC4648 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'\nvar RFC4648_HEX = '0123456789ABCDEFGHIJKLMNOPQRSTUV'\nvar CROCKFORD = '0123456789ABCDEFGHJKMNPQRSTVWXYZ'\n\nfunction readChar (alphabet, char) {\n var idx = alphabet.indexOf(char)\n\n if (idx === -1) {\n throw new Error('Invalid character found: ' + char)\n }\n\n return idx\n}\n\nmodule.exports = function base32Decode (input, variant) {\n var alphabet\n\n switch (variant) {\n case 'RFC3548':\n case 'RFC4648':\n alphabet = RFC4648\n input = input.replace(/=+$/, '')\n break\n case 'RFC4648-HEX':\n alphabet = RFC4648_HEX\n input = input.replace(/=+$/, '')\n break\n case 'Crockford':\n alphabet = CROCKFORD\n input = input.toUpperCase().replace(/O/g, '0').replace(/[IL]/g, '1')\n break\n default:\n throw new Error('Unknown base32 variant: ' + variant)\n }\n\n var length = input.length\n\n var bits = 0\n var value = 0\n\n var index = 0\n var output = new Uint8Array((length * 5 / 8) | 0)\n\n for (var i = 0; i < length; i++) {\n value = (value << 5) | readChar(alphabet, input[i])\n bits += 5\n\n if (bits >= 8) {\n output[index++] = (value >>> (bits - 8)) & 255\n bits -= 8\n }\n }\n\n return output.buffer\n}\n", "//\n// Copyright 2020 DXOS.org\n//\n\nexport * from './dxn';\nexport * from './identity-did';\nexport * from './object-id';\nexport * from './parse-id';\nexport * from './public-key';\nexport * from './space-id';\nexport type * from './types';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\nimport type { InspectOptionsStylized, inspect } from 'node:util';\n\nimport { type DevtoolsFormatter, devtoolsFormatter, inspectCustom } from '@dxos/debug';\nimport { assertArgument, invariant } from '@dxos/invariant';\n\nimport { ObjectId } from './object-id';\nimport { SpaceId } from './space-id';\n\n/**\n * Tags for ECHO DXNs that should resolve the object ID in the local space.\n */\n// TODO(dmaretskyi): Rebrand this as \"unknown location\" to specify objects in the same space or queue. Essentially making the DXN it a URI not URL\n// TODO(dmaretskyi): \"@\" is a separator character in the URI spec.\nexport const LOCAL_SPACE_TAG = '@';\n\nexport const DXN_ECHO_REGEXP = /@(dxn:[a-zA-Z0-p:@]+)/;\n\n// TODO(burdon): Namespace for.\nexport const QueueSubspaceTags = Object.freeze({\n DATA: 'data',\n TRACE: 'trace',\n});\n\nexport type QueueSubspaceTag = (typeof QueueSubspaceTags)[keyof typeof QueueSubspaceTags];\n\n// TODO(burdon): Refactor.\n// Consider: https://github.com/multiformats/multiaddr\n// dxn:echo:[<space-id>:[<queue-id>:]]<object-id>\n// dxn:echo:[S/<space-id>:[Q/<queue-id>:]]<object-id>\n// dxn:type:org.dxos.markdown.contact\n\n/**\n * DXN unambiguously names a resource like an ECHO object, schema definition, plugin, etc.\n * Each DXN starts with a dxn prefix, followed by a resource kind.\n * Colon Symbol : is used a delimiter between parts.\n * DXNs may contain slashes.\n * '@' in the place of the space id is used to denote that the DXN should be resolved in the local space.\n *\n * @example\n * ```\n * dxn:echo:<space key>:<echo id>\n * dxn:echo:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6\n * dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6\n * dxn:type:org.dxos.type.calendar\n * dxn:plugin:org.dxos.agent.plugin.functions\n * ```\n */\nexport class DXN {\n // TODO(burdon): Rename to DXN (i.e., DXN.DXN).\n // TODO(dmaretskyi): Should this be a transformation into the DXN type?\n static Schema = Schema.NonEmptyString.pipe(\n Schema.pattern(/^dxn:([^:]+):(?:[^:]+:?)+[^:]$/),\n // TODO(dmaretskyi): To set the format we need to move the annotation IDs out of the echo-schema package.\n // FormatAnnotation.set(TypeFormat.DXN),\n Schema.annotations({\n title: 'DXN',\n description: 'DXN URI',\n examples: ['dxn:type:com.example.type.my-type', 'dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6'],\n }),\n );\n\n static hash(dxn: DXN): string {\n return dxn.toString();\n }\n\n /**\n * Kind constants.\n */\n static kind = Object.freeze({\n /**\n * dxn:type:<type_name>[:<version>]\n */\n TYPE: 'type',\n\n /**\n * dxn:echo:<space_id>:<echo_id>\n * dxn:echo:@:<echo_id>\n */\n // TODO(burdon): Rename to OBJECT? (BREAKING CHANGE to update \"echo\").\n // TODO(burdon): Add separate Kind for space?\n ECHO: 'echo',\n\n /**\n * The subspace tag enables us to partition queues by usage within the context of a space.\n * dxn:queue:<subspace_tag>:<space_id>:<queue_id>[:object_id]\n * dxn:queue:data:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6\n * dxn:queue:trace:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6\n */\n QUEUE: 'queue',\n });\n\n /**\n * Exactly equals.\n */\n static equals(a: DXN, b: DXN): boolean {\n return a.kind === b.kind && a.parts.length === b.parts.length && a.parts.every((part, i) => part === b.parts[i]);\n }\n\n static equalsEchoId(a: DXN, b: DXN): boolean {\n const a1 = a.asEchoDXN();\n const b1 = b.asEchoDXN();\n return !!a1 && !!b1 && a1.echoId === b1.echoId;\n }\n\n // TODO(burdon): Rename isValid.\n static isDXNString(dxn: string): boolean {\n return dxn.startsWith('dxn:');\n }\n\n static parse(dxn: string): DXN {\n if (typeof dxn !== 'string') {\n throw new Error(`Invalid DXN: ${dxn}`);\n }\n const [prefix, kind, ...parts] = dxn.split(':');\n if (!(prefix === 'dxn')) {\n throw new Error(`Invalid DXN: ${dxn}`);\n }\n if (!(typeof kind === 'string' && kind.length > 0)) {\n throw new Error(`Invalid DXN: ${dxn}`);\n }\n if (!(parts.length > 0)) {\n throw new Error(`Invalid DXN: ${dxn}`);\n }\n\n return new DXN(kind, parts);\n }\n\n static tryParse(dxn: string): DXN | undefined {\n try {\n return DXN.parse(dxn);\n } catch {\n return undefined;\n }\n }\n\n /**\n * @example `dxn:type:com.example.type.person`\n */\n static fromTypename(typename: string): DXN {\n return new DXN(DXN.kind.TYPE, [typename]);\n }\n\n /**\n * @example `dxn:type:com.example.type.person:0.1.0`\n */\n // TODO(dmaretskyi): Consider using @ as the version separator.\n static fromTypenameAndVersion(typename: string, version: string): DXN {\n return new DXN(DXN.kind.TYPE, [typename, version]);\n }\n\n /**\n * @example `dxn:echo:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6`\n */\n static fromSpaceAndObjectId(spaceId: SpaceId, objectId: ObjectId): DXN {\n assertArgument(SpaceId.isValid(spaceId), `Invalid space ID: ${spaceId}`);\n assertArgument(ObjectId.isValid(objectId), 'objectId', `Invalid object ID: ${objectId}`);\n return new DXN(DXN.kind.ECHO, [spaceId, objectId]);\n }\n\n /**\n * @example `dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6`\n */\n static fromLocalObjectId(id: string): DXN {\n assertArgument(ObjectId.isValid(id), 'id', `Invalid object ID: ${id}`);\n return new DXN(DXN.kind.ECHO, [LOCAL_SPACE_TAG, id]);\n }\n\n static fromQueue(subspaceTag: QueueSubspaceTag, spaceId: SpaceId, queueId: ObjectId, objectId?: ObjectId) {\n assertArgument(SpaceId.isValid(spaceId), `Invalid space ID: ${spaceId}`);\n assertArgument(ObjectId.isValid(queueId), 'queueId', `Invalid queue ID: ${queueId}`);\n assertArgument(!objectId || ObjectId.isValid(objectId), 'objectId', `Invalid object ID: ${objectId}`);\n\n return new DXN(DXN.kind.QUEUE, [subspaceTag, spaceId, queueId, ...(objectId ? [objectId] : [])]);\n }\n\n #kind: string;\n #parts: string[];\n\n constructor(kind: string, parts: string[]) {\n assertArgument(parts.length > 0, 'parts', `Invalid DXN: ${parts}`);\n assertArgument(\n parts.every((part) => typeof part === 'string' && part.length > 0 && part.indexOf(':') === -1),\n 'parts',\n `Invalid DXN: ${parts}`,\n );\n\n // Per-type validation.\n switch (kind) {\n case DXN.kind.TYPE:\n if (parts.length > 2) {\n throw new Error('Invalid DXN.kind.TYPE');\n }\n break;\n case DXN.kind.ECHO:\n if (parts.length !== 2) {\n throw new Error('Invalid DXN.kind.ECHO');\n }\n break;\n }\n\n this.#kind = kind;\n this.#parts = parts;\n }\n\n toString(): DXN.String {\n return `dxn:${this.#kind}:${this.#parts.join(':')}` as DXN.String;\n }\n\n toJSON(): string {\n return this.toString();\n }\n\n /**\n * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.\n */\n [inspectCustom](depth: number, options: InspectOptionsStylized, inspectFn: typeof inspect): string {\n const printControlCode = (code: number) => {\n return `\\x1b[${code}m`;\n };\n\n return (\n printControlCode(inspectFn.colors.blueBright![0]) + this.toString() + printControlCode(inspectFn.colors.reset![0])\n );\n }\n\n get [devtoolsFormatter](): DevtoolsFormatter {\n return {\n header: () => {\n return ['span', { style: 'font-weight: bold;' }, this.toString()];\n },\n };\n }\n\n get kind() {\n return this.#kind;\n }\n\n get parts() {\n return this.#parts;\n }\n\n // TODO(burdon): Should getters fail?\n get typename() {\n invariant(this.#kind === DXN.kind.TYPE);\n return this.#parts[0];\n }\n\n equals(other: DXN): boolean {\n return DXN.equals(this, other);\n }\n\n hasTypenameOf(typename: string): boolean {\n return this.#kind === DXN.kind.TYPE && this.#parts.length === 1 && this.#parts[0] === typename;\n }\n\n isLocalObjectId(): boolean {\n return this.#kind === DXN.kind.ECHO && this.#parts[0] === LOCAL_SPACE_TAG && this.#parts.length === 2;\n }\n\n asTypeDXN(): DXN.TypeDXN | undefined {\n if (this.kind !== DXN.kind.TYPE) {\n return undefined;\n }\n\n const [type, version] = this.#parts;\n return {\n // TODO(wittjosiah): Should be `typename` for consistency.\n type,\n version: version as string | undefined,\n };\n }\n\n asEchoDXN(): DXN.EchoDXN | undefined {\n if (this.kind !== DXN.kind.ECHO) {\n return undefined;\n }\n\n const [spaceId, echoId] = this.#parts;\n return {\n spaceId: spaceId === LOCAL_SPACE_TAG ? undefined : (spaceId as SpaceId | undefined),\n // TODO(burdon): objectId.\n echoId,\n };\n }\n\n asQueueDXN(): DXN.QueueDXN | undefined {\n if (this.kind !== DXN.kind.QUEUE) {\n return undefined;\n }\n\n const [subspaceTag, spaceId, queueId, objectId] = this.#parts;\n if (typeof queueId !== 'string') {\n return undefined;\n }\n\n return {\n subspaceTag: subspaceTag as QueueSubspaceTag,\n spaceId: spaceId as SpaceId,\n queueId,\n objectId: objectId as string | undefined,\n };\n }\n\n /**\n * Produces a new DXN with the given parts appended.\n */\n extend(parts: string[]): DXN {\n return new DXN(this.#kind, [...this.#parts, ...parts]);\n }\n}\n\n/**\n * API namespace.\n */\nexport declare namespace DXN {\n /**\n * DXN represented as a javascript string.\n */\n // TODO(burdon): Use Effect branded string?\n // export const String = S.String.pipe(S.brand('DXN'));\n // export type String = S.To(typoeof String);\n export type String = string & { __DXNString: never };\n\n export type TypeDXN = {\n type: string;\n version?: string;\n };\n\n export type EchoDXN = {\n spaceId?: SpaceId;\n echoId: string; // TODO(dmaretskyi): Rename to `objectId` and use `ObjectId` for the type.\n };\n\n export type QueueDXN = {\n subspaceTag: QueueSubspaceTag;\n spaceId: SpaceId;\n queueId: string; // TODO(dmaretskyi): ObjectId.\n objectId?: string; // TODO(dmaretskyi): ObjectId.\n };\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\nimport { type PRNG, type ULIDFactory, monotonicFactory } from 'ulidx';\n\n// TODO(dmaretskyi): Make brand.\n// export const ObjectIdBrand: unique symbol = Symbol('@dxos/echo/ObjectId');\n// export const ObjectIdSchema = Schema.ULID.pipe(S.brand(ObjectIdBrand));\nconst ObjectIdSchema = Schema.String.pipe(Schema.pattern(/^[0-7][0-9A-HJKMNP-TV-Z]{25}$/i)).annotations({\n description: 'A Universally Unique Lexicographically Sortable Identifier',\n pattern: '^[0-7][0-9A-HJKMNP-TV-Z]{25}$',\n});\n\nexport type ObjectId = typeof ObjectIdSchema.Type;\n\nexport interface ObjectIdClass extends Schema.SchemaClass<ObjectId, string> {\n /**\n * @returns true if the string is a valid ObjectId.\n */\n isValid(id: string): id is ObjectId;\n\n /**\n * Creates an ObjectId from a string validating the format.\n */\n make(id: string): ObjectId;\n\n /**\n * Generates a random ObjectId.\n */\n random(): ObjectId;\n\n /**\n * WARNING: To be used only within tests.\n *\n * Disables randomness in ObjectId generation, causing the same sequence of IDs to be generated.\n * Do not use in production code as this will cause data collisions.\n * Place this at the top of the test file to ensure that the same sequence of IDs is generated.\n *\n * ```ts\n * ObjectId.dangerouslyDisableRandomness();\n *\n * describe('suite', () => {\n * // ...\n * });\n * ```\n *\n * NOTE: The generated IDs depend on the order of ObjectId.random() calls, which might be affected by test order, scheduling, etc.\n */\n dangerouslyDisableRandomness(): void;\n\n /**\n * WARNING: To be used only within tests.\n *\n * Pins the time component of generated ObjectIds and seeds the PRNG used for the random component,\n * causing the same sequence of IDs to be generated across runs.\n * Do not use in production code as this will cause data collisions.\n *\n * @param time - Fixed timestamp (ms since epoch) used as the ULID time component.\n * @param seed - Seed value for the PRNG used for the ULID random component.\n *\n * ```ts\n * ObjectId.dangerouslySetSeed(new Date('2025-01-01').getTime(), 42);\n * ```\n *\n * NOTE: The generated IDs depend on the order of ObjectId.random() calls, which might be affected by test order, scheduling, etc.\n */\n dangerouslySetSeed(time: number, seed: number): void;\n}\n\n/**\n * Randomly generated unique identifier for an object.\n *\n * Follows ULID spec.\n */\nexport const ObjectId: ObjectIdClass = class extends ObjectIdSchema {\n static #factory: ULIDFactory = monotonicFactory();\n static #seedTime: number | undefined = undefined;\n\n static isValid(id: string): id is ObjectId {\n try {\n Schema.decodeSync(ObjectId)(id);\n return true;\n } catch {\n return false;\n }\n }\n\n static random(): ObjectId {\n return this.#factory(this.#seedTime) as ObjectId;\n }\n\n static dangerouslyDisableRandomness() {\n this.#factory = monotonicFactory(makeTestPRNG());\n this.#seedTime = new Date('2025-01-01').getTime();\n }\n\n static dangerouslySetSeed(time: number, seed: number) {\n this.#factory = monotonicFactory(makeTestPRNG(seed));\n this.#seedTime = time;\n }\n};\n\n/**\n * Test PRNG that always starts with the same seed and produces the same sequence.\n */\nconst makeTestPRNG = (seed: number = 0): PRNG => {\n const rng = new SimplePRNG(seed);\n return () => {\n return rng.next();\n };\n};\n\n/**\n * Simple Linear Congruential Generator (LCG) for pseudo-random number generation.\n * Returns numbers in the range [0, 1) (0 inclusive, 1 exclusive).\n */\nexport class SimplePRNG {\n #seed: number;\n\n // LCG parameters (from Numerical Recipes)\n static readonly #a = 1664525;\n static readonly #c = 1013904223;\n static readonly #m = Math.pow(2, 32);\n\n /**\n * Creates a new PRNG instance.\n * @param seed - Initial seed value. If not provided, uses 0.\n */\n constructor(seed: number = 0) {\n this.#seed = seed;\n }\n\n /**\n * Generates the next pseudo-random number in the range [0, 1).\n * @returns A pseudo-random number between 0 (inclusive) and 1 (exclusive).\n */\n next(): number {\n // Update seed using LCG formula: (a * seed + c) mod m\n this.#seed = (SimplePRNG.#a * this.#seed + SimplePRNG.#c) % SimplePRNG.#m;\n\n // Normalize to [0, 1) range\n return this.#seed / SimplePRNG.#m;\n }\n\n /**\n * Resets the generator with a new seed.\n * @param seed - New seed value.\n */\n reset(seed: number): void {\n this.#seed = seed;\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport base32Decode from 'base32-decode';\nimport base32Encode from 'base32-encode';\nimport * as Schema from 'effect/Schema';\n\nimport { invariant } from '@dxos/invariant';\n\nimport { randomBytes } from './random-bytes';\n\n/**\n * Denotes RFC4648 base-32 format.\n */\nconst MULTIBASE_PREFIX = 'B';\n\nconst ENCODED_LENGTH = 33;\n\nconst isValid = (value: unknown): value is SpaceId => {\n return typeof value === 'string' && value.startsWith(MULTIBASE_PREFIX) && value.length === ENCODED_LENGTH;\n};\n\n/**\n * A unique identifier for a space.\n * Space keys are generated by creating a keypair, and then taking the first 20 bytes of the SHA-256 hash of the public key and encoding them to multibase RFC4648 base-32 format (prefixed with B, see Multibase Table).\n * @example BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE\n */\n// TODO(burdon): Use effect branded type?\nexport type SpaceId = string & { __SpaceId: true };\n\nexport const SpaceId: Schema.Schema<SpaceId, string> & {\n byteLength: number;\n encode: (value: Uint8Array) => SpaceId;\n decode: (value: SpaceId) => Uint8Array;\n isValid: (value: unknown) => value is SpaceId;\n make: (value: string) => SpaceId;\n random: () => SpaceId;\n} = class extends Schema.String.pipe(Schema.filter(isValid)) {\n static byteLength = 20;\n\n static encode = (value: Uint8Array): SpaceId => {\n invariant(value instanceof Uint8Array, 'Invalid type');\n invariant(value.length === SpaceId.byteLength, 'Invalid length');\n return (MULTIBASE_PREFIX + base32Encode(value, 'RFC4648')) as SpaceId;\n };\n\n static decode = (value: SpaceId): Uint8Array => {\n invariant(value.startsWith(MULTIBASE_PREFIX), 'Invalid multibase32 encoding');\n return new Uint8Array(base32Decode(value.slice(1), 'RFC4648'));\n };\n\n static isValid = isValid;\n\n static random = (): SpaceId => {\n return SpaceId.encode(randomBytes(SpaceId.byteLength));\n };\n};\n", "import toDataView from 'to-data-view'\n\nconst RFC4648 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'\nconst RFC4648_HEX = '0123456789ABCDEFGHIJKLMNOPQRSTUV'\nconst CROCKFORD = '0123456789ABCDEFGHJKMNPQRSTVWXYZ'\n\nexport default function base32Encode (data, variant, options) {\n options = options || {}\n let alphabet, defaultPadding\n\n switch (variant) {\n case 'RFC3548':\n case 'RFC4648':\n alphabet = RFC4648\n defaultPadding = true\n break\n case 'RFC4648-HEX':\n alphabet = RFC4648_HEX\n defaultPadding = true\n break\n case 'Crockford':\n alphabet = CROCKFORD\n defaultPadding = false\n break\n default:\n throw new Error('Unknown base32 variant: ' + variant)\n }\n\n const padding = (options.padding !== undefined ? options.padding : defaultPadding)\n const view = toDataView(data)\n\n let bits = 0\n let value = 0\n let output = ''\n\n for (let i = 0; i < view.byteLength; i++) {\n value = (value << 8) | view.getUint8(i)\n bits += 8\n\n while (bits >= 5) {\n output += alphabet[(value >>> (bits - 5)) & 31]\n bits -= 5\n }\n }\n\n if (bits > 0) {\n output += alphabet[(value << (5 - bits)) & 31]\n }\n\n if (padding) {\n while ((output.length % 8) !== 0) {\n output += '='\n }\n }\n\n return output\n}\n", "export default function toDataView (data) {\n if (data instanceof Int8Array || data instanceof Uint8Array || data instanceof Uint8ClampedArray) {\n return new DataView(data.buffer, data.byteOffset, data.byteLength)\n }\n\n if (data instanceof ArrayBuffer) {\n return new DataView(data)\n }\n\n throw new TypeError('Expected `data` to be an ArrayBuffer, Buffer, Int8Array, Uint8Array or Uint8ClampedArray')\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nexport const randomBytes = (length: number) => {\n // globalThis.crypto is not available in Node.js when running in vitest even though the documentation says it should be.\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const webCrypto = globalThis.crypto ?? require('node:crypto').webcrypto;\n\n const bytes = new Uint8Array(length);\n webCrypto.getRandomValues(bytes);\n return bytes;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport base32Decode from 'base32-decode';\nimport base32Encode from 'base32-encode';\n\nimport { invariant } from '@dxos/invariant';\n\nimport { randomBytes } from './random-bytes';\n\n/**\n * A unique identifier for an identity.\n * Identity DIDs are generated by creating a keypair, and then taking the first 20 bytes of the SHA-256 hash of the public key and encoding them to multibase RFC4648 base-32 format (prefixed with B, see Multibase Table).\n * @example did:halo:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE\n */\nexport type IdentityDid = string & { __IdentityDid: never };\n\nexport const IdentityDid = Object.freeze({\n byteLength: 20,\n encode: (value: Uint8Array): IdentityDid => {\n invariant(value instanceof Uint8Array, 'Invalid type');\n invariant(value.length === IdentityDid.byteLength, 'Invalid length');\n\n return (DID_PREFIX + MULTIBASE_PREFIX + base32Encode(value, 'RFC4648')) as IdentityDid;\n },\n decode: (value: IdentityDid): Uint8Array => {\n invariant(value.startsWith(DID_PREFIX + MULTIBASE_PREFIX), 'Invalid multibase32 encoding');\n\n return new Uint8Array(base32Decode(value.slice(10), 'RFC4648'));\n },\n isValid: (value: string): value is IdentityDid => {\n return (\n typeof value === 'string' && value.startsWith(DID_PREFIX + MULTIBASE_PREFIX) && value.length === ENCODED_LENGTH\n );\n },\n random: (): IdentityDid => {\n return IdentityDid.encode(randomBytes(IdentityDid.byteLength));\n },\n});\n\n/**\n * Denotes RFC4648 base-32 format.\n */\nconst MULTIBASE_PREFIX = 'B';\n\nconst DID_PREFIX = 'did:halo:';\n\nconst ENCODED_LENGTH = 42;\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type ObjectId } from './object-id';\nimport { type SpaceId } from './space-id';\n\nexport const SPACE_ID_LENGTH = 33;\nexport const OBJECT_ID_LENGTH = 26;\nexport const FQ_ID_LENGTH = SPACE_ID_LENGTH + OBJECT_ID_LENGTH + 1;\n\nexport const parseId = (id?: string): { spaceId?: SpaceId; objectId?: ObjectId } => {\n if (!id) {\n return {};\n } else if (id.length === SPACE_ID_LENGTH) {\n return {\n spaceId: id as SpaceId,\n };\n } else if (id.length === OBJECT_ID_LENGTH) {\n return {\n objectId: id as ObjectId,\n };\n } else if (id.length === FQ_ID_LENGTH && id.indexOf(':') === SPACE_ID_LENGTH) {\n const [spaceId, objectId] = id.split(':');\n return {\n spaceId: spaceId as SpaceId,\n objectId: objectId as ObjectId,\n };\n } else {\n return {};\n }\n};\n", "//\n// Copyright 2020 DXOS.org\n//\n\nimport base32Decode from 'base32-decode';\nimport base32Encode from 'base32-encode';\nimport { type InspectOptionsStylized, type inspect } from 'node:util';\n\nimport {\n type DevtoolsFormatter,\n type Equatable,\n devtoolsFormatter,\n equalsSymbol,\n inspectCustom,\n truncateKey,\n} from '@dxos/debug';\nimport { invariant } from '@dxos/invariant';\n\nimport { randomBytes } from './random-bytes';\n\nexport const PUBLIC_KEY_LENGTH = 32;\nexport const SECRET_KEY_LENGTH = 64;\n\n/**\n * All representations that can be converted to a PublicKey.\n */\nexport type PublicKeyLike = PublicKey | Buffer | Uint8Array | ArrayBuffer | string;\n\n/**\n * Vitest with JSDom causes instanceof ArrayBuffer check to fail\n */\nconst isLikeArrayBuffer = (value: any): value is ArrayBuffer =>\n typeof value === 'object' && value !== null && Object.getPrototypeOf(value).constructor.name === 'ArrayBuffer';\n\n/**\n * The purpose of this class is to assure consistent use of keys throughout the project.\n * Keys should be maintained as buffers in objects and proto definitions, and converted to hex\n * strings as late as possible (eg, to log/display).\n */\nexport class PublicKey implements Equatable {\n static ZERO = PublicKey.from('00'.repeat(PUBLIC_KEY_LENGTH));\n\n /**\n * Creates new instance of PublicKey automatically determining the input format.\n * @param source A Buffer, or Uint8Array, or hex encoded string, or something with an `asUint8Array` method on it\n * @returns PublicKey\n */\n static from(source: PublicKeyLike): PublicKey {\n invariant(source);\n if (source instanceof PublicKey) {\n return source;\n } else if (source instanceof Buffer) {\n return new PublicKey(new Uint8Array(source.buffer, source.byteOffset, source.byteLength));\n } else if (source instanceof Uint8Array) {\n return new PublicKey(source);\n } else if (source instanceof ArrayBuffer || isLikeArrayBuffer(source)) {\n return new PublicKey(new Uint8Array(source));\n } else if (typeof source === 'string') {\n // TODO(burdon): Check length.\n return PublicKey.fromHex(source);\n } else if ((<any>source).asUint8Array) {\n return new PublicKey((<any>source).asUint8Array());\n } else {\n throw new TypeError(`Unable to create PublicKey from ${source}`);\n }\n }\n\n /**\n * Same as `PublicKey.from` but does not throw and instead returns a `{ key: PublicKey }` or `{ error: Error }`\n * @param source Same PublicKeyLike argument as for `PublicKey.from`\n * @returns PublicKey\n */\n static safeFrom(source?: PublicKeyLike): PublicKey | undefined {\n if (!source) {\n return undefined;\n }\n\n try {\n const key = PublicKey.from(source);\n // TODO(wittjosiah): Space keys don't pass this check.\n // if (key.length !== PUBLIC_KEY_LENGTH && key.length !== SECRET_KEY_LENGTH) {\n // return undefined;\n // }\n return key;\n } catch (err: any) {\n return undefined;\n }\n }\n\n /**\n * Creates new instance of PublicKey from hex string.\n */\n static fromHex(hex: string): PublicKey {\n if (hex.startsWith('0x')) {\n hex = hex.slice(2);\n }\n\n const buf = Buffer.from(hex, 'hex');\n // TODO(burdon): Test if key.\n return new PublicKey(new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength));\n }\n\n /**\n * Creates a new key.\n */\n static random(): PublicKey {\n // TODO(burdon): Enable seed for debugging.\n return PublicKey.from(randomBytes(PUBLIC_KEY_LENGTH));\n }\n\n static randomOfLength(length: number): PublicKey {\n return PublicKey.from(randomBytes(length));\n }\n\n static *randomSequence(): Generator<PublicKey> {\n for (let i = 0; i < 1_0000; i++) {\n // Counter just to protect against infinite loops.\n yield PublicKey.random();\n }\n throw new Error('Too many keys requested');\n }\n\n /**\n * Tests if provided values is an instance of PublicKey.\n */\n static isPublicKey(value: any): value is PublicKey {\n return value instanceof PublicKey;\n }\n\n /**\n * Asserts that provided values is an instance of PublicKey.\n */\n static assertValidPublicKey(value: any): asserts value is PublicKey {\n if (!this.isPublicKey(value)) {\n throw new TypeError('Invalid PublicKey');\n }\n }\n\n /**\n * Tests two keys for equality.\n */\n static equals(left: PublicKeyLike, right: PublicKeyLike): boolean {\n return PublicKey.from(left).equals(right);\n }\n\n /**\n * @param str string representation of key.\n * @return Key buffer.\n * @deprecated All keys should be represented as instances of PublicKey.\n */\n static bufferize(str: string): Buffer {\n invariant(typeof str === 'string', 'Invalid type');\n const buffer = Buffer.from(str, 'hex');\n // invariant(buffer.length === PUBLIC_KEY_LENGTH || buffer.length === SECRET_KEY_LENGTH,\n // `Invalid key length: ${buffer.length}`);\n return buffer;\n }\n\n /**\n * @param key key like data structure (but not PublicKey which should use toString).\n * @return Hex string representation of key.\n * @deprecated All keys should be represented as instances of PublicKey.\n */\n static stringify(key: Buffer | Uint8Array | ArrayBuffer): string {\n if (key instanceof PublicKey) {\n key = key.asBuffer();\n } else if (key instanceof Uint8Array) {\n key = Buffer.from(key.buffer, key.byteOffset, key.byteLength);\n }\n\n invariant(key instanceof Buffer, 'Invalid type');\n return key.toString('hex');\n }\n\n /**\n * To be used with ComplexMap and ComplexSet.\n * Returns a scalar representation for this key.\n */\n static hash(key: PublicKey): string {\n return key.toHex();\n }\n\n static fromMultibase32(encoded: string): PublicKey {\n invariant(encoded.startsWith('B'), 'Invalid multibase32 encoding');\n\n return new PublicKey(new Uint8Array(base32Decode(encoded.slice(1), 'RFC4648')));\n }\n\n constructor(private readonly _value: Uint8Array) {\n if (!(_value instanceof Uint8Array)) {\n throw new TypeError(`Expected Uint8Array, got: ${_value}`);\n }\n }\n\n toString(): string {\n return this.toHex();\n }\n\n toJSON(): string {\n return this.toHex();\n }\n\n toJSONL(): string {\n return this.truncate();\n }\n\n get length() {\n return this._value.length;\n }\n\n toHex(): string {\n return this.asBuffer().toString('hex');\n }\n\n toMultibase32(): string {\n return 'B' + base32Encode(this._value, 'RFC4648');\n }\n\n truncate(length?: number): string {\n return truncateKey(this, length);\n }\n\n asBuffer(): Buffer {\n return Buffer.from(this._value.buffer, this._value.byteOffset, this._value.byteLength);\n }\n\n asUint8Array(): Uint8Array {\n return this._value;\n }\n\n getInsecureHash(modulo: number): number {\n return Math.abs(this._value.reduce((acc, val) => (acc ^ val) | 0, 0)) % modulo;\n }\n\n /**\n * Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.\n */\n [inspectCustom](depth: number, options: InspectOptionsStylized, inspectFn: typeof inspect): string {\n if (!options.colors || typeof process.stdout.hasColors !== 'function' || !process.stdout.hasColors()) {\n return `<PublicKey ${this.truncate()}>`;\n }\n\n const printControlCode = (code: number) => {\n return `\\x1b[${code}m`;\n };\n\n // NOTE: Keep in sync with formatter colors.\n const colors = [\n 'red',\n 'green',\n 'yellow',\n 'blue',\n 'magenta',\n 'cyan',\n 'redBright',\n 'greenBright',\n 'yellowBright',\n 'blueBright',\n 'magentaBright',\n 'cyanBright',\n 'whiteBright',\n ];\n const color = colors[this.getInsecureHash(colors.length)];\n\n return `PublicKey(${printControlCode(inspectFn.colors[color]![0])}${this.truncate()}${printControlCode(\n inspectFn.colors.reset![0],\n )})`;\n }\n\n get [devtoolsFormatter](): DevtoolsFormatter {\n return {\n header: () => {\n // NOTE: Keep in sync with inspect colors.\n const colors = [\n 'darkred',\n 'green',\n 'orange',\n 'blue',\n 'darkmagenta',\n 'darkcyan',\n 'red',\n 'green',\n 'orange',\n 'blue',\n 'magenta',\n 'darkcyan',\n 'black',\n ];\n const color = colors[this.getInsecureHash(colors.length)];\n\n return [\n 'span',\n {},\n ['span', {}, 'PublicKey('],\n ['span', { style: `color: ${color};` }, this.truncate()],\n ['span', {}, ')'],\n ];\n },\n };\n }\n\n /**\n * Test this key for equality with some other key.\n */\n equals(other: PublicKeyLike): boolean {\n const otherConverted = PublicKey.from(other);\n if (this._value.length !== otherConverted._value.length) {\n return false;\n }\n\n let equal = true;\n for (let i = 0; i < this._value.length; i++) {\n equal &&= this._value[i] === otherConverted._value[i];\n }\n\n return equal;\n }\n\n [equalsSymbol](other: any): boolean {\n if (!PublicKey.isPublicKey(other)) {\n return false;\n }\n\n return this.equals(other);\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAC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AI,KAAKrB,SAAQ,CAAA,GAAKmB,iBACpFL,UAAUC,OAAOO,MAAO,CAAA,CAAE,CAAA;EAE9B;EAEA,KAAKC,kBAAAA,IAAwC;AAC3C,WAAO;MACLC,QAAQ,MAAA;AAEN,cAAMT,SAAS;UACb;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;AAEF,cAAMM,QAAQN,OAAO,KAAKX,gBAAgBW,OAAOrC,MAAM,CAAA;AAEvD,eAAO;UACL;UACA,CAAC;UACD;YAAC;YAAQ,CAAC;YAAG;;UACb;YAAC;YAAQ;cAAE+C,OAAO,UAAUJ,KAAAA;YAAS;YAAG,KAAKrB,SAAQ;;UACrD;YAAC;YAAQ,CAAC;YAAG;;;MAEjB;IACF;EACF;;;;EAKAhB,OAAO0C,OAA+B;AACpC,UAAMC,iBAAiB3E,WAAUE,KAAKwE,KAAAA;AACtC,QAAI,KAAK7B,OAAOnB,WAAWiD,eAAe9B,OAAOnB,QAAQ;AACvD,aAAO;IACT;AAEA,QAAIkD,QAAQ;AACZ,aAAShD,IAAI,GAAGA,IAAI,KAAKiB,OAAOnB,QAAQE,KAAK;AAC3CgD,gBAAU,KAAK/B,OAAOjB,CAAAA,MAAO+C,eAAe9B,OAAOjB,CAAAA;IACrD;AAEA,WAAOgD;EACT;EAEA,CAACC,YAAAA,EAAcH,OAAqB;AAClC,QAAI,CAAC1E,WAAU8B,YAAY4C,KAAAA,GAAQ;AACjC,aAAO;IACT;AAEA,WAAO,KAAK1C,OAAO0C,KAAAA;EACrB;AACF;",
|
|
6
|
+
"names": ["Buffer", "RFC4648", "RFC4648_HEX", "CROCKFORD", "base32Decode", "Schema", "devtoolsFormatter", "inspectCustom", "assertArgument", "invariant", "Schema", "monotonicFactory", "ObjectIdSchema", "String", "pipe", "pattern", "annotations", "description", "ObjectId", "undefined", "isValid", "id", "decodeSync", "random", "dangerouslyDisableRandomness", "makeTestPRNG", "Date", "getTime", "dangerouslySetSeed", "time", "seed", "rng", "SimplePRNG", "next", "Math", "pow", "reset", "Schema", "invariant", "randomBytes", "length", "webCrypto", "globalThis", "crypto", "require", "webcrypto", "bytes", "Uint8Array", "getRandomValues", "MULTIBASE_PREFIX", "ENCODED_LENGTH", "isValid", "value", "startsWith", "length", "SpaceId", "String", "pipe", "filter", "byteLength", "encode", "invariant", "Uint8Array", "base32Encode", "decode", "base32Decode", "slice", "random", "randomBytes", "LOCAL_SPACE_TAG", "DXN_ECHO_REGEXP", "QueueSubspaceTags", "Object", "freeze", "DATA", "TRACE", "DXN", "Schema", "NonEmptyString", "pipe", "pattern", "annotations", "title", "description", "examples", "hash", "dxn", "toString", "kind", "TYPE", "ECHO", "QUEUE", "equals", "a", "b", "parts", "length", "every", "part", "i", "equalsEchoId", "a1", "asEchoDXN", "b1", "echoId", "isDXNString", "startsWith", "parse", "Error", "prefix", "split", "tryParse", "undefined", "fromTypename", "typename", "fromTypenameAndVersion", "version", "fromSpaceAndObjectId", "spaceId", "objectId", "assertArgument", "SpaceId", "isValid", "ObjectId", "fromLocalObjectId", "id", "fromQueue", "subspaceTag", "queueId", "indexOf", "join", "toJSON", "inspectCustom", "depth", "options", "inspectFn", "printControlCode", "code", "colors", "blueBright", "reset", "devtoolsFormatter", "header", "style", "invariant", "other", "hasTypenameOf", "isLocalObjectId", "asTypeDXN", "type", "asQueueDXN", "extend", "import_base32_decode", "invariant", "IdentityDid", "Object", "freeze", "byteLength", "encode", "value", "invariant", "Uint8Array", "length", "DID_PREFIX", "MULTIBASE_PREFIX", "base32Encode", "decode", "startsWith", "base32Decode", "slice", "isValid", "ENCODED_LENGTH", "random", "randomBytes", "SPACE_ID_LENGTH", "OBJECT_ID_LENGTH", "FQ_ID_LENGTH", "parseId", "id", "length", "spaceId", "objectId", "indexOf", "split", "import_base32_decode", "devtoolsFormatter", "equalsSymbol", "inspectCustom", "truncateKey", "invariant", "PUBLIC_KEY_LENGTH", "SECRET_KEY_LENGTH", "isLikeArrayBuffer", "value", "Object", "getPrototypeOf", "name", "PublicKey", "ZERO", "from", "repeat", "source", "invariant", "Buffer", "Uint8Array", "buffer", "byteOffset", "byteLength", "ArrayBuffer", "fromHex", "asUint8Array", "TypeError", "safeFrom", "undefined", "key", "err", "hex", "startsWith", "slice", "buf", "random", "randomBytes", "randomOfLength", "length", "randomSequence", "i", "Error", "isPublicKey", "assertValidPublicKey", "equals", "left", "right", "bufferize", "str", "stringify", "asBuffer", "toString", "hash", "toHex", "fromMultibase32", "encoded", "base32Decode", "_value", "toJSON", "toJSONL", "truncate", "toMultibase32", "base32Encode", "truncateKey", "getInsecureHash", "modulo", "Math", "abs", "reduce", "acc", "val", "inspectCustom", "depth", "options", "inspectFn", "colors", "process", "stdout", "hasColors", "printControlCode", "code", "color", "reset", "devtoolsFormatter", "header", "style", "other", "otherConverted", "equal", "equalsSymbol"]
|
|
7
7
|
}
|