@reclaimprotocol/attestor-core 5.0.1-beta.9 → 5.0.2-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (310) hide show
  1. package/browser/resources/attestor-browser.min.mjs +4513 -0
  2. package/lib/client/tunnels/make-rpc-tls-tunnel.d.ts +1 -1
  3. package/lib/external-rpc/index.js +10397 -3
  4. package/lib/index.js +8325 -10
  5. package/lib/server/utils/generics.d.ts +1 -1
  6. package/lib/server/utils/proxy-session.d.ts +1 -1
  7. package/lib/types/general.d.ts +0 -1
  8. package/lib/types/providers.d.ts +3 -2
  9. package/lib/types/signatures.d.ts +1 -2
  10. package/lib/utils/generics.d.ts +1 -6
  11. package/lib/utils/index.d.ts +0 -1
  12. package/package.json +9 -11
  13. package/lib/avs/abis/avsDirectoryABI.js +0 -343
  14. package/lib/avs/abis/delegationABI.js +0 -4
  15. package/lib/avs/abis/registryABI.js +0 -728
  16. package/lib/avs/client/create-claim-on-avs.js +0 -168
  17. package/lib/avs/config.js +0 -26
  18. package/lib/avs/contracts/ReclaimServiceManager.js +0 -0
  19. package/lib/avs/contracts/common.js +0 -0
  20. package/lib/avs/contracts/factories/ReclaimServiceManager__factory.js +0 -1183
  21. package/lib/avs/contracts/factories/index.js +0 -4
  22. package/lib/avs/contracts/index.js +0 -6
  23. package/lib/avs/types/index.js +0 -0
  24. package/lib/avs/utils/contracts.js +0 -53
  25. package/lib/avs/utils/register.js +0 -74
  26. package/lib/avs/utils/tasks.js +0 -48
  27. package/lib/browser/avs/abis/avsDirectoryABI.d.ts +0 -60
  28. package/lib/browser/avs/abis/avsDirectoryABI.js +0 -343
  29. package/lib/browser/avs/abis/delegationABI.d.ts +0 -126
  30. package/lib/browser/avs/abis/delegationABI.js +0 -4
  31. package/lib/browser/avs/abis/registryABI.d.ts +0 -136
  32. package/lib/browser/avs/abis/registryABI.js +0 -728
  33. package/lib/browser/avs/client/create-claim-on-avs.d.ts +0 -12
  34. package/lib/browser/avs/client/create-claim-on-avs.js +0 -168
  35. package/lib/browser/avs/config.d.ts +0 -7
  36. package/lib/browser/avs/config.js +0 -26
  37. package/lib/browser/avs/contracts/ReclaimServiceManager.d.ts +0 -601
  38. package/lib/browser/avs/contracts/ReclaimServiceManager.js +0 -0
  39. package/lib/browser/avs/contracts/common.d.ts +0 -50
  40. package/lib/browser/avs/contracts/common.js +0 -0
  41. package/lib/browser/avs/contracts/factories/ReclaimServiceManager__factory.d.ts +0 -890
  42. package/lib/browser/avs/contracts/factories/ReclaimServiceManager__factory.js +0 -1183
  43. package/lib/browser/avs/contracts/factories/index.d.ts +0 -1
  44. package/lib/browser/avs/contracts/factories/index.js +0 -4
  45. package/lib/browser/avs/contracts/index.d.ts +0 -3
  46. package/lib/browser/avs/contracts/index.js +0 -6
  47. package/lib/browser/avs/types/index.d.ts +0 -55
  48. package/lib/browser/avs/types/index.js +0 -0
  49. package/lib/browser/avs/utils/contracts.d.ts +0 -21
  50. package/lib/browser/avs/utils/contracts.js +0 -53
  51. package/lib/browser/avs/utils/register.d.ts +0 -27
  52. package/lib/browser/avs/utils/register.js +0 -74
  53. package/lib/browser/avs/utils/tasks.d.ts +0 -22
  54. package/lib/browser/avs/utils/tasks.js +0 -48
  55. package/lib/browser/client/create-claim.d.ts +0 -5
  56. package/lib/browser/client/create-claim.js +0 -461
  57. package/lib/browser/client/index.d.ts +0 -3
  58. package/lib/browser/client/index.js +0 -3
  59. package/lib/browser/client/tunnels/make-rpc-tcp-tunnel.d.ts +0 -16
  60. package/lib/browser/client/tunnels/make-rpc-tcp-tunnel.js +0 -53
  61. package/lib/browser/client/tunnels/make-rpc-tls-tunnel.d.ts +0 -26
  62. package/lib/browser/client/tunnels/make-rpc-tls-tunnel.js +0 -127
  63. package/lib/browser/client/utils/attestor-pool.d.ts +0 -8
  64. package/lib/browser/client/utils/attestor-pool.js +0 -24
  65. package/lib/browser/client/utils/client-socket.d.ts +0 -11
  66. package/lib/browser/client/utils/client-socket.js +0 -120
  67. package/lib/browser/client/utils/message-handler.d.ts +0 -4
  68. package/lib/browser/client/utils/message-handler.js +0 -97
  69. package/lib/browser/config/index.d.ts +0 -31
  70. package/lib/browser/config/index.js +0 -62
  71. package/lib/browser/external-rpc/benchmark.d.ts +0 -1
  72. package/lib/browser/external-rpc/benchmark.js +0 -82
  73. package/lib/browser/external-rpc/event-bus.d.ts +0 -7
  74. package/lib/browser/external-rpc/event-bus.js +0 -17
  75. package/lib/browser/external-rpc/global.d.js +0 -0
  76. package/lib/browser/external-rpc/handle-incoming-msg.d.ts +0 -2
  77. package/lib/browser/external-rpc/handle-incoming-msg.js +0 -241
  78. package/lib/browser/external-rpc/index.d.ts +0 -3
  79. package/lib/browser/external-rpc/index.js +0 -3
  80. package/lib/browser/external-rpc/jsc-polyfills/1.d.ts +0 -14
  81. package/lib/browser/external-rpc/jsc-polyfills/1.js +0 -80
  82. package/lib/browser/external-rpc/jsc-polyfills/2.d.ts +0 -1
  83. package/lib/browser/external-rpc/jsc-polyfills/2.js +0 -15
  84. package/lib/browser/external-rpc/jsc-polyfills/event.d.ts +0 -10
  85. package/lib/browser/external-rpc/jsc-polyfills/event.js +0 -19
  86. package/lib/browser/external-rpc/jsc-polyfills/index.d.ts +0 -2
  87. package/lib/browser/external-rpc/jsc-polyfills/index.js +0 -2
  88. package/lib/browser/external-rpc/jsc-polyfills/ws.d.ts +0 -21
  89. package/lib/browser/external-rpc/jsc-polyfills/ws.js +0 -83
  90. package/lib/browser/external-rpc/setup-browser.d.ts +0 -6
  91. package/lib/browser/external-rpc/setup-browser.js +0 -33
  92. package/lib/browser/external-rpc/setup-jsc.d.ts +0 -24
  93. package/lib/browser/external-rpc/setup-jsc.js +0 -22
  94. package/lib/browser/external-rpc/types.d.ts +0 -213
  95. package/lib/browser/external-rpc/types.js +0 -0
  96. package/lib/browser/external-rpc/utils.d.ts +0 -20
  97. package/lib/browser/external-rpc/utils.js +0 -100
  98. package/lib/browser/external-rpc/zk.d.ts +0 -14
  99. package/lib/browser/external-rpc/zk.js +0 -58
  100. package/lib/browser/index.browser.js +0 -13
  101. package/lib/browser/index.d.ts +0 -9
  102. package/lib/browser/index.js +0 -13
  103. package/lib/browser/mechain/abis/governanceABI.d.ts +0 -50
  104. package/lib/browser/mechain/abis/governanceABI.js +0 -461
  105. package/lib/browser/mechain/abis/taskABI.d.ts +0 -157
  106. package/lib/browser/mechain/abis/taskABI.js +0 -512
  107. package/lib/browser/mechain/client/create-claim-on-mechain.d.ts +0 -10
  108. package/lib/browser/mechain/client/create-claim-on-mechain.js +0 -33
  109. package/lib/browser/mechain/client/index.d.ts +0 -1
  110. package/lib/browser/mechain/client/index.js +0 -1
  111. package/lib/browser/mechain/constants/index.d.ts +0 -3
  112. package/lib/browser/mechain/constants/index.js +0 -8
  113. package/lib/browser/mechain/index.d.ts +0 -2
  114. package/lib/browser/mechain/index.js +0 -2
  115. package/lib/browser/mechain/types/index.d.ts +0 -23
  116. package/lib/browser/mechain/types/index.js +0 -0
  117. package/lib/browser/proto/api.d.ts +0 -651
  118. package/lib/browser/proto/api.js +0 -4250
  119. package/lib/browser/proto/tee-bundle.d.ts +0 -156
  120. package/lib/browser/proto/tee-bundle.js +0 -1296
  121. package/lib/browser/providers/http/index.d.ts +0 -18
  122. package/lib/browser/providers/http/index.js +0 -640
  123. package/lib/browser/providers/http/patch-parse5-tree.d.ts +0 -6
  124. package/lib/browser/providers/http/patch-parse5-tree.js +0 -34
  125. package/lib/browser/providers/http/utils.d.ts +0 -77
  126. package/lib/browser/providers/http/utils.js +0 -283
  127. package/lib/browser/providers/index.d.ts +0 -4
  128. package/lib/browser/providers/index.js +0 -7
  129. package/lib/browser/types/bgp.d.ts +0 -11
  130. package/lib/browser/types/bgp.js +0 -0
  131. package/lib/browser/types/claims.d.ts +0 -70
  132. package/lib/browser/types/claims.js +0 -0
  133. package/lib/browser/types/client.d.ts +0 -163
  134. package/lib/browser/types/client.js +0 -0
  135. package/lib/browser/types/general.d.ts +0 -77
  136. package/lib/browser/types/general.js +0 -0
  137. package/lib/browser/types/handlers.d.ts +0 -10
  138. package/lib/browser/types/handlers.js +0 -0
  139. package/lib/browser/types/index.d.ts +0 -10
  140. package/lib/browser/types/index.js +0 -10
  141. package/lib/browser/types/providers.d.ts +0 -161
  142. package/lib/browser/types/providers.gen.d.ts +0 -443
  143. package/lib/browser/types/providers.gen.js +0 -16
  144. package/lib/browser/types/providers.js +0 -0
  145. package/lib/browser/types/rpc.d.ts +0 -35
  146. package/lib/browser/types/rpc.js +0 -0
  147. package/lib/browser/types/signatures.d.ts +0 -28
  148. package/lib/browser/types/signatures.js +0 -0
  149. package/lib/browser/types/tunnel.d.ts +0 -18
  150. package/lib/browser/types/tunnel.js +0 -0
  151. package/lib/browser/types/zk.d.ts +0 -38
  152. package/lib/browser/types/zk.js +0 -0
  153. package/lib/browser/utils/auth.d.ts +0 -8
  154. package/lib/browser/utils/auth.js +0 -71
  155. package/lib/browser/utils/b64-json.d.ts +0 -2
  156. package/lib/browser/utils/b64-json.js +0 -17
  157. package/lib/browser/utils/claims.d.ts +0 -33
  158. package/lib/browser/utils/claims.js +0 -89
  159. package/lib/browser/utils/env.d.ts +0 -3
  160. package/lib/browser/utils/env.js +0 -19
  161. package/lib/browser/utils/error.d.ts +0 -26
  162. package/lib/browser/utils/error.js +0 -54
  163. package/lib/browser/utils/generics.d.ts +0 -119
  164. package/lib/browser/utils/generics.js +0 -272
  165. package/lib/browser/utils/http-parser.d.ts +0 -59
  166. package/lib/browser/utils/http-parser.js +0 -201
  167. package/lib/browser/utils/index.browser.js +0 -13
  168. package/lib/browser/utils/index.d.ts +0 -13
  169. package/lib/browser/utils/index.js +0 -13
  170. package/lib/browser/utils/logger.browser.js +0 -88
  171. package/lib/browser/utils/logger.d.ts +0 -14
  172. package/lib/browser/utils/logger.js +0 -88
  173. package/lib/browser/utils/prepare-packets.d.ts +0 -16
  174. package/lib/browser/utils/prepare-packets.js +0 -69
  175. package/lib/browser/utils/redactions.d.ts +0 -73
  176. package/lib/browser/utils/redactions.js +0 -135
  177. package/lib/browser/utils/retries.d.ts +0 -12
  178. package/lib/browser/utils/retries.js +0 -26
  179. package/lib/browser/utils/signatures/eth.d.ts +0 -2
  180. package/lib/browser/utils/signatures/eth.js +0 -31
  181. package/lib/browser/utils/signatures/index.d.ts +0 -5
  182. package/lib/browser/utils/signatures/index.js +0 -12
  183. package/lib/browser/utils/socket-base.d.ts +0 -23
  184. package/lib/browser/utils/socket-base.js +0 -96
  185. package/lib/browser/utils/tls-imports.d.ts +0 -21
  186. package/lib/browser/utils/tls-imports.js +0 -71
  187. package/lib/browser/utils/tls.d.ts +0 -2
  188. package/lib/browser/utils/tls.js +0 -58
  189. package/lib/browser/utils/ws.d.ts +0 -7
  190. package/lib/browser/utils/ws.js +0 -22
  191. package/lib/browser/utils/zk.d.ts +0 -71
  192. package/lib/browser/utils/zk.js +0 -625
  193. package/lib/client/create-claim.js +0 -461
  194. package/lib/client/index.js +0 -3
  195. package/lib/client/tunnels/make-rpc-tcp-tunnel.js +0 -53
  196. package/lib/client/tunnels/make-rpc-tls-tunnel.js +0 -127
  197. package/lib/client/utils/attestor-pool.js +0 -24
  198. package/lib/client/utils/client-socket.js +0 -120
  199. package/lib/client/utils/message-handler.js +0 -97
  200. package/lib/config/index.js +0 -62
  201. package/lib/external-rpc/benchmark.js +0 -82
  202. package/lib/external-rpc/event-bus.js +0 -17
  203. package/lib/external-rpc/global.d.js +0 -0
  204. package/lib/external-rpc/handle-incoming-msg.js +0 -241
  205. package/lib/external-rpc/jsc-polyfills/1.js +0 -80
  206. package/lib/external-rpc/jsc-polyfills/2.js +0 -15
  207. package/lib/external-rpc/jsc-polyfills/event.js +0 -19
  208. package/lib/external-rpc/jsc-polyfills/index.js +0 -2
  209. package/lib/external-rpc/jsc-polyfills/ws.js +0 -83
  210. package/lib/external-rpc/setup-browser.js +0 -33
  211. package/lib/external-rpc/setup-jsc.js +0 -22
  212. package/lib/external-rpc/types.js +0 -0
  213. package/lib/external-rpc/utils.js +0 -100
  214. package/lib/external-rpc/zk.js +0 -58
  215. package/lib/index.browser.d.ts +0 -9
  216. package/lib/mechain/abis/governanceABI.js +0 -461
  217. package/lib/mechain/abis/taskABI.js +0 -512
  218. package/lib/mechain/client/create-claim-on-mechain.js +0 -33
  219. package/lib/mechain/client/index.js +0 -1
  220. package/lib/mechain/constants/index.js +0 -8
  221. package/lib/mechain/index.js +0 -2
  222. package/lib/mechain/types/index.js +0 -0
  223. package/lib/proto/api.js +0 -4250
  224. package/lib/proto/tee-bundle.js +0 -1296
  225. package/lib/providers/http/index.js +0 -640
  226. package/lib/providers/http/patch-parse5-tree.js +0 -34
  227. package/lib/providers/http/utils.js +0 -283
  228. package/lib/providers/index.js +0 -7
  229. package/lib/scripts/check-avs-registration.js +0 -28
  230. package/lib/scripts/fallbacks/crypto.js +0 -4
  231. package/lib/scripts/fallbacks/empty.js +0 -4
  232. package/lib/scripts/fallbacks/re2.js +0 -7
  233. package/lib/scripts/fallbacks/snarkjs.js +0 -10
  234. package/lib/scripts/fallbacks/stwo.js +0 -159
  235. package/lib/scripts/generate-provider-types.js +0 -101
  236. package/lib/scripts/generate-receipt.js +0 -101
  237. package/lib/scripts/generate-toprf-keys.js +0 -24
  238. package/lib/scripts/jsc-cli-rpc.js +0 -35
  239. package/lib/scripts/register-avs-operator.js +0 -3
  240. package/lib/scripts/start-server.js +0 -11
  241. package/lib/scripts/update-avs-metadata.js +0 -20
  242. package/lib/scripts/utils.js +0 -10
  243. package/lib/scripts/whitelist-operator.js +0 -16
  244. package/lib/server/create-server.js +0 -105
  245. package/lib/server/handlers/claimTeeBundle.js +0 -232
  246. package/lib/server/handlers/claimTunnel.js +0 -80
  247. package/lib/server/handlers/completeClaimOnChain.js +0 -29
  248. package/lib/server/handlers/createClaimOnChain.js +0 -32
  249. package/lib/server/handlers/createTaskOnMechain.js +0 -57
  250. package/lib/server/handlers/createTunnel.js +0 -98
  251. package/lib/server/handlers/disconnectTunnel.js +0 -8
  252. package/lib/server/handlers/fetchCertificateBytes.js +0 -57
  253. package/lib/server/handlers/index.js +0 -25
  254. package/lib/server/handlers/init.js +0 -33
  255. package/lib/server/handlers/toprf.js +0 -19
  256. package/lib/server/index.js +0 -4
  257. package/lib/server/socket.js +0 -112
  258. package/lib/server/tunnels/make-tcp-tunnel.js +0 -202
  259. package/lib/server/utils/apm.js +0 -29
  260. package/lib/server/utils/assert-valid-claim-request.js +0 -354
  261. package/lib/server/utils/config-env.js +0 -4
  262. package/lib/server/utils/dns.js +0 -24
  263. package/lib/server/utils/gcp-attestation.js +0 -237
  264. package/lib/server/utils/generics.js +0 -45
  265. package/lib/server/utils/iso.js +0 -259
  266. package/lib/server/utils/keep-alive.js +0 -38
  267. package/lib/server/utils/nitro-attestation.js +0 -249
  268. package/lib/server/utils/oprf-raw.js +0 -61
  269. package/lib/server/utils/process-handshake.js +0 -233
  270. package/lib/server/utils/proxy-session.js +0 -4
  271. package/lib/server/utils/tee-oprf-mpc-verification.js +0 -86
  272. package/lib/server/utils/tee-oprf-verification.js +0 -151
  273. package/lib/server/utils/tee-transcript-reconstruction.js +0 -140
  274. package/lib/server/utils/tee-verification.js +0 -358
  275. package/lib/server/utils/validation.js +0 -45
  276. package/lib/types/bgp.js +0 -0
  277. package/lib/types/claims.js +0 -0
  278. package/lib/types/client.js +0 -0
  279. package/lib/types/general.js +0 -0
  280. package/lib/types/handlers.js +0 -0
  281. package/lib/types/index.js +0 -10
  282. package/lib/types/providers.gen.js +0 -16
  283. package/lib/types/providers.js +0 -0
  284. package/lib/types/rpc.js +0 -0
  285. package/lib/types/signatures.js +0 -0
  286. package/lib/types/tunnel.js +0 -0
  287. package/lib/types/zk.js +0 -0
  288. package/lib/utils/auth.js +0 -71
  289. package/lib/utils/b64-json.js +0 -17
  290. package/lib/utils/bgp-listener.js +0 -123
  291. package/lib/utils/claims.js +0 -89
  292. package/lib/utils/env.js +0 -19
  293. package/lib/utils/error.js +0 -54
  294. package/lib/utils/generics.js +0 -272
  295. package/lib/utils/http-parser.js +0 -201
  296. package/lib/utils/index.browser.d.ts +0 -13
  297. package/lib/utils/index.js +0 -14
  298. package/lib/utils/logger.browser.d.ts +0 -14
  299. package/lib/utils/logger.js +0 -82
  300. package/lib/utils/prepare-packets.js +0 -69
  301. package/lib/utils/redactions.js +0 -135
  302. package/lib/utils/retries.js +0 -26
  303. package/lib/utils/signatures/eth.js +0 -31
  304. package/lib/utils/signatures/index.js +0 -12
  305. package/lib/utils/socket-base.js +0 -96
  306. package/lib/utils/tls-imports.d.ts +0 -21
  307. package/lib/utils/tls-imports.js +0 -71
  308. package/lib/utils/tls.js +0 -58
  309. package/lib/utils/ws.js +0 -22
  310. package/lib/utils/zk.js +0 -625
