@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
@@ -1,5 +1,5 @@
1
- import { ClaimTunnelResponse } from '../proto/api';
2
- import { ClaimID, ClaimInfo, CompleteClaimData, ProviderParams } from '../types';
1
+ import { ClaimTunnelResponse } from '#src/proto/api.ts';
2
+ import type { ClaimID, ClaimInfo, CompleteClaimData, ProviderParams } from '#src/types/index.ts';
3
3
  /**
4
4
  * Creates the standard string to sign for a claim.
5
5
  * This data is what the attestor will sign when it successfully
@@ -16,7 +16,7 @@ export declare function createSignDataForClaim(data: CompleteClaimData): string;
16
16
  * The successful run of this function means that the claim
17
17
  * is valid, and the attestor that signed the claim is valid.
18
18
  */
19
- export declare function assertValidClaimSignatures({ signatures, ...res }: Partial<ClaimTunnelResponse>, metadata?: import("../proto/api").InitRequest): Promise<void>;
19
+ export declare function assertValidClaimSignatures({ signatures, ...res }: Partial<ClaimTunnelResponse>, metadata?: import("#src/proto/api.ts").InitRequest): Promise<void>;
20
20
  /**
21
21
  * Generates a unique identifier for given claim info
22
22
  * @param info
@@ -1,112 +1,89 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createSignDataForClaim = createSignDataForClaim;
7
- exports.assertValidClaimSignatures = assertValidClaimSignatures;
8
- exports.getIdentifierFromClaimInfo = getIdentifierFromClaimInfo;
9
- exports.canonicalStringify = canonicalStringify;
10
- exports.hashProviderParams = hashProviderParams;
11
- const tls_1 = require("@reclaimprotocol/tls");
12
- const canonicalize_1 = __importDefault(require("canonicalize"));
13
- const ethers_1 = require("ethers");
14
- const config_1 = require("../config");
15
- const api_1 = require("../proto/api");
16
- const signatures_1 = require("../utils/signatures");
17
- /**
18
- * Creates the standard string to sign for a claim.
19
- * This data is what the attestor will sign when it successfully
20
- * verifies a claim.
21
- */
1
+ import canonicalize from "canonicalize";
2
+ import { keccak256 } from "ethers";
3
+ import { DEFAULT_METADATA } from "../config/index.js";
4
+ import { ClaimTunnelResponse } from "../proto/api.js";
5
+ import { SIGNATURES, strToUint8Array } from "../utils/index.js";
22
6
  function createSignDataForClaim(data) {
23
- const identifier = 'identifier' in data
24
- ? data.identifier
25
- : getIdentifierFromClaimInfo(data);
26
- const lines = [
27
- identifier,
28
- // we lowercase the owner to ensure that the
29
- // ETH addresses always serialize the same way
30
- data.owner.toLowerCase(),
31
- data.timestampS.toString(),
32
- data.epoch.toString(),
33
- ];
34
- return lines.join('\n');
7
+ const lines = [
8
+ getIdentifierFromClaimInfo(data),
9
+ // we lowercase the owner to ensure that the
10
+ // ETH addresses always serialize the same way
11
+ data.owner.toLowerCase(),
12
+ data.timestampS.toString(),
13
+ data.epoch.toString()
14
+ ];
15
+ return lines.join("\n");
35
16
  }
