@did-btcr2/method 0.44.0 → 0.45.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/.tsbuildinfo +1 -1
- package/dist/browser.js +14767 -93320
- package/dist/browser.mjs +14746 -93299
- package/dist/cjs/index.js +9 -908
- package/dist/esm/utils/appendix.js +0 -19
- package/dist/esm/utils/appendix.js.map +1 -1
- package/dist/types/utils/appendix.d.ts +0 -7
- package/dist/types/utils/appendix.d.ts.map +1 -1
- package/package.json +5 -7
- package/src/utils/appendix.ts +0 -24
package/dist/cjs/index.js
CHANGED
|
@@ -1,30 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
10
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
9
|
};
|
|
12
|
-
var __copyProps = (to,
|
|
13
|
-
if (
|
|
14
|
-
for (let key of __getOwnPropNames(
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
15
13
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () =>
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/index.ts
|
|
@@ -135,8 +125,8 @@ var DUST_LIMIT_SATS = {
|
|
|
135
125
|
p2tr: 330
|
|
136
126
|
};
|
|
137
127
|
function beaconTxVsize(beaconKind, changeKind) {
|
|
138
|
-
const
|
|
139
|
-
return
|
|
128
|
+
const base = SINGLETON_BEACON_TX_VSIZE[beaconKind] - CHANGE_OUTPUT_VBYTES[beaconKind];
|
|
129
|
+
return base + CHANGE_OUTPUT_VBYTES[changeKind];
|
|
140
130
|
}
|
|
141
131
|
function detectSingletonScriptKind(bitcoinAddress, network) {
|
|
142
132
|
const decoded = (0, import_btc_signer.Address)(network).decode(bitcoinAddress);
|
|
@@ -689,882 +679,6 @@ var import_btc_signer2 = require("@scure/btc-signer");
|
|
|
689
679
|
|
|
690
680
|
// src/utils/appendix.ts
|
|
691
681
|
var import_dids = require("@web5/dids");
|
|
692
|
-
|
|
693
|
-
// ../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/bytes.js
|
|
694
|
-
var empty = new Uint8Array(0);
|
|
695
|
-
function equals(aa, bb) {
|
|
696
|
-
if (aa === bb) {
|
|
697
|
-
return true;
|
|
698
|
-
}
|
|
699
|
-
if (aa.byteLength !== bb.byteLength) {
|
|
700
|
-
return false;
|
|
701
|
-
}
|
|
702
|
-
for (let ii = 0; ii < aa.byteLength; ii++) {
|
|
703
|
-
if (aa[ii] !== bb[ii]) {
|
|
704
|
-
return false;
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
return true;
|
|
708
|
-
}
|
|
709
|
-
function coerce(o) {
|
|
710
|
-
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array") {
|
|
711
|
-
return o;
|
|
712
|
-
}
|
|
713
|
-
if (o instanceof ArrayBuffer) {
|
|
714
|
-
return new Uint8Array(o);
|
|
715
|
-
}
|
|
716
|
-
if (ArrayBuffer.isView(o)) {
|
|
717
|
-
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
|
|
718
|
-
}
|
|
719
|
-
throw new Error("Unknown type, must be binary type");
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
// ../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/vendor/base-x.js
|
|
723
|
-
function base(ALPHABET, name) {
|
|
724
|
-
if (ALPHABET.length >= 255) {
|
|
725
|
-
throw new TypeError("Alphabet too long");
|
|
726
|
-
}
|
|
727
|
-
var BASE_MAP = new Uint8Array(256);
|
|
728
|
-
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
729
|
-
BASE_MAP[j] = 255;
|
|
730
|
-
}
|
|
731
|
-
for (var i = 0; i < ALPHABET.length; i++) {
|
|
732
|
-
var x = ALPHABET.charAt(i);
|
|
733
|
-
var xc = x.charCodeAt(0);
|
|
734
|
-
if (BASE_MAP[xc] !== 255) {
|
|
735
|
-
throw new TypeError(x + " is ambiguous");
|
|
736
|
-
}
|
|
737
|
-
BASE_MAP[xc] = i;
|
|
738
|
-
}
|
|
739
|
-
var BASE = ALPHABET.length;
|
|
740
|
-
var LEADER = ALPHABET.charAt(0);
|
|
741
|
-
var FACTOR = Math.log(BASE) / Math.log(256);
|
|
742
|
-
var iFACTOR = Math.log(256) / Math.log(BASE);
|
|
743
|
-
function encode4(source) {
|
|
744
|
-
if (source instanceof Uint8Array)
|
|
745
|
-
;
|
|
746
|
-
else if (ArrayBuffer.isView(source)) {
|
|
747
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
748
|
-
} else if (Array.isArray(source)) {
|
|
749
|
-
source = Uint8Array.from(source);
|
|
750
|
-
}
|
|
751
|
-
if (!(source instanceof Uint8Array)) {
|
|
752
|
-
throw new TypeError("Expected Uint8Array");
|
|
753
|
-
}
|
|
754
|
-
if (source.length === 0) {
|
|
755
|
-
return "";
|
|
756
|
-
}
|
|
757
|
-
var zeroes = 0;
|
|
758
|
-
var length2 = 0;
|
|
759
|
-
var pbegin = 0;
|
|
760
|
-
var pend = source.length;
|
|
761
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
762
|
-
pbegin++;
|
|
763
|
-
zeroes++;
|
|
764
|
-
}
|
|
765
|
-
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
766
|
-
var b58 = new Uint8Array(size);
|
|
767
|
-
while (pbegin !== pend) {
|
|
768
|
-
var carry = source[pbegin];
|
|
769
|
-
var i2 = 0;
|
|
770
|
-
for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
|
|
771
|
-
carry += 256 * b58[it1] >>> 0;
|
|
772
|
-
b58[it1] = carry % BASE >>> 0;
|
|
773
|
-
carry = carry / BASE >>> 0;
|
|
774
|
-
}
|
|
775
|
-
if (carry !== 0) {
|
|
776
|
-
throw new Error("Non-zero carry");
|
|
777
|
-
}
|
|
778
|
-
length2 = i2;
|
|
779
|
-
pbegin++;
|
|
780
|
-
}
|
|
781
|
-
var it2 = size - length2;
|
|
782
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
783
|
-
it2++;
|
|
784
|
-
}
|
|
785
|
-
var str = LEADER.repeat(zeroes);
|
|
786
|
-
for (; it2 < size; ++it2) {
|
|
787
|
-
str += ALPHABET.charAt(b58[it2]);
|
|
788
|
-
}
|
|
789
|
-
return str;
|
|
790
|
-
}
|
|
791
|
-
function decodeUnsafe(source) {
|
|
792
|
-
if (typeof source !== "string") {
|
|
793
|
-
throw new TypeError("Expected String");
|
|
794
|
-
}
|
|
795
|
-
if (source.length === 0) {
|
|
796
|
-
return new Uint8Array();
|
|
797
|
-
}
|
|
798
|
-
var psz = 0;
|
|
799
|
-
if (source[psz] === " ") {
|
|
800
|
-
return;
|
|
801
|
-
}
|
|
802
|
-
var zeroes = 0;
|
|
803
|
-
var length2 = 0;
|
|
804
|
-
while (source[psz] === LEADER) {
|
|
805
|
-
zeroes++;
|
|
806
|
-
psz++;
|
|
807
|
-
}
|
|
808
|
-
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
809
|
-
var b256 = new Uint8Array(size);
|
|
810
|
-
while (source[psz]) {
|
|
811
|
-
var carry = BASE_MAP[source.charCodeAt(psz)];
|
|
812
|
-
if (carry === 255) {
|
|
813
|
-
return;
|
|
814
|
-
}
|
|
815
|
-
var i2 = 0;
|
|
816
|
-
for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
|
|
817
|
-
carry += BASE * b256[it3] >>> 0;
|
|
818
|
-
b256[it3] = carry % 256 >>> 0;
|
|
819
|
-
carry = carry / 256 >>> 0;
|
|
820
|
-
}
|
|
821
|
-
if (carry !== 0) {
|
|
822
|
-
throw new Error("Non-zero carry");
|
|
823
|
-
}
|
|
824
|
-
length2 = i2;
|
|
825
|
-
psz++;
|
|
826
|
-
}
|
|
827
|
-
if (source[psz] === " ") {
|
|
828
|
-
return;
|
|
829
|
-
}
|
|
830
|
-
var it4 = size - length2;
|
|
831
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
832
|
-
it4++;
|
|
833
|
-
}
|
|
834
|
-
var vch = new Uint8Array(zeroes + (size - it4));
|
|
835
|
-
var j2 = zeroes;
|
|
836
|
-
while (it4 !== size) {
|
|
837
|
-
vch[j2++] = b256[it4++];
|
|
838
|
-
}
|
|
839
|
-
return vch;
|
|
840
|
-
}
|
|
841
|
-
function decode6(string) {
|
|
842
|
-
var buffer = decodeUnsafe(string);
|
|
843
|
-
if (buffer) {
|
|
844
|
-
return buffer;
|
|
845
|
-
}
|
|
846
|
-
throw new Error(`Non-${name} character`);
|
|
847
|
-
}
|
|
848
|
-
return {
|
|
849
|
-
encode: encode4,
|
|
850
|
-
decodeUnsafe,
|
|
851
|
-
decode: decode6
|
|
852
|
-
};
|
|
853
|
-
}
|
|
854
|
-
var src = base;
|
|
855
|
-
var _brrp__multiformats_scope_baseX = src;
|
|
856
|
-
var base_x_default = _brrp__multiformats_scope_baseX;
|
|
857
|
-
|
|
858
|
-
// ../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/bases/base.js
|
|
859
|
-
var Encoder = class {
|
|
860
|
-
name;
|
|
861
|
-
prefix;
|
|
862
|
-
baseEncode;
|
|
863
|
-
constructor(name, prefix, baseEncode) {
|
|
864
|
-
this.name = name;
|
|
865
|
-
this.prefix = prefix;
|
|
866
|
-
this.baseEncode = baseEncode;
|
|
867
|
-
}
|
|
868
|
-
encode(bytes) {
|
|
869
|
-
if (bytes instanceof Uint8Array) {
|
|
870
|
-
return `${this.prefix}${this.baseEncode(bytes)}`;
|
|
871
|
-
} else {
|
|
872
|
-
throw Error("Unknown type, must be binary type");
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
};
|
|
876
|
-
var Decoder = class {
|
|
877
|
-
name;
|
|
878
|
-
prefix;
|
|
879
|
-
baseDecode;
|
|
880
|
-
prefixCodePoint;
|
|
881
|
-
constructor(name, prefix, baseDecode) {
|
|
882
|
-
this.name = name;
|
|
883
|
-
this.prefix = prefix;
|
|
884
|
-
const prefixCodePoint = prefix.codePointAt(0);
|
|
885
|
-
if (prefixCodePoint === void 0) {
|
|
886
|
-
throw new Error("Invalid prefix character");
|
|
887
|
-
}
|
|
888
|
-
this.prefixCodePoint = prefixCodePoint;
|
|
889
|
-
this.baseDecode = baseDecode;
|
|
890
|
-
}
|
|
891
|
-
decode(text) {
|
|
892
|
-
if (typeof text === "string") {
|
|
893
|
-
if (text.codePointAt(0) !== this.prefixCodePoint) {
|
|
894
|
-
throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
|
|
895
|
-
}
|
|
896
|
-
return this.baseDecode(text.slice(this.prefix.length));
|
|
897
|
-
} else {
|
|
898
|
-
throw Error("Can only multibase decode strings");
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
or(decoder) {
|
|
902
|
-
return or(this, decoder);
|
|
903
|
-
}
|
|
904
|
-
};
|
|
905
|
-
var ComposedDecoder = class {
|
|
906
|
-
decoders;
|
|
907
|
-
constructor(decoders) {
|
|
908
|
-
this.decoders = decoders;
|
|
909
|
-
}
|
|
910
|
-
or(decoder) {
|
|
911
|
-
return or(this, decoder);
|
|
912
|
-
}
|
|
913
|
-
decode(input) {
|
|
914
|
-
const prefix = input[0];
|
|
915
|
-
const decoder = this.decoders[prefix];
|
|
916
|
-
if (decoder != null) {
|
|
917
|
-
return decoder.decode(input);
|
|
918
|
-
} else {
|
|
919
|
-
throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
};
|
|
923
|
-
function or(left, right) {
|
|
924
|
-
return new ComposedDecoder({
|
|
925
|
-
...left.decoders ?? { [left.prefix]: left },
|
|
926
|
-
...right.decoders ?? { [right.prefix]: right }
|
|
927
|
-
});
|
|
928
|
-
}
|
|
929
|
-
var Codec = class {
|
|
930
|
-
name;
|
|
931
|
-
prefix;
|
|
932
|
-
baseEncode;
|
|
933
|
-
baseDecode;
|
|
934
|
-
encoder;
|
|
935
|
-
decoder;
|
|
936
|
-
constructor(name, prefix, baseEncode, baseDecode) {
|
|
937
|
-
this.name = name;
|
|
938
|
-
this.prefix = prefix;
|
|
939
|
-
this.baseEncode = baseEncode;
|
|
940
|
-
this.baseDecode = baseDecode;
|
|
941
|
-
this.encoder = new Encoder(name, prefix, baseEncode);
|
|
942
|
-
this.decoder = new Decoder(name, prefix, baseDecode);
|
|
943
|
-
}
|
|
944
|
-
encode(input) {
|
|
945
|
-
return this.encoder.encode(input);
|
|
946
|
-
}
|
|
947
|
-
decode(input) {
|
|
948
|
-
return this.decoder.decode(input);
|
|
949
|
-
}
|
|
950
|
-
};
|
|
951
|
-
function from({ name, prefix, encode: encode4, decode: decode6 }) {
|
|
952
|
-
return new Codec(name, prefix, encode4, decode6);
|
|
953
|
-
}
|
|
954
|
-
function baseX({ name, prefix, alphabet }) {
|
|
955
|
-
const { encode: encode4, decode: decode6 } = base_x_default(alphabet, name);
|
|
956
|
-
return from({
|
|
957
|
-
prefix,
|
|
958
|
-
name,
|
|
959
|
-
encode: encode4,
|
|
960
|
-
decode: (text) => coerce(decode6(text))
|
|
961
|
-
});
|
|
962
|
-
}
|
|
963
|
-
function decode2(string, alphabetIdx, bitsPerChar, name) {
|
|
964
|
-
let end = string.length;
|
|
965
|
-
while (string[end - 1] === "=") {
|
|
966
|
-
--end;
|
|
967
|
-
}
|
|
968
|
-
const out = new Uint8Array(end * bitsPerChar / 8 | 0);
|
|
969
|
-
let bits = 0;
|
|
970
|
-
let buffer = 0;
|
|
971
|
-
let written = 0;
|
|
972
|
-
for (let i = 0; i < end; ++i) {
|
|
973
|
-
const value = alphabetIdx[string[i]];
|
|
974
|
-
if (value === void 0) {
|
|
975
|
-
throw new SyntaxError(`Non-${name} character`);
|
|
976
|
-
}
|
|
977
|
-
buffer = buffer << bitsPerChar | value;
|
|
978
|
-
bits += bitsPerChar;
|
|
979
|
-
if (bits >= 8) {
|
|
980
|
-
bits -= 8;
|
|
981
|
-
out[written++] = 255 & buffer >> bits;
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
if (bits >= bitsPerChar || (255 & buffer << 8 - bits) !== 0) {
|
|
985
|
-
throw new SyntaxError("Unexpected end of data");
|
|
986
|
-
}
|
|
987
|
-
return out;
|
|
988
|
-
}
|
|
989
|
-
function encode2(data, alphabet, bitsPerChar) {
|
|
990
|
-
const pad = alphabet[alphabet.length - 1] === "=";
|
|
991
|
-
const mask = (1 << bitsPerChar) - 1;
|
|
992
|
-
let out = "";
|
|
993
|
-
let bits = 0;
|
|
994
|
-
let buffer = 0;
|
|
995
|
-
for (let i = 0; i < data.length; ++i) {
|
|
996
|
-
buffer = buffer << 8 | data[i];
|
|
997
|
-
bits += 8;
|
|
998
|
-
while (bits > bitsPerChar) {
|
|
999
|
-
bits -= bitsPerChar;
|
|
1000
|
-
out += alphabet[mask & buffer >> bits];
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
if (bits !== 0) {
|
|
1004
|
-
out += alphabet[mask & buffer << bitsPerChar - bits];
|
|
1005
|
-
}
|
|
1006
|
-
if (pad) {
|
|
1007
|
-
while ((out.length * bitsPerChar & 7) !== 0) {
|
|
1008
|
-
out += "=";
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
return out;
|
|
1012
|
-
}
|
|
1013
|
-
function createAlphabetIdx(alphabet) {
|
|
1014
|
-
const alphabetIdx = {};
|
|
1015
|
-
for (let i = 0; i < alphabet.length; ++i) {
|
|
1016
|
-
alphabetIdx[alphabet[i]] = i;
|
|
1017
|
-
}
|
|
1018
|
-
return alphabetIdx;
|
|
1019
|
-
}
|
|
1020
|
-
function rfc4648({ name, prefix, bitsPerChar, alphabet }) {
|
|
1021
|
-
const alphabetIdx = createAlphabetIdx(alphabet);
|
|
1022
|
-
return from({
|
|
1023
|
-
prefix,
|
|
1024
|
-
name,
|
|
1025
|
-
encode(input) {
|
|
1026
|
-
return encode2(input, alphabet, bitsPerChar);
|
|
1027
|
-
},
|
|
1028
|
-
decode(input) {
|
|
1029
|
-
return decode2(input, alphabetIdx, bitsPerChar, name);
|
|
1030
|
-
}
|
|
1031
|
-
});
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
// ../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/bases/base32.js
|
|
1035
|
-
var base32 = rfc4648({
|
|
1036
|
-
prefix: "b",
|
|
1037
|
-
name: "base32",
|
|
1038
|
-
alphabet: "abcdefghijklmnopqrstuvwxyz234567",
|
|
1039
|
-
bitsPerChar: 5
|
|
1040
|
-
});
|
|
1041
|
-
var base32upper = rfc4648({
|
|
1042
|
-
prefix: "B",
|
|
1043
|
-
name: "base32upper",
|
|
1044
|
-
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
|
|
1045
|
-
bitsPerChar: 5
|
|
1046
|
-
});
|
|
1047
|
-
var base32pad = rfc4648({
|
|
1048
|
-
prefix: "c",
|
|
1049
|
-
name: "base32pad",
|
|
1050
|
-
alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
|
|
1051
|
-
bitsPerChar: 5
|
|
1052
|
-
});
|
|
1053
|
-
var base32padupper = rfc4648({
|
|
1054
|
-
prefix: "C",
|
|
1055
|
-
name: "base32padupper",
|
|
1056
|
-
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
|
|
1057
|
-
bitsPerChar: 5
|
|
1058
|
-
});
|
|
1059
|
-
var base32hex = rfc4648({
|
|
1060
|
-
prefix: "v",
|
|
1061
|
-
name: "base32hex",
|
|
1062
|
-
alphabet: "0123456789abcdefghijklmnopqrstuv",
|
|
1063
|
-
bitsPerChar: 5
|
|
1064
|
-
});
|
|
1065
|
-
var base32hexupper = rfc4648({
|
|
1066
|
-
prefix: "V",
|
|
1067
|
-
name: "base32hexupper",
|
|
1068
|
-
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
|
|
1069
|
-
bitsPerChar: 5
|
|
1070
|
-
});
|
|
1071
|
-
var base32hexpad = rfc4648({
|
|
1072
|
-
prefix: "t",
|
|
1073
|
-
name: "base32hexpad",
|
|
1074
|
-
alphabet: "0123456789abcdefghijklmnopqrstuv=",
|
|
1075
|
-
bitsPerChar: 5
|
|
1076
|
-
});
|
|
1077
|
-
var base32hexpadupper = rfc4648({
|
|
1078
|
-
prefix: "T",
|
|
1079
|
-
name: "base32hexpadupper",
|
|
1080
|
-
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
|
|
1081
|
-
bitsPerChar: 5
|
|
1082
|
-
});
|
|
1083
|
-
var base32z = rfc4648({
|
|
1084
|
-
prefix: "h",
|
|
1085
|
-
name: "base32z",
|
|
1086
|
-
alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
|
|
1087
|
-
bitsPerChar: 5
|
|
1088
|
-
});
|
|
1089
|
-
|
|
1090
|
-
// ../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/bases/base36.js
|
|
1091
|
-
var base36 = baseX({
|
|
1092
|
-
prefix: "k",
|
|
1093
|
-
name: "base36",
|
|
1094
|
-
alphabet: "0123456789abcdefghijklmnopqrstuvwxyz"
|
|
1095
|
-
});
|
|
1096
|
-
var base36upper = baseX({
|
|
1097
|
-
prefix: "K",
|
|
1098
|
-
name: "base36upper",
|
|
1099
|
-
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
1100
|
-
});
|
|
1101
|
-
|
|
1102
|
-
// ../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/bases/base58.js
|
|
1103
|
-
var base58btc = baseX({
|
|
1104
|
-
name: "base58btc",
|
|
1105
|
-
prefix: "z",
|
|
1106
|
-
alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
|
1107
|
-
});
|
|
1108
|
-
var base58flickr = baseX({
|
|
1109
|
-
name: "base58flickr",
|
|
1110
|
-
prefix: "Z",
|
|
1111
|
-
alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
|
|
1112
|
-
});
|
|
1113
|
-
|
|
1114
|
-
// ../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/vendor/varint.js
|
|
1115
|
-
var encode_1 = encode3;
|
|
1116
|
-
var MSB = 128;
|
|
1117
|
-
var REST = 127;
|
|
1118
|
-
var MSBALL = ~REST;
|
|
1119
|
-
var INT = Math.pow(2, 31);
|
|
1120
|
-
function encode3(num, out, offset) {
|
|
1121
|
-
out = out || [];
|
|
1122
|
-
offset = offset || 0;
|
|
1123
|
-
var oldOffset = offset;
|
|
1124
|
-
while (num >= INT) {
|
|
1125
|
-
out[offset++] = num & 255 | MSB;
|
|
1126
|
-
num /= 128;
|
|
1127
|
-
}
|
|
1128
|
-
while (num & MSBALL) {
|
|
1129
|
-
out[offset++] = num & 255 | MSB;
|
|
1130
|
-
num >>>= 7;
|
|
1131
|
-
}
|
|
1132
|
-
out[offset] = num | 0;
|
|
1133
|
-
encode3.bytes = offset - oldOffset + 1;
|
|
1134
|
-
return out;
|
|
1135
|
-
}
|
|
1136
|
-
var decode3 = read;
|
|
1137
|
-
var MSB$1 = 128;
|
|
1138
|
-
var REST$1 = 127;
|
|
1139
|
-
function read(buf, offset) {
|
|
1140
|
-
var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
|
|
1141
|
-
do {
|
|
1142
|
-
if (counter >= l) {
|
|
1143
|
-
read.bytes = 0;
|
|
1144
|
-
throw new RangeError("Could not decode varint");
|
|
1145
|
-
}
|
|
1146
|
-
b = buf[counter++];
|
|
1147
|
-
res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
|
|
1148
|
-
shift += 7;
|
|
1149
|
-
} while (b >= MSB$1);
|
|
1150
|
-
read.bytes = counter - offset;
|
|
1151
|
-
return res;
|
|
1152
|
-
}
|
|
1153
|
-
var N1 = Math.pow(2, 7);
|
|
1154
|
-
var N2 = Math.pow(2, 14);
|
|
1155
|
-
var N3 = Math.pow(2, 21);
|
|
1156
|
-
var N4 = Math.pow(2, 28);
|
|
1157
|
-
var N5 = Math.pow(2, 35);
|
|
1158
|
-
var N6 = Math.pow(2, 42);
|
|
1159
|
-
var N7 = Math.pow(2, 49);
|
|
1160
|
-
var N8 = Math.pow(2, 56);
|
|
1161
|
-
var N9 = Math.pow(2, 63);
|
|
1162
|
-
var length = function(value) {
|
|
1163
|
-
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;
|
|
1164
|
-
};
|
|
1165
|
-
var varint = {
|
|
1166
|
-
encode: encode_1,
|
|
1167
|
-
decode: decode3,
|
|
1168
|
-
encodingLength: length
|
|
1169
|
-
};
|
|
1170
|
-
var _brrp_varint = varint;
|
|
1171
|
-
var varint_default = _brrp_varint;
|
|
1172
|
-
|
|
1173
|
-
// ../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/varint.js
|
|
1174
|
-
function decode4(data, offset = 0) {
|
|
1175
|
-
const code = varint_default.decode(data, offset);
|
|
1176
|
-
return [code, varint_default.decode.bytes];
|
|
1177
|
-
}
|
|
1178
|
-
function encodeTo(int, target, offset = 0) {
|
|
1179
|
-
varint_default.encode(int, target, offset);
|
|
1180
|
-
return target;
|
|
1181
|
-
}
|
|
1182
|
-
function encodingLength(int) {
|
|
1183
|
-
return varint_default.encodingLength(int);
|
|
1184
|
-
}
|
|
1185
|
-
|
|
1186
|
-
// ../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/hashes/digest.js
|
|
1187
|
-
function create(code, digest) {
|
|
1188
|
-
const size = digest.byteLength;
|
|
1189
|
-
const sizeOffset = encodingLength(code);
|
|
1190
|
-
const digestOffset = sizeOffset + encodingLength(size);
|
|
1191
|
-
const bytes = new Uint8Array(digestOffset + size);
|
|
1192
|
-
encodeTo(code, bytes, 0);
|
|
1193
|
-
encodeTo(size, bytes, sizeOffset);
|
|
1194
|
-
bytes.set(digest, digestOffset);
|
|
1195
|
-
return new Digest(code, size, digest, bytes);
|
|
1196
|
-
}
|
|
1197
|
-
function decode5(multihash) {
|
|
1198
|
-
const bytes = coerce(multihash);
|
|
1199
|
-
const [code, sizeOffset] = decode4(bytes);
|
|
1200
|
-
const [size, digestOffset] = decode4(bytes.subarray(sizeOffset));
|
|
1201
|
-
const digest = bytes.subarray(sizeOffset + digestOffset);
|
|
1202
|
-
if (digest.byteLength !== size) {
|
|
1203
|
-
throw new Error("Incorrect length");
|
|
1204
|
-
}
|
|
1205
|
-
return new Digest(code, size, digest, bytes);
|
|
1206
|
-
}
|
|
1207
|
-
function equals2(a, b) {
|
|
1208
|
-
if (a === b) {
|
|
1209
|
-
return true;
|
|
1210
|
-
} else {
|
|
1211
|
-
const data = b;
|
|
1212
|
-
return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals(a.bytes, data.bytes);
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
var Digest = class {
|
|
1216
|
-
code;
|
|
1217
|
-
size;
|
|
1218
|
-
digest;
|
|
1219
|
-
bytes;
|
|
1220
|
-
/**
|
|
1221
|
-
* Creates a multihash digest.
|
|
1222
|
-
*/
|
|
1223
|
-
constructor(code, size, digest, bytes) {
|
|
1224
|
-
this.code = code;
|
|
1225
|
-
this.size = size;
|
|
1226
|
-
this.digest = digest;
|
|
1227
|
-
this.bytes = bytes;
|
|
1228
|
-
}
|
|
1229
|
-
};
|
|
1230
|
-
|
|
1231
|
-
// ../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/cid.js
|
|
1232
|
-
function format(link, base2) {
|
|
1233
|
-
const { bytes, version } = link;
|
|
1234
|
-
switch (version) {
|
|
1235
|
-
case 0:
|
|
1236
|
-
return toStringV0(bytes, baseCache(link), base2 ?? base58btc.encoder);
|
|
1237
|
-
default:
|
|
1238
|
-
return toStringV1(bytes, baseCache(link), base2 ?? base32.encoder);
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
var cache = /* @__PURE__ */ new WeakMap();
|
|
1242
|
-
function baseCache(cid) {
|
|
1243
|
-
const baseCache2 = cache.get(cid);
|
|
1244
|
-
if (baseCache2 == null) {
|
|
1245
|
-
const baseCache3 = /* @__PURE__ */ new Map();
|
|
1246
|
-
cache.set(cid, baseCache3);
|
|
1247
|
-
return baseCache3;
|
|
1248
|
-
}
|
|
1249
|
-
return baseCache2;
|
|
1250
|
-
}
|
|
1251
|
-
var CID = class _CID {
|
|
1252
|
-
code;
|
|
1253
|
-
version;
|
|
1254
|
-
multihash;
|
|
1255
|
-
bytes;
|
|
1256
|
-
"/";
|
|
1257
|
-
/**
|
|
1258
|
-
* @param version - Version of the CID
|
|
1259
|
-
* @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
1260
|
-
* @param multihash - (Multi)hash of the of the content.
|
|
1261
|
-
*/
|
|
1262
|
-
constructor(version, code, multihash, bytes) {
|
|
1263
|
-
this.code = code;
|
|
1264
|
-
this.version = version;
|
|
1265
|
-
this.multihash = multihash;
|
|
1266
|
-
this.bytes = bytes;
|
|
1267
|
-
this["/"] = bytes;
|
|
1268
|
-
}
|
|
1269
|
-
/**
|
|
1270
|
-
* Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes`
|
|
1271
|
-
* please either use `CID.asCID(cid)` or switch to new signalling mechanism
|
|
1272
|
-
*
|
|
1273
|
-
* @deprecated
|
|
1274
|
-
*/
|
|
1275
|
-
get asCID() {
|
|
1276
|
-
return this;
|
|
1277
|
-
}
|
|
1278
|
-
// ArrayBufferView
|
|
1279
|
-
get byteOffset() {
|
|
1280
|
-
return this.bytes.byteOffset;
|
|
1281
|
-
}
|
|
1282
|
-
// ArrayBufferView
|
|
1283
|
-
get byteLength() {
|
|
1284
|
-
return this.bytes.byteLength;
|
|
1285
|
-
}
|
|
1286
|
-
toV0() {
|
|
1287
|
-
switch (this.version) {
|
|
1288
|
-
case 0: {
|
|
1289
|
-
return this;
|
|
1290
|
-
}
|
|
1291
|
-
case 1: {
|
|
1292
|
-
const { code, multihash } = this;
|
|
1293
|
-
if (code !== DAG_PB_CODE) {
|
|
1294
|
-
throw new Error("Cannot convert a non dag-pb CID to CIDv0");
|
|
1295
|
-
}
|
|
1296
|
-
if (multihash.code !== SHA_256_CODE) {
|
|
1297
|
-
throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
|
|
1298
|
-
}
|
|
1299
|
-
return _CID.createV0(multihash);
|
|
1300
|
-
}
|
|
1301
|
-
default: {
|
|
1302
|
-
throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`);
|
|
1303
|
-
}
|
|
1304
|
-
}
|
|
1305
|
-
}
|
|
1306
|
-
toV1() {
|
|
1307
|
-
switch (this.version) {
|
|
1308
|
-
case 0: {
|
|
1309
|
-
const { code, digest } = this.multihash;
|
|
1310
|
-
const multihash = create(code, digest);
|
|
1311
|
-
return _CID.createV1(this.code, multihash);
|
|
1312
|
-
}
|
|
1313
|
-
case 1: {
|
|
1314
|
-
return this;
|
|
1315
|
-
}
|
|
1316
|
-
default: {
|
|
1317
|
-
throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`);
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
}
|
|
1321
|
-
equals(other) {
|
|
1322
|
-
return _CID.equals(this, other);
|
|
1323
|
-
}
|
|
1324
|
-
static equals(self, other) {
|
|
1325
|
-
const unknown = other;
|
|
1326
|
-
return unknown != null && self.code === unknown.code && self.version === unknown.version && equals2(self.multihash, unknown.multihash);
|
|
1327
|
-
}
|
|
1328
|
-
toString(base2) {
|
|
1329
|
-
return format(this, base2);
|
|
1330
|
-
}
|
|
1331
|
-
toJSON() {
|
|
1332
|
-
return { "/": format(this) };
|
|
1333
|
-
}
|
|
1334
|
-
link() {
|
|
1335
|
-
return this;
|
|
1336
|
-
}
|
|
1337
|
-
[Symbol.toStringTag] = "CID";
|
|
1338
|
-
// Legacy
|
|
1339
|
-
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
1340
|
-
return `CID(${this.toString()})`;
|
|
1341
|
-
}
|
|
1342
|
-
/**
|
|
1343
|
-
* Takes any input `value` and returns a `CID` instance if it was
|
|
1344
|
-
* a `CID` otherwise returns `null`. If `value` is instanceof `CID`
|
|
1345
|
-
* it will return value back. If `value` is not instance of this CID
|
|
1346
|
-
* class, but is compatible CID it will return new instance of this
|
|
1347
|
-
* `CID` class. Otherwise returns null.
|
|
1348
|
-
*
|
|
1349
|
-
* This allows two different incompatible versions of CID library to
|
|
1350
|
-
* co-exist and interop as long as binary interface is compatible.
|
|
1351
|
-
*/
|
|
1352
|
-
static asCID(input) {
|
|
1353
|
-
if (input == null) {
|
|
1354
|
-
return null;
|
|
1355
|
-
}
|
|
1356
|
-
const value = input;
|
|
1357
|
-
if (value instanceof _CID) {
|
|
1358
|
-
return value;
|
|
1359
|
-
} else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) {
|
|
1360
|
-
const { version, code, multihash, bytes } = value;
|
|
1361
|
-
return new _CID(version, code, multihash, bytes ?? encodeCID(version, code, multihash.bytes));
|
|
1362
|
-
} else if (value[cidSymbol] === true) {
|
|
1363
|
-
const { version, multihash, code } = value;
|
|
1364
|
-
const digest = decode5(multihash);
|
|
1365
|
-
return _CID.create(version, code, digest);
|
|
1366
|
-
} else {
|
|
1367
|
-
return null;
|
|
1368
|
-
}
|
|
1369
|
-
}
|
|
1370
|
-
/**
|
|
1371
|
-
* @param version - Version of the CID
|
|
1372
|
-
* @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
|
|
1373
|
-
* @param digest - (Multi)hash of the of the content.
|
|
1374
|
-
*/
|
|
1375
|
-
static create(version, code, digest) {
|
|
1376
|
-
if (typeof code !== "number") {
|
|
1377
|
-
throw new Error("String codecs are no longer supported");
|
|
1378
|
-
}
|
|
1379
|
-
if (!(digest.bytes instanceof Uint8Array)) {
|
|
1380
|
-
throw new Error("Invalid digest");
|
|
1381
|
-
}
|
|
1382
|
-
switch (version) {
|
|
1383
|
-
case 0: {
|
|
1384
|
-
if (code !== DAG_PB_CODE) {
|
|
1385
|
-
throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`);
|
|
1386
|
-
} else {
|
|
1387
|
-
return new _CID(version, code, digest, digest.bytes);
|
|
1388
|
-
}
|
|
1389
|
-
}
|
|
1390
|
-
case 1: {
|
|
1391
|
-
const bytes = encodeCID(version, code, digest.bytes);
|
|
1392
|
-
return new _CID(version, code, digest, bytes);
|
|
1393
|
-
}
|
|
1394
|
-
default: {
|
|
1395
|
-
throw new Error("Invalid version");
|
|
1396
|
-
}
|
|
1397
|
-
}
|
|
1398
|
-
}
|
|
1399
|
-
/**
|
|
1400
|
-
* Simplified version of `create` for CIDv0.
|
|
1401
|
-
*/
|
|
1402
|
-
static createV0(digest) {
|
|
1403
|
-
return _CID.create(0, DAG_PB_CODE, digest);
|
|
1404
|
-
}
|
|
1405
|
-
/**
|
|
1406
|
-
* Simplified version of `create` for CIDv1.
|
|
1407
|
-
*
|
|
1408
|
-
* @param code - Content encoding format code.
|
|
1409
|
-
* @param digest - Multihash of the content.
|
|
1410
|
-
*/
|
|
1411
|
-
static createV1(code, digest) {
|
|
1412
|
-
return _CID.create(1, code, digest);
|
|
1413
|
-
}
|
|
1414
|
-
/**
|
|
1415
|
-
* Decoded a CID from its binary representation. The byte array must contain
|
|
1416
|
-
* only the CID with no additional bytes.
|
|
1417
|
-
*
|
|
1418
|
-
* An error will be thrown if the bytes provided do not contain a valid
|
|
1419
|
-
* binary representation of a CID.
|
|
1420
|
-
*/
|
|
1421
|
-
static decode(bytes) {
|
|
1422
|
-
const [cid, remainder] = _CID.decodeFirst(bytes);
|
|
1423
|
-
if (remainder.length !== 0) {
|
|
1424
|
-
throw new Error("Incorrect length");
|
|
1425
|
-
}
|
|
1426
|
-
return cid;
|
|
1427
|
-
}
|
|
1428
|
-
/**
|
|
1429
|
-
* Decoded a CID from its binary representation at the beginning of a byte
|
|
1430
|
-
* array.
|
|
1431
|
-
*
|
|
1432
|
-
* Returns an array with the first element containing the CID and the second
|
|
1433
|
-
* element containing the remainder of the original byte array. The remainder
|
|
1434
|
-
* will be a zero-length byte array if the provided bytes only contained a
|
|
1435
|
-
* binary CID representation.
|
|
1436
|
-
*/
|
|
1437
|
-
static decodeFirst(bytes) {
|
|
1438
|
-
const specs = _CID.inspectBytes(bytes);
|
|
1439
|
-
const prefixSize = specs.size - specs.multihashSize;
|
|
1440
|
-
const multihashBytes = coerce(bytes.subarray(prefixSize, prefixSize + specs.multihashSize));
|
|
1441
|
-
if (multihashBytes.byteLength !== specs.multihashSize) {
|
|
1442
|
-
throw new Error("Incorrect length");
|
|
1443
|
-
}
|
|
1444
|
-
const digestBytes = multihashBytes.subarray(specs.multihashSize - specs.digestSize);
|
|
1445
|
-
const digest = new Digest(specs.multihashCode, specs.digestSize, digestBytes, multihashBytes);
|
|
1446
|
-
const cid = specs.version === 0 ? _CID.createV0(digest) : _CID.createV1(specs.codec, digest);
|
|
1447
|
-
return [cid, bytes.subarray(specs.size)];
|
|
1448
|
-
}
|
|
1449
|
-
/**
|
|
1450
|
-
* Inspect the initial bytes of a CID to determine its properties.
|
|
1451
|
-
*
|
|
1452
|
-
* Involves decoding up to 4 varints. Typically this will require only 4 to 6
|
|
1453
|
-
* bytes but for larger multicodec code values and larger multihash digest
|
|
1454
|
-
* lengths these varints can be quite large. It is recommended that at least
|
|
1455
|
-
* 10 bytes be made available in the `initialBytes` argument for a complete
|
|
1456
|
-
* inspection.
|
|
1457
|
-
*/
|
|
1458
|
-
static inspectBytes(initialBytes) {
|
|
1459
|
-
let offset = 0;
|
|
1460
|
-
const next = () => {
|
|
1461
|
-
const [i, length2] = decode4(initialBytes.subarray(offset));
|
|
1462
|
-
offset += length2;
|
|
1463
|
-
return i;
|
|
1464
|
-
};
|
|
1465
|
-
let version = next();
|
|
1466
|
-
let codec = DAG_PB_CODE;
|
|
1467
|
-
if (version === 18) {
|
|
1468
|
-
version = 0;
|
|
1469
|
-
offset = 0;
|
|
1470
|
-
} else {
|
|
1471
|
-
codec = next();
|
|
1472
|
-
}
|
|
1473
|
-
if (version !== 0 && version !== 1) {
|
|
1474
|
-
throw new RangeError(`Invalid CID version ${version}`);
|
|
1475
|
-
}
|
|
1476
|
-
const prefixSize = offset;
|
|
1477
|
-
const multihashCode = next();
|
|
1478
|
-
const digestSize = next();
|
|
1479
|
-
const size = offset + digestSize;
|
|
1480
|
-
const multihashSize = size - prefixSize;
|
|
1481
|
-
return { version, codec, multihashCode, digestSize, multihashSize, size };
|
|
1482
|
-
}
|
|
1483
|
-
/**
|
|
1484
|
-
* Takes cid in a string representation and creates an instance. If `base`
|
|
1485
|
-
* decoder is not provided will use a default from the configuration. It will
|
|
1486
|
-
* throw an error if encoding of the CID is not compatible with supplied (or
|
|
1487
|
-
* a default decoder).
|
|
1488
|
-
*/
|
|
1489
|
-
static parse(source, base2) {
|
|
1490
|
-
const [prefix, bytes] = parseCIDtoBytes(source, base2);
|
|
1491
|
-
const cid = _CID.decode(bytes);
|
|
1492
|
-
if (cid.version === 0 && source[0] !== "Q") {
|
|
1493
|
-
throw Error("Version 0 CID string must not include multibase prefix");
|
|
1494
|
-
}
|
|
1495
|
-
baseCache(cid).set(prefix, source);
|
|
1496
|
-
return cid;
|
|
1497
|
-
}
|
|
1498
|
-
};
|
|
1499
|
-
function parseCIDtoBytes(source, base2) {
|
|
1500
|
-
switch (source[0]) {
|
|
1501
|
-
// CIDv0 is parsed differently
|
|
1502
|
-
case "Q": {
|
|
1503
|
-
const decoder = base2 ?? base58btc;
|
|
1504
|
-
return [
|
|
1505
|
-
base58btc.prefix,
|
|
1506
|
-
decoder.decode(`${base58btc.prefix}${source}`)
|
|
1507
|
-
];
|
|
1508
|
-
}
|
|
1509
|
-
case base58btc.prefix: {
|
|
1510
|
-
const decoder = base2 ?? base58btc;
|
|
1511
|
-
return [base58btc.prefix, decoder.decode(source)];
|
|
1512
|
-
}
|
|
1513
|
-
case base32.prefix: {
|
|
1514
|
-
const decoder = base2 ?? base32;
|
|
1515
|
-
return [base32.prefix, decoder.decode(source)];
|
|
1516
|
-
}
|
|
1517
|
-
case base36.prefix: {
|
|
1518
|
-
const decoder = base2 ?? base36;
|
|
1519
|
-
return [base36.prefix, decoder.decode(source)];
|
|
1520
|
-
}
|
|
1521
|
-
default: {
|
|
1522
|
-
if (base2 == null) {
|
|
1523
|
-
throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");
|
|
1524
|
-
}
|
|
1525
|
-
return [source[0], base2.decode(source)];
|
|
1526
|
-
}
|
|
1527
|
-
}
|
|
1528
|
-
}
|
|
1529
|
-
function toStringV0(bytes, cache2, base2) {
|
|
1530
|
-
const { prefix } = base2;
|
|
1531
|
-
if (prefix !== base58btc.prefix) {
|
|
1532
|
-
throw Error(`Cannot string encode V0 in ${base2.name} encoding`);
|
|
1533
|
-
}
|
|
1534
|
-
const cid = cache2.get(prefix);
|
|
1535
|
-
if (cid == null) {
|
|
1536
|
-
const cid2 = base2.encode(bytes).slice(1);
|
|
1537
|
-
cache2.set(prefix, cid2);
|
|
1538
|
-
return cid2;
|
|
1539
|
-
} else {
|
|
1540
|
-
return cid;
|
|
1541
|
-
}
|
|
1542
|
-
}
|
|
1543
|
-
function toStringV1(bytes, cache2, base2) {
|
|
1544
|
-
const { prefix } = base2;
|
|
1545
|
-
const cid = cache2.get(prefix);
|
|
1546
|
-
if (cid == null) {
|
|
1547
|
-
const cid2 = base2.encode(bytes);
|
|
1548
|
-
cache2.set(prefix, cid2);
|
|
1549
|
-
return cid2;
|
|
1550
|
-
} else {
|
|
1551
|
-
return cid;
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
var DAG_PB_CODE = 112;
|
|
1555
|
-
var SHA_256_CODE = 18;
|
|
1556
|
-
function encodeCID(version, code, multihash) {
|
|
1557
|
-
const codeOffset = encodingLength(version);
|
|
1558
|
-
const hashOffset = codeOffset + encodingLength(code);
|
|
1559
|
-
const bytes = new Uint8Array(hashOffset + multihash.byteLength);
|
|
1560
|
-
encodeTo(version, bytes, 0);
|
|
1561
|
-
encodeTo(code, bytes, codeOffset);
|
|
1562
|
-
bytes.set(multihash, hashOffset);
|
|
1563
|
-
return bytes;
|
|
1564
|
-
}
|
|
1565
|
-
var cidSymbol = Symbol.for("@ipld/js-cid/CID");
|
|
1566
|
-
|
|
1567
|
-
// src/utils/appendix.ts
|
|
1568
682
|
var Appendix = class _Appendix {
|
|
1569
683
|
/**
|
|
1570
684
|
* Extracts a DID fragment from a given input
|
|
@@ -1710,25 +824,12 @@ var Appendix = class _Appendix {
|
|
|
1710
824
|
rootCapability.invocationTarget = Identifier2;
|
|
1711
825
|
return rootCapability;
|
|
1712
826
|
}
|
|
1713
|
-
/**
|
|
1714
|
-
* Implements CAS Lookup Step from {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-beacon-signals | 7.2.e Process Beacon Signals }.
|
|
1715
|
-
* @param {HashBytes} hashBytes The hash bytes to look up in the CAS system.
|
|
1716
|
-
* @returns {Promise<string | undefined>} The content fetched from the CAS system, or undefined if not found.
|
|
1717
|
-
*/
|
|
1718
|
-
static async fetchFromCas(hashBytes) {
|
|
1719
|
-
const cid = CID.create(1, 1, create(1, hashBytes));
|
|
1720
|
-
const { createHelia } = await import("helia");
|
|
1721
|
-
const { strings } = await import("@helia/strings");
|
|
1722
|
-
const helia = await createHelia();
|
|
1723
|
-
const node = strings(helia);
|
|
1724
|
-
return await node.get(cid, {});
|
|
1725
|
-
}
|
|
1726
827
|
};
|
|
1727
828
|
|
|
1728
829
|
// src/core/identifier.ts
|
|
1729
830
|
var import_common6 = require("@did-btcr2/common");
|
|
1730
831
|
var import_keypair = require("@did-btcr2/keypair");
|
|
1731
|
-
var
|
|
832
|
+
var import_base = require("@scure/base");
|
|
1732
833
|
var Identifier = class _Identifier {
|
|
1733
834
|
/**
|
|
1734
835
|
* Implements {@link https://dcdpr.github.io/did-btcr2/#didbtcr2-identifier-encoding | 3.2 did:btcr2 Identifier Encoding}.
|
|
@@ -1790,7 +891,7 @@ var Identifier = class _Identifier {
|
|
|
1790
891
|
}
|
|
1791
892
|
}
|
|
1792
893
|
const dataBytes = new Uint8Array([nibbles[2 * 0] << 4 | nibbles[2 * 0 + 1], ...genesisBytes]);
|
|
1793
|
-
return `did:btcr2:${
|
|
894
|
+
return `did:btcr2:${import_base.bech32m.encodeFromBytes(hrp, dataBytes)}`;
|
|
1794
895
|
}
|
|
1795
896
|
/**
|
|
1796
897
|
* Implements {@link https://dcdpr.github.io/did-btcr2/#didbtcr2-identifier-decoding | 3.3 did:btcr2 Identifier Decoding}.
|
|
@@ -1815,7 +916,7 @@ var Identifier = class _Identifier {
|
|
|
1815
916
|
if (!encoded) {
|
|
1816
917
|
throw new import_common6.IdentifierError(`Invalid method-specific id: ${identifier}`, import_common6.INVALID_DID, { identifier });
|
|
1817
918
|
}
|
|
1818
|
-
const { prefix: hrp, bytes: dataBytes } =
|
|
919
|
+
const { prefix: hrp, bytes: dataBytes } = import_base.bech32m.decodeToBytes(encoded);
|
|
1819
920
|
if (!["x", "k"].includes(hrp)) {
|
|
1820
921
|
throw new import_common6.IdentifierError(`Invalid hrp: ${hrp}`, import_common6.INVALID_DID, { identifier });
|
|
1821
922
|
}
|