@dxos/keys 0.8.4-main.a4bbb77 → 0.8.4-main.abd8ff62ef
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/dist/lib/browser/index.mjs +136 -392
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +136 -392
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/dxn.d.ts +6 -6
- package/dist/types/src/dxn.d.ts.map +1 -1
- package/dist/types/src/object-id.d.ts +1 -1
- package/dist/types/src/object-id.d.ts.map +1 -1
- 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/src/space-id.d.ts +2 -2
- package/dist/types/src/space-id.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -9
- package/src/dxn.ts +10 -11
- package/src/object-id.ts +1 -1
- package/src/public-key.ts +2 -3
- package/src/space-id.ts +3 -3
|
@@ -82,82 +82,20 @@ var require_base32_decode = __commonJS({
|
|
|
82
82
|
});
|
|
83
83
|
|
|
84
84
|
// src/dxn.ts
|
|
85
|
-
import
|
|
85
|
+
import * as Schema3 from "effect/Schema";
|
|
86
86
|
import { devtoolsFormatter, inspectCustom } from "@dxos/debug";
|
|
87
87
|
import { assertArgument, invariant as invariant2 } from "@dxos/invariant";
|
|
88
88
|
|
|
89
89
|
// src/object-id.ts
|
|
90
|
-
import
|
|
90
|
+
import * as Schema from "effect/Schema";
|
|
91
91
|
import { monotonicFactory } from "ulidx";
|
|
92
|
-
function _check_private_redeclaration(obj, privateCollection) {
|
|
93
|
-
if (privateCollection.has(obj)) {
|
|
94
|
-
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
function _class_apply_descriptor_get(receiver, descriptor) {
|
|
98
|
-
if (descriptor.get) {
|
|
99
|
-
return descriptor.get.call(receiver);
|
|
100
|
-
}
|
|
101
|
-
return descriptor.value;
|
|
102
|
-
}
|
|
103
|
-
function _class_apply_descriptor_set(receiver, descriptor, value) {
|
|
104
|
-
if (descriptor.set) {
|
|
105
|
-
descriptor.set.call(receiver, value);
|
|
106
|
-
} else {
|
|
107
|
-
if (!descriptor.writable) {
|
|
108
|
-
throw new TypeError("attempted to set read only private field");
|
|
109
|
-
}
|
|
110
|
-
descriptor.value = value;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
function _class_check_private_static_field_descriptor(descriptor, action) {
|
|
114
|
-
if (descriptor === void 0) {
|
|
115
|
-
throw new TypeError("attempted to " + action + " private static field before its declaration");
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
function _class_extract_field_descriptor(receiver, privateMap, action) {
|
|
119
|
-
if (!privateMap.has(receiver)) {
|
|
120
|
-
throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
121
|
-
}
|
|
122
|
-
return privateMap.get(receiver);
|
|
123
|
-
}
|
|
124
|
-
function _class_private_field_get(receiver, privateMap) {
|
|
125
|
-
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
|
|
126
|
-
return _class_apply_descriptor_get(receiver, descriptor);
|
|
127
|
-
}
|
|
128
|
-
function _class_private_field_init(obj, privateMap, value) {
|
|
129
|
-
_check_private_redeclaration(obj, privateMap);
|
|
130
|
-
privateMap.set(obj, value);
|
|
131
|
-
}
|
|
132
|
-
function _class_private_field_set(receiver, privateMap, value) {
|
|
133
|
-
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
|
|
134
|
-
_class_apply_descriptor_set(receiver, descriptor, value);
|
|
135
|
-
return value;
|
|
136
|
-
}
|
|
137
|
-
function _class_static_private_field_spec_get(receiver, classConstructor, descriptor) {
|
|
138
|
-
_class_check_private_static_access(receiver, classConstructor);
|
|
139
|
-
_class_check_private_static_field_descriptor(descriptor, "get");
|
|
140
|
-
return _class_apply_descriptor_get(receiver, descriptor);
|
|
141
|
-
}
|
|
142
|
-
function _class_static_private_field_spec_set(receiver, classConstructor, descriptor, value) {
|
|
143
|
-
_class_check_private_static_access(receiver, classConstructor);
|
|
144
|
-
_class_check_private_static_field_descriptor(descriptor, "set");
|
|
145
|
-
_class_apply_descriptor_set(receiver, descriptor, value);
|
|
146
|
-
return value;
|
|
147
|
-
}
|
|
148
|
-
function _class_check_private_static_access(receiver, classConstructor) {
|
|
149
|
-
if (receiver !== classConstructor) {
|
|
150
|
-
throw new TypeError("Private static access of wrong provenance");
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
var _class;
|
|
154
|
-
var _factory;
|
|
155
|
-
var _seedTime;
|
|
156
92
|
var ObjectIdSchema = Schema.String.pipe(Schema.pattern(/^[0-7][0-9A-HJKMNP-TV-Z]{25}$/i)).annotations({
|
|
157
93
|
description: "A Universally Unique Lexicographically Sortable Identifier",
|
|
158
94
|
pattern: "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
|
|
159
95
|
});
|
|
160
|
-
var ObjectId =
|
|
96
|
+
var ObjectId = class extends ObjectIdSchema {
|
|
97
|
+
static #factory = monotonicFactory();
|
|
98
|
+
static #seedTime = void 0;
|
|
161
99
|
static isValid(id) {
|
|
162
100
|
try {
|
|
163
101
|
Schema.decodeSync(ObjectId)(id);
|
|
@@ -167,65 +105,47 @@ var ObjectId = (_class = class extends ObjectIdSchema {
|
|
|
167
105
|
}
|
|
168
106
|
}
|
|
169
107
|
static random() {
|
|
170
|
-
return
|
|
108
|
+
return this.#factory(this.#seedTime);
|
|
171
109
|
}
|
|
172
110
|
static dangerouslyDisableRandomness() {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
writable: true,
|
|
178
|
-
value: monotonicFactory()
|
|
179
|
-
}, _seedTime = {
|
|
180
|
-
writable: true,
|
|
181
|
-
value: void 0
|
|
182
|
-
}, _class);
|
|
111
|
+
this.#factory = monotonicFactory(makeTestPRNG());
|
|
112
|
+
this.#seedTime = (/* @__PURE__ */ new Date("2025-01-01")).getTime();
|
|
113
|
+
}
|
|
114
|
+
};
|
|
183
115
|
var makeTestPRNG = () => {
|
|
184
116
|
const rng = new SimplePRNG();
|
|
185
117
|
return () => {
|
|
186
118
|
return rng.next();
|
|
187
119
|
};
|
|
188
120
|
};
|
|
189
|
-
var _seed = /* @__PURE__ */ new WeakMap();
|
|
190
121
|
var SimplePRNG = class _SimplePRNG {
|
|
122
|
+
#seed;
|
|
123
|
+
// LCG parameters (from Numerical Recipes)
|
|
124
|
+
static #a = 1664525;
|
|
125
|
+
static #c = 1013904223;
|
|
126
|
+
static #m = Math.pow(2, 32);
|
|
127
|
+
/**
|
|
128
|
+
* Creates a new PRNG instance.
|
|
129
|
+
* @param seed - Initial seed value. If not provided, uses 0.
|
|
130
|
+
*/
|
|
131
|
+
constructor(seed = 0) {
|
|
132
|
+
this.#seed = seed;
|
|
133
|
+
}
|
|
191
134
|
/**
|
|
192
135
|
* Generates the next pseudo-random number in the range [0, 1).
|
|
193
136
|
* @returns A pseudo-random number between 0 (inclusive) and 1 (exclusive).
|
|
194
137
|
*/
|
|
195
138
|
next() {
|
|
196
|
-
|
|
197
|
-
return
|
|
139
|
+
this.#seed = (_SimplePRNG.#a * this.#seed + _SimplePRNG.#c) % _SimplePRNG.#m;
|
|
140
|
+
return this.#seed / _SimplePRNG.#m;
|
|
198
141
|
}
|
|
199
142
|
/**
|
|
200
143
|
* Resets the generator with a new seed.
|
|
201
144
|
* @param seed - New seed value.
|
|
202
145
|
*/
|
|
203
146
|
reset(seed) {
|
|
204
|
-
|
|
147
|
+
this.#seed = seed;
|
|
205
148
|
}
|
|
206
|
-
/**
|
|
207
|
-
* Creates a new PRNG instance.
|
|
208
|
-
* @param seed - Initial seed value. If not provided, uses 0.
|
|
209
|
-
*/
|
|
210
|
-
constructor(seed = 0) {
|
|
211
|
-
_class_private_field_init(this, _seed, {
|
|
212
|
-
writable: true,
|
|
213
|
-
value: void 0
|
|
214
|
-
});
|
|
215
|
-
_class_private_field_set(this, _seed, seed);
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
var _a = {
|
|
219
|
-
writable: true,
|
|
220
|
-
value: 1664525
|
|
221
|
-
};
|
|
222
|
-
var _c = {
|
|
223
|
-
writable: true,
|
|
224
|
-
value: 1013904223
|
|
225
|
-
};
|
|
226
|
-
var _m = {
|
|
227
|
-
writable: true,
|
|
228
|
-
value: Math.pow(2, 32)
|
|
229
149
|
};
|
|
230
150
|
|
|
231
151
|
// src/space-id.ts
|
|
@@ -291,7 +211,7 @@ function base32Encode(data, variant, options) {
|
|
|
291
211
|
}
|
|
292
212
|
|
|
293
213
|
// src/space-id.ts
|
|
294
|
-
import
|
|
214
|
+
import * as Schema2 from "effect/Schema";
|
|
295
215
|
import { invariant } from "@dxos/invariant";
|
|
296
216
|
|
|
297
217
|
// src/random-bytes.ts
|
|
@@ -303,133 +223,78 @@ var randomBytes = (length) => {
|
|
|
303
223
|
};
|
|
304
224
|
|
|
305
225
|
// src/space-id.ts
|
|
306
|
-
function _define_property(obj, key, value) {
|
|
307
|
-
if (key in obj) {
|
|
308
|
-
Object.defineProperty(obj, key, {
|
|
309
|
-
value,
|
|
310
|
-
enumerable: true,
|
|
311
|
-
configurable: true,
|
|
312
|
-
writable: true
|
|
313
|
-
});
|
|
314
|
-
} else {
|
|
315
|
-
obj[key] = value;
|
|
316
|
-
}
|
|
317
|
-
return obj;
|
|
318
|
-
}
|
|
319
|
-
var _Schema_String_pipe;
|
|
320
|
-
var _class2;
|
|
321
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/common/keys/src/space-id.ts";
|
|
322
226
|
var MULTIBASE_PREFIX = "B";
|
|
323
227
|
var ENCODED_LENGTH = 33;
|
|
324
228
|
var isValid = (value) => {
|
|
325
229
|
return typeof value === "string" && value.startsWith(MULTIBASE_PREFIX) && value.length === ENCODED_LENGTH;
|
|
326
230
|
};
|
|
327
|
-
var SpaceId =
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
"value.length === SpaceId.byteLength",
|
|
344
|
-
"'Invalid length'"
|
|
345
|
-
]
|
|
346
|
-
});
|
|
347
|
-
return MULTIBASE_PREFIX + base32Encode(value, "RFC4648");
|
|
348
|
-
}), _define_property(_class2, "decode", (value) => {
|
|
349
|
-
invariant(value.startsWith(MULTIBASE_PREFIX), "Invalid multibase32 encoding", {
|
|
350
|
-
F: __dxlog_file,
|
|
351
|
-
L: 49,
|
|
352
|
-
S: _class2,
|
|
353
|
-
A: [
|
|
354
|
-
"value.startsWith(MULTIBASE_PREFIX)",
|
|
355
|
-
"'Invalid multibase32 encoding'"
|
|
356
|
-
]
|
|
357
|
-
});
|
|
358
|
-
return new Uint8Array((0, import_base32_decode.default)(value.slice(1), "RFC4648"));
|
|
359
|
-
}), _define_property(_class2, "isValid", isValid), _define_property(_class2, "random", () => {
|
|
360
|
-
return SpaceId.encode(randomBytes(SpaceId.byteLength));
|
|
361
|
-
}), _class2);
|
|
231
|
+
var SpaceId = class extends Schema2.String.pipe(Schema2.filter(isValid)) {
|
|
232
|
+
static byteLength = 20;
|
|
233
|
+
static encode = (value) => {
|
|
234
|
+
invariant(value instanceof Uint8Array, "Invalid type");
|
|
235
|
+
invariant(value.length === SpaceId.byteLength, "Invalid length");
|
|
236
|
+
return MULTIBASE_PREFIX + base32Encode(value, "RFC4648");
|
|
237
|
+
};
|
|
238
|
+
static decode = (value) => {
|
|
239
|
+
invariant(value.startsWith(MULTIBASE_PREFIX), "Invalid multibase32 encoding");
|
|
240
|
+
return new Uint8Array((0, import_base32_decode.default)(value.slice(1), "RFC4648"));
|
|
241
|
+
};
|
|
242
|
+
static isValid = isValid;
|
|
243
|
+
static random = () => {
|
|
244
|
+
return SpaceId.encode(randomBytes(SpaceId.byteLength));
|
|
245
|
+
};
|
|
246
|
+
};
|
|
362
247
|
|
|
363
248
|
// src/dxn.ts
|
|
364
|
-
function _check_private_redeclaration2(obj, privateCollection) {
|
|
365
|
-
if (privateCollection.has(obj)) {
|
|
366
|
-
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
function _class_apply_descriptor_get2(receiver, descriptor) {
|
|
370
|
-
if (descriptor.get) {
|
|
371
|
-
return descriptor.get.call(receiver);
|
|
372
|
-
}
|
|
373
|
-
return descriptor.value;
|
|
374
|
-
}
|
|
375
|
-
function _class_apply_descriptor_set2(receiver, descriptor, value) {
|
|
376
|
-
if (descriptor.set) {
|
|
377
|
-
descriptor.set.call(receiver, value);
|
|
378
|
-
} else {
|
|
379
|
-
if (!descriptor.writable) {
|
|
380
|
-
throw new TypeError("attempted to set read only private field");
|
|
381
|
-
}
|
|
382
|
-
descriptor.value = value;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
function _class_extract_field_descriptor2(receiver, privateMap, action) {
|
|
386
|
-
if (!privateMap.has(receiver)) {
|
|
387
|
-
throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
388
|
-
}
|
|
389
|
-
return privateMap.get(receiver);
|
|
390
|
-
}
|
|
391
|
-
function _class_private_field_get2(receiver, privateMap) {
|
|
392
|
-
var descriptor = _class_extract_field_descriptor2(receiver, privateMap, "get");
|
|
393
|
-
return _class_apply_descriptor_get2(receiver, descriptor);
|
|
394
|
-
}
|
|
395
|
-
function _class_private_field_init2(obj, privateMap, value) {
|
|
396
|
-
_check_private_redeclaration2(obj, privateMap);
|
|
397
|
-
privateMap.set(obj, value);
|
|
398
|
-
}
|
|
399
|
-
function _class_private_field_set2(receiver, privateMap, value) {
|
|
400
|
-
var descriptor = _class_extract_field_descriptor2(receiver, privateMap, "set");
|
|
401
|
-
_class_apply_descriptor_set2(receiver, descriptor, value);
|
|
402
|
-
return value;
|
|
403
|
-
}
|
|
404
|
-
function _define_property2(obj, key, value) {
|
|
405
|
-
if (key in obj) {
|
|
406
|
-
Object.defineProperty(obj, key, {
|
|
407
|
-
value,
|
|
408
|
-
enumerable: true,
|
|
409
|
-
configurable: true,
|
|
410
|
-
writable: true
|
|
411
|
-
});
|
|
412
|
-
} else {
|
|
413
|
-
obj[key] = value;
|
|
414
|
-
}
|
|
415
|
-
return obj;
|
|
416
|
-
}
|
|
417
|
-
var __dxlog_file2 = "/__w/dxos/dxos/packages/common/keys/src/dxn.ts";
|
|
418
249
|
var LOCAL_SPACE_TAG = "@";
|
|
419
250
|
var DXN_ECHO_REGEXP = /@(dxn:[a-zA-Z0-p:@]+)/;
|
|
420
251
|
var QueueSubspaceTags = Object.freeze({
|
|
421
252
|
DATA: "data",
|
|
422
253
|
TRACE: "trace"
|
|
423
254
|
});
|
|
424
|
-
var _kind = /* @__PURE__ */ new WeakMap();
|
|
425
|
-
var _parts = /* @__PURE__ */ new WeakMap();
|
|
426
|
-
var _inspectCustom = inspectCustom;
|
|
427
|
-
var _devtoolsFormatter = devtoolsFormatter;
|
|
428
255
|
var DXN = class _DXN {
|
|
256
|
+
// TODO(burdon): Rename to DXN (i.e., DXN.DXN).
|
|
257
|
+
// TODO(dmaretskyi): Should this be a transformation into the DXN type?
|
|
258
|
+
static Schema = Schema3.NonEmptyString.pipe(
|
|
259
|
+
Schema3.pattern(/^dxn:([^:]+):(?:[^:]+:?)+[^:]$/),
|
|
260
|
+
// TODO(dmaretskyi): To set the format we need to move the annotation IDs out of the echo-schema package.
|
|
261
|
+
// FormatAnnotation.set(TypeFormat.DXN),
|
|
262
|
+
Schema3.annotations({
|
|
263
|
+
title: "DXN",
|
|
264
|
+
description: "DXN URI",
|
|
265
|
+
examples: [
|
|
266
|
+
"dxn:type:com.example.type.my-type",
|
|
267
|
+
"dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6"
|
|
268
|
+
]
|
|
269
|
+
})
|
|
270
|
+
);
|
|
429
271
|
static hash(dxn) {
|
|
430
272
|
return dxn.toString();
|
|
431
273
|
}
|
|
432
274
|
/**
|
|
275
|
+
* Kind constants.
|
|
276
|
+
*/
|
|
277
|
+
static kind = Object.freeze({
|
|
278
|
+
/**
|
|
279
|
+
* dxn:type:<type_name>[:<version>]
|
|
280
|
+
*/
|
|
281
|
+
TYPE: "type",
|
|
282
|
+
/**
|
|
283
|
+
* dxn:echo:<space_id>:<echo_id>
|
|
284
|
+
* dxn:echo:@:<echo_id>
|
|
285
|
+
*/
|
|
286
|
+
// TODO(burdon): Rename to OBJECT? (BREAKING CHANGE to update "echo").
|
|
287
|
+
// TODO(burdon): Add separate Kind for space?
|
|
288
|
+
ECHO: "echo",
|
|
289
|
+
/**
|
|
290
|
+
* The subspace tag enables us to partition queues by usage within the context of a space.
|
|
291
|
+
* dxn:queue:<subspace_tag>:<space_id>:<queue_id>[:object_id]
|
|
292
|
+
* dxn:queue:data:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
|
|
293
|
+
* dxn:queue:trace:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
|
|
294
|
+
*/
|
|
295
|
+
QUEUE: "queue"
|
|
296
|
+
});
|
|
297
|
+
/**
|
|
433
298
|
* Exactly equals.
|
|
434
299
|
*/
|
|
435
300
|
static equals(a, b) {
|
|
@@ -468,7 +333,7 @@ var DXN = class _DXN {
|
|
|
468
333
|
}
|
|
469
334
|
}
|
|
470
335
|
/**
|
|
471
|
-
* @example `dxn:type:example.
|
|
336
|
+
* @example `dxn:type:com.example.type.person`
|
|
472
337
|
*/
|
|
473
338
|
static fromTypename(typename) {
|
|
474
339
|
return new _DXN(_DXN.kind.TYPE, [
|
|
@@ -476,7 +341,7 @@ var DXN = class _DXN {
|
|
|
476
341
|
]);
|
|
477
342
|
}
|
|
478
343
|
/**
|
|
479
|
-
* @example `dxn:type:example.
|
|
344
|
+
* @example `dxn:type:com.example.type.person:0.1.0`
|
|
480
345
|
*/
|
|
481
346
|
// TODO(dmaretskyi): Consider using @ as the version separator.
|
|
482
347
|
static fromTypenameAndVersion(typename, version) {
|
|
@@ -519,8 +384,28 @@ var DXN = class _DXN {
|
|
|
519
384
|
] : []
|
|
520
385
|
]);
|
|
521
386
|
}
|
|
387
|
+
#kind;
|
|
388
|
+
#parts;
|
|
389
|
+
constructor(kind, parts) {
|
|
390
|
+
assertArgument(parts.length > 0, "parts", `Invalid DXN: ${parts}`);
|
|
391
|
+
assertArgument(parts.every((part) => typeof part === "string" && part.length > 0 && part.indexOf(":") === -1), "parts", `Invalid DXN: ${parts}`);
|
|
392
|
+
switch (kind) {
|
|
393
|
+
case _DXN.kind.TYPE:
|
|
394
|
+
if (parts.length > 2) {
|
|
395
|
+
throw new Error("Invalid DXN.kind.TYPE");
|
|
396
|
+
}
|
|
397
|
+
break;
|
|
398
|
+
case _DXN.kind.ECHO:
|
|
399
|
+
if (parts.length !== 2) {
|
|
400
|
+
throw new Error("Invalid DXN.kind.ECHO");
|
|
401
|
+
}
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
404
|
+
this.#kind = kind;
|
|
405
|
+
this.#parts = parts;
|
|
406
|
+
}
|
|
522
407
|
toString() {
|
|
523
|
-
return `dxn:${
|
|
408
|
+
return `dxn:${this.#kind}:${this.#parts.join(":")}`;
|
|
524
409
|
}
|
|
525
410
|
toJSON() {
|
|
526
411
|
return this.toString();
|
|
@@ -528,13 +413,13 @@ var DXN = class _DXN {
|
|
|
528
413
|
/**
|
|
529
414
|
* Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
|
|
530
415
|
*/
|
|
531
|
-
[
|
|
416
|
+
[inspectCustom](depth, options, inspectFn) {
|
|
532
417
|
const printControlCode = (code) => {
|
|
533
418
|
return `\x1B[${code}m`;
|
|
534
419
|
};
|
|
535
420
|
return printControlCode(inspectFn.colors.blueBright[0]) + this.toString() + printControlCode(inspectFn.colors.reset[0]);
|
|
536
421
|
}
|
|
537
|
-
get [
|
|
422
|
+
get [devtoolsFormatter]() {
|
|
538
423
|
return {
|
|
539
424
|
header: () => {
|
|
540
425
|
return [
|
|
@@ -548,38 +433,30 @@ var DXN = class _DXN {
|
|
|
548
433
|
};
|
|
549
434
|
}
|
|
550
435
|
get kind() {
|
|
551
|
-
return
|
|
436
|
+
return this.#kind;
|
|
552
437
|
}
|
|
553
438
|
get parts() {
|
|
554
|
-
return
|
|
439
|
+
return this.#parts;
|
|
555
440
|
}
|
|
556
441
|
// TODO(burdon): Should getters fail?
|
|
557
442
|
get typename() {
|
|
558
|
-
invariant2(
|
|
559
|
-
|
|
560
|
-
L: 250,
|
|
561
|
-
S: this,
|
|
562
|
-
A: [
|
|
563
|
-
"this.#kind === DXN.kind.TYPE",
|
|
564
|
-
""
|
|
565
|
-
]
|
|
566
|
-
});
|
|
567
|
-
return _class_private_field_get2(this, _parts)[0];
|
|
443
|
+
invariant2(this.#kind === _DXN.kind.TYPE);
|
|
444
|
+
return this.#parts[0];
|
|
568
445
|
}
|
|
569
446
|
equals(other) {
|
|
570
447
|
return _DXN.equals(this, other);
|
|
571
448
|
}
|
|
572
449
|
hasTypenameOf(typename) {
|
|
573
|
-
return
|
|
450
|
+
return this.#kind === _DXN.kind.TYPE && this.#parts.length === 1 && this.#parts[0] === typename;
|
|
574
451
|
}
|
|
575
452
|
isLocalObjectId() {
|
|
576
|
-
return
|
|
453
|
+
return this.#kind === _DXN.kind.ECHO && this.#parts[0] === LOCAL_SPACE_TAG && this.#parts.length === 2;
|
|
577
454
|
}
|
|
578
455
|
asTypeDXN() {
|
|
579
456
|
if (this.kind !== _DXN.kind.TYPE) {
|
|
580
457
|
return void 0;
|
|
581
458
|
}
|
|
582
|
-
const [type, version] =
|
|
459
|
+
const [type, version] = this.#parts;
|
|
583
460
|
return {
|
|
584
461
|
// TODO(wittjosiah): Should be `typename` for consistency.
|
|
585
462
|
type,
|
|
@@ -590,7 +467,7 @@ var DXN = class _DXN {
|
|
|
590
467
|
if (this.kind !== _DXN.kind.ECHO) {
|
|
591
468
|
return void 0;
|
|
592
469
|
}
|
|
593
|
-
const [spaceId, echoId] =
|
|
470
|
+
const [spaceId, echoId] = this.#parts;
|
|
594
471
|
return {
|
|
595
472
|
spaceId: spaceId === LOCAL_SPACE_TAG ? void 0 : spaceId,
|
|
596
473
|
// TODO(burdon): objectId.
|
|
@@ -601,7 +478,7 @@ var DXN = class _DXN {
|
|
|
601
478
|
if (this.kind !== _DXN.kind.QUEUE) {
|
|
602
479
|
return void 0;
|
|
603
480
|
}
|
|
604
|
-
const [subspaceTag, spaceId, queueId, objectId] =
|
|
481
|
+
const [subspaceTag, spaceId, queueId, objectId] = this.#parts;
|
|
605
482
|
if (typeof queueId !== "string") {
|
|
606
483
|
return void 0;
|
|
607
484
|
}
|
|
@@ -616,109 +493,25 @@ var DXN = class _DXN {
|
|
|
616
493
|
* Produces a new DXN with the given parts appended.
|
|
617
494
|
*/
|
|
618
495
|
extend(parts) {
|
|
619
|
-
return new _DXN(
|
|
620
|
-
...
|
|
496
|
+
return new _DXN(this.#kind, [
|
|
497
|
+
...this.#parts,
|
|
621
498
|
...parts
|
|
622
499
|
]);
|
|
623
500
|
}
|
|
624
|
-
constructor(kind, parts) {
|
|
625
|
-
_class_private_field_init2(this, _kind, {
|
|
626
|
-
writable: true,
|
|
627
|
-
value: void 0
|
|
628
|
-
});
|
|
629
|
-
_class_private_field_init2(this, _parts, {
|
|
630
|
-
writable: true,
|
|
631
|
-
value: void 0
|
|
632
|
-
});
|
|
633
|
-
assertArgument(parts.length > 0, "parts", `Invalid DXN: ${parts}`);
|
|
634
|
-
assertArgument(parts.every((part) => typeof part === "string" && part.length > 0 && part.indexOf(":") === -1), "parts", `Invalid DXN: ${parts}`);
|
|
635
|
-
switch (kind) {
|
|
636
|
-
case _DXN.kind.TYPE:
|
|
637
|
-
if (parts.length > 2) {
|
|
638
|
-
throw new Error("Invalid DXN.kind.TYPE");
|
|
639
|
-
}
|
|
640
|
-
break;
|
|
641
|
-
case _DXN.kind.ECHO:
|
|
642
|
-
if (parts.length !== 2) {
|
|
643
|
-
throw new Error("Invalid DXN.kind.ECHO");
|
|
644
|
-
}
|
|
645
|
-
break;
|
|
646
|
-
}
|
|
647
|
-
_class_private_field_set2(this, _kind, kind);
|
|
648
|
-
_class_private_field_set2(this, _parts, parts);
|
|
649
|
-
}
|
|
650
501
|
};
|
|
651
|
-
_define_property2(DXN, "Schema", Schema3.NonEmptyString.pipe(
|
|
652
|
-
Schema3.pattern(/^dxn:([^:]+):(?:[^:]+:?)+[^:]$/),
|
|
653
|
-
// TODO(dmaretskyi): To set the format we need to move the annotation IDs out of the echo-schema package.
|
|
654
|
-
// FormatAnnotation.set(FormatEnum.DXN),
|
|
655
|
-
Schema3.annotations({
|
|
656
|
-
title: "DXN",
|
|
657
|
-
description: "DXN URI",
|
|
658
|
-
examples: [
|
|
659
|
-
"dxn:type:example.com/type/MyType",
|
|
660
|
-
"dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6"
|
|
661
|
-
]
|
|
662
|
-
})
|
|
663
|
-
));
|
|
664
|
-
_define_property2(DXN, "kind", Object.freeze({
|
|
665
|
-
/**
|
|
666
|
-
* dxn:type:<type_name>[:<version>]
|
|
667
|
-
*/
|
|
668
|
-
TYPE: "type",
|
|
669
|
-
/**
|
|
670
|
-
* dxn:echo:<space_id>:<echo_id>
|
|
671
|
-
* dxn:echo:@:<echo_id>
|
|
672
|
-
*/
|
|
673
|
-
// TODO(burdon): Rename to OBJECT? (BREAKING CHANGE to update "echo").
|
|
674
|
-
// TODO(burdon): Add separate Kind for space?
|
|
675
|
-
ECHO: "echo",
|
|
676
|
-
/**
|
|
677
|
-
* The subspace tag enables us to partition queues by usage within the context of a space.
|
|
678
|
-
* dxn:queue:<subspace_tag>:<space_id>:<queue_id>[:object_id]
|
|
679
|
-
* dxn:queue:data:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
|
|
680
|
-
* dxn:queue:trace:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
|
|
681
|
-
*/
|
|
682
|
-
QUEUE: "queue"
|
|
683
|
-
}));
|
|
684
502
|
|
|
685
503
|
// src/identity-did.ts
|
|
686
504
|
var import_base32_decode2 = __toESM(require_base32_decode(), 1);
|
|
687
505
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
688
|
-
var __dxlog_file3 = "/__w/dxos/dxos/packages/common/keys/src/identity-did.ts";
|
|
689
506
|
var IdentityDid = Object.freeze({
|
|
690
507
|
byteLength: 20,
|
|
691
508
|
encode: (value) => {
|
|
692
|
-
invariant3(value instanceof Uint8Array, "Invalid type"
|
|
693
|
-
|
|
694
|
-
L: 22,
|
|
695
|
-
S: void 0,
|
|
696
|
-
A: [
|
|
697
|
-
"value instanceof Uint8Array",
|
|
698
|
-
"'Invalid type'"
|
|
699
|
-
]
|
|
700
|
-
});
|
|
701
|
-
invariant3(value.length === IdentityDid.byteLength, "Invalid length", {
|
|
702
|
-
F: __dxlog_file3,
|
|
703
|
-
L: 23,
|
|
704
|
-
S: void 0,
|
|
705
|
-
A: [
|
|
706
|
-
"value.length === IdentityDid.byteLength",
|
|
707
|
-
"'Invalid length'"
|
|
708
|
-
]
|
|
709
|
-
});
|
|
509
|
+
invariant3(value instanceof Uint8Array, "Invalid type");
|
|
510
|
+
invariant3(value.length === IdentityDid.byteLength, "Invalid length");
|
|
710
511
|
return DID_PREFIX + MULTIBASE_PREFIX2 + base32Encode(value, "RFC4648");
|
|
711
512
|
},
|
|
712
513
|
decode: (value) => {
|
|
713
|
-
invariant3(value.startsWith(DID_PREFIX + MULTIBASE_PREFIX2), "Invalid multibase32 encoding"
|
|
714
|
-
F: __dxlog_file3,
|
|
715
|
-
L: 28,
|
|
716
|
-
S: void 0,
|
|
717
|
-
A: [
|
|
718
|
-
"value.startsWith(DID_PREFIX + MULTIBASE_PREFIX)",
|
|
719
|
-
"'Invalid multibase32 encoding'"
|
|
720
|
-
]
|
|
721
|
-
});
|
|
514
|
+
invariant3(value.startsWith(DID_PREFIX + MULTIBASE_PREFIX2), "Invalid multibase32 encoding");
|
|
722
515
|
return new Uint8Array((0, import_base32_decode2.default)(value.slice(10), "RFC4648"));
|
|
723
516
|
},
|
|
724
517
|
isValid: (value) => {
|
|
@@ -736,42 +529,19 @@ var ENCODED_LENGTH2 = 42;
|
|
|
736
529
|
var import_base32_decode3 = __toESM(require_base32_decode(), 1);
|
|
737
530
|
import { devtoolsFormatter as devtoolsFormatter2, equalsSymbol, inspectCustom as inspectCustom2, truncateKey } from "@dxos/debug";
|
|
738
531
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
739
|
-
function _define_property3(obj, key, value) {
|
|
740
|
-
if (key in obj) {
|
|
741
|
-
Object.defineProperty(obj, key, {
|
|
742
|
-
value,
|
|
743
|
-
enumerable: true,
|
|
744
|
-
configurable: true,
|
|
745
|
-
writable: true
|
|
746
|
-
});
|
|
747
|
-
} else {
|
|
748
|
-
obj[key] = value;
|
|
749
|
-
}
|
|
750
|
-
return obj;
|
|
751
|
-
}
|
|
752
|
-
var __dxlog_file4 = "/__w/dxos/dxos/packages/common/keys/src/public-key.ts";
|
|
753
532
|
var PUBLIC_KEY_LENGTH = 32;
|
|
754
533
|
var SECRET_KEY_LENGTH = 64;
|
|
755
534
|
var isLikeArrayBuffer = (value) => typeof value === "object" && value !== null && Object.getPrototypeOf(value).constructor.name === "ArrayBuffer";
|
|
756
|
-
var _inspectCustom2 = inspectCustom2;
|
|
757
|
-
var _devtoolsFormatter2 = devtoolsFormatter2;
|
|
758
|
-
var _equalsSymbol = equalsSymbol;
|
|
759
535
|
var PublicKey = class _PublicKey {
|
|
536
|
+
_value;
|
|
537
|
+
static ZERO = _PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH));
|
|
760
538
|
/**
|
|
761
539
|
* Creates new instance of PublicKey automatically determining the input format.
|
|
762
540
|
* @param source A Buffer, or Uint8Array, or hex encoded string, or something with an `asUint8Array` method on it
|
|
763
541
|
* @returns PublicKey
|
|
764
542
|
*/
|
|
765
543
|
static from(source) {
|
|
766
|
-
invariant4(source
|
|
767
|
-
F: __dxlog_file4,
|
|
768
|
-
L: 50,
|
|
769
|
-
S: this,
|
|
770
|
-
A: [
|
|
771
|
-
"source",
|
|
772
|
-
""
|
|
773
|
-
]
|
|
774
|
-
});
|
|
544
|
+
invariant4(source);
|
|
775
545
|
if (source instanceof _PublicKey) {
|
|
776
546
|
return source;
|
|
777
547
|
} else if (source instanceof Buffer) {
|
|
@@ -855,15 +625,7 @@ var PublicKey = class _PublicKey {
|
|
|
855
625
|
* @deprecated All keys should be represented as instances of PublicKey.
|
|
856
626
|
*/
|
|
857
627
|
static bufferize(str) {
|
|
858
|
-
invariant4(typeof str === "string", "Invalid type"
|
|
859
|
-
F: __dxlog_file4,
|
|
860
|
-
L: 153,
|
|
861
|
-
S: this,
|
|
862
|
-
A: [
|
|
863
|
-
"typeof str === 'string'",
|
|
864
|
-
"'Invalid type'"
|
|
865
|
-
]
|
|
866
|
-
});
|
|
628
|
+
invariant4(typeof str === "string", "Invalid type");
|
|
867
629
|
const buffer = Buffer.from(str, "hex");
|
|
868
630
|
return buffer;
|
|
869
631
|
}
|
|
@@ -878,15 +640,7 @@ var PublicKey = class _PublicKey {
|
|
|
878
640
|
} else if (key instanceof Uint8Array) {
|
|
879
641
|
key = Buffer.from(key.buffer, key.byteOffset, key.byteLength);
|
|
880
642
|
}
|
|
881
|
-
invariant4(key instanceof Buffer, "Invalid type"
|
|
882
|
-
F: __dxlog_file4,
|
|
883
|
-
L: 172,
|
|
884
|
-
S: this,
|
|
885
|
-
A: [
|
|
886
|
-
"key instanceof Buffer",
|
|
887
|
-
"'Invalid type'"
|
|
888
|
-
]
|
|
889
|
-
});
|
|
643
|
+
invariant4(key instanceof Buffer, "Invalid type");
|
|
890
644
|
return key.toString("hex");
|
|
891
645
|
}
|
|
892
646
|
/**
|
|
@@ -897,17 +651,15 @@ var PublicKey = class _PublicKey {
|
|
|
897
651
|
return key.toHex();
|
|
898
652
|
}
|
|
899
653
|
static fromMultibase32(encoded) {
|
|
900
|
-
invariant4(encoded.startsWith("B"), "Invalid multibase32 encoding"
|
|
901
|
-
F: __dxlog_file4,
|
|
902
|
-
L: 185,
|
|
903
|
-
S: this,
|
|
904
|
-
A: [
|
|
905
|
-
"encoded.startsWith('B')",
|
|
906
|
-
"'Invalid multibase32 encoding'"
|
|
907
|
-
]
|
|
908
|
-
});
|
|
654
|
+
invariant4(encoded.startsWith("B"), "Invalid multibase32 encoding");
|
|
909
655
|
return new _PublicKey(new Uint8Array((0, import_base32_decode3.default)(encoded.slice(1), "RFC4648")));
|
|
910
656
|
}
|
|
657
|
+
constructor(_value) {
|
|
658
|
+
this._value = _value;
|
|
659
|
+
if (!(_value instanceof Uint8Array)) {
|
|
660
|
+
throw new TypeError(`Expected Uint8Array, got: ${_value}`);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
911
663
|
toString() {
|
|
912
664
|
return this.toHex();
|
|
913
665
|
}
|
|
@@ -926,7 +678,7 @@ var PublicKey = class _PublicKey {
|
|
|
926
678
|
toMultibase32() {
|
|
927
679
|
return "B" + base32Encode(this._value, "RFC4648");
|
|
928
680
|
}
|
|
929
|
-
truncate(length
|
|
681
|
+
truncate(length) {
|
|
930
682
|
return truncateKey(this, length);
|
|
931
683
|
}
|
|
932
684
|
asBuffer() {
|
|
@@ -941,7 +693,7 @@ var PublicKey = class _PublicKey {
|
|
|
941
693
|
/**
|
|
942
694
|
* Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
|
|
943
695
|
*/
|
|
944
|
-
[
|
|
696
|
+
[inspectCustom2](depth, options, inspectFn) {
|
|
945
697
|
if (!options.colors || typeof process.stdout.hasColors !== "function" || !process.stdout.hasColors()) {
|
|
946
698
|
return `<PublicKey ${this.truncate()}>`;
|
|
947
699
|
}
|
|
@@ -966,7 +718,7 @@ var PublicKey = class _PublicKey {
|
|
|
966
718
|
const color = colors[this.getInsecureHash(colors.length)];
|
|
967
719
|
return `PublicKey(${printControlCode(inspectFn.colors[color][0])}${this.truncate()}${printControlCode(inspectFn.colors.reset[0])})`;
|
|
968
720
|
}
|
|
969
|
-
get [
|
|
721
|
+
get [devtoolsFormatter2]() {
|
|
970
722
|
return {
|
|
971
723
|
header: () => {
|
|
972
724
|
const colors = [
|
|
@@ -1019,25 +771,17 @@ var PublicKey = class _PublicKey {
|
|
|
1019
771
|
}
|
|
1020
772
|
let equal = true;
|
|
1021
773
|
for (let i = 0; i < this._value.length; i++) {
|
|
1022
|
-
equal
|
|
774
|
+
equal &&= this._value[i] === otherConverted._value[i];
|
|
1023
775
|
}
|
|
1024
776
|
return equal;
|
|
1025
777
|
}
|
|
1026
|
-
[
|
|
778
|
+
[equalsSymbol](other) {
|
|
1027
779
|
if (!_PublicKey.isPublicKey(other)) {
|
|
1028
780
|
return false;
|
|
1029
781
|
}
|
|
1030
782
|
return this.equals(other);
|
|
1031
783
|
}
|
|
1032
|
-
constructor(_value) {
|
|
1033
|
-
_define_property3(this, "_value", void 0);
|
|
1034
|
-
this._value = _value;
|
|
1035
|
-
if (!(_value instanceof Uint8Array)) {
|
|
1036
|
-
throw new TypeError(`Expected Uint8Array, got: ${_value}`);
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
784
|
};
|
|
1040
|
-
_define_property3(PublicKey, "ZERO", PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH)));
|
|
1041
785
|
export {
|
|
1042
786
|
DXN,
|
|
1043
787
|
DXN_ECHO_REGEXP,
|