36
- /**
37
- * Verify the claim tunnel response from a attestor.
38
- *
39
- * If you'd only like to verify the claim signature, you can
40
- * optionally only pass "claim" & "signatures.claimSignature"
41
- * to this function.
42
- *
43
- * The successful run of this function means that the claim
44
- * is valid, and the attestor that signed the claim is valid.
45
- */
46
- async function assertValidClaimSignatures({ signatures, ...res }, metadata = config_1.DEFAULT_METADATA) {
47
- if (!signatures) {
48
- throw new Error('No signatures provided');
49
- }
50
- const { resultSignature, claimSignature, attestorAddress } = signatures;
51
- const { verify } = signatures_1.SIGNATURES[metadata.signatureType];
52
- if (signatures === null || signatures === void 0 ? void 0 : signatures.resultSignature) {
53
- const resBytes = api_1.ClaimTunnelResponse.encode(api_1.ClaimTunnelResponse.create(res)).finish();
54
- const verified = await verify(resBytes, resultSignature, attestorAddress);
55
- if (!verified) {
56
- throw new Error('Invalid result signature');
57
- }
58
- }
59
- // claim wasn't generated -- i.e. the transcript
60
- // did not contain the necessary data
61
- if (!res.claim) {
62
- return;
63
- }
64
- const signData = createSignDataForClaim(res.claim);
65
- const verifiedClaim = await verify((0, tls_1.strToUint8Array)(signData), claimSignature, attestorAddress);
66
- if (!verifiedClaim) {
67
- throw new Error('Invalid claim signature');
17
+ async function assertValidClaimSignatures({
18
+ signatures,
19
+ ...res
20
+ }, metadata = DEFAULT_METADATA) {
21
+ if (!signatures) {
22
+ throw new Error("No signatures provided");
23
+ }
24
+ const {
25
+ resultSignature,
26
+ claimSignature,
27
+ attestorAddress
28
+ } = signatures;
29
+ const { verify } = SIGNATURES[metadata.signatureType];
30
+ if (signatures?.resultSignature) {
31
+ const resBytes = ClaimTunnelResponse.encode(ClaimTunnelResponse.create(res)).finish();
32
+ const verified = await verify(resBytes, resultSignature, attestorAddress);
33
+ if (!verified) {
34
+ throw new Error("Invalid result signature");
68
35
  }
36
+ }
37
+ if (!res.claim) {
38
+ return;
39
+ }
40
+ const signData = createSignDataForClaim(res.claim);
41
+ const verifiedClaim = await verify(
42
+ strToUint8Array(signData),
43
+ claimSignature,
44
+ attestorAddress
45
+ );
46
+ if (!verifiedClaim) {
47
+ throw new Error("Invalid claim signature");
48
+ }
69
49
  }
70
- /**
71
- * Generates a unique identifier for given claim info
72
- * @param info
73
- * @returns
74
- */
75
50
  function getIdentifierFromClaimInfo(info) {
76
- var _a;
77
- //re-canonicalize context if it's not empty
78
- if (((_a = info.context) === null || _a === void 0 ? void 0 : _a.length) > 0) {
79
- try {
80
- const ctx = JSON.parse(info.context);
81
- info.context = canonicalStringify(ctx);
82
- }
83
- catch (e) {
84
- throw new Error('unable to parse non-empty context. Must be JSON');
85
- }
51
+ if (info.context?.length > 0) {
52
+ try {
53
+ const ctx = JSON.parse(info.context);
54
+ info.context = canonicalStringify(ctx);
55
+ } catch {
56
+ throw new Error("unable to parse non-empty context. Must be JSON");
86
57
  }
87
- const str = `${info.provider}\n${info.parameters}\n${info.context || ''}`;
88
- //console.log('Identifier: ' + btoa(str))
89
- return ethers_1.utils.keccak256((0, tls_1.strToUint8Array)(str)).toLowerCase();
58
+ }
59
+ const str = `${info.provider}
60
+ ${info.parameters}
61
+ ${info.context || ""}`;
62
+ return keccak256(strToUint8Array(str)).toLowerCase();
90
63
  }
91
- /**
92
- * Canonically stringifies an object, so that the same object will always
93
- * produce the same string despite the order of keys
94
- */
95
64
  function canonicalStringify(params) {
96
- if (!params) {
97
- return '';
98
- }
99
- return (0, canonicalize_1.default)(params) || '';
65
+ if (!params) {
66
+ return "";
67
+ }
68
+ return canonicalize(params) || "";
100
69
  }
101
70
  function hashProviderParams(params) {
102
- const filteredParams = {
103
- url: params.url,
104
- method: params.method,
105
- body: params.body,
106
- responseMatches: params.responseMatches,
107
- responseRedactions: params.responseRedactions
108
- };
109
- const serializedParams = canonicalStringify(filteredParams);
110
- return ethers_1.utils.keccak256((0, tls_1.strToUint8Array)(serializedParams)).toLowerCase();
71
+ const filteredParams = {
72
+ url: params.url,
73
+ method: params.method,
74
+ body: params.body,
75
+ responseMatches: params.responseMatches,
76
+ responseRedactions: params.responseRedactions
77
+ };
78
+ const serializedParams = canonicalStringify(filteredParams);
79
+ return keccak256(
80
+ strToUint8Array(serializedParams)
81
+ ).toLowerCase();
111
82
  }
112
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xhaW1zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3V0aWxzL2NsYWltcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQWFBLHdEQWNDO0FBWUQsZ0VBK0NDO0FBT0QsZ0VBaUJDO0FBTUQsZ0RBTUM7QUFFRCxnREFhQztBQXpJRCw4Q0FBc0Q7QUFDdEQsZ0VBQXVDO0FBQ3ZDLG1DQUE4QjtBQUM5Qix1Q0FBNkM7QUFDN0MsdUNBQW1EO0FBRW5ELHFEQUFpRDtBQUVqRDs7OztHQUlHO0FBQ0gsU0FBZ0Isc0JBQXNCLENBQUMsSUFBdUI7SUFDN0QsTUFBTSxVQUFVLEdBQUcsWUFBWSxJQUFJLElBQUk7UUFDdEMsQ0FBQyxDQUFDLElBQUksQ0FBQyxVQUFVO1FBQ2pCLENBQUMsQ0FBQywwQkFBMEIsQ0FBQyxJQUFJLENBQUMsQ0FBQTtJQUNuQyxNQUFNLEtBQUssR0FBRztRQUNiLFVBQ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QVEsS0FBSyxJQUFJLENBQUMsVUFBVSxLQUFLLElBQUksQ0FBQyxPQUFPLElBQUksRUFBRSxFQUFFLENBQUE7SUFDekUseUNBQXlDO0lBQ3pDLE9BQU8sY0FBSyxDQUFDLFNBQVMsQ0FDckIsSUFBQSxxQkFBZSxFQUFDLEdBQUcsQ0FBQyxDQUNwQixDQUFDLFdBQVcsRUFBRSxDQUFBO0FBQ2hCLENBQUM7QUFFRDs7O0dBR0c7QUFDSCxTQUFnQixrQkFBa0IsQ0FBQyxNQUEwQztJQUM1RSxJQUFHLENBQUMsTUFBTSxFQUFFLENBQUM7UUFDWixPQUFPLEVBQUUsQ0FBQTtJQUNWLENBQUM7SUFFRCxPQUFPLElBQUEsc0JBQVksRUFBQyxNQUFNLENBQUMsSUFBSSxFQUFFLENBQUE7QUFDbEMsQ0FBQztBQUVELFNBQWdCLGtCQUFrQixDQUFDLE1BQThCO0lBQ2hFLE1BQU0sY0FBYyxHQUFHO1FBQ3RCLEdBQUcsRUFBQyxNQUFNLENBQUMsR0FBRztRQUNkLE1BQU0sRUFBQyxNQUFNLENBQUMsTUFBTTtRQUNwQixJQUFJLEVBQUUsTUFBTSxDQUFDLElBQUk7UUFDakIsZUFBZSxFQUFFLE1BQU0sQ0FBQyxlQUFlO1FBQ3ZDLGtCQUFrQixFQUFFLE1BQU0sQ0FBQyxrQkFBa0I7S0FDN0MsQ0FBQTtJQUVELE1BQU0sZ0JBQWdCLEdBQUcsa0JBQWtCLENBQUMsY0FBYyxDQUFDLENBQUE7SUFDM0QsT0FBTyxjQUFLLENBQUMsU0FBUyxDQUNyQixJQUFBLHFCQUFlLEVBQUMsZ0JBQWdCLENBQUMsQ0FDakMsQ0FBQyxXQUFXLEVBQUUsQ0FBQTtBQUNoQixDQUFDIn0=
83
+ export {
84
+ assertValidClaimSignatures,
85
+ canonicalStringify,
86
+ createSignDataForClaim,
87
+ getIdentifierFromClaimInfo,
88
+ hashProviderParams
89
+ };
package/lib/utils/env.js CHANGED
@@ -1,20 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.detectEnvironment = detectEnvironment;
4
- exports.getEnvVariable = getEnvVariable;
5
1
  function detectEnvironment() {
6
- if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
7
- return 'react-native';
8
- }
9
- if (typeof window !== 'undefined') {
10
- return 'browser';
11
- }
12
- return 'node';
2
+ if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
3
+ return "react-native";
4
+ }
5
+ if (typeof window !== "undefined") {
6
+ return "browser";
7
+ }
8
+ return "node";
13
9
  }
14
10
  function getEnvVariable(name) {
15
- if (typeof process === 'undefined') {
16
- return undefined;
17
- }
18
- return process === null || process === void 0 ? void 0 : process.env[name];
11
+ if (typeof process === "undefined") {
12
+ return void 0;
13
+ }
14
+ return process?.env[name];
19
15
  }
20
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZW52LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3V0aWxzL2Vudi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUVBLDhDQVVDO0FBRUQsd0NBTUM7QUFsQkQsU0FBZ0IsaUJBQWlCO0lBQ2hDLElBQUcsT0FBTyxTQUFTLEtBQUssV0FBVyxJQUFJLFNBQVMsQ0FBQyxPQUFPLEtBQUssYUFBYSxFQUFFLENBQUM7UUFDNUUsT0FBTyxjQUFjLENBQUE7SUFDdEIsQ0FBQztJQUVELElBQUcsT0FBTyxNQUFNLEtBQUssV0FBVyxFQUFFLENBQUM7UUFDbEMsT0FBTyxTQUFTLENBQUE7SUFDakIsQ0FBQztJQUVELE9BQU8sTUFBTSxDQUFBO0FBQ2QsQ0FBQztBQUVELFNBQWdCLGNBQWMsQ0FBQyxJQUFZO0lBQzFDLElBQUcsT0FBTyxPQUFPLEtBQUssV0FBVyxFQUFFLENBQUM7UUFDbkMsT0FBTyxTQUFTLENBQUE7SUFDakIsQ0FBQztJQUVELE9BQU8sT0FBTyxhQUFQLE9BQU8sdUJBQVAsT0FBTyxDQUFFLEdBQUcsQ0FBQyxJQUFJLENBQUMsQ0FBQTtBQUMxQixDQUFDIn0=
16
+ export {
17
+ detectEnvironment,
18
+ getEnvVariable
19
+ };
@@ -1,26 +1,25 @@
1
- import { ErrorCode, ErrorData } from '../proto/api';
1
+ import { ErrorCode, ErrorData } from '#src/proto/api.ts';
2
2
  /**
3
3
  * Represents an error that can be thrown by the Attestor Core
4
4
  * or server. Provides a code, and optional data
5
5
  * to pass along with the error.
6
6
  */
7
7
  export declare class AttestorError extends Error {
8
- code: keyof typeof ErrorCode;
9
- message: string;
10
- data?: {
8
+ readonly name = "AttestorError";
9
+ readonly code: keyof typeof ErrorCode;
10
+ readonly data: {
11
11
  [_: string]: any;
12
12
  } | undefined;
13
- readonly name = "AttestorError";
14
13
  constructor(code: keyof typeof ErrorCode, message: string, data?: {
15
14
  [_: string]: any;
16
- } | undefined);
15
+ });
17
16
  /**
18
17
  * Encodes the error as a ErrorData
19
18
  * protobuf message
20
19
  */
21
20
  toProto(): ErrorData;
22
21
  static fromProto(data?: ErrorData): AttestorError;
23
- static fromError(err: Error): AttestorError;
22
+ static fromError(err: Error, code?: keyof typeof ErrorCode): AttestorError;
24
23
  static badRequest(message: string, data?: {
25
24
  [_: string]: any;
26
25
  }): AttestorError;
@@ -1,43 +1,54 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AttestorError = void 0;
4
- const api_1 = require("../proto/api");
5
- /**
6
- * Represents an error that can be thrown by the Attestor Core
7
- * or server. Provides a code, and optional data
8
- * to pass along with the error.
9
- */
1
+ import { ErrorCode, ErrorData } from "../proto/api.js";
2
+ const PROTO_ERROR = ErrorData.fromJSON({});
10
3
  class AttestorError extends Error {
11
- constructor(code, message, data) {
12
- super(message);
13
- this.code = code;
14
- this.message = message;
15
- this.data = data;
16
- this.name = 'AttestorError';
4
+ name = "AttestorError";
5
+ code;
6
+ data;
7
+ constructor(code, message, data) {
8
+ super(message);
9
+ this.code = code;
10
+ this.data = data;
11
+ }
12
+ /**
13
+ * Encodes the error as a ErrorData
14
+ * protobuf message
15
+ */
16
+ toProto() {
17
+ return ErrorData.create({
18
+ code: ErrorCode[this.code],
19
+ message: this.message,
20
+ data: JSON.stringify(this.data)
21
+ });
22
+ }
23
+ static fromProto(data = PROTO_ERROR) {
24
+ return new AttestorError(
25
+ typeof data.code === "number" ? getKeyForValue(ErrorCode, data.code) || "UNRECOGNIZED" : data.code,
26
+ data.message,
27
+ data.data ? JSON.parse(data.data) : void 0
28
+ );
29
+ }
30
+ static fromError(err, code = "ERROR_INTERNAL") {
31
+ if (err instanceof AttestorError) {
32
+ return err;
17
33
  }
18
- /**
19
- * Encodes the error as a ErrorData
20
- * protobuf message
21
- */
22
- toProto() {
23
- return api_1.ErrorData.create({
24
- code: api_1.ErrorCode[this.code],
25
- message: this.message,
26
- data: JSON.stringify(this.data)
27
- });
28
- }
29
- static fromProto(data = api_1.ErrorData.fromJSON({})) {
30
- return new AttestorError(api_1.ErrorCode[data.code], data.message, data.data ? JSON.parse(data.data) : undefined);
31
- }
32
- static fromError(err) {
33
- if (err instanceof AttestorError) {
34
- return err;
35
- }
36
- return new AttestorError('ERROR_INTERNAL', err.message);
37
- }
38
- static badRequest(message, data) {
39
- return new AttestorError('ERROR_BAD_REQUEST', message, data);
34
+ return new AttestorError(code, err.message);
35
+ }
36
+ static badRequest(message, data) {
37
+ return new AttestorError(
38
+ "ERROR_BAD_REQUEST",
39
+ message,
40
+ data
41
+ );
42
+ }
43
+ }
44
+ function getKeyForValue(obj, value) {
45
+ for (const key in obj) {
46
+ if (obj[key] === value) {
47
+ return key;
40
48
  }
49
+ }
50
+ return void 0;
41
51
  }
42
- exports.AttestorError = AttestorError;
43
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXJyb3IuanMiLCJzb3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FNLENBQUMsU0FBUyxDQUFDLEdBQVU7UUFDMUIsSUFBRyxHQUFHLFlBQVksYUFBYSxFQUFFLENBQUM7WUFDakMsT0FBTyxHQUFHLENBQUE7UUFDWCxDQUFDO1FBRUQsT0FBTyxJQUFJLGFBQWEsQ0FDdkIsZ0JBQWdCLEVBQ2hCLEdBQUcsQ0FBQyxPQUFPLENBQ1gsQ0FBQTtJQUNGLENBQUM7SUFFRCxNQUFNLENBQUMsVUFBVSxDQUFDLE9BQWUsRUFBRSxJQUEyQjtRQUM3RCxPQUFPLElBQUksYUFBYSxDQUN2QixtQkFBbUIsRUFDbkIsT0FBTyxFQUNQLElBQUksQ0FDSixDQUFBO0lBQ0YsQ0FBQztDQUNEO0FBbERELHNDQWtEQyJ9
52
+ export {
53
+ AttestorError
54
+ };
@@ -1,21 +1,22 @@
1
- import { CipherSuite, TLSProtocolVersion } from '@reclaimprotocol/tls';
2
- import { RPCMessage, RPCMessages } from '../proto/api';
3
- import { CompleteTLSPacket, IDecryptedTranscript, IDecryptedTranscriptMessage, ProviderField, RPCEvent, RPCEventMap, RPCEventType, RPCType, Transcript } from '../types';
1
+ import type { CipherSuite, TLSProtocolVersion } from '@reclaimprotocol/tls';
2
+ import { uint8ArrayToBinaryStr } from '#src/utils/tls-imports.ts';
3
+ import { RPCMessage, RPCMessages } from '#src/proto/api.ts';
4
+ import type { CompleteTLSPacket, IDecryptedTranscript, IDecryptedTranscriptMessage, ProviderField, RPCEvent, RPCEventMap, RPCEventType, RPCType, Transcript } from '#src/types/index.ts';
5
+ export { uint8ArrayToBinaryStr };
6
+ /**
7
+ * Decodes a Uint8Array to a UTF-8 string.
8
+ */
4
9
  export declare function uint8ArrayToStr(arr: Uint8Array): string;
10
+ /**
11
+ * Encodes a UTF-8 string to a Uint8Array.
12
+ */
13
+ export declare function strToUint8Array(str: string): Uint8Array;
5
14
  export declare function getTranscriptString(receipt: IDecryptedTranscript): string;
6
15
  export declare const unixTimestampSeconds: () => number;
7
16
  /**
8
17
  * Find index of needle in haystack
9
18
  */
10
19
  export declare function findIndexInUint8Array(haystack: Uint8Array, needle: Uint8Array): number;
11
- /**
12
- * convert a Uint8Array to a binary encoded str
13
- * from: https://github.com/feross/buffer/blob/795bbb5bda1b39f1370ebd784bea6107b087e3a7/index.js#L1063
14
- * @param buf
15
- * @returns
16
- */
17
- export declare function uint8ArrayToBinaryStr(buf: Uint8Array): string;
18
- export declare function gunzipSync(buf: Uint8Array): Uint8Array;
19
20
  /**
20
21
  * Fetch the ZK algorithm for the specified cipher suite
21
22
  */
@@ -100,8 +101,8 @@ export declare function extractHandshakeFromTranscript({ transcript, tlsVersion
100
101
  tlsVersion: TLSProtocolVersion;
101
102
  }): HandshakeTranscript<Uint8Array<ArrayBufferLike>>;
102
103
  export declare function decryptDirect(directReveal: any, cipherSuite: CipherSuite, recordHeader: Uint8Array, serverTlsVersion: TLSProtocolVersion, content: Uint8Array): Promise<{
103
- plaintext: Uint8Array;
104
- iv: Uint8Array;
104
+ plaintext: Uint8Array<ArrayBufferLike>;
105
+ iv: Uint8Array<ArrayBufferLike>;
105
106
  }>;
106
107
  export declare function packRpcMessages(...msgs: Partial<RPCMessage>[]): RPCMessages;
107
108
  /**
@@ -110,3 +111,9 @@ export declare function packRpcMessages(...msgs: Partial<RPCMessage>[]): RPCMess
110
111
  * Required to correctly JSON.stringify the struct.
111
112
  */
112
113
  export declare function ethersStructToPlainObject<T>(struct: T): T;
114
+ export declare function isTls13Suite(suite: CipherSuite): suite is "TLS_CHACHA20_POLY1305_SHA256" | "TLS_AES_256_GCM_SHA384" | "TLS_AES_128_GCM_SHA256";
115
+ /**
116
+ * Validates a proxy session ID format.
117
+ * Must be 8-14 lowercase alphanumeric characters.
118
+ */
119
+ export declare function isValidProxySessionId(sessionId: string): boolean;