@tinycloud/sdk-core 2.7.0-beta.2 → 2.7.0-beta.4
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/{capability-Dbx-xqUh.d.cts → capability-BjzXwtNw.d.cts} +2 -1
- package/dist/{capability-Dbx-xqUh.d.ts → capability-BjzXwtNw.d.ts} +2 -1
- package/dist/index.cjs +3271 -358
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +392 -18
- package/dist/index.d.ts +392 -18
- package/dist/index.js +3266 -350
- package/dist/index.js.map +1 -1
- package/dist/policy/index.cjs +1217 -59
- package/dist/policy/index.cjs.map +1 -1
- package/dist/policy/index.d.cts +4 -4
- package/dist/policy/index.d.ts +4 -4
- package/dist/policy/index.js +1208 -54
- package/dist/policy/index.js.map +1 -1
- package/dist/requester/index.cjs +1234 -78
- package/dist/requester/index.cjs.map +1 -1
- package/dist/requester/index.d.cts +1 -1
- package/dist/requester/index.d.ts +1 -1
- package/dist/requester/index.js +1227 -75
- package/dist/requester/index.js.map +1 -1
- package/dist/{signed-object-C9Gur3ZY.d.ts → signed-object-C6mWbTbB.d.ts} +1 -1
- package/dist/{signed-object-Cy_81K45.d.cts → signed-object-IMAm5a32.d.cts} +1 -1
- package/package.json +6 -3
package/dist/index.cjs
CHANGED
|
@@ -5,15 +5,19 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __typeError = (msg) => {
|
|
9
|
+
throw TypeError(msg);
|
|
10
|
+
};
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
12
|
var __export = (target, all) => {
|
|
9
|
-
for (var
|
|
10
|
-
__defProp(target,
|
|
13
|
+
for (var name2 in all)
|
|
14
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
11
15
|
};
|
|
12
|
-
var __copyProps = (to,
|
|
13
|
-
if (
|
|
14
|
-
for (let key of __getOwnPropNames(
|
|
16
|
+
var __copyProps = (to, from3, except, desc) => {
|
|
17
|
+
if (from3 && typeof from3 === "object" || typeof from3 === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from3))
|
|
15
19
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () =>
|
|
20
|
+
__defProp(to, key, { get: () => from3[key], enumerable: !(desc = __getOwnPropDesc(from3, key)) || desc.enumerable });
|
|
17
21
|
}
|
|
18
22
|
return to;
|
|
19
23
|
};
|
|
@@ -26,6 +30,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
30
|
mod
|
|
27
31
|
));
|
|
28
32
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
34
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
35
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
36
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
37
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
29
38
|
|
|
30
39
|
// src/index.ts
|
|
31
40
|
var index_exports = {};
|
|
@@ -49,6 +58,7 @@ __export(index_exports, {
|
|
|
49
58
|
CAPABILITY_REGISTRY: () => import_bootstrap3.CAPABILITY_REGISTRY,
|
|
50
59
|
CapabilityKeyRegistry: () => CapabilityKeyRegistry,
|
|
51
60
|
CapabilityKeyRegistryErrorCodes: () => CapabilityKeyRegistryErrorCodes,
|
|
61
|
+
CaveatedDelegationUnsupportedError: () => CaveatedDelegationUnsupportedError,
|
|
52
62
|
ClientSessionSchema: () => ClientSessionSchema,
|
|
53
63
|
CloudLocationResolutionError: () => CloudLocationResolutionError,
|
|
54
64
|
DECRYPT_ACTION: () => import_sdk_services7.DECRYPT_ACTION,
|
|
@@ -67,6 +77,7 @@ __export(index_exports, {
|
|
|
67
77
|
DUCKDB: () => import_bootstrap3.DUCKDB,
|
|
68
78
|
DataVaultService: () => import_sdk_services7.DataVaultService,
|
|
69
79
|
DatabaseHandle: () => import_sdk_services7.DatabaseHandle,
|
|
80
|
+
DecryptTransportResponseError: () => import_sdk_services7.DecryptTransportResponseError,
|
|
70
81
|
DelegationErrorCodes: () => DelegationErrorCodes,
|
|
71
82
|
DelegationManager: () => DelegationManager,
|
|
72
83
|
DuckDbAction: () => import_sdk_services7.DuckDbAction,
|
|
@@ -174,6 +185,7 @@ __export(index_exports, {
|
|
|
174
185
|
canonicalizeDidUrl: () => canonicalizeDidUrl,
|
|
175
186
|
canonicalizeEncryptionJson: () => import_sdk_services7.canonicalizeEncryptionJson,
|
|
176
187
|
canonicalizeNetworkId: () => canonicalizeNetworkId,
|
|
188
|
+
canonicalizeRecapCaveats: () => canonicalizeRecapCaveats,
|
|
177
189
|
canonicalizeSecretScope: () => import_sdk_services7.canonicalizeSecretScope,
|
|
178
190
|
canonicalizeSignedObjectUnsigned: () => canonicalizeSignedObjectUnsigned,
|
|
179
191
|
checkDecryptInvocationInput: () => import_sdk_services7.checkDecryptInvocationInput,
|
|
@@ -247,6 +259,7 @@ __export(index_exports, {
|
|
|
247
259
|
pkhDid: () => pkhDid,
|
|
248
260
|
principalDid: () => principalDid,
|
|
249
261
|
principalDidEquals: () => principalDidEquals,
|
|
262
|
+
recapCaveatsEqual: () => recapCaveatsEqual,
|
|
250
263
|
resolveCloudLocation: () => resolveCloudLocation,
|
|
251
264
|
resolveManifest: () => resolveManifest,
|
|
252
265
|
resolveManifestKnowledgeRoot: () => resolveManifestKnowledgeRoot,
|
|
@@ -399,40 +412,945 @@ function canonicalizeDidUrl(didUrl) {
|
|
|
399
412
|
function principalDid(didUrl) {
|
|
400
413
|
return canonicalizeDid(splitDidUrl(didUrl).did);
|
|
401
414
|
}
|
|
402
|
-
function didEquals(a, b,
|
|
403
|
-
const canonicalize =
|
|
415
|
+
function didEquals(a, b, options2 = {}) {
|
|
416
|
+
const canonicalize = options2.ignoreFragment ? principalDid : canonicalizeDidUrl;
|
|
404
417
|
return canonicalize(a) === canonicalize(b);
|
|
405
418
|
}
|
|
406
419
|
function principalDidEquals(a, b) {
|
|
407
420
|
return didEquals(a, b, { ignoreFragment: true });
|
|
408
421
|
}
|
|
409
|
-
function didCacheKey(input,
|
|
422
|
+
function didCacheKey(input, options2 = {}) {
|
|
410
423
|
const { did, fragment } = splitDidUrl(input);
|
|
411
424
|
const pkh = parsePkhDid(did);
|
|
412
|
-
const
|
|
413
|
-
return
|
|
425
|
+
const base3 = pkh ? `did:pkh:eip155:${pkh.chainId}:${addressStorageKey(pkh.address)}` : canonicalizeDid(did);
|
|
426
|
+
return options2.preserveFragment ? `${base3}${fragment}` : base3;
|
|
414
427
|
}
|
|
415
|
-
function makePkhSpaceId(address, chainId,
|
|
428
|
+
function makePkhSpaceId(address, chainId, name2) {
|
|
416
429
|
assertValidChainId(chainId);
|
|
417
|
-
if (!
|
|
430
|
+
if (!name2) {
|
|
418
431
|
throw new IdentityParseError("Space name cannot be empty");
|
|
419
432
|
}
|
|
420
|
-
return `tinycloud:pkh:eip155:${chainId}:${canonicalizeAddress(address)}:${
|
|
433
|
+
return `tinycloud:pkh:eip155:${chainId}:${canonicalizeAddress(address)}:${name2}`;
|
|
421
434
|
}
|
|
422
435
|
|
|
423
436
|
// src/requester/index.ts
|
|
424
437
|
var import_viem4 = require("viem");
|
|
425
438
|
var import_blake3 = require("@noble/hashes/blake3");
|
|
426
|
-
|
|
427
|
-
|
|
439
|
+
|
|
440
|
+
// ../../node_modules/multiformats/dist/src/bases/base32.js
|
|
441
|
+
var base32_exports = {};
|
|
442
|
+
__export(base32_exports, {
|
|
443
|
+
base32: () => base32,
|
|
444
|
+
base32hex: () => base32hex,
|
|
445
|
+
base32hexpad: () => base32hexpad,
|
|
446
|
+
base32hexpadupper: () => base32hexpadupper,
|
|
447
|
+
base32hexupper: () => base32hexupper,
|
|
448
|
+
base32pad: () => base32pad,
|
|
449
|
+
base32padupper: () => base32padupper,
|
|
450
|
+
base32upper: () => base32upper,
|
|
451
|
+
base32z: () => base32z
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
// ../../node_modules/multiformats/dist/src/bytes.js
|
|
455
|
+
var empty = new Uint8Array(0);
|
|
456
|
+
function equals(aa, bb) {
|
|
457
|
+
if (aa === bb) {
|
|
458
|
+
return true;
|
|
459
|
+
}
|
|
460
|
+
if (aa.byteLength !== bb.byteLength) {
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
463
|
+
for (let ii = 0; ii < aa.byteLength; ii++) {
|
|
464
|
+
if (aa[ii] !== bb[ii]) {
|
|
465
|
+
return false;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return true;
|
|
469
|
+
}
|
|
470
|
+
function coerce(o) {
|
|
471
|
+
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array") {
|
|
472
|
+
return o;
|
|
473
|
+
}
|
|
474
|
+
if (o instanceof ArrayBuffer) {
|
|
475
|
+
return new Uint8Array(o);
|
|
476
|
+
}
|
|
477
|
+
if (ArrayBuffer.isView(o)) {
|
|
478
|
+
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
|
|
479
|
+
}
|
|
480
|
+
throw new Error("Unknown type, must be binary type");
|
|
481
|
+
}
|
|
482
|
+
function fromString(str) {
|
|
483
|
+
return new TextEncoder().encode(str);
|
|
484
|
+
}
|
|
485
|
+
function toString(b) {
|
|
486
|
+
return new TextDecoder().decode(b);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// ../../node_modules/multiformats/dist/src/vendor/base-x.js
|
|
490
|
+
function base(ALPHABET, name2) {
|
|
491
|
+
if (ALPHABET.length >= 255) {
|
|
492
|
+
throw new TypeError("Alphabet too long");
|
|
493
|
+
}
|
|
494
|
+
var BASE_MAP = new Uint8Array(256);
|
|
495
|
+
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
496
|
+
BASE_MAP[j] = 255;
|
|
497
|
+
}
|
|
498
|
+
for (var i = 0; i < ALPHABET.length; i++) {
|
|
499
|
+
var x = ALPHABET.charAt(i);
|
|
500
|
+
var xc = x.charCodeAt(0);
|
|
501
|
+
if (BASE_MAP[xc] !== 255) {
|
|
502
|
+
throw new TypeError(x + " is ambiguous");
|
|
503
|
+
}
|
|
504
|
+
BASE_MAP[xc] = i;
|
|
505
|
+
}
|
|
506
|
+
var BASE = ALPHABET.length;
|
|
507
|
+
var LEADER = ALPHABET.charAt(0);
|
|
508
|
+
var FACTOR = Math.log(BASE) / Math.log(256);
|
|
509
|
+
var iFACTOR = Math.log(256) / Math.log(BASE);
|
|
510
|
+
function encode5(source) {
|
|
511
|
+
if (source instanceof Uint8Array)
|
|
512
|
+
;
|
|
513
|
+
else if (ArrayBuffer.isView(source)) {
|
|
514
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
515
|
+
} else if (Array.isArray(source)) {
|
|
516
|
+
source = Uint8Array.from(source);
|
|
517
|
+
}
|
|
518
|
+
if (!(source instanceof Uint8Array)) {
|
|
519
|
+
throw new TypeError("Expected Uint8Array");
|
|
520
|
+
}
|
|
521
|
+
if (source.length === 0) {
|
|
522
|
+
return "";
|
|
523
|
+
}
|
|
524
|
+
var zeroes = 0;
|
|
525
|
+
var length2 = 0;
|
|
526
|
+
var pbegin = 0;
|
|
527
|
+
var pend = source.length;
|
|
528
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
529
|
+
pbegin++;
|
|
530
|
+
zeroes++;
|
|
531
|
+
}
|
|
532
|
+
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
533
|
+
var b58 = new Uint8Array(size);
|
|
534
|
+
while (pbegin !== pend) {
|
|
535
|
+
var carry = source[pbegin];
|
|
536
|
+
var i2 = 0;
|
|
537
|
+
for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
|
|
538
|
+
carry += 256 * b58[it1] >>> 0;
|
|
539
|
+
b58[it1] = carry % BASE >>> 0;
|
|
540
|
+
carry = carry / BASE >>> 0;
|
|
541
|
+
}
|
|
542
|
+
if (carry !== 0) {
|
|
543
|
+
throw new Error("Non-zero carry");
|
|
544
|
+
}
|
|
545
|
+
length2 = i2;
|
|
546
|
+
pbegin++;
|
|
547
|
+
}
|
|
548
|
+
var it2 = size - length2;
|
|
549
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
550
|
+
it2++;
|
|
551
|
+
}
|
|
552
|
+
var str = LEADER.repeat(zeroes);
|
|
553
|
+
for (; it2 < size; ++it2) {
|
|
554
|
+
str += ALPHABET.charAt(b58[it2]);
|
|
555
|
+
}
|
|
556
|
+
return str;
|
|
557
|
+
}
|
|
558
|
+
function decodeUnsafe(source) {
|
|
559
|
+
if (typeof source !== "string") {
|
|
560
|
+
throw new TypeError("Expected String");
|
|
561
|
+
}
|
|
562
|
+
if (source.length === 0) {
|
|
563
|
+
return new Uint8Array();
|
|
564
|
+
}
|
|
565
|
+
var psz = 0;
|
|
566
|
+
if (source[psz] === " ") {
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
var zeroes = 0;
|
|
570
|
+
var length2 = 0;
|
|
571
|
+
while (source[psz] === LEADER) {
|
|
572
|
+
zeroes++;
|
|
573
|
+
psz++;
|
|
574
|
+
}
|
|
575
|
+
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
576
|
+
var b256 = new Uint8Array(size);
|
|
577
|
+
while (source[psz]) {
|
|
578
|
+
var carry = BASE_MAP[source.charCodeAt(psz)];
|
|
579
|
+
if (carry === 255) {
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
var i2 = 0;
|
|
583
|
+
for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
|
|
584
|
+
carry += BASE * b256[it3] >>> 0;
|
|
585
|
+
b256[it3] = carry % 256 >>> 0;
|
|
586
|
+
carry = carry / 256 >>> 0;
|
|
587
|
+
}
|
|
588
|
+
if (carry !== 0) {
|
|
589
|
+
throw new Error("Non-zero carry");
|
|
590
|
+
}
|
|
591
|
+
length2 = i2;
|
|
592
|
+
psz++;
|
|
593
|
+
}
|
|
594
|
+
if (source[psz] === " ") {
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
var it4 = size - length2;
|
|
598
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
599
|
+
it4++;
|
|
600
|
+
}
|
|
601
|
+
var vch = new Uint8Array(zeroes + (size - it4));
|
|
602
|
+
var j2 = zeroes;
|
|
603
|
+
while (it4 !== size) {
|
|
604
|
+
vch[j2++] = b256[it4++];
|
|
605
|
+
}
|
|
606
|
+
return vch;
|
|
607
|
+
}
|
|
608
|
+
function decode7(string2) {
|
|
609
|
+
var buffer = decodeUnsafe(string2);
|
|
610
|
+
if (buffer) {
|
|
611
|
+
return buffer;
|
|
612
|
+
}
|
|
613
|
+
throw new Error(`Non-${name2} character`);
|
|
614
|
+
}
|
|
615
|
+
return {
|
|
616
|
+
encode: encode5,
|
|
617
|
+
decodeUnsafe,
|
|
618
|
+
decode: decode7
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
var src = base;
|
|
622
|
+
var _brrp__multiformats_scope_baseX = src;
|
|
623
|
+
var base_x_default = _brrp__multiformats_scope_baseX;
|
|
624
|
+
|
|
625
|
+
// ../../node_modules/multiformats/dist/src/bases/base.js
|
|
626
|
+
var Encoder = class {
|
|
627
|
+
constructor(name2, prefix, baseEncode) {
|
|
628
|
+
__publicField(this, "name");
|
|
629
|
+
__publicField(this, "prefix");
|
|
630
|
+
__publicField(this, "baseEncode");
|
|
631
|
+
this.name = name2;
|
|
632
|
+
this.prefix = prefix;
|
|
633
|
+
this.baseEncode = baseEncode;
|
|
634
|
+
}
|
|
635
|
+
encode(bytes) {
|
|
636
|
+
if (bytes instanceof Uint8Array) {
|
|
637
|
+
return `${this.prefix}${this.baseEncode(bytes)}`;
|
|
638
|
+
} else {
|
|
639
|
+
throw Error("Unknown type, must be binary type");
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
var Decoder = class {
|
|
644
|
+
constructor(name2, prefix, baseDecode) {
|
|
645
|
+
__publicField(this, "name");
|
|
646
|
+
__publicField(this, "prefix");
|
|
647
|
+
__publicField(this, "baseDecode");
|
|
648
|
+
__publicField(this, "prefixCodePoint");
|
|
649
|
+
this.name = name2;
|
|
650
|
+
this.prefix = prefix;
|
|
651
|
+
const prefixCodePoint = prefix.codePointAt(0);
|
|
652
|
+
if (prefixCodePoint === void 0) {
|
|
653
|
+
throw new Error("Invalid prefix character");
|
|
654
|
+
}
|
|
655
|
+
this.prefixCodePoint = prefixCodePoint;
|
|
656
|
+
this.baseDecode = baseDecode;
|
|
657
|
+
}
|
|
658
|
+
decode(text) {
|
|
659
|
+
if (typeof text === "string") {
|
|
660
|
+
if (text.codePointAt(0) !== this.prefixCodePoint) {
|
|
661
|
+
throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
|
|
662
|
+
}
|
|
663
|
+
return this.baseDecode(text.slice(this.prefix.length));
|
|
664
|
+
} else {
|
|
665
|
+
throw Error("Can only multibase decode strings");
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
or(decoder) {
|
|
669
|
+
return or(this, decoder);
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
var ComposedDecoder = class {
|
|
673
|
+
constructor(decoders2) {
|
|
674
|
+
__publicField(this, "decoders");
|
|
675
|
+
this.decoders = decoders2;
|
|
676
|
+
}
|
|
677
|
+
or(decoder) {
|
|
678
|
+
return or(this, decoder);
|
|
679
|
+
}
|
|
680
|
+
decode(input) {
|
|
681
|
+
const prefix = input[0];
|
|
682
|
+
const decoder = this.decoders[prefix];
|
|
683
|
+
if (decoder != null) {
|
|
684
|
+
return decoder.decode(input);
|
|
685
|
+
} else {
|
|
686
|
+
throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
function or(left, right) {
|
|
691
|
+
return new ComposedDecoder({
|
|
692
|
+
...left.decoders ?? { [left.prefix]: left },
|
|
693
|
+
...right.decoders ?? { [right.prefix]: right }
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
var Codec = class {
|
|
697
|
+
constructor(name2, prefix, baseEncode, baseDecode) {
|
|
698
|
+
__publicField(this, "name");
|
|
699
|
+
__publicField(this, "prefix");
|
|
700
|
+
__publicField(this, "baseEncode");
|
|
701
|
+
__publicField(this, "baseDecode");
|
|
702
|
+
__publicField(this, "encoder");
|
|
703
|
+
__publicField(this, "decoder");
|
|
704
|
+
this.name = name2;
|
|
705
|
+
this.prefix = prefix;
|
|
706
|
+
this.baseEncode = baseEncode;
|
|
707
|
+
this.baseDecode = baseDecode;
|
|
708
|
+
this.encoder = new Encoder(name2, prefix, baseEncode);
|
|
709
|
+
this.decoder = new Decoder(name2, prefix, baseDecode);
|
|
710
|
+
}
|
|
711
|
+
encode(input) {
|
|
712
|
+
return this.encoder.encode(input);
|
|
713
|
+
}
|
|
714
|
+
decode(input) {
|
|
715
|
+
return this.decoder.decode(input);
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
function from({ name: name2, prefix, encode: encode5, decode: decode7 }) {
|
|
719
|
+
return new Codec(name2, prefix, encode5, decode7);
|
|
720
|
+
}
|
|
721
|
+
function baseX({ name: name2, prefix, alphabet: alphabet2 }) {
|
|
722
|
+
const { encode: encode5, decode: decode7 } = base_x_default(alphabet2, name2);
|
|
723
|
+
return from({
|
|
724
|
+
prefix,
|
|
725
|
+
name: name2,
|
|
726
|
+
encode: encode5,
|
|
727
|
+
decode: (text) => coerce(decode7(text))
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
function decode(string2, alphabetIdx, bitsPerChar, name2) {
|
|
731
|
+
let end = string2.length;
|
|
732
|
+
while (string2[end - 1] === "=") {
|
|
733
|
+
--end;
|
|
734
|
+
}
|
|
735
|
+
const out = new Uint8Array(end * bitsPerChar / 8 | 0);
|
|
736
|
+
let bits = 0;
|
|
737
|
+
let buffer = 0;
|
|
738
|
+
let written = 0;
|
|
739
|
+
for (let i = 0; i < end; ++i) {
|
|
740
|
+
const value = alphabetIdx[string2[i]];
|
|
741
|
+
if (value === void 0) {
|
|
742
|
+
throw new SyntaxError(`Non-${name2} character`);
|
|
743
|
+
}
|
|
744
|
+
buffer = buffer << bitsPerChar | value;
|
|
745
|
+
bits += bitsPerChar;
|
|
746
|
+
if (bits >= 8) {
|
|
747
|
+
bits -= 8;
|
|
748
|
+
out[written++] = 255 & buffer >> bits;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
if (bits >= bitsPerChar || (255 & buffer << 8 - bits) !== 0) {
|
|
752
|
+
throw new SyntaxError("Unexpected end of data");
|
|
753
|
+
}
|
|
754
|
+
return out;
|
|
755
|
+
}
|
|
756
|
+
function encode(data, alphabet2, bitsPerChar) {
|
|
757
|
+
const pad = alphabet2[alphabet2.length - 1] === "=";
|
|
758
|
+
const mask = (1 << bitsPerChar) - 1;
|
|
759
|
+
let out = "";
|
|
760
|
+
let bits = 0;
|
|
761
|
+
let buffer = 0;
|
|
762
|
+
for (let i = 0; i < data.length; ++i) {
|
|
763
|
+
buffer = buffer << 8 | data[i];
|
|
764
|
+
bits += 8;
|
|
765
|
+
while (bits > bitsPerChar) {
|
|
766
|
+
bits -= bitsPerChar;
|
|
767
|
+
out += alphabet2[mask & buffer >> bits];
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
if (bits !== 0) {
|
|
771
|
+
out += alphabet2[mask & buffer << bitsPerChar - bits];
|
|
772
|
+
}
|
|
773
|
+
if (pad) {
|
|
774
|
+
while ((out.length * bitsPerChar & 7) !== 0) {
|
|
775
|
+
out += "=";
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
return out;
|
|
779
|
+
}
|
|
780
|
+
function createAlphabetIdx(alphabet2) {
|
|
781
|
+
const alphabetIdx = {};
|
|
782
|
+
for (let i = 0; i < alphabet2.length; ++i) {
|
|
783
|
+
alphabetIdx[alphabet2[i]] = i;
|
|
784
|
+
}
|
|
785
|
+
return alphabetIdx;
|
|
786
|
+
}
|
|
787
|
+
function rfc4648({ name: name2, prefix, bitsPerChar, alphabet: alphabet2 }) {
|
|
788
|
+
const alphabetIdx = createAlphabetIdx(alphabet2);
|
|
789
|
+
return from({
|
|
790
|
+
prefix,
|
|
791
|
+
name: name2,
|
|
792
|
+
encode(input) {
|
|
793
|
+
return encode(input, alphabet2, bitsPerChar);
|
|
794
|
+
},
|
|
795
|
+
decode(input) {
|
|
796
|
+
return decode(input, alphabetIdx, bitsPerChar, name2);
|
|
797
|
+
}
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
// ../../node_modules/multiformats/dist/src/bases/base32.js
|
|
802
|
+
var base32 = rfc4648({
|
|
803
|
+
prefix: "b",
|
|
804
|
+
name: "base32",
|
|
805
|
+
alphabet: "abcdefghijklmnopqrstuvwxyz234567",
|
|
806
|
+
bitsPerChar: 5
|
|
807
|
+
});
|
|
808
|
+
var base32upper = rfc4648({
|
|
809
|
+
prefix: "B",
|
|
810
|
+
name: "base32upper",
|
|
811
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
|
|
812
|
+
bitsPerChar: 5
|
|
813
|
+
});
|
|
814
|
+
var base32pad = rfc4648({
|
|
815
|
+
prefix: "c",
|
|
816
|
+
name: "base32pad",
|
|
817
|
+
alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
|
|
818
|
+
bitsPerChar: 5
|
|
819
|
+
});
|
|
820
|
+
var base32padupper = rfc4648({
|
|
821
|
+
prefix: "C",
|
|
822
|
+
name: "base32padupper",
|
|
823
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
|
|
824
|
+
bitsPerChar: 5
|
|
825
|
+
});
|
|
826
|
+
var base32hex = rfc4648({
|
|
827
|
+
prefix: "v",
|
|
828
|
+
name: "base32hex",
|
|
829
|
+
alphabet: "0123456789abcdefghijklmnopqrstuv",
|
|
830
|
+
bitsPerChar: 5
|
|
831
|
+
});
|
|
832
|
+
var base32hexupper = rfc4648({
|
|
833
|
+
prefix: "V",
|
|
834
|
+
name: "base32hexupper",
|
|
835
|
+
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
|
|
836
|
+
bitsPerChar: 5
|
|
837
|
+
});
|
|
838
|
+
var base32hexpad = rfc4648({
|
|
839
|
+
prefix: "t",
|
|
840
|
+
name: "base32hexpad",
|
|
841
|
+
alphabet: "0123456789abcdefghijklmnopqrstuv=",
|
|
842
|
+
bitsPerChar: 5
|
|
843
|
+
});
|
|
844
|
+
var base32hexpadupper = rfc4648({
|
|
845
|
+
prefix: "T",
|
|
846
|
+
name: "base32hexpadupper",
|
|
847
|
+
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
|
|
848
|
+
bitsPerChar: 5
|
|
849
|
+
});
|
|
850
|
+
var base32z = rfc4648({
|
|
851
|
+
prefix: "h",
|
|
852
|
+
name: "base32z",
|
|
853
|
+
alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
|
|
854
|
+
bitsPerChar: 5
|
|
855
|
+
});
|
|
856
|
+
|
|
857
|
+
// ../../node_modules/multiformats/dist/src/bases/base36.js
|
|
858
|
+
var base36_exports = {};
|
|
859
|
+
__export(base36_exports, {
|
|
860
|
+
base36: () => base36,
|
|
861
|
+
base36upper: () => base36upper
|
|
862
|
+
});
|
|
863
|
+
var base36 = baseX({
|
|
864
|
+
prefix: "k",
|
|
865
|
+
name: "base36",
|
|
866
|
+
alphabet: "0123456789abcdefghijklmnopqrstuvwxyz"
|
|
867
|
+
});
|
|
868
|
+
var base36upper = baseX({
|
|
869
|
+
prefix: "K",
|
|
870
|
+
name: "base36upper",
|
|
871
|
+
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
872
|
+
});
|
|
873
|
+
|
|
874
|
+
// ../../node_modules/multiformats/dist/src/bases/base58.js
|
|
875
|
+
var base58_exports = {};
|
|
876
|
+
__export(base58_exports, {
|
|
877
|
+
base58btc: () => base58btc,
|
|
878
|
+
base58flickr: () => base58flickr
|
|
879
|
+
});
|
|
880
|
+
var base58btc = baseX({
|
|
881
|
+
name: "base58btc",
|
|
882
|
+
prefix: "z",
|
|
883
|
+
alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
|
884
|
+
});
|
|
885
|
+
var base58flickr = baseX({
|
|
886
|
+
name: "base58flickr",
|
|
887
|
+
prefix: "Z",
|
|
888
|
+
alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
|
|
889
|
+
});
|
|
890
|
+
|
|
891
|
+
// ../../node_modules/multiformats/dist/src/vendor/varint.js
|
|
892
|
+
var encode_1 = encode2;
|
|
893
|
+
var MSB = 128;
|
|
894
|
+
var REST = 127;
|
|
895
|
+
var MSBALL = ~REST;
|
|
896
|
+
var INT = Math.pow(2, 31);
|
|
897
|
+
function encode2(num, out, offset) {
|
|
898
|
+
out = out || [];
|
|
899
|
+
offset = offset || 0;
|
|
900
|
+
var oldOffset = offset;
|
|
901
|
+
while (num >= INT) {
|
|
902
|
+
out[offset++] = num & 255 | MSB;
|
|
903
|
+
num /= 128;
|
|
904
|
+
}
|
|
905
|
+
while (num & MSBALL) {
|
|
906
|
+
out[offset++] = num & 255 | MSB;
|
|
907
|
+
num >>>= 7;
|
|
908
|
+
}
|
|
909
|
+
out[offset] = num | 0;
|
|
910
|
+
encode2.bytes = offset - oldOffset + 1;
|
|
911
|
+
return out;
|
|
912
|
+
}
|
|
913
|
+
var decode2 = read;
|
|
914
|
+
var MSB$1 = 128;
|
|
915
|
+
var REST$1 = 127;
|
|
916
|
+
function read(buf, offset) {
|
|
917
|
+
var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
|
|
918
|
+
do {
|
|
919
|
+
if (counter >= l) {
|
|
920
|
+
read.bytes = 0;
|
|
921
|
+
throw new RangeError("Could not decode varint");
|
|
922
|
+
}
|
|
923
|
+
b = buf[counter++];
|
|
924
|
+
res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
|
|
925
|
+
shift += 7;
|
|
926
|
+
} while (b >= MSB$1);
|
|
927
|
+
read.bytes = counter - offset;
|
|
928
|
+
return res;
|
|
929
|
+
}
|
|
930
|
+
var N1 = Math.pow(2, 7);
|
|
931
|
+
var N2 = Math.pow(2, 14);
|
|
932
|
+
var N3 = Math.pow(2, 21);
|
|
933
|
+
var N4 = Math.pow(2, 28);
|
|
934
|
+
var N5 = Math.pow(2, 35);
|
|
935
|
+
var N6 = Math.pow(2, 42);
|
|
936
|
+
var N7 = Math.pow(2, 49);
|
|
937
|
+
var N8 = Math.pow(2, 56);
|
|
938
|
+
var N9 = Math.pow(2, 63);
|
|
939
|
+
var length = function(value) {
|
|
940
|
+
return value < N1 ? 1 : value < N2 ? 2 : value < N3 ? 3 : value < N4 ? 4 : value < N5 ? 5 : value < N6 ? 6 : value < N7 ? 7 : value < N8 ? 8 : value < N9 ? 9 : 10;
|
|
941
|
+
};
|
|
942
|
+
var varint = {
|
|
943
|
+
encode: encode_1,
|
|
944
|
+
decode: decode2,
|
|
945
|
+
encodingLength: length
|
|
946
|
+
};
|
|
947
|
+
var _brrp_varint = varint;
|
|
948
|
+
var varint_default = _brrp_varint;
|
|
949
|
+
|
|
950
|
+
// ../../node_modules/multiformats/dist/src/varint.js
|
|
951
|
+
function decode3(data, offset = 0) {
|
|
952
|
+
const code2 = varint_default.decode(data, offset);
|
|
953
|
+
return [code2, varint_default.decode.bytes];
|
|
954
|
+
}
|
|
955
|
+
function encodeTo(int, target, offset = 0) {
|
|
956
|
+
varint_default.encode(int, target, offset);
|
|
957
|
+
return target;
|
|
958
|
+
}
|
|
959
|
+
function encodingLength(int) {
|
|
960
|
+
return varint_default.encodingLength(int);
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
// ../../node_modules/multiformats/dist/src/hashes/digest.js
|
|
964
|
+
function create(code2, digest2) {
|
|
965
|
+
const size = digest2.byteLength;
|
|
966
|
+
const sizeOffset = encodingLength(code2);
|
|
967
|
+
const digestOffset = sizeOffset + encodingLength(size);
|
|
968
|
+
const bytes = new Uint8Array(digestOffset + size);
|
|
969
|
+
encodeTo(code2, bytes, 0);
|
|
970
|
+
encodeTo(size, bytes, sizeOffset);
|
|
971
|
+
bytes.set(digest2, digestOffset);
|
|
972
|
+
return new Digest(code2, size, digest2, bytes);
|
|
973
|
+
}
|
|
974
|
+
function decode4(multihash) {
|
|
975
|
+
const bytes = coerce(multihash);
|
|
976
|
+
const [code2, sizeOffset] = decode3(bytes);
|
|
977
|
+
const [size, digestOffset] = decode3(bytes.subarray(sizeOffset));
|
|
978
|
+
const digest2 = bytes.subarray(sizeOffset + digestOffset);
|
|
979
|
+
if (digest2.byteLength !== size) {
|
|
980
|
+
throw new Error("Incorrect length");
|
|
981
|
+
}
|
|
982
|
+
return new Digest(code2, size, digest2, bytes);
|
|
983
|
+
}
|
|
984
|
+
function equals2(a, b) {
|
|
985
|
+
if (a === b) {
|
|
986
|
+
return true;
|
|
987
|
+
} else {
|
|
988
|
+
const data = b;
|
|
989
|
+
return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals(a.bytes, data.bytes);
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
var Digest = class {
|
|
993
|
+
/**
|
|
994
|
+
* Creates a multihash digest.
|
|
995
|
+
*/
|
|
996
|
+
constructor(code2, size, digest2, bytes) {
|
|
997
|
+
__publicField(this, "code");
|
|
998
|
+
__publicField(this, "size");
|
|
999
|
+
__publicField(this, "digest");
|
|
1000
|
+
__publicField(this, "bytes");
|
|
1001
|
+
this.code = code2;
|
|
1002
|
+
this.size = size;
|
|
1003
|
+
this.digest = digest2;
|
|
1004
|
+
this.bytes = bytes;
|
|
1005
|
+
}
|
|
1006
|
+
};
|
|
1007
|
+
|
|
1008
|
+
// ../../node_modules/multiformats/dist/src/cid.js
|
|
1009
|
+
function format(link, base3) {
|
|
1010
|
+
const { bytes, version } = link;
|
|
1011
|
+
switch (version) {
|
|
1012
|
+
case 0:
|
|
1013
|
+
return toStringV0(bytes, baseCache(link), base3 ?? base58btc.encoder);
|
|
1014
|
+
default:
|
|
1015
|
+
return toStringV1(bytes, baseCache(link), base3 ?? base32.encoder);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
var cache = /* @__PURE__ */ new WeakMap();
|
|
1019
|
+
function baseCache(cid) {
|
|
1020
|
+
const baseCache2 = cache.get(cid);
|
|
1021
|
+
if (baseCache2 == null) {
|
|
1022
|
+
const baseCache3 = /* @__PURE__ */ new Map();
|
|
1023
|
+
cache.set(cid, baseCache3);
|
|
1024
|
+
return baseCache3;
|
|
1025
|
+
}
|
|
1026
|
+
return baseCache2;
|
|
1027
|
+
}
|
|
1028
|
+
var _a;
|
|
1029
|
+
var CID = class _CID {
|
|
1030
|
+
/**
|
|
1031
|
+
* @param version - Version of the CID
|
|
1032
|
+
* @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
1033
|
+
* @param multihash - (Multi)hash of the of the content.
|
|
1034
|
+
*/
|
|
1035
|
+
constructor(version, code2, multihash, bytes) {
|
|
1036
|
+
__publicField(this, "code");
|
|
1037
|
+
__publicField(this, "version");
|
|
1038
|
+
__publicField(this, "multihash");
|
|
1039
|
+
__publicField(this, "bytes");
|
|
1040
|
+
__publicField(this, "/");
|
|
1041
|
+
__publicField(this, _a, "CID");
|
|
1042
|
+
this.code = code2;
|
|
1043
|
+
this.version = version;
|
|
1044
|
+
this.multihash = multihash;
|
|
1045
|
+
this.bytes = bytes;
|
|
1046
|
+
this["/"] = bytes;
|
|
1047
|
+
}
|
|
1048
|
+
/**
|
|
1049
|
+
* Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes`
|
|
1050
|
+
* please either use `CID.asCID(cid)` or switch to new signalling mechanism
|
|
1051
|
+
*
|
|
1052
|
+
* @deprecated
|
|
1053
|
+
*/
|
|
1054
|
+
get asCID() {
|
|
1055
|
+
return this;
|
|
1056
|
+
}
|
|
1057
|
+
// ArrayBufferView
|
|
1058
|
+
get byteOffset() {
|
|
1059
|
+
return this.bytes.byteOffset;
|
|
1060
|
+
}
|
|
1061
|
+
// ArrayBufferView
|
|
1062
|
+
get byteLength() {
|
|
1063
|
+
return this.bytes.byteLength;
|
|
1064
|
+
}
|
|
1065
|
+
toV0() {
|
|
1066
|
+
switch (this.version) {
|
|
1067
|
+
case 0: {
|
|
1068
|
+
return this;
|
|
1069
|
+
}
|
|
1070
|
+
case 1: {
|
|
1071
|
+
const { code: code2, multihash } = this;
|
|
1072
|
+
if (code2 !== DAG_PB_CODE) {
|
|
1073
|
+
throw new Error("Cannot convert a non dag-pb CID to CIDv0");
|
|
1074
|
+
}
|
|
1075
|
+
if (multihash.code !== SHA_256_CODE) {
|
|
1076
|
+
throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
|
|
1077
|
+
}
|
|
1078
|
+
return _CID.createV0(multihash);
|
|
1079
|
+
}
|
|
1080
|
+
default: {
|
|
1081
|
+
throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
toV1() {
|
|
1086
|
+
switch (this.version) {
|
|
1087
|
+
case 0: {
|
|
1088
|
+
const { code: code2, digest: digest2 } = this.multihash;
|
|
1089
|
+
const multihash = create(code2, digest2);
|
|
1090
|
+
return _CID.createV1(this.code, multihash);
|
|
1091
|
+
}
|
|
1092
|
+
case 1: {
|
|
1093
|
+
return this;
|
|
1094
|
+
}
|
|
1095
|
+
default: {
|
|
1096
|
+
throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`);
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
equals(other) {
|
|
1101
|
+
return _CID.equals(this, other);
|
|
1102
|
+
}
|
|
1103
|
+
static equals(self, other) {
|
|
1104
|
+
const unknown = other;
|
|
1105
|
+
return unknown != null && self.code === unknown.code && self.version === unknown.version && equals2(self.multihash, unknown.multihash);
|
|
1106
|
+
}
|
|
1107
|
+
toString(base3) {
|
|
1108
|
+
return format(this, base3);
|
|
1109
|
+
}
|
|
1110
|
+
toJSON() {
|
|
1111
|
+
return { "/": format(this) };
|
|
1112
|
+
}
|
|
1113
|
+
link() {
|
|
1114
|
+
return this;
|
|
1115
|
+
}
|
|
1116
|
+
// Legacy
|
|
1117
|
+
[(_a = Symbol.toStringTag, /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom"))]() {
|
|
1118
|
+
return `CID(${this.toString()})`;
|
|
1119
|
+
}
|
|
1120
|
+
/**
|
|
1121
|
+
* Takes any input `value` and returns a `CID` instance if it was
|
|
1122
|
+
* a `CID` otherwise returns `null`. If `value` is instanceof `CID`
|
|
1123
|
+
* it will return value back. If `value` is not instance of this CID
|
|
1124
|
+
* class, but is compatible CID it will return new instance of this
|
|
1125
|
+
* `CID` class. Otherwise returns null.
|
|
1126
|
+
*
|
|
1127
|
+
* This allows two different incompatible versions of CID library to
|
|
1128
|
+
* co-exist and interop as long as binary interface is compatible.
|
|
1129
|
+
*/
|
|
1130
|
+
static asCID(input) {
|
|
1131
|
+
if (input == null) {
|
|
1132
|
+
return null;
|
|
1133
|
+
}
|
|
1134
|
+
const value = input;
|
|
1135
|
+
if (value instanceof _CID) {
|
|
1136
|
+
return value;
|
|
1137
|
+
} else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) {
|
|
1138
|
+
const { version, code: code2, multihash, bytes } = value;
|
|
1139
|
+
return new _CID(version, code2, multihash, bytes ?? encodeCID(version, code2, multihash.bytes));
|
|
1140
|
+
} else if (value[cidSymbol] === true) {
|
|
1141
|
+
const { version, multihash, code: code2 } = value;
|
|
1142
|
+
const digest2 = decode4(multihash);
|
|
1143
|
+
return _CID.create(version, code2, digest2);
|
|
1144
|
+
} else {
|
|
1145
|
+
return null;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
/**
|
|
1149
|
+
* @param version - Version of the CID
|
|
1150
|
+
* @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
1151
|
+
* @param digest - (Multi)hash of the of the content.
|
|
1152
|
+
*/
|
|
1153
|
+
static create(version, code2, digest2) {
|
|
1154
|
+
if (typeof code2 !== "number") {
|
|
1155
|
+
throw new Error("String codecs are no longer supported");
|
|
1156
|
+
}
|
|
1157
|
+
if (!(digest2.bytes instanceof Uint8Array)) {
|
|
1158
|
+
throw new Error("Invalid digest");
|
|
1159
|
+
}
|
|
1160
|
+
switch (version) {
|
|
1161
|
+
case 0: {
|
|
1162
|
+
if (code2 !== DAG_PB_CODE) {
|
|
1163
|
+
throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`);
|
|
1164
|
+
} else {
|
|
1165
|
+
return new _CID(version, code2, digest2, digest2.bytes);
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
case 1: {
|
|
1169
|
+
const bytes = encodeCID(version, code2, digest2.bytes);
|
|
1170
|
+
return new _CID(version, code2, digest2, bytes);
|
|
1171
|
+
}
|
|
1172
|
+
default: {
|
|
1173
|
+
throw new Error("Invalid version");
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
/**
|
|
1178
|
+
* Simplified version of `create` for CIDv0.
|
|
1179
|
+
*/
|
|
1180
|
+
static createV0(digest2) {
|
|
1181
|
+
return _CID.create(0, DAG_PB_CODE, digest2);
|
|
1182
|
+
}
|
|
1183
|
+
/**
|
|
1184
|
+
* Simplified version of `create` for CIDv1.
|
|
1185
|
+
*
|
|
1186
|
+
* @param code - Content encoding format code.
|
|
1187
|
+
* @param digest - Multihash of the content.
|
|
1188
|
+
*/
|
|
1189
|
+
static createV1(code2, digest2) {
|
|
1190
|
+
return _CID.create(1, code2, digest2);
|
|
1191
|
+
}
|
|
1192
|
+
/**
|
|
1193
|
+
* Decoded a CID from its binary representation. The byte array must contain
|
|
1194
|
+
* only the CID with no additional bytes.
|
|
1195
|
+
*
|
|
1196
|
+
* An error will be thrown if the bytes provided do not contain a valid
|
|
1197
|
+
* binary representation of a CID.
|
|
1198
|
+
*/
|
|
1199
|
+
static decode(bytes) {
|
|
1200
|
+
const [cid, remainder] = _CID.decodeFirst(bytes);
|
|
1201
|
+
if (remainder.length !== 0) {
|
|
1202
|
+
throw new Error("Incorrect length");
|
|
1203
|
+
}
|
|
1204
|
+
return cid;
|
|
1205
|
+
}
|
|
1206
|
+
/**
|
|
1207
|
+
* Decoded a CID from its binary representation at the beginning of a byte
|
|
1208
|
+
* array.
|
|
1209
|
+
*
|
|
1210
|
+
* Returns an array with the first element containing the CID and the second
|
|
1211
|
+
* element containing the remainder of the original byte array. The remainder
|
|
1212
|
+
* will be a zero-length byte array if the provided bytes only contained a
|
|
1213
|
+
* binary CID representation.
|
|
1214
|
+
*/
|
|
1215
|
+
static decodeFirst(bytes) {
|
|
1216
|
+
const specs = _CID.inspectBytes(bytes);
|
|
1217
|
+
const prefixSize = specs.size - specs.multihashSize;
|
|
1218
|
+
const multihashBytes = coerce(bytes.subarray(prefixSize, prefixSize + specs.multihashSize));
|
|
1219
|
+
if (multihashBytes.byteLength !== specs.multihashSize) {
|
|
1220
|
+
throw new Error("Incorrect length");
|
|
1221
|
+
}
|
|
1222
|
+
const digestBytes = multihashBytes.subarray(specs.multihashSize - specs.digestSize);
|
|
1223
|
+
const digest2 = new Digest(specs.multihashCode, specs.digestSize, digestBytes, multihashBytes);
|
|
1224
|
+
const cid = specs.version === 0 ? _CID.createV0(digest2) : _CID.createV1(specs.codec, digest2);
|
|
1225
|
+
return [cid, bytes.subarray(specs.size)];
|
|
1226
|
+
}
|
|
1227
|
+
/**
|
|
1228
|
+
* Inspect the initial bytes of a CID to determine its properties.
|
|
1229
|
+
*
|
|
1230
|
+
* Involves decoding up to 4 varints. Typically this will require only 4 to 6
|
|
1231
|
+
* bytes but for larger multicodec code values and larger multihash digest
|
|
1232
|
+
* lengths these varints can be quite large. It is recommended that at least
|
|
1233
|
+
* 10 bytes be made available in the `initialBytes` argument for a complete
|
|
1234
|
+
* inspection.
|
|
1235
|
+
*/
|
|
1236
|
+
static inspectBytes(initialBytes) {
|
|
1237
|
+
let offset = 0;
|
|
1238
|
+
const next = () => {
|
|
1239
|
+
const [i, length2] = decode3(initialBytes.subarray(offset));
|
|
1240
|
+
offset += length2;
|
|
1241
|
+
return i;
|
|
1242
|
+
};
|
|
1243
|
+
let version = next();
|
|
1244
|
+
let codec = DAG_PB_CODE;
|
|
1245
|
+
if (version === 18) {
|
|
1246
|
+
version = 0;
|
|
1247
|
+
offset = 0;
|
|
1248
|
+
} else {
|
|
1249
|
+
codec = next();
|
|
1250
|
+
}
|
|
1251
|
+
if (version !== 0 && version !== 1) {
|
|
1252
|
+
throw new RangeError(`Invalid CID version ${version}`);
|
|
1253
|
+
}
|
|
1254
|
+
const prefixSize = offset;
|
|
1255
|
+
const multihashCode = next();
|
|
1256
|
+
const digestSize = next();
|
|
1257
|
+
const size = offset + digestSize;
|
|
1258
|
+
const multihashSize = size - prefixSize;
|
|
1259
|
+
return { version, codec, multihashCode, digestSize, multihashSize, size };
|
|
1260
|
+
}
|
|
1261
|
+
/**
|
|
1262
|
+
* Takes cid in a string representation and creates an instance. If `base`
|
|
1263
|
+
* decoder is not provided will use a default from the configuration. It will
|
|
1264
|
+
* throw an error if encoding of the CID is not compatible with supplied (or
|
|
1265
|
+
* a default decoder).
|
|
1266
|
+
*/
|
|
1267
|
+
static parse(source, base3) {
|
|
1268
|
+
const [prefix, bytes] = parseCIDtoBytes(source, base3);
|
|
1269
|
+
const cid = _CID.decode(bytes);
|
|
1270
|
+
if (cid.version === 0 && source[0] !== "Q") {
|
|
1271
|
+
throw Error("Version 0 CID string must not include multibase prefix");
|
|
1272
|
+
}
|
|
1273
|
+
baseCache(cid).set(prefix, source);
|
|
1274
|
+
return cid;
|
|
1275
|
+
}
|
|
1276
|
+
};
|
|
1277
|
+
function parseCIDtoBytes(source, base3) {
|
|
1278
|
+
switch (source[0]) {
|
|
1279
|
+
// CIDv0 is parsed differently
|
|
1280
|
+
case "Q": {
|
|
1281
|
+
const decoder = base3 ?? base58btc;
|
|
1282
|
+
return [
|
|
1283
|
+
base58btc.prefix,
|
|
1284
|
+
decoder.decode(`${base58btc.prefix}${source}`)
|
|
1285
|
+
];
|
|
1286
|
+
}
|
|
1287
|
+
case base58btc.prefix: {
|
|
1288
|
+
const decoder = base3 ?? base58btc;
|
|
1289
|
+
return [base58btc.prefix, decoder.decode(source)];
|
|
1290
|
+
}
|
|
1291
|
+
case base32.prefix: {
|
|
1292
|
+
const decoder = base3 ?? base32;
|
|
1293
|
+
return [base32.prefix, decoder.decode(source)];
|
|
1294
|
+
}
|
|
1295
|
+
case base36.prefix: {
|
|
1296
|
+
const decoder = base3 ?? base36;
|
|
1297
|
+
return [base36.prefix, decoder.decode(source)];
|
|
1298
|
+
}
|
|
1299
|
+
default: {
|
|
1300
|
+
if (base3 == null) {
|
|
1301
|
+
throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");
|
|
1302
|
+
}
|
|
1303
|
+
return [source[0], base3.decode(source)];
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
function toStringV0(bytes, cache2, base3) {
|
|
1308
|
+
const { prefix } = base3;
|
|
1309
|
+
if (prefix !== base58btc.prefix) {
|
|
1310
|
+
throw Error(`Cannot string encode V0 in ${base3.name} encoding`);
|
|
1311
|
+
}
|
|
1312
|
+
const cid = cache2.get(prefix);
|
|
1313
|
+
if (cid == null) {
|
|
1314
|
+
const cid2 = base3.encode(bytes).slice(1);
|
|
1315
|
+
cache2.set(prefix, cid2);
|
|
1316
|
+
return cid2;
|
|
1317
|
+
} else {
|
|
1318
|
+
return cid;
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
function toStringV1(bytes, cache2, base3) {
|
|
1322
|
+
const { prefix } = base3;
|
|
1323
|
+
const cid = cache2.get(prefix);
|
|
1324
|
+
if (cid == null) {
|
|
1325
|
+
const cid2 = base3.encode(bytes);
|
|
1326
|
+
cache2.set(prefix, cid2);
|
|
1327
|
+
return cid2;
|
|
1328
|
+
} else {
|
|
1329
|
+
return cid;
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
var DAG_PB_CODE = 112;
|
|
1333
|
+
var SHA_256_CODE = 18;
|
|
1334
|
+
function encodeCID(version, code2, multihash) {
|
|
1335
|
+
const codeOffset = encodingLength(version);
|
|
1336
|
+
const hashOffset = codeOffset + encodingLength(code2);
|
|
1337
|
+
const bytes = new Uint8Array(hashOffset + multihash.byteLength);
|
|
1338
|
+
encodeTo(version, bytes, 0);
|
|
1339
|
+
encodeTo(code2, bytes, codeOffset);
|
|
1340
|
+
bytes.set(multihash, hashOffset);
|
|
1341
|
+
return bytes;
|
|
1342
|
+
}
|
|
1343
|
+
var cidSymbol = /* @__PURE__ */ Symbol.for("@ipld/js-cid/CID");
|
|
1344
|
+
|
|
1345
|
+
// src/requester/index.ts
|
|
428
1346
|
var import_zod2 = require("zod");
|
|
429
1347
|
|
|
430
1348
|
// src/policy/errors.ts
|
|
431
1349
|
var SignedObjectProfileError = class extends Error {
|
|
432
|
-
constructor(
|
|
1350
|
+
constructor(code2, message) {
|
|
433
1351
|
super(message);
|
|
434
1352
|
this.name = "SignedObjectProfileError";
|
|
435
|
-
this.code =
|
|
1353
|
+
this.code = code2;
|
|
436
1354
|
}
|
|
437
1355
|
};
|
|
438
1356
|
var SignedObjectSchemaError = class extends SignedObjectProfileError {
|
|
@@ -630,35 +1548,33 @@ function assertNoSymbolKeys(input, path) {
|
|
|
630
1548
|
);
|
|
631
1549
|
}
|
|
632
1550
|
}
|
|
633
|
-
function isArrayIndexKey(key,
|
|
1551
|
+
function isArrayIndexKey(key, length2) {
|
|
634
1552
|
if (!/^(0|[1-9]\d*)$/.test(key)) {
|
|
635
1553
|
return false;
|
|
636
1554
|
}
|
|
637
1555
|
const index = Number(key);
|
|
638
|
-
return Number.isSafeInteger(index) && index >= 0 && index <
|
|
1556
|
+
return Number.isSafeInteger(index) && index >= 0 && index < length2;
|
|
639
1557
|
}
|
|
640
1558
|
function serializeObject(value) {
|
|
641
|
-
const keys = Object.keys(value).sort(
|
|
1559
|
+
const keys = Object.keys(value).sort(compareUtf16CodeUnits);
|
|
642
1560
|
const parts = keys.map((key) => `${JSON.stringify(key)}:${serialize(value[key])}`);
|
|
643
1561
|
return `{${parts.join(",")}}`;
|
|
644
1562
|
}
|
|
645
|
-
function
|
|
646
|
-
const
|
|
647
|
-
const right = Array.from(b);
|
|
648
|
-
const max = Math.min(left.length, right.length);
|
|
1563
|
+
function compareUtf16CodeUnits(a, b) {
|
|
1564
|
+
const max = Math.min(a.length, b.length);
|
|
649
1565
|
for (let index = 0; index < max; index++) {
|
|
650
|
-
const
|
|
651
|
-
const
|
|
652
|
-
if (
|
|
653
|
-
return
|
|
1566
|
+
const leftCodeUnit = a.charCodeAt(index);
|
|
1567
|
+
const rightCodeUnit = b.charCodeAt(index);
|
|
1568
|
+
if (leftCodeUnit !== rightCodeUnit) {
|
|
1569
|
+
return leftCodeUnit - rightCodeUnit;
|
|
654
1570
|
}
|
|
655
1571
|
}
|
|
656
|
-
return
|
|
1572
|
+
return a.length - b.length;
|
|
657
1573
|
}
|
|
658
1574
|
function assertUnicodeScalarString(value, path) {
|
|
659
1575
|
for (let index = 0; index < value.length; index++) {
|
|
660
|
-
const
|
|
661
|
-
if (
|
|
1576
|
+
const code2 = value.charCodeAt(index);
|
|
1577
|
+
if (code2 >= 55296 && code2 <= 56319) {
|
|
662
1578
|
const next = value.charCodeAt(index + 1);
|
|
663
1579
|
if (Number.isNaN(next) || next < 56320 || next > 57343) {
|
|
664
1580
|
throw new SignedObjectCanonicalizationError(
|
|
@@ -668,7 +1584,7 @@ function assertUnicodeScalarString(value, path) {
|
|
|
668
1584
|
index++;
|
|
669
1585
|
continue;
|
|
670
1586
|
}
|
|
671
|
-
if (
|
|
1587
|
+
if (code2 >= 56320 && code2 <= 57343) {
|
|
672
1588
|
throw new SignedObjectCanonicalizationError(
|
|
673
1589
|
`${path} contains a lone low surrogate`
|
|
674
1590
|
);
|
|
@@ -681,10 +1597,10 @@ var import_bootstrap = require("@tinycloud/bootstrap");
|
|
|
681
1597
|
var import_viem2 = require("viem");
|
|
682
1598
|
var textEncoder = new TextEncoder();
|
|
683
1599
|
var PolicyCapabilityError = class extends Error {
|
|
684
|
-
constructor(
|
|
1600
|
+
constructor(code2, message) {
|
|
685
1601
|
super(message);
|
|
686
1602
|
this.name = "PolicyCapabilityError";
|
|
687
|
-
this.code =
|
|
1603
|
+
this.code = code2;
|
|
688
1604
|
}
|
|
689
1605
|
};
|
|
690
1606
|
var objectHasOwn2 = Object.hasOwn ?? Object.prototype.hasOwnProperty.call.bind(
|
|
@@ -735,7 +1651,7 @@ function policyCapabilityContains(authority, request) {
|
|
|
735
1651
|
}
|
|
736
1652
|
return caveatsContain(auth.caveats, req.caveats);
|
|
737
1653
|
}
|
|
738
|
-
function normalizePolicyCapabilityWithOptions(input,
|
|
1654
|
+
function normalizePolicyCapabilityWithOptions(input, options2) {
|
|
739
1655
|
const object = expectObject(input, "$");
|
|
740
1656
|
assertExactKeys(object, ["service", "space", "path", "actions", "caveats"], "$");
|
|
741
1657
|
const service = requiredString(object, "service", "$", "policy-capability-malformed-service");
|
|
@@ -748,26 +1664,26 @@ function normalizePolicyCapabilityWithOptions(input, options) {
|
|
|
748
1664
|
const space = requiredString(object, "space", "$", "policy-capability-malformed-space");
|
|
749
1665
|
validateConcreteSpace(space);
|
|
750
1666
|
const canonicalSpace = space.normalize("NFC");
|
|
751
|
-
if (
|
|
1667
|
+
if (options2.requireCanonical && canonicalSpace !== space) {
|
|
752
1668
|
throw new PolicyCapabilityError(
|
|
753
1669
|
"policy-capability-malformed-space",
|
|
754
1670
|
"$.space must already be canonical NFC"
|
|
755
1671
|
);
|
|
756
1672
|
}
|
|
757
1673
|
const rawPath = requiredString(object, "path", "$", "policy-capability-malformed-path");
|
|
758
|
-
validateRawPath(rawPath,
|
|
1674
|
+
validateRawPath(rawPath, options2);
|
|
759
1675
|
const path = normalizePath(rawPath);
|
|
760
|
-
if (
|
|
1676
|
+
if (options2.requireCanonical && path !== rawPath) {
|
|
761
1677
|
throw new PolicyCapabilityError(
|
|
762
1678
|
"policy-capability-malformed-path",
|
|
763
1679
|
"$.path must already be canonical"
|
|
764
1680
|
);
|
|
765
1681
|
}
|
|
766
|
-
validateRawPath(path,
|
|
1682
|
+
validateRawPath(path, options2);
|
|
767
1683
|
const actions = normalizeActions(
|
|
768
1684
|
requiredArray(object, "actions", "$", "policy-capability-malformed-action"),
|
|
769
1685
|
service,
|
|
770
|
-
|
|
1686
|
+
options2
|
|
771
1687
|
);
|
|
772
1688
|
const output = /* @__PURE__ */ Object.create(null);
|
|
773
1689
|
output.service = service;
|
|
@@ -810,23 +1726,23 @@ function assertExactKeys(object, allowed, path) {
|
|
|
810
1726
|
}
|
|
811
1727
|
}
|
|
812
1728
|
}
|
|
813
|
-
function requiredValue(object, key, path,
|
|
1729
|
+
function requiredValue(object, key, path, code2) {
|
|
814
1730
|
if (!hasOwn(object, key)) {
|
|
815
|
-
throw new PolicyCapabilityError(
|
|
1731
|
+
throw new PolicyCapabilityError(code2, `${path}.${key} is required`);
|
|
816
1732
|
}
|
|
817
1733
|
return object[key];
|
|
818
1734
|
}
|
|
819
|
-
function requiredString(object, key, path,
|
|
820
|
-
const value = requiredValue(object, key, path,
|
|
1735
|
+
function requiredString(object, key, path, code2) {
|
|
1736
|
+
const value = requiredValue(object, key, path, code2);
|
|
821
1737
|
if (typeof value !== "string" || value.length === 0) {
|
|
822
|
-
throw new PolicyCapabilityError(
|
|
1738
|
+
throw new PolicyCapabilityError(code2, `${path}.${key} must be a non-empty string`);
|
|
823
1739
|
}
|
|
824
1740
|
return value;
|
|
825
1741
|
}
|
|
826
|
-
function requiredArray(object, key, path,
|
|
827
|
-
const value = requiredValue(object, key, path,
|
|
1742
|
+
function requiredArray(object, key, path, code2) {
|
|
1743
|
+
const value = requiredValue(object, key, path, code2);
|
|
828
1744
|
if (!Array.isArray(value)) {
|
|
829
|
-
throw new PolicyCapabilityError(
|
|
1745
|
+
throw new PolicyCapabilityError(code2, `${path}.${key} must be an array`);
|
|
830
1746
|
}
|
|
831
1747
|
return value;
|
|
832
1748
|
}
|
|
@@ -838,11 +1754,11 @@ function validateConcreteSpace(space) {
|
|
|
838
1754
|
);
|
|
839
1755
|
}
|
|
840
1756
|
}
|
|
841
|
-
function validateRawPath(path,
|
|
1757
|
+
function validateRawPath(path, options2) {
|
|
842
1758
|
if (path.length === 0) {
|
|
843
1759
|
throw new PolicyCapabilityError("policy-capability-malformed-path", "$.path is empty");
|
|
844
1760
|
}
|
|
845
|
-
if (!
|
|
1761
|
+
if (!options2.allowPrefixPaths && path.endsWith("/")) {
|
|
846
1762
|
throw new PolicyCapabilityError(
|
|
847
1763
|
"policy-capability-malformed-path",
|
|
848
1764
|
"$.path must be an exact concrete path, not a prefix"
|
|
@@ -854,7 +1770,7 @@ function validateRawPath(path, options) {
|
|
|
854
1770
|
const segments = path.split("/");
|
|
855
1771
|
for (let index = 0; index < segments.length; index++) {
|
|
856
1772
|
const segment = segments[index];
|
|
857
|
-
const isTrailingPrefixSegment =
|
|
1773
|
+
const isTrailingPrefixSegment = options2.allowPrefixPaths && index === segments.length - 1 && segment.length === 0;
|
|
858
1774
|
if (segment.length === 0 && !isTrailingPrefixSegment) {
|
|
859
1775
|
throw new PolicyCapabilityError("policy-capability-malformed-path", "$.path has an empty segment");
|
|
860
1776
|
}
|
|
@@ -881,7 +1797,7 @@ function decodeUnreserved(path) {
|
|
|
881
1797
|
return /^[A-Za-z0-9._~-]$/.test(char) ? char : encoded.toUpperCase();
|
|
882
1798
|
});
|
|
883
1799
|
}
|
|
884
|
-
function normalizeActions(actions, service,
|
|
1800
|
+
function normalizeActions(actions, service, options2) {
|
|
885
1801
|
const accepted = GRANTABLE_ACTIONS.get(service);
|
|
886
1802
|
if (accepted === void 0) {
|
|
887
1803
|
throw new PolicyCapabilityError(
|
|
@@ -915,7 +1831,7 @@ function normalizeActions(actions, service, options) {
|
|
|
915
1831
|
);
|
|
916
1832
|
}
|
|
917
1833
|
const normalizedActions = [...unique].sort();
|
|
918
|
-
if (
|
|
1834
|
+
if (options2.requireCanonical && (rawActions.length !== normalizedActions.length || rawActions.some((action, index) => action !== normalizedActions[index]))) {
|
|
919
1835
|
throw new PolicyCapabilityError(
|
|
920
1836
|
"policy-capability-malformed-action",
|
|
921
1837
|
"$.actions must already be sorted, deduplicated canonical action URNs"
|
|
@@ -1057,50 +1973,291 @@ function hasOwn(object, key) {
|
|
|
1057
1973
|
|
|
1058
1974
|
// src/policy/signed-object.ts
|
|
1059
1975
|
var import_ed25519 = require("@noble/curves/ed25519");
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
var
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
var
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
};
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
var
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
);
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1976
|
+
|
|
1977
|
+
// ../../node_modules/multiformats/dist/src/bases/base10.js
|
|
1978
|
+
var base10_exports = {};
|
|
1979
|
+
__export(base10_exports, {
|
|
1980
|
+
base10: () => base10
|
|
1981
|
+
});
|
|
1982
|
+
var base10 = baseX({
|
|
1983
|
+
prefix: "9",
|
|
1984
|
+
name: "base10",
|
|
1985
|
+
alphabet: "0123456789"
|
|
1986
|
+
});
|
|
1987
|
+
|
|
1988
|
+
// ../../node_modules/multiformats/dist/src/bases/base16.js
|
|
1989
|
+
var base16_exports = {};
|
|
1990
|
+
__export(base16_exports, {
|
|
1991
|
+
base16: () => base16,
|
|
1992
|
+
base16upper: () => base16upper
|
|
1993
|
+
});
|
|
1994
|
+
var base16 = rfc4648({
|
|
1995
|
+
prefix: "f",
|
|
1996
|
+
name: "base16",
|
|
1997
|
+
alphabet: "0123456789abcdef",
|
|
1998
|
+
bitsPerChar: 4
|
|
1999
|
+
});
|
|
2000
|
+
var base16upper = rfc4648({
|
|
2001
|
+
prefix: "F",
|
|
2002
|
+
name: "base16upper",
|
|
2003
|
+
alphabet: "0123456789ABCDEF",
|
|
2004
|
+
bitsPerChar: 4
|
|
2005
|
+
});
|
|
2006
|
+
|
|
2007
|
+
// ../../node_modules/multiformats/dist/src/bases/base2.js
|
|
2008
|
+
var base2_exports = {};
|
|
2009
|
+
__export(base2_exports, {
|
|
2010
|
+
base2: () => base2
|
|
2011
|
+
});
|
|
2012
|
+
var base2 = rfc4648({
|
|
2013
|
+
prefix: "0",
|
|
2014
|
+
name: "base2",
|
|
2015
|
+
alphabet: "01",
|
|
2016
|
+
bitsPerChar: 1
|
|
2017
|
+
});
|
|
2018
|
+
|
|
2019
|
+
// ../../node_modules/multiformats/dist/src/bases/base256emoji.js
|
|
2020
|
+
var base256emoji_exports = {};
|
|
2021
|
+
__export(base256emoji_exports, {
|
|
2022
|
+
base256emoji: () => base256emoji
|
|
2023
|
+
});
|
|
2024
|
+
var alphabet = Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}");
|
|
2025
|
+
var alphabetBytesToChars = alphabet.reduce((p, c, i) => {
|
|
2026
|
+
p[i] = c;
|
|
2027
|
+
return p;
|
|
2028
|
+
}, []);
|
|
2029
|
+
var alphabetCharsToBytes = alphabet.reduce((p, c, i) => {
|
|
2030
|
+
const codePoint = c.codePointAt(0);
|
|
2031
|
+
if (codePoint == null) {
|
|
2032
|
+
throw new Error(`Invalid character: ${c}`);
|
|
2033
|
+
}
|
|
2034
|
+
p[codePoint] = i;
|
|
2035
|
+
return p;
|
|
2036
|
+
}, []);
|
|
2037
|
+
function encode3(data) {
|
|
2038
|
+
return data.reduce((p, c) => {
|
|
2039
|
+
p += alphabetBytesToChars[c];
|
|
2040
|
+
return p;
|
|
2041
|
+
}, "");
|
|
2042
|
+
}
|
|
2043
|
+
function decode5(str) {
|
|
2044
|
+
const byts = [];
|
|
2045
|
+
for (const char of str) {
|
|
2046
|
+
const codePoint = char.codePointAt(0);
|
|
2047
|
+
if (codePoint == null) {
|
|
2048
|
+
throw new Error(`Invalid character: ${char}`);
|
|
2049
|
+
}
|
|
2050
|
+
const byt = alphabetCharsToBytes[codePoint];
|
|
2051
|
+
if (byt == null) {
|
|
2052
|
+
throw new Error(`Non-base256emoji character: ${char}`);
|
|
2053
|
+
}
|
|
2054
|
+
byts.push(byt);
|
|
2055
|
+
}
|
|
2056
|
+
return new Uint8Array(byts);
|
|
2057
|
+
}
|
|
2058
|
+
var base256emoji = from({
|
|
2059
|
+
prefix: "\u{1F680}",
|
|
2060
|
+
name: "base256emoji",
|
|
2061
|
+
encode: encode3,
|
|
2062
|
+
decode: decode5
|
|
2063
|
+
});
|
|
2064
|
+
|
|
2065
|
+
// ../../node_modules/multiformats/dist/src/bases/base64.js
|
|
2066
|
+
var base64_exports = {};
|
|
2067
|
+
__export(base64_exports, {
|
|
2068
|
+
base64: () => base64,
|
|
2069
|
+
base64pad: () => base64pad,
|
|
2070
|
+
base64url: () => base64url,
|
|
2071
|
+
base64urlpad: () => base64urlpad
|
|
2072
|
+
});
|
|
2073
|
+
var base64 = rfc4648({
|
|
2074
|
+
prefix: "m",
|
|
2075
|
+
name: "base64",
|
|
2076
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
|
|
2077
|
+
bitsPerChar: 6
|
|
2078
|
+
});
|
|
2079
|
+
var base64pad = rfc4648({
|
|
2080
|
+
prefix: "M",
|
|
2081
|
+
name: "base64pad",
|
|
2082
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
|
|
2083
|
+
bitsPerChar: 6
|
|
2084
|
+
});
|
|
2085
|
+
var base64url = rfc4648({
|
|
2086
|
+
prefix: "u",
|
|
2087
|
+
name: "base64url",
|
|
2088
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",
|
|
2089
|
+
bitsPerChar: 6
|
|
2090
|
+
});
|
|
2091
|
+
var base64urlpad = rfc4648({
|
|
2092
|
+
prefix: "U",
|
|
2093
|
+
name: "base64urlpad",
|
|
2094
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",
|
|
2095
|
+
bitsPerChar: 6
|
|
2096
|
+
});
|
|
2097
|
+
|
|
2098
|
+
// ../../node_modules/multiformats/dist/src/bases/base8.js
|
|
2099
|
+
var base8_exports = {};
|
|
2100
|
+
__export(base8_exports, {
|
|
2101
|
+
base8: () => base8
|
|
2102
|
+
});
|
|
2103
|
+
var base8 = rfc4648({
|
|
2104
|
+
prefix: "7",
|
|
2105
|
+
name: "base8",
|
|
2106
|
+
alphabet: "01234567",
|
|
2107
|
+
bitsPerChar: 3
|
|
2108
|
+
});
|
|
2109
|
+
|
|
2110
|
+
// ../../node_modules/multiformats/dist/src/bases/identity.js
|
|
2111
|
+
var identity_exports = {};
|
|
2112
|
+
__export(identity_exports, {
|
|
2113
|
+
identity: () => identity
|
|
2114
|
+
});
|
|
2115
|
+
var identity = from({
|
|
2116
|
+
prefix: "\0",
|
|
2117
|
+
name: "identity",
|
|
2118
|
+
encode: (buf) => toString(buf),
|
|
2119
|
+
decode: (str) => fromString(str)
|
|
2120
|
+
});
|
|
2121
|
+
|
|
2122
|
+
// ../../node_modules/multiformats/dist/src/codecs/json.js
|
|
2123
|
+
var textEncoder2 = new TextEncoder();
|
|
2124
|
+
var textDecoder = new TextDecoder();
|
|
2125
|
+
|
|
2126
|
+
// ../../node_modules/multiformats/dist/src/hashes/identity.js
|
|
2127
|
+
var identity_exports2 = {};
|
|
2128
|
+
__export(identity_exports2, {
|
|
2129
|
+
identity: () => identity2
|
|
2130
|
+
});
|
|
2131
|
+
var code = 0;
|
|
2132
|
+
var name = "identity";
|
|
2133
|
+
var encode4 = coerce;
|
|
2134
|
+
function digest(input, options2) {
|
|
2135
|
+
if (options2?.truncate != null && options2.truncate !== input.byteLength) {
|
|
2136
|
+
if (options2.truncate < 0 || options2.truncate > input.byteLength) {
|
|
2137
|
+
throw new Error(`Invalid truncate option, must be less than or equal to ${input.byteLength}`);
|
|
2138
|
+
}
|
|
2139
|
+
input = input.subarray(0, options2.truncate);
|
|
2140
|
+
}
|
|
2141
|
+
return create(code, encode4(input));
|
|
2142
|
+
}
|
|
2143
|
+
var identity2 = { code, name, encode: encode4, digest };
|
|
2144
|
+
|
|
2145
|
+
// ../../node_modules/multiformats/dist/src/hashes/sha2.js
|
|
2146
|
+
var sha2_exports = {};
|
|
2147
|
+
__export(sha2_exports, {
|
|
2148
|
+
sha256: () => sha2562,
|
|
2149
|
+
sha512: () => sha512
|
|
2150
|
+
});
|
|
2151
|
+
var import_crypto = __toESM(require("crypto"), 1);
|
|
2152
|
+
|
|
2153
|
+
// ../../node_modules/multiformats/dist/src/hashes/hasher.js
|
|
2154
|
+
var DEFAULT_MIN_DIGEST_LENGTH = 20;
|
|
2155
|
+
function from2({ name: name2, code: code2, encode: encode5, minDigestLength, maxDigestLength }) {
|
|
2156
|
+
return new Hasher(name2, code2, encode5, minDigestLength, maxDigestLength);
|
|
2157
|
+
}
|
|
2158
|
+
var Hasher = class {
|
|
2159
|
+
constructor(name2, code2, encode5, minDigestLength, maxDigestLength) {
|
|
2160
|
+
__publicField(this, "name");
|
|
2161
|
+
__publicField(this, "code");
|
|
2162
|
+
__publicField(this, "encode");
|
|
2163
|
+
__publicField(this, "minDigestLength");
|
|
2164
|
+
__publicField(this, "maxDigestLength");
|
|
2165
|
+
this.name = name2;
|
|
2166
|
+
this.code = code2;
|
|
2167
|
+
this.encode = encode5;
|
|
2168
|
+
this.minDigestLength = minDigestLength ?? DEFAULT_MIN_DIGEST_LENGTH;
|
|
2169
|
+
this.maxDigestLength = maxDigestLength;
|
|
2170
|
+
}
|
|
2171
|
+
digest(input, options2) {
|
|
2172
|
+
if (options2?.truncate != null) {
|
|
2173
|
+
if (options2.truncate < this.minDigestLength) {
|
|
2174
|
+
throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);
|
|
2175
|
+
}
|
|
2176
|
+
if (this.maxDigestLength != null && options2.truncate > this.maxDigestLength) {
|
|
2177
|
+
throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`);
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
if (input instanceof Uint8Array) {
|
|
2181
|
+
const result = this.encode(input);
|
|
2182
|
+
if (result instanceof Uint8Array) {
|
|
2183
|
+
return createDigest(result, this.code, options2?.truncate);
|
|
2184
|
+
}
|
|
2185
|
+
return result.then((digest2) => createDigest(digest2, this.code, options2?.truncate));
|
|
2186
|
+
} else {
|
|
2187
|
+
throw Error("Unknown type, must be binary type");
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
};
|
|
2191
|
+
function createDigest(digest2, code2, truncate) {
|
|
2192
|
+
if (truncate != null && truncate !== digest2.byteLength) {
|
|
2193
|
+
if (truncate > digest2.byteLength) {
|
|
2194
|
+
throw new Error(`Invalid truncate option, must be less than or equal to ${digest2.byteLength}`);
|
|
2195
|
+
}
|
|
2196
|
+
digest2 = digest2.subarray(0, truncate);
|
|
2197
|
+
}
|
|
2198
|
+
return create(code2, digest2);
|
|
2199
|
+
}
|
|
2200
|
+
|
|
2201
|
+
// ../../node_modules/multiformats/dist/src/hashes/sha2.js
|
|
2202
|
+
var sha2562 = from2({
|
|
2203
|
+
name: "sha2-256",
|
|
2204
|
+
code: 18,
|
|
2205
|
+
encode: (input) => coerce(import_crypto.default.createHash("sha256").update(input).digest())
|
|
2206
|
+
});
|
|
2207
|
+
var sha512 = from2({
|
|
2208
|
+
name: "sha2-512",
|
|
2209
|
+
code: 19,
|
|
2210
|
+
encode: (input) => coerce(import_crypto.default.createHash("sha512").update(input).digest())
|
|
2211
|
+
});
|
|
2212
|
+
|
|
2213
|
+
// ../../node_modules/multiformats/dist/src/basics.js
|
|
2214
|
+
var bases = { ...identity_exports, ...base2_exports, ...base8_exports, ...base10_exports, ...base16_exports, ...base32_exports, ...base36_exports, ...base58_exports, ...base64_exports, ...base256emoji_exports };
|
|
2215
|
+
var hashes = { ...sha2_exports, ...identity_exports2 };
|
|
2216
|
+
|
|
2217
|
+
// src/policy/signed-object.ts
|
|
2218
|
+
var import_viem3 = require("viem");
|
|
2219
|
+
var POLICY_SCHEMA = "xyz.tinycloud.policy/policy/v0";
|
|
2220
|
+
var POLICY_STATUS_SCHEMA = "xyz.tinycloud.policy/status/v0";
|
|
2221
|
+
var POLICY_ENGINE_RECORD_SCHEMA = "xyz.tinycloud.policy/engine-record/v0";
|
|
2222
|
+
var ED25519_JCS_SIGNATURE_SUITE = "eddsa-ed25519-sha256-jcs-v1";
|
|
2223
|
+
var EIP191_JCS_SIGNATURE_SUITE = "eip191-secp256k1-sha256-jcs-v1";
|
|
2224
|
+
var DESCRIPTORS = {
|
|
2225
|
+
Policy: {
|
|
2226
|
+
kind: "Policy",
|
|
2227
|
+
schema: POLICY_SCHEMA,
|
|
2228
|
+
idField: "policyId",
|
|
2229
|
+
idPrefix: "pol_",
|
|
2230
|
+
domain: POLICY_SCHEMA
|
|
2231
|
+
},
|
|
2232
|
+
PolicyStatus: {
|
|
2233
|
+
kind: "PolicyStatus",
|
|
2234
|
+
schema: POLICY_STATUS_SCHEMA,
|
|
2235
|
+
idField: "statusId",
|
|
2236
|
+
idPrefix: "polst_",
|
|
2237
|
+
domain: POLICY_STATUS_SCHEMA
|
|
2238
|
+
},
|
|
2239
|
+
PolicyEngineRecord: {
|
|
2240
|
+
kind: "PolicyEngineRecord",
|
|
2241
|
+
schema: POLICY_ENGINE_RECORD_SCHEMA,
|
|
2242
|
+
idField: "engineRecordId",
|
|
2243
|
+
idPrefix: "peng_",
|
|
2244
|
+
domain: POLICY_ENGINE_RECORD_SCHEMA
|
|
2245
|
+
}
|
|
2246
|
+
};
|
|
2247
|
+
var textEncoder3 = new TextEncoder();
|
|
2248
|
+
var BASE32_ALPHABET = "abcdefghijklmnopqrstuvwxyz234567";
|
|
2249
|
+
var BASE64URL_RE = /^[A-Za-z0-9_-]+$/;
|
|
2250
|
+
var objectHasOwn3 = Object.hasOwn ?? Object.prototype.hasOwnProperty.call.bind(
|
|
2251
|
+
Object.prototype.hasOwnProperty
|
|
2252
|
+
);
|
|
2253
|
+
function canonicalizeSignedObjectUnsigned(input) {
|
|
2254
|
+
return jcsCanonicalize(input);
|
|
2255
|
+
}
|
|
2256
|
+
function deriveSignedObjectMaterial(input) {
|
|
2257
|
+
const descriptor = descriptorForUnsigned(input);
|
|
2258
|
+
const unsigned = validateUnsignedForDescriptor(input, descriptor);
|
|
2259
|
+
return materialForUnsigned(unsigned, descriptor);
|
|
2260
|
+
}
|
|
1104
2261
|
function signedObjectIdFor(input) {
|
|
1105
2262
|
return deriveSignedObjectMaterial(input).id;
|
|
1106
2263
|
}
|
|
@@ -1536,9 +2693,9 @@ function validateAudit(input, path) {
|
|
|
1536
2693
|
}
|
|
1537
2694
|
function materialForUnsigned(unsigned, descriptor) {
|
|
1538
2695
|
const jcs = jcsCanonicalize(unsigned);
|
|
1539
|
-
const jcsBytes =
|
|
1540
|
-
const
|
|
1541
|
-
const id = `${descriptor.idPrefix}${base32LowerNoPad(
|
|
2696
|
+
const jcsBytes = textEncoder3.encode(jcs);
|
|
2697
|
+
const digest2 = sha256Bytes(concatBytes(textEncoder3.encode(`${descriptor.domain}\0`), jcsBytes));
|
|
2698
|
+
const id = `${descriptor.idPrefix}${base32LowerNoPad(digest2)}`;
|
|
1542
2699
|
return {
|
|
1543
2700
|
kind: descriptor.kind,
|
|
1544
2701
|
idField: descriptor.idField,
|
|
@@ -1547,8 +2704,8 @@ function materialForUnsigned(unsigned, descriptor) {
|
|
|
1547
2704
|
unsigned,
|
|
1548
2705
|
jcs,
|
|
1549
2706
|
jcsBytes,
|
|
1550
|
-
digest,
|
|
1551
|
-
digestHex: (0, import_viem3.bytesToHex)(
|
|
2707
|
+
digest: digest2,
|
|
2708
|
+
digestHex: (0, import_viem3.bytesToHex)(digest2).slice(2)
|
|
1552
2709
|
};
|
|
1553
2710
|
}
|
|
1554
2711
|
function assertIdMatches(signed, material, descriptor) {
|
|
@@ -1596,12 +2753,12 @@ function assertSignerDidMatchesSuite(signerDid, suite) {
|
|
|
1596
2753
|
}
|
|
1597
2754
|
throw new UnsupportedSignatureSuiteError(`unsupported signature suite: ${suite}`);
|
|
1598
2755
|
}
|
|
1599
|
-
async function verifySignature(signature,
|
|
2756
|
+
async function verifySignature(signature, digest2) {
|
|
1600
2757
|
if (signature.suite === ED25519_JCS_SIGNATURE_SUITE) {
|
|
1601
2758
|
const publicKey = ed25519PublicKeyFromDidKey(signature.signerDid);
|
|
1602
2759
|
const signatureBytes = decodeSignatureValue(signature.value, signature.suite);
|
|
1603
2760
|
try {
|
|
1604
|
-
return import_ed25519.ed25519.verify(signatureBytes,
|
|
2761
|
+
return import_ed25519.ed25519.verify(signatureBytes, digest2, publicKey);
|
|
1605
2762
|
} catch {
|
|
1606
2763
|
throw new SignatureVerificationError("Ed25519 signature verification failed");
|
|
1607
2764
|
}
|
|
@@ -1612,7 +2769,7 @@ async function verifySignature(signature, digest) {
|
|
|
1612
2769
|
try {
|
|
1613
2770
|
return (0, import_viem3.verifyMessage)({
|
|
1614
2771
|
address: pkh.address,
|
|
1615
|
-
message: { raw:
|
|
2772
|
+
message: { raw: digest2 },
|
|
1616
2773
|
signature: (0, import_viem3.bytesToHex)(signatureBytes)
|
|
1617
2774
|
});
|
|
1618
2775
|
} catch {
|
|
@@ -1631,7 +2788,7 @@ function ed25519PublicKeyFromDidKey(did) {
|
|
|
1631
2788
|
}
|
|
1632
2789
|
let bytes;
|
|
1633
2790
|
try {
|
|
1634
|
-
bytes =
|
|
2791
|
+
bytes = bases.base58btc.decode(identifier);
|
|
1635
2792
|
} catch {
|
|
1636
2793
|
throw new SignatureMaterialError("did:key signerDid is undecodable");
|
|
1637
2794
|
}
|
|
@@ -1844,20 +3001,20 @@ function base32LowerNoPad(bytes) {
|
|
|
1844
3001
|
return output;
|
|
1845
3002
|
}
|
|
1846
3003
|
function base64UrlEncode(bytes) {
|
|
1847
|
-
const
|
|
3004
|
+
const alphabet2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
1848
3005
|
let output = "";
|
|
1849
3006
|
for (let index = 0; index < bytes.length; index += 3) {
|
|
1850
3007
|
const a = bytes[index];
|
|
1851
3008
|
const b = bytes[index + 1];
|
|
1852
3009
|
const c = bytes[index + 2];
|
|
1853
3010
|
const triplet = a << 16 | (b ?? 0) << 8 | (c ?? 0);
|
|
1854
|
-
output +=
|
|
1855
|
-
output +=
|
|
3011
|
+
output += alphabet2[triplet >> 18 & 63];
|
|
3012
|
+
output += alphabet2[triplet >> 12 & 63];
|
|
1856
3013
|
if (index + 1 < bytes.length) {
|
|
1857
|
-
output +=
|
|
3014
|
+
output += alphabet2[triplet >> 6 & 63];
|
|
1858
3015
|
}
|
|
1859
3016
|
if (index + 2 < bytes.length) {
|
|
1860
|
-
output +=
|
|
3017
|
+
output += alphabet2[triplet & 63];
|
|
1861
3018
|
}
|
|
1862
3019
|
}
|
|
1863
3020
|
return output;
|
|
@@ -1866,12 +3023,12 @@ function base64UrlDecode(value) {
|
|
|
1866
3023
|
if (value.length % 4 === 1) {
|
|
1867
3024
|
throw new SignatureMaterialError("signature value is not canonical base64url");
|
|
1868
3025
|
}
|
|
1869
|
-
const
|
|
3026
|
+
const alphabet2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
1870
3027
|
const bytes = [];
|
|
1871
3028
|
let buffer = 0;
|
|
1872
3029
|
let bits = 0;
|
|
1873
3030
|
for (const char of value) {
|
|
1874
|
-
const index =
|
|
3031
|
+
const index = alphabet2.indexOf(char);
|
|
1875
3032
|
if (index < 0) {
|
|
1876
3033
|
throw new SignatureMaterialError("signature value is not base64url");
|
|
1877
3034
|
}
|
|
@@ -1906,14 +3063,14 @@ var OWNER_NODE_ENDPOINT_SCHEMA = "xyz.tinycloud.exchange/owner-node-endpoint/v1"
|
|
|
1906
3063
|
var POLICY_VERSION_V0 = "v0";
|
|
1907
3064
|
var W3C_VC_CREDENTIAL_VERIFIER = "w3c.vc/credential/v1";
|
|
1908
3065
|
var PolicyAuthoringError = class extends Error {
|
|
1909
|
-
constructor(
|
|
3066
|
+
constructor(code2, message) {
|
|
1910
3067
|
super(message);
|
|
1911
3068
|
this.name = "PolicyAuthoringError";
|
|
1912
|
-
this.code =
|
|
3069
|
+
this.code = code2;
|
|
1913
3070
|
}
|
|
1914
3071
|
};
|
|
1915
|
-
async function verifyPolicyEngineRecordForRequester(
|
|
1916
|
-
const normalized = expectObject2(
|
|
3072
|
+
async function verifyPolicyEngineRecordForRequester(options2) {
|
|
3073
|
+
const normalized = expectObject2(options2, "$", "policy-authoring-malformed");
|
|
1917
3074
|
assertExactKeys3(
|
|
1918
3075
|
normalized,
|
|
1919
3076
|
[
|
|
@@ -2020,11 +3177,11 @@ async function verifyPolicyEngineRecordForRequester(options) {
|
|
|
2020
3177
|
}
|
|
2021
3178
|
return verified;
|
|
2022
3179
|
}
|
|
2023
|
-
function expectObject2(input, path,
|
|
3180
|
+
function expectObject2(input, path, code2) {
|
|
2024
3181
|
try {
|
|
2025
3182
|
const normalized = normalizeJson(input);
|
|
2026
3183
|
if (normalized === null || typeof normalized !== "object" || Array.isArray(normalized)) {
|
|
2027
|
-
throw new PolicyAuthoringError(
|
|
3184
|
+
throw new PolicyAuthoringError(code2, `${path} must be an object`);
|
|
2028
3185
|
}
|
|
2029
3186
|
return normalized;
|
|
2030
3187
|
} catch (error) {
|
|
@@ -2032,7 +3189,7 @@ function expectObject2(input, path, code) {
|
|
|
2032
3189
|
throw error;
|
|
2033
3190
|
}
|
|
2034
3191
|
throw new PolicyAuthoringError(
|
|
2035
|
-
|
|
3192
|
+
code2,
|
|
2036
3193
|
error instanceof Error ? error.message : String(error)
|
|
2037
3194
|
);
|
|
2038
3195
|
}
|
|
@@ -2067,14 +3224,14 @@ function requiredString3(object, key, path) {
|
|
|
2067
3224
|
}
|
|
2068
3225
|
return value;
|
|
2069
3226
|
}
|
|
2070
|
-
function fieldString(object, key, path,
|
|
3227
|
+
function fieldString(object, key, path, code2) {
|
|
2071
3228
|
if (!hasOwn3(object, key)) {
|
|
2072
|
-
throw new PolicyAuthoringError(
|
|
3229
|
+
throw new PolicyAuthoringError(code2, `${path}.${key} is required`);
|
|
2073
3230
|
}
|
|
2074
3231
|
const value = object[key];
|
|
2075
3232
|
if (typeof value !== "string" || value.length === 0) {
|
|
2076
3233
|
throw new PolicyAuthoringError(
|
|
2077
|
-
|
|
3234
|
+
code2,
|
|
2078
3235
|
`${path}.${key} must be a non-empty string`
|
|
2079
3236
|
);
|
|
2080
3237
|
}
|
|
@@ -2180,10 +3337,10 @@ var POLICY_ENGINE_GRANT_PRESENTATION_DENIAL_CODES = [
|
|
|
2180
3337
|
"rate-limited"
|
|
2181
3338
|
];
|
|
2182
3339
|
var TranscriptRequesterError = class extends Error {
|
|
2183
|
-
constructor(
|
|
3340
|
+
constructor(code2, message, state = "invalid", denialCode, status) {
|
|
2184
3341
|
super(message);
|
|
2185
3342
|
this.name = "TranscriptRequesterError";
|
|
2186
|
-
this.code =
|
|
3343
|
+
this.code = code2;
|
|
2187
3344
|
this.state = state;
|
|
2188
3345
|
this.denialCode = denialCode;
|
|
2189
3346
|
this.status = status;
|
|
@@ -2321,50 +3478,50 @@ var LISTEN_SQL_STATEMENT_BY_NAME = new Map(
|
|
|
2321
3478
|
])
|
|
2322
3479
|
);
|
|
2323
3480
|
var TranscriptRequester = class _TranscriptRequester {
|
|
2324
|
-
constructor(bootstrap, requestedCapabilities, nativeAuthorityCeiling, requestedCapabilitiesHash2, policyEngineRecordExpiresAtMs, policyEngineAddresses, ownerNodeAddresses,
|
|
3481
|
+
constructor(bootstrap, requestedCapabilities, nativeAuthorityCeiling, requestedCapabilitiesHash2, policyEngineRecordExpiresAtMs, policyEngineAddresses, ownerNodeAddresses, options2) {
|
|
2325
3482
|
this.usedChallengeNonces = /* @__PURE__ */ new Set();
|
|
2326
3483
|
this.accessEnded = false;
|
|
2327
3484
|
this.bootstrap = bootstrap;
|
|
2328
3485
|
this.requestedCapabilities = requestedCapabilities;
|
|
2329
3486
|
this.nativeAuthorityCeiling = nativeAuthorityCeiling;
|
|
2330
3487
|
this.requestedCapabilitiesHash = requestedCapabilitiesHash2;
|
|
2331
|
-
this.requesterDid =
|
|
2332
|
-
this.ownerDid =
|
|
2333
|
-
this.audience =
|
|
2334
|
-
this.grantIssuerDid =
|
|
2335
|
-
this.transport =
|
|
2336
|
-
this.signingCapability =
|
|
2337
|
-
this.invocationCapability =
|
|
3488
|
+
this.requesterDid = options2.requesterDid;
|
|
3489
|
+
this.ownerDid = options2.ownerDid;
|
|
3490
|
+
this.audience = options2.audience;
|
|
3491
|
+
this.grantIssuerDid = options2.grantIssuerDid;
|
|
3492
|
+
this.transport = options2.transport;
|
|
3493
|
+
this.signingCapability = options2.signingCapability;
|
|
3494
|
+
this.invocationCapability = options2.invocationCapability;
|
|
2338
3495
|
this.policyEngineRecordExpiresAtMs = policyEngineRecordExpiresAtMs;
|
|
2339
3496
|
this.policyEngineAddresses = policyEngineAddresses;
|
|
2340
3497
|
this.ownerNodeAddresses = ownerNodeAddresses;
|
|
2341
|
-
this.eligibleSubjectDid =
|
|
2342
|
-
this.holderBinding =
|
|
3498
|
+
this.eligibleSubjectDid = options2.eligibleSubjectDid ?? options2.signingCapability?.eligibleSubjectDid ?? options2.requesterDid;
|
|
3499
|
+
this.holderBinding = options2.holderBinding ?? options2.signingCapability?.holderBinding ?? {
|
|
2343
3500
|
type: "enrolled-agent",
|
|
2344
3501
|
enrollment: {
|
|
2345
3502
|
schema: "xyz.tinycloud.policy/holder-enrollment/v0",
|
|
2346
|
-
holderDid:
|
|
3503
|
+
holderDid: options2.requesterDid
|
|
2347
3504
|
}
|
|
2348
3505
|
};
|
|
2349
|
-
this.evidence =
|
|
3506
|
+
this.evidence = options2.evidence ?? options2.signingCapability?.evidence;
|
|
2350
3507
|
this.presentationTtlSeconds = Math.min(
|
|
2351
|
-
Math.max(
|
|
3508
|
+
Math.max(options2.presentationTtlSeconds ?? 60, 1),
|
|
2352
3509
|
300
|
|
2353
3510
|
);
|
|
2354
|
-
this.now =
|
|
2355
|
-
this.sleep =
|
|
2356
|
-
this.random =
|
|
2357
|
-
this.engineRetryAttempts =
|
|
2358
|
-
}
|
|
2359
|
-
static async create(
|
|
2360
|
-
const bootstrap = parseBootstrap(
|
|
2361
|
-
if (bootstrap.ownerNode.endpoint !==
|
|
3511
|
+
this.now = options2.now ?? (() => /* @__PURE__ */ new Date());
|
|
3512
|
+
this.sleep = options2.sleep ?? ((milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds)));
|
|
3513
|
+
this.random = options2.random ?? Math.random;
|
|
3514
|
+
this.engineRetryAttempts = options2.engineRetryAttempts ?? REQUESTER_ENGINE_RETRY_ATTEMPTS;
|
|
3515
|
+
}
|
|
3516
|
+
static async create(options2) {
|
|
3517
|
+
const bootstrap = parseBootstrap(options2.bootstrap);
|
|
3518
|
+
if (bootstrap.ownerNode.endpoint !== options2.trustedOwnerNode.endpoint || bootstrap.ownerNode.spaceId !== options2.trustedOwnerNode.spaceId) {
|
|
2362
3519
|
throw endpointError(
|
|
2363
3520
|
"owner-node",
|
|
2364
3521
|
"bootstrap owner-node binding does not match trusted discovery/config"
|
|
2365
3522
|
);
|
|
2366
3523
|
}
|
|
2367
|
-
const record = await verifyRecordBeforeEgress(bootstrap,
|
|
3524
|
+
const record = await verifyRecordBeforeEgress(bootstrap, options2);
|
|
2368
3525
|
if (record.endpoint !== bootstrap.policyEngine.endpoint) {
|
|
2369
3526
|
throw new TranscriptRequesterError(
|
|
2370
3527
|
"requester-engine-record-endpoint-mismatch",
|
|
@@ -2381,12 +3538,12 @@ var TranscriptRequester = class _TranscriptRequester {
|
|
|
2381
3538
|
}
|
|
2382
3539
|
const policyEngineAddresses = await validateAndResolvePublicEndpoint(
|
|
2383
3540
|
bootstrap.policyEngine.endpoint,
|
|
2384
|
-
|
|
3541
|
+
options2.transport,
|
|
2385
3542
|
"policy-engine"
|
|
2386
3543
|
);
|
|
2387
3544
|
const ownerNodeAddresses = await validateAndResolveOwnerNode(
|
|
2388
3545
|
bootstrap.ownerNode.endpoint,
|
|
2389
|
-
|
|
3546
|
+
options2.transport
|
|
2390
3547
|
);
|
|
2391
3548
|
const requestedCapabilities = bootstrap.resourceHint.requestedCapabilities.map(
|
|
2392
3549
|
(capability, index) => parsePolicyCapability(
|
|
@@ -2406,7 +3563,7 @@ var TranscriptRequester = class _TranscriptRequester {
|
|
|
2406
3563
|
parseStrictRfc33392(record.expiresAt),
|
|
2407
3564
|
policyEngineAddresses,
|
|
2408
3565
|
ownerNodeAddresses,
|
|
2409
|
-
|
|
3566
|
+
options2
|
|
2410
3567
|
);
|
|
2411
3568
|
}
|
|
2412
3569
|
get accessState() {
|
|
@@ -2930,8 +4087,8 @@ var TranscriptRequester = class _TranscriptRequester {
|
|
|
2930
4087
|
}
|
|
2931
4088
|
}
|
|
2932
4089
|
};
|
|
2933
|
-
async function createTranscriptRequester(
|
|
2934
|
-
return TranscriptRequester.create(
|
|
4090
|
+
async function createTranscriptRequester(options2) {
|
|
4091
|
+
return TranscriptRequester.create(options2);
|
|
2935
4092
|
}
|
|
2936
4093
|
function parseBootstrap(input) {
|
|
2937
4094
|
const normalized = normalizeExternal(input, "requester-bootstrap-malformed");
|
|
@@ -2945,35 +4102,35 @@ function parseBootstrap(input) {
|
|
|
2945
4102
|
}
|
|
2946
4103
|
return parsed.data;
|
|
2947
4104
|
}
|
|
2948
|
-
async function verifyRecordBeforeEgress(bootstrap,
|
|
4105
|
+
async function verifyRecordBeforeEgress(bootstrap, options2) {
|
|
2949
4106
|
try {
|
|
2950
4107
|
return await verifyPolicyEngineRecordForRequester({
|
|
2951
4108
|
signedRecord: bootstrap.policyEngine.signedRecord,
|
|
2952
|
-
ownerDid:
|
|
2953
|
-
audience:
|
|
2954
|
-
grantIssuerDid:
|
|
2955
|
-
now: (
|
|
4109
|
+
ownerDid: options2.ownerDid,
|
|
4110
|
+
audience: options2.audience,
|
|
4111
|
+
grantIssuerDid: options2.grantIssuerDid,
|
|
4112
|
+
now: (options2.now ?? (() => /* @__PURE__ */ new Date()))().toISOString().replace(".000Z", "Z"),
|
|
2956
4113
|
requiredPolicyVersion: POLICY_VERSION_V0,
|
|
2957
4114
|
requiredEvidenceVerifier: W3C_VC_CREDENTIAL_VERIFIER
|
|
2958
4115
|
});
|
|
2959
4116
|
} catch (error) {
|
|
2960
|
-
const
|
|
4117
|
+
const code2 = errorCodeForRecordFailure(error);
|
|
2961
4118
|
throw new TranscriptRequesterError(
|
|
2962
|
-
|
|
4119
|
+
code2,
|
|
2963
4120
|
error instanceof Error ? error.message : String(error),
|
|
2964
4121
|
"bootstrap-invalid"
|
|
2965
4122
|
);
|
|
2966
4123
|
}
|
|
2967
4124
|
}
|
|
2968
4125
|
function errorCodeForRecordFailure(error) {
|
|
2969
|
-
const
|
|
2970
|
-
if (
|
|
4126
|
+
const code2 = typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
|
|
4127
|
+
if (code2 === "policy-engine-record-signature-invalid") {
|
|
2971
4128
|
return "requester-engine-record-signature-invalid";
|
|
2972
4129
|
}
|
|
2973
|
-
if (
|
|
4130
|
+
if (code2 === "policy-engine-record-owner-mismatch") {
|
|
2974
4131
|
return "requester-engine-record-owner-mismatch";
|
|
2975
4132
|
}
|
|
2976
|
-
if (
|
|
4133
|
+
if (code2 === "policy-engine-record-audience-mismatch") {
|
|
2977
4134
|
return "requester-engine-record-audience-mismatch";
|
|
2978
4135
|
}
|
|
2979
4136
|
return "requester-engine-record-invalid";
|
|
@@ -3273,16 +4430,16 @@ function nodeErrorMessage(body) {
|
|
|
3273
4430
|
if (typeof body === "string") return body;
|
|
3274
4431
|
if (body !== null && typeof body === "object") {
|
|
3275
4432
|
const record = body;
|
|
3276
|
-
const
|
|
4433
|
+
const code2 = typeof record.code === "string" ? record.code : void 0;
|
|
3277
4434
|
const message = typeof record.message === "string" ? record.message : void 0;
|
|
3278
|
-
if (
|
|
3279
|
-
return message === void 0 ?
|
|
4435
|
+
if (code2 !== void 0)
|
|
4436
|
+
return message === void 0 ? code2 : `${code2}: ${message}`;
|
|
3280
4437
|
}
|
|
3281
4438
|
return "native node refusal";
|
|
3282
4439
|
}
|
|
3283
4440
|
function deriveDelegationCid(encoded) {
|
|
3284
|
-
const
|
|
3285
|
-
return
|
|
4441
|
+
const digest2 = create(30, (0, import_blake3.blake3)(new TextEncoder().encode(encoded)));
|
|
4442
|
+
return CID.createV1(85, digest2).toString();
|
|
3286
4443
|
}
|
|
3287
4444
|
function headersRecord(headers) {
|
|
3288
4445
|
return Array.isArray(headers) ? Object.fromEntries(headers) : headers;
|
|
@@ -3393,21 +4550,21 @@ function errorForDenial(denial, status) {
|
|
|
3393
4550
|
);
|
|
3394
4551
|
}
|
|
3395
4552
|
function retryDelay(attempt, random) {
|
|
3396
|
-
const
|
|
4553
|
+
const base3 = Math.min(REQUESTER_ENGINE_RETRY_MAX_DELAY_MS, 50 * 2 ** attempt);
|
|
3397
4554
|
return Math.min(
|
|
3398
4555
|
REQUESTER_ENGINE_RETRY_MAX_DELAY_MS,
|
|
3399
|
-
Math.floor(
|
|
4556
|
+
Math.floor(base3 * (0.5 + random))
|
|
3400
4557
|
);
|
|
3401
4558
|
}
|
|
3402
4559
|
function trimTrailingSlash(value) {
|
|
3403
4560
|
return value.endsWith("/") ? value.slice(0, -1) : value;
|
|
3404
4561
|
}
|
|
3405
|
-
function normalizeExternal(input,
|
|
4562
|
+
function normalizeExternal(input, code2) {
|
|
3406
4563
|
try {
|
|
3407
4564
|
return normalizeJson(input);
|
|
3408
4565
|
} catch (error) {
|
|
3409
4566
|
throw new TranscriptRequesterError(
|
|
3410
|
-
|
|
4567
|
+
code2,
|
|
3411
4568
|
error instanceof Error ? error.message : String(error)
|
|
3412
4569
|
);
|
|
3413
4570
|
}
|
|
@@ -3700,6 +4857,8 @@ var DelegationSchema = import_zod4.z.object({
|
|
|
3700
4857
|
path: import_zod4.z.string(),
|
|
3701
4858
|
/** Actions this delegation authorizes */
|
|
3702
4859
|
actions: import_zod4.z.array(import_zod4.z.string()),
|
|
4860
|
+
/** Exact ReCap caveats that constrain every action in this scope. */
|
|
4861
|
+
caveats: import_zod4.z.array(import_zod4.z.record(import_zod4.z.string(), import_zod4.z.unknown())).optional(),
|
|
3703
4862
|
/** When this delegation expires (accepts Date or ISO string from JSON) */
|
|
3704
4863
|
expiry: import_zod4.z.coerce.date(),
|
|
3705
4864
|
/** Whether this delegation has been revoked */
|
|
@@ -3731,6 +4890,43 @@ var DelegationStatusSchema = import_zod4.z.object({
|
|
|
3731
4890
|
});
|
|
3732
4891
|
}
|
|
3733
4892
|
});
|
|
4893
|
+
var DelegationRevocationReceiptSchema = import_zod4.z.object({
|
|
4894
|
+
revoked: import_zod4.z.literal(true),
|
|
4895
|
+
cid: import_zod4.z.string().min(1)
|
|
4896
|
+
}).strict();
|
|
4897
|
+
var AccountDelegationResourceSchema = import_zod4.z.object({
|
|
4898
|
+
resource: import_zod4.z.string().min(1),
|
|
4899
|
+
actions: import_zod4.z.array(import_zod4.z.string()),
|
|
4900
|
+
caveats: import_zod4.z.array(import_zod4.z.record(import_zod4.z.string(), import_zod4.z.unknown()))
|
|
4901
|
+
}).strict();
|
|
4902
|
+
var AccountDelegationDateSchema = import_zod4.z.string().datetime({ offset: true }).transform((value) => new Date(value));
|
|
4903
|
+
var AccountDelegationRecordSchema = import_zod4.z.object({
|
|
4904
|
+
cid: import_zod4.z.string().min(1),
|
|
4905
|
+
direction: import_zod4.z.enum(["granted", "received"]),
|
|
4906
|
+
delegatorDid: import_zod4.z.string().min(1),
|
|
4907
|
+
delegateDid: import_zod4.z.string().min(1),
|
|
4908
|
+
resources: import_zod4.z.array(AccountDelegationResourceSchema),
|
|
4909
|
+
parents: import_zod4.z.array(import_zod4.z.string()),
|
|
4910
|
+
issuedAt: AccountDelegationDateSchema.nullable(),
|
|
4911
|
+
notBefore: AccountDelegationDateSchema.nullable(),
|
|
4912
|
+
expiresAt: AccountDelegationDateSchema.nullable(),
|
|
4913
|
+
status: import_zod4.z.enum(["active", "pending", "expired", "revoked", "ancestor_revoked"]),
|
|
4914
|
+
revokedAt: AccountDelegationDateSchema.nullable().optional(),
|
|
4915
|
+
revokedBy: import_zod4.z.string().optional(),
|
|
4916
|
+
revokedAncestorCid: import_zod4.z.string().optional()
|
|
4917
|
+
}).strict();
|
|
4918
|
+
var AccountDelegationPageSchema = import_zod4.z.object({
|
|
4919
|
+
schemaVersion: import_zod4.z.literal(2),
|
|
4920
|
+
items: import_zod4.z.array(AccountDelegationRecordSchema),
|
|
4921
|
+
nextCursor: import_zod4.z.string().optional()
|
|
4922
|
+
}).strict();
|
|
4923
|
+
var AccountDelegationQueryOptionsSchema = import_zod4.z.object({
|
|
4924
|
+
direction: import_zod4.z.enum(["granted", "received", "all"]).optional(),
|
|
4925
|
+
status: import_zod4.z.enum(["active", "pending", "expired", "revoked", "ancestor_revoked"]).optional(),
|
|
4926
|
+
space: import_zod4.z.string().trim().min(1).optional(),
|
|
4927
|
+
limit: import_zod4.z.number().int().min(1).max(100).optional(),
|
|
4928
|
+
cursor: import_zod4.z.string().min(1).optional()
|
|
4929
|
+
}).strict();
|
|
3734
4930
|
var CapabilityEntrySchema = import_zod4.z.object({
|
|
3735
4931
|
/** Resource URI this capability applies to */
|
|
3736
4932
|
resource: import_zod4.z.string(),
|
|
@@ -3885,6 +5081,8 @@ var GenerateShareParamsSchema = import_zod4.z.object({
|
|
|
3885
5081
|
var DelegationManagerConfigSchema = import_zod4.z.object({
|
|
3886
5082
|
/** TinyCloud host URLs */
|
|
3887
5083
|
hosts: import_zod4.z.array(import_zod4.z.string()),
|
|
5084
|
+
/** Account space used by account-wide delegation history queries */
|
|
5085
|
+
accountSpaceId: import_zod4.z.string().min(1).optional(),
|
|
3888
5086
|
/** Active session for authentication */
|
|
3889
5087
|
session: import_zod4.z.unknown().refine(
|
|
3890
5088
|
(val) => val !== null && typeof val === "object",
|
|
@@ -3941,7 +5139,9 @@ var DelegatedResourceSchema = import_zod4.z.object({
|
|
|
3941
5139
|
/** Resource path; empty string when the resource URI had no path segment. */
|
|
3942
5140
|
path: import_zod4.z.string(),
|
|
3943
5141
|
/** Full-URN ability strings, e.g. ["tinycloud.kv/get", "tinycloud.kv/put"]. */
|
|
3944
|
-
actions: import_zod4.z.array(import_zod4.z.string())
|
|
5142
|
+
actions: import_zod4.z.array(import_zod4.z.string()),
|
|
5143
|
+
/** Exact ReCap caveats that constrain every action in this scope. */
|
|
5144
|
+
caveats: import_zod4.z.array(import_zod4.z.record(import_zod4.z.string(), import_zod4.z.unknown())).optional()
|
|
3945
5145
|
});
|
|
3946
5146
|
var CreateDelegationWasmParamsSchema = import_zod4.z.object({
|
|
3947
5147
|
/** The session containing delegation credentials */
|
|
@@ -4216,13 +5416,13 @@ function parseSpaceUri(uri) {
|
|
|
4216
5416
|
/^tinycloud:pkh:eip155:(\d+):(0x[a-fA-F0-9]{40}):(.+)$/
|
|
4217
5417
|
);
|
|
4218
5418
|
if (fullUriMatch) {
|
|
4219
|
-
const [, chainId, address,
|
|
5419
|
+
const [, chainId, address, name2] = fullUriMatch;
|
|
4220
5420
|
try {
|
|
4221
5421
|
const chainIdNumber = Number(chainId);
|
|
4222
5422
|
const canonicalAddress = canonicalizeAddress(address);
|
|
4223
5423
|
return {
|
|
4224
5424
|
owner: pkhDid(canonicalAddress, chainIdNumber),
|
|
4225
|
-
name,
|
|
5425
|
+
name: name2,
|
|
4226
5426
|
chainId: String(chainIdNumber),
|
|
4227
5427
|
address: canonicalAddress
|
|
4228
5428
|
};
|
|
@@ -4239,12 +5439,12 @@ function parseSpaceUri(uri) {
|
|
|
4239
5439
|
}
|
|
4240
5440
|
return null;
|
|
4241
5441
|
}
|
|
4242
|
-
function buildSpaceUri(owner,
|
|
5442
|
+
function buildSpaceUri(owner, name2) {
|
|
4243
5443
|
const pkh = parsePkhDid(owner);
|
|
4244
5444
|
if (pkh) {
|
|
4245
|
-
return makePkhSpaceId(pkh.address, pkh.chainId,
|
|
5445
|
+
return makePkhSpaceId(pkh.address, pkh.chainId, name2);
|
|
4246
5446
|
}
|
|
4247
|
-
return `tinycloud:${owner}:${
|
|
5447
|
+
return `tinycloud:${owner}:${name2}`;
|
|
4248
5448
|
}
|
|
4249
5449
|
function transformServerDelegations(validatedData, defaultSpaceId) {
|
|
4250
5450
|
const result = [];
|
|
@@ -4509,13 +5709,13 @@ var SpaceService = class {
|
|
|
4509
5709
|
*
|
|
4510
5710
|
* @param name - The name for the new space
|
|
4511
5711
|
*/
|
|
4512
|
-
async create(
|
|
5712
|
+
async create(name2) {
|
|
4513
5713
|
if (!this.session) {
|
|
4514
5714
|
return (0, import_sdk_services2.err)(
|
|
4515
5715
|
(0, import_sdk_services2.serviceError)(SpaceErrorCodes.AUTH_REQUIRED, "Authentication required", SERVICE_NAME)
|
|
4516
5716
|
);
|
|
4517
5717
|
}
|
|
4518
|
-
if (!
|
|
5718
|
+
if (!name2 || !/^[a-zA-Z0-9_-]+$/.test(name2)) {
|
|
4519
5719
|
return (0, import_sdk_services2.err)(
|
|
4520
5720
|
(0, import_sdk_services2.serviceError)(
|
|
4521
5721
|
SpaceErrorCodes.INVALID_NAME,
|
|
@@ -4525,11 +5725,11 @@ var SpaceService = class {
|
|
|
4525
5725
|
);
|
|
4526
5726
|
}
|
|
4527
5727
|
try {
|
|
4528
|
-
const headers = this.invoke(this.session, "space",
|
|
5728
|
+
const headers = this.invoke(this.session, "space", name2, "tinycloud.space/create");
|
|
4529
5729
|
const response = await this.fetchFn(`${this.host}/invoke`, {
|
|
4530
5730
|
method: "POST",
|
|
4531
5731
|
headers,
|
|
4532
|
-
body: JSON.stringify({ name })
|
|
5732
|
+
body: JSON.stringify({ name: name2 })
|
|
4533
5733
|
});
|
|
4534
5734
|
if (!response.ok) {
|
|
4535
5735
|
const errorText = await response.text();
|
|
@@ -4537,7 +5737,7 @@ var SpaceService = class {
|
|
|
4537
5737
|
return (0, import_sdk_services2.err)(
|
|
4538
5738
|
(0, import_sdk_services2.serviceError)(
|
|
4539
5739
|
SpaceErrorCodes.ALREADY_EXISTS,
|
|
4540
|
-
`Space "${
|
|
5740
|
+
`Space "${name2}" already exists`,
|
|
4541
5741
|
SERVICE_NAME
|
|
4542
5742
|
)
|
|
4543
5743
|
);
|
|
@@ -4565,7 +5765,7 @@ var SpaceService = class {
|
|
|
4565
5765
|
}
|
|
4566
5766
|
const spaceInfo = {
|
|
4567
5767
|
id: validationResult.data.id,
|
|
4568
|
-
name: validationResult.data.name ||
|
|
5768
|
+
name: validationResult.data.name || name2,
|
|
4569
5769
|
owner: validationResult.data.owner || this.userDid || "",
|
|
4570
5770
|
type: "owned",
|
|
4571
5771
|
permissions: ["*"]
|
|
@@ -4604,10 +5804,10 @@ var SpaceService = class {
|
|
|
4604
5804
|
return cached;
|
|
4605
5805
|
}
|
|
4606
5806
|
const parsed = parseSpaceUri(spaceId);
|
|
4607
|
-
const
|
|
5807
|
+
const name2 = parsed?.name ?? this.extractNameFromId(spaceId);
|
|
4608
5808
|
const config = {
|
|
4609
5809
|
id: spaceId,
|
|
4610
|
-
name,
|
|
5810
|
+
name: name2,
|
|
4611
5811
|
createKV: this.createSpaceScopedKV.bind(this),
|
|
4612
5812
|
createVault: this.createSpaceScopedVault.bind(this),
|
|
4613
5813
|
createSecrets: this.createSpaceScopedSecrets.bind(this),
|
|
@@ -5051,12 +6251,12 @@ var TinyCloud = class _TinyCloud {
|
|
|
5051
6251
|
hooks: import_sdk_services3.HooksService,
|
|
5052
6252
|
...this.config.services
|
|
5053
6253
|
};
|
|
5054
|
-
for (const [
|
|
5055
|
-
const serviceConfig = this.config.serviceConfigs?.[
|
|
6254
|
+
for (const [name2, ServiceClass] of Object.entries(serviceConstructors)) {
|
|
6255
|
+
const serviceConfig = this.config.serviceConfigs?.[name2] ?? {};
|
|
5056
6256
|
const service = new ServiceClass(serviceConfig);
|
|
5057
6257
|
service.initialize(this._serviceContext);
|
|
5058
|
-
this._serviceContext.registerService(
|
|
5059
|
-
this._services.set(
|
|
6258
|
+
this._serviceContext.registerService(name2, service);
|
|
6259
|
+
this._services.set(name2, service);
|
|
5060
6260
|
}
|
|
5061
6261
|
this._servicesInitialized = true;
|
|
5062
6262
|
}
|
|
@@ -5072,14 +6272,23 @@ var TinyCloud = class _TinyCloud {
|
|
|
5072
6272
|
}
|
|
5073
6273
|
return this._serviceContext;
|
|
5074
6274
|
}
|
|
6275
|
+
/** @internal Retire this service graph after its owner replaces a session. */
|
|
6276
|
+
retireServices() {
|
|
6277
|
+
try {
|
|
6278
|
+
this._serviceContext?.retire();
|
|
6279
|
+
} finally {
|
|
6280
|
+
this._services.clear();
|
|
6281
|
+
this._servicesInitialized = false;
|
|
6282
|
+
}
|
|
6283
|
+
}
|
|
5075
6284
|
/**
|
|
5076
6285
|
* Get a registered service by name.
|
|
5077
6286
|
*
|
|
5078
6287
|
* @param name - Service name (e.g., 'kv')
|
|
5079
6288
|
* @returns The service instance or undefined
|
|
5080
6289
|
*/
|
|
5081
|
-
getService(
|
|
5082
|
-
return this._services.get(
|
|
6290
|
+
getService(name2) {
|
|
6291
|
+
return this._services.get(name2);
|
|
5083
6292
|
}
|
|
5084
6293
|
/**
|
|
5085
6294
|
* Get the KV service.
|
|
@@ -5247,8 +6456,8 @@ var TinyCloud = class _TinyCloud {
|
|
|
5247
6456
|
* @param options - Optional per-call SIWE overrides for this sign-in only
|
|
5248
6457
|
* @returns The new session
|
|
5249
6458
|
*/
|
|
5250
|
-
async signIn(
|
|
5251
|
-
const session = await this.userAuthorization.signIn(
|
|
6459
|
+
async signIn(options2) {
|
|
6460
|
+
const session = await this.userAuthorization.signIn(options2);
|
|
5252
6461
|
const serviceSession = this.toServiceSession(session);
|
|
5253
6462
|
this.notifyServicesOfSessionChange(serviceSession);
|
|
5254
6463
|
return session;
|
|
@@ -5787,32 +6996,32 @@ function validateManifestSecrets(secrets) {
|
|
|
5787
6996
|
if (secrets === null || typeof secrets !== "object" || Array.isArray(secrets)) {
|
|
5788
6997
|
throw new ManifestValidationError("manifest.secrets must be an object");
|
|
5789
6998
|
}
|
|
5790
|
-
for (const [
|
|
5791
|
-
if (!import_sdk_services4.SECRET_NAME_RE.test(
|
|
6999
|
+
for (const [name2, spec] of Object.entries(secrets)) {
|
|
7000
|
+
if (!import_sdk_services4.SECRET_NAME_RE.test(name2)) {
|
|
5792
7001
|
throw new ManifestValidationError(
|
|
5793
|
-
`manifest.secrets.${
|
|
7002
|
+
`manifest.secrets.${name2} must match ${import_sdk_services4.SECRET_NAME_RE.source}`
|
|
5794
7003
|
);
|
|
5795
7004
|
}
|
|
5796
7005
|
try {
|
|
5797
7006
|
(0, import_sdk_services4.resolveSecretPath)(
|
|
5798
|
-
secretNameFromSpec(
|
|
7007
|
+
secretNameFromSpec(name2, spec),
|
|
5799
7008
|
{ scope: secretScopeFromSpec(spec) }
|
|
5800
7009
|
);
|
|
5801
7010
|
} catch (error) {
|
|
5802
7011
|
throw new ManifestValidationError(
|
|
5803
|
-
`manifest.secrets.${
|
|
7012
|
+
`manifest.secrets.${name2}: ${error instanceof Error ? error.message : String(error)}`
|
|
5804
7013
|
);
|
|
5805
7014
|
}
|
|
5806
|
-
const actions = secretActionsFromSpec(
|
|
7015
|
+
const actions = secretActionsFromSpec(name2, spec);
|
|
5807
7016
|
if (actions.length === 0) {
|
|
5808
7017
|
throw new ManifestValidationError(
|
|
5809
|
-
`manifest.secrets.${
|
|
7018
|
+
`manifest.secrets.${name2} actions must be non-empty`
|
|
5810
7019
|
);
|
|
5811
7020
|
}
|
|
5812
7021
|
for (const action of actions) {
|
|
5813
7022
|
if (typeof action !== "string" || action.length === 0) {
|
|
5814
7023
|
throw new ManifestValidationError(
|
|
5815
|
-
`manifest.secrets.${
|
|
7024
|
+
`manifest.secrets.${name2} actions must be non-empty strings`
|
|
5816
7025
|
);
|
|
5817
7026
|
}
|
|
5818
7027
|
}
|
|
@@ -5854,6 +7063,11 @@ function validatePermissionEntry(p, path) {
|
|
|
5854
7063
|
vaultActionExpansion(action);
|
|
5855
7064
|
}
|
|
5856
7065
|
}
|
|
7066
|
+
if (entry.caveats !== void 0 && (!Array.isArray(entry.caveats) || entry.caveats.some(
|
|
7067
|
+
(caveat) => caveat === null || typeof caveat !== "object" || Array.isArray(caveat)
|
|
7068
|
+
))) {
|
|
7069
|
+
throw new ManifestValidationError(`${path}.caveats must be an array of objects`);
|
|
7070
|
+
}
|
|
5857
7071
|
if (entry.expiry !== void 0) {
|
|
5858
7072
|
parseExpiry(entry.expiry);
|
|
5859
7073
|
}
|
|
@@ -5971,7 +7185,7 @@ function secretScopeFromSpec(spec) {
|
|
|
5971
7185
|
}
|
|
5972
7186
|
return void 0;
|
|
5973
7187
|
}
|
|
5974
|
-
function secretActionsFromSpec(
|
|
7188
|
+
function secretActionsFromSpec(name2, spec) {
|
|
5975
7189
|
if (spec === true) {
|
|
5976
7190
|
return ["read"];
|
|
5977
7191
|
}
|
|
@@ -5983,7 +7197,7 @@ function secretActionsFromSpec(name, spec) {
|
|
|
5983
7197
|
}
|
|
5984
7198
|
if (spec === null || typeof spec !== "object") {
|
|
5985
7199
|
throw new ManifestValidationError(
|
|
5986
|
-
`manifest.secrets.${
|
|
7200
|
+
`manifest.secrets.${name2} must be true, a string action, an actions array, or an object`
|
|
5987
7201
|
);
|
|
5988
7202
|
}
|
|
5989
7203
|
if (spec.actions === void 0) {
|
|
@@ -5996,7 +7210,7 @@ function secretActionsFromSpec(name, spec) {
|
|
|
5996
7210
|
return spec.actions;
|
|
5997
7211
|
}
|
|
5998
7212
|
throw new ManifestValidationError(
|
|
5999
|
-
`manifest.secrets.${
|
|
7213
|
+
`manifest.secrets.${name2}.actions must be a string or array`
|
|
6000
7214
|
);
|
|
6001
7215
|
}
|
|
6002
7216
|
function secretEntriesForManifest(secrets) {
|
|
@@ -6004,10 +7218,10 @@ function secretEntriesForManifest(secrets) {
|
|
|
6004
7218
|
return [];
|
|
6005
7219
|
}
|
|
6006
7220
|
const entries = [];
|
|
6007
|
-
for (const [
|
|
6008
|
-
const actions = secretActionsFromSpec(
|
|
7221
|
+
for (const [name2, spec] of Object.entries(secrets)) {
|
|
7222
|
+
const actions = secretActionsFromSpec(name2, spec);
|
|
6009
7223
|
const secretPath = (0, import_sdk_services4.resolveSecretPath)(
|
|
6010
|
-
secretNameFromSpec(
|
|
7224
|
+
secretNameFromSpec(name2, spec),
|
|
6011
7225
|
{ scope: secretScopeFromSpec(spec) }
|
|
6012
7226
|
);
|
|
6013
7227
|
const extra = spec !== true && typeof spec === "object" && !Array.isArray(spec) ? spec : {};
|
|
@@ -6048,18 +7262,18 @@ function expandVaultPermissionEntry(entry) {
|
|
|
6048
7262
|
const byBase = /* @__PURE__ */ new Map();
|
|
6049
7263
|
for (const action of entry.actions) {
|
|
6050
7264
|
const expansion = vaultActionExpansion(action);
|
|
6051
|
-
for (const
|
|
6052
|
-
const actions = byBase.get(
|
|
7265
|
+
for (const base3 of expansion.bases) {
|
|
7266
|
+
const actions = byBase.get(base3) ?? [];
|
|
6053
7267
|
if (!actions.includes(expansion.action)) {
|
|
6054
7268
|
actions.push(expansion.action);
|
|
6055
7269
|
}
|
|
6056
|
-
byBase.set(
|
|
7270
|
+
byBase.set(base3, actions);
|
|
6057
7271
|
}
|
|
6058
7272
|
}
|
|
6059
|
-
return [...byBase.entries()].map(([
|
|
7273
|
+
return [...byBase.entries()].map(([base3, actions]) => ({
|
|
6060
7274
|
...entry,
|
|
6061
7275
|
service: "tinycloud.kv",
|
|
6062
|
-
path: vaultKVPath(
|
|
7276
|
+
path: vaultKVPath(base3, entry.path),
|
|
6063
7277
|
actions,
|
|
6064
7278
|
skipPrefix: true
|
|
6065
7279
|
}));
|
|
@@ -6102,9 +7316,9 @@ function normalizeVaultAction(action) {
|
|
|
6102
7316
|
}
|
|
6103
7317
|
return action;
|
|
6104
7318
|
}
|
|
6105
|
-
function vaultKVPath(
|
|
7319
|
+
function vaultKVPath(base3, path) {
|
|
6106
7320
|
const normalized = path.startsWith("/") ? path.slice(1) : path;
|
|
6107
|
-
return `${
|
|
7321
|
+
return `${base3}/${normalized}`;
|
|
6108
7322
|
}
|
|
6109
7323
|
function cloneResourceCapability(entry) {
|
|
6110
7324
|
return {
|
|
@@ -6122,6 +7336,7 @@ function clonePermissionEntry(entry) {
|
|
|
6122
7336
|
...entry.space !== void 0 ? { space: entry.space } : {},
|
|
6123
7337
|
path: entry.path,
|
|
6124
7338
|
actions: [...entry.actions],
|
|
7339
|
+
...entry.caveats !== void 0 ? { caveats: JSON.parse(JSON.stringify(entry.caveats)) } : {},
|
|
6125
7340
|
...entry.skipPrefix !== void 0 ? { skipPrefix: entry.skipPrefix } : {},
|
|
6126
7341
|
...entry.expiry !== void 0 ? { expiry: entry.expiry } : {},
|
|
6127
7342
|
...entry.description !== void 0 ? { description: entry.description } : {}
|
|
@@ -6170,12 +7385,20 @@ function withCapabilitiesReadForSpaces(resources) {
|
|
|
6170
7385
|
]);
|
|
6171
7386
|
}
|
|
6172
7387
|
function accountRegistryPermissions() {
|
|
6173
|
-
return [
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
7388
|
+
return [
|
|
7389
|
+
...[ACCOUNT_REGISTRY_PATH, "spaces/"].map((path) => ({
|
|
7390
|
+
service: "tinycloud.kv",
|
|
7391
|
+
space: ACCOUNT_REGISTRY_SPACE,
|
|
7392
|
+
path,
|
|
7393
|
+
actions: ["tinycloud.kv/get", "tinycloud.kv/put", "tinycloud.kv/list"]
|
|
7394
|
+
})),
|
|
7395
|
+
{
|
|
7396
|
+
service: "tinycloud.delegation",
|
|
7397
|
+
space: ACCOUNT_REGISTRY_SPACE,
|
|
7398
|
+
path: "",
|
|
7399
|
+
actions: ["tinycloud.delegation/list"]
|
|
7400
|
+
}
|
|
7401
|
+
];
|
|
6179
7402
|
}
|
|
6180
7403
|
function accountRegistryIndexPermission() {
|
|
6181
7404
|
return {
|
|
@@ -6185,13 +7408,13 @@ function accountRegistryIndexPermission() {
|
|
|
6185
7408
|
actions: ["tinycloud.sql/read", "tinycloud.sql/write", "tinycloud.sql/schema"]
|
|
6186
7409
|
};
|
|
6187
7410
|
}
|
|
6188
|
-
function composeManifestRequest(inputs,
|
|
7411
|
+
function composeManifestRequest(inputs, options2 = {}) {
|
|
6189
7412
|
if (!Array.isArray(inputs) || inputs.length === 0) {
|
|
6190
7413
|
throw new ManifestValidationError(
|
|
6191
7414
|
"composeManifestRequest requires at least one manifest"
|
|
6192
7415
|
);
|
|
6193
7416
|
}
|
|
6194
|
-
const includeAccountRegistryPermissions =
|
|
7417
|
+
const includeAccountRegistryPermissions = options2.includeAccountRegistryPermissions ?? true;
|
|
6195
7418
|
const manifests = inputs.map(validateManifest);
|
|
6196
7419
|
const resolved = manifests.map(resolveManifest);
|
|
6197
7420
|
const resources = resolved.flatMap((entry) => entry.resources);
|
|
@@ -6296,13 +7519,13 @@ var AccountService = class {
|
|
|
6296
7519
|
constructor(config) {
|
|
6297
7520
|
this.config = config;
|
|
6298
7521
|
this.applications = {
|
|
6299
|
-
list: async (
|
|
6300
|
-
if (
|
|
7522
|
+
list: async (options2 = {}) => {
|
|
7523
|
+
if (options2.preferIndex) {
|
|
6301
7524
|
const indexed = await this.index.applications.list();
|
|
6302
7525
|
if (indexed.ok && indexed.data.length > 0) return indexed;
|
|
6303
7526
|
if (!indexed.ok && !isMissingIndexError(indexed.error)) return indexed;
|
|
6304
7527
|
const canonical = await this.applications.list();
|
|
6305
|
-
if (canonical.ok &&
|
|
7528
|
+
if (canonical.ok && options2.refreshIndex !== false) {
|
|
6306
7529
|
await this.replaceApplicationsIndexQuietly(canonical.data);
|
|
6307
7530
|
}
|
|
6308
7531
|
return canonical;
|
|
@@ -6379,13 +7602,13 @@ var AccountService = class {
|
|
|
6379
7602
|
}
|
|
6380
7603
|
};
|
|
6381
7604
|
this.spaces = {
|
|
6382
|
-
list: async (
|
|
6383
|
-
if (
|
|
7605
|
+
list: async (options2 = {}) => {
|
|
7606
|
+
if (options2.preferIndex) {
|
|
6384
7607
|
const indexed = await this.index.spaces.list();
|
|
6385
7608
|
if (indexed.ok && indexed.data.length > 0) return indexed;
|
|
6386
7609
|
if (!indexed.ok && !isMissingIndexError(indexed.error)) return indexed;
|
|
6387
7610
|
const canonical = await this.spaces.syncAccessible();
|
|
6388
|
-
if (canonical.ok &&
|
|
7611
|
+
if (canonical.ok && options2.refreshIndex !== false) {
|
|
6389
7612
|
await this.replaceSpacesIndexQuietly(canonical.data);
|
|
6390
7613
|
}
|
|
6391
7614
|
return canonical;
|
|
@@ -6442,32 +7665,44 @@ var AccountService = class {
|
|
|
6442
7665
|
}
|
|
6443
7666
|
};
|
|
6444
7667
|
this.delegations = {
|
|
6445
|
-
|
|
6446
|
-
|
|
6447
|
-
|
|
7668
|
+
query: async (options2 = {}) => {
|
|
7669
|
+
const manager = this.config.getDelegationManager?.();
|
|
7670
|
+
if (!manager) {
|
|
7671
|
+
return (0, import_sdk_services5.err)((0, import_sdk_services5.serviceError)(
|
|
7672
|
+
"NOT_INITIALIZED",
|
|
7673
|
+
"Delegation history requires an authenticated delegation manager",
|
|
7674
|
+
SERVICE_NAME2
|
|
7675
|
+
));
|
|
7676
|
+
}
|
|
7677
|
+
const queried = await manager.query(options2);
|
|
7678
|
+
return queried.ok ? (0, import_sdk_services5.ok)(queried.data) : accountErr(queried.error);
|
|
7679
|
+
},
|
|
7680
|
+
list: async (options2 = {}) => {
|
|
7681
|
+
if (options2.preferIndex) {
|
|
7682
|
+
const indexed = await this.index.delegations.list(options2);
|
|
6448
7683
|
if (indexed.ok && indexed.data.length > 0) return indexed;
|
|
6449
7684
|
if (!indexed.ok && !isMissingIndexError(indexed.error)) return indexed;
|
|
6450
7685
|
const live = await this.delegations.list({
|
|
6451
|
-
direction:
|
|
6452
|
-
space:
|
|
7686
|
+
direction: options2.direction,
|
|
7687
|
+
space: options2.space
|
|
6453
7688
|
});
|
|
6454
|
-
if (live.ok &&
|
|
7689
|
+
if (live.ok && options2.refreshIndex !== false) {
|
|
6455
7690
|
await this.replaceDelegationsIndexQuietly(live.data);
|
|
6456
7691
|
}
|
|
6457
7692
|
return live;
|
|
6458
7693
|
}
|
|
6459
7694
|
const spaces = await this.config.getSpaces().list();
|
|
6460
7695
|
if (!spaces.ok) return accountErr(spaces.error);
|
|
6461
|
-
const targetSpaces =
|
|
7696
|
+
const targetSpaces = options2.space ? spaces.data.filter((space) => space.id === options2.space || space.name === options2.space) : spaces.data;
|
|
6462
7697
|
const delegations = [];
|
|
6463
7698
|
for (const space of targetSpaces) {
|
|
6464
7699
|
const scoped = this.config.getSpaces().get(space.id).delegations;
|
|
6465
|
-
if (
|
|
7700
|
+
if (options2.direction !== "received") {
|
|
6466
7701
|
const granted = await scoped.list();
|
|
6467
7702
|
if (!granted.ok) return accountErr(granted.error);
|
|
6468
7703
|
delegations.push(...granted.data.map((d) => mapDelegation(d, space, "granted")));
|
|
6469
7704
|
}
|
|
6470
|
-
if (
|
|
7705
|
+
if (options2.direction !== "granted") {
|
|
6471
7706
|
const received = await scoped.listReceived();
|
|
6472
7707
|
if (!received.ok) return accountErr(received.error);
|
|
6473
7708
|
delegations.push(...received.data.map((d) => mapDelegation(d, space, "received")));
|
|
@@ -6476,10 +7711,23 @@ var AccountService = class {
|
|
|
6476
7711
|
delegations.sort((a, b) => a.spaceId.localeCompare(b.spaceId) || a.cid.localeCompare(b.cid));
|
|
6477
7712
|
return (0, import_sdk_services5.ok)(delegations);
|
|
6478
7713
|
},
|
|
6479
|
-
revoke: async (
|
|
6480
|
-
const
|
|
7714
|
+
revoke: async (input) => {
|
|
7715
|
+
const cid = typeof input === "string" ? input : input.cid;
|
|
7716
|
+
const manager = this.config.getDelegationManager?.();
|
|
7717
|
+
if (manager) {
|
|
7718
|
+
const revoked2 = await manager.revoke(cid);
|
|
7719
|
+
return revoked2.ok ? (0, import_sdk_services5.ok)(revoked2.data) : accountErr(revoked2.error);
|
|
7720
|
+
}
|
|
7721
|
+
if (typeof input === "string") {
|
|
7722
|
+
return (0, import_sdk_services5.err)((0, import_sdk_services5.serviceError)(
|
|
7723
|
+
"NOT_INITIALIZED",
|
|
7724
|
+
"CID-only revocation requires an authenticated delegation manager",
|
|
7725
|
+
SERVICE_NAME2
|
|
7726
|
+
));
|
|
7727
|
+
}
|
|
7728
|
+
const space = await this.resolveSpace(input.space);
|
|
6481
7729
|
if (!space.ok) return space;
|
|
6482
|
-
const revoked = await this.config.getSpaces().get(space.data.id).delegations.revoke(
|
|
7730
|
+
const revoked = await this.config.getSpaces().get(space.data.id).delegations.revoke(cid);
|
|
6483
7731
|
if (!revoked.ok) return accountErr(revoked.error);
|
|
6484
7732
|
return (0, import_sdk_services5.ok)(void 0);
|
|
6485
7733
|
}
|
|
@@ -6602,18 +7850,18 @@ var AccountService = class {
|
|
|
6602
7850
|
}
|
|
6603
7851
|
},
|
|
6604
7852
|
delegations: {
|
|
6605
|
-
list: async (
|
|
7853
|
+
list: async (options2 = {}) => {
|
|
6606
7854
|
const dbResult = this.accountDb();
|
|
6607
7855
|
if (!dbResult.ok) return dbResult;
|
|
6608
7856
|
const where = [];
|
|
6609
7857
|
const params = [];
|
|
6610
|
-
if (
|
|
7858
|
+
if (options2.direction && options2.direction !== "all") {
|
|
6611
7859
|
where.push("direction = ?");
|
|
6612
|
-
params.push(
|
|
7860
|
+
params.push(options2.direction);
|
|
6613
7861
|
}
|
|
6614
|
-
if (
|
|
7862
|
+
if (options2.space) {
|
|
6615
7863
|
where.push("(space_id = ? OR space_name = ?)");
|
|
6616
|
-
params.push(
|
|
7864
|
+
params.push(options2.space, options2.space);
|
|
6617
7865
|
}
|
|
6618
7866
|
const queried = await dbResult.data.query(
|
|
6619
7867
|
`SELECT cid, direction, space_id, space_name, counterparty_did, delegate_did, delegator_did, path, actions_json, expiry, status, created_at FROM delegations${where.length > 0 ? ` WHERE ${where.join(" AND ")}` : ""} ORDER BY space_id, cid`,
|
|
@@ -6934,10 +8182,10 @@ function applicationFromRecord(key, record) {
|
|
|
6934
8182
|
};
|
|
6935
8183
|
}
|
|
6936
8184
|
function indexedApplicationFromRow(row) {
|
|
6937
|
-
const [appId,
|
|
8185
|
+
const [appId, name2, description, updatedAt, manifestJson, manifestHash] = row;
|
|
6938
8186
|
return {
|
|
6939
8187
|
appId,
|
|
6940
|
-
name:
|
|
8188
|
+
name: name2 ?? void 0,
|
|
6941
8189
|
description: description ?? void 0,
|
|
6942
8190
|
updatedAt: updatedAt ?? void 0,
|
|
6943
8191
|
manifests: JSON.parse(manifestJson),
|
|
@@ -6988,10 +8236,10 @@ function spaceFromRecord(key, record) {
|
|
|
6988
8236
|
};
|
|
6989
8237
|
}
|
|
6990
8238
|
function indexedSpaceFromRow(row) {
|
|
6991
|
-
const [spaceId,
|
|
8239
|
+
const [spaceId, name2, ownerDid, type, permissionsJson, status, registeredAt, updatedAt, expiresAt] = row;
|
|
6992
8240
|
return {
|
|
6993
8241
|
spaceId,
|
|
6994
|
-
name,
|
|
8242
|
+
name: name2,
|
|
6995
8243
|
ownerDid,
|
|
6996
8244
|
type,
|
|
6997
8245
|
permissions: JSON.parse(permissionsJson),
|
|
@@ -7159,9 +8407,9 @@ var DelegationAction = {
|
|
|
7159
8407
|
GET: "tinycloud.delegation/get",
|
|
7160
8408
|
CHECK: "tinycloud.delegation/check"
|
|
7161
8409
|
};
|
|
7162
|
-
function createError(
|
|
8410
|
+
function createError(code2, message, cause, meta) {
|
|
7163
8411
|
return {
|
|
7164
|
-
code,
|
|
8412
|
+
code: code2,
|
|
7165
8413
|
message,
|
|
7166
8414
|
service: "delegation",
|
|
7167
8415
|
cause,
|
|
@@ -7180,6 +8428,7 @@ var DelegationManager = class {
|
|
|
7180
8428
|
this.invoke = config.invoke;
|
|
7181
8429
|
this.invokeAny = config.invokeAny;
|
|
7182
8430
|
this.fetchFn = config.fetch ?? globalThis.fetch.bind(globalThis);
|
|
8431
|
+
this.accountSpaceId = config.accountSpaceId;
|
|
7183
8432
|
}
|
|
7184
8433
|
/**
|
|
7185
8434
|
* Updates the session (e.g., after re-authentication).
|
|
@@ -7385,7 +8634,19 @@ var DelegationManager = class {
|
|
|
7385
8634
|
)
|
|
7386
8635
|
};
|
|
7387
8636
|
}
|
|
7388
|
-
|
|
8637
|
+
const parsed = DelegationRevocationReceiptSchema.safeParse(await response.json());
|
|
8638
|
+
if (!parsed.success || parsed.data.cid !== cid) {
|
|
8639
|
+
return {
|
|
8640
|
+
ok: false,
|
|
8641
|
+
error: createError(
|
|
8642
|
+
DelegationErrorCodes.REVOCATION_FAILED,
|
|
8643
|
+
"Node returned an invalid delegation revocation receipt",
|
|
8644
|
+
void 0,
|
|
8645
|
+
{ cid }
|
|
8646
|
+
)
|
|
8647
|
+
};
|
|
8648
|
+
}
|
|
8649
|
+
return { ok: true, data: parsed.data };
|
|
7389
8650
|
} catch (error) {
|
|
7390
8651
|
if (error instanceof Error && error.name === "AbortError") {
|
|
7391
8652
|
return {
|
|
@@ -7482,6 +8743,86 @@ var DelegationManager = class {
|
|
|
7482
8743
|
};
|
|
7483
8744
|
}
|
|
7484
8745
|
}
|
|
8746
|
+
/** Query lifecycle-complete delegation history for the authenticated account. */
|
|
8747
|
+
async query(options2 = {}) {
|
|
8748
|
+
const validated = AccountDelegationQueryOptionsSchema.safeParse(options2);
|
|
8749
|
+
if (!validated.success) {
|
|
8750
|
+
return {
|
|
8751
|
+
ok: false,
|
|
8752
|
+
error: createError(
|
|
8753
|
+
DelegationErrorCodes.INVALID_INPUT,
|
|
8754
|
+
"Invalid delegation query options",
|
|
8755
|
+
void 0,
|
|
8756
|
+
{ issues: validated.error.issues }
|
|
8757
|
+
)
|
|
8758
|
+
};
|
|
8759
|
+
}
|
|
8760
|
+
if (!this.invokeAny) {
|
|
8761
|
+
return {
|
|
8762
|
+
ok: false,
|
|
8763
|
+
error: createError(
|
|
8764
|
+
DelegationErrorCodes.NOT_INITIALIZED,
|
|
8765
|
+
"Delegation query requires an invokeAny function"
|
|
8766
|
+
)
|
|
8767
|
+
};
|
|
8768
|
+
}
|
|
8769
|
+
if (!this.accountSpaceId) {
|
|
8770
|
+
return {
|
|
8771
|
+
ok: false,
|
|
8772
|
+
error: createError(
|
|
8773
|
+
DelegationErrorCodes.NOT_INITIALIZED,
|
|
8774
|
+
"Delegation query requires an account space"
|
|
8775
|
+
)
|
|
8776
|
+
};
|
|
8777
|
+
}
|
|
8778
|
+
try {
|
|
8779
|
+
const invocationHeaders = this.invokeAny(this.session, [{
|
|
8780
|
+
spaceId: this.accountSpaceId,
|
|
8781
|
+
service: "delegation",
|
|
8782
|
+
path: "",
|
|
8783
|
+
action: DelegationAction.LIST
|
|
8784
|
+
}]);
|
|
8785
|
+
const headers = Object.fromEntries(new Headers(invocationHeaders).entries());
|
|
8786
|
+
headers["content-type"] = "application/json";
|
|
8787
|
+
const response = await this.fetchFn(`${this.host}/delegation/query`, {
|
|
8788
|
+
method: "POST",
|
|
8789
|
+
headers,
|
|
8790
|
+
body: JSON.stringify(validated.data)
|
|
8791
|
+
});
|
|
8792
|
+
if (!response.ok) {
|
|
8793
|
+
const errorText = await response.text();
|
|
8794
|
+
return {
|
|
8795
|
+
ok: false,
|
|
8796
|
+
error: createError(
|
|
8797
|
+
DelegationErrorCodes.NETWORK_ERROR,
|
|
8798
|
+
`Failed to query delegations: ${response.status} - ${errorText}`,
|
|
8799
|
+
void 0,
|
|
8800
|
+
{ status: response.status }
|
|
8801
|
+
)
|
|
8802
|
+
};
|
|
8803
|
+
}
|
|
8804
|
+
const parsed = AccountDelegationPageSchema.safeParse(await response.json());
|
|
8805
|
+
if (!parsed.success) {
|
|
8806
|
+
return {
|
|
8807
|
+
ok: false,
|
|
8808
|
+
error: createError(
|
|
8809
|
+
DelegationErrorCodes.INVALID_TOKEN,
|
|
8810
|
+
"Node returned an invalid delegation query response"
|
|
8811
|
+
)
|
|
8812
|
+
};
|
|
8813
|
+
}
|
|
8814
|
+
return { ok: true, data: parsed.data };
|
|
8815
|
+
} catch (error) {
|
|
8816
|
+
return {
|
|
8817
|
+
ok: false,
|
|
8818
|
+
error: createError(
|
|
8819
|
+
DelegationErrorCodes.NETWORK_ERROR,
|
|
8820
|
+
`Network error during delegation query: ${String(error)}`,
|
|
8821
|
+
error instanceof Error ? error : void 0
|
|
8822
|
+
)
|
|
8823
|
+
};
|
|
8824
|
+
}
|
|
8825
|
+
}
|
|
7485
8826
|
/**
|
|
7486
8827
|
* Lists all delegations for the current session's space.
|
|
7487
8828
|
*
|
|
@@ -7877,6 +9218,17 @@ var SessionExpiredError = class extends Error {
|
|
|
7877
9218
|
this.expiredAt = expiredAt;
|
|
7878
9219
|
}
|
|
7879
9220
|
};
|
|
9221
|
+
var CaveatedDelegationUnsupportedError = class extends Error {
|
|
9222
|
+
constructor(entries) {
|
|
9223
|
+
super(
|
|
9224
|
+
"Cannot create a caveated delegation because this WASM delegation boundary cannot preserve every ReCap caveat branch exactly."
|
|
9225
|
+
);
|
|
9226
|
+
/** Stable machine-readable error code for fail-closed caveated delegation. */
|
|
9227
|
+
this.code = "CAVEATED_DELEGATION_UNSUPPORTED";
|
|
9228
|
+
this.name = "CaveatedDelegationUnsupportedError";
|
|
9229
|
+
this.entries = entries.map(cloneEntry);
|
|
9230
|
+
}
|
|
9231
|
+
};
|
|
7880
9232
|
function normalizeSpace(space) {
|
|
7881
9233
|
if (!space.startsWith("tinycloud:")) {
|
|
7882
9234
|
return space;
|
|
@@ -7917,8 +9269,42 @@ function canonicalizeEntryMatches(requested, granted) {
|
|
|
7917
9269
|
return false;
|
|
7918
9270
|
}
|
|
7919
9271
|
}
|
|
9272
|
+
if (!recapCaveatsEqual(requested.caveats, granted.caveats)) {
|
|
9273
|
+
return false;
|
|
9274
|
+
}
|
|
7920
9275
|
return true;
|
|
7921
9276
|
}
|
|
9277
|
+
function recapCaveatsEqual(left, right) {
|
|
9278
|
+
return canonicalizeRecapCaveats(left) === canonicalizeRecapCaveats(right);
|
|
9279
|
+
}
|
|
9280
|
+
function canonicalizeRecapCaveats(caveats) {
|
|
9281
|
+
const canonicalize = (value) => {
|
|
9282
|
+
if (value === null || typeof value === "boolean" || typeof value === "string") {
|
|
9283
|
+
return JSON.stringify(value);
|
|
9284
|
+
}
|
|
9285
|
+
if (typeof value === "number") {
|
|
9286
|
+
if (Number.isFinite(value)) return JSON.stringify(value);
|
|
9287
|
+
throw new Error("ReCap caveats must contain only JSON values.");
|
|
9288
|
+
}
|
|
9289
|
+
if (Array.isArray(value)) return `[${value.map(canonicalize).join(",")}]`;
|
|
9290
|
+
if (typeof value === "object") {
|
|
9291
|
+
const object = value;
|
|
9292
|
+
const prototype = Object.getPrototypeOf(object);
|
|
9293
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
9294
|
+
throw new Error("ReCap caveats must contain only JSON values.");
|
|
9295
|
+
}
|
|
9296
|
+
return `{${Object.keys(object).sort().map(
|
|
9297
|
+
(key) => `${JSON.stringify(key)}:${canonicalize(object[key])}`
|
|
9298
|
+
).join(",")}}`;
|
|
9299
|
+
}
|
|
9300
|
+
throw new Error("ReCap caveats must contain only JSON values.");
|
|
9301
|
+
};
|
|
9302
|
+
const branches = (caveats ?? []).map(canonicalize).sort();
|
|
9303
|
+
if (branches.length === 0 || branches.length === 1 && branches[0] === "{}") {
|
|
9304
|
+
return "[]";
|
|
9305
|
+
}
|
|
9306
|
+
return `[${branches.join(",")}]`;
|
|
9307
|
+
}
|
|
7922
9308
|
function actionContains(grantedAction, requestedAction) {
|
|
7923
9309
|
if (grantedAction === "*" || grantedAction === requestedAction) return true;
|
|
7924
9310
|
if (!grantedAction.endsWith("/*")) return false;
|
|
@@ -7940,6 +9326,7 @@ function cloneEntry(entry) {
|
|
|
7940
9326
|
...entry.space !== void 0 ? { space: entry.space } : {},
|
|
7941
9327
|
path: entry.path,
|
|
7942
9328
|
actions: [...entry.actions],
|
|
9329
|
+
...entry.caveats !== void 0 ? { caveats: JSON.parse(JSON.stringify(entry.caveats)) } : {},
|
|
7943
9330
|
...entry.skipPrefix !== void 0 ? { skipPrefix: entry.skipPrefix } : {},
|
|
7944
9331
|
...entry.expiry !== void 0 ? { expiry: entry.expiry } : {}
|
|
7945
9332
|
};
|
|
@@ -7963,7 +9350,8 @@ function parseRecapCapabilities(parseWasm, siwe) {
|
|
|
7963
9350
|
// returned entries match the shape manifests use.
|
|
7964
9351
|
space: normalizeSpace(entry.space),
|
|
7965
9352
|
path: entry.path,
|
|
7966
|
-
actions: [...entry.actions]
|
|
9353
|
+
actions: [...entry.actions],
|
|
9354
|
+
...entry.caveats === void 0 ? {} : { caveats: JSON.parse(JSON.stringify(entry.caveats)) }
|
|
7967
9355
|
};
|
|
7968
9356
|
});
|
|
7969
9357
|
normalized.sort((a, b) => {
|
|
@@ -7978,7 +9366,6 @@ function parseRecapCapabilities(parseWasm, siwe) {
|
|
|
7978
9366
|
}
|
|
7979
9367
|
|
|
7980
9368
|
// src/delegations/SharingService.ts
|
|
7981
|
-
var import_basics2 = require("multiformats/basics");
|
|
7982
9369
|
var import_ed255192 = require("@noble/curves/ed25519");
|
|
7983
9370
|
function inferShortServiceFromActionUrns(actions) {
|
|
7984
9371
|
let short;
|
|
@@ -7999,9 +9386,9 @@ function inferShortServiceFromActionUrns(actions) {
|
|
|
7999
9386
|
var DEFAULT_READ_ACTIONS = ["tinycloud.kv/get", "tinycloud.kv/metadata"];
|
|
8000
9387
|
var DEFAULT_EXPIRY_MS = EXPIRY.SHARE_MS;
|
|
8001
9388
|
var BASE64_PREFIX = "tc1:";
|
|
8002
|
-
function createError2(
|
|
9389
|
+
function createError2(code2, message, cause, meta) {
|
|
8003
9390
|
return {
|
|
8004
|
-
code,
|
|
9391
|
+
code: code2,
|
|
8005
9392
|
message,
|
|
8006
9393
|
service: "delegation",
|
|
8007
9394
|
cause,
|
|
@@ -8009,25 +9396,25 @@ function createError2(code, message, cause, meta) {
|
|
|
8009
9396
|
};
|
|
8010
9397
|
}
|
|
8011
9398
|
function base64UrlEncode2(data) {
|
|
8012
|
-
let
|
|
9399
|
+
let base642;
|
|
8013
9400
|
if (typeof btoa !== "undefined") {
|
|
8014
|
-
|
|
9401
|
+
base642 = btoa(unescape(encodeURIComponent(data)));
|
|
8015
9402
|
} else if (typeof Buffer !== "undefined") {
|
|
8016
|
-
|
|
9403
|
+
base642 = Buffer.from(data, "utf-8").toString("base64");
|
|
8017
9404
|
} else {
|
|
8018
9405
|
throw new Error("No base64 encoding available");
|
|
8019
9406
|
}
|
|
8020
|
-
return
|
|
9407
|
+
return base642.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
8021
9408
|
}
|
|
8022
9409
|
function base64UrlDecode2(encoded) {
|
|
8023
|
-
let
|
|
8024
|
-
while (
|
|
8025
|
-
|
|
9410
|
+
let base642 = encoded.replace(/-/g, "+").replace(/_/g, "/");
|
|
9411
|
+
while (base642.length % 4) {
|
|
9412
|
+
base642 += "=";
|
|
8026
9413
|
}
|
|
8027
9414
|
if (typeof atob !== "undefined") {
|
|
8028
|
-
return decodeURIComponent(escape(atob(
|
|
9415
|
+
return decodeURIComponent(escape(atob(base642)));
|
|
8029
9416
|
} else if (typeof Buffer !== "undefined") {
|
|
8030
|
-
return Buffer.from(
|
|
9417
|
+
return Buffer.from(base642, "base64").toString("utf-8");
|
|
8031
9418
|
} else {
|
|
8032
9419
|
throw new Error("No base64 decoding available");
|
|
8033
9420
|
}
|
|
@@ -8052,6 +9439,7 @@ var SharingService = class {
|
|
|
8052
9439
|
this.pathPrefix = config.pathPrefix ?? "";
|
|
8053
9440
|
this.sessionExpiry = config.sessionExpiry;
|
|
8054
9441
|
this.onRootDelegationNeeded = config.onRootDelegationNeeded;
|
|
9442
|
+
this.assertActiveFn = config.assertActive;
|
|
8055
9443
|
}
|
|
8056
9444
|
/**
|
|
8057
9445
|
* Gets the primary host URL.
|
|
@@ -8063,6 +9451,7 @@ var SharingService = class {
|
|
|
8063
9451
|
* Updates the session (e.g., after re-authentication).
|
|
8064
9452
|
*/
|
|
8065
9453
|
updateSession(session) {
|
|
9454
|
+
this.assertActiveFn?.();
|
|
8066
9455
|
this.session = session;
|
|
8067
9456
|
}
|
|
8068
9457
|
/**
|
|
@@ -8070,6 +9459,7 @@ var SharingService = class {
|
|
|
8070
9459
|
* Used to add full capabilities (session, delegationManager, createDelegation, createDelegationWasm) after signIn.
|
|
8071
9460
|
*/
|
|
8072
9461
|
updateConfig(config) {
|
|
9462
|
+
this.assertActiveFn?.();
|
|
8073
9463
|
if (config.session !== void 0) {
|
|
8074
9464
|
this.session = config.session;
|
|
8075
9465
|
}
|
|
@@ -8088,6 +9478,9 @@ var SharingService = class {
|
|
|
8088
9478
|
if (config.onRootDelegationNeeded !== void 0) {
|
|
8089
9479
|
this.onRootDelegationNeeded = config.onRootDelegationNeeded;
|
|
8090
9480
|
}
|
|
9481
|
+
if (config.assertActive !== void 0) {
|
|
9482
|
+
this.assertActiveFn = config.assertActive;
|
|
9483
|
+
}
|
|
8091
9484
|
}
|
|
8092
9485
|
/**
|
|
8093
9486
|
* Generate a sharing link with an embedded private key.
|
|
@@ -8100,6 +9493,8 @@ var SharingService = class {
|
|
|
8100
9493
|
* 5. Return link string
|
|
8101
9494
|
*/
|
|
8102
9495
|
async generate(params) {
|
|
9496
|
+
const activeError = this.retiredGraphError();
|
|
9497
|
+
if (activeError) return { ok: false, error: activeError };
|
|
8103
9498
|
if (!this.session) {
|
|
8104
9499
|
return {
|
|
8105
9500
|
ok: false,
|
|
@@ -8147,7 +9542,11 @@ var SharingService = class {
|
|
|
8147
9542
|
try {
|
|
8148
9543
|
const shareKeyName = `share:${Date.now()}:${Math.random().toString(36).substring(2, 10)}`;
|
|
8149
9544
|
keyId = await this.keyProvider.createSessionKey(shareKeyName);
|
|
9545
|
+
const keyCreationActiveError = this.retiredGraphError();
|
|
9546
|
+
if (keyCreationActiveError) return { ok: false, error: keyCreationActiveError };
|
|
8150
9547
|
keyDid = await this.keyProvider.getDID(keyId);
|
|
9548
|
+
const keyDidActiveError = this.retiredGraphError();
|
|
9549
|
+
if (keyDidActiveError) return { ok: false, error: keyDidActiveError };
|
|
8151
9550
|
keyJwk = this.keyProvider.getJWK(keyId);
|
|
8152
9551
|
if (!keyJwk.d) {
|
|
8153
9552
|
return {
|
|
@@ -8183,6 +9582,8 @@ var SharingService = class {
|
|
|
8183
9582
|
);
|
|
8184
9583
|
if (canSatisfyFromRegistry) {
|
|
8185
9584
|
const delegationResult = await this.createSessionDelegation(plainDID, fullPath, actions, expiry);
|
|
9585
|
+
const childDelegationActiveError = this.retiredGraphError();
|
|
9586
|
+
if (childDelegationActiveError) return { ok: false, error: childDelegationActiveError };
|
|
8186
9587
|
const parsed = handleDelegationResult(delegationResult);
|
|
8187
9588
|
if ("ok" in parsed && parsed.ok === false) {
|
|
8188
9589
|
return parsed;
|
|
@@ -8197,39 +9598,41 @@ var SharingService = class {
|
|
|
8197
9598
|
actions,
|
|
8198
9599
|
requestedExpiry
|
|
8199
9600
|
});
|
|
9601
|
+
const rootDelegationActiveError = this.retiredGraphError();
|
|
9602
|
+
if (rootDelegationActiveError) return { ok: false, error: rootDelegationActiveError };
|
|
8200
9603
|
if (rootDelegation) {
|
|
8201
9604
|
delegation = rootDelegation;
|
|
8202
9605
|
expiry = requestedExpiry;
|
|
8203
9606
|
} else {
|
|
8204
|
-
|
|
8205
|
-
|
|
8206
|
-
|
|
8207
|
-
|
|
8208
|
-
|
|
8209
|
-
|
|
8210
|
-
}
|
|
8211
|
-
delegation = parsed;
|
|
9607
|
+
return {
|
|
9608
|
+
ok: false,
|
|
9609
|
+
error: createError2(
|
|
9610
|
+
DelegationErrorCodes.PERMISSION_DENIED,
|
|
9611
|
+
"The active session ReCap does not authorize this sharing delegation."
|
|
9612
|
+
)
|
|
9613
|
+
};
|
|
8212
9614
|
}
|
|
8213
9615
|
} catch (err6) {
|
|
8214
|
-
|
|
8215
|
-
|
|
8216
|
-
|
|
8217
|
-
|
|
8218
|
-
|
|
8219
|
-
|
|
8220
|
-
|
|
8221
|
-
|
|
9616
|
+
return {
|
|
9617
|
+
ok: false,
|
|
9618
|
+
error: createError2(
|
|
9619
|
+
DelegationErrorCodes.PERMISSION_DENIED,
|
|
9620
|
+
"The active session ReCap does not authorize this sharing delegation.",
|
|
9621
|
+
err6 instanceof Error ? err6 : void 0
|
|
9622
|
+
)
|
|
9623
|
+
};
|
|
8222
9624
|
}
|
|
8223
9625
|
} else {
|
|
8224
|
-
|
|
8225
|
-
|
|
8226
|
-
|
|
8227
|
-
|
|
8228
|
-
|
|
8229
|
-
|
|
8230
|
-
}
|
|
8231
|
-
delegation = parsed;
|
|
9626
|
+
return {
|
|
9627
|
+
ok: false,
|
|
9628
|
+
error: createError2(
|
|
9629
|
+
DelegationErrorCodes.PERMISSION_DENIED,
|
|
9630
|
+
"The active session ReCap does not authorize this sharing delegation."
|
|
9631
|
+
)
|
|
9632
|
+
};
|
|
8232
9633
|
}
|
|
9634
|
+
const finalActiveError = this.retiredGraphError();
|
|
9635
|
+
if (finalActiveError) return { ok: false, error: finalActiveError };
|
|
8233
9636
|
const shareData = {
|
|
8234
9637
|
key: keyJwk,
|
|
8235
9638
|
keyDid,
|
|
@@ -8262,13 +9665,16 @@ var SharingService = class {
|
|
|
8262
9665
|
* @internal
|
|
8263
9666
|
*/
|
|
8264
9667
|
findSuitableKeyForDelegation(path, actions, requestedExpiry) {
|
|
8265
|
-
if (this.sessionExpiry && requestedExpiry <= this.sessionExpiry) {
|
|
8266
|
-
return true;
|
|
8267
|
-
}
|
|
8268
9668
|
const allKeys = this.registry.getAllKeys();
|
|
8269
9669
|
for (const key of allKeys) {
|
|
8270
9670
|
const delegations = this.registry.getDelegationsForKey(key.id);
|
|
8271
9671
|
for (const delegation of delegations) {
|
|
9672
|
+
if (delegation.spaceId !== this.session?.spaceId) {
|
|
9673
|
+
continue;
|
|
9674
|
+
}
|
|
9675
|
+
if ((delegation.caveats?.length ?? 0) > 0) {
|
|
9676
|
+
continue;
|
|
9677
|
+
}
|
|
8272
9678
|
if (!this.registry.isDelegationValid(delegation)) {
|
|
8273
9679
|
continue;
|
|
8274
9680
|
}
|
|
@@ -8294,6 +9700,18 @@ var SharingService = class {
|
|
|
8294
9700
|
}
|
|
8295
9701
|
return false;
|
|
8296
9702
|
}
|
|
9703
|
+
retiredGraphError() {
|
|
9704
|
+
try {
|
|
9705
|
+
this.assertActiveFn?.();
|
|
9706
|
+
return void 0;
|
|
9707
|
+
} catch (err6) {
|
|
9708
|
+
return createError2(
|
|
9709
|
+
DelegationErrorCodes.NOT_INITIALIZED,
|
|
9710
|
+
"The session service graph has been retired.",
|
|
9711
|
+
err6 instanceof Error ? err6 : void 0
|
|
9712
|
+
);
|
|
9713
|
+
}
|
|
9714
|
+
}
|
|
8297
9715
|
/**
|
|
8298
9716
|
* Check if a delegation path matches/covers the requested path.
|
|
8299
9717
|
* A delegation path covers the request if:
|
|
@@ -8316,19 +9734,14 @@ var SharingService = class {
|
|
|
8316
9734
|
}
|
|
8317
9735
|
return false;
|
|
8318
9736
|
}
|
|
8319
|
-
/**
|
|
8320
|
-
* Handle fallback to session extension when root delegation is not available.
|
|
8321
|
-
* @internal
|
|
8322
|
-
*/
|
|
8323
|
-
async handleSessionExtensionFallback(requestedExpiry) {
|
|
8324
|
-
return { expiry: this.sessionExpiry ?? requestedExpiry };
|
|
8325
|
-
}
|
|
8326
9737
|
/**
|
|
8327
9738
|
* Create a delegation from the current session to a share key.
|
|
8328
9739
|
* This is the fallback path when root delegation is not available.
|
|
8329
9740
|
* @internal
|
|
8330
9741
|
*/
|
|
8331
9742
|
async createSessionDelegation(delegateDID, path, actions, expiry) {
|
|
9743
|
+
const activeError = this.retiredGraphError();
|
|
9744
|
+
if (activeError) return { ok: false, error: activeError };
|
|
8332
9745
|
if (!this.session) {
|
|
8333
9746
|
return {
|
|
8334
9747
|
ok: false,
|
|
@@ -8370,14 +9783,20 @@ var SharingService = class {
|
|
|
8370
9783
|
},
|
|
8371
9784
|
expirationSecs: Math.floor(expiry.getTime() / 1e3)
|
|
8372
9785
|
});
|
|
9786
|
+
const childSigningActiveError = this.retiredGraphError();
|
|
9787
|
+
if (childSigningActiveError) return { ok: false, error: childSigningActiveError };
|
|
8373
9788
|
const registerRes = await this.fetchFn(`${this.host}/delegate`, {
|
|
8374
9789
|
method: "POST",
|
|
8375
9790
|
headers: {
|
|
8376
9791
|
Authorization: wasmResult.delegation
|
|
8377
9792
|
}
|
|
8378
9793
|
});
|
|
9794
|
+
const registrationActiveError = this.retiredGraphError();
|
|
9795
|
+
if (registrationActiveError) return { ok: false, error: registrationActiveError };
|
|
8379
9796
|
if (!registerRes.ok) {
|
|
8380
9797
|
const errorText = await registerRes.text();
|
|
9798
|
+
const registrationTextActiveError = this.retiredGraphError();
|
|
9799
|
+
if (registrationTextActiveError) return { ok: false, error: registrationTextActiveError };
|
|
8381
9800
|
return {
|
|
8382
9801
|
ok: false,
|
|
8383
9802
|
error: createError2(
|
|
@@ -8427,6 +9846,8 @@ var SharingService = class {
|
|
|
8427
9846
|
disableSubDelegation: false
|
|
8428
9847
|
};
|
|
8429
9848
|
const delegationResult = this.createDelegationFn ? await this.createDelegationFn(delegationParams) : await this.delegationManager.create(delegationParams);
|
|
9849
|
+
const delegationCreationActiveError = this.retiredGraphError();
|
|
9850
|
+
if (delegationCreationActiveError) return { ok: false, error: delegationCreationActiveError };
|
|
8430
9851
|
if (!delegationResult.ok) {
|
|
8431
9852
|
return {
|
|
8432
9853
|
ok: false,
|
|
@@ -8452,12 +9873,14 @@ var SharingService = class {
|
|
|
8452
9873
|
* - Register sub-delegation capabilities
|
|
8453
9874
|
* 4. Return ShareAccess with pre-configured KV service
|
|
8454
9875
|
*/
|
|
8455
|
-
async receive(link,
|
|
9876
|
+
async receive(link, options2 = {}) {
|
|
9877
|
+
const activeError = this.retiredGraphError();
|
|
9878
|
+
if (activeError) return { ok: false, error: activeError };
|
|
8456
9879
|
const {
|
|
8457
9880
|
autoSubdelegate = true,
|
|
8458
9881
|
useSessionKey = true,
|
|
8459
9882
|
ingestOptions
|
|
8460
|
-
} =
|
|
9883
|
+
} = options2;
|
|
8461
9884
|
const decodeResult = this.decodeLinkWithValidation(link);
|
|
8462
9885
|
if (!decodeResult.ok) {
|
|
8463
9886
|
return decodeResult;
|
|
@@ -8543,9 +9966,12 @@ var SharingService = class {
|
|
|
8543
9966
|
* be logged or stored insecurely.
|
|
8544
9967
|
*/
|
|
8545
9968
|
async delegateReceivedShare(link, params) {
|
|
9969
|
+
const activeError = this.retiredGraphError();
|
|
9970
|
+
if (activeError) return { ok: false, error: activeError };
|
|
8546
9971
|
const decoded = this.decodeLinkWithValidation(link);
|
|
8547
9972
|
if (!decoded.ok) return decoded;
|
|
8548
9973
|
const shareData = decoded.data;
|
|
9974
|
+
this.assertDelegationCaveatsPreservable(shareData.delegation);
|
|
8549
9975
|
const parentExpiry = new Date(shareData.delegation.expiry);
|
|
8550
9976
|
const now = /* @__PURE__ */ new Date();
|
|
8551
9977
|
if (parentExpiry <= now) {
|
|
@@ -8679,6 +10105,8 @@ var SharingService = class {
|
|
|
8679
10105
|
abilities: { [service]: { [path]: actions } },
|
|
8680
10106
|
expirationSecs: Math.floor(expiry.getTime() / 1e3)
|
|
8681
10107
|
});
|
|
10108
|
+
const childSigningActiveError = this.retiredGraphError();
|
|
10109
|
+
if (childSigningActiveError) return { ok: false, error: childSigningActiveError };
|
|
8682
10110
|
const verifiedChild = verifySignedChild(result, {
|
|
8683
10111
|
delegateDID,
|
|
8684
10112
|
issuerDID: principalDid(shareData.keyDid),
|
|
@@ -8705,6 +10133,8 @@ var SharingService = class {
|
|
|
8705
10133
|
redirect: "error"
|
|
8706
10134
|
};
|
|
8707
10135
|
const registration = await this.fetchFn(new URL("/delegate", trustedHost).toString(), registrationInit);
|
|
10136
|
+
const registrationActiveError = this.retiredGraphError();
|
|
10137
|
+
if (registrationActiveError) return { ok: false, error: registrationActiveError };
|
|
8708
10138
|
if (!registration.ok) {
|
|
8709
10139
|
throw new Error(`node rejected child delegation (${registration.status})`);
|
|
8710
10140
|
}
|
|
@@ -8750,6 +10180,22 @@ var SharingService = class {
|
|
|
8750
10180
|
};
|
|
8751
10181
|
}
|
|
8752
10182
|
}
|
|
10183
|
+
/**
|
|
10184
|
+
* The child-delegation WASM boundary accepts action-only abilities. Reject
|
|
10185
|
+
* every constrained parent branch before that boundary can broaden it.
|
|
10186
|
+
*/
|
|
10187
|
+
assertDelegationCaveatsPreservable(delegation) {
|
|
10188
|
+
if (recapCaveatsEqual(delegation.caveats, void 0)) return;
|
|
10189
|
+
const service = delegation.actions[0]?.split("/", 1)[0] ?? "tinycloud.unknown";
|
|
10190
|
+
const entry = {
|
|
10191
|
+
service,
|
|
10192
|
+
space: delegation.spaceId,
|
|
10193
|
+
path: delegation.path,
|
|
10194
|
+
actions: [...delegation.actions],
|
|
10195
|
+
caveats: delegation.caveats ?? []
|
|
10196
|
+
};
|
|
10197
|
+
throw new CaveatedDelegationUnsupportedError([entry]);
|
|
10198
|
+
}
|
|
8753
10199
|
/**
|
|
8754
10200
|
* Encode sharing data into a link string.
|
|
8755
10201
|
*
|
|
@@ -8918,7 +10364,7 @@ function capabilityPathContains(parent, child) {
|
|
|
8918
10364
|
function shareKeyMatchesDid(key, didUrl) {
|
|
8919
10365
|
if (key.kty !== "OKP" || key.crv !== "Ed25519" || typeof key.x !== "string" || typeof key.d !== "string") return false;
|
|
8920
10366
|
try {
|
|
8921
|
-
const didBytes =
|
|
10367
|
+
const didBytes = bases.base58btc.decode(principalDid(didUrl).slice("did:key:".length));
|
|
8922
10368
|
const publicKey = didBytes.length === 34 && didBytes[0] === 237 && didBytes[1] === 1 ? didBytes.slice(2) : null;
|
|
8923
10369
|
if (!publicKey) return false;
|
|
8924
10370
|
const jwkBytes = decodeBase64UrlBytes(key.x);
|
|
@@ -9030,7 +10476,14 @@ var CapabilityKeyRegistry = class {
|
|
|
9030
10476
|
removeKey(keyId) {
|
|
9031
10477
|
const delegations = this.store.byKey.get(keyId) || [];
|
|
9032
10478
|
for (const delegation of delegations) {
|
|
9033
|
-
this.store.byCid.
|
|
10479
|
+
const chains = this.store.byCid.get(delegation.cid);
|
|
10480
|
+
if (!chains) continue;
|
|
10481
|
+
const remaining = chains.filter((chain) => chain.keyId !== keyId);
|
|
10482
|
+
if (remaining.length === 0) {
|
|
10483
|
+
this.store.byCid.delete(delegation.cid);
|
|
10484
|
+
} else {
|
|
10485
|
+
this.store.byCid.set(delegation.cid, remaining);
|
|
10486
|
+
}
|
|
9034
10487
|
}
|
|
9035
10488
|
for (const [capKey, entries] of this.store.byCapability) {
|
|
9036
10489
|
const filtered = entries.filter(
|
|
@@ -9120,8 +10573,8 @@ var CapabilityKeyRegistry = class {
|
|
|
9120
10573
|
* @param delegation - Delegation to associate with the key
|
|
9121
10574
|
* @param options - Ingestion options
|
|
9122
10575
|
*/
|
|
9123
|
-
ingestKey(key, delegation,
|
|
9124
|
-
const keyToStore =
|
|
10576
|
+
ingestKey(key, delegation, options2) {
|
|
10577
|
+
const keyToStore = options2?.priority !== void 0 ? { ...key, priority: options2.priority } : key;
|
|
9125
10578
|
this.keys.set(keyToStore.id, keyToStore);
|
|
9126
10579
|
if (!this.store.byKey.has(keyToStore.id)) {
|
|
9127
10580
|
this.store.byKey.set(keyToStore.id, []);
|
|
@@ -9190,7 +10643,7 @@ var CapabilityKeyRegistry = class {
|
|
|
9190
10643
|
*/
|
|
9191
10644
|
revokeDelegation(cid) {
|
|
9192
10645
|
const stored = this.store.byCid.get(cid);
|
|
9193
|
-
if (!stored) {
|
|
10646
|
+
if (!stored || stored.length === 0) {
|
|
9194
10647
|
return (0, import_sdk_services6.err)(
|
|
9195
10648
|
(0, import_sdk_services6.serviceError)(
|
|
9196
10649
|
CapabilityKeyRegistryErrorCodes.KEY_NOT_FOUND,
|
|
@@ -9199,12 +10652,10 @@ var CapabilityKeyRegistry = class {
|
|
|
9199
10652
|
)
|
|
9200
10653
|
);
|
|
9201
10654
|
}
|
|
9202
|
-
stored.delegation.isRevoked = true;
|
|
9203
|
-
const keyDelegations
|
|
9204
|
-
|
|
9205
|
-
|
|
9206
|
-
if (delegation) {
|
|
9207
|
-
delegation.isRevoked = true;
|
|
10655
|
+
for (const chain of stored) chain.delegation.isRevoked = true;
|
|
10656
|
+
for (const keyDelegations of this.store.byKey.values()) {
|
|
10657
|
+
for (const delegation of keyDelegations) {
|
|
10658
|
+
if (delegation.cid === cid) delegation.isRevoked = true;
|
|
9208
10659
|
}
|
|
9209
10660
|
}
|
|
9210
10661
|
for (const entries of this.store.byCapability.values()) {
|
|
@@ -9251,22 +10702,28 @@ var CapabilityKeyRegistry = class {
|
|
|
9251
10702
|
*/
|
|
9252
10703
|
addDelegation(key, delegation) {
|
|
9253
10704
|
const keyDelegations = this.store.byKey.get(key.id) || [];
|
|
9254
|
-
if (!keyDelegations.some((d) => d
|
|
10705
|
+
if (!keyDelegations.some((d) => this.sameDelegationScope(d, delegation))) {
|
|
9255
10706
|
keyDelegations.push(delegation);
|
|
9256
10707
|
this.store.byKey.set(key.id, keyDelegations);
|
|
9257
10708
|
}
|
|
9258
|
-
|
|
9259
|
-
|
|
10709
|
+
const chains = this.store.byCid.get(delegation.cid) ?? [];
|
|
10710
|
+
if (!chains.some(
|
|
10711
|
+
(chain) => chain.keyId === key.id && this.sameDelegationScope(chain.delegation, delegation)
|
|
10712
|
+
)) {
|
|
10713
|
+
chains.push({
|
|
9260
10714
|
delegation,
|
|
9261
10715
|
parentCid: delegation.parentCid,
|
|
9262
10716
|
keyId: key.id,
|
|
9263
10717
|
storedAt: /* @__PURE__ */ new Date()
|
|
9264
10718
|
});
|
|
10719
|
+
this.store.byCid.set(delegation.cid, chains);
|
|
9265
10720
|
}
|
|
9266
10721
|
for (const action of delegation.actions) {
|
|
9267
10722
|
const capKey = this.makeCapabilityKey(delegation.path, action);
|
|
9268
10723
|
const entries = this.store.byCapability.get(capKey) || [];
|
|
9269
|
-
const existingEntry = entries.find(
|
|
10724
|
+
const existingEntry = entries.find(
|
|
10725
|
+
(e) => this.sameDelegationScope(e.delegation, delegation)
|
|
10726
|
+
);
|
|
9270
10727
|
if (existingEntry) {
|
|
9271
10728
|
if (!existingEntry.keys.some((k) => k.id === key.id)) {
|
|
9272
10729
|
existingEntry.keys.push(key);
|
|
@@ -9295,6 +10752,9 @@ var CapabilityKeyRegistry = class {
|
|
|
9295
10752
|
makeCapabilityKey(resource, action) {
|
|
9296
10753
|
return `${resource}|${action}`;
|
|
9297
10754
|
}
|
|
10755
|
+
sameDelegationScope(left, right) {
|
|
10756
|
+
return left.cid === right.cid && left.spaceId === right.spaceId && left.path === right.path && left.actions.length === right.actions.length && left.actions.every((action) => right.actions.includes(action)) && recapCaveatsEqual(left.caveats, right.caveats);
|
|
10757
|
+
}
|
|
9298
10758
|
/**
|
|
9299
10759
|
* Find capability entries that match a resource and action.
|
|
9300
10760
|
*
|
|
@@ -9316,7 +10776,9 @@ var CapabilityKeyRegistry = class {
|
|
|
9316
10776
|
continue;
|
|
9317
10777
|
}
|
|
9318
10778
|
if (this.resourceMatchesPattern(resource, entry.resource)) {
|
|
9319
|
-
if (!results.some(
|
|
10779
|
+
if (!results.some(
|
|
10780
|
+
(r) => this.sameDelegationScope(r.delegation, entry.delegation)
|
|
10781
|
+
)) {
|
|
9320
10782
|
results.push(entry);
|
|
9321
10783
|
}
|
|
9322
10784
|
}
|
|
@@ -9397,24 +10859,24 @@ function openKeyApprovalReason(body) {
|
|
|
9397
10859
|
}
|
|
9398
10860
|
return "OpenKey explicit approval required";
|
|
9399
10861
|
}
|
|
9400
|
-
function createOpenKeyCallbackSigningStrategy(
|
|
10862
|
+
function createOpenKeyCallbackSigningStrategy(options2) {
|
|
9401
10863
|
return {
|
|
9402
10864
|
type: "callback",
|
|
9403
10865
|
openKeyAutoSign: true,
|
|
9404
10866
|
handler: async (request) => {
|
|
9405
|
-
const fetchImpl =
|
|
10867
|
+
const fetchImpl = options2.fetch ?? globalThis.fetch;
|
|
9406
10868
|
if (!fetchImpl) {
|
|
9407
10869
|
throw new Error("OpenKey signing strategy requires a fetch implementation");
|
|
9408
10870
|
}
|
|
9409
|
-
const token = await resolveOpenKeyToken(
|
|
9410
|
-
const extraHeaders = await resolveOpenKeyHeaders(
|
|
10871
|
+
const token = await resolveOpenKeyToken(options2.token);
|
|
10872
|
+
const extraHeaders = await resolveOpenKeyHeaders(options2.headers);
|
|
9411
10873
|
const body = {
|
|
9412
10874
|
...request,
|
|
9413
|
-
...
|
|
10875
|
+
...options2.keyId ? { keyId: options2.keyId } : {}
|
|
9414
10876
|
};
|
|
9415
|
-
const response = await fetchImpl(
|
|
10877
|
+
const response = await fetchImpl(options2.endpoint, {
|
|
9416
10878
|
method: "POST",
|
|
9417
|
-
credentials:
|
|
10879
|
+
credentials: options2.credentials,
|
|
9418
10880
|
headers: {
|
|
9419
10881
|
"content-type": "application/json",
|
|
9420
10882
|
...token ? { authorization: `Bearer ${token}` } : {},
|
|
@@ -9531,12 +10993,1459 @@ async function checkNodeInfo(host, sdkProtocol, fetchFn = globalThis.fetch.bind(
|
|
|
9531
10993
|
// src/index.ts
|
|
9532
10994
|
var import_bootstrap3 = require("@tinycloud/bootstrap");
|
|
9533
10995
|
|
|
10996
|
+
// ../../node_modules/uint8arrays/dist/src/equals.js
|
|
10997
|
+
function equals3(a, b) {
|
|
10998
|
+
if (a === b) {
|
|
10999
|
+
return true;
|
|
11000
|
+
}
|
|
11001
|
+
if (a.byteLength !== b.byteLength) {
|
|
11002
|
+
return false;
|
|
11003
|
+
}
|
|
11004
|
+
for (let i = 0; i < a.byteLength; i++) {
|
|
11005
|
+
if (a[i] !== b[i]) {
|
|
11006
|
+
return false;
|
|
11007
|
+
}
|
|
11008
|
+
}
|
|
11009
|
+
return true;
|
|
11010
|
+
}
|
|
11011
|
+
|
|
11012
|
+
// ../../node_modules/uint8arrays/dist/src/alloc.node.js
|
|
11013
|
+
var import_node_buffer = require("buffer");
|
|
11014
|
+
|
|
11015
|
+
// ../../node_modules/uint8arrays/dist/src/util/as-uint8array.node.js
|
|
11016
|
+
function asUint8Array(buf) {
|
|
11017
|
+
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
11018
|
+
}
|
|
11019
|
+
|
|
11020
|
+
// ../../node_modules/uint8arrays/dist/src/alloc.node.js
|
|
11021
|
+
function allocUnsafe(size = 0) {
|
|
11022
|
+
return asUint8Array(import_node_buffer.Buffer.allocUnsafe(size));
|
|
11023
|
+
}
|
|
11024
|
+
|
|
11025
|
+
// ../../node_modules/uint8-varint/dist/src/index.js
|
|
11026
|
+
var N12 = Math.pow(2, 7);
|
|
11027
|
+
var N22 = Math.pow(2, 14);
|
|
11028
|
+
var N32 = Math.pow(2, 21);
|
|
11029
|
+
var N42 = Math.pow(2, 28);
|
|
11030
|
+
var N52 = Math.pow(2, 35);
|
|
11031
|
+
var N62 = Math.pow(2, 42);
|
|
11032
|
+
var N72 = Math.pow(2, 49);
|
|
11033
|
+
var MSB2 = 128;
|
|
11034
|
+
var REST2 = 127;
|
|
11035
|
+
function encodingLength2(value) {
|
|
11036
|
+
if (value < N12) {
|
|
11037
|
+
return 1;
|
|
11038
|
+
}
|
|
11039
|
+
if (value < N22) {
|
|
11040
|
+
return 2;
|
|
11041
|
+
}
|
|
11042
|
+
if (value < N32) {
|
|
11043
|
+
return 3;
|
|
11044
|
+
}
|
|
11045
|
+
if (value < N42) {
|
|
11046
|
+
return 4;
|
|
11047
|
+
}
|
|
11048
|
+
if (value < N52) {
|
|
11049
|
+
return 5;
|
|
11050
|
+
}
|
|
11051
|
+
if (value < N62) {
|
|
11052
|
+
return 6;
|
|
11053
|
+
}
|
|
11054
|
+
if (value < N72) {
|
|
11055
|
+
return 7;
|
|
11056
|
+
}
|
|
11057
|
+
if (Number.MAX_SAFE_INTEGER != null && value > Number.MAX_SAFE_INTEGER) {
|
|
11058
|
+
throw new RangeError("Could not encode varint");
|
|
11059
|
+
}
|
|
11060
|
+
return 8;
|
|
11061
|
+
}
|
|
11062
|
+
function encodeUint8Array(value, buf, offset = 0) {
|
|
11063
|
+
switch (encodingLength2(value)) {
|
|
11064
|
+
case 8: {
|
|
11065
|
+
buf[offset++] = value & 255 | MSB2;
|
|
11066
|
+
value /= 128;
|
|
11067
|
+
}
|
|
11068
|
+
case 7: {
|
|
11069
|
+
buf[offset++] = value & 255 | MSB2;
|
|
11070
|
+
value /= 128;
|
|
11071
|
+
}
|
|
11072
|
+
case 6: {
|
|
11073
|
+
buf[offset++] = value & 255 | MSB2;
|
|
11074
|
+
value /= 128;
|
|
11075
|
+
}
|
|
11076
|
+
case 5: {
|
|
11077
|
+
buf[offset++] = value & 255 | MSB2;
|
|
11078
|
+
value /= 128;
|
|
11079
|
+
}
|
|
11080
|
+
case 4: {
|
|
11081
|
+
buf[offset++] = value & 255 | MSB2;
|
|
11082
|
+
value >>>= 7;
|
|
11083
|
+
}
|
|
11084
|
+
case 3: {
|
|
11085
|
+
buf[offset++] = value & 255 | MSB2;
|
|
11086
|
+
value >>>= 7;
|
|
11087
|
+
}
|
|
11088
|
+
case 2: {
|
|
11089
|
+
buf[offset++] = value & 255 | MSB2;
|
|
11090
|
+
value >>>= 7;
|
|
11091
|
+
}
|
|
11092
|
+
case 1: {
|
|
11093
|
+
buf[offset++] = value & 255;
|
|
11094
|
+
value >>>= 7;
|
|
11095
|
+
break;
|
|
11096
|
+
}
|
|
11097
|
+
default:
|
|
11098
|
+
throw new Error("unreachable");
|
|
11099
|
+
}
|
|
11100
|
+
return buf;
|
|
11101
|
+
}
|
|
11102
|
+
function decodeUint8Array(buf, offset) {
|
|
11103
|
+
let b = buf[offset];
|
|
11104
|
+
let res = 0;
|
|
11105
|
+
res += b & REST2;
|
|
11106
|
+
if (b < MSB2) {
|
|
11107
|
+
return res;
|
|
11108
|
+
}
|
|
11109
|
+
b = buf[offset + 1];
|
|
11110
|
+
res += (b & REST2) << 7;
|
|
11111
|
+
if (b < MSB2) {
|
|
11112
|
+
return res;
|
|
11113
|
+
}
|
|
11114
|
+
b = buf[offset + 2];
|
|
11115
|
+
res += (b & REST2) << 14;
|
|
11116
|
+
if (b < MSB2) {
|
|
11117
|
+
return res;
|
|
11118
|
+
}
|
|
11119
|
+
b = buf[offset + 3];
|
|
11120
|
+
res += (b & REST2) << 21;
|
|
11121
|
+
if (b < MSB2) {
|
|
11122
|
+
return res;
|
|
11123
|
+
}
|
|
11124
|
+
b = buf[offset + 4];
|
|
11125
|
+
res += (b & REST2) * N42;
|
|
11126
|
+
if (b < MSB2) {
|
|
11127
|
+
return res;
|
|
11128
|
+
}
|
|
11129
|
+
b = buf[offset + 5];
|
|
11130
|
+
res += (b & REST2) * N52;
|
|
11131
|
+
if (b < MSB2) {
|
|
11132
|
+
return res;
|
|
11133
|
+
}
|
|
11134
|
+
b = buf[offset + 6];
|
|
11135
|
+
res += (b & REST2) * N62;
|
|
11136
|
+
if (b < MSB2) {
|
|
11137
|
+
return res;
|
|
11138
|
+
}
|
|
11139
|
+
b = buf[offset + 7];
|
|
11140
|
+
res += (b & REST2) * N72;
|
|
11141
|
+
if (b < MSB2) {
|
|
11142
|
+
return res;
|
|
11143
|
+
}
|
|
11144
|
+
throw new RangeError("Could not decode varint");
|
|
11145
|
+
}
|
|
11146
|
+
function decodeUint8ArrayList(buf, offset) {
|
|
11147
|
+
let b = buf.get(offset);
|
|
11148
|
+
let res = 0;
|
|
11149
|
+
res += b & REST2;
|
|
11150
|
+
if (b < MSB2) {
|
|
11151
|
+
return res;
|
|
11152
|
+
}
|
|
11153
|
+
b = buf.get(offset + 1);
|
|
11154
|
+
res += (b & REST2) << 7;
|
|
11155
|
+
if (b < MSB2) {
|
|
11156
|
+
return res;
|
|
11157
|
+
}
|
|
11158
|
+
b = buf.get(offset + 2);
|
|
11159
|
+
res += (b & REST2) << 14;
|
|
11160
|
+
if (b < MSB2) {
|
|
11161
|
+
return res;
|
|
11162
|
+
}
|
|
11163
|
+
b = buf.get(offset + 3);
|
|
11164
|
+
res += (b & REST2) << 21;
|
|
11165
|
+
if (b < MSB2) {
|
|
11166
|
+
return res;
|
|
11167
|
+
}
|
|
11168
|
+
b = buf.get(offset + 4);
|
|
11169
|
+
res += (b & REST2) * N42;
|
|
11170
|
+
if (b < MSB2) {
|
|
11171
|
+
return res;
|
|
11172
|
+
}
|
|
11173
|
+
b = buf.get(offset + 5);
|
|
11174
|
+
res += (b & REST2) * N52;
|
|
11175
|
+
if (b < MSB2) {
|
|
11176
|
+
return res;
|
|
11177
|
+
}
|
|
11178
|
+
b = buf.get(offset + 6);
|
|
11179
|
+
res += (b & REST2) * N62;
|
|
11180
|
+
if (b < MSB2) {
|
|
11181
|
+
return res;
|
|
11182
|
+
}
|
|
11183
|
+
b = buf.get(offset + 7);
|
|
11184
|
+
res += (b & REST2) * N72;
|
|
11185
|
+
if (b < MSB2) {
|
|
11186
|
+
return res;
|
|
11187
|
+
}
|
|
11188
|
+
throw new RangeError("Could not decode varint");
|
|
11189
|
+
}
|
|
11190
|
+
function decode6(buf, offset = 0) {
|
|
11191
|
+
if (buf instanceof Uint8Array) {
|
|
11192
|
+
return decodeUint8Array(buf, offset);
|
|
11193
|
+
} else {
|
|
11194
|
+
return decodeUint8ArrayList(buf, offset);
|
|
11195
|
+
}
|
|
11196
|
+
}
|
|
11197
|
+
|
|
11198
|
+
// ../../node_modules/uint8arrays/dist/src/concat.node.js
|
|
11199
|
+
var import_node_buffer2 = require("buffer");
|
|
11200
|
+
function concat(arrays, length2) {
|
|
11201
|
+
return asUint8Array(import_node_buffer2.Buffer.concat(arrays, length2));
|
|
11202
|
+
}
|
|
11203
|
+
|
|
11204
|
+
// ../../node_modules/uint8arrays/dist/src/from-string.node.js
|
|
11205
|
+
var import_node_buffer3 = require("buffer");
|
|
11206
|
+
|
|
11207
|
+
// ../../node_modules/uint8arrays/dist/src/util/bases.js
|
|
11208
|
+
function createCodec(name2, prefix, encode5, decode7) {
|
|
11209
|
+
return {
|
|
11210
|
+
name: name2,
|
|
11211
|
+
prefix,
|
|
11212
|
+
encoder: {
|
|
11213
|
+
name: name2,
|
|
11214
|
+
prefix,
|
|
11215
|
+
encode: encode5
|
|
11216
|
+
},
|
|
11217
|
+
decoder: {
|
|
11218
|
+
decode: decode7
|
|
11219
|
+
}
|
|
11220
|
+
};
|
|
11221
|
+
}
|
|
11222
|
+
var string = createCodec("utf8", "u", (buf) => {
|
|
11223
|
+
const decoder = new TextDecoder("utf8");
|
|
11224
|
+
return "u" + decoder.decode(buf);
|
|
11225
|
+
}, (str) => {
|
|
11226
|
+
const encoder = new TextEncoder();
|
|
11227
|
+
return encoder.encode(str.substring(1));
|
|
11228
|
+
});
|
|
11229
|
+
var ascii = createCodec("ascii", "a", (buf) => {
|
|
11230
|
+
let string2 = "a";
|
|
11231
|
+
for (let i = 0; i < buf.length; i++) {
|
|
11232
|
+
string2 += String.fromCharCode(buf[i]);
|
|
11233
|
+
}
|
|
11234
|
+
return string2;
|
|
11235
|
+
}, (str) => {
|
|
11236
|
+
str = str.substring(1);
|
|
11237
|
+
const buf = allocUnsafe(str.length);
|
|
11238
|
+
for (let i = 0; i < str.length; i++) {
|
|
11239
|
+
buf[i] = str.charCodeAt(i);
|
|
11240
|
+
}
|
|
11241
|
+
return buf;
|
|
11242
|
+
});
|
|
11243
|
+
var BASES = {
|
|
11244
|
+
utf8: string,
|
|
11245
|
+
"utf-8": string,
|
|
11246
|
+
hex: bases.base16,
|
|
11247
|
+
latin1: ascii,
|
|
11248
|
+
ascii,
|
|
11249
|
+
binary: ascii,
|
|
11250
|
+
...bases
|
|
11251
|
+
};
|
|
11252
|
+
var bases_default = BASES;
|
|
11253
|
+
|
|
11254
|
+
// ../../node_modules/uint8arrays/dist/src/from-string.node.js
|
|
11255
|
+
function fromString2(string2, encoding = "utf8") {
|
|
11256
|
+
const base3 = bases_default[encoding];
|
|
11257
|
+
if (base3 == null) {
|
|
11258
|
+
throw new Error(`Unsupported encoding "${encoding}"`);
|
|
11259
|
+
}
|
|
11260
|
+
if (encoding === "utf8" || encoding === "utf-8") {
|
|
11261
|
+
return asUint8Array(import_node_buffer3.Buffer.from(string2, "utf-8"));
|
|
11262
|
+
}
|
|
11263
|
+
return base3.decoder.decode(`${base3.prefix}${string2}`);
|
|
11264
|
+
}
|
|
11265
|
+
|
|
11266
|
+
// ../../node_modules/uint8arrays/dist/src/to-string.node.js
|
|
11267
|
+
var import_node_buffer4 = require("buffer");
|
|
11268
|
+
function toString2(array, encoding = "utf8") {
|
|
11269
|
+
const base3 = bases_default[encoding];
|
|
11270
|
+
if (base3 == null) {
|
|
11271
|
+
throw new Error(`Unsupported encoding "${encoding}"`);
|
|
11272
|
+
}
|
|
11273
|
+
if (encoding === "utf8" || encoding === "utf-8") {
|
|
11274
|
+
return import_node_buffer4.Buffer.from(array.buffer, array.byteOffset, array.byteLength).toString("utf8");
|
|
11275
|
+
}
|
|
11276
|
+
return base3.encoder.encode(array).substring(1);
|
|
11277
|
+
}
|
|
11278
|
+
|
|
11279
|
+
// ../../node_modules/@multiformats/multiaddr/dist/src/errors.js
|
|
11280
|
+
var InvalidMultiaddrError = class extends Error {
|
|
11281
|
+
constructor() {
|
|
11282
|
+
super(...arguments);
|
|
11283
|
+
__publicField(this, "name", "InvalidMultiaddrError");
|
|
11284
|
+
}
|
|
11285
|
+
};
|
|
11286
|
+
__publicField(InvalidMultiaddrError, "name", "InvalidMultiaddrError");
|
|
11287
|
+
var ValidationError = class extends Error {
|
|
11288
|
+
constructor() {
|
|
11289
|
+
super(...arguments);
|
|
11290
|
+
__publicField(this, "name", "ValidationError");
|
|
11291
|
+
}
|
|
11292
|
+
};
|
|
11293
|
+
__publicField(ValidationError, "name", "ValidationError");
|
|
11294
|
+
var InvalidParametersError = class extends Error {
|
|
11295
|
+
constructor() {
|
|
11296
|
+
super(...arguments);
|
|
11297
|
+
__publicField(this, "name", "InvalidParametersError");
|
|
11298
|
+
}
|
|
11299
|
+
};
|
|
11300
|
+
__publicField(InvalidParametersError, "name", "InvalidParametersError");
|
|
11301
|
+
var UnknownProtocolError = class extends Error {
|
|
11302
|
+
constructor() {
|
|
11303
|
+
super(...arguments);
|
|
11304
|
+
__publicField(this, "name", "UnknownProtocolError");
|
|
11305
|
+
}
|
|
11306
|
+
};
|
|
11307
|
+
__publicField(UnknownProtocolError, "name", "UnknownProtocolError");
|
|
11308
|
+
|
|
11309
|
+
// ../../node_modules/@chainsafe/is-ip/lib/is-ip.node.js
|
|
11310
|
+
var import_node_net = require("net");
|
|
11311
|
+
|
|
11312
|
+
// ../../node_modules/@multiformats/multiaddr/dist/src/constants.js
|
|
11313
|
+
var CODE_IP4 = 4;
|
|
11314
|
+
var CODE_TCP = 6;
|
|
11315
|
+
var CODE_UDP = 273;
|
|
11316
|
+
var CODE_DCCP = 33;
|
|
11317
|
+
var CODE_IP6 = 41;
|
|
11318
|
+
var CODE_IP6ZONE = 42;
|
|
11319
|
+
var CODE_IPCIDR = 43;
|
|
11320
|
+
var CODE_DNS = 53;
|
|
11321
|
+
var CODE_DNS4 = 54;
|
|
11322
|
+
var CODE_DNS6 = 55;
|
|
11323
|
+
var CODE_DNSADDR = 56;
|
|
11324
|
+
var CODE_SCTP = 132;
|
|
11325
|
+
var CODE_UDT = 301;
|
|
11326
|
+
var CODE_UTP = 302;
|
|
11327
|
+
var CODE_UNIX = 400;
|
|
11328
|
+
var CODE_P2P = 421;
|
|
11329
|
+
var CODE_ONION = 444;
|
|
11330
|
+
var CODE_ONION3 = 445;
|
|
11331
|
+
var CODE_GARLIC64 = 446;
|
|
11332
|
+
var CODE_GARLIC32 = 447;
|
|
11333
|
+
var CODE_TLS = 448;
|
|
11334
|
+
var CODE_SNI = 449;
|
|
11335
|
+
var CODE_NOISE = 454;
|
|
11336
|
+
var CODE_QUIC = 460;
|
|
11337
|
+
var CODE_QUIC_V1 = 461;
|
|
11338
|
+
var CODE_WEBTRANSPORT = 465;
|
|
11339
|
+
var CODE_CERTHASH = 466;
|
|
11340
|
+
var CODE_HTTP = 480;
|
|
11341
|
+
var CODE_HTTP_PATH = 481;
|
|
11342
|
+
var CODE_HTTPS = 443;
|
|
11343
|
+
var CODE_WS = 477;
|
|
11344
|
+
var CODE_WSS = 478;
|
|
11345
|
+
var CODE_P2P_WEBSOCKET_STAR = 479;
|
|
11346
|
+
var CODE_P2P_STARDUST = 277;
|
|
11347
|
+
var CODE_P2P_WEBRTC_STAR = 275;
|
|
11348
|
+
var CODE_P2P_WEBRTC_DIRECT = 276;
|
|
11349
|
+
var CODE_WEBRTC_DIRECT = 280;
|
|
11350
|
+
var CODE_WEBRTC = 281;
|
|
11351
|
+
var CODE_P2P_CIRCUIT = 290;
|
|
11352
|
+
var CODE_MEMORY = 777;
|
|
11353
|
+
|
|
11354
|
+
// ../../node_modules/@multiformats/multiaddr/dist/src/utils.js
|
|
11355
|
+
function bytesToString(base3) {
|
|
11356
|
+
return (buf) => {
|
|
11357
|
+
return toString2(buf, base3);
|
|
11358
|
+
};
|
|
11359
|
+
}
|
|
11360
|
+
function stringToBytes(base3) {
|
|
11361
|
+
return (buf) => {
|
|
11362
|
+
return fromString2(buf, base3);
|
|
11363
|
+
};
|
|
11364
|
+
}
|
|
11365
|
+
function bytes2port(buf) {
|
|
11366
|
+
const view = new DataView(buf.buffer);
|
|
11367
|
+
return view.getUint16(buf.byteOffset).toString();
|
|
11368
|
+
}
|
|
11369
|
+
function port2bytes(port) {
|
|
11370
|
+
const buf = new ArrayBuffer(2);
|
|
11371
|
+
const view = new DataView(buf);
|
|
11372
|
+
view.setUint16(0, typeof port === "string" ? parseInt(port) : port);
|
|
11373
|
+
return new Uint8Array(buf);
|
|
11374
|
+
}
|
|
11375
|
+
function onion2bytes(str) {
|
|
11376
|
+
const addr = str.split(":");
|
|
11377
|
+
if (addr.length !== 2) {
|
|
11378
|
+
throw new Error(`failed to parse onion addr: ["'${addr.join('", "')}'"]' does not contain a port number`);
|
|
11379
|
+
}
|
|
11380
|
+
if (addr[0].length !== 16) {
|
|
11381
|
+
throw new Error(`failed to parse onion addr: ${addr[0]} not a Tor onion address.`);
|
|
11382
|
+
}
|
|
11383
|
+
const buf = fromString2(addr[0], "base32");
|
|
11384
|
+
const port = parseInt(addr[1], 10);
|
|
11385
|
+
if (port < 1 || port > 65536) {
|
|
11386
|
+
throw new Error("Port number is not in range(1, 65536)");
|
|
11387
|
+
}
|
|
11388
|
+
const portBuf = port2bytes(port);
|
|
11389
|
+
return concat([buf, portBuf], buf.length + portBuf.length);
|
|
11390
|
+
}
|
|
11391
|
+
function onion32bytes(str) {
|
|
11392
|
+
const addr = str.split(":");
|
|
11393
|
+
if (addr.length !== 2) {
|
|
11394
|
+
throw new Error(`failed to parse onion addr: ["'${addr.join('", "')}'"]' does not contain a port number`);
|
|
11395
|
+
}
|
|
11396
|
+
if (addr[0].length !== 56) {
|
|
11397
|
+
throw new Error(`failed to parse onion addr: ${addr[0]} not a Tor onion3 address.`);
|
|
11398
|
+
}
|
|
11399
|
+
const buf = base32.decode(`b${addr[0]}`);
|
|
11400
|
+
const port = parseInt(addr[1], 10);
|
|
11401
|
+
if (port < 1 || port > 65536) {
|
|
11402
|
+
throw new Error("Port number is not in range(1, 65536)");
|
|
11403
|
+
}
|
|
11404
|
+
const portBuf = port2bytes(port);
|
|
11405
|
+
return concat([buf, portBuf], buf.length + portBuf.length);
|
|
11406
|
+
}
|
|
11407
|
+
function bytes2onion(buf) {
|
|
11408
|
+
const addrBytes = buf.subarray(0, buf.length - 2);
|
|
11409
|
+
const portBytes = buf.subarray(buf.length - 2);
|
|
11410
|
+
const addr = toString2(addrBytes, "base32");
|
|
11411
|
+
const port = bytes2port(portBytes);
|
|
11412
|
+
return `${addr}:${port}`;
|
|
11413
|
+
}
|
|
11414
|
+
var ip4ToBytes = function(ip) {
|
|
11415
|
+
ip = ip.toString().trim();
|
|
11416
|
+
const bytes = new Uint8Array(4);
|
|
11417
|
+
ip.split(/\./g).forEach((byte, index) => {
|
|
11418
|
+
const value = parseInt(byte, 10);
|
|
11419
|
+
if (isNaN(value) || value < 0 || value > 255) {
|
|
11420
|
+
throw new InvalidMultiaddrError("Invalid byte value in IP address");
|
|
11421
|
+
}
|
|
11422
|
+
bytes[index] = value;
|
|
11423
|
+
});
|
|
11424
|
+
return bytes;
|
|
11425
|
+
};
|
|
11426
|
+
var ip6ToBytes = function(ip) {
|
|
11427
|
+
let offset = 0;
|
|
11428
|
+
ip = ip.toString().trim();
|
|
11429
|
+
const sections = ip.split(":", 8);
|
|
11430
|
+
let i;
|
|
11431
|
+
for (i = 0; i < sections.length; i++) {
|
|
11432
|
+
const isv4 = (0, import_node_net.isIPv4)(sections[i]);
|
|
11433
|
+
let v4Buffer;
|
|
11434
|
+
if (isv4) {
|
|
11435
|
+
v4Buffer = ip4ToBytes(sections[i]);
|
|
11436
|
+
sections[i] = toString2(v4Buffer.subarray(0, 2), "base16");
|
|
11437
|
+
}
|
|
11438
|
+
if (v4Buffer != null && ++i < 8) {
|
|
11439
|
+
sections.splice(i, 0, toString2(v4Buffer.subarray(2, 4), "base16"));
|
|
11440
|
+
}
|
|
11441
|
+
}
|
|
11442
|
+
if (sections[0] === "") {
|
|
11443
|
+
while (sections.length < 8) {
|
|
11444
|
+
sections.unshift("0");
|
|
11445
|
+
}
|
|
11446
|
+
} else if (sections[sections.length - 1] === "") {
|
|
11447
|
+
while (sections.length < 8) {
|
|
11448
|
+
sections.push("0");
|
|
11449
|
+
}
|
|
11450
|
+
} else if (sections.length < 8) {
|
|
11451
|
+
for (i = 0; i < sections.length && sections[i] !== ""; i++) {
|
|
11452
|
+
}
|
|
11453
|
+
const argv = [i, 1];
|
|
11454
|
+
for (i = 9 - sections.length; i > 0; i--) {
|
|
11455
|
+
argv.push("0");
|
|
11456
|
+
}
|
|
11457
|
+
sections.splice.apply(sections, argv);
|
|
11458
|
+
}
|
|
11459
|
+
const bytes = new Uint8Array(offset + 16);
|
|
11460
|
+
for (i = 0; i < sections.length; i++) {
|
|
11461
|
+
if (sections[i] === "") {
|
|
11462
|
+
sections[i] = "0";
|
|
11463
|
+
}
|
|
11464
|
+
const word2 = parseInt(sections[i], 16);
|
|
11465
|
+
if (isNaN(word2) || word2 < 0 || word2 > 65535) {
|
|
11466
|
+
throw new InvalidMultiaddrError("Invalid byte value in IP address");
|
|
11467
|
+
}
|
|
11468
|
+
bytes[offset++] = word2 >> 8 & 255;
|
|
11469
|
+
bytes[offset++] = word2 & 255;
|
|
11470
|
+
}
|
|
11471
|
+
return bytes;
|
|
11472
|
+
};
|
|
11473
|
+
var ip4ToString = function(buf) {
|
|
11474
|
+
if (buf.byteLength !== 4) {
|
|
11475
|
+
throw new InvalidMultiaddrError("IPv4 address was incorrect length");
|
|
11476
|
+
}
|
|
11477
|
+
const result = [];
|
|
11478
|
+
for (let i = 0; i < buf.byteLength; i++) {
|
|
11479
|
+
result.push(buf[i]);
|
|
11480
|
+
}
|
|
11481
|
+
return result.join(".");
|
|
11482
|
+
};
|
|
11483
|
+
var ip6ToString = function(buf) {
|
|
11484
|
+
if (buf.byteLength !== 16) {
|
|
11485
|
+
throw new InvalidMultiaddrError("IPv6 address was incorrect length");
|
|
11486
|
+
}
|
|
11487
|
+
const result = [];
|
|
11488
|
+
for (let i = 0; i < buf.byteLength; i += 2) {
|
|
11489
|
+
const byte1 = buf[i];
|
|
11490
|
+
const byte2 = buf[i + 1];
|
|
11491
|
+
const tuple = `${byte1.toString(16).padStart(2, "0")}${byte2.toString(16).padStart(2, "0")}`;
|
|
11492
|
+
result.push(tuple);
|
|
11493
|
+
}
|
|
11494
|
+
const ip = result.join(":");
|
|
11495
|
+
try {
|
|
11496
|
+
const url = new URL(`http://[${ip}]`);
|
|
11497
|
+
return url.hostname.substring(1, url.hostname.length - 1);
|
|
11498
|
+
} catch {
|
|
11499
|
+
throw new InvalidMultiaddrError(`Invalid IPv6 address "${ip}"`);
|
|
11500
|
+
}
|
|
11501
|
+
};
|
|
11502
|
+
function ip6StringToValue(str) {
|
|
11503
|
+
try {
|
|
11504
|
+
const url = new URL(`http://[${str}]`);
|
|
11505
|
+
return url.hostname.substring(1, url.hostname.length - 1);
|
|
11506
|
+
} catch {
|
|
11507
|
+
throw new InvalidMultiaddrError(`Invalid IPv6 address "${str}"`);
|
|
11508
|
+
}
|
|
11509
|
+
}
|
|
11510
|
+
var decoders = Object.values(bases).map((c) => c.decoder);
|
|
11511
|
+
var anybaseDecoder = (function() {
|
|
11512
|
+
let acc = decoders[0].or(decoders[1]);
|
|
11513
|
+
decoders.slice(2).forEach((d) => acc = acc.or(d));
|
|
11514
|
+
return acc;
|
|
11515
|
+
})();
|
|
11516
|
+
function mb2bytes(mbstr) {
|
|
11517
|
+
return anybaseDecoder.decode(mbstr);
|
|
11518
|
+
}
|
|
11519
|
+
function bytes2mb(base3) {
|
|
11520
|
+
return (buf) => {
|
|
11521
|
+
return base3.encoder.encode(buf);
|
|
11522
|
+
};
|
|
11523
|
+
}
|
|
11524
|
+
|
|
11525
|
+
// ../../node_modules/@multiformats/multiaddr/dist/src/validation.js
|
|
11526
|
+
function integer(value) {
|
|
11527
|
+
const int = parseInt(value);
|
|
11528
|
+
if (int.toString() !== value) {
|
|
11529
|
+
throw new ValidationError("Value must be an integer");
|
|
11530
|
+
}
|
|
11531
|
+
}
|
|
11532
|
+
function positive(value) {
|
|
11533
|
+
if (value < 0) {
|
|
11534
|
+
throw new ValidationError("Value must be a positive integer, or zero");
|
|
11535
|
+
}
|
|
11536
|
+
}
|
|
11537
|
+
function maxValue(max) {
|
|
11538
|
+
return (value) => {
|
|
11539
|
+
if (value > max) {
|
|
11540
|
+
throw new ValidationError(`Value must be smaller than or equal to ${max}`);
|
|
11541
|
+
}
|
|
11542
|
+
};
|
|
11543
|
+
}
|
|
11544
|
+
function validate(...funcs) {
|
|
11545
|
+
return (value) => {
|
|
11546
|
+
for (const fn of funcs) {
|
|
11547
|
+
fn(value);
|
|
11548
|
+
}
|
|
11549
|
+
};
|
|
11550
|
+
}
|
|
11551
|
+
var validatePort = validate(integer, positive, maxValue(65535));
|
|
11552
|
+
|
|
11553
|
+
// ../../node_modules/@multiformats/multiaddr/dist/src/registry.js
|
|
11554
|
+
var V = -1;
|
|
11555
|
+
var Registry = class {
|
|
11556
|
+
constructor() {
|
|
11557
|
+
__publicField(this, "protocolsByCode", /* @__PURE__ */ new Map());
|
|
11558
|
+
__publicField(this, "protocolsByName", /* @__PURE__ */ new Map());
|
|
11559
|
+
}
|
|
11560
|
+
getProtocol(key) {
|
|
11561
|
+
let codec;
|
|
11562
|
+
if (typeof key === "string") {
|
|
11563
|
+
codec = this.protocolsByName.get(key);
|
|
11564
|
+
} else {
|
|
11565
|
+
codec = this.protocolsByCode.get(key);
|
|
11566
|
+
}
|
|
11567
|
+
if (codec == null) {
|
|
11568
|
+
throw new UnknownProtocolError(`Protocol ${key} was unknown`);
|
|
11569
|
+
}
|
|
11570
|
+
return codec;
|
|
11571
|
+
}
|
|
11572
|
+
addProtocol(codec) {
|
|
11573
|
+
this.protocolsByCode.set(codec.code, codec);
|
|
11574
|
+
this.protocolsByName.set(codec.name, codec);
|
|
11575
|
+
codec.aliases?.forEach((alias) => {
|
|
11576
|
+
this.protocolsByName.set(alias, codec);
|
|
11577
|
+
});
|
|
11578
|
+
}
|
|
11579
|
+
removeProtocol(code2) {
|
|
11580
|
+
const codec = this.protocolsByCode.get(code2);
|
|
11581
|
+
if (codec == null) {
|
|
11582
|
+
return;
|
|
11583
|
+
}
|
|
11584
|
+
this.protocolsByCode.delete(codec.code);
|
|
11585
|
+
this.protocolsByName.delete(codec.name);
|
|
11586
|
+
codec.aliases?.forEach((alias) => {
|
|
11587
|
+
this.protocolsByName.delete(alias);
|
|
11588
|
+
});
|
|
11589
|
+
}
|
|
11590
|
+
};
|
|
11591
|
+
var registry = new Registry();
|
|
11592
|
+
var codecs = [{
|
|
11593
|
+
code: CODE_IP4,
|
|
11594
|
+
name: "ip4",
|
|
11595
|
+
size: 32,
|
|
11596
|
+
valueToBytes: ip4ToBytes,
|
|
11597
|
+
bytesToValue: ip4ToString,
|
|
11598
|
+
validate: (value) => {
|
|
11599
|
+
if (!(0, import_node_net.isIPv4)(value)) {
|
|
11600
|
+
throw new ValidationError(`Invalid IPv4 address "${value}"`);
|
|
11601
|
+
}
|
|
11602
|
+
}
|
|
11603
|
+
}, {
|
|
11604
|
+
code: CODE_TCP,
|
|
11605
|
+
name: "tcp",
|
|
11606
|
+
size: 16,
|
|
11607
|
+
valueToBytes: port2bytes,
|
|
11608
|
+
bytesToValue: bytes2port,
|
|
11609
|
+
validate: validatePort
|
|
11610
|
+
}, {
|
|
11611
|
+
code: CODE_UDP,
|
|
11612
|
+
name: "udp",
|
|
11613
|
+
size: 16,
|
|
11614
|
+
valueToBytes: port2bytes,
|
|
11615
|
+
bytesToValue: bytes2port,
|
|
11616
|
+
validate: validatePort
|
|
11617
|
+
}, {
|
|
11618
|
+
code: CODE_DCCP,
|
|
11619
|
+
name: "dccp",
|
|
11620
|
+
size: 16,
|
|
11621
|
+
valueToBytes: port2bytes,
|
|
11622
|
+
bytesToValue: bytes2port,
|
|
11623
|
+
validate: validatePort
|
|
11624
|
+
}, {
|
|
11625
|
+
code: CODE_IP6,
|
|
11626
|
+
name: "ip6",
|
|
11627
|
+
size: 128,
|
|
11628
|
+
valueToBytes: ip6ToBytes,
|
|
11629
|
+
bytesToValue: ip6ToString,
|
|
11630
|
+
stringToValue: ip6StringToValue,
|
|
11631
|
+
validate: (value) => {
|
|
11632
|
+
if (!(0, import_node_net.isIPv6)(value)) {
|
|
11633
|
+
throw new ValidationError(`Invalid IPv6 address "${value}"`);
|
|
11634
|
+
}
|
|
11635
|
+
}
|
|
11636
|
+
}, {
|
|
11637
|
+
code: CODE_IP6ZONE,
|
|
11638
|
+
name: "ip6zone",
|
|
11639
|
+
size: V
|
|
11640
|
+
}, {
|
|
11641
|
+
code: CODE_IPCIDR,
|
|
11642
|
+
name: "ipcidr",
|
|
11643
|
+
size: 8,
|
|
11644
|
+
bytesToValue: bytesToString("base10"),
|
|
11645
|
+
valueToBytes: stringToBytes("base10")
|
|
11646
|
+
}, {
|
|
11647
|
+
code: CODE_DNS,
|
|
11648
|
+
name: "dns",
|
|
11649
|
+
size: V
|
|
11650
|
+
}, {
|
|
11651
|
+
code: CODE_DNS4,
|
|
11652
|
+
name: "dns4",
|
|
11653
|
+
size: V
|
|
11654
|
+
}, {
|
|
11655
|
+
code: CODE_DNS6,
|
|
11656
|
+
name: "dns6",
|
|
11657
|
+
size: V
|
|
11658
|
+
}, {
|
|
11659
|
+
code: CODE_DNSADDR,
|
|
11660
|
+
name: "dnsaddr",
|
|
11661
|
+
size: V
|
|
11662
|
+
}, {
|
|
11663
|
+
code: CODE_SCTP,
|
|
11664
|
+
name: "sctp",
|
|
11665
|
+
size: 16,
|
|
11666
|
+
valueToBytes: port2bytes,
|
|
11667
|
+
bytesToValue: bytes2port,
|
|
11668
|
+
validate: validatePort
|
|
11669
|
+
}, {
|
|
11670
|
+
code: CODE_UDT,
|
|
11671
|
+
name: "udt"
|
|
11672
|
+
}, {
|
|
11673
|
+
code: CODE_UTP,
|
|
11674
|
+
name: "utp"
|
|
11675
|
+
}, {
|
|
11676
|
+
code: CODE_UNIX,
|
|
11677
|
+
name: "unix",
|
|
11678
|
+
size: V,
|
|
11679
|
+
stringToValue: (str) => decodeURIComponent(str),
|
|
11680
|
+
valueToString: (val) => encodeURIComponent(val)
|
|
11681
|
+
}, {
|
|
11682
|
+
code: CODE_P2P,
|
|
11683
|
+
name: "p2p",
|
|
11684
|
+
aliases: ["ipfs"],
|
|
11685
|
+
size: V,
|
|
11686
|
+
bytesToValue: bytesToString("base58btc"),
|
|
11687
|
+
valueToBytes: (val) => {
|
|
11688
|
+
if (val.startsWith("Q") || val.startsWith("1")) {
|
|
11689
|
+
return stringToBytes("base58btc")(val);
|
|
11690
|
+
}
|
|
11691
|
+
return CID.parse(val).multihash.bytes;
|
|
11692
|
+
}
|
|
11693
|
+
}, {
|
|
11694
|
+
code: CODE_ONION,
|
|
11695
|
+
name: "onion",
|
|
11696
|
+
size: 96,
|
|
11697
|
+
bytesToValue: bytes2onion,
|
|
11698
|
+
valueToBytes: onion2bytes
|
|
11699
|
+
}, {
|
|
11700
|
+
code: CODE_ONION3,
|
|
11701
|
+
name: "onion3",
|
|
11702
|
+
size: 296,
|
|
11703
|
+
bytesToValue: bytes2onion,
|
|
11704
|
+
valueToBytes: onion32bytes
|
|
11705
|
+
}, {
|
|
11706
|
+
code: CODE_GARLIC64,
|
|
11707
|
+
name: "garlic64",
|
|
11708
|
+
size: V
|
|
11709
|
+
}, {
|
|
11710
|
+
code: CODE_GARLIC32,
|
|
11711
|
+
name: "garlic32",
|
|
11712
|
+
size: V
|
|
11713
|
+
}, {
|
|
11714
|
+
code: CODE_TLS,
|
|
11715
|
+
name: "tls"
|
|
11716
|
+
}, {
|
|
11717
|
+
code: CODE_SNI,
|
|
11718
|
+
name: "sni",
|
|
11719
|
+
size: V
|
|
11720
|
+
}, {
|
|
11721
|
+
code: CODE_NOISE,
|
|
11722
|
+
name: "noise"
|
|
11723
|
+
}, {
|
|
11724
|
+
code: CODE_QUIC,
|
|
11725
|
+
name: "quic"
|
|
11726
|
+
}, {
|
|
11727
|
+
code: CODE_QUIC_V1,
|
|
11728
|
+
name: "quic-v1"
|
|
11729
|
+
}, {
|
|
11730
|
+
code: CODE_WEBTRANSPORT,
|
|
11731
|
+
name: "webtransport"
|
|
11732
|
+
}, {
|
|
11733
|
+
code: CODE_CERTHASH,
|
|
11734
|
+
name: "certhash",
|
|
11735
|
+
size: V,
|
|
11736
|
+
bytesToValue: bytes2mb(base64url),
|
|
11737
|
+
valueToBytes: mb2bytes
|
|
11738
|
+
}, {
|
|
11739
|
+
code: CODE_HTTP,
|
|
11740
|
+
name: "http"
|
|
11741
|
+
}, {
|
|
11742
|
+
code: CODE_HTTP_PATH,
|
|
11743
|
+
name: "http-path",
|
|
11744
|
+
size: V,
|
|
11745
|
+
stringToValue: (str) => `/${decodeURIComponent(str)}`,
|
|
11746
|
+
valueToString: (val) => encodeURIComponent(val.substring(1))
|
|
11747
|
+
}, {
|
|
11748
|
+
code: CODE_HTTPS,
|
|
11749
|
+
name: "https"
|
|
11750
|
+
}, {
|
|
11751
|
+
code: CODE_WS,
|
|
11752
|
+
name: "ws"
|
|
11753
|
+
}, {
|
|
11754
|
+
code: CODE_WSS,
|
|
11755
|
+
name: "wss"
|
|
11756
|
+
}, {
|
|
11757
|
+
code: CODE_P2P_WEBSOCKET_STAR,
|
|
11758
|
+
name: "p2p-websocket-star"
|
|
11759
|
+
}, {
|
|
11760
|
+
code: CODE_P2P_STARDUST,
|
|
11761
|
+
name: "p2p-stardust"
|
|
11762
|
+
}, {
|
|
11763
|
+
code: CODE_P2P_WEBRTC_STAR,
|
|
11764
|
+
name: "p2p-webrtc-star"
|
|
11765
|
+
}, {
|
|
11766
|
+
code: CODE_P2P_WEBRTC_DIRECT,
|
|
11767
|
+
name: "p2p-webrtc-direct"
|
|
11768
|
+
}, {
|
|
11769
|
+
code: CODE_WEBRTC_DIRECT,
|
|
11770
|
+
name: "webrtc-direct"
|
|
11771
|
+
}, {
|
|
11772
|
+
code: CODE_WEBRTC,
|
|
11773
|
+
name: "webrtc"
|
|
11774
|
+
}, {
|
|
11775
|
+
code: CODE_P2P_CIRCUIT,
|
|
11776
|
+
name: "p2p-circuit"
|
|
11777
|
+
}, {
|
|
11778
|
+
code: CODE_MEMORY,
|
|
11779
|
+
name: "memory",
|
|
11780
|
+
size: V
|
|
11781
|
+
}];
|
|
11782
|
+
codecs.forEach((codec) => {
|
|
11783
|
+
registry.addProtocol(codec);
|
|
11784
|
+
});
|
|
11785
|
+
|
|
11786
|
+
// ../../node_modules/@multiformats/multiaddr/dist/src/components.js
|
|
11787
|
+
function bytesToComponents(bytes) {
|
|
11788
|
+
const components = [];
|
|
11789
|
+
let i = 0;
|
|
11790
|
+
while (i < bytes.length) {
|
|
11791
|
+
const code2 = decode6(bytes, i);
|
|
11792
|
+
const codec = registry.getProtocol(code2);
|
|
11793
|
+
const codeLength = encodingLength2(code2);
|
|
11794
|
+
const size = sizeForAddr(codec, bytes, i + codeLength);
|
|
11795
|
+
let sizeLength = 0;
|
|
11796
|
+
if (size > 0 && codec.size === V) {
|
|
11797
|
+
sizeLength = encodingLength2(size);
|
|
11798
|
+
}
|
|
11799
|
+
const componentLength = codeLength + sizeLength + size;
|
|
11800
|
+
const component = {
|
|
11801
|
+
code: code2,
|
|
11802
|
+
name: codec.name,
|
|
11803
|
+
bytes: bytes.subarray(i, i + componentLength)
|
|
11804
|
+
};
|
|
11805
|
+
if (size > 0) {
|
|
11806
|
+
const valueOffset = i + codeLength + sizeLength;
|
|
11807
|
+
const valueBytes = bytes.subarray(valueOffset, valueOffset + size);
|
|
11808
|
+
component.value = codec.bytesToValue?.(valueBytes) ?? toString2(valueBytes);
|
|
11809
|
+
}
|
|
11810
|
+
components.push(component);
|
|
11811
|
+
i += componentLength;
|
|
11812
|
+
}
|
|
11813
|
+
return components;
|
|
11814
|
+
}
|
|
11815
|
+
function componentsToBytes(components) {
|
|
11816
|
+
let length2 = 0;
|
|
11817
|
+
const bytes = [];
|
|
11818
|
+
for (const component of components) {
|
|
11819
|
+
if (component.bytes == null) {
|
|
11820
|
+
const codec = registry.getProtocol(component.code);
|
|
11821
|
+
const codecLength = encodingLength2(component.code);
|
|
11822
|
+
let valueBytes;
|
|
11823
|
+
let valueLength = 0;
|
|
11824
|
+
let valueLengthLength = 0;
|
|
11825
|
+
if (component.value != null) {
|
|
11826
|
+
valueBytes = codec.valueToBytes?.(component.value) ?? fromString2(component.value);
|
|
11827
|
+
valueLength = valueBytes.byteLength;
|
|
11828
|
+
if (codec.size === V) {
|
|
11829
|
+
valueLengthLength = encodingLength2(valueLength);
|
|
11830
|
+
}
|
|
11831
|
+
}
|
|
11832
|
+
const bytes2 = new Uint8Array(codecLength + valueLengthLength + valueLength);
|
|
11833
|
+
let offset = 0;
|
|
11834
|
+
encodeUint8Array(component.code, bytes2, offset);
|
|
11835
|
+
offset += codecLength;
|
|
11836
|
+
if (valueBytes != null) {
|
|
11837
|
+
if (codec.size === V) {
|
|
11838
|
+
encodeUint8Array(valueLength, bytes2, offset);
|
|
11839
|
+
offset += valueLengthLength;
|
|
11840
|
+
}
|
|
11841
|
+
bytes2.set(valueBytes, offset);
|
|
11842
|
+
}
|
|
11843
|
+
component.bytes = bytes2;
|
|
11844
|
+
}
|
|
11845
|
+
bytes.push(component.bytes);
|
|
11846
|
+
length2 += component.bytes.byteLength;
|
|
11847
|
+
}
|
|
11848
|
+
return concat(bytes, length2);
|
|
11849
|
+
}
|
|
11850
|
+
function stringToComponents(string2) {
|
|
11851
|
+
if (string2.charAt(0) !== "/") {
|
|
11852
|
+
throw new InvalidMultiaddrError('String multiaddr must start with "/"');
|
|
11853
|
+
}
|
|
11854
|
+
const components = [];
|
|
11855
|
+
let collecting = "protocol";
|
|
11856
|
+
let value = "";
|
|
11857
|
+
let protocol = "";
|
|
11858
|
+
for (let i = 1; i < string2.length; i++) {
|
|
11859
|
+
const char = string2.charAt(i);
|
|
11860
|
+
if (char !== "/") {
|
|
11861
|
+
if (collecting === "protocol") {
|
|
11862
|
+
protocol += string2.charAt(i);
|
|
11863
|
+
} else {
|
|
11864
|
+
value += string2.charAt(i);
|
|
11865
|
+
}
|
|
11866
|
+
}
|
|
11867
|
+
const ended = i === string2.length - 1;
|
|
11868
|
+
if (char === "/" || ended) {
|
|
11869
|
+
const codec = registry.getProtocol(protocol);
|
|
11870
|
+
if (collecting === "protocol") {
|
|
11871
|
+
if (codec.size == null || codec.size === 0) {
|
|
11872
|
+
components.push({
|
|
11873
|
+
code: codec.code,
|
|
11874
|
+
name: codec.name
|
|
11875
|
+
});
|
|
11876
|
+
value = "";
|
|
11877
|
+
protocol = "";
|
|
11878
|
+
collecting = "protocol";
|
|
11879
|
+
continue;
|
|
11880
|
+
} else if (ended) {
|
|
11881
|
+
throw new InvalidMultiaddrError(`Component ${protocol} was missing value`);
|
|
11882
|
+
}
|
|
11883
|
+
collecting = "value";
|
|
11884
|
+
} else if (collecting === "value") {
|
|
11885
|
+
const component = {
|
|
11886
|
+
code: codec.code,
|
|
11887
|
+
name: codec.name
|
|
11888
|
+
};
|
|
11889
|
+
if (codec.size != null && codec.size !== 0) {
|
|
11890
|
+
if (value === "") {
|
|
11891
|
+
throw new InvalidMultiaddrError(`Component ${protocol} was missing value`);
|
|
11892
|
+
}
|
|
11893
|
+
component.value = codec.stringToValue?.(value) ?? value;
|
|
11894
|
+
}
|
|
11895
|
+
components.push(component);
|
|
11896
|
+
value = "";
|
|
11897
|
+
protocol = "";
|
|
11898
|
+
collecting = "protocol";
|
|
11899
|
+
}
|
|
11900
|
+
}
|
|
11901
|
+
}
|
|
11902
|
+
if (protocol !== "" && value !== "") {
|
|
11903
|
+
throw new InvalidMultiaddrError("Incomplete multiaddr");
|
|
11904
|
+
}
|
|
11905
|
+
return components;
|
|
11906
|
+
}
|
|
11907
|
+
function componentsToString(components) {
|
|
11908
|
+
return `/${components.flatMap((component) => {
|
|
11909
|
+
if (component.value == null) {
|
|
11910
|
+
return component.name;
|
|
11911
|
+
}
|
|
11912
|
+
const codec = registry.getProtocol(component.code);
|
|
11913
|
+
if (codec == null) {
|
|
11914
|
+
throw new InvalidMultiaddrError(`Unknown protocol code ${component.code}`);
|
|
11915
|
+
}
|
|
11916
|
+
return [
|
|
11917
|
+
component.name,
|
|
11918
|
+
codec.valueToString?.(component.value) ?? component.value
|
|
11919
|
+
];
|
|
11920
|
+
}).join("/")}`;
|
|
11921
|
+
}
|
|
11922
|
+
function sizeForAddr(codec, bytes, offset) {
|
|
11923
|
+
if (codec.size == null || codec.size === 0) {
|
|
11924
|
+
return 0;
|
|
11925
|
+
}
|
|
11926
|
+
if (codec.size > 0) {
|
|
11927
|
+
return codec.size / 8;
|
|
11928
|
+
}
|
|
11929
|
+
return decode6(bytes, offset);
|
|
11930
|
+
}
|
|
11931
|
+
|
|
11932
|
+
// ../../node_modules/@multiformats/multiaddr/dist/src/multiaddr.js
|
|
11933
|
+
var inspect = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
11934
|
+
var symbol = /* @__PURE__ */ Symbol.for("@multiformats/multiaddr");
|
|
11935
|
+
function toComponents(addr) {
|
|
11936
|
+
if (addr == null) {
|
|
11937
|
+
addr = "/";
|
|
11938
|
+
}
|
|
11939
|
+
if (isMultiaddr(addr)) {
|
|
11940
|
+
return addr.getComponents();
|
|
11941
|
+
}
|
|
11942
|
+
if (addr instanceof Uint8Array) {
|
|
11943
|
+
return bytesToComponents(addr);
|
|
11944
|
+
}
|
|
11945
|
+
if (typeof addr === "string") {
|
|
11946
|
+
addr = addr.replace(/\/(\/)+/, "/").replace(/(\/)+$/, "");
|
|
11947
|
+
if (addr === "") {
|
|
11948
|
+
addr = "/";
|
|
11949
|
+
}
|
|
11950
|
+
return stringToComponents(addr);
|
|
11951
|
+
}
|
|
11952
|
+
if (Array.isArray(addr)) {
|
|
11953
|
+
return addr;
|
|
11954
|
+
}
|
|
11955
|
+
throw new InvalidMultiaddrError("Must be a string, Uint8Array, Component[], or another Multiaddr");
|
|
11956
|
+
}
|
|
11957
|
+
var _a2, _components, _string, _bytes;
|
|
11958
|
+
var _Multiaddr = class _Multiaddr {
|
|
11959
|
+
constructor(addr = "/", options2 = {}) {
|
|
11960
|
+
__publicField(this, _a2, true);
|
|
11961
|
+
__privateAdd(this, _components);
|
|
11962
|
+
// cache string representation
|
|
11963
|
+
__privateAdd(this, _string);
|
|
11964
|
+
// cache byte representation
|
|
11965
|
+
__privateAdd(this, _bytes);
|
|
11966
|
+
__privateSet(this, _components, toComponents(addr));
|
|
11967
|
+
if (options2.validate !== false) {
|
|
11968
|
+
validate2(this);
|
|
11969
|
+
}
|
|
11970
|
+
}
|
|
11971
|
+
get bytes() {
|
|
11972
|
+
if (__privateGet(this, _bytes) == null) {
|
|
11973
|
+
__privateSet(this, _bytes, componentsToBytes(__privateGet(this, _components)));
|
|
11974
|
+
}
|
|
11975
|
+
return __privateGet(this, _bytes);
|
|
11976
|
+
}
|
|
11977
|
+
toString() {
|
|
11978
|
+
if (__privateGet(this, _string) == null) {
|
|
11979
|
+
__privateSet(this, _string, componentsToString(__privateGet(this, _components)));
|
|
11980
|
+
}
|
|
11981
|
+
return __privateGet(this, _string);
|
|
11982
|
+
}
|
|
11983
|
+
toJSON() {
|
|
11984
|
+
return this.toString();
|
|
11985
|
+
}
|
|
11986
|
+
getComponents() {
|
|
11987
|
+
return [
|
|
11988
|
+
...__privateGet(this, _components).map((c) => ({ ...c }))
|
|
11989
|
+
];
|
|
11990
|
+
}
|
|
11991
|
+
encapsulate(addr) {
|
|
11992
|
+
const ma = new _Multiaddr(addr);
|
|
11993
|
+
return new _Multiaddr([
|
|
11994
|
+
...__privateGet(this, _components),
|
|
11995
|
+
...ma.getComponents()
|
|
11996
|
+
], {
|
|
11997
|
+
validate: false
|
|
11998
|
+
});
|
|
11999
|
+
}
|
|
12000
|
+
decapsulate(addr) {
|
|
12001
|
+
const addrString = addr.toString();
|
|
12002
|
+
const s = this.toString();
|
|
12003
|
+
const i = s.lastIndexOf(addrString);
|
|
12004
|
+
if (i < 0) {
|
|
12005
|
+
throw new InvalidParametersError(`Address ${this.toString()} does not contain subaddress: ${addrString}`);
|
|
12006
|
+
}
|
|
12007
|
+
return new _Multiaddr(s.slice(0, i), {
|
|
12008
|
+
validate: false
|
|
12009
|
+
});
|
|
12010
|
+
}
|
|
12011
|
+
decapsulateCode(code2) {
|
|
12012
|
+
let index;
|
|
12013
|
+
for (let i = __privateGet(this, _components).length - 1; i > -1; i--) {
|
|
12014
|
+
if (__privateGet(this, _components)[i].code === code2) {
|
|
12015
|
+
index = i;
|
|
12016
|
+
break;
|
|
12017
|
+
}
|
|
12018
|
+
}
|
|
12019
|
+
return new _Multiaddr(__privateGet(this, _components).slice(0, index), {
|
|
12020
|
+
validate: false
|
|
12021
|
+
});
|
|
12022
|
+
}
|
|
12023
|
+
equals(addr) {
|
|
12024
|
+
return equals3(this.bytes, addr.bytes);
|
|
12025
|
+
}
|
|
12026
|
+
/**
|
|
12027
|
+
* Returns Multiaddr as a human-readable string
|
|
12028
|
+
* https://nodejs.org/api/util.html#utilinspectcustom
|
|
12029
|
+
*
|
|
12030
|
+
* @example
|
|
12031
|
+
* ```js
|
|
12032
|
+
* import { multiaddr } from '@multiformats/multiaddr'
|
|
12033
|
+
*
|
|
12034
|
+
* console.info(multiaddr('/ip4/127.0.0.1/tcp/4001'))
|
|
12035
|
+
* // 'Multiaddr(/ip4/127.0.0.1/tcp/4001)'
|
|
12036
|
+
* ```
|
|
12037
|
+
*/
|
|
12038
|
+
[(_a2 = symbol, inspect)]() {
|
|
12039
|
+
return `Multiaddr(${this.toString()})`;
|
|
12040
|
+
}
|
|
12041
|
+
};
|
|
12042
|
+
_components = new WeakMap();
|
|
12043
|
+
_string = new WeakMap();
|
|
12044
|
+
_bytes = new WeakMap();
|
|
12045
|
+
var Multiaddr = _Multiaddr;
|
|
12046
|
+
function validate2(addr) {
|
|
12047
|
+
addr.getComponents().forEach((component) => {
|
|
12048
|
+
const codec = registry.getProtocol(component.code);
|
|
12049
|
+
if (component.value == null) {
|
|
12050
|
+
return;
|
|
12051
|
+
}
|
|
12052
|
+
codec.validate?.(component.value);
|
|
12053
|
+
});
|
|
12054
|
+
}
|
|
12055
|
+
|
|
12056
|
+
// ../../node_modules/@multiformats/multiaddr/dist/src/index.js
|
|
12057
|
+
function isMultiaddr(value) {
|
|
12058
|
+
return Boolean(value?.[symbol]);
|
|
12059
|
+
}
|
|
12060
|
+
function multiaddr(addr) {
|
|
12061
|
+
return new Multiaddr(addr);
|
|
12062
|
+
}
|
|
12063
|
+
|
|
12064
|
+
// ../../node_modules/@multiformats/multiaddr-to-uri/dist/src/index.js
|
|
12065
|
+
var ASSUME_HTTP_CODES = [
|
|
12066
|
+
CODE_TCP,
|
|
12067
|
+
CODE_DNS,
|
|
12068
|
+
CODE_DNSADDR,
|
|
12069
|
+
CODE_DNS4,
|
|
12070
|
+
CODE_DNS6
|
|
12071
|
+
];
|
|
12072
|
+
function extractSNI(ma) {
|
|
12073
|
+
return extractTuple("sni", ma)?.value;
|
|
12074
|
+
}
|
|
12075
|
+
function extractPort(ma) {
|
|
12076
|
+
const port = extractTuple("tcp", ma)?.value;
|
|
12077
|
+
if (port == null) {
|
|
12078
|
+
return "";
|
|
12079
|
+
}
|
|
12080
|
+
return `:${port}`;
|
|
12081
|
+
}
|
|
12082
|
+
function extractTuple(name2, ma) {
|
|
12083
|
+
return ma.find((component) => component.name === name2);
|
|
12084
|
+
}
|
|
12085
|
+
function hasTLS(ma) {
|
|
12086
|
+
return ma.some(({ code: code2 }) => code2 === CODE_TLS);
|
|
12087
|
+
}
|
|
12088
|
+
function interpretNext(head, rest) {
|
|
12089
|
+
const interpreter = interpreters[head.name];
|
|
12090
|
+
if (interpreter == null) {
|
|
12091
|
+
throw new Error(`Can't interpret protocol ${head.name}`);
|
|
12092
|
+
}
|
|
12093
|
+
const restVal = interpreter(head, rest);
|
|
12094
|
+
if (head.code === CODE_IP6) {
|
|
12095
|
+
return `[${restVal}]`;
|
|
12096
|
+
}
|
|
12097
|
+
return restVal;
|
|
12098
|
+
}
|
|
12099
|
+
var interpreters = {
|
|
12100
|
+
ip4: (head, rest) => head.value,
|
|
12101
|
+
ip6: (head, rest) => {
|
|
12102
|
+
if (rest.length === 0) {
|
|
12103
|
+
return head.value;
|
|
12104
|
+
}
|
|
12105
|
+
return `[${head.value}]`;
|
|
12106
|
+
},
|
|
12107
|
+
tcp: (head, rest) => {
|
|
12108
|
+
const tail = rest.pop();
|
|
12109
|
+
if (tail == null) {
|
|
12110
|
+
throw new Error("Unexpected end of multiaddr");
|
|
12111
|
+
}
|
|
12112
|
+
return `tcp://${interpretNext(tail, rest)}:${head.value}`;
|
|
12113
|
+
},
|
|
12114
|
+
udp: (head, rest) => {
|
|
12115
|
+
const tail = rest.pop();
|
|
12116
|
+
if (tail == null) {
|
|
12117
|
+
throw new Error("Unexpected end of multiaddr");
|
|
12118
|
+
}
|
|
12119
|
+
return `udp://${interpretNext(tail, rest)}:${head.value}`;
|
|
12120
|
+
},
|
|
12121
|
+
dnsaddr: (head, rest) => head.value,
|
|
12122
|
+
dns4: (head, rest) => head.value,
|
|
12123
|
+
dns6: (head, rest) => head.value,
|
|
12124
|
+
dns: (head, rest) => head.value,
|
|
12125
|
+
ipfs: (head, rest) => {
|
|
12126
|
+
const tail = rest.pop();
|
|
12127
|
+
if (tail == null) {
|
|
12128
|
+
throw new Error("Unexpected end of multiaddr");
|
|
12129
|
+
}
|
|
12130
|
+
return `${interpretNext(tail, rest)}`;
|
|
12131
|
+
},
|
|
12132
|
+
p2p: (head, rest) => {
|
|
12133
|
+
const tail = rest.pop();
|
|
12134
|
+
if (tail == null) {
|
|
12135
|
+
throw new Error("Unexpected end of multiaddr");
|
|
12136
|
+
}
|
|
12137
|
+
return `${interpretNext(tail, rest)}`;
|
|
12138
|
+
},
|
|
12139
|
+
http: (head, rest) => {
|
|
12140
|
+
const maHasTLS = hasTLS(rest);
|
|
12141
|
+
const sni = extractSNI(rest);
|
|
12142
|
+
const port = extractPort(rest);
|
|
12143
|
+
if (maHasTLS && sni != null) {
|
|
12144
|
+
return `https://${sni}${port}`;
|
|
12145
|
+
}
|
|
12146
|
+
const protocol = maHasTLS ? "https://" : "http://";
|
|
12147
|
+
const tail = rest.pop();
|
|
12148
|
+
if (tail == null) {
|
|
12149
|
+
throw new Error("Unexpected end of multiaddr");
|
|
12150
|
+
}
|
|
12151
|
+
let baseVal = interpretNext(tail, rest);
|
|
12152
|
+
baseVal = baseVal?.replace("tcp://", "");
|
|
12153
|
+
return `${protocol}${baseVal}`;
|
|
12154
|
+
},
|
|
12155
|
+
"http-path": (head, rest) => {
|
|
12156
|
+
const tail = rest.pop();
|
|
12157
|
+
if (tail == null) {
|
|
12158
|
+
throw new Error("Unexpected end of multiaddr");
|
|
12159
|
+
}
|
|
12160
|
+
const baseVal = interpretNext(tail, rest);
|
|
12161
|
+
const decodedValue = decodeURIComponent(head.value ?? "");
|
|
12162
|
+
return `${baseVal}${decodedValue}`;
|
|
12163
|
+
},
|
|
12164
|
+
tls: (head, rest) => {
|
|
12165
|
+
const tail = rest.pop();
|
|
12166
|
+
if (tail == null) {
|
|
12167
|
+
throw new Error("Unexpected end of multiaddr");
|
|
12168
|
+
}
|
|
12169
|
+
return interpretNext(tail, rest);
|
|
12170
|
+
},
|
|
12171
|
+
sni: (head, rest) => {
|
|
12172
|
+
const tail = rest.pop();
|
|
12173
|
+
if (tail == null) {
|
|
12174
|
+
throw new Error("Unexpected end of multiaddr");
|
|
12175
|
+
}
|
|
12176
|
+
return interpretNext(tail, rest);
|
|
12177
|
+
},
|
|
12178
|
+
https: (head, rest) => {
|
|
12179
|
+
const tail = rest.pop();
|
|
12180
|
+
if (tail == null) {
|
|
12181
|
+
throw new Error("Unexpected end of multiaddr");
|
|
12182
|
+
}
|
|
12183
|
+
let baseVal = interpretNext(tail, rest);
|
|
12184
|
+
baseVal = baseVal?.replace("tcp://", "");
|
|
12185
|
+
return `https://${baseVal}`;
|
|
12186
|
+
},
|
|
12187
|
+
ws: (head, rest) => {
|
|
12188
|
+
const maHasTLS = hasTLS(rest);
|
|
12189
|
+
const sni = extractSNI(rest);
|
|
12190
|
+
const port = extractPort(rest);
|
|
12191
|
+
if (maHasTLS && sni != null) {
|
|
12192
|
+
return `wss://${sni}${port}`;
|
|
12193
|
+
}
|
|
12194
|
+
const protocol = maHasTLS ? "wss://" : "ws://";
|
|
12195
|
+
const tail = rest.pop();
|
|
12196
|
+
if (tail == null) {
|
|
12197
|
+
throw new Error("Unexpected end of multiaddr");
|
|
12198
|
+
}
|
|
12199
|
+
let baseVal = interpretNext(tail, rest);
|
|
12200
|
+
baseVal = baseVal?.replace("tcp://", "");
|
|
12201
|
+
return `${protocol}${baseVal}`;
|
|
12202
|
+
},
|
|
12203
|
+
wss: (head, rest) => {
|
|
12204
|
+
const tail = rest.pop();
|
|
12205
|
+
if (tail == null) {
|
|
12206
|
+
throw new Error("Unexpected end of multiaddr");
|
|
12207
|
+
}
|
|
12208
|
+
let baseVal = interpretNext(tail, rest);
|
|
12209
|
+
baseVal = baseVal?.replace("tcp://", "");
|
|
12210
|
+
return `wss://${baseVal}`;
|
|
12211
|
+
}
|
|
12212
|
+
};
|
|
12213
|
+
function multiaddrToUri(input, opts) {
|
|
12214
|
+
const ma = multiaddr(input);
|
|
12215
|
+
const components = ma.getComponents();
|
|
12216
|
+
const head = components.pop();
|
|
12217
|
+
if (head == null) {
|
|
12218
|
+
throw new Error("Unexpected end of multiaddr");
|
|
12219
|
+
}
|
|
12220
|
+
const interpreter = interpreters[head.name];
|
|
12221
|
+
if (interpreter == null) {
|
|
12222
|
+
throw new Error(`No interpreter found for ${head.name}`);
|
|
12223
|
+
}
|
|
12224
|
+
let uri = interpreter(head, components) ?? "";
|
|
12225
|
+
if (opts?.assumeHttp !== false && ASSUME_HTTP_CODES.includes(head.code)) {
|
|
12226
|
+
uri = uri.replace(/^.*:\/\//, "");
|
|
12227
|
+
if (head.value === "443") {
|
|
12228
|
+
uri = `https://${uri}`;
|
|
12229
|
+
} else {
|
|
12230
|
+
uri = `http://${uri}`;
|
|
12231
|
+
}
|
|
12232
|
+
}
|
|
12233
|
+
if (uri.startsWith("http://") || uri.startsWith("https://") || uri.startsWith("ws://") || uri.startsWith("wss://")) {
|
|
12234
|
+
uri = new URL(uri).toString();
|
|
12235
|
+
if (uri.endsWith("/")) {
|
|
12236
|
+
uri = uri.substring(0, uri.length - 1);
|
|
12237
|
+
}
|
|
12238
|
+
}
|
|
12239
|
+
return uri;
|
|
12240
|
+
}
|
|
12241
|
+
|
|
12242
|
+
// ../../node_modules/ip-regex/index.js
|
|
12243
|
+
var word = "[a-fA-F\\d:]";
|
|
12244
|
+
var boundry = (options2) => options2 && options2.includeBoundaries ? `(?:(?<=\\s|^)(?=${word})|(?<=${word})(?=\\s|$))` : "";
|
|
12245
|
+
var v4 = "(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}";
|
|
12246
|
+
var v6segment = "[a-fA-F\\d]{1,4}";
|
|
12247
|
+
var v6 = `
|
|
12248
|
+
(?:
|
|
12249
|
+
(?:${v6segment}:){7}(?:${v6segment}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
|
|
12250
|
+
(?:${v6segment}:){6}(?:${v4}|:${v6segment}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4
|
|
12251
|
+
(?:${v6segment}:){5}(?::${v4}|(?::${v6segment}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4
|
|
12252
|
+
(?:${v6segment}:){4}(?:(?::${v6segment}){0,1}:${v4}|(?::${v6segment}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4
|
|
12253
|
+
(?:${v6segment}:){3}(?:(?::${v6segment}){0,2}:${v4}|(?::${v6segment}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4
|
|
12254
|
+
(?:${v6segment}:){2}(?:(?::${v6segment}){0,3}:${v4}|(?::${v6segment}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
|
|
12255
|
+
(?:${v6segment}:){1}(?:(?::${v6segment}){0,4}:${v4}|(?::${v6segment}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
|
|
12256
|
+
(?::(?:(?::${v6segment}){0,5}:${v4}|(?::${v6segment}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
|
|
12257
|
+
)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
|
|
12258
|
+
`.replace(/\s*\/\/.*$/gm, "").replace(/\n/g, "").trim();
|
|
12259
|
+
var v46Exact = new RegExp(`(?:^${v4}$)|(?:^${v6}$)`);
|
|
12260
|
+
var v4exact = new RegExp(`^${v4}$`);
|
|
12261
|
+
var v6exact = new RegExp(`^${v6}$`);
|
|
12262
|
+
var ipRegex = (options2) => options2 && options2.exact ? v46Exact : new RegExp(`(?:${boundry(options2)}${v4}${boundry(options2)})|(?:${boundry(options2)}${v6}${boundry(options2)})`, "g");
|
|
12263
|
+
ipRegex.v4 = (options2) => options2 && options2.exact ? v4exact : new RegExp(`${boundry(options2)}${v4}${boundry(options2)}`, "g");
|
|
12264
|
+
ipRegex.v6 = (options2) => options2 && options2.exact ? v6exact : new RegExp(`${boundry(options2)}${v6}${boundry(options2)}`, "g");
|
|
12265
|
+
var ip_regex_default = ipRegex;
|
|
12266
|
+
|
|
12267
|
+
// ../../node_modules/function-timeout/index.js
|
|
12268
|
+
var import_node_vm = __toESM(require("vm"), 1);
|
|
12269
|
+
function functionTimeout(function_, { timeout } = {}) {
|
|
12270
|
+
const script = new import_node_vm.default.Script("returnValue = function_()");
|
|
12271
|
+
const wrappedFunction = (...arguments_) => {
|
|
12272
|
+
const context = {
|
|
12273
|
+
function_: () => function_(...arguments_)
|
|
12274
|
+
};
|
|
12275
|
+
script.runInNewContext(context, { timeout });
|
|
12276
|
+
return context.returnValue;
|
|
12277
|
+
};
|
|
12278
|
+
Object.defineProperty(wrappedFunction, "name", {
|
|
12279
|
+
value: `functionTimeout(${function_.name || "<anonymous>"})`,
|
|
12280
|
+
configurable: true
|
|
12281
|
+
});
|
|
12282
|
+
return wrappedFunction;
|
|
12283
|
+
}
|
|
12284
|
+
function isTimeoutError(error) {
|
|
12285
|
+
return error?.code === "ERR_SCRIPT_EXECUTION_TIMEOUT";
|
|
12286
|
+
}
|
|
12287
|
+
|
|
12288
|
+
// ../../node_modules/clone-regexp/node_modules/is-regexp/index.js
|
|
12289
|
+
var { toString: toString3 } = Object.prototype;
|
|
12290
|
+
function isRegexp(value) {
|
|
12291
|
+
return toString3.call(value) === "[object RegExp]";
|
|
12292
|
+
}
|
|
12293
|
+
|
|
12294
|
+
// ../../node_modules/clone-regexp/index.js
|
|
12295
|
+
var flagMap = {
|
|
12296
|
+
global: "g",
|
|
12297
|
+
ignoreCase: "i",
|
|
12298
|
+
multiline: "m",
|
|
12299
|
+
dotAll: "s",
|
|
12300
|
+
sticky: "y",
|
|
12301
|
+
unicode: "u"
|
|
12302
|
+
};
|
|
12303
|
+
function clonedRegexp(regexp, options2 = {}) {
|
|
12304
|
+
if (!isRegexp(regexp)) {
|
|
12305
|
+
throw new TypeError("Expected a RegExp instance");
|
|
12306
|
+
}
|
|
12307
|
+
const flags = Object.keys(flagMap).map((flag) => (typeof options2[flag] === "boolean" ? options2[flag] : regexp[flag]) ? flagMap[flag] : "").join("");
|
|
12308
|
+
const clonedRegexp2 = new RegExp(options2.source || regexp.source, flags);
|
|
12309
|
+
clonedRegexp2.lastIndex = typeof options2.lastIndex === "number" ? options2.lastIndex : regexp.lastIndex;
|
|
12310
|
+
return clonedRegexp2;
|
|
12311
|
+
}
|
|
12312
|
+
|
|
12313
|
+
// ../../node_modules/super-regex/index.js
|
|
12314
|
+
function isMatch(regex, string2, { timeout } = {}) {
|
|
12315
|
+
try {
|
|
12316
|
+
return functionTimeout(() => clonedRegexp(regex).test(string2), { timeout })();
|
|
12317
|
+
} catch (error) {
|
|
12318
|
+
if (isTimeoutError(error)) {
|
|
12319
|
+
return false;
|
|
12320
|
+
}
|
|
12321
|
+
throw error;
|
|
12322
|
+
}
|
|
12323
|
+
}
|
|
12324
|
+
|
|
12325
|
+
// ../../node_modules/is-ip/index.js
|
|
12326
|
+
var maxIPv4Length = 15;
|
|
12327
|
+
var maxIPv6Length = 45;
|
|
12328
|
+
var options = {
|
|
12329
|
+
timeout: 400
|
|
12330
|
+
};
|
|
12331
|
+
function isIPv62(string2) {
|
|
12332
|
+
if (string2.length > maxIPv6Length) {
|
|
12333
|
+
return false;
|
|
12334
|
+
}
|
|
12335
|
+
return isMatch(ip_regex_default.v6({ exact: true }), string2, options);
|
|
12336
|
+
}
|
|
12337
|
+
function isIPv42(string2) {
|
|
12338
|
+
if (string2.length > maxIPv4Length) {
|
|
12339
|
+
return false;
|
|
12340
|
+
}
|
|
12341
|
+
return isMatch(ip_regex_default.v4({ exact: true }), string2, options);
|
|
12342
|
+
}
|
|
12343
|
+
|
|
12344
|
+
// ../../node_modules/@multiformats/uri-to-multiaddr/dist/src/index.js
|
|
12345
|
+
var portFor = {
|
|
12346
|
+
http: "80",
|
|
12347
|
+
https: "443",
|
|
12348
|
+
ws: "80",
|
|
12349
|
+
wss: "443"
|
|
12350
|
+
};
|
|
12351
|
+
var BROWSER_SCHEMES = ["http", "https", "ws", "wss"];
|
|
12352
|
+
function uriToMultiaddr(uriStr, opts) {
|
|
12353
|
+
opts = opts ?? {};
|
|
12354
|
+
const defaultDnsType = opts.defaultDnsType ?? "dns";
|
|
12355
|
+
const { scheme, hostname, port, path } = parseUri(uriStr);
|
|
12356
|
+
const parts = [
|
|
12357
|
+
tupleForHostname(hostname, defaultDnsType),
|
|
12358
|
+
tupleForPort(port, scheme),
|
|
12359
|
+
tupleForScheme(scheme)
|
|
12360
|
+
];
|
|
12361
|
+
if (path != null) {
|
|
12362
|
+
parts.push(tupleForPath(path));
|
|
12363
|
+
}
|
|
12364
|
+
const multiaddrStr = "/" + parts.filter((x) => Boolean(x)).reduce((a, b) => a.concat(b), []).join("/");
|
|
12365
|
+
return multiaddr(multiaddrStr);
|
|
12366
|
+
}
|
|
12367
|
+
function parseUri(uriStr) {
|
|
12368
|
+
const [scheme] = uriStr.split(":");
|
|
12369
|
+
if (!BROWSER_SCHEMES.includes(scheme)) {
|
|
12370
|
+
uriStr = "http" + uriStr.substring(scheme.length);
|
|
12371
|
+
}
|
|
12372
|
+
let { protocol, hostname, port, pathname, search } = new URL(uriStr);
|
|
12373
|
+
if (port == null || port === "") {
|
|
12374
|
+
const protocolPort = portForProtocol(scheme);
|
|
12375
|
+
if (protocolPort != null) {
|
|
12376
|
+
port = protocolPort;
|
|
12377
|
+
}
|
|
12378
|
+
if (protocolPort == null && protocol === "http:") {
|
|
12379
|
+
port = "80";
|
|
12380
|
+
}
|
|
12381
|
+
}
|
|
12382
|
+
let path;
|
|
12383
|
+
if (pathname != null && pathname !== "" && pathname !== "/") {
|
|
12384
|
+
if (pathname.startsWith("/")) {
|
|
12385
|
+
pathname = pathname.substring(1);
|
|
12386
|
+
}
|
|
12387
|
+
path = pathname;
|
|
12388
|
+
}
|
|
12389
|
+
if (search != null && search !== "") {
|
|
12390
|
+
path = path ?? "";
|
|
12391
|
+
path += search;
|
|
12392
|
+
}
|
|
12393
|
+
return { scheme, hostname, port, path };
|
|
12394
|
+
}
|
|
12395
|
+
function tupleForHostname(hostname, defaultDnsType) {
|
|
12396
|
+
if (hostname == null || hostname === "") {
|
|
12397
|
+
return void 0;
|
|
12398
|
+
}
|
|
12399
|
+
if (isIPv42(hostname)) {
|
|
12400
|
+
return ["ip4", hostname];
|
|
12401
|
+
}
|
|
12402
|
+
if (isIPv62(hostname)) {
|
|
12403
|
+
return ["ip6", hostname];
|
|
12404
|
+
}
|
|
12405
|
+
if (hostname[0] === "[") {
|
|
12406
|
+
const trimmed = hostname.substring(1, hostname.length - 1);
|
|
12407
|
+
if (isIPv62(trimmed)) {
|
|
12408
|
+
return ["ip6", trimmed];
|
|
12409
|
+
}
|
|
12410
|
+
}
|
|
12411
|
+
return [defaultDnsType, hostname];
|
|
12412
|
+
}
|
|
12413
|
+
function tupleForPort(port, scheme) {
|
|
12414
|
+
if (port == null || port === "") {
|
|
12415
|
+
return void 0;
|
|
12416
|
+
}
|
|
12417
|
+
if (scheme === "udp") {
|
|
12418
|
+
return ["udp", port];
|
|
12419
|
+
}
|
|
12420
|
+
return ["tcp", port];
|
|
12421
|
+
}
|
|
12422
|
+
function tupleForScheme(scheme) {
|
|
12423
|
+
if (scheme.match(/^tcp$|^udp$/) != null) {
|
|
12424
|
+
return void 0;
|
|
12425
|
+
}
|
|
12426
|
+
if (scheme === "https") {
|
|
12427
|
+
return ["/tls/http"];
|
|
12428
|
+
}
|
|
12429
|
+
if (scheme === "wss") {
|
|
12430
|
+
return ["/tls/ws"];
|
|
12431
|
+
}
|
|
12432
|
+
return [scheme];
|
|
12433
|
+
}
|
|
12434
|
+
function tupleForPath(path) {
|
|
12435
|
+
if (path == null || path === "") {
|
|
12436
|
+
return void 0;
|
|
12437
|
+
}
|
|
12438
|
+
return ["http-path", encodeURIComponent(path)];
|
|
12439
|
+
}
|
|
12440
|
+
function portForProtocol(protocol) {
|
|
12441
|
+
if (protocol == null || protocol === "" || portFor[protocol] == null) {
|
|
12442
|
+
return void 0;
|
|
12443
|
+
}
|
|
12444
|
+
return portFor[protocol];
|
|
12445
|
+
}
|
|
12446
|
+
|
|
9534
12447
|
// src/location.ts
|
|
9535
|
-
var import_multiaddr = require("@multiformats/multiaddr");
|
|
9536
|
-
var import_multiaddr_to_uri = require("@multiformats/multiaddr-to-uri");
|
|
9537
|
-
var import_uri_to_multiaddr = require("@multiformats/uri-to-multiaddr");
|
|
9538
12448
|
var import_ed255193 = require("@noble/curves/ed25519");
|
|
9539
|
-
var import_basics3 = require("multiformats/basics");
|
|
9540
12449
|
var import_viem5 = require("viem");
|
|
9541
12450
|
var DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL = "https://registry.tinycloud.xyz";
|
|
9542
12451
|
var DEFAULT_TINYCLOUD_FALLBACK_HOST = "https://node.tinycloud.xyz";
|
|
@@ -9643,14 +12552,14 @@ async function fetchLocationRecord(registryUrl, subject, fetchFn = globalThis.fe
|
|
|
9643
12552
|
}
|
|
9644
12553
|
return validateLocationRecord(body.record);
|
|
9645
12554
|
}
|
|
9646
|
-
async function resolveCloudLocation(subject,
|
|
12555
|
+
async function resolveCloudLocation(subject, options2 = {}) {
|
|
9647
12556
|
validateSubject(subject);
|
|
9648
|
-
const verifyRecords =
|
|
12557
|
+
const verifyRecords = options2.verifyRecords ?? true;
|
|
9649
12558
|
const attempts = await Promise.all([
|
|
9650
|
-
resolveExplicit(subject,
|
|
9651
|
-
resolveBlockchain(subject,
|
|
9652
|
-
resolveCentralized(subject,
|
|
9653
|
-
resolveFallback(subject,
|
|
12559
|
+
resolveExplicit(subject, options2.explicitMultiaddrs),
|
|
12560
|
+
resolveBlockchain(subject, options2.blockchain, verifyRecords),
|
|
12561
|
+
resolveCentralized(subject, options2, verifyRecords),
|
|
12562
|
+
resolveFallback(subject, options2.fallbackMultiaddrs)
|
|
9654
12563
|
]);
|
|
9655
12564
|
const winner = attempts.find((attempt) => attempt.candidate)?.candidate;
|
|
9656
12565
|
if (!winner) {
|
|
@@ -9665,16 +12574,16 @@ async function resolveCloudLocation(subject, options = {}) {
|
|
|
9665
12574
|
resolvedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
9666
12575
|
};
|
|
9667
12576
|
}
|
|
9668
|
-
async function resolveTinyCloudHosts(subject,
|
|
12577
|
+
async function resolveTinyCloudHosts(subject, options2 = {}) {
|
|
9669
12578
|
const location = await resolveCloudLocation(subject, {
|
|
9670
|
-
explicitMultiaddrs: hostsToMultiaddrs(
|
|
9671
|
-
blockchain:
|
|
9672
|
-
centralizedRegistryUrl:
|
|
12579
|
+
explicitMultiaddrs: hostsToMultiaddrs(options2.explicitHosts),
|
|
12580
|
+
blockchain: options2.blockchain,
|
|
12581
|
+
centralizedRegistryUrl: options2.registryUrl === null ? void 0 : options2.registryUrl ?? DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL,
|
|
9673
12582
|
fallbackMultiaddrs: hostsToMultiaddrs(
|
|
9674
|
-
|
|
12583
|
+
options2.fallbackHosts === null ? void 0 : options2.fallbackHosts ?? [DEFAULT_TINYCLOUD_FALLBACK_HOST]
|
|
9675
12584
|
),
|
|
9676
|
-
fetch:
|
|
9677
|
-
verifyRecords:
|
|
12585
|
+
fetch: options2.fetch,
|
|
12586
|
+
verifyRecords: options2.verifyRecords
|
|
9678
12587
|
});
|
|
9679
12588
|
return {
|
|
9680
12589
|
hosts: location.multiaddrs.map((addr) => multiaddrToHttpUrl(addr)),
|
|
@@ -9682,7 +12591,7 @@ async function resolveTinyCloudHosts(subject, options = {}) {
|
|
|
9682
12591
|
};
|
|
9683
12592
|
}
|
|
9684
12593
|
function multiaddrToHttpUrl(input) {
|
|
9685
|
-
const uri =
|
|
12594
|
+
const uri = multiaddrToUri(multiaddr(input));
|
|
9686
12595
|
if (!uri.startsWith("http://") && !uri.startsWith("https://")) {
|
|
9687
12596
|
throw new LocationRecordValidationError(
|
|
9688
12597
|
`multiaddr does not resolve to http/https: ${input}`
|
|
@@ -9695,7 +12604,7 @@ function httpUrlToMultiaddr(input) {
|
|
|
9695
12604
|
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
9696
12605
|
throw new LocationRecordValidationError("URL must use http or https");
|
|
9697
12606
|
}
|
|
9698
|
-
return
|
|
12607
|
+
return uriToMultiaddr(url.toString()).toString();
|
|
9699
12608
|
}
|
|
9700
12609
|
function hostsToMultiaddrs(hosts) {
|
|
9701
12610
|
if (hosts === void 0 || hosts.length === 0) {
|
|
@@ -9726,15 +12635,15 @@ async function resolveBlockchain(subject, resolver, verifyRecords) {
|
|
|
9726
12635
|
);
|
|
9727
12636
|
});
|
|
9728
12637
|
}
|
|
9729
|
-
async function resolveCentralized(subject,
|
|
12638
|
+
async function resolveCentralized(subject, options2, verifyRecords) {
|
|
9730
12639
|
return resolveAttempt("centralized", async () => {
|
|
9731
|
-
if (!
|
|
12640
|
+
if (!options2.centralizedRegistryUrl) {
|
|
9732
12641
|
return null;
|
|
9733
12642
|
}
|
|
9734
12643
|
const record = await fetchLocationRecord(
|
|
9735
|
-
|
|
12644
|
+
options2.centralizedRegistryUrl,
|
|
9736
12645
|
subject,
|
|
9737
|
-
|
|
12646
|
+
options2.fetch
|
|
9738
12647
|
);
|
|
9739
12648
|
return toCandidate(subject, "centralized", record, verifyRecords);
|
|
9740
12649
|
});
|
|
@@ -9827,7 +12736,7 @@ function validateMultiaddrs(input) {
|
|
|
9827
12736
|
);
|
|
9828
12737
|
}
|
|
9829
12738
|
try {
|
|
9830
|
-
|
|
12739
|
+
multiaddr(addr);
|
|
9831
12740
|
} catch {
|
|
9832
12741
|
throw new LocationRecordValidationError(`invalid multiaddr: ${addr}`);
|
|
9833
12742
|
}
|
|
@@ -9874,7 +12783,7 @@ function ed25519PublicKeyFromDidKey2(did) {
|
|
|
9874
12783
|
"did:key must use base58btc multibase"
|
|
9875
12784
|
);
|
|
9876
12785
|
}
|
|
9877
|
-
const bytes =
|
|
12786
|
+
const bytes = bases.base58btc.decode(identifier);
|
|
9878
12787
|
if (bytes.length === 34 && bytes[0] === 237 && bytes[1] === 1) {
|
|
9879
12788
|
return bytes.slice(2);
|
|
9880
12789
|
}
|
|
@@ -9886,31 +12795,31 @@ function ed25519PublicKeyFromDidKey2(did) {
|
|
|
9886
12795
|
);
|
|
9887
12796
|
}
|
|
9888
12797
|
function base64UrlEncode3(bytes) {
|
|
9889
|
-
const
|
|
12798
|
+
const alphabet2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
9890
12799
|
let output = "";
|
|
9891
12800
|
for (let i = 0; i < bytes.length; i += 3) {
|
|
9892
12801
|
const a = bytes[i];
|
|
9893
12802
|
const b = bytes[i + 1];
|
|
9894
12803
|
const c = bytes[i + 2];
|
|
9895
12804
|
const triplet = a << 16 | (b ?? 0) << 8 | (c ?? 0);
|
|
9896
|
-
output +=
|
|
9897
|
-
output +=
|
|
12805
|
+
output += alphabet2[triplet >> 18 & 63];
|
|
12806
|
+
output += alphabet2[triplet >> 12 & 63];
|
|
9898
12807
|
if (i + 1 < bytes.length) {
|
|
9899
|
-
output +=
|
|
12808
|
+
output += alphabet2[triplet >> 6 & 63];
|
|
9900
12809
|
}
|
|
9901
12810
|
if (i + 2 < bytes.length) {
|
|
9902
|
-
output +=
|
|
12811
|
+
output += alphabet2[triplet & 63];
|
|
9903
12812
|
}
|
|
9904
12813
|
}
|
|
9905
12814
|
return output;
|
|
9906
12815
|
}
|
|
9907
12816
|
function decodeBase64Url(value) {
|
|
9908
|
-
const
|
|
12817
|
+
const alphabet2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
9909
12818
|
const bytes = [];
|
|
9910
12819
|
let buffer = 0;
|
|
9911
12820
|
let bits = 0;
|
|
9912
12821
|
for (const char of value) {
|
|
9913
|
-
const index =
|
|
12822
|
+
const index = alphabet2.indexOf(char);
|
|
9914
12823
|
if (index < 0) {
|
|
9915
12824
|
throw new LocationRecordValidationError(
|
|
9916
12825
|
"did:key signature must be base64url"
|
|
@@ -9946,6 +12855,7 @@ function decodeBase64Url(value) {
|
|
|
9946
12855
|
CAPABILITY_REGISTRY,
|
|
9947
12856
|
CapabilityKeyRegistry,
|
|
9948
12857
|
CapabilityKeyRegistryErrorCodes,
|
|
12858
|
+
CaveatedDelegationUnsupportedError,
|
|
9949
12859
|
ClientSessionSchema,
|
|
9950
12860
|
CloudLocationResolutionError,
|
|
9951
12861
|
DECRYPT_ACTION,
|
|
@@ -9964,6 +12874,7 @@ function decodeBase64Url(value) {
|
|
|
9964
12874
|
DUCKDB,
|
|
9965
12875
|
DataVaultService,
|
|
9966
12876
|
DatabaseHandle,
|
|
12877
|
+
DecryptTransportResponseError,
|
|
9967
12878
|
DelegationErrorCodes,
|
|
9968
12879
|
DelegationManager,
|
|
9969
12880
|
DuckDbAction,
|
|
@@ -10071,6 +12982,7 @@ function decodeBase64Url(value) {
|
|
|
10071
12982
|
canonicalizeDidUrl,
|
|
10072
12983
|
canonicalizeEncryptionJson,
|
|
10073
12984
|
canonicalizeNetworkId,
|
|
12985
|
+
canonicalizeRecapCaveats,
|
|
10074
12986
|
canonicalizeSecretScope,
|
|
10075
12987
|
canonicalizeSignedObjectUnsigned,
|
|
10076
12988
|
checkDecryptInvocationInput,
|
|
@@ -10144,6 +13056,7 @@ function decodeBase64Url(value) {
|
|
|
10144
13056
|
pkhDid,
|
|
10145
13057
|
principalDid,
|
|
10146
13058
|
principalDidEquals,
|
|
13059
|
+
recapCaveatsEqual,
|
|
10147
13060
|
resolveCloudLocation,
|
|
10148
13061
|
resolveManifest,
|
|
10149
13062
|
resolveManifestKnowledgeRoot,
|