@did-btcr2/method 0.22.0 → 0.23.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/browser.js +274 -1239
- package/dist/browser.mjs +274 -1239
- package/dist/cjs/core/beacon/aggregation/cohort/index.js +13 -2
- package/dist/cjs/core/beacon/aggregation/cohort/index.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js +7 -2
- package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js +5 -10
- package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js +4 -7
- package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/session/index.js +15 -3
- package/dist/cjs/core/beacon/aggregation/session/index.js.map +1 -1
- package/dist/cjs/core/beacon/cas-beacon.js +1 -1
- package/dist/cjs/core/beacon/cas-beacon.js.map +1 -1
- package/dist/cjs/core/beacon/signal-discovery.js +6 -6
- package/dist/cjs/core/beacon/signal-discovery.js.map +1 -1
- package/dist/cjs/core/beacon/singleton.js +13 -12
- package/dist/cjs/core/beacon/singleton.js.map +1 -1
- package/dist/cjs/core/beacon/smt-beacon.js +1 -1
- package/dist/cjs/core/beacon/smt-beacon.js.map +1 -1
- package/dist/cjs/core/identifier.js +11 -13
- package/dist/cjs/core/identifier.js.map +1 -1
- package/dist/cjs/core/resolve.js +14 -15
- package/dist/cjs/core/resolve.js.map +1 -1
- package/dist/cjs/core/update.js +2 -2
- package/dist/cjs/core/update.js.map +1 -1
- package/dist/cjs/did-btcr2.js +11 -14
- package/dist/cjs/did-btcr2.js.map +1 -1
- package/dist/cjs/utils/did-document.js +13 -2
- package/dist/cjs/utils/did-document.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/cohort/index.js +13 -2
- package/dist/esm/core/beacon/aggregation/cohort/index.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/base.js +7 -2
- package/dist/esm/core/beacon/aggregation/cohort/messages/base.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js +5 -10
- package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +4 -7
- package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/session/index.js +15 -3
- package/dist/esm/core/beacon/aggregation/session/index.js.map +1 -1
- package/dist/esm/core/beacon/cas-beacon.js +1 -1
- package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
- package/dist/esm/core/beacon/signal-discovery.js +6 -6
- package/dist/esm/core/beacon/signal-discovery.js.map +1 -1
- package/dist/esm/core/beacon/singleton.js +13 -12
- package/dist/esm/core/beacon/singleton.js.map +1 -1
- package/dist/esm/core/beacon/smt-beacon.js +1 -1
- package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
- package/dist/esm/core/identifier.js +11 -13
- package/dist/esm/core/identifier.js.map +1 -1
- package/dist/esm/core/resolve.js +14 -15
- package/dist/esm/core/resolve.js.map +1 -1
- package/dist/esm/core/update.js +2 -2
- package/dist/esm/core/update.js.map +1 -1
- package/dist/esm/did-btcr2.js +11 -14
- package/dist/esm/did-btcr2.js.map +1 -1
- package/dist/esm/utils/did-document.js +13 -2
- package/dist/esm/utils/did-document.js.map +1 -1
- package/dist/types/core/beacon/aggregation/cohort/index.d.ts +1 -1
- package/dist/types/core/beacon/aggregation/cohort/index.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts +1 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/session/index.d.ts +1 -1
- package/dist/types/core/beacon/aggregation/session/index.d.ts.map +1 -1
- package/dist/types/core/beacon/beacon.d.ts +3 -3
- package/dist/types/core/beacon/beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/cas-beacon.d.ts +3 -3
- package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/signal-discovery.d.ts +5 -5
- package/dist/types/core/beacon/signal-discovery.d.ts.map +1 -1
- package/dist/types/core/beacon/singleton.d.ts +3 -3
- package/dist/types/core/beacon/singleton.d.ts.map +1 -1
- package/dist/types/core/beacon/smt-beacon.d.ts +3 -3
- package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
- package/dist/types/core/identifier.d.ts +17 -21
- package/dist/types/core/identifier.d.ts.map +1 -1
- package/dist/types/core/interfaces.d.ts +2 -2
- package/dist/types/core/interfaces.d.ts.map +1 -1
- package/dist/types/core/resolve.d.ts +3 -3
- package/dist/types/core/resolve.d.ts.map +1 -1
- package/dist/types/core/update.d.ts +2 -2
- package/dist/types/core/update.d.ts.map +1 -1
- package/dist/types/did-btcr2.d.ts +4 -4
- package/dist/types/did-btcr2.d.ts.map +1 -1
- package/dist/types/utils/did-document.d.ts +3 -1
- package/dist/types/utils/did-document.d.ts.map +1 -1
- package/package.json +5 -6
- package/src/core/beacon/aggregation/cohort/index.ts +13 -2
- package/src/core/beacon/aggregation/cohort/messages/base.ts +7 -2
- package/src/core/beacon/aggregation/communication/adapter/did-comm.ts +5 -12
- package/src/core/beacon/aggregation/communication/adapter/nostr.ts +5 -8
- package/src/core/beacon/aggregation/session/index.ts +15 -3
- package/src/core/beacon/beacon.ts +3 -3
- package/src/core/beacon/cas-beacon.ts +3 -3
- package/src/core/beacon/signal-discovery.ts +9 -9
- package/src/core/beacon/singleton.ts +15 -15
- package/src/core/beacon/smt-beacon.ts +3 -3
- package/src/core/identifier.ts +31 -28
- package/src/core/interfaces.ts +2 -2
- package/src/core/resolve.ts +17 -18
- package/src/core/update.ts +4 -4
- package/src/did-btcr2.ts +21 -19
- package/src/utils/did-document.ts +14 -2
package/dist/browser.js
CHANGED
|
@@ -57601,8 +57601,9 @@ var BTCR2 = (() => {
|
|
|
57601
57601
|
MethodErrorCode2["MISSING_UPDATE_DATA"] = "MISSING_UPDATE_DATA";
|
|
57602
57602
|
MethodErrorCode2["INVALID_UPDATE"] = "INVALID_UPDATE";
|
|
57603
57603
|
MethodErrorCode2["INVALID_DOMAIN_ERROR"] = "INVALID_DOMAIN_ERROR";
|
|
57604
|
+
MethodErrorCode2["MISSING_RESOLUTION_OPTIONS"] = "MISSING_RESOLUTION_OPTIONS";
|
|
57604
57605
|
})(MethodErrorCode || (MethodErrorCode = {}));
|
|
57605
|
-
var { INVALID_DID, METHOD_NOT_SUPPORTED, INTERNAL_ERROR, INVALID_DID_DOCUMENT, INVALID_DID_UPDATE, INVALID_DID_DOCUMENT_LENGTH, INVALID_DID_URL, INVALID_PREVIOUS_DID_PROOF, INVALID_PUBLIC_KEY, INVALID_PUBLIC_KEY_MULTIBASE, INVALID_PUBLIC_KEY_LENGTH, INVALID_PUBLIC_KEY_TYPE, INVALID_SIGNATURE, NOT_FOUND, REPRESENTATION_NOT_SUPPORTED, UNSUPPORTED_PUBLIC_KEY_TYPE, PROOF_VERIFICATION_ERROR, PROOF_GENERATION_ERROR, PROOF_SERIALIZATION_ERROR, PROOF_PARSING_ERROR, VERIFICATION_METHOD_ERROR, LATE_PUBLISHING_ERROR, INVALID_SIDECAR_DATA, MISSING_UPDATE_DATA, INVALID_UPDATE, INVALID_DOMAIN_ERROR } = MethodErrorCode;
|
|
57606
|
+
var { INVALID_DID, METHOD_NOT_SUPPORTED, INTERNAL_ERROR, INVALID_DID_DOCUMENT, INVALID_DID_UPDATE, INVALID_DID_DOCUMENT_LENGTH, INVALID_DID_URL, INVALID_PREVIOUS_DID_PROOF, INVALID_PUBLIC_KEY, INVALID_PUBLIC_KEY_MULTIBASE, INVALID_PUBLIC_KEY_LENGTH, INVALID_PUBLIC_KEY_TYPE, INVALID_SIGNATURE, NOT_FOUND, REPRESENTATION_NOT_SUPPORTED, UNSUPPORTED_PUBLIC_KEY_TYPE, PROOF_VERIFICATION_ERROR, PROOF_GENERATION_ERROR, PROOF_SERIALIZATION_ERROR, PROOF_PARSING_ERROR, VERIFICATION_METHOD_ERROR, LATE_PUBLISHING_ERROR, INVALID_SIDECAR_DATA, MISSING_UPDATE_DATA, INVALID_UPDATE, INVALID_DOMAIN_ERROR, MISSING_RESOLUTION_OPTIONS } = MethodErrorCode;
|
|
57606
57607
|
var NotImplementedError = class _NotImplementedError extends Error {
|
|
57607
57608
|
name = "NotImplementedError";
|
|
57608
57609
|
type = "NotImplementedError";
|
|
@@ -57692,6 +57693,40 @@ var BTCR2 = (() => {
|
|
|
57692
57693
|
}
|
|
57693
57694
|
};
|
|
57694
57695
|
|
|
57696
|
+
// ../../node_modules/.pnpm/multiformats@13.4.1/node_modules/multiformats/dist/src/bases/base64.js
|
|
57697
|
+
var base64_exports = {};
|
|
57698
|
+
__export(base64_exports, {
|
|
57699
|
+
base64: () => base64,
|
|
57700
|
+
base64pad: () => base64pad,
|
|
57701
|
+
base64url: () => base64url,
|
|
57702
|
+
base64urlpad: () => base64urlpad
|
|
57703
|
+
});
|
|
57704
|
+
init_shim();
|
|
57705
|
+
var base64 = rfc4648({
|
|
57706
|
+
prefix: "m",
|
|
57707
|
+
name: "base64",
|
|
57708
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
|
|
57709
|
+
bitsPerChar: 6
|
|
57710
|
+
});
|
|
57711
|
+
var base64pad = rfc4648({
|
|
57712
|
+
prefix: "M",
|
|
57713
|
+
name: "base64pad",
|
|
57714
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
|
|
57715
|
+
bitsPerChar: 6
|
|
57716
|
+
});
|
|
57717
|
+
var base64url = rfc4648({
|
|
57718
|
+
prefix: "u",
|
|
57719
|
+
name: "base64url",
|
|
57720
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",
|
|
57721
|
+
bitsPerChar: 6
|
|
57722
|
+
});
|
|
57723
|
+
var base64urlpad = rfc4648({
|
|
57724
|
+
prefix: "U",
|
|
57725
|
+
name: "base64urlpad",
|
|
57726
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",
|
|
57727
|
+
bitsPerChar: 6
|
|
57728
|
+
});
|
|
57729
|
+
|
|
57695
57730
|
// ../common/dist/esm/canonicalization.js
|
|
57696
57731
|
var Canonicalization = class _Canonicalization {
|
|
57697
57732
|
/**
|
|
@@ -57715,7 +57750,7 @@ var BTCR2 = (() => {
|
|
|
57715
57750
|
*/
|
|
57716
57751
|
static normalizeEncoding(encoding) {
|
|
57717
57752
|
const normalized = encoding.toLowerCase();
|
|
57718
|
-
if (
|
|
57753
|
+
if (!["hex", "base58btc", "base64url"].includes(normalized)) {
|
|
57719
57754
|
throw new CanonicalizationError(`Unsupported encoding: ${encoding}`, "ENCODING_ERROR");
|
|
57720
57755
|
}
|
|
57721
57756
|
return normalized;
|
|
@@ -57731,7 +57766,7 @@ var BTCR2 = (() => {
|
|
|
57731
57766
|
*
|
|
57732
57767
|
* @param {Record<any, any>} object The object to process.
|
|
57733
57768
|
* @param {Object} [options] Options for processing.
|
|
57734
|
-
* @param {CanonicalizationEncoding} [options.encoding='hex'] The encoding format ('hex' or '
|
|
57769
|
+
* @param {CanonicalizationEncoding} [options.encoding='hex'] The encoding format ('hex' or 'base58btc').
|
|
57735
57770
|
* @param {CanonicalizationAlgorithm} [options.algorithm] The canonicalization algorithm to use.
|
|
57736
57771
|
* @returns {string} The final SHA-256 hash bytes as a hex string.
|
|
57737
57772
|
*/
|
|
@@ -57774,9 +57809,9 @@ var BTCR2 = (() => {
|
|
|
57774
57809
|
return sha256(canonicalized);
|
|
57775
57810
|
}
|
|
57776
57811
|
/**
|
|
57777
|
-
* Step 3: Encodes SHA-256 hashed, canonicalized object as a hex or
|
|
57812
|
+
* Step 3: Encodes SHA-256 hashed, canonicalized object as a hex or base58btc string.
|
|
57778
57813
|
* @param {string} canonicalizedhash The canonicalized object to encode.
|
|
57779
|
-
* @param {CanonicalizationEncoding} encoding The encoding format ('hex' or '
|
|
57814
|
+
* @param {CanonicalizationEncoding} encoding The encoding format ('hex' or 'base58btc').
|
|
57780
57815
|
* @throws {CanonicalizationError} If the encoding format is not supported.
|
|
57781
57816
|
* @returns {string} The encoded string.
|
|
57782
57817
|
*/
|
|
@@ -57785,15 +57820,18 @@ var BTCR2 = (() => {
|
|
|
57785
57820
|
if (normalized === "hex") {
|
|
57786
57821
|
return this.toHex(canonicalizedhash);
|
|
57787
57822
|
}
|
|
57788
|
-
if (normalized === "
|
|
57823
|
+
if (normalized === "base58btc") {
|
|
57789
57824
|
return this.toBase58(canonicalizedhash);
|
|
57790
57825
|
}
|
|
57826
|
+
if (normalized === "base64url") {
|
|
57827
|
+
return this.toBase64Url(canonicalizedhash);
|
|
57828
|
+
}
|
|
57791
57829
|
throw new CanonicalizationError(`Unsupported encoding: ${encoding}`, "ENCODING_ERROR");
|
|
57792
57830
|
}
|
|
57793
57831
|
/**
|
|
57794
|
-
* Decodes SHA-256 hashed, canonicalized object as a hex or
|
|
57832
|
+
* Decodes SHA-256 hashed, canonicalized object as a hex or base58btc string.
|
|
57795
57833
|
* @param {string} canonicalizedhash The canonicalized object to encode.
|
|
57796
|
-
* @param {CanonicalizationEncoding} encoding The encoding format ('hex' or '
|
|
57834
|
+
* @param {CanonicalizationEncoding} encoding The encoding format ('hex' or 'base58btc').
|
|
57797
57835
|
* @throws {CanonicalizationError} If the encoding format is not supported.
|
|
57798
57836
|
* @returns {string} The encoded string.
|
|
57799
57837
|
*/
|
|
@@ -57802,9 +57840,12 @@ var BTCR2 = (() => {
|
|
|
57802
57840
|
if (normalized === "hex") {
|
|
57803
57841
|
return this.fromHex(canonicalizedhash);
|
|
57804
57842
|
}
|
|
57805
|
-
if (normalized === "
|
|
57843
|
+
if (normalized === "base58btc") {
|
|
57806
57844
|
return this.fromBase58(canonicalizedhash);
|
|
57807
57845
|
}
|
|
57846
|
+
if (normalized === "base64url") {
|
|
57847
|
+
return this.fromBase64Url(canonicalizedhash);
|
|
57848
|
+
}
|
|
57808
57849
|
throw new CanonicalizationError(`Unsupported encoding: ${encoding}`, "DECODING_ERROR");
|
|
57809
57850
|
}
|
|
57810
57851
|
/**
|
|
@@ -57832,13 +57873,29 @@ var BTCR2 = (() => {
|
|
|
57832
57873
|
return base58btc.encode(hashBytes);
|
|
57833
57874
|
}
|
|
57834
57875
|
/**
|
|
57835
|
-
* Decodes a
|
|
57836
|
-
* @param {string} b58str The hash as a
|
|
57876
|
+
* Decodes a base58btc string to HashBytes (Uint8Array).
|
|
57877
|
+
* @param {string} b58str The hash as a base58btc string.
|
|
57837
57878
|
* @returns {HashBytes} The hash bytes.
|
|
57838
57879
|
*/
|
|
57839
57880
|
static fromBase58(b58str) {
|
|
57840
57881
|
return base58btc.decode(b58str);
|
|
57841
57882
|
}
|
|
57883
|
+
/**
|
|
57884
|
+
* Step 3.2: Encodes HashBytes (Uint8Array) to a base64url string.
|
|
57885
|
+
* @param {HashBytes} hashBytes The hash as a Uint8Array.
|
|
57886
|
+
* @returns {string} The hash as a base64url string.
|
|
57887
|
+
*/
|
|
57888
|
+
static toBase64Url(hashBytes) {
|
|
57889
|
+
return base64url.encode(hashBytes);
|
|
57890
|
+
}
|
|
57891
|
+
/**
|
|
57892
|
+
* Decodes a base64url string to HashBytes (Uint8Array).
|
|
57893
|
+
* @param {string} b64urlstr The hash as a base64url string.
|
|
57894
|
+
* @returns {HashBytes} The hash bytes.
|
|
57895
|
+
*/
|
|
57896
|
+
static fromBase64Url(b64urlstr) {
|
|
57897
|
+
return base64url.decode(b64urlstr);
|
|
57898
|
+
}
|
|
57842
57899
|
/**
|
|
57843
57900
|
* Canonicalizes an object, hashes it and returns it as hash bytes.
|
|
57844
57901
|
* Step 1-2: Canonicalize → Hash.
|
|
@@ -57862,13 +57919,22 @@ var BTCR2 = (() => {
|
|
|
57862
57919
|
return hexed;
|
|
57863
57920
|
}
|
|
57864
57921
|
/**
|
|
57865
|
-
* Computes the SHA-256 hashes of canonicalized object and encodes it as a
|
|
57866
|
-
* Step 2-3: Hash → Encode(
|
|
57922
|
+
* Computes the SHA-256 hashes of canonicalized object and encodes it as a base58btc string.
|
|
57923
|
+
* Step 2-3: Hash → Encode(base58btc).
|
|
57867
57924
|
* @param {string} canonicalized The canonicalized object to hash.
|
|
57868
|
-
* @returns {string} The SHA-256 hash as a
|
|
57925
|
+
* @returns {string} The SHA-256 hash as a base58btc string.
|
|
57869
57926
|
*/
|
|
57870
57927
|
static andHashToBase58(canonicalized) {
|
|
57871
|
-
return this.encode(this.toHash(canonicalized), "
|
|
57928
|
+
return this.encode(this.toHash(canonicalized), "base58btc");
|
|
57929
|
+
}
|
|
57930
|
+
/**
|
|
57931
|
+
* Computes the SHA-256 hashes of canonicalized object and encodes it as a base64url string.
|
|
57932
|
+
* Step 2-3: Hash → Encode(base64url).
|
|
57933
|
+
* @param {string} canonicalized The canonicalized object to hash.
|
|
57934
|
+
* @returns {string} The SHA-256 hash as a base64url string.
|
|
57935
|
+
*/
|
|
57936
|
+
static andHashToBase64Url(canonicalized) {
|
|
57937
|
+
return this.toBase64Url(this.toHash(canonicalized));
|
|
57872
57938
|
}
|
|
57873
57939
|
};
|
|
57874
57940
|
|
|
@@ -57952,9 +58018,6 @@ var BTCR2 = (() => {
|
|
|
57952
58018
|
CONTEXT_URL_MAP.w3c.jsonldpatch.v1
|
|
57953
58019
|
];
|
|
57954
58020
|
|
|
57955
|
-
// ../common/dist/esm/interfaces.js
|
|
57956
|
-
init_shim();
|
|
57957
|
-
|
|
57958
58021
|
// ../common/dist/esm/json-patch.js
|
|
57959
58022
|
init_shim();
|
|
57960
58023
|
|
|
@@ -59623,51 +59686,6 @@ var BTCR2 = (() => {
|
|
|
59623
59686
|
|
|
59624
59687
|
// ../common/dist/esm/utils/string.js
|
|
59625
59688
|
init_shim();
|
|
59626
|
-
var StringUtils = class {
|
|
59627
|
-
/**
|
|
59628
|
-
* Escape special characters in a string for use in a regular expression.
|
|
59629
|
-
* @param {string} value - The string to escape.
|
|
59630
|
-
* @returns {string} The escaped string.
|
|
59631
|
-
*/
|
|
59632
|
-
static escapeRegExp(value3) {
|
|
59633
|
-
return value3.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
59634
|
-
}
|
|
59635
|
-
/**
|
|
59636
|
-
* Convert a camelCase string to snake_case.
|
|
59637
|
-
* @param {string} value - The camelCase string to convert.
|
|
59638
|
-
* @returns {string} The converted snake_case string.
|
|
59639
|
-
*/
|
|
59640
|
-
static toSnake(value3) {
|
|
59641
|
-
return value3.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase();
|
|
59642
|
-
}
|
|
59643
|
-
/**
|
|
59644
|
-
* Convert a string to SNAKE_SCREAMING_CASE.
|
|
59645
|
-
* @param {string} value - The string to convert.
|
|
59646
|
-
* @returns {string} The converted SNAKE_SCREAMING_CASE string.
|
|
59647
|
-
*/
|
|
59648
|
-
static toSnakeScream(value3) {
|
|
59649
|
-
return this.toSnake(value3).toUpperCase();
|
|
59650
|
-
}
|
|
59651
|
-
/**
|
|
59652
|
-
* Remove the last character from a string.
|
|
59653
|
-
* @param {string} value - The string to chop.
|
|
59654
|
-
* @returns {string} The chopped string.
|
|
59655
|
-
*/
|
|
59656
|
-
static chop(value3) {
|
|
59657
|
-
return value3.length > 0 ? value3.slice(0, -1) : "";
|
|
59658
|
-
}
|
|
59659
|
-
/**
|
|
59660
|
-
* Replace the end of a string if it matches a given pattern.
|
|
59661
|
-
* @param {string} value - The string to modify.
|
|
59662
|
-
* @param {string | RegExp} pattern - The pattern to match at the end of the string.
|
|
59663
|
-
* @param {string} [replacement=''] - The replacement string.
|
|
59664
|
-
* @returns {string} The modified string.
|
|
59665
|
-
*/
|
|
59666
|
-
static replaceEnd(value3, pattern, replacement = "") {
|
|
59667
|
-
const regex3 = pattern instanceof RegExp ? new RegExp(pattern.source.endsWith("$") ? pattern.source : `${pattern.source}$`, pattern.flags.replace(/g/g, "")) : new RegExp(`${this.escapeRegExp(pattern)}$`);
|
|
59668
|
-
return value3.replace(regex3, replacement);
|
|
59669
|
-
}
|
|
59670
|
-
};
|
|
59671
59689
|
|
|
59672
59690
|
// src/core/beacon/error.ts
|
|
59673
59691
|
var BeaconError = class extends MethodError {
|
|
@@ -59730,8 +59748,13 @@ var BTCR2 = (() => {
|
|
|
59730
59748
|
* Converts a BaseMessage to a JSON object.
|
|
59731
59749
|
* @returns {Base} The JSON representation of the BaseMessage.
|
|
59732
59750
|
*/
|
|
59733
|
-
|
|
59734
|
-
return
|
|
59751
|
+
toJSON() {
|
|
59752
|
+
return {
|
|
59753
|
+
type: this.type,
|
|
59754
|
+
to: this.to,
|
|
59755
|
+
from: this.from,
|
|
59756
|
+
body: this.body
|
|
59757
|
+
};
|
|
59735
59758
|
}
|
|
59736
59759
|
};
|
|
59737
59760
|
|
|
@@ -59915,7 +59938,7 @@ var BTCR2 = (() => {
|
|
|
59915
59938
|
throw new AggregateBeaconError(
|
|
59916
59939
|
`Missing ${missing} nonce contributions. Received ${this.cohort?.participants.length} of ${this.nonceContributions.size} nonce contributions. Current status: ${this.status}`,
|
|
59917
59940
|
"NONCE_CONTRIBUTION_ERROR",
|
|
59918
|
-
this.
|
|
59941
|
+
this.toJSON()
|
|
59919
59942
|
);
|
|
59920
59943
|
}
|
|
59921
59944
|
const sortedPubkeys = sortKeys(this.cohort.cohortKeys);
|
|
@@ -59982,8 +60005,20 @@ var BTCR2 = (() => {
|
|
|
59982
60005
|
* Converts the signing session instance to a JSON object representation.
|
|
59983
60006
|
* @returns {BeaconCohortSigningSession} The JSON object representation of the signing session.
|
|
59984
60007
|
*/
|
|
59985
|
-
|
|
59986
|
-
return
|
|
60008
|
+
toJSON() {
|
|
60009
|
+
return {
|
|
60010
|
+
id: this.id,
|
|
60011
|
+
cohort: this.cohort,
|
|
60012
|
+
pendingTx: this.pendingTx,
|
|
60013
|
+
nonceContributions: this.nonceContributions,
|
|
60014
|
+
aggregatedNonce: this.aggregatedNonce,
|
|
60015
|
+
partialSignatures: this.partialSignatures,
|
|
60016
|
+
signature: this.signature,
|
|
60017
|
+
status: this.status,
|
|
60018
|
+
processedRequests: this.processedRequests,
|
|
60019
|
+
nonceSecrets: this.nonceSecrets,
|
|
60020
|
+
musig2Session: this.musig2Session
|
|
60021
|
+
};
|
|
59987
60022
|
}
|
|
59988
60023
|
/**
|
|
59989
60024
|
* Checks if the signing session is a completed state.
|
|
@@ -60267,8 +60302,19 @@ var BTCR2 = (() => {
|
|
|
60267
60302
|
* Converts the cohort instance to a JSON object representation.
|
|
60268
60303
|
* @returns {BeaconCohort} The JSON object representation of the cohort.
|
|
60269
60304
|
*/
|
|
60270
|
-
|
|
60271
|
-
return
|
|
60305
|
+
toJSON() {
|
|
60306
|
+
return {
|
|
60307
|
+
id: this.id,
|
|
60308
|
+
coordinatorDid: this.coordinatorDid,
|
|
60309
|
+
minParticipants: this.minParticipants,
|
|
60310
|
+
status: this.status,
|
|
60311
|
+
network: this.network,
|
|
60312
|
+
pendingSignatureRequests: this.pendingSignatureRequests,
|
|
60313
|
+
participants: this.participants,
|
|
60314
|
+
cohortKeys: this.cohortKeys,
|
|
60315
|
+
trMerkleRoot: this.trMerkleRoot,
|
|
60316
|
+
beaconAddress: this.beaconAddress
|
|
60317
|
+
};
|
|
60272
60318
|
}
|
|
60273
60319
|
};
|
|
60274
60320
|
|
|
@@ -60659,7 +60705,7 @@ var BTCR2 = (() => {
|
|
|
60659
60705
|
* Converts the secret key to a JSON object.
|
|
60660
60706
|
* @returns {SecretKeyObject} The secret key as a JSON object
|
|
60661
60707
|
*/
|
|
60662
|
-
|
|
60708
|
+
toJSON() {
|
|
60663
60709
|
return {
|
|
60664
60710
|
bytes: Array.from(this.bytes),
|
|
60665
60711
|
seed: this.seed.toString(),
|
|
@@ -60804,9 +60850,13 @@ var BTCR2 = (() => {
|
|
|
60804
60850
|
|
|
60805
60851
|
// ../keypair/dist/esm/public.js
|
|
60806
60852
|
var CompressedSecp256k1PublicKey = class _CompressedSecp256k1PublicKey {
|
|
60807
|
-
/**
|
|
60853
|
+
/**
|
|
60854
|
+
* The public key bytes
|
|
60855
|
+
**/
|
|
60808
60856
|
#bytes;
|
|
60809
|
-
/**
|
|
60857
|
+
/**
|
|
60858
|
+
* The public key as a MultibaseObject
|
|
60859
|
+
*/
|
|
60810
60860
|
#multibase = {
|
|
60811
60861
|
prefix: BIP340_PUBLIC_KEY_MULTIBASE_PREFIX,
|
|
60812
60862
|
key: [],
|
|
@@ -60978,7 +61028,7 @@ var BTCR2 = (() => {
|
|
|
60978
61028
|
* JSON representation of a CompressedSecp256k1PublicKey object.
|
|
60979
61029
|
* @returns {PublicKeyObject} The CompressedSecp256k1PublicKey as a JSON object.
|
|
60980
61030
|
*/
|
|
60981
|
-
|
|
61031
|
+
toJSON() {
|
|
60982
61032
|
return {
|
|
60983
61033
|
hex: this.hex,
|
|
60984
61034
|
multibase: this.multibase,
|
|
@@ -61207,10 +61257,10 @@ var BTCR2 = (() => {
|
|
|
61207
61257
|
* JSON representation of a Keys.
|
|
61208
61258
|
* @returns {SchnorrKeyPairObject} The Keys as a JSON object
|
|
61209
61259
|
*/
|
|
61210
|
-
|
|
61260
|
+
toJSON() {
|
|
61211
61261
|
return {
|
|
61212
|
-
secretKey: this.secretKey.
|
|
61213
|
-
publicKey: this.publicKey.
|
|
61262
|
+
secretKey: this.secretKey.toJSON(),
|
|
61263
|
+
publicKey: this.publicKey.toJSON()
|
|
61214
61264
|
};
|
|
61215
61265
|
}
|
|
61216
61266
|
/**
|
|
@@ -61303,14 +61353,12 @@ var BTCR2 = (() => {
|
|
|
61303
61353
|
* - a key-value representing a secp256k1 public key; or
|
|
61304
61354
|
* - a hash-value representing the hash of an initiating external DID document.
|
|
61305
61355
|
*
|
|
61306
|
-
* @param {
|
|
61307
|
-
* @param {
|
|
61308
|
-
* @param {string} params.network Bitcoin network name.
|
|
61309
|
-
* @param {number} params.version Identifier version.
|
|
61310
|
-
* @param {KeyBytes | DocumentBytes} params.genesisBytes Public key or an intermediate document bytes.
|
|
61356
|
+
* @param {KeyBytes | DocumentBytes} genesisBytes The genesis bytes (public key or document bytes).
|
|
61357
|
+
* @param {DidCreateOptions} options The DID creation options.
|
|
61311
61358
|
* @returns {string} The new did:btcr2 identifier.
|
|
61312
61359
|
*/
|
|
61313
|
-
static encode(
|
|
61360
|
+
static encode(genesisBytes, options2) {
|
|
61361
|
+
const { idType, version: version3 = 1, network } = options2;
|
|
61314
61362
|
if (!(idType in IdentifierTypes)) {
|
|
61315
61363
|
throw new IdentifierError('Expected "idType" to be "KEY" or "EXTERNAL"', INVALID_DID, { idType });
|
|
61316
61364
|
}
|
|
@@ -61439,14 +61487,16 @@ var BTCR2 = (() => {
|
|
|
61439
61487
|
* @returns {string} The new did:btcr2 identifier.
|
|
61440
61488
|
*/
|
|
61441
61489
|
static generate() {
|
|
61442
|
-
const
|
|
61443
|
-
const did = this.encode(
|
|
61444
|
-
|
|
61445
|
-
|
|
61446
|
-
|
|
61447
|
-
|
|
61448
|
-
|
|
61449
|
-
|
|
61490
|
+
const keyPair = SchnorrKeyPair.generate();
|
|
61491
|
+
const did = this.encode(
|
|
61492
|
+
keyPair.publicKey.compressed,
|
|
61493
|
+
{
|
|
61494
|
+
idType: "KEY",
|
|
61495
|
+
version: 1,
|
|
61496
|
+
network: "regtest"
|
|
61497
|
+
}
|
|
61498
|
+
);
|
|
61499
|
+
return { keyPair: keyPair.toJSON(), did };
|
|
61450
61500
|
}
|
|
61451
61501
|
/**
|
|
61452
61502
|
* Validates a did:btcr2 identifier.
|
|
@@ -61481,12 +61531,7 @@ var BTCR2 = (() => {
|
|
|
61481
61531
|
idType: "KEY",
|
|
61482
61532
|
network: "mutinynet"
|
|
61483
61533
|
};
|
|
61484
|
-
this.did = config?.did || Identifier.encode(
|
|
61485
|
-
{
|
|
61486
|
-
...this.components,
|
|
61487
|
-
genesisBytes: this.keys.public
|
|
61488
|
-
}
|
|
61489
|
-
);
|
|
61534
|
+
this.did = config?.did || Identifier.encode(this.keys.public, this.components);
|
|
61490
61535
|
this.coordinatorDids = config?.coordinatorDids || [];
|
|
61491
61536
|
}
|
|
61492
61537
|
};
|
|
@@ -61556,22 +61601,22 @@ var BTCR2 = (() => {
|
|
|
61556
61601
|
this.config.keys.secret = Secp256k1SecretKey.random();
|
|
61557
61602
|
this.config.keys.public = Secp256k1SecretKey.getPublicKey(this.config.keys.secret).compressed;
|
|
61558
61603
|
this.config.did = Identifier.encode(
|
|
61604
|
+
this.config.keys.public,
|
|
61559
61605
|
{
|
|
61560
61606
|
idType: this.config.components.idType || "KEY",
|
|
61561
61607
|
version: this.config.components.version || 1,
|
|
61562
|
-
network: this.config.components.network || "
|
|
61563
|
-
genesisBytes: this.config.keys.public
|
|
61608
|
+
network: this.config.components.network || "regtest"
|
|
61564
61609
|
}
|
|
61565
61610
|
);
|
|
61566
61611
|
return this.config;
|
|
61567
61612
|
}
|
|
61568
61613
|
this.config.keys = keys;
|
|
61569
61614
|
this.config.did = Identifier.encode(
|
|
61615
|
+
this.config.keys.public,
|
|
61570
61616
|
{
|
|
61571
61617
|
idType: this.config.components.idType || "KEY",
|
|
61572
61618
|
version: this.config.components.version || 1,
|
|
61573
|
-
network: this.config.components.network || "
|
|
61574
|
-
genesisBytes: this.config.keys.public
|
|
61619
|
+
network: this.config.components.network || "regtest"
|
|
61575
61620
|
}
|
|
61576
61621
|
);
|
|
61577
61622
|
return this.config;
|
|
@@ -64212,8 +64257,8 @@ var BTCR2 = (() => {
|
|
|
64212
64257
|
var base32 = chain2(radix22(5), alphabet2("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), padding2(5), join2(""));
|
|
64213
64258
|
var base32hex = chain2(radix22(5), alphabet2("0123456789ABCDEFGHIJKLMNOPQRSTUV"), padding2(5), join2(""));
|
|
64214
64259
|
var base32crockford = chain2(radix22(5), alphabet2("0123456789ABCDEFGHJKMNPQRSTVWXYZ"), join2(""), normalize2((s2) => s2.toUpperCase().replace(/O/g, "0").replace(/[IL]/g, "1")));
|
|
64215
|
-
var
|
|
64216
|
-
var
|
|
64260
|
+
var base642 = chain2(radix22(6), alphabet2("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), padding2(6), join2(""));
|
|
64261
|
+
var base64url2 = chain2(radix22(6), alphabet2("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), padding2(6), join2(""));
|
|
64217
64262
|
var genBase582 = (abc) => chain2(radix3(58), alphabet2(abc), join2(""));
|
|
64218
64263
|
var base582 = genBase582("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
64219
64264
|
var base58flickr2 = genBase582("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ");
|
|
@@ -64335,8 +64380,8 @@ var BTCR2 = (() => {
|
|
|
64335
64380
|
hex: hex2,
|
|
64336
64381
|
base16,
|
|
64337
64382
|
base32,
|
|
64338
|
-
base64,
|
|
64339
|
-
base64url,
|
|
64383
|
+
base64: base642,
|
|
64384
|
+
base64url: base64url2,
|
|
64340
64385
|
base58: base582,
|
|
64341
64386
|
base58xmr
|
|
64342
64387
|
};
|
|
@@ -66545,8 +66590,8 @@ var BTCR2 = (() => {
|
|
|
66545
66590
|
let iv = Uint8Array.from(randomBytes4(16));
|
|
66546
66591
|
let plaintext = utf8Encoder.encode(text);
|
|
66547
66592
|
let ciphertext = cbc(normalizedKey, iv).encrypt(plaintext);
|
|
66548
|
-
let ctb64 =
|
|
66549
|
-
let ivb64 =
|
|
66593
|
+
let ctb64 = base642.encode(new Uint8Array(ciphertext));
|
|
66594
|
+
let ivb64 = base642.encode(new Uint8Array(iv.buffer));
|
|
66550
66595
|
return `${ctb64}?iv=${ivb64}`;
|
|
66551
66596
|
}
|
|
66552
66597
|
function decrypt2(secretKey, pubkey, data) {
|
|
@@ -66554,8 +66599,8 @@ var BTCR2 = (() => {
|
|
|
66554
66599
|
let [ctb64, ivb64] = data.split("?iv=");
|
|
66555
66600
|
let key = secp256k12.getSharedSecret(privkey, "02" + pubkey);
|
|
66556
66601
|
let normalizedKey = getNormalizedX(key);
|
|
66557
|
-
let iv =
|
|
66558
|
-
let ciphertext =
|
|
66602
|
+
let iv = base642.decode(ivb64);
|
|
66603
|
+
let ciphertext = base642.decode(ctb64);
|
|
66559
66604
|
let plaintext = cbc(normalizedKey, iv).decrypt(ciphertext);
|
|
66560
66605
|
return utf8Decoder.decode(plaintext);
|
|
66561
66606
|
}
|
|
@@ -66865,7 +66910,7 @@ var BTCR2 = (() => {
|
|
|
66865
66910
|
throw new Error("unknown encryption version");
|
|
66866
66911
|
let data;
|
|
66867
66912
|
try {
|
|
66868
|
-
data =
|
|
66913
|
+
data = base642.decode(payload);
|
|
66869
66914
|
} catch (error) {
|
|
66870
66915
|
throw new Error("invalid base64: " + error.message);
|
|
66871
66916
|
}
|
|
@@ -66886,7 +66931,7 @@ var BTCR2 = (() => {
|
|
|
66886
66931
|
const padded = pad(plaintext);
|
|
66887
66932
|
const ciphertext = chacha20(chacha_key, chacha_nonce, padded);
|
|
66888
66933
|
const mac = hmacAad(hmac_key, ciphertext, nonce);
|
|
66889
|
-
return
|
|
66934
|
+
return base642.encode(concatBytes7(new Uint8Array([2]), nonce, ciphertext, mac));
|
|
66890
66935
|
}
|
|
66891
66936
|
function decrypt22(payload, conversationKey) {
|
|
66892
66937
|
const { nonce, ciphertext, mac } = decodePayload(payload);
|
|
@@ -67625,7 +67670,7 @@ var BTCR2 = (() => {
|
|
|
67625
67670
|
}
|
|
67626
67671
|
const signedEvent = await sign2(event);
|
|
67627
67672
|
const authorizationScheme = includeAuthorizationScheme ? _authorizationScheme : "";
|
|
67628
|
-
return authorizationScheme +
|
|
67673
|
+
return authorizationScheme + base642.encode(utf8Encoder.encode(JSON.stringify(signedEvent)));
|
|
67629
67674
|
}
|
|
67630
67675
|
async function validateToken(token, url, method) {
|
|
67631
67676
|
const event = await unpackEventFromToken(token).catch((error) => {
|
|
@@ -67641,7 +67686,7 @@ var BTCR2 = (() => {
|
|
|
67641
67686
|
throw new Error("Missing token");
|
|
67642
67687
|
}
|
|
67643
67688
|
token = token.replace(_authorizationScheme, "");
|
|
67644
|
-
const eventB64 = utf8Decoder.decode(
|
|
67689
|
+
const eventB64 = utf8Decoder.decode(base642.decode(token));
|
|
67645
67690
|
if (!eventB64 || eventB64.length === 0 || !eventB64.startsWith("{")) {
|
|
67646
67691
|
throw new Error("Invalid token");
|
|
67647
67692
|
}
|
|
@@ -68593,11 +68638,10 @@ var BTCR2 = (() => {
|
|
|
68593
68638
|
constructor(config = { keys: {}, components: {}, relays: DEFAULT_NOSTR_RELAYS }) {
|
|
68594
68639
|
this.config = config;
|
|
68595
68640
|
this.config.keys = this.config.keys || SchnorrKeyPair.generate().raw;
|
|
68596
|
-
this.config.did = config.did || Identifier.encode({
|
|
68641
|
+
this.config.did = config.did || Identifier.encode(this.config.keys.public, {
|
|
68597
68642
|
idType: config.components.idType || "KEY",
|
|
68598
68643
|
version: config.components.version || 1,
|
|
68599
|
-
network: config.components.network || "signet"
|
|
68600
|
-
genesisBytes: this.config.keys.public
|
|
68644
|
+
network: config.components.network || "signet"
|
|
68601
68645
|
});
|
|
68602
68646
|
}
|
|
68603
68647
|
/**
|
|
@@ -68737,22 +68781,22 @@ var BTCR2 = (() => {
|
|
|
68737
68781
|
this.config.keys.secret = Secp256k1SecretKey.random();
|
|
68738
68782
|
this.config.keys.public = Secp256k1SecretKey.getPublicKey(this.config.keys.secret).compressed;
|
|
68739
68783
|
this.config.did = Identifier.encode(
|
|
68784
|
+
this.config.keys.public,
|
|
68740
68785
|
{
|
|
68741
68786
|
idType: this.config.components.idType || "KEY",
|
|
68742
68787
|
version: this.config.components.version || 1,
|
|
68743
|
-
network: this.config.components.network || "signet"
|
|
68744
|
-
genesisBytes: this.config.keys.public
|
|
68788
|
+
network: this.config.components.network || "signet"
|
|
68745
68789
|
}
|
|
68746
68790
|
);
|
|
68747
68791
|
return this.config;
|
|
68748
68792
|
}
|
|
68749
68793
|
this.config.keys = keys;
|
|
68750
68794
|
this.config.did = Identifier.encode(
|
|
68795
|
+
this.config.keys.public,
|
|
68751
68796
|
{
|
|
68752
68797
|
idType: this.config.components.idType || "KEY",
|
|
68753
68798
|
version: this.config.components.version || 1,
|
|
68754
|
-
network: this.config.components.network || "signet"
|
|
68755
|
-
genesisBytes: this.config.keys.public
|
|
68799
|
+
network: this.config.components.network || "signet"
|
|
68756
68800
|
}
|
|
68757
68801
|
);
|
|
68758
68802
|
return this.config;
|
|
@@ -69947,12 +69991,12 @@ var BTCR2 = (() => {
|
|
|
69947
69991
|
* Broadcast CAS Beacon signal to the Bitcoin network.
|
|
69948
69992
|
* @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
|
|
69949
69993
|
* @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
|
|
69950
|
-
* @param {
|
|
69994
|
+
* @param {BitcoinConnection} bitcoin The Bitcoin network connection.
|
|
69951
69995
|
* @return {Promise<SignedBTCR2Update>} The signed update that was broadcasted.
|
|
69952
69996
|
* @throws {CASBeaconError} if broadcasting fails.
|
|
69953
69997
|
*/
|
|
69954
|
-
async broadcastSignal(signedUpdate, secretKey,
|
|
69955
|
-
throw new CASBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signedUpdate, secretKey, bitcoin:
|
|
69998
|
+
async broadcastSignal(signedUpdate, secretKey, bitcoin2) {
|
|
69999
|
+
throw new CASBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signedUpdate, secretKey, bitcoin: bitcoin2 });
|
|
69956
70000
|
}
|
|
69957
70001
|
};
|
|
69958
70002
|
|
|
@@ -69961,68 +70005,6 @@ var BTCR2 = (() => {
|
|
|
69961
70005
|
|
|
69962
70006
|
// src/core/beacon/singleton.ts
|
|
69963
70007
|
init_shim();
|
|
69964
|
-
|
|
69965
|
-
// ../kms/dist/esm/index.js
|
|
69966
|
-
init_shim();
|
|
69967
|
-
|
|
69968
|
-
// ../kms/dist/esm/interface.js
|
|
69969
|
-
init_shim();
|
|
69970
|
-
|
|
69971
|
-
// ../kms/dist/esm/kms.js
|
|
69972
|
-
init_shim();
|
|
69973
|
-
|
|
69974
|
-
// ../kms/dist/esm/store.js
|
|
69975
|
-
init_shim();
|
|
69976
|
-
|
|
69977
|
-
// ../kms/dist/esm/signer.js
|
|
69978
|
-
init_shim();
|
|
69979
|
-
var Signer = class {
|
|
69980
|
-
/**
|
|
69981
|
-
* The key pair used for signing.
|
|
69982
|
-
* @type {SchnorrKeyPair}
|
|
69983
|
-
*/
|
|
69984
|
-
keyPair;
|
|
69985
|
-
/**
|
|
69986
|
-
* The network associated with the signer.
|
|
69987
|
-
* @type {keyof AvailableNetworks}
|
|
69988
|
-
*/
|
|
69989
|
-
network;
|
|
69990
|
-
/**
|
|
69991
|
-
* Creates an instance of Signer.
|
|
69992
|
-
* @param {{ keyPair: SchnorrKeyPair; network: keyof AvailableNetworks; }} params The parameters for the signer.
|
|
69993
|
-
* @param {SchnorrKeyPair} params.keyPair The key pair used for signing.
|
|
69994
|
-
* @param {keyof AvailableNetworks} params.network The network associated with the signer.
|
|
69995
|
-
*/
|
|
69996
|
-
constructor(params) {
|
|
69997
|
-
this.keyPair = params.keyPair;
|
|
69998
|
-
this.network = params.network;
|
|
69999
|
-
}
|
|
70000
|
-
/**
|
|
70001
|
-
* Gets the public key bytes.
|
|
70002
|
-
* @returns {KeyBytes} The public key bytes.
|
|
70003
|
-
*/
|
|
70004
|
-
get publicKey() {
|
|
70005
|
-
return this.keyPair.publicKey.compressed;
|
|
70006
|
-
}
|
|
70007
|
-
/**
|
|
70008
|
-
* Signs the given hash using ECDSA.
|
|
70009
|
-
* @param {Bytes} hash The hash to sign.
|
|
70010
|
-
* @returns {SignatureBytes} The signature of the hash.
|
|
70011
|
-
*/
|
|
70012
|
-
sign(hash4) {
|
|
70013
|
-
return this.keyPair.secretKey.sign(hash4, { scheme: "ecdsa" });
|
|
70014
|
-
}
|
|
70015
|
-
/**
|
|
70016
|
-
* Signs the given hash using Schnorr signature.
|
|
70017
|
-
* @param {Bytes} hash The hash to sign.
|
|
70018
|
-
* @returns {SignatureBytes} The Schnorr signature of the hash.
|
|
70019
|
-
*/
|
|
70020
|
-
signSchnorr(hash4) {
|
|
70021
|
-
return this.keyPair.secretKey.sign(hash4);
|
|
70022
|
-
}
|
|
70023
|
-
};
|
|
70024
|
-
|
|
70025
|
-
// src/core/beacon/singleton.ts
|
|
70026
70008
|
var SingletonBeacon = class extends Beacon {
|
|
70027
70009
|
/**
|
|
70028
70010
|
* Creates an instance of SingletonBeacon.
|
|
@@ -70049,7 +70031,7 @@ var BTCR2 = (() => {
|
|
|
70049
70031
|
signal
|
|
70050
70032
|
);
|
|
70051
70033
|
}
|
|
70052
|
-
const encodedUpdate = Canonicalization.process(signedUpdate, { encoding: "
|
|
70034
|
+
const encodedUpdate = Canonicalization.process(signedUpdate, { encoding: "base58btc" });
|
|
70053
70035
|
const signalBytes = base58btc.encode(import_buffer.Buffer.from(updateHash, "hex"));
|
|
70054
70036
|
if (encodedUpdate !== signalBytes) {
|
|
70055
70037
|
throw new SingletonBeaconError(
|
|
@@ -70066,13 +70048,13 @@ var BTCR2 = (() => {
|
|
|
70066
70048
|
* Broadcasts a SingletonBeacon signal to the Bitcoin network.
|
|
70067
70049
|
* @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
|
|
70068
70050
|
* @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
|
|
70069
|
-
* @param {
|
|
70051
|
+
* @param {BitcoinConnection} bitcoin The Bitcoin network connection.
|
|
70070
70052
|
* @returns {Promise<SignedBTCR2Update>} The signed update that was broadcast.
|
|
70071
70053
|
* @throws {SingletonBeaconError} if the bitcoin address is invalid or unfunded.
|
|
70072
70054
|
*/
|
|
70073
|
-
async broadcastSignal(signedUpdate, secretKey,
|
|
70055
|
+
async broadcastSignal(signedUpdate, secretKey, bitcoin2) {
|
|
70074
70056
|
const bitcoinAddress = this.service.serviceEndpoint.replace("bitcoin:", "");
|
|
70075
|
-
const utxos = await
|
|
70057
|
+
const utxos = await bitcoin2.rest.address.getUtxos(bitcoinAddress);
|
|
70076
70058
|
if (!utxos.length) {
|
|
70077
70059
|
throw new SingletonBeaconError(
|
|
70078
70060
|
"No UTXOs found, please fund address!",
|
|
@@ -70090,17 +70072,20 @@ var BTCR2 = (() => {
|
|
|
70090
70072
|
{ bitcoinAddress }
|
|
70091
70073
|
);
|
|
70092
70074
|
}
|
|
70093
|
-
const prevTx = await
|
|
70075
|
+
const prevTx = await bitcoin2.rest.transaction.getHex(utxo.txid);
|
|
70094
70076
|
const updateHash = Canonicalization.andHash(signedUpdate);
|
|
70095
|
-
const spendTx = new Psbt2({ network:
|
|
70077
|
+
const spendTx = new Psbt2({ network: bitcoin2.data }).addInput({
|
|
70096
70078
|
hash: utxo.txid,
|
|
70097
70079
|
index: utxo.vout,
|
|
70098
70080
|
nonWitnessUtxo: import_buffer.Buffer.from(prevTx, "hex")
|
|
70099
70081
|
}).addOutput({ address: bitcoinAddress, value: BigInt(utxo.value) - BigInt(500) }).addOutput({ script: script_exports.compile([OPS.OP_RETURN, updateHash]), value: 0n });
|
|
70100
70082
|
const keyPair = SchnorrKeyPair.fromSecret(secretKey);
|
|
70101
|
-
const signer =
|
|
70083
|
+
const signer = {
|
|
70084
|
+
publicKey: keyPair.publicKey.compressed,
|
|
70085
|
+
sign: (hash4) => keyPair.secretKey.sign(hash4, { scheme: "ecdsa" })
|
|
70086
|
+
};
|
|
70102
70087
|
const signedTx = spendTx.signInput(0, signer).finalizeAllInputs().extractTransaction().toHex();
|
|
70103
|
-
const txid = await
|
|
70088
|
+
const txid = await bitcoin2.rest.transaction.send(signedTx);
|
|
70104
70089
|
console.info(`Singleton Beacon Signal Broadcasted with txid: ${txid}`);
|
|
70105
70090
|
return signedUpdate;
|
|
70106
70091
|
}
|
|
@@ -70130,12 +70115,12 @@ var BTCR2 = (() => {
|
|
|
70130
70115
|
* Broadcast CAS Beacon signal to the Bitcoin network.
|
|
70131
70116
|
* @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
|
|
70132
70117
|
* @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
|
|
70133
|
-
* @param {
|
|
70118
|
+
* @param {BitcoinConnection} bitcoin The Bitcoin network connection.
|
|
70134
70119
|
* @return {Promise<SignedBTCR2Update>} The signed update that was broadcasted.
|
|
70135
70120
|
* @throws {SMTBeaconError} if broadcasting fails.
|
|
70136
70121
|
*/
|
|
70137
|
-
async broadcastSignal(signedUpdate, secretKey,
|
|
70138
|
-
throw new SMTBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signedUpdate, secretKey, bitcoin:
|
|
70122
|
+
async broadcastSignal(signedUpdate, secretKey, bitcoin2) {
|
|
70123
|
+
throw new SMTBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signedUpdate, secretKey, bitcoin: bitcoin2 });
|
|
70139
70124
|
}
|
|
70140
70125
|
};
|
|
70141
70126
|
|
|
@@ -70175,382 +70160,23 @@ var BTCR2 = (() => {
|
|
|
70175
70160
|
// ../bitcoin/dist/esm/client/rest/index.js
|
|
70176
70161
|
init_shim();
|
|
70177
70162
|
|
|
70178
|
-
// ../bitcoin/dist/esm/constants.js
|
|
70179
|
-
init_shim();
|
|
70180
|
-
var TXIN_WITNESS_COINBASE = "0000000000000000000000000000000000000000000000000000000000000000";
|
|
70181
|
-
var GENESIS_TX_ID = "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b";
|
|
70182
|
-
var DEFAULT_BITCOIN_NETWORK_CONFIG = {
|
|
70183
|
-
bitcoin: {
|
|
70184
|
-
rpc: void 0,
|
|
70185
|
-
rest: { host: "https://mempool.space/api" }
|
|
70186
|
-
},
|
|
70187
|
-
testnet3: {
|
|
70188
|
-
rpc: void 0,
|
|
70189
|
-
rest: { host: "https://mempool.space/testnet/api" }
|
|
70190
|
-
},
|
|
70191
|
-
testnet4: {
|
|
70192
|
-
rpc: void 0,
|
|
70193
|
-
rest: { host: "https://mempool.space/testnet4/api" }
|
|
70194
|
-
},
|
|
70195
|
-
signet: {
|
|
70196
|
-
rpc: void 0,
|
|
70197
|
-
rest: { host: "https://mempool.space/signet/api" }
|
|
70198
|
-
},
|
|
70199
|
-
mutinynet: {
|
|
70200
|
-
rpc: void 0,
|
|
70201
|
-
rest: { host: "https://mutinynet.com/api" }
|
|
70202
|
-
},
|
|
70203
|
-
regtest: {
|
|
70204
|
-
rpc: {
|
|
70205
|
-
network: "regtest",
|
|
70206
|
-
host: "http://localhost:18443",
|
|
70207
|
-
port: 18443,
|
|
70208
|
-
username: "polaruser",
|
|
70209
|
-
password: "polarpass",
|
|
70210
|
-
allowDefaultWallet: true,
|
|
70211
|
-
version: "28.1.0"
|
|
70212
|
-
},
|
|
70213
|
-
rest: { host: "http://localhost:3000" }
|
|
70214
|
-
}
|
|
70215
|
-
};
|
|
70216
|
-
|
|
70217
70163
|
// ../bitcoin/dist/esm/client/rest/address.js
|
|
70218
70164
|
init_shim();
|
|
70219
|
-
var BitcoinAddress = class {
|
|
70220
|
-
api;
|
|
70221
|
-
constructor(api) {
|
|
70222
|
-
this.api = api;
|
|
70223
|
-
}
|
|
70224
|
-
/**
|
|
70225
|
-
* Get transaction history for the specified address/scripthash, sorted with newest first.
|
|
70226
|
-
* Returns up to 50 mempool transactions plus the first 25 confirmed transactions.
|
|
70227
|
-
* See {@link https://github.com/blockstream/esplora/blob/master/API.md#get-addressaddresstxs | Esplora GET /address/:address/txs } for details.
|
|
70228
|
-
* @param {string} addressOrScripthash The address or scripthash to check.
|
|
70229
|
-
* @returns {Promise<Array<RawTransactionRest>>} A promise resolving to an array of {@link RawTransactionRest} objects.
|
|
70230
|
-
*/
|
|
70231
|
-
async getTxs(addressOrScripthash) {
|
|
70232
|
-
return await this.api({ path: `/address/${addressOrScripthash}/txs` });
|
|
70233
|
-
}
|
|
70234
|
-
/**
|
|
70235
|
-
* Calls getAddressTxs and checks if any funds come back.
|
|
70236
|
-
* Toggle if those funds are confirmed.
|
|
70237
|
-
* @param {string} addressOrScripthash The address or scripthash to check.
|
|
70238
|
-
* @returns {Promise<boolean>} True if the address has any funds, false otherwise.
|
|
70239
|
-
*/
|
|
70240
|
-
async isFundedAddress(addressOrScripthash) {
|
|
70241
|
-
const txs = await this.getConfirmedTxs(addressOrScripthash);
|
|
70242
|
-
const confirmed = txs.filter((tx) => tx.status.confirmed);
|
|
70243
|
-
return !!(confirmed && confirmed.length);
|
|
70244
|
-
}
|
|
70245
|
-
/**
|
|
70246
|
-
* Get unconfirmed transaction history for the specified address/scripthash.
|
|
70247
|
-
* Returns up to 50 transactions (no paging).
|
|
70248
|
-
* @param {string} addressOrScripthash The address or scripthash to check.
|
|
70249
|
-
* @returns {Promise<Array<RawTransactionRest>>} A promise resolving to an array of {@link RawTransactionRest} objects.
|
|
70250
|
-
*/
|
|
70251
|
-
async getTxsMempool(addressOrScripthash) {
|
|
70252
|
-
return await this.api({ path: `/address/${addressOrScripthash}/txs/mempool` });
|
|
70253
|
-
}
|
|
70254
|
-
/**
|
|
70255
|
-
* Get information about an address/scripthash.
|
|
70256
|
-
* Available fields: address/scripthash, chain_stats and mempool_stats.
|
|
70257
|
-
* {chain,mempool}_stats each contain an object with tx_count, funded_txo_count, funded_txo_sum, spent_txo_count and spent_txo_sum.
|
|
70258
|
-
* Elements-based chains don't have the {funded,spent}_txo_sum fields.
|
|
70259
|
-
* @param {string} addressOrScripthash The address or scripthash to check.
|
|
70260
|
-
* @returns {Promise<AddressInfo>} A promise resolving to an {@link AddressInfo} object.
|
|
70261
|
-
*/
|
|
70262
|
-
async getInfo(addressOrScripthash) {
|
|
70263
|
-
return await this.api({ path: `/address/${addressOrScripthash}` });
|
|
70264
|
-
}
|
|
70265
|
-
/**
|
|
70266
|
-
* Get confirmed transaction history for the specified address/scripthash, sorted with newest first.
|
|
70267
|
-
* Returns 25 transactions per page. More can be requested by specifying the last txid seen by the previous query.
|
|
70268
|
-
* @param {string} addressOrScripthash The address or scripthash to check.
|
|
70269
|
-
* @param lastSeenTxId The last transaction id seen by the previous query (optional).
|
|
70270
|
-
* @returns {Promise<Array<RawTransactionRest>>} A promise resolving to an array of {@link RawTransactionRest} objects.
|
|
70271
|
-
*/
|
|
70272
|
-
async getConfirmedTxs(addressOrScripthash, lastSeenTxId) {
|
|
70273
|
-
return await this.api({
|
|
70274
|
-
path: lastSeenTxId ? `/address/${addressOrScripthash}/txs/chain/${lastSeenTxId}` : `/address/${addressOrScripthash}/txs/chain`
|
|
70275
|
-
});
|
|
70276
|
-
}
|
|
70277
|
-
/**
|
|
70278
|
-
* Get the list of unspent transaction outputs associated with the address/scripthash.
|
|
70279
|
-
* See {@link https://github.com/Blockstream/esplora/blob/master/API.md#get-addressaddressutxo | Esplora GET /address/:address/utxo } for details.
|
|
70280
|
-
* @param {string} addressOrScripthash The address or scripthash to check.
|
|
70281
|
-
* @returns {Promise<Array<RawTransactionRest>>} A promise resolving to an array of {@link RawTransactionRest} objects.
|
|
70282
|
-
*/
|
|
70283
|
-
async getUtxos(addressOrScripthash) {
|
|
70284
|
-
return await this.api({ path: `/address/${addressOrScripthash}/utxo` });
|
|
70285
|
-
}
|
|
70286
|
-
};
|
|
70287
70165
|
|
|
70288
70166
|
// ../bitcoin/dist/esm/client/rest/block.js
|
|
70289
70167
|
init_shim();
|
|
70290
70168
|
|
|
70291
70169
|
// ../bitcoin/dist/esm/errors.js
|
|
70292
70170
|
init_shim();
|
|
70293
|
-
var BitcoinRpcError = class extends Error {
|
|
70294
|
-
type;
|
|
70295
|
-
code;
|
|
70296
|
-
data;
|
|
70297
|
-
constructor(type, code8, message2, data) {
|
|
70298
|
-
super(message2);
|
|
70299
|
-
this.type = type;
|
|
70300
|
-
this.code = code8;
|
|
70301
|
-
this.data = data;
|
|
70302
|
-
this.name = "BitcoinRpcError";
|
|
70303
|
-
}
|
|
70304
|
-
};
|
|
70305
|
-
var BitcoinRestError = class extends Error {
|
|
70306
|
-
data;
|
|
70307
|
-
constructor(message2, data) {
|
|
70308
|
-
super(message2);
|
|
70309
|
-
this.data = data;
|
|
70310
|
-
this.name = "BitcoinRestError";
|
|
70311
|
-
}
|
|
70312
|
-
};
|
|
70313
|
-
|
|
70314
|
-
// ../bitcoin/dist/esm/client/rest/block.js
|
|
70315
|
-
var BitcoinBlock = class {
|
|
70316
|
-
api;
|
|
70317
|
-
constructor(api) {
|
|
70318
|
-
this.api = api;
|
|
70319
|
-
}
|
|
70320
|
-
/**
|
|
70321
|
-
* Returns the blockheight of the most-work fully-validated chain. The genesis block has height 0.
|
|
70322
|
-
* @returns {Blockheight} The number of the blockheight with the most-work of the fully-validated chain.
|
|
70323
|
-
*/
|
|
70324
|
-
async count() {
|
|
70325
|
-
return await this.api({ path: "/blocks/tip/height" });
|
|
70326
|
-
}
|
|
70327
|
-
/**
|
|
70328
|
-
* Returns the block data associated with a `blockhash` of a valid block.
|
|
70329
|
-
* @param {GetBlockParams} params See {@link GetBlockParams} for details.
|
|
70330
|
-
* @param {?string} params.blockhash The blockhash of the block to query.
|
|
70331
|
-
* @param {?number} params.height The block height of the block to query.
|
|
70332
|
-
* @returns {BlockResponse} A promise resolving to a {@link BlockResponse} formatted depending on `verbosity` level.
|
|
70333
|
-
* @throws {BitcoinRpcError} If neither `blockhash` nor `height` is provided.
|
|
70334
|
-
*/
|
|
70335
|
-
async get({ blockhash, height }) {
|
|
70336
|
-
if (!blockhash && height === void 0) {
|
|
70337
|
-
throw new BitcoinRestError("INVALID_PARAMS_GET_BLOCK: blockhash or height required", { blockhash, height });
|
|
70338
|
-
}
|
|
70339
|
-
blockhash ??= await this.getHash(height);
|
|
70340
|
-
if (!blockhash || typeof blockhash !== "string") {
|
|
70341
|
-
return void 0;
|
|
70342
|
-
}
|
|
70343
|
-
return await this.api({ path: `/block/${blockhash}` });
|
|
70344
|
-
}
|
|
70345
|
-
/**
|
|
70346
|
-
* Get the block hash for a given block height.
|
|
70347
|
-
* See {@link https://github.com/blockstream/esplora/blob/master/API.md#get-block-heightheight | Esplora GET /block-height/:height } for details.
|
|
70348
|
-
* @param {number} height The block height (required).
|
|
70349
|
-
* @returns {Promise<string>} The hash of the block currently at height..
|
|
70350
|
-
*/
|
|
70351
|
-
async getHash(height) {
|
|
70352
|
-
return await this.api({ path: `/block-height/${height}` });
|
|
70353
|
-
}
|
|
70354
|
-
};
|
|
70355
70171
|
|
|
70356
70172
|
// ../bitcoin/dist/esm/client/rest/transaction.js
|
|
70357
70173
|
init_shim();
|
|
70358
|
-
var BitcoinTransaction = class {
|
|
70359
|
-
api;
|
|
70360
|
-
constructor(api) {
|
|
70361
|
-
this.api = api;
|
|
70362
|
-
}
|
|
70363
|
-
/**
|
|
70364
|
-
* Returns the transaction in JSON format.
|
|
70365
|
-
* See {@link https://github.com/blockstream/esplora/blob/master/API.md#get-txtxid | Esplora GET /tx/:txid } for details.
|
|
70366
|
-
* @param {string} txid The transaction id (required).
|
|
70367
|
-
* @returns {GetRawTransaction} A promise resolving to data about a transaction in the form specified by verbosity.
|
|
70368
|
-
*/
|
|
70369
|
-
async get(txid) {
|
|
70370
|
-
return await this.api({ path: `/tx/${txid}` });
|
|
70371
|
-
}
|
|
70372
|
-
/**
|
|
70373
|
-
* Returns the transaction in JSON format.
|
|
70374
|
-
* See {@link https://github.com/blockstream/esplora/blob/master/API.md#get-txtxid | Esplora GET /tx/:txid } for details.
|
|
70375
|
-
* @param {string} txid The transaction id (required).
|
|
70376
|
-
* @returns {GetRawTransaction} A promise resolving to data about a transaction in the form specified by verbosity.
|
|
70377
|
-
*/
|
|
70378
|
-
async isConfirmed(txid) {
|
|
70379
|
-
const tx = await this.get(txid);
|
|
70380
|
-
return tx.status.confirmed;
|
|
70381
|
-
}
|
|
70382
|
-
/**
|
|
70383
|
-
* Returns the raw transaction in hex or as binary data.
|
|
70384
|
-
* See {@link https://github.com/blockstream/esplora/blob/master/API.md#get-txtxidhex | Esplora GET /tx/:txid/hex } and
|
|
70385
|
-
* {@link https://github.com/blockstream/esplora/blob/master/API.md#get-txtxidraw | Esplora GET /tx/:txid/raw } for details.
|
|
70386
|
-
* @param {string} txid The transaction id (required).
|
|
70387
|
-
* @returns {Promise<RawTransactionRest | string>} A promise resolving to the raw transaction in the specified format.
|
|
70388
|
-
*/
|
|
70389
|
-
async getHex(txid) {
|
|
70390
|
-
return await this.api({ path: `/tx/${txid}/hex` });
|
|
70391
|
-
}
|
|
70392
|
-
/**
|
|
70393
|
-
* Returns the raw transaction in hex or as binary data.
|
|
70394
|
-
* See {@link https://github.com/blockstream/esplora/blob/master/API.md#get-txtxidhex | Esplora GET /tx/:txid/hex } and
|
|
70395
|
-
* {@link https://github.com/blockstream/esplora/blob/master/API.md#get-txtxidraw | Esplora GET /tx/:txid/raw } for details.
|
|
70396
|
-
* @param {string} txid The transaction id (required).
|
|
70397
|
-
* @returns {Promise<RawTransactionRest | string>} A promise resolving to the raw transaction in the specified format.
|
|
70398
|
-
*/
|
|
70399
|
-
async getRaw(txid) {
|
|
70400
|
-
return await this.api({ path: `/tx/${txid}/raw` });
|
|
70401
|
-
}
|
|
70402
|
-
/**
|
|
70403
|
-
* Broadcast a raw transaction to the network. The transaction should be provided as hex in the request body. The txid
|
|
70404
|
-
* will be returned on success.
|
|
70405
|
-
* See {@link https://github.com/blockstream/esplora/blob/master/API.md#post-tx | Esplora POST /tx } for details.
|
|
70406
|
-
* @param {string} tx The raw transaction in hex format (required).
|
|
70407
|
-
* @returns {Promise<string>} The transaction id of the broadcasted transaction.
|
|
70408
|
-
*/
|
|
70409
|
-
async send(tx) {
|
|
70410
|
-
return await this.api({ path: "/tx", method: "POST", body: tx, headers: { "Content-Type": "text/plain" } });
|
|
70411
|
-
}
|
|
70412
|
-
};
|
|
70413
70174
|
|
|
70414
|
-
// ../bitcoin/dist/esm/
|
|
70175
|
+
// ../bitcoin/dist/esm/client/rest/protocol.js
|
|
70415
70176
|
init_shim();
|
|
70416
|
-
var RestClientConfig = class {
|
|
70417
|
-
host;
|
|
70418
|
-
headers;
|
|
70419
|
-
constructor({ host, headers }) {
|
|
70420
|
-
this.host = host;
|
|
70421
|
-
this.headers = headers;
|
|
70422
|
-
}
|
|
70423
|
-
};
|
|
70424
|
-
var BitcoinRpcClientConfig = class {
|
|
70425
|
-
network;
|
|
70426
|
-
headers;
|
|
70427
|
-
host;
|
|
70428
|
-
logger;
|
|
70429
|
-
password;
|
|
70430
|
-
timeout;
|
|
70431
|
-
username;
|
|
70432
|
-
version;
|
|
70433
|
-
wallet;
|
|
70434
|
-
allowDefaultWallet;
|
|
70435
|
-
constructor(options2 = {
|
|
70436
|
-
headers: {},
|
|
70437
|
-
host: "http://localhost",
|
|
70438
|
-
logger: console,
|
|
70439
|
-
password: "",
|
|
70440
|
-
timeout: 3e4,
|
|
70441
|
-
username: "",
|
|
70442
|
-
version: "0.21.1",
|
|
70443
|
-
wallet: "",
|
|
70444
|
-
allowDefaultWallet: false
|
|
70445
|
-
}) {
|
|
70446
|
-
this.headers = options2.headers;
|
|
70447
|
-
this.host = options2.host;
|
|
70448
|
-
this.logger = options2.logger;
|
|
70449
|
-
this.password = options2.password;
|
|
70450
|
-
this.timeout = options2.timeout;
|
|
70451
|
-
this.username = options2.username;
|
|
70452
|
-
this.version = options2.version;
|
|
70453
|
-
this.wallet = options2.wallet;
|
|
70454
|
-
this.allowDefaultWallet = options2.allowDefaultWallet;
|
|
70455
|
-
}
|
|
70456
|
-
};
|
|
70457
|
-
var VerbosityLevel;
|
|
70458
|
-
(function(VerbosityLevel2) {
|
|
70459
|
-
VerbosityLevel2[VerbosityLevel2["hex"] = 0] = "hex";
|
|
70460
|
-
VerbosityLevel2[VerbosityLevel2["json"] = 1] = "json";
|
|
70461
|
-
VerbosityLevel2[VerbosityLevel2["jsonext"] = 2] = "jsonext";
|
|
70462
|
-
VerbosityLevel2[VerbosityLevel2["jsonextprev"] = 3] = "jsonextprev";
|
|
70463
|
-
})(VerbosityLevel || (VerbosityLevel = {}));
|
|
70464
70177
|
|
|
70465
|
-
// ../bitcoin/dist/esm/client/
|
|
70466
|
-
|
|
70467
|
-
/**
|
|
70468
|
-
* The encapsulated {@link RestClientConfig} object.
|
|
70469
|
-
* @private
|
|
70470
|
-
* @type {RestClientConfig}
|
|
70471
|
-
*/
|
|
70472
|
-
_config;
|
|
70473
|
-
/**
|
|
70474
|
-
* The api calls related to bitcoin transactions.
|
|
70475
|
-
* @type {BitcoinTransaction}
|
|
70476
|
-
*/
|
|
70477
|
-
transaction;
|
|
70478
|
-
/**
|
|
70479
|
-
* The api calls related to bitcoin blocks.
|
|
70480
|
-
* @type {BitcoinBlock}
|
|
70481
|
-
*/
|
|
70482
|
-
block;
|
|
70483
|
-
/**
|
|
70484
|
-
* The api calls related to bitcoin addresses.
|
|
70485
|
-
* @type {BitcoinAddress}
|
|
70486
|
-
*/
|
|
70487
|
-
address;
|
|
70488
|
-
/**
|
|
70489
|
-
* The API call method that can be used to make requests to the REST API.
|
|
70490
|
-
* @returns {Promise<any>} A promise resolving to the response data.
|
|
70491
|
-
*/
|
|
70492
|
-
api = this.call;
|
|
70493
|
-
constructor(config) {
|
|
70494
|
-
this._config = new RestClientConfig(config);
|
|
70495
|
-
this.api = this.call.bind(this);
|
|
70496
|
-
this.transaction = new BitcoinTransaction(this.api);
|
|
70497
|
-
this.block = new BitcoinBlock(this.api);
|
|
70498
|
-
this.address = new BitcoinAddress(this.api);
|
|
70499
|
-
}
|
|
70500
|
-
/**
|
|
70501
|
-
* Get the configuration object.
|
|
70502
|
-
* @private
|
|
70503
|
-
*/
|
|
70504
|
-
get config() {
|
|
70505
|
-
const config = this._config;
|
|
70506
|
-
return config;
|
|
70507
|
-
}
|
|
70508
|
-
/**
|
|
70509
|
-
* Static method connects to a bitcoin node running a esplora REST API.
|
|
70510
|
-
*
|
|
70511
|
-
* @param {RestClientConfig} config The configuration object for the client (optional).
|
|
70512
|
-
* @returns {BitcoinRestClient} A new {@link BitcoinRestClient} instance.
|
|
70513
|
-
* @example
|
|
70514
|
-
* ```
|
|
70515
|
-
* const rest = BitcoinRestClient.connect();
|
|
70516
|
-
* ```
|
|
70517
|
-
*/
|
|
70518
|
-
static connect(config) {
|
|
70519
|
-
return new _BitcoinRestClient(config ?? DEFAULT_BITCOIN_NETWORK_CONFIG.regtest.rest);
|
|
70520
|
-
}
|
|
70521
|
-
/**
|
|
70522
|
-
* Make a REST API call to the configured Bitcoin node.
|
|
70523
|
-
* @private
|
|
70524
|
-
* @param {RestApiCallParams} params The parameters for the API call. See {@link RestApiCallParams} for details.
|
|
70525
|
-
* @param {string} [params.path] The path to the API endpoint (required).
|
|
70526
|
-
* @param {string} [params.url] The full URL to the API endpoint (optional).
|
|
70527
|
-
* @param {string} [params.method] The HTTP method to use (default is 'GET').
|
|
70528
|
-
* @param {any} [params.body] The body of the request (optional).
|
|
70529
|
-
* @param {any} [params.headers] Additional headers to include in the request (optional).
|
|
70530
|
-
* @returns {Promise<any>} A promise resolving to the response data.
|
|
70531
|
-
*/
|
|
70532
|
-
async call({ path, url, method, body, headers }) {
|
|
70533
|
-
url ??= `${StringUtils.replaceEnd(this.config.host, "/")}${path}`;
|
|
70534
|
-
method ??= "GET";
|
|
70535
|
-
const requestInit = {
|
|
70536
|
-
method,
|
|
70537
|
-
headers: headers ?? {
|
|
70538
|
-
"Content-Type": "application/json",
|
|
70539
|
-
...this.config.headers
|
|
70540
|
-
}
|
|
70541
|
-
};
|
|
70542
|
-
if (body) {
|
|
70543
|
-
requestInit.body = JSONUtils.isObject(body) ? JSON.stringify(body) : body;
|
|
70544
|
-
requestInit.method = "POST";
|
|
70545
|
-
}
|
|
70546
|
-
const response2 = await fetch(url, requestInit);
|
|
70547
|
-
const data = (response2.headers.get("Content-Type") ?? "json") === "text/plain" ? await response2.text() : await response2.json();
|
|
70548
|
-
if (!response2.ok) {
|
|
70549
|
-
throw new MethodError(`Request to ${url} failed: ${response2.status} - ${response2.statusText}`, "FAILED_HTTP_REQUEST", { data, response: response2 });
|
|
70550
|
-
}
|
|
70551
|
-
return data;
|
|
70552
|
-
}
|
|
70553
|
-
};
|
|
70178
|
+
// ../bitcoin/dist/esm/client/http.js
|
|
70179
|
+
init_shim();
|
|
70554
70180
|
|
|
70555
70181
|
// ../bitcoin/dist/esm/client/rpc/index.js
|
|
70556
70182
|
init_shim();
|
|
@@ -70560,506 +70186,9 @@ var BTCR2 = (() => {
|
|
|
70560
70186
|
|
|
70561
70187
|
// ../bitcoin/dist/esm/client/utils.js
|
|
70562
70188
|
init_shim();
|
|
70563
|
-
function toBase642(s2) {
|
|
70564
|
-
if (typeof import_buffer.Buffer !== "undefined")
|
|
70565
|
-
return import_buffer.Buffer.from(s2, "utf8").toString("base64");
|
|
70566
|
-
if (typeof btoa !== "undefined")
|
|
70567
|
-
return btoa(s2);
|
|
70568
|
-
throw new Error("No base64 encoder available");
|
|
70569
|
-
}
|
|
70570
|
-
async function safeText(res) {
|
|
70571
|
-
try {
|
|
70572
|
-
return await res.text();
|
|
70573
|
-
} catch {
|
|
70574
|
-
return "";
|
|
70575
|
-
}
|
|
70576
|
-
}
|
|
70577
70189
|
|
|
70578
|
-
// ../bitcoin/dist/esm/client/rpc/
|
|
70579
|
-
|
|
70580
|
-
url;
|
|
70581
|
-
authHeader;
|
|
70582
|
-
id = 0;
|
|
70583
|
-
constructor(cfg) {
|
|
70584
|
-
this.url = (cfg.host || "http://127.0.0.1:8332").replace(/\/+$/, "");
|
|
70585
|
-
if (cfg.username && cfg.password) {
|
|
70586
|
-
this.authHeader = `Basic ${toBase642(`${cfg.username}:${cfg.password}`)}`;
|
|
70587
|
-
} else {
|
|
70588
|
-
try {
|
|
70589
|
-
const u = new URL(this.url);
|
|
70590
|
-
if (u.username || u.password) {
|
|
70591
|
-
this.authHeader = `Basic ${toBase642(`${decodeURIComponent(u.username)}:${decodeURIComponent(u.password)}`)}`;
|
|
70592
|
-
u.username = "";
|
|
70593
|
-
u.password = "";
|
|
70594
|
-
this.url = u.toString().replace(/\/+$/, "");
|
|
70595
|
-
}
|
|
70596
|
-
} catch (error) {
|
|
70597
|
-
console.error(`Invalid URL in Bitcoin RPC config: ${this.url}`, error);
|
|
70598
|
-
}
|
|
70599
|
-
}
|
|
70600
|
-
}
|
|
70601
|
-
/**
|
|
70602
|
-
* Make a JSON-RPC call or batch of calls to the Bitcoin node.
|
|
70603
|
-
* @param {BatchOption[] | { method: string; parameters?: any[] }} batch A single RPC call or an array of calls to be made.
|
|
70604
|
-
* @returns {Promise<any[] | any>} The result of the RPC call(s).
|
|
70605
|
-
* @example
|
|
70606
|
-
*/
|
|
70607
|
-
async command(batch) {
|
|
70608
|
-
if (Array.isArray(batch)) {
|
|
70609
|
-
const out = [];
|
|
70610
|
-
for (const item of batch) {
|
|
70611
|
-
out.push(await this.call(item.method, item.parameters ?? []));
|
|
70612
|
-
}
|
|
70613
|
-
return out;
|
|
70614
|
-
} else {
|
|
70615
|
-
return this.call(batch.method, batch.parameters ?? []);
|
|
70616
|
-
}
|
|
70617
|
-
}
|
|
70618
|
-
/**
|
|
70619
|
-
* Internal method to perform the actual JSON-RPC call.
|
|
70620
|
-
* @param {string} method The RPC method to call.
|
|
70621
|
-
* @param {any[]} params The parameters for the RPC method.
|
|
70622
|
-
* @returns {Promise<any>} The result of the RPC call.
|
|
70623
|
-
*/
|
|
70624
|
-
async call(method, params) {
|
|
70625
|
-
const body = { jsonrpc: "2.0", id: ++this.id, method, params };
|
|
70626
|
-
const res = await fetch(this.url, {
|
|
70627
|
-
method: "POST",
|
|
70628
|
-
headers: {
|
|
70629
|
-
"Content-Type": "application/json",
|
|
70630
|
-
...this.authHeader ? { Authorization: this.authHeader } : {}
|
|
70631
|
-
},
|
|
70632
|
-
body: JSON.stringify(body)
|
|
70633
|
-
});
|
|
70634
|
-
if (!res.ok) {
|
|
70635
|
-
const text = await safeText(res);
|
|
70636
|
-
const err2 = new Error(text || `${res.status} ${res.statusText}`);
|
|
70637
|
-
err2.code = res.status;
|
|
70638
|
-
err2.rpc = true;
|
|
70639
|
-
throw err2;
|
|
70640
|
-
}
|
|
70641
|
-
const payload = await res.json();
|
|
70642
|
-
if (payload.error) {
|
|
70643
|
-
const err2 = new Error(payload.error.message);
|
|
70644
|
-
err2.code = payload.error.code;
|
|
70645
|
-
err2.rpc = true;
|
|
70646
|
-
throw err2;
|
|
70647
|
-
}
|
|
70648
|
-
return payload.result;
|
|
70649
|
-
}
|
|
70650
|
-
};
|
|
70651
|
-
|
|
70652
|
-
// ../bitcoin/dist/esm/client/rpc/index.js
|
|
70653
|
-
var BitcoinCoreRpcClient = class _BitcoinCoreRpcClient {
|
|
70654
|
-
/**
|
|
70655
|
-
* The singleton instance of the BitcoinCoreRpcClient.
|
|
70656
|
-
* @type {BitcoinCoreRpcClient}
|
|
70657
|
-
* @private
|
|
70658
|
-
*/
|
|
70659
|
-
static #instance;
|
|
70660
|
-
/**
|
|
70661
|
-
* The JSON-RPC transport layer.
|
|
70662
|
-
* @type {JsonRpcTransport}
|
|
70663
|
-
* @private
|
|
70664
|
-
*/
|
|
70665
|
-
#transport;
|
|
70666
|
-
/**
|
|
70667
|
-
* The configuration for the RPC client.
|
|
70668
|
-
* @type {RpcClientConfig}
|
|
70669
|
-
* @private
|
|
70670
|
-
*/
|
|
70671
|
-
#config;
|
|
70672
|
-
/**
|
|
70673
|
-
* Constructs a new {@link BitcoinCoreRpcClient} instance from a new {@link RpcClient | RpcClient}.
|
|
70674
|
-
* @param {RpcClientConfig} config The bitcoin-core client instance.
|
|
70675
|
-
* @example
|
|
70676
|
-
* ```
|
|
70677
|
-
* import BitcoinRpcClient from '@did-btcr2/method';
|
|
70678
|
-
* const bob = BitcoinRpcClient.connect(); // To use default polar config, pass no args. Polar must run locally.
|
|
70679
|
-
* ```
|
|
70680
|
-
*/
|
|
70681
|
-
constructor(config) {
|
|
70682
|
-
this.#config = new BitcoinRpcClientConfig(config);
|
|
70683
|
-
this.#transport = new JsonRpcTransport(this.#config);
|
|
70684
|
-
}
|
|
70685
|
-
/**
|
|
70686
|
-
* Get the config for the current BitcoinRpcClient object.
|
|
70687
|
-
* @returns {BitcoinRpcClient} The encapsulated {@link BitcoinRpcClient} object.
|
|
70688
|
-
* @example
|
|
70689
|
-
* ```
|
|
70690
|
-
* import BitcoinRpcClient from '@did-btcr2/method';
|
|
70691
|
-
* const alice = BitcoinRpcClient.connect();
|
|
70692
|
-
* const config = alice.config;
|
|
70693
|
-
* ```
|
|
70694
|
-
*/
|
|
70695
|
-
get config() {
|
|
70696
|
-
const config = this.#config;
|
|
70697
|
-
return config;
|
|
70698
|
-
}
|
|
70699
|
-
/**
|
|
70700
|
-
* Get the client for the current BitcoinRpcClient object.
|
|
70701
|
-
* @returns {RpcClient} The encapsulated {@link RpcClient} object.
|
|
70702
|
-
* @example
|
|
70703
|
-
* ```
|
|
70704
|
-
* const alice = BitcoinRpcClient.connect();
|
|
70705
|
-
* const config = alice.client;
|
|
70706
|
-
* ```
|
|
70707
|
-
*/
|
|
70708
|
-
get client() {
|
|
70709
|
-
const client = this.#transport;
|
|
70710
|
-
return client;
|
|
70711
|
-
}
|
|
70712
|
-
/**
|
|
70713
|
-
* Static method initializes a static instance of BitcoinCoreRpcClient with the given configuration.
|
|
70714
|
-
* The RpcClient returned by this method does not have any named methods.
|
|
70715
|
-
* Use this method to create and pass a new RpcClient instance to a BitcoinCoreRpcClient constructor.
|
|
70716
|
-
*
|
|
70717
|
-
* @param {RpcClientConfig} config The configuration object for the client (optional).
|
|
70718
|
-
* @returns {BitcoinCoreRpcClient} A new RpcClient instance.
|
|
70719
|
-
* @example
|
|
70720
|
-
* ```
|
|
70721
|
-
* const options: RpcClientConfig = {
|
|
70722
|
-
* host: 'http://localhost:18443',
|
|
70723
|
-
* username: 'alice',
|
|
70724
|
-
* password: 'alicepass',
|
|
70725
|
-
* version: '28.1.0',
|
|
70726
|
-
* }
|
|
70727
|
-
* const alice = BitcoinCoreRpcClient.initialize(options); // Client config required
|
|
70728
|
-
* ```
|
|
70729
|
-
*/
|
|
70730
|
-
static initialize(config) {
|
|
70731
|
-
const cfg = new BitcoinRpcClientConfig(config);
|
|
70732
|
-
_BitcoinCoreRpcClient.#instance = new _BitcoinCoreRpcClient(cfg);
|
|
70733
|
-
return _BitcoinCoreRpcClient.#instance;
|
|
70734
|
-
}
|
|
70735
|
-
/**
|
|
70736
|
-
* Static method connects to a bitcoin node running the bitcoin core daemon (bitcoind).
|
|
70737
|
-
* To use default polar config, do not pass a config. See {@link DEFAULT_BITCOIN_NETWORK_CONFIG} for default config.
|
|
70738
|
-
* @required A locally running {@link https://github.com/jamaljsr/polar | Polar Lightning} regtest node.
|
|
70739
|
-
*
|
|
70740
|
-
* @param {?RpcClientConfig} config The configuration object for the client (optional).
|
|
70741
|
-
* @returns A new {@link BitcoinRpcClient} instance.
|
|
70742
|
-
* @example
|
|
70743
|
-
* ```
|
|
70744
|
-
* const alice = BitcoinRpcClient.connect();
|
|
70745
|
-
* ```
|
|
70746
|
-
*/
|
|
70747
|
-
static connect(config) {
|
|
70748
|
-
return new _BitcoinCoreRpcClient(config ?? DEFAULT_BITCOIN_NETWORK_CONFIG.regtest.rpc);
|
|
70749
|
-
}
|
|
70750
|
-
/**
|
|
70751
|
-
* Check if the given error is a JSON-RPC error.
|
|
70752
|
-
* @param {unknown} e The error to check.
|
|
70753
|
-
* @returns {boolean} True if the error is a JSON-RPC error, false otherwise.
|
|
70754
|
-
*/
|
|
70755
|
-
isJsonRpcError(e2) {
|
|
70756
|
-
return e2 instanceof Error && e2.name === "RpcError" && typeof e2.code === "number";
|
|
70757
|
-
}
|
|
70758
|
-
/**
|
|
70759
|
-
* Executes a JSON-RPC command on the bitcoind node.
|
|
70760
|
-
* @param {MethodNameInLowerCase} method The name of the method to call.
|
|
70761
|
-
* @param {Array<any>} parameters The parameters to pass to the method.
|
|
70762
|
-
* @returns {Promise<T>} A promise resolving to the result of the command.
|
|
70763
|
-
*/
|
|
70764
|
-
async executeRpc(method, parameters = []) {
|
|
70765
|
-
try {
|
|
70766
|
-
const raw = await this.client.command([{ method, parameters }]);
|
|
70767
|
-
const normalized = JSONUtils.isUnprototyped(raw) ? JSONUtils.normalize(raw) : raw;
|
|
70768
|
-
const result = Array.isArray(normalized) ? normalized[normalized.length - 1] : normalized;
|
|
70769
|
-
return result;
|
|
70770
|
-
} catch (err2) {
|
|
70771
|
-
this.handleError(err2, method, parameters);
|
|
70772
|
-
}
|
|
70773
|
-
}
|
|
70774
|
-
/**
|
|
70775
|
-
*
|
|
70776
|
-
* Map JSON-RPC error codes to HTTP status codes.
|
|
70777
|
-
* @param {number | undefined} code The JSON-RPC error code.
|
|
70778
|
-
* @returns {number} The corresponding HTTP status code.
|
|
70779
|
-
*
|
|
70780
|
-
* | Error type | HTTP code |
|
|
70781
|
-
* | -------------------------------| --------------------|
|
|
70782
|
-
* | Valid JSON-RPC failure | **400 / 404 / 422** |
|
|
70783
|
-
* | JSON-RPC authentication issues | **401 / 403** |
|
|
70784
|
-
* | Upstream bitcoind unreachable | **502** |
|
|
70785
|
-
* | Upstream timeout | **504** |
|
|
70786
|
-
* | Network transient errors | **503** |
|
|
70787
|
-
* | Unknown unexpected errors | **500** |
|
|
70788
|
-
*/
|
|
70789
|
-
mapRpcCodeToHttp(code8) {
|
|
70790
|
-
switch (code8) {
|
|
70791
|
-
case -32700:
|
|
70792
|
-
case -32600:
|
|
70793
|
-
case -32602:
|
|
70794
|
-
return 400;
|
|
70795
|
-
case -32601:
|
|
70796
|
-
return 404;
|
|
70797
|
-
default:
|
|
70798
|
-
return 422;
|
|
70799
|
-
}
|
|
70800
|
-
}
|
|
70801
|
-
/**
|
|
70802
|
-
* Handle errors that occur while executing commands.
|
|
70803
|
-
* @param methods An array of {@link BatchOption} objects.
|
|
70804
|
-
* @param error The error that was thrown.
|
|
70805
|
-
* @throws Throws a {@link BitcoinRpcError} with the error message.
|
|
70806
|
-
*/
|
|
70807
|
-
handleError(err2, method, params) {
|
|
70808
|
-
if (this.isJsonRpcError(err2)) {
|
|
70809
|
-
throw new BitcoinRpcError(err2.name.toUpperCase(), this.mapRpcCodeToHttp(err2.code), `RPC ${method} failed: ${err2.message}`, { method, params });
|
|
70810
|
-
}
|
|
70811
|
-
throw new BitcoinRpcError("UNKNOWN_ERROR", 500, `Unknown failure in ${method}`, { method, params, err: err2 });
|
|
70812
|
-
}
|
|
70813
|
-
/**
|
|
70814
|
-
* Returns the block data associated with a `blockhash` of a valid block.
|
|
70815
|
-
* @param {GetBlockParams} params See {@link GetBlockParams} for details.
|
|
70816
|
-
* @param {?string} params.blockhash The blockhash of the block to query.
|
|
70817
|
-
* @param {?number} params.height The block height of the block to query.
|
|
70818
|
-
* @param {?VerbosityLevel} params.verbosity The verbosity level. See {@link VerbosityLevel}.
|
|
70819
|
-
* @returns {BlockResponse} A promise resolving to a {@link BlockResponse} formatted depending on `verbosity` level.
|
|
70820
|
-
* @throws {BitcoinRpcError} If neither `blockhash` nor `height` is provided.
|
|
70821
|
-
*/
|
|
70822
|
-
async getBlock({ blockhash, height, verbosity }) {
|
|
70823
|
-
if (!blockhash && height === void 0) {
|
|
70824
|
-
throw new BitcoinRpcError("INVALID_PARAMS_GET_BLOCK", 400, "blockhash or height required", { blockhash, height });
|
|
70825
|
-
}
|
|
70826
|
-
blockhash ??= await this.getBlockHash(height);
|
|
70827
|
-
if (!blockhash || typeof blockhash !== "string") {
|
|
70828
|
-
return void 0;
|
|
70829
|
-
}
|
|
70830
|
-
const block = await this.executeRpc("getblock", [blockhash, verbosity ?? 3]);
|
|
70831
|
-
switch (verbosity) {
|
|
70832
|
-
case 0:
|
|
70833
|
-
return block;
|
|
70834
|
-
case 1:
|
|
70835
|
-
return block;
|
|
70836
|
-
case 2:
|
|
70837
|
-
return block;
|
|
70838
|
-
case 3:
|
|
70839
|
-
return block;
|
|
70840
|
-
default:
|
|
70841
|
-
return block;
|
|
70842
|
-
}
|
|
70843
|
-
}
|
|
70844
|
-
/**
|
|
70845
|
-
* Returns the blockheight of the most-work fully-validated chain. The genesis block has height 0.
|
|
70846
|
-
* @returns {Blockheight} The number of the blockheight with the most-work of the fully-validated chain.
|
|
70847
|
-
*/
|
|
70848
|
-
async getBlockCount() {
|
|
70849
|
-
return await this.executeRpc("getblockcount");
|
|
70850
|
-
}
|
|
70851
|
-
/**
|
|
70852
|
-
* Returns the blockhash of the block at the given height in the active chain.
|
|
70853
|
-
*/
|
|
70854
|
-
async getBlockHash(height) {
|
|
70855
|
-
return await this.executeRpc("getblockhash", [height]);
|
|
70856
|
-
}
|
|
70857
|
-
/**
|
|
70858
|
-
* Returns an object containing various blockchain state info.
|
|
70859
|
-
*/
|
|
70860
|
-
async getBlockchainInfo() {
|
|
70861
|
-
return this.executeRpc("getblockchaininfo");
|
|
70862
|
-
}
|
|
70863
|
-
/**
|
|
70864
|
-
* Sign inputs for raw transaction (serialized, hex-encoded).
|
|
70865
|
-
* The second optional argument (may be null) is an array of previous transaction outputs that
|
|
70866
|
-
* this transaction depends on but may not yet be in the block chain.
|
|
70867
|
-
* Requires wallet passphrase to be set with walletpassphrase call if wallet is encrypted.
|
|
70868
|
-
* @param {string} hexstring The hex-encoded transaction to send.
|
|
70869
|
-
*/
|
|
70870
|
-
async signRawTransaction(hexstring) {
|
|
70871
|
-
return await this.executeRpc("signrawtransactionwithwallet", [hexstring]);
|
|
70872
|
-
}
|
|
70873
|
-
/**
|
|
70874
|
-
* Submit a raw transaction (serialized, hex-encoded) to local node and network.
|
|
70875
|
-
*
|
|
70876
|
-
* The transaction will be sent unconditionally to all peers, so using sendrawtransaction
|
|
70877
|
-
* for manual rebroadcast may degrade privacy by leaking the transaction's origin, as
|
|
70878
|
-
* nodes will normally not rebroadcast non-wallet transactions already in their mempool.
|
|
70879
|
-
*
|
|
70880
|
-
* @param {string} hexstring The hex-encoded transaction to send.
|
|
70881
|
-
* @param {numbner} [maxfeerate] If not passed, default is 0.10.
|
|
70882
|
-
* @returns {Promise<string>} A promise resolving to the transaction hash in hex.
|
|
70883
|
-
*/
|
|
70884
|
-
async sendRawTransaction(hexstring, maxfeerate, maxBurnAmount) {
|
|
70885
|
-
return await this.executeRpc("sendrawtransaction", [hexstring, maxfeerate ?? 0.1, maxBurnAmount ?? 0]);
|
|
70886
|
-
}
|
|
70887
|
-
/**
|
|
70888
|
-
* Combines calls to `signRawTransaction` and `sendRawTransaction`.
|
|
70889
|
-
* @param {string} params.hexstring The hex-encoded transaction to send.
|
|
70890
|
-
* @returns {Promise<string>} A promise resolving to the transaction hash in hex.
|
|
70891
|
-
*/
|
|
70892
|
-
async signAndSendRawTransaction(hexstring) {
|
|
70893
|
-
const signedRawTx = await this.signRawTransaction(hexstring);
|
|
70894
|
-
return await this.sendRawTransaction(signedRawTx.hex);
|
|
70895
|
-
}
|
|
70896
|
-
/**
|
|
70897
|
-
* Combines calls to `createRawTransaction`, `signRawTransaction` and `sendRawTransaction`.
|
|
70898
|
-
* @param {CreateRawTxInputs[]} inputs The inputs to the transaction (required).
|
|
70899
|
-
* @param {CreateRawTxOutputs[]} outputs The outputs of the transaction (required).
|
|
70900
|
-
* @returns {Promise<string>} A promise resolving to the transaction hash in hex.
|
|
70901
|
-
*/
|
|
70902
|
-
async createSignSendRawTransaction(inputs2, outputs2) {
|
|
70903
|
-
const rawTx = await this.createRawTransaction(inputs2, outputs2);
|
|
70904
|
-
const signedRawTx = await this.signRawTransaction(rawTx);
|
|
70905
|
-
const sentRawTx = await this.sendRawTransaction(signedRawTx.hex);
|
|
70906
|
-
return sentRawTx;
|
|
70907
|
-
}
|
|
70908
|
-
/**
|
|
70909
|
-
* Returns up to 'count' most recent transactions skipping the first 'from' transactions for account 'label'.
|
|
70910
|
-
* @param {ListTransactionsParams} params The parameters for the listTransactions command.
|
|
70911
|
-
* @returns {Promise<ListTransactionsResult>} A promise resolving to a {@link ListTransactionsResult} object.
|
|
70912
|
-
*/
|
|
70913
|
-
async listTransactions(params) {
|
|
70914
|
-
return await this.executeRpc("listtransactions", [params]);
|
|
70915
|
-
}
|
|
70916
|
-
/**
|
|
70917
|
-
* Create a transaction spending the given inputs and creating new outputs.
|
|
70918
|
-
* Outputs can be addresses or data.
|
|
70919
|
-
* Returns hex-encoded raw transaction.
|
|
70920
|
-
* Note that the transaction's inputs are not signed, and
|
|
70921
|
-
* it is not stored in the wallet or transmitted to the network.
|
|
70922
|
-
* @param {TxInForCreateRaw[]} inputs The inputs to the transaction (required).
|
|
70923
|
-
* @param {CreateRawTxOutputs[]} outputs The outputs of the transaction (required).
|
|
70924
|
-
* @param {number} [locktime] The locktime of the transaction (optional).
|
|
70925
|
-
* @param {boolean} [replacable] Whether the transaction is replaceable (optional).
|
|
70926
|
-
* @returns {string} The hex-encoded raw transaction.
|
|
70927
|
-
*/
|
|
70928
|
-
async createRawTransaction(inputs2, outputs2, locktime, replacable) {
|
|
70929
|
-
return await this.executeRpc("createrawtransaction", [inputs2, outputs2, locktime, replacable]);
|
|
70930
|
-
}
|
|
70931
|
-
/**
|
|
70932
|
-
* Derives one or more addresses corresponding to an output descriptor.
|
|
70933
|
-
* Examples of output descriptors are:
|
|
70934
|
-
* pkh(<pubkey>) P2PKH outputs for the given pubkey
|
|
70935
|
-
* wpkh(<pubkey>) Native segwit P2PKH outputs for the given pubkey
|
|
70936
|
-
* sh(multi(<n>,<pubkey>,<pubkey>,...)) P2SH-multisig outputs for the given threshold and pubkeys
|
|
70937
|
-
* raw(<hex script>) Outputs whose output script equals the specified hex-encoded bytes
|
|
70938
|
-
* tr(<pubkey>,multi_a(<n>,<pubkey>,<pubkey>,...)) P2TR-multisig outputs for the given threshold and pubkeys
|
|
70939
|
-
*
|
|
70940
|
-
* In the above, <pubkey> either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv optionally followed by one
|
|
70941
|
-
* or more path elements separated by "/", where "h" represents a hardened child key.
|
|
70942
|
-
*
|
|
70943
|
-
* See {@link https://github.com/bitcoin/bitcoin/blob/master/doc/descriptors.md | github.com/bitcoin/bitcoin/descriptors.md}
|
|
70944
|
-
* for more information.
|
|
70945
|
-
* @param {string} descriptor The descriptor.
|
|
70946
|
-
* @param {Array<number>} range If descriptor is ranged, must specify end or [begin,end] to derive.
|
|
70947
|
-
* @returns {Array<DerivedAddresses>} a list of derived addresses
|
|
70948
|
-
* @example First three native segwit receive addresses
|
|
70949
|
-
* ```
|
|
70950
|
-
* const bitcoind = BitcoinRpcClient.connect()
|
|
70951
|
-
* const addresses = bitcoind.deriveAddresses("wpkh([d34db33f/84h/0h/0h]xpub6DJ2dN.../0/*)#cjjspncu", [0,2])
|
|
70952
|
-
* ```
|
|
70953
|
-
*/
|
|
70954
|
-
async deriveAddresses(descriptor, range5) {
|
|
70955
|
-
return await this.executeRpc("deriveaddresses", [descriptor, range5]);
|
|
70956
|
-
}
|
|
70957
|
-
/**
|
|
70958
|
-
* Returns the total available balance. The available balance is what the wallet
|
|
70959
|
-
* considers currently spendable, and is thus affected by options which limit
|
|
70960
|
-
* spendability such as -spendzeroconfchange.
|
|
70961
|
-
* @returns {Promise<number>} A promise resolving to the total available balance in BTC.
|
|
70962
|
-
*/
|
|
70963
|
-
async getBalance() {
|
|
70964
|
-
return await this.executeRpc("getbalance");
|
|
70965
|
-
}
|
|
70966
|
-
/**
|
|
70967
|
-
* Returns a new Bitcoin address for receiving payments. If 'label' is specified,
|
|
70968
|
-
* it is added to the address book so payments received with the address will be associated with 'label'.
|
|
70969
|
-
* The 'address_type' can be one of "legacy", "p2sh-segwit", "bech32", or "bech32m".
|
|
70970
|
-
* @param {string} addressType The address type to use (required, options=["legacy", "p2sh-segwit", "bech32", "bech32m"], default="bech32").
|
|
70971
|
-
* @param {string} [label] The label to associate with the new address (optional).
|
|
70972
|
-
* @returns {Promise<string>} A promise resolving to the new address.
|
|
70973
|
-
*/
|
|
70974
|
-
async getNewAddress(addressType, label) {
|
|
70975
|
-
return await this.executeRpc("getnewaddress", [label ?? "", addressType]);
|
|
70976
|
-
}
|
|
70977
|
-
/**
|
|
70978
|
-
* Returns array of unspent transaction outputs with between minconf and maxconf (inclusive) confirmations.
|
|
70979
|
-
* Optionally filter to only include txouts paid to specified addresses.
|
|
70980
|
-
* @param {Object} params The parameters for the listUnspent command.
|
|
70981
|
-
* @param {number} [params.minconf=0] The minimum number of confirmations an output must have to be included.
|
|
70982
|
-
* @param {number} [params.maxconf=9999999] The maximum number of confirmations an output can have to be included.
|
|
70983
|
-
* @param {string[]} [params.address] Only include outputs paid to these addresses.
|
|
70984
|
-
* @param {boolean} [params.include_unsafe=true] Whether to include outputs that are not safe to spend.
|
|
70985
|
-
* @returns {Promise<UnspentTxInfo[]>} A promise resolving to an array of {@link UnspentTxInfo} objects.
|
|
70986
|
-
*/
|
|
70987
|
-
async listUnspent(params) {
|
|
70988
|
-
const args = { minconf: 0, maxconf: 9999999, include_unsafe: true, ...params };
|
|
70989
|
-
return await this.executeRpc("listunspent", [args]);
|
|
70990
|
-
}
|
|
70991
|
-
/**
|
|
70992
|
-
* Send an amount to a given address.
|
|
70993
|
-
* @param {string} address The address to send to.
|
|
70994
|
-
* @param {number} amount The amount to send in BTC.
|
|
70995
|
-
* @returns {Promise<SendToAddressResult>} A promise resolving to the transaction id.
|
|
70996
|
-
*/
|
|
70997
|
-
async sendToAddress(address, amount) {
|
|
70998
|
-
const txid = await this.executeRpc("sendtoaddress", [address, amount]);
|
|
70999
|
-
return await this.getRawTransaction(txid);
|
|
71000
|
-
}
|
|
71001
|
-
/**
|
|
71002
|
-
* Sign a message with the private key of an address.
|
|
71003
|
-
* @param {string} address The address to sign the message with.
|
|
71004
|
-
* @param {string} message The message to sign.
|
|
71005
|
-
* @returns {Promise<string>} A promise resolving to the signature in base64.
|
|
71006
|
-
*/
|
|
71007
|
-
async signMessage(address, message2) {
|
|
71008
|
-
return await this.executeRpc("signmessage", [address, message2]);
|
|
71009
|
-
}
|
|
71010
|
-
/**
|
|
71011
|
-
* Verify a signed message.
|
|
71012
|
-
* @param {string} address The address to verify the message with.
|
|
71013
|
-
* @param {string} signature The signature to verify in base64.
|
|
71014
|
-
* @param {string} message The message to verify.
|
|
71015
|
-
* @returns {Promise<boolean>} A promise resolving to true if the signature is valid, false otherwise.
|
|
71016
|
-
*/
|
|
71017
|
-
async verifyMessage(address, signature2, message2) {
|
|
71018
|
-
return await this.executeRpc("verifymessage", [address, signature2, message2]);
|
|
71019
|
-
}
|
|
71020
|
-
/**
|
|
71021
|
-
* Get detailed information about in-wallet transaction <txid>.
|
|
71022
|
-
* @param txid: The transaction id. (string, required)
|
|
71023
|
-
* @param {boolean} include_watchonly Whether to include watch-only addresses in balance calculation and details.
|
|
71024
|
-
* @returns {WalletTransaction} A promise resolving to a {@link WalletTransaction} object.
|
|
71025
|
-
*/
|
|
71026
|
-
async getTransaction(txid, include_watchonly) {
|
|
71027
|
-
return await this.executeRpc("gettransaction", [txid, include_watchonly]);
|
|
71028
|
-
}
|
|
71029
|
-
/**
|
|
71030
|
-
* Get detailed information about a transaction.
|
|
71031
|
-
* By default, this call only returns a transaction if it is in the mempool. If -txindex is enabled
|
|
71032
|
-
* and no blockhash argument is passed, it will return the transaction if it is in the mempool or any block.
|
|
71033
|
-
* If a blockhash argument is passed, it will return the transaction if the specified block is available and
|
|
71034
|
-
* the transaction is in that block.
|
|
71035
|
-
* @param {string} txid The transaction id (required).
|
|
71036
|
-
* @param {?VerbosityLevel} verbosity Response format: 0 (hex), 1 (json) or 2 (jsonext).
|
|
71037
|
-
* @param {?string} blockhash The block in which to look for the transaction (optional).
|
|
71038
|
-
* @returns {GetRawTransaction} A promise resolving to data about a transaction in the form specified by verbosity.
|
|
71039
|
-
*/
|
|
71040
|
-
async getRawTransaction(txid, verbosity, blockhash) {
|
|
71041
|
-
const rawTransaction = await this.executeRpc("getrawtransaction", [txid, verbosity ?? 2, blockhash]);
|
|
71042
|
-
switch (verbosity) {
|
|
71043
|
-
case 0:
|
|
71044
|
-
return rawTransaction;
|
|
71045
|
-
case 1:
|
|
71046
|
-
return rawTransaction;
|
|
71047
|
-
case 2:
|
|
71048
|
-
return rawTransaction;
|
|
71049
|
-
default:
|
|
71050
|
-
return rawTransaction;
|
|
71051
|
-
}
|
|
71052
|
-
}
|
|
71053
|
-
/**
|
|
71054
|
-
* Get detailed information about multiple transactions. An extension of {@link getRawTransaction}.
|
|
71055
|
-
* @param {Array<string>} txids An array of transaction ids.
|
|
71056
|
-
* @param {?VerbosityLevel} verbosity Response format: 0 (hex), 1 (json) or 2 (jsonext).
|
|
71057
|
-
* @returns {Promise<Array<RawTransactionResponse>>}
|
|
71058
|
-
*/
|
|
71059
|
-
async getRawTransactions(txids, verbosity) {
|
|
71060
|
-
return await Promise.all(txids.map(async (txid) => await this.getRawTransaction(txid, verbosity ?? 2)));
|
|
71061
|
-
}
|
|
71062
|
-
};
|
|
70190
|
+
// ../bitcoin/dist/esm/client/rpc/protocol.js
|
|
70191
|
+
init_shim();
|
|
71063
70192
|
|
|
71064
70193
|
// ../bitcoin/dist/esm/network.js
|
|
71065
70194
|
init_shim();
|
|
@@ -71079,97 +70208,20 @@ var BTCR2 = (() => {
|
|
|
71079
70208
|
}
|
|
71080
70209
|
}
|
|
71081
70210
|
|
|
71082
|
-
// ../bitcoin/dist/esm/
|
|
71083
|
-
|
|
71084
|
-
|
|
71085
|
-
|
|
71086
|
-
testnet3;
|
|
71087
|
-
testnet4;
|
|
71088
|
-
signet;
|
|
71089
|
-
mutinynet;
|
|
71090
|
-
regtest;
|
|
71091
|
-
/**
|
|
71092
|
-
* Creates an instance of the Bitcoin class.
|
|
71093
|
-
* @param {BitcoinNetworkConfigMap} configs Optional configuration object for the Bitcoin client. If not provided, it will
|
|
71094
|
-
* be loaded from the BITCOIN_CLIENT_CONFIG environment variables.
|
|
71095
|
-
* @throws {MethodError} If no configs is passed and BITCOIN_NETWORK_CONFIG is missing or invalid.
|
|
71096
|
-
*/
|
|
71097
|
-
constructor(configs) {
|
|
71098
|
-
const BITCOIN_NETWORK_CONFIG = import_process.default.env.BITCOIN_NETWORK_CONFIG ?? JSON.stringify(configs ?? DEFAULT_BITCOIN_NETWORK_CONFIG);
|
|
71099
|
-
if (!BITCOIN_NETWORK_CONFIG) {
|
|
71100
|
-
throw new MethodError("No BITCOIN_NETWORK_CONFIG available: must pass `configs` to constructor or set `BITCOIN_NETWORK_CONFIG` in env", "MISSING_BITCOIN_NETWORK_CONFIG", { BITCOIN_NETWORK_CONFIG });
|
|
71101
|
-
}
|
|
71102
|
-
if (!JSONUtils.isParsable(BITCOIN_NETWORK_CONFIG)) {
|
|
71103
|
-
throw new MethodError("Parsing failed: malformed BITCOIN_NETWORK_CONFIG", "MISSING_MALFORMED_BITCOIN_NETWORK_CONFIG", { BITCOIN_NETWORK_CONFIG });
|
|
71104
|
-
}
|
|
71105
|
-
const networkConfigs = JSON.parse(BITCOIN_NETWORK_CONFIG);
|
|
71106
|
-
const networks2 = ["bitcoin", "testnet3", "testnet4", "signet", "mutinynet", "regtest"];
|
|
71107
|
-
for (const network of networks2) {
|
|
71108
|
-
const networkConfig = configs?.[network] ?? networkConfigs[network];
|
|
71109
|
-
if (networkConfig) {
|
|
71110
|
-
this[network] = {
|
|
71111
|
-
name: network,
|
|
71112
|
-
config: networkConfig,
|
|
71113
|
-
rpc: new BitcoinCoreRpcClient(networkConfig.rpc),
|
|
71114
|
-
rest: new BitcoinRestClient(networkConfig.rest),
|
|
71115
|
-
data: getNetwork(network)
|
|
71116
|
-
};
|
|
71117
|
-
}
|
|
71118
|
-
}
|
|
71119
|
-
const ACTIVE_NETWORK = import_process.default.env.ACTIVE_NETWORK?.toLowerCase() ?? "regtest";
|
|
71120
|
-
if (!ACTIVE_NETWORK) {
|
|
71121
|
-
throw new MethodError("Missing ACTIVE_NETWORK environment variable", "MISSING_ACTIVE_NETWORK", { ACTIVE_NETWORK });
|
|
71122
|
-
}
|
|
71123
|
-
if (!this[ACTIVE_NETWORK]) {
|
|
71124
|
-
throw new MethodError(`No configuration found for ACTIVE_NETWORK='${ACTIVE_NETWORK}'`, "MISSING_CONFIG_FOR_NETWORK");
|
|
71125
|
-
}
|
|
71126
|
-
this.network = this[ACTIVE_NETWORK];
|
|
71127
|
-
}
|
|
71128
|
-
/**
|
|
71129
|
-
* Get the Bitcoin network configuration for a specific network.
|
|
71130
|
-
* @param {keyof AvailableNetworks} network - The Bitcoin network (e.g., 'bitcoin', 'testnet3', 'signet', 'regtest').
|
|
71131
|
-
* @returns {Bitcoin} The Bitcoin object.
|
|
71132
|
-
*/
|
|
71133
|
-
getNetworkConnection(network) {
|
|
71134
|
-
const availableNetwork = network;
|
|
71135
|
-
if (!this[availableNetwork]) {
|
|
71136
|
-
throw new MethodError(`No configuration found for network='${availableNetwork}'`, "MISSING_CONFIG_FOR_NETWORK");
|
|
71137
|
-
}
|
|
71138
|
-
return this;
|
|
71139
|
-
}
|
|
71140
|
-
/**
|
|
71141
|
-
* Sets the active Bitcoin network.
|
|
71142
|
-
* @param {keyof AvailableNetworks} active - The Bitcoin network to set as active (e.g., 'bitcoin', 'testnet3', 'signet', 'regtest').
|
|
71143
|
-
* @throws {MethodError} If no configuration is found for the specified network.
|
|
71144
|
-
*/
|
|
71145
|
-
setActiveNetwork(active) {
|
|
71146
|
-
const availableNetwork = active;
|
|
71147
|
-
if (!this[availableNetwork]) {
|
|
71148
|
-
throw new MethodError(`No configuration found for network='${availableNetwork}'`, "MISSING_CONFIG_FOR_NETWORK");
|
|
71149
|
-
}
|
|
71150
|
-
this.network = this[availableNetwork];
|
|
71151
|
-
}
|
|
71152
|
-
/**
|
|
71153
|
-
* Converts Bitcoin (BTC) to satoshis (SAT).
|
|
71154
|
-
* @param {number} btc - The amount in BTC.
|
|
71155
|
-
* @returns {number} The amount in SAT.
|
|
71156
|
-
*/
|
|
71157
|
-
static btcToSats(btc) {
|
|
71158
|
-
return Math.round(btc * 1e8);
|
|
71159
|
-
}
|
|
71160
|
-
/**
|
|
71161
|
-
* Converts satoshis (SAT) to Bitcoin (BTC).
|
|
71162
|
-
* @param {number} sats - The amount in SAT.
|
|
71163
|
-
* @returns {number} The amount in BTC.
|
|
71164
|
-
*/
|
|
71165
|
-
static satsToBtc(sats) {
|
|
71166
|
-
return sats / 1e8;
|
|
71167
|
-
}
|
|
71168
|
-
};
|
|
71169
|
-
var bitcoin2 = new BitcoinNetworkConnection();
|
|
70211
|
+
// ../bitcoin/dist/esm/constants.js
|
|
70212
|
+
init_shim();
|
|
70213
|
+
var TXIN_WITNESS_COINBASE = "0000000000000000000000000000000000000000000000000000000000000000";
|
|
70214
|
+
var GENESIS_TX_ID = "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b";
|
|
71170
70215
|
|
|
71171
|
-
// ../bitcoin/dist/esm/
|
|
70216
|
+
// ../bitcoin/dist/esm/types.js
|
|
71172
70217
|
init_shim();
|
|
70218
|
+
var VerbosityLevel;
|
|
70219
|
+
(function(VerbosityLevel2) {
|
|
70220
|
+
VerbosityLevel2[VerbosityLevel2["hex"] = 0] = "hex";
|
|
70221
|
+
VerbosityLevel2[VerbosityLevel2["json"] = 1] = "json";
|
|
70222
|
+
VerbosityLevel2[VerbosityLevel2["jsonext"] = 2] = "jsonext";
|
|
70223
|
+
VerbosityLevel2[VerbosityLevel2["jsonextprev"] = 3] = "jsonextprev";
|
|
70224
|
+
})(VerbosityLevel || (VerbosityLevel = {}));
|
|
71173
70225
|
|
|
71174
70226
|
// src/core/beacon/utils.ts
|
|
71175
70227
|
init_shim();
|
|
@@ -71935,40 +70987,6 @@ var BTCR2 = (() => {
|
|
|
71935
70987
|
decode: decode25
|
|
71936
70988
|
});
|
|
71937
70989
|
|
|
71938
|
-
// ../../node_modules/.pnpm/multiformats@13.4.1/node_modules/multiformats/dist/src/bases/base64.js
|
|
71939
|
-
var base64_exports = {};
|
|
71940
|
-
__export(base64_exports, {
|
|
71941
|
-
base64: () => base642,
|
|
71942
|
-
base64pad: () => base64pad,
|
|
71943
|
-
base64url: () => base64url2,
|
|
71944
|
-
base64urlpad: () => base64urlpad
|
|
71945
|
-
});
|
|
71946
|
-
init_shim();
|
|
71947
|
-
var base642 = rfc4648({
|
|
71948
|
-
prefix: "m",
|
|
71949
|
-
name: "base64",
|
|
71950
|
-
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
|
|
71951
|
-
bitsPerChar: 6
|
|
71952
|
-
});
|
|
71953
|
-
var base64pad = rfc4648({
|
|
71954
|
-
prefix: "M",
|
|
71955
|
-
name: "base64pad",
|
|
71956
|
-
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
|
|
71957
|
-
bitsPerChar: 6
|
|
71958
|
-
});
|
|
71959
|
-
var base64url2 = rfc4648({
|
|
71960
|
-
prefix: "u",
|
|
71961
|
-
name: "base64url",
|
|
71962
|
-
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",
|
|
71963
|
-
bitsPerChar: 6
|
|
71964
|
-
});
|
|
71965
|
-
var base64urlpad = rfc4648({
|
|
71966
|
-
prefix: "U",
|
|
71967
|
-
name: "base64urlpad",
|
|
71968
|
-
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",
|
|
71969
|
-
bitsPerChar: 6
|
|
71970
|
-
});
|
|
71971
|
-
|
|
71972
70990
|
// ../../node_modules/.pnpm/multiformats@13.4.1/node_modules/multiformats/dist/src/bases/base8.js
|
|
71973
70991
|
var base8_exports = {};
|
|
71974
70992
|
__export(base8_exports, {
|
|
@@ -73847,7 +72865,7 @@ var BTCR2 = (() => {
|
|
|
73847
72865
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
73848
72866
|
});
|
|
73849
72867
|
};
|
|
73850
|
-
var
|
|
72868
|
+
var MemoryStore = class {
|
|
73851
72869
|
constructor() {
|
|
73852
72870
|
this.store = /* @__PURE__ */ new Map();
|
|
73853
72871
|
}
|
|
@@ -79800,7 +78818,7 @@ var BTCR2 = (() => {
|
|
|
79800
78818
|
constructor(params) {
|
|
79801
78819
|
var _a3;
|
|
79802
78820
|
this._algorithmInstances = /* @__PURE__ */ new Map();
|
|
79803
|
-
this._keyStore = (_a3 = params === null || params === void 0 ? void 0 : params.keyStore) !== null && _a3 !== void 0 ? _a3 : new
|
|
78821
|
+
this._keyStore = (_a3 = params === null || params === void 0 ? void 0 : params.keyStore) !== null && _a3 !== void 0 ? _a3 : new MemoryStore();
|
|
79804
78822
|
}
|
|
79805
78823
|
/**
|
|
79806
78824
|
* Generates a hash digest of the provided data.
|
|
@@ -87998,7 +87016,7 @@ var BTCR2 = (() => {
|
|
|
87998
87016
|
return v == null ? "undefined" : base322.baseEncode(v);
|
|
87999
87017
|
};
|
|
88000
87018
|
src_default.formatters.m = (v) => {
|
|
88001
|
-
return v == null ? "undefined" :
|
|
87019
|
+
return v == null ? "undefined" : base64.baseEncode(v);
|
|
88002
87020
|
};
|
|
88003
87021
|
src_default.formatters.p = (v) => {
|
|
88004
87022
|
return v == null ? "undefined" : v.toString();
|
|
@@ -93876,7 +92894,7 @@ var BTCR2 = (() => {
|
|
|
93876
92894
|
];
|
|
93877
92895
|
}
|
|
93878
92896
|
function bytesEncoder(bytes6) {
|
|
93879
|
-
const bytesString =
|
|
92897
|
+
const bytesString = base64.encode(bytes6).slice(1);
|
|
93880
92898
|
return [
|
|
93881
92899
|
new Token(Type.map, Infinity, 1),
|
|
93882
92900
|
new Token(Type.string, "/", 1),
|
|
@@ -93984,7 +93002,7 @@ var BTCR2 = (() => {
|
|
|
93984
93002
|
throw new Error("Invalid encoded Bytes form");
|
|
93985
93003
|
}
|
|
93986
93004
|
}
|
|
93987
|
-
const bytes6 =
|
|
93005
|
+
const bytes6 = base64.decode(`m${innerValueToken.value}`);
|
|
93988
93006
|
return new Token(Type.bytes, bytes6, innerValueToken.value.length);
|
|
93989
93007
|
}
|
|
93990
93008
|
this.tokenBuffer.push(innerValueToken);
|
|
@@ -99562,7 +98580,7 @@ var BTCR2 = (() => {
|
|
|
99562
98580
|
c: iterations,
|
|
99563
98581
|
dkLen: keySize
|
|
99564
98582
|
});
|
|
99565
|
-
return
|
|
98583
|
+
return base64.encode(dek).substring(1);
|
|
99566
98584
|
}
|
|
99567
98585
|
|
|
99568
98586
|
// ../../node_modules/.pnpm/@libp2p+utils@6.7.2/node_modules/@libp2p/utils/dist/src/filters/hashes.js
|
|
@@ -99974,7 +98992,7 @@ var BTCR2 = (() => {
|
|
|
99974
98992
|
this.initialProviders = init.providers ?? [];
|
|
99975
98993
|
}
|
|
99976
98994
|
async retrieve(cid, options2 = {}) {
|
|
99977
|
-
const cidStr =
|
|
98995
|
+
const cidStr = base64.encode(cid.multihash.bytes);
|
|
99978
98996
|
const existingJob = this.requests.get(cidStr);
|
|
99979
98997
|
if (existingJob != null) {
|
|
99980
98998
|
this.log("join existing request for %c", cid);
|
|
@@ -101836,15 +100854,15 @@ var BTCR2 = (() => {
|
|
|
101836
100854
|
this.pendingBytes = 0;
|
|
101837
100855
|
}
|
|
101838
100856
|
addWantlistEntry(cid, entry) {
|
|
101839
|
-
const key =
|
|
100857
|
+
const key = base64.encode(cid.multihash.bytes);
|
|
101840
100858
|
this.wantlist.set(key, entry);
|
|
101841
100859
|
}
|
|
101842
100860
|
addBlockPresence(cid, blockPresence) {
|
|
101843
|
-
const key =
|
|
100861
|
+
const key = base64.encode(cid.multihash.bytes);
|
|
101844
100862
|
this.blockPresences.set(key, blockPresence);
|
|
101845
100863
|
}
|
|
101846
100864
|
addBlock(cid, block) {
|
|
101847
|
-
const key =
|
|
100865
|
+
const key = base64.encode(cid.multihash.bytes);
|
|
101848
100866
|
this.blocks.set(key, block);
|
|
101849
100867
|
}
|
|
101850
100868
|
};
|
|
@@ -103399,7 +102417,7 @@ var BTCR2 = (() => {
|
|
|
103399
102417
|
code: CODE_CERTHASH,
|
|
103400
102418
|
name: "certhash",
|
|
103401
102419
|
size: V,
|
|
103402
|
-
bytesToValue: bytes2mb(
|
|
102420
|
+
bytesToValue: bytes2mb(base64url),
|
|
103403
102421
|
valueToBytes: mb2bytes
|
|
103404
102422
|
}, {
|
|
103405
102423
|
code: CODE_HTTP,
|
|
@@ -104705,7 +103723,7 @@ var BTCR2 = (() => {
|
|
|
104705
103723
|
*/
|
|
104706
103724
|
#uniqueBlockId(cid) {
|
|
104707
103725
|
const multihashBytes = cid.multihash.bytes;
|
|
104708
|
-
return
|
|
103726
|
+
return base64.encode(multihashBytes);
|
|
104709
103727
|
}
|
|
104710
103728
|
/**
|
|
104711
103729
|
* Fetch a raw block from `this.url` following the specification defined at
|
|
@@ -116473,7 +115491,7 @@ ${values.join("\n")}` : `${blockName} :`;
|
|
|
116473
115491
|
async function exporter(privateKey, password) {
|
|
116474
115492
|
const cipher = aes_gcm_browser_exports.create();
|
|
116475
115493
|
const encryptedKey = await cipher.encrypt(privateKey, password);
|
|
116476
|
-
return
|
|
115494
|
+
return base64.encode(encryptedKey);
|
|
116477
115495
|
}
|
|
116478
115496
|
async function exportPrivateKey(key, password, format4) {
|
|
116479
115497
|
if (key.type === "RSA") {
|
|
@@ -116638,7 +115656,7 @@ ${values.join("\n")}` : `${blockName} :`;
|
|
|
116638
115656
|
return importFromPem(encryptedKey, password);
|
|
116639
115657
|
}
|
|
116640
115658
|
async function importer(privateKey, password) {
|
|
116641
|
-
const encryptedKey =
|
|
115659
|
+
const encryptedKey = base64.decode(privateKey);
|
|
116642
115660
|
const cipher = aes_gcm_browser_exports.create();
|
|
116643
115661
|
return cipher.decrypt(encryptedKey, password);
|
|
116644
115662
|
}
|
|
@@ -154716,7 +153734,7 @@ ${values.join("\n")}` : `${blockName} :`;
|
|
|
154716
153734
|
const output6 = fingerprint.split(":").map((str) => parseInt(str, 16));
|
|
154717
153735
|
const encoded = Uint8Array.from(output6);
|
|
154718
153736
|
const digest2 = create(sha2565.code, encoded);
|
|
154719
|
-
return multiaddr(`/certhash/${
|
|
153737
|
+
return multiaddr(`/certhash/${base64url.encode(digest2.bytes)}`);
|
|
154720
153738
|
}
|
|
154721
153739
|
function toSupportedHashFunction(code8) {
|
|
154722
153740
|
switch (code8) {
|
|
@@ -155125,7 +154143,7 @@ a=end-of-candidates
|
|
|
155125
154143
|
}, renewTime);
|
|
155126
154144
|
return {
|
|
155127
154145
|
pem: cert.toString("pem"),
|
|
155128
|
-
certhash:
|
|
154146
|
+
certhash: base64url.encode((await sha2565.digest(new Uint8Array(cert.rawData))).bytes)
|
|
155129
154147
|
};
|
|
155130
154148
|
}
|
|
155131
154149
|
async loadCertificate(dsKey, keyPair) {
|
|
@@ -156120,15 +155138,15 @@ a=end-of-candidates
|
|
|
156120
155138
|
* Retrieves the beacon signals for the given array of BeaconService objects
|
|
156121
155139
|
* using an esplora/electrs REST API connection via a bitcoin I/O driver.
|
|
156122
155140
|
* @param {Array<BeaconService>} beaconServices Array of BeaconService objects to retrieve signals for
|
|
156123
|
-
* @param {
|
|
155141
|
+
* @param {BitcoinConnection} bitcoin Bitcoin network connection to use for REST calls
|
|
156124
155142
|
* @returns {Promise<Map<BeaconService, Array<BeaconSignal>>>} Map of beacon service to its discovered signals
|
|
156125
155143
|
*/
|
|
156126
|
-
static async indexer(beaconServices,
|
|
155144
|
+
static async indexer(beaconServices, bitcoin2) {
|
|
156127
155145
|
const beaconServiceSignals = /* @__PURE__ */ new Map();
|
|
156128
|
-
const currentBlockCount = await
|
|
155146
|
+
const currentBlockCount = await bitcoin2.rest.block.count();
|
|
156129
155147
|
for (const beaconService of beaconServices) {
|
|
156130
155148
|
beaconServiceSignals.set(beaconService, []);
|
|
156131
|
-
const beaconSignals = await
|
|
155149
|
+
const beaconSignals = await bitcoin2.rest.address.getTxs(
|
|
156132
155150
|
beaconService.serviceEndpoint
|
|
156133
155151
|
);
|
|
156134
155152
|
if (!beaconSignals || !beaconSignals.length) {
|
|
@@ -156165,22 +155183,22 @@ a=end-of-candidates
|
|
|
156165
155183
|
/**
|
|
156166
155184
|
* Traverse the full blockchain from genesis to chain top looking for beacon signals.
|
|
156167
155185
|
* @param {Array<BeaconService>} beaconServices Array of BeaconService objects to search for signals.
|
|
156168
|
-
* @param {
|
|
155186
|
+
* @param {BitcoinConnection} bitcoin Bitcoin network connection to use for RPC calls.
|
|
156169
155187
|
* @returns {Promise<Map<BeaconService, Array<BeaconSignal>>>} Map of beacon service to its discovered signals.
|
|
156170
155188
|
*/
|
|
156171
|
-
static async fullnode(beaconServices,
|
|
155189
|
+
static async fullnode(beaconServices, bitcoin2) {
|
|
156172
155190
|
const beaconServiceSignals = /* @__PURE__ */ new Map();
|
|
156173
155191
|
for (const beaconService of beaconServices) {
|
|
156174
155192
|
beaconServiceSignals.set(beaconService, []);
|
|
156175
155193
|
}
|
|
156176
|
-
const rpc =
|
|
155194
|
+
const rpc = bitcoin2.rpc;
|
|
156177
155195
|
if (!rpc) {
|
|
156178
|
-
throw new ResolveError("RPC connection is not available", "RPC_CONNECTION_ERROR",
|
|
155196
|
+
throw new ResolveError("RPC connection is not available", "RPC_CONNECTION_ERROR", bitcoin2);
|
|
156179
155197
|
}
|
|
156180
155198
|
const targetHeight = await rpc.getBlockCount();
|
|
156181
155199
|
const beaconServicesMap = BeaconUtils.getBeaconServicesMap(beaconServices);
|
|
156182
155200
|
let height = 0;
|
|
156183
|
-
let block = await
|
|
155201
|
+
let block = await bitcoin2.rpc.getBlock({ height });
|
|
156184
155202
|
console.info(`Searching for beacon signals, please wait ...`);
|
|
156185
155203
|
while (block.height <= targetHeight) {
|
|
156186
155204
|
for (const tx of block.tx) {
|
|
@@ -156645,13 +155663,13 @@ a=end-of-candidates
|
|
|
156645
155663
|
* Convert the multikey to a JSON object.
|
|
156646
155664
|
* @returns {MultikeyObject} The multikey as a JSON object.
|
|
156647
155665
|
*/
|
|
156648
|
-
|
|
155666
|
+
toJSON() {
|
|
156649
155667
|
return {
|
|
156650
155668
|
id: this.id,
|
|
156651
155669
|
controller: this.controller,
|
|
156652
155670
|
fullId: this.fullId(),
|
|
156653
155671
|
signer: this.signer,
|
|
156654
|
-
keyPair: this.keyPair.
|
|
155672
|
+
keyPair: this.keyPair.toJSON(),
|
|
156655
155673
|
verificationMethod: this.toVerificationMethod()
|
|
156656
155674
|
};
|
|
156657
155675
|
}
|
|
@@ -156811,8 +155829,18 @@ a=end-of-candidates
|
|
|
156811
155829
|
* Convert the DidDocument to a JSON object.
|
|
156812
155830
|
* @returns {DidDocument} The JSON representation of the DidDocument.
|
|
156813
155831
|
*/
|
|
156814
|
-
|
|
156815
|
-
return
|
|
155832
|
+
toJSON() {
|
|
155833
|
+
return {
|
|
155834
|
+
id: this.id,
|
|
155835
|
+
"@context": this["@context"],
|
|
155836
|
+
verificationMethod: this.verificationMethod,
|
|
155837
|
+
authentication: this.authentication,
|
|
155838
|
+
assertionMethod: this.assertionMethod,
|
|
155839
|
+
capabilityInvocation: this.capabilityInvocation,
|
|
155840
|
+
capabilityDelegation: this.capabilityDelegation,
|
|
155841
|
+
service: this.service,
|
|
155842
|
+
deactivated: this.deactivated
|
|
155843
|
+
};
|
|
156816
155844
|
}
|
|
156817
155845
|
/**
|
|
156818
155846
|
* Create a minimal DidDocument from "k1" btcr2 identifier.
|
|
@@ -157110,7 +156138,7 @@ a=end-of-candidates
|
|
|
157110
156138
|
patch: patches,
|
|
157111
156139
|
targetHash: "",
|
|
157112
156140
|
targetVersionId: sourceVersionId + 1,
|
|
157113
|
-
sourceHash: Canonicalization.process(sourceDocument, { encoding: "
|
|
156141
|
+
sourceHash: Canonicalization.process(sourceDocument, { encoding: "base58btc" })
|
|
157114
156142
|
};
|
|
157115
156143
|
const targetDocument = JSONPatch.apply(sourceDocument, patches);
|
|
157116
156144
|
try {
|
|
@@ -157122,7 +156150,7 @@ a=end-of-candidates
|
|
|
157122
156150
|
targetDocument
|
|
157123
156151
|
);
|
|
157124
156152
|
}
|
|
157125
|
-
unsignedUpdate.targetHash = Canonicalization.process(targetDocument, { encoding: "
|
|
156153
|
+
unsignedUpdate.targetHash = Canonicalization.process(targetDocument, { encoding: "base58btc" });
|
|
157126
156154
|
return unsignedUpdate;
|
|
157127
156155
|
}
|
|
157128
156156
|
/**
|
|
@@ -157165,9 +156193,9 @@ a=end-of-candidates
|
|
|
157165
156193
|
* @returns {SignedBTCR2Update} The SignedBTCR2Update object containing data to validate the Beacon Signal
|
|
157166
156194
|
* @throws {UpdateError} if the beaconService type is invalid
|
|
157167
156195
|
*/
|
|
157168
|
-
static async announce(beaconService, update, secretKey,
|
|
156196
|
+
static async announce(beaconService, update, secretKey, bitcoin2) {
|
|
157169
156197
|
const beacon = BeaconFactory.establish(beaconService);
|
|
157170
|
-
const result = await beacon.broadcastSignal(update, secretKey,
|
|
156198
|
+
const result = await beacon.broadcastSignal(update, secretKey, bitcoin2);
|
|
157171
156199
|
return result;
|
|
157172
156200
|
}
|
|
157173
156201
|
};
|
|
@@ -157204,7 +156232,7 @@ a=end-of-candidates
|
|
|
157204
156232
|
options2
|
|
157205
156233
|
);
|
|
157206
156234
|
}
|
|
157207
|
-
return Identifier.encode({ idType,
|
|
156235
|
+
return Identifier.encode(genesisBytes, { idType, version: version3, network });
|
|
157208
156236
|
}
|
|
157209
156237
|
/**
|
|
157210
156238
|
* Entry point for section {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html | 7.2 Resolve}.
|
|
@@ -157255,15 +156283,17 @@ a=end-of-candidates
|
|
|
157255
156283
|
const currentDocument = await Resolve.currentDocument(didComponents, genesisDocument);
|
|
157256
156284
|
const beaconServices = currentDocument.service.filter(BeaconUtils.isBeaconService).map(BeaconUtils.parseBeaconServiceEndpoint);
|
|
157257
156285
|
if (!resolutionOptions?.drivers?.bitcoin) {
|
|
157258
|
-
|
|
157259
|
-
|
|
157260
|
-
|
|
156286
|
+
throw new ResolveError(
|
|
156287
|
+
"Bitcoin connection required for resolve. Pass a configured driver via resolutionOptions.drivers.bitcoin or use DidBtcr2Api which injects it automatically.",
|
|
156288
|
+
MISSING_RESOLUTION_OPTIONS,
|
|
156289
|
+
resolutionOptions
|
|
156290
|
+
);
|
|
157261
156291
|
}
|
|
157262
|
-
const
|
|
156292
|
+
const bitcoin2 = resolutionOptions.drivers.bitcoin;
|
|
157263
156293
|
const unsortedUpdates = await Resolve.beaconSignals(
|
|
157264
156294
|
beaconServices,
|
|
157265
156295
|
sidecarData,
|
|
157266
|
-
|
|
156296
|
+
bitcoin2
|
|
157267
156297
|
);
|
|
157268
156298
|
if (!unsortedUpdates.length) {
|
|
157269
156299
|
didResolutionResult.didDocument = currentDocument;
|
|
@@ -157281,8 +156311,7 @@ a=end-of-candidates
|
|
|
157281
156311
|
didResolutionResult.didDocumentMetadata = result.metadata;
|
|
157282
156312
|
return didResolutionResult;
|
|
157283
156313
|
} catch (error) {
|
|
157284
|
-
|
|
157285
|
-
if (!(error instanceof ResolveError)) throw new Error(error);
|
|
156314
|
+
if (!(error instanceof ResolveError)) throw new Error(error.message ?? error, { cause: error });
|
|
157286
156315
|
return {
|
|
157287
156316
|
...EMPTY_DID_RESOLUTION_RESULT,
|
|
157288
156317
|
didResolutionMetadata: {
|
|
@@ -157307,7 +156336,7 @@ a=end-of-candidates
|
|
|
157307
156336
|
* @param {string} params.verificationMethodId The verificationMethod ID to sign the update with.
|
|
157308
156337
|
* @param {string} params.beaconId The beacon ID associated with the update.
|
|
157309
156338
|
* @param {KeyBytes | HexString} [params.signingMaterial] Optional signing material (key bytes or hex string).
|
|
157310
|
-
* @param {
|
|
156339
|
+
* @param {BitcoinConnection} [params.bitcoin] Optional Bitcoin network connection for announcing the update. If not provided, a default connection will be initialized.
|
|
157311
156340
|
* @return {Promise<SignedBTCR2Update>} Promise resolving to the signed BTCR2 update.
|
|
157312
156341
|
* @throws {UpdateError} if no verificationMethod, verificationMethod type is not `Multikey` or the publicKeyMultibase
|
|
157313
156342
|
* header is not `zQ3s`
|
|
@@ -157319,7 +156348,7 @@ a=end-of-candidates
|
|
|
157319
156348
|
verificationMethodId,
|
|
157320
156349
|
beaconId,
|
|
157321
156350
|
signingMaterial,
|
|
157322
|
-
bitcoin:
|
|
156351
|
+
bitcoin: bitcoin2
|
|
157323
156352
|
}) {
|
|
157324
156353
|
if (!signingMaterial) {
|
|
157325
156354
|
throw new UpdateError(
|
|
@@ -157368,8 +156397,14 @@ a=end-of-candidates
|
|
|
157368
156397
|
{ sourceDocument, beaconId }
|
|
157369
156398
|
);
|
|
157370
156399
|
}
|
|
157371
|
-
|
|
157372
|
-
|
|
156400
|
+
if (!bitcoin2) {
|
|
156401
|
+
throw new UpdateError(
|
|
156402
|
+
"Bitcoin connection required for update. Pass a configured `bitcoin` parameter or use DidBtcr2Api which injects it automatically.",
|
|
156403
|
+
INVALID_DID_UPDATE,
|
|
156404
|
+
{ beaconId }
|
|
156405
|
+
);
|
|
156406
|
+
}
|
|
156407
|
+
await Update.announce(beaconService, signed, secretKey, bitcoin2);
|
|
157373
156408
|
return signed;
|
|
157374
156409
|
}
|
|
157375
156410
|
/**
|
|
@@ -157409,8 +156444,8 @@ a=end-of-candidates
|
|
|
157409
156444
|
* @returns {DidDocument} The resolved DID Document object.
|
|
157410
156445
|
*/
|
|
157411
156446
|
static deterministic(didComponents) {
|
|
157412
|
-
const did = Identifier.encode(didComponents);
|
|
157413
156447
|
const { genesisBytes } = didComponents;
|
|
156448
|
+
const did = Identifier.encode(genesisBytes, didComponents);
|
|
157414
156449
|
const { multibase: publicKeyMultibase } = new CompressedSecp256k1PublicKey(genesisBytes);
|
|
157415
156450
|
const service = BeaconUtils.generateBeaconServices({
|
|
157416
156451
|
id: did,
|
|
@@ -157438,15 +156473,15 @@ a=end-of-candidates
|
|
|
157438
156473
|
*/
|
|
157439
156474
|
static async external(didComponents, genesisDocument) {
|
|
157440
156475
|
const hashBytes = Canonicalization.process(genesisDocument, { encoding: "hex" });
|
|
157441
|
-
const genesisBytes =
|
|
157442
|
-
if (genesisBytes !== hashBytes) {
|
|
156476
|
+
const { genesisBytes } = didComponents;
|
|
156477
|
+
if (bytesToHex(genesisBytes) !== hashBytes) {
|
|
157443
156478
|
throw new ResolveError(
|
|
157444
|
-
`Initial document mismatch: genesisBytes ${genesisBytes} !== hashBytes ${hashBytes}`,
|
|
156479
|
+
`Initial document mismatch: genesisBytes ${bytesToHex(genesisBytes)} !== hashBytes ${hashBytes}`,
|
|
157445
156480
|
INVALID_DID_DOCUMENT,
|
|
157446
156481
|
{ genesisBytes, hashBytes }
|
|
157447
156482
|
);
|
|
157448
156483
|
}
|
|
157449
|
-
const did = Identifier.encode(didComponents);
|
|
156484
|
+
const did = Identifier.encode(genesisBytes, didComponents);
|
|
157450
156485
|
const currentDocument = JSON.parse(
|
|
157451
156486
|
JSON.stringify(genesisDocument).replaceAll(ID_PLACEHOLDER_VALUE, did)
|
|
157452
156487
|
);
|
|
@@ -157512,11 +156547,11 @@ a=end-of-candidates
|
|
|
157512
156547
|
* Signal Bytes (last output in OP_RETURN transaction).
|
|
157513
156548
|
* @param {Array<BeaconService>} beaconServices The array of BeaconService objects to search for signals.
|
|
157514
156549
|
* @param {SidecarData} sidecarData The sidecar data containing maps of updates, CAS announcements, and SMT proofs.
|
|
157515
|
-
* @param {
|
|
156550
|
+
* @param {BitcoinConnection} bitcoin The bitcoin network connection used to fetch beacon signals
|
|
157516
156551
|
* @returns {Promise<Array<[SignedBTCR2Update, BlockMetadata]>>} The array of BTCR2 Signed Updates announced by the Beacon Signals.
|
|
157517
156552
|
*/
|
|
157518
|
-
static async beaconSignals(beaconServices, sidecarData,
|
|
157519
|
-
const beaconServicesSignals =
|
|
156553
|
+
static async beaconSignals(beaconServices, sidecarData, bitcoin2) {
|
|
156554
|
+
const beaconServicesSignals = bitcoin2.rest ? await BeaconSignalDiscovery.indexer(beaconServices, bitcoin2) : await BeaconSignalDiscovery.fullnode(beaconServices, bitcoin2);
|
|
157520
156555
|
const promises = await Promise.all(
|
|
157521
156556
|
Array.from(beaconServicesSignals.entries()).map(
|
|
157522
156557
|
async ([service, signals]) => {
|
|
@@ -157551,7 +156586,7 @@ a=end-of-candidates
|
|
|
157551
156586
|
}
|
|
157552
156587
|
};
|
|
157553
156588
|
for (const [update, block] of updates) {
|
|
157554
|
-
const currentDocumentHash = Canonicalization.process(response2.didDocument, { encoding: "
|
|
156589
|
+
const currentDocumentHash = Canonicalization.process(response2.didDocument, { encoding: "base58btc" });
|
|
157555
156590
|
const blocktime = DateUtils.blocktimeToTimestamp(block.time);
|
|
157556
156591
|
response2.metadata.updated = DateUtils.toISOStringNonFractional(blocktime);
|
|
157557
156592
|
response2.metadata.confirmations = block.confirmations;
|
|
@@ -157573,7 +156608,7 @@ a=end-of-candidates
|
|
|
157573
156608
|
}
|
|
157574
156609
|
response2.didDocument = await this.applyUpdate(response2.didDocument, update);
|
|
157575
156610
|
const unsignedUpdate = JSONUtils.deleteKeys(update, ["proof"]);
|
|
157576
|
-
updateHashHistory.push(Canonicalization.process(unsignedUpdate, { encoding: "
|
|
156611
|
+
updateHashHistory.push(Canonicalization.process(unsignedUpdate, { encoding: "base58btc" }));
|
|
157577
156612
|
} else if (update.targetVersionId > currentVersionId + 1) {
|
|
157578
156613
|
throw new ResolveError(
|
|
157579
156614
|
`Version Id Mismatch: targetVersionId cannot be > currentVersionId + 1`,
|
|
@@ -157654,11 +156689,11 @@ a=end-of-candidates
|
|
|
157654
156689
|
}
|
|
157655
156690
|
const updatedDocument = JSONPatch.apply(currentDocument, update.patch);
|
|
157656
156691
|
DidDocument2.validate(updatedDocument);
|
|
157657
|
-
const currentDocumentHash = Canonicalization.process(updatedDocument, { encoding: "
|
|
157658
|
-
const updateTargetHash = update.targetHash
|
|
157659
|
-
if (
|
|
156692
|
+
const currentDocumentHash = Canonicalization.process(updatedDocument, { encoding: "base58btc" });
|
|
156693
|
+
const updateTargetHash = update.targetHash;
|
|
156694
|
+
if (update.targetHash !== currentDocumentHash) {
|
|
157660
156695
|
throw new ResolveError(
|
|
157661
|
-
`Invalid update:
|
|
156696
|
+
`Invalid update: update.targetHash !== currentDocumentHash`,
|
|
157662
156697
|
INVALID_DID_UPDATE,
|
|
157663
156698
|
{ updateTargetHash, currentDocumentHash }
|
|
157664
156699
|
);
|