@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,41 @@
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/ContractConfigurationError');
18
+ /**
19
+ * An error occurred while executing a constructor, or a circuit, of an executable contract with regards to
20
+ * its configuration.
21
+ *
22
+ * @category errors
23
+ */
24
+ export class ContractConfigurationError extends Error.TypeIdError(TypeId, 'ContractConfigurationError') {
25
+ }
26
+ /**
27
+ * Determines if a value is a contract configuration error.
28
+ *
29
+ * @param u The value to check.
30
+ * @returns `true` if `u` is a {@link ContractConfigurationError}; `false` otherwise.
31
+ *
32
+ * @category guards
33
+ */
34
+ export const isConfigurationError = (u) => hasProperty(u, TypeId);
35
+ /**
36
+ * Creates a new {@link ContractConfigurationError}.
37
+ *
38
+ * @category constructors
39
+ */
40
+ export const make = (message, contractState, cause) => new ContractConfigurationError({ message, contractState, cause });
41
+ //# sourceMappingURL=ContractConfigurationError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContractConfigurationError.js","sourceRoot":"","sources":["../../../src/effect/ContractConfigurationError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,KAAK,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAgB/C,MAAM,MAAM,GAAkB,MAAM,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC;AAGzF;;;;;GAKG;AACH,MAAM,OAAO,0BAA2B,SAAQ,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,4BAA4B,CAOpG;CAAI;AAEN;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAU,EAAmC,EAAE,CAAC,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAE5G;;;;GAIG;AACH,MAAM,CAAC,MAAM,IAAI,GAIb,CAAC,OAAe,EAAE,aAA6B,EAAE,KAAe,EAAE,EAAE,CACtE,IAAI,0BAA0B,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,CAAC"}
@@ -0,0 +1,150 @@
1
+ import { Context, Effect, Layer, PubSub, Ref, Stream } from 'effect';
2
+ import * as ContractLog from './ContractLog.js';
3
+ import * as MalformedHexPrefixError from './MalformedHexPrefixError.js';
4
+ /**
5
+ * Provides an in-process store, query surface, and subscription feed for contract log events.
6
+ *
7
+ * @category services
8
+ */
9
+ export class ContractEventStore extends Context.Tag('compact-js/ContractEventStore')() {
10
+ }
11
+ // --- filter matching --------------------------------------------------------------------------
12
+ /** Lowercase and strip a single leading `0x`; does NOT validate that the result is hex. */
13
+ const normalizeHex = (hex) => hex.toLowerCase().replace(/^0x/, '');
14
+ /** A (possibly empty) run of lowercase hex digits — the shape a normalized prefix must have. */
15
+ const HEX_PREFIX = /^[0-9a-f]*$/;
16
+ const HEX_DIGITS = '0123456789abcdef';
17
+ /**
18
+ * Validates that every `fieldPrefixes` prefix in a filter is valid hex, failing fast with a
19
+ * {@link MalformedHexPrefixError.MalformedHexPrefixError} otherwise. A non-hex prefix is a caller
20
+ * programming error that would otherwise silently match nothing (see {@link bytesHaveHexPrefix}),
21
+ * so it is surfaced rather than swallowed — distinct from the never-throw contract that governs
22
+ * on-chain event decoding.
23
+ */
24
+ const validateFilter = (filter) => Effect.gen(function* () {
25
+ if (filter?.fieldPrefixes === undefined)
26
+ return;
27
+ for (const { prefix } of filter.fieldPrefixes) {
28
+ const normalized = normalizeHex(prefix);
29
+ if (!HEX_PREFIX.test(normalized))
30
+ return yield* Effect.fail(MalformedHexPrefixError.make(normalized));
31
+ }
32
+ });
33
+ /**
34
+ * Tests whether `bytes` begins with the (already-normalized, lowercase) hex `prefix`, comparing
35
+ * only the bytes the prefix actually covers rather than rendering the whole field to hex. Each
36
+ * pair of hex chars matches one whole byte; a trailing odd nibble matches the **high** nibble of
37
+ * the next byte — so `'7'` matches any field whose first byte is `0x70`–`0x7f`, whereas `'07'`
38
+ * matches only the byte `0x07`. Pass an **even-length** prefix for byte-accurate matching. An
39
+ * empty prefix matches any field. A prefix longer (in nibbles) than the field is never a match.
40
+ */
41
+ const bytesHaveHexPrefix = (bytes, prefix) => {
42
+ if ((prefix.length + 1) >> 1 > bytes.length)
43
+ return false;
44
+ const fullBytes = prefix.length >> 1;
45
+ for (let i = 0; i < fullBytes; i++) {
46
+ const hi = HEX_DIGITS.indexOf(prefix[i * 2]);
47
+ const lo = HEX_DIGITS.indexOf(prefix[i * 2 + 1]);
48
+ if (bytes[i] !== ((hi << 4) | lo))
49
+ return false;
50
+ }
51
+ if ((prefix.length & 1) === 1 && bytes[fullBytes] >> 4 !== HEX_DIGITS.indexOf(prefix[prefix.length - 1]))
52
+ return false;
53
+ return true;
54
+ };
55
+ const sameAddress = (a, b) => String(a).toLowerCase() === String(b).toLowerCase();
56
+ const matchesFieldPrefix = (event, filter) => {
57
+ const fields = ContractLog.indexedFields(event);
58
+ const prefix = normalizeHex(filter.prefix);
59
+ const candidates = filter.fieldName !== undefined
60
+ ? fields[filter.fieldName] !== undefined
61
+ ? [fields[filter.fieldName]]
62
+ : []
63
+ : Object.values(fields);
64
+ return candidates.some((bytes) => bytesHaveHexPrefix(bytes, prefix));
65
+ };
66
+ /** Determine whether a stored event satisfies every present criterion of a filter. */
67
+ export const matches = (event, filter) => {
68
+ if (filter === undefined)
69
+ return true;
70
+ if (filter.contractAddress !== undefined && !sameAddress(event.address, filter.contractAddress))
71
+ return false;
72
+ if (filter.eventType !== undefined && event.eventType !== filter.eventType)
73
+ return false;
74
+ if (filter.fromId !== undefined && event.id < filter.fromId)
75
+ return false;
76
+ if (filter.fieldPrefixes !== undefined && !filter.fieldPrefixes.every((f) => matchesFieldPrefix(event, f)))
77
+ return false;
78
+ return true;
79
+ };
80
+ /** Default `PubSub` capacity for the live subscription feed. */
81
+ export const DEFAULT_CAPACITY = 1024;
82
+ /**
83
+ * Builds an in-memory {@link ContractEventStore} layer backed by a `Ref` (full history) and a
84
+ * **sliding** `PubSub` (live feed). Events accumulate for the lifetime of the provided scope; ids
85
+ * are monotonic starting at `1`.
86
+ *
87
+ * @remarks
88
+ * The live feed uses a **sliding** buffer rather than a back-pressuring one, and this is a
89
+ * deliberate liveness choice: `append` publishes to the feed while holding the append lock, so a
90
+ * back-pressuring buffer would let a single slow or non-draining subscriber fill the buffer, wedge
91
+ * the suspended publish under the lock, and block **every** subsequent append — including those
92
+ * driven by circuit execution — indefinitely. A sliding buffer never suspends the publisher, so
93
+ * appends can never be wedged by a stalled consumer. The trade-off is that a subscriber that cannot
94
+ * keep up loses the **oldest** un-consumed live events once more than `capacity` accumulate (a gap
95
+ * in its live tail). Because the full history is always retained in the backing `Ref`, such a
96
+ * subscriber can recover any missed events by re-`query`-ing or resubscribing with a `fromId`
97
+ * cursor.
98
+ *
99
+ * @param capacity The live-feed buffer size; once more than this many events are buffered for a
100
+ * subscriber, the oldest are dropped for that subscriber. Defaults to {@link DEFAULT_CAPACITY}.
101
+ *
102
+ * @category layers
103
+ */
104
+ export const makeLayer = (capacity = DEFAULT_CAPACITY) => Layer.effect(ContractEventStore, Effect.gen(function* () {
105
+ const state = yield* Ref.make({ nextId: 1n, events: [] });
106
+ // Sliding, not back-pressuring: see `makeLayer`'s @remarks — because `publishAll` runs under
107
+ // `appendMutex`, a bounded buffer would let one stalled subscriber wedge every append.
108
+ const pubsub = yield* PubSub.sliding(capacity);
109
+ // Serialize appends: id assignment (`Ref.modify`) and publishing to the live feed are two
110
+ // effects, so without a critical section two concurrent appends could publish out of id
111
+ // order (e.g. assign 1, assign 2, publish 2, publish 1). The mutex makes each append's
112
+ // assign-then-publish atomic, honoring the ascending-`id` guarantee of `subscribe`.
113
+ const appendMutex = yield* Effect.makeSemaphore(1);
114
+ const append = (events) => appendMutex.withPermits(1)(Effect.gen(function* () {
115
+ const stored = yield* Ref.modify(state, (current) => {
116
+ const assigned = events.map((event, i) => ({ ...event, id: current.nextId + BigInt(i) }));
117
+ return [
118
+ assigned,
119
+ { nextId: current.nextId + BigInt(events.length), events: [...current.events, ...assigned] }
120
+ ];
121
+ });
122
+ yield* PubSub.publishAll(pubsub, stored);
123
+ return stored;
124
+ }));
125
+ const query = (filter) => validateFilter(filter).pipe(Effect.andThen(Ref.get(state)), Effect.map((current) => current.events.filter((event) => matches(event, filter))));
126
+ const subscribe = (filter) => Stream.unwrapScoped(Effect.gen(function* () {
127
+ // Reject a malformed query prefix before wiring up the subscription (fails the stream).
128
+ yield* validateFilter(filter);
129
+ // Subscribe to the live feed BEFORE snapshotting history, so no event appended during
130
+ // set-up can slip through the gap between the two.
131
+ const subscription = yield* PubSub.subscribe(pubsub);
132
+ const snapshot = yield* Ref.get(state);
133
+ // Everything with id <= snapshotMaxId is in the replayed snapshot; live events (which
134
+ // have strictly greater, monotonic ids) are tailed from the PubSub. This id boundary is
135
+ // what prevents a duplicate for an event that is in both the snapshot and the queue.
136
+ const snapshotMaxId = snapshot.events.length > 0 ? snapshot.events[snapshot.events.length - 1].id : 0n;
137
+ const history = snapshot.events.filter((event) => matches(event, filter));
138
+ const live = Stream.fromQueue(subscription).pipe(Stream.filter((event) => event.id > snapshotMaxId && matches(event, filter)));
139
+ return Stream.concat(Stream.fromIterable(history), live);
140
+ }));
141
+ return { append, query, subscribe };
142
+ }));
143
+ /**
144
+ * An in-memory {@link ContractEventStore} layer with the default live-feed capacity
145
+ * ({@link DEFAULT_CAPACITY}). See {@link makeLayer} to configure the capacity.
146
+ *
147
+ * @category layers
148
+ */
149
+ export const layer = makeLayer();
150
+ //# sourceMappingURL=ContractEventStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContractEventStore.js","sourceRoot":"","sources":["../../../src/effect/ContractEventStore.ts"],"names":[],"mappings":"AA0CA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErE,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,uBAAuB,MAAM,8BAA8B,CAAC;AAgDxE;;;;GAIG;AACH,MAAM,OAAO,kBAAmB,SAAQ,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,EAGjF;CAAG;AAwDN,iGAAiG;AAEjG,2FAA2F;AAC3F,MAAM,YAAY,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAEnF,gGAAgG;AAChG,MAAM,UAAU,GAAG,aAAa,CAAC;AAEjC,MAAM,UAAU,GAAG,kBAAkB,CAAC;AAEtC;;;;;;GAMG;AACH,MAAM,cAAc,GAAG,CAAC,MAA4B,EAAwE,EAAE,CAC5H,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,IAAI,MAAM,EAAE,aAAa,KAAK,SAAS;QAAE,OAAO;IAChD,KAAK,MAAM,EAAE,MAAM,EAAE,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;QAC9C,MAAM,UAAU,GAAG,YAAY,CAAC,MAA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MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACpF,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;QAC1E,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,IAAI,CAC9C,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,aAAa,IAAI,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAC7E,CAAC;QACF,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,CAAC;IAC3D,CAAC,CAAC,CACH,CAAC;IAEJ,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AACtC,CAAC,CAAC,CACH,CAAC;AAEJ;;;;;GAKG;AACH,MAAM,CAAC,MAAM,KAAK,GAAoC,SAAS,EAAE,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/ContractEventValidationError');
18
+ /**
19
+ * An error that occurred while validating that contract events comply with system constraints.
20
+ *
21
+ * @category errors
22
+ */
23
+ export class ContractEventValidationError extends Error.TypeIdError(TypeId, 'ContractEventValidationError') {
24
+ }
25
+ /**
26
+ * Determines if a value is a contract event validation error.
27
+ *
28
+ * @param u The value to check.
29
+ * @returns `true` if `u` is a {@link ContractEventValidationError}; `false` otherwise.
30
+ *
31
+ * @category guards
32
+ */
33
+ export const isValidationError = (u) => hasProperty(u, TypeId);
34
+ /**
35
+ * Creates a new {@link ContractEventValidationError}.
36
+ *
37
+ * @category constructors
38
+ */
39
+ export const make = (message, cause) => new ContractEventValidationError({ message, cause });
40
+ //# sourceMappingURL=ContractEventValidationError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContractEventValidationError.js","sourceRoot":"","sources":["../../../src/effect/ContractEventValidationError.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,gDAAgD,CAAC,CAAC;AAG3F;;;;GAIG;AACH,MAAM,OAAO,4BAA6B,SAAQ,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,8BAA8B,CAKxG;CAAI;AAEN;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAU,EAAqC,EAAE,CAAC,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAE3G;;;;GAIG;AACH,MAAM,CAAC,MAAM,IAAI,GAAuE,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CACzG,IAAI,4BAA4B,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC"}
@@ -0,0 +1,49 @@
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 { Effect } from 'effect';
16
+ import { TreeFormatter } from 'effect/ParseResult';
17
+ import * as Schema from 'effect/Schema';
18
+ import * as ContractEventValidationError from './ContractEventValidationError.js';
19
+ import { LogEventTypeSchema } from './ContractLog.js';
20
+ /**
21
+ * Structural schema for a single contract log event — the `content` of a `log`-tagged
22
+ * `GatherResult`.
23
+ *
24
+ * The `data` payload is an on-chain `EncodedStateValue` whose deep structure is parsed (and
25
+ * gracefully degraded) by the ledger/VM per MIP-0002, so it is accepted as-is here: this
26
+ * boundary check only asserts that the event envelope is well-formed.
27
+ */
28
+ const LogEventSchema = Schema.Struct({
29
+ version: Schema.Number,
30
+ eventType: LogEventTypeSchema,
31
+ data: Schema.Unknown
32
+ });
33
+ const decodeLogEvents = Schema.decodeUnknown(Schema.Array(LogEventSchema), { errors: 'all' });
34
+ /**
35
+ * Validates that `events` is a well-formed array of contract log events.
36
+ *
37
+ * Events reach this boundary as untrusted input, so they are decoded from `unknown` with a
38
+ * {@link Schema} — yielding both the structural validation and a typed failure, rather than
39
+ * hand-rolled `in`/`instanceof` checks.
40
+ *
41
+ * @param events The value to validate.
42
+ * @returns An {@link Effect} that fails with a
43
+ * {@link ContractEventValidationError.ContractEventValidationError} if `events` is not a valid
44
+ * array of log events.
45
+ *
46
+ * @category validation
47
+ */
48
+ export const validateEvents = (events) => decodeLogEvents(events).pipe(Effect.asVoid, Effect.mapError((parseError) => ContractEventValidationError.make(`Invalid contract log events: ${TreeFormatter.formatErrorSync(parseError)}`, parseError)));
49
+ //# sourceMappingURL=ContractEventValidator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContractEventValidator.js","sourceRoot":"","sources":["../../../src/effect/ContractEventValidator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,4BAA4B,MAAM,mCAAmC,CAAC;AAClF,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD;;;;;;;GAOG;AACH,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC;IACnC,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,SAAS,EAAE,kBAAkB;IAC7B,IAAI,EAAE,MAAM,CAAC,OAAO;CACrB,CAAC,CAAC;AAEH,MAAM,eAAe,GAAG,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;AAE9F;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,MAAe,EACiE,EAAE,CAClF,eAAe,CAAC,MAAM,CAAC,CAAC,IAAI,CAC1B,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,QAAQ,CAAC,CAAC,UAAU,EAAE,EAAE,CAC7B,4BAA4B,CAAC,IAAI,CAC/B,gCAAgC,aAAa,CAAC,eAAe,CAAC,UAAU,CAAC,EAAE,EAC3E,UAAU,CACX,CACF,CACF,CAAC"}
@@ -0,0 +1,50 @@
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
+ * Contract execution for the era this build binds.
17
+ *
18
+ * @remarks
19
+ * The bodies live in `internal/executable.ts`, which takes an era pair as arguments; this module is
20
+ * that factory applied to the {@link Ledger} and {@link CompactRuntime} facades — so it follows
21
+ * each seam's `current.ts`, exactly as it did when it held the implementation itself. Consumers
22
+ * see no difference: the type and function names, their parameters and their results are unchanged.
23
+ *
24
+ * What changed is that this is no longer the *only* application. `internal/era/v8Executable.ts` and
25
+ * `internal/era/v9Executable.ts` apply the same factory to a pinned era pair, which is what lets
26
+ * `/v8/effect` and `/v9/effect` export an executable that genuinely belongs to the era its path
27
+ * names rather than to whichever era the build bound (midnight-sdk#387/#388).
28
+ *
29
+ * @module
30
+ */
31
+ import * as CompactRuntime from './CompactRuntime.js';
32
+ import * as Internal from './internal/executable.js';
33
+ import * as Ledger from './Ledger.js';
34
+ const executable = Internal.makeExecutable(Ledger, CompactRuntime);
35
+ /**
36
+ * Takes a Compact compiled contract, and makes it executable.
37
+ *
38
+ * @param compiledContract A {@link CompiledContract}
39
+ * @returns A {@link ContractExecutable} for `compiledContract`.
40
+ *
41
+ * @category constructors
42
+ */
43
+ export const make = executable.make;
44
+ /**
45
+ * Provides a layer to the executable contract.
46
+ *
47
+ * @category combinators
48
+ */
49
+ export const provide = executable.provide;
50
+ //# sourceMappingURL=ContractExecutable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContractExecutable.js","sourceRoot":"","sources":["../../../src/effect/ContractExecutable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAC;AAEtD,OAAO,KAAK,QAAQ,MAAM,0BAA0B,CAAC;AACrD,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAMtC,MAAM,UAAU,GAAG,QAAQ,CAAC,cAAc,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AA0EnE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;AAEpC;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC"}
@@ -0,0 +1,17 @@
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 { ManagedRuntime } from 'effect';
16
+ export const make = (layer) => ManagedRuntime.make(layer);
17
+ //# sourceMappingURL=ContractExecutableRuntime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContractExecutableRuntime.js","sourceRoot":"","sources":["../../../src/effect/ContractExecutableRuntime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAc,cAAc,EAAE,MAAM,QAAQ,CAAC;AAIpD,MAAM,CAAC,MAAM,IAAI,GAAG,CAAI,KAAiD,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA"}
@@ -0,0 +1,67 @@
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 { sha256 } from '@noble/hashes/sha2.js';
16
+ import { bytesToHex } from '@noble/hashes/utils.js';
17
+ const PREFIX = 'contract:';
18
+ const CONTRACT_ADDRESS_PATTERN = /^[0-9a-fA-F]{64}$/;
19
+ const CIRCUIT_ID_PATTERN = /^[A-Za-z0-9_]+$/;
20
+ const VERIFIER_KEY_HASH_PATTERN = /^[0-9a-f]{64}$/;
21
+ const LOCATION_PATTERN = /^contract:([0-9a-fA-F]{64})\/([A-Za-z0-9_]+)\?vk=([0-9a-f]{64})$/;
22
+ /**
23
+ * Computes the lowercase hex SHA-256 digest of a raw verifier key.
24
+ *
25
+ * @param verifierKey The raw verifier key bytes, exactly as deployed in the contract's operation.
26
+ */
27
+ export const hashVerifierKey = (verifierKey) => bytesToHex(sha256(verifierKey));
28
+ /**
29
+ * Encodes a {@link ContractKeyLocation} into the canonical grammar.
30
+ *
31
+ * @throws Error If any component fails validation; an invalid component can never be a key
32
+ * location, and silently encoding one would produce a location no prover can resolve.
33
+ */
34
+ export const encodeContractKeyLocation = (location) => {
35
+ if (!CONTRACT_ADDRESS_PATTERN.test(location.contractAddress)) {
36
+ throw new Error(`Cannot encode contract key location: contract address '${location.contractAddress}' is not 64 hex characters.`);
37
+ }
38
+ if (!CIRCUIT_ID_PATTERN.test(location.circuitId)) {
39
+ throw new Error(`Cannot encode contract key location: circuit id '${location.circuitId}' must match [A-Za-z0-9_]+.`);
40
+ }
41
+ if (!VERIFIER_KEY_HASH_PATTERN.test(location.verifierKeyHash)) {
42
+ throw new Error(`Cannot encode contract key location: verifier key hash '${location.verifierKeyHash}' is not a lowercase hex SHA-256 digest.`);
43
+ }
44
+ return `${PREFIX}${location.contractAddress}/${location.circuitId}?vk=${location.verifierKeyHash}`;
45
+ };
46
+ /**
47
+ * Parses a canonical key location, returning `undefined` when the input is not in the canonical
48
+ * grammar (e.g. a bare circuit name, or a `midnight/` protocol builtin). Parsing is strict:
49
+ * a string that begins with `contract:` but deviates from the grammar is rejected rather than
50
+ * repaired, so that assembler and prover can never disagree about a location's meaning.
51
+ */
52
+ export const parseContractKeyLocation = (keyLocation) => {
53
+ const match = LOCATION_PATTERN.exec(keyLocation);
54
+ if (match === null) {
55
+ return undefined;
56
+ }
57
+ const contractAddress = match[1];
58
+ const circuitId = match[2];
59
+ const verifierKeyHash = match[3];
60
+ if (contractAddress === undefined || circuitId === undefined || verifierKeyHash === undefined) {
61
+ // Unreachable: the pattern has exactly three non-optional capture groups. Guarded (rather
62
+ // than asserted) so the module is sound under `noUncheckedIndexedAccess` in any consumer.
63
+ return undefined;
64
+ }
65
+ return { contractAddress, circuitId, verifierKeyHash };
66
+ };
67
+ //# sourceMappingURL=ContractKeyLocation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContractKeyLocation.js","sourceRoot":"","sources":["../../../src/effect/ContractKeyLocation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAqCpD,MAAM,MAAM,GAAG,WAAW,CAAC;AAC3B,MAAM,wBAAwB,GAAG,mBAAmB,CAAC;AACrD,MAAM,kBAAkB,GAAG,iBAAiB,CAAC;AAC7C,MAAM,yBAAyB,GAAG,gBAAgB,CAAC;AACnD,MAAM,gBAAgB,GAAG,kEAAkE,CAAC;AAE5F;;;;GAIG;A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