@reclaimprotocol/attestor-core 4.0.3 → 5.0.1-beta.2
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/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/{window-rpc → external-rpc}/types.d.ts +56 -35
- 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.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/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/fallbacks/stwo.js +159 -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 +6 -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 +29 -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 +15 -13
- package/lib/utils/generics.js +217 -297
- package/lib/utils/http-parser.d.ts +1 -1
- package/lib/utils/http-parser.js +186 -237
- package/lib/utils/index.d.ts +13 -12
- package/lib/utils/index.js +13 -29
- 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.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 +72 -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.d.ts +0 -1
- 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 → external-rpc/jsc-polyfills/2.d.ts} +0 -0
- /package/lib/{tests/test.bgp-listener.d.ts → scripts/build-browser.d.ts} +0 -0
- /package/lib/{tests/test.claim-creation.d.ts → scripts/build-jsc.d.ts} +0 -0
- /package/lib/{tests/test.http-provider-utils.d.ts → scripts/build-lib.d.ts} +0 -0
|
@@ -1,200 +1,354 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* 2. Next, we produce the transcript of the TLS exchange
|
|
20
|
-
* from the proofs provided by the client.
|
|
21
|
-
* 3. We then pull the provider the client is trying to claim
|
|
22
|
-
* from
|
|
23
|
-
* 4. We then use the provider's verification function to verify
|
|
24
|
-
* whether the claim is valid.
|
|
25
|
-
*
|
|
26
|
-
* If any of these steps fail, we throw an error.
|
|
27
|
-
*/
|
|
1
|
+
import { areUint8ArraysEqual, concatenateUint8Arrays } from "@reclaimprotocol/tls";
|
|
2
|
+
import { ClaimTunnelRequest, TranscriptMessageSenderType } from "../../proto/api.js";
|
|
3
|
+
import { providers } from "../../providers/index.js";
|
|
4
|
+
import { niceParseJsonObject } from "../../server/utils/generics.js";
|
|
5
|
+
import { computeOPRFRaw } from "../../server/utils/oprf-raw.js";
|
|
6
|
+
import { processHandshake } from "../../server/utils/process-handshake.js";
|
|
7
|
+
import { assertValidateProviderParams } from "../../server/utils/validation.js";
|
|
8
|
+
import {
|
|
9
|
+
AttestorError,
|
|
10
|
+
binaryHashToStr,
|
|
11
|
+
canonicalStringify,
|
|
12
|
+
decryptDirect,
|
|
13
|
+
extractApplicationDataFromTranscript,
|
|
14
|
+
hashProviderParams,
|
|
15
|
+
SIGNATURES,
|
|
16
|
+
verifyZkPacket
|
|
17
|
+
} from "../../utils/index.js";
|
|
18
|
+
import { getEngineString } from "../../utils/zk.js";
|
|
28
19
|
async function assertValidClaimRequest(request, metadata, logger) {
|
|
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
|
-
|
|
20
|
+
const {
|
|
21
|
+
data,
|
|
22
|
+
signatures: { requestSignature } = {},
|
|
23
|
+
zkEngine,
|
|
24
|
+
fixedServerIV,
|
|
25
|
+
fixedClientIV
|
|
26
|
+
} = request;
|
|
27
|
+
if (!data) {
|
|
28
|
+
throw new AttestorError(
|
|
29
|
+
"ERROR_INVALID_CLAIM",
|
|
30
|
+
"No info provided on claim request"
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
if (!requestSignature?.length) {
|
|
34
|
+
throw new AttestorError(
|
|
35
|
+
"ERROR_INVALID_CLAIM",
|
|
36
|
+
"No signature provided on claim request"
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
const serialisedReq = ClaimTunnelRequest.encode({ ...request, signatures: void 0 }).finish();
|
|
40
|
+
const { verify: verifySig } = SIGNATURES[metadata.signatureType];
|
|
41
|
+
const verified = await verifySig(serialisedReq, requestSignature, data.owner);
|
|
42
|
+
if (!verified) {
|
|
43
|
+
throw new AttestorError(
|
|
44
|
+
"ERROR_INVALID_CLAIM",
|
|
45
|
+
"Invalid signature on claim request"
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
const receipt = await decryptTranscript(
|
|
49
|
+
request.transcript,
|
|
50
|
+
logger,
|
|
51
|
+
getEngineString(zkEngine),
|
|
52
|
+
fixedServerIV,
|
|
53
|
+
fixedClientIV
|
|
54
|
+
);
|
|
55
|
+
const reqHost = request.request?.host;
|
|
56
|
+
if (receipt.hostname !== reqHost) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
`Expected server name ${reqHost}, got ${receipt.hostname}`
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
const applData = extractApplicationDataFromTranscript(receipt);
|
|
62
|
+
const newData = await assertValidProviderTranscript(
|
|
63
|
+
applData,
|
|
64
|
+
data,
|
|
65
|
+
logger,
|
|
66
|
+
{ version: metadata.clientVersion },
|
|
67
|
+
receipt.oprfRawReplacements
|
|
68
|
+
);
|
|
69
|
+
if (newData !== data) {
|
|
70
|
+
logger.info({ newData }, "updated claim info");
|
|
71
|
+
}
|
|
72
|
+
return newData;
|
|
58
73
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
(
|
|
73
|
-
|
|
74
|
-
receipt: applData,
|
|
75
|
-
params,
|
|
76
|
-
logger,
|
|
77
|
-
ctx: providerCtx
|
|
78
|
-
});
|
|
79
|
-
ctx.providerHash = (0, utils_1.hashProviderParams)(params);
|
|
80
|
-
const extractedParameters = (rslt === null || rslt === void 0 ? void 0 : rslt.extractedParameters) || {};
|
|
81
|
-
if (Object.keys(extractedParameters).length) {
|
|
82
|
-
ctx.extractedParameters = extractedParameters;
|
|
74
|
+
async function assertValidProviderTranscript(applData, info, logger, providerCtx, oprfRawReplacements) {
|
|
75
|
+
const providerName = info.provider;
|
|
76
|
+
const provider = providers[providerName];
|
|
77
|
+
if (!provider) {
|
|
78
|
+
throw new AttestorError(
|
|
79
|
+
"ERROR_INVALID_CLAIM",
|
|
80
|
+
`Unsupported provider: ${providerName}`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
let params = niceParseJsonObject(info.parameters, "params");
|
|
84
|
+
const ctx = niceParseJsonObject(info.context, "context");
|
|
85
|
+
if (oprfRawReplacements?.length) {
|
|
86
|
+
let strParams = canonicalStringify(params) ?? "{}";
|
|
87
|
+
for (const { originalText, nullifierText } of oprfRawReplacements) {
|
|
88
|
+
strParams = strParams.replaceAll(originalText, nullifierText);
|
|
83
89
|
}
|
|
84
|
-
|
|
85
|
-
|
|
90
|
+
params = JSON.parse(strParams);
|
|
91
|
+
info.parameters = strParams;
|
|
92
|
+
logger.debug(
|
|
93
|
+
{ replacements: oprfRawReplacements.length },
|
|
94
|
+
"applied oprf-raw parameter replacements"
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
assertValidateProviderParams(providerName, params);
|
|
98
|
+
const rslt = await provider.assertValidProviderReceipt({
|
|
99
|
+
receipt: applData,
|
|
100
|
+
params,
|
|
101
|
+
logger,
|
|
102
|
+
ctx: providerCtx
|
|
103
|
+
});
|
|
104
|
+
ctx.providerHash = hashProviderParams(params);
|
|
105
|
+
const extractedParameters = rslt?.extractedParameters || {};
|
|
106
|
+
if (Object.keys(extractedParameters).length) {
|
|
107
|
+
ctx.extractedParameters = extractedParameters;
|
|
108
|
+
}
|
|
109
|
+
info.context = canonicalStringify(ctx) ?? "";
|
|
110
|
+
return info;
|
|
86
111
|
}
|
|
87
|
-
/**
|
|
88
|
-
* Verify that the transcript provided by the client
|
|
89
|
-
* matches the transcript of the tunnel, the server
|
|
90
|
-
* has created.
|
|
91
|
-
*/
|
|
92
112
|
function assertTranscriptsMatch(clientTranscript, tunnelTranscript) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
113
|
+
const clientSends = concatenateUint8Arrays(
|
|
114
|
+
clientTranscript.filter((m) => m.sender === TranscriptMessageSenderType.TRANSCRIPT_MESSAGE_SENDER_TYPE_CLIENT).map((m) => m.message)
|
|
115
|
+
);
|
|
116
|
+
const tunnelSends = concatenateUint8Arrays(
|
|
117
|
+
tunnelTranscript.filter((m) => m.sender === "client").map((m) => m.message)
|
|
118
|
+
);
|
|
119
|
+
if (!areUint8ArraysEqual(clientSends, tunnelSends)) {
|
|
120
|
+
throw AttestorError.badRequest(
|
|
121
|
+
"Outgoing messages from client do not match the tunnel transcript"
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
const clientRecvs = concatenateUint8Arrays(
|
|
125
|
+
clientTranscript.filter((m) => m.sender === TranscriptMessageSenderType.TRANSCRIPT_MESSAGE_SENDER_TYPE_SERVER).map((m) => m.message)
|
|
126
|
+
);
|
|
127
|
+
const tunnelRecvs = concatenateUint8Arrays(
|
|
128
|
+
tunnelTranscript.filter((m) => m.sender === "server").map((m) => m.message)
|
|
129
|
+
).slice(0, clientRecvs.length);
|
|
130
|
+
if (!areUint8ArraysEqual(clientRecvs, tunnelRecvs)) {
|
|
131
|
+
throw AttestorError.badRequest(
|
|
132
|
+
"Incoming messages from server do not match the tunnel transcript"
|
|
133
|
+
);
|
|
134
|
+
}
|
|
116
135
|
}
|
|
117
136
|
async function decryptTranscript(transcript, logger, zkEngine, serverIV, clientIV) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
137
|
+
const {
|
|
138
|
+
tlsVersion,
|
|
139
|
+
cipherSuite,
|
|
140
|
+
hostname,
|
|
141
|
+
nextMsgIndex
|
|
142
|
+
} = await processHandshake(transcript, logger);
|
|
143
|
+
let clientRecordNumber = tlsVersion === "TLS1_3" ? -1 : 0;
|
|
144
|
+
let serverRecordNumber = clientRecordNumber;
|
|
145
|
+
transcript = transcript.slice(nextMsgIndex);
|
|
146
|
+
const overshotMap = {};
|
|
147
|
+
const decryptedTranscript = [];
|
|
148
|
+
const oprfRawReplacements = [];
|
|
149
|
+
const pendingOprfRaw = {};
|
|
150
|
+
for (const [i, {
|
|
151
|
+
sender,
|
|
152
|
+
message,
|
|
153
|
+
reveal: { zkReveal, directReveal } = {}
|
|
154
|
+
}] of transcript.entries()) {
|
|
155
|
+
try {
|
|
156
|
+
await decryptMessage(sender, message, directReveal, zkReveal, i);
|
|
157
|
+
} catch (error) {
|
|
158
|
+
const err = new AttestorError(
|
|
159
|
+
"ERROR_INVALID_CLAIM",
|
|
160
|
+
`error in handling packet at idx ${i}: ${error}`,
|
|
161
|
+
{ packetIdx: i, error }
|
|
162
|
+
);
|
|
163
|
+
if (error.stack) {
|
|
164
|
+
err.stack = error.stack;
|
|
165
|
+
}
|
|
166
|
+
throw err;
|
|
126
167
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
168
|
+
}
|
|
169
|
+
const remainingPending = Object.keys(pendingOprfRaw);
|
|
170
|
+
if (remainingPending.length) {
|
|
171
|
+
throw new AttestorError(
|
|
172
|
+
"ERROR_INVALID_CLAIM",
|
|
173
|
+
`oprf-raw cross-block markers incomplete: pending for packets ${remainingPending.join(", ")}`
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
transcript: decryptedTranscript,
|
|
178
|
+
hostname,
|
|
179
|
+
tlsVersion,
|
|
180
|
+
oprfRawReplacements: oprfRawReplacements.length ? oprfRawReplacements : void 0
|
|
181
|
+
};
|
|
182
|
+
async function decryptMessage(sender, message, directReveal, zkReveal, i) {
|
|
183
|
+
const isServer = sender === TranscriptMessageSenderType.TRANSCRIPT_MESSAGE_SENDER_TYPE_SERVER;
|
|
184
|
+
const recordHeader = message.slice(0, 5);
|
|
185
|
+
const content = getWithoutHeader(message);
|
|
186
|
+
if (isServer) {
|
|
187
|
+
serverRecordNumber++;
|
|
188
|
+
} else {
|
|
189
|
+
clientRecordNumber++;
|
|
190
|
+
}
|
|
191
|
+
let redacted = true;
|
|
192
|
+
let plaintext = void 0;
|
|
193
|
+
let plaintextLength;
|
|
194
|
+
if (directReveal?.key?.length) {
|
|
195
|
+
const result = await decryptDirect(
|
|
196
|
+
directReveal,
|
|
197
|
+
cipherSuite,
|
|
198
|
+
recordHeader,
|
|
199
|
+
tlsVersion,
|
|
200
|
+
content
|
|
201
|
+
);
|
|
202
|
+
plaintext = result.plaintext;
|
|
203
|
+
redacted = false;
|
|
204
|
+
plaintextLength = plaintext.length;
|
|
205
|
+
} else if (zkReveal?.proofs?.length) {
|
|
206
|
+
const iv = sender === TranscriptMessageSenderType.TRANSCRIPT_MESSAGE_SENDER_TYPE_SERVER ? serverIV : clientIV;
|
|
207
|
+
const recordNumber = isServer ? serverRecordNumber : clientRecordNumber;
|
|
208
|
+
const result = await verifyZkPacket(
|
|
209
|
+
{
|
|
210
|
+
ciphertext: content,
|
|
211
|
+
zkReveal,
|
|
212
|
+
iv,
|
|
213
|
+
recordNumber,
|
|
214
|
+
toprfOvershotNullifier: overshotMap[i]?.data,
|
|
215
|
+
getNextPacket(overshot) {
|
|
216
|
+
const nextIdx = transcript.findIndex((t, j) => t.sender === sender && j > i);
|
|
217
|
+
if (nextIdx < 0) {
|
|
218
|
+
return;
|
|
176
219
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
220
|
+
overshotMap[nextIdx] = { data: overshot };
|
|
221
|
+
return getWithoutHeader(transcript[nextIdx].message);
|
|
222
|
+
},
|
|
223
|
+
logger,
|
|
224
|
+
cipherSuite,
|
|
225
|
+
zkEngine
|
|
226
|
+
}
|
|
227
|
+
);
|
|
228
|
+
plaintext = result.redactedPlaintext;
|
|
229
|
+
const pendingForThis = pendingOprfRaw[i];
|
|
230
|
+
if (pendingForThis && zkReveal?.overshotOprfRawLength) {
|
|
231
|
+
const overshootLen = zkReveal.overshotOprfRawLength;
|
|
232
|
+
const overshootData = plaintext.slice(0, overshootLen);
|
|
233
|
+
const fullData = concatenateUint8Arrays([
|
|
234
|
+
pendingForThis.partialData,
|
|
235
|
+
overshootData
|
|
236
|
+
]);
|
|
237
|
+
const expectedLen = pendingForThis.dataLocation.length;
|
|
238
|
+
if (fullData.length !== expectedLen) {
|
|
239
|
+
throw new AttestorError(
|
|
240
|
+
"ERROR_INVALID_CLAIM",
|
|
241
|
+
`oprf-raw cross-block length mismatch: got ${fullData.length}, expected ${expectedLen}`
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
const oprfResults = await computeOPRFRaw(
|
|
245
|
+
fullData,
|
|
246
|
+
[{ dataLocation: { fromIndex: 0, length: fullData.length } }],
|
|
247
|
+
logger
|
|
248
|
+
);
|
|
249
|
+
if (oprfResults.length) {
|
|
250
|
+
const { nullifier } = oprfResults[0];
|
|
251
|
+
const originalText = new TextDecoder().decode(fullData);
|
|
252
|
+
const nullifierStr = binaryHashToStr(nullifier, fullData.length);
|
|
253
|
+
oprfRawReplacements.push({ originalText, nullifierText: nullifierStr });
|
|
254
|
+
const nullifierBytes = new TextEncoder().encode(nullifierStr);
|
|
255
|
+
const overshootNullifier = nullifierBytes.slice(pendingForThis.partialData.length);
|
|
256
|
+
plaintext.set(overshootNullifier, 0);
|
|
257
|
+
const prevPkt = decryptedTranscript[pendingForThis.originPktIdx];
|
|
258
|
+
if (prevPkt) {
|
|
259
|
+
const firstPartNullifier = nullifierBytes.slice(0, pendingForThis.partialData.length);
|
|
260
|
+
prevPkt.message.set(firstPartNullifier, pendingForThis.dataLocation.fromIndex);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
delete pendingOprfRaw[i];
|
|
264
|
+
}
|
|
265
|
+
if (result.oprfRawMarkers?.length) {
|
|
266
|
+
const { markersThisPacket, pendingMarker } = separateOprfRawMarkers(
|
|
267
|
+
result.oprfRawMarkers,
|
|
268
|
+
plaintext.length,
|
|
269
|
+
() => transcript.findIndex((t, j) => t.sender === sender && j > i),
|
|
270
|
+
decryptedTranscript.length,
|
|
271
|
+
logger
|
|
272
|
+
);
|
|
273
|
+
if (pendingMarker) {
|
|
274
|
+
pendingMarker.pending.partialData.set(
|
|
275
|
+
plaintext.slice(pendingMarker.pending.dataLocation.fromIndex)
|
|
276
|
+
);
|
|
277
|
+
pendingOprfRaw[pendingMarker.nextIdx] = pendingMarker.pending;
|
|
187
278
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
279
|
+
if (markersThisPacket.length) {
|
|
280
|
+
const pt = plaintext;
|
|
281
|
+
const oprfResults = await computeOPRFRaw(pt, markersThisPacket, logger);
|
|
282
|
+
const originalTexts = oprfResults.map(({ dataLocation }) => new TextDecoder().decode(
|
|
283
|
+
pt.slice(dataLocation.fromIndex, dataLocation.fromIndex + dataLocation.length)
|
|
284
|
+
));
|
|
285
|
+
for (const [idx, { dataLocation, nullifier }] of oprfResults.entries()) {
|
|
286
|
+
const originalText = originalTexts[idx];
|
|
287
|
+
const nullifierStr = binaryHashToStr(nullifier, dataLocation.length);
|
|
288
|
+
oprfRawReplacements.push({ originalText, nullifierText: nullifierStr });
|
|
289
|
+
const nullifierBytes = new TextEncoder().encode(nullifierStr);
|
|
290
|
+
pt.set(nullifierBytes, dataLocation.fromIndex);
|
|
291
|
+
}
|
|
193
292
|
}
|
|
293
|
+
}
|
|
294
|
+
redacted = false;
|
|
295
|
+
plaintextLength = plaintext.length;
|
|
296
|
+
} else {
|
|
297
|
+
plaintext = content;
|
|
298
|
+
plaintextLength = plaintext.length;
|
|
194
299
|
}
|
|
300
|
+
decryptedTranscript.push({
|
|
301
|
+
sender: sender === TranscriptMessageSenderType.TRANSCRIPT_MESSAGE_SENDER_TYPE_CLIENT ? "client" : "server",
|
|
302
|
+
redacted,
|
|
303
|
+
message: plaintext,
|
|
304
|
+
recordHeader,
|
|
305
|
+
plaintextLength
|
|
306
|
+
});
|
|
307
|
+
}
|
|
195
308
|
}
|
|
196
309
|
function getWithoutHeader(message) {
|
|
197
|
-
|
|
198
|
-
|
|
310
|
+
return message.slice(5);
|
|
311
|
+
}
|
|
312
|
+
function separateOprfRawMarkers(markers, plaintextLength, findNextPacketIdx, currentTranscriptLength, logger) {
|
|
313
|
+
const markersThisPacket = [];
|
|
314
|
+
let pendingMarker;
|
|
315
|
+
for (const marker of markers) {
|
|
316
|
+
const dataLocation = marker.dataLocation;
|
|
317
|
+
if (!dataLocation) {
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
const { fromIndex, length } = dataLocation;
|
|
321
|
+
const endInPacket = fromIndex + length;
|
|
322
|
+
if (endInPacket <= plaintextLength) {
|
|
323
|
+
markersThisPacket.push({ dataLocation });
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
const nextIdx = findNextPacketIdx();
|
|
327
|
+
if (nextIdx < 0) {
|
|
328
|
+
throw new AttestorError(
|
|
329
|
+
"ERROR_INVALID_CLAIM",
|
|
330
|
+
"oprf-raw marker spans packets but no next packet found"
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
pendingMarker = {
|
|
334
|
+
nextIdx,
|
|
335
|
+
pending: {
|
|
336
|
+
partialData: new Uint8Array(plaintextLength - fromIndex),
|
|
337
|
+
dataLocation: { fromIndex, length },
|
|
338
|
+
originPktIdx: currentTranscriptLength
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
logger.debug(
|
|
342
|
+
{ fromIndex, length, partialLen: plaintextLength - fromIndex, nextIdx },
|
|
343
|
+
"oprf-raw marker spans packets, storing partial data"
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
return { markersThisPacket, pendingMarker };
|
|
199
347
|
}
|
|
200
|
-
|
|
348
|
+
export {
|
|
349
|
+
assertTranscriptsMatch,
|
|
350
|
+
assertValidClaimRequest,
|
|
351
|
+
assertValidProviderTranscript,
|
|
352
|
+
decryptTranscript,
|
|
353
|
+
getWithoutHeader
|
|
354
|
+
};
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const nodeEnv = (0, env_1.getEnvVariable)('NODE_ENV') || 'development';
|
|
6
|
-
(0, dotenv_1.config)({ path: `.env.${nodeEnv}` });
|
|
7
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uZmlnLWVudi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zZXJ2ZXIvdXRpbHMvY29uZmlnLWVudi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLG1DQUErQjtBQUMvQix1Q0FBOEM7QUFFOUMsTUFBTSxPQUFPLEdBQUcsSUFBQSxvQkFBYyxFQUFDLFVBQVUsQ0FBQyxJQUFJLGFBQWEsQ0FBQTtBQUMzRCxJQUFBLGVBQU0sRUFBQyxFQUFFLElBQUksRUFBRSxRQUFRLE9BQU8sRUFBRSxFQUFFLENBQUMsQ0FBQSJ9
|
|
1
|
+
import { config } from "dotenv";
|
|
2
|
+
import { getEnvVariable } from "../../utils/env.js";
|
|
3
|
+
const nodeEnv = getEnvVariable("NODE_ENV") || "development";
|
|
4
|
+
config({ path: `.env.${nodeEnv}` });
|
package/lib/server/utils/dns.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.resolveHostnames = resolveHostnames;
|
|
4
|
-
const dns_1 = require("dns");
|
|
5
|
-
const config_1 = require("../../config");
|
|
1
|
+
import { resolve, setServers } from "dns";
|
|
2
|
+
import { DNS_SERVERS } from "../../config/index.js";
|
|
6
3
|
setDnsServers();
|
|
7
4
|
async function resolveHostnames(hostname) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
return new Promise((_resolve, reject) => {
|
|
6
|
+
resolve(hostname, (err, addresses) => {
|
|
7
|
+
if (err) {
|
|
8
|
+
reject(
|
|
9
|
+
new Error(
|
|
10
|
+
`Could not resolve hostname: ${hostname}, ${err.message}`
|
|
11
|
+
)
|
|
12
|
+
);
|
|
13
|
+
} else {
|
|
14
|
+
_resolve(addresses);
|
|
15
|
+
}
|
|
17
16
|
});
|
|
17
|
+
});
|
|
18
18
|
}
|
|
19
19
|
function setDnsServers() {
|
|
20
|
-
|
|
20
|
+
setServers(DNS_SERVERS);
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
export {
|
|
23
|
+
resolveHostnames
|
|
24
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GCP attestation validation utilities
|
|
3
|
+
* Validates JWT tokens from Google Confidential Computing
|
|
4
|
+
*/
|
|
5
|
+
import type { Logger } from '#src/types/general.ts';
|
|
6
|
+
export interface GcpValidationResult {
|
|
7
|
+
isValid: boolean;
|
|
8
|
+
errors: string[];
|
|
9
|
+
ethAddress?: Uint8Array;
|
|
10
|
+
userDataType?: string;
|
|
11
|
+
pcr0?: string;
|
|
12
|
+
envVars?: Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Validates GCP JWT attestation and extracts ETH address
|
|
16
|
+
*/
|
|
17
|
+
export declare function validateGcpAttestationAndExtractKey(attestationBytes: Uint8Array, logger?: Logger): Promise<GcpValidationResult>;
|