@midnightntwrk/compact-js 0.0.0-stage → 4.0.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.
Files changed (233) hide show
  1. package/LICENSE +14 -0
  2. package/README.md +158 -2
  3. package/dist/dts/effect/CompactContext.d.ts +20 -0
  4. package/dist/dts/effect/CompactContext.d.ts.map +1 -0
  5. package/dist/dts/effect/CompactRuntime.d.ts +76 -0
  6. package/dist/dts/effect/CompactRuntime.d.ts.map +1 -0
  7. package/dist/dts/effect/CompiledContract.d.ts +107 -0
  8. package/dist/dts/effect/CompiledContract.d.ts.map +1 -0
  9. package/dist/dts/effect/Contract.d.ts +154 -0
  10. package/dist/dts/effect/Contract.d.ts.map +1 -0
  11. package/dist/dts/effect/ContractConfigurationError.d.ts +54 -0
  12. package/dist/dts/effect/ContractConfigurationError.d.ts.map +1 -0
  13. package/dist/dts/effect/ContractEventStore.d.ts +167 -0
  14. package/dist/dts/effect/ContractEventStore.d.ts.map +1 -0
  15. package/dist/dts/effect/ContractEventValidationError.d.ts +34 -0
  16. package/dist/dts/effect/ContractEventValidationError.d.ts.map +1 -0
  17. package/dist/dts/effect/ContractEventValidator.d.ts +18 -0
  18. package/dist/dts/effect/ContractEventValidator.d.ts.map +1 -0
  19. package/dist/dts/effect/ContractExecutable.d.ts +99 -0
  20. package/dist/dts/effect/ContractExecutable.d.ts.map +1 -0
  21. package/dist/dts/effect/ContractExecutableRuntime.d.ts +4 -0
  22. package/dist/dts/effect/ContractExecutableRuntime.d.ts.map +1 -0
  23. package/dist/dts/effect/ContractKeyLocation.d.ts +55 -0
  24. package/dist/dts/effect/ContractKeyLocation.d.ts.map +1 -0
  25. package/dist/dts/effect/ContractLog.d.ts +273 -0
  26. package/dist/dts/effect/ContractLog.d.ts.map +1 -0
  27. package/dist/dts/effect/ContractRuntimeError.d.ts +34 -0
  28. package/dist/dts/effect/ContractRuntimeError.d.ts.map +1 -0
  29. package/dist/dts/effect/Ledger.d.ts +104 -0
  30. package/dist/dts/effect/Ledger.d.ts.map +1 -0
  31. package/dist/dts/effect/MalformedHexPrefixError.d.ts +37 -0
  32. package/dist/dts/effect/MalformedHexPrefixError.d.ts.map +1 -0
  33. package/dist/dts/effect/ZKConfiguration.d.ts +52 -0
  34. package/dist/dts/effect/ZKConfiguration.d.ts.map +1 -0
  35. package/dist/dts/effect/ZKConfigurationReadError.d.ts +45 -0
  36. package/dist/dts/effect/ZKConfigurationReadError.d.ts.map +1 -0
  37. package/dist/dts/effect/ZKManifest.d.ts +50 -0
  38. package/dist/dts/effect/ZKManifest.d.ts.map +1 -0
  39. package/dist/dts/effect/ZKManifestError.d.ts +34 -0
  40. package/dist/dts/effect/ZKManifestError.d.ts.map +1 -0
  41. package/dist/dts/effect/index.d.ts +22 -0
  42. package/dist/dts/effect/index.d.ts.map +1 -0
  43. package/dist/dts/effect/internal/boundary.d.ts +35 -0
  44. package/dist/dts/effect/internal/boundary.d.ts.map +1 -0
  45. package/dist/dts/effect/internal/compactContext.d.ts +29 -0
  46. package/dist/dts/effect/internal/compactContext.d.ts.map +1 -0
  47. package/dist/dts/effect/internal/contractEventsSurface.d.ts +43 -0
  48. package/dist/dts/effect/internal/contractEventsSurface.d.ts.map +1 -0
  49. package/dist/dts/effect/internal/era/v8Executable.d.ts +65 -0
  50. package/dist/dts/effect/internal/era/v8Executable.d.ts.map +1 -0
  51. package/dist/dts/effect/internal/era/v8Ledger.d.ts +76 -0
  52. package/dist/dts/effect/internal/era/v8Ledger.d.ts.map +1 -0
  53. package/dist/dts/effect/internal/era/v8Runtime.d.ts +26 -0
  54. package/dist/dts/effect/internal/era/v8Runtime.d.ts.map +1 -0
  55. package/dist/dts/effect/internal/era/v9Executable.d.ts +65 -0
  56. package/dist/dts/effect/internal/era/v9Executable.d.ts.map +1 -0
  57. package/dist/dts/effect/internal/era/v9Ledger.d.ts +76 -0
  58. package/dist/dts/effect/internal/era/v9Ledger.d.ts.map +1 -0
  59. package/dist/dts/effect/internal/era/v9Runtime.d.ts +15 -0
  60. package/dist/dts/effect/internal/era/v9Runtime.d.ts.map +1 -0
  61. package/dist/dts/effect/internal/era.d.ts +117 -0
  62. package/dist/dts/effect/internal/era.d.ts.map +1 -0
  63. package/dist/dts/effect/internal/eraFreeSurface.d.ts +49 -0
  64. package/dist/dts/effect/internal/eraFreeSurface.d.ts.map +1 -0
  65. package/dist/dts/effect/internal/eraNeutralSurface.d.ts +35 -0
  66. package/dist/dts/effect/internal/eraNeutralSurface.d.ts.map +1 -0
  67. package/dist/dts/effect/internal/executable.d.ts +371 -0
  68. package/dist/dts/effect/internal/executable.d.ts.map +1 -0
  69. package/dist/dts/effect/internal/ledger/binding.d.ts +2 -0
  70. package/dist/dts/effect/internal/ledger/binding.d.ts.map +1 -0
  71. package/dist/dts/effect/internal/ledger/conformance.d.ts +2 -0
  72. package/dist/dts/effect/internal/ledger/conformance.d.ts.map +1 -0
  73. package/dist/dts/effect/internal/ledger/conversions.d.ts +167 -0
  74. package/dist/dts/effect/internal/ledger/conversions.d.ts.map +1 -0
  75. package/dist/dts/effect/internal/ledger/current.d.ts +8 -0
  76. package/dist/dts/effect/internal/ledger/current.d.ts.map +1 -0
  77. package/dist/dts/effect/internal/ledger/v8.d.ts +100 -0
  78. package/dist/dts/effect/internal/ledger/v8.d.ts.map +1 -0
  79. package/dist/dts/effect/internal/ledger/v9.d.ts +66 -0
  80. package/dist/dts/effect/internal/ledger/v9.d.ts.map +1 -0
  81. package/dist/dts/effect/internal/runtime/binding.d.ts +2 -0
  82. package/dist/dts/effect/internal/runtime/binding.d.ts.map +1 -0
  83. package/dist/dts/effect/internal/runtime/conformance.d.ts +2 -0
  84. package/dist/dts/effect/internal/runtime/conformance.d.ts.map +1 -0
  85. package/dist/dts/effect/internal/runtime/current.d.ts +11 -0
  86. package/dist/dts/effect/internal/runtime/current.d.ts.map +1 -0
  87. package/dist/dts/effect/internal/runtime/execution.d.ts +176 -0
  88. package/dist/dts/effect/internal/runtime/execution.d.ts.map +1 -0
  89. package/dist/dts/effect/internal/runtime/v0_16.d.ts +169 -0
  90. package/dist/dts/effect/internal/runtime/v0_16.d.ts.map +1 -0
  91. package/dist/dts/effect/internal/runtime/v0_21.d.ts +81 -0
  92. package/dist/dts/effect/internal/runtime/v0_21.d.ts.map +1 -0
  93. package/dist/dts/effect/internal/typeAssertions.d.ts +2 -0
  94. package/dist/dts/effect/internal/typeAssertions.d.ts.map +1 -0
  95. package/dist/dts/index.d.ts +7 -0
  96. package/dist/dts/index.d.ts.map +1 -0
  97. package/dist/dts/v8/effect.d.ts +50 -0
  98. package/dist/dts/v8/effect.d.ts.map +1 -0
  99. package/dist/dts/v8/index.d.ts +10 -0
  100. package/dist/dts/v8/index.d.ts.map +1 -0
  101. package/dist/dts/v9/effect.d.ts +28 -0
  102. package/dist/dts/v9/effect.d.ts.map +1 -0
  103. package/dist/dts/v9/index.d.ts +16 -0
  104. package/dist/dts/v9/index.d.ts.map +1 -0
  105. package/dist/esm/effect/CompactContext.js +16 -0
  106. package/dist/esm/effect/CompactContext.js.map +1 -0
  107. package/dist/esm/effect/CompactRuntime.js +44 -0
  108. package/dist/esm/effect/CompactRuntime.js.map +1 -0
  109. package/dist/esm/effect/CompiledContract.js +102 -0
  110. package/dist/esm/effect/CompiledContract.js.map +1 -0
  111. package/dist/esm/effect/Contract.js +40 -0
  112. package/dist/esm/effect/Contract.js.map +1 -0
  113. package/dist/esm/effect/ContractConfigurationError.js +41 -0
  114. package/dist/esm/effect/ContractConfigurationError.js.map +1 -0
  115. package/dist/esm/effect/ContractEventStore.js +150 -0
  116. package/dist/esm/effect/ContractEventStore.js.map +1 -0
  117. package/dist/esm/effect/ContractEventValidationError.js +40 -0
  118. package/dist/esm/effect/ContractEventValidationError.js.map +1 -0
  119. package/dist/esm/effect/ContractEventValidator.js +49 -0
  120. package/dist/esm/effect/ContractEventValidator.js.map +1 -0
  121. package/dist/esm/effect/ContractExecutable.js +50 -0
  122. package/dist/esm/effect/ContractExecutable.js.map +1 -0
  123. package/dist/esm/effect/ContractExecutableRuntime.js +17 -0
  124. package/dist/esm/effect/ContractExecutableRuntime.js.map +1 -0
  125. package/dist/esm/effect/ContractKeyLocation.js +67 -0
  126. package/dist/esm/effect/ContractKeyLocation.js.map +1 -0
  127. package/dist/esm/effect/ContractLog.js +268 -0
  128. package/dist/esm/effect/ContractLog.js.map +1 -0
  129. package/dist/esm/effect/ContractRuntimeError.js +40 -0
  130. package/dist/esm/effect/ContractRuntimeError.js.map +1 -0
  131. package/dist/esm/effect/Ledger.js +115 -0
  132. package/dist/esm/effect/Ledger.js.map +1 -0
  133. package/dist/esm/effect/MalformedHexPrefixError.js +43 -0
  134. package/dist/esm/effect/MalformedHexPrefixError.js.map +1 -0
  135. package/dist/esm/effect/ZKConfiguration.js +23 -0
  136. package/dist/esm/effect/ZKConfiguration.js.map +1 -0
  137. package/dist/esm/effect/ZKConfigurationReadError.js +46 -0
  138. package/dist/esm/effect/ZKConfigurationReadError.js.map +1 -0
  139. package/dist/esm/effect/ZKManifest.js +286 -0
  140. package/dist/esm/effect/ZKManifest.js.map +1 -0
  141. package/dist/esm/effect/ZKManifestError.js +40 -0
  142. package/dist/esm/effect/ZKManifestError.js.map +1 -0
  143. package/dist/esm/effect/index.js +36 -0
  144. package/dist/esm/effect/index.js.map +1 -0
  145. package/dist/esm/effect/internal/boundary.js +61 -0
  146. package/dist/esm/effect/internal/boundary.js.map +1 -0
  147. package/dist/esm/effect/internal/compactContext.js +52 -0
  148. package/dist/esm/effect/internal/compactContext.js.map +1 -0
  149. package/dist/esm/effect/internal/contractEventsSurface.js +57 -0
  150. package/dist/esm/effect/internal/contractEventsSurface.js.map +1 -0
  151. package/dist/esm/effect/internal/era/v8Executable.js +31 -0
  152. package/dist/esm/effect/internal/era/v8Executable.js.map +1 -0
  153. package/dist/esm/effect/internal/era/v8Ledger.js +85 -0
  154. package/dist/esm/effect/internal/era/v8Ledger.js.map +1 -0
  155. package/dist/esm/effect/internal/era/v8Runtime.js +39 -0
  156. package/dist/esm/effect/internal/era/v8Runtime.js.map +1 -0
  157. package/dist/esm/effect/internal/era/v9Executable.js +31 -0
  158. package/dist/esm/effect/internal/era/v9Executable.js.map +1 -0
  159. package/dist/esm/effect/internal/era/v9Ledger.js +83 -0
  160. package/dist/esm/effect/internal/era/v9Ledger.js.map +1 -0
  161. package/dist/esm/effect/internal/era/v9Runtime.js +28 -0
  162. package/dist/esm/effect/internal/era/v9Runtime.js.map +1 -0
  163. package/dist/esm/effect/internal/era.js +16 -0
  164. package/dist/esm/effect/internal/era.js.map +1 -0
  165. package/dist/esm/effect/internal/eraFreeSurface.js +63 -0
  166. package/dist/esm/effect/internal/eraFreeSurface.js.map +1 -0
  167. package/dist/esm/effect/internal/eraNeutralSurface.js +49 -0
  168. package/dist/esm/effect/internal/eraNeutralSurface.js.map +1 -0
  169. package/dist/esm/effect/internal/executable.js +531 -0
  170. package/dist/esm/effect/internal/executable.js.map +1 -0
  171. package/dist/esm/effect/internal/ledger/binding.js +20 -0
  172. package/dist/esm/effect/internal/ledger/binding.js.map +1 -0
  173. package/dist/esm/effect/internal/ledger/conformance.js +16 -0
  174. package/dist/esm/effect/internal/ledger/conformance.js.map +1 -0
  175. package/dist/esm/effect/internal/ledger/conversions.js +119 -0
  176. package/dist/esm/effect/internal/ledger/conversions.js.map +1 -0
  177. package/dist/esm/effect/internal/ledger/current.js +22 -0
  178. package/dist/esm/effect/internal/ledger/current.js.map +1 -0
  179. package/dist/esm/effect/internal/ledger/v8.js +101 -0
  180. package/dist/esm/effect/internal/ledger/v8.js.map +1 -0
  181. package/dist/esm/effect/internal/ledger/v9.js +91 -0
  182. package/dist/esm/effect/internal/ledger/v9.js.map +1 -0
  183. package/dist/esm/effect/internal/runtime/binding.js +16 -0
  184. package/dist/esm/effect/internal/runtime/binding.js.map +1 -0
  185. package/dist/esm/effect/internal/runtime/conformance.js +16 -0
  186. package/dist/esm/effect/internal/runtime/conformance.js.map +1 -0
  187. package/dist/esm/effect/internal/runtime/current.js +25 -0
  188. package/dist/esm/effect/internal/runtime/current.js.map +1 -0
  189. package/dist/esm/effect/internal/runtime/execution.js +16 -0
  190. package/dist/esm/effect/internal/runtime/execution.js.map +1 -0
  191. package/dist/esm/effect/internal/runtime/v0_16.js +178 -0
  192. package/dist/esm/effect/internal/runtime/v0_16.js.map +1 -0
  193. package/dist/esm/effect/internal/runtime/v0_21.js +129 -0
  194. package/dist/esm/effect/internal/runtime/v0_21.js.map +1 -0
  195. package/dist/esm/effect/internal/typeAssertions.js +16 -0
  196. package/dist/esm/effect/internal/typeAssertions.js.map +1 -0
  197. package/dist/esm/index.js +21 -0
  198. package/dist/esm/index.js.map +1 -0
  199. package/dist/esm/package.json +4 -0
  200. package/dist/esm/v8/effect.js +64 -0
  201. package/dist/esm/v8/effect.js.map +1 -0
  202. package/dist/esm/v8/index.js +24 -0
  203. package/dist/esm/v8/index.js.map +1 -0
  204. package/dist/esm/v9/effect.js +47 -0
  205. package/dist/esm/v9/effect.js.map +1 -0
  206. package/dist/esm/v9/index.js +30 -0
  207. package/dist/esm/v9/index.js.map +1 -0
  208. package/effect/CompactContext/package.json +5 -0
  209. package/effect/CompactRuntime/package.json +5 -0
  210. package/effect/CompiledContract/package.json +5 -0
  211. package/effect/Contract/package.json +5 -0
  212. package/effect/ContractConfigurationError/package.json +5 -0
  213. package/effect/ContractEventStore/package.json +5 -0
  214. package/effect/ContractEventValidationError/package.json +5 -0
  215. package/effect/ContractEventValidator/package.json +5 -0
  216. package/effect/ContractExecutable/package.json +5 -0
  217. package/effect/ContractExecutableRuntime/package.json +5 -0
  218. package/effect/ContractKeyLocation/package.json +5 -0
  219. package/effect/ContractLog/package.json +5 -0
  220. package/effect/ContractRuntimeError/package.json +5 -0
  221. package/effect/Ledger/package.json +5 -0
  222. package/effect/MalformedHexPrefixError/package.json +5 -0
  223. package/effect/ZKConfiguration/package.json +5 -0
  224. package/effect/ZKConfigurationReadError/package.json +5 -0
  225. package/effect/ZKManifest/package.json +5 -0
  226. package/effect/ZKManifestError/package.json +5 -0
  227. package/effect/index/package.json +5 -0
  228. package/effect/package.json +5 -0
  229. package/package.json +220 -4
  230. package/v8/effect/package.json +5 -0
  231. package/v8/package.json +5 -0
  232. package/v9/effect/package.json +5 -0
  233. package/v9/package.json +5 -0
