@sig-net/midnight 0.19.0 → 0.20.0-rc.1
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 +42 -2
- package/dist/abi-serde.d.ts +32 -30
- package/dist/abi-serde.d.ts.map +1 -1
- package/dist/abi-serde.js +139 -75
- package/dist/abi-serde.js.map +1 -1
- package/dist/byte-codecs.d.ts +62 -0
- package/dist/byte-codecs.d.ts.map +1 -0
- package/dist/byte-codecs.js +116 -0
- package/dist/byte-codecs.js.map +1 -0
- package/dist/compact-descriptors.d.ts +89 -0
- package/dist/compact-descriptors.d.ts.map +1 -0
- package/dist/compact-descriptors.js +139 -0
- package/dist/compact-descriptors.js.map +1 -0
- package/dist/constants.d.ts +18 -43
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +19 -45
- package/dist/constants.js.map +1 -1
- package/dist/ecdsa-attestation.d.ts +49 -97
- package/dist/ecdsa-attestation.d.ts.map +1 -1
- package/dist/ecdsa-attestation.js +78 -142
- package/dist/ecdsa-attestation.js.map +1 -1
- package/dist/epsilon-derivation.d.ts +24 -31
- package/dist/epsilon-derivation.d.ts.map +1 -1
- package/dist/epsilon-derivation.js +52 -62
- package/dist/epsilon-derivation.js.map +1 -1
- package/dist/index.d.ts +10 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -8
- package/dist/index.js.map +1 -1
- package/dist/managed/compiler/contract-info.json +0 -22
- package/dist/managed/compiler/contract-manifest.json +8 -8
- package/dist/managed/contract/index.d.ts +0 -3
- package/dist/managed/contract/index.js +65 -80
- package/dist/managed/contract/index.js.map +1 -1
- package/dist/raw-contract-state.d.ts +25 -0
- package/dist/raw-contract-state.d.ts.map +1 -0
- package/dist/raw-contract-state.js +52 -0
- package/dist/raw-contract-state.js.map +1 -0
- package/dist/signature-requests-state-reader.d.ts +18 -44
- package/dist/signature-requests-state-reader.d.ts.map +1 -1
- package/dist/signature-requests-state-reader.js +82 -146
- package/dist/signature-requests-state-reader.js.map +1 -1
- package/dist/signature-response-verification.d.ts +9 -8
- package/dist/signature-response-verification.d.ts.map +1 -1
- package/dist/signature-response-verification.js +20 -17
- package/dist/signature-response-verification.js.map +1 -1
- package/dist/signet-contract-events.d.ts +56 -64
- package/dist/signet-contract-events.d.ts.map +1 -1
- package/dist/signet-contract-events.js +46 -48
- package/dist/signet-contract-events.js.map +1 -1
- package/dist/signet-evtype2tx-record-decoding.d.ts +18 -0
- package/dist/signet-evtype2tx-record-decoding.d.ts.map +1 -0
- package/dist/signet-evtype2tx-record-decoding.js +97 -0
- package/dist/signet-evtype2tx-record-decoding.js.map +1 -0
- package/dist/signet-evtype2tx-requests.d.ts +43 -87
- package/dist/signet-evtype2tx-requests.d.ts.map +1 -1
- package/dist/signet-evtype2tx-requests.js +59 -130
- package/dist/signet-evtype2tx-requests.js.map +1 -1
- package/dist/signet-request-id.d.ts +14 -0
- package/dist/signet-request-id.d.ts.map +1 -0
- package/dist/signet-request-id.js +27 -0
- package/dist/signet-request-id.js.map +1 -0
- package/dist/signet-request-response-reader.d.ts +34 -56
- package/dist/signet-request-response-reader.d.ts.map +1 -1
- package/dist/signet-request-response-reader.js +56 -68
- package/dist/signet-request-response-reader.js.map +1 -1
- package/dist/signet-requests.d.ts +28 -92
- package/dist/signet-requests.d.ts.map +1 -1
- package/dist/signet-requests.js +39 -141
- package/dist/signet-requests.js.map +1 -1
- package/dist/testing.d.ts +3 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +20 -0
- package/dist/testing.js.map +1 -0
- package/package.json +12 -3
- package/src/Signet.compact +110 -171
- package/src/circuits.compact +9 -16
- package/dist/signature-state-reading.d.ts +0 -43
- package/dist/signature-state-reading.d.ts.map +0 -1
- package/dist/signature-state-reading.js +0 -74
- package/dist/signature-state-reading.js.map +0 -1
- package/dist/signet-request-feed.d.ts +0 -126
- package/dist/signet-request-feed.d.ts.map +0 -1
- package/dist/signet-request-feed.js +0 -216
- package/dist/signet-request-feed.js.map +0 -1
|
@@ -18,9 +18,8 @@ export declare const SIGNET_EVENT_NAME_LENGTH = 32;
|
|
|
18
18
|
export declare const SIGNET_EVENT_PAYLOAD_LENGTH = 256;
|
|
19
19
|
/**
|
|
20
20
|
* A signet contract event in decoded form: the NUL-trimmed name and the full
|
|
21
|
-
* re-padded {@link SIGNET_EVENT_PAYLOAD_LENGTH}-byte payload.
|
|
22
|
-
*
|
|
23
|
-
* before the per-event payload decoders run.
|
|
21
|
+
* re-padded {@link SIGNET_EVENT_PAYLOAD_LENGTH}-byte payload. The one shape
|
|
22
|
+
* every source normalises to before the per-event payload decoders run.
|
|
24
23
|
*/
|
|
25
24
|
export interface SignetMiscEvent {
|
|
26
25
|
/** The event name, NUL padding stripped (compare to {@link SignetEventName}). */
|
|
@@ -30,8 +29,8 @@ export interface SignetMiscEvent {
|
|
|
30
29
|
}
|
|
31
30
|
/**
|
|
32
31
|
* Source of the signet contract's emitted events, the event-side sibling of
|
|
33
|
-
*
|
|
34
|
-
*
|
|
32
|
+
* `SignetPublicStateSource`. Structural, so tests can stub it. Adapt a
|
|
33
|
+
* full midnight-js `PublicDataProvider` with
|
|
35
34
|
* {@link signetEventSourceFromPublicDataProvider}.
|
|
36
35
|
*/
|
|
37
36
|
export interface SignetEventSource {
|
|
@@ -44,6 +43,22 @@ export interface SignetEventSource {
|
|
|
44
43
|
*/
|
|
45
44
|
querySignetEvents(contractAddress: string): Promise<SignetMiscEvent[]>;
|
|
46
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Whether a decoded event carries `name`.
|
|
48
|
+
*
|
|
49
|
+
* A decoded event's `name` comes from arbitrary on-chain bytes, so it is a
|
|
50
|
+
* plain string and NOT the enum. Comparing the two directly is what
|
|
51
|
+
* `no-unsafe-enum-comparison` exists to catch, and it is right to: the
|
|
52
|
+
* widening belongs here, once, rather than at every call site.
|
|
53
|
+
*
|
|
54
|
+
* @param event - The decoded signet event.
|
|
55
|
+
* @param event.name - Its decoded, NUL-stripped event name.
|
|
56
|
+
* @param name - The event name to match.
|
|
57
|
+
* @returns Whether the event's decoded name equals `name`.
|
|
58
|
+
*/
|
|
59
|
+
export declare function isSignetEventNamed(event: {
|
|
60
|
+
name: string;
|
|
61
|
+
}, name: SignetEventName): boolean;
|
|
47
62
|
/**
|
|
48
63
|
* Strip the NUL padding off a fixed-width event name and decode it as ASCII:
|
|
49
64
|
* the inverse of the contract's `pad(32, "...")`.
|
|
@@ -53,30 +68,30 @@ export interface SignetEventSource {
|
|
|
53
68
|
*/
|
|
54
69
|
export declare function decodeSignetEventName(name: Uint8Array): string;
|
|
55
70
|
/**
|
|
56
|
-
* Decode the simulator's circuit-execution log into signet events
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* atom shape or width) throw: in the simulator the emitting contract is under
|
|
60
|
-
* test, so a malformed event is a bug, not noise to skip.
|
|
71
|
+
* Decode the simulator's circuit-execution log into signet events. For
|
|
72
|
+
* simulator tests. The indexer-path counterpart is
|
|
73
|
+
* {@link signetEventSourceFromPublicDataProvider}.
|
|
61
74
|
*
|
|
62
75
|
* @param events - The `context.events` of a `CircuitResults`.
|
|
63
76
|
* @param contractAddress - Optional filter: only events this contract emitted.
|
|
64
77
|
* @returns The decoded events, in emission order.
|
|
65
|
-
* @throws Error
|
|
78
|
+
* @throws {Error} When a `misc` event is not a single bytes atom of the signet
|
|
66
79
|
* name ++ payload width.
|
|
67
80
|
*/
|
|
68
81
|
export declare function decodeSignetLogEvents(events: readonly LogEvent[], contractAddress?: string): SignetMiscEvent[];
|
|
69
82
|
/**
|
|
70
83
|
* The least of a midnight-js `PublicDataProvider` the event source adapter
|
|
71
84
|
* needs: the `Misc` contract events of one address. Structural, so any full
|
|
72
|
-
* provider
|
|
85
|
+
* provider is assignable.
|
|
73
86
|
*/
|
|
74
87
|
export interface SignetContractEventQuerySource {
|
|
75
88
|
/**
|
|
76
|
-
* Retrieve a contract's events
|
|
89
|
+
* Retrieve a contract's events: see
|
|
77
90
|
* `PublicDataProvider.queryContractEvents`.
|
|
78
91
|
*
|
|
79
92
|
* @param filter - The contract address and event-type narrowing.
|
|
93
|
+
* @param filter.contractAddress - The contract whose events to read.
|
|
94
|
+
* @param filter.types - Event types to keep; omit for all of them.
|
|
80
95
|
* @returns The matching events, oldest first.
|
|
81
96
|
*/
|
|
82
97
|
queryContractEvents(filter: {
|
|
@@ -90,10 +105,8 @@ export interface SignetContractEventQuerySource {
|
|
|
90
105
|
}
|
|
91
106
|
/**
|
|
92
107
|
* Adapt a midnight-js `PublicDataProvider` (or anything exposing its
|
|
93
|
-
* `queryContractEvents`) into a {@link SignetEventSource}
|
|
94
|
-
*
|
|
95
|
-
* serves `name` and `payload` as hex-encoded byte strings; the name is
|
|
96
|
-
* NUL-trimmed and the payload re-padded to the full
|
|
108
|
+
* `queryContractEvents`) into a {@link SignetEventSource}. Each event's name
|
|
109
|
+
* is NUL-trimmed and its payload re-padded to the full
|
|
97
110
|
* {@link SIGNET_EVENT_PAYLOAD_LENGTH}.
|
|
98
111
|
*
|
|
99
112
|
* @param provider - The provider to query events through.
|
|
@@ -115,10 +128,9 @@ export interface AffinePoint {
|
|
|
115
128
|
* The MPC's canonical ECDSA signature as both respond events carry it
|
|
116
129
|
* (Compact `Signature`, matching the MPC's own
|
|
117
130
|
* `Signature { big_r, s, recovery_id }` and the EVM/Solana signer
|
|
118
|
-
* contracts)
|
|
119
|
-
* `
|
|
120
|
-
*
|
|
121
|
-
* `ecdsaSignatureToMpcSignature` / `mpcSignatureToEcdsaSignature`.
|
|
131
|
+
* contracts). Emitted UNVERIFIED. Decode to an ethers signature with
|
|
132
|
+
* `signatureRespondedEventToSignature`. Tests mint records with the
|
|
133
|
+
* `@sig-net/midnight/testing` entry point's `ecdsaSignatureToMpcSignature`.
|
|
122
134
|
*/
|
|
123
135
|
export interface MpcSignature {
|
|
124
136
|
/** The signature's nonce point R. */
|
|
@@ -130,12 +142,9 @@ export interface MpcSignature {
|
|
|
130
142
|
}
|
|
131
143
|
/**
|
|
132
144
|
* The MPC's signature over the requested EVM transaction (Compact
|
|
133
|
-
* `SignatureRespondedEvent`)
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* the id routes, and VERIFYING the signature against the transaction the
|
|
137
|
-
* request describes establishes authenticity (see
|
|
138
|
-
* {@link SignetRequestResponseReader.getVerifiedSignatureRespondedEvent}).
|
|
145
|
+
* `SignatureRespondedEvent`), carried beside the request id it answers (see
|
|
146
|
+
* {@link SignetEventPost}). Emitted UNVERIFIED: authenticity comes from
|
|
147
|
+
* `SignetRequestResponseReader.getVerifiedSignatureRespondedEvent`.
|
|
139
148
|
*/
|
|
140
149
|
export interface SignatureRespondedEvent {
|
|
141
150
|
/** The requested signature over the transaction the request describes. */
|
|
@@ -144,15 +153,10 @@ export interface SignatureRespondedEvent {
|
|
|
144
153
|
/**
|
|
145
154
|
* The MPC's respond-bidirectional attestation of a request's remote EVM
|
|
146
155
|
* execution (Compact `RespondBidirectionalEvent`): the ECDSA signature over
|
|
147
|
-
* the attestation digest `
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* it answers (see {@link SignetEventPost}), so that signature check
|
|
152
|
-
* against the expected MPC response key is the only thing separating a
|
|
153
|
-
* genuine post from garbage: in-circuit via
|
|
154
|
-
* `verifyRespondBidirectionalEvent`, off chain via
|
|
155
|
-
* {@link verifyRespondBidirectionalSignature}.
|
|
156
|
+
* the attestation digest (`calculateSignetAttestationDigest`), carried
|
|
157
|
+
* beside the request id it answers (see {@link SignetEventPost}). Emitted
|
|
158
|
+
* UNVERIFIED: verify in-circuit via `verifyRespondBidirectionalEvent` or off
|
|
159
|
+
* chain via `verifyRespondBidirectionalSignature`.
|
|
156
160
|
*/
|
|
157
161
|
export interface RespondBidirectionalEvent {
|
|
158
162
|
/** ECDSA signature over the attestation digest. */
|
|
@@ -161,13 +165,8 @@ export interface RespondBidirectionalEvent {
|
|
|
161
165
|
/**
|
|
162
166
|
* A decoded signet event payload: the request id the emitting circuit
|
|
163
167
|
* disclosed beside the posted record. The id is UNAUTHENTICATED routing
|
|
164
|
-
* data: it scopes reads to one request and proves nothing.
|
|
165
|
-
*
|
|
166
|
-
* authenticity check (see
|
|
167
|
-
* {@link SignetRequestResponseReader.getVerifiedSignatureRespondedEvent} and
|
|
168
|
-
* {@link SignetRequestResponseReader.getVerifiedRespondBidirectionalEvent});
|
|
169
|
-
* for the notification, reading the declared request back from the named
|
|
170
|
-
* caller's own ledger does (see signet-request-feed.ts).
|
|
168
|
+
* data: it scopes reads to one request and proves nothing. Each record
|
|
169
|
+
* type's own doc names its authenticity check.
|
|
171
170
|
*/
|
|
172
171
|
export interface SignetEventPost<TRecord> {
|
|
173
172
|
/** The request id the post declares it concerns, 32 bytes. Routing data only. */
|
|
@@ -181,7 +180,7 @@ export interface SignetEventPost<TRecord> {
|
|
|
181
180
|
*
|
|
182
181
|
* @param payload - The event's payload.
|
|
183
182
|
* @returns The decoded post: declared request id plus record.
|
|
184
|
-
* @throws Error
|
|
183
|
+
* @throws {Error} When the payload is too short to hold the packed leaves.
|
|
185
184
|
*/
|
|
186
185
|
export declare function decodeSignatureRespondedEventPayload(payload: Uint8Array): SignetEventPost<SignatureRespondedEvent>;
|
|
187
186
|
/**
|
|
@@ -190,7 +189,7 @@ export declare function decodeSignatureRespondedEventPayload(payload: Uint8Array
|
|
|
190
189
|
*
|
|
191
190
|
* @param payload - The event's payload.
|
|
192
191
|
* @returns The decoded post: declared request id plus record.
|
|
193
|
-
* @throws Error
|
|
192
|
+
* @throws {Error} When the payload is too short to hold the packed leaves.
|
|
194
193
|
*/
|
|
195
194
|
export declare function decodeRespondBidirectionalEventPayload(payload: Uint8Array): SignetEventPost<RespondBidirectionalEvent>;
|
|
196
195
|
/**
|
|
@@ -213,17 +212,14 @@ export interface SignBidirectionalNotificationRecord {
|
|
|
213
212
|
*
|
|
214
213
|
* @param payload - The event's payload.
|
|
215
214
|
* @returns The decoded post: declared request id plus raw notification record.
|
|
216
|
-
* @throws Error
|
|
215
|
+
* @throws {Error} When the payload is too short to hold the record.
|
|
217
216
|
*/
|
|
218
217
|
export declare function decodeSignBidirectionalEventNotificationPayload(payload: Uint8Array): SignetEventPost<SignBidirectionalNotificationRecord>;
|
|
219
218
|
/**
|
|
220
219
|
* A decoded V1 notification: the flat pointer a client emitted to tell the
|
|
221
|
-
* MPC a request was stored, and WHERE to read the authenticated copy
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
* notification points at and reads the request from the named caller's own
|
|
225
|
-
* authenticated ledger (see signet-request-feed.ts). The fields themselves
|
|
226
|
-
* confer no authority.
|
|
220
|
+
* MPC a request was stored, and WHERE to read the authenticated copy
|
|
221
|
+
* (resolve with `lookupSignetRequestAt`). The fields themselves confer no
|
|
222
|
+
* authority.
|
|
227
223
|
*/
|
|
228
224
|
export interface SignBidirectionalNotification {
|
|
229
225
|
/** Payload layout tag: this decoder only produces version 1. */
|
|
@@ -231,36 +227,32 @@ export interface SignBidirectionalNotification {
|
|
|
231
227
|
/**
|
|
232
228
|
* Address of the contract whose request map holds the request, rendered
|
|
233
229
|
* as lowercase hex, no `0x` prefix: directly usable as a
|
|
234
|
-
* `queryContractState` argument.
|
|
235
|
-
* contract's authenticated state. The field itself confers no authority.
|
|
230
|
+
* `queryContractState` argument.
|
|
236
231
|
*/
|
|
237
232
|
callerAddress: string;
|
|
238
233
|
/**
|
|
239
234
|
* Resolved ledger-tree path of the `SignBidirectionalEventMap` in
|
|
240
235
|
* {@link callerAddress}, as compactc records it in that contract's
|
|
241
236
|
* `contract-info.json` (`"index"`): `[4]` for a flat contract's field 4,
|
|
242
|
-
* `[1, 14]` once chunking applies.
|
|
243
|
-
*
|
|
237
|
+
* `[1, 14]` once chunking applies. Followed node for node by
|
|
238
|
+
* `signetFieldNodeByPath`.
|
|
244
239
|
*/
|
|
245
240
|
requestsPath: number[];
|
|
246
241
|
}
|
|
247
242
|
/**
|
|
248
243
|
* Unpack a {@link SignBidirectionalNotificationRecord}'s payload by the
|
|
249
244
|
* fixed V1 offsets: the decode twin of the compiled
|
|
250
|
-
* `constructSignBidirectionalEventNotificationV1` circuit (
|
|
251
|
-
*
|
|
252
|
-
*
|
|
245
|
+
* `constructSignBidirectionalEventNotificationV1` circuit (the pack↔decode
|
|
246
|
+
* lockstep is pinned by a unit test round-tripping through the real
|
|
247
|
+
* circuit). V1 layout:
|
|
253
248
|
* callerAddress (32) ++ requestsPathDepth (1) ++ requestsPath (4) ++ zero
|
|
254
249
|
* padding (91), where only the first `requestsPathDepth` path bytes are
|
|
255
|
-
* meaningful.
|
|
256
|
-
*
|
|
257
|
-
* Fails closed on an unrecognised `version`: a future payload layout adds a
|
|
258
|
-
* branch here rather than silently misinterpreting bytes under the V1 offsets.
|
|
250
|
+
* meaningful. Fails closed on an unrecognised `version`.
|
|
259
251
|
*
|
|
260
252
|
* @param record - The raw notification record.
|
|
261
253
|
* @returns The decoded notification, its `requestsPath` trimmed to the
|
|
262
254
|
* declared depth.
|
|
263
|
-
* @throws Error
|
|
255
|
+
* @throws {Error} If the record's `version` is not one this decoder understands,
|
|
264
256
|
* or its `requestsPathDepth` is zero or exceeds {@link MAX_LEDGER_PATH_DEPTH}.
|
|
265
257
|
*/
|
|
266
258
|
export declare function decodeSignBidirectionalNotification(record: SignBidirectionalNotificationRecord): SignBidirectionalNotification;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signet-contract-events.d.ts","sourceRoot":"","sources":["../src/signet-contract-events.ts"],"names":[],"mappings":"AAcA,OAAO,
|
|
1
|
+
{"version":3,"file":"signet-contract-events.d.ts","sourceRoot":"","sources":["../src/signet-contract-events.ts"],"names":[],"mappings":"AAcA,OAAO,EAAoB,KAAK,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAKlF;;;;GAIG;AACH,oBAAY,eAAe;IACzB,gEAAgE;IAChE,sBAAsB,2BAA2B;IACjD,iDAAiD;IACjD,uBAAuB,4BAA4B;IACnD,0EAA0E;IAC1E,yBAAyB,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AC;CACxB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mCAAmC,CACjD,MAAM,EAAE,mCAAmC,GAC1C,6BAA6B,CA2B/B"}
|
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
// Every event is UNAUTHENTICATED: verification is the reader's job. The
|
|
12
12
|
// request id every payload discloses is routing data only, so it scopes
|
|
13
13
|
// reads to one request and proves nothing.
|
|
14
|
-
import { CompactTypeBytes
|
|
15
|
-
import { bytesToHex, hexToBytes
|
|
14
|
+
import { CompactTypeBytes } from "@midnight-ntwrk/compact-runtime";
|
|
15
|
+
import { bytesToHex, hexToBytes } from "./byte-codecs.js";
|
|
16
|
+
import { decodeExactly } from "./compact-descriptors.js";
|
|
16
17
|
/**
|
|
17
18
|
* The event names the signet contract emits, exactly as the contract's
|
|
18
19
|
* `emit` literals spell them (the on-wire name is this string NUL-padded to
|
|
@@ -33,6 +34,22 @@ export const SIGNET_EVENT_NAME_LENGTH = 32;
|
|
|
33
34
|
export const SIGNET_EVENT_PAYLOAD_LENGTH = 256;
|
|
34
35
|
/** Descriptor re-padding a name ++ payload event atom to its full width. */
|
|
35
36
|
const eventBytes = new CompactTypeBytes(SIGNET_EVENT_NAME_LENGTH + SIGNET_EVENT_PAYLOAD_LENGTH);
|
|
37
|
+
/**
|
|
38
|
+
* Whether a decoded event carries `name`.
|
|
39
|
+
*
|
|
40
|
+
* A decoded event's `name` comes from arbitrary on-chain bytes, so it is a
|
|
41
|
+
* plain string and NOT the enum. Comparing the two directly is what
|
|
42
|
+
* `no-unsafe-enum-comparison` exists to catch, and it is right to: the
|
|
43
|
+
* widening belongs here, once, rather than at every call site.
|
|
44
|
+
*
|
|
45
|
+
* @param event - The decoded signet event.
|
|
46
|
+
* @param event.name - Its decoded, NUL-stripped event name.
|
|
47
|
+
* @param name - The event name to match.
|
|
48
|
+
* @returns Whether the event's decoded name equals `name`.
|
|
49
|
+
*/
|
|
50
|
+
export function isSignetEventNamed(event, name) {
|
|
51
|
+
return event.name === name;
|
|
52
|
+
}
|
|
36
53
|
/**
|
|
37
54
|
* Strip the NUL padding off a fixed-width event name and decode it as ASCII:
|
|
38
55
|
* the inverse of the contract's `pad(32, "...")`.
|
|
@@ -48,16 +65,14 @@ export function decodeSignetEventName(name) {
|
|
|
48
65
|
return new TextDecoder().decode(name.slice(0, end));
|
|
49
66
|
}
|
|
50
67
|
/**
|
|
51
|
-
* Decode the simulator's circuit-execution log into signet events
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* atom shape or width) throw: in the simulator the emitting contract is under
|
|
55
|
-
* test, so a malformed event is a bug, not noise to skip.
|
|
68
|
+
* Decode the simulator's circuit-execution log into signet events. For
|
|
69
|
+
* simulator tests. The indexer-path counterpart is
|
|
70
|
+
* {@link signetEventSourceFromPublicDataProvider}.
|
|
56
71
|
*
|
|
57
72
|
* @param events - The `context.events` of a `CircuitResults`.
|
|
58
73
|
* @param contractAddress - Optional filter: only events this contract emitted.
|
|
59
74
|
* @returns The decoded events, in emission order.
|
|
60
|
-
* @throws Error
|
|
75
|
+
* @throws {Error} When a `misc` event is not a single bytes atom of the signet
|
|
61
76
|
* name ++ payload width.
|
|
62
77
|
*/
|
|
63
78
|
export function decodeSignetLogEvents(events, contractAddress) {
|
|
@@ -71,9 +86,8 @@ export function decodeSignetLogEvents(events, contractAddress) {
|
|
|
71
86
|
if (event.data.tag !== "cell") {
|
|
72
87
|
throw new Error(`misc event data is a '${event.data.tag}', expected a cell`);
|
|
73
88
|
}
|
|
74
|
-
// fromValue
|
|
75
|
-
|
|
76
|
-
const bytes = eventBytes.fromValue([...event.data.content.value]);
|
|
89
|
+
// fromValue re-pads the trailing zeros the state layer trims.
|
|
90
|
+
const bytes = decodeExactly(eventBytes, event.data.content.value, "misc event data");
|
|
77
91
|
out.push({
|
|
78
92
|
name: decodeSignetEventName(bytes.slice(0, SIGNET_EVENT_NAME_LENGTH)),
|
|
79
93
|
payload: bytes.slice(SIGNET_EVENT_NAME_LENGTH),
|
|
@@ -81,22 +95,10 @@ export function decodeSignetLogEvents(events, contractAddress) {
|
|
|
81
95
|
}
|
|
82
96
|
return out;
|
|
83
97
|
}
|
|
84
|
-
/**
|
|
85
|
-
* Normalize one indexer-served hex field that may or may not carry a `0x`
|
|
86
|
-
* prefix into bytes.
|
|
87
|
-
*
|
|
88
|
-
* @param hex - The hex string.
|
|
89
|
-
* @returns The decoded bytes.
|
|
90
|
-
*/
|
|
91
|
-
function eventFieldBytes(hex) {
|
|
92
|
-
return hexToBytes(hex.startsWith("0x") ? hex.slice(2) : hex);
|
|
93
|
-
}
|
|
94
98
|
/**
|
|
95
99
|
* Adapt a midnight-js `PublicDataProvider` (or anything exposing its
|
|
96
|
-
* `queryContractEvents`) into a {@link SignetEventSource}
|
|
97
|
-
*
|
|
98
|
-
* serves `name` and `payload` as hex-encoded byte strings; the name is
|
|
99
|
-
* NUL-trimmed and the payload re-padded to the full
|
|
100
|
+
* `queryContractEvents`) into a {@link SignetEventSource}. Each event's name
|
|
101
|
+
* is NUL-trimmed and its payload re-padded to the full
|
|
100
102
|
* {@link SIGNET_EVENT_PAYLOAD_LENGTH}.
|
|
101
103
|
*
|
|
102
104
|
* @param provider - The provider to query events through.
|
|
@@ -115,11 +117,11 @@ export function signetEventSourceFromPublicDataProvider(provider) {
|
|
|
115
117
|
continue;
|
|
116
118
|
if (event.name === undefined || event.payload === undefined)
|
|
117
119
|
continue;
|
|
118
|
-
const payload =
|
|
120
|
+
const payload = hexToBytes(event.payload);
|
|
119
121
|
const padded = new Uint8Array(SIGNET_EVENT_PAYLOAD_LENGTH);
|
|
120
122
|
padded.set(payload.slice(0, SIGNET_EVENT_PAYLOAD_LENGTH), 0);
|
|
121
123
|
out.push({
|
|
122
|
-
name: decodeSignetEventName(
|
|
124
|
+
name: decodeSignetEventName(hexToBytes(event.name)),
|
|
123
125
|
payload: padded,
|
|
124
126
|
});
|
|
125
127
|
}
|
|
@@ -136,17 +138,16 @@ const SIGNATURE_RECOVERY_ID_OFFSET = 128;
|
|
|
136
138
|
/**
|
|
137
139
|
* Unpack the leaves both respond payloads lead with:
|
|
138
140
|
* requestId (32) ++ bigR.x (32) ++ bigR.y (32) ++ s (32) ++ recoveryId (1).
|
|
139
|
-
* Bytes beyond the recovery id are padding
|
|
140
|
-
* future payload extension does not break existing readers.
|
|
141
|
+
* Bytes beyond the recovery id are padding and are ignored.
|
|
141
142
|
*
|
|
142
143
|
* @param payload - The full event payload.
|
|
143
144
|
* @returns The declared request id and the decoded signature.
|
|
144
|
-
* @throws Error
|
|
145
|
+
* @throws {Error} When the payload is too short to hold the packed leaves.
|
|
145
146
|
*/
|
|
146
147
|
function decodeRespondPayload(payload) {
|
|
147
148
|
const recoveryId = payload[SIGNATURE_RECOVERY_ID_OFFSET];
|
|
148
149
|
if (recoveryId === undefined) {
|
|
149
|
-
throw new Error(`signet event payload of ${payload.length} bytes is too short for a packed respond record`);
|
|
150
|
+
throw new Error(`signet event payload of ${String(payload.length)} bytes is too short for a packed respond record`);
|
|
150
151
|
}
|
|
151
152
|
return {
|
|
152
153
|
requestId: payload.slice(RESPOND_REQUEST_ID_OFFSET, SIGNATURE_BIG_R_X_OFFSET),
|
|
@@ -166,7 +167,7 @@ function decodeRespondPayload(payload) {
|
|
|
166
167
|
*
|
|
167
168
|
* @param payload - The event's payload.
|
|
168
169
|
* @returns The decoded post: declared request id plus record.
|
|
169
|
-
* @throws Error
|
|
170
|
+
* @throws {Error} When the payload is too short to hold the packed leaves.
|
|
170
171
|
*/
|
|
171
172
|
export function decodeSignatureRespondedEventPayload(payload) {
|
|
172
173
|
const { requestId, signature } = decodeRespondPayload(payload);
|
|
@@ -178,7 +179,7 @@ export function decodeSignatureRespondedEventPayload(payload) {
|
|
|
178
179
|
*
|
|
179
180
|
* @param payload - The event's payload.
|
|
180
181
|
* @returns The decoded post: declared request id plus record.
|
|
181
|
-
* @throws Error
|
|
182
|
+
* @throws {Error} When the payload is too short to hold the packed leaves.
|
|
182
183
|
*/
|
|
183
184
|
export function decodeRespondBidirectionalEventPayload(payload) {
|
|
184
185
|
const { requestId, signature } = decodeRespondPayload(payload);
|
|
@@ -200,13 +201,13 @@ const NOTIFICATION_PAYLOAD_LENGTH = 128;
|
|
|
200
201
|
*
|
|
201
202
|
* @param payload - The event's payload.
|
|
202
203
|
* @returns The decoded post: declared request id plus raw notification record.
|
|
203
|
-
* @throws Error
|
|
204
|
+
* @throws {Error} When the payload is too short to hold the record.
|
|
204
205
|
*/
|
|
205
206
|
export function decodeSignBidirectionalEventNotificationPayload(payload) {
|
|
206
207
|
const version = payload[NOTIFICATION_EVENT_VERSION_OFFSET];
|
|
207
208
|
const end = NOTIFICATION_EVENT_PAYLOAD_OFFSET + NOTIFICATION_PAYLOAD_LENGTH;
|
|
208
209
|
if (version === undefined || payload.length < end) {
|
|
209
|
-
throw new Error(`signet event payload of ${payload.length} bytes is too short for a packed notification`);
|
|
210
|
+
throw new Error(`signet event payload of ${String(payload.length)} bytes is too short for a packed notification`);
|
|
210
211
|
}
|
|
211
212
|
return {
|
|
212
213
|
requestId: payload.slice(NOTIFICATION_EVENT_REQUEST_ID_OFFSET, NOTIFICATION_EVENT_PAYLOAD_OFFSET),
|
|
@@ -225,7 +226,7 @@ const NOTIFICATION_PATH_OFFSET = 33;
|
|
|
225
226
|
/**
|
|
226
227
|
* Maximum ledger-tree path depth the V1 payload carries, matching the
|
|
227
228
|
* `Vector<4, Uint<8>>` the `constructSignBidirectionalEventNotificationV1`
|
|
228
|
-
* circuit packs.
|
|
229
|
+
* circuit packs.
|
|
229
230
|
*/
|
|
230
231
|
const MAX_LEDGER_PATH_DEPTH = 4;
|
|
231
232
|
/** The only payload interpretation {@link decodeSignBidirectionalNotification} understands today. */
|
|
@@ -233,32 +234,29 @@ const SUPPORTED_NOTIFICATION_VERSION = 1n;
|
|
|
233
234
|
/**
|
|
234
235
|
* Unpack a {@link SignBidirectionalNotificationRecord}'s payload by the
|
|
235
236
|
* fixed V1 offsets: the decode twin of the compiled
|
|
236
|
-
* `constructSignBidirectionalEventNotificationV1` circuit (
|
|
237
|
-
*
|
|
238
|
-
*
|
|
237
|
+
* `constructSignBidirectionalEventNotificationV1` circuit (the pack↔decode
|
|
238
|
+
* lockstep is pinned by a unit test round-tripping through the real
|
|
239
|
+
* circuit). V1 layout:
|
|
239
240
|
* callerAddress (32) ++ requestsPathDepth (1) ++ requestsPath (4) ++ zero
|
|
240
241
|
* padding (91), where only the first `requestsPathDepth` path bytes are
|
|
241
|
-
* meaningful.
|
|
242
|
-
*
|
|
243
|
-
* Fails closed on an unrecognised `version`: a future payload layout adds a
|
|
244
|
-
* branch here rather than silently misinterpreting bytes under the V1 offsets.
|
|
242
|
+
* meaningful. Fails closed on an unrecognised `version`.
|
|
245
243
|
*
|
|
246
244
|
* @param record - The raw notification record.
|
|
247
245
|
* @returns The decoded notification, its `requestsPath` trimmed to the
|
|
248
246
|
* declared depth.
|
|
249
|
-
* @throws Error
|
|
247
|
+
* @throws {Error} If the record's `version` is not one this decoder understands,
|
|
250
248
|
* or its `requestsPathDepth` is zero or exceeds {@link MAX_LEDGER_PATH_DEPTH}.
|
|
251
249
|
*/
|
|
252
250
|
export function decodeSignBidirectionalNotification(record) {
|
|
253
251
|
if (record.version !== SUPPORTED_NOTIFICATION_VERSION) {
|
|
254
|
-
throw new Error(`SignBidirectionalEventNotification version ${record.version} is not supported ` +
|
|
255
|
-
`(this decoder understands version ${SUPPORTED_NOTIFICATION_VERSION})`);
|
|
252
|
+
throw new Error(`SignBidirectionalEventNotification version ${String(record.version)} is not supported ` +
|
|
253
|
+
`(this decoder understands version ${String(SUPPORTED_NOTIFICATION_VERSION)})`);
|
|
256
254
|
}
|
|
257
255
|
const callerAddress = bytesToHex(record.payload.slice(NOTIFICATION_CALLER_ADDRESS_OFFSET, NOTIFICATION_PATH_DEPTH_OFFSET));
|
|
258
256
|
const depth = record.payload[NOTIFICATION_PATH_DEPTH_OFFSET];
|
|
259
257
|
if (depth === undefined || depth < 1 || depth > MAX_LEDGER_PATH_DEPTH) {
|
|
260
|
-
throw new Error(`SignBidirectionalEventNotification requestsPathDepth ${depth} is out of range ` +
|
|
261
|
-
`(expected 1 to ${MAX_LEDGER_PATH_DEPTH})`);
|
|
258
|
+
throw new Error(`SignBidirectionalEventNotification requestsPathDepth ${String(depth)} is out of range ` +
|
|
259
|
+
`(expected 1 to ${String(MAX_LEDGER_PATH_DEPTH)})`);
|
|
262
260
|
}
|
|
263
261
|
// payload is a re-padded Bytes<128> and depth is bounded to MAX_LEDGER_PATH_DEPTH
|
|
264
262
|
// above, so this slice always yields exactly `depth` bytes.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signet-contract-events.js","sourceRoot":"","sources":["../src/signet-contract-events.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,wEAAwE;AACxE,4EAA4E;AAC5E,2CAA2C;AAC3C,0GAA0G;AAC1G,wHAAwH;AACxH,wHAAwH;AACxH,wEAAwE;AACxE,4EAA4E;AAC5E,6EAA6E;AAC7E,wEAAwE;AACxE,wEAAwE;AACxE,2CAA2C;AAE3C,OAAO,
|
|
1
|
+
{"version":3,"file":"signet-contract-events.js","sourceRoot":"","sources":["../src/signet-contract-events.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,wEAAwE;AACxE,4EAA4E;AAC5E,2CAA2C;AAC3C,0GAA0G;AAC1G,wHAAwH;AACxH,wHAAwH;AACxH,wEAAwE;AACxE,4EAA4E;AAC5E,6EAA6E;AAC7E,wEAAwE;AACxE,wEAAwE;AACxE,2CAA2C;AAE3C,OAAO,EAAE,gBAAgB,EAAiB,MAAM,iCAAiC,CAAC;AAElF,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD;;;;GAIG;AACH,MAAM,CAAN,IAAY,eAOX;AAPD,WAAY,eAAe;IACzB,gEAAgE;IAChE,oEAAiD,CAAA;IACjD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;;;GAIG;AACH,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAEhC,qGAAqG;AACrG,MAAM,8BAA8B,GAAG,EAAE,CAAC;AA2B1C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,mCAAmC,CACjD,MAA2C;IAE3C,IAAI,MAAM,CAAC,OAAO,KAAK,8BAA8B,EAAE,CAAC;QACtD,MAAM,IAAI,KAAK,CACb,8CAA8C,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,oBAAoB;YACtF,qCAAqC,MAAM,CAAC,8BAA8B,CAAC,GAAG,CACjF,CAAC;IACJ,CAAC;IACD,MAAM,aAAa,GAAG,UAAU,CAC9B,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,8BAA8B,CAAC,CACzF,CAAC;IACF,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,8BAA8B,CAAC,CAAC;IAC7D,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,qBAAqB,EAAE,CAAC;QACtE,MAAM,IAAI,KAAK,CACb,wDAAwD,MAAM,CAAC,KAAK,CAAC,mBAAmB;YACtF,kBAAkB,MAAM,CAAC,qBAAqB,CAAC,GAAG,CACrD,CAAC;IACJ,CAAC;IACD,kFAAkF;IAClF,4DAA4D;IAC5D,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAC7B,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,wBAAwB,GAAG,KAAK,CAAC,CACjF,CAAC;IACF,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;QAC/B,aAAa;QACb,YAAY;KACb,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AlignedValue } from "@midnight-ntwrk/compact-runtime";
|
|
2
|
+
import type { SignBidirectionalEvent } from "./signet-requests.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Decode a stored evmType2 request record in one pass, refusing a cell whose
|
|
5
|
+
* declared widths are not a signet record's. Measures the capacity
|
|
6
|
+
* instantiation from the declared alignment widths (the schema widths from
|
|
7
|
+
* the last two atoms' DECLARED lengths), instantiates the descriptor once
|
|
8
|
+
* and decodes once. Does NOT verify the record against the id it is filed
|
|
9
|
+
* under, and does NOT check the `txParamType` tag: the dispatching caller
|
|
10
|
+
* does.
|
|
11
|
+
*
|
|
12
|
+
* @param cell - The record cell as stored (value atoms plus alignment).
|
|
13
|
+
* @param what - Error-message subject.
|
|
14
|
+
* @returns The decoded record.
|
|
15
|
+
* @throws {Error} If the cell is not a decodable evmType2 request record.
|
|
16
|
+
*/
|
|
17
|
+
export declare function decodeEvmType2SignBidirectionalEvent(cell: AlignedValue, what: string): SignBidirectionalEvent;
|
|
18
|
+
//# sourceMappingURL=signet-evtype2tx-record-decoding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signet-evtype2tx-record-decoding.d.ts","sourceRoot":"","sources":["../src/signet-evtype2tx-record-decoding.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAIpE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAqFnE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oCAAoC,CAClD,IAAI,EAAE,YAAY,EAClB,IAAI,EAAE,MAAM,GACX,sBAAsB,CAsBxB"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Raw-cell decoding of a stored evmType2 request record: measure the
|
|
2
|
+
// capacity instantiation the requester contract was compiled with from the
|
|
3
|
+
// cell's declared alignment widths, instantiate the record descriptor once
|
|
4
|
+
// and decode once. The TS twin of the capacity measurement in the MPC's Rust
|
|
5
|
+
// reader (chain-signatures/chain-midnight/src/reader.rs) and MUST stay in
|
|
6
|
+
// lockstep with it. The chain-agnostic reading and the per-decomposition
|
|
7
|
+
// dispatch live in signature-requests-state-reader.ts.
|
|
8
|
+
import { declaredWidths, decodeExactly } from "./compact-descriptors.js";
|
|
9
|
+
import { signBidirectionalEventDescriptor } from "./signet-evtype2tx-requests.js";
|
|
10
|
+
// Atom layout of an evmType2 request record: the fixed atom count, the
|
|
11
|
+
// fixed head before the calldata words, and the fixed tail (caip2Id + the
|
|
12
|
+
// two schemas). A stored cell holds
|
|
13
|
+
// EVM_TYPE2_FIXED_ATOMS + maxCalldataWords
|
|
14
|
+
// + maxAccessListEntries * (2 + maxStorageKeysPerEntry) atoms.
|
|
15
|
+
const EVM_TYPE2_FIXED_ATOMS = 22;
|
|
16
|
+
const EVM_TYPE2_HEAD_ATOMS = 18;
|
|
17
|
+
const EVM_TYPE2_TAIL_ATOMS = 3;
|
|
18
|
+
/**
|
|
19
|
+
* Recover the sizing parameters the requester's contract was compiled with
|
|
20
|
+
* (`#maxCalldataWords`, `#maxAccessListEntries`, `#maxStorageKeysPerEntry`)
|
|
21
|
+
* from the declared widths alone. The tail anchors from the end: calldata
|
|
22
|
+
* words, storage keys and `caip2Id` are all `Bytes<32>`, so no forward scan
|
|
23
|
+
* can find the boundaries.
|
|
24
|
+
*
|
|
25
|
+
* @param widths - The record's declared atom widths.
|
|
26
|
+
* @param what - Error-message subject.
|
|
27
|
+
* @returns The capacity instantiation.
|
|
28
|
+
* @throws {Error} If the widths are not an evmType2 record's.
|
|
29
|
+
*/
|
|
30
|
+
function evmType2Capacities(widths, what) {
|
|
31
|
+
if (widths.length < EVM_TYPE2_FIXED_ATOMS) {
|
|
32
|
+
throw new Error(`${what} has ${String(widths.length)} value atoms, fewer than the ` +
|
|
33
|
+
`${String(EVM_TYPE2_FIXED_ATOMS)} its fixed fields need`);
|
|
34
|
+
}
|
|
35
|
+
const tail = widths.length - EVM_TYPE2_TAIL_ATOMS;
|
|
36
|
+
let index = EVM_TYPE2_HEAD_ATOMS;
|
|
37
|
+
while (index < tail && widths[index] === 32) {
|
|
38
|
+
index += 1;
|
|
39
|
+
}
|
|
40
|
+
const maxCalldataWords = index - EVM_TYPE2_HEAD_ATOMS;
|
|
41
|
+
const boundary = index < tail ? widths[index] : undefined;
|
|
42
|
+
if (boundary !== 1) {
|
|
43
|
+
const found = boundary === undefined ? "the record's tail" : `Bytes<${String(boundary)}>`;
|
|
44
|
+
throw new Error(`expected the Bytes<1> access-list entry count after ${String(maxCalldataWords)} ` +
|
|
45
|
+
`calldata words, found ${found}`);
|
|
46
|
+
}
|
|
47
|
+
index += 1;
|
|
48
|
+
const region = widths.slice(index, tail);
|
|
49
|
+
const maxAccessListEntries = region.filter((width) => width === 20).length;
|
|
50
|
+
let maxStorageKeysPerEntry;
|
|
51
|
+
if (maxAccessListEntries === 0) {
|
|
52
|
+
if (region.length !== 0) {
|
|
53
|
+
throw new Error(`the access-list region holds ${String(region.length)} atoms but declares no ` +
|
|
54
|
+
`Bytes<20> entry address`);
|
|
55
|
+
}
|
|
56
|
+
maxStorageKeysPerEntry = 0;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
if (region.length % maxAccessListEntries !== 0) {
|
|
60
|
+
throw new Error(`the access-list region's ${String(region.length)} atoms do not divide evenly ` +
|
|
61
|
+
`across ${String(maxAccessListEntries)} entries`);
|
|
62
|
+
}
|
|
63
|
+
const perEntry = region.length / maxAccessListEntries;
|
|
64
|
+
if (perEntry < 2) {
|
|
65
|
+
throw new Error(`each access-list entry needs at least an address and a key count, ` +
|
|
66
|
+
`got ${String(perEntry)} atoms`);
|
|
67
|
+
}
|
|
68
|
+
maxStorageKeysPerEntry = perEntry - 2;
|
|
69
|
+
}
|
|
70
|
+
return { maxCalldataWords, maxAccessListEntries, maxStorageKeysPerEntry };
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Decode a stored evmType2 request record in one pass, refusing a cell whose
|
|
74
|
+
* declared widths are not a signet record's. Measures the capacity
|
|
75
|
+
* instantiation from the declared alignment widths (the schema widths from
|
|
76
|
+
* the last two atoms' DECLARED lengths), instantiates the descriptor once
|
|
77
|
+
* and decodes once. Does NOT verify the record against the id it is filed
|
|
78
|
+
* under, and does NOT check the `txParamType` tag: the dispatching caller
|
|
79
|
+
* does.
|
|
80
|
+
*
|
|
81
|
+
* @param cell - The record cell as stored (value atoms plus alignment).
|
|
82
|
+
* @param what - Error-message subject.
|
|
83
|
+
* @returns The decoded record.
|
|
84
|
+
* @throws {Error} If the cell is not a decodable evmType2 request record.
|
|
85
|
+
*/
|
|
86
|
+
export function decodeEvmType2SignBidirectionalEvent(cell, what) {
|
|
87
|
+
const widths = declaredWidths(cell, what);
|
|
88
|
+
const capacities = evmType2Capacities(widths, what);
|
|
89
|
+
const lenOutputDeserialization = widths.at(-2);
|
|
90
|
+
const lenRespondSerialization = widths.at(-1);
|
|
91
|
+
if (lenOutputDeserialization === undefined || lenRespondSerialization === undefined) {
|
|
92
|
+
throw new Error(`${what} has ${String(widths.length)} value atoms: too few to hold the ` +
|
|
93
|
+
`trailing output-deserialization and respond-serialization schemas`);
|
|
94
|
+
}
|
|
95
|
+
return decodeExactly(signBidirectionalEventDescriptor(capacities.maxCalldataWords, capacities.maxAccessListEntries, capacities.maxStorageKeysPerEntry, lenOutputDeserialization, lenRespondSerialization), cell.value, what);
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=signet-evtype2tx-record-decoding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signet-evtype2tx-record-decoding.js","sourceRoot":"","sources":["../src/signet-evtype2tx-record-decoding.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,2EAA2E;AAC3E,2EAA2E;AAC3E,6EAA6E;AAC7E,0EAA0E;AAC1E,yEAAyE;AACzE,uDAAuD;AAIvD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,gCAAgC,EAAE,MAAM,gCAAgC,CAAC;AAGlF,uEAAuE;AACvE,0EAA0E;AAC1E,oCAAoC;AACpC,2CAA2C;AA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