@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
@@ -38,24 +38,42 @@ export interface SignetRequestsLedger {
38
38
  *
39
39
  * @param raw - Raw contract state, e.g. `queryContractState(address).data`
40
40
  * from the indexer or `ctx.currentQueryContext.state` from the simulator.
41
- * @param requestsIndexField - Ledger field position of the request index.
42
- * @param nonceField - Ledger field position of the request counter.
41
+ * @param requestsIndexPath - Resolved ledger-tree path of the request index.
42
+ * @param noncePath - Resolved ledger-tree path of the request counter.
43
43
  * @returns The decoded {@link SignetRequestsLedger}.
44
44
  * @throws Error if a field is missing, has the wrong state-value shape, or a
45
45
  * record matches no capacity split.
46
46
  */
47
- export declare function readSignetRequestsLedgerFromState(raw: RawContractState, requestsIndexField: number, nonceField: number): SignetRequestsLedger;
47
+ export declare function readSignetRequestsLedgerFromState(raw: RawContractState, requestsIndexPath: readonly number[], noncePath: readonly number[]): SignetRequestsLedger;
48
+ /**
49
+ * Enumerate a contract's WHOLE request index at an arbitrary ledger path:
50
+ * the discovery primitive of the event-based feed. A notification event
51
+ * names only the requester contract and the path of its request map, so the
52
+ * MPC enumerates that map and serves what it has not served before: every
53
+ * record here was read from the caller's own authenticated ledger.
54
+ *
55
+ * Fail-closed like {@link lookupSignetRequestAt}: a path out of range, a
56
+ * non-Map node, or an undecodable cell yields an EMPTY (or smaller) index
57
+ * rather than a throw, so a malformed or adversarial notification can never
58
+ * crash the reader.
59
+ *
60
+ * @param raw - Raw contract state, e.g. `queryContractState(address).data`.
61
+ * @param requestsPath - Resolved ledger-tree path of the request index in
62
+ * `raw`, as the notification carries it.
63
+ * @returns The decoded index, keyed by hex request id, empty when the path
64
+ * holds no readable request map.
65
+ */
66
+ export declare function readSignetRequestIndexAt(raw: RawContractState, requestsPath: readonly number[]): SignBidirectionalEventIndex;
48
67
  /**
49
68
  * Look up ONE request by id in a contract's request index at an arbitrary
50
69
  * ledger field, the single-record sibling of
51
- * {@link readSignetRequestsLedgerFromState}, and what the discovery path
70
+ * {@link readSignetRequestsLedgerFromState}, and what a point verification
52
71
  * uses: a notification names both the requester contract AND which field
53
72
  * holds its index.
54
73
  *
55
- * This is the mandatory membership check of the discovery flow (see
56
- * signet-request-resolver.ts): `undefined` means the id is NOT a member of the
57
- * index at `fieldIndex` (the notification is forged, stale, points at the
58
- * wrong field, or the request is not yet indexed) and the caller MUST drop it.
74
+ * `undefined` means the id is NOT a member of the index at `requestsPath`
75
+ * (the pointer is forged, stale, points at the wrong field, or the request is
76
+ * not yet indexed) and the caller MUST drop it.
59
77
  * Every non-membership case (field out of range, field is not a Map, id absent,
60
78
  * a cell that fails to decode) returns `undefined` rather than throwing, so a
61
79
  * malformed or adversarial notification can never crash the reader.
@@ -66,9 +84,10 @@ export declare function readSignetRequestsLedgerFromState(raw: RawContractState,
66
84
  * fieldIndex, …).requestsIndex.get(requestId)`.
67
85
  *
68
86
  * @param raw - Raw contract state, e.g. `queryContractState(address).data`.
69
- * @param fieldIndex - Ledger field position of the request index in `raw`.
87
+ * @param requestsPath - Resolved ledger-tree path of the request index in
88
+ * `raw`, as the notification carries it.
70
89
  * @param requestId - The request id to look up.
71
90
  * @returns The stored request record, or `undefined` when it is not a member.
72
91
  */
73
- export declare function lookupSignetRequestAt(raw: RawContractState, fieldIndex: number, requestId: RequestIdHex): SignBidirectionalEvent | undefined;
92
+ export declare function lookupSignetRequestAt(raw: RawContractState, requestsPath: readonly number[], requestId: RequestIdHex): SignBidirectionalEvent | undefined;
74
93
  //# sourceMappingURL=signature-requests-state-reader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"signature-requests-state-reader.d.ts","sourceRoot":"","sources":["../src/signature-requests-state-reader.ts"],"names":[],"mappings":"AAmBA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,EACjC,MAAM,sBAAsB,CAAC;AAK9B,OAAO,EAIL,KAAK,gBAAgB,EACtB,MAAM,8BAA8B,CAAC;AAEtC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,yBAAyB,KAAK,CAAC;AA6F5C;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,aAAa,EAAE,2BAA2B,CAAC;CAC5C;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iCAAiC,CAC/C,GAAG,EAAE,gBAAgB,EACrB,kBAAkB,EAAE,MAAM,EAC1B,UAAU,EAAE,MAAM,GACjB,oBAAoB,CAqBtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,gBAAgB,EACrB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,YAAY,GACtB,sBAAsB,GAAG,SAAS,CA2BpC"}
1
+ {"version":3,"file":"signature-requests-state-reader.d.ts","sourceRoot":"","sources":["../src/signature-requests-state-reader.ts"],"names":[],"mappings":"AAmBA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,EACjC,MAAM,sBAAsB,CAAC;AAK9B,OAAO,EAIL,KAAK,gBAAgB,EACtB,MAAM,8BAA8B,CAAC;AAEtC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,yBAAyB,KAAK,CAAC;AA6F5C;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,aAAa,EAAE,2BAA2B,CAAC;CAC5C;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iCAAiC,CAC/C,GAAG,EAAE,gBAAgB,EACrB,iBAAiB,EAAE,SAAS,MAAM,EAAE,EACpC,SAAS,EAAE,SAAS,MAAM,EAAE,GAC3B,oBAAoB,CAqBtB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,gBAAgB,EACrB,YAAY,EAAE,SAAS,MAAM,EAAE,GAC9B,2BAA2B,CAwB7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,gBAAgB,EACrB,YAAY,EAAE,SAAS,MAAM,EAAE,EAC/B,SAAS,EAAE,YAAY,GACtB,sBAAsB,GAAG,SAAS,CA2BpC"}
@@ -2,17 +2,17 @@
2
2
  // request ledger fields out of a contract's raw state WITHOUT the compiled
3
3
  // contract. This is how the MPC monitor consumes signet contracts: it has only
4
4
  // a contract address, queries raw state from the indexer
5
- // (queryContractState(address).data), and decodes by ledger field POSITION.
5
+ // (queryContractState(address).data), and decodes by ledger-tree PATH.
6
6
  // A contract is free to place its request index at any field: the caller
7
- // supplies the position, which the discovery path learns from the
8
- // notification's requestsIndexField.
9
- // The compiled contract's generated ledger() does exactly this walk internally.
7
+ // supplies the resolved path, which the discovery path learns from the
8
+ // notification's requestsPath (sourced from the caller's contract-info.json).
9
+ // The compiled contract's generated ledger() follows exactly this path internally.
10
10
  // The record descriptors themselves are the parameterised twins in
11
11
  // signet-requests.ts. The generic tree walk and shared base descriptors live
12
12
  // in signature-state-reading.ts.
13
13
  import { calculateRequestId, signBidirectionalEventDescriptor, } from "./signet-evtype2tx-requests.js";
14
14
  import { requestIdHex, } from "./signet-requests.js";
15
- import { requestIdType, signetFieldNode, u64, } from "./signature-state-reading.js";
15
+ import { requestIdType, signetFieldNodeByPath, u64, } from "./signature-state-reading.js";
16
16
  /**
17
17
  * Aligned-value entry count of an event record EXCLUDING the capacity-scaled
18
18
  * vectors: sender (1) + requestNonce (1) + keyVersion (1) + path (1) +
@@ -115,16 +115,16 @@ function decodeSignBidirectionalEvent(atoms, expectedRequestId) {
115
115
  *
116
116
  * @param raw - Raw contract state, e.g. `queryContractState(address).data`
117
117
  * from the indexer or `ctx.currentQueryContext.state` from the simulator.
118
- * @param requestsIndexField - Ledger field position of the request index.
119
- * @param nonceField - Ledger field position of the request counter.
118
+ * @param requestsIndexPath - Resolved ledger-tree path of the request index.
119
+ * @param noncePath - Resolved ledger-tree path of the request counter.
120
120
  * @returns The decoded {@link SignetRequestsLedger}.
121
121
  * @throws Error if a field is missing, has the wrong state-value shape, or a
122
122
  * record matches no capacity split.
123
123
  */
124
- export function readSignetRequestsLedgerFromState(raw, requestsIndexField, nonceField) {
125
- const map = signetFieldNode(raw, requestsIndexField).asMap();
124
+ export function readSignetRequestsLedgerFromState(raw, requestsIndexPath, noncePath) {
125
+ const map = signetFieldNodeByPath(raw, requestsIndexPath).asMap();
126
126
  if (map === undefined) {
127
- throw new Error(`Ledger field ${requestsIndexField} is not a Map`);
127
+ throw new Error(`Ledger field at path ${JSON.stringify(requestsIndexPath)} is not a Map`);
128
128
  }
129
129
  const requestsIndex = new Map();
130
130
  for (const key of map.keys()) {
@@ -135,24 +135,69 @@ export function readSignetRequestsLedgerFromState(raw, requestsIndexField, nonce
135
135
  continue;
136
136
  requestsIndex.set(requestId, decodeSignBidirectionalEvent(cell.value, requestId));
137
137
  }
138
- const nonceCell = signetFieldNode(raw, nonceField).asCell();
138
+ const nonceCell = signetFieldNodeByPath(raw, noncePath).asCell();
139
139
  if (nonceCell === undefined) {
140
- throw new Error(`Ledger field ${nonceField} is not a Cell`);
140
+ throw new Error(`Ledger field at path ${JSON.stringify(noncePath)} is not a Cell`);
141
141
  }
142
142
  const nonce = u64.fromValue([...nonceCell.value]);
143
143
  return { nonce, requestsIndex };
144
144
  }
145
+ /**
146
+ * Enumerate a contract's WHOLE request index at an arbitrary ledger path:
147
+ * the discovery primitive of the event-based feed. A notification event
148
+ * names only the requester contract and the path of its request map, so the
149
+ * MPC enumerates that map and serves what it has not served before: every
150
+ * record here was read from the caller's own authenticated ledger.
151
+ *
152
+ * Fail-closed like {@link lookupSignetRequestAt}: a path out of range, a
153
+ * non-Map node, or an undecodable cell yields an EMPTY (or smaller) index
154
+ * rather than a throw, so a malformed or adversarial notification can never
155
+ * crash the reader.
156
+ *
157
+ * @param raw - Raw contract state, e.g. `queryContractState(address).data`.
158
+ * @param requestsPath - Resolved ledger-tree path of the request index in
159
+ * `raw`, as the notification carries it.
160
+ * @returns The decoded index, keyed by hex request id, empty when the path
161
+ * holds no readable request map.
162
+ */
163
+ export function readSignetRequestIndexAt(raw, requestsPath) {
164
+ const index = new Map();
165
+ let node;
166
+ try {
167
+ node = signetFieldNodeByPath(raw, requestsPath);
168
+ }
169
+ catch {
170
+ return index; // path out of range for this contract
171
+ }
172
+ const map = node.asMap();
173
+ if (map === undefined) {
174
+ return index; // the named field is not a request index
175
+ }
176
+ for (const key of map.keys()) {
177
+ // fromValue consumes its input, so hand each descriptor a copy.
178
+ const requestId = requestIdHex(requestIdType.fromValue([...key.value]));
179
+ const cell = map.get(key)?.asCell();
180
+ if (cell === undefined)
181
+ continue;
182
+ try {
183
+ index.set(requestId, decodeSignBidirectionalEvent(cell.value, requestId));
184
+ }
185
+ catch {
186
+ continue; // a cell that is not a decodable request record
187
+ }
188
+ }
189
+ return index;
190
+ }
145
191
  /**
146
192
  * Look up ONE request by id in a contract's request index at an arbitrary
147
193
  * ledger field, the single-record sibling of
148
- * {@link readSignetRequestsLedgerFromState}, and what the discovery path
194
+ * {@link readSignetRequestsLedgerFromState}, and what a point verification
149
195
  * uses: a notification names both the requester contract AND which field
150
196
  * holds its index.
151
197
  *
152
- * This is the mandatory membership check of the discovery flow (see
153
- * signet-request-resolver.ts): `undefined` means the id is NOT a member of the
154
- * index at `fieldIndex` (the notification is forged, stale, points at the
155
- * wrong field, or the request is not yet indexed) and the caller MUST drop it.
198
+ * `undefined` means the id is NOT a member of the index at `requestsPath`
199
+ * (the pointer is forged, stale, points at the wrong field, or the request is
200
+ * not yet indexed) and the caller MUST drop it.
156
201
  * Every non-membership case (field out of range, field is not a Map, id absent,
157
202
  * a cell that fails to decode) returns `undefined` rather than throwing, so a
158
203
  * malformed or adversarial notification can never crash the reader.
@@ -163,17 +208,18 @@ export function readSignetRequestsLedgerFromState(raw, requestsIndexField, nonce
163
208
  * fieldIndex, …).requestsIndex.get(requestId)`.
164
209
  *
165
210
  * @param raw - Raw contract state, e.g. `queryContractState(address).data`.
166
- * @param fieldIndex - Ledger field position of the request index in `raw`.
211
+ * @param requestsPath - Resolved ledger-tree path of the request index in
212
+ * `raw`, as the notification carries it.
167
213
  * @param requestId - The request id to look up.
168
214
  * @returns The stored request record, or `undefined` when it is not a member.
169
215
  */
170
- export function lookupSignetRequestAt(raw, fieldIndex, requestId) {
216
+ export function lookupSignetRequestAt(raw, requestsPath, requestId) {
171
217
  let node;
172
218
  try {
173
- node = signetFieldNode(raw, fieldIndex);
219
+ node = signetFieldNodeByPath(raw, requestsPath);
174
220
  }
175
221
  catch {
176
- return undefined; // field position out of range for this contract
222
+ return undefined; // path out of range for this contract
177
223
  }
178
224
  const map = node.asMap();
179
225
  if (map === undefined) {
@@ -1 +1 @@
1
- {"version":3,"file":"signature-requests-state-reader.js","sourceRoot":"","sources":["../src/signature-requests-state-reader.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,2EAA2E;AAC3E,+EA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EAAE,aAAa,EAAE,CAAC;AAClC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,qBAAqB,CACnC,GAAqB,EACrB,UAAkB,EAClB,SAAuB;IAEvB,IAAI,IAAI,CAAC;IACT,IAAI,CAAC;QACH,IAAI,GAAG,eAAe,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IAC1C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC,CAAC,gDAAgD;IACpE,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;IACzB,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,OAAO,SAAS,CAAC,CAAC,yCAAyC;IAC7D,CAAC;IACD,KAAK,MAAM,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;QAC7B,gEAAgE;QAChE,IAAI,YAAY,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC;YACxE,SAAS;QACX,CAAC;QACD,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;QACpC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,IAAI,CAAC;YACH,OAAO,4BAA4B,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QAC7D,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAC,CAAC,gDAAgD;QACpE,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC,CAAC,2BAA2B;AAC/C,CAAC"}
1
+ {"version":3,"file":"signature-requests-state-reader.js","sourceRoot":"","sources":["../src/signature-requests-state-reader.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,2EAA2E;AAC3E,+EAA+E;AAC/E,yDAAyD;AACzD,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AI,CAAC;QACH,IAAI,GAAG,qBAAqB,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;IAClD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC,CAAC,sCAAsC;IAC1D,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;IACzB,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,OAAO,SAAS,CAAC,CAAC,yCAAyC;IAC7D,CAAC;IACD,KAAK,MAAM,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;QAC7B,gEAAgE;QAChE,IAAI,YAAY,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC;YACxE,SAAS;QACX,CAAC;QACD,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;QACpC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,IAAI,CAAC;YACH,OAAO,4BAA4B,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QAC7D,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAC,CAAC,gDAAgD;QACpE,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC,CAAC,2BAA2B;AAC/C,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { SignBidirectionalEvent } from "./signet-requests.ts";
2
- import type { SignatureRespondedEvent } from "./signet-contract-state-reader.ts";
2
+ import type { SignatureRespondedEvent } from "./signet-contract-events.ts";
3
3
  /**
4
4
  * Recover the EVM address that produced a response signature, over the
5
5
  * signing hash of the transaction the request describes.
@@ -1 +1 @@
1
- {"version":3,"file":"signature-response-verification.d.ts","sourceRoot":"","sources":["../src/signature-response-verification.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAEjF;;;;;;;;;;GAUG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,sBAAsB,EAC/B,QAAQ,EAAE,uBAAuB,GAChC,MAAM,CAKR;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,sBAAsB,EAC/B,QAAQ,EAAE,uBAAuB,EACjC,cAAc,EAAE,MAAM,GACrB,OAAO,CAST"}
1
+ {"version":3,"file":"signature-response-verification.d.ts","sourceRoot":"","sources":["../src/signature-response-verification.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E;;;;;;;;;;GAUG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,sBAAsB,EAC/B,QAAQ,EAAE,uBAAuB,GAChC,MAAM,CAKR;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,sBAAsB,EAC/B,QAAQ,EAAE,uBAAuB,EACjC,cAAc,EAAE,MAAM,GACrB,OAAO,CAST"}
@@ -1,6 +1,6 @@
1
- // Client-side verification of MPC signature responses. Posting to the
2
- // signet contract's signature response log is UNAUTHENTICATED (see "Signet
3
- // Layout" in Signet.compact), so a poller must verify every posted response
1
+ // Client-side verification of MPC signature responses. The signet contract
2
+ // emits signature responses UNAUTHENTICATED (see the module header in
3
+ // Signet.compact), so a poller must verify every posted response
4
4
  // before trusting it: rebuild the unsigned EVM transaction from the on-ledger
5
5
  // request record, assembled exactly as the MPC assembles it (sig-net/mpc
6
6
  // response server, managed/erc20-vault/signet/calldata-builder.ts), and
@@ -1 +1 @@
1
- {"version":3,"file":"signature-response-verification.js","sourceRoot":"","sources":["../src/signature-response-verification.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,2EAA2E;AAC3E,4EAA4E;AAC5E,8EAA8E;AAC9E,yEAAyE;AACzE,wEAAwE;AACxE,6EAA6E;AAC7E,oDAAoD;AAEpD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAEpD,OAAO,EACL,8CAA8C,EAC9C,kCAAkC,GACnC,MAAM,gCAAgC,CAAC;AAIxC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,8BAA8B,CAC5C,OAA+B,EAC/B,QAAiC;IAEjC,OAAO,cAAc,CACnB,8CAA8C,CAAC,OAAO,CAAC,CAAC,YAAY,EACpE,kCAAkC,CAAC,QAAQ,CAAC,CAC7C,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,6BAA6B,CAC3C,OAA+B,EAC/B,QAAiC,EACjC,cAAsB;IAEtB,IAAI,CAAC;QACH,OAAO,CACL,8BAA8B,CAAC,OAAO,EAAE,QAAQ,CAAC;YACjD,UAAU,CAAC,cAAc,CAAC,CAC3B,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"signature-response-verification.js","sourceRoot":"","sources":["../src/signature-response-verification.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,sEAAsE;AACtE,iEAAiE;AACjE,8EAA8E;AAC9E,yEAAyE;AACzE,wEAAwE;AACxE,6EAA6E;AAC7E,oDAAoD;AAEpD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAEpD,OAAO,EACL,8CAA8C,EAC9C,kCAAkC,GACnC,MAAM,gCAAgC,CAAC;AAIxC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,8BAA8B,CAC5C,OAA+B,EAC/B,QAAiC;IAEjC,OAAO,cAAc,CACnB,8CAA8C,CAAC,OAAO,CAAC,CAAC,YAAY,EACpE,kCAAkC,CAAC,QAAQ,CAAC,CAC7C,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,6BAA6B,CAC3C,OAA+B,EAC/B,QAAiC,EACjC,cAAsB;IAEtB,IAAI,CAAC;QACH,OAAO,CACL,8BAA8B,CAAC,OAAO,EAAE,QAAQ,CAAC;YACjD,UAAU,CAAC,cAAc,CAAC,CAC3B,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
@@ -19,33 +19,25 @@ export type RawContractState = StateValue | {
19
19
  state: StateValue;
20
20
  };
21
21
  /**
22
- * Resolve a flat ledger field index to its node in the raw state tree: the
23
- * MPC-perspective primitive: given only a contract's raw state and a field
24
- * number (e.g. the `requestsIndexField` a notification names), return that
25
- * field's block of stored state, regardless of what field types sit before
26
- * or after it.
22
+ * Follow a resolved ledger-tree path to its node in raw state: the
23
+ * MPC-perspective primitive, given only a contract's raw state and the path a
24
+ * notification carries. It walks the path node for node, exactly as the
25
+ * compiled `ledger()` accessor does, and never inspects array widths or
26
+ * re-derives the compiler's chunk structure.
27
27
  *
28
- * Layout, as compactc emits it (probed on 4/15/16/20/226-field contracts;
29
- * the generated `ledger()` reader indexes with exactly these paths):
30
- * - Up to {@link CHUNK_ARITY} fields: the root array holds the fields
31
- * directly, field n at `root[n]`.
32
- * - More fields: a depth-uniform tree of chunk arrays, filled REMAINDER
33
- * FIRST: 16 fields become chunks of [1, 15], 20 become [5, 15], 226
34
- * become [1, 15x15] one level deeper. Every chunk on the rightmost spine
35
- * is therefore always FULL (exactly {@link CHUNK_ARITY} entries).
36
- *
37
- * Chunk detection walks that rightmost spine: each consecutive
38
- * arity-{@link CHUNK_ARITY} array is one chunk level to flatten. This never
39
- * misreads a field node as a chunk, because no ledger ADT stores an
40
- * arity-15 array at field level; in particular a `List` (array-typed, like
41
- * a chunk) is a fixed THREE-slot cons node. The one theoretical blind spot
42
- * is a future ADT whose field node is an arity-15 array sitting exactly at
43
- * the last declared field of a contract.
28
+ * The path is the value compactc records for a field in the client's own
29
+ * `contract-info.json` (`"index"`): a single-element path (`[4]`) for a flat
30
+ * contract's field, a longer one (`[1, 14]`) once a contract declares more
31
+ * than 15 fields and the compiler stores them in a chunk tree. Because the
32
+ * consumer is told the path rather than guessing it, no field whose own value
33
+ * is an array can be mistaken for a compiler chunk.
44
34
  *
45
35
  * @param raw - Raw contract state from the indexer or simulator.
46
- * @param flatIndex - Zero-based ledger field position in declaration order.
47
- * @returns The `StateValue` node holding that field.
48
- * @throws Error if `flatIndex` is beyond the contract's field count.
36
+ * @param path - Resolved chunk-tree path in declaration order, from the
37
+ * notification (which sources it from the client's `contract-info.json`).
38
+ * @returns The `StateValue` node at the end of the path.
39
+ * @throws Error if `path` is empty, steps into a non-array, or an index is out
40
+ * of range.
49
41
  */
50
- export declare function signetFieldNode(raw: RawContractState, flatIndex: number): StateValue;
42
+ export declare function signetFieldNodeByPath(raw: RawContractState, path: readonly number[]): StateValue;
51
43
  //# sourceMappingURL=signature-state-reading.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"signature-state-reading.d.ts","sourceRoot":"","sources":["../src/signature-state-reading.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,KAAK,WAAW,EAChB,KAAK,UAAU,EAChB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAOtD,qEAAqE;AACrE,eAAO,MAAM,GAAG,4BAA2D,CAAC;AAE5E,4CAA4C;AAC5C,eAAO,MAAM,OAAO,kBAA2B,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,WAAW,CAAC,SAAS,CAAW,CAAC;AAI7D;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG;IAAE,KAAK,EAAE,UAAU,CAAA;CAAE,CAAC;AAkBlE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,gBAAgB,EACrB,SAAS,EAAE,MAAM,GAChB,UAAU,CA+BZ"}
1
+ {"version":3,"file":"signature-state-reading.d.ts","sourceRoot":"","sources":["../src/signature-state-reading.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,KAAK,WAAW,EAChB,KAAK,UAAU,EAChB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAOtD,qEAAqE;AACrE,eAAO,MAAM,GAAG,4BAA2D,CAAC;AAE5E,4CAA4C;AAC5C,eAAO,MAAM,OAAO,kBAA2B,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,WAAW,CAAC,SAAS,CAAW,CAAC;AAI7D;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG;IAAE,KAAK,EAAE,UAAU,CAAA;CAAE,CAAC;AAWlE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,gBAAgB,EACrB,IAAI,EAAE,SAAS,MAAM,EAAE,GACtB,UAAU,CAwBZ"}
@@ -1,9 +1,9 @@
1
- // Common signet raw-state reading, shared by the request and response readers
2
- // (signature-requests-state-reader.ts, signet-contract-state-reader.ts).
1
+ // Common signet raw-state reading for the request-side readers
2
+ // (signature-requests-state-reader.ts).
3
3
  // This is the MPC-/client-style path: decode a contract's ledger fields out of
4
- // its raw state WITHOUT the compiled contract, walking the state tree by field
5
- // position alone. Here live the generic tree walk (RawContractState,
6
- // signetFieldNode) and the base type descriptors both readers share; each
4
+ // its raw state WITHOUT the compiled contract, following a resolved ledger-tree
5
+ // path. Here live the generic path walk (RawContractState,
6
+ // signetFieldNodeByPath) and the base type descriptors both readers share; each
7
7
  // reader adds only the descriptors for its own layout.
8
8
  import { CompactTypeBytes, CompactTypeUnsignedInteger, } from "@midnight-ntwrk/compact-runtime";
9
9
  import {} from "./signet-requests.js";
@@ -29,65 +29,45 @@ export const requestIdType = bytes32;
29
29
  */
30
30
  const unwrap = (raw) => "state" in raw ? raw.state : raw;
31
31
  /**
32
- * The compact compiler's chunking arity: a StateValue array level holds at
33
- * most this many entries, so a contract with more ledger fields gets a
34
- * depth-uniform tree of chunks (see {@link signetFieldNode}).
35
- */
36
- const CHUNK_ARITY = 15;
37
- /**
38
- * Resolve a flat ledger field index to its node in the raw state tree: the
39
- * MPC-perspective primitive: given only a contract's raw state and a field
40
- * number (e.g. the `requestsIndexField` a notification names), return that
41
- * field's block of stored state, regardless of what field types sit before
42
- * or after it.
43
- *
44
- * Layout, as compactc emits it (probed on 4/15/16/20/226-field contracts;
45
- * the generated `ledger()` reader indexes with exactly these paths):
46
- * - Up to {@link CHUNK_ARITY} fields: the root array holds the fields
47
- * directly, field n at `root[n]`.
48
- * - More fields: a depth-uniform tree of chunk arrays, filled REMAINDER
49
- * FIRST: 16 fields become chunks of [1, 15], 20 become [5, 15], 226
50
- * become [1, 15x15] one level deeper. Every chunk on the rightmost spine
51
- * is therefore always FULL (exactly {@link CHUNK_ARITY} entries).
32
+ * Follow a resolved ledger-tree path to its node in raw state: the
33
+ * MPC-perspective primitive, given only a contract's raw state and the path a
34
+ * notification carries. It walks the path node for node, exactly as the
35
+ * compiled `ledger()` accessor does, and never inspects array widths or
36
+ * re-derives the compiler's chunk structure.
52
37
  *
53
- * Chunk detection walks that rightmost spine: each consecutive
54
- * arity-{@link CHUNK_ARITY} array is one chunk level to flatten. This never
55
- * misreads a field node as a chunk, because no ledger ADT stores an
56
- * arity-15 array at field level; in particular a `List` (array-typed, like
57
- * a chunk) is a fixed THREE-slot cons node. The one theoretical blind spot
58
- * is a future ADT whose field node is an arity-15 array sitting exactly at
59
- * the last declared field of a contract.
38
+ * The path is the value compactc records for a field in the client's own
39
+ * `contract-info.json` (`"index"`): a single-element path (`[4]`) for a flat
40
+ * contract's field, a longer one (`[1, 14]`) once a contract declares more
41
+ * than 15 fields and the compiler stores them in a chunk tree. Because the
42
+ * consumer is told the path rather than guessing it, no field whose own value
43
+ * is an array can be mistaken for a compiler chunk.
60
44
  *
61
45
  * @param raw - Raw contract state from the indexer or simulator.
62
- * @param flatIndex - Zero-based ledger field position in declaration order.
63
- * @returns The `StateValue` node holding that field.
64
- * @throws Error if `flatIndex` is beyond the contract's field count.
46
+ * @param path - Resolved chunk-tree path in declaration order, from the
47
+ * notification (which sources it from the client's `contract-info.json`).
48
+ * @returns The `StateValue` node at the end of the path.
49
+ * @throws Error if `path` is empty, steps into a non-array, or an index is out
50
+ * of range.
65
51
  */
66
- export function signetFieldNode(raw, flatIndex) {
67
- const root = unwrap(raw);
68
- if (root.type() !== "array") {
69
- if (flatIndex === 0)
70
- return root;
71
- throw new Error(`Field index ${flatIndex} out of range: root is a leaf`);
72
- }
73
- let fields = root.asArray() ?? [];
74
- // Count chunk levels below the root along the rightmost spine: chunks on
75
- // it are always full, field nodes never have CHUNK_ARITY entries.
76
- let chunkLevels = 0;
77
- let spine = fields[fields.length - 1];
78
- while (spine !== undefined &&
79
- spine.type() === "array" &&
80
- (spine.asArray()?.length ?? 0) === CHUNK_ARITY) {
81
- chunkLevels += 1;
82
- const children = spine.asArray() ?? [];
83
- spine = children[children.length - 1];
84
- }
85
- for (let level = 0; level < chunkLevels; level += 1) {
86
- fields = fields.flatMap((chunk) => chunk.asArray() ?? []);
52
+ export function signetFieldNodeByPath(raw, path) {
53
+ if (path.length === 0) {
54
+ throw new Error("Ledger field path is empty");
87
55
  }
88
- const node = fields[flatIndex];
89
- if (node === undefined) {
90
- throw new Error(`Field index ${flatIndex} out of range`);
56
+ let node = unwrap(raw);
57
+ for (const [level, index] of path.entries()) {
58
+ if (node.type() !== "array") {
59
+ // A one-field contract stores its field as the bare (non-array) root,
60
+ // addressable only as the whole state at a final [0]; the compiled
61
+ // accessor reads it the same way.
62
+ if (index === 0 && level === path.length - 1)
63
+ return node;
64
+ throw new Error(`Ledger field path ${JSON.stringify(path)} steps into a non-array at level ${level}`);
65
+ }
66
+ const next = (node.asArray() ?? [])[index];
67
+ if (next === undefined) {
68
+ throw new Error(`Ledger field path ${JSON.stringify(path)} index ${index} out of range at level ${level}`);
69
+ }
70
+ node = next;
91
71
  }
92
72
  return node;
93
73
  }
@@ -1 +1 @@
1
- {"version":3,"file":"signature-state-reading.js","sourceRoot":"","sources":["../src/signature-state-reading.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,yEAAyE;AACzE,+EAA+E;AAC/E,+EAA+E;AAC/E,qEAAqE;AACrE,0EAA0E;AAC1E,uDAAuD;AAEvD,OAAO,EACL,gBAAgB,EAChB,0BAA0B,GAG3B,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAkB,MAAM,sBAAsB,CAAC;AAEtD,yCAAyC;AACzC,8EAA8E;AAC9E,+EAA+E;AAC/E,mCAAmC;AAEnC,qEAAqE;AACrE,MAAM,CAAC,MAAM,GAAG,GAAG,IAAI,0BAA0B,CAAC,qBAAqB,EAAE,CAAC,CAAC,CAAC;AAE5E,4CAA4C;AAC5C,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,gBAAgB,CAAC,EAAE,CAAC,CAAC;AAEhD;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAA2B,OAAO,CAAC;AAW7D;;;;;GAKG;AACH,MAAM,MAAM,GAAG,CAAC,GAAqB,EAAc,EAAE,CACnD,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;AAEnC;;;;GAIG;AACH,MAAM,WAAW,GAAG,EAAE,CAAC;AAEvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,eAAe,CAC7B,GAAqB,EACrB,SAAiB;IAEjB,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IACzB,IAAI,IA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