@did-btcr2/aggregation 0.1.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/LICENSE +373 -0
- package/README.md +19 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/browser.js +24017 -0
- package/dist/browser.mjs +24011 -0
- package/dist/cjs/index.js +5690 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/beacon-strategy.js +76 -0
- package/dist/esm/beacon-strategy.js.map +1 -0
- package/dist/esm/cohort.js +316 -0
- package/dist/esm/cohort.js.map +1 -0
- package/dist/esm/conditions.js +102 -0
- package/dist/esm/conditions.js.map +1 -0
- package/dist/esm/errors.js +22 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/fallback-spend.js +132 -0
- package/dist/esm/fallback-spend.js.map +1 -0
- package/dist/esm/index.js +21 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/logger.js +15 -0
- package/dist/esm/logger.js.map +1 -0
- package/dist/esm/messages/base.js +36 -0
- package/dist/esm/messages/base.js.map +1 -0
- package/dist/esm/messages/bodies.js +149 -0
- package/dist/esm/messages/bodies.js.map +1 -0
- package/dist/esm/messages/constants.js +37 -0
- package/dist/esm/messages/constants.js.map +1 -0
- package/dist/esm/messages/factories.js +139 -0
- package/dist/esm/messages/factories.js.map +1 -0
- package/dist/esm/messages/guards.js +40 -0
- package/dist/esm/messages/guards.js.map +1 -0
- package/dist/esm/messages/index.js +6 -0
- package/dist/esm/messages/index.js.map +1 -0
- package/dist/esm/participant.js +588 -0
- package/dist/esm/participant.js.map +1 -0
- package/dist/esm/phases.js +45 -0
- package/dist/esm/phases.js.map +1 -0
- package/dist/esm/recovery-policy.js +156 -0
- package/dist/esm/recovery-policy.js.map +1 -0
- package/dist/esm/recovery-spend.js +106 -0
- package/dist/esm/recovery-spend.js.map +1 -0
- package/dist/esm/runner/aggregation-runner.js +75 -0
- package/dist/esm/runner/aggregation-runner.js.map +1 -0
- package/dist/esm/runner/events.js +2 -0
- package/dist/esm/runner/events.js.map +1 -0
- package/dist/esm/runner/index.js +6 -0
- package/dist/esm/runner/index.js.map +1 -0
- package/dist/esm/runner/participant-runner.js +407 -0
- package/dist/esm/runner/participant-runner.js.map +1 -0
- package/dist/esm/runner/service-runner.js +701 -0
- package/dist/esm/runner/service-runner.js.map +1 -0
- package/dist/esm/runner/typed-emitter.js +80 -0
- package/dist/esm/runner/typed-emitter.js.map +1 -0
- package/dist/esm/service.js +774 -0
- package/dist/esm/service.js.map +1 -0
- package/dist/esm/signer.js +33 -0
- package/dist/esm/signer.js.map +1 -0
- package/dist/esm/signing-session.js +195 -0
- package/dist/esm/signing-session.js.map +1 -0
- package/dist/esm/transport/didcomm.js +41 -0
- package/dist/esm/transport/didcomm.js.map +1 -0
- package/dist/esm/transport/error.js +12 -0
- package/dist/esm/transport/error.js.map +1 -0
- package/dist/esm/transport/factory.js +29 -0
- package/dist/esm/transport/factory.js.map +1 -0
- package/dist/esm/transport/http/client.js +342 -0
- package/dist/esm/transport/http/client.js.map +1 -0
- package/dist/esm/transport/http/envelope.js +126 -0
- package/dist/esm/transport/http/envelope.js.map +1 -0
- package/dist/esm/transport/http/errors.js +11 -0
- package/dist/esm/transport/http/errors.js.map +1 -0
- package/dist/esm/transport/http/inbox-buffer.js +45 -0
- package/dist/esm/transport/http/inbox-buffer.js.map +1 -0
- package/dist/esm/transport/http/index.js +12 -0
- package/dist/esm/transport/http/index.js.map +1 -0
- package/dist/esm/transport/http/nonce-cache.js +38 -0
- package/dist/esm/transport/http/nonce-cache.js.map +1 -0
- package/dist/esm/transport/http/protocol.js +28 -0
- package/dist/esm/transport/http/protocol.js.map +1 -0
- package/dist/esm/transport/http/rate-limiter.js +45 -0
- package/dist/esm/transport/http/rate-limiter.js.map +1 -0
- package/dist/esm/transport/http/request-auth.js +100 -0
- package/dist/esm/transport/http/request-auth.js.map +1 -0
- package/dist/esm/transport/http/server.js +475 -0
- package/dist/esm/transport/http/server.js.map +1 -0
- package/dist/esm/transport/http/sse-stream.js +110 -0
- package/dist/esm/transport/http/sse-stream.js.map +1 -0
- package/dist/esm/transport/http/sse-writer.js +25 -0
- package/dist/esm/transport/http/sse-writer.js.map +1 -0
- package/dist/esm/transport/in-memory.js +149 -0
- package/dist/esm/transport/in-memory.js.map +1 -0
- package/dist/esm/transport/index.js +8 -0
- package/dist/esm/transport/index.js.map +1 -0
- package/dist/esm/transport/nostr.js +491 -0
- package/dist/esm/transport/nostr.js.map +1 -0
- package/dist/esm/transport/transport.js +2 -0
- package/dist/esm/transport/transport.js.map +1 -0
- package/dist/types/beacon-strategy.d.ts +56 -0
- package/dist/types/beacon-strategy.d.ts.map +1 -0
- package/dist/types/cohort.d.ts +188 -0
- package/dist/types/cohort.d.ts.map +1 -0
- package/dist/types/conditions.d.ts +86 -0
- package/dist/types/conditions.d.ts.map +1 -0
- package/dist/types/errors.d.ts +14 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/fallback-spend.d.ts +94 -0
- package/dist/types/fallback-spend.d.ts.map +1 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/logger.d.ts +22 -0
- package/dist/types/logger.d.ts.map +1 -0
- package/dist/types/messages/base.d.ts +58 -0
- package/dist/types/messages/base.d.ts.map +1 -0
- package/dist/types/messages/bodies.d.ts +177 -0
- package/dist/types/messages/bodies.d.ts.map +1 -0
- package/dist/types/messages/constants.d.ts +31 -0
- package/dist/types/messages/constants.d.ts.map +1 -0
- package/dist/types/messages/factories.d.ts +217 -0
- package/dist/types/messages/factories.d.ts.map +1 -0
- package/dist/types/messages/guards.d.ts +11 -0
- package/dist/types/messages/guards.d.ts.map +1 -0
- package/dist/types/messages/index.d.ts +6 -0
- package/dist/types/messages/index.d.ts.map +1 -0
- package/dist/types/participant.d.ts +162 -0
- package/dist/types/participant.d.ts.map +1 -0
- package/dist/types/phases.d.ts +55 -0
- package/dist/types/phases.d.ts.map +1 -0
- package/dist/types/recovery-policy.d.ts +132 -0
- package/dist/types/recovery-policy.d.ts.map +1 -0
- package/dist/types/recovery-spend.d.ts +94 -0
- package/dist/types/recovery-spend.d.ts.map +1 -0
- package/dist/types/runner/aggregation-runner.d.ts +72 -0
- package/dist/types/runner/aggregation-runner.d.ts.map +1 -0
- package/dist/types/runner/events.d.ts +147 -0
- package/dist/types/runner/events.d.ts.map +1 -0
- package/dist/types/runner/index.d.ts +6 -0
- package/dist/types/runner/index.d.ts.map +1 -0
- package/dist/types/runner/participant-runner.d.ts +122 -0
- package/dist/types/runner/participant-runner.d.ts.map +1 -0
- package/dist/types/runner/service-runner.d.ts +228 -0
- package/dist/types/runner/service-runner.d.ts.map +1 -0
- package/dist/types/runner/typed-emitter.d.ts +41 -0
- package/dist/types/runner/typed-emitter.d.ts.map +1 -0
- package/dist/types/service.d.ts +177 -0
- package/dist/types/service.d.ts.map +1 -0
- package/dist/types/signer.d.ts +50 -0
- package/dist/types/signer.d.ts.map +1 -0
- package/dist/types/signing-session.d.ts +81 -0
- package/dist/types/signing-session.d.ts.map +1 -0
- package/dist/types/transport/didcomm.d.ts +23 -0
- package/dist/types/transport/didcomm.d.ts.map +1 -0
- package/dist/types/transport/error.d.ts +8 -0
- package/dist/types/transport/error.d.ts.map +1 -0
- package/dist/types/transport/factory.d.ts +28 -0
- package/dist/types/transport/factory.d.ts.map +1 -0
- package/dist/types/transport/http/client.d.ts +56 -0
- package/dist/types/transport/http/client.d.ts.map +1 -0
- package/dist/types/transport/http/envelope.d.ts +64 -0
- package/dist/types/transport/http/envelope.d.ts.map +1 -0
- package/dist/types/transport/http/errors.d.ts +9 -0
- package/dist/types/transport/http/errors.d.ts.map +1 -0
- package/dist/types/transport/http/inbox-buffer.d.ts +32 -0
- package/dist/types/transport/http/inbox-buffer.d.ts.map +1 -0
- package/dist/types/transport/http/index.d.ts +12 -0
- package/dist/types/transport/http/index.d.ts.map +1 -0
- package/dist/types/transport/http/nonce-cache.d.ts +26 -0
- package/dist/types/transport/http/nonce-cache.d.ts.map +1 -0
- package/dist/types/transport/http/protocol.d.ts +53 -0
- package/dist/types/transport/http/protocol.d.ts.map +1 -0
- package/dist/types/transport/http/rate-limiter.d.ts +41 -0
- package/dist/types/transport/http/rate-limiter.d.ts.map +1 -0
- package/dist/types/transport/http/request-auth.d.ts +50 -0
- package/dist/types/transport/http/request-auth.d.ts.map +1 -0
- package/dist/types/transport/http/server.d.ts +118 -0
- package/dist/types/transport/http/server.d.ts.map +1 -0
- package/dist/types/transport/http/sse-stream.d.ts +34 -0
- package/dist/types/transport/http/sse-stream.d.ts.map +1 -0
- package/dist/types/transport/http/sse-writer.d.ts +12 -0
- package/dist/types/transport/http/sse-writer.d.ts.map +1 -0
- package/dist/types/transport/in-memory.d.ts +64 -0
- package/dist/types/transport/in-memory.d.ts.map +1 -0
- package/dist/types/transport/index.d.ts +8 -0
- package/dist/types/transport/index.d.ts.map +1 -0
- package/dist/types/transport/nostr.d.ts +153 -0
- package/dist/types/transport/nostr.d.ts.map +1 -0
- package/dist/types/transport/transport.d.ts +62 -0
- package/dist/types/transport/transport.d.ts.map +1 -0
- package/package.json +128 -0
- package/src/beacon-strategy.ts +142 -0
- package/src/cohort.ts +422 -0
- package/src/conditions.ts +172 -0
- package/src/errors.ts +25 -0
- package/src/fallback-spend.ts +223 -0
- package/src/index.ts +23 -0
- package/src/logger.ts +33 -0
- package/src/messages/base.ts +80 -0
- package/src/messages/bodies.ts +328 -0
- package/src/messages/constants.ts +40 -0
- package/src/messages/factories.ts +297 -0
- package/src/messages/guards.ts +61 -0
- package/src/messages/index.ts +5 -0
- package/src/participant.ts +779 -0
- package/src/phases.ts +91 -0
- package/src/recovery-policy.ts +237 -0
- package/src/recovery-spend.ts +192 -0
- package/src/runner/aggregation-runner.ts +125 -0
- package/src/runner/events.ts +129 -0
- package/src/runner/index.ts +5 -0
- package/src/runner/participant-runner.ts +488 -0
- package/src/runner/service-runner.ts +891 -0
- package/src/runner/typed-emitter.ts +87 -0
- package/src/service.ts +1000 -0
- package/src/signer.ts +67 -0
- package/src/signing-session.ts +290 -0
- package/src/transport/didcomm.ts +59 -0
- package/src/transport/error.ts +13 -0
- package/src/transport/factory.ts +65 -0
- package/src/transport/http/client.ts +409 -0
- package/src/transport/http/envelope.ts +204 -0
- package/src/transport/http/errors.ts +11 -0
- package/src/transport/http/inbox-buffer.ts +53 -0
- package/src/transport/http/index.ts +11 -0
- package/src/transport/http/nonce-cache.ts +43 -0
- package/src/transport/http/protocol.ts +57 -0
- package/src/transport/http/rate-limiter.ts +75 -0
- package/src/transport/http/request-auth.ts +164 -0
- package/src/transport/http/server.ts +617 -0
- package/src/transport/http/sse-stream.ts +121 -0
- package/src/transport/http/sse-writer.ts +23 -0
- package/src/transport/in-memory.ts +178 -0
- package/src/transport/index.ts +7 -0
- package/src/transport/nostr.ts +576 -0
- package/src/transport/transport.ts +79 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import type { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
|
|
2
|
+
import type { SerializedSMTProof } from '@did-btcr2/smt';
|
|
3
|
+
import type { FundingModel } from './recovery-policy.js';
|
|
4
|
+
/**
|
|
5
|
+
* The CAS Beacon Announcement Map a cohort produces: a record of DID to update hash.
|
|
6
|
+
* Defined locally so the aggregation package does not depend on method; it is
|
|
7
|
+
* structurally compatible with method's resolution-side `CASAnnouncement` type, which
|
|
8
|
+
* the resolver consumes when reading the announcement off the content-addressed store.
|
|
9
|
+
*/
|
|
10
|
+
export type CASAnnouncementMap = Record<string, string>;
|
|
11
|
+
export type AggregationCohortParams = {
|
|
12
|
+
id?: string;
|
|
13
|
+
serviceDid?: string;
|
|
14
|
+
minParticipants?: number;
|
|
15
|
+
network: string;
|
|
16
|
+
beaconType?: string;
|
|
17
|
+
/** Operator recovery key, x-only (32 bytes). Required to compute the beacon address. */
|
|
18
|
+
recoveryKey?: Uint8Array;
|
|
19
|
+
/** Relative-timelock (BIP-68 nSequence) before recovery is spendable. Required to compute the beacon address. */
|
|
20
|
+
recoverySequence?: number;
|
|
21
|
+
/** Funding model governing the recovery leaves. Defaults to 'operator-funded'. */
|
|
22
|
+
fundingModel?: FundingModel;
|
|
23
|
+
/** Advertised k of the k-of-n fallback leaf. Absent defaults to n-1 at address computation. */
|
|
24
|
+
fallbackThreshold?: number;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Represents an Aggregation Cohort: a set of Aggregation Participants who
|
|
28
|
+
* submitted cryptographic material to an Aggregation Service to coordinate
|
|
29
|
+
* signing of a shared n-of-n MuSig2 Bitcoin transaction.
|
|
30
|
+
*
|
|
31
|
+
* This is a pure data class: it holds cohort state and provides computation
|
|
32
|
+
* helpers (key aggregation, CAS Announcement building, SMT tree building).
|
|
33
|
+
* It performs no I/O and emits no messages. Both AggregationService and
|
|
34
|
+
* AggregationParticipant create their own AggregationCohort instances to
|
|
35
|
+
* track their respective views of the cohort state.
|
|
36
|
+
*
|
|
37
|
+
* @class AggregationCohort
|
|
38
|
+
*/
|
|
39
|
+
export declare class AggregationCohort {
|
|
40
|
+
#private;
|
|
41
|
+
/** Unique identifier for the cohort. */
|
|
42
|
+
id: string;
|
|
43
|
+
/** DID of the Aggregation Service managing this cohort. */
|
|
44
|
+
serviceDid: string;
|
|
45
|
+
/** Minimum number of participants required to finalize the cohort. */
|
|
46
|
+
minParticipants: number;
|
|
47
|
+
/** Network on which the cohort operates (mainnet, mutinynet, etc.). */
|
|
48
|
+
network: string;
|
|
49
|
+
/** Type of beacon used in the cohort: 'CASBeacon' or 'SMTBeacon'. */
|
|
50
|
+
beaconType: string;
|
|
51
|
+
/** List of participant DIDs that have been accepted into the cohort. */
|
|
52
|
+
participants: Array<string>;
|
|
53
|
+
/**
|
|
54
|
+
* Mapping from participant DID to their compressed secp256k1 public key.
|
|
55
|
+
* Distinct from {@link cohortKeys} (which is sorted per BIP-327): this lets
|
|
56
|
+
* callers look up a participant's key without knowing their position in the
|
|
57
|
+
* sorted array. Populated by the service at `acceptParticipant` time.
|
|
58
|
+
*/
|
|
59
|
+
participantKeys: Map<string, Uint8Array>;
|
|
60
|
+
/**
|
|
61
|
+
* BIP-341 TapTweak scalar: `taggedHash("TapTweak", internalPubkey || tapMerkleRoot)`.
|
|
62
|
+
* The beacon output is an internal key (the MuSig2 aggregate) plus a script
|
|
63
|
+
* tree (the recovery leaves), so the tweak commits to the tree's Merkle root.
|
|
64
|
+
* The MuSig2 signing session applies this as an x-only tweak; a value that does
|
|
65
|
+
* not match the root the funded address was derived from silently yields an
|
|
66
|
+
* invalid key-path signature.
|
|
67
|
+
*/
|
|
68
|
+
tapTweak: Uint8Array;
|
|
69
|
+
/** The n-of-n MuSig2 aggregate internal key, x-only (32 bytes), set by computeBeaconAddress(). */
|
|
70
|
+
internalKey: Uint8Array;
|
|
71
|
+
/** BIP-341 Taproot Merkle root of the recovery script tree, set by computeBeaconAddress(). */
|
|
72
|
+
tapMerkleRoot: Uint8Array;
|
|
73
|
+
/** Operator recovery key, x-only (32 bytes). Used to build the CSV recovery leaf. */
|
|
74
|
+
recoveryKey?: Uint8Array;
|
|
75
|
+
/** Relative-timelock (BIP-68 nSequence) before the recovery leaf is spendable. */
|
|
76
|
+
recoverySequence?: number;
|
|
77
|
+
/** Funding model governing the recovery leaves (default 'operator-funded'). */
|
|
78
|
+
fundingModel: FundingModel;
|
|
79
|
+
/**
|
|
80
|
+
* Advertised k of the k-of-n fallback leaf, or undefined to default to n-1 at
|
|
81
|
+
* address computation. Read the resolved value via {@link effectiveFallbackThreshold}.
|
|
82
|
+
*/
|
|
83
|
+
fallbackThreshold?: number;
|
|
84
|
+
/** The Taproot beacon address: key path is the MuSig2 aggregate, script path is fallback + recovery. */
|
|
85
|
+
beaconAddress: string;
|
|
86
|
+
/** Pending DID updates submitted by participants, keyed by DID. */
|
|
87
|
+
pendingUpdates: Map<string, SignedBTCR2Update>;
|
|
88
|
+
/**
|
|
89
|
+
* Participant DIDs that explicitly declined to submit an update this round
|
|
90
|
+
* (cooperative non-inclusion). A decliner is absent from the CAS Announcement
|
|
91
|
+
* Map and carries a non-inclusion leaf in the SMT, yet still signs. Kept
|
|
92
|
+
* disjoint from {@link pendingUpdates} so CAS correctness holds by construction.
|
|
93
|
+
*/
|
|
94
|
+
nonIncluded: Set<string>;
|
|
95
|
+
/** CAS Beacon Announcement Map (DID to updateHash), set by buildCASAnnouncement(). */
|
|
96
|
+
casAnnouncement?: CASAnnouncementMap;
|
|
97
|
+
/** Per-participant SMT proofs, set by buildSMTTree(). */
|
|
98
|
+
smtProofs?: Map<string, SerializedSMTProof>;
|
|
99
|
+
/** Signal bytes (32 bytes) for OP_RETURN: SHA-256 of CAS announcement OR SMT root. */
|
|
100
|
+
signalBytes?: Uint8Array;
|
|
101
|
+
/** Set of participant DIDs that have approved the aggregated data. */
|
|
102
|
+
validationAcks: Set<string>;
|
|
103
|
+
/** Set of participant DIDs that have rejected the aggregated data. */
|
|
104
|
+
validationRejections: Set<string>;
|
|
105
|
+
constructor({ id, minParticipants, serviceDid, network, beaconType, recoveryKey, recoverySequence, fundingModel, fallbackThreshold }: AggregationCohortParams);
|
|
106
|
+
/** Sorted cohort keys (sorted on assignment per BIP-327). */
|
|
107
|
+
get cohortKeys(): Array<Uint8Array>;
|
|
108
|
+
set cohortKeys(keys: Array<Uint8Array>);
|
|
109
|
+
/**
|
|
110
|
+
* The resolved k of the k-of-n fallback leaf: the advertised
|
|
111
|
+
* {@link fallbackThreshold}, or n-1 (floored at 1) when unadvertised, where n is
|
|
112
|
+
* the current cohort size. This is the value the beacon address commits to and
|
|
113
|
+
* the spend builders must reproduce. Returns 0 before any cohort keys are set.
|
|
114
|
+
*/
|
|
115
|
+
get effectiveFallbackThreshold(): number;
|
|
116
|
+
/**
|
|
117
|
+
* Computes the Taproot beacon address from the cohort keys and recovery params.
|
|
118
|
+
*
|
|
119
|
+
* The output's key path is the n-of-n MuSig2 aggregate of the cohort keys; its
|
|
120
|
+
* script path is the recovery tree (a CSV recovery leaf so a missing signer
|
|
121
|
+
* cannot permanently lock the UTXO). Sets `internalKey`, `tapMerkleRoot`, and
|
|
122
|
+
* the `tapTweak` the MuSig2 session must apply for the key-path spend.
|
|
123
|
+
*
|
|
124
|
+
* The tweak is derived from the Merkle root the address was built with (read
|
|
125
|
+
* back from the payment), never recomputed by hand, so the MuSig2 key-path
|
|
126
|
+
* signature is guaranteed to validate against the funded address.
|
|
127
|
+
*/
|
|
128
|
+
computeBeaconAddress(): string;
|
|
129
|
+
/**
|
|
130
|
+
* Validates that the participant's key is in the cohort and the beacon address
|
|
131
|
+
* matches the locally-computed one. Used by participants to verify cohort ready
|
|
132
|
+
* messages from the service.
|
|
133
|
+
*/
|
|
134
|
+
validateMembership(participantPkHex: string, cohortKeysHex: Array<string>, expectedBeaconAddress: string): void;
|
|
135
|
+
/**
|
|
136
|
+
* Returns the position of a participant's public key in the sorted
|
|
137
|
+
* {@link cohortKeys} array, or -1 if the participant is not in the cohort.
|
|
138
|
+
* Required by MuSig2 partial-sig verification which indexes by signer position.
|
|
139
|
+
*/
|
|
140
|
+
indexOfParticipant(did: string): number;
|
|
141
|
+
addUpdate(participantDid: string, signedUpdate: SignedBTCR2Update): void;
|
|
142
|
+
/**
|
|
143
|
+
* Record that a participant declined to submit an update this round
|
|
144
|
+
* (cooperative non-inclusion). The member stays in the cohort and still signs.
|
|
145
|
+
*/
|
|
146
|
+
addNonInclusion(participantDid: string): void;
|
|
147
|
+
hasAllUpdates(): boolean;
|
|
148
|
+
/**
|
|
149
|
+
* True when every participant has responded for this round, either with an
|
|
150
|
+
* update or with an explicit non-inclusion. This is the aggregation gate when
|
|
151
|
+
* non-inclusion is in play; it generalizes {@link hasAllUpdates} the same way
|
|
152
|
+
* {@link hasAllValidationResponses} generalizes a unanimous ack.
|
|
153
|
+
*/
|
|
154
|
+
hasAllResponses(): boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Builds a CAS Announcement Map from collected updates.
|
|
157
|
+
* Maps each participant DID to base64url canonical hash of their signed update.
|
|
158
|
+
* Computes signal bytes as SHA-256 of canonicalized announcement.
|
|
159
|
+
*
|
|
160
|
+
* Members who declined (cooperative non-inclusion) are naturally absent from
|
|
161
|
+
* the map: the body iterates {@link pendingUpdates}, which never holds a
|
|
162
|
+
* decliner. Absence from the map is exactly the CAS non-inclusion signal.
|
|
163
|
+
*/
|
|
164
|
+
buildCASAnnouncement(): CASAnnouncementMap;
|
|
165
|
+
/**
|
|
166
|
+
* Builds an SMT tree with one leaf per participant.
|
|
167
|
+
*
|
|
168
|
+
* A member who submitted an update gets an inclusion leaf
|
|
169
|
+
* (SHA-256(SHA-256(nonce) || SHA-256(update))); a member who declined gets a
|
|
170
|
+
* non-inclusion leaf (SHA-256(SHA-256(nonce)), the `signedUpdate` entry field
|
|
171
|
+
* omitted). The cohort mints each member's nonce and returns it inside that
|
|
172
|
+
* member's serialized proof, so a decliner can self-validate its own
|
|
173
|
+
* non-inclusion slot and the resolver can recompute the leaf. Stores
|
|
174
|
+
* per-participant proofs and the SMT root as signalBytes.
|
|
175
|
+
*/
|
|
176
|
+
buildSMTTree(): Map<string, SerializedSMTProof>;
|
|
177
|
+
addValidation(participantDid: string, approved: boolean): void;
|
|
178
|
+
/**
|
|
179
|
+
* True when every participant has either approved or rejected the aggregated data.
|
|
180
|
+
*/
|
|
181
|
+
hasAllValidationResponses(): boolean;
|
|
182
|
+
/**
|
|
183
|
+
* True when all participants approved. Note: differs from {@link hasAllValidationResponses},
|
|
184
|
+
* this returns false if any participant rejected, even if all responses are in.
|
|
185
|
+
*/
|
|
186
|
+
isFullyValidated(): boolean;
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=cohort.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cohort.d.ts","sourceRoot":"","sources":["../../src/cohort.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAa,MAAM,gB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AAC,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,iBAAiB,GAAG,IAAI;IAU/E;;;OAGG;IACI,eAAe,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI;IAkB7C,aAAa,IAAI,OAAO;IAI/B;;;;;OAKG;IACI,eAAe,IAAI,OAAO;IAIjC;;;;;;;;OAQG;IACI,oBAAoB,IAAI,kBAAkB;IAgBjD;;;;;;;;;;OAUG;IACI,YAAY,IAAI,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC;IAkC/C,aAAa,CAAC,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,IAAI;IAcrE;;OAEG;IACI,yBAAyB,IAAI,OAAO;IAI3C;;;OAGG;IACI,gBAAgB,IAAI,OAAO;CAInC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cohort conditions: the constraints an Aggregation Service advertises for a
|
|
3
|
+
* cohort (did:btcr2 spec, "Step 1: Create Aggregation Cohort"). See ADR 039.
|
|
4
|
+
*
|
|
5
|
+
* The spec frames these as an optional menu ("the Aggregation Service can define
|
|
6
|
+
* conditions such as ..."), so only `beaconType` and `minParticipants` are
|
|
7
|
+
* required here; every other condition is optional and, when absent, means
|
|
8
|
+
* unconstrained.
|
|
9
|
+
*
|
|
10
|
+
* Enforcement is staged (ADR 039): `beaconType` and the participant bounds are
|
|
11
|
+
* enforced by the state machine now; DIDs-per-participant, timing/cadence, and
|
|
12
|
+
* the pending-update trigger are modeled and advertised here but enforced when
|
|
13
|
+
* the multi-cohort (AGG-4) and non-inclusion (AGG-5) tracks land. The two cost
|
|
14
|
+
* conditions are advertised metadata only - the protocol performs no payment or
|
|
15
|
+
* settlement (consistent with ADR 008).
|
|
16
|
+
*/
|
|
17
|
+
import type { FundingModel } from './recovery-policy.js';
|
|
18
|
+
/** Beacon types that support aggregation (singleton is single-party only, per ADR 037). */
|
|
19
|
+
export declare const KNOWN_BEACON_TYPES: readonly ["CASBeacon", "SMTBeacon"];
|
|
20
|
+
/** Funding models an operator may advertise. Only 'operator-funded' is implemented (ADR 042). */
|
|
21
|
+
export declare const KNOWN_FUNDING_MODELS: readonly ["operator-funded", "participant-funded"];
|
|
22
|
+
/**
|
|
23
|
+
* An advertised price. `unit` is operator-defined (the spec does not specify a
|
|
24
|
+
* currency); `basis` distinguishes a per-DID from a per-participant charge for
|
|
25
|
+
* "cost per announcement". Advertised only - never settled by the protocol.
|
|
26
|
+
*/
|
|
27
|
+
export interface CohortCost {
|
|
28
|
+
amount: number;
|
|
29
|
+
unit: string;
|
|
30
|
+
basis?: 'per-did' | 'per-participant';
|
|
31
|
+
}
|
|
32
|
+
/** The seven spec cohort conditions. Only beaconType + minParticipants are required. */
|
|
33
|
+
export interface CohortConditions {
|
|
34
|
+
/** 1. Beacon mechanism: 'CASBeacon' or 'SMTBeacon'. Enforced. */
|
|
35
|
+
beaconType: string;
|
|
36
|
+
/** 2. Lower bound on cohort size. Enforced (finalize floor). */
|
|
37
|
+
minParticipants: number;
|
|
38
|
+
/** 2. Upper bound on cohort size. Enforced (accept/finalize ceiling). */
|
|
39
|
+
maxParticipants?: number;
|
|
40
|
+
/** 3. Lower bound on DIDs a participant may register. Advertised; enforcement staged (AGG-5). */
|
|
41
|
+
minDidsPerParticipant?: number;
|
|
42
|
+
/** 3. Upper bound on DIDs a participant may register. Advertised; enforcement staged (AGG-5). */
|
|
43
|
+
maxDidsPerParticipant?: number;
|
|
44
|
+
/** 4. One-time enrollment price. Advertised only - no settlement. */
|
|
45
|
+
costOfEnrollment?: CohortCost;
|
|
46
|
+
/** 5. Recurring per-announcement price. Advertised only - no settlement. */
|
|
47
|
+
costPerAnnouncement?: CohortCost;
|
|
48
|
+
/** 6. Floor on time between announcements (seconds). Advertised; enforcement staged (AGG-4/5). */
|
|
49
|
+
minSecondsBetweenAnnouncements?: number;
|
|
50
|
+
/** 6. Ceiling on time between announcements (seconds). Advertised; enforcement staged - generalizes the ADR 027 Cohort TTL. */
|
|
51
|
+
maxSecondsBetweenAnnouncements?: number;
|
|
52
|
+
/** 7. Pending-update count that triggers an announcement. Advertised; enforcement staged (AGG-5) - generalizes hasAllUpdates(). */
|
|
53
|
+
pendingUpdateTrigger?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Who funds the beacon UTXO and holds the recovery path. Defaults to
|
|
56
|
+
* 'operator-funded' when absent. See ADR 042.
|
|
57
|
+
*/
|
|
58
|
+
fundingModel?: FundingModel;
|
|
59
|
+
/**
|
|
60
|
+
* Operator recovery key, x-only (64-character hex / 32 bytes). The beacon
|
|
61
|
+
* output commits to a CSV recovery leaf keyed to this key, so a missing signer
|
|
62
|
+
* can never permanently lock the funded UTXO. Required (ADR 042).
|
|
63
|
+
*/
|
|
64
|
+
recoveryKey: string;
|
|
65
|
+
/**
|
|
66
|
+
* Relative-timelock (BIP-68 nSequence, in blocks) before the recovery leaf is
|
|
67
|
+
* spendable. Required, >= 1 (ADR 042).
|
|
68
|
+
*/
|
|
69
|
+
recoverySequence: number;
|
|
70
|
+
/**
|
|
71
|
+
* Number of signers (k) the k-of-n fallback leaf requires, so any k cohort
|
|
72
|
+
* members can still announce when the optimistic n-of-n key path stalls
|
|
73
|
+
* (graceful liveness, ADR 042). Optional: when absent it defaults to n-1 at
|
|
74
|
+
* keygen, where n is the finalized participant count. When advertised it must
|
|
75
|
+
* be an integer >= 1 (and <= maxParticipants when that is set); the upper bound
|
|
76
|
+
* against the actual cohort size n is enforced at keygen.
|
|
77
|
+
*/
|
|
78
|
+
fallbackThreshold?: number;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Validate a set of cohort conditions. Returns a list of human-readable problems
|
|
82
|
+
* (empty when valid) so the caller can decide how to surface them. Used by
|
|
83
|
+
* `createCohort()` to fail fast instead of discovering invalidity at finalize.
|
|
84
|
+
*/
|
|
85
|
+
export declare function validateCohortConditions(c: CohortConditions): string[];
|
|
86
|
+
//# sourceMappingURL=conditions.d.ts.map
|
|
@@ -0,0 +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,wBAAwB,CAAC,CAAC,EAAE,gBAAgB,GAAG,MAAM,EAAE,CAqDtE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MethodError } from '@did-btcr2/common';
|
|
2
|
+
export declare class AggregationServiceError extends MethodError {
|
|
3
|
+
constructor(message: string, type?: string, data?: Record<string, any>);
|
|
4
|
+
}
|
|
5
|
+
export declare class AggregationParticipantError extends MethodError {
|
|
6
|
+
constructor(message: string, type?: string, data?: Record<string, any>);
|
|
7
|
+
}
|
|
8
|
+
export declare class AggregationCohortError extends MethodError {
|
|
9
|
+
constructor(message: string, type?: string, data?: Record<string, any>);
|
|
10
|
+
}
|
|
11
|
+
export declare class SigningSessionError extends MethodError {
|
|
12
|
+
constructor(message: string, type?: string, data?: Record<string, any>);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,qBAAa,uBAAwB,SAAQ,WAAW;gBAC1C,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAAkC,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAGlG;AAED,qBAAa,2BAA4B,SAAQ,WAAW;gBAC9C,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAAsC,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAGtG;AAED,qBAAa,sBAAuB,SAAQ,WAAW;gBACzC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAAiC,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAGjG;AAED,qBAAa,mBAAoB,SAAQ,WAAW;gBACtC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAA8B,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAG9F"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fallback spend builder for aggregate beacon outputs.
|
|
3
|
+
*
|
|
4
|
+
* An aggregate beacon UTXO is a Taproot output whose key path is the cohort's
|
|
5
|
+
* n-of-n MuSig2 aggregate key and whose script path carries a k-of-n fallback
|
|
6
|
+
* leaf (`p2tr_ms` CHECKSIGADD) plus a CSV recovery leaf (see
|
|
7
|
+
* {@link ./recovery-policy.ts} and ADR 042). When the optimistic n-of-n key path
|
|
8
|
+
* stalls (a missing or defecting signer), the cohort can still push the SAME
|
|
9
|
+
* announcement transaction through the fallback leaf with any k members'
|
|
10
|
+
* signatures, instead of abandoning the round or waiting out the recovery
|
|
11
|
+
* timelock.
|
|
12
|
+
*
|
|
13
|
+
* Unlike the MuSig2 key path, the fallback is a plain k-of-n script-path spend:
|
|
14
|
+
* each signer produces a standalone BIP-340 signature over the script-path
|
|
15
|
+
* sighash (no nonce round), and the coordinator assembles k of them into the
|
|
16
|
+
* witness. The coordinator never holds a participant secret - it injects the
|
|
17
|
+
* collected signatures and finalizes.
|
|
18
|
+
*
|
|
19
|
+
* This module is pure with respect to the network: it takes the beacon
|
|
20
|
+
* transaction, the cohort and recovery parameters, the spent output, and the
|
|
21
|
+
* collected signatures, and returns a finalized {@link Transaction}.
|
|
22
|
+
* Broadcasting is the caller's concern.
|
|
23
|
+
*/
|
|
24
|
+
import type { Transaction } from '@scure/btc-signer';
|
|
25
|
+
import type { FundingModel } from './recovery-policy.js';
|
|
26
|
+
/** A single member's standalone signature over the fallback script-path sighash. */
|
|
27
|
+
export interface FallbackSignature {
|
|
28
|
+
/** Signer's x-only public key (32 bytes). Must be one of the cohort's keys. */
|
|
29
|
+
pubKey: Uint8Array;
|
|
30
|
+
/** 64-byte BIP-340 Schnorr signature over the script-path sighash. */
|
|
31
|
+
signature: Uint8Array;
|
|
32
|
+
}
|
|
33
|
+
/** Inputs to {@link buildFallbackSpend}. */
|
|
34
|
+
export interface FallbackSpendParams {
|
|
35
|
+
/**
|
|
36
|
+
* The beacon announcement transaction to finalize. Input {@link inputIndex}
|
|
37
|
+
* spends the beacon UTXO; its key-path witness must not be set (the fallback
|
|
38
|
+
* assembles a script-path witness instead).
|
|
39
|
+
*/
|
|
40
|
+
pendingTx: Transaction;
|
|
41
|
+
/** Index of the beacon input within {@link pendingTx}. Defaults to 0. */
|
|
42
|
+
inputIndex?: number;
|
|
43
|
+
/**
|
|
44
|
+
* The cohort's participant public keys (compressed secp256k1, 33 bytes).
|
|
45
|
+
* Sorted internally per BIP-327 so the reconstructed tree matches the funded
|
|
46
|
+
* output.
|
|
47
|
+
*/
|
|
48
|
+
cohortKeys: Uint8Array[];
|
|
49
|
+
/**
|
|
50
|
+
* The advertised k of the k-of-n fallback leaf, or omit for the cohort's n-1
|
|
51
|
+
* default. Resolved against `cohortKeys.length` exactly as the cohort does.
|
|
52
|
+
*/
|
|
53
|
+
fallbackThreshold?: number;
|
|
54
|
+
/** Operator recovery key, x-only (32 bytes). Needed to reconstruct the script tree. */
|
|
55
|
+
recoveryKey: Uint8Array;
|
|
56
|
+
/** Relative-timelock (BIP-68) the recovery leaf enforces. Needed to reconstruct the script tree. */
|
|
57
|
+
recoverySequence: number;
|
|
58
|
+
/** Funding model governing the leaves. Defaults to 'operator-funded'. */
|
|
59
|
+
fundingModel?: FundingModel;
|
|
60
|
+
/** Bitcoin network name (bitcoin/mainnet, mutinynet, signet, testnet, regtest). */
|
|
61
|
+
network: string;
|
|
62
|
+
/** scriptPubKey of the beacon UTXO being spent. Must equal the reconstructed tree output script. */
|
|
63
|
+
prevOutScript: Uint8Array;
|
|
64
|
+
/** Value of the beacon UTXO in satoshis. */
|
|
65
|
+
prevOutValue: bigint;
|
|
66
|
+
/**
|
|
67
|
+
* Standalone signatures collected from cohort members. At least
|
|
68
|
+
* {@link fallbackThreshold} valid, distinct-by-key signatures are required;
|
|
69
|
+
* exactly k are injected (a k-of-n CHECKSIGADD leaf demands exactly k).
|
|
70
|
+
*/
|
|
71
|
+
signatures: FallbackSignature[];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Compute the BIP-341 script-path sighash a cohort member must sign to authorize
|
|
75
|
+
* the fallback spend. The leaf is the k-of-n fallback leaf; signers produce a
|
|
76
|
+
* standalone BIP-340 signature over this digest with SIGHASH_DEFAULT.
|
|
77
|
+
*/
|
|
78
|
+
export declare function fallbackSighash(tx: Transaction, inputIndex: number, prevOutScript: Uint8Array, prevOutValue: bigint, fallbackLeafScript: Uint8Array): Uint8Array;
|
|
79
|
+
/**
|
|
80
|
+
* Assemble and finalize a k-of-n fallback spend of an aggregate beacon UTXO.
|
|
81
|
+
*
|
|
82
|
+
* Reconstructs the funded Taproot output (MuSig2 internal key + fallback/recovery
|
|
83
|
+
* script tree), verifies each collected signature against the script-path
|
|
84
|
+
* sighash and a cohort key, injects exactly k distinct valid signatures into the
|
|
85
|
+
* fallback leaf, and finalizes the witness. The returned transaction is the same
|
|
86
|
+
* announcement the optimistic path would have produced, signed via the script
|
|
87
|
+
* path instead of the key path.
|
|
88
|
+
*
|
|
89
|
+
* @throws {AggregationCohortError} when there are no cohort keys, the spent
|
|
90
|
+
* script does not match the reconstructed tree output, or fewer than k valid
|
|
91
|
+
* distinct signatures were supplied.
|
|
92
|
+
*/
|
|
93
|
+
export declare function buildFallbackSpend(params: FallbackSpendParams): Transaction;
|
|
94
|
+
//# sourceMappingURL=fallback-spend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fallback-spend.d.ts","sourceRoot":"","sources":["../../src/fallback-spend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAIpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAUzD,oFAAoF;AACpF,MAAM,WAAW,iBAAiB;IAChC,+EAA+E;IAC/E,MAAM,EAAE,UAAU,CAAC;IACnB,sEAAsE;IACtE,SAAS,EAAE,UAAU,CAAC;CACvB;AAED,4CAA4C;AAC5C,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,SAAS,EAAE,WAAW,CAAC;IACvB,yEAAyE;IACzE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,UAAU,EAAE,UAAU,EAAE,CAAC;IACzB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,uFAAuF;IACvF,WAAW,EAAE,UAAU,CAAC;IACxB,oGAAoG;IACpG,gBAAgB,EAAE,MAAM,CAAC;IACzB,yEAAyE;IACzE,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,mFAAmF;IACnF,OAAO,EAAE,MAAM,CAAC;IAChB,oGAAoG;IACpG,aAAa,EAAE,UAAU,CAAC;IAC1B,4CAA4C;IAC5C,YAAY,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,UAAU,EAAE,iBAAiB,EAAE,CAAC;CACjC;AAMD;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,EAAE,EAAE,WAAW,EACf,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,UAAU,EACzB,YAAY,EAAE,MAAM,EACpB,kBAAkB,EAAE,UAAU,GAC7B,UAAU,CAUZ;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,mBAAmB,GAAG,WAAW,CA4F3E"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from './service.js';
|
|
2
|
+
export * from './participant.js';
|
|
3
|
+
export * from './signer.js';
|
|
4
|
+
export * from './conditions.js';
|
|
5
|
+
export * from './recovery-policy.js';
|
|
6
|
+
export * from './recovery-spend.js';
|
|
7
|
+
export * from './fallback-spend.js';
|
|
8
|
+
export * from './cohort.js';
|
|
9
|
+
export * from './signing-session.js';
|
|
10
|
+
export * from './phases.js';
|
|
11
|
+
export * from './errors.js';
|
|
12
|
+
export * from './beacon-strategy.js';
|
|
13
|
+
export * from './logger.js';
|
|
14
|
+
export * from './messages/index.js';
|
|
15
|
+
export * from './transport/index.js';
|
|
16
|
+
export * from './runner/index.js';
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAG5B,cAAc,qBAAqB,CAAC;AAGpC,cAAc,sBAAsB,CAAC;AAGrC,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal injectable logger for the aggregation subsystem.
|
|
3
|
+
*
|
|
4
|
+
* Each runner and transport adapter accepts a `Logger` option; the default is
|
|
5
|
+
* {@link CONSOLE_LOGGER}, which forwards to `console.*`. Pass
|
|
6
|
+
* {@link SILENT_LOGGER} to suppress output (useful for tests) or a custom
|
|
7
|
+
* implementation to route logs to pino, winston, Sentry, etc.
|
|
8
|
+
*
|
|
9
|
+
* The interface is intentionally small: we don't want production code taking
|
|
10
|
+
* a hard dependency on any specific logger library.
|
|
11
|
+
*/
|
|
12
|
+
export interface Logger {
|
|
13
|
+
debug(message: string, ...args: unknown[]): void;
|
|
14
|
+
info(message: string, ...args: unknown[]): void;
|
|
15
|
+
warn(message: string, ...args: unknown[]): void;
|
|
16
|
+
error(message: string, ...args: unknown[]): void;
|
|
17
|
+
}
|
|
18
|
+
/** Console-backed logger. Default for runners and transports. */
|
|
19
|
+
export declare const CONSOLE_LOGGER: Logger;
|
|
20
|
+
/** No-op logger. Useful for tests and production environments with own logging pipeline. */
|
|
21
|
+
export declare const SILENT_LOGGER: Logger;
|
|
22
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACjD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CAClD;AAED,iEAAiE;AACjE,eAAO,MAAM,cAAc,EAAE,MAK5B,CAAC;AAEF,4FAA4F;AAC5F,eAAO,MAAM,aAAa,EAAE,MAK3B,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { CohortConditions } from '../conditions.js';
|
|
2
|
+
/**
|
|
3
|
+
* Current on-the-wire protocol version.
|
|
4
|
+
*
|
|
5
|
+
* Receivers reject messages with an unknown (mismatched) version. Bumping this
|
|
6
|
+
* requires coordinated updates across all participants and any intermediate
|
|
7
|
+
* relays that inspect message content.
|
|
8
|
+
*/
|
|
9
|
+
export declare const AGGREGATION_WIRE_VERSION = 1;
|
|
10
|
+
export type BaseBody = Partial<CohortConditions> & {
|
|
11
|
+
cohortId: string;
|
|
12
|
+
network?: string;
|
|
13
|
+
participantPk?: Uint8Array;
|
|
14
|
+
beaconAddress?: string;
|
|
15
|
+
cohortKeys?: Array<Uint8Array>;
|
|
16
|
+
sessionId?: string;
|
|
17
|
+
aggregatedNonce?: Uint8Array;
|
|
18
|
+
nonceContribution?: Uint8Array;
|
|
19
|
+
partialSignature?: Uint8Array;
|
|
20
|
+
/** Fallback (k-of-n script-path) leaf script, hex. Carried on FALLBACK_AUTHORIZATION_REQUEST. */
|
|
21
|
+
fallbackLeafScriptHex?: string;
|
|
22
|
+
/** Signer's x-only key for a fallback signature (which CHECKSIGADD slot it satisfies). */
|
|
23
|
+
signerPk?: Uint8Array;
|
|
24
|
+
/** A member's standalone BIP-340 fallback script-path signature (64 bytes). */
|
|
25
|
+
fallbackSignature?: Uint8Array;
|
|
26
|
+
pendingTx?: string;
|
|
27
|
+
/** Hex-encoded scriptPubKey of the UTXO being spent. Required for BIP-341 sighash. */
|
|
28
|
+
prevOutScriptHex?: string;
|
|
29
|
+
prevOutValue?: string;
|
|
30
|
+
communicationPk?: Uint8Array;
|
|
31
|
+
data?: string;
|
|
32
|
+
signedUpdate?: Record<string, unknown>;
|
|
33
|
+
casAnnouncement?: Record<string, string>;
|
|
34
|
+
smtProof?: Record<string, unknown>;
|
|
35
|
+
signalBytesHex?: string;
|
|
36
|
+
approved?: boolean;
|
|
37
|
+
};
|
|
38
|
+
export type Base = {
|
|
39
|
+
type: string;
|
|
40
|
+
version?: number;
|
|
41
|
+
to?: string;
|
|
42
|
+
from: string;
|
|
43
|
+
body?: BaseBody;
|
|
44
|
+
};
|
|
45
|
+
export declare class BaseMessage {
|
|
46
|
+
type: string;
|
|
47
|
+
version: number;
|
|
48
|
+
to?: string;
|
|
49
|
+
from: string;
|
|
50
|
+
body?: BaseBody;
|
|
51
|
+
constructor({ type, version, to, from, body }: Base);
|
|
52
|
+
/**
|
|
53
|
+
* Converts a BaseMessage to a JSON object.
|
|
54
|
+
* @returns {Base} The JSON representation of the BaseMessage.
|
|
55
|
+
*/
|
|
56
|
+
toJSON(): Base;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/messages/base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAK1C,MAAM,MAAM,QAAQ,GAAG,OAAO,CAAC,gBAAgB,CAAC,GAAG;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,UAAU,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,UAAU,CAAC;IAC7B,iBAAiB,CAAC,EAAE,UAAU,CAAC;IAC/B,gBAAgB,CAAC,EAAE,UAAU,CAAC;IAC9B,iGAAiG;IACjG,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,0FAA0F;IAC1F,QAAQ,CAAC,EAAE,UAAU,CAAC;IACtB,+EAA+E;IAC/E,iBAAiB,CAAC,EAAE,UAAU,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sFAAsF;IACtF,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,UAAU,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA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