@reclaimprotocol/attestor-core 5.0.1-beta.1 → 5.0.1-beta.2

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 (261) hide show
  1. package/lib/avs/abis/avsDirectoryABI.d.ts +60 -0
  2. package/lib/avs/abis/avsDirectoryABI.js +343 -0
  3. package/lib/avs/abis/delegationABI.d.ts +126 -0
  4. package/lib/avs/abis/delegationABI.js +4 -0
  5. package/lib/avs/abis/registryABI.d.ts +136 -0
  6. package/lib/avs/abis/registryABI.js +728 -0
  7. package/lib/avs/client/create-claim-on-avs.d.ts +12 -0
  8. package/lib/avs/client/create-claim-on-avs.js +168 -0
  9. package/lib/avs/config.d.ts +7 -0
  10. package/lib/avs/config.js +26 -0
  11. package/lib/avs/contracts/ReclaimServiceManager.d.ts +601 -0
  12. package/lib/avs/contracts/ReclaimServiceManager.js +0 -0
  13. package/lib/avs/contracts/common.d.ts +50 -0
  14. package/lib/avs/contracts/common.js +0 -0
  15. package/lib/avs/contracts/factories/ReclaimServiceManager__factory.d.ts +890 -0
  16. package/lib/avs/contracts/factories/ReclaimServiceManager__factory.js +1183 -0
  17. package/lib/avs/contracts/factories/index.d.ts +1 -0
  18. package/lib/avs/contracts/factories/index.js +4 -0
  19. package/lib/avs/contracts/index.d.ts +3 -0
  20. package/lib/avs/contracts/index.js +6 -0
  21. package/lib/avs/types/index.d.ts +55 -0
  22. package/lib/avs/types/index.js +0 -0
  23. package/lib/avs/utils/contracts.d.ts +21 -0
  24. package/lib/avs/utils/contracts.js +53 -0
  25. package/lib/avs/utils/register.d.ts +27 -0
  26. package/lib/avs/utils/register.js +74 -0
  27. package/lib/avs/utils/tasks.d.ts +22 -0
  28. package/lib/avs/utils/tasks.js +48 -0
  29. package/lib/client/create-claim.d.ts +5 -0
  30. package/lib/client/create-claim.js +461 -0
  31. package/lib/client/index.d.ts +3 -0
  32. package/lib/client/index.js +3 -0
  33. package/lib/client/tunnels/make-rpc-tcp-tunnel.d.ts +16 -0
  34. package/lib/client/tunnels/make-rpc-tcp-tunnel.js +53 -0
  35. package/lib/client/tunnels/make-rpc-tls-tunnel.d.ts +26 -0
  36. package/lib/client/tunnels/make-rpc-tls-tunnel.js +127 -0
  37. package/lib/client/utils/attestor-pool.d.ts +8 -0
  38. package/lib/client/utils/attestor-pool.js +24 -0
  39. package/lib/client/utils/client-socket.d.ts +11 -0
  40. package/lib/client/utils/client-socket.js +120 -0
  41. package/lib/client/utils/message-handler.d.ts +4 -0
  42. package/lib/client/utils/message-handler.js +97 -0
  43. package/lib/config/index.d.ts +31 -0
  44. package/lib/config/index.js +62 -0
  45. package/lib/external-rpc/benchmark.d.ts +1 -0
  46. package/lib/external-rpc/benchmark.js +82 -0
  47. package/lib/external-rpc/event-bus.d.ts +7 -0
  48. package/lib/external-rpc/event-bus.js +17 -0
  49. package/lib/external-rpc/global.d.js +0 -0
  50. package/lib/external-rpc/handle-incoming-msg.d.ts +2 -0
  51. package/lib/external-rpc/handle-incoming-msg.js +241 -0
  52. package/lib/external-rpc/index.d.ts +3 -0
  53. package/lib/external-rpc/index.js +3 -0
  54. package/lib/external-rpc/jsc-polyfills/1.d.ts +14 -0
  55. package/lib/external-rpc/jsc-polyfills/1.js +80 -0
  56. package/lib/external-rpc/jsc-polyfills/2.d.ts +1 -0
  57. package/lib/external-rpc/jsc-polyfills/2.js +15 -0
  58. package/lib/external-rpc/jsc-polyfills/event.d.ts +10 -0
  59. package/lib/external-rpc/jsc-polyfills/event.js +19 -0
  60. package/lib/external-rpc/jsc-polyfills/index.d.ts +2 -0
  61. package/lib/external-rpc/jsc-polyfills/index.js +2 -0
  62. package/lib/external-rpc/jsc-polyfills/ws.d.ts +21 -0
  63. package/lib/external-rpc/jsc-polyfills/ws.js +83 -0
  64. package/lib/external-rpc/setup-browser.d.ts +6 -0
  65. package/lib/external-rpc/setup-browser.js +33 -0
  66. package/lib/external-rpc/setup-jsc.d.ts +24 -0
  67. package/lib/external-rpc/setup-jsc.js +22 -0
  68. package/lib/external-rpc/types.d.ts +213 -0
  69. package/lib/external-rpc/types.js +0 -0
  70. package/lib/external-rpc/utils.d.ts +20 -0
  71. package/lib/external-rpc/utils.js +100 -0
  72. package/lib/external-rpc/zk.d.ts +14 -0
  73. package/lib/external-rpc/zk.js +58 -0
  74. package/lib/index.d.ts +9 -0
  75. package/lib/index.js +13 -0
  76. package/lib/mechain/abis/governanceABI.d.ts +50 -0
  77. package/lib/mechain/abis/governanceABI.js +461 -0
  78. package/lib/mechain/abis/taskABI.d.ts +157 -0
  79. package/lib/mechain/abis/taskABI.js +512 -0
  80. package/lib/mechain/client/create-claim-on-mechain.d.ts +10 -0
  81. package/lib/mechain/client/create-claim-on-mechain.js +33 -0
  82. package/lib/mechain/client/index.d.ts +1 -0
  83. package/lib/mechain/client/index.js +1 -0
  84. package/lib/mechain/constants/index.d.ts +3 -0
  85. package/lib/mechain/constants/index.js +8 -0
  86. package/lib/mechain/index.d.ts +2 -0
  87. package/lib/mechain/index.js +2 -0
  88. package/lib/mechain/types/index.d.ts +23 -0
  89. package/lib/mechain/types/index.js +0 -0
  90. package/lib/proto/api.d.ts +651 -0
  91. package/lib/proto/api.js +4250 -0
  92. package/lib/proto/tee-bundle.d.ts +156 -0
  93. package/lib/proto/tee-bundle.js +1296 -0
  94. package/lib/providers/http/index.d.ts +18 -0
  95. package/lib/providers/http/index.js +640 -0
  96. package/lib/providers/http/patch-parse5-tree.d.ts +6 -0
  97. package/lib/providers/http/patch-parse5-tree.js +34 -0
  98. package/lib/providers/http/utils.d.ts +77 -0
  99. package/lib/providers/http/utils.js +283 -0
  100. package/lib/providers/index.d.ts +4 -0
  101. package/lib/providers/index.js +7 -0
  102. package/lib/scripts/build-browser.d.ts +1 -0
  103. package/lib/scripts/build-jsc.d.ts +1 -0
  104. package/lib/scripts/build-lib.d.ts +1 -0
  105. package/lib/scripts/check-avs-registration.d.ts +1 -0
  106. package/lib/scripts/check-avs-registration.js +28 -0
  107. package/lib/scripts/fallbacks/crypto.d.ts +1 -0
  108. package/lib/scripts/fallbacks/crypto.js +4 -0
  109. package/lib/scripts/fallbacks/empty.d.ts +3 -0
  110. package/lib/scripts/fallbacks/empty.js +4 -0
  111. package/lib/scripts/fallbacks/re2.d.ts +1 -0
  112. package/lib/scripts/fallbacks/re2.js +7 -0
  113. package/lib/scripts/fallbacks/snarkjs.d.ts +1 -0
  114. package/lib/scripts/fallbacks/snarkjs.js +10 -0
  115. package/lib/scripts/fallbacks/stwo.d.ts +6 -0
  116. package/lib/scripts/fallbacks/stwo.js +159 -0
  117. package/lib/scripts/generate-provider-types.d.ts +5 -0
  118. package/lib/scripts/generate-provider-types.js +101 -0
  119. package/lib/scripts/generate-receipt.d.ts +9 -0
  120. package/lib/scripts/generate-receipt.js +101 -0
  121. package/lib/scripts/generate-toprf-keys.d.ts +1 -0
  122. package/lib/scripts/generate-toprf-keys.js +24 -0
  123. package/lib/scripts/jsc-cli-rpc.d.ts +1 -0
  124. package/lib/scripts/jsc-cli-rpc.js +35 -0
  125. package/lib/scripts/register-avs-operator.d.ts +1 -0
  126. package/lib/scripts/register-avs-operator.js +3 -0
  127. package/lib/scripts/start-server.d.ts +1 -0
  128. package/lib/scripts/start-server.js +11 -0
  129. package/lib/scripts/update-avs-metadata.d.ts +1 -0
  130. package/lib/scripts/update-avs-metadata.js +20 -0
  131. package/lib/scripts/utils.d.ts +1 -0
  132. package/lib/scripts/utils.js +10 -0
  133. package/lib/scripts/whitelist-operator.d.ts +1 -0
  134. package/lib/scripts/whitelist-operator.js +16 -0
  135. package/lib/server/create-server.d.ts +8 -0
  136. package/lib/server/create-server.js +105 -0
  137. package/lib/server/handlers/claimTeeBundle.d.ts +6 -0
  138. package/lib/server/handlers/claimTeeBundle.js +232 -0
  139. package/lib/server/handlers/claimTunnel.d.ts +2 -0
  140. package/lib/server/handlers/claimTunnel.js +80 -0
  141. package/lib/server/handlers/completeClaimOnChain.d.ts +2 -0
  142. package/lib/server/handlers/completeClaimOnChain.js +29 -0
  143. package/lib/server/handlers/createClaimOnChain.d.ts +2 -0
  144. package/lib/server/handlers/createClaimOnChain.js +32 -0
  145. package/lib/server/handlers/createTaskOnMechain.d.ts +2 -0
  146. package/lib/server/handlers/createTaskOnMechain.js +57 -0
  147. package/lib/server/handlers/createTunnel.d.ts +2 -0
  148. package/lib/server/handlers/createTunnel.js +98 -0
  149. package/lib/server/handlers/disconnectTunnel.d.ts +2 -0
  150. package/lib/server/handlers/disconnectTunnel.js +8 -0
  151. package/lib/server/handlers/fetchCertificateBytes.d.ts +2 -0
  152. package/lib/server/handlers/fetchCertificateBytes.js +57 -0
  153. package/lib/server/handlers/index.d.ts +4 -0
  154. package/lib/server/handlers/index.js +25 -0
  155. package/lib/server/handlers/init.d.ts +2 -0
  156. package/lib/server/handlers/init.js +33 -0
  157. package/lib/server/handlers/toprf.d.ts +2 -0
  158. package/lib/server/handlers/toprf.js +19 -0
  159. package/lib/server/index.d.ts +4 -0
  160. package/lib/server/index.js +4 -0
  161. package/lib/server/socket.d.ts +13 -0
  162. package/lib/server/socket.js +112 -0
  163. package/lib/server/tunnels/make-tcp-tunnel.d.ts +22 -0
  164. package/lib/server/tunnels/make-tcp-tunnel.js +202 -0
  165. package/lib/server/utils/apm.d.ts +11 -0
  166. package/lib/server/utils/apm.js +29 -0
  167. package/lib/server/utils/assert-valid-claim-request.d.ts +31 -0
  168. package/lib/server/utils/assert-valid-claim-request.js +354 -0
  169. package/lib/server/utils/config-env.d.ts +1 -0
  170. package/lib/server/utils/config-env.js +4 -0
  171. package/lib/server/utils/dns.d.ts +1 -0
  172. package/lib/server/utils/dns.js +24 -0
  173. package/lib/server/utils/gcp-attestation.d.ts +17 -0
  174. package/lib/server/utils/gcp-attestation.js +237 -0
  175. package/lib/server/utils/generics.d.ts +22 -0
  176. package/lib/server/utils/generics.js +45 -0
  177. package/lib/server/utils/iso.d.ts +1 -0
  178. package/lib/server/utils/iso.js +259 -0
  179. package/lib/server/utils/keep-alive.d.ts +7 -0
  180. package/lib/server/utils/keep-alive.js +38 -0
  181. package/lib/server/utils/nitro-attestation.d.ts +33 -0
  182. package/lib/server/utils/nitro-attestation.js +249 -0
  183. package/lib/server/utils/oprf-raw.d.ts +21 -0
  184. package/lib/server/utils/oprf-raw.js +61 -0
  185. package/lib/server/utils/process-handshake.d.ts +13 -0
  186. package/lib/server/utils/process-handshake.js +233 -0
  187. package/lib/server/utils/proxy-session.d.ts +1 -0
  188. package/lib/server/utils/proxy-session.js +6 -0
  189. package/lib/server/utils/tee-oprf-mpc-verification.d.ts +16 -0
  190. package/lib/server/utils/tee-oprf-mpc-verification.js +86 -0
  191. package/lib/server/utils/tee-oprf-verification.d.ts +24 -0
  192. package/lib/server/utils/tee-oprf-verification.js +151 -0
  193. package/lib/server/utils/tee-transcript-reconstruction.d.ts +24 -0
  194. package/lib/server/utils/tee-transcript-reconstruction.js +140 -0
  195. package/lib/server/utils/tee-verification.d.ts +28 -0
  196. package/lib/server/utils/tee-verification.js +358 -0
  197. package/lib/server/utils/validation.d.ts +2 -0
  198. package/lib/server/utils/validation.js +45 -0
  199. package/lib/types/bgp.d.ts +11 -0
  200. package/lib/types/bgp.js +0 -0
  201. package/lib/types/claims.d.ts +70 -0
  202. package/lib/types/claims.js +0 -0
  203. package/lib/types/client.d.ts +163 -0
  204. package/lib/types/client.js +0 -0
  205. package/lib/types/general.d.ts +76 -0
  206. package/lib/types/general.js +0 -0
  207. package/lib/types/handlers.d.ts +10 -0
  208. package/lib/types/handlers.js +0 -0
  209. package/lib/types/index.d.ts +10 -0
  210. package/lib/types/index.js +10 -0
  211. package/lib/types/providers.d.ts +161 -0
  212. package/lib/types/providers.gen.d.ts +443 -0
  213. package/lib/types/providers.gen.js +16 -0
  214. package/lib/types/providers.js +0 -0
  215. package/lib/types/rpc.d.ts +35 -0
  216. package/lib/types/rpc.js +0 -0
  217. package/lib/types/signatures.d.ts +28 -0
  218. package/lib/types/signatures.js +0 -0
  219. package/lib/types/tunnel.d.ts +18 -0
  220. package/lib/types/tunnel.js +0 -0
  221. package/lib/types/zk.d.ts +38 -0
  222. package/lib/types/zk.js +0 -0
  223. package/lib/utils/auth.d.ts +8 -0
  224. package/lib/utils/auth.js +71 -0
  225. package/lib/utils/b64-json.d.ts +2 -0
  226. package/lib/utils/b64-json.js +17 -0
  227. package/lib/utils/bgp-listener.d.ts +7 -0
  228. package/lib/utils/bgp-listener.js +123 -0
  229. package/lib/utils/claims.d.ts +33 -0
  230. package/lib/utils/claims.js +89 -0
  231. package/lib/utils/env.d.ts +3 -0
  232. package/lib/utils/env.js +19 -0
  233. package/lib/utils/error.d.ts +26 -0
  234. package/lib/utils/error.js +54 -0
  235. package/lib/utils/generics.d.ts +114 -0
  236. package/lib/utils/generics.js +268 -0
  237. package/lib/utils/http-parser.d.ts +59 -0
  238. package/lib/utils/http-parser.js +201 -0
  239. package/lib/utils/index.d.ts +13 -0
  240. package/lib/utils/index.js +13 -0
  241. package/lib/utils/logger.d.ts +13 -0
  242. package/lib/utils/logger.js +82 -0
  243. package/lib/utils/prepare-packets.d.ts +16 -0
  244. package/lib/utils/prepare-packets.js +69 -0
  245. package/lib/utils/redactions.d.ts +73 -0
  246. package/lib/utils/redactions.js +135 -0
  247. package/lib/utils/retries.d.ts +12 -0
  248. package/lib/utils/retries.js +26 -0
  249. package/lib/utils/signatures/eth.d.ts +2 -0
  250. package/lib/utils/signatures/eth.js +31 -0
  251. package/lib/utils/signatures/index.d.ts +5 -0
  252. package/lib/utils/signatures/index.js +12 -0
  253. package/lib/utils/socket-base.d.ts +23 -0
  254. package/lib/utils/socket-base.js +96 -0
  255. package/lib/utils/tls.d.ts +2 -0
  256. package/lib/utils/tls.js +58 -0
  257. package/lib/utils/ws.d.ts +7 -0
  258. package/lib/utils/ws.js +22 -0
  259. package/lib/utils/zk.d.ts +71 -0
  260. package/lib/utils/zk.js +625 -0
  261. package/package.json +2 -2
