@sig-net/midnight 0.15.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.
- 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 +23 -5
- package/dist/signature-requests-state-reader.d.ts.map +1 -1
- package/dist/signature-requests-state-reader.js +50 -5
- package/dist/signature-requests-state-reader.js.map +1 -1
- 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 +262 -0
- package/dist/signet-contract-events.d.ts.map +1 -0
- package/dist/signet-contract-events.js +266 -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 +59 -34
- package/dist/signet-request-feed.d.ts.map +1 -1
- package/dist/signet-request-feed.js +95 -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 +43 -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,247 +0,0 @@
|
|
|
1
|
-
import { type CompactType } from "@midnight-ntwrk/compact-runtime";
|
|
2
|
-
import { type RequestId, type RequestIdHex } from "./signet-requests.ts";
|
|
3
|
-
import { type RawContractState } from "./signature-state-reading.ts";
|
|
4
|
-
/** Signet contract layout: the notification counter map is ledger field 0. */
|
|
5
|
-
export declare const SIGN_BIDIRECTIONAL_EVENT_NOTIFICATION_COUNTER_MAP_FIELD = 0;
|
|
6
|
-
/** Signet contract layout: the notification map is ledger field 1. */
|
|
7
|
-
export declare const SIGN_BIDIRECTIONAL_EVENT_NOTIFICATION_MAP_FIELD = 1;
|
|
8
|
-
/** Signet contract layout: the `respond` counter map is ledger field 2. */
|
|
9
|
-
export declare const RESPOND_COUNTER_MAP_FIELD = 2;
|
|
10
|
-
/** Signet contract layout: the `respond` post log is ledger field 3. */
|
|
11
|
-
export declare const RESPOND_MAP_FIELD = 3;
|
|
12
|
-
/** Signet contract layout: the respond-bidirectional counter map is ledger field 4. */
|
|
13
|
-
export declare const RESPOND_BIDIRECTIONAL_COUNTER_MAP_FIELD = 4;
|
|
14
|
-
/** Signet contract layout: the respond-bidirectional map is ledger field 5. */
|
|
15
|
-
export declare const RESPOND_BIDIRECTIONAL_MAP_FIELD = 5;
|
|
16
|
-
/**
|
|
17
|
-
* A curve point in affine coordinates (Compact `AffinePoint`), SEC1
|
|
18
|
-
* big-endian, the same shape the sig-net EVM and Solana signer contracts
|
|
19
|
-
* expose.
|
|
20
|
-
*/
|
|
21
|
-
export interface AffinePoint {
|
|
22
|
-
/** The x coordinate, 32 big-endian bytes. */
|
|
23
|
-
x: Uint8Array;
|
|
24
|
-
/** The y coordinate, 32 big-endian bytes. */
|
|
25
|
-
y: Uint8Array;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* The MPC's canonical ECDSA signature as both respond events store it
|
|
29
|
-
* (Compact `Signature`, matching the MPC's own
|
|
30
|
-
* `Signature { big_r, s, recovery_id }` and the EVM/Solana signer
|
|
31
|
-
* contracts): `bigR` the full nonce point so consumers never decompress,
|
|
32
|
-
* `s` big-endian, `recoveryId` the parity of R.y. Stored UNVERIFIED like
|
|
33
|
-
* everything else on the singleton. Convert with
|
|
34
|
-
* `ecdsaSignatureToMpcSignature` / `mpcSignatureToEcdsaSignature`.
|
|
35
|
-
*/
|
|
36
|
-
export interface MpcSignature {
|
|
37
|
-
/** The signature's nonce point R. */
|
|
38
|
-
bigR: AffinePoint;
|
|
39
|
-
/** Signature scalar s, 32 big-endian bytes. */
|
|
40
|
-
s: Uint8Array;
|
|
41
|
-
/** Recovery id (parity of R.y): 0 or 1. */
|
|
42
|
-
recoveryId: bigint;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* The MPC's signature over the requested EVM transaction (Compact
|
|
46
|
-
* `SignatureRespondedEvent`): decode to an ethers signature with
|
|
47
|
-
* `signatureRespondedEventToSignature`. The request id it answers lives in
|
|
48
|
-
* the map key.
|
|
49
|
-
*/
|
|
50
|
-
export interface SignatureRespondedEvent {
|
|
51
|
-
/** The requested signature over the transaction the request describes. */
|
|
52
|
-
signature: MpcSignature;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Hand-composed descriptor for {@link SignatureRespondedEvent}: the single
|
|
56
|
-
* {@link MpcSignature} field, matching the Compact struct.
|
|
57
|
-
*/
|
|
58
|
-
export declare const signatureRespondedEventType: CompactType<SignatureRespondedEvent>;
|
|
59
|
-
/**
|
|
60
|
-
* The MPC's respond-bidirectional attestation of a request's remote EVM
|
|
61
|
-
* execution (Compact `RespondBidirectionalEvent`): the ECDSA signature over
|
|
62
|
-
* the attestation digest `keccak256(requestId || serializedOutput)`. Both the
|
|
63
|
-
* digest and the output travel off chain: readers fetch the output, recompute
|
|
64
|
-
* the digest (`calculateSignetAttestationDigest`) and verify the signature
|
|
65
|
-
* over it. Stored UNVERIFIED by the signet contract, so that signature check
|
|
66
|
-
* against the expected MPC response key is the only thing separating a
|
|
67
|
-
* genuine post from garbage (in-circuit via
|
|
68
|
-
* `verifyRespondBidirectionalEvent`, off chain via
|
|
69
|
-
* {@link verifyRespondBidirectionalSignature}).
|
|
70
|
-
*/
|
|
71
|
-
export interface RespondBidirectionalEvent {
|
|
72
|
-
/** ECDSA signature over the attestation digest. */
|
|
73
|
-
signature: MpcSignature;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Composite key of one posted entry in the signet contract's maps (Compact
|
|
77
|
-
* `SignetMapKey`): the request id it belongs to plus the post's 0-based
|
|
78
|
-
* count. Field order (count first, then request id) mirrors the Compact
|
|
79
|
-
* struct.
|
|
80
|
-
*/
|
|
81
|
-
export interface SignetMapKey {
|
|
82
|
-
/** 0-based position of this post among the entries for {@link requestId}. */
|
|
83
|
-
count: bigint;
|
|
84
|
-
/** 32-byte id of the request this entry belongs to. */
|
|
85
|
-
requestId: RequestId;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Hand-composed descriptor for {@link SignetMapKey}, the map key of every
|
|
89
|
-
* posted-entry map in the signet contract. Field order (count, then
|
|
90
|
-
* requestId) must match the Compact struct.
|
|
91
|
-
*/
|
|
92
|
-
export declare const signetMapKeyType: CompactType<SignetMapKey>;
|
|
93
|
-
/**
|
|
94
|
-
* Hand-composed descriptor for {@link RespondBidirectionalEvent}: the single
|
|
95
|
-
* {@link MpcSignature} field, matching the Compact struct.
|
|
96
|
-
*/
|
|
97
|
-
export declare const respondBidirectionalEventType: CompactType<RespondBidirectionalEvent>;
|
|
98
|
-
/**
|
|
99
|
-
* Raw twin of the Compact `SignBidirectionalEventNotification` struct as
|
|
100
|
-
* stored on-ledger: the version tag plus the still-packed 128-byte payload.
|
|
101
|
-
* Decode the payload with {@link decodeSignBidirectionalNotification}.
|
|
102
|
-
*/
|
|
103
|
-
export interface SignBidirectionalNotificationRecord {
|
|
104
|
-
/** Payload layout tag (Compact `Uint<8>`): 1 = the V1 layout. */
|
|
105
|
-
version: bigint;
|
|
106
|
-
/** The packed payload bytes, exactly as the registering circuit built them. */
|
|
107
|
-
payload: Uint8Array;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Hand-composed descriptor for {@link SignBidirectionalNotificationRecord}.
|
|
111
|
-
* Field order (version, payload) must match the Compact struct.
|
|
112
|
-
*/
|
|
113
|
-
export declare const signBidirectionalNotificationType: CompactType<SignBidirectionalNotificationRecord>;
|
|
114
|
-
/**
|
|
115
|
-
* A decoded V1 notification from the signet contract's registry: the flat
|
|
116
|
-
* pointer a client registered to tell the MPC a request was stored, and
|
|
117
|
-
* WHERE to read the authenticated copy. The request id is NOT in the payload:
|
|
118
|
-
* it lives in the registry map key the record was stored under. Never trusted
|
|
119
|
-
* on its own: the resolver authenticates by reading the request back from
|
|
120
|
-
* {@link callerAddress}'s own ledger (see signet-request-resolver.ts).
|
|
121
|
-
*/
|
|
122
|
-
export interface SignBidirectionalNotification {
|
|
123
|
-
/** Payload layout tag: this decoder only produces version 1. */
|
|
124
|
-
version: number;
|
|
125
|
-
/**
|
|
126
|
-
* Address of the contract whose request map holds the request, rendered
|
|
127
|
-
* as lowercase hex, no `0x` prefix: directly usable as a
|
|
128
|
-
* `queryContractState` argument. The MPC reads the request from THIS
|
|
129
|
-
* contract's authenticated state. The field itself confers no authority.
|
|
130
|
-
*/
|
|
131
|
-
callerAddress: string;
|
|
132
|
-
/**
|
|
133
|
-
* Resolved ledger-tree path of the `SignBidirectionalEventMap` in
|
|
134
|
-
* {@link callerAddress}, as compactc records it in that contract's
|
|
135
|
-
* `contract-info.json` (`"index"`): `[4]` for a flat contract's field 4,
|
|
136
|
-
* `[1, 14]` once chunking applies. The reader follows it node for node
|
|
137
|
-
* (see {@link signetFieldNodeByPath}) and never assumes a layout.
|
|
138
|
-
*/
|
|
139
|
-
requestsPath: number[];
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Unpack a stored {@link SignBidirectionalNotificationRecord}'s payload by
|
|
143
|
-
* the fixed V1 offsets: the decode twin of the compiled
|
|
144
|
-
* `constructSignBidirectionalEventNotificationV1` circuit (byte plumbing
|
|
145
|
-
* only: the pack↔decode lockstep is pinned by the state-reader unit test that
|
|
146
|
-
* round-trips through the real circuit). V1 layout:
|
|
147
|
-
* callerAddress (32) ++ requestsPathDepth (1) ++ requestsPath (4) ++ zero
|
|
148
|
-
* padding (91), where only the first `requestsPathDepth` path bytes are
|
|
149
|
-
* meaningful.
|
|
150
|
-
*
|
|
151
|
-
* Fails closed on an unrecognised `version`: a future payload layout adds a
|
|
152
|
-
* branch here rather than silently misinterpreting bytes under the V1 offsets.
|
|
153
|
-
*
|
|
154
|
-
* @param record - The raw on-ledger record.
|
|
155
|
-
* @returns The decoded notification, its `requestsPath` trimmed to the
|
|
156
|
-
* declared depth.
|
|
157
|
-
* @throws Error if the record's `version` is not one this decoder understands,
|
|
158
|
-
* or its `requestsPathDepth` is zero or exceeds {@link MAX_LEDGER_PATH_DEPTH}.
|
|
159
|
-
*/
|
|
160
|
-
export declare function decodeSignBidirectionalNotification(record: SignBidirectionalNotificationRecord): SignBidirectionalNotification;
|
|
161
|
-
/**
|
|
162
|
-
* Plain-JS notification registry parsed out of the ledger: hex request id
|
|
163
|
-
* (from the `SignetMapKey` the notification was stored under) to the raw
|
|
164
|
-
* stored record. Re-notifies append under higher counts. This index keeps
|
|
165
|
-
* the FIRST post (count 0) per request id, the record the original submit
|
|
166
|
-
* registered. Decode each record with
|
|
167
|
-
* {@link decodeSignBidirectionalNotification}.
|
|
168
|
-
*/
|
|
169
|
-
export type SignBidirectionalNotificationIndex = Map<RequestIdHex, SignBidirectionalNotificationRecord>;
|
|
170
|
-
/**
|
|
171
|
-
* Plain-JS counter map parsed out of the ledger: hex request id (see
|
|
172
|
-
* {@link requestIdHex}) to the number of entries posted for that request.
|
|
173
|
-
* Entries in the corresponding map exist for counts `0 .. value - 1`.
|
|
174
|
-
*/
|
|
175
|
-
export type SignetCounterIndex = Map<RequestIdHex, bigint>;
|
|
176
|
-
/**
|
|
177
|
-
* Plain-JS signature response log parsed out of the ledger, keyed by
|
|
178
|
-
* {@link signetMapEntryKey} (`"<hexRequestId>:<count>"`) so the composite
|
|
179
|
-
* Compact key survives as a usable JS `Map` key.
|
|
180
|
-
*/
|
|
181
|
-
export type SignatureResponseIndex = Map<string, SignatureRespondedEvent>;
|
|
182
|
-
/**
|
|
183
|
-
* Plain-JS respond-bidirectional log parsed out of the ledger, keyed by
|
|
184
|
-
* {@link signetMapEntryKey} (`"<hexRequestId>:<count>"`).
|
|
185
|
-
*/
|
|
186
|
-
export type RespondBidirectionalIndex = Map<string, RespondBidirectionalEvent>;
|
|
187
|
-
/**
|
|
188
|
-
* Build the flattened JS map key for a `(requestId, count)` pair: the
|
|
189
|
-
* composite Compact {@link SignetMapKey} as a string so it works as a JS
|
|
190
|
-
* `Map` key.
|
|
191
|
-
*
|
|
192
|
-
* @param id - The request id the entry belongs to, in canonical hex form.
|
|
193
|
-
* @param count - 0-based post count within that request.
|
|
194
|
-
* @returns `"<hexRequestId>:<count>"`.
|
|
195
|
-
*/
|
|
196
|
-
export declare function signetMapEntryKey(id: RequestIdHex, count: bigint): string;
|
|
197
|
-
/**
|
|
198
|
-
* Read ONLY the notification registry (ledger field
|
|
199
|
-
* {@link SIGN_BIDIRECTIONAL_EVENT_NOTIFICATION_MAP_FIELD}) out of raw signet
|
|
200
|
-
* contract state: the poll-loop primitive of {@link SignetRequestFeed},
|
|
201
|
-
* which cycles frequently and has no use for the response fields. One record
|
|
202
|
-
* per request id (the count-0 post, see
|
|
203
|
-
* {@link SignBidirectionalNotificationIndex}).
|
|
204
|
-
*
|
|
205
|
-
* @param raw - Raw contract state, e.g. `queryContractState(address).data`
|
|
206
|
-
* from the indexer or `ctx.currentQueryContext.state` from the simulator.
|
|
207
|
-
* @returns The registry, keyed by the hex request id of each entry's map key.
|
|
208
|
-
* @throws Error if the field is missing or is not a Map.
|
|
209
|
-
*/
|
|
210
|
-
export declare function readSignBidirectionalNotificationIndexFromState(raw: RawContractState): SignBidirectionalNotificationIndex;
|
|
211
|
-
/**
|
|
212
|
-
* The decoded ledger fields of the signet contract: the three
|
|
213
|
-
* (counter map, entry map) pairs, namely notifications (fields 0/1), signature
|
|
214
|
-
* responses (fields 2/3), respond-bidirectional responses (fields 4/5).
|
|
215
|
-
* Together they give a poller everything the contract ever records about a
|
|
216
|
-
* request. All entries are UNAUTHENTICATED: verify before trusting.
|
|
217
|
-
*/
|
|
218
|
-
export interface SignetContractLedger {
|
|
219
|
-
/** Notification post counts per request id (ledger field 0). */
|
|
220
|
-
signBidirectionalEventNotificationCounterMap: SignetCounterIndex;
|
|
221
|
-
/**
|
|
222
|
-
* The notification registry (ledger field 1), one record per request id
|
|
223
|
-
* (count-0 post).
|
|
224
|
-
*/
|
|
225
|
-
signBidirectionalEventNotificationMap: SignBidirectionalNotificationIndex;
|
|
226
|
-
/** `respond` post counts per request id (ledger field 2). */
|
|
227
|
-
respondCounterMap: SignetCounterIndex;
|
|
228
|
-
/** The `respond` post log (ledger field 3), keyed by {@link signetMapEntryKey}. */
|
|
229
|
-
respondMap: SignatureResponseIndex;
|
|
230
|
-
/** Respond-bidirectional post counts per request id (ledger field 4). */
|
|
231
|
-
respondBidirectionalCounterMap: SignetCounterIndex;
|
|
232
|
-
/** The respond-bidirectional log (ledger field 5), keyed by {@link signetMapEntryKey}. */
|
|
233
|
-
respondBidirectionalMap: RespondBidirectionalIndex;
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* MPC-/client-style read: parse the signet contract's ledger fields out of
|
|
237
|
-
* raw contract state by field position alone, with no compiled contract and
|
|
238
|
-
* no generated `ledger()`, only the declaration-order layout and the
|
|
239
|
-
* canonical descriptors above.
|
|
240
|
-
*
|
|
241
|
-
* @param raw - Raw contract state, e.g. `queryContractState(address).data`
|
|
242
|
-
* from the indexer or `ctx.currentQueryContext.state` from the simulator.
|
|
243
|
-
* @returns The decoded {@link SignetContractLedger}.
|
|
244
|
-
* @throws Error if a field is missing or has the wrong state-value shape.
|
|
245
|
-
*/
|
|
246
|
-
export declare function readSignetContractLedgerFromState(raw: RawContractState): SignetContractLedger;
|
|
247
|
-
//# sourceMappingURL=signet-contract-state-reader.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signet-contract-state-reader.d.ts","sourceRoot":"","sources":["../src/signet-contract-state-reader.ts"],"names":[],"mappings":"AAiBA,OAAO,EAGL,KAAK,WAAW,EACjB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAGL,KAAK,SAAS,EACd,KAAK,YAAY,EAClB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAIL,KAAK,gBAAgB,EACtB,MAAM,8BAA8B,CAAC;AAEtC,8EAA8E;AAC9E,eAAO,MAAM,uDAAuD,IAAI,CAAC;AAEzE,sEAAsE;AACtE,eAAO,MAAM,+CAA+C,IAAI,CAAC;AAEjE,2EAA2E;AAC3E,eAAO,MAAM,yBAAyB,IAAI,CAAC;AAE3C,wEAAwE;AACxE,eAAO,MAAM,iBAAiB,IAAI,CAAC;AAEnC,uFAAuF;AACvF,eAAO,MAAM,uCAAuC,IAAI,CAAC;AAEzD,+EAA+E;AAC/E,eAAO,MAAM,+BAA+B,IAAI,CAAC;AAajD;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,6CAA6C;IAC7C,CAAC,EAAE,UAAU,CAAC;IACd,6CAA6C;IAC7C,CAAC,EAAE,UA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C,CACjD,MAAM,EAAE,mCAAmC,GAC1C,6BAA6B,CA8B/B;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,kCAAkC,GAAG,GAAG,CAClD,YAAY,EACZ,mCAAmC,CACpC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,GAAG,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;AAE3D;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG,GAAG,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;AAE1E;;;GAGG;AACH,MAAM,MAAM,yBAAyB,GAAG,GAAG,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAC;AAE/E;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEzE;AA4CD;;;;;;;;;;;;GAYG;AACH,wBAAgB,+CAA+C,CAC7D,GAAG,EAAE,gBAAgB,GACpB,kCAAkC,CAwBpC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC,gEAAgE;IAChE,4CAA4C,EAAE,kBAAkB,CAAC;IACjE;;;OAGG;IACH,qCAAqC,EAAE,kCAAkC,CAAC;IAC1E,6DAA6D;IAC7D,iBAAiB,EAAE,kBAAkB,CAAC;IACtC,mFAAmF;IACnF,UAAU,EAAE,sBAAsB,CAAC;IACnC,yEAAyE;IACzE,8BAA8B,EAAE,kBAAkB,CAAC;IACnD,0FAA0F;IAC1F,uBAAuB,EAAE,yBAAyB,CAAC;CACpD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iCAAiC,CAC/C,GAAG,EAAE,gBAAgB,GACpB,oBAAoB,CA2BtB"}
|
|
@@ -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,sB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