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