@@ -0,0 +1,268 @@
1
+ /*
2
+ * This file is part of midnight-sdk.
3
+ * Copyright (C) 2025 Midnight Foundation
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * You may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ /**
16
+ * Typed domain model for the contract log events emitted from Compact contracts via the `emit`
17
+ * expression (MIP-0002).
18
+ *
19
+ * Events flow from contract emission → ledger wrapping → indexer storage → DApp queries. This
20
+ * module turns the raw, on-chain-encoded {@link LogEvent} surfaced on a circuit result into a
21
+ * typed, discriminated {@link ContractEvent} whose `payload` is decoded per event type.
22
+ *
23
+ * @remarks
24
+ * - **Event version**: Phase-1 wire format is `version: 1`. Version `0` is reserved on-chain for
25
+ * the decoder's malformed-input fallback, so it is treated here as degraded/unknown, never an
26
+ * error.
27
+ * - **Graceful degradation** (MIP-0002): an oversized or malformed payload is dropped on-chain
28
+ * (surfaced as an empty `{ tag: 'null' }` `data`, or a short buffer). Decoding **never throws**
29
+ * and never fails a batch — such events decode to a {@link ContractEvent} with `degraded: true`
30
+ * and `payload: undefined`. Absence is normal.
31
+ * - **Indexed fields** are derived from the event type (not marked by the author); see
32
+ * {@link indexedFields}. `Misc` and lifecycle events index nothing.
33
+ * - **Non-consensus**: events are NOT consensus state; retention is a downstream (indexer) policy.
34
+ * - **Wire layout**: the intra-`data` field byte-offsets read by {@link decode} follow the
35
+ * corrected field-aligned layout from issue #278 — a 65-byte `Either` (`[is_left:1][left:32][right:32]`,
36
+ * `is_left=1` → coin-public-key), little-endian `Uint<128>` with trailing zeros stripped (buffers
37
+ * are right-padded to canonical width before slicing), and the post-compact#590 `shielded-receive`
38
+ * field order `(commitment, ciphertext, contractAddress)`. See the layout table in
39
+ * `test/effect/logEventFixtures.ts`. The authoritative reference is the indexer's Rust decoder
40
+ * (`ledger_state.rs`); the end-to-end cross-check against a live `emit` (see that file's provenance
41
+ * note) is the final validation gate. A wrong offset decodes **silently** to a wrong value rather
42
+ * than degrading.
43
+ *
44
+ * @packageDocumentation
45
+ */
46
+ import * as ContractAddress from '@midnight-ntwrk/platform-js/effect/ContractAddress';
47
+ import { Option } from 'effect';
48
+ import * as Schema from 'effect/Schema';
49
+ /**
50
+ * Schema for the standard `LogEventType` discriminants emitted by Compact contracts — the single
51
+ * source of truth for the event-type literals, imported by `ContractEventValidator`.
52
+ *
53
+ * @category model
54
+ */
55
+ export const LogEventTypeSchema = Schema.Literal('shielded-spend', 'shielded-receive', 'shielded-mint', 'shielded-burn', 'unshielded-spend', 'unshielded-receive', 'unshielded-mint', 'unshielded-burn', 'paused', 'unpaused', 'misc');
56
+ // --- byte-buffer readers ----------------------------------------------------------------------
57
+ const concatSegments = (segments) => {
58
+ if (segments.length === 1)
59
+ return segments[0];
60
+ const total = segments.reduce((n, s) => n + s.length, 0);
61
+ const out = new Uint8Array(total);
62
+ let offset = 0;
63
+ for (const s of segments) {
64
+ out.set(s, offset);
65
+ offset += s.length;
66
+ }
67
+ return out;
68
+ };
69
+ /** Flatten a `LogEvent.data` to its concatenated byte buffer, or `undefined` if not a `cell`. */
70
+ const flatten = (data) => data.tag === 'cell' ? concatSegments(data.content.value) : undefined;
71
+ /** Read a little-endian `Uint<128>` (≤16 bytes; wire strips trailing/high-order zeros). */
72
+ const readUint128 = (buf, offset) => {
73
+ let v = 0n;
74
+ for (let i = 15; i >= 0; i--)
75
+ v = (v << 8n) | BigInt(buf[offset + i] ?? 0);
76
+ return v;
77
+ };
78
+ /** Read a `Maybe<Bytes<size>>`: a flag byte (`1` = some) followed by the fixed-width payload. */
79
+ const readMaybeBytes = (buf, offset, size) => buf[offset] === 1 ? Option.some(buf.slice(offset + 1, offset + 1 + size)) : Option.none();
80
+ /** Read a `Maybe<Uint<128>>`: a flag byte (`1` = some) followed by the 16-byte value. */
81
+ const readMaybeUint128 = (buf, offset) => buf[offset] === 1 ? Option.some(readUint128(buf, offset + 1)) : Option.none();
82
+ /**
83
+ * Read an `Either<ZswapCoinPublicKey, ContractAddress>` (65 B): `[is_left:1][left:32][right:32]`,
84
+ * both arms present, inactive arm zero-filled. `is_left=1` → Left → coin-public-key (left arm);
85
+ * `is_left=0` → Right → contract-address (right arm). Any other discriminant is garbage (out-of-range
86
+ * byte, or a misaligned read) and yields `undefined` so the caller degrades rather than decoding to a
87
+ * confident wrong `kind`.
88
+ */
89
+ const readEither = (buf, offset) => {
90
+ const isLeft = buf[offset];
91
+ if (isLeft !== 0 && isLeft !== 1)
92
+ return undefined;
93
+ return isLeft === 1
94
+ ? { kind: 'coin-public-key', bytes: buf.slice(offset + 1, offset + 33) }
95
+ : { kind: 'contract-address', bytes: buf.slice(offset + 33, offset + 65) };
96
+ };
97
+ /** Right-pad `buf` with zero bytes up to `size` (undoing the wire's trailing-zero stripping). */
98
+ const padRight = (buf, size) => {
99
+ if (buf.length >= size)
100
+ return buf;
101
+ const out = new Uint8Array(size);
102
+ out.set(buf, 0);
103
+ return out;
104
+ };
105
+ /**
106
+ * The canonical (unstripped) serialized size, in bytes, of each event's payload. The wire strips
107
+ * trailing zero bytes, so a real buffer may be shorter; {@link decodePayload} right-pads to this
108
+ * width before slicing at fixed offsets (indexer parity), so a short buffer is normal, not degraded.
109
+ */
110
+ const PAYLOAD_SIZE = {
111
+ 'shielded-spend': 32,
112
+ 'shielded-receive': 578,
113
+ 'shielded-mint': 81,
114
+ 'shielded-burn': 49,
115
+ 'unshielded-spend': 145,
116
+ 'unshielded-receive': 145,
117
+ 'unshielded-mint': 80,
118
+ 'unshielded-burn': 113,
119
+ 'paused': 0,
120
+ 'unpaused': 0,
121
+ 'misc': 288
122
+ };
123
+ /**
124
+ * Decode the payload buffer for a given event type. Byte offsets follow the field-aligned layout
125
+ * tabulated in `test/effect/logEventFixtures.ts`.
126
+ *
127
+ * The wire strips trailing zero bytes, so the raw buffer is first right-padded to the canonical
128
+ * width ({@link PAYLOAD_SIZE}) before slicing — a short buffer is normal (small/zero tail), not
129
+ * degraded. Degradation still occurs on `{ tag: 'null' }` data, `version: 0`, a bad envelope
130
+ * address, or an out-of-range `Either` discriminant (which returns `undefined` here).
131
+ */
132
+ const decodePayload = (eventType, raw) => {
133
+ const buf = padRight(raw, PAYLOAD_SIZE[eventType]);
134
+ switch (eventType) {
135
+ case 'shielded-spend':
136
+ return { nullifier: buf.slice(0, 32) };
137
+ case 'shielded-receive':
138
+ return {
139
+ commitment: buf.slice(0, 32),
140
+ ciphertext: readMaybeBytes(buf, 32, 512),
141
+ contractAddress: readMaybeBytes(buf, 545, 32)
142
+ };
143
+ case 'shielded-mint':
144
+ return { commitment: buf.slice(0, 32), domainSep: buf.slice(32, 64), amount: readMaybeUint128(buf, 64) };
145
+ case 'shielded-burn':
146
+ return { nullifier: buf.slice(0, 32), amount: readMaybeUint128(buf, 32) };
147
+ case 'unshielded-spend': {
148
+ const sender = readEither(buf, 0);
149
+ return sender === undefined
150
+ ? undefined
151
+ : { sender, domainSep: buf.slice(65, 97), tokenType: buf.slice(97, 129), amount: readUint128(buf, 129) };
152
+ }
153
+ case 'unshielded-receive': {
154
+ const recipient = readEither(buf, 0);
155
+ return recipient === undefined
156
+ ? undefined
157
+ : { recipient, domainSep: buf.slice(65, 97), tokenType: buf.slice(97, 129), amount: readUint128(buf, 129) };
158
+ }
159
+ case 'unshielded-mint':
160
+ return { domainSep: buf.slice(0, 32), tokenType: buf.slice(32, 64), amount: readUint128(buf, 64) };
161
+ case 'unshielded-burn': {
162
+ const sender = readEither(buf, 0);
163
+ return sender === undefined
164
+ ? undefined
165
+ : { sender, tokenType: buf.slice(65, 97), amount: readUint128(buf, 97) };
166
+ }
167
+ case 'paused':
168
+ case 'unpaused':
169
+ return {};
170
+ case 'misc':
171
+ return { name: buf.slice(0, 32), payload: buf.slice(32, 288) };
172
+ }
173
+ };
174
+ // --- public decoding API ----------------------------------------------------------------------
175
+ /**
176
+ * Decode a single raw {@link LogEvent} into a typed {@link ContractEvent}.
177
+ *
178
+ * This is a total, pure function: it **never throws**. A dropped (`{ tag: 'null' }`), truncated,
179
+ * or `version: 0` payload — or a malformed envelope address — decodes to a {@link DegradedEvent}
180
+ * (`degraded: true`, `payload: undefined`) per the MIP-0002 graceful-degradation rule; the raw
181
+ * event remains on `raw`.
182
+ *
183
+ * The `payload` field byte-offsets follow the corrected layout from issue #278 (see the module-level
184
+ * remarks). The end-to-end cross-check against a live `emit` is the final validation gate; a wrong
185
+ * offset decodes silently to a wrong value rather than degrading.
186
+ *
187
+ * @param raw The raw log event surfaced on a circuit result.
188
+ * @returns The decoded, typed event.
189
+ *
190
+ * @category decoding
191
+ */
192
+ export const decode = (raw) => {
193
+ // Construct the emitting address with the brand's *safe* variant: a malformed envelope address
194
+ // (wrong length, non-hex, `0x`-prefixed) would otherwise throw a `Brand.BrandErrors`, breaking
195
+ // the never-throw guarantee. A bad address is a degraded envelope — surface it best-effort (the
196
+ // raw string is always available on `raw.address`) and mark the event degraded.
197
+ const address = ContractAddress.ContractAddress.option(raw.address);
198
+ if (Option.isNone(address)) {
199
+ return {
200
+ version: raw.version,
201
+ address: raw.address,
202
+ raw,
203
+ eventType: raw.eventType,
204
+ payload: undefined,
205
+ degraded: true
206
+ };
207
+ }
208
+ const base = { version: raw.version, address: address.value, raw };
209
+ const buf = raw.version === 0 ? undefined : flatten(raw.data);
210
+ const payload = buf === undefined ? undefined : decodePayload(raw.eventType, buf);
211
+ return payload === undefined
212
+ ? { ...base, eventType: raw.eventType, payload: undefined, degraded: true }
213
+ : { ...base, eventType: raw.eventType, payload, degraded: false };
214
+ };
215
+ /**
216
+ * Decode a batch of raw {@link LogEvent}s (e.g. `result.events`) into typed {@link ContractEvent}s.
217
+ *
218
+ * Like {@link decode}, this never throws — degraded events are preserved in place rather than
219
+ * dropped, so the returned array is index-aligned with the input.
220
+ *
221
+ * @param events The raw log events to decode.
222
+ * @returns The decoded, typed events, in input order.
223
+ *
224
+ * @category decoding
225
+ */
226
+ export const decodeAll = (events) => events.map(decode);
227
+ /**
228
+ * Derive the indexable fields of a decoded event, as raw byte values keyed by field name.
229
+ *
230
+ * Indexed fields are determined by the event type (MIP-0002), not marked by the author:
231
+ * - `shielded-spend`/`shielded-burn` → `nullifier`
232
+ * - `shielded-receive` → `commitment`
233
+ * - `shielded-mint` → `commitment`, `domainSep`
234
+ * - `unshielded-spend`/`unshielded-burn` → `sender`, `tokenType`
235
+ * - `unshielded-receive` → `recipient`, `tokenType`
236
+ * - `unshielded-mint` → `domainSep`, `tokenType`
237
+ * - `paused`/`unpaused`/`misc` and any degraded event → none
238
+ *
239
+ * @param event The decoded event.
240
+ * @returns A map of indexable field name to its raw bytes; empty when the type indexes nothing.
241
+ *
242
+ * @category indexing
243
+ */
244
+ export const indexedFields = (event) => {
245
+ if (event.degraded)
246
+ return {};
247
+ switch (event.eventType) {
248
+ case 'shielded-spend':
249
+ return { nullifier: event.payload.nullifier };
250
+ case 'shielded-receive':
251
+ return { commitment: event.payload.commitment };
252
+ case 'shielded-mint':
253
+ return { commitment: event.payload.commitment, domainSep: event.payload.domainSep };
254
+ case 'shielded-burn':
255
+ return { nullifier: event.payload.nullifier };
256
+ case 'unshielded-spend':
257
+ return { sender: event.payload.sender.bytes, tokenType: event.payload.tokenType };
258
+ case 'unshielded-receive':
259
+ return { recipient: event.payload.recipient.bytes, tokenType: event.payload.tokenType };
260
+ case 'unshielded-mint':
261
+ return { domainSep: event.payload.domainSep, tokenType: event.payload.tokenType };
262
+ case 'unshielded-burn':
263
+ return { sender: event.payload.sender.bytes, tokenType: event.payload.tokenType };
264
+ default:
265
+ return {};
266
+ }
267
+ };
268
+ //# sourceMappingURL=ContractLog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContractLog.js","sourceRoot":"","sources":["../../../src/effect/ContractLog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,OAAO,KAAK,eAAe,MAAM,oDAAoD,CAAC;AACtF,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AA8CxC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,OAAO,CAC9C,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,QAAQ,EACR,UAAU,EACV,MAAM,CACP,CAAC;AAoJF,iGAAiG;AAEjG,MAAM,cAAc,GAAG,CAAC,QAA+B,EAAc,EAAE;IACrE,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAC,CAAC,CAAE,CAAC;IAC/C,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACzD,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;IAClC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;QACzB,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QACnB,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC;IACrB,CAAC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O,EAAE,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;QACpF;YACE,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,40 @@
1
+ /*
2
+ * This file is part of midnight-sdk.
3
+ * Copyright (C) 2025 Midnight Foundation
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * You may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ import * as Error from '@effect/platform/Error';
16
+ import { hasProperty } from 'effect/Predicate';
17
+ const TypeId = Symbol.for('compact-js/effect/ContractRuntimeError');
18
+ /**
19
+ * A runtime error occurred while executing a constructor, or a circuit, of an executable contract.
20
+ *
21
+ * @category errors
22
+ */
23
+ export class ContractRuntimeError extends Error.TypeIdError(TypeId, 'ContractRuntimeError') {
24
+ }
25
+ /**
26
+ * Determines if a value is a contract runtime error.
27
+ *
28
+ * @param u The value to check.
29
+ * @returns `true` if `u` is a {@link ContractRuntimeError}; `false` otherwise.
30
+ *
31
+ * @category guards
32
+ */
33
+ export const isRuntimeError = (u) => hasProperty(u, TypeId);
34
+ /**
35
+ * Creates a new {@link ContractRuntimeError}.
36
+ *
37
+ * @category constructors
38
+ */
39
+ export const make = (message, cause) => new ContractRuntimeError({ message, cause });
40
+ //# sourceMappingURL=ContractRuntimeError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContractRuntimeError.js","sourceRoot":"","sources":["../../../src/effect/ContractRuntimeError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,KAAK,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,MAAM,GAAkB,MAAM,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;AAGnF;;;;GAIG;AACH,MAAM,OAAO,oBAAqB,SAAQ,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,sBAAsB,CAKxF;CAAI;AAEN;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAU,EAA6B,EAAE,CAAC,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAEhG;;;;GAIG;AACH,MAAM,CAAC,MAAM,IAAI,GAA+D,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CACjG,IAAI,oBAAoB,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC"}
@@ -0,0 +1,115 @@
1
+ /*
2
+ * This file is part of midnight-sdk.
3
+ * Copyright (C) 2025 Midnight Foundation
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * You may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ /**
16
+ * The ledger era seam.
17
+ *
18
+ * All ledger types, constructors, and runtime↔ledger conversions used by compact-js (and its
19
+ * sibling packages) are reached through this module rather than a `@midnightntwrk/ledger-v<N>`
20
+ * package directly. The concrete era is bound in `internal/ledger/current.ts`. The facade
21
+ * re-exports a curated list of ledger names: if one you need is missing, widen the era binding
22
+ * (`internal/ledger/v9.ts`) rather than importing the ledger package around the seam. Tests may
23
+ * import the ledger package directly where they must compare module identity.
24
+ *
25
+ * The seam is deliberately a module, not an injected service: which ledger era a build speaks is
26
+ * a packaging-level fact — one era per build artifact — not a runtime dependency to vary per
27
+ * effect. Downstream multi-era consumers select between era-scoped entries instead.
28
+ */
29
+ import { Effect } from 'effect';
30
+ import * as ContractRuntimeError from './ContractRuntimeError.js';
31
+ import { makeConversions, tryConvert } from './internal/ledger/conversions.js';
32
+ import * as CurrentEra from './internal/ledger/current.js';
33
+ import * as CurrentRuntime from './internal/runtime/current.js';
34
+ export { tryConvert } from './internal/ledger/conversions.js';
35
+ export * from './internal/ledger/current.js';
36
+ // The conversions are instantiated from the two `current.ts` bindings rather than written against
37
+ // them, so a second era can be instantiated alongside this one (midnight-sdk#387/#388). Passing
38
+ // both halves in one call is also what finally ties the era pair together statically: the ledger
39
+ // era and the compact-runtime line are era-paired, and until this existed only
40
+ // `CompactRuntime.test.ts` checked at run time that the two independent `current.ts` files agreed.
41
+ const conversions = makeConversions(CurrentEra, CurrentRuntime);
42
+ /**
43
+ * Converts a runtime `ContractState` to this era's ledger `ContractState`.
44
+ *
45
+ * @category conversions
46
+ */
47
+ export const fromRuntimeContractState = conversions.fromRuntimeContractState;
48
+ /**
49
+ * Converts this era's ledger `ContractState` to a runtime `ContractState`.
50
+ *
51
+ * @category conversions
52
+ */
53
+ export const toRuntimeContractState = conversions.toRuntimeContractState;
54
+ /**
55
+ * Deserializes ledger-serialized bytes into this era's ledger `ContractState`.
56
+ *
57
+ * @category conversions
58
+ */
59
+ export const contractStateFromBytes = conversions.contractStateFromBytes;
60
+ /**
61
+ * Deserializes ledger-serialized bytes into this era's `LedgerParameters`.
62
+ *
63
+ * @category conversions
64
+ */
65
+ export const parametersFromBytes = conversions.parametersFromBytes;
66
+ /**
67
+ * Converts a runtime `ContractMaintenanceAuthority` to this era's ledger one.
68
+ *
69
+ * @category conversions
70
+ */
71
+ export const fromRuntimeMaintenanceAuthority = conversions.fromRuntimeMaintenanceAuthority;
72
+ /**
73
+ * Converts a runtime `StateValue` to this era's ledger `StateValue` via the shared binary
74
+ * encoding.
75
+ *
76
+ * @category conversions
77
+ */
78
+ export const fromRuntimeStateValue = conversions.fromRuntimeStateValue;
79
+ /**
80
+ * Converts a runtime `QueryContext` to this era's ledger `QueryContext`, carrying `state`,
81
+ * `address`, `block`, `effects`, and the commitment indices (`comIndices`).
82
+ *
83
+ * @category conversions
84
+ */
85
+ export const fromRuntimeQueryContext = conversions.fromRuntimeQueryContext;
86
+ /**
87
+ * Adapts a platform-js signing key to this era's ledger `SigningKey`, failing when the signature
88
+ * scheme is not supported by the era's CMA path.
89
+ *
90
+ * @category conversions
91
+ */
92
+ export const fromPlatformSigningKey = conversions.fromPlatformSigningKey;
93
+ /**
94
+ * Resolves the `ContractOperation` for a circuit from a contract's ledger state, failing with a
95
+ * {@link ContractRuntimeError.ContractRuntimeError} if absent. A state with no operation for the
96
+ * requested circuit (e.g. a state file for the wrong contract) would otherwise be cast from
97
+ * `undefined` and surface as an opaque native fault.
98
+ *
99
+ * Era-independent, so it stays here rather than in the conversions factory: it reads the era's own
100
+ * `ContractState` and needs no second binding.
101
+ *
102
+ * @remarks
103
+ * Both of the ways a bad state file fails here are held in the error channel. `operation()`
104
+ * returning `undefined` is the wrong-contract case; `operation()` *throwing* is the
105
+ * wrong-WASM-instance case (`expected instance of ContractState`), and since this function's
106
+ * result is built while the caller's `Effect.gen` body runs, an unwrapped throw would be a defect
107
+ * that escapes the caller's `catchAll` entirely — the opaque fault this function exists to
108
+ * prevent.
109
+ *
110
+ * @category conversions
111
+ */
112
+ export const operationForCircuit = (state, circuitId, contractAddress) => tryConvert(`Unexpected error resolving the operation for circuit '${circuitId}' on '${contractAddress}'`, () => state.operation(circuitId)).pipe(Effect.flatMap((operation) => operation === undefined
113
+ ? ContractRuntimeError.make(`Contract state for '${contractAddress}' has no operation for circuit '${circuitId}'.`)
114
+ : Effect.succeed(operation)));
115
+ //# sourceMappingURL=Ledger.js.map
@@ -0,0 +1 @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C,sBAAsB,CAAC;AAEzE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAI8D,CAC5F,KAAK,EACL,SAAS,EACT,eAAe,EACf,EAAE,CACF,UAAU,CAAC,yDAAyD,SAAS,SAAS,eAAe,GAAG,EAAE,GAAG,EAAE,CAC7G,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,CAC3B,CAAC,IAAI,CACJ,MAAM,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE,CAC3B,SAAS,KAAK,SAAS;IACrB,CAAC,CAAC,oBAAoB,CAAC,IAAI,CACvB,uBAAuB,eAAe,mCAAmC,SAAS,IAAI,CACvF;IACH,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAC9B,CACF,CAAC"}
@@ -0,0 +1,43 @@
1
+ /*
2
+ * This file is part of midnight-sdk.
3
+ * Copyright (C) 2025 Midnight Foundation
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * You may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ import * as Error from '@effect/platform/Error';
16
+ import { hasProperty } from 'effect/Predicate';
17
+ const TypeId = Symbol.for('compact-js/effect/MalformedHexPrefixError');
18
+ /**
19
+ * A query supplied a `fieldPrefixes` prefix that is not valid hex. Unlike the never-throw contract
20
+ * for on-chain event decoding, a malformed query prefix is a caller programming error (a typo, or a
21
+ * non-hex blob such as a UUID) rather than a normal degraded input — surfacing it fails fast instead
22
+ * of silently matching nothing.
23
+ *
24
+ * @category errors
25
+ */
26
+ export class MalformedHexPrefixError extends Error.TypeIdError(TypeId, 'MalformedHexPrefixError') {
27
+ }
28
+ /**
29
+ * Determines if a value is a malformed hex prefix error.
30
+ *
31
+ * @param u The value to check.
32
+ * @returns `true` if `u` is a {@link MalformedHexPrefixError}; `false` otherwise.
33
+ *
34
+ * @category guards
35
+ */
36
+ export const isMalformedHexPrefixError = (u) => hasProperty(u, TypeId);
37
+ /**
38
+ * Creates a new {@link MalformedHexPrefixError} for the given (normalized) prefix.
39
+ *
40
+ * @category constructors
41
+ */
42
+ export const make = (prefix) => new MalformedHexPrefixError({ message: `Malformed hex prefix in query filter: "${prefix}"`, prefix });
43
+ //# sourceMappingURL=MalformedHexPrefixError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MalformedHexPrefixError.js","sourceRoot":"","sources":["../../../src/effect/MalformedHexPrefixError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,KAAK,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,MAAM,GAAkB,MAAM,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;AAGtF;;;;;;;GAOG;AACH,MAAM,OAAO,uBAAwB,SAAQ,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,yBAAyB,CAK9F;CAAG;AAEL;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAU,EAAgC,EAAE,CAAC,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAE9G;;;;GAIG;AACH,MAAM,CAAC,MAAM,IAAI,GAAgD,CAAC,MAAM,EAAE,EAAE,CAC1E,IAAI,uBAAuB,CAAC,EAAE,OAAO,EAAE,0CAA0C,MAAM,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC"}
@@ -0,0 +1,23 @@
1
+ /*
2
+ * This file is part of midnight-sdk.
3
+ * Copyright (C) 2025 Midnight Foundation
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * You may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ import { Context } from 'effect';
16
+ /**
17
+ * Provides utilities for working with the ZK assets of a compiled Compact contract.
18
+ *
19
+ * @category services
20
+ */
21
+ export class ZKConfiguration extends Context.Tag('compact-js/ZKConfiguration')() {
22
+ }
23
+ //# sourceMappingURL=ZKConfiguration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ZKConfiguration.js","sourceRoot":"","sources":["../../../src/effect/ZKConfiguration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,OAAO,EAA4B,MAAM,QAAQ,CAAC;AAM3D;;;;GAIG;AACH,MAAM,OAAO,eAAgB,SAAQ,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,EAG3E;CAAG"}
@@ -0,0 +1,46 @@
1
+ /*
2
+ * This file is part of midnight-sdk.
3
+ * Copyright (C) 2025 Midnight Foundation
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * You may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ import * as Error from '@effect/platform/Error';
16
+ import { hasProperty } from 'effect/Predicate';
17
+ const TypeId = Symbol.for('compact-js/effect/ZKConfigurationReadError');
18
+ /**
19
+ * Error indicating a failure to read a ZK asset.
20
+ *
21
+ * @category errors
22
+ */
23
+ export class ZKConfigurationReadError extends Error.TypeIdError(TypeId, 'ZKConfigurationReadError') {
24
+ }
25
+ /**
26
+ * Determines if a value is a ZK configuration read error.
27
+ *
28
+ * @param u The value to check.
29
+ * @returns `true` if `u` is a {@link ZKConfigurationReadError}; `false` otherwise.
30
+ *
31
+ * @category guards
32
+ */
33
+ export const isReadError = (u) => hasProperty(u, TypeId);
34
+ /**
35
+ * Creates a new {@link ZKConfigurationReadError}.
36
+ *
37
+ * @category constructors
38
+ */
39
+ export const make = (contractTag, provableCircuitId, assetType, cause) => new ZKConfigurationReadError({
40
+ contractTag,
41
+ provableCircuitId,
42
+ assetType,
43
+ message: `Failed to read ${assetType.replaceAll('-', ' ')} for ${contractTag}#${provableCircuitId}`,
44
+ cause
45
+ });
46
+ //# sourceMappingURL=ZKConfigurationReadError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ZKConfigurationReadError.js","sourceRoot":"","sources":["../../../src/effect/ZKConfigurationReadError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,KAAK,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAI/C,MAAM,MAAM,GAAkB,MAAM,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;AAQvF;;;;GAIG;AACH,MAAM,OAAO,wBAAyB,SAAQ,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,0BAA0B,CAehG;CAAI;AAEN;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAU,EAAiC,EAAE,CAAC,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAEjG;;;;GAIG;AACH,MAAM,CAAC,MAAO,IAAI,GAKc,CAAC,WAAW,EAAE,iBAAiB,EAAE,SAAS,EAAE,KAAe,EAAE,EAAE,CAC7F,IAAI,wBAAwB,CAAC;IAC3B,WAAW;IACX,iBAAiB;IACjB,SAAS;IACT,OAAO,EAAE,kBAAkB,SAAS,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,QAAQ,WAAW,IAAI,iBAAiB,EAAE;IACnG,KAAK;CACN,CAAC,CAAC"}