@dxos/keys 0.8.4-main.c1de068 → 0.8.4-main.c4373fc
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
|
@@ -82,29 +82,150 @@ 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
|
|
91
|
-
import {
|
|
90
|
+
import * as Schema from "effect/Schema";
|
|
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;
|
|
92
156
|
var ObjectIdSchema = Schema.String.pipe(Schema.pattern(/^[0-7][0-9A-HJKMNP-TV-Z]{25}$/i)).annotations({
|
|
93
|
-
description: "
|
|
157
|
+
description: "A Universally Unique Lexicographically Sortable Identifier",
|
|
94
158
|
pattern: "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
|
|
95
159
|
});
|
|
96
|
-
var ObjectId = class extends ObjectIdSchema {
|
|
160
|
+
var ObjectId = (_class = class extends ObjectIdSchema {
|
|
97
161
|
static isValid(id) {
|
|
98
162
|
try {
|
|
99
163
|
Schema.decodeSync(ObjectId)(id);
|
|
100
164
|
return true;
|
|
101
|
-
} catch
|
|
165
|
+
} catch {
|
|
102
166
|
return false;
|
|
103
167
|
}
|
|
104
168
|
}
|
|
105
169
|
static random() {
|
|
106
|
-
return
|
|
170
|
+
return _class_static_private_field_spec_get(this, _class, _factory).call(_class, _class_static_private_field_spec_get(this, _class, _seedTime));
|
|
171
|
+
}
|
|
172
|
+
static dangerouslyDisableRandomness() {
|
|
173
|
+
_class_static_private_field_spec_set(this, _class, _factory, monotonicFactory(makeTestPRNG()));
|
|
174
|
+
_class_static_private_field_spec_set(this, _class, _seedTime, (/* @__PURE__ */ new Date("2025-01-01")).getTime());
|
|
175
|
+
}
|
|
176
|
+
}, _factory = {
|
|
177
|
+
writable: true,
|
|
178
|
+
value: monotonicFactory()
|
|
179
|
+
}, _seedTime = {
|
|
180
|
+
writable: true,
|
|
181
|
+
value: void 0
|
|
182
|
+
}, _class);
|
|
183
|
+
var makeTestPRNG = () => {
|
|
184
|
+
const rng = new SimplePRNG();
|
|
185
|
+
return () => {
|
|
186
|
+
return rng.next();
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
var _seed = /* @__PURE__ */ new WeakMap();
|
|
190
|
+
var SimplePRNG = class _SimplePRNG {
|
|
191
|
+
/**
|
|
192
|
+
* Generates the next pseudo-random number in the range [0, 1).
|
|
193
|
+
* @returns A pseudo-random number between 0 (inclusive) and 1 (exclusive).
|
|
194
|
+
*/
|
|
195
|
+
next() {
|
|
196
|
+
_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));
|
|
197
|
+
return _class_private_field_get(this, _seed) / _class_static_private_field_spec_get(_SimplePRNG, _SimplePRNG, _m);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Resets the generator with a new seed.
|
|
201
|
+
* @param seed - New seed value.
|
|
202
|
+
*/
|
|
203
|
+
reset(seed) {
|
|
204
|
+
_class_private_field_set(this, _seed, seed);
|
|
107
205
|
}
|
|
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)
|
|
108
229
|
};
|
|
109
230
|
|
|
110
231
|
// src/space-id.ts
|
|
@@ -170,7 +291,7 @@ function base32Encode(data, variant, options) {
|
|
|
170
291
|
}
|
|
171
292
|
|
|
172
293
|
// src/space-id.ts
|
|
173
|
-
import
|
|
294
|
+
import * as Schema2 from "effect/Schema";
|
|
174
295
|
import { invariant } from "@dxos/invariant";
|
|
175
296
|
|
|
176
297
|
// src/random-bytes.ts
|
|
@@ -182,121 +303,143 @@ var randomBytes = (length) => {
|
|
|
182
303
|
};
|
|
183
304
|
|
|
184
305
|
// 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;
|
|
185
321
|
var __dxlog_file = "/__w/dxos/dxos/packages/common/keys/src/space-id.ts";
|
|
186
322
|
var MULTIBASE_PREFIX = "B";
|
|
187
323
|
var ENCODED_LENGTH = 33;
|
|
188
324
|
var isValid = (value) => {
|
|
189
325
|
return typeof value === "string" && value.startsWith(MULTIBASE_PREFIX) && value.length === ENCODED_LENGTH;
|
|
190
326
|
};
|
|
191
|
-
var SpaceId = class extends Schema2.String.pipe(Schema2.filter(isValid)) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
327
|
+
var SpaceId = (_class2 = class extends (_Schema_String_pipe = Schema2.String.pipe(Schema2.filter(isValid))) {
|
|
328
|
+
}, _define_property(_class2, "byteLength", 20), _define_property(_class2, "encode", (value) => {
|
|
329
|
+
invariant(value instanceof Uint8Array, "Invalid type", {
|
|
330
|
+
F: __dxlog_file,
|
|
331
|
+
L: 43,
|
|
332
|
+
S: _class2,
|
|
333
|
+
A: [
|
|
334
|
+
"value instanceof Uint8Array",
|
|
335
|
+
"'Invalid type'"
|
|
336
|
+
]
|
|
337
|
+
});
|
|
338
|
+
invariant(value.length === SpaceId.byteLength, "Invalid length", {
|
|
339
|
+
F: __dxlog_file,
|
|
340
|
+
L: 44,
|
|
341
|
+
S: _class2,
|
|
342
|
+
A: [
|
|
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);
|
|
362
|
+
|
|
363
|
+
// 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");
|
|
217
367
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
L: 49,
|
|
223
|
-
S: this,
|
|
224
|
-
A: [
|
|
225
|
-
"value.startsWith(MULTIBASE_PREFIX)",
|
|
226
|
-
"'Invalid multibase32 encoding'"
|
|
227
|
-
]
|
|
228
|
-
});
|
|
229
|
-
return new Uint8Array((0, import_base32_decode.default)(value.slice(1), "RFC4648"));
|
|
230
|
-
};
|
|
368
|
+
}
|
|
369
|
+
function _class_apply_descriptor_get2(receiver, descriptor) {
|
|
370
|
+
if (descriptor.get) {
|
|
371
|
+
return descriptor.get.call(receiver);
|
|
231
372
|
}
|
|
232
|
-
|
|
233
|
-
|
|
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;
|
|
234
383
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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");
|
|
239
388
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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
|
+
}
|
|
243
417
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/common/keys/src/dxn.ts";
|
|
244
418
|
var LOCAL_SPACE_TAG = "@";
|
|
419
|
+
var DXN_ECHO_REGEXP = /@(dxn:[a-zA-Z0-p:@]+)/;
|
|
245
420
|
var QueueSubspaceTags = Object.freeze({
|
|
246
421
|
DATA: "data",
|
|
247
422
|
TRACE: "trace"
|
|
248
423
|
});
|
|
424
|
+
var _kind = /* @__PURE__ */ new WeakMap();
|
|
425
|
+
var _parts = /* @__PURE__ */ new WeakMap();
|
|
426
|
+
var _inspectCustom = inspectCustom;
|
|
427
|
+
var _devtoolsFormatter = devtoolsFormatter;
|
|
249
428
|
var DXN = class _DXN {
|
|
250
|
-
static {
|
|
251
|
-
// TODO(dmaretskyi): Should this be a transformation into the DXN type?
|
|
252
|
-
this.Schema = Schema3.NonEmptyString.pipe(
|
|
253
|
-
Schema3.pattern(/^dxn:([^:]+):(?:[^:]+:?)+[^:]$/),
|
|
254
|
-
// TODO(dmaretskyi): To set the format we need to move the annotation IDs out of the echo-schema package.
|
|
255
|
-
// FormatAnnotation.set(FormatEnum.DXN),
|
|
256
|
-
Schema3.annotations({
|
|
257
|
-
title: "DXN",
|
|
258
|
-
description: "DXN URI",
|
|
259
|
-
examples: [
|
|
260
|
-
"dxn:type:example.com/type/MyType",
|
|
261
|
-
"dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6"
|
|
262
|
-
]
|
|
263
|
-
})
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
429
|
static hash(dxn) {
|
|
267
430
|
return dxn.toString();
|
|
268
431
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
*/
|
|
273
|
-
this.kind = Object.freeze({
|
|
274
|
-
/**
|
|
275
|
-
* dxn:type:<type name>[:<version>]
|
|
276
|
-
*/
|
|
277
|
-
TYPE: "type",
|
|
278
|
-
/**
|
|
279
|
-
* dxn:echo:<space id>:<echo id>
|
|
280
|
-
* dxn:echo:@:<echo id>
|
|
281
|
-
*/
|
|
282
|
-
// TODO(burdon): Rename to OBJECT? (BREAKING CHANGE).
|
|
283
|
-
// TODO(burdon): Add separate Kind for space.
|
|
284
|
-
ECHO: "echo",
|
|
285
|
-
/**
|
|
286
|
-
* The subspace tag enables us to partition queues by usage within the context of a space.
|
|
287
|
-
* dxn:queue:<subspace_tag>:<space_id>:<queue_id>[:object_id]
|
|
288
|
-
* dxn:queue:data:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
|
|
289
|
-
* dxn:queue:trace:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
|
|
290
|
-
*/
|
|
291
|
-
QUEUE: "queue"
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
get kind() {
|
|
295
|
-
return this.#kind;
|
|
296
|
-
}
|
|
432
|
+
/**
|
|
433
|
+
* Exactly equals.
|
|
434
|
+
*/
|
|
297
435
|
static equals(a, b) {
|
|
298
436
|
return a.kind === b.kind && a.parts.length === b.parts.length && a.parts.every((part, i) => part === b.parts[i]);
|
|
299
437
|
}
|
|
438
|
+
static equalsEchoId(a, b) {
|
|
439
|
+
const a1 = a.asEchoDXN();
|
|
440
|
+
const b1 = b.asEchoDXN();
|
|
441
|
+
return !!a1 && !!b1 && a1.echoId === b1.echoId;
|
|
442
|
+
}
|
|
300
443
|
// TODO(burdon): Rename isValid.
|
|
301
444
|
static isDXNString(dxn) {
|
|
302
445
|
return dxn.startsWith("dxn:");
|
|
@@ -320,7 +463,7 @@ var DXN = class _DXN {
|
|
|
320
463
|
static tryParse(dxn) {
|
|
321
464
|
try {
|
|
322
465
|
return _DXN.parse(dxn);
|
|
323
|
-
} catch
|
|
466
|
+
} catch {
|
|
324
467
|
return void 0;
|
|
325
468
|
}
|
|
326
469
|
}
|
|
@@ -343,43 +486,30 @@ var DXN = class _DXN {
|
|
|
343
486
|
]);
|
|
344
487
|
}
|
|
345
488
|
/**
|
|
489
|
+
* @example `dxn:echo:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6`
|
|
490
|
+
*/
|
|
491
|
+
static fromSpaceAndObjectId(spaceId, objectId) {
|
|
492
|
+
assertArgument(SpaceId.isValid(spaceId), `Invalid space ID: ${spaceId}`);
|
|
493
|
+
assertArgument(ObjectId.isValid(objectId), "objectId", `Invalid object ID: ${objectId}`);
|
|
494
|
+
return new _DXN(_DXN.kind.ECHO, [
|
|
495
|
+
spaceId,
|
|
496
|
+
objectId
|
|
497
|
+
]);
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
346
500
|
* @example `dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6`
|
|
347
501
|
*/
|
|
348
502
|
static fromLocalObjectId(id) {
|
|
349
|
-
assertArgument(ObjectId.isValid(id), `Invalid object ID: ${id}`);
|
|
503
|
+
assertArgument(ObjectId.isValid(id), "id", `Invalid object ID: ${id}`);
|
|
350
504
|
return new _DXN(_DXN.kind.ECHO, [
|
|
351
505
|
LOCAL_SPACE_TAG,
|
|
352
506
|
id
|
|
353
507
|
]);
|
|
354
508
|
}
|
|
355
509
|
static fromQueue(subspaceTag, spaceId, queueId, objectId) {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
S: this,
|
|
360
|
-
A: [
|
|
361
|
-
"SpaceId.isValid(spaceId)",
|
|
362
|
-
""
|
|
363
|
-
]
|
|
364
|
-
});
|
|
365
|
-
invariant2(ObjectId.isValid(queueId), void 0, {
|
|
366
|
-
F: __dxlog_file2,
|
|
367
|
-
L: 152,
|
|
368
|
-
S: this,
|
|
369
|
-
A: [
|
|
370
|
-
"ObjectId.isValid(queueId)",
|
|
371
|
-
""
|
|
372
|
-
]
|
|
373
|
-
});
|
|
374
|
-
invariant2(!objectId || ObjectId.isValid(objectId), void 0, {
|
|
375
|
-
F: __dxlog_file2,
|
|
376
|
-
L: 153,
|
|
377
|
-
S: this,
|
|
378
|
-
A: [
|
|
379
|
-
"!objectId || ObjectId.isValid(objectId)",
|
|
380
|
-
""
|
|
381
|
-
]
|
|
382
|
-
});
|
|
510
|
+
assertArgument(SpaceId.isValid(spaceId), `Invalid space ID: ${spaceId}`);
|
|
511
|
+
assertArgument(ObjectId.isValid(queueId), "queueId", `Invalid queue ID: ${queueId}`);
|
|
512
|
+
assertArgument(!objectId || ObjectId.isValid(objectId), "objectId", `Invalid object ID: ${objectId}`);
|
|
383
513
|
return new _DXN(_DXN.kind.QUEUE, [
|
|
384
514
|
subspaceTag,
|
|
385
515
|
spaceId,
|
|
@@ -389,44 +519,8 @@ var DXN = class _DXN {
|
|
|
389
519
|
] : []
|
|
390
520
|
]);
|
|
391
521
|
}
|
|
392
|
-
#kind;
|
|
393
|
-
#parts;
|
|
394
|
-
constructor(kind, parts) {
|
|
395
|
-
invariant2(parts.length > 0, void 0, {
|
|
396
|
-
F: __dxlog_file2,
|
|
397
|
-
L: 162,
|
|
398
|
-
S: this,
|
|
399
|
-
A: [
|
|
400
|
-
"parts.length > 0",
|
|
401
|
-
""
|
|
402
|
-
]
|
|
403
|
-
});
|
|
404
|
-
invariant2(parts.every((part) => typeof part === "string" && part.length > 0 && part.indexOf(":") === -1), void 0, {
|
|
405
|
-
F: __dxlog_file2,
|
|
406
|
-
L: 163,
|
|
407
|
-
S: this,
|
|
408
|
-
A: [
|
|
409
|
-
"parts.every((part) => typeof part === 'string' && part.length > 0 && part.indexOf(':') === -1)",
|
|
410
|
-
""
|
|
411
|
-
]
|
|
412
|
-
});
|
|
413
|
-
switch (kind) {
|
|
414
|
-
case _DXN.kind.TYPE:
|
|
415
|
-
if (parts.length > 2) {
|
|
416
|
-
throw new Error('Invalid "type" DXN');
|
|
417
|
-
}
|
|
418
|
-
break;
|
|
419
|
-
case _DXN.kind.ECHO:
|
|
420
|
-
if (parts.length !== 2) {
|
|
421
|
-
throw new Error('Invalid "echo" DXN');
|
|
422
|
-
}
|
|
423
|
-
break;
|
|
424
|
-
}
|
|
425
|
-
this.#kind = kind;
|
|
426
|
-
this.#parts = parts;
|
|
427
|
-
}
|
|
428
522
|
toString() {
|
|
429
|
-
return `dxn:${this
|
|
523
|
+
return `dxn:${_class_private_field_get2(this, _kind)}:${_class_private_field_get2(this, _parts).join(":")}`;
|
|
430
524
|
}
|
|
431
525
|
toJSON() {
|
|
432
526
|
return this.toString();
|
|
@@ -434,13 +528,13 @@ var DXN = class _DXN {
|
|
|
434
528
|
/**
|
|
435
529
|
* Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
|
|
436
530
|
*/
|
|
437
|
-
[
|
|
531
|
+
[_inspectCustom](depth, options, inspectFn) {
|
|
438
532
|
const printControlCode = (code) => {
|
|
439
533
|
return `\x1B[${code}m`;
|
|
440
534
|
};
|
|
441
535
|
return printControlCode(inspectFn.colors.blueBright[0]) + this.toString() + printControlCode(inspectFn.colors.reset[0]);
|
|
442
536
|
}
|
|
443
|
-
get [
|
|
537
|
+
get [_devtoolsFormatter]() {
|
|
444
538
|
return {
|
|
445
539
|
header: () => {
|
|
446
540
|
return [
|
|
@@ -453,33 +547,39 @@ var DXN = class _DXN {
|
|
|
453
547
|
}
|
|
454
548
|
};
|
|
455
549
|
}
|
|
550
|
+
get kind() {
|
|
551
|
+
return _class_private_field_get2(this, _kind);
|
|
552
|
+
}
|
|
456
553
|
get parts() {
|
|
457
|
-
return this
|
|
554
|
+
return _class_private_field_get2(this, _parts);
|
|
458
555
|
}
|
|
459
556
|
// TODO(burdon): Should getters fail?
|
|
460
557
|
get typename() {
|
|
461
|
-
invariant2(this
|
|
558
|
+
invariant2(_class_private_field_get2(this, _kind) === _DXN.kind.TYPE, void 0, {
|
|
462
559
|
F: __dxlog_file2,
|
|
463
|
-
L:
|
|
560
|
+
L: 250,
|
|
464
561
|
S: this,
|
|
465
562
|
A: [
|
|
466
563
|
"this.#kind === DXN.kind.TYPE",
|
|
467
564
|
""
|
|
468
565
|
]
|
|
469
566
|
});
|
|
470
|
-
return this
|
|
567
|
+
return _class_private_field_get2(this, _parts)[0];
|
|
568
|
+
}
|
|
569
|
+
equals(other) {
|
|
570
|
+
return _DXN.equals(this, other);
|
|
471
571
|
}
|
|
472
572
|
hasTypenameOf(typename) {
|
|
473
|
-
return this
|
|
573
|
+
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;
|
|
474
574
|
}
|
|
475
575
|
isLocalObjectId() {
|
|
476
|
-
return this
|
|
576
|
+
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;
|
|
477
577
|
}
|
|
478
578
|
asTypeDXN() {
|
|
479
579
|
if (this.kind !== _DXN.kind.TYPE) {
|
|
480
580
|
return void 0;
|
|
481
581
|
}
|
|
482
|
-
const [type, version] = this
|
|
582
|
+
const [type, version] = _class_private_field_get2(this, _parts);
|
|
483
583
|
return {
|
|
484
584
|
// TODO(wittjosiah): Should be `typename` for consistency.
|
|
485
585
|
type,
|
|
@@ -490,9 +590,10 @@ var DXN = class _DXN {
|
|
|
490
590
|
if (this.kind !== _DXN.kind.ECHO) {
|
|
491
591
|
return void 0;
|
|
492
592
|
}
|
|
493
|
-
const [spaceId, echoId] = this
|
|
593
|
+
const [spaceId, echoId] = _class_private_field_get2(this, _parts);
|
|
494
594
|
return {
|
|
495
595
|
spaceId: spaceId === LOCAL_SPACE_TAG ? void 0 : spaceId,
|
|
596
|
+
// TODO(burdon): objectId.
|
|
496
597
|
echoId
|
|
497
598
|
};
|
|
498
599
|
}
|
|
@@ -500,7 +601,7 @@ var DXN = class _DXN {
|
|
|
500
601
|
if (this.kind !== _DXN.kind.QUEUE) {
|
|
501
602
|
return void 0;
|
|
502
603
|
}
|
|
503
|
-
const [subspaceTag, spaceId, queueId, objectId] = this
|
|
604
|
+
const [subspaceTag, spaceId, queueId, objectId] = _class_private_field_get2(this, _parts);
|
|
504
605
|
if (typeof queueId !== "string") {
|
|
505
606
|
return void 0;
|
|
506
607
|
}
|
|
@@ -511,7 +612,75 @@ var DXN = class _DXN {
|
|
|
511
612
|
objectId
|
|
512
613
|
};
|
|
513
614
|
}
|
|
615
|
+
/**
|
|
616
|
+
* Produces a new DXN with the given parts appended.
|
|
617
|
+
*/
|
|
618
|
+
extend(parts) {
|
|
619
|
+
return new _DXN(_class_private_field_get2(this, _kind), [
|
|
620
|
+
..._class_private_field_get2(this, _parts),
|
|
621
|
+
...parts
|
|
622
|
+
]);
|
|
623
|
+
}
|
|
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
|
+
}
|
|
514
650
|
};
|
|
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
|
+
}));
|
|
515
684
|
|
|
516
685
|
// src/identity-did.ts
|
|
517
686
|
var import_base32_decode2 = __toESM(require_base32_decode(), 1);
|
|
@@ -567,14 +736,27 @@ var ENCODED_LENGTH2 = 42;
|
|
|
567
736
|
var import_base32_decode3 = __toESM(require_base32_decode(), 1);
|
|
568
737
|
import { devtoolsFormatter as devtoolsFormatter2, equalsSymbol, inspectCustom as inspectCustom2, truncateKey } from "@dxos/debug";
|
|
569
738
|
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
|
+
}
|
|
570
752
|
var __dxlog_file4 = "/__w/dxos/dxos/packages/common/keys/src/public-key.ts";
|
|
571
753
|
var PUBLIC_KEY_LENGTH = 32;
|
|
572
754
|
var SECRET_KEY_LENGTH = 64;
|
|
573
755
|
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;
|
|
574
759
|
var PublicKey = class _PublicKey {
|
|
575
|
-
static {
|
|
576
|
-
this.ZERO = _PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH));
|
|
577
|
-
}
|
|
578
760
|
/**
|
|
579
761
|
* Creates new instance of PublicKey automatically determining the input format.
|
|
580
762
|
* @param source A Buffer, or Uint8Array, or hex encoded string, or something with an `asUint8Array` method on it
|
|
@@ -583,7 +765,7 @@ var PublicKey = class _PublicKey {
|
|
|
583
765
|
static from(source) {
|
|
584
766
|
invariant4(source, void 0, {
|
|
585
767
|
F: __dxlog_file4,
|
|
586
|
-
L:
|
|
768
|
+
L: 50,
|
|
587
769
|
S: this,
|
|
588
770
|
A: [
|
|
589
771
|
"source",
|
|
@@ -675,7 +857,7 @@ var PublicKey = class _PublicKey {
|
|
|
675
857
|
static bufferize(str) {
|
|
676
858
|
invariant4(typeof str === "string", "Invalid type", {
|
|
677
859
|
F: __dxlog_file4,
|
|
678
|
-
L:
|
|
860
|
+
L: 153,
|
|
679
861
|
S: this,
|
|
680
862
|
A: [
|
|
681
863
|
"typeof str === 'string'",
|
|
@@ -698,7 +880,7 @@ var PublicKey = class _PublicKey {
|
|
|
698
880
|
}
|
|
699
881
|
invariant4(key instanceof Buffer, "Invalid type", {
|
|
700
882
|
F: __dxlog_file4,
|
|
701
|
-
L:
|
|
883
|
+
L: 172,
|
|
702
884
|
S: this,
|
|
703
885
|
A: [
|
|
704
886
|
"key instanceof Buffer",
|
|
@@ -717,7 +899,7 @@ var PublicKey = class _PublicKey {
|
|
|
717
899
|
static fromMultibase32(encoded) {
|
|
718
900
|
invariant4(encoded.startsWith("B"), "Invalid multibase32 encoding", {
|
|
719
901
|
F: __dxlog_file4,
|
|
720
|
-
L:
|
|
902
|
+
L: 185,
|
|
721
903
|
S: this,
|
|
722
904
|
A: [
|
|
723
905
|
"encoded.startsWith('B')",
|
|
@@ -726,12 +908,6 @@ var PublicKey = class _PublicKey {
|
|
|
726
908
|
});
|
|
727
909
|
return new _PublicKey(new Uint8Array((0, import_base32_decode3.default)(encoded.slice(1), "RFC4648")));
|
|
728
910
|
}
|
|
729
|
-
constructor(_value) {
|
|
730
|
-
this._value = _value;
|
|
731
|
-
if (!(_value instanceof Uint8Array)) {
|
|
732
|
-
throw new TypeError(`Expected Uint8Array, got: ${_value}`);
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
911
|
toString() {
|
|
736
912
|
return this.toHex();
|
|
737
913
|
}
|
|
@@ -765,7 +941,7 @@ var PublicKey = class _PublicKey {
|
|
|
765
941
|
/**
|
|
766
942
|
* Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
|
|
767
943
|
*/
|
|
768
|
-
[
|
|
944
|
+
[_inspectCustom2](depth, options, inspectFn) {
|
|
769
945
|
if (!options.colors || typeof process.stdout.hasColors !== "function" || !process.stdout.hasColors()) {
|
|
770
946
|
return `<PublicKey ${this.truncate()}>`;
|
|
771
947
|
}
|
|
@@ -790,7 +966,7 @@ var PublicKey = class _PublicKey {
|
|
|
790
966
|
const color = colors[this.getInsecureHash(colors.length)];
|
|
791
967
|
return `PublicKey(${printControlCode(inspectFn.colors[color][0])}${this.truncate()}${printControlCode(inspectFn.colors.reset[0])})`;
|
|
792
968
|
}
|
|
793
|
-
get [
|
|
969
|
+
get [_devtoolsFormatter2]() {
|
|
794
970
|
return {
|
|
795
971
|
header: () => {
|
|
796
972
|
const colors = [
|
|
@@ -843,19 +1019,28 @@ var PublicKey = class _PublicKey {
|
|
|
843
1019
|
}
|
|
844
1020
|
let equal = true;
|
|
845
1021
|
for (let i = 0; i < this._value.length; i++) {
|
|
846
|
-
equal
|
|
1022
|
+
equal && (equal = this._value[i] === otherConverted._value[i]);
|
|
847
1023
|
}
|
|
848
1024
|
return equal;
|
|
849
1025
|
}
|
|
850
|
-
[
|
|
1026
|
+
[_equalsSymbol](other) {
|
|
851
1027
|
if (!_PublicKey.isPublicKey(other)) {
|
|
852
1028
|
return false;
|
|
853
1029
|
}
|
|
854
1030
|
return this.equals(other);
|
|
855
1031
|
}
|
|
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
|
+
}
|
|
856
1039
|
};
|
|
1040
|
+
_define_property3(PublicKey, "ZERO", PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH)));
|
|
857
1041
|
export {
|
|
858
1042
|
DXN,
|
|
1043
|
+
DXN_ECHO_REGEXP,
|
|
859
1044
|
IdentityDid,
|
|
860
1045
|
LOCAL_SPACE_TAG,
|
|
861
1046
|
ObjectId,
|
|
@@ -863,6 +1048,7 @@ export {
|
|
|
863
1048
|
PublicKey,
|
|
864
1049
|
QueueSubspaceTags,
|
|
865
1050
|
SECRET_KEY_LENGTH,
|
|
1051
|
+
SimplePRNG,
|
|
866
1052
|
SpaceId
|
|
867
1053
|
};
|
|
868
1054
|
//# sourceMappingURL=index.mjs.map
|