@did-btcr2/method 0.33.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/dist/.tsbuildinfo +1 -1
- package/dist/browser.js +183 -9
- package/dist/browser.mjs +183 -9
- package/dist/cjs/index.js +198 -23
- 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 +4 -4
- package/dist/esm/core/beacon/smt-beacon.js.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/resolver.d.ts +1 -1
- package/package.json +4 -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 +4 -4
- package/src/core/resolver.ts +1 -1
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,
|
|
@@ -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.
|
|
@@ -4895,7 +5067,7 @@ var SMTBeacon = class extends Beacon {
|
|
|
4895
5067
|
* Builds a single-entry Sparse Merkle Tree from the signed update, then broadcasts the tree's
|
|
4896
5068
|
* root hash via OP_RETURN. For multi-party aggregation, use the {@link AggregationService}
|
|
4897
5069
|
* subsystem directly instead of this method. UTXO selection, PSBT construction, fee estimation,
|
|
4898
|
-
* signing, and broadcast are delegated to {@link
|
|
5070
|
+
* signing, and broadcast are delegated to {@link SinglePartyBeacon.buildSignAndBroadcast}.
|
|
4899
5071
|
*
|
|
4900
5072
|
* @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
|
|
4901
5073
|
* @param {Signer} signer Signer that produces the ECDSA signature for the Bitcoin transaction.
|
|
@@ -4907,7 +5079,7 @@ var SMTBeacon = class extends Beacon {
|
|
|
4907
5079
|
async broadcastSignal(signedUpdate, signer, bitcoin, options) {
|
|
4908
5080
|
const did = this.service.id.split("#")[0];
|
|
4909
5081
|
const canonicalBytes = new TextEncoder().encode((0, import_common15.canonicalize)(signedUpdate));
|
|
4910
|
-
const nonce = (0,
|
|
5082
|
+
const nonce = (0, import_utils9.randomBytes)(32);
|
|
4911
5083
|
const tree = new import_smt3.BTCR2MerkleTree();
|
|
4912
5084
|
tree.addEntries([{ did, nonce, signedUpdate: canonicalBytes }]);
|
|
4913
5085
|
tree.finalize();
|
|
@@ -4921,7 +5093,7 @@ var BeaconFactory = class {
|
|
|
4921
5093
|
/**
|
|
4922
5094
|
* Establish a Beacon instance based on the provided service and optional sidecar data.
|
|
4923
5095
|
* @param {BeaconService} service The beacon service configuration.
|
|
4924
|
-
* @returns {
|
|
5096
|
+
* @returns {SinglePartyBeacon} The established Beacon instance.
|
|
4925
5097
|
*/
|
|
4926
5098
|
static establish(service) {
|
|
4927
5099
|
switch (service.type) {
|
|
@@ -6278,7 +6450,7 @@ var import_cryptosuite2 = require("@did-btcr2/cryptosuite");
|
|
|
6278
6450
|
var import_bitcoin3 = require("@did-btcr2/bitcoin");
|
|
6279
6451
|
var import_common19 = require("@did-btcr2/common");
|
|
6280
6452
|
var import_keypair5 = require("@did-btcr2/keypair");
|
|
6281
|
-
var
|
|
6453
|
+
var import_utils11 = require("@web5/dids/utils");
|
|
6282
6454
|
var import_btc_signer6 = require("@scure/btc-signer");
|
|
6283
6455
|
var BTCR2_DID_DOCUMENT_CONTEXT = [
|
|
6284
6456
|
"https://www.w3.org/ns/did/v1.1",
|
|
@@ -6488,7 +6660,7 @@ var DidDocument = class _DidDocument {
|
|
|
6488
6660
|
* @returns {boolean} True if the services are valid.
|
|
6489
6661
|
*/
|
|
6490
6662
|
static isValidServices(service) {
|
|
6491
|
-
return Array.isArray(service) && service.every(
|
|
6663
|
+
return Array.isArray(service) && service.every(import_utils11.isDidService);
|
|
6492
6664
|
}
|
|
6493
6665
|
/**
|
|
6494
6666
|
* Validates verification relationships (authentication, assertionMethod, capabilityInvocation, capabilityDelegation).
|
|
@@ -7068,7 +7240,7 @@ var DidBtcr2 = class {
|
|
|
7068
7240
|
};
|
|
7069
7241
|
|
|
7070
7242
|
// src/core/resolver.ts
|
|
7071
|
-
var
|
|
7243
|
+
var import_utils13 = require("@noble/curves/utils.js");
|
|
7072
7244
|
var Resolver = class _Resolver {
|
|
7073
7245
|
// --- Immutable inputs ---
|
|
7074
7246
|
#didComponents;
|
|
@@ -7135,7 +7307,7 @@ var Resolver = class _Resolver {
|
|
|
7135
7307
|
*/
|
|
7136
7308
|
static external(didComponents, genesisDocument) {
|
|
7137
7309
|
const genesisDocumentHash = (0, import_common22.canonicalHashBytes)(genesisDocument);
|
|
7138
|
-
if (!(0,
|
|
7310
|
+
if (!(0, import_utils13.equalBytes)(didComponents.genesisBytes, genesisDocumentHash)) {
|
|
7139
7311
|
throw new import_common22.ResolveError(
|
|
7140
7312
|
`Initial document mismatch: genesisBytes !== genesisDocumentHash`,
|
|
7141
7313
|
import_common22.INVALID_DID_DOCUMENT,
|
|
@@ -7212,7 +7384,7 @@ var Resolver = class _Resolver {
|
|
|
7212
7384
|
this.confirmDuplicate(update, updateHashHistory);
|
|
7213
7385
|
} else if (update.targetVersionId === currentVersionId + 1) {
|
|
7214
7386
|
const sourceHashBytes = (0, import_common22.decode)(update.sourceHash, "base64urlnopad");
|
|
7215
|
-
if (!(0,
|
|
7387
|
+
if (!(0, import_utils13.equalBytes)(sourceHashBytes, currentDocumentHash)) {
|
|
7216
7388
|
throw new import_common22.ResolveError(
|
|
7217
7389
|
`Hash mismatch: update.sourceHash !== currentDocumentHash`,
|
|
7218
7390
|
import_common22.INVALID_DID_UPDATE,
|
|
@@ -7259,7 +7431,7 @@ var Resolver = class _Resolver {
|
|
|
7259
7431
|
const { proof: _, ...unsignedUpdate } = update;
|
|
7260
7432
|
const unsignedUpdateHash = (0, import_common22.canonicalHashBytes)(unsignedUpdate);
|
|
7261
7433
|
const historicalUpdateHash = updateHashHistory[update.targetVersionId - 2];
|
|
7262
|
-
if (!(0,
|
|
7434
|
+
if (!(0, import_utils13.equalBytes)(historicalUpdateHash, unsignedUpdateHash)) {
|
|
7263
7435
|
throw new import_common22.ResolveError(
|
|
7264
7436
|
`Invalid duplicate: unsigned update hash does not match historical hash`,
|
|
7265
7437
|
import_common22.LATE_PUBLISHING_ERROR,
|
|
@@ -7312,7 +7484,7 @@ var Resolver = class _Resolver {
|
|
|
7312
7484
|
DidDocument.validate(updatedDocument);
|
|
7313
7485
|
const currentDocumentHash = (0, import_common22.canonicalHashBytes)(updatedDocument);
|
|
7314
7486
|
const updateTargetHash = (0, import_common22.decode)(update.targetHash);
|
|
7315
|
-
if (!(0,
|
|
7487
|
+
if (!(0, import_utils13.equalBytes)(updateTargetHash, currentDocumentHash)) {
|
|
7316
7488
|
throw new import_common22.ResolveError(
|
|
7317
7489
|
`Invalid update: update.targetHash !== currentDocumentHash`,
|
|
7318
7490
|
import_common22.INVALID_DID_UPDATE,
|
|
@@ -7539,6 +7711,7 @@ var DidDocumentBuilder = class {
|
|
|
7539
7711
|
AggregationParticipant,
|
|
7540
7712
|
AggregationParticipantError,
|
|
7541
7713
|
AggregationParticipantRunner,
|
|
7714
|
+
AggregationRunner,
|
|
7542
7715
|
AggregationService,
|
|
7543
7716
|
AggregationServiceError,
|
|
7544
7717
|
AggregationServiceRunner,
|
|
@@ -7546,7 +7719,6 @@ var DidDocumentBuilder = class {
|
|
|
7546
7719
|
BECH32M_CHARS,
|
|
7547
7720
|
BTCR2_DID_DOCUMENT_CONTEXT,
|
|
7548
7721
|
BaseMessage,
|
|
7549
|
-
Beacon,
|
|
7550
7722
|
BeaconError,
|
|
7551
7723
|
BeaconFactory,
|
|
7552
7724
|
BeaconSignalDiscovery,
|
|
@@ -7581,7 +7753,9 @@ var DidDocumentBuilder = class {
|
|
|
7581
7753
|
HttpTransportError,
|
|
7582
7754
|
ID_PLACEHOLDER_VALUE,
|
|
7583
7755
|
Identifier,
|
|
7756
|
+
InMemoryBus,
|
|
7584
7757
|
InMemoryRateLimitStore,
|
|
7758
|
+
InMemoryTransport,
|
|
7585
7759
|
InboxBuffer,
|
|
7586
7760
|
NONCE_CONTRIBUTION,
|
|
7587
7761
|
NonceCache,
|
|
@@ -7603,6 +7777,7 @@ var DidDocumentBuilder = class {
|
|
|
7603
7777
|
ServiceCohortPhase,
|
|
7604
7778
|
SigningSessionError,
|
|
7605
7779
|
SigningSessionPhase,
|
|
7780
|
+
SinglePartyBeacon,
|
|
7606
7781
|
SingletonBeacon,
|
|
7607
7782
|
SingletonBeaconError,
|
|
7608
7783
|
StaticFeeEstimator,
|
|
@@ -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,IAAI,CAAC,OAA0B;QAC1C,MAAM,SAAS,GAAG,IAAI,iBAAiB,CAAC,IAAI,WAAW,EAAE,CAAC,CAAC;QAC3D,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACnE,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAC3E,4EAA4E;QAC5E,4DAA4D;QAC5D,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAC/F,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACvF,SAAS,CAAC,KAAK,EAAE,CAAC;QAElB,MAAM,OAAO,GAAG,IAAI,wBAAwB,CAAC;YAC3C,SAAS;YACT,GAAG,EAAsB,OAAO,CAAC,OAAO,CAAC,GAAG;YAC5C,IAAI,EAAqB,OAAO,CAAC,OAAO,CAAC,IAAI;YAC7C,MAAM,EAAmB,EAAE,eAAe,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE;YACvH,eAAe,EAAU,OAAO,CAAC,eAAe;YAChD,WAAW,EAAc,OAAO,CAAC,WAAW;YAC5C,cAAc,EAAW,OAAO,CAAC,cAAc;YAC/C,yEAAyE;YACzE,kEAAkE;YAClE,sBAAsB,EAAG,CAAC;SAC3B,CAAC,CAAC;QAEH,MAAM,WAAW,GAAG,IAAI,4BAA4B,CAAC;YACnD,SAAS;YACT,GAAG,EAAe,OAAO,CAAC,WAAW,CAAC,GAAG;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"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { bytesToHex, hexToBytes } from '@noble/hashes/utils';
|
|
2
|
+
/**
|
|
3
|
+
* In-process message bus connecting one or more {@link InMemoryTransport}
|
|
4
|
+
* instances. Routes broadcasts to every registered actor and directed messages
|
|
5
|
+
* to the actor that owns the recipient DID — with no relay, server, or network.
|
|
6
|
+
*
|
|
7
|
+
* Each delivery does a JSON round-trip (Uint8Array preserved as `__bytes` hex)
|
|
8
|
+
* so handlers receive an isolated, serialization-faithful copy, exactly as a
|
|
9
|
+
* real transport would. The message `body` is merged to the top level to match
|
|
10
|
+
* the shape the {@link NostrTransport} dispatch produces.
|
|
11
|
+
*
|
|
12
|
+
* @class InMemoryBus
|
|
13
|
+
*/
|
|
14
|
+
export class InMemoryBus {
|
|
15
|
+
#transports = new Set();
|
|
16
|
+
/** Attach a transport to this bus. Called by the transport's constructor. */
|
|
17
|
+
register(transport) {
|
|
18
|
+
this.#transports.add(transport);
|
|
19
|
+
}
|
|
20
|
+
/** Detach a transport from this bus. */
|
|
21
|
+
unregister(transport) {
|
|
22
|
+
this.#transports.delete(transport);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Deliver a message. With no `recipient` the message is broadcast to every
|
|
26
|
+
* actor on the bus; otherwise it is routed to the single transport that owns
|
|
27
|
+
* the recipient DID.
|
|
28
|
+
*/
|
|
29
|
+
async deliver(message, _sender, recipient) {
|
|
30
|
+
const type = message.type;
|
|
31
|
+
if (!type)
|
|
32
|
+
return;
|
|
33
|
+
// JSON round-trip to mimic transport serialization, preserving Uint8Array.
|
|
34
|
+
const replacer = (_k, v) => v instanceof Uint8Array ? { __bytes: bytesToHex(v) } : v;
|
|
35
|
+
const reviver = (_k, v) => v && typeof v === 'object' && '__bytes' in v
|
|
36
|
+
? hexToBytes(v.__bytes)
|
|
37
|
+
: v;
|
|
38
|
+
const raw = JSON.parse(JSON.stringify(message, replacer), reviver);
|
|
39
|
+
const serialized = { ...raw, ...(raw.body ?? {}) };
|
|
40
|
+
if (!recipient) {
|
|
41
|
+
for (const t of this.#transports) {
|
|
42
|
+
await t.dispatchBroadcast(type, serialized);
|
|
43
|
+
}
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
for (const t of this.#transports) {
|
|
47
|
+
if (t.hasActor(recipient)) {
|
|
48
|
+
await t.dispatchDirected(recipient, type, serialized);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* In-process {@link Transport} that routes aggregation messages through an
|
|
56
|
+
* {@link InMemoryBus} instead of a relay or HTTP server. Supports multiple
|
|
57
|
+
* actors per instance, so a single transport can host both a service and its
|
|
58
|
+
* participants (e.g. a cohort-of-one via {@link AggregationRunner.solo}).
|
|
59
|
+
*
|
|
60
|
+
* Encryption is a no-op (in-process, same trust domain); `registerPeer` /
|
|
61
|
+
* `getPeerPk` keep a registry so the contract matches the wire transports.
|
|
62
|
+
*
|
|
63
|
+
* @class InMemoryTransport
|
|
64
|
+
* @implements {Transport}
|
|
65
|
+
*/
|
|
66
|
+
export class InMemoryTransport {
|
|
67
|
+
name = 'in-memory';
|
|
68
|
+
bus;
|
|
69
|
+
#actors = new Map();
|
|
70
|
+
#peers = new Map();
|
|
71
|
+
/** @param bus Shared bus. Pass the same bus to connect multiple transports. */
|
|
72
|
+
constructor(bus = new InMemoryBus()) {
|
|
73
|
+
this.bus = bus;
|
|
74
|
+
this.bus.register(this);
|
|
75
|
+
}
|
|
76
|
+
start() {
|
|
77
|
+
// No-op: there is no underlying connection to open.
|
|
78
|
+
}
|
|
79
|
+
registerActor(did, keys) {
|
|
80
|
+
this.#actors.set(did, { keys, handlers: new Map() });
|
|
81
|
+
}
|
|
82
|
+
getActorPk(did) {
|
|
83
|
+
return this.#actors.get(did)?.keys.publicKey.compressed;
|
|
84
|
+
}
|
|
85
|
+
/** True if `did` is registered on this transport. Used by the bus for routing. */
|
|
86
|
+
hasActor(did) {
|
|
87
|
+
return this.#actors.has(did);
|
|
88
|
+
}
|
|
89
|
+
registerPeer(did, communicationPk) {
|
|
90
|
+
this.#peers.set(did, communicationPk);
|
|
91
|
+
}
|
|
92
|
+
getPeerPk(did) {
|
|
93
|
+
return this.#peers.get(did);
|
|
94
|
+
}
|
|
95
|
+
registerMessageHandler(actorDid, messageType, handler) {
|
|
96
|
+
const actor = this.#actors.get(actorDid);
|
|
97
|
+
if (actor)
|
|
98
|
+
actor.handlers.set(messageType, handler);
|
|
99
|
+
}
|
|
100
|
+
unregisterMessageHandler(actorDid, messageType) {
|
|
101
|
+
const actor = this.#actors.get(actorDid);
|
|
102
|
+
if (actor)
|
|
103
|
+
actor.handlers.delete(messageType);
|
|
104
|
+
}
|
|
105
|
+
unregisterActor(did) {
|
|
106
|
+
const actor = this.#actors.get(did);
|
|
107
|
+
if (!actor)
|
|
108
|
+
return;
|
|
109
|
+
actor.handlers.clear();
|
|
110
|
+
this.#actors.delete(did);
|
|
111
|
+
this.#peers.delete(did);
|
|
112
|
+
}
|
|
113
|
+
async sendMessage(message, sender, recipient) {
|
|
114
|
+
await this.bus.deliver(message, sender, recipient);
|
|
115
|
+
}
|
|
116
|
+
publishRepeating(message, sender, intervalMs, recipient) {
|
|
117
|
+
let stopped = false;
|
|
118
|
+
void this.sendMessage(message, sender, recipient).catch(() => { });
|
|
119
|
+
const timer = setInterval(() => {
|
|
120
|
+
if (stopped)
|
|
121
|
+
return;
|
|
122
|
+
void this.sendMessage(message, sender, recipient).catch(() => { });
|
|
123
|
+
}, intervalMs);
|
|
124
|
+
return () => {
|
|
125
|
+
if (stopped)
|
|
126
|
+
return;
|
|
127
|
+
stopped = true;
|
|
128
|
+
clearInterval(timer);
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/** Deliver a broadcast message to every actor on this transport that handles `type`. */
|
|
132
|
+
async dispatchBroadcast(type, message) {
|
|
133
|
+
for (const actor of this.#actors.values()) {
|
|
134
|
+
const handler = actor.handlers.get(type);
|
|
135
|
+
if (handler)
|
|
136
|
+
await handler(message);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/** Deliver a directed message to the recipient actor's handler for `type`. */
|
|
140
|
+
async dispatchDirected(recipientDid, type, message) {
|
|
141
|
+
const handler = this.#actors.get(recipientDid)?.handlers.get(type);
|
|
142
|
+
if (handler)
|
|
143
|
+
await handler(message);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=in-memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory.js","sourceRoot":"","sources":["../../../../../src/core/aggregation/transport/in-memory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAU7D;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,WAAW;IACtB,WAAW,GAA2B,IAAI,GAAG,EAAE,CAAC;IAEhD,6EAA6E;IAC7E,QAAQ,CAAC,SAA4B;QACnC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC;IAED,wCAAwC;IACxC,UAAU,CAAC,SAA4B;QACrC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACrC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,OAAO,CAAC,OAAoB,EAAE,OAAe,EAAE,SAAkB;QACrE,MAAM,IAAI,GAAI,OAA6B,CAAC,IAAI,CAAC;QACjD,IAAG,CAAC,IAAI;YAAE,OAAO;QAEjB,2EAA2E;QAC3E,MAAM,QAAQ,GAAG,CAAC,EAAU,EAAE,CAAU,EAAW,EAAE,CAAC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AK,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YACzC,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACzC,IAAG,OAAO;gBAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;IAED,8EAA8E;IAC9E,KAAK,CAAC,gBAAgB,CAAC,YAAoB,EAAE,IAAY,EAAE,OAAgB;QACzE,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACnE,IAAG,OAAO;YAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/aggregation/transport/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/aggregation/transport/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}
|