@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,40 @@
|
|
|
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
|
+
|
|
15
|
+
// Step 1: Cohort Formation
|
|
16
|
+
export const COHORT_ADVERT = `${AGGREGATION_MESSAGE_PREFIX}/keygen/cohort_advert`;
|
|
17
|
+
export const COHORT_OPT_IN = `${AGGREGATION_MESSAGE_PREFIX}/keygen/cohort_opt_in`;
|
|
18
|
+
export const COHORT_OPT_IN_ACCEPT = `${AGGREGATION_MESSAGE_PREFIX}/keygen/cohort_opt_in_accept`;
|
|
19
|
+
export const COHORT_READY = `${AGGREGATION_MESSAGE_PREFIX}/keygen/cohort_ready`;
|
|
20
|
+
|
|
21
|
+
// Step 2 + 3: Update Submission, Aggregation, Validation
|
|
22
|
+
export const SUBMIT_UPDATE = `${AGGREGATION_MESSAGE_PREFIX}/update/submit_update`;
|
|
23
|
+
/** A member with no update this round declines explicitly (cooperative non-inclusion). */
|
|
24
|
+
export const SUBMIT_NONINCLUDED = `${AGGREGATION_MESSAGE_PREFIX}/update/submit_nonincluded`;
|
|
25
|
+
export const DISTRIBUTE_AGGREGATED_DATA = `${AGGREGATION_MESSAGE_PREFIX}/update/distribute_aggregated_data`;
|
|
26
|
+
export const VALIDATION_ACK = `${AGGREGATION_MESSAGE_PREFIX}/update/validation_ack`;
|
|
27
|
+
|
|
28
|
+
// Step 4: Signing
|
|
29
|
+
export const AUTHORIZATION_REQUEST = `${AGGREGATION_MESSAGE_PREFIX}/sign/authorization_request`;
|
|
30
|
+
export const NONCE_CONTRIBUTION = `${AGGREGATION_MESSAGE_PREFIX}/sign/nonce_contribution`;
|
|
31
|
+
export const AGGREGATED_NONCE = `${AGGREGATION_MESSAGE_PREFIX}/sign/aggregated_nonce`;
|
|
32
|
+
export const SIGNATURE_AUTHORIZATION = `${AGGREGATION_MESSAGE_PREFIX}/sign/signature_authorization`;
|
|
33
|
+
|
|
34
|
+
// Step 4 fallback: k-of-n script-path signing when the optimistic n-of-n key
|
|
35
|
+
// path stalls (graceful liveness, ADR 042). A single standalone BIP-340
|
|
36
|
+
// signature per member, no nonce round.
|
|
37
|
+
/** Service asks members to sign the fallback (k-of-n) script path of the beacon tx. */
|
|
38
|
+
export const FALLBACK_AUTHORIZATION_REQUEST = `${AGGREGATION_MESSAGE_PREFIX}/sign/fallback_authorization_request`;
|
|
39
|
+
/** A member returns a standalone BIP-340 signature over the fallback script-path sighash. */
|
|
40
|
+
export const FALLBACK_SIGNATURE = `${AGGREGATION_MESSAGE_PREFIX}/sign/fallback_signature`;
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import type { CohortConditions } from '../conditions.js';
|
|
2
|
+
import { BaseMessage } from './base.js';
|
|
3
|
+
import {
|
|
4
|
+
AGGREGATED_NONCE,
|
|
5
|
+
AUTHORIZATION_REQUEST,
|
|
6
|
+
COHORT_ADVERT,
|
|
7
|
+
COHORT_OPT_IN,
|
|
8
|
+
COHORT_OPT_IN_ACCEPT,
|
|
9
|
+
COHORT_READY,
|
|
10
|
+
DISTRIBUTE_AGGREGATED_DATA,
|
|
11
|
+
FALLBACK_AUTHORIZATION_REQUEST,
|
|
12
|
+
FALLBACK_SIGNATURE,
|
|
13
|
+
NONCE_CONTRIBUTION,
|
|
14
|
+
SIGNATURE_AUTHORIZATION,
|
|
15
|
+
SUBMIT_NONINCLUDED,
|
|
16
|
+
SUBMIT_UPDATE,
|
|
17
|
+
VALIDATION_ACK,
|
|
18
|
+
} from './constants.js';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Step 1: Cohort Formation
|
|
22
|
+
* Factory functions for creating messages related to the cohort formation step, where cohorts are
|
|
23
|
+
* formed and participants opt in to join the cohort.
|
|
24
|
+
*/
|
|
25
|
+
type CohortAdvertMessage = CohortConditions & {
|
|
26
|
+
from: string;
|
|
27
|
+
cohortId: string;
|
|
28
|
+
network: string;
|
|
29
|
+
communicationPk: Uint8Array;
|
|
30
|
+
};
|
|
31
|
+
type CohortOptInMessage = {
|
|
32
|
+
from: string;
|
|
33
|
+
to: string;
|
|
34
|
+
cohortId: string;
|
|
35
|
+
participantPk: Uint8Array;
|
|
36
|
+
communicationPk: Uint8Array;
|
|
37
|
+
};
|
|
38
|
+
type CohortOptInAcceptMessage = {
|
|
39
|
+
from: string;
|
|
40
|
+
to: string;
|
|
41
|
+
cohortId: string;
|
|
42
|
+
};
|
|
43
|
+
type CohortReadyMessage = {
|
|
44
|
+
from: string;
|
|
45
|
+
to: string;
|
|
46
|
+
cohortId: string;
|
|
47
|
+
beaconAddress: string;
|
|
48
|
+
cohortKeys: Array<Uint8Array>;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Factory function for creating a Cohort Advert message, which is used to announce the formation of
|
|
53
|
+
* a new cohort and invite participants to join.
|
|
54
|
+
* @param {CohortAdvertMessage} fields - The fields required to create a Cohort Advert message.
|
|
55
|
+
* @returns {BaseMessage} The created Cohort Advert message.
|
|
56
|
+
*/
|
|
57
|
+
export function createCohortAdvertMessage(fields: CohortAdvertMessage): BaseMessage {
|
|
58
|
+
const { from, ...body } = fields;
|
|
59
|
+
return new BaseMessage({ type: COHORT_ADVERT, from, body });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Factory function for creating a Cohort Opt-In message, which is sent by a participant to express
|
|
64
|
+
* interest in joining a cohort.
|
|
65
|
+
* @param {CohortOptInMessage} fields - The fields required to create a Cohort Opt-In message, which
|
|
66
|
+
* is sent by a participant to express interest in joining a cohort.
|
|
67
|
+
* @returns {BaseMessage} The created Cohort Opt-In message.
|
|
68
|
+
*/
|
|
69
|
+
export function createCohortOptInMessage(fields: CohortOptInMessage): BaseMessage {
|
|
70
|
+
const { from, to, ...body } = fields;
|
|
71
|
+
return new BaseMessage({ type: COHORT_OPT_IN, from, to, body });
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function createCohortOptInAcceptMessage(fields: CohortOptInAcceptMessage): BaseMessage {
|
|
75
|
+
const { from, to, ...body } = fields;
|
|
76
|
+
return new BaseMessage({ type: COHORT_OPT_IN_ACCEPT, from, to, body });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function createCohortReadyMessage(fields: CohortReadyMessage): BaseMessage {
|
|
80
|
+
const { from, to, ...body } = fields;
|
|
81
|
+
return new BaseMessage({ type: COHORT_READY, from, to, body });
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Step 2: Update Submission
|
|
86
|
+
* Factory functions for creating messages related to the update submission step, where participants
|
|
87
|
+
* submit their signed updates for aggregation.
|
|
88
|
+
*/
|
|
89
|
+
type SubmitUpdateMessage = {
|
|
90
|
+
from: string;
|
|
91
|
+
to: string;
|
|
92
|
+
cohortId: string;
|
|
93
|
+
signedUpdate: Record<string, unknown>;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Factory function for creating a Submit Update message, which is sent by a participant to submit
|
|
98
|
+
* their signed update for aggregation.
|
|
99
|
+
* @param {SubmitUpdateMessage} fields - The fields required to create a Submit Update message,
|
|
100
|
+
* which is sent by a participant to submit their signed update for aggregation.
|
|
101
|
+
* @returns {BaseMessage} The created Submit Update message.
|
|
102
|
+
*/
|
|
103
|
+
export function createSubmitUpdateMessage(fields: SubmitUpdateMessage): BaseMessage {
|
|
104
|
+
const { from, to, ...body } = fields;
|
|
105
|
+
return new BaseMessage({ type: SUBMIT_UPDATE, from, to, body });
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
type SubmitNonIncludedMessage = {
|
|
109
|
+
from: string;
|
|
110
|
+
to: string;
|
|
111
|
+
cohortId: string;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Factory for a Submit Non-Included message: a member declares it has no update
|
|
116
|
+
* this round (cooperative non-inclusion). Membership is proven by the signed
|
|
117
|
+
* envelope, so the body carries only the cohortId.
|
|
118
|
+
*/
|
|
119
|
+
export function createSubmitNonIncludedMessage(fields: SubmitNonIncludedMessage): BaseMessage {
|
|
120
|
+
const { from, to, ...body } = fields;
|
|
121
|
+
return new BaseMessage({ type: SUBMIT_NONINCLUDED, from, to, body });
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Step 3: Aggregate & Validate
|
|
126
|
+
* Factory functions for creating messages related to the aggregate and validate step, where
|
|
127
|
+
* participants aggregate their updates and validate the aggregated data.
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
type DistributeAggregatedDataMessage = {
|
|
131
|
+
from: string;
|
|
132
|
+
to: string;
|
|
133
|
+
cohortId: string;
|
|
134
|
+
beaconType: string;
|
|
135
|
+
signalBytesHex: string;
|
|
136
|
+
casAnnouncement?: Record<string, string>;
|
|
137
|
+
smtProof?: Record<string, unknown>;
|
|
138
|
+
};
|
|
139
|
+
type ValidationAckMessage = {
|
|
140
|
+
from: string;
|
|
141
|
+
to: string;
|
|
142
|
+
cohortId: string;
|
|
143
|
+
approved: boolean;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Factory function for creating a Distribute Aggregated Data message, which is sent by the
|
|
148
|
+
* aggregator to distribute the aggregated data to participants for validation.
|
|
149
|
+
* @param {DistributeAggregatedDataMessage} fields - The fields required to create a Distribute
|
|
150
|
+
* Aggregated Data message, which is sent by the aggregator to distribute the aggregated data to
|
|
151
|
+
* participants for validation.
|
|
152
|
+
* @returns {BaseMessage} The created Distribute Aggregated Data message.
|
|
153
|
+
*/
|
|
154
|
+
export function createDistributeAggregatedDataMessage(
|
|
155
|
+
fields: DistributeAggregatedDataMessage
|
|
156
|
+
): BaseMessage {
|
|
157
|
+
const { from, to, ...body } = fields;
|
|
158
|
+
return new BaseMessage({ type: DISTRIBUTE_AGGREGATED_DATA, from, to, body });
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Factory function for creating a Validation Acknowledgment message, which is sent by a participant
|
|
163
|
+
* to acknowledge.
|
|
164
|
+
* @param {ValidationAckMessage} fields - The fields required to create a Validation Acknowledgment
|
|
165
|
+
* message, which is sent by a participant to acknowledge the validation of the aggregated data.
|
|
166
|
+
* @returns {BaseMessage} The created Validation Acknowledgment message.
|
|
167
|
+
*/
|
|
168
|
+
export function createValidationAckMessage(fields: ValidationAckMessage): BaseMessage {
|
|
169
|
+
const { from, to, ...body } = fields;
|
|
170
|
+
return new BaseMessage({ type: VALIDATION_ACK, from, to, body });
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Step 4: Signing
|
|
175
|
+
* Factory functions for creating messages related to the signing step, where participants request
|
|
176
|
+
* signatures, contribute nonces, and authorize signatures.
|
|
177
|
+
*/
|
|
178
|
+
|
|
179
|
+
type AuthorizationRequestMessage = {
|
|
180
|
+
from: string;
|
|
181
|
+
to: string;
|
|
182
|
+
cohortId: string;
|
|
183
|
+
sessionId: string;
|
|
184
|
+
pendingTx: string;
|
|
185
|
+
prevOutScriptHex: string;
|
|
186
|
+
prevOutValue: string;
|
|
187
|
+
};
|
|
188
|
+
type NonceContributionMessage = {
|
|
189
|
+
from: string;
|
|
190
|
+
to: string;
|
|
191
|
+
cohortId: string;
|
|
192
|
+
sessionId: string;
|
|
193
|
+
nonceContribution: Uint8Array;
|
|
194
|
+
};
|
|
195
|
+
type AggregatedNonceMessage = {
|
|
196
|
+
from: string;
|
|
197
|
+
to: string;
|
|
198
|
+
cohortId: string;
|
|
199
|
+
sessionId: string;
|
|
200
|
+
aggregatedNonce: Uint8Array;
|
|
201
|
+
};
|
|
202
|
+
type SignatureAuthorizationMessage = {
|
|
203
|
+
from: string;
|
|
204
|
+
to: string;
|
|
205
|
+
cohortId: string;
|
|
206
|
+
sessionId: string;
|
|
207
|
+
partialSignature: Uint8Array;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Factory function for creating an Authorization Request message, which is sent by a participant to
|
|
212
|
+
* request authorization for their signature.
|
|
213
|
+
* @param {AuthorizationRequestMessage} fields - The fields required to create an Authorization
|
|
214
|
+
* Request message, which is sent by a participant to request authorization for their signature.
|
|
215
|
+
* @returns {BaseMessage} The created Authorization Request message.
|
|
216
|
+
*/
|
|
217
|
+
export function createAuthorizationRequestMessage(fields: AuthorizationRequestMessage): BaseMessage {
|
|
218
|
+
const { from, to, ...body } = fields;
|
|
219
|
+
return new BaseMessage({ type: AUTHORIZATION_REQUEST, from, to, body });
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Factory function for creating a Nonce Contribution message, which is sent by a participant to
|
|
224
|
+
* contribute their nonce for the signature aggregation process.
|
|
225
|
+
* @param {NonceContributionMessage} fields - The fields required to create a Nonce Contribution
|
|
226
|
+
* message, which is sent by a participant to contribute their nonce for the signature aggregation
|
|
227
|
+
* process.
|
|
228
|
+
* @returns {BaseMessage} The created Nonce Contribution message.
|
|
229
|
+
*/
|
|
230
|
+
export function createNonceContributionMessage(fields: NonceContributionMessage): BaseMessage {
|
|
231
|
+
const { from, to, ...body } = fields;
|
|
232
|
+
return new BaseMessage({ type: NONCE_CONTRIBUTION, from, to, body });
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Factory function for creating an Aggregated Nonce message, which is sent by the aggregator to
|
|
237
|
+
* distribute the aggregated nonce to participants for the signature aggregation process.
|
|
238
|
+
* @param {AggregatedNonceMessage} fields - The fields required to create an Aggregated Nonce
|
|
239
|
+
* message, which is sent by the aggregator to distribute the aggregated nonce to participants for
|
|
240
|
+
* the signature aggregation process.
|
|
241
|
+
* @returns {BaseMessage} The created Aggregated Nonce message.
|
|
242
|
+
*/
|
|
243
|
+
export function createAggregatedNonceMessage(fields: AggregatedNonceMessage): BaseMessage {
|
|
244
|
+
const { from, to, ...body } = fields;
|
|
245
|
+
return new BaseMessage({ type: AGGREGATED_NONCE, from, to, body });
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Factory function for creating a Signature Authorization message, which is sent by a participant
|
|
250
|
+
* to authorize their partial signature for the signature aggregation process.
|
|
251
|
+
* @param {SignatureAuthorizationMessage} fields - The fields required to create a Signature
|
|
252
|
+
* Authorization message, which is sent by a participant to authorize their partial signature for
|
|
253
|
+
* the signature aggregation process.
|
|
254
|
+
* @returns {BaseMessage} The created Signature Authorization message.
|
|
255
|
+
*/
|
|
256
|
+
export function createSignatureAuthorizationMessage(fields: SignatureAuthorizationMessage): BaseMessage {
|
|
257
|
+
const { from, to, ...body } = fields;
|
|
258
|
+
return new BaseMessage({ type: SIGNATURE_AUTHORIZATION, from, to, body });
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
type FallbackAuthorizationRequestMessage = {
|
|
262
|
+
from: string;
|
|
263
|
+
to: string;
|
|
264
|
+
cohortId: string;
|
|
265
|
+
sessionId: string;
|
|
266
|
+
pendingTx: string;
|
|
267
|
+
prevOutScriptHex: string;
|
|
268
|
+
prevOutValue: string;
|
|
269
|
+
fallbackLeafScriptHex: string;
|
|
270
|
+
};
|
|
271
|
+
type FallbackSignatureMessage = {
|
|
272
|
+
from: string;
|
|
273
|
+
to: string;
|
|
274
|
+
cohortId: string;
|
|
275
|
+
sessionId: string;
|
|
276
|
+
signerPk: Uint8Array;
|
|
277
|
+
fallbackSignature: Uint8Array;
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Factory for a Fallback Authorization Request: the service asks members to
|
|
282
|
+
* authorize the k-of-n script-path spend of the beacon transaction when the
|
|
283
|
+
* optimistic n-of-n key path stalls (ADR 042).
|
|
284
|
+
*/
|
|
285
|
+
export function createFallbackAuthorizationRequestMessage(fields: FallbackAuthorizationRequestMessage): BaseMessage {
|
|
286
|
+
const { from, to, ...body } = fields;
|
|
287
|
+
return new BaseMessage({ type: FALLBACK_AUTHORIZATION_REQUEST, from, to, body });
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Factory for a Fallback Signature: a member's standalone BIP-340 signature over
|
|
292
|
+
* the fallback script-path sighash (no nonce round).
|
|
293
|
+
*/
|
|
294
|
+
export function createFallbackSignatureMessage(fields: FallbackSignatureMessage): BaseMessage {
|
|
295
|
+
const { from, to, ...body } = fields;
|
|
296
|
+
return new BaseMessage({ type: FALLBACK_SIGNATURE, from, to, body });
|
|
297
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AGGREGATED_NONCE,
|
|
3
|
+
AUTHORIZATION_REQUEST,
|
|
4
|
+
COHORT_ADVERT,
|
|
5
|
+
COHORT_OPT_IN,
|
|
6
|
+
COHORT_OPT_IN_ACCEPT,
|
|
7
|
+
COHORT_READY,
|
|
8
|
+
DISTRIBUTE_AGGREGATED_DATA,
|
|
9
|
+
FALLBACK_AUTHORIZATION_REQUEST,
|
|
10
|
+
FALLBACK_SIGNATURE,
|
|
11
|
+
NONCE_CONTRIBUTION,
|
|
12
|
+
SIGNATURE_AUTHORIZATION,
|
|
13
|
+
SUBMIT_NONINCLUDED,
|
|
14
|
+
SUBMIT_UPDATE,
|
|
15
|
+
VALIDATION_ACK,
|
|
16
|
+
} from './constants.js';
|
|
17
|
+
|
|
18
|
+
const KEYGEN_VALUES: Set<string> = new Set([
|
|
19
|
+
COHORT_ADVERT,
|
|
20
|
+
COHORT_OPT_IN,
|
|
21
|
+
COHORT_OPT_IN_ACCEPT,
|
|
22
|
+
COHORT_READY,
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
const UPDATE_VALUES: Set<string> = new Set([
|
|
26
|
+
SUBMIT_UPDATE,
|
|
27
|
+
SUBMIT_NONINCLUDED,
|
|
28
|
+
DISTRIBUTE_AGGREGATED_DATA,
|
|
29
|
+
VALIDATION_ACK,
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
const SIGN_VALUES: Set<string> = new Set([
|
|
33
|
+
AUTHORIZATION_REQUEST,
|
|
34
|
+
NONCE_CONTRIBUTION,
|
|
35
|
+
AGGREGATED_NONCE,
|
|
36
|
+
SIGNATURE_AUTHORIZATION,
|
|
37
|
+
FALLBACK_AUTHORIZATION_REQUEST,
|
|
38
|
+
FALLBACK_SIGNATURE,
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Checks if the provided type is a valid aggregation message type.
|
|
43
|
+
*/
|
|
44
|
+
export function isAggregationMessageType(type: string): boolean {
|
|
45
|
+
return KEYGEN_VALUES.has(type) || UPDATE_VALUES.has(type) || SIGN_VALUES.has(type);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Checks if the message type belongs to the keygen phase. */
|
|
49
|
+
export function isKeygenMessageType(type: string): boolean {
|
|
50
|
+
return KEYGEN_VALUES.has(type);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Checks if the message type belongs to the update phase. */
|
|
54
|
+
export function isUpdateMessageType(type: string): boolean {
|
|
55
|
+
return UPDATE_VALUES.has(type);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Checks if the message type belongs to the signing phase. */
|
|
59
|
+
export function isSignMessageType(type: string): boolean {
|
|
60
|
+
return SIGN_VALUES.has(type);
|
|
61
|
+
}
|