@did-btcr2/method 0.32.0 → 0.34.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/README.md +25 -13
- package/dist/.tsbuildinfo +1 -1
- package/dist/browser.js +332 -582
- package/dist/browser.mjs +332 -582
- package/dist/cjs/index.js +213 -35
- package/dist/esm/core/aggregation/beacon-strategy.js +5 -4
- package/dist/esm/core/aggregation/beacon-strategy.js.map +1 -1
- package/dist/esm/core/aggregation/runner/aggregation-runner.js +66 -0
- package/dist/esm/core/aggregation/runner/aggregation-runner.js.map +1 -0
- package/dist/esm/core/aggregation/runner/index.js +1 -0
- package/dist/esm/core/aggregation/runner/index.js.map +1 -1
- package/dist/esm/core/aggregation/transport/in-memory.js +146 -0
- package/dist/esm/core/aggregation/transport/in-memory.js.map +1 -0
- package/dist/esm/core/aggregation/transport/index.js +1 -0
- package/dist/esm/core/aggregation/transport/index.js.map +1 -1
- package/dist/esm/core/beacon/beacon.js +10 -8
- package/dist/esm/core/beacon/beacon.js.map +1 -1
- package/dist/esm/core/beacon/cas-beacon.js +4 -4
- package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
- package/dist/esm/core/beacon/factory.js +1 -1
- package/dist/esm/core/beacon/singleton-beacon.js +4 -4
- package/dist/esm/core/beacon/singleton-beacon.js.map +1 -1
- package/dist/esm/core/beacon/smt-beacon.js +23 -15
- package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
- package/dist/esm/core/resolver.js +7 -4
- package/dist/esm/core/resolver.js.map +1 -1
- package/dist/types/core/aggregation/beacon-strategy.d.ts.map +1 -1
- package/dist/types/core/aggregation/runner/aggregation-runner.d.ts +56 -0
- package/dist/types/core/aggregation/runner/aggregation-runner.d.ts.map +1 -0
- package/dist/types/core/aggregation/runner/index.d.ts +1 -0
- package/dist/types/core/aggregation/runner/index.d.ts.map +1 -1
- package/dist/types/core/aggregation/transport/in-memory.d.ts +64 -0
- package/dist/types/core/aggregation/transport/in-memory.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/index.d.ts +1 -0
- package/dist/types/core/aggregation/transport/index.d.ts.map +1 -1
- package/dist/types/core/beacon/beacon.d.ts +12 -10
- package/dist/types/core/beacon/beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/cas-beacon.d.ts +4 -4
- package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/factory.d.ts +3 -3
- package/dist/types/core/beacon/factory.d.ts.map +1 -1
- package/dist/types/core/beacon/singleton-beacon.d.ts +4 -4
- package/dist/types/core/beacon/singleton-beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/smt-beacon.d.ts +4 -4
- package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
- package/dist/types/core/interfaces.d.ts +14 -11
- package/dist/types/core/interfaces.d.ts.map +1 -1
- package/dist/types/core/resolver.d.ts +1 -1
- package/dist/types/core/resolver.d.ts.map +1 -1
- package/package.json +20 -8
- package/src/core/aggregation/beacon-strategy.ts +5 -4
- package/src/core/aggregation/runner/aggregation-runner.ts +96 -0
- package/src/core/aggregation/runner/index.ts +1 -0
- package/src/core/aggregation/transport/in-memory.ts +174 -0
- package/src/core/aggregation/transport/index.ts +1 -0
- package/src/core/beacon/beacon.ts +12 -10
- package/src/core/beacon/cas-beacon.ts +4 -4
- package/src/core/beacon/factory.ts +3 -3
- package/src/core/beacon/singleton-beacon.ts +4 -4
- package/src/core/beacon/smt-beacon.ts +24 -16
- package/src/core/interfaces.ts +14 -11
- package/src/core/resolver.ts +9 -6
package/dist/cjs/index.js
CHANGED
|
@@ -40,6 +40,7 @@ __export(index_exports, {
|
|
|
40
40
|
AggregationParticipant: () => AggregationParticipant,
|
|
41
41
|
AggregationParticipantError: () => AggregationParticipantError,
|
|
42
42
|
AggregationParticipantRunner: () => AggregationParticipantRunner,
|
|
43
|
+
AggregationRunner: () => AggregationRunner,
|
|
43
44
|
AggregationService: () => AggregationService,
|
|
44
45
|
AggregationServiceError: () => AggregationServiceError,
|
|
45
46
|
AggregationServiceRunner: () => AggregationServiceRunner,
|
|
@@ -47,7 +48,6 @@ __export(index_exports, {
|
|
|
47
48
|
BECH32M_CHARS: () => BECH32M_CHARS,
|
|
48
49
|
BTCR2_DID_DOCUMENT_CONTEXT: () => BTCR2_DID_DOCUMENT_CONTEXT,
|
|
49
50
|
BaseMessage: () => BaseMessage,
|
|
50
|
-
Beacon: () => Beacon,
|
|
51
51
|
BeaconError: () => BeaconError,
|
|
52
52
|
BeaconFactory: () => BeaconFactory,
|
|
53
53
|
BeaconSignalDiscovery: () => BeaconSignalDiscovery,
|
|
@@ -82,7 +82,9 @@ __export(index_exports, {
|
|
|
82
82
|
HttpTransportError: () => HttpTransportError,
|
|
83
83
|
ID_PLACEHOLDER_VALUE: () => ID_PLACEHOLDER_VALUE,
|
|
84
84
|
Identifier: () => Identifier,
|
|
85
|
+
InMemoryBus: () => InMemoryBus,
|
|
85
86
|
InMemoryRateLimitStore: () => InMemoryRateLimitStore,
|
|
87
|
+
InMemoryTransport: () => InMemoryTransport,
|
|
86
88
|
InboxBuffer: () => InboxBuffer,
|
|
87
89
|
NONCE_CONTRIBUTION: () => NONCE_CONTRIBUTION,
|
|
88
90
|
NonceCache: () => NonceCache,
|
|
@@ -104,6 +106,7 @@ __export(index_exports, {
|
|
|
104
106
|
ServiceCohortPhase: () => ServiceCohortPhase,
|
|
105
107
|
SigningSessionError: () => SigningSessionError,
|
|
106
108
|
SigningSessionPhase: () => SigningSessionPhase,
|
|
109
|
+
SinglePartyBeacon: () => SinglePartyBeacon,
|
|
107
110
|
SingletonBeacon: () => SingletonBeacon,
|
|
108
111
|
SingletonBeaconError: () => SingletonBeaconError,
|
|
109
112
|
StaticFeeEstimator: () => StaticFeeEstimator,
|
|
@@ -197,12 +200,12 @@ var SMT_STRATEGY = {
|
|
|
197
200
|
const smtProof = body.smtProof;
|
|
198
201
|
if (!smtProof?.updateId || !smtProof?.nonce) return { matches: false };
|
|
199
202
|
const canonicalBytes = new TextEncoder().encode((0, import_common.canonicalize)(submittedUpdate));
|
|
200
|
-
const expectedUpdateId = (0, import_smt.
|
|
203
|
+
const expectedUpdateId = (0, import_smt.hashToBase64Url)((0, import_smt.blockHash)(canonicalBytes));
|
|
201
204
|
if (smtProof.updateId !== expectedUpdateId) {
|
|
202
205
|
return { matches: false, smtProof };
|
|
203
206
|
}
|
|
204
207
|
const index = (0, import_smt.didToIndex)(participantDid);
|
|
205
|
-
const candidateHash = (0, import_smt.blockHash)((0, import_smt.blockHash)((0, import_smt.
|
|
208
|
+
const candidateHash = (0, import_smt.blockHash)((0, import_smt.blockHash)((0, import_smt.base64UrlToHash)(smtProof.nonce)), (0, import_smt.base64UrlToHash)(smtProof.updateId));
|
|
206
209
|
return {
|
|
207
210
|
matches: (0, import_smt.verifySerializedProof)(smtProof, index, candidateHash),
|
|
208
211
|
smtProof
|
|
@@ -3641,6 +3644,119 @@ var TransportFactory = class {
|
|
|
3641
3644
|
}
|
|
3642
3645
|
};
|
|
3643
3646
|
|
|
3647
|
+
// src/core/aggregation/transport/in-memory.ts
|
|
3648
|
+
var import_utils7 = require("@noble/hashes/utils");
|
|
3649
|
+
var InMemoryBus = class {
|
|
3650
|
+
#transports = /* @__PURE__ */ new Set();
|
|
3651
|
+
/** Attach a transport to this bus. Called by the transport's constructor. */
|
|
3652
|
+
register(transport) {
|
|
3653
|
+
this.#transports.add(transport);
|
|
3654
|
+
}
|
|
3655
|
+
/** Detach a transport from this bus. */
|
|
3656
|
+
unregister(transport) {
|
|
3657
|
+
this.#transports.delete(transport);
|
|
3658
|
+
}
|
|
3659
|
+
/**
|
|
3660
|
+
* Deliver a message. With no `recipient` the message is broadcast to every
|
|
3661
|
+
* actor on the bus; otherwise it is routed to the single transport that owns
|
|
3662
|
+
* the recipient DID.
|
|
3663
|
+
*/
|
|
3664
|
+
async deliver(message, _sender, recipient) {
|
|
3665
|
+
const type = message.type;
|
|
3666
|
+
if (!type) return;
|
|
3667
|
+
const replacer = (_k, v) => v instanceof Uint8Array ? { __bytes: (0, import_utils7.bytesToHex)(v) } : v;
|
|
3668
|
+
const reviver = (_k, v) => v && typeof v === "object" && "__bytes" in v ? (0, import_utils7.hexToBytes)(v.__bytes) : v;
|
|
3669
|
+
const raw = JSON.parse(JSON.stringify(message, replacer), reviver);
|
|
3670
|
+
const serialized = { ...raw, ...raw.body ?? {} };
|
|
3671
|
+
if (!recipient) {
|
|
3672
|
+
for (const t of this.#transports) {
|
|
3673
|
+
await t.dispatchBroadcast(type, serialized);
|
|
3674
|
+
}
|
|
3675
|
+
return;
|
|
3676
|
+
}
|
|
3677
|
+
for (const t of this.#transports) {
|
|
3678
|
+
if (t.hasActor(recipient)) {
|
|
3679
|
+
await t.dispatchDirected(recipient, type, serialized);
|
|
3680
|
+
return;
|
|
3681
|
+
}
|
|
3682
|
+
}
|
|
3683
|
+
}
|
|
3684
|
+
};
|
|
3685
|
+
var InMemoryTransport = class {
|
|
3686
|
+
name = "in-memory";
|
|
3687
|
+
bus;
|
|
3688
|
+
#actors = /* @__PURE__ */ new Map();
|
|
3689
|
+
#peers = /* @__PURE__ */ new Map();
|
|
3690
|
+
/** @param bus Shared bus. Pass the same bus to connect multiple transports. */
|
|
3691
|
+
constructor(bus = new InMemoryBus()) {
|
|
3692
|
+
this.bus = bus;
|
|
3693
|
+
this.bus.register(this);
|
|
3694
|
+
}
|
|
3695
|
+
start() {
|
|
3696
|
+
}
|
|
3697
|
+
registerActor(did, keys) {
|
|
3698
|
+
this.#actors.set(did, { keys, handlers: /* @__PURE__ */ new Map() });
|
|
3699
|
+
}
|
|
3700
|
+
getActorPk(did) {
|
|
3701
|
+
return this.#actors.get(did)?.keys.publicKey.compressed;
|
|
3702
|
+
}
|
|
3703
|
+
/** True if `did` is registered on this transport. Used by the bus for routing. */
|
|
3704
|
+
hasActor(did) {
|
|
3705
|
+
return this.#actors.has(did);
|
|
3706
|
+
}
|
|
3707
|
+
registerPeer(did, communicationPk) {
|
|
3708
|
+
this.#peers.set(did, communicationPk);
|
|
3709
|
+
}
|
|
3710
|
+
getPeerPk(did) {
|
|
3711
|
+
return this.#peers.get(did);
|
|
3712
|
+
}
|
|
3713
|
+
registerMessageHandler(actorDid, messageType, handler) {
|
|
3714
|
+
const actor = this.#actors.get(actorDid);
|
|
3715
|
+
if (actor) actor.handlers.set(messageType, handler);
|
|
3716
|
+
}
|
|
3717
|
+
unregisterMessageHandler(actorDid, messageType) {
|
|
3718
|
+
const actor = this.#actors.get(actorDid);
|
|
3719
|
+
if (actor) actor.handlers.delete(messageType);
|
|
3720
|
+
}
|
|
3721
|
+
unregisterActor(did) {
|
|
3722
|
+
const actor = this.#actors.get(did);
|
|
3723
|
+
if (!actor) return;
|
|
3724
|
+
actor.handlers.clear();
|
|
3725
|
+
this.#actors.delete(did);
|
|
3726
|
+
this.#peers.delete(did);
|
|
3727
|
+
}
|
|
3728
|
+
async sendMessage(message, sender, recipient) {
|
|
3729
|
+
await this.bus.deliver(message, sender, recipient);
|
|
3730
|
+
}
|
|
3731
|
+
publishRepeating(message, sender, intervalMs, recipient) {
|
|
3732
|
+
let stopped = false;
|
|
3733
|
+
void this.sendMessage(message, sender, recipient).catch(() => {
|
|
3734
|
+
});
|
|
3735
|
+
const timer = setInterval(() => {
|
|
3736
|
+
if (stopped) return;
|
|
3737
|
+
void this.sendMessage(message, sender, recipient).catch(() => {
|
|
3738
|
+
});
|
|
3739
|
+
}, intervalMs);
|
|
3740
|
+
return () => {
|
|
3741
|
+
if (stopped) return;
|
|
3742
|
+
stopped = true;
|
|
3743
|
+
clearInterval(timer);
|
|
3744
|
+
};
|
|
3745
|
+
}
|
|
3746
|
+
/** Deliver a broadcast message to every actor on this transport that handles `type`. */
|
|
3747
|
+
async dispatchBroadcast(type, message) {
|
|
3748
|
+
for (const actor of this.#actors.values()) {
|
|
3749
|
+
const handler = actor.handlers.get(type);
|
|
3750
|
+
if (handler) await handler(message);
|
|
3751
|
+
}
|
|
3752
|
+
}
|
|
3753
|
+
/** Deliver a directed message to the recipient actor's handler for `type`. */
|
|
3754
|
+
async dispatchDirected(recipientDid, type, message) {
|
|
3755
|
+
const handler = this.#actors.get(recipientDid)?.handlers.get(type);
|
|
3756
|
+
if (handler) await handler(message);
|
|
3757
|
+
}
|
|
3758
|
+
};
|
|
3759
|
+
|
|
3644
3760
|
// src/core/aggregation/transport/didcomm.ts
|
|
3645
3761
|
var import_common11 = require("@did-btcr2/common");
|
|
3646
3762
|
var DidCommTransport = class {
|
|
@@ -4368,8 +4484,64 @@ var AggregationParticipantRunner = class _AggregationParticipantRunner extends T
|
|
|
4368
4484
|
}
|
|
4369
4485
|
};
|
|
4370
4486
|
|
|
4487
|
+
// src/core/aggregation/runner/aggregation-runner.ts
|
|
4488
|
+
var AggregationRunner = class {
|
|
4489
|
+
/**
|
|
4490
|
+
* Run a cohort of ONE participant entirely in-process and return the
|
|
4491
|
+
* aggregated MuSig2 result.
|
|
4492
|
+
*
|
|
4493
|
+
* One party plays both the coordinating service and the lone participant,
|
|
4494
|
+
* connected over an {@link InMemoryTransport} (no relay or HTTP server). This
|
|
4495
|
+
* makes the single-participant aggregate-beacon path — the N=1 corner of the
|
|
4496
|
+
* two-axis beacon matrix (see ADR 037) — first-class, useful for generating
|
|
4497
|
+
* and reproducing single-participant aggregate test vectors.
|
|
4498
|
+
*
|
|
4499
|
+
* The service advertises a cohort with `minParticipants: 1`; the participant
|
|
4500
|
+
* joins, submits its update, and the two complete keygen, data distribution,
|
|
4501
|
+
* validation, and a one-signer MuSig2 P2TR key-path signing round.
|
|
4502
|
+
*
|
|
4503
|
+
* @param options Service + participant identities, cohort config, and the
|
|
4504
|
+
* update / tx-data callbacks.
|
|
4505
|
+
* @returns The {@link AggregationResult} (cohort id, aggregated signature, signed tx).
|
|
4506
|
+
*/
|
|
4507
|
+
static async solo(options) {
|
|
4508
|
+
const transport = new InMemoryTransport(new InMemoryBus());
|
|
4509
|
+
transport.registerActor(options.service.did, options.service.keys);
|
|
4510
|
+
transport.registerActor(options.participant.did, options.participant.keys);
|
|
4511
|
+
transport.registerPeer(options.participant.did, options.participant.keys.publicKey.compressed);
|
|
4512
|
+
transport.registerPeer(options.service.did, options.service.keys.publicKey.compressed);
|
|
4513
|
+
transport.start();
|
|
4514
|
+
const service = new AggregationServiceRunner({
|
|
4515
|
+
transport,
|
|
4516
|
+
did: options.service.did,
|
|
4517
|
+
keys: options.service.keys,
|
|
4518
|
+
config: { minParticipants: 1, network: options.config.network, beaconType: options.config.beaconType },
|
|
4519
|
+
onProvideTxData: options.onProvideTxData,
|
|
4520
|
+
cohortTtlMs: options.cohortTtlMs,
|
|
4521
|
+
phaseTimeoutMs: options.phaseTimeoutMs,
|
|
4522
|
+
// In-process bus with the participant already listening: a single advert
|
|
4523
|
+
// suffices, so disable the republish loop (no dangling interval).
|
|
4524
|
+
advertRepeatIntervalMs: 0
|
|
4525
|
+
});
|
|
4526
|
+
const participant = new AggregationParticipantRunner({
|
|
4527
|
+
transport,
|
|
4528
|
+
did: options.participant.did,
|
|
4529
|
+
keys: options.participant.keys,
|
|
4530
|
+
shouldJoin: async () => true,
|
|
4531
|
+
onProvideUpdate: options.onProvideUpdate
|
|
4532
|
+
});
|
|
4533
|
+
await participant.start();
|
|
4534
|
+
try {
|
|
4535
|
+
return await service.run();
|
|
4536
|
+
} finally {
|
|
4537
|
+
participant.stop();
|
|
4538
|
+
service.stop();
|
|
4539
|
+
}
|
|
4540
|
+
}
|
|
4541
|
+
};
|
|
4542
|
+
|
|
4371
4543
|
// src/core/beacon/beacon.ts
|
|
4372
|
-
var
|
|
4544
|
+
var import_utils8 = require("@noble/hashes/utils.js");
|
|
4373
4545
|
var import_btc_signer4 = require("@scure/btc-signer");
|
|
4374
4546
|
|
|
4375
4547
|
// src/core/beacon/error.ts
|
|
@@ -4467,7 +4639,7 @@ async function fetchSpendableUtxo(bitcoinAddress, bitcoin) {
|
|
|
4467
4639
|
);
|
|
4468
4640
|
}
|
|
4469
4641
|
const prevTxHex = await bitcoin.rest.transaction.getHex(utxo.txid);
|
|
4470
|
-
return { utxo, prevTxBytes: (0,
|
|
4642
|
+
return { utxo, prevTxBytes: (0, import_utils8.hexToBytes)(prevTxHex) };
|
|
4471
4643
|
}
|
|
4472
4644
|
async function buildAggregationBeaconTx(opts) {
|
|
4473
4645
|
const feeEstimator = opts.feeEstimator ?? DEFAULT_FEE_ESTIMATOR;
|
|
@@ -4508,7 +4680,7 @@ async function signSingletonInput(tx, inputIdx, kind, signer, prevOutScript, amo
|
|
|
4508
4680
|
const sighashType = import_btc_signer4.SigHash.ALL;
|
|
4509
4681
|
const sighash2 = tx.preimageLegacy(inputIdx, prevOutScript, sighashType);
|
|
4510
4682
|
const sig2 = signer.sign(sighash2, "ecdsa");
|
|
4511
|
-
const sigWithType = (0,
|
|
4683
|
+
const sigWithType = (0, import_utils8.concatBytes)(sig2, new Uint8Array([sighashType]));
|
|
4512
4684
|
tx.updateInput(inputIdx, { partialSig: [[pubkey, sigWithType]] }, true);
|
|
4513
4685
|
tx.finalize();
|
|
4514
4686
|
return tx.hex;
|
|
@@ -4526,7 +4698,7 @@ async function signSingletonInput(tx, inputIdx, kind, signer, prevOutScript, amo
|
|
|
4526
4698
|
const sighashType = import_btc_signer4.SigHash.ALL;
|
|
4527
4699
|
const sighash2 = tx.preimageWitnessV0(inputIdx, sighashScript, sighashType, amount);
|
|
4528
4700
|
const sig2 = signer.sign(sighash2, "ecdsa");
|
|
4529
|
-
const sigWithType = (0,
|
|
4701
|
+
const sigWithType = (0, import_utils8.concatBytes)(sig2, new Uint8Array([sighashType]));
|
|
4530
4702
|
tx.updateInput(inputIdx, { partialSig: [[pubkey, sigWithType]] }, true);
|
|
4531
4703
|
tx.finalize();
|
|
4532
4704
|
return tx.hex;
|
|
@@ -4537,7 +4709,7 @@ async function signSingletonInput(tx, inputIdx, kind, signer, prevOutScript, amo
|
|
|
4537
4709
|
tx.finalize();
|
|
4538
4710
|
return tx.hex;
|
|
4539
4711
|
}
|
|
4540
|
-
var
|
|
4712
|
+
var SinglePartyBeacon = class {
|
|
4541
4713
|
/**
|
|
4542
4714
|
* The Beacon service configuration parsed from the DID Document.
|
|
4543
4715
|
*/
|
|
@@ -4674,7 +4846,7 @@ var Beacon = class {
|
|
|
4674
4846
|
|
|
4675
4847
|
// src/core/beacon/cas-beacon.ts
|
|
4676
4848
|
var import_common13 = require("@did-btcr2/common");
|
|
4677
|
-
var CASBeacon = class extends
|
|
4849
|
+
var CASBeacon = class extends SinglePartyBeacon {
|
|
4678
4850
|
/**
|
|
4679
4851
|
* Creates an instance of CASBeacon.
|
|
4680
4852
|
* @param {BeaconService} service The service of the Beacon.
|
|
@@ -4734,7 +4906,7 @@ var CASBeacon = class extends Beacon {
|
|
|
4734
4906
|
* Creates a CAS Announcement mapping the DID to the update hash, broadcasts the hash of the
|
|
4735
4907
|
* announcement via OP_RETURN, and optionally publishes the announcement off-chain via the
|
|
4736
4908
|
* supplied `casPublish` callback. UTXO selection, PSBT construction, fee estimation, signing,
|
|
4737
|
-
* and broadcast are delegated to {@link
|
|
4909
|
+
* and broadcast are delegated to {@link SinglePartyBeacon.buildSignAndBroadcast}.
|
|
4738
4910
|
*
|
|
4739
4911
|
* @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
|
|
4740
4912
|
* @param {Signer} signer Signer that produces the ECDSA signature for the Bitcoin transaction.
|
|
@@ -4762,7 +4934,7 @@ var import_common16 = require("@did-btcr2/common");
|
|
|
4762
4934
|
|
|
4763
4935
|
// src/core/beacon/singleton-beacon.ts
|
|
4764
4936
|
var import_common14 = require("@did-btcr2/common");
|
|
4765
|
-
var SingletonBeacon = class extends
|
|
4937
|
+
var SingletonBeacon = class extends SinglePartyBeacon {
|
|
4766
4938
|
/**
|
|
4767
4939
|
* Creates an instance of SingletonBeacon.
|
|
4768
4940
|
* @param {BeaconService} service The BeaconService object representing the funded beacon to announce the update to.
|
|
@@ -4799,7 +4971,7 @@ var SingletonBeacon = class extends Beacon {
|
|
|
4799
4971
|
*
|
|
4800
4972
|
* The signal bytes embedded in OP_RETURN are the SHA-256 canonical hash of the signed update.
|
|
4801
4973
|
* UTXO selection, PSBT construction, fee estimation, signing, and broadcast are delegated to
|
|
4802
|
-
* {@link
|
|
4974
|
+
* {@link SinglePartyBeacon.buildSignAndBroadcast}.
|
|
4803
4975
|
*
|
|
4804
4976
|
* @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
|
|
4805
4977
|
* @param {Signer} signer Signer that produces the ECDSA signature for the Bitcoin transaction.
|
|
@@ -4818,8 +4990,8 @@ var SingletonBeacon = class extends Beacon {
|
|
|
4818
4990
|
// src/core/beacon/smt-beacon.ts
|
|
4819
4991
|
var import_common15 = require("@did-btcr2/common");
|
|
4820
4992
|
var import_smt3 = require("@did-btcr2/smt");
|
|
4821
|
-
var
|
|
4822
|
-
var SMTBeacon = class extends
|
|
4993
|
+
var import_utils9 = require("@noble/hashes/utils");
|
|
4994
|
+
var SMTBeacon = class extends SinglePartyBeacon {
|
|
4823
4995
|
/**
|
|
4824
4996
|
* Creates an instance of SMTBeacon.
|
|
4825
4997
|
* @param {BeaconService} service The Beacon service.
|
|
@@ -4854,9 +5026,6 @@ var SMTBeacon = class extends Beacon {
|
|
|
4854
5026
|
});
|
|
4855
5027
|
continue;
|
|
4856
5028
|
}
|
|
4857
|
-
if (!smtProof.updateId) {
|
|
4858
|
-
continue;
|
|
4859
|
-
}
|
|
4860
5029
|
if (!smtProof.nonce) {
|
|
4861
5030
|
throw new SMTBeaconError(
|
|
4862
5031
|
"SMT proof missing required nonce field.",
|
|
@@ -4865,7 +5034,8 @@ var SMTBeacon = class extends Beacon {
|
|
|
4865
5034
|
);
|
|
4866
5035
|
}
|
|
4867
5036
|
const index = (0, import_smt3.didToIndex)(did);
|
|
4868
|
-
const
|
|
5037
|
+
const nonceHash = (0, import_smt3.base64UrlToHash)(smtProof.nonce);
|
|
5038
|
+
const candidateHash = smtProof.updateId ? (0, import_smt3.blockHash)((0, import_smt3.blockHash)(nonceHash), (0, import_smt3.base64UrlToHash)(smtProof.updateId)) : (0, import_smt3.blockHash)((0, import_smt3.blockHash)(nonceHash));
|
|
4869
5039
|
const valid = (0, import_smt3.verifySerializedProof)(smtProof, index, candidateHash);
|
|
4870
5040
|
if (!valid) {
|
|
4871
5041
|
throw new SMTBeaconError(
|
|
@@ -4874,11 +5044,15 @@ var SMTBeacon = class extends Beacon {
|
|
|
4874
5044
|
{ smtProof, did }
|
|
4875
5045
|
);
|
|
4876
5046
|
}
|
|
4877
|
-
|
|
5047
|
+
if (!smtProof.updateId) {
|
|
5048
|
+
continue;
|
|
5049
|
+
}
|
|
5050
|
+
const updateHashHex = (0, import_smt3.hashToHex)((0, import_smt3.base64UrlToHash)(smtProof.updateId));
|
|
5051
|
+
const signedUpdate = sidecar.updateMap.get(updateHashHex);
|
|
4878
5052
|
if (!signedUpdate) {
|
|
4879
5053
|
needs.push({
|
|
4880
5054
|
kind: "NeedSignedUpdate",
|
|
4881
|
-
updateHash:
|
|
5055
|
+
updateHash: updateHashHex,
|
|
4882
5056
|
beaconServiceId: this.service.id
|
|
4883
5057
|
});
|
|
4884
5058
|
continue;
|
|
@@ -4893,7 +5067,7 @@ var SMTBeacon = class extends Beacon {
|
|
|
4893
5067
|
* Builds a single-entry Sparse Merkle Tree from the signed update, then broadcasts the tree's
|
|
4894
5068
|
* root hash via OP_RETURN. For multi-party aggregation, use the {@link AggregationService}
|
|
4895
5069
|
* subsystem directly instead of this method. UTXO selection, PSBT construction, fee estimation,
|
|
4896
|
-
* signing, and broadcast are delegated to {@link
|
|
5070
|
+
* signing, and broadcast are delegated to {@link SinglePartyBeacon.buildSignAndBroadcast}.
|
|
4897
5071
|
*
|
|
4898
5072
|
* @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
|
|
4899
5073
|
* @param {Signer} signer Signer that produces the ECDSA signature for the Bitcoin transaction.
|
|
@@ -4905,7 +5079,7 @@ var SMTBeacon = class extends Beacon {
|
|
|
4905
5079
|
async broadcastSignal(signedUpdate, signer, bitcoin, options) {
|
|
4906
5080
|
const did = this.service.id.split("#")[0];
|
|
4907
5081
|
const canonicalBytes = new TextEncoder().encode((0, import_common15.canonicalize)(signedUpdate));
|
|
4908
|
-
const nonce = (0,
|
|
5082
|
+
const nonce = (0, import_utils9.randomBytes)(32);
|
|
4909
5083
|
const tree = new import_smt3.BTCR2MerkleTree();
|
|
4910
5084
|
tree.addEntries([{ did, nonce, signedUpdate: canonicalBytes }]);
|
|
4911
5085
|
tree.finalize();
|
|
@@ -4919,7 +5093,7 @@ var BeaconFactory = class {
|
|
|
4919
5093
|
/**
|
|
4920
5094
|
* Establish a Beacon instance based on the provided service and optional sidecar data.
|
|
4921
5095
|
* @param {BeaconService} service The beacon service configuration.
|
|
4922
|
-
* @returns {
|
|
5096
|
+
* @returns {SinglePartyBeacon} The established Beacon instance.
|
|
4923
5097
|
*/
|
|
4924
5098
|
static establish(service) {
|
|
4925
5099
|
switch (service.type) {
|
|
@@ -6276,7 +6450,7 @@ var import_cryptosuite2 = require("@did-btcr2/cryptosuite");
|
|
|
6276
6450
|
var import_bitcoin3 = require("@did-btcr2/bitcoin");
|
|
6277
6451
|
var import_common19 = require("@did-btcr2/common");
|
|
6278
6452
|
var import_keypair5 = require("@did-btcr2/keypair");
|
|
6279
|
-
var
|
|
6453
|
+
var import_utils11 = require("@web5/dids/utils");
|
|
6280
6454
|
var import_btc_signer6 = require("@scure/btc-signer");
|
|
6281
6455
|
var BTCR2_DID_DOCUMENT_CONTEXT = [
|
|
6282
6456
|
"https://www.w3.org/ns/did/v1.1",
|
|
@@ -6486,7 +6660,7 @@ var DidDocument = class _DidDocument {
|
|
|
6486
6660
|
* @returns {boolean} True if the services are valid.
|
|
6487
6661
|
*/
|
|
6488
6662
|
static isValidServices(service) {
|
|
6489
|
-
return Array.isArray(service) && service.every(
|
|
6663
|
+
return Array.isArray(service) && service.every(import_utils11.isDidService);
|
|
6490
6664
|
}
|
|
6491
6665
|
/**
|
|
6492
6666
|
* Validates verification relationships (authentication, assertionMethod, capabilityInvocation, capabilityDelegation).
|
|
@@ -7066,7 +7240,7 @@ var DidBtcr2 = class {
|
|
|
7066
7240
|
};
|
|
7067
7241
|
|
|
7068
7242
|
// src/core/resolver.ts
|
|
7069
|
-
var
|
|
7243
|
+
var import_utils13 = require("@noble/curves/utils.js");
|
|
7070
7244
|
var Resolver = class _Resolver {
|
|
7071
7245
|
// --- Immutable inputs ---
|
|
7072
7246
|
#didComponents;
|
|
@@ -7133,7 +7307,7 @@ var Resolver = class _Resolver {
|
|
|
7133
7307
|
*/
|
|
7134
7308
|
static external(didComponents, genesisDocument) {
|
|
7135
7309
|
const genesisDocumentHash = (0, import_common22.canonicalHashBytes)(genesisDocument);
|
|
7136
|
-
if (!(0,
|
|
7310
|
+
if (!(0, import_utils13.equalBytes)(didComponents.genesisBytes, genesisDocumentHash)) {
|
|
7137
7311
|
throw new import_common22.ResolveError(
|
|
7138
7312
|
`Initial document mismatch: genesisBytes !== genesisDocumentHash`,
|
|
7139
7313
|
import_common22.INVALID_DID_DOCUMENT,
|
|
@@ -7168,7 +7342,7 @@ var Resolver = class _Resolver {
|
|
|
7168
7342
|
const smtMap = /* @__PURE__ */ new Map();
|
|
7169
7343
|
if (sidecar.smtProofs?.length)
|
|
7170
7344
|
for (const proof of sidecar.smtProofs) {
|
|
7171
|
-
smtMap.set(proof.id, proof);
|
|
7345
|
+
smtMap.set((0, import_common22.encode)((0, import_common22.decode)(proof.id, "base64urlnopad"), "hex"), proof);
|
|
7172
7346
|
}
|
|
7173
7347
|
return { updateMap, casMap, smtMap };
|
|
7174
7348
|
}
|
|
@@ -7210,7 +7384,7 @@ var Resolver = class _Resolver {
|
|
|
7210
7384
|
this.confirmDuplicate(update, updateHashHistory);
|
|
7211
7385
|
} else if (update.targetVersionId === currentVersionId + 1) {
|
|
7212
7386
|
const sourceHashBytes = (0, import_common22.decode)(update.sourceHash, "base64urlnopad");
|
|
7213
|
-
if (!(0,
|
|
7387
|
+
if (!(0, import_utils13.equalBytes)(sourceHashBytes, currentDocumentHash)) {
|
|
7214
7388
|
throw new import_common22.ResolveError(
|
|
7215
7389
|
`Hash mismatch: update.sourceHash !== currentDocumentHash`,
|
|
7216
7390
|
import_common22.INVALID_DID_UPDATE,
|
|
@@ -7257,7 +7431,7 @@ var Resolver = class _Resolver {
|
|
|
7257
7431
|
const { proof: _, ...unsignedUpdate } = update;
|
|
7258
7432
|
const unsignedUpdateHash = (0, import_common22.canonicalHashBytes)(unsignedUpdate);
|
|
7259
7433
|
const historicalUpdateHash = updateHashHistory[update.targetVersionId - 2];
|
|
7260
|
-
if (!(0,
|
|
7434
|
+
if (!(0, import_utils13.equalBytes)(historicalUpdateHash, unsignedUpdateHash)) {
|
|
7261
7435
|
throw new import_common22.ResolveError(
|
|
7262
7436
|
`Invalid duplicate: unsigned update hash does not match historical hash`,
|
|
7263
7437
|
import_common22.LATE_PUBLISHING_ERROR,
|
|
@@ -7310,7 +7484,7 @@ var Resolver = class _Resolver {
|
|
|
7310
7484
|
DidDocument.validate(updatedDocument);
|
|
7311
7485
|
const currentDocumentHash = (0, import_common22.canonicalHashBytes)(updatedDocument);
|
|
7312
7486
|
const updateTargetHash = (0, import_common22.decode)(update.targetHash);
|
|
7313
|
-
if (!(0,
|
|
7487
|
+
if (!(0, import_utils13.equalBytes)(updateTargetHash, currentDocumentHash)) {
|
|
7314
7488
|
throw new import_common22.ResolveError(
|
|
7315
7489
|
`Invalid update: update.targetHash !== currentDocumentHash`,
|
|
7316
7490
|
import_common22.INVALID_DID_UPDATE,
|
|
@@ -7456,11 +7630,12 @@ var Resolver = class _Resolver {
|
|
|
7456
7630
|
case "NeedSMTProof": {
|
|
7457
7631
|
const smtNeed = need;
|
|
7458
7632
|
const proof = data;
|
|
7459
|
-
|
|
7633
|
+
const proofIdHex = (0, import_common22.encode)((0, import_common22.decode)(proof.id, "base64urlnopad"), "hex");
|
|
7634
|
+
if (proofIdHex !== smtNeed.smtRootHash) {
|
|
7460
7635
|
throw new import_common22.ResolveError(
|
|
7461
|
-
`SMT proof root hash mismatch: expected ${smtNeed.smtRootHash}, got ${
|
|
7636
|
+
`SMT proof root hash mismatch: expected ${smtNeed.smtRootHash}, got ${proofIdHex}`,
|
|
7462
7637
|
import_common22.INVALID_DID_UPDATE,
|
|
7463
|
-
{ expected: smtNeed.smtRootHash, actual:
|
|
7638
|
+
{ expected: smtNeed.smtRootHash, actual: proofIdHex }
|
|
7464
7639
|
);
|
|
7465
7640
|
}
|
|
7466
7641
|
this.#sidecarData.smtMap.set(smtNeed.smtRootHash, proof);
|
|
@@ -7536,6 +7711,7 @@ var DidDocumentBuilder = class {
|
|
|
7536
7711
|
AggregationParticipant,
|
|
7537
7712
|
AggregationParticipantError,
|
|
7538
7713
|
AggregationParticipantRunner,
|
|
7714
|
+
AggregationRunner,
|
|
7539
7715
|
AggregationService,
|
|
7540
7716
|
AggregationServiceError,
|
|
7541
7717
|
AggregationServiceRunner,
|
|
@@ -7543,7 +7719,6 @@ var DidDocumentBuilder = class {
|
|
|
7543
7719
|
BECH32M_CHARS,
|
|
7544
7720
|
BTCR2_DID_DOCUMENT_CONTEXT,
|
|
7545
7721
|
BaseMessage,
|
|
7546
|
-
Beacon,
|
|
7547
7722
|
BeaconError,
|
|
7548
7723
|
BeaconFactory,
|
|
7549
7724
|
BeaconSignalDiscovery,
|
|
@@ -7578,7 +7753,9 @@ var DidDocumentBuilder = class {
|
|
|
7578
7753
|
HttpTransportError,
|
|
7579
7754
|
ID_PLACEHOLDER_VALUE,
|
|
7580
7755
|
Identifier,
|
|
7756
|
+
InMemoryBus,
|
|
7581
7757
|
InMemoryRateLimitStore,
|
|
7758
|
+
InMemoryTransport,
|
|
7582
7759
|
InboxBuffer,
|
|
7583
7760
|
NONCE_CONTRIBUTION,
|
|
7584
7761
|
NonceCache,
|
|
@@ -7600,6 +7777,7 @@ var DidDocumentBuilder = class {
|
|
|
7600
7777
|
ServiceCohortPhase,
|
|
7601
7778
|
SigningSessionError,
|
|
7602
7779
|
SigningSessionPhase,
|
|
7780
|
+
SinglePartyBeacon,
|
|
7603
7781
|
SingletonBeacon,
|
|
7604
7782
|
SingletonBeaconError,
|
|
7605
7783
|
StaticFeeEstimator,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { canonicalize } from '@did-btcr2/common';
|
|
2
|
-
import { blockHash, didToIndex,
|
|
2
|
+
import { base64UrlToHash, blockHash, didToIndex, hashToBase64Url, verifySerializedProof } from '@did-btcr2/smt';
|
|
3
3
|
const CAS_STRATEGY = {
|
|
4
4
|
type: 'CASBeacon',
|
|
5
5
|
buildAggregatedData(cohort) {
|
|
@@ -31,15 +31,16 @@ const SMT_STRATEGY = {
|
|
|
31
31
|
const smtProof = body.smtProof;
|
|
32
32
|
if (!smtProof?.updateId || !smtProof?.nonce)
|
|
33
33
|
return { matches: false };
|
|
34
|
-
// Verify updateId matches the canonicalized update hash
|
|
34
|
+
// Verify updateId matches the canonicalized update hash. Proof hash fields
|
|
35
|
+
// are base64url (no padding) per the SMT Proof spec.
|
|
35
36
|
const canonicalBytes = new TextEncoder().encode(canonicalize(submittedUpdate));
|
|
36
|
-
const expectedUpdateId =
|
|
37
|
+
const expectedUpdateId = hashToBase64Url(blockHash(canonicalBytes));
|
|
37
38
|
if (smtProof.updateId !== expectedUpdateId) {
|
|
38
39
|
return { matches: false, smtProof };
|
|
39
40
|
}
|
|
40
41
|
// Verify Merkle inclusion
|
|
41
42
|
const index = didToIndex(participantDid);
|
|
42
|
-
const candidateHash = blockHash(blockHash(
|
|
43
|
+
const candidateHash = blockHash(blockHash(base64UrlToHash(smtProof.nonce)), base64UrlToHash(smtProof.updateId));
|
|
43
44
|
return {
|
|
44
45
|
matches: verifySerializedProof(smtProof, index, candidateHash),
|
|
45
46
|
smtProof,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"beacon-strategy.js","sourceRoot":"","sources":["../../../../src/core/aggregation/beacon-strategy.ts"],"names":[],"mappings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,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { InMemoryBus, InMemoryTransport } from '../transport/in-memory.js';
|
|
2
|
+
import { AggregationParticipantRunner } from './participant-runner.js';
|
|
3
|
+
import { AggregationServiceRunner } from './service-runner.js';
|
|
4
|
+
/**
|
|
5
|
+
* High-level facades for driving an aggregation cohort to completion.
|
|
6
|
+
*
|
|
7
|
+
* @class AggregationRunner
|
|
8
|
+
*/
|
|
9
|
+
export class AggregationRunner {
|
|
10
|
+
/**
|
|
11
|
+
* Run a cohort of ONE participant entirely in-process and return the
|
|
12
|
+
* aggregated MuSig2 result.
|
|
13
|
+
*
|
|
14
|
+
* One party plays both the coordinating service and the lone participant,
|
|
15
|
+
* connected over an {@link InMemoryTransport} (no relay or HTTP server). This
|
|
16
|
+
* makes the single-participant aggregate-beacon path — the N=1 corner of the
|
|
17
|
+
* two-axis beacon matrix (see ADR 037) — first-class, useful for generating
|
|
18
|
+
* and reproducing single-participant aggregate test vectors.
|
|
19
|
+
*
|
|
20
|
+
* The service advertises a cohort with `minParticipants: 1`; the participant
|
|
21
|
+
* joins, submits its update, and the two complete keygen, data distribution,
|
|
22
|
+
* validation, and a one-signer MuSig2 P2TR key-path signing round.
|
|
23
|
+
*
|
|
24
|
+
* @param options Service + participant identities, cohort config, and the
|
|
25
|
+
* update / tx-data callbacks.
|
|
26
|
+
* @returns The {@link AggregationResult} (cohort id, aggregated signature, signed tx).
|
|
27
|
+
*/
|
|
28
|
+
static async solo(options) {
|
|
29
|
+
const transport = new InMemoryTransport(new InMemoryBus());
|
|
30
|
+
transport.registerActor(options.service.did, options.service.keys);
|
|
31
|
+
transport.registerActor(options.participant.did, options.participant.keys);
|
|
32
|
+
// Pre-register communication keys both ways. Production exchanges these via
|
|
33
|
+
// the protocol handshake; in-process we wire them directly.
|
|
34
|
+
transport.registerPeer(options.participant.did, options.participant.keys.publicKey.compressed);
|
|
35
|
+
transport.registerPeer(options.service.did, options.service.keys.publicKey.compressed);
|
|
36
|
+
transport.start();
|
|
37
|
+
const service = new AggregationServiceRunner({
|
|
38
|
+
transport,
|
|
39
|
+
did: options.service.did,
|
|
40
|
+
keys: options.service.keys,
|
|
41
|
+
config: { minParticipants: 1, network: options.config.network, beaconType: options.config.beaconType },
|
|
42
|
+
onProvideTxData: options.onProvideTxData,
|
|
43
|
+
cohortTtlMs: options.cohortTtlMs,
|
|
44
|
+
phaseTimeoutMs: options.phaseTimeoutMs,
|
|
45
|
+
// In-process bus with the participant already listening: a single advert
|
|
46
|
+
// suffices, so disable the republish loop (no dangling interval).
|
|
47
|
+
advertRepeatIntervalMs: 0,
|
|
48
|
+
});
|
|
49
|
+
const participant = new AggregationParticipantRunner({
|
|
50
|
+
transport,
|
|
51
|
+
did: options.participant.did,
|
|
52
|
+
keys: options.participant.keys,
|
|
53
|
+
shouldJoin: async () => true,
|
|
54
|
+
onProvideUpdate: options.onProvideUpdate,
|
|
55
|
+
});
|
|
56
|
+
await participant.start();
|
|
57
|
+
try {
|
|
58
|
+
return await service.run();
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
participant.stop();
|
|
62
|
+
service.stop();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=aggregation-runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aggregation-runner.js","sourceRoot":"","sources":["../../../../../src/core/aggregation/runner/aggregation-runner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC3E,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AAEvE,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AA2B/D;;;;GAIG;AACH,MAAM,OAAO,iBAAiB;IAC5B;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,KAAK,CAAC,IAA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AG;YACzC,IAAI,EAAc,OAAO,CAAC,WAAW,CAAC,IAAI;YAC1C,UAAU,EAAQ,KAAK,IAAI,EAAE,CAAC,IAAI;YAClC,eAAe,EAAG,OAAO,CAAC,eAAe;SAC1C,CAAC,CAAC;QAEH,MAAM,WAAW,CAAC,KAAK,EAAE,CAAC;QAC1B,IAAI,CAAC;YACH,OAAO,MAAM,OAAO,CAAC,GAAG,EAAE,CAAC;QAC7B,CAAC;gBAAS,CAAC;YACT,WAAW,CAAC,IAAI,EAAE,CAAC;YACnB,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/aggregation/runner/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/aggregation/runner/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC"}
|