@did-btcr2/api 0.1.1 → 0.2.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 +828 -1511
- package/dist/browser.mjs +828 -1511
- package/dist/cjs/api.js +6 -6
- package/dist/cjs/api.js.map +1 -1
- package/dist/esm/api.js +6 -6
- package/dist/esm/api.js.map +1 -1
- package/dist/types/api.d.ts +13 -5
- package/dist/types/api.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/api.ts +22 -11
package/dist/browser.js
CHANGED
|
@@ -1975,17 +1975,17 @@ var BTCR2 = (() => {
|
|
|
1975
1975
|
init_shim();
|
|
1976
1976
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1977
1977
|
exports.wrapXOFConstructorWithOpts = exports.wrapConstructorWithOpts = exports.wrapConstructor = exports.Hash = exports.nextTick = exports.swap32IfBE = exports.byteSwapIfBE = exports.swap8IfBE = exports.isLE = void 0;
|
|
1978
|
-
exports.isBytes =
|
|
1978
|
+
exports.isBytes = isBytes12;
|
|
1979
1979
|
exports.anumber = anumber4;
|
|
1980
|
-
exports.abytes =
|
|
1980
|
+
exports.abytes = abytes5;
|
|
1981
1981
|
exports.ahash = ahash3;
|
|
1982
|
-
exports.aexists =
|
|
1983
|
-
exports.aoutput =
|
|
1982
|
+
exports.aexists = aexists3;
|
|
1983
|
+
exports.aoutput = aoutput3;
|
|
1984
1984
|
exports.u8 = u82;
|
|
1985
1985
|
exports.u32 = u323;
|
|
1986
|
-
exports.clean =
|
|
1987
|
-
exports.createView =
|
|
1988
|
-
exports.rotr =
|
|
1986
|
+
exports.clean = clean3;
|
|
1987
|
+
exports.createView = createView9;
|
|
1988
|
+
exports.rotr = rotr6;
|
|
1989
1989
|
exports.rotl = rotl4;
|
|
1990
1990
|
exports.byteSwap = byteSwap;
|
|
1991
1991
|
exports.byteSwap32 = byteSwap32;
|
|
@@ -2003,15 +2003,15 @@ var BTCR2 = (() => {
|
|
|
2003
2003
|
exports.createXOFer = createXOFer;
|
|
2004
2004
|
exports.randomBytes = randomBytes7;
|
|
2005
2005
|
var crypto_1 = require_crypto();
|
|
2006
|
-
function
|
|
2006
|
+
function isBytes12(a3) {
|
|
2007
2007
|
return a3 instanceof Uint8Array || ArrayBuffer.isView(a3) && a3.constructor.name === "Uint8Array";
|
|
2008
2008
|
}
|
|
2009
2009
|
function anumber4(n3) {
|
|
2010
2010
|
if (!Number.isSafeInteger(n3) || n3 < 0)
|
|
2011
2011
|
throw new Error("positive integer expected, got " + n3);
|
|
2012
2012
|
}
|
|
2013
|
-
function
|
|
2014
|
-
if (!
|
|
2013
|
+
function abytes5(b3, ...lengths) {
|
|
2014
|
+
if (!isBytes12(b3))
|
|
2015
2015
|
throw new Error("Uint8Array expected");
|
|
2016
2016
|
if (lengths.length > 0 && !lengths.includes(b3.length))
|
|
2017
2017
|
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b3.length);
|
|
@@ -2022,14 +2022,14 @@ var BTCR2 = (() => {
|
|
|
2022
2022
|
anumber4(h2.outputLen);
|
|
2023
2023
|
anumber4(h2.blockLen);
|
|
2024
2024
|
}
|
|
2025
|
-
function
|
|
2025
|
+
function aexists3(instance3, checkFinished = true) {
|
|
2026
2026
|
if (instance3.destroyed)
|
|
2027
2027
|
throw new Error("Hash instance has been destroyed");
|
|
2028
2028
|
if (checkFinished && instance3.finished)
|
|
2029
2029
|
throw new Error("Hash#digest() has already been called");
|
|
2030
2030
|
}
|
|
2031
|
-
function
|
|
2032
|
-
|
|
2031
|
+
function aoutput3(out, instance3) {
|
|
2032
|
+
abytes5(out);
|
|
2033
2033
|
const min = instance3.outputLen;
|
|
2034
2034
|
if (out.length < min) {
|
|
2035
2035
|
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
@@ -2041,15 +2041,15 @@ var BTCR2 = (() => {
|
|
|
2041
2041
|
function u323(arr) {
|
|
2042
2042
|
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
2043
2043
|
}
|
|
2044
|
-
function
|
|
2044
|
+
function clean3(...arrays) {
|
|
2045
2045
|
for (let i5 = 0; i5 < arrays.length; i5++) {
|
|
2046
2046
|
arrays[i5].fill(0);
|
|
2047
2047
|
}
|
|
2048
2048
|
}
|
|
2049
|
-
function
|
|
2049
|
+
function createView9(arr) {
|
|
2050
2050
|
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
2051
2051
|
}
|
|
2052
|
-
function
|
|
2052
|
+
function rotr6(word2, shift) {
|
|
2053
2053
|
return word2 << 32 - shift | word2 >>> shift;
|
|
2054
2054
|
}
|
|
2055
2055
|
function rotl4(word2, shift) {
|
|
@@ -2074,7 +2074,7 @@ var BTCR2 = (() => {
|
|
|
2074
2074
|
))();
|
|
2075
2075
|
var hexes5 = /* @__PURE__ */ Array.from({ length: 256 }, (_, i5) => i5.toString(16).padStart(2, "0"));
|
|
2076
2076
|
function bytesToHex6(bytes6) {
|
|
2077
|
-
|
|
2077
|
+
abytes5(bytes6);
|
|
2078
2078
|
if (hasHexBuiltin3)
|
|
2079
2079
|
return bytes6.toHex();
|
|
2080
2080
|
let hex3 = "";
|
|
@@ -2139,20 +2139,20 @@ var BTCR2 = (() => {
|
|
|
2139
2139
|
function toBytes8(data) {
|
|
2140
2140
|
if (typeof data === "string")
|
|
2141
2141
|
data = utf8ToBytes11(data);
|
|
2142
|
-
|
|
2142
|
+
abytes5(data);
|
|
2143
2143
|
return data;
|
|
2144
2144
|
}
|
|
2145
2145
|
function kdfInputToBytes2(data) {
|
|
2146
2146
|
if (typeof data === "string")
|
|
2147
2147
|
data = utf8ToBytes11(data);
|
|
2148
|
-
|
|
2148
|
+
abytes5(data);
|
|
2149
2149
|
return data;
|
|
2150
2150
|
}
|
|
2151
2151
|
function concatBytes11(...arrays) {
|
|
2152
2152
|
let sum = 0;
|
|
2153
2153
|
for (let i5 = 0; i5 < arrays.length; i5++) {
|
|
2154
2154
|
const a3 = arrays[i5];
|
|
2155
|
-
|
|
2155
|
+
abytes5(a3);
|
|
2156
2156
|
sum += a3.length;
|
|
2157
2157
|
}
|
|
2158
2158
|
const res = new Uint8Array(sum);
|
|
@@ -2219,8 +2219,8 @@ var BTCR2 = (() => {
|
|
|
2219
2219
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2220
2220
|
exports.SHA512_IV = exports.SHA384_IV = exports.SHA224_IV = exports.SHA256_IV = exports.HashMD = void 0;
|
|
2221
2221
|
exports.setBigUint64 = setBigUint648;
|
|
2222
|
-
exports.Chi =
|
|
2223
|
-
exports.Maj =
|
|
2222
|
+
exports.Chi = Chi6;
|
|
2223
|
+
exports.Maj = Maj6;
|
|
2224
2224
|
var utils_ts_1 = require_utils();
|
|
2225
2225
|
function setBigUint648(view, byteOffset, value3, isLE7) {
|
|
2226
2226
|
if (typeof view.setBigUint64 === "function")
|
|
@@ -2234,13 +2234,13 @@ var BTCR2 = (() => {
|
|
|
2234
2234
|
view.setUint32(byteOffset + h2, wh, isLE7);
|
|
2235
2235
|
view.setUint32(byteOffset + l2, wl, isLE7);
|
|
2236
2236
|
}
|
|
2237
|
-
function
|
|
2237
|
+
function Chi6(a3, b3, c2) {
|
|
2238
2238
|
return a3 & b3 ^ ~a3 & c2;
|
|
2239
2239
|
}
|
|
2240
|
-
function
|
|
2240
|
+
function Maj6(a3, b3, c2) {
|
|
2241
2241
|
return a3 & b3 ^ a3 & c2 ^ b3 & c2;
|
|
2242
2242
|
}
|
|
2243
|
-
var
|
|
2243
|
+
var HashMD3 = class extends utils_ts_1.Hash {
|
|
2244
2244
|
constructor(blockLen, outputLen, padOffset, isLE7) {
|
|
2245
2245
|
super();
|
|
2246
2246
|
this.finished = false;
|
|
@@ -2330,7 +2330,7 @@ var BTCR2 = (() => {
|
|
|
2330
2330
|
return this._cloneInto();
|
|
2331
2331
|
}
|
|
2332
2332
|
};
|
|
2333
|
-
exports.HashMD =
|
|
2333
|
+
exports.HashMD = HashMD3;
|
|
2334
2334
|
exports.SHA256_IV = Uint32Array.from([
|
|
2335
2335
|
1779033703,
|
|
2336
2336
|
3144134277,
|
|
@@ -2497,7 +2497,7 @@ var BTCR2 = (() => {
|
|
|
2497
2497
|
var _md_ts_1 = require_md();
|
|
2498
2498
|
var u642 = require_u64();
|
|
2499
2499
|
var utils_ts_1 = require_utils();
|
|
2500
|
-
var
|
|
2500
|
+
var SHA256_K6 = /* @__PURE__ */ Uint32Array.from([
|
|
2501
2501
|
1116352408,
|
|
2502
2502
|
1899447441,
|
|
2503
2503
|
3049323471,
|
|
@@ -2563,7 +2563,7 @@ var BTCR2 = (() => {
|
|
|
2563
2563
|
3204031479,
|
|
2564
2564
|
3329325298
|
|
2565
2565
|
]);
|
|
2566
|
-
var
|
|
2566
|
+
var SHA256_W6 = /* @__PURE__ */ new Uint32Array(64);
|
|
2567
2567
|
var SHA2566 = class extends _md_ts_1.HashMD {
|
|
2568
2568
|
constructor(outputLen = 32) {
|
|
2569
2569
|
super(64, outputLen, 8, false);
|
|
@@ -2593,18 +2593,18 @@ var BTCR2 = (() => {
|
|
|
2593
2593
|
}
|
|
2594
2594
|
process(view, offset) {
|
|
2595
2595
|
for (let i5 = 0; i5 < 16; i5++, offset += 4)
|
|
2596
|
-
|
|
2596
|
+
SHA256_W6[i5] = view.getUint32(offset, false);
|
|
2597
2597
|
for (let i5 = 16; i5 < 64; i5++) {
|
|
2598
|
-
const W15 =
|
|
2599
|
-
const W2 =
|
|
2598
|
+
const W15 = SHA256_W6[i5 - 15];
|
|
2599
|
+
const W2 = SHA256_W6[i5 - 2];
|
|
2600
2600
|
const s0 = (0, utils_ts_1.rotr)(W15, 7) ^ (0, utils_ts_1.rotr)(W15, 18) ^ W15 >>> 3;
|
|
2601
2601
|
const s1 = (0, utils_ts_1.rotr)(W2, 17) ^ (0, utils_ts_1.rotr)(W2, 19) ^ W2 >>> 10;
|
|
2602
|
-
|
|
2602
|
+
SHA256_W6[i5] = s1 + SHA256_W6[i5 - 7] + s0 + SHA256_W6[i5 - 16] | 0;
|
|
2603
2603
|
}
|
|
2604
2604
|
let { A, B, C: C2, D, E, F, G: G2, H } = this;
|
|
2605
2605
|
for (let i5 = 0; i5 < 64; i5++) {
|
|
2606
2606
|
const sigma1 = (0, utils_ts_1.rotr)(E, 6) ^ (0, utils_ts_1.rotr)(E, 11) ^ (0, utils_ts_1.rotr)(E, 25);
|
|
2607
|
-
const T1 = H + sigma1 + (0, _md_ts_1.Chi)(E, F, G2) +
|
|
2607
|
+
const T1 = H + sigma1 + (0, _md_ts_1.Chi)(E, F, G2) + SHA256_K6[i5] + SHA256_W6[i5] | 0;
|
|
2608
2608
|
const sigma0 = (0, utils_ts_1.rotr)(A, 2) ^ (0, utils_ts_1.rotr)(A, 13) ^ (0, utils_ts_1.rotr)(A, 22);
|
|
2609
2609
|
const T2 = sigma0 + (0, _md_ts_1.Maj)(A, B, C2) | 0;
|
|
2610
2610
|
H = G2;
|
|
@@ -2627,7 +2627,7 @@ var BTCR2 = (() => {
|
|
|
2627
2627
|
this.set(A, B, C2, D, E, F, G2, H);
|
|
2628
2628
|
}
|
|
2629
2629
|
roundClean() {
|
|
2630
|
-
(0, utils_ts_1.clean)(
|
|
2630
|
+
(0, utils_ts_1.clean)(SHA256_W6);
|
|
2631
2631
|
}
|
|
2632
2632
|
destroy() {
|
|
2633
2633
|
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
@@ -40375,9 +40375,9 @@ var BTCR2 = (() => {
|
|
|
40375
40375
|
}
|
|
40376
40376
|
/**
|
|
40377
40377
|
* Add a proof to a document.
|
|
40378
|
-
* @param {
|
|
40378
|
+
* @param {UnsignedBTCR2Update} unsignedDocument The document to add the proof to.
|
|
40379
40379
|
* @param {DataIntegrityConfig} config The configuration for generating the proof.
|
|
40380
|
-
* @returns {
|
|
40380
|
+
* @returns {SignedBTCR2Update} A document with a proof added.
|
|
40381
40381
|
*/
|
|
40382
40382
|
addProof(unsignedDocument, config) {
|
|
40383
40383
|
const proof = this.cryptosuite.createProof(unsignedDocument, config);
|
|
@@ -40492,7 +40492,7 @@ var BTCR2 = (() => {
|
|
|
40492
40492
|
}
|
|
40493
40493
|
/**
|
|
40494
40494
|
* Verify a proof for a secure document.
|
|
40495
|
-
* @param {
|
|
40495
|
+
* @param {SignedBTCR2Update} secureDocument The secure document to verify.
|
|
40496
40496
|
* @returns {VerificationResult} The result of the verification.
|
|
40497
40497
|
*/
|
|
40498
40498
|
verifyProof(secureDocument) {
|
|
@@ -40507,7 +40507,7 @@ var BTCR2 = (() => {
|
|
|
40507
40507
|
}
|
|
40508
40508
|
/**
|
|
40509
40509
|
* Transform a document into canonical form.
|
|
40510
|
-
* @param {
|
|
40510
|
+
* @param {UnsignedBTCR2Update | SignedBTCR2Update} document The document to transform.
|
|
40511
40511
|
* @param {DataIntegrityConfig} config The config to use when transforming the document.
|
|
40512
40512
|
* @returns {string} The canonicalized document.
|
|
40513
40513
|
* @throws {MethodError} if the document cannot be transformed.
|
|
@@ -40613,16 +40613,16 @@ var BTCR2 = (() => {
|
|
|
40613
40613
|
#multibase;
|
|
40614
40614
|
/**
|
|
40615
40615
|
* Instantiates an instance of Secp256k1SecretKey.
|
|
40616
|
-
* @param {
|
|
40616
|
+
* @param {Bytes | bigint} entropy bytes (Uint8Array) or secret (bigint)
|
|
40617
40617
|
* @throws {SecretKeyError} If entropy is not provided, not a valid 32-byte secret key or not a valid bigint seed
|
|
40618
40618
|
*/
|
|
40619
40619
|
constructor(entropy) {
|
|
40620
|
-
const
|
|
40620
|
+
const isBytes12 = entropy instanceof Uint8Array;
|
|
40621
40621
|
const isSecret = typeof entropy === "bigint";
|
|
40622
|
-
if (!
|
|
40622
|
+
if (!isBytes12 && !isSecret) {
|
|
40623
40623
|
throw new SecretKeyError("Invalid entropy: must be a valid byte array (32) or bigint", "CONSTRUCTOR_ERROR");
|
|
40624
40624
|
}
|
|
40625
|
-
if (
|
|
40625
|
+
if (isBytes12 && entropy.length === 32) {
|
|
40626
40626
|
this.#bytes = entropy;
|
|
40627
40627
|
this.#seed = _Secp256k1SecretKey2.toSecret(entropy);
|
|
40628
40628
|
}
|
|
@@ -40807,15 +40807,23 @@ var BTCR2 = (() => {
|
|
|
40807
40807
|
}
|
|
40808
40808
|
return new Uint8Array(bytes6);
|
|
40809
40809
|
}
|
|
40810
|
+
/**
|
|
40811
|
+
* Creates a new Secp256k1SecretKey object from random bytes.
|
|
40812
|
+
* @param {KeyBytes} bytes The secret key bytes
|
|
40813
|
+
* @returns {Secp256k1SecretKey} A new Secp256k1SecretKey object
|
|
40814
|
+
*/
|
|
40815
|
+
static fromBytes(bytes6) {
|
|
40816
|
+
return new _Secp256k1SecretKey2(bytes6);
|
|
40817
|
+
}
|
|
40810
40818
|
/**
|
|
40811
40819
|
* Creates a new Secp256k1SecretKey object from a bigint secret.
|
|
40812
|
-
* @param {bigint}
|
|
40820
|
+
* @param {bigint} bint The secret bigint
|
|
40813
40821
|
* @returns {Secp256k1SecretKey} A new Secp256k1SecretKey object
|
|
40814
40822
|
*/
|
|
40815
|
-
static
|
|
40816
|
-
const hexsecret =
|
|
40817
|
-
const
|
|
40818
|
-
return new _Secp256k1SecretKey2(
|
|
40823
|
+
static fromBigInt(bint) {
|
|
40824
|
+
const hexsecret = bint.toString(16).padStart(64, "0");
|
|
40825
|
+
const bytes6 = new Uint8Array(hexsecret.match(/.{2}/g).map((byte) => parseInt(byte, 16)));
|
|
40826
|
+
return new _Secp256k1SecretKey2(bytes6);
|
|
40819
40827
|
}
|
|
40820
40828
|
/**
|
|
40821
40829
|
* Generates random secret key bytes.
|
|
@@ -41132,12 +41140,18 @@ var BTCR2 = (() => {
|
|
|
41132
41140
|
|
|
41133
41141
|
// ../keypair/dist/esm/pair.js
|
|
41134
41142
|
var SchnorrKeyPair = class _SchnorrKeyPair2 {
|
|
41135
|
-
/**
|
|
41143
|
+
/**
|
|
41144
|
+
* The secret key objec
|
|
41145
|
+
*/
|
|
41136
41146
|
#secretKey;
|
|
41137
41147
|
#publicKey;
|
|
41138
|
-
/**
|
|
41148
|
+
/**
|
|
41149
|
+
* The public key in multibase forma
|
|
41150
|
+
*/
|
|
41139
41151
|
#publicKeyMultibase;
|
|
41140
|
-
/**
|
|
41152
|
+
/**
|
|
41153
|
+
* The secret key in multibase forma
|
|
41154
|
+
*/
|
|
41141
41155
|
#secretKeyMultibase;
|
|
41142
41156
|
/**
|
|
41143
41157
|
* Creates an instance of Keys. Must provide a at least a secret key.
|
|
@@ -41275,11 +41289,11 @@ var BTCR2 = (() => {
|
|
|
41275
41289
|
}
|
|
41276
41290
|
/**
|
|
41277
41291
|
* Static method creates a new Keys (Secp256k1SecretKey/CompressedSecp256k1PublicKey) from bigint entropy.
|
|
41278
|
-
* @param {bigint}
|
|
41292
|
+
* @param {bigint} bint The entropy in bigint form
|
|
41279
41293
|
* @returns {SchnorrKeyPair} A new SchnorrKeyPair object
|
|
41280
41294
|
*/
|
|
41281
|
-
static
|
|
41282
|
-
const secretKey = Secp256k1SecretKey.
|
|
41295
|
+
static fromBigInt(bint) {
|
|
41296
|
+
const secretKey = Secp256k1SecretKey.fromBigInt(bint);
|
|
41283
41297
|
const publicKey2 = secretKey.computePublicKey();
|
|
41284
41298
|
return new _SchnorrKeyPair2({ secretKey, publicKey: publicKey2 });
|
|
41285
41299
|
}
|
|
@@ -43389,29 +43403,27 @@ var BTCR2 = (() => {
|
|
|
43389
43403
|
* @param {MultikeyParams} params The parameters to create the multikey
|
|
43390
43404
|
* @param {string} params.id The id of the multikey (required)
|
|
43391
43405
|
* @param {string} params.controller The controller of the multikey (required)
|
|
43392
|
-
* @param {
|
|
43393
|
-
* @param {CompressedSecp256k1PublicKey} params.keys.publicKey The public key of the multikey (optional, required if no privateKey)
|
|
43394
|
-
* @param {Secp256k1SecretKey} params.keys.privateKey The private key of the multikey (optional)
|
|
43406
|
+
* @param {SchnorrKeyPair} params.keyPair The key pair of the multikey (optional, required if no publicKey)
|
|
43395
43407
|
* @throws {MultikeyError} if neither a publicKey nor a privateKey is provided
|
|
43396
43408
|
*/
|
|
43397
|
-
constructor({ id, controller,
|
|
43398
|
-
if (!
|
|
43399
|
-
throw new MultikeyError('Argument missing: "
|
|
43409
|
+
constructor({ id, controller, keyPair }) {
|
|
43410
|
+
if (!keyPair) {
|
|
43411
|
+
throw new MultikeyError('Argument missing: "keyPair" required', "CONSTRUCTOR_ERROR");
|
|
43400
43412
|
}
|
|
43401
|
-
if (!
|
|
43402
|
-
throw new MultikeyError('Argument missing: "
|
|
43413
|
+
if (!keyPair.publicKey) {
|
|
43414
|
+
throw new MultikeyError('Argument missing: "keyPair" must contain a "publicKey"', "CONSTRUCTOR_ERROR");
|
|
43403
43415
|
}
|
|
43404
43416
|
this.id = id;
|
|
43405
43417
|
this.controller = controller;
|
|
43406
|
-
this.#keyPair =
|
|
43418
|
+
this.#keyPair = keyPair;
|
|
43407
43419
|
}
|
|
43408
43420
|
/**
|
|
43409
43421
|
* @readonly
|
|
43410
43422
|
* Get the SchnorrKeyPair.
|
|
43411
43423
|
*/
|
|
43412
43424
|
get keyPair() {
|
|
43413
|
-
const
|
|
43414
|
-
return
|
|
43425
|
+
const keyPair = this.#keyPair;
|
|
43426
|
+
return keyPair;
|
|
43415
43427
|
}
|
|
43416
43428
|
/**
|
|
43417
43429
|
* @readonly
|
|
@@ -43518,9 +43530,10 @@ var BTCR2 = (() => {
|
|
|
43518
43530
|
throw new MultikeyError('Invalid "type" in verificationMethod', VERIFICATION_METHOD_ERROR, { verificationMethod });
|
|
43519
43531
|
}
|
|
43520
43532
|
const decoded = this.publicKey.decode();
|
|
43521
|
-
const
|
|
43522
|
-
const
|
|
43523
|
-
|
|
43533
|
+
const pk = decoded.slice(2, decoded.length);
|
|
43534
|
+
const publicKey2 = new CompressedSecp256k1PublicKey(pk);
|
|
43535
|
+
const keyPair = new SchnorrKeyPair({ publicKey: publicKey2 });
|
|
43536
|
+
return new _SchnorrMultikey2({ id, controller, keyPair });
|
|
43524
43537
|
}
|
|
43525
43538
|
/**
|
|
43526
43539
|
* @readonly
|
|
@@ -43554,22 +43567,21 @@ var BTCR2 = (() => {
|
|
|
43554
43567
|
* @throws {MultikeyError} if neither a publicKey nor a privateKey is provided
|
|
43555
43568
|
* @returns {SchnorrMultikey} A new Multikey instance
|
|
43556
43569
|
*/
|
|
43557
|
-
static create({ id, controller,
|
|
43558
|
-
return new _SchnorrMultikey2({ id, controller,
|
|
43570
|
+
static create({ id, controller, keyPair }) {
|
|
43571
|
+
return new _SchnorrMultikey2({ id, controller, keyPair });
|
|
43559
43572
|
}
|
|
43560
43573
|
/**
|
|
43561
43574
|
* Creates a `Multikey` instance from a private key
|
|
43562
|
-
* @param {FromPublicKey} params The parameters to create the multikey
|
|
43563
43575
|
* @param {string} params.id The id of the multikey
|
|
43564
43576
|
* @param {string} params.controller The controller of the multikey
|
|
43565
43577
|
* @param {KeyBytes} params.entropy The private key bytes for the multikey
|
|
43566
43578
|
* @returns {SchnorrMultikey} The new multikey instance
|
|
43567
43579
|
*/
|
|
43568
|
-
static
|
|
43569
|
-
const secretKey = new Secp256k1SecretKey(
|
|
43580
|
+
static fromSecretKey(id, controller, secretKeyb) {
|
|
43581
|
+
const secretKey = new Secp256k1SecretKey(secretKeyb);
|
|
43570
43582
|
const publicKey2 = secretKey.computePublicKey();
|
|
43571
|
-
const
|
|
43572
|
-
return new _SchnorrMultikey2({ id, controller,
|
|
43583
|
+
const keyPair = new SchnorrKeyPair({ publicKey: publicKey2, secretKey });
|
|
43584
|
+
return new _SchnorrMultikey2({ id, controller, keyPair });
|
|
43573
43585
|
}
|
|
43574
43586
|
/**
|
|
43575
43587
|
* Creates a `Multikey` instance from a public key
|
|
@@ -43580,24 +43592,29 @@ var BTCR2 = (() => {
|
|
|
43580
43592
|
* @returns {Multikey} The new multikey instance
|
|
43581
43593
|
*/
|
|
43582
43594
|
static fromPublicKey({ id, controller, publicKeyBytes }) {
|
|
43583
|
-
const
|
|
43584
|
-
|
|
43595
|
+
const publicKey2 = new CompressedSecp256k1PublicKey(publicKeyBytes);
|
|
43596
|
+
const keyPair = new SchnorrKeyPair({ publicKey: publicKey2 });
|
|
43597
|
+
return new _SchnorrMultikey2({ id, controller, keyPair });
|
|
43585
43598
|
}
|
|
43586
43599
|
/**
|
|
43587
43600
|
* Creates a `Multikey` instance from a public key multibase.
|
|
43588
|
-
* @param {
|
|
43589
|
-
* @param {string}
|
|
43590
|
-
* @param {string}
|
|
43601
|
+
* @param {DidVerificationMethod} vm The verification method containing the public key multibase.
|
|
43602
|
+
* @param {string} vm.id The id of the multikey.
|
|
43603
|
+
* @param {string} vm.controller The controller of the multikey.
|
|
43604
|
+
* @param {string} vm.publicKeyMultibase The public key multibase of the multikey.
|
|
43591
43605
|
* @returns {Multikey} The new multikey instance.
|
|
43592
43606
|
*/
|
|
43593
|
-
static
|
|
43607
|
+
static fromVerificationMethod({ id, controller, publicKeyMultibase }) {
|
|
43608
|
+
if (!publicKeyMultibase) {
|
|
43609
|
+
throw new MultikeyError("Invalid publicKeyMultibase: cannot be undefined", VERIFICATION_METHOD_ERROR, { publicKeyMultibase });
|
|
43610
|
+
}
|
|
43594
43611
|
const publicKeyMultibaseBytes = base58btc.decode(publicKeyMultibase);
|
|
43595
43612
|
if (publicKeyMultibaseBytes.length !== 35) {
|
|
43596
43613
|
throw new MultikeyError(`Invalid publicKeyMultibase length: ${publicKeyMultibaseBytes.length}`, VERIFICATION_METHOD_ERROR, { publicKeyMultibase });
|
|
43597
43614
|
}
|
|
43598
43615
|
const publicKey2 = publicKeyMultibaseBytes.slice(2);
|
|
43599
|
-
const
|
|
43600
|
-
return new _SchnorrMultikey2({ id, controller,
|
|
43616
|
+
const keyPair = new SchnorrKeyPair({ publicKey: publicKey2 });
|
|
43617
|
+
return new _SchnorrMultikey2({ id, controller, keyPair });
|
|
43601
43618
|
}
|
|
43602
43619
|
};
|
|
43603
43620
|
|
|
@@ -45566,17 +45583,17 @@ var BTCR2 = (() => {
|
|
|
45566
45583
|
init_shim2();
|
|
45567
45584
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45568
45585
|
exports.wrapXOFConstructorWithOpts = exports.wrapConstructorWithOpts = exports.wrapConstructor = exports.Hash = exports.nextTick = exports.swap32IfBE = exports.byteSwapIfBE = exports.swap8IfBE = exports.isLE = void 0;
|
|
45569
|
-
exports.isBytes =
|
|
45586
|
+
exports.isBytes = isBytes12;
|
|
45570
45587
|
exports.anumber = anumber4;
|
|
45571
|
-
exports.abytes =
|
|
45588
|
+
exports.abytes = abytes5;
|
|
45572
45589
|
exports.ahash = ahash22;
|
|
45573
|
-
exports.aexists =
|
|
45574
|
-
exports.aoutput =
|
|
45590
|
+
exports.aexists = aexists3;
|
|
45591
|
+
exports.aoutput = aoutput3;
|
|
45575
45592
|
exports.u8 = u82;
|
|
45576
45593
|
exports.u32 = u323;
|
|
45577
|
-
exports.clean =
|
|
45578
|
-
exports.createView =
|
|
45579
|
-
exports.rotr =
|
|
45594
|
+
exports.clean = clean3;
|
|
45595
|
+
exports.createView = createView9;
|
|
45596
|
+
exports.rotr = rotr6;
|
|
45580
45597
|
exports.rotl = rotl4;
|
|
45581
45598
|
exports.byteSwap = byteSwap;
|
|
45582
45599
|
exports.byteSwap32 = byteSwap32;
|
|
@@ -45589,20 +45606,20 @@ var BTCR2 = (() => {
|
|
|
45589
45606
|
exports.kdfInputToBytes = kdfInputToBytes2;
|
|
45590
45607
|
exports.concatBytes = concatBytes11;
|
|
45591
45608
|
exports.checkOpts = checkOpts4;
|
|
45592
|
-
exports.createHasher =
|
|
45609
|
+
exports.createHasher = createHasher22;
|
|
45593
45610
|
exports.createOptHasher = createOptHasher;
|
|
45594
45611
|
exports.createXOFer = createXOFer;
|
|
45595
45612
|
exports.randomBytes = randomBytes10;
|
|
45596
45613
|
var crypto_1 = require_crypto2();
|
|
45597
|
-
function
|
|
45614
|
+
function isBytes12(a3) {
|
|
45598
45615
|
return a3 instanceof Uint8Array || ArrayBuffer.isView(a3) && a3.constructor.name === "Uint8Array";
|
|
45599
45616
|
}
|
|
45600
45617
|
function anumber4(n3) {
|
|
45601
45618
|
if (!Number.isSafeInteger(n3) || n3 < 0)
|
|
45602
45619
|
throw new Error("positive integer expected, got " + n3);
|
|
45603
45620
|
}
|
|
45604
|
-
function
|
|
45605
|
-
if (!
|
|
45621
|
+
function abytes5(b22, ...lengths) {
|
|
45622
|
+
if (!isBytes12(b22))
|
|
45606
45623
|
throw new Error("Uint8Array expected");
|
|
45607
45624
|
if (lengths.length > 0 && !lengths.includes(b22.length))
|
|
45608
45625
|
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b22.length);
|
|
@@ -45613,14 +45630,14 @@ var BTCR2 = (() => {
|
|
|
45613
45630
|
anumber4(h2.outputLen);
|
|
45614
45631
|
anumber4(h2.blockLen);
|
|
45615
45632
|
}
|
|
45616
|
-
function
|
|
45633
|
+
function aexists3(instance3, checkFinished = true) {
|
|
45617
45634
|
if (instance3.destroyed)
|
|
45618
45635
|
throw new Error("Hash instance has been destroyed");
|
|
45619
45636
|
if (checkFinished && instance3.finished)
|
|
45620
45637
|
throw new Error("Hash#digest() has already been called");
|
|
45621
45638
|
}
|
|
45622
|
-
function
|
|
45623
|
-
|
|
45639
|
+
function aoutput3(out, instance3) {
|
|
45640
|
+
abytes5(out);
|
|
45624
45641
|
const min = instance3.outputLen;
|
|
45625
45642
|
if (out.length < min) {
|
|
45626
45643
|
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
@@ -45632,15 +45649,15 @@ var BTCR2 = (() => {
|
|
|
45632
45649
|
function u323(arr) {
|
|
45633
45650
|
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
45634
45651
|
}
|
|
45635
|
-
function
|
|
45652
|
+
function clean3(...arrays) {
|
|
45636
45653
|
for (let i42 = 0; i42 < arrays.length; i42++) {
|
|
45637
45654
|
arrays[i42].fill(0);
|
|
45638
45655
|
}
|
|
45639
45656
|
}
|
|
45640
|
-
function
|
|
45657
|
+
function createView9(arr) {
|
|
45641
45658
|
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
45642
45659
|
}
|
|
45643
|
-
function
|
|
45660
|
+
function rotr6(word2, shift) {
|
|
45644
45661
|
return word2 << 32 - shift | word2 >>> shift;
|
|
45645
45662
|
}
|
|
45646
45663
|
function rotl4(word2, shift) {
|
|
@@ -45665,7 +45682,7 @@ var BTCR2 = (() => {
|
|
|
45665
45682
|
))();
|
|
45666
45683
|
var hexes5 = /* @__PURE__ */ Array.from({ length: 256 }, (_, i42) => i42.toString(16).padStart(2, "0"));
|
|
45667
45684
|
function bytesToHex6(bytes6) {
|
|
45668
|
-
|
|
45685
|
+
abytes5(bytes6);
|
|
45669
45686
|
if (hasHexBuiltin3)
|
|
45670
45687
|
return bytes6.toHex();
|
|
45671
45688
|
let hex3 = "";
|
|
@@ -45730,20 +45747,20 @@ var BTCR2 = (() => {
|
|
|
45730
45747
|
function toBytes8(data) {
|
|
45731
45748
|
if (typeof data === "string")
|
|
45732
45749
|
data = utf8ToBytes11(data);
|
|
45733
|
-
|
|
45750
|
+
abytes5(data);
|
|
45734
45751
|
return data;
|
|
45735
45752
|
}
|
|
45736
45753
|
function kdfInputToBytes2(data) {
|
|
45737
45754
|
if (typeof data === "string")
|
|
45738
45755
|
data = utf8ToBytes11(data);
|
|
45739
|
-
|
|
45756
|
+
abytes5(data);
|
|
45740
45757
|
return data;
|
|
45741
45758
|
}
|
|
45742
45759
|
function concatBytes11(...arrays) {
|
|
45743
45760
|
let sum = 0;
|
|
45744
45761
|
for (let i42 = 0; i42 < arrays.length; i42++) {
|
|
45745
45762
|
const a3 = arrays[i42];
|
|
45746
|
-
|
|
45763
|
+
abytes5(a3);
|
|
45747
45764
|
sum += a3.length;
|
|
45748
45765
|
}
|
|
45749
45766
|
const res = new Uint8Array(sum);
|
|
@@ -45763,7 +45780,7 @@ var BTCR2 = (() => {
|
|
|
45763
45780
|
var Hash7 = class {
|
|
45764
45781
|
};
|
|
45765
45782
|
exports.Hash = Hash7;
|
|
45766
|
-
function
|
|
45783
|
+
function createHasher22(hashCons) {
|
|
45767
45784
|
const hashC = (msg) => hashCons().update(toBytes8(msg)).digest();
|
|
45768
45785
|
const tmp = hashCons();
|
|
45769
45786
|
hashC.outputLen = tmp.outputLen;
|
|
@@ -45787,7 +45804,7 @@ var BTCR2 = (() => {
|
|
|
45787
45804
|
hashC.create = (opts) => hashCons(opts);
|
|
45788
45805
|
return hashC;
|
|
45789
45806
|
}
|
|
45790
|
-
exports.wrapConstructor =
|
|
45807
|
+
exports.wrapConstructor = createHasher22;
|
|
45791
45808
|
exports.wrapConstructorWithOpts = createOptHasher;
|
|
45792
45809
|
exports.wrapXOFConstructorWithOpts = createXOFer;
|
|
45793
45810
|
function randomBytes10(bytesLength = 32) {
|
|
@@ -45808,8 +45825,8 @@ var BTCR2 = (() => {
|
|
|
45808
45825
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45809
45826
|
exports.SHA512_IV = exports.SHA384_IV = exports.SHA224_IV = exports.SHA256_IV = exports.HashMD = void 0;
|
|
45810
45827
|
exports.setBigUint64 = setBigUint648;
|
|
45811
|
-
exports.Chi =
|
|
45812
|
-
exports.Maj =
|
|
45828
|
+
exports.Chi = Chi6;
|
|
45829
|
+
exports.Maj = Maj6;
|
|
45813
45830
|
var utils_ts_1 = require_utils8();
|
|
45814
45831
|
function setBigUint648(view, byteOffset, value3, isLE7) {
|
|
45815
45832
|
if (typeof view.setBigUint64 === "function")
|
|
@@ -45823,13 +45840,13 @@ var BTCR2 = (() => {
|
|
|
45823
45840
|
view.setUint32(byteOffset + h2, wh, isLE7);
|
|
45824
45841
|
view.setUint32(byteOffset + l2, wl, isLE7);
|
|
45825
45842
|
}
|
|
45826
|
-
function
|
|
45843
|
+
function Chi6(a3, b22, c2) {
|
|
45827
45844
|
return a3 & b22 ^ ~a3 & c2;
|
|
45828
45845
|
}
|
|
45829
|
-
function
|
|
45846
|
+
function Maj6(a3, b22, c2) {
|
|
45830
45847
|
return a3 & b22 ^ a3 & c2 ^ b22 & c2;
|
|
45831
45848
|
}
|
|
45832
|
-
var
|
|
45849
|
+
var HashMD3 = class extends utils_ts_1.Hash {
|
|
45833
45850
|
constructor(blockLen, outputLen, padOffset, isLE7) {
|
|
45834
45851
|
super();
|
|
45835
45852
|
this.finished = false;
|
|
@@ -45919,7 +45936,7 @@ var BTCR2 = (() => {
|
|
|
45919
45936
|
return this._cloneInto();
|
|
45920
45937
|
}
|
|
45921
45938
|
};
|
|
45922
|
-
exports.HashMD =
|
|
45939
|
+
exports.HashMD = HashMD3;
|
|
45923
45940
|
exports.SHA256_IV = Uint32Array.from([
|
|
45924
45941
|
1779033703,
|
|
45925
45942
|
3144134277,
|
|
@@ -46082,7 +46099,7 @@ var BTCR2 = (() => {
|
|
|
46082
46099
|
var _md_ts_1 = require_md2();
|
|
46083
46100
|
var u642 = require_u642();
|
|
46084
46101
|
var utils_ts_1 = require_utils8();
|
|
46085
|
-
var
|
|
46102
|
+
var SHA256_K6 = /* @__PURE__ */ Uint32Array.from([
|
|
46086
46103
|
1116352408,
|
|
46087
46104
|
1899447441,
|
|
46088
46105
|
3049323471,
|
|
@@ -46148,7 +46165,7 @@ var BTCR2 = (() => {
|
|
|
46148
46165
|
3204031479,
|
|
46149
46166
|
3329325298
|
|
46150
46167
|
]);
|
|
46151
|
-
var
|
|
46168
|
+
var SHA256_W6 = /* @__PURE__ */ new Uint32Array(64);
|
|
46152
46169
|
var SHA2566 = class extends _md_ts_1.HashMD {
|
|
46153
46170
|
constructor(outputLen = 32) {
|
|
46154
46171
|
super(64, outputLen, 8, false);
|
|
@@ -46178,18 +46195,18 @@ var BTCR2 = (() => {
|
|
|
46178
46195
|
}
|
|
46179
46196
|
process(view, offset) {
|
|
46180
46197
|
for (let i42 = 0; i42 < 16; i42++, offset += 4)
|
|
46181
|
-
|
|
46198
|
+
SHA256_W6[i42] = view.getUint32(offset, false);
|
|
46182
46199
|
for (let i42 = 16; i42 < 64; i42++) {
|
|
46183
|
-
const W15 =
|
|
46184
|
-
const W2 =
|
|
46200
|
+
const W15 = SHA256_W6[i42 - 15];
|
|
46201
|
+
const W2 = SHA256_W6[i42 - 2];
|
|
46185
46202
|
const s0 = (0, utils_ts_1.rotr)(W15, 7) ^ (0, utils_ts_1.rotr)(W15, 18) ^ W15 >>> 3;
|
|
46186
46203
|
const s1 = (0, utils_ts_1.rotr)(W2, 17) ^ (0, utils_ts_1.rotr)(W2, 19) ^ W2 >>> 10;
|
|
46187
|
-
|
|
46204
|
+
SHA256_W6[i42] = s1 + SHA256_W6[i42 - 7] + s0 + SHA256_W6[i42 - 16] | 0;
|
|
46188
46205
|
}
|
|
46189
46206
|
let { A, B, C: C2, D, E, F, G: G2, H } = this;
|
|
46190
46207
|
for (let i42 = 0; i42 < 64; i42++) {
|
|
46191
46208
|
const sigma1 = (0, utils_ts_1.rotr)(E, 6) ^ (0, utils_ts_1.rotr)(E, 11) ^ (0, utils_ts_1.rotr)(E, 25);
|
|
46192
|
-
const T1 = H + sigma1 + (0, _md_ts_1.Chi)(E, F, G2) +
|
|
46209
|
+
const T1 = H + sigma1 + (0, _md_ts_1.Chi)(E, F, G2) + SHA256_K6[i42] + SHA256_W6[i42] | 0;
|
|
46193
46210
|
const sigma0 = (0, utils_ts_1.rotr)(A, 2) ^ (0, utils_ts_1.rotr)(A, 13) ^ (0, utils_ts_1.rotr)(A, 22);
|
|
46194
46211
|
const T2 = sigma0 + (0, _md_ts_1.Maj)(A, B, C2) | 0;
|
|
46195
46212
|
H = G2;
|
|
@@ -46212,7 +46229,7 @@ var BTCR2 = (() => {
|
|
|
46212
46229
|
this.set(A, B, C2, D, E, F, G2, H);
|
|
46213
46230
|
}
|
|
46214
46231
|
roundClean() {
|
|
46215
|
-
(0, utils_ts_1.clean)(
|
|
46232
|
+
(0, utils_ts_1.clean)(SHA256_W6);
|
|
46216
46233
|
}
|
|
46217
46234
|
destroy() {
|
|
46218
46235
|
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
@@ -48845,7 +48862,7 @@ var BTCR2 = (() => {
|
|
|
48845
48862
|
exports.expand_message_xof = expand_message_xof;
|
|
48846
48863
|
exports.hash_to_field = hash_to_field;
|
|
48847
48864
|
exports.isogenyMap = isogenyMap;
|
|
48848
|
-
exports.createHasher =
|
|
48865
|
+
exports.createHasher = createHasher22;
|
|
48849
48866
|
var utils_ts_1 = require_utils22();
|
|
48850
48867
|
var modular_ts_1 = require_modular2();
|
|
48851
48868
|
var os2ip = utils_ts_1.bytesToNumberBE;
|
|
@@ -48960,7 +48977,7 @@ var BTCR2 = (() => {
|
|
|
48960
48977
|
};
|
|
48961
48978
|
}
|
|
48962
48979
|
exports._DST_scalar = (0, utils_ts_1.utf8ToBytes)("HashToScalar-");
|
|
48963
|
-
function
|
|
48980
|
+
function createHasher22(Point7, mapToCurve, defaults2) {
|
|
48964
48981
|
if (typeof mapToCurve !== "function")
|
|
48965
48982
|
throw new Error("mapToCurve() must be defined");
|
|
48966
48983
|
function map3(num22) {
|
|
@@ -90522,7 +90539,7 @@ var BTCR2 = (() => {
|
|
|
90522
90539
|
}
|
|
90523
90540
|
var genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain(/* @__PURE__ */ radix(58), /* @__PURE__ */ alphabet(abc), /* @__PURE__ */ join(""));
|
|
90524
90541
|
var base58 = /* @__PURE__ */ genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
90525
|
-
var createBase58check = (
|
|
90542
|
+
var createBase58check = (sha25610) => /* @__PURE__ */ chain(checksum(4, (data) => sha25610(sha25610(data))), base58);
|
|
90526
90543
|
var BECH_ALPHABET = /* @__PURE__ */ chain(/* @__PURE__ */ alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), /* @__PURE__ */ join(""));
|
|
90527
90544
|
var POLYMOD_GENERATORS = [996825010, 642813549, 513874426, 1027748829, 705979059];
|
|
90528
90545
|
function bech32Polymod(pre) {
|
|
@@ -91046,7 +91063,7 @@ var BTCR2 = (() => {
|
|
|
91046
91063
|
this.buffers.push(new Uint8Array([b22]));
|
|
91047
91064
|
this.pos++;
|
|
91048
91065
|
}
|
|
91049
|
-
finish(
|
|
91066
|
+
finish(clean3 = true) {
|
|
91050
91067
|
if (this.finished)
|
|
91051
91068
|
throw this.err("buffer: finished");
|
|
91052
91069
|
if (this.bitPos)
|
|
@@ -91064,7 +91081,7 @@ var BTCR2 = (() => {
|
|
|
91064
91081
|
buf2.set(ptr.ptr.encode(pos), ptr.pos);
|
|
91065
91082
|
pos += ptr.buffer.length;
|
|
91066
91083
|
}
|
|
91067
|
-
if (
|
|
91084
|
+
if (clean3) {
|
|
91068
91085
|
this.buffers = [];
|
|
91069
91086
|
for (const p3 of this.ptrs)
|
|
91070
91087
|
p3.buffer.fill(0);
|
|
@@ -99958,11 +99975,6 @@ var BTCR2 = (() => {
|
|
|
99958
99975
|
super(message2, { type, name: "ResolveError", data });
|
|
99959
99976
|
}
|
|
99960
99977
|
};
|
|
99961
|
-
var KeyManagerError = class extends DidMethodError2 {
|
|
99962
|
-
constructor(message2, type = "KeyManagerError", data) {
|
|
99963
|
-
super(message2, { type, name: type, data });
|
|
99964
|
-
}
|
|
99965
|
-
};
|
|
99966
99978
|
var DidDocumentError = class extends DidMethodError2 {
|
|
99967
99979
|
constructor(message2, type = "DidDocumentError", data) {
|
|
99968
99980
|
super(message2, { type, name: type, data });
|
|
@@ -99998,11 +100010,6 @@ var BTCR2 = (() => {
|
|
|
99998
100010
|
super(message2, { type, name: type, data });
|
|
99999
100011
|
}
|
|
100000
100012
|
};
|
|
100001
|
-
var SingletonBeaconError = class extends DidMethodError2 {
|
|
100002
|
-
constructor(message2, type = "SingletonBeaconError", data) {
|
|
100003
|
-
super(message2, { type, name: type, data });
|
|
100004
|
-
}
|
|
100005
|
-
};
|
|
100006
100013
|
var CanonicalizationError2 = class extends DidMethodError2 {
|
|
100007
100014
|
constructor(message2, type = "CanonicalizationError", data) {
|
|
100008
100015
|
super(message2, { type, name: type, data });
|
|
@@ -101801,6 +101808,26 @@ var BTCR2 = (() => {
|
|
|
101801
101808
|
return value3.replace(regex3, replacement);
|
|
101802
101809
|
}
|
|
101803
101810
|
};
|
|
101811
|
+
var BeaconError = class extends MethodError2 {
|
|
101812
|
+
constructor(message2, type = "BeaconError", data) {
|
|
101813
|
+
super(message2, type, data);
|
|
101814
|
+
}
|
|
101815
|
+
};
|
|
101816
|
+
var SingletonBeaconError = class extends MethodError2 {
|
|
101817
|
+
constructor(message2, type = "SingletonBeaconError", data) {
|
|
101818
|
+
super(message2, type, data);
|
|
101819
|
+
}
|
|
101820
|
+
};
|
|
101821
|
+
var CASBeaconError = class extends MethodError2 {
|
|
101822
|
+
constructor(message2, type = "CASBeaconError", data) {
|
|
101823
|
+
super(message2, type, data);
|
|
101824
|
+
}
|
|
101825
|
+
};
|
|
101826
|
+
var SMTBeaconError = class extends MethodError2 {
|
|
101827
|
+
constructor(message2, type = "SMTBeaconError", data) {
|
|
101828
|
+
super(message2, type, data);
|
|
101829
|
+
}
|
|
101830
|
+
};
|
|
101804
101831
|
init_shim2();
|
|
101805
101832
|
init_shim2();
|
|
101806
101833
|
init_shim2();
|
|
@@ -101844,16 +101871,16 @@ var BTCR2 = (() => {
|
|
|
101844
101871
|
#multibase;
|
|
101845
101872
|
/**
|
|
101846
101873
|
* Instantiates an instance of Secp256k1SecretKey.
|
|
101847
|
-
* @param {
|
|
101874
|
+
* @param {Bytes | bigint} entropy bytes (Uint8Array) or secret (bigint)
|
|
101848
101875
|
* @throws {SecretKeyError} If entropy is not provided, not a valid 32-byte secret key or not a valid bigint seed
|
|
101849
101876
|
*/
|
|
101850
101877
|
constructor(entropy) {
|
|
101851
|
-
const
|
|
101878
|
+
const isBytes12 = entropy instanceof Uint8Array;
|
|
101852
101879
|
const isSecret = typeof entropy === "bigint";
|
|
101853
|
-
if (!
|
|
101880
|
+
if (!isBytes12 && !isSecret) {
|
|
101854
101881
|
throw new SecretKeyError2("Invalid entropy: must be a valid byte array (32) or bigint", "CONSTRUCTOR_ERROR");
|
|
101855
101882
|
}
|
|
101856
|
-
if (
|
|
101883
|
+
if (isBytes12 && entropy.length === 32) {
|
|
101857
101884
|
this.#bytes = entropy;
|
|
101858
101885
|
this.#seed = _Secp256k1SecretKey.toSecret(entropy);
|
|
101859
101886
|
}
|
|
@@ -102038,15 +102065,23 @@ var BTCR2 = (() => {
|
|
|
102038
102065
|
}
|
|
102039
102066
|
return new Uint8Array(bytes6);
|
|
102040
102067
|
}
|
|
102068
|
+
/**
|
|
102069
|
+
* Creates a new Secp256k1SecretKey object from random bytes.
|
|
102070
|
+
* @param {KeyBytes} bytes The secret key bytes
|
|
102071
|
+
* @returns {Secp256k1SecretKey} A new Secp256k1SecretKey object
|
|
102072
|
+
*/
|
|
102073
|
+
static fromBytes(bytes6) {
|
|
102074
|
+
return new _Secp256k1SecretKey(bytes6);
|
|
102075
|
+
}
|
|
102041
102076
|
/**
|
|
102042
102077
|
* Creates a new Secp256k1SecretKey object from a bigint secret.
|
|
102043
|
-
* @param {bigint}
|
|
102078
|
+
* @param {bigint} bint The secret bigint
|
|
102044
102079
|
* @returns {Secp256k1SecretKey} A new Secp256k1SecretKey object
|
|
102045
102080
|
*/
|
|
102046
|
-
static
|
|
102047
|
-
const hexsecret =
|
|
102048
|
-
const
|
|
102049
|
-
return new _Secp256k1SecretKey(
|
|
102081
|
+
static fromBigInt(bint) {
|
|
102082
|
+
const hexsecret = bint.toString(16).padStart(64, "0");
|
|
102083
|
+
const bytes6 = new Uint8Array(hexsecret.match(/.{2}/g).map((byte) => parseInt(byte, 16)));
|
|
102084
|
+
return new _Secp256k1SecretKey(bytes6);
|
|
102050
102085
|
}
|
|
102051
102086
|
/**
|
|
102052
102087
|
* Generates random secret key bytes.
|
|
@@ -102359,12 +102394,18 @@ var BTCR2 = (() => {
|
|
|
102359
102394
|
}
|
|
102360
102395
|
};
|
|
102361
102396
|
var SchnorrKeyPair2 = class _SchnorrKeyPair {
|
|
102362
|
-
/**
|
|
102397
|
+
/**
|
|
102398
|
+
* The secret key objec
|
|
102399
|
+
*/
|
|
102363
102400
|
#secretKey;
|
|
102364
102401
|
#publicKey;
|
|
102365
|
-
/**
|
|
102402
|
+
/**
|
|
102403
|
+
* The public key in multibase forma
|
|
102404
|
+
*/
|
|
102366
102405
|
#publicKeyMultibase;
|
|
102367
|
-
/**
|
|
102406
|
+
/**
|
|
102407
|
+
* The secret key in multibase forma
|
|
102408
|
+
*/
|
|
102368
102409
|
#secretKeyMultibase;
|
|
102369
102410
|
/**
|
|
102370
102411
|
* Creates an instance of Keys. Must provide a at least a secret key.
|
|
@@ -102502,11 +102543,11 @@ var BTCR2 = (() => {
|
|
|
102502
102543
|
}
|
|
102503
102544
|
/**
|
|
102504
102545
|
* Static method creates a new Keys (Secp256k1SecretKey/CompressedSecp256k1PublicKey) from bigint entropy.
|
|
102505
|
-
* @param {bigint}
|
|
102546
|
+
* @param {bigint} bint The entropy in bigint form
|
|
102506
102547
|
* @returns {SchnorrKeyPair} A new SchnorrKeyPair object
|
|
102507
102548
|
*/
|
|
102508
|
-
static
|
|
102509
|
-
const secretKey = Secp256k1SecretKey2.
|
|
102549
|
+
static fromBigInt(bint) {
|
|
102550
|
+
const secretKey = Secp256k1SecretKey2.fromBigInt(bint);
|
|
102510
102551
|
const publicKey2 = secretKey.computePublicKey();
|
|
102511
102552
|
return new _SchnorrKeyPair({ secretKey, publicKey: publicKey2 });
|
|
102512
102553
|
}
|
|
@@ -108918,75 +108959,44 @@ var BTCR2 = (() => {
|
|
|
108918
108959
|
return pbkdf2Output(PRF, PRFSalt, DK, prfW, u);
|
|
108919
108960
|
}
|
|
108920
108961
|
init_shim2();
|
|
108921
|
-
|
|
108922
|
-
var AggregateBeacon = class {
|
|
108962
|
+
var Beacon = class {
|
|
108923
108963
|
/**
|
|
108924
|
-
* The Beacon service
|
|
108964
|
+
* The Beacon service configuration parsed from the DID Document.
|
|
108925
108965
|
*/
|
|
108926
108966
|
service;
|
|
108927
|
-
|
|
108928
|
-
* The array of Beacon Signals associated with this Beacon service.
|
|
108929
|
-
*/
|
|
108930
|
-
signals;
|
|
108931
|
-
/**
|
|
108932
|
-
* The sidecar data associated with this Beacon service.
|
|
108933
|
-
* TODO: Make this more specific to Beacon type.
|
|
108934
|
-
*/
|
|
108935
|
-
sidecar;
|
|
108936
|
-
/**
|
|
108937
|
-
* The Bitcoin network connection associated with this Beacon service.
|
|
108938
|
-
*/
|
|
108939
|
-
bitcoin;
|
|
108940
|
-
constructor(service, signals, sidecar, bitcoin32) {
|
|
108967
|
+
constructor(service) {
|
|
108941
108968
|
this.service = service;
|
|
108942
|
-
this.signals = signals;
|
|
108943
|
-
this.sidecar = sidecar;
|
|
108944
|
-
this.bitcoin = bitcoin32;
|
|
108945
108969
|
}
|
|
108946
108970
|
};
|
|
108947
|
-
|
|
108971
|
+
init_shim2();
|
|
108972
|
+
var CASBeacon = class extends Beacon {
|
|
108948
108973
|
/**
|
|
108949
108974
|
* Creates an instance of CASBeacon.
|
|
108950
108975
|
* @param {BeaconService} service The service of the Beacon.
|
|
108951
|
-
* @param {?BeaconSidecarData} [sidecar] The sidecar data of the Beacon.
|
|
108952
|
-
*/
|
|
108953
|
-
constructor(service, signals, sidecar, bitcoin32) {
|
|
108954
|
-
super({ ...service, type: "CASBeacon" }, signals, sidecar, bitcoin32);
|
|
108955
|
-
}
|
|
108956
|
-
/**
|
|
108957
|
-
* Establish a CASBeacon instance based on the provided service and sidecar data.
|
|
108958
|
-
* @param {BeaconService} service - The beacon service configuration.
|
|
108959
|
-
* @param {SidecarData} sidecar - The sidecar data.
|
|
108960
|
-
* @returns {CASBeacon} The established CASBeacon instance.
|
|
108961
|
-
*/
|
|
108962
|
-
static establish(service, signals, sidecar) {
|
|
108963
|
-
return new _CASBeacon(service, signals, sidecar);
|
|
108964
|
-
}
|
|
108965
|
-
/**
|
|
108966
|
-
* TODO: Figure out if this is necessary or not.
|
|
108967
|
-
* @param {HexString} updateHash The hash of the update to generate the signal for.
|
|
108968
|
-
* @returns {BeaconSignal} The generated signal.
|
|
108969
|
-
* @throws {MethodError} if the signal is invalid.
|
|
108970
108976
|
*/
|
|
108971
|
-
|
|
108972
|
-
|
|
108977
|
+
constructor(service) {
|
|
108978
|
+
super({ ...service, type: "CASBeacon" });
|
|
108973
108979
|
}
|
|
108974
108980
|
/**
|
|
108975
108981
|
* Implements {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-cas-beacon | 7.2.e.1 Process CAS Beacon}.
|
|
108976
|
-
* @
|
|
108977
|
-
* @
|
|
108982
|
+
* @param {Array<BeaconSignal>} signals The array of Beacon Signals to process.
|
|
108983
|
+
* @param {SidecarData} sidecar The sidecar data associated with the CAS Beacon.
|
|
108984
|
+
* @returns {Promise<Array<[SignedBTCR2Update, BlockMetadata]>>} The processed signals.
|
|
108985
|
+
* @throws {CASBeaconError} if processing fails.
|
|
108978
108986
|
*/
|
|
108979
|
-
processSignals() {
|
|
108980
|
-
throw new
|
|
108987
|
+
processSignals(signals, sidecar) {
|
|
108988
|
+
throw new CASBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signals, sidecar });
|
|
108981
108989
|
}
|
|
108982
108990
|
/**
|
|
108983
|
-
*
|
|
108984
|
-
* @param {
|
|
108985
|
-
* @
|
|
108986
|
-
* @
|
|
108991
|
+
* Broadcast CAS Beacon signal to the Bitcoin network.
|
|
108992
|
+
* @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
|
|
108993
|
+
* @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
|
|
108994
|
+
* @param {BitcoinNetworkConnection} bitcoin The Bitcoin network connection.
|
|
108995
|
+
* @return {Promise<SignedBTCR2Update>} The signed update that was broadcasted.
|
|
108996
|
+
* @throws {CASBeaconError} if broadcasting fails.
|
|
108987
108997
|
*/
|
|
108988
|
-
async broadcastSignal(
|
|
108989
|
-
throw new
|
|
108998
|
+
async broadcastSignal(signedUpdate, secretKey, bitcoin32) {
|
|
108999
|
+
throw new CASBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signedUpdate, secretKey, bitcoin: bitcoin32 });
|
|
108990
109000
|
}
|
|
108991
109001
|
};
|
|
108992
109002
|
init_shim2();
|
|
@@ -108996,609 +109006,6 @@ var BTCR2 = (() => {
|
|
|
108996
109006
|
init_shim2();
|
|
108997
109007
|
init_shim2();
|
|
108998
109008
|
init_shim2();
|
|
108999
|
-
init_shim2();
|
|
109000
|
-
function isBytes6(a3) {
|
|
109001
|
-
return a3 instanceof Uint8Array || ArrayBuffer.isView(a3) && a3.constructor.name === "Uint8Array";
|
|
109002
|
-
}
|
|
109003
|
-
function abytes3(value3, length7, title = "") {
|
|
109004
|
-
const bytes6 = isBytes6(value3);
|
|
109005
|
-
const len = value3?.length;
|
|
109006
|
-
const needsLen = length7 !== void 0;
|
|
109007
|
-
if (!bytes6 || needsLen && len !== length7) {
|
|
109008
|
-
const prefix = title && `"${title}" `;
|
|
109009
|
-
const ofLen = needsLen ? ` of length ${length7}` : "";
|
|
109010
|
-
const got = bytes6 ? `length=${len}` : `type=${typeof value3}`;
|
|
109011
|
-
throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
|
|
109012
|
-
}
|
|
109013
|
-
return value3;
|
|
109014
|
-
}
|
|
109015
|
-
function aexists22(instance3, checkFinished = true) {
|
|
109016
|
-
if (instance3.destroyed)
|
|
109017
|
-
throw new Error("Hash instance has been destroyed");
|
|
109018
|
-
if (checkFinished && instance3.finished)
|
|
109019
|
-
throw new Error("Hash#digest() has already been called");
|
|
109020
|
-
}
|
|
109021
|
-
function aoutput22(out, instance3) {
|
|
109022
|
-
abytes3(out, void 0, "digestInto() output");
|
|
109023
|
-
const min = instance3.outputLen;
|
|
109024
|
-
if (out.length < min) {
|
|
109025
|
-
throw new Error('"digestInto() output" expected to be of length >=' + min);
|
|
109026
|
-
}
|
|
109027
|
-
}
|
|
109028
|
-
function clean22(...arrays) {
|
|
109029
|
-
for (let i42 = 0; i42 < arrays.length; i42++) {
|
|
109030
|
-
arrays[i42].fill(0);
|
|
109031
|
-
}
|
|
109032
|
-
}
|
|
109033
|
-
function createView6(arr) {
|
|
109034
|
-
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
109035
|
-
}
|
|
109036
|
-
function rotr4(word2, shift) {
|
|
109037
|
-
return word2 << 32 - shift | word2 >>> shift;
|
|
109038
|
-
}
|
|
109039
|
-
function createHasher22(hashCons, info = {}) {
|
|
109040
|
-
const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
|
|
109041
|
-
const tmp = hashCons(void 0);
|
|
109042
|
-
hashC.outputLen = tmp.outputLen;
|
|
109043
|
-
hashC.blockLen = tmp.blockLen;
|
|
109044
|
-
hashC.create = (opts) => hashCons(opts);
|
|
109045
|
-
Object.assign(hashC, info);
|
|
109046
|
-
return Object.freeze(hashC);
|
|
109047
|
-
}
|
|
109048
|
-
var oidNist = (suffix) => ({
|
|
109049
|
-
oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
|
|
109050
|
-
});
|
|
109051
|
-
function Chi4(a3, b22, c2) {
|
|
109052
|
-
return a3 & b22 ^ ~a3 & c2;
|
|
109053
|
-
}
|
|
109054
|
-
function Maj4(a3, b22, c2) {
|
|
109055
|
-
return a3 & b22 ^ a3 & c2 ^ b22 & c2;
|
|
109056
|
-
}
|
|
109057
|
-
var HashMD22 = class {
|
|
109058
|
-
blockLen;
|
|
109059
|
-
outputLen;
|
|
109060
|
-
padOffset;
|
|
109061
|
-
isLE;
|
|
109062
|
-
// For partial updates less than block size
|
|
109063
|
-
buffer;
|
|
109064
|
-
view;
|
|
109065
|
-
finished = false;
|
|
109066
|
-
length = 0;
|
|
109067
|
-
pos = 0;
|
|
109068
|
-
destroyed = false;
|
|
109069
|
-
constructor(blockLen, outputLen, padOffset, isLE7) {
|
|
109070
|
-
this.blockLen = blockLen;
|
|
109071
|
-
this.outputLen = outputLen;
|
|
109072
|
-
this.padOffset = padOffset;
|
|
109073
|
-
this.isLE = isLE7;
|
|
109074
|
-
this.buffer = new Uint8Array(blockLen);
|
|
109075
|
-
this.view = createView6(this.buffer);
|
|
109076
|
-
}
|
|
109077
|
-
update(data) {
|
|
109078
|
-
aexists22(this);
|
|
109079
|
-
abytes3(data);
|
|
109080
|
-
const { view, buffer: buffer2, blockLen } = this;
|
|
109081
|
-
const len = data.length;
|
|
109082
|
-
for (let pos = 0; pos < len; ) {
|
|
109083
|
-
const take2 = Math.min(blockLen - this.pos, len - pos);
|
|
109084
|
-
if (take2 === blockLen) {
|
|
109085
|
-
const dataView2 = createView6(data);
|
|
109086
|
-
for (; blockLen <= len - pos; pos += blockLen)
|
|
109087
|
-
this.process(dataView2, pos);
|
|
109088
|
-
continue;
|
|
109089
|
-
}
|
|
109090
|
-
buffer2.set(data.subarray(pos, pos + take2), this.pos);
|
|
109091
|
-
this.pos += take2;
|
|
109092
|
-
pos += take2;
|
|
109093
|
-
if (this.pos === blockLen) {
|
|
109094
|
-
this.process(view, 0);
|
|
109095
|
-
this.pos = 0;
|
|
109096
|
-
}
|
|
109097
|
-
}
|
|
109098
|
-
this.length += data.length;
|
|
109099
|
-
this.roundClean();
|
|
109100
|
-
return this;
|
|
109101
|
-
}
|
|
109102
|
-
digestInto(out) {
|
|
109103
|
-
aexists22(this);
|
|
109104
|
-
aoutput22(out, this);
|
|
109105
|
-
this.finished = true;
|
|
109106
|
-
const { buffer: buffer2, view, blockLen, isLE: isLE7 } = this;
|
|
109107
|
-
let { pos } = this;
|
|
109108
|
-
buffer2[pos++] = 128;
|
|
109109
|
-
clean22(this.buffer.subarray(pos));
|
|
109110
|
-
if (this.padOffset > blockLen - pos) {
|
|
109111
|
-
this.process(view, 0);
|
|
109112
|
-
pos = 0;
|
|
109113
|
-
}
|
|
109114
|
-
for (let i42 = pos; i42 < blockLen; i42++)
|
|
109115
|
-
buffer2[i42] = 0;
|
|
109116
|
-
view.setBigUint64(blockLen - 8, BigInt(this.length * 8), isLE7);
|
|
109117
|
-
this.process(view, 0);
|
|
109118
|
-
const oview = createView6(out);
|
|
109119
|
-
const len = this.outputLen;
|
|
109120
|
-
if (len % 4)
|
|
109121
|
-
throw new Error("_sha2: outputLen must be aligned to 32bit");
|
|
109122
|
-
const outLen = len / 4;
|
|
109123
|
-
const state = this.get();
|
|
109124
|
-
if (outLen > state.length)
|
|
109125
|
-
throw new Error("_sha2: outputLen bigger than state");
|
|
109126
|
-
for (let i42 = 0; i42 < outLen; i42++)
|
|
109127
|
-
oview.setUint32(4 * i42, state[i42], isLE7);
|
|
109128
|
-
}
|
|
109129
|
-
digest() {
|
|
109130
|
-
const { buffer: buffer2, outputLen } = this;
|
|
109131
|
-
this.digestInto(buffer2);
|
|
109132
|
-
const res = buffer2.slice(0, outputLen);
|
|
109133
|
-
this.destroy();
|
|
109134
|
-
return res;
|
|
109135
|
-
}
|
|
109136
|
-
_cloneInto(to) {
|
|
109137
|
-
to ||= new this.constructor();
|
|
109138
|
-
to.set(...this.get());
|
|
109139
|
-
const { blockLen, buffer: buffer2, length: length7, finished, destroyed, pos } = this;
|
|
109140
|
-
to.destroyed = destroyed;
|
|
109141
|
-
to.finished = finished;
|
|
109142
|
-
to.length = length7;
|
|
109143
|
-
to.pos = pos;
|
|
109144
|
-
if (length7 % blockLen)
|
|
109145
|
-
to.buffer.set(buffer2);
|
|
109146
|
-
return to;
|
|
109147
|
-
}
|
|
109148
|
-
clone() {
|
|
109149
|
-
return this._cloneInto();
|
|
109150
|
-
}
|
|
109151
|
-
};
|
|
109152
|
-
var SHA256_IV22 = /* @__PURE__ */ Uint32Array.from([
|
|
109153
|
-
1779033703,
|
|
109154
|
-
3144134277,
|
|
109155
|
-
1013904242,
|
|
109156
|
-
2773480762,
|
|
109157
|
-
1359893119,
|
|
109158
|
-
2600822924,
|
|
109159
|
-
528734635,
|
|
109160
|
-
1541459225
|
|
109161
|
-
]);
|
|
109162
|
-
var SHA256_K4 = /* @__PURE__ */ Uint32Array.from([
|
|
109163
|
-
1116352408,
|
|
109164
|
-
1899447441,
|
|
109165
|
-
3049323471,
|
|
109166
|
-
3921009573,
|
|
109167
|
-
961987163,
|
|
109168
|
-
1508970993,
|
|
109169
|
-
2453635748,
|
|
109170
|
-
2870763221,
|
|
109171
|
-
3624381080,
|
|
109172
|
-
310598401,
|
|
109173
|
-
607225278,
|
|
109174
|
-
1426881987,
|
|
109175
|
-
1925078388,
|
|
109176
|
-
2162078206,
|
|
109177
|
-
2614888103,
|
|
109178
|
-
3248222580,
|
|
109179
|
-
3835390401,
|
|
109180
|
-
4022224774,
|
|
109181
|
-
264347078,
|
|
109182
|
-
604807628,
|
|
109183
|
-
770255983,
|
|
109184
|
-
1249150122,
|
|
109185
|
-
1555081692,
|
|
109186
|
-
1996064986,
|
|
109187
|
-
2554220882,
|
|
109188
|
-
2821834349,
|
|
109189
|
-
2952996808,
|
|
109190
|
-
3210313671,
|
|
109191
|
-
3336571891,
|
|
109192
|
-
3584528711,
|
|
109193
|
-
113926993,
|
|
109194
|
-
338241895,
|
|
109195
|
-
666307205,
|
|
109196
|
-
773529912,
|
|
109197
|
-
1294757372,
|
|
109198
|
-
1396182291,
|
|
109199
|
-
1695183700,
|
|
109200
|
-
1986661051,
|
|
109201
|
-
2177026350,
|
|
109202
|
-
2456956037,
|
|
109203
|
-
2730485921,
|
|
109204
|
-
2820302411,
|
|
109205
|
-
3259730800,
|
|
109206
|
-
3345764771,
|
|
109207
|
-
3516065817,
|
|
109208
|
-
3600352804,
|
|
109209
|
-
4094571909,
|
|
109210
|
-
275423344,
|
|
109211
|
-
430227734,
|
|
109212
|
-
506948616,
|
|
109213
|
-
659060556,
|
|
109214
|
-
883997877,
|
|
109215
|
-
958139571,
|
|
109216
|
-
1322822218,
|
|
109217
|
-
1537002063,
|
|
109218
|
-
1747873779,
|
|
109219
|
-
1955562222,
|
|
109220
|
-
2024104815,
|
|
109221
|
-
2227730452,
|
|
109222
|
-
2361852424,
|
|
109223
|
-
2428436474,
|
|
109224
|
-
2756734187,
|
|
109225
|
-
3204031479,
|
|
109226
|
-
3329325298
|
|
109227
|
-
]);
|
|
109228
|
-
var SHA256_W4 = /* @__PURE__ */ new Uint32Array(64);
|
|
109229
|
-
var SHA2_32B = class extends HashMD22 {
|
|
109230
|
-
constructor(outputLen) {
|
|
109231
|
-
super(64, outputLen, 8, false);
|
|
109232
|
-
}
|
|
109233
|
-
get() {
|
|
109234
|
-
const { A, B, C: C2, D, E, F, G: G2, H } = this;
|
|
109235
|
-
return [A, B, C2, D, E, F, G2, H];
|
|
109236
|
-
}
|
|
109237
|
-
// prettier-ignore
|
|
109238
|
-
set(A, B, C2, D, E, F, G2, H) {
|
|
109239
|
-
this.A = A | 0;
|
|
109240
|
-
this.B = B | 0;
|
|
109241
|
-
this.C = C2 | 0;
|
|
109242
|
-
this.D = D | 0;
|
|
109243
|
-
this.E = E | 0;
|
|
109244
|
-
this.F = F | 0;
|
|
109245
|
-
this.G = G2 | 0;
|
|
109246
|
-
this.H = H | 0;
|
|
109247
|
-
}
|
|
109248
|
-
process(view, offset) {
|
|
109249
|
-
for (let i42 = 0; i42 < 16; i42++, offset += 4)
|
|
109250
|
-
SHA256_W4[i42] = view.getUint32(offset, false);
|
|
109251
|
-
for (let i42 = 16; i42 < 64; i42++) {
|
|
109252
|
-
const W15 = SHA256_W4[i42 - 15];
|
|
109253
|
-
const W2 = SHA256_W4[i42 - 2];
|
|
109254
|
-
const s0 = rotr4(W15, 7) ^ rotr4(W15, 18) ^ W15 >>> 3;
|
|
109255
|
-
const s1 = rotr4(W2, 17) ^ rotr4(W2, 19) ^ W2 >>> 10;
|
|
109256
|
-
SHA256_W4[i42] = s1 + SHA256_W4[i42 - 7] + s0 + SHA256_W4[i42 - 16] | 0;
|
|
109257
|
-
}
|
|
109258
|
-
let { A, B, C: C2, D, E, F, G: G2, H } = this;
|
|
109259
|
-
for (let i42 = 0; i42 < 64; i42++) {
|
|
109260
|
-
const sigma1 = rotr4(E, 6) ^ rotr4(E, 11) ^ rotr4(E, 25);
|
|
109261
|
-
const T1 = H + sigma1 + Chi4(E, F, G2) + SHA256_K4[i42] + SHA256_W4[i42] | 0;
|
|
109262
|
-
const sigma0 = rotr4(A, 2) ^ rotr4(A, 13) ^ rotr4(A, 22);
|
|
109263
|
-
const T2 = sigma0 + Maj4(A, B, C2) | 0;
|
|
109264
|
-
H = G2;
|
|
109265
|
-
G2 = F;
|
|
109266
|
-
F = E;
|
|
109267
|
-
E = D + T1 | 0;
|
|
109268
|
-
D = C2;
|
|
109269
|
-
C2 = B;
|
|
109270
|
-
B = A;
|
|
109271
|
-
A = T1 + T2 | 0;
|
|
109272
|
-
}
|
|
109273
|
-
A = A + this.A | 0;
|
|
109274
|
-
B = B + this.B | 0;
|
|
109275
|
-
C2 = C2 + this.C | 0;
|
|
109276
|
-
D = D + this.D | 0;
|
|
109277
|
-
E = E + this.E | 0;
|
|
109278
|
-
F = F + this.F | 0;
|
|
109279
|
-
G2 = G2 + this.G | 0;
|
|
109280
|
-
H = H + this.H | 0;
|
|
109281
|
-
this.set(A, B, C2, D, E, F, G2, H);
|
|
109282
|
-
}
|
|
109283
|
-
roundClean() {
|
|
109284
|
-
clean22(SHA256_W4);
|
|
109285
|
-
}
|
|
109286
|
-
destroy() {
|
|
109287
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
109288
|
-
clean22(this.buffer);
|
|
109289
|
-
}
|
|
109290
|
-
};
|
|
109291
|
-
var _SHA256 = class extends SHA2_32B {
|
|
109292
|
-
// We cannot use array here since array allows indexing by variable
|
|
109293
|
-
// which means optimizer/compiler cannot use registers.
|
|
109294
|
-
A = SHA256_IV22[0] | 0;
|
|
109295
|
-
B = SHA256_IV22[1] | 0;
|
|
109296
|
-
C = SHA256_IV22[2] | 0;
|
|
109297
|
-
D = SHA256_IV22[3] | 0;
|
|
109298
|
-
E = SHA256_IV22[4] | 0;
|
|
109299
|
-
F = SHA256_IV22[5] | 0;
|
|
109300
|
-
G = SHA256_IV22[6] | 0;
|
|
109301
|
-
H = SHA256_IV22[7] | 0;
|
|
109302
|
-
constructor() {
|
|
109303
|
-
super(32);
|
|
109304
|
-
}
|
|
109305
|
-
};
|
|
109306
|
-
var sha2565 = /* @__PURE__ */ createHasher22(
|
|
109307
|
-
() => new _SHA256(),
|
|
109308
|
-
/* @__PURE__ */ oidNist(1)
|
|
109309
|
-
);
|
|
109310
|
-
init_shim2();
|
|
109311
|
-
var MemoryStore = class {
|
|
109312
|
-
/**
|
|
109313
|
-
* A private field that contains the Map used as the key-value store.
|
|
109314
|
-
*/
|
|
109315
|
-
store = /* @__PURE__ */ new Map();
|
|
109316
|
-
/**
|
|
109317
|
-
* Clears all entries in the key-value store.
|
|
109318
|
-
*
|
|
109319
|
-
* @returns {void} returns once the operation is complete.
|
|
109320
|
-
*/
|
|
109321
|
-
clear() {
|
|
109322
|
-
this.store.clear();
|
|
109323
|
-
}
|
|
109324
|
-
/**
|
|
109325
|
-
* This operation is no-op for `MemoryStore`.
|
|
109326
|
-
*/
|
|
109327
|
-
close() {
|
|
109328
|
-
}
|
|
109329
|
-
/**
|
|
109330
|
-
* Deletes an entry from the key-value store by its key.
|
|
109331
|
-
*
|
|
109332
|
-
* @param {K} id - The key of the entry to delete.
|
|
109333
|
-
* @returns {boolean} a boolean indicating whether the entry was successfully deleted.
|
|
109334
|
-
*/
|
|
109335
|
-
delete(id) {
|
|
109336
|
-
return this.store.delete(id);
|
|
109337
|
-
}
|
|
109338
|
-
/**
|
|
109339
|
-
* Retrieves the value of an entry by its key.
|
|
109340
|
-
*
|
|
109341
|
-
* @param {K} id - The key of the entry to retrieve.
|
|
109342
|
-
* @returns {V | undefined} the value of the entry, or `undefined` if the entry does not exist.
|
|
109343
|
-
*/
|
|
109344
|
-
get(id) {
|
|
109345
|
-
return this.store.get(id);
|
|
109346
|
-
}
|
|
109347
|
-
/**
|
|
109348
|
-
* Checks for the presence of an entry by key.
|
|
109349
|
-
*
|
|
109350
|
-
* @param {K} id - The key to check for the existence of.
|
|
109351
|
-
* @returns {boolean} a boolean indicating whether an element with the specified key exists or not.
|
|
109352
|
-
*/
|
|
109353
|
-
has(id) {
|
|
109354
|
-
return this.store.has(id);
|
|
109355
|
-
}
|
|
109356
|
-
/**
|
|
109357
|
-
* Retrieves all values in the key-value store.
|
|
109358
|
-
|
|
109359
|
-
* @returns {Array<V>} an array of all values in the store.
|
|
109360
|
-
*/
|
|
109361
|
-
list() {
|
|
109362
|
-
return Array.from(this.store.values());
|
|
109363
|
-
}
|
|
109364
|
-
/**
|
|
109365
|
-
* Retrieves all entries in the key-value store.
|
|
109366
|
-
*
|
|
109367
|
-
* @returns {Array<[K, V]>} an array of key-value pairs in the store.
|
|
109368
|
-
*/
|
|
109369
|
-
entries() {
|
|
109370
|
-
return Array.from(this.store.entries());
|
|
109371
|
-
}
|
|
109372
|
-
/**
|
|
109373
|
-
* Sets the value of an entry in the key-value store.
|
|
109374
|
-
*
|
|
109375
|
-
* @param {K} id - The key of the entry to set.
|
|
109376
|
-
* @param {V} key - The new value for the entry.
|
|
109377
|
-
* @returns {void} once operation is complete.
|
|
109378
|
-
*/
|
|
109379
|
-
set(id, key) {
|
|
109380
|
-
this.store.set(id, key);
|
|
109381
|
-
}
|
|
109382
|
-
};
|
|
109383
|
-
var Kms = class _Kms {
|
|
109384
|
-
/**
|
|
109385
|
-
* Singleton instance of the Kms.
|
|
109386
|
-
* @private
|
|
109387
|
-
* @type {KeyManager}
|
|
109388
|
-
*/
|
|
109389
|
-
static #instance;
|
|
109390
|
-
/**
|
|
109391
|
-
* The `store` is a private variable in `KeyManager`. It is a `KeyValueStore` instance used for
|
|
109392
|
-
* storing and managing cryptographic keys. It allows the `KeyManager` class to save,
|
|
109393
|
-
* retrieve, and handle keys efficiently within the local Key Management System (KMS) context.
|
|
109394
|
-
* This variable can be configured to use different storage backends, like in-memory storage or
|
|
109395
|
-
* persistent storage, providing flexibility in key management according to the application's
|
|
109396
|
-
* requirements.
|
|
109397
|
-
* @private
|
|
109398
|
-
* @type {KeyValueStore<KeyIdentifier, KeyBytes>} The key store for managing cryptographic keys.
|
|
109399
|
-
*/
|
|
109400
|
-
#store;
|
|
109401
|
-
/**
|
|
109402
|
-
* The `#activeKeyId` property is a string that points to the currently active key.
|
|
109403
|
-
* It is used to identify the key that will be used for signing and verifying operations.
|
|
109404
|
-
* This property is optional and can be set to a specific key ID when initializing the
|
|
109405
|
-
* `KeyManager` instance. If not set, the key manager will use the default key id.
|
|
109406
|
-
* @private
|
|
109407
|
-
* @type {KeyIdentifier}
|
|
109408
|
-
*/
|
|
109409
|
-
#activeKeyId;
|
|
109410
|
-
/**
|
|
109411
|
-
* Creates an instance of KeyManager.
|
|
109412
|
-
* @param {KeyValueStore<KeyIdentifier, KeyBytes>} store An optional property to specify a custom
|
|
109413
|
-
* `KeyValueStore` instance for key management. If not provided, {@link KeyManager} uses a default `MemoryStore`
|
|
109414
|
-
* instance. This store is responsible for managing cryptographic keys, allowing them to be retrieved, stored, and
|
|
109415
|
-
* managed during cryptographic operations.
|
|
109416
|
-
*/
|
|
109417
|
-
constructor(store52) {
|
|
109418
|
-
this.#store = store52 ?? new MemoryStore();
|
|
109419
|
-
}
|
|
109420
|
-
/**
|
|
109421
|
-
* Gets the ID of the active key.
|
|
109422
|
-
* @returns {KeyIdentifier | undefined} The ID of the active key.
|
|
109423
|
-
*/
|
|
109424
|
-
get activeKeyId() {
|
|
109425
|
-
return this.#activeKeyId;
|
|
109426
|
-
}
|
|
109427
|
-
/**
|
|
109428
|
-
* Gets the key pair associated with the given ID or the active key if no ID is provided.
|
|
109429
|
-
* @param {KeyIdentifier} [id] The ID of the key to get.
|
|
109430
|
-
* @returns {KeyBytes} A promise resolving to the key pair.
|
|
109431
|
-
* @throws {KeyManagerError} If the key is not found or no active key is set.
|
|
109432
|
-
*/
|
|
109433
|
-
#getKeyOrThrow(id) {
|
|
109434
|
-
const keyId2 = id ?? this.#activeKeyId;
|
|
109435
|
-
if (!keyId2) {
|
|
109436
|
-
throw new KeyManagerError("No active key set", "ACTIVE_KEY_URI_NOT_SET");
|
|
109437
|
-
}
|
|
109438
|
-
const _secretKey = this.#store.get(keyId2);
|
|
109439
|
-
if (!_secretKey) {
|
|
109440
|
-
throw new KeyManagerError(`Key not found: ${keyId2}`, "KEY_NOT_FOUND");
|
|
109441
|
-
}
|
|
109442
|
-
const kp = new SchnorrKeyPair2({ secretKey: _secretKey });
|
|
109443
|
-
return kp;
|
|
109444
|
-
}
|
|
109445
|
-
/**
|
|
109446
|
-
* Checks if a key with the given ID exists in the key store.
|
|
109447
|
-
* @param {KeyIdentifier} id The ID of the key to check.
|
|
109448
|
-
* @returns {boolean} A promise resolving to a boolean indicating if the key exists.
|
|
109449
|
-
*/
|
|
109450
|
-
#exists(id) {
|
|
109451
|
-
const key = this.#store.get(id);
|
|
109452
|
-
return !!key;
|
|
109453
|
-
}
|
|
109454
|
-
/**
|
|
109455
|
-
* Removes a key from the key store.
|
|
109456
|
-
* @param {KeyIdentifier} id The key identifier of the key to remove.
|
|
109457
|
-
* @param {{ force?: boolean }} options The options for removing the key.
|
|
109458
|
-
* @param {boolean} [options.force] Whether to force the removal of the key.
|
|
109459
|
-
* @returns {void} A promise that resolves when the key is removed.
|
|
109460
|
-
* @throws {KeyManagerError} If attempting to remove the active key without force.
|
|
109461
|
-
*/
|
|
109462
|
-
removeKey(id, options2 = {}) {
|
|
109463
|
-
if (this.#activeKeyId === id && !options2.force) {
|
|
109464
|
-
throw new KeyManagerError('Cannot remove active key (use "force": true or switch active key)', "ACTIVE_KEY_DELETE");
|
|
109465
|
-
}
|
|
109466
|
-
if (!this.#exists(id)) {
|
|
109467
|
-
throw new KeyManagerError(`Key not found: ${id}`, "KEY_NOT_FOUND");
|
|
109468
|
-
}
|
|
109469
|
-
this.#store.delete(id);
|
|
109470
|
-
if (this.#activeKeyId === id) {
|
|
109471
|
-
this.#activeKeyId = void 0;
|
|
109472
|
-
}
|
|
109473
|
-
}
|
|
109474
|
-
/**
|
|
109475
|
-
* Lists all key identifiers in the key store.
|
|
109476
|
-
* @returns {Promise<KeyIdentifier[]>} A promise that resolves to an array of key identifiers.
|
|
109477
|
-
*/
|
|
109478
|
-
listKeys() {
|
|
109479
|
-
return this.#store.entries().flatMap(([k, _]) => [k]);
|
|
109480
|
-
}
|
|
109481
|
-
/**
|
|
109482
|
-
* Sets the active key to the key associated with the given ID.
|
|
109483
|
-
* @param {KeyIdentifier} id The ID of the key to set as active.
|
|
109484
|
-
* @returns {Promise<void>} A promise that resolves when the active key is set.
|
|
109485
|
-
* @throws {KeyManagerError} If the key is not found.
|
|
109486
|
-
*/
|
|
109487
|
-
setActiveKey(id) {
|
|
109488
|
-
this.#getKeyOrThrow(id);
|
|
109489
|
-
this.#activeKeyId = id;
|
|
109490
|
-
}
|
|
109491
|
-
/**
|
|
109492
|
-
* Gets the public key associated with the given ID or the active key if no ID is provided.
|
|
109493
|
-
* @param {KeyIdentifier} [id] The ID of the key to get the public key for.
|
|
109494
|
-
* @returns {Promise<KeyBytes>} A promise resolving to the public key bytes.
|
|
109495
|
-
*/
|
|
109496
|
-
getPublicKey(id) {
|
|
109497
|
-
const { publicKey: publicKey2 } = this.#getKeyOrThrow(id);
|
|
109498
|
-
return publicKey2.compressed;
|
|
109499
|
-
}
|
|
109500
|
-
/**
|
|
109501
|
-
* Signs the given data using the key associated with the key ID.
|
|
109502
|
-
* @param {Bytes} data The data to sign.
|
|
109503
|
-
* @param {KeyIdentifier} [id] The ID of the key to sign the data with.
|
|
109504
|
-
* @returns {Promise<SignatureBytes>} A promise resolving to the signature of the data.
|
|
109505
|
-
*/
|
|
109506
|
-
sign(data, id) {
|
|
109507
|
-
const { secretKey } = this.#getKeyOrThrow(id);
|
|
109508
|
-
if (!secretKey) {
|
|
109509
|
-
throw new KeyManagerError(`Key ID ${id} is not a signer`, "KEY_NOT_SIGNER");
|
|
109510
|
-
}
|
|
109511
|
-
return secretKey.sign(data);
|
|
109512
|
-
}
|
|
109513
|
-
/**
|
|
109514
|
-
* Verifies a signature using the key associated with the key ID.
|
|
109515
|
-
* @param {KeyIdentifier} id The ID of the key to verify the signature with.
|
|
109516
|
-
* @param {SignatureBytes} signature The signature to verify.
|
|
109517
|
-
* @param {Hex} data The data to verify the signature with.
|
|
109518
|
-
* @returns {Promise<boolean>} A promise resolving to a boolean indicating the verification result.
|
|
109519
|
-
*/
|
|
109520
|
-
verify(signature22, data, id) {
|
|
109521
|
-
const { publicKey: publicKey2 } = this.#getKeyOrThrow(id);
|
|
109522
|
-
return publicKey2.verify(signature22, data);
|
|
109523
|
-
}
|
|
109524
|
-
/**
|
|
109525
|
-
* Imports a key pair into the key store.
|
|
109526
|
-
* @param {SchnorrKeyPair} keyPair The key pair to import.
|
|
109527
|
-
* @param {{ id?: KeyIdentifier; setActive?: boolean }} options The options for importing the key pair.
|
|
109528
|
-
* @param {KeyIdentifier} [options.id] The ID of the key to import (optional).
|
|
109529
|
-
* @param {boolean} [options.setActive] Whether to set the key as active (optional, default: true).
|
|
109530
|
-
* @returns {Promise<KeyIdentifier>} A promise resolving to the ID of the imported key.
|
|
109531
|
-
*/
|
|
109532
|
-
importKey(keyPair, options2 = {}) {
|
|
109533
|
-
if (!keyPair.publicKey) {
|
|
109534
|
-
keyPair.publicKey = keyPair.secretKey.computePublicKey();
|
|
109535
|
-
}
|
|
109536
|
-
const id = options2.id ?? keyPair.publicKey.hex;
|
|
109537
|
-
if (this.#exists(id)) {
|
|
109538
|
-
throw new KeyManagerError(`Key already exists: ${id}`, "KEY_FOUND");
|
|
109539
|
-
}
|
|
109540
|
-
this.#store.set(id, keyPair.secretKey.bytes);
|
|
109541
|
-
const setActive = options2.setActive ?? true;
|
|
109542
|
-
if (setActive) {
|
|
109543
|
-
this.#activeKeyId = id;
|
|
109544
|
-
}
|
|
109545
|
-
return id;
|
|
109546
|
-
}
|
|
109547
|
-
/**
|
|
109548
|
-
* Computes the hash of the given data.
|
|
109549
|
-
* @param {Uint8Array} data The data to hash.
|
|
109550
|
-
* @returns {HashBytes} The hash of the data.
|
|
109551
|
-
*/
|
|
109552
|
-
digest(data) {
|
|
109553
|
-
return sha2565(data);
|
|
109554
|
-
}
|
|
109555
|
-
/**
|
|
109556
|
-
* Generates a new key pair and stores it in the key store.
|
|
109557
|
-
* @returns {KeyIdentifier} The key identifier of the generated key.
|
|
109558
|
-
*/
|
|
109559
|
-
generateKey() {
|
|
109560
|
-
const kp = SchnorrKeyPair2.generate();
|
|
109561
|
-
const id = kp.publicKey.hex;
|
|
109562
|
-
this.#store.set(id, kp.secretKey.bytes);
|
|
109563
|
-
this.#activeKeyId = id;
|
|
109564
|
-
return id;
|
|
109565
|
-
}
|
|
109566
|
-
/**
|
|
109567
|
-
* Initializes a singleton KeyManager instance.
|
|
109568
|
-
* @param {SchnorrKeyPair} keyPair The secret key to import.
|
|
109569
|
-
* @param {string} id The ID to set as the active key.
|
|
109570
|
-
* @returns {void}
|
|
109571
|
-
*/
|
|
109572
|
-
static initialize(keyPair, id) {
|
|
109573
|
-
if (_Kms.#instance) {
|
|
109574
|
-
console.warn("WARNING: Kms global instance is already initialized.");
|
|
109575
|
-
return _Kms.#instance;
|
|
109576
|
-
}
|
|
109577
|
-
if (!keyPair) {
|
|
109578
|
-
console.warn("WARNING: secretKey not provided, generating new SchnorrKeyPair ...");
|
|
109579
|
-
}
|
|
109580
|
-
keyPair ??= SchnorrKeyPair2.generate();
|
|
109581
|
-
_Kms.#instance = new _Kms();
|
|
109582
|
-
_Kms.#instance.importKey(keyPair, { setActive: true, id });
|
|
109583
|
-
_Kms.#instance.#activeKeyId = id;
|
|
109584
|
-
console.info(`Kms initialized with Active Key ID: ${_Kms.#instance.#activeKeyId}`);
|
|
109585
|
-
return _Kms.#instance;
|
|
109586
|
-
}
|
|
109587
|
-
/**
|
|
109588
|
-
* Retrieves a keypair from the key store using the provided key ID.
|
|
109589
|
-
* @public
|
|
109590
|
-
* @param {KeyIdentifier} id The ID of the keypair to retrieve.
|
|
109591
|
-
* @returns {Promise<SchnorrKeyPair | undefined>} The retrieved keypair, or undefined if not found.
|
|
109592
|
-
*/
|
|
109593
|
-
static getKey(id) {
|
|
109594
|
-
if (!_Kms.#instance) {
|
|
109595
|
-
throw new KeyManagerError("Kms instance not initialized", "KMS_NOT_INITIALIZED");
|
|
109596
|
-
}
|
|
109597
|
-
id ??= _Kms.#instance.activeKeyId;
|
|
109598
|
-
return _Kms.#instance.#getKeyOrThrow(id);
|
|
109599
|
-
}
|
|
109600
|
-
};
|
|
109601
|
-
init_shim2();
|
|
109602
109009
|
var Signer = class {
|
|
109603
109010
|
/**
|
|
109604
109011
|
* The key pair used for signing.
|
|
@@ -109632,7 +109039,7 @@ var BTCR2 = (() => {
|
|
|
109632
109039
|
* @param {Bytes} hash The hash to sign.
|
|
109633
109040
|
* @returns {SignatureBytes} The signature of the hash.
|
|
109634
109041
|
*/
|
|
109635
|
-
|
|
109042
|
+
sign(hash4) {
|
|
109636
109043
|
return this.keyPair.secretKey.sign(hash4, { scheme: "ecdsa" });
|
|
109637
109044
|
}
|
|
109638
109045
|
/**
|
|
@@ -109640,7 +109047,7 @@ var BTCR2 = (() => {
|
|
|
109640
109047
|
* @param {Bytes} hash The hash to sign.
|
|
109641
109048
|
* @returns {SignatureBytes} The Schnorr signature of the hash.
|
|
109642
109049
|
*/
|
|
109643
|
-
|
|
109050
|
+
signSchnorr(hash4) {
|
|
109644
109051
|
return this.keyPair.secretKey.sign(hash4);
|
|
109645
109052
|
}
|
|
109646
109053
|
};
|
|
@@ -112310,11 +111717,11 @@ var BTCR2 = (() => {
|
|
|
112310
111717
|
init_shim2();
|
|
112311
111718
|
init_shim2();
|
|
112312
111719
|
init_shim2();
|
|
112313
|
-
function
|
|
111720
|
+
function isBytes6(a3) {
|
|
112314
111721
|
return a3 instanceof Uint8Array || a3 != null && typeof a3 === "object" && a3.constructor.name === "Uint8Array";
|
|
112315
111722
|
}
|
|
112316
111723
|
function bytes4(b22, ...lengths) {
|
|
112317
|
-
if (!
|
|
111724
|
+
if (!isBytes6(b22))
|
|
112318
111725
|
throw new Error("Uint8Array expected");
|
|
112319
111726
|
if (lengths.length > 0 && !lengths.includes(b22.length))
|
|
112320
111727
|
throw new Error(`Uint8Array expected of length ${lengths}, not of length=${b22.length}`);
|
|
@@ -112335,8 +111742,8 @@ var BTCR2 = (() => {
|
|
|
112335
111742
|
init_shim2();
|
|
112336
111743
|
init_shim2();
|
|
112337
111744
|
var crypto5 = typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
112338
|
-
var
|
|
112339
|
-
var
|
|
111745
|
+
var createView6 = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
111746
|
+
var rotr4 = (word2, shift) => word2 << 32 - shift | word2 >>> shift;
|
|
112340
111747
|
var isLE4 = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
112341
111748
|
function utf8ToBytes6(str) {
|
|
112342
111749
|
if (typeof str !== "string")
|
|
@@ -112382,9 +111789,9 @@ var BTCR2 = (() => {
|
|
|
112382
111789
|
view.setUint32(byteOffset + h2, wh, isLE7);
|
|
112383
111790
|
view.setUint32(byteOffset + l2, wl, isLE7);
|
|
112384
111791
|
}
|
|
112385
|
-
var
|
|
112386
|
-
var
|
|
112387
|
-
var
|
|
111792
|
+
var Chi4 = (a3, b22, c2) => a3 & b22 ^ ~a3 & c2;
|
|
111793
|
+
var Maj4 = (a3, b22, c2) => a3 & b22 ^ a3 & c2 ^ b22 & c2;
|
|
111794
|
+
var HashMD22 = class extends Hash4 {
|
|
112388
111795
|
constructor(blockLen, outputLen, padOffset, isLE7) {
|
|
112389
111796
|
super();
|
|
112390
111797
|
this.blockLen = blockLen;
|
|
@@ -112396,7 +111803,7 @@ var BTCR2 = (() => {
|
|
|
112396
111803
|
this.pos = 0;
|
|
112397
111804
|
this.destroyed = false;
|
|
112398
111805
|
this.buffer = new Uint8Array(blockLen);
|
|
112399
|
-
this.view =
|
|
111806
|
+
this.view = createView6(this.buffer);
|
|
112400
111807
|
}
|
|
112401
111808
|
update(data) {
|
|
112402
111809
|
exists4(this);
|
|
@@ -112406,7 +111813,7 @@ var BTCR2 = (() => {
|
|
|
112406
111813
|
for (let pos = 0; pos < len; ) {
|
|
112407
111814
|
const take2 = Math.min(blockLen - this.pos, len - pos);
|
|
112408
111815
|
if (take2 === blockLen) {
|
|
112409
|
-
const dataView2 =
|
|
111816
|
+
const dataView2 = createView6(data);
|
|
112410
111817
|
for (; blockLen <= len - pos; pos += blockLen)
|
|
112411
111818
|
this.process(dataView2, pos);
|
|
112412
111819
|
continue;
|
|
@@ -112439,7 +111846,7 @@ var BTCR2 = (() => {
|
|
|
112439
111846
|
buffer2[i42] = 0;
|
|
112440
111847
|
setBigUint645(view, blockLen - 8, BigInt(this.length * 8), isLE7);
|
|
112441
111848
|
this.process(view, 0);
|
|
112442
|
-
const oview =
|
|
111849
|
+
const oview = createView6(out);
|
|
112443
111850
|
const len = this.outputLen;
|
|
112444
111851
|
if (len % 4)
|
|
112445
111852
|
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
@@ -112470,7 +111877,7 @@ var BTCR2 = (() => {
|
|
|
112470
111877
|
return to;
|
|
112471
111878
|
}
|
|
112472
111879
|
};
|
|
112473
|
-
var
|
|
111880
|
+
var SHA256_K4 = /* @__PURE__ */ new Uint32Array([
|
|
112474
111881
|
1116352408,
|
|
112475
111882
|
1899447441,
|
|
112476
111883
|
3049323471,
|
|
@@ -112536,7 +111943,7 @@ var BTCR2 = (() => {
|
|
|
112536
111943
|
3204031479,
|
|
112537
111944
|
3329325298
|
|
112538
111945
|
]);
|
|
112539
|
-
var
|
|
111946
|
+
var SHA256_IV22 = /* @__PURE__ */ new Uint32Array([
|
|
112540
111947
|
1779033703,
|
|
112541
111948
|
3144134277,
|
|
112542
111949
|
1013904242,
|
|
@@ -112546,18 +111953,18 @@ var BTCR2 = (() => {
|
|
|
112546
111953
|
528734635,
|
|
112547
111954
|
1541459225
|
|
112548
111955
|
]);
|
|
112549
|
-
var
|
|
112550
|
-
var SHA2564 = class extends
|
|
111956
|
+
var SHA256_W4 = /* @__PURE__ */ new Uint32Array(64);
|
|
111957
|
+
var SHA2564 = class extends HashMD22 {
|
|
112551
111958
|
constructor() {
|
|
112552
111959
|
super(64, 32, 8, false);
|
|
112553
|
-
this.A =
|
|
112554
|
-
this.B =
|
|
112555
|
-
this.C =
|
|
112556
|
-
this.D =
|
|
112557
|
-
this.E =
|
|
112558
|
-
this.F =
|
|
112559
|
-
this.G =
|
|
112560
|
-
this.H =
|
|
111960
|
+
this.A = SHA256_IV22[0] | 0;
|
|
111961
|
+
this.B = SHA256_IV22[1] | 0;
|
|
111962
|
+
this.C = SHA256_IV22[2] | 0;
|
|
111963
|
+
this.D = SHA256_IV22[3] | 0;
|
|
111964
|
+
this.E = SHA256_IV22[4] | 0;
|
|
111965
|
+
this.F = SHA256_IV22[5] | 0;
|
|
111966
|
+
this.G = SHA256_IV22[6] | 0;
|
|
111967
|
+
this.H = SHA256_IV22[7] | 0;
|
|
112561
111968
|
}
|
|
112562
111969
|
get() {
|
|
112563
111970
|
const { A, B, C: C2, D, E, F, G: G2, H } = this;
|
|
@@ -112576,20 +111983,20 @@ var BTCR2 = (() => {
|
|
|
112576
111983
|
}
|
|
112577
111984
|
process(view, offset) {
|
|
112578
111985
|
for (let i42 = 0; i42 < 16; i42++, offset += 4)
|
|
112579
|
-
|
|
111986
|
+
SHA256_W4[i42] = view.getUint32(offset, false);
|
|
112580
111987
|
for (let i42 = 16; i42 < 64; i42++) {
|
|
112581
|
-
const W15 =
|
|
112582
|
-
const W2 =
|
|
112583
|
-
const s0 =
|
|
112584
|
-
const s1 =
|
|
112585
|
-
|
|
111988
|
+
const W15 = SHA256_W4[i42 - 15];
|
|
111989
|
+
const W2 = SHA256_W4[i42 - 2];
|
|
111990
|
+
const s0 = rotr4(W15, 7) ^ rotr4(W15, 18) ^ W15 >>> 3;
|
|
111991
|
+
const s1 = rotr4(W2, 17) ^ rotr4(W2, 19) ^ W2 >>> 10;
|
|
111992
|
+
SHA256_W4[i42] = s1 + SHA256_W4[i42 - 7] + s0 + SHA256_W4[i42 - 16] | 0;
|
|
112586
111993
|
}
|
|
112587
111994
|
let { A, B, C: C2, D, E, F, G: G2, H } = this;
|
|
112588
111995
|
for (let i42 = 0; i42 < 64; i42++) {
|
|
112589
|
-
const sigma1 =
|
|
112590
|
-
const T1 = H + sigma1 +
|
|
112591
|
-
const sigma0 =
|
|
112592
|
-
const T2 = sigma0 +
|
|
111996
|
+
const sigma1 = rotr4(E, 6) ^ rotr4(E, 11) ^ rotr4(E, 25);
|
|
111997
|
+
const T1 = H + sigma1 + Chi4(E, F, G2) + SHA256_K4[i42] + SHA256_W4[i42] | 0;
|
|
111998
|
+
const sigma0 = rotr4(A, 2) ^ rotr4(A, 13) ^ rotr4(A, 22);
|
|
111999
|
+
const T2 = sigma0 + Maj4(A, B, C2) | 0;
|
|
112593
112000
|
H = G2;
|
|
112594
112001
|
G2 = F;
|
|
112595
112002
|
F = E;
|
|
@@ -112610,14 +112017,14 @@ var BTCR2 = (() => {
|
|
|
112610
112017
|
this.set(A, B, C2, D, E, F, G2, H);
|
|
112611
112018
|
}
|
|
112612
112019
|
roundClean() {
|
|
112613
|
-
|
|
112020
|
+
SHA256_W4.fill(0);
|
|
112614
112021
|
}
|
|
112615
112022
|
destroy() {
|
|
112616
112023
|
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
112617
112024
|
this.buffer.fill(0);
|
|
112618
112025
|
}
|
|
112619
112026
|
};
|
|
112620
|
-
var
|
|
112027
|
+
var sha2565 = /* @__PURE__ */ wrapConstructor3(() => new SHA2564());
|
|
112621
112028
|
var __awaiter3 = function(thisArg, _arguments, P3, generator) {
|
|
112622
112029
|
function adopt(value3) {
|
|
112623
112030
|
return value3 instanceof P3 ? value3 : new P3(function(resolve) {
|
|
@@ -112667,7 +112074,7 @@ var BTCR2 = (() => {
|
|
|
112667
112074
|
*/
|
|
112668
112075
|
static digest(_a3) {
|
|
112669
112076
|
return __awaiter3(this, arguments, void 0, function* ({ data }) {
|
|
112670
|
-
const hash4 =
|
|
112077
|
+
const hash4 = sha2565(data);
|
|
112671
112078
|
return hash4;
|
|
112672
112079
|
});
|
|
112673
112080
|
}
|
|
@@ -112749,11 +112156,11 @@ var BTCR2 = (() => {
|
|
|
112749
112156
|
if (!Number.isSafeInteger(n3) || n3 < 0)
|
|
112750
112157
|
throw new Error(`Wrong positive integer: ${n3}`);
|
|
112751
112158
|
}
|
|
112752
|
-
function
|
|
112159
|
+
function isBytes7(a3) {
|
|
112753
112160
|
return a3 instanceof Uint8Array || a3 != null && typeof a3 === "object" && a3.constructor.name === "Uint8Array";
|
|
112754
112161
|
}
|
|
112755
112162
|
function bytes5(b22, ...lengths) {
|
|
112756
|
-
if (!
|
|
112163
|
+
if (!isBytes7(b22))
|
|
112757
112164
|
throw new Error("Expected Uint8Array");
|
|
112758
112165
|
if (lengths.length > 0 && !lengths.includes(b22.length))
|
|
112759
112166
|
throw new Error(`Expected Uint8Array of length ${lengths}, not of length=${b22.length}`);
|
|
@@ -112780,11 +112187,11 @@ var BTCR2 = (() => {
|
|
|
112780
112187
|
init_shim2();
|
|
112781
112188
|
init_shim2();
|
|
112782
112189
|
var crypto6 = typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
112783
|
-
function
|
|
112190
|
+
function isBytes8(a3) {
|
|
112784
112191
|
return a3 instanceof Uint8Array || a3 != null && typeof a3 === "object" && a3.constructor.name === "Uint8Array";
|
|
112785
112192
|
}
|
|
112786
|
-
var
|
|
112787
|
-
var
|
|
112193
|
+
var createView7 = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
112194
|
+
var rotr5 = (word2, shift) => word2 << 32 - shift | word2 >>> shift;
|
|
112788
112195
|
var isLE5 = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
112789
112196
|
if (!isLE5)
|
|
112790
112197
|
throw new Error("Non little-endian hardware is not supported");
|
|
@@ -112796,7 +112203,7 @@ var BTCR2 = (() => {
|
|
|
112796
112203
|
function toBytes6(data) {
|
|
112797
112204
|
if (typeof data === "string")
|
|
112798
112205
|
data = utf8ToBytes7(data);
|
|
112799
|
-
if (!
|
|
112206
|
+
if (!isBytes8(data))
|
|
112800
112207
|
throw new Error(`expected Uint8Array, got ${typeof data}`);
|
|
112801
112208
|
return data;
|
|
112802
112209
|
}
|
|
@@ -112804,7 +112211,7 @@ var BTCR2 = (() => {
|
|
|
112804
112211
|
let sum = 0;
|
|
112805
112212
|
for (let i42 = 0; i42 < arrays.length; i42++) {
|
|
112806
112213
|
const a3 = arrays[i42];
|
|
112807
|
-
if (!
|
|
112214
|
+
if (!isBytes8(a3))
|
|
112808
112215
|
throw new Error("Uint8Array expected");
|
|
112809
112216
|
sum += a3.length;
|
|
112810
112217
|
}
|
|
@@ -112861,7 +112268,7 @@ var BTCR2 = (() => {
|
|
|
112861
112268
|
this.pos = 0;
|
|
112862
112269
|
this.destroyed = false;
|
|
112863
112270
|
this.buffer = new Uint8Array(blockLen);
|
|
112864
|
-
this.view =
|
|
112271
|
+
this.view = createView7(this.buffer);
|
|
112865
112272
|
}
|
|
112866
112273
|
update(data) {
|
|
112867
112274
|
exists5(this);
|
|
@@ -112871,7 +112278,7 @@ var BTCR2 = (() => {
|
|
|
112871
112278
|
for (let pos = 0; pos < len; ) {
|
|
112872
112279
|
const take2 = Math.min(blockLen - this.pos, len - pos);
|
|
112873
112280
|
if (take2 === blockLen) {
|
|
112874
|
-
const dataView2 =
|
|
112281
|
+
const dataView2 = createView7(data);
|
|
112875
112282
|
for (; blockLen <= len - pos; pos += blockLen)
|
|
112876
112283
|
this.process(dataView2, pos);
|
|
112877
112284
|
continue;
|
|
@@ -112904,7 +112311,7 @@ var BTCR2 = (() => {
|
|
|
112904
112311
|
buffer2[i42] = 0;
|
|
112905
112312
|
setBigUint646(view, blockLen - 8, BigInt(this.length * 8), isLE7);
|
|
112906
112313
|
this.process(view, 0);
|
|
112907
|
-
const oview =
|
|
112314
|
+
const oview = createView7(out);
|
|
112908
112315
|
const len = this.outputLen;
|
|
112909
112316
|
if (len % 4)
|
|
112910
112317
|
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
@@ -112935,9 +112342,9 @@ var BTCR2 = (() => {
|
|
|
112935
112342
|
return to;
|
|
112936
112343
|
}
|
|
112937
112344
|
};
|
|
112938
|
-
var
|
|
112939
|
-
var
|
|
112940
|
-
var
|
|
112345
|
+
var Chi5 = (a3, b22, c2) => a3 & b22 ^ ~a3 & c2;
|
|
112346
|
+
var Maj5 = (a3, b22, c2) => a3 & b22 ^ a3 & c2 ^ b22 & c2;
|
|
112347
|
+
var SHA256_K5 = /* @__PURE__ */ new Uint32Array([
|
|
112941
112348
|
1116352408,
|
|
112942
112349
|
1899447441,
|
|
112943
112350
|
3049323471,
|
|
@@ -113013,7 +112420,7 @@ var BTCR2 = (() => {
|
|
|
113013
112420
|
528734635,
|
|
113014
112421
|
1541459225
|
|
113015
112422
|
]);
|
|
113016
|
-
var
|
|
112423
|
+
var SHA256_W5 = /* @__PURE__ */ new Uint32Array(64);
|
|
113017
112424
|
var SHA2565 = class extends SHA23 {
|
|
113018
112425
|
constructor() {
|
|
113019
112426
|
super(64, 32, 8, false);
|
|
@@ -113043,20 +112450,20 @@ var BTCR2 = (() => {
|
|
|
113043
112450
|
}
|
|
113044
112451
|
process(view, offset) {
|
|
113045
112452
|
for (let i42 = 0; i42 < 16; i42++, offset += 4)
|
|
113046
|
-
|
|
112453
|
+
SHA256_W5[i42] = view.getUint32(offset, false);
|
|
113047
112454
|
for (let i42 = 16; i42 < 64; i42++) {
|
|
113048
|
-
const W15 =
|
|
113049
|
-
const W2 =
|
|
113050
|
-
const s0 =
|
|
113051
|
-
const s1 =
|
|
113052
|
-
|
|
112455
|
+
const W15 = SHA256_W5[i42 - 15];
|
|
112456
|
+
const W2 = SHA256_W5[i42 - 2];
|
|
112457
|
+
const s0 = rotr5(W15, 7) ^ rotr5(W15, 18) ^ W15 >>> 3;
|
|
112458
|
+
const s1 = rotr5(W2, 17) ^ rotr5(W2, 19) ^ W2 >>> 10;
|
|
112459
|
+
SHA256_W5[i42] = s1 + SHA256_W5[i42 - 7] + s0 + SHA256_W5[i42 - 16] | 0;
|
|
113053
112460
|
}
|
|
113054
112461
|
let { A, B, C: C2, D, E, F, G: G2, H } = this;
|
|
113055
112462
|
for (let i42 = 0; i42 < 64; i42++) {
|
|
113056
|
-
const sigma1 =
|
|
113057
|
-
const T1 = H + sigma1 +
|
|
113058
|
-
const sigma0 =
|
|
113059
|
-
const T2 = sigma0 +
|
|
112463
|
+
const sigma1 = rotr5(E, 6) ^ rotr5(E, 11) ^ rotr5(E, 25);
|
|
112464
|
+
const T1 = H + sigma1 + Chi5(E, F, G2) + SHA256_K5[i42] + SHA256_W5[i42] | 0;
|
|
112465
|
+
const sigma0 = rotr5(A, 2) ^ rotr5(A, 13) ^ rotr5(A, 22);
|
|
112466
|
+
const T2 = sigma0 + Maj5(A, B, C2) | 0;
|
|
113060
112467
|
H = G2;
|
|
113061
112468
|
G2 = F;
|
|
113062
112469
|
F = E;
|
|
@@ -113077,14 +112484,14 @@ var BTCR2 = (() => {
|
|
|
113077
112484
|
this.set(A, B, C2, D, E, F, G2, H);
|
|
113078
112485
|
}
|
|
113079
112486
|
roundClean() {
|
|
113080
|
-
|
|
112487
|
+
SHA256_W5.fill(0);
|
|
113081
112488
|
}
|
|
113082
112489
|
destroy() {
|
|
113083
112490
|
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
113084
112491
|
this.buffer.fill(0);
|
|
113085
112492
|
}
|
|
113086
112493
|
};
|
|
113087
|
-
var
|
|
112494
|
+
var sha2566 = /* @__PURE__ */ wrapConstructor4(() => new SHA2565());
|
|
113088
112495
|
init_shim2();
|
|
113089
112496
|
var utils_exports4 = {};
|
|
113090
112497
|
__export2(utils_exports4, {
|
|
@@ -113101,7 +112508,7 @@ var BTCR2 = (() => {
|
|
|
113101
112508
|
equalBytes: () => equalBytes7,
|
|
113102
112509
|
hexToBytes: () => hexToBytes4,
|
|
113103
112510
|
hexToNumber: () => hexToNumber3,
|
|
113104
|
-
isBytes: () =>
|
|
112511
|
+
isBytes: () => isBytes9,
|
|
113105
112512
|
numberToBytesBE: () => numberToBytesBE4,
|
|
113106
112513
|
numberToBytesLE: () => numberToBytesLE3,
|
|
113107
112514
|
numberToHexUnpadded: () => numberToHexUnpadded3,
|
|
@@ -113113,12 +112520,12 @@ var BTCR2 = (() => {
|
|
|
113113
112520
|
var _0n11 = BigInt(0);
|
|
113114
112521
|
var _1n11 = BigInt(1);
|
|
113115
112522
|
var _2n8 = BigInt(2);
|
|
113116
|
-
function
|
|
112523
|
+
function isBytes9(a3) {
|
|
113117
112524
|
return a3 instanceof Uint8Array || a3 != null && typeof a3 === "object" && a3.constructor.name === "Uint8Array";
|
|
113118
112525
|
}
|
|
113119
112526
|
var hexes4 = /* @__PURE__ */ Array.from({ length: 256 }, (_, i42) => i42.toString(16).padStart(2, "0"));
|
|
113120
112527
|
function bytesToHex4(bytes6) {
|
|
113121
|
-
if (!
|
|
112528
|
+
if (!isBytes9(bytes6))
|
|
113122
112529
|
throw new Error("Uint8Array expected");
|
|
113123
112530
|
let hex3 = "";
|
|
113124
112531
|
for (let i42 = 0; i42 < bytes6.length; i42++) {
|
|
@@ -113168,7 +112575,7 @@ var BTCR2 = (() => {
|
|
|
113168
112575
|
return hexToNumber3(bytesToHex4(bytes6));
|
|
113169
112576
|
}
|
|
113170
112577
|
function bytesToNumberLE3(bytes6) {
|
|
113171
|
-
if (!
|
|
112578
|
+
if (!isBytes9(bytes6))
|
|
113172
112579
|
throw new Error("Uint8Array expected");
|
|
113173
112580
|
return hexToNumber3(bytesToHex4(Uint8Array.from(bytes6).reverse()));
|
|
113174
112581
|
}
|
|
@@ -113189,7 +112596,7 @@ var BTCR2 = (() => {
|
|
|
113189
112596
|
} catch (e2) {
|
|
113190
112597
|
throw new Error(`${title} must be valid hex string, got "${hex3}". Cause: ${e2}`);
|
|
113191
112598
|
}
|
|
113192
|
-
} else if (
|
|
112599
|
+
} else if (isBytes9(hex3)) {
|
|
113193
112600
|
res = Uint8Array.from(hex3);
|
|
113194
112601
|
} else {
|
|
113195
112602
|
throw new Error(`${title} must be hex string or Uint8Array`);
|
|
@@ -113203,7 +112610,7 @@ var BTCR2 = (() => {
|
|
|
113203
112610
|
let sum = 0;
|
|
113204
112611
|
for (let i42 = 0; i42 < arrays.length; i42++) {
|
|
113205
112612
|
const a3 = arrays[i42];
|
|
113206
|
-
if (!
|
|
112613
|
+
if (!isBytes9(a3))
|
|
113207
112614
|
throw new Error("Uint8Array expected");
|
|
113208
112615
|
sum += a3.length;
|
|
113209
112616
|
}
|
|
@@ -113297,7 +112704,7 @@ var BTCR2 = (() => {
|
|
|
113297
112704
|
function: (val) => typeof val === "function",
|
|
113298
112705
|
boolean: (val) => typeof val === "boolean",
|
|
113299
112706
|
string: (val) => typeof val === "string",
|
|
113300
|
-
stringOrUint8Array: (val) => typeof val === "string" ||
|
|
112707
|
+
stringOrUint8Array: (val) => typeof val === "string" || isBytes9(val),
|
|
113301
112708
|
isSafeInteger: (val) => Number.isSafeInteger(val),
|
|
113302
112709
|
array: (val) => Array.isArray(val),
|
|
113303
112710
|
field: (val, object22) => object22.Fp.isValid(val),
|
|
@@ -113760,7 +113167,7 @@ var BTCR2 = (() => {
|
|
|
113760
113167
|
toSig(hex3) {
|
|
113761
113168
|
const { Err: E } = DER3;
|
|
113762
113169
|
const data = typeof hex3 === "string" ? h2b2(hex3) : hex3;
|
|
113763
|
-
if (!
|
|
113170
|
+
if (!isBytes9(data))
|
|
113764
113171
|
throw new Error("ui8a expected");
|
|
113765
113172
|
let l2 = data.length;
|
|
113766
113173
|
if (l2 < 2 || data[0] != 48)
|
|
@@ -113824,7 +113231,7 @@ var BTCR2 = (() => {
|
|
|
113824
113231
|
function normPrivateKeyToScalar(key) {
|
|
113825
113232
|
const { allowedPrivateKeyLengths: lengths, nByteLength, wrapPrivateKey, n: n3 } = CURVE22;
|
|
113826
113233
|
if (lengths && typeof key !== "bigint") {
|
|
113827
|
-
if (
|
|
113234
|
+
if (isBytes9(key))
|
|
113828
113235
|
key = bytesToHex4(key);
|
|
113829
113236
|
if (typeof key !== "string" || !lengths.includes(key.length))
|
|
113830
113237
|
throw new Error("Invalid key");
|
|
@@ -114359,7 +113766,7 @@ var BTCR2 = (() => {
|
|
|
114359
113766
|
return Point7.fromPrivateKey(privateKey).toRawBytes(isCompressed);
|
|
114360
113767
|
}
|
|
114361
113768
|
function isProbPub(item) {
|
|
114362
|
-
const arr =
|
|
113769
|
+
const arr = isBytes9(item);
|
|
114363
113770
|
const str = typeof item === "string";
|
|
114364
113771
|
const len = (arr || str) && item.length;
|
|
114365
113772
|
if (arr)
|
|
@@ -114454,7 +113861,7 @@ var BTCR2 = (() => {
|
|
|
114454
113861
|
let _sig = void 0;
|
|
114455
113862
|
let P3;
|
|
114456
113863
|
try {
|
|
114457
|
-
if (typeof sg === "string" ||
|
|
113864
|
+
if (typeof sg === "string" || isBytes9(sg)) {
|
|
114458
113865
|
try {
|
|
114459
113866
|
_sig = Signature.fromDER(sg);
|
|
114460
113867
|
} catch (derError) {
|
|
@@ -114651,7 +114058,7 @@ var BTCR2 = (() => {
|
|
|
114651
114058
|
return { k1neg, k1, k2neg, k2 };
|
|
114652
114059
|
}
|
|
114653
114060
|
}
|
|
114654
|
-
},
|
|
114061
|
+
}, sha2566);
|
|
114655
114062
|
var _0n15 = BigInt(0);
|
|
114656
114063
|
var Point5 = secp256k13.ProjectivePoint;
|
|
114657
114064
|
init_shim2();
|
|
@@ -115328,7 +114735,7 @@ var BTCR2 = (() => {
|
|
|
115328
114735
|
static sign(_a3) {
|
|
115329
114736
|
return __awaiter6(this, arguments, void 0, function* ({ data, key }) {
|
|
115330
114737
|
const privateKeyBytes = yield _Secp256k1.privateKeyToBytes({ privateKey: key });
|
|
115331
|
-
const digest2 =
|
|
114738
|
+
const digest2 = sha2565(data);
|
|
115332
114739
|
const signatureObject = secp256k13.sign(digest2, privateKeyBytes);
|
|
115333
114740
|
const signature22 = signatureObject.toCompactRawBytes();
|
|
115334
114741
|
return signature22;
|
|
@@ -115440,7 +114847,7 @@ var BTCR2 = (() => {
|
|
|
115440
114847
|
static verify(_a3) {
|
|
115441
114848
|
return __awaiter6(this, arguments, void 0, function* ({ key, signature: signature22, data }) {
|
|
115442
114849
|
const publicKeyBytes = yield _Secp256k1.publicKeyToBytes({ publicKey: key });
|
|
115443
|
-
const digest2 =
|
|
114850
|
+
const digest2 = sha2565(data);
|
|
115444
114851
|
const isValid2 = secp256k13.verify(signature22, digest2, publicKeyBytes, { lowS: false });
|
|
115445
114852
|
return isValid2;
|
|
115446
114853
|
});
|
|
@@ -115508,7 +114915,7 @@ var BTCR2 = (() => {
|
|
|
115508
114915
|
Gy: BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),
|
|
115509
114916
|
h: BigInt(1),
|
|
115510
114917
|
lowS: false
|
|
115511
|
-
},
|
|
114918
|
+
}, sha2566);
|
|
115512
114919
|
var secp256r1 = p256;
|
|
115513
114920
|
var __awaiter7 = function(thisArg, _arguments, P3, generator) {
|
|
115514
114921
|
function adopt(value3) {
|
|
@@ -116049,7 +115456,7 @@ var BTCR2 = (() => {
|
|
|
116049
115456
|
static sign(_a3) {
|
|
116050
115457
|
return __awaiter7(this, arguments, void 0, function* ({ data, key }) {
|
|
116051
115458
|
const privateKeyBytes = yield _Secp256r1.privateKeyToBytes({ privateKey: key });
|
|
116052
|
-
const digest2 =
|
|
115459
|
+
const digest2 = sha2565(data);
|
|
116053
115460
|
const signatureObject = secp256r1.sign(digest2, privateKeyBytes);
|
|
116054
115461
|
const signature22 = signatureObject.toCompactRawBytes();
|
|
116055
115462
|
return signature22;
|
|
@@ -116161,7 +115568,7 @@ var BTCR2 = (() => {
|
|
|
116161
115568
|
static verify(_a3) {
|
|
116162
115569
|
return __awaiter7(this, arguments, void 0, function* ({ key, signature: signature22, data }) {
|
|
116163
115570
|
const publicKeyBytes = yield _Secp256r1.publicKeyToBytes({ publicKey: key });
|
|
116164
|
-
const digest2 =
|
|
115571
|
+
const digest2 = sha2565(data);
|
|
116165
115572
|
const isValid2 = secp256r1.verify(signature22, digest2, publicKeyBytes, { lowS: false });
|
|
116166
115573
|
return isValid2;
|
|
116167
115574
|
});
|
|
@@ -123180,7 +122587,7 @@ var BTCR2 = (() => {
|
|
|
123180
122587
|
*/
|
|
123181
122588
|
async (data) => new Uint8Array(await crypto.subtle.digest(name10, data))
|
|
123182
122589
|
);
|
|
123183
|
-
var
|
|
122590
|
+
var sha2567 = from5({
|
|
123184
122591
|
name: "sha2-256",
|
|
123185
122592
|
code: 18,
|
|
123186
122593
|
encode: sha("SHA-256")
|
|
@@ -123228,7 +122635,7 @@ var BTCR2 = (() => {
|
|
|
123228
122635
|
let multihash;
|
|
123229
122636
|
switch (hashAlgorithmInMultihashCode) {
|
|
123230
122637
|
case 18:
|
|
123231
|
-
let hasher = yield
|
|
122638
|
+
let hasher = yield sha2567.digest(content);
|
|
123232
122639
|
multihash = hasher.bytes;
|
|
123233
122640
|
break;
|
|
123234
122641
|
default:
|
|
@@ -123247,7 +122654,7 @@ var BTCR2 = (() => {
|
|
|
123247
122654
|
let hash4;
|
|
123248
122655
|
switch (hashAlgorithmInMultihashCode) {
|
|
123249
122656
|
case 18:
|
|
123250
|
-
hash4 = yield
|
|
122657
|
+
hash4 = yield sha2567.encode(content);
|
|
123251
122658
|
break;
|
|
123252
122659
|
default:
|
|
123253
122660
|
throw new IonError(ErrorCode_default.MultihashUnsupportedHashAlgorithm, `Hash algorithm defined in multihash code ${hashAlgorithmInMultihashCode} is not supported.`);
|
|
@@ -123658,12 +123065,12 @@ var BTCR2 = (() => {
|
|
|
123658
123065
|
};
|
|
123659
123066
|
var isBig = (n3) => typeof n3 === "bigint";
|
|
123660
123067
|
var isStr = (s2) => typeof s2 === "string";
|
|
123661
|
-
var
|
|
123662
|
-
var
|
|
123068
|
+
var isBytes10 = (a3) => a3 instanceof Uint8Array || ArrayBuffer.isView(a3) && a3.constructor.name === "Uint8Array";
|
|
123069
|
+
var abytes3 = (a3, l2) => !isBytes10(a3) || typeof l2 === "number" && l2 > 0 && a3.length !== l2 ? err("Uint8Array expected") : a3;
|
|
123663
123070
|
var u8n3 = (len) => new Uint8Array(len);
|
|
123664
123071
|
var u8fr3 = (buf2) => Uint8Array.from(buf2);
|
|
123665
123072
|
var padh = (n3, pad2) => n3.toString(16).padStart(pad2, "0");
|
|
123666
|
-
var bytesToHex5 = (b22) => Array.from(
|
|
123073
|
+
var bytesToHex5 = (b22) => Array.from(abytes3(b22)).map((e2) => padh(e2, 2)).join("");
|
|
123667
123074
|
var C = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
123668
123075
|
var _ch = (ch) => {
|
|
123669
123076
|
if (ch >= C._0 && ch <= C._9)
|
|
@@ -123692,9 +123099,9 @@ var BTCR2 = (() => {
|
|
|
123692
123099
|
}
|
|
123693
123100
|
return array22;
|
|
123694
123101
|
};
|
|
123695
|
-
var toU8 = (a3, len) =>
|
|
123102
|
+
var toU8 = (a3, len) => abytes3(isStr(a3) ? hexToBytes5(a3) : u8fr3(abytes3(a3)), len);
|
|
123696
123103
|
var concatBytes10 = (...arrs) => {
|
|
123697
|
-
const r2 = u8n3(arrs.reduce((sum, a3) => sum +
|
|
123104
|
+
const r2 = u8n3(arrs.reduce((sum, a3) => sum + abytes3(a3).length, 0));
|
|
123698
123105
|
let pad2 = 0;
|
|
123699
123106
|
arrs.forEach((a3) => {
|
|
123700
123107
|
r2.set(a3, pad2);
|
|
@@ -123751,7 +123158,7 @@ var BTCR2 = (() => {
|
|
|
123751
123158
|
}
|
|
123752
123159
|
/** Convert Uint8Array or hex string to Point. */
|
|
123753
123160
|
static fromBytes(bytes6) {
|
|
123754
|
-
|
|
123161
|
+
abytes3(bytes6);
|
|
123755
123162
|
let p3 = void 0;
|
|
123756
123163
|
const head = bytes6[0];
|
|
123757
123164
|
const tail = bytes6.subarray(1);
|
|
@@ -125851,7 +125258,7 @@ var BTCR2 = (() => {
|
|
|
125851
125258
|
}
|
|
125852
125259
|
var sha2_browser_exports = {};
|
|
125853
125260
|
__export2(sha2_browser_exports, {
|
|
125854
|
-
sha256: () =>
|
|
125261
|
+
sha256: () => sha2568,
|
|
125855
125262
|
sha512: () => sha5124
|
|
125856
125263
|
});
|
|
125857
125264
|
init_shim2();
|
|
@@ -125905,7 +125312,7 @@ var BTCR2 = (() => {
|
|
|
125905
125312
|
function sha2(name10) {
|
|
125906
125313
|
return async (data) => new Uint8Array(await crypto.subtle.digest(name10, data));
|
|
125907
125314
|
}
|
|
125908
|
-
var
|
|
125315
|
+
var sha2568 = from6({
|
|
125909
125316
|
name: "sha2-256",
|
|
125910
125317
|
code: 18,
|
|
125911
125318
|
encode: sha2("SHA-256")
|
|
@@ -126174,7 +125581,7 @@ var BTCR2 = (() => {
|
|
|
126174
125581
|
}
|
|
126175
125582
|
async add(string4, options2 = {}) {
|
|
126176
125583
|
const buf2 = fromString2(string4);
|
|
126177
|
-
const hash4 = await (options2.hasher ??
|
|
125584
|
+
const hash4 = await (options2.hasher ?? sha2568).digest(buf2);
|
|
126178
125585
|
const codec2 = options2.codec ?? raw_exports;
|
|
126179
125586
|
const cid = CID2.createV1(codec2.code, hash4);
|
|
126180
125587
|
await this.components.blockstore.put(cid, buf2, options2);
|
|
@@ -130069,7 +129476,7 @@ var BTCR2 = (() => {
|
|
|
130069
129476
|
* @param {string | Uint8Array} s
|
|
130070
129477
|
* @param {boolean} [clean]
|
|
130071
129478
|
*/
|
|
130072
|
-
constructor(s2,
|
|
129479
|
+
constructor(s2, clean3) {
|
|
130073
129480
|
if (typeof s2 === "string") {
|
|
130074
129481
|
this._buf = fromString2(s2);
|
|
130075
129482
|
} else if (s2 instanceof Uint8Array) {
|
|
@@ -130077,10 +129484,10 @@ var BTCR2 = (() => {
|
|
|
130077
129484
|
} else {
|
|
130078
129485
|
throw new Error("Invalid key, should be String of Uint8Array");
|
|
130079
129486
|
}
|
|
130080
|
-
if (
|
|
130081
|
-
|
|
129487
|
+
if (clean3 == null) {
|
|
129488
|
+
clean3 = true;
|
|
130082
129489
|
}
|
|
130083
|
-
if (
|
|
129490
|
+
if (clean3) {
|
|
130084
129491
|
this.clean();
|
|
130085
129492
|
}
|
|
130086
129493
|
if (this._buf.byteLength === 0 || this._buf[0] !== pathSep) {
|
|
@@ -133498,7 +132905,7 @@ var BTCR2 = (() => {
|
|
|
133498
132905
|
init_shim2();
|
|
133499
132906
|
function getHasher(initialHashers = [], loadHasher) {
|
|
133500
132907
|
const hashers = {
|
|
133501
|
-
[
|
|
132908
|
+
[sha2568.code]: sha2568,
|
|
133502
132909
|
[sha5124.code]: sha5124,
|
|
133503
132910
|
[identity2.code]: identity2
|
|
133504
132911
|
};
|
|
@@ -137830,7 +137237,7 @@ var BTCR2 = (() => {
|
|
|
137830
137237
|
init_shim2();
|
|
137831
137238
|
var PRIVATE_KEY_BYTE_LENGTH2 = 32;
|
|
137832
137239
|
function hashAndSign4(key, msg, options2) {
|
|
137833
|
-
const p3 =
|
|
137240
|
+
const p3 = sha2568.digest(msg instanceof Uint8Array ? msg : msg.subarray());
|
|
137834
137241
|
if (isPromise3(p3)) {
|
|
137835
137242
|
return p3.then(({ digest: digest2 }) => {
|
|
137836
137243
|
options2?.signal?.throwIfAborted();
|
|
@@ -137849,7 +137256,7 @@ var BTCR2 = (() => {
|
|
|
137849
137256
|
}
|
|
137850
137257
|
}
|
|
137851
137258
|
function hashAndVerify4(key, sig, msg, options2) {
|
|
137852
|
-
const p3 =
|
|
137259
|
+
const p3 = sha2568.digest(msg instanceof Uint8Array ? msg : msg.subarray());
|
|
137853
137260
|
if (isPromise3(p3)) {
|
|
137854
137261
|
return p3.then(({ digest: digest2 }) => {
|
|
137855
137262
|
options2?.signal?.throwIfAborted();
|
|
@@ -140056,7 +139463,7 @@ var BTCR2 = (() => {
|
|
|
140056
139463
|
return multihash.code === identity2.code;
|
|
140057
139464
|
}
|
|
140058
139465
|
function isSha256Multihash(multihash) {
|
|
140059
|
-
return multihash.code ===
|
|
139466
|
+
return multihash.code === sha2568.code;
|
|
140060
139467
|
}
|
|
140061
139468
|
function mapIterable(iter, map3) {
|
|
140062
139469
|
const iterator = {
|
|
@@ -140878,7 +140285,7 @@ var BTCR2 = (() => {
|
|
|
140878
140285
|
const cidVersion = values[0];
|
|
140879
140286
|
const multicodec2 = values[1];
|
|
140880
140287
|
const hashAlg = values[2];
|
|
140881
|
-
const hasher = hashAlg ===
|
|
140288
|
+
const hasher = hashAlg === sha2568.code ? sha2568 : await this.hashLoader?.getHasher(hashAlg);
|
|
140882
140289
|
if (hasher == null) {
|
|
140883
140290
|
this.log.error("unknown hash algorithm", hashAlg);
|
|
140884
140291
|
continue;
|
|
@@ -154742,7 +154149,7 @@ ${values.join("\n")}` : `${blockName} :`;
|
|
|
154742
154149
|
}
|
|
154743
154150
|
async function keyId(key) {
|
|
154744
154151
|
const pb = privateKeyToProtobuf(key);
|
|
154745
|
-
const hash4 = await
|
|
154152
|
+
const hash4 = await sha2568.digest(pb);
|
|
154746
154153
|
return base58btc2.encode(hash4.bytes).substring(1);
|
|
154747
154154
|
}
|
|
154748
154155
|
var Keychain = class {
|
|
@@ -155067,7 +154474,7 @@ ${values.join("\n")}` : `${blockName} :`;
|
|
|
155067
154474
|
init_shim2();
|
|
155068
154475
|
init_shim2();
|
|
155069
154476
|
init_shim2();
|
|
155070
|
-
function
|
|
154477
|
+
function isBytes11(a3) {
|
|
155071
154478
|
return a3 instanceof Uint8Array || ArrayBuffer.isView(a3) && a3.constructor.name === "Uint8Array";
|
|
155072
154479
|
}
|
|
155073
154480
|
function abool2(b22) {
|
|
@@ -155078,20 +154485,20 @@ ${values.join("\n")}` : `${blockName} :`;
|
|
|
155078
154485
|
if (!Number.isSafeInteger(n3) || n3 < 0)
|
|
155079
154486
|
throw new Error("positive integer expected, got " + n3);
|
|
155080
154487
|
}
|
|
155081
|
-
function
|
|
155082
|
-
if (!
|
|
154488
|
+
function abytes4(b22, ...lengths) {
|
|
154489
|
+
if (!isBytes11(b22))
|
|
155083
154490
|
throw new Error("Uint8Array expected");
|
|
155084
154491
|
if (lengths.length > 0 && !lengths.includes(b22.length))
|
|
155085
154492
|
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b22.length);
|
|
155086
154493
|
}
|
|
155087
|
-
function
|
|
154494
|
+
function aexists22(instance3, checkFinished = true) {
|
|
155088
154495
|
if (instance3.destroyed)
|
|
155089
154496
|
throw new Error("Hash instance has been destroyed");
|
|
155090
154497
|
if (checkFinished && instance3.finished)
|
|
155091
154498
|
throw new Error("Hash#digest() has already been called");
|
|
155092
154499
|
}
|
|
155093
|
-
function
|
|
155094
|
-
|
|
154500
|
+
function aoutput22(out, instance3) {
|
|
154501
|
+
abytes4(out);
|
|
155095
154502
|
const min = instance3.outputLen;
|
|
155096
154503
|
if (out.length < min) {
|
|
155097
154504
|
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
@@ -155100,12 +154507,12 @@ ${values.join("\n")}` : `${blockName} :`;
|
|
|
155100
154507
|
function u322(arr) {
|
|
155101
154508
|
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
155102
154509
|
}
|
|
155103
|
-
function
|
|
154510
|
+
function clean22(...arrays) {
|
|
155104
154511
|
for (let i42 = 0; i42 < arrays.length; i42++) {
|
|
155105
154512
|
arrays[i42].fill(0);
|
|
155106
154513
|
}
|
|
155107
154514
|
}
|
|
155108
|
-
function
|
|
154515
|
+
function createView8(arr) {
|
|
155109
154516
|
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
155110
154517
|
}
|
|
155111
154518
|
var isLE6 = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
@@ -155117,7 +154524,7 @@ ${values.join("\n")}` : `${blockName} :`;
|
|
|
155117
154524
|
function toBytes7(data) {
|
|
155118
154525
|
if (typeof data === "string")
|
|
155119
154526
|
data = utf8ToBytes10(data);
|
|
155120
|
-
else if (
|
|
154527
|
+
else if (isBytes11(data))
|
|
155121
154528
|
data = copyBytes2(data);
|
|
155122
154529
|
else
|
|
155123
154530
|
throw new Error("Uint8Array expected, got " + typeof data);
|
|
@@ -155139,7 +154546,7 @@ ${values.join("\n")}` : `${blockName} :`;
|
|
|
155139
154546
|
}
|
|
155140
154547
|
var wrapCipher2 = /* @__NO_SIDE_EFFECTS__ */ (params, constructor) => {
|
|
155141
154548
|
function wrappedCipher(key, ...args) {
|
|
155142
|
-
|
|
154549
|
+
abytes4(key);
|
|
155143
154550
|
if (!isLE6)
|
|
155144
154551
|
throw new Error("Non little-endian hardware is not yet supported");
|
|
155145
154552
|
if (params.nonceLength !== void 0) {
|
|
@@ -155147,20 +154554,20 @@ ${values.join("\n")}` : `${blockName} :`;
|
|
|
155147
154554
|
if (!nonce)
|
|
155148
154555
|
throw new Error("nonce / iv required");
|
|
155149
154556
|
if (params.varSizeNonce)
|
|
155150
|
-
|
|
154557
|
+
abytes4(nonce);
|
|
155151
154558
|
else
|
|
155152
|
-
|
|
154559
|
+
abytes4(nonce, params.nonceLength);
|
|
155153
154560
|
}
|
|
155154
154561
|
const tagl = params.tagLength;
|
|
155155
154562
|
if (tagl && args[1] !== void 0) {
|
|
155156
|
-
|
|
154563
|
+
abytes4(args[1]);
|
|
155157
154564
|
}
|
|
155158
154565
|
const cipher = constructor(key, ...args);
|
|
155159
154566
|
const checkOutput = (fnLength, output6) => {
|
|
155160
154567
|
if (output6 !== void 0) {
|
|
155161
154568
|
if (fnLength !== 2)
|
|
155162
154569
|
throw new Error("cipher output not supported");
|
|
155163
|
-
|
|
154570
|
+
abytes4(output6);
|
|
155164
154571
|
}
|
|
155165
154572
|
};
|
|
155166
154573
|
let called = false;
|
|
@@ -155169,12 +154576,12 @@ ${values.join("\n")}` : `${blockName} :`;
|
|
|
155169
154576
|
if (called)
|
|
155170
154577
|
throw new Error("cannot encrypt() twice with same key + nonce");
|
|
155171
154578
|
called = true;
|
|
155172
|
-
|
|
154579
|
+
abytes4(data);
|
|
155173
154580
|
checkOutput(cipher.encrypt.length, output6);
|
|
155174
154581
|
return cipher.encrypt(data, output6);
|
|
155175
154582
|
},
|
|
155176
154583
|
decrypt(data, output6) {
|
|
155177
|
-
|
|
154584
|
+
abytes4(data);
|
|
155178
154585
|
if (tagl && data.length < tagl)
|
|
155179
154586
|
throw new Error("invalid ciphertext length: smaller than tagLength=" + tagl);
|
|
155180
154587
|
checkOutput(cipher.decrypt.length, output6);
|
|
@@ -155210,7 +154617,7 @@ ${values.join("\n")}` : `${blockName} :`;
|
|
|
155210
154617
|
function u64Lengths(dataLength, aadLength, isLE7) {
|
|
155211
154618
|
abool2(isLE7);
|
|
155212
154619
|
const num22 = new Uint8Array(16);
|
|
155213
|
-
const view =
|
|
154620
|
+
const view = createView8(num22);
|
|
155214
154621
|
setBigUint647(view, 0, BigInt(aadLength), isLE7);
|
|
155215
154622
|
setBigUint647(view, 8, BigInt(dataLength), isLE7);
|
|
155216
154623
|
return num22;
|
|
@@ -155275,13 +154682,13 @@ ${values.join("\n")}` : `${blockName} :`;
|
|
|
155275
154682
|
abool2(counterRight);
|
|
155276
154683
|
abool2(allowShortKeys);
|
|
155277
154684
|
return (key, nonce, data, output6, counter = 0) => {
|
|
155278
|
-
|
|
155279
|
-
|
|
155280
|
-
|
|
154685
|
+
abytes4(key);
|
|
154686
|
+
abytes4(nonce);
|
|
154687
|
+
abytes4(data);
|
|
155281
154688
|
const len = data.length;
|
|
155282
154689
|
if (output6 === void 0)
|
|
155283
154690
|
output6 = new Uint8Array(len);
|
|
155284
|
-
|
|
154691
|
+
abytes4(output6);
|
|
155285
154692
|
anumber3(counter);
|
|
155286
154693
|
if (counter < 0 || counter >= MAX_COUNTER2)
|
|
155287
154694
|
throw new Error("arx: counter overflow");
|
|
@@ -155323,7 +154730,7 @@ ${values.join("\n")}` : `${blockName} :`;
|
|
|
155323
154730
|
}
|
|
155324
154731
|
const n32 = u322(nonce);
|
|
155325
154732
|
runCipher2(core, sigma2, k32, n32, data, output6, counter, rounds);
|
|
155326
|
-
|
|
154733
|
+
clean22(...toClean);
|
|
155327
154734
|
return output6;
|
|
155328
154735
|
};
|
|
155329
154736
|
}
|
|
@@ -155340,7 +154747,7 @@ ${values.join("\n")}` : `${blockName} :`;
|
|
|
155340
154747
|
this.pos = 0;
|
|
155341
154748
|
this.finished = false;
|
|
155342
154749
|
key = toBytes7(key);
|
|
155343
|
-
|
|
154750
|
+
abytes4(key, 32);
|
|
155344
154751
|
const t0 = u8to162(key, 0);
|
|
155345
154752
|
const t1 = u8to162(key, 2);
|
|
155346
154753
|
const t2 = u8to162(key, 4);
|
|
@@ -155516,12 +154923,12 @@ ${values.join("\n")}` : `${blockName} :`;
|
|
|
155516
154923
|
f2 = (h2[i42] + pad2[i42] | 0) + (f2 >>> 16) | 0;
|
|
155517
154924
|
h2[i42] = f2 & 65535;
|
|
155518
154925
|
}
|
|
155519
|
-
|
|
154926
|
+
clean22(g);
|
|
155520
154927
|
}
|
|
155521
154928
|
update(data) {
|
|
155522
|
-
|
|
154929
|
+
aexists22(this);
|
|
155523
154930
|
data = toBytes7(data);
|
|
155524
|
-
|
|
154931
|
+
abytes4(data);
|
|
155525
154932
|
const { buffer: buffer2, blockLen } = this;
|
|
155526
154933
|
const len = data.length;
|
|
155527
154934
|
for (let pos = 0; pos < len; ) {
|
|
@@ -155542,11 +154949,11 @@ ${values.join("\n")}` : `${blockName} :`;
|
|
|
155542
154949
|
return this;
|
|
155543
154950
|
}
|
|
155544
154951
|
destroy() {
|
|
155545
|
-
|
|
154952
|
+
clean22(this.h, this.r, this.buffer, this.pad);
|
|
155546
154953
|
}
|
|
155547
154954
|
digestInto(out) {
|
|
155548
|
-
|
|
155549
|
-
|
|
154955
|
+
aexists22(this);
|
|
154956
|
+
aoutput22(out, this);
|
|
155550
154957
|
this.finished = true;
|
|
155551
154958
|
const { buffer: buffer2, h: h2 } = this;
|
|
155552
154959
|
let { pos } = this;
|
|
@@ -155774,7 +155181,7 @@ ${values.join("\n")}` : `${blockName} :`;
|
|
|
155774
155181
|
const num22 = u64Lengths(data.length, AAD ? AAD.length : 0, true);
|
|
155775
155182
|
h2.update(num22);
|
|
155776
155183
|
const res = h2.digest();
|
|
155777
|
-
|
|
155184
|
+
clean22(authKey, num22);
|
|
155778
155185
|
return res;
|
|
155779
155186
|
}
|
|
155780
155187
|
var _poly1305_aead2 = (xorStream) => (key, nonce, AAD) => {
|
|
@@ -155788,7 +155195,7 @@ ${values.join("\n")}` : `${blockName} :`;
|
|
|
155788
155195
|
xorStream(key, nonce, oPlain, oPlain, 1);
|
|
155789
155196
|
const tag = computeTag3(xorStream, key, nonce, oPlain, AAD);
|
|
155790
155197
|
output6.set(tag, plength);
|
|
155791
|
-
|
|
155198
|
+
clean22(tag);
|
|
155792
155199
|
return output6;
|
|
155793
155200
|
},
|
|
155794
155201
|
decrypt(ciphertext, output6) {
|
|
@@ -155800,7 +155207,7 @@ ${values.join("\n")}` : `${blockName} :`;
|
|
|
155800
155207
|
throw new Error("invalid tag");
|
|
155801
155208
|
output6.set(ciphertext.subarray(0, -tagLength));
|
|
155802
155209
|
xorStream(key, nonce, output6, output6, 1);
|
|
155803
|
-
|
|
155210
|
+
clean22(tag);
|
|
155804
155211
|
return output6;
|
|
155805
155212
|
}
|
|
155806
155213
|
};
|
|
@@ -162321,7 +161728,7 @@ ${values.join("\n")}` : `${blockName} :`;
|
|
|
162321
161728
|
};
|
|
162322
161729
|
}
|
|
162323
161730
|
async function convertBuffer(buf2, options2) {
|
|
162324
|
-
const multihash = await
|
|
161731
|
+
const multihash = await sha2568.digest(buf2);
|
|
162325
161732
|
options2?.signal?.throwIfAborted();
|
|
162326
161733
|
return multihash.digest;
|
|
162327
161734
|
}
|
|
@@ -181467,7 +180874,7 @@ ${values.join("\n")}` : `${blockName} :`;
|
|
|
181467
180874
|
const keyPrefix2 = generated_prefix_list_browser_default[targetPrefix];
|
|
181468
180875
|
const keyBuffer = new ArrayBuffer(34);
|
|
181469
180876
|
const keyView = new DataView(keyBuffer, 0, keyBuffer.byteLength);
|
|
181470
|
-
keyView.setUint8(0,
|
|
180877
|
+
keyView.setUint8(0, sha2568.code);
|
|
181471
180878
|
keyView.setUint8(1, 32);
|
|
181472
180879
|
keyView.setUint32(2, keyPrefix2, false);
|
|
181473
180880
|
return new Uint8Array(keyView.buffer, keyView.byteOffset, keyView.byteLength);
|
|
@@ -187891,7 +187298,7 @@ ${values.join("\n")}` : `${blockName} :`;
|
|
|
187891
187298
|
var md4 = create6(id_md5);
|
|
187892
187299
|
var sha13 = create6(id_sha1);
|
|
187893
187300
|
var sha2243 = create6(id_sha224);
|
|
187894
|
-
var
|
|
187301
|
+
var sha2569 = create6(id_sha256);
|
|
187895
187302
|
var sha3842 = create6(id_sha384);
|
|
187896
187303
|
var sha5126 = create6(id_sha512);
|
|
187897
187304
|
var sha512_2242 = create6(id_sha512_224);
|
|
@@ -191858,7 +191265,7 @@ ${values.join("\n")}` : `${blockName} :`;
|
|
|
191858
191265
|
function fingerprint2Ma(fingerprint) {
|
|
191859
191266
|
const output6 = fingerprint.split(":").map((str) => parseInt(str, 16));
|
|
191860
191267
|
const encoded = Uint8Array.from(output6);
|
|
191861
|
-
const digest2 = create3(
|
|
191268
|
+
const digest2 = create3(sha2568.code, encoded);
|
|
191862
191269
|
return multiaddr(`/certhash/${base64url4.encode(digest2.bytes)}`);
|
|
191863
191270
|
}
|
|
191864
191271
|
function toSupportedHashFunction(code8) {
|
|
@@ -191935,7 +191342,7 @@ a=end-of-candidates
|
|
|
191935
191342
|
function generateNoisePrologue(localFingerprint, remoteAddr, role) {
|
|
191936
191343
|
const localFpString = localFingerprint.trim().toLowerCase().replaceAll(":", "");
|
|
191937
191344
|
const localFpArray = fromString2(localFpString, "hex");
|
|
191938
|
-
const local = create3(
|
|
191345
|
+
const local = create3(sha2568.code, localFpArray);
|
|
191939
191346
|
const remote = multibaseDecoder.decode(certhash(remoteAddr));
|
|
191940
191347
|
const byteLength = PREFIX.byteLength + local.bytes.byteLength + remote.byteLength;
|
|
191941
191348
|
if (role === "server") {
|
|
@@ -192258,7 +191665,7 @@ a=end-of-candidates
|
|
|
192258
191665
|
}, renewTime);
|
|
192259
191666
|
return {
|
|
192260
191667
|
pem: cert.toString("pem"),
|
|
192261
|
-
certhash: base64url4.encode((await
|
|
191668
|
+
certhash: base64url4.encode((await sha2568.digest(new Uint8Array(cert.rawData))).bytes)
|
|
192262
191669
|
};
|
|
192263
191670
|
}
|
|
192264
191671
|
async loadCertificate(dsKey, keyPair) {
|
|
@@ -192968,13 +192375,12 @@ a=end-of-candidates
|
|
|
192968
192375
|
* ```
|
|
192969
192376
|
*/
|
|
192970
192377
|
static deriveRootCapability(identifier) {
|
|
192971
|
-
|
|
192972
|
-
|
|
192973
|
-
|
|
192974
|
-
|
|
192975
|
-
|
|
192976
|
-
|
|
192977
|
-
return rootCapability;
|
|
192378
|
+
return {
|
|
192379
|
+
"@context": "https://w3id.org/zcap/v1",
|
|
192380
|
+
id: `urn:zcap:root:${encodeURIComponent(identifier)}`,
|
|
192381
|
+
controller: identifier,
|
|
192382
|
+
invocationTarget: identifier
|
|
192383
|
+
};
|
|
192978
192384
|
}
|
|
192979
192385
|
/**
|
|
192980
192386
|
* Implements {@link https://dcdpr.github.io/did-btcr2/#dereference-root-capability-identifier | 9.4.2 Dereference Root Capability Identifier}.
|
|
@@ -193072,7 +192478,6 @@ a=end-of-candidates
|
|
|
193072
192478
|
if (!Appendix.isDidService(obj)) return false;
|
|
193073
192479
|
if (!["SingletonBeacon", "CASBeacon", "SMTBeacon"].includes(obj.type)) return false;
|
|
193074
192480
|
if ([obj.serviceEndpoint].flat().some((ep) => typeof ep === "string" && !ep.startsWith("bitcoin:"))) return false;
|
|
193075
|
-
if (obj.casType && typeof obj.casType !== "string") return false;
|
|
193076
192481
|
return true;
|
|
193077
192482
|
}
|
|
193078
192483
|
/**
|
|
@@ -193097,8 +192502,11 @@ a=end-of-candidates
|
|
|
193097
192502
|
(addrType) => this.createBeaconService(did, addrType, beaconType)
|
|
193098
192503
|
);
|
|
193099
192504
|
} catch (error) {
|
|
193100
|
-
|
|
193101
|
-
|
|
192505
|
+
throw new BeaconError(
|
|
192506
|
+
"Failed to create beacon services: " + error.message,
|
|
192507
|
+
"BEACON_SERVICE_ERROR",
|
|
192508
|
+
{ did, beaconType }
|
|
192509
|
+
);
|
|
193102
192510
|
}
|
|
193103
192511
|
}
|
|
193104
192512
|
/**
|
|
@@ -193118,8 +192526,11 @@ a=end-of-candidates
|
|
|
193118
192526
|
const serviceEndpoint = `bitcoin:${payments_exports2[addressType]({ pubkey, network }).address}`;
|
|
193119
192527
|
return { id, type: beaconType, serviceEndpoint };
|
|
193120
192528
|
} catch (error) {
|
|
193121
|
-
|
|
193122
|
-
|
|
192529
|
+
throw new BeaconError(
|
|
192530
|
+
"Failed to create beacon service: " + error.message,
|
|
192531
|
+
"BEACON_SERVICE_ERROR",
|
|
192532
|
+
{ did, beaconType }
|
|
192533
|
+
);
|
|
193123
192534
|
}
|
|
193124
192535
|
}
|
|
193125
192536
|
/**
|
|
@@ -193154,8 +192565,11 @@ a=end-of-candidates
|
|
|
193154
192565
|
}
|
|
193155
192566
|
];
|
|
193156
192567
|
} catch (error) {
|
|
193157
|
-
|
|
193158
|
-
|
|
192568
|
+
throw new BeaconError(
|
|
192569
|
+
"Failed to create beacon services: " + error.message,
|
|
192570
|
+
"BEACON_SERVICE_ERROR",
|
|
192571
|
+
{ id, publicKey: publicKey2, network, beaconType }
|
|
192572
|
+
);
|
|
193159
192573
|
}
|
|
193160
192574
|
}
|
|
193161
192575
|
/**
|
|
@@ -193201,9 +192615,9 @@ a=end-of-candidates
|
|
|
193201
192615
|
}
|
|
193202
192616
|
/**
|
|
193203
192617
|
* Add a proof to a document.
|
|
193204
|
-
* @param {
|
|
192618
|
+
* @param {UnsignedBTCR2Update} unsignedDocument The document to add the proof to.
|
|
193205
192619
|
* @param {DataIntegrityConfig} config The configuration for generating the proof.
|
|
193206
|
-
* @returns {
|
|
192620
|
+
* @returns {SignedBTCR2Update} A document with a proof added.
|
|
193207
192621
|
*/
|
|
193208
192622
|
addProof(unsignedDocument, config) {
|
|
193209
192623
|
const proof = this.cryptosuite.createProof(unsignedDocument, config);
|
|
@@ -193316,7 +192730,7 @@ a=end-of-candidates
|
|
|
193316
192730
|
}
|
|
193317
192731
|
/**
|
|
193318
192732
|
* Verify a proof for a secure document.
|
|
193319
|
-
* @param {
|
|
192733
|
+
* @param {SignedBTCR2Update} secureDocument The secure document to verify.
|
|
193320
192734
|
* @returns {VerificationResult} The result of the verification.
|
|
193321
192735
|
*/
|
|
193322
192736
|
verifyProof(secureDocument) {
|
|
@@ -193331,7 +192745,7 @@ a=end-of-candidates
|
|
|
193331
192745
|
}
|
|
193332
192746
|
/**
|
|
193333
192747
|
* Transform a document into canonical form.
|
|
193334
|
-
* @param {
|
|
192748
|
+
* @param {UnsignedBTCR2Update | SignedBTCR2Update} document The document to transform.
|
|
193335
192749
|
* @param {DataIntegrityConfig} config The config to use when transforming the document.
|
|
193336
192750
|
* @returns {string} The canonicalized document.
|
|
193337
192751
|
* @throws {MethodError} if the document cannot be transformed.
|
|
@@ -193430,29 +192844,27 @@ a=end-of-candidates
|
|
|
193430
192844
|
* @param {MultikeyParams} params The parameters to create the multikey
|
|
193431
192845
|
* @param {string} params.id The id of the multikey (required)
|
|
193432
192846
|
* @param {string} params.controller The controller of the multikey (required)
|
|
193433
|
-
* @param {
|
|
193434
|
-
* @param {CompressedSecp256k1PublicKey} params.keys.publicKey The public key of the multikey (optional, required if no privateKey)
|
|
193435
|
-
* @param {Secp256k1SecretKey} params.keys.privateKey The private key of the multikey (optional)
|
|
192847
|
+
* @param {SchnorrKeyPair} params.keyPair The key pair of the multikey (optional, required if no publicKey)
|
|
193436
192848
|
* @throws {MultikeyError} if neither a publicKey nor a privateKey is provided
|
|
193437
192849
|
*/
|
|
193438
|
-
constructor({ id, controller,
|
|
193439
|
-
if (!
|
|
193440
|
-
throw new MultikeyError2('Argument missing: "
|
|
192850
|
+
constructor({ id, controller, keyPair }) {
|
|
192851
|
+
if (!keyPair) {
|
|
192852
|
+
throw new MultikeyError2('Argument missing: "keyPair" required', "CONSTRUCTOR_ERROR");
|
|
193441
192853
|
}
|
|
193442
|
-
if (!
|
|
193443
|
-
throw new MultikeyError2('Argument missing: "
|
|
192854
|
+
if (!keyPair.publicKey) {
|
|
192855
|
+
throw new MultikeyError2('Argument missing: "keyPair" must contain a "publicKey"', "CONSTRUCTOR_ERROR");
|
|
193444
192856
|
}
|
|
193445
192857
|
this.id = id;
|
|
193446
192858
|
this.controller = controller;
|
|
193447
|
-
this.#keyPair =
|
|
192859
|
+
this.#keyPair = keyPair;
|
|
193448
192860
|
}
|
|
193449
192861
|
/**
|
|
193450
192862
|
* @readonly
|
|
193451
192863
|
* Get the SchnorrKeyPair.
|
|
193452
192864
|
*/
|
|
193453
192865
|
get keyPair() {
|
|
193454
|
-
const
|
|
193455
|
-
return
|
|
192866
|
+
const keyPair = this.#keyPair;
|
|
192867
|
+
return keyPair;
|
|
193456
192868
|
}
|
|
193457
192869
|
/**
|
|
193458
192870
|
* @readonly
|
|
@@ -193559,9 +192971,10 @@ a=end-of-candidates
|
|
|
193559
192971
|
throw new MultikeyError2('Invalid "type" in verificationMethod', VERIFICATION_METHOD_ERROR2, { verificationMethod });
|
|
193560
192972
|
}
|
|
193561
192973
|
const decoded = this.publicKey.decode();
|
|
193562
|
-
const
|
|
193563
|
-
const
|
|
193564
|
-
|
|
192974
|
+
const pk = decoded.slice(2, decoded.length);
|
|
192975
|
+
const publicKey2 = new CompressedSecp256k1PublicKey2(pk);
|
|
192976
|
+
const keyPair = new SchnorrKeyPair2({ publicKey: publicKey2 });
|
|
192977
|
+
return new _SchnorrMultikey({ id, controller, keyPair });
|
|
193565
192978
|
}
|
|
193566
192979
|
/**
|
|
193567
192980
|
* @readonly
|
|
@@ -193595,22 +193008,21 @@ a=end-of-candidates
|
|
|
193595
193008
|
* @throws {MultikeyError} if neither a publicKey nor a privateKey is provided
|
|
193596
193009
|
* @returns {SchnorrMultikey} A new Multikey instance
|
|
193597
193010
|
*/
|
|
193598
|
-
static create({ id, controller,
|
|
193599
|
-
return new _SchnorrMultikey({ id, controller,
|
|
193011
|
+
static create({ id, controller, keyPair }) {
|
|
193012
|
+
return new _SchnorrMultikey({ id, controller, keyPair });
|
|
193600
193013
|
}
|
|
193601
193014
|
/**
|
|
193602
193015
|
* Creates a `Multikey` instance from a private key
|
|
193603
|
-
* @param {FromPublicKey} params The parameters to create the multikey
|
|
193604
193016
|
* @param {string} params.id The id of the multikey
|
|
193605
193017
|
* @param {string} params.controller The controller of the multikey
|
|
193606
193018
|
* @param {KeyBytes} params.entropy The private key bytes for the multikey
|
|
193607
193019
|
* @returns {SchnorrMultikey} The new multikey instance
|
|
193608
193020
|
*/
|
|
193609
|
-
static
|
|
193610
|
-
const secretKey = new Secp256k1SecretKey2(
|
|
193021
|
+
static fromSecretKey(id, controller, secretKeyb) {
|
|
193022
|
+
const secretKey = new Secp256k1SecretKey2(secretKeyb);
|
|
193611
193023
|
const publicKey2 = secretKey.computePublicKey();
|
|
193612
|
-
const
|
|
193613
|
-
return new _SchnorrMultikey({ id, controller,
|
|
193024
|
+
const keyPair = new SchnorrKeyPair2({ publicKey: publicKey2, secretKey });
|
|
193025
|
+
return new _SchnorrMultikey({ id, controller, keyPair });
|
|
193614
193026
|
}
|
|
193615
193027
|
/**
|
|
193616
193028
|
* Creates a `Multikey` instance from a public key
|
|
@@ -193621,24 +193033,29 @@ a=end-of-candidates
|
|
|
193621
193033
|
* @returns {Multikey} The new multikey instance
|
|
193622
193034
|
*/
|
|
193623
193035
|
static fromPublicKey({ id, controller, publicKeyBytes }) {
|
|
193624
|
-
const
|
|
193625
|
-
|
|
193036
|
+
const publicKey2 = new CompressedSecp256k1PublicKey2(publicKeyBytes);
|
|
193037
|
+
const keyPair = new SchnorrKeyPair2({ publicKey: publicKey2 });
|
|
193038
|
+
return new _SchnorrMultikey({ id, controller, keyPair });
|
|
193626
193039
|
}
|
|
193627
193040
|
/**
|
|
193628
193041
|
* Creates a `Multikey` instance from a public key multibase.
|
|
193629
|
-
* @param {
|
|
193630
|
-
* @param {string}
|
|
193631
|
-
* @param {string}
|
|
193042
|
+
* @param {DidVerificationMethod} vm The verification method containing the public key multibase.
|
|
193043
|
+
* @param {string} vm.id The id of the multikey.
|
|
193044
|
+
* @param {string} vm.controller The controller of the multikey.
|
|
193045
|
+
* @param {string} vm.publicKeyMultibase The public key multibase of the multikey.
|
|
193632
193046
|
* @returns {Multikey} The new multikey instance.
|
|
193633
193047
|
*/
|
|
193634
|
-
static
|
|
193048
|
+
static fromVerificationMethod({ id, controller, publicKeyMultibase }) {
|
|
193049
|
+
if (!publicKeyMultibase) {
|
|
193050
|
+
throw new MultikeyError2("Invalid publicKeyMultibase: cannot be undefined", VERIFICATION_METHOD_ERROR2, { publicKeyMultibase });
|
|
193051
|
+
}
|
|
193635
193052
|
const publicKeyMultibaseBytes = base58btc2.decode(publicKeyMultibase);
|
|
193636
193053
|
if (publicKeyMultibaseBytes.length !== 35) {
|
|
193637
193054
|
throw new MultikeyError2(`Invalid publicKeyMultibase length: ${publicKeyMultibaseBytes.length}`, VERIFICATION_METHOD_ERROR2, { publicKeyMultibase });
|
|
193638
193055
|
}
|
|
193639
193056
|
const publicKey2 = publicKeyMultibaseBytes.slice(2);
|
|
193640
|
-
const
|
|
193641
|
-
return new _SchnorrMultikey({ id, controller,
|
|
193057
|
+
const keyPair = new SchnorrKeyPair2({ publicKey: publicKey2 });
|
|
193058
|
+
return new _SchnorrMultikey({ id, controller, keyPair });
|
|
193642
193059
|
}
|
|
193643
193060
|
};
|
|
193644
193061
|
init_shim2();
|
|
@@ -193808,6 +193225,7 @@ a=end-of-candidates
|
|
|
193808
193225
|
* @returns {boolean} True if the id is valid.
|
|
193809
193226
|
*/
|
|
193810
193227
|
static isValidId(id) {
|
|
193228
|
+
if (typeof id !== "string") return false;
|
|
193811
193229
|
try {
|
|
193812
193230
|
Identifier.decode(id);
|
|
193813
193231
|
return true;
|
|
@@ -193857,18 +193275,14 @@ a=end-of-candidates
|
|
|
193857
193275
|
"capabilityInvocation",
|
|
193858
193276
|
"capabilityDelegation"
|
|
193859
193277
|
];
|
|
193860
|
-
const
|
|
193861
|
-
const
|
|
193862
|
-
|
|
193863
|
-
|
|
193864
|
-
|
|
193865
|
-
// Check if the key exists in the DID Document
|
|
193866
|
-
didDocument[key] && // Check if the key is an array
|
|
193867
|
-
Array.isArray(didDocument[key]) && // Check that every value in the array is a string or DidVerificationMethod
|
|
193868
|
-
didDocument[key].every(
|
|
193278
|
+
const keys = Object.keys(didDocument);
|
|
193279
|
+
const availableKeys = possibleVerificationRelationships.filter((key) => keys.includes(key));
|
|
193280
|
+
return availableKeys.every((key) => {
|
|
193281
|
+
const value3 = didDocument[key];
|
|
193282
|
+
return value3 && Array.isArray(value3) && value3.every(
|
|
193869
193283
|
(entry) => typeof entry === "string" || Appendix.isDidVerificationMethod(entry)
|
|
193870
|
-
)
|
|
193871
|
-
)
|
|
193284
|
+
);
|
|
193285
|
+
});
|
|
193872
193286
|
}
|
|
193873
193287
|
/**
|
|
193874
193288
|
* Validate the DID Document
|
|
@@ -193989,13 +193403,192 @@ a=end-of-candidates
|
|
|
193989
193403
|
return new _GenesisDocument(object22);
|
|
193990
193404
|
}
|
|
193991
193405
|
};
|
|
193406
|
+
init_shim2();
|
|
193407
|
+
var BeaconSignalDiscovery = class {
|
|
193408
|
+
/**
|
|
193409
|
+
* Retrieves the beacon signals for the given array of BeaconService objects
|
|
193410
|
+
* using an esplora/electrs REST API connection via a bitcoin I/O driver.
|
|
193411
|
+
* @param {Array<BeaconService>} beaconServices Array of BeaconService objects to retrieve signals for
|
|
193412
|
+
* @param {BitcoinNetworkConnection} bitcoin Bitcoin network connection to use for REST calls
|
|
193413
|
+
* @returns {Promise<Map<BeaconService, Array<BeaconSignal>>>} Map of beacon service to its discovered signals
|
|
193414
|
+
*/
|
|
193415
|
+
static async indexer(beaconServices, bitcoin32) {
|
|
193416
|
+
const beaconServiceSignals = /* @__PURE__ */ new Map();
|
|
193417
|
+
const currentBlockCount = await bitcoin32.network.rest.block.count();
|
|
193418
|
+
for (const beaconService of beaconServices) {
|
|
193419
|
+
beaconServiceSignals.set(beaconService, []);
|
|
193420
|
+
const beaconSignals = await bitcoin32.network.rest.address.getTxs(
|
|
193421
|
+
beaconService.serviceEndpoint
|
|
193422
|
+
);
|
|
193423
|
+
if (!beaconSignals || !beaconSignals.length) {
|
|
193424
|
+
continue;
|
|
193425
|
+
}
|
|
193426
|
+
for (const beaconSignal of beaconSignals) {
|
|
193427
|
+
const signalVout = beaconSignal.vout.slice(-1)[0];
|
|
193428
|
+
if (!signalVout || !signalVout.scriptpubkey_asm.includes("OP_RETURN")) {
|
|
193429
|
+
continue;
|
|
193430
|
+
}
|
|
193431
|
+
const outputMap = new Map(Object.entries(signalVout));
|
|
193432
|
+
const signalVoutScriptPubkey = outputMap.get("scriptpubkey_asm");
|
|
193433
|
+
if (!signalVoutScriptPubkey) {
|
|
193434
|
+
continue;
|
|
193435
|
+
}
|
|
193436
|
+
const updateHash = signalVoutScriptPubkey.split(" ").slice(-1)[0];
|
|
193437
|
+
if (!updateHash) {
|
|
193438
|
+
continue;
|
|
193439
|
+
}
|
|
193440
|
+
const confirmations = currentBlockCount - beaconSignal.status.block_height + 1;
|
|
193441
|
+
beaconServiceSignals.get(beaconService)?.push({
|
|
193442
|
+
tx: beaconSignal,
|
|
193443
|
+
signalBytes: updateHash,
|
|
193444
|
+
blockMetadata: {
|
|
193445
|
+
confirmations,
|
|
193446
|
+
height: beaconSignal.status.block_height,
|
|
193447
|
+
time: beaconSignal.status.block_time
|
|
193448
|
+
}
|
|
193449
|
+
});
|
|
193450
|
+
}
|
|
193451
|
+
}
|
|
193452
|
+
return beaconServiceSignals;
|
|
193453
|
+
}
|
|
193454
|
+
/**
|
|
193455
|
+
* Traverse the full blockchain from genesis to chain top looking for beacon signals.
|
|
193456
|
+
* @param {Array<BeaconService>} beaconServices Array of BeaconService objects to search for signals.
|
|
193457
|
+
* @param {BitcoinNetworkConnection} bitcoin Bitcoin network connection to use for RPC calls.
|
|
193458
|
+
* @returns {Promise<Map<BeaconService, Array<BeaconSignal>>>} Map of beacon service to its discovered signals.
|
|
193459
|
+
*/
|
|
193460
|
+
static async fullnode(beaconServices, bitcoin32) {
|
|
193461
|
+
const beaconServiceSignals = /* @__PURE__ */ new Map();
|
|
193462
|
+
for (const beaconService of beaconServices) {
|
|
193463
|
+
beaconServiceSignals.set(beaconService, []);
|
|
193464
|
+
}
|
|
193465
|
+
const rpc = bitcoin32.network.rpc;
|
|
193466
|
+
if (!rpc) {
|
|
193467
|
+
throw new ResolveError("RPC connection is not available", "RPC_CONNECTION_ERROR", bitcoin32);
|
|
193468
|
+
}
|
|
193469
|
+
const targetHeight = await rpc.getBlockCount();
|
|
193470
|
+
const beaconServicesMap = BeaconUtils.getBeaconServicesMap(beaconServices);
|
|
193471
|
+
let height = 0;
|
|
193472
|
+
let block = await bitcoin32.network.rpc.getBlock({ height });
|
|
193473
|
+
console.info(`Searching for beacon signals, please wait ...`);
|
|
193474
|
+
while (block.height <= targetHeight) {
|
|
193475
|
+
for (const tx of block.tx) {
|
|
193476
|
+
if (tx.txid === GENESIS_TX_ID) {
|
|
193477
|
+
continue;
|
|
193478
|
+
}
|
|
193479
|
+
for (const vin of tx.vin) {
|
|
193480
|
+
if (vin.coinbase) {
|
|
193481
|
+
continue;
|
|
193482
|
+
}
|
|
193483
|
+
if (vin.txinwitness && vin.txinwitness.length === 1 && vin.txinwitness[0] === TXIN_WITNESS_COINBASE) {
|
|
193484
|
+
continue;
|
|
193485
|
+
}
|
|
193486
|
+
if (!vin.txid) {
|
|
193487
|
+
continue;
|
|
193488
|
+
}
|
|
193489
|
+
if (vin.vout === void 0) {
|
|
193490
|
+
continue;
|
|
193491
|
+
}
|
|
193492
|
+
const prevout = await rpc.getRawTransaction(vin.txid, 2);
|
|
193493
|
+
if (!prevout.vout[vin.vout]) {
|
|
193494
|
+
continue;
|
|
193495
|
+
}
|
|
193496
|
+
const scriptPubKey = prevout.vout[vin.vout].scriptPubKey;
|
|
193497
|
+
if (!scriptPubKey.address) {
|
|
193498
|
+
continue;
|
|
193499
|
+
}
|
|
193500
|
+
const beaconService = beaconServicesMap.get(scriptPubKey.address);
|
|
193501
|
+
if (!beaconService) {
|
|
193502
|
+
continue;
|
|
193503
|
+
}
|
|
193504
|
+
const txVoutScriptPubkeyAsm = prevout.vout[vin.vout].scriptPubKey.asm;
|
|
193505
|
+
if (!txVoutScriptPubkeyAsm.includes("OP_RETURN")) {
|
|
193506
|
+
continue;
|
|
193507
|
+
}
|
|
193508
|
+
console.info(`Tx ${tx.txid} contains beacon service address ${scriptPubKey.address} and OP_RETURN!`, tx);
|
|
193509
|
+
const updateHash = txVoutScriptPubkeyAsm.split(" ").slice(-1)[0];
|
|
193510
|
+
if (!updateHash) {
|
|
193511
|
+
continue;
|
|
193512
|
+
}
|
|
193513
|
+
beaconServiceSignals.get(beaconService)?.push({
|
|
193514
|
+
tx,
|
|
193515
|
+
signalBytes: updateHash,
|
|
193516
|
+
blockMetadata: {
|
|
193517
|
+
height: block.height,
|
|
193518
|
+
time: block.time,
|
|
193519
|
+
confirmations: block.confirmations
|
|
193520
|
+
}
|
|
193521
|
+
});
|
|
193522
|
+
}
|
|
193523
|
+
;
|
|
193524
|
+
}
|
|
193525
|
+
height += 1;
|
|
193526
|
+
if (height > targetHeight) {
|
|
193527
|
+
console.info(`Chain tip reached ${height}, breaking ...`);
|
|
193528
|
+
break;
|
|
193529
|
+
}
|
|
193530
|
+
block = await rpc.getBlock({ height });
|
|
193531
|
+
}
|
|
193532
|
+
return beaconServiceSignals;
|
|
193533
|
+
}
|
|
193534
|
+
};
|
|
193992
193535
|
var Resolve = class {
|
|
193536
|
+
/**
|
|
193537
|
+
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#if-genesis_bytes-is-a-secp256k1-public-key | 7.2.d.1 if genesis bytes is a secp256k1 Public Key}.
|
|
193538
|
+
* @param {DidComponents} didComponents The decoded components of the did.
|
|
193539
|
+
* @returns {DidDocument} The resolved DID Document object.
|
|
193540
|
+
*/
|
|
193541
|
+
static deterministic(didComponents) {
|
|
193542
|
+
const did = Identifier.encode(didComponents);
|
|
193543
|
+
const { genesisBytes } = didComponents;
|
|
193544
|
+
const { multibase: publicKeyMultibase } = new CompressedSecp256k1PublicKey2(genesisBytes);
|
|
193545
|
+
const service = BeaconUtils.generateBeaconServices({
|
|
193546
|
+
id: did,
|
|
193547
|
+
publicKey: genesisBytes,
|
|
193548
|
+
network: getNetwork2(didComponents.network),
|
|
193549
|
+
beaconType: "SingletonBeacon"
|
|
193550
|
+
});
|
|
193551
|
+
return new DidDocument2({
|
|
193552
|
+
id: did,
|
|
193553
|
+
controller: [did],
|
|
193554
|
+
verificationMethod: [{
|
|
193555
|
+
id: `${did}#initialKey`,
|
|
193556
|
+
type: "Multikey",
|
|
193557
|
+
controller: did,
|
|
193558
|
+
publicKeyMultibase: publicKeyMultibase.encoded
|
|
193559
|
+
}],
|
|
193560
|
+
service
|
|
193561
|
+
});
|
|
193562
|
+
}
|
|
193563
|
+
/**
|
|
193564
|
+
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#if-genesis_bytes-is-a-sha-256-hash | 7.2.d.2 if genesis_bytes is a SHA-256 Hash}.
|
|
193565
|
+
* @param {DidComponents} didComponents BTCR2 DID components used to resolve the DID Document
|
|
193566
|
+
* @param {GenesisDocument} genesisDocument The genesis document for resolving the DID Document.
|
|
193567
|
+
* @returns {Promise<DidDocument>} The resolved DID Document object
|
|
193568
|
+
* @throws {ResolveError} InvalidDidDocument if not conformant to DID Core v1.1
|
|
193569
|
+
*/
|
|
193570
|
+
static async external(didComponents, genesisDocument) {
|
|
193571
|
+
const hashBytes = canonicalization22.process(genesisDocument, { encoding: "hex" });
|
|
193572
|
+
const genesisBytes = bytesToHex2(didComponents.genesisBytes);
|
|
193573
|
+
if (genesisBytes !== hashBytes) {
|
|
193574
|
+
throw new ResolveError(
|
|
193575
|
+
`Initial document mismatch: genesisBytes ${genesisBytes} !== hashBytes ${hashBytes}`,
|
|
193576
|
+
INVALID_DID_DOCUMENT2,
|
|
193577
|
+
{ genesisBytes, hashBytes }
|
|
193578
|
+
);
|
|
193579
|
+
}
|
|
193580
|
+
const did = Identifier.encode(didComponents);
|
|
193581
|
+
const currentDocument = JSON.parse(
|
|
193582
|
+
JSON.stringify(genesisDocument).replaceAll(ID_PLACEHOLDER_VALUE, did)
|
|
193583
|
+
);
|
|
193584
|
+
return new DidDocument2(currentDocument);
|
|
193585
|
+
}
|
|
193993
193586
|
/**
|
|
193994
193587
|
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-sidecar-data | Process Sidecar Data}
|
|
193995
193588
|
* @param {Sidecar} sidecar The sidecar data to process.
|
|
193996
|
-
* @returns {
|
|
193589
|
+
* @returns {ProcessedSidecar} The processed sidecar data containing maps of updates, CAS announcements, and SMT proofs.
|
|
193997
193590
|
*/
|
|
193998
|
-
static
|
|
193591
|
+
static sidecarData(sidecar = {}) {
|
|
193999
193592
|
const updateMap = /* @__PURE__ */ new Map();
|
|
194000
193593
|
if (sidecar.updates?.length)
|
|
194001
193594
|
for (const update of sidecar.updates) {
|
|
@@ -194020,9 +193613,9 @@ a=end-of-candidates
|
|
|
194020
193613
|
* @param {DidComponents} didComponents The decoded components of the did.
|
|
194021
193614
|
* @param {GenesisDocument} genesisDocument The genesis document for resolving the DID Document.
|
|
194022
193615
|
* @returns {Promise<DidDocument>} The resolved DID Document object.
|
|
194023
|
-
* @throws {
|
|
193616
|
+
* @throws {ResolveError} if the DID hrp is invalid, no sidecarData passed and hrp = "x".
|
|
194024
193617
|
*/
|
|
194025
|
-
static async
|
|
193618
|
+
static async currentDocument(didComponents, genesisDocument) {
|
|
194026
193619
|
const { hrp, genesisBytes } = didComponents;
|
|
194027
193620
|
if (hrp === IdentifierHrp2.x) {
|
|
194028
193621
|
if (!genesisDocument)
|
|
@@ -194045,84 +193638,33 @@ a=end-of-candidates
|
|
|
194045
193638
|
}
|
|
194046
193639
|
throw new ResolveError(`Unsupported DID hrp ${hrp}`, INVALID_DID2, { hrp });
|
|
194047
193640
|
}
|
|
194048
|
-
/**
|
|
194049
|
-
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#if-genesis_bytes-is-a-secp256k1-public-key | 7.2.d.1 if genesis bytes is a secp256k1 Public Key}.
|
|
194050
|
-
* @param {DidComponents} didComponents The decoded components of the did.
|
|
194051
|
-
* @returns {DidDocument} The resolved DID Document object.
|
|
194052
|
-
*/
|
|
194053
|
-
static deterministic(didComponents) {
|
|
194054
|
-
const did = Identifier.encode(didComponents);
|
|
194055
|
-
const { genesisBytes } = didComponents;
|
|
194056
|
-
const { multibase: publicKeyMultibase } = new CompressedSecp256k1PublicKey2(genesisBytes);
|
|
194057
|
-
const service = BeaconUtils.generateBeaconServices({
|
|
194058
|
-
id: did,
|
|
194059
|
-
publicKey: genesisBytes,
|
|
194060
|
-
network: getNetwork2(didComponents.network),
|
|
194061
|
-
beaconType: "SingletonBeacon"
|
|
194062
|
-
});
|
|
194063
|
-
return new DidDocument2({
|
|
194064
|
-
id: did,
|
|
194065
|
-
controller: [did],
|
|
194066
|
-
verificationMethod: [{
|
|
194067
|
-
id: `${did}#initialKey`,
|
|
194068
|
-
type: "Multikey",
|
|
194069
|
-
controller: did,
|
|
194070
|
-
publicKeyMultibase: publicKeyMultibase.encoded
|
|
194071
|
-
}],
|
|
194072
|
-
service
|
|
194073
|
-
});
|
|
194074
|
-
}
|
|
194075
|
-
/**
|
|
194076
|
-
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#if-genesis_bytes-is-a-sha-256-hash | 7.2.d.2 if genesis_bytes is a SHA-256 Hash}.
|
|
194077
|
-
* @param {DidComponents} didComponents BTCR2 DID components used to resolve the DID Document
|
|
194078
|
-
* @param {GenesisDocument} genesisDocument The genesis document for resolving the DID Document.
|
|
194079
|
-
* @returns {Promise<DidDocument>} The resolved DID Document object
|
|
194080
|
-
* @throws {MethodError} InvalidDidDocument if not conformant to DID Core v1.1
|
|
194081
|
-
*/
|
|
194082
|
-
static async external(didComponents, genesisDocument) {
|
|
194083
|
-
const hashBytes = canonicalization22.process(genesisDocument, { encoding: "hex" });
|
|
194084
|
-
const genesisBytes = bytesToHex2(didComponents.genesisBytes);
|
|
194085
|
-
if (genesisBytes !== hashBytes) {
|
|
194086
|
-
throw new MethodError2(
|
|
194087
|
-
`Initial document mismatch: genesisBytes ${genesisBytes} !== hashBytes ${hashBytes}`,
|
|
194088
|
-
INVALID_DID_DOCUMENT2,
|
|
194089
|
-
{ genesisBytes, hashBytes }
|
|
194090
|
-
);
|
|
194091
|
-
}
|
|
194092
|
-
const did = Identifier.encode(didComponents);
|
|
194093
|
-
const currentDocument = JSON.parse(
|
|
194094
|
-
JSON.stringify(genesisDocument).replaceAll(ID_PLACEHOLDER_VALUE, did)
|
|
194095
|
-
);
|
|
194096
|
-
return new DidDocument2(currentDocument);
|
|
194097
|
-
}
|
|
194098
193641
|
/**
|
|
194099
193642
|
* Finds uses the beacon services in the currentDocument to scan for onchain Beacon Signals (transactions) containing
|
|
194100
193643
|
* Signal Bytes (last output in OP_RETURN transaction).
|
|
194101
193644
|
* @param {Array<BeaconService>} beaconServices The array of BeaconService objects to search for signals.
|
|
194102
193645
|
* @param {SidecarData} sidecarData The sidecar data containing maps of updates, CAS announcements, and SMT proofs.
|
|
194103
193646
|
* @param {BitcoinNetworkConnection} bitcoin The bitcoin network connection used to fetch beacon signals
|
|
194104
|
-
* @
|
|
194105
|
-
* @returns {Promise<Array<[BTCR2SignedUpdate, BlockMetadata]>>} The array of BTCR2 Signed Updates announced by the Beacon Signals.
|
|
193647
|
+
* @returns {Promise<Array<[SignedBTCR2Update, BlockMetadata]>>} The array of BTCR2 Signed Updates announced by the Beacon Signals.
|
|
194106
193648
|
*/
|
|
194107
|
-
static async
|
|
194108
|
-
const beaconServicesSignals =
|
|
194109
|
-
const
|
|
194110
|
-
|
|
194111
|
-
|
|
194112
|
-
|
|
194113
|
-
|
|
194114
|
-
|
|
194115
|
-
return
|
|
193649
|
+
static async beaconSignals(beaconServices, sidecarData, bitcoin32) {
|
|
193650
|
+
const beaconServicesSignals = bitcoin32.network.rest ? await BeaconSignalDiscovery.indexer(beaconServices, bitcoin32) : await BeaconSignalDiscovery.fullnode(beaconServices, bitcoin32);
|
|
193651
|
+
const promises = Array.from(beaconServicesSignals.entries()).map(
|
|
193652
|
+
async ([service, signals]) => {
|
|
193653
|
+
if (!signals.length) return [];
|
|
193654
|
+
return BeaconFactory.establish(service).processSignals(signals, sidecarData);
|
|
193655
|
+
}
|
|
193656
|
+
);
|
|
193657
|
+
return (await Promise.all(promises)).flat();
|
|
194116
193658
|
}
|
|
194117
193659
|
/**
|
|
194118
193660
|
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-updates | 7.2.f Process updates Array}.
|
|
194119
193661
|
* @param {DidDocument} currentDocument The current DID Document to apply the updates to.
|
|
194120
|
-
* @param {Array<[
|
|
193662
|
+
* @param {Array<[SignedBTCR2Update, BlockMetadata]>} unsortedUpdates The unsorted array of BTCR2 Signed Updates and their associated Block Metadata.
|
|
194121
193663
|
* @param {string} [versionTime] The optional version time to limit updates to.
|
|
194122
193664
|
* @param {string} [versionId] The optional version id to limit updates to.
|
|
194123
193665
|
* @returns {Promise<DidResolutionResponse>} The updated DID Document, number of confirmations, and version id.
|
|
194124
193666
|
*/
|
|
194125
|
-
static async
|
|
193667
|
+
static async updates(currentDocument, unsortedUpdates, versionTime, versionId) {
|
|
194126
193668
|
let currentVersionId = 1;
|
|
194127
193669
|
const updateHashHistory = [];
|
|
194128
193670
|
const updates = unsortedUpdates.sort(
|
|
@@ -194145,7 +193687,7 @@ a=end-of-candidates
|
|
|
194145
193687
|
}
|
|
194146
193688
|
if (update.targetVersionId <= currentVersionId) {
|
|
194147
193689
|
updateHashHistory.push(currentDocumentHash);
|
|
194148
|
-
this.
|
|
193690
|
+
this.confirmDuplicate(update, updateHashHistory);
|
|
194149
193691
|
} else if (update.targetVersionId === currentVersionId + 1) {
|
|
194150
193692
|
const sourceHash = update.sourceHash.startsWith("z") ? update.sourceHash : `z${update.sourceHash}`;
|
|
194151
193693
|
if (sourceHash !== currentDocumentHash) {
|
|
@@ -194155,7 +193697,7 @@ a=end-of-candidates
|
|
|
194155
193697
|
{ sourceHash, currentDocumentHash }
|
|
194156
193698
|
);
|
|
194157
193699
|
}
|
|
194158
|
-
response2.currentDocument = await this.
|
|
193700
|
+
response2.currentDocument = await this.applyUpdate(response2.currentDocument, update);
|
|
194159
193701
|
const unsignedUpdate = JSONUtils2.deleteKeys(update, ["proof"]);
|
|
194160
193702
|
updateHashHistory.push(canonicalization22.process(unsignedUpdate, { encoding: "base58" }));
|
|
194161
193703
|
} else if (update.targetVersionId > currentVersionId + 1) {
|
|
@@ -194179,138 +193721,13 @@ a=end-of-candidates
|
|
|
194179
193721
|
}
|
|
194180
193722
|
return response2;
|
|
194181
193723
|
}
|
|
194182
|
-
/**
|
|
194183
|
-
* Retrieves the beacon signals for the given array of BeaconService objects
|
|
194184
|
-
* using a esplora/electrs REST API connection via a bitcoin I/O driver.
|
|
194185
|
-
* @param {Array<BeaconService>} beaconServices Array of BeaconService objects to retrieve signals for
|
|
194186
|
-
* @param {BitcoinNetworkConnection} bitcoin Bitcoin network connection to use for REST calls
|
|
194187
|
-
* @returns {Promise<Array<BeaconSignal>>} Promise resolving to an array of BeaconSignal objects
|
|
194188
|
-
*/
|
|
194189
|
-
static async queryBlockchainIndexer(beaconServices, bitcoin32) {
|
|
194190
|
-
const beaconServiceSignals = /* @__PURE__ */ new Map();
|
|
194191
|
-
for (const beaconService of beaconServices) {
|
|
194192
|
-
beaconServiceSignals.set(beaconService, []);
|
|
194193
|
-
const beaconSignals = await bitcoin32.network.rest.address.getTxs(
|
|
194194
|
-
beaconService.serviceEndpoint
|
|
194195
|
-
);
|
|
194196
|
-
if (!beaconSignals || !beaconSignals.length) {
|
|
194197
|
-
continue;
|
|
194198
|
-
}
|
|
194199
|
-
for (const beaconSignal of beaconSignals) {
|
|
194200
|
-
const signalVout = beaconSignal.vout.slice(-1)[0];
|
|
194201
|
-
if (!signalVout || !signalVout.scriptpubkey_asm.includes("OP_RETURN")) {
|
|
194202
|
-
continue;
|
|
194203
|
-
}
|
|
194204
|
-
const outputMap = new Map(Object.entries(signalVout));
|
|
194205
|
-
const signalVoutScriptPubkey = outputMap.get("scriptpubkey_asm");
|
|
194206
|
-
if (!signalVoutScriptPubkey) {
|
|
194207
|
-
continue;
|
|
194208
|
-
}
|
|
194209
|
-
const updateHash = signalVoutScriptPubkey.split(" ").slice(-1)[0];
|
|
194210
|
-
if (!updateHash) {
|
|
194211
|
-
continue;
|
|
194212
|
-
}
|
|
194213
|
-
const confirmations = await bitcoin32.network.rest.block.count() - beaconSignal.status.block_height + 1;
|
|
194214
|
-
beaconServiceSignals.get(beaconService)?.push({
|
|
194215
|
-
tx: beaconSignal,
|
|
194216
|
-
signalBytes: updateHash,
|
|
194217
|
-
blockMetadata: {
|
|
194218
|
-
confirmations,
|
|
194219
|
-
height: beaconSignal.status.block_height,
|
|
194220
|
-
time: beaconSignal.status.block_time
|
|
194221
|
-
}
|
|
194222
|
-
});
|
|
194223
|
-
}
|
|
194224
|
-
}
|
|
194225
|
-
return beaconServiceSignals;
|
|
194226
|
-
}
|
|
194227
|
-
/**
|
|
194228
|
-
* Traverse the full blockchain from genesis to chain top looking for beacon signals.
|
|
194229
|
-
* @param {Array<BeaconService>} beaconServices Array of BeaconService objects to search for signals.
|
|
194230
|
-
* @param {BitcoinNetworkConnection} bitcoin Bitcoin network connection to use for RPC calls.
|
|
194231
|
-
* @returns {Promise<Array<BeaconSignal>>} Promise resolving to an array of BeaconSignal objects.
|
|
194232
|
-
*/
|
|
194233
|
-
static async traverseFullBlockchain(beaconServices, bitcoin32) {
|
|
194234
|
-
const beaconServiceSignals = /* @__PURE__ */ new Map();
|
|
194235
|
-
for (const beaconService of beaconServices) {
|
|
194236
|
-
beaconServiceSignals.set(beaconService, []);
|
|
194237
|
-
}
|
|
194238
|
-
const rpc = bitcoin32.network.rpc;
|
|
194239
|
-
if (!rpc) {
|
|
194240
|
-
throw new ResolveError("RPC connection is not available", "RPC_CONNECTION_ERROR", bitcoin32);
|
|
194241
|
-
}
|
|
194242
|
-
const targetHeight = await rpc.getBlockCount();
|
|
194243
|
-
let height = 0;
|
|
194244
|
-
let block = await bitcoin32.network.rpc.getBlock({ height });
|
|
194245
|
-
console.info(`Searching for beacon signals, please wait ...`);
|
|
194246
|
-
while (block.height <= targetHeight) {
|
|
194247
|
-
for (const tx of block.tx) {
|
|
194248
|
-
if (tx.txid === GENESIS_TX_ID) {
|
|
194249
|
-
continue;
|
|
194250
|
-
}
|
|
194251
|
-
for (const vin of tx.vin) {
|
|
194252
|
-
if (vin.coinbase) {
|
|
194253
|
-
continue;
|
|
194254
|
-
}
|
|
194255
|
-
if (vin.txinwitness && vin.txinwitness.length === 1 && vin.txinwitness[0] === TXIN_WITNESS_COINBASE) {
|
|
194256
|
-
continue;
|
|
194257
|
-
}
|
|
194258
|
-
if (!vin.txid) {
|
|
194259
|
-
continue;
|
|
194260
|
-
}
|
|
194261
|
-
if (vin.vout === void 0) {
|
|
194262
|
-
continue;
|
|
194263
|
-
}
|
|
194264
|
-
const prevout = await rpc.getRawTransaction(vin.txid, 2);
|
|
194265
|
-
if (!prevout.vout[vin.vout]) {
|
|
194266
|
-
continue;
|
|
194267
|
-
}
|
|
194268
|
-
const scriptPubKey = prevout.vout[vin.vout].scriptPubKey;
|
|
194269
|
-
if (!scriptPubKey.address) {
|
|
194270
|
-
continue;
|
|
194271
|
-
}
|
|
194272
|
-
const beaconService = BeaconUtils.getBeaconServicesMap(beaconServices).get(scriptPubKey.address);
|
|
194273
|
-
if (!beaconService) {
|
|
194274
|
-
continue;
|
|
194275
|
-
}
|
|
194276
|
-
const txVoutScriptPubkeyAsm = prevout.vout[vin.vout].scriptPubKey.asm;
|
|
194277
|
-
if (!txVoutScriptPubkeyAsm.includes("OP_RETURN")) {
|
|
194278
|
-
continue;
|
|
194279
|
-
}
|
|
194280
|
-
console.info(`Tx ${tx.txid} contains beacon service address ${scriptPubKey.address} and OP_RETURN!`, tx);
|
|
194281
|
-
const updateHash = txVoutScriptPubkeyAsm.split(" ").slice(-1)[0];
|
|
194282
|
-
if (!updateHash) {
|
|
194283
|
-
continue;
|
|
194284
|
-
}
|
|
194285
|
-
beaconServiceSignals.get(beaconService)?.push({
|
|
194286
|
-
tx,
|
|
194287
|
-
signalBytes: updateHash,
|
|
194288
|
-
blockMetadata: {
|
|
194289
|
-
height: block.height,
|
|
194290
|
-
time: block.time,
|
|
194291
|
-
confirmations: block.confirmations
|
|
194292
|
-
}
|
|
194293
|
-
});
|
|
194294
|
-
}
|
|
194295
|
-
;
|
|
194296
|
-
}
|
|
194297
|
-
height += 1;
|
|
194298
|
-
const tip = await rpc.getBlockCount();
|
|
194299
|
-
if (height > tip) {
|
|
194300
|
-
console.info(`Chain tip reached ${height}, breaking ...`);
|
|
194301
|
-
break;
|
|
194302
|
-
}
|
|
194303
|
-
block = await rpc.getBlock({ height });
|
|
194304
|
-
}
|
|
194305
|
-
return beaconServiceSignals;
|
|
194306
|
-
}
|
|
194307
193724
|
/**
|
|
194308
193725
|
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/#confirm-duplicate-update | 7.2.f.1 Confirm Duplicate Update}.
|
|
194309
193726
|
* This step confirms that an update with a lower-than-expected targetVersionId is a true duplicate.
|
|
194310
|
-
* @param {
|
|
193727
|
+
* @param {SignedBTCR2Update} update The BTCR2 Signed Update to confirm as a duplicate.
|
|
194311
193728
|
* @returns {void} Does not return a value, but throws an error if the update is not a valid duplicate.
|
|
194312
193729
|
*/
|
|
194313
|
-
static
|
|
193730
|
+
static confirmDuplicate(update, updateHashHistory) {
|
|
194314
193731
|
const unsignedUpdate = JSONUtils2.deleteKeys(update, ["proof"]);
|
|
194315
193732
|
const unsignedUpdateHash = canonicalization22.process(unsignedUpdate);
|
|
194316
193733
|
const historicalUpdateHash = updateHashHistory[update.targetVersionId - 2];
|
|
@@ -194325,11 +193742,11 @@ a=end-of-candidates
|
|
|
194325
193742
|
/**
|
|
194326
193743
|
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#apply-update | 7.2.f.3 Apply Update}.
|
|
194327
193744
|
* @param {DidDocument} currentDocument The current DID Document to apply the update to.
|
|
194328
|
-
* @param {
|
|
193745
|
+
* @param {SignedBTCR2Update} update The BTCR2 Signed Update to apply.
|
|
194329
193746
|
* @returns {Promise<DidDocument>} The updated DID Document after applying the update.
|
|
194330
193747
|
* @throws {ResolveError} If the update is invalid or cannot be applied.
|
|
194331
193748
|
*/
|
|
194332
|
-
static async
|
|
193749
|
+
static async applyUpdate(currentDocument, update) {
|
|
194333
193750
|
const capabilityId = update.proof?.capability;
|
|
194334
193751
|
if (!capabilityId) {
|
|
194335
193752
|
throw new ResolveError("No root capability found in update", INVALID_DID_UPDATE2, update);
|
|
@@ -194348,18 +193765,13 @@ a=end-of-candidates
|
|
|
194348
193765
|
throw new ResolveError("No verificationMethod found in update", INVALID_DID_UPDATE2, update);
|
|
194349
193766
|
}
|
|
194350
193767
|
const vm = DidBtcr2.getSigningMethod(currentDocument, verificationMethodId);
|
|
194351
|
-
const
|
|
194352
|
-
const multikey = SchnorrMultikey2.fromPublicKeyMultibase(
|
|
194353
|
-
`#${vmId}`,
|
|
194354
|
-
vmController,
|
|
194355
|
-
vm.publicKeyMultibase
|
|
194356
|
-
);
|
|
193768
|
+
const multikey = SchnorrMultikey2.fromVerificationMethod(vm);
|
|
194357
193769
|
const cryptosuite = new BIP340Cryptosuite2(multikey);
|
|
194358
193770
|
const canonicalUpdate = canonicalization22.canonicalize(update);
|
|
194359
193771
|
const diProof = new BIP340DataIntegrityProof2(cryptosuite);
|
|
194360
193772
|
const verificationResult = diProof.verifyProof(canonicalUpdate, "capabilityInvocation");
|
|
194361
193773
|
if (!verificationResult.verified) {
|
|
194362
|
-
throw new
|
|
193774
|
+
throw new ResolveError(
|
|
194363
193775
|
"Invalid update: proof not verified",
|
|
194364
193776
|
INVALID_DID_UPDATE2,
|
|
194365
193777
|
verificationResult
|
|
@@ -194370,7 +193782,7 @@ a=end-of-candidates
|
|
|
194370
193782
|
const currentDocumentHash = canonicalization22.process(currentDocument, { encoding: "base58" });
|
|
194371
193783
|
const updateTargetHash = update.targetHash.startsWith("z") ? update.targetHash : `z${update.targetHash}`;
|
|
194372
193784
|
if (updateTargetHash !== currentDocumentHash) {
|
|
194373
|
-
throw new
|
|
193785
|
+
throw new ResolveError(
|
|
194374
193786
|
`Invalid update: updateTargetHash !== currentDocumentHash`,
|
|
194375
193787
|
INVALID_DID_UPDATE2,
|
|
194376
193788
|
{ updateTargetHash, currentDocumentHash }
|
|
@@ -194382,103 +193794,55 @@ a=end-of-candidates
|
|
|
194382
193794
|
init_shim2();
|
|
194383
193795
|
var Update = class {
|
|
194384
193796
|
/**
|
|
194385
|
-
* Implements {@link https://dcdpr.github.io/did-btcr2
|
|
194386
|
-
*
|
|
194387
|
-
* The Construct DID Update Payload algorithm applies the documentPatch to the sourceDocument and verifies the
|
|
194388
|
-
* resulting targetDocument is a conformant DID document. It takes in a Identifier, sourceDocument,
|
|
194389
|
-
* sourceVersionId, and documentPatch objects. It returns an unsigned DID Update Payload.
|
|
193797
|
+
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/update.html#construct-btcr2-unsigned-update | 7.3.b Construct BTCR2 Unsigned Update}.
|
|
193798
|
+
* This process constructs a BTCR2 Unsigned Update conformant to the spec template.
|
|
194390
193799
|
*
|
|
194391
|
-
* @param {
|
|
194392
|
-
* @param {
|
|
194393
|
-
* @param {
|
|
194394
|
-
* @
|
|
194395
|
-
* @
|
|
194396
|
-
* @returns {Promise<BTCR2SignedUpdate>} The constructed BTCR2SignedUpdate object.
|
|
194397
|
-
* @throws {MethodError} InvalidDid if sourceDocument.id does not match identifier.
|
|
193800
|
+
* @param {Btcr2DidDocument} sourceDocument The source DID document to be updated.
|
|
193801
|
+
* @param {PatchOperation[]} patches The array of JSON Patch operations to apply to the sourceDocument.
|
|
193802
|
+
* @param {number} sourceVersionId The version ID of the source document.
|
|
193803
|
+
* @returns {Promise<SignedBTCR2Update>} The constructed SignedBTCR2Update object.
|
|
193804
|
+
* @throws {UpdateError} InvalidDid if sourceDocument.id does not match identifier.
|
|
194398
193805
|
*/
|
|
194399
|
-
static async construct({
|
|
194400
|
-
identifier,
|
|
194401
|
-
sourceDocument,
|
|
194402
|
-
sourceVersionId,
|
|
194403
|
-
patch
|
|
194404
|
-
}) {
|
|
194405
|
-
if (sourceDocument.id !== identifier) {
|
|
194406
|
-
throw new UpdateError(
|
|
194407
|
-
"Identifier mismatch: sourceDocument.id !== identifier",
|
|
194408
|
-
INVALID_DID_UPDATE2,
|
|
194409
|
-
{ sourceDocument, identifier }
|
|
194410
|
-
);
|
|
194411
|
-
}
|
|
193806
|
+
static async construct(sourceDocument, patches, sourceVersionId) {
|
|
194412
193807
|
const unsignedUpdate = {
|
|
194413
|
-
// 3. Set BTCR2SignedUpdate.@context to the following list
|
|
194414
193808
|
"@context": [
|
|
194415
193809
|
"https://w3id.org/security/v2",
|
|
194416
193810
|
"https://w3id.org/zcap/v1",
|
|
194417
193811
|
"https://w3id.org/json-ld-patch/v1",
|
|
194418
193812
|
"https://btcr2.dev/context/v1"
|
|
194419
193813
|
],
|
|
194420
|
-
|
|
194421
|
-
patch,
|
|
193814
|
+
patch: patches,
|
|
194422
193815
|
targetHash: "",
|
|
194423
|
-
targetVersionId:
|
|
194424
|
-
sourceHash: ""
|
|
194425
|
-
};
|
|
194426
|
-
const targetDocument = JSONPatch.apply(sourceDocument,
|
|
194427
|
-
|
|
194428
|
-
|
|
194429
|
-
|
|
194430
|
-
|
|
193816
|
+
targetVersionId: sourceVersionId + 1,
|
|
193817
|
+
sourceHash: canonicalization22.process(sourceDocument, { encoding: "base58" })
|
|
193818
|
+
};
|
|
193819
|
+
const targetDocument = JSONPatch.apply(sourceDocument, patches);
|
|
193820
|
+
try {
|
|
193821
|
+
DidDocument2.isValid(targetDocument);
|
|
193822
|
+
} catch (error) {
|
|
193823
|
+
throw new UpdateError(
|
|
193824
|
+
"Error validating targetDocument: " + (error instanceof Error ? error.message : String(error)),
|
|
193825
|
+
INVALID_DID_UPDATE2,
|
|
193826
|
+
targetDocument
|
|
193827
|
+
);
|
|
193828
|
+
}
|
|
193829
|
+
unsignedUpdate.targetHash = canonicalization22.process(targetDocument, { encoding: "base58" });
|
|
194431
193830
|
return unsignedUpdate;
|
|
194432
193831
|
}
|
|
194433
193832
|
/**
|
|
194434
|
-
* {@link
|
|
194435
|
-
*
|
|
194436
|
-
* The Invoke DID Update Payload algorithm takes in a Identifier, an unsigned BTCR2SignedUpdate, and a
|
|
194437
|
-
* verificationMethod. It retrieves the privateKeyBytes for the verificationMethod and adds a capability invocation in
|
|
194438
|
-
* the form of a Data Integrity proof following the Authorization Capabilities (ZCAP-LD) and VC Data Integrity
|
|
194439
|
-
* specifications. It returns the invoked DID Update Payload.
|
|
193833
|
+
* Implements subsection {@link http://dcdpr.github.io/did-btcr2/operations/update.html#construct-btcr2-signed-update | 7.3.c Construct BTCR2 Signed Update }.
|
|
193834
|
+
* This process constructs a BTCR2 Signed Update from a BTCR2 Unsigned Update.
|
|
194440
193835
|
*
|
|
194441
|
-
* @param {
|
|
194442
|
-
* @param {
|
|
194443
|
-
* @param {
|
|
194444
|
-
* @
|
|
194445
|
-
* @
|
|
194446
|
-
* @throws {MethodError} if the privateKeyBytes are invalid
|
|
193836
|
+
* @param {string} did The did-btcr2 identifier to derive the root capability from
|
|
193837
|
+
* @param {UnsignedBTCR2Update} unsignedUpdate The updatePayload object to be signed
|
|
193838
|
+
* @param {DidVerificationMethod} verificationMethod The verificationMethod object to be used for signing
|
|
193839
|
+
* @returns {SignedBTCR2Update} Did update payload secured with a proof => SignedBTCR2Update
|
|
193840
|
+
* @throws {UpdateError} if the privateKeyBytes are invalid
|
|
194447
193841
|
*/
|
|
194448
|
-
static async
|
|
194449
|
-
|
|
194450
|
-
|
|
194451
|
-
|
|
194452
|
-
}) {
|
|
194453
|
-
const { id: fullId, controller, publicKeyMultibase, secretKeyMultibase } = verificationMethod;
|
|
194454
|
-
if (!publicKeyMultibase) {
|
|
194455
|
-
throw new MethodError2(
|
|
194456
|
-
"Invalid publicKeyMultibase: cannot be undefined",
|
|
194457
|
-
INVALID_PUBLIC_KEY_TYPE2,
|
|
194458
|
-
verificationMethod
|
|
194459
|
-
);
|
|
194460
|
-
}
|
|
194461
|
-
const id = fullId.slice(fullId.indexOf("#"));
|
|
194462
|
-
const components = Identifier.decode(id);
|
|
194463
|
-
const keyUri = new CompressedSecp256k1PublicKey2(components.genesisBytes).hex;
|
|
194464
|
-
const keys = secretKeyMultibase ? new SchnorrKeyPair2({ secretKey: Secp256k1SecretKey2.decode(secretKeyMultibase) }) : Kms.getKey(keyUri);
|
|
194465
|
-
if (!keys) {
|
|
194466
|
-
throw new MethodError2(
|
|
194467
|
-
"No privateKey found in kms or vm",
|
|
194468
|
-
NOT_FOUND2,
|
|
194469
|
-
verificationMethod
|
|
194470
|
-
);
|
|
194471
|
-
}
|
|
194472
|
-
const multikey = SchnorrMultikey2.create({ id, controller, keys });
|
|
194473
|
-
if (!multikey) {
|
|
194474
|
-
throw new MethodError2(
|
|
194475
|
-
"Failed to create multikey from verification method",
|
|
194476
|
-
"MULTKEY_CREATE_FAILED",
|
|
194477
|
-
verificationMethod
|
|
194478
|
-
);
|
|
194479
|
-
}
|
|
194480
|
-
const rootCapability = Appendix.deriveRootCapability(identifier);
|
|
194481
|
-
const cryptosuite = "bip340-jcs-2025";
|
|
193842
|
+
static async sign(did, unsignedUpdate, verificationMethod, secretKey) {
|
|
193843
|
+
const controller = verificationMethod.controller;
|
|
193844
|
+
const id = verificationMethod.id.slice(verificationMethod.id.indexOf("#"));
|
|
193845
|
+
const multikey = SchnorrMultikey2.fromSecretKey(id, controller, secretKey);
|
|
194482
193846
|
const config = {
|
|
194483
193847
|
"@context": [
|
|
194484
193848
|
"https://w3id.org/security/v2",
|
|
@@ -194486,62 +193850,37 @@ a=end-of-candidates
|
|
|
194486
193850
|
"https://w3id.org/json-ld-patch/v1",
|
|
194487
193851
|
"https://btcr2.dev/context/v1"
|
|
194488
193852
|
],
|
|
194489
|
-
cryptosuite,
|
|
193853
|
+
cryptosuite: "bip340-jcs-2025",
|
|
194490
193854
|
type: "DataIntegrityProof",
|
|
194491
|
-
verificationMethod:
|
|
193855
|
+
verificationMethod: verificationMethod.id,
|
|
194492
193856
|
proofPurpose: "capabilityInvocation",
|
|
194493
|
-
capability:
|
|
193857
|
+
capability: `urn:zcap:root:${encodeURIComponent(did)}`,
|
|
194494
193858
|
capabilityAction: "Write"
|
|
194495
193859
|
};
|
|
194496
193860
|
const diproof = multikey.toCryptosuite().toDataIntegrityProof();
|
|
194497
|
-
return
|
|
193861
|
+
return diproof.addProof(unsignedUpdate, config);
|
|
194498
193862
|
}
|
|
194499
193863
|
/**
|
|
194500
|
-
* Implements {@link https://dcdpr.github.io/did-btcr2
|
|
194501
|
-
*
|
|
194502
|
-
*
|
|
194503
|
-
*
|
|
194504
|
-
*
|
|
194505
|
-
* data to validate the Beacon Signal
|
|
194506
|
-
*
|
|
194507
|
-
* @param {AnnounceUpdatePayloadParams} params Required params for calling the announcePayload method
|
|
194508
|
-
* @param {DidDocument} params.sourceDocument The did-btcr2 did document to derive the root capability from
|
|
194509
|
-
* @param {string[]} params.beaconIds The BTCR2SignedUpdate object to be signed
|
|
194510
|
-
* @param {BTCR2SignedUpdate} params.BTCR2SignedUpdate The verificationMethod object to be used for signing
|
|
194511
|
-
* @returns {BTCR2SignedUpdate} The BTCR2SignedUpdate object containing data to validate the Beacon Signal
|
|
194512
|
-
* @throws {MethodError} if the beaconService type is invalid
|
|
193864
|
+
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/update.html#announce-did-update | 7.3.d Announce DID Update}.
|
|
193865
|
+
* BTCR2 Signed Updates are announced to the Bitcoin blockchain depending on the Beacon Type.
|
|
193866
|
+
* @param {BeaconService} beaconService The BeaconService object representing the funded beacon to announce the update to.
|
|
193867
|
+
* @param {SignedBTCR2Update} update The signed update object to be announced.
|
|
193868
|
+
* @param {KeyBytes} secretKey The private key used to sign the update for announcement.
|
|
193869
|
+
* @returns {SignedBTCR2Update} The SignedBTCR2Update object containing data to validate the Beacon Signal
|
|
193870
|
+
* @throws {UpdateError} if the beaconService type is invalid
|
|
194513
193871
|
*/
|
|
194514
|
-
static async announce({
|
|
194515
|
-
|
|
194516
|
-
|
|
194517
|
-
|
|
194518
|
-
}) {
|
|
194519
|
-
const beaconServices = [];
|
|
194520
|
-
let sidecarData;
|
|
194521
|
-
for (const beaconId of beaconIds) {
|
|
194522
|
-
const beaconService = sourceDocument.service.find((s2) => s2.id === beaconId);
|
|
194523
|
-
if (!beaconService) {
|
|
194524
|
-
throw new MethodError2("Not found: sourceDocument does not contain beaconId", INVALID_DID_DOCUMENT2, { beaconId });
|
|
194525
|
-
}
|
|
194526
|
-
beaconServices.push(beaconService);
|
|
194527
|
-
}
|
|
194528
|
-
for (const beaconService of beaconServices) {
|
|
194529
|
-
console.log("TODO: refactor this code", signedUpdate, beaconService);
|
|
194530
|
-
}
|
|
194531
|
-
if (!sidecarData) {
|
|
194532
|
-
throw new MethodError2(
|
|
194533
|
-
"Invalid beacon: no sidecarData found",
|
|
194534
|
-
INVALID_DID_DOCUMENT2,
|
|
194535
|
-
{ beaconServices }
|
|
194536
|
-
);
|
|
194537
|
-
}
|
|
194538
|
-
return sidecarData;
|
|
193872
|
+
static async announce(beaconService, update, secretKey, bitcoin32) {
|
|
193873
|
+
const beacon = BeaconFactory.establish(beaconService);
|
|
193874
|
+
const result = await beacon.broadcastSignal(update, secretKey, bitcoin32);
|
|
193875
|
+
return result;
|
|
194539
193876
|
}
|
|
194540
193877
|
};
|
|
194541
193878
|
var canonicalization22 = new Canonicalization2();
|
|
194542
193879
|
initEccLib2(tinysecp32);
|
|
194543
193880
|
var DidBtcr2 = class {
|
|
194544
|
-
/**
|
|
193881
|
+
/**
|
|
193882
|
+
* Name of the DID method, as defined in the DID BTCR2 specification
|
|
193883
|
+
*/
|
|
194545
193884
|
static methodName = "btcr2";
|
|
194546
193885
|
/**
|
|
194547
193886
|
* Implements section {@link https://dcdpr.github.io/did-btcr2/operations/create.html | 7.1 Create}.
|
|
@@ -194566,7 +193905,7 @@ a=end-of-candidates
|
|
|
194566
193905
|
return Identifier.encode({ idType, genesisBytes, version: version3, network });
|
|
194567
193906
|
}
|
|
194568
193907
|
/**
|
|
194569
|
-
* Entry point for section {@link https://dcdpr.github.io/did-btcr2
|
|
193908
|
+
* Entry point for section {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html | 7.2 Resolve}.
|
|
194570
193909
|
* See specification for the {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process | Resolve Process}.
|
|
194571
193910
|
* See {@link Resolve | Resolve (class)} for class implementation.
|
|
194572
193911
|
*
|
|
@@ -194575,14 +193914,10 @@ a=end-of-candidates
|
|
|
194575
193914
|
* blockchain by Authorized Beacon Signals. The Initial DID Document is either
|
|
194576
193915
|
* deterministically created from the DID or provided by Sidecar Data.
|
|
194577
193916
|
*
|
|
194578
|
-
* @param {string} did
|
|
194579
|
-
* @param {ResolutionOptions} resolutionOptions
|
|
194580
|
-
* @param {number} resolutionOptions.versionId optional version of the identifier and/or DID document
|
|
194581
|
-
* @param {number} resolutionOptions.versionTime optional timestamp used during resolution as a bound for when to stop resolving
|
|
194582
|
-
* @param {DidDocument} resolutionOptions.sidecar optional data necessary for resolving a DID
|
|
193917
|
+
* @param {string} did The did:btcr2 identifier to be resolved.
|
|
193918
|
+
* @param {ResolutionOptions} resolutionOptions Options used during the resolution process.
|
|
194583
193919
|
* @returns {Promise<DidResolutionResult>} Promise resolving to a DID Resolution Result containing the `targetDocument`
|
|
194584
|
-
* @throws {
|
|
194585
|
-
* @throws {DidError} InvalidDid if the identifier is invalid
|
|
193920
|
+
* @throws {ResolveError} If the resolution process fails at any step.
|
|
194586
193921
|
* @example
|
|
194587
193922
|
* ```ts
|
|
194588
193923
|
* const resolution = await DidBtcr2.resolve(
|
|
@@ -194604,8 +193939,9 @@ a=end-of-candidates
|
|
|
194604
193939
|
didDocument: null
|
|
194605
193940
|
};
|
|
194606
193941
|
const didComponents = Identifier.decode(did);
|
|
194607
|
-
const sidecarData = Resolve.
|
|
194608
|
-
if (!resolutionOptions
|
|
193942
|
+
const sidecarData = Resolve.sidecarData(resolutionOptions.sidecar);
|
|
193943
|
+
if (!resolutionOptions?.drivers?.bitcoin) {
|
|
193944
|
+
resolutionOptions.drivers = resolutionOptions.drivers || {};
|
|
194609
193945
|
resolutionOptions.drivers.bitcoin = new BitcoinNetworkConnection2();
|
|
194610
193946
|
resolutionOptions.drivers.bitcoin.setActiveNetwork(didComponents.network);
|
|
194611
193947
|
}
|
|
@@ -194618,20 +193954,21 @@ a=end-of-candidates
|
|
|
194618
193954
|
{ resolutionOptions }
|
|
194619
193955
|
);
|
|
194620
193956
|
}
|
|
194621
|
-
const currentDocument = await Resolve.
|
|
193957
|
+
const currentDocument = await Resolve.currentDocument(didComponents, genesisDocument);
|
|
194622
193958
|
const beaconServices = currentDocument.service.filter(BeaconUtils.isBeaconService).map(BeaconUtils.parseBeaconServiceEndpoint);
|
|
194623
|
-
|
|
193959
|
+
console.log("beaconServices", beaconServices);
|
|
193960
|
+
const unsortedUpdates = await Resolve.beaconSignals(
|
|
194624
193961
|
beaconServices,
|
|
194625
193962
|
sidecarData,
|
|
194626
|
-
resolutionOptions.drivers.bitcoin
|
|
194627
|
-
resolutionOptions.fullBlockchainTraversal
|
|
193963
|
+
resolutionOptions.drivers.bitcoin
|
|
194628
193964
|
);
|
|
193965
|
+
console.log("unsortedUpdates", unsortedUpdates);
|
|
194629
193966
|
if (!unsortedUpdates.length) {
|
|
194630
193967
|
didResolutionResult.didDocument = currentDocument;
|
|
194631
193968
|
didResolutionResult.didDocumentMetadata.deactivated = !!currentDocument.deactivated;
|
|
194632
193969
|
return didResolutionResult;
|
|
194633
193970
|
}
|
|
194634
|
-
const result = await Resolve.
|
|
193971
|
+
const result = await Resolve.updates(
|
|
194635
193972
|
currentDocument,
|
|
194636
193973
|
unsortedUpdates,
|
|
194637
193974
|
resolutionOptions.versionTime,
|
|
@@ -194655,68 +193992,90 @@ a=end-of-candidates
|
|
|
194655
193992
|
}
|
|
194656
193993
|
}
|
|
194657
193994
|
/**
|
|
194658
|
-
* Entry point for section {@link https://dcdpr.github.io/did-btcr2/#
|
|
194659
|
-
* See {@link
|
|
194660
|
-
*
|
|
194661
|
-
*
|
|
194662
|
-
*
|
|
194663
|
-
*
|
|
194664
|
-
*
|
|
194665
|
-
*
|
|
194666
|
-
*
|
|
194667
|
-
*
|
|
194668
|
-
*
|
|
194669
|
-
*
|
|
194670
|
-
*
|
|
194671
|
-
*
|
|
194672
|
-
*
|
|
194673
|
-
*
|
|
194674
|
-
* @
|
|
194675
|
-
*
|
|
194676
|
-
|
|
194677
|
-
|
|
194678
|
-
|
|
194679
|
-
|
|
194680
|
-
|
|
194681
|
-
|
|
194682
|
-
|
|
194683
|
-
|
|
194684
|
-
|
|
194685
|
-
|
|
194686
|
-
|
|
194687
|
-
|
|
194688
|
-
|
|
194689
|
-
|
|
194690
|
-
|
|
194691
|
-
|
|
194692
|
-
}
|
|
194693
|
-
const
|
|
194694
|
-
|
|
194695
|
-
|
|
194696
|
-
|
|
194697
|
-
|
|
194698
|
-
|
|
194699
|
-
|
|
193995
|
+
* Entry point for section {@link https://dcdpr.github.io/did-btcr2/#read | 7.3 Update}.
|
|
193996
|
+
* See specification for the {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process | Resolve Process}.
|
|
193997
|
+
* See {@link Update | Update (class)} for class implementation.
|
|
193998
|
+
*
|
|
193999
|
+
* BTCR2 DID documents can be updated by anchoring BTCR2 Updates to Bitcoin transactions. These transactions MAY be
|
|
194000
|
+
* published to the Bitcoin network. Any property in the DID document may be updated except the id. Doing so would
|
|
194001
|
+
* invalidate the DID document.
|
|
194002
|
+
* @param params An object containing the parameters for the update operation.
|
|
194003
|
+
* @param {Btcr2DidDocument} params.sourceDocument The DID document being updated.
|
|
194004
|
+
* @param {PatchOperation[]} params.patches The array of JSON Patch operations to apply to the sourceDocument.
|
|
194005
|
+
* @param {string} params.sourceVersionId The version ID before applying the update.
|
|
194006
|
+
* @param {string} params.verificationMethodId The verificationMethod ID to sign the update with.
|
|
194007
|
+
* @param {string} params.beaconId The beacon ID associated with the update.
|
|
194008
|
+
* @param {KeyBytes | HexString} [params.signingMaterial] Optional signing material (key bytes or hex string).
|
|
194009
|
+
* @param {BitcoinNetworkConnection} [params.bitcoin] Optional Bitcoin network connection for announcing the update. If not provided, a default connection will be initialized.
|
|
194010
|
+
* @return {Promise<SignedBTCR2Update>} Promise resolving to the signed BTCR2 update.
|
|
194011
|
+
* @throws {UpdateError} if no verificationMethod, verificationMethod type is not `Multikey` or the publicKeyMultibase
|
|
194012
|
+
* header is not `zQ3s`
|
|
194013
|
+
*/
|
|
194014
|
+
static async update({
|
|
194015
|
+
sourceDocument,
|
|
194016
|
+
patches,
|
|
194017
|
+
sourceVersionId,
|
|
194018
|
+
verificationMethodId,
|
|
194019
|
+
beaconId,
|
|
194020
|
+
signingMaterial,
|
|
194021
|
+
bitcoin: bitcoin32
|
|
194022
|
+
}) {
|
|
194023
|
+
if (!signingMaterial) {
|
|
194024
|
+
throw new UpdateError(
|
|
194025
|
+
"Missing signing material for update",
|
|
194026
|
+
INVALID_DID_UPDATE2,
|
|
194027
|
+
{ signingMaterial }
|
|
194028
|
+
);
|
|
194029
|
+
}
|
|
194030
|
+
const secretKey = typeof signingMaterial === "string" ? import_buffer2.Buffer.from(signingMaterial, "hex") : signingMaterial;
|
|
194031
|
+
if (!sourceDocument.capabilityInvocation?.some((vr) => vr === verificationMethodId)) {
|
|
194032
|
+
throw new UpdateError(
|
|
194033
|
+
"Invalid verificationMethodId: not authorized for capabilityInvocation",
|
|
194034
|
+
INVALID_DID_DOCUMENT2,
|
|
194035
|
+
sourceDocument
|
|
194036
|
+
);
|
|
194037
|
+
}
|
|
194038
|
+
const verificationMethod = this.getSigningMethod(sourceDocument, verificationMethodId);
|
|
194700
194039
|
if (!verificationMethod) {
|
|
194701
|
-
throw new
|
|
194040
|
+
throw new UpdateError(
|
|
194041
|
+
"Invalid verificationMethod: not found in source document",
|
|
194042
|
+
INVALID_DID_DOCUMENT2,
|
|
194043
|
+
{ sourceDocument, verificationMethodId }
|
|
194044
|
+
);
|
|
194702
194045
|
}
|
|
194703
194046
|
if (verificationMethod.type !== "Multikey") {
|
|
194704
|
-
throw new
|
|
194047
|
+
throw new UpdateError(
|
|
194048
|
+
'Invalid verificationMethod: verificationMethod.type must be "Multikey"',
|
|
194049
|
+
INVALID_DID_DOCUMENT2,
|
|
194050
|
+
verificationMethod
|
|
194051
|
+
);
|
|
194705
194052
|
}
|
|
194706
|
-
|
|
194707
|
-
|
|
194708
|
-
|
|
194053
|
+
if (verificationMethod.publicKeyMultibase?.slice(0, 4) !== "zQ3s") {
|
|
194054
|
+
throw new UpdateError(
|
|
194055
|
+
'Invalid verificationMethodId: publicKeyMultibase prefix must start with "zQ3s"',
|
|
194056
|
+
INVALID_DID_DOCUMENT2,
|
|
194057
|
+
verificationMethod
|
|
194058
|
+
);
|
|
194709
194059
|
}
|
|
194710
|
-
const
|
|
194711
|
-
const
|
|
194712
|
-
|
|
194060
|
+
const update = await Update.construct(sourceDocument, patches, sourceVersionId);
|
|
194061
|
+
const signed = await Update.sign(sourceDocument.id, update, verificationMethod, secretKey);
|
|
194062
|
+
const beaconService = sourceDocument.service.filter((service) => service.id === beaconId).filter((service) => !!service).shift();
|
|
194063
|
+
if (!beaconService) {
|
|
194064
|
+
throw new UpdateError(
|
|
194065
|
+
"No beacon service found for provided beaconId",
|
|
194066
|
+
INVALID_DID_UPDATE2,
|
|
194067
|
+
{ sourceDocument, beaconId }
|
|
194068
|
+
);
|
|
194069
|
+
}
|
|
194070
|
+
bitcoin32 ??= new BitcoinNetworkConnection2();
|
|
194071
|
+
return signed;
|
|
194713
194072
|
}
|
|
194714
194073
|
/**
|
|
194715
194074
|
* Given the W3C DID Document of a `did:btcr2` identifier, return the signing verification method that will be used
|
|
194716
194075
|
* for signing messages and credentials. If given, the `methodId` parameter is used to select the
|
|
194717
194076
|
* verification method. If not given, the Identity Key's verification method with an ID fragment
|
|
194718
194077
|
* of '#initialKey' is used.
|
|
194719
|
-
* @param {
|
|
194078
|
+
* @param {Btcr2DidDocument} didDocument The DID Document of the `did:btcr2` identifier.
|
|
194720
194079
|
* @param {string} [methodId] Optional verification method ID to be used for signing.
|
|
194721
194080
|
* @returns {DidVerificationMethod} Promise resolving to the {@link DidVerificationMethod} object used for signing.
|
|
194722
194081
|
* @throws {DidError} if the parsed did method does not match `btcr2` or signing method could not be determined.
|
|
@@ -194739,43 +194098,25 @@ a=end-of-candidates
|
|
|
194739
194098
|
return verificationMethod;
|
|
194740
194099
|
}
|
|
194741
194100
|
};
|
|
194742
|
-
var SingletonBeacon = class
|
|
194101
|
+
var SingletonBeacon = class extends Beacon {
|
|
194743
194102
|
/**
|
|
194744
194103
|
* Creates an instance of SingletonBeacon.
|
|
194745
|
-
* @param {BeaconService} service The
|
|
194746
|
-
*
|
|
194747
|
-
*/
|
|
194748
|
-
constructor(service, signals, sidecar, bitcoin32) {
|
|
194749
|
-
super({ ...service, type: "SingletonBeacon" }, signals, sidecar, bitcoin32);
|
|
194750
|
-
}
|
|
194751
|
-
/**
|
|
194752
|
-
* Static, convenience method for establishing a CASBeacon object.
|
|
194753
|
-
* @param {string} service The Beacon service.
|
|
194754
|
-
* @param {SidecarData} sidecar The sidecar data.
|
|
194755
|
-
* @returns {SingletonBeacon} The Singleton Beacon.
|
|
194756
|
-
*/
|
|
194757
|
-
static establish(service, signals, sidecar) {
|
|
194758
|
-
return new _SingletonBeacon(service, signals, sidecar);
|
|
194759
|
-
}
|
|
194760
|
-
/**
|
|
194761
|
-
* Generates a Beacon Signal for a Singleton Beacon Service.
|
|
194762
|
-
* @param {HexString} updateHash The update hash to be included in the Beacon Signal.
|
|
194763
|
-
* @returns {BeaconSignal} The generated signal.
|
|
194764
|
-
* @throws {MethodError} if the signal is invalid.
|
|
194104
|
+
* @param {BeaconService} service The BeaconService object representing the funded beacon to announce the update to.
|
|
194105
|
+
*
|
|
194765
194106
|
*/
|
|
194766
|
-
|
|
194767
|
-
|
|
194107
|
+
constructor(service) {
|
|
194108
|
+
super({ ...service, type: "SingletonBeacon" });
|
|
194768
194109
|
}
|
|
194769
194110
|
/**
|
|
194770
194111
|
* Processes an array of Beacon Signals associated with a Singleton Beacon Service.
|
|
194771
|
-
* @returns {Promise<
|
|
194112
|
+
* @returns {Promise<SignedBTCR2Update | undefined>} The DID Update payload announced by the Beacon Signal.
|
|
194772
194113
|
* @throws {SingletonBeaconError} if the signalTx is invalid or the signalSidecarData is invalid.
|
|
194773
194114
|
*/
|
|
194774
|
-
async processSignals() {
|
|
194115
|
+
async processSignals(signals, sidecar) {
|
|
194775
194116
|
const updates = new Array();
|
|
194776
|
-
for (const signal of
|
|
194117
|
+
for (const signal of signals) {
|
|
194777
194118
|
const updateHash = signal.signalBytes;
|
|
194778
|
-
const signedUpdate =
|
|
194119
|
+
const signedUpdate = sidecar.updateMap.get(updateHash);
|
|
194779
194120
|
if (!signedUpdate) {
|
|
194780
194121
|
throw new SingletonBeaconError(
|
|
194781
194122
|
`BTCR2 Signed Update not found for update hash ${updateHash}.`,
|
|
@@ -194797,19 +194138,26 @@ a=end-of-candidates
|
|
|
194797
194138
|
return updates;
|
|
194798
194139
|
}
|
|
194799
194140
|
/**
|
|
194800
|
-
* Broadcasts a SingletonBeacon signal.
|
|
194801
|
-
*
|
|
194802
|
-
*
|
|
194803
|
-
* @
|
|
194141
|
+
* Broadcasts a SingletonBeacon signal to the Bitcoin network.
|
|
194142
|
+
* @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
|
|
194143
|
+
* @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
|
|
194144
|
+
* @param {BitcoinNetworkConnection} bitcoin The Bitcoin network connection.
|
|
194145
|
+
* @returns {Promise<SignedBTCR2Update>} The signed update that was broadcast.
|
|
194804
194146
|
* @throws {SingletonBeaconError} if the bitcoin address is invalid or unfunded.
|
|
194805
194147
|
*/
|
|
194806
|
-
async broadcastSignal(
|
|
194148
|
+
async broadcastSignal(signedUpdate, secretKey, bitcoin32) {
|
|
194807
194149
|
const bitcoinAddress = this.service.serviceEndpoint.replace("bitcoin:", "");
|
|
194808
|
-
const utxos = await
|
|
194150
|
+
const utxos = await bitcoin32.network.rest.address.getUtxos(bitcoinAddress);
|
|
194809
194151
|
if (!utxos.length) {
|
|
194810
|
-
throw new SingletonBeaconError(
|
|
194152
|
+
throw new SingletonBeaconError(
|
|
194153
|
+
"No UTXOs found, please fund address!",
|
|
194154
|
+
"UNFUNDED_BEACON_ADDRESS",
|
|
194155
|
+
{ bitcoinAddress }
|
|
194156
|
+
);
|
|
194811
194157
|
}
|
|
194812
|
-
const utxo = utxos.sort(
|
|
194158
|
+
const utxo = utxos.sort(
|
|
194159
|
+
(a3, b22) => b22.status.block_height - a3.status.block_height
|
|
194160
|
+
).shift();
|
|
194813
194161
|
if (!utxo) {
|
|
194814
194162
|
throw new SingletonBeaconError(
|
|
194815
194163
|
"Beacon bitcoin address unfunded or utxos unconfirmed.",
|
|
@@ -194817,99 +194165,69 @@ a=end-of-candidates
|
|
|
194817
194165
|
{ bitcoinAddress }
|
|
194818
194166
|
);
|
|
194819
194167
|
}
|
|
194820
|
-
const
|
|
194821
|
-
|
|
194822
|
-
|
|
194823
|
-
|
|
194824
|
-
|
|
194825
|
-
const prevTx = await this.bitcoin.network.rest.transaction.getHex(txid);
|
|
194826
|
-
const input = {
|
|
194827
|
-
hash: txid,
|
|
194828
|
-
index: vout,
|
|
194168
|
+
const prevTx = await bitcoin32.network.rest.transaction.getHex(utxo.txid);
|
|
194169
|
+
const updateHash = canonicalization22.canonicalhash(signedUpdate);
|
|
194170
|
+
const spendTx = new Psbt22({ network: bitcoin32.network.data }).addInput({
|
|
194171
|
+
hash: utxo.txid,
|
|
194172
|
+
index: utxo.vout,
|
|
194829
194173
|
nonWitnessUtxo: import_buffer2.Buffer.from(prevTx, "hex")
|
|
194830
|
-
};
|
|
194831
|
-
const
|
|
194832
|
-
const components = Identifier.decode(this.service.id);
|
|
194833
|
-
const keyUri = new CompressedSecp256k1PublicKey2(components.genesisBytes).hex;
|
|
194834
|
-
const keyPair = Kms.getKey(keyUri);
|
|
194174
|
+
}).addOutput({ address: bitcoinAddress, value: BigInt(utxo.value) - BigInt(500) }).addOutput({ script: script_exports2.compile([OPS9.OP_RETURN, updateHash]), value: 0n });
|
|
194175
|
+
const keyPair = SchnorrKeyPair2.fromSecret(secretKey);
|
|
194835
194176
|
if (!keyPair) {
|
|
194836
|
-
throw new
|
|
194177
|
+
throw new SingletonBeaconError("Key pair not found.", "KEY_PAIR_NOT_FOUND", { secretKey });
|
|
194837
194178
|
}
|
|
194838
|
-
const signer = new Signer({ keyPair, network:
|
|
194179
|
+
const signer = new Signer({ keyPair, network: bitcoin32.network.name });
|
|
194839
194180
|
const signedTx = spendTx.signInput(0, signer).finalizeAllInputs().extractTransaction().toHex();
|
|
194840
|
-
|
|
194841
|
-
|
|
194842
|
-
|
|
194843
|
-
const spentTx = await this.bitcoin.network.rest.transaction.send(signedTx);
|
|
194844
|
-
if (!spentTx) {
|
|
194845
|
-
throw new SingletonBeaconError("Failed to send raw transaction.", "SEND_FAILED", { spentTx });
|
|
194846
|
-
}
|
|
194847
|
-
return spentTx;
|
|
194181
|
+
const txid = await bitcoin32.network.rest.transaction.send(signedTx);
|
|
194182
|
+
console.info(`Broadcasted Singleton Beacon signal with txid ${txid}`);
|
|
194183
|
+
return signedUpdate;
|
|
194848
194184
|
}
|
|
194849
194185
|
};
|
|
194850
194186
|
init_shim2();
|
|
194851
|
-
var SMTBeacon = class
|
|
194187
|
+
var SMTBeacon = class extends Beacon {
|
|
194852
194188
|
/**
|
|
194853
|
-
* Creates an instance of
|
|
194189
|
+
* Creates an instance of SMTBeacon.
|
|
194854
194190
|
* @param {BeaconService} service The Beacon service.
|
|
194855
|
-
* @param {Array<BeaconSignal>} signals The SingletonBeacon sidecar data.
|
|
194856
|
-
* @param {SidecarData} sidecar The sidecar data.
|
|
194857
|
-
*/
|
|
194858
|
-
constructor(service, signals, sidecar, bitcoin32) {
|
|
194859
|
-
super({ ...service, type: "SMTBeacon" }, signals, sidecar, bitcoin32);
|
|
194860
|
-
}
|
|
194861
|
-
/**
|
|
194862
|
-
* Static, convenience method for establishing a SMTBeacon object.
|
|
194863
|
-
* @param {string} service The Beacon service.
|
|
194864
|
-
* @param {SidecarData} sidecar The sidecar data.
|
|
194865
|
-
* @returns {SingletonBeacon} The Singleton Beacon.
|
|
194866
194191
|
*/
|
|
194867
|
-
|
|
194868
|
-
|
|
194192
|
+
constructor(service) {
|
|
194193
|
+
super({ ...service, type: "SMTBeacon" });
|
|
194869
194194
|
}
|
|
194870
194195
|
/**
|
|
194871
|
-
*
|
|
194872
|
-
* @param {
|
|
194873
|
-
* @
|
|
194874
|
-
* @
|
|
194196
|
+
* Implements {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-smt-beacon | 7.2.e.1 Process SMT Beacon}.
|
|
194197
|
+
* @param {Array<BeaconSignal>} signals The array of Beacon Signals to process.
|
|
194198
|
+
* @param {SidecarData} sidecar The sidecar data associated with the SMT Beacon.
|
|
194199
|
+
* @returns {Promise<Array<[SignedBTCR2Update, BlockMetadata]>>} The processed signals.
|
|
194200
|
+
* @throws {SMTBeaconError} if processing fails.
|
|
194875
194201
|
*/
|
|
194876
|
-
|
|
194877
|
-
throw new
|
|
194202
|
+
processSignals(signals, sidecar) {
|
|
194203
|
+
throw new SMTBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signals, sidecar });
|
|
194878
194204
|
}
|
|
194879
194205
|
/**
|
|
194880
|
-
*
|
|
194881
|
-
* @
|
|
194882
|
-
* @
|
|
194206
|
+
* Broadcast CAS Beacon signal to the Bitcoin network.
|
|
194207
|
+
* @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
|
|
194208
|
+
* @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
|
|
194209
|
+
* @param {BitcoinNetworkConnection} bitcoin The Bitcoin network connection.
|
|
194210
|
+
* @return {Promise<SignedBTCR2Update>} The signed update that was broadcasted.
|
|
194211
|
+
* @throws {SMTBeaconError} if broadcasting fails.
|
|
194883
194212
|
*/
|
|
194884
|
-
async
|
|
194885
|
-
throw new
|
|
194886
|
-
}
|
|
194887
|
-
/**
|
|
194888
|
-
* Broadcast a SMTBeacon signal.
|
|
194889
|
-
* @param {HexString} updateHash The hash of the BTCR2 update to broadcast.
|
|
194890
|
-
* @returns {Promise<SignalsMetadata>} The result of the broadcast.
|
|
194891
|
-
* @throws {MethodError} if the broadcast fails.
|
|
194892
|
-
*/
|
|
194893
|
-
async broadcastSignal(updateHash) {
|
|
194894
|
-
throw new MethodError2("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { updateHash });
|
|
194213
|
+
async broadcastSignal(signedUpdate, secretKey, bitcoin32) {
|
|
194214
|
+
throw new SMTBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signedUpdate, secretKey, bitcoin: bitcoin32 });
|
|
194895
194215
|
}
|
|
194896
194216
|
};
|
|
194897
194217
|
var BeaconFactory = class {
|
|
194898
194218
|
/**
|
|
194899
194219
|
* Establish a Beacon instance based on the provided service and optional sidecar data.
|
|
194900
|
-
* @param {BeaconService} service
|
|
194901
|
-
* @param {Array<BeaconSignal>} signals - The array of beacon signals.
|
|
194902
|
-
* @param {SidecarData} sidecar - The sidecar data associated with the beacon.
|
|
194220
|
+
* @param {BeaconService} service The beacon service configuration.
|
|
194903
194221
|
* @returns {Beacon} The established Beacon instance.
|
|
194904
194222
|
*/
|
|
194905
|
-
static establish(service
|
|
194223
|
+
static establish(service) {
|
|
194906
194224
|
switch (service.type) {
|
|
194907
194225
|
case "SingletonBeacon":
|
|
194908
|
-
return new SingletonBeacon(service
|
|
194226
|
+
return new SingletonBeacon(service);
|
|
194909
194227
|
case "CASBeacon":
|
|
194910
|
-
return new CASBeacon(service
|
|
194228
|
+
return new CASBeacon(service);
|
|
194911
194229
|
case "SMTBeacon":
|
|
194912
|
-
return new SMTBeacon(service
|
|
194230
|
+
return new SMTBeacon(service);
|
|
194913
194231
|
default:
|
|
194914
194232
|
throw new MethodError2("Invalid Beacon Type", "INVALID_BEACON_ERROR", service);
|
|
194915
194233
|
}
|
|
@@ -194918,6 +194236,7 @@ a=end-of-candidates
|
|
|
194918
194236
|
init_shim2();
|
|
194919
194237
|
init_shim2();
|
|
194920
194238
|
init_shim2();
|
|
194239
|
+
init_shim2();
|
|
194921
194240
|
var DidDocumentBuilder = class {
|
|
194922
194241
|
document = {};
|
|
194923
194242
|
constructor(initialDocument) {
|
|
@@ -197123,22 +196442,23 @@ zoo`.split("\n");
|
|
|
197123
196442
|
* This delegates to MethodUpdate (which follows the cryptosuite rules internally).
|
|
197124
196443
|
*/
|
|
197125
196444
|
async update({
|
|
197126
|
-
identifier,
|
|
197127
196445
|
sourceDocument,
|
|
196446
|
+
patches,
|
|
197128
196447
|
sourceVersionId,
|
|
197129
|
-
patch,
|
|
197130
196448
|
verificationMethodId,
|
|
197131
|
-
|
|
196449
|
+
beaconId,
|
|
196450
|
+
signingMaterial,
|
|
196451
|
+
bitcoin: bitcoin4
|
|
197132
196452
|
}) {
|
|
197133
|
-
|
|
197134
|
-
identifier,
|
|
196453
|
+
return await DidBtcr2.update({
|
|
197135
196454
|
sourceDocument,
|
|
196455
|
+
patches,
|
|
197136
196456
|
sourceVersionId,
|
|
197137
|
-
patch,
|
|
197138
196457
|
verificationMethodId,
|
|
197139
|
-
|
|
196458
|
+
beaconId,
|
|
196459
|
+
signingMaterial,
|
|
196460
|
+
bitcoin: bitcoin4
|
|
197140
196461
|
});
|
|
197141
|
-
return result;
|
|
197142
196462
|
}
|
|
197143
196463
|
/** Deactivate convenience: applies the standard `deactivated: true` patch. */
|
|
197144
196464
|
async deactivate() {
|
|
@@ -197347,9 +196667,6 @@ fast-json-patch/module/duplex.mjs:
|
|
|
197347
196667
|
@scure/bip39/esm/index.js:
|
|
197348
196668
|
(*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
|
|
197349
196669
|
|
|
197350
|
-
@noble/hashes/utils.js:
|
|
197351
|
-
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
197352
|
-
|
|
197353
196670
|
@noble/hashes/esm/utils.js:
|
|
197354
196671
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
197355
196672
|
|