@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.mjs
CHANGED
|
@@ -57529,8 +57529,9 @@ var MethodErrorCode;
|
|
|
57529
57529
|
MethodErrorCode2["MISSING_UPDATE_DATA"] = "MISSING_UPDATE_DATA";
|
|
57530
57530
|
MethodErrorCode2["INVALID_UPDATE"] = "INVALID_UPDATE";
|
|
57531
57531
|
MethodErrorCode2["INVALID_DOMAIN_ERROR"] = "INVALID_DOMAIN_ERROR";
|
|
57532
|
+
MethodErrorCode2["MISSING_RESOLUTION_OPTIONS"] = "MISSING_RESOLUTION_OPTIONS";
|
|
57532
57533
|
})(MethodErrorCode || (MethodErrorCode = {}));
|
|
57533
|
-
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;
|
|
57534
|
+
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;
|
|
57534
57535
|
var NotImplementedError = class _NotImplementedError extends Error {
|
|
57535
57536
|
name = "NotImplementedError";
|
|
57536
57537
|
type = "NotImplementedError";
|
|
@@ -57620,6 +57621,40 @@ var CanonicalizationError = class extends DidMethodError {
|
|
|
57620
57621
|
}
|
|
57621
57622
|
};
|
|
57622
57623
|
|
|
57624
|
+
// ../../node_modules/.pnpm/multiformats@13.4.1/node_modules/multiformats/dist/src/bases/base64.js
|
|
57625
|
+
var base64_exports = {};
|
|
57626
|
+
__export(base64_exports, {
|
|
57627
|
+
base64: () => base64,
|
|
57628
|
+
base64pad: () => base64pad,
|
|
57629
|
+
base64url: () => base64url,
|
|
57630
|
+
base64urlpad: () => base64urlpad
|
|
57631
|
+
});
|
|
57632
|
+
init_shim();
|
|
57633
|
+
var base64 = rfc4648({
|
|
57634
|
+
prefix: "m",
|
|
57635
|
+
name: "base64",
|
|
57636
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
|
|
57637
|
+
bitsPerChar: 6
|
|
57638
|
+
});
|
|
57639
|
+
var base64pad = rfc4648({
|
|
57640
|
+
prefix: "M",
|
|
57641
|
+
name: "base64pad",
|
|
57642
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
|
|
57643
|
+
bitsPerChar: 6
|
|
57644
|
+
});
|
|
57645
|
+
var base64url = rfc4648({
|
|
57646
|
+
prefix: "u",
|
|
57647
|
+
name: "base64url",
|
|
57648
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",
|
|
57649
|
+
bitsPerChar: 6
|
|
57650
|
+
});
|
|
57651
|
+
var base64urlpad = rfc4648({
|
|
57652
|
+
prefix: "U",
|
|
57653
|
+
name: "base64urlpad",
|
|
57654
|
+
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",
|
|
57655
|
+
bitsPerChar: 6
|
|
57656
|
+
});
|
|
57657
|
+
|
|
57623
57658
|
// ../common/dist/esm/canonicalization.js
|
|
57624
57659
|
var Canonicalization = class _Canonicalization {
|
|
57625
57660
|
/**
|
|
@@ -57643,7 +57678,7 @@ var Canonicalization = class _Canonicalization {
|
|
|
57643
57678
|
*/
|
|
57644
57679
|
static normalizeEncoding(encoding) {
|
|
57645
57680
|
const normalized = encoding.toLowerCase();
|
|
57646
|
-
if (
|
|
57681
|
+
if (!["hex", "base58btc", "base64url"].includes(normalized)) {
|
|
57647
57682
|
throw new CanonicalizationError(`Unsupported encoding: ${encoding}`, "ENCODING_ERROR");
|
|
57648
57683
|
}
|
|
57649
57684
|
return normalized;
|
|
@@ -57659,7 +57694,7 @@ var Canonicalization = class _Canonicalization {
|
|
|
57659
57694
|
*
|
|
57660
57695
|
* @param {Record<any, any>} object The object to process.
|
|
57661
57696
|
* @param {Object} [options] Options for processing.
|
|
57662
|
-
* @param {CanonicalizationEncoding} [options.encoding='hex'] The encoding format ('hex' or '
|
|
57697
|
+
* @param {CanonicalizationEncoding} [options.encoding='hex'] The encoding format ('hex' or 'base58btc').
|
|
57663
57698
|
* @param {CanonicalizationAlgorithm} [options.algorithm] The canonicalization algorithm to use.
|
|
57664
57699
|
* @returns {string} The final SHA-256 hash bytes as a hex string.
|
|
57665
57700
|
*/
|
|
@@ -57702,9 +57737,9 @@ var Canonicalization = class _Canonicalization {
|
|
|
57702
57737
|
return sha256(canonicalized);
|
|
57703
57738
|
}
|
|
57704
57739
|
/**
|
|
57705
|
-
* Step 3: Encodes SHA-256 hashed, canonicalized object as a hex or
|
|
57740
|
+
* Step 3: Encodes SHA-256 hashed, canonicalized object as a hex or base58btc string.
|
|
57706
57741
|
* @param {string} canonicalizedhash The canonicalized object to encode.
|
|
57707
|
-
* @param {CanonicalizationEncoding} encoding The encoding format ('hex' or '
|
|
57742
|
+
* @param {CanonicalizationEncoding} encoding The encoding format ('hex' or 'base58btc').
|
|
57708
57743
|
* @throws {CanonicalizationError} If the encoding format is not supported.
|
|
57709
57744
|
* @returns {string} The encoded string.
|
|
57710
57745
|
*/
|
|
@@ -57713,15 +57748,18 @@ var Canonicalization = class _Canonicalization {
|
|
|
57713
57748
|
if (normalized === "hex") {
|
|
57714
57749
|
return this.toHex(canonicalizedhash);
|
|
57715
57750
|
}
|
|
57716
|
-
if (normalized === "
|
|
57751
|
+
if (normalized === "base58btc") {
|
|
57717
57752
|
return this.toBase58(canonicalizedhash);
|
|
57718
57753
|
}
|
|
57754
|
+
if (normalized === "base64url") {
|
|
57755
|
+
return this.toBase64Url(canonicalizedhash);
|
|
57756
|
+
}
|
|
57719
57757
|
throw new CanonicalizationError(`Unsupported encoding: ${encoding}`, "ENCODING_ERROR");
|
|
57720
57758
|
}
|
|
57721
57759
|
/**
|
|
57722
|
-
* Decodes SHA-256 hashed, canonicalized object as a hex or
|
|
57760
|
+
* Decodes SHA-256 hashed, canonicalized object as a hex or base58btc string.
|
|
57723
57761
|
* @param {string} canonicalizedhash The canonicalized object to encode.
|
|
57724
|
-
* @param {CanonicalizationEncoding} encoding The encoding format ('hex' or '
|
|
57762
|
+
* @param {CanonicalizationEncoding} encoding The encoding format ('hex' or 'base58btc').
|
|
57725
57763
|
* @throws {CanonicalizationError} If the encoding format is not supported.
|
|
57726
57764
|
* @returns {string} The encoded string.
|
|
57727
57765
|
*/
|
|
@@ -57730,9 +57768,12 @@ var Canonicalization = class _Canonicalization {
|
|
|
57730
57768
|
if (normalized === "hex") {
|
|
57731
57769
|
return this.fromHex(canonicalizedhash);
|
|
57732
57770
|
}
|
|
57733
|
-
if (normalized === "
|
|
57771
|
+
if (normalized === "base58btc") {
|
|
57734
57772
|
return this.fromBase58(canonicalizedhash);
|
|
57735
57773
|
}
|
|
57774
|
+
if (normalized === "base64url") {
|
|
57775
|
+
return this.fromBase64Url(canonicalizedhash);
|
|
57776
|
+
}
|
|
57736
57777
|
throw new CanonicalizationError(`Unsupported encoding: ${encoding}`, "DECODING_ERROR");
|
|
57737
57778
|
}
|
|
57738
57779
|
/**
|
|
@@ -57760,13 +57801,29 @@ var Canonicalization = class _Canonicalization {
|
|
|
57760
57801
|
return base58btc.encode(hashBytes);
|
|
57761
57802
|
}
|
|
57762
57803
|
/**
|
|
57763
|
-
* Decodes a
|
|
57764
|
-
* @param {string} b58str The hash as a
|
|
57804
|
+
* Decodes a base58btc string to HashBytes (Uint8Array).
|
|
57805
|
+
* @param {string} b58str The hash as a base58btc string.
|
|
57765
57806
|
* @returns {HashBytes} The hash bytes.
|
|
57766
57807
|
*/
|
|
57767
57808
|
static fromBase58(b58str) {
|
|
57768
57809
|
return base58btc.decode(b58str);
|
|
57769
57810
|
}
|
|
57811
|
+
/**
|
|
57812
|
+
* Step 3.2: Encodes HashBytes (Uint8Array) to a base64url string.
|
|
57813
|
+
* @param {HashBytes} hashBytes The hash as a Uint8Array.
|
|
57814
|
+
* @returns {string} The hash as a base64url string.
|
|
57815
|
+
*/
|
|
57816
|
+
static toBase64Url(hashBytes) {
|
|
57817
|
+
return base64url.encode(hashBytes);
|
|
57818
|
+
}
|
|
57819
|
+
/**
|
|
57820
|
+
* Decodes a base64url string to HashBytes (Uint8Array).
|
|
57821
|
+
* @param {string} b64urlstr The hash as a base64url string.
|
|
57822
|
+
* @returns {HashBytes} The hash bytes.
|
|
57823
|
+
*/
|
|
57824
|
+
static fromBase64Url(b64urlstr) {
|
|
57825
|
+
return base64url.decode(b64urlstr);
|
|
57826
|
+
}
|
|
57770
57827
|
/**
|
|
57771
57828
|
* Canonicalizes an object, hashes it and returns it as hash bytes.
|
|
57772
57829
|
* Step 1-2: Canonicalize → Hash.
|
|
@@ -57790,13 +57847,22 @@ var Canonicalization = class _Canonicalization {
|
|
|
57790
57847
|
return hexed;
|
|
57791
57848
|
}
|
|
57792
57849
|
/**
|
|
57793
|
-
* Computes the SHA-256 hashes of canonicalized object and encodes it as a
|
|
57794
|
-
* Step 2-3: Hash → Encode(
|
|
57850
|
+
* Computes the SHA-256 hashes of canonicalized object and encodes it as a base58btc string.
|
|
57851
|
+
* Step 2-3: Hash → Encode(base58btc).
|
|
57795
57852
|
* @param {string} canonicalized The canonicalized object to hash.
|
|
57796
|
-
* @returns {string} The SHA-256 hash as a
|
|
57853
|
+
* @returns {string} The SHA-256 hash as a base58btc string.
|
|
57797
57854
|
*/
|
|
57798
57855
|
static andHashToBase58(canonicalized) {
|
|
57799
|
-
return this.encode(this.toHash(canonicalized), "
|
|
57856
|
+
return this.encode(this.toHash(canonicalized), "base58btc");
|
|
57857
|
+
}
|
|
57858
|
+
/**
|
|
57859
|
+
* Computes the SHA-256 hashes of canonicalized object and encodes it as a base64url string.
|
|
57860
|
+
* Step 2-3: Hash → Encode(base64url).
|
|
57861
|
+
* @param {string} canonicalized The canonicalized object to hash.
|
|
57862
|
+
* @returns {string} The SHA-256 hash as a base64url string.
|
|
57863
|
+
*/
|
|
57864
|
+
static andHashToBase64Url(canonicalized) {
|
|
57865
|
+
return this.toBase64Url(this.toHash(canonicalized));
|
|
57800
57866
|
}
|
|
57801
57867
|
};
|
|
57802
57868
|
|
|
@@ -57880,9 +57946,6 @@ var BTCR2_DID_UPDATE_PAYLOAD_CONTEXT = [
|
|
|
57880
57946
|
CONTEXT_URL_MAP.w3c.jsonldpatch.v1
|
|
57881
57947
|
];
|
|
57882
57948
|
|
|
57883
|
-
// ../common/dist/esm/interfaces.js
|
|
57884
|
-
init_shim();
|
|
57885
|
-
|
|
57886
57949
|
// ../common/dist/esm/json-patch.js
|
|
57887
57950
|
init_shim();
|
|
57888
57951
|
|
|
@@ -59551,51 +59614,6 @@ init_shim();
|
|
|
59551
59614
|
|
|
59552
59615
|
// ../common/dist/esm/utils/string.js
|
|
59553
59616
|
init_shim();
|
|
59554
|
-
var StringUtils = class {
|
|
59555
|
-
/**
|
|
59556
|
-
* Escape special characters in a string for use in a regular expression.
|
|
59557
|
-
* @param {string} value - The string to escape.
|
|
59558
|
-
* @returns {string} The escaped string.
|
|
59559
|
-
*/
|
|
59560
|
-
static escapeRegExp(value3) {
|
|
59561
|
-
return value3.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
59562
|
-
}
|
|
59563
|
-
/**
|
|
59564
|
-
* Convert a camelCase string to snake_case.
|
|
59565
|
-
* @param {string} value - The camelCase string to convert.
|
|
59566
|
-
* @returns {string} The converted snake_case string.
|
|
59567
|
-
*/
|
|
59568
|
-
static toSnake(value3) {
|
|
59569
|
-
return value3.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase();
|
|
59570
|
-
}
|
|
59571
|
-
/**
|
|
59572
|
-
* Convert a string to SNAKE_SCREAMING_CASE.
|
|
59573
|
-
* @param {string} value - The string to convert.
|
|
59574
|
-
* @returns {string} The converted SNAKE_SCREAMING_CASE string.
|
|
59575
|
-
*/
|
|
59576
|
-
static toSnakeScream(value3) {
|
|
59577
|
-
return this.toSnake(value3).toUpperCase();
|
|
59578
|
-
}
|
|
59579
|
-
/**
|
|
59580
|
-
* Remove the last character from a string.
|
|
59581
|
-
* @param {string} value - The string to chop.
|
|
59582
|
-
* @returns {string} The chopped string.
|
|
59583
|
-
*/
|
|
59584
|
-
static chop(value3) {
|
|
59585
|
-
return value3.length > 0 ? value3.slice(0, -1) : "";
|
|
59586
|
-
}
|
|
59587
|
-
/**
|
|
59588
|
-
* Replace the end of a string if it matches a given pattern.
|
|
59589
|
-
* @param {string} value - The string to modify.
|
|
59590
|
-
* @param {string | RegExp} pattern - The pattern to match at the end of the string.
|
|
59591
|
-
* @param {string} [replacement=''] - The replacement string.
|
|
59592
|
-
* @returns {string} The modified string.
|
|
59593
|
-
*/
|
|
59594
|
-
static replaceEnd(value3, pattern, replacement = "") {
|
|
59595
|
-
const regex3 = pattern instanceof RegExp ? new RegExp(pattern.source.endsWith("$") ? pattern.source : `${pattern.source}$`, pattern.flags.replace(/g/g, "")) : new RegExp(`${this.escapeRegExp(pattern)}$`);
|
|
59596
|
-
return value3.replace(regex3, replacement);
|
|
59597
|
-
}
|
|
59598
|
-
};
|
|
59599
59617
|
|
|
59600
59618
|
// src/core/beacon/error.ts
|
|
59601
59619
|
var BeaconError = class extends MethodError {
|
|
@@ -59658,8 +59676,13 @@ var BaseMessage = class {
|
|
|
59658
59676
|
* Converts a BaseMessage to a JSON object.
|
|
59659
59677
|
* @returns {Base} The JSON representation of the BaseMessage.
|
|
59660
59678
|
*/
|
|
59661
|
-
|
|
59662
|
-
return
|
|
59679
|
+
toJSON() {
|
|
59680
|
+
return {
|
|
59681
|
+
type: this.type,
|
|
59682
|
+
to: this.to,
|
|
59683
|
+
from: this.from,
|
|
59684
|
+
body: this.body
|
|
59685
|
+
};
|
|
59663
59686
|
}
|
|
59664
59687
|
};
|
|
59665
59688
|
|
|
@@ -59843,7 +59866,7 @@ var BeaconCohortSigningSession = class {
|
|
|
59843
59866
|
throw new AggregateBeaconError(
|
|
59844
59867
|
`Missing ${missing} nonce contributions. Received ${this.cohort?.participants.length} of ${this.nonceContributions.size} nonce contributions. Current status: ${this.status}`,
|
|
59845
59868
|
"NONCE_CONTRIBUTION_ERROR",
|
|
59846
|
-
this.
|
|
59869
|
+
this.toJSON()
|
|
59847
59870
|
);
|
|
59848
59871
|
}
|
|
59849
59872
|
const sortedPubkeys = sortKeys(this.cohort.cohortKeys);
|
|
@@ -59910,8 +59933,20 @@ var BeaconCohortSigningSession = class {
|
|
|
59910
59933
|
* Converts the signing session instance to a JSON object representation.
|
|
59911
59934
|
* @returns {BeaconCohortSigningSession} The JSON object representation of the signing session.
|
|
59912
59935
|
*/
|
|
59913
|
-
|
|
59914
|
-
return
|
|
59936
|
+
toJSON() {
|
|
59937
|
+
return {
|
|
59938
|
+
id: this.id,
|
|
59939
|
+
cohort: this.cohort,
|
|
59940
|
+
pendingTx: this.pendingTx,
|
|
59941
|
+
nonceContributions: this.nonceContributions,
|
|
59942
|
+
aggregatedNonce: this.aggregatedNonce,
|
|
59943
|
+
partialSignatures: this.partialSignatures,
|
|
59944
|
+
signature: this.signature,
|
|
59945
|
+
status: this.status,
|
|
59946
|
+
processedRequests: this.processedRequests,
|
|
59947
|
+
nonceSecrets: this.nonceSecrets,
|
|
59948
|
+
musig2Session: this.musig2Session
|
|
59949
|
+
};
|
|
59915
59950
|
}
|
|
59916
59951
|
/**
|
|
59917
59952
|
* Checks if the signing session is a completed state.
|
|
@@ -60195,8 +60230,19 @@ var AggregateBeaconCohort = class _AggregateBeaconCohort {
|
|
|
60195
60230
|
* Converts the cohort instance to a JSON object representation.
|
|
60196
60231
|
* @returns {BeaconCohort} The JSON object representation of the cohort.
|
|
60197
60232
|
*/
|
|
60198
|
-
|
|
60199
|
-
return
|
|
60233
|
+
toJSON() {
|
|
60234
|
+
return {
|
|
60235
|
+
id: this.id,
|
|
60236
|
+
coordinatorDid: this.coordinatorDid,
|
|
60237
|
+
minParticipants: this.minParticipants,
|
|
60238
|
+
status: this.status,
|
|
60239
|
+
network: this.network,
|
|
60240
|
+
pendingSignatureRequests: this.pendingSignatureRequests,
|
|
60241
|
+
participants: this.participants,
|
|
60242
|
+
cohortKeys: this.cohortKeys,
|
|
60243
|
+
trMerkleRoot: this.trMerkleRoot,
|
|
60244
|
+
beaconAddress: this.beaconAddress
|
|
60245
|
+
};
|
|
60200
60246
|
}
|
|
60201
60247
|
};
|
|
60202
60248
|
|
|
@@ -60587,7 +60633,7 @@ var Secp256k1SecretKey = class _Secp256k1SecretKey {
|
|
|
60587
60633
|
* Converts the secret key to a JSON object.
|
|
60588
60634
|
* @returns {SecretKeyObject} The secret key as a JSON object
|
|
60589
60635
|
*/
|
|
60590
|
-
|
|
60636
|
+
toJSON() {
|
|
60591
60637
|
return {
|
|
60592
60638
|
bytes: Array.from(this.bytes),
|
|
60593
60639
|
seed: this.seed.toString(),
|
|
@@ -60732,9 +60778,13 @@ var Secp256k1SecretKey = class _Secp256k1SecretKey {
|
|
|
60732
60778
|
|
|
60733
60779
|
// ../keypair/dist/esm/public.js
|
|
60734
60780
|
var CompressedSecp256k1PublicKey = class _CompressedSecp256k1PublicKey {
|
|
60735
|
-
/**
|
|
60781
|
+
/**
|
|
60782
|
+
* The public key bytes
|
|
60783
|
+
**/
|
|
60736
60784
|
#bytes;
|
|
60737
|
-
/**
|
|
60785
|
+
/**
|
|
60786
|
+
* The public key as a MultibaseObject
|
|
60787
|
+
*/
|
|
60738
60788
|
#multibase = {
|
|
60739
60789
|
prefix: BIP340_PUBLIC_KEY_MULTIBASE_PREFIX,
|
|
60740
60790
|
key: [],
|
|
@@ -60906,7 +60956,7 @@ var CompressedSecp256k1PublicKey = class _CompressedSecp256k1PublicKey {
|
|
|
60906
60956
|
* JSON representation of a CompressedSecp256k1PublicKey object.
|
|
60907
60957
|
* @returns {PublicKeyObject} The CompressedSecp256k1PublicKey as a JSON object.
|
|
60908
60958
|
*/
|
|
60909
|
-
|
|
60959
|
+
toJSON() {
|
|
60910
60960
|
return {
|
|
60911
60961
|
hex: this.hex,
|
|
60912
60962
|
multibase: this.multibase,
|
|
@@ -61135,10 +61185,10 @@ var SchnorrKeyPair = class _SchnorrKeyPair {
|
|
|
61135
61185
|
* JSON representation of a Keys.
|
|
61136
61186
|
* @returns {SchnorrKeyPairObject} The Keys as a JSON object
|
|
61137
61187
|
*/
|
|
61138
|
-
|
|
61188
|
+
toJSON() {
|
|
61139
61189
|
return {
|
|
61140
|
-
secretKey: this.secretKey.
|
|
61141
|
-
publicKey: this.publicKey.
|
|
61190
|
+
secretKey: this.secretKey.toJSON(),
|
|
61191
|
+
publicKey: this.publicKey.toJSON()
|
|
61142
61192
|
};
|
|
61143
61193
|
}
|
|
61144
61194
|
/**
|
|
@@ -61231,14 +61281,12 @@ var Identifier = class {
|
|
|
61231
61281
|
* - a key-value representing a secp256k1 public key; or
|
|
61232
61282
|
* - a hash-value representing the hash of an initiating external DID document.
|
|
61233
61283
|
*
|
|
61234
|
-
* @param {
|
|
61235
|
-
* @param {
|
|
61236
|
-
* @param {string} params.network Bitcoin network name.
|
|
61237
|
-
* @param {number} params.version Identifier version.
|
|
61238
|
-
* @param {KeyBytes | DocumentBytes} params.genesisBytes Public key or an intermediate document bytes.
|
|
61284
|
+
* @param {KeyBytes | DocumentBytes} genesisBytes The genesis bytes (public key or document bytes).
|
|
61285
|
+
* @param {DidCreateOptions} options The DID creation options.
|
|
61239
61286
|
* @returns {string} The new did:btcr2 identifier.
|
|
61240
61287
|
*/
|
|
61241
|
-
static encode(
|
|
61288
|
+
static encode(genesisBytes, options2) {
|
|
61289
|
+
const { idType, version: version3 = 1, network } = options2;
|
|
61242
61290
|
if (!(idType in IdentifierTypes)) {
|
|
61243
61291
|
throw new IdentifierError('Expected "idType" to be "KEY" or "EXTERNAL"', INVALID_DID, { idType });
|
|
61244
61292
|
}
|
|
@@ -61367,14 +61415,16 @@ var Identifier = class {
|
|
|
61367
61415
|
* @returns {string} The new did:btcr2 identifier.
|
|
61368
61416
|
*/
|
|
61369
61417
|
static generate() {
|
|
61370
|
-
const
|
|
61371
|
-
const did = this.encode(
|
|
61372
|
-
|
|
61373
|
-
|
|
61374
|
-
|
|
61375
|
-
|
|
61376
|
-
|
|
61377
|
-
|
|
61418
|
+
const keyPair = SchnorrKeyPair.generate();
|
|
61419
|
+
const did = this.encode(
|
|
61420
|
+
keyPair.publicKey.compressed,
|
|
61421
|
+
{
|
|
61422
|
+
idType: "KEY",
|
|
61423
|
+
version: 1,
|
|
61424
|
+
network: "regtest"
|
|
61425
|
+
}
|
|
61426
|
+
);
|
|
61427
|
+
return { keyPair: keyPair.toJSON(), did };
|
|
61378
61428
|
}
|
|
61379
61429
|
/**
|
|
61380
61430
|
* Validates a did:btcr2 identifier.
|
|
@@ -61409,12 +61459,7 @@ var DidCommAdapterConfig = class {
|
|
|
61409
61459
|
idType: "KEY",
|
|
61410
61460
|
network: "mutinynet"
|
|
61411
61461
|
};
|
|
61412
|
-
this.did = config?.did || Identifier.encode(
|
|
61413
|
-
{
|
|
61414
|
-
...this.components,
|
|
61415
|
-
genesisBytes: this.keys.public
|
|
61416
|
-
}
|
|
61417
|
-
);
|
|
61462
|
+
this.did = config?.did || Identifier.encode(this.keys.public, this.components);
|
|
61418
61463
|
this.coordinatorDids = config?.coordinatorDids || [];
|
|
61419
61464
|
}
|
|
61420
61465
|
};
|
|
@@ -61484,22 +61529,22 @@ var DidCommAdapter = class {
|
|
|
61484
61529
|
this.config.keys.secret = Secp256k1SecretKey.random();
|
|
61485
61530
|
this.config.keys.public = Secp256k1SecretKey.getPublicKey(this.config.keys.secret).compressed;
|
|
61486
61531
|
this.config.did = Identifier.encode(
|
|
61532
|
+
this.config.keys.public,
|
|
61487
61533
|
{
|
|
61488
61534
|
idType: this.config.components.idType || "KEY",
|
|
61489
61535
|
version: this.config.components.version || 1,
|
|
61490
|
-
network: this.config.components.network || "
|
|
61491
|
-
genesisBytes: this.config.keys.public
|
|
61536
|
+
network: this.config.components.network || "regtest"
|
|
61492
61537
|
}
|
|
61493
61538
|
);
|
|
61494
61539
|
return this.config;
|
|
61495
61540
|
}
|
|
61496
61541
|
this.config.keys = keys;
|
|
61497
61542
|
this.config.did = Identifier.encode(
|
|
61543
|
+
this.config.keys.public,
|
|
61498
61544
|
{
|
|
61499
61545
|
idType: this.config.components.idType || "KEY",
|
|
61500
61546
|
version: this.config.components.version || 1,
|
|
61501
|
-
network: this.config.components.network || "
|
|
61502
|
-
genesisBytes: this.config.keys.public
|
|
61547
|
+
network: this.config.components.network || "regtest"
|
|
61503
61548
|
}
|
|
61504
61549
|
);
|
|
61505
61550
|
return this.config;
|
|
@@ -64140,8 +64185,8 @@ var base16 = chain2(radix22(4), alphabet2("0123456789ABCDEF"), join2(""));
|
|
|
64140
64185
|
var base32 = chain2(radix22(5), alphabet2("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), padding2(5), join2(""));
|
|
64141
64186
|
var base32hex = chain2(radix22(5), alphabet2("0123456789ABCDEFGHIJKLMNOPQRSTUV"), padding2(5), join2(""));
|
|
64142
64187
|
var base32crockford = chain2(radix22(5), alphabet2("0123456789ABCDEFGHJKMNPQRSTVWXYZ"), join2(""), normalize2((s2) => s2.toUpperCase().replace(/O/g, "0").replace(/[IL]/g, "1")));
|
|
64143
|
-
var
|
|
64144
|
-
var
|
|
64188
|
+
var base642 = chain2(radix22(6), alphabet2("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), padding2(6), join2(""));
|
|
64189
|
+
var base64url2 = chain2(radix22(6), alphabet2("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), padding2(6), join2(""));
|
|
64145
64190
|
var genBase582 = (abc) => chain2(radix3(58), alphabet2(abc), join2(""));
|
|
64146
64191
|
var base582 = genBase582("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
64147
64192
|
var base58flickr2 = genBase582("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ");
|
|
@@ -64263,8 +64308,8 @@ var CODERS = {
|
|
|
64263
64308
|
hex: hex2,
|
|
64264
64309
|
base16,
|
|
64265
64310
|
base32,
|
|
64266
|
-
base64,
|
|
64267
|
-
base64url,
|
|
64311
|
+
base64: base642,
|
|
64312
|
+
base64url: base64url2,
|
|
64268
64313
|
base58: base582,
|
|
64269
64314
|
base58xmr
|
|
64270
64315
|
};
|
|
@@ -66473,8 +66518,8 @@ function encrypt2(secretKey, pubkey, text) {
|
|
|
66473
66518
|
let iv = Uint8Array.from(randomBytes4(16));
|
|
66474
66519
|
let plaintext = utf8Encoder.encode(text);
|
|
66475
66520
|
let ciphertext = cbc(normalizedKey, iv).encrypt(plaintext);
|
|
66476
|
-
let ctb64 =
|
|
66477
|
-
let ivb64 =
|
|
66521
|
+
let ctb64 = base642.encode(new Uint8Array(ciphertext));
|
|
66522
|
+
let ivb64 = base642.encode(new Uint8Array(iv.buffer));
|
|
66478
66523
|
return `${ctb64}?iv=${ivb64}`;
|
|
66479
66524
|
}
|
|
66480
66525
|
function decrypt2(secretKey, pubkey, data) {
|
|
@@ -66482,8 +66527,8 @@ function decrypt2(secretKey, pubkey, data) {
|
|
|
66482
66527
|
let [ctb64, ivb64] = data.split("?iv=");
|
|
66483
66528
|
let key = secp256k12.getSharedSecret(privkey, "02" + pubkey);
|
|
66484
66529
|
let normalizedKey = getNormalizedX(key);
|
|
66485
|
-
let iv =
|
|
66486
|
-
let ciphertext =
|
|
66530
|
+
let iv = base642.decode(ivb64);
|
|
66531
|
+
let ciphertext = base642.decode(ctb64);
|
|
66487
66532
|
let plaintext = cbc(normalizedKey, iv).decrypt(ciphertext);
|
|
66488
66533
|
return utf8Decoder.decode(plaintext);
|
|
66489
66534
|
}
|
|
@@ -66793,7 +66838,7 @@ function decodePayload(payload) {
|
|
|
66793
66838
|
throw new Error("unknown encryption version");
|
|
66794
66839
|
let data;
|
|
66795
66840
|
try {
|
|
66796
|
-
data =
|
|
66841
|
+
data = base642.decode(payload);
|
|
66797
66842
|
} catch (error) {
|
|
66798
66843
|
throw new Error("invalid base64: " + error.message);
|
|
66799
66844
|
}
|
|
@@ -66814,7 +66859,7 @@ function encrypt22(plaintext, conversationKey, nonce = randomBytes4(32)) {
|
|
|
66814
66859
|
const padded = pad(plaintext);
|
|
66815
66860
|
const ciphertext = chacha20(chacha_key, chacha_nonce, padded);
|
|
66816
66861
|
const mac = hmacAad(hmac_key, ciphertext, nonce);
|
|
66817
|
-
return
|
|
66862
|
+
return base642.encode(concatBytes7(new Uint8Array([2]), nonce, ciphertext, mac));
|
|
66818
66863
|
}
|
|
66819
66864
|
function decrypt22(payload, conversationKey) {
|
|
66820
66865
|
const { nonce, ciphertext, mac } = decodePayload(payload);
|
|
@@ -67553,7 +67598,7 @@ async function getToken(loginUrl, httpMethod, sign2, includeAuthorizationScheme
|
|
|
67553
67598
|
}
|
|
67554
67599
|
const signedEvent = await sign2(event);
|
|
67555
67600
|
const authorizationScheme = includeAuthorizationScheme ? _authorizationScheme : "";
|
|
67556
|
-
return authorizationScheme +
|
|
67601
|
+
return authorizationScheme + base642.encode(utf8Encoder.encode(JSON.stringify(signedEvent)));
|
|
67557
67602
|
}
|
|
67558
67603
|
async function validateToken(token, url, method) {
|
|
67559
67604
|
const event = await unpackEventFromToken(token).catch((error) => {
|
|
@@ -67569,7 +67614,7 @@ async function unpackEventFromToken(token) {
|
|
|
67569
67614
|
throw new Error("Missing token");
|
|
67570
67615
|
}
|
|
67571
67616
|
token = token.replace(_authorizationScheme, "");
|
|
67572
|
-
const eventB64 = utf8Decoder.decode(
|
|
67617
|
+
const eventB64 = utf8Decoder.decode(base642.decode(token));
|
|
67573
67618
|
if (!eventB64 || eventB64.length === 0 || !eventB64.startsWith("{")) {
|
|
67574
67619
|
throw new Error("Invalid token");
|
|
67575
67620
|
}
|
|
@@ -68521,11 +68566,10 @@ var NostrAdapter = class {
|
|
|
68521
68566
|
constructor(config = { keys: {}, components: {}, relays: DEFAULT_NOSTR_RELAYS }) {
|
|
68522
68567
|
this.config = config;
|
|
68523
68568
|
this.config.keys = this.config.keys || SchnorrKeyPair.generate().raw;
|
|
68524
|
-
this.config.did = config.did || Identifier.encode({
|
|
68569
|
+
this.config.did = config.did || Identifier.encode(this.config.keys.public, {
|
|
68525
68570
|
idType: config.components.idType || "KEY",
|
|
68526
68571
|
version: config.components.version || 1,
|
|
68527
|
-
network: config.components.network || "signet"
|
|
68528
|
-
genesisBytes: this.config.keys.public
|
|
68572
|
+
network: config.components.network || "signet"
|
|
68529
68573
|
});
|
|
68530
68574
|
}
|
|
68531
68575
|
/**
|
|
@@ -68665,22 +68709,22 @@ var NostrAdapter = class {
|
|
|
68665
68709
|
this.config.keys.secret = Secp256k1SecretKey.random();
|
|
68666
68710
|
this.config.keys.public = Secp256k1SecretKey.getPublicKey(this.config.keys.secret).compressed;
|
|
68667
68711
|
this.config.did = Identifier.encode(
|
|
68712
|
+
this.config.keys.public,
|
|
68668
68713
|
{
|
|
68669
68714
|
idType: this.config.components.idType || "KEY",
|
|
68670
68715
|
version: this.config.components.version || 1,
|
|
68671
|
-
network: this.config.components.network || "signet"
|
|
68672
|
-
genesisBytes: this.config.keys.public
|
|
68716
|
+
network: this.config.components.network || "signet"
|
|
68673
68717
|
}
|
|
68674
68718
|
);
|
|
68675
68719
|
return this.config;
|
|
68676
68720
|
}
|
|
68677
68721
|
this.config.keys = keys;
|
|
68678
68722
|
this.config.did = Identifier.encode(
|
|
68723
|
+
this.config.keys.public,
|
|
68679
68724
|
{
|
|
68680
68725
|
idType: this.config.components.idType || "KEY",
|
|
68681
68726
|
version: this.config.components.version || 1,
|
|
68682
|
-
network: this.config.components.network || "signet"
|
|
68683
|
-
genesisBytes: this.config.keys.public
|
|
68727
|
+
network: this.config.components.network || "signet"
|
|
68684
68728
|
}
|
|
68685
68729
|
);
|
|
68686
68730
|
return this.config;
|
|
@@ -69875,12 +69919,12 @@ var CASBeacon = class extends Beacon {
|
|
|
69875
69919
|
* Broadcast CAS Beacon signal to the Bitcoin network.
|
|
69876
69920
|
* @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
|
|
69877
69921
|
* @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
|
|
69878
|
-
* @param {
|
|
69922
|
+
* @param {BitcoinConnection} bitcoin The Bitcoin network connection.
|
|
69879
69923
|
* @return {Promise<SignedBTCR2Update>} The signed update that was broadcasted.
|
|
69880
69924
|
* @throws {CASBeaconError} if broadcasting fails.
|
|
69881
69925
|
*/
|
|
69882
|
-
async broadcastSignal(signedUpdate, secretKey,
|
|
69883
|
-
throw new CASBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signedUpdate, secretKey, bitcoin:
|
|
69926
|
+
async broadcastSignal(signedUpdate, secretKey, bitcoin2) {
|
|
69927
|
+
throw new CASBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signedUpdate, secretKey, bitcoin: bitcoin2 });
|
|
69884
69928
|
}
|
|
69885
69929
|
};
|
|
69886
69930
|
|
|
@@ -69889,68 +69933,6 @@ init_shim();
|
|
|
69889
69933
|
|
|
69890
69934
|
// src/core/beacon/singleton.ts
|
|
69891
69935
|
init_shim();
|
|
69892
|
-
|
|
69893
|
-
// ../kms/dist/esm/index.js
|
|
69894
|
-
init_shim();
|
|
69895
|
-
|
|
69896
|
-
// ../kms/dist/esm/interface.js
|
|
69897
|
-
init_shim();
|
|
69898
|
-
|
|
69899
|
-
// ../kms/dist/esm/kms.js
|
|
69900
|
-
init_shim();
|
|
69901
|
-
|
|
69902
|
-
// ../kms/dist/esm/store.js
|
|
69903
|
-
init_shim();
|
|
69904
|
-
|
|
69905
|
-
// ../kms/dist/esm/signer.js
|
|
69906
|
-
init_shim();
|
|
69907
|
-
var Signer = class {
|
|
69908
|
-
/**
|
|
69909
|
-
* The key pair used for signing.
|
|
69910
|
-
* @type {SchnorrKeyPair}
|
|
69911
|
-
*/
|
|
69912
|
-
keyPair;
|
|
69913
|
-
/**
|
|
69914
|
-
* The network associated with the signer.
|
|
69915
|
-
* @type {keyof AvailableNetworks}
|
|
69916
|
-
*/
|
|
69917
|
-
network;
|
|
69918
|
-
/**
|
|
69919
|
-
* Creates an instance of Signer.
|
|
69920
|
-
* @param {{ keyPair: SchnorrKeyPair; network: keyof AvailableNetworks; }} params The parameters for the signer.
|
|
69921
|
-
* @param {SchnorrKeyPair} params.keyPair The key pair used for signing.
|
|
69922
|
-
* @param {keyof AvailableNetworks} params.network The network associated with the signer.
|
|
69923
|
-
*/
|
|
69924
|
-
constructor(params) {
|
|
69925
|
-
this.keyPair = params.keyPair;
|
|
69926
|
-
this.network = params.network;
|
|
69927
|
-
}
|
|
69928
|
-
/**
|
|
69929
|
-
* Gets the public key bytes.
|
|
69930
|
-
* @returns {KeyBytes} The public key bytes.
|
|
69931
|
-
*/
|
|
69932
|
-
get publicKey() {
|
|
69933
|
-
return this.keyPair.publicKey.compressed;
|
|
69934
|
-
}
|
|
69935
|
-
/**
|
|
69936
|
-
* Signs the given hash using ECDSA.
|
|
69937
|
-
* @param {Bytes} hash The hash to sign.
|
|
69938
|
-
* @returns {SignatureBytes} The signature of the hash.
|
|
69939
|
-
*/
|
|
69940
|
-
sign(hash4) {
|
|
69941
|
-
return this.keyPair.secretKey.sign(hash4, { scheme: "ecdsa" });
|
|
69942
|
-
}
|
|
69943
|
-
/**
|
|
69944
|
-
* Signs the given hash using Schnorr signature.
|
|
69945
|
-
* @param {Bytes} hash The hash to sign.
|
|
69946
|
-
* @returns {SignatureBytes} The Schnorr signature of the hash.
|
|
69947
|
-
*/
|
|
69948
|
-
signSchnorr(hash4) {
|
|
69949
|
-
return this.keyPair.secretKey.sign(hash4);
|
|
69950
|
-
}
|
|
69951
|
-
};
|
|
69952
|
-
|
|
69953
|
-
// src/core/beacon/singleton.ts
|
|
69954
69936
|
var SingletonBeacon = class extends Beacon {
|
|
69955
69937
|
/**
|
|
69956
69938
|
* Creates an instance of SingletonBeacon.
|
|
@@ -69977,7 +69959,7 @@ var SingletonBeacon = class extends Beacon {
|
|
|
69977
69959
|
signal
|
|
69978
69960
|
);
|
|
69979
69961
|
}
|
|
69980
|
-
const encodedUpdate = Canonicalization.process(signedUpdate, { encoding: "
|
|
69962
|
+
const encodedUpdate = Canonicalization.process(signedUpdate, { encoding: "base58btc" });
|
|
69981
69963
|
const signalBytes = base58btc.encode(import_buffer.Buffer.from(updateHash, "hex"));
|
|
69982
69964
|
if (encodedUpdate !== signalBytes) {
|
|
69983
69965
|
throw new SingletonBeaconError(
|
|
@@ -69994,13 +69976,13 @@ var SingletonBeacon = class extends Beacon {
|
|
|
69994
69976
|
* Broadcasts a SingletonBeacon signal to the Bitcoin network.
|
|
69995
69977
|
* @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
|
|
69996
69978
|
* @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
|
|
69997
|
-
* @param {
|
|
69979
|
+
* @param {BitcoinConnection} bitcoin The Bitcoin network connection.
|
|
69998
69980
|
* @returns {Promise<SignedBTCR2Update>} The signed update that was broadcast.
|
|
69999
69981
|
* @throws {SingletonBeaconError} if the bitcoin address is invalid or unfunded.
|
|
70000
69982
|
*/
|
|
70001
|
-
async broadcastSignal(signedUpdate, secretKey,
|
|
69983
|
+
async broadcastSignal(signedUpdate, secretKey, bitcoin2) {
|
|
70002
69984
|
const bitcoinAddress = this.service.serviceEndpoint.replace("bitcoin:", "");
|
|
70003
|
-
const utxos = await
|
|
69985
|
+
const utxos = await bitcoin2.rest.address.getUtxos(bitcoinAddress);
|
|
70004
69986
|
if (!utxos.length) {
|
|
70005
69987
|
throw new SingletonBeaconError(
|
|
70006
69988
|
"No UTXOs found, please fund address!",
|
|
@@ -70018,17 +70000,20 @@ var SingletonBeacon = class extends Beacon {
|
|
|
70018
70000
|
{ bitcoinAddress }
|
|
70019
70001
|
);
|
|
70020
70002
|
}
|
|
70021
|
-
const prevTx = await
|
|
70003
|
+
const prevTx = await bitcoin2.rest.transaction.getHex(utxo.txid);
|
|
70022
70004
|
const updateHash = Canonicalization.andHash(signedUpdate);
|
|
70023
|
-
const spendTx = new Psbt2({ network:
|
|
70005
|
+
const spendTx = new Psbt2({ network: bitcoin2.data }).addInput({
|
|
70024
70006
|
hash: utxo.txid,
|
|
70025
70007
|
index: utxo.vout,
|
|
70026
70008
|
nonWitnessUtxo: import_buffer.Buffer.from(prevTx, "hex")
|
|
70027
70009
|
}).addOutput({ address: bitcoinAddress, value: BigInt(utxo.value) - BigInt(500) }).addOutput({ script: script_exports.compile([OPS.OP_RETURN, updateHash]), value: 0n });
|
|
70028
70010
|
const keyPair = SchnorrKeyPair.fromSecret(secretKey);
|
|
70029
|
-
const signer =
|
|
70011
|
+
const signer = {
|
|
70012
|
+
publicKey: keyPair.publicKey.compressed,
|
|
70013
|
+
sign: (hash4) => keyPair.secretKey.sign(hash4, { scheme: "ecdsa" })
|
|
70014
|
+
};
|
|
70030
70015
|
const signedTx = spendTx.signInput(0, signer).finalizeAllInputs().extractTransaction().toHex();
|
|
70031
|
-
const txid = await
|
|
70016
|
+
const txid = await bitcoin2.rest.transaction.send(signedTx);
|
|
70032
70017
|
console.info(`Singleton Beacon Signal Broadcasted with txid: ${txid}`);
|
|
70033
70018
|
return signedUpdate;
|
|
70034
70019
|
}
|
|
@@ -70058,12 +70043,12 @@ var SMTBeacon = class extends Beacon {
|
|
|
70058
70043
|
* Broadcast CAS Beacon signal to the Bitcoin network.
|
|
70059
70044
|
* @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
|
|
70060
70045
|
* @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
|
|
70061
|
-
* @param {
|
|
70046
|
+
* @param {BitcoinConnection} bitcoin The Bitcoin network connection.
|
|
70062
70047
|
* @return {Promise<SignedBTCR2Update>} The signed update that was broadcasted.
|
|
70063
70048
|
* @throws {SMTBeaconError} if broadcasting fails.
|
|
70064
70049
|
*/
|
|
70065
|
-
async broadcastSignal(signedUpdate, secretKey,
|
|
70066
|
-
throw new SMTBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signedUpdate, secretKey, bitcoin:
|
|
70050
|
+
async broadcastSignal(signedUpdate, secretKey, bitcoin2) {
|
|
70051
|
+
throw new SMTBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signedUpdate, secretKey, bitcoin: bitcoin2 });
|
|
70067
70052
|
}
|
|
70068
70053
|
};
|
|
70069
70054
|
|
|
@@ -70103,382 +70088,23 @@ init_shim();
|
|
|
70103
70088
|
// ../bitcoin/dist/esm/client/rest/index.js
|
|
70104
70089
|
init_shim();
|
|
70105
70090
|
|
|
70106
|
-
// ../bitcoin/dist/esm/constants.js
|
|
70107
|
-
init_shim();
|
|
70108
|
-
var TXIN_WITNESS_COINBASE = "0000000000000000000000000000000000000000000000000000000000000000";
|
|
70109
|
-
var GENESIS_TX_ID = "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b";
|
|
70110
|
-
var DEFAULT_BITCOIN_NETWORK_CONFIG = {
|
|
70111
|
-
bitcoin: {
|
|
70112
|
-
rpc: void 0,
|
|
70113
|
-
rest: { host: "https://mempool.space/api" }
|
|
70114
|
-
},
|
|
70115
|
-
testnet3: {
|
|
70116
|
-
rpc: void 0,
|
|
70117
|
-
rest: { host: "https://mempool.space/testnet/api" }
|
|
70118
|
-
},
|
|
70119
|
-
testnet4: {
|
|
70120
|
-
rpc: void 0,
|
|
70121
|
-
rest: { host: "https://mempool.space/testnet4/api" }
|
|
70122
|
-
},
|
|
70123
|
-
signet: {
|
|
70124
|
-
rpc: void 0,
|
|
70125
|
-
rest: { host: "https://mempool.space/signet/api" }
|
|
70126
|
-
},
|
|
70127
|
-
mutinynet: {
|
|
70128
|
-
rpc: void 0,
|
|
70129
|
-
rest: { host: "https://mutinynet.com/api" }
|
|
70130
|
-
},
|
|
70131
|
-
regtest: {
|
|
70132
|
-
rpc: {
|
|
70133
|
-
network: "regtest",
|
|
70134
|
-
host: "http://localhost:18443",
|
|
70135
|
-
port: 18443,
|
|
70136
|
-
username: "polaruser",
|
|
70137
|
-
password: "polarpass",
|
|
70138
|
-
allowDefaultWallet: true,
|
|
70139
|
-
version: "28.1.0"
|
|
70140
|
-
},
|
|
70141
|
-
rest: { host: "http://localhost:3000" }
|
|
70142
|
-
}
|
|
70143
|
-
};
|
|
70144
|
-
|
|
70145
70091
|
// ../bitcoin/dist/esm/client/rest/address.js
|
|
70146
70092
|
init_shim();
|
|
70147
|
-
var BitcoinAddress = class {
|
|
70148
|
-
api;
|
|
70149
|
-
constructor(api) {
|
|
70150
|
-
this.api = api;
|
|
70151
|
-
}
|
|
70152
|
-
/**
|
|
70153
|
-
* Get transaction history for the specified address/scripthash, sorted with newest first.
|
|
70154
|
-
* Returns up to 50 mempool transactions plus the first 25 confirmed transactions.
|
|
70155
|
-
* See {@link https://github.com/blockstream/esplora/blob/master/API.md#get-addressaddresstxs | Esplora GET /address/:address/txs } for details.
|
|
70156
|
-
* @param {string} addressOrScripthash The address or scripthash to check.
|
|
70157
|
-
* @returns {Promise<Array<RawTransactionRest>>} A promise resolving to an array of {@link RawTransactionRest} objects.
|
|
70158
|
-
*/
|
|
70159
|
-
async getTxs(addressOrScripthash) {
|
|
70160
|
-
return await this.api({ path: `/address/${addressOrScripthash}/txs` });
|
|
70161
|
-
}
|
|
70162
|
-
/**
|
|
70163
|
-
* Calls getAddressTxs and checks if any funds come back.
|
|
70164
|
-
* Toggle if those funds are confirmed.
|
|
70165
|
-
* @param {string} addressOrScripthash The address or scripthash to check.
|
|
70166
|
-
* @returns {Promise<boolean>} True if the address has any funds, false otherwise.
|
|
70167
|
-
*/
|
|
70168
|
-
async isFundedAddress(addressOrScripthash) {
|
|
70169
|
-
const txs = await this.getConfirmedTxs(addressOrScripthash);
|
|
70170
|
-
const confirmed = txs.filter((tx) => tx.status.confirmed);
|
|
70171
|
-
return !!(confirmed && confirmed.length);
|
|
70172
|
-
}
|
|
70173
|
-
/**
|
|
70174
|
-
* Get unconfirmed transaction history for the specified address/scripthash.
|
|
70175
|
-
* Returns up to 50 transactions (no paging).
|
|
70176
|
-
* @param {string} addressOrScripthash The address or scripthash to check.
|
|
70177
|
-
* @returns {Promise<Array<RawTransactionRest>>} A promise resolving to an array of {@link RawTransactionRest} objects.
|
|
70178
|
-
*/
|
|
70179
|
-
async getTxsMempool(addressOrScripthash) {
|
|
70180
|
-
return await this.api({ path: `/address/${addressOrScripthash}/txs/mempool` });
|
|
70181
|
-
}
|
|
70182
|
-
/**
|
|
70183
|
-
* Get information about an address/scripthash.
|
|
70184
|
-
* Available fields: address/scripthash, chain_stats and mempool_stats.
|
|
70185
|
-
* {chain,mempool}_stats each contain an object with tx_count, funded_txo_count, funded_txo_sum, spent_txo_count and spent_txo_sum.
|
|
70186
|
-
* Elements-based chains don't have the {funded,spent}_txo_sum fields.
|
|
70187
|
-
* @param {string} addressOrScripthash The address or scripthash to check.
|
|
70188
|
-
* @returns {Promise<AddressInfo>} A promise resolving to an {@link AddressInfo} object.
|
|
70189
|
-
*/
|
|
70190
|
-
async getInfo(addressOrScripthash) {
|
|
70191
|
-
return await this.api({ path: `/address/${addressOrScripthash}` });
|
|
70192
|
-
}
|
|
70193
|
-
/**
|
|
70194
|
-
* Get confirmed transaction history for the specified address/scripthash, sorted with newest first.
|
|
70195
|
-
* Returns 25 transactions per page. More can be requested by specifying the last txid seen by the previous query.
|
|
70196
|
-
* @param {string} addressOrScripthash The address or scripthash to check.
|
|
70197
|
-
* @param lastSeenTxId The last transaction id seen by the previous query (optional).
|
|
70198
|
-
* @returns {Promise<Array<RawTransactionRest>>} A promise resolving to an array of {@link RawTransactionRest} objects.
|
|
70199
|
-
*/
|
|
70200
|
-
async getConfirmedTxs(addressOrScripthash, lastSeenTxId) {
|
|
70201
|
-
return await this.api({
|
|
70202
|
-
path: lastSeenTxId ? `/address/${addressOrScripthash}/txs/chain/${lastSeenTxId}` : `/address/${addressOrScripthash}/txs/chain`
|
|
70203
|
-
});
|
|
70204
|
-
}
|
|
70205
|
-
/**
|
|
70206
|
-
* Get the list of unspent transaction outputs associated with the address/scripthash.
|
|
70207
|
-
* See {@link https://github.com/Blockstream/esplora/blob/master/API.md#get-addressaddressutxo | Esplora GET /address/:address/utxo } for details.
|
|
70208
|
-
* @param {string} addressOrScripthash The address or scripthash to check.
|
|
70209
|
-
* @returns {Promise<Array<RawTransactionRest>>} A promise resolving to an array of {@link RawTransactionRest} objects.
|
|
70210
|
-
*/
|
|
70211
|
-
async getUtxos(addressOrScripthash) {
|
|
70212
|
-
return await this.api({ path: `/address/${addressOrScripthash}/utxo` });
|
|
70213
|
-
}
|
|
70214
|
-
};
|
|
70215
70093
|
|
|
70216
70094
|
// ../bitcoin/dist/esm/client/rest/block.js
|
|
70217
70095
|
init_shim();
|
|
70218
70096
|
|
|
70219
70097
|
// ../bitcoin/dist/esm/errors.js
|
|
70220
70098
|
init_shim();
|
|
70221
|
-
var BitcoinRpcError = class extends Error {
|
|
70222
|
-
type;
|
|
70223
|
-
code;
|
|
70224
|
-
data;
|
|
70225
|
-
constructor(type, code8, message2, data) {
|
|
70226
|
-
super(message2);
|
|
70227
|
-
this.type = type;
|
|
70228
|
-
this.code = code8;
|
|
70229
|
-
this.data = data;
|
|
70230
|
-
this.name = "BitcoinRpcError";
|
|
70231
|
-
}
|
|
70232
|
-
};
|
|
70233
|
-
var BitcoinRestError = class extends Error {
|
|
70234
|
-
data;
|
|
70235
|
-
constructor(message2, data) {
|
|
70236
|
-
super(message2);
|
|
70237
|
-
this.data = data;
|
|
70238
|
-
this.name = "BitcoinRestError";
|
|
70239
|
-
}
|
|
70240
|
-
};
|
|
70241
|
-
|
|
70242
|
-
// ../bitcoin/dist/esm/client/rest/block.js
|
|
70243
|
-
var BitcoinBlock = class {
|
|
70244
|
-
api;
|
|
70245
|
-
constructor(api) {
|
|
70246
|
-
this.api = api;
|
|
70247
|
-
}
|
|
70248
|
-
/**
|
|
70249
|
-
* Returns the blockheight of the most-work fully-validated chain. The genesis block has height 0.
|
|
70250
|
-
* @returns {Blockheight} The number of the blockheight with the most-work of the fully-validated chain.
|
|
70251
|
-
*/
|
|
70252
|
-
async count() {
|
|
70253
|
-
return await this.api({ path: "/blocks/tip/height" });
|
|
70254
|
-
}
|
|
70255
|
-
/**
|
|
70256
|
-
* Returns the block data associated with a `blockhash` of a valid block.
|
|
70257
|
-
* @param {GetBlockParams} params See {@link GetBlockParams} for details.
|
|
70258
|
-
* @param {?string} params.blockhash The blockhash of the block to query.
|
|
70259
|
-
* @param {?number} params.height The block height of the block to query.
|
|
70260
|
-
* @returns {BlockResponse} A promise resolving to a {@link BlockResponse} formatted depending on `verbosity` level.
|
|
70261
|
-
* @throws {BitcoinRpcError} If neither `blockhash` nor `height` is provided.
|
|
70262
|
-
*/
|
|
70263
|
-
async get({ blockhash, height }) {
|
|
70264
|
-
if (!blockhash && height === void 0) {
|
|
70265
|
-
throw new BitcoinRestError("INVALID_PARAMS_GET_BLOCK: blockhash or height required", { blockhash, height });
|
|
70266
|
-
}
|
|
70267
|
-
blockhash ??= await this.getHash(height);
|
|
70268
|
-
if (!blockhash || typeof blockhash !== "string") {
|
|
70269
|
-
return void 0;
|
|
70270
|
-
}
|
|
70271
|
-
return await this.api({ path: `/block/${blockhash}` });
|
|
70272
|
-
}
|
|
70273
|
-
/**
|
|
70274
|
-
* Get the block hash for a given block height.
|
|
70275
|
-
* See {@link https://github.com/blockstream/esplora/blob/master/API.md#get-block-heightheight | Esplora GET /block-height/:height } for details.
|
|
70276
|
-
* @param {number} height The block height (required).
|
|
70277
|
-
* @returns {Promise<string>} The hash of the block currently at height..
|
|
70278
|
-
*/
|
|
70279
|
-
async getHash(height) {
|
|
70280
|
-
return await this.api({ path: `/block-height/${height}` });
|
|
70281
|
-
}
|
|
70282
|
-
};
|
|
70283
70099
|
|
|
70284
70100
|
// ../bitcoin/dist/esm/client/rest/transaction.js
|
|
70285
70101
|
init_shim();
|
|
70286
|
-
var BitcoinTransaction = class {
|
|
70287
|
-
api;
|
|
70288
|
-
constructor(api) {
|
|
70289
|
-
this.api = api;
|
|
70290
|
-
}
|
|
70291
|
-
/**
|
|
70292
|
-
* Returns the transaction in JSON format.
|
|
70293
|
-
* See {@link https://github.com/blockstream/esplora/blob/master/API.md#get-txtxid | Esplora GET /tx/:txid } for details.
|
|
70294
|
-
* @param {string} txid The transaction id (required).
|
|
70295
|
-
* @returns {GetRawTransaction} A promise resolving to data about a transaction in the form specified by verbosity.
|
|
70296
|
-
*/
|
|
70297
|
-
async get(txid) {
|
|
70298
|
-
return await this.api({ path: `/tx/${txid}` });
|
|
70299
|
-
}
|
|
70300
|
-
/**
|
|
70301
|
-
* Returns the transaction in JSON format.
|
|
70302
|
-
* See {@link https://github.com/blockstream/esplora/blob/master/API.md#get-txtxid | Esplora GET /tx/:txid } for details.
|
|
70303
|
-
* @param {string} txid The transaction id (required).
|
|
70304
|
-
* @returns {GetRawTransaction} A promise resolving to data about a transaction in the form specified by verbosity.
|
|
70305
|
-
*/
|
|
70306
|
-
async isConfirmed(txid) {
|
|
70307
|
-
const tx = await this.get(txid);
|
|
70308
|
-
return tx.status.confirmed;
|
|
70309
|
-
}
|
|
70310
|
-
/**
|
|
70311
|
-
* Returns the raw transaction in hex or as binary data.
|
|
70312
|
-
* See {@link https://github.com/blockstream/esplora/blob/master/API.md#get-txtxidhex | Esplora GET /tx/:txid/hex } and
|
|
70313
|
-
* {@link https://github.com/blockstream/esplora/blob/master/API.md#get-txtxidraw | Esplora GET /tx/:txid/raw } for details.
|
|
70314
|
-
* @param {string} txid The transaction id (required).
|
|
70315
|
-
* @returns {Promise<RawTransactionRest | string>} A promise resolving to the raw transaction in the specified format.
|
|
70316
|
-
*/
|
|
70317
|
-
async getHex(txid) {
|
|
70318
|
-
return await this.api({ path: `/tx/${txid}/hex` });
|
|
70319
|
-
}
|
|
70320
|
-
/**
|
|
70321
|
-
* Returns the raw transaction in hex or as binary data.
|
|
70322
|
-
* See {@link https://github.com/blockstream/esplora/blob/master/API.md#get-txtxidhex | Esplora GET /tx/:txid/hex } and
|
|
70323
|
-
* {@link https://github.com/blockstream/esplora/blob/master/API.md#get-txtxidraw | Esplora GET /tx/:txid/raw } for details.
|
|
70324
|
-
* @param {string} txid The transaction id (required).
|
|
70325
|
-
* @returns {Promise<RawTransactionRest | string>} A promise resolving to the raw transaction in the specified format.
|
|
70326
|
-
*/
|
|
70327
|
-
async getRaw(txid) {
|
|
70328
|
-
return await this.api({ path: `/tx/${txid}/raw` });
|
|
70329
|
-
}
|
|
70330
|
-
/**
|
|
70331
|
-
* Broadcast a raw transaction to the network. The transaction should be provided as hex in the request body. The txid
|
|
70332
|
-
* will be returned on success.
|
|
70333
|
-
* See {@link https://github.com/blockstream/esplora/blob/master/API.md#post-tx | Esplora POST /tx } for details.
|
|
70334
|
-
* @param {string} tx The raw transaction in hex format (required).
|
|
70335
|
-
* @returns {Promise<string>} The transaction id of the broadcasted transaction.
|
|
70336
|
-
*/
|
|
70337
|
-
async send(tx) {
|
|
70338
|
-
return await this.api({ path: "/tx", method: "POST", body: tx, headers: { "Content-Type": "text/plain" } });
|
|
70339
|
-
}
|
|
70340
|
-
};
|
|
70341
70102
|
|
|
70342
|
-
// ../bitcoin/dist/esm/
|
|
70103
|
+
// ../bitcoin/dist/esm/client/rest/protocol.js
|
|
70343
70104
|
init_shim();
|
|
70344
|
-
var RestClientConfig = class {
|
|
70345
|
-
host;
|
|
70346
|
-
headers;
|
|
70347
|
-
constructor({ host, headers }) {
|
|
70348
|
-
this.host = host;
|
|
70349
|
-
this.headers = headers;
|
|
70350
|
-
}
|
|
70351
|
-
};
|
|
70352
|
-
var BitcoinRpcClientConfig = class {
|
|
70353
|
-
network;
|
|
70354
|
-
headers;
|
|
70355
|
-
host;
|
|
70356
|
-
logger;
|
|
70357
|
-
password;
|
|
70358
|
-
timeout;
|
|
70359
|
-
username;
|
|
70360
|
-
version;
|
|
70361
|
-
wallet;
|
|
70362
|
-
allowDefaultWallet;
|
|
70363
|
-
constructor(options2 = {
|
|
70364
|
-
headers: {},
|
|
70365
|
-
host: "http://localhost",
|
|
70366
|
-
logger: console,
|
|
70367
|
-
password: "",
|
|
70368
|
-
timeout: 3e4,
|
|
70369
|
-
username: "",
|
|
70370
|
-
version: "0.21.1",
|
|
70371
|
-
wallet: "",
|
|
70372
|
-
allowDefaultWallet: false
|
|
70373
|
-
}) {
|
|
70374
|
-
this.headers = options2.headers;
|
|
70375
|
-
this.host = options2.host;
|
|
70376
|
-
this.logger = options2.logger;
|
|
70377
|
-
this.password = options2.password;
|
|
70378
|
-
this.timeout = options2.timeout;
|
|
70379
|
-
this.username = options2.username;
|
|
70380
|
-
this.version = options2.version;
|
|
70381
|
-
this.wallet = options2.wallet;
|
|
70382
|
-
this.allowDefaultWallet = options2.allowDefaultWallet;
|
|
70383
|
-
}
|
|
70384
|
-
};
|
|
70385
|
-
var VerbosityLevel;
|
|
70386
|
-
(function(VerbosityLevel2) {
|
|
70387
|
-
VerbosityLevel2[VerbosityLevel2["hex"] = 0] = "hex";
|
|
70388
|
-
VerbosityLevel2[VerbosityLevel2["json"] = 1] = "json";
|
|
70389
|
-
VerbosityLevel2[VerbosityLevel2["jsonext"] = 2] = "jsonext";
|
|
70390
|
-
VerbosityLevel2[VerbosityLevel2["jsonextprev"] = 3] = "jsonextprev";
|
|
70391
|
-
})(VerbosityLevel || (VerbosityLevel = {}));
|
|
70392
70105
|
|
|
70393
|
-
// ../bitcoin/dist/esm/client/
|
|
70394
|
-
|
|
70395
|
-
/**
|
|
70396
|
-
* The encapsulated {@link RestClientConfig} object.
|
|
70397
|
-
* @private
|
|
70398
|
-
* @type {RestClientConfig}
|
|
70399
|
-
*/
|
|
70400
|
-
_config;
|
|
70401
|
-
/**
|
|
70402
|
-
* The api calls related to bitcoin transactions.
|
|
70403
|
-
* @type {BitcoinTransaction}
|
|
70404
|
-
*/
|
|
70405
|
-
transaction;
|
|
70406
|
-
/**
|
|
70407
|
-
* The api calls related to bitcoin blocks.
|
|
70408
|
-
* @type {BitcoinBlock}
|
|
70409
|
-
*/
|
|
70410
|
-
block;
|
|
70411
|
-
/**
|
|
70412
|
-
* The api calls related to bitcoin addresses.
|
|
70413
|
-
* @type {BitcoinAddress}
|
|
70414
|
-
*/
|
|
70415
|
-
address;
|
|
70416
|
-
/**
|
|
70417
|
-
* The API call method that can be used to make requests to the REST API.
|
|
70418
|
-
* @returns {Promise<any>} A promise resolving to the response data.
|
|
70419
|
-
*/
|
|
70420
|
-
api = this.call;
|
|
70421
|
-
constructor(config) {
|
|
70422
|
-
this._config = new RestClientConfig(config);
|
|
70423
|
-
this.api = this.call.bind(this);
|
|
70424
|
-
this.transaction = new BitcoinTransaction(this.api);
|
|
70425
|
-
this.block = new BitcoinBlock(this.api);
|
|
70426
|
-
this.address = new BitcoinAddress(this.api);
|
|
70427
|
-
}
|
|
70428
|
-
/**
|
|
70429
|
-
* Get the configuration object.
|
|
70430
|
-
* @private
|
|
70431
|
-
*/
|
|
70432
|
-
get config() {
|
|
70433
|
-
const config = this._config;
|
|
70434
|
-
return config;
|
|
70435
|
-
}
|
|
70436
|
-
/**
|
|
70437
|
-
* Static method connects to a bitcoin node running a esplora REST API.
|
|
70438
|
-
*
|
|
70439
|
-
* @param {RestClientConfig} config The configuration object for the client (optional).
|
|
70440
|
-
* @returns {BitcoinRestClient} A new {@link BitcoinRestClient} instance.
|
|
70441
|
-
* @example
|
|
70442
|
-
* ```
|
|
70443
|
-
* const rest = BitcoinRestClient.connect();
|
|
70444
|
-
* ```
|
|
70445
|
-
*/
|
|
70446
|
-
static connect(config) {
|
|
70447
|
-
return new _BitcoinRestClient(config ?? DEFAULT_BITCOIN_NETWORK_CONFIG.regtest.rest);
|
|
70448
|
-
}
|
|
70449
|
-
/**
|
|
70450
|
-
* Make a REST API call to the configured Bitcoin node.
|
|
70451
|
-
* @private
|
|
70452
|
-
* @param {RestApiCallParams} params The parameters for the API call. See {@link RestApiCallParams} for details.
|
|
70453
|
-
* @param {string} [params.path] The path to the API endpoint (required).
|
|
70454
|
-
* @param {string} [params.url] The full URL to the API endpoint (optional).
|
|
70455
|
-
* @param {string} [params.method] The HTTP method to use (default is 'GET').
|
|
70456
|
-
* @param {any} [params.body] The body of the request (optional).
|
|
70457
|
-
* @param {any} [params.headers] Additional headers to include in the request (optional).
|
|
70458
|
-
* @returns {Promise<any>} A promise resolving to the response data.
|
|
70459
|
-
*/
|
|
70460
|
-
async call({ path, url, method, body, headers }) {
|
|
70461
|
-
url ??= `${StringUtils.replaceEnd(this.config.host, "/")}${path}`;
|
|
70462
|
-
method ??= "GET";
|
|
70463
|
-
const requestInit = {
|
|
70464
|
-
method,
|
|
70465
|
-
headers: headers ?? {
|
|
70466
|
-
"Content-Type": "application/json",
|
|
70467
|
-
...this.config.headers
|
|
70468
|
-
}
|
|
70469
|
-
};
|
|
70470
|
-
if (body) {
|
|
70471
|
-
requestInit.body = JSONUtils.isObject(body) ? JSON.stringify(body) : body;
|
|
70472
|
-
requestInit.method = "POST";
|
|
70473
|
-
}
|
|
70474
|
-
const response2 = await fetch(url, requestInit);
|
|
70475
|
-
const data = (response2.headers.get("Content-Type") ?? "json") === "text/plain" ? await response2.text() : await response2.json();
|
|
70476
|
-
if (!response2.ok) {
|
|
70477
|
-
throw new MethodError(`Request to ${url} failed: ${response2.status} - ${response2.statusText}`, "FAILED_HTTP_REQUEST", { data, response: response2 });
|
|
70478
|
-
}
|
|
70479
|
-
return data;
|
|
70480
|
-
}
|
|
70481
|
-
};
|
|
70106
|
+
// ../bitcoin/dist/esm/client/http.js
|
|
70107
|
+
init_shim();
|
|
70482
70108
|
|
|
70483
70109
|
// ../bitcoin/dist/esm/client/rpc/index.js
|
|
70484
70110
|
init_shim();
|
|
@@ -70488,506 +70114,9 @@ init_shim();
|
|
|
70488
70114
|
|
|
70489
70115
|
// ../bitcoin/dist/esm/client/utils.js
|
|
70490
70116
|
init_shim();
|
|
70491
|
-
function toBase642(s2) {
|
|
70492
|
-
if (typeof import_buffer.Buffer !== "undefined")
|
|
70493
|
-
return import_buffer.Buffer.from(s2, "utf8").toString("base64");
|
|
70494
|
-
if (typeof btoa !== "undefined")
|
|
70495
|
-
return btoa(s2);
|
|
70496
|
-
throw new Error("No base64 encoder available");
|
|
70497
|
-
}
|
|
70498
|
-
async function safeText(res) {
|
|
70499
|
-
try {
|
|
70500
|
-
return await res.text();
|
|
70501
|
-
} catch {
|
|
70502
|
-
return "";
|
|
70503
|
-
}
|
|
70504
|
-
}
|
|
70505
70117
|
|
|
70506
|
-
// ../bitcoin/dist/esm/client/rpc/
|
|
70507
|
-
|
|
70508
|
-
url;
|
|
70509
|
-
authHeader;
|
|
70510
|
-
id = 0;
|
|
70511
|
-
constructor(cfg) {
|
|
70512
|
-
this.url = (cfg.host || "http://127.0.0.1:8332").replace(/\/+$/, "");
|
|
70513
|
-
if (cfg.username && cfg.password) {
|
|
70514
|
-
this.authHeader = `Basic ${toBase642(`${cfg.username}:${cfg.password}`)}`;
|
|
70515
|
-
} else {
|
|
70516
|
-
try {
|
|
70517
|
-
const u = new URL(this.url);
|
|
70518
|
-
if (u.username || u.password) {
|
|
70519
|
-
this.authHeader = `Basic ${toBase642(`${decodeURIComponent(u.username)}:${decodeURIComponent(u.password)}`)}`;
|
|
70520
|
-
u.username = "";
|
|
70521
|
-
u.password = "";
|
|
70522
|
-
this.url = u.toString().replace(/\/+$/, "");
|
|
70523
|
-
}
|
|
70524
|
-
} catch (error) {
|
|
70525
|
-
console.error(`Invalid URL in Bitcoin RPC config: ${this.url}`, error);
|
|
70526
|
-
}
|
|
70527
|
-
}
|
|
70528
|
-
}
|
|
70529
|
-
/**
|
|
70530
|
-
* Make a JSON-RPC call or batch of calls to the Bitcoin node.
|
|
70531
|
-
* @param {BatchOption[] | { method: string; parameters?: any[] }} batch A single RPC call or an array of calls to be made.
|
|
70532
|
-
* @returns {Promise<any[] | any>} The result of the RPC call(s).
|
|
70533
|
-
* @example
|
|
70534
|
-
*/
|
|
70535
|
-
async command(batch) {
|
|
70536
|
-
if (Array.isArray(batch)) {
|
|
70537
|
-
const out = [];
|
|
70538
|
-
for (const item of batch) {
|
|
70539
|
-
out.push(await this.call(item.method, item.parameters ?? []));
|
|
70540
|
-
}
|
|
70541
|
-
return out;
|
|
70542
|
-
} else {
|
|
70543
|
-
return this.call(batch.method, batch.parameters ?? []);
|
|
70544
|
-
}
|
|
70545
|
-
}
|
|
70546
|
-
/**
|
|
70547
|
-
* Internal method to perform the actual JSON-RPC call.
|
|
70548
|
-
* @param {string} method The RPC method to call.
|
|
70549
|
-
* @param {any[]} params The parameters for the RPC method.
|
|
70550
|
-
* @returns {Promise<any>} The result of the RPC call.
|
|
70551
|
-
*/
|
|
70552
|
-
async call(method, params) {
|
|
70553
|
-
const body = { jsonrpc: "2.0", id: ++this.id, method, params };
|
|
70554
|
-
const res = await fetch(this.url, {
|
|
70555
|
-
method: "POST",
|
|
70556
|
-
headers: {
|
|
70557
|
-
"Content-Type": "application/json",
|
|
70558
|
-
...this.authHeader ? { Authorization: this.authHeader } : {}
|
|
70559
|
-
},
|
|
70560
|
-
body: JSON.stringify(body)
|
|
70561
|
-
});
|
|
70562
|
-
if (!res.ok) {
|
|
70563
|
-
const text = await safeText(res);
|
|
70564
|
-
const err2 = new Error(text || `${res.status} ${res.statusText}`);
|
|
70565
|
-
err2.code = res.status;
|
|
70566
|
-
err2.rpc = true;
|
|
70567
|
-
throw err2;
|
|
70568
|
-
}
|
|
70569
|
-
const payload = await res.json();
|
|
70570
|
-
if (payload.error) {
|
|
70571
|
-
const err2 = new Error(payload.error.message);
|
|
70572
|
-
err2.code = payload.error.code;
|
|
70573
|
-
err2.rpc = true;
|
|
70574
|
-
throw err2;
|
|
70575
|
-
}
|
|
70576
|
-
return payload.result;
|
|
70577
|
-
}
|
|
70578
|
-
};
|
|
70579
|
-
|
|
70580
|
-
// ../bitcoin/dist/esm/client/rpc/index.js
|
|
70581
|
-
var BitcoinCoreRpcClient = class _BitcoinCoreRpcClient {
|
|
70582
|
-
/**
|
|
70583
|
-
* The singleton instance of the BitcoinCoreRpcClient.
|
|
70584
|
-
* @type {BitcoinCoreRpcClient}
|
|
70585
|
-
* @private
|
|
70586
|
-
*/
|
|
70587
|
-
static #instance;
|
|
70588
|
-
/**
|
|
70589
|
-
* The JSON-RPC transport layer.
|
|
70590
|
-
* @type {JsonRpcTransport}
|
|
70591
|
-
* @private
|
|
70592
|
-
*/
|
|
70593
|
-
#transport;
|
|
70594
|
-
/**
|
|
70595
|
-
* The configuration for the RPC client.
|
|
70596
|
-
* @type {RpcClientConfig}
|
|
70597
|
-
* @private
|
|
70598
|
-
*/
|
|
70599
|
-
#config;
|
|
70600
|
-
/**
|
|
70601
|
-
* Constructs a new {@link BitcoinCoreRpcClient} instance from a new {@link RpcClient | RpcClient}.
|
|
70602
|
-
* @param {RpcClientConfig} config The bitcoin-core client instance.
|
|
70603
|
-
* @example
|
|
70604
|
-
* ```
|
|
70605
|
-
* import BitcoinRpcClient from '@did-btcr2/method';
|
|
70606
|
-
* const bob = BitcoinRpcClient.connect(); // To use default polar config, pass no args. Polar must run locally.
|
|
70607
|
-
* ```
|
|
70608
|
-
*/
|
|
70609
|
-
constructor(config) {
|
|
70610
|
-
this.#config = new BitcoinRpcClientConfig(config);
|
|
70611
|
-
this.#transport = new JsonRpcTransport(this.#config);
|
|
70612
|
-
}
|
|
70613
|
-
/**
|
|
70614
|
-
* Get the config for the current BitcoinRpcClient object.
|
|
70615
|
-
* @returns {BitcoinRpcClient} The encapsulated {@link BitcoinRpcClient} object.
|
|
70616
|
-
* @example
|
|
70617
|
-
* ```
|
|
70618
|
-
* import BitcoinRpcClient from '@did-btcr2/method';
|
|
70619
|
-
* const alice = BitcoinRpcClient.connect();
|
|
70620
|
-
* const config = alice.config;
|
|
70621
|
-
* ```
|
|
70622
|
-
*/
|
|
70623
|
-
get config() {
|
|
70624
|
-
const config = this.#config;
|
|
70625
|
-
return config;
|
|
70626
|
-
}
|
|
70627
|
-
/**
|
|
70628
|
-
* Get the client for the current BitcoinRpcClient object.
|
|
70629
|
-
* @returns {RpcClient} The encapsulated {@link RpcClient} object.
|
|
70630
|
-
* @example
|
|
70631
|
-
* ```
|
|
70632
|
-
* const alice = BitcoinRpcClient.connect();
|
|
70633
|
-
* const config = alice.client;
|
|
70634
|
-
* ```
|
|
70635
|
-
*/
|
|
70636
|
-
get client() {
|
|
70637
|
-
const client = this.#transport;
|
|
70638
|
-
return client;
|
|
70639
|
-
}
|
|
70640
|
-
/**
|
|
70641
|
-
* Static method initializes a static instance of BitcoinCoreRpcClient with the given configuration.
|
|
70642
|
-
* The RpcClient returned by this method does not have any named methods.
|
|
70643
|
-
* Use this method to create and pass a new RpcClient instance to a BitcoinCoreRpcClient constructor.
|
|
70644
|
-
*
|
|
70645
|
-
* @param {RpcClientConfig} config The configuration object for the client (optional).
|
|
70646
|
-
* @returns {BitcoinCoreRpcClient} A new RpcClient instance.
|
|
70647
|
-
* @example
|
|
70648
|
-
* ```
|
|
70649
|
-
* const options: RpcClientConfig = {
|
|
70650
|
-
* host: 'http://localhost:18443',
|
|
70651
|
-
* username: 'alice',
|
|
70652
|
-
* password: 'alicepass',
|
|
70653
|
-
* version: '28.1.0',
|
|
70654
|
-
* }
|
|
70655
|
-
* const alice = BitcoinCoreRpcClient.initialize(options); // Client config required
|
|
70656
|
-
* ```
|
|
70657
|
-
*/
|
|
70658
|
-
static initialize(config) {
|
|
70659
|
-
const cfg = new BitcoinRpcClientConfig(config);
|
|
70660
|
-
_BitcoinCoreRpcClient.#instance = new _BitcoinCoreRpcClient(cfg);
|
|
70661
|
-
return _BitcoinCoreRpcClient.#instance;
|
|
70662
|
-
}
|
|
70663
|
-
/**
|
|
70664
|
-
* Static method connects to a bitcoin node running the bitcoin core daemon (bitcoind).
|
|
70665
|
-
* To use default polar config, do not pass a config. See {@link DEFAULT_BITCOIN_NETWORK_CONFIG} for default config.
|
|
70666
|
-
* @required A locally running {@link https://github.com/jamaljsr/polar | Polar Lightning} regtest node.
|
|
70667
|
-
*
|
|
70668
|
-
* @param {?RpcClientConfig} config The configuration object for the client (optional).
|
|
70669
|
-
* @returns A new {@link BitcoinRpcClient} instance.
|
|
70670
|
-
* @example
|
|
70671
|
-
* ```
|
|
70672
|
-
* const alice = BitcoinRpcClient.connect();
|
|
70673
|
-
* ```
|
|
70674
|
-
*/
|
|
70675
|
-
static connect(config) {
|
|
70676
|
-
return new _BitcoinCoreRpcClient(config ?? DEFAULT_BITCOIN_NETWORK_CONFIG.regtest.rpc);
|
|
70677
|
-
}
|
|
70678
|
-
/**
|
|
70679
|
-
* Check if the given error is a JSON-RPC error.
|
|
70680
|
-
* @param {unknown} e The error to check.
|
|
70681
|
-
* @returns {boolean} True if the error is a JSON-RPC error, false otherwise.
|
|
70682
|
-
*/
|
|
70683
|
-
isJsonRpcError(e2) {
|
|
70684
|
-
return e2 instanceof Error && e2.name === "RpcError" && typeof e2.code === "number";
|
|
70685
|
-
}
|
|
70686
|
-
/**
|
|
70687
|
-
* Executes a JSON-RPC command on the bitcoind node.
|
|
70688
|
-
* @param {MethodNameInLowerCase} method The name of the method to call.
|
|
70689
|
-
* @param {Array<any>} parameters The parameters to pass to the method.
|
|
70690
|
-
* @returns {Promise<T>} A promise resolving to the result of the command.
|
|
70691
|
-
*/
|
|
70692
|
-
async executeRpc(method, parameters = []) {
|
|
70693
|
-
try {
|
|
70694
|
-
const raw = await this.client.command([{ method, parameters }]);
|
|
70695
|
-
const normalized = JSONUtils.isUnprototyped(raw) ? JSONUtils.normalize(raw) : raw;
|
|
70696
|
-
const result = Array.isArray(normalized) ? normalized[normalized.length - 1] : normalized;
|
|
70697
|
-
return result;
|
|
70698
|
-
} catch (err2) {
|
|
70699
|
-
this.handleError(err2, method, parameters);
|
|
70700
|
-
}
|
|
70701
|
-
}
|
|
70702
|
-
/**
|
|
70703
|
-
*
|
|
70704
|
-
* Map JSON-RPC error codes to HTTP status codes.
|
|
70705
|
-
* @param {number | undefined} code The JSON-RPC error code.
|
|
70706
|
-
* @returns {number} The corresponding HTTP status code.
|
|
70707
|
-
*
|
|
70708
|
-
* | Error type | HTTP code |
|
|
70709
|
-
* | -------------------------------| --------------------|
|
|
70710
|
-
* | Valid JSON-RPC failure | **400 / 404 / 422** |
|
|
70711
|
-
* | JSON-RPC authentication issues | **401 / 403** |
|
|
70712
|
-
* | Upstream bitcoind unreachable | **502** |
|
|
70713
|
-
* | Upstream timeout | **504** |
|
|
70714
|
-
* | Network transient errors | **503** |
|
|
70715
|
-
* | Unknown unexpected errors | **500** |
|
|
70716
|
-
*/
|
|
70717
|
-
mapRpcCodeToHttp(code8) {
|
|
70718
|
-
switch (code8) {
|
|
70719
|
-
case -32700:
|
|
70720
|
-
case -32600:
|
|
70721
|
-
case -32602:
|
|
70722
|
-
return 400;
|
|
70723
|
-
case -32601:
|
|
70724
|
-
return 404;
|
|
70725
|
-
default:
|
|
70726
|
-
return 422;
|
|
70727
|
-
}
|
|
70728
|
-
}
|
|
70729
|
-
/**
|
|
70730
|
-
* Handle errors that occur while executing commands.
|
|
70731
|
-
* @param methods An array of {@link BatchOption} objects.
|
|
70732
|
-
* @param error The error that was thrown.
|
|
70733
|
-
* @throws Throws a {@link BitcoinRpcError} with the error message.
|
|
70734
|
-
*/
|
|
70735
|
-
handleError(err2, method, params) {
|
|
70736
|
-
if (this.isJsonRpcError(err2)) {
|
|
70737
|
-
throw new BitcoinRpcError(err2.name.toUpperCase(), this.mapRpcCodeToHttp(err2.code), `RPC ${method} failed: ${err2.message}`, { method, params });
|
|
70738
|
-
}
|
|
70739
|
-
throw new BitcoinRpcError("UNKNOWN_ERROR", 500, `Unknown failure in ${method}`, { method, params, err: err2 });
|
|
70740
|
-
}
|
|
70741
|
-
/**
|
|
70742
|
-
* Returns the block data associated with a `blockhash` of a valid block.
|
|
70743
|
-
* @param {GetBlockParams} params See {@link GetBlockParams} for details.
|
|
70744
|
-
* @param {?string} params.blockhash The blockhash of the block to query.
|
|
70745
|
-
* @param {?number} params.height The block height of the block to query.
|
|
70746
|
-
* @param {?VerbosityLevel} params.verbosity The verbosity level. See {@link VerbosityLevel}.
|
|
70747
|
-
* @returns {BlockResponse} A promise resolving to a {@link BlockResponse} formatted depending on `verbosity` level.
|
|
70748
|
-
* @throws {BitcoinRpcError} If neither `blockhash` nor `height` is provided.
|
|
70749
|
-
*/
|
|
70750
|
-
async getBlock({ blockhash, height, verbosity }) {
|
|
70751
|
-
if (!blockhash && height === void 0) {
|
|
70752
|
-
throw new BitcoinRpcError("INVALID_PARAMS_GET_BLOCK", 400, "blockhash or height required", { blockhash, height });
|
|
70753
|
-
}
|
|
70754
|
-
blockhash ??= await this.getBlockHash(height);
|
|
70755
|
-
if (!blockhash || typeof blockhash !== "string") {
|
|
70756
|
-
return void 0;
|
|
70757
|
-
}
|
|
70758
|
-
const block = await this.executeRpc("getblock", [blockhash, verbosity ?? 3]);
|
|
70759
|
-
switch (verbosity) {
|
|
70760
|
-
case 0:
|
|
70761
|
-
return block;
|
|
70762
|
-
case 1:
|
|
70763
|
-
return block;
|
|
70764
|
-
case 2:
|
|
70765
|
-
return block;
|
|
70766
|
-
case 3:
|
|
70767
|
-
return block;
|
|
70768
|
-
default:
|
|
70769
|
-
return block;
|
|
70770
|
-
}
|
|
70771
|
-
}
|
|
70772
|
-
/**
|
|
70773
|
-
* Returns the blockheight of the most-work fully-validated chain. The genesis block has height 0.
|
|
70774
|
-
* @returns {Blockheight} The number of the blockheight with the most-work of the fully-validated chain.
|
|
70775
|
-
*/
|
|
70776
|
-
async getBlockCount() {
|
|
70777
|
-
return await this.executeRpc("getblockcount");
|
|
70778
|
-
}
|
|
70779
|
-
/**
|
|
70780
|
-
* Returns the blockhash of the block at the given height in the active chain.
|
|
70781
|
-
*/
|
|
70782
|
-
async getBlockHash(height) {
|
|
70783
|
-
return await this.executeRpc("getblockhash", [height]);
|
|
70784
|
-
}
|
|
70785
|
-
/**
|
|
70786
|
-
* Returns an object containing various blockchain state info.
|
|
70787
|
-
*/
|
|
70788
|
-
async getBlockchainInfo() {
|
|
70789
|
-
return this.executeRpc("getblockchaininfo");
|
|
70790
|
-
}
|
|
70791
|
-
/**
|
|
70792
|
-
* Sign inputs for raw transaction (serialized, hex-encoded).
|
|
70793
|
-
* The second optional argument (may be null) is an array of previous transaction outputs that
|
|
70794
|
-
* this transaction depends on but may not yet be in the block chain.
|
|
70795
|
-
* Requires wallet passphrase to be set with walletpassphrase call if wallet is encrypted.
|
|
70796
|
-
* @param {string} hexstring The hex-encoded transaction to send.
|
|
70797
|
-
*/
|
|
70798
|
-
async signRawTransaction(hexstring) {
|
|
70799
|
-
return await this.executeRpc("signrawtransactionwithwallet", [hexstring]);
|
|
70800
|
-
}
|
|
70801
|
-
/**
|
|
70802
|
-
* Submit a raw transaction (serialized, hex-encoded) to local node and network.
|
|
70803
|
-
*
|
|
70804
|
-
* The transaction will be sent unconditionally to all peers, so using sendrawtransaction
|
|
70805
|
-
* for manual rebroadcast may degrade privacy by leaking the transaction's origin, as
|
|
70806
|
-
* nodes will normally not rebroadcast non-wallet transactions already in their mempool.
|
|
70807
|
-
*
|
|
70808
|
-
* @param {string} hexstring The hex-encoded transaction to send.
|
|
70809
|
-
* @param {numbner} [maxfeerate] If not passed, default is 0.10.
|
|
70810
|
-
* @returns {Promise<string>} A promise resolving to the transaction hash in hex.
|
|
70811
|
-
*/
|
|
70812
|
-
async sendRawTransaction(hexstring, maxfeerate, maxBurnAmount) {
|
|
70813
|
-
return await this.executeRpc("sendrawtransaction", [hexstring, maxfeerate ?? 0.1, maxBurnAmount ?? 0]);
|
|
70814
|
-
}
|
|
70815
|
-
/**
|
|
70816
|
-
* Combines calls to `signRawTransaction` and `sendRawTransaction`.
|
|
70817
|
-
* @param {string} params.hexstring The hex-encoded transaction to send.
|
|
70818
|
-
* @returns {Promise<string>} A promise resolving to the transaction hash in hex.
|
|
70819
|
-
*/
|
|
70820
|
-
async signAndSendRawTransaction(hexstring) {
|
|
70821
|
-
const signedRawTx = await this.signRawTransaction(hexstring);
|
|
70822
|
-
return await this.sendRawTransaction(signedRawTx.hex);
|
|
70823
|
-
}
|
|
70824
|
-
/**
|
|
70825
|
-
* Combines calls to `createRawTransaction`, `signRawTransaction` and `sendRawTransaction`.
|
|
70826
|
-
* @param {CreateRawTxInputs[]} inputs The inputs to the transaction (required).
|
|
70827
|
-
* @param {CreateRawTxOutputs[]} outputs The outputs of the transaction (required).
|
|
70828
|
-
* @returns {Promise<string>} A promise resolving to the transaction hash in hex.
|
|
70829
|
-
*/
|
|
70830
|
-
async createSignSendRawTransaction(inputs2, outputs2) {
|
|
70831
|
-
const rawTx = await this.createRawTransaction(inputs2, outputs2);
|
|
70832
|
-
const signedRawTx = await this.signRawTransaction(rawTx);
|
|
70833
|
-
const sentRawTx = await this.sendRawTransaction(signedRawTx.hex);
|
|
70834
|
-
return sentRawTx;
|
|
70835
|
-
}
|
|
70836
|
-
/**
|
|
70837
|
-
* Returns up to 'count' most recent transactions skipping the first 'from' transactions for account 'label'.
|
|
70838
|
-
* @param {ListTransactionsParams} params The parameters for the listTransactions command.
|
|
70839
|
-
* @returns {Promise<ListTransactionsResult>} A promise resolving to a {@link ListTransactionsResult} object.
|
|
70840
|
-
*/
|
|
70841
|
-
async listTransactions(params) {
|
|
70842
|
-
return await this.executeRpc("listtransactions", [params]);
|
|
70843
|
-
}
|
|
70844
|
-
/**
|
|
70845
|
-
* Create a transaction spending the given inputs and creating new outputs.
|
|
70846
|
-
* Outputs can be addresses or data.
|
|
70847
|
-
* Returns hex-encoded raw transaction.
|
|
70848
|
-
* Note that the transaction's inputs are not signed, and
|
|
70849
|
-
* it is not stored in the wallet or transmitted to the network.
|
|
70850
|
-
* @param {TxInForCreateRaw[]} inputs The inputs to the transaction (required).
|
|
70851
|
-
* @param {CreateRawTxOutputs[]} outputs The outputs of the transaction (required).
|
|
70852
|
-
* @param {number} [locktime] The locktime of the transaction (optional).
|
|
70853
|
-
* @param {boolean} [replacable] Whether the transaction is replaceable (optional).
|
|
70854
|
-
* @returns {string} The hex-encoded raw transaction.
|
|
70855
|
-
*/
|
|
70856
|
-
async createRawTransaction(inputs2, outputs2, locktime, replacable) {
|
|
70857
|
-
return await this.executeRpc("createrawtransaction", [inputs2, outputs2, locktime, replacable]);
|
|
70858
|
-
}
|
|
70859
|
-
/**
|
|
70860
|
-
* Derives one or more addresses corresponding to an output descriptor.
|
|
70861
|
-
* Examples of output descriptors are:
|
|
70862
|
-
* pkh(<pubkey>) P2PKH outputs for the given pubkey
|
|
70863
|
-
* wpkh(<pubkey>) Native segwit P2PKH outputs for the given pubkey
|
|
70864
|
-
* sh(multi(<n>,<pubkey>,<pubkey>,...)) P2SH-multisig outputs for the given threshold and pubkeys
|
|
70865
|
-
* raw(<hex script>) Outputs whose output script equals the specified hex-encoded bytes
|
|
70866
|
-
* tr(<pubkey>,multi_a(<n>,<pubkey>,<pubkey>,...)) P2TR-multisig outputs for the given threshold and pubkeys
|
|
70867
|
-
*
|
|
70868
|
-
* In the above, <pubkey> either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv optionally followed by one
|
|
70869
|
-
* or more path elements separated by "/", where "h" represents a hardened child key.
|
|
70870
|
-
*
|
|
70871
|
-
* See {@link https://github.com/bitcoin/bitcoin/blob/master/doc/descriptors.md | github.com/bitcoin/bitcoin/descriptors.md}
|
|
70872
|
-
* for more information.
|
|
70873
|
-
* @param {string} descriptor The descriptor.
|
|
70874
|
-
* @param {Array<number>} range If descriptor is ranged, must specify end or [begin,end] to derive.
|
|
70875
|
-
* @returns {Array<DerivedAddresses>} a list of derived addresses
|
|
70876
|
-
* @example First three native segwit receive addresses
|
|
70877
|
-
* ```
|
|
70878
|
-
* const bitcoind = BitcoinRpcClient.connect()
|
|
70879
|
-
* const addresses = bitcoind.deriveAddresses("wpkh([d34db33f/84h/0h/0h]xpub6DJ2dN.../0/*)#cjjspncu", [0,2])
|
|
70880
|
-
* ```
|
|
70881
|
-
*/
|
|
70882
|
-
async deriveAddresses(descriptor, range5) {
|
|
70883
|
-
return await this.executeRpc("deriveaddresses", [descriptor, range5]);
|
|
70884
|
-
}
|
|
70885
|
-
/**
|
|
70886
|
-
* Returns the total available balance. The available balance is what the wallet
|
|
70887
|
-
* considers currently spendable, and is thus affected by options which limit
|
|
70888
|
-
* spendability such as -spendzeroconfchange.
|
|
70889
|
-
* @returns {Promise<number>} A promise resolving to the total available balance in BTC.
|
|
70890
|
-
*/
|
|
70891
|
-
async getBalance() {
|
|
70892
|
-
return await this.executeRpc("getbalance");
|
|
70893
|
-
}
|
|
70894
|
-
/**
|
|
70895
|
-
* Returns a new Bitcoin address for receiving payments. If 'label' is specified,
|
|
70896
|
-
* it is added to the address book so payments received with the address will be associated with 'label'.
|
|
70897
|
-
* The 'address_type' can be one of "legacy", "p2sh-segwit", "bech32", or "bech32m".
|
|
70898
|
-
* @param {string} addressType The address type to use (required, options=["legacy", "p2sh-segwit", "bech32", "bech32m"], default="bech32").
|
|
70899
|
-
* @param {string} [label] The label to associate with the new address (optional).
|
|
70900
|
-
* @returns {Promise<string>} A promise resolving to the new address.
|
|
70901
|
-
*/
|
|
70902
|
-
async getNewAddress(addressType, label) {
|
|
70903
|
-
return await this.executeRpc("getnewaddress", [label ?? "", addressType]);
|
|
70904
|
-
}
|
|
70905
|
-
/**
|
|
70906
|
-
* Returns array of unspent transaction outputs with between minconf and maxconf (inclusive) confirmations.
|
|
70907
|
-
* Optionally filter to only include txouts paid to specified addresses.
|
|
70908
|
-
* @param {Object} params The parameters for the listUnspent command.
|
|
70909
|
-
* @param {number} [params.minconf=0] The minimum number of confirmations an output must have to be included.
|
|
70910
|
-
* @param {number} [params.maxconf=9999999] The maximum number of confirmations an output can have to be included.
|
|
70911
|
-
* @param {string[]} [params.address] Only include outputs paid to these addresses.
|
|
70912
|
-
* @param {boolean} [params.include_unsafe=true] Whether to include outputs that are not safe to spend.
|
|
70913
|
-
* @returns {Promise<UnspentTxInfo[]>} A promise resolving to an array of {@link UnspentTxInfo} objects.
|
|
70914
|
-
*/
|
|
70915
|
-
async listUnspent(params) {
|
|
70916
|
-
const args = { minconf: 0, maxconf: 9999999, include_unsafe: true, ...params };
|
|
70917
|
-
return await this.executeRpc("listunspent", [args]);
|
|
70918
|
-
}
|
|
70919
|
-
/**
|
|
70920
|
-
* Send an amount to a given address.
|
|
70921
|
-
* @param {string} address The address to send to.
|
|
70922
|
-
* @param {number} amount The amount to send in BTC.
|
|
70923
|
-
* @returns {Promise<SendToAddressResult>} A promise resolving to the transaction id.
|
|
70924
|
-
*/
|
|
70925
|
-
async sendToAddress(address, amount) {
|
|
70926
|
-
const txid = await this.executeRpc("sendtoaddress", [address, amount]);
|
|
70927
|
-
return await this.getRawTransaction(txid);
|
|
70928
|
-
}
|
|
70929
|
-
/**
|
|
70930
|
-
* Sign a message with the private key of an address.
|
|
70931
|
-
* @param {string} address The address to sign the message with.
|
|
70932
|
-
* @param {string} message The message to sign.
|
|
70933
|
-
* @returns {Promise<string>} A promise resolving to the signature in base64.
|
|
70934
|
-
*/
|
|
70935
|
-
async signMessage(address, message2) {
|
|
70936
|
-
return await this.executeRpc("signmessage", [address, message2]);
|
|
70937
|
-
}
|
|
70938
|
-
/**
|
|
70939
|
-
* Verify a signed message.
|
|
70940
|
-
* @param {string} address The address to verify the message with.
|
|
70941
|
-
* @param {string} signature The signature to verify in base64.
|
|
70942
|
-
* @param {string} message The message to verify.
|
|
70943
|
-
* @returns {Promise<boolean>} A promise resolving to true if the signature is valid, false otherwise.
|
|
70944
|
-
*/
|
|
70945
|
-
async verifyMessage(address, signature2, message2) {
|
|
70946
|
-
return await this.executeRpc("verifymessage", [address, signature2, message2]);
|
|
70947
|
-
}
|
|
70948
|
-
/**
|
|
70949
|
-
* Get detailed information about in-wallet transaction <txid>.
|
|
70950
|
-
* @param txid: The transaction id. (string, required)
|
|
70951
|
-
* @param {boolean} include_watchonly Whether to include watch-only addresses in balance calculation and details.
|
|
70952
|
-
* @returns {WalletTransaction} A promise resolving to a {@link WalletTransaction} object.
|
|
70953
|
-
*/
|
|
70954
|
-
async getTransaction(txid, include_watchonly) {
|
|
70955
|
-
return await this.executeRpc("gettransaction", [txid, include_watchonly]);
|
|
70956
|
-
}
|
|
70957
|
-
/**
|
|
70958
|
-
* Get detailed information about a transaction.
|
|
70959
|
-
* By default, this call only returns a transaction if it is in the mempool. If -txindex is enabled
|
|
70960
|
-
* and no blockhash argument is passed, it will return the transaction if it is in the mempool or any block.
|
|
70961
|
-
* If a blockhash argument is passed, it will return the transaction if the specified block is available and
|
|
70962
|
-
* the transaction is in that block.
|
|
70963
|
-
* @param {string} txid The transaction id (required).
|
|
70964
|
-
* @param {?VerbosityLevel} verbosity Response format: 0 (hex), 1 (json) or 2 (jsonext).
|
|
70965
|
-
* @param {?string} blockhash The block in which to look for the transaction (optional).
|
|
70966
|
-
* @returns {GetRawTransaction} A promise resolving to data about a transaction in the form specified by verbosity.
|
|
70967
|
-
*/
|
|
70968
|
-
async getRawTransaction(txid, verbosity, blockhash) {
|
|
70969
|
-
const rawTransaction = await this.executeRpc("getrawtransaction", [txid, verbosity ?? 2, blockhash]);
|
|
70970
|
-
switch (verbosity) {
|
|
70971
|
-
case 0:
|
|
70972
|
-
return rawTransaction;
|
|
70973
|
-
case 1:
|
|
70974
|
-
return rawTransaction;
|
|
70975
|
-
case 2:
|
|
70976
|
-
return rawTransaction;
|
|
70977
|
-
default:
|
|
70978
|
-
return rawTransaction;
|
|
70979
|
-
}
|
|
70980
|
-
}
|
|
70981
|
-
/**
|
|
70982
|
-
* Get detailed information about multiple transactions. An extension of {@link getRawTransaction}.
|
|
70983
|
-
* @param {Array<string>} txids An array of transaction ids.
|
|
70984
|
-
* @param {?VerbosityLevel} verbosity Response format: 0 (hex), 1 (json) or 2 (jsonext).
|
|
70985
|
-
* @returns {Promise<Array<RawTransactionResponse>>}
|
|
70986
|
-
*/
|
|
70987
|
-
async getRawTransactions(txids, verbosity) {
|
|
70988
|
-
return await Promise.all(txids.map(async (txid) => await this.getRawTransaction(txid, verbosity ?? 2)));
|
|
70989
|
-
}
|
|
70990
|
-
};
|
|
70118
|
+
// ../bitcoin/dist/esm/client/rpc/protocol.js
|
|
70119
|
+
init_shim();
|
|
70991
70120
|
|
|
70992
70121
|
// ../bitcoin/dist/esm/network.js
|
|
70993
70122
|
init_shim();
|
|
@@ -71007,97 +70136,20 @@ function getNetwork(network) {
|
|
|
71007
70136
|
}
|
|
71008
70137
|
}
|
|
71009
70138
|
|
|
71010
|
-
// ../bitcoin/dist/esm/
|
|
71011
|
-
|
|
71012
|
-
|
|
71013
|
-
|
|
71014
|
-
testnet3;
|
|
71015
|
-
testnet4;
|
|
71016
|
-
signet;
|
|
71017
|
-
mutinynet;
|
|
71018
|
-
regtest;
|
|
71019
|
-
/**
|
|
71020
|
-
* Creates an instance of the Bitcoin class.
|
|
71021
|
-
* @param {BitcoinNetworkConfigMap} configs Optional configuration object for the Bitcoin client. If not provided, it will
|
|
71022
|
-
* be loaded from the BITCOIN_CLIENT_CONFIG environment variables.
|
|
71023
|
-
* @throws {MethodError} If no configs is passed and BITCOIN_NETWORK_CONFIG is missing or invalid.
|
|
71024
|
-
*/
|
|
71025
|
-
constructor(configs) {
|
|
71026
|
-
const BITCOIN_NETWORK_CONFIG = import_process.default.env.BITCOIN_NETWORK_CONFIG ?? JSON.stringify(configs ?? DEFAULT_BITCOIN_NETWORK_CONFIG);
|
|
71027
|
-
if (!BITCOIN_NETWORK_CONFIG) {
|
|
71028
|
-
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 });
|
|
71029
|
-
}
|
|
71030
|
-
if (!JSONUtils.isParsable(BITCOIN_NETWORK_CONFIG)) {
|
|
71031
|
-
throw new MethodError("Parsing failed: malformed BITCOIN_NETWORK_CONFIG", "MISSING_MALFORMED_BITCOIN_NETWORK_CONFIG", { BITCOIN_NETWORK_CONFIG });
|
|
71032
|
-
}
|
|
71033
|
-
const networkConfigs = JSON.parse(BITCOIN_NETWORK_CONFIG);
|
|
71034
|
-
const networks2 = ["bitcoin", "testnet3", "testnet4", "signet", "mutinynet", "regtest"];
|
|
71035
|
-
for (const network of networks2) {
|
|
71036
|
-
const networkConfig = configs?.[network] ?? networkConfigs[network];
|
|
71037
|
-
if (networkConfig) {
|
|
71038
|
-
this[network] = {
|
|
71039
|
-
name: network,
|
|
71040
|
-
config: networkConfig,
|
|
71041
|
-
rpc: new BitcoinCoreRpcClient(networkConfig.rpc),
|
|
71042
|
-
rest: new BitcoinRestClient(networkConfig.rest),
|
|
71043
|
-
data: getNetwork(network)
|
|
71044
|
-
};
|
|
71045
|
-
}
|
|
71046
|
-
}
|
|
71047
|
-
const ACTIVE_NETWORK = import_process.default.env.ACTIVE_NETWORK?.toLowerCase() ?? "regtest";
|
|
71048
|
-
if (!ACTIVE_NETWORK) {
|
|
71049
|
-
throw new MethodError("Missing ACTIVE_NETWORK environment variable", "MISSING_ACTIVE_NETWORK", { ACTIVE_NETWORK });
|
|
71050
|
-
}
|
|
71051
|
-
if (!this[ACTIVE_NETWORK]) {
|
|
71052
|
-
throw new MethodError(`No configuration found for ACTIVE_NETWORK='${ACTIVE_NETWORK}'`, "MISSING_CONFIG_FOR_NETWORK");
|
|
71053
|
-
}
|
|
71054
|
-
this.network = this[ACTIVE_NETWORK];
|
|
71055
|
-
}
|
|
71056
|
-
/**
|
|
71057
|
-
* Get the Bitcoin network configuration for a specific network.
|
|
71058
|
-
* @param {keyof AvailableNetworks} network - The Bitcoin network (e.g., 'bitcoin', 'testnet3', 'signet', 'regtest').
|
|
71059
|
-
* @returns {Bitcoin} The Bitcoin object.
|
|
71060
|
-
*/
|
|
71061
|
-
getNetworkConnection(network) {
|
|
71062
|
-
const availableNetwork = network;
|
|
71063
|
-
if (!this[availableNetwork]) {
|
|
71064
|
-
throw new MethodError(`No configuration found for network='${availableNetwork}'`, "MISSING_CONFIG_FOR_NETWORK");
|
|
71065
|
-
}
|
|
71066
|
-
return this;
|
|
71067
|
-
}
|
|
71068
|
-
/**
|
|
71069
|
-
* Sets the active Bitcoin network.
|
|
71070
|
-
* @param {keyof AvailableNetworks} active - The Bitcoin network to set as active (e.g., 'bitcoin', 'testnet3', 'signet', 'regtest').
|
|
71071
|
-
* @throws {MethodError} If no configuration is found for the specified network.
|
|
71072
|
-
*/
|
|
71073
|
-
setActiveNetwork(active) {
|
|
71074
|
-
const availableNetwork = active;
|
|
71075
|
-
if (!this[availableNetwork]) {
|
|
71076
|
-
throw new MethodError(`No configuration found for network='${availableNetwork}'`, "MISSING_CONFIG_FOR_NETWORK");
|
|
71077
|
-
}
|
|
71078
|
-
this.network = this[availableNetwork];
|
|
71079
|
-
}
|
|
71080
|
-
/**
|
|
71081
|
-
* Converts Bitcoin (BTC) to satoshis (SAT).
|
|
71082
|
-
* @param {number} btc - The amount in BTC.
|
|
71083
|
-
* @returns {number} The amount in SAT.
|
|
71084
|
-
*/
|
|
71085
|
-
static btcToSats(btc) {
|
|
71086
|
-
return Math.round(btc * 1e8);
|
|
71087
|
-
}
|
|
71088
|
-
/**
|
|
71089
|
-
* Converts satoshis (SAT) to Bitcoin (BTC).
|
|
71090
|
-
* @param {number} sats - The amount in SAT.
|
|
71091
|
-
* @returns {number} The amount in BTC.
|
|
71092
|
-
*/
|
|
71093
|
-
static satsToBtc(sats) {
|
|
71094
|
-
return sats / 1e8;
|
|
71095
|
-
}
|
|
71096
|
-
};
|
|
71097
|
-
var bitcoin2 = new BitcoinNetworkConnection();
|
|
70139
|
+
// ../bitcoin/dist/esm/constants.js
|
|
70140
|
+
init_shim();
|
|
70141
|
+
var TXIN_WITNESS_COINBASE = "0000000000000000000000000000000000000000000000000000000000000000";
|
|
70142
|
+
var GENESIS_TX_ID = "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b";
|
|
71098
70143
|
|
|
71099
|
-
// ../bitcoin/dist/esm/
|
|
70144
|
+
// ../bitcoin/dist/esm/types.js
|
|
71100
70145
|
init_shim();
|
|
70146
|
+
var VerbosityLevel;
|
|
70147
|
+
(function(VerbosityLevel2) {
|
|
70148
|
+
VerbosityLevel2[VerbosityLevel2["hex"] = 0] = "hex";
|
|
70149
|
+
VerbosityLevel2[VerbosityLevel2["json"] = 1] = "json";
|
|
70150
|
+
VerbosityLevel2[VerbosityLevel2["jsonext"] = 2] = "jsonext";
|
|
70151
|
+
VerbosityLevel2[VerbosityLevel2["jsonextprev"] = 3] = "jsonextprev";
|
|
70152
|
+
})(VerbosityLevel || (VerbosityLevel = {}));
|
|
71101
70153
|
|
|
71102
70154
|
// src/core/beacon/utils.ts
|
|
71103
70155
|
init_shim();
|
|
@@ -71863,40 +70915,6 @@ var base256emoji = from({
|
|
|
71863
70915
|
decode: decode25
|
|
71864
70916
|
});
|
|
71865
70917
|
|
|
71866
|
-
// ../../node_modules/.pnpm/multiformats@13.4.1/node_modules/multiformats/dist/src/bases/base64.js
|
|
71867
|
-
var base64_exports = {};
|
|
71868
|
-
__export(base64_exports, {
|
|
71869
|
-
base64: () => base642,
|
|
71870
|
-
base64pad: () => base64pad,
|
|
71871
|
-
base64url: () => base64url2,
|
|
71872
|
-
base64urlpad: () => base64urlpad
|
|
71873
|
-
});
|
|
71874
|
-
init_shim();
|
|
71875
|
-
var base642 = rfc4648({
|
|
71876
|
-
prefix: "m",
|
|
71877
|
-
name: "base64",
|
|
71878
|
-
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
|
|
71879
|
-
bitsPerChar: 6
|
|
71880
|
-
});
|
|
71881
|
-
var base64pad = rfc4648({
|
|
71882
|
-
prefix: "M",
|
|
71883
|
-
name: "base64pad",
|
|
71884
|
-
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
|
|
71885
|
-
bitsPerChar: 6
|
|
71886
|
-
});
|
|
71887
|
-
var base64url2 = rfc4648({
|
|
71888
|
-
prefix: "u",
|
|
71889
|
-
name: "base64url",
|
|
71890
|
-
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",
|
|
71891
|
-
bitsPerChar: 6
|
|
71892
|
-
});
|
|
71893
|
-
var base64urlpad = rfc4648({
|
|
71894
|
-
prefix: "U",
|
|
71895
|
-
name: "base64urlpad",
|
|
71896
|
-
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",
|
|
71897
|
-
bitsPerChar: 6
|
|
71898
|
-
});
|
|
71899
|
-
|
|
71900
70918
|
// ../../node_modules/.pnpm/multiformats@13.4.1/node_modules/multiformats/dist/src/bases/base8.js
|
|
71901
70919
|
var base8_exports = {};
|
|
71902
70920
|
__export(base8_exports, {
|
|
@@ -73775,7 +72793,7 @@ var __awaiter2 = function(thisArg, _arguments, P3, generator) {
|
|
|
73775
72793
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
73776
72794
|
});
|
|
73777
72795
|
};
|
|
73778
|
-
var
|
|
72796
|
+
var MemoryStore = class {
|
|
73779
72797
|
constructor() {
|
|
73780
72798
|
this.store = /* @__PURE__ */ new Map();
|
|
73781
72799
|
}
|
|
@@ -79728,7 +78746,7 @@ var LocalKeyManager = class {
|
|
|
79728
78746
|
constructor(params) {
|
|
79729
78747
|
var _a3;
|
|
79730
78748
|
this._algorithmInstances = /* @__PURE__ */ new Map();
|
|
79731
|
-
this._keyStore = (_a3 = params === null || params === void 0 ? void 0 : params.keyStore) !== null && _a3 !== void 0 ? _a3 : new
|
|
78749
|
+
this._keyStore = (_a3 = params === null || params === void 0 ? void 0 : params.keyStore) !== null && _a3 !== void 0 ? _a3 : new MemoryStore();
|
|
79732
78750
|
}
|
|
79733
78751
|
/**
|
|
79734
78752
|
* Generates a hash digest of the provided data.
|
|
@@ -87926,7 +86944,7 @@ src_default.formatters.t = (v) => {
|
|
|
87926
86944
|
return v == null ? "undefined" : base322.baseEncode(v);
|
|
87927
86945
|
};
|
|
87928
86946
|
src_default.formatters.m = (v) => {
|
|
87929
|
-
return v == null ? "undefined" :
|
|
86947
|
+
return v == null ? "undefined" : base64.baseEncode(v);
|
|
87930
86948
|
};
|
|
87931
86949
|
src_default.formatters.p = (v) => {
|
|
87932
86950
|
return v == null ? "undefined" : v.toString();
|
|
@@ -93804,7 +92822,7 @@ function cidEncoder2(obj) {
|
|
|
93804
92822
|
];
|
|
93805
92823
|
}
|
|
93806
92824
|
function bytesEncoder(bytes6) {
|
|
93807
|
-
const bytesString =
|
|
92825
|
+
const bytesString = base64.encode(bytes6).slice(1);
|
|
93808
92826
|
return [
|
|
93809
92827
|
new Token(Type.map, Infinity, 1),
|
|
93810
92828
|
new Token(Type.string, "/", 1),
|
|
@@ -93912,7 +92930,7 @@ var DagJsonTokenizer = class extends Tokenizer {
|
|
|
93912
92930
|
throw new Error("Invalid encoded Bytes form");
|
|
93913
92931
|
}
|
|
93914
92932
|
}
|
|
93915
|
-
const bytes6 =
|
|
92933
|
+
const bytes6 = base64.decode(`m${innerValueToken.value}`);
|
|
93916
92934
|
return new Token(Type.bytes, bytes6, innerValueToken.value.length);
|
|
93917
92935
|
}
|
|
93918
92936
|
this.tokenBuffer.push(innerValueToken);
|
|
@@ -99490,7 +98508,7 @@ function pbkdf22(password, salt, iterations, keySize, hash4) {
|
|
|
99490
98508
|
c: iterations,
|
|
99491
98509
|
dkLen: keySize
|
|
99492
98510
|
});
|
|
99493
|
-
return
|
|
98511
|
+
return base64.encode(dek).substring(1);
|
|
99494
98512
|
}
|
|
99495
98513
|
|
|
99496
98514
|
// ../../node_modules/.pnpm/@libp2p+utils@6.7.2/node_modules/@libp2p/utils/dist/src/filters/hashes.js
|
|
@@ -99902,7 +98920,7 @@ var AbstractSession = class extends TypedEventEmitter {
|
|
|
99902
98920
|
this.initialProviders = init.providers ?? [];
|
|
99903
98921
|
}
|
|
99904
98922
|
async retrieve(cid, options2 = {}) {
|
|
99905
|
-
const cidStr =
|
|
98923
|
+
const cidStr = base64.encode(cid.multihash.bytes);
|
|
99906
98924
|
const existingJob = this.requests.get(cidStr);
|
|
99907
98925
|
if (existingJob != null) {
|
|
99908
98926
|
this.log("join existing request for %c", cid);
|
|
@@ -101764,15 +100782,15 @@ var QueuedBitswapMessage = class {
|
|
|
101764
100782
|
this.pendingBytes = 0;
|
|
101765
100783
|
}
|
|
101766
100784
|
addWantlistEntry(cid, entry) {
|
|
101767
|
-
const key =
|
|
100785
|
+
const key = base64.encode(cid.multihash.bytes);
|
|
101768
100786
|
this.wantlist.set(key, entry);
|
|
101769
100787
|
}
|
|
101770
100788
|
addBlockPresence(cid, blockPresence) {
|
|
101771
|
-
const key =
|
|
100789
|
+
const key = base64.encode(cid.multihash.bytes);
|
|
101772
100790
|
this.blockPresences.set(key, blockPresence);
|
|
101773
100791
|
}
|
|
101774
100792
|
addBlock(cid, block) {
|
|
101775
|
-
const key =
|
|
100793
|
+
const key = base64.encode(cid.multihash.bytes);
|
|
101776
100794
|
this.blocks.set(key, block);
|
|
101777
100795
|
}
|
|
101778
100796
|
};
|
|
@@ -103327,7 +102345,7 @@ var codecs = [{
|
|
|
103327
102345
|
code: CODE_CERTHASH,
|
|
103328
102346
|
name: "certhash",
|
|
103329
102347
|
size: V,
|
|
103330
|
-
bytesToValue: bytes2mb(
|
|
102348
|
+
bytesToValue: bytes2mb(base64url),
|
|
103331
102349
|
valueToBytes: mb2bytes
|
|
103332
102350
|
}, {
|
|
103333
102351
|
code: CODE_HTTP,
|
|
@@ -104633,7 +103651,7 @@ var TrustlessGateway = class {
|
|
|
104633
103651
|
*/
|
|
104634
103652
|
#uniqueBlockId(cid) {
|
|
104635
103653
|
const multihashBytes = cid.multihash.bytes;
|
|
104636
|
-
return
|
|
103654
|
+
return base64.encode(multihashBytes);
|
|
104637
103655
|
}
|
|
104638
103656
|
/**
|
|
104639
103657
|
* Fetch a raw block from `this.url` following the specification defined at
|
|
@@ -116401,7 +115419,7 @@ var ITERATIONS = 1e4;
|
|
|
116401
115419
|
async function exporter(privateKey, password) {
|
|
116402
115420
|
const cipher = aes_gcm_browser_exports.create();
|
|
116403
115421
|
const encryptedKey = await cipher.encrypt(privateKey, password);
|
|
116404
|
-
return
|
|
115422
|
+
return base64.encode(encryptedKey);
|
|
116405
115423
|
}
|
|
116406
115424
|
async function exportPrivateKey(key, password, format4) {
|
|
116407
115425
|
if (key.type === "RSA") {
|
|
@@ -116566,7 +115584,7 @@ async function importPrivateKey(encryptedKey, password) {
|
|
|
116566
115584
|
return importFromPem(encryptedKey, password);
|
|
116567
115585
|
}
|
|
116568
115586
|
async function importer(privateKey, password) {
|
|
116569
|
-
const encryptedKey =
|
|
115587
|
+
const encryptedKey = base64.decode(privateKey);
|
|
116570
115588
|
const cipher = aes_gcm_browser_exports.create();
|
|
116571
115589
|
return cipher.decrypt(encryptedKey, password);
|
|
116572
115590
|
}
|
|
@@ -154644,7 +153662,7 @@ function fingerprint2Ma(fingerprint) {
|
|
|
154644
153662
|
const output6 = fingerprint.split(":").map((str) => parseInt(str, 16));
|
|
154645
153663
|
const encoded = Uint8Array.from(output6);
|
|
154646
153664
|
const digest2 = create(sha2565.code, encoded);
|
|
154647
|
-
return multiaddr(`/certhash/${
|
|
153665
|
+
return multiaddr(`/certhash/${base64url.encode(digest2.bytes)}`);
|
|
154648
153666
|
}
|
|
154649
153667
|
function toSupportedHashFunction(code8) {
|
|
154650
153668
|
switch (code8) {
|
|
@@ -155053,7 +154071,7 @@ var WebRTCDirectTransport = class {
|
|
|
155053
154071
|
}, renewTime);
|
|
155054
154072
|
return {
|
|
155055
154073
|
pem: cert.toString("pem"),
|
|
155056
|
-
certhash:
|
|
154074
|
+
certhash: base64url.encode((await sha2565.digest(new Uint8Array(cert.rawData))).bytes)
|
|
155057
154075
|
};
|
|
155058
154076
|
}
|
|
155059
154077
|
async loadCertificate(dsKey, keyPair) {
|
|
@@ -156048,15 +155066,15 @@ var BeaconSignalDiscovery = class {
|
|
|
156048
155066
|
* Retrieves the beacon signals for the given array of BeaconService objects
|
|
156049
155067
|
* using an esplora/electrs REST API connection via a bitcoin I/O driver.
|
|
156050
155068
|
* @param {Array<BeaconService>} beaconServices Array of BeaconService objects to retrieve signals for
|
|
156051
|
-
* @param {
|
|
155069
|
+
* @param {BitcoinConnection} bitcoin Bitcoin network connection to use for REST calls
|
|
156052
155070
|
* @returns {Promise<Map<BeaconService, Array<BeaconSignal>>>} Map of beacon service to its discovered signals
|
|
156053
155071
|
*/
|
|
156054
|
-
static async indexer(beaconServices,
|
|
155072
|
+
static async indexer(beaconServices, bitcoin2) {
|
|
156055
155073
|
const beaconServiceSignals = /* @__PURE__ */ new Map();
|
|
156056
|
-
const currentBlockCount = await
|
|
155074
|
+
const currentBlockCount = await bitcoin2.rest.block.count();
|
|
156057
155075
|
for (const beaconService of beaconServices) {
|
|
156058
155076
|
beaconServiceSignals.set(beaconService, []);
|
|
156059
|
-
const beaconSignals = await
|
|
155077
|
+
const beaconSignals = await bitcoin2.rest.address.getTxs(
|
|
156060
155078
|
beaconService.serviceEndpoint
|
|
156061
155079
|
);
|
|
156062
155080
|
if (!beaconSignals || !beaconSignals.length) {
|
|
@@ -156093,22 +155111,22 @@ var BeaconSignalDiscovery = class {
|
|
|
156093
155111
|
/**
|
|
156094
155112
|
* Traverse the full blockchain from genesis to chain top looking for beacon signals.
|
|
156095
155113
|
* @param {Array<BeaconService>} beaconServices Array of BeaconService objects to search for signals.
|
|
156096
|
-
* @param {
|
|
155114
|
+
* @param {BitcoinConnection} bitcoin Bitcoin network connection to use for RPC calls.
|
|
156097
155115
|
* @returns {Promise<Map<BeaconService, Array<BeaconSignal>>>} Map of beacon service to its discovered signals.
|
|
156098
155116
|
*/
|
|
156099
|
-
static async fullnode(beaconServices,
|
|
155117
|
+
static async fullnode(beaconServices, bitcoin2) {
|
|
156100
155118
|
const beaconServiceSignals = /* @__PURE__ */ new Map();
|
|
156101
155119
|
for (const beaconService of beaconServices) {
|
|
156102
155120
|
beaconServiceSignals.set(beaconService, []);
|
|
156103
155121
|
}
|
|
156104
|
-
const rpc =
|
|
155122
|
+
const rpc = bitcoin2.rpc;
|
|
156105
155123
|
if (!rpc) {
|
|
156106
|
-
throw new ResolveError("RPC connection is not available", "RPC_CONNECTION_ERROR",
|
|
155124
|
+
throw new ResolveError("RPC connection is not available", "RPC_CONNECTION_ERROR", bitcoin2);
|
|
156107
155125
|
}
|
|
156108
155126
|
const targetHeight = await rpc.getBlockCount();
|
|
156109
155127
|
const beaconServicesMap = BeaconUtils.getBeaconServicesMap(beaconServices);
|
|
156110
155128
|
let height = 0;
|
|
156111
|
-
let block = await
|
|
155129
|
+
let block = await bitcoin2.rpc.getBlock({ height });
|
|
156112
155130
|
console.info(`Searching for beacon signals, please wait ...`);
|
|
156113
155131
|
while (block.height <= targetHeight) {
|
|
156114
155132
|
for (const tx of block.tx) {
|
|
@@ -156573,13 +155591,13 @@ var SchnorrMultikey = class _SchnorrMultikey {
|
|
|
156573
155591
|
* Convert the multikey to a JSON object.
|
|
156574
155592
|
* @returns {MultikeyObject} The multikey as a JSON object.
|
|
156575
155593
|
*/
|
|
156576
|
-
|
|
155594
|
+
toJSON() {
|
|
156577
155595
|
return {
|
|
156578
155596
|
id: this.id,
|
|
156579
155597
|
controller: this.controller,
|
|
156580
155598
|
fullId: this.fullId(),
|
|
156581
155599
|
signer: this.signer,
|
|
156582
|
-
keyPair: this.keyPair.
|
|
155600
|
+
keyPair: this.keyPair.toJSON(),
|
|
156583
155601
|
verificationMethod: this.toVerificationMethod()
|
|
156584
155602
|
};
|
|
156585
155603
|
}
|
|
@@ -156739,8 +155757,18 @@ var DidDocument2 = class _DidDocument {
|
|
|
156739
155757
|
* Convert the DidDocument to a JSON object.
|
|
156740
155758
|
* @returns {DidDocument} The JSON representation of the DidDocument.
|
|
156741
155759
|
*/
|
|
156742
|
-
|
|
156743
|
-
return
|
|
155760
|
+
toJSON() {
|
|
155761
|
+
return {
|
|
155762
|
+
id: this.id,
|
|
155763
|
+
"@context": this["@context"],
|
|
155764
|
+
verificationMethod: this.verificationMethod,
|
|
155765
|
+
authentication: this.authentication,
|
|
155766
|
+
assertionMethod: this.assertionMethod,
|
|
155767
|
+
capabilityInvocation: this.capabilityInvocation,
|
|
155768
|
+
capabilityDelegation: this.capabilityDelegation,
|
|
155769
|
+
service: this.service,
|
|
155770
|
+
deactivated: this.deactivated
|
|
155771
|
+
};
|
|
156744
155772
|
}
|
|
156745
155773
|
/**
|
|
156746
155774
|
* Create a minimal DidDocument from "k1" btcr2 identifier.
|
|
@@ -157038,7 +156066,7 @@ var Update = class {
|
|
|
157038
156066
|
patch: patches,
|
|
157039
156067
|
targetHash: "",
|
|
157040
156068
|
targetVersionId: sourceVersionId + 1,
|
|
157041
|
-
sourceHash: Canonicalization.process(sourceDocument, { encoding: "
|
|
156069
|
+
sourceHash: Canonicalization.process(sourceDocument, { encoding: "base58btc" })
|
|
157042
156070
|
};
|
|
157043
156071
|
const targetDocument = JSONPatch.apply(sourceDocument, patches);
|
|
157044
156072
|
try {
|
|
@@ -157050,7 +156078,7 @@ var Update = class {
|
|
|
157050
156078
|
targetDocument
|
|
157051
156079
|
);
|
|
157052
156080
|
}
|
|
157053
|
-
unsignedUpdate.targetHash = Canonicalization.process(targetDocument, { encoding: "
|
|
156081
|
+
unsignedUpdate.targetHash = Canonicalization.process(targetDocument, { encoding: "base58btc" });
|
|
157054
156082
|
return unsignedUpdate;
|
|
157055
156083
|
}
|
|
157056
156084
|
/**
|
|
@@ -157093,9 +156121,9 @@ var Update = class {
|
|
|
157093
156121
|
* @returns {SignedBTCR2Update} The SignedBTCR2Update object containing data to validate the Beacon Signal
|
|
157094
156122
|
* @throws {UpdateError} if the beaconService type is invalid
|
|
157095
156123
|
*/
|
|
157096
|
-
static async announce(beaconService, update, secretKey,
|
|
156124
|
+
static async announce(beaconService, update, secretKey, bitcoin2) {
|
|
157097
156125
|
const beacon = BeaconFactory.establish(beaconService);
|
|
157098
|
-
const result = await beacon.broadcastSignal(update, secretKey,
|
|
156126
|
+
const result = await beacon.broadcastSignal(update, secretKey, bitcoin2);
|
|
157099
156127
|
return result;
|
|
157100
156128
|
}
|
|
157101
156129
|
};
|
|
@@ -157132,7 +156160,7 @@ var DidBtcr2 = class {
|
|
|
157132
156160
|
options2
|
|
157133
156161
|
);
|
|
157134
156162
|
}
|
|
157135
|
-
return Identifier.encode({ idType,
|
|
156163
|
+
return Identifier.encode(genesisBytes, { idType, version: version3, network });
|
|
157136
156164
|
}
|
|
157137
156165
|
/**
|
|
157138
156166
|
* Entry point for section {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html | 7.2 Resolve}.
|
|
@@ -157183,15 +156211,17 @@ var DidBtcr2 = class {
|
|
|
157183
156211
|
const currentDocument = await Resolve.currentDocument(didComponents, genesisDocument);
|
|
157184
156212
|
const beaconServices = currentDocument.service.filter(BeaconUtils.isBeaconService).map(BeaconUtils.parseBeaconServiceEndpoint);
|
|
157185
156213
|
if (!resolutionOptions?.drivers?.bitcoin) {
|
|
157186
|
-
|
|
157187
|
-
|
|
157188
|
-
|
|
156214
|
+
throw new ResolveError(
|
|
156215
|
+
"Bitcoin connection required for resolve. Pass a configured driver via resolutionOptions.drivers.bitcoin or use DidBtcr2Api which injects it automatically.",
|
|
156216
|
+
MISSING_RESOLUTION_OPTIONS,
|
|
156217
|
+
resolutionOptions
|
|
156218
|
+
);
|
|
157189
156219
|
}
|
|
157190
|
-
const
|
|
156220
|
+
const bitcoin2 = resolutionOptions.drivers.bitcoin;
|
|
157191
156221
|
const unsortedUpdates = await Resolve.beaconSignals(
|
|
157192
156222
|
beaconServices,
|
|
157193
156223
|
sidecarData,
|
|
157194
|
-
|
|
156224
|
+
bitcoin2
|
|
157195
156225
|
);
|
|
157196
156226
|
if (!unsortedUpdates.length) {
|
|
157197
156227
|
didResolutionResult.didDocument = currentDocument;
|
|
@@ -157209,8 +156239,7 @@ var DidBtcr2 = class {
|
|
|
157209
156239
|
didResolutionResult.didDocumentMetadata = result.metadata;
|
|
157210
156240
|
return didResolutionResult;
|
|
157211
156241
|
} catch (error) {
|
|
157212
|
-
|
|
157213
|
-
if (!(error instanceof ResolveError)) throw new Error(error);
|
|
156242
|
+
if (!(error instanceof ResolveError)) throw new Error(error.message ?? error, { cause: error });
|
|
157214
156243
|
return {
|
|
157215
156244
|
...EMPTY_DID_RESOLUTION_RESULT,
|
|
157216
156245
|
didResolutionMetadata: {
|
|
@@ -157235,7 +156264,7 @@ var DidBtcr2 = class {
|
|
|
157235
156264
|
* @param {string} params.verificationMethodId The verificationMethod ID to sign the update with.
|
|
157236
156265
|
* @param {string} params.beaconId The beacon ID associated with the update.
|
|
157237
156266
|
* @param {KeyBytes | HexString} [params.signingMaterial] Optional signing material (key bytes or hex string).
|
|
157238
|
-
* @param {
|
|
156267
|
+
* @param {BitcoinConnection} [params.bitcoin] Optional Bitcoin network connection for announcing the update. If not provided, a default connection will be initialized.
|
|
157239
156268
|
* @return {Promise<SignedBTCR2Update>} Promise resolving to the signed BTCR2 update.
|
|
157240
156269
|
* @throws {UpdateError} if no verificationMethod, verificationMethod type is not `Multikey` or the publicKeyMultibase
|
|
157241
156270
|
* header is not `zQ3s`
|
|
@@ -157247,7 +156276,7 @@ var DidBtcr2 = class {
|
|
|
157247
156276
|
verificationMethodId,
|
|
157248
156277
|
beaconId,
|
|
157249
156278
|
signingMaterial,
|
|
157250
|
-
bitcoin:
|
|
156279
|
+
bitcoin: bitcoin2
|
|
157251
156280
|
}) {
|
|
157252
156281
|
if (!signingMaterial) {
|
|
157253
156282
|
throw new UpdateError(
|
|
@@ -157296,8 +156325,14 @@ var DidBtcr2 = class {
|
|
|
157296
156325
|
{ sourceDocument, beaconId }
|
|
157297
156326
|
);
|
|
157298
156327
|
}
|
|
157299
|
-
|
|
157300
|
-
|
|
156328
|
+
if (!bitcoin2) {
|
|
156329
|
+
throw new UpdateError(
|
|
156330
|
+
"Bitcoin connection required for update. Pass a configured `bitcoin` parameter or use DidBtcr2Api which injects it automatically.",
|
|
156331
|
+
INVALID_DID_UPDATE,
|
|
156332
|
+
{ beaconId }
|
|
156333
|
+
);
|
|
156334
|
+
}
|
|
156335
|
+
await Update.announce(beaconService, signed, secretKey, bitcoin2);
|
|
157301
156336
|
return signed;
|
|
157302
156337
|
}
|
|
157303
156338
|
/**
|
|
@@ -157337,8 +156372,8 @@ var Resolve = class {
|
|
|
157337
156372
|
* @returns {DidDocument} The resolved DID Document object.
|
|
157338
156373
|
*/
|
|
157339
156374
|
static deterministic(didComponents) {
|
|
157340
|
-
const did = Identifier.encode(didComponents);
|
|
157341
156375
|
const { genesisBytes } = didComponents;
|
|
156376
|
+
const did = Identifier.encode(genesisBytes, didComponents);
|
|
157342
156377
|
const { multibase: publicKeyMultibase } = new CompressedSecp256k1PublicKey(genesisBytes);
|
|
157343
156378
|
const service = BeaconUtils.generateBeaconServices({
|
|
157344
156379
|
id: did,
|
|
@@ -157366,15 +156401,15 @@ var Resolve = class {
|
|
|
157366
156401
|
*/
|
|
157367
156402
|
static async external(didComponents, genesisDocument) {
|
|
157368
156403
|
const hashBytes = Canonicalization.process(genesisDocument, { encoding: "hex" });
|
|
157369
|
-
const genesisBytes =
|
|
157370
|
-
if (genesisBytes !== hashBytes) {
|
|
156404
|
+
const { genesisBytes } = didComponents;
|
|
156405
|
+
if (bytesToHex(genesisBytes) !== hashBytes) {
|
|
157371
156406
|
throw new ResolveError(
|
|
157372
|
-
`Initial document mismatch: genesisBytes ${genesisBytes} !== hashBytes ${hashBytes}`,
|
|
156407
|
+
`Initial document mismatch: genesisBytes ${bytesToHex(genesisBytes)} !== hashBytes ${hashBytes}`,
|
|
157373
156408
|
INVALID_DID_DOCUMENT,
|
|
157374
156409
|
{ genesisBytes, hashBytes }
|
|
157375
156410
|
);
|
|
157376
156411
|
}
|
|
157377
|
-
const did = Identifier.encode(didComponents);
|
|
156412
|
+
const did = Identifier.encode(genesisBytes, didComponents);
|
|
157378
156413
|
const currentDocument = JSON.parse(
|
|
157379
156414
|
JSON.stringify(genesisDocument).replaceAll(ID_PLACEHOLDER_VALUE, did)
|
|
157380
156415
|
);
|
|
@@ -157440,11 +156475,11 @@ var Resolve = class {
|
|
|
157440
156475
|
* Signal Bytes (last output in OP_RETURN transaction).
|
|
157441
156476
|
* @param {Array<BeaconService>} beaconServices The array of BeaconService objects to search for signals.
|
|
157442
156477
|
* @param {SidecarData} sidecarData The sidecar data containing maps of updates, CAS announcements, and SMT proofs.
|
|
157443
|
-
* @param {
|
|
156478
|
+
* @param {BitcoinConnection} bitcoin The bitcoin network connection used to fetch beacon signals
|
|
157444
156479
|
* @returns {Promise<Array<[SignedBTCR2Update, BlockMetadata]>>} The array of BTCR2 Signed Updates announced by the Beacon Signals.
|
|
157445
156480
|
*/
|
|
157446
|
-
static async beaconSignals(beaconServices, sidecarData,
|
|
157447
|
-
const beaconServicesSignals =
|
|
156481
|
+
static async beaconSignals(beaconServices, sidecarData, bitcoin2) {
|
|
156482
|
+
const beaconServicesSignals = bitcoin2.rest ? await BeaconSignalDiscovery.indexer(beaconServices, bitcoin2) : await BeaconSignalDiscovery.fullnode(beaconServices, bitcoin2);
|
|
157448
156483
|
const promises = await Promise.all(
|
|
157449
156484
|
Array.from(beaconServicesSignals.entries()).map(
|
|
157450
156485
|
async ([service, signals]) => {
|
|
@@ -157479,7 +156514,7 @@ var Resolve = class {
|
|
|
157479
156514
|
}
|
|
157480
156515
|
};
|
|
157481
156516
|
for (const [update, block] of updates) {
|
|
157482
|
-
const currentDocumentHash = Canonicalization.process(response2.didDocument, { encoding: "
|
|
156517
|
+
const currentDocumentHash = Canonicalization.process(response2.didDocument, { encoding: "base58btc" });
|
|
157483
156518
|
const blocktime = DateUtils.blocktimeToTimestamp(block.time);
|
|
157484
156519
|
response2.metadata.updated = DateUtils.toISOStringNonFractional(blocktime);
|
|
157485
156520
|
response2.metadata.confirmations = block.confirmations;
|
|
@@ -157501,7 +156536,7 @@ var Resolve = class {
|
|
|
157501
156536
|
}
|
|
157502
156537
|
response2.didDocument = await this.applyUpdate(response2.didDocument, update);
|
|
157503
156538
|
const unsignedUpdate = JSONUtils.deleteKeys(update, ["proof"]);
|
|
157504
|
-
updateHashHistory.push(Canonicalization.process(unsignedUpdate, { encoding: "
|
|
156539
|
+
updateHashHistory.push(Canonicalization.process(unsignedUpdate, { encoding: "base58btc" }));
|
|
157505
156540
|
} else if (update.targetVersionId > currentVersionId + 1) {
|
|
157506
156541
|
throw new ResolveError(
|
|
157507
156542
|
`Version Id Mismatch: targetVersionId cannot be > currentVersionId + 1`,
|
|
@@ -157582,11 +156617,11 @@ var Resolve = class {
|
|
|
157582
156617
|
}
|
|
157583
156618
|
const updatedDocument = JSONPatch.apply(currentDocument, update.patch);
|
|
157584
156619
|
DidDocument2.validate(updatedDocument);
|
|
157585
|
-
const currentDocumentHash = Canonicalization.process(updatedDocument, { encoding: "
|
|
157586
|
-
const updateTargetHash = update.targetHash
|
|
157587
|
-
if (
|
|
156620
|
+
const currentDocumentHash = Canonicalization.process(updatedDocument, { encoding: "base58btc" });
|
|
156621
|
+
const updateTargetHash = update.targetHash;
|
|
156622
|
+
if (update.targetHash !== currentDocumentHash) {
|
|
157588
156623
|
throw new ResolveError(
|
|
157589
|
-
`Invalid update:
|
|
156624
|
+
`Invalid update: update.targetHash !== currentDocumentHash`,
|
|
157590
156625
|
INVALID_DID_UPDATE,
|
|
157591
156626
|
{ updateTargetHash, currentDocumentHash }
|
|
157592
156627
|
);
|