@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.
Files changed (90) hide show
  1. package/README.md +20 -0
  2. package/dist/constants.d.ts +62 -0
  3. package/dist/constants.d.ts.map +1 -0
  4. package/dist/constants.js +83 -0
  5. package/dist/constants.js.map +1 -0
  6. package/dist/epsilon-derivation.d.ts +32 -0
  7. package/dist/epsilon-derivation.d.ts.map +1 -0
  8. package/dist/epsilon-derivation.js +54 -0
  9. package/dist/epsilon-derivation.js.map +1 -0
  10. package/dist/index.d.ts +26 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +30 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/managed/compiler/contract-info.json +165 -0
  15. package/dist/managed/compiler/contract-manifest.json +32 -0
  16. package/dist/managed/contract/index.d.ts +65 -0
  17. package/dist/managed/contract/index.js +611 -0
  18. package/dist/managed/contract/index.js.map +8 -0
  19. package/dist/schnorr.d.ts +100 -0
  20. package/dist/schnorr.d.ts.map +1 -0
  21. package/dist/schnorr.js +144 -0
  22. package/dist/schnorr.js.map +1 -0
  23. package/dist/signature-requests-state-reader.d.ts +74 -0
  24. package/dist/signature-requests-state-reader.d.ts.map +1 -0
  25. package/dist/signature-requests-state-reader.js +167 -0
  26. package/dist/signature-requests-state-reader.js.map +1 -0
  27. package/dist/signature-response-verification.d.ts +27 -0
  28. package/dist/signature-response-verification.d.ts.map +1 -0
  29. package/dist/signature-response-verification.js +45 -0
  30. package/dist/signature-response-verification.js.map +1 -0
  31. package/dist/signature-state-reading.d.ts +36 -0
  32. package/dist/signature-state-reading.d.ts.map +1 -0
  33. package/dist/signature-state-reading.js +62 -0
  34. package/dist/signature-state-reading.js.map +1 -0
  35. package/dist/signet-contract-state-reader.d.ts +146 -0
  36. package/dist/signet-contract-state-reader.d.ts.map +1 -0
  37. package/dist/signet-contract-state-reader.js +226 -0
  38. package/dist/signet-contract-state-reader.js.map +1 -0
  39. package/dist/signet-event-observer.d.ts +102 -0
  40. package/dist/signet-event-observer.d.ts.map +1 -0
  41. package/dist/signet-event-observer.js +127 -0
  42. package/dist/signet-event-observer.js.map +1 -0
  43. package/dist/signet-events.d.ts +175 -0
  44. package/dist/signet-events.d.ts.map +1 -0
  45. package/dist/signet-events.js +210 -0
  46. package/dist/signet-events.js.map +1 -0
  47. package/dist/signet-request-feed.d.ts +78 -0
  48. package/dist/signet-request-feed.d.ts.map +1 -0
  49. package/dist/signet-request-feed.js +116 -0
  50. package/dist/signet-request-feed.js.map +1 -0
  51. package/dist/signet-request-resolver.d.ts +58 -0
  52. package/dist/signet-request-resolver.d.ts.map +1 -0
  53. package/dist/signet-request-resolver.js +76 -0
  54. package/dist/signet-request-resolver.js.map +1 -0
  55. package/dist/signet-request-response-reader.d.ts +160 -0
  56. package/dist/signet-request-response-reader.d.ts.map +1 -0
  57. package/dist/signet-request-response-reader.js +198 -0
  58. package/dist/signet-request-response-reader.js.map +1 -0
  59. package/dist/signet-requests.d.ts +363 -0
  60. package/dist/signet-requests.d.ts.map +1 -0
  61. package/dist/signet-requests.js +497 -0
  62. package/dist/signet-requests.js.map +1 -0
  63. package/dist/signet-response-feed.d.ts +161 -0
  64. package/dist/signet-response-feed.d.ts.map +1 -0
  65. package/dist/signet-response-feed.js +234 -0
  66. package/dist/signet-response-feed.js.map +1 -0
  67. package/package.json +47 -0
  68. package/src/Schnorr.compact +63 -0
  69. package/src/Signet.compact +529 -0
  70. package/src/circuits.compact +36 -0
  71. package/src/constants.ts +97 -0
  72. package/src/epsilon-derivation.ts +62 -0
  73. package/src/index.ts +31 -0
  74. package/src/managed/compiler/contract-info.json +165 -0
  75. package/src/managed/compiler/contract-manifest.json +32 -0
  76. package/src/managed/contract/index.d.ts +65 -0
  77. package/src/managed/contract/index.js +611 -0
  78. package/src/managed/contract/index.js.map +8 -0
  79. package/src/schnorr.ts +210 -0
  80. package/src/signature-requests-state-reader.ts +223 -0
  81. package/src/signature-response-verification.ts +64 -0
  82. package/src/signature-state-reading.ts +87 -0
  83. package/src/signet-contract-state-reader.ts +391 -0
  84. package/src/signet-event-observer.ts +186 -0
  85. package/src/signet-events.ts +337 -0
  86. package/src/signet-request-feed.ts +158 -0
  87. package/src/signet-request-resolver.ts +116 -0
  88. package/src/signet-request-response-reader.ts +324 -0
  89. package/src/signet-requests.ts +737 -0
  90. package/src/signet-response-feed.ts +325 -0
