@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,77 @@
|
|
|
1
|
+
import '#src/providers/http/patch-parse5-tree.ts';
|
|
2
|
+
import RE2 from "../../scripts/fallbacks/re2.js";
|
|
3
|
+
import type { ArraySlice, CompleteTLSPacket, ProviderParams, Transcript } from '#src/types/index.ts';
|
|
4
|
+
import type { HttpRequest, HttpResponse } from '#src/utils/index.ts';
|
|
5
|
+
export type JSONIndex = {
|
|
6
|
+
start: number;
|
|
7
|
+
end: number;
|
|
8
|
+
};
|
|
9
|
+
type HTTPProviderParams = ProviderParams<'http'>;
|
|
10
|
+
/**
|
|
11
|
+
* Returns only first extracted element
|
|
12
|
+
* @param html
|
|
13
|
+
* @param xpathExpression
|
|
14
|
+
* @param contentsOnly
|
|
15
|
+
*/
|
|
16
|
+
export declare function extractHTMLElement(html: string, xpathExpression: string, contentsOnly: boolean): string;
|
|
17
|
+
/**
|
|
18
|
+
* Returns all extracted elements
|
|
19
|
+
* @param html
|
|
20
|
+
* @param xpathExpression
|
|
21
|
+
* @param contentsOnly
|
|
22
|
+
*/
|
|
23
|
+
export declare function extractHTMLElements(html: string, xpathExpression: string, contentsOnly: boolean): string[];
|
|
24
|
+
/**
|
|
25
|
+
* returns a single index of extracted element
|
|
26
|
+
* @param html
|
|
27
|
+
* @param xpathExpression
|
|
28
|
+
* @param contentsOnly
|
|
29
|
+
*/
|
|
30
|
+
export declare function extractHTMLElementIndex(html: string, xpathExpression: string, contentsOnly: boolean): {
|
|
31
|
+
start: number;
|
|
32
|
+
end: number;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Returns indexes of all extracted elements
|
|
36
|
+
* @param html
|
|
37
|
+
* @param xpathExpression
|
|
38
|
+
* @param contentsOnly indices of the start and end of the element's contents only,
|
|
39
|
+
* not the whole tag
|
|
40
|
+
*/
|
|
41
|
+
export declare function extractHTMLElementsIndexes(html: string, xpathExpression: string, contentsOnly: boolean): {
|
|
42
|
+
start: number;
|
|
43
|
+
end: number;
|
|
44
|
+
}[];
|
|
45
|
+
export declare function extractJSONValueIndex(json: string, jsonPath: string): {
|
|
46
|
+
start: number;
|
|
47
|
+
end: number;
|
|
48
|
+
};
|
|
49
|
+
export declare function extractJSONValueIndexes(json: string, jsonPath: string): {
|
|
50
|
+
start: number;
|
|
51
|
+
end: number;
|
|
52
|
+
}[];
|
|
53
|
+
export declare function buildHeaders(input: HTTPProviderParams['headers']): string[];
|
|
54
|
+
/**
|
|
55
|
+
* Converts position in HTTP response body to an absolute position in TLS transcript considering chunked encoding
|
|
56
|
+
* @param pos
|
|
57
|
+
* @param bodyStartIdx
|
|
58
|
+
* @param chunks
|
|
59
|
+
*/
|
|
60
|
+
export declare function convertResponsePosToAbsolutePos(pos: number, bodyStartIdx: number, chunks?: ArraySlice[]): number;
|
|
61
|
+
/**
|
|
62
|
+
* If this reveal spans the boundary of two chunks, we'll
|
|
63
|
+
*
|
|
64
|
+
*/
|
|
65
|
+
export declare function getRedactionsForChunkHeaders(from: number, to: number, chunks?: ArraySlice[]): ArraySlice[];
|
|
66
|
+
export declare function parseHttpResponse(buff: Uint8Array): HttpResponse;
|
|
67
|
+
export declare function makeRegex(str: string): RE2;
|
|
68
|
+
/**
|
|
69
|
+
* Try to match strings that contain templates like {{param}}
|
|
70
|
+
* against redacted string that has *** instead of that param
|
|
71
|
+
*/
|
|
72
|
+
export declare function matchRedactedStrings(templateString: Uint8Array, redactedString?: Uint8Array): boolean;
|
|
73
|
+
export declare function generateRequstAndResponseFromTranscript(transcript: Transcript<CompleteTLSPacket>, tlsVersion: string): {
|
|
74
|
+
req: HttpRequest;
|
|
75
|
+
res: HttpResponse;
|
|
76
|
+
};
|
|
77
|
+
export {};
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import "../../providers/http/patch-parse5-tree.js";
|
|
2
|
+
import { concatenateUint8Arrays } from "../../utils/tls-imports.js";
|
|
3
|
+
import {
|
|
4
|
+
ArrayExpression,
|
|
5
|
+
ExpressionStatement,
|
|
6
|
+
ObjectExpression,
|
|
7
|
+
parseScript,
|
|
8
|
+
Property,
|
|
9
|
+
Syntax
|
|
10
|
+
} from "esprima-next";
|
|
11
|
+
import { JSONPath } from "jsonpath-plus";
|
|
12
|
+
import { parse } from "parse5";
|
|
13
|
+
import { adapter as htmlAdapter } from "parse5-htmlparser2-tree-adapter";
|
|
14
|
+
import RE2 from "../../scripts/fallbacks/re2.js";
|
|
15
|
+
import xpath from "xpath";
|
|
16
|
+
import { getHttpRequestDataFromTranscript, isApplicationData, makeHttpResponseParser, REDACTION_CHAR_CODE } from "../../utils/index.js";
|
|
17
|
+
function extractHTMLElement(html, xpathExpression, contentsOnly) {
|
|
18
|
+
const { start, end } = extractHTMLElementIndex(html, xpathExpression, contentsOnly);
|
|
19
|
+
return html.slice(start, end);
|
|
20
|
+
}
|
|
21
|
+
function extractHTMLElements(html, xpathExpression, contentsOnly) {
|
|
22
|
+
const indexes = extractHTMLElementsIndexes(html, xpathExpression, contentsOnly);
|
|
23
|
+
const res = [];
|
|
24
|
+
for (const { start, end } of indexes) {
|
|
25
|
+
res.push(html.slice(start, end));
|
|
26
|
+
}
|
|
27
|
+
return res;
|
|
28
|
+
}
|
|
29
|
+
function extractHTMLElementIndex(html, xpathExpression, contentsOnly) {
|
|
30
|
+
return extractHTMLElementsIndexes(html, xpathExpression, contentsOnly)[0];
|
|
31
|
+
}
|
|
32
|
+
function extractHTMLElementsIndexes(html, xpathExpression, contentsOnly) {
|
|
33
|
+
return extractHTMLElementIndexesParse5(html, xpathExpression, contentsOnly);
|
|
34
|
+
}
|
|
35
|
+
function extractHTMLElementIndexesParse5(html, xpathExpression, contentsOnly) {
|
|
36
|
+
const domLight = parse(
|
|
37
|
+
html,
|
|
38
|
+
{ treeAdapter: htmlAdapter, sourceCodeLocationInfo: true }
|
|
39
|
+
);
|
|
40
|
+
domLight["name"] = "root";
|
|
41
|
+
const parsedPath = xpath.parse(xpathExpression);
|
|
42
|
+
const nodes = parsedPath.select({
|
|
43
|
+
node: domLight,
|
|
44
|
+
allowAnyNamespaceForNoPrefix: true
|
|
45
|
+
});
|
|
46
|
+
if (!nodes.length) {
|
|
47
|
+
throw new Error(`Failed to find XPath: "${xpathExpression}"`);
|
|
48
|
+
}
|
|
49
|
+
return nodes.map((node) => getNodeRange(node, contentsOnly));
|
|
50
|
+
}
|
|
51
|
+
function getNodeRange(node, contentsOnly) {
|
|
52
|
+
if (!contentsOnly) {
|
|
53
|
+
return { start: node.startIndex, end: node.endIndex };
|
|
54
|
+
}
|
|
55
|
+
if (!("firstChild" in node) || !node.firstChild) {
|
|
56
|
+
throw new Error(`Node "${node["name"]}" has no children`);
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
start: node.firstChild.startIndex,
|
|
60
|
+
end: node.lastChild.endIndex
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function extractJSONValueIndex(json, jsonPath) {
|
|
64
|
+
return extractJSONValueIndexes(json, jsonPath)[0];
|
|
65
|
+
}
|
|
66
|
+
function extractJSONValueIndexes(json, jsonPath) {
|
|
67
|
+
const pointers = JSONPath({
|
|
68
|
+
path: jsonPath,
|
|
69
|
+
json: JSON.parse(json),
|
|
70
|
+
wrap: false,
|
|
71
|
+
resultType: "pointer",
|
|
72
|
+
eval: "safe",
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
ignoreEvalErrors: true
|
|
75
|
+
});
|
|
76
|
+
if (!pointers) {
|
|
77
|
+
throw new Error("jsonPath not found");
|
|
78
|
+
}
|
|
79
|
+
const tree = parseScript("(" + json + ")", { range: true });
|
|
80
|
+
if (tree.body[0] instanceof ExpressionStatement && (tree.body[0].expression instanceof ObjectExpression || tree.body[0].expression instanceof ArrayExpression)) {
|
|
81
|
+
const traversePointers = Array.isArray(pointers) ? pointers : [pointers];
|
|
82
|
+
const res = [];
|
|
83
|
+
for (const pointer of traversePointers) {
|
|
84
|
+
const index = traverse(tree.body[0].expression, "", [pointer]);
|
|
85
|
+
if (index) {
|
|
86
|
+
res.push({
|
|
87
|
+
start: index.start - 1,
|
|
88
|
+
//account for '('
|
|
89
|
+
end: index.end - 1
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return res;
|
|
94
|
+
}
|
|
95
|
+
throw new Error("jsonPath not found");
|
|
96
|
+
}
|
|
97
|
+
function traverse(o, path, pointers) {
|
|
98
|
+
if (o instanceof ObjectExpression) {
|
|
99
|
+
for (const p of o.properties) {
|
|
100
|
+
if (!(p instanceof Property)) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const localPath = p.key.type === Syntax.Literal ? path + "/" + p.key.value : path;
|
|
104
|
+
if (pointers.includes(localPath) && "range" in p && Array.isArray(p.range)) {
|
|
105
|
+
return {
|
|
106
|
+
start: p.range[0],
|
|
107
|
+
end: p.range[1]
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
if (p.value instanceof ObjectExpression || p.value instanceof ArrayExpression) {
|
|
111
|
+
const res = traverse(p.value, localPath, pointers);
|
|
112
|
+
if (res) {
|
|
113
|
+
return res;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (o instanceof ArrayExpression) {
|
|
119
|
+
for (let i = 0; i < o.elements.length; i++) {
|
|
120
|
+
const element = o.elements[i];
|
|
121
|
+
if (!element) {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const localPath = path + "/" + i;
|
|
125
|
+
if (pointers.includes(localPath) && "range" in element && Array.isArray(element.range)) {
|
|
126
|
+
return {
|
|
127
|
+
start: element.range[0],
|
|
128
|
+
end: element.range[1]
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
if (element instanceof ObjectExpression) {
|
|
132
|
+
const res = traverse(element, localPath, pointers);
|
|
133
|
+
if (res) {
|
|
134
|
+
return res;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (element instanceof ArrayExpression) {
|
|
138
|
+
const res = traverse(element, localPath, pointers);
|
|
139
|
+
if (res) {
|
|
140
|
+
return res;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
function buildHeaders(input) {
|
|
148
|
+
const headers = [];
|
|
149
|
+
for (const [key, value] of Object.entries(input || {})) {
|
|
150
|
+
headers.push(`${key}: ${value}`);
|
|
151
|
+
}
|
|
152
|
+
return headers;
|
|
153
|
+
}
|
|
154
|
+
function convertResponsePosToAbsolutePos(pos, bodyStartIdx, chunks) {
|
|
155
|
+
if (chunks?.length) {
|
|
156
|
+
let chunkBodyStart = 0;
|
|
157
|
+
for (const chunk of chunks) {
|
|
158
|
+
const chunkSize = chunk.toIndex - chunk.fromIndex;
|
|
159
|
+
if (pos >= chunkBodyStart && pos <= chunkBodyStart + chunkSize) {
|
|
160
|
+
return pos - chunkBodyStart + chunk.fromIndex;
|
|
161
|
+
}
|
|
162
|
+
chunkBodyStart += chunkSize;
|
|
163
|
+
}
|
|
164
|
+
throw new Error("position out of range");
|
|
165
|
+
}
|
|
166
|
+
return bodyStartIdx + pos;
|
|
167
|
+
}
|
|
168
|
+
function getRedactionsForChunkHeaders(from, to, chunks) {
|
|
169
|
+
const res = [];
|
|
170
|
+
if (!chunks?.length) {
|
|
171
|
+
return res;
|
|
172
|
+
}
|
|
173
|
+
for (let i = 1; i < chunks?.length; i++) {
|
|
174
|
+
const chunk = chunks[i];
|
|
175
|
+
if (chunk.fromIndex > from && chunk.fromIndex < to) {
|
|
176
|
+
res.push({
|
|
177
|
+
fromIndex: chunks[i - 1].toIndex,
|
|
178
|
+
toIndex: chunk.fromIndex
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return res;
|
|
183
|
+
}
|
|
184
|
+
function parseHttpResponse(buff) {
|
|
185
|
+
const parser = makeHttpResponseParser();
|
|
186
|
+
parser.onChunk(buff);
|
|
187
|
+
parser.streamEnded();
|
|
188
|
+
return parser.res;
|
|
189
|
+
}
|
|
190
|
+
function makeRegex(str) {
|
|
191
|
+
return RE2(str, "sgiu");
|
|
192
|
+
}
|
|
193
|
+
const TEMPLATE_START_CHARCODE = "{".charCodeAt(0);
|
|
194
|
+
const TEMPLATE_END_CHARCODE = "}".charCodeAt(0);
|
|
195
|
+
function matchRedactedStrings(templateString, redactedString) {
|
|
196
|
+
if (templateString.length === 0 && redactedString?.length === 0) {
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
if (!redactedString) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
let ts = -1;
|
|
203
|
+
let rs = -1;
|
|
204
|
+
while (ts < templateString.length && rs < redactedString.length) {
|
|
205
|
+
let ct = getTChar();
|
|
206
|
+
let cr = getRChar();
|
|
207
|
+
if (ct !== cr) {
|
|
208
|
+
if (ct === TEMPLATE_START_CHARCODE && cr === REDACTION_CHAR_CODE) {
|
|
209
|
+
if (getTChar() !== TEMPLATE_START_CHARCODE) {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
while ((ct = getTChar()) !== TEMPLATE_END_CHARCODE && ct !== -1) {
|
|
213
|
+
}
|
|
214
|
+
while ((ct = getTChar()) !== TEMPLATE_END_CHARCODE && ct !== -1) {
|
|
215
|
+
}
|
|
216
|
+
if (ct === -1) {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
while ((cr = getRChar()) === REDACTION_CHAR_CODE && cr !== -1) {
|
|
220
|
+
}
|
|
221
|
+
if (cr === -1) {
|
|
222
|
+
return getTChar() === -1;
|
|
223
|
+
}
|
|
224
|
+
rs--;
|
|
225
|
+
} else {
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function getTChar() {
|
|
231
|
+
ts++;
|
|
232
|
+
if (ts < templateString.length) {
|
|
233
|
+
return templateString[ts];
|
|
234
|
+
} else {
|
|
235
|
+
return -1;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function getRChar() {
|
|
239
|
+
if (!redactedString) {
|
|
240
|
+
return -1;
|
|
241
|
+
}
|
|
242
|
+
rs++;
|
|
243
|
+
if (rs < redactedString.length) {
|
|
244
|
+
return redactedString[rs];
|
|
245
|
+
} else {
|
|
246
|
+
return -1;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return ts === templateString.length && rs === redactedString.length;
|
|
250
|
+
}
|
|
251
|
+
function generateRequstAndResponseFromTranscript(transcript, tlsVersion) {
|
|
252
|
+
const allPackets = transcript;
|
|
253
|
+
const packets = [];
|
|
254
|
+
for (const b of allPackets) {
|
|
255
|
+
if (b.message.type !== "ciphertext" || !isApplicationData(b.message, tlsVersion)) {
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
const plaintext = tlsVersion === "TLS1_3" ? b.message.plaintext.slice(0, -1) : b.message.plaintext;
|
|
259
|
+
packets.push({
|
|
260
|
+
message: plaintext,
|
|
261
|
+
sender: b.sender
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
const req = getHttpRequestDataFromTranscript(packets);
|
|
265
|
+
const responsePackets = concatenateUint8Arrays(packets.filter((p) => p.sender === "server").map((p) => p.message).filter((b) => !b.every((b2) => b2 === REDACTION_CHAR_CODE)));
|
|
266
|
+
const res = parseHttpResponse(responsePackets);
|
|
267
|
+
return { req, res };
|
|
268
|
+
}
|
|
269
|
+
export {
|
|
270
|
+
buildHeaders,
|
|
271
|
+
convertResponsePosToAbsolutePos,
|
|
272
|
+
extractHTMLElement,
|
|
273
|
+
extractHTMLElementIndex,
|
|
274
|
+
extractHTMLElements,
|
|
275
|
+
extractHTMLElementsIndexes,
|
|
276
|
+
extractJSONValueIndex,
|
|
277
|
+
extractJSONValueIndexes,
|
|
278
|
+
generateRequstAndResponseFromTranscript,
|
|
279
|
+
getRedactionsForChunkHeaders,
|
|
280
|
+
makeRegex,
|
|
281
|
+
matchRedactedStrings,
|
|
282
|
+
parseHttpResponse
|
|
283
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const GNARK_ERROR = "gnark requires native code and cannot run in browser. Use snarkjs or stwo instead.";
|
|
2
|
+
function makeGnarkZkOperator(opts) {
|
|
3
|
+
throw new Error(GNARK_ERROR);
|
|
4
|
+
}
|
|
5
|
+
function makeGnarkOPRFOperator(algorithm, fetcher) {
|
|
6
|
+
throw new Error(GNARK_ERROR);
|
|
7
|
+
}
|
|
8
|
+
async function initGnark() {
|
|
9
|
+
throw new Error(GNARK_ERROR);
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
initGnark,
|
|
13
|
+
makeGnarkOPRFOperator,
|
|
14
|
+
makeGnarkZkOperator
|
|
15
|
+
};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
const Base64 = {
|
|
2
|
+
fromUint8Array(arr) {
|
|
3
|
+
let binary = "";
|
|
4
|
+
for (const element of arr) {
|
|
5
|
+
binary += String.fromCharCode(element);
|
|
6
|
+
}
|
|
7
|
+
return btoa(binary);
|
|
8
|
+
},
|
|
9
|
+
toUint8Array(str) {
|
|
10
|
+
const binary = atob(str);
|
|
11
|
+
const arr = new Uint8Array(binary.length);
|
|
12
|
+
for (let i = 0; i < binary.length; i++) {
|
|
13
|
+
arr[i] = binary.charCodeAt(i);
|
|
14
|
+
}
|
|
15
|
+
return arr;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
function getS2Circuits() {
|
|
19
|
+
const s2 = window["s2circuits"];
|
|
20
|
+
if (!s2) {
|
|
21
|
+
throw new Error("s2circuits not loaded. Make sure s2circuits.js is loaded before using stwo.");
|
|
22
|
+
}
|
|
23
|
+
return s2;
|
|
24
|
+
}
|
|
25
|
+
function assertU32Counter(counter) {
|
|
26
|
+
if (!Number.isInteger(counter) || counter < 0 || counter > 4294967295) {
|
|
27
|
+
throw new RangeError("counter must be a uint32 integer (0 to 4294967295)");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
let wasmInitialized = false;
|
|
31
|
+
let initPromise;
|
|
32
|
+
async function ensureWasmInitialized(fetcher, logger) {
|
|
33
|
+
if (wasmInitialized) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (initPromise) {
|
|
37
|
+
return initPromise;
|
|
38
|
+
}
|
|
39
|
+
initPromise = (async () => {
|
|
40
|
+
try {
|
|
41
|
+
const s2 = getS2Circuits();
|
|
42
|
+
const wasmBytes = await fetcher.fetch("stwo", "s2circuits_bg.wasm", logger);
|
|
43
|
+
s2.initSync({ module: wasmBytes });
|
|
44
|
+
wasmInitialized = true;
|
|
45
|
+
} catch (err) {
|
|
46
|
+
initPromise = void 0;
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
49
|
+
})();
|
|
50
|
+
return initPromise;
|
|
51
|
+
}
|
|
52
|
+
function serializeWitness(algorithm, input) {
|
|
53
|
+
if (!input.noncesAndCounters?.length) {
|
|
54
|
+
throw new Error("noncesAndCounters must be a non-empty array");
|
|
55
|
+
}
|
|
56
|
+
const { noncesAndCounters: [{ nonce, counter }] } = input;
|
|
57
|
+
assertU32Counter(counter);
|
|
58
|
+
const data = {
|
|
59
|
+
algorithm,
|
|
60
|
+
key: Base64.fromUint8Array(input.key),
|
|
61
|
+
nonce: Base64.fromUint8Array(nonce),
|
|
62
|
+
counter,
|
|
63
|
+
plaintext: Base64.fromUint8Array(input.out),
|
|
64
|
+
// out = decrypted plaintext
|
|
65
|
+
ciphertext: Base64.fromUint8Array(input.in)
|
|
66
|
+
// in = encrypted ciphertext
|
|
67
|
+
};
|
|
68
|
+
return new TextEncoder().encode(JSON.stringify(data));
|
|
69
|
+
}
|
|
70
|
+
function deserializeWitness(witness) {
|
|
71
|
+
const json = new TextDecoder().decode(witness);
|
|
72
|
+
return JSON.parse(json);
|
|
73
|
+
}
|
|
74
|
+
function makeStwoZkOperator({
|
|
75
|
+
algorithm,
|
|
76
|
+
fetcher
|
|
77
|
+
}) {
|
|
78
|
+
return {
|
|
79
|
+
generateWitness(input) {
|
|
80
|
+
return serializeWitness(algorithm, input);
|
|
81
|
+
},
|
|
82
|
+
async groth16Prove(witness, logger) {
|
|
83
|
+
await ensureWasmInitialized(fetcher, logger);
|
|
84
|
+
const s2 = getS2Circuits();
|
|
85
|
+
const data = deserializeWitness(witness);
|
|
86
|
+
const key = Base64.toUint8Array(data.key);
|
|
87
|
+
const nonce = Base64.toUint8Array(data.nonce);
|
|
88
|
+
const plaintext = Base64.toUint8Array(data.plaintext);
|
|
89
|
+
const ciphertext = Base64.toUint8Array(data.ciphertext);
|
|
90
|
+
let resultJson;
|
|
91
|
+
switch (data.algorithm) {
|
|
92
|
+
case "chacha20":
|
|
93
|
+
resultJson = s2.generate_chacha20_proof(key, nonce, data.counter, plaintext, ciphertext);
|
|
94
|
+
break;
|
|
95
|
+
case "aes-128-ctr":
|
|
96
|
+
resultJson = s2.generate_aes128_ctr_proof(key, nonce, data.counter, plaintext, ciphertext);
|
|
97
|
+
break;
|
|
98
|
+
case "aes-256-ctr":
|
|
99
|
+
resultJson = s2.generate_aes256_ctr_proof(key, nonce, data.counter, plaintext, ciphertext);
|
|
100
|
+
break;
|
|
101
|
+
default:
|
|
102
|
+
throw new Error(`Unsupported algorithm: ${data.algorithm}`);
|
|
103
|
+
}
|
|
104
|
+
const result = JSON.parse(resultJson);
|
|
105
|
+
if (result.error) {
|
|
106
|
+
throw new Error(`Stwo proof generation failed: ${result.error}`);
|
|
107
|
+
}
|
|
108
|
+
if (!result.proof) {
|
|
109
|
+
throw new Error("Stwo proof generation failed: no proof returned");
|
|
110
|
+
}
|
|
111
|
+
return { proof: result.proof };
|
|
112
|
+
},
|
|
113
|
+
async groth16Verify(publicSignals, proof, logger) {
|
|
114
|
+
await ensureWasmInitialized(fetcher, logger);
|
|
115
|
+
const s2 = getS2Circuits();
|
|
116
|
+
const expectedNonce = publicSignals.noncesAndCounters[0]?.nonce;
|
|
117
|
+
const expectedCounter = publicSignals.noncesAndCounters[0]?.counter;
|
|
118
|
+
const expectedCiphertext = publicSignals.in;
|
|
119
|
+
const expectedPlaintext = publicSignals.out;
|
|
120
|
+
if (!expectedNonce || expectedCounter === void 0) {
|
|
121
|
+
logger?.warn("Invalid publicSignals: missing nonce or counter");
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
assertU32Counter(expectedCounter);
|
|
125
|
+
const proofStr = typeof proof === "string" ? proof : new TextDecoder().decode(proof);
|
|
126
|
+
let resultJson;
|
|
127
|
+
if (algorithm === "chacha20") {
|
|
128
|
+
resultJson = s2.verify_chacha20_proof(
|
|
129
|
+
proofStr,
|
|
130
|
+
expectedNonce,
|
|
131
|
+
expectedCounter,
|
|
132
|
+
expectedPlaintext,
|
|
133
|
+
expectedCiphertext
|
|
134
|
+
);
|
|
135
|
+
} else {
|
|
136
|
+
resultJson = s2.verify_aes_ctr_proof(
|
|
137
|
+
proofStr,
|
|
138
|
+
expectedNonce,
|
|
139
|
+
expectedCounter,
|
|
140
|
+
expectedPlaintext,
|
|
141
|
+
expectedCiphertext
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
const result = JSON.parse(resultJson);
|
|
145
|
+
if (result.error) {
|
|
146
|
+
logger?.warn({ error: result.error }, "Stwo STARK verification failed");
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
return result.valid === true;
|
|
150
|
+
},
|
|
151
|
+
release() {
|
|
152
|
+
wasmInitialized = false;
|
|
153
|
+
initPromise = void 0;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
export {
|
|
158
|
+
makeStwoZkOperator
|
|
159
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type BGPAnnouncementOverlapData = {
|
|
2
|
+
prefix: string;
|
|
3
|
+
};
|
|
4
|
+
export type BGPListener = {
|
|
5
|
+
/**
|
|
6
|
+
* Add an IP to listen for overlap,
|
|
7
|
+
* @returns a function to remove the IP from the listener
|
|
8
|
+
*/
|
|
9
|
+
onOverlap(ips: string[], callback: (event: BGPAnnouncementOverlapData) => void): (() => void);
|
|
10
|
+
close(): void;
|
|
11
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { ProviderClaimData } from '#src/proto/api.ts';
|
|
2
|
+
import type { IAttestorClient, IAttestorClientInitParams } from '#src/types/client.ts';
|
|
3
|
+
import type { CompleteTLSPacket, Logger } from '#src/types/general.ts';
|
|
4
|
+
import type { ProofGenerationStep, ProviderName, ProviderParams, ProviderSecretParams } from '#src/types/providers.ts';
|
|
5
|
+
import type { Transcript } from '#src/types/tunnel.ts';
|
|
6
|
+
import type { PrepareZKProofsBaseOpts } from '#src/types/zk.ts';
|
|
7
|
+
/**
|
|
8
|
+
* Uniquely identifies a claim.
|
|
9
|
+
* Hash of claim info.
|
|
10
|
+
* Utilise `getIdentifierFromClaimInfo` to obtain this.
|
|
11
|
+
*/
|
|
12
|
+
export type ClaimID = ProviderClaimData['identifier'];
|
|
13
|
+
export type ClaimInfo = Pick<ProviderClaimData, 'context' | 'provider' | 'parameters'>;
|
|
14
|
+
export type CompleteClaimData = Pick<ProviderClaimData, 'owner' | 'timestampS' | 'epoch'> & ClaimInfo;
|
|
15
|
+
export type CreateClaimOnAttestorOpts<N extends ProviderName> = {
|
|
16
|
+
/** name of the provider to generate signed receipt for */
|
|
17
|
+
name: N;
|
|
18
|
+
/**
|
|
19
|
+
* secrets that are used to make the API request;
|
|
20
|
+
* not included in the receipt & cannot be viewed by anyone
|
|
21
|
+
* outside this client
|
|
22
|
+
*/
|
|
23
|
+
secretParams: ProviderSecretParams<N>;
|
|
24
|
+
params: ProviderParams<N>;
|
|
25
|
+
/**
|
|
26
|
+
* Some metadata context to be included in the claim
|
|
27
|
+
*/
|
|
28
|
+
context?: {
|
|
29
|
+
[key: string]: any;
|
|
30
|
+
};
|
|
31
|
+
onStep?(step: ProofGenerationStep): void;
|
|
32
|
+
/**
|
|
33
|
+
* Private key in hex format,
|
|
34
|
+
* prefixed with '0x'
|
|
35
|
+
*/
|
|
36
|
+
ownerPrivateKey: string;
|
|
37
|
+
/**
|
|
38
|
+
* Provide either the client or the URL
|
|
39
|
+
* to the server -- so a client can be created internally.
|
|
40
|
+
*
|
|
41
|
+
* The created client will go into the global client pool.
|
|
42
|
+
*/
|
|
43
|
+
client: IAttestorClient | IAttestorClientInitParams;
|
|
44
|
+
/**
|
|
45
|
+
* Optionally set the timestamp of the claim
|
|
46
|
+
* in unix seconds. If not provided, the current
|
|
47
|
+
* time will be used.
|
|
48
|
+
*/
|
|
49
|
+
timestampS?: number;
|
|
50
|
+
logger?: Logger;
|
|
51
|
+
/**
|
|
52
|
+
* Maximum number of retries to attempt
|
|
53
|
+
* @default 3
|
|
54
|
+
*/
|
|
55
|
+
maxRetries?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Optionally update the provider parameters
|
|
58
|
+
* based on the transcript
|
|
59
|
+
*/
|
|
60
|
+
updateProviderParams?(transcript: Transcript<CompleteTLSPacket>, tlsVersion: string): Promise<{
|
|
61
|
+
params: Partial<ProviderParams<N>>;
|
|
62
|
+
secretParams: Partial<ProviderSecretParams<N>>;
|
|
63
|
+
}>;
|
|
64
|
+
/**
|
|
65
|
+
* Replaces paramValue with corresponding OPRF hash before proof is made
|
|
66
|
+
* Only if there's matching redaction exists
|
|
67
|
+
* For example: "domain.com" -> "dv4Nrgtr"
|
|
68
|
+
*/
|
|
69
|
+
updateParametersFromOprfData?: boolean;
|
|
70
|
+
} & PrepareZKProofsBaseOpts;
|
|
File without changes
|