@dxos/keys 0.8.4-main.3f58842 → 0.8.4-main.406dc2a
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 +380 -194
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +380 -194
- 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 +30 -13
- package/dist/types/src/dxn.d.ts.map +1 -1
- package/dist/types/src/object-id.d.ts +50 -1
- package/dist/types/src/object-id.d.ts.map +1 -1
- package/dist/types/src/prng.d.ts +32 -0
- package/dist/types/src/prng.d.ts.map +1 -0
- package/dist/types/src/public-key.d.ts +2 -2
- package/dist/types/src/public-key.d.ts.map +1 -1
- package/dist/types/src/space-id.d.ts +1 -1
- package/dist/types/src/space-id.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -10
- package/src/dxn.ts +73 -53
- package/src/object-id.ts +94 -5
- package/src/prng.ts +54 -0
- package/src/public-key.ts +4 -3
- package/src/space-id.ts +1 -1
|
@@ -100,30 +100,151 @@ init_inject_globals();
|
|
|
100
100
|
|
|
101
101
|
// src/dxn.ts
|
|
102
102
|
init_inject_globals();
|
|
103
|
-
import
|
|
103
|
+
import * as Schema3 from "effect/Schema";
|
|
104
104
|
import { devtoolsFormatter, inspectCustom } from "@dxos/debug";
|
|
105
105
|
import { assertArgument, invariant as invariant2 } from "@dxos/invariant";
|
|
106
106
|
|
|
107
107
|
// src/object-id.ts
|
|
108
108
|
init_inject_globals();
|
|
109
|
-
import
|
|
110
|
-
import {
|
|
109
|
+
import * as Schema from "effect/Schema";
|
|
110
|
+
import { monotonicFactory } from "ulidx";
|
|
111
|
+
function _check_private_redeclaration(obj, privateCollection) {
|
|
112
|
+
if (privateCollection.has(obj)) {
|
|
113
|
+
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function _class_apply_descriptor_get(receiver, descriptor) {
|
|
117
|
+
if (descriptor.get) {
|
|
118
|
+
return descriptor.get.call(receiver);
|
|
119
|
+
}
|
|
120
|
+
return descriptor.value;
|
|
121
|
+
}
|
|
122
|
+
function _class_apply_descriptor_set(receiver, descriptor, value) {
|
|
123
|
+
if (descriptor.set) {
|
|
124
|
+
descriptor.set.call(receiver, value);
|
|
125
|
+
} else {
|
|
126
|
+
if (!descriptor.writable) {
|
|
127
|
+
throw new TypeError("attempted to set read only private field");
|
|
128
|
+
}
|
|
129
|
+
descriptor.value = value;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function _class_check_private_static_field_descriptor(descriptor, action) {
|
|
133
|
+
if (descriptor === void 0) {
|
|
134
|
+
throw new TypeError("attempted to " + action + " private static field before its declaration");
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function _class_extract_field_descriptor(receiver, privateMap, action) {
|
|
138
|
+
if (!privateMap.has(receiver)) {
|
|
139
|
+
throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
140
|
+
}
|
|
141
|
+
return privateMap.get(receiver);
|
|
142
|
+
}
|
|
143
|
+
function _class_private_field_get(receiver, privateMap) {
|
|
144
|
+
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
|
|
145
|
+
return _class_apply_descriptor_get(receiver, descriptor);
|
|
146
|
+
}
|
|
147
|
+
function _class_private_field_init(obj, privateMap, value) {
|
|
148
|
+
_check_private_redeclaration(obj, privateMap);
|
|
149
|
+
privateMap.set(obj, value);
|
|
150
|
+
}
|
|
151
|
+
function _class_private_field_set(receiver, privateMap, value) {
|
|
152
|
+
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
|
|
153
|
+
_class_apply_descriptor_set(receiver, descriptor, value);
|
|
154
|
+
return value;
|
|
155
|
+
}
|
|
156
|
+
function _class_static_private_field_spec_get(receiver, classConstructor, descriptor) {
|
|
157
|
+
_class_check_private_static_access(receiver, classConstructor);
|
|
158
|
+
_class_check_private_static_field_descriptor(descriptor, "get");
|
|
159
|
+
return _class_apply_descriptor_get(receiver, descriptor);
|
|
160
|
+
}
|
|
161
|
+
function _class_static_private_field_spec_set(receiver, classConstructor, descriptor, value) {
|
|
162
|
+
_class_check_private_static_access(receiver, classConstructor);
|
|
163
|
+
_class_check_private_static_field_descriptor(descriptor, "set");
|
|
164
|
+
_class_apply_descriptor_set(receiver, descriptor, value);
|
|
165
|
+
return value;
|
|
166
|
+
}
|
|
167
|
+
function _class_check_private_static_access(receiver, classConstructor) {
|
|
168
|
+
if (receiver !== classConstructor) {
|
|
169
|
+
throw new TypeError("Private static access of wrong provenance");
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
var _class;
|
|
173
|
+
var _factory;
|
|
174
|
+
var _seedTime;
|
|
111
175
|
var ObjectIdSchema = Schema.String.pipe(Schema.pattern(/^[0-7][0-9A-HJKMNP-TV-Z]{25}$/i)).annotations({
|
|
112
|
-
description: "
|
|
176
|
+
description: "A Universally Unique Lexicographically Sortable Identifier",
|
|
113
177
|
pattern: "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
|
|
114
178
|
});
|
|
115
|
-
var ObjectId = class extends ObjectIdSchema {
|
|
179
|
+
var ObjectId = (_class = class extends ObjectIdSchema {
|
|
116
180
|
static isValid(id) {
|
|
117
181
|
try {
|
|
118
182
|
Schema.decodeSync(ObjectId)(id);
|
|
119
183
|
return true;
|
|
120
|
-
} catch
|
|
184
|
+
} catch {
|
|
121
185
|
return false;
|
|
122
186
|
}
|
|
123
187
|
}
|
|
124
188
|
static random() {
|
|
125
|
-
return
|
|
189
|
+
return _class_static_private_field_spec_get(this, _class, _factory).call(_class, _class_static_private_field_spec_get(this, _class, _seedTime));
|
|
190
|
+
}
|
|
191
|
+
static dangerouslyDisableRandomness() {
|
|
192
|
+
_class_static_private_field_spec_set(this, _class, _factory, monotonicFactory(makeTestPRNG()));
|
|
193
|
+
_class_static_private_field_spec_set(this, _class, _seedTime, (/* @__PURE__ */ new Date("2025-01-01")).getTime());
|
|
194
|
+
}
|
|
195
|
+
}, _factory = {
|
|
196
|
+
writable: true,
|
|
197
|
+
value: monotonicFactory()
|
|
198
|
+
}, _seedTime = {
|
|
199
|
+
writable: true,
|
|
200
|
+
value: void 0
|
|
201
|
+
}, _class);
|
|
202
|
+
var makeTestPRNG = () => {
|
|
203
|
+
const rng = new SimplePRNG();
|
|
204
|
+
return () => {
|
|
205
|
+
return rng.next();
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
var _seed = /* @__PURE__ */ new WeakMap();
|
|
209
|
+
var SimplePRNG = class _SimplePRNG {
|
|
210
|
+
/**
|
|
211
|
+
* Generates the next pseudo-random number in the range [0, 1).
|
|
212
|
+
* @returns A pseudo-random number between 0 (inclusive) and 1 (exclusive).
|
|
213
|
+
*/
|
|
214
|
+
next() {
|
|
215
|
+
_class_private_field_set(this, _seed, (_class_static_private_field_spec_get(_SimplePRNG, _SimplePRNG, _a) * _class_private_field_get(this, _seed) + _class_static_private_field_spec_get(_SimplePRNG, _SimplePRNG, _c)) % _class_static_private_field_spec_get(_SimplePRNG, _SimplePRNG, _m));
|
|
216
|
+
return _class_private_field_get(this, _seed) / _class_static_private_field_spec_get(_SimplePRNG, _SimplePRNG, _m);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Resets the generator with a new seed.
|
|
220
|
+
* @param seed - New seed value.
|
|
221
|
+
*/
|
|
222
|
+
reset(seed) {
|
|
223
|
+
_class_private_field_set(this, _seed, seed);
|
|
126
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Creates a new PRNG instance.
|
|
227
|
+
* @param seed - Initial seed value. If not provided, uses 0.
|
|
228
|
+
*/
|
|
229
|
+
constructor(seed = 0) {
|
|
230
|
+
_class_private_field_init(this, _seed, {
|
|
231
|
+
writable: true,
|
|
232
|
+
value: void 0
|
|
233
|
+
});
|
|
234
|
+
_class_private_field_set(this, _seed, seed);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
var _a = {
|
|
238
|
+
writable: true,
|
|
239
|
+
value: 1664525
|
|
240
|
+
};
|
|
241
|
+
var _c = {
|
|
242
|
+
writable: true,
|
|
243
|
+
value: 1013904223
|
|
244
|
+
};
|
|
245
|
+
var _m = {
|
|
246
|
+
writable: true,
|
|
247
|
+
value: Math.pow(2, 32)
|
|
127
248
|
};
|
|
128
249
|
|
|
129
250
|
// src/space-id.ts
|
|
@@ -194,7 +315,7 @@ function base32Encode(data, variant, options) {
|
|
|
194
315
|
}
|
|
195
316
|
|
|
196
317
|
// src/space-id.ts
|
|
197
|
-
import
|
|
318
|
+
import * as Schema2 from "effect/Schema";
|
|
198
319
|
import { invariant } from "@dxos/invariant";
|
|
199
320
|
|
|
200
321
|
// src/random-bytes.ts
|
|
@@ -207,121 +328,143 @@ var randomBytes = (length) => {
|
|
|
207
328
|
};
|
|
208
329
|
|
|
209
330
|
// src/space-id.ts
|
|
331
|
+
function _define_property(obj, key, value) {
|
|
332
|
+
if (key in obj) {
|
|
333
|
+
Object.defineProperty(obj, key, {
|
|
334
|
+
value,
|
|
335
|
+
enumerable: true,
|
|
336
|
+
configurable: true,
|
|
337
|
+
writable: true
|
|
338
|
+
});
|
|
339
|
+
} else {
|
|
340
|
+
obj[key] = value;
|
|
341
|
+
}
|
|
342
|
+
return obj;
|
|
343
|
+
}
|
|
344
|
+
var _Schema_String_pipe;
|
|
345
|
+
var _class2;
|
|
210
346
|
var __dxlog_file = "/__w/dxos/dxos/packages/common/keys/src/space-id.ts";
|
|
211
347
|
var MULTIBASE_PREFIX = "B";
|
|
212
348
|
var ENCODED_LENGTH = 33;
|
|
213
349
|
var isValid = (value) => {
|
|
214
350
|
return typeof value === "string" && value.startsWith(MULTIBASE_PREFIX) && value.length === ENCODED_LENGTH;
|
|
215
351
|
};
|
|
216
|
-
var SpaceId = class extends Schema2.String.pipe(Schema2.filter(isValid)) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
352
|
+
var SpaceId = (_class2 = class extends (_Schema_String_pipe = Schema2.String.pipe(Schema2.filter(isValid))) {
|
|
353
|
+
}, _define_property(_class2, "byteLength", 20), _define_property(_class2, "encode", (value) => {
|
|
354
|
+
invariant(value instanceof Uint8Array, "Invalid type", {
|
|
355
|
+
F: __dxlog_file,
|
|
356
|
+
L: 43,
|
|
357
|
+
S: _class2,
|
|
358
|
+
A: [
|
|
359
|
+
"value instanceof Uint8Array",
|
|
360
|
+
"'Invalid type'"
|
|
361
|
+
]
|
|
362
|
+
});
|
|
363
|
+
invariant(value.length === SpaceId.byteLength, "Invalid length", {
|
|
364
|
+
F: __dxlog_file,
|
|
365
|
+
L: 44,
|
|
366
|
+
S: _class2,
|
|
367
|
+
A: [
|
|
368
|
+
"value.length === SpaceId.byteLength",
|
|
369
|
+
"'Invalid length'"
|
|
370
|
+
]
|
|
371
|
+
});
|
|
372
|
+
return MULTIBASE_PREFIX + base32Encode(value, "RFC4648");
|
|
373
|
+
}), _define_property(_class2, "decode", (value) => {
|
|
374
|
+
invariant(value.startsWith(MULTIBASE_PREFIX), "Invalid multibase32 encoding", {
|
|
375
|
+
F: __dxlog_file,
|
|
376
|
+
L: 49,
|
|
377
|
+
S: _class2,
|
|
378
|
+
A: [
|
|
379
|
+
"value.startsWith(MULTIBASE_PREFIX)",
|
|
380
|
+
"'Invalid multibase32 encoding'"
|
|
381
|
+
]
|
|
382
|
+
});
|
|
383
|
+
return new Uint8Array((0, import_base32_decode.default)(value.slice(1), "RFC4648"));
|
|
384
|
+
}), _define_property(_class2, "isValid", isValid), _define_property(_class2, "random", () => {
|
|
385
|
+
return SpaceId.encode(randomBytes(SpaceId.byteLength));
|
|
386
|
+
}), _class2);
|
|
387
|
+
|
|
388
|
+
// src/dxn.ts
|
|
389
|
+
function _check_private_redeclaration2(obj, privateCollection) {
|
|
390
|
+
if (privateCollection.has(obj)) {
|
|
391
|
+
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
242
392
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
L: 49,
|
|
248
|
-
S: this,
|
|
249
|
-
A: [
|
|
250
|
-
"value.startsWith(MULTIBASE_PREFIX)",
|
|
251
|
-
"'Invalid multibase32 encoding'"
|
|
252
|
-
]
|
|
253
|
-
});
|
|
254
|
-
return new Uint8Array((0, import_base32_decode.default)(value.slice(1), "RFC4648"));
|
|
255
|
-
};
|
|
393
|
+
}
|
|
394
|
+
function _class_apply_descriptor_get2(receiver, descriptor) {
|
|
395
|
+
if (descriptor.get) {
|
|
396
|
+
return descriptor.get.call(receiver);
|
|
256
397
|
}
|
|
257
|
-
|
|
258
|
-
|
|
398
|
+
return descriptor.value;
|
|
399
|
+
}
|
|
400
|
+
function _class_apply_descriptor_set2(receiver, descriptor, value) {
|
|
401
|
+
if (descriptor.set) {
|
|
402
|
+
descriptor.set.call(receiver, value);
|
|
403
|
+
} else {
|
|
404
|
+
if (!descriptor.writable) {
|
|
405
|
+
throw new TypeError("attempted to set read only private field");
|
|
406
|
+
}
|
|
407
|
+
descriptor.value = value;
|
|
259
408
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
409
|
+
}
|
|
410
|
+
function _class_extract_field_descriptor2(receiver, privateMap, action) {
|
|
411
|
+
if (!privateMap.has(receiver)) {
|
|
412
|
+
throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
264
413
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
414
|
+
return privateMap.get(receiver);
|
|
415
|
+
}
|
|
416
|
+
function _class_private_field_get2(receiver, privateMap) {
|
|
417
|
+
var descriptor = _class_extract_field_descriptor2(receiver, privateMap, "get");
|
|
418
|
+
return _class_apply_descriptor_get2(receiver, descriptor);
|
|
419
|
+
}
|
|
420
|
+
function _class_private_field_init2(obj, privateMap, value) {
|
|
421
|
+
_check_private_redeclaration2(obj, privateMap);
|
|
422
|
+
privateMap.set(obj, value);
|
|
423
|
+
}
|
|
424
|
+
function _class_private_field_set2(receiver, privateMap, value) {
|
|
425
|
+
var descriptor = _class_extract_field_descriptor2(receiver, privateMap, "set");
|
|
426
|
+
_class_apply_descriptor_set2(receiver, descriptor, value);
|
|
427
|
+
return value;
|
|
428
|
+
}
|
|
429
|
+
function _define_property2(obj, key, value) {
|
|
430
|
+
if (key in obj) {
|
|
431
|
+
Object.defineProperty(obj, key, {
|
|
432
|
+
value,
|
|
433
|
+
enumerable: true,
|
|
434
|
+
configurable: true,
|
|
435
|
+
writable: true
|
|
436
|
+
});
|
|
437
|
+
} else {
|
|
438
|
+
obj[key] = value;
|
|
439
|
+
}
|
|
440
|
+
return obj;
|
|
441
|
+
}
|
|
268
442
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/common/keys/src/dxn.ts";
|
|
269
443
|
var LOCAL_SPACE_TAG = "@";
|
|
444
|
+
var DXN_ECHO_REGEXP = /@(dxn:[a-zA-Z0-p:@]+)/;
|
|
270
445
|
var QueueSubspaceTags = Object.freeze({
|
|
271
446
|
DATA: "data",
|
|
272
447
|
TRACE: "trace"
|
|
273
448
|
});
|
|
449
|
+
var _kind = /* @__PURE__ */ new WeakMap();
|
|
450
|
+
var _parts = /* @__PURE__ */ new WeakMap();
|
|
451
|
+
var _inspectCustom = inspectCustom;
|
|
452
|
+
var _devtoolsFormatter = devtoolsFormatter;
|
|
274
453
|
var DXN = class _DXN {
|
|
275
|
-
static {
|
|
276
|
-
// TODO(dmaretskyi): Should this be a transformation into the DXN type?
|
|
277
|
-
this.Schema = Schema3.NonEmptyString.pipe(
|
|
278
|
-
Schema3.pattern(/^dxn:([^:]+):(?:[^:]+:?)+[^:]$/),
|
|
279
|
-
// TODO(dmaretskyi): To set the format we need to move the annotation IDs out of the echo-schema package.
|
|
280
|
-
// FormatAnnotation.set(FormatEnum.DXN),
|
|
281
|
-
Schema3.annotations({
|
|
282
|
-
title: "DXN",
|
|
283
|
-
description: "DXN URI",
|
|
284
|
-
examples: [
|
|
285
|
-
"dxn:type:example.com/type/MyType",
|
|
286
|
-
"dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6"
|
|
287
|
-
]
|
|
288
|
-
})
|
|
289
|
-
);
|
|
290
|
-
}
|
|
291
454
|
static hash(dxn) {
|
|
292
455
|
return dxn.toString();
|
|
293
456
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
*/
|
|
298
|
-
this.kind = Object.freeze({
|
|
299
|
-
/**
|
|
300
|
-
* dxn:type:<type name>[:<version>]
|
|
301
|
-
*/
|
|
302
|
-
TYPE: "type",
|
|
303
|
-
/**
|
|
304
|
-
* dxn:echo:<space id>:<echo id>
|
|
305
|
-
* dxn:echo:@:<echo id>
|
|
306
|
-
*/
|
|
307
|
-
// TODO(burdon): Rename to OBJECT? (BREAKING CHANGE).
|
|
308
|
-
// TODO(burdon): Add separate Kind for space.
|
|
309
|
-
ECHO: "echo",
|
|
310
|
-
/**
|
|
311
|
-
* The subspace tag enables us to partition queues by usage within the context of a space.
|
|
312
|
-
* dxn:queue:<subspace_tag>:<space_id>:<queue_id>[:object_id]
|
|
313
|
-
* dxn:queue:data:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
|
|
314
|
-
* dxn:queue:trace:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
|
|
315
|
-
*/
|
|
316
|
-
QUEUE: "queue"
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
get kind() {
|
|
320
|
-
return this.#kind;
|
|
321
|
-
}
|
|
457
|
+
/**
|
|
458
|
+
* Exactly equals.
|
|
459
|
+
*/
|
|
322
460
|
static equals(a, b) {
|
|
323
461
|
return a.kind === b.kind && a.parts.length === b.parts.length && a.parts.every((part, i) => part === b.parts[i]);
|
|
324
462
|
}
|
|
463
|
+
static equalsEchoId(a, b) {
|
|
464
|
+
const a1 = a.asEchoDXN();
|
|
465
|
+
const b1 = b.asEchoDXN();
|
|
466
|
+
return !!a1 && !!b1 && a1.echoId === b1.echoId;
|
|
467
|
+
}
|
|
325
468
|
// TODO(burdon): Rename isValid.
|
|
326
469
|
static isDXNString(dxn) {
|
|
327
470
|
return dxn.startsWith("dxn:");
|
|
@@ -345,7 +488,7 @@ var DXN = class _DXN {
|
|
|
345
488
|
static tryParse(dxn) {
|
|
346
489
|
try {
|
|
347
490
|
return _DXN.parse(dxn);
|
|
348
|
-
} catch
|
|
491
|
+
} catch {
|
|
349
492
|
return void 0;
|
|
350
493
|
}
|
|
351
494
|
}
|
|
@@ -368,43 +511,30 @@ var DXN = class _DXN {
|
|
|
368
511
|
]);
|
|
369
512
|
}
|
|
370
513
|
/**
|
|
514
|
+
* @example `dxn:echo:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6`
|
|
515
|
+
*/
|
|
516
|
+
static fromSpaceAndObjectId(spaceId, objectId) {
|
|
517
|
+
assertArgument(SpaceId.isValid(spaceId), `Invalid space ID: ${spaceId}`);
|
|
518
|
+
assertArgument(ObjectId.isValid(objectId), "objectId", `Invalid object ID: ${objectId}`);
|
|
519
|
+
return new _DXN(_DXN.kind.ECHO, [
|
|
520
|
+
spaceId,
|
|
521
|
+
objectId
|
|
522
|
+
]);
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
371
525
|
* @example `dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6`
|
|
372
526
|
*/
|
|
373
527
|
static fromLocalObjectId(id) {
|
|
374
|
-
assertArgument(ObjectId.isValid(id), `Invalid object ID: ${id}`);
|
|
528
|
+
assertArgument(ObjectId.isValid(id), "id", `Invalid object ID: ${id}`);
|
|
375
529
|
return new _DXN(_DXN.kind.ECHO, [
|
|
376
530
|
LOCAL_SPACE_TAG,
|
|
377
531
|
id
|
|
378
532
|
]);
|
|
379
533
|
}
|
|
380
534
|
static fromQueue(subspaceTag, spaceId, queueId, objectId) {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
S: this,
|
|
385
|
-
A: [
|
|
386
|
-
"SpaceId.isValid(spaceId)",
|
|
387
|
-
""
|
|
388
|
-
]
|
|
389
|
-
});
|
|
390
|
-
invariant2(ObjectId.isValid(queueId), void 0, {
|
|
391
|
-
F: __dxlog_file2,
|
|
392
|
-
L: 152,
|
|
393
|
-
S: this,
|
|
394
|
-
A: [
|
|
395
|
-
"ObjectId.isValid(queueId)",
|
|
396
|
-
""
|
|
397
|
-
]
|
|
398
|
-
});
|
|
399
|
-
invariant2(!objectId || ObjectId.isValid(objectId), void 0, {
|
|
400
|
-
F: __dxlog_file2,
|
|
401
|
-
L: 153,
|
|
402
|
-
S: this,
|
|
403
|
-
A: [
|
|
404
|
-
"!objectId || ObjectId.isValid(objectId)",
|
|
405
|
-
""
|
|
406
|
-
]
|
|
407
|
-
});
|
|
535
|
+
assertArgument(SpaceId.isValid(spaceId), `Invalid space ID: ${spaceId}`);
|
|
536
|
+
assertArgument(ObjectId.isValid(queueId), "queueId", `Invalid queue ID: ${queueId}`);
|
|
537
|
+
assertArgument(!objectId || ObjectId.isValid(objectId), "objectId", `Invalid object ID: ${objectId}`);
|
|
408
538
|
return new _DXN(_DXN.kind.QUEUE, [
|
|
409
539
|
subspaceTag,
|
|
410
540
|
spaceId,
|
|
@@ -414,44 +544,8 @@ var DXN = class _DXN {
|
|
|
414
544
|
] : []
|
|
415
545
|
]);
|
|
416
546
|
}
|
|
417
|
-
#kind;
|
|
418
|
-
#parts;
|
|
419
|
-
constructor(kind, parts) {
|
|
420
|
-
invariant2(parts.length > 0, void 0, {
|
|
421
|
-
F: __dxlog_file2,
|
|
422
|
-
L: 162,
|
|
423
|
-
S: this,
|
|
424
|
-
A: [
|
|
425
|
-
"parts.length > 0",
|
|
426
|
-
""
|
|
427
|
-
]
|
|
428
|
-
});
|
|
429
|
-
invariant2(parts.every((part) => typeof part === "string" && part.length > 0 && part.indexOf(":") === -1), void 0, {
|
|
430
|
-
F: __dxlog_file2,
|
|
431
|
-
L: 163,
|
|
432
|
-
S: this,
|
|
433
|
-
A: [
|
|
434
|
-
"parts.every((part) => typeof part === 'string' && part.length > 0 && part.indexOf(':') === -1)",
|
|
435
|
-
""
|
|
436
|
-
]
|
|
437
|
-
});
|
|
438
|
-
switch (kind) {
|
|
439
|
-
case _DXN.kind.TYPE:
|
|
440
|
-
if (parts.length > 2) {
|
|
441
|
-
throw new Error('Invalid "type" DXN');
|
|
442
|
-
}
|
|
443
|
-
break;
|
|
444
|
-
case _DXN.kind.ECHO:
|
|
445
|
-
if (parts.length !== 2) {
|
|
446
|
-
throw new Error('Invalid "echo" DXN');
|
|
447
|
-
}
|
|
448
|
-
break;
|
|
449
|
-
}
|
|
450
|
-
this.#kind = kind;
|
|
451
|
-
this.#parts = parts;
|
|
452
|
-
}
|
|
453
547
|
toString() {
|
|
454
|
-
return `dxn:${this
|
|
548
|
+
return `dxn:${_class_private_field_get2(this, _kind)}:${_class_private_field_get2(this, _parts).join(":")}`;
|
|
455
549
|
}
|
|
456
550
|
toJSON() {
|
|
457
551
|
return this.toString();
|
|
@@ -459,13 +553,13 @@ var DXN = class _DXN {
|
|
|
459
553
|
/**
|
|
460
554
|
* Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
|
|
461
555
|
*/
|
|
462
|
-
[
|
|
556
|
+
[_inspectCustom](depth, options, inspectFn) {
|
|
463
557
|
const printControlCode = (code) => {
|
|
464
558
|
return `\x1B[${code}m`;
|
|
465
559
|
};
|
|
466
560
|
return printControlCode(inspectFn.colors.blueBright[0]) + this.toString() + printControlCode(inspectFn.colors.reset[0]);
|
|
467
561
|
}
|
|
468
|
-
get [
|
|
562
|
+
get [_devtoolsFormatter]() {
|
|
469
563
|
return {
|
|
470
564
|
header: () => {
|
|
471
565
|
return [
|
|
@@ -478,33 +572,39 @@ var DXN = class _DXN {
|
|
|
478
572
|
}
|
|
479
573
|
};
|
|
480
574
|
}
|
|
575
|
+
get kind() {
|
|
576
|
+
return _class_private_field_get2(this, _kind);
|
|
577
|
+
}
|
|
481
578
|
get parts() {
|
|
482
|
-
return this
|
|
579
|
+
return _class_private_field_get2(this, _parts);
|
|
483
580
|
}
|
|
484
581
|
// TODO(burdon): Should getters fail?
|
|
485
582
|
get typename() {
|
|
486
|
-
invariant2(this
|
|
583
|
+
invariant2(_class_private_field_get2(this, _kind) === _DXN.kind.TYPE, void 0, {
|
|
487
584
|
F: __dxlog_file2,
|
|
488
|
-
L:
|
|
585
|
+
L: 250,
|
|
489
586
|
S: this,
|
|
490
587
|
A: [
|
|
491
588
|
"this.#kind === DXN.kind.TYPE",
|
|
492
589
|
""
|
|
493
590
|
]
|
|
494
591
|
});
|
|
495
|
-
return this
|
|
592
|
+
return _class_private_field_get2(this, _parts)[0];
|
|
593
|
+
}
|
|
594
|
+
equals(other) {
|
|
595
|
+
return _DXN.equals(this, other);
|
|
496
596
|
}
|
|
497
597
|
hasTypenameOf(typename) {
|
|
498
|
-
return this
|
|
598
|
+
return _class_private_field_get2(this, _kind) === _DXN.kind.TYPE && _class_private_field_get2(this, _parts).length === 1 && _class_private_field_get2(this, _parts)[0] === typename;
|
|
499
599
|
}
|
|
500
600
|
isLocalObjectId() {
|
|
501
|
-
return this
|
|
601
|
+
return _class_private_field_get2(this, _kind) === _DXN.kind.ECHO && _class_private_field_get2(this, _parts)[0] === LOCAL_SPACE_TAG && _class_private_field_get2(this, _parts).length === 2;
|
|
502
602
|
}
|
|
503
603
|
asTypeDXN() {
|
|
504
604
|
if (this.kind !== _DXN.kind.TYPE) {
|
|
505
605
|
return void 0;
|
|
506
606
|
}
|
|
507
|
-
const [type, version] = this
|
|
607
|
+
const [type, version] = _class_private_field_get2(this, _parts);
|
|
508
608
|
return {
|
|
509
609
|
// TODO(wittjosiah): Should be `typename` for consistency.
|
|
510
610
|
type,
|
|
@@ -515,9 +615,10 @@ var DXN = class _DXN {
|
|
|
515
615
|
if (this.kind !== _DXN.kind.ECHO) {
|
|
516
616
|
return void 0;
|
|
517
617
|
}
|
|
518
|
-
const [spaceId, echoId] = this
|
|
618
|
+
const [spaceId, echoId] = _class_private_field_get2(this, _parts);
|
|
519
619
|
return {
|
|
520
620
|
spaceId: spaceId === LOCAL_SPACE_TAG ? void 0 : spaceId,
|
|
621
|
+
// TODO(burdon): objectId.
|
|
521
622
|
echoId
|
|
522
623
|
};
|
|
523
624
|
}
|
|
@@ -525,7 +626,7 @@ var DXN = class _DXN {
|
|
|
525
626
|
if (this.kind !== _DXN.kind.QUEUE) {
|
|
526
627
|
return void 0;
|
|
527
628
|
}
|
|
528
|
-
const [subspaceTag, spaceId, queueId, objectId] = this
|
|
629
|
+
const [subspaceTag, spaceId, queueId, objectId] = _class_private_field_get2(this, _parts);
|
|
529
630
|
if (typeof queueId !== "string") {
|
|
530
631
|
return void 0;
|
|
531
632
|
}
|
|
@@ -536,7 +637,75 @@ var DXN = class _DXN {
|
|
|
536
637
|
objectId
|
|
537
638
|
};
|
|
538
639
|
}
|
|
640
|
+
/**
|
|
641
|
+
* Produces a new DXN with the given parts appended.
|
|
642
|
+
*/
|
|
643
|
+
extend(parts) {
|
|
644
|
+
return new _DXN(_class_private_field_get2(this, _kind), [
|
|
645
|
+
..._class_private_field_get2(this, _parts),
|
|
646
|
+
...parts
|
|
647
|
+
]);
|
|
648
|
+
}
|
|
649
|
+
constructor(kind, parts) {
|
|
650
|
+
_class_private_field_init2(this, _kind, {
|
|
651
|
+
writable: true,
|
|
652
|
+
value: void 0
|
|
653
|
+
});
|
|
654
|
+
_class_private_field_init2(this, _parts, {
|
|
655
|
+
writable: true,
|
|
656
|
+
value: void 0
|
|
657
|
+
});
|
|
658
|
+
assertArgument(parts.length > 0, "parts", `Invalid DXN: ${parts}`);
|
|
659
|
+
assertArgument(parts.every((part) => typeof part === "string" && part.length > 0 && part.indexOf(":") === -1), "parts", `Invalid DXN: ${parts}`);
|
|
660
|
+
switch (kind) {
|
|
661
|
+
case _DXN.kind.TYPE:
|
|
662
|
+
if (parts.length > 2) {
|
|
663
|
+
throw new Error("Invalid DXN.kind.TYPE");
|
|
664
|
+
}
|
|
665
|
+
break;
|
|
666
|
+
case _DXN.kind.ECHO:
|
|
667
|
+
if (parts.length !== 2) {
|
|
668
|
+
throw new Error("Invalid DXN.kind.ECHO");
|
|
669
|
+
}
|
|
670
|
+
break;
|
|
671
|
+
}
|
|
672
|
+
_class_private_field_set2(this, _kind, kind);
|
|
673
|
+
_class_private_field_set2(this, _parts, parts);
|
|
674
|
+
}
|
|
539
675
|
};
|
|
676
|
+
_define_property2(DXN, "Schema", Schema3.NonEmptyString.pipe(
|
|
677
|
+
Schema3.pattern(/^dxn:([^:]+):(?:[^:]+:?)+[^:]$/),
|
|
678
|
+
// TODO(dmaretskyi): To set the format we need to move the annotation IDs out of the echo-schema package.
|
|
679
|
+
// FormatAnnotation.set(FormatEnum.DXN),
|
|
680
|
+
Schema3.annotations({
|
|
681
|
+
title: "DXN",
|
|
682
|
+
description: "DXN URI",
|
|
683
|
+
examples: [
|
|
684
|
+
"dxn:type:example.com/type/MyType",
|
|
685
|
+
"dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6"
|
|
686
|
+
]
|
|
687
|
+
})
|
|
688
|
+
));
|
|
689
|
+
_define_property2(DXN, "kind", Object.freeze({
|
|
690
|
+
/**
|
|
691
|
+
* dxn:type:<type_name>[:<version>]
|
|
692
|
+
*/
|
|
693
|
+
TYPE: "type",
|
|
694
|
+
/**
|
|
695
|
+
* dxn:echo:<space_id>:<echo_id>
|
|
696
|
+
* dxn:echo:@:<echo_id>
|
|
697
|
+
*/
|
|
698
|
+
// TODO(burdon): Rename to OBJECT? (BREAKING CHANGE to update "echo").
|
|
699
|
+
// TODO(burdon): Add separate Kind for space?
|
|
700
|
+
ECHO: "echo",
|
|
701
|
+
/**
|
|
702
|
+
* The subspace tag enables us to partition queues by usage within the context of a space.
|
|
703
|
+
* dxn:queue:<subspace_tag>:<space_id>:<queue_id>[:object_id]
|
|
704
|
+
* dxn:queue:data:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
|
|
705
|
+
* dxn:queue:trace:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
|
|
706
|
+
*/
|
|
707
|
+
QUEUE: "queue"
|
|
708
|
+
}));
|
|
540
709
|
|
|
541
710
|
// src/identity-did.ts
|
|
542
711
|
init_inject_globals();
|
|
@@ -594,14 +763,27 @@ init_inject_globals();
|
|
|
594
763
|
var import_base32_decode3 = __toESM(require_base32_decode(), 1);
|
|
595
764
|
import { devtoolsFormatter as devtoolsFormatter2, equalsSymbol, inspectCustom as inspectCustom2, truncateKey } from "@dxos/debug";
|
|
596
765
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
766
|
+
function _define_property3(obj, key, value) {
|
|
767
|
+
if (key in obj) {
|
|
768
|
+
Object.defineProperty(obj, key, {
|
|
769
|
+
value,
|
|
770
|
+
enumerable: true,
|
|
771
|
+
configurable: true,
|
|
772
|
+
writable: true
|
|
773
|
+
});
|
|
774
|
+
} else {
|
|
775
|
+
obj[key] = value;
|
|
776
|
+
}
|
|
777
|
+
return obj;
|
|
778
|
+
}
|
|
597
779
|
var __dxlog_file4 = "/__w/dxos/dxos/packages/common/keys/src/public-key.ts";
|
|
598
780
|
var PUBLIC_KEY_LENGTH = 32;
|
|
599
781
|
var SECRET_KEY_LENGTH = 64;
|
|
600
782
|
var isLikeArrayBuffer = (value) => typeof value === "object" && value !== null && Object.getPrototypeOf(value).constructor.name === "ArrayBuffer";
|
|
783
|
+
var _inspectCustom2 = inspectCustom2;
|
|
784
|
+
var _devtoolsFormatter2 = devtoolsFormatter2;
|
|
785
|
+
var _equalsSymbol = equalsSymbol;
|
|
601
786
|
var PublicKey = class _PublicKey {
|
|
602
|
-
static {
|
|
603
|
-
this.ZERO = _PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH));
|
|
604
|
-
}
|
|
605
787
|
/**
|
|
606
788
|
* Creates new instance of PublicKey automatically determining the input format.
|
|
607
789
|
* @param source A Buffer, or Uint8Array, or hex encoded string, or something with an `asUint8Array` method on it
|
|
@@ -610,7 +792,7 @@ var PublicKey = class _PublicKey {
|
|
|
610
792
|
static from(source) {
|
|
611
793
|
invariant4(source, void 0, {
|
|
612
794
|
F: __dxlog_file4,
|
|
613
|
-
L:
|
|
795
|
+
L: 50,
|
|
614
796
|
S: this,
|
|
615
797
|
A: [
|
|
616
798
|
"source",
|
|
@@ -702,7 +884,7 @@ var PublicKey = class _PublicKey {
|
|
|
702
884
|
static bufferize(str) {
|
|
703
885
|
invariant4(typeof str === "string", "Invalid type", {
|
|
704
886
|
F: __dxlog_file4,
|
|
705
|
-
L:
|
|
887
|
+
L: 153,
|
|
706
888
|
S: this,
|
|
707
889
|
A: [
|
|
708
890
|
"typeof str === 'string'",
|
|
@@ -725,7 +907,7 @@ var PublicKey = class _PublicKey {
|
|
|
725
907
|
}
|
|
726
908
|
invariant4(key instanceof Buffer2, "Invalid type", {
|
|
727
909
|
F: __dxlog_file4,
|
|
728
|
-
L:
|
|
910
|
+
L: 172,
|
|
729
911
|
S: this,
|
|
730
912
|
A: [
|
|
731
913
|
"key instanceof Buffer",
|
|
@@ -744,7 +926,7 @@ var PublicKey = class _PublicKey {
|
|
|
744
926
|
static fromMultibase32(encoded) {
|
|
745
927
|
invariant4(encoded.startsWith("B"), "Invalid multibase32 encoding", {
|
|
746
928
|
F: __dxlog_file4,
|
|
747
|
-
L:
|
|
929
|
+
L: 185,
|
|
748
930
|
S: this,
|
|
749
931
|
A: [
|
|
750
932
|
"encoded.startsWith('B')",
|
|
@@ -753,12 +935,6 @@ var PublicKey = class _PublicKey {
|
|
|
753
935
|
});
|
|
754
936
|
return new _PublicKey(new Uint8Array((0, import_base32_decode3.default)(encoded.slice(1), "RFC4648")));
|
|
755
937
|
}
|
|
756
|
-
constructor(_value) {
|
|
757
|
-
this._value = _value;
|
|
758
|
-
if (!(_value instanceof Uint8Array)) {
|
|
759
|
-
throw new TypeError(`Expected Uint8Array, got: ${_value}`);
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
938
|
toString() {
|
|
763
939
|
return this.toHex();
|
|
764
940
|
}
|
|
@@ -792,7 +968,7 @@ var PublicKey = class _PublicKey {
|
|
|
792
968
|
/**
|
|
793
969
|
* Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
|
|
794
970
|
*/
|
|
795
|
-
[
|
|
971
|
+
[_inspectCustom2](depth, options, inspectFn) {
|
|
796
972
|
if (!options.colors || typeof process.stdout.hasColors !== "function" || !process.stdout.hasColors()) {
|
|
797
973
|
return `<PublicKey ${this.truncate()}>`;
|
|
798
974
|
}
|
|
@@ -817,7 +993,7 @@ var PublicKey = class _PublicKey {
|
|
|
817
993
|
const color = colors[this.getInsecureHash(colors.length)];
|
|
818
994
|
return `PublicKey(${printControlCode(inspectFn.colors[color][0])}${this.truncate()}${printControlCode(inspectFn.colors.reset[0])})`;
|
|
819
995
|
}
|
|
820
|
-
get [
|
|
996
|
+
get [_devtoolsFormatter2]() {
|
|
821
997
|
return {
|
|
822
998
|
header: () => {
|
|
823
999
|
const colors = [
|
|
@@ -870,19 +1046,28 @@ var PublicKey = class _PublicKey {
|
|
|
870
1046
|
}
|
|
871
1047
|
let equal = true;
|
|
872
1048
|
for (let i = 0; i < this._value.length; i++) {
|
|
873
|
-
equal
|
|
1049
|
+
equal && (equal = this._value[i] === otherConverted._value[i]);
|
|
874
1050
|
}
|
|
875
1051
|
return equal;
|
|
876
1052
|
}
|
|
877
|
-
[
|
|
1053
|
+
[_equalsSymbol](other) {
|
|
878
1054
|
if (!_PublicKey.isPublicKey(other)) {
|
|
879
1055
|
return false;
|
|
880
1056
|
}
|
|
881
1057
|
return this.equals(other);
|
|
882
1058
|
}
|
|
1059
|
+
constructor(_value) {
|
|
1060
|
+
_define_property3(this, "_value", void 0);
|
|
1061
|
+
this._value = _value;
|
|
1062
|
+
if (!(_value instanceof Uint8Array)) {
|
|
1063
|
+
throw new TypeError(`Expected Uint8Array, got: ${_value}`);
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
883
1066
|
};
|
|
1067
|
+
_define_property3(PublicKey, "ZERO", PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH)));
|
|
884
1068
|
export {
|
|
885
1069
|
DXN,
|
|
1070
|
+
DXN_ECHO_REGEXP,
|
|
886
1071
|
IdentityDid,
|
|
887
1072
|
LOCAL_SPACE_TAG,
|
|
888
1073
|
ObjectId,
|
|
@@ -890,6 +1075,7 @@ export {
|
|
|
890
1075
|
PublicKey,
|
|
891
1076
|
QueueSubspaceTags,
|
|
892
1077
|
SECRET_KEY_LENGTH,
|
|
1078
|
+
SimplePRNG,
|
|
893
1079
|
SpaceId
|
|
894
1080
|
};
|
|
895
1081
|
//# sourceMappingURL=index.mjs.map
|