@reclaimprotocol/attestor-core 5.0.1-beta.2 → 5.0.1-beta.22
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/avs/abis/avsDirectoryABI.js +338 -341
- package/lib/avs/abis/delegationABI.js +1 -4
- package/lib/avs/abis/registryABI.js +719 -722
- package/lib/avs/client/create-claim-on-avs.js +129 -157
- package/lib/avs/config.js +18 -24
- package/lib/avs/contracts/ReclaimServiceManager.js +1 -0
- package/lib/avs/contracts/common.js +1 -0
- package/lib/avs/contracts/factories/ReclaimServiceManager__factory.js +1139 -1156
- package/lib/avs/contracts/factories/index.js +4 -4
- package/lib/avs/contracts/index.js +2 -6
- package/lib/avs/types/index.js +1 -0
- package/lib/avs/utils/contracts.js +30 -50
- package/lib/avs/utils/register.js +75 -70
- package/lib/avs/utils/tasks.js +38 -45
- package/lib/client/create-claim.js +402 -431
- package/lib/client/tunnels/make-rpc-tcp-tunnel.js +46 -48
- package/lib/client/tunnels/make-rpc-tls-tunnel.js +125 -121
- package/lib/client/utils/attestor-pool.js +23 -22
- package/lib/client/utils/client-socket.js +86 -109
- package/lib/client/utils/message-handler.js +79 -89
- package/lib/config/index.js +40 -58
- package/lib/external-rpc/benchmark.js +61 -74
- package/lib/external-rpc/event-bus.js +12 -15
- package/lib/external-rpc/handle-incoming-msg.js +216 -225
- package/lib/external-rpc/jsc-polyfills/1.js +70 -68
- package/lib/external-rpc/jsc-polyfills/2.js +17 -12
- package/lib/external-rpc/jsc-polyfills/event.js +10 -15
- package/lib/external-rpc/jsc-polyfills/index.js +2 -2
- package/lib/external-rpc/jsc-polyfills/ws.js +77 -79
- package/lib/external-rpc/setup-browser.js +28 -28
- package/lib/external-rpc/setup-jsc.js +17 -17
- package/lib/external-rpc/types.js +1 -0
- package/lib/external-rpc/utils.js +89 -89
- package/lib/external-rpc/zk.js +55 -50
- package/lib/index.js +2 -6
- package/lib/mechain/abis/governanceABI.js +457 -460
- package/lib/mechain/abis/taskABI.js +502 -505
- package/lib/mechain/client/create-claim-on-mechain.js +24 -29
- package/lib/mechain/constants/index.js +3 -8
- package/lib/mechain/types/index.js +1 -0
- package/lib/proto/api.js +4200 -4087
- package/lib/proto/tee-bundle.js +1261 -1241
- package/lib/providers/http/index.js +616 -603
- package/lib/providers/http/patch-parse5-tree.js +27 -29
- package/lib/providers/http/utils.js +289 -248
- package/lib/providers/index.js +3 -6
- package/lib/server/create-server.js +89 -91
- package/lib/server/handlers/claimTeeBundle.js +231 -211
- package/lib/server/handlers/claimTunnel.js +66 -73
- package/lib/server/handlers/completeClaimOnChain.js +20 -25
- package/lib/server/handlers/createClaimOnChain.js +21 -27
- package/lib/server/handlers/createTaskOnMechain.js +40 -50
- package/lib/server/handlers/createTunnel.js +85 -90
- package/lib/server/handlers/disconnectTunnel.js +4 -7
- package/lib/server/handlers/fetchCertificateBytes.js +37 -53
- package/lib/server/handlers/index.js +21 -24
- package/lib/server/handlers/init.js +27 -28
- package/lib/server/handlers/toprf.js +13 -16
- package/lib/server/socket.js +97 -100
- package/lib/server/tunnels/make-tcp-tunnel.js +161 -186
- package/lib/server/utils/apm.js +32 -25
- package/lib/server/utils/assert-valid-claim-request.js +305 -334
- package/lib/server/utils/config-env.js +2 -2
- package/lib/server/utils/dns.js +12 -18
- package/lib/server/utils/gcp-attestation.js +233 -181
- package/lib/server/utils/generics.d.ts +1 -1
- package/lib/server/utils/generics.js +43 -37
- package/lib/server/utils/iso.js +253 -256
- package/lib/server/utils/keep-alive.js +36 -36
- package/lib/server/utils/nitro-attestation.js +295 -220
- package/lib/server/utils/oprf-raw.js +48 -55
- package/lib/server/utils/process-handshake.js +200 -218
- package/lib/server/utils/proxy-session.js +5 -5
- package/lib/server/utils/tee-oprf-mpc-verification.js +82 -78
- package/lib/server/utils/tee-oprf-verification.js +165 -142
- package/lib/server/utils/tee-transcript-reconstruction.js +176 -129
- package/lib/server/utils/tee-verification.js +397 -334
- package/lib/server/utils/validation.js +30 -37
- package/lib/types/bgp.js +1 -0
- package/lib/types/claims.js +1 -0
- package/lib/types/client.js +1 -0
- package/lib/types/general.js +1 -0
- package/lib/types/handlers.js +1 -0
- package/lib/types/providers.d.ts +3 -2
- package/lib/types/providers.gen.js +9 -15
- package/lib/types/providers.js +1 -0
- package/lib/types/rpc.js +1 -0
- package/lib/types/signatures.d.ts +1 -2
- package/lib/types/signatures.js +1 -0
- package/lib/types/tunnel.js +1 -0
- package/lib/types/zk.js +1 -0
- package/lib/utils/auth.js +54 -66
- package/lib/utils/b64-json.js +15 -15
- package/lib/utils/bgp-listener.js +107 -111
- package/lib/utils/claims.js +89 -80
- package/lib/utils/env.js +13 -17
- package/lib/utils/error.js +43 -47
- package/lib/utils/generics.js +284 -235
- package/lib/utils/http-parser.js +232 -187
- package/lib/utils/logger.js +80 -71
- package/lib/utils/prepare-packets.js +69 -67
- package/lib/utils/redactions.js +163 -121
- package/lib/utils/retries.js +22 -24
- package/lib/utils/signatures/eth.js +29 -28
- package/lib/utils/signatures/index.js +5 -10
- package/lib/utils/socket-base.js +84 -88
- package/lib/utils/tls.js +28 -28
- package/lib/utils/ws.js +19 -19
- package/lib/utils/zk.js +542 -582
- package/package.json +12 -5
- package/lib/external-rpc/global.d.js +0 -0
- package/lib/scripts/build-browser.d.ts +0 -1
- package/lib/scripts/build-jsc.d.ts +0 -1
- package/lib/scripts/build-lib.d.ts +0 -1
- package/lib/scripts/check-avs-registration.d.ts +0 -1
- package/lib/scripts/check-avs-registration.js +0 -28
- package/lib/scripts/fallbacks/crypto.d.ts +0 -1
- package/lib/scripts/fallbacks/crypto.js +0 -4
- package/lib/scripts/fallbacks/empty.d.ts +0 -3
- package/lib/scripts/fallbacks/empty.js +0 -4
- package/lib/scripts/fallbacks/re2.d.ts +0 -1
- package/lib/scripts/fallbacks/re2.js +0 -7
- package/lib/scripts/fallbacks/snarkjs.d.ts +0 -1
- package/lib/scripts/fallbacks/snarkjs.js +0 -10
- package/lib/scripts/fallbacks/stwo.d.ts +0 -6
- package/lib/scripts/fallbacks/stwo.js +0 -159
- package/lib/scripts/generate-provider-types.d.ts +0 -5
- package/lib/scripts/generate-provider-types.js +0 -101
- package/lib/scripts/generate-receipt.d.ts +0 -9
- package/lib/scripts/generate-receipt.js +0 -101
- package/lib/scripts/generate-toprf-keys.d.ts +0 -1
- package/lib/scripts/generate-toprf-keys.js +0 -24
- package/lib/scripts/jsc-cli-rpc.d.ts +0 -1
- package/lib/scripts/jsc-cli-rpc.js +0 -35
- package/lib/scripts/register-avs-operator.d.ts +0 -1
- package/lib/scripts/register-avs-operator.js +0 -3
- package/lib/scripts/start-server.d.ts +0 -1
- package/lib/scripts/start-server.js +0 -11
- package/lib/scripts/update-avs-metadata.d.ts +0 -1
- package/lib/scripts/update-avs-metadata.js +0 -20
- package/lib/scripts/utils.d.ts +0 -1
- package/lib/scripts/utils.js +0 -10
- package/lib/scripts/whitelist-operator.d.ts +0 -1
- package/lib/scripts/whitelist-operator.js +0 -16
|
@@ -1,97 +1,87 @@
|
|
|
1
1
|
import { RPCMessages } from "../../proto/api.js";
|
|
2
2
|
import { AttestorError, extractArrayBufferFromWsData, getRpcRequest, getRpcRequestType, getRpcResponseType } from "../../utils/index.js";
|
|
3
|
-
async function wsMessageHandler(data) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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;
|
|
3
|
+
export async function wsMessageHandler(data) {
|
|
4
|
+
// extract array buffer from WS data & decode proto
|
|
5
|
+
const buff = await extractArrayBufferFromWsData(data);
|
|
6
|
+
const { messages } = RPCMessages.decode(buff);
|
|
7
|
+
for (const msg of messages) {
|
|
8
|
+
await handleMessage.call(this, msg);
|
|
42
9
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
10
|
+
}
|
|
11
|
+
export function handleMessage(msg) {
|
|
12
|
+
this.logger?.trace({ msg }, 'received message');
|
|
13
|
+
// handle connection termination alert
|
|
14
|
+
if (msg.connectionTerminationAlert) {
|
|
15
|
+
const err = AttestorError.fromProto(msg.connectionTerminationAlert);
|
|
16
|
+
this.logger?.warn({
|
|
17
|
+
err: err.code !== 'ERROR_NO_ERROR'
|
|
18
|
+
? err
|
|
19
|
+
: undefined
|
|
20
|
+
}, 'received connection termination alert');
|
|
21
|
+
this.dispatchRPCEvent('connection-terminated', err);
|
|
22
|
+
return;
|
|
53
23
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
{ type: rpcRequest.type, res },
|
|
63
|
-
"connection closed before responding"
|
|
64
|
-
);
|
|
65
|
-
reject(new Error("connection closed"));
|
|
24
|
+
const rpcRequest = getRpcRequest(msg);
|
|
25
|
+
if (rpcRequest) {
|
|
26
|
+
if (rpcRequest.direction === 'response'
|
|
27
|
+
&& rpcRequest.type === 'error') {
|
|
28
|
+
this.dispatchRPCEvent('rpc-response', {
|
|
29
|
+
id: msg.id,
|
|
30
|
+
error: AttestorError.fromProto(msg.requestError)
|
|
31
|
+
});
|
|
66
32
|
return;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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]
|
|
73
40
|
});
|
|
74
|
-
|
|
75
|
-
resolve();
|
|
76
|
-
return this.sendMessage({ id: msg.id, [resType]: res });
|
|
41
|
+
return;
|
|
77
42
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
43
|
+
if (!this.isInitialised && rpcRequest.type !== 'init') {
|
|
44
|
+
this.logger.warn({ type: rpcRequest.type }, 'RPC request received before initialisation');
|
|
45
|
+
void this.sendMessage({
|
|
46
|
+
id: msg.id,
|
|
47
|
+
requestError: AttestorError
|
|
48
|
+
.badRequest('Initialise connection first')
|
|
49
|
+
.toProto()
|
|
50
|
+
});
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
this.dispatchRPCEvent('rpc-request', {
|
|
55
|
+
requestId: msg.id,
|
|
56
|
+
type: rpcRequest.type,
|
|
57
|
+
data: msg[getRpcRequestType(rpcRequest.type)],
|
|
58
|
+
respond: (res) => {
|
|
59
|
+
if (!this.isOpen) {
|
|
60
|
+
this.logger?.debug({ type: rpcRequest.type, res }, 'connection closed before responding');
|
|
61
|
+
reject(new Error('connection closed'));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if ('code' in res) {
|
|
65
|
+
reject(res);
|
|
66
|
+
return this.sendMessage({
|
|
67
|
+
id: msg.id,
|
|
68
|
+
requestError: res.toProto()
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
resolve();
|
|
72
|
+
return this
|
|
73
|
+
.sendMessage({ id: msg.id, [resType]: res });
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
if (msg.tunnelMessage) {
|
|
79
|
+
this.dispatchRPCEvent('tunnel-message', msg.tunnelMessage);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (msg.tunnelDisconnectEvent) {
|
|
83
|
+
this.dispatchRPCEvent('tunnel-disconnect-event', msg.tunnelDisconnectEvent);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
this.logger.warn({ msg }, 'unhandled message');
|
|
93
87
|
}
|
|
94
|
-
export {
|
|
95
|
-
handleMessage,
|
|
96
|
-
wsMessageHandler
|
|
97
|
-
};
|
package/lib/config/index.js
CHANGED
|
@@ -1,62 +1,44 @@
|
|
|
1
1
|
import { AttestorVersion, ServiceSignatureType } from "../proto/api.js";
|
|
2
|
-
const DEFAULT_ZK_CONCURRENCY = 10;
|
|
3
|
-
const RECLAIM_USER_AGENT =
|
|
4
|
-
const DEFAULT_HTTPS_PORT = 443;
|
|
5
|
-
const WS_PATHNAME =
|
|
6
|
-
const BROWSER_RPC_PATHNAME =
|
|
7
|
-
const ATTESTOR_ADDRESS_PATHNAME =
|
|
8
|
-
const DEFAULT_REMOTE_FILE_FETCH_BASE_URL = `${BROWSER_RPC_PATHNAME}/resources`;
|
|
9
|
-
const API_SERVER_PORT = 8001;
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
export const DEFAULT_ZK_CONCURRENCY = 10;
|
|
3
|
+
export const RECLAIM_USER_AGENT = 'reclaim/0.0.1';
|
|
4
|
+
export const DEFAULT_HTTPS_PORT = 443;
|
|
5
|
+
export const WS_PATHNAME = '/ws';
|
|
6
|
+
export const BROWSER_RPC_PATHNAME = '/browser-rpc';
|
|
7
|
+
export const ATTESTOR_ADDRESS_PATHNAME = '/address';
|
|
8
|
+
export const DEFAULT_REMOTE_FILE_FETCH_BASE_URL = `${BROWSER_RPC_PATHNAME}/resources`;
|
|
9
|
+
export const API_SERVER_PORT = 8001;
|
|
10
|
+
// 10s
|
|
11
|
+
export const CONNECTION_TIMEOUT_MS = 10_000;
|
|
12
|
+
export const DNS_SERVERS = [
|
|
13
|
+
'8.8.8.8',
|
|
14
|
+
'8.8.4.4'
|
|
14
15
|
];
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
// 10m
|
|
17
|
+
export const MAX_CLAIM_TIMESTAMP_DIFF_S = 10 * 60;
|
|
18
|
+
export const CURRENT_ATTESTOR_VERSION = AttestorVersion.ATTESTOR_VERSION_3_0_0;
|
|
19
|
+
export const DEFAULT_METADATA = {
|
|
20
|
+
signatureType: ServiceSignatureType.SERVICE_SIGNATURE_TYPE_ETH,
|
|
21
|
+
clientVersion: CURRENT_ATTESTOR_VERSION,
|
|
22
|
+
auth: undefined
|
|
21
23
|
};
|
|
22
|
-
const PROVIDER_CTX = { version: CURRENT_ATTESTOR_VERSION };
|
|
23
|
-
const PING_INTERVAL_MS =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
export const PROVIDER_CTX = { version: CURRENT_ATTESTOR_VERSION };
|
|
25
|
+
export const PING_INTERVAL_MS = 10_000;
|
|
26
|
+
/**
|
|
27
|
+
* Maximum interval in seconds to wait for before assuming
|
|
28
|
+
* the connection is dead
|
|
29
|
+
* @default 30s
|
|
30
|
+
*/
|
|
31
|
+
export const MAX_NO_DATA_INTERVAL_MS = 30_000;
|
|
32
|
+
export const MAX_PAYLOAD_SIZE = 512 * 1024 * 1024; // 512MB
|
|
33
|
+
export const DEFAULT_AUTH_EXPIRY_S = 15 * 60; // 15m
|
|
34
|
+
export const DEFAULT_RPC_TIMEOUT_MS = 90_000;
|
|
35
|
+
export const TOPRF_DOMAIN_SEPARATOR = 'reclaim-toprf';
|
|
36
|
+
export const MAX_CERT_SIZE_BYTES = 10 * 1024 * 1024 * 1024; // 10MB
|
|
37
|
+
export const CERT_ALLOWED_MIMETYPES = [
|
|
38
|
+
'application/x-x509-ca-cert',
|
|
39
|
+
'application/x-x509-user-cert',
|
|
40
|
+
'application/pkix-cert',
|
|
41
|
+
'application/pkcs7-mime',
|
|
42
|
+
'application/octet-stream'
|
|
36
43
|
];
|
|
37
|
-
const BGP_WS_URL =
|
|
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
|
-
};
|
|
44
|
+
export const BGP_WS_URL = 'wss://ris-live.ripe.net/v1/ws/?client=reclaim-hijack-detector';
|
|
@@ -1,82 +1,69 @@
|
|
|
1
|
-
import {
|
|
2
|
-
crypto,
|
|
3
|
-
encryptWrappedRecord,
|
|
4
|
-
SUPPORTED_CIPHER_SUITE_MAP
|
|
5
|
-
} from "@reclaimprotocol/tls";
|
|
1
|
+
import { crypto, encryptWrappedRecord, SUPPORTED_CIPHER_SUITE_MAP } from '@reclaimprotocol/tls';
|
|
6
2
|
import { strToUint8Array } from "../utils/generics.js";
|
|
7
3
|
import { logger } from "../utils/logger.js";
|
|
8
4
|
import { makeZkProofGenerator } from "../utils/zk.js";
|
|
9
5
|
const ZK_CIPHER_SUITES = [
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
'TLS_CHACHA20_POLY1305_SHA256',
|
|
7
|
+
'TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384',
|
|
8
|
+
'TLS_AES_128_GCM_SHA256'
|
|
13
9
|
];
|
|
14
|
-
async function benchmark() {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
10
|
+
export async function benchmark() {
|
|
11
|
+
let benchmarkRes = '';
|
|
12
|
+
for (const cipherSuite of ZK_CIPHER_SUITES) {
|
|
13
|
+
const now = Date.now();
|
|
14
|
+
const alg = cipherSuite.includes('CHACHA20')
|
|
15
|
+
? 'CHACHA20-POLY1305'
|
|
16
|
+
: (cipherSuite.includes('AES_256_GCM')
|
|
17
|
+
? 'AES-256-GCM'
|
|
18
|
+
: 'AES-128-GCM');
|
|
19
|
+
const keylength = alg === 'AES-128-GCM' ? 16 : 32;
|
|
20
|
+
const key = Buffer.alloc(keylength, 0);
|
|
21
|
+
const { ivLength: fixedIvLength, } = SUPPORTED_CIPHER_SUITE_MAP[cipherSuite];
|
|
22
|
+
const fixedIv = Buffer.alloc(fixedIvLength, 0);
|
|
23
|
+
const encKey = await crypto.importKey(alg, key);
|
|
24
|
+
const vectors = [
|
|
25
|
+
{
|
|
26
|
+
plaintext: 'My cool API secret is "my name jeff". Please don\'t reveal it'
|
|
27
|
+
}
|
|
28
|
+
];
|
|
29
|
+
const proofGenerator = await makeZkProofGenerator({
|
|
30
|
+
logger,
|
|
31
|
+
cipherSuite,
|
|
32
|
+
});
|
|
33
|
+
for (const { plaintext } of vectors) {
|
|
34
|
+
const plaintextArr = strToUint8Array(plaintext);
|
|
35
|
+
const { ciphertext, iv } = await encryptWrappedRecord(plaintextArr, {
|
|
36
|
+
key: encKey,
|
|
37
|
+
iv: fixedIv,
|
|
38
|
+
recordNumber: 0,
|
|
39
|
+
recordHeaderOpts: {
|
|
40
|
+
type: 'WRAPPED_RECORD'
|
|
41
|
+
},
|
|
42
|
+
cipherSuite,
|
|
43
|
+
version: cipherSuite.includes('ECDHE_')
|
|
44
|
+
? 'TLS1_2'
|
|
45
|
+
: 'TLS1_3',
|
|
46
|
+
});
|
|
47
|
+
const packet = {
|
|
48
|
+
type: 'ciphertext',
|
|
49
|
+
encKey,
|
|
50
|
+
iv,
|
|
51
|
+
recordNumber: 0,
|
|
52
|
+
plaintext: plaintextArr,
|
|
53
|
+
ciphertext,
|
|
54
|
+
fixedIv: new Uint8Array(0),
|
|
55
|
+
data: ciphertext
|
|
56
|
+
};
|
|
57
|
+
await proofGenerator.addPacketToProve(packet, {
|
|
58
|
+
type: 'zk',
|
|
59
|
+
redactedPlaintext: plaintextArr,
|
|
60
|
+
}, () => { }, () => {
|
|
61
|
+
throw new Error('should not be called in benchmark');
|
|
62
|
+
});
|
|
63
|
+
await proofGenerator.generateProofs();
|
|
48
64
|
}
|
|
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();
|
|
65
|
+
benchmarkRes = benchmarkRes + `Benchmark ${alg} ok. Took ${Date.now() - now} ms \n`;
|
|
73
66
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
logger.info(benchmarkRes);
|
|
78
|
-
return benchmarkRes;
|
|
67
|
+
logger.info(benchmarkRes);
|
|
68
|
+
return benchmarkRes;
|
|
79
69
|
}
|
|
80
|
-
export {
|
|
81
|
-
benchmark
|
|
82
|
-
};
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
class EventBus {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
export 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
|
+
}
|
|
12
13
|
}
|
|
13
|
-
}
|
|
14
14
|
}
|
|
15
|
-
export {
|
|
16
|
-
EventBus
|
|
17
|
-
};
|