@sig-net/midnight 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/ecdsa-attestation.d.ts +53 -1
- package/dist/ecdsa-attestation.d.ts.map +1 -1
- package/dist/ecdsa-attestation.js +96 -4
- package/dist/ecdsa-attestation.js.map +1 -1
- package/dist/epsilon-derivation.d.ts +8 -8
- package/dist/epsilon-derivation.d.ts.map +1 -1
- package/dist/epsilon-derivation.js +15 -17
- package/dist/epsilon-derivation.js.map +1 -1
- package/dist/managed/compiler/contract-info.json +42 -24
- package/dist/managed/compiler/contract-manifest.json +8 -8
- package/dist/managed/contract/index.d.ts +14 -10
- package/dist/managed/contract/index.js +142 -86
- package/dist/managed/contract/index.js.map +1 -1
- package/dist/signature-requests-state-reader.d.ts +2 -2
- package/dist/signature-requests-state-reader.d.ts.map +1 -1
- package/dist/signature-requests-state-reader.js +32 -15
- package/dist/signature-requests-state-reader.js.map +1 -1
- package/dist/signature-response-verification.d.ts +1 -1
- package/dist/signature-response-verification.js +5 -5
- package/dist/signature-response-verification.js.map +1 -1
- package/dist/signet-contract-state-reader.d.ts +49 -30
- package/dist/signet-contract-state-reader.d.ts.map +1 -1
- package/dist/signet-contract-state-reader.js +55 -35
- package/dist/signet-contract-state-reader.js.map +1 -1
- package/dist/signet-evtype2tx-requests.d.ts +47 -44
- package/dist/signet-evtype2tx-requests.d.ts.map +1 -1
- package/dist/signet-evtype2tx-requests.js +47 -79
- package/dist/signet-evtype2tx-requests.js.map +1 -1
- package/dist/signet-request-response-reader.d.ts +3 -3
- package/dist/signet-request-response-reader.js +9 -9
- package/dist/signet-request-response-reader.js.map +1 -1
- package/dist/signet-requests.d.ts +4 -4
- package/dist/signet-requests.js +1 -1
- package/package.json +1 -1
- package/src/Signet.compact +85 -51
|
@@ -4,12 +4,12 @@ import type { SignatureRespondedEvent } from "./signet-contract-state-reader.ts"
|
|
|
4
4
|
import { type Maybe, type RequestId, type SignBidirectionalEvent } from "./signet-requests.ts";
|
|
5
5
|
/**
|
|
6
6
|
* ABI calldata as a 4-byte selector + 32-byte word slots (Compact:
|
|
7
|
-
* `
|
|
7
|
+
* `EvmCalldata<#maxWords>`). Every stored byte is ABI-READY: the calldata the
|
|
8
8
|
* MPC signs is `selector || words[0..noWords]` VERBATIM (see
|
|
9
9
|
* {@link assembleCalldata}), so words are big-endian broadcast-form ABI words,
|
|
10
10
|
* built in-circuit by Signet.compact's `evmAddressAbiWord` / `numericAbiWord`.
|
|
11
11
|
*/
|
|
12
|
-
export interface
|
|
12
|
+
export interface EvmCalldata {
|
|
13
13
|
/** The literal first 4 calldata bytes (as broadcast). */
|
|
14
14
|
selector: Uint8Array;
|
|
15
15
|
/** How many leading {@link words} are real (Compact `noWords: Uint<16>`). */
|
|
@@ -22,9 +22,9 @@ export interface EVMCalldata {
|
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* One EIP-2930 access-list entry (Compact:
|
|
25
|
-
* `
|
|
25
|
+
* `EvmAccessListEntry<#maxStorageKeys>`).
|
|
26
26
|
*/
|
|
27
|
-
export interface
|
|
27
|
+
export interface EvmAccessListEntry {
|
|
28
28
|
/** The pre-declared contract address, 20 display-order bytes. */
|
|
29
29
|
address: Uint8Array;
|
|
30
30
|
/** How many leading {@link storageKeys} are real. */
|
|
@@ -34,53 +34,53 @@ export interface EVMAccessListEntry {
|
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* The EVM transaction to be signed, decomposed into typed fields (Compact:
|
|
37
|
-
* `
|
|
37
|
+
* `EvmType2TxParams<#maxCalldataWords, #maxAccessListEntries,
|
|
38
38
|
* #maxStorageKeysPerEntry>`; EIP-1559 — https://eips.ethereum.org/EIPS/eip-1559).
|
|
39
39
|
* Compact `Bytes<N>` fields arrive as N-byte `Uint8Array`s, `Uint<N>` as
|
|
40
40
|
* `bigint`. Vector capacities are each contract's compile-time throttle;
|
|
41
41
|
* the runtime counts say how many leading slots are real.
|
|
42
42
|
*/
|
|
43
|
-
export interface
|
|
44
|
-
/** Call target (e.g. the ERC20 contract), 20 bytes. */
|
|
45
|
-
to: Uint8Array;
|
|
43
|
+
export interface EvmType2TxParams {
|
|
46
44
|
/** EVM chain id (also expressed in the record's `caip2Id`). */
|
|
47
45
|
chainId: bigint;
|
|
48
46
|
/** Account nonce of the MPC-derived sender address. */
|
|
49
47
|
nonce: bigint;
|
|
50
|
-
/** Gas ceiling for the call. */
|
|
51
|
-
gasLimit: bigint;
|
|
52
|
-
/** Max total fee per gas, wei. */
|
|
53
|
-
maxFeePerGas: bigint;
|
|
54
48
|
/** Max priority fee per gas, wei. */
|
|
55
49
|
maxPriorityFeePerGas: bigint;
|
|
50
|
+
/** Max total fee per gas, wei. */
|
|
51
|
+
maxFeePerGas: bigint;
|
|
52
|
+
/** Gas ceiling for the call. */
|
|
53
|
+
gasLimit: bigint;
|
|
54
|
+
/** Call target (e.g. the ERC20 contract), 20 bytes. */
|
|
55
|
+
to: Uint8Array;
|
|
56
56
|
/** ETH sent with the call, wei. */
|
|
57
57
|
value: bigint;
|
|
58
|
+
/** Call data; `is_some: false` means a plain ETH transfer (`0x` data). */
|
|
59
|
+
calldata: Maybe<EvmCalldata>;
|
|
58
60
|
/** How many leading {@link accessList} entries are real. */
|
|
59
61
|
accessListEntryCount: bigint;
|
|
60
62
|
/** EIP-2930 access list slots (capacity = contract's throttle). */
|
|
61
|
-
accessList:
|
|
62
|
-
/** Call data; `is_some: false` means a plain ETH transfer (`0x` data). */
|
|
63
|
-
calldata: Maybe<EVMCalldata>;
|
|
63
|
+
accessList: EvmAccessListEntry[];
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
|
-
* Descriptor of {@link
|
|
67
|
-
* of instantiating Compact's `
|
|
66
|
+
* Descriptor of {@link EvmCalldata} at one word capacity — the TS analogue
|
|
67
|
+
* of instantiating Compact's `EvmCalldata<#maxWords>`.
|
|
68
68
|
*
|
|
69
69
|
* @param maxWords - The contract's calldata word capacity (the vault uses 2).
|
|
70
70
|
* @returns The calldata descriptor.
|
|
71
71
|
*/
|
|
72
|
-
export declare function evmCalldataDescriptor(maxWords: number): CompactType<
|
|
72
|
+
export declare function evmCalldataDescriptor(maxWords: number): CompactType<EvmCalldata>;
|
|
73
73
|
/**
|
|
74
|
-
* Descriptor of {@link
|
|
75
|
-
* (Compact: `
|
|
74
|
+
* Descriptor of {@link EvmAccessListEntry} at one storage-key capacity
|
|
75
|
+
* (Compact: `EvmAccessListEntry<#maxStorageKeys>`).
|
|
76
76
|
*
|
|
77
77
|
* @param maxStorageKeys - Storage-key capacity per entry.
|
|
78
78
|
* @returns The entry descriptor.
|
|
79
79
|
*/
|
|
80
|
-
export declare function evmAccessListEntryDescriptor(maxStorageKeys: number): CompactType<
|
|
80
|
+
export declare function evmAccessListEntryDescriptor(maxStorageKeys: number): CompactType<EvmAccessListEntry>;
|
|
81
81
|
/**
|
|
82
|
-
* Descriptor of {@link
|
|
83
|
-
* the TS analogue of Compact's `
|
|
82
|
+
* Descriptor of {@link EvmType2TxParams} at one capacity instantiation —
|
|
83
|
+
* the TS analogue of Compact's `EvmType2TxParams<#maxCalldataWords,
|
|
84
84
|
* #maxAccessListEntries, #maxStorageKeysPerEntry>`.
|
|
85
85
|
*
|
|
86
86
|
* @param maxCalldataWords - Calldata word capacity.
|
|
@@ -88,7 +88,7 @@ export declare function evmAccessListEntryDescriptor(maxStorageKeys: number): Co
|
|
|
88
88
|
* @param maxStorageKeysPerEntry - Storage-key capacity per entry.
|
|
89
89
|
* @returns The tx-params descriptor.
|
|
90
90
|
*/
|
|
91
|
-
export declare function evmType2TxParamsDescriptor(maxCalldataWords: number, maxAccessListEntries: number, maxStorageKeysPerEntry: number): CompactType<
|
|
91
|
+
export declare function evmType2TxParamsDescriptor(maxCalldataWords: number, maxAccessListEntries: number, maxStorageKeysPerEntry: number): CompactType<EvmType2TxParams>;
|
|
92
92
|
/**
|
|
93
93
|
* Descriptor of {@link SignBidirectionalEvent} at one EVM Type-2 capacity
|
|
94
94
|
* instantiation — the generic record descriptor
|
|
@@ -126,7 +126,8 @@ export declare function calculateRequestId(request: SignBidirectionalEvent): Req
|
|
|
126
126
|
* builders, tests).
|
|
127
127
|
*
|
|
128
128
|
* @param value - The word's numeric value (e.g. an amount).
|
|
129
|
-
* @returns The ABI-ready 32-byte word to store in an {@link
|
|
129
|
+
* @returns The ABI-ready 32-byte word to store in an {@link EvmCalldata} word.
|
|
130
|
+
* @throws Error if the value is negative or does not fit 32 bytes.
|
|
130
131
|
*/
|
|
131
132
|
export declare function numericAbiWord(value: bigint): Uint8Array;
|
|
132
133
|
/**
|
|
@@ -135,7 +136,7 @@ export declare function numericAbiWord(value: bigint): Uint8Array;
|
|
|
135
136
|
* `evmAddressAbiWord` circuit (lockstep-tested against the compiled circuit).
|
|
136
137
|
*
|
|
137
138
|
* @param address - The 20-byte address in display order.
|
|
138
|
-
* @returns The ABI-ready 32-byte word to store in an {@link
|
|
139
|
+
* @returns The ABI-ready 32-byte word to store in an {@link EvmCalldata} word.
|
|
139
140
|
* @throws Error if the address is not exactly 20 bytes.
|
|
140
141
|
*/
|
|
141
142
|
export declare function evmAddressAbiWord(address: Uint8Array): Uint8Array;
|
|
@@ -145,7 +146,7 @@ export declare function evmAddressAbiWord(address: Uint8Array): Uint8Array;
|
|
|
145
146
|
* (lockstep-tested against the compiled circuit).
|
|
146
147
|
*
|
|
147
148
|
* @param value - The word's Boolean value.
|
|
148
|
-
* @returns The ABI-ready 32-byte word to store in an {@link
|
|
149
|
+
* @returns The ABI-ready 32-byte word to store in an {@link EvmCalldata} word.
|
|
149
150
|
*/
|
|
150
151
|
export declare function boolAbiWord(value: boolean): Uint8Array;
|
|
151
152
|
/**
|
|
@@ -172,15 +173,15 @@ export declare function abiWordToBool(word: Uint8Array): boolean;
|
|
|
172
173
|
/**
|
|
173
174
|
* Assemble the raw calldata a request's words describe:
|
|
174
175
|
* `data = selector || words[0..noWords]`, VERBATIM. Words are stored
|
|
175
|
-
* ABI-ready (see {@link
|
|
176
|
+
* ABI-ready (see {@link EvmCalldata}), so no byte of the stored record is
|
|
176
177
|
* reordered or reinterpreted on the way into the transaction; slots past
|
|
177
178
|
* `noWords` are unused capacity and are dropped. This is THE implementation
|
|
178
|
-
* of the signer-side assembly documented on `
|
|
179
|
+
* of the signer-side assembly documented on `EvmCalldata` in Signet.compact.
|
|
179
180
|
*
|
|
180
181
|
* @param calldata - The request's calldata field.
|
|
181
182
|
* @returns Hex calldata for the transaction (`"0x"` when absent).
|
|
182
183
|
*/
|
|
183
|
-
export declare function assembleCalldata(calldata: Maybe<
|
|
184
|
+
export declare function assembleCalldata(calldata: Maybe<EvmCalldata>): string;
|
|
184
185
|
/**
|
|
185
186
|
* Rebuild the unsigned EIP-1559 transaction a request record describes,
|
|
186
187
|
* byte-identical to the one the MPC assembles and signs: calldata from the
|
|
@@ -196,25 +197,27 @@ export declare function assembleCalldata(calldata: Maybe<EVMCalldata>): string;
|
|
|
196
197
|
* MPC signs).
|
|
197
198
|
* @throws Error if a calldata word carries an unknown kind.
|
|
198
199
|
*/
|
|
199
|
-
export declare function
|
|
200
|
+
export declare function signBidirectionalEventToUnsignedEvmTransaction(request: SignBidirectionalEvent): Transaction;
|
|
200
201
|
/**
|
|
201
202
|
* Decode a response signature record (as posted to the signet contract's
|
|
202
|
-
* signature response log
|
|
203
|
-
*
|
|
204
|
-
*
|
|
203
|
+
* signature response log) into an ethers {@link Signature}. Goes through
|
|
204
|
+
* {@link mpcSignatureToEcdsaSignature} rather than reading the record's
|
|
205
|
+
* fields directly, so this and in-circuit claims decode a post identically:
|
|
206
|
+
* ethers' `r` is the ECDSA scalar (`bigR.x` reduced mod the curve order),
|
|
207
|
+
* not the raw coordinate, and a malformed record is rejected the same way
|
|
208
|
+
* in both paths.
|
|
205
209
|
*
|
|
206
210
|
* @param response - The posted signature record.
|
|
207
211
|
* @returns The ethers signature.
|
|
208
|
-
* @throws Error if the
|
|
212
|
+
* @throws Error if the record is malformed (see {@link mpcSignatureToEcdsaSignature}).
|
|
209
213
|
*/
|
|
210
214
|
export declare function signatureRespondedEventToSignature(response: SignatureRespondedEvent): Signature;
|
|
211
215
|
/**
|
|
212
216
|
* Encode an ECDSA signature as the response record posted to the signet
|
|
213
|
-
* contract — the inverse of {@link signatureRespondedEventToSignature},
|
|
214
|
-
*
|
|
215
|
-
* carries
|
|
216
|
-
*
|
|
217
|
-
* point on the curve (y² = x³ + 7 over the secp256k1 base field).
|
|
217
|
+
* contract — the inverse of {@link signatureRespondedEventToSignature}, for
|
|
218
|
+
* MPC-side posters (the fakenet signer, tests). An `r || s || v` signature
|
|
219
|
+
* carries only R.x and the parity of R.y, so the full R point the record
|
|
220
|
+
* stores is recovered on-curve (see {@link ecdsaSignatureToMpcSignature}).
|
|
218
221
|
*
|
|
219
222
|
* The parameter is structural (the r/s/yParity subset of an ethers
|
|
220
223
|
* {@link Signature}) so signatures from ANY ethers instance qualify — posters
|
|
@@ -223,13 +226,13 @@ export declare function signatureRespondedEventToSignature(response: SignatureRe
|
|
|
223
226
|
*
|
|
224
227
|
* @param signature - The signature to encode (`r`/`s` as 0x hex, `yParity` 0 or 1).
|
|
225
228
|
* @returns The response record, ready to post.
|
|
226
|
-
* @throws Error if `r` is not the x coordinate of a
|
|
229
|
+
* @throws Error if `r` is not the x coordinate of a secp256k1 point.
|
|
227
230
|
*/
|
|
228
231
|
export declare function signatureToSignatureRespondedEvent(signature: Pick<Signature, "r" | "s" | "yParity">): SignatureRespondedEvent;
|
|
229
232
|
/**
|
|
230
233
|
* Assemble the broadcast-ready signed EIP-1559 transaction for a request from
|
|
231
234
|
* its MPC signature response: rebuild the exact unsigned transaction the MPC
|
|
232
|
-
* signed (see {@link
|
|
235
|
+
* signed (see {@link signBidirectionalEventToUnsignedEvmTransaction}) and
|
|
233
236
|
* attach the signature. Does NOT check that the signature recovers to the
|
|
234
237
|
* requester's derived address — the response log is unauthenticated, so
|
|
235
238
|
* verify first with `verifySignatureRespondedEvent`.
|
|
@@ -240,8 +243,8 @@ export declare function signatureToSignatureRespondedEvent(signature: Pick<Signa
|
|
|
240
243
|
* `eth_sendRawTransaction`, `hash` its on-chain hash, `from` the recovered
|
|
241
244
|
* sender.
|
|
242
245
|
* @throws Error if the request record is malformed (see
|
|
243
|
-
* {@link
|
|
246
|
+
* {@link signBidirectionalEventToUnsignedEvmTransaction}) or the response
|
|
244
247
|
* is not a decodable signature.
|
|
245
248
|
*/
|
|
246
|
-
export declare function
|
|
249
|
+
export declare function signBidirectionalEventToSignedEvmTransaction(request: SignBidirectionalEvent, response: SignatureRespondedEvent): Transaction;
|
|
247
250
|
//# sourceMappingURL=signet-evtype2tx-requests.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signet-evtype2tx-requests.d.ts","sourceRoot":"","sources":["../src/signet-evtype2tx-requests.ts"],"names":[],"mappings":"AAYA,OAAO,EAKL,KAAK,WAAW,EACjB,MAAM,iCAAiC,CAAC;AACzC,OAAO,
|
|
1
|
+
{"version":3,"file":"signet-evtype2tx-requests.d.ts","sourceRoot":"","sources":["../src/signet-evtype2tx-requests.ts"],"names":[],"mappings":"AAYA,OAAO,EAKL,KAAK,WAAW,EACjB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAc,SAAS,EAAW,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAMjF,OAAO,EAKL,KAAK,KAAK,EACV,KAAK,SAAS,EACd,KAAK,sBAAsB,EAC5B,MAAM,sBAAsB,CAAC;AAE9B;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B,yDAAyD;IACzD,QAAQ,EAAE,UAAU,CAAC;IACrB,6EAA6E;IAC7E,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,KAAK,EAAE,UAAU,EAAE,C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ation of the signet request protocol:
|
|
2
|
-
// TypeScript twins of the `
|
|
2
|
+
// TypeScript twins of the `EvmType2TxParams` decomposition structs in
|
|
3
3
|
// `Signet.compact`, their runtime descriptors, the ABI-word helpers, and the
|
|
4
4
|
// request -> transaction assembly the signer runs. Everything chain-agnostic
|
|
5
5
|
// (the request record itself, ids, the descriptor toolkit) lives in
|
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
// The no-translation invariant lives here: words are stored ABI-ready and
|
|
10
10
|
// {@link assembleCalldata} concatenates `selector || words` VERBATIM, so the
|
|
11
11
|
// transaction the MPC signs carries the contract-stored bytes untouched.
|
|
12
|
-
import { CompactTypeBytes, CompactTypeUnsignedInteger, CompactTypeVector,
|
|
13
|
-
import { getAddress,
|
|
12
|
+
import { CompactTypeBytes, CompactTypeUnsignedInteger, CompactTypeVector, keccak256, } from "@midnight-ntwrk/compact-runtime";
|
|
13
|
+
import { getAddress, Signature, toBeHex, Transaction } from "ethers";
|
|
14
|
+
import { bigintToBytes32BE, ecdsaSignatureToMpcSignature, mpcSignatureToEcdsaSignature, } from "./ecdsa-attestation.js";
|
|
14
15
|
import { bytesToHex, compactMaybeDescriptor, compactStructDescriptor, signBidirectionalEventDescriptorWith, } from "./signet-requests.js";
|
|
15
16
|
// ---- Runtime descriptors (see the deviation note in signet-requests.ts) ----
|
|
16
17
|
// Base-type literals match what the compiler emits for the EVM structs'
|
|
@@ -23,8 +24,8 @@ const UINT_16 = new CompactTypeUnsignedInteger(2n ** 16n - 1n, 2);
|
|
|
23
24
|
const UINT_64 = new CompactTypeUnsignedInteger(2n ** 64n - 1n, 8);
|
|
24
25
|
const UINT_128 = new CompactTypeUnsignedInteger(2n ** 128n - 1n, 16);
|
|
25
26
|
/**
|
|
26
|
-
* Descriptor of {@link
|
|
27
|
-
* of instantiating Compact's `
|
|
27
|
+
* Descriptor of {@link EvmCalldata} at one word capacity — the TS analogue
|
|
28
|
+
* of instantiating Compact's `EvmCalldata<#maxWords>`.
|
|
28
29
|
*
|
|
29
30
|
* @param maxWords - The contract's calldata word capacity (the vault uses 2).
|
|
30
31
|
* @returns The calldata descriptor.
|
|
@@ -37,8 +38,8 @@ export function evmCalldataDescriptor(maxWords) {
|
|
|
37
38
|
});
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
40
|
-
* Descriptor of {@link
|
|
41
|
-
* (Compact: `
|
|
41
|
+
* Descriptor of {@link EvmAccessListEntry} at one storage-key capacity
|
|
42
|
+
* (Compact: `EvmAccessListEntry<#maxStorageKeys>`).
|
|
42
43
|
*
|
|
43
44
|
* @param maxStorageKeys - Storage-key capacity per entry.
|
|
44
45
|
* @returns The entry descriptor.
|
|
@@ -51,8 +52,8 @@ export function evmAccessListEntryDescriptor(maxStorageKeys) {
|
|
|
51
52
|
});
|
|
52
53
|
}
|
|
53
54
|
/**
|
|
54
|
-
* Descriptor of {@link
|
|
55
|
-
* the TS analogue of Compact's `
|
|
55
|
+
* Descriptor of {@link EvmType2TxParams} at one capacity instantiation —
|
|
56
|
+
* the TS analogue of Compact's `EvmType2TxParams<#maxCalldataWords,
|
|
56
57
|
* #maxAccessListEntries, #maxStorageKeysPerEntry>`.
|
|
57
58
|
*
|
|
58
59
|
* @param maxCalldataWords - Calldata word capacity.
|
|
@@ -61,17 +62,18 @@ export function evmAccessListEntryDescriptor(maxStorageKeys) {
|
|
|
61
62
|
* @returns The tx-params descriptor.
|
|
62
63
|
*/
|
|
63
64
|
export function evmType2TxParamsDescriptor(maxCalldataWords, maxAccessListEntries, maxStorageKeysPerEntry) {
|
|
65
|
+
// Key order IS the encoding order: keep it identical to the Compact struct's.
|
|
64
66
|
return compactStructDescriptor({
|
|
65
|
-
to: BYTES_20,
|
|
66
67
|
chainId: UINT_64,
|
|
67
68
|
nonce: UINT_64,
|
|
68
|
-
gasLimit: UINT_64,
|
|
69
|
-
maxFeePerGas: UINT_128,
|
|
70
69
|
maxPriorityFeePerGas: UINT_128,
|
|
70
|
+
maxFeePerGas: UINT_128,
|
|
71
|
+
gasLimit: UINT_64,
|
|
72
|
+
to: BYTES_20,
|
|
71
73
|
value: UINT_128,
|
|
74
|
+
calldata: compactMaybeDescriptor(evmCalldataDescriptor(maxCalldataWords)),
|
|
72
75
|
accessListEntryCount: UINT_8,
|
|
73
76
|
accessList: new CompactTypeVector(maxAccessListEntries, evmAccessListEntryDescriptor(maxStorageKeysPerEntry)),
|
|
74
|
-
calldata: compactMaybeDescriptor(evmCalldataDescriptor(maxCalldataWords)),
|
|
75
77
|
});
|
|
76
78
|
}
|
|
77
79
|
/**
|
|
@@ -109,7 +111,7 @@ export function calculateRequestId(request) {
|
|
|
109
111
|
const maxCalldataWords = txParams.calldata.value.words.length;
|
|
110
112
|
const maxAccessListEntries = txParams.accessList.length;
|
|
111
113
|
const maxStorageKeysPerEntry = maxAccessListEntries === 0 ? 0 : txParams.accessList[0].storageKeys.length;
|
|
112
|
-
return
|
|
114
|
+
return keccak256(signBidirectionalEventDescriptor(maxCalldataWords, maxAccessListEntries, maxStorageKeysPerEntry, request.outputDeserializationSchema.length, request.respondSerializationSchema.length), request);
|
|
113
115
|
}
|
|
114
116
|
// ---- ABI words / calldata / transaction assembly ---------------------------
|
|
115
117
|
/**
|
|
@@ -120,7 +122,8 @@ export function calculateRequestId(request) {
|
|
|
120
122
|
* builders, tests).
|
|
121
123
|
*
|
|
122
124
|
* @param value - The word's numeric value (e.g. an amount).
|
|
123
|
-
* @returns The ABI-ready 32-byte word to store in an {@link
|
|
125
|
+
* @returns The ABI-ready 32-byte word to store in an {@link EvmCalldata} word.
|
|
126
|
+
* @throws Error if the value is negative or does not fit 32 bytes.
|
|
124
127
|
*/
|
|
125
128
|
export function numericAbiWord(value) {
|
|
126
129
|
return bigintToBytes32BE(value);
|
|
@@ -131,7 +134,7 @@ export function numericAbiWord(value) {
|
|
|
131
134
|
* `evmAddressAbiWord` circuit (lockstep-tested against the compiled circuit).
|
|
132
135
|
*
|
|
133
136
|
* @param address - The 20-byte address in display order.
|
|
134
|
-
* @returns The ABI-ready 32-byte word to store in an {@link
|
|
137
|
+
* @returns The ABI-ready 32-byte word to store in an {@link EvmCalldata} word.
|
|
135
138
|
* @throws Error if the address is not exactly 20 bytes.
|
|
136
139
|
*/
|
|
137
140
|
export function evmAddressAbiWord(address) {
|
|
@@ -148,7 +151,7 @@ export function evmAddressAbiWord(address) {
|
|
|
148
151
|
* (lockstep-tested against the compiled circuit).
|
|
149
152
|
*
|
|
150
153
|
* @param value - The word's Boolean value.
|
|
151
|
-
* @returns The ABI-ready 32-byte word to store in an {@link
|
|
154
|
+
* @returns The ABI-ready 32-byte word to store in an {@link EvmCalldata} word.
|
|
152
155
|
*/
|
|
153
156
|
export function boolAbiWord(value) {
|
|
154
157
|
const word = new Uint8Array(32);
|
|
@@ -199,10 +202,10 @@ export function abiWordToBool(word) {
|
|
|
199
202
|
/**
|
|
200
203
|
* Assemble the raw calldata a request's words describe:
|
|
201
204
|
* `data = selector || words[0..noWords]`, VERBATIM. Words are stored
|
|
202
|
-
* ABI-ready (see {@link
|
|
205
|
+
* ABI-ready (see {@link EvmCalldata}), so no byte of the stored record is
|
|
203
206
|
* reordered or reinterpreted on the way into the transaction; slots past
|
|
204
207
|
* `noWords` are unused capacity and are dropped. This is THE implementation
|
|
205
|
-
* of the signer-side assembly documented on `
|
|
208
|
+
* of the signer-side assembly documented on `EvmCalldata` in Signet.compact.
|
|
206
209
|
*
|
|
207
210
|
* @param calldata - The request's calldata field.
|
|
208
211
|
* @returns Hex calldata for the transaction (`"0x"` when absent).
|
|
@@ -250,7 +253,7 @@ function decodeAccessList(txParams) {
|
|
|
250
253
|
* MPC signs).
|
|
251
254
|
* @throws Error if a calldata word carries an unknown kind.
|
|
252
255
|
*/
|
|
253
|
-
export function
|
|
256
|
+
export function signBidirectionalEventToUnsignedEvmTransaction(request) {
|
|
254
257
|
const { txParams } = request;
|
|
255
258
|
return Transaction.from({
|
|
256
259
|
type: 2,
|
|
@@ -267,57 +270,31 @@ export function signBidirectionalEventToUnsignedEVMTransaction(request) {
|
|
|
267
270
|
}
|
|
268
271
|
/**
|
|
269
272
|
* Decode a response signature record (as posted to the signet contract's
|
|
270
|
-
* signature response log
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
+
* signature response log) into an ethers {@link Signature}. Goes through
|
|
274
|
+
* {@link mpcSignatureToEcdsaSignature} rather than reading the record's
|
|
275
|
+
* fields directly, so this and in-circuit claims decode a post identically:
|
|
276
|
+
* ethers' `r` is the ECDSA scalar (`bigR.x` reduced mod the curve order),
|
|
277
|
+
* not the raw coordinate, and a malformed record is rejected the same way
|
|
278
|
+
* in both paths.
|
|
273
279
|
*
|
|
274
280
|
* @param response - The posted signature record.
|
|
275
281
|
* @returns The ethers signature.
|
|
276
|
-
* @throws Error if the
|
|
282
|
+
* @throws Error if the record is malformed (see {@link mpcSignatureToEcdsaSignature}).
|
|
277
283
|
*/
|
|
278
284
|
export function signatureRespondedEventToSignature(response) {
|
|
279
|
-
const recoveryId =
|
|
280
|
-
if (recoveryId !== 0 && recoveryId !== 1) {
|
|
281
|
-
throw new Error(`expected a recovery id of 0 or 1, got ${recoveryId}`);
|
|
282
|
-
}
|
|
285
|
+
const { r, s, recoveryId } = mpcSignatureToEcdsaSignature(response.signature);
|
|
283
286
|
return Signature.from({
|
|
284
|
-
r:
|
|
285
|
-
s:
|
|
287
|
+
r: toBeHex(r, 32),
|
|
288
|
+
s: toBeHex(s, 32),
|
|
286
289
|
v: recoveryId + 27,
|
|
287
290
|
});
|
|
288
291
|
}
|
|
289
|
-
/** secp256k1 base field prime (2^256 - 2^32 - 977). */
|
|
290
|
-
const SECP256K1_P = 2n ** 256n - 2n ** 32n - 977n;
|
|
291
|
-
/** Modular exponentiation by squaring. */
|
|
292
|
-
function modPow(base, exponent, modulus) {
|
|
293
|
-
let result = 1n;
|
|
294
|
-
let b = base % modulus;
|
|
295
|
-
let e = exponent;
|
|
296
|
-
while (e > 0n) {
|
|
297
|
-
if (e & 1n)
|
|
298
|
-
result = (result * b) % modulus;
|
|
299
|
-
b = (b * b) % modulus;
|
|
300
|
-
e >>= 1n;
|
|
301
|
-
}
|
|
302
|
-
return result;
|
|
303
|
-
}
|
|
304
|
-
/** Encode a bigint as exactly 32 BIG-endian bytes (secp256k1 scalar form). */
|
|
305
|
-
function bigintToBytes32BE(value) {
|
|
306
|
-
const out = new Uint8Array(32);
|
|
307
|
-
let v = value;
|
|
308
|
-
for (let i = 31; i >= 0; i--) {
|
|
309
|
-
out[i] = Number(v & 0xffn);
|
|
310
|
-
v >>= 8n;
|
|
311
|
-
}
|
|
312
|
-
return out;
|
|
313
|
-
}
|
|
314
292
|
/**
|
|
315
293
|
* Encode an ECDSA signature as the response record posted to the signet
|
|
316
|
-
* contract — the inverse of {@link signatureRespondedEventToSignature},
|
|
317
|
-
*
|
|
318
|
-
* carries
|
|
319
|
-
*
|
|
320
|
-
* point on the curve (y² = x³ + 7 over the secp256k1 base field).
|
|
294
|
+
* contract — the inverse of {@link signatureRespondedEventToSignature}, for
|
|
295
|
+
* MPC-side posters (the fakenet signer, tests). An `r || s || v` signature
|
|
296
|
+
* carries only R.x and the parity of R.y, so the full R point the record
|
|
297
|
+
* stores is recovered on-curve (see {@link ecdsaSignatureToMpcSignature}).
|
|
321
298
|
*
|
|
322
299
|
* The parameter is structural (the r/s/yParity subset of an ethers
|
|
323
300
|
* {@link Signature}) so signatures from ANY ethers instance qualify — posters
|
|
@@ -326,30 +303,21 @@ function bigintToBytes32BE(value) {
|
|
|
326
303
|
*
|
|
327
304
|
* @param signature - The signature to encode (`r`/`s` as 0x hex, `yParity` 0 or 1).
|
|
328
305
|
* @returns The response record, ready to post.
|
|
329
|
-
* @throws Error if `r` is not the x coordinate of a
|
|
306
|
+
* @throws Error if `r` is not the x coordinate of a secp256k1 point.
|
|
330
307
|
*/
|
|
331
308
|
export function signatureToSignatureRespondedEvent(signature) {
|
|
332
|
-
const x = BigInt(signature.r);
|
|
333
|
-
const ySquared = (modPow(x, 3n, SECP256K1_P) + 7n) % SECP256K1_P;
|
|
334
|
-
// P ≡ 3 (mod 4), so a square root (when one exists) is c^((P+1)/4).
|
|
335
|
-
let y = modPow(ySquared, (SECP256K1_P + 1n) / 4n, SECP256K1_P);
|
|
336
|
-
if ((y * y) % SECP256K1_P !== ySquared) {
|
|
337
|
-
throw new Error("signature r is not the x coordinate of a secp256k1 point");
|
|
338
|
-
}
|
|
339
|
-
if ((y & 1n) !== BigInt(signature.yParity)) {
|
|
340
|
-
y = SECP256K1_P - y;
|
|
341
|
-
}
|
|
342
309
|
return {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
310
|
+
signature: ecdsaSignatureToMpcSignature({
|
|
311
|
+
r: BigInt(signature.r),
|
|
312
|
+
s: BigInt(signature.s),
|
|
313
|
+
recoveryId: signature.yParity,
|
|
314
|
+
}),
|
|
347
315
|
};
|
|
348
316
|
}
|
|
349
317
|
/**
|
|
350
318
|
* Assemble the broadcast-ready signed EIP-1559 transaction for a request from
|
|
351
319
|
* its MPC signature response: rebuild the exact unsigned transaction the MPC
|
|
352
|
-
* signed (see {@link
|
|
320
|
+
* signed (see {@link signBidirectionalEventToUnsignedEvmTransaction}) and
|
|
353
321
|
* attach the signature. Does NOT check that the signature recovers to the
|
|
354
322
|
* requester's derived address — the response log is unauthenticated, so
|
|
355
323
|
* verify first with `verifySignatureRespondedEvent`.
|
|
@@ -360,11 +328,11 @@ export function signatureToSignatureRespondedEvent(signature) {
|
|
|
360
328
|
* `eth_sendRawTransaction`, `hash` its on-chain hash, `from` the recovered
|
|
361
329
|
* sender.
|
|
362
330
|
* @throws Error if the request record is malformed (see
|
|
363
|
-
* {@link
|
|
331
|
+
* {@link signBidirectionalEventToUnsignedEvmTransaction}) or the response
|
|
364
332
|
* is not a decodable signature.
|
|
365
333
|
*/
|
|
366
|
-
export function
|
|
367
|
-
const transaction =
|
|
334
|
+
export function signBidirectionalEventToSignedEvmTransaction(request, response) {
|
|
335
|
+
const transaction = signBidirectionalEventToUnsignedEvmTransaction(request);
|
|
368
336
|
transaction.signature = signatureRespondedEventToSignature(response);
|
|
369
337
|
return transaction;
|
|
370
338
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signet-evtype2tx-requests.js","sourceRoot":"","sources":["../src/signet-evtype2tx-requests.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,sEAAsE;AACtE,6EAA6E;AAC7E,6EAA6E;AAC7E,oEAAoE;AACpE,8EAA8E;AAC9E,QAAQ;AACR,EAAE;AACF,0EAA0E;AAC1E,6EAA6E;AAC7E,yEAAyE;AAEzE,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,iBAAiB,EACjB,
|
|
1
|
+
{"version":3,"file":"signet-evtype2tx-requests.js","sourceRoot":"","sources":["../src/signet-evtype2tx-requests.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,sEAAsE;AACtE,6EAA6E;AAC7E,6EAA6E;AAC7E,oEAAoE;AACpE,8EAA8E;AAC9E,QAAQ;AACR,EAAE;AACF,0EAA0E;AAC1E,6EAA6E;AAC7E,yEAAyE;AAEzE,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,iBAAiB,EACjB,SAAS,GAEV,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAGrE,OAAO,EACL,iBAAiB,EACjB,4BAA4B,EAC5B,4BAA4B,GAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,UAAU,EACV,sBAAsB,EACtB,uBAAuB,EACvB,oCAAoC,GAIrC,MAAM,sBAAsB,CAAC;AAiE9B,+EAA+E;AAC/E,wEAAwE;AACxE,8CAA8C;AAC9C,MAAM,OAAO,GAAG,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAAC;AACxC,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC,EAAE,CAAC,CAAC;AAC1C,MAAM,QAA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E,EAAE,CAAC;QACjB,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC;QACjB,CAAC,EAAE,UAAU,GAAG,EAAE;KACnB,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,kCAAkC,CAChD,SAAiD;IAEjD,OAAO;QACL,SAAS,EAAE,4BAA4B,CAAC;YACtC,CAAC,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;YACtB,CAAC,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;YACtB,UAAU,EAAE,SAAS,CAAC,OAAO;SAC9B,CAAC;KACH,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,4CAA4C,CAC1D,OAA+B,EAC/B,QAAiC;IAEjC,MAAM,WAAW,GAAG,8CAA8C,CAAC,OAAO,CAAC,CAAC;IAC5E,WAAW,CAAC,SAAS,GAAG,kCAAkC,CAAC,QAAQ,CAAC,CAAC;IACrE,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -107,7 +107,7 @@ export declare class SignetRequestResponseReader {
|
|
|
107
107
|
getSignatureResponses(requestId: RequestIdHex): Promise<SignatureRespondedEvent[]>;
|
|
108
108
|
/**
|
|
109
109
|
* Fetch and verify the responses posted for `requestId`: each post's
|
|
110
|
-
*
|
|
110
|
+
* signature must recover to `expectedSigner`
|
|
111
111
|
* (compared case-insensitively) over the signing hash of the transaction
|
|
112
112
|
* the request record describes. The first valid post wins; every post gets
|
|
113
113
|
* a verdict so callers can report the noise.
|
|
@@ -132,7 +132,7 @@ export declare class SignetRequestResponseReader {
|
|
|
132
132
|
* @throws Error when the requester contract has no state or holds no
|
|
133
133
|
* request under `requestId`.
|
|
134
134
|
*/
|
|
135
|
-
|
|
135
|
+
getUnsignedEvmTransaction(requestId: RequestIdHex): Promise<Transaction>;
|
|
136
136
|
/**
|
|
137
137
|
* Assemble the broadcast-ready signed EIP-1559 transaction for `requestId`:
|
|
138
138
|
* rebuild the request's transaction and attach the first VERIFIED response
|
|
@@ -149,7 +149,7 @@ export declare class SignetRequestResponseReader {
|
|
|
149
149
|
* @throws Error when either contract has no state, the request is not on the
|
|
150
150
|
* requester's ledger, or the responses ledger is inconsistent.
|
|
151
151
|
*/
|
|
152
|
-
|
|
152
|
+
getSignedEvmTransaction(requestId: RequestIdHex, expectedSigner: string): Promise<Transaction | undefined>;
|
|
153
153
|
/**
|
|
154
154
|
* Fetch every respond-bidirectional response posted for `requestId`, in
|
|
155
155
|
* post (count) order. UNVERIFIED — the signet contract stores posts without
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
import { lookupSignetRequestAt } from "./signature-requests-state-reader.js";
|
|
12
12
|
import { readSignetContractLedgerFromState, signetMapEntryKey, } from "./signet-contract-state-reader.js";
|
|
13
13
|
import { recoverSignatureResponseSigner } from "./signature-response-verification.js";
|
|
14
|
-
import {
|
|
14
|
+
import { signBidirectionalEventToSignedEvmTransaction, signBidirectionalEventToUnsignedEvmTransaction, } from "./signet-evtype2tx-requests.js";
|
|
15
15
|
/**
|
|
16
16
|
* Reader over one requester contract / signet contract pair.
|
|
17
17
|
* Construct once per pair and reuse: fetched request records are cached (they
|
|
@@ -79,11 +79,11 @@ export class SignetRequestResponseReader {
|
|
|
79
79
|
*/
|
|
80
80
|
async getSignatureResponses(requestId) {
|
|
81
81
|
const raw = await this.queryRawState(this.config.signetContractAddress, "signet contract");
|
|
82
|
-
const {
|
|
83
|
-
const totalPosts =
|
|
82
|
+
const { respondCounterMap, respondMap } = readSignetContractLedgerFromState(raw);
|
|
83
|
+
const totalPosts = respondCounterMap.get(requestId) ?? 0n;
|
|
84
84
|
const responses = [];
|
|
85
85
|
for (let count = 0n; count < totalPosts; count++) {
|
|
86
|
-
const response =
|
|
86
|
+
const response = respondMap.get(signetMapEntryKey(requestId, count));
|
|
87
87
|
if (response === undefined) {
|
|
88
88
|
throw new Error(`response log has no entry ${count} for request ${requestId} ` +
|
|
89
89
|
`despite its counter reading ${totalPosts} — ledger state is inconsistent`);
|
|
@@ -94,7 +94,7 @@ export class SignetRequestResponseReader {
|
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
96
|
* Fetch and verify the responses posted for `requestId`: each post's
|
|
97
|
-
*
|
|
97
|
+
* signature must recover to `expectedSigner`
|
|
98
98
|
* (compared case-insensitively) over the signing hash of the transaction
|
|
99
99
|
* the request record describes. The first valid post wins; every post gets
|
|
100
100
|
* a verdict so callers can report the noise.
|
|
@@ -149,8 +149,8 @@ export class SignetRequestResponseReader {
|
|
|
149
149
|
* @throws Error when the requester contract has no state or holds no
|
|
150
150
|
* request under `requestId`.
|
|
151
151
|
*/
|
|
152
|
-
async
|
|
153
|
-
return
|
|
152
|
+
async getUnsignedEvmTransaction(requestId) {
|
|
153
|
+
return signBidirectionalEventToUnsignedEvmTransaction(await this.getSignatureRequest(requestId));
|
|
154
154
|
}
|
|
155
155
|
/**
|
|
156
156
|
* Assemble the broadcast-ready signed EIP-1559 transaction for `requestId`:
|
|
@@ -168,7 +168,7 @@ export class SignetRequestResponseReader {
|
|
|
168
168
|
* @throws Error when either contract has no state, the request is not on the
|
|
169
169
|
* requester's ledger, or the responses ledger is inconsistent.
|
|
170
170
|
*/
|
|
171
|
-
async
|
|
171
|
+
async getSignedEvmTransaction(requestId, expectedSigner) {
|
|
172
172
|
const { verified } = await this.getVerifiedSignatureRespondedEvent(requestId, expectedSigner);
|
|
173
173
|
if (verified === undefined) {
|
|
174
174
|
return undefined;
|
|
@@ -176,7 +176,7 @@ export class SignetRequestResponseReader {
|
|
|
176
176
|
// getSignatureRequest is cached — getVerifiedSignatureRespondedEvent already
|
|
177
177
|
// fetched it, so this is a free lookup, not a second query.
|
|
178
178
|
const request = await this.getSignatureRequest(requestId);
|
|
179
|
-
return
|
|
179
|
+
return signBidirectionalEventToSignedEvmTransaction(request, verified);
|
|
180
180
|
}
|
|
181
181
|
/**
|
|
182
182
|
* Fetch every respond-bidirectional response posted for `requestId`, in
|