@reclaimprotocol/attestor-core 5.0.1-beta.13 → 5.0.1-beta.16

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 (134) hide show
  1. package/lib/external-rpc/index.js +17321 -3
  2. package/lib/index.d.ts +1 -0
  3. package/lib/index.js +15391 -11
  4. package/lib/scripts/build-browser-debug.d.ts +1 -0
  5. package/package.json +1 -1
  6. package/lib/avs/abis/avsDirectoryABI.js +0 -343
  7. package/lib/avs/abis/delegationABI.js +0 -4
  8. package/lib/avs/abis/registryABI.js +0 -728
  9. package/lib/avs/client/create-claim-on-avs.js +0 -168
  10. package/lib/avs/config.js +0 -26
  11. package/lib/avs/contracts/ReclaimServiceManager.js +0 -0
  12. package/lib/avs/contracts/common.js +0 -0
  13. package/lib/avs/contracts/factories/ReclaimServiceManager__factory.js +0 -1183
  14. package/lib/avs/contracts/factories/index.js +0 -4
  15. package/lib/avs/contracts/index.js +0 -6
  16. package/lib/avs/types/index.js +0 -0
  17. package/lib/avs/utils/contracts.js +0 -53
  18. package/lib/avs/utils/register.js +0 -74
  19. package/lib/avs/utils/tasks.js +0 -48
  20. package/lib/client/create-claim.js +0 -461
  21. package/lib/client/index.js +0 -3
  22. package/lib/client/tunnels/make-rpc-tcp-tunnel.js +0 -53
  23. package/lib/client/tunnels/make-rpc-tls-tunnel.js +0 -127
  24. package/lib/client/utils/attestor-pool.js +0 -24
  25. package/lib/client/utils/client-socket.js +0 -120
  26. package/lib/client/utils/message-handler.js +0 -97
  27. package/lib/config/index.js +0 -62
  28. package/lib/external-rpc/benchmark.js +0 -82
  29. package/lib/external-rpc/event-bus.js +0 -17
  30. package/lib/external-rpc/handle-incoming-msg.js +0 -241
  31. package/lib/external-rpc/jsc-polyfills/1.js +0 -80
  32. package/lib/external-rpc/jsc-polyfills/2.js +0 -15
  33. package/lib/external-rpc/jsc-polyfills/event.js +0 -19
  34. package/lib/external-rpc/jsc-polyfills/index.js +0 -2
  35. package/lib/external-rpc/jsc-polyfills/ws.js +0 -83
  36. package/lib/external-rpc/setup-browser.js +0 -33
  37. package/lib/external-rpc/setup-jsc.js +0 -22
  38. package/lib/external-rpc/types.js +0 -0
  39. package/lib/external-rpc/utils.js +0 -100
  40. package/lib/external-rpc/zk.js +0 -58
  41. package/lib/mechain/abis/governanceABI.js +0 -461
  42. package/lib/mechain/abis/taskABI.js +0 -512
  43. package/lib/mechain/client/create-claim-on-mechain.js +0 -33
  44. package/lib/mechain/client/index.js +0 -1
  45. package/lib/mechain/constants/index.js +0 -8
  46. package/lib/mechain/index.js +0 -2
  47. package/lib/mechain/types/index.js +0 -0
  48. package/lib/proto/api.js +0 -4250
  49. package/lib/proto/tee-bundle.js +0 -1296
  50. package/lib/providers/http/index.js +0 -640
  51. package/lib/providers/http/patch-parse5-tree.js +0 -34
  52. package/lib/providers/http/utils.js +0 -283
  53. package/lib/providers/index.js +0 -7
  54. package/lib/scripts/build-browser.js +0 -38
  55. package/lib/scripts/build-jsc.js +0 -47
  56. package/lib/scripts/build-lib.js +0 -47
  57. package/lib/scripts/check-avs-registration.js +0 -28
  58. package/lib/scripts/fallbacks/crypto.js +0 -4
  59. package/lib/scripts/fallbacks/empty.js +0 -4
  60. package/lib/scripts/fallbacks/re2.js +0 -7
  61. package/lib/scripts/fallbacks/snarkjs.js +0 -10
  62. package/lib/scripts/fallbacks/stwo.js +0 -159
  63. package/lib/scripts/generate-provider-types.js +0 -101
  64. package/lib/scripts/generate-receipt.js +0 -101
  65. package/lib/scripts/generate-toprf-keys.js +0 -24
  66. package/lib/scripts/jsc-cli-rpc.js +0 -35
  67. package/lib/scripts/register-avs-operator.js +0 -3
  68. package/lib/scripts/start-server.js +0 -11
  69. package/lib/scripts/update-avs-metadata.js +0 -20
  70. package/lib/scripts/utils.js +0 -10
  71. package/lib/scripts/whitelist-operator.js +0 -16
  72. package/lib/server/create-server.js +0 -105
  73. package/lib/server/handlers/claimTeeBundle.js +0 -232
  74. package/lib/server/handlers/claimTunnel.js +0 -80
  75. package/lib/server/handlers/completeClaimOnChain.js +0 -29
  76. package/lib/server/handlers/createClaimOnChain.js +0 -32
  77. package/lib/server/handlers/createTaskOnMechain.js +0 -57
  78. package/lib/server/handlers/createTunnel.js +0 -98
  79. package/lib/server/handlers/disconnectTunnel.js +0 -8
  80. package/lib/server/handlers/fetchCertificateBytes.js +0 -57
  81. package/lib/server/handlers/index.js +0 -25
  82. package/lib/server/handlers/init.js +0 -33
  83. package/lib/server/handlers/toprf.js +0 -19
  84. package/lib/server/index.js +0 -4
  85. package/lib/server/socket.js +0 -112
  86. package/lib/server/tunnels/make-tcp-tunnel.js +0 -202
  87. package/lib/server/utils/apm.js +0 -29
  88. package/lib/server/utils/assert-valid-claim-request.js +0 -354
  89. package/lib/server/utils/config-env.js +0 -4
  90. package/lib/server/utils/dns.js +0 -24
  91. package/lib/server/utils/gcp-attestation.js +0 -237
  92. package/lib/server/utils/generics.js +0 -45
  93. package/lib/server/utils/iso.js +0 -259
  94. package/lib/server/utils/keep-alive.js +0 -38
  95. package/lib/server/utils/nitro-attestation.js +0 -249
  96. package/lib/server/utils/oprf-raw.js +0 -61
  97. package/lib/server/utils/process-handshake.js +0 -233
  98. package/lib/server/utils/proxy-session.js +0 -6
  99. package/lib/server/utils/tee-oprf-mpc-verification.js +0 -86
  100. package/lib/server/utils/tee-oprf-verification.js +0 -151
  101. package/lib/server/utils/tee-transcript-reconstruction.js +0 -140
  102. package/lib/server/utils/tee-verification.js +0 -358
  103. package/lib/server/utils/validation.js +0 -45
  104. package/lib/types/bgp.js +0 -0
  105. package/lib/types/claims.js +0 -0
  106. package/lib/types/client.js +0 -0
  107. package/lib/types/general.js +0 -0
  108. package/lib/types/handlers.js +0 -0
  109. package/lib/types/index.js +0 -10
  110. package/lib/types/providers.gen.js +0 -16
  111. package/lib/types/providers.js +0 -0
  112. package/lib/types/rpc.js +0 -0
  113. package/lib/types/signatures.js +0 -0
  114. package/lib/types/tunnel.js +0 -0
  115. package/lib/types/zk.js +0 -0
  116. package/lib/utils/auth.js +0 -71
  117. package/lib/utils/b64-json.js +0 -17
  118. package/lib/utils/bgp-listener.js +0 -123
  119. package/lib/utils/claims.js +0 -89
  120. package/lib/utils/env.js +0 -19
  121. package/lib/utils/error.js +0 -54
  122. package/lib/utils/generics.js +0 -268
  123. package/lib/utils/http-parser.js +0 -201
  124. package/lib/utils/index.js +0 -13
  125. package/lib/utils/logger.js +0 -82
  126. package/lib/utils/prepare-packets.js +0 -69
  127. package/lib/utils/redactions.js +0 -135
  128. package/lib/utils/retries.js +0 -26
  129. package/lib/utils/signatures/eth.js +0 -31
  130. package/lib/utils/signatures/index.js +0 -12
  131. package/lib/utils/socket-base.js +0 -96
  132. package/lib/utils/tls.js +0 -58
  133. package/lib/utils/ws.js +0 -22
  134. package/lib/utils/zk.js +0 -625