@@ -0,0 +1,62 @@
1
+ // Common signet raw-state reading, shared by the request and response readers
2
+ // (signature-requests-state-reader.ts, signet-contract-state-reader.ts).
3
+ // This is the MPC-/client-style path: decode a contract's ledger fields out of
4
+ // its raw state WITHOUT the compiled contract, walking the state tree by field
5
+ // position alone. Here live the generic tree walk (RawContractState,
6
+ // signetFieldNode) and the base type descriptors both readers share; each
7
+ // reader adds only the descriptors for its own layout.
8
+ import { CompactTypeBytes, CompactTypeUnsignedInteger, } from "@midnight-ntwrk/compact-runtime";
9
+ import {} from "./signet-requests.js";
10
+ // ---- Shared base type descriptors ----
11
+ // fromValue consumes the aligned value sequentially, so any width change here
12
+ // is silent data corruption, not an error. These mirror the Compact base types
13
+ // used across both signet layouts.
14
+ /** Descriptor for a Compact `Uint<64>` (8-byte unsigned integer). */
15
+ export const u64 = new CompactTypeUnsignedInteger(18446744073709551615n, 8);
16
+ /** Descriptor for a Compact `Bytes<32>`. */
17
+ export const bytes32 = new CompactTypeBytes(32);
18
+ /**
19
+ * Descriptor for a request id ledger key (Compact `RequestId`, a
20
+ * nominal `Bytes<32>`). Use it to encode a {@link RequestId} into the
21
+ * aligned form the state tree stores, or decode one back.
22
+ */
23
+ export const requestIdType = bytes32;
24
+ /**
25
+ * Unwrap a {@link RawContractState} to the underlying `StateValue`.
26
+ *
27
+ * @param raw - Bare state value or a `.state`-carrying wrapper.
28
+ * @returns The bare `StateValue`.
29
+ */
30
+ const unwrap = (raw) => "state" in raw ? raw.state : raw;
31
+ /**
32
+ * Resolve a flat ledger field index to its node in the raw state tree.
33
+ *
34
+ * The runtime stores ledger fields as a root array and chunks them one level
35
+ * deep once the field count grows, so chunked roots are flattened before
36
+ * indexing. Chunk detection assumes signet field 0 is a `Map`, never a
37
+ * `List` (whose node is also array-typed) — guaranteed by the signet layout
38
+ * convention.
39
+ *
40
+ * @param raw - Raw contract state from the indexer or simulator.
41
+ * @param flatIndex - Zero-based ledger field position in declaration order.
42
+ * @returns The `StateValue` node holding that field.
43
+ * @throws Error if `flatIndex` is beyond the contract's field count.
44
+ */
45
+ export function signetFieldNode(raw, flatIndex) {
46
+ const root = unwrap(raw);
47
+ if (root.type() !== "array") {
48
+ if (flatIndex === 0)
49
+ return root;
50
+ throw new Error(`Field index ${flatIndex} out of range: root is a leaf`);
51
+ }
52
+ const nodes = root.asArray() ?? [];
53
+ const fields = nodes[0]?.type() === "array"
54
+ ? nodes.flatMap((chunk) => chunk.asArray() ?? [])
55
+ : nodes;
56
+ const node = fields[flatIndex];
57
+ if (node === undefined) {
58
+ throw new Error(`Field index ${flatIndex} out of range`);
59
+ }
60
+ return node;
61
+ }
62
+ //# sourceMappingURL=signature-state-reading.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signature-state-reading.js","sourceRoot":"","sources":["../src/signature-state-reading.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,yEAAyE;AACzE,+EAA+E;AAC/E,+EAA+E;AAC/E,qEAAqE;AACrE,0EAA0E;AAC1E,uDAAuD;AAEvD,OAAO,EACL,gBAAgB,EAChB,0BAA0B,GAG3B,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAkB,MAAM,sBAAsB,CAAC;AAEtD,yCAAyC;AACzC,8EAA8E;AAC9E,+EAA+E;AAC/E,mCAAmC;AAEnC,qEAAqE;AACrE,MAAM,CAAC,MAAM,GAAG,GAAG,IAAI,0BAA0B,CAAC,qBAAqB,EAAE,CAAC,CAAC,CAAC;AAE5E,4CAA4C;AAC5C,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,gBAAgB,CAAC,EAAE,CAAC,CAAC;AAEhD;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAA2B,OAAO,CAAC;AAW7D;;;;;GAKG;AACH,MAAM,MAAM,GAAG,CAAC,GAAqB,EAAc,EAAE,CACnD,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;AAEnC;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,eAAe,CAC7B,GAAqB,EACrB,SAAiB;IAEjB,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IACzB,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,OAAO,EAAE,CAAC;QAC5B,IAAI,SAAS,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,eAAe,SAAS,+BAA+B,CAAC,CAAC;IAC3E,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC;IACnC,MAAM,MAAM,GACV,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,OAAO;QAC1B,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC;QACjD,CAAC,CAAC,KAAK,CAAC;IACZ,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;IAC/B,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,eAAe,SAAS,eAAe,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,146 @@
1
+ import { type CompactType, type JubjubPoint } 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 signature response counter index is ledger field 0. */
5
+ export declare const SIGNATURE_RESPONSE_COUNTER_INDEX_FIELD = 0;
6
+ /** Signet contract layout: the signature response log is ledger field 1. */
7
+ export declare const SIGNATURE_RESPONSE_INDEX_FIELD = 1;
8
+ /** Signet contract layout: the respond-bidirectional index is ledger field 2. */
9
+ export declare const RESPOND_BIDIRECTIONAL_INDEX_FIELD = 2;
10
+ /** Signet contract layout: the sealed MPC attestation key hash is ledger field 3. */
11
+ export declare const MPC_PUB_KEY_HASH_FIELD = 3;
12
+ /**
13
+ * The MPC's secp256k1 signature over the requested EVM transaction (Compact
14
+ * `SignatureResponse` — the canonical MPC `Signature { big_r, s,
15
+ * recovery_id }` with `big_r` decomposed into affine coordinates, big-endian
16
+ * scalar bytes). The request id it answers lives in the response index key,
17
+ * not here.
18
+ */
19
+ export interface SignatureResponse {
20
+ /** Signature R.x, 32 big-endian bytes. */
21
+ bigRx: Uint8Array;
22
+ /** Signature R.y, 32 big-endian bytes. */
23
+ bigRy: Uint8Array;
24
+ /** Signature s, 32 big-endian bytes. */
25
+ s: Uint8Array;
26
+ /** Parity of R.y for public-key recovery (0 or 1). */
27
+ recoveryId: bigint;
28
+ }
29
+ /**
30
+ * Hand-composed descriptor for {@link SignatureResponse}. Field
31
+ * order (bigRx, bigRy, s, recoveryId) must match the Compact struct.
32
+ */
33
+ export declare const signatureResponseType: CompactType<SignatureResponse>;
34
+ /**
35
+ * The MPC's respond-bidirectional attestation of a request's remote EVM
36
+ * execution (Compact `RespondBidirectional`): the serialized execution
37
+ * output plus the Schnorr signature over
38
+ * `(requestId, hash(serializedOutput, outputLen))`. Stored records were
39
+ * verified IN-CIRCUIT by the signet contract at post time, so readers can
40
+ * trust them without re-verifying.
41
+ */
42
+ export interface RespondBidirectional {
43
+ /** ABI-encoded return data (canonical serialized_output), zero-padded to 128 bytes. */
44
+ serializedOutput: Uint8Array;
45
+ /** Meaningful byte count of {@link serializedOutput}. */
46
+ outputLen: bigint;
47
+ /** The MPC attestation key (hash-checked against the sealed key at post). */
48
+ pk: JubjubPoint;
49
+ /** Schnorr nonce commitment R. */
50
+ announcement: JubjubPoint;
51
+ /** Schnorr response scalar s. */
52
+ response: bigint;
53
+ }
54
+ /**
55
+ * Composite key of one posted signature response (Compact
56
+ * `SignetResponseKey`): the request id it answers plus this post's 0-based
57
+ * count. Field order — count first, then request id — mirrors the Compact
58
+ * struct.
59
+ */
60
+ export interface SignetResponseKey {
61
+ /** 0-based position of this post among the responses for {@link requestId}. */
62
+ count: bigint;
63
+ /** 32-byte id of the request this response answers. */
64
+ requestId: RequestId;
65
+ }
66
+ /**
67
+ * Hand-composed descriptor for {@link SignetResponseKey} — the map key of
68
+ * the signature response log. Field order (count, then requestId) must match
69
+ * the Compact struct.
70
+ */
71
+ export declare const signetResponseKeyType: CompactType<SignetResponseKey>;
72
+ /**
73
+ * Hand-composed descriptor for {@link RespondBidirectional}. Field
74
+ * order (serializedOutput, outputLen, pk, announcement, response) must match
75
+ * the Compact struct.
76
+ */
77
+ export declare const respondBidirectionalType: CompactType<RespondBidirectional>;
78
+ /**
79
+ * Plain-JS signature response counter index parsed out of the ledger: hex
80
+ * request id (see {@link requestIdHex}) to the number of responses posted for
81
+ * that request. Entries in the response log exist for counts `0 .. value - 1`.
82
+ */
83
+ export type SignatureResponseCounterIndex = Map<RequestIdHex, bigint>;
84
+ /**
85
+ * Plain-JS signature response log parsed out of the ledger, keyed by
86
+ * {@link signetResponseIndexKey} (`"<hexRequestId>:<count>"`) so the
87
+ * composite Compact key survives as a usable JS `Map` key.
88
+ */
89
+ export type SignatureResponseIndex = Map<string, SignatureResponse>;
90
+ /**
91
+ * Plain-JS respond-bidirectional index parsed out of the ledger: hex
92
+ * request id to the contract-verified attestation. One slot per request.
93
+ */
94
+ export type RespondBidirectionalIndex = Map<RequestIdHex, RespondBidirectional>;
95
+ /**
96
+ * Build the {@link SignatureResponseIndex} key for a `(requestId, count)`
97
+ * pair — the composite Compact key flattened to a string so it works as a JS
98
+ * `Map` key.
99
+ *
100
+ * @param id - The request id the response answers, in canonical hex form.
101
+ * @param count - 0-based post count within that request.
102
+ * @returns `"<hexRequestId>:<count>"`.
103
+ */
104
+ export declare function signetResponseIndexKey(id: RequestIdHex, count: bigint): string;
105
+ /**
106
+ * The decoded ledger fields of the signet contract: the signature response
107
+ * counter (field 0) and log (field 1), the respond-bidirectional index
108
+ * (field 2), and the sealed MPC attestation key hash (field 3). Together
109
+ * they give a client everything the MPC ever delivers for a request.
110
+ */
111
+ export interface SignetContractLedger {
112
+ /**
113
+ * The signature response counter index (ledger field
114
+ * {@link SIGNATURE_RESPONSE_COUNTER_INDEX_FIELD}), keyed by hex request id.
115
+ */
116
+ signatureResponseCounterIndex: SignatureResponseCounterIndex;
117
+ /**
118
+ * The signature response log (ledger field
119
+ * {@link SIGNATURE_RESPONSE_INDEX_FIELD}), keyed by
120
+ * {@link signetResponseIndexKey}.
121
+ */
122
+ signatureResponseIndex: SignatureResponseIndex;
123
+ /**
124
+ * The respond-bidirectional index (ledger field
125
+ * {@link RESPOND_BIDIRECTIONAL_INDEX_FIELD}), keyed by hex request id.
126
+ */
127
+ respondBidirectionalIndex: RespondBidirectionalIndex;
128
+ /**
129
+ * The sealed MPC attestation key hash (ledger field
130
+ * {@link MPC_PUB_KEY_HASH_FIELD}) posts are verified against.
131
+ */
132
+ mpcPubKeyHash: Uint8Array;
133
+ }
134
+ /**
135
+ * MPC-/client-style read: parse the signet contract's ledger fields out of
136
+ * raw contract state by field position alone — no compiled contract, no
137
+ * generated `ledger()`, only the signet contract layout convention and the
138
+ * canonical descriptors above.
139
+ *
140
+ * @param raw - Raw contract state, e.g. `queryContractState(address).data`
141
+ * from the indexer or `ctx.currentQueryContext.state` from the simulator.
142
+ * @returns The decoded {@link SignetContractLedger}.
143
+ * @throws Error if a field is missing or has the wrong state-value shape.
144
+ */
145
+ export declare function readSignetContractLedgerFromState(raw: RawContractState): SignetContractLedger;
146
+ //# sourceMappingURL=signet-contract-state-reader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signet-contract-state-reader.d.ts","sourceRoot":"","sources":["../src/signet-contract-state-reader.ts"],"names":[],"mappings":"AAWA,OAAO,EAKL,KAAK,WAAW,EAChB,KAAK,WAAW,EACjB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,YAAY,EAClB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAIL,KAAK,gBAAgB,EACtB,MAAM,8BAA8B,CAAC;AAEtC,sFAAsF;AACtF,eAAO,MAAM,sCAAsC,IAAI,CAAC;AAExD,4EAA4E;AAC5E,eAAO,MAAM,8BAA8B,IAAI,CAAC;AAEhD,iFAAiF;AACjF,eAAO,MAAM,iCAAiC,IAAI,CAAC;AAEnD,qFAAqF;AACrF,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAgBxC;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IAChC,0CAA0C;IAC1C,KAAK,EAAE,UAAU,CAAC;IAClB,0CAA0C;IAC1C,KAAK,EAAE,UAAU,CAAC;IAClB,wCAAwC;IACxC,CAAC,EAAE,UAAU,CAAC;IACd,sDAAsD;IACtD,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,eAAO,MAAM,qBAAqB,EAAE,WAAW,CAAC,iBAAiB,CAqChE,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB;IACnC,uFAAuF;IACvF,gBAAgB,EAAE,UAAU,CAAC;IAC7B,yDAAyD;IACzD,SAAS,EAAE,MAAM,CAAC;IAClB,6EAA6E;IAC7E,EAAE,EAAE,WAAW,CAAC;IAChB,kCAAkC;IAClC,YAAY,EAAE,WAAW,CAAC;IAC1B,iCAAiC;IACjC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,+EAA+E;IAC/E,KAAK,EAAE,MAAM,CAAC;IACd,uDAAuD;IACvD,SAAS,EAAE,SAAS,CAAC;CACtB;AAED;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,EAAE,WAAW,CAAC,iBAAiB,CA0BhE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,EAAE,WAAW,CAAC,oBAAoB,CAwCtE,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,6BAA6B,GAAG,GAAG,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;AAEtE;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;AAEpE;;;GAGG;AACH,MAAM,MAAM,yBAAyB,GAAG,GAAG,CACzC,YAAY,EACZ,oBAAoB,CACrB,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,EAAE,EAAE,YAAY,EAChB,KAAK,EAAE,MAAM,GACZ,MAAM,CAER;AAED;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,6BAA6B,EAAE,6BAA6B,CAAC;IAC7D;;;;OAIG;IACH,sBAAsB,EAAE,sBAAsB,CAAC;IAC/C;;;OAGG;IACH,yBAAyB,EAAE,yBAAyB,CAAC;IACrD;;;OAGG;IACH,aAAa,EAAE,UAAU,CAAC;CAC3B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iCAAiC,CAC/C,GAAG,EAAE,gBAAgB,GACpB,oBAAoB,CA0EtB"}
@@ -0,0 +1,226 @@
1
+ // MPC-/client-style raw state reader for the central SIGNET contract: decode
2
+ // its ledger fields out of a contract's raw state WITHOUT the compiled
3
+ // contract, the mirror image of signature-requests-state-reader.ts. A poller
4
+ // has only the contract address, queries raw state from the indexer
5
+ // (queryContractState(address).data), and decodes by the signet contract
6
+ // layout convention (see "Signet Contract Ledger Layout" in Signet.compact):
7
+ // signature response counter index (field 0), signature response log
8
+ // (field 1), respond-bidirectional index (field 2), sealed MPC key hash
9
+ // (field 3). The generic state-tree walk (RawContractState, signetFieldNode)
10
+ // and the shared base descriptors live in signature-state-reading.ts.
11
+ import { CompactTypeBytes, CompactTypeField, CompactTypeJubjubPoint, CompactTypeUnsignedInteger, } from "@midnight-ntwrk/compact-runtime";
12
+ import { requestIdHex, } from "./signet-requests.js";
13
+ import { requestIdType, signetFieldNode, u64, } from "./signature-state-reading.js";
14
+ /** Signet contract layout: the signature response counter index is ledger field 0. */
15
+ export const SIGNATURE_RESPONSE_COUNTER_INDEX_FIELD = 0;
16
+ /** Signet contract layout: the signature response log is ledger field 1. */
17
+ export const SIGNATURE_RESPONSE_INDEX_FIELD = 1;
18
+ /** Signet contract layout: the respond-bidirectional index is ledger field 2. */
19
+ export const RESPOND_BIDIRECTIONAL_INDEX_FIELD = 2;
20
+ /** Signet contract layout: the sealed MPC attestation key hash is ledger field 3. */
21
+ export const MPC_PUB_KEY_HASH_FIELD = 3;
22
+ // ---- Type descriptors (must mirror Signet.compact field-for-field) ----
23
+ // As in the requests reader, fromValue consumes the aligned value
24
+ // sequentially, so field order and width here must match the Compact structs
25
+ // exactly — a mismatch is silent data corruption, not an error.
26
+ /** Descriptor for a signature scalar / MPC key hash (`Bytes<32>`). */
27
+ const bytes32 = new CompactTypeBytes(32);
28
+ /** Descriptor for the attestation's serialized output (`Bytes<128>`). */
29
+ const bytes128 = new CompactTypeBytes(128);
30
+ /** Descriptor for a Compact `Uint<8>` (1-byte unsigned integer). */
31
+ const u8 = new CompactTypeUnsignedInteger(255n, 1);
32
+ /**
33
+ * Hand-composed descriptor for {@link SignatureResponse}. Field
34
+ * order (bigRx, bigRy, s, recoveryId) must match the Compact struct.
35
+ */
36
+ export const signatureResponseType = {
37
+ /** @returns Compound alignment of the struct's fields in declaration order. */
38
+ alignment() {
39
+ return bytes32
40
+ .alignment()
41
+ .concat(bytes32.alignment())
42
+ .concat(bytes32.alignment())
43
+ .concat(u8.alignment());
44
+ },
45
+ /**
46
+ * Decode one signature response from an aligned value, consuming it field
47
+ * by field.
48
+ *
49
+ * @param value - Mutable aligned value cursor; pass a copy.
50
+ * @returns The decoded record.
51
+ */
52
+ fromValue(value) {
53
+ return {
54
+ bigRx: bytes32.fromValue(value),
55
+ bigRy: bytes32.fromValue(value),
56
+ s: bytes32.fromValue(value),
57
+ recoveryId: u8.fromValue(value),
58
+ };
59
+ },
60
+ /**
61
+ * Encode a signature response into its aligned on-ledger representation.
62
+ *
63
+ * @param record - The record to encode.
64
+ * @returns The aligned value, fields concatenated in declaration order.
65
+ */
66
+ toValue(record) {
67
+ return bytes32
68
+ .toValue(record.bigRx)
69
+ .concat(bytes32.toValue(record.bigRy))
70
+ .concat(bytes32.toValue(record.s))
71
+ .concat(u8.toValue(record.recoveryId));
72
+ },
73
+ };
74
+ /**
75
+ * Hand-composed descriptor for {@link SignetResponseKey} — the map key of
76
+ * the signature response log. Field order (count, then requestId) must match
77
+ * the Compact struct.
78
+ */
79
+ export const signetResponseKeyType = {
80
+ /** @returns Compound alignment of the struct's fields in declaration order. */
81
+ alignment() {
82
+ return u64.alignment().concat(requestIdType.alignment());
83
+ },
84
+ /**
85
+ * Decode one key from an aligned value, consuming it field by field.
86
+ *
87
+ * @param value - Mutable aligned value cursor; pass a copy.
88
+ * @returns The decoded composite key.
89
+ */
90
+ fromValue(value) {
91
+ return {
92
+ count: u64.fromValue(value),
93
+ requestId: requestIdType.fromValue(value),
94
+ };
95
+ },
96
+ /**
97
+ * Encode a key into its aligned on-ledger representation.
98
+ *
99
+ * @param key - The composite key to encode.
100
+ * @returns The aligned value, fields concatenated in declaration order.
101
+ */
102
+ toValue(key) {
103
+ return u64.toValue(key.count).concat(requestIdType.toValue(key.requestId));
104
+ },
105
+ };
106
+ /**
107
+ * Hand-composed descriptor for {@link RespondBidirectional}. Field
108
+ * order (serializedOutput, outputLen, pk, announcement, response) must match
109
+ * the Compact struct.
110
+ */
111
+ export const respondBidirectionalType = {
112
+ /** @returns Compound alignment of the struct's fields in declaration order. */
113
+ alignment() {
114
+ return bytes128
115
+ .alignment()
116
+ .concat(u8.alignment())
117
+ .concat(CompactTypeJubjubPoint.alignment())
118
+ .concat(CompactTypeJubjubPoint.alignment())
119
+ .concat(CompactTypeField.alignment());
120
+ },
121
+ /**
122
+ * Decode one attestation record from an aligned value, consuming it field
123
+ * by field.
124
+ *
125
+ * @param value - Mutable aligned value cursor; pass a copy.
126
+ * @returns The decoded record.
127
+ */
128
+ fromValue(value) {
129
+ return {
130
+ serializedOutput: bytes128.fromValue(value),
131
+ outputLen: u8.fromValue(value),
132
+ pk: CompactTypeJubjubPoint.fromValue(value),
133
+ announcement: CompactTypeJubjubPoint.fromValue(value),
134
+ response: CompactTypeField.fromValue(value),
135
+ };
136
+ },
137
+ /**
138
+ * Encode an attestation record into its aligned on-ledger representation.
139
+ *
140
+ * @param record - The record to encode.
141
+ * @returns The aligned value, fields concatenated in declaration order.
142
+ */
143
+ toValue(record) {
144
+ return bytes128
145
+ .toValue(record.serializedOutput)
146
+ .concat(u8.toValue(record.outputLen))
147
+ .concat(CompactTypeJubjubPoint.toValue(record.pk))
148
+ .concat(CompactTypeJubjubPoint.toValue(record.announcement))
149
+ .concat(CompactTypeField.toValue(record.response));
150
+ },
151
+ };
152
+ /**
153
+ * Build the {@link SignatureResponseIndex} key for a `(requestId, count)`
154
+ * pair — the composite Compact key flattened to a string so it works as a JS
155
+ * `Map` key.
156
+ *
157
+ * @param id - The request id the response answers, in canonical hex form.
158
+ * @param count - 0-based post count within that request.
159
+ * @returns `"<hexRequestId>:<count>"`.
160
+ */
161
+ export function signetResponseIndexKey(id, count) {
162
+ return `${id}:${count}`;
163
+ }
164
+ /**
165
+ * MPC-/client-style read: parse the signet contract's ledger fields out of
166
+ * raw contract state by field position alone — no compiled contract, no
167
+ * generated `ledger()`, only the signet contract layout convention and the
168
+ * canonical descriptors above.
169
+ *
170
+ * @param raw - Raw contract state, e.g. `queryContractState(address).data`
171
+ * from the indexer or `ctx.currentQueryContext.state` from the simulator.
172
+ * @returns The decoded {@link SignetContractLedger}.
173
+ * @throws Error if a field is missing or has the wrong state-value shape.
174
+ */
175
+ export function readSignetContractLedgerFromState(raw) {
176
+ const counterMap = signetFieldNode(raw, SIGNATURE_RESPONSE_COUNTER_INDEX_FIELD).asMap();
177
+ if (counterMap === undefined) {
178
+ throw new Error(`Ledger field ${SIGNATURE_RESPONSE_COUNTER_INDEX_FIELD} is not a Map`);
179
+ }
180
+ const signatureResponseCounterIndex = new Map();
181
+ for (const key of counterMap.keys()) {
182
+ // fromValue consumes its input, so hand each descriptor a copy.
183
+ const requestId = requestIdType.fromValue([...key.value]);
184
+ // A Counter is stored as a plain u64 cell.
185
+ const cell = counterMap.get(key)?.asCell();
186
+ if (cell === undefined)
187
+ continue;
188
+ signatureResponseCounterIndex.set(requestIdHex(requestId), u64.fromValue([...cell.value]));
189
+ }
190
+ const responseMap = signetFieldNode(raw, SIGNATURE_RESPONSE_INDEX_FIELD).asMap();
191
+ if (responseMap === undefined) {
192
+ throw new Error(`Ledger field ${SIGNATURE_RESPONSE_INDEX_FIELD} is not a Map`);
193
+ }
194
+ const signatureResponseIndex = new Map();
195
+ for (const key of responseMap.keys()) {
196
+ const responseKey = signetResponseKeyType.fromValue([...key.value]);
197
+ const cell = responseMap.get(key)?.asCell();
198
+ if (cell === undefined)
199
+ continue;
200
+ signatureResponseIndex.set(signetResponseIndexKey(requestIdHex(responseKey.requestId), responseKey.count), signatureResponseType.fromValue([...cell.value]));
201
+ }
202
+ const respondBidirectionalMap = signetFieldNode(raw, RESPOND_BIDIRECTIONAL_INDEX_FIELD).asMap();
203
+ if (respondBidirectionalMap === undefined) {
204
+ throw new Error(`Ledger field ${RESPOND_BIDIRECTIONAL_INDEX_FIELD} is not a Map`);
205
+ }
206
+ const respondBidirectionalIndex = new Map();
207
+ for (const key of respondBidirectionalMap.keys()) {
208
+ const requestId = requestIdType.fromValue([...key.value]);
209
+ const cell = respondBidirectionalMap.get(key)?.asCell();
210
+ if (cell === undefined)
211
+ continue;
212
+ respondBidirectionalIndex.set(requestIdHex(requestId), respondBidirectionalType.fromValue([...cell.value]));
213
+ }
214
+ const hashCell = signetFieldNode(raw, MPC_PUB_KEY_HASH_FIELD).asCell();
215
+ if (hashCell === undefined) {
216
+ throw new Error(`Ledger field ${MPC_PUB_KEY_HASH_FIELD} is not a Cell`);
217
+ }
218
+ const mpcPubKeyHash = bytes32.fromValue([...hashCell.value]);
219
+ return {
220
+ signatureResponseCounterIndex,
221
+ signatureResponseIndex,
222
+ respondBidirectionalIndex,
223
+ mpcPubKeyHash,
224
+ };
225
+ }
226
+ //# sourceMappingURL=signet-contract-state-reader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signet-contract-state-reader.js","sourceRoot":"","sources":["../src/signet-contract-state-reader.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,uEAAuE;AACvE,6EAA6E;AAC7E,oEAAoE;AACpE,yEAAyE;AACzE,6EAA6E;AAC7E,qEAAqE;AACrE,wEAAwE;AACxE,6EAA6E;AAC7E,sEAAsE;AAEtE,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,EACtB,0BAA0B,GAG3B,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACL,YAAY,GAGb,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,aAAa,EACb,eAAe,EACf,GAAG,GAEJ,MAAM,8BAA8B,CAAC;AAEtC,sFAAsF;AACtF,MAAM,CAAC,MAAM,sCAAsC,GAAG,CAAC,CAAC;AAExD,4EAA4E;AAC5E,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,CAAC;AAEhD,iFAAiF;AACjF,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,CAAC;AAEnD,qFAAqF;AACrF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAExC,0EAA0E;AAC1E,kEAAkE;AAClE,6EAA6E;AAC7E,gEAAgE;AAEhE,sEAAsE;AACtE,MAAM,OAAO,GAAG,IAAI,gBAAgB,CAAC,EAAE,CAAC,CAAC;AA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AAC,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;QACxD,IAAI,IAAI,KAAK,SAAS;YAAE,SAAS;QACjC,yBAAyB,CAAC,GAAG,CAC3B,YAAY,CAAC,SAAS,CAAC,EACvB,wBAAwB,CAAC,SAAS,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CACpD,CAAC;IACJ,CAAC;IAED,MAAM,QAAQ,GAAG,eAAe,CAAC,GAAG,EAAE,sBAAsB,CAAC,CAAC,MAAM,EAAE,CAAC;IACvE,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,gBAAgB,sBAAsB,gBAAgB,CAAC,CAAC;IAC1E,CAAC;IACD,MAAM,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IAE7D,OAAO;QACL,6BAA6B;QAC7B,sBAAsB;QACtB,yBAAyB;QACzB,aAAa;KACd,CAAC;AACJ,CAAC"}
@@ -0,0 +1,102 @@
1
+ import type { ContractEvent, ContractEventQueryFilter, PublicDataProvider } from "@midnight-ntwrk/midnight-js-types";
2
+ import { type SignetMiscEventCodec } from "./signet-events.ts";
3
+ /** Default gap between polls of the indexer's event stream. */
4
+ export declare const DEFAULT_EVENT_POLL_INTERVAL_MS = 3000;
5
+ /**
6
+ * The least of midnight-js's `PublicDataProvider` the event path needs: read a
7
+ * contract's events, and (optionally) stream them live. Declared structurally
8
+ * so tests can satisfy it with a plain stub; any full `PublicDataProvider`
9
+ * (e.g. `indexerPublicDataProvider`) is assignable to it.
10
+ */
11
+ export interface SignetEventSource {
12
+ /**
13
+ * Point-in-time read of a contract's events matching `filter`.
14
+ *
15
+ * @param filter - The event filter; `contractAddress` is required, an empty
16
+ * `types` array is rejected (omit for all).
17
+ * @returns The matching events, in ascending indexer-id order.
18
+ */
19
+ queryContractEvents(filter: ContractEventQueryFilter): Promise<ContractEvent[]>;
20
+ /**
21
+ * Optional live stream, for a future push path. Typed off
22
+ * `PublicDataProvider` so a full provider stays assignable; the observer's
23
+ * default path polls {@link queryContractEvents}.
24
+ */
25
+ contractEventsObservable?: PublicDataProvider["contractEventsObservable"];
26
+ }
27
+ /** Everything a {@link SignetEventObserver} needs. */
28
+ export interface SignetEventObserverConfig<T> {
29
+ /** Address of the central signet contract whose events to watch. */
30
+ readonly signetContractAddress: string;
31
+ /** Source of contract events, e.g. midnight-js's `indexerPublicDataProvider`. */
32
+ readonly source: SignetEventSource;
33
+ /**
34
+ * Which signet event kind to surface: the `Misc.name` tag to filter on and
35
+ * the payload decoder, e.g. `signBidirectionalEventCodec` or
36
+ * `signatureRespondedEventCodec` (signet-events.ts).
37
+ */
38
+ readonly codec: SignetMiscEventCodec<T>;
39
+ /**
40
+ * Durable resume floor: only events with `id >= fromEventId` are considered
41
+ * (the in-memory cursor of a prior run, persisted across restarts so nothing
42
+ * is missed or replayed). Defaults to 0 — the start of the event stream.
43
+ */
44
+ readonly fromEventId?: number;
45
+ /** Poll cadence for {@link SignetEventObserver.watch}; default {@link DEFAULT_EVENT_POLL_INTERVAL_MS}. */
46
+ readonly pollIntervalMs?: number;
47
+ }
48
+ /**
49
+ * Resolve after `ms`, or immediately once `signal` aborts. Used to space out
50
+ * polls without wedging a shutdown.
51
+ */
52
+ declare function sleep(ms: number, signal?: AbortSignal): Promise<void>;
53
+ /**
54
+ * Watches one signet contract's `Misc` events and surfaces the notifications
55
+ * of ONE kind among them (the codec's name tag), decoded and in ascending
56
+ * indexer-id order. A single decode failure is logged and skipped — one
57
+ * malformed event never stalls the stream.
58
+ */
59
+ export declare class SignetEventObserver<T> {
60
+ private readonly signetContractAddress;
61
+ private readonly source;
62
+ private readonly codec;
63
+ private readonly fromEventId;
64
+ private readonly pollIntervalMs;
65
+ /**
66
+ * @param config - The signet contract, event source, codec, and resume floor.
67
+ */
68
+ constructor(config: SignetEventObserverConfig<T>);
69
+ /** The `Misc` filter for the watched signet contract. */
70
+ private filter;
71
+ /**
72
+ * Every currently-visible notification of the codec's kind at or after the
73
+ * resume floor, each paired with its indexer cursor id, ascending by id.
74
+ * Non-`Misc` events, other name tags, and decode failures are dropped
75
+ * (failures logged).
76
+ */
77
+ private scan;
78
+ /**
79
+ * One-shot: every notification of the codec's kind currently visible at or
80
+ * after the resume floor, in id order. The polling feeds
81
+ * ({@link SignetRequestFeed}, `SignetResponseFeed`) re-scan through this
82
+ * each cycle (so a not-yet-indexed write is retried); it does NOT advance a
83
+ * cursor — the feeds dedupe by content instead.
84
+ *
85
+ * @returns The decoded notifications, ascending by indexer id.
86
+ */
87
+ currentEvents(): Promise<T[]>;
88
+ /**
89
+ * Live stream: poll the event source forever, yielding each notification
90
+ * exactly once in id order — nothing at or below the last yielded id is
91
+ * re-emitted (the cursor advances as `id + 1`, matching the indexer's
92
+ * resume convention). Runs until `opts.signal` aborts.
93
+ *
94
+ * @param opts.signal - Abort to stop the stream (between polls or on the next yield).
95
+ * @yields Each decoded notification once, ascending by indexer id.
96
+ */
97
+ watch(opts?: {
98
+ signal?: AbortSignal;
99
+ }): AsyncIterableIterator<T>;
100
+ }
101
+ export { sleep as sleepUnlessAborted };
102
+ //# sourceMappingURL=signet-event-observer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signet-event-observer.d.ts","sourceRoot":"","sources":["../src/signet-event-observer.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EACV,aAAa,EACb,wBAAwB,EACxB,kBAAkB,EACnB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,oBAAoB,CAAC;AAE5B,+DAA+D;AAC/D,eAAO,MAAM,8BAA8B,OAAO,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;;OAMG;IACH,mBAAmB,CAAC,MAAM,EAAE,wBAAwB,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IAChF;;;;OAIG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