@sig-net/midnight 0.14.0 → 0.16.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.
Files changed (57) hide show
  1. package/README.md +133 -48
  2. package/dist/constants.d.ts +55 -0
  3. package/dist/constants.d.ts.map +1 -1
  4. package/dist/constants.js +85 -5
  5. package/dist/constants.js.map +1 -1
  6. package/dist/ecdsa-attestation.d.ts +6 -5
  7. package/dist/ecdsa-attestation.d.ts.map +1 -1
  8. package/dist/ecdsa-attestation.js +5 -4
  9. package/dist/ecdsa-attestation.js.map +1 -1
  10. package/dist/index.d.ts +1 -2
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +3 -4
  13. package/dist/index.js.map +1 -1
  14. package/dist/managed/compiler/contract-info.json +12 -1
  15. package/dist/managed/compiler/contract-manifest.json +8 -8
  16. package/dist/managed/contract/index.d.ts +8 -6
  17. package/dist/managed/contract/index.js +76 -60
  18. package/dist/managed/contract/index.js.map +1 -1
  19. package/dist/signature-requests-state-reader.d.ts +29 -10
  20. package/dist/signature-requests-state-reader.d.ts.map +1 -1
  21. package/dist/signature-requests-state-reader.js +67 -21
  22. package/dist/signature-requests-state-reader.js.map +1 -1
  23. package/dist/signature-response-verification.d.ts +1 -1
  24. package/dist/signature-response-verification.d.ts.map +1 -1
  25. package/dist/signature-response-verification.js +3 -3
  26. package/dist/signature-response-verification.js.map +1 -1
  27. package/dist/signature-state-reading.d.ts +17 -25
  28. package/dist/signature-state-reading.d.ts.map +1 -1
  29. package/dist/signature-state-reading.js +39 -59
  30. package/dist/signature-state-reading.js.map +1 -1
  31. package/dist/signet-contract-events.d.ts +262 -0
  32. package/dist/signet-contract-events.d.ts.map +1 -0
  33. package/dist/signet-contract-events.js +266 -0
  34. package/dist/signet-contract-events.js.map +1 -0
  35. package/dist/signet-evtype2tx-requests.d.ts +4 -4
  36. package/dist/signet-evtype2tx-requests.d.ts.map +1 -1
  37. package/dist/signet-evtype2tx-requests.js +3 -3
  38. package/dist/signet-request-feed.d.ts +59 -34
  39. package/dist/signet-request-feed.d.ts.map +1 -1
  40. package/dist/signet-request-feed.js +95 -62
  41. package/dist/signet-request-feed.js.map +1 -1
  42. package/dist/signet-request-response-reader.d.ts +70 -62
  43. package/dist/signet-request-response-reader.d.ts.map +1 -1
  44. package/dist/signet-request-response-reader.js +88 -102
  45. package/dist/signet-request-response-reader.js.map +1 -1
  46. package/dist/signet-requests.js +2 -2
  47. package/dist/signet-requests.js.map +1 -1
  48. package/package.json +2 -2
  49. package/src/Signet.compact +90 -43
  50. package/dist/signet-contract-state-reader.d.ts +0 -241
  51. package/dist/signet-contract-state-reader.d.ts.map +0 -1
  52. package/dist/signet-contract-state-reader.js +0 -345
  53. package/dist/signet-contract-state-reader.js.map +0 -1
  54. package/dist/signet-request-resolver.d.ts +0 -60
  55. package/dist/signet-request-resolver.d.ts.map +0 -1
  56. package/dist/signet-request-resolver.js +0 -78
  57. package/dist/signet-request-resolver.js.map +0 -1
