@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,132 @@
|
|
|
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 { getNetwork } from '@did-btcr2/bitcoin';
|
|
25
|
+
import { schnorr } from '@noble/curves/secp256k1.js';
|
|
26
|
+
import { SigHash, p2tr } from '@scure/btc-signer';
|
|
27
|
+
import { keyAggExport, keyAggregate, sortKeys } from '@scure/btc-signer/musig2';
|
|
28
|
+
import { AggregationCohortError } from './errors.js';
|
|
29
|
+
import { DEFAULT_FUNDING_MODEL, TAPROOT_LEAF_VERSION, buildFallbackLeaf, buildRecoveryLeaves, resolveFallbackThreshold, tapLeafHash, } from './recovery-policy.js';
|
|
30
|
+
function bytesEqual(a, b) {
|
|
31
|
+
return a.length === b.length && a.every((x, i) => x === b[i]);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Compute the BIP-341 script-path sighash a cohort member must sign to authorize
|
|
35
|
+
* the fallback spend. The leaf is the k-of-n fallback leaf; signers produce a
|
|
36
|
+
* standalone BIP-340 signature over this digest with SIGHASH_DEFAULT.
|
|
37
|
+
*/
|
|
38
|
+
export function fallbackSighash(tx, inputIndex, prevOutScript, prevOutValue, fallbackLeafScript) {
|
|
39
|
+
return tx.preimageWitnessV1(inputIndex, [prevOutScript], SigHash.DEFAULT, [prevOutValue], undefined, fallbackLeafScript, TAPROOT_LEAF_VERSION);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Assemble and finalize a k-of-n fallback spend of an aggregate beacon UTXO.
|
|
43
|
+
*
|
|
44
|
+
* Reconstructs the funded Taproot output (MuSig2 internal key + fallback/recovery
|
|
45
|
+
* script tree), verifies each collected signature against the script-path
|
|
46
|
+
* sighash and a cohort key, injects exactly k distinct valid signatures into the
|
|
47
|
+
* fallback leaf, and finalizes the witness. The returned transaction is the same
|
|
48
|
+
* announcement the optimistic path would have produced, signed via the script
|
|
49
|
+
* path instead of the key path.
|
|
50
|
+
*
|
|
51
|
+
* @throws {AggregationCohortError} when there are no cohort keys, the spent
|
|
52
|
+
* script does not match the reconstructed tree output, or fewer than k valid
|
|
53
|
+
* distinct signatures were supplied.
|
|
54
|
+
*/
|
|
55
|
+
export function buildFallbackSpend(params) {
|
|
56
|
+
const { pendingTx, cohortKeys, recoveryKey, recoverySequence, fundingModel, network, prevOutScript, prevOutValue, signatures, } = params;
|
|
57
|
+
const inputIndex = params.inputIndex ?? 0;
|
|
58
|
+
if (cohortKeys.length === 0) {
|
|
59
|
+
throw new AggregationCohortError('Cannot build fallback spend: no cohort keys.', 'NO_COHORT_KEYS');
|
|
60
|
+
}
|
|
61
|
+
// Resolve k the same way the cohort did, so the reconstructed leaf matches.
|
|
62
|
+
const fallbackThreshold = resolveFallbackThreshold(params.fallbackThreshold, cohortKeys.length);
|
|
63
|
+
// Reconstruct the funded output the same way the cohort derived its address.
|
|
64
|
+
const internalKey = keyAggExport(keyAggregate(sortKeys(cohortKeys)));
|
|
65
|
+
const leaves = buildRecoveryLeaves(fundingModel ?? DEFAULT_FUNDING_MODEL, {
|
|
66
|
+
recoveryKey, recoverySequence, cohortKeys, fallbackThreshold,
|
|
67
|
+
});
|
|
68
|
+
const net = getNetwork(network);
|
|
69
|
+
// allowUnknownOutputs: the CSV recovery leaf is a custom script (see cohort.ts).
|
|
70
|
+
const payment = p2tr(internalKey, leaves, net, true);
|
|
71
|
+
// The output we are spending must be the cohort's funded beacon output; if the
|
|
72
|
+
// reconstructed tree script differs, the witness would not match the chain.
|
|
73
|
+
if (!bytesEqual(payment.script, prevOutScript)) {
|
|
74
|
+
throw new AggregationCohortError('Reconstructed beacon output script does not match the spent prevout script.', 'PREVOUT_SCRIPT_MISMATCH');
|
|
75
|
+
}
|
|
76
|
+
const fallbackLeaf = buildFallbackLeaf({ cohortKeys, fallbackThreshold });
|
|
77
|
+
// Locate the fallback leaf's tapLeafScript entry: each entry is
|
|
78
|
+
// [controlBlock, script || leafVersion]; strip the trailing version byte to
|
|
79
|
+
// compare the script.
|
|
80
|
+
const leafEntry = payment.tapLeafScript?.find(([, scriptVer]) => {
|
|
81
|
+
const script = scriptVer.slice(0, scriptVer.length - 1);
|
|
82
|
+
return bytesEqual(script, fallbackLeaf);
|
|
83
|
+
});
|
|
84
|
+
if (!leafEntry) {
|
|
85
|
+
throw new AggregationCohortError('Could not locate the fallback leaf in the reconstructed beacon output.', 'FALLBACK_LEAF_NOT_FOUND');
|
|
86
|
+
}
|
|
87
|
+
// Validate the collected signatures against the script-path sighash. The leaf
|
|
88
|
+
// is keyed by x-only cohort keys, so a valid signature must verify against one
|
|
89
|
+
// of them. Keep only distinct, valid signatures (first occurrence per key).
|
|
90
|
+
const cohortXOnly = sortKeys(cohortKeys).map(k => k.slice(1));
|
|
91
|
+
const tx = pendingTx;
|
|
92
|
+
const sighash = fallbackSighash(tx, inputIndex, prevOutScript, prevOutValue, fallbackLeaf);
|
|
93
|
+
const leafHash = tapLeafHash(fallbackLeaf);
|
|
94
|
+
const accepted = new Map(); // x-only hex to signature
|
|
95
|
+
for (const { pubKey, signature } of signatures) {
|
|
96
|
+
if (pubKey.length !== 32 || signature.length !== 64)
|
|
97
|
+
continue;
|
|
98
|
+
const isCohortKey = cohortXOnly.some(k => bytesEqual(k, pubKey));
|
|
99
|
+
if (!isCohortKey)
|
|
100
|
+
continue;
|
|
101
|
+
const hex = Array.from(pubKey, b => b.toString(16).padStart(2, '0')).join('');
|
|
102
|
+
if (accepted.has(hex))
|
|
103
|
+
continue;
|
|
104
|
+
let ok = false;
|
|
105
|
+
try {
|
|
106
|
+
ok = schnorr.verify(signature, sighash, pubKey);
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
ok = false;
|
|
110
|
+
}
|
|
111
|
+
if (ok)
|
|
112
|
+
accepted.set(hex, signature);
|
|
113
|
+
}
|
|
114
|
+
if (accepted.size < fallbackThreshold) {
|
|
115
|
+
throw new AggregationCohortError(`Not enough valid fallback signatures: have ${accepted.size}, need ${fallbackThreshold}.`, 'NOT_ENOUGH_FALLBACK_SIGNATURES', { have: accepted.size, need: fallbackThreshold });
|
|
116
|
+
}
|
|
117
|
+
// A k-of-n CHECKSIGADD leaf demands EXACTLY k satisfied signatures (the final
|
|
118
|
+
// <k> NUMEQUAL fails if the running count differs), so inject exactly k.
|
|
119
|
+
const chosen = cohortXOnly
|
|
120
|
+
.filter(k => accepted.has(Array.from(k, b => b.toString(16).padStart(2, '0')).join('')))
|
|
121
|
+
.slice(0, fallbackThreshold);
|
|
122
|
+
tx.updateInput(inputIndex, {
|
|
123
|
+
tapLeafScript: [leafEntry],
|
|
124
|
+
tapScriptSig: chosen.map(pubKey => {
|
|
125
|
+
const hex = Array.from(pubKey, b => b.toString(16).padStart(2, '0')).join('');
|
|
126
|
+
return [{ pubKey, leafHash }, accepted.get(hex)];
|
|
127
|
+
}),
|
|
128
|
+
});
|
|
129
|
+
tx.finalize();
|
|
130
|
+
return tx;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=fallback-spend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fallback-spend.js","sourceRoot":"","sources":["../../src/fallback-spend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,wBAAwB,EACxB,WAAW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,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,iBAAiB,EAAE,CACnF,CAAC;IACJ,CAAC;IAED,8EAA8E;IAC9E,yEAAyE;IACzE,MAAM,MAAM,GAAG,WAAW;SACvB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;SACvF,KAAK,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC;IAE/B,EAAE,CAAC,WAAW,CAAC,UAAU,EAAE;QACzB,aAAa,EAAG,CAAE,SAAS,CAAE;QAC7B,YAAY,EAAI,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;YAClC,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC9E,OAAO,CAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAE,CAAE,CAAC;QACtD,CAAC,CAAC;KACH,CAAC,CAAC;IACH,EAAE,CAAC,QAAQ,EAAE,CAAC;IACd,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// State machines + core data
|
|
2
|
+
export * from './service.js';
|
|
3
|
+
export * from './participant.js';
|
|
4
|
+
export * from './signer.js';
|
|
5
|
+
export * from './conditions.js';
|
|
6
|
+
export * from './recovery-policy.js';
|
|
7
|
+
export * from './recovery-spend.js';
|
|
8
|
+
export * from './fallback-spend.js';
|
|
9
|
+
export * from './cohort.js';
|
|
10
|
+
export * from './signing-session.js';
|
|
11
|
+
export * from './phases.js';
|
|
12
|
+
export * from './errors.js';
|
|
13
|
+
export * from './beacon-strategy.js';
|
|
14
|
+
export * from './logger.js';
|
|
15
|
+
// Messages
|
|
16
|
+
export * from './messages/index.js';
|
|
17
|
+
// Transport
|
|
18
|
+
export * from './transport/index.js';
|
|
19
|
+
// Runner facades
|
|
20
|
+
export * from './runner/index.js';
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,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;AAE5B,WAAW;AACX,cAAc,qBAAqB,CAAC;AAEpC,YAAY;AACZ,cAAc,sBAAsB,CAAC;AAErC,iBAAiB;AACjB,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Console-backed logger. Default for runners and transports. */
|
|
2
|
+
export const CONSOLE_LOGGER = {
|
|
3
|
+
debug: (msg, ...args) => console.debug(msg, ...args),
|
|
4
|
+
info: (msg, ...args) => console.info(msg, ...args),
|
|
5
|
+
warn: (msg, ...args) => console.warn(msg, ...args),
|
|
6
|
+
error: (msg, ...args) => console.error(msg, ...args),
|
|
7
|
+
};
|
|
8
|
+
/** No-op logger. Useful for tests and production environments with own logging pipeline. */
|
|
9
|
+
export const SILENT_LOGGER = {
|
|
10
|
+
debug: () => { },
|
|
11
|
+
info: () => { },
|
|
12
|
+
warn: () => { },
|
|
13
|
+
error: () => { },
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAkBA,iEAAiE;AACjE,MAAM,CAAC,MAAM,cAAc,GAAW;IACpC,KAAK,EAAG,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;IACrD,IAAI,EAAI,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;IACpD,IAAI,EAAI,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;IACpD,KAAK,EAAG,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;CACtD,CAAC;AAEF,4FAA4F;AAC5F,MAAM,CAAC,MAAM,aAAa,GAAW;IACnC,KAAK,EAAG,GAAG,EAAE,GAAE,CAAC;IAChB,IAAI,EAAI,GAAG,EAAE,GAAE,CAAC;IAChB,IAAI,EAAI,GAAG,EAAE,GAAE,CAAC;IAChB,KAAK,EAAG,GAAG,EAAE,GAAE,CAAC;CACjB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Current on-the-wire protocol version.
|
|
3
|
+
*
|
|
4
|
+
* Receivers reject messages with an unknown (mismatched) version. Bumping this
|
|
5
|
+
* requires coordinated updates across all participants and any intermediate
|
|
6
|
+
* relays that inspect message content.
|
|
7
|
+
*/
|
|
8
|
+
export const AGGREGATION_WIRE_VERSION = 1;
|
|
9
|
+
export class BaseMessage {
|
|
10
|
+
type;
|
|
11
|
+
version;
|
|
12
|
+
to;
|
|
13
|
+
from;
|
|
14
|
+
body;
|
|
15
|
+
constructor({ type, version, to, from, body }) {
|
|
16
|
+
this.type = type;
|
|
17
|
+
this.version = version ?? AGGREGATION_WIRE_VERSION;
|
|
18
|
+
this.to = to;
|
|
19
|
+
this.from = from;
|
|
20
|
+
this.body = body;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Converts a BaseMessage to a JSON object.
|
|
24
|
+
* @returns {Base} The JSON representation of the BaseMessage.
|
|
25
|
+
*/
|
|
26
|
+
toJSON() {
|
|
27
|
+
return {
|
|
28
|
+
type: this.type,
|
|
29
|
+
version: this.version,
|
|
30
|
+
to: this.to,
|
|
31
|
+
from: this.from,
|
|
32
|
+
body: this.body
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/messages/base.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC;AA0C1C,MAAM,OAAO,WAAW;IACf,IAAI,CAAS;IACb,OAAO,CAAS;IAChB,EAAE,CAAU;IACZ,IAAI,CAAS;IACb,IAAI,CAAY;IAEvB,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAQ;QACjD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,wBAAwB,CAAC;QACnD,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;OAGG;IACI,MAAM;QACX,OAAO;YACL,IAAI,EAAM,IAAI,CAAC,IAAI;YACnB,OAAO,EAAG,IAAI,CAAC,OAAO;YACtB,EAAE,EAAQ,IAAI,CAAC,EAAE;YACjB,IAAI,EAAM,IAAI,CAAC,IAAI;YACnB,IAAI,EAAM,IAAI,CAAC,IAAI;SACpB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-message-type body interfaces and a discriminated {@link AggregationMessage}
|
|
3
|
+
* union.
|
|
4
|
+
*
|
|
5
|
+
* {@link BaseBody} remains the superset-of-all-fields body type used by the
|
|
6
|
+
* raw {@link BaseMessage} class (see `base.ts`). The narrow interfaces here
|
|
7
|
+
* describe what each specific message type is *required* to carry and are
|
|
8
|
+
* exposed alongside type guards for consumers who want compile-time narrowing.
|
|
9
|
+
*
|
|
10
|
+
* Guards validate both `type` and the presence of required body fields so they
|
|
11
|
+
* are safe to use on messages that have round-tripped through JSON / a relay.
|
|
12
|
+
*/
|
|
13
|
+
import { KNOWN_FUNDING_MODELS } from '../conditions.js';
|
|
14
|
+
import { MAX_RECOVERY_SEQUENCE } from '../recovery-policy.js';
|
|
15
|
+
import { AGGREGATED_NONCE, AUTHORIZATION_REQUEST, COHORT_ADVERT, COHORT_OPT_IN, COHORT_OPT_IN_ACCEPT, COHORT_READY, DISTRIBUTE_AGGREGATED_DATA, FALLBACK_AUTHORIZATION_REQUEST, FALLBACK_SIGNATURE, NONCE_CONTRIBUTION, SIGNATURE_AUTHORIZATION, SUBMIT_NONINCLUDED, SUBMIT_UPDATE, VALIDATION_ACK, } from './constants.js';
|
|
16
|
+
// ── Type guards ───────────────────────────────────────────────────────────
|
|
17
|
+
// Each guard validates `type` plus required body fields so it's safe to use
|
|
18
|
+
// on messages that have round-tripped through JSON / a relay.
|
|
19
|
+
const hasStr = (b, k) => !!b && typeof b[k] === 'string';
|
|
20
|
+
/** Present, an integer, and >= min. */
|
|
21
|
+
const hasIntMin = (b, k, min) => {
|
|
22
|
+
const v = b ? b[k] : undefined;
|
|
23
|
+
return typeof v === 'number' && Number.isInteger(v) && v >= min;
|
|
24
|
+
};
|
|
25
|
+
/** Absent, or present as an integer >= min. */
|
|
26
|
+
const optIntMin = (b, k, min) => {
|
|
27
|
+
const v = b ? b[k] : undefined;
|
|
28
|
+
return v === undefined || (typeof v === 'number' && Number.isInteger(v) && v >= min);
|
|
29
|
+
};
|
|
30
|
+
/** Present, an integer, and within [min, max] inclusive. */
|
|
31
|
+
const intInRange = (b, k, min, max) => {
|
|
32
|
+
const v = b ? b[k] : undefined;
|
|
33
|
+
return typeof v === 'number' && Number.isInteger(v) && v >= min && v <= max;
|
|
34
|
+
};
|
|
35
|
+
/** Absent, or present as a string in the allowed set. */
|
|
36
|
+
const optStrOneOf = (b, k, allowed) => {
|
|
37
|
+
const v = b ? b[k] : undefined;
|
|
38
|
+
return v === undefined || (typeof v === 'string' && allowed.includes(v));
|
|
39
|
+
};
|
|
40
|
+
const hasBool = (b, k) => !!b && typeof b[k] === 'boolean';
|
|
41
|
+
const hasBytes = (b, k) => !!b && b[k] instanceof Uint8Array;
|
|
42
|
+
const hasBytesArray = (b, k) => {
|
|
43
|
+
const v = b ? b[k] : undefined;
|
|
44
|
+
return Array.isArray(v) && v.every(x => x instanceof Uint8Array);
|
|
45
|
+
};
|
|
46
|
+
export function isCohortAdvertMessage(m) {
|
|
47
|
+
// Range-check the participant bounds so a malformed advert (missing or
|
|
48
|
+
// zero/negative minParticipants) is rejected rather than silently accepted as
|
|
49
|
+
// a zero-floor cohort. The service does the full cross-field validation at
|
|
50
|
+
// createCohort (see validateCohortConditions); here we guard the wire shape.
|
|
51
|
+
return m.type === COHORT_ADVERT
|
|
52
|
+
&& hasStr(m.body, 'cohortId')
|
|
53
|
+
&& hasIntMin(m.body, 'minParticipants', 1)
|
|
54
|
+
&& optIntMin(m.body, 'maxParticipants', 1)
|
|
55
|
+
&& hasStr(m.body, 'beaconType')
|
|
56
|
+
&& hasStr(m.body, 'network')
|
|
57
|
+
// Recovery params are mandatory: a participant must see the recovery terms
|
|
58
|
+
// (key + timelock) before funding the beacon UTXO (ADR 042). recoverySequence
|
|
59
|
+
// is range-checked here because the participant funds based on the advert and
|
|
60
|
+
// does not separately run validateCohortConditions: an out-of-range value
|
|
61
|
+
// (e.g. one with the BIP-68 disable bit set) must be rejected before funding.
|
|
62
|
+
&& hasStr(m.body, 'recoveryKey')
|
|
63
|
+
&& intInRange(m.body, 'recoverySequence', 1, MAX_RECOVERY_SEQUENCE)
|
|
64
|
+
// fundingModel is optional on the wire (absent means the operator-funded
|
|
65
|
+
// default), but when present it must name a known model.
|
|
66
|
+
&& optStrOneOf(m.body, 'fundingModel', KNOWN_FUNDING_MODELS)
|
|
67
|
+
// fallbackThreshold is optional (absent means n-1 at keygen); when present it
|
|
68
|
+
// must be a positive integer. The upper bound against the cohort size is
|
|
69
|
+
// checked when the participant recomputes the beacon address.
|
|
70
|
+
&& optIntMin(m.body, 'fallbackThreshold', 1)
|
|
71
|
+
&& hasBytes(m.body, 'communicationPk');
|
|
72
|
+
}
|
|
73
|
+
export function isCohortOptInMessage(m) {
|
|
74
|
+
return m.type === COHORT_OPT_IN
|
|
75
|
+
&& hasStr(m.body, 'cohortId')
|
|
76
|
+
&& hasBytes(m.body, 'participantPk')
|
|
77
|
+
&& hasBytes(m.body, 'communicationPk');
|
|
78
|
+
}
|
|
79
|
+
export function isCohortOptInAcceptMessage(m) {
|
|
80
|
+
return m.type === COHORT_OPT_IN_ACCEPT && hasStr(m.body, 'cohortId');
|
|
81
|
+
}
|
|
82
|
+
export function isCohortReadyMessage(m) {
|
|
83
|
+
return m.type === COHORT_READY
|
|
84
|
+
&& hasStr(m.body, 'cohortId')
|
|
85
|
+
&& hasStr(m.body, 'beaconAddress')
|
|
86
|
+
&& hasBytesArray(m.body, 'cohortKeys');
|
|
87
|
+
}
|
|
88
|
+
export function isSubmitUpdateMessage(m) {
|
|
89
|
+
return m.type === SUBMIT_UPDATE
|
|
90
|
+
&& hasStr(m.body, 'cohortId')
|
|
91
|
+
&& !!m.body && typeof m.body.signedUpdate === 'object';
|
|
92
|
+
}
|
|
93
|
+
export function isSubmitNonIncludedMessage(m) {
|
|
94
|
+
return m.type === SUBMIT_NONINCLUDED && hasStr(m.body, 'cohortId');
|
|
95
|
+
}
|
|
96
|
+
export function isDistributeAggregatedDataMessage(m) {
|
|
97
|
+
return m.type === DISTRIBUTE_AGGREGATED_DATA
|
|
98
|
+
&& hasStr(m.body, 'cohortId')
|
|
99
|
+
&& hasStr(m.body, 'beaconType')
|
|
100
|
+
&& hasStr(m.body, 'signalBytesHex');
|
|
101
|
+
}
|
|
102
|
+
export function isValidationAckMessage(m) {
|
|
103
|
+
return m.type === VALIDATION_ACK
|
|
104
|
+
&& hasStr(m.body, 'cohortId')
|
|
105
|
+
&& hasBool(m.body, 'approved');
|
|
106
|
+
}
|
|
107
|
+
export function isAuthorizationRequestMessage(m) {
|
|
108
|
+
return m.type === AUTHORIZATION_REQUEST
|
|
109
|
+
&& hasStr(m.body, 'cohortId')
|
|
110
|
+
&& hasStr(m.body, 'sessionId')
|
|
111
|
+
&& hasStr(m.body, 'pendingTx')
|
|
112
|
+
&& hasStr(m.body, 'prevOutScriptHex')
|
|
113
|
+
&& hasStr(m.body, 'prevOutValue');
|
|
114
|
+
}
|
|
115
|
+
export function isNonceContributionMessage(m) {
|
|
116
|
+
return m.type === NONCE_CONTRIBUTION
|
|
117
|
+
&& hasStr(m.body, 'cohortId')
|
|
118
|
+
&& hasStr(m.body, 'sessionId')
|
|
119
|
+
&& hasBytes(m.body, 'nonceContribution');
|
|
120
|
+
}
|
|
121
|
+
export function isAggregatedNonceMessage(m) {
|
|
122
|
+
return m.type === AGGREGATED_NONCE
|
|
123
|
+
&& hasStr(m.body, 'cohortId')
|
|
124
|
+
&& hasStr(m.body, 'sessionId')
|
|
125
|
+
&& hasBytes(m.body, 'aggregatedNonce');
|
|
126
|
+
}
|
|
127
|
+
export function isSignatureAuthorizationMessage(m) {
|
|
128
|
+
return m.type === SIGNATURE_AUTHORIZATION
|
|
129
|
+
&& hasStr(m.body, 'cohortId')
|
|
130
|
+
&& hasStr(m.body, 'sessionId')
|
|
131
|
+
&& hasBytes(m.body, 'partialSignature');
|
|
132
|
+
}
|
|
133
|
+
export function isFallbackAuthorizationRequestMessage(m) {
|
|
134
|
+
return m.type === FALLBACK_AUTHORIZATION_REQUEST
|
|
135
|
+
&& hasStr(m.body, 'cohortId')
|
|
136
|
+
&& hasStr(m.body, 'sessionId')
|
|
137
|
+
&& hasStr(m.body, 'pendingTx')
|
|
138
|
+
&& hasStr(m.body, 'prevOutScriptHex')
|
|
139
|
+
&& hasStr(m.body, 'prevOutValue')
|
|
140
|
+
&& hasStr(m.body, 'fallbackLeafScriptHex');
|
|
141
|
+
}
|
|
142
|
+
export function isFallbackSignatureMessage(m) {
|
|
143
|
+
return m.type === FALLBACK_SIGNATURE
|
|
144
|
+
&& hasStr(m.body, 'cohortId')
|
|
145
|
+
&& hasStr(m.body, 'sessionId')
|
|
146
|
+
&& hasBytes(m.body, 'signerPk')
|
|
147
|
+
&& hasBytes(m.body, 'fallbackSignature');
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=bodies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bodies.js","sourceRoot":"","sources":["../../../src/messages/bodies.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,YAAY,EACZ,0BAA0B,EAC1B,8BAA8B,EAC9B,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACvB,kBAAkB,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M,CAAC,CAAC,CAAC,IAAI,EAAE,kBAAkB,CAAC;WAClC,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,cAAc,CAAC;WAC9B,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,uBAAuB,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,CAAc;IACvD,OAAO,CAAC,CAAC,IAAI,KAAK,kBAAkB;WAC/B,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,UAAU,CAAC;WAC1B,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,WAAW,CAAC;WAC3B,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,UAAU,CAAC;WAC5B,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message type URLs for the did:btcr2 Aggregate Beacon protocol.
|
|
3
|
+
*
|
|
4
|
+
* Naming follows the spec (https://dcdpr.github.io/did-btcr2/beacons/aggregate-beacons.html):
|
|
5
|
+
* - Step 1 (Cohort Formation): COHORT_ADVERT, COHORT_OPT_IN, COHORT_OPT_IN_ACCEPT, COHORT_READY
|
|
6
|
+
* - Step 2 (Update Submission): SUBMIT_UPDATE
|
|
7
|
+
* - Step 3 (Aggregate & Validate): DISTRIBUTE_AGGREGATED_DATA, VALIDATION_ACK
|
|
8
|
+
* - Step 4 (Sign & Broadcast): AUTHORIZATION_REQUEST, NONCE_CONTRIBUTION,
|
|
9
|
+
* AGGREGATED_NONCE, SIGNATURE_AUTHORIZATION
|
|
10
|
+
* - Step 4 fallback (k-of-n script path, ADR 042): FALLBACK_AUTHORIZATION_REQUEST,
|
|
11
|
+
* FALLBACK_SIGNATURE
|
|
12
|
+
*/
|
|
13
|
+
export const AGGREGATION_MESSAGE_PREFIX = 'https://btcr2.dev/aggregation';
|
|
14
|
+
// Step 1: Cohort Formation
|
|
15
|
+
export const COHORT_ADVERT = `${AGGREGATION_MESSAGE_PREFIX}/keygen/cohort_advert`;
|
|
16
|
+
export const COHORT_OPT_IN = `${AGGREGATION_MESSAGE_PREFIX}/keygen/cohort_opt_in`;
|
|
17
|
+
export const COHORT_OPT_IN_ACCEPT = `${AGGREGATION_MESSAGE_PREFIX}/keygen/cohort_opt_in_accept`;
|
|
18
|
+
export const COHORT_READY = `${AGGREGATION_MESSAGE_PREFIX}/keygen/cohort_ready`;
|
|
19
|
+
// Step 2 + 3: Update Submission, Aggregation, Validation
|
|
20
|
+
export const SUBMIT_UPDATE = `${AGGREGATION_MESSAGE_PREFIX}/update/submit_update`;
|
|
21
|
+
/** A member with no update this round declines explicitly (cooperative non-inclusion). */
|
|
22
|
+
export const SUBMIT_NONINCLUDED = `${AGGREGATION_MESSAGE_PREFIX}/update/submit_nonincluded`;
|
|
23
|
+
export const DISTRIBUTE_AGGREGATED_DATA = `${AGGREGATION_MESSAGE_PREFIX}/update/distribute_aggregated_data`;
|
|
24
|
+
export const VALIDATION_ACK = `${AGGREGATION_MESSAGE_PREFIX}/update/validation_ack`;
|
|
25
|
+
// Step 4: Signing
|
|
26
|
+
export const AUTHORIZATION_REQUEST = `${AGGREGATION_MESSAGE_PREFIX}/sign/authorization_request`;
|
|
27
|
+
export const NONCE_CONTRIBUTION = `${AGGREGATION_MESSAGE_PREFIX}/sign/nonce_contribution`;
|
|
28
|
+
export const AGGREGATED_NONCE = `${AGGREGATION_MESSAGE_PREFIX}/sign/aggregated_nonce`;
|
|
29
|
+
export const SIGNATURE_AUTHORIZATION = `${AGGREGATION_MESSAGE_PREFIX}/sign/signature_authorization`;
|
|
30
|
+
// Step 4 fallback: k-of-n script-path signing when the optimistic n-of-n key
|
|
31
|
+
// path stalls (graceful liveness, ADR 042). A single standalone BIP-340
|
|
32
|
+
// signature per member, no nonce round.
|
|
33
|
+
/** Service asks members to sign the fallback (k-of-n) script path of the beacon tx. */
|
|
34
|
+
export const FALLBACK_AUTHORIZATION_REQUEST = `${AGGREGATION_MESSAGE_PREFIX}/sign/fallback_authorization_request`;
|
|
35
|
+
/** A member returns a standalone BIP-340 signature over the fallback script-path sighash. */
|
|
36
|
+
export const FALLBACK_SIGNATURE = `${AGGREGATION_MESSAGE_PREFIX}/sign/fallback_signature`;
|
|
37
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/messages/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,+BAA+B,CAAC;AAE1E,2BAA2B;AAC3B,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,0BAA0B,uBAAuB,CAAC;AAClF,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,0BAA0B,uBAAuB,CAAC;AAClF,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,0BAA0B,8BAA8B,CAAC;AAChG,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,0BAA0B,sBAAsB,CAAC;AAEhF,yDAAyD;AACzD,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,0BAA0B,uBAAuB,CAAC;AAClF,0FAA0F;AAC1F,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,0BAA0B,4BAA4B,CAAC;AAC5F,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,0BAA0B,oCAAoC,CAAC;AAC5G,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,0BAA0B,wBAAwB,CAAC;AAEpF,kBAAkB;AAClB,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,0BAA0B,6BAA6B,CAAC;AAChG,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,0BAA0B,0BAA0B,CAAC;AAC1F,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,0BAA0B,wBAAwB,CAAC;AACtF,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,0BAA0B,+BAA+B,CAAC;AAEpG,6EAA6E;AAC7E,wEAAwE;AACxE,wCAAwC;AACxC,uFAAuF;AACvF,MAAM,CAAC,MAAM,8BAA8B,GAAG,GAAG,0BAA0B,sCAAsC,CAAC;AAClH,6FAA6F;AAC7F,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,0BAA0B,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { BaseMessage } from './base.js';
|
|
2
|
+
import { AGGREGATED_NONCE, AUTHORIZATION_REQUEST, COHORT_ADVERT, COHORT_OPT_IN, COHORT_OPT_IN_ACCEPT, COHORT_READY, DISTRIBUTE_AGGREGATED_DATA, FALLBACK_AUTHORIZATION_REQUEST, FALLBACK_SIGNATURE, NONCE_CONTRIBUTION, SIGNATURE_AUTHORIZATION, SUBMIT_NONINCLUDED, SUBMIT_UPDATE, VALIDATION_ACK, } from './constants.js';
|
|
3
|
+
/**
|
|
4
|
+
* Factory function for creating a Cohort Advert message, which is used to announce the formation of
|
|
5
|
+
* a new cohort and invite participants to join.
|
|
6
|
+
* @param {CohortAdvertMessage} fields - The fields required to create a Cohort Advert message.
|
|
7
|
+
* @returns {BaseMessage} The created Cohort Advert message.
|
|
8
|
+
*/
|
|
9
|
+
export function createCohortAdvertMessage(fields) {
|
|
10
|
+
const { from, ...body } = fields;
|
|
11
|
+
return new BaseMessage({ type: COHORT_ADVERT, from, body });
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Factory function for creating a Cohort Opt-In message, which is sent by a participant to express
|
|
15
|
+
* interest in joining a cohort.
|
|
16
|
+
* @param {CohortOptInMessage} fields - The fields required to create a Cohort Opt-In message, which
|
|
17
|
+
* is sent by a participant to express interest in joining a cohort.
|
|
18
|
+
* @returns {BaseMessage} The created Cohort Opt-In message.
|
|
19
|
+
*/
|
|
20
|
+
export function createCohortOptInMessage(fields) {
|
|
21
|
+
const { from, to, ...body } = fields;
|
|
22
|
+
return new BaseMessage({ type: COHORT_OPT_IN, from, to, body });
|
|
23
|
+
}
|
|
24
|
+
export function createCohortOptInAcceptMessage(fields) {
|
|
25
|
+
const { from, to, ...body } = fields;
|
|
26
|
+
return new BaseMessage({ type: COHORT_OPT_IN_ACCEPT, from, to, body });
|
|
27
|
+
}
|
|
28
|
+
export function createCohortReadyMessage(fields) {
|
|
29
|
+
const { from, to, ...body } = fields;
|
|
30
|
+
return new BaseMessage({ type: COHORT_READY, from, to, body });
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Factory function for creating a Submit Update message, which is sent by a participant to submit
|
|
34
|
+
* their signed update for aggregation.
|
|
35
|
+
* @param {SubmitUpdateMessage} fields - The fields required to create a Submit Update message,
|
|
36
|
+
* which is sent by a participant to submit their signed update for aggregation.
|
|
37
|
+
* @returns {BaseMessage} The created Submit Update message.
|
|
38
|
+
*/
|
|
39
|
+
export function createSubmitUpdateMessage(fields) {
|
|
40
|
+
const { from, to, ...body } = fields;
|
|
41
|
+
return new BaseMessage({ type: SUBMIT_UPDATE, from, to, body });
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Factory for a Submit Non-Included message: a member declares it has no update
|
|
45
|
+
* this round (cooperative non-inclusion). Membership is proven by the signed
|
|
46
|
+
* envelope, so the body carries only the cohortId.
|
|
47
|
+
*/
|
|
48
|
+
export function createSubmitNonIncludedMessage(fields) {
|
|
49
|
+
const { from, to, ...body } = fields;
|
|
50
|
+
return new BaseMessage({ type: SUBMIT_NONINCLUDED, from, to, body });
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Factory function for creating a Distribute Aggregated Data message, which is sent by the
|
|
54
|
+
* aggregator to distribute the aggregated data to participants for validation.
|
|
55
|
+
* @param {DistributeAggregatedDataMessage} fields - The fields required to create a Distribute
|
|
56
|
+
* Aggregated Data message, which is sent by the aggregator to distribute the aggregated data to
|
|
57
|
+
* participants for validation.
|
|
58
|
+
* @returns {BaseMessage} The created Distribute Aggregated Data message.
|
|
59
|
+
*/
|
|
60
|
+
export function createDistributeAggregatedDataMessage(fields) {
|
|
61
|
+
const { from, to, ...body } = fields;
|
|
62
|
+
return new BaseMessage({ type: DISTRIBUTE_AGGREGATED_DATA, from, to, body });
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Factory function for creating a Validation Acknowledgment message, which is sent by a participant
|
|
66
|
+
* to acknowledge.
|
|
67
|
+
* @param {ValidationAckMessage} fields - The fields required to create a Validation Acknowledgment
|
|
68
|
+
* message, which is sent by a participant to acknowledge the validation of the aggregated data.
|
|
69
|
+
* @returns {BaseMessage} The created Validation Acknowledgment message.
|
|
70
|
+
*/
|
|
71
|
+
export function createValidationAckMessage(fields) {
|
|
72
|
+
const { from, to, ...body } = fields;
|
|
73
|
+
return new BaseMessage({ type: VALIDATION_ACK, from, to, body });
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Factory function for creating an Authorization Request message, which is sent by a participant to
|
|
77
|
+
* request authorization for their signature.
|
|
78
|
+
* @param {AuthorizationRequestMessage} fields - The fields required to create an Authorization
|
|
79
|
+
* Request message, which is sent by a participant to request authorization for their signature.
|
|
80
|
+
* @returns {BaseMessage} The created Authorization Request message.
|
|
81
|
+
*/
|
|
82
|
+
export function createAuthorizationRequestMessage(fields) {
|
|
83
|
+
const { from, to, ...body } = fields;
|
|
84
|
+
return new BaseMessage({ type: AUTHORIZATION_REQUEST, from, to, body });
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Factory function for creating a Nonce Contribution message, which is sent by a participant to
|
|
88
|
+
* contribute their nonce for the signature aggregation process.
|
|
89
|
+
* @param {NonceContributionMessage} fields - The fields required to create a Nonce Contribution
|
|
90
|
+
* message, which is sent by a participant to contribute their nonce for the signature aggregation
|
|
91
|
+
* process.
|
|
92
|
+
* @returns {BaseMessage} The created Nonce Contribution message.
|
|
93
|
+
*/
|
|
94
|
+
export function createNonceContributionMessage(fields) {
|
|
95
|
+
const { from, to, ...body } = fields;
|
|
96
|
+
return new BaseMessage({ type: NONCE_CONTRIBUTION, from, to, body });
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Factory function for creating an Aggregated Nonce message, which is sent by the aggregator to
|
|
100
|
+
* distribute the aggregated nonce to participants for the signature aggregation process.
|
|
101
|
+
* @param {AggregatedNonceMessage} fields - The fields required to create an Aggregated Nonce
|
|
102
|
+
* message, which is sent by the aggregator to distribute the aggregated nonce to participants for
|
|
103
|
+
* the signature aggregation process.
|
|
104
|
+
* @returns {BaseMessage} The created Aggregated Nonce message.
|
|
105
|
+
*/
|
|
106
|
+
export function createAggregatedNonceMessage(fields) {
|
|
107
|
+
const { from, to, ...body } = fields;
|
|
108
|
+
return new BaseMessage({ type: AGGREGATED_NONCE, from, to, body });
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Factory function for creating a Signature Authorization message, which is sent by a participant
|
|
112
|
+
* to authorize their partial signature for the signature aggregation process.
|
|
113
|
+
* @param {SignatureAuthorizationMessage} fields - The fields required to create a Signature
|
|
114
|
+
* Authorization message, which is sent by a participant to authorize their partial signature for
|
|
115
|
+
* the signature aggregation process.
|
|
116
|
+
* @returns {BaseMessage} The created Signature Authorization message.
|
|
117
|
+
*/
|
|
118
|
+
export function createSignatureAuthorizationMessage(fields) {
|
|
119
|
+
const { from, to, ...body } = fields;
|
|
120
|
+
return new BaseMessage({ type: SIGNATURE_AUTHORIZATION, from, to, body });
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Factory for a Fallback Authorization Request: the service asks members to
|
|
124
|
+
* authorize the k-of-n script-path spend of the beacon transaction when the
|
|
125
|
+
* optimistic n-of-n key path stalls (ADR 042).
|
|
126
|
+
*/
|
|
127
|
+
export function createFallbackAuthorizationRequestMessage(fields) {
|
|
128
|
+
const { from, to, ...body } = fields;
|
|
129
|
+
return new BaseMessage({ type: FALLBACK_AUTHORIZATION_REQUEST, from, to, body });
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Factory for a Fallback Signature: a member's standalone BIP-340 signature over
|
|
133
|
+
* the fallback script-path sighash (no nonce round).
|
|
134
|
+
*/
|
|
135
|
+
export function createFallbackSignatureMessage(fields) {
|
|
136
|
+
const { from, to, ...body } = fields;
|
|
137
|
+
return new BaseMessage({ type: FALLBACK_SIGNATURE, from, to, body });
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=factories.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factories.js","sourceRoot":"","sources":["../../../src/messages/factories.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,YAAY,EACZ,0BAA0B,EAC1B,8BAA8B,EAC9B,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACvB,kBAAkB,EAClB,aAAa,EACb,cAAc,GACf,MAAM,gBAAgB,CAAC;AAiCxB;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CAAC,MAA2B;IACnE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IACjC,OAAO,IAAI,WAAW,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAA0B;IACjE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IACrC,OAAO,IAAI,WAAW,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,8BAA8B,CAAC,MAAgC;IAC7E,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,MA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,yCAAyC,CAAC,MAA2C;IACnG,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IACrC,OAAO,IAAI,WAAW,CAAC,EAAE,IAAI,EAAE,8BAA8B,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AACnF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,8BAA8B,CAAC,MAAgC;IAC7E,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IACrC,OAAO,IAAI,WAAW,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { AGGREGATED_NONCE, AUTHORIZATION_REQUEST, COHORT_ADVERT, COHORT_OPT_IN, COHORT_OPT_IN_ACCEPT, COHORT_READY, DISTRIBUTE_AGGREGATED_DATA, FALLBACK_AUTHORIZATION_REQUEST, FALLBACK_SIGNATURE, NONCE_CONTRIBUTION, SIGNATURE_AUTHORIZATION, SUBMIT_NONINCLUDED, SUBMIT_UPDATE, VALIDATION_ACK, } from './constants.js';
|
|
2
|
+
const KEYGEN_VALUES = new Set([
|
|
3
|
+
COHORT_ADVERT,
|
|
4
|
+
COHORT_OPT_IN,
|
|
5
|
+
COHORT_OPT_IN_ACCEPT,
|
|
6
|
+
COHORT_READY,
|
|
7
|
+
]);
|
|
8
|
+
const UPDATE_VALUES = new Set([
|
|
9
|
+
SUBMIT_UPDATE,
|
|
10
|
+
SUBMIT_NONINCLUDED,
|
|
11
|
+
DISTRIBUTE_AGGREGATED_DATA,
|
|
12
|
+
VALIDATION_ACK,
|
|
13
|
+
]);
|
|
14
|
+
const SIGN_VALUES = new Set([
|
|
15
|
+
AUTHORIZATION_REQUEST,
|
|
16
|
+
NONCE_CONTRIBUTION,
|
|
17
|
+
AGGREGATED_NONCE,
|
|
18
|
+
SIGNATURE_AUTHORIZATION,
|
|
19
|
+
FALLBACK_AUTHORIZATION_REQUEST,
|
|
20
|
+
FALLBACK_SIGNATURE,
|
|
21
|
+
]);
|
|
22
|
+
/**
|
|
23
|
+
* Checks if the provided type is a valid aggregation message type.
|
|
24
|
+
*/
|
|
25
|
+
export function isAggregationMessageType(type) {
|
|
26
|
+
return KEYGEN_VALUES.has(type) || UPDATE_VALUES.has(type) || SIGN_VALUES.has(type);
|
|
27
|
+
}
|
|
28
|
+
/** Checks if the message type belongs to the keygen phase. */
|
|
29
|
+
export function isKeygenMessageType(type) {
|
|
30
|
+
return KEYGEN_VALUES.has(type);
|
|
31
|
+
}
|
|
32
|
+
/** Checks if the message type belongs to the update phase. */
|
|
33
|
+
export function isUpdateMessageType(type) {
|
|
34
|
+
return UPDATE_VALUES.has(type);
|
|
35
|
+
}
|
|
36
|
+
/** Checks if the message type belongs to the signing phase. */
|
|
37
|
+
export function isSignMessageType(type) {
|
|
38
|
+
return SIGN_VALUES.has(type);
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=guards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../../src/messages/guards.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,YAAY,EACZ,0BAA0B,EAC1B,8BAA8B,EAC9B,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACvB,kBAAkB,EAClB,aAAa,EACb,cAAc,GACf,MAAM,gBAAgB,CAAC;AAExB,MAAM,aAAa,GAAgB,IAAI,GAAG,CAAC;IACzC,aAAa;IACb,aAAa;IACb,oBAAoB;IACpB,YAAY;CACb,CAAC,CAAC;AAEH,MAAM,aAAa,GAAgB,IAAI,GAAG,CAAC;IACzC,aAAa;IACb,kBAAkB;IAClB,0BAA0B;IAC1B,cAAc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