@@ -1,283 +0,0 @@
1
- import "#src/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 "#src/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
- };
@@ -1,7 +0,0 @@
1
- import http from "#src/providers/http/index.js";
2
- const providers = {
3
- http
4
- };
5
- export {
6
- providers
7
- };
@@ -1,38 +0,0 @@
1
- import * as esbuild from "esbuild";
2
- const rslt = await esbuild.build({
3
- entryPoints: ["src/external-rpc/setup-browser.js"],
4
- bundle: true,
5
- minify: true,
6
- outfile: "browser/resources/attestor-browser.min.mjs",
7
- platform: "browser",
8
- format: "esm",
9
- tsconfig: "tsconfig.build.json",
10
- legalComments: "none",
11
- metafile: true,
12
- // Enable metafile generation
13
- treeShaking: true,
14
- alias: {
15
- "crypto": "#src/scripts/fallbacks/crypto.js",
16
- "koffi": "#src/scripts/fallbacks/empty.js",
17
- "ip-cidr": "#src/scripts/fallbacks/empty.js",
18
- "snarkjs": "#src/scripts/fallbacks/snarkjs.js",
19
- "re2": "#src/scripts/fallbacks/re2.js",
20
- "@reclaimprotocol/zk-symmetric-crypto/stwo": "#src/scripts/fallbacks/stwo.js"
21
- },
22
- external: [
23
- "dotenv",
24
- "elastic-apm-node",
25
- "https-proxy-agent",
26
- "ip-cidr",
27
- "serve-static",
28
- "re2",
29
- "snarkjs",
30
- "ws",
31
- "fs/promises",
32
- "path"
33
- ]
34
- });
35
- if (process.argv.includes("--analyze")) {
36
- const analysis = await esbuild.analyzeMetafile(rslt.metafile);
37
- console.log(analysis);
38
- }
@@ -1,47 +0,0 @@
1
- import * as esbuild from "esbuild";
2
- const isCliBuild = process.argv.includes("--cli");
3
- if (isCliBuild) {
4
- console.log("Building for CLI...");
5
- }
6
- const rslt = await esbuild.build({
7
- bundle: true,
8
- ...isCliBuild ? {
9
- entryPoints: ["src/scripts/jsc-cli-rpc.js"],
10
- outfile: "out/jsc-cli-rpc.mjs",
11
- format: "esm"
12
- } : {
13
- minify: true,
14
- entryPoints: ["src/external-rpc/setup-jsc.js"],
15
- outfile: "browser/resources/attestor-jsc.min.mjs",
16
- format: "iife"
17
- },
18
- tsconfig: "tsconfig.build.json",
19
- legalComments: "none",
20
- metafile: true,
21
- // Enable metafile generation
22
- treeShaking: true,
23
- alias: {
24
- "crypto": "#src/scripts/fallbacks/crypto.js",
25
- "koffi": "#src/scripts/fallbacks/empty.js",
26
- "ip-cidr": "#src/scripts/fallbacks/empty.js",
27
- "snarkjs": "#src/scripts/fallbacks/empty.js",
28
- "re2": "#src/scripts/fallbacks/re2.js",
29
- "@reclaimprotocol/zk-symmetric-crypto/stwo": "#src/scripts/fallbacks/stwo.js"
30
- },
31
- external: [
32
- "dotenv",
33
- "elastic-apm-node",
34
- "https-proxy-agent",
35
- "ip-cidr",
36
- "serve-static",
37
- "re2",
38
- "snarkjs",
39
- "ws",
40
- "fs/promises",
41
- "path"
42
- ]
43
- });
44
- if (process.argv.includes("--analyze")) {
45
- const analysis = await esbuild.analyzeMetafile(rslt.metafile);
46
- console.log(analysis);
47
- }
@@ -1,47 +0,0 @@
1
- import * as esbuild from "esbuild";
2
- import { readdir, readFile, writeFile } from "node:fs/promises";
3
- import { join } from "node:path";
4
- async function* glob(dir) {
5
- const entries = await readdir(dir, { withFileTypes: true });
6
- for (const entry of entries) {
7
- const path = join(dir, entry.name);
8
- if (entry.isDirectory()) {
9
- yield* glob(path);
10
- } else if (entry.name.endsWith(".js") && !entry.name.endsWith(".d.js")) {
11
- yield path;
12
- }
13
- }
14
- }
15
- const files = [];
16
- for await (const file of glob("src")) {
17
- if (!file.includes("/tests/") && !file.includes(".test.js") && !file.includes("/test.js")) {
18
- files.push(file);
19
- }
20
- }
21
- await esbuild.build({
22
- entryPoints: files,
23
- outdir: "lib",
24
- format: "esm",
25
- platform: "node",
26
- target: "es2022",
27
- outbase: "src",
28
- bundle: false
29
- });
30
- async function fixImports(dir) {
31
- const entries = await readdir(dir, { withFileTypes: true });
32
- for (const entry of entries) {
33
- const path = join(dir, entry.name);
34
- if (entry.isDirectory()) {
35
- await fixImports(path);
36
- } else if (entry.name.endsWith(".js")) {
37
- const content = await readFile(path, "utf-8");
38
- let fixed = content.replace(/^import\s+['"].*\.d\.ts['"];?\s*\n?/gm, "");
39
- fixed = fixed.replace(/\.ts(['"])/g, ".js$1");
40
- if (fixed !== content) {
41
- await writeFile(path, fixed);
42
- }
43
- }
44
- }
45
- }
46
- await fixImports("lib");
47
- console.log(`Built ${files.length} files to lib/`);
@@ -1,28 +0,0 @@
1
- import "src/server/utils/config-env";
2
- import { getContracts } from "#src/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();
@@ -1,4 +0,0 @@
1
- const webcrypto = globalThis.crypto;
2
- export {
3
- webcrypto
4
- };
@@ -1,4 +0,0 @@
1
- var empty_default = {};
2
- export {
3
- empty_default as default
4
- };
@@ -1,7 +0,0 @@
1
- function regularRegex(pattern, flags) {
2
- flags = flags?.replace("u", "");
3
- return new RegExp(pattern, flags);
4
- }
5
- export {
6
- regularRegex as default
7
- };
@@ -1,10 +0,0 @@
1
- const {
2
- wtns,
3
- groth16,
4
- zkey
5
- } = window["snarkjs"] || {};
6
- export {
7
- groth16,
8
- wtns,
9
- zkey
10
- };
@@ -1,159 +0,0 @@
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
- };