@sig-net/midnight 0.0.1
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/README.md +20 -0
- package/dist/constants.d.ts +62 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +83 -0
- package/dist/constants.js.map +1 -0
- package/dist/epsilon-derivation.d.ts +32 -0
- package/dist/epsilon-derivation.d.ts.map +1 -0
- package/dist/epsilon-derivation.js +54 -0
- package/dist/epsilon-derivation.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/managed/compiler/contract-info.json +165 -0
- package/dist/managed/compiler/contract-manifest.json +32 -0
- package/dist/managed/contract/index.d.ts +65 -0
- package/dist/managed/contract/index.js +611 -0
- package/dist/managed/contract/index.js.map +8 -0
- package/dist/schnorr.d.ts +100 -0
- package/dist/schnorr.d.ts.map +1 -0
- package/dist/schnorr.js +144 -0
- package/dist/schnorr.js.map +1 -0
- package/dist/signature-requests-state-reader.d.ts +74 -0
- package/dist/signature-requests-state-reader.d.ts.map +1 -0
- package/dist/signature-requests-state-reader.js +167 -0
- package/dist/signature-requests-state-reader.js.map +1 -0
- package/dist/signature-response-verification.d.ts +27 -0
- package/dist/signature-response-verification.d.ts.map +1 -0
- package/dist/signature-response-verification.js +45 -0
- package/dist/signature-response-verification.js.map +1 -0
- package/dist/signature-state-reading.d.ts +36 -0
- package/dist/signature-state-reading.d.ts.map +1 -0
- package/dist/signature-state-reading.js +62 -0
- package/dist/signature-state-reading.js.map +1 -0
- package/dist/signet-contract-state-reader.d.ts +146 -0
- package/dist/signet-contract-state-reader.d.ts.map +1 -0
- package/dist/signet-contract-state-reader.js +226 -0
- package/dist/signet-contract-state-reader.js.map +1 -0
- package/dist/signet-event-observer.d.ts +102 -0
- package/dist/signet-event-observer.d.ts.map +1 -0
- package/dist/signet-event-observer.js +127 -0
- package/dist/signet-event-observer.js.map +1 -0
- package/dist/signet-events.d.ts +175 -0
- package/dist/signet-events.d.ts.map +1 -0
- package/dist/signet-events.js +210 -0
- package/dist/signet-events.js.map +1 -0
- package/dist/signet-request-feed.d.ts +78 -0
- package/dist/signet-request-feed.d.ts.map +1 -0
- package/dist/signet-request-feed.js +116 -0
- package/dist/signet-request-feed.js.map +1 -0
- package/dist/signet-request-resolver.d.ts +58 -0
- package/dist/signet-request-resolver.d.ts.map +1 -0
- package/dist/signet-request-resolver.js +76 -0
- package/dist/signet-request-resolver.js.map +1 -0
- package/dist/signet-request-response-reader.d.ts +160 -0
- package/dist/signet-request-response-reader.d.ts.map +1 -0
- package/dist/signet-request-response-reader.js +198 -0
- package/dist/signet-request-response-reader.js.map +1 -0
- package/dist/signet-requests.d.ts +363 -0
- package/dist/signet-requests.d.ts.map +1 -0
- package/dist/signet-requests.js +497 -0
- package/dist/signet-requests.js.map +1 -0
- package/dist/signet-response-feed.d.ts +161 -0
- package/dist/signet-response-feed.d.ts.map +1 -0
- package/dist/signet-response-feed.js +234 -0
- package/dist/signet-response-feed.js.map +1 -0
- package/package.json +47 -0
- package/src/Schnorr.compact +63 -0
- package/src/Signet.compact +529 -0
- package/src/circuits.compact +36 -0
- package/src/constants.ts +97 -0
- package/src/epsilon-derivation.ts +62 -0
- package/src/index.ts +31 -0
- package/src/managed/compiler/contract-info.json +165 -0
- package/src/managed/compiler/contract-manifest.json +32 -0
- package/src/managed/contract/index.d.ts +65 -0
- package/src/managed/contract/index.js +611 -0
- package/src/managed/contract/index.js.map +8 -0
- package/src/schnorr.ts +210 -0
- package/src/signature-requests-state-reader.ts +223 -0
- package/src/signature-response-verification.ts +64 -0
- package/src/signature-state-reading.ts +87 -0
- package/src/signet-contract-state-reader.ts +391 -0
- package/src/signet-event-observer.ts +186 -0
- package/src/signet-events.ts +337 -0
- package/src/signet-request-feed.ts +158 -0
- package/src/signet-request-resolver.ts +116 -0
- package/src/signet-request-response-reader.ts +324 -0
- package/src/signet-requests.ts +737 -0
- package/src/signet-response-feed.ts +325 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signet-response-feed.d.ts","sourceRoot":"","sources":["../src/signet-response-feed.ts"],"names":[],"mappings":"AAuBA,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,4BAA4B,CAAC;AAOpC,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAEL,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC7B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EACV,YAAY,EACZ,wBAAwB,EACzB,MAAM,sBAAsB,CAAC;AAE9B,8EAA8E;AAC9E,eAAO,MAAM,sCAAsC,OAAO,CAAC;AAE3D,qDAAqD;AACrD,MAAM,WAAW,wBAAwB;IACvC,qFAAqF;IACrF,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACvC,uGAAuG;IACvG,QAAQ,CAAC,wBAAwB,EAAE,MAAM,CAAC;IAC1C;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,iBAAiB,GAAG,uBAAuB,CAAC;IAC7D,4GAA4G;IAC5G,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,oHAAoH;IACpH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAED;;;;;;;;GAQG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA+C;IACxE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA8B;IACrD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IAIxC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwC;IAEhE;;;OAGG;gBACS,MAAM,EAAE,wBAAwB;IAiB5C,mEAAmE;IACnE,OAAO,CAAC,aAAa;IASrB;;;;;;;;;;;;;;;OAeG;IACG,IAAI,CACR,SAAS,EAAE,YAAY,EACvB,cAAc,EAAE,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C;CAU7C"}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
// The requesting client's entry point for discovering MPC signature responses
|
|
2
|
+
// by event observation: watch the central signet contract's
|
|
3
|
+
// SignatureRespondedEvent notifications, and when one announces a post for a
|
|
4
|
+
// request the client cares about, read the response log back and verify every
|
|
5
|
+
// post against the request — the response-direction mirror of
|
|
6
|
+
// signet-request-feed.ts. The event is only the TRIGGER for a state read; the
|
|
7
|
+
// verdicts come from the ledger via the same SignetRequestResponseReader all
|
|
8
|
+
// other consumers use, so an event/state indexing skew in either direction is
|
|
9
|
+
// tolerated (a post visible in state before its event is still yielded; an
|
|
10
|
+
// event whose write has not indexed yet is retried next cycle).
|
|
11
|
+
//
|
|
12
|
+
// Trust model (see "Signet Contract Ledger Layout" in Signet.compact): the
|
|
13
|
+
// response log is UNAUTHENTICATED — neither the event nor the stored record
|
|
14
|
+
// confers authenticity. Only the off-chain signature verification does, which
|
|
15
|
+
// is why the feed yields per-post VERDICTS rather than raw responses.
|
|
16
|
+
//
|
|
17
|
+
// The MPC's OTHER response kind — the respond-bidirectional attestation of a
|
|
18
|
+
// request's remote execution — gets the same event-gated treatment via
|
|
19
|
+
// SignetRespondBidirectionalFeed (RespondBidirectionalEvent → index read),
|
|
20
|
+
// but with the opposite trust model: the signet contract verified the
|
|
21
|
+
// attestation IN-CIRCUIT at post time, so the feed yields the stored record
|
|
22
|
+
// itself, no verdicts.
|
|
23
|
+
import { SignetEventObserver, sleepUnlessAborted, } from "./signet-event-observer.js";
|
|
24
|
+
import { respondBidirectionalEventCodec, signatureRespondedEventCodec, } from "./signet-events.js";
|
|
25
|
+
import { readSignetContractLedgerFromState, } from "./signet-contract-state-reader.js";
|
|
26
|
+
import { SignetRequestResponseReader, } from "./signet-request-response-reader.js";
|
|
27
|
+
/** Default gap between poll cycles of {@link SignetResponseFeed.verdicts}. */
|
|
28
|
+
export const DEFAULT_RESPONSE_FEED_POLL_INTERVAL_MS = 3000;
|
|
29
|
+
/**
|
|
30
|
+
* The event-driven signature response feed. Composes a
|
|
31
|
+
* {@link SignetEventObserver} of {@link SignatureRespondedEvent} notifications
|
|
32
|
+
* (discovery) with a {@link SignetRequestResponseReader} (verification),
|
|
33
|
+
* yielding one {@link SignatureResponseVerdict} per posted response, in count
|
|
34
|
+
* order, each exactly once per feed lifetime. Consumers act on the first
|
|
35
|
+
* valid verdict and surface the rejected ones as they see fit — the feed,
|
|
36
|
+
* like the reader, never logs.
|
|
37
|
+
*/
|
|
38
|
+
export class SignetResponseFeed {
|
|
39
|
+
observer;
|
|
40
|
+
reader;
|
|
41
|
+
pollIntervalMs;
|
|
42
|
+
// Post counts already yielded, per request. NOT a trust boundary (the
|
|
43
|
+
// verdicts are) — just an exactly-once gate so a post is not re-judged.
|
|
44
|
+
yielded = new Map();
|
|
45
|
+
/**
|
|
46
|
+
* @param config - The contract pair, combined event/state source, and
|
|
47
|
+
* resume floor.
|
|
48
|
+
*/
|
|
49
|
+
constructor(config) {
|
|
50
|
+
this.observer = new SignetEventObserver({
|
|
51
|
+
signetContractAddress: config.signetContractAddress,
|
|
52
|
+
source: config.source,
|
|
53
|
+
codec: signatureRespondedEventCodec,
|
|
54
|
+
fromEventId: config.fromEventId,
|
|
55
|
+
pollIntervalMs: config.pollIntervalMs,
|
|
56
|
+
});
|
|
57
|
+
this.reader = new SignetRequestResponseReader({
|
|
58
|
+
requesterContractAddress: config.requesterContractAddress,
|
|
59
|
+
signetContractAddress: config.signetContractAddress,
|
|
60
|
+
publicDataProvider: config.source,
|
|
61
|
+
});
|
|
62
|
+
this.pollIntervalMs =
|
|
63
|
+
config.pollIntervalMs ?? DEFAULT_RESPONSE_FEED_POLL_INTERVAL_MS;
|
|
64
|
+
}
|
|
65
|
+
/** The yielded-count set for `requestId`, created on first use. */
|
|
66
|
+
yieldedCounts(requestId) {
|
|
67
|
+
let counts = this.yielded.get(requestId);
|
|
68
|
+
if (counts === undefined) {
|
|
69
|
+
counts = new Set();
|
|
70
|
+
this.yielded.set(requestId, counts);
|
|
71
|
+
}
|
|
72
|
+
return counts;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* One-shot: the verdicts on every response post for `requestId` not yielded
|
|
76
|
+
* before, in count order. The response log is only read when a currently-
|
|
77
|
+
* visible event announces a post this feed has not yielded yet — no new
|
|
78
|
+
* event, no state query. Ledger posts the read then surfaces beyond the
|
|
79
|
+
* announced ones are yielded too (events are the trigger, the ledger is the
|
|
80
|
+
* source of truth), and a post whose event is visible but whose write has
|
|
81
|
+
* not indexed yet is simply retried next cycle.
|
|
82
|
+
*
|
|
83
|
+
* @param requestId - The request whose response posts to judge.
|
|
84
|
+
* @param expectedSigner - The EVM address (0x hex, any case) the genuine
|
|
85
|
+
* response must be signed by — the requester's MPC-derived address.
|
|
86
|
+
* @returns The newly-judged verdicts this cycle (possibly empty).
|
|
87
|
+
* @throws Error when either contract has no state, the request is not on
|
|
88
|
+
* the requester's ledger, or the responses ledger is inconsistent.
|
|
89
|
+
*/
|
|
90
|
+
async poll(requestId, expectedSigner) {
|
|
91
|
+
const events = await this.observer.currentEvents();
|
|
92
|
+
const counts = this.yieldedCounts(requestId);
|
|
93
|
+
const announcesNew = events.some((event) => event.requestId === requestId && !counts.has(event.count));
|
|
94
|
+
if (!announcesNew) {
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
const { verdicts } = await this.reader.getVerifiedSignatureResponse(requestId, expectedSigner);
|
|
98
|
+
const fresh = verdicts.filter((verdict) => !counts.has(verdict.count));
|
|
99
|
+
for (const verdict of fresh) {
|
|
100
|
+
counts.add(verdict.count);
|
|
101
|
+
}
|
|
102
|
+
return fresh;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Live stream: poll + sleep, yielding the verdict on each posted response
|
|
106
|
+
* exactly once, in count order, until `opts.signal` aborts. The natural
|
|
107
|
+
* consumption is to warn on each rejected verdict and act on the first
|
|
108
|
+
* valid one (see the cli's poll-signature-response command).
|
|
109
|
+
*
|
|
110
|
+
* @param requestId - The request whose response posts to judge.
|
|
111
|
+
* @param expectedSigner - The EVM address (0x hex, any case) the genuine
|
|
112
|
+
* response must be signed by — the requester's MPC-derived address.
|
|
113
|
+
* @param opts.signal - Abort to stop the stream.
|
|
114
|
+
* @yields Each post's verdict, in discovery order.
|
|
115
|
+
* @throws Error when either contract has no state, the request is not on
|
|
116
|
+
* the requester's ledger, or the responses ledger is inconsistent.
|
|
117
|
+
*/
|
|
118
|
+
async *verdicts(requestId, expectedSigner, opts) {
|
|
119
|
+
while (!opts?.signal?.aborted) {
|
|
120
|
+
const batch = await this.poll(requestId, expectedSigner);
|
|
121
|
+
for (const verdict of batch)
|
|
122
|
+
yield verdict;
|
|
123
|
+
if (opts?.signal?.aborted)
|
|
124
|
+
break;
|
|
125
|
+
await sleepUnlessAborted(this.pollIntervalMs, opts?.signal);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The request record a verdict's response answers, read through the feed's
|
|
130
|
+
* own reader (cached after the first fetch — free after any {@link poll}
|
|
131
|
+
* that reached verification). What a consumer needs to assemble the signed
|
|
132
|
+
* transaction from a valid verdict via
|
|
133
|
+
* `signBidirectionalRequestToSignedEVMTransaction`.
|
|
134
|
+
*
|
|
135
|
+
* @param requestId - The request id to look up.
|
|
136
|
+
* @returns The stored request record.
|
|
137
|
+
* @throws Error when the requester contract has no state or holds no
|
|
138
|
+
* request under `requestId`.
|
|
139
|
+
*/
|
|
140
|
+
async getSignatureRequest(requestId) {
|
|
141
|
+
return this.reader.getSignatureRequest(requestId);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The event-driven respond-bidirectional feed: composes a
|
|
146
|
+
* {@link SignetEventObserver} of {@link RespondBidirectionalEvent}
|
|
147
|
+
* notifications (discovery) with a read of the signet contract's
|
|
148
|
+
* respond-bidirectional index (the source of truth), yielding the MPC's
|
|
149
|
+
* attestation of a request's remote execution. No verdicts and no off-chain
|
|
150
|
+
* verification — the signet contract verified the attestation IN-CIRCUIT at
|
|
151
|
+
* post time (Schnorr over `(requestId, hash(serializedOutput, outputLen))`
|
|
152
|
+
* against its sealed MPC key), so the stored record is authentic by
|
|
153
|
+
* construction and there is exactly one per request (first valid write wins).
|
|
154
|
+
*/
|
|
155
|
+
export class SignetRespondBidirectionalFeed {
|
|
156
|
+
observer;
|
|
157
|
+
signetContractAddress;
|
|
158
|
+
source;
|
|
159
|
+
pollIntervalMs;
|
|
160
|
+
// Attestation records never change once stored (one authenticated slot per
|
|
161
|
+
// request, first valid write wins), so cache them across polls.
|
|
162
|
+
attestations = new Map();
|
|
163
|
+
/**
|
|
164
|
+
* @param config - The signet contract, combined event/state source, and
|
|
165
|
+
* resume floor.
|
|
166
|
+
*/
|
|
167
|
+
constructor(config) {
|
|
168
|
+
this.observer = new SignetEventObserver({
|
|
169
|
+
signetContractAddress: config.signetContractAddress,
|
|
170
|
+
source: config.source,
|
|
171
|
+
codec: respondBidirectionalEventCodec,
|
|
172
|
+
fromEventId: config.fromEventId,
|
|
173
|
+
pollIntervalMs: config.pollIntervalMs,
|
|
174
|
+
});
|
|
175
|
+
this.signetContractAddress = config.signetContractAddress;
|
|
176
|
+
this.source = config.source;
|
|
177
|
+
this.pollIntervalMs =
|
|
178
|
+
config.pollIntervalMs ?? DEFAULT_RESPONSE_FEED_POLL_INTERVAL_MS;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* One-shot: the attestation for `requestId`, or `undefined` while none is
|
|
182
|
+
* discoverable yet. The index is only read when a currently-visible event
|
|
183
|
+
* announces `requestId`'s attestation — no event, no state query. An event
|
|
184
|
+
* whose ledger write has not indexed yet is simply retried next cycle
|
|
185
|
+
* (events are the trigger, the ledger is the source of truth).
|
|
186
|
+
*
|
|
187
|
+
* @param requestId - The request whose attestation to look for.
|
|
188
|
+
* @returns The stored attestation record, or `undefined` when its event is
|
|
189
|
+
* not yet visible or its write not yet indexed.
|
|
190
|
+
* @throws Error when the signet contract has no state on-chain.
|
|
191
|
+
*/
|
|
192
|
+
async poll(requestId) {
|
|
193
|
+
const cached = this.attestations.get(requestId);
|
|
194
|
+
if (cached !== undefined) {
|
|
195
|
+
return cached;
|
|
196
|
+
}
|
|
197
|
+
const events = await this.observer.currentEvents();
|
|
198
|
+
if (!events.some((event) => event.requestId === requestId)) {
|
|
199
|
+
return undefined;
|
|
200
|
+
}
|
|
201
|
+
const state = await this.source.queryContractState(this.signetContractAddress);
|
|
202
|
+
if (!state?.data) {
|
|
203
|
+
throw new Error(`no state data found for signet contract '${this.signetContractAddress}' - is it deployed?`);
|
|
204
|
+
}
|
|
205
|
+
const record = readSignetContractLedgerFromState(state.data).respondBidirectionalIndex.get(requestId);
|
|
206
|
+
if (record === undefined) {
|
|
207
|
+
return undefined;
|
|
208
|
+
}
|
|
209
|
+
this.attestations.set(requestId, record);
|
|
210
|
+
return record;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Live wait: poll + sleep until `requestId`'s attestation is discoverable,
|
|
214
|
+
* and return it. Runs until `opts.signal` aborts — the caller owns the
|
|
215
|
+
* give-up policy (see the cli's poll-respond-bidirectional command).
|
|
216
|
+
*
|
|
217
|
+
* @param requestId - The request whose attestation to wait for.
|
|
218
|
+
* @param opts.signal - Abort to stop waiting.
|
|
219
|
+
* @returns The stored attestation record, or `undefined` when aborted
|
|
220
|
+
* before one was discovered.
|
|
221
|
+
* @throws Error when the signet contract has no state on-chain.
|
|
222
|
+
*/
|
|
223
|
+
async attestation(requestId, opts) {
|
|
224
|
+
while (!opts?.signal?.aborted) {
|
|
225
|
+
const record = await this.poll(requestId);
|
|
226
|
+
if (record !== undefined) {
|
|
227
|
+
return record;
|
|
228
|
+
}
|
|
229
|
+
await sleepUnlessAborted(this.pollIntervalMs, opts?.signal);
|
|
230
|
+
}
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
//# sourceMappingURL=signet-response-feed.js.map
|
|
@@ -0,0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B,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK,CAAC,WAAW,CACf,SAAuB,EACvB,IAA+B;QAE/B,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;YAC9B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC1C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACzB,OAAO,MAAM,CAAC;YAChB,CAAC;YACD,MAAM,kBAAkB,CAAC,IAAI,CAAC,cAAc,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAC9D,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sig-net/midnight",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Midnight-side sig-net integration — the seed of a future signet.js Midnight adapter.",
|
|
6
|
+
"//exports": "Local dev consumes raw TS source. `publishConfig.exports` below swaps this to the emitted ./dist at publish time, so npm consumers get JS + .d.ts while the monorepo keeps resolving to src.",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"src"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"compile": "compact compile --skip-zk src/circuits.compact src/managed",
|
|
19
|
+
"build": "rm -rf dist && tsc -p tsconfig.json && tsc -p tsconfig.build.json && cp -R src/managed dist/managed",
|
|
20
|
+
"prepack": "yarn build",
|
|
21
|
+
"test": "vitest run --passWithNoTests"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public",
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"default": "./dist/index.js"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@midnight-ntwrk/compact-runtime": "0.18.0-rc.0",
|
|
36
|
+
"@midnight-ntwrk/midnight-js-types": "5.0.0-beta.3",
|
|
37
|
+
"@noble/curves": "^2.2.0",
|
|
38
|
+
"ethers": "^6.17.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "^26.1.0",
|
|
42
|
+
"typescript": "^6.0.3",
|
|
43
|
+
"vitest": "^4.1.9"
|
|
44
|
+
},
|
|
45
|
+
"main": "./dist/index.js",
|
|
46
|
+
"types": "./dist/index.d.ts"
|
|
47
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Schnorr — shared Compact library: the off-chain-callable challenge circuit
|
|
3
|
+
// for Schnorr signatures on the Jubjub curve embedded in BLS12-381.
|
|
4
|
+
// ============================================================================
|
|
5
|
+
// Verification itself is CompactStandardLibrary's `jubjubSchnorrVerify`
|
|
6
|
+
// (contracts call it directly). The standard library keeps its challenge
|
|
7
|
+
// hashing internal, but off-chain SIGNERS need the same challenge value to
|
|
8
|
+
// compute the response scalar, so this module exports it as a pure circuit
|
|
9
|
+
// (compiled via circuits.compact) — never a TS re-implementation.
|
|
10
|
+
//
|
|
11
|
+
// `SchnorrHashInput` mirrors the standard library's internal
|
|
12
|
+
// `JubjubSchnorrHashInput` field-for-field; the signet-midnight sign→verify
|
|
13
|
+
// round-trip test (schnorrSign + contract-side jubjubSchnorrVerify) keeps the
|
|
14
|
+
// two in agreement.
|
|
15
|
+
//
|
|
16
|
+
// The sig-net MPC attests remote EVM execution by Schnorr-signing a message
|
|
17
|
+
// on Jubjub (see signetAttestationMessage in Signet.compact); contracts
|
|
18
|
+
// verify that signature in-circuit — the signet contract at post time, the
|
|
19
|
+
// vault again at claim time. The challenge is Poseidon (transientHash), so
|
|
20
|
+
// off-chain signers MUST compute it through the COMPILED schnorrChallenge
|
|
21
|
+
// pure circuit (re-exported via circuits.compact).
|
|
22
|
+
//
|
|
23
|
+
// Import from a contract (resolved through node_modules via COMPACT_PATH —
|
|
24
|
+
// see the consuming package's compile script):
|
|
25
|
+
// import "@sig-net/midnight/src/Schnorr" prefix Schnorr_;
|
|
26
|
+
//
|
|
27
|
+
// This file must contain ONLY this module (plus comments) so the compiler
|
|
28
|
+
// accepts it as an external module import.
|
|
29
|
+
|
|
30
|
+
module Schnorr {
|
|
31
|
+
import CompactStandardLibrary;
|
|
32
|
+
|
|
33
|
+
// The tuple Poseidon-hashed into the challenge: both points' coordinates
|
|
34
|
+
// then the message limbs, in exactly this order — the wire format the MPC
|
|
35
|
+
// signs against (identical to the standard library's internal
|
|
36
|
+
// JubjubSchnorrHashInput). Never reorder.
|
|
37
|
+
struct SchnorrHashInput<#n> {
|
|
38
|
+
ann_x: Field;
|
|
39
|
+
ann_y: Field;
|
|
40
|
+
pk_x: Field;
|
|
41
|
+
pk_y: Field;
|
|
42
|
+
msg: Vector<n, Field>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// The Schnorr challenge as `jubjubSchnorrVerify` computes it: the Poseidon
|
|
46
|
+
// transientHash of (R, pk, msg), reduced into Jubjub's scalar field (the
|
|
47
|
+
// `as JubjubScalar` cast reduces mod the Jubjub subgroup order; the cast
|
|
48
|
+
// back to Field is exact). Off-chain signers use the returned value
|
|
49
|
+
// directly: s = (k + c * sk) mod JUBJUB_ORDER.
|
|
50
|
+
export pure circuit schnorrChallenge(
|
|
51
|
+
ann_x: Field,
|
|
52
|
+
ann_y: Field,
|
|
53
|
+
pk_x: Field,
|
|
54
|
+
pk_y: Field,
|
|
55
|
+
msg: Vector<4, Field>
|
|
56
|
+
): Field {
|
|
57
|
+
const cFull: Field =
|
|
58
|
+
transientHash<SchnorrHashInput<4>>(
|
|
59
|
+
SchnorrHashInput<4> { ann_x: ann_x, ann_y: ann_y, pk_x: pk_x, pk_y: pk_y, msg: msg }
|
|
60
|
+
);
|
|
61
|
+
return (cFull as JubjubScalar) as Field;
|
|
62
|
+
}
|
|
63
|
+
}
|