@@ -0,0 +1,77 @@
1
+ import '#src/providers/http/patch-parse5-tree.ts';
2
+ import RE2 from 're2';
3
+ import type { ArraySlice, CompleteTLSPacket, ProviderParams, Transcript } from '#src/types/index.ts';
4
+ import type { HttpRequest, HttpResponse } from '#src/utils/index.ts';
5
+ export type JSONIndex = {
6
+ start: number;
7
+ end: number;
8
+ };
9
+ type HTTPProviderParams = ProviderParams<'http'>;
10
+ /**
11
+ * Returns only first extracted element
12
+ * @param html
13
+ * @param xpathExpression
14
+ * @param contentsOnly
15
+ */
16
+ export declare function extractHTMLElement(html: string, xpathExpression: string, contentsOnly: boolean): string;
17
+ /**
18
+ * Returns all extracted elements
19
+ * @param html
20
+ * @param xpathExpression
21
+ * @param contentsOnly
22
+ */
23
+ export declare function extractHTMLElements(html: string, xpathExpression: string, contentsOnly: boolean): string[];
24
+ /**
25
+ * returns a single index of extracted element
26
+ * @param html
27
+ * @param xpathExpression
28
+ * @param contentsOnly
29
+ */
30
+ export declare function extractHTMLElementIndex(html: string, xpathExpression: string, contentsOnly: boolean): {
31
+ start: number;
32
+ end: number;
33
+ };
34
+ /**
35
+ * Returns indexes of all extracted elements
36
+ * @param html
37
+ * @param xpathExpression
38
+ * @param contentsOnly indices of the start and end of the element's contents only,
39
+ * not the whole tag
40
+ */
41
+ export declare function extractHTMLElementsIndexes(html: string, xpathExpression: string, contentsOnly: boolean): {
42
+ start: number;
43
+ end: number;
44
+ }[];
45
+ export declare function extractJSONValueIndex(json: string, jsonPath: string): {
46
+ start: number;
47
+ end: number;
48
+ };
49
+ export declare function extractJSONValueIndexes(json: string, jsonPath: string): {
50
+ start: number;
51
+ end: number;
52
+ }[];
53
+ export declare function buildHeaders(input: HTTPProviderParams['headers']): string[];
54
+ /**
55
+ * Converts position in HTTP response body to an absolute position in TLS transcript considering chunked encoding
56
+ * @param pos
57
+ * @param bodyStartIdx
58
+ * @param chunks
59
+ */
60
+ export declare function convertResponsePosToAbsolutePos(pos: number, bodyStartIdx: number, chunks?: ArraySlice[]): number;
61
+ /**
62
+ * If this reveal spans the boundary of two chunks, we'll
63
+ *
64
+ */
65
+ export declare function getRedactionsForChunkHeaders(from: number, to: number, chunks?: ArraySlice[]): ArraySlice[];
66
+ export declare function parseHttpResponse(buff: Uint8Array): HttpResponse;
67
+ export declare function makeRegex(str: string): RE2;
68
+ /**
69
+ * Try to match strings that contain templates like {{param}}
70
+ * against redacted string that has *** instead of that param
71
+ */
72
+ export declare function matchRedactedStrings(templateString: Uint8Array, redactedString?: Uint8Array): boolean;
73
+ export declare function generateRequstAndResponseFromTranscript(transcript: Transcript<CompleteTLSPacket>, tlsVersion: string): {
74
+ req: HttpRequest;
75
+ res: HttpResponse;
76
+ };
77
+ export {};
@@ -0,0 +1,283 @@
1
+ import "../../providers/http/patch-parse5-tree.js";
2
+ import { concatenateUint8Arrays } from "@reclaimprotocol/tls";
3
+ import {
4
+ ArrayExpression,
5
+ ExpressionStatement,
6
+ ObjectExpression,
7
+ parseScript,
8
+ Property,
9
+ Syntax
10
+ } from "esprima-next";
11
+ import { JSONPath } from "jsonpath-plus";
12
+ import { parse } from "parse5";
13
+ import { adapter as htmlAdapter } from "parse5-htmlparser2-tree-adapter";
14
+ import RE2 from "re2";
15
+ import xpath from "xpath";
16
+ import { getHttpRequestDataFromTranscript, isApplicationData, makeHttpResponseParser, REDACTION_CHAR_CODE } from "../../utils/index.js";
17
+ function extractHTMLElement(html, xpathExpression, contentsOnly) {
18
+ const { start, end } = extractHTMLElementIndex(html, xpathExpression, contentsOnly);
19
+ return html.slice(start, end);
20
+ }
21
+ function extractHTMLElements(html, xpathExpression, contentsOnly) {
22
+ const indexes = extractHTMLElementsIndexes(html, xpathExpression, contentsOnly);
23
+ const res = [];
24
+ for (const { start, end } of indexes) {
25
+ res.push(html.slice(start, end));
26
+ }
27
+ return res;
28
+ }
29
+ function extractHTMLElementIndex(html, xpathExpression, contentsOnly) {
30
+ return extractHTMLElementsIndexes(html, xpathExpression, contentsOnly)[0];
31
+ }
32
+ function extractHTMLElementsIndexes(html, xpathExpression, contentsOnly) {
33
+ return extractHTMLElementIndexesParse5(html, xpathExpression, contentsOnly);
34
+ }
35
+ function extractHTMLElementIndexesParse5(html, xpathExpression, contentsOnly) {
36
+ const domLight = parse(
37
+ html,
38
+ { treeAdapter: htmlAdapter, sourceCodeLocationInfo: true }
39
+ );
40
+ domLight["name"] = "root";
41
+ const parsedPath = xpath.parse(xpathExpression);
42
+ const nodes = parsedPath.select({
43
+ node: domLight,
44
+ allowAnyNamespaceForNoPrefix: true
45
+ });
46
+ if (!nodes.length) {
47
+ throw new Error(`Failed to find XPath: "${xpathExpression}"`);
48
+ }
49
+ return nodes.map((node) => getNodeRange(node, contentsOnly));
50
+ }
51
+ function getNodeRange(node, contentsOnly) {
52
+ if (!contentsOnly) {
53
+ return { start: node.startIndex, end: node.endIndex };
54
+ }
55
+ if (!("firstChild" in node) || !node.firstChild) {
56
+ throw new Error(`Node "${node["name"]}" has no children`);
57
+ }
58
+ return {
59
+ start: node.firstChild.startIndex,
60
+ end: node.lastChild.endIndex
61
+ };
62
+ }
63
+ function extractJSONValueIndex(json, jsonPath) {
64
+ return extractJSONValueIndexes(json, jsonPath)[0];
65
+ }
66
+ function extractJSONValueIndexes(json, jsonPath) {
67
+ const pointers = JSONPath({
68
+ path: jsonPath,
69
+ json: JSON.parse(json),
70
+ wrap: false,
71
+ resultType: "pointer",
72
+ eval: "safe",
73
+ // @ts-ignore
74
+ ignoreEvalErrors: true
75
+ });
76
+ if (!pointers) {
77
+ throw new Error("jsonPath not found");
78
+ }
79
+ const tree = parseScript("(" + json + ")", { range: true });
80
+ if (tree.body[0] instanceof ExpressionStatement && (tree.body[0].expression instanceof ObjectExpression || tree.body[0].expression instanceof ArrayExpression)) {
81
+ const traversePointers = Array.isArray(pointers) ? pointers : [pointers];
82
+ const res = [];
83
+ for (const pointer of traversePointers) {
84
+ const index = traverse(tree.body[0].expression, "", [pointer]);
85
+ if (index) {
86
+ res.push({
87
+ start: index.start - 1,
88
+ //account for '('
89
+ end: index.end - 1
90
+ });
91
+ }
92
+ }
93
+ return res;
94
+ }
95
+ throw new Error("jsonPath not found");
96
+ }
97
+ function traverse(o, path, pointers) {
98
+ if (o instanceof ObjectExpression) {
99
+ for (const p of o.properties) {
100
+ if (!(p instanceof Property)) {
101
+ continue;
102
+ }
103
+ const localPath = p.key.type === Syntax.Literal ? path + "/" + p.key.value : path;
104
+ if (pointers.includes(localPath) && "range" in p && Array.isArray(p.range)) {
105
+ return {
106
+ start: p.range[0],
107
+ end: p.range[1]
108
+ };
109
+ }
110
+ if (p.value instanceof ObjectExpression || p.value instanceof ArrayExpression) {
111
+ const res = traverse(p.value, localPath, pointers);
112
+ if (res) {
113
+ return res;
114
+ }
115
+ }
116
+ }
117
+ }
118
+ if (o instanceof ArrayExpression) {
119
+ for (let i = 0; i < o.elements.length; i++) {
120
+ const element = o.elements[i];
121
+ if (!element) {
122
+ continue;
123
+ }
124
+ const localPath = path + "/" + i;
125
+ if (pointers.includes(localPath) && "range" in element && Array.isArray(element.range)) {
126
+ return {
127
+ start: element.range[0],
128
+ end: element.range[1]
129
+ };
130
+ }
131
+ if (element instanceof ObjectExpression) {
132
+ const res = traverse(element, localPath, pointers);
133
+ if (res) {
134
+ return res;
135
+ }
136
+ }
137
+ if (element instanceof ArrayExpression) {
138
+ const res = traverse(element, localPath, pointers);
139
+ if (res) {
140
+ return res;
141
+ }
142
+ }
143
+ }
144
+ }
145
+ return null;
146
+ }
147
+ function buildHeaders(input) {
148
+ const headers = [];
149
+ for (const [key, value] of Object.entries(input || {})) {
150
+ headers.push(`${key}: ${value}`);
151
+ }
152
+ return headers;
153
+ }
154
+ function convertResponsePosToAbsolutePos(pos, bodyStartIdx, chunks) {
155
+ if (chunks?.length) {
156
+ let chunkBodyStart = 0;
157
+ for (const chunk of chunks) {
158
+ const chunkSize = chunk.toIndex - chunk.fromIndex;
159
+ if (pos >= chunkBodyStart && pos <= chunkBodyStart + chunkSize) {
160
+ return pos - chunkBodyStart + chunk.fromIndex;
161
+ }
162
+ chunkBodyStart += chunkSize;
163
+ }
164
+ throw new Error("position out of range");
165
+ }
166
+ return bodyStartIdx + pos;
167
+ }
168
+ function getRedactionsForChunkHeaders(from, to, chunks) {
169
+ const res = [];
170
+ if (!chunks?.length) {
171
+ return res;
172
+ }
173
+ for (let i = 1; i < chunks?.length; i++) {
174
+ const chunk = chunks[i];
175
+ if (chunk.fromIndex > from && chunk.fromIndex < to) {
176
+ res.push({
177
+ fromIndex: chunks[i - 1].toIndex,
178
+ toIndex: chunk.fromIndex
179
+ });
180
+ }
181
+ }
182
+ return res;
183
+ }
184
+ function parseHttpResponse(buff) {
185
+ const parser = makeHttpResponseParser();
186
+ parser.onChunk(buff);
187
+ parser.streamEnded();
188
+ return parser.res;
189
+ }
190
+ function makeRegex(str) {
191
+ return RE2(str, "sgiu");
192
+ }
193
+ const TEMPLATE_START_CHARCODE = "{".charCodeAt(0);
194
+ const TEMPLATE_END_CHARCODE = "}".charCodeAt(0);
195
+ function matchRedactedStrings(templateString, redactedString) {
196
+ if (templateString.length === 0 && redactedString?.length === 0) {
197
+ return true;
198
+ }
199
+ if (!redactedString) {
200
+ return false;
201
+ }
202
+ let ts = -1;
203
+ let rs = -1;
204
+ while (ts < templateString.length && rs < redactedString.length) {
205
+ let ct = getTChar();
206
+ let cr = getRChar();
207
+ if (ct !== cr) {
208
+ if (ct === TEMPLATE_START_CHARCODE && cr === REDACTION_CHAR_CODE) {
209
+ if (getTChar() !== TEMPLATE_START_CHARCODE) {
210
+ return false;
211
+ }
212
+ while ((ct = getTChar()) !== TEMPLATE_END_CHARCODE && ct !== -1) {
213
+ }
214
+ while ((ct = getTChar()) !== TEMPLATE_END_CHARCODE && ct !== -1) {
215
+ }
216
+ if (ct === -1) {
217
+ return false;
218
+ }
219
+ while ((cr = getRChar()) === REDACTION_CHAR_CODE && cr !== -1) {
220
+ }
221
+ if (cr === -1) {
222
+ return getTChar() === -1;
223
+ }
224
+ rs--;
225
+ } else {
226
+ return false;
227
+ }
228
+ }
229
+ }
230
+ function getTChar() {
231
+ ts++;
232
+ if (ts < templateString.length) {
233
+ return templateString[ts];
234
+ } else {
235
+ return -1;
236
+ }
237
+ }
238
+ function getRChar() {
239
+ if (!redactedString) {
240
+ return -1;
241
+ }
242
+ rs++;
243
+ if (rs < redactedString.length) {
244
+ return redactedString[rs];
245
+ } else {
246
+ return -1;
247
+ }
248
+ }
249
+ return ts === templateString.length && rs === redactedString.length;
250
+ }
251
+ function generateRequstAndResponseFromTranscript(transcript, tlsVersion) {
252
+ const allPackets = transcript;
253
+ const packets = [];
254
+ for (const b of allPackets) {
255
+ if (b.message.type !== "ciphertext" || !isApplicationData(b.message, tlsVersion)) {
256
+ continue;
257
+ }
258
+ const plaintext = tlsVersion === "TLS1_3" ? b.message.plaintext.slice(0, -1) : b.message.plaintext;
259
+ packets.push({
260
+ message: plaintext,
261
+ sender: b.sender
262
+ });
263
+ }
264
+ const req = getHttpRequestDataFromTranscript(packets);
265
+ const responsePackets = concatenateUint8Arrays(packets.filter((p) => p.sender === "server").map((p) => p.message).filter((b) => !b.every((b2) => b2 === REDACTION_CHAR_CODE)));
266
+ const res = parseHttpResponse(responsePackets);
267
+ return { req, res };
268
+ }
269
+ export {
270
+ buildHeaders,
271
+ convertResponsePosToAbsolutePos,
272
+ extractHTMLElement,
273
+ extractHTMLElementIndex,
274
+ extractHTMLElements,
275
+ extractHTMLElementsIndexes,
276
+ extractJSONValueIndex,
277
+ extractJSONValueIndexes,
278
+ generateRequstAndResponseFromTranscript,
279
+ getRedactionsForChunkHeaders,
280
+ makeRegex,
281
+ matchRedactedStrings,
282
+ parseHttpResponse
283
+ };
@@ -0,0 +1,4 @@
1
+ import type { Provider, ProviderName } from '#src/types/index.ts';
2
+ export declare const providers: {
3
+ [T in ProviderName]: Provider<T>;
4
+ };
@@ -0,0 +1,7 @@
1
+ import http from "../providers/http/index.js";
2
+ const providers = {
3
+ http
4
+ };
5
+ export {
6
+ providers
7
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ import 'src/server/utils/config-env';
@@ -0,0 +1,28 @@
1
+ import "src/server/utils/config-env";
2
+ import { getContracts } from "../avs/utils/contracts.js";
3
+ async function main() {
4
+ const { wallet, contract } = getContracts();
5
+ const meta = await contract.taskCreationMetadata();
6
+ console.log(
7
+ "Metadata parameters:",
8
+ `maxTaskCreationDelayS: ${meta.maxTaskCreationDelayS}`,
9
+ `minSignaturesPerTask: ${meta.minSignaturesPerTask}`,
10
+ `maxTaskLifetimeS: ${meta.maxTaskLifetimeS}`
11
+ );
12
+ console.log(`Checking registration for operator ${wallet.address}`);
13
+ const operatorAddr = wallet.address;
14
+ const metadata = await contract.getMetadataForOperator(operatorAddr).catch((err) => {
15
+ if (err.message.includes("Operator not found")) {
16
+ return;
17
+ }
18
+ throw err;
19
+ });
20
+ if (!metadata) {
21
+ console.log("Operator not registered");
22
+ const isWhitelisted = await contract.isOperatorWhitelisted(operatorAddr);
23
+ console.log(`Is whitelisted: ${isWhitelisted}`);
24
+ return;
25
+ }
26
+ console.log("Operator registered, URL:", metadata.url);
27
+ }
28
+ void main();
@@ -0,0 +1 @@
1
+ export declare const webcrypto: Crypto;
@@ -0,0 +1,4 @@
1
+ const webcrypto = globalThis.crypto;
2
+ export {
3
+ webcrypto
4
+ };
@@ -0,0 +1,3 @@
1
+ declare const _default: {};
2
+ export default _default;
3
+ export {};
@@ -0,0 +1,4 @@
1
+ var empty_default = {};
2
+ export {
3
+ empty_default as default
4
+ };
@@ -0,0 +1 @@
1
+ export default function regularRegex(pattern: string, flags?: string): RegExp;
@@ -0,0 +1,7 @@
1
+ function regularRegex(pattern, flags) {
2
+ flags = flags?.replace("u", "");
3
+ return new RegExp(pattern, flags);
4
+ }
5
+ export {
6
+ regularRegex as default
7
+ };
@@ -0,0 +1 @@
1
+ export declare const wtns: any, groth16: any, zkey: any;
@@ -0,0 +1,10 @@
1
+ const {
2
+ wtns,
3
+ groth16,
4
+ zkey
5
+ } = window["snarkjs"] || {};
6
+ export {
7
+ groth16,
8
+ wtns,
9
+ zkey
10
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Browser fallback for stwo - loads from window.s2circuits
3
+ * The s2circuits.js script must be loaded before this runs
4
+ */
5
+ import type { MakeZKOperatorOpts, ZKOperator } from '@reclaimprotocol/zk-symmetric-crypto';
6
+ export declare function makeStwoZkOperator({ algorithm, fetcher, }: MakeZKOperatorOpts<object>): ZKOperator;
@@ -0,0 +1,159 @@
1
+ const Base64 = {
2
+ fromUint8Array(arr) {
3
+ let binary = "";
4
+ for (const element of arr) {
5
+ binary += String.fromCharCode(element);
6
+ }
7
+ return btoa(binary);
8
+ },
9
+ toUint8Array(str) {
10
+ const binary = atob(str);
11
+ const arr = new Uint8Array(binary.length);
12
+ for (let i = 0; i < binary.length; i++) {
13
+ arr[i] = binary.charCodeAt(i);
14
+ }
15
+ return arr;
16
+ }
17
+ };
18
+ function getS2Circuits() {
19
+ const s2 = window["s2circuits"];
20
+ if (!s2) {
21
+ throw new Error("s2circuits not loaded. Make sure s2circuits.js is loaded before using stwo.");
22
+ }
23
+ return s2;
24
+ }
25
+ function assertU32Counter(counter) {
26
+ if (!Number.isInteger(counter) || counter < 0 || counter > 4294967295) {
27
+ throw new RangeError("counter must be a uint32 integer (0 to 4294967295)");
28
+ }
29
+ }
30
+ let wasmInitialized = false;
31
+ let initPromise;
32
+ async function ensureWasmInitialized(fetcher, logger) {
33
+ if (wasmInitialized) {
34
+ return;
35
+ }
36
+ if (initPromise) {
37
+ return initPromise;
38
+ }
39
+ initPromise = (async () => {
40
+ try {
41
+ const s2 = getS2Circuits();
42
+ const wasmBytes = await fetcher.fetch("stwo", "s2circuits_bg.wasm", logger);
43
+ s2.initSync({ module: wasmBytes });
44
+ wasmInitialized = true;
45
+ } catch (err) {
46
+ initPromise = void 0;
47
+ throw err;
48
+ }
49
+ })();
50
+ return initPromise;
51
+ }
52
+ function serializeWitness(algorithm, input) {
53
+ if (!input.noncesAndCounters?.length) {
54
+ throw new Error("noncesAndCounters must be a non-empty array");
55
+ }
56
+ const { noncesAndCounters: [{ nonce, counter }] } = input;
57
+ assertU32Counter(counter);
58
+ const data = {
59
+ algorithm,
60
+ key: Base64.fromUint8Array(input.key),
61
+ nonce: Base64.fromUint8Array(nonce),
62
+ counter,
63
+ plaintext: Base64.fromUint8Array(input.out),
64
+ // out = decrypted plaintext
65
+ ciphertext: Base64.fromUint8Array(input.in)
66
+ // in = encrypted ciphertext
67
+ };
68
+ return new TextEncoder().encode(JSON.stringify(data));
69
+ }
70
+ function deserializeWitness(witness) {
71
+ const json = new TextDecoder().decode(witness);
72
+ return JSON.parse(json);
73
+ }
74
+ function makeStwoZkOperator({
75
+ algorithm,
76
+ fetcher
77
+ }) {
78
+ return {
79
+ generateWitness(input) {
80
+ return serializeWitness(algorithm, input);
81
+ },
82
+ async groth16Prove(witness, logger) {
83
+ await ensureWasmInitialized(fetcher, logger);
84
+ const s2 = getS2Circuits();
85
+ const data = deserializeWitness(witness);
86
+ const key = Base64.toUint8Array(data.key);
87
+ const nonce = Base64.toUint8Array(data.nonce);
88
+ const plaintext = Base64.toUint8Array(data.plaintext);
89
+ const ciphertext = Base64.toUint8Array(data.ciphertext);
90
+ let resultJson;
91
+ switch (data.algorithm) {
92
+ case "chacha20":
93
+ resultJson = s2.generate_chacha20_proof(key, nonce, data.counter, plaintext, ciphertext);
94
+ break;
95
+ case "aes-128-ctr":
96
+ resultJson = s2.generate_aes128_ctr_proof(key, nonce, data.counter, plaintext, ciphertext);
97
+ break;
98
+ case "aes-256-ctr":
99
+ resultJson = s2.generate_aes256_ctr_proof(key, nonce, data.counter, plaintext, ciphertext);
100
+ break;
101
+ default:
102
+ throw new Error(`Unsupported algorithm: ${data.algorithm}`);
103
+ }
104
+ const result = JSON.parse(resultJson);
105
+ if (result.error) {
106
+ throw new Error(`Stwo proof generation failed: ${result.error}`);
107
+ }
108
+ if (!result.proof) {
109
+ throw new Error("Stwo proof generation failed: no proof returned");
110
+ }
111
+ return { proof: result.proof };
112
+ },
113
+ async groth16Verify(publicSignals, proof, logger) {
114
+ await ensureWasmInitialized(fetcher, logger);
115
+ const s2 = getS2Circuits();
116
+ const expectedNonce = publicSignals.noncesAndCounters[0]?.nonce;
117
+ const expectedCounter = publicSignals.noncesAndCounters[0]?.counter;
118
+ const expectedCiphertext = publicSignals.in;
119
+ const expectedPlaintext = publicSignals.out;
120
+ if (!expectedNonce || expectedCounter === void 0) {
121
+ logger?.warn("Invalid publicSignals: missing nonce or counter");
122
+ return false;
123
+ }
124
+ assertU32Counter(expectedCounter);
125
+ const proofStr = typeof proof === "string" ? proof : new TextDecoder().decode(proof);
126
+ let resultJson;
127
+ if (algorithm === "chacha20") {
128
+ resultJson = s2.verify_chacha20_proof(
129
+ proofStr,
130
+ expectedNonce,
131
+ expectedCounter,
132
+ expectedPlaintext,
133
+ expectedCiphertext
134
+ );
135
+ } else {
136
+ resultJson = s2.verify_aes_ctr_proof(
137
+ proofStr,
138
+ expectedNonce,
139
+ expectedCounter,
140
+ expectedPlaintext,
141
+ expectedCiphertext
142
+ );
143
+ }
144
+ const result = JSON.parse(resultJson);
145
+ if (result.error) {
146
+ logger?.warn({ error: result.error }, "Stwo STARK verification failed");
147
+ return false;
148
+ }
149
+ return result.valid === true;
150
+ },
151
+ release() {
152
+ wasmInitialized = false;
153
+ initPromise = void 0;
154
+ }
155
+ };
156
+ }
157
+ export {
158
+ makeStwoZkOperator
159
+ };
@@ -0,0 +1,5 @@
1
+ export declare function generateTsFromYamlSchema(name: string, type: 'parameters' | 'secret-parameters'): Promise<{
2
+ ts: string;
3
+ schemaTitle: any;
4
+ jsonTitle: string;
5
+ }>;