@reclaimprotocol/attestor-core 5.0.1-beta.1 → 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/lib/avs/abis/avsDirectoryABI.d.ts +60 -0
- package/lib/avs/abis/avsDirectoryABI.js +343 -0
- package/lib/avs/abis/delegationABI.d.ts +126 -0
- package/lib/avs/abis/delegationABI.js +4 -0
- package/lib/avs/abis/registryABI.d.ts +136 -0
- package/lib/avs/abis/registryABI.js +728 -0
- package/lib/avs/client/create-claim-on-avs.d.ts +12 -0
- package/lib/avs/client/create-claim-on-avs.js +168 -0
- package/lib/avs/config.d.ts +7 -0
- package/lib/avs/config.js +26 -0
- package/lib/avs/contracts/ReclaimServiceManager.d.ts +601 -0
- package/lib/avs/contracts/ReclaimServiceManager.js +0 -0
- package/lib/avs/contracts/common.d.ts +50 -0
- package/lib/avs/contracts/common.js +0 -0
- package/lib/avs/contracts/factories/ReclaimServiceManager__factory.d.ts +890 -0
- package/lib/avs/contracts/factories/ReclaimServiceManager__factory.js +1183 -0
- package/lib/avs/contracts/factories/index.d.ts +1 -0
- package/lib/avs/contracts/factories/index.js +4 -0
- package/lib/avs/contracts/index.d.ts +3 -0
- package/lib/avs/contracts/index.js +6 -0
- package/lib/avs/types/index.d.ts +55 -0
- package/lib/avs/types/index.js +0 -0
- package/lib/avs/utils/contracts.d.ts +21 -0
- package/lib/avs/utils/contracts.js +53 -0
- package/lib/avs/utils/register.d.ts +27 -0
- package/lib/avs/utils/register.js +74 -0
- package/lib/avs/utils/tasks.d.ts +22 -0
- package/lib/avs/utils/tasks.js +48 -0
- package/lib/client/create-claim.d.ts +5 -0
- package/lib/client/create-claim.js +461 -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 +53 -0
- package/lib/client/tunnels/make-rpc-tls-tunnel.d.ts +26 -0
- package/lib/client/tunnels/make-rpc-tls-tunnel.js +127 -0
- package/lib/client/utils/attestor-pool.d.ts +8 -0
- package/lib/client/utils/attestor-pool.js +24 -0
- package/lib/client/utils/client-socket.d.ts +11 -0
- package/lib/client/utils/client-socket.js +120 -0
- package/lib/client/utils/message-handler.d.ts +4 -0
- package/lib/client/utils/message-handler.js +97 -0
- package/lib/config/index.d.ts +31 -0
- package/lib/config/index.js +62 -0
- 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.d.ts +1 -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.d.ts +9 -0
- package/lib/index.js +13 -0
- package/lib/mechain/abis/governanceABI.d.ts +50 -0
- package/lib/mechain/abis/governanceABI.js +461 -0
- package/lib/mechain/abis/taskABI.d.ts +157 -0
- package/lib/mechain/abis/taskABI.js +512 -0
- package/lib/mechain/client/create-claim-on-mechain.d.ts +10 -0
- package/lib/mechain/client/create-claim-on-mechain.js +33 -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/lib/mechain/constants/index.js +8 -0
- 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 +0 -0
- package/lib/proto/api.d.ts +651 -0
- package/lib/proto/api.js +4250 -0
- package/lib/proto/tee-bundle.d.ts +156 -0
- package/lib/proto/tee-bundle.js +1296 -0
- package/lib/providers/http/index.d.ts +18 -0
- package/lib/providers/http/index.js +640 -0
- 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 +77 -0
- package/lib/providers/http/utils.js +283 -0
- package/lib/providers/index.d.ts +4 -0
- package/lib/providers/index.js +7 -0
- package/lib/scripts/build-browser.d.ts +1 -0
- package/lib/scripts/build-jsc.d.ts +1 -0
- package/lib/scripts/build-lib.d.ts +1 -0
- package/lib/scripts/check-avs-registration.d.ts +1 -0
- package/lib/scripts/check-avs-registration.js +28 -0
- 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.d.ts +5 -0
- package/lib/scripts/generate-provider-types.js +101 -0
- package/lib/scripts/generate-receipt.d.ts +9 -0
- package/lib/scripts/generate-receipt.js +101 -0
- package/lib/scripts/generate-toprf-keys.d.ts +1 -0
- package/lib/scripts/generate-toprf-keys.js +24 -0
- 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 -0
- package/lib/scripts/register-avs-operator.js +3 -0
- package/lib/scripts/start-server.d.ts +1 -0
- package/lib/scripts/start-server.js +11 -0
- package/lib/scripts/update-avs-metadata.d.ts +1 -0
- package/lib/scripts/update-avs-metadata.js +20 -0
- package/lib/scripts/utils.d.ts +1 -0
- package/lib/scripts/utils.js +10 -0
- package/lib/scripts/whitelist-operator.d.ts +1 -0
- package/lib/scripts/whitelist-operator.js +16 -0
- package/lib/server/create-server.d.ts +8 -0
- package/lib/server/create-server.js +105 -0
- package/lib/server/handlers/claimTeeBundle.d.ts +6 -0
- package/lib/server/handlers/claimTeeBundle.js +232 -0
- package/lib/server/handlers/claimTunnel.d.ts +2 -0
- package/lib/server/handlers/claimTunnel.js +80 -0
- package/lib/server/handlers/completeClaimOnChain.d.ts +2 -0
- package/lib/server/handlers/completeClaimOnChain.js +29 -0
- package/lib/server/handlers/createClaimOnChain.d.ts +2 -0
- package/lib/server/handlers/createClaimOnChain.js +32 -0
- package/lib/server/handlers/createTaskOnMechain.d.ts +2 -0
- package/lib/server/handlers/createTaskOnMechain.js +57 -0
- package/lib/server/handlers/createTunnel.d.ts +2 -0
- package/lib/server/handlers/createTunnel.js +98 -0
- package/lib/server/handlers/disconnectTunnel.d.ts +2 -0
- package/lib/server/handlers/disconnectTunnel.js +8 -0
- package/lib/server/handlers/fetchCertificateBytes.d.ts +2 -0
- package/lib/server/handlers/fetchCertificateBytes.js +57 -0
- package/lib/server/handlers/index.d.ts +4 -0
- package/lib/server/handlers/index.js +25 -0
- package/lib/server/handlers/init.d.ts +2 -0
- package/lib/server/handlers/init.js +33 -0
- package/lib/server/handlers/toprf.d.ts +2 -0
- package/lib/server/handlers/toprf.js +19 -0
- package/lib/server/index.d.ts +4 -0
- package/lib/server/index.js +4 -0
- package/lib/server/socket.d.ts +13 -0
- package/lib/server/socket.js +112 -0
- package/lib/server/tunnels/make-tcp-tunnel.d.ts +22 -0
- package/lib/server/tunnels/make-tcp-tunnel.js +202 -0
- package/lib/server/utils/apm.d.ts +11 -0
- package/lib/server/utils/apm.js +29 -0
- package/lib/server/utils/assert-valid-claim-request.d.ts +31 -0
- package/lib/server/utils/assert-valid-claim-request.js +354 -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 +24 -0
- 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 +22 -0
- package/lib/server/utils/generics.js +45 -0
- package/lib/server/utils/iso.d.ts +1 -0
- package/lib/server/utils/iso.js +259 -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 +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 +13 -0
- package/lib/server/utils/process-handshake.js +233 -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-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/server/utils/validation.d.ts +2 -0
- package/lib/server/utils/validation.js +45 -0
- package/lib/types/bgp.d.ts +11 -0
- package/lib/types/bgp.js +0 -0
- package/lib/types/claims.d.ts +70 -0
- package/lib/types/claims.js +0 -0
- package/lib/types/client.d.ts +163 -0
- package/lib/types/client.js +0 -0
- package/lib/types/general.d.ts +76 -0
- package/lib/types/general.js +0 -0
- package/lib/types/handlers.d.ts +10 -0
- package/lib/types/handlers.js +0 -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 +16 -0
- package/lib/types/providers.js +0 -0
- package/lib/types/rpc.d.ts +35 -0
- package/lib/types/rpc.js +0 -0
- package/lib/types/signatures.d.ts +28 -0
- package/lib/types/signatures.js +0 -0
- package/lib/types/tunnel.d.ts +18 -0
- package/lib/types/tunnel.js +0 -0
- package/lib/types/zk.d.ts +38 -0
- package/lib/types/zk.js +0 -0
- package/lib/utils/auth.d.ts +8 -0
- package/lib/utils/auth.js +71 -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 +123 -0
- package/lib/utils/claims.d.ts +33 -0
- package/lib/utils/claims.js +89 -0
- package/lib/utils/env.d.ts +3 -0
- package/lib/utils/env.js +19 -0
- package/lib/utils/error.d.ts +26 -0
- package/lib/utils/error.js +54 -0
- package/lib/utils/generics.d.ts +114 -0
- package/lib/utils/generics.js +268 -0
- package/lib/utils/http-parser.d.ts +59 -0
- package/lib/utils/http-parser.js +201 -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 +82 -0
- package/lib/utils/prepare-packets.d.ts +16 -0
- package/lib/utils/prepare-packets.js +69 -0
- package/lib/utils/redactions.d.ts +73 -0
- package/lib/utils/redactions.js +135 -0
- package/lib/utils/retries.d.ts +12 -0
- package/lib/utils/retries.js +26 -0
- package/lib/utils/signatures/eth.d.ts +2 -0
- package/lib/utils/signatures/eth.js +31 -0
- package/lib/utils/signatures/index.d.ts +5 -0
- package/lib/utils/signatures/index.js +12 -0
- package/lib/utils/socket-base.d.ts +23 -0
- package/lib/utils/socket-base.js +96 -0
- package/lib/utils/tls.d.ts +2 -0
- package/lib/utils/tls.js +58 -0
- package/lib/utils/ws.d.ts +7 -0
- package/lib/utils/ws.js +22 -0
- package/lib/utils/zk.d.ts +71 -0
- package/lib/utils/zk.js +625 -0
- package/package.json +2 -2
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { AttestorError } from "../../utils/error.js";
|
|
2
|
+
import { REDACTION_CHAR_CODE } from "../../utils/index.js";
|
|
3
|
+
async function reconstructTlsTranscript(bundleData, logger, oprfResults) {
|
|
4
|
+
try {
|
|
5
|
+
const revealedRequest = reconstructRequest(bundleData, logger);
|
|
6
|
+
const reconstructedResponse = await reconstructConsolidatedResponse(bundleData, logger, oprfResults);
|
|
7
|
+
const certificateInfo = bundleData.kOutputPayload.certificateInfo;
|
|
8
|
+
logger.info("TLS transcript reconstruction completed successfully", {
|
|
9
|
+
requestSize: revealedRequest.length,
|
|
10
|
+
responseSize: reconstructedResponse.length,
|
|
11
|
+
hasCertificateInfo: !!certificateInfo
|
|
12
|
+
});
|
|
13
|
+
return {
|
|
14
|
+
revealedRequest,
|
|
15
|
+
reconstructedResponse,
|
|
16
|
+
certificateInfo
|
|
17
|
+
};
|
|
18
|
+
} catch (error) {
|
|
19
|
+
logger.error({ error }, "TLS transcript reconstruction failed");
|
|
20
|
+
throw new AttestorError("ERROR_INVALID_CLAIM", `Transcript reconstruction failed: ${error.message}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function reconstructRequest(bundleData, logger) {
|
|
24
|
+
const { kOutputPayload } = bundleData;
|
|
25
|
+
if (!kOutputPayload.requestRedactionRanges || kOutputPayload.requestRedactionRanges.length === 0) {
|
|
26
|
+
logger.warn("No request redaction ranges - using redacted request as-is");
|
|
27
|
+
return kOutputPayload.redactedRequest;
|
|
28
|
+
}
|
|
29
|
+
const revealedRequest = new Uint8Array(kOutputPayload.redactedRequest);
|
|
30
|
+
const prettyRequest = new Uint8Array(revealedRequest);
|
|
31
|
+
for (const range of kOutputPayload.requestRedactionRanges) {
|
|
32
|
+
if (!range.type.includes("proof")) {
|
|
33
|
+
const start = range.start;
|
|
34
|
+
const length = range.length;
|
|
35
|
+
for (let i = 0; i < length && start + i < prettyRequest.length; i++) {
|
|
36
|
+
prettyRequest[start + i] = REDACTION_CHAR_CODE;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return prettyRequest;
|
|
41
|
+
}
|
|
42
|
+
async function reconstructConsolidatedResponse(bundleData, logger, oprfResults) {
|
|
43
|
+
const { kOutputPayload, tOutputPayload } = bundleData;
|
|
44
|
+
const consolidatedKeystream = kOutputPayload.consolidatedResponseKeystream;
|
|
45
|
+
const consolidatedCiphertext = tOutputPayload.consolidatedResponseCiphertext;
|
|
46
|
+
if (!consolidatedKeystream || consolidatedKeystream.length === 0) {
|
|
47
|
+
throw new AttestorError("ERROR_INVALID_CLAIM", "No consolidated response keystream available");
|
|
48
|
+
}
|
|
49
|
+
if (!consolidatedCiphertext || consolidatedCiphertext.length === 0) {
|
|
50
|
+
throw new AttestorError("ERROR_INVALID_CLAIM", "No consolidated response ciphertext available");
|
|
51
|
+
}
|
|
52
|
+
if (consolidatedKeystream.length !== consolidatedCiphertext.length) {
|
|
53
|
+
logger.warn("Keystream and ciphertext length mismatch", {
|
|
54
|
+
keystreamLength: consolidatedKeystream.length,
|
|
55
|
+
ciphertextLength: consolidatedCiphertext.length
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const minLength = Math.min(consolidatedKeystream.length, consolidatedCiphertext.length);
|
|
59
|
+
const reconstructedResponse = new Uint8Array(minLength);
|
|
60
|
+
for (let i = 0; i < minLength; i++) {
|
|
61
|
+
reconstructedResponse[i] = consolidatedKeystream[i] ^ consolidatedCiphertext[i];
|
|
62
|
+
}
|
|
63
|
+
logger.info(`Reconstructed response: ${reconstructedResponse.length} bytes, ${kOutputPayload.responseRedactionRanges?.length || 0} redaction ranges`);
|
|
64
|
+
let processedResponse = applyResponseRedactionRanges(reconstructedResponse, kOutputPayload.responseRedactionRanges, logger);
|
|
65
|
+
if (oprfResults && oprfResults.length > 0) {
|
|
66
|
+
logger.info(`Applying ${oprfResults.length} OPRF replacements before trimming`);
|
|
67
|
+
const { replaceOprfRanges } = await import("../../server/utils/tee-oprf-verification.js");
|
|
68
|
+
processedResponse = replaceOprfRanges(processedResponse, oprfResults, logger);
|
|
69
|
+
}
|
|
70
|
+
let leadingAsterisks = 0;
|
|
71
|
+
for (const element of processedResponse) {
|
|
72
|
+
if (element === REDACTION_CHAR_CODE) {
|
|
73
|
+
leadingAsterisks++;
|
|
74
|
+
} else {
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
let trailingAsterisks = 0;
|
|
79
|
+
for (let i = processedResponse.length - 1; i >= leadingAsterisks; i--) {
|
|
80
|
+
if (processedResponse[i] === REDACTION_CHAR_CODE) {
|
|
81
|
+
trailingAsterisks++;
|
|
82
|
+
} else {
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const finalLength = processedResponse.length - leadingAsterisks - trailingAsterisks;
|
|
87
|
+
logger.info(`After processing: ${processedResponse.length} bytes, ${leadingAsterisks} leading and ${trailingAsterisks} trailing asterisks trimmed, final: ${finalLength} bytes`);
|
|
88
|
+
return processedResponse.slice(leadingAsterisks, processedResponse.length - trailingAsterisks);
|
|
89
|
+
}
|
|
90
|
+
function applyResponseRedactionRanges(response, redactionRanges, logger) {
|
|
91
|
+
if (!redactionRanges || redactionRanges.length === 0) {
|
|
92
|
+
return response;
|
|
93
|
+
}
|
|
94
|
+
const result = new Uint8Array(response);
|
|
95
|
+
const consolidatedRanges = consolidateRedactionRanges(redactionRanges);
|
|
96
|
+
if (logger) {
|
|
97
|
+
logger.info(`Applying ${consolidatedRanges.length} redaction ranges to ${response.length} byte response`);
|
|
98
|
+
}
|
|
99
|
+
for (const [idx, range] of consolidatedRanges.entries()) {
|
|
100
|
+
const rangeStart = range.start;
|
|
101
|
+
const rangeEnd = range.start + range.length;
|
|
102
|
+
if (rangeStart < 0 || rangeEnd > result.length) {
|
|
103
|
+
if (logger) {
|
|
104
|
+
logger.warn(`Redaction range #${idx} out of bounds: [${rangeStart}-${rangeEnd}] vs ${result.length}`);
|
|
105
|
+
}
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (logger && idx < 3) {
|
|
109
|
+
logger.info(`Redaction range #${idx}: [${rangeStart}-${rangeEnd}]`);
|
|
110
|
+
}
|
|
111
|
+
for (let i = rangeStart; i < rangeEnd; i++) {
|
|
112
|
+
result[i] = REDACTION_CHAR_CODE;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
function consolidateRedactionRanges(ranges) {
|
|
118
|
+
if (ranges.length === 0) {
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
const sortedRanges = [...ranges].sort((a, b) => a.start - b.start);
|
|
122
|
+
const consolidated = [];
|
|
123
|
+
let current = { ...sortedRanges[0] };
|
|
124
|
+
for (let i = 1; i < sortedRanges.length; i++) {
|
|
125
|
+
const next = sortedRanges[i];
|
|
126
|
+
if (next.start <= current.start + current.length) {
|
|
127
|
+
const endCurrent = current.start + current.length;
|
|
128
|
+
const endNext = next.start + next.length;
|
|
129
|
+
current.length = Math.max(endCurrent, endNext) - current.start;
|
|
130
|
+
} else {
|
|
131
|
+
consolidated.push(current);
|
|
132
|
+
current = { ...next };
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
consolidated.push(current);
|
|
136
|
+
return consolidated;
|
|
137
|
+
}
|
|
138
|
+
export {
|
|
139
|
+
reconstructTlsTranscript
|
|
140
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TEE Bundle verification utilities
|
|
3
|
+
* Handles validation of TEE verification bundles including attestations and signatures
|
|
4
|
+
*/
|
|
5
|
+
import type { SignedMessage } from '#src/proto/tee-bundle.ts';
|
|
6
|
+
import { KOutputPayload, TOutputPayload } from '#src/proto/tee-bundle.ts';
|
|
7
|
+
import type { Logger } from '#src/types/general.ts';
|
|
8
|
+
export interface TeeBundleData {
|
|
9
|
+
teekSigned: SignedMessage;
|
|
10
|
+
teetSigned: SignedMessage;
|
|
11
|
+
kOutputPayload: KOutputPayload;
|
|
12
|
+
tOutputPayload: TOutputPayload;
|
|
13
|
+
teekPcr0: string;
|
|
14
|
+
teetPcr0: string;
|
|
15
|
+
teeSessionId: string;
|
|
16
|
+
}
|
|
17
|
+
export interface TeeSignatureVerificationResult {
|
|
18
|
+
isValid: boolean;
|
|
19
|
+
errors: string[];
|
|
20
|
+
address?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Verifies a complete TEE verification bundle
|
|
24
|
+
* @param bundleBytes - Raw protobuf-encoded verification bundle
|
|
25
|
+
* @param logger - Logger instance
|
|
26
|
+
* @returns Validated TEE bundle data
|
|
27
|
+
*/
|
|
28
|
+
export declare function verifyTeeBundle(bundleBytes: Uint8Array, logger: Logger): Promise<TeeBundleData>;
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { ServiceSignatureType } from "../../proto/api.js";
|
|
2
|
+
import { BodyType, KOutputPayload, TOutputPayload, VerificationBundle } from "../../proto/tee-bundle.js";
|
|
3
|
+
import { validateGcpAttestationAndExtractKey } from "../../server/utils/gcp-attestation.js";
|
|
4
|
+
import { validateNitroAttestationAndExtractKey } from "../../server/utils/nitro-attestation.js";
|
|
5
|
+
import { AttestorError } from "../../utils/error.js";
|
|
6
|
+
import { SIGNATURES } from "../../utils/signatures/index.js";
|
|
7
|
+
async function verifyTeeBundle(bundleBytes, logger) {
|
|
8
|
+
const bundle = parseVerificationBundle(bundleBytes);
|
|
9
|
+
validateBundleCompleteness(bundle);
|
|
10
|
+
const { teekKeyResult, teetKeyResult } = await extractPublicKeys(bundle, logger);
|
|
11
|
+
await verifyTeeSignatures(bundle, teekKeyResult, teetKeyResult, logger);
|
|
12
|
+
if (!bundle.teekSigned || !bundle.teetSigned) {
|
|
13
|
+
throw new AttestorError("ERROR_INVALID_CLAIM", "Missing TEE signed messages");
|
|
14
|
+
}
|
|
15
|
+
const kOutputPayload = parseKOutputPayload(bundle.teekSigned);
|
|
16
|
+
const tOutputPayload = parseTOutputPayload(bundle.teetSigned);
|
|
17
|
+
validateTimestamps(kOutputPayload, tOutputPayload, logger);
|
|
18
|
+
const teeSessionId = validateSessionIds(kOutputPayload, tOutputPayload, logger);
|
|
19
|
+
logger.info("TEE bundle verification successful");
|
|
20
|
+
return {
|
|
21
|
+
teekSigned: bundle.teekSigned,
|
|
22
|
+
teetSigned: bundle.teetSigned,
|
|
23
|
+
kOutputPayload,
|
|
24
|
+
tOutputPayload,
|
|
25
|
+
teekPcr0: teekKeyResult.pcr0,
|
|
26
|
+
teetPcr0: teetKeyResult.pcr0,
|
|
27
|
+
teeSessionId
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function parseVerificationBundle(bundleBytes) {
|
|
31
|
+
try {
|
|
32
|
+
return VerificationBundle.decode(bundleBytes);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
throw new Error(`Failed to parse verification bundle: ${error.message}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function validateBundleCompleteness(bundle) {
|
|
38
|
+
if (!bundle.teekSigned) {
|
|
39
|
+
throw new Error("SECURITY ERROR: missing TEE_K signed message - verification bundle incomplete");
|
|
40
|
+
}
|
|
41
|
+
if (!bundle.teetSigned) {
|
|
42
|
+
throw new Error("SECURITY ERROR: missing TEE_T signed message - verification bundle incomplete");
|
|
43
|
+
}
|
|
44
|
+
const hasAttestations = bundle.teekSigned.attestationReport?.report && bundle.teekSigned.attestationReport.report.length > 0 || bundle.teetSigned.attestationReport?.report && bundle.teetSigned.attestationReport.report.length > 0;
|
|
45
|
+
const hasPublicKeys = bundle.teekSigned.ethAddress && bundle.teekSigned.ethAddress.length > 0 || bundle.teetSigned.ethAddress && bundle.teetSigned.ethAddress.length > 0;
|
|
46
|
+
if (!hasAttestations && !hasPublicKeys) {
|
|
47
|
+
throw new Error("SECURITY ERROR: bundle must have either Nitro attestations (production) or embedded public keys (development)");
|
|
48
|
+
}
|
|
49
|
+
if (bundle.teekSigned.bodyType !== BodyType.BODY_TYPE_K_OUTPUT) {
|
|
50
|
+
throw new Error("Invalid TEE_K signed message: wrong body type");
|
|
51
|
+
}
|
|
52
|
+
if (bundle.teetSigned.bodyType !== BodyType.BODY_TYPE_T_OUTPUT) {
|
|
53
|
+
throw new Error("Invalid TEE_T signed message: wrong body type");
|
|
54
|
+
}
|
|
55
|
+
if (!bundle.teekSigned.body || bundle.teekSigned.body.length === 0) {
|
|
56
|
+
throw new Error("Invalid TEE_K signed message: empty body");
|
|
57
|
+
}
|
|
58
|
+
if (!bundle.teetSigned.body || bundle.teetSigned.body.length === 0) {
|
|
59
|
+
throw new Error("Invalid TEE_T signed message: empty body");
|
|
60
|
+
}
|
|
61
|
+
if (!bundle.teekSigned.signature || bundle.teekSigned.signature.length === 0) {
|
|
62
|
+
throw new Error("Invalid TEE_K signed message: missing signature");
|
|
63
|
+
}
|
|
64
|
+
if (!bundle.teetSigned.signature || bundle.teetSigned.signature.length === 0) {
|
|
65
|
+
throw new Error("Invalid TEE_T signed message: missing signature");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async function extractPublicKeys(bundle, logger) {
|
|
69
|
+
const hasEmbeddedAttestations = bundle.teekSigned.attestationReport?.report && bundle.teekSigned.attestationReport.report.length > 0 && (bundle.teetSigned.attestationReport?.report && bundle.teetSigned.attestationReport.report.length > 0);
|
|
70
|
+
let teekKeyResult;
|
|
71
|
+
let teetKeyResult;
|
|
72
|
+
if (hasEmbeddedAttestations) {
|
|
73
|
+
logger.info("Using production mode: extracting keys from attestations");
|
|
74
|
+
if (!bundle.teekSigned?.attestationReport?.report) {
|
|
75
|
+
throw new Error("TEE_K embedded attestation report missing");
|
|
76
|
+
}
|
|
77
|
+
if (!bundle.teetSigned?.attestationReport?.report) {
|
|
78
|
+
throw new Error("TEE_T embedded attestation report missing");
|
|
79
|
+
}
|
|
80
|
+
const teekAttestationType = bundle.teekSigned.attestationReport.type || "nitro";
|
|
81
|
+
const teetAttestationType = bundle.teetSigned.attestationReport.type || "nitro";
|
|
82
|
+
logger.info(`TEE_K attestation type: ${teekAttestationType}`);
|
|
83
|
+
logger.info(`TEE_T attestation type: ${teetAttestationType}`);
|
|
84
|
+
const teekAttestationBytes = bundle.teekSigned.attestationReport.report;
|
|
85
|
+
const teetAttestationBytes = bundle.teetSigned.attestationReport.report;
|
|
86
|
+
if (teekAttestationType === "gcp") {
|
|
87
|
+
const gcpResult = await validateGcpAttestationAndExtractKey(teekAttestationBytes, logger);
|
|
88
|
+
if (!gcpResult.isValid) {
|
|
89
|
+
throw new Error(`TEE_K GCP attestation validation failed: ${gcpResult.errors.join(", ")}`);
|
|
90
|
+
}
|
|
91
|
+
if (!gcpResult.ethAddress) {
|
|
92
|
+
throw new Error("TEE_K GCP attestation validation failed: no address");
|
|
93
|
+
}
|
|
94
|
+
if (gcpResult.userDataType !== "tee_k") {
|
|
95
|
+
throw new Error(`TEE_K GCP attestation validation failed: wrong TEE type, expected tee_k, got ${gcpResult.userDataType}`);
|
|
96
|
+
}
|
|
97
|
+
teekKeyResult = {
|
|
98
|
+
teeType: gcpResult.userDataType,
|
|
99
|
+
ethAddress: "0x" + Buffer.from(gcpResult.ethAddress).toString("hex"),
|
|
100
|
+
pcr0: gcpResult.pcr0 || "gcp-no-digest"
|
|
101
|
+
};
|
|
102
|
+
} else {
|
|
103
|
+
const nitroResult = await validateNitroAttestationAndExtractKey(teekAttestationBytes);
|
|
104
|
+
if (!nitroResult.isValid) {
|
|
105
|
+
throw new Error(`TEE_K Nitro attestation validation failed: ${nitroResult.errors.join(", ")}`);
|
|
106
|
+
}
|
|
107
|
+
if (!nitroResult.ethAddress) {
|
|
108
|
+
throw new Error("TEE_K Nitro attestation validation failed: no address");
|
|
109
|
+
}
|
|
110
|
+
if (nitroResult.userDataType !== "tee_k") {
|
|
111
|
+
throw new Error(`TEE_K Nitro attestation validation failed: wrong TEE type, expected tee_k, got ${nitroResult.userDataType}`);
|
|
112
|
+
}
|
|
113
|
+
teekKeyResult = {
|
|
114
|
+
teeType: nitroResult.userDataType,
|
|
115
|
+
ethAddress: nitroResult.ethAddress,
|
|
116
|
+
pcr0: nitroResult.pcr0
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (teetAttestationType === "gcp") {
|
|
120
|
+
const gcpResult = await validateGcpAttestationAndExtractKey(teetAttestationBytes, logger);
|
|
121
|
+
if (!gcpResult.isValid) {
|
|
122
|
+
throw new Error(`TEE_T GCP attestation validation failed: ${gcpResult.errors.join(", ")}`);
|
|
123
|
+
}
|
|
124
|
+
if (!gcpResult.ethAddress) {
|
|
125
|
+
throw new Error("TEE_T GCP attestation validation failed: no address");
|
|
126
|
+
}
|
|
127
|
+
if (gcpResult.userDataType !== "tee_t") {
|
|
128
|
+
throw new Error(`TEE_T GCP attestation validation failed: wrong TEE type, expected tee_t, got ${gcpResult.userDataType}`);
|
|
129
|
+
}
|
|
130
|
+
teetKeyResult = {
|
|
131
|
+
teeType: gcpResult.userDataType,
|
|
132
|
+
ethAddress: "0x" + Buffer.from(gcpResult.ethAddress).toString("hex"),
|
|
133
|
+
pcr0: gcpResult.pcr0 || "gcp-no-digest"
|
|
134
|
+
};
|
|
135
|
+
if (!gcpResult.envVars?.EXPECTED_TEEK_PCR0) {
|
|
136
|
+
throw new Error("TEE_T GCP attestation missing required EXPECTED_TEEK_PCR0 environment variable");
|
|
137
|
+
}
|
|
138
|
+
const expectedPcr0 = gcpResult.envVars.EXPECTED_TEEK_PCR0;
|
|
139
|
+
const actualPcr0 = teekKeyResult.pcr0;
|
|
140
|
+
logger.info(`Cross-validating TEE_K PCR0: expected=${expectedPcr0}, actual=${actualPcr0}`);
|
|
141
|
+
if (expectedPcr0 !== actualPcr0) {
|
|
142
|
+
throw new Error(`TEE cross-validation failed: TEE_T expects TEE_K PCR0 "${expectedPcr0}" but got "${actualPcr0}"`);
|
|
143
|
+
}
|
|
144
|
+
logger.info("TEE cross-validation successful: TEE_K PCR0 matches TEE_T expectation");
|
|
145
|
+
} else {
|
|
146
|
+
const nitroResult = await validateNitroAttestationAndExtractKey(teetAttestationBytes);
|
|
147
|
+
if (!nitroResult.isValid) {
|
|
148
|
+
throw new Error(`TEE_T Nitro attestation validation failed: ${nitroResult.errors.join(", ")}`);
|
|
149
|
+
}
|
|
150
|
+
if (!nitroResult.ethAddress) {
|
|
151
|
+
throw new Error("TEE_T Nitro attestation validation failed: no address");
|
|
152
|
+
}
|
|
153
|
+
if (nitroResult.userDataType !== "tee_t") {
|
|
154
|
+
throw new Error(`TEE_T Nitro attestation validation failed: wrong TEE type, expected tee_t, got ${nitroResult.userDataType}`);
|
|
155
|
+
}
|
|
156
|
+
teetKeyResult = {
|
|
157
|
+
teeType: nitroResult.userDataType,
|
|
158
|
+
ethAddress: nitroResult.ethAddress,
|
|
159
|
+
pcr0: nitroResult.pcr0
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
logger.info("Attestations validated successfully");
|
|
163
|
+
} else {
|
|
164
|
+
const standaloneEnabled = process.env.TEE_STANDALONE === "true" || process.env.TEE_STANDALONE === "1";
|
|
165
|
+
if (!standaloneEnabled) {
|
|
166
|
+
throw new Error("Missing attestation reports and standalone mode is not enabled (set TEE_STANDALONE=true to enable)");
|
|
167
|
+
}
|
|
168
|
+
const hasEmbeddedKeys = bundle.teekSigned.ethAddress && bundle.teekSigned.ethAddress.length > 0 && (bundle.teetSigned.ethAddress && bundle.teetSigned.ethAddress.length > 0);
|
|
169
|
+
if (!hasEmbeddedKeys) {
|
|
170
|
+
throw new Error("Missing attestation and no embedded ETH addresses for standalone mode");
|
|
171
|
+
}
|
|
172
|
+
logger.warn("STANDALONE MODE ENABLED: Using embedded ETH addresses without attestation verification");
|
|
173
|
+
const teekAddress = Buffer.from(bundle.teekSigned.ethAddress).toString("utf8");
|
|
174
|
+
teekKeyResult = {
|
|
175
|
+
teeType: "tee_k",
|
|
176
|
+
ethAddress: teekAddress,
|
|
177
|
+
pcr0: "standalone-mode"
|
|
178
|
+
// No PCR0 in standalone mode
|
|
179
|
+
};
|
|
180
|
+
logger.info(`TEE_K standalone address: ${teekAddress}`);
|
|
181
|
+
const teetAddress = Buffer.from(bundle.teetSigned.ethAddress).toString("utf8");
|
|
182
|
+
teetKeyResult = {
|
|
183
|
+
teeType: "tee_t",
|
|
184
|
+
ethAddress: teetAddress,
|
|
185
|
+
pcr0: "standalone-mode"
|
|
186
|
+
// No PCR0 in standalone mode
|
|
187
|
+
};
|
|
188
|
+
logger.info(`TEE_T standalone address: ${teetAddress}`);
|
|
189
|
+
logger.info("Standalone mode key extraction successful");
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
teekKeyResult,
|
|
193
|
+
teetKeyResult
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
async function verifyTeeSignatures(bundle, teekKeyResult, teetKeyResult, logger) {
|
|
197
|
+
if (!bundle.teekSigned) {
|
|
198
|
+
throw new Error("TEE_K signed message is missing");
|
|
199
|
+
}
|
|
200
|
+
const teekResult = await verifyTeeSignature(
|
|
201
|
+
bundle.teekSigned,
|
|
202
|
+
teekKeyResult,
|
|
203
|
+
"TEE_K",
|
|
204
|
+
logger
|
|
205
|
+
);
|
|
206
|
+
if (!teekResult.isValid) {
|
|
207
|
+
throw new Error(`TEE_K signature verification failed: ${teekResult.errors.join(", ")}`);
|
|
208
|
+
}
|
|
209
|
+
if (!bundle.teetSigned) {
|
|
210
|
+
throw new Error("TEE_T signed message is missing");
|
|
211
|
+
}
|
|
212
|
+
const teetResult = await verifyTeeSignature(
|
|
213
|
+
bundle.teetSigned,
|
|
214
|
+
teetKeyResult,
|
|
215
|
+
"TEE_T",
|
|
216
|
+
logger
|
|
217
|
+
);
|
|
218
|
+
if (!teetResult.isValid) {
|
|
219
|
+
throw new Error(`TEE_T signature verification failed: ${teetResult.errors.join(", ")}`);
|
|
220
|
+
}
|
|
221
|
+
logger.info("TEE signatures verified successfully");
|
|
222
|
+
}
|
|
223
|
+
async function verifyTeeSignature(signedMessage, extractedKey, teeType, logger) {
|
|
224
|
+
const errors = [];
|
|
225
|
+
if (!signedMessage) {
|
|
226
|
+
return {
|
|
227
|
+
isValid: false,
|
|
228
|
+
errors: ["Signed message is null or undefined"]
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
try {
|
|
232
|
+
let ethAddress;
|
|
233
|
+
if (extractedKey.ethAddress) {
|
|
234
|
+
ethAddress = extractedKey.ethAddress;
|
|
235
|
+
logger.debug(`${teeType} using ETH address from attestation: ${ethAddress}`);
|
|
236
|
+
} else {
|
|
237
|
+
return {
|
|
238
|
+
isValid: false,
|
|
239
|
+
errors: ["eth address is null"]
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
const { verify: verifySig } = SIGNATURES[ServiceSignatureType.SERVICE_SIGNATURE_TYPE_ETH];
|
|
243
|
+
const isValid = await verifySig(
|
|
244
|
+
signedMessage.body,
|
|
245
|
+
signedMessage.signature,
|
|
246
|
+
ethAddress
|
|
247
|
+
);
|
|
248
|
+
if (!isValid) {
|
|
249
|
+
errors.push(`${teeType} signature verification failed for address ${ethAddress}`);
|
|
250
|
+
}
|
|
251
|
+
logger.debug(`${teeType} signature verification result: ${isValid} for address ${ethAddress}`);
|
|
252
|
+
return {
|
|
253
|
+
isValid: errors.length === 0,
|
|
254
|
+
errors,
|
|
255
|
+
address: extractedKey.ethAddress
|
|
256
|
+
};
|
|
257
|
+
} catch (error) {
|
|
258
|
+
errors.push(`${teeType} signature verification error: ${error.message}`);
|
|
259
|
+
return {
|
|
260
|
+
isValid: false,
|
|
261
|
+
errors
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function parseKOutputPayload(signedMessage) {
|
|
266
|
+
const payload = KOutputPayload.decode(signedMessage.body);
|
|
267
|
+
if (!payload.redactedRequest) {
|
|
268
|
+
throw new Error("Missing redacted request in TEE_K payload");
|
|
269
|
+
}
|
|
270
|
+
if (!payload.consolidatedResponseKeystream || payload.consolidatedResponseKeystream.length === 0) {
|
|
271
|
+
throw new Error("Missing consolidated response keystream in TEE_K payload");
|
|
272
|
+
}
|
|
273
|
+
if (!payload.certificateInfo) {
|
|
274
|
+
throw new Error("Missing certificate info in TEE_K payload");
|
|
275
|
+
}
|
|
276
|
+
return payload;
|
|
277
|
+
}
|
|
278
|
+
function parseTOutputPayload(signedMessage) {
|
|
279
|
+
const payload = TOutputPayload.decode(signedMessage.body);
|
|
280
|
+
if (!payload.consolidatedResponseCiphertext || payload.consolidatedResponseCiphertext.length === 0) {
|
|
281
|
+
throw new Error("Missing consolidated response ciphertext in TEE_T payload");
|
|
282
|
+
}
|
|
283
|
+
return payload;
|
|
284
|
+
}
|
|
285
|
+
function validateTimestamps(kPayload, tPayload, logger) {
|
|
286
|
+
const now = Date.now();
|
|
287
|
+
const kTimestamp = kPayload.timestampMs;
|
|
288
|
+
const tTimestamp = tPayload.timestampMs;
|
|
289
|
+
const kTimestampS = Math.floor(kTimestamp / 1e3);
|
|
290
|
+
const tTimestampS = Math.floor(tTimestamp / 1e3);
|
|
291
|
+
const nowS = Math.floor(now / 1e3);
|
|
292
|
+
logger.info("Validating TEE timestamps", {
|
|
293
|
+
kTimestampMs: kTimestamp,
|
|
294
|
+
tTimestampMs: tTimestamp,
|
|
295
|
+
kTimestampS,
|
|
296
|
+
tTimestampS,
|
|
297
|
+
nowS
|
|
298
|
+
});
|
|
299
|
+
const maxAgeMs = 10 * 60 * 1e3;
|
|
300
|
+
const oldestAllowed = now - maxAgeMs;
|
|
301
|
+
if (kTimestamp < oldestAllowed) {
|
|
302
|
+
throw new Error(`TEE_K timestamp ${kTimestamp} is too old. Must be within 10 minutes of current time ${now}`);
|
|
303
|
+
}
|
|
304
|
+
if (tTimestamp < oldestAllowed) {
|
|
305
|
+
throw new Error(`TEE_T timestamp ${tTimestamp} is too old. Must be within 10 minutes of current time ${now}`);
|
|
306
|
+
}
|
|
307
|
+
const maxFutureMs = 60 * 1e3;
|
|
308
|
+
const maxAllowed = now + maxFutureMs;
|
|
309
|
+
if (kTimestamp > maxAllowed) {
|
|
310
|
+
throw new Error(`TEE_K timestamp ${kTimestamp} is in the future. Current time is ${now}`);
|
|
311
|
+
}
|
|
312
|
+
if (tTimestamp > maxAllowed) {
|
|
313
|
+
throw new Error(`TEE_T timestamp ${tTimestamp} is in the future. Current time is ${now}`);
|
|
314
|
+
}
|
|
315
|
+
const timestampDiffMs = Math.abs(kTimestamp - tTimestamp);
|
|
316
|
+
const maxDiffMs = 60 * 1e3;
|
|
317
|
+
if (timestampDiffMs > maxDiffMs) {
|
|
318
|
+
throw new Error(`TEE timestamps differ by ${timestampDiffMs}ms, which exceeds maximum allowed difference of ${maxDiffMs}ms (1 minute)`);
|
|
319
|
+
}
|
|
320
|
+
logger.info("TEE timestamp validation successful", {
|
|
321
|
+
timestampDiffMs,
|
|
322
|
+
ageKMs: now - kTimestamp,
|
|
323
|
+
ageTMs: now - tTimestamp
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
function validateSessionIds(kPayload, tPayload, logger) {
|
|
327
|
+
const kSessionId = kPayload.sessionId;
|
|
328
|
+
const tSessionId = tPayload.sessionId;
|
|
329
|
+
logger.info("Validating TEE session IDs", {
|
|
330
|
+
kSessionId,
|
|
331
|
+
tSessionId
|
|
332
|
+
});
|
|
333
|
+
if (!kSessionId || kSessionId.length === 0) {
|
|
334
|
+
throw new AttestorError(
|
|
335
|
+
"ERROR_INVALID_CLAIM",
|
|
336
|
+
"Missing session_id in TEE_K payload - required for cross-TEE binding"
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
if (!tSessionId || tSessionId.length === 0) {
|
|
340
|
+
throw new AttestorError(
|
|
341
|
+
"ERROR_INVALID_CLAIM",
|
|
342
|
+
"Missing session_id in TEE_T payload - required for cross-TEE binding"
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
if (kSessionId !== tSessionId) {
|
|
346
|
+
throw new AttestorError(
|
|
347
|
+
"ERROR_INVALID_CLAIM",
|
|
348
|
+
`Session ID mismatch: TEE_K session_id "${kSessionId}" does not match TEE_T session_id "${tSessionId}".`
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
logger.info("TEE session ID validation successful", {
|
|
352
|
+
sessionId: kSessionId
|
|
353
|
+
});
|
|
354
|
+
return kSessionId;
|
|
355
|
+
}
|
|
356
|
+
export {
|
|
357
|
+
verifyTeeBundle
|
|
358
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Ajv } from "ajv";
|
|
2
|
+
import { PROVIDER_SCHEMAS } from "../../types/providers.gen.js";
|
|
3
|
+
import { AttestorError } from "../../utils/error.js";
|
|
4
|
+
const PROVIDER_VALIDATOR_MAP = {};
|
|
5
|
+
const AJV = new Ajv({
|
|
6
|
+
allErrors: true,
|
|
7
|
+
strict: true,
|
|
8
|
+
strictRequired: false,
|
|
9
|
+
formats: {
|
|
10
|
+
binary(data) {
|
|
11
|
+
return data instanceof Uint8Array || typeof Buffer !== "undefined" && Buffer.isBuffer(data);
|
|
12
|
+
},
|
|
13
|
+
url(data) {
|
|
14
|
+
try {
|
|
15
|
+
new URL(data);
|
|
16
|
+
return true;
|
|
17
|
+
} catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
function assertValidateProviderParams(name, params) {
|
|
24
|
+
let validate = PROVIDER_VALIDATOR_MAP[name];
|
|
25
|
+
if (!validate) {
|
|
26
|
+
const schema = PROVIDER_SCHEMAS[name]?.parameters;
|
|
27
|
+
if (!schema) {
|
|
28
|
+
throw new AttestorError(
|
|
29
|
+
"ERROR_BAD_REQUEST",
|
|
30
|
+
`Invalid provider name "${String(name)}"`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
validate = AJV.compile(schema);
|
|
34
|
+
}
|
|
35
|
+
if (!validate?.(params)) {
|
|
36
|
+
throw new AttestorError(
|
|
37
|
+
"ERROR_BAD_REQUEST",
|
|
38
|
+
"Params validation failed",
|
|
39
|
+
{ errors: JSON.stringify(validate.errors) }
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
assertValidateProviderParams
|
|
45
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type BGPAnnouncementOverlapData = {
|
|
2
|
+
prefix: string;
|
|
3
|
+
};
|
|
4
|
+
export type BGPListener = {
|
|
5
|
+
/**
|
|
6
|
+
* Add an IP to listen for overlap,
|
|
7
|
+
* @returns a function to remove the IP from the listener
|
|
8
|
+
*/
|
|
9
|
+
onOverlap(ips: string[], callback: (event: BGPAnnouncementOverlapData) => void): (() => void);
|
|
10
|
+
close(): void;
|
|
11
|
+
};
|
package/lib/types/bgp.js
ADDED
|
File without changes
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { ProviderClaimData } from '#src/proto/api.ts';
|
|
2
|
+
import type { IAttestorClient, IAttestorClientInitParams } from '#src/types/client.ts';
|
|
3
|
+
import type { CompleteTLSPacket, Logger } from '#src/types/general.ts';
|
|
4
|
+
import type { ProofGenerationStep, ProviderName, ProviderParams, ProviderSecretParams } from '#src/types/providers.ts';
|
|
5
|
+
import type { Transcript } from '#src/types/tunnel.ts';
|
|
6
|
+
import type { PrepareZKProofsBaseOpts } from '#src/types/zk.ts';
|
|
7
|
+
/**
|
|
8
|
+
* Uniquely identifies a claim.
|
|
9
|
+
* Hash of claim info.
|
|
10
|
+
* Utilise `getIdentifierFromClaimInfo` to obtain this.
|
|
11
|
+
*/
|
|
12
|
+
export type ClaimID = ProviderClaimData['identifier'];
|
|
13
|
+
export type ClaimInfo = Pick<ProviderClaimData, 'context' | 'provider' | 'parameters'>;
|
|
14
|
+
export type CompleteClaimData = Pick<ProviderClaimData, 'owner' | 'timestampS' | 'epoch'> & ClaimInfo;
|
|
15
|
+
export type CreateClaimOnAttestorOpts<N extends ProviderName> = {
|
|
16
|
+
/** name of the provider to generate signed receipt for */
|
|
17
|
+
name: N;
|
|
18
|
+
/**
|
|
19
|
+
* secrets that are used to make the API request;
|
|
20
|
+
* not included in the receipt & cannot be viewed by anyone
|
|
21
|
+
* outside this client
|
|
22
|
+
*/
|
|
23
|
+
secretParams: ProviderSecretParams<N>;
|
|
24
|
+
params: ProviderParams<N>;
|
|
25
|
+
/**
|
|
26
|
+
* Some metadata context to be included in the claim
|
|
27
|
+
*/
|
|
28
|
+
context?: {
|
|
29
|
+
[key: string]: any;
|
|
30
|
+
};
|
|
31
|
+
onStep?(step: ProofGenerationStep): void;
|
|
32
|
+
/**
|
|
33
|
+
* Private key in hex format,
|
|
34
|
+
* prefixed with '0x'
|
|
35
|
+
*/
|
|
36
|
+
ownerPrivateKey: string;
|
|
37
|
+
/**
|
|
38
|
+
* Provide either the client or the URL
|
|
39
|
+
* to the server -- so a client can be created internally.
|
|
40
|
+
*
|
|
41
|
+
* The created client will go into the global client pool.
|
|
42
|
+
*/
|
|
43
|
+
client: IAttestorClient | IAttestorClientInitParams;
|
|
44
|
+
/**
|
|
45
|
+
* Optionally set the timestamp of the claim
|
|
46
|
+
* in unix seconds. If not provided, the current
|
|
47
|
+
* time will be used.
|
|
48
|
+
*/
|
|
49
|
+
timestampS?: number;
|
|
50
|
+
logger?: Logger;
|
|
51
|
+
/**
|
|
52
|
+
* Maximum number of retries to attempt
|
|
53
|
+
* @default 3
|
|
54
|
+
*/
|
|
55
|
+
maxRetries?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Optionally update the provider parameters
|
|
58
|
+
* based on the transcript
|
|
59
|
+
*/
|
|
60
|
+
updateProviderParams?(transcript: Transcript<CompleteTLSPacket>, tlsVersion: string): Promise<{
|
|
61
|
+
params: Partial<ProviderParams<N>>;
|
|
62
|
+
secretParams: Partial<ProviderSecretParams<N>>;
|
|
63
|
+
}>;
|
|
64
|
+
/**
|
|
65
|
+
* Replaces paramValue with corresponding OPRF hash before proof is made
|
|
66
|
+
* Only if there's matching redaction exists
|
|
67
|
+
* For example: "domain.com" -> "dv4Nrgtr"
|
|
68
|
+
*/
|
|
69
|
+
updateParametersFromOprfData?: boolean;
|
|
70
|
+
} & PrepareZKProofsBaseOpts;
|
|
File without changes
|