@reclaimprotocol/attestor-core 4.0.3 → 5.0.1-beta.10

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 (474) hide show
  1. package/LICENSE +660 -660
  2. package/README.md +1 -2
  3. package/lib/avs/abis/avsDirectoryABI.js +341 -342
  4. package/lib/avs/abis/delegationABI.js +4 -5
  5. package/lib/avs/abis/registryABI.js +722 -723
  6. package/lib/avs/client/create-claim-on-avs.d.ts +5 -5
  7. package/lib/avs/client/create-claim-on-avs.js +160 -139
  8. package/lib/avs/config.d.ts +1 -1
  9. package/lib/avs/config.js +25 -23
  10. package/lib/avs/contracts/ReclaimServiceManager.d.ts +436 -532
  11. package/lib/avs/contracts/ReclaimServiceManager.js +0 -3
  12. package/lib/avs/contracts/common.d.ts +40 -11
  13. package/lib/avs/contracts/common.js +0 -3
  14. package/lib/avs/contracts/factories/ReclaimServiceManager__factory.d.ts +13 -11
  15. package/lib/avs/contracts/factories/ReclaimServiceManager__factory.js +1157 -1148
  16. package/lib/avs/contracts/factories/index.d.ts +1 -1
  17. package/lib/avs/contracts/factories/index.js +4 -9
  18. package/lib/avs/contracts/index.d.ts +3 -3
  19. package/lib/avs/contracts/index.js +6 -40
  20. package/lib/avs/types/index.d.ts +6 -6
  21. package/lib/avs/types/index.js +0 -3
  22. package/lib/avs/utils/contracts.d.ts +14 -14
  23. package/lib/avs/utils/contracts.js +50 -35
  24. package/lib/avs/utils/register.d.ts +3 -3
  25. package/lib/avs/utils/register.js +71 -79
  26. package/lib/avs/utils/tasks.d.ts +4 -4
  27. package/lib/avs/utils/tasks.js +44 -41
  28. package/lib/browser/avs/abis/avsDirectoryABI.d.ts +60 -0
  29. package/lib/browser/avs/abis/avsDirectoryABI.js +343 -0
  30. package/lib/browser/avs/abis/delegationABI.d.ts +126 -0
  31. package/lib/browser/avs/abis/delegationABI.js +4 -0
  32. package/lib/browser/avs/abis/registryABI.d.ts +136 -0
  33. package/lib/browser/avs/abis/registryABI.js +728 -0
  34. package/lib/browser/avs/client/create-claim-on-avs.d.ts +12 -0
  35. package/lib/browser/avs/client/create-claim-on-avs.js +168 -0
  36. package/lib/browser/avs/config.d.ts +7 -0
  37. package/lib/browser/avs/config.js +26 -0
  38. package/lib/browser/avs/contracts/ReclaimServiceManager.d.ts +601 -0
  39. package/lib/browser/avs/contracts/ReclaimServiceManager.js +0 -0
  40. package/lib/browser/avs/contracts/common.d.ts +50 -0
  41. package/lib/browser/avs/contracts/common.js +0 -0
  42. package/lib/browser/avs/contracts/factories/ReclaimServiceManager__factory.d.ts +890 -0
  43. package/lib/browser/avs/contracts/factories/ReclaimServiceManager__factory.js +1183 -0
  44. package/lib/browser/avs/contracts/factories/index.d.ts +1 -0
  45. package/lib/browser/avs/contracts/factories/index.js +4 -0
  46. package/lib/browser/avs/contracts/index.d.ts +3 -0
  47. package/lib/browser/avs/contracts/index.js +6 -0
  48. package/lib/browser/avs/types/index.d.ts +55 -0
  49. package/lib/browser/avs/types/index.js +0 -0
  50. package/lib/browser/avs/utils/contracts.d.ts +21 -0
  51. package/lib/browser/avs/utils/contracts.js +53 -0
  52. package/lib/browser/avs/utils/register.d.ts +27 -0
  53. package/lib/browser/avs/utils/register.js +74 -0
  54. package/lib/browser/avs/utils/tasks.d.ts +22 -0
  55. package/lib/browser/avs/utils/tasks.js +48 -0
  56. package/lib/browser/client/create-claim.d.ts +5 -0
  57. package/lib/browser/client/create-claim.js +461 -0
  58. package/lib/browser/client/index.d.ts +3 -0
  59. package/lib/browser/client/index.js +3 -0
  60. package/lib/browser/client/tunnels/make-rpc-tcp-tunnel.d.ts +16 -0
  61. package/lib/browser/client/tunnels/make-rpc-tcp-tunnel.js +53 -0
  62. package/lib/browser/client/tunnels/make-rpc-tls-tunnel.d.ts +26 -0
  63. package/lib/browser/client/tunnels/make-rpc-tls-tunnel.js +127 -0
  64. package/lib/browser/client/utils/attestor-pool.d.ts +8 -0
  65. package/lib/browser/client/utils/attestor-pool.js +24 -0
  66. package/lib/browser/client/utils/client-socket.d.ts +11 -0
  67. package/lib/browser/client/utils/client-socket.js +120 -0
  68. package/lib/browser/client/utils/message-handler.d.ts +4 -0
  69. package/lib/browser/client/utils/message-handler.js +97 -0
  70. package/lib/browser/config/index.d.ts +31 -0
  71. package/lib/browser/config/index.js +62 -0
  72. package/lib/browser/external-rpc/benchmark.d.ts +1 -0
  73. package/lib/browser/external-rpc/benchmark.js +82 -0
  74. package/lib/browser/external-rpc/event-bus.d.ts +7 -0
  75. package/lib/browser/external-rpc/event-bus.js +17 -0
  76. package/lib/browser/external-rpc/global.d.js +0 -0
  77. package/lib/browser/external-rpc/handle-incoming-msg.d.ts +2 -0
  78. package/lib/browser/external-rpc/handle-incoming-msg.js +241 -0
  79. package/lib/browser/external-rpc/index.d.ts +3 -0
  80. package/lib/browser/external-rpc/index.js +3 -0
  81. package/lib/browser/external-rpc/jsc-polyfills/1.d.ts +14 -0
  82. package/lib/browser/external-rpc/jsc-polyfills/1.js +80 -0
  83. package/lib/browser/external-rpc/jsc-polyfills/2.js +15 -0
  84. package/lib/browser/external-rpc/jsc-polyfills/event.d.ts +10 -0
  85. package/lib/browser/external-rpc/jsc-polyfills/event.js +19 -0
  86. package/lib/browser/external-rpc/jsc-polyfills/index.d.ts +2 -0
  87. package/lib/browser/external-rpc/jsc-polyfills/index.js +2 -0
  88. package/lib/browser/external-rpc/jsc-polyfills/ws.d.ts +21 -0
  89. package/lib/browser/external-rpc/jsc-polyfills/ws.js +83 -0
  90. package/lib/browser/external-rpc/setup-browser.d.ts +6 -0
  91. package/lib/browser/external-rpc/setup-browser.js +33 -0
  92. package/lib/browser/external-rpc/setup-jsc.d.ts +24 -0
  93. package/lib/browser/external-rpc/setup-jsc.js +22 -0
  94. package/lib/{window-rpc → browser/external-rpc}/types.d.ts +56 -35
  95. package/lib/browser/external-rpc/types.js +0 -0
  96. package/lib/browser/external-rpc/utils.d.ts +20 -0
  97. package/lib/browser/external-rpc/utils.js +100 -0
  98. package/lib/browser/external-rpc/zk.d.ts +14 -0
  99. package/lib/browser/external-rpc/zk.js +58 -0
  100. package/lib/browser/index.browser.js +13 -0
  101. package/lib/browser/index.d.ts +9 -0
  102. package/lib/browser/index.js +13 -0
  103. package/lib/browser/mechain/abis/governanceABI.d.ts +50 -0
  104. package/lib/browser/mechain/abis/governanceABI.js +461 -0
  105. package/lib/browser/mechain/abis/taskABI.d.ts +157 -0
  106. package/lib/browser/mechain/abis/taskABI.js +512 -0
  107. package/lib/browser/mechain/client/create-claim-on-mechain.d.ts +10 -0
  108. package/lib/browser/mechain/client/create-claim-on-mechain.js +33 -0
  109. package/lib/browser/mechain/client/index.d.ts +1 -0
  110. package/lib/browser/mechain/client/index.js +1 -0
  111. package/lib/browser/mechain/constants/index.d.ts +3 -0
  112. package/lib/browser/mechain/constants/index.js +8 -0
  113. package/lib/browser/mechain/index.d.ts +2 -0
  114. package/lib/browser/mechain/index.js +2 -0
  115. package/lib/browser/mechain/types/index.d.ts +23 -0
  116. package/lib/browser/mechain/types/index.js +0 -0
  117. package/lib/browser/proto/api.d.ts +651 -0
  118. package/lib/browser/proto/api.js +4250 -0
  119. package/lib/browser/proto/tee-bundle.d.ts +156 -0
  120. package/lib/browser/proto/tee-bundle.js +1296 -0
  121. package/lib/browser/providers/http/index.d.ts +18 -0
  122. package/lib/browser/providers/http/index.js +640 -0
  123. package/lib/browser/providers/http/patch-parse5-tree.d.ts +6 -0
  124. package/lib/browser/providers/http/patch-parse5-tree.js +34 -0
  125. package/lib/browser/providers/http/utils.d.ts +77 -0
  126. package/lib/browser/providers/http/utils.js +283 -0
  127. package/lib/browser/providers/index.d.ts +4 -0
  128. package/lib/browser/providers/index.js +7 -0
  129. package/lib/browser/scripts/fallbacks/crypto.js +4 -0
  130. package/lib/browser/scripts/fallbacks/empty.js +4 -0
  131. package/lib/browser/scripts/fallbacks/gnark.js +15 -0
  132. package/lib/browser/scripts/fallbacks/re2.js +7 -0
  133. package/lib/browser/scripts/fallbacks/snarkjs.js +10 -0
  134. package/lib/browser/scripts/fallbacks/stwo.js +159 -0
  135. package/lib/browser/types/bgp.d.ts +11 -0
  136. package/lib/browser/types/bgp.js +0 -0
  137. package/lib/browser/types/claims.d.ts +70 -0
  138. package/lib/browser/types/claims.js +0 -0
  139. package/lib/browser/types/client.d.ts +163 -0
  140. package/lib/browser/types/client.js +0 -0
  141. package/lib/browser/types/general.d.ts +77 -0
  142. package/lib/browser/types/general.js +0 -0
  143. package/lib/browser/types/handlers.d.ts +10 -0
  144. package/lib/browser/types/handlers.js +0 -0
  145. package/lib/browser/types/index.d.ts +10 -0
  146. package/lib/browser/types/index.js +10 -0
  147. package/lib/browser/types/providers.d.ts +161 -0
  148. package/lib/browser/types/providers.gen.d.ts +443 -0
  149. package/lib/browser/types/providers.gen.js +16 -0
  150. package/lib/browser/types/providers.js +0 -0
  151. package/lib/browser/types/rpc.d.ts +35 -0
  152. package/lib/browser/types/rpc.js +0 -0
  153. package/lib/browser/types/signatures.d.ts +28 -0
  154. package/lib/browser/types/signatures.js +0 -0
  155. package/lib/browser/types/tunnel.d.ts +18 -0
  156. package/lib/browser/types/tunnel.js +0 -0
  157. package/lib/browser/types/zk.d.ts +38 -0
  158. package/lib/browser/types/zk.js +0 -0
  159. package/lib/browser/utils/auth.d.ts +8 -0
  160. package/lib/browser/utils/auth.js +71 -0
  161. package/lib/browser/utils/b64-json.d.ts +2 -0
  162. package/lib/browser/utils/b64-json.js +17 -0
  163. package/lib/browser/utils/claims.d.ts +33 -0
  164. package/lib/browser/utils/claims.js +89 -0
  165. package/lib/browser/utils/env.d.ts +3 -0
  166. package/lib/browser/utils/env.js +19 -0
  167. package/lib/browser/utils/error.d.ts +26 -0
  168. package/lib/browser/utils/error.js +54 -0
  169. package/lib/browser/utils/generics.d.ts +119 -0
  170. package/lib/browser/utils/generics.js +272 -0
  171. package/lib/browser/utils/http-parser.d.ts +59 -0
  172. package/lib/browser/utils/http-parser.js +201 -0
  173. package/lib/browser/utils/index.browser.js +13 -0
  174. package/lib/browser/utils/index.d.ts +13 -0
  175. package/lib/browser/utils/index.js +13 -0
  176. package/lib/browser/utils/logger.browser.js +88 -0
  177. package/lib/browser/utils/logger.d.ts +14 -0
  178. package/lib/browser/utils/logger.js +88 -0
  179. package/lib/browser/utils/prepare-packets.d.ts +16 -0
  180. package/lib/browser/utils/prepare-packets.js +69 -0
  181. package/lib/browser/utils/redactions.d.ts +73 -0
  182. package/lib/browser/utils/redactions.js +135 -0
  183. package/lib/browser/utils/retries.d.ts +12 -0
  184. package/lib/browser/utils/retries.js +26 -0
  185. package/lib/browser/utils/signatures/eth.d.ts +2 -0
  186. package/lib/browser/utils/signatures/eth.js +31 -0
  187. package/lib/browser/utils/signatures/index.d.ts +5 -0
  188. package/lib/browser/utils/signatures/index.js +12 -0
  189. package/lib/browser/utils/socket-base.d.ts +23 -0
  190. package/lib/browser/utils/socket-base.js +96 -0
  191. package/lib/browser/utils/tls-imports.d.ts +21 -0
  192. package/lib/browser/utils/tls-imports.js +71 -0
  193. package/lib/browser/utils/tls.d.ts +2 -0
  194. package/lib/browser/utils/tls.js +58 -0
  195. package/lib/browser/utils/ws.d.ts +7 -0
  196. package/lib/browser/utils/ws.js +22 -0
  197. package/lib/browser/utils/zk.d.ts +71 -0
  198. package/lib/browser/utils/zk.js +625 -0
  199. package/lib/client/create-claim.d.ts +2 -2
  200. package/lib/client/create-claim.js +437 -400
  201. package/lib/client/index.d.ts +3 -3
  202. package/lib/client/index.js +3 -20
  203. package/lib/client/tunnels/make-rpc-tcp-tunnel.d.ts +2 -2
  204. package/lib/client/tunnels/make-rpc-tcp-tunnel.js +49 -56
  205. package/lib/client/tunnels/make-rpc-tls-tunnel.d.ts +4 -3
  206. package/lib/client/tunnels/make-rpc-tls-tunnel.js +123 -131
  207. package/lib/client/utils/attestor-pool.d.ts +3 -1
  208. package/lib/client/utils/attestor-pool.js +21 -25
  209. package/lib/client/utils/client-socket.d.ts +4 -4
  210. package/lib/client/utils/client-socket.js +114 -94
  211. package/lib/client/utils/message-handler.d.ts +2 -2
  212. package/lib/client/utils/message-handler.js +89 -86
  213. package/lib/config/index.d.ts +6 -3
  214. package/lib/config/index.js +60 -37
  215. package/lib/external-rpc/benchmark.d.ts +1 -0
  216. package/lib/external-rpc/benchmark.js +82 -0
  217. package/lib/external-rpc/event-bus.d.ts +7 -0
  218. package/lib/external-rpc/event-bus.js +17 -0
  219. package/lib/external-rpc/global.d.js +0 -0
  220. package/lib/external-rpc/handle-incoming-msg.d.ts +2 -0
  221. package/lib/external-rpc/handle-incoming-msg.js +241 -0
  222. package/lib/external-rpc/index.d.ts +3 -0
  223. package/lib/external-rpc/index.js +3 -0
  224. package/lib/external-rpc/jsc-polyfills/1.d.ts +14 -0
  225. package/lib/external-rpc/jsc-polyfills/1.js +80 -0
  226. package/lib/external-rpc/jsc-polyfills/2.js +15 -0
  227. package/lib/external-rpc/jsc-polyfills/event.d.ts +10 -0
  228. package/lib/external-rpc/jsc-polyfills/event.js +19 -0
  229. package/lib/external-rpc/jsc-polyfills/index.d.ts +2 -0
  230. package/lib/external-rpc/jsc-polyfills/index.js +2 -0
  231. package/lib/external-rpc/jsc-polyfills/ws.d.ts +21 -0
  232. package/lib/external-rpc/jsc-polyfills/ws.js +83 -0
  233. package/lib/external-rpc/setup-browser.d.ts +6 -0
  234. package/lib/external-rpc/setup-browser.js +33 -0
  235. package/lib/external-rpc/setup-jsc.d.ts +24 -0
  236. package/lib/external-rpc/setup-jsc.js +22 -0
  237. package/lib/external-rpc/types.d.ts +213 -0
  238. package/lib/external-rpc/types.js +0 -0
  239. package/lib/external-rpc/utils.d.ts +20 -0
  240. package/lib/external-rpc/utils.js +100 -0
  241. package/lib/external-rpc/zk.d.ts +14 -0
  242. package/lib/external-rpc/zk.js +58 -0
  243. package/lib/index.browser.d.ts +9 -0
  244. package/lib/index.d.ts +8 -9
  245. package/lib/index.js +12 -49
  246. package/lib/mechain/abis/governanceABI.js +460 -461
  247. package/lib/mechain/abis/taskABI.js +505 -506
  248. package/lib/mechain/client/create-claim-on-mechain.d.ts +3 -3
  249. package/lib/mechain/client/create-claim-on-mechain.js +31 -30
  250. package/lib/mechain/client/index.d.ts +1 -1
  251. package/lib/mechain/client/index.js +1 -18
  252. package/lib/mechain/constants/index.js +8 -7
  253. package/lib/mechain/index.d.ts +2 -2
  254. package/lib/mechain/index.js +2 -19
  255. package/lib/mechain/types/index.d.ts +2 -2
  256. package/lib/mechain/types/index.js +0 -3
  257. package/lib/proto/api.d.ts +182 -39
  258. package/lib/proto/api.js +4105 -3555
  259. package/lib/proto/tee-bundle.d.ts +156 -0
  260. package/lib/proto/tee-bundle.js +1296 -0
  261. package/lib/providers/http/index.d.ts +16 -1
  262. package/lib/providers/http/index.js +603 -576
  263. package/lib/providers/http/patch-parse5-tree.d.ts +6 -0
  264. package/lib/providers/http/patch-parse5-tree.js +34 -0
  265. package/lib/providers/http/utils.d.ts +7 -4
  266. package/lib/providers/http/utils.js +240 -317
  267. package/lib/providers/index.d.ts +1 -1
  268. package/lib/providers/index.js +5 -9
  269. package/lib/scripts/check-avs-registration.d.ts +1 -1
  270. package/lib/scripts/check-avs-registration.js +24 -25
  271. package/lib/scripts/fallbacks/crypto.d.ts +1 -0
  272. package/lib/scripts/fallbacks/crypto.js +4 -0
  273. package/lib/scripts/fallbacks/empty.d.ts +3 -0
  274. package/lib/scripts/fallbacks/empty.js +4 -0
  275. package/lib/scripts/fallbacks/gnark.d.ts +7 -0
  276. package/lib/scripts/fallbacks/gnark.js +15 -0
  277. package/lib/scripts/fallbacks/re2.d.ts +1 -0
  278. package/lib/scripts/fallbacks/re2.js +7 -0
  279. package/lib/scripts/fallbacks/snarkjs.d.ts +1 -0
  280. package/lib/scripts/fallbacks/snarkjs.js +10 -0
  281. package/lib/scripts/fallbacks/stwo.d.ts +6 -0
  282. package/lib/scripts/generate-provider-types.js +92 -73
  283. package/lib/scripts/generate-receipt.d.ts +2 -2
  284. package/lib/scripts/generate-receipt.js +94 -83
  285. package/lib/scripts/generate-toprf-keys.js +17 -16
  286. package/lib/scripts/jsc-cli-rpc.d.ts +1 -0
  287. package/lib/scripts/jsc-cli-rpc.js +35 -0
  288. package/lib/scripts/register-avs-operator.d.ts +1 -1
  289. package/lib/scripts/register-avs-operator.js +3 -7
  290. package/lib/scripts/start-server.d.ts +1 -1
  291. package/lib/scripts/start-server.js +9 -11
  292. package/lib/scripts/update-avs-metadata.d.ts +1 -1
  293. package/lib/scripts/update-avs-metadata.js +17 -19
  294. package/lib/scripts/utils.js +8 -9
  295. package/lib/scripts/whitelist-operator.d.ts +1 -1
  296. package/lib/scripts/whitelist-operator.js +13 -15
  297. package/lib/server/create-server.d.ts +3 -2
  298. package/lib/server/create-server.js +98 -85
  299. package/lib/server/handlers/claimTeeBundle.d.ts +6 -0
  300. package/lib/server/handlers/claimTeeBundle.js +232 -0
  301. package/lib/server/handlers/claimTunnel.d.ts +1 -1
  302. package/lib/server/handlers/claimTunnel.js +75 -73
  303. package/lib/server/handlers/completeClaimOnChain.d.ts +1 -1
  304. package/lib/server/handlers/completeClaimOnChain.js +27 -26
  305. package/lib/server/handlers/createClaimOnChain.d.ts +1 -1
  306. package/lib/server/handlers/createClaimOnChain.js +30 -29
  307. package/lib/server/handlers/createTaskOnMechain.d.ts +1 -1
  308. package/lib/server/handlers/createTaskOnMechain.js +54 -49
  309. package/lib/server/handlers/createTunnel.d.ts +1 -1
  310. package/lib/server/handlers/createTunnel.js +91 -94
  311. package/lib/server/handlers/disconnectTunnel.d.ts +1 -1
  312. package/lib/server/handlers/disconnectTunnel.js +6 -8
  313. package/lib/server/handlers/fetchCertificateBytes.d.ts +2 -0
  314. package/lib/server/handlers/fetchCertificateBytes.js +57 -0
  315. package/lib/server/handlers/index.d.ts +1 -1
  316. package/lib/server/handlers/index.js +24 -21
  317. package/lib/server/handlers/init.d.ts +1 -1
  318. package/lib/server/handlers/init.js +31 -34
  319. package/lib/server/handlers/toprf.d.ts +1 -1
  320. package/lib/server/handlers/toprf.js +17 -19
  321. package/lib/server/index.d.ts +4 -4
  322. package/lib/server/index.js +4 -21
  323. package/lib/server/socket.d.ts +7 -7
  324. package/lib/server/socket.js +104 -106
  325. package/lib/server/tunnels/make-tcp-tunnel.d.ts +5 -3
  326. package/lib/server/tunnels/make-tcp-tunnel.js +189 -162
  327. package/lib/server/utils/apm.d.ts +1 -1
  328. package/lib/server/utils/apm.js +26 -40
  329. package/lib/server/utils/assert-valid-claim-request.d.ts +6 -5
  330. package/lib/server/utils/assert-valid-claim-request.js +339 -185
  331. package/lib/server/utils/config-env.js +4 -7
  332. package/lib/server/utils/dns.js +18 -16
  333. package/lib/server/utils/gcp-attestation.d.ts +17 -0
  334. package/lib/server/utils/gcp-attestation.js +237 -0
  335. package/lib/server/utils/generics.d.ts +3 -3
  336. package/lib/server/utils/generics.js +37 -51
  337. package/lib/server/utils/iso.js +255 -256
  338. package/lib/server/utils/keep-alive.d.ts +2 -2
  339. package/lib/server/utils/keep-alive.js +36 -40
  340. package/lib/server/utils/nitro-attestation.d.ts +33 -0
  341. package/lib/server/utils/nitro-attestation.js +249 -0
  342. package/lib/server/utils/oprf-raw.d.ts +21 -0
  343. package/lib/server/utils/oprf-raw.js +61 -0
  344. package/lib/server/utils/process-handshake.d.ts +3 -3
  345. package/lib/server/utils/process-handshake.js +217 -175
  346. package/lib/server/utils/proxy-session.d.ts +1 -0
  347. package/lib/server/utils/proxy-session.js +4 -0
  348. package/lib/server/utils/tee-oprf-mpc-verification.d.ts +16 -0
  349. package/lib/server/utils/tee-oprf-mpc-verification.js +86 -0
  350. package/lib/server/utils/tee-oprf-verification.d.ts +24 -0
  351. package/lib/server/utils/tee-oprf-verification.js +151 -0
  352. package/lib/server/utils/tee-transcript-reconstruction.d.ts +24 -0
  353. package/lib/server/utils/tee-transcript-reconstruction.js +140 -0
  354. package/lib/server/utils/tee-verification.d.ts +28 -0
  355. package/lib/server/utils/tee-verification.js +358 -0
  356. package/lib/{utils → server/utils}/validation.d.ts +1 -1
  357. package/lib/server/utils/validation.js +45 -0
  358. package/lib/types/bgp.js +0 -3
  359. package/lib/types/claims.d.ts +7 -10
  360. package/lib/types/claims.js +0 -3
  361. package/lib/types/client.d.ts +5 -5
  362. package/lib/types/client.js +0 -3
  363. package/lib/types/general.d.ts +30 -4
  364. package/lib/types/general.js +0 -3
  365. package/lib/types/handlers.d.ts +3 -3
  366. package/lib/types/handlers.js +0 -3
  367. package/lib/types/index.d.ts +10 -10
  368. package/lib/types/index.js +10 -27
  369. package/lib/types/providers.d.ts +15 -4
  370. package/lib/types/providers.gen.d.ts +15 -1
  371. package/lib/types/providers.gen.js +15 -13
  372. package/lib/types/providers.js +0 -3
  373. package/lib/types/rpc.d.ts +2 -2
  374. package/lib/types/rpc.js +0 -3
  375. package/lib/types/signatures.js +0 -3
  376. package/lib/types/tunnel.d.ts +2 -2
  377. package/lib/types/tunnel.js +0 -3
  378. package/lib/types/zk.d.ts +17 -2
  379. package/lib/types/zk.js +0 -3
  380. package/lib/utils/auth.d.ts +2 -1
  381. package/lib/utils/auth.js +66 -59
  382. package/lib/utils/b64-json.js +13 -19
  383. package/lib/utils/bgp-listener.d.ts +1 -1
  384. package/lib/utils/bgp-listener.js +111 -114
  385. package/lib/utils/claims.d.ts +3 -3
  386. package/lib/utils/claims.js +78 -101
  387. package/lib/utils/env.js +15 -16
  388. package/lib/utils/error.d.ts +6 -7
  389. package/lib/utils/error.js +50 -39
  390. package/lib/utils/generics.d.ts +20 -13
  391. package/lib/utils/generics.js +221 -297
  392. package/lib/utils/http-parser.d.ts +1 -1
  393. package/lib/utils/http-parser.js +186 -237
  394. package/lib/utils/index.browser.d.ts +13 -0
  395. package/lib/utils/index.d.ts +14 -12
  396. package/lib/utils/index.js +14 -29
  397. package/lib/utils/logger.browser.d.ts +14 -0
  398. package/lib/utils/logger.d.ts +1 -1
  399. package/lib/utils/logger.js +69 -87
  400. package/lib/utils/prepare-packets.d.ts +3 -3
  401. package/lib/utils/prepare-packets.js +66 -58
  402. package/lib/utils/redactions.d.ts +20 -1
  403. package/lib/utils/redactions.js +116 -129
  404. package/lib/utils/retries.d.ts +1 -1
  405. package/lib/utils/retries.js +24 -26
  406. package/lib/utils/signatures/eth.d.ts +1 -1
  407. package/lib/utils/signatures/eth.js +28 -30
  408. package/lib/utils/signatures/index.d.ts +3 -3
  409. package/lib/utils/signatures/index.js +11 -10
  410. package/lib/utils/socket-base.d.ts +6 -5
  411. package/lib/utils/socket-base.js +89 -88
  412. package/lib/utils/tls-imports.d.ts +21 -0
  413. package/lib/utils/tls-imports.js +71 -0
  414. package/lib/utils/tls.d.ts +1 -1
  415. package/lib/utils/tls.js +54 -28
  416. package/lib/utils/ws.d.ts +1 -6
  417. package/lib/utils/ws.js +17 -33
  418. package/lib/utils/zk.d.ts +28 -12
  419. package/lib/utils/zk.js +587 -406
  420. package/package.json +79 -60
  421. package/lib/avs/tests/test.operator.d.ts +0 -11
  422. package/lib/avs/tests/test.operator.js +0 -313
  423. package/lib/avs/tests/utils.d.ts +0 -2
  424. package/lib/avs/tests/utils.js +0 -50
  425. package/lib/scripts/verify-root-ca.d.ts +0 -1
  426. package/lib/scripts/verify-root-ca.js +0 -51
  427. package/lib/tests/describe-with-server.d.ts +0 -20
  428. package/lib/tests/describe-with-server.js +0 -64
  429. package/lib/tests/mock-provider-server.d.ts +0 -13
  430. package/lib/tests/mock-provider-server.js +0 -65
  431. package/lib/tests/mocks.d.ts +0 -4
  432. package/lib/tests/mocks.js +0 -23
  433. package/lib/tests/test.auth.js +0 -75
  434. package/lib/tests/test.bgp-listener.js +0 -169
  435. package/lib/tests/test.claim-creation.js +0 -280
  436. package/lib/tests/test.http-parser.d.ts +0 -1
  437. package/lib/tests/test.http-parser.js +0 -120
  438. package/lib/tests/test.http-provider-utils.js +0 -2416
  439. package/lib/tests/test.http-provider.js +0 -114
  440. package/lib/tests/test.rpc-communication.d.ts +0 -1
  441. package/lib/tests/test.rpc-communication.js +0 -64
  442. package/lib/tests/test.rpc-tunnel.d.ts +0 -1
  443. package/lib/tests/test.rpc-tunnel.js +0 -172
  444. package/lib/tests/test.signatures.d.ts +0 -1
  445. package/lib/tests/test.signatures.js +0 -24
  446. package/lib/tests/test.tcp-tunnel.d.ts +0 -1
  447. package/lib/tests/test.tcp-tunnel.js +0 -64
  448. package/lib/tests/test.zk.d.ts +0 -1
  449. package/lib/tests/test.zk.js +0 -337
  450. package/lib/tests/utils.d.ts +0 -18
  451. package/lib/tests/utils.js +0 -64
  452. package/lib/utils/atomic-operations.d.ts +0 -24
  453. package/lib/utils/atomic-operations.js +0 -65
  454. package/lib/utils/benchmark.d.ts +0 -1
  455. package/lib/utils/benchmark.js +0 -70
  456. package/lib/utils/connection-state-machine.d.ts +0 -43
  457. package/lib/utils/connection-state-machine.js +0 -129
  458. package/lib/utils/resource-monitor.d.ts +0 -61
  459. package/lib/utils/resource-monitor.js +0 -107
  460. package/lib/utils/validation.js +0 -46
  461. package/lib/window-rpc/index.d.ts +0 -3
  462. package/lib/window-rpc/index.js +0 -20
  463. package/lib/window-rpc/setup-window-rpc.d.ts +0 -5
  464. package/lib/window-rpc/setup-window-rpc.js +0 -291
  465. package/lib/window-rpc/types.js +0 -3
  466. package/lib/window-rpc/utils.d.ts +0 -14
  467. package/lib/window-rpc/utils.js +0 -102
  468. package/lib/window-rpc/window-rpc-zk.d.ts +0 -15
  469. package/lib/window-rpc/window-rpc-zk.js +0 -85
  470. /package/lib/{tests/test.auth.d.ts → browser/external-rpc/jsc-polyfills/2.d.ts} +0 -0
  471. /package/lib/{tests/test.bgp-listener.d.ts → external-rpc/jsc-polyfills/2.d.ts} +0 -0
  472. /package/lib/{tests/test.claim-creation.d.ts → scripts/build-browser.d.ts} +0 -0
  473. /package/lib/{tests/test.http-provider-utils.d.ts → scripts/build-jsc.d.ts} +0 -0
  474. /package/lib/{tests/test.http-provider.d.ts → scripts/build-lib.d.ts} +0 -0