@@ -1,77 +0,0 @@
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 {};
@@ -1,283 +0,0 @@
1
- import "../../providers/http/patch-parse5-tree.js";
2
- import { concatenateUint8Arrays } from "../../utils/tls-imports.js";
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
- };
@@ -1,4 +0,0 @@
1
- import type { Provider, ProviderName } from '#src/types/index.ts';
2
- export declare const providers: {
3
- [T in ProviderName]: Provider<T>;
4
- };
@@ -1,7 +0,0 @@
1
- import http from "../providers/http/index.js";
2
- const providers = {
3
- http
4
- };
5
- export {
6
- providers
7
- };
@@ -1,11 +0,0 @@
1
- export type BGPAnnouncementOverlapData = {
2
- prefix: string;
3
- };
4
- export type BGPListener = {
5
- /**
6
- * Add an IP to listen for overlap,
7
- * @returns a function to remove the IP from the listener
8
- */
9
- onOverlap(ips: string[], callback: (event: BGPAnnouncementOverlapData) => void): (() => void);
10
- close(): void;
11
- };
File without changes
@@ -1,70 +0,0 @@
1
- import type { ProviderClaimData } from '#src/proto/api.ts';
2
- import type { IAttestorClient, IAttestorClientInitParams } from '#src/types/client.ts';
3
- import type { CompleteTLSPacket, Logger } from '#src/types/general.ts';
4
- import type { ProofGenerationStep, ProviderName, ProviderParams, ProviderSecretParams } from '#src/types/providers.ts';
5
- import type { Transcript } from '#src/types/tunnel.ts';
6
- import type { PrepareZKProofsBaseOpts } from '#src/types/zk.ts';
7
- /**
8
- * Uniquely identifies a claim.
9
- * Hash of claim info.
10
- * Utilise `getIdentifierFromClaimInfo` to obtain this.
11
- */
12
- export type ClaimID = ProviderClaimData['identifier'];
13
- export type ClaimInfo = Pick<ProviderClaimData, 'context' | 'provider' | 'parameters'>;
14
- export type CompleteClaimData = Pick<ProviderClaimData, 'owner' | 'timestampS' | 'epoch'> & ClaimInfo;
15
- export type CreateClaimOnAttestorOpts<N extends ProviderName> = {
16
- /** name of the provider to generate signed receipt for */
17
- name: N;
18
- /**
19
- * secrets that are used to make the API request;
20
- * not included in the receipt & cannot be viewed by anyone
21
- * outside this client
22
- */
23
- secretParams: ProviderSecretParams<N>;
24
- params: ProviderParams<N>;
25
- /**
26
- * Some metadata context to be included in the claim
27
- */
28
- context?: {
29
- [key: string]: any;
30
- };
31
- onStep?(step: ProofGenerationStep): void;
32
- /**
33
- * Private key in hex format,
34
- * prefixed with '0x'
35
- */
36
- ownerPrivateKey: string;
37
- /**
38
- * Provide either the client or the URL
39
- * to the server -- so a client can be created internally.
40
- *
41
- * The created client will go into the global client pool.
42
- */
43
- client: IAttestorClient | IAttestorClientInitParams;
44
- /**
45
- * Optionally set the timestamp of the claim
46
- * in unix seconds. If not provided, the current
47
- * time will be used.
48
- */
49
- timestampS?: number;
50
- logger?: Logger;
51
- /**
52
- * Maximum number of retries to attempt
53
- * @default 3
54
- */
55
- maxRetries?: number;
56
- /**
57
- * Optionally update the provider parameters
58
- * based on the transcript
59
- */
60
- updateProviderParams?(transcript: Transcript<CompleteTLSPacket>, tlsVersion: string): Promise<{
61
- params: Partial<ProviderParams<N>>;
62
- secretParams: Partial<ProviderSecretParams<N>>;
63
- }>;
64
- /**
65
- * Replaces paramValue with corresponding OPRF hash before proof is made
66
- * Only if there's matching redaction exists
67
- * For example: "domain.com" -> "dv4Nrgtr"
68
- */
69
- updateParametersFromOprfData?: boolean;
70
- } & PrepareZKProofsBaseOpts;
File without changes
@@ -1,163 +0,0 @@
1
- import type { IncomingMessage } from 'http';
2
- import type { WebSocket as WSWebSocket } from 'ws';
3
- import type { AuthenticationRequest, InitRequest, InitResponse, RPCMessage, RPCMessages, ServiceSignatureType, TunnelMessage } from '#src/proto/api.ts';
4
- import type { BGPListener } from '#src/types/bgp.ts';
5
- import type { Logger } from '#src/types/general.ts';
6
- import type { RPCEvent, RPCEventMap, RPCEventType, RPCRequestData, RPCResponseData, RPCType } from '#src/types/rpc.ts';
7
- import type { TCPSocketProperties, Tunnel } from '#src/types/tunnel.ts';
8
- /**
9
- * Any WebSocket implementation -- either the native
10
- * WebSocket or the WebSocket from the `ws` package.
11
- */
12
- export type AnyWebSocket = WebSocket | WSWebSocket;
13
- export type MakeWebSocket = (url: string | URL) => AnyWebSocket;
14
- export type AcceptNewConnectionOpts = {
15
- req: IncomingMessage;
16
- logger: Logger;
17
- bgpListener?: BGPListener;
18
- };
19
- export type IAttestorClientInitParams = {
20
- /**
21
- * Attestor WS URL
22
- */
23
- url: string | URL;
24
- /**
25
- * If the attestor being connected to has authentication
26
- * enabled, provide the authentication request here, or a
27
- * function that will return the authentication request.
28
- */
29
- authRequest?: AuthenticationRequest | (() => Promise<AuthenticationRequest>);
30
- };
31
- export type IAttestorClientCreateOpts = {
32
- /**
33
- * Attestor WS URL
34
- */
35
- url: string | URL;
36
- authRequest?: AuthenticationRequest;
37
- signatureType?: ServiceSignatureType;
38
- logger?: Logger;
39
- /**
40
- * Initial messages to send to the server
41
- * in the query parameter used to establish
42
- * the connection.
43
- */
44
- initMessages?: Partial<RPCMessage>[];
45
- /**
46
- * Provide a custom WebSocket implementation,
47
- * will use the native WebSocket if not provided.
48
- */
49
- makeWebSocket?: MakeWebSocket;
50
- };
51
- /**
52
- * Base layer for the WebSocket connection on
53
- * the client and server.
54
- */
55
- export declare class IAttestorSocket {
56
- metadata: InitRequest;
57
- logger: Logger;
58
- /**
59
- * Is the WebSocket connection open?
60
- */
61
- isOpen: boolean;
62
- /**
63
- * Has the WebSocket connection been closed
64
- */
65
- isClosed: boolean;
66
- /**
67
- * Whether the WebSocket has been initialised
68
- * by receiving an "init-response" message.
69
- */
70
- isInitialised: boolean;
71
- /**
72
- * Sends RPC messages to the server in a single packet.
73
- * If the ID is not provided, it will be generated.
74
- *
75
- * Promisify the `send` method if using the `ws` package's
76
- * WebSocket implementation.
77
- */
78
- sendMessage(...msgs: Partial<RPCMessage>[]): Promise<RPCMessages>;
79
- /**
80
- * Sends a "terminateConnectionAlert" message to the server
81
- * with the specified error (if any), if the connection is
82
- * still open and then closes the connection.
83
- */
84
- terminateConnection(err?: Error): Promise<void>;
85
- /**
86
- * Use this to listen to events on the WebSocket.
87
- */
88
- addEventListener<K extends RPCEventType>(type: K, listener: (data: RPCEvent<K>) => void): void;
89
- removeEventListener<K extends RPCEventType>(type: K, listener: (data: RPCEvent<K>) => void): void;
90
- /**
91
- * Syntactic sugar for emitting events on the WebSocket.
92
- * Wraps the `makeRpcEvent` call internally
93
- */
94
- dispatchRPCEvent<K extends RPCEventType>(type: K, data: RPCEventMap[K]): void;
95
- /**
96
- * Starts processing RPC messages from the WebSocket
97
- * & emits events for each message type. These can be
98
- * captured by the `addEventListener` method.
99
- *
100
- * Will also listen to "error" & "close" events on the WebSocket
101
- * and emit a "attestor-error" event with the error.
102
- * So, you only need to listen to the "attestor-error"
103
- * event to capture anything you're interested in.
104
- */
105
- constructor(ws: WebSocket, metadata: InitRequest, logger: Logger);
106
- }
107
- export declare class IAttestorServerSocket extends IAttestorSocket {
108
- /**
109
- * Unique identifier for this WebSocket connection
110
- */
111
- sessionId: number;
112
- /**
113
- * Set of tunnels this client created. Only available
114
- * when WS is created by the server
115
- */
116
- tunnels: {
117
- [id: TunnelMessage['tunnelId']]: Tunnel<TCPSocketProperties>;
118
- };
119
- /**
120
- * Fetches a tunnel by its ID.
121
- * If the tunnel does not exist, it will throw an error.
122
- */
123
- getTunnel(tunnelId: TunnelMessage['tunnelId']): Tunnel<TCPSocketProperties>;
124
- removeTunnel(tunnelId: TunnelMessage['tunnelId']): void;
125
- bgpListener?: BGPListener;
126
- }
127
- export declare class IAttestorClient extends IAttestorSocket {
128
- initResponse?: InitResponse;
129
- constructor(opts: IAttestorClientCreateOpts);
130
- /**
131
- * Waits for a particular message to come in.
132
- * If the connection is closed before the message is received,
133
- * the promise will reject.
134
- */
135
- waitForResponse<T extends RPCType>(id: number, timeoutMs?: number): Promise<RPCResponseData<T>>;
136
- /**
137
- * Make an RPC request to the other end of the WebSocket.
138
- */
139
- rpc<T extends RPCType>(type: T, request: Partial<RPCRequestData<T>>, timeoutMs?: number): Promise<RPCResponseData<T>>;
140
- /**
141
- * Waits for the "init" request to be responded to
142
- */
143
- waitForInit(): Promise<void>;
144
- }
145
- interface WebSocketWithServerSocket {
146
- /**
147
- * Our RPC socket instance
148
- */
149
- serverSocket?: IAttestorServerSocket;
150
- /**
151
- * Just promisified send
152
- */
153
- sendPromise?: (data: Uint8Array) => Promise<void>;
154
- }
155
- declare module 'ws' {
156
- namespace WebSocket {
157
- interface WebSocket extends WebSocketWithServerSocket {
158
- }
159
- }
160
- interface WebSocket extends WebSocketWithServerSocket {
161
- }
162
- }
163
- export {};
File without changes