@sig-net/midnight 0.19.0 → 0.21.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 +66 -96
- package/dist/ecdsa-attestation.d.ts.map +1 -1
- package/dist/ecdsa-attestation.js +115 -140
- 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 +102 -225
- 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 +67 -66
- package/dist/signet-contract-events.d.ts.map +1 -1
- package/dist/signet-contract-events.js +57 -52
- 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 +149 -198
- 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
|
@@ -1,32 +1,36 @@
|
|
|
1
1
|
// Client-side verification of MPC signature responses. The signet contract
|
|
2
2
|
// emits signature responses UNAUTHENTICATED (see the module header in
|
|
3
|
-
// Signet.compact), so a poller must verify every posted response
|
|
4
|
-
//
|
|
5
|
-
// request record, assembled exactly as the MPC assembles it (sig-net/mpc
|
|
6
|
-
// response server, managed/erc20-vault/signet/calldata-builder.ts), and
|
|
7
|
-
// check that the posted signature record recovers to the requester's derived
|
|
8
|
-
// EVM address over that transaction's signing hash.
|
|
3
|
+
// Signet.compact), so a poller must verify every posted response before
|
|
4
|
+
// trusting it.
|
|
9
5
|
import { getAddress, recoverAddress } from "ethers";
|
|
10
|
-
import {
|
|
6
|
+
import { signatureRespondedEventToSignature } from "./ecdsa-attestation.js";
|
|
7
|
+
import { signBidirectionalEventToUnsignedEvmTransaction } from "./signet-evtype2tx-requests.js";
|
|
8
|
+
import { TxParamType } from "./signet-requests.js";
|
|
11
9
|
/**
|
|
12
|
-
* Recover the
|
|
13
|
-
*
|
|
10
|
+
* Recover the address that produced a response signature, over the signing
|
|
11
|
+
* digest of the transaction the request describes: the response-side
|
|
12
|
+
* dispatch on the request's `txParamType`.
|
|
14
13
|
*
|
|
15
14
|
* @param request - The on-ledger request record the response answers.
|
|
16
15
|
* @param response - The posted signature record answering it.
|
|
17
16
|
* @returns The checksummed recovered signer address.
|
|
18
|
-
* @throws Error
|
|
19
|
-
*
|
|
17
|
+
* @throws {Error} If the request's `txParamType` names a decomposition this
|
|
18
|
+
* library does not sign-verify, the response is not a decodable signature,
|
|
19
|
+
* or the request record is malformed (see
|
|
20
20
|
* {@link signBidirectionalEventToUnsignedEvmTransaction}).
|
|
21
21
|
*/
|
|
22
22
|
export function recoverSignatureResponseSigner(request, response) {
|
|
23
|
-
|
|
23
|
+
switch (request.txParamType) {
|
|
24
|
+
case TxParamType.evmType2:
|
|
25
|
+
return recoverAddress(signBidirectionalEventToUnsignedEvmTransaction(request).unsignedHash, signatureRespondedEventToSignature(response));
|
|
26
|
+
default:
|
|
27
|
+
throw new Error(`unsupported txParamType ${String(request.txParamType)}`);
|
|
28
|
+
}
|
|
24
29
|
}
|
|
25
30
|
/**
|
|
26
31
|
* Verify a posted response against its request: does the signature recover
|
|
27
|
-
* to `expectedSigner`? Never throws: a
|
|
28
|
-
*
|
|
29
|
-
* on an unauthenticated log.
|
|
32
|
+
* to `expectedSigner`? Never throws: a malformed or wrongly-signed response
|
|
33
|
+
* is simply not valid.
|
|
30
34
|
*
|
|
31
35
|
* @param request - The on-ledger request record the response answers.
|
|
32
36
|
* @param response - The posted signature record answering it.
|
|
@@ -35,8 +39,7 @@ export function recoverSignatureResponseSigner(request, response) {
|
|
|
35
39
|
*/
|
|
36
40
|
export function verifySignatureRespondedEvent(request, response, expectedSigner) {
|
|
37
41
|
try {
|
|
38
|
-
return
|
|
39
|
-
getAddress(expectedSigner));
|
|
42
|
+
return recoverSignatureResponseSigner(request, response) === getAddress(expectedSigner);
|
|
40
43
|
}
|
|
41
44
|
catch {
|
|
42
45
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signature-response-verification.js","sourceRoot":"","sources":["../src/signature-response-verification.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,sEAAsE;AACtE,
|
|
1
|
+
{"version":3,"file":"signature-response-verification.js","sourceRoot":"","sources":["../src/signature-response-verification.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,sEAAsE;AACtE,wEAAwE;AACxE,eAAe;AAEf,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAEpD,OAAO,EAAE,kCAAkC,EAAE,MAAM,wBAAwB,CAAC;AAE5E,OAAO,EAAE,8CAA8C,EAAE,MAAM,gCAAgC,CAAC;AAChG,OAAO,EAA+B,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEhF;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,8BAA8B,CAC5C,OAA+B,EAC/B,QAAiC;IAEjC,QAAQ,OAAO,CAAC,WAAW,EAAE,CAAC;QAC5B,KAAK,WAAW,CAAC,QAAQ;YACvB,OAAO,cAAc,CACnB,8CAA8C,CAAC,OAAO,CAAC,CAAC,YAAY,EACpE,kCAAkC,CAAC,QAAQ,CAAC,CAC7C,CAAC;QACJ;YACE,MAAM,IAAI,KAAK,CAAC,2BAA2B,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IAC9E,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,6BAA6B,CAC3C,OAA+B,EAC/B,QAAiC,EACjC,cAAsB;IAEtB,IAAI,CAAC;QACH,OAAO,8BAA8B,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,UAAU,CAAC,cAAc,CAAC,CAAC;IAC1F,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -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,35 +68,44 @@ 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
|
|
77
|
-
* `PublicDataProvider.queryContractEvents`.
|
|
89
|
+
* Retrieve one page of a contract's events: see
|
|
90
|
+
* `PublicDataProvider.queryContractEvents`. Callers MUST pass `page` and
|
|
91
|
+
* keep requesting until a short page: a provider caps an un-paged call at
|
|
92
|
+
* its default page size (midnight-js: 100), silently truncating a busy
|
|
93
|
+
* contract's history.
|
|
78
94
|
*
|
|
79
95
|
* @param filter - The contract address and event-type narrowing.
|
|
80
|
-
* @
|
|
96
|
+
* @param filter.contractAddress - The contract whose events to read.
|
|
97
|
+
* @param filter.types - Event types to keep; omit for all of them.
|
|
98
|
+
* @param page - The window to read: `limit` events starting at `offset`.
|
|
99
|
+
* @param page.limit - Maximum events to return.
|
|
100
|
+
* @param page.offset - Events to skip from the start of the history.
|
|
101
|
+
* @returns The matching events in the window, oldest first.
|
|
81
102
|
*/
|
|
82
103
|
queryContractEvents(filter: {
|
|
83
104
|
contractAddress: string;
|
|
84
105
|
types?: "Misc"[];
|
|
106
|
+
}, page: {
|
|
107
|
+
limit: number;
|
|
108
|
+
offset: number;
|
|
85
109
|
}): Promise<{
|
|
86
110
|
eventType: string;
|
|
87
111
|
name?: string;
|
|
@@ -90,10 +114,8 @@ export interface SignetContractEventQuerySource {
|
|
|
90
114
|
}
|
|
91
115
|
/**
|
|
92
116
|
* 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
|
|
117
|
+
* `queryContractEvents`) into a {@link SignetEventSource}. Each event's name
|
|
118
|
+
* is NUL-trimmed and its payload re-padded to the full
|
|
97
119
|
* {@link SIGNET_EVENT_PAYLOAD_LENGTH}.
|
|
98
120
|
*
|
|
99
121
|
* @param provider - The provider to query events through.
|
|
@@ -115,10 +137,9 @@ export interface AffinePoint {
|
|
|
115
137
|
* The MPC's canonical ECDSA signature as both respond events carry it
|
|
116
138
|
* (Compact `Signature`, matching the MPC's own
|
|
117
139
|
* `Signature { big_r, s, recovery_id }` and the EVM/Solana signer
|
|
118
|
-
* contracts)
|
|
119
|
-
* `
|
|
120
|
-
*
|
|
121
|
-
* `ecdsaSignatureToMpcSignature` / `mpcSignatureToEcdsaSignature`.
|
|
140
|
+
* contracts). Emitted UNVERIFIED. Decode to an ethers signature with
|
|
141
|
+
* `signatureRespondedEventToSignature`. Tests mint records with the
|
|
142
|
+
* `@sig-net/midnight/testing` entry point's `ecdsaSignatureToMpcSignature`.
|
|
122
143
|
*/
|
|
123
144
|
export interface MpcSignature {
|
|
124
145
|
/** The signature's nonce point R. */
|
|
@@ -130,12 +151,9 @@ export interface MpcSignature {
|
|
|
130
151
|
}
|
|
131
152
|
/**
|
|
132
153
|
* 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}).
|
|
154
|
+
* `SignatureRespondedEvent`), carried beside the request id it answers (see
|
|
155
|
+
* {@link SignetEventPost}). Emitted UNVERIFIED: authenticity comes from
|
|
156
|
+
* `SignetRequestResponseReader.getVerifiedSignatureRespondedEvent`.
|
|
139
157
|
*/
|
|
140
158
|
export interface SignatureRespondedEvent {
|
|
141
159
|
/** The requested signature over the transaction the request describes. */
|
|
@@ -144,15 +162,10 @@ export interface SignatureRespondedEvent {
|
|
|
144
162
|
/**
|
|
145
163
|
* The MPC's respond-bidirectional attestation of a request's remote EVM
|
|
146
164
|
* 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}.
|
|
165
|
+
* the attestation digest (`calculateSignetAttestationDigest`), carried
|
|
166
|
+
* beside the request id it answers (see {@link SignetEventPost}). Emitted
|
|
167
|
+
* UNVERIFIED: verify in-circuit via `verifyRespondBidirectionalEvent` or off
|
|
168
|
+
* chain via `verifyRespondBidirectionalSignature`.
|
|
156
169
|
*/
|
|
157
170
|
export interface RespondBidirectionalEvent {
|
|
158
171
|
/** ECDSA signature over the attestation digest. */
|
|
@@ -161,13 +174,8 @@ export interface RespondBidirectionalEvent {
|
|
|
161
174
|
/**
|
|
162
175
|
* A decoded signet event payload: the request id the emitting circuit
|
|
163
176
|
* 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).
|
|
177
|
+
* data: it scopes reads to one request and proves nothing. Each record
|
|
178
|
+
* type's own doc names its authenticity check.
|
|
171
179
|
*/
|
|
172
180
|
export interface SignetEventPost<TRecord> {
|
|
173
181
|
/** The request id the post declares it concerns, 32 bytes. Routing data only. */
|
|
@@ -181,7 +189,7 @@ export interface SignetEventPost<TRecord> {
|
|
|
181
189
|
*
|
|
182
190
|
* @param payload - The event's payload.
|
|
183
191
|
* @returns The decoded post: declared request id plus record.
|
|
184
|
-
* @throws Error
|
|
192
|
+
* @throws {Error} When the payload is too short to hold the packed leaves.
|
|
185
193
|
*/
|
|
186
194
|
export declare function decodeSignatureRespondedEventPayload(payload: Uint8Array): SignetEventPost<SignatureRespondedEvent>;
|
|
187
195
|
/**
|
|
@@ -190,7 +198,7 @@ export declare function decodeSignatureRespondedEventPayload(payload: Uint8Array
|
|
|
190
198
|
*
|
|
191
199
|
* @param payload - The event's payload.
|
|
192
200
|
* @returns The decoded post: declared request id plus record.
|
|
193
|
-
* @throws Error
|
|
201
|
+
* @throws {Error} When the payload is too short to hold the packed leaves.
|
|
194
202
|
*/
|
|
195
203
|
export declare function decodeRespondBidirectionalEventPayload(payload: Uint8Array): SignetEventPost<RespondBidirectionalEvent>;
|
|
196
204
|
/**
|
|
@@ -213,17 +221,14 @@ export interface SignBidirectionalNotificationRecord {
|
|
|
213
221
|
*
|
|
214
222
|
* @param payload - The event's payload.
|
|
215
223
|
* @returns The decoded post: declared request id plus raw notification record.
|
|
216
|
-
* @throws Error
|
|
224
|
+
* @throws {Error} When the payload is too short to hold the record.
|
|
217
225
|
*/
|
|
218
226
|
export declare function decodeSignBidirectionalEventNotificationPayload(payload: Uint8Array): SignetEventPost<SignBidirectionalNotificationRecord>;
|
|
219
227
|
/**
|
|
220
228
|
* 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.
|
|
229
|
+
* MPC a request was stored, and WHERE to read the authenticated copy
|
|
230
|
+
* (resolve with `lookupSignetRequestAt`). The fields themselves confer no
|
|
231
|
+
* authority.
|
|
227
232
|
*/
|
|
228
233
|
export interface SignBidirectionalNotification {
|
|
229
234
|
/** Payload layout tag: this decoder only produces version 1. */
|
|
@@ -231,36 +236,32 @@ export interface SignBidirectionalNotification {
|
|
|
231
236
|
/**
|
|
232
237
|
* Address of the contract whose request map holds the request, rendered
|
|
233
238
|
* as lowercase hex, no `0x` prefix: directly usable as a
|
|
234
|
-
* `queryContractState` argument.
|
|
235
|
-
* contract's authenticated state. The field itself confers no authority.
|
|
239
|
+
* `queryContractState` argument.
|
|
236
240
|
*/
|
|
237
241
|
callerAddress: string;
|
|
238
242
|
/**
|
|
239
243
|
* Resolved ledger-tree path of the `SignBidirectionalEventMap` in
|
|
240
244
|
* {@link callerAddress}, as compactc records it in that contract's
|
|
241
245
|
* `contract-info.json` (`"index"`): `[4]` for a flat contract's field 4,
|
|
242
|
-
* `[1, 14]` once chunking applies.
|
|
243
|
-
*
|
|
246
|
+
* `[1, 14]` once chunking applies. Followed node for node by
|
|
247
|
+
* `signetFieldNodeByPath`.
|
|
244
248
|
*/
|
|
245
249
|
requestsPath: number[];
|
|
246
250
|
}
|
|
247
251
|
/**
|
|
248
252
|
* Unpack a {@link SignBidirectionalNotificationRecord}'s payload by the
|
|
249
253
|
* fixed V1 offsets: the decode twin of the compiled
|
|
250
|
-
* `constructSignBidirectionalEventNotificationV1` circuit (
|
|
251
|
-
*
|
|
252
|
-
*
|
|
254
|
+
* `constructSignBidirectionalEventNotificationV1` circuit (the pack↔decode
|
|
255
|
+
* lockstep is pinned by a unit test round-tripping through the real
|
|
256
|
+
* circuit). V1 layout:
|
|
253
257
|
* callerAddress (32) ++ requestsPathDepth (1) ++ requestsPath (4) ++ zero
|
|
254
258
|
* 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.
|
|
259
|
+
* meaningful. Fails closed on an unrecognised `version`.
|
|
259
260
|
*
|
|
260
261
|
* @param record - The raw notification record.
|
|
261
262
|
* @returns The decoded notification, its `requestsPath` trimmed to the
|
|
262
263
|
* declared depth.
|
|
263
|
-
* @throws Error
|
|
264
|
+
* @throws {Error} If the record's `version` is not one this decoder understands,
|
|
264
265
|
* or its `requestsPathDepth` is zero or exceeds {@link MAX_LEDGER_PATH_DEPTH}.
|
|
265
266
|
*/
|
|
266
267
|
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,8BAA8B;CACxD;AAED,oEAAoE;AACpE,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAE3C,yDAAyD;AACzD,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAE/C;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,iFAAiF;IACjF,IAAI,EAAE,MAAM,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|
|
@@ -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.
|
|
@@ -105,21 +107,28 @@ function eventFieldBytes(hex) {
|
|
|
105
107
|
export function signetEventSourceFromPublicDataProvider(provider) {
|
|
106
108
|
return {
|
|
107
109
|
async querySignetEvents(contractAddress) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
// Page until a short page: a single un-paged read caps at the
|
|
111
|
+
// provider's default page size and silently truncates a busy signet's
|
|
112
|
+
// history, starving every consumer of the events past the cap.
|
|
113
|
+
const events = [];
|
|
114
|
+
const pageLimit = 100;
|
|
115
|
+
for (let pageOffset = 0;; pageOffset += pageLimit) {
|
|
116
|
+
const page = await provider.queryContractEvents({ contractAddress, types: ["Misc"] }, { limit: pageLimit, offset: pageOffset });
|
|
117
|
+
events.push(...page);
|
|
118
|
+
if (page.length < pageLimit)
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
112
121
|
const out = [];
|
|
113
122
|
for (const event of events) {
|
|
114
123
|
if (event.eventType !== "Misc")
|
|
115
124
|
continue;
|
|
116
125
|
if (event.name === undefined || event.payload === undefined)
|
|
117
126
|
continue;
|
|
118
|
-
const payload =
|
|
127
|
+
const payload = hexToBytes(event.payload);
|
|
119
128
|
const padded = new Uint8Array(SIGNET_EVENT_PAYLOAD_LENGTH);
|
|
120
129
|
padded.set(payload.slice(0, SIGNET_EVENT_PAYLOAD_LENGTH), 0);
|
|
121
130
|
out.push({
|
|
122
|
-
name: decodeSignetEventName(
|
|
131
|
+
name: decodeSignetEventName(hexToBytes(event.name)),
|
|
123
132
|
payload: padded,
|
|
124
133
|
});
|
|
125
134
|
}
|
|
@@ -136,17 +145,16 @@ const SIGNATURE_RECOVERY_ID_OFFSET = 128;
|
|
|
136
145
|
/**
|
|
137
146
|
* Unpack the leaves both respond payloads lead with:
|
|
138
147
|
* 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.
|
|
148
|
+
* Bytes beyond the recovery id are padding and are ignored.
|
|
141
149
|
*
|
|
142
150
|
* @param payload - The full event payload.
|
|
143
151
|
* @returns The declared request id and the decoded signature.
|
|
144
|
-
* @throws Error
|
|
152
|
+
* @throws {Error} When the payload is too short to hold the packed leaves.
|
|
145
153
|
*/
|
|
146
154
|
function decodeRespondPayload(payload) {
|
|
147
155
|
const recoveryId = payload[SIGNATURE_RECOVERY_ID_OFFSET];
|
|
148
156
|
if (recoveryId === undefined) {
|
|
149
|
-
throw new Error(`signet event payload of ${payload.length} bytes is too short for a packed respond record`);
|
|
157
|
+
throw new Error(`signet event payload of ${String(payload.length)} bytes is too short for a packed respond record`);
|
|
150
158
|
}
|
|
151
159
|
return {
|
|
152
160
|
requestId: payload.slice(RESPOND_REQUEST_ID_OFFSET, SIGNATURE_BIG_R_X_OFFSET),
|
|
@@ -166,7 +174,7 @@ function decodeRespondPayload(payload) {
|
|
|
166
174
|
*
|
|
167
175
|
* @param payload - The event's payload.
|
|
168
176
|
* @returns The decoded post: declared request id plus record.
|
|
169
|
-
* @throws Error
|
|
177
|
+
* @throws {Error} When the payload is too short to hold the packed leaves.
|
|
170
178
|
*/
|
|
171
179
|
export function decodeSignatureRespondedEventPayload(payload) {
|
|
172
180
|
const { requestId, signature } = decodeRespondPayload(payload);
|
|
@@ -178,7 +186,7 @@ export function decodeSignatureRespondedEventPayload(payload) {
|
|
|
178
186
|
*
|
|
179
187
|
* @param payload - The event's payload.
|
|
180
188
|
* @returns The decoded post: declared request id plus record.
|
|
181
|
-
* @throws Error
|
|
189
|
+
* @throws {Error} When the payload is too short to hold the packed leaves.
|
|
182
190
|
*/
|
|
183
191
|
export function decodeRespondBidirectionalEventPayload(payload) {
|
|
184
192
|
const { requestId, signature } = decodeRespondPayload(payload);
|
|
@@ -200,13 +208,13 @@ const NOTIFICATION_PAYLOAD_LENGTH = 128;
|
|
|
200
208
|
*
|
|
201
209
|
* @param payload - The event's payload.
|
|
202
210
|
* @returns The decoded post: declared request id plus raw notification record.
|
|
203
|
-
* @throws Error
|
|
211
|
+
* @throws {Error} When the payload is too short to hold the record.
|
|
204
212
|
*/
|
|
205
213
|
export function decodeSignBidirectionalEventNotificationPayload(payload) {
|
|
206
214
|
const version = payload[NOTIFICATION_EVENT_VERSION_OFFSET];
|
|
207
215
|
const end = NOTIFICATION_EVENT_PAYLOAD_OFFSET + NOTIFICATION_PAYLOAD_LENGTH;
|
|
208
216
|
if (version === undefined || payload.length < end) {
|
|
209
|
-
throw new Error(`signet event payload of ${payload.length} bytes is too short for a packed notification`);
|
|
217
|
+
throw new Error(`signet event payload of ${String(payload.length)} bytes is too short for a packed notification`);
|
|
210
218
|
}
|
|
211
219
|
return {
|
|
212
220
|
requestId: payload.slice(NOTIFICATION_EVENT_REQUEST_ID_OFFSET, NOTIFICATION_EVENT_PAYLOAD_OFFSET),
|
|
@@ -225,7 +233,7 @@ const NOTIFICATION_PATH_OFFSET = 33;
|
|
|
225
233
|
/**
|
|
226
234
|
* Maximum ledger-tree path depth the V1 payload carries, matching the
|
|
227
235
|
* `Vector<4, Uint<8>>` the `constructSignBidirectionalEventNotificationV1`
|
|
228
|
-
* circuit packs.
|
|
236
|
+
* circuit packs.
|
|
229
237
|
*/
|
|
230
238
|
const MAX_LEDGER_PATH_DEPTH = 4;
|
|
231
239
|
/** The only payload interpretation {@link decodeSignBidirectionalNotification} understands today. */
|
|
@@ -233,32 +241,29 @@ const SUPPORTED_NOTIFICATION_VERSION = 1n;
|
|
|
233
241
|
/**
|
|
234
242
|
* Unpack a {@link SignBidirectionalNotificationRecord}'s payload by the
|
|
235
243
|
* fixed V1 offsets: the decode twin of the compiled
|
|
236
|
-
* `constructSignBidirectionalEventNotificationV1` circuit (
|
|
237
|
-
*
|
|
238
|
-
*
|
|
244
|
+
* `constructSignBidirectionalEventNotificationV1` circuit (the pack↔decode
|
|
245
|
+
* lockstep is pinned by a unit test round-tripping through the real
|
|
246
|
+
* circuit). V1 layout:
|
|
239
247
|
* callerAddress (32) ++ requestsPathDepth (1) ++ requestsPath (4) ++ zero
|
|
240
248
|
* 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.
|
|
249
|
+
* meaningful. Fails closed on an unrecognised `version`.
|
|
245
250
|
*
|
|
246
251
|
* @param record - The raw notification record.
|
|
247
252
|
* @returns The decoded notification, its `requestsPath` trimmed to the
|
|
248
253
|
* declared depth.
|
|
249
|
-
* @throws Error
|
|
254
|
+
* @throws {Error} If the record's `version` is not one this decoder understands,
|
|
250
255
|
* or its `requestsPathDepth` is zero or exceeds {@link MAX_LEDGER_PATH_DEPTH}.
|
|
251
256
|
*/
|
|
252
257
|
export function decodeSignBidirectionalNotification(record) {
|
|
253
258
|
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})`);
|
|
259
|
+
throw new Error(`SignBidirectionalEventNotification version ${String(record.version)} is not supported ` +
|
|
260
|
+
`(this decoder understands version ${String(SUPPORTED_NOTIFICATION_VERSION)})`);
|
|
256
261
|
}
|
|
257
262
|
const callerAddress = bytesToHex(record.payload.slice(NOTIFICATION_CALLER_ADDRESS_OFFSET, NOTIFICATION_PATH_DEPTH_OFFSET));
|
|
258
263
|
const depth = record.payload[NOTIFICATION_PATH_DEPTH_OFFSET];
|
|
259
264
|
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})`);
|
|
265
|
+
throw new Error(`SignBidirectionalEventNotification requestsPathDepth ${String(depth)} is out of range ` +
|
|
266
|
+
`(expected 1 to ${String(MAX_LEDGER_PATH_DEPTH)})`);
|
|
262
267
|
}
|
|
263
268
|
// payload is a re-padded Bytes<128> and depth is bounded to MAX_LEDGER_PATH_DEPTH
|
|
264
269
|
// 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;A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AAM,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"}
|