@@ -0,0 +1,443 @@
1
+ type BinaryData = Uint8Array | string;
2
+ export interface HttpProviderParameters {
3
+ /**
4
+ * which URL does the request have to be made to Has to be a valid https URL for eg. https://amazon.in/orders?q=abcd
5
+ */
6
+ url: string;
7
+ method: "GET" | "POST" | "PUT" | "PATCH";
8
+ /**
9
+ * Specify the geographical location from where to proxy the request. 2-letter ISO country code or parameter (public or secret)
10
+ */
11
+ geoLocation?: string;
12
+ /**
13
+ * Specify the unique session id for allowing use of same proxy ip across multiple requests. Can be a smallcase alphanumeric string of length 8-14 characters. eg. "mystring12345", "something1234".
14
+ */
15
+ proxySessionId?: string;
16
+ /**
17
+ * Any additional headers to be sent with the request Note: these will be revealed to the attestor & won't be redacted from the transcript. To add hidden headers, use 'secretParams.headers' instead
18
+ */
19
+ headers?: {
20
+ [k: string]: string;
21
+ };
22
+ /**
23
+ * Body of the HTTP request
24
+ */
25
+ body?: BinaryData;
26
+ /**
27
+ * If the API doesn't perform well with the "key-update" method of redaction, you can switch to "zk" mode by setting this to "zk"
28
+ */
29
+ writeRedactionMode?: "zk" | "key-update";
30
+ /**
31
+ * Apply TLS configuration when creating the tunnel to the attestor.
32
+ */
33
+ additionalClientOptions?: {
34
+ /**
35
+ * @minItems 1
36
+ */
37
+ supportedProtocolVersions?: ("TLS1_2" | "TLS1_3")[];
38
+ };
39
+ /**
40
+ * The attestor will use this list to check that the redacted response does indeed match all the provided strings/regexes
41
+ *
42
+ * @minItems 1
43
+ */
44
+ responseMatches: {
45
+ /**
46
+ * "regex": the response must match the regex "contains": the response must contain the provided
47
+ * string exactly
48
+ */
49
+ value: string;
50
+ /**
51
+ * The string/regex to match against
52
+ */
53
+ type: "regex" | "contains";
54
+ /**
55
+ * Inverses the matching logic. Fail when match is found and proceed otherwise
56
+ */
57
+ invert?: boolean;
58
+ }[];
59
+ /**
60
+ * which portions to select from a response. These are selected in order, xpath => jsonPath => regex * These redactions are done client side and only the selected portions are sent to the attestor. The attestor will only be able to see the selected portions alongside the first line of the HTTP response (i.e. "HTTP/1.1 200 OK") * To disable any redactions, pass an empty array
61
+ */
62
+ responseRedactions?: {
63
+ /**
64
+ * expect an HTML response, and to contain a certain xpath for eg. "/html/body/div.a1/div.a2/span.a5"
65
+ */
66
+ xPath?: string;
67
+ /**
68
+ * expect a JSON response, retrieve the item at this path using dot notation for e.g. 'email.addresses.0'
69
+ */
70
+ jsonPath?: string;
71
+ /**
72
+ * select a regex match from the response
73
+ */
74
+ regex?: string;
75
+ /**
76
+ * If provided, the value inside will be hashed instead of being redacted. Useful for cases where the data inside is an identifiying piece of information that you don't want to reveal to the attestor, eg. an email address.
77
+ * If the hash function produces more bytes than the original value, the hash will be truncated.
78
+ * Eg. if hash is enabled, the original value is "hello", and hashed is "a1b2c", then the attestor will only see "a1b2c".
79
+ * Note: if a regex with named groups is provided, only the named groups will be hashed.
80
+ */
81
+ hash?: "oprf" | "oprf-mpc" | "oprf-raw";
82
+ }[];
83
+ /**
84
+ * A map of parameter values which are user in form of {{param}} in URL, responseMatches, responseRedactions, body, geolocation. Those in URL, responseMatches & geo will be put into context and signed This value will NOT be included in provider hash
85
+ */
86
+ paramValues?: {
87
+ [k: string]: string;
88
+ };
89
+ }
90
+ export declare const HttpProviderParametersJson: {
91
+ title: string;
92
+ type: string;
93
+ required: string[];
94
+ properties: {
95
+ url: {
96
+ type: string;
97
+ format: string;
98
+ description: string;
99
+ };
100
+ method: {
101
+ type: string;
102
+ enum: string[];
103
+ };
104
+ geoLocation: {
105
+ type: string;
106
+ nullable: boolean;
107
+ description: string;
108
+ };
109
+ proxySessionId: {
110
+ type: string;
111
+ nullable: boolean;
112
+ description: string;
113
+ };
114
+ headers: {
115
+ type: string;
116
+ description: string;
117
+ additionalProperties: {
118
+ type: string;
119
+ };
120
+ };
121
+ body: {
122
+ description: string;
123
+ oneOf: ({
124
+ type: string;
125
+ format: string;
126
+ } | {
127
+ type: string;
128
+ format?: undefined;
129
+ })[];
130
+ };
131
+ writeRedactionMode: {
132
+ type: string;
133
+ description: string;
134
+ enum: string[];
135
+ };
136
+ additionalClientOptions: {
137
+ type: string;
138
+ description: string;
139
+ nullable: boolean;
140
+ properties: {
141
+ supportedProtocolVersions: {
142
+ type: string;
143
+ minItems: number;
144
+ uniqueItems: boolean;
145
+ items: {
146
+ type: string;
147
+ enum: string[];
148
+ };
149
+ };
150
+ };
151
+ };
152
+ responseMatches: {
153
+ type: string;
154
+ minItems: number;
155
+ uniqueItems: boolean;
156
+ description: string;
157
+ items: {
158
+ type: string;
159
+ required: string[];
160
+ properties: {
161
+ value: {
162
+ type: string;
163
+ description: string;
164
+ };
165
+ type: {
166
+ type: string;
167
+ description: string;
168
+ enum: string[];
169
+ };
170
+ invert: {
171
+ type: string;
172
+ description: string;
173
+ };
174
+ };
175
+ additionalProperties: boolean;
176
+ };
177
+ };
178
+ responseRedactions: {
179
+ type: string;
180
+ uniqueItems: boolean;
181
+ description: string;
182
+ items: {
183
+ type: string;
184
+ properties: {
185
+ xPath: {
186
+ type: string;
187
+ nullable: boolean;
188
+ description: string;
189
+ };
190
+ jsonPath: {
191
+ type: string;
192
+ nullable: boolean;
193
+ description: string;
194
+ };
195
+ regex: {
196
+ type: string;
197
+ nullable: boolean;
198
+ description: string;
199
+ };
200
+ hash: {
201
+ type: string;
202
+ description: string;
203
+ enum: string[];
204
+ };
205
+ };
206
+ additionalProperties: boolean;
207
+ };
208
+ };
209
+ paramValues: {
210
+ type: string;
211
+ description: string;
212
+ additionalProperties: {
213
+ type: string;
214
+ };
215
+ };
216
+ };
217
+ additionalProperties: boolean;
218
+ };
219
+ /**
220
+ * Secret parameters to be used with HTTP provider. None of the values in this object will be shown to the attestor
221
+ */
222
+ export interface HttpProviderSecretParameters {
223
+ /**
224
+ * cookie string for authorisation.
225
+ */
226
+ cookieStr?: string;
227
+ /**
228
+ * authorisation header value
229
+ */
230
+ authorisationHeader?: string;
231
+ /**
232
+ * Headers that need to be hidden from the attestor
233
+ */
234
+ headers?: {
235
+ [k: string]: string;
236
+ };
237
+ /**
238
+ * A map of parameter values which are user in form of {{param}} in body these parameters will NOT be shown to attestor and extracted
239
+ */
240
+ paramValues?: {
241
+ [k: string]: string;
242
+ };
243
+ }
244
+ export declare const HttpProviderSecretParametersJson: {
245
+ title: string;
246
+ type: string;
247
+ description: string;
248
+ properties: {
249
+ cookieStr: {
250
+ type: string;
251
+ description: string;
252
+ };
253
+ authorisationHeader: {
254
+ type: string;
255
+ description: string;
256
+ };
257
+ headers: {
258
+ type: string;
259
+ description: string;
260
+ additionalProperties: {
261
+ type: string;
262
+ };
263
+ };
264
+ paramValues: {
265
+ type: string;
266
+ description: string;
267
+ additionalProperties: {
268
+ type: string;
269
+ };
270
+ };
271
+ };
272
+ additionalProperties: boolean;
273
+ };
274
+ export interface ProvidersConfig {
275
+ http: {
276
+ parameters: HttpProviderParameters;
277
+ secretParameters: HttpProviderSecretParameters;
278
+ };
279
+ }
280
+ export declare const PROVIDER_SCHEMAS: {
281
+ http: {
282
+ parameters: {
283
+ title: string;
284
+ type: string;
285
+ required: string[];
286
+ properties: {
287
+ url: {
288
+ type: string;
289
+ format: string;
290
+ description: string;
291
+ };
292
+ method: {
293
+ type: string;
294
+ enum: string[];
295
+ };
296
+ geoLocation: {
297
+ type: string;
298
+ nullable: boolean;
299
+ description: string;
300
+ };
301
+ proxySessionId: {
302
+ type: string;
303
+ nullable: boolean;
304
+ description: string;
305
+ };
306
+ headers: {
307
+ type: string;
308
+ description: string;
309
+ additionalProperties: {
310
+ type: string;
311
+ };
312
+ };
313
+ body: {
314
+ description: string;
315
+ oneOf: ({
316
+ type: string;
317
+ format: string;
318
+ } | {
319
+ type: string;
320
+ format?: undefined;
321
+ })[];
322
+ };
323
+ writeRedactionMode: {
324
+ type: string;
325
+ description: string;
326
+ enum: string[];
327
+ };
328
+ additionalClientOptions: {
329
+ type: string;
330
+ description: string;
331
+ nullable: boolean;
332
+ properties: {
333
+ supportedProtocolVersions: {
334
+ type: string;
335
+ minItems: number;
336
+ uniqueItems: boolean;
337
+ items: {
338
+ type: string;
339
+ enum: string[];
340
+ };
341
+ };
342
+ };
343
+ };
344
+ responseMatches: {
345
+ type: string;
346
+ minItems: number;
347
+ uniqueItems: boolean;
348
+ description: string;
349
+ items: {
350
+ type: string;
351
+ required: string[];
352
+ properties: {
353
+ value: {
354
+ type: string;
355
+ description: string;
356
+ };
357
+ type: {
358
+ type: string;
359
+ description: string;
360
+ enum: string[];
361
+ };
362
+ invert: {
363
+ type: string;
364
+ description: string;
365
+ };
366
+ };
367
+ additionalProperties: boolean;
368
+ };
369
+ };
370
+ responseRedactions: {
371
+ type: string;
372
+ uniqueItems: boolean;
373
+ description: string;
374
+ items: {
375
+ type: string;
376
+ properties: {
377
+ xPath: {
378
+ type: string;
379
+ nullable: boolean;
380
+ description: string;
381
+ };
382
+ jsonPath: {
383
+ type: string;
384
+ nullable: boolean;
385
+ description: string;
386
+ };
387
+ regex: {
388
+ type: string;
389
+ nullable: boolean;
390
+ description: string;
391
+ };
392
+ hash: {
393
+ type: string;
394
+ description: string;
395
+ enum: string[];
396
+ };
397
+ };
398
+ additionalProperties: boolean;
399
+ };
400
+ };
401
+ paramValues: {
402
+ type: string;
403
+ description: string;
404
+ additionalProperties: {
405
+ type: string;
406
+ };
407
+ };
408
+ };
409
+ additionalProperties: boolean;
410
+ };
411
+ secretParameters: {
412
+ title: string;
413
+ type: string;
414
+ description: string;
415
+ properties: {
416
+ cookieStr: {
417
+ type: string;
418
+ description: string;
419
+ };
420
+ authorisationHeader: {
421
+ type: string;
422
+ description: string;
423
+ };
424
+ headers: {
425
+ type: string;
426
+ description: string;
427
+ additionalProperties: {
428
+ type: string;
429
+ };
430
+ };
431
+ paramValues: {
432
+ type: string;
433
+ description: string;
434
+ additionalProperties: {
435
+ type: string;
436
+ };
437
+ };
438
+ };
439
+ additionalProperties: boolean;
440
+ };
441
+ };
442
+ };
443
+ export {};
@@ -0,0 +1,16 @@
1
+ const HttpProviderParametersJson = { "title": "HttpProviderParameters", "type": "object", "required": ["url", "method", "responseMatches"], "properties": { "url": { "type": "string", "format": "url", "description": "which URL does the request have to be made to Has to be a valid https URL for eg. https://amazon.in/orders?q=abcd" }, "method": { "type": "string", "enum": ["GET", "POST", "PUT", "PATCH"] }, "geoLocation": { "type": "string", "nullable": true, "description": "Specify the geographical location from where to proxy the request. 2-letter ISO country code or parameter (public or secret)" }, "proxySessionId": { "type": "string", "nullable": true, "description": 'Specify the unique session id for allowing use of same proxy ip across multiple requests. Can be a smallcase alphanumeric string of length 8-14 characters. eg. "mystring12345", "something1234".' }, "headers": { "type": "object", "description": "Any additional headers to be sent with the request Note: these will be revealed to the attestor & won't be redacted from the transcript. To add hidden headers, use 'secretParams.headers' instead", "additionalProperties": { "type": "string" } }, "body": { "description": "Body of the HTTP request", "oneOf": [{ "type": "string", "format": "binary" }, { "type": "string" }] }, "writeRedactionMode": { "type": "string", "description": `If the API doesn't perform well with the "key-update" method of redaction, you can switch to "zk" mode by setting this to "zk"`, "enum": ["zk", "key-update"] }, "additionalClientOptions": { "type": "object", "description": "Apply TLS configuration when creating the tunnel to the attestor.", "nullable": true, "properties": { "supportedProtocolVersions": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "enum": ["TLS1_2", "TLS1_3"] } } } }, "responseMatches": { "type": "array", "minItems": 1, "uniqueItems": true, "description": "The attestor will use this list to check that the redacted response does indeed match all the provided strings/regexes", "items": { "type": "object", "required": ["value", "type"], "properties": { "value": { "type": "string", "description": '"regex": the response must match the regex "contains": the response must contain the provided\n string exactly' }, "type": { "type": "string", "description": "The string/regex to match against", "enum": ["regex", "contains"] }, "invert": { "type": "boolean", "description": "Inverses the matching logic. Fail when match is found and proceed otherwise" } }, "additionalProperties": false } }, "responseRedactions": { "type": "array", "uniqueItems": true, "description": 'which portions to select from a response. These are selected in order, xpath => jsonPath => regex * These redactions are done client side and only the selected portions are sent to the attestor. The attestor will only be able to see the selected portions alongside the first line of the HTTP response (i.e. "HTTP/1.1 200 OK") * To disable any redactions, pass an empty array', "items": { "type": "object", "properties": { "xPath": { "type": "string", "nullable": true, "description": 'expect an HTML response, and to contain a certain xpath for eg. "/html/body/div.a1/div.a2/span.a5"' }, "jsonPath": { "type": "string", "nullable": true, "description": "expect a JSON response, retrieve the item at this path using dot notation for e.g. 'email.addresses.0'" }, "regex": { "type": "string", "nullable": true, "description": "select a regex match from the response" }, "hash": { "type": "string", "description": `If provided, the value inside will be hashed instead of being redacted. Useful for cases where the data inside is an identifiying piece of information that you don't want to reveal to the attestor, eg. an email address.
2
+ If the hash function produces more bytes than the original value, the hash will be truncated.
3
+ Eg. if hash is enabled, the original value is "hello", and hashed is "a1b2c", then the attestor will only see "a1b2c".
4
+ Note: if a regex with named groups is provided, only the named groups will be hashed.`, "enum": ["oprf", "oprf-mpc", "oprf-raw"] } }, "additionalProperties": false } }, "paramValues": { "type": "object", "description": "A map of parameter values which are user in form of {{param}} in URL, responseMatches, responseRedactions, body, geolocation. Those in URL, responseMatches & geo will be put into context and signed This value will NOT be included in provider hash", "additionalProperties": { "type": "string" } } }, "additionalProperties": false };
5
+ const HttpProviderSecretParametersJson = { "title": "HttpProviderSecretParameters", "type": "object", "description": "Secret parameters to be used with HTTP provider. None of the values in this object will be shown to the attestor", "properties": { "cookieStr": { "type": "string", "description": "cookie string for authorisation." }, "authorisationHeader": { "type": "string", "description": "authorisation header value" }, "headers": { "type": "object", "description": "Headers that need to be hidden from the attestor", "additionalProperties": { "type": "string" } }, "paramValues": { "type": "object", "description": "A map of parameter values which are user in form of {{param}} in body these parameters will NOT be shown to attestor and extracted", "additionalProperties": { "type": "string" } } }, "additionalProperties": false };
6
+ const PROVIDER_SCHEMAS = {
7
+ http: {
8
+ parameters: HttpProviderParametersJson,
9
+ secretParameters: HttpProviderSecretParametersJson
10
+ }
11
+ };
12
+ export {
13
+ HttpProviderParametersJson,
14
+ HttpProviderSecretParametersJson,
15
+ PROVIDER_SCHEMAS
16
+ };
File without changes
@@ -0,0 +1,35 @@
1
+ import type { RPCMessage, TunnelDisconnectEvent, TunnelMessage } from '#src/proto/api.ts';
2
+ import type { AttestorError } from '#src/utils/error.ts';
3
+ type ExtractPrefix<T, S extends string> = T extends `${infer _}${S}` ? _ : never;
4
+ export type RPCType = ExtractPrefix<keyof RPCMessage, 'Request'>;
5
+ type RPCRequestType<T extends RPCType> = `${T}Request`;
6
+ type RPCResponseType<T extends RPCType> = `${T}Response`;
7
+ export type RPCRequestData<T extends RPCType> = Exclude<RPCMessage[RPCRequestType<T>], undefined>;
8
+ export type RPCResponseData<T extends RPCType> = Exclude<RPCMessage[RPCResponseType<T>], undefined>;
9
+ export type RPCRequest<T extends RPCType> = {
10
+ requestId: RPCMessage['id'];
11
+ type: T;
12
+ data: RPCRequestData<T>;
13
+ respond(res: RPCResponseData<T> | AttestorError): void;
14
+ };
15
+ export type RPCResponse<T extends RPCType> = {
16
+ id: RPCMessage['id'];
17
+ type: T;
18
+ data: RPCResponseData<T>;
19
+ } | {
20
+ id: RPCMessage['id'];
21
+ error: AttestorError;
22
+ };
23
+ export type RPCEventMap = {
24
+ 'connection-terminated': AttestorError;
25
+ 'tunnel-message': TunnelMessage;
26
+ 'tunnel-disconnect-event': TunnelDisconnectEvent;
27
+ 'rpc-request': RPCRequest<RPCType>;
28
+ 'rpc-response': RPCResponse<RPCType>;
29
+ };
30
+ export type RPCEventType = keyof RPCEventMap;
31
+ export interface RPCEvent<T extends RPCEventType> extends Event {
32
+ type: T;
33
+ data: RPCEventMap[T];
34
+ }
35
+ export {};
File without changes
@@ -0,0 +1,28 @@
1
+ export type PrivateKey = string;
2
+ type Awaitable<T> = T | Promise<T>;
3
+ export type ServiceSignatureProvider = {
4
+ /**
5
+ * Returns public key in compressed (compact) format used in Reclaim RPC calls
6
+ * @param privateKey corresponding private key in raw o hex form
7
+ */
8
+ getPublicKey(privateKey: PrivateKey): Uint8Array;
9
+ /**
10
+ * Returns address corresponding to the provided public key
11
+ * @param publicKey raw o hex form, compressed or uncompressed
12
+ */
13
+ getAddress(publicKey: Uint8Array): string;
14
+ /**
15
+ * Signs data with the provided private key
16
+ * @param data raw data to be signed
17
+ * @param privateKey private key in raw or hex format
18
+ */
19
+ sign(data: Uint8Array, privateKey: PrivateKey): Awaitable<Uint8Array>;
20
+ /**
21
+ * Verifies signature against provided data and an address
22
+ * @param data raw data to be verified. Must be same as used in sign() call
23
+ * @param signature signature bytes or string
24
+ * @param addressBytes address corresponding to a public key
25
+ */
26
+ verify(data: Uint8Array, signature: Uint8Array | string, addressBytes: Uint8Array | string): Awaitable<boolean>;
27
+ };
28
+ export {};
File without changes
@@ -0,0 +1,18 @@
1
+ import type { CreateTunnelRequest } from '#src/proto/api.ts';
2
+ export type MakeTunnelBaseOpts<O> = O & {
3
+ onClose?(err?: Error): void;
4
+ onMessage?(data: Uint8Array): void;
5
+ };
6
+ export type Tunnel<E> = E & {
7
+ write(data: Uint8Array): void | Promise<void>;
8
+ close(err?: Error): void | Promise<void>;
9
+ };
10
+ export type MakeTunnelFn<O, E = {}> = (opts: MakeTunnelBaseOpts<O>) => (Tunnel<E> | Promise<Tunnel<E>>);
11
+ export type Transcript<T> = {
12
+ sender: 'client' | 'server';
13
+ message: T;
14
+ }[];
15
+ export type TCPSocketProperties = {
16
+ transcript: Transcript<Uint8Array>;
17
+ createRequest: Pick<CreateTunnelRequest, 'host' | 'port' | 'geoLocation' | 'proxySessionId'>;
18
+ };
File without changes
@@ -0,0 +1,38 @@
1
+ import type { EncryptionAlgorithm, OPRFOperator, ZKEngine, ZKOperator } from '@reclaimprotocol/zk-symmetric-crypto';
2
+ import type { TOPRFPayload } from '#src/proto/api.ts';
3
+ export type ZKOperators = {
4
+ [E in EncryptionAlgorithm]?: ZKOperator;
5
+ };
6
+ export type OPRFOperators = {
7
+ [E in EncryptionAlgorithm]?: OPRFOperator;
8
+ };
9
+ export type PrepareZKProofsBaseOpts = {
10
+ /** get ZK operator for specified algorithm */
11
+ zkOperators?: ZKOperators;
12
+ oprfOperators?: OPRFOperators;
13
+ /**
14
+ * max number of ZK proofs to generate concurrently
15
+ * @default 10
16
+ */
17
+ zkProofConcurrency?: number;
18
+ zkEngine?: ZKEngine;
19
+ };
20
+ export type TOPRFProofParams = TOPRFPayload & {
21
+ mask: Uint8Array;
22
+ plaintext: Uint8Array;
23
+ overshoot?: {
24
+ ciphertext: Uint8Array;
25
+ iv: Uint8Array;
26
+ recordNumber: number;
27
+ };
28
+ };
29
+ /**
30
+ * Marker for server-side OPRF computation (oprf-raw mode).
31
+ * Data is revealed to attestor who computes OPRF directly.
32
+ */
33
+ export type OPRFRawMarker = {
34
+ dataLocation: {
35
+ fromIndex: number;
36
+ length: number;
37
+ };
38
+ };
File without changes
@@ -0,0 +1,8 @@
1
+ import type { AuthenticationRequest, ServiceSignatureType } from '#src/proto/api.ts';
2
+ import { AuthenticatedUserData } from '#src/proto/api.ts';
3
+ export declare function assertValidAuthRequest(request: AuthenticationRequest | undefined, signatureType: ServiceSignatureType): Promise<void>;
4
+ /**
5
+ * Create an authentication request with the given data and private key,
6
+ * which can then be used to authenticate with the service.
7
+ */
8
+ export declare function createAuthRequest(_data: Partial<AuthenticatedUserData>, privateKey: string): Promise<AuthenticationRequest>;
@@ -0,0 +1,71 @@
1
+ import { getBytes } from "ethers";
2
+ import { DEFAULT_AUTH_EXPIRY_S } from "../config/index.js";
3
+ import { AuthenticatedUserData } from "../proto/api.js";
4
+ import { getEnvVariable } from "../utils/env.js";
5
+ import { AttestorError } from "../utils/error.js";
6
+ import { unixTimestampSeconds } from "../utils/generics.js";
7
+ import { SelectedServiceSignature, SIGNATURES } from "../utils/signatures/index.js";
8
+ async function assertValidAuthRequest(request, signatureType) {
9
+ const publicKey = getEnvVariable("AUTHENTICATION_PUBLIC_KEY");
10
+ if (!request) {
11
+ if (publicKey) {
12
+ throw new AttestorError(
13
+ "ERROR_AUTHENTICATION_FAILED",
14
+ "User must be authenticated"
15
+ );
16
+ }
17
+ return;
18
+ }
19
+ if (!publicKey) {
20
+ throw new AttestorError(
21
+ "ERROR_BAD_REQUEST",
22
+ "The attestor is not configured for authentication"
23
+ );
24
+ }
25
+ const { signature, data } = request;
26
+ if (!data) {
27
+ throw new AttestorError(
28
+ "ERROR_AUTHENTICATION_FAILED",
29
+ "Missing data in auth request"
30
+ );
31
+ }
32
+ if (data.expiresAt < unixTimestampSeconds()) {
33
+ throw new AttestorError(
34
+ "ERROR_AUTHENTICATION_FAILED",
35
+ "Authentication request has expired"
36
+ );
37
+ }
38
+ const proto = AuthenticatedUserData.encode(data).finish();
39
+ const signatureAlg = SIGNATURES[signatureType];
40
+ const address = signatureAlg.getAddress(
41
+ getBytes(publicKey)
42
+ );
43
+ const verified = await signatureAlg.verify(proto, signature, address);
44
+ if (!verified) {
45
+ throw new AttestorError(
46
+ "ERROR_AUTHENTICATION_FAILED",
47
+ "Signature verification failed"
48
+ );
49
+ }
50
+ }
51
+ async function createAuthRequest(_data, privateKey) {
52
+ const createdAt = unixTimestampSeconds();
53
+ const data = {
54
+ createdAt,
55
+ expiresAt: createdAt + DEFAULT_AUTH_EXPIRY_S,
56
+ id: "",
57
+ hostWhitelist: [],
58
+ ..._data
59
+ };
60
+ const proto = AuthenticatedUserData.encode(data).finish();
61
+ const signature = await SelectedServiceSignature.sign(proto, privateKey);
62
+ const request = {
63
+ data,
64
+ signature
65
+ };
66
+ return request;
67
+ }
68
+ export {
69
+ assertValidAuthRequest,
70
+ createAuthRequest
71
+ };