@tinycloud/sdk-core 2.7.0-beta.3 → 2.7.0
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-DpdAwc1W.d.cts → capability-BjzXwtNw.d.cts} +3 -2
- package/dist/{capability-DpdAwc1W.d.ts → capability-BjzXwtNw.d.ts} +3 -2
- package/dist/index.cjs +3100 -352
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +154 -10
- package/dist/index.d.ts +154 -10
- package/dist/index.js +3095 -344
- 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-BHkLbCXI.d.ts → signed-object-C6mWbTbB.d.ts} +1 -1
- package/dist/{signed-object-CpXNKC4d.d.cts → signed-object-IMAm5a32.d.cts} +1 -1
- package/package.json +6 -3
package/dist/policy/index.js
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name2 in all)
|
|
5
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
6
|
+
};
|
|
7
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
|
+
|
|
1
9
|
// src/policy/errors.ts
|
|
2
10
|
var SignedObjectProfileError = class extends Error {
|
|
3
|
-
constructor(
|
|
11
|
+
constructor(code2, message) {
|
|
4
12
|
super(message);
|
|
5
13
|
this.name = "SignedObjectProfileError";
|
|
6
|
-
this.code =
|
|
14
|
+
this.code = code2;
|
|
7
15
|
}
|
|
8
16
|
};
|
|
9
17
|
var SignedObjectSchemaError = class extends SignedObjectProfileError {
|
|
@@ -201,35 +209,33 @@ function assertNoSymbolKeys(input, path) {
|
|
|
201
209
|
);
|
|
202
210
|
}
|
|
203
211
|
}
|
|
204
|
-
function isArrayIndexKey(key,
|
|
212
|
+
function isArrayIndexKey(key, length2) {
|
|
205
213
|
if (!/^(0|[1-9]\d*)$/.test(key)) {
|
|
206
214
|
return false;
|
|
207
215
|
}
|
|
208
216
|
const index = Number(key);
|
|
209
|
-
return Number.isSafeInteger(index) && index >= 0 && index <
|
|
217
|
+
return Number.isSafeInteger(index) && index >= 0 && index < length2;
|
|
210
218
|
}
|
|
211
219
|
function serializeObject(value) {
|
|
212
|
-
const keys = Object.keys(value).sort(
|
|
220
|
+
const keys = Object.keys(value).sort(compareUtf16CodeUnits);
|
|
213
221
|
const parts = keys.map((key) => `${JSON.stringify(key)}:${serialize(value[key])}`);
|
|
214
222
|
return `{${parts.join(",")}}`;
|
|
215
223
|
}
|
|
216
|
-
function
|
|
217
|
-
const
|
|
218
|
-
const right = Array.from(b);
|
|
219
|
-
const max = Math.min(left.length, right.length);
|
|
224
|
+
function compareUtf16CodeUnits(a, b) {
|
|
225
|
+
const max = Math.min(a.length, b.length);
|
|
220
226
|
for (let index = 0; index < max; index++) {
|
|
221
|
-
const
|
|
222
|
-
const
|
|
223
|
-
if (
|
|
224
|
-
return
|
|
227
|
+
const leftCodeUnit = a.charCodeAt(index);
|
|
228
|
+
const rightCodeUnit = b.charCodeAt(index);
|
|
229
|
+
if (leftCodeUnit !== rightCodeUnit) {
|
|
230
|
+
return leftCodeUnit - rightCodeUnit;
|
|
225
231
|
}
|
|
226
232
|
}
|
|
227
|
-
return
|
|
233
|
+
return a.length - b.length;
|
|
228
234
|
}
|
|
229
235
|
function assertUnicodeScalarString(value, path) {
|
|
230
236
|
for (let index = 0; index < value.length; index++) {
|
|
231
|
-
const
|
|
232
|
-
if (
|
|
237
|
+
const code2 = value.charCodeAt(index);
|
|
238
|
+
if (code2 >= 55296 && code2 <= 56319) {
|
|
233
239
|
const next = value.charCodeAt(index + 1);
|
|
234
240
|
if (Number.isNaN(next) || next < 56320 || next > 57343) {
|
|
235
241
|
throw new SignedObjectCanonicalizationError(
|
|
@@ -239,7 +245,7 @@ function assertUnicodeScalarString(value, path) {
|
|
|
239
245
|
index++;
|
|
240
246
|
continue;
|
|
241
247
|
}
|
|
242
|
-
if (
|
|
248
|
+
if (code2 >= 56320 && code2 <= 57343) {
|
|
243
249
|
throw new SignedObjectCanonicalizationError(
|
|
244
250
|
`${path} contains a lone low surrogate`
|
|
245
251
|
);
|
|
@@ -253,10 +259,10 @@ import { bytesToHex, sha256 } from "viem";
|
|
|
253
259
|
var POLICY_CAPABILITY_DOMAIN = "xyz.tinycloud.policy/PolicyCapability/v0";
|
|
254
260
|
var textEncoder = new TextEncoder();
|
|
255
261
|
var PolicyCapabilityError = class extends Error {
|
|
256
|
-
constructor(
|
|
262
|
+
constructor(code2, message) {
|
|
257
263
|
super(message);
|
|
258
264
|
this.name = "PolicyCapabilityError";
|
|
259
|
-
this.code =
|
|
265
|
+
this.code = code2;
|
|
260
266
|
}
|
|
261
267
|
};
|
|
262
268
|
var objectHasOwn2 = Object.hasOwn ?? Object.prototype.hasOwnProperty.call.bind(
|
|
@@ -391,23 +397,23 @@ function assertExactKeys(object, allowed, path) {
|
|
|
391
397
|
}
|
|
392
398
|
}
|
|
393
399
|
}
|
|
394
|
-
function requiredValue(object, key, path,
|
|
400
|
+
function requiredValue(object, key, path, code2) {
|
|
395
401
|
if (!hasOwn(object, key)) {
|
|
396
|
-
throw new PolicyCapabilityError(
|
|
402
|
+
throw new PolicyCapabilityError(code2, `${path}.${key} is required`);
|
|
397
403
|
}
|
|
398
404
|
return object[key];
|
|
399
405
|
}
|
|
400
|
-
function requiredString(object, key, path,
|
|
401
|
-
const value = requiredValue(object, key, path,
|
|
406
|
+
function requiredString(object, key, path, code2) {
|
|
407
|
+
const value = requiredValue(object, key, path, code2);
|
|
402
408
|
if (typeof value !== "string" || value.length === 0) {
|
|
403
|
-
throw new PolicyCapabilityError(
|
|
409
|
+
throw new PolicyCapabilityError(code2, `${path}.${key} must be a non-empty string`);
|
|
404
410
|
}
|
|
405
411
|
return value;
|
|
406
412
|
}
|
|
407
|
-
function requiredArray(object, key, path,
|
|
408
|
-
const value = requiredValue(object, key, path,
|
|
413
|
+
function requiredArray(object, key, path, code2) {
|
|
414
|
+
const value = requiredValue(object, key, path, code2);
|
|
409
415
|
if (!Array.isArray(value)) {
|
|
410
|
-
throw new PolicyCapabilityError(
|
|
416
|
+
throw new PolicyCapabilityError(code2, `${path}.${key} must be an array`);
|
|
411
417
|
}
|
|
412
418
|
return value;
|
|
413
419
|
}
|
|
@@ -638,8 +644,1156 @@ function hasOwn(object, key) {
|
|
|
638
644
|
|
|
639
645
|
// src/policy/signed-object.ts
|
|
640
646
|
import { ed25519 } from "@noble/curves/ed25519";
|
|
641
|
-
|
|
642
|
-
|
|
647
|
+
|
|
648
|
+
// ../../node_modules/multiformats/dist/src/bases/base10.js
|
|
649
|
+
var base10_exports = {};
|
|
650
|
+
__export(base10_exports, {
|
|
651
|
+
base10: () => base10
|
|
652
|
+
});
|
|
653
|
+
|
|
654
|
+
// ../../node_modules/multiformats/dist/src/bytes.js
|
|
655
|
+
var empty = new Uint8Array(0);
|
|
656
|
+
function equals(aa, bb) {
|
|
657
|
+
if (aa === bb) {
|
|
658
|
+
return true;
|
|
659
|
+
}
|
|
660
|
+
if (aa.byteLength !== bb.byteLength) {
|
|
661
|
+
return false;
|
|
662
|
+
}
|
|
663
|
+
for (let ii = 0; ii < aa.byteLength; ii++) {
|
|
664
|
+
if (aa[ii] !== bb[ii]) {
|
|
665
|
+
return false;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
return true;
|
|
669
|
+
}
|
|
670
|
+
function coerce(o) {
|
|
671
|
+
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array") {
|
|
672
|
+
return o;
|
|
673
|
+
}
|
|
674
|
+
if (o instanceof ArrayBuffer) {
|
|
675
|
+
return new Uint8Array(o);
|
|
676
|
+
}
|
|
677
|
+
if (ArrayBuffer.isView(o)) {
|
|
678
|
+
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
|
|
679
|
+
}
|
|
680
|
+
throw new Error("Unknown type, must be binary type");
|
|
681
|
+
}
|
|
682
|
+
function fromString(str) {
|
|
683
|
+
return new TextEncoder().encode(str);
|
|
684
|
+
}
|
|
685
|
+
function toString(b) {
|
|
686
|
+
return new TextDecoder().decode(b);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
// ../../node_modules/multiformats/dist/src/vendor/base-x.js
|
|
690
|
+
function base(ALPHABET, name2) {
|
|
691
|
+
if (ALPHABET.length >= 255) {
|
|
692
|
+
throw new TypeError("Alphabet too long");
|
|
693
|
+
}
|
|
694
|
+
var BASE_MAP = new Uint8Array(256);
|
|
695
|
+
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
696
|
+
BASE_MAP[j] = 255;
|
|
697
|
+
}
|
|
698
|
+
for (var i = 0; i < ALPHABET.length; i++) {
|
|
699
|
+
var x = ALPHABET.charAt(i);
|
|
700
|
+
var xc = x.charCodeAt(0);
|
|
701
|
+
if (BASE_MAP[xc] !== 255) {
|
|
702
|
+
throw new TypeError(x + " is ambiguous");
|
|
703
|
+
}
|
|
704
|
+
BASE_MAP[xc] = i;
|
|
705
|
+
}
|
|
706
|
+
var BASE = ALPHABET.length;
|
|
707
|
+
var LEADER = ALPHABET.charAt(0);
|
|
708
|
+
var FACTOR = Math.log(BASE) / Math.log(256);
|
|
709
|
+
var iFACTOR = Math.log(256) / Math.log(BASE);
|
|
710
|
+
function encode5(source) {
|
|
711
|
+
if (source instanceof Uint8Array)
|
|
712
|
+
;
|
|
713
|
+
else if (ArrayBuffer.isView(source)) {
|
|
714
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
715
|
+
} else if (Array.isArray(source)) {
|
|
716
|
+
source = Uint8Array.from(source);
|
|
717
|
+
}
|
|
718
|
+
if (!(source instanceof Uint8Array)) {
|
|
719
|
+
throw new TypeError("Expected Uint8Array");
|
|
720
|
+
}
|
|
721
|
+
if (source.length === 0) {
|
|
722
|
+
return "";
|
|
723
|
+
}
|
|
724
|
+
var zeroes = 0;
|
|
725
|
+
var length2 = 0;
|
|
726
|
+
var pbegin = 0;
|
|
727
|
+
var pend = source.length;
|
|
728
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
729
|
+
pbegin++;
|
|
730
|
+
zeroes++;
|
|
731
|
+
}
|
|
732
|
+
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
733
|
+
var b58 = new Uint8Array(size);
|
|
734
|
+
while (pbegin !== pend) {
|
|
735
|
+
var carry = source[pbegin];
|
|
736
|
+
var i2 = 0;
|
|
737
|
+
for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
|
|
738
|
+
carry += 256 * b58[it1] >>> 0;
|
|
739
|
+
b58[it1] = carry % BASE >>> 0;
|
|
740
|
+
carry = carry / BASE >>> 0;
|
|
741
|
+
}
|
|
742
|
+
if (carry !== 0) {
|
|
743
|
+
throw new Error("Non-zero carry");
|
|
744
|
+
}
|
|
745
|
+
length2 = i2;
|
|
746
|
+
pbegin++;
|
|
747
|
+
}
|
|
748
|
+
var it2 = size - length2;
|
|
749
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
750
|
+
it2++;
|
|
751
|
+
}
|
|
752
|
+
var str = LEADER.repeat(zeroes);
|
|
753
|
+
for (; it2 < size; ++it2) {
|
|
754
|
+
str += ALPHABET.charAt(b58[it2]);
|
|
755
|
+
}
|
|
756
|
+
return str;
|
|
757
|
+
}
|
|
758
|
+
function decodeUnsafe(source) {
|
|
759
|
+
if (typeof source !== "string") {
|
|
760
|
+
throw new TypeError("Expected String");
|
|
761
|
+
}
|
|
762
|
+
if (source.length === 0) {
|
|
763
|
+
return new Uint8Array();
|
|
764
|
+
}
|
|
765
|
+
var psz = 0;
|
|
766
|
+
if (source[psz] === " ") {
|
|
767
|
+
return;
|
|
768
|
+
}
|
|
769
|
+
var zeroes = 0;
|
|
770
|
+
var length2 = 0;
|
|
771
|
+
while (source[psz] === LEADER) {
|
|
772
|
+
zeroes++;
|
|
773
|
+
psz++;
|
|
774
|
+
}
|
|
775
|
+
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
776
|
+
var b256 = new Uint8Array(size);
|
|
777
|
+
while (source[psz]) {
|
|
778
|
+
var carry = BASE_MAP[source.charCodeAt(psz)];
|
|
779
|
+
if (carry === 255) {
|
|
780
|
+
return;
|
|
781
|
+
}
|
|
782
|
+
var i2 = 0;
|
|
783
|
+
for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
|
|
784
|
+
carry += BASE * b256[it3] >>> 0;
|
|
785
|
+
b256[it3] = carry % 256 >>> 0;
|
|
786
|
+
carry = carry / 256 >>> 0;
|
|
787
|
+
}
|
|
788
|
+
if (carry !== 0) {
|
|
789
|
+
throw new Error("Non-zero carry");
|
|
790
|
+
}
|
|
791
|
+
length2 = i2;
|
|
792
|
+
psz++;
|
|
793
|
+
}
|
|
794
|
+
if (source[psz] === " ") {
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
var it4 = size - length2;
|
|
798
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
799
|
+
it4++;
|
|
800
|
+
}
|
|
801
|
+
var vch = new Uint8Array(zeroes + (size - it4));
|
|
802
|
+
var j2 = zeroes;
|
|
803
|
+
while (it4 !== size) {
|
|
804
|
+
vch[j2++] = b256[it4++];
|
|
805
|
+
}
|
|
806
|
+
return vch;
|
|
807
|
+
}
|
|
808
|
+
function decode6(string) {
|
|
809
|
+
var buffer = decodeUnsafe(string);
|
|
810
|
+
if (buffer) {
|
|
811
|
+
return buffer;
|
|
812
|
+
}
|
|
813
|
+
throw new Error(`Non-${name2} character`);
|
|
814
|
+
}
|
|
815
|
+
return {
|
|
816
|
+
encode: encode5,
|
|
817
|
+
decodeUnsafe,
|
|
818
|
+
decode: decode6
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
var src = base;
|
|
822
|
+
var _brrp__multiformats_scope_baseX = src;
|
|
823
|
+
var base_x_default = _brrp__multiformats_scope_baseX;
|
|
824
|
+
|
|
825
|
+
// ../../node_modules/multiformats/dist/src/bases/base.js
|
|
826
|
+
var Encoder = class {
|
|
827
|
+
constructor(name2, prefix, baseEncode) {
|
|
828
|
+
__publicField(this, "name");
|
|
829
|
+
__publicField(this, "prefix");
|
|
830
|
+
__publicField(this, "baseEncode");
|
|
831
|
+
this.name = name2;
|
|
832
|
+
this.prefix = prefix;
|
|
833
|
+
this.baseEncode = baseEncode;
|
|
834
|
+
}
|
|
835
|
+
encode(bytes) {
|
|
836
|
+
if (bytes instanceof Uint8Array) {
|
|
837
|
+
return `${this.prefix}${this.baseEncode(bytes)}`;
|
|
838
|
+
} else {
|
|
839
|
+
throw Error("Unknown type, must be binary type");
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
};
|
|
843
|
+
var Decoder = class {
|
|
844
|
+
constructor(name2, prefix, baseDecode) {
|
|
845
|
+
__publicField(this, "name");
|
|
846
|
+
__publicField(this, "prefix");
|
|
847
|
+
__publicField(this, "baseDecode");
|
|
848
|
+
__publicField(this, "prefixCodePoint");
|
|
849
|
+
this.name = name2;
|
|
850
|
+
this.prefix = prefix;
|
|
851
|
+
const prefixCodePoint = prefix.codePointAt(0);
|
|
852
|
+
if (prefixCodePoint === void 0) {
|
|
853
|
+
throw new Error("Invalid prefix character");
|
|
854
|
+
}
|
|
855
|
+
this.prefixCodePoint = prefixCodePoint;
|
|
856
|
+
this.baseDecode = baseDecode;
|
|
857
|
+
}
|
|
858
|
+
decode(text) {
|
|
859
|
+
if (typeof text === "string") {
|
|
860
|
+
if (text.codePointAt(0) !== this.prefixCodePoint) {
|
|
861
|
+
throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
|
|
862
|
+
}
|
|
863
|
+
return this.baseDecode(text.slice(this.prefix.length));
|
|
864
|
+
} else {
|
|
865
|
+
throw Error("Can only multibase decode strings");
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
or(decoder) {
|
|
869
|
+
return or(this, decoder);
|
|
870
|
+
}
|
|
871
|
+
};
|
|
872
|
+
var ComposedDecoder = class {
|
|
873
|
+
constructor(decoders) {
|
|
874
|
+
__publicField(this, "decoders");
|
|
875
|
+
this.decoders = decoders;
|
|
876
|
+
}
|
|
877
|
+
or(decoder) {
|
|
878
|
+
return or(this, decoder);
|
|
879
|
+
}
|
|
880
|
+
decode(input) {
|
|
881
|
+
const prefix = input[0];
|
|
882
|
+
const decoder = this.decoders[prefix];
|
|
883
|
+
if (decoder != null) {
|
|
884
|
+
return decoder.decode(input);
|
|
885
|
+
} else {
|
|
886
|
+
throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
};
|
|
890
|
+
function or(left, right) {
|
|
891
|
+
return new ComposedDecoder({
|
|
892
|
+
...left.decoders ?? { [left.prefix]: left },
|
|
893
|
+
...right.decoders ?? { [right.prefix]: right }
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
var Codec = class {
|
|
897
|
+
constructor(name2, prefix, baseEncode, baseDecode) {
|
|
898
|
+
__publicField(this, "name");
|
|
899
|
+
__publicField(this, "prefix");
|
|
900
|
+
__publicField(this, "baseEncode");
|
|
901
|
+
__publicField(this, "baseDecode");
|
|
902
|
+
__publicField(this, "encoder");
|
|
903
|
+
__publicField(this, "decoder");
|
|
904
|
+
this.name = name2;
|
|
905
|
+
this.prefix = prefix;
|
|
906
|
+
this.baseEncode = baseEncode;
|
|
907
|
+
this.baseDecode = baseDecode;
|
|
908
|
+
this.encoder = new Encoder(name2, prefix, baseEncode);
|
|
909
|
+
this.decoder = new Decoder(name2, prefix, baseDecode);
|
|
910
|
+
}
|
|
911
|
+
encode(input) {
|
|
912
|
+
return this.encoder.encode(input);
|
|
913
|
+
}
|
|
914
|
+
decode(input) {
|
|
915
|
+
return this.decoder.decode(input);
|
|
916
|
+
}
|
|
917
|
+
};
|
|
918
|
+
function from({ name: name2, prefix, encode: encode5, decode: decode6 }) {
|
|
919
|
+
return new Codec(name2, prefix, encode5, decode6);
|
|
920
|
+
}
|
|
921
|
+
function baseX({ name: name2, prefix, alphabet: alphabet2 }) {
|
|
922
|
+
const { encode: encode5, decode: decode6 } = base_x_default(alphabet2, name2);
|
|
923
|
+
return from({
|
|
924
|
+
prefix,
|
|
925
|
+
name: name2,
|
|
926
|
+
encode: encode5,
|
|
927
|
+
decode: (text) => coerce(decode6(text))
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
function decode(string, alphabetIdx, bitsPerChar, name2) {
|
|
931
|
+
let end = string.length;
|
|
932
|
+
while (string[end - 1] === "=") {
|
|
933
|
+
--end;
|
|
934
|
+
}
|
|
935
|
+
const out = new Uint8Array(end * bitsPerChar / 8 | 0);
|
|
936
|
+
let bits = 0;
|
|
937
|
+
let buffer = 0;
|
|
938
|
+
let written = 0;
|
|
939
|
+
for (let i = 0; i < end; ++i) {
|
|
940
|
+
const value = alphabetIdx[string[i]];
|
|
941
|
+
if (value === void 0) {
|
|
942
|
+
throw new SyntaxError(`Non-${name2} character`);
|
|
943
|
+
}
|
|
944
|
+
buffer = buffer << bitsPerChar | value;
|
|
945
|
+
bits += bitsPerChar;
|
|
946
|
+
if (bits >= 8) {
|
|
947
|
+
bits -= 8;
|
|
948
|
+
out[written++] = 255 & buffer >> bits;
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
if (bits >= bitsPerChar || (255 & buffer << 8 - bits) !== 0) {
|
|
952
|
+
throw new SyntaxError("Unexpected end of data");
|
|
953
|
+
}
|
|
954
|
+
return out;
|
|
955
|
+
}
|
|
956
|
+
function encode(data, alphabet2, bitsPerChar) {
|
|
957
|
+
const pad = alphabet2[alphabet2.length - 1] === "=";
|
|
958
|
+
const mask = (1 << bitsPerChar) - 1;
|
|
959
|
+
let out = "";
|
|
960
|
+
let bits = 0;
|
|
961
|
+
let buffer = 0;
|
|
962
|
+
for (let i = 0; i < data.length; ++i) {
|
|
963
|
+
buffer = buffer << 8 | data[i];
|
|
964
|
+
bits += 8;
|
|
965
|
+
while (bits > bitsPerChar) {
|
|
966
|
+
bits -= bitsPerChar;
|
|
967
|
+
out += alphabet2[mask & buffer >> bits];
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
if (bits !== 0) {
|
|
971
|
+
out += alphabet2[mask & buffer << bitsPerChar - bits];
|
|
972
|
+
}
|
|
973
|
+
if (pad) {
|
|
974
|
+
while ((out.length * bitsPerChar & 7) !== 0) {
|
|
975
|
+
out += "=";
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
return out;
|
|
979
|
+
}
|
|
980
|
+
function createAlphabetIdx(alphabet2) {
|
|
981
|
+
const alphabetIdx = {};
|
|
982
|
+
for (let i = 0; i < alphabet2.length; ++i) {
|
|
983
|
+
alphabetIdx[alphabet2[i]] = i;
|
|
984
|
+
}
|
|
985
|
+
return alphabetIdx;
|
|
986
|
+
}
|
|
987
|
+
function rfc4648({ name: name2, prefix, bitsPerChar, alphabet: alphabet2 }) {
|
|
988
|
+
const alphabetIdx = createAlphabetIdx(alphabet2);
|
|
989
|
+
return from({
|
|
990
|
+
prefix,
|
|
991
|
+
name: name2,
|
|
992
|
+
encode(input) {
|
|
993
|
+
return encode(input, alphabet2, bitsPerChar);
|
|
994
|
+
},
|
|
995
|
+
decode(input) {
|
|
996
|
+
return decode(input, alphabetIdx, bitsPerChar, name2);
|
|
997
|
+
}
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
// ../../node_modules/multiformats/dist/src/bases/base10.js
|
|
1002
|
+
var base10 = baseX({
|
|
1003
|
+
prefix: "9",
|
|
1004
|
+
name: "base10",
|
|
1005
|
+
alphabet: "0123456789"
|
|
1006
|
+
});
|
|
1007
|
+
|
|
1008
|
+
// ../../node_modules/multiformats/dist/src/bases/base16.js
|
|
1009
|
+
var base16_exports = {};
|
|
1010
|
+
__export(base16_exports, {
|
|
1011
|
+
base16: () => base16,
|
|
1012
|
+
base16upper: () => base16upper
|
|
1013
|
+
});
|
|
1014
|
+
var base16 = rfc4648({
|
|
1015
|
+
prefix: "f",
|
|
1016
|
+
name: "base16",
|
|
1017
|
+
alphabet: "0123456789abcdef",
|
|
1018
|
+
bitsPerChar: 4
|
|
1019
|
+
});
|
|
1020
|
+
var base16upper = rfc4648({
|
|
1021
|
+
prefix: "F",
|
|
1022
|
+
name: "base16upper",
|
|
1023
|
+
alphabet: "0123456789ABCDEF",
|
|
1024
|
+
bitsPerChar: 4
|
|
1025
|
+
});
|
|
1026
|
+
|
|
1027
|
+
// ../../node_modules/multiformats/dist/src/bases/base2.js
|
|
1028
|
+
var base2_exports = {};
|
|
1029
|
+
__export(base2_exports, {
|
|
1030
|
+
base2: () => base2
|
|
1031
|
+
});
|
|
1032
|
+
var base2 = rfc4648({
|
|
1033
|
+
prefix: "0",
|
|
1034
|
+
name: "base2",
|
|
1035
|
+
alphabet: "01",
|
|
1036
|
+
bitsPerChar: 1
|
|
1037
|
+
});
|
|
1038
|
+
|
|
1039
|
+
// ../../node_modules/multiformats/dist/src/bases/base256emoji.js
|
|
1040
|
+
var base256emoji_exports = {};
|
|
1041
|
+
__export(base256emoji_exports, {
|
|
1042
|
+
base256emoji: () => base256emoji
|
|
1043
|
+
});
|
|
1044
|
+
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}");
|
|
1045
|
+
var alphabetBytesToChars = alphabet.reduce((p, c, i) => {
|
|
1046
|
+
p[i] = c;
|
|
1047
|
+
return p;
|
|
1048
|
+
}, []);
|
|
1049
|
+
var alphabetCharsToBytes = alphabet.reduce((p, c, i) => {
|
|
1050
|
+
const codePoint = c.codePointAt(0);
|
|
1051
|
+
if (codePoint == null) {
|
|
1052
|
+
throw new Error(`Invalid character: ${c}`);
|
|
1053
|
+
}
|
|
1054
|
+
p[codePoint] = i;
|
|
1055
|
+
return p;
|
|
1056
|
+
}, []);
|
|
1057
|
+
function encode2(data) {
|
|
1058
|
+
return data.reduce((p, c) => {
|
|
1059
|
+
p += alphabetBytesToChars[c];
|
|
1060
|
+
return p;
|
|
1061
|
+
}, "");
|
|
1062
|
+
}
|
|
1063
|
+
function decode2(str) {
|
|
1064
|
+
const byts = [];
|
|
1065
|
+
for (const char of str) {
|
|
1066
|
+
const codePoint = char.codePointAt(0);
|
|
1067
|
+
if (codePoint == null) {
|
|
1068
|
+
throw new Error(`Invalid character: ${char}`);
|
|
1069
|
+
}
|
|
1070
|
+
const byt = alphabetCharsToBytes[codePoint];
|
|
1071
|
+
if (byt == null) {
|
|
1072
|
+
throw new Error(`Non-base256emoji character: ${char}`);
|
|
1073
|
+
}
|
|
1074
|
+
byts.push(byt);
|
|
1075
|
+
}
|
|
1076
|
+
return new Uint8Array(byts);
|
|
1077
|
+
}
|
|
1078
|
+
var base256emoji = from({
|
|
1079
|
+
prefix: "\u{1F680}",
|
|
1080
|
+
name: "base256emoji",
|
|
1081
|
+
encode: encode2,
|
|
1082
|
+
decode: decode2
|
|
1083
|
+
});
|
|
1084
|
+
|
|
1085
|
+
// ../../node_modules/multiformats/dist/src/bases/base32.js
|
|
1086
|
+
var base32_exports = {};
|
|
1087
|
+
__export(base32_exports, {
|
|
1088
|
+
base32: () => base32,
|
|
1089
|
+
base32hex: () => base32hex,
|
|
1090
|
+
base32hexpad: () => base32hexpad,
|
|
1091
|
+
base32hexpadupper: () => base32hexpadupper,
|
|
1092
|
+
base32hexupper: () => base32hexupper,
|
|
1093
|
+
base32pad: () => base32pad,
|
|
1094
|
+
base32padupper: () => base32padupper,
|
|
1095
|
+
base32upper: () => base32upper,
|
|
1096
|
+
base32z: () => base32z
|
|
1097
|
+
});
|
|
1098
|
+
var base32 = rfc4648({
|
|
1099
|
+
prefix: "b",
|
|
1100
|
+
name: "base32",
|
|
1101
|
+
alphabet: "abcdefghijklmnopqrstuvwxyz234567",
|
|
1102
|
+
bitsPerChar: 5
|
|
1103
|
+
});
|
|
1104
|
+
var base32upper = rfc4648({
|
|
1105
|
+
prefix: "B",
|
|
1106
|
+
name: "base32upper",
|
|
1107
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
|
|
1108
|
+
bitsPerChar: 5
|
|
1109
|
+
});
|
|
1110
|
+
var base32pad = rfc4648({
|
|
1111
|
+
prefix: "c",
|
|
1112
|
+
name: "base32pad",
|
|
1113
|
+
alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
|
|
1114
|
+
bitsPerChar: 5
|
|
1115
|
+
});
|
|
1116
|
+
var base32padupper = rfc4648({
|
|
1117
|
+
prefix: "C",
|
|
1118
|
+
name: "base32padupper",
|
|
1119
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
|
|
1120
|
+
bitsPerChar: 5
|
|
1121
|
+
});
|
|
1122
|
+
var base32hex = rfc4648({
|
|
1123
|
+
prefix: "v",
|
|
1124
|
+
name: "base32hex",
|
|
1125
|
+
alphabet: "0123456789abcdefghijklmnopqrstuv",
|
|
1126
|
+
bitsPerChar: 5
|
|
1127
|
+
});
|
|
1128
|
+
var base32hexupper = rfc4648({
|
|
1129
|
+
prefix: "V",
|
|
1130
|
+
name: "base32hexupper",
|
|
1131
|
+
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
|
|
1132
|
+
bitsPerChar: 5
|
|
1133
|
+
});
|
|
1134
|
+
var base32hexpad = rfc4648({
|
|
1135
|
+
prefix: "t",
|
|
1136
|
+
name: "base32hexpad",
|
|
1137
|
+
alphabet: "0123456789abcdefghijklmnopqrstuv=",
|
|
1138
|
+
bitsPerChar: 5
|
|
1139
|
+
});
|
|
1140
|
+
var base32hexpadupper = rfc4648({
|
|
1141
|
+
prefix: "T",
|
|
1142
|
+
name: "base32hexpadupper",
|
|
1143
|
+
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
|
|
1144
|
+
bitsPerChar: 5
|
|
1145
|
+
});
|
|
1146
|
+
var base32z = rfc4648({
|
|
1147
|
+
prefix: "h",
|
|
1148
|
+
name: "base32z",
|
|
1149
|
+
alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
|
|
1150
|
+
bitsPerChar: 5
|
|
1151
|
+
});
|
|
1152
|
+
|
|
1153
|
+
// ../../node_modules/multiformats/dist/src/bases/base36.js
|
|
1154
|
+
var base36_exports = {};
|
|
1155
|
+
__export(base36_exports, {
|
|
1156
|
+
base36: () => base36,
|
|
1157
|
+
base36upper: () => base36upper
|
|
1158
|
+
});
|
|
1159
|
+
var base36 = baseX({
|
|
1160
|
+
prefix: "k",
|
|
1161
|
+
name: "base36",
|
|
1162
|
+
alphabet: "0123456789abcdefghijklmnopqrstuvwxyz"
|
|
1163
|
+
});
|
|
1164
|
+
var base36upper = baseX({
|
|
1165
|
+
prefix: "K",
|
|
1166
|
+
name: "base36upper",
|
|
1167
|
+
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
1168
|
+
});
|
|
1169
|
+
|
|
1170
|
+
// ../../node_modules/multiformats/dist/src/bases/base58.js
|
|
1171
|
+
var base58_exports = {};
|
|
1172
|
+
__export(base58_exports, {
|
|
1173
|
+
base58btc: () => base58btc,
|
|
1174
|
+
base58flickr: () => base58flickr
|
|
1175
|
+
});
|
|
1176
|
+
var base58btc = baseX({
|
|
1177
|
+
name: "base58btc",
|
|
1178
|
+
prefix: "z",
|
|
1179
|
+
alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
|
1180
|
+
});
|
|
1181
|
+
var base58flickr = baseX({
|
|
1182
|
+
name: "base58flickr",
|
|
1183
|
+
prefix: "Z",
|
|
1184
|
+
alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
|
|
1185
|
+
});
|
|
1186
|
+
|
|
1187
|
+
// ../../node_modules/multiformats/dist/src/bases/base64.js
|
|
1188
|
+
var base64_exports = {};
|
|
1189
|
+
__export(base64_exports, {
|
|
1190
|
+
base64: () => base64,
|
|
1191
|
+
base64pad: () => base64pad,
|
|
1192
|
+
base64url: () => base64url,
|
|
1193
|
+
base64urlpad: () => base64urlpad
|
|
1194
|
+
});
|
|
1195
|
+
var base64 = rfc4648({
|
|
1196
|
+
prefix: "m",
|
|
1197
|
+
name: "base64",
|
|
1198
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
|
|
1199
|
+
bitsPerChar: 6
|
|
1200
|
+
});
|
|
1201
|
+
var base64pad = rfc4648({
|
|
1202
|
+
prefix: "M",
|
|
1203
|
+
name: "base64pad",
|
|
1204
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
|
|
1205
|
+
bitsPerChar: 6
|
|
1206
|
+
});
|
|
1207
|
+
var base64url = rfc4648({
|
|
1208
|
+
prefix: "u",
|
|
1209
|
+
name: "base64url",
|
|
1210
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",
|
|
1211
|
+
bitsPerChar: 6
|
|
1212
|
+
});
|
|
1213
|
+
var base64urlpad = rfc4648({
|
|
1214
|
+
prefix: "U",
|
|
1215
|
+
name: "base64urlpad",
|
|
1216
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",
|
|
1217
|
+
bitsPerChar: 6
|
|
1218
|
+
});
|
|
1219
|
+
|
|
1220
|
+
// ../../node_modules/multiformats/dist/src/bases/base8.js
|
|
1221
|
+
var base8_exports = {};
|
|
1222
|
+
__export(base8_exports, {
|
|
1223
|
+
base8: () => base8
|
|
1224
|
+
});
|
|
1225
|
+
var base8 = rfc4648({
|
|
1226
|
+
prefix: "7",
|
|
1227
|
+
name: "base8",
|
|
1228
|
+
alphabet: "01234567",
|
|
1229
|
+
bitsPerChar: 3
|
|
1230
|
+
});
|
|
1231
|
+
|
|
1232
|
+
// ../../node_modules/multiformats/dist/src/bases/identity.js
|
|
1233
|
+
var identity_exports = {};
|
|
1234
|
+
__export(identity_exports, {
|
|
1235
|
+
identity: () => identity
|
|
1236
|
+
});
|
|
1237
|
+
var identity = from({
|
|
1238
|
+
prefix: "\0",
|
|
1239
|
+
name: "identity",
|
|
1240
|
+
encode: (buf) => toString(buf),
|
|
1241
|
+
decode: (str) => fromString(str)
|
|
1242
|
+
});
|
|
1243
|
+
|
|
1244
|
+
// ../../node_modules/multiformats/dist/src/codecs/json.js
|
|
1245
|
+
var textEncoder2 = new TextEncoder();
|
|
1246
|
+
var textDecoder = new TextDecoder();
|
|
1247
|
+
|
|
1248
|
+
// ../../node_modules/multiformats/dist/src/hashes/identity.js
|
|
1249
|
+
var identity_exports2 = {};
|
|
1250
|
+
__export(identity_exports2, {
|
|
1251
|
+
identity: () => identity2
|
|
1252
|
+
});
|
|
1253
|
+
|
|
1254
|
+
// ../../node_modules/multiformats/dist/src/vendor/varint.js
|
|
1255
|
+
var encode_1 = encode3;
|
|
1256
|
+
var MSB = 128;
|
|
1257
|
+
var REST = 127;
|
|
1258
|
+
var MSBALL = ~REST;
|
|
1259
|
+
var INT = Math.pow(2, 31);
|
|
1260
|
+
function encode3(num, out, offset) {
|
|
1261
|
+
out = out || [];
|
|
1262
|
+
offset = offset || 0;
|
|
1263
|
+
var oldOffset = offset;
|
|
1264
|
+
while (num >= INT) {
|
|
1265
|
+
out[offset++] = num & 255 | MSB;
|
|
1266
|
+
num /= 128;
|
|
1267
|
+
}
|
|
1268
|
+
while (num & MSBALL) {
|
|
1269
|
+
out[offset++] = num & 255 | MSB;
|
|
1270
|
+
num >>>= 7;
|
|
1271
|
+
}
|
|
1272
|
+
out[offset] = num | 0;
|
|
1273
|
+
encode3.bytes = offset - oldOffset + 1;
|
|
1274
|
+
return out;
|
|
1275
|
+
}
|
|
1276
|
+
var decode3 = read;
|
|
1277
|
+
var MSB$1 = 128;
|
|
1278
|
+
var REST$1 = 127;
|
|
1279
|
+
function read(buf, offset) {
|
|
1280
|
+
var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
|
|
1281
|
+
do {
|
|
1282
|
+
if (counter >= l) {
|
|
1283
|
+
read.bytes = 0;
|
|
1284
|
+
throw new RangeError("Could not decode varint");
|
|
1285
|
+
}
|
|
1286
|
+
b = buf[counter++];
|
|
1287
|
+
res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
|
|
1288
|
+
shift += 7;
|
|
1289
|
+
} while (b >= MSB$1);
|
|
1290
|
+
read.bytes = counter - offset;
|
|
1291
|
+
return res;
|
|
1292
|
+
}
|
|
1293
|
+
var N1 = Math.pow(2, 7);
|
|
1294
|
+
var N2 = Math.pow(2, 14);
|
|
1295
|
+
var N3 = Math.pow(2, 21);
|
|
1296
|
+
var N4 = Math.pow(2, 28);
|
|
1297
|
+
var N5 = Math.pow(2, 35);
|
|
1298
|
+
var N6 = Math.pow(2, 42);
|
|
1299
|
+
var N7 = Math.pow(2, 49);
|
|
1300
|
+
var N8 = Math.pow(2, 56);
|
|
1301
|
+
var N9 = Math.pow(2, 63);
|
|
1302
|
+
var length = function(value) {
|
|
1303
|
+
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;
|
|
1304
|
+
};
|
|
1305
|
+
var varint = {
|
|
1306
|
+
encode: encode_1,
|
|
1307
|
+
decode: decode3,
|
|
1308
|
+
encodingLength: length
|
|
1309
|
+
};
|
|
1310
|
+
var _brrp_varint = varint;
|
|
1311
|
+
var varint_default = _brrp_varint;
|
|
1312
|
+
|
|
1313
|
+
// ../../node_modules/multiformats/dist/src/varint.js
|
|
1314
|
+
function decode4(data, offset = 0) {
|
|
1315
|
+
const code2 = varint_default.decode(data, offset);
|
|
1316
|
+
return [code2, varint_default.decode.bytes];
|
|
1317
|
+
}
|
|
1318
|
+
function encodeTo(int, target, offset = 0) {
|
|
1319
|
+
varint_default.encode(int, target, offset);
|
|
1320
|
+
return target;
|
|
1321
|
+
}
|
|
1322
|
+
function encodingLength(int) {
|
|
1323
|
+
return varint_default.encodingLength(int);
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
// ../../node_modules/multiformats/dist/src/hashes/digest.js
|
|
1327
|
+
function create(code2, digest2) {
|
|
1328
|
+
const size = digest2.byteLength;
|
|
1329
|
+
const sizeOffset = encodingLength(code2);
|
|
1330
|
+
const digestOffset = sizeOffset + encodingLength(size);
|
|
1331
|
+
const bytes = new Uint8Array(digestOffset + size);
|
|
1332
|
+
encodeTo(code2, bytes, 0);
|
|
1333
|
+
encodeTo(size, bytes, sizeOffset);
|
|
1334
|
+
bytes.set(digest2, digestOffset);
|
|
1335
|
+
return new Digest(code2, size, digest2, bytes);
|
|
1336
|
+
}
|
|
1337
|
+
function decode5(multihash) {
|
|
1338
|
+
const bytes = coerce(multihash);
|
|
1339
|
+
const [code2, sizeOffset] = decode4(bytes);
|
|
1340
|
+
const [size, digestOffset] = decode4(bytes.subarray(sizeOffset));
|
|
1341
|
+
const digest2 = bytes.subarray(sizeOffset + digestOffset);
|
|
1342
|
+
if (digest2.byteLength !== size) {
|
|
1343
|
+
throw new Error("Incorrect length");
|
|
1344
|
+
}
|
|
1345
|
+
return new Digest(code2, size, digest2, bytes);
|
|
1346
|
+
}
|
|
1347
|
+
function equals2(a, b) {
|
|
1348
|
+
if (a === b) {
|
|
1349
|
+
return true;
|
|
1350
|
+
} else {
|
|
1351
|
+
const data = b;
|
|
1352
|
+
return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals(a.bytes, data.bytes);
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
var Digest = class {
|
|
1356
|
+
/**
|
|
1357
|
+
* Creates a multihash digest.
|
|
1358
|
+
*/
|
|
1359
|
+
constructor(code2, size, digest2, bytes) {
|
|
1360
|
+
__publicField(this, "code");
|
|
1361
|
+
__publicField(this, "size");
|
|
1362
|
+
__publicField(this, "digest");
|
|
1363
|
+
__publicField(this, "bytes");
|
|
1364
|
+
this.code = code2;
|
|
1365
|
+
this.size = size;
|
|
1366
|
+
this.digest = digest2;
|
|
1367
|
+
this.bytes = bytes;
|
|
1368
|
+
}
|
|
1369
|
+
};
|
|
1370
|
+
|
|
1371
|
+
// ../../node_modules/multiformats/dist/src/hashes/identity.js
|
|
1372
|
+
var code = 0;
|
|
1373
|
+
var name = "identity";
|
|
1374
|
+
var encode4 = coerce;
|
|
1375
|
+
function digest(input, options) {
|
|
1376
|
+
if (options?.truncate != null && options.truncate !== input.byteLength) {
|
|
1377
|
+
if (options.truncate < 0 || options.truncate > input.byteLength) {
|
|
1378
|
+
throw new Error(`Invalid truncate option, must be less than or equal to ${input.byteLength}`);
|
|
1379
|
+
}
|
|
1380
|
+
input = input.subarray(0, options.truncate);
|
|
1381
|
+
}
|
|
1382
|
+
return create(code, encode4(input));
|
|
1383
|
+
}
|
|
1384
|
+
var identity2 = { code, name, encode: encode4, digest };
|
|
1385
|
+
|
|
1386
|
+
// ../../node_modules/multiformats/dist/src/hashes/sha2.js
|
|
1387
|
+
var sha2_exports = {};
|
|
1388
|
+
__export(sha2_exports, {
|
|
1389
|
+
sha256: () => sha2562,
|
|
1390
|
+
sha512: () => sha512
|
|
1391
|
+
});
|
|
1392
|
+
import crypto from "crypto";
|
|
1393
|
+
|
|
1394
|
+
// ../../node_modules/multiformats/dist/src/hashes/hasher.js
|
|
1395
|
+
var DEFAULT_MIN_DIGEST_LENGTH = 20;
|
|
1396
|
+
function from2({ name: name2, code: code2, encode: encode5, minDigestLength, maxDigestLength }) {
|
|
1397
|
+
return new Hasher(name2, code2, encode5, minDigestLength, maxDigestLength);
|
|
1398
|
+
}
|
|
1399
|
+
var Hasher = class {
|
|
1400
|
+
constructor(name2, code2, encode5, minDigestLength, maxDigestLength) {
|
|
1401
|
+
__publicField(this, "name");
|
|
1402
|
+
__publicField(this, "code");
|
|
1403
|
+
__publicField(this, "encode");
|
|
1404
|
+
__publicField(this, "minDigestLength");
|
|
1405
|
+
__publicField(this, "maxDigestLength");
|
|
1406
|
+
this.name = name2;
|
|
1407
|
+
this.code = code2;
|
|
1408
|
+
this.encode = encode5;
|
|
1409
|
+
this.minDigestLength = minDigestLength ?? DEFAULT_MIN_DIGEST_LENGTH;
|
|
1410
|
+
this.maxDigestLength = maxDigestLength;
|
|
1411
|
+
}
|
|
1412
|
+
digest(input, options) {
|
|
1413
|
+
if (options?.truncate != null) {
|
|
1414
|
+
if (options.truncate < this.minDigestLength) {
|
|
1415
|
+
throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);
|
|
1416
|
+
}
|
|
1417
|
+
if (this.maxDigestLength != null && options.truncate > this.maxDigestLength) {
|
|
1418
|
+
throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`);
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
if (input instanceof Uint8Array) {
|
|
1422
|
+
const result = this.encode(input);
|
|
1423
|
+
if (result instanceof Uint8Array) {
|
|
1424
|
+
return createDigest(result, this.code, options?.truncate);
|
|
1425
|
+
}
|
|
1426
|
+
return result.then((digest2) => createDigest(digest2, this.code, options?.truncate));
|
|
1427
|
+
} else {
|
|
1428
|
+
throw Error("Unknown type, must be binary type");
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
};
|
|
1432
|
+
function createDigest(digest2, code2, truncate) {
|
|
1433
|
+
if (truncate != null && truncate !== digest2.byteLength) {
|
|
1434
|
+
if (truncate > digest2.byteLength) {
|
|
1435
|
+
throw new Error(`Invalid truncate option, must be less than or equal to ${digest2.byteLength}`);
|
|
1436
|
+
}
|
|
1437
|
+
digest2 = digest2.subarray(0, truncate);
|
|
1438
|
+
}
|
|
1439
|
+
return create(code2, digest2);
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
// ../../node_modules/multiformats/dist/src/hashes/sha2.js
|
|
1443
|
+
var sha2562 = from2({
|
|
1444
|
+
name: "sha2-256",
|
|
1445
|
+
code: 18,
|
|
1446
|
+
encode: (input) => coerce(crypto.createHash("sha256").update(input).digest())
|
|
1447
|
+
});
|
|
1448
|
+
var sha512 = from2({
|
|
1449
|
+
name: "sha2-512",
|
|
1450
|
+
code: 19,
|
|
1451
|
+
encode: (input) => coerce(crypto.createHash("sha512").update(input).digest())
|
|
1452
|
+
});
|
|
1453
|
+
|
|
1454
|
+
// ../../node_modules/multiformats/dist/src/cid.js
|
|
1455
|
+
function format(link, base3) {
|
|
1456
|
+
const { bytes, version } = link;
|
|
1457
|
+
switch (version) {
|
|
1458
|
+
case 0:
|
|
1459
|
+
return toStringV0(bytes, baseCache(link), base3 ?? base58btc.encoder);
|
|
1460
|
+
default:
|
|
1461
|
+
return toStringV1(bytes, baseCache(link), base3 ?? base32.encoder);
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
var cache = /* @__PURE__ */ new WeakMap();
|
|
1465
|
+
function baseCache(cid) {
|
|
1466
|
+
const baseCache2 = cache.get(cid);
|
|
1467
|
+
if (baseCache2 == null) {
|
|
1468
|
+
const baseCache3 = /* @__PURE__ */ new Map();
|
|
1469
|
+
cache.set(cid, baseCache3);
|
|
1470
|
+
return baseCache3;
|
|
1471
|
+
}
|
|
1472
|
+
return baseCache2;
|
|
1473
|
+
}
|
|
1474
|
+
var _a;
|
|
1475
|
+
var CID = class _CID {
|
|
1476
|
+
/**
|
|
1477
|
+
* @param version - Version of the CID
|
|
1478
|
+
* @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
1479
|
+
* @param multihash - (Multi)hash of the of the content.
|
|
1480
|
+
*/
|
|
1481
|
+
constructor(version, code2, multihash, bytes) {
|
|
1482
|
+
__publicField(this, "code");
|
|
1483
|
+
__publicField(this, "version");
|
|
1484
|
+
__publicField(this, "multihash");
|
|
1485
|
+
__publicField(this, "bytes");
|
|
1486
|
+
__publicField(this, "/");
|
|
1487
|
+
__publicField(this, _a, "CID");
|
|
1488
|
+
this.code = code2;
|
|
1489
|
+
this.version = version;
|
|
1490
|
+
this.multihash = multihash;
|
|
1491
|
+
this.bytes = bytes;
|
|
1492
|
+
this["/"] = bytes;
|
|
1493
|
+
}
|
|
1494
|
+
/**
|
|
1495
|
+
* Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes`
|
|
1496
|
+
* please either use `CID.asCID(cid)` or switch to new signalling mechanism
|
|
1497
|
+
*
|
|
1498
|
+
* @deprecated
|
|
1499
|
+
*/
|
|
1500
|
+
get asCID() {
|
|
1501
|
+
return this;
|
|
1502
|
+
}
|
|
1503
|
+
// ArrayBufferView
|
|
1504
|
+
get byteOffset() {
|
|
1505
|
+
return this.bytes.byteOffset;
|
|
1506
|
+
}
|
|
1507
|
+
// ArrayBufferView
|
|
1508
|
+
get byteLength() {
|
|
1509
|
+
return this.bytes.byteLength;
|
|
1510
|
+
}
|
|
1511
|
+
toV0() {
|
|
1512
|
+
switch (this.version) {
|
|
1513
|
+
case 0: {
|
|
1514
|
+
return this;
|
|
1515
|
+
}
|
|
1516
|
+
case 1: {
|
|
1517
|
+
const { code: code2, multihash } = this;
|
|
1518
|
+
if (code2 !== DAG_PB_CODE) {
|
|
1519
|
+
throw new Error("Cannot convert a non dag-pb CID to CIDv0");
|
|
1520
|
+
}
|
|
1521
|
+
if (multihash.code !== SHA_256_CODE) {
|
|
1522
|
+
throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
|
|
1523
|
+
}
|
|
1524
|
+
return _CID.createV0(multihash);
|
|
1525
|
+
}
|
|
1526
|
+
default: {
|
|
1527
|
+
throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`);
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
toV1() {
|
|
1532
|
+
switch (this.version) {
|
|
1533
|
+
case 0: {
|
|
1534
|
+
const { code: code2, digest: digest2 } = this.multihash;
|
|
1535
|
+
const multihash = create(code2, digest2);
|
|
1536
|
+
return _CID.createV1(this.code, multihash);
|
|
1537
|
+
}
|
|
1538
|
+
case 1: {
|
|
1539
|
+
return this;
|
|
1540
|
+
}
|
|
1541
|
+
default: {
|
|
1542
|
+
throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`);
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
equals(other) {
|
|
1547
|
+
return _CID.equals(this, other);
|
|
1548
|
+
}
|
|
1549
|
+
static equals(self, other) {
|
|
1550
|
+
const unknown = other;
|
|
1551
|
+
return unknown != null && self.code === unknown.code && self.version === unknown.version && equals2(self.multihash, unknown.multihash);
|
|
1552
|
+
}
|
|
1553
|
+
toString(base3) {
|
|
1554
|
+
return format(this, base3);
|
|
1555
|
+
}
|
|
1556
|
+
toJSON() {
|
|
1557
|
+
return { "/": format(this) };
|
|
1558
|
+
}
|
|
1559
|
+
link() {
|
|
1560
|
+
return this;
|
|
1561
|
+
}
|
|
1562
|
+
// Legacy
|
|
1563
|
+
[(_a = Symbol.toStringTag, /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom"))]() {
|
|
1564
|
+
return `CID(${this.toString()})`;
|
|
1565
|
+
}
|
|
1566
|
+
/**
|
|
1567
|
+
* Takes any input `value` and returns a `CID` instance if it was
|
|
1568
|
+
* a `CID` otherwise returns `null`. If `value` is instanceof `CID`
|
|
1569
|
+
* it will return value back. If `value` is not instance of this CID
|
|
1570
|
+
* class, but is compatible CID it will return new instance of this
|
|
1571
|
+
* `CID` class. Otherwise returns null.
|
|
1572
|
+
*
|
|
1573
|
+
* This allows two different incompatible versions of CID library to
|
|
1574
|
+
* co-exist and interop as long as binary interface is compatible.
|
|
1575
|
+
*/
|
|
1576
|
+
static asCID(input) {
|
|
1577
|
+
if (input == null) {
|
|
1578
|
+
return null;
|
|
1579
|
+
}
|
|
1580
|
+
const value = input;
|
|
1581
|
+
if (value instanceof _CID) {
|
|
1582
|
+
return value;
|
|
1583
|
+
} else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) {
|
|
1584
|
+
const { version, code: code2, multihash, bytes } = value;
|
|
1585
|
+
return new _CID(version, code2, multihash, bytes ?? encodeCID(version, code2, multihash.bytes));
|
|
1586
|
+
} else if (value[cidSymbol] === true) {
|
|
1587
|
+
const { version, multihash, code: code2 } = value;
|
|
1588
|
+
const digest2 = decode5(multihash);
|
|
1589
|
+
return _CID.create(version, code2, digest2);
|
|
1590
|
+
} else {
|
|
1591
|
+
return null;
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
/**
|
|
1595
|
+
* @param version - Version of the CID
|
|
1596
|
+
* @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
1597
|
+
* @param digest - (Multi)hash of the of the content.
|
|
1598
|
+
*/
|
|
1599
|
+
static create(version, code2, digest2) {
|
|
1600
|
+
if (typeof code2 !== "number") {
|
|
1601
|
+
throw new Error("String codecs are no longer supported");
|
|
1602
|
+
}
|
|
1603
|
+
if (!(digest2.bytes instanceof Uint8Array)) {
|
|
1604
|
+
throw new Error("Invalid digest");
|
|
1605
|
+
}
|
|
1606
|
+
switch (version) {
|
|
1607
|
+
case 0: {
|
|
1608
|
+
if (code2 !== DAG_PB_CODE) {
|
|
1609
|
+
throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`);
|
|
1610
|
+
} else {
|
|
1611
|
+
return new _CID(version, code2, digest2, digest2.bytes);
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
case 1: {
|
|
1615
|
+
const bytes = encodeCID(version, code2, digest2.bytes);
|
|
1616
|
+
return new _CID(version, code2, digest2, bytes);
|
|
1617
|
+
}
|
|
1618
|
+
default: {
|
|
1619
|
+
throw new Error("Invalid version");
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
/**
|
|
1624
|
+
* Simplified version of `create` for CIDv0.
|
|
1625
|
+
*/
|
|
1626
|
+
static createV0(digest2) {
|
|
1627
|
+
return _CID.create(0, DAG_PB_CODE, digest2);
|
|
1628
|
+
}
|
|
1629
|
+
/**
|
|
1630
|
+
* Simplified version of `create` for CIDv1.
|
|
1631
|
+
*
|
|
1632
|
+
* @param code - Content encoding format code.
|
|
1633
|
+
* @param digest - Multihash of the content.
|
|
1634
|
+
*/
|
|
1635
|
+
static createV1(code2, digest2) {
|
|
1636
|
+
return _CID.create(1, code2, digest2);
|
|
1637
|
+
}
|
|
1638
|
+
/**
|
|
1639
|
+
* Decoded a CID from its binary representation. The byte array must contain
|
|
1640
|
+
* only the CID with no additional bytes.
|
|
1641
|
+
*
|
|
1642
|
+
* An error will be thrown if the bytes provided do not contain a valid
|
|
1643
|
+
* binary representation of a CID.
|
|
1644
|
+
*/
|
|
1645
|
+
static decode(bytes) {
|
|
1646
|
+
const [cid, remainder] = _CID.decodeFirst(bytes);
|
|
1647
|
+
if (remainder.length !== 0) {
|
|
1648
|
+
throw new Error("Incorrect length");
|
|
1649
|
+
}
|
|
1650
|
+
return cid;
|
|
1651
|
+
}
|
|
1652
|
+
/**
|
|
1653
|
+
* Decoded a CID from its binary representation at the beginning of a byte
|
|
1654
|
+
* array.
|
|
1655
|
+
*
|
|
1656
|
+
* Returns an array with the first element containing the CID and the second
|
|
1657
|
+
* element containing the remainder of the original byte array. The remainder
|
|
1658
|
+
* will be a zero-length byte array if the provided bytes only contained a
|
|
1659
|
+
* binary CID representation.
|
|
1660
|
+
*/
|
|
1661
|
+
static decodeFirst(bytes) {
|
|
1662
|
+
const specs = _CID.inspectBytes(bytes);
|
|
1663
|
+
const prefixSize = specs.size - specs.multihashSize;
|
|
1664
|
+
const multihashBytes = coerce(bytes.subarray(prefixSize, prefixSize + specs.multihashSize));
|
|
1665
|
+
if (multihashBytes.byteLength !== specs.multihashSize) {
|
|
1666
|
+
throw new Error("Incorrect length");
|
|
1667
|
+
}
|
|
1668
|
+
const digestBytes = multihashBytes.subarray(specs.multihashSize - specs.digestSize);
|
|
1669
|
+
const digest2 = new Digest(specs.multihashCode, specs.digestSize, digestBytes, multihashBytes);
|
|
1670
|
+
const cid = specs.version === 0 ? _CID.createV0(digest2) : _CID.createV1(specs.codec, digest2);
|
|
1671
|
+
return [cid, bytes.subarray(specs.size)];
|
|
1672
|
+
}
|
|
1673
|
+
/**
|
|
1674
|
+
* Inspect the initial bytes of a CID to determine its properties.
|
|
1675
|
+
*
|
|
1676
|
+
* Involves decoding up to 4 varints. Typically this will require only 4 to 6
|
|
1677
|
+
* bytes but for larger multicodec code values and larger multihash digest
|
|
1678
|
+
* lengths these varints can be quite large. It is recommended that at least
|
|
1679
|
+
* 10 bytes be made available in the `initialBytes` argument for a complete
|
|
1680
|
+
* inspection.
|
|
1681
|
+
*/
|
|
1682
|
+
static inspectBytes(initialBytes) {
|
|
1683
|
+
let offset = 0;
|
|
1684
|
+
const next = () => {
|
|
1685
|
+
const [i, length2] = decode4(initialBytes.subarray(offset));
|
|
1686
|
+
offset += length2;
|
|
1687
|
+
return i;
|
|
1688
|
+
};
|
|
1689
|
+
let version = next();
|
|
1690
|
+
let codec = DAG_PB_CODE;
|
|
1691
|
+
if (version === 18) {
|
|
1692
|
+
version = 0;
|
|
1693
|
+
offset = 0;
|
|
1694
|
+
} else {
|
|
1695
|
+
codec = next();
|
|
1696
|
+
}
|
|
1697
|
+
if (version !== 0 && version !== 1) {
|
|
1698
|
+
throw new RangeError(`Invalid CID version ${version}`);
|
|
1699
|
+
}
|
|
1700
|
+
const prefixSize = offset;
|
|
1701
|
+
const multihashCode = next();
|
|
1702
|
+
const digestSize = next();
|
|
1703
|
+
const size = offset + digestSize;
|
|
1704
|
+
const multihashSize = size - prefixSize;
|
|
1705
|
+
return { version, codec, multihashCode, digestSize, multihashSize, size };
|
|
1706
|
+
}
|
|
1707
|
+
/**
|
|
1708
|
+
* Takes cid in a string representation and creates an instance. If `base`
|
|
1709
|
+
* decoder is not provided will use a default from the configuration. It will
|
|
1710
|
+
* throw an error if encoding of the CID is not compatible with supplied (or
|
|
1711
|
+
* a default decoder).
|
|
1712
|
+
*/
|
|
1713
|
+
static parse(source, base3) {
|
|
1714
|
+
const [prefix, bytes] = parseCIDtoBytes(source, base3);
|
|
1715
|
+
const cid = _CID.decode(bytes);
|
|
1716
|
+
if (cid.version === 0 && source[0] !== "Q") {
|
|
1717
|
+
throw Error("Version 0 CID string must not include multibase prefix");
|
|
1718
|
+
}
|
|
1719
|
+
baseCache(cid).set(prefix, source);
|
|
1720
|
+
return cid;
|
|
1721
|
+
}
|
|
1722
|
+
};
|
|
1723
|
+
function parseCIDtoBytes(source, base3) {
|
|
1724
|
+
switch (source[0]) {
|
|
1725
|
+
// CIDv0 is parsed differently
|
|
1726
|
+
case "Q": {
|
|
1727
|
+
const decoder = base3 ?? base58btc;
|
|
1728
|
+
return [
|
|
1729
|
+
base58btc.prefix,
|
|
1730
|
+
decoder.decode(`${base58btc.prefix}${source}`)
|
|
1731
|
+
];
|
|
1732
|
+
}
|
|
1733
|
+
case base58btc.prefix: {
|
|
1734
|
+
const decoder = base3 ?? base58btc;
|
|
1735
|
+
return [base58btc.prefix, decoder.decode(source)];
|
|
1736
|
+
}
|
|
1737
|
+
case base32.prefix: {
|
|
1738
|
+
const decoder = base3 ?? base32;
|
|
1739
|
+
return [base32.prefix, decoder.decode(source)];
|
|
1740
|
+
}
|
|
1741
|
+
case base36.prefix: {
|
|
1742
|
+
const decoder = base3 ?? base36;
|
|
1743
|
+
return [base36.prefix, decoder.decode(source)];
|
|
1744
|
+
}
|
|
1745
|
+
default: {
|
|
1746
|
+
if (base3 == null) {
|
|
1747
|
+
throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");
|
|
1748
|
+
}
|
|
1749
|
+
return [source[0], base3.decode(source)];
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
function toStringV0(bytes, cache2, base3) {
|
|
1754
|
+
const { prefix } = base3;
|
|
1755
|
+
if (prefix !== base58btc.prefix) {
|
|
1756
|
+
throw Error(`Cannot string encode V0 in ${base3.name} encoding`);
|
|
1757
|
+
}
|
|
1758
|
+
const cid = cache2.get(prefix);
|
|
1759
|
+
if (cid == null) {
|
|
1760
|
+
const cid2 = base3.encode(bytes).slice(1);
|
|
1761
|
+
cache2.set(prefix, cid2);
|
|
1762
|
+
return cid2;
|
|
1763
|
+
} else {
|
|
1764
|
+
return cid;
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
function toStringV1(bytes, cache2, base3) {
|
|
1768
|
+
const { prefix } = base3;
|
|
1769
|
+
const cid = cache2.get(prefix);
|
|
1770
|
+
if (cid == null) {
|
|
1771
|
+
const cid2 = base3.encode(bytes);
|
|
1772
|
+
cache2.set(prefix, cid2);
|
|
1773
|
+
return cid2;
|
|
1774
|
+
} else {
|
|
1775
|
+
return cid;
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
var DAG_PB_CODE = 112;
|
|
1779
|
+
var SHA_256_CODE = 18;
|
|
1780
|
+
function encodeCID(version, code2, multihash) {
|
|
1781
|
+
const codeOffset = encodingLength(version);
|
|
1782
|
+
const hashOffset = codeOffset + encodingLength(code2);
|
|
1783
|
+
const bytes = new Uint8Array(hashOffset + multihash.byteLength);
|
|
1784
|
+
encodeTo(version, bytes, 0);
|
|
1785
|
+
encodeTo(code2, bytes, codeOffset);
|
|
1786
|
+
bytes.set(multihash, hashOffset);
|
|
1787
|
+
return bytes;
|
|
1788
|
+
}
|
|
1789
|
+
var cidSymbol = /* @__PURE__ */ Symbol.for("@ipld/js-cid/CID");
|
|
1790
|
+
|
|
1791
|
+
// ../../node_modules/multiformats/dist/src/basics.js
|
|
1792
|
+
var bases = { ...identity_exports, ...base2_exports, ...base8_exports, ...base10_exports, ...base16_exports, ...base32_exports, ...base36_exports, ...base58_exports, ...base64_exports, ...base256emoji_exports };
|
|
1793
|
+
var hashes = { ...sha2_exports, ...identity_exports2 };
|
|
1794
|
+
|
|
1795
|
+
// src/policy/signed-object.ts
|
|
1796
|
+
import { bytesToHex as bytesToHex2, sha256 as sha2563, verifyMessage } from "viem";
|
|
643
1797
|
|
|
644
1798
|
// src/identity.ts
|
|
645
1799
|
import { getAddress, isAddress } from "viem";
|
|
@@ -706,7 +1860,7 @@ var DESCRIPTORS = {
|
|
|
706
1860
|
domain: POLICY_ENGINE_RECORD_SCHEMA
|
|
707
1861
|
}
|
|
708
1862
|
};
|
|
709
|
-
var
|
|
1863
|
+
var textEncoder3 = new TextEncoder();
|
|
710
1864
|
var BASE32_ALPHABET = "abcdefghijklmnopqrstuvwxyz234567";
|
|
711
1865
|
var BASE64URL_RE = /^[A-Za-z0-9_-]+$/;
|
|
712
1866
|
var objectHasOwn3 = Object.hasOwn ?? Object.prototype.hasOwnProperty.call.bind(
|
|
@@ -1155,9 +2309,9 @@ function validateAudit(input, path) {
|
|
|
1155
2309
|
}
|
|
1156
2310
|
function materialForUnsigned(unsigned, descriptor) {
|
|
1157
2311
|
const jcs = jcsCanonicalize(unsigned);
|
|
1158
|
-
const jcsBytes =
|
|
1159
|
-
const
|
|
1160
|
-
const id = `${descriptor.idPrefix}${base32LowerNoPad(
|
|
2312
|
+
const jcsBytes = textEncoder3.encode(jcs);
|
|
2313
|
+
const digest2 = sha256Bytes(concatBytes(textEncoder3.encode(`${descriptor.domain}\0`), jcsBytes));
|
|
2314
|
+
const id = `${descriptor.idPrefix}${base32LowerNoPad(digest2)}`;
|
|
1161
2315
|
return {
|
|
1162
2316
|
kind: descriptor.kind,
|
|
1163
2317
|
idField: descriptor.idField,
|
|
@@ -1166,8 +2320,8 @@ function materialForUnsigned(unsigned, descriptor) {
|
|
|
1166
2320
|
unsigned,
|
|
1167
2321
|
jcs,
|
|
1168
2322
|
jcsBytes,
|
|
1169
|
-
digest,
|
|
1170
|
-
digestHex: bytesToHex2(
|
|
2323
|
+
digest: digest2,
|
|
2324
|
+
digestHex: bytesToHex2(digest2).slice(2)
|
|
1171
2325
|
};
|
|
1172
2326
|
}
|
|
1173
2327
|
function assertIdMatches(signed, material, descriptor) {
|
|
@@ -1215,12 +2369,12 @@ function assertSignerDidMatchesSuite(signerDid, suite) {
|
|
|
1215
2369
|
}
|
|
1216
2370
|
throw new UnsupportedSignatureSuiteError(`unsupported signature suite: ${suite}`);
|
|
1217
2371
|
}
|
|
1218
|
-
async function verifySignature(signature,
|
|
2372
|
+
async function verifySignature(signature, digest2) {
|
|
1219
2373
|
if (signature.suite === ED25519_JCS_SIGNATURE_SUITE) {
|
|
1220
2374
|
const publicKey = ed25519PublicKeyFromDidKey(signature.signerDid);
|
|
1221
2375
|
const signatureBytes = decodeSignatureValue(signature.value, signature.suite);
|
|
1222
2376
|
try {
|
|
1223
|
-
return ed25519.verify(signatureBytes,
|
|
2377
|
+
return ed25519.verify(signatureBytes, digest2, publicKey);
|
|
1224
2378
|
} catch {
|
|
1225
2379
|
throw new SignatureVerificationError("Ed25519 signature verification failed");
|
|
1226
2380
|
}
|
|
@@ -1231,7 +2385,7 @@ async function verifySignature(signature, digest) {
|
|
|
1231
2385
|
try {
|
|
1232
2386
|
return verifyMessage({
|
|
1233
2387
|
address: pkh.address,
|
|
1234
|
-
message: { raw:
|
|
2388
|
+
message: { raw: digest2 },
|
|
1235
2389
|
signature: bytesToHex2(signatureBytes)
|
|
1236
2390
|
});
|
|
1237
2391
|
} catch {
|
|
@@ -1437,7 +2591,7 @@ function assertSupportedSignatureSuite(suite) {
|
|
|
1437
2591
|
}
|
|
1438
2592
|
}
|
|
1439
2593
|
function sha256Bytes(bytes) {
|
|
1440
|
-
return
|
|
2594
|
+
return sha2563(bytes, "bytes");
|
|
1441
2595
|
}
|
|
1442
2596
|
function concatBytes(left, right) {
|
|
1443
2597
|
const output = new Uint8Array(left.length + right.length);
|
|
@@ -1463,20 +2617,20 @@ function base32LowerNoPad(bytes) {
|
|
|
1463
2617
|
return output;
|
|
1464
2618
|
}
|
|
1465
2619
|
function base64UrlEncode(bytes) {
|
|
1466
|
-
const
|
|
2620
|
+
const alphabet2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
1467
2621
|
let output = "";
|
|
1468
2622
|
for (let index = 0; index < bytes.length; index += 3) {
|
|
1469
2623
|
const a = bytes[index];
|
|
1470
2624
|
const b = bytes[index + 1];
|
|
1471
2625
|
const c = bytes[index + 2];
|
|
1472
2626
|
const triplet = a << 16 | (b ?? 0) << 8 | (c ?? 0);
|
|
1473
|
-
output +=
|
|
1474
|
-
output +=
|
|
2627
|
+
output += alphabet2[triplet >> 18 & 63];
|
|
2628
|
+
output += alphabet2[triplet >> 12 & 63];
|
|
1475
2629
|
if (index + 1 < bytes.length) {
|
|
1476
|
-
output +=
|
|
2630
|
+
output += alphabet2[triplet >> 6 & 63];
|
|
1477
2631
|
}
|
|
1478
2632
|
if (index + 2 < bytes.length) {
|
|
1479
|
-
output +=
|
|
2633
|
+
output += alphabet2[triplet & 63];
|
|
1480
2634
|
}
|
|
1481
2635
|
}
|
|
1482
2636
|
return output;
|
|
@@ -1485,12 +2639,12 @@ function base64UrlDecode(value) {
|
|
|
1485
2639
|
if (value.length % 4 === 1) {
|
|
1486
2640
|
throw new SignatureMaterialError("signature value is not canonical base64url");
|
|
1487
2641
|
}
|
|
1488
|
-
const
|
|
2642
|
+
const alphabet2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
1489
2643
|
const bytes = [];
|
|
1490
2644
|
let buffer = 0;
|
|
1491
2645
|
let bits = 0;
|
|
1492
2646
|
for (const char of value) {
|
|
1493
|
-
const index =
|
|
2647
|
+
const index = alphabet2.indexOf(char);
|
|
1494
2648
|
if (index < 0) {
|
|
1495
2649
|
throw new SignatureMaterialError("signature value is not base64url");
|
|
1496
2650
|
}
|
|
@@ -1525,10 +2679,10 @@ var OWNER_NODE_ENDPOINT_SCHEMA = "xyz.tinycloud.exchange/owner-node-endpoint/v1"
|
|
|
1525
2679
|
var POLICY_VERSION_V0 = "v0";
|
|
1526
2680
|
var W3C_VC_CREDENTIAL_VERIFIER = "w3c.vc/credential/v1";
|
|
1527
2681
|
var PolicyAuthoringError = class extends Error {
|
|
1528
|
-
constructor(
|
|
2682
|
+
constructor(code2, message) {
|
|
1529
2683
|
super(message);
|
|
1530
2684
|
this.name = "PolicyAuthoringError";
|
|
1531
|
-
this.code =
|
|
2685
|
+
this.code = code2;
|
|
1532
2686
|
}
|
|
1533
2687
|
};
|
|
1534
2688
|
async function createAndSignTranscriptSharePolicy(input, signer) {
|
|
@@ -1832,11 +2986,11 @@ async function verifyPolicyEngineRecordForRequester(options) {
|
|
|
1832
2986
|
}
|
|
1833
2987
|
return verified;
|
|
1834
2988
|
}
|
|
1835
|
-
function expectObject2(input, path,
|
|
2989
|
+
function expectObject2(input, path, code2) {
|
|
1836
2990
|
try {
|
|
1837
2991
|
const normalized = normalizeJson(input);
|
|
1838
2992
|
if (normalized === null || typeof normalized !== "object" || Array.isArray(normalized)) {
|
|
1839
|
-
throw new PolicyAuthoringError(
|
|
2993
|
+
throw new PolicyAuthoringError(code2, `${path} must be an object`);
|
|
1840
2994
|
}
|
|
1841
2995
|
return normalized;
|
|
1842
2996
|
} catch (error) {
|
|
@@ -1844,7 +2998,7 @@ function expectObject2(input, path, code) {
|
|
|
1844
2998
|
throw error;
|
|
1845
2999
|
}
|
|
1846
3000
|
throw new PolicyAuthoringError(
|
|
1847
|
-
|
|
3001
|
+
code2,
|
|
1848
3002
|
error instanceof Error ? error.message : String(error)
|
|
1849
3003
|
);
|
|
1850
3004
|
}
|
|
@@ -1895,14 +3049,14 @@ function requiredString3(object, key, path) {
|
|
|
1895
3049
|
}
|
|
1896
3050
|
return value;
|
|
1897
3051
|
}
|
|
1898
|
-
function fieldString(object, key, path,
|
|
3052
|
+
function fieldString(object, key, path, code2) {
|
|
1899
3053
|
if (!hasOwn3(object, key)) {
|
|
1900
|
-
throw new PolicyAuthoringError(
|
|
3054
|
+
throw new PolicyAuthoringError(code2, `${path}.${key} is required`);
|
|
1901
3055
|
}
|
|
1902
3056
|
const value = object[key];
|
|
1903
3057
|
if (typeof value !== "string" || value.length === 0) {
|
|
1904
3058
|
throw new PolicyAuthoringError(
|
|
1905
|
-
|
|
3059
|
+
code2,
|
|
1906
3060
|
`${path}.${key} must be a non-empty string`
|
|
1907
3061
|
);
|
|
1908
3062
|
}
|