@sig-net/midnight 0.15.0 → 0.17.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 +113 -49
- package/dist/constants.d.ts +55 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +85 -5
- package/dist/constants.js.map +1 -1
- package/dist/ecdsa-attestation.d.ts +6 -5
- package/dist/ecdsa-attestation.d.ts.map +1 -1
- package/dist/ecdsa-attestation.js +5 -4
- package/dist/ecdsa-attestation.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/managed/compiler/contract-manifest.json +2 -2
- package/dist/managed/contract/index.js +31 -31
- package/dist/managed/contract/index.js.map +1 -1
- package/dist/signature-requests-state-reader.d.ts +7 -7
- package/dist/signature-requests-state-reader.js +7 -7
- package/dist/signature-response-verification.d.ts +1 -1
- package/dist/signature-response-verification.d.ts.map +1 -1
- package/dist/signature-response-verification.js +3 -3
- package/dist/signature-response-verification.js.map +1 -1
- package/dist/signature-state-reading.js +2 -2
- package/dist/signature-state-reading.js.map +1 -1
- package/dist/signet-contract-events.d.ts +267 -0
- package/dist/signet-contract-events.d.ts.map +1 -0
- package/dist/signet-contract-events.js +272 -0
- package/dist/signet-contract-events.js.map +1 -0
- package/dist/signet-evtype2tx-requests.d.ts +4 -4
- package/dist/signet-evtype2tx-requests.d.ts.map +1 -1
- package/dist/signet-evtype2tx-requests.js +3 -3
- package/dist/signet-request-feed.d.ts +61 -33
- package/dist/signet-request-feed.d.ts.map +1 -1
- package/dist/signet-request-feed.js +116 -62
- package/dist/signet-request-feed.js.map +1 -1
- package/dist/signet-request-response-reader.d.ts +62 -55
- package/dist/signet-request-response-reader.d.ts.map +1 -1
- package/dist/signet-request-response-reader.js +85 -99
- package/dist/signet-request-response-reader.js.map +1 -1
- package/dist/signet-requests.js +2 -2
- package/dist/signet-requests.js.map +1 -1
- package/package.json +2 -2
- package/src/Signet.compact +45 -36
- package/dist/signet-contract-state-reader.d.ts +0 -247
- package/dist/signet-contract-state-reader.d.ts.map +0 -1
- package/dist/signet-contract-state-reader.js +0 -363
- package/dist/signet-contract-state-reader.js.map +0 -1
- package/dist/signet-request-resolver.d.ts +0 -60
- package/dist/signet-request-resolver.d.ts.map +0 -1
- package/dist/signet-request-resolver.js +0 -78
- package/dist/signet-request-resolver.js.map +0 -1
package/src/Signet.compact
CHANGED
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
// Terms:
|
|
7
7
|
// - client contract(s): contracts on the Midnight blockchain that integrate with the Signet Distributed MPC
|
|
8
8
|
// to execute arbitrary transactions on foreign blockchains.
|
|
9
|
-
// - Signet singleton: a single contract on the Midnight blockchain
|
|
10
|
-
// signature requests and
|
|
11
|
-
//
|
|
9
|
+
// - Signet singleton: a single contract on the Midnight blockchain through which clients notify the MPC of
|
|
10
|
+
// signature requests, and through which the MPC posts back signatures and signed attestations
|
|
11
|
+
// of foreign executions. Each post is emitted as a contract event (the execution
|
|
12
|
+
// outputs themselves travel off chain).
|
|
12
13
|
//
|
|
13
14
|
// Usage:
|
|
14
15
|
// // Import this module at the start of a contract (resolved through node_modules via COMPACT_PATH):
|
|
@@ -28,28 +29,34 @@
|
|
|
28
29
|
// - SignBidirectionalEventNotification: Notification delivered by client contracts via cross contract call to Signet singleton
|
|
29
30
|
// (via SignetSigner interface) to notify the MPC of a SignBidirectionalEvent.
|
|
30
31
|
// - SignatureRespondedEvent: Counterpart to SignBidirectionalEvent containing MPC generated signature requested by a SignBidirectionalEvent.
|
|
31
|
-
// Posted by MPC
|
|
32
|
+
// Posted by the MPC through the Signet singleton, which emits it as a contract
|
|
33
|
+
// event. Clients extract it to build a signed transaction.
|
|
32
34
|
// - RespondBidirectionalEvent: Attestation of a transaction executed on a foreign blockchain: the MPC's ECDSA
|
|
33
35
|
// signature over the attestation digest of the request id and serialised output
|
|
34
36
|
// (see calculateSignetAttestationDigest), signed with the MPC's RESPONSE key for
|
|
35
37
|
// the requesting contract: the key derived from the client contract's address +
|
|
36
38
|
// the fixed path "midnight response key". Both the digest and the output itself
|
|
37
|
-
// travel off chain. Posted by MPC
|
|
38
|
-
//
|
|
39
|
-
// contract.
|
|
39
|
+
// travel off chain. Posted by the MPC through the Signet singleton, which
|
|
40
|
+
// emits it as a contract event. Clients extract it, verify it (see
|
|
41
|
+
// verifyRespondBidirectionalEvent) and deliver it back to the client contract.
|
|
40
42
|
//
|
|
41
43
|
// These key types are best understood within the sign bidirectional flow that they enable:
|
|
42
|
-
// 1. Client contract stores a SignBidirectionalEvent in a SignBidirectionalEventMap its own ledger
|
|
43
|
-
// (against the calculated RequestId) and requests a signature from the MPC
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
// 2. MPC polls the Signet singleton contract's
|
|
47
|
-
//
|
|
48
|
-
// signature and
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
//
|
|
44
|
+
// 1. Client contract stores a SignBidirectionalEvent in a SignBidirectionalEventMap in its own ledger
|
|
45
|
+
// (against the calculated RequestId) and requests a signature from the MPC via a cross contract call
|
|
46
|
+
// against the SignetSigner interface. The Signet singleton emits the
|
|
47
|
+
// SignBidirectionalEventNotification as a contract event, the RequestId disclosed beside it.
|
|
48
|
+
// 2. MPC polls the Signet singleton contract's events for SignBidirectionalEventNotifications and uses
|
|
49
|
+
// each one to look the declared SignBidirectionalEvent signature request up in the named client's own ledger.
|
|
50
|
+
// It generates the signature and posts a SignatureRespondedEvent (the requested signature) through
|
|
51
|
+
// the Signet singleton, which emits it as a contract event.
|
|
52
|
+
// 3. Client polls the Signet singleton contract's SignatureRespondedEvent events. Each event carries
|
|
53
|
+
// the request id it answers beside the signature. The id is unauthenticated routing data: the client
|
|
54
|
+
// reads its own request's posts by id, verifies each candidate, and takes the first one whose
|
|
55
|
+
// signature recovers to its derived key. Then it broadcasts the signed txn to the destination chain.
|
|
56
|
+
// 4. MPC observes txn execution on destination chain and posts a RespondBidirectionalEvent attestation
|
|
57
|
+
// through the central Signet contract, which emits it as a contract event beside the request id.
|
|
58
|
+
// The client polls its request's posts and takes the first one that verifies over the request id
|
|
59
|
+
// and output.
|
|
53
60
|
// The client recovers the execution output itself off chain (for EVM: the mined
|
|
54
61
|
// call's return data via debug_traceTransaction, also served by the fakenet
|
|
55
62
|
// responder's /responses/{requestId} helper API) and hands output plus attestation
|
|
@@ -58,7 +65,8 @@
|
|
|
58
65
|
// Read more:
|
|
59
66
|
// - For full integration examples (such as an ERC20 cross chain vault example) see
|
|
60
67
|
// the Midnight Examples repository at: https://github.com/sig-net/midnight-examples.
|
|
61
|
-
// -
|
|
68
|
+
// - The sign bidirectional flow and key derivation: this package's README
|
|
69
|
+
// ("Sign bidirectional flow", "Derived keys").
|
|
62
70
|
// - Compact language reference (modules, types):
|
|
63
71
|
// https://docs.midnight.network/compact/reference/compact-reference
|
|
64
72
|
|
|
@@ -79,11 +87,15 @@ module Signet {
|
|
|
79
87
|
|
|
80
88
|
// MPC Key Derivation Parameters.
|
|
81
89
|
// Every key the MPC signs with is scoped by the requesting contract:
|
|
82
|
-
// derivedSigningKey = f(mpcRootKey[keyVersion], sender, path)
|
|
83
|
-
//
|
|
84
|
-
// for
|
|
85
|
-
//
|
|
86
|
-
//
|
|
90
|
+
// derivedSigningKey = f(mpcRootKey[keyVersion], caip2ChainId, sender, hex::encode(path))
|
|
91
|
+
// where caip2ChainId is the CAIP-2 id of the ORIGINATING chain (the Midnight
|
|
92
|
+
// variant for requests made from Midnight contracts), not this record's target
|
|
93
|
+
// caip2Id. The path is 32 opaque bytes of the client contract's choosing (e.g a
|
|
94
|
+
// fixed literal for a contract-owned account or a hash of a caller's secret for
|
|
95
|
+
// per-user accounts): no format is enforced, any 32 bytes are valid. CRITICAL:
|
|
96
|
+
// the MPC renders the path as hex::encode(path) before deriving (lowercase hex
|
|
97
|
+
// of the full 32 bytes, no trimming, no 0x prefix). The sender is always part
|
|
98
|
+
// of the derivation, so no contract can reach another contract's derived keys.
|
|
87
99
|
keyVersion: Uint<8>; // MPC root-key version to derive from. Set to 1.
|
|
88
100
|
path: Bytes<32>; // Key derivation path: 32 opaque bytes, client contract's choice.
|
|
89
101
|
|
|
@@ -199,11 +211,13 @@ module Signet {
|
|
|
199
211
|
// Called by client contracts to notify the MPC of a SignBidirectionalEvent.
|
|
200
212
|
circuit signBidirectional(
|
|
201
213
|
// Canonical id of the SignBidirectionalEvent (calculate with calculateRequestId).
|
|
214
|
+
// Disclosed in the emitted notification event: the MPC looks this id up in the
|
|
215
|
+
// caller's own request map.
|
|
202
216
|
requestId: RequestId,
|
|
203
217
|
// Versioned notification of the SignBidirectionalEvent
|
|
204
218
|
// (construct with constructSignBidirectionalEventNotificationV1).
|
|
205
219
|
notification: SignBidirectionalEventNotification
|
|
206
|
-
):
|
|
220
|
+
): [];
|
|
207
221
|
}
|
|
208
222
|
|
|
209
223
|
// Notification delivered by client contracts via cross contract call to Signet singleton
|
|
@@ -310,8 +324,10 @@ module Signet {
|
|
|
310
324
|
// signature = signSECP256k1(mpcResponseKey, attestationDigest)
|
|
311
325
|
//
|
|
312
326
|
// Where the MPC response key is a per-client-contract key derived using the same derivation function
|
|
313
|
-
// as request signing keys, with the path set to the fixed "midnight response key"
|
|
314
|
-
//
|
|
327
|
+
// as request signing keys, with the path set to the fixed "midnight response key" (a protocol
|
|
328
|
+
// string that enters the derivation verbatim, unlike a request's 32 path bytes which are
|
|
329
|
+
// hex-encoded first):
|
|
330
|
+
// mpcResponseKey = f(mpcRootKey[keyVersion], caip2ChainId, sender, "midnight response key")
|
|
315
331
|
//
|
|
316
332
|
// Storage & Verification:
|
|
317
333
|
// The execution output is of variable size, so it travels off chain, and the digest
|
|
@@ -319,19 +335,12 @@ module Signet {
|
|
|
319
335
|
// the attestation digest and verifies the signature in-circuit via
|
|
320
336
|
// verifyRespondBidirectionalEvent against its derived MPC response key. The signature
|
|
321
337
|
// is the ONLY thing that distinguishes a genuine post from garbage: the Signet
|
|
322
|
-
// singleton is an unauthenticated log and
|
|
338
|
+
// singleton is an unauthenticated log and emits every post unverified.
|
|
323
339
|
export struct RespondBidirectionalEvent {
|
|
324
340
|
// The MPC's ECDSA signature over the attestation digest.
|
|
325
341
|
signature: Signature;
|
|
326
342
|
}
|
|
327
343
|
|
|
328
|
-
// SignetMapKey used to locate SignBidirectionalEventNotifications, SignatureRespondedEvent and
|
|
329
|
-
// RespondBidirectionalEvents in Signet singleton contract storage.
|
|
330
|
-
export struct SignetMapKey {
|
|
331
|
-
count: Uint<64>;
|
|
332
|
-
requestId: RequestId;
|
|
333
|
-
};
|
|
334
|
-
|
|
335
344
|
// Calculates the 32-byte attestation digest for a remote execution output:
|
|
336
345
|
// attestationDigest = keccak256(requestId + serializedOutput)
|
|
337
346
|
//
|
|
@@ -371,7 +380,7 @@ module Signet {
|
|
|
371
380
|
// signatures, and one that is not simply fails to verify.
|
|
372
381
|
//
|
|
373
382
|
// Note: Client contracts must run this check before consuming outputs, as the Signet
|
|
374
|
-
// singleton
|
|
383
|
+
// singleton emits responses unverified.
|
|
375
384
|
export pure circuit verifyRespondBidirectionalEvent<#serializedOutputLength>(
|
|
376
385
|
requestId: RequestId,
|
|
377
386
|
serializedOutput: Bytes<serializedOutputLength>,
|
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import { type CompactType } from "@midnight-ntwrk/compact-runtime";
|
|
2
|
-
import { type RequestId, type RequestIdHex } from "./signet-requests.ts";
|
|
3
|
-
import { type RawContractState } from "./signature-state-reading.ts";
|
|
4
|
-
/** Signet contract layout: the notification counter map is ledger field 0. */
|
|
5
|
-
export declare const SIGN_BIDIRECTIONAL_EVENT_NOTIFICATION_COUNTER_MAP_FIELD = 0;
|
|
6
|
-
/** Signet contract layout: the notification map is ledger field 1. */
|
|
7
|
-
export declare const SIGN_BIDIRECTIONAL_EVENT_NOTIFICATION_MAP_FIELD = 1;
|
|
8
|
-
/** Signet contract layout: the `respond` counter map is ledger field 2. */
|
|
9
|
-
export declare const RESPOND_COUNTER_MAP_FIELD = 2;
|
|
10
|
-
/** Signet contract layout: the `respond` post log is ledger field 3. */
|
|
11
|
-
export declare const RESPOND_MAP_FIELD = 3;
|
|
12
|
-
/** Signet contract layout: the respond-bidirectional counter map is ledger field 4. */
|
|
13
|
-
export declare const RESPOND_BIDIRECTIONAL_COUNTER_MAP_FIELD = 4;
|
|
14
|
-
/** Signet contract layout: the respond-bidirectional map is ledger field 5. */
|
|
15
|
-
export declare const RESPOND_BIDIRECTIONAL_MAP_FIELD = 5;
|
|
16
|
-
/**
|
|
17
|
-
* A curve point in affine coordinates (Compact `AffinePoint`), SEC1
|
|
18
|
-
* big-endian, the same shape the sig-net EVM and Solana signer contracts
|
|
19
|
-
* expose.
|
|
20
|
-
*/
|
|
21
|
-
export interface AffinePoint {
|
|
22
|
-
/** The x coordinate, 32 big-endian bytes. */
|
|
23
|
-
x: Uint8Array;
|
|
24
|
-
/** The y coordinate, 32 big-endian bytes. */
|
|
25
|
-
y: Uint8Array;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* The MPC's canonical ECDSA signature as both respond events store it
|
|
29
|
-
* (Compact `Signature`, matching the MPC's own
|
|
30
|
-
* `Signature { big_r, s, recovery_id }` and the EVM/Solana signer
|
|
31
|
-
* contracts): `bigR` the full nonce point so consumers never decompress,
|
|
32
|
-
* `s` big-endian, `recoveryId` the parity of R.y. Stored UNVERIFIED like
|
|
33
|
-
* everything else on the singleton. Convert with
|
|
34
|
-
* `ecdsaSignatureToMpcSignature` / `mpcSignatureToEcdsaSignature`.
|
|
35
|
-
*/
|
|
36
|
-
export interface MpcSignature {
|
|
37
|
-
/** The signature's nonce point R. */
|
|
38
|
-
bigR: AffinePoint;
|
|
39
|
-
/** Signature scalar s, 32 big-endian bytes. */
|
|
40
|
-
s: Uint8Array;
|
|
41
|
-
/** Recovery id (parity of R.y): 0 or 1. */
|
|
42
|
-
recoveryId: bigint;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* The MPC's signature over the requested EVM transaction (Compact
|
|
46
|
-
* `SignatureRespondedEvent`): decode to an ethers signature with
|
|
47
|
-
* `signatureRespondedEventToSignature`. The request id it answers lives in
|
|
48
|
-
* the map key.
|
|
49
|
-
*/
|
|
50
|
-
export interface SignatureRespondedEvent {
|
|
51
|
-
/** The requested signature over the transaction the request describes. */
|
|
52
|
-
signature: MpcSignature;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Hand-composed descriptor for {@link SignatureRespondedEvent}: the single
|
|
56
|
-
* {@link MpcSignature} field, matching the Compact struct.
|
|
57
|
-
*/
|
|
58
|
-
export declare const signatureRespondedEventType: CompactType<SignatureRespondedEvent>;
|
|
59
|
-
/**
|
|
60
|
-
* The MPC's respond-bidirectional attestation of a request's remote EVM
|
|
61
|
-
* execution (Compact `RespondBidirectionalEvent`): the ECDSA signature over
|
|
62
|
-
* the attestation digest `keccak256(requestId || serializedOutput)`. Both the
|
|
63
|
-
* digest and the output travel off chain: readers fetch the output, recompute
|
|
64
|
-
* the digest (`calculateSignetAttestationDigest`) and verify the signature
|
|
65
|
-
* over it. Stored UNVERIFIED by the signet contract, so that signature check
|
|
66
|
-
* against the expected MPC response key is the only thing separating a
|
|
67
|
-
* genuine post from garbage (in-circuit via
|
|
68
|
-
* `verifyRespondBidirectionalEvent`, off chain via
|
|
69
|
-
* {@link verifyRespondBidirectionalSignature}).
|
|
70
|
-
*/
|
|
71
|
-
export interface RespondBidirectionalEvent {
|
|
72
|
-
/** ECDSA signature over the attestation digest. */
|
|
73
|
-
signature: MpcSignature;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Composite key of one posted entry in the signet contract's maps (Compact
|
|
77
|
-
* `SignetMapKey`): the request id it belongs to plus the post's 0-based
|
|
78
|
-
* count. Field order (count first, then request id) mirrors the Compact
|
|
79
|
-
* struct.
|
|
80
|
-
*/
|
|
81
|
-
export interface SignetMapKey {
|
|
82
|
-
/** 0-based position of this post among the entries for {@link requestId}. */
|
|
83
|
-
count: bigint;
|
|
84
|
-
/** 32-byte id of the request this entry belongs to. */
|
|
85
|
-
requestId: RequestId;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Hand-composed descriptor for {@link SignetMapKey}, the map key of every
|
|
89
|
-
* posted-entry map in the signet contract. Field order (count, then
|
|
90
|
-
* requestId) must match the Compact struct.
|
|
91
|
-
*/
|
|
92
|
-
export declare const signetMapKeyType: CompactType<SignetMapKey>;
|
|
93
|
-
/**
|
|
94
|
-
* Hand-composed descriptor for {@link RespondBidirectionalEvent}: the single
|
|
95
|
-
* {@link MpcSignature} field, matching the Compact struct.
|
|
96
|
-
*/
|
|
97
|
-
export declare const respondBidirectionalEventType: CompactType<RespondBidirectionalEvent>;
|
|
98
|
-
/**
|
|
99
|
-
* Raw twin of the Compact `SignBidirectionalEventNotification` struct as
|
|
100
|
-
* stored on-ledger: the version tag plus the still-packed 128-byte payload.
|
|
101
|
-
* Decode the payload with {@link decodeSignBidirectionalNotification}.
|
|
102
|
-
*/
|
|
103
|
-
export interface SignBidirectionalNotificationRecord {
|
|
104
|
-
/** Payload layout tag (Compact `Uint<8>`): 1 = the V1 layout. */
|
|
105
|
-
version: bigint;
|
|
106
|
-
/** The packed payload bytes, exactly as the registering circuit built them. */
|
|
107
|
-
payload: Uint8Array;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Hand-composed descriptor for {@link SignBidirectionalNotificationRecord}.
|
|
111
|
-
* Field order (version, payload) must match the Compact struct.
|
|
112
|
-
*/
|
|
113
|
-
export declare const signBidirectionalNotificationType: CompactType<SignBidirectionalNotificationRecord>;
|
|
114
|
-
/**
|
|
115
|
-
* A decoded V1 notification from the signet contract's registry: the flat
|
|
116
|
-
* pointer a client registered to tell the MPC a request was stored, and
|
|
117
|
-
* WHERE to read the authenticated copy. The request id is NOT in the payload:
|
|
118
|
-
* it lives in the registry map key the record was stored under. Never trusted
|
|
119
|
-
* on its own: the resolver authenticates by reading the request back from
|
|
120
|
-
* {@link callerAddress}'s own ledger (see signet-request-resolver.ts).
|
|
121
|
-
*/
|
|
122
|
-
export interface SignBidirectionalNotification {
|
|
123
|
-
/** Payload layout tag: this decoder only produces version 1. */
|
|
124
|
-
version: number;
|
|
125
|
-
/**
|
|
126
|
-
* Address of the contract whose request map holds the request, rendered
|
|
127
|
-
* as lowercase hex, no `0x` prefix: directly usable as a
|
|
128
|
-
* `queryContractState` argument. The MPC reads the request from THIS
|
|
129
|
-
* contract's authenticated state. The field itself confers no authority.
|
|
130
|
-
*/
|
|
131
|
-
callerAddress: string;
|
|
132
|
-
/**
|
|
133
|
-
* Resolved ledger-tree path of the `SignBidirectionalEventMap` in
|
|
134
|
-
* {@link callerAddress}, as compactc records it in that contract's
|
|
135
|
-
* `contract-info.json` (`"index"`): `[4]` for a flat contract's field 4,
|
|
136
|
-
* `[1, 14]` once chunking applies. The reader follows it node for node
|
|
137
|
-
* (see {@link signetFieldNodeByPath}) and never assumes a layout.
|
|
138
|
-
*/
|
|
139
|
-
requestsPath: number[];
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Unpack a stored {@link SignBidirectionalNotificationRecord}'s payload by
|
|
143
|
-
* the fixed V1 offsets: the decode twin of the compiled
|
|
144
|
-
* `constructSignBidirectionalEventNotificationV1` circuit (byte plumbing
|
|
145
|
-
* only: the pack↔decode lockstep is pinned by the state-reader unit test that
|
|
146
|
-
* round-trips through the real circuit). V1 layout:
|
|
147
|
-
* callerAddress (32) ++ requestsPathDepth (1) ++ requestsPath (4) ++ zero
|
|
148
|
-
* padding (91), where only the first `requestsPathDepth` path bytes are
|
|
149
|
-
* meaningful.
|
|
150
|
-
*
|
|
151
|
-
* Fails closed on an unrecognised `version`: a future payload layout adds a
|
|
152
|
-
* branch here rather than silently misinterpreting bytes under the V1 offsets.
|
|
153
|
-
*
|
|
154
|
-
* @param record - The raw on-ledger record.
|
|
155
|
-
* @returns The decoded notification, its `requestsPath` trimmed to the
|
|
156
|
-
* declared depth.
|
|
157
|
-
* @throws Error if the record's `version` is not one this decoder understands,
|
|
158
|
-
* or its `requestsPathDepth` is zero or exceeds {@link MAX_LEDGER_PATH_DEPTH}.
|
|
159
|
-
*/
|
|
160
|
-
export declare function decodeSignBidirectionalNotification(record: SignBidirectionalNotificationRecord): SignBidirectionalNotification;
|
|
161
|
-
/**
|
|
162
|
-
* Plain-JS notification registry parsed out of the ledger: hex request id
|
|
163
|
-
* (from the `SignetMapKey` the notification was stored under) to the raw
|
|
164
|
-
* stored record. Re-notifies append under higher counts. This index keeps
|
|
165
|
-
* the FIRST post (count 0) per request id, the record the original submit
|
|
166
|
-
* registered. Decode each record with
|
|
167
|
-
* {@link decodeSignBidirectionalNotification}.
|
|
168
|
-
*/
|
|
169
|
-
export type SignBidirectionalNotificationIndex = Map<RequestIdHex, SignBidirectionalNotificationRecord>;
|
|
170
|
-
/**
|
|
171
|
-
* Plain-JS counter map parsed out of the ledger: hex request id (see
|
|
172
|
-
* {@link requestIdHex}) to the number of entries posted for that request.
|
|
173
|
-
* Entries in the corresponding map exist for counts `0 .. value - 1`.
|
|
174
|
-
*/
|
|
175
|
-
export type SignetCounterIndex = Map<RequestIdHex, bigint>;
|
|
176
|
-
/**
|
|
177
|
-
* Plain-JS signature response log parsed out of the ledger, keyed by
|
|
178
|
-
* {@link signetMapEntryKey} (`"<hexRequestId>:<count>"`) so the composite
|
|
179
|
-
* Compact key survives as a usable JS `Map` key.
|
|
180
|
-
*/
|
|
181
|
-
export type SignatureResponseIndex = Map<string, SignatureRespondedEvent>;
|
|
182
|
-
/**
|
|
183
|
-
* Plain-JS respond-bidirectional log parsed out of the ledger, keyed by
|
|
184
|
-
* {@link signetMapEntryKey} (`"<hexRequestId>:<count>"`).
|
|
185
|
-
*/
|
|
186
|
-
export type RespondBidirectionalIndex = Map<string, RespondBidirectionalEvent>;
|
|
187
|
-
/**
|
|
188
|
-
* Build the flattened JS map key for a `(requestId, count)` pair: the
|
|
189
|
-
* composite Compact {@link SignetMapKey} as a string so it works as a JS
|
|
190
|
-
* `Map` key.
|
|
191
|
-
*
|
|
192
|
-
* @param id - The request id the entry belongs to, in canonical hex form.
|
|
193
|
-
* @param count - 0-based post count within that request.
|
|
194
|
-
* @returns `"<hexRequestId>:<count>"`.
|
|
195
|
-
*/
|
|
196
|
-
export declare function signetMapEntryKey(id: RequestIdHex, count: bigint): string;
|
|
197
|
-
/**
|
|
198
|
-
* Read ONLY the notification registry (ledger field
|
|
199
|
-
* {@link SIGN_BIDIRECTIONAL_EVENT_NOTIFICATION_MAP_FIELD}) out of raw signet
|
|
200
|
-
* contract state: the poll-loop primitive of {@link SignetRequestFeed},
|
|
201
|
-
* which cycles frequently and has no use for the response fields. One record
|
|
202
|
-
* per request id (the count-0 post, see
|
|
203
|
-
* {@link SignBidirectionalNotificationIndex}).
|
|
204
|
-
*
|
|
205
|
-
* @param raw - Raw contract state, e.g. `queryContractState(address).data`
|
|
206
|
-
* from the indexer or `ctx.currentQueryContext.state` from the simulator.
|
|
207
|
-
* @returns The registry, keyed by the hex request id of each entry's map key.
|
|
208
|
-
* @throws Error if the field is missing or is not a Map.
|
|
209
|
-
*/
|
|
210
|
-
export declare function readSignBidirectionalNotificationIndexFromState(raw: RawContractState): SignBidirectionalNotificationIndex;
|
|
211
|
-
/**
|
|
212
|
-
* The decoded ledger fields of the signet contract: the three
|
|
213
|
-
* (counter map, entry map) pairs, namely notifications (fields 0/1), signature
|
|
214
|
-
* responses (fields 2/3), respond-bidirectional responses (fields 4/5).
|
|
215
|
-
* Together they give a poller everything the contract ever records about a
|
|
216
|
-
* request. All entries are UNAUTHENTICATED: verify before trusting.
|
|
217
|
-
*/
|
|
218
|
-
export interface SignetContractLedger {
|
|
219
|
-
/** Notification post counts per request id (ledger field 0). */
|
|
220
|
-
signBidirectionalEventNotificationCounterMap: SignetCounterIndex;
|
|
221
|
-
/**
|
|
222
|
-
* The notification registry (ledger field 1), one record per request id
|
|
223
|
-
* (count-0 post).
|
|
224
|
-
*/
|
|
225
|
-
signBidirectionalEventNotificationMap: SignBidirectionalNotificationIndex;
|
|
226
|
-
/** `respond` post counts per request id (ledger field 2). */
|
|
227
|
-
respondCounterMap: SignetCounterIndex;
|
|
228
|
-
/** The `respond` post log (ledger field 3), keyed by {@link signetMapEntryKey}. */
|
|
229
|
-
respondMap: SignatureResponseIndex;
|
|
230
|
-
/** Respond-bidirectional post counts per request id (ledger field 4). */
|
|
231
|
-
respondBidirectionalCounterMap: SignetCounterIndex;
|
|
232
|
-
/** The respond-bidirectional log (ledger field 5), keyed by {@link signetMapEntryKey}. */
|
|
233
|
-
respondBidirectionalMap: RespondBidirectionalIndex;
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* MPC-/client-style read: parse the signet contract's ledger fields out of
|
|
237
|
-
* raw contract state by field position alone, with no compiled contract and
|
|
238
|
-
* no generated `ledger()`, only the declaration-order layout and the
|
|
239
|
-
* canonical descriptors above.
|
|
240
|
-
*
|
|
241
|
-
* @param raw - Raw contract state, e.g. `queryContractState(address).data`
|
|
242
|
-
* from the indexer or `ctx.currentQueryContext.state` from the simulator.
|
|
243
|
-
* @returns The decoded {@link SignetContractLedger}.
|
|
244
|
-
* @throws Error if a field is missing or has the wrong state-value shape.
|
|
245
|
-
*/
|
|
246
|
-
export declare function readSignetContractLedgerFromState(raw: RawContractState): SignetContractLedger;
|
|
247
|
-
//# sourceMappingURL=signet-contract-state-reader.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signet-contract-state-reader.d.ts","sourceRoot":"","sources":["../src/signet-contract-state-reader.ts"],"names":[],"mappings":"AAiBA,OAAO,EAGL,KAAK,WAAW,EACjB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAGL,KAAK,SAAS,EACd,KAAK,YAAY,EAClB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAIL,KAAK,gBAAgB,EACtB,MAAM,8BAA8B,C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