@ocap/mpc-hsm 0.0.0-stage → 1.33.6

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.
@@ -0,0 +1,242 @@
1
+ import { LinearPedersenDleqProof, PedersenPokProof, RandomBytesFn, SchnorrPokProof } from "./secp256k1-scalar.mjs";
2
+ import { BaseOtReceiverState, BaseOtSenderState, OtExtStep1Message, OtExtStep2Message, OtExtStep3Message } from "./ot.mjs";
3
+ import { GadgetMtaPayload } from "./mta.mjs";
4
+
5
+ //#region src/presign.d.ts
6
+ interface MpcPublicClusterInfo {
7
+ readonly rootId: string;
8
+ readonly keyEpoch: bigint;
9
+ readonly t: number;
10
+ readonly nParties: number;
11
+ readonly hDkg32: Uint8Array;
12
+ readonly rootPublicKeyComp33: Uint8Array;
13
+ /** Map from 1-based party `slot` (`1..nParties`) to compressed 33-byte public share `X_slot`. */
14
+ readonly publicSharesComp33BySlot: ReadonlyMap<number, Uint8Array>;
15
+ }
16
+ interface MpcPartyBaseOtChannels {
17
+ readonly ownerSlot: number;
18
+ /** Used when `ownerSlot` acts as Extended Sender `A` against peer `receiverSlotB`. */
19
+ readonly asExtendedSenderA: Map<number, BaseOtReceiverState>;
20
+ /** Used when `ownerSlot` acts as Extended Receiver `B` against peer `senderSlotA`. */
21
+ readonly asExtendedReceiverB: Map<number, BaseOtSenderState>;
22
+ }
23
+ interface PresignRound1CommitmentMsg {
24
+ readonly slot: number;
25
+ readonly commitment32: Uint8Array;
26
+ }
27
+ interface PresignRound1RevealMsg {
28
+ readonly slot: number;
29
+ readonly comSalt32: Uint8Array;
30
+ readonly gammaPointComp33: Uint8Array;
31
+ readonly bPointComp33: Uint8Array;
32
+ readonly ckPointComp33: Uint8Array;
33
+ readonly zetaEpk32: Uint8Array;
34
+ readonly pokGamma: SchnorrPokProof;
35
+ readonly pokB: SchnorrPokProof;
36
+ readonly pokCk: PedersenPokProof;
37
+ }
38
+ type MtaInstanceKind = 'k_gamma' | 'k_b';
39
+ interface PresignMtaOtStep1Bundle {
40
+ readonly fromReceiverSlotB: number;
41
+ readonly toSenderSlotA: number;
42
+ readonly kGammaOt1: OtExtStep1Message;
43
+ readonly kBOt1: OtExtStep1Message;
44
+ }
45
+ interface PresignMtaOtStep2Bundle {
46
+ readonly fromSenderSlotA: number;
47
+ readonly toReceiverSlotB: number;
48
+ readonly kGammaOt2: OtExtStep2Message;
49
+ readonly kBOt2: OtExtStep2Message;
50
+ }
51
+ interface PresignMtaOtStep3Bundle {
52
+ readonly fromReceiverSlotB: number;
53
+ readonly toSenderSlotA: number;
54
+ readonly kGammaOt3: OtExtStep3Message;
55
+ readonly kBOt3: OtExtStep3Message;
56
+ }
57
+ interface PresignMtaStep4PayloadBundle {
58
+ readonly fromSenderSlotA: number;
59
+ readonly toReceiverSlotB: number;
60
+ readonly kGammaMta: GadgetMtaPayload;
61
+ readonly kBMta: GadgetMtaPayload;
62
+ }
63
+ interface PresignRound3BroadcastMsg {
64
+ readonly slot: number;
65
+ readonly deltaShareBytes32: Uint8Array;
66
+ readonly eShareBytes32: Uint8Array;
67
+ }
68
+ interface PresignRound4BroadcastMsg {
69
+ readonly slot: number;
70
+ readonly kSharePointComp33: Uint8Array;
71
+ readonly zSharePointComp33: Uint8Array;
72
+ readonly piLinK: LinearPedersenDleqProof;
73
+ readonly piPokZ: SchnorrPokProof;
74
+ }
75
+ interface PresignaturePublicVerification {
76
+ readonly presigId32: Uint8Array;
77
+ readonly presigIdHex: string;
78
+ readonly rootId: string;
79
+ readonly keyEpoch: bigint;
80
+ readonly subset: ReadonlyArray<number>;
81
+ readonly hDkg32: Uint8Array;
82
+ readonly rootPublicKeyComp33: Uint8Array;
83
+ readonly rPointComp33: Uint8Array;
84
+ readonly kPointsComp33BySlot: ReadonlyMap<number, Uint8Array>;
85
+ readonly zPointsComp33BySlot: ReadonlyMap<number, Uint8Array>;
86
+ }
87
+ interface PresignatureShareRecord {
88
+ readonly slot: number;
89
+ readonly publicVerification: PresignaturePublicVerification;
90
+ /** Zeroized immediately upon consumption or abort/panic wipe. */
91
+ readonly kShareBytes32: Uint8Array;
92
+ /** Zeroized immediately upon consumption or abort/panic wipe. */
93
+ readonly chiShareBytes32: Uint8Array;
94
+ }
95
+ /**
96
+ * Computes the canonical subset-bound `presigId` (`design.md` §4.5(1)):
97
+ * `SHA256("ARC-MPC-PRESIG-ID-V1" || LP(rootId) || u64be(keyEpoch) || sortedSubsetBytes(S) || H_dkg || Com^{pre}_{i_1..i_t})`.
98
+ */
99
+ declare function computeSubsetBoundPresigId(params: {
100
+ rootId: string;
101
+ keyEpoch: bigint;
102
+ subset: ReadonlyArray<number>;
103
+ hDkg32: Uint8Array;
104
+ orderedCommitments32: ReadonlyArray<Uint8Array>;
105
+ }): Uint8Array;
106
+ /**
107
+ * Stateful single-party 4-round Beaver-masked Presignature participant (`design.md` §4.5(1)).
108
+ * Enforces strict phase ordering, non-reuse of `b_i`, and immediate zeroization of all single-use
109
+ * ephemeral scalars upon completion or any abort!
110
+ */
111
+ declare class PresignPartySession {
112
+ readonly slot: number;
113
+ readonly cluster: MpcPublicClusterInfo;
114
+ readonly subset: ReadonlyArray<number>;
115
+ readonly sessionNonce32: Uint8Array;
116
+ private readonly baseOtChannels;
117
+ private readonly rng;
118
+ private phase;
119
+ private readonly xTildeBytes32;
120
+ private readonly kBytes32;
121
+ private readonly gammaBytes32;
122
+ private readonly bBytes32;
123
+ private readonly rhoKBytes32;
124
+ private readonly zetaEsk32;
125
+ private readonly cShareBytes32;
126
+ private readonly deltaShareBytes32;
127
+ private readonly chiShareBytes32;
128
+ private ownRevealMsg;
129
+ private round1CommitmentsBySlot;
130
+ private round1RevealsBySlot;
131
+ private linearizedPublicSharesBySlot;
132
+ private presigId32;
133
+ private aggGammaPoint;
134
+ private rPoint;
135
+ private pendingOtReceiverByPeer;
136
+ private pendingOtSenderByPeer;
137
+ private verifiedOtReceiverByPeer;
138
+ private senderMtaGammaAcc;
139
+ private senderMtaBAcc;
140
+ constructor(params: {
141
+ slot: number;
142
+ nodeSecretShareBytes32: Uint8Array;
143
+ cluster: MpcPublicClusterInfo;
144
+ subset: ReadonlyArray<number>;
145
+ sessionNonce32: Uint8Array;
146
+ baseOtChannels: MpcPartyBaseOtChannels;
147
+ rng?: RandomBytesFn;
148
+ });
149
+ get isAborted(): boolean;
150
+ abort(): void;
151
+ private wipeAllEphemeralSecrets;
152
+ private assertPhase;
153
+ private pokContextParts;
154
+ /**
155
+ * Round 1a: Generates hash commitment `Com^{pre}_i` over `(\Gamma_i, B_i, C_{k,i}, \pi_\Gamma, \pi_B, \pi_{C_k})`.
156
+ */
157
+ round1CreateCommitment(): PresignRound1CommitmentMsg;
158
+ /**
159
+ * Round 1b: Locks all `t` commitments, derives subset-bound `presigId`, and reveals `Reveal^{pre}_i`.
160
+ */
161
+ round1ReceiveCommitmentsAndReveal(commitments: ReadonlyArray<PresignRound1CommitmentMsg>): {
162
+ presigId32: Uint8Array;
163
+ reveal: PresignRound1RevealMsg;
164
+ };
165
+ /**
166
+ * Verifies all `t` Round-1 reveals & PoKs, attributing `culpritSlot` on any invalid commitment or PoK.
167
+ */
168
+ round1VerifyAllReveals(reveals: ReadonlyArray<PresignRound1RevealMsg>): void;
169
+ /**
170
+ * Round 2 Step 1 (acting as Extended Receiver `B` for `(\gamma_i, b_i)` against each peer `j != i`):
171
+ * Encodes `\gamma_i` and `b_i` via LHL NUMS gadget (`768` bits + `256` sacrifice bits) and emits
172
+ * `OT-Ext Step 1` columns (`\tilde{x}_i` NEVER enters OT!).
173
+ */
174
+ round2CreateOtStep1Messages(): PresignMtaOtStep1Bundle[];
175
+ /**
176
+ * Round 2 Step 2 (acting as Extended Sender `A` against each peer `j != i`):
177
+ * Transposes `Q` and issues coin-toss `xiSeed32` challenges BEFORE touching `k_i`.
178
+ */
179
+ round2ProcessOtStep1AndCreateStep2(incomingStep1: ReadonlyArray<PresignMtaOtStep1Bundle>): PresignMtaOtStep2Bundle[];
180
+ /**
181
+ * Round 2 Step 3 (acting as Extended Receiver `B`):
182
+ * Emits `KOS15` correlation proofs `(x, T_chk)`.
183
+ */
184
+ round2ProcessOtStep2AndCreateStep3(incomingStep2: ReadonlyArray<PresignMtaOtStep2Bundle>): PresignMtaOtStep3Bundle[];
185
+ /**
186
+ * Round 2 Step 4a (acting as Extended Sender `A`):
187
+ * Runs `KOS15` check strictly BEFORE computing single-row dual-pad `GadgetMtA` messages
188
+ * anchored to Round-1 `C_{k,i}`.
189
+ */
190
+ round2VerifyKos15AndCreateMtaPayloads(incomingStep3: ReadonlyArray<PresignMtaOtStep3Bundle>): PresignMtaStep4PayloadBundle[];
191
+ /**
192
+ * Round 2 Step 4b (acting as Extended Receiver `B`):
193
+ * Verifies `C_alpha === C_{k,j}`, Pedersen openings, and all 768 single-row dual-pad checks,
194
+ * then accumulates `\delta_i` and `c_i`.
195
+ */
196
+ round2VerifyMtaPayloads(incomingMta: ReadonlyArray<PresignMtaStep4PayloadBundle>): void;
197
+ /**
198
+ * Round 3a: Reveals `(\delta_i, e_i = \tilde{x}_i - b_i mod n)` and IMMEDIATELY zeroizes
199
+ * `b_i` and `\tilde{x}_i` so `b_i` can never be reused across any abort or retry!
200
+ */
201
+ round3CreateBroadcast(): PresignRound3BroadcastMsg;
202
+ /**
203
+ * Round 3b: Verifies `e_j * G == \tilde{X}_j - B_j` (attributing exact `culpritSlot = j` on
204
+ * corruption), computes `R = \delta^{-1} \Gamma` (`R != O && R_x < n`), and derives `\chi_i`
205
+ * with pairwise cancelling `\zeta_{i,j} = -\zeta_{j,i} mod n`.
206
+ */
207
+ round3VerifyAndCreateRound4Broadcast(round3Messages: ReadonlyArray<PresignRound3BroadcastMsg>): PresignRound4BroadcastMsg;
208
+ /**
209
+ * Round 4b: Verifies `\pi^{lin}_{K,j}` and `\pi^{pok}_{Z,j}` in base `R` for every `j \in S`
210
+ * (attributing exact `culpritSlot = j` on invalid proof), checks `\sum K_j == G` and
211
+ * `\sum Z_j == P_root`, and outputs the single-use `PresignatureShareRecord`.
212
+ */
213
+ round4VerifyAndFinalize(round4Messages: ReadonlyArray<PresignRound4BroadcastMsg>): PresignatureShareRecord;
214
+ }
215
+ /**
216
+ * Volatile in-RAM single-use presignature pool (`design.md` §4.5(1), §7):
217
+ * - Synchronous `consume-before-use` atomic lock: under concurrent `Promise.all` contention,
218
+ * exact 1 caller acquires the `PresignatureShareRecord` and all others synchronously fail.
219
+ * - Strict `requestedSubset === presig.S` enforcement.
220
+ * - `wipeRoot(rootId)` / `wipeAll()` zeroize all RAM presignature scalars on Panic or shutdown.
221
+ */
222
+ declare class VolatilePresignaturePool {
223
+ private readonly activeByPresigIdHex;
224
+ private readonly tombstonedPresigIdHexes;
225
+ get size(): number;
226
+ isTombstoned(presigId: Uint8Array | string): boolean;
227
+ store(record: PresignatureShareRecord): void;
228
+ /**
229
+ * Synchronously validates `(rootId, requestedSubset)` and atomically removes + tombstones
230
+ * `presigId` in a single JS turn with zero `await` points.
231
+ */
232
+ consume(params: {
233
+ rootId: string;
234
+ presigId: Uint8Array | string;
235
+ requestedSubset: ReadonlyArray<number>;
236
+ preValidateRecord?: (record: PresignatureShareRecord) => void;
237
+ }): PresignatureShareRecord;
238
+ wipeRoot(rootId: string): number;
239
+ wipeAll(): number;
240
+ }
241
+ //#endregion
242
+ export { MpcPartyBaseOtChannels, MpcPublicClusterInfo, MtaInstanceKind, PresignMtaOtStep1Bundle, PresignMtaOtStep2Bundle, PresignMtaOtStep3Bundle, PresignMtaStep4PayloadBundle, PresignPartySession, PresignRound1CommitmentMsg, PresignRound1RevealMsg, PresignRound3BroadcastMsg, PresignRound4BroadcastMsg, PresignaturePublicVerification, PresignatureShareRecord, VolatilePresignaturePool, computeSubsetBoundPresigId };