@joclaim/attestor-core 0.2.0 → 0.2.3
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/README.md +21 -15
- package/lib/avs/abis/avsDirectoryABI.d.ts +60 -0
- package/lib/avs/abis/avsDirectoryABI.js +340 -0
- package/lib/avs/abis/delegationABI.d.ts +126 -0
- package/lib/avs/abis/delegationABI.js +1 -0
- package/lib/avs/abis/registryABI.d.ts +136 -0
- package/lib/avs/abis/registryABI.js +725 -0
- package/lib/avs/client/create-claim-on-avs.d.ts +12 -0
- package/lib/avs/client/create-claim-on-avs.js +138 -0
- package/lib/avs/config.d.ts +7 -0
- package/lib/avs/config.js +20 -0
- package/lib/avs/contracts/ReclaimServiceManager.d.ts +697 -0
- package/lib/avs/contracts/ReclaimServiceManager.js +1 -0
- package/lib/avs/contracts/common.d.ts +21 -0
- package/lib/avs/contracts/common.js +1 -0
- package/lib/avs/contracts/factories/ReclaimServiceManager__factory.d.ts +888 -0
- package/lib/avs/contracts/factories/ReclaimServiceManager__factory.js +1169 -0
- package/lib/avs/contracts/factories/index.d.ts +1 -0
- package/{src/avs/contracts/factories/index.ts → lib/avs/contracts/factories/index.js} +1 -1
- package/{src/avs/contracts/index.ts → lib/avs/contracts/index.d.ts} +0 -3
- package/lib/avs/contracts/index.js +2 -0
- package/lib/avs/types/index.d.ts +55 -0
- package/lib/avs/types/index.js +1 -0
- package/lib/avs/utils/contracts.d.ts +21 -0
- package/lib/avs/utils/contracts.js +33 -0
- package/lib/avs/utils/register.d.ts +27 -0
- package/lib/avs/utils/register.js +78 -0
- package/lib/avs/utils/tasks.d.ts +22 -0
- package/lib/avs/utils/tasks.js +40 -0
- package/lib/client/create-claim.d.ts +5 -0
- package/lib/client/create-claim.js +437 -0
- package/lib/client/index.d.ts +3 -0
- package/lib/client/index.js +3 -0
- package/lib/client/tunnels/make-rpc-tcp-tunnel.d.ts +16 -0
- package/lib/client/tunnels/make-rpc-tcp-tunnel.js +51 -0
- package/lib/client/tunnels/make-rpc-tls-tunnel.d.ts +26 -0
- package/lib/client/tunnels/make-rpc-tls-tunnel.js +131 -0
- package/lib/client/utils/attestor-pool.d.ts +8 -0
- package/lib/client/utils/attestor-pool.js +25 -0
- package/lib/client/utils/client-socket.d.ts +11 -0
- package/lib/client/utils/client-socket.js +98 -0
- package/lib/client/utils/message-handler.d.ts +4 -0
- package/lib/client/utils/message-handler.js +87 -0
- package/lib/config/index.d.ts +30 -0
- package/lib/config/index.js +43 -0
- package/lib/external-rpc/benchmark.d.ts +1 -0
- package/lib/external-rpc/benchmark.js +69 -0
- package/lib/external-rpc/event-bus.d.ts +7 -0
- package/lib/external-rpc/event-bus.js +14 -0
- package/lib/external-rpc/handle-incoming-msg.d.ts +2 -0
- package/lib/external-rpc/handle-incoming-msg.js +233 -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 +82 -0
- package/lib/external-rpc/jsc-polyfills/2.d.ts +1 -0
- package/lib/external-rpc/jsc-polyfills/2.js +20 -0
- package/lib/external-rpc/jsc-polyfills/event.d.ts +10 -0
- package/lib/external-rpc/jsc-polyfills/event.js +14 -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 +81 -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 +1 -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 +63 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +9 -0
- package/lib/mechain/abis/governanceABI.d.ts +50 -0
- package/lib/mechain/abis/governanceABI.js +458 -0
- package/lib/mechain/abis/taskABI.d.ts +157 -0
- package/lib/mechain/abis/taskABI.js +509 -0
- package/lib/mechain/client/create-claim-on-mechain.d.ts +10 -0
- package/lib/mechain/client/create-claim-on-mechain.js +28 -0
- package/lib/mechain/client/index.d.ts +1 -0
- package/lib/mechain/client/index.js +1 -0
- package/lib/mechain/constants/index.d.ts +3 -0
- package/{src/mechain/constants/index.ts → lib/mechain/constants/index.js} +3 -5
- package/lib/mechain/index.d.ts +2 -0
- package/lib/mechain/index.js +2 -0
- package/lib/mechain/types/index.d.ts +23 -0
- package/lib/mechain/types/index.js +1 -0
- package/lib/proto/api.d.ts +633 -0
- package/lib/proto/api.js +4258 -0
- package/lib/proto/tee-bundle.d.ts +135 -0
- package/lib/proto/tee-bundle.js +1161 -0
- package/lib/providers/http/index.d.ts +18 -0
- package/lib/providers/http/index.js +658 -0
- package/lib/providers/http/patch-parse5-tree.d.ts +6 -0
- package/lib/providers/http/patch-parse5-tree.js +33 -0
- package/lib/providers/http/utils.d.ts +77 -0
- package/lib/providers/http/utils.js +324 -0
- package/lib/providers/index.d.ts +4 -0
- package/lib/providers/index.js +4 -0
- package/lib/scripts/build-browser.d.ts +1 -0
- package/lib/scripts/build-browser.js +37 -0
- package/lib/scripts/build-jsc.d.ts +1 -0
- package/lib/scripts/build-jsc.js +49 -0
- package/lib/scripts/check-avs-registration.d.ts +1 -0
- package/lib/scripts/check-avs-registration.js +26 -0
- package/lib/scripts/fallbacks/crypto.d.ts +1 -0
- package/lib/scripts/fallbacks/crypto.js +1 -0
- package/lib/scripts/fallbacks/empty.d.ts +3 -0
- package/lib/scripts/fallbacks/empty.js +1 -0
- package/lib/scripts/fallbacks/re2.d.ts +1 -0
- package/lib/scripts/fallbacks/re2.js +4 -0
- package/lib/scripts/fallbacks/snarkjs.d.ts +1 -0
- package/lib/scripts/fallbacks/snarkjs.js +1 -0
- package/lib/scripts/generate-provider-types.d.ts +5 -0
- package/lib/scripts/generate-provider-types.js +78 -0
- package/lib/scripts/generate-receipt.d.ts +9 -0
- package/lib/scripts/generate-receipt.js +90 -0
- package/lib/scripts/generate-toprf-keys.d.ts +1 -0
- package/lib/scripts/generate-toprf-keys.js +20 -0
- package/lib/scripts/jsc-cli-rpc.d.ts +1 -0
- package/lib/scripts/jsc-cli-rpc.js +37 -0
- package/lib/scripts/register-avs-operator.d.ts +1 -0
- package/lib/scripts/register-avs-operator.js +4 -0
- package/lib/scripts/start-server.d.ts +1 -0
- package/lib/scripts/start-server.js +13 -0
- package/lib/scripts/update-avs-metadata.d.ts +1 -0
- package/lib/scripts/update-avs-metadata.js +19 -0
- package/lib/scripts/utils.d.ts +1 -0
- package/lib/scripts/utils.js +7 -0
- package/lib/scripts/whitelist-operator.d.ts +1 -0
- package/lib/scripts/whitelist-operator.js +15 -0
- package/lib/server/create-server.d.ts +7 -0
- package/lib/server/create-server.js +122 -0
- package/lib/server/handlers/claimTeeBundle.d.ts +6 -0
- package/lib/server/handlers/claimTeeBundle.js +206 -0
- package/lib/server/handlers/claimTunnel.d.ts +2 -0
- package/lib/server/handlers/claimTunnel.js +73 -0
- package/lib/server/handlers/completeClaimOnChain.d.ts +2 -0
- package/lib/server/handlers/completeClaimOnChain.js +22 -0
- package/lib/server/handlers/createClaimOnChain.d.ts +2 -0
- package/lib/server/handlers/createClaimOnChain.js +26 -0
- package/lib/server/handlers/createTaskOnMechain.d.ts +2 -0
- package/lib/server/handlers/createTaskOnMechain.js +47 -0
- package/lib/server/handlers/createTunnel.d.ts +2 -0
- package/lib/server/handlers/createTunnel.js +93 -0
- package/lib/server/handlers/disconnectTunnel.d.ts +2 -0
- package/lib/server/handlers/disconnectTunnel.js +5 -0
- package/lib/server/handlers/fetchCertificateBytes.d.ts +2 -0
- package/lib/server/handlers/fetchCertificateBytes.js +41 -0
- package/lib/server/handlers/index.d.ts +4 -0
- package/lib/server/handlers/index.js +22 -0
- package/lib/server/handlers/init.d.ts +2 -0
- package/lib/server/handlers/init.js +30 -0
- package/lib/server/handlers/toprf.d.ts +2 -0
- package/lib/server/handlers/toprf.js +16 -0
- package/lib/server/index.d.ts +4 -0
- package/lib/server/index.js +4 -0
- package/lib/server/provider-api.d.ts +9 -0
- package/lib/server/provider-api.js +98 -0
- package/lib/server/provider-store.d.ts +53 -0
- package/lib/server/provider-store.js +80 -0
- package/lib/server/session-api.d.ts +9 -0
- package/lib/server/session-api.js +95 -0
- package/lib/server/session-store.d.ts +14 -0
- package/lib/server/session-store.js +36 -0
- package/lib/server/socket.d.ts +13 -0
- package/lib/server/socket.js +109 -0
- package/lib/server/tunnels/make-tcp-tunnel.d.ts +22 -0
- package/lib/server/tunnels/make-tcp-tunnel.js +177 -0
- package/lib/server/utils/apm.d.ts +11 -0
- package/lib/server/utils/apm.js +36 -0
- package/lib/server/utils/assert-valid-claim-request.d.ts +31 -0
- package/lib/server/utils/assert-valid-claim-request.js +229 -0
- package/lib/server/utils/config-env.d.ts +1 -0
- package/lib/server/utils/config-env.js +4 -0
- package/lib/server/utils/dns.d.ts +1 -0
- package/lib/server/utils/dns.js +18 -0
- package/lib/server/utils/gcp-attestation.d.ts +17 -0
- package/lib/server/utils/gcp-attestation.js +289 -0
- package/lib/server/utils/generics.d.ts +22 -0
- package/lib/server/utils/generics.js +51 -0
- package/lib/server/utils/iso.d.ts +1 -0
- package/lib/server/utils/iso.js +256 -0
- package/lib/server/utils/keep-alive.d.ts +7 -0
- package/lib/server/utils/keep-alive.js +38 -0
- package/lib/server/utils/nitro-attestation.d.ts +33 -0
- package/lib/server/utils/nitro-attestation.js +325 -0
- package/lib/server/utils/process-handshake.d.ts +13 -0
- package/lib/server/utils/process-handshake.js +214 -0
- package/lib/server/utils/proxy-session.d.ts +1 -0
- package/lib/server/utils/proxy-session.js +6 -0
- package/lib/server/utils/tee-oprf-verification.d.ts +22 -0
- package/lib/server/utils/tee-oprf-verification.js +160 -0
- package/lib/server/utils/tee-transcript-reconstruction.d.ts +24 -0
- package/lib/server/utils/tee-transcript-reconstruction.js +187 -0
- package/lib/server/utils/tee-verification.d.ts +27 -0
- package/lib/server/utils/tee-verification.js +365 -0
- package/lib/server/utils/validation.d.ts +2 -0
- package/lib/server/utils/validation.js +38 -0
- package/lib/types/bgp.d.ts +11 -0
- package/lib/types/bgp.js +1 -0
- package/lib/types/claims.d.ts +73 -0
- package/lib/types/claims.js +1 -0
- package/lib/types/client.d.ts +163 -0
- package/lib/types/client.js +1 -0
- package/lib/types/general.d.ts +54 -0
- package/lib/types/general.js +1 -0
- package/lib/types/handlers.d.ts +10 -0
- package/lib/types/handlers.js +1 -0
- package/lib/types/index.d.ts +10 -0
- package/lib/types/index.js +10 -0
- package/lib/types/providers.d.ts +161 -0
- package/lib/types/providers.gen.d.ts +443 -0
- package/lib/types/providers.gen.js +10 -0
- package/lib/types/providers.js +1 -0
- package/lib/types/rpc.d.ts +35 -0
- package/lib/types/rpc.js +1 -0
- package/lib/types/signatures.d.ts +28 -0
- package/lib/types/signatures.js +1 -0
- package/lib/types/tunnel.d.ts +18 -0
- package/lib/types/tunnel.js +1 -0
- package/lib/types/zk.d.ts +28 -0
- package/lib/types/zk.js +1 -0
- package/lib/utils/auth.d.ts +8 -0
- package/lib/utils/auth.js +59 -0
- package/lib/utils/b64-json.d.ts +2 -0
- package/lib/utils/b64-json.js +17 -0
- package/lib/utils/bgp-listener.d.ts +7 -0
- package/lib/utils/bgp-listener.js +119 -0
- package/lib/utils/claims.d.ts +33 -0
- package/lib/utils/claims.js +101 -0
- package/lib/utils/env.d.ts +3 -0
- package/lib/utils/env.js +15 -0
- package/lib/utils/error.d.ts +26 -0
- package/lib/utils/error.js +50 -0
- package/lib/utils/generics.d.ts +114 -0
- package/lib/utils/generics.js +317 -0
- package/lib/utils/http-parser.d.ts +59 -0
- package/lib/utils/http-parser.js +246 -0
- package/lib/utils/index.d.ts +13 -0
- package/lib/utils/index.js +13 -0
- package/lib/utils/logger.d.ts +13 -0
- package/lib/utils/logger.js +91 -0
- package/lib/utils/prepare-packets.d.ts +16 -0
- package/lib/utils/prepare-packets.js +62 -0
- package/lib/utils/redactions.d.ts +62 -0
- package/lib/utils/redactions.js +148 -0
- package/lib/utils/retries.d.ts +12 -0
- package/lib/utils/retries.js +24 -0
- package/lib/utils/signatures/eth.d.ts +2 -0
- package/lib/utils/signatures/eth.js +29 -0
- package/lib/utils/signatures/index.d.ts +5 -0
- package/lib/utils/signatures/index.js +7 -0
- package/lib/utils/socket-base.d.ts +23 -0
- package/lib/utils/socket-base.js +90 -0
- package/lib/utils/tls.d.ts +2 -0
- package/{src/utils/tls.ts → lib/utils/tls.js} +28 -35
- package/lib/utils/ws.d.ts +7 -0
- package/lib/utils/ws.js +22 -0
- package/lib/utils/zk.d.ts +70 -0
- package/lib/utils/zk.js +572 -0
- package/package.json +19 -12
- package/src/avs/abis/avsDirectoryABI.ts +0 -340
- package/src/avs/abis/delegationABI.ts +0 -1
- package/src/avs/abis/registryABI.ts +0 -725
- package/src/avs/client/create-claim-on-avs.ts +0 -206
- package/src/avs/config.ts +0 -25
- package/src/avs/contracts/ReclaimServiceManager.ts +0 -1457
- package/src/avs/contracts/common.ts +0 -44
- package/src/avs/contracts/factories/ReclaimServiceManager__factory.ts +0 -1213
- package/src/avs/tests/test.operator.ts +0 -413
- package/src/avs/tests/utils.ts +0 -51
- package/src/avs/types/index.ts +0 -60
- package/src/avs/utils/contracts.ts +0 -66
- package/src/avs/utils/register.ts +0 -125
- package/src/avs/utils/tasks.ts +0 -76
- package/src/client/create-claim.ts +0 -626
- package/src/client/index.ts +0 -3
- package/src/client/tunnels/make-rpc-tcp-tunnel.ts +0 -78
- package/src/client/tunnels/make-rpc-tls-tunnel.ts +0 -172
- package/src/client/utils/attestor-pool.ts +0 -35
- package/src/client/utils/client-socket.ts +0 -160
- package/src/client/utils/message-handler.ts +0 -116
- package/src/config/index.ts +0 -65
- package/src/external-rpc/benchmark.ts +0 -102
- package/src/external-rpc/event-bus.ts +0 -19
- package/src/external-rpc/global.d.ts +0 -20
- package/src/external-rpc/handle-incoming-msg.ts +0 -308
- package/src/external-rpc/index.ts +0 -3
- package/src/external-rpc/jsc-polyfills/1.ts +0 -117
- package/src/external-rpc/jsc-polyfills/2.ts +0 -24
- package/src/external-rpc/jsc-polyfills/event.ts +0 -16
- package/src/external-rpc/jsc-polyfills/index.ts +0 -2
- package/src/external-rpc/jsc-polyfills/ws.ts +0 -105
- package/src/external-rpc/setup-browser.ts +0 -42
- package/src/external-rpc/setup-jsc.ts +0 -48
- package/src/external-rpc/types.ts +0 -289
- package/src/external-rpc/utils.ts +0 -126
- package/src/external-rpc/zk.ts +0 -79
- package/src/index.ts +0 -9
- package/src/mechain/abis/governanceABI.ts +0 -458
- package/src/mechain/abis/taskABI.ts +0 -509
- package/src/mechain/client/create-claim-on-mechain.ts +0 -52
- package/src/mechain/client/index.ts +0 -1
- package/src/mechain/index.ts +0 -2
- package/src/mechain/types/index.ts +0 -29
- package/src/proto/api.ts +0 -5285
- package/src/proto/tee-bundle.ts +0 -1413
- package/src/providers/http/index.ts +0 -873
- package/src/providers/http/patch-parse5-tree.ts +0 -49
- package/src/providers/http/utils.ts +0 -439
- package/src/providers/index.ts +0 -8
- package/src/scripts/build-browser.sh +0 -9
- package/src/scripts/build-browser.ts +0 -40
- package/src/scripts/build-jsc.ts +0 -55
- package/src/scripts/check-avs-registration.ts +0 -38
- package/src/scripts/contract-data-gen.sh +0 -8
- package/src/scripts/fallbacks/crypto.ts +0 -1
- package/src/scripts/fallbacks/empty.ts +0 -2
- package/src/scripts/fallbacks/re2.ts +0 -5
- package/src/scripts/fallbacks/snarkjs.ts +0 -5
- package/src/scripts/generate-certs.sh +0 -11
- package/src/scripts/generate-proto.sh +0 -5
- package/src/scripts/generate-provider-types.ts +0 -121
- package/src/scripts/generate-receipt.ts +0 -138
- package/src/scripts/generate-toprf-keys.ts +0 -30
- package/src/scripts/jsc-cli-rpc.ts +0 -48
- package/src/scripts/register-avs-operator.ts +0 -5
- package/src/scripts/start-server.ts +0 -17
- package/src/scripts/update-avs-metadata.ts +0 -26
- package/src/scripts/utils.ts +0 -8
- package/src/scripts/whitelist-operator.ts +0 -22
- package/src/server/create-server.ts +0 -169
- package/src/server/handlers/claimTeeBundle.ts +0 -308
- package/src/server/handlers/claimTunnel.ts +0 -106
- package/src/server/handlers/completeClaimOnChain.ts +0 -36
- package/src/server/handlers/createClaimOnChain.ts +0 -39
- package/src/server/handlers/createTaskOnMechain.ts +0 -80
- package/src/server/handlers/createTunnel.ts +0 -128
- package/src/server/handlers/disconnectTunnel.ts +0 -11
- package/src/server/handlers/fetchCertificateBytes.ts +0 -66
- package/src/server/handlers/index.ts +0 -24
- package/src/server/handlers/init.ts +0 -46
- package/src/server/handlers/toprf.ts +0 -25
- package/src/server/index.ts +0 -4
- package/src/server/provider-api.ts +0 -118
- package/src/server/provider-store.ts +0 -117
- package/src/server/session-api.ts +0 -115
- package/src/server/session-store.ts +0 -60
- package/src/server/socket.ts +0 -156
- package/src/server/tunnels/make-tcp-tunnel.ts +0 -275
- package/src/server/utils/apm.ts +0 -49
- package/src/server/utils/assert-valid-claim-request.ts +0 -375
- package/src/server/utils/config-env.ts +0 -6
- package/src/server/utils/dns.ts +0 -25
- package/src/server/utils/gcp-attestation.ts +0 -415
- package/src/server/utils/generics.ts +0 -68
- package/src/server/utils/iso.ts +0 -258
- package/src/server/utils/keep-alive.ts +0 -50
- package/src/server/utils/nitro-attestation.ts +0 -396
- package/src/server/utils/process-handshake.ts +0 -311
- package/src/server/utils/proxy-session.ts +0 -6
- package/src/server/utils/tee-oprf-verification.ts +0 -231
- package/src/server/utils/tee-transcript-reconstruction.ts +0 -254
- package/src/server/utils/tee-verification.ts +0 -513
- package/src/server/utils/validation.ts +0 -57
- package/src/tests/auth.test.ts +0 -105
- package/src/tests/bgp-listener.test.ts +0 -193
- package/src/tests/claim-creation.test.ts +0 -415
- package/src/tests/describe-with-server.ts +0 -94
- package/src/tests/gcp-attestation.test.ts +0 -206
- package/src/tests/http-parser.test.ts +0 -135
- package/src/tests/http-provider-utils.test.ts +0 -3306
- package/src/tests/http-provider.test.ts +0 -125
- package/src/tests/jsc.test_mac.ts +0 -296
- package/src/tests/mock-provider-server.ts +0 -106
- package/src/tests/mocks.ts +0 -25
- package/src/tests/proof_bundle.bin +0 -0
- package/src/tests/rpc-communication.test.ts +0 -115
- package/src/tests/rpc-tunnel.test.ts +0 -239
- package/src/tests/signatures.test.ts +0 -37
- package/src/tests/tcp-tunnel.test.ts +0 -154
- package/src/tests/tee-bundle.test.ts +0 -321
- package/src/tests/tee-signatures.test.ts +0 -81
- package/src/tests/utils.ts +0 -108
- package/src/tests/verification_bundle.pb +0 -0
- package/src/tests/verification_bundle_tee.pb +0 -0
- package/src/tests/zk.test.ts +0 -453
- package/src/types/bgp.ts +0 -17
- package/src/types/claims.ts +0 -79
- package/src/types/client.ts +0 -205
- package/src/types/general.ts +0 -61
- package/src/types/handlers.ts +0 -16
- package/src/types/index.ts +0 -10
- package/src/types/providers.gen.ts +0 -135
- package/src/types/providers.ts +0 -203
- package/src/types/rpc.ts +0 -46
- package/src/types/signatures.ts +0 -29
- package/src/types/tunnel.ts +0 -25
- package/src/types/zk.ts +0 -31
- package/src/utils/auth.ts +0 -92
- package/src/utils/b64-json.ts +0 -25
- package/src/utils/bgp-listener.ts +0 -159
- package/src/utils/claims.ts +0 -132
- package/src/utils/env.ts +0 -21
- package/src/utils/error.ts +0 -76
- package/src/utils/generics.ts +0 -429
- package/src/utils/http-parser.ts +0 -312
- package/src/utils/index.ts +0 -13
- package/src/utils/logger.ts +0 -114
- package/src/utils/prepare-packets.ts +0 -98
- package/src/utils/redactions.ts +0 -203
- package/src/utils/retries.ts +0 -41
- package/src/utils/signatures/eth.ts +0 -35
- package/src/utils/signatures/index.ts +0 -11
- package/src/utils/socket-base.ts +0 -132
- package/src/utils/ws.ts +0 -30
- package/src/utils/zk.ts +0 -908
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { asciiToUint8Array, concatenateUint8Arrays } from '@joclaim/tls';
|
|
2
|
+
import { findIndexInUint8Array, uint8ArrayToStr } from '../utils/generics.js';
|
|
3
|
+
import { REDACTION_CHAR_CODE } from '../utils/redactions.js';
|
|
4
|
+
const HTTP_HEADER_LINE_END = asciiToUint8Array('\r\n');
|
|
5
|
+
/**
|
|
6
|
+
* parses http/1.1 responses
|
|
7
|
+
*/
|
|
8
|
+
export function makeHttpResponseParser() {
|
|
9
|
+
/** the HTTP response data */
|
|
10
|
+
const res = {
|
|
11
|
+
statusCode: 0,
|
|
12
|
+
statusMessage: '',
|
|
13
|
+
headers: {},
|
|
14
|
+
body: new Uint8Array(),
|
|
15
|
+
complete: false,
|
|
16
|
+
headersComplete: false,
|
|
17
|
+
headerIndices: new Map(),
|
|
18
|
+
headerEndIdx: 0
|
|
19
|
+
};
|
|
20
|
+
let remainingBodyBytes = 0;
|
|
21
|
+
let isChunked = false;
|
|
22
|
+
let remaining = new Uint8Array();
|
|
23
|
+
let currentByteIdx = 0;
|
|
24
|
+
return {
|
|
25
|
+
res,
|
|
26
|
+
/**
|
|
27
|
+
* Parse the next chunk of data
|
|
28
|
+
* @param data the data to parse
|
|
29
|
+
*/
|
|
30
|
+
onChunk(data) {
|
|
31
|
+
// concatenate the remaining data from the last chunk
|
|
32
|
+
remaining = concatenateUint8Arrays([remaining, data]);
|
|
33
|
+
// if we don't have the headers yet, keep reading lines
|
|
34
|
+
// as each header is in a line
|
|
35
|
+
if (!res.headersComplete) {
|
|
36
|
+
for (let line = getLine(); typeof line !== 'undefined'; line = getLine()) {
|
|
37
|
+
// first line is the HTTP version, status code & message
|
|
38
|
+
if (!res.statusCode) {
|
|
39
|
+
const [, statusCode, statusMessage] = line.match(/HTTP\/\d\.\d (\d+) (.*)/) || [];
|
|
40
|
+
res.statusCode = Number(statusCode);
|
|
41
|
+
res.statusMessage = statusMessage;
|
|
42
|
+
res.statusLineEndIndex = currentByteIdx - HTTP_HEADER_LINE_END.length;
|
|
43
|
+
}
|
|
44
|
+
else if (line === '') { // empty line signifies end of headers
|
|
45
|
+
res.headersComplete = true;
|
|
46
|
+
res.headerEndIdx = currentByteIdx - 4;
|
|
47
|
+
// if the response is chunked, we need to process the body differently
|
|
48
|
+
if (res.headers['transfer-encoding']?.includes('chunked')) {
|
|
49
|
+
isChunked = true;
|
|
50
|
+
res.chunks = [];
|
|
51
|
+
break;
|
|
52
|
+
// if the response has a content-length, we know how many bytes to read
|
|
53
|
+
}
|
|
54
|
+
else if (res.headers['content-length']) {
|
|
55
|
+
remainingBodyBytes = Number(res.headers['content-length']);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
remainingBodyBytes = -1;
|
|
60
|
+
break;
|
|
61
|
+
// otherwise,
|
|
62
|
+
// no content-length, no chunked transfer encoding
|
|
63
|
+
// means wait till the stream ends
|
|
64
|
+
// https://stackoverflow.com/a/11376887
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else if (!res.complete) { // parse the header
|
|
68
|
+
const [key, value] = line.split(': ');
|
|
69
|
+
res.headers[key.toLowerCase()] = value;
|
|
70
|
+
res.headerIndices[key.toLowerCase()] = {
|
|
71
|
+
fromIndex: currentByteIdx - line.length - HTTP_HEADER_LINE_END.length,
|
|
72
|
+
toIndex: currentByteIdx - HTTP_HEADER_LINE_END.length
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
throw new Error('got more data after response was complete');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (res.headersComplete) {
|
|
81
|
+
if (remainingBodyBytes) {
|
|
82
|
+
readBody();
|
|
83
|
+
// if no more body bytes to read,
|
|
84
|
+
// and the response was not chunked we're done
|
|
85
|
+
if (!remainingBodyBytes && !isChunked) {
|
|
86
|
+
res.complete = true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (res.headers['content-length'] === '0') {
|
|
90
|
+
res.complete = true;
|
|
91
|
+
}
|
|
92
|
+
if (isChunked) {
|
|
93
|
+
for (let line = getLine(); typeof line !== 'undefined'; line = getLine()) {
|
|
94
|
+
if (line === '') {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
const chunkSize = Number.parseInt(line, 16);
|
|
98
|
+
// if chunk size is 0, we're done
|
|
99
|
+
if (!chunkSize) {
|
|
100
|
+
res.complete = true;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
res.chunks?.push({
|
|
104
|
+
fromIndex: currentByteIdx,
|
|
105
|
+
toIndex: currentByteIdx + chunkSize,
|
|
106
|
+
});
|
|
107
|
+
// otherwise read the chunk
|
|
108
|
+
remainingBodyBytes = chunkSize;
|
|
109
|
+
readBody();
|
|
110
|
+
// if we read all the data we had,
|
|
111
|
+
// but there's still data left,
|
|
112
|
+
// break the loop and wait for the next chunk
|
|
113
|
+
if (remainingBodyBytes) {
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
/**
|
|
121
|
+
* Call to prevent further parsing; indicating the end of the request
|
|
122
|
+
* Checks that the response is valid & complete, otherwise throws an error
|
|
123
|
+
*/
|
|
124
|
+
streamEnded() {
|
|
125
|
+
if (!res.headersComplete) {
|
|
126
|
+
throw new Error('stream ended before headers were complete');
|
|
127
|
+
}
|
|
128
|
+
if (remaining.length) {
|
|
129
|
+
throw new Error('stream ended before remaining data arrived');
|
|
130
|
+
}
|
|
131
|
+
if (remainingBodyBytes > 0) {
|
|
132
|
+
throw new Error('stream ended before all body bytes were received');
|
|
133
|
+
}
|
|
134
|
+
res.complete = true;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
function readBody() {
|
|
138
|
+
if (res.complete) {
|
|
139
|
+
throw new Error('got more data after response was complete');
|
|
140
|
+
}
|
|
141
|
+
if (!res.bodyStartIndex) {
|
|
142
|
+
res.bodyStartIndex = currentByteIdx;
|
|
143
|
+
}
|
|
144
|
+
let bytesToCopy;
|
|
145
|
+
if (remainingBodyBytes === -1) {
|
|
146
|
+
// all bytes are body bytes
|
|
147
|
+
bytesToCopy = remaining.length;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
// take the number of bytes we need to read, or the number of bytes remaining
|
|
151
|
+
// and append to the bytes of the body
|
|
152
|
+
bytesToCopy = Math.min(remainingBodyBytes, remaining.length);
|
|
153
|
+
remainingBodyBytes -= bytesToCopy;
|
|
154
|
+
}
|
|
155
|
+
res.body = concatenateUint8Arrays([
|
|
156
|
+
res.body,
|
|
157
|
+
remaining.slice(0, bytesToCopy)
|
|
158
|
+
]);
|
|
159
|
+
remaining = remaining.slice(bytesToCopy);
|
|
160
|
+
currentByteIdx += bytesToCopy;
|
|
161
|
+
}
|
|
162
|
+
function getLine() {
|
|
163
|
+
// find end of line, if it exists
|
|
164
|
+
// otherwise return undefined
|
|
165
|
+
const idx = findIndexInUint8Array(remaining, HTTP_HEADER_LINE_END);
|
|
166
|
+
if (idx === -1) {
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
const line = uint8ArrayToStr(remaining.slice(0, idx));
|
|
170
|
+
remaining = remaining.slice(idx + HTTP_HEADER_LINE_END.length);
|
|
171
|
+
currentByteIdx += idx + HTTP_HEADER_LINE_END.length;
|
|
172
|
+
return line;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Read the HTTP request from a TLS receipt transcript.
|
|
177
|
+
* @param receipt the transcript to read from or application messages if they were extracted beforehand
|
|
178
|
+
* @returns the parsed HTTP request
|
|
179
|
+
*/
|
|
180
|
+
export function getHttpRequestDataFromTranscript(receipt) {
|
|
181
|
+
const clientMsgs = receipt
|
|
182
|
+
.filter(s => s.sender === 'client');
|
|
183
|
+
// if the first message is redacted, we can't parse it
|
|
184
|
+
// as we don't know what the request was
|
|
185
|
+
if (clientMsgs[0].message[0] === REDACTION_CHAR_CODE) {
|
|
186
|
+
throw new Error('First client message request is redacted. Cannot parse');
|
|
187
|
+
}
|
|
188
|
+
const request = {
|
|
189
|
+
method: '',
|
|
190
|
+
url: '',
|
|
191
|
+
protocol: '',
|
|
192
|
+
headers: {}
|
|
193
|
+
};
|
|
194
|
+
let requestBuffer = concatenateUint8Arrays(clientMsgs.map(m => m.message));
|
|
195
|
+
// keep reading lines until we get to the end of the headers
|
|
196
|
+
for (let line = getLine(); typeof line !== 'undefined'; line = getLine()) {
|
|
197
|
+
if (line === '') {
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
if (!request.method) {
|
|
201
|
+
const [, method, url, protocol] = line.match(/(\w+) (.*) (.*)/) || [];
|
|
202
|
+
request.method = method.toLowerCase();
|
|
203
|
+
request.url = url;
|
|
204
|
+
request.protocol = protocol;
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
let keyIdx = line.indexOf(':');
|
|
208
|
+
if (keyIdx === -1) {
|
|
209
|
+
keyIdx = line.length - 1;
|
|
210
|
+
}
|
|
211
|
+
const key = line.slice(0, keyIdx)
|
|
212
|
+
.toLowerCase()
|
|
213
|
+
.trim();
|
|
214
|
+
const value = line.slice(keyIdx + 1)
|
|
215
|
+
.trim();
|
|
216
|
+
const oldValue = request.headers[key];
|
|
217
|
+
if (typeof oldValue === 'string') {
|
|
218
|
+
request.headers[key] = [oldValue, value];
|
|
219
|
+
}
|
|
220
|
+
else if (Array.isArray(oldValue)) {
|
|
221
|
+
oldValue.push(value);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
request.headers[key] = value;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
//the rest is request body
|
|
229
|
+
if (requestBuffer.length) {
|
|
230
|
+
request.body = requestBuffer;
|
|
231
|
+
}
|
|
232
|
+
if (!request.method) {
|
|
233
|
+
throw new Error('Client request is incomplete');
|
|
234
|
+
}
|
|
235
|
+
return request;
|
|
236
|
+
function getLine() {
|
|
237
|
+
const idx = findIndexInUint8Array(requestBuffer, HTTP_HEADER_LINE_END);
|
|
238
|
+
if (idx === -1) {
|
|
239
|
+
return undefined;
|
|
240
|
+
}
|
|
241
|
+
const line = uint8ArrayToStr(requestBuffer.slice(0, idx));
|
|
242
|
+
requestBuffer = requestBuffer
|
|
243
|
+
.slice(idx + HTTP_HEADER_LINE_END.length);
|
|
244
|
+
return line;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './generics.ts';
|
|
2
|
+
export * from './logger.ts';
|
|
3
|
+
export * from './redactions.ts';
|
|
4
|
+
export * from './http-parser.ts';
|
|
5
|
+
export * from './zk.ts';
|
|
6
|
+
export * from './claims.ts';
|
|
7
|
+
export * from './error.ts';
|
|
8
|
+
export * from './prepare-packets.ts';
|
|
9
|
+
export * from './signatures/index.ts';
|
|
10
|
+
export * from './auth.ts';
|
|
11
|
+
export * from './b64-json.ts';
|
|
12
|
+
export * from './bgp-listener.ts';
|
|
13
|
+
export * from './tls.ts';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./generics.js";
|
|
2
|
+
export * from "./logger.js";
|
|
3
|
+
export * from "./redactions.js";
|
|
4
|
+
export * from "./http-parser.js";
|
|
5
|
+
export * from "./zk.js";
|
|
6
|
+
export * from "./claims.js";
|
|
7
|
+
export * from "./error.js";
|
|
8
|
+
export * from "./prepare-packets.js";
|
|
9
|
+
export * from "./signatures/index.js";
|
|
10
|
+
export * from "./auth.js";
|
|
11
|
+
export * from "./b64-json.js";
|
|
12
|
+
export * from "./bgp-listener.js";
|
|
13
|
+
export * from "./tls.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { LogLevel } from '../types/index.js';
|
|
2
|
+
export declare let logger: import("pino").Logger<never, boolean>;
|
|
3
|
+
/**
|
|
4
|
+
* Creates a logger instance with optional redaction of PII.
|
|
5
|
+
* Replaces default logger
|
|
6
|
+
* See PII_PROPERTIES for the list of properties that will be redacted.
|
|
7
|
+
*
|
|
8
|
+
* @param redactPii - whether to redact PII from logs
|
|
9
|
+
* @param level - the log level to use
|
|
10
|
+
* @param onLog - a callback to call when a log is written
|
|
11
|
+
*/
|
|
12
|
+
export declare function makeLogger(redactPii: boolean, level?: LogLevel, onLog?: (level: LogLevel, log: any) => void): import("pino").Logger<never, boolean>;
|
|
13
|
+
export declare function redact(json: any): any;
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
export let logger = pino();
|
|
7
|
+
makeLogger(false, envLevel);
|
|
8
|
+
/**
|
|
9
|
+
* Creates a logger instance with optional redaction of PII.
|
|
10
|
+
* Replaces default logger
|
|
11
|
+
* See PII_PROPERTIES for the list of properties that will be redacted.
|
|
12
|
+
*
|
|
13
|
+
* @param redactPii - whether to redact PII from logs
|
|
14
|
+
* @param level - the log level to use
|
|
15
|
+
* @param onLog - a callback to call when a log is written
|
|
16
|
+
*/
|
|
17
|
+
export function makeLogger(redactPii, level, onLog) {
|
|
18
|
+
const opts = {
|
|
19
|
+
// Log human readable time stamps instead of epoch time
|
|
20
|
+
timestamp: stdTimeFunctions.isoTime,
|
|
21
|
+
};
|
|
22
|
+
if (redactPii) {
|
|
23
|
+
opts.formatters = { log: redact };
|
|
24
|
+
opts.serializers = { redact };
|
|
25
|
+
opts.browser = {
|
|
26
|
+
write: {
|
|
27
|
+
fatal: log => writeLog('fatal', log),
|
|
28
|
+
error: log => writeLog('error', log),
|
|
29
|
+
warn: log => writeLog('warn', log),
|
|
30
|
+
info: log => writeLog('info', log),
|
|
31
|
+
debug: log => writeLog('debug', log),
|
|
32
|
+
trace: log => writeLog('trace', log),
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const pLogger = pino(opts);
|
|
37
|
+
pLogger.level = level || 'info';
|
|
38
|
+
logger = pLogger;
|
|
39
|
+
return pLogger;
|
|
40
|
+
function writeLog(level, log) {
|
|
41
|
+
log = redact(log);
|
|
42
|
+
const { msg, ...obj } = log;
|
|
43
|
+
if (console[level]) {
|
|
44
|
+
console[level](obj, msg);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
console.log(obj, msg);
|
|
48
|
+
}
|
|
49
|
+
onLog?.(level, log);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function isObjectProperty(property) {
|
|
53
|
+
return (typeof property) === 'object'
|
|
54
|
+
&& !Array.isArray(property)
|
|
55
|
+
&& property !== null;
|
|
56
|
+
}
|
|
57
|
+
function getReplacer() {
|
|
58
|
+
// Store references to previously visited objects
|
|
59
|
+
const references = new WeakSet();
|
|
60
|
+
return function (key, value) {
|
|
61
|
+
const isObject = (typeof value) === 'object' && value !== null;
|
|
62
|
+
if (isObject) {
|
|
63
|
+
if (references.has(value)) {
|
|
64
|
+
return '[CIRCULAR]';
|
|
65
|
+
}
|
|
66
|
+
references.add(value);
|
|
67
|
+
}
|
|
68
|
+
return value;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export function redact(json) {
|
|
72
|
+
const isObject = isObjectProperty(json);
|
|
73
|
+
if (!isObject && !Array.isArray(json)) {
|
|
74
|
+
return json;
|
|
75
|
+
}
|
|
76
|
+
const redacted = JSON.parse(JSON.stringify(json, getReplacer()));
|
|
77
|
+
for (const prop in redacted) {
|
|
78
|
+
if (PII_PROPERTIES.includes(prop)) {
|
|
79
|
+
redacted[prop] = redactedText;
|
|
80
|
+
}
|
|
81
|
+
if (Array.isArray(redacted[prop])) {
|
|
82
|
+
for (const [index, value] of redacted[prop].entries()) {
|
|
83
|
+
redacted[prop][index] = redact(value);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else if (isObjectProperty(redacted[prop])) {
|
|
87
|
+
redacted[prop] = redact(redacted[prop]);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return redacted;
|
|
91
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CipherSuite, TLSPacketContext } from '@joclaim/tls';
|
|
2
|
+
import type { ClaimTunnelRequest_TranscriptMessage as TranscriptMessage } from '../proto/api.js';
|
|
3
|
+
import type { CompleteTLSPacket, Logger, MessageRevealInfo, PrepareZKProofsBaseOpts, Transcript } from '../types/index.js';
|
|
4
|
+
export type PreparePacketsForRevealOpts = {
|
|
5
|
+
cipherSuite: CipherSuite;
|
|
6
|
+
logger: Logger;
|
|
7
|
+
/**
|
|
8
|
+
* Progress of Zk proof generation
|
|
9
|
+
*/
|
|
10
|
+
onZkProgress?(blocksDone: number, totalBlocks: number): void;
|
|
11
|
+
} & PrepareZKProofsBaseOpts;
|
|
12
|
+
/**
|
|
13
|
+
* Prepares the packets for reveal to the server
|
|
14
|
+
* according to the specified reveal type
|
|
15
|
+
*/
|
|
16
|
+
export declare function preparePacketsForReveal(tlsTranscript: Transcript<CompleteTLSPacket>, reveals: Map<TLSPacketContext, MessageRevealInfo>, { onZkProgress, ...opts }: PreparePacketsForRevealOpts): Promise<TranscriptMessage[]>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { concatenateUint8Arrays, crypto } from '@joclaim/tls';
|
|
2
|
+
import { TranscriptMessageSenderType } from '../proto/api.js';
|
|
3
|
+
import { makeZkProofGenerator } from '../utils/zk.js';
|
|
4
|
+
/**
|
|
5
|
+
* Prepares the packets for reveal to the server
|
|
6
|
+
* according to the specified reveal type
|
|
7
|
+
*/
|
|
8
|
+
export async function preparePacketsForReveal(tlsTranscript, reveals, { onZkProgress, ...opts }) {
|
|
9
|
+
const transcript = [];
|
|
10
|
+
const proofGenerator = await makeZkProofGenerator(opts);
|
|
11
|
+
let zkPacketsDone = 0;
|
|
12
|
+
await Promise.all(tlsTranscript.map(async ({ message, sender }, i) => {
|
|
13
|
+
const msg = {
|
|
14
|
+
sender: sender === 'client'
|
|
15
|
+
? TranscriptMessageSenderType.TRANSCRIPT_MESSAGE_SENDER_TYPE_CLIENT
|
|
16
|
+
: TranscriptMessageSenderType.TRANSCRIPT_MESSAGE_SENDER_TYPE_SERVER,
|
|
17
|
+
message: message.data,
|
|
18
|
+
reveal: undefined
|
|
19
|
+
};
|
|
20
|
+
transcript.push(msg);
|
|
21
|
+
const reveal = reveals.get(message);
|
|
22
|
+
if (!reveal || message.type === 'plaintext') {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
switch (reveal?.type) {
|
|
26
|
+
case 'complete':
|
|
27
|
+
msg.reveal = {
|
|
28
|
+
directReveal: {
|
|
29
|
+
key: await crypto.exportKey(message.encKey),
|
|
30
|
+
iv: message.fixedIv,
|
|
31
|
+
recordNumber: message.recordNumber,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
break;
|
|
35
|
+
case 'zk':
|
|
36
|
+
// the redacted section can be smaller than the actual
|
|
37
|
+
// plaintext encrypted, in case of TLS1.3 as it has a
|
|
38
|
+
// content type suffix
|
|
39
|
+
reveal.redactedPlaintext = concatenateUint8Arrays([
|
|
40
|
+
reveal.redactedPlaintext,
|
|
41
|
+
message.plaintext.slice(reveal.redactedPlaintext.length)
|
|
42
|
+
]);
|
|
43
|
+
await proofGenerator.addPacketToProve(message, reveal, (proofs, toprfs) => (msg.reveal = { zkReveal: { proofs, toprfs } }), () => {
|
|
44
|
+
const next = tlsTranscript
|
|
45
|
+
.slice(i + 1)
|
|
46
|
+
.find(t => t.sender === sender);
|
|
47
|
+
return next?.message;
|
|
48
|
+
});
|
|
49
|
+
break;
|
|
50
|
+
default:
|
|
51
|
+
// no reveal
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}));
|
|
55
|
+
const zkPacketsTotal = proofGenerator.getTotalChunksToProve();
|
|
56
|
+
onZkProgress?.(zkPacketsDone, zkPacketsTotal);
|
|
57
|
+
await proofGenerator.generateProofs(() => {
|
|
58
|
+
zkPacketsDone += 1;
|
|
59
|
+
onZkProgress?.(zkPacketsDone, zkPacketsTotal);
|
|
60
|
+
});
|
|
61
|
+
return transcript;
|
|
62
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { ArraySlice, RedactedOrHashedArraySlice, TOPRFProofParams } from '../types/index.js';
|
|
2
|
+
export declare const REDACTION_CHAR = "*";
|
|
3
|
+
export declare const REDACTION_CHAR_CODE: number;
|
|
4
|
+
type SliceWithReveal<T> = {
|
|
5
|
+
block: T;
|
|
6
|
+
redactedPlaintext: Uint8Array;
|
|
7
|
+
/**
|
|
8
|
+
* If the block has some TOPRF claims -- they'll be set here
|
|
9
|
+
*/
|
|
10
|
+
toprfs?: TOPRFProofParams[];
|
|
11
|
+
/**
|
|
12
|
+
* If text was replaced in the previous block w TOPRF but
|
|
13
|
+
* it overshot into this block. The "length" specifies how much
|
|
14
|
+
* of it got overshot into this block
|
|
15
|
+
*/
|
|
16
|
+
overshotToprfFromPrevBlock?: {
|
|
17
|
+
length: number;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export type RevealedSlices<T> = 'all' | SliceWithReveal<T>[];
|
|
21
|
+
/**
|
|
22
|
+
* Check if a redacted string is congruent with the original string.
|
|
23
|
+
* @param redacted the redacted content, redacted content is replaced by '*'
|
|
24
|
+
* @param original the original content
|
|
25
|
+
*/
|
|
26
|
+
export declare function isRedactionCongruent<T extends string | Uint8Array>(redacted: T, original: T): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Is the string fully redacted?
|
|
29
|
+
*/
|
|
30
|
+
export declare function isFullyRedacted<T extends string | Uint8Array>(redacted: T): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Given some plaintext blocks and a redaction function, return the blocks that
|
|
33
|
+
* need to be revealed to the other party
|
|
34
|
+
*
|
|
35
|
+
* Use case: we get the response for a request in several blocks, and want to redact
|
|
36
|
+
* pieces that go through multiple blocks. We can use this function to get the
|
|
37
|
+
* blocks that need to be revealed to the other party
|
|
38
|
+
*
|
|
39
|
+
* @example if we received ["secret is 12","345","678. Thanks"]. We'd want
|
|
40
|
+
* to redact the "12345678" and reveal the rest. We'd pass in the blocks and
|
|
41
|
+
* the redact function will return the redactions, namely [10,19].
|
|
42
|
+
* The function will return the blocks ["secret is **","***. Thanks"].
|
|
43
|
+
* The middle block is fully redacted, so it's not returned
|
|
44
|
+
*
|
|
45
|
+
* @param blocks blocks to reveal
|
|
46
|
+
* @param redact function that returns the redactions
|
|
47
|
+
* @returns blocks to reveal
|
|
48
|
+
*/
|
|
49
|
+
export declare function getBlocksToReveal<T extends {
|
|
50
|
+
plaintext: Uint8Array;
|
|
51
|
+
}>(blocks: T[], redact: (total: Uint8Array) => RedactedOrHashedArraySlice[], performOprf: (plaintext: Uint8Array) => Promise<TOPRFProofParams>): Promise<"all" | SliceWithReveal<T>[]>;
|
|
52
|
+
/**
|
|
53
|
+
* Redact the following slices from the total
|
|
54
|
+
*/
|
|
55
|
+
export declare function redactSlices(total: Uint8Array, slices: ArraySlice[]): Uint8Array<ArrayBuffer>;
|
|
56
|
+
/**
|
|
57
|
+
* Converts the binary hash to an ASCII string of the expected length.
|
|
58
|
+
* If the hash is shorter than the expected length, it will be padded with
|
|
59
|
+
* '0' characters. If it's longer, it will be truncated.
|
|
60
|
+
*/
|
|
61
|
+
export declare function binaryHashToStr(hash: Uint8Array, expLength: number): string;
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { base64Encode } from '@bufbuild/protobuf/wire';
|
|
2
|
+
import { concatenateUint8Arrays } from '@joclaim/tls';
|
|
3
|
+
export const REDACTION_CHAR = '*';
|
|
4
|
+
export const REDACTION_CHAR_CODE = REDACTION_CHAR.charCodeAt(0);
|
|
5
|
+
/**
|
|
6
|
+
* Check if a redacted string is congruent with the original string.
|
|
7
|
+
* @param redacted the redacted content, redacted content is replaced by '*'
|
|
8
|
+
* @param original the original content
|
|
9
|
+
*/
|
|
10
|
+
export function isRedactionCongruent(redacted, original) {
|
|
11
|
+
// eslint-disable-next-line unicorn/no-for-loop
|
|
12
|
+
for (let i = 0; i < redacted.length; i++) {
|
|
13
|
+
const element = redacted[i];
|
|
14
|
+
const areSame = element === original[i]
|
|
15
|
+
|| (typeof element === 'string' && element === REDACTION_CHAR)
|
|
16
|
+
|| (typeof element === 'number' && element === REDACTION_CHAR_CODE);
|
|
17
|
+
if (!areSame) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Is the string fully redacted?
|
|
25
|
+
*/
|
|
26
|
+
export function isFullyRedacted(redacted) {
|
|
27
|
+
for (const element of redacted) {
|
|
28
|
+
if (element !== REDACTION_CHAR
|
|
29
|
+
&& element !== REDACTION_CHAR_CODE) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Given some plaintext blocks and a redaction function, return the blocks that
|
|
37
|
+
* need to be revealed to the other party
|
|
38
|
+
*
|
|
39
|
+
* Use case: we get the response for a request in several blocks, and want to redact
|
|
40
|
+
* pieces that go through multiple blocks. We can use this function to get the
|
|
41
|
+
* blocks that need to be revealed to the other party
|
|
42
|
+
*
|
|
43
|
+
* @example if we received ["secret is 12","345","678. Thanks"]. We'd want
|
|
44
|
+
* to redact the "12345678" and reveal the rest. We'd pass in the blocks and
|
|
45
|
+
* the redact function will return the redactions, namely [10,19].
|
|
46
|
+
* The function will return the blocks ["secret is **","***. Thanks"].
|
|
47
|
+
* The middle block is fully redacted, so it's not returned
|
|
48
|
+
*
|
|
49
|
+
* @param blocks blocks to reveal
|
|
50
|
+
* @param redact function that returns the redactions
|
|
51
|
+
* @returns blocks to reveal
|
|
52
|
+
*/
|
|
53
|
+
export async function getBlocksToReveal(blocks, redact, performOprf) {
|
|
54
|
+
const slicesWithReveal = blocks.map(block => ({
|
|
55
|
+
block,
|
|
56
|
+
// copy the plaintext to avoid mutating the original
|
|
57
|
+
redactedPlaintext: new Uint8Array(block.plaintext)
|
|
58
|
+
}));
|
|
59
|
+
const total = concatenateUint8Arrays(blocks.map(b => b.plaintext));
|
|
60
|
+
const redactions = redact(total);
|
|
61
|
+
if (!redactions.length) {
|
|
62
|
+
return 'all';
|
|
63
|
+
}
|
|
64
|
+
let blockIdx = 0;
|
|
65
|
+
let cursorInBlock = 0;
|
|
66
|
+
let cursor = 0;
|
|
67
|
+
for (const redaction of redactions) {
|
|
68
|
+
await redactBlocks(redaction);
|
|
69
|
+
}
|
|
70
|
+
// only reveal blocks that have some data to reveal,
|
|
71
|
+
// or are completely plaintext
|
|
72
|
+
return slicesWithReveal
|
|
73
|
+
.filter(s => !isFullyRedacted(s.redactedPlaintext));
|
|
74
|
+
async function redactBlocks(slice) {
|
|
75
|
+
while (cursor < slice.fromIndex) {
|
|
76
|
+
advance();
|
|
77
|
+
}
|
|
78
|
+
if (slice.hash) {
|
|
79
|
+
const plaintext = total.slice(slice.fromIndex, slice.toIndex);
|
|
80
|
+
const { nullifier, responses, mask } = await performOprf(plaintext);
|
|
81
|
+
// set the TOPRF claim on the first blocks this
|
|
82
|
+
// redaction covers
|
|
83
|
+
const toprf = {
|
|
84
|
+
nullifier,
|
|
85
|
+
responses,
|
|
86
|
+
dataLocation: {
|
|
87
|
+
fromIndex: cursorInBlock,
|
|
88
|
+
length: slice.toIndex - slice.fromIndex
|
|
89
|
+
},
|
|
90
|
+
mask,
|
|
91
|
+
plaintext
|
|
92
|
+
};
|
|
93
|
+
const startBlockIdx = blockIdx;
|
|
94
|
+
const block = slicesWithReveal[blockIdx];
|
|
95
|
+
block.toprfs ||= [];
|
|
96
|
+
block.toprfs.push(toprf);
|
|
97
|
+
const nullifierStr = binaryHashToStr(nullifier, toprf.dataLocation.length);
|
|
98
|
+
let i = 0;
|
|
99
|
+
let overshootLen = 0;
|
|
100
|
+
while (cursor < slice.toIndex) {
|
|
101
|
+
if (blockIdx !== startBlockIdx) {
|
|
102
|
+
overshootLen += 1;
|
|
103
|
+
}
|
|
104
|
+
slicesWithReveal[blockIdx].redactedPlaintext[cursorInBlock]
|
|
105
|
+
= nullifierStr.charCodeAt(i);
|
|
106
|
+
advance();
|
|
107
|
+
i += 1;
|
|
108
|
+
}
|
|
109
|
+
if (overshootLen) {
|
|
110
|
+
slicesWithReveal[blockIdx]
|
|
111
|
+
.overshotToprfFromPrevBlock = { length: overshootLen };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
while (cursor < slice.toIndex) {
|
|
115
|
+
slicesWithReveal[blockIdx]
|
|
116
|
+
.redactedPlaintext[cursorInBlock] = REDACTION_CHAR_CODE;
|
|
117
|
+
advance();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function advance() {
|
|
121
|
+
cursor += 1;
|
|
122
|
+
cursorInBlock += 1;
|
|
123
|
+
if (cursorInBlock >= blocks[blockIdx].plaintext.length) {
|
|
124
|
+
blockIdx += 1;
|
|
125
|
+
cursorInBlock = 0;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Redact the following slices from the total
|
|
131
|
+
*/
|
|
132
|
+
export function redactSlices(total, slices) {
|
|
133
|
+
const redacted = new Uint8Array(total);
|
|
134
|
+
for (const slice of slices) {
|
|
135
|
+
for (let i = slice.fromIndex; i < slice.toIndex; i++) {
|
|
136
|
+
redacted[i] = REDACTION_CHAR_CODE;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return redacted;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Converts the binary hash to an ASCII string of the expected length.
|
|
143
|
+
* If the hash is shorter than the expected length, it will be padded with
|
|
144
|
+
* '0' characters. If it's longer, it will be truncated.
|
|
145
|
+
*/
|
|
146
|
+
export function binaryHashToStr(hash, expLength) {
|
|
147
|
+
return base64Encode(hash).padEnd(expLength, '0').slice(0, expLength);
|
|
148
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Logger } from '../types/index.js';
|
|
2
|
+
type RetryLoopOptions = {
|
|
3
|
+
maxRetries?: number;
|
|
4
|
+
logger: Logger;
|
|
5
|
+
shouldRetry: (error: Error) => boolean;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Execute a function, and upon failure -- retry
|
|
9
|
+
* based on specified options.
|
|
10
|
+
*/
|
|
11
|
+
export declare function executeWithRetries<T>(code: (attempt: number) => Promise<T>, { maxRetries, shouldRetry, logger, }: RetryLoopOptions): Promise<T>;
|
|
12
|
+
export {};
|