@sig-net/midnight 0.0.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 +20 -0
- package/dist/constants.d.ts +62 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +83 -0
- package/dist/constants.js.map +1 -0
- package/dist/epsilon-derivation.d.ts +32 -0
- package/dist/epsilon-derivation.d.ts.map +1 -0
- package/dist/epsilon-derivation.js +54 -0
- package/dist/epsilon-derivation.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/managed/compiler/contract-info.json +165 -0
- package/dist/managed/compiler/contract-manifest.json +32 -0
- package/dist/managed/contract/index.d.ts +65 -0
- package/dist/managed/contract/index.js +611 -0
- package/dist/managed/contract/index.js.map +8 -0
- package/dist/schnorr.d.ts +100 -0
- package/dist/schnorr.d.ts.map +1 -0
- package/dist/schnorr.js +144 -0
- package/dist/schnorr.js.map +1 -0
- package/dist/signature-requests-state-reader.d.ts +74 -0
- package/dist/signature-requests-state-reader.d.ts.map +1 -0
- package/dist/signature-requests-state-reader.js +167 -0
- package/dist/signature-requests-state-reader.js.map +1 -0
- package/dist/signature-response-verification.d.ts +27 -0
- package/dist/signature-response-verification.d.ts.map +1 -0
- package/dist/signature-response-verification.js +45 -0
- package/dist/signature-response-verification.js.map +1 -0
- package/dist/signature-state-reading.d.ts +36 -0
- package/dist/signature-state-reading.d.ts.map +1 -0
- package/dist/signature-state-reading.js +62 -0
- package/dist/signature-state-reading.js.map +1 -0
- package/dist/signet-contract-state-reader.d.ts +146 -0
- package/dist/signet-contract-state-reader.d.ts.map +1 -0
- package/dist/signet-contract-state-reader.js +226 -0
- package/dist/signet-contract-state-reader.js.map +1 -0
- package/dist/signet-event-observer.d.ts +102 -0
- package/dist/signet-event-observer.d.ts.map +1 -0
- package/dist/signet-event-observer.js +127 -0
- package/dist/signet-event-observer.js.map +1 -0
- package/dist/signet-events.d.ts +175 -0
- package/dist/signet-events.d.ts.map +1 -0
- package/dist/signet-events.js +210 -0
- package/dist/signet-events.js.map +1 -0
- package/dist/signet-request-feed.d.ts +78 -0
- package/dist/signet-request-feed.d.ts.map +1 -0
- package/dist/signet-request-feed.js +116 -0
- package/dist/signet-request-feed.js.map +1 -0
- package/dist/signet-request-resolver.d.ts +58 -0
- package/dist/signet-request-resolver.d.ts.map +1 -0
- package/dist/signet-request-resolver.js +76 -0
- package/dist/signet-request-resolver.js.map +1 -0
- package/dist/signet-request-response-reader.d.ts +160 -0
- package/dist/signet-request-response-reader.d.ts.map +1 -0
- package/dist/signet-request-response-reader.js +198 -0
- package/dist/signet-request-response-reader.js.map +1 -0
- package/dist/signet-requests.d.ts +363 -0
- package/dist/signet-requests.d.ts.map +1 -0
- package/dist/signet-requests.js +497 -0
- package/dist/signet-requests.js.map +1 -0
- package/dist/signet-response-feed.d.ts +161 -0
- package/dist/signet-response-feed.d.ts.map +1 -0
- package/dist/signet-response-feed.js +234 -0
- package/dist/signet-response-feed.js.map +1 -0
- package/package.json +47 -0
- package/src/Schnorr.compact +63 -0
- package/src/Signet.compact +529 -0
- package/src/circuits.compact +36 -0
- package/src/constants.ts +97 -0
- package/src/epsilon-derivation.ts +62 -0
- package/src/index.ts +31 -0
- package/src/managed/compiler/contract-info.json +165 -0
- package/src/managed/compiler/contract-manifest.json +32 -0
- package/src/managed/contract/index.d.ts +65 -0
- package/src/managed/contract/index.js +611 -0
- package/src/managed/contract/index.js.map +8 -0
- package/src/schnorr.ts +210 -0
- package/src/signature-requests-state-reader.ts +223 -0
- package/src/signature-response-verification.ts +64 -0
- package/src/signature-state-reading.ts +87 -0
- package/src/signet-contract-state-reader.ts +391 -0
- package/src/signet-event-observer.ts +186 -0
- package/src/signet-events.ts +337 -0
- package/src/signet-request-feed.ts +158 -0
- package/src/signet-request-resolver.ts +116 -0
- package/src/signet-request-response-reader.ts +324 -0
- package/src/signet-requests.ts +737 -0
- package/src/signet-response-feed.ts +325 -0
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import { type CompactType } from "@midnight-ntwrk/compact-runtime";
|
|
2
|
+
import { Signature, Transaction } from "ethers";
|
|
3
|
+
import type { SignatureResponse } from "./signet-contract-state-reader.ts";
|
|
4
|
+
/**
|
|
5
|
+
* 32-byte signet request id (Compact: `new type RequestId = Bytes<32>`).
|
|
6
|
+
* Chain-agnostic: downstream consumers treat it as an opaque key. Ids are
|
|
7
|
+
* minted by `calculateRequestId` in Signet.compact — the domain-separated
|
|
8
|
+
* hash of the full {@link SignBidirectionalRequest} record.
|
|
9
|
+
*/
|
|
10
|
+
export type RequestId = Uint8Array;
|
|
11
|
+
/**
|
|
12
|
+
* Which transaction-param decomposition a request carries (Compact:
|
|
13
|
+
* `enum TxParamType`), as the generated code represents enums: a `number`
|
|
14
|
+
* holding the 0-based variant index. Exported as a `const` object (not a TS
|
|
15
|
+
* `enum`) so the values stay structurally `number`.
|
|
16
|
+
*/
|
|
17
|
+
export declare const TxParamType: {
|
|
18
|
+
/** {@link EVMType2TxParams}: an EIP-1559 EVM transaction. */
|
|
19
|
+
readonly evmType2: 0;
|
|
20
|
+
/**
|
|
21
|
+
* Never emitted — mirrors the Compact-side padding variant that keeps the
|
|
22
|
+
* enum at >= 2 variants (a 1-variant enum is a zero-byte value the proof
|
|
23
|
+
* server cannot parse inside persistentHash preimages).
|
|
24
|
+
*/
|
|
25
|
+
readonly reserved: 1;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Compact's standard-library `Maybe<T>` as the compiler generates it: a
|
|
29
|
+
* plain struct. Even when `is_some` is false, `value` carries a full
|
|
30
|
+
* default-valued `T` (so vector capacities remain inferable).
|
|
31
|
+
*/
|
|
32
|
+
export interface Maybe<T> {
|
|
33
|
+
is_some: boolean;
|
|
34
|
+
value: T;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* ABI calldata as a 4-byte selector + 32-byte word slots (Compact:
|
|
38
|
+
* `EVMCalldata<#maxWords>`). Each word is a little-endian field embed (what the
|
|
39
|
+
* contract's `x as Field as Bytes<32>` cast produces); the MPC re-encodes the
|
|
40
|
+
* leading {@link noWords} of them big-endian to form the calldata body —
|
|
41
|
+
* `data = selector || BE(words[0..noWords])`, see {@link assembleCalldata}.
|
|
42
|
+
*/
|
|
43
|
+
export interface EVMCalldata {
|
|
44
|
+
/** The literal first 4 calldata bytes (big-endian, as broadcast). */
|
|
45
|
+
selector: Uint8Array;
|
|
46
|
+
/** How many leading {@link words} are real (Compact `noWords: Uint<16>`). */
|
|
47
|
+
noWords: bigint;
|
|
48
|
+
/** 32-byte word slots; capacity is the contract's `#maxWords` (vault: 2). */
|
|
49
|
+
words: Uint8Array[];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* One EIP-2930 access-list entry (Compact:
|
|
53
|
+
* `EVMAccessListEntry<#maxStorageKeys>`).
|
|
54
|
+
*/
|
|
55
|
+
export interface EVMAccessListEntry {
|
|
56
|
+
/** The pre-declared contract address, 20 display-order bytes. */
|
|
57
|
+
address: Uint8Array;
|
|
58
|
+
/** How many leading {@link storageKeys} are real. */
|
|
59
|
+
storageKeyCount: bigint;
|
|
60
|
+
/** Raw 32-byte storage keys, copied verbatim into the transaction. */
|
|
61
|
+
storageKeys: Uint8Array[];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The EVM transaction to be signed, decomposed into typed fields (Compact:
|
|
65
|
+
* `EVMType2TxParams<#maxCalldataWords, #maxAccessListEntries,
|
|
66
|
+
* #maxStorageKeysPerEntry>`; EIP-1559 — https://eips.ethereum.org/EIPS/eip-1559).
|
|
67
|
+
* Compact `Bytes<N>` fields arrive as N-byte `Uint8Array`s, `Uint<N>` as
|
|
68
|
+
* `bigint`. Vector capacities are each contract's compile-time throttle;
|
|
69
|
+
* the runtime counts say how many leading slots are real.
|
|
70
|
+
*/
|
|
71
|
+
export interface EVMType2TxParams {
|
|
72
|
+
/** Call target (e.g. the ERC20 contract), 20 bytes. */
|
|
73
|
+
to: Uint8Array;
|
|
74
|
+
/** EVM chain id (also expressed in {@link SignBidirectionalRequest.caip2Id}). */
|
|
75
|
+
chainId: bigint;
|
|
76
|
+
/** Account nonce of the MPC-derived sender address. */
|
|
77
|
+
nonce: bigint;
|
|
78
|
+
/** Gas ceiling for the call. */
|
|
79
|
+
gasLimit: bigint;
|
|
80
|
+
/** Max total fee per gas, wei. */
|
|
81
|
+
maxFeePerGas: bigint;
|
|
82
|
+
/** Max priority fee per gas, wei. */
|
|
83
|
+
maxPriorityFeePerGas: bigint;
|
|
84
|
+
/** ETH sent with the call, wei. */
|
|
85
|
+
value: bigint;
|
|
86
|
+
/** How many leading {@link accessList} entries are real. */
|
|
87
|
+
accessListEntryCount: bigint;
|
|
88
|
+
/** EIP-2930 access list slots (capacity = contract's throttle). */
|
|
89
|
+
accessList: EVMAccessListEntry[];
|
|
90
|
+
/** Call data; `is_some: false` means a plain ETH transfer (`0x` data). */
|
|
91
|
+
calldata: Maybe<EVMCalldata>;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Canonical signet request record (Compact:
|
|
95
|
+
* `SignBidirectionalRequest<TxParams>`), stored per {@link RequestId} in a
|
|
96
|
+
* requesting contract's index (ledger field 0). Mirrors the MPC's
|
|
97
|
+
* SignBidirectionalRequest with the transaction decomposed. The TS twin fixes
|
|
98
|
+
* the type parameter at {@link EVMType2TxParams} — the only decomposition
|
|
99
|
+
* so far; new tx kinds add a union here alongside their Compact struct.
|
|
100
|
+
*/
|
|
101
|
+
export interface SignBidirectionalRequest {
|
|
102
|
+
/** Contract-local nonce captured when the request was created. */
|
|
103
|
+
requestNonce: bigint;
|
|
104
|
+
/** A {@link TxParamType} value tagging the txParams decomposition. */
|
|
105
|
+
txParamType: number;
|
|
106
|
+
/** The transaction decomposition. */
|
|
107
|
+
txParams: EVMType2TxParams;
|
|
108
|
+
/** Target chain in CAIP-2 form (https://chainagnostic.org/CAIPs/caip-2), zero-padded; 32 bytes. */
|
|
109
|
+
caip2Id: Uint8Array;
|
|
110
|
+
/** MPC root-key version to derive from (>= 1; version 0 is the unsupported legacy format). */
|
|
111
|
+
keyVersion: bigint;
|
|
112
|
+
/** Key-derivation path: canonical lowercase hex of the caller's identity commitment, zero-padded; 256 bytes. */
|
|
113
|
+
path: Uint8Array;
|
|
114
|
+
/** Signature scheme, zero-padded ASCII, e.g. "ecdsa"; 32 bytes. */
|
|
115
|
+
algo: Uint8Array;
|
|
116
|
+
/** Response destination, zero-padded ASCII, e.g. "ethereum"; 32 bytes. */
|
|
117
|
+
dest: Uint8Array;
|
|
118
|
+
/** Scheme-specific extras, opaque; 64 bytes. */
|
|
119
|
+
params: Uint8Array;
|
|
120
|
+
/** MPC output_deserialization_schema (destination chain -> MPC); 128 bytes. */
|
|
121
|
+
outputDeserializationSchema: Uint8Array;
|
|
122
|
+
/** MPC respond_serialization_schema (MPC -> source chain); 128 bytes. */
|
|
123
|
+
respondSerializationSchema: Uint8Array;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Descriptor of {@link EVMCalldata} at one word capacity — the TS analogue
|
|
127
|
+
* of instantiating Compact's `EVMCalldata<#maxWords>`.
|
|
128
|
+
*
|
|
129
|
+
* @param maxWords - The contract's calldata word capacity (the vault uses 2).
|
|
130
|
+
* @returns The calldata descriptor.
|
|
131
|
+
*/
|
|
132
|
+
export declare function evmCalldataDescriptor(maxWords: number): CompactType<EVMCalldata>;
|
|
133
|
+
/**
|
|
134
|
+
* Descriptor of {@link EVMAccessListEntry} at one storage-key capacity
|
|
135
|
+
* (Compact: `EVMAccessListEntry<#maxStorageKeys>`).
|
|
136
|
+
*
|
|
137
|
+
* @param maxStorageKeys - Storage-key capacity per entry.
|
|
138
|
+
* @returns The entry descriptor.
|
|
139
|
+
*/
|
|
140
|
+
export declare function evmAccessListEntryDescriptor(maxStorageKeys: number): CompactType<EVMAccessListEntry>;
|
|
141
|
+
/**
|
|
142
|
+
* Descriptor of {@link EVMType2TxParams} at one capacity instantiation —
|
|
143
|
+
* the TS analogue of Compact's `EVMType2TxParams<#maxCalldataWords,
|
|
144
|
+
* #maxAccessListEntries, #maxStorageKeysPerEntry>`.
|
|
145
|
+
*
|
|
146
|
+
* @param maxCalldataWords - Calldata word capacity.
|
|
147
|
+
* @param maxAccessListEntries - Access-list entry capacity.
|
|
148
|
+
* @param maxStorageKeysPerEntry - Storage-key capacity per entry.
|
|
149
|
+
* @returns The tx-params descriptor.
|
|
150
|
+
*/
|
|
151
|
+
export declare function evmType2TxParamsDescriptor(maxCalldataWords: number, maxAccessListEntries: number, maxStorageKeysPerEntry: number): CompactType<EVMType2TxParams>;
|
|
152
|
+
/**
|
|
153
|
+
* Descriptor of {@link SignBidirectionalRequest} at one capacity instantiation.
|
|
154
|
+
*
|
|
155
|
+
* @param maxCalldataWords - Calldata word capacity.
|
|
156
|
+
* @param maxAccessListEntries - Access-list entry capacity.
|
|
157
|
+
* @param maxStorageKeysPerEntry - Storage-key capacity per entry.
|
|
158
|
+
* @returns The request record descriptor.
|
|
159
|
+
*/
|
|
160
|
+
export declare function signBidirectionalRequestDescriptor(maxCalldataWords: number, maxAccessListEntries: number, maxStorageKeysPerEntry: number): CompactType<SignBidirectionalRequest>;
|
|
161
|
+
/**
|
|
162
|
+
* Canonical id of a signet request: the domain-separated persistent hash of
|
|
163
|
+
* the entire request record. TS twin of Signet.compact's `calculateRequestId`
|
|
164
|
+
* circuit (see the deviation note atop this section), generic over the
|
|
165
|
+
* capacity instantiation via the record's own array lengths — pass the
|
|
166
|
+
* record exactly as the ledger stores it, unused slots included.
|
|
167
|
+
*
|
|
168
|
+
* @param request - The full request record (contract-shaped, all slots).
|
|
169
|
+
* @returns The 32-byte request id — the record's ledger map key.
|
|
170
|
+
*/
|
|
171
|
+
export declare function calculateRequestId(request: SignBidirectionalRequest): RequestId;
|
|
172
|
+
/**
|
|
173
|
+
* The 32-byte value of a numeric ABI word: the little-endian field embed of
|
|
174
|
+
* the number, exactly what Compact's `x as Field as Bytes<32>` cast produces
|
|
175
|
+
* in-circuit. Use when building words off-chain (UIs, expected-record
|
|
176
|
+
* builders, tests).
|
|
177
|
+
*
|
|
178
|
+
* @param value - The word's numeric value (e.g. an amount).
|
|
179
|
+
* @returns The 32-byte LE embed to store in an {@link EVMCalldata} word.
|
|
180
|
+
*/
|
|
181
|
+
export declare function numericAbiWordValue(value: bigint): Uint8Array;
|
|
182
|
+
/**
|
|
183
|
+
* The 32-byte staticArg word value for an EVM address: the BIG-ENDIAN
|
|
184
|
+
* numeric reading of its 20 display-order bytes, LE-embedded. TS mirror of
|
|
185
|
+
* Signet.compact's `evmAddressAbiValue` circuit (+ `as Bytes<32>`); see the
|
|
186
|
+
* warning there — embedding the display-order bytes directly would come out
|
|
187
|
+
* byte-reversed in the assembled calldata.
|
|
188
|
+
*
|
|
189
|
+
* @param address - The 20-byte address in display order.
|
|
190
|
+
* @returns The 32-byte word value to store in an {@link EVMCalldata} word.
|
|
191
|
+
*/
|
|
192
|
+
export declare function evmAddressAbiWord(address: Uint8Array): Uint8Array;
|
|
193
|
+
/**
|
|
194
|
+
* Re-assemble the raw calldata a request's words describe:
|
|
195
|
+
* `data = selector || BE(words[0..noWords])`. Each word is a little-endian
|
|
196
|
+
* field embed (the contract's `x as Field as Bytes<32>` cast); the leading
|
|
197
|
+
* `noWords` are re-encoded big-endian into 32-byte ABI words and any remaining
|
|
198
|
+
* capacity slots are dropped. This is THE implementation of the MPC re-assembly
|
|
199
|
+
* documented on `EVMCalldata` in Signet.compact.
|
|
200
|
+
*
|
|
201
|
+
* @param calldata - The request's calldata field.
|
|
202
|
+
* @returns Hex calldata for the transaction (`"0x"` when absent).
|
|
203
|
+
*/
|
|
204
|
+
export declare function assembleCalldata(calldata: Maybe<EVMCalldata>): string;
|
|
205
|
+
/**
|
|
206
|
+
* Rebuild the unsigned EIP-1559 transaction a request record describes,
|
|
207
|
+
* byte-identical to the one the MPC assembles and signs: calldata from the
|
|
208
|
+
* tagged words (see {@link assembleCalldata}), the count-trimmed access
|
|
209
|
+
* list, and the stored envelope fields. This is the canonical
|
|
210
|
+
* request→transaction transform; response-side verification
|
|
211
|
+
* (`signature-response-verification.ts`) and the signed-transaction builder
|
|
212
|
+
* below both go through it, so the transaction a client broadcasts is
|
|
213
|
+
* provably the one the MPC put its signature over.
|
|
214
|
+
*
|
|
215
|
+
* @param event - The on-ledger request record.
|
|
216
|
+
* @returns The unsigned ethers transaction (`unsignedHash` is the digest the
|
|
217
|
+
* MPC signs).
|
|
218
|
+
* @throws Error if a calldata word carries an unknown kind.
|
|
219
|
+
*/
|
|
220
|
+
export declare function signBidirectionalRequestToUnsignedEVMTransaction(event: SignBidirectionalRequest): Transaction;
|
|
221
|
+
/**
|
|
222
|
+
* Decode a response signature record (as posted to the signet contract's
|
|
223
|
+
* signature response log — the canonical MPC `Signature { big_r, s,
|
|
224
|
+
* recovery_id }` shape) into an ethers {@link Signature}: `r` is `bigR`'s x
|
|
225
|
+
* coordinate, `v` the legacy parity derived from the recovery id.
|
|
226
|
+
*
|
|
227
|
+
* @param response - The posted signature record.
|
|
228
|
+
* @returns The ethers signature.
|
|
229
|
+
* @throws Error if the recovery id is not 0 or 1.
|
|
230
|
+
*/
|
|
231
|
+
export declare function signatureResponseToSignature(response: SignatureResponse): Signature;
|
|
232
|
+
/**
|
|
233
|
+
* Encode an ECDSA signature as the response record posted to the signet
|
|
234
|
+
* contract — the inverse of {@link signatureResponseToSignature},
|
|
235
|
+
* for MPC-side posters (the fakenet signer, tests). The canonical record
|
|
236
|
+
* carries `bigR` as a full affine point but an `r || s || v` signature only
|
|
237
|
+
* has R.x and the parity of R.y, so R.y is recovered by decompressing the
|
|
238
|
+
* point on the curve (y² = x³ + 7 over the secp256k1 base field).
|
|
239
|
+
*
|
|
240
|
+
* The parameter is structural (the r/s/yParity subset of an ethers
|
|
241
|
+
* {@link Signature}) so signatures from ANY ethers instance qualify — posters
|
|
242
|
+
* living in other repos resolve their own ethers install, and nominal class
|
|
243
|
+
* typing would reject it.
|
|
244
|
+
*
|
|
245
|
+
* @param signature - The signature to encode (`r`/`s` as 0x hex, `yParity` 0 or 1).
|
|
246
|
+
* @returns The response record, ready to post.
|
|
247
|
+
* @throws Error if `r` is not the x coordinate of a curve point.
|
|
248
|
+
*/
|
|
249
|
+
export declare function signatureToSignatureResponse(signature: Pick<Signature, "r" | "s" | "yParity">): SignatureResponse;
|
|
250
|
+
/**
|
|
251
|
+
* Assemble the broadcast-ready signed EIP-1559 transaction for a request from
|
|
252
|
+
* its MPC signature response: rebuild the exact unsigned transaction the MPC
|
|
253
|
+
* signed (see {@link signBidirectionalRequestToUnsignedEVMTransaction}) and
|
|
254
|
+
* attach the signature. Does NOT check that the signature recovers to the
|
|
255
|
+
* requester's derived address — the response log is unauthenticated, so
|
|
256
|
+
* verify first with `verifySignatureResponse`.
|
|
257
|
+
*
|
|
258
|
+
* @param event - The on-ledger request record.
|
|
259
|
+
* @param response - The posted signature record answering it.
|
|
260
|
+
* @returns The signed ethers transaction; `serialized` is the raw payload for
|
|
261
|
+
* `eth_sendRawTransaction`, `hash` its on-chain hash, `from` the recovered
|
|
262
|
+
* sender.
|
|
263
|
+
* @throws Error if the request record is malformed (see
|
|
264
|
+
* {@link signBidirectionalRequestToUnsignedEVMTransaction}) or the response
|
|
265
|
+
* is not a decodable signature.
|
|
266
|
+
*/
|
|
267
|
+
export declare function signBidirectionalRequestToSignedEVMTransaction(event: SignBidirectionalRequest, response: SignatureResponse): Transaction;
|
|
268
|
+
/**
|
|
269
|
+
* The generated ledger shape of `Map<RequestId, SignBidirectionalRequest>`:
|
|
270
|
+
* what a contract's `ledger(state).signetRequestsIndex` provides. Structural,
|
|
271
|
+
* so any contract exposing the index satisfies it.
|
|
272
|
+
*/
|
|
273
|
+
export interface SignBidirectionalRequestLedgerIndex extends Iterable<[RequestId, SignBidirectionalRequest]> {
|
|
274
|
+
/** @returns `true` when the index holds no requests. */
|
|
275
|
+
isEmpty(): boolean;
|
|
276
|
+
/** @returns Number of requests in the index. */
|
|
277
|
+
size(): bigint;
|
|
278
|
+
/**
|
|
279
|
+
* @param requestId - 32-byte request id to probe.
|
|
280
|
+
* @returns `true` when the index holds an entry for `requestId`.
|
|
281
|
+
*/
|
|
282
|
+
member(requestId: RequestId): boolean;
|
|
283
|
+
/**
|
|
284
|
+
* @param requestId - 32-byte request id to fetch.
|
|
285
|
+
* @returns The stored request record; throws when absent — guard with
|
|
286
|
+
* {@link member} first.
|
|
287
|
+
*/
|
|
288
|
+
lookup(requestId: RequestId): SignBidirectionalRequest;
|
|
289
|
+
}
|
|
290
|
+
declare const requestIdHexBrand: unique symbol;
|
|
291
|
+
/**
|
|
292
|
+
* 64-char lowercase hex rendering of a {@link RequestId} — THE
|
|
293
|
+
* representation of a request id everywhere in TypeScript. Raw
|
|
294
|
+
* {@link RequestId} bytes appear only at the Compact boundary (state
|
|
295
|
+
* readers, compiled-circuit calls); the moment an id crosses that boundary it
|
|
296
|
+
* becomes this type. Branded (the TS analogue of Compact's `new type`) so an
|
|
297
|
+
* arbitrary string cannot pose as a request id: mint one with
|
|
298
|
+
* {@link requestIdHex} (from ledger bytes) or {@link parseRequestIdHex}
|
|
299
|
+
* (from user input), and go back to bytes with {@link requestIdBytes}.
|
|
300
|
+
*/
|
|
301
|
+
export type RequestIdHex = string & {
|
|
302
|
+
readonly [requestIdHexBrand]: true;
|
|
303
|
+
};
|
|
304
|
+
/** Plain-JS index parsed out of the ledger, keyed by hex request id. */
|
|
305
|
+
export type SignBidirectionalRequestIndex = Map<RequestIdHex, SignBidirectionalRequest>;
|
|
306
|
+
/**
|
|
307
|
+
* Render bytes as a lowercase hex string, no `0x` prefix.
|
|
308
|
+
*
|
|
309
|
+
* @param bytes - The bytes to render.
|
|
310
|
+
* @returns Lowercase hex, two chars per byte.
|
|
311
|
+
*/
|
|
312
|
+
export declare function bytesToHex(bytes: Uint8Array): string;
|
|
313
|
+
/**
|
|
314
|
+
* Render a request id in its canonical TS form (see
|
|
315
|
+
* {@link RequestIdHex}) — also usable as a JS `Map` key, which raw
|
|
316
|
+
* `Uint8Array` ids are not (they compare by reference).
|
|
317
|
+
*
|
|
318
|
+
* @param requestId - 32-byte request id.
|
|
319
|
+
* @returns The branded 64-char lowercase hex string, no `0x` prefix.
|
|
320
|
+
*/
|
|
321
|
+
export declare function requestIdHex(requestId: RequestId): RequestIdHex;
|
|
322
|
+
/**
|
|
323
|
+
* Validate and normalize an untrusted string (CLI argument, config value)
|
|
324
|
+
* into a {@link RequestIdHex}: an optional `0x` prefix is stripped and
|
|
325
|
+
* the digits lowercased before validation.
|
|
326
|
+
*
|
|
327
|
+
* @param value - The candidate request id string.
|
|
328
|
+
* @returns The branded, normalized request id hex.
|
|
329
|
+
* @throws Error if the value is not 64 hex chars after normalization.
|
|
330
|
+
*/
|
|
331
|
+
export declare function parseRequestIdHex(value: string): RequestIdHex;
|
|
332
|
+
/**
|
|
333
|
+
* Decode a request id back to its 32 raw bytes for the Compact boundary
|
|
334
|
+
* (compiled-circuit calls, ledger lookups).
|
|
335
|
+
*
|
|
336
|
+
* @param id - The request id in canonical hex form.
|
|
337
|
+
* @returns The 32-byte request id.
|
|
338
|
+
*/
|
|
339
|
+
export declare function requestIdBytes(id: RequestIdHex): RequestId;
|
|
340
|
+
/** Byte width of the path field (Compact `Bytes<256>`). */
|
|
341
|
+
export declare const PATH_BYTES = 256;
|
|
342
|
+
/**
|
|
343
|
+
* Build the canonical MPC derivation path for an identity commitment: the
|
|
344
|
+
* lowercase hex of the commitment as ASCII, zero-padded to {@link PATH_BYTES}
|
|
345
|
+
* — exactly what the contract's `assertPathCommitment` accepts. Use this to
|
|
346
|
+
* populate {@link SignBidirectionalRequest.path} when constructing requests.
|
|
347
|
+
*
|
|
348
|
+
* @param commitment - 32-byte identity commitment.
|
|
349
|
+
* @returns The 256-byte path field value.
|
|
350
|
+
*/
|
|
351
|
+
export declare function signetPathOfCommitment(commitment: Uint8Array): Uint8Array;
|
|
352
|
+
/**
|
|
353
|
+
* Parse the on-ledger request map into a plain-JS index keyed by hex
|
|
354
|
+
* request id.
|
|
355
|
+
*
|
|
356
|
+
* @param ledgerIndex - Iterable of `[requestId, request]` entries — e.g. a
|
|
357
|
+
* contract's `ledger(state).signetRequestsIndex` (any
|
|
358
|
+
* {@link SignBidirectionalRequestLedgerIndex}).
|
|
359
|
+
* @returns A new `Map` from {@link requestIdHex} key to request record.
|
|
360
|
+
*/
|
|
361
|
+
export declare function toSignBidirectionalRequestIndex(ledgerIndex: Iterable<[RequestId, SignBidirectionalRequest]>): SignBidirectionalRequestIndex;
|
|
362
|
+
export {};
|
|
363
|
+
//# sourceMappingURL=signet-requests.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signet-requests.d.ts","sourceRoot":"","sources":["../src/signet-requests.ts"],"names":[],"mappings":"AAgBA,OAAO,EAOL,KAAK,WAAW,EACjB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAwB,SAAS,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAItE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAE3E;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC;AAEnC;;;;;GAKG;AACH,eAAO,MAAM,WAAW;IACtB,6DAA6D;;IAE7D;;;;OAIG;;CAEK,CAAC;AAEX;;;;GAIG;AACH,MAAM,WAAW,KAAK,CAAC,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,CAAC,CAAC;CACV;AAED;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B,qEAAqE;IACrE,QAAQ,EAAE,UAAU,CAAC;IACrB,6EAA6E;IAC7E,OAAO,EAAE,MAAM,CAAC;IAChB,6EAA6E;IAC7E,KAAK,EAAE,UAAU,EAAE,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,iEAAiE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