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

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 (268) hide show
  1. package/lib/avs/client/create-claim-on-avs.js +5 -5
  2. package/lib/avs/config.js +1 -1
  3. package/lib/avs/utils/contracts.js +5 -5
  4. package/lib/avs/utils/register.js +3 -3
  5. package/lib/avs/utils/tasks.js +1 -1
  6. package/lib/client/create-claim.js +10 -10
  7. package/lib/client/tunnels/make-rpc-tcp-tunnel.js +1 -1
  8. package/lib/client/tunnels/make-rpc-tls-tunnel.d.ts +1 -1
  9. package/lib/client/tunnels/make-rpc-tls-tunnel.js +4 -4
  10. package/lib/client/utils/attestor-pool.js +1 -1
  11. package/lib/client/utils/client-socket.js +5 -5
  12. package/lib/client/utils/message-handler.js +2 -2
  13. package/lib/config/index.js +1 -1
  14. package/lib/external-rpc/benchmark.js +4 -4
  15. package/lib/external-rpc/handle-incoming-msg.js +9 -9
  16. package/lib/external-rpc/jsc-polyfills/1.js +1 -1
  17. package/lib/external-rpc/jsc-polyfills/2.js +2 -2
  18. package/lib/external-rpc/jsc-polyfills/index.js +2 -2
  19. package/lib/external-rpc/jsc-polyfills/ws.js +1 -1
  20. package/lib/external-rpc/setup-browser.js +5 -5
  21. package/lib/external-rpc/setup-jsc.js +4 -4
  22. package/lib/external-rpc/utils.js +4 -4
  23. package/lib/external-rpc/zk.js +2 -2
  24. package/lib/mechain/client/create-claim-on-mechain.js +2 -2
  25. package/lib/providers/http/index.js +6 -6
  26. package/lib/providers/http/utils.js +3 -3
  27. package/lib/providers/index.js +1 -1
  28. package/lib/scripts/build-browser.js +38 -0
  29. package/lib/scripts/build-jsc.js +47 -0
  30. package/lib/scripts/build-lib.js +47 -0
  31. package/lib/scripts/check-avs-registration.js +1 -1
  32. package/lib/scripts/generate-provider-types.js +1 -1
  33. package/lib/scripts/generate-receipt.js +6 -6
  34. package/lib/scripts/generate-toprf-keys.js +1 -1
  35. package/lib/scripts/jsc-cli-rpc.js +3 -3
  36. package/lib/scripts/register-avs-operator.js +1 -1
  37. package/lib/scripts/start-server.js +3 -3
  38. package/lib/scripts/update-avs-metadata.js +2 -2
  39. package/lib/scripts/whitelist-operator.js +2 -2
  40. package/lib/server/create-server.js +9 -9
  41. package/lib/server/handlers/claimTeeBundle.js +11 -11
  42. package/lib/server/handlers/claimTunnel.js +6 -6
  43. package/lib/server/handlers/completeClaimOnChain.js +3 -3
  44. package/lib/server/handlers/createClaimOnChain.js +4 -4
  45. package/lib/server/handlers/createTaskOnMechain.js +4 -4
  46. package/lib/server/handlers/createTunnel.js +4 -4
  47. package/lib/server/handlers/fetchCertificateBytes.js +2 -2
  48. package/lib/server/handlers/index.js +10 -10
  49. package/lib/server/handlers/init.js +5 -5
  50. package/lib/server/handlers/toprf.js +2 -2
  51. package/lib/server/socket.js +7 -7
  52. package/lib/server/tunnels/make-tcp-tunnel.js +6 -6
  53. package/lib/server/utils/apm.js +2 -2
  54. package/lib/server/utils/assert-valid-claim-request.js +8 -8
  55. package/lib/server/utils/config-env.js +1 -1
  56. package/lib/server/utils/dns.js +1 -1
  57. package/lib/server/utils/generics.js +4 -4
  58. package/lib/server/utils/keep-alive.js +1 -1
  59. package/lib/server/utils/oprf-raw.js +3 -3
  60. package/lib/server/utils/process-handshake.js +2 -2
  61. package/lib/server/utils/proxy-session.d.ts +1 -1
  62. package/lib/server/utils/proxy-session.js +3 -1
  63. package/lib/server/utils/tee-oprf-mpc-verification.js +1 -1
  64. package/lib/server/utils/tee-oprf-verification.js +2 -2
  65. package/lib/server/utils/tee-transcript-reconstruction.js +3 -3
  66. package/lib/server/utils/tee-verification.js +6 -6
  67. package/lib/server/utils/validation.js +2 -2
  68. package/lib/types/general.d.ts +0 -1
  69. package/lib/utils/auth.js +6 -6
  70. package/lib/utils/bgp-listener.js +2 -2
  71. package/lib/utils/claims.js +3 -3
  72. package/lib/utils/error.js +1 -1
  73. package/lib/utils/generics.d.ts +1 -6
  74. package/lib/utils/generics.js +2 -6
  75. package/lib/utils/http-parser.js +3 -3
  76. package/lib/utils/index.d.ts +0 -1
  77. package/lib/utils/index.js +0 -1
  78. package/lib/utils/logger.js +1 -1
  79. package/lib/utils/prepare-packets.js +3 -3
  80. package/lib/utils/redactions.js +1 -1
  81. package/lib/utils/signatures/index.js +2 -2
  82. package/lib/utils/socket-base.js +3 -3
  83. package/lib/utils/tls.js +2 -2
  84. package/lib/utils/zk.js +8 -8
  85. package/package.json +3 -9
  86. package/lib/browser/avs/abis/avsDirectoryABI.d.ts +0 -60
  87. package/lib/browser/avs/abis/avsDirectoryABI.js +0 -343
  88. package/lib/browser/avs/abis/delegationABI.d.ts +0 -126
  89. package/lib/browser/avs/abis/delegationABI.js +0 -4
  90. package/lib/browser/avs/abis/registryABI.d.ts +0 -136
  91. package/lib/browser/avs/abis/registryABI.js +0 -728
  92. package/lib/browser/avs/client/create-claim-on-avs.d.ts +0 -12
  93. package/lib/browser/avs/client/create-claim-on-avs.js +0 -168
  94. package/lib/browser/avs/config.d.ts +0 -7
  95. package/lib/browser/avs/config.js +0 -26
  96. package/lib/browser/avs/contracts/ReclaimServiceManager.d.ts +0 -601
  97. package/lib/browser/avs/contracts/ReclaimServiceManager.js +0 -0
  98. package/lib/browser/avs/contracts/common.d.ts +0 -50
  99. package/lib/browser/avs/contracts/common.js +0 -0
  100. package/lib/browser/avs/contracts/factories/ReclaimServiceManager__factory.d.ts +0 -890
  101. package/lib/browser/avs/contracts/factories/ReclaimServiceManager__factory.js +0 -1183
  102. package/lib/browser/avs/contracts/factories/index.d.ts +0 -1
  103. package/lib/browser/avs/contracts/factories/index.js +0 -4
  104. package/lib/browser/avs/contracts/index.d.ts +0 -3
  105. package/lib/browser/avs/contracts/index.js +0 -6
  106. package/lib/browser/avs/types/index.d.ts +0 -55
  107. package/lib/browser/avs/types/index.js +0 -0
  108. package/lib/browser/avs/utils/contracts.d.ts +0 -21
  109. package/lib/browser/avs/utils/contracts.js +0 -53
  110. package/lib/browser/avs/utils/register.d.ts +0 -27
  111. package/lib/browser/avs/utils/register.js +0 -74
  112. package/lib/browser/avs/utils/tasks.d.ts +0 -22
  113. package/lib/browser/avs/utils/tasks.js +0 -48
  114. package/lib/browser/client/create-claim.d.ts +0 -5
  115. package/lib/browser/client/create-claim.js +0 -461
  116. package/lib/browser/client/index.d.ts +0 -3
  117. package/lib/browser/client/index.js +0 -3
  118. package/lib/browser/client/tunnels/make-rpc-tcp-tunnel.d.ts +0 -16
  119. package/lib/browser/client/tunnels/make-rpc-tcp-tunnel.js +0 -53
  120. package/lib/browser/client/tunnels/make-rpc-tls-tunnel.d.ts +0 -26
  121. package/lib/browser/client/tunnels/make-rpc-tls-tunnel.js +0 -127
  122. package/lib/browser/client/utils/attestor-pool.d.ts +0 -8
  123. package/lib/browser/client/utils/attestor-pool.js +0 -24
  124. package/lib/browser/client/utils/client-socket.d.ts +0 -11
  125. package/lib/browser/client/utils/client-socket.js +0 -120
  126. package/lib/browser/client/utils/message-handler.d.ts +0 -4
  127. package/lib/browser/client/utils/message-handler.js +0 -97
  128. package/lib/browser/config/index.d.ts +0 -31
  129. package/lib/browser/config/index.js +0 -62
  130. package/lib/browser/external-rpc/benchmark.d.ts +0 -1
  131. package/lib/browser/external-rpc/benchmark.js +0 -82
  132. package/lib/browser/external-rpc/event-bus.d.ts +0 -7
  133. package/lib/browser/external-rpc/event-bus.js +0 -17
  134. package/lib/browser/external-rpc/global.d.js +0 -0
  135. package/lib/browser/external-rpc/handle-incoming-msg.d.ts +0 -2
  136. package/lib/browser/external-rpc/handle-incoming-msg.js +0 -241
  137. package/lib/browser/external-rpc/index.d.ts +0 -3
  138. package/lib/browser/external-rpc/index.js +0 -3
  139. package/lib/browser/external-rpc/jsc-polyfills/1.d.ts +0 -14
  140. package/lib/browser/external-rpc/jsc-polyfills/1.js +0 -80
  141. package/lib/browser/external-rpc/jsc-polyfills/2.d.ts +0 -1
  142. package/lib/browser/external-rpc/jsc-polyfills/2.js +0 -15
  143. package/lib/browser/external-rpc/jsc-polyfills/event.d.ts +0 -10
  144. package/lib/browser/external-rpc/jsc-polyfills/event.js +0 -19
  145. package/lib/browser/external-rpc/jsc-polyfills/index.d.ts +0 -2
  146. package/lib/browser/external-rpc/jsc-polyfills/index.js +0 -2
  147. package/lib/browser/external-rpc/jsc-polyfills/ws.d.ts +0 -21
  148. package/lib/browser/external-rpc/jsc-polyfills/ws.js +0 -83
  149. package/lib/browser/external-rpc/setup-browser.d.ts +0 -6
  150. package/lib/browser/external-rpc/setup-browser.js +0 -33
  151. package/lib/browser/external-rpc/setup-jsc.d.ts +0 -24
  152. package/lib/browser/external-rpc/setup-jsc.js +0 -22
  153. package/lib/browser/external-rpc/types.d.ts +0 -213
  154. package/lib/browser/external-rpc/types.js +0 -0
  155. package/lib/browser/external-rpc/utils.d.ts +0 -20
  156. package/lib/browser/external-rpc/utils.js +0 -100
  157. package/lib/browser/external-rpc/zk.d.ts +0 -14
  158. package/lib/browser/external-rpc/zk.js +0 -58
  159. package/lib/browser/index.browser.js +0 -13
  160. package/lib/browser/index.d.ts +0 -9
  161. package/lib/browser/index.js +0 -13
  162. package/lib/browser/mechain/abis/governanceABI.d.ts +0 -50
  163. package/lib/browser/mechain/abis/governanceABI.js +0 -461
  164. package/lib/browser/mechain/abis/taskABI.d.ts +0 -157
  165. package/lib/browser/mechain/abis/taskABI.js +0 -512
  166. package/lib/browser/mechain/client/create-claim-on-mechain.d.ts +0 -10
  167. package/lib/browser/mechain/client/create-claim-on-mechain.js +0 -33
  168. package/lib/browser/mechain/client/index.d.ts +0 -1
  169. package/lib/browser/mechain/client/index.js +0 -1
  170. package/lib/browser/mechain/constants/index.d.ts +0 -3
  171. package/lib/browser/mechain/constants/index.js +0 -8
  172. package/lib/browser/mechain/index.d.ts +0 -2
  173. package/lib/browser/mechain/index.js +0 -2
  174. package/lib/browser/mechain/types/index.d.ts +0 -23
  175. package/lib/browser/mechain/types/index.js +0 -0
  176. package/lib/browser/proto/api.d.ts +0 -651
  177. package/lib/browser/proto/api.js +0 -4250
  178. package/lib/browser/proto/tee-bundle.d.ts +0 -156
  179. package/lib/browser/proto/tee-bundle.js +0 -1296
  180. package/lib/browser/providers/http/index.d.ts +0 -18
  181. package/lib/browser/providers/http/index.js +0 -640
  182. package/lib/browser/providers/http/patch-parse5-tree.d.ts +0 -6
  183. package/lib/browser/providers/http/patch-parse5-tree.js +0 -34
  184. package/lib/browser/providers/http/utils.d.ts +0 -77
  185. package/lib/browser/providers/http/utils.js +0 -283
  186. package/lib/browser/providers/index.d.ts +0 -4
  187. package/lib/browser/providers/index.js +0 -7
  188. package/lib/browser/scripts/fallbacks/crypto.js +0 -4
  189. package/lib/browser/scripts/fallbacks/empty.js +0 -4
  190. package/lib/browser/scripts/fallbacks/gnark.js +0 -15
  191. package/lib/browser/scripts/fallbacks/re2.js +0 -7
  192. package/lib/browser/scripts/fallbacks/snarkjs.js +0 -10
  193. package/lib/browser/scripts/fallbacks/zk-file-fetch.js +0 -50
  194. package/lib/browser/types/bgp.d.ts +0 -11
  195. package/lib/browser/types/bgp.js +0 -0
  196. package/lib/browser/types/claims.d.ts +0 -70
  197. package/lib/browser/types/claims.js +0 -0
  198. package/lib/browser/types/client.d.ts +0 -163
  199. package/lib/browser/types/client.js +0 -0
  200. package/lib/browser/types/general.d.ts +0 -77
  201. package/lib/browser/types/general.js +0 -0
  202. package/lib/browser/types/handlers.d.ts +0 -10
  203. package/lib/browser/types/handlers.js +0 -0
  204. package/lib/browser/types/index.d.ts +0 -10
  205. package/lib/browser/types/index.js +0 -10
  206. package/lib/browser/types/providers.d.ts +0 -161
  207. package/lib/browser/types/providers.gen.d.ts +0 -443
  208. package/lib/browser/types/providers.gen.js +0 -16
  209. package/lib/browser/types/providers.js +0 -0
  210. package/lib/browser/types/rpc.d.ts +0 -35
  211. package/lib/browser/types/rpc.js +0 -0
  212. package/lib/browser/types/signatures.d.ts +0 -28
  213. package/lib/browser/types/signatures.js +0 -0
  214. package/lib/browser/types/tunnel.d.ts +0 -18
  215. package/lib/browser/types/tunnel.js +0 -0
  216. package/lib/browser/types/zk.d.ts +0 -38
  217. package/lib/browser/types/zk.js +0 -0
  218. package/lib/browser/utils/auth.d.ts +0 -8
  219. package/lib/browser/utils/auth.js +0 -71
  220. package/lib/browser/utils/b64-json.d.ts +0 -2
  221. package/lib/browser/utils/b64-json.js +0 -17
  222. package/lib/browser/utils/claims.d.ts +0 -33
  223. package/lib/browser/utils/claims.js +0 -89
  224. package/lib/browser/utils/env.d.ts +0 -3
  225. package/lib/browser/utils/env.js +0 -19
  226. package/lib/browser/utils/error.d.ts +0 -26
  227. package/lib/browser/utils/error.js +0 -54
  228. package/lib/browser/utils/generics.d.ts +0 -119
  229. package/lib/browser/utils/generics.js +0 -272
  230. package/lib/browser/utils/http-parser.d.ts +0 -59
  231. package/lib/browser/utils/http-parser.js +0 -201
  232. package/lib/browser/utils/index.browser.js +0 -13
  233. package/lib/browser/utils/index.d.ts +0 -13
  234. package/lib/browser/utils/index.js +0 -13
  235. package/lib/browser/utils/logger.browser.js +0 -88
  236. package/lib/browser/utils/logger.d.ts +0 -14
  237. package/lib/browser/utils/logger.js +0 -88
  238. package/lib/browser/utils/prepare-packets.d.ts +0 -16
  239. package/lib/browser/utils/prepare-packets.js +0 -69
  240. package/lib/browser/utils/redactions.d.ts +0 -73
  241. package/lib/browser/utils/redactions.js +0 -135
  242. package/lib/browser/utils/retries.d.ts +0 -12
  243. package/lib/browser/utils/retries.js +0 -26
  244. package/lib/browser/utils/signatures/eth.d.ts +0 -2
  245. package/lib/browser/utils/signatures/eth.js +0 -31
  246. package/lib/browser/utils/signatures/index.d.ts +0 -5
  247. package/lib/browser/utils/signatures/index.js +0 -12
  248. package/lib/browser/utils/socket-base.d.ts +0 -23
  249. package/lib/browser/utils/socket-base.js +0 -96
  250. package/lib/browser/utils/tls-imports.d.ts +0 -21
  251. package/lib/browser/utils/tls-imports.js +0 -71
  252. package/lib/browser/utils/tls.d.ts +0 -2
  253. package/lib/browser/utils/tls.js +0 -58
  254. package/lib/browser/utils/ws.d.ts +0 -7
  255. package/lib/browser/utils/ws.js +0 -22
  256. package/lib/browser/utils/zk.d.ts +0 -71
  257. package/lib/browser/utils/zk.js +0 -623
  258. package/lib/external-rpc/global.d.js +0 -0
  259. package/lib/index.browser.d.ts +0 -9
  260. package/lib/scripts/fallbacks/gnark.d.ts +0 -7
  261. package/lib/scripts/fallbacks/gnark.js +0 -15
  262. package/lib/scripts/fallbacks/zk-file-fetch.d.ts +0 -24
  263. package/lib/scripts/fallbacks/zk-file-fetch.js +0 -50
  264. package/lib/utils/index.browser.d.ts +0 -13
  265. package/lib/utils/logger.browser.d.ts +0 -14
  266. package/lib/utils/tls-imports.d.ts +0 -21
  267. package/lib/utils/tls-imports.js +0 -71
  268. /package/lib/{browser/scripts → scripts}/fallbacks/stwo.js +0 -0
