@sig-net/midnight 0.15.0 → 0.17.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/README.md +113 -49
- package/dist/constants.d.ts +55 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +85 -5
- package/dist/constants.js.map +1 -1
- package/dist/ecdsa-attestation.d.ts +6 -5
- package/dist/ecdsa-attestation.d.ts.map +1 -1
- package/dist/ecdsa-attestation.js +5 -4
- package/dist/ecdsa-attestation.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/managed/compiler/contract-manifest.json +2 -2
- package/dist/managed/contract/index.js +31 -31
- package/dist/managed/contract/index.js.map +1 -1
- package/dist/signature-requests-state-reader.d.ts +7 -7
- package/dist/signature-requests-state-reader.js +7 -7
- package/dist/signature-response-verification.d.ts +1 -1
- package/dist/signature-response-verification.d.ts.map +1 -1
- package/dist/signature-response-verification.js +3 -3
- package/dist/signature-response-verification.js.map +1 -1
- package/dist/signature-state-reading.js +2 -2
- package/dist/signature-state-reading.js.map +1 -1
- package/dist/signet-contract-events.d.ts +267 -0
- package/dist/signet-contract-events.d.ts.map +1 -0
- package/dist/signet-contract-events.js +272 -0
- package/dist/signet-contract-events.js.map +1 -0
- package/dist/signet-evtype2tx-requests.d.ts +4 -4
- package/dist/signet-evtype2tx-requests.d.ts.map +1 -1
- package/dist/signet-evtype2tx-requests.js +3 -3
- package/dist/signet-request-feed.d.ts +61 -33
- package/dist/signet-request-feed.d.ts.map +1 -1
- package/dist/signet-request-feed.js +116 -62
- package/dist/signet-request-feed.js.map +1 -1
- package/dist/signet-request-response-reader.d.ts +62 -55
- package/dist/signet-request-response-reader.d.ts.map +1 -1
- package/dist/signet-request-response-reader.js +85 -99
- package/dist/signet-request-response-reader.js.map +1 -1
- package/dist/signet-requests.js +2 -2
- package/dist/signet-requests.js.map +1 -1
- package/package.json +2 -2
- package/src/Signet.compact +45 -36
- package/dist/signet-contract-state-reader.d.ts +0 -247
- package/dist/signet-contract-state-reader.d.ts.map +0 -1
- package/dist/signet-contract-state-reader.js +0 -363
- package/dist/signet-contract-state-reader.js.map +0 -1
- package/dist/signet-request-resolver.d.ts +0 -60
- package/dist/signet-request-resolver.d.ts.map +0 -1
- package/dist/signet-request-resolver.js +0 -78
- package/dist/signet-request-resolver.js.map +0 -1
|
@@ -1,363 +0,0 @@
|
|
|
1
|
-
// MPC-/client-style raw state reader for the central SIGNET contract: decode
|
|
2
|
-
// its ledger fields out of a contract's raw state WITHOUT the compiled
|
|
3
|
-
// contract, the mirror image of signature-requests-state-reader.ts. A poller
|
|
4
|
-
// has only the contract address, queries raw state from the indexer
|
|
5
|
-
// (queryContractState(address).data), and decodes by the signet contract's
|
|
6
|
-
// declaration-order layout:
|
|
7
|
-
// field 0: signBidirectionalEventNotificationCounterMap (Map<RequestId, Counter>)
|
|
8
|
-
// field 1: signBidirectionalEventNotificationMap (Map<SignetMapKey, Notification>)
|
|
9
|
-
// field 2: respondCounterMap (Map<RequestId, Counter>)
|
|
10
|
-
// field 3: respondMap (Map<SignetMapKey, SignatureRespondedEvent>)
|
|
11
|
-
// field 4: respondBidirectionalCounterMap (Map<RequestId, Counter>)
|
|
12
|
-
// field 5: respondBidirectionalMap (Map<SignetMapKey, RespondBidirectionalEvent>)
|
|
13
|
-
// Every store is an unauthenticated append-only log keyed by
|
|
14
|
-
// (requestId, count): verification is the reader's job. The generic
|
|
15
|
-
// state-tree walk (RawContractState, signetFieldNodeByPath) and the shared base
|
|
16
|
-
// descriptors live in signature-state-reading.ts.
|
|
17
|
-
import { CompactTypeBytes, CompactTypeUnsignedInteger, } from "@midnight-ntwrk/compact-runtime";
|
|
18
|
-
import { bytesToHex, requestIdHex, } from "./signet-requests.js";
|
|
19
|
-
import { requestIdType, signetFieldNodeByPath, u64, } from "./signature-state-reading.js";
|
|
20
|
-
/** Signet contract layout: the notification counter map is ledger field 0. */
|
|
21
|
-
export const SIGN_BIDIRECTIONAL_EVENT_NOTIFICATION_COUNTER_MAP_FIELD = 0;
|
|
22
|
-
/** Signet contract layout: the notification map is ledger field 1. */
|
|
23
|
-
export const SIGN_BIDIRECTIONAL_EVENT_NOTIFICATION_MAP_FIELD = 1;
|
|
24
|
-
/** Signet contract layout: the `respond` counter map is ledger field 2. */
|
|
25
|
-
export const RESPOND_COUNTER_MAP_FIELD = 2;
|
|
26
|
-
/** Signet contract layout: the `respond` post log is ledger field 3. */
|
|
27
|
-
export const RESPOND_MAP_FIELD = 3;
|
|
28
|
-
/** Signet contract layout: the respond-bidirectional counter map is ledger field 4. */
|
|
29
|
-
export const RESPOND_BIDIRECTIONAL_COUNTER_MAP_FIELD = 4;
|
|
30
|
-
/** Signet contract layout: the respond-bidirectional map is ledger field 5. */
|
|
31
|
-
export const RESPOND_BIDIRECTIONAL_MAP_FIELD = 5;
|
|
32
|
-
// ---- Type descriptors (must mirror Signet.compact field-for-field) ----
|
|
33
|
-
// As in the requests reader, fromValue consumes the aligned value
|
|
34
|
-
// sequentially, so field order and width here must match the Compact structs
|
|
35
|
-
// exactly: a mismatch is silent data corruption, not an error.
|
|
36
|
-
/** Descriptor for a 32-byte scalar / coordinate / hash (`Bytes<32>`). */
|
|
37
|
-
const bytes32 = new CompactTypeBytes(32);
|
|
38
|
-
/** Descriptor for a Compact `Uint<8>` (1-byte unsigned integer). */
|
|
39
|
-
const u8 = new CompactTypeUnsignedInteger(255n, 1);
|
|
40
|
-
/**
|
|
41
|
-
* Hand-composed descriptor for {@link MpcSignature}. Leaf order
|
|
42
|
-
* (bigR.x, bigR.y, s, recoveryId) must match the nested Compact structs.
|
|
43
|
-
*/
|
|
44
|
-
const mpcSignatureType = {
|
|
45
|
-
/** @returns Compound alignment of the struct's leaves in declaration order. */
|
|
46
|
-
alignment() {
|
|
47
|
-
return bytes32
|
|
48
|
-
.alignment()
|
|
49
|
-
.concat(bytes32.alignment())
|
|
50
|
-
.concat(bytes32.alignment())
|
|
51
|
-
.concat(u8.alignment());
|
|
52
|
-
},
|
|
53
|
-
/**
|
|
54
|
-
* Decode one signature from an aligned value, consuming it leaf by leaf.
|
|
55
|
-
*
|
|
56
|
-
* @param value - Mutable aligned value cursor: pass a copy.
|
|
57
|
-
* @returns The decoded signature.
|
|
58
|
-
*/
|
|
59
|
-
fromValue(value) {
|
|
60
|
-
return {
|
|
61
|
-
bigR: { x: bytes32.fromValue(value), y: bytes32.fromValue(value) },
|
|
62
|
-
s: bytes32.fromValue(value),
|
|
63
|
-
recoveryId: u8.fromValue(value),
|
|
64
|
-
};
|
|
65
|
-
},
|
|
66
|
-
/**
|
|
67
|
-
* Encode a signature into its aligned on-ledger representation.
|
|
68
|
-
*
|
|
69
|
-
* @param record - The signature to encode.
|
|
70
|
-
* @returns The aligned value, leaves concatenated in declaration order.
|
|
71
|
-
*/
|
|
72
|
-
toValue(record) {
|
|
73
|
-
return bytes32
|
|
74
|
-
.toValue(record.bigR.x)
|
|
75
|
-
.concat(bytes32.toValue(record.bigR.y))
|
|
76
|
-
.concat(bytes32.toValue(record.s))
|
|
77
|
-
.concat(u8.toValue(record.recoveryId));
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
/**
|
|
81
|
-
* Hand-composed descriptor for {@link SignatureRespondedEvent}: the single
|
|
82
|
-
* {@link MpcSignature} field, matching the Compact struct.
|
|
83
|
-
*/
|
|
84
|
-
export const signatureRespondedEventType = {
|
|
85
|
-
/** @returns Alignment of the struct's single signature field. */
|
|
86
|
-
alignment() {
|
|
87
|
-
return mpcSignatureType.alignment();
|
|
88
|
-
},
|
|
89
|
-
/**
|
|
90
|
-
* Decode one signature response from an aligned value.
|
|
91
|
-
*
|
|
92
|
-
* @param value - Mutable aligned value cursor: pass a copy.
|
|
93
|
-
* @returns The decoded record.
|
|
94
|
-
*/
|
|
95
|
-
fromValue(value) {
|
|
96
|
-
return { signature: mpcSignatureType.fromValue(value) };
|
|
97
|
-
},
|
|
98
|
-
/**
|
|
99
|
-
* Encode a signature response into its aligned on-ledger representation.
|
|
100
|
-
*
|
|
101
|
-
* @param record - The record to encode.
|
|
102
|
-
* @returns The aligned value.
|
|
103
|
-
*/
|
|
104
|
-
toValue(record) {
|
|
105
|
-
return mpcSignatureType.toValue(record.signature);
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* Hand-composed descriptor for {@link SignetMapKey}, the map key of every
|
|
110
|
-
* posted-entry map in the signet contract. Field order (count, then
|
|
111
|
-
* requestId) must match the Compact struct.
|
|
112
|
-
*/
|
|
113
|
-
export const signetMapKeyType = {
|
|
114
|
-
/** @returns Compound alignment of the struct's fields in declaration order. */
|
|
115
|
-
alignment() {
|
|
116
|
-
return u64.alignment().concat(requestIdType.alignment());
|
|
117
|
-
},
|
|
118
|
-
/**
|
|
119
|
-
* Decode one key from an aligned value, consuming it field by field.
|
|
120
|
-
*
|
|
121
|
-
* @param value - Mutable aligned value cursor: pass a copy.
|
|
122
|
-
* @returns The decoded composite key.
|
|
123
|
-
*/
|
|
124
|
-
fromValue(value) {
|
|
125
|
-
return {
|
|
126
|
-
count: u64.fromValue(value),
|
|
127
|
-
requestId: requestIdType.fromValue(value),
|
|
128
|
-
};
|
|
129
|
-
},
|
|
130
|
-
/**
|
|
131
|
-
* Encode a key into its aligned on-ledger representation.
|
|
132
|
-
*
|
|
133
|
-
* @param key - The composite key to encode.
|
|
134
|
-
* @returns The aligned value, fields concatenated in declaration order.
|
|
135
|
-
*/
|
|
136
|
-
toValue(key) {
|
|
137
|
-
return u64.toValue(key.count).concat(requestIdType.toValue(key.requestId));
|
|
138
|
-
},
|
|
139
|
-
};
|
|
140
|
-
/**
|
|
141
|
-
* Hand-composed descriptor for {@link RespondBidirectionalEvent}: the single
|
|
142
|
-
* {@link MpcSignature} field, matching the Compact struct.
|
|
143
|
-
*/
|
|
144
|
-
export const respondBidirectionalEventType = {
|
|
145
|
-
/** @returns Alignment of the struct's single signature field. */
|
|
146
|
-
alignment() {
|
|
147
|
-
return mpcSignatureType.alignment();
|
|
148
|
-
},
|
|
149
|
-
/**
|
|
150
|
-
* Decode one response record from an aligned value.
|
|
151
|
-
*
|
|
152
|
-
* @param value - Mutable aligned value cursor: pass a copy.
|
|
153
|
-
* @returns The decoded record.
|
|
154
|
-
*/
|
|
155
|
-
fromValue(value) {
|
|
156
|
-
return { signature: mpcSignatureType.fromValue(value) };
|
|
157
|
-
},
|
|
158
|
-
/**
|
|
159
|
-
* Encode a response record into its aligned on-ledger representation.
|
|
160
|
-
*
|
|
161
|
-
* @param record - The record to encode.
|
|
162
|
-
* @returns The aligned value.
|
|
163
|
-
*/
|
|
164
|
-
toValue(record) {
|
|
165
|
-
return mpcSignatureType.toValue(record.signature);
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
/** Descriptor for the notification's packed V1 payload (`Bytes<128>`). */
|
|
169
|
-
const bytes128Payload = new CompactTypeBytes(128);
|
|
170
|
-
/**
|
|
171
|
-
* Hand-composed descriptor for {@link SignBidirectionalNotificationRecord}.
|
|
172
|
-
* Field order (version, payload) must match the Compact struct.
|
|
173
|
-
*/
|
|
174
|
-
export const signBidirectionalNotificationType = {
|
|
175
|
-
/** @returns Compound alignment of the struct's fields in declaration order. */
|
|
176
|
-
alignment() {
|
|
177
|
-
return u8.alignment().concat(bytes128Payload.alignment());
|
|
178
|
-
},
|
|
179
|
-
/**
|
|
180
|
-
* Decode one notification record from an aligned value, consuming it
|
|
181
|
-
* field by field.
|
|
182
|
-
*
|
|
183
|
-
* @param value - Mutable aligned value cursor: pass a copy.
|
|
184
|
-
* @returns The decoded record.
|
|
185
|
-
*/
|
|
186
|
-
fromValue(value) {
|
|
187
|
-
return {
|
|
188
|
-
version: u8.fromValue(value),
|
|
189
|
-
payload: bytes128Payload.fromValue(value),
|
|
190
|
-
};
|
|
191
|
-
},
|
|
192
|
-
/**
|
|
193
|
-
* Encode a notification record into its aligned on-ledger representation.
|
|
194
|
-
*
|
|
195
|
-
* @param record - The record to encode.
|
|
196
|
-
* @returns The aligned value, fields concatenated in declaration order.
|
|
197
|
-
*/
|
|
198
|
-
toValue(record) {
|
|
199
|
-
return u8
|
|
200
|
-
.toValue(record.version)
|
|
201
|
-
.concat(bytes128Payload.toValue(record.payload));
|
|
202
|
-
},
|
|
203
|
-
};
|
|
204
|
-
/** Offset of the V1 `callerAddress` in the packed payload (`Bytes<32>` at the front). */
|
|
205
|
-
const NOTIFICATION_CALLER_ADDRESS_OFFSET = 0;
|
|
206
|
-
/** Offset of the V1 `requestsPathDepth` (after the 32 callerAddress bytes). */
|
|
207
|
-
const NOTIFICATION_PATH_DEPTH_OFFSET = 32;
|
|
208
|
-
/** Offset of the V1 `requestsPath` bytes (after the 1-byte depth). */
|
|
209
|
-
const NOTIFICATION_PATH_OFFSET = 33;
|
|
210
|
-
/**
|
|
211
|
-
* Maximum ledger-tree path depth the V1 payload carries, matching the
|
|
212
|
-
* `Vector<4, Uint<8>>` the `constructSignBidirectionalEventNotificationV1`
|
|
213
|
-
* circuit packs. Depth 1 addresses up to 15 fields, depth 4 up to 15^4.
|
|
214
|
-
*/
|
|
215
|
-
const MAX_LEDGER_PATH_DEPTH = 4;
|
|
216
|
-
/** The only payload interpretation {@link decodeSignBidirectionalNotification} understands today. */
|
|
217
|
-
const SUPPORTED_NOTIFICATION_VERSION = 1n;
|
|
218
|
-
/**
|
|
219
|
-
* Unpack a stored {@link SignBidirectionalNotificationRecord}'s payload by
|
|
220
|
-
* the fixed V1 offsets: the decode twin of the compiled
|
|
221
|
-
* `constructSignBidirectionalEventNotificationV1` circuit (byte plumbing
|
|
222
|
-
* only: the pack↔decode lockstep is pinned by the state-reader unit test that
|
|
223
|
-
* round-trips through the real circuit). V1 layout:
|
|
224
|
-
* callerAddress (32) ++ requestsPathDepth (1) ++ requestsPath (4) ++ zero
|
|
225
|
-
* padding (91), where only the first `requestsPathDepth` path bytes are
|
|
226
|
-
* meaningful.
|
|
227
|
-
*
|
|
228
|
-
* Fails closed on an unrecognised `version`: a future payload layout adds a
|
|
229
|
-
* branch here rather than silently misinterpreting bytes under the V1 offsets.
|
|
230
|
-
*
|
|
231
|
-
* @param record - The raw on-ledger record.
|
|
232
|
-
* @returns The decoded notification, its `requestsPath` trimmed to the
|
|
233
|
-
* declared depth.
|
|
234
|
-
* @throws Error if the record's `version` is not one this decoder understands,
|
|
235
|
-
* or its `requestsPathDepth` is zero or exceeds {@link MAX_LEDGER_PATH_DEPTH}.
|
|
236
|
-
*/
|
|
237
|
-
export function decodeSignBidirectionalNotification(record) {
|
|
238
|
-
if (record.version !== SUPPORTED_NOTIFICATION_VERSION) {
|
|
239
|
-
throw new Error(`SignBidirectionalEventNotification version ${record.version} is not supported ` +
|
|
240
|
-
`(this decoder understands version ${SUPPORTED_NOTIFICATION_VERSION})`);
|
|
241
|
-
}
|
|
242
|
-
const callerAddress = bytesToHex(record.payload.slice(NOTIFICATION_CALLER_ADDRESS_OFFSET, NOTIFICATION_PATH_DEPTH_OFFSET));
|
|
243
|
-
const depth = record.payload[NOTIFICATION_PATH_DEPTH_OFFSET];
|
|
244
|
-
if (depth === undefined || depth < 1 || depth > MAX_LEDGER_PATH_DEPTH) {
|
|
245
|
-
throw new Error(`SignBidirectionalEventNotification requestsPathDepth ${depth} is out of range ` +
|
|
246
|
-
`(expected 1 to ${MAX_LEDGER_PATH_DEPTH})`);
|
|
247
|
-
}
|
|
248
|
-
// payload is a re-padded Bytes<128> and depth is bounded to MAX_LEDGER_PATH_DEPTH
|
|
249
|
-
// above, so this slice always yields exactly `depth` bytes.
|
|
250
|
-
const requestsPath = Array.from(record.payload.slice(NOTIFICATION_PATH_OFFSET, NOTIFICATION_PATH_OFFSET + depth));
|
|
251
|
-
return {
|
|
252
|
-
version: Number(record.version),
|
|
253
|
-
callerAddress,
|
|
254
|
-
requestsPath,
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Build the flattened JS map key for a `(requestId, count)` pair: the
|
|
259
|
-
* composite Compact {@link SignetMapKey} as a string so it works as a JS
|
|
260
|
-
* `Map` key.
|
|
261
|
-
*
|
|
262
|
-
* @param id - The request id the entry belongs to, in canonical hex form.
|
|
263
|
-
* @param count - 0-based post count within that request.
|
|
264
|
-
* @returns `"<hexRequestId>:<count>"`.
|
|
265
|
-
*/
|
|
266
|
-
export function signetMapEntryKey(id, count) {
|
|
267
|
-
return `${id}:${count}`;
|
|
268
|
-
}
|
|
269
|
-
/** Decode a `Map<RequestId, Counter>` ledger field into a {@link SignetCounterIndex}. */
|
|
270
|
-
function readCounterMap(raw, field) {
|
|
271
|
-
// The central singleton is flat (6 fields), so a field number is a depth-1 path.
|
|
272
|
-
const counterMap = signetFieldNodeByPath(raw, [field]).asMap();
|
|
273
|
-
if (counterMap === undefined) {
|
|
274
|
-
throw new Error(`Ledger field ${field} is not a Map`);
|
|
275
|
-
}
|
|
276
|
-
const index = new Map();
|
|
277
|
-
for (const key of counterMap.keys()) {
|
|
278
|
-
// fromValue consumes its input, so hand each descriptor a copy.
|
|
279
|
-
const requestId = requestIdType.fromValue([...key.value]);
|
|
280
|
-
// A Counter is stored as a plain u64 cell.
|
|
281
|
-
const cell = counterMap.get(key)?.asCell();
|
|
282
|
-
if (cell === undefined)
|
|
283
|
-
continue;
|
|
284
|
-
index.set(requestIdHex(requestId), u64.fromValue([...cell.value]));
|
|
285
|
-
}
|
|
286
|
-
return index;
|
|
287
|
-
}
|
|
288
|
-
/** Decode a `Map<SignetMapKey, T>` ledger field into a string-keyed JS map. */
|
|
289
|
-
function readSignetKeyedMap(raw, field, valueType) {
|
|
290
|
-
const map = signetFieldNodeByPath(raw, [field]).asMap();
|
|
291
|
-
if (map === undefined) {
|
|
292
|
-
throw new Error(`Ledger field ${field} is not a Map`);
|
|
293
|
-
}
|
|
294
|
-
const index = new Map();
|
|
295
|
-
for (const key of map.keys()) {
|
|
296
|
-
const mapKey = signetMapKeyType.fromValue([...key.value]);
|
|
297
|
-
const cell = map.get(key)?.asCell();
|
|
298
|
-
if (cell === undefined)
|
|
299
|
-
continue;
|
|
300
|
-
index.set(signetMapEntryKey(requestIdHex(mapKey.requestId), mapKey.count), valueType.fromValue([...cell.value]));
|
|
301
|
-
}
|
|
302
|
-
return index;
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* Read ONLY the notification registry (ledger field
|
|
306
|
-
* {@link SIGN_BIDIRECTIONAL_EVENT_NOTIFICATION_MAP_FIELD}) out of raw signet
|
|
307
|
-
* contract state: the poll-loop primitive of {@link SignetRequestFeed},
|
|
308
|
-
* which cycles frequently and has no use for the response fields. One record
|
|
309
|
-
* per request id (the count-0 post, see
|
|
310
|
-
* {@link SignBidirectionalNotificationIndex}).
|
|
311
|
-
*
|
|
312
|
-
* @param raw - Raw contract state, e.g. `queryContractState(address).data`
|
|
313
|
-
* from the indexer or `ctx.currentQueryContext.state` from the simulator.
|
|
314
|
-
* @returns The registry, keyed by the hex request id of each entry's map key.
|
|
315
|
-
* @throws Error if the field is missing or is not a Map.
|
|
316
|
-
*/
|
|
317
|
-
export function readSignBidirectionalNotificationIndexFromState(raw) {
|
|
318
|
-
const notificationMap = signetFieldNodeByPath(raw, [
|
|
319
|
-
SIGN_BIDIRECTIONAL_EVENT_NOTIFICATION_MAP_FIELD,
|
|
320
|
-
]).asMap();
|
|
321
|
-
if (notificationMap === undefined) {
|
|
322
|
-
throw new Error(`Ledger field ${SIGN_BIDIRECTIONAL_EVENT_NOTIFICATION_MAP_FIELD} is not a Map`);
|
|
323
|
-
}
|
|
324
|
-
const index = new Map();
|
|
325
|
-
const counts = new Map();
|
|
326
|
-
for (const key of notificationMap.keys()) {
|
|
327
|
-
// fromValue consumes its input, so hand each descriptor a copy.
|
|
328
|
-
const mapKey = signetMapKeyType.fromValue([...key.value]);
|
|
329
|
-
const cell = notificationMap.get(key)?.asCell();
|
|
330
|
-
if (cell === undefined)
|
|
331
|
-
continue;
|
|
332
|
-
const id = requestIdHex(mapKey.requestId);
|
|
333
|
-
const seen = counts.get(id);
|
|
334
|
-
// Keep the FIRST post (lowest count) per request id.
|
|
335
|
-
if (seen !== undefined && seen <= mapKey.count)
|
|
336
|
-
continue;
|
|
337
|
-
counts.set(id, mapKey.count);
|
|
338
|
-
index.set(id, signBidirectionalNotificationType.fromValue([...cell.value]));
|
|
339
|
-
}
|
|
340
|
-
return index;
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* MPC-/client-style read: parse the signet contract's ledger fields out of
|
|
344
|
-
* raw contract state by field position alone, with no compiled contract and
|
|
345
|
-
* no generated `ledger()`, only the declaration-order layout and the
|
|
346
|
-
* canonical descriptors above.
|
|
347
|
-
*
|
|
348
|
-
* @param raw - Raw contract state, e.g. `queryContractState(address).data`
|
|
349
|
-
* from the indexer or `ctx.currentQueryContext.state` from the simulator.
|
|
350
|
-
* @returns The decoded {@link SignetContractLedger}.
|
|
351
|
-
* @throws Error if a field is missing or has the wrong state-value shape.
|
|
352
|
-
*/
|
|
353
|
-
export function readSignetContractLedgerFromState(raw) {
|
|
354
|
-
return {
|
|
355
|
-
signBidirectionalEventNotificationCounterMap: readCounterMap(raw, SIGN_BIDIRECTIONAL_EVENT_NOTIFICATION_COUNTER_MAP_FIELD),
|
|
356
|
-
signBidirectionalEventNotificationMap: readSignBidirectionalNotificationIndexFromState(raw),
|
|
357
|
-
respondCounterMap: readCounterMap(raw, RESPOND_COUNTER_MAP_FIELD),
|
|
358
|
-
respondMap: readSignetKeyedMap(raw, RESPOND_MAP_FIELD, signatureRespondedEventType),
|
|
359
|
-
respondBidirectionalCounterMap: readCounterMap(raw, RESPOND_BIDIRECTIONAL_COUNTER_MAP_FIELD),
|
|
360
|
-
respondBidirectionalMap: readSignetKeyedMap(raw, RESPOND_BIDIRECTIONAL_MAP_FIELD, respondBidirectionalEventType),
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
//# sourceMappingURL=signet-contract-state-reader.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,2EAA2E;AAC3E,4BAA4B;AAC5B,oFAAoF;AACpF,qFAAqF;AACrF,yDAAyD;AACzD,qEAAqE;AACrE,sEAAsE;AACtE,oFAAoF;AACpF,6DAA6D;AAC7D,oEAAoE;AACpE,gFAAgF;AAChF,kDAAkD;AAElD,OAAO,EACL,gBAAgB,EAChB,0BAA0B,GAE3B,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACL,UAAU,EACV,YAAY,GAGb,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,GAAG,GAEJ,MAAM,8BAA8B,CAAC;AAEtC,8EAA8E;AAC9E,MAAM,CAAC,MAAM,uDAAuD,GAAG,CAAC,CAAC;AAEzE,sEAAsE;AACtE,MAAM,CAAC,MAAM,+CAA+C,GAAG,CAAC,CAAC;AAEjE,2EAA2E;AAC3E,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAE3C,wEAAwE;AACxE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAEnC,uFAAuF;AACvF,MAAM,CAAC,MAAM,uCAAuC,GAAG,CAAC,CAAC;AAEzD,+EAA+E;AAC/E,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAAC,CAAC;AAEjD,0EAA0E;AAC1E,kEAAkE;AAClE,6EAA6E;AAC7E,+DAA+D;AAE/D,yEAAyE;AACzE,MAAM,OAAO,GAAG,IAAI,gBAAgB,CAAC,EAAE,CAAC,CAAC;AAEzC,oEAAoE;AACpE,MAAM,EAAE,GAAG,IAAI,0BAA0B,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AAgCnD;;;GAGG;AACH,MAAM,gBAAgB,GAA8B;IAClD,+EAA+E;IAC/E,SAA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D,8BAA8B,EAAE,cAAc,CAC5C,GAAG,EACH,uCAAuC,CACxC;QACD,uBAAuB,EAAE,kBAAkB,CACzC,GAAG,EACH,+BAA+B,EAC/B,6BAA6B,CAC9B;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { SignBidirectionalNotification } from "./signet-contract-state-reader.ts";
|
|
2
|
-
import type { SignetPublicStateSource } from "./signet-request-response-reader.ts";
|
|
3
|
-
import type { RequestIdHex, SignBidirectionalEvent } from "./signet-requests.ts";
|
|
4
|
-
/**
|
|
5
|
-
* A {@link SignBidirectionalNotification} resolved to the authenticated
|
|
6
|
-
* request it refers to: the request record read from `callerAddress`'s own
|
|
7
|
-
* ledger, with `requestId` confirmed to be a member of that contract's index.
|
|
8
|
-
*/
|
|
9
|
-
export interface ResolvedSignetRequest {
|
|
10
|
-
/**
|
|
11
|
-
* The contract whose authenticated state the request was read from — the
|
|
12
|
-
* epsilon-derivation predecessor. Key derivation keys off THIS, never off a
|
|
13
|
-
* field taken from the notification on faith.
|
|
14
|
-
*/
|
|
15
|
-
callerAddress: string;
|
|
16
|
-
/** The request id, confirmed to be a member of `callerAddress`'s index. */
|
|
17
|
-
requestId: RequestIdHex;
|
|
18
|
-
/** The authenticated request record to sign. */
|
|
19
|
-
request: SignBidirectionalEvent;
|
|
20
|
-
}
|
|
21
|
-
/** Everything a {@link SignetRequestResolver} needs. */
|
|
22
|
-
export interface SignetRequestResolverConfig {
|
|
23
|
-
/** Source of raw contract state, e.g. midnight-js's `indexerPublicDataProvider`. */
|
|
24
|
-
readonly source: SignetPublicStateSource;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Resolves {@link SignBidirectionalNotification}s to authenticated
|
|
28
|
-
* {@link ResolvedSignetRequest}s by reading the named caller's ledger and
|
|
29
|
-
* enforcing the membership check. Construct once and reuse: resolved records
|
|
30
|
-
* are immutable (their ledger key is their hash), so they are cached by request
|
|
31
|
-
* id and a repeated notification for the same request costs no query.
|
|
32
|
-
*
|
|
33
|
-
* NB the cache is keyed by request id, NOT by contract address: a caller
|
|
34
|
-
* contract's state grows as it stores new requests, so caching its state would
|
|
35
|
-
* make the resolver blind to later requests from the same caller. Caching the
|
|
36
|
-
* immutable resolved record instead is the same pattern
|
|
37
|
-
* {@link SignetRequestResponseReader.getSignatureRequest} uses.
|
|
38
|
-
*/
|
|
39
|
-
export declare class SignetRequestResolver {
|
|
40
|
-
private readonly source;
|
|
41
|
-
private readonly resolvedCache;
|
|
42
|
-
/**
|
|
43
|
-
* @param config - The state source to read caller ledgers through.
|
|
44
|
-
*/
|
|
45
|
-
constructor(config: SignetRequestResolverConfig);
|
|
46
|
-
/**
|
|
47
|
-
* Resolve a notification to its authenticated request, or `undefined` when it
|
|
48
|
-
* cannot be trusted: the caller contract has no state, or `requestId` is not
|
|
49
|
-
* a member of the map at `requestsPath` (forged, stale, wrong field,
|
|
50
|
-
* or not yet indexed — poll again). Never throws on an untrusted
|
|
51
|
-
* notification; a bad one is dropped, not surfaced as an error.
|
|
52
|
-
*
|
|
53
|
-
* @param requestId - The request id the notification was registered under
|
|
54
|
-
* (the registry map key — the V1 payload does not carry one).
|
|
55
|
-
* @param notification - The decoded notification.
|
|
56
|
-
* @returns The authenticated request, or `undefined` to drop the notification.
|
|
57
|
-
*/
|
|
58
|
-
resolve(requestId: RequestIdHex, notification: SignBidirectionalNotification): Promise<ResolvedSignetRequest | undefined>;
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=signet-request-resolver.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signet-request-resolver.d.ts","sourceRoot":"","sources":["../src/signet-request-resolver.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,KAAK,EACV,YAAY,EACZ,sBAAsB,EACvB,MAAM,sBAAsB,CAAC;AAE9B;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB,2EAA2E;IAC3E,SAAS,EAAE,YAAY,CAAC;IACxB,gDAAgD;IAChD,OAAO,EAAE,sBAAsB,CAAC;CACjC;AAED,wDAAwD;AACxD,MAAM,WAAW,2BAA2B;IAC1C,oFAAoF;IACpF,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC;CAC1C;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0B;IAIjD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAkD;IAEhF;;OAEG;gBACS,MAAM,EAAE,2BAA2B;IAI/C;;;;;;;;;;;OAWG;IACG,OAAO,CACX,SAAS,EAAE,YAAY,EACvB,YAAY,EAAE,6BAA6B,GAC1C,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;CA8B9C"}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
// Turn a SignBidirectionalNotification into an AUTHENTICATED request record.
|
|
2
|
-
// This is the security core of the discovery flow (see
|
|
3
|
-
// knowledge-base/caller-attribution.md): the notification says only WHERE to
|
|
4
|
-
// look; the request that gets signed is read from the named caller's own
|
|
5
|
-
// authenticated ledger, and the notification's `requestId` must be a member
|
|
6
|
-
// of that contract's request index. An attacker cannot write into a contract
|
|
7
|
-
// it does not control, so a forged notification can at most re-point at a
|
|
8
|
-
// legitimate request that already exists — never inject one.
|
|
9
|
-
//
|
|
10
|
-
// Key derivation stays f(callerAddress, path), keyed off the contract whose
|
|
11
|
-
// authenticated state was actually read — the notification registry is a
|
|
12
|
-
// pointer board, never an authority.
|
|
13
|
-
import { lookupSignetRequestAt } from "./signature-requests-state-reader.js";
|
|
14
|
-
/**
|
|
15
|
-
* Resolves {@link SignBidirectionalNotification}s to authenticated
|
|
16
|
-
* {@link ResolvedSignetRequest}s by reading the named caller's ledger and
|
|
17
|
-
* enforcing the membership check. Construct once and reuse: resolved records
|
|
18
|
-
* are immutable (their ledger key is their hash), so they are cached by request
|
|
19
|
-
* id and a repeated notification for the same request costs no query.
|
|
20
|
-
*
|
|
21
|
-
* NB the cache is keyed by request id, NOT by contract address: a caller
|
|
22
|
-
* contract's state grows as it stores new requests, so caching its state would
|
|
23
|
-
* make the resolver blind to later requests from the same caller. Caching the
|
|
24
|
-
* immutable resolved record instead is the same pattern
|
|
25
|
-
* {@link SignetRequestResponseReader.getSignatureRequest} uses.
|
|
26
|
-
*/
|
|
27
|
-
export class SignetRequestResolver {
|
|
28
|
-
source;
|
|
29
|
-
// Resolved records never change; cache them so a redelivered notification for
|
|
30
|
-
// the same request id does not re-query the caller's state.
|
|
31
|
-
resolvedCache = new Map();
|
|
32
|
-
/**
|
|
33
|
-
* @param config - The state source to read caller ledgers through.
|
|
34
|
-
*/
|
|
35
|
-
constructor(config) {
|
|
36
|
-
this.source = config.source;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Resolve a notification to its authenticated request, or `undefined` when it
|
|
40
|
-
* cannot be trusted: the caller contract has no state, or `requestId` is not
|
|
41
|
-
* a member of the map at `requestsPath` (forged, stale, wrong field,
|
|
42
|
-
* or not yet indexed — poll again). Never throws on an untrusted
|
|
43
|
-
* notification; a bad one is dropped, not surfaced as an error.
|
|
44
|
-
*
|
|
45
|
-
* @param requestId - The request id the notification was registered under
|
|
46
|
-
* (the registry map key — the V1 payload does not carry one).
|
|
47
|
-
* @param notification - The decoded notification.
|
|
48
|
-
* @returns The authenticated request, or `undefined` to drop the notification.
|
|
49
|
-
*/
|
|
50
|
-
async resolve(requestId, notification) {
|
|
51
|
-
const cached = this.resolvedCache.get(requestId);
|
|
52
|
-
if (cached !== undefined) {
|
|
53
|
-
return cached;
|
|
54
|
-
}
|
|
55
|
-
let state;
|
|
56
|
-
try {
|
|
57
|
-
state = await this.source.queryContractState(notification.callerAddress);
|
|
58
|
-
}
|
|
59
|
-
catch {
|
|
60
|
-
return undefined; // caller address not a contract / transient read error
|
|
61
|
-
}
|
|
62
|
-
if (!state?.data) {
|
|
63
|
-
return undefined; // no state at the named caller — cannot authenticate
|
|
64
|
-
}
|
|
65
|
-
const request = lookupSignetRequestAt(state.data, notification.requestsPath, requestId);
|
|
66
|
-
if (request === undefined) {
|
|
67
|
-
return undefined; // membership check failed — drop the notification
|
|
68
|
-
}
|
|
69
|
-
const resolved = {
|
|
70
|
-
callerAddress: notification.callerAddress,
|
|
71
|
-
requestId,
|
|
72
|
-
request,
|
|
73
|
-
};
|
|
74
|
-
this.resolvedCache.set(requestId, resolved);
|
|
75
|
-
return resolved;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
//# sourceMappingURL=signet-request-resolver.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signet-request-resolver.js","sourceRoot":"","sources":["../src/signet-request-resolver.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,uDAAuD;AACvD,6EAA6E;AAC7E,yEAAyE;AACzE,4EAA4E;AAC5E,6EAA6E;AAC7E,0EAA0E;AAC1E,6DAA6D;AAC7D,EAAE;AACF,4EAA4E;AAC5E,yEAAyE;AACzE,qCAAqC;AAErC,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAiC7E;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,qBAAqB;IACf,MAAM,CAA0B;IAEjD,8EAA8E;IAC9E,4DAA4D;IAC3C,aAAa,GAAG,IAAI,GAAG,EAAuC,CAAC;IAEhF;;OAEG;IACH,YAAY,MAAmC;QAC7C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,OAAO,CACX,SAAuB,EACvB,YAA2C;QAE3C,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,SAAS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