@@ -1,345 +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, signetFieldNode) 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, signetFieldNode, 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 `requestsIndexField` (after the 32 callerAddress bytes). */
207
- const NOTIFICATION_REQUESTS_INDEX_FIELD_OFFSET = 32;
208
- /** The only payload interpretation {@link decodeSignBidirectionalNotification} understands today. */
209
- const SUPPORTED_NOTIFICATION_VERSION = 1n;
210
- /**
211
- * Unpack a stored {@link SignBidirectionalNotificationRecord}'s payload by
212
- * the fixed V1 offsets: the decode twin of the compiled
213
- * `constructSignBidirectionalEventNotificationV1` circuit (byte plumbing
214
- * only: the pack↔decode lockstep is pinned by the state-reader unit test that
215
- * round-trips through the real circuit). V1 layout:
216
- * callerAddress (32) ++ requestsIndexField (1) ++ zero padding (95).
217
- *
218
- * Fails closed on an unrecognised `version`: a future payload layout adds a
219
- * branch here rather than silently misinterpreting bytes under the V1 offsets.
220
- *
221
- * @param record - The raw on-ledger record.
222
- * @returns The decoded flat notification.
223
- * @throws Error if the record's `version` is not one this decoder understands.
224
- */
225
- export function decodeSignBidirectionalNotification(record) {
226
- if (record.version !== SUPPORTED_NOTIFICATION_VERSION) {
227
- throw new Error(`SignBidirectionalEventNotification version ${record.version} is not supported ` +
228
- `(this decoder understands version ${SUPPORTED_NOTIFICATION_VERSION})`);
229
- }
230
- const callerAddress = bytesToHex(record.payload.slice(NOTIFICATION_CALLER_ADDRESS_OFFSET, NOTIFICATION_REQUESTS_INDEX_FIELD_OFFSET));
231
- const requestsIndexField = record.payload[NOTIFICATION_REQUESTS_INDEX_FIELD_OFFSET];
232
- if (requestsIndexField === undefined) {
233
- throw new Error(`SignBidirectionalEventNotification payload is ${record.payload.length} bytes: ` +
234
- `too short for the V1 requestsIndexField at offset ${NOTIFICATION_REQUESTS_INDEX_FIELD_OFFSET}`);
235
- }
236
- return {
237
- version: Number(record.version),
238
- callerAddress,
239
- requestsIndexField,
240
- };
241
- }
242
- /**
243
- * Build the flattened JS map key for a `(requestId, count)` pair: the
244
- * composite Compact {@link SignetMapKey} as a string so it works as a JS
245
- * `Map` key.
246
- *
247
- * @param id - The request id the entry belongs to, in canonical hex form.
248
- * @param count - 0-based post count within that request.
249
- * @returns `"<hexRequestId>:<count>"`.
250
- */
251
- export function signetMapEntryKey(id, count) {
252
- return `${id}:${count}`;
253
- }
254
- /** Decode a `Map<RequestId, Counter>` ledger field into a {@link SignetCounterIndex}. */
255
- function readCounterMap(raw, field) {
256
- const counterMap = signetFieldNode(raw, field).asMap();
257
- if (counterMap === undefined) {
258
- throw new Error(`Ledger field ${field} is not a Map`);
259
- }
260
- const index = new Map();
261
- for (const key of counterMap.keys()) {
262
- // fromValue consumes its input, so hand each descriptor a copy.
263
- const requestId = requestIdType.fromValue([...key.value]);
264
- // A Counter is stored as a plain u64 cell.
265
- const cell = counterMap.get(key)?.asCell();
266
- if (cell === undefined)
267
- continue;
268
- index.set(requestIdHex(requestId), u64.fromValue([...cell.value]));
269
- }
270
- return index;
271
- }
272
- /** Decode a `Map<SignetMapKey, T>` ledger field into a string-keyed JS map. */
273
- function readSignetKeyedMap(raw, field, valueType) {
274
- const map = signetFieldNode(raw, field).asMap();
275
- if (map === undefined) {
276
- throw new Error(`Ledger field ${field} is not a Map`);
277
- }
278
- const index = new Map();
279
- for (const key of map.keys()) {
280
- const mapKey = signetMapKeyType.fromValue([...key.value]);
281
- const cell = map.get(key)?.asCell();
282
- if (cell === undefined)
283
- continue;
284
- index.set(signetMapEntryKey(requestIdHex(mapKey.requestId), mapKey.count), valueType.fromValue([...cell.value]));
285
- }
286
- return index;
287
- }
288
- /**
289
- * Read ONLY the notification registry (ledger field
290
- * {@link SIGN_BIDIRECTIONAL_EVENT_NOTIFICATION_MAP_FIELD}) out of raw signet
291
- * contract state: the poll-loop primitive of {@link SignetRequestFeed},
292
- * which cycles frequently and has no use for the response fields. One record
293
- * per request id (the count-0 post, see
294
- * {@link SignBidirectionalNotificationIndex}).
295
- *
296
- * @param raw - Raw contract state, e.g. `queryContractState(address).data`
297
- * from the indexer or `ctx.currentQueryContext.state` from the simulator.
298
- * @returns The registry, keyed by the hex request id of each entry's map key.
299
- * @throws Error if the field is missing or is not a Map.
300
- */
301
- export function readSignBidirectionalNotificationIndexFromState(raw) {
302
- const notificationMap = signetFieldNode(raw, SIGN_BIDIRECTIONAL_EVENT_NOTIFICATION_MAP_FIELD).asMap();
303
- if (notificationMap === undefined) {
304
- throw new Error(`Ledger field ${SIGN_BIDIRECTIONAL_EVENT_NOTIFICATION_MAP_FIELD} is not a Map`);
305
- }
306
- const index = new Map();
307
- const counts = new Map();
308
- for (const key of notificationMap.keys()) {
309
- // fromValue consumes its input, so hand each descriptor a copy.
310
- const mapKey = signetMapKeyType.fromValue([...key.value]);
311
- const cell = notificationMap.get(key)?.asCell();
312
- if (cell === undefined)
313
- continue;
314
- const id = requestIdHex(mapKey.requestId);
315
- const seen = counts.get(id);
316
- // Keep the FIRST post (lowest count) per request id.
317
- if (seen !== undefined && seen <= mapKey.count)
318
- continue;
319
- counts.set(id, mapKey.count);
320
- index.set(id, signBidirectionalNotificationType.fromValue([...cell.value]));
321
- }
322
- return index;
323
- }
324
- /**
325
- * MPC-/client-style read: parse the signet contract's ledger fields out of
326
- * raw contract state by field position alone, with no compiled contract and
327
- * no generated `ledger()`, only the declaration-order layout and the
328
- * canonical descriptors above.
329
- *
330
- * @param raw - Raw contract state, e.g. `queryContractState(address).data`
331
- * from the indexer or `ctx.currentQueryContext.state` from the simulator.
332
- * @returns The decoded {@link SignetContractLedger}.
333
- * @throws Error if a field is missing or has the wrong state-value shape.
334
- */
335
- export function readSignetContractLedgerFromState(raw) {
336
- return {
337
- signBidirectionalEventNotificationCounterMap: readCounterMap(raw, SIGN_BIDIRECTIONAL_EVENT_NOTIFICATION_COUNTER_MAP_FIELD),
338
- signBidirectionalEventNotificationMap: readSignBidirectionalNotificationIndexFromState(raw),
339
- respondCounterMap: readCounterMap(raw, RESPOND_COUNTER_MAP_FIELD),
340
- respondMap: readSignetKeyedMap(raw, RESPOND_MAP_FIELD, signatureRespondedEventType),
341
- respondBidirectionalCounterMap: readCounterMap(raw, RESPOND_BIDIRECTIONAL_COUNTER_MAP_FIELD),
342
- respondBidirectionalMap: readSignetKeyedMap(raw, RESPOND_BIDIRECTIONAL_MAP_FIELD, respondBidirectionalEventType),
343
- };
344
- }
345
- //# 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,0EAA0E;AAC1E,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,eAAe,EACf,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,GAA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C;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 `requestsIndexField` (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 `requestsIndexField` (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.requestsIndexField, 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,CAAC,CAAC;QACjD,IAAI,MAAM,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