@sig-net/midnight 0.0.1 → 0.0.3
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/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -4
- package/dist/index.js.map +1 -1
- package/dist/managed/compiler/contract-info.json +57 -0
- package/dist/managed/compiler/contract-manifest.json +8 -8
- package/dist/managed/contract/index.d.ts +13 -0
- package/dist/managed/contract/index.js +138 -73
- package/dist/managed/contract/index.js.map +1 -1
- package/dist/signature-requests-state-reader.d.ts +5 -5
- package/dist/signature-requests-state-reader.js +5 -5
- package/dist/signet-contract-state-reader.d.ts +88 -2
- package/dist/signet-contract-state-reader.d.ts.map +1 -1
- package/dist/signet-contract-state-reader.js +106 -3
- package/dist/signet-contract-state-reader.js.map +1 -1
- package/dist/signet-request-feed.d.ts +40 -21
- package/dist/signet-request-feed.d.ts.map +1 -1
- package/dist/signet-request-feed.js +79 -34
- package/dist/signet-request-feed.js.map +1 -1
- package/dist/signet-request-resolver.d.ts +11 -11
- package/dist/signet-request-resolver.d.ts.map +1 -1
- package/dist/signet-request-resolver.js +22 -22
- package/dist/signet-request-resolver.js.map +1 -1
- package/dist/signet-requests.d.ts +18 -4
- package/dist/signet-requests.d.ts.map +1 -1
- package/dist/signet-requests.js +29 -6
- package/dist/signet-requests.js.map +1 -1
- package/package.json +2 -2
- package/src/Signet.compact +75 -99
- package/src/circuits.compact +5 -2
- package/dist/signet-event-observer.d.ts +0 -102
- package/dist/signet-event-observer.d.ts.map +0 -1
- package/dist/signet-event-observer.js +0 -127
- package/dist/signet-event-observer.js.map +0 -1
- package/dist/signet-events.d.ts +0 -175
- package/dist/signet-events.d.ts.map +0 -1
- package/dist/signet-events.js +0 -210
- package/dist/signet-events.js.map +0 -1
- package/dist/signet-response-feed.d.ts +0 -161
- package/dist/signet-response-feed.d.ts.map +0 -1
- package/dist/signet-response-feed.js +0 -234
- package/dist/signet-response-feed.js.map +0 -1
- package/src/constants.ts +0 -97
- package/src/epsilon-derivation.ts +0 -62
- package/src/index.ts +0 -31
- package/src/managed/compiler/contract-info.json +0 -165
- package/src/managed/compiler/contract-manifest.json +0 -32
- package/src/managed/contract/index.d.ts +0 -65
- package/src/managed/contract/index.js +0 -611
- package/src/managed/contract/index.js.map +0 -8
- package/src/schnorr.ts +0 -210
- package/src/signature-requests-state-reader.ts +0 -223
- package/src/signature-response-verification.ts +0 -64
- package/src/signature-state-reading.ts +0 -87
- package/src/signet-contract-state-reader.ts +0 -391
- package/src/signet-event-observer.ts +0 -186
- package/src/signet-events.ts +0 -337
- package/src/signet-request-feed.ts +0 -158
- package/src/signet-request-resolver.ts +0 -116
- package/src/signet-request-response-reader.ts +0 -324
- package/src/signet-requests.ts +0 -737
- package/src/signet-response-feed.ts +0 -325
|
@@ -9,6 +9,8 @@ export declare const SIGNATURE_RESPONSE_INDEX_FIELD = 1;
|
|
|
9
9
|
export declare const RESPOND_BIDIRECTIONAL_INDEX_FIELD = 2;
|
|
10
10
|
/** Signet contract layout: the sealed MPC attestation key hash is ledger field 3. */
|
|
11
11
|
export declare const MPC_PUB_KEY_HASH_FIELD = 3;
|
|
12
|
+
/** Signet contract layout: the request notification registry is ledger field 4. */
|
|
13
|
+
export declare const SIGN_BIDIRECTIONAL_NOTIFICATION_INDEX_FIELD = 4;
|
|
12
14
|
/**
|
|
13
15
|
* The MPC's secp256k1 signature over the requested EVM transaction (Compact
|
|
14
16
|
* `SignatureResponse` — the canonical MPC `Signature { big_r, s,
|
|
@@ -75,6 +77,70 @@ export declare const signetResponseKeyType: CompactType<SignetResponseKey>;
|
|
|
75
77
|
* the Compact struct.
|
|
76
78
|
*/
|
|
77
79
|
export declare const respondBidirectionalType: CompactType<RespondBidirectional>;
|
|
80
|
+
/**
|
|
81
|
+
* Raw twin of the Compact `SignBidirectionalNotification` struct as stored
|
|
82
|
+
* on-ledger: the version tag plus the still-packed 65-byte payload. Decode
|
|
83
|
+
* the payload with {@link decodeSignBidirectionalNotification}.
|
|
84
|
+
*/
|
|
85
|
+
export interface SignBidirectionalNotificationRecord {
|
|
86
|
+
/** Payload layout tag (Compact `Uint<8>`); 1 = the V1 layout. */
|
|
87
|
+
version: bigint;
|
|
88
|
+
/** The packed payload bytes, exactly as the registering circuit built them. */
|
|
89
|
+
payload: Uint8Array;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Hand-composed descriptor for {@link SignBidirectionalNotificationRecord}.
|
|
93
|
+
* Field order (version, payload) must match the Compact struct.
|
|
94
|
+
*/
|
|
95
|
+
export declare const signBidirectionalNotificationType: CompactType<SignBidirectionalNotificationRecord>;
|
|
96
|
+
/**
|
|
97
|
+
* A decoded V1 notification from the signet contract's registry: the flat
|
|
98
|
+
* pointer a client registered to tell the MPC a request was stored — and
|
|
99
|
+
* WHERE to read the authenticated copy. Never trusted on its own: the
|
|
100
|
+
* resolver authenticates by reading the request back from
|
|
101
|
+
* {@link callerAddress}'s own ledger (see signet-request-resolver.ts).
|
|
102
|
+
*/
|
|
103
|
+
export interface SignBidirectionalNotification {
|
|
104
|
+
/** Payload layout tag; this decoder only produces version 1. */
|
|
105
|
+
version: number;
|
|
106
|
+
/**
|
|
107
|
+
* Address of the contract whose request index holds the request, rendered
|
|
108
|
+
* as lowercase hex, no `0x` prefix — directly usable as a
|
|
109
|
+
* `queryContractState` argument. The MPC reads the request from THIS
|
|
110
|
+
* contract's authenticated state; the field itself confers no authority.
|
|
111
|
+
*/
|
|
112
|
+
callerAddress: string;
|
|
113
|
+
/** Which request in {@link callerAddress}'s index this notification is about. */
|
|
114
|
+
requestId: RequestIdHex;
|
|
115
|
+
/**
|
|
116
|
+
* Ledger field position of the `Map<RequestId, SignBidirectionalRequest>`
|
|
117
|
+
* request index in {@link callerAddress} (the signet layout convention puts
|
|
118
|
+
* it at field 0, but the notification carries it so the reader never assumes).
|
|
119
|
+
*/
|
|
120
|
+
requestsIndexField: number;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Unpack a stored {@link SignBidirectionalNotificationRecord}'s payload by
|
|
124
|
+
* the fixed V1 offsets — the decode twin of the compiled
|
|
125
|
+
* `constructSignBidirectionalNotificationV1` circuit (byte plumbing only; the
|
|
126
|
+
* pack↔decode lockstep is pinned by the state-reader unit test that round-trips
|
|
127
|
+
* through the real circuit).
|
|
128
|
+
*
|
|
129
|
+
* Fails closed on an unrecognised `version`: a future payload layout adds a
|
|
130
|
+
* branch here rather than silently misinterpreting bytes under the V1 offsets.
|
|
131
|
+
*
|
|
132
|
+
* @param record - The raw on-ledger record.
|
|
133
|
+
* @returns The decoded flat notification.
|
|
134
|
+
* @throws Error if the record's `version` is not one this decoder understands.
|
|
135
|
+
*/
|
|
136
|
+
export declare function decodeSignBidirectionalNotification(record: SignBidirectionalNotificationRecord): SignBidirectionalNotification;
|
|
137
|
+
/**
|
|
138
|
+
* Plain-JS notification registry parsed out of the ledger: hex request id
|
|
139
|
+
* (the map KEY under which the notification was registered) to the raw
|
|
140
|
+
* stored record. Decode each record with
|
|
141
|
+
* {@link decodeSignBidirectionalNotification}.
|
|
142
|
+
*/
|
|
143
|
+
export type SignBidirectionalNotificationIndex = Map<RequestIdHex, SignBidirectionalNotificationRecord>;
|
|
78
144
|
/**
|
|
79
145
|
* Plain-JS signature response counter index parsed out of the ledger: hex
|
|
80
146
|
* request id (see {@link requestIdHex}) to the number of responses posted for
|
|
@@ -102,11 +168,25 @@ export type RespondBidirectionalIndex = Map<RequestIdHex, RespondBidirectional>;
|
|
|
102
168
|
* @returns `"<hexRequestId>:<count>"`.
|
|
103
169
|
*/
|
|
104
170
|
export declare function signetResponseIndexKey(id: RequestIdHex, count: bigint): string;
|
|
171
|
+
/**
|
|
172
|
+
* Read ONLY the notification registry (ledger field
|
|
173
|
+
* {@link SIGN_BIDIRECTIONAL_NOTIFICATION_INDEX_FIELD}) out of raw signet
|
|
174
|
+
* contract state — the poll-loop primitive of {@link SignetRequestFeed},
|
|
175
|
+
* which cycles frequently and has no use for the response fields.
|
|
176
|
+
*
|
|
177
|
+
* @param raw - Raw contract state, e.g. `queryContractState(address).data`
|
|
178
|
+
* from the indexer or `ctx.currentQueryContext.state` from the simulator.
|
|
179
|
+
* @returns The registry, keyed by the hex request id each record was
|
|
180
|
+
* registered under.
|
|
181
|
+
* @throws Error if the field is missing or is not a Map.
|
|
182
|
+
*/
|
|
183
|
+
export declare function readSignBidirectionalNotificationIndexFromState(raw: RawContractState): SignBidirectionalNotificationIndex;
|
|
105
184
|
/**
|
|
106
185
|
* The decoded ledger fields of the signet contract: the signature response
|
|
107
186
|
* counter (field 0) and log (field 1), the respond-bidirectional index
|
|
108
|
-
* (field 2),
|
|
109
|
-
*
|
|
187
|
+
* (field 2), the sealed MPC attestation key hash (field 3), and the request
|
|
188
|
+
* notification registry (field 4). Together they give a poller everything
|
|
189
|
+
* the contract ever records about a request.
|
|
110
190
|
*/
|
|
111
191
|
export interface SignetContractLedger {
|
|
112
192
|
/**
|
|
@@ -130,6 +210,12 @@ export interface SignetContractLedger {
|
|
|
130
210
|
* {@link MPC_PUB_KEY_HASH_FIELD}) posts are verified against.
|
|
131
211
|
*/
|
|
132
212
|
mpcPubKeyHash: Uint8Array;
|
|
213
|
+
/**
|
|
214
|
+
* The request notification registry (ledger field
|
|
215
|
+
* {@link SIGN_BIDIRECTIONAL_NOTIFICATION_INDEX_FIELD}), keyed by hex
|
|
216
|
+
* request id.
|
|
217
|
+
*/
|
|
218
|
+
signBidirectionalNotificationIndex: SignBidirectionalNotificationIndex;
|
|
133
219
|
}
|
|
134
220
|
/**
|
|
135
221
|
* MPC-/client-style read: parse the signet contract's ledger fields out of
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signet-contract-state-reader.d.ts","sourceRoot":"","sources":["../src/signet-contract-state-reader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"signet-contract-state-reader.d.ts","sourceRoot":"","sources":["../src/signet-contract-state-reader.ts"],"names":[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gB,GACpB,kCAAkC,CAsBpC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,6BAA6B,EAAE,6BAA6B,CAAC;IAC7D;;;;OAIG;IACH,sBAAsB,EAAE,sBAAsB,CAAC;IAC/C;;;OAGG;IACH,yBAAyB,EAAE,yBAAyB,CAAC;IACrD;;;OAGG;IACH,aAAa,EAAE,UAAU,CAAC;IAC1B;;;;OAIG;IACH,kCAAkC,EAAE,kCAAkC,CAAC;CACxE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iCAAiC,CAC/C,GAAG,EAAE,gBAAgB,GACpB,oBAAoB,CA4EtB"}
|
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
// layout convention (see "Signet Contract Ledger Layout" in Signet.compact):
|
|
7
7
|
// signature response counter index (field 0), signature response log
|
|
8
8
|
// (field 1), respond-bidirectional index (field 2), sealed MPC key hash
|
|
9
|
-
// (field 3). The generic state-tree walk
|
|
10
|
-
// and the shared base descriptors live in
|
|
9
|
+
// (field 3), notification registry (field 4). The generic state-tree walk
|
|
10
|
+
// (RawContractState, signetFieldNode) and the shared base descriptors live in
|
|
11
|
+
// signature-state-reading.ts.
|
|
11
12
|
import { CompactTypeBytes, CompactTypeField, CompactTypeJubjubPoint, CompactTypeUnsignedInteger, } from "@midnight-ntwrk/compact-runtime";
|
|
12
|
-
import { requestIdHex, } from "./signet-requests.js";
|
|
13
|
+
import { bytesToHex, requestIdHex, } from "./signet-requests.js";
|
|
13
14
|
import { requestIdType, signetFieldNode, u64, } from "./signature-state-reading.js";
|
|
14
15
|
/** Signet contract layout: the signature response counter index is ledger field 0. */
|
|
15
16
|
export const SIGNATURE_RESPONSE_COUNTER_INDEX_FIELD = 0;
|
|
@@ -19,6 +20,8 @@ export const SIGNATURE_RESPONSE_INDEX_FIELD = 1;
|
|
|
19
20
|
export const RESPOND_BIDIRECTIONAL_INDEX_FIELD = 2;
|
|
20
21
|
/** Signet contract layout: the sealed MPC attestation key hash is ledger field 3. */
|
|
21
22
|
export const MPC_PUB_KEY_HASH_FIELD = 3;
|
|
23
|
+
/** Signet contract layout: the request notification registry is ledger field 4. */
|
|
24
|
+
export const SIGN_BIDIRECTIONAL_NOTIFICATION_INDEX_FIELD = 4;
|
|
22
25
|
// ---- Type descriptors (must mirror Signet.compact field-for-field) ----
|
|
23
26
|
// As in the requests reader, fromValue consumes the aligned value
|
|
24
27
|
// sequentially, so field order and width here must match the Compact structs
|
|
@@ -149,6 +152,77 @@ export const respondBidirectionalType = {
|
|
|
149
152
|
.concat(CompactTypeField.toValue(record.response));
|
|
150
153
|
},
|
|
151
154
|
};
|
|
155
|
+
/** Descriptor for the notification's packed V1 payload (`Bytes<65>`). */
|
|
156
|
+
const bytes65 = new CompactTypeBytes(65);
|
|
157
|
+
/**
|
|
158
|
+
* Hand-composed descriptor for {@link SignBidirectionalNotificationRecord}.
|
|
159
|
+
* Field order (version, payload) must match the Compact struct.
|
|
160
|
+
*/
|
|
161
|
+
export const signBidirectionalNotificationType = {
|
|
162
|
+
/** @returns Compound alignment of the struct's fields in declaration order. */
|
|
163
|
+
alignment() {
|
|
164
|
+
return u8.alignment().concat(bytes65.alignment());
|
|
165
|
+
},
|
|
166
|
+
/**
|
|
167
|
+
* Decode one notification record from an aligned value, consuming it
|
|
168
|
+
* field by field.
|
|
169
|
+
*
|
|
170
|
+
* @param value - Mutable aligned value cursor; pass a copy.
|
|
171
|
+
* @returns The decoded record.
|
|
172
|
+
*/
|
|
173
|
+
fromValue(value) {
|
|
174
|
+
return {
|
|
175
|
+
version: u8.fromValue(value),
|
|
176
|
+
payload: bytes65.fromValue(value),
|
|
177
|
+
};
|
|
178
|
+
},
|
|
179
|
+
/**
|
|
180
|
+
* Encode a notification record into its aligned on-ledger representation.
|
|
181
|
+
*
|
|
182
|
+
* @param record - The record to encode.
|
|
183
|
+
* @returns The aligned value, fields concatenated in declaration order.
|
|
184
|
+
*/
|
|
185
|
+
toValue(record) {
|
|
186
|
+
return u8.toValue(record.version).concat(bytes65.toValue(record.payload));
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
/** Offset of the V1 `callerAddress` in the packed payload (`Bytes<32>` at the front). */
|
|
190
|
+
const NOTIFICATION_CALLER_ADDRESS_OFFSET = 0;
|
|
191
|
+
/** Offset of the V1 `requestId` (after the 32 callerAddress bytes). */
|
|
192
|
+
const NOTIFICATION_REQUEST_ID_OFFSET = 32;
|
|
193
|
+
/** Offset of the V1 `requestsIndexField` (after callerAddress + requestId). */
|
|
194
|
+
const NOTIFICATION_REQUESTS_INDEX_FIELD_OFFSET = 64;
|
|
195
|
+
/** The only payload interpretation {@link decodeSignBidirectionalNotification} understands today. */
|
|
196
|
+
const SUPPORTED_NOTIFICATION_VERSION = 1n;
|
|
197
|
+
/**
|
|
198
|
+
* Unpack a stored {@link SignBidirectionalNotificationRecord}'s payload by
|
|
199
|
+
* the fixed V1 offsets — the decode twin of the compiled
|
|
200
|
+
* `constructSignBidirectionalNotificationV1` circuit (byte plumbing only; the
|
|
201
|
+
* pack↔decode lockstep is pinned by the state-reader unit test that round-trips
|
|
202
|
+
* through the real circuit).
|
|
203
|
+
*
|
|
204
|
+
* Fails closed on an unrecognised `version`: a future payload layout adds a
|
|
205
|
+
* branch here rather than silently misinterpreting bytes under the V1 offsets.
|
|
206
|
+
*
|
|
207
|
+
* @param record - The raw on-ledger record.
|
|
208
|
+
* @returns The decoded flat notification.
|
|
209
|
+
* @throws Error if the record's `version` is not one this decoder understands.
|
|
210
|
+
*/
|
|
211
|
+
export function decodeSignBidirectionalNotification(record) {
|
|
212
|
+
if (record.version !== SUPPORTED_NOTIFICATION_VERSION) {
|
|
213
|
+
throw new Error(`SignBidirectionalNotification version ${record.version} is not supported ` +
|
|
214
|
+
`(this decoder understands version ${SUPPORTED_NOTIFICATION_VERSION})`);
|
|
215
|
+
}
|
|
216
|
+
const callerAddress = bytesToHex(record.payload.slice(NOTIFICATION_CALLER_ADDRESS_OFFSET, NOTIFICATION_REQUEST_ID_OFFSET));
|
|
217
|
+
const requestId = requestIdHex(record.payload.slice(NOTIFICATION_REQUEST_ID_OFFSET, NOTIFICATION_REQUESTS_INDEX_FIELD_OFFSET));
|
|
218
|
+
const requestsIndexField = record.payload[NOTIFICATION_REQUESTS_INDEX_FIELD_OFFSET];
|
|
219
|
+
return {
|
|
220
|
+
version: Number(record.version),
|
|
221
|
+
callerAddress,
|
|
222
|
+
requestId,
|
|
223
|
+
requestsIndexField,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
152
226
|
/**
|
|
153
227
|
* Build the {@link SignatureResponseIndex} key for a `(requestId, count)`
|
|
154
228
|
* pair — the composite Compact key flattened to a string so it works as a JS
|
|
@@ -161,6 +235,34 @@ export const respondBidirectionalType = {
|
|
|
161
235
|
export function signetResponseIndexKey(id, count) {
|
|
162
236
|
return `${id}:${count}`;
|
|
163
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* Read ONLY the notification registry (ledger field
|
|
240
|
+
* {@link SIGN_BIDIRECTIONAL_NOTIFICATION_INDEX_FIELD}) out of raw signet
|
|
241
|
+
* contract state — the poll-loop primitive of {@link SignetRequestFeed},
|
|
242
|
+
* which cycles frequently and has no use for the response fields.
|
|
243
|
+
*
|
|
244
|
+
* @param raw - Raw contract state, e.g. `queryContractState(address).data`
|
|
245
|
+
* from the indexer or `ctx.currentQueryContext.state` from the simulator.
|
|
246
|
+
* @returns The registry, keyed by the hex request id each record was
|
|
247
|
+
* registered under.
|
|
248
|
+
* @throws Error if the field is missing or is not a Map.
|
|
249
|
+
*/
|
|
250
|
+
export function readSignBidirectionalNotificationIndexFromState(raw) {
|
|
251
|
+
const notificationMap = signetFieldNode(raw, SIGN_BIDIRECTIONAL_NOTIFICATION_INDEX_FIELD).asMap();
|
|
252
|
+
if (notificationMap === undefined) {
|
|
253
|
+
throw new Error(`Ledger field ${SIGN_BIDIRECTIONAL_NOTIFICATION_INDEX_FIELD} is not a Map`);
|
|
254
|
+
}
|
|
255
|
+
const index = new Map();
|
|
256
|
+
for (const key of notificationMap.keys()) {
|
|
257
|
+
// fromValue consumes its input, so hand each descriptor a copy.
|
|
258
|
+
const requestId = requestIdType.fromValue([...key.value]);
|
|
259
|
+
const cell = notificationMap.get(key)?.asCell();
|
|
260
|
+
if (cell === undefined)
|
|
261
|
+
continue;
|
|
262
|
+
index.set(requestIdHex(requestId), signBidirectionalNotificationType.fromValue([...cell.value]));
|
|
263
|
+
}
|
|
264
|
+
return index;
|
|
265
|
+
}
|
|
164
266
|
/**
|
|
165
267
|
* MPC-/client-style read: parse the signet contract's ledger fields out of
|
|
166
268
|
* raw contract state by field position alone — no compiled contract, no
|
|
@@ -221,6 +323,7 @@ export function readSignetContractLedgerFromState(raw) {
|
|
|
221
323
|
signatureResponseIndex,
|
|
222
324
|
respondBidirectionalIndex,
|
|
223
325
|
mpcPubKeyHash,
|
|
326
|
+
signBidirectionalNotificationIndex: readSignBidirectionalNotificationIndexFromState(raw),
|
|
224
327
|
};
|
|
225
328
|
}
|
|
226
329
|
//# sourceMappingURL=signet-contract-state-reader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signet-contract-state-reader.js","sourceRoot":"","sources":["../src/signet-contract-state-reader.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,uEAAuE;AACvE,6EAA6E;AAC7E,oEAAoE;AACpE,yEAAyE;AACzE,6EAA6E;AAC7E,qEAAqE;AACrE,wEAAwE;AACxE,
|
|
1
|
+
{"version":3,"file":"signet-contract-state-reader.js","sourceRoot":"","sources":["../src/signet-contract-state-reader.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,uEAAuE;AACvE,6EAA6E;AAC7E,oEAAoE;AACpE,yEAAyE;AACzE,6EAA6E;AAC7E,qEAAqE;AACrE,wEAAwE;AACxE,0EAA0E;AAC1E,8EAA8E;AAC9E,8BAA8B;AAE9B,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,EACtB,0BAA0B,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
1
|
-
import { type SignetEventSource } from "./signet-event-observer.ts";
|
|
2
1
|
import { type ResolvedSignetRequest } from "./signet-request-resolver.ts";
|
|
3
2
|
import type { SignetPublicStateSource } from "./signet-request-response-reader.ts";
|
|
4
|
-
import type
|
|
3
|
+
import { type RequestIdHex } from "./signet-requests.ts";
|
|
5
4
|
/** Default gap between poll cycles of {@link SignetRequestFeed.requests}. */
|
|
6
5
|
export declare const DEFAULT_FEED_POLL_INTERVAL_MS = 3000;
|
|
7
6
|
/** Everything a {@link SignetRequestFeed} needs. */
|
|
8
7
|
export interface SignetRequestFeedConfig {
|
|
9
|
-
/** Address of the central signet contract whose
|
|
8
|
+
/** Address of the central signet contract whose notification registry to poll. */
|
|
10
9
|
readonly signetContractAddress: string;
|
|
11
10
|
/**
|
|
12
|
-
* Source of
|
|
13
|
-
*
|
|
11
|
+
* Source of raw contract state for BOTH the signet contract's registry and
|
|
12
|
+
* the requester ledgers the resolver authenticates against — a full
|
|
13
|
+
* `indexerPublicDataProvider` is assignable.
|
|
14
14
|
*/
|
|
15
|
-
readonly source:
|
|
15
|
+
readonly source: SignetPublicStateSource;
|
|
16
16
|
/**
|
|
17
17
|
* Optional policy allow-list of requester contract addresses to serve
|
|
18
18
|
* (matched case- and `0x`-prefix-insensitively). Omit to serve every
|
|
19
19
|
* requester the resolver can authenticate. NOT a security control.
|
|
20
20
|
*/
|
|
21
21
|
readonly allowContracts?: Iterable<string>;
|
|
22
|
-
/** Durable resume floor for the underlying observer (see {@link SignetEventObserverConfig.fromEventId}). */
|
|
23
|
-
readonly fromEventId?: number;
|
|
24
22
|
/** Poll cadence for {@link SignetRequestFeed.requests}; default {@link DEFAULT_FEED_POLL_INTERVAL_MS}. */
|
|
25
23
|
readonly pollIntervalMs?: number;
|
|
26
24
|
}
|
|
27
25
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
26
|
+
* Resolve after `ms`, or immediately once `signal` aborts. Used to space out
|
|
27
|
+
* polls without wedging a shutdown.
|
|
28
|
+
*
|
|
29
|
+
* @param ms - Milliseconds to wait.
|
|
30
|
+
* @param signal - Abort to resolve early.
|
|
31
|
+
* @returns A promise that settles after the delay or the abort.
|
|
32
|
+
*/
|
|
33
|
+
export declare function sleepUnlessAborted(ms: number, signal?: AbortSignal): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* The registry-polling request feed. Reads the signet contract's notification
|
|
36
|
+
* registry (discovery) and hands each notification to a
|
|
37
|
+
* {@link SignetRequestResolver} (authentication), yielding only notifications
|
|
38
|
+
* that resolve to a real, member request. Dedupes by request id across its
|
|
39
|
+
* lifetime, so a re-registered notification is not re-yielded; call
|
|
32
40
|
* {@link forget} to re-arm a request whose downstream processing failed.
|
|
33
41
|
*/
|
|
34
42
|
export declare class SignetRequestFeed {
|
|
35
|
-
private readonly
|
|
43
|
+
private readonly signetContractAddress;
|
|
44
|
+
private readonly source;
|
|
36
45
|
private readonly resolver;
|
|
37
46
|
private readonly allowContracts?;
|
|
38
47
|
private readonly pollIntervalMs;
|
|
39
48
|
private readonly yielded;
|
|
40
49
|
/**
|
|
41
|
-
* @param config - The signet contract,
|
|
42
|
-
*
|
|
50
|
+
* @param config - The signet contract, state source, and optional policy
|
|
51
|
+
* allow-list.
|
|
43
52
|
*/
|
|
44
53
|
constructor(config: SignetRequestFeedConfig);
|
|
45
54
|
/** Whether the policy allow-list admits `callerAddress` (always true when unset). */
|
|
46
55
|
private allowed;
|
|
47
56
|
/**
|
|
48
|
-
* One-shot: every currently-
|
|
49
|
-
* allow-list, not already yielded, and resolves to an
|
|
50
|
-
* request.
|
|
51
|
-
*
|
|
52
|
-
*
|
|
57
|
+
* One-shot: every currently-registered notification that decodes, is
|
|
58
|
+
* admitted by the allow-list, not already yielded, and resolves to an
|
|
59
|
+
* authenticated member request. Registry enumeration has no meaningful
|
|
60
|
+
* on-ledger order, so entries are processed in ascending request-id-hex
|
|
61
|
+
* order — a stable, deterministic sequence. Forged / not-yet-indexed /
|
|
62
|
+
* wrong-field notifications resolve to nothing and are dropped WITHOUT
|
|
63
|
+
* being marked yielded, so a genuine request whose ledger write has not
|
|
64
|
+
* indexed yet is retried next cycle; undecodable or unsupported-version
|
|
65
|
+
* records are likewise skipped (and logged) without being marked.
|
|
66
|
+
*
|
|
67
|
+
* Dedupe and resolution key off the notification PAYLOAD's request id (the
|
|
68
|
+
* canonical one — the registry map key is caller-supplied and could
|
|
69
|
+
* disagree; the resolver's membership check authenticates the payload's).
|
|
53
70
|
*
|
|
54
|
-
* @returns The newly-authenticated requests this cycle
|
|
71
|
+
* @returns The newly-authenticated requests this cycle.
|
|
72
|
+
* @throws Error if the signet contract has no readable state at the
|
|
73
|
+
* configured address (wrong address or not yet deployed/indexed).
|
|
55
74
|
*/
|
|
56
75
|
poll(): Promise<ResolvedSignetRequest[]>;
|
|
57
76
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signet-request-feed.d.ts","sourceRoot":"","sources":["../src/signet-request-feed.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"signet-request-feed.d.ts","sourceRoot":"","sources":["../src/signet-request-feed.ts"],"names":[],"mappings":"AAkBA,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzE,6EAA6E;AAC7E,eAAO,MAAM,6BAA6B,OAAO,CAAC;AAElD,oDAAoD;AACpD,MAAM,WAAW,uBAAuB;IACtC,kFAAkF;IAClF,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACvC;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC;IACzC;;;;OAIG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3C,0GAA0G;IAC1G,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,MAAM,EACV,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,CAAC,CAaf;AAOD;;;;;;;GAOG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAS;IAC/C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0B;IACjD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwB;IACjD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAc;IAC9C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IAIxC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2B;IAEnD;;;OAGG;gBACS,MAAM,EAAE,uBAAuB;IAW3C,qFAAqF;IACrF,OAAO,CAAC,OAAO;IAOf;;;;;;;;;;;;;;;;;;OAkBG;IACG,IAAI,IAAI,OAAO,CAAC,qBAAqB,EAAE,CAAC;IAqC9C;;;;;;OAMG;IACH,MAAM,CAAC,SAAS,EAAE,YAAY,GAAG,IAAI;IAIrC;;;;;;;;OAQG;IACI,QAAQ,CAAC,IAAI,CAAC,EAAE;QACrB,MAAM,CAAC,EAAE,WAAW,CAAC;KACtB,GAAG,qBAAqB,CAAC,qBAAqB,CAAC;CAQjD"}
|
|
@@ -1,33 +1,59 @@
|
|
|
1
|
-
// The MPC's single entry point for discovering signature requests
|
|
2
|
-
//
|
|
3
|
-
// to an AUTHENTICATED request read from the named caller's
|
|
4
|
-
// yield only the ones that pass the membership check.
|
|
5
|
-
//
|
|
6
|
-
//
|
|
1
|
+
// The MPC's single entry point for discovering signature requests: poll the
|
|
2
|
+
// central signet contract's notification registry (ledger field 4), resolve
|
|
3
|
+
// each notification to an AUTHENTICATED request read from the named caller's
|
|
4
|
+
// own ledger, and yield only the ones that pass the membership check. The
|
|
5
|
+
// registry is append-only with no on-ledger cursor, so the feed's in-memory
|
|
6
|
+
// `yielded` set is the diff cursor: every poll enumerates the registry and
|
|
7
|
+
// serves what it has not served before.
|
|
7
8
|
//
|
|
8
9
|
// The requester allow-list is an OPTIONAL policy filter here (drop requests
|
|
9
10
|
// from contracts you choose not to serve), never a security requirement and
|
|
10
11
|
// never the discovery mechanism — attribution comes from the resolver's
|
|
11
12
|
// authenticated read (see signet-request-resolver.ts and
|
|
12
13
|
// knowledge-base/caller-attribution.md).
|
|
13
|
-
import {
|
|
14
|
-
import { signBidirectionalEventCodec, stripHexPrefix, } from "./signet-events.js";
|
|
14
|
+
import { decodeSignBidirectionalNotification, readSignBidirectionalNotificationIndexFromState, } from "./signet-contract-state-reader.js";
|
|
15
15
|
import { SignetRequestResolver, } from "./signet-request-resolver.js";
|
|
16
|
+
import { stripHexPrefix } from "./signet-requests.js";
|
|
16
17
|
/** Default gap between poll cycles of {@link SignetRequestFeed.requests}. */
|
|
17
18
|
export const DEFAULT_FEED_POLL_INTERVAL_MS = 3000;
|
|
19
|
+
/**
|
|
20
|
+
* Resolve after `ms`, or immediately once `signal` aborts. Used to space out
|
|
21
|
+
* polls without wedging a shutdown.
|
|
22
|
+
*
|
|
23
|
+
* @param ms - Milliseconds to wait.
|
|
24
|
+
* @param signal - Abort to resolve early.
|
|
25
|
+
* @returns A promise that settles after the delay or the abort.
|
|
26
|
+
*/
|
|
27
|
+
export function sleepUnlessAborted(ms, signal) {
|
|
28
|
+
return new Promise((resolve) => {
|
|
29
|
+
if (signal?.aborted)
|
|
30
|
+
return resolve();
|
|
31
|
+
const timer = setTimeout(() => {
|
|
32
|
+
signal?.removeEventListener("abort", onAbort);
|
|
33
|
+
resolve();
|
|
34
|
+
}, ms);
|
|
35
|
+
const onAbort = () => {
|
|
36
|
+
clearTimeout(timer);
|
|
37
|
+
resolve();
|
|
38
|
+
};
|
|
39
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
40
|
+
});
|
|
41
|
+
}
|
|
18
42
|
/** Canonical form for comparing contract addresses: no `0x`, lowercase. */
|
|
19
43
|
function normalizeAddress(address) {
|
|
20
44
|
return stripHexPrefix(address).toLowerCase();
|
|
21
45
|
}
|
|
22
46
|
/**
|
|
23
|
-
* The
|
|
24
|
-
* (discovery)
|
|
25
|
-
*
|
|
26
|
-
*
|
|
47
|
+
* The registry-polling request feed. Reads the signet contract's notification
|
|
48
|
+
* registry (discovery) and hands each notification to a
|
|
49
|
+
* {@link SignetRequestResolver} (authentication), yielding only notifications
|
|
50
|
+
* that resolve to a real, member request. Dedupes by request id across its
|
|
51
|
+
* lifetime, so a re-registered notification is not re-yielded; call
|
|
27
52
|
* {@link forget} to re-arm a request whose downstream processing failed.
|
|
28
53
|
*/
|
|
29
54
|
export class SignetRequestFeed {
|
|
30
|
-
|
|
55
|
+
signetContractAddress;
|
|
56
|
+
source;
|
|
31
57
|
resolver;
|
|
32
58
|
allowContracts;
|
|
33
59
|
pollIntervalMs;
|
|
@@ -35,17 +61,12 @@ export class SignetRequestFeed {
|
|
|
35
61
|
// just an at-most-once gate so one request is not processed twice.
|
|
36
62
|
yielded = new Set();
|
|
37
63
|
/**
|
|
38
|
-
* @param config - The signet contract,
|
|
39
|
-
*
|
|
64
|
+
* @param config - The signet contract, state source, and optional policy
|
|
65
|
+
* allow-list.
|
|
40
66
|
*/
|
|
41
67
|
constructor(config) {
|
|
42
|
-
this.
|
|
43
|
-
|
|
44
|
-
source: config.source,
|
|
45
|
-
codec: signBidirectionalEventCodec,
|
|
46
|
-
fromEventId: config.fromEventId,
|
|
47
|
-
pollIntervalMs: config.pollIntervalMs,
|
|
48
|
-
});
|
|
68
|
+
this.signetContractAddress = config.signetContractAddress;
|
|
69
|
+
this.source = config.source;
|
|
49
70
|
this.resolver = new SignetRequestResolver({ source: config.source });
|
|
50
71
|
this.allowContracts = config.allowContracts
|
|
51
72
|
? new Set(Array.from(config.allowContracts, normalizeAddress))
|
|
@@ -59,26 +80,50 @@ export class SignetRequestFeed {
|
|
|
59
80
|
this.allowContracts.has(normalizeAddress(callerAddress)));
|
|
60
81
|
}
|
|
61
82
|
/**
|
|
62
|
-
* One-shot: every currently-
|
|
63
|
-
* allow-list, not already yielded, and resolves to an
|
|
64
|
-
* request.
|
|
65
|
-
*
|
|
66
|
-
*
|
|
83
|
+
* One-shot: every currently-registered notification that decodes, is
|
|
84
|
+
* admitted by the allow-list, not already yielded, and resolves to an
|
|
85
|
+
* authenticated member request. Registry enumeration has no meaningful
|
|
86
|
+
* on-ledger order, so entries are processed in ascending request-id-hex
|
|
87
|
+
* order — a stable, deterministic sequence. Forged / not-yet-indexed /
|
|
88
|
+
* wrong-field notifications resolve to nothing and are dropped WITHOUT
|
|
89
|
+
* being marked yielded, so a genuine request whose ledger write has not
|
|
90
|
+
* indexed yet is retried next cycle; undecodable or unsupported-version
|
|
91
|
+
* records are likewise skipped (and logged) without being marked.
|
|
67
92
|
*
|
|
68
|
-
*
|
|
93
|
+
* Dedupe and resolution key off the notification PAYLOAD's request id (the
|
|
94
|
+
* canonical one — the registry map key is caller-supplied and could
|
|
95
|
+
* disagree; the resolver's membership check authenticates the payload's).
|
|
96
|
+
*
|
|
97
|
+
* @returns The newly-authenticated requests this cycle.
|
|
98
|
+
* @throws Error if the signet contract has no readable state at the
|
|
99
|
+
* configured address (wrong address or not yet deployed/indexed).
|
|
69
100
|
*/
|
|
70
101
|
async poll() {
|
|
71
|
-
const
|
|
102
|
+
const state = await this.source.queryContractState(this.signetContractAddress);
|
|
103
|
+
if (!state?.data) {
|
|
104
|
+
throw new Error(`No contract state at signet contract ${this.signetContractAddress} ` +
|
|
105
|
+
`— wrong address, or not yet deployed/indexed`);
|
|
106
|
+
}
|
|
107
|
+
const registry = readSignBidirectionalNotificationIndexFromState(state.data);
|
|
72
108
|
const out = [];
|
|
73
|
-
for (const
|
|
74
|
-
|
|
109
|
+
for (const [registryKey, record] of [...registry.entries()].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) {
|
|
110
|
+
let notification;
|
|
111
|
+
try {
|
|
112
|
+
notification = decodeSignBidirectionalNotification(record);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
console.warn(`SignetRequestFeed: skipping undecodable notification ` +
|
|
116
|
+
`registered under ${registryKey}: ${String(error)}`);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (this.yielded.has(notification.requestId))
|
|
75
120
|
continue;
|
|
76
|
-
if (!this.allowed(
|
|
121
|
+
if (!this.allowed(notification.callerAddress))
|
|
77
122
|
continue;
|
|
78
|
-
const resolved = await this.resolver.resolve(
|
|
123
|
+
const resolved = await this.resolver.resolve(notification);
|
|
79
124
|
if (resolved === undefined)
|
|
80
125
|
continue;
|
|
81
|
-
this.yielded.add(
|
|
126
|
+
this.yielded.add(notification.requestId);
|
|
82
127
|
out.push(resolved);
|
|
83
128
|
}
|
|
84
129
|
return out;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signet-request-feed.js","sourceRoot":"","sources":["../src/signet-request-feed.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"signet-request-feed.js","sourceRoot":"","sources":["../src/signet-request-feed.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,4EAA4E;AAC5E,6EAA6E;AAC7E,0EAA0E;AAC1E,4EAA4E;AAC5E,2EAA2E;AAC3E,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,4EAA4E;AAC5E,wEAAwE;AACxE,yDAAyD;AACzD,yCAAyC;AAEzC,OAAO,EACL,mCAAmC,EACnC,+CAA+C,GAChD,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,qBAAqB,GAEtB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,cAAc,EAAqB,MAAM,sBAAsB,CAAC;AAEzE,6EAA6E;AAC7E,MAAM,CAAC,MAAM,6BAA6B,GAAG,IAAI,CAAC;AAsBlD;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB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