@dxos/keys 0.8.3 → 0.8.4-main.84f28bd
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 +48 -45
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +46 -43
- 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 +7 -6
- package/dist/types/src/dxn.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/dxn.ts +29 -25
- package/dist/lib/node/index.cjs +0 -866
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
package/dist/lib/node/index.cjs
DELETED
|
@@ -1,866 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var node_exports = {};
|
|
20
|
-
__export(node_exports, {
|
|
21
|
-
DXN: () => DXN,
|
|
22
|
-
IdentityDid: () => IdentityDid,
|
|
23
|
-
LOCAL_SPACE_TAG: () => LOCAL_SPACE_TAG,
|
|
24
|
-
ObjectId: () => ObjectId,
|
|
25
|
-
PUBLIC_KEY_LENGTH: () => PUBLIC_KEY_LENGTH,
|
|
26
|
-
PublicKey: () => PublicKey,
|
|
27
|
-
QueueSubspaceTags: () => QueueSubspaceTags,
|
|
28
|
-
SECRET_KEY_LENGTH: () => SECRET_KEY_LENGTH,
|
|
29
|
-
SpaceId: () => SpaceId
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(node_exports);
|
|
32
|
-
var import_effect = require("effect");
|
|
33
|
-
var import_debug = require("@dxos/debug");
|
|
34
|
-
var import_invariant = require("@dxos/invariant");
|
|
35
|
-
var import_effect2 = require("effect");
|
|
36
|
-
var import_ulidx = require("ulidx");
|
|
37
|
-
var import_effect3 = require("effect");
|
|
38
|
-
var import_invariant2 = require("@dxos/invariant");
|
|
39
|
-
var import_invariant3 = require("@dxos/invariant");
|
|
40
|
-
var import_debug2 = require("@dxos/debug");
|
|
41
|
-
var import_invariant4 = require("@dxos/invariant");
|
|
42
|
-
var __create = Object.create;
|
|
43
|
-
var __defProp2 = Object.defineProperty;
|
|
44
|
-
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
45
|
-
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
46
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
47
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
48
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
49
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
50
|
-
}) : x)(function(x) {
|
|
51
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
52
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
53
|
-
});
|
|
54
|
-
var __commonJS = (cb, mod) => function __require2() {
|
|
55
|
-
return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
56
|
-
};
|
|
57
|
-
var __copyProps2 = (to, from, except, desc) => {
|
|
58
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
59
|
-
for (let key of __getOwnPropNames2(from))
|
|
60
|
-
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
61
|
-
__defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
|
|
62
|
-
}
|
|
63
|
-
return to;
|
|
64
|
-
};
|
|
65
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps2(
|
|
66
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
67
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
68
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
69
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
70
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
|
|
71
|
-
mod
|
|
72
|
-
));
|
|
73
|
-
var require_base32_decode = __commonJS({
|
|
74
|
-
"node_modules/.pnpm/base32-decode@1.0.0/node_modules/base32-decode/index.js"(exports2, module2) {
|
|
75
|
-
var RFC46482 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
76
|
-
var RFC4648_HEX2 = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
|
|
77
|
-
var CROCKFORD2 = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
78
|
-
function readChar(alphabet, char) {
|
|
79
|
-
var idx = alphabet.indexOf(char);
|
|
80
|
-
if (idx === -1) {
|
|
81
|
-
throw new Error("Invalid character found: " + char);
|
|
82
|
-
}
|
|
83
|
-
return idx;
|
|
84
|
-
}
|
|
85
|
-
module2.exports = function base32Decode4(input, variant) {
|
|
86
|
-
var alphabet;
|
|
87
|
-
switch (variant) {
|
|
88
|
-
case "RFC3548":
|
|
89
|
-
case "RFC4648":
|
|
90
|
-
alphabet = RFC46482;
|
|
91
|
-
input = input.replace(/=+$/, "");
|
|
92
|
-
break;
|
|
93
|
-
case "RFC4648-HEX":
|
|
94
|
-
alphabet = RFC4648_HEX2;
|
|
95
|
-
input = input.replace(/=+$/, "");
|
|
96
|
-
break;
|
|
97
|
-
case "Crockford":
|
|
98
|
-
alphabet = CROCKFORD2;
|
|
99
|
-
input = input.toUpperCase().replace(/O/g, "0").replace(/[IL]/g, "1");
|
|
100
|
-
break;
|
|
101
|
-
default:
|
|
102
|
-
throw new Error("Unknown base32 variant: " + variant);
|
|
103
|
-
}
|
|
104
|
-
var length = input.length;
|
|
105
|
-
var bits = 0;
|
|
106
|
-
var value = 0;
|
|
107
|
-
var index = 0;
|
|
108
|
-
var output = new Uint8Array(length * 5 / 8 | 0);
|
|
109
|
-
for (var i = 0; i < length; i++) {
|
|
110
|
-
value = value << 5 | readChar(alphabet, input[i]);
|
|
111
|
-
bits += 5;
|
|
112
|
-
if (bits >= 8) {
|
|
113
|
-
output[index++] = value >>> bits - 8 & 255;
|
|
114
|
-
bits -= 8;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return output.buffer;
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
var ObjectIdSchema = import_effect2.Schema.String.pipe(import_effect2.Schema.pattern(/^[0-7][0-9A-HJKMNP-TV-Z]{25}$/i)).annotations({
|
|
122
|
-
description: "a Universally Unique Lexicographically Sortable Identifier",
|
|
123
|
-
pattern: "^[0-7][0-9A-HJKMNP-TV-Z]{25}$"
|
|
124
|
-
});
|
|
125
|
-
var ObjectId = class extends ObjectIdSchema {
|
|
126
|
-
static isValid(id) {
|
|
127
|
-
try {
|
|
128
|
-
import_effect2.Schema.decodeSync(ObjectId)(id);
|
|
129
|
-
return true;
|
|
130
|
-
} catch (err) {
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
static random() {
|
|
135
|
-
return (0, import_ulidx.ulid)();
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
var import_base32_decode = __toESM(require_base32_decode(), 1);
|
|
139
|
-
function toDataView(data) {
|
|
140
|
-
if (data instanceof Int8Array || data instanceof Uint8Array || data instanceof Uint8ClampedArray) {
|
|
141
|
-
return new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
142
|
-
}
|
|
143
|
-
if (data instanceof ArrayBuffer) {
|
|
144
|
-
return new DataView(data);
|
|
145
|
-
}
|
|
146
|
-
throw new TypeError("Expected `data` to be an ArrayBuffer, Buffer, Int8Array, Uint8Array or Uint8ClampedArray");
|
|
147
|
-
}
|
|
148
|
-
var RFC4648 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
149
|
-
var RFC4648_HEX = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
|
|
150
|
-
var CROCKFORD = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
151
|
-
function base32Encode(data, variant, options) {
|
|
152
|
-
options = options || {};
|
|
153
|
-
let alphabet, defaultPadding;
|
|
154
|
-
switch (variant) {
|
|
155
|
-
case "RFC3548":
|
|
156
|
-
case "RFC4648":
|
|
157
|
-
alphabet = RFC4648;
|
|
158
|
-
defaultPadding = true;
|
|
159
|
-
break;
|
|
160
|
-
case "RFC4648-HEX":
|
|
161
|
-
alphabet = RFC4648_HEX;
|
|
162
|
-
defaultPadding = true;
|
|
163
|
-
break;
|
|
164
|
-
case "Crockford":
|
|
165
|
-
alphabet = CROCKFORD;
|
|
166
|
-
defaultPadding = false;
|
|
167
|
-
break;
|
|
168
|
-
default:
|
|
169
|
-
throw new Error("Unknown base32 variant: " + variant);
|
|
170
|
-
}
|
|
171
|
-
const padding = options.padding !== void 0 ? options.padding : defaultPadding;
|
|
172
|
-
const view = toDataView(data);
|
|
173
|
-
let bits = 0;
|
|
174
|
-
let value = 0;
|
|
175
|
-
let output = "";
|
|
176
|
-
for (let i = 0; i < view.byteLength; i++) {
|
|
177
|
-
value = value << 8 | view.getUint8(i);
|
|
178
|
-
bits += 8;
|
|
179
|
-
while (bits >= 5) {
|
|
180
|
-
output += alphabet[value >>> bits - 5 & 31];
|
|
181
|
-
bits -= 5;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
if (bits > 0) {
|
|
185
|
-
output += alphabet[value << 5 - bits & 31];
|
|
186
|
-
}
|
|
187
|
-
if (padding) {
|
|
188
|
-
while (output.length % 8 !== 0) {
|
|
189
|
-
output += "=";
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return output;
|
|
193
|
-
}
|
|
194
|
-
var randomBytes = (length) => {
|
|
195
|
-
const webCrypto = globalThis.crypto ?? __require("node:crypto").webcrypto;
|
|
196
|
-
const bytes = new Uint8Array(length);
|
|
197
|
-
webCrypto.getRandomValues(bytes);
|
|
198
|
-
return bytes;
|
|
199
|
-
};
|
|
200
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/common/keys/src/space-id.ts";
|
|
201
|
-
var MULTIBASE_PREFIX = "B";
|
|
202
|
-
var ENCODED_LENGTH = 33;
|
|
203
|
-
var isValid = (value) => {
|
|
204
|
-
return typeof value === "string" && value.startsWith(MULTIBASE_PREFIX) && value.length === ENCODED_LENGTH;
|
|
205
|
-
};
|
|
206
|
-
var SpaceId = class extends import_effect3.Schema.String.pipe(import_effect3.Schema.filter(isValid)) {
|
|
207
|
-
static {
|
|
208
|
-
this.byteLength = 20;
|
|
209
|
-
}
|
|
210
|
-
static {
|
|
211
|
-
this.encode = (value) => {
|
|
212
|
-
(0, import_invariant2.invariant)(value instanceof Uint8Array, "Invalid type", {
|
|
213
|
-
F: __dxlog_file,
|
|
214
|
-
L: 43,
|
|
215
|
-
S: this,
|
|
216
|
-
A: [
|
|
217
|
-
"value instanceof Uint8Array",
|
|
218
|
-
"'Invalid type'"
|
|
219
|
-
]
|
|
220
|
-
});
|
|
221
|
-
(0, import_invariant2.invariant)(value.length === SpaceId.byteLength, "Invalid length", {
|
|
222
|
-
F: __dxlog_file,
|
|
223
|
-
L: 44,
|
|
224
|
-
S: this,
|
|
225
|
-
A: [
|
|
226
|
-
"value.length === SpaceId.byteLength",
|
|
227
|
-
"'Invalid length'"
|
|
228
|
-
]
|
|
229
|
-
});
|
|
230
|
-
return MULTIBASE_PREFIX + base32Encode(value, "RFC4648");
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
static {
|
|
234
|
-
this.decode = (value) => {
|
|
235
|
-
(0, import_invariant2.invariant)(value.startsWith(MULTIBASE_PREFIX), "Invalid multibase32 encoding", {
|
|
236
|
-
F: __dxlog_file,
|
|
237
|
-
L: 49,
|
|
238
|
-
S: this,
|
|
239
|
-
A: [
|
|
240
|
-
"value.startsWith(MULTIBASE_PREFIX)",
|
|
241
|
-
"'Invalid multibase32 encoding'"
|
|
242
|
-
]
|
|
243
|
-
});
|
|
244
|
-
return new Uint8Array((0, import_base32_decode.default)(value.slice(1), "RFC4648"));
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
static {
|
|
248
|
-
this.isValid = isValid;
|
|
249
|
-
}
|
|
250
|
-
static {
|
|
251
|
-
this.random = () => {
|
|
252
|
-
return SpaceId.encode(randomBytes(SpaceId.byteLength));
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/common/keys/src/dxn.ts";
|
|
257
|
-
var LOCAL_SPACE_TAG = "@";
|
|
258
|
-
var QueueSubspaceTags = Object.freeze({
|
|
259
|
-
DATA: "data",
|
|
260
|
-
TRACE: "trace"
|
|
261
|
-
});
|
|
262
|
-
var DXN = class _DXN {
|
|
263
|
-
static {
|
|
264
|
-
this.Schema = import_effect.Schema.NonEmptyString.pipe(
|
|
265
|
-
import_effect.Schema.pattern(/^dxn:([^:]+):(?:[^:]+:?)+[^:]$/),
|
|
266
|
-
// TODO(dmaretskyi): To set the format we need to move the annotation IDs out of the echo-schema package.
|
|
267
|
-
// FormatAnnotation.set(FormatEnum.DXN),
|
|
268
|
-
import_effect.Schema.annotations({
|
|
269
|
-
title: "DXN",
|
|
270
|
-
description: "DXN URI",
|
|
271
|
-
examples: [
|
|
272
|
-
"dxn:type:example.com/type/MyType",
|
|
273
|
-
"dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6"
|
|
274
|
-
]
|
|
275
|
-
})
|
|
276
|
-
);
|
|
277
|
-
}
|
|
278
|
-
static hash(dxn) {
|
|
279
|
-
return dxn.toString();
|
|
280
|
-
}
|
|
281
|
-
static {
|
|
282
|
-
this.kind = Object.freeze({
|
|
283
|
-
/**
|
|
284
|
-
* dxn:type:<type name>[:<version>]
|
|
285
|
-
*/
|
|
286
|
-
TYPE: "type",
|
|
287
|
-
/**
|
|
288
|
-
* dxn:echo:<space id>:<echo id>
|
|
289
|
-
* dxn:echo:@:<echo id>
|
|
290
|
-
*/
|
|
291
|
-
// TODO(burdon): Rename to OBJECT? (BREAKING CHANGE).
|
|
292
|
-
// TODO(burdon): Add separate Kind for space.
|
|
293
|
-
ECHO: "echo",
|
|
294
|
-
/**
|
|
295
|
-
* The subspace tag enables us to partition queues by usage within the context of a space.
|
|
296
|
-
* dxn:queue:<subspace_tag>:<space_id>:<queue_id>[:object_id]
|
|
297
|
-
* dxn:queue:data:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
|
|
298
|
-
* dxn:queue:trace:BA25QRC2FEWCSAMRP4RZL65LWJ7352CKE:01J00J9B45YHYSGZQTQMSKMGJ6
|
|
299
|
-
*/
|
|
300
|
-
QUEUE: "queue"
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
get kind() {
|
|
304
|
-
return this.#kind;
|
|
305
|
-
}
|
|
306
|
-
static equals(a, b) {
|
|
307
|
-
return a.kind === b.kind && a.parts.length === b.parts.length && a.parts.every((part, i) => part === b.parts[i]);
|
|
308
|
-
}
|
|
309
|
-
// TODO(burdon): Rename isValid.
|
|
310
|
-
static isDXNString(dxn) {
|
|
311
|
-
return dxn.startsWith("dxn:");
|
|
312
|
-
}
|
|
313
|
-
static parse(dxn) {
|
|
314
|
-
if (typeof dxn !== "string") {
|
|
315
|
-
throw new Error(`Invalid DXN: ${dxn}`);
|
|
316
|
-
}
|
|
317
|
-
const [prefix, kind, ...parts] = dxn.split(":");
|
|
318
|
-
if (!(prefix === "dxn")) {
|
|
319
|
-
throw new Error(`Invalid DXN: ${dxn}`);
|
|
320
|
-
}
|
|
321
|
-
if (!(typeof kind === "string" && kind.length > 0)) {
|
|
322
|
-
throw new Error(`Invalid DXN: ${dxn}`);
|
|
323
|
-
}
|
|
324
|
-
if (!(parts.length > 0)) {
|
|
325
|
-
throw new Error(`Invalid DXN: ${dxn}`);
|
|
326
|
-
}
|
|
327
|
-
return new _DXN(kind, parts);
|
|
328
|
-
}
|
|
329
|
-
static tryParse(dxn) {
|
|
330
|
-
try {
|
|
331
|
-
return _DXN.parse(dxn);
|
|
332
|
-
} catch (error) {
|
|
333
|
-
return void 0;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* @example `dxn:type:example.com/type/Contact`
|
|
338
|
-
*/
|
|
339
|
-
static fromTypename(typename) {
|
|
340
|
-
return new _DXN(_DXN.kind.TYPE, [
|
|
341
|
-
typename
|
|
342
|
-
]);
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* @example `dxn:type:example.com/type/Contact:0.1.0`
|
|
346
|
-
*/
|
|
347
|
-
// TODO(dmaretskyi): Consider using @ as the version separator.
|
|
348
|
-
static fromTypenameAndVersion(typename, version) {
|
|
349
|
-
return new _DXN(_DXN.kind.TYPE, [
|
|
350
|
-
typename,
|
|
351
|
-
version
|
|
352
|
-
]);
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* @example `dxn:echo:@:01J00J9B45YHYSGZQTQMSKMGJ6`
|
|
356
|
-
*/
|
|
357
|
-
static fromLocalObjectId(id) {
|
|
358
|
-
return new _DXN(_DXN.kind.ECHO, [
|
|
359
|
-
LOCAL_SPACE_TAG,
|
|
360
|
-
id
|
|
361
|
-
]);
|
|
362
|
-
}
|
|
363
|
-
static fromQueue(subspaceTag, spaceId, queueId, objectId) {
|
|
364
|
-
(0, import_invariant.invariant)(SpaceId.isValid(spaceId), void 0, {
|
|
365
|
-
F: __dxlog_file2,
|
|
366
|
-
L: 150,
|
|
367
|
-
S: this,
|
|
368
|
-
A: [
|
|
369
|
-
"SpaceId.isValid(spaceId)",
|
|
370
|
-
""
|
|
371
|
-
]
|
|
372
|
-
});
|
|
373
|
-
(0, import_invariant.invariant)(ObjectId.isValid(queueId), void 0, {
|
|
374
|
-
F: __dxlog_file2,
|
|
375
|
-
L: 151,
|
|
376
|
-
S: this,
|
|
377
|
-
A: [
|
|
378
|
-
"ObjectId.isValid(queueId)",
|
|
379
|
-
""
|
|
380
|
-
]
|
|
381
|
-
});
|
|
382
|
-
(0, import_invariant.invariant)(!objectId || ObjectId.isValid(objectId), void 0, {
|
|
383
|
-
F: __dxlog_file2,
|
|
384
|
-
L: 152,
|
|
385
|
-
S: this,
|
|
386
|
-
A: [
|
|
387
|
-
"!objectId || ObjectId.isValid(objectId)",
|
|
388
|
-
""
|
|
389
|
-
]
|
|
390
|
-
});
|
|
391
|
-
return new _DXN(_DXN.kind.QUEUE, [
|
|
392
|
-
subspaceTag,
|
|
393
|
-
spaceId,
|
|
394
|
-
queueId,
|
|
395
|
-
...objectId ? [
|
|
396
|
-
objectId
|
|
397
|
-
] : []
|
|
398
|
-
]);
|
|
399
|
-
}
|
|
400
|
-
#kind;
|
|
401
|
-
#parts;
|
|
402
|
-
constructor(kind, parts) {
|
|
403
|
-
(0, import_invariant.invariant)(parts.length > 0, void 0, {
|
|
404
|
-
F: __dxlog_file2,
|
|
405
|
-
L: 161,
|
|
406
|
-
S: this,
|
|
407
|
-
A: [
|
|
408
|
-
"parts.length > 0",
|
|
409
|
-
""
|
|
410
|
-
]
|
|
411
|
-
});
|
|
412
|
-
(0, import_invariant.invariant)(parts.every((part) => typeof part === "string" && part.length > 0 && part.indexOf(":") === -1), void 0, {
|
|
413
|
-
F: __dxlog_file2,
|
|
414
|
-
L: 162,
|
|
415
|
-
S: this,
|
|
416
|
-
A: [
|
|
417
|
-
"parts.every((part) => typeof part === 'string' && part.length > 0 && part.indexOf(':') === -1)",
|
|
418
|
-
""
|
|
419
|
-
]
|
|
420
|
-
});
|
|
421
|
-
switch (kind) {
|
|
422
|
-
case _DXN.kind.TYPE:
|
|
423
|
-
if (parts.length > 2) {
|
|
424
|
-
throw new Error('Invalid "type" DXN');
|
|
425
|
-
}
|
|
426
|
-
break;
|
|
427
|
-
case _DXN.kind.ECHO:
|
|
428
|
-
if (parts.length !== 2) {
|
|
429
|
-
throw new Error('Invalid "echo" DXN');
|
|
430
|
-
}
|
|
431
|
-
break;
|
|
432
|
-
}
|
|
433
|
-
this.#kind = kind;
|
|
434
|
-
this.#parts = parts;
|
|
435
|
-
}
|
|
436
|
-
get parts() {
|
|
437
|
-
return this.#parts;
|
|
438
|
-
}
|
|
439
|
-
// TODO(burdon): Should getters fail?
|
|
440
|
-
get typename() {
|
|
441
|
-
(0, import_invariant.invariant)(this.#kind === _DXN.kind.TYPE, void 0, {
|
|
442
|
-
F: __dxlog_file2,
|
|
443
|
-
L: 188,
|
|
444
|
-
S: this,
|
|
445
|
-
A: [
|
|
446
|
-
"this.#kind === DXN.kind.TYPE",
|
|
447
|
-
""
|
|
448
|
-
]
|
|
449
|
-
});
|
|
450
|
-
return this.#parts[0];
|
|
451
|
-
}
|
|
452
|
-
hasTypenameOf(typename) {
|
|
453
|
-
return this.#kind === _DXN.kind.TYPE && this.#parts.length === 1 && this.#parts[0] === typename;
|
|
454
|
-
}
|
|
455
|
-
isLocalObjectId() {
|
|
456
|
-
return this.#kind === _DXN.kind.ECHO && this.#parts[0] === LOCAL_SPACE_TAG && this.#parts.length === 2;
|
|
457
|
-
}
|
|
458
|
-
asTypeDXN() {
|
|
459
|
-
if (this.kind !== _DXN.kind.TYPE) {
|
|
460
|
-
return void 0;
|
|
461
|
-
}
|
|
462
|
-
const [type, version] = this.#parts;
|
|
463
|
-
return {
|
|
464
|
-
type,
|
|
465
|
-
version
|
|
466
|
-
};
|
|
467
|
-
}
|
|
468
|
-
asEchoDXN() {
|
|
469
|
-
if (this.kind !== _DXN.kind.ECHO) {
|
|
470
|
-
return void 0;
|
|
471
|
-
}
|
|
472
|
-
const [spaceId, echoId] = this.#parts;
|
|
473
|
-
return {
|
|
474
|
-
spaceId: spaceId === LOCAL_SPACE_TAG ? void 0 : spaceId,
|
|
475
|
-
echoId
|
|
476
|
-
};
|
|
477
|
-
}
|
|
478
|
-
asQueueDXN() {
|
|
479
|
-
if (this.kind !== _DXN.kind.QUEUE) {
|
|
480
|
-
return void 0;
|
|
481
|
-
}
|
|
482
|
-
const [subspaceTag, spaceId, queueId, objectId] = this.#parts;
|
|
483
|
-
if (typeof queueId !== "string") {
|
|
484
|
-
return void 0;
|
|
485
|
-
}
|
|
486
|
-
return {
|
|
487
|
-
subspaceTag,
|
|
488
|
-
spaceId,
|
|
489
|
-
queueId,
|
|
490
|
-
objectId
|
|
491
|
-
};
|
|
492
|
-
}
|
|
493
|
-
toString() {
|
|
494
|
-
return `dxn:${this.#kind}:${this.#parts.join(":")}`;
|
|
495
|
-
}
|
|
496
|
-
/**
|
|
497
|
-
* Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
|
|
498
|
-
*/
|
|
499
|
-
[import_debug.inspectCustom](depth, options, inspectFn) {
|
|
500
|
-
const printControlCode = (code) => {
|
|
501
|
-
return `\x1B[${code}m`;
|
|
502
|
-
};
|
|
503
|
-
return printControlCode(inspectFn.colors.blueBright[0]) + this.toString() + printControlCode(inspectFn.colors.reset[0]);
|
|
504
|
-
}
|
|
505
|
-
get [import_debug.devtoolsFormatter]() {
|
|
506
|
-
return {
|
|
507
|
-
header: () => {
|
|
508
|
-
return [
|
|
509
|
-
"span",
|
|
510
|
-
{
|
|
511
|
-
style: "font-weight: bold;"
|
|
512
|
-
},
|
|
513
|
-
this.toString()
|
|
514
|
-
];
|
|
515
|
-
}
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
};
|
|
519
|
-
var import_base32_decode2 = __toESM(require_base32_decode(), 1);
|
|
520
|
-
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/common/keys/src/identity-did.ts";
|
|
521
|
-
var IdentityDid = Object.freeze({
|
|
522
|
-
byteLength: 20,
|
|
523
|
-
encode: (value) => {
|
|
524
|
-
(0, import_invariant3.invariant)(value instanceof Uint8Array, "Invalid type", {
|
|
525
|
-
F: __dxlog_file3,
|
|
526
|
-
L: 22,
|
|
527
|
-
S: void 0,
|
|
528
|
-
A: [
|
|
529
|
-
"value instanceof Uint8Array",
|
|
530
|
-
"'Invalid type'"
|
|
531
|
-
]
|
|
532
|
-
});
|
|
533
|
-
(0, import_invariant3.invariant)(value.length === IdentityDid.byteLength, "Invalid length", {
|
|
534
|
-
F: __dxlog_file3,
|
|
535
|
-
L: 23,
|
|
536
|
-
S: void 0,
|
|
537
|
-
A: [
|
|
538
|
-
"value.length === IdentityDid.byteLength",
|
|
539
|
-
"'Invalid length'"
|
|
540
|
-
]
|
|
541
|
-
});
|
|
542
|
-
return DID_PREFIX + MULTIBASE_PREFIX2 + base32Encode(value, "RFC4648");
|
|
543
|
-
},
|
|
544
|
-
decode: (value) => {
|
|
545
|
-
(0, import_invariant3.invariant)(value.startsWith(DID_PREFIX + MULTIBASE_PREFIX2), "Invalid multibase32 encoding", {
|
|
546
|
-
F: __dxlog_file3,
|
|
547
|
-
L: 28,
|
|
548
|
-
S: void 0,
|
|
549
|
-
A: [
|
|
550
|
-
"value.startsWith(DID_PREFIX + MULTIBASE_PREFIX)",
|
|
551
|
-
"'Invalid multibase32 encoding'"
|
|
552
|
-
]
|
|
553
|
-
});
|
|
554
|
-
return new Uint8Array((0, import_base32_decode2.default)(value.slice(10), "RFC4648"));
|
|
555
|
-
},
|
|
556
|
-
isValid: (value) => {
|
|
557
|
-
return typeof value === "string" && value.startsWith(DID_PREFIX + MULTIBASE_PREFIX2) && value.length === ENCODED_LENGTH2;
|
|
558
|
-
},
|
|
559
|
-
random: () => {
|
|
560
|
-
return IdentityDid.encode(randomBytes(IdentityDid.byteLength));
|
|
561
|
-
}
|
|
562
|
-
});
|
|
563
|
-
var MULTIBASE_PREFIX2 = "B";
|
|
564
|
-
var DID_PREFIX = "did:halo:";
|
|
565
|
-
var ENCODED_LENGTH2 = 42;
|
|
566
|
-
var import_base32_decode3 = __toESM(require_base32_decode(), 1);
|
|
567
|
-
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/common/keys/src/public-key.ts";
|
|
568
|
-
var PUBLIC_KEY_LENGTH = 32;
|
|
569
|
-
var SECRET_KEY_LENGTH = 64;
|
|
570
|
-
var isLikeArrayBuffer = (value) => typeof value === "object" && value !== null && Object.getPrototypeOf(value).constructor.name === "ArrayBuffer";
|
|
571
|
-
var PublicKey = class _PublicKey {
|
|
572
|
-
static {
|
|
573
|
-
this.ZERO = _PublicKey.from("00".repeat(PUBLIC_KEY_LENGTH));
|
|
574
|
-
}
|
|
575
|
-
/**
|
|
576
|
-
* Creates new instance of PublicKey automatically determining the input format.
|
|
577
|
-
* @param source A Buffer, or Uint8Array, or hex encoded string, or something with an `asUint8Array` method on it
|
|
578
|
-
* @returns PublicKey
|
|
579
|
-
*/
|
|
580
|
-
static from(source) {
|
|
581
|
-
(0, import_invariant4.invariant)(source, void 0, {
|
|
582
|
-
F: __dxlog_file4,
|
|
583
|
-
L: 49,
|
|
584
|
-
S: this,
|
|
585
|
-
A: [
|
|
586
|
-
"source",
|
|
587
|
-
""
|
|
588
|
-
]
|
|
589
|
-
});
|
|
590
|
-
if (source instanceof _PublicKey) {
|
|
591
|
-
return source;
|
|
592
|
-
} else if (source instanceof Buffer) {
|
|
593
|
-
return new _PublicKey(new Uint8Array(source.buffer, source.byteOffset, source.byteLength));
|
|
594
|
-
} else if (source instanceof Uint8Array) {
|
|
595
|
-
return new _PublicKey(source);
|
|
596
|
-
} else if (source instanceof ArrayBuffer || isLikeArrayBuffer(source)) {
|
|
597
|
-
return new _PublicKey(new Uint8Array(source));
|
|
598
|
-
} else if (typeof source === "string") {
|
|
599
|
-
return _PublicKey.fromHex(source);
|
|
600
|
-
} else if (source.asUint8Array) {
|
|
601
|
-
return new _PublicKey(source.asUint8Array());
|
|
602
|
-
} else {
|
|
603
|
-
throw new TypeError(`Unable to create PublicKey from ${source}`);
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
/**
|
|
607
|
-
* Same as `PublicKey.from` but does not throw and instead returns a `{ key: PublicKey }` or `{ error: Error }`
|
|
608
|
-
* @param source Same PublicKeyLike argument as for `PublicKey.from`
|
|
609
|
-
* @returns PublicKey
|
|
610
|
-
*/
|
|
611
|
-
static safeFrom(source) {
|
|
612
|
-
if (!source) {
|
|
613
|
-
return void 0;
|
|
614
|
-
}
|
|
615
|
-
try {
|
|
616
|
-
const key = _PublicKey.from(source);
|
|
617
|
-
return key;
|
|
618
|
-
} catch (err) {
|
|
619
|
-
return void 0;
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
/**
|
|
623
|
-
* Creates new instance of PublicKey from hex string.
|
|
624
|
-
*/
|
|
625
|
-
static fromHex(hex) {
|
|
626
|
-
if (hex.startsWith("0x")) {
|
|
627
|
-
hex = hex.slice(2);
|
|
628
|
-
}
|
|
629
|
-
const buf = Buffer.from(hex, "hex");
|
|
630
|
-
return new _PublicKey(new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength));
|
|
631
|
-
}
|
|
632
|
-
/**
|
|
633
|
-
* Creates a new key.
|
|
634
|
-
*/
|
|
635
|
-
static random() {
|
|
636
|
-
return _PublicKey.from(randomBytes(PUBLIC_KEY_LENGTH));
|
|
637
|
-
}
|
|
638
|
-
static randomOfLength(length) {
|
|
639
|
-
return _PublicKey.from(randomBytes(length));
|
|
640
|
-
}
|
|
641
|
-
static *randomSequence() {
|
|
642
|
-
for (let i = 0; i < 1e4; i++) {
|
|
643
|
-
yield _PublicKey.random();
|
|
644
|
-
}
|
|
645
|
-
throw new Error("Too many keys requested");
|
|
646
|
-
}
|
|
647
|
-
/**
|
|
648
|
-
* Tests if provided values is an instance of PublicKey.
|
|
649
|
-
*/
|
|
650
|
-
static isPublicKey(value) {
|
|
651
|
-
return value instanceof _PublicKey;
|
|
652
|
-
}
|
|
653
|
-
/**
|
|
654
|
-
* Asserts that provided values is an instance of PublicKey.
|
|
655
|
-
*/
|
|
656
|
-
static assertValidPublicKey(value) {
|
|
657
|
-
if (!this.isPublicKey(value)) {
|
|
658
|
-
throw new TypeError("Invalid PublicKey");
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
/**
|
|
662
|
-
* Tests two keys for equality.
|
|
663
|
-
*/
|
|
664
|
-
static equals(left, right) {
|
|
665
|
-
return _PublicKey.from(left).equals(right);
|
|
666
|
-
}
|
|
667
|
-
/**
|
|
668
|
-
* @param str string representation of key.
|
|
669
|
-
* @return Key buffer.
|
|
670
|
-
* @deprecated All keys should be represented as instances of PublicKey.
|
|
671
|
-
*/
|
|
672
|
-
static bufferize(str) {
|
|
673
|
-
(0, import_invariant4.invariant)(typeof str === "string", "Invalid type", {
|
|
674
|
-
F: __dxlog_file4,
|
|
675
|
-
L: 152,
|
|
676
|
-
S: this,
|
|
677
|
-
A: [
|
|
678
|
-
"typeof str === 'string'",
|
|
679
|
-
"'Invalid type'"
|
|
680
|
-
]
|
|
681
|
-
});
|
|
682
|
-
const buffer = Buffer.from(str, "hex");
|
|
683
|
-
return buffer;
|
|
684
|
-
}
|
|
685
|
-
/**
|
|
686
|
-
* @param key key like data structure (but not PublicKey which should use toString).
|
|
687
|
-
* @return Hex string representation of key.
|
|
688
|
-
* @deprecated All keys should be represented as instances of PublicKey.
|
|
689
|
-
*/
|
|
690
|
-
static stringify(key) {
|
|
691
|
-
if (key instanceof _PublicKey) {
|
|
692
|
-
key = key.asBuffer();
|
|
693
|
-
} else if (key instanceof Uint8Array) {
|
|
694
|
-
key = Buffer.from(key.buffer, key.byteOffset, key.byteLength);
|
|
695
|
-
}
|
|
696
|
-
(0, import_invariant4.invariant)(key instanceof Buffer, "Invalid type", {
|
|
697
|
-
F: __dxlog_file4,
|
|
698
|
-
L: 171,
|
|
699
|
-
S: this,
|
|
700
|
-
A: [
|
|
701
|
-
"key instanceof Buffer",
|
|
702
|
-
"'Invalid type'"
|
|
703
|
-
]
|
|
704
|
-
});
|
|
705
|
-
return key.toString("hex");
|
|
706
|
-
}
|
|
707
|
-
/**
|
|
708
|
-
* To be used with ComplexMap and ComplexSet.
|
|
709
|
-
* Returns a scalar representation for this key.
|
|
710
|
-
*/
|
|
711
|
-
static hash(key) {
|
|
712
|
-
return key.toHex();
|
|
713
|
-
}
|
|
714
|
-
static fromMultibase32(encoded) {
|
|
715
|
-
(0, import_invariant4.invariant)(encoded.startsWith("B"), "Invalid multibase32 encoding", {
|
|
716
|
-
F: __dxlog_file4,
|
|
717
|
-
L: 184,
|
|
718
|
-
S: this,
|
|
719
|
-
A: [
|
|
720
|
-
"encoded.startsWith('B')",
|
|
721
|
-
"'Invalid multibase32 encoding'"
|
|
722
|
-
]
|
|
723
|
-
});
|
|
724
|
-
return new _PublicKey(new Uint8Array((0, import_base32_decode3.default)(encoded.slice(1), "RFC4648")));
|
|
725
|
-
}
|
|
726
|
-
constructor(_value) {
|
|
727
|
-
this._value = _value;
|
|
728
|
-
if (!(_value instanceof Uint8Array)) {
|
|
729
|
-
throw new TypeError(`Expected Uint8Array, got: ${_value}`);
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
toString() {
|
|
733
|
-
return this.toHex();
|
|
734
|
-
}
|
|
735
|
-
toJSON() {
|
|
736
|
-
return this.toHex();
|
|
737
|
-
}
|
|
738
|
-
toJSONL() {
|
|
739
|
-
return this.truncate();
|
|
740
|
-
}
|
|
741
|
-
get length() {
|
|
742
|
-
return this._value.length;
|
|
743
|
-
}
|
|
744
|
-
toHex() {
|
|
745
|
-
return this.asBuffer().toString("hex");
|
|
746
|
-
}
|
|
747
|
-
toMultibase32() {
|
|
748
|
-
return "B" + base32Encode(this._value, "RFC4648");
|
|
749
|
-
}
|
|
750
|
-
truncate(length = void 0) {
|
|
751
|
-
return (0, import_debug2.truncateKey)(this, length);
|
|
752
|
-
}
|
|
753
|
-
asBuffer() {
|
|
754
|
-
return Buffer.from(this._value.buffer, this._value.byteOffset, this._value.byteLength);
|
|
755
|
-
}
|
|
756
|
-
asUint8Array() {
|
|
757
|
-
return this._value;
|
|
758
|
-
}
|
|
759
|
-
getInsecureHash(modulo) {
|
|
760
|
-
return Math.abs(this._value.reduce((acc, val) => acc ^ val | 0, 0)) % modulo;
|
|
761
|
-
}
|
|
762
|
-
/**
|
|
763
|
-
* Used by Node.js to get textual representation of this object when it's printed with a `console.log` statement.
|
|
764
|
-
*/
|
|
765
|
-
[import_debug2.inspectCustom](depth, options, inspectFn) {
|
|
766
|
-
if (!options.colors || typeof process.stdout.hasColors !== "function" || !process.stdout.hasColors()) {
|
|
767
|
-
return `<PublicKey ${this.truncate()}>`;
|
|
768
|
-
}
|
|
769
|
-
const printControlCode = (code) => {
|
|
770
|
-
return `\x1B[${code}m`;
|
|
771
|
-
};
|
|
772
|
-
const colors = [
|
|
773
|
-
"red",
|
|
774
|
-
"green",
|
|
775
|
-
"yellow",
|
|
776
|
-
"blue",
|
|
777
|
-
"magenta",
|
|
778
|
-
"cyan",
|
|
779
|
-
"redBright",
|
|
780
|
-
"greenBright",
|
|
781
|
-
"yellowBright",
|
|
782
|
-
"blueBright",
|
|
783
|
-
"magentaBright",
|
|
784
|
-
"cyanBright",
|
|
785
|
-
"whiteBright"
|
|
786
|
-
];
|
|
787
|
-
const color = colors[this.getInsecureHash(colors.length)];
|
|
788
|
-
return `PublicKey(${printControlCode(inspectFn.colors[color][0])}${this.truncate()}${printControlCode(inspectFn.colors.reset[0])})`;
|
|
789
|
-
}
|
|
790
|
-
get [import_debug2.devtoolsFormatter]() {
|
|
791
|
-
return {
|
|
792
|
-
header: () => {
|
|
793
|
-
const colors = [
|
|
794
|
-
"darkred",
|
|
795
|
-
"green",
|
|
796
|
-
"orange",
|
|
797
|
-
"blue",
|
|
798
|
-
"darkmagenta",
|
|
799
|
-
"darkcyan",
|
|
800
|
-
"red",
|
|
801
|
-
"green",
|
|
802
|
-
"orange",
|
|
803
|
-
"blue",
|
|
804
|
-
"magenta",
|
|
805
|
-
"darkcyan",
|
|
806
|
-
"black"
|
|
807
|
-
];
|
|
808
|
-
const color = colors[this.getInsecureHash(colors.length)];
|
|
809
|
-
return [
|
|
810
|
-
"span",
|
|
811
|
-
{},
|
|
812
|
-
[
|
|
813
|
-
"span",
|
|
814
|
-
{},
|
|
815
|
-
"PublicKey("
|
|
816
|
-
],
|
|
817
|
-
[
|
|
818
|
-
"span",
|
|
819
|
-
{
|
|
820
|
-
style: `color: ${color};`
|
|
821
|
-
},
|
|
822
|
-
this.truncate()
|
|
823
|
-
],
|
|
824
|
-
[
|
|
825
|
-
"span",
|
|
826
|
-
{},
|
|
827
|
-
")"
|
|
828
|
-
]
|
|
829
|
-
];
|
|
830
|
-
}
|
|
831
|
-
};
|
|
832
|
-
}
|
|
833
|
-
/**
|
|
834
|
-
* Test this key for equality with some other key.
|
|
835
|
-
*/
|
|
836
|
-
equals(other) {
|
|
837
|
-
const otherConverted = _PublicKey.from(other);
|
|
838
|
-
if (this._value.length !== otherConverted._value.length) {
|
|
839
|
-
return false;
|
|
840
|
-
}
|
|
841
|
-
let equal = true;
|
|
842
|
-
for (let i = 0; i < this._value.length; i++) {
|
|
843
|
-
equal &&= this._value[i] === otherConverted._value[i];
|
|
844
|
-
}
|
|
845
|
-
return equal;
|
|
846
|
-
}
|
|
847
|
-
[import_debug2.equalsSymbol](other) {
|
|
848
|
-
if (!_PublicKey.isPublicKey(other)) {
|
|
849
|
-
return false;
|
|
850
|
-
}
|
|
851
|
-
return this.equals(other);
|
|
852
|
-
}
|
|
853
|
-
};
|
|
854
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
855
|
-
0 && (module.exports = {
|
|
856
|
-
DXN,
|
|
857
|
-
IdentityDid,
|
|
858
|
-
LOCAL_SPACE_TAG,
|
|
859
|
-
ObjectId,
|
|
860
|
-
PUBLIC_KEY_LENGTH,
|
|
861
|
-
PublicKey,
|
|
862
|
-
QueueSubspaceTags,
|
|
863
|
-
SECRET_KEY_LENGTH,
|
|
864
|
-
SpaceId
|
|
865
|
-
});
|
|
866
|
-
//# sourceMappingURL=index.cjs.map
|