@reclaimprotocol/attestor-core 5.0.1-beta.2 → 5.0.1-beta.21
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/browser/resources/attestor-browser.min.mjs +4512 -0
- package/lib/external-rpc/index.js +10399 -3
- package/lib/index.js +8323 -10
- package/package.json +9 -4
- package/lib/avs/abis/avsDirectoryABI.js +0 -343
- package/lib/avs/abis/delegationABI.js +0 -4
- package/lib/avs/abis/registryABI.js +0 -728
- package/lib/avs/client/create-claim-on-avs.js +0 -168
- package/lib/avs/config.js +0 -26
- package/lib/avs/contracts/ReclaimServiceManager.js +0 -0
- package/lib/avs/contracts/common.js +0 -0
- package/lib/avs/contracts/factories/ReclaimServiceManager__factory.js +0 -1183
- package/lib/avs/contracts/factories/index.js +0 -4
- package/lib/avs/contracts/index.js +0 -6
- package/lib/avs/types/index.js +0 -0
- package/lib/avs/utils/contracts.js +0 -53
- package/lib/avs/utils/register.js +0 -74
- package/lib/avs/utils/tasks.js +0 -48
- package/lib/client/create-claim.js +0 -461
- package/lib/client/index.js +0 -3
- package/lib/client/tunnels/make-rpc-tcp-tunnel.js +0 -53
- package/lib/client/tunnels/make-rpc-tls-tunnel.js +0 -127
- package/lib/client/utils/attestor-pool.js +0 -24
- package/lib/client/utils/client-socket.js +0 -120
- package/lib/client/utils/message-handler.js +0 -97
- package/lib/config/index.js +0 -62
- package/lib/external-rpc/benchmark.js +0 -82
- package/lib/external-rpc/event-bus.js +0 -17
- package/lib/external-rpc/global.d.js +0 -0
- package/lib/external-rpc/handle-incoming-msg.js +0 -241
- package/lib/external-rpc/jsc-polyfills/1.js +0 -80
- package/lib/external-rpc/jsc-polyfills/2.js +0 -15
- package/lib/external-rpc/jsc-polyfills/event.js +0 -19
- package/lib/external-rpc/jsc-polyfills/index.js +0 -2
- package/lib/external-rpc/jsc-polyfills/ws.js +0 -83
- package/lib/external-rpc/setup-browser.js +0 -33
- package/lib/external-rpc/setup-jsc.js +0 -22
- package/lib/external-rpc/types.js +0 -0
- package/lib/external-rpc/utils.js +0 -100
- package/lib/external-rpc/zk.js +0 -58
- package/lib/mechain/abis/governanceABI.js +0 -461
- package/lib/mechain/abis/taskABI.js +0 -512
- package/lib/mechain/client/create-claim-on-mechain.js +0 -33
- package/lib/mechain/client/index.js +0 -1
- package/lib/mechain/constants/index.js +0 -8
- package/lib/mechain/index.js +0 -2
- package/lib/mechain/types/index.js +0 -0
- package/lib/proto/api.js +0 -4250
- package/lib/proto/tee-bundle.js +0 -1296
- package/lib/providers/http/index.js +0 -640
- package/lib/providers/http/patch-parse5-tree.js +0 -34
- package/lib/providers/http/utils.js +0 -283
- package/lib/providers/index.js +0 -7
- package/lib/scripts/check-avs-registration.js +0 -28
- package/lib/scripts/fallbacks/crypto.js +0 -4
- package/lib/scripts/fallbacks/empty.js +0 -4
- package/lib/scripts/fallbacks/re2.js +0 -7
- package/lib/scripts/fallbacks/snarkjs.js +0 -10
- package/lib/scripts/fallbacks/stwo.js +0 -159
- package/lib/scripts/generate-provider-types.js +0 -101
- package/lib/scripts/generate-receipt.js +0 -101
- package/lib/scripts/generate-toprf-keys.js +0 -24
- package/lib/scripts/jsc-cli-rpc.js +0 -35
- package/lib/scripts/register-avs-operator.js +0 -3
- package/lib/scripts/start-server.js +0 -11
- package/lib/scripts/update-avs-metadata.js +0 -20
- package/lib/scripts/utils.js +0 -10
- package/lib/scripts/whitelist-operator.js +0 -16
- package/lib/server/create-server.js +0 -105
- package/lib/server/handlers/claimTeeBundle.js +0 -232
- package/lib/server/handlers/claimTunnel.js +0 -80
- package/lib/server/handlers/completeClaimOnChain.js +0 -29
- package/lib/server/handlers/createClaimOnChain.js +0 -32
- package/lib/server/handlers/createTaskOnMechain.js +0 -57
- package/lib/server/handlers/createTunnel.js +0 -98
- package/lib/server/handlers/disconnectTunnel.js +0 -8
- package/lib/server/handlers/fetchCertificateBytes.js +0 -57
- package/lib/server/handlers/index.js +0 -25
- package/lib/server/handlers/init.js +0 -33
- package/lib/server/handlers/toprf.js +0 -19
- package/lib/server/index.js +0 -4
- package/lib/server/socket.js +0 -112
- package/lib/server/tunnels/make-tcp-tunnel.js +0 -202
- package/lib/server/utils/apm.js +0 -29
- package/lib/server/utils/assert-valid-claim-request.js +0 -354
- package/lib/server/utils/config-env.js +0 -4
- package/lib/server/utils/dns.js +0 -24
- package/lib/server/utils/gcp-attestation.js +0 -237
- package/lib/server/utils/generics.js +0 -45
- package/lib/server/utils/iso.js +0 -259
- package/lib/server/utils/keep-alive.js +0 -38
- package/lib/server/utils/nitro-attestation.js +0 -249
- package/lib/server/utils/oprf-raw.js +0 -61
- package/lib/server/utils/process-handshake.js +0 -233
- package/lib/server/utils/proxy-session.js +0 -6
- package/lib/server/utils/tee-oprf-mpc-verification.js +0 -86
- package/lib/server/utils/tee-oprf-verification.js +0 -151
- package/lib/server/utils/tee-transcript-reconstruction.js +0 -140
- package/lib/server/utils/tee-verification.js +0 -358
- package/lib/server/utils/validation.js +0 -45
- package/lib/types/bgp.js +0 -0
- package/lib/types/claims.js +0 -0
- package/lib/types/client.js +0 -0
- package/lib/types/general.js +0 -0
- package/lib/types/handlers.js +0 -0
- package/lib/types/index.js +0 -10
- package/lib/types/providers.gen.js +0 -16
- package/lib/types/providers.js +0 -0
- package/lib/types/rpc.js +0 -0
- package/lib/types/signatures.js +0 -0
- package/lib/types/tunnel.js +0 -0
- package/lib/types/zk.js +0 -0
- package/lib/utils/auth.js +0 -71
- package/lib/utils/b64-json.js +0 -17
- package/lib/utils/bgp-listener.js +0 -123
- package/lib/utils/claims.js +0 -89
- package/lib/utils/env.js +0 -19
- package/lib/utils/error.js +0 -54
- package/lib/utils/generics.js +0 -268
- package/lib/utils/http-parser.js +0 -201
- package/lib/utils/index.js +0 -13
- package/lib/utils/logger.js +0 -82
- package/lib/utils/prepare-packets.js +0 -69
- package/lib/utils/redactions.js +0 -135
- package/lib/utils/retries.js +0 -26
- package/lib/utils/signatures/eth.js +0 -31
- package/lib/utils/signatures/index.js +0 -12
- package/lib/utils/socket-base.js +0 -96
- package/lib/utils/tls.js +0 -58
- package/lib/utils/ws.js +0 -22
- package/lib/utils/zk.js +0 -625
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { AttestorError } from "../../utils/index.js";
|
|
2
|
-
const makeRpcTcpTunnel = ({
|
|
3
|
-
tunnelId,
|
|
4
|
-
client,
|
|
5
|
-
onClose,
|
|
6
|
-
onMessage
|
|
7
|
-
}) => {
|
|
8
|
-
let closed = false;
|
|
9
|
-
client.addEventListener("tunnel-message", onMessageListener);
|
|
10
|
-
client.addEventListener("tunnel-disconnect-event", onDisconnectListener);
|
|
11
|
-
client.addEventListener("connection-terminated", onConnectionTerminatedListener);
|
|
12
|
-
return {
|
|
13
|
-
async write(message) {
|
|
14
|
-
await client.sendMessage({ tunnelMessage: { tunnelId, message } });
|
|
15
|
-
},
|
|
16
|
-
async close(err) {
|
|
17
|
-
if (closed) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
onErrorRecv(err);
|
|
21
|
-
await client.rpc("disconnectTunnel", { id: tunnelId });
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
function onMessageListener({ data }) {
|
|
25
|
-
if (data.tunnelId !== tunnelId) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
onMessage?.(data.message);
|
|
29
|
-
}
|
|
30
|
-
function onDisconnectListener({ data }) {
|
|
31
|
-
if (data.tunnelId !== tunnelId) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
onErrorRecv(
|
|
35
|
-
data.error?.code ? AttestorError.fromProto(data.error) : void 0
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
function onConnectionTerminatedListener({ data }) {
|
|
39
|
-
onErrorRecv(data);
|
|
40
|
-
}
|
|
41
|
-
function onErrorRecv(err) {
|
|
42
|
-
client.logger?.debug({ tunnelId, err }, "TCP tunnel closed");
|
|
43
|
-
client.removeEventListener("tunnel-message", onMessageListener);
|
|
44
|
-
client.removeEventListener("tunnel-disconnect-event", onDisconnectListener);
|
|
45
|
-
client.removeEventListener("connection-terminated", onConnectionTerminatedListener);
|
|
46
|
-
onClose?.(err);
|
|
47
|
-
onClose = void 0;
|
|
48
|
-
closed = true;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
export {
|
|
52
|
-
makeRpcTcpTunnel
|
|
53
|
-
};
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { concatenateUint8Arrays, makeTLSClient } from "@reclaimprotocol/tls";
|
|
2
|
-
import { makeRpcTcpTunnel } from "../../client/tunnels/make-rpc-tcp-tunnel.js";
|
|
3
|
-
import { DEFAULT_HTTPS_PORT } from "../../config/index.js";
|
|
4
|
-
import { generateRpcMessageId, generateTunnelId } from "../../utils/index.js";
|
|
5
|
-
const makeRpcTlsTunnel = async ({
|
|
6
|
-
onMessage,
|
|
7
|
-
onClose,
|
|
8
|
-
tlsOpts,
|
|
9
|
-
request,
|
|
10
|
-
connect,
|
|
11
|
-
logger
|
|
12
|
-
}) => {
|
|
13
|
-
const transcript = [];
|
|
14
|
-
const tunnelId = request.id || generateTunnelId();
|
|
15
|
-
let tunnel;
|
|
16
|
-
let client;
|
|
17
|
-
let handshakeResolve;
|
|
18
|
-
let handshakeReject;
|
|
19
|
-
const waitForHandshake = new Promise((resolve, reject) => {
|
|
20
|
-
handshakeResolve = resolve;
|
|
21
|
-
handshakeReject = reject;
|
|
22
|
-
});
|
|
23
|
-
const tls = makeTLSClient({
|
|
24
|
-
host: request.host,
|
|
25
|
-
...tlsOpts,
|
|
26
|
-
logger,
|
|
27
|
-
onHandshake() {
|
|
28
|
-
handshakeResolve?.();
|
|
29
|
-
},
|
|
30
|
-
onApplicationData(plaintext) {
|
|
31
|
-
return onMessage?.(plaintext);
|
|
32
|
-
},
|
|
33
|
-
onTlsEnd: onConnectionClose,
|
|
34
|
-
async write(packet, ctx) {
|
|
35
|
-
const message = concatenateUint8Arrays([
|
|
36
|
-
packet.header,
|
|
37
|
-
packet.content
|
|
38
|
-
]);
|
|
39
|
-
transcript.push({
|
|
40
|
-
sender: "client",
|
|
41
|
-
message: { ...ctx, data: message }
|
|
42
|
-
});
|
|
43
|
-
if (!tunnel) {
|
|
44
|
-
const createTunnelReqId = generateRpcMessageId();
|
|
45
|
-
client = connect([
|
|
46
|
-
{
|
|
47
|
-
id: createTunnelReqId,
|
|
48
|
-
createTunnelRequest: {
|
|
49
|
-
host: request.host || "",
|
|
50
|
-
port: request.port || DEFAULT_HTTPS_PORT,
|
|
51
|
-
geoLocation: request.geoLocation || "",
|
|
52
|
-
proxySessionId: request.proxySessionId || "",
|
|
53
|
-
id: tunnelId
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
{ tunnelMessage: { tunnelId, message } }
|
|
57
|
-
]);
|
|
58
|
-
try {
|
|
59
|
-
await makeTunnel();
|
|
60
|
-
await client.waitForResponse(createTunnelReqId);
|
|
61
|
-
} catch (err) {
|
|
62
|
-
onConnectionClose(err);
|
|
63
|
-
}
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
return tunnel.write(message);
|
|
67
|
-
},
|
|
68
|
-
onRead(packet, ctx) {
|
|
69
|
-
transcript.push({
|
|
70
|
-
sender: "server",
|
|
71
|
-
message: {
|
|
72
|
-
...ctx,
|
|
73
|
-
data: concatenateUint8Arrays([
|
|
74
|
-
packet.header,
|
|
75
|
-
// the TLS package sends us the decrypted
|
|
76
|
-
// content, so we need to get the orginal
|
|
77
|
-
// ciphertext received from the server
|
|
78
|
-
// as that's part of the true transcript.
|
|
79
|
-
ctx.type === "ciphertext" ? ctx.ciphertext : packet.content
|
|
80
|
-
])
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
await tls.startHandshake();
|
|
86
|
-
await waitForHandshake;
|
|
87
|
-
handshakeResolve = handshakeReject = void 0;
|
|
88
|
-
return {
|
|
89
|
-
transcript,
|
|
90
|
-
tls,
|
|
91
|
-
write(data) {
|
|
92
|
-
return tls.write(data);
|
|
93
|
-
},
|
|
94
|
-
async close(err) {
|
|
95
|
-
onConnectionClose(err);
|
|
96
|
-
try {
|
|
97
|
-
await tunnel.close(err);
|
|
98
|
-
} catch (err2) {
|
|
99
|
-
logger?.error({ err: err2 }, "err in close tunnel");
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
function onConnectionClose(err) {
|
|
104
|
-
onClose?.(err);
|
|
105
|
-
onClose = void 0;
|
|
106
|
-
handshakeReject?.(
|
|
107
|
-
err || new Error("TLS connection closed")
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
async function makeTunnel() {
|
|
111
|
-
tunnel = await makeRpcTcpTunnel({
|
|
112
|
-
tunnelId,
|
|
113
|
-
client,
|
|
114
|
-
onMessage(data) {
|
|
115
|
-
tls.handleReceivedBytes(data);
|
|
116
|
-
},
|
|
117
|
-
onClose(err) {
|
|
118
|
-
tls.end(err);
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
logger?.debug("plaintext tunnel created");
|
|
122
|
-
return tunnel;
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
export {
|
|
126
|
-
makeRpcTlsTunnel
|
|
127
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { AttestorClient } from "../../client/utils/client-socket.js";
|
|
2
|
-
const POOL = {};
|
|
3
|
-
function getAttestorClientFromPool(url, getCreateOpts = () => ({})) {
|
|
4
|
-
const key = url.toString();
|
|
5
|
-
let client = POOL[key];
|
|
6
|
-
let createReason;
|
|
7
|
-
if (client?.isClosed) {
|
|
8
|
-
createReason = "closed";
|
|
9
|
-
} else if (!client) {
|
|
10
|
-
createReason = "non-existent";
|
|
11
|
-
}
|
|
12
|
-
if (createReason) {
|
|
13
|
-
const createOpts = getCreateOpts();
|
|
14
|
-
createOpts?.logger?.info(
|
|
15
|
-
{ key, createReason },
|
|
16
|
-
"creating new client"
|
|
17
|
-
);
|
|
18
|
-
client = POOL[key] = new AttestorClient({ ...createOpts, url });
|
|
19
|
-
}
|
|
20
|
-
return client;
|
|
21
|
-
}
|
|
22
|
-
export {
|
|
23
|
-
getAttestorClientFromPool
|
|
24
|
-
};
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { encodeBase64 } from "ethers";
|
|
2
|
-
import { DEFAULT_METADATA, DEFAULT_RPC_TIMEOUT_MS } from "../../config/index.js";
|
|
3
|
-
import { RPCMessages } from "../../proto/api.js";
|
|
4
|
-
import { AttestorError, generateRpcMessageId, getRpcRequestType, logger as LOGGER, packRpcMessages } from "../../utils/index.js";
|
|
5
|
-
import { AttestorSocket } from "../../utils/socket-base.js";
|
|
6
|
-
import { makeWebSocket as defaultMakeWebSocket } from "../../utils/ws.js";
|
|
7
|
-
class AttestorClient extends AttestorSocket {
|
|
8
|
-
waitForInitPromise;
|
|
9
|
-
initResponse;
|
|
10
|
-
constructor({
|
|
11
|
-
url,
|
|
12
|
-
initMessages = [],
|
|
13
|
-
signatureType = DEFAULT_METADATA.signatureType,
|
|
14
|
-
logger = LOGGER,
|
|
15
|
-
authRequest,
|
|
16
|
-
makeWebSocket = defaultMakeWebSocket
|
|
17
|
-
}) {
|
|
18
|
-
const initRequest = {
|
|
19
|
-
...DEFAULT_METADATA,
|
|
20
|
-
signatureType,
|
|
21
|
-
auth: authRequest
|
|
22
|
-
};
|
|
23
|
-
const msg = packRpcMessages({ initRequest }, ...initMessages);
|
|
24
|
-
const initRequestBytes = RPCMessages.encode(msg).finish();
|
|
25
|
-
const initRequestB64 = encodeBase64(initRequestBytes);
|
|
26
|
-
url = new URL(url.toString());
|
|
27
|
-
url.searchParams.set("messages", initRequestB64);
|
|
28
|
-
super(
|
|
29
|
-
makeWebSocket(url),
|
|
30
|
-
initRequest,
|
|
31
|
-
logger
|
|
32
|
-
);
|
|
33
|
-
const initReqId = msg.messages[0].id;
|
|
34
|
-
this.waitForInitPromise = this.waitForResponse(initReqId, DEFAULT_RPC_TIMEOUT_MS).then((res) => {
|
|
35
|
-
logger.info("client initialised");
|
|
36
|
-
this.isInitialised = true;
|
|
37
|
-
this.initResponse = res;
|
|
38
|
-
});
|
|
39
|
-
this.waitForInitPromise.catch(() => {
|
|
40
|
-
});
|
|
41
|
-
this.addEventListener("connection-terminated", (ev) => logger.info({ err: ev.data }, "connection terminated"));
|
|
42
|
-
}
|
|
43
|
-
async rpc(type, request, timeoutMs = DEFAULT_RPC_TIMEOUT_MS) {
|
|
44
|
-
const msgId = generateRpcMessageId();
|
|
45
|
-
this.logger.debug({ type, id: msgId }, "sending rpc request");
|
|
46
|
-
const now = Date.now();
|
|
47
|
-
try {
|
|
48
|
-
const rslt = this.waitForResponse(msgId, timeoutMs);
|
|
49
|
-
await this.sendMessage({ id: msgId, [getRpcRequestType(type)]: request });
|
|
50
|
-
return await rslt;
|
|
51
|
-
} finally {
|
|
52
|
-
const timeTakenMs = Date.now() - now;
|
|
53
|
-
this.logger.debug({ type, timeTakenMs }, "received rpc response");
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
waitForResponse(id, timeoutMs = DEFAULT_RPC_TIMEOUT_MS) {
|
|
57
|
-
if (this.isClosed) {
|
|
58
|
-
throw new AttestorError(
|
|
59
|
-
"ERROR_NETWORK_ERROR",
|
|
60
|
-
"Client connection already closed"
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
return new Promise((resolve, reject) => {
|
|
64
|
-
const handler = (event) => {
|
|
65
|
-
if (event.data.id !== id) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
removeHandlers();
|
|
69
|
-
if ("error" in event.data) {
|
|
70
|
-
reject(event.data.error);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
resolve(event.data.data);
|
|
74
|
-
};
|
|
75
|
-
const terminateHandler = (event) => {
|
|
76
|
-
removeHandlers();
|
|
77
|
-
if (event.data.code === "ERROR_NO_ERROR") {
|
|
78
|
-
reject(
|
|
79
|
-
new AttestorError(
|
|
80
|
-
"ERROR_NETWORK_ERROR",
|
|
81
|
-
event.data.message,
|
|
82
|
-
event.data.data
|
|
83
|
-
)
|
|
84
|
-
);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
reject(event.data);
|
|
88
|
-
};
|
|
89
|
-
const timeout = setTimeout(() => {
|
|
90
|
-
removeHandlers();
|
|
91
|
-
reject(
|
|
92
|
-
new AttestorError(
|
|
93
|
-
"ERROR_TIMEOUT",
|
|
94
|
-
`RPC request timed out after ${timeoutMs}ms`,
|
|
95
|
-
{ id }
|
|
96
|
-
)
|
|
97
|
-
);
|
|
98
|
-
}, timeoutMs);
|
|
99
|
-
const removeHandlers = () => {
|
|
100
|
-
clearTimeout(timeout);
|
|
101
|
-
this.removeEventListener("rpc-response", handler);
|
|
102
|
-
this.removeEventListener("connection-terminated", terminateHandler);
|
|
103
|
-
};
|
|
104
|
-
this.addEventListener("rpc-response", handler);
|
|
105
|
-
this.addEventListener("connection-terminated", terminateHandler);
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
waitForInit = () => {
|
|
109
|
-
if (this.isClosed) {
|
|
110
|
-
throw new AttestorError(
|
|
111
|
-
"ERROR_NETWORK_ERROR",
|
|
112
|
-
"Client connection already closed"
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
return this.waitForInitPromise;
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
export {
|
|
119
|
-
AttestorClient
|
|
120
|
-
};
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { RPCMessages } from "../../proto/api.js";
|
|
2
|
-
import { AttestorError, extractArrayBufferFromWsData, getRpcRequest, getRpcRequestType, getRpcResponseType } from "../../utils/index.js";
|
|
3
|
-
async function wsMessageHandler(data) {
|
|
4
|
-
const buff = await extractArrayBufferFromWsData(data);
|
|
5
|
-
const { messages } = RPCMessages.decode(buff);
|
|
6
|
-
for (const msg of messages) {
|
|
7
|
-
await handleMessage.call(this, msg);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
function handleMessage(msg) {
|
|
11
|
-
this.logger?.trace({ msg }, "received message");
|
|
12
|
-
if (msg.connectionTerminationAlert) {
|
|
13
|
-
const err = AttestorError.fromProto(
|
|
14
|
-
msg.connectionTerminationAlert
|
|
15
|
-
);
|
|
16
|
-
this.logger?.warn(
|
|
17
|
-
{
|
|
18
|
-
err: err.code !== "ERROR_NO_ERROR" ? err : void 0
|
|
19
|
-
},
|
|
20
|
-
"received connection termination alert"
|
|
21
|
-
);
|
|
22
|
-
this.dispatchRPCEvent("connection-terminated", err);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const rpcRequest = getRpcRequest(msg);
|
|
26
|
-
if (rpcRequest) {
|
|
27
|
-
if (rpcRequest.direction === "response" && rpcRequest.type === "error") {
|
|
28
|
-
this.dispatchRPCEvent("rpc-response", {
|
|
29
|
-
id: msg.id,
|
|
30
|
-
error: AttestorError.fromProto(msg.requestError)
|
|
31
|
-
});
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const resType = getRpcResponseType(rpcRequest.type);
|
|
35
|
-
if (rpcRequest.direction === "response") {
|
|
36
|
-
this.dispatchRPCEvent("rpc-response", {
|
|
37
|
-
id: msg.id,
|
|
38
|
-
type: rpcRequest.type,
|
|
39
|
-
data: msg[resType]
|
|
40
|
-
});
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
if (!this.isInitialised && rpcRequest.type !== "init") {
|
|
44
|
-
this.logger.warn(
|
|
45
|
-
{ type: rpcRequest.type },
|
|
46
|
-
"RPC request received before initialisation"
|
|
47
|
-
);
|
|
48
|
-
void this.sendMessage({
|
|
49
|
-
id: msg.id,
|
|
50
|
-
requestError: AttestorError.badRequest("Initialise connection first").toProto()
|
|
51
|
-
});
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
return new Promise((resolve, reject) => {
|
|
55
|
-
this.dispatchRPCEvent("rpc-request", {
|
|
56
|
-
requestId: msg.id,
|
|
57
|
-
type: rpcRequest.type,
|
|
58
|
-
data: msg[getRpcRequestType(rpcRequest.type)],
|
|
59
|
-
respond: (res) => {
|
|
60
|
-
if (!this.isOpen) {
|
|
61
|
-
this.logger?.debug(
|
|
62
|
-
{ type: rpcRequest.type, res },
|
|
63
|
-
"connection closed before responding"
|
|
64
|
-
);
|
|
65
|
-
reject(new Error("connection closed"));
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
if ("code" in res) {
|
|
69
|
-
reject(res);
|
|
70
|
-
return this.sendMessage({
|
|
71
|
-
id: msg.id,
|
|
72
|
-
requestError: res.toProto()
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
resolve();
|
|
76
|
-
return this.sendMessage({ id: msg.id, [resType]: res });
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
if (msg.tunnelMessage) {
|
|
82
|
-
this.dispatchRPCEvent("tunnel-message", msg.tunnelMessage);
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
if (msg.tunnelDisconnectEvent) {
|
|
86
|
-
this.dispatchRPCEvent(
|
|
87
|
-
"tunnel-disconnect-event",
|
|
88
|
-
msg.tunnelDisconnectEvent
|
|
89
|
-
);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
this.logger.warn({ msg }, "unhandled message");
|
|
93
|
-
}
|
|
94
|
-
export {
|
|
95
|
-
handleMessage,
|
|
96
|
-
wsMessageHandler
|
|
97
|
-
};
|
package/lib/config/index.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { AttestorVersion, ServiceSignatureType } from "../proto/api.js";
|
|
2
|
-
const DEFAULT_ZK_CONCURRENCY = 10;
|
|
3
|
-
const RECLAIM_USER_AGENT = "reclaim/0.0.1";
|
|
4
|
-
const DEFAULT_HTTPS_PORT = 443;
|
|
5
|
-
const WS_PATHNAME = "/ws";
|
|
6
|
-
const BROWSER_RPC_PATHNAME = "/browser-rpc";
|
|
7
|
-
const ATTESTOR_ADDRESS_PATHNAME = "/address";
|
|
8
|
-
const DEFAULT_REMOTE_FILE_FETCH_BASE_URL = `${BROWSER_RPC_PATHNAME}/resources`;
|
|
9
|
-
const API_SERVER_PORT = 8001;
|
|
10
|
-
const CONNECTION_TIMEOUT_MS = 1e4;
|
|
11
|
-
const DNS_SERVERS = [
|
|
12
|
-
"8.8.8.8",
|
|
13
|
-
"8.8.4.4"
|
|
14
|
-
];
|
|
15
|
-
const MAX_CLAIM_TIMESTAMP_DIFF_S = 10 * 60;
|
|
16
|
-
const CURRENT_ATTESTOR_VERSION = AttestorVersion.ATTESTOR_VERSION_3_0_0;
|
|
17
|
-
const DEFAULT_METADATA = {
|
|
18
|
-
signatureType: ServiceSignatureType.SERVICE_SIGNATURE_TYPE_ETH,
|
|
19
|
-
clientVersion: CURRENT_ATTESTOR_VERSION,
|
|
20
|
-
auth: void 0
|
|
21
|
-
};
|
|
22
|
-
const PROVIDER_CTX = { version: CURRENT_ATTESTOR_VERSION };
|
|
23
|
-
const PING_INTERVAL_MS = 1e4;
|
|
24
|
-
const MAX_NO_DATA_INTERVAL_MS = 3e4;
|
|
25
|
-
const MAX_PAYLOAD_SIZE = 512 * 1024 * 1024;
|
|
26
|
-
const DEFAULT_AUTH_EXPIRY_S = 15 * 60;
|
|
27
|
-
const DEFAULT_RPC_TIMEOUT_MS = 9e4;
|
|
28
|
-
const TOPRF_DOMAIN_SEPARATOR = "reclaim-toprf";
|
|
29
|
-
const MAX_CERT_SIZE_BYTES = 10 * 1024 * 1024 * 1024;
|
|
30
|
-
const CERT_ALLOWED_MIMETYPES = [
|
|
31
|
-
"application/x-x509-ca-cert",
|
|
32
|
-
"application/x-x509-user-cert",
|
|
33
|
-
"application/pkix-cert",
|
|
34
|
-
"application/pkcs7-mime",
|
|
35
|
-
"application/octet-stream"
|
|
36
|
-
];
|
|
37
|
-
const BGP_WS_URL = "wss://ris-live.ripe.net/v1/ws/?client=reclaim-hijack-detector";
|
|
38
|
-
export {
|
|
39
|
-
API_SERVER_PORT,
|
|
40
|
-
ATTESTOR_ADDRESS_PATHNAME,
|
|
41
|
-
BGP_WS_URL,
|
|
42
|
-
BROWSER_RPC_PATHNAME,
|
|
43
|
-
CERT_ALLOWED_MIMETYPES,
|
|
44
|
-
CONNECTION_TIMEOUT_MS,
|
|
45
|
-
CURRENT_ATTESTOR_VERSION,
|
|
46
|
-
DEFAULT_AUTH_EXPIRY_S,
|
|
47
|
-
DEFAULT_HTTPS_PORT,
|
|
48
|
-
DEFAULT_METADATA,
|
|
49
|
-
DEFAULT_REMOTE_FILE_FETCH_BASE_URL,
|
|
50
|
-
DEFAULT_RPC_TIMEOUT_MS,
|
|
51
|
-
DEFAULT_ZK_CONCURRENCY,
|
|
52
|
-
DNS_SERVERS,
|
|
53
|
-
MAX_CERT_SIZE_BYTES,
|
|
54
|
-
MAX_CLAIM_TIMESTAMP_DIFF_S,
|
|
55
|
-
MAX_NO_DATA_INTERVAL_MS,
|
|
56
|
-
MAX_PAYLOAD_SIZE,
|
|
57
|
-
PING_INTERVAL_MS,
|
|
58
|
-
PROVIDER_CTX,
|
|
59
|
-
RECLAIM_USER_AGENT,
|
|
60
|
-
TOPRF_DOMAIN_SEPARATOR,
|
|
61
|
-
WS_PATHNAME
|
|
62
|
-
};
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
crypto,
|
|
3
|
-
encryptWrappedRecord,
|
|
4
|
-
SUPPORTED_CIPHER_SUITE_MAP
|
|
5
|
-
} from "@reclaimprotocol/tls";
|
|
6
|
-
import { strToUint8Array } from "../utils/generics.js";
|
|
7
|
-
import { logger } from "../utils/logger.js";
|
|
8
|
-
import { makeZkProofGenerator } from "../utils/zk.js";
|
|
9
|
-
const ZK_CIPHER_SUITES = [
|
|
10
|
-
"TLS_CHACHA20_POLY1305_SHA256",
|
|
11
|
-
"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
|
|
12
|
-
"TLS_AES_128_GCM_SHA256"
|
|
13
|
-
];
|
|
14
|
-
async function benchmark() {
|
|
15
|
-
let benchmarkRes = "";
|
|
16
|
-
for (const cipherSuite of ZK_CIPHER_SUITES) {
|
|
17
|
-
const now = Date.now();
|
|
18
|
-
const alg = cipherSuite.includes("CHACHA20") ? "CHACHA20-POLY1305" : cipherSuite.includes("AES_256_GCM") ? "AES-256-GCM" : "AES-128-GCM";
|
|
19
|
-
const keylength = alg === "AES-128-GCM" ? 16 : 32;
|
|
20
|
-
const key = Buffer.alloc(keylength, 0);
|
|
21
|
-
const {
|
|
22
|
-
ivLength: fixedIvLength
|
|
23
|
-
} = SUPPORTED_CIPHER_SUITE_MAP[cipherSuite];
|
|
24
|
-
const fixedIv = Buffer.alloc(fixedIvLength, 0);
|
|
25
|
-
const encKey = await crypto.importKey(alg, key);
|
|
26
|
-
const vectors = [
|
|
27
|
-
{
|
|
28
|
-
plaintext: `My cool API secret is "my name jeff". Please don't reveal it`
|
|
29
|
-
}
|
|
30
|
-
];
|
|
31
|
-
const proofGenerator = await makeZkProofGenerator({
|
|
32
|
-
logger,
|
|
33
|
-
cipherSuite
|
|
34
|
-
});
|
|
35
|
-
for (const { plaintext } of vectors) {
|
|
36
|
-
const plaintextArr = strToUint8Array(plaintext);
|
|
37
|
-
const { ciphertext, iv } = await encryptWrappedRecord(
|
|
38
|
-
plaintextArr,
|
|
39
|
-
{
|
|
40
|
-
key: encKey,
|
|
41
|
-
iv: fixedIv,
|
|
42
|
-
recordNumber: 0,
|
|
43
|
-
recordHeaderOpts: {
|
|
44
|
-
type: "WRAPPED_RECORD"
|
|
45
|
-
},
|
|
46
|
-
cipherSuite,
|
|
47
|
-
version: cipherSuite.includes("ECDHE_") ? "TLS1_2" : "TLS1_3"
|
|
48
|
-
}
|
|
49
|
-
);
|
|
50
|
-
const packet = {
|
|
51
|
-
type: "ciphertext",
|
|
52
|
-
encKey,
|
|
53
|
-
iv,
|
|
54
|
-
recordNumber: 0,
|
|
55
|
-
plaintext: plaintextArr,
|
|
56
|
-
ciphertext,
|
|
57
|
-
fixedIv: new Uint8Array(0),
|
|
58
|
-
data: ciphertext
|
|
59
|
-
};
|
|
60
|
-
await proofGenerator.addPacketToProve(
|
|
61
|
-
packet,
|
|
62
|
-
{
|
|
63
|
-
type: "zk",
|
|
64
|
-
redactedPlaintext: plaintextArr
|
|
65
|
-
},
|
|
66
|
-
() => {
|
|
67
|
-
},
|
|
68
|
-
() => {
|
|
69
|
-
throw new Error("should not be called in benchmark");
|
|
70
|
-
}
|
|
71
|
-
);
|
|
72
|
-
await proofGenerator.generateProofs();
|
|
73
|
-
}
|
|
74
|
-
benchmarkRes = benchmarkRes + `Benchmark ${alg} ok. Took ${Date.now() - now} ms
|
|
75
|
-
`;
|
|
76
|
-
}
|
|
77
|
-
logger.info(benchmarkRes);
|
|
78
|
-
return benchmarkRes;
|
|
79
|
-
}
|
|
80
|
-
export {
|
|
81
|
-
benchmark
|
|
82
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
class EventBus {
|
|
2
|
-
#listeners = [];
|
|
3
|
-
addListener(fn) {
|
|
4
|
-
this.#listeners.push(fn);
|
|
5
|
-
return () => {
|
|
6
|
-
this.#listeners = this.#listeners.filter((l) => l !== fn);
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
dispatch(data) {
|
|
10
|
-
for (const listener of this.#listeners) {
|
|
11
|
-
listener(data);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export {
|
|
16
|
-
EventBus
|
|
17
|
-
};
|
|
File without changes
|