@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
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { PublicDataProvider } from "@midnight-ntwrk/midnight-js-types";
|
|
2
2
|
import type { Transaction } from "ethers";
|
|
3
|
-
import { type SignetEventSource, type SignatureRespondedEvent, type RespondBidirectionalEvent } from "./signet-contract-events.ts";
|
|
4
3
|
import { type Secp256k1Point } from "./ecdsa-attestation.ts";
|
|
5
|
-
import type { RawContractState } from "./
|
|
6
|
-
import { type
|
|
4
|
+
import type { RawContractState } from "./raw-contract-state.ts";
|
|
5
|
+
import { type RespondBidirectionalEvent, type SignatureRespondedEvent, type SignetEventSource } from "./signet-contract-events.ts";
|
|
6
|
+
import { type RequestIdHex, type SignBidirectionalEvent } from "./signet-requests.ts";
|
|
7
7
|
/**
|
|
8
8
|
* The least of midnight-js's `PublicDataProvider` the reader needs: raw
|
|
9
9
|
* contract state by address. Declared structurally so tests can satisfy it
|
|
@@ -29,9 +29,7 @@ export interface SignetRequestResponseReaderConfig {
|
|
|
29
29
|
/**
|
|
30
30
|
* Resolved ledger-tree path of the requester contract's request index: the
|
|
31
31
|
* same path the contract packs as `requestsPath` in its notifications
|
|
32
|
-
* (`[4]` for a flat contract's field 4, longer once chunking applies).
|
|
33
|
-
* contract is free to declare the index at any field, so the reader cannot
|
|
34
|
-
* assume one.
|
|
32
|
+
* (`[4]` for a flat contract's field 4, longer once chunking applies).
|
|
35
33
|
*/
|
|
36
34
|
readonly requesterRequestsPath: readonly number[];
|
|
37
35
|
/** Address of the central signet contract. */
|
|
@@ -62,17 +60,13 @@ export interface VerifiedSignatureResponseResult {
|
|
|
62
60
|
* response has been posted yet: poll again.
|
|
63
61
|
*/
|
|
64
62
|
verified?: SignatureRespondedEvent;
|
|
65
|
-
/**
|
|
66
|
-
* One verdict per post, emission order. Pure data: the reader never logs,
|
|
67
|
-
* so callers decide how to surface rejected posts.
|
|
68
|
-
*/
|
|
63
|
+
/** One verdict per post, emission order. */
|
|
69
64
|
verdicts: SignatureResponseVerdict[];
|
|
70
65
|
}
|
|
71
66
|
/**
|
|
72
|
-
* Reader over one requester contract / signet contract pair.
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* calls cost one event query each.
|
|
67
|
+
* Reader over one requester contract / signet contract pair. Construct once
|
|
68
|
+
* per pair and reuse: fetched request records are cached, so repeated
|
|
69
|
+
* verification calls cost one event query each.
|
|
76
70
|
*/
|
|
77
71
|
export declare class SignetRequestResponseReader {
|
|
78
72
|
private readonly config;
|
|
@@ -84,20 +78,17 @@ export declare class SignetRequestResponseReader {
|
|
|
84
78
|
constructor(config: SignetRequestResponseReaderConfig);
|
|
85
79
|
/**
|
|
86
80
|
* Fetch the request record for `requestId` from the requester contract's
|
|
87
|
-
* request index
|
|
88
|
-
* after the first fetch.
|
|
81
|
+
* request index. Cached after the first fetch.
|
|
89
82
|
*
|
|
90
83
|
* @param requestId - The request id to look up.
|
|
91
84
|
* @returns The stored request record.
|
|
92
|
-
* @throws Error
|
|
85
|
+
* @throws {Error} When the requester contract has no state or holds no
|
|
93
86
|
* request under `requestId` at the configured index path.
|
|
94
87
|
*/
|
|
95
88
|
getSignatureRequest(requestId: RequestIdHex): Promise<SignBidirectionalEvent>;
|
|
96
89
|
/**
|
|
97
|
-
* Fetch
|
|
98
|
-
*
|
|
99
|
-
* `requestId`, in emission order. The declared id is routing data only:
|
|
100
|
-
* the verified getters run the actual authenticity checks.
|
|
90
|
+
* Fetch the signet contract's posts of event `name` that declare
|
|
91
|
+
* `requestId`, in emission order. The declared id is routing data only.
|
|
101
92
|
*
|
|
102
93
|
* @param name - The signet event name to keep.
|
|
103
94
|
* @param decode - The payload decoder for that event kind.
|
|
@@ -107,10 +98,8 @@ export declare class SignetRequestResponseReader {
|
|
|
107
98
|
private getRespondPostsNamed;
|
|
108
99
|
/**
|
|
109
100
|
* Fetch every signature response posted under `requestId`, in emission
|
|
110
|
-
* order. UNVERIFIED:
|
|
111
|
-
*
|
|
112
|
-
* {@link getVerifiedSignatureRespondedEvent}, where verification
|
|
113
|
-
* establishes authenticity).
|
|
101
|
+
* order. UNVERIFIED: any post may still be garbage, sift with
|
|
102
|
+
* {@link getVerifiedSignatureRespondedEvent} first.
|
|
114
103
|
*
|
|
115
104
|
* @param requestId - The request id the posts must declare.
|
|
116
105
|
* @returns The request's posted records, oldest first, empty when none yet.
|
|
@@ -118,40 +107,36 @@ export declare class SignetRequestResponseReader {
|
|
|
118
107
|
getSignatureRespondedEvents(requestId: RequestIdHex): Promise<SignatureRespondedEvent[]>;
|
|
119
108
|
/**
|
|
120
109
|
* Fetch the signature responses posted under `requestId` and verify each
|
|
121
|
-
* against the request: a post's signature
|
|
110
|
+
* against the request: a valid post's signature recovers to
|
|
122
111
|
* `expectedSigner` (compared case-insensitively) over the signing hash of
|
|
123
|
-
* the
|
|
124
|
-
*
|
|
125
|
-
* declared id only routes: this verification is what separates the genuine
|
|
126
|
-
* response from garbage posted under the same id.
|
|
112
|
+
* the request's transaction. The first valid post wins, and every
|
|
113
|
+
* candidate gets a verdict.
|
|
127
114
|
*
|
|
128
115
|
* @param requestId - The request id to fetch a verified response for.
|
|
129
116
|
* @param expectedSigner - The EVM address (0x hex, any case) the genuine
|
|
130
117
|
* response must be signed by: the requester's MPC-derived address.
|
|
131
118
|
* @returns The first valid response (if any) plus per-post verdicts.
|
|
132
|
-
* @throws Error
|
|
119
|
+
* @throws {Error} When the requester contract has no state or the request is
|
|
133
120
|
* not on its ledger.
|
|
134
121
|
*/
|
|
135
122
|
getVerifiedSignatureRespondedEvent(requestId: RequestIdHex, expectedSigner: string): Promise<VerifiedSignatureResponseResult>;
|
|
136
123
|
/**
|
|
137
124
|
* Rebuild the unsigned EIP-1559 transaction for `requestId`: the exact
|
|
138
|
-
* transaction the MPC signs,
|
|
139
|
-
*
|
|
140
|
-
* (fetched via {@link getSignatureRequest}, cached).
|
|
125
|
+
* transaction the MPC signs, from the request record alone (fetched via
|
|
126
|
+
* {@link getSignatureRequest}, cached).
|
|
141
127
|
*
|
|
142
128
|
* @param requestId - The request id whose transaction to rebuild.
|
|
143
129
|
* @returns The unsigned ethers transaction (`unsignedHash` is the MPC's
|
|
144
130
|
* signing digest).
|
|
145
|
-
* @throws Error
|
|
146
|
-
* request under `requestId
|
|
131
|
+
* @throws {Error} When the requester contract has no state, holds no
|
|
132
|
+
* request under `requestId`, or the request is not an evmType2 record.
|
|
147
133
|
*/
|
|
148
134
|
getUnsignedEvmTransaction(requestId: RequestIdHex): Promise<Transaction>;
|
|
149
135
|
/**
|
|
150
|
-
* Assemble the broadcast-ready signed EIP-1559 transaction for
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
* and unverified posts are never attached).
|
|
136
|
+
* Assemble the broadcast-ready signed EIP-1559 transaction for
|
|
137
|
+
* `requestId`, attaching the first VERIFIED response signed by
|
|
138
|
+
* `expectedSigner` (see {@link getVerifiedSignatureRespondedEvent}).
|
|
139
|
+
* Unverified posts are never attached.
|
|
155
140
|
*
|
|
156
141
|
* @param requestId - The request id to produce a signed transaction for.
|
|
157
142
|
* @param expectedSigner - The EVM address (0x hex, any case) the genuine
|
|
@@ -159,18 +144,15 @@ export declare class SignetRequestResponseReader {
|
|
|
159
144
|
* @returns The signed ethers transaction (`serialized` is the payload for
|
|
160
145
|
* `eth_sendRawTransaction`), or `undefined` when no valid response has
|
|
161
146
|
* been posted yet: poll again.
|
|
162
|
-
* @throws Error
|
|
163
|
-
* not on its ledger.
|
|
147
|
+
* @throws {Error} When the requester contract has no state, the request is
|
|
148
|
+
* not on its ledger, or the request is not an evmType2 record.
|
|
164
149
|
*/
|
|
165
150
|
getSignedEvmTransaction(requestId: RequestIdHex, expectedSigner: string): Promise<Transaction | undefined>;
|
|
166
151
|
/**
|
|
167
152
|
* Fetch every respond-bidirectional response posted under `requestId`, in
|
|
168
|
-
* emission order. UNVERIFIED:
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
* at claim time, or off chain with
|
|
172
|
-
* {@link verifyRespondBidirectionalSignature} over the output you fetched.
|
|
173
|
-
* An empty array simply means none posted yet: poll again.
|
|
153
|
+
* emission order. UNVERIFIED: any post may still be garbage, sift with
|
|
154
|
+
* {@link getVerifiedRespondBidirectionalEvent} (or in-circuit at claim
|
|
155
|
+
* time) first.
|
|
174
156
|
*
|
|
175
157
|
* @param requestId - The request id the posts must declare.
|
|
176
158
|
* @returns The request's posted records, oldest first, empty when none yet.
|
|
@@ -180,13 +162,9 @@ export declare class SignetRequestResponseReader {
|
|
|
180
162
|
* Fetch the respond-bidirectional posts declared under `requestId` and
|
|
181
163
|
* return the first (oldest) one whose signature verifies over
|
|
182
164
|
* `serializedOutput` against `mpcResponseKey`: the off-chain twin of the
|
|
183
|
-
* check the client contract runs in-circuit
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
* The output must be the exact unpadded bytes the attestation commits to
|
|
187
|
-
* (the packed respond payload, recomputed from the execution output the
|
|
188
|
-
* client fetched), so a post that verifies here is the post that proves at
|
|
189
|
-
* claim time.
|
|
165
|
+
* check the client contract runs in-circuit. The output must be the exact
|
|
166
|
+
* unpadded bytes the attestation commits to, so a post that verifies here
|
|
167
|
+
* is the post that proves at claim time.
|
|
190
168
|
*
|
|
191
169
|
* @param requestId - The request id the posts must declare and the
|
|
192
170
|
* attestation must commit to.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signet-request-response-reader.d.ts","sourceRoot":"","sources":["../src/signet-request-response-reader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"signet-request-response-reader.d.ts","sourceRoot":"","sources":["../src/signet-request-response-reader.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAE1C,OAAO,EAAE,KAAK,cAAc,EAAuC,MAAM,wBAAwB,CAAC;AAClG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBA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AA2B;IACtC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoC;IAG3D,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAmD;IAEhF;;;OAGG;IACH,YAAY,MAAM,EAAE,iCAAiC,EAEpD;IAED;;;;;;;;OAQG;IACG,mBAAmB,CAAC,SAAS,EAAE,YAAY,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAsBlF;IAED;;;;;;;;OAQG;YACW,oBAAoB;IAelC;;;;;;;OAOG;IACG,2BAA2B,CAAC,SAAS,EAAE,YAAY,GAAG,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAM7F;IAED;;;;;;;;;;;;;OAaG;IACG,kCAAkC,CACtC,SAAS,EAAE,YAAY,EACvB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,+BAA+B,CAAC,CA6B1C;IAED;;;;;;;;;;OAUG;IACG,yBAAyB,CAAC,SAAS,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CAI7E;IAED;;;;;;;;;;;;;;OAcG;IACG,uBAAuB,CAC3B,SAAS,EAAE,YAAY,EACvB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAQlC;IAED;;;;;;;;OAQG;IACG,6BAA6B,CACjC,SAAS,EAAE,YAAY,GACtB,OAAO,CAAC,yBAAyB,EAAE,CAAC,CAMtC;IAED;;;;;;;;;;;;;;;;OAgBG;IACG,oCAAoC,CACxC,SAAS,EAAE,YAAY,EACvB,gBAAgB,EAAE,UAAU,EAC5B,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,yBAAyB,GAAG,SAAS,CAAC,CAUhD;CACF"}
|
|
@@ -1,28 +1,31 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
// signature response answers a request exactly when it recovers to that
|
|
9
|
-
// request's derived signer over the request's transaction, and a
|
|
10
|
-
// respond-bidirectional post answers exactly when it verifies over
|
|
11
|
-
// (requestId, output) against the request's MPC response key. This class
|
|
12
|
-
// packages that flow so every consumer (CLI poller, integration tests, a
|
|
13
|
-
// future UI) shares one implementation. Single-shot by design: each call
|
|
14
|
-
// queries once, and the caller owns any poll loop.
|
|
1
|
+
// Client-side reader for the signet request/response flow: fetch a request
|
|
2
|
+
// record from the requester contract's ledger, read the request's responses
|
|
3
|
+
// out of the contract events the signet contract emits, and verify each
|
|
4
|
+
// candidate against the request. The request id a response declares is
|
|
5
|
+
// UNAUTHENTICATED routing data: VERIFICATION establishes authenticity.
|
|
6
|
+
// Single-shot: each call queries once, and the caller owns any poll loop.
|
|
7
|
+
import { verifyRespondBidirectionalSignature } from "./ecdsa-attestation.js";
|
|
15
8
|
import { lookupSignetRequestAt } from "./signature-requests-state-reader.js";
|
|
16
|
-
import { decodeRespondBidirectionalEventPayload, decodeSignatureRespondedEventPayload, SignetEventName, } from "./signet-contract-events.js";
|
|
17
9
|
import { recoverSignatureResponseSigner } from "./signature-response-verification.js";
|
|
18
|
-
import {
|
|
10
|
+
import { decodeRespondBidirectionalEventPayload, decodeSignatureRespondedEventPayload, isSignetEventNamed, SignetEventName, } from "./signet-contract-events.js";
|
|
19
11
|
import { signBidirectionalEventToSignedEvmTransaction, signBidirectionalEventToUnsignedEvmTransaction, } from "./signet-evtype2tx-requests.js";
|
|
20
|
-
import { requestIdBytes, requestIdHex, } from "./signet-requests.js";
|
|
12
|
+
import { requestIdBytes, requestIdHex, TxParamType, } from "./signet-requests.js";
|
|
21
13
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
14
|
+
* Assert a fetched request carries the evmType2 decomposition, the only one
|
|
15
|
+
* the EVM-transaction methods may read `txParams` from.
|
|
16
|
+
*
|
|
17
|
+
* @param request - The fetched request record.
|
|
18
|
+
* @throws {Error} If the record carries any other decomposition.
|
|
19
|
+
*/
|
|
20
|
+
function assertEvmType2Request(request) {
|
|
21
|
+
if (request.txParamType !== TxParamType.evmType2) {
|
|
22
|
+
throw new Error(`unsupported txParamType ${String(request.txParamType)}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Reader over one requester contract / signet contract pair. Construct once
|
|
27
|
+
* per pair and reuse: fetched request records are cached, so repeated
|
|
28
|
+
* verification calls cost one event query each.
|
|
26
29
|
*/
|
|
27
30
|
export class SignetRequestResponseReader {
|
|
28
31
|
config;
|
|
@@ -37,12 +40,11 @@ export class SignetRequestResponseReader {
|
|
|
37
40
|
}
|
|
38
41
|
/**
|
|
39
42
|
* Fetch the request record for `requestId` from the requester contract's
|
|
40
|
-
* request index
|
|
41
|
-
* after the first fetch.
|
|
43
|
+
* request index. Cached after the first fetch.
|
|
42
44
|
*
|
|
43
45
|
* @param requestId - The request id to look up.
|
|
44
46
|
* @returns The stored request record.
|
|
45
|
-
* @throws Error
|
|
47
|
+
* @throws {Error} When the requester contract has no state or holds no
|
|
46
48
|
* request under `requestId` at the configured index path.
|
|
47
49
|
*/
|
|
48
50
|
async getSignatureRequest(requestId) {
|
|
@@ -63,10 +65,8 @@ export class SignetRequestResponseReader {
|
|
|
63
65
|
return request;
|
|
64
66
|
}
|
|
65
67
|
/**
|
|
66
|
-
* Fetch
|
|
67
|
-
*
|
|
68
|
-
* `requestId`, in emission order. The declared id is routing data only:
|
|
69
|
-
* the verified getters run the actual authenticity checks.
|
|
68
|
+
* Fetch the signet contract's posts of event `name` that declare
|
|
69
|
+
* `requestId`, in emission order. The declared id is routing data only.
|
|
70
70
|
*
|
|
71
71
|
* @param name - The signet event name to keep.
|
|
72
72
|
* @param decode - The payload decoder for that event kind.
|
|
@@ -76,17 +76,15 @@ export class SignetRequestResponseReader {
|
|
|
76
76
|
async getRespondPostsNamed(name, decode, requestId) {
|
|
77
77
|
const events = await this.config.eventSource.querySignetEvents(this.config.signetContractAddress);
|
|
78
78
|
return events
|
|
79
|
-
.filter((event) => event
|
|
79
|
+
.filter((event) => isSignetEventNamed(event, name))
|
|
80
80
|
.map((event) => decode(event.payload))
|
|
81
81
|
.filter((post) => requestIdHex(post.requestId) === requestId)
|
|
82
82
|
.map((post) => post.event);
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
85
|
* Fetch every signature response posted under `requestId`, in emission
|
|
86
|
-
* order. UNVERIFIED:
|
|
87
|
-
*
|
|
88
|
-
* {@link getVerifiedSignatureRespondedEvent}, where verification
|
|
89
|
-
* establishes authenticity).
|
|
86
|
+
* order. UNVERIFIED: any post may still be garbage, sift with
|
|
87
|
+
* {@link getVerifiedSignatureRespondedEvent} first.
|
|
90
88
|
*
|
|
91
89
|
* @param requestId - The request id the posts must declare.
|
|
92
90
|
* @returns The request's posted records, oldest first, empty when none yet.
|
|
@@ -96,18 +94,16 @@ export class SignetRequestResponseReader {
|
|
|
96
94
|
}
|
|
97
95
|
/**
|
|
98
96
|
* Fetch the signature responses posted under `requestId` and verify each
|
|
99
|
-
* against the request: a post's signature
|
|
97
|
+
* against the request: a valid post's signature recovers to
|
|
100
98
|
* `expectedSigner` (compared case-insensitively) over the signing hash of
|
|
101
|
-
* the
|
|
102
|
-
*
|
|
103
|
-
* declared id only routes: this verification is what separates the genuine
|
|
104
|
-
* response from garbage posted under the same id.
|
|
99
|
+
* the request's transaction. The first valid post wins, and every
|
|
100
|
+
* candidate gets a verdict.
|
|
105
101
|
*
|
|
106
102
|
* @param requestId - The request id to fetch a verified response for.
|
|
107
103
|
* @param expectedSigner - The EVM address (0x hex, any case) the genuine
|
|
108
104
|
* response must be signed by: the requester's MPC-derived address.
|
|
109
105
|
* @returns The first valid response (if any) plus per-post verdicts.
|
|
110
|
-
* @throws Error
|
|
106
|
+
* @throws {Error} When the requester contract has no state or the request is
|
|
111
107
|
* not on its ledger.
|
|
112
108
|
*/
|
|
113
109
|
async getVerifiedSignatureRespondedEvent(requestId, expectedSigner) {
|
|
@@ -143,25 +139,25 @@ export class SignetRequestResponseReader {
|
|
|
143
139
|
}
|
|
144
140
|
/**
|
|
145
141
|
* Rebuild the unsigned EIP-1559 transaction for `requestId`: the exact
|
|
146
|
-
* transaction the MPC signs,
|
|
147
|
-
*
|
|
148
|
-
* (fetched via {@link getSignatureRequest}, cached).
|
|
142
|
+
* transaction the MPC signs, from the request record alone (fetched via
|
|
143
|
+
* {@link getSignatureRequest}, cached).
|
|
149
144
|
*
|
|
150
145
|
* @param requestId - The request id whose transaction to rebuild.
|
|
151
146
|
* @returns The unsigned ethers transaction (`unsignedHash` is the MPC's
|
|
152
147
|
* signing digest).
|
|
153
|
-
* @throws Error
|
|
154
|
-
* request under `requestId
|
|
148
|
+
* @throws {Error} When the requester contract has no state, holds no
|
|
149
|
+
* request under `requestId`, or the request is not an evmType2 record.
|
|
155
150
|
*/
|
|
156
151
|
async getUnsignedEvmTransaction(requestId) {
|
|
157
|
-
|
|
152
|
+
const request = await this.getSignatureRequest(requestId);
|
|
153
|
+
assertEvmType2Request(request);
|
|
154
|
+
return signBidirectionalEventToUnsignedEvmTransaction(request);
|
|
158
155
|
}
|
|
159
156
|
/**
|
|
160
|
-
* Assemble the broadcast-ready signed EIP-1559 transaction for
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* and unverified posts are never attached).
|
|
157
|
+
* Assemble the broadcast-ready signed EIP-1559 transaction for
|
|
158
|
+
* `requestId`, attaching the first VERIFIED response signed by
|
|
159
|
+
* `expectedSigner` (see {@link getVerifiedSignatureRespondedEvent}).
|
|
160
|
+
* Unverified posts are never attached.
|
|
165
161
|
*
|
|
166
162
|
* @param requestId - The request id to produce a signed transaction for.
|
|
167
163
|
* @param expectedSigner - The EVM address (0x hex, any case) the genuine
|
|
@@ -169,27 +165,23 @@ export class SignetRequestResponseReader {
|
|
|
169
165
|
* @returns The signed ethers transaction (`serialized` is the payload for
|
|
170
166
|
* `eth_sendRawTransaction`), or `undefined` when no valid response has
|
|
171
167
|
* been posted yet: poll again.
|
|
172
|
-
* @throws Error
|
|
173
|
-
* not on its ledger.
|
|
168
|
+
* @throws {Error} When the requester contract has no state, the request is
|
|
169
|
+
* not on its ledger, or the request is not an evmType2 record.
|
|
174
170
|
*/
|
|
175
171
|
async getSignedEvmTransaction(requestId, expectedSigner) {
|
|
172
|
+
const request = await this.getSignatureRequest(requestId);
|
|
173
|
+
assertEvmType2Request(request);
|
|
176
174
|
const { verified } = await this.getVerifiedSignatureRespondedEvent(requestId, expectedSigner);
|
|
177
175
|
if (verified === undefined) {
|
|
178
176
|
return undefined;
|
|
179
177
|
}
|
|
180
|
-
// getSignatureRequest is cached: getVerifiedSignatureRespondedEvent already
|
|
181
|
-
// fetched it, so this is a free lookup.
|
|
182
|
-
const request = await this.getSignatureRequest(requestId);
|
|
183
178
|
return signBidirectionalEventToSignedEvmTransaction(request, verified);
|
|
184
179
|
}
|
|
185
180
|
/**
|
|
186
181
|
* Fetch every respond-bidirectional response posted under `requestId`, in
|
|
187
|
-
* emission order. UNVERIFIED:
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
* at claim time, or off chain with
|
|
191
|
-
* {@link verifyRespondBidirectionalSignature} over the output you fetched.
|
|
192
|
-
* An empty array simply means none posted yet: poll again.
|
|
182
|
+
* emission order. UNVERIFIED: any post may still be garbage, sift with
|
|
183
|
+
* {@link getVerifiedRespondBidirectionalEvent} (or in-circuit at claim
|
|
184
|
+
* time) first.
|
|
193
185
|
*
|
|
194
186
|
* @param requestId - The request id the posts must declare.
|
|
195
187
|
* @returns The request's posted records, oldest first, empty when none yet.
|
|
@@ -201,13 +193,9 @@ export class SignetRequestResponseReader {
|
|
|
201
193
|
* Fetch the respond-bidirectional posts declared under `requestId` and
|
|
202
194
|
* return the first (oldest) one whose signature verifies over
|
|
203
195
|
* `serializedOutput` against `mpcResponseKey`: the off-chain twin of the
|
|
204
|
-
* check the client contract runs in-circuit
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
* The output must be the exact unpadded bytes the attestation commits to
|
|
208
|
-
* (the packed respond payload, recomputed from the execution output the
|
|
209
|
-
* client fetched), so a post that verifies here is the post that proves at
|
|
210
|
-
* claim time.
|
|
196
|
+
* check the client contract runs in-circuit. The output must be the exact
|
|
197
|
+
* unpadded bytes the attestation commits to, so a post that verifies here
|
|
198
|
+
* is the post that proves at claim time.
|
|
211
199
|
*
|
|
212
200
|
* @param requestId - The request id the posts must declare and the
|
|
213
201
|
* attestation must commit to.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signet-request-response-reader.js","sourceRoot":"","sources":["../src/signet-request-response-reader.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,
|
|
1
|
+
{"version":3,"file":"signet-request-response-reader.js","sourceRoot":"","sources":["../src/signet-request-response-reader.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,4EAA4E;AAC5E,wEAAwE;AACxE,uEAAuE;AACvE,uEAAuE;AACvE,0EAA0E;AAK1E,OAAO,EAAuB,mCAAmC,EAAE,MAAM,wBAAwB,CAAC;AAElG,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AACtF,OAAO,EACL,sCAAsC,EACtC,oCAAoC,EACpC,kBAAkB,EAGlB,eAAe,GAGhB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,4CAA4C,EAC5C,8CAA8C,GAC/C,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,cAAc,EAEd,YAAY,EAEZ,WAAW,GACZ,MAAM,sBAAsB,CAAC;AAiE9B;;;;;;GAMG;AACH,SAAS,qBAAqB,CAAC,OAA+B;IAC5D,IAAI,OAAO,CAAC,WAAW,KAAK,WAAW,CAAC,QAAQ,EAAE,CAAC;QACjD,MAAM,IAAI,KAAK,CAAC,2BAA2B,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IAC5E,CAAC;AACH,CAAC;AAED;;;;GAIG;AAC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