@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
package/lib/utils/logger.js
CHANGED
|
@@ -1,100 +1,82 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.makeLogger = makeLogger;
|
|
8
|
-
exports.redact = redact;
|
|
9
|
-
const pino_1 = __importDefault(require("pino"));
|
|
10
|
-
const env_1 = require("../utils/env");
|
|
11
|
-
const PII_PROPERTIES = ['ownerPrivateKey', 'secretParams'];
|
|
12
|
-
const redactedText = '[REDACTED]';
|
|
13
|
-
const envLevel = (0, env_1.getEnvVariable)('LOG_LEVEL');
|
|
14
|
-
exports.logger = (0, pino_1.default)();
|
|
1
|
+
import { pino, stdTimeFunctions } from "pino";
|
|
2
|
+
import { getEnvVariable } from "../utils/env.js";
|
|
3
|
+
const PII_PROPERTIES = ["ownerPrivateKey", "secretParams"];
|
|
4
|
+
const redactedText = "[REDACTED]";
|
|
5
|
+
const envLevel = getEnvVariable("LOG_LEVEL");
|
|
6
|
+
let logger = pino();
|
|
15
7
|
makeLogger(false, envLevel);
|
|
16
|
-
/**
|
|
17
|
-
* Creates a logger instance with optional redaction of PII.
|
|
18
|
-
* Replaces default logger
|
|
19
|
-
* See PII_PROPERTIES for the list of properties that will be redacted.
|
|
20
|
-
*
|
|
21
|
-
* @param redactPii - whether to redact PII from logs
|
|
22
|
-
* @param level - the log level to use
|
|
23
|
-
* @param onLog - a callback to call when a log is written
|
|
24
|
-
*/
|
|
25
8
|
function makeLogger(redactPii, level, onLog) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
9
|
+
const opts = {
|
|
10
|
+
// Log human readable time stamps instead of epoch time
|
|
11
|
+
timestamp: stdTimeFunctions.isoTime
|
|
12
|
+
};
|
|
13
|
+
if (redactPii) {
|
|
14
|
+
opts.formatters = { log: redact };
|
|
15
|
+
opts.serializers = { redact };
|
|
16
|
+
opts.browser = {
|
|
17
|
+
write: {
|
|
18
|
+
fatal: (log) => writeLog("fatal", log),
|
|
19
|
+
error: (log) => writeLog("error", log),
|
|
20
|
+
warn: (log) => writeLog("warn", log),
|
|
21
|
+
info: (log) => writeLog("info", log),
|
|
22
|
+
debug: (log) => writeLog("debug", log),
|
|
23
|
+
trace: (log) => writeLog("trace", log)
|
|
24
|
+
}
|
|
29
25
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
const pLogger = (0, pino_1.default)(opts);
|
|
45
|
-
pLogger.level = level || 'info';
|
|
46
|
-
exports.logger = pLogger;
|
|
47
|
-
return pLogger;
|
|
48
|
-
function writeLog(level, log) {
|
|
49
|
-
log = redact(log);
|
|
50
|
-
const { msg, ...obj } = log;
|
|
51
|
-
if (console[level]) {
|
|
52
|
-
console[level](obj, msg);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
console.log(obj, msg);
|
|
56
|
-
}
|
|
57
|
-
onLog === null || onLog === void 0 ? void 0 : onLog(level, log);
|
|
26
|
+
}
|
|
27
|
+
const pLogger = pino(opts);
|
|
28
|
+
pLogger.level = level || "info";
|
|
29
|
+
logger = pLogger;
|
|
30
|
+
return pLogger;
|
|
31
|
+
function writeLog(level2, log) {
|
|
32
|
+
log = redact(log);
|
|
33
|
+
const { msg, ...obj } = log;
|
|
34
|
+
if (console[level2]) {
|
|
35
|
+
console[level2](obj, msg);
|
|
36
|
+
} else {
|
|
37
|
+
console.log(obj, msg);
|
|
58
38
|
}
|
|
39
|
+
onLog?.(level2, log);
|
|
40
|
+
}
|
|
59
41
|
}
|
|
60
42
|
function isObjectProperty(property) {
|
|
61
|
-
|
|
62
|
-
&& !Array.isArray(property)
|
|
63
|
-
&& property !== null;
|
|
43
|
+
return typeof property === "object" && !Array.isArray(property) && property !== null;
|
|
64
44
|
}
|
|
65
45
|
function getReplacer() {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
};
|
|
46
|
+
const references = /* @__PURE__ */ new WeakSet();
|
|
47
|
+
return function(key, value) {
|
|
48
|
+
const isObject = typeof value === "object" && value !== null;
|
|
49
|
+
if (isObject) {
|
|
50
|
+
if (references.has(value)) {
|
|
51
|
+
return "[CIRCULAR]";
|
|
52
|
+
}
|
|
53
|
+
references.add(value);
|
|
54
|
+
}
|
|
55
|
+
return value;
|
|
56
|
+
};
|
|
78
57
|
}
|
|
79
58
|
function redact(json) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
59
|
+
const isObject = isObjectProperty(json);
|
|
60
|
+
if (!isObject && !Array.isArray(json)) {
|
|
61
|
+
return json;
|
|
62
|
+
}
|
|
63
|
+
const redacted = JSON.parse(JSON.stringify(json, getReplacer()));
|
|
64
|
+
for (const prop in redacted) {
|
|
65
|
+
if (PII_PROPERTIES.includes(prop)) {
|
|
66
|
+
redacted[prop] = redactedText;
|
|
83
67
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
for (const [index, value] of redacted[prop].entries()) {
|
|
91
|
-
redacted[prop][index] = redact(value);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
else if (isObjectProperty(redacted[prop])) {
|
|
95
|
-
redacted[prop] = redact(redacted[prop]);
|
|
96
|
-
}
|
|
68
|
+
if (Array.isArray(redacted[prop])) {
|
|
69
|
+
for (const [index, value] of redacted[prop].entries()) {
|
|
70
|
+
redacted[prop][index] = redact(value);
|
|
71
|
+
}
|
|
72
|
+
} else if (isObjectProperty(redacted[prop])) {
|
|
73
|
+
redacted[prop] = redact(redacted[prop]);
|
|
97
74
|
}
|
|
98
|
-
|
|
75
|
+
}
|
|
76
|
+
return redacted;
|
|
99
77
|
}
|
|
100
|
-
|
|
78
|
+
export {
|
|
79
|
+
logger,
|
|
80
|
+
makeLogger,
|
|
81
|
+
redact
|
|
82
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CipherSuite, TLSPacketContext } from '@reclaimprotocol/tls';
|
|
2
|
-
import { ClaimTunnelRequest_TranscriptMessage as TranscriptMessage } from '
|
|
3
|
-
import { CompleteTLSPacket, Logger, MessageRevealInfo, PrepareZKProofsBaseOpts, Transcript } from '
|
|
1
|
+
import type { CipherSuite, TLSPacketContext } from '@reclaimprotocol/tls';
|
|
2
|
+
import type { ClaimTunnelRequest_TranscriptMessage as TranscriptMessage } from '#src/proto/api.ts';
|
|
3
|
+
import type { CompleteTLSPacket, Logger, MessageRevealInfo, PrepareZKProofsBaseOpts, Transcript } from '#src/types/index.ts';
|
|
4
4
|
export type PreparePacketsForRevealOpts = {
|
|
5
5
|
cipherSuite: CipherSuite;
|
|
6
6
|
logger: Logger;
|
|
@@ -1,61 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const zk_1 = require("../utils/zk");
|
|
7
|
-
/**
|
|
8
|
-
* Prepares the packets for reveal to the server
|
|
9
|
-
* according to the specified reveal type
|
|
10
|
-
*/
|
|
1
|
+
import { concatenateUint8Arrays, crypto } from "../utils/tls-imports.js";
|
|
2
|
+
import {
|
|
3
|
+
TranscriptMessageSenderType
|
|
4
|
+
} from "../proto/api.js";
|
|
5
|
+
import { makeZkProofGenerator } from "../utils/zk.js";
|
|
11
6
|
async function preparePacketsForReveal(tlsTranscript, reveals, { onZkProgress, ...opts }) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
7
|
+
const transcript = [];
|
|
8
|
+
const proofGenerator = await makeZkProofGenerator(opts);
|
|
9
|
+
let zkPacketsDone = 0;
|
|
10
|
+
await Promise.all(tlsTranscript.map(async ({ message, sender }, i) => {
|
|
11
|
+
const msg = {
|
|
12
|
+
sender: sender === "client" ? TranscriptMessageSenderType.TRANSCRIPT_MESSAGE_SENDER_TYPE_CLIENT : TranscriptMessageSenderType.TRANSCRIPT_MESSAGE_SENDER_TYPE_SERVER,
|
|
13
|
+
message: message.data,
|
|
14
|
+
reveal: void 0
|
|
15
|
+
};
|
|
16
|
+
transcript.push(msg);
|
|
17
|
+
const reveal = reveals.get(message);
|
|
18
|
+
if (!reveal || message.type === "plaintext") {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
switch (reveal?.type) {
|
|
22
|
+
case "complete":
|
|
23
|
+
msg.reveal = {
|
|
24
|
+
directReveal: {
|
|
25
|
+
key: await crypto.exportKey(message.encKey),
|
|
26
|
+
iv: message.fixedIv,
|
|
27
|
+
recordNumber: message.recordNumber
|
|
28
|
+
}
|
|
22
29
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return transcript;
|
|
30
|
+
break;
|
|
31
|
+
case "zk": {
|
|
32
|
+
reveal.redactedPlaintext = concatenateUint8Arrays([
|
|
33
|
+
reveal.redactedPlaintext,
|
|
34
|
+
message.plaintext.slice(reveal.redactedPlaintext.length)
|
|
35
|
+
]);
|
|
36
|
+
const oprfRawMarkers = reveal.oprfRawMarkers?.map((m) => ({
|
|
37
|
+
dataLocation: m.dataLocation
|
|
38
|
+
})) || [];
|
|
39
|
+
const overshotOprfRawLength = reveal.overshotOprfRawFromPrevBlock?.length ?? 0;
|
|
40
|
+
await proofGenerator.addPacketToProve(
|
|
41
|
+
message,
|
|
42
|
+
reveal,
|
|
43
|
+
(proofs, toprfs) => msg.reveal = {
|
|
44
|
+
zkReveal: { proofs, toprfs, oprfRawMarkers, overshotOprfRawLength }
|
|
45
|
+
},
|
|
46
|
+
() => {
|
|
47
|
+
const next = tlsTranscript.slice(i + 1).find((t) => t.sender === sender);
|
|
48
|
+
return next?.message;
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
default:
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}));
|
|
57
|
+
const zkPacketsTotal = proofGenerator.getTotalChunksToProve();
|
|
58
|
+
onZkProgress?.(zkPacketsDone, zkPacketsTotal);
|
|
59
|
+
await proofGenerator.generateProofs(
|
|
60
|
+
() => {
|
|
61
|
+
zkPacketsDone += 1;
|
|
62
|
+
onZkProgress?.(zkPacketsDone, zkPacketsTotal);
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
return transcript;
|
|
60
66
|
}
|
|
61
|
-
|
|
67
|
+
export {
|
|
68
|
+
preparePacketsForReveal
|
|
69
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ArraySlice, RedactedOrHashedArraySlice, TOPRFProofParams } from '
|
|
1
|
+
import type { ArraySlice, OPRFRawMarker, RedactedOrHashedArraySlice, TOPRFProofParams } from '#src/types/index.ts';
|
|
2
2
|
export declare const REDACTION_CHAR = "*";
|
|
3
3
|
export declare const REDACTION_CHAR_CODE: number;
|
|
4
4
|
type SliceWithReveal<T> = {
|
|
@@ -8,6 +8,25 @@ type SliceWithReveal<T> = {
|
|
|
8
8
|
* If the block has some TOPRF claims -- they'll be set here
|
|
9
9
|
*/
|
|
10
10
|
toprfs?: TOPRFProofParams[];
|
|
11
|
+
/**
|
|
12
|
+
* If the block has oprf-raw markers for server-side OPRF computation
|
|
13
|
+
*/
|
|
14
|
+
oprfRawMarkers?: OPRFRawMarker[];
|
|
15
|
+
/**
|
|
16
|
+
* If text was replaced in the previous block w TOPRF but
|
|
17
|
+
* it overshot into this block. The "length" specifies how much
|
|
18
|
+
* of it got overshot into this block
|
|
19
|
+
*/
|
|
20
|
+
overshotToprfFromPrevBlock?: {
|
|
21
|
+
length: number;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* If an oprf-raw marker from the previous block overshot into this block.
|
|
25
|
+
* The server will collect plaintext from this block to complete the OPRF.
|
|
26
|
+
*/
|
|
27
|
+
overshotOprfRawFromPrevBlock?: {
|
|
28
|
+
length: number;
|
|
29
|
+
};
|
|
11
30
|
};
|
|
12
31
|
export type RevealedSlices<T> = 'all' | SliceWithReveal<T>[];
|
|
13
32
|
/**
|
package/lib/utils/redactions.js
CHANGED
|
@@ -1,148 +1,135 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
exports.isFullyRedacted = isFullyRedacted;
|
|
6
|
-
exports.getBlocksToReveal = getBlocksToReveal;
|
|
7
|
-
exports.redactSlices = redactSlices;
|
|
8
|
-
exports.binaryHashToStr = binaryHashToStr;
|
|
9
|
-
const wire_1 = require("@bufbuild/protobuf/wire");
|
|
10
|
-
const tls_1 = require("@reclaimprotocol/tls");
|
|
11
|
-
exports.REDACTION_CHAR = '*';
|
|
12
|
-
exports.REDACTION_CHAR_CODE = exports.REDACTION_CHAR.charCodeAt(0);
|
|
13
|
-
/**
|
|
14
|
-
* Check if a redacted string is congruent with the original string.
|
|
15
|
-
* @param redacted the redacted content, redacted content is replaced by '*'
|
|
16
|
-
* @param original the original content
|
|
17
|
-
*/
|
|
1
|
+
import { base64Encode } from "@bufbuild/protobuf/wire";
|
|
2
|
+
import { concatenateUint8Arrays } from "../utils/tls-imports.js";
|
|
3
|
+
const REDACTION_CHAR = "*";
|
|
4
|
+
const REDACTION_CHAR_CODE = REDACTION_CHAR.charCodeAt(0);
|
|
18
5
|
function isRedactionCongruent(redacted, original) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|| (typeof element === 'number' && element === exports.REDACTION_CHAR_CODE);
|
|
25
|
-
if (!areSame) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
6
|
+
for (let i = 0; i < redacted.length; i++) {
|
|
7
|
+
const element = redacted[i];
|
|
8
|
+
const areSame = element === original[i] || typeof element === "string" && element === REDACTION_CHAR || typeof element === "number" && element === REDACTION_CHAR_CODE;
|
|
9
|
+
if (!areSame) {
|
|
10
|
+
return false;
|
|
28
11
|
}
|
|
29
|
-
|
|
12
|
+
}
|
|
13
|
+
return true;
|
|
30
14
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Is the string fully redacted?
|
|
33
|
-
*/
|
|
34
15
|
function isFullyRedacted(redacted) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
16
|
+
for (const element of redacted) {
|
|
17
|
+
if (element !== REDACTION_CHAR && element !== REDACTION_CHAR_CODE) {
|
|
18
|
+
return false;
|
|
40
19
|
}
|
|
41
|
-
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
42
22
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Given some plaintext blocks and a redaction function, return the blocks that
|
|
45
|
-
* need to be revealed to the other party
|
|
46
|
-
*
|
|
47
|
-
* Use case: we get the response for a request in several blocks, and want to redact
|
|
48
|
-
* pieces that go through multiple blocks. We can use this function to get the
|
|
49
|
-
* blocks that need to be revealed to the other party
|
|
50
|
-
*
|
|
51
|
-
* @example if we received ["secret is 12","345","678. Thanks"]. We'd want
|
|
52
|
-
* to redact the "12345678" and reveal the rest. We'd pass in the blocks and
|
|
53
|
-
* the redact function will return the redactions, namely [10,19].
|
|
54
|
-
* The function will return the blocks ["secret is **","***. Thanks"].
|
|
55
|
-
* The middle block is fully redacted, so it's not returned
|
|
56
|
-
*
|
|
57
|
-
* @param blocks blocks to reveal
|
|
58
|
-
* @param redact function that returns the redactions
|
|
59
|
-
* @returns blocks to reveal
|
|
60
|
-
*/
|
|
61
23
|
async function getBlocksToReveal(blocks, redact, performOprf) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
24
|
+
const slicesWithReveal = blocks.map((block) => ({
|
|
25
|
+
block,
|
|
26
|
+
// copy the plaintext to avoid mutating the original
|
|
27
|
+
redactedPlaintext: new Uint8Array(block.plaintext)
|
|
28
|
+
}));
|
|
29
|
+
const total = concatenateUint8Arrays(blocks.map((b) => b.plaintext));
|
|
30
|
+
const redactions = redact(total);
|
|
31
|
+
if (!redactions.length) {
|
|
32
|
+
return "all";
|
|
33
|
+
}
|
|
34
|
+
let blockIdx = 0;
|
|
35
|
+
let cursorInBlock = 0;
|
|
36
|
+
let cursor = 0;
|
|
37
|
+
for (const redaction of redactions) {
|
|
38
|
+
await redactBlocks(redaction);
|
|
39
|
+
}
|
|
40
|
+
return slicesWithReveal.filter((s) => !isFullyRedacted(s.redactedPlaintext));
|
|
41
|
+
async function redactBlocks(slice) {
|
|
42
|
+
while (cursor < slice.fromIndex) {
|
|
43
|
+
advance();
|
|
71
44
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
async function redactBlocks(slice) {
|
|
83
|
-
while (cursor < slice.fromIndex) {
|
|
84
|
-
advance();
|
|
85
|
-
}
|
|
86
|
-
if (slice.hash) {
|
|
87
|
-
const plaintext = total.slice(slice.fromIndex, slice.toIndex);
|
|
88
|
-
const { nullifier, responses, mask } = await performOprf(plaintext);
|
|
89
|
-
// set the TOPRF claim on the first blocks this
|
|
90
|
-
// redaction covers
|
|
91
|
-
const toprf = {
|
|
92
|
-
nullifier,
|
|
93
|
-
responses,
|
|
94
|
-
dataLocation: {
|
|
95
|
-
fromIndex: cursorInBlock,
|
|
96
|
-
length: slice.toIndex - slice.fromIndex
|
|
97
|
-
},
|
|
98
|
-
mask,
|
|
99
|
-
plaintext
|
|
100
|
-
};
|
|
101
|
-
const block = slicesWithReveal[blockIdx];
|
|
102
|
-
block.toprfs || (block.toprfs = []);
|
|
103
|
-
block.toprfs.push(toprf);
|
|
104
|
-
const nullifierStr = binaryHashToStr(nullifier, toprf.dataLocation.length);
|
|
105
|
-
let i = 0;
|
|
106
|
-
while (cursor < slice.toIndex) {
|
|
107
|
-
slicesWithReveal[blockIdx].redactedPlaintext[cursorInBlock]
|
|
108
|
-
= nullifierStr.charCodeAt(i);
|
|
109
|
-
advance();
|
|
110
|
-
i += 1;
|
|
111
|
-
}
|
|
45
|
+
if (slice.hash === "oprf-raw") {
|
|
46
|
+
const startBlockIdx = blockIdx;
|
|
47
|
+
const startCursorInBlock = cursorInBlock;
|
|
48
|
+
const totalLength = slice.toIndex - slice.fromIndex;
|
|
49
|
+
const block = slicesWithReveal[blockIdx];
|
|
50
|
+
block.oprfRawMarkers ||= [];
|
|
51
|
+
block.oprfRawMarkers.push({
|
|
52
|
+
dataLocation: {
|
|
53
|
+
fromIndex: startCursorInBlock,
|
|
54
|
+
length: totalLength
|
|
112
55
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
56
|
+
});
|
|
57
|
+
let overshootLen = 0;
|
|
58
|
+
while (cursor < slice.toIndex) {
|
|
59
|
+
if (blockIdx !== startBlockIdx) {
|
|
60
|
+
overshootLen += 1;
|
|
117
61
|
}
|
|
62
|
+
advance();
|
|
63
|
+
}
|
|
64
|
+
if (overshootLen) {
|
|
65
|
+
slicesWithReveal[blockIdx].overshotOprfRawFromPrevBlock = { length: overshootLen };
|
|
66
|
+
}
|
|
67
|
+
return;
|
|
118
68
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
69
|
+
if (slice.hash) {
|
|
70
|
+
const plaintext = total.slice(slice.fromIndex, slice.toIndex);
|
|
71
|
+
const { nullifier, responses, mask } = await performOprf(plaintext);
|
|
72
|
+
const toprf = {
|
|
73
|
+
nullifier,
|
|
74
|
+
responses,
|
|
75
|
+
dataLocation: {
|
|
76
|
+
fromIndex: cursorInBlock,
|
|
77
|
+
length: slice.toIndex - slice.fromIndex
|
|
78
|
+
},
|
|
79
|
+
mask,
|
|
80
|
+
plaintext
|
|
81
|
+
};
|
|
82
|
+
const startBlockIdx = blockIdx;
|
|
83
|
+
const block = slicesWithReveal[blockIdx];
|
|
84
|
+
block.toprfs ||= [];
|
|
85
|
+
block.toprfs.push(toprf);
|
|
86
|
+
const nullifierStr = binaryHashToStr(nullifier, toprf.dataLocation.length);
|
|
87
|
+
let i = 0;
|
|
88
|
+
let overshootLen = 0;
|
|
89
|
+
while (cursor < slice.toIndex) {
|
|
90
|
+
if (blockIdx !== startBlockIdx) {
|
|
91
|
+
overshootLen += 1;
|
|
125
92
|
}
|
|
93
|
+
slicesWithReveal[blockIdx].redactedPlaintext[cursorInBlock] = nullifierStr.charCodeAt(i);
|
|
94
|
+
advance();
|
|
95
|
+
i += 1;
|
|
96
|
+
}
|
|
97
|
+
if (overshootLen) {
|
|
98
|
+
slicesWithReveal[blockIdx].overshotToprfFromPrevBlock = { length: overshootLen };
|
|
99
|
+
}
|
|
126
100
|
}
|
|
101
|
+
while (cursor < slice.toIndex) {
|
|
102
|
+
slicesWithReveal[blockIdx].redactedPlaintext[cursorInBlock] = REDACTION_CHAR_CODE;
|
|
103
|
+
advance();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function advance() {
|
|
107
|
+
cursor += 1;
|
|
108
|
+
cursorInBlock += 1;
|
|
109
|
+
if (cursorInBlock >= blocks[blockIdx].plaintext.length) {
|
|
110
|
+
blockIdx += 1;
|
|
111
|
+
cursorInBlock = 0;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
127
114
|
}
|
|
128
|
-
/**
|
|
129
|
-
* Redact the following slices from the total
|
|
130
|
-
*/
|
|
131
115
|
function redactSlices(total, slices) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
116
|
+
const redacted = new Uint8Array(total);
|
|
117
|
+
for (const slice of slices) {
|
|
118
|
+
for (let i = slice.fromIndex; i < slice.toIndex; i++) {
|
|
119
|
+
redacted[i] = REDACTION_CHAR_CODE;
|
|
137
120
|
}
|
|
138
|
-
|
|
121
|
+
}
|
|
122
|
+
return redacted;
|
|
139
123
|
}
|
|
140
|
-
/**
|
|
141
|
-
* Converts the binary hash to an ASCII string of the expected length.
|
|
142
|
-
* If the hash is shorter than the expected length, it will be padded with
|
|
143
|
-
* '0' characters. If it's longer, it will be truncated.
|
|
144
|
-
*/
|
|
145
124
|
function binaryHashToStr(hash, expLength) {
|
|
146
|
-
|
|
125
|
+
return base64Encode(hash).padEnd(expLength, "0").slice(0, expLength);
|
|
147
126
|
}
|
|
148
|
-
|
|
127
|
+
export {
|
|
128
|
+
REDACTION_CHAR,
|
|
129
|
+
REDACTION_CHAR_CODE,
|
|
130
|
+
binaryHashToStr,
|
|
131
|
+
getBlocksToReveal,
|
|
132
|
+
isFullyRedacted,
|
|
133
|
+
isRedactionCongruent,
|
|
134
|
+
redactSlices
|
|
135
|
+
};
|
package/lib/utils/retries.d.ts
CHANGED