@@ -1,18 +0,0 @@
1
- import type { Provider, ProviderParams, ProviderSecretParams } from '#src/types/index.ts';
2
- type HTTPProviderParams = ProviderParams<'http'>;
3
- declare const HTTP_PROVIDER: Provider<'http'>;
4
- export declare function substituteParamValues(currentParams: HTTPProviderParams, secretParams?: ProviderSecretParams<'http'>, ignoreMissingParams?: boolean): {
5
- newParams: HTTPProviderParams;
6
- extractedValues: {
7
- [_: string]: string;
8
- };
9
- hiddenBodyParts: {
10
- index: number;
11
- length: number;
12
- }[];
13
- hiddenURLParts: {
14
- index: number;
15
- length: number;
16
- }[];
17
- };
18
- export default HTTP_PROVIDER;
@@ -1,640 +0,0 @@
1
- import { areUint8ArraysEqual, concatenateUint8Arrays, uint8ArrayToBinaryStr } from "../../utils/tls-imports.js";
2
- import { encodeBase64 } from "ethers";
3
- import { DEFAULT_HTTPS_PORT, RECLAIM_USER_AGENT } from "../../config/index.js";
4
- import { AttestorVersion } from "../../proto/api.js";
5
- import {
6
- buildHeaders,
7
- convertResponsePosToAbsolutePos,
8
- extractHTMLElementsIndexes,
9
- extractJSONValueIndexes,
10
- getRedactionsForChunkHeaders,
11
- makeRegex,
12
- matchRedactedStrings,
13
- parseHttpResponse
14
- } from "../../providers/http/utils.js";
15
- import { isValidProxySessionId } from "../../utils/generics.js";
16
- import {
17
- findIndexInUint8Array,
18
- getHttpRequestDataFromTranscript,
19
- logger,
20
- REDACTION_CHAR_CODE,
21
- strToUint8Array,
22
- uint8ArrayToStr
23
- } from "../../utils/index.js";
24
- const OK_HTTP_HEADER = "HTTP/1.1 200";
25
- const dateHeaderRegex = "[dD]ate: ((?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), (?:[0-3][0-9]) (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (?:[0-9]{4}) (?:[01][0-9]|2[0-3])(?::[0-5][0-9]){2} GMT)";
26
- const dateDiff = 1e3 * 60 * 10;
27
- const HTTP_PROVIDER = {
28
- hostPort: getHostPort,
29
- writeRedactionMode(params) {
30
- return "writeRedactionMode" in params ? params.writeRedactionMode : void 0;
31
- },
32
- geoLocation(params, secretParams) {
33
- return "geoLocation" in params ? getGeoLocation(params, secretParams) : void 0;
34
- },
35
- proxySessionId(params, secretParams) {
36
- return "proxySessionId" in params ? getProxySessionId(params, secretParams) : void 0;
37
- },
38
- additionalClientOptions(params) {
39
- let defaultOptions = {
40
- applicationLayerProtocols: ["http/1.1"]
41
- };
42
- if ("additionalClientOptions" in params) {
43
- defaultOptions = {
44
- ...defaultOptions,
45
- ...params.additionalClientOptions
46
- };
47
- }
48
- return defaultOptions;
49
- },
50
- createRequest(secretParams, params, logger2) {
51
- if (!secretParams.cookieStr && !secretParams.authorisationHeader && !secretParams.headers) {
52
- throw new Error("auth parameters are not set");
53
- }
54
- const pubHeaders = params.headers || {};
55
- const secHeaders = { ...secretParams.headers };
56
- if (secretParams.cookieStr) {
57
- secHeaders["Cookie"] = secretParams.cookieStr;
58
- }
59
- if (secretParams.authorisationHeader) {
60
- secHeaders["Authorization"] = secretParams.authorisationHeader;
61
- }
62
- const hasUserAgent = Object.keys(pubHeaders).some((k) => k.toLowerCase() === "user-agent") || Object.keys(secHeaders).some((k) => k.toLowerCase() === "user-agent");
63
- if (!hasUserAgent) {
64
- pubHeaders["User-Agent"] = RECLAIM_USER_AGENT;
65
- }
66
- const newParams = substituteParamValues(params, secretParams);
67
- params = newParams.newParams;
68
- const url = new URL(params.url);
69
- const { pathname } = url;
70
- const searchParams = params.url.includes("?") ? params.url.split("?")[1] : "";
71
- logger2.info({ url: params.url, path: pathname, query: searchParams.toString() });
72
- const body = params.body instanceof Uint8Array ? params.body : strToUint8Array(params.body || "");
73
- const contentLength = body.length;
74
- const reqLine = `${params.method} ${pathname}${searchParams?.length ? "?" + searchParams : ""} HTTP/1.1`;
75
- const secHeadersList = buildHeaders(secHeaders);
76
- logger2.info({ requestLine: reqLine });
77
- const httpReqHeaderStr = [
78
- reqLine,
79
- `Host: ${getHostHeaderString(url)}`,
80
- `Content-Length: ${contentLength}`,
81
- "Connection: close",
82
- //no compression
83
- "Accept-Encoding: identity",
84
- ...buildHeaders(pubHeaders),
85
- ...secHeadersList,
86
- "\r\n"
87
- ].join("\r\n");
88
- const headerStr = strToUint8Array(httpReqHeaderStr);
89
- const data = concatenateUint8Arrays([headerStr, body]);
90
- const secHeadersStr = secHeadersList.join("\r\n");
91
- const tokenStartIndex = findIndexInUint8Array(data, strToUint8Array(secHeadersStr));
92
- const redactions = [
93
- {
94
- fromIndex: tokenStartIndex,
95
- toIndex: tokenStartIndex + secHeadersStr.length
96
- }
97
- ];
98
- if (newParams.hiddenBodyParts?.length > 0) {
99
- for (const hiddenBodyPart of newParams.hiddenBodyParts) {
100
- if (hiddenBodyPart.length) {
101
- redactions.push({
102
- fromIndex: headerStr.length + hiddenBodyPart.index,
103
- toIndex: headerStr.length + hiddenBodyPart.index + hiddenBodyPart.length
104
- });
105
- }
106
- }
107
- }
108
- if (newParams.hiddenURLParts?.length > 0) {
109
- for (const hiddenURLPart of newParams.hiddenURLParts) {
110
- if (hiddenURLPart.length) {
111
- redactions.push({
112
- fromIndex: hiddenURLPart.index,
113
- toIndex: hiddenURLPart.index + hiddenURLPart.length
114
- });
115
- }
116
- }
117
- }
118
- redactions.sort((a, b) => a.toIndex - b.toIndex);
119
- return {
120
- data,
121
- redactions
122
- };
123
- },
124
- getResponseRedactions({ response, params: rawParams, logger: logger2, ctx }) {
125
- logger2.debug({ response: encodeBase64(response), params: rawParams });
126
- const res = parseHttpResponse(response);
127
- if (!rawParams.responseRedactions?.length) {
128
- return [];
129
- }
130
- if (res.statusCode / 100 >> 0 !== 2) {
131
- logger2.error({ response: encodeBase64(response), params: rawParams });
132
- throw new Error(
133
- `Expected status 2xx, got ${res.statusCode} (${res.statusMessage})`
134
- );
135
- }
136
- const newParams = substituteParamValues(rawParams, void 0, true);
137
- const params = newParams.newParams;
138
- const headerEndIndex = res.statusLineEndIndex;
139
- const bodyStartIdx = res.bodyStartIndex ?? 0;
140
- if (bodyStartIdx < 4) {
141
- logger2.error({ response: encodeBase64(response) });
142
- throw new Error("Failed to find response body");
143
- }
144
- const reveals = [
145
- { fromIndex: 0, toIndex: headerEndIndex }
146
- ];
147
- if (shouldRevealCrlf(ctx)) {
148
- const crlfs = response.slice(res.headerEndIdx, res.headerEndIdx + 4);
149
- if (!areUint8ArraysEqual(crlfs, strToUint8Array("\r\n\r\n"))) {
150
- logger2.error({ response: encodeBase64(response) });
151
- throw new Error(
152
- `Failed to find header/body separator at index ${res.headerEndIdx}`
153
- );
154
- }
155
- }
156
- reveals.push({ fromIndex: res.headerEndIdx, toIndex: res.headerEndIdx + 4 });
157
- if (res.headerIndices["date"]) {
158
- reveals.push(res.headerIndices["date"]);
159
- }
160
- const body = uint8ArrayToBinaryStr(res.body);
161
- const redactions = [];
162
- for (const rs of params.responseRedactions || []) {
163
- const processor = processRedactionRequest(
164
- body,
165
- rs,
166
- bodyStartIdx,
167
- res.chunks
168
- );
169
- for (const { reveal, redactions: reds } of processor) {
170
- reveals.push(reveal);
171
- redactions.push(...reds);
172
- }
173
- }
174
- reveals.sort((a, b) => a.toIndex - b.toIndex);
175
- if (reveals.length > 1) {
176
- let currentIndex = 0;
177
- for (const r of reveals) {
178
- if (currentIndex < r.fromIndex) {
179
- redactions.push({ fromIndex: currentIndex, toIndex: r.fromIndex });
180
- }
181
- currentIndex = r.toIndex;
182
- }
183
- redactions.push({ fromIndex: currentIndex, toIndex: response.length });
184
- }
185
- for (const r of reveals) {
186
- if (!r.hash) {
187
- continue;
188
- }
189
- redactions.push(r);
190
- }
191
- redactions.sort((a, b) => a.toIndex - b.toIndex);
192
- return redactions;
193
- },
194
- assertValidProviderReceipt({ receipt, params: paramsAny, logger: logger2, ctx }) {
195
- logTranscript();
196
- let extractedParams = {};
197
- const secretParams = "secretParams" in paramsAny ? paramsAny.secretParams : void 0;
198
- const newParams = substituteParamValues(paramsAny, secretParams, !secretParams);
199
- const params = newParams.newParams;
200
- extractedParams = { ...extractedParams, ...newParams.extractedValues };
201
- const req = getHttpRequestDataFromTranscript(receipt);
202
- if (req.method !== params.method.toLowerCase()) {
203
- throw new Error(`Invalid method: ${req.method}`);
204
- }
205
- const url = new URL(params.url);
206
- const { protocol, pathname } = url;
207
- if (protocol !== "https:") {
208
- logger2.error("params URL: %s", params.url);
209
- throw new Error(`Expected protocol: https, found: ${protocol}`);
210
- }
211
- const searchParams = params.url.includes("?") ? params.url.split("?")[1] : "";
212
- const expectedPath = pathname.replaceAll("%7B", "{").replaceAll("%7D", "}") + (searchParams?.length ? "?" + searchParams : "");
213
- if (!matchRedactedStrings(strToUint8Array(expectedPath), strToUint8Array(req.url))) {
214
- logger2.error("params URL: %s", params.url);
215
- throw new Error(`Expected path: ${expectedPath}, found: ${req.url}`);
216
- }
217
- const expectedHostStr = getHostHeaderString(url);
218
- if (req.headers.host !== expectedHostStr) {
219
- throw new Error(`Expected host: ${expectedHostStr}, found: ${req.headers.host}`);
220
- }
221
- const connectionHeader = req.headers["connection"];
222
- if (connectionHeader !== "close") {
223
- throw new Error(`Connection header must be "close", got "${connectionHeader}"`);
224
- }
225
- const serverBlocks = receipt.filter((s) => s.sender === "server").map((r) => r.message).filter((b) => !b.every((b2) => b2 === REDACTION_CHAR_CODE));
226
- const response = concatArrays(...serverBlocks);
227
- let res;
228
- res = uint8ArrayToStr(response);
229
- const okRegex = makeRegex("^HTTP\\/1.1 2\\d{2}");
230
- const matchRes = okRegex.exec(res);
231
- if (!matchRes) {
232
- const statusRegex = makeRegex("^HTTP\\/1.1 (\\d{3})");
233
- const matchRes2 = statusRegex.exec(res);
234
- if (matchRes2 && matchRes2.length > 1) {
235
- throw new Error(`Provider returned error ${matchRes2[1]}`);
236
- }
237
- let lineEnd = res.indexOf("*");
238
- if (lineEnd === -1) {
239
- lineEnd = res.indexOf("\n");
240
- }
241
- if (lineEnd === -1) {
242
- lineEnd = OK_HTTP_HEADER.length;
243
- }
244
- throw new Error(
245
- `Response did not start with "HTTP/1.1 2XX" got "${res.slice(0, lineEnd)}"`
246
- );
247
- }
248
- let bodyStart;
249
- if (shouldRevealCrlf(ctx)) {
250
- bodyStart = res.indexOf("\r\n\r\n", OK_HTTP_HEADER.length) + 4;
251
- if (bodyStart < 4) {
252
- throw new Error("Response body start not found");
253
- }
254
- } else {
255
- bodyStart = OK_HTTP_HEADER.length;
256
- }
257
- const dateHeader = makeRegex(dateHeaderRegex).exec(res);
258
- if (dateHeader && dateHeader.length > 1) {
259
- const serverDate = new Date(dateHeader[1]);
260
- if (Date.now() - serverDate.getTime() > dateDiff) {
261
- logger2.info({ dateHeader: dateHeader[0], current: Date.now() }, "date header is off");
262
- }
263
- }
264
- const paramBody = params.body instanceof Uint8Array ? params.body : strToUint8Array(params.body || "");
265
- if (paramBody.length > 0 && !matchRedactedStrings(paramBody, req.body)) {
266
- throw new Error("request body mismatch");
267
- }
268
- if (!secretParams) {
269
- res = res.slice(bodyStart).replace(/(\*){3,}/g, "");
270
- }
271
- for (const { type, value, invert } of params.responseMatches || []) {
272
- const inv = Boolean(invert);
273
- switch (type) {
274
- case "regex":
275
- const regexRes = makeRegex(value).exec(res);
276
- const match = regexRes !== null;
277
- if (match === inv) {
278
- throw new Error(
279
- `Invalid receipt. Regex "${value}" ${invert ? "matched" : "didn't match"}`
280
- );
281
- }
282
- if (!match) {
283
- continue;
284
- }
285
- const groups = regexRes?.groups;
286
- for (const paramName in groups || []) {
287
- if (paramName in extractedParams) {
288
- throw new Error(`Duplicate parameter ${paramName}`);
289
- }
290
- const value2 = groups?.[paramName];
291
- if (typeof value2 !== "string") {
292
- continue;
293
- }
294
- extractedParams[paramName] = value2;
295
- }
296
- break;
297
- case "contains":
298
- const includes = res.includes(value);
299
- if (includes === inv) {
300
- throw new Error(
301
- `Invalid receipt. Response ${invert ? "contains" : "does not contain"} "${value}"`
302
- );
303
- }
304
- break;
305
- default:
306
- throw new Error(`Invalid response match type ${type}`);
307
- }
308
- }
309
- function concatArrays(...bufs) {
310
- const totalSize = bufs.reduce((acc, e) => acc + e.length, 0);
311
- const merged = new Uint8Array(totalSize);
312
- let lenDone = 0;
313
- for (const array of bufs) {
314
- merged.set(array, lenDone);
315
- lenDone += array.length;
316
- }
317
- return merged;
318
- }
319
- return { extractedParameters: extractedParams };
320
- function logTranscript() {
321
- const clientMsgs = receipt.filter((s) => s.sender === "client").map((m) => m.message);
322
- const serverMsgs = receipt.filter((s) => s.sender === "server").map((m) => m.message);
323
- const clientTranscript = encodeBase64(concatenateUint8Arrays(clientMsgs));
324
- const serverTranscript = encodeBase64(concatenateUint8Arrays(serverMsgs));
325
- logger2.debug({ request: clientTranscript, response: serverTranscript, params: paramsAny });
326
- }
327
- }
328
- };
329
- function shouldRevealCrlf({ version }) {
330
- return version >= AttestorVersion.ATTESTOR_VERSION_2_0_1;
331
- }
332
- function getHostPort(params, secretParams) {
333
- const { host } = new URL(getURL(params, secretParams));
334
- if (!host) {
335
- throw new Error("url is incorrect");
336
- }
337
- return host;
338
- }
339
- function getHostHeaderString(url) {
340
- const host = url.hostname;
341
- const port = url.port;
342
- return port && +port !== DEFAULT_HTTPS_PORT ? `${host}:${port}` : host;
343
- }
344
- const paramsRegex = /{{([^{}]+)}}/sgi;
345
- function* processRedactionRequest(body, rs, bodyStartIdx, resChunks) {
346
- let element = body;
347
- let elementIdx = 0;
348
- let elementLength = -1;
349
- if (rs.xPath) {
350
- const indexes = extractHTMLElementsIndexes(body, rs.xPath, !!rs.jsonPath);
351
- for (const { start, end } of indexes) {
352
- element = body.slice(start, end);
353
- elementIdx = start;
354
- elementLength = end - start;
355
- if (rs.jsonPath) {
356
- yield* processJsonPath();
357
- } else if (rs.regex) {
358
- yield* processRegexp();
359
- } else {
360
- yield* addRedaction();
361
- }
362
- }
363
- } else if (rs.jsonPath) {
364
- yield* processJsonPath();
365
- } else if (rs.regex) {
366
- yield* processRegexp();
367
- } else {
368
- throw new Error(
369
- "Expected either xPath, jsonPath or regex for redaction"
370
- );
371
- }
372
- function* processJsonPath() {
373
- const jsonPathIndexes = extractJSONValueIndexes(element, rs.jsonPath);
374
- const eIndex = elementIdx;
375
- for (const ji of jsonPathIndexes) {
376
- const jStart = ji.start;
377
- const jEnd = ji.end;
378
- element = body.slice(eIndex + jStart, eIndex + jEnd);
379
- elementIdx = eIndex + jStart;
380
- elementLength = jEnd - jStart;
381
- if (rs.regex) {
382
- yield* processRegexp();
383
- } else {
384
- yield* addRedaction();
385
- }
386
- }
387
- }
388
- function* processRegexp() {
389
- logger.debug({
390
- element: encodeBase64(strToUint8Array(element)),
391
- body: encodeBase64(strToUint8Array(body))
392
- });
393
- const regexp = makeRegex(rs.regex);
394
- const elem = element || body;
395
- const match = regexp.exec(elem);
396
- if (!match?.[0]) {
397
- throw new Error(
398
- `regexp ${rs.regex} does not match found element '${encodeBase64(strToUint8Array(elem))}'`
399
- );
400
- }
401
- elementIdx += match.index;
402
- elementLength = regexp.lastIndex - match.index;
403
- element = match[0];
404
- if (rs.hash && (!match.groups || Object.keys(match.groups).length > 1)) {
405
- throw new Error(
406
- "Exactly one named capture group is needed per hashed redaction"
407
- );
408
- }
409
- if (!rs.hash || !match.groups) {
410
- yield* addRedaction();
411
- return;
412
- }
413
- const fullStr = match[0];
414
- const grp = Object.values(match.groups)[0];
415
- const grpIdx = fullStr.indexOf(grp);
416
- elementLength = grpIdx;
417
- element = fullStr.slice(0, grpIdx);
418
- yield* addRedaction(null);
419
- elementIdx += grpIdx;
420
- element = grp;
421
- elementLength = grp.length;
422
- const reveal = getReveal(elementIdx, elementLength, rs.hash);
423
- const chunkReds = getRedactionsForChunkHeaders(reveal.fromIndex, reveal.toIndex, resChunks);
424
- if (chunkReds.length) {
425
- throw new Error(
426
- "Hash redactions cannot be performed if the redacted string is split between 2 or more HTTP chunks"
427
- );
428
- }
429
- yield { reveal, redactions: chunkReds };
430
- elementIdx += grp.length;
431
- element = fullStr.slice(grpIdx + grp.length);
432
- elementLength = element.length;
433
- yield* addRedaction(null);
434
- }
435
- function* addRedaction(hash = rs.hash, _resChunks = resChunks) {
436
- if (elementIdx < 0 || !elementLength) {
437
- return;
438
- }
439
- const reveal = getReveal(elementIdx, elementLength, hash || void 0);
440
- yield {
441
- reveal,
442
- redactions: getRedactionsForChunkHeaders(
443
- reveal.fromIndex,
444
- reveal.toIndex,
445
- _resChunks
446
- )
447
- };
448
- }
449
- function getReveal(startIdx, len, hash) {
450
- const from = convertResponsePosToAbsolutePos(
451
- startIdx,
452
- bodyStartIdx,
453
- resChunks
454
- );
455
- const to = convertResponsePosToAbsolutePos(
456
- startIdx + len,
457
- bodyStartIdx,
458
- resChunks
459
- );
460
- return { fromIndex: from, toIndex: to, hash };
461
- }
462
- }
463
- function substituteParamValues(currentParams, secretParams, ignoreMissingParams) {
464
- const params = JSON.parse(JSON.stringify(currentParams));
465
- let extractedValues = {};
466
- const hiddenURLParts = [];
467
- const urlParams = extractAndReplaceTemplateValues(params.url, ignoreMissingParams);
468
- if (urlParams) {
469
- params.url = urlParams.newParam;
470
- extractedValues = { ...urlParams.extractedValues };
471
- if (urlParams.hiddenParts.length) {
472
- const host = getHostHeaderString(new URL(params.url));
473
- const offset = `https://${host}`.length - currentParams.method.length - 1;
474
- for (const hiddenURLPart of urlParams.hiddenParts) {
475
- hiddenURLParts.push({ index: hiddenURLPart.index - offset, length: hiddenURLPart.length });
476
- }
477
- }
478
- }
479
- let bodyParams;
480
- let hiddenBodyParts = [];
481
- if (params.body) {
482
- const strBody = typeof params.body === "string" ? params.body : uint8ArrayToStr(params.body);
483
- bodyParams = extractAndReplaceTemplateValues(strBody, ignoreMissingParams);
484
- if (bodyParams) {
485
- params.body = bodyParams.newParam;
486
- extractedValues = { ...extractedValues, ...bodyParams.extractedValues };
487
- hiddenBodyParts = bodyParams.hiddenParts;
488
- }
489
- }
490
- const geoParams = extractAndReplaceTemplateValues(params.geoLocation);
491
- if (geoParams) {
492
- params.geoLocation = geoParams.newParam;
493
- extractedValues = { ...extractedValues, ...geoParams.extractedValues };
494
- }
495
- const proxySessionIdParams = extractAndReplaceTemplateValues(params.proxySessionId);
496
- if (proxySessionIdParams) {
497
- params.proxySessionId = proxySessionIdParams.newParam;
498
- extractedValues = { ...extractedValues, ...proxySessionIdParams.extractedValues };
499
- }
500
- if (params.responseRedactions) {
501
- for (const r of params.responseRedactions) {
502
- if (r.regex) {
503
- const regexParams = extractAndReplaceTemplateValues(r.regex);
504
- r.regex = regexParams?.newParam;
505
- }
506
- if (r.xPath) {
507
- const xpathParams = extractAndReplaceTemplateValues(r.xPath);
508
- r.xPath = xpathParams?.newParam;
509
- }
510
- if (r.jsonPath) {
511
- const jsonPathParams = extractAndReplaceTemplateValues(r.jsonPath);
512
- r.jsonPath = jsonPathParams?.newParam;
513
- }
514
- }
515
- }
516
- if (params.responseMatches) {
517
- for (const r of params.responseMatches) {
518
- if (r.value !== "") {
519
- const matchParam = extractAndReplaceTemplateValues(r.value);
520
- r.value = matchParam?.newParam;
521
- extractedValues = { ...extractedValues, ...matchParam?.extractedValues };
522
- }
523
- }
524
- }
525
- return {
526
- newParams: params,
527
- extractedValues,
528
- hiddenBodyParts,
529
- hiddenURLParts
530
- };
531
- function extractAndReplaceTemplateValues(param, ignoreMissingParams2) {
532
- if (!param) {
533
- return null;
534
- }
535
- const extractedValues2 = {};
536
- const hiddenParts = [];
537
- let totalOffset = 0;
538
- param = param.replace(paramsRegex, (match, pn, offset) => {
539
- if (params.paramValues && pn in params.paramValues) {
540
- extractedValues2[pn] = params.paramValues[pn];
541
- totalOffset += params.paramValues[pn].length - match.length;
542
- return params.paramValues[pn];
543
- } else if (secretParams) {
544
- if (secretParams?.paramValues && pn in secretParams?.paramValues) {
545
- hiddenParts.push({
546
- index: offset + totalOffset,
547
- length: secretParams.paramValues[pn].length
548
- });
549
- totalOffset += secretParams.paramValues[pn].length - match.length;
550
- return secretParams.paramValues[pn];
551
- } else {
552
- throw new Error(`parameter's "${pn}" value not found in paramValues and secret parameter's paramValues`);
553
- }
554
- } else {
555
- if (!!!ignoreMissingParams2) {
556
- throw new Error(`parameter's "${pn}" value not found in paramValues`);
557
- } else {
558
- return match;
559
- }
560
- }
561
- });
562
- return {
563
- newParam: param,
564
- extractedValues: extractedValues2,
565
- hiddenParts
566
- };
567
- }
568
- }
569
- function getGeoLocation(v2Params, secretParams) {
570
- if (v2Params?.geoLocation) {
571
- const paramNames = /* @__PURE__ */ new Set();
572
- let geo = v2Params.geoLocation;
573
- let match = null;
574
- while (match = paramsRegex.exec(geo)) {
575
- paramNames.add(match[1]);
576
- }
577
- for (const pn of paramNames) {
578
- if (v2Params.paramValues && pn in v2Params.paramValues) {
579
- geo = geo?.replaceAll(`{{${pn}}}`, v2Params.paramValues[pn].toString());
580
- } else if (secretParams?.paramValues && pn in secretParams.paramValues) {
581
- geo = geo?.replaceAll(`{{${pn}}}`, secretParams.paramValues[pn].toString());
582
- } else {
583
- throw new Error(`parameter "${pn}" value not found in templateParams`);
584
- }
585
- }
586
- const geoRegex = /^[A-Za-z]{2}$/sgiu;
587
- if (!geoRegex.test(geo)) {
588
- throw new Error(`Geolocation ${geo} is invalid`);
589
- }
590
- return geo;
591
- }
592
- return void 0;
593
- }
594
- function getProxySessionId(v2Params, secretParams) {
595
- if (v2Params?.proxySessionId) {
596
- const paramNames = /* @__PURE__ */ new Set();
597
- let proxySessionIdValue = v2Params.proxySessionId;
598
- let match = null;
599
- while (match = paramsRegex.exec(proxySessionIdValue)) {
600
- paramNames.add(match[1]);
601
- }
602
- for (const pn of paramNames) {
603
- if (v2Params.paramValues && pn in v2Params.paramValues) {
604
- proxySessionIdValue = proxySessionIdValue?.replaceAll(`{{${pn}}}`, v2Params.paramValues[pn].toString());
605
- } else if (secretParams?.paramValues && pn in secretParams.paramValues) {
606
- proxySessionIdValue = proxySessionIdValue?.replaceAll(`{{${pn}}}`, secretParams.paramValues[pn].toString());
607
- } else {
608
- throw new Error(`parameter "${pn}" value not found in templateParams`);
609
- }
610
- }
611
- if (!isValidProxySessionId(proxySessionIdValue)) {
612
- throw new Error(`proxySessionId ${proxySessionIdValue} is invalid`);
613
- }
614
- return proxySessionIdValue;
615
- }
616
- return void 0;
617
- }
618
- function getURL(v2Params, secretParams) {
619
- let hostPort = v2Params?.url;
620
- const paramNames = /* @__PURE__ */ new Set();
621
- let match = null;
622
- while (match = paramsRegex.exec(hostPort)) {
623
- paramNames.add(match[1]);
624
- }
625
- for (const pn of paramNames) {
626
- if (v2Params.paramValues && pn in v2Params.paramValues) {
627
- hostPort = hostPort?.replaceAll(`{{${pn}}}`, v2Params.paramValues[pn].toString());
628
- } else if (secretParams?.paramValues && pn in secretParams.paramValues) {
629
- hostPort = hostPort?.replaceAll(`{{${pn}}}`, secretParams.paramValues[pn].toString());
630
- } else {
631
- throw new Error(`parameter "${pn}" value not found in templateParams`);
632
- }
633
- }
634
- return hostPort;
635
- }
636
- var http_default = HTTP_PROVIDER;
637
- export {
638
- http_default as default,
639
- substituteParamValues
640
- };
@@ -1,6 +0,0 @@
1
- import { Node } from 'domhandler';
2
- declare module 'xpath' {
3
- function parse(expr: string): {
4
- select(opts: unknown): Node[];
5
- };
6
- }
@@ -1,34 +0,0 @@
1
- import { Element, Node } from "domhandler";
2
- Element.prototype.toString = function() {
3
- throw new Error("Element.toString() is not supported");
4
- };
5
- Object.defineProperty(Node.prototype, "nodeName", {
6
- get: function() {
7
- return this.name;
8
- }
9
- });
10
- Object.defineProperty(Node.prototype, "localName", {
11
- get: function() {
12
- return this.name;
13
- }
14
- });
15
- const origAttributes = Object.getOwnPropertyDescriptor(
16
- Element.prototype,
17
- "attributes"
18
- )?.get;
19
- if (origAttributes) {
20
- Object.defineProperty(Element.prototype, "attributes", {
21
- get: function(...args) {
22
- const attrs = origAttributes.call(this, ...args);
23
- attrs.item = (idx) => {
24
- const el = attrs[idx];
25
- return { ...el, nodeType: 2, localName: el.name };
26
- };
27
- return attrs;
28
- }
29
- });
30
- } else {
31
- console.warn(
32
- "[WARN] Unable to patch DOM: Element.attributes property descriptor not found"
33
- );
34
- }