@sig-net/midnight 0.18.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 +13 -4
- 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,13 +1,13 @@
|
|
|
1
1
|
import { type CompactType } from "@midnight-ntwrk/compact-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { Transaction } from "ethers";
|
|
3
|
+
import { type Maybe } from "./compact-descriptors.ts";
|
|
3
4
|
import type { SignatureRespondedEvent } from "./signet-contract-events.ts";
|
|
4
|
-
import { type
|
|
5
|
+
import { type SignBidirectionalEvent } from "./signet-requests.ts";
|
|
5
6
|
/**
|
|
6
7
|
* ABI calldata as a 4-byte selector + 32-byte word slots (Compact:
|
|
7
|
-
* `EvmCalldata<#maxWords>`). Every stored byte is ABI-READY:
|
|
8
|
-
*
|
|
9
|
-
* {@link assembleCalldata})
|
|
10
|
-
* built in-circuit by Signet.compact's `evmAddressAbiWord` / `numericAbiWord`.
|
|
8
|
+
* `EvmCalldata<#maxWords>`). Every stored byte is ABI-READY: words are
|
|
9
|
+
* big-endian broadcast-form ABI words, and the calldata the MPC signs is
|
|
10
|
+
* `selector || words[0..noWords]` VERBATIM (see {@link assembleCalldata}).
|
|
11
11
|
*/
|
|
12
12
|
export interface EvmCalldata {
|
|
13
13
|
/** The literal first 4 calldata bytes (as broadcast). */
|
|
@@ -35,10 +35,10 @@ export interface EvmAccessListEntry {
|
|
|
35
35
|
/**
|
|
36
36
|
* The EVM transaction to be signed, decomposed into typed fields (Compact:
|
|
37
37
|
* `EvmType2TxParams<#maxCalldataWords, #maxAccessListEntries,
|
|
38
|
-
* #maxStorageKeysPerEntry>`, EIP-1559
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
38
|
+
* #maxStorageKeysPerEntry>`, EIP-1559). Compact `Bytes<N>` fields arrive as
|
|
39
|
+
* N-byte `Uint8Array`s, `Uint<N>` as `bigint`. Vector capacities are each
|
|
40
|
+
* contract's compile-time throttle, and the runtime counts say how many
|
|
41
|
+
* leading slots are real.
|
|
42
42
|
*/
|
|
43
43
|
export interface EvmType2TxParams {
|
|
44
44
|
/** EVM chain id (also expressed in the record's `caip2Id`). */
|
|
@@ -89,11 +89,20 @@ export declare function evmAccessListEntryDescriptor(maxStorageKeys: number): Co
|
|
|
89
89
|
* @returns The tx-params descriptor.
|
|
90
90
|
*/
|
|
91
91
|
export declare function evmType2TxParamsDescriptor(maxCalldataWords: number, maxAccessListEntries: number, maxStorageKeysPerEntry: number): CompactType<EvmType2TxParams>;
|
|
92
|
+
/**
|
|
93
|
+
* Descriptor of {@link EvmType2TxParams} at the capacity instantiation a
|
|
94
|
+
* stored value itself exhibits: vector capacities are read off the value's
|
|
95
|
+
* array lengths, which carry the contract's compile-time throttles. For
|
|
96
|
+
* hashing or re-encoding a record already decoded at full capacity (see
|
|
97
|
+
* `calculateRequestId` in signet-request-id.ts).
|
|
98
|
+
*
|
|
99
|
+
* @param txParams - The transaction decomposition to size against.
|
|
100
|
+
* @returns The tx-params descriptor at the value's capacities.
|
|
101
|
+
*/
|
|
102
|
+
export declare function evmType2TxParamsDescriptorOf(txParams: EvmType2TxParams): CompactType<EvmType2TxParams>;
|
|
92
103
|
/**
|
|
93
104
|
* Descriptor of {@link SignBidirectionalEvent} at one EVM Type-2 capacity
|
|
94
|
-
* instantiation
|
|
95
|
-
* (`signBidirectionalEventDescriptorWith`) over
|
|
96
|
-
* {@link evmType2TxParamsDescriptor}.
|
|
105
|
+
* instantiation.
|
|
97
106
|
*
|
|
98
107
|
* @param maxCalldataWords - Calldata word capacity.
|
|
99
108
|
* @param maxAccessListEntries - Access-list entry capacity.
|
|
@@ -106,28 +115,14 @@ export declare function evmType2TxParamsDescriptor(maxCalldataWords: number, max
|
|
|
106
115
|
*/
|
|
107
116
|
export declare function signBidirectionalEventDescriptor(maxCalldataWords: number, maxAccessListEntries: number, maxStorageKeysPerEntry: number, lenOutputDeserialization: number, lenRespondSerialization: number): CompactType<SignBidirectionalEvent>;
|
|
108
117
|
/**
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
* signet-requests.ts), generic over the capacity instantiation via the
|
|
114
|
-
* record's own array lengths: pass the record exactly as the ledger stores
|
|
115
|
-
* it, unused slots included and schemas at their declared widths.
|
|
116
|
-
*
|
|
117
|
-
* @param request - The full event record (contract-shaped, all slots).
|
|
118
|
-
* @returns The 32-byte request id, the record's ledger map key.
|
|
119
|
-
*/
|
|
120
|
-
export declare function calculateRequestId(request: SignBidirectionalEvent): RequestId;
|
|
121
|
-
/**
|
|
122
|
-
* The ABI word for a numeric value (e.g. an ERC20 amount): the value as a
|
|
123
|
-
* 32-byte BIG-ENDIAN integer, exactly as broadcast. TS mirror of
|
|
124
|
-
* Signet.compact's `numericAbiWord` circuit (lockstep-tested against the
|
|
125
|
-
* compiled circuit). Use when building words off-chain (UIs, expected-record
|
|
126
|
-
* builders, tests).
|
|
118
|
+
* The ABI word for a numeric value: the value as a 32-byte BIG-ENDIAN
|
|
119
|
+
* integer, exactly as broadcast. TS mirror of Signet.compact's
|
|
120
|
+
* `numericAbiWord` circuit (lockstep-tested against the compiled circuit).
|
|
121
|
+
* For off-chain word builders (UIs, expected-record builders, tests).
|
|
127
122
|
*
|
|
128
123
|
* @param value - The word's numeric value (e.g. an amount).
|
|
129
124
|
* @returns The ABI-ready 32-byte word to store in an {@link EvmCalldata} word.
|
|
130
|
-
* @throws Error
|
|
125
|
+
* @throws {Error} If the value is negative or does not fit 32 bytes.
|
|
131
126
|
*/
|
|
132
127
|
export declare function numericAbiWord(value: bigint): Uint8Array;
|
|
133
128
|
/**
|
|
@@ -137,7 +132,7 @@ export declare function numericAbiWord(value: bigint): Uint8Array;
|
|
|
137
132
|
*
|
|
138
133
|
* @param address - The 20-byte address in display order.
|
|
139
134
|
* @returns The ABI-ready 32-byte word to store in an {@link EvmCalldata} word.
|
|
140
|
-
* @throws Error
|
|
135
|
+
* @throws {Error} If the address is not exactly 20 bytes.
|
|
141
136
|
*/
|
|
142
137
|
export declare function evmAddressAbiWord(address: Uint8Array): Uint8Array;
|
|
143
138
|
/**
|
|
@@ -146,37 +141,33 @@ export declare function evmAddressAbiWord(address: Uint8Array): Uint8Array;
|
|
|
146
141
|
* (lockstep-tested against the compiled circuit).
|
|
147
142
|
*
|
|
148
143
|
* @param value - The word's Boolean value.
|
|
149
|
-
* @returns The ABI-ready 32-byte word
|
|
144
|
+
* @returns The ABI-ready 32-byte word.
|
|
150
145
|
*/
|
|
151
146
|
export declare function boolAbiWord(value: boolean): Uint8Array;
|
|
152
147
|
/**
|
|
153
148
|
* Read a numeric ABI word back into a bigint: the big-endian reading of bytes
|
|
154
|
-
* 16..31
|
|
155
|
-
*
|
|
156
|
-
* than Uint<128> is rejected rather than silently truncated.
|
|
149
|
+
* 16..31, with the leading 16 bytes required to be zero. TS mirror of
|
|
150
|
+
* Signet.compact's `abiWordToUint128` circuit, canonicality check included.
|
|
157
151
|
*
|
|
158
152
|
* @param word - The ABI-ready 32-byte word.
|
|
159
153
|
* @returns The word's numeric value.
|
|
160
|
-
* @throws Error
|
|
154
|
+
* @throws {Error} If the word is not 32 bytes or its leading half is nonzero.
|
|
161
155
|
*/
|
|
162
156
|
export declare function abiWordToUint128(word: Uint8Array): bigint;
|
|
163
157
|
/**
|
|
164
|
-
* Read a Boolean ABI word back into a boolean
|
|
165
|
-
*
|
|
166
|
-
*
|
|
158
|
+
* Read a Boolean ABI word back into a boolean: the first 31 bytes must be
|
|
159
|
+
* zero and the last byte 0 or 1. TS mirror of Signet.compact's
|
|
160
|
+
* `abiWordToBool` circuit, canonicality check included.
|
|
167
161
|
*
|
|
168
162
|
* @param word - The ABI-ready 32-byte word.
|
|
169
163
|
* @returns The word's Boolean value.
|
|
170
|
-
* @throws Error
|
|
164
|
+
* @throws {Error} If the word is not 32 bytes or is not a canonical Boolean.
|
|
171
165
|
*/
|
|
172
166
|
export declare function abiWordToBool(word: Uint8Array): boolean;
|
|
173
167
|
/**
|
|
174
168
|
* Assemble the raw calldata a request's words describe:
|
|
175
|
-
* `data = selector || words[0..noWords]`, VERBATIM
|
|
176
|
-
*
|
|
177
|
-
* reordered or reinterpreted on the way into the transaction. Slots past
|
|
178
|
-
* `noWords` are unused capacity and are dropped. This is THE implementation
|
|
179
|
-
* of the signer-side assembly documented on `EvmCalldata` in Signet.compact.
|
|
169
|
+
* `data = selector || words[0..noWords]`, VERBATIM (see {@link EvmCalldata}).
|
|
170
|
+
* Slots past `noWords` are unused capacity and are dropped.
|
|
180
171
|
*
|
|
181
172
|
* @param calldata - The request's calldata field.
|
|
182
173
|
* @returns Hex calldata for the transaction (`"0x"` when absent).
|
|
@@ -184,51 +175,16 @@ export declare function abiWordToBool(word: Uint8Array): boolean;
|
|
|
184
175
|
export declare function assembleCalldata(calldata: Maybe<EvmCalldata>): string;
|
|
185
176
|
/**
|
|
186
177
|
* Rebuild the unsigned EIP-1559 transaction a request record describes,
|
|
187
|
-
* byte-identical to the one the MPC assembles and signs
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
* request→transaction transform. Response-side verification
|
|
191
|
-
* (`signature-response-verification.ts`) and the signed-transaction builder
|
|
192
|
-
* below both go through it, so the transaction a client broadcasts is
|
|
193
|
-
* provably the one the MPC put its signature over.
|
|
178
|
+
* byte-identical to the one the MPC assembles and signs. The canonical
|
|
179
|
+
* request-to-transaction transform: response-side verification and
|
|
180
|
+
* {@link signBidirectionalEventToSignedEvmTransaction} both go through it.
|
|
194
181
|
*
|
|
195
182
|
* @param request - The on-ledger request record.
|
|
196
183
|
* @returns The unsigned ethers transaction (`unsignedHash` is the digest the
|
|
197
184
|
* MPC signs).
|
|
198
|
-
* @throws Error
|
|
185
|
+
* @throws {Error} If a calldata word carries an unknown kind.
|
|
199
186
|
*/
|
|
200
187
|
export declare function signBidirectionalEventToUnsignedEvmTransaction(request: SignBidirectionalEvent): Transaction;
|
|
201
|
-
/**
|
|
202
|
-
* Decode a response signature record (as the signet contract emits it in a
|
|
203
|
-
* signature response event) into an ethers {@link Signature}. Goes through
|
|
204
|
-
* {@link mpcSignatureToEcdsaSignature}, so this and in-circuit claims decode
|
|
205
|
-
* 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.
|
|
209
|
-
*
|
|
210
|
-
* @param response - The posted signature record.
|
|
211
|
-
* @returns The ethers signature.
|
|
212
|
-
* @throws Error if the record is malformed (see {@link mpcSignatureToEcdsaSignature}).
|
|
213
|
-
*/
|
|
214
|
-
export declare function signatureRespondedEventToSignature(response: SignatureRespondedEvent): Signature;
|
|
215
|
-
/**
|
|
216
|
-
* Encode an ECDSA signature as the response record posted to the signet
|
|
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}).
|
|
221
|
-
*
|
|
222
|
-
* The parameter is structural (the r/s/yParity subset of an ethers
|
|
223
|
-
* {@link Signature}) so signatures from ANY ethers instance qualify: posters
|
|
224
|
-
* living in other repos resolve their own ethers install, and nominal class
|
|
225
|
-
* typing would reject it.
|
|
226
|
-
*
|
|
227
|
-
* @param signature - The signature to encode (`r`/`s` as 0x hex, `yParity` 0 or 1).
|
|
228
|
-
* @returns The response record, ready to post.
|
|
229
|
-
* @throws Error if `r` is not the x coordinate of a secp256k1 point.
|
|
230
|
-
*/
|
|
231
|
-
export declare function signatureToSignatureRespondedEvent(signature: Pick<Signature, "r" | "s" | "yParity">): SignatureRespondedEvent;
|
|
232
188
|
/**
|
|
233
189
|
* Assemble the broadcast-ready signed EIP-1559 transaction for a request from
|
|
234
190
|
* its MPC signature response: rebuild the exact unsigned transaction the MPC
|
|
@@ -242,7 +198,7 @@ export declare function signatureToSignatureRespondedEvent(signature: Pick<Signa
|
|
|
242
198
|
* @returns The signed ethers transaction: `serialized` is the raw payload for
|
|
243
199
|
* `eth_sendRawTransaction`, `hash` its on-chain hash, `from` the recovered
|
|
244
200
|
* sender.
|
|
245
|
-
* @throws Error
|
|
201
|
+
* @throws {Error} If the request record is malformed (see
|
|
246
202
|
* {@link signBidirectionalEventToUnsignedEvmTransaction}) or the response
|
|
247
203
|
* is not a decodable signature.
|
|
248
204
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signet-evtype2tx-requests.d.ts","sourceRoot":"","sources":["../src/signet-evtype2tx-requests.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"signet-evtype2tx-requests.d.ts","sourceRoot":"","sources":["../src/signet-evtype2tx-requests.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,WAAW,EAAqB,MAAM,iCAAiC,CAAC;AACtF,OAAO,EAAc,WAAW,EAAE,MAAM,QAAQ,CAAC;AAGjD,OAAO,EAML,KAAK,KAAK,EAKX,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EACL,KAAK,sBAAsB,EAE5B,MAAM,sBAAsB,CAAC;AAE9B;;;;;GAKG;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,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,iEAAiE;IACjE,OAAO,EAAE,UAAU,CAAC;IACpB,qDAAqD;IACrD,eAAe,EAAE,MAAM,CAAC;IACxB,sEAAsE;IACtE,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAC/B,+DAA+D;IAC/D,OAAO,EAAE,MAAM,CAAC;IAChB,uDAAuD;IACvD,KAAK,EAAE,MAAM,CAAC;IACd,qCAAqC;IACr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G,UAAU,CAOjE;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAItD;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAYzD;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CASvD;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,KAAK,CAAC,WAAW,CAAC,GAAG,MAAM,CAUrE;AAoBD;;;;;;;;;;GAUG;AACH,wBAAgB,8CAA8C,CAC5D,OAAO,EAAE,sBAAsB,GAC9B,WAAW,CAcb;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,4CAA4C,CAC1D,OAAO,EAAE,sBAAsB,EAC/B,QAAQ,EAAE,uBAAuB,GAChC,WAAW,CAIb"}
|
|
@@ -1,28 +1,21 @@
|
|
|
1
1
|
// The EVM Type-2 (EIP-1559) instantiation of the signet request protocol:
|
|
2
2
|
// TypeScript twins of the `EvmType2TxParams` decomposition structs in
|
|
3
3
|
// `Signet.compact`, their runtime descriptors, the ABI-word helpers, and the
|
|
4
|
-
// request -> transaction assembly
|
|
5
|
-
//
|
|
6
|
-
// `signet-requests.ts`. A future non-EVM decomposition gets a sibling of THIS
|
|
7
|
-
// file.
|
|
4
|
+
// request -> transaction assembly. Everything chain-agnostic lives in
|
|
5
|
+
// `signet-requests.ts`.
|
|
8
6
|
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
import {
|
|
13
|
-
import { getAddress,
|
|
14
|
-
import { bigintToBytes32BE,
|
|
15
|
-
import {
|
|
7
|
+
// Words are stored ABI-ready: {@link assembleCalldata} concatenates
|
|
8
|
+
// `selector || words` VERBATIM, so the transaction the MPC signs carries the
|
|
9
|
+
// contract-stored bytes untouched.
|
|
10
|
+
import { CompactTypeVector } from "@midnight-ntwrk/compact-runtime";
|
|
11
|
+
import { getAddress, Transaction } from "ethers";
|
|
12
|
+
import { bigintToBytes32BE, bytesToHex } from "./byte-codecs.js";
|
|
13
|
+
import { BYTES_4, BYTES_20, BYTES_32, compactMaybeDescriptor, compactStructDescriptor, UINT_8, UINT_16, UINT_64, UINT_128, } from "./compact-descriptors.js";
|
|
14
|
+
import { signatureRespondedEventToSignature } from "./ecdsa-attestation.js";
|
|
15
|
+
import { signBidirectionalEventDescriptorWith, } from "./signet-requests.js";
|
|
16
16
|
// ---- Runtime descriptors (see the deviation note in signet-requests.ts) ----
|
|
17
|
-
// Base-type
|
|
18
|
-
// fields (Uint<8/16/64/128>, Bytes<4/20/32>).
|
|
19
|
-
const BYTES_4 = new CompactTypeBytes(4);
|
|
20
|
-
const BYTES_20 = new CompactTypeBytes(20);
|
|
21
|
-
const BYTES_32 = new CompactTypeBytes(32);
|
|
22
|
-
const UINT_8 = new CompactTypeUnsignedInteger(2n ** 8n - 1n, 1);
|
|
23
|
-
const UINT_16 = new CompactTypeUnsignedInteger(2n ** 16n - 1n, 2);
|
|
24
|
-
const UINT_64 = new CompactTypeUnsignedInteger(2n ** 64n - 1n, 8);
|
|
25
|
-
const UINT_128 = new CompactTypeUnsignedInteger(2n ** 128n - 1n, 16);
|
|
17
|
+
// Base-type descriptors come from compact-descriptors.ts at the literals the
|
|
18
|
+
// compiler emits for the EVM structs' fields (Uint<8/16/64/128>, Bytes<4/20/32>).
|
|
26
19
|
/**
|
|
27
20
|
* Descriptor of {@link EvmCalldata} at one word capacity: the TS analogue
|
|
28
21
|
* of instantiating Compact's `EvmCalldata<#maxWords>`.
|
|
@@ -76,11 +69,22 @@ export function evmType2TxParamsDescriptor(maxCalldataWords, maxAccessListEntrie
|
|
|
76
69
|
accessList: new CompactTypeVector(maxAccessListEntries, evmAccessListEntryDescriptor(maxStorageKeysPerEntry)),
|
|
77
70
|
});
|
|
78
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Descriptor of {@link EvmType2TxParams} at the capacity instantiation a
|
|
74
|
+
* stored value itself exhibits: vector capacities are read off the value's
|
|
75
|
+
* array lengths, which carry the contract's compile-time throttles. For
|
|
76
|
+
* hashing or re-encoding a record already decoded at full capacity (see
|
|
77
|
+
* `calculateRequestId` in signet-request-id.ts).
|
|
78
|
+
*
|
|
79
|
+
* @param txParams - The transaction decomposition to size against.
|
|
80
|
+
* @returns The tx-params descriptor at the value's capacities.
|
|
81
|
+
*/
|
|
82
|
+
export function evmType2TxParamsDescriptorOf(txParams) {
|
|
83
|
+
return evmType2TxParamsDescriptor(txParams.calldata.value.words.length, txParams.accessList.length, txParams.accessList[0]?.storageKeys.length ?? 0);
|
|
84
|
+
}
|
|
79
85
|
/**
|
|
80
86
|
* Descriptor of {@link SignBidirectionalEvent} at one EVM Type-2 capacity
|
|
81
|
-
* instantiation
|
|
82
|
-
* (`signBidirectionalEventDescriptorWith`) over
|
|
83
|
-
* {@link evmType2TxParamsDescriptor}.
|
|
87
|
+
* instantiation.
|
|
84
88
|
*
|
|
85
89
|
* @param maxCalldataWords - Calldata word capacity.
|
|
86
90
|
* @param maxAccessListEntries - Access-list entry capacity.
|
|
@@ -94,36 +98,16 @@ export function evmType2TxParamsDescriptor(maxCalldataWords, maxAccessListEntrie
|
|
|
94
98
|
export function signBidirectionalEventDescriptor(maxCalldataWords, maxAccessListEntries, maxStorageKeysPerEntry, lenOutputDeserialization, lenRespondSerialization) {
|
|
95
99
|
return signBidirectionalEventDescriptorWith(evmType2TxParamsDescriptor(maxCalldataWords, maxAccessListEntries, maxStorageKeysPerEntry), lenOutputDeserialization, lenRespondSerialization);
|
|
96
100
|
}
|
|
97
|
-
/**
|
|
98
|
-
* Canonical id of a signet request: the persistent hash of the entire event
|
|
99
|
-
* record (which commits to every field, the sender address included, and
|
|
100
|
-
* deliberately carries no extra domain tag). TS twin of Signet.compact's
|
|
101
|
-
* `calculateRequestId` circuit (see the deviation note in
|
|
102
|
-
* signet-requests.ts), generic over the capacity instantiation via the
|
|
103
|
-
* record's own array lengths: pass the record exactly as the ledger stores
|
|
104
|
-
* it, unused slots included and schemas at their declared widths.
|
|
105
|
-
*
|
|
106
|
-
* @param request - The full event record (contract-shaped, all slots).
|
|
107
|
-
* @returns The 32-byte request id, the record's ledger map key.
|
|
108
|
-
*/
|
|
109
|
-
export function calculateRequestId(request) {
|
|
110
|
-
const { txParams } = request;
|
|
111
|
-
const maxCalldataWords = txParams.calldata.value.words.length;
|
|
112
|
-
const maxAccessListEntries = txParams.accessList.length;
|
|
113
|
-
const maxStorageKeysPerEntry = maxAccessListEntries === 0 ? 0 : txParams.accessList[0].storageKeys.length;
|
|
114
|
-
return keccak256(signBidirectionalEventDescriptor(maxCalldataWords, maxAccessListEntries, maxStorageKeysPerEntry, request.outputDeserializationSchema.length, request.respondSerializationSchema.length), request);
|
|
115
|
-
}
|
|
116
101
|
// ---- ABI words / calldata / transaction assembly ---------------------------
|
|
117
102
|
/**
|
|
118
|
-
* The ABI word for a numeric value
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
* builders, tests).
|
|
103
|
+
* The ABI word for a numeric value: the value as a 32-byte BIG-ENDIAN
|
|
104
|
+
* integer, exactly as broadcast. TS mirror of Signet.compact's
|
|
105
|
+
* `numericAbiWord` circuit (lockstep-tested against the compiled circuit).
|
|
106
|
+
* For off-chain word builders (UIs, expected-record builders, tests).
|
|
123
107
|
*
|
|
124
108
|
* @param value - The word's numeric value (e.g. an amount).
|
|
125
109
|
* @returns The ABI-ready 32-byte word to store in an {@link EvmCalldata} word.
|
|
126
|
-
* @throws Error
|
|
110
|
+
* @throws {Error} If the value is negative or does not fit 32 bytes.
|
|
127
111
|
*/
|
|
128
112
|
export function numericAbiWord(value) {
|
|
129
113
|
return bigintToBytes32BE(value);
|
|
@@ -135,11 +119,11 @@ export function numericAbiWord(value) {
|
|
|
135
119
|
*
|
|
136
120
|
* @param address - The 20-byte address in display order.
|
|
137
121
|
* @returns The ABI-ready 32-byte word to store in an {@link EvmCalldata} word.
|
|
138
|
-
* @throws Error
|
|
122
|
+
* @throws {Error} If the address is not exactly 20 bytes.
|
|
139
123
|
*/
|
|
140
124
|
export function evmAddressAbiWord(address) {
|
|
141
125
|
if (address.length !== 20) {
|
|
142
|
-
throw new Error(`EVM address must be 20 bytes, got ${address.length}`);
|
|
126
|
+
throw new Error(`EVM address must be 20 bytes, got ${String(address.length)}`);
|
|
143
127
|
}
|
|
144
128
|
const word = new Uint8Array(32);
|
|
145
129
|
word.set(address, 12);
|
|
@@ -151,7 +135,7 @@ export function evmAddressAbiWord(address) {
|
|
|
151
135
|
* (lockstep-tested against the compiled circuit).
|
|
152
136
|
*
|
|
153
137
|
* @param value - The word's Boolean value.
|
|
154
|
-
* @returns The ABI-ready 32-byte word
|
|
138
|
+
* @returns The ABI-ready 32-byte word.
|
|
155
139
|
*/
|
|
156
140
|
export function boolAbiWord(value) {
|
|
157
141
|
const word = new Uint8Array(32);
|
|
@@ -160,52 +144,49 @@ export function boolAbiWord(value) {
|
|
|
160
144
|
}
|
|
161
145
|
/**
|
|
162
146
|
* Read a numeric ABI word back into a bigint: the big-endian reading of bytes
|
|
163
|
-
* 16..31
|
|
164
|
-
*
|
|
165
|
-
* than Uint<128> is rejected rather than silently truncated.
|
|
147
|
+
* 16..31, with the leading 16 bytes required to be zero. TS mirror of
|
|
148
|
+
* Signet.compact's `abiWordToUint128` circuit, canonicality check included.
|
|
166
149
|
*
|
|
167
150
|
* @param word - The ABI-ready 32-byte word.
|
|
168
151
|
* @returns The word's numeric value.
|
|
169
|
-
* @throws Error
|
|
152
|
+
* @throws {Error} If the word is not 32 bytes or its leading half is nonzero.
|
|
170
153
|
*/
|
|
171
154
|
export function abiWordToUint128(word) {
|
|
172
155
|
if (word.length !== 32) {
|
|
173
|
-
throw new Error(`ABI word must be 32 bytes, got ${word.length}`);
|
|
156
|
+
throw new Error(`ABI word must be 32 bytes, got ${String(word.length)}`);
|
|
174
157
|
}
|
|
175
158
|
if (word.slice(0, 16).some((byte) => byte !== 0)) {
|
|
176
159
|
throw new Error("ABI word exceeds Uint<128>");
|
|
177
160
|
}
|
|
178
161
|
let value = 0n;
|
|
179
|
-
for (
|
|
180
|
-
value = value * 256n + BigInt(
|
|
162
|
+
for (const byte of word.subarray(16, 32)) {
|
|
163
|
+
value = value * 256n + BigInt(byte);
|
|
181
164
|
}
|
|
182
165
|
return value;
|
|
183
166
|
}
|
|
184
167
|
/**
|
|
185
|
-
* Read a Boolean ABI word back into a boolean
|
|
186
|
-
*
|
|
187
|
-
*
|
|
168
|
+
* Read a Boolean ABI word back into a boolean: the first 31 bytes must be
|
|
169
|
+
* zero and the last byte 0 or 1. TS mirror of Signet.compact's
|
|
170
|
+
* `abiWordToBool` circuit, canonicality check included.
|
|
188
171
|
*
|
|
189
172
|
* @param word - The ABI-ready 32-byte word.
|
|
190
173
|
* @returns The word's Boolean value.
|
|
191
|
-
* @throws Error
|
|
174
|
+
* @throws {Error} If the word is not 32 bytes or is not a canonical Boolean.
|
|
192
175
|
*/
|
|
193
176
|
export function abiWordToBool(word) {
|
|
194
177
|
if (word.length !== 32) {
|
|
195
|
-
throw new Error(`ABI word must be 32 bytes, got ${word.length}`);
|
|
178
|
+
throw new Error(`ABI word must be 32 bytes, got ${String(word.length)}`);
|
|
196
179
|
}
|
|
197
|
-
|
|
180
|
+
const low = word[31];
|
|
181
|
+
if (low === undefined || word.slice(0, 31).some((byte) => byte !== 0) || low > 1) {
|
|
198
182
|
throw new Error("ABI word is not a canonical Boolean");
|
|
199
183
|
}
|
|
200
|
-
return
|
|
184
|
+
return low === 1;
|
|
201
185
|
}
|
|
202
186
|
/**
|
|
203
187
|
* Assemble the raw calldata a request's words describe:
|
|
204
|
-
* `data = selector || words[0..noWords]`, VERBATIM
|
|
205
|
-
*
|
|
206
|
-
* reordered or reinterpreted on the way into the transaction. Slots past
|
|
207
|
-
* `noWords` are unused capacity and are dropped. This is THE implementation
|
|
208
|
-
* of the signer-side assembly documented on `EvmCalldata` in Signet.compact.
|
|
188
|
+
* `data = selector || words[0..noWords]`, VERBATIM (see {@link EvmCalldata}).
|
|
189
|
+
* Slots past `noWords` are unused capacity and are dropped.
|
|
209
190
|
*
|
|
210
191
|
* @param calldata - The request's calldata field.
|
|
211
192
|
* @returns Hex calldata for the transaction (`"0x"` when absent).
|
|
@@ -216,8 +197,8 @@ export function assembleCalldata(calldata) {
|
|
|
216
197
|
}
|
|
217
198
|
const { selector, noWords, words } = calldata.value;
|
|
218
199
|
let data = `0x${bytesToHex(selector)}`;
|
|
219
|
-
for (
|
|
220
|
-
data += bytesToHex(
|
|
200
|
+
for (const word of words.slice(0, Number(noWords))) {
|
|
201
|
+
data += bytesToHex(word);
|
|
221
202
|
}
|
|
222
203
|
return data;
|
|
223
204
|
}
|
|
@@ -229,9 +210,7 @@ export function assembleCalldata(calldata) {
|
|
|
229
210
|
* @returns The access list, possibly empty.
|
|
230
211
|
*/
|
|
231
212
|
function decodeAccessList(txParams) {
|
|
232
|
-
return txParams.accessList
|
|
233
|
-
.slice(0, Number(txParams.accessListEntryCount))
|
|
234
|
-
.map((entry) => ({
|
|
213
|
+
return txParams.accessList.slice(0, Number(txParams.accessListEntryCount)).map((entry) => ({
|
|
235
214
|
address: getAddress(`0x${bytesToHex(entry.address)}`),
|
|
236
215
|
storageKeys: entry.storageKeys
|
|
237
216
|
.slice(0, Number(entry.storageKeyCount))
|
|
@@ -240,18 +219,14 @@ function decodeAccessList(txParams) {
|
|
|
240
219
|
}
|
|
241
220
|
/**
|
|
242
221
|
* Rebuild the unsigned EIP-1559 transaction a request record describes,
|
|
243
|
-
* byte-identical to the one the MPC assembles and signs
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
* request→transaction transform. Response-side verification
|
|
247
|
-
* (`signature-response-verification.ts`) and the signed-transaction builder
|
|
248
|
-
* below both go through it, so the transaction a client broadcasts is
|
|
249
|
-
* provably the one the MPC put its signature over.
|
|
222
|
+
* byte-identical to the one the MPC assembles and signs. The canonical
|
|
223
|
+
* request-to-transaction transform: response-side verification and
|
|
224
|
+
* {@link signBidirectionalEventToSignedEvmTransaction} both go through it.
|
|
250
225
|
*
|
|
251
226
|
* @param request - The on-ledger request record.
|
|
252
227
|
* @returns The unsigned ethers transaction (`unsignedHash` is the digest the
|
|
253
228
|
* MPC signs).
|
|
254
|
-
* @throws Error
|
|
229
|
+
* @throws {Error} If a calldata word carries an unknown kind.
|
|
255
230
|
*/
|
|
256
231
|
export function signBidirectionalEventToUnsignedEvmTransaction(request) {
|
|
257
232
|
const { txParams } = request;
|
|
@@ -268,52 +243,6 @@ export function signBidirectionalEventToUnsignedEvmTransaction(request) {
|
|
|
268
243
|
data: assembleCalldata(txParams.calldata),
|
|
269
244
|
});
|
|
270
245
|
}
|
|
271
|
-
/**
|
|
272
|
-
* Decode a response signature record (as the signet contract emits it in a
|
|
273
|
-
* signature response event) into an ethers {@link Signature}. Goes through
|
|
274
|
-
* {@link mpcSignatureToEcdsaSignature}, so this and in-circuit claims decode
|
|
275
|
-
* 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.
|
|
279
|
-
*
|
|
280
|
-
* @param response - The posted signature record.
|
|
281
|
-
* @returns The ethers signature.
|
|
282
|
-
* @throws Error if the record is malformed (see {@link mpcSignatureToEcdsaSignature}).
|
|
283
|
-
*/
|
|
284
|
-
export function signatureRespondedEventToSignature(response) {
|
|
285
|
-
const { r, s, recoveryId } = mpcSignatureToEcdsaSignature(response.signature);
|
|
286
|
-
return Signature.from({
|
|
287
|
-
r: toBeHex(r, 32),
|
|
288
|
-
s: toBeHex(s, 32),
|
|
289
|
-
v: recoveryId + 27,
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Encode an ECDSA signature as the response record posted to the signet
|
|
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}).
|
|
298
|
-
*
|
|
299
|
-
* The parameter is structural (the r/s/yParity subset of an ethers
|
|
300
|
-
* {@link Signature}) so signatures from ANY ethers instance qualify: posters
|
|
301
|
-
* living in other repos resolve their own ethers install, and nominal class
|
|
302
|
-
* typing would reject it.
|
|
303
|
-
*
|
|
304
|
-
* @param signature - The signature to encode (`r`/`s` as 0x hex, `yParity` 0 or 1).
|
|
305
|
-
* @returns The response record, ready to post.
|
|
306
|
-
* @throws Error if `r` is not the x coordinate of a secp256k1 point.
|
|
307
|
-
*/
|
|
308
|
-
export function signatureToSignatureRespondedEvent(signature) {
|
|
309
|
-
return {
|
|
310
|
-
signature: ecdsaSignatureToMpcSignature({
|
|
311
|
-
r: BigInt(signature.r),
|
|
312
|
-
s: BigInt(signature.s),
|
|
313
|
-
recoveryId: signature.yParity,
|
|
314
|
-
}),
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
246
|
/**
|
|
318
247
|
* Assemble the broadcast-ready signed EIP-1559 transaction for a request from
|
|
319
248
|
* its MPC signature response: rebuild the exact unsigned transaction the MPC
|
|
@@ -327,7 +256,7 @@ export function signatureToSignatureRespondedEvent(signature) {
|
|
|
327
256
|
* @returns The signed ethers transaction: `serialized` is the raw payload for
|
|
328
257
|
* `eth_sendRawTransaction`, `hash` its on-chain hash, `from` the recovered
|
|
329
258
|
* sender.
|
|
330
|
-
* @throws Error
|
|
259
|
+
* @throws {Error} If the request record is malformed (see
|
|
331
260
|
* {@link signBidirectionalEventToUnsignedEvmTransaction}) or the response
|
|
332
261
|
* is not a decodable signature.
|
|
333
262
|
*/
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"signet-evtype2tx-requests.js","sourceRoot":"","sources":["../src/signet-evtype2tx-requests.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,sEAAsE;AACtE,6EAA6E;AAC7E,sEAAsE;AACtE,wBAAwB;AACxB,EAAE;AACF,oEAAoE;AACpE,6EAA6E;AAC7E,mCAAmC;AAEnC,OAAO,EAAoB,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAEjD,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EACL,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,sBAAsB,EACtB,uBAAuB,EAEvB,MAAM,EACN,OAAO,EACP,OAAO,EACP,QAAQ,GACT,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,kCAAkC,EAAE,MAAM,wBAAwB,CAAC;AAE5E,OAAO,EAEL,oCAAoC,GACrC,MAAM,sBAAsB,CAAC;AAgE9B,+EAA+E;AAC/E,6EAA6E;AAC7E,kFAAkF;AAElF;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,QAAgB;IACpD,OAAO,uBAAuB,CAAc;QAC1C,QAAQ,EAAE,OAAO;QACjB,OAAO,EAAE,OAAO;QAChB,KAAK,EAAE,IAAI,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,CAAC;KACjD,CAAC,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,4BAA4B,CAC1C,cAAsB;IAEtB,OAAO,uBAAuB,CAAqB;QACjD,OAAO,EAAE,QAAQ;QACjB,eAAe,EAAE,MAAM;QACvB,WAAW,EAAE,IAAI,iBAAiB,CAAC,cAAc,EAAE,QAAQ,CAAC;KAC7D,CAAC,CAAC;AACL,CA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,CAAC,CAAC;IACrE,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type RequestId, type SignBidirectionalEvent } from "./signet-requests.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Canonical id of a signet request: the keccak256 of the entire event
|
|
4
|
+
* record, the sender address included, with no extra domain tag. Pass the
|
|
5
|
+
* record exactly as the ledger stores it, unused slots included and schemas
|
|
6
|
+
* at their declared widths.
|
|
7
|
+
*
|
|
8
|
+
* @param request - The full event record (contract-shaped, all slots).
|
|
9
|
+
* @returns The 32-byte request id, the record's ledger map key.
|
|
10
|
+
* @throws {Error} If the record's `txParamType` names a decomposition this
|
|
11
|
+
* computation has no descriptor for.
|
|
12
|
+
*/
|
|
13
|
+
export declare function calculateRequestId(request: SignBidirectionalEvent): RequestId;
|
|
14
|
+
//# sourceMappingURL=signet-request-id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signet-request-id.d.ts","sourceRoot":"","sources":["../src/signet-request-id.ts"],"names":[],"mappings":"AASA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,sBAAsB,EAG5B,MAAM,sBAAsB,CAAC;AAE9B;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,sBAAsB,GAAG,SAAS,CAe7E"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// The signet request id computation: the TS twin of Signet.compact's
|
|
2
|
+
// `calculateRequestId` circuit (see the deviation note in
|
|
3
|
+
// signet-requests.ts). Chain-agnostic entry point that resolves each
|
|
4
|
+
// record's tx-params descriptor by its `txParamType` tag, so every
|
|
5
|
+
// decomposition mints ids through this one function.
|
|
6
|
+
import { keccak256 } from "@midnight-ntwrk/compact-runtime";
|
|
7
|
+
import { evmType2TxParamsDescriptorOf } from "./signet-evtype2tx-requests.js";
|
|
8
|
+
import { signBidirectionalEventDescriptorWith, TxParamType, } from "./signet-requests.js";
|
|
9
|
+
/**
|
|
10
|
+
* Canonical id of a signet request: the keccak256 of the entire event
|
|
11
|
+
* record, the sender address included, with no extra domain tag. Pass the
|
|
12
|
+
* record exactly as the ledger stores it, unused slots included and schemas
|
|
13
|
+
* at their declared widths.
|
|
14
|
+
*
|
|
15
|
+
* @param request - The full event record (contract-shaped, all slots).
|
|
16
|
+
* @returns The 32-byte request id, the record's ledger map key.
|
|
17
|
+
* @throws {Error} If the record's `txParamType` names a decomposition this
|
|
18
|
+
* computation has no descriptor for.
|
|
19
|
+
*/
|
|
20
|
+
export function calculateRequestId(request) {
|
|
21
|
+
if (request.txParamType !== TxParamType.evmType2) {
|
|
22
|
+
throw new Error(`unsupported txParamType ${String(request.txParamType)}: this id computation ` +
|
|
23
|
+
`understands evmType2 (${String(TxParamType.evmType2)})`);
|
|
24
|
+
}
|
|
25
|
+
return keccak256(signBidirectionalEventDescriptorWith(evmType2TxParamsDescriptorOf(request.txParams), request.outputDeserializationSchema.length, request.respondSerializationSchema.length), request);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=signet-request-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signet-request-id.js","sourceRoot":"","sources":["../src/signet-request-id.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,0DAA0D;AAC1D,qEAAqE;AACrE,mEAAmE;AACnE,qDAAqD;AAErD,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAE5D,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,EAGL,oCAAoC,EACpC,WAAW,GACZ,MAAM,sBAAsB,CAAC;AAE9B;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAA+B;IAChE,IAAI,OAAO,CAAC,WAAW,KAAK,WAAW,CAAC,QAAQ,EAAE,CAAC;QACjD,MAAM,IAAI,KAAK,CACb,2BAA2B,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,wBAAwB;YAC5E,yBAAyB,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAC3D,CAAC;IACJ,CAAC;IACD,OAAO,SAAS,CACd,oCAAoC,CAClC,4BAA4B,CAAC,OAAO,CAAC,QAAQ,CAAC,EAC9C,OAAO,CAAC,2BAA2B,CAAC,MAAM,EAC1C,OAAO,CAAC,0BAA0B,CAAC,MAAM,CAC1C,EACD,OAAO,CACR,CAAC;AACJ,CAAC"}
|