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