@did-btcr2/method 0.19.0 → 0.20.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 +715 -1445
- package/dist/browser.mjs +715 -1445
- package/dist/cjs/core/beacon/beacon.js +25 -0
- package/dist/cjs/core/beacon/beacon.js.map +1 -0
- package/dist/cjs/core/beacon/cas-beacon.js +20 -36
- package/dist/cjs/core/beacon/cas-beacon.js.map +1 -1
- package/dist/cjs/core/beacon/error.js +4 -4
- package/dist/cjs/core/beacon/error.js.map +1 -1
- package/dist/cjs/core/beacon/factory.js +5 -7
- package/dist/cjs/core/beacon/factory.js.map +1 -1
- package/dist/cjs/core/beacon/interfaces.js +1 -31
- package/dist/cjs/core/beacon/interfaces.js.map +1 -1
- package/dist/cjs/core/beacon/signal-discovery.js +183 -0
- package/dist/cjs/core/beacon/signal-discovery.js.map +1 -0
- package/dist/cjs/core/beacon/singleton.js +54 -81
- package/dist/cjs/core/beacon/singleton.js.map +1 -1
- package/dist/cjs/core/beacon/smt-beacon.js +22 -39
- package/dist/cjs/core/beacon/smt-beacon.js.map +1 -1
- package/dist/cjs/core/beacon/utils.js +4 -9
- package/dist/cjs/core/beacon/utils.js.map +1 -1
- package/dist/cjs/core/resolve.js +87 -277
- package/dist/cjs/core/resolve.js.map +1 -1
- package/dist/cjs/core/update.js +62 -153
- package/dist/cjs/core/update.js.map +1 -1
- package/dist/cjs/did-btcr2.js +80 -75
- package/dist/cjs/did-btcr2.js.map +1 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utils/appendix.js +6 -15
- package/dist/cjs/utils/appendix.js.map +1 -1
- package/dist/cjs/utils/did-document-builder.js +5 -0
- package/dist/cjs/utils/did-document-builder.js.map +1 -1
- package/dist/cjs/utils/did-document.js +11 -14
- package/dist/cjs/utils/did-document.js.map +1 -1
- package/dist/esm/core/beacon/beacon.js +25 -0
- package/dist/esm/core/beacon/beacon.js.map +1 -0
- package/dist/esm/core/beacon/cas-beacon.js +20 -36
- package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
- package/dist/esm/core/beacon/error.js +4 -4
- package/dist/esm/core/beacon/error.js.map +1 -1
- package/dist/esm/core/beacon/factory.js +5 -7
- package/dist/esm/core/beacon/factory.js.map +1 -1
- package/dist/esm/core/beacon/interfaces.js +1 -31
- package/dist/esm/core/beacon/interfaces.js.map +1 -1
- package/dist/esm/core/beacon/signal-discovery.js +183 -0
- package/dist/esm/core/beacon/signal-discovery.js.map +1 -0
- package/dist/esm/core/beacon/singleton.js +54 -81
- package/dist/esm/core/beacon/singleton.js.map +1 -1
- package/dist/esm/core/beacon/smt-beacon.js +22 -39
- package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
- package/dist/esm/core/beacon/utils.js +4 -9
- package/dist/esm/core/beacon/utils.js.map +1 -1
- package/dist/esm/core/resolve.js +87 -277
- package/dist/esm/core/resolve.js.map +1 -1
- package/dist/esm/core/update.js +62 -153
- package/dist/esm/core/update.js.map +1 -1
- package/dist/esm/did-btcr2.js +80 -75
- package/dist/esm/did-btcr2.js.map +1 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/appendix.js +6 -15
- package/dist/esm/utils/appendix.js.map +1 -1
- package/dist/esm/utils/did-document-builder.js +5 -0
- package/dist/esm/utils/did-document-builder.js.map +1 -1
- package/dist/esm/utils/did-document.js +11 -14
- package/dist/esm/utils/did-document.js.map +1 -1
- package/dist/types/core/beacon/beacon.d.ts +44 -0
- package/dist/types/core/beacon/beacon.d.ts.map +1 -0
- package/dist/types/core/beacon/cas-beacon.d.ts +19 -30
- package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/error.d.ts +2 -2
- package/dist/types/core/beacon/error.d.ts.map +1 -1
- package/dist/types/core/beacon/factory.d.ts +4 -6
- package/dist/types/core/beacon/factory.d.ts.map +1 -1
- package/dist/types/core/beacon/interfaces.d.ts +7 -46
- package/dist/types/core/beacon/interfaces.d.ts.map +1 -1
- package/dist/types/core/beacon/signal-discovery.d.ts +25 -0
- package/dist/types/core/beacon/signal-discovery.d.ts.map +1 -0
- package/dist/types/core/beacon/singleton.d.ts +16 -29
- package/dist/types/core/beacon/singleton.d.ts.map +1 -1
- package/dist/types/core/beacon/smt-beacon.d.ts +21 -33
- package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/utils.d.ts.map +1 -1
- package/dist/types/core/interfaces.d.ts +1 -8
- package/dist/types/core/interfaces.d.ts.map +1 -1
- package/dist/types/core/resolve.d.ts +27 -43
- package/dist/types/core/resolve.d.ts.map +1 -1
- package/dist/types/core/types.d.ts +21 -8
- package/dist/types/core/types.d.ts.map +1 -1
- package/dist/types/core/update.d.ts +30 -73
- package/dist/types/core/update.d.ts.map +1 -1
- package/dist/types/did-btcr2.d.ts +37 -44
- package/dist/types/did-btcr2.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/utils/appendix.d.ts.map +1 -1
- package/dist/types/utils/did-document-builder.d.ts +5 -0
- package/dist/types/utils/did-document-builder.d.ts.map +1 -1
- package/dist/types/utils/did-document.d.ts +16 -14
- package/dist/types/utils/did-document.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/core/beacon/beacon.ts +58 -0
- package/src/core/beacon/cas-beacon.ts +30 -44
- package/src/core/beacon/error.ts +5 -6
- package/src/core/beacon/factory.ts +7 -9
- package/src/core/beacon/interfaces.ts +7 -64
- package/src/core/beacon/signal-discovery.ts +237 -0
- package/src/core/beacon/singleton.ts +74 -94
- package/src/core/beacon/smt-beacon.ts +32 -49
- package/src/core/beacon/utils.ts +16 -13
- package/src/core/interfaces.ts +1 -9
- package/src/core/resolve.ts +116 -360
- package/src/core/types.ts +25 -8
- package/src/core/update.ts +90 -235
- package/src/did-btcr2.ts +131 -95
- package/src/index.ts +8 -1
- package/src/utils/appendix.ts +8 -22
- package/src/utils/did-document-builder.ts +5 -0
- package/src/utils/did-document.ts +41 -45
package/dist/browser.mjs
CHANGED
|
@@ -1972,17 +1972,17 @@ var require_utils = __commonJS({
|
|
|
1972
1972
|
init_shim();
|
|
1973
1973
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1974
1974
|
exports.wrapXOFConstructorWithOpts = exports.wrapConstructorWithOpts = exports.wrapConstructor = exports.Hash = exports.nextTick = exports.swap32IfBE = exports.byteSwapIfBE = exports.swap8IfBE = exports.isLE = void 0;
|
|
1975
|
-
exports.isBytes =
|
|
1975
|
+
exports.isBytes = isBytes12;
|
|
1976
1976
|
exports.anumber = anumber4;
|
|
1977
|
-
exports.abytes =
|
|
1977
|
+
exports.abytes = abytes5;
|
|
1978
1978
|
exports.ahash = ahash2;
|
|
1979
|
-
exports.aexists =
|
|
1980
|
-
exports.aoutput =
|
|
1979
|
+
exports.aexists = aexists3;
|
|
1980
|
+
exports.aoutput = aoutput3;
|
|
1981
1981
|
exports.u8 = u82;
|
|
1982
1982
|
exports.u32 = u323;
|
|
1983
|
-
exports.clean =
|
|
1984
|
-
exports.createView =
|
|
1985
|
-
exports.rotr =
|
|
1983
|
+
exports.clean = clean3;
|
|
1984
|
+
exports.createView = createView9;
|
|
1985
|
+
exports.rotr = rotr6;
|
|
1986
1986
|
exports.rotl = rotl4;
|
|
1987
1987
|
exports.byteSwap = byteSwap;
|
|
1988
1988
|
exports.byteSwap32 = byteSwap32;
|
|
@@ -1995,20 +1995,20 @@ var require_utils = __commonJS({
|
|
|
1995
1995
|
exports.kdfInputToBytes = kdfInputToBytes2;
|
|
1996
1996
|
exports.concatBytes = concatBytes11;
|
|
1997
1997
|
exports.checkOpts = checkOpts4;
|
|
1998
|
-
exports.createHasher =
|
|
1998
|
+
exports.createHasher = createHasher2;
|
|
1999
1999
|
exports.createOptHasher = createOptHasher;
|
|
2000
2000
|
exports.createXOFer = createXOFer;
|
|
2001
2001
|
exports.randomBytes = randomBytes10;
|
|
2002
2002
|
var crypto_1 = require_crypto();
|
|
2003
|
-
function
|
|
2003
|
+
function isBytes12(a3) {
|
|
2004
2004
|
return a3 instanceof Uint8Array || ArrayBuffer.isView(a3) && a3.constructor.name === "Uint8Array";
|
|
2005
2005
|
}
|
|
2006
2006
|
function anumber4(n3) {
|
|
2007
2007
|
if (!Number.isSafeInteger(n3) || n3 < 0)
|
|
2008
2008
|
throw new Error("positive integer expected, got " + n3);
|
|
2009
2009
|
}
|
|
2010
|
-
function
|
|
2011
|
-
if (!
|
|
2010
|
+
function abytes5(b2, ...lengths) {
|
|
2011
|
+
if (!isBytes12(b2))
|
|
2012
2012
|
throw new Error("Uint8Array expected");
|
|
2013
2013
|
if (lengths.length > 0 && !lengths.includes(b2.length))
|
|
2014
2014
|
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b2.length);
|
|
@@ -2019,14 +2019,14 @@ var require_utils = __commonJS({
|
|
|
2019
2019
|
anumber4(h2.outputLen);
|
|
2020
2020
|
anumber4(h2.blockLen);
|
|
2021
2021
|
}
|
|
2022
|
-
function
|
|
2022
|
+
function aexists3(instance3, checkFinished = true) {
|
|
2023
2023
|
if (instance3.destroyed)
|
|
2024
2024
|
throw new Error("Hash instance has been destroyed");
|
|
2025
2025
|
if (checkFinished && instance3.finished)
|
|
2026
2026
|
throw new Error("Hash#digest() has already been called");
|
|
2027
2027
|
}
|
|
2028
|
-
function
|
|
2029
|
-
|
|
2028
|
+
function aoutput3(out, instance3) {
|
|
2029
|
+
abytes5(out);
|
|
2030
2030
|
const min = instance3.outputLen;
|
|
2031
2031
|
if (out.length < min) {
|
|
2032
2032
|
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
@@ -2038,15 +2038,15 @@ var require_utils = __commonJS({
|
|
|
2038
2038
|
function u323(arr) {
|
|
2039
2039
|
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
2040
2040
|
}
|
|
2041
|
-
function
|
|
2041
|
+
function clean3(...arrays) {
|
|
2042
2042
|
for (let i4 = 0; i4 < arrays.length; i4++) {
|
|
2043
2043
|
arrays[i4].fill(0);
|
|
2044
2044
|
}
|
|
2045
2045
|
}
|
|
2046
|
-
function
|
|
2046
|
+
function createView9(arr) {
|
|
2047
2047
|
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
2048
2048
|
}
|
|
2049
|
-
function
|
|
2049
|
+
function rotr6(word2, shift) {
|
|
2050
2050
|
return word2 << 32 - shift | word2 >>> shift;
|
|
2051
2051
|
}
|
|
2052
2052
|
function rotl4(word2, shift) {
|
|
@@ -2071,7 +2071,7 @@ var require_utils = __commonJS({
|
|
|
2071
2071
|
))();
|
|
2072
2072
|
var hexes5 = /* @__PURE__ */ Array.from({ length: 256 }, (_, i4) => i4.toString(16).padStart(2, "0"));
|
|
2073
2073
|
function bytesToHex6(bytes6) {
|
|
2074
|
-
|
|
2074
|
+
abytes5(bytes6);
|
|
2075
2075
|
if (hasHexBuiltin3)
|
|
2076
2076
|
return bytes6.toHex();
|
|
2077
2077
|
let hex3 = "";
|
|
@@ -2136,20 +2136,20 @@ var require_utils = __commonJS({
|
|
|
2136
2136
|
function toBytes8(data) {
|
|
2137
2137
|
if (typeof data === "string")
|
|
2138
2138
|
data = utf8ToBytes11(data);
|
|
2139
|
-
|
|
2139
|
+
abytes5(data);
|
|
2140
2140
|
return data;
|
|
2141
2141
|
}
|
|
2142
2142
|
function kdfInputToBytes2(data) {
|
|
2143
2143
|
if (typeof data === "string")
|
|
2144
2144
|
data = utf8ToBytes11(data);
|
|
2145
|
-
|
|
2145
|
+
abytes5(data);
|
|
2146
2146
|
return data;
|
|
2147
2147
|
}
|
|
2148
2148
|
function concatBytes11(...arrays) {
|
|
2149
2149
|
let sum = 0;
|
|
2150
2150
|
for (let i4 = 0; i4 < arrays.length; i4++) {
|
|
2151
2151
|
const a3 = arrays[i4];
|
|
2152
|
-
|
|
2152
|
+
abytes5(a3);
|
|
2153
2153
|
sum += a3.length;
|
|
2154
2154
|
}
|
|
2155
2155
|
const res = new Uint8Array(sum);
|
|
@@ -2169,7 +2169,7 @@ var require_utils = __commonJS({
|
|
|
2169
2169
|
var Hash7 = class {
|
|
2170
2170
|
};
|
|
2171
2171
|
exports.Hash = Hash7;
|
|
2172
|
-
function
|
|
2172
|
+
function createHasher2(hashCons) {
|
|
2173
2173
|
const hashC = (msg) => hashCons().update(toBytes8(msg)).digest();
|
|
2174
2174
|
const tmp = hashCons();
|
|
2175
2175
|
hashC.outputLen = tmp.outputLen;
|
|
@@ -2193,7 +2193,7 @@ var require_utils = __commonJS({
|
|
|
2193
2193
|
hashC.create = (opts) => hashCons(opts);
|
|
2194
2194
|
return hashC;
|
|
2195
2195
|
}
|
|
2196
|
-
exports.wrapConstructor =
|
|
2196
|
+
exports.wrapConstructor = createHasher2;
|
|
2197
2197
|
exports.wrapConstructorWithOpts = createOptHasher;
|
|
2198
2198
|
exports.wrapXOFConstructorWithOpts = createXOFer;
|
|
2199
2199
|
function randomBytes10(bytesLength = 32) {
|
|
@@ -2216,8 +2216,8 @@ var require_md = __commonJS({
|
|
|
2216
2216
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2217
2217
|
exports.SHA512_IV = exports.SHA384_IV = exports.SHA224_IV = exports.SHA256_IV = exports.HashMD = void 0;
|
|
2218
2218
|
exports.setBigUint64 = setBigUint648;
|
|
2219
|
-
exports.Chi =
|
|
2220
|
-
exports.Maj =
|
|
2219
|
+
exports.Chi = Chi6;
|
|
2220
|
+
exports.Maj = Maj6;
|
|
2221
2221
|
var utils_ts_1 = require_utils();
|
|
2222
2222
|
function setBigUint648(view, byteOffset, value3, isLE7) {
|
|
2223
2223
|
if (typeof view.setBigUint64 === "function")
|
|
@@ -2231,13 +2231,13 @@ var require_md = __commonJS({
|
|
|
2231
2231
|
view.setUint32(byteOffset + h2, wh, isLE7);
|
|
2232
2232
|
view.setUint32(byteOffset + l2, wl, isLE7);
|
|
2233
2233
|
}
|
|
2234
|
-
function
|
|
2234
|
+
function Chi6(a3, b2, c2) {
|
|
2235
2235
|
return a3 & b2 ^ ~a3 & c2;
|
|
2236
2236
|
}
|
|
2237
|
-
function
|
|
2237
|
+
function Maj6(a3, b2, c2) {
|
|
2238
2238
|
return a3 & b2 ^ a3 & c2 ^ b2 & c2;
|
|
2239
2239
|
}
|
|
2240
|
-
var
|
|
2240
|
+
var HashMD3 = class extends utils_ts_1.Hash {
|
|
2241
2241
|
constructor(blockLen, outputLen, padOffset, isLE7) {
|
|
2242
2242
|
super();
|
|
2243
2243
|
this.finished = false;
|
|
@@ -2327,7 +2327,7 @@ var require_md = __commonJS({
|
|
|
2327
2327
|
return this._cloneInto();
|
|
2328
2328
|
}
|
|
2329
2329
|
};
|
|
2330
|
-
exports.HashMD =
|
|
2330
|
+
exports.HashMD = HashMD3;
|
|
2331
2331
|
exports.SHA256_IV = Uint32Array.from([
|
|
2332
2332
|
1779033703,
|
|
2333
2333
|
3144134277,
|
|
@@ -2494,7 +2494,7 @@ var require_sha2 = __commonJS({
|
|
|
2494
2494
|
var _md_ts_1 = require_md();
|
|
2495
2495
|
var u642 = require_u64();
|
|
2496
2496
|
var utils_ts_1 = require_utils();
|
|
2497
|
-
var
|
|
2497
|
+
var SHA256_K6 = /* @__PURE__ */ Uint32Array.from([
|
|
2498
2498
|
1116352408,
|
|
2499
2499
|
1899447441,
|
|
2500
2500
|
3049323471,
|
|
@@ -2560,7 +2560,7 @@ var require_sha2 = __commonJS({
|
|
|
2560
2560
|
3204031479,
|
|
2561
2561
|
3329325298
|
|
2562
2562
|
]);
|
|
2563
|
-
var
|
|
2563
|
+
var SHA256_W6 = /* @__PURE__ */ new Uint32Array(64);
|
|
2564
2564
|
var SHA2566 = class extends _md_ts_1.HashMD {
|
|
2565
2565
|
constructor(outputLen = 32) {
|
|
2566
2566
|
super(64, outputLen, 8, false);
|
|
@@ -2590,18 +2590,18 @@ var require_sha2 = __commonJS({
|
|
|
2590
2590
|
}
|
|
2591
2591
|
process(view, offset) {
|
|
2592
2592
|
for (let i4 = 0; i4 < 16; i4++, offset += 4)
|
|
2593
|
-
|
|
2593
|
+
SHA256_W6[i4] = view.getUint32(offset, false);
|
|
2594
2594
|
for (let i4 = 16; i4 < 64; i4++) {
|
|
2595
|
-
const W15 =
|
|
2596
|
-
const W2 =
|
|
2595
|
+
const W15 = SHA256_W6[i4 - 15];
|
|
2596
|
+
const W2 = SHA256_W6[i4 - 2];
|
|
2597
2597
|
const s0 = (0, utils_ts_1.rotr)(W15, 7) ^ (0, utils_ts_1.rotr)(W15, 18) ^ W15 >>> 3;
|
|
2598
2598
|
const s1 = (0, utils_ts_1.rotr)(W2, 17) ^ (0, utils_ts_1.rotr)(W2, 19) ^ W2 >>> 10;
|
|
2599
|
-
|
|
2599
|
+
SHA256_W6[i4] = s1 + SHA256_W6[i4 - 7] + s0 + SHA256_W6[i4 - 16] | 0;
|
|
2600
2600
|
}
|
|
2601
2601
|
let { A, B, C: C2, D, E, F, G: G2, H } = this;
|
|
2602
2602
|
for (let i4 = 0; i4 < 64; i4++) {
|
|
2603
2603
|
const sigma1 = (0, utils_ts_1.rotr)(E, 6) ^ (0, utils_ts_1.rotr)(E, 11) ^ (0, utils_ts_1.rotr)(E, 25);
|
|
2604
|
-
const T1 = H + sigma1 + (0, _md_ts_1.Chi)(E, F, G2) +
|
|
2604
|
+
const T1 = H + sigma1 + (0, _md_ts_1.Chi)(E, F, G2) + SHA256_K6[i4] + SHA256_W6[i4] | 0;
|
|
2605
2605
|
const sigma0 = (0, utils_ts_1.rotr)(A, 2) ^ (0, utils_ts_1.rotr)(A, 13) ^ (0, utils_ts_1.rotr)(A, 22);
|
|
2606
2606
|
const T2 = sigma0 + (0, _md_ts_1.Maj)(A, B, C2) | 0;
|
|
2607
2607
|
H = G2;
|
|
@@ -2624,7 +2624,7 @@ var require_sha2 = __commonJS({
|
|
|
2624
2624
|
this.set(A, B, C2, D, E, F, G2, H);
|
|
2625
2625
|
}
|
|
2626
2626
|
roundClean() {
|
|
2627
|
-
(0, utils_ts_1.clean)(
|
|
2627
|
+
(0, utils_ts_1.clean)(SHA256_W6);
|
|
2628
2628
|
}
|
|
2629
2629
|
destroy() {
|
|
2630
2630
|
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
@@ -5271,7 +5271,7 @@ var require_hash_to_curve = __commonJS({
|
|
|
5271
5271
|
exports.expand_message_xof = expand_message_xof;
|
|
5272
5272
|
exports.hash_to_field = hash_to_field;
|
|
5273
5273
|
exports.isogenyMap = isogenyMap;
|
|
5274
|
-
exports.createHasher =
|
|
5274
|
+
exports.createHasher = createHasher2;
|
|
5275
5275
|
var utils_ts_1 = require_utils2();
|
|
5276
5276
|
var modular_ts_1 = require_modular();
|
|
5277
5277
|
var os2ip = utils_ts_1.bytesToNumberBE;
|
|
@@ -5386,7 +5386,7 @@ var require_hash_to_curve = __commonJS({
|
|
|
5386
5386
|
};
|
|
5387
5387
|
}
|
|
5388
5388
|
exports._DST_scalar = (0, utils_ts_1.utf8ToBytes)("HashToScalar-");
|
|
5389
|
-
function
|
|
5389
|
+
function createHasher2(Point7, mapToCurve, defaults2) {
|
|
5390
5390
|
if (typeof mapToCurve !== "function")
|
|
5391
5391
|
throw new Error("mapToCurve() must be defined");
|
|
5392
5392
|
function map3(num2) {
|
|
@@ -47620,7 +47620,7 @@ var utils = {
|
|
|
47620
47620
|
};
|
|
47621
47621
|
var genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain(/* @__PURE__ */ radix(58), /* @__PURE__ */ alphabet(abc), /* @__PURE__ */ join(""));
|
|
47622
47622
|
var base58 = /* @__PURE__ */ genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
47623
|
-
var createBase58check = (
|
|
47623
|
+
var createBase58check = (sha25610) => /* @__PURE__ */ chain(checksum(4, (data) => sha25610(sha25610(data))), base58);
|
|
47624
47624
|
var BECH_ALPHABET = /* @__PURE__ */ chain(/* @__PURE__ */ alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), /* @__PURE__ */ join(""));
|
|
47625
47625
|
var POLYMOD_GENERATORS = [996825010, 642813549, 513874426, 1027748829, 705979059];
|
|
47626
47626
|
function bech32Polymod(pre) {
|
|
@@ -48146,7 +48146,7 @@ var _Writer = class {
|
|
|
48146
48146
|
this.buffers.push(new Uint8Array([b2]));
|
|
48147
48147
|
this.pos++;
|
|
48148
48148
|
}
|
|
48149
|
-
finish(
|
|
48149
|
+
finish(clean3 = true) {
|
|
48150
48150
|
if (this.finished)
|
|
48151
48151
|
throw this.err("buffer: finished");
|
|
48152
48152
|
if (this.bitPos)
|
|
@@ -48164,7 +48164,7 @@ var _Writer = class {
|
|
|
48164
48164
|
buf2.set(ptr.ptr.encode(pos), ptr.pos);
|
|
48165
48165
|
pos += ptr.buffer.length;
|
|
48166
48166
|
}
|
|
48167
|
-
if (
|
|
48167
|
+
if (clean3) {
|
|
48168
48168
|
this.buffers = [];
|
|
48169
48169
|
for (const p3 of this.ptrs)
|
|
48170
48170
|
p3.buffer.fill(0);
|
|
@@ -57579,11 +57579,6 @@ var ResolveError = class extends DidMethodError {
|
|
|
57579
57579
|
super(message2, { type, name: "ResolveError", data });
|
|
57580
57580
|
}
|
|
57581
57581
|
};
|
|
57582
|
-
var KeyManagerError = class extends DidMethodError {
|
|
57583
|
-
constructor(message2, type = "KeyManagerError", data) {
|
|
57584
|
-
super(message2, { type, name: type, data });
|
|
57585
|
-
}
|
|
57586
|
-
};
|
|
57587
57582
|
var DidDocumentError = class extends DidMethodError {
|
|
57588
57583
|
constructor(message2, type = "DidDocumentError", data) {
|
|
57589
57584
|
super(message2, { type, name: type, data });
|
|
@@ -57619,11 +57614,6 @@ var MultikeyError = class extends DidMethodError {
|
|
|
57619
57614
|
super(message2, { type, name: type, data });
|
|
57620
57615
|
}
|
|
57621
57616
|
};
|
|
57622
|
-
var SingletonBeaconError = class extends DidMethodError {
|
|
57623
|
-
constructor(message2, type = "SingletonBeaconError", data) {
|
|
57624
|
-
super(message2, { type, name: type, data });
|
|
57625
|
-
}
|
|
57626
|
-
};
|
|
57627
57617
|
var CanonicalizationError = class extends DidMethodError {
|
|
57628
57618
|
constructor(message2, type = "CanonicalizationError", data) {
|
|
57629
57619
|
super(message2, { type, name: type, data });
|
|
@@ -59603,7 +59593,7 @@ var BeaconParticipantError = class extends MethodError {
|
|
|
59603
59593
|
super(message2, type, data);
|
|
59604
59594
|
}
|
|
59605
59595
|
};
|
|
59606
|
-
var
|
|
59596
|
+
var SingletonBeaconError = class extends MethodError {
|
|
59607
59597
|
constructor(message2, type = "SingletonBeaconError", data) {
|
|
59608
59598
|
super(message2, type, data);
|
|
59609
59599
|
}
|
|
@@ -59613,13 +59603,13 @@ var AggregateBeaconError = class extends MethodError {
|
|
|
59613
59603
|
super(message2, type, data);
|
|
59614
59604
|
}
|
|
59615
59605
|
};
|
|
59616
|
-
var
|
|
59617
|
-
constructor(message2, type = "
|
|
59606
|
+
var CASBeaconError = class extends MethodError {
|
|
59607
|
+
constructor(message2, type = "CASBeaconError", data) {
|
|
59618
59608
|
super(message2, type, data);
|
|
59619
59609
|
}
|
|
59620
59610
|
};
|
|
59621
|
-
var
|
|
59622
|
-
constructor(message2, type = "
|
|
59611
|
+
var SMTBeaconError = class extends MethodError {
|
|
59612
|
+
constructor(message2, type = "SMTBeaconError", data) {
|
|
59623
59613
|
super(message2, type, data);
|
|
59624
59614
|
}
|
|
59625
59615
|
};
|
|
@@ -60482,16 +60472,16 @@ var Secp256k1SecretKey = class _Secp256k1SecretKey {
|
|
|
60482
60472
|
#multibase;
|
|
60483
60473
|
/**
|
|
60484
60474
|
* Instantiates an instance of Secp256k1SecretKey.
|
|
60485
|
-
* @param {
|
|
60475
|
+
* @param {Bytes | bigint} entropy bytes (Uint8Array) or secret (bigint)
|
|
60486
60476
|
* @throws {SecretKeyError} If entropy is not provided, not a valid 32-byte secret key or not a valid bigint seed
|
|
60487
60477
|
*/
|
|
60488
60478
|
constructor(entropy) {
|
|
60489
|
-
const
|
|
60479
|
+
const isBytes12 = entropy instanceof Uint8Array;
|
|
60490
60480
|
const isSecret = typeof entropy === "bigint";
|
|
60491
|
-
if (!
|
|
60481
|
+
if (!isBytes12 && !isSecret) {
|
|
60492
60482
|
throw new SecretKeyError("Invalid entropy: must be a valid byte array (32) or bigint", "CONSTRUCTOR_ERROR");
|
|
60493
60483
|
}
|
|
60494
|
-
if (
|
|
60484
|
+
if (isBytes12 && entropy.length === 32) {
|
|
60495
60485
|
this.#bytes = entropy;
|
|
60496
60486
|
this.#seed = _Secp256k1SecretKey.toSecret(entropy);
|
|
60497
60487
|
}
|
|
@@ -60676,15 +60666,23 @@ var Secp256k1SecretKey = class _Secp256k1SecretKey {
|
|
|
60676
60666
|
}
|
|
60677
60667
|
return new Uint8Array(bytes6);
|
|
60678
60668
|
}
|
|
60669
|
+
/**
|
|
60670
|
+
* Creates a new Secp256k1SecretKey object from random bytes.
|
|
60671
|
+
* @param {KeyBytes} bytes The secret key bytes
|
|
60672
|
+
* @returns {Secp256k1SecretKey} A new Secp256k1SecretKey object
|
|
60673
|
+
*/
|
|
60674
|
+
static fromBytes(bytes6) {
|
|
60675
|
+
return new _Secp256k1SecretKey(bytes6);
|
|
60676
|
+
}
|
|
60679
60677
|
/**
|
|
60680
60678
|
* Creates a new Secp256k1SecretKey object from a bigint secret.
|
|
60681
|
-
* @param {bigint}
|
|
60679
|
+
* @param {bigint} bint The secret bigint
|
|
60682
60680
|
* @returns {Secp256k1SecretKey} A new Secp256k1SecretKey object
|
|
60683
60681
|
*/
|
|
60684
|
-
static
|
|
60685
|
-
const hexsecret =
|
|
60686
|
-
const
|
|
60687
|
-
return new _Secp256k1SecretKey(
|
|
60682
|
+
static fromBigInt(bint) {
|
|
60683
|
+
const hexsecret = bint.toString(16).padStart(64, "0");
|
|
60684
|
+
const bytes6 = new Uint8Array(hexsecret.match(/.{2}/g).map((byte) => parseInt(byte, 16)));
|
|
60685
|
+
return new _Secp256k1SecretKey(bytes6);
|
|
60688
60686
|
}
|
|
60689
60687
|
/**
|
|
60690
60688
|
* Generates random secret key bytes.
|
|
@@ -61001,12 +60999,18 @@ var CompressedSecp256k1PublicKey = class _CompressedSecp256k1PublicKey {
|
|
|
61001
60999
|
|
|
61002
61000
|
// ../keypair/dist/esm/pair.js
|
|
61003
61001
|
var SchnorrKeyPair = class _SchnorrKeyPair {
|
|
61004
|
-
/**
|
|
61002
|
+
/**
|
|
61003
|
+
* The secret key objec
|
|
61004
|
+
*/
|
|
61005
61005
|
#secretKey;
|
|
61006
61006
|
#publicKey;
|
|
61007
|
-
/**
|
|
61007
|
+
/**
|
|
61008
|
+
* The public key in multibase forma
|
|
61009
|
+
*/
|
|
61008
61010
|
#publicKeyMultibase;
|
|
61009
|
-
/**
|
|
61011
|
+
/**
|
|
61012
|
+
* The secret key in multibase forma
|
|
61013
|
+
*/
|
|
61010
61014
|
#secretKeyMultibase;
|
|
61011
61015
|
/**
|
|
61012
61016
|
* Creates an instance of Keys. Must provide a at least a secret key.
|
|
@@ -61144,11 +61148,11 @@ var SchnorrKeyPair = class _SchnorrKeyPair {
|
|
|
61144
61148
|
}
|
|
61145
61149
|
/**
|
|
61146
61150
|
* Static method creates a new Keys (Secp256k1SecretKey/CompressedSecp256k1PublicKey) from bigint entropy.
|
|
61147
|
-
* @param {bigint}
|
|
61151
|
+
* @param {bigint} bint The entropy in bigint form
|
|
61148
61152
|
* @returns {SchnorrKeyPair} A new SchnorrKeyPair object
|
|
61149
61153
|
*/
|
|
61150
|
-
static
|
|
61151
|
-
const secretKey = Secp256k1SecretKey.
|
|
61154
|
+
static fromBigInt(bint) {
|
|
61155
|
+
const secretKey = Secp256k1SecretKey.fromBigInt(bint);
|
|
61152
61156
|
const publicKey2 = secretKey.computePublicKey();
|
|
61153
61157
|
return new _SchnorrKeyPair({ secretKey, publicKey: publicKey2 });
|
|
61154
61158
|
}
|
|
@@ -69815,81 +69819,48 @@ var BeaconParticipant = class _BeaconParticipant {
|
|
|
69815
69819
|
}
|
|
69816
69820
|
};
|
|
69817
69821
|
|
|
69818
|
-
// src/core/beacon/
|
|
69822
|
+
// src/core/beacon/beacon.ts
|
|
69819
69823
|
init_shim();
|
|
69820
|
-
|
|
69821
|
-
// src/core/beacon/interfaces.ts
|
|
69822
|
-
init_shim();
|
|
69823
|
-
var AggregateBeacon = class {
|
|
69824
|
+
var Beacon = class {
|
|
69824
69825
|
/**
|
|
69825
|
-
* The Beacon service
|
|
69826
|
+
* The Beacon service configuration parsed from the DID Document.
|
|
69826
69827
|
*/
|
|
69827
69828
|
service;
|
|
69828
|
-
|
|
69829
|
-
* The array of Beacon Signals associated with this Beacon service.
|
|
69830
|
-
*/
|
|
69831
|
-
signals;
|
|
69832
|
-
/**
|
|
69833
|
-
* The sidecar data associated with this Beacon service.
|
|
69834
|
-
* TODO: Make this more specific to Beacon type.
|
|
69835
|
-
*/
|
|
69836
|
-
sidecar;
|
|
69837
|
-
/**
|
|
69838
|
-
* The Bitcoin network connection associated with this Beacon service.
|
|
69839
|
-
*/
|
|
69840
|
-
bitcoin;
|
|
69841
|
-
constructor(service, signals, sidecar, bitcoin3) {
|
|
69829
|
+
constructor(service) {
|
|
69842
69830
|
this.service = service;
|
|
69843
|
-
this.signals = signals;
|
|
69844
|
-
this.sidecar = sidecar;
|
|
69845
|
-
this.bitcoin = bitcoin3;
|
|
69846
69831
|
}
|
|
69847
69832
|
};
|
|
69848
69833
|
|
|
69849
69834
|
// src/core/beacon/cas-beacon.ts
|
|
69850
|
-
|
|
69835
|
+
init_shim();
|
|
69836
|
+
var CASBeacon = class extends Beacon {
|
|
69851
69837
|
/**
|
|
69852
69838
|
* Creates an instance of CASBeacon.
|
|
69853
69839
|
* @param {BeaconService} service The service of the Beacon.
|
|
69854
|
-
* @param {?BeaconSidecarData} [sidecar] The sidecar data of the Beacon.
|
|
69855
|
-
*/
|
|
69856
|
-
constructor(service, signals, sidecar, bitcoin3) {
|
|
69857
|
-
super({ ...service, type: "CASBeacon" }, signals, sidecar, bitcoin3);
|
|
69858
|
-
}
|
|
69859
|
-
/**
|
|
69860
|
-
* Establish a CASBeacon instance based on the provided service and sidecar data.
|
|
69861
|
-
* @param {BeaconService} service - The beacon service configuration.
|
|
69862
|
-
* @param {SidecarData} sidecar - The sidecar data.
|
|
69863
|
-
* @returns {CASBeacon} The established CASBeacon instance.
|
|
69864
|
-
*/
|
|
69865
|
-
static establish(service, signals, sidecar) {
|
|
69866
|
-
return new _CASBeacon(service, signals, sidecar);
|
|
69867
|
-
}
|
|
69868
|
-
/**
|
|
69869
|
-
* TODO: Figure out if this is necessary or not.
|
|
69870
|
-
* @param {HexString} updateHash The hash of the update to generate the signal for.
|
|
69871
|
-
* @returns {BeaconSignal} The generated signal.
|
|
69872
|
-
* @throws {MethodError} if the signal is invalid.
|
|
69873
69840
|
*/
|
|
69874
|
-
|
|
69875
|
-
|
|
69841
|
+
constructor(service) {
|
|
69842
|
+
super({ ...service, type: "CASBeacon" });
|
|
69876
69843
|
}
|
|
69877
69844
|
/**
|
|
69878
69845
|
* Implements {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-cas-beacon | 7.2.e.1 Process CAS Beacon}.
|
|
69879
|
-
* @
|
|
69880
|
-
* @
|
|
69846
|
+
* @param {Array<BeaconSignal>} signals The array of Beacon Signals to process.
|
|
69847
|
+
* @param {SidecarData} sidecar The sidecar data associated with the CAS Beacon.
|
|
69848
|
+
* @returns {Promise<Array<[SignedBTCR2Update, BlockMetadata]>>} The processed signals.
|
|
69849
|
+
* @throws {CASBeaconError} if processing fails.
|
|
69881
69850
|
*/
|
|
69882
|
-
processSignals() {
|
|
69883
|
-
throw new
|
|
69851
|
+
processSignals(signals, sidecar) {
|
|
69852
|
+
throw new CASBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signals, sidecar });
|
|
69884
69853
|
}
|
|
69885
69854
|
/**
|
|
69886
|
-
*
|
|
69887
|
-
* @param {
|
|
69888
|
-
* @
|
|
69889
|
-
* @
|
|
69855
|
+
* Broadcast CAS Beacon signal to the Bitcoin network.
|
|
69856
|
+
* @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
|
|
69857
|
+
* @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
|
|
69858
|
+
* @param {BitcoinNetworkConnection} bitcoin The Bitcoin network connection.
|
|
69859
|
+
* @return {Promise<SignedBTCR2Update>} The signed update that was broadcasted.
|
|
69860
|
+
* @throws {CASBeaconError} if broadcasting fails.
|
|
69890
69861
|
*/
|
|
69891
|
-
async broadcastSignal(
|
|
69892
|
-
throw new
|
|
69862
|
+
async broadcastSignal(signedUpdate, secretKey, bitcoin3) {
|
|
69863
|
+
throw new CASBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signedUpdate, secretKey, bitcoin: bitcoin3 });
|
|
69893
69864
|
}
|
|
69894
69865
|
};
|
|
69895
69866
|
|
|
@@ -69908,623 +69879,8 @@ init_shim();
|
|
|
69908
69879
|
// ../kms/dist/esm/kms.js
|
|
69909
69880
|
init_shim();
|
|
69910
69881
|
|
|
69911
|
-
// ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/sha2.js
|
|
69912
|
-
init_shim();
|
|
69913
|
-
|
|
69914
|
-
// ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/_md.js
|
|
69915
|
-
init_shim();
|
|
69916
|
-
|
|
69917
|
-
// ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/utils.js
|
|
69918
|
-
init_shim();
|
|
69919
|
-
function isBytes6(a3) {
|
|
69920
|
-
return a3 instanceof Uint8Array || ArrayBuffer.isView(a3) && a3.constructor.name === "Uint8Array";
|
|
69921
|
-
}
|
|
69922
|
-
function abytes3(value3, length7, title = "") {
|
|
69923
|
-
const bytes6 = isBytes6(value3);
|
|
69924
|
-
const len = value3?.length;
|
|
69925
|
-
const needsLen = length7 !== void 0;
|
|
69926
|
-
if (!bytes6 || needsLen && len !== length7) {
|
|
69927
|
-
const prefix = title && `"${title}" `;
|
|
69928
|
-
const ofLen = needsLen ? ` of length ${length7}` : "";
|
|
69929
|
-
const got = bytes6 ? `length=${len}` : `type=${typeof value3}`;
|
|
69930
|
-
throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
|
|
69931
|
-
}
|
|
69932
|
-
return value3;
|
|
69933
|
-
}
|
|
69934
|
-
function aexists2(instance3, checkFinished = true) {
|
|
69935
|
-
if (instance3.destroyed)
|
|
69936
|
-
throw new Error("Hash instance has been destroyed");
|
|
69937
|
-
if (checkFinished && instance3.finished)
|
|
69938
|
-
throw new Error("Hash#digest() has already been called");
|
|
69939
|
-
}
|
|
69940
|
-
function aoutput2(out, instance3) {
|
|
69941
|
-
abytes3(out, void 0, "digestInto() output");
|
|
69942
|
-
const min = instance3.outputLen;
|
|
69943
|
-
if (out.length < min) {
|
|
69944
|
-
throw new Error('"digestInto() output" expected to be of length >=' + min);
|
|
69945
|
-
}
|
|
69946
|
-
}
|
|
69947
|
-
function clean2(...arrays) {
|
|
69948
|
-
for (let i4 = 0; i4 < arrays.length; i4++) {
|
|
69949
|
-
arrays[i4].fill(0);
|
|
69950
|
-
}
|
|
69951
|
-
}
|
|
69952
|
-
function createView6(arr) {
|
|
69953
|
-
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
69954
|
-
}
|
|
69955
|
-
function rotr4(word2, shift) {
|
|
69956
|
-
return word2 << 32 - shift | word2 >>> shift;
|
|
69957
|
-
}
|
|
69958
|
-
function createHasher2(hashCons, info = {}) {
|
|
69959
|
-
const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
|
|
69960
|
-
const tmp = hashCons(void 0);
|
|
69961
|
-
hashC.outputLen = tmp.outputLen;
|
|
69962
|
-
hashC.blockLen = tmp.blockLen;
|
|
69963
|
-
hashC.create = (opts) => hashCons(opts);
|
|
69964
|
-
Object.assign(hashC, info);
|
|
69965
|
-
return Object.freeze(hashC);
|
|
69966
|
-
}
|
|
69967
|
-
var oidNist = (suffix) => ({
|
|
69968
|
-
oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
|
|
69969
|
-
});
|
|
69970
|
-
|
|
69971
|
-
// ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/_md.js
|
|
69972
|
-
function Chi4(a3, b2, c2) {
|
|
69973
|
-
return a3 & b2 ^ ~a3 & c2;
|
|
69974
|
-
}
|
|
69975
|
-
function Maj4(a3, b2, c2) {
|
|
69976
|
-
return a3 & b2 ^ a3 & c2 ^ b2 & c2;
|
|
69977
|
-
}
|
|
69978
|
-
var HashMD2 = class {
|
|
69979
|
-
blockLen;
|
|
69980
|
-
outputLen;
|
|
69981
|
-
padOffset;
|
|
69982
|
-
isLE;
|
|
69983
|
-
// For partial updates less than block size
|
|
69984
|
-
buffer;
|
|
69985
|
-
view;
|
|
69986
|
-
finished = false;
|
|
69987
|
-
length = 0;
|
|
69988
|
-
pos = 0;
|
|
69989
|
-
destroyed = false;
|
|
69990
|
-
constructor(blockLen, outputLen, padOffset, isLE7) {
|
|
69991
|
-
this.blockLen = blockLen;
|
|
69992
|
-
this.outputLen = outputLen;
|
|
69993
|
-
this.padOffset = padOffset;
|
|
69994
|
-
this.isLE = isLE7;
|
|
69995
|
-
this.buffer = new Uint8Array(blockLen);
|
|
69996
|
-
this.view = createView6(this.buffer);
|
|
69997
|
-
}
|
|
69998
|
-
update(data) {
|
|
69999
|
-
aexists2(this);
|
|
70000
|
-
abytes3(data);
|
|
70001
|
-
const { view, buffer: buffer2, blockLen } = this;
|
|
70002
|
-
const len = data.length;
|
|
70003
|
-
for (let pos = 0; pos < len; ) {
|
|
70004
|
-
const take2 = Math.min(blockLen - this.pos, len - pos);
|
|
70005
|
-
if (take2 === blockLen) {
|
|
70006
|
-
const dataView2 = createView6(data);
|
|
70007
|
-
for (; blockLen <= len - pos; pos += blockLen)
|
|
70008
|
-
this.process(dataView2, pos);
|
|
70009
|
-
continue;
|
|
70010
|
-
}
|
|
70011
|
-
buffer2.set(data.subarray(pos, pos + take2), this.pos);
|
|
70012
|
-
this.pos += take2;
|
|
70013
|
-
pos += take2;
|
|
70014
|
-
if (this.pos === blockLen) {
|
|
70015
|
-
this.process(view, 0);
|
|
70016
|
-
this.pos = 0;
|
|
70017
|
-
}
|
|
70018
|
-
}
|
|
70019
|
-
this.length += data.length;
|
|
70020
|
-
this.roundClean();
|
|
70021
|
-
return this;
|
|
70022
|
-
}
|
|
70023
|
-
digestInto(out) {
|
|
70024
|
-
aexists2(this);
|
|
70025
|
-
aoutput2(out, this);
|
|
70026
|
-
this.finished = true;
|
|
70027
|
-
const { buffer: buffer2, view, blockLen, isLE: isLE7 } = this;
|
|
70028
|
-
let { pos } = this;
|
|
70029
|
-
buffer2[pos++] = 128;
|
|
70030
|
-
clean2(this.buffer.subarray(pos));
|
|
70031
|
-
if (this.padOffset > blockLen - pos) {
|
|
70032
|
-
this.process(view, 0);
|
|
70033
|
-
pos = 0;
|
|
70034
|
-
}
|
|
70035
|
-
for (let i4 = pos; i4 < blockLen; i4++)
|
|
70036
|
-
buffer2[i4] = 0;
|
|
70037
|
-
view.setBigUint64(blockLen - 8, BigInt(this.length * 8), isLE7);
|
|
70038
|
-
this.process(view, 0);
|
|
70039
|
-
const oview = createView6(out);
|
|
70040
|
-
const len = this.outputLen;
|
|
70041
|
-
if (len % 4)
|
|
70042
|
-
throw new Error("_sha2: outputLen must be aligned to 32bit");
|
|
70043
|
-
const outLen = len / 4;
|
|
70044
|
-
const state = this.get();
|
|
70045
|
-
if (outLen > state.length)
|
|
70046
|
-
throw new Error("_sha2: outputLen bigger than state");
|
|
70047
|
-
for (let i4 = 0; i4 < outLen; i4++)
|
|
70048
|
-
oview.setUint32(4 * i4, state[i4], isLE7);
|
|
70049
|
-
}
|
|
70050
|
-
digest() {
|
|
70051
|
-
const { buffer: buffer2, outputLen } = this;
|
|
70052
|
-
this.digestInto(buffer2);
|
|
70053
|
-
const res = buffer2.slice(0, outputLen);
|
|
70054
|
-
this.destroy();
|
|
70055
|
-
return res;
|
|
70056
|
-
}
|
|
70057
|
-
_cloneInto(to) {
|
|
70058
|
-
to ||= new this.constructor();
|
|
70059
|
-
to.set(...this.get());
|
|
70060
|
-
const { blockLen, buffer: buffer2, length: length7, finished, destroyed, pos } = this;
|
|
70061
|
-
to.destroyed = destroyed;
|
|
70062
|
-
to.finished = finished;
|
|
70063
|
-
to.length = length7;
|
|
70064
|
-
to.pos = pos;
|
|
70065
|
-
if (length7 % blockLen)
|
|
70066
|
-
to.buffer.set(buffer2);
|
|
70067
|
-
return to;
|
|
70068
|
-
}
|
|
70069
|
-
clone() {
|
|
70070
|
-
return this._cloneInto();
|
|
70071
|
-
}
|
|
70072
|
-
};
|
|
70073
|
-
var SHA256_IV2 = /* @__PURE__ */ Uint32Array.from([
|
|
70074
|
-
1779033703,
|
|
70075
|
-
3144134277,
|
|
70076
|
-
1013904242,
|
|
70077
|
-
2773480762,
|
|
70078
|
-
1359893119,
|
|
70079
|
-
2600822924,
|
|
70080
|
-
528734635,
|
|
70081
|
-
1541459225
|
|
70082
|
-
]);
|
|
70083
|
-
|
|
70084
|
-
// ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/sha2.js
|
|
70085
|
-
var SHA256_K4 = /* @__PURE__ */ Uint32Array.from([
|
|
70086
|
-
1116352408,
|
|
70087
|
-
1899447441,
|
|
70088
|
-
3049323471,
|
|
70089
|
-
3921009573,
|
|
70090
|
-
961987163,
|
|
70091
|
-
1508970993,
|
|
70092
|
-
2453635748,
|
|
70093
|
-
2870763221,
|
|
70094
|
-
3624381080,
|
|
70095
|
-
310598401,
|
|
70096
|
-
607225278,
|
|
70097
|
-
1426881987,
|
|
70098
|
-
1925078388,
|
|
70099
|
-
2162078206,
|
|
70100
|
-
2614888103,
|
|
70101
|
-
3248222580,
|
|
70102
|
-
3835390401,
|
|
70103
|
-
4022224774,
|
|
70104
|
-
264347078,
|
|
70105
|
-
604807628,
|
|
70106
|
-
770255983,
|
|
70107
|
-
1249150122,
|
|
70108
|
-
1555081692,
|
|
70109
|
-
1996064986,
|
|
70110
|
-
2554220882,
|
|
70111
|
-
2821834349,
|
|
70112
|
-
2952996808,
|
|
70113
|
-
3210313671,
|
|
70114
|
-
3336571891,
|
|
70115
|
-
3584528711,
|
|
70116
|
-
113926993,
|
|
70117
|
-
338241895,
|
|
70118
|
-
666307205,
|
|
70119
|
-
773529912,
|
|
70120
|
-
1294757372,
|
|
70121
|
-
1396182291,
|
|
70122
|
-
1695183700,
|
|
70123
|
-
1986661051,
|
|
70124
|
-
2177026350,
|
|
70125
|
-
2456956037,
|
|
70126
|
-
2730485921,
|
|
70127
|
-
2820302411,
|
|
70128
|
-
3259730800,
|
|
70129
|
-
3345764771,
|
|
70130
|
-
3516065817,
|
|
70131
|
-
3600352804,
|
|
70132
|
-
4094571909,
|
|
70133
|
-
275423344,
|
|
70134
|
-
430227734,
|
|
70135
|
-
506948616,
|
|
70136
|
-
659060556,
|
|
70137
|
-
883997877,
|
|
70138
|
-
958139571,
|
|
70139
|
-
1322822218,
|
|
70140
|
-
1537002063,
|
|
70141
|
-
1747873779,
|
|
70142
|
-
1955562222,
|
|
70143
|
-
2024104815,
|
|
70144
|
-
2227730452,
|
|
70145
|
-
2361852424,
|
|
70146
|
-
2428436474,
|
|
70147
|
-
2756734187,
|
|
70148
|
-
3204031479,
|
|
70149
|
-
3329325298
|
|
70150
|
-
]);
|
|
70151
|
-
var SHA256_W4 = /* @__PURE__ */ new Uint32Array(64);
|
|
70152
|
-
var SHA2_32B = class extends HashMD2 {
|
|
70153
|
-
constructor(outputLen) {
|
|
70154
|
-
super(64, outputLen, 8, false);
|
|
70155
|
-
}
|
|
70156
|
-
get() {
|
|
70157
|
-
const { A, B, C: C2, D, E, F, G: G2, H } = this;
|
|
70158
|
-
return [A, B, C2, D, E, F, G2, H];
|
|
70159
|
-
}
|
|
70160
|
-
// prettier-ignore
|
|
70161
|
-
set(A, B, C2, D, E, F, G2, H) {
|
|
70162
|
-
this.A = A | 0;
|
|
70163
|
-
this.B = B | 0;
|
|
70164
|
-
this.C = C2 | 0;
|
|
70165
|
-
this.D = D | 0;
|
|
70166
|
-
this.E = E | 0;
|
|
70167
|
-
this.F = F | 0;
|
|
70168
|
-
this.G = G2 | 0;
|
|
70169
|
-
this.H = H | 0;
|
|
70170
|
-
}
|
|
70171
|
-
process(view, offset) {
|
|
70172
|
-
for (let i4 = 0; i4 < 16; i4++, offset += 4)
|
|
70173
|
-
SHA256_W4[i4] = view.getUint32(offset, false);
|
|
70174
|
-
for (let i4 = 16; i4 < 64; i4++) {
|
|
70175
|
-
const W15 = SHA256_W4[i4 - 15];
|
|
70176
|
-
const W2 = SHA256_W4[i4 - 2];
|
|
70177
|
-
const s0 = rotr4(W15, 7) ^ rotr4(W15, 18) ^ W15 >>> 3;
|
|
70178
|
-
const s1 = rotr4(W2, 17) ^ rotr4(W2, 19) ^ W2 >>> 10;
|
|
70179
|
-
SHA256_W4[i4] = s1 + SHA256_W4[i4 - 7] + s0 + SHA256_W4[i4 - 16] | 0;
|
|
70180
|
-
}
|
|
70181
|
-
let { A, B, C: C2, D, E, F, G: G2, H } = this;
|
|
70182
|
-
for (let i4 = 0; i4 < 64; i4++) {
|
|
70183
|
-
const sigma1 = rotr4(E, 6) ^ rotr4(E, 11) ^ rotr4(E, 25);
|
|
70184
|
-
const T1 = H + sigma1 + Chi4(E, F, G2) + SHA256_K4[i4] + SHA256_W4[i4] | 0;
|
|
70185
|
-
const sigma0 = rotr4(A, 2) ^ rotr4(A, 13) ^ rotr4(A, 22);
|
|
70186
|
-
const T2 = sigma0 + Maj4(A, B, C2) | 0;
|
|
70187
|
-
H = G2;
|
|
70188
|
-
G2 = F;
|
|
70189
|
-
F = E;
|
|
70190
|
-
E = D + T1 | 0;
|
|
70191
|
-
D = C2;
|
|
70192
|
-
C2 = B;
|
|
70193
|
-
B = A;
|
|
70194
|
-
A = T1 + T2 | 0;
|
|
70195
|
-
}
|
|
70196
|
-
A = A + this.A | 0;
|
|
70197
|
-
B = B + this.B | 0;
|
|
70198
|
-
C2 = C2 + this.C | 0;
|
|
70199
|
-
D = D + this.D | 0;
|
|
70200
|
-
E = E + this.E | 0;
|
|
70201
|
-
F = F + this.F | 0;
|
|
70202
|
-
G2 = G2 + this.G | 0;
|
|
70203
|
-
H = H + this.H | 0;
|
|
70204
|
-
this.set(A, B, C2, D, E, F, G2, H);
|
|
70205
|
-
}
|
|
70206
|
-
roundClean() {
|
|
70207
|
-
clean2(SHA256_W4);
|
|
70208
|
-
}
|
|
70209
|
-
destroy() {
|
|
70210
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
70211
|
-
clean2(this.buffer);
|
|
70212
|
-
}
|
|
70213
|
-
};
|
|
70214
|
-
var _SHA256 = class extends SHA2_32B {
|
|
70215
|
-
// We cannot use array here since array allows indexing by variable
|
|
70216
|
-
// which means optimizer/compiler cannot use registers.
|
|
70217
|
-
A = SHA256_IV2[0] | 0;
|
|
70218
|
-
B = SHA256_IV2[1] | 0;
|
|
70219
|
-
C = SHA256_IV2[2] | 0;
|
|
70220
|
-
D = SHA256_IV2[3] | 0;
|
|
70221
|
-
E = SHA256_IV2[4] | 0;
|
|
70222
|
-
F = SHA256_IV2[5] | 0;
|
|
70223
|
-
G = SHA256_IV2[6] | 0;
|
|
70224
|
-
H = SHA256_IV2[7] | 0;
|
|
70225
|
-
constructor() {
|
|
70226
|
-
super(32);
|
|
70227
|
-
}
|
|
70228
|
-
};
|
|
70229
|
-
var sha2565 = /* @__PURE__ */ createHasher2(
|
|
70230
|
-
() => new _SHA256(),
|
|
70231
|
-
/* @__PURE__ */ oidNist(1)
|
|
70232
|
-
);
|
|
70233
|
-
|
|
70234
69882
|
// ../kms/dist/esm/store.js
|
|
70235
69883
|
init_shim();
|
|
70236
|
-
var MemoryStore = class {
|
|
70237
|
-
/**
|
|
70238
|
-
* A private field that contains the Map used as the key-value store.
|
|
70239
|
-
*/
|
|
70240
|
-
store = /* @__PURE__ */ new Map();
|
|
70241
|
-
/**
|
|
70242
|
-
* Clears all entries in the key-value store.
|
|
70243
|
-
*
|
|
70244
|
-
* @returns {void} returns once the operation is complete.
|
|
70245
|
-
*/
|
|
70246
|
-
clear() {
|
|
70247
|
-
this.store.clear();
|
|
70248
|
-
}
|
|
70249
|
-
/**
|
|
70250
|
-
* This operation is no-op for `MemoryStore`.
|
|
70251
|
-
*/
|
|
70252
|
-
close() {
|
|
70253
|
-
}
|
|
70254
|
-
/**
|
|
70255
|
-
* Deletes an entry from the key-value store by its key.
|
|
70256
|
-
*
|
|
70257
|
-
* @param {K} id - The key of the entry to delete.
|
|
70258
|
-
* @returns {boolean} a boolean indicating whether the entry was successfully deleted.
|
|
70259
|
-
*/
|
|
70260
|
-
delete(id) {
|
|
70261
|
-
return this.store.delete(id);
|
|
70262
|
-
}
|
|
70263
|
-
/**
|
|
70264
|
-
* Retrieves the value of an entry by its key.
|
|
70265
|
-
*
|
|
70266
|
-
* @param {K} id - The key of the entry to retrieve.
|
|
70267
|
-
* @returns {V | undefined} the value of the entry, or `undefined` if the entry does not exist.
|
|
70268
|
-
*/
|
|
70269
|
-
get(id) {
|
|
70270
|
-
return this.store.get(id);
|
|
70271
|
-
}
|
|
70272
|
-
/**
|
|
70273
|
-
* Checks for the presence of an entry by key.
|
|
70274
|
-
*
|
|
70275
|
-
* @param {K} id - The key to check for the existence of.
|
|
70276
|
-
* @returns {boolean} a boolean indicating whether an element with the specified key exists or not.
|
|
70277
|
-
*/
|
|
70278
|
-
has(id) {
|
|
70279
|
-
return this.store.has(id);
|
|
70280
|
-
}
|
|
70281
|
-
/**
|
|
70282
|
-
* Retrieves all values in the key-value store.
|
|
70283
|
-
|
|
70284
|
-
* @returns {Array<V>} an array of all values in the store.
|
|
70285
|
-
*/
|
|
70286
|
-
list() {
|
|
70287
|
-
return Array.from(this.store.values());
|
|
70288
|
-
}
|
|
70289
|
-
/**
|
|
70290
|
-
* Retrieves all entries in the key-value store.
|
|
70291
|
-
*
|
|
70292
|
-
* @returns {Array<[K, V]>} an array of key-value pairs in the store.
|
|
70293
|
-
*/
|
|
70294
|
-
entries() {
|
|
70295
|
-
return Array.from(this.store.entries());
|
|
70296
|
-
}
|
|
70297
|
-
/**
|
|
70298
|
-
* Sets the value of an entry in the key-value store.
|
|
70299
|
-
*
|
|
70300
|
-
* @param {K} id - The key of the entry to set.
|
|
70301
|
-
* @param {V} key - The new value for the entry.
|
|
70302
|
-
* @returns {void} once operation is complete.
|
|
70303
|
-
*/
|
|
70304
|
-
set(id, key) {
|
|
70305
|
-
this.store.set(id, key);
|
|
70306
|
-
}
|
|
70307
|
-
};
|
|
70308
|
-
|
|
70309
|
-
// ../kms/dist/esm/kms.js
|
|
70310
|
-
var Kms = class _Kms {
|
|
70311
|
-
/**
|
|
70312
|
-
* Singleton instance of the Kms.
|
|
70313
|
-
* @private
|
|
70314
|
-
* @type {KeyManager}
|
|
70315
|
-
*/
|
|
70316
|
-
static #instance;
|
|
70317
|
-
/**
|
|
70318
|
-
* The `store` is a private variable in `KeyManager`. It is a `KeyValueStore` instance used for
|
|
70319
|
-
* storing and managing cryptographic keys. It allows the `KeyManager` class to save,
|
|
70320
|
-
* retrieve, and handle keys efficiently within the local Key Management System (KMS) context.
|
|
70321
|
-
* This variable can be configured to use different storage backends, like in-memory storage or
|
|
70322
|
-
* persistent storage, providing flexibility in key management according to the application's
|
|
70323
|
-
* requirements.
|
|
70324
|
-
* @private
|
|
70325
|
-
* @type {KeyValueStore<KeyIdentifier, KeyBytes>} The key store for managing cryptographic keys.
|
|
70326
|
-
*/
|
|
70327
|
-
#store;
|
|
70328
|
-
/**
|
|
70329
|
-
* The `#activeKeyId` property is a string that points to the currently active key.
|
|
70330
|
-
* It is used to identify the key that will be used for signing and verifying operations.
|
|
70331
|
-
* This property is optional and can be set to a specific key ID when initializing the
|
|
70332
|
-
* `KeyManager` instance. If not set, the key manager will use the default key id.
|
|
70333
|
-
* @private
|
|
70334
|
-
* @type {KeyIdentifier}
|
|
70335
|
-
*/
|
|
70336
|
-
#activeKeyId;
|
|
70337
|
-
/**
|
|
70338
|
-
* Creates an instance of KeyManager.
|
|
70339
|
-
* @param {KeyValueStore<KeyIdentifier, KeyBytes>} store An optional property to specify a custom
|
|
70340
|
-
* `KeyValueStore` instance for key management. If not provided, {@link KeyManager} uses a default `MemoryStore`
|
|
70341
|
-
* instance. This store is responsible for managing cryptographic keys, allowing them to be retrieved, stored, and
|
|
70342
|
-
* managed during cryptographic operations.
|
|
70343
|
-
*/
|
|
70344
|
-
constructor(store5) {
|
|
70345
|
-
this.#store = store5 ?? new MemoryStore();
|
|
70346
|
-
}
|
|
70347
|
-
/**
|
|
70348
|
-
* Gets the ID of the active key.
|
|
70349
|
-
* @returns {KeyIdentifier | undefined} The ID of the active key.
|
|
70350
|
-
*/
|
|
70351
|
-
get activeKeyId() {
|
|
70352
|
-
return this.#activeKeyId;
|
|
70353
|
-
}
|
|
70354
|
-
/**
|
|
70355
|
-
* Gets the key pair associated with the given ID or the active key if no ID is provided.
|
|
70356
|
-
* @param {KeyIdentifier} [id] The ID of the key to get.
|
|
70357
|
-
* @returns {KeyBytes} A promise resolving to the key pair.
|
|
70358
|
-
* @throws {KeyManagerError} If the key is not found or no active key is set.
|
|
70359
|
-
*/
|
|
70360
|
-
#getKeyOrThrow(id) {
|
|
70361
|
-
const keyId2 = id ?? this.#activeKeyId;
|
|
70362
|
-
if (!keyId2) {
|
|
70363
|
-
throw new KeyManagerError("No active key set", "ACTIVE_KEY_URI_NOT_SET");
|
|
70364
|
-
}
|
|
70365
|
-
const _secretKey = this.#store.get(keyId2);
|
|
70366
|
-
if (!_secretKey) {
|
|
70367
|
-
throw new KeyManagerError(`Key not found: ${keyId2}`, "KEY_NOT_FOUND");
|
|
70368
|
-
}
|
|
70369
|
-
const kp = new SchnorrKeyPair({ secretKey: _secretKey });
|
|
70370
|
-
return kp;
|
|
70371
|
-
}
|
|
70372
|
-
/**
|
|
70373
|
-
* Checks if a key with the given ID exists in the key store.
|
|
70374
|
-
* @param {KeyIdentifier} id The ID of the key to check.
|
|
70375
|
-
* @returns {boolean} A promise resolving to a boolean indicating if the key exists.
|
|
70376
|
-
*/
|
|
70377
|
-
#exists(id) {
|
|
70378
|
-
const key = this.#store.get(id);
|
|
70379
|
-
return !!key;
|
|
70380
|
-
}
|
|
70381
|
-
/**
|
|
70382
|
-
* Removes a key from the key store.
|
|
70383
|
-
* @param {KeyIdentifier} id The key identifier of the key to remove.
|
|
70384
|
-
* @param {{ force?: boolean }} options The options for removing the key.
|
|
70385
|
-
* @param {boolean} [options.force] Whether to force the removal of the key.
|
|
70386
|
-
* @returns {void} A promise that resolves when the key is removed.
|
|
70387
|
-
* @throws {KeyManagerError} If attempting to remove the active key without force.
|
|
70388
|
-
*/
|
|
70389
|
-
removeKey(id, options2 = {}) {
|
|
70390
|
-
if (this.#activeKeyId === id && !options2.force) {
|
|
70391
|
-
throw new KeyManagerError('Cannot remove active key (use "force": true or switch active key)', "ACTIVE_KEY_DELETE");
|
|
70392
|
-
}
|
|
70393
|
-
if (!this.#exists(id)) {
|
|
70394
|
-
throw new KeyManagerError(`Key not found: ${id}`, "KEY_NOT_FOUND");
|
|
70395
|
-
}
|
|
70396
|
-
this.#store.delete(id);
|
|
70397
|
-
if (this.#activeKeyId === id) {
|
|
70398
|
-
this.#activeKeyId = void 0;
|
|
70399
|
-
}
|
|
70400
|
-
}
|
|
70401
|
-
/**
|
|
70402
|
-
* Lists all key identifiers in the key store.
|
|
70403
|
-
* @returns {Promise<KeyIdentifier[]>} A promise that resolves to an array of key identifiers.
|
|
70404
|
-
*/
|
|
70405
|
-
listKeys() {
|
|
70406
|
-
return this.#store.entries().flatMap(([k, _]) => [k]);
|
|
70407
|
-
}
|
|
70408
|
-
/**
|
|
70409
|
-
* Sets the active key to the key associated with the given ID.
|
|
70410
|
-
* @param {KeyIdentifier} id The ID of the key to set as active.
|
|
70411
|
-
* @returns {Promise<void>} A promise that resolves when the active key is set.
|
|
70412
|
-
* @throws {KeyManagerError} If the key is not found.
|
|
70413
|
-
*/
|
|
70414
|
-
setActiveKey(id) {
|
|
70415
|
-
this.#getKeyOrThrow(id);
|
|
70416
|
-
this.#activeKeyId = id;
|
|
70417
|
-
}
|
|
70418
|
-
/**
|
|
70419
|
-
* Gets the public key associated with the given ID or the active key if no ID is provided.
|
|
70420
|
-
* @param {KeyIdentifier} [id] The ID of the key to get the public key for.
|
|
70421
|
-
* @returns {Promise<KeyBytes>} A promise resolving to the public key bytes.
|
|
70422
|
-
*/
|
|
70423
|
-
getPublicKey(id) {
|
|
70424
|
-
const { publicKey: publicKey2 } = this.#getKeyOrThrow(id);
|
|
70425
|
-
return publicKey2.compressed;
|
|
70426
|
-
}
|
|
70427
|
-
/**
|
|
70428
|
-
* Signs the given data using the key associated with the key ID.
|
|
70429
|
-
* @param {Bytes} data The data to sign.
|
|
70430
|
-
* @param {KeyIdentifier} [id] The ID of the key to sign the data with.
|
|
70431
|
-
* @returns {Promise<SignatureBytes>} A promise resolving to the signature of the data.
|
|
70432
|
-
*/
|
|
70433
|
-
sign(data, id) {
|
|
70434
|
-
const { secretKey } = this.#getKeyOrThrow(id);
|
|
70435
|
-
if (!secretKey) {
|
|
70436
|
-
throw new KeyManagerError(`Key ID ${id} is not a signer`, "KEY_NOT_SIGNER");
|
|
70437
|
-
}
|
|
70438
|
-
return secretKey.sign(data);
|
|
70439
|
-
}
|
|
70440
|
-
/**
|
|
70441
|
-
* Verifies a signature using the key associated with the key ID.
|
|
70442
|
-
* @param {KeyIdentifier} id The ID of the key to verify the signature with.
|
|
70443
|
-
* @param {SignatureBytes} signature The signature to verify.
|
|
70444
|
-
* @param {Hex} data The data to verify the signature with.
|
|
70445
|
-
* @returns {Promise<boolean>} A promise resolving to a boolean indicating the verification result.
|
|
70446
|
-
*/
|
|
70447
|
-
verify(signature2, data, id) {
|
|
70448
|
-
const { publicKey: publicKey2 } = this.#getKeyOrThrow(id);
|
|
70449
|
-
return publicKey2.verify(signature2, data);
|
|
70450
|
-
}
|
|
70451
|
-
/**
|
|
70452
|
-
* Imports a key pair into the key store.
|
|
70453
|
-
* @param {SchnorrKeyPair} keyPair The key pair to import.
|
|
70454
|
-
* @param {{ id?: KeyIdentifier; setActive?: boolean }} options The options for importing the key pair.
|
|
70455
|
-
* @param {KeyIdentifier} [options.id] The ID of the key to import (optional).
|
|
70456
|
-
* @param {boolean} [options.setActive] Whether to set the key as active (optional, default: true).
|
|
70457
|
-
* @returns {Promise<KeyIdentifier>} A promise resolving to the ID of the imported key.
|
|
70458
|
-
*/
|
|
70459
|
-
importKey(keyPair, options2 = {}) {
|
|
70460
|
-
if (!keyPair.publicKey) {
|
|
70461
|
-
keyPair.publicKey = keyPair.secretKey.computePublicKey();
|
|
70462
|
-
}
|
|
70463
|
-
const id = options2.id ?? keyPair.publicKey.hex;
|
|
70464
|
-
if (this.#exists(id)) {
|
|
70465
|
-
throw new KeyManagerError(`Key already exists: ${id}`, "KEY_FOUND");
|
|
70466
|
-
}
|
|
70467
|
-
this.#store.set(id, keyPair.secretKey.bytes);
|
|
70468
|
-
const setActive = options2.setActive ?? true;
|
|
70469
|
-
if (setActive) {
|
|
70470
|
-
this.#activeKeyId = id;
|
|
70471
|
-
}
|
|
70472
|
-
return id;
|
|
70473
|
-
}
|
|
70474
|
-
/**
|
|
70475
|
-
* Computes the hash of the given data.
|
|
70476
|
-
* @param {Uint8Array} data The data to hash.
|
|
70477
|
-
* @returns {HashBytes} The hash of the data.
|
|
70478
|
-
*/
|
|
70479
|
-
digest(data) {
|
|
70480
|
-
return sha2565(data);
|
|
70481
|
-
}
|
|
70482
|
-
/**
|
|
70483
|
-
* Generates a new key pair and stores it in the key store.
|
|
70484
|
-
* @returns {KeyIdentifier} The key identifier of the generated key.
|
|
70485
|
-
*/
|
|
70486
|
-
generateKey() {
|
|
70487
|
-
const kp = SchnorrKeyPair.generate();
|
|
70488
|
-
const id = kp.publicKey.hex;
|
|
70489
|
-
this.#store.set(id, kp.secretKey.bytes);
|
|
70490
|
-
this.#activeKeyId = id;
|
|
70491
|
-
return id;
|
|
70492
|
-
}
|
|
70493
|
-
/**
|
|
70494
|
-
* Initializes a singleton KeyManager instance.
|
|
70495
|
-
* @param {SchnorrKeyPair} keyPair The secret key to import.
|
|
70496
|
-
* @param {string} id The ID to set as the active key.
|
|
70497
|
-
* @returns {void}
|
|
70498
|
-
*/
|
|
70499
|
-
static initialize(keyPair, id) {
|
|
70500
|
-
if (_Kms.#instance) {
|
|
70501
|
-
console.warn("WARNING: Kms global instance is already initialized.");
|
|
70502
|
-
return _Kms.#instance;
|
|
70503
|
-
}
|
|
70504
|
-
if (!keyPair) {
|
|
70505
|
-
console.warn("WARNING: secretKey not provided, generating new SchnorrKeyPair ...");
|
|
70506
|
-
}
|
|
70507
|
-
keyPair ??= SchnorrKeyPair.generate();
|
|
70508
|
-
_Kms.#instance = new _Kms();
|
|
70509
|
-
_Kms.#instance.importKey(keyPair, { setActive: true, id });
|
|
70510
|
-
_Kms.#instance.#activeKeyId = id;
|
|
70511
|
-
console.info(`Kms initialized with Active Key ID: ${_Kms.#instance.#activeKeyId}`);
|
|
70512
|
-
return _Kms.#instance;
|
|
70513
|
-
}
|
|
70514
|
-
/**
|
|
70515
|
-
* Retrieves a keypair from the key store using the provided key ID.
|
|
70516
|
-
* @public
|
|
70517
|
-
* @param {KeyIdentifier} id The ID of the keypair to retrieve.
|
|
70518
|
-
* @returns {Promise<SchnorrKeyPair | undefined>} The retrieved keypair, or undefined if not found.
|
|
70519
|
-
*/
|
|
70520
|
-
static getKey(id) {
|
|
70521
|
-
if (!_Kms.#instance) {
|
|
70522
|
-
throw new KeyManagerError("Kms instance not initialized", "KMS_NOT_INITIALIZED");
|
|
70523
|
-
}
|
|
70524
|
-
id ??= _Kms.#instance.activeKeyId;
|
|
70525
|
-
return _Kms.#instance.#getKeyOrThrow(id);
|
|
70526
|
-
}
|
|
70527
|
-
};
|
|
70528
69884
|
|
|
70529
69885
|
// ../kms/dist/esm/signer.js
|
|
70530
69886
|
init_shim();
|
|
@@ -70561,7 +69917,7 @@ var Signer = class {
|
|
|
70561
69917
|
* @param {Bytes} hash The hash to sign.
|
|
70562
69918
|
* @returns {SignatureBytes} The signature of the hash.
|
|
70563
69919
|
*/
|
|
70564
|
-
|
|
69920
|
+
sign(hash4) {
|
|
70565
69921
|
return this.keyPair.secretKey.sign(hash4, { scheme: "ecdsa" });
|
|
70566
69922
|
}
|
|
70567
69923
|
/**
|
|
@@ -70569,7 +69925,7 @@ var Signer = class {
|
|
|
70569
69925
|
* @param {Bytes} hash The hash to sign.
|
|
70570
69926
|
* @returns {SignatureBytes} The Schnorr signature of the hash.
|
|
70571
69927
|
*/
|
|
70572
|
-
|
|
69928
|
+
signSchnorr(hash4) {
|
|
70573
69929
|
return this.keyPair.secretKey.sign(hash4);
|
|
70574
69930
|
}
|
|
70575
69931
|
};
|
|
@@ -73375,11 +72731,11 @@ init_shim();
|
|
|
73375
72731
|
|
|
73376
72732
|
// ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/_assert.js
|
|
73377
72733
|
init_shim();
|
|
73378
|
-
function
|
|
72734
|
+
function isBytes6(a3) {
|
|
73379
72735
|
return a3 instanceof Uint8Array || a3 != null && typeof a3 === "object" && a3.constructor.name === "Uint8Array";
|
|
73380
72736
|
}
|
|
73381
72737
|
function bytes4(b2, ...lengths) {
|
|
73382
|
-
if (!
|
|
72738
|
+
if (!isBytes6(b2))
|
|
73383
72739
|
throw new Error("Uint8Array expected");
|
|
73384
72740
|
if (lengths.length > 0 && !lengths.includes(b2.length))
|
|
73385
72741
|
throw new Error(`Uint8Array expected of length ${lengths}, not of length=${b2.length}`);
|
|
@@ -73406,8 +72762,8 @@ init_shim();
|
|
|
73406
72762
|
var crypto5 = typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
73407
72763
|
|
|
73408
72764
|
// ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/utils.js
|
|
73409
|
-
var
|
|
73410
|
-
var
|
|
72765
|
+
var createView6 = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
72766
|
+
var rotr4 = (word2, shift) => word2 << 32 - shift | word2 >>> shift;
|
|
73411
72767
|
var isLE4 = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
73412
72768
|
function utf8ToBytes6(str) {
|
|
73413
72769
|
if (typeof str !== "string")
|
|
@@ -73455,9 +72811,9 @@ function setBigUint645(view, byteOffset, value3, isLE7) {
|
|
|
73455
72811
|
view.setUint32(byteOffset + h2, wh, isLE7);
|
|
73456
72812
|
view.setUint32(byteOffset + l2, wl, isLE7);
|
|
73457
72813
|
}
|
|
73458
|
-
var
|
|
73459
|
-
var
|
|
73460
|
-
var
|
|
72814
|
+
var Chi4 = (a3, b2, c2) => a3 & b2 ^ ~a3 & c2;
|
|
72815
|
+
var Maj4 = (a3, b2, c2) => a3 & b2 ^ a3 & c2 ^ b2 & c2;
|
|
72816
|
+
var HashMD2 = class extends Hash4 {
|
|
73461
72817
|
constructor(blockLen, outputLen, padOffset, isLE7) {
|
|
73462
72818
|
super();
|
|
73463
72819
|
this.blockLen = blockLen;
|
|
@@ -73469,7 +72825,7 @@ var HashMD3 = class extends Hash4 {
|
|
|
73469
72825
|
this.pos = 0;
|
|
73470
72826
|
this.destroyed = false;
|
|
73471
72827
|
this.buffer = new Uint8Array(blockLen);
|
|
73472
|
-
this.view =
|
|
72828
|
+
this.view = createView6(this.buffer);
|
|
73473
72829
|
}
|
|
73474
72830
|
update(data) {
|
|
73475
72831
|
exists4(this);
|
|
@@ -73479,7 +72835,7 @@ var HashMD3 = class extends Hash4 {
|
|
|
73479
72835
|
for (let pos = 0; pos < len; ) {
|
|
73480
72836
|
const take2 = Math.min(blockLen - this.pos, len - pos);
|
|
73481
72837
|
if (take2 === blockLen) {
|
|
73482
|
-
const dataView2 =
|
|
72838
|
+
const dataView2 = createView6(data);
|
|
73483
72839
|
for (; blockLen <= len - pos; pos += blockLen)
|
|
73484
72840
|
this.process(dataView2, pos);
|
|
73485
72841
|
continue;
|
|
@@ -73512,7 +72868,7 @@ var HashMD3 = class extends Hash4 {
|
|
|
73512
72868
|
buffer2[i4] = 0;
|
|
73513
72869
|
setBigUint645(view, blockLen - 8, BigInt(this.length * 8), isLE7);
|
|
73514
72870
|
this.process(view, 0);
|
|
73515
|
-
const oview =
|
|
72871
|
+
const oview = createView6(out);
|
|
73516
72872
|
const len = this.outputLen;
|
|
73517
72873
|
if (len % 4)
|
|
73518
72874
|
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
@@ -73545,7 +72901,7 @@ var HashMD3 = class extends Hash4 {
|
|
|
73545
72901
|
};
|
|
73546
72902
|
|
|
73547
72903
|
// ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/sha256.js
|
|
73548
|
-
var
|
|
72904
|
+
var SHA256_K4 = /* @__PURE__ */ new Uint32Array([
|
|
73549
72905
|
1116352408,
|
|
73550
72906
|
1899447441,
|
|
73551
72907
|
3049323471,
|
|
@@ -73611,7 +72967,7 @@ var SHA256_K5 = /* @__PURE__ */ new Uint32Array([
|
|
|
73611
72967
|
3204031479,
|
|
73612
72968
|
3329325298
|
|
73613
72969
|
]);
|
|
73614
|
-
var
|
|
72970
|
+
var SHA256_IV2 = /* @__PURE__ */ new Uint32Array([
|
|
73615
72971
|
1779033703,
|
|
73616
72972
|
3144134277,
|
|
73617
72973
|
1013904242,
|
|
@@ -73621,18 +72977,18 @@ var SHA256_IV3 = /* @__PURE__ */ new Uint32Array([
|
|
|
73621
72977
|
528734635,
|
|
73622
72978
|
1541459225
|
|
73623
72979
|
]);
|
|
73624
|
-
var
|
|
73625
|
-
var SHA2564 = class extends
|
|
72980
|
+
var SHA256_W4 = /* @__PURE__ */ new Uint32Array(64);
|
|
72981
|
+
var SHA2564 = class extends HashMD2 {
|
|
73626
72982
|
constructor() {
|
|
73627
72983
|
super(64, 32, 8, false);
|
|
73628
|
-
this.A =
|
|
73629
|
-
this.B =
|
|
73630
|
-
this.C =
|
|
73631
|
-
this.D =
|
|
73632
|
-
this.E =
|
|
73633
|
-
this.F =
|
|
73634
|
-
this.G =
|
|
73635
|
-
this.H =
|
|
72984
|
+
this.A = SHA256_IV2[0] | 0;
|
|
72985
|
+
this.B = SHA256_IV2[1] | 0;
|
|
72986
|
+
this.C = SHA256_IV2[2] | 0;
|
|
72987
|
+
this.D = SHA256_IV2[3] | 0;
|
|
72988
|
+
this.E = SHA256_IV2[4] | 0;
|
|
72989
|
+
this.F = SHA256_IV2[5] | 0;
|
|
72990
|
+
this.G = SHA256_IV2[6] | 0;
|
|
72991
|
+
this.H = SHA256_IV2[7] | 0;
|
|
73636
72992
|
}
|
|
73637
72993
|
get() {
|
|
73638
72994
|
const { A, B, C: C2, D, E, F, G: G2, H } = this;
|
|
@@ -73651,20 +73007,20 @@ var SHA2564 = class extends HashMD3 {
|
|
|
73651
73007
|
}
|
|
73652
73008
|
process(view, offset) {
|
|
73653
73009
|
for (let i4 = 0; i4 < 16; i4++, offset += 4)
|
|
73654
|
-
|
|
73010
|
+
SHA256_W4[i4] = view.getUint32(offset, false);
|
|
73655
73011
|
for (let i4 = 16; i4 < 64; i4++) {
|
|
73656
|
-
const W15 =
|
|
73657
|
-
const W2 =
|
|
73658
|
-
const s0 =
|
|
73659
|
-
const s1 =
|
|
73660
|
-
|
|
73012
|
+
const W15 = SHA256_W4[i4 - 15];
|
|
73013
|
+
const W2 = SHA256_W4[i4 - 2];
|
|
73014
|
+
const s0 = rotr4(W15, 7) ^ rotr4(W15, 18) ^ W15 >>> 3;
|
|
73015
|
+
const s1 = rotr4(W2, 17) ^ rotr4(W2, 19) ^ W2 >>> 10;
|
|
73016
|
+
SHA256_W4[i4] = s1 + SHA256_W4[i4 - 7] + s0 + SHA256_W4[i4 - 16] | 0;
|
|
73661
73017
|
}
|
|
73662
73018
|
let { A, B, C: C2, D, E, F, G: G2, H } = this;
|
|
73663
73019
|
for (let i4 = 0; i4 < 64; i4++) {
|
|
73664
|
-
const sigma1 =
|
|
73665
|
-
const T1 = H + sigma1 +
|
|
73666
|
-
const sigma0 =
|
|
73667
|
-
const T2 = sigma0 +
|
|
73020
|
+
const sigma1 = rotr4(E, 6) ^ rotr4(E, 11) ^ rotr4(E, 25);
|
|
73021
|
+
const T1 = H + sigma1 + Chi4(E, F, G2) + SHA256_K4[i4] + SHA256_W4[i4] | 0;
|
|
73022
|
+
const sigma0 = rotr4(A, 2) ^ rotr4(A, 13) ^ rotr4(A, 22);
|
|
73023
|
+
const T2 = sigma0 + Maj4(A, B, C2) | 0;
|
|
73668
73024
|
H = G2;
|
|
73669
73025
|
G2 = F;
|
|
73670
73026
|
F = E;
|
|
@@ -73685,14 +73041,14 @@ var SHA2564 = class extends HashMD3 {
|
|
|
73685
73041
|
this.set(A, B, C2, D, E, F, G2, H);
|
|
73686
73042
|
}
|
|
73687
73043
|
roundClean() {
|
|
73688
|
-
|
|
73044
|
+
SHA256_W4.fill(0);
|
|
73689
73045
|
}
|
|
73690
73046
|
destroy() {
|
|
73691
73047
|
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
73692
73048
|
this.buffer.fill(0);
|
|
73693
73049
|
}
|
|
73694
73050
|
};
|
|
73695
|
-
var
|
|
73051
|
+
var sha2565 = /* @__PURE__ */ wrapConstructor3(() => new SHA2564());
|
|
73696
73052
|
|
|
73697
73053
|
// ../../node_modules/.pnpm/@web5+crypto@1.0.6/node_modules/@web5/crypto/dist/esm/primitives/sha256.js
|
|
73698
73054
|
var __awaiter3 = function(thisArg, _arguments, P3, generator) {
|
|
@@ -73744,7 +73100,7 @@ var Sha256 = class {
|
|
|
73744
73100
|
*/
|
|
73745
73101
|
static digest(_a3) {
|
|
73746
73102
|
return __awaiter3(this, arguments, void 0, function* ({ data }) {
|
|
73747
|
-
const hash4 =
|
|
73103
|
+
const hash4 = sha2565(data);
|
|
73748
73104
|
return hash4;
|
|
73749
73105
|
});
|
|
73750
73106
|
}
|
|
@@ -73842,11 +73198,11 @@ function number6(n3) {
|
|
|
73842
73198
|
if (!Number.isSafeInteger(n3) || n3 < 0)
|
|
73843
73199
|
throw new Error(`Wrong positive integer: ${n3}`);
|
|
73844
73200
|
}
|
|
73845
|
-
function
|
|
73201
|
+
function isBytes7(a3) {
|
|
73846
73202
|
return a3 instanceof Uint8Array || a3 != null && typeof a3 === "object" && a3.constructor.name === "Uint8Array";
|
|
73847
73203
|
}
|
|
73848
73204
|
function bytes5(b2, ...lengths) {
|
|
73849
|
-
if (!
|
|
73205
|
+
if (!isBytes7(b2))
|
|
73850
73206
|
throw new Error("Expected Uint8Array");
|
|
73851
73207
|
if (lengths.length > 0 && !lengths.includes(b2.length))
|
|
73852
73208
|
throw new Error(`Expected Uint8Array of length ${lengths}, not of length=${b2.length}`);
|
|
@@ -73879,11 +73235,11 @@ init_shim();
|
|
|
73879
73235
|
var crypto6 = typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
73880
73236
|
|
|
73881
73237
|
// ../../node_modules/.pnpm/@noble+hashes@1.3.3/node_modules/@noble/hashes/esm/utils.js
|
|
73882
|
-
function
|
|
73238
|
+
function isBytes8(a3) {
|
|
73883
73239
|
return a3 instanceof Uint8Array || a3 != null && typeof a3 === "object" && a3.constructor.name === "Uint8Array";
|
|
73884
73240
|
}
|
|
73885
|
-
var
|
|
73886
|
-
var
|
|
73241
|
+
var createView7 = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
73242
|
+
var rotr5 = (word2, shift) => word2 << 32 - shift | word2 >>> shift;
|
|
73887
73243
|
var isLE5 = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
73888
73244
|
if (!isLE5)
|
|
73889
73245
|
throw new Error("Non little-endian hardware is not supported");
|
|
@@ -73895,7 +73251,7 @@ function utf8ToBytes7(str) {
|
|
|
73895
73251
|
function toBytes6(data) {
|
|
73896
73252
|
if (typeof data === "string")
|
|
73897
73253
|
data = utf8ToBytes7(data);
|
|
73898
|
-
if (!
|
|
73254
|
+
if (!isBytes8(data))
|
|
73899
73255
|
throw new Error(`expected Uint8Array, got ${typeof data}`);
|
|
73900
73256
|
return data;
|
|
73901
73257
|
}
|
|
@@ -73903,7 +73259,7 @@ function concatBytes8(...arrays) {
|
|
|
73903
73259
|
let sum = 0;
|
|
73904
73260
|
for (let i4 = 0; i4 < arrays.length; i4++) {
|
|
73905
73261
|
const a3 = arrays[i4];
|
|
73906
|
-
if (!
|
|
73262
|
+
if (!isBytes8(a3))
|
|
73907
73263
|
throw new Error("Uint8Array expected");
|
|
73908
73264
|
sum += a3.length;
|
|
73909
73265
|
}
|
|
@@ -73962,7 +73318,7 @@ var SHA23 = class extends Hash5 {
|
|
|
73962
73318
|
this.pos = 0;
|
|
73963
73319
|
this.destroyed = false;
|
|
73964
73320
|
this.buffer = new Uint8Array(blockLen);
|
|
73965
|
-
this.view =
|
|
73321
|
+
this.view = createView7(this.buffer);
|
|
73966
73322
|
}
|
|
73967
73323
|
update(data) {
|
|
73968
73324
|
exists5(this);
|
|
@@ -73972,7 +73328,7 @@ var SHA23 = class extends Hash5 {
|
|
|
73972
73328
|
for (let pos = 0; pos < len; ) {
|
|
73973
73329
|
const take2 = Math.min(blockLen - this.pos, len - pos);
|
|
73974
73330
|
if (take2 === blockLen) {
|
|
73975
|
-
const dataView2 =
|
|
73331
|
+
const dataView2 = createView7(data);
|
|
73976
73332
|
for (; blockLen <= len - pos; pos += blockLen)
|
|
73977
73333
|
this.process(dataView2, pos);
|
|
73978
73334
|
continue;
|
|
@@ -74005,7 +73361,7 @@ var SHA23 = class extends Hash5 {
|
|
|
74005
73361
|
buffer2[i4] = 0;
|
|
74006
73362
|
setBigUint646(view, blockLen - 8, BigInt(this.length * 8), isLE7);
|
|
74007
73363
|
this.process(view, 0);
|
|
74008
|
-
const oview =
|
|
73364
|
+
const oview = createView7(out);
|
|
74009
73365
|
const len = this.outputLen;
|
|
74010
73366
|
if (len % 4)
|
|
74011
73367
|
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
@@ -74038,9 +73394,9 @@ var SHA23 = class extends Hash5 {
|
|
|
74038
73394
|
};
|
|
74039
73395
|
|
|
74040
73396
|
// ../../node_modules/.pnpm/@noble+hashes@1.3.3/node_modules/@noble/hashes/esm/sha256.js
|
|
74041
|
-
var
|
|
74042
|
-
var
|
|
74043
|
-
var
|
|
73397
|
+
var Chi5 = (a3, b2, c2) => a3 & b2 ^ ~a3 & c2;
|
|
73398
|
+
var Maj5 = (a3, b2, c2) => a3 & b2 ^ a3 & c2 ^ b2 & c2;
|
|
73399
|
+
var SHA256_K5 = /* @__PURE__ */ new Uint32Array([
|
|
74044
73400
|
1116352408,
|
|
74045
73401
|
1899447441,
|
|
74046
73402
|
3049323471,
|
|
@@ -74116,7 +73472,7 @@ var IV3 = /* @__PURE__ */ new Uint32Array([
|
|
|
74116
73472
|
528734635,
|
|
74117
73473
|
1541459225
|
|
74118
73474
|
]);
|
|
74119
|
-
var
|
|
73475
|
+
var SHA256_W5 = /* @__PURE__ */ new Uint32Array(64);
|
|
74120
73476
|
var SHA2565 = class extends SHA23 {
|
|
74121
73477
|
constructor() {
|
|
74122
73478
|
super(64, 32, 8, false);
|
|
@@ -74146,20 +73502,20 @@ var SHA2565 = class extends SHA23 {
|
|
|
74146
73502
|
}
|
|
74147
73503
|
process(view, offset) {
|
|
74148
73504
|
for (let i4 = 0; i4 < 16; i4++, offset += 4)
|
|
74149
|
-
|
|
73505
|
+
SHA256_W5[i4] = view.getUint32(offset, false);
|
|
74150
73506
|
for (let i4 = 16; i4 < 64; i4++) {
|
|
74151
|
-
const W15 =
|
|
74152
|
-
const W2 =
|
|
74153
|
-
const s0 =
|
|
74154
|
-
const s1 =
|
|
74155
|
-
|
|
73507
|
+
const W15 = SHA256_W5[i4 - 15];
|
|
73508
|
+
const W2 = SHA256_W5[i4 - 2];
|
|
73509
|
+
const s0 = rotr5(W15, 7) ^ rotr5(W15, 18) ^ W15 >>> 3;
|
|
73510
|
+
const s1 = rotr5(W2, 17) ^ rotr5(W2, 19) ^ W2 >>> 10;
|
|
73511
|
+
SHA256_W5[i4] = s1 + SHA256_W5[i4 - 7] + s0 + SHA256_W5[i4 - 16] | 0;
|
|
74156
73512
|
}
|
|
74157
73513
|
let { A, B, C: C2, D, E, F, G: G2, H } = this;
|
|
74158
73514
|
for (let i4 = 0; i4 < 64; i4++) {
|
|
74159
|
-
const sigma1 =
|
|
74160
|
-
const T1 = H + sigma1 +
|
|
74161
|
-
const sigma0 =
|
|
74162
|
-
const T2 = sigma0 +
|
|
73515
|
+
const sigma1 = rotr5(E, 6) ^ rotr5(E, 11) ^ rotr5(E, 25);
|
|
73516
|
+
const T1 = H + sigma1 + Chi5(E, F, G2) + SHA256_K5[i4] + SHA256_W5[i4] | 0;
|
|
73517
|
+
const sigma0 = rotr5(A, 2) ^ rotr5(A, 13) ^ rotr5(A, 22);
|
|
73518
|
+
const T2 = sigma0 + Maj5(A, B, C2) | 0;
|
|
74163
73519
|
H = G2;
|
|
74164
73520
|
G2 = F;
|
|
74165
73521
|
F = E;
|
|
@@ -74180,14 +73536,14 @@ var SHA2565 = class extends SHA23 {
|
|
|
74180
73536
|
this.set(A, B, C2, D, E, F, G2, H);
|
|
74181
73537
|
}
|
|
74182
73538
|
roundClean() {
|
|
74183
|
-
|
|
73539
|
+
SHA256_W5.fill(0);
|
|
74184
73540
|
}
|
|
74185
73541
|
destroy() {
|
|
74186
73542
|
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
74187
73543
|
this.buffer.fill(0);
|
|
74188
73544
|
}
|
|
74189
73545
|
};
|
|
74190
|
-
var
|
|
73546
|
+
var sha2566 = /* @__PURE__ */ wrapConstructor4(() => new SHA2565());
|
|
74191
73547
|
|
|
74192
73548
|
// ../../node_modules/.pnpm/@noble+curves@1.3.0/node_modules/@noble/curves/esm/abstract/modular.js
|
|
74193
73549
|
init_shim();
|
|
@@ -74208,7 +73564,7 @@ __export(utils_exports4, {
|
|
|
74208
73564
|
equalBytes: () => equalBytes7,
|
|
74209
73565
|
hexToBytes: () => hexToBytes4,
|
|
74210
73566
|
hexToNumber: () => hexToNumber3,
|
|
74211
|
-
isBytes: () =>
|
|
73567
|
+
isBytes: () => isBytes9,
|
|
74212
73568
|
numberToBytesBE: () => numberToBytesBE4,
|
|
74213
73569
|
numberToBytesLE: () => numberToBytesLE3,
|
|
74214
73570
|
numberToHexUnpadded: () => numberToHexUnpadded3,
|
|
@@ -74220,12 +73576,12 @@ init_shim();
|
|
|
74220
73576
|
var _0n11 = BigInt(0);
|
|
74221
73577
|
var _1n11 = BigInt(1);
|
|
74222
73578
|
var _2n8 = BigInt(2);
|
|
74223
|
-
function
|
|
73579
|
+
function isBytes9(a3) {
|
|
74224
73580
|
return a3 instanceof Uint8Array || a3 != null && typeof a3 === "object" && a3.constructor.name === "Uint8Array";
|
|
74225
73581
|
}
|
|
74226
73582
|
var hexes4 = /* @__PURE__ */ Array.from({ length: 256 }, (_, i4) => i4.toString(16).padStart(2, "0"));
|
|
74227
73583
|
function bytesToHex4(bytes6) {
|
|
74228
|
-
if (!
|
|
73584
|
+
if (!isBytes9(bytes6))
|
|
74229
73585
|
throw new Error("Uint8Array expected");
|
|
74230
73586
|
let hex3 = "";
|
|
74231
73587
|
for (let i4 = 0; i4 < bytes6.length; i4++) {
|
|
@@ -74275,7 +73631,7 @@ function bytesToNumberBE4(bytes6) {
|
|
|
74275
73631
|
return hexToNumber3(bytesToHex4(bytes6));
|
|
74276
73632
|
}
|
|
74277
73633
|
function bytesToNumberLE3(bytes6) {
|
|
74278
|
-
if (!
|
|
73634
|
+
if (!isBytes9(bytes6))
|
|
74279
73635
|
throw new Error("Uint8Array expected");
|
|
74280
73636
|
return hexToNumber3(bytesToHex4(Uint8Array.from(bytes6).reverse()));
|
|
74281
73637
|
}
|
|
@@ -74296,7 +73652,7 @@ function ensureBytes3(title, hex3, expectedLength) {
|
|
|
74296
73652
|
} catch (e2) {
|
|
74297
73653
|
throw new Error(`${title} must be valid hex string, got "${hex3}". Cause: ${e2}`);
|
|
74298
73654
|
}
|
|
74299
|
-
} else if (
|
|
73655
|
+
} else if (isBytes9(hex3)) {
|
|
74300
73656
|
res = Uint8Array.from(hex3);
|
|
74301
73657
|
} else {
|
|
74302
73658
|
throw new Error(`${title} must be hex string or Uint8Array`);
|
|
@@ -74310,7 +73666,7 @@ function concatBytes9(...arrays) {
|
|
|
74310
73666
|
let sum = 0;
|
|
74311
73667
|
for (let i4 = 0; i4 < arrays.length; i4++) {
|
|
74312
73668
|
const a3 = arrays[i4];
|
|
74313
|
-
if (!
|
|
73669
|
+
if (!isBytes9(a3))
|
|
74314
73670
|
throw new Error("Uint8Array expected");
|
|
74315
73671
|
sum += a3.length;
|
|
74316
73672
|
}
|
|
@@ -74404,7 +73760,7 @@ var validatorFns2 = {
|
|
|
74404
73760
|
function: (val) => typeof val === "function",
|
|
74405
73761
|
boolean: (val) => typeof val === "boolean",
|
|
74406
73762
|
string: (val) => typeof val === "string",
|
|
74407
|
-
stringOrUint8Array: (val) => typeof val === "string" ||
|
|
73763
|
+
stringOrUint8Array: (val) => typeof val === "string" || isBytes9(val),
|
|
74408
73764
|
isSafeInteger: (val) => Number.isSafeInteger(val),
|
|
74409
73765
|
array: (val) => Array.isArray(val),
|
|
74410
73766
|
field: (val, object2) => object2.Fp.isValid(val),
|
|
@@ -74875,7 +74231,7 @@ var DER3 = {
|
|
|
74875
74231
|
toSig(hex3) {
|
|
74876
74232
|
const { Err: E } = DER3;
|
|
74877
74233
|
const data = typeof hex3 === "string" ? h2b2(hex3) : hex3;
|
|
74878
|
-
if (!
|
|
74234
|
+
if (!isBytes9(data))
|
|
74879
74235
|
throw new Error("ui8a expected");
|
|
74880
74236
|
let l2 = data.length;
|
|
74881
74237
|
if (l2 < 2 || data[0] != 48)
|
|
@@ -74939,7 +74295,7 @@ function weierstrassPoints2(opts) {
|
|
|
74939
74295
|
function normPrivateKeyToScalar(key) {
|
|
74940
74296
|
const { allowedPrivateKeyLengths: lengths, nByteLength, wrapPrivateKey, n: n3 } = CURVE2;
|
|
74941
74297
|
if (lengths && typeof key !== "bigint") {
|
|
74942
|
-
if (
|
|
74298
|
+
if (isBytes9(key))
|
|
74943
74299
|
key = bytesToHex4(key);
|
|
74944
74300
|
if (typeof key !== "string" || !lengths.includes(key.length))
|
|
74945
74301
|
throw new Error("Invalid key");
|
|
@@ -75474,7 +74830,7 @@ function weierstrass3(curveDef) {
|
|
|
75474
74830
|
return Point7.fromPrivateKey(privateKey).toRawBytes(isCompressed);
|
|
75475
74831
|
}
|
|
75476
74832
|
function isProbPub(item) {
|
|
75477
|
-
const arr =
|
|
74833
|
+
const arr = isBytes9(item);
|
|
75478
74834
|
const str = typeof item === "string";
|
|
75479
74835
|
const len = (arr || str) && item.length;
|
|
75480
74836
|
if (arr)
|
|
@@ -75569,7 +74925,7 @@ function weierstrass3(curveDef) {
|
|
|
75569
74925
|
let _sig = void 0;
|
|
75570
74926
|
let P3;
|
|
75571
74927
|
try {
|
|
75572
|
-
if (typeof sg === "string" ||
|
|
74928
|
+
if (typeof sg === "string" || isBytes9(sg)) {
|
|
75573
74929
|
try {
|
|
75574
74930
|
_sig = Signature.fromDER(sg);
|
|
75575
74931
|
} catch (derError) {
|
|
@@ -75774,7 +75130,7 @@ var secp256k13 = createCurve3({
|
|
|
75774
75130
|
return { k1neg, k1, k2neg, k2 };
|
|
75775
75131
|
}
|
|
75776
75132
|
}
|
|
75777
|
-
},
|
|
75133
|
+
}, sha2566);
|
|
75778
75134
|
var _0n15 = BigInt(0);
|
|
75779
75135
|
var Point5 = secp256k13.ProjectivePoint;
|
|
75780
75136
|
|
|
@@ -76459,7 +75815,7 @@ var Secp256k1 = class _Secp256k1 {
|
|
|
76459
75815
|
static sign(_a3) {
|
|
76460
75816
|
return __awaiter6(this, arguments, void 0, function* ({ data, key }) {
|
|
76461
75817
|
const privateKeyBytes = yield _Secp256k1.privateKeyToBytes({ privateKey: key });
|
|
76462
|
-
const digest2 =
|
|
75818
|
+
const digest2 = sha2565(data);
|
|
76463
75819
|
const signatureObject = secp256k13.sign(digest2, privateKeyBytes);
|
|
76464
75820
|
const signature2 = signatureObject.toCompactRawBytes();
|
|
76465
75821
|
return signature2;
|
|
@@ -76571,7 +75927,7 @@ var Secp256k1 = class _Secp256k1 {
|
|
|
76571
75927
|
static verify(_a3) {
|
|
76572
75928
|
return __awaiter6(this, arguments, void 0, function* ({ key, signature: signature2, data }) {
|
|
76573
75929
|
const publicKeyBytes = yield _Secp256k1.publicKeyToBytes({ publicKey: key });
|
|
76574
|
-
const digest2 =
|
|
75930
|
+
const digest2 = sha2565(data);
|
|
76575
75931
|
const isValid2 = secp256k13.verify(signature2, digest2, publicKeyBytes, { lowS: false });
|
|
76576
75932
|
return isValid2;
|
|
76577
75933
|
});
|
|
@@ -76643,7 +75999,7 @@ var p256 = createCurve3({
|
|
|
76643
75999
|
Gy: BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),
|
|
76644
76000
|
h: BigInt(1),
|
|
76645
76001
|
lowS: false
|
|
76646
|
-
},
|
|
76002
|
+
}, sha2566);
|
|
76647
76003
|
var secp256r1 = p256;
|
|
76648
76004
|
|
|
76649
76005
|
// ../../node_modules/.pnpm/@web5+crypto@1.0.6/node_modules/@web5/crypto/dist/esm/primitives/secp256r1.js
|
|
@@ -77186,7 +76542,7 @@ var Secp256r1 = class _Secp256r1 {
|
|
|
77186
76542
|
static sign(_a3) {
|
|
77187
76543
|
return __awaiter7(this, arguments, void 0, function* ({ data, key }) {
|
|
77188
76544
|
const privateKeyBytes = yield _Secp256r1.privateKeyToBytes({ privateKey: key });
|
|
77189
|
-
const digest2 =
|
|
76545
|
+
const digest2 = sha2565(data);
|
|
77190
76546
|
const signatureObject = secp256r1.sign(digest2, privateKeyBytes);
|
|
77191
76547
|
const signature2 = signatureObject.toCompactRawBytes();
|
|
77192
76548
|
return signature2;
|
|
@@ -77298,7 +76654,7 @@ var Secp256r1 = class _Secp256r1 {
|
|
|
77298
76654
|
static verify(_a3) {
|
|
77299
76655
|
return __awaiter7(this, arguments, void 0, function* ({ key, signature: signature2, data }) {
|
|
77300
76656
|
const publicKeyBytes = yield _Secp256r1.publicKeyToBytes({ publicKey: key });
|
|
77301
|
-
const digest2 =
|
|
76657
|
+
const digest2 = sha2565(data);
|
|
77302
76658
|
const isValid2 = secp256r1.verify(signature2, digest2, publicKeyBytes, { lowS: false });
|
|
77303
76659
|
return isValid2;
|
|
77304
76660
|
});
|
|
@@ -84481,7 +83837,7 @@ var sha = (name10) => (
|
|
|
84481
83837
|
*/
|
|
84482
83838
|
async (data) => new Uint8Array(await crypto.subtle.digest(name10, data))
|
|
84483
83839
|
);
|
|
84484
|
-
var
|
|
83840
|
+
var sha2567 = from5({
|
|
84485
83841
|
name: "sha2-256",
|
|
84486
83842
|
code: 18,
|
|
84487
83843
|
encode: sha("SHA-256")
|
|
@@ -84531,7 +83887,7 @@ var Multihash = class _Multihash {
|
|
|
84531
83887
|
let multihash;
|
|
84532
83888
|
switch (hashAlgorithmInMultihashCode) {
|
|
84533
83889
|
case 18:
|
|
84534
|
-
let hasher = yield
|
|
83890
|
+
let hasher = yield sha2567.digest(content);
|
|
84535
83891
|
multihash = hasher.bytes;
|
|
84536
83892
|
break;
|
|
84537
83893
|
default:
|
|
@@ -84550,7 +83906,7 @@ var Multihash = class _Multihash {
|
|
|
84550
83906
|
let hash4;
|
|
84551
83907
|
switch (hashAlgorithmInMultihashCode) {
|
|
84552
83908
|
case 18:
|
|
84553
|
-
hash4 = yield
|
|
83909
|
+
hash4 = yield sha2567.encode(content);
|
|
84554
83910
|
break;
|
|
84555
83911
|
default:
|
|
84556
83912
|
throw new IonError(ErrorCode_default.MultihashUnsupportedHashAlgorithm, `Hash algorithm defined in multihash code ${hashAlgorithmInMultihashCode} is not supported.`);
|
|
@@ -84973,12 +84329,12 @@ var err = (m2 = "") => {
|
|
|
84973
84329
|
};
|
|
84974
84330
|
var isBig = (n3) => typeof n3 === "bigint";
|
|
84975
84331
|
var isStr = (s2) => typeof s2 === "string";
|
|
84976
|
-
var
|
|
84977
|
-
var
|
|
84332
|
+
var isBytes10 = (a3) => a3 instanceof Uint8Array || ArrayBuffer.isView(a3) && a3.constructor.name === "Uint8Array";
|
|
84333
|
+
var abytes3 = (a3, l2) => !isBytes10(a3) || typeof l2 === "number" && l2 > 0 && a3.length !== l2 ? err("Uint8Array expected") : a3;
|
|
84978
84334
|
var u8n3 = (len) => new Uint8Array(len);
|
|
84979
84335
|
var u8fr3 = (buf2) => Uint8Array.from(buf2);
|
|
84980
84336
|
var padh = (n3, pad2) => n3.toString(16).padStart(pad2, "0");
|
|
84981
|
-
var bytesToHex5 = (b2) => Array.from(
|
|
84337
|
+
var bytesToHex5 = (b2) => Array.from(abytes3(b2)).map((e2) => padh(e2, 2)).join("");
|
|
84982
84338
|
var C = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
84983
84339
|
var _ch = (ch) => {
|
|
84984
84340
|
if (ch >= C._0 && ch <= C._9)
|
|
@@ -85007,10 +84363,10 @@ var hexToBytes5 = (hex3) => {
|
|
|
85007
84363
|
}
|
|
85008
84364
|
return array2;
|
|
85009
84365
|
};
|
|
85010
|
-
var toU8 = (a3, len) =>
|
|
84366
|
+
var toU8 = (a3, len) => abytes3(isStr(a3) ? hexToBytes5(a3) : u8fr3(abytes3(a3)), len);
|
|
85011
84367
|
var cr = () => globalThis?.crypto;
|
|
85012
84368
|
var concatBytes10 = (...arrs) => {
|
|
85013
|
-
const r2 = u8n3(arrs.reduce((sum, a3) => sum +
|
|
84369
|
+
const r2 = u8n3(arrs.reduce((sum, a3) => sum + abytes3(a3).length, 0));
|
|
85014
84370
|
let pad2 = 0;
|
|
85015
84371
|
arrs.forEach((a3) => {
|
|
85016
84372
|
r2.set(a3, pad2);
|
|
@@ -85071,7 +84427,7 @@ var Point6 = class _Point {
|
|
|
85071
84427
|
}
|
|
85072
84428
|
/** Convert Uint8Array or hex string to Point. */
|
|
85073
84429
|
static fromBytes(bytes6) {
|
|
85074
|
-
|
|
84430
|
+
abytes3(bytes6);
|
|
85075
84431
|
let p3 = void 0;
|
|
85076
84432
|
const head = bytes6[0];
|
|
85077
84433
|
const tail = bytes6.subarray(1);
|
|
@@ -87250,7 +86606,7 @@ function decode37(data) {
|
|
|
87250
86606
|
// ../../node_modules/.pnpm/multiformats@13.4.1/node_modules/multiformats/dist/src/hashes/sha2-browser.js
|
|
87251
86607
|
var sha2_browser_exports = {};
|
|
87252
86608
|
__export(sha2_browser_exports, {
|
|
87253
|
-
sha256: () =>
|
|
86609
|
+
sha256: () => sha2568,
|
|
87254
86610
|
sha512: () => sha5124
|
|
87255
86611
|
});
|
|
87256
86612
|
init_shim();
|
|
@@ -87308,7 +86664,7 @@ function createDigest(digest2, code8, truncate) {
|
|
|
87308
86664
|
function sha2(name10) {
|
|
87309
86665
|
return async (data) => new Uint8Array(await crypto.subtle.digest(name10, data));
|
|
87310
86666
|
}
|
|
87311
|
-
var
|
|
86667
|
+
var sha2568 = from6({
|
|
87312
86668
|
name: "sha2-256",
|
|
87313
86669
|
code: 18,
|
|
87314
86670
|
encode: sha2("SHA-256")
|
|
@@ -87625,7 +86981,7 @@ var DefaultStrings = class {
|
|
|
87625
86981
|
}
|
|
87626
86982
|
async add(string4, options2 = {}) {
|
|
87627
86983
|
const buf2 = fromString2(string4);
|
|
87628
|
-
const hash4 = await (options2.hasher ??
|
|
86984
|
+
const hash4 = await (options2.hasher ?? sha2568).digest(buf2);
|
|
87629
86985
|
const codec2 = options2.codec ?? raw_exports;
|
|
87630
86986
|
const cid = CID2.createV1(codec2.code, hash4);
|
|
87631
86987
|
await this.components.blockstore.put(cid, buf2, options2);
|
|
@@ -91684,7 +91040,7 @@ var Key = class _Key {
|
|
|
91684
91040
|
* @param {string | Uint8Array} s
|
|
91685
91041
|
* @param {boolean} [clean]
|
|
91686
91042
|
*/
|
|
91687
|
-
constructor(s2,
|
|
91043
|
+
constructor(s2, clean3) {
|
|
91688
91044
|
if (typeof s2 === "string") {
|
|
91689
91045
|
this._buf = fromString2(s2);
|
|
91690
91046
|
} else if (s2 instanceof Uint8Array) {
|
|
@@ -91692,10 +91048,10 @@ var Key = class _Key {
|
|
|
91692
91048
|
} else {
|
|
91693
91049
|
throw new Error("Invalid key, should be String of Uint8Array");
|
|
91694
91050
|
}
|
|
91695
|
-
if (
|
|
91696
|
-
|
|
91051
|
+
if (clean3 == null) {
|
|
91052
|
+
clean3 = true;
|
|
91697
91053
|
}
|
|
91698
|
-
if (
|
|
91054
|
+
if (clean3) {
|
|
91699
91055
|
this.clean();
|
|
91700
91056
|
}
|
|
91701
91057
|
if (this._buf.byteLength === 0 || this._buf[0] !== pathSep) {
|
|
@@ -95207,7 +94563,7 @@ function getCodec(initialCodecs = [], loadCodec) {
|
|
|
95207
94563
|
init_shim();
|
|
95208
94564
|
function getHasher(initialHashers = [], loadHasher) {
|
|
95209
94565
|
const hashers = {
|
|
95210
|
-
[
|
|
94566
|
+
[sha2568.code]: sha2568,
|
|
95211
94567
|
[sha5124.code]: sha5124,
|
|
95212
94568
|
[identity2.code]: identity2
|
|
95213
94569
|
};
|
|
@@ -99681,7 +99037,7 @@ function rsaKeySize(jwk) {
|
|
|
99681
99037
|
init_shim();
|
|
99682
99038
|
var PRIVATE_KEY_BYTE_LENGTH2 = 32;
|
|
99683
99039
|
function hashAndSign4(key, msg, options2) {
|
|
99684
|
-
const p3 =
|
|
99040
|
+
const p3 = sha2568.digest(msg instanceof Uint8Array ? msg : msg.subarray());
|
|
99685
99041
|
if (isPromise3(p3)) {
|
|
99686
99042
|
return p3.then(({ digest: digest2 }) => {
|
|
99687
99043
|
options2?.signal?.throwIfAborted();
|
|
@@ -99700,7 +99056,7 @@ function hashAndSign4(key, msg, options2) {
|
|
|
99700
99056
|
}
|
|
99701
99057
|
}
|
|
99702
99058
|
function hashAndVerify4(key, sig, msg, options2) {
|
|
99703
|
-
const p3 =
|
|
99059
|
+
const p3 = sha2568.digest(msg instanceof Uint8Array ? msg : msg.subarray());
|
|
99704
99060
|
if (isPromise3(p3)) {
|
|
99705
99061
|
return p3.then(({ digest: digest2 }) => {
|
|
99706
99062
|
options2?.signal?.throwIfAborted();
|
|
@@ -102007,7 +101363,7 @@ function isIdentityMultihash(multihash) {
|
|
|
102007
101363
|
return multihash.code === identity2.code;
|
|
102008
101364
|
}
|
|
102009
101365
|
function isSha256Multihash(multihash) {
|
|
102010
|
-
return multihash.code ===
|
|
101366
|
+
return multihash.code === sha2568.code;
|
|
102011
101367
|
}
|
|
102012
101368
|
|
|
102013
101369
|
// ../../node_modules/.pnpm/@libp2p+peer-collections@6.0.35/node_modules/@libp2p/peer-collections/dist/src/util.js
|
|
@@ -102865,7 +102221,7 @@ var WantList = class extends TypedEventEmitter {
|
|
|
102865
102221
|
const cidVersion = values[0];
|
|
102866
102222
|
const multicodec2 = values[1];
|
|
102867
102223
|
const hashAlg = values[2];
|
|
102868
|
-
const hasher = hashAlg ===
|
|
102224
|
+
const hasher = hashAlg === sha2568.code ? sha2568 : await this.hashLoader?.getHasher(hashAlg);
|
|
102869
102225
|
if (hasher == null) {
|
|
102870
102226
|
this.log.error("unknown hash algorithm", hashAlg);
|
|
102871
102227
|
continue;
|
|
@@ -117175,7 +116531,7 @@ function DsInfoName(name10) {
|
|
|
117175
116531
|
}
|
|
117176
116532
|
async function keyId(key) {
|
|
117177
116533
|
const pb = privateKeyToProtobuf(key);
|
|
117178
|
-
const hash4 = await
|
|
116534
|
+
const hash4 = await sha2568.digest(pb);
|
|
117179
116535
|
return base58btc.encode(hash4.bytes).substring(1);
|
|
117180
116536
|
}
|
|
117181
116537
|
var Keychain = class {
|
|
@@ -117528,7 +116884,7 @@ init_shim();
|
|
|
117528
116884
|
|
|
117529
116885
|
// ../../node_modules/.pnpm/@noble+ciphers@1.3.0/node_modules/@noble/ciphers/esm/utils.js
|
|
117530
116886
|
init_shim();
|
|
117531
|
-
function
|
|
116887
|
+
function isBytes11(a3) {
|
|
117532
116888
|
return a3 instanceof Uint8Array || ArrayBuffer.isView(a3) && a3.constructor.name === "Uint8Array";
|
|
117533
116889
|
}
|
|
117534
116890
|
function abool2(b2) {
|
|
@@ -117539,20 +116895,20 @@ function anumber3(n3) {
|
|
|
117539
116895
|
if (!Number.isSafeInteger(n3) || n3 < 0)
|
|
117540
116896
|
throw new Error("positive integer expected, got " + n3);
|
|
117541
116897
|
}
|
|
117542
|
-
function
|
|
117543
|
-
if (!
|
|
116898
|
+
function abytes4(b2, ...lengths) {
|
|
116899
|
+
if (!isBytes11(b2))
|
|
117544
116900
|
throw new Error("Uint8Array expected");
|
|
117545
116901
|
if (lengths.length > 0 && !lengths.includes(b2.length))
|
|
117546
116902
|
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b2.length);
|
|
117547
116903
|
}
|
|
117548
|
-
function
|
|
116904
|
+
function aexists2(instance3, checkFinished = true) {
|
|
117549
116905
|
if (instance3.destroyed)
|
|
117550
116906
|
throw new Error("Hash instance has been destroyed");
|
|
117551
116907
|
if (checkFinished && instance3.finished)
|
|
117552
116908
|
throw new Error("Hash#digest() has already been called");
|
|
117553
116909
|
}
|
|
117554
|
-
function
|
|
117555
|
-
|
|
116910
|
+
function aoutput2(out, instance3) {
|
|
116911
|
+
abytes4(out);
|
|
117556
116912
|
const min = instance3.outputLen;
|
|
117557
116913
|
if (out.length < min) {
|
|
117558
116914
|
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
@@ -117561,12 +116917,12 @@ function aoutput3(out, instance3) {
|
|
|
117561
116917
|
function u322(arr) {
|
|
117562
116918
|
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
117563
116919
|
}
|
|
117564
|
-
function
|
|
116920
|
+
function clean2(...arrays) {
|
|
117565
116921
|
for (let i4 = 0; i4 < arrays.length; i4++) {
|
|
117566
116922
|
arrays[i4].fill(0);
|
|
117567
116923
|
}
|
|
117568
116924
|
}
|
|
117569
|
-
function
|
|
116925
|
+
function createView8(arr) {
|
|
117570
116926
|
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
117571
116927
|
}
|
|
117572
116928
|
var isLE6 = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
@@ -117578,7 +116934,7 @@ function utf8ToBytes10(str) {
|
|
|
117578
116934
|
function toBytes7(data) {
|
|
117579
116935
|
if (typeof data === "string")
|
|
117580
116936
|
data = utf8ToBytes10(data);
|
|
117581
|
-
else if (
|
|
116937
|
+
else if (isBytes11(data))
|
|
117582
116938
|
data = copyBytes2(data);
|
|
117583
116939
|
else
|
|
117584
116940
|
throw new Error("Uint8Array expected, got " + typeof data);
|
|
@@ -117600,7 +116956,7 @@ function equalBytes8(a3, b2) {
|
|
|
117600
116956
|
}
|
|
117601
116957
|
var wrapCipher2 = /* @__NO_SIDE_EFFECTS__ */ (params, constructor) => {
|
|
117602
116958
|
function wrappedCipher(key, ...args) {
|
|
117603
|
-
|
|
116959
|
+
abytes4(key);
|
|
117604
116960
|
if (!isLE6)
|
|
117605
116961
|
throw new Error("Non little-endian hardware is not yet supported");
|
|
117606
116962
|
if (params.nonceLength !== void 0) {
|
|
@@ -117608,20 +116964,20 @@ var wrapCipher2 = /* @__NO_SIDE_EFFECTS__ */ (params, constructor) => {
|
|
|
117608
116964
|
if (!nonce)
|
|
117609
116965
|
throw new Error("nonce / iv required");
|
|
117610
116966
|
if (params.varSizeNonce)
|
|
117611
|
-
|
|
116967
|
+
abytes4(nonce);
|
|
117612
116968
|
else
|
|
117613
|
-
|
|
116969
|
+
abytes4(nonce, params.nonceLength);
|
|
117614
116970
|
}
|
|
117615
116971
|
const tagl = params.tagLength;
|
|
117616
116972
|
if (tagl && args[1] !== void 0) {
|
|
117617
|
-
|
|
116973
|
+
abytes4(args[1]);
|
|
117618
116974
|
}
|
|
117619
116975
|
const cipher = constructor(key, ...args);
|
|
117620
116976
|
const checkOutput = (fnLength, output6) => {
|
|
117621
116977
|
if (output6 !== void 0) {
|
|
117622
116978
|
if (fnLength !== 2)
|
|
117623
116979
|
throw new Error("cipher output not supported");
|
|
117624
|
-
|
|
116980
|
+
abytes4(output6);
|
|
117625
116981
|
}
|
|
117626
116982
|
};
|
|
117627
116983
|
let called = false;
|
|
@@ -117630,12 +116986,12 @@ var wrapCipher2 = /* @__NO_SIDE_EFFECTS__ */ (params, constructor) => {
|
|
|
117630
116986
|
if (called)
|
|
117631
116987
|
throw new Error("cannot encrypt() twice with same key + nonce");
|
|
117632
116988
|
called = true;
|
|
117633
|
-
|
|
116989
|
+
abytes4(data);
|
|
117634
116990
|
checkOutput(cipher.encrypt.length, output6);
|
|
117635
116991
|
return cipher.encrypt(data, output6);
|
|
117636
116992
|
},
|
|
117637
116993
|
decrypt(data, output6) {
|
|
117638
|
-
|
|
116994
|
+
abytes4(data);
|
|
117639
116995
|
if (tagl && data.length < tagl)
|
|
117640
116996
|
throw new Error("invalid ciphertext length: smaller than tagLength=" + tagl);
|
|
117641
116997
|
checkOutput(cipher.decrypt.length, output6);
|
|
@@ -117671,7 +117027,7 @@ function setBigUint647(view, byteOffset, value3, isLE7) {
|
|
|
117671
117027
|
function u64Lengths(dataLength, aadLength, isLE7) {
|
|
117672
117028
|
abool2(isLE7);
|
|
117673
117029
|
const num2 = new Uint8Array(16);
|
|
117674
|
-
const view =
|
|
117030
|
+
const view = createView8(num2);
|
|
117675
117031
|
setBigUint647(view, 0, BigInt(aadLength), isLE7);
|
|
117676
117032
|
setBigUint647(view, 8, BigInt(dataLength), isLE7);
|
|
117677
117033
|
return num2;
|
|
@@ -117738,13 +117094,13 @@ function createCipher2(core, opts) {
|
|
|
117738
117094
|
abool2(counterRight);
|
|
117739
117095
|
abool2(allowShortKeys);
|
|
117740
117096
|
return (key, nonce, data, output6, counter = 0) => {
|
|
117741
|
-
|
|
117742
|
-
|
|
117743
|
-
|
|
117097
|
+
abytes4(key);
|
|
117098
|
+
abytes4(nonce);
|
|
117099
|
+
abytes4(data);
|
|
117744
117100
|
const len = data.length;
|
|
117745
117101
|
if (output6 === void 0)
|
|
117746
117102
|
output6 = new Uint8Array(len);
|
|
117747
|
-
|
|
117103
|
+
abytes4(output6);
|
|
117748
117104
|
anumber3(counter);
|
|
117749
117105
|
if (counter < 0 || counter >= MAX_COUNTER2)
|
|
117750
117106
|
throw new Error("arx: counter overflow");
|
|
@@ -117786,7 +117142,7 @@ function createCipher2(core, opts) {
|
|
|
117786
117142
|
}
|
|
117787
117143
|
const n32 = u322(nonce);
|
|
117788
117144
|
runCipher2(core, sigma2, k32, n32, data, output6, counter, rounds);
|
|
117789
|
-
|
|
117145
|
+
clean2(...toClean);
|
|
117790
117146
|
return output6;
|
|
117791
117147
|
};
|
|
117792
117148
|
}
|
|
@@ -117805,7 +117161,7 @@ var Poly13052 = class {
|
|
|
117805
117161
|
this.pos = 0;
|
|
117806
117162
|
this.finished = false;
|
|
117807
117163
|
key = toBytes7(key);
|
|
117808
|
-
|
|
117164
|
+
abytes4(key, 32);
|
|
117809
117165
|
const t0 = u8to162(key, 0);
|
|
117810
117166
|
const t1 = u8to162(key, 2);
|
|
117811
117167
|
const t2 = u8to162(key, 4);
|
|
@@ -117981,12 +117337,12 @@ var Poly13052 = class {
|
|
|
117981
117337
|
f2 = (h2[i4] + pad2[i4] | 0) + (f2 >>> 16) | 0;
|
|
117982
117338
|
h2[i4] = f2 & 65535;
|
|
117983
117339
|
}
|
|
117984
|
-
|
|
117340
|
+
clean2(g);
|
|
117985
117341
|
}
|
|
117986
117342
|
update(data) {
|
|
117987
|
-
|
|
117343
|
+
aexists2(this);
|
|
117988
117344
|
data = toBytes7(data);
|
|
117989
|
-
|
|
117345
|
+
abytes4(data);
|
|
117990
117346
|
const { buffer: buffer2, blockLen } = this;
|
|
117991
117347
|
const len = data.length;
|
|
117992
117348
|
for (let pos = 0; pos < len; ) {
|
|
@@ -118007,11 +117363,11 @@ var Poly13052 = class {
|
|
|
118007
117363
|
return this;
|
|
118008
117364
|
}
|
|
118009
117365
|
destroy() {
|
|
118010
|
-
|
|
117366
|
+
clean2(this.h, this.r, this.buffer, this.pad);
|
|
118011
117367
|
}
|
|
118012
117368
|
digestInto(out) {
|
|
118013
|
-
|
|
118014
|
-
|
|
117369
|
+
aexists2(this);
|
|
117370
|
+
aoutput2(out, this);
|
|
118015
117371
|
this.finished = true;
|
|
118016
117372
|
const { buffer: buffer2, h: h2 } = this;
|
|
118017
117373
|
let { pos } = this;
|
|
@@ -118241,7 +117597,7 @@ function computeTag3(fn, key, nonce, data, AAD) {
|
|
|
118241
117597
|
const num2 = u64Lengths(data.length, AAD ? AAD.length : 0, true);
|
|
118242
117598
|
h2.update(num2);
|
|
118243
117599
|
const res = h2.digest();
|
|
118244
|
-
|
|
117600
|
+
clean2(authKey, num2);
|
|
118245
117601
|
return res;
|
|
118246
117602
|
}
|
|
118247
117603
|
var _poly1305_aead2 = (xorStream) => (key, nonce, AAD) => {
|
|
@@ -118255,7 +117611,7 @@ var _poly1305_aead2 = (xorStream) => (key, nonce, AAD) => {
|
|
|
118255
117611
|
xorStream(key, nonce, oPlain, oPlain, 1);
|
|
118256
117612
|
const tag = computeTag3(xorStream, key, nonce, oPlain, AAD);
|
|
118257
117613
|
output6.set(tag, plength);
|
|
118258
|
-
|
|
117614
|
+
clean2(tag);
|
|
118259
117615
|
return output6;
|
|
118260
117616
|
},
|
|
118261
117617
|
decrypt(ciphertext, output6) {
|
|
@@ -118267,7 +117623,7 @@ var _poly1305_aead2 = (xorStream) => (key, nonce, AAD) => {
|
|
|
118267
117623
|
throw new Error("invalid tag");
|
|
118268
117624
|
output6.set(ciphertext.subarray(0, -tagLength));
|
|
118269
117625
|
xorStream(key, nonce, output6, output6, 1);
|
|
118270
|
-
|
|
117626
|
+
clean2(tag);
|
|
118271
117627
|
return output6;
|
|
118272
117628
|
}
|
|
118273
117629
|
};
|
|
@@ -124990,7 +124346,7 @@ function removePrivateAddressesMapper(peer) {
|
|
|
124990
124346
|
};
|
|
124991
124347
|
}
|
|
124992
124348
|
async function convertBuffer(buf2, options2) {
|
|
124993
|
-
const multihash = await
|
|
124349
|
+
const multihash = await sha2568.digest(buf2);
|
|
124994
124350
|
options2?.signal?.throwIfAborted();
|
|
124995
124351
|
return multihash.digest;
|
|
124996
124352
|
}
|
|
@@ -144188,7 +143544,7 @@ var RoutingTableRefresh = class {
|
|
|
144188
143544
|
const keyPrefix2 = generated_prefix_list_browser_default[targetPrefix];
|
|
144189
143545
|
const keyBuffer = new ArrayBuffer(34);
|
|
144190
143546
|
const keyView = new DataView(keyBuffer, 0, keyBuffer.byteLength);
|
|
144191
|
-
keyView.setUint8(0,
|
|
143547
|
+
keyView.setUint8(0, sha2568.code);
|
|
144192
143548
|
keyView.setUint8(1, 32);
|
|
144193
143549
|
keyView.setUint32(2, keyPrefix2, false);
|
|
144194
143550
|
return new Uint8Array(keyView.buffer, keyView.byteOffset, keyView.byteLength);
|
|
@@ -151010,7 +150366,7 @@ var md2 = create6(id_md2);
|
|
|
151010
150366
|
var md4 = create6(id_md5);
|
|
151011
150367
|
var sha13 = create6(id_sha1);
|
|
151012
150368
|
var sha2243 = create6(id_sha224);
|
|
151013
|
-
var
|
|
150369
|
+
var sha2569 = create6(id_sha256);
|
|
151014
150370
|
var sha3842 = create6(id_sha384);
|
|
151015
150371
|
var sha5126 = create6(id_sha512);
|
|
151016
150372
|
var sha512_2242 = create6(id_sha512_224);
|
|
@@ -155129,7 +154485,7 @@ function ma2Fingerprint(ma) {
|
|
|
155129
154485
|
function fingerprint2Ma(fingerprint) {
|
|
155130
154486
|
const output6 = fingerprint.split(":").map((str) => parseInt(str, 16));
|
|
155131
154487
|
const encoded = Uint8Array.from(output6);
|
|
155132
|
-
const digest2 = create3(
|
|
154488
|
+
const digest2 = create3(sha2568.code, encoded);
|
|
155133
154489
|
return multiaddr(`/certhash/${base64url4.encode(digest2.bytes)}`);
|
|
155134
154490
|
}
|
|
155135
154491
|
function toSupportedHashFunction(code8) {
|
|
@@ -155208,7 +154564,7 @@ var PREFIX = fromString2("libp2p-webrtc-noise:");
|
|
|
155208
154564
|
function generateNoisePrologue(localFingerprint, remoteAddr, role) {
|
|
155209
154565
|
const localFpString = localFingerprint.trim().toLowerCase().replaceAll(":", "");
|
|
155210
154566
|
const localFpArray = fromString2(localFpString, "hex");
|
|
155211
|
-
const local = create3(
|
|
154567
|
+
const local = create3(sha2568.code, localFpArray);
|
|
155212
154568
|
const remote = multibaseDecoder.decode(certhash(remoteAddr));
|
|
155213
154569
|
const byteLength = PREFIX.byteLength + local.bytes.byteLength + remote.byteLength;
|
|
155214
154570
|
if (role === "server") {
|
|
@@ -155539,7 +154895,7 @@ var WebRTCDirectTransport = class {
|
|
|
155539
154895
|
}, renewTime);
|
|
155540
154896
|
return {
|
|
155541
154897
|
pem: cert.toString("pem"),
|
|
155542
|
-
certhash: base64url4.encode((await
|
|
154898
|
+
certhash: base64url4.encode((await sha2568.digest(new Uint8Array(cert.rawData))).bytes)
|
|
155543
154899
|
};
|
|
155544
154900
|
}
|
|
155545
154901
|
async loadCertificate(dsKey, keyPair) {
|
|
@@ -156301,13 +155657,12 @@ var Appendix = class _Appendix {
|
|
|
156301
155657
|
* ```
|
|
156302
155658
|
*/
|
|
156303
155659
|
static deriveRootCapability(identifier) {
|
|
156304
|
-
|
|
156305
|
-
|
|
156306
|
-
|
|
156307
|
-
|
|
156308
|
-
|
|
156309
|
-
|
|
156310
|
-
return rootCapability;
|
|
155660
|
+
return {
|
|
155661
|
+
"@context": "https://w3id.org/zcap/v1",
|
|
155662
|
+
id: `urn:zcap:root:${encodeURIComponent(identifier)}`,
|
|
155663
|
+
controller: identifier,
|
|
155664
|
+
invocationTarget: identifier
|
|
155665
|
+
};
|
|
156311
155666
|
}
|
|
156312
155667
|
/**
|
|
156313
155668
|
* Implements {@link https://dcdpr.github.io/did-btcr2/#dereference-root-capability-identifier | 9.4.2 Dereference Root Capability Identifier}.
|
|
@@ -156407,7 +155762,6 @@ var BeaconUtils = class {
|
|
|
156407
155762
|
if (!Appendix.isDidService(obj)) return false;
|
|
156408
155763
|
if (!["SingletonBeacon", "CASBeacon", "SMTBeacon"].includes(obj.type)) return false;
|
|
156409
155764
|
if ([obj.serviceEndpoint].flat().some((ep) => typeof ep === "string" && !ep.startsWith("bitcoin:"))) return false;
|
|
156410
|
-
if (obj.casType && typeof obj.casType !== "string") return false;
|
|
156411
155765
|
return true;
|
|
156412
155766
|
}
|
|
156413
155767
|
/**
|
|
@@ -156432,8 +155786,11 @@ var BeaconUtils = class {
|
|
|
156432
155786
|
(addrType) => this.createBeaconService(did, addrType, beaconType)
|
|
156433
155787
|
);
|
|
156434
155788
|
} catch (error) {
|
|
156435
|
-
|
|
156436
|
-
|
|
155789
|
+
throw new BeaconError(
|
|
155790
|
+
"Failed to create beacon services: " + error.message,
|
|
155791
|
+
"BEACON_SERVICE_ERROR",
|
|
155792
|
+
{ did, beaconType }
|
|
155793
|
+
);
|
|
156437
155794
|
}
|
|
156438
155795
|
}
|
|
156439
155796
|
/**
|
|
@@ -156453,8 +155810,11 @@ var BeaconUtils = class {
|
|
|
156453
155810
|
const serviceEndpoint = `bitcoin:${payments_exports[addressType]({ pubkey, network }).address}`;
|
|
156454
155811
|
return { id, type: beaconType, serviceEndpoint };
|
|
156455
155812
|
} catch (error) {
|
|
156456
|
-
|
|
156457
|
-
|
|
155813
|
+
throw new BeaconError(
|
|
155814
|
+
"Failed to create beacon service: " + error.message,
|
|
155815
|
+
"BEACON_SERVICE_ERROR",
|
|
155816
|
+
{ did, beaconType }
|
|
155817
|
+
);
|
|
156458
155818
|
}
|
|
156459
155819
|
}
|
|
156460
155820
|
/**
|
|
@@ -156489,8 +155849,11 @@ var BeaconUtils = class {
|
|
|
156489
155849
|
}
|
|
156490
155850
|
];
|
|
156491
155851
|
} catch (error) {
|
|
156492
|
-
|
|
156493
|
-
|
|
155852
|
+
throw new BeaconError(
|
|
155853
|
+
"Failed to create beacon services: " + error.message,
|
|
155854
|
+
"BEACON_SERVICE_ERROR",
|
|
155855
|
+
{ id, publicKey: publicKey2, network, beaconType }
|
|
155856
|
+
);
|
|
156494
155857
|
}
|
|
156495
155858
|
}
|
|
156496
155859
|
/**
|
|
@@ -156544,9 +155907,9 @@ var BIP340DataIntegrityProof = class {
|
|
|
156544
155907
|
}
|
|
156545
155908
|
/**
|
|
156546
155909
|
* Add a proof to a document.
|
|
156547
|
-
* @param {
|
|
155910
|
+
* @param {UnsignedBTCR2Update} unsignedDocument The document to add the proof to.
|
|
156548
155911
|
* @param {DataIntegrityConfig} config The configuration for generating the proof.
|
|
156549
|
-
* @returns {
|
|
155912
|
+
* @returns {SignedBTCR2Update} A document with a proof added.
|
|
156550
155913
|
*/
|
|
156551
155914
|
addProof(unsignedDocument, config) {
|
|
156552
155915
|
const proof = this.cryptosuite.createProof(unsignedDocument, config);
|
|
@@ -156661,7 +156024,7 @@ var BIP340Cryptosuite = class {
|
|
|
156661
156024
|
}
|
|
156662
156025
|
/**
|
|
156663
156026
|
* Verify a proof for a secure document.
|
|
156664
|
-
* @param {
|
|
156027
|
+
* @param {SignedBTCR2Update} secureDocument The secure document to verify.
|
|
156665
156028
|
* @returns {VerificationResult} The result of the verification.
|
|
156666
156029
|
*/
|
|
156667
156030
|
verifyProof(secureDocument) {
|
|
@@ -156676,7 +156039,7 @@ var BIP340Cryptosuite = class {
|
|
|
156676
156039
|
}
|
|
156677
156040
|
/**
|
|
156678
156041
|
* Transform a document into canonical form.
|
|
156679
|
-
* @param {
|
|
156042
|
+
* @param {UnsignedBTCR2Update | SignedBTCR2Update} document The document to transform.
|
|
156680
156043
|
* @param {DataIntegrityConfig} config The config to use when transforming the document.
|
|
156681
156044
|
* @returns {string} The canonicalized document.
|
|
156682
156045
|
* @throws {MethodError} if the document cannot be transformed.
|
|
@@ -156781,29 +156144,27 @@ var SchnorrMultikey = class _SchnorrMultikey {
|
|
|
156781
156144
|
* @param {MultikeyParams} params The parameters to create the multikey
|
|
156782
156145
|
* @param {string} params.id The id of the multikey (required)
|
|
156783
156146
|
* @param {string} params.controller The controller of the multikey (required)
|
|
156784
|
-
* @param {
|
|
156785
|
-
* @param {CompressedSecp256k1PublicKey} params.keys.publicKey The public key of the multikey (optional, required if no privateKey)
|
|
156786
|
-
* @param {Secp256k1SecretKey} params.keys.privateKey The private key of the multikey (optional)
|
|
156147
|
+
* @param {SchnorrKeyPair} params.keyPair The key pair of the multikey (optional, required if no publicKey)
|
|
156787
156148
|
* @throws {MultikeyError} if neither a publicKey nor a privateKey is provided
|
|
156788
156149
|
*/
|
|
156789
|
-
constructor({ id, controller,
|
|
156790
|
-
if (!
|
|
156791
|
-
throw new MultikeyError('Argument missing: "
|
|
156150
|
+
constructor({ id, controller, keyPair }) {
|
|
156151
|
+
if (!keyPair) {
|
|
156152
|
+
throw new MultikeyError('Argument missing: "keyPair" required', "CONSTRUCTOR_ERROR");
|
|
156792
156153
|
}
|
|
156793
|
-
if (!
|
|
156794
|
-
throw new MultikeyError('Argument missing: "
|
|
156154
|
+
if (!keyPair.publicKey) {
|
|
156155
|
+
throw new MultikeyError('Argument missing: "keyPair" must contain a "publicKey"', "CONSTRUCTOR_ERROR");
|
|
156795
156156
|
}
|
|
156796
156157
|
this.id = id;
|
|
156797
156158
|
this.controller = controller;
|
|
156798
|
-
this.#keyPair =
|
|
156159
|
+
this.#keyPair = keyPair;
|
|
156799
156160
|
}
|
|
156800
156161
|
/**
|
|
156801
156162
|
* @readonly
|
|
156802
156163
|
* Get the SchnorrKeyPair.
|
|
156803
156164
|
*/
|
|
156804
156165
|
get keyPair() {
|
|
156805
|
-
const
|
|
156806
|
-
return
|
|
156166
|
+
const keyPair = this.#keyPair;
|
|
156167
|
+
return keyPair;
|
|
156807
156168
|
}
|
|
156808
156169
|
/**
|
|
156809
156170
|
* @readonly
|
|
@@ -156910,9 +156271,10 @@ var SchnorrMultikey = class _SchnorrMultikey {
|
|
|
156910
156271
|
throw new MultikeyError('Invalid "type" in verificationMethod', VERIFICATION_METHOD_ERROR, { verificationMethod });
|
|
156911
156272
|
}
|
|
156912
156273
|
const decoded = this.publicKey.decode();
|
|
156913
|
-
const
|
|
156914
|
-
const
|
|
156915
|
-
|
|
156274
|
+
const pk = decoded.slice(2, decoded.length);
|
|
156275
|
+
const publicKey2 = new CompressedSecp256k1PublicKey(pk);
|
|
156276
|
+
const keyPair = new SchnorrKeyPair({ publicKey: publicKey2 });
|
|
156277
|
+
return new _SchnorrMultikey({ id, controller, keyPair });
|
|
156916
156278
|
}
|
|
156917
156279
|
/**
|
|
156918
156280
|
* @readonly
|
|
@@ -156946,22 +156308,21 @@ var SchnorrMultikey = class _SchnorrMultikey {
|
|
|
156946
156308
|
* @throws {MultikeyError} if neither a publicKey nor a privateKey is provided
|
|
156947
156309
|
* @returns {SchnorrMultikey} A new Multikey instance
|
|
156948
156310
|
*/
|
|
156949
|
-
static create({ id, controller,
|
|
156950
|
-
return new _SchnorrMultikey({ id, controller,
|
|
156311
|
+
static create({ id, controller, keyPair }) {
|
|
156312
|
+
return new _SchnorrMultikey({ id, controller, keyPair });
|
|
156951
156313
|
}
|
|
156952
156314
|
/**
|
|
156953
156315
|
* Creates a `Multikey` instance from a private key
|
|
156954
|
-
* @param {FromPublicKey} params The parameters to create the multikey
|
|
156955
156316
|
* @param {string} params.id The id of the multikey
|
|
156956
156317
|
* @param {string} params.controller The controller of the multikey
|
|
156957
156318
|
* @param {KeyBytes} params.entropy The private key bytes for the multikey
|
|
156958
156319
|
* @returns {SchnorrMultikey} The new multikey instance
|
|
156959
156320
|
*/
|
|
156960
|
-
static
|
|
156961
|
-
const secretKey = new Secp256k1SecretKey(
|
|
156321
|
+
static fromSecretKey(id, controller, secretKeyb) {
|
|
156322
|
+
const secretKey = new Secp256k1SecretKey(secretKeyb);
|
|
156962
156323
|
const publicKey2 = secretKey.computePublicKey();
|
|
156963
|
-
const
|
|
156964
|
-
return new _SchnorrMultikey({ id, controller,
|
|
156324
|
+
const keyPair = new SchnorrKeyPair({ publicKey: publicKey2, secretKey });
|
|
156325
|
+
return new _SchnorrMultikey({ id, controller, keyPair });
|
|
156965
156326
|
}
|
|
156966
156327
|
/**
|
|
156967
156328
|
* Creates a `Multikey` instance from a public key
|
|
@@ -156972,24 +156333,29 @@ var SchnorrMultikey = class _SchnorrMultikey {
|
|
|
156972
156333
|
* @returns {Multikey} The new multikey instance
|
|
156973
156334
|
*/
|
|
156974
156335
|
static fromPublicKey({ id, controller, publicKeyBytes }) {
|
|
156975
|
-
const
|
|
156976
|
-
|
|
156336
|
+
const publicKey2 = new CompressedSecp256k1PublicKey(publicKeyBytes);
|
|
156337
|
+
const keyPair = new SchnorrKeyPair({ publicKey: publicKey2 });
|
|
156338
|
+
return new _SchnorrMultikey({ id, controller, keyPair });
|
|
156977
156339
|
}
|
|
156978
156340
|
/**
|
|
156979
156341
|
* Creates a `Multikey` instance from a public key multibase.
|
|
156980
|
-
* @param {
|
|
156981
|
-
* @param {string}
|
|
156982
|
-
* @param {string}
|
|
156342
|
+
* @param {DidVerificationMethod} vm The verification method containing the public key multibase.
|
|
156343
|
+
* @param {string} vm.id The id of the multikey.
|
|
156344
|
+
* @param {string} vm.controller The controller of the multikey.
|
|
156345
|
+
* @param {string} vm.publicKeyMultibase The public key multibase of the multikey.
|
|
156983
156346
|
* @returns {Multikey} The new multikey instance.
|
|
156984
156347
|
*/
|
|
156985
|
-
static
|
|
156348
|
+
static fromVerificationMethod({ id, controller, publicKeyMultibase }) {
|
|
156349
|
+
if (!publicKeyMultibase) {
|
|
156350
|
+
throw new MultikeyError("Invalid publicKeyMultibase: cannot be undefined", VERIFICATION_METHOD_ERROR, { publicKeyMultibase });
|
|
156351
|
+
}
|
|
156986
156352
|
const publicKeyMultibaseBytes = base58btc.decode(publicKeyMultibase);
|
|
156987
156353
|
if (publicKeyMultibaseBytes.length !== 35) {
|
|
156988
156354
|
throw new MultikeyError(`Invalid publicKeyMultibase length: ${publicKeyMultibaseBytes.length}`, VERIFICATION_METHOD_ERROR, { publicKeyMultibase });
|
|
156989
156355
|
}
|
|
156990
156356
|
const publicKey2 = publicKeyMultibaseBytes.slice(2);
|
|
156991
|
-
const
|
|
156992
|
-
return new _SchnorrMultikey({ id, controller,
|
|
156357
|
+
const keyPair = new SchnorrKeyPair({ publicKey: publicKey2 });
|
|
156358
|
+
return new _SchnorrMultikey({ id, controller, keyPair });
|
|
156993
156359
|
}
|
|
156994
156360
|
};
|
|
156995
156361
|
|
|
@@ -157164,6 +156530,7 @@ var DidDocument2 = class _DidDocument {
|
|
|
157164
156530
|
* @returns {boolean} True if the id is valid.
|
|
157165
156531
|
*/
|
|
157166
156532
|
static isValidId(id) {
|
|
156533
|
+
if (typeof id !== "string") return false;
|
|
157167
156534
|
try {
|
|
157168
156535
|
Identifier.decode(id);
|
|
157169
156536
|
return true;
|
|
@@ -157213,18 +156580,14 @@ var DidDocument2 = class _DidDocument {
|
|
|
157213
156580
|
"capabilityInvocation",
|
|
157214
156581
|
"capabilityDelegation"
|
|
157215
156582
|
];
|
|
157216
|
-
const
|
|
157217
|
-
const
|
|
157218
|
-
|
|
157219
|
-
|
|
157220
|
-
|
|
157221
|
-
// Check if the key exists in the DID Document
|
|
157222
|
-
didDocument[key] && // Check if the key is an array
|
|
157223
|
-
Array.isArray(didDocument[key]) && // Check that every value in the array is a string or DidVerificationMethod
|
|
157224
|
-
didDocument[key].every(
|
|
156583
|
+
const keys = Object.keys(didDocument);
|
|
156584
|
+
const availableKeys = possibleVerificationRelationships.filter((key) => keys.includes(key));
|
|
156585
|
+
return availableKeys.every((key) => {
|
|
156586
|
+
const value3 = didDocument[key];
|
|
156587
|
+
return value3 && Array.isArray(value3) && value3.every(
|
|
157225
156588
|
(entry) => typeof entry === "string" || Appendix.isDidVerificationMethod(entry)
|
|
157226
|
-
)
|
|
157227
|
-
)
|
|
156589
|
+
);
|
|
156590
|
+
});
|
|
157228
156591
|
}
|
|
157229
156592
|
/**
|
|
157230
156593
|
* Validate the DID Document
|
|
@@ -157351,14 +156714,195 @@ var GenesisDocument = class _GenesisDocument extends DidDocument2 {
|
|
|
157351
156714
|
}
|
|
157352
156715
|
};
|
|
157353
156716
|
|
|
156717
|
+
// src/core/beacon/signal-discovery.ts
|
|
156718
|
+
init_shim();
|
|
156719
|
+
var BeaconSignalDiscovery = class {
|
|
156720
|
+
/**
|
|
156721
|
+
* Retrieves the beacon signals for the given array of BeaconService objects
|
|
156722
|
+
* using an esplora/electrs REST API connection via a bitcoin I/O driver.
|
|
156723
|
+
* @param {Array<BeaconService>} beaconServices Array of BeaconService objects to retrieve signals for
|
|
156724
|
+
* @param {BitcoinNetworkConnection} bitcoin Bitcoin network connection to use for REST calls
|
|
156725
|
+
* @returns {Promise<Map<BeaconService, Array<BeaconSignal>>>} Map of beacon service to its discovered signals
|
|
156726
|
+
*/
|
|
156727
|
+
static async indexer(beaconServices, bitcoin3) {
|
|
156728
|
+
const beaconServiceSignals = /* @__PURE__ */ new Map();
|
|
156729
|
+
const currentBlockCount = await bitcoin3.network.rest.block.count();
|
|
156730
|
+
for (const beaconService of beaconServices) {
|
|
156731
|
+
beaconServiceSignals.set(beaconService, []);
|
|
156732
|
+
const beaconSignals = await bitcoin3.network.rest.address.getTxs(
|
|
156733
|
+
beaconService.serviceEndpoint
|
|
156734
|
+
);
|
|
156735
|
+
if (!beaconSignals || !beaconSignals.length) {
|
|
156736
|
+
continue;
|
|
156737
|
+
}
|
|
156738
|
+
for (const beaconSignal of beaconSignals) {
|
|
156739
|
+
const signalVout = beaconSignal.vout.slice(-1)[0];
|
|
156740
|
+
if (!signalVout || !signalVout.scriptpubkey_asm.includes("OP_RETURN")) {
|
|
156741
|
+
continue;
|
|
156742
|
+
}
|
|
156743
|
+
const outputMap = new Map(Object.entries(signalVout));
|
|
156744
|
+
const signalVoutScriptPubkey = outputMap.get("scriptpubkey_asm");
|
|
156745
|
+
if (!signalVoutScriptPubkey) {
|
|
156746
|
+
continue;
|
|
156747
|
+
}
|
|
156748
|
+
const updateHash = signalVoutScriptPubkey.split(" ").slice(-1)[0];
|
|
156749
|
+
if (!updateHash) {
|
|
156750
|
+
continue;
|
|
156751
|
+
}
|
|
156752
|
+
const confirmations = currentBlockCount - beaconSignal.status.block_height + 1;
|
|
156753
|
+
beaconServiceSignals.get(beaconService)?.push({
|
|
156754
|
+
tx: beaconSignal,
|
|
156755
|
+
signalBytes: updateHash,
|
|
156756
|
+
blockMetadata: {
|
|
156757
|
+
confirmations,
|
|
156758
|
+
height: beaconSignal.status.block_height,
|
|
156759
|
+
time: beaconSignal.status.block_time
|
|
156760
|
+
}
|
|
156761
|
+
});
|
|
156762
|
+
}
|
|
156763
|
+
}
|
|
156764
|
+
return beaconServiceSignals;
|
|
156765
|
+
}
|
|
156766
|
+
/**
|
|
156767
|
+
* Traverse the full blockchain from genesis to chain top looking for beacon signals.
|
|
156768
|
+
* @param {Array<BeaconService>} beaconServices Array of BeaconService objects to search for signals.
|
|
156769
|
+
* @param {BitcoinNetworkConnection} bitcoin Bitcoin network connection to use for RPC calls.
|
|
156770
|
+
* @returns {Promise<Map<BeaconService, Array<BeaconSignal>>>} Map of beacon service to its discovered signals.
|
|
156771
|
+
*/
|
|
156772
|
+
static async fullnode(beaconServices, bitcoin3) {
|
|
156773
|
+
const beaconServiceSignals = /* @__PURE__ */ new Map();
|
|
156774
|
+
for (const beaconService of beaconServices) {
|
|
156775
|
+
beaconServiceSignals.set(beaconService, []);
|
|
156776
|
+
}
|
|
156777
|
+
const rpc = bitcoin3.network.rpc;
|
|
156778
|
+
if (!rpc) {
|
|
156779
|
+
throw new ResolveError("RPC connection is not available", "RPC_CONNECTION_ERROR", bitcoin3);
|
|
156780
|
+
}
|
|
156781
|
+
const targetHeight = await rpc.getBlockCount();
|
|
156782
|
+
const beaconServicesMap = BeaconUtils.getBeaconServicesMap(beaconServices);
|
|
156783
|
+
let height = 0;
|
|
156784
|
+
let block = await bitcoin3.network.rpc.getBlock({ height });
|
|
156785
|
+
console.info(`Searching for beacon signals, please wait ...`);
|
|
156786
|
+
while (block.height <= targetHeight) {
|
|
156787
|
+
for (const tx of block.tx) {
|
|
156788
|
+
if (tx.txid === GENESIS_TX_ID) {
|
|
156789
|
+
continue;
|
|
156790
|
+
}
|
|
156791
|
+
for (const vin of tx.vin) {
|
|
156792
|
+
if (vin.coinbase) {
|
|
156793
|
+
continue;
|
|
156794
|
+
}
|
|
156795
|
+
if (vin.txinwitness && vin.txinwitness.length === 1 && vin.txinwitness[0] === TXIN_WITNESS_COINBASE) {
|
|
156796
|
+
continue;
|
|
156797
|
+
}
|
|
156798
|
+
if (!vin.txid) {
|
|
156799
|
+
continue;
|
|
156800
|
+
}
|
|
156801
|
+
if (vin.vout === void 0) {
|
|
156802
|
+
continue;
|
|
156803
|
+
}
|
|
156804
|
+
const prevout = await rpc.getRawTransaction(vin.txid, 2);
|
|
156805
|
+
if (!prevout.vout[vin.vout]) {
|
|
156806
|
+
continue;
|
|
156807
|
+
}
|
|
156808
|
+
const scriptPubKey = prevout.vout[vin.vout].scriptPubKey;
|
|
156809
|
+
if (!scriptPubKey.address) {
|
|
156810
|
+
continue;
|
|
156811
|
+
}
|
|
156812
|
+
const beaconService = beaconServicesMap.get(scriptPubKey.address);
|
|
156813
|
+
if (!beaconService) {
|
|
156814
|
+
continue;
|
|
156815
|
+
}
|
|
156816
|
+
const txVoutScriptPubkeyAsm = prevout.vout[vin.vout].scriptPubKey.asm;
|
|
156817
|
+
if (!txVoutScriptPubkeyAsm.includes("OP_RETURN")) {
|
|
156818
|
+
continue;
|
|
156819
|
+
}
|
|
156820
|
+
console.info(`Tx ${tx.txid} contains beacon service address ${scriptPubKey.address} and OP_RETURN!`, tx);
|
|
156821
|
+
const updateHash = txVoutScriptPubkeyAsm.split(" ").slice(-1)[0];
|
|
156822
|
+
if (!updateHash) {
|
|
156823
|
+
continue;
|
|
156824
|
+
}
|
|
156825
|
+
beaconServiceSignals.get(beaconService)?.push({
|
|
156826
|
+
tx,
|
|
156827
|
+
signalBytes: updateHash,
|
|
156828
|
+
blockMetadata: {
|
|
156829
|
+
height: block.height,
|
|
156830
|
+
time: block.time,
|
|
156831
|
+
confirmations: block.confirmations
|
|
156832
|
+
}
|
|
156833
|
+
});
|
|
156834
|
+
}
|
|
156835
|
+
;
|
|
156836
|
+
}
|
|
156837
|
+
height += 1;
|
|
156838
|
+
if (height > targetHeight) {
|
|
156839
|
+
console.info(`Chain tip reached ${height}, breaking ...`);
|
|
156840
|
+
break;
|
|
156841
|
+
}
|
|
156842
|
+
block = await rpc.getBlock({ height });
|
|
156843
|
+
}
|
|
156844
|
+
return beaconServiceSignals;
|
|
156845
|
+
}
|
|
156846
|
+
};
|
|
156847
|
+
|
|
157354
156848
|
// src/core/resolve.ts
|
|
157355
156849
|
var Resolve = class {
|
|
156850
|
+
/**
|
|
156851
|
+
* 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}.
|
|
156852
|
+
* @param {DidComponents} didComponents The decoded components of the did.
|
|
156853
|
+
* @returns {DidDocument} The resolved DID Document object.
|
|
156854
|
+
*/
|
|
156855
|
+
static deterministic(didComponents) {
|
|
156856
|
+
const did = Identifier.encode(didComponents);
|
|
156857
|
+
const { genesisBytes } = didComponents;
|
|
156858
|
+
const { multibase: publicKeyMultibase } = new CompressedSecp256k1PublicKey(genesisBytes);
|
|
156859
|
+
const service = BeaconUtils.generateBeaconServices({
|
|
156860
|
+
id: did,
|
|
156861
|
+
publicKey: genesisBytes,
|
|
156862
|
+
network: getNetwork(didComponents.network),
|
|
156863
|
+
beaconType: "SingletonBeacon"
|
|
156864
|
+
});
|
|
156865
|
+
return new DidDocument2({
|
|
156866
|
+
id: did,
|
|
156867
|
+
controller: [did],
|
|
156868
|
+
verificationMethod: [{
|
|
156869
|
+
id: `${did}#initialKey`,
|
|
156870
|
+
type: "Multikey",
|
|
156871
|
+
controller: did,
|
|
156872
|
+
publicKeyMultibase: publicKeyMultibase.encoded
|
|
156873
|
+
}],
|
|
156874
|
+
service
|
|
156875
|
+
});
|
|
156876
|
+
}
|
|
156877
|
+
/**
|
|
156878
|
+
* 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}.
|
|
156879
|
+
* @param {DidComponents} didComponents BTCR2 DID components used to resolve the DID Document
|
|
156880
|
+
* @param {GenesisDocument} genesisDocument The genesis document for resolving the DID Document.
|
|
156881
|
+
* @returns {Promise<DidDocument>} The resolved DID Document object
|
|
156882
|
+
* @throws {ResolveError} InvalidDidDocument if not conformant to DID Core v1.1
|
|
156883
|
+
*/
|
|
156884
|
+
static async external(didComponents, genesisDocument) {
|
|
156885
|
+
const hashBytes = canonicalization2.process(genesisDocument, { encoding: "hex" });
|
|
156886
|
+
const genesisBytes = bytesToHex(didComponents.genesisBytes);
|
|
156887
|
+
if (genesisBytes !== hashBytes) {
|
|
156888
|
+
throw new ResolveError(
|
|
156889
|
+
`Initial document mismatch: genesisBytes ${genesisBytes} !== hashBytes ${hashBytes}`,
|
|
156890
|
+
INVALID_DID_DOCUMENT,
|
|
156891
|
+
{ genesisBytes, hashBytes }
|
|
156892
|
+
);
|
|
156893
|
+
}
|
|
156894
|
+
const did = Identifier.encode(didComponents);
|
|
156895
|
+
const currentDocument = JSON.parse(
|
|
156896
|
+
JSON.stringify(genesisDocument).replaceAll(ID_PLACEHOLDER_VALUE, did)
|
|
156897
|
+
);
|
|
156898
|
+
return new DidDocument2(currentDocument);
|
|
156899
|
+
}
|
|
157356
156900
|
/**
|
|
157357
156901
|
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-sidecar-data | Process Sidecar Data}
|
|
157358
156902
|
* @param {Sidecar} sidecar The sidecar data to process.
|
|
157359
|
-
* @returns {
|
|
156903
|
+
* @returns {ProcessedSidecar} The processed sidecar data containing maps of updates, CAS announcements, and SMT proofs.
|
|
157360
156904
|
*/
|
|
157361
|
-
static
|
|
156905
|
+
static sidecarData(sidecar = {}) {
|
|
157362
156906
|
const updateMap = /* @__PURE__ */ new Map();
|
|
157363
156907
|
if (sidecar.updates?.length)
|
|
157364
156908
|
for (const update of sidecar.updates) {
|
|
@@ -157383,9 +156927,9 @@ var Resolve = class {
|
|
|
157383
156927
|
* @param {DidComponents} didComponents The decoded components of the did.
|
|
157384
156928
|
* @param {GenesisDocument} genesisDocument The genesis document for resolving the DID Document.
|
|
157385
156929
|
* @returns {Promise<DidDocument>} The resolved DID Document object.
|
|
157386
|
-
* @throws {
|
|
156930
|
+
* @throws {ResolveError} if the DID hrp is invalid, no sidecarData passed and hrp = "x".
|
|
157387
156931
|
*/
|
|
157388
|
-
static async
|
|
156932
|
+
static async currentDocument(didComponents, genesisDocument) {
|
|
157389
156933
|
const { hrp, genesisBytes } = didComponents;
|
|
157390
156934
|
if (hrp === IdentifierHrp.x) {
|
|
157391
156935
|
if (!genesisDocument)
|
|
@@ -157408,84 +156952,33 @@ var Resolve = class {
|
|
|
157408
156952
|
}
|
|
157409
156953
|
throw new ResolveError(`Unsupported DID hrp ${hrp}`, INVALID_DID, { hrp });
|
|
157410
156954
|
}
|
|
157411
|
-
/**
|
|
157412
|
-
* 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}.
|
|
157413
|
-
* @param {DidComponents} didComponents The decoded components of the did.
|
|
157414
|
-
* @returns {DidDocument} The resolved DID Document object.
|
|
157415
|
-
*/
|
|
157416
|
-
static deterministic(didComponents) {
|
|
157417
|
-
const did = Identifier.encode(didComponents);
|
|
157418
|
-
const { genesisBytes } = didComponents;
|
|
157419
|
-
const { multibase: publicKeyMultibase } = new CompressedSecp256k1PublicKey(genesisBytes);
|
|
157420
|
-
const service = BeaconUtils.generateBeaconServices({
|
|
157421
|
-
id: did,
|
|
157422
|
-
publicKey: genesisBytes,
|
|
157423
|
-
network: getNetwork(didComponents.network),
|
|
157424
|
-
beaconType: "SingletonBeacon"
|
|
157425
|
-
});
|
|
157426
|
-
return new DidDocument2({
|
|
157427
|
-
id: did,
|
|
157428
|
-
controller: [did],
|
|
157429
|
-
verificationMethod: [{
|
|
157430
|
-
id: `${did}#initialKey`,
|
|
157431
|
-
type: "Multikey",
|
|
157432
|
-
controller: did,
|
|
157433
|
-
publicKeyMultibase: publicKeyMultibase.encoded
|
|
157434
|
-
}],
|
|
157435
|
-
service
|
|
157436
|
-
});
|
|
157437
|
-
}
|
|
157438
|
-
/**
|
|
157439
|
-
* 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}.
|
|
157440
|
-
* @param {DidComponents} didComponents BTCR2 DID components used to resolve the DID Document
|
|
157441
|
-
* @param {GenesisDocument} genesisDocument The genesis document for resolving the DID Document.
|
|
157442
|
-
* @returns {Promise<DidDocument>} The resolved DID Document object
|
|
157443
|
-
* @throws {MethodError} InvalidDidDocument if not conformant to DID Core v1.1
|
|
157444
|
-
*/
|
|
157445
|
-
static async external(didComponents, genesisDocument) {
|
|
157446
|
-
const hashBytes = canonicalization2.process(genesisDocument, { encoding: "hex" });
|
|
157447
|
-
const genesisBytes = bytesToHex(didComponents.genesisBytes);
|
|
157448
|
-
if (genesisBytes !== hashBytes) {
|
|
157449
|
-
throw new MethodError(
|
|
157450
|
-
`Initial document mismatch: genesisBytes ${genesisBytes} !== hashBytes ${hashBytes}`,
|
|
157451
|
-
INVALID_DID_DOCUMENT,
|
|
157452
|
-
{ genesisBytes, hashBytes }
|
|
157453
|
-
);
|
|
157454
|
-
}
|
|
157455
|
-
const did = Identifier.encode(didComponents);
|
|
157456
|
-
const currentDocument = JSON.parse(
|
|
157457
|
-
JSON.stringify(genesisDocument).replaceAll(ID_PLACEHOLDER_VALUE, did)
|
|
157458
|
-
);
|
|
157459
|
-
return new DidDocument2(currentDocument);
|
|
157460
|
-
}
|
|
157461
156955
|
/**
|
|
157462
156956
|
* Finds uses the beacon services in the currentDocument to scan for onchain Beacon Signals (transactions) containing
|
|
157463
156957
|
* Signal Bytes (last output in OP_RETURN transaction).
|
|
157464
156958
|
* @param {Array<BeaconService>} beaconServices The array of BeaconService objects to search for signals.
|
|
157465
156959
|
* @param {SidecarData} sidecarData The sidecar data containing maps of updates, CAS announcements, and SMT proofs.
|
|
157466
156960
|
* @param {BitcoinNetworkConnection} bitcoin The bitcoin network connection used to fetch beacon signals
|
|
157467
|
-
* @
|
|
157468
|
-
* @returns {Promise<Array<[BTCR2SignedUpdate, BlockMetadata]>>} The array of BTCR2 Signed Updates announced by the Beacon Signals.
|
|
156961
|
+
* @returns {Promise<Array<[SignedBTCR2Update, BlockMetadata]>>} The array of BTCR2 Signed Updates announced by the Beacon Signals.
|
|
157469
156962
|
*/
|
|
157470
|
-
static async
|
|
157471
|
-
const beaconServicesSignals =
|
|
157472
|
-
const
|
|
157473
|
-
|
|
157474
|
-
|
|
157475
|
-
|
|
157476
|
-
|
|
157477
|
-
|
|
157478
|
-
return
|
|
156963
|
+
static async beaconSignals(beaconServices, sidecarData, bitcoin3) {
|
|
156964
|
+
const beaconServicesSignals = bitcoin3.network.rest ? await BeaconSignalDiscovery.indexer(beaconServices, bitcoin3) : await BeaconSignalDiscovery.fullnode(beaconServices, bitcoin3);
|
|
156965
|
+
const promises = Array.from(beaconServicesSignals.entries()).map(
|
|
156966
|
+
async ([service, signals]) => {
|
|
156967
|
+
if (!signals.length) return [];
|
|
156968
|
+
return BeaconFactory.establish(service).processSignals(signals, sidecarData);
|
|
156969
|
+
}
|
|
156970
|
+
);
|
|
156971
|
+
return (await Promise.all(promises)).flat();
|
|
157479
156972
|
}
|
|
157480
156973
|
/**
|
|
157481
156974
|
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-updates | 7.2.f Process updates Array}.
|
|
157482
156975
|
* @param {DidDocument} currentDocument The current DID Document to apply the updates to.
|
|
157483
|
-
* @param {Array<[
|
|
156976
|
+
* @param {Array<[SignedBTCR2Update, BlockMetadata]>} unsortedUpdates The unsorted array of BTCR2 Signed Updates and their associated Block Metadata.
|
|
157484
156977
|
* @param {string} [versionTime] The optional version time to limit updates to.
|
|
157485
156978
|
* @param {string} [versionId] The optional version id to limit updates to.
|
|
157486
156979
|
* @returns {Promise<DidResolutionResponse>} The updated DID Document, number of confirmations, and version id.
|
|
157487
156980
|
*/
|
|
157488
|
-
static async
|
|
156981
|
+
static async updates(currentDocument, unsortedUpdates, versionTime, versionId) {
|
|
157489
156982
|
let currentVersionId = 1;
|
|
157490
156983
|
const updateHashHistory = [];
|
|
157491
156984
|
const updates = unsortedUpdates.sort(
|
|
@@ -157508,7 +157001,7 @@ var Resolve = class {
|
|
|
157508
157001
|
}
|
|
157509
157002
|
if (update.targetVersionId <= currentVersionId) {
|
|
157510
157003
|
updateHashHistory.push(currentDocumentHash);
|
|
157511
|
-
this.
|
|
157004
|
+
this.confirmDuplicate(update, updateHashHistory);
|
|
157512
157005
|
} else if (update.targetVersionId === currentVersionId + 1) {
|
|
157513
157006
|
const sourceHash = update.sourceHash.startsWith("z") ? update.sourceHash : `z${update.sourceHash}`;
|
|
157514
157007
|
if (sourceHash !== currentDocumentHash) {
|
|
@@ -157518,7 +157011,7 @@ var Resolve = class {
|
|
|
157518
157011
|
{ sourceHash, currentDocumentHash }
|
|
157519
157012
|
);
|
|
157520
157013
|
}
|
|
157521
|
-
response2.currentDocument = await this.
|
|
157014
|
+
response2.currentDocument = await this.applyUpdate(response2.currentDocument, update);
|
|
157522
157015
|
const unsignedUpdate = JSONUtils.deleteKeys(update, ["proof"]);
|
|
157523
157016
|
updateHashHistory.push(canonicalization2.process(unsignedUpdate, { encoding: "base58" }));
|
|
157524
157017
|
} else if (update.targetVersionId > currentVersionId + 1) {
|
|
@@ -157542,138 +157035,13 @@ var Resolve = class {
|
|
|
157542
157035
|
}
|
|
157543
157036
|
return response2;
|
|
157544
157037
|
}
|
|
157545
|
-
/**
|
|
157546
|
-
* Retrieves the beacon signals for the given array of BeaconService objects
|
|
157547
|
-
* using a esplora/electrs REST API connection via a bitcoin I/O driver.
|
|
157548
|
-
* @param {Array<BeaconService>} beaconServices Array of BeaconService objects to retrieve signals for
|
|
157549
|
-
* @param {BitcoinNetworkConnection} bitcoin Bitcoin network connection to use for REST calls
|
|
157550
|
-
* @returns {Promise<Array<BeaconSignal>>} Promise resolving to an array of BeaconSignal objects
|
|
157551
|
-
*/
|
|
157552
|
-
static async queryBlockchainIndexer(beaconServices, bitcoin3) {
|
|
157553
|
-
const beaconServiceSignals = /* @__PURE__ */ new Map();
|
|
157554
|
-
for (const beaconService of beaconServices) {
|
|
157555
|
-
beaconServiceSignals.set(beaconService, []);
|
|
157556
|
-
const beaconSignals = await bitcoin3.network.rest.address.getTxs(
|
|
157557
|
-
beaconService.serviceEndpoint
|
|
157558
|
-
);
|
|
157559
|
-
if (!beaconSignals || !beaconSignals.length) {
|
|
157560
|
-
continue;
|
|
157561
|
-
}
|
|
157562
|
-
for (const beaconSignal of beaconSignals) {
|
|
157563
|
-
const signalVout = beaconSignal.vout.slice(-1)[0];
|
|
157564
|
-
if (!signalVout || !signalVout.scriptpubkey_asm.includes("OP_RETURN")) {
|
|
157565
|
-
continue;
|
|
157566
|
-
}
|
|
157567
|
-
const outputMap = new Map(Object.entries(signalVout));
|
|
157568
|
-
const signalVoutScriptPubkey = outputMap.get("scriptpubkey_asm");
|
|
157569
|
-
if (!signalVoutScriptPubkey) {
|
|
157570
|
-
continue;
|
|
157571
|
-
}
|
|
157572
|
-
const updateHash = signalVoutScriptPubkey.split(" ").slice(-1)[0];
|
|
157573
|
-
if (!updateHash) {
|
|
157574
|
-
continue;
|
|
157575
|
-
}
|
|
157576
|
-
const confirmations = await bitcoin3.network.rest.block.count() - beaconSignal.status.block_height + 1;
|
|
157577
|
-
beaconServiceSignals.get(beaconService)?.push({
|
|
157578
|
-
tx: beaconSignal,
|
|
157579
|
-
signalBytes: updateHash,
|
|
157580
|
-
blockMetadata: {
|
|
157581
|
-
confirmations,
|
|
157582
|
-
height: beaconSignal.status.block_height,
|
|
157583
|
-
time: beaconSignal.status.block_time
|
|
157584
|
-
}
|
|
157585
|
-
});
|
|
157586
|
-
}
|
|
157587
|
-
}
|
|
157588
|
-
return beaconServiceSignals;
|
|
157589
|
-
}
|
|
157590
|
-
/**
|
|
157591
|
-
* Traverse the full blockchain from genesis to chain top looking for beacon signals.
|
|
157592
|
-
* @param {Array<BeaconService>} beaconServices Array of BeaconService objects to search for signals.
|
|
157593
|
-
* @param {BitcoinNetworkConnection} bitcoin Bitcoin network connection to use for RPC calls.
|
|
157594
|
-
* @returns {Promise<Array<BeaconSignal>>} Promise resolving to an array of BeaconSignal objects.
|
|
157595
|
-
*/
|
|
157596
|
-
static async traverseFullBlockchain(beaconServices, bitcoin3) {
|
|
157597
|
-
const beaconServiceSignals = /* @__PURE__ */ new Map();
|
|
157598
|
-
for (const beaconService of beaconServices) {
|
|
157599
|
-
beaconServiceSignals.set(beaconService, []);
|
|
157600
|
-
}
|
|
157601
|
-
const rpc = bitcoin3.network.rpc;
|
|
157602
|
-
if (!rpc) {
|
|
157603
|
-
throw new ResolveError("RPC connection is not available", "RPC_CONNECTION_ERROR", bitcoin3);
|
|
157604
|
-
}
|
|
157605
|
-
const targetHeight = await rpc.getBlockCount();
|
|
157606
|
-
let height = 0;
|
|
157607
|
-
let block = await bitcoin3.network.rpc.getBlock({ height });
|
|
157608
|
-
console.info(`Searching for beacon signals, please wait ...`);
|
|
157609
|
-
while (block.height <= targetHeight) {
|
|
157610
|
-
for (const tx of block.tx) {
|
|
157611
|
-
if (tx.txid === GENESIS_TX_ID) {
|
|
157612
|
-
continue;
|
|
157613
|
-
}
|
|
157614
|
-
for (const vin of tx.vin) {
|
|
157615
|
-
if (vin.coinbase) {
|
|
157616
|
-
continue;
|
|
157617
|
-
}
|
|
157618
|
-
if (vin.txinwitness && vin.txinwitness.length === 1 && vin.txinwitness[0] === TXIN_WITNESS_COINBASE) {
|
|
157619
|
-
continue;
|
|
157620
|
-
}
|
|
157621
|
-
if (!vin.txid) {
|
|
157622
|
-
continue;
|
|
157623
|
-
}
|
|
157624
|
-
if (vin.vout === void 0) {
|
|
157625
|
-
continue;
|
|
157626
|
-
}
|
|
157627
|
-
const prevout = await rpc.getRawTransaction(vin.txid, 2);
|
|
157628
|
-
if (!prevout.vout[vin.vout]) {
|
|
157629
|
-
continue;
|
|
157630
|
-
}
|
|
157631
|
-
const scriptPubKey = prevout.vout[vin.vout].scriptPubKey;
|
|
157632
|
-
if (!scriptPubKey.address) {
|
|
157633
|
-
continue;
|
|
157634
|
-
}
|
|
157635
|
-
const beaconService = BeaconUtils.getBeaconServicesMap(beaconServices).get(scriptPubKey.address);
|
|
157636
|
-
if (!beaconService) {
|
|
157637
|
-
continue;
|
|
157638
|
-
}
|
|
157639
|
-
const txVoutScriptPubkeyAsm = prevout.vout[vin.vout].scriptPubKey.asm;
|
|
157640
|
-
if (!txVoutScriptPubkeyAsm.includes("OP_RETURN")) {
|
|
157641
|
-
continue;
|
|
157642
|
-
}
|
|
157643
|
-
console.info(`Tx ${tx.txid} contains beacon service address ${scriptPubKey.address} and OP_RETURN!`, tx);
|
|
157644
|
-
const updateHash = txVoutScriptPubkeyAsm.split(" ").slice(-1)[0];
|
|
157645
|
-
if (!updateHash) {
|
|
157646
|
-
continue;
|
|
157647
|
-
}
|
|
157648
|
-
beaconServiceSignals.get(beaconService)?.push({
|
|
157649
|
-
tx,
|
|
157650
|
-
signalBytes: updateHash,
|
|
157651
|
-
blockMetadata: {
|
|
157652
|
-
height: block.height,
|
|
157653
|
-
time: block.time,
|
|
157654
|
-
confirmations: block.confirmations
|
|
157655
|
-
}
|
|
157656
|
-
});
|
|
157657
|
-
}
|
|
157658
|
-
;
|
|
157659
|
-
}
|
|
157660
|
-
height += 1;
|
|
157661
|
-
const tip = await rpc.getBlockCount();
|
|
157662
|
-
if (height > tip) {
|
|
157663
|
-
console.info(`Chain tip reached ${height}, breaking ...`);
|
|
157664
|
-
break;
|
|
157665
|
-
}
|
|
157666
|
-
block = await rpc.getBlock({ height });
|
|
157667
|
-
}
|
|
157668
|
-
return beaconServiceSignals;
|
|
157669
|
-
}
|
|
157670
157038
|
/**
|
|
157671
157039
|
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/#confirm-duplicate-update | 7.2.f.1 Confirm Duplicate Update}.
|
|
157672
157040
|
* This step confirms that an update with a lower-than-expected targetVersionId is a true duplicate.
|
|
157673
|
-
* @param {
|
|
157041
|
+
* @param {SignedBTCR2Update} update The BTCR2 Signed Update to confirm as a duplicate.
|
|
157674
157042
|
* @returns {void} Does not return a value, but throws an error if the update is not a valid duplicate.
|
|
157675
157043
|
*/
|
|
157676
|
-
static
|
|
157044
|
+
static confirmDuplicate(update, updateHashHistory) {
|
|
157677
157045
|
const unsignedUpdate = JSONUtils.deleteKeys(update, ["proof"]);
|
|
157678
157046
|
const unsignedUpdateHash = canonicalization2.process(unsignedUpdate);
|
|
157679
157047
|
const historicalUpdateHash = updateHashHistory[update.targetVersionId - 2];
|
|
@@ -157688,11 +157056,11 @@ var Resolve = class {
|
|
|
157688
157056
|
/**
|
|
157689
157057
|
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#apply-update | 7.2.f.3 Apply Update}.
|
|
157690
157058
|
* @param {DidDocument} currentDocument The current DID Document to apply the update to.
|
|
157691
|
-
* @param {
|
|
157059
|
+
* @param {SignedBTCR2Update} update The BTCR2 Signed Update to apply.
|
|
157692
157060
|
* @returns {Promise<DidDocument>} The updated DID Document after applying the update.
|
|
157693
157061
|
* @throws {ResolveError} If the update is invalid or cannot be applied.
|
|
157694
157062
|
*/
|
|
157695
|
-
static async
|
|
157063
|
+
static async applyUpdate(currentDocument, update) {
|
|
157696
157064
|
const capabilityId = update.proof?.capability;
|
|
157697
157065
|
if (!capabilityId) {
|
|
157698
157066
|
throw new ResolveError("No root capability found in update", INVALID_DID_UPDATE, update);
|
|
@@ -157711,18 +157079,13 @@ var Resolve = class {
|
|
|
157711
157079
|
throw new ResolveError("No verificationMethod found in update", INVALID_DID_UPDATE, update);
|
|
157712
157080
|
}
|
|
157713
157081
|
const vm = DidBtcr2.getSigningMethod(currentDocument, verificationMethodId);
|
|
157714
|
-
const
|
|
157715
|
-
const multikey = SchnorrMultikey.fromPublicKeyMultibase(
|
|
157716
|
-
`#${vmId}`,
|
|
157717
|
-
vmController,
|
|
157718
|
-
vm.publicKeyMultibase
|
|
157719
|
-
);
|
|
157082
|
+
const multikey = SchnorrMultikey.fromVerificationMethod(vm);
|
|
157720
157083
|
const cryptosuite = new BIP340Cryptosuite(multikey);
|
|
157721
157084
|
const canonicalUpdate = canonicalization2.canonicalize(update);
|
|
157722
157085
|
const diProof = new BIP340DataIntegrityProof(cryptosuite);
|
|
157723
157086
|
const verificationResult = diProof.verifyProof(canonicalUpdate, "capabilityInvocation");
|
|
157724
157087
|
if (!verificationResult.verified) {
|
|
157725
|
-
throw new
|
|
157088
|
+
throw new ResolveError(
|
|
157726
157089
|
"Invalid update: proof not verified",
|
|
157727
157090
|
INVALID_DID_UPDATE,
|
|
157728
157091
|
verificationResult
|
|
@@ -157733,7 +157096,7 @@ var Resolve = class {
|
|
|
157733
157096
|
const currentDocumentHash = canonicalization2.process(currentDocument, { encoding: "base58" });
|
|
157734
157097
|
const updateTargetHash = update.targetHash.startsWith("z") ? update.targetHash : `z${update.targetHash}`;
|
|
157735
157098
|
if (updateTargetHash !== currentDocumentHash) {
|
|
157736
|
-
throw new
|
|
157099
|
+
throw new ResolveError(
|
|
157737
157100
|
`Invalid update: updateTargetHash !== currentDocumentHash`,
|
|
157738
157101
|
INVALID_DID_UPDATE,
|
|
157739
157102
|
{ updateTargetHash, currentDocumentHash }
|
|
@@ -157747,103 +157110,55 @@ var Resolve = class {
|
|
|
157747
157110
|
init_shim();
|
|
157748
157111
|
var Update = class {
|
|
157749
157112
|
/**
|
|
157750
|
-
* Implements {@link https://dcdpr.github.io/did-btcr2
|
|
157751
|
-
*
|
|
157752
|
-
* The Construct DID Update Payload algorithm applies the documentPatch to the sourceDocument and verifies the
|
|
157753
|
-
* resulting targetDocument is a conformant DID document. It takes in a Identifier, sourceDocument,
|
|
157754
|
-
* sourceVersionId, and documentPatch objects. It returns an unsigned DID Update Payload.
|
|
157113
|
+
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/update.html#construct-btcr2-unsigned-update | 7.3.b Construct BTCR2 Unsigned Update}.
|
|
157114
|
+
* This process constructs a BTCR2 Unsigned Update conformant to the spec template.
|
|
157755
157115
|
*
|
|
157756
|
-
* @param {
|
|
157757
|
-
* @param {
|
|
157758
|
-
* @param {
|
|
157759
|
-
* @
|
|
157760
|
-
* @
|
|
157761
|
-
* @returns {Promise<BTCR2SignedUpdate>} The constructed BTCR2SignedUpdate object.
|
|
157762
|
-
* @throws {MethodError} InvalidDid if sourceDocument.id does not match identifier.
|
|
157116
|
+
* @param {Btcr2DidDocument} sourceDocument The source DID document to be updated.
|
|
157117
|
+
* @param {PatchOperation[]} patches The array of JSON Patch operations to apply to the sourceDocument.
|
|
157118
|
+
* @param {number} sourceVersionId The version ID of the source document.
|
|
157119
|
+
* @returns {Promise<SignedBTCR2Update>} The constructed SignedBTCR2Update object.
|
|
157120
|
+
* @throws {UpdateError} InvalidDid if sourceDocument.id does not match identifier.
|
|
157763
157121
|
*/
|
|
157764
|
-
static async construct({
|
|
157765
|
-
identifier,
|
|
157766
|
-
sourceDocument,
|
|
157767
|
-
sourceVersionId,
|
|
157768
|
-
patch
|
|
157769
|
-
}) {
|
|
157770
|
-
if (sourceDocument.id !== identifier) {
|
|
157771
|
-
throw new UpdateError(
|
|
157772
|
-
"Identifier mismatch: sourceDocument.id !== identifier",
|
|
157773
|
-
INVALID_DID_UPDATE,
|
|
157774
|
-
{ sourceDocument, identifier }
|
|
157775
|
-
);
|
|
157776
|
-
}
|
|
157122
|
+
static async construct(sourceDocument, patches, sourceVersionId) {
|
|
157777
157123
|
const unsignedUpdate = {
|
|
157778
|
-
// 3. Set BTCR2SignedUpdate.@context to the following list
|
|
157779
157124
|
"@context": [
|
|
157780
157125
|
"https://w3id.org/security/v2",
|
|
157781
157126
|
"https://w3id.org/zcap/v1",
|
|
157782
157127
|
"https://w3id.org/json-ld-patch/v1",
|
|
157783
157128
|
"https://btcr2.dev/context/v1"
|
|
157784
157129
|
],
|
|
157785
|
-
|
|
157786
|
-
patch,
|
|
157130
|
+
patch: patches,
|
|
157787
157131
|
targetHash: "",
|
|
157788
|
-
targetVersionId:
|
|
157789
|
-
sourceHash: ""
|
|
157790
|
-
};
|
|
157791
|
-
const targetDocument = JSONPatch.apply(sourceDocument,
|
|
157792
|
-
|
|
157793
|
-
|
|
157794
|
-
|
|
157795
|
-
|
|
157132
|
+
targetVersionId: sourceVersionId + 1,
|
|
157133
|
+
sourceHash: canonicalization2.process(sourceDocument, { encoding: "base58" })
|
|
157134
|
+
};
|
|
157135
|
+
const targetDocument = JSONPatch.apply(sourceDocument, patches);
|
|
157136
|
+
try {
|
|
157137
|
+
DidDocument2.isValid(targetDocument);
|
|
157138
|
+
} catch (error) {
|
|
157139
|
+
throw new UpdateError(
|
|
157140
|
+
"Error validating targetDocument: " + (error instanceof Error ? error.message : String(error)),
|
|
157141
|
+
INVALID_DID_UPDATE,
|
|
157142
|
+
targetDocument
|
|
157143
|
+
);
|
|
157144
|
+
}
|
|
157145
|
+
unsignedUpdate.targetHash = canonicalization2.process(targetDocument, { encoding: "base58" });
|
|
157796
157146
|
return unsignedUpdate;
|
|
157797
157147
|
}
|
|
157798
157148
|
/**
|
|
157799
|
-
* {@link
|
|
157800
|
-
*
|
|
157801
|
-
* The Invoke DID Update Payload algorithm takes in a Identifier, an unsigned BTCR2SignedUpdate, and a
|
|
157802
|
-
* verificationMethod. It retrieves the privateKeyBytes for the verificationMethod and adds a capability invocation in
|
|
157803
|
-
* the form of a Data Integrity proof following the Authorization Capabilities (ZCAP-LD) and VC Data Integrity
|
|
157804
|
-
* specifications. It returns the invoked DID Update Payload.
|
|
157149
|
+
* Implements subsection {@link http://dcdpr.github.io/did-btcr2/operations/update.html#construct-btcr2-signed-update | 7.3.c Construct BTCR2 Signed Update }.
|
|
157150
|
+
* This process constructs a BTCR2 Signed Update from a BTCR2 Unsigned Update.
|
|
157805
157151
|
*
|
|
157806
|
-
* @param {
|
|
157807
|
-
* @param {
|
|
157808
|
-
* @param {
|
|
157809
|
-
* @
|
|
157810
|
-
* @
|
|
157811
|
-
* @throws {MethodError} if the privateKeyBytes are invalid
|
|
157152
|
+
* @param {string} did The did-btcr2 identifier to derive the root capability from
|
|
157153
|
+
* @param {UnsignedBTCR2Update} unsignedUpdate The updatePayload object to be signed
|
|
157154
|
+
* @param {DidVerificationMethod} verificationMethod The verificationMethod object to be used for signing
|
|
157155
|
+
* @returns {SignedBTCR2Update} Did update payload secured with a proof => SignedBTCR2Update
|
|
157156
|
+
* @throws {UpdateError} if the privateKeyBytes are invalid
|
|
157812
157157
|
*/
|
|
157813
|
-
static async
|
|
157814
|
-
|
|
157815
|
-
|
|
157816
|
-
|
|
157817
|
-
}) {
|
|
157818
|
-
const { id: fullId, controller, publicKeyMultibase, secretKeyMultibase } = verificationMethod;
|
|
157819
|
-
if (!publicKeyMultibase) {
|
|
157820
|
-
throw new MethodError(
|
|
157821
|
-
"Invalid publicKeyMultibase: cannot be undefined",
|
|
157822
|
-
INVALID_PUBLIC_KEY_TYPE,
|
|
157823
|
-
verificationMethod
|
|
157824
|
-
);
|
|
157825
|
-
}
|
|
157826
|
-
const id = fullId.slice(fullId.indexOf("#"));
|
|
157827
|
-
const components = Identifier.decode(id);
|
|
157828
|
-
const keyUri = new CompressedSecp256k1PublicKey(components.genesisBytes).hex;
|
|
157829
|
-
const keys = secretKeyMultibase ? new SchnorrKeyPair({ secretKey: Secp256k1SecretKey.decode(secretKeyMultibase) }) : Kms.getKey(keyUri);
|
|
157830
|
-
if (!keys) {
|
|
157831
|
-
throw new MethodError(
|
|
157832
|
-
"No privateKey found in kms or vm",
|
|
157833
|
-
NOT_FOUND,
|
|
157834
|
-
verificationMethod
|
|
157835
|
-
);
|
|
157836
|
-
}
|
|
157837
|
-
const multikey = SchnorrMultikey.create({ id, controller, keys });
|
|
157838
|
-
if (!multikey) {
|
|
157839
|
-
throw new MethodError(
|
|
157840
|
-
"Failed to create multikey from verification method",
|
|
157841
|
-
"MULTKEY_CREATE_FAILED",
|
|
157842
|
-
verificationMethod
|
|
157843
|
-
);
|
|
157844
|
-
}
|
|
157845
|
-
const rootCapability = Appendix.deriveRootCapability(identifier);
|
|
157846
|
-
const cryptosuite = "bip340-jcs-2025";
|
|
157158
|
+
static async sign(did, unsignedUpdate, verificationMethod, secretKey) {
|
|
157159
|
+
const controller = verificationMethod.controller;
|
|
157160
|
+
const id = verificationMethod.id.slice(verificationMethod.id.indexOf("#"));
|
|
157161
|
+
const multikey = SchnorrMultikey.fromSecretKey(id, controller, secretKey);
|
|
157847
157162
|
const config = {
|
|
157848
157163
|
"@context": [
|
|
157849
157164
|
"https://w3id.org/security/v2",
|
|
@@ -157851,56 +157166,29 @@ var Update = class {
|
|
|
157851
157166
|
"https://w3id.org/json-ld-patch/v1",
|
|
157852
157167
|
"https://btcr2.dev/context/v1"
|
|
157853
157168
|
],
|
|
157854
|
-
cryptosuite,
|
|
157169
|
+
cryptosuite: "bip340-jcs-2025",
|
|
157855
157170
|
type: "DataIntegrityProof",
|
|
157856
|
-
verificationMethod:
|
|
157171
|
+
verificationMethod: verificationMethod.id,
|
|
157857
157172
|
proofPurpose: "capabilityInvocation",
|
|
157858
|
-
capability:
|
|
157173
|
+
capability: `urn:zcap:root:${encodeURIComponent(did)}`,
|
|
157859
157174
|
capabilityAction: "Write"
|
|
157860
157175
|
};
|
|
157861
157176
|
const diproof = multikey.toCryptosuite().toDataIntegrityProof();
|
|
157862
|
-
return
|
|
157177
|
+
return diproof.addProof(unsignedUpdate, config);
|
|
157863
157178
|
}
|
|
157864
157179
|
/**
|
|
157865
|
-
* Implements {@link https://dcdpr.github.io/did-btcr2
|
|
157866
|
-
*
|
|
157867
|
-
*
|
|
157868
|
-
*
|
|
157869
|
-
*
|
|
157870
|
-
* data to validate the Beacon Signal
|
|
157871
|
-
*
|
|
157872
|
-
* @param {AnnounceUpdatePayloadParams} params Required params for calling the announcePayload method
|
|
157873
|
-
* @param {DidDocument} params.sourceDocument The did-btcr2 did document to derive the root capability from
|
|
157874
|
-
* @param {string[]} params.beaconIds The BTCR2SignedUpdate object to be signed
|
|
157875
|
-
* @param {BTCR2SignedUpdate} params.BTCR2SignedUpdate The verificationMethod object to be used for signing
|
|
157876
|
-
* @returns {BTCR2SignedUpdate} The BTCR2SignedUpdate object containing data to validate the Beacon Signal
|
|
157877
|
-
* @throws {MethodError} if the beaconService type is invalid
|
|
157180
|
+
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/update.html#announce-did-update | 7.3.d Announce DID Update}.
|
|
157181
|
+
* BTCR2 Signed Updates are announced to the Bitcoin blockchain depending on the Beacon Type.
|
|
157182
|
+
* @param {BeaconService} beaconService The BeaconService object representing the funded beacon to announce the update to.
|
|
157183
|
+
* @param {SignedBTCR2Update} update The signed update object to be announced.
|
|
157184
|
+
* @param {KeyBytes} secretKey The private key used to sign the update for announcement.
|
|
157185
|
+
* @returns {SignedBTCR2Update} The SignedBTCR2Update object containing data to validate the Beacon Signal
|
|
157186
|
+
* @throws {UpdateError} if the beaconService type is invalid
|
|
157878
157187
|
*/
|
|
157879
|
-
static async announce({
|
|
157880
|
-
|
|
157881
|
-
|
|
157882
|
-
|
|
157883
|
-
}) {
|
|
157884
|
-
const beaconServices = [];
|
|
157885
|
-
let sidecarData;
|
|
157886
|
-
for (const beaconId of beaconIds) {
|
|
157887
|
-
const beaconService = sourceDocument.service.find((s2) => s2.id === beaconId);
|
|
157888
|
-
if (!beaconService) {
|
|
157889
|
-
throw new MethodError("Not found: sourceDocument does not contain beaconId", INVALID_DID_DOCUMENT, { beaconId });
|
|
157890
|
-
}
|
|
157891
|
-
beaconServices.push(beaconService);
|
|
157892
|
-
}
|
|
157893
|
-
for (const beaconService of beaconServices) {
|
|
157894
|
-
console.log("TODO: refactor this code", signedUpdate, beaconService);
|
|
157895
|
-
}
|
|
157896
|
-
if (!sidecarData) {
|
|
157897
|
-
throw new MethodError(
|
|
157898
|
-
"Invalid beacon: no sidecarData found",
|
|
157899
|
-
INVALID_DID_DOCUMENT,
|
|
157900
|
-
{ beaconServices }
|
|
157901
|
-
);
|
|
157902
|
-
}
|
|
157903
|
-
return sidecarData;
|
|
157188
|
+
static async announce(beaconService, update, secretKey, bitcoin3) {
|
|
157189
|
+
const beacon = BeaconFactory.establish(beaconService);
|
|
157190
|
+
const result = await beacon.broadcastSignal(update, secretKey, bitcoin3);
|
|
157191
|
+
return result;
|
|
157904
157192
|
}
|
|
157905
157193
|
};
|
|
157906
157194
|
|
|
@@ -157908,7 +157196,9 @@ var Update = class {
|
|
|
157908
157196
|
var canonicalization2 = new Canonicalization();
|
|
157909
157197
|
initEccLib(tinysecp3);
|
|
157910
157198
|
var DidBtcr2 = class {
|
|
157911
|
-
/**
|
|
157199
|
+
/**
|
|
157200
|
+
* Name of the DID method, as defined in the DID BTCR2 specification
|
|
157201
|
+
*/
|
|
157912
157202
|
static methodName = "btcr2";
|
|
157913
157203
|
/**
|
|
157914
157204
|
* Implements section {@link https://dcdpr.github.io/did-btcr2/operations/create.html | 7.1 Create}.
|
|
@@ -157933,7 +157223,7 @@ var DidBtcr2 = class {
|
|
|
157933
157223
|
return Identifier.encode({ idType, genesisBytes, version: version3, network });
|
|
157934
157224
|
}
|
|
157935
157225
|
/**
|
|
157936
|
-
* Entry point for section {@link https://dcdpr.github.io/did-btcr2
|
|
157226
|
+
* Entry point for section {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html | 7.2 Resolve}.
|
|
157937
157227
|
* See specification for the {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process | Resolve Process}.
|
|
157938
157228
|
* See {@link Resolve | Resolve (class)} for class implementation.
|
|
157939
157229
|
*
|
|
@@ -157942,14 +157232,10 @@ var DidBtcr2 = class {
|
|
|
157942
157232
|
* blockchain by Authorized Beacon Signals. The Initial DID Document is either
|
|
157943
157233
|
* deterministically created from the DID or provided by Sidecar Data.
|
|
157944
157234
|
*
|
|
157945
|
-
* @param {string} did
|
|
157946
|
-
* @param {ResolutionOptions} resolutionOptions
|
|
157947
|
-
* @param {number} resolutionOptions.versionId optional version of the identifier and/or DID document
|
|
157948
|
-
* @param {number} resolutionOptions.versionTime optional timestamp used during resolution as a bound for when to stop resolving
|
|
157949
|
-
* @param {DidDocument} resolutionOptions.sidecar optional data necessary for resolving a DID
|
|
157235
|
+
* @param {string} did The did:btcr2 identifier to be resolved.
|
|
157236
|
+
* @param {ResolutionOptions} resolutionOptions Options used during the resolution process.
|
|
157950
157237
|
* @returns {Promise<DidResolutionResult>} Promise resolving to a DID Resolution Result containing the `targetDocument`
|
|
157951
|
-
* @throws {
|
|
157952
|
-
* @throws {DidError} InvalidDid if the identifier is invalid
|
|
157238
|
+
* @throws {ResolveError} If the resolution process fails at any step.
|
|
157953
157239
|
* @example
|
|
157954
157240
|
* ```ts
|
|
157955
157241
|
* const resolution = await DidBtcr2.resolve(
|
|
@@ -157971,8 +157257,9 @@ var DidBtcr2 = class {
|
|
|
157971
157257
|
didDocument: null
|
|
157972
157258
|
};
|
|
157973
157259
|
const didComponents = Identifier.decode(did);
|
|
157974
|
-
const sidecarData = Resolve.
|
|
157975
|
-
if (!resolutionOptions
|
|
157260
|
+
const sidecarData = Resolve.sidecarData(resolutionOptions.sidecar);
|
|
157261
|
+
if (!resolutionOptions?.drivers?.bitcoin) {
|
|
157262
|
+
resolutionOptions.drivers = resolutionOptions.drivers || {};
|
|
157976
157263
|
resolutionOptions.drivers.bitcoin = new BitcoinNetworkConnection();
|
|
157977
157264
|
resolutionOptions.drivers.bitcoin.setActiveNetwork(didComponents.network);
|
|
157978
157265
|
}
|
|
@@ -157985,20 +157272,21 @@ var DidBtcr2 = class {
|
|
|
157985
157272
|
{ resolutionOptions }
|
|
157986
157273
|
);
|
|
157987
157274
|
}
|
|
157988
|
-
const currentDocument = await Resolve.
|
|
157275
|
+
const currentDocument = await Resolve.currentDocument(didComponents, genesisDocument);
|
|
157989
157276
|
const beaconServices = currentDocument.service.filter(BeaconUtils.isBeaconService).map(BeaconUtils.parseBeaconServiceEndpoint);
|
|
157990
|
-
|
|
157277
|
+
console.log("beaconServices", beaconServices);
|
|
157278
|
+
const unsortedUpdates = await Resolve.beaconSignals(
|
|
157991
157279
|
beaconServices,
|
|
157992
157280
|
sidecarData,
|
|
157993
|
-
resolutionOptions.drivers.bitcoin
|
|
157994
|
-
resolutionOptions.fullBlockchainTraversal
|
|
157281
|
+
resolutionOptions.drivers.bitcoin
|
|
157995
157282
|
);
|
|
157283
|
+
console.log("unsortedUpdates", unsortedUpdates);
|
|
157996
157284
|
if (!unsortedUpdates.length) {
|
|
157997
157285
|
didResolutionResult.didDocument = currentDocument;
|
|
157998
157286
|
didResolutionResult.didDocumentMetadata.deactivated = !!currentDocument.deactivated;
|
|
157999
157287
|
return didResolutionResult;
|
|
158000
157288
|
}
|
|
158001
|
-
const result = await Resolve.
|
|
157289
|
+
const result = await Resolve.updates(
|
|
158002
157290
|
currentDocument,
|
|
158003
157291
|
unsortedUpdates,
|
|
158004
157292
|
resolutionOptions.versionTime,
|
|
@@ -158022,68 +157310,90 @@ var DidBtcr2 = class {
|
|
|
158022
157310
|
}
|
|
158023
157311
|
}
|
|
158024
157312
|
/**
|
|
158025
|
-
* Entry point for section {@link https://dcdpr.github.io/did-btcr2/#
|
|
158026
|
-
* See {@link
|
|
158027
|
-
*
|
|
158028
|
-
*
|
|
158029
|
-
*
|
|
158030
|
-
*
|
|
158031
|
-
*
|
|
158032
|
-
*
|
|
158033
|
-
*
|
|
158034
|
-
*
|
|
158035
|
-
*
|
|
158036
|
-
*
|
|
158037
|
-
*
|
|
158038
|
-
*
|
|
158039
|
-
*
|
|
158040
|
-
*
|
|
158041
|
-
* @
|
|
158042
|
-
*
|
|
158043
|
-
|
|
158044
|
-
|
|
158045
|
-
|
|
158046
|
-
|
|
158047
|
-
|
|
158048
|
-
|
|
158049
|
-
|
|
158050
|
-
|
|
158051
|
-
|
|
158052
|
-
|
|
158053
|
-
|
|
158054
|
-
|
|
158055
|
-
|
|
158056
|
-
|
|
158057
|
-
|
|
158058
|
-
|
|
158059
|
-
}
|
|
158060
|
-
const
|
|
158061
|
-
|
|
158062
|
-
|
|
158063
|
-
|
|
158064
|
-
|
|
158065
|
-
|
|
158066
|
-
|
|
157313
|
+
* Entry point for section {@link https://dcdpr.github.io/did-btcr2/#read | 7.3 Update}.
|
|
157314
|
+
* See specification for the {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process | Resolve Process}.
|
|
157315
|
+
* See {@link Update | Update (class)} for class implementation.
|
|
157316
|
+
*
|
|
157317
|
+
* BTCR2 DID documents can be updated by anchoring BTCR2 Updates to Bitcoin transactions. These transactions MAY be
|
|
157318
|
+
* published to the Bitcoin network. Any property in the DID document may be updated except the id. Doing so would
|
|
157319
|
+
* invalidate the DID document.
|
|
157320
|
+
* @param params An object containing the parameters for the update operation.
|
|
157321
|
+
* @param {Btcr2DidDocument} params.sourceDocument The DID document being updated.
|
|
157322
|
+
* @param {PatchOperation[]} params.patches The array of JSON Patch operations to apply to the sourceDocument.
|
|
157323
|
+
* @param {string} params.sourceVersionId The version ID before applying the update.
|
|
157324
|
+
* @param {string} params.verificationMethodId The verificationMethod ID to sign the update with.
|
|
157325
|
+
* @param {string} params.beaconId The beacon ID associated with the update.
|
|
157326
|
+
* @param {KeyBytes | HexString} [params.signingMaterial] Optional signing material (key bytes or hex string).
|
|
157327
|
+
* @param {BitcoinNetworkConnection} [params.bitcoin] Optional Bitcoin network connection for announcing the update. If not provided, a default connection will be initialized.
|
|
157328
|
+
* @return {Promise<SignedBTCR2Update>} Promise resolving to the signed BTCR2 update.
|
|
157329
|
+
* @throws {UpdateError} if no verificationMethod, verificationMethod type is not `Multikey` or the publicKeyMultibase
|
|
157330
|
+
* header is not `zQ3s`
|
|
157331
|
+
*/
|
|
157332
|
+
static async update({
|
|
157333
|
+
sourceDocument,
|
|
157334
|
+
patches,
|
|
157335
|
+
sourceVersionId,
|
|
157336
|
+
verificationMethodId,
|
|
157337
|
+
beaconId,
|
|
157338
|
+
signingMaterial,
|
|
157339
|
+
bitcoin: bitcoin3
|
|
157340
|
+
}) {
|
|
157341
|
+
if (!signingMaterial) {
|
|
157342
|
+
throw new UpdateError(
|
|
157343
|
+
"Missing signing material for update",
|
|
157344
|
+
INVALID_DID_UPDATE,
|
|
157345
|
+
{ signingMaterial }
|
|
157346
|
+
);
|
|
157347
|
+
}
|
|
157348
|
+
const secretKey = typeof signingMaterial === "string" ? import_buffer.Buffer.from(signingMaterial, "hex") : signingMaterial;
|
|
157349
|
+
if (!sourceDocument.capabilityInvocation?.some((vr) => vr === verificationMethodId)) {
|
|
157350
|
+
throw new UpdateError(
|
|
157351
|
+
"Invalid verificationMethodId: not authorized for capabilityInvocation",
|
|
157352
|
+
INVALID_DID_DOCUMENT,
|
|
157353
|
+
sourceDocument
|
|
157354
|
+
);
|
|
157355
|
+
}
|
|
157356
|
+
const verificationMethod = this.getSigningMethod(sourceDocument, verificationMethodId);
|
|
158067
157357
|
if (!verificationMethod) {
|
|
158068
|
-
throw new
|
|
157358
|
+
throw new UpdateError(
|
|
157359
|
+
"Invalid verificationMethod: not found in source document",
|
|
157360
|
+
INVALID_DID_DOCUMENT,
|
|
157361
|
+
{ sourceDocument, verificationMethodId }
|
|
157362
|
+
);
|
|
158069
157363
|
}
|
|
158070
157364
|
if (verificationMethod.type !== "Multikey") {
|
|
158071
|
-
throw new
|
|
157365
|
+
throw new UpdateError(
|
|
157366
|
+
'Invalid verificationMethod: verificationMethod.type must be "Multikey"',
|
|
157367
|
+
INVALID_DID_DOCUMENT,
|
|
157368
|
+
verificationMethod
|
|
157369
|
+
);
|
|
158072
157370
|
}
|
|
158073
|
-
|
|
158074
|
-
|
|
158075
|
-
|
|
157371
|
+
if (verificationMethod.publicKeyMultibase?.slice(0, 4) !== "zQ3s") {
|
|
157372
|
+
throw new UpdateError(
|
|
157373
|
+
'Invalid verificationMethodId: publicKeyMultibase prefix must start with "zQ3s"',
|
|
157374
|
+
INVALID_DID_DOCUMENT,
|
|
157375
|
+
verificationMethod
|
|
157376
|
+
);
|
|
158076
157377
|
}
|
|
158077
|
-
const
|
|
158078
|
-
const
|
|
158079
|
-
|
|
157378
|
+
const update = await Update.construct(sourceDocument, patches, sourceVersionId);
|
|
157379
|
+
const signed = await Update.sign(sourceDocument.id, update, verificationMethod, secretKey);
|
|
157380
|
+
const beaconService = sourceDocument.service.filter((service) => service.id === beaconId).filter((service) => !!service).shift();
|
|
157381
|
+
if (!beaconService) {
|
|
157382
|
+
throw new UpdateError(
|
|
157383
|
+
"No beacon service found for provided beaconId",
|
|
157384
|
+
INVALID_DID_UPDATE,
|
|
157385
|
+
{ sourceDocument, beaconId }
|
|
157386
|
+
);
|
|
157387
|
+
}
|
|
157388
|
+
bitcoin3 ??= new BitcoinNetworkConnection();
|
|
157389
|
+
return signed;
|
|
158080
157390
|
}
|
|
158081
157391
|
/**
|
|
158082
157392
|
* Given the W3C DID Document of a `did:btcr2` identifier, return the signing verification method that will be used
|
|
158083
157393
|
* for signing messages and credentials. If given, the `methodId` parameter is used to select the
|
|
158084
157394
|
* verification method. If not given, the Identity Key's verification method with an ID fragment
|
|
158085
157395
|
* of '#initialKey' is used.
|
|
158086
|
-
* @param {
|
|
157396
|
+
* @param {Btcr2DidDocument} didDocument The DID Document of the `did:btcr2` identifier.
|
|
158087
157397
|
* @param {string} [methodId] Optional verification method ID to be used for signing.
|
|
158088
157398
|
* @returns {DidVerificationMethod} Promise resolving to the {@link DidVerificationMethod} object used for signing.
|
|
158089
157399
|
* @throws {DidError} if the parsed did method does not match `btcr2` or signing method could not be determined.
|
|
@@ -158108,43 +157418,25 @@ var DidBtcr2 = class {
|
|
|
158108
157418
|
};
|
|
158109
157419
|
|
|
158110
157420
|
// src/core/beacon/singleton.ts
|
|
158111
|
-
var SingletonBeacon = class
|
|
157421
|
+
var SingletonBeacon = class extends Beacon {
|
|
158112
157422
|
/**
|
|
158113
157423
|
* Creates an instance of SingletonBeacon.
|
|
158114
|
-
* @param {BeaconService} service The
|
|
158115
|
-
*
|
|
158116
|
-
*/
|
|
158117
|
-
constructor(service, signals, sidecar, bitcoin3) {
|
|
158118
|
-
super({ ...service, type: "SingletonBeacon" }, signals, sidecar, bitcoin3);
|
|
158119
|
-
}
|
|
158120
|
-
/**
|
|
158121
|
-
* Static, convenience method for establishing a CASBeacon object.
|
|
158122
|
-
* @param {string} service The Beacon service.
|
|
158123
|
-
* @param {SidecarData} sidecar The sidecar data.
|
|
158124
|
-
* @returns {SingletonBeacon} The Singleton Beacon.
|
|
158125
|
-
*/
|
|
158126
|
-
static establish(service, signals, sidecar) {
|
|
158127
|
-
return new _SingletonBeacon(service, signals, sidecar);
|
|
158128
|
-
}
|
|
158129
|
-
/**
|
|
158130
|
-
* Generates a Beacon Signal for a Singleton Beacon Service.
|
|
158131
|
-
* @param {HexString} updateHash The update hash to be included in the Beacon Signal.
|
|
158132
|
-
* @returns {BeaconSignal} The generated signal.
|
|
158133
|
-
* @throws {MethodError} if the signal is invalid.
|
|
157424
|
+
* @param {BeaconService} service The BeaconService object representing the funded beacon to announce the update to.
|
|
157425
|
+
*
|
|
158134
157426
|
*/
|
|
158135
|
-
|
|
158136
|
-
|
|
157427
|
+
constructor(service) {
|
|
157428
|
+
super({ ...service, type: "SingletonBeacon" });
|
|
158137
157429
|
}
|
|
158138
157430
|
/**
|
|
158139
157431
|
* Processes an array of Beacon Signals associated with a Singleton Beacon Service.
|
|
158140
|
-
* @returns {Promise<
|
|
157432
|
+
* @returns {Promise<SignedBTCR2Update | undefined>} The DID Update payload announced by the Beacon Signal.
|
|
158141
157433
|
* @throws {SingletonBeaconError} if the signalTx is invalid or the signalSidecarData is invalid.
|
|
158142
157434
|
*/
|
|
158143
|
-
async processSignals() {
|
|
157435
|
+
async processSignals(signals, sidecar) {
|
|
158144
157436
|
const updates = new Array();
|
|
158145
|
-
for (const signal of
|
|
157437
|
+
for (const signal of signals) {
|
|
158146
157438
|
const updateHash = signal.signalBytes;
|
|
158147
|
-
const signedUpdate =
|
|
157439
|
+
const signedUpdate = sidecar.updateMap.get(updateHash);
|
|
158148
157440
|
if (!signedUpdate) {
|
|
158149
157441
|
throw new SingletonBeaconError(
|
|
158150
157442
|
`BTCR2 Signed Update not found for update hash ${updateHash}.`,
|
|
@@ -158166,19 +157458,26 @@ var SingletonBeacon = class _SingletonBeacon extends AggregateBeacon {
|
|
|
158166
157458
|
return updates;
|
|
158167
157459
|
}
|
|
158168
157460
|
/**
|
|
158169
|
-
* Broadcasts a SingletonBeacon signal.
|
|
158170
|
-
*
|
|
158171
|
-
*
|
|
158172
|
-
* @
|
|
157461
|
+
* Broadcasts a SingletonBeacon signal to the Bitcoin network.
|
|
157462
|
+
* @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
|
|
157463
|
+
* @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
|
|
157464
|
+
* @param {BitcoinNetworkConnection} bitcoin The Bitcoin network connection.
|
|
157465
|
+
* @returns {Promise<SignedBTCR2Update>} The signed update that was broadcast.
|
|
158173
157466
|
* @throws {SingletonBeaconError} if the bitcoin address is invalid or unfunded.
|
|
158174
157467
|
*/
|
|
158175
|
-
async broadcastSignal(
|
|
157468
|
+
async broadcastSignal(signedUpdate, secretKey, bitcoin3) {
|
|
158176
157469
|
const bitcoinAddress = this.service.serviceEndpoint.replace("bitcoin:", "");
|
|
158177
|
-
const utxos = await
|
|
157470
|
+
const utxos = await bitcoin3.network.rest.address.getUtxos(bitcoinAddress);
|
|
158178
157471
|
if (!utxos.length) {
|
|
158179
|
-
throw new SingletonBeaconError(
|
|
157472
|
+
throw new SingletonBeaconError(
|
|
157473
|
+
"No UTXOs found, please fund address!",
|
|
157474
|
+
"UNFUNDED_BEACON_ADDRESS",
|
|
157475
|
+
{ bitcoinAddress }
|
|
157476
|
+
);
|
|
158180
157477
|
}
|
|
158181
|
-
const utxo = utxos.sort(
|
|
157478
|
+
const utxo = utxos.sort(
|
|
157479
|
+
(a3, b2) => b2.status.block_height - a3.status.block_height
|
|
157480
|
+
).shift();
|
|
158182
157481
|
if (!utxo) {
|
|
158183
157482
|
throw new SingletonBeaconError(
|
|
158184
157483
|
"Beacon bitcoin address unfunded or utxos unconfirmed.",
|
|
@@ -158186,83 +157485,55 @@ var SingletonBeacon = class _SingletonBeacon extends AggregateBeacon {
|
|
|
158186
157485
|
{ bitcoinAddress }
|
|
158187
157486
|
);
|
|
158188
157487
|
}
|
|
158189
|
-
const
|
|
158190
|
-
|
|
158191
|
-
|
|
158192
|
-
|
|
158193
|
-
|
|
158194
|
-
const prevTx = await this.bitcoin.network.rest.transaction.getHex(txid);
|
|
158195
|
-
const input = {
|
|
158196
|
-
hash: txid,
|
|
158197
|
-
index: vout,
|
|
157488
|
+
const prevTx = await bitcoin3.network.rest.transaction.getHex(utxo.txid);
|
|
157489
|
+
const updateHash = canonicalization2.canonicalhash(signedUpdate);
|
|
157490
|
+
const spendTx = new Psbt2({ network: bitcoin3.network.data }).addInput({
|
|
157491
|
+
hash: utxo.txid,
|
|
157492
|
+
index: utxo.vout,
|
|
158198
157493
|
nonWitnessUtxo: import_buffer.Buffer.from(prevTx, "hex")
|
|
158199
|
-
};
|
|
158200
|
-
const
|
|
158201
|
-
const components = Identifier.decode(this.service.id);
|
|
158202
|
-
const keyUri = new CompressedSecp256k1PublicKey(components.genesisBytes).hex;
|
|
158203
|
-
const keyPair = Kms.getKey(keyUri);
|
|
157494
|
+
}).addOutput({ address: bitcoinAddress, value: BigInt(utxo.value) - BigInt(500) }).addOutput({ script: script_exports.compile([OPS.OP_RETURN, updateHash]), value: 0n });
|
|
157495
|
+
const keyPair = SchnorrKeyPair.fromSecret(secretKey);
|
|
158204
157496
|
if (!keyPair) {
|
|
158205
|
-
throw new
|
|
157497
|
+
throw new SingletonBeaconError("Key pair not found.", "KEY_PAIR_NOT_FOUND", { secretKey });
|
|
158206
157498
|
}
|
|
158207
|
-
const signer = new Signer({ keyPair, network:
|
|
157499
|
+
const signer = new Signer({ keyPair, network: bitcoin3.network.name });
|
|
158208
157500
|
const signedTx = spendTx.signInput(0, signer).finalizeAllInputs().extractTransaction().toHex();
|
|
158209
|
-
|
|
158210
|
-
|
|
158211
|
-
|
|
158212
|
-
const spentTx = await this.bitcoin.network.rest.transaction.send(signedTx);
|
|
158213
|
-
if (!spentTx) {
|
|
158214
|
-
throw new SingletonBeaconError("Failed to send raw transaction.", "SEND_FAILED", { spentTx });
|
|
158215
|
-
}
|
|
158216
|
-
return spentTx;
|
|
157501
|
+
const txid = await bitcoin3.network.rest.transaction.send(signedTx);
|
|
157502
|
+
console.info(`Broadcasted Singleton Beacon signal with txid ${txid}`);
|
|
157503
|
+
return signedUpdate;
|
|
158217
157504
|
}
|
|
158218
157505
|
};
|
|
158219
157506
|
|
|
158220
157507
|
// src/core/beacon/smt-beacon.ts
|
|
158221
157508
|
init_shim();
|
|
158222
|
-
var SMTBeacon = class
|
|
157509
|
+
var SMTBeacon = class extends Beacon {
|
|
158223
157510
|
/**
|
|
158224
|
-
* Creates an instance of
|
|
157511
|
+
* Creates an instance of SMTBeacon.
|
|
158225
157512
|
* @param {BeaconService} service The Beacon service.
|
|
158226
|
-
* @param {Array<BeaconSignal>} signals The SingletonBeacon sidecar data.
|
|
158227
|
-
* @param {SidecarData} sidecar The sidecar data.
|
|
158228
157513
|
*/
|
|
158229
|
-
constructor(service
|
|
158230
|
-
super({ ...service, type: "SMTBeacon" }
|
|
157514
|
+
constructor(service) {
|
|
157515
|
+
super({ ...service, type: "SMTBeacon" });
|
|
158231
157516
|
}
|
|
158232
157517
|
/**
|
|
158233
|
-
*
|
|
158234
|
-
* @param {
|
|
158235
|
-
* @param {SidecarData} sidecar The sidecar data.
|
|
158236
|
-
* @returns {
|
|
157518
|
+
* Implements {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-smt-beacon | 7.2.e.1 Process SMT Beacon}.
|
|
157519
|
+
* @param {Array<BeaconSignal>} signals The array of Beacon Signals to process.
|
|
157520
|
+
* @param {SidecarData} sidecar The sidecar data associated with the SMT Beacon.
|
|
157521
|
+
* @returns {Promise<Array<[SignedBTCR2Update, BlockMetadata]>>} The processed signals.
|
|
157522
|
+
* @throws {SMTBeaconError} if processing fails.
|
|
158237
157523
|
*/
|
|
158238
|
-
|
|
158239
|
-
|
|
157524
|
+
processSignals(signals, sidecar) {
|
|
157525
|
+
throw new SMTBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signals, sidecar });
|
|
158240
157526
|
}
|
|
158241
157527
|
/**
|
|
158242
|
-
*
|
|
158243
|
-
* @param {
|
|
158244
|
-
* @
|
|
158245
|
-
* @
|
|
157528
|
+
* Broadcast CAS Beacon signal to the Bitcoin network.
|
|
157529
|
+
* @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
|
|
157530
|
+
* @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
|
|
157531
|
+
* @param {BitcoinNetworkConnection} bitcoin The Bitcoin network connection.
|
|
157532
|
+
* @return {Promise<SignedBTCR2Update>} The signed update that was broadcasted.
|
|
157533
|
+
* @throws {SMTBeaconError} if broadcasting fails.
|
|
158246
157534
|
*/
|
|
158247
|
-
|
|
158248
|
-
throw new
|
|
158249
|
-
}
|
|
158250
|
-
/**
|
|
158251
|
-
* Process SMTBeacon signals.
|
|
158252
|
-
* @returns {Promise<Array<BTCR2SignedUpdate>>} The processed signed update or undefined.
|
|
158253
|
-
* @throws {MethodError} if the signal processing fails.
|
|
158254
|
-
*/
|
|
158255
|
-
async processSignals() {
|
|
158256
|
-
throw new MethodError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`);
|
|
158257
|
-
}
|
|
158258
|
-
/**
|
|
158259
|
-
* Broadcast a SMTBeacon signal.
|
|
158260
|
-
* @param {HexString} updateHash The hash of the BTCR2 update to broadcast.
|
|
158261
|
-
* @returns {Promise<SignalsMetadata>} The result of the broadcast.
|
|
158262
|
-
* @throws {MethodError} if the broadcast fails.
|
|
158263
|
-
*/
|
|
158264
|
-
async broadcastSignal(updateHash) {
|
|
158265
|
-
throw new MethodError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { updateHash });
|
|
157535
|
+
async broadcastSignal(signedUpdate, secretKey, bitcoin3) {
|
|
157536
|
+
throw new SMTBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signedUpdate, secretKey, bitcoin: bitcoin3 });
|
|
158266
157537
|
}
|
|
158267
157538
|
};
|
|
158268
157539
|
|
|
@@ -158270,25 +157541,26 @@ var SMTBeacon = class _SMTBeacon extends AggregateBeacon {
|
|
|
158270
157541
|
var BeaconFactory = class {
|
|
158271
157542
|
/**
|
|
158272
157543
|
* Establish a Beacon instance based on the provided service and optional sidecar data.
|
|
158273
|
-
* @param {BeaconService} service
|
|
158274
|
-
* @param {Array<BeaconSignal>} signals - The array of beacon signals.
|
|
158275
|
-
* @param {SidecarData} sidecar - The sidecar data associated with the beacon.
|
|
157544
|
+
* @param {BeaconService} service The beacon service configuration.
|
|
158276
157545
|
* @returns {Beacon} The established Beacon instance.
|
|
158277
157546
|
*/
|
|
158278
|
-
static establish(service
|
|
157547
|
+
static establish(service) {
|
|
158279
157548
|
switch (service.type) {
|
|
158280
157549
|
case "SingletonBeacon":
|
|
158281
|
-
return new SingletonBeacon(service
|
|
157550
|
+
return new SingletonBeacon(service);
|
|
158282
157551
|
case "CASBeacon":
|
|
158283
|
-
return new CASBeacon(service
|
|
157552
|
+
return new CASBeacon(service);
|
|
158284
157553
|
case "SMTBeacon":
|
|
158285
|
-
return new SMTBeacon(service
|
|
157554
|
+
return new SMTBeacon(service);
|
|
158286
157555
|
default:
|
|
158287
157556
|
throw new MethodError("Invalid Beacon Type", "INVALID_BEACON_ERROR", service);
|
|
158288
157557
|
}
|
|
158289
157558
|
}
|
|
158290
157559
|
};
|
|
158291
157560
|
|
|
157561
|
+
// src/core/beacon/interfaces.ts
|
|
157562
|
+
init_shim();
|
|
157563
|
+
|
|
158292
157564
|
// src/core/interfaces.ts
|
|
158293
157565
|
init_shim();
|
|
158294
157566
|
|
|
@@ -160568,7 +159840,6 @@ var GeneralUtils = class {
|
|
|
160568
159840
|
}
|
|
160569
159841
|
};
|
|
160570
159842
|
export {
|
|
160571
|
-
AggregateBeacon,
|
|
160572
159843
|
AggregateBeaconCohort,
|
|
160573
159844
|
AggregateBeaconError,
|
|
160574
159845
|
AggregateBeaconMessage,
|
|
@@ -160585,6 +159856,7 @@ export {
|
|
|
160585
159856
|
BEACON_COHORT_SIGNATURE_AUTHORIZATION,
|
|
160586
159857
|
BECH32M_CHARS,
|
|
160587
159858
|
BaseMessage,
|
|
159859
|
+
Beacon,
|
|
160588
159860
|
BeaconCohortAdvertMessage,
|
|
160589
159861
|
BeaconCohortAggregatedNonceMessage,
|
|
160590
159862
|
BeaconCohortAuthorizationRequestMessage,
|
|
@@ -160602,9 +159874,10 @@ export {
|
|
|
160602
159874
|
BeaconFactory,
|
|
160603
159875
|
BeaconParticipant,
|
|
160604
159876
|
BeaconParticipantError,
|
|
159877
|
+
BeaconSignalDiscovery,
|
|
160605
159878
|
BeaconUtils,
|
|
160606
159879
|
CASBeacon,
|
|
160607
|
-
|
|
159880
|
+
CASBeaconError,
|
|
160608
159881
|
COHORT_STATUS,
|
|
160609
159882
|
CommunicationAdapterError,
|
|
160610
159883
|
CommunicationFactory,
|
|
@@ -160626,10 +159899,10 @@ export {
|
|
|
160626
159899
|
NostrAdapter,
|
|
160627
159900
|
Resolve,
|
|
160628
159901
|
SIGNING_SESSION_STATUS,
|
|
160629
|
-
SMTAggregateBeaconError,
|
|
160630
159902
|
SMTBeacon,
|
|
159903
|
+
SMTBeaconError,
|
|
160631
159904
|
SingletonBeacon,
|
|
160632
|
-
|
|
159905
|
+
SingletonBeaconError,
|
|
160633
159906
|
Update,
|
|
160634
159907
|
bigEndianToInt,
|
|
160635
159908
|
canonicalization2 as canonicalization,
|
|
@@ -160813,9 +160086,6 @@ fast-json-patch/module/duplex.mjs:
|
|
|
160813
160086
|
@scure/bip39/esm/index.js:
|
|
160814
160087
|
(*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
|
|
160815
160088
|
|
|
160816
|
-
@noble/hashes/utils.js:
|
|
160817
|
-
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
160818
|
-
|
|
160819
160089
|
@noble/hashes/esm/utils.js:
|
|
160820
160090
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
160821
160091
|
|