@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,19 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
// @ts-expect-error
|
|
2
|
+
export class EventPolyfill {
|
|
3
|
+
type;
|
|
4
|
+
constructor(type, eventInitDict) {
|
|
5
|
+
this.type = type;
|
|
6
|
+
Object.assign(this, eventInitDict);
|
|
7
|
+
}
|
|
7
8
|
}
|
|
8
|
-
class ErrorEventPolyfill extends EventPolyfill {
|
|
9
|
+
export class ErrorEventPolyfill extends EventPolyfill {
|
|
9
10
|
}
|
|
10
|
-
class CloseEventPolyfill extends EventPolyfill {
|
|
11
|
+
export class CloseEventPolyfill extends EventPolyfill {
|
|
11
12
|
}
|
|
12
|
-
class MessageEventPolyfill extends EventPolyfill {
|
|
13
|
+
export class MessageEventPolyfill extends EventPolyfill {
|
|
13
14
|
}
|
|
14
|
-
export {
|
|
15
|
-
CloseEventPolyfill,
|
|
16
|
-
ErrorEventPolyfill,
|
|
17
|
-
EventPolyfill,
|
|
18
|
-
MessageEventPolyfill
|
|
19
|
-
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import "
|
|
1
|
+
import "./1.js";
|
|
2
|
+
import "./2.js";
|
|
@@ -1,83 +1,81 @@
|
|
|
1
|
-
import { RPC_MSG_BRIDGE, rpcRequest } from "
|
|
2
|
-
class RPCWebSocket extends EventTarget {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (typeof data !== "string" && !ArrayBuffer.isView(data)) {
|
|
31
|
-
throw new TypeError("Data must be a string, Uint8Array or ArrayBuffer");
|
|
1
|
+
import { RPC_MSG_BRIDGE, rpcRequest } from "../utils.js";
|
|
2
|
+
export class RPCWebSocket extends EventTarget {
|
|
3
|
+
CONNECTING = 0;
|
|
4
|
+
OPEN = 1;
|
|
5
|
+
CLOSING = 2;
|
|
6
|
+
CLOSED = 3;
|
|
7
|
+
id = `ws_${Date.now()}`;
|
|
8
|
+
binaryType = 'arraybuffer';
|
|
9
|
+
bufferedAmount = 0;
|
|
10
|
+
extensions = '';
|
|
11
|
+
url;
|
|
12
|
+
protocol;
|
|
13
|
+
readyState = this.CONNECTING;
|
|
14
|
+
onopen;
|
|
15
|
+
onerror;
|
|
16
|
+
onclose;
|
|
17
|
+
onmessage;
|
|
18
|
+
#cancelRpcBridge;
|
|
19
|
+
constructor(url) {
|
|
20
|
+
super();
|
|
21
|
+
this.url = url;
|
|
22
|
+
this.protocol = '';
|
|
23
|
+
this.#onMessage = this.#onMessage.bind(this);
|
|
24
|
+
rpcRequest({
|
|
25
|
+
type: 'connectWs',
|
|
26
|
+
request: { id: this.id, url }
|
|
27
|
+
})
|
|
28
|
+
.then(() => this.#callOpen(new Event('open')))
|
|
29
|
+
.catch(error => this.#callError(new ErrorEvent('error', { error })));
|
|
32
30
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
request: { id: this.id, code, reason }
|
|
40
|
-
}).then(() => this.#callClose(new CloseEvent("close", { code, reason }))).catch((error) => this.#callError(new ErrorEvent("error", { error })));
|
|
41
|
-
}
|
|
42
|
-
#callOpen(ev) {
|
|
43
|
-
this.readyState = this.OPEN;
|
|
44
|
-
this.onopen?.call(this, ev);
|
|
45
|
-
this.dispatchEvent(ev);
|
|
46
|
-
this.#cancelRpcBridge?.();
|
|
47
|
-
this.#cancelRpcBridge = RPC_MSG_BRIDGE.addListener(this.#onMessage);
|
|
48
|
-
}
|
|
49
|
-
#callError(ev) {
|
|
50
|
-
this.readyState = this.CLOSED;
|
|
51
|
-
this.onerror?.call(this, ev);
|
|
52
|
-
this.dispatchEvent(ev);
|
|
53
|
-
}
|
|
54
|
-
#callClose(ev) {
|
|
55
|
-
this.readyState = this.CLOSED;
|
|
56
|
-
this.onclose?.call(this, ev);
|
|
57
|
-
this.dispatchEvent(ev);
|
|
58
|
-
}
|
|
59
|
-
#onMessage = (msg) => {
|
|
60
|
-
if (msg.type === "sendWsMessage" && msg.request.id === this.id) {
|
|
61
|
-
const data = msg.request.data;
|
|
62
|
-
const event = new MessageEvent("message", { data });
|
|
63
|
-
this.onmessage?.call(this, event);
|
|
64
|
-
this.dispatchEvent(event);
|
|
65
|
-
return;
|
|
31
|
+
send(data) {
|
|
32
|
+
if (typeof data !== 'string'
|
|
33
|
+
&& !ArrayBuffer.isView(data)) {
|
|
34
|
+
throw new TypeError('Data must be a string, Uint8Array or ArrayBuffer');
|
|
35
|
+
}
|
|
36
|
+
rpcRequest({ type: 'sendWsMessage', request: { id: this.id, data: data } });
|
|
66
37
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
new ErrorEvent("error", { error: new Error(msg.request.err) })
|
|
76
|
-
);
|
|
77
|
-
return;
|
|
38
|
+
close(code, reason) {
|
|
39
|
+
this.readyState = this.CLOSING;
|
|
40
|
+
rpcRequest({
|
|
41
|
+
type: 'disconnectWs',
|
|
42
|
+
request: { id: this.id, code, reason }
|
|
43
|
+
})
|
|
44
|
+
.then(() => this.#callClose(new CloseEvent('close', { code, reason })))
|
|
45
|
+
.catch(error => this.#callError(new ErrorEvent('error', { error })));
|
|
78
46
|
}
|
|
79
|
-
|
|
47
|
+
#callOpen(ev) {
|
|
48
|
+
this.readyState = this.OPEN;
|
|
49
|
+
this.onopen?.call(this, ev);
|
|
50
|
+
this.dispatchEvent(ev);
|
|
51
|
+
this.#cancelRpcBridge?.();
|
|
52
|
+
this.#cancelRpcBridge = RPC_MSG_BRIDGE.addListener(this.#onMessage);
|
|
53
|
+
}
|
|
54
|
+
#callError(ev) {
|
|
55
|
+
this.readyState = this.CLOSED;
|
|
56
|
+
this.onerror?.call(this, ev);
|
|
57
|
+
this.dispatchEvent(ev);
|
|
58
|
+
}
|
|
59
|
+
#callClose(ev) {
|
|
60
|
+
this.readyState = this.CLOSED;
|
|
61
|
+
this.onclose?.call(this, ev);
|
|
62
|
+
this.dispatchEvent(ev);
|
|
63
|
+
}
|
|
64
|
+
#onMessage = (msg) => {
|
|
65
|
+
if (msg.type === 'sendWsMessage' && msg.request.id === this.id) {
|
|
66
|
+
const data = msg.request.data;
|
|
67
|
+
const event = new MessageEvent('message', { data });
|
|
68
|
+
this.onmessage?.call(this, event);
|
|
69
|
+
this.dispatchEvent(event);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (msg.type === 'disconnectWs' && msg.request.id === this.id) {
|
|
73
|
+
if (!msg.request.err) {
|
|
74
|
+
this.#callClose(new CloseEvent('close', { code: 1000, reason: 'Normal Closure' }));
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
this.#callError(new ErrorEvent('error', { error: new Error(msg.request.err) }));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
80
81
|
}
|
|
81
|
-
export {
|
|
82
|
-
RPCWebSocket
|
|
83
|
-
};
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { setCryptoImplementation } from
|
|
2
|
-
import { webcryptoCrypto } from
|
|
3
|
-
import { handleIncomingMessage } from "
|
|
4
|
-
import { getWsApiUrlFromBaseUrl } from "
|
|
1
|
+
import { setCryptoImplementation } from '@reclaimprotocol/tls';
|
|
2
|
+
import { webcryptoCrypto } from '@reclaimprotocol/tls/webcrypto';
|
|
3
|
+
import { handleIncomingMessage } from "./handle-incoming-msg.js";
|
|
4
|
+
import { getWsApiUrlFromBaseUrl } from "./utils.js";
|
|
5
5
|
import { logger, makeLogger } from "../utils/index.js";
|
|
6
6
|
makeLogger(true);
|
|
7
7
|
setCryptoImplementation(webcryptoCrypto);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
8
|
+
/**
|
|
9
|
+
* For browsers only. Sets up the current window to listen for RPC requests
|
|
10
|
+
* from React Native or other windows
|
|
11
|
+
*/
|
|
12
|
+
export function setupWindowRpc(baseUrl, channel = 'attestor-core') {
|
|
13
|
+
if (baseUrl) {
|
|
14
|
+
globalThis.ATTESTOR_BASE_URL = baseUrl;
|
|
15
|
+
}
|
|
16
|
+
else if (typeof window !== 'undefined' && window.location) {
|
|
17
|
+
globalThis.ATTESTOR_BASE_URL = window.location.toString();
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
throw new Error('No base URL provided and window.location unavailable');
|
|
21
|
+
}
|
|
22
|
+
if (channel) {
|
|
23
|
+
globalThis.RPC_CHANNEL_NAME = channel;
|
|
24
|
+
}
|
|
25
|
+
else if (!globalThis.RPC_CHANNEL_NAME) {
|
|
26
|
+
throw new Error('No channel name provided and globalThis.RPC_CHANNEL_NAME unavailable');
|
|
27
|
+
}
|
|
28
|
+
if (typeof window !== 'undefined') {
|
|
29
|
+
window.addEventListener('message', ev => handleIncomingMessage(ev.data), false);
|
|
30
|
+
}
|
|
31
|
+
logger.info({ defaultUrl: getWsApiUrlFromBaseUrl() }, 'window RPC setup');
|
|
29
32
|
}
|
|
30
33
|
export * from "../index.js";
|
|
31
|
-
export {
|
|
32
|
-
setupWindowRpc
|
|
33
|
-
};
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import "
|
|
2
|
-
1;
|
|
3
|
-
import { setCryptoImplementation } from
|
|
4
|
-
import { pureJsCrypto } from
|
|
5
|
-
import * as AttestorRPCImport from "
|
|
1
|
+
import "./jsc-polyfills/index.js";
|
|
2
|
+
1; // done to avoid eslint rule
|
|
3
|
+
import { setCryptoImplementation } from '@reclaimprotocol/tls';
|
|
4
|
+
import { pureJsCrypto } from '@reclaimprotocol/tls/purejs-crypto';
|
|
5
|
+
import * as AttestorRPCImport from "./index.js";
|
|
6
6
|
import { makeLogger } from "../utils/logger.js";
|
|
7
7
|
setCryptoImplementation(pureJsCrypto);
|
|
8
8
|
makeLogger(true);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Sets up the library to run in JS environments like QuickJS or JavascriptCore.
|
|
11
|
+
*/
|
|
12
|
+
export function setupJsRpc(baseUrl, channel = 'attestor-core') {
|
|
13
|
+
globalThis.ATTESTOR_BASE_URL = baseUrl;
|
|
14
|
+
globalThis.RPC_CHANNEL_NAME = channel;
|
|
15
|
+
const rpcChannel = {
|
|
16
|
+
postMessage(message) {
|
|
17
|
+
return globalThis.sendMessage(channel, message);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
globalThis[channel] = rpcChannel;
|
|
18
21
|
}
|
|
19
22
|
globalThis.AttestorRPC = { ...AttestorRPCImport, setupJsRpc };
|
|
20
|
-
export {
|
|
21
|
-
setupJsRpc
|
|
22
|
-
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../..";
|
|
@@ -1,100 +1,100 @@
|
|
|
1
1
|
import { WS_PATHNAME } from "../config/index.js";
|
|
2
|
-
import { EventBus } from "
|
|
2
|
+
import { EventBus } from "./event-bus.js";
|
|
3
3
|
import { B64_JSON_REPLACER } from "../utils/b64-json.js";
|
|
4
4
|
import { AttestorError } from "../utils/error.js";
|
|
5
|
-
const RPC_MSG_BRIDGE = new EventBus();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
5
|
+
export const RPC_MSG_BRIDGE = new EventBus();
|
|
6
|
+
// track memory usage
|
|
7
|
+
export async function getCurrentMemoryUsage() {
|
|
8
|
+
if (!window.crossOriginIsolated) {
|
|
9
|
+
return {
|
|
10
|
+
available: false,
|
|
11
|
+
content: 'N/A (page not cross-origin-isolated)'
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
else if (!performance.measureUserAgentSpecificMemory) {
|
|
15
|
+
return {
|
|
16
|
+
available: false,
|
|
17
|
+
content: 'N/A (performance.measureUserAgentSpecificMemory() is not available)',
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
try {
|
|
22
|
+
const result = performance.measureUserAgentSpecificMemory();
|
|
23
|
+
const totalmb = Math.round(result.bytes / 1024 / 1024);
|
|
24
|
+
return { available: true, content: `${totalmb}mb` };
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (error instanceof DOMException && error.name === 'SecurityError') {
|
|
28
|
+
return { available: false, content: `N/A (${error.message})` };
|
|
29
|
+
}
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
27
32
|
}
|
|
28
|
-
}
|
|
29
33
|
}
|
|
30
|
-
function generateRpcRequestId() {
|
|
31
|
-
|
|
34
|
+
export function generateRpcRequestId() {
|
|
35
|
+
return Math.random().toString(36).slice(2);
|
|
32
36
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
/**
|
|
38
|
+
* The window RPC will be served from the same origin as the API server.
|
|
39
|
+
* so we can get the API server's origin from the location.
|
|
40
|
+
*/
|
|
41
|
+
export function getWsApiUrlFromBaseUrl() {
|
|
42
|
+
if (typeof ATTESTOR_BASE_URL !== 'string') {
|
|
43
|
+
throw new Error('ATTESTOR_BASE_URL is not set');
|
|
44
|
+
}
|
|
45
|
+
const parsed = new URL(ATTESTOR_BASE_URL);
|
|
46
|
+
const { host, protocol } = parsed;
|
|
47
|
+
const wsProtocol = protocol === 'https:' ? 'wss:' : 'ws:';
|
|
48
|
+
return `${wsProtocol}//${host}${WS_PATHNAME}`;
|
|
41
49
|
}
|
|
42
|
-
function rpcRequest(opts) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
export function rpcRequest(opts) {
|
|
51
|
+
const id = generateRpcRequestId();
|
|
52
|
+
const waitForRes = waitForResponse(opts.type, id);
|
|
53
|
+
// @ts-expect-error
|
|
54
|
+
sendMessageToApp({
|
|
55
|
+
id,
|
|
56
|
+
type: opts.type,
|
|
57
|
+
request: opts.request,
|
|
58
|
+
});
|
|
59
|
+
return waitForRes;
|
|
51
60
|
}
|
|
52
|
-
function waitForResponse(type, requestId, timeoutMs =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
clearTimeout(timeout);
|
|
77
|
-
cancel();
|
|
61
|
+
export function waitForResponse(type, requestId, timeoutMs = 60_000) {
|
|
62
|
+
const returnType = `${type}Done`;
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
const timeout = setTimeout(() => {
|
|
65
|
+
reject(new AttestorError('ERROR_INTERNAL', `Timeout waiting for response: ${type}`, { requestId }));
|
|
66
|
+
cancel();
|
|
67
|
+
}, timeoutMs);
|
|
68
|
+
const cancel = RPC_MSG_BRIDGE.addListener(msg => {
|
|
69
|
+
if (msg.id !== requestId) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (msg.type === 'error') {
|
|
73
|
+
reject(new Error(msg.data.message));
|
|
74
|
+
}
|
|
75
|
+
else if (msg.type === returnType) {
|
|
76
|
+
resolve(msg.response);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
clearTimeout(timeout);
|
|
82
|
+
cancel();
|
|
83
|
+
});
|
|
78
84
|
});
|
|
79
|
-
});
|
|
80
85
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Sends a message back to the host app
|
|
88
|
+
* @param data
|
|
89
|
+
*/
|
|
90
|
+
export function sendMessageToApp(data) {
|
|
91
|
+
const str = JSON.stringify(data, B64_JSON_REPLACER);
|
|
92
|
+
if (!RPC_CHANNEL_NAME) {
|
|
93
|
+
throw new Error('global RPC_CHANNEL_NAME is not set');
|
|
94
|
+
}
|
|
95
|
+
const channel = globalThis[RPC_CHANNEL_NAME];
|
|
96
|
+
if (!channel) {
|
|
97
|
+
throw new Error(`RPC channel ${RPC_CHANNEL_NAME} not set on globalThis`);
|
|
98
|
+
}
|
|
99
|
+
channel.postMessage(str);
|
|
91
100
|
}
|
|
92
|
-
export {
|
|
93
|
-
RPC_MSG_BRIDGE,
|
|
94
|
-
generateRpcRequestId,
|
|
95
|
-
getCurrentMemoryUsage,
|
|
96
|
-
getWsApiUrlFromBaseUrl,
|
|
97
|
-
rpcRequest,
|
|
98
|
-
sendMessageToApp,
|
|
99
|
-
waitForResponse
|
|
100
|
-
};
|
package/lib/external-rpc/zk.js
CHANGED
|
@@ -1,58 +1,63 @@
|
|
|
1
|
-
import { rpcRequest } from "
|
|
1
|
+
import { rpcRequest } from "./utils.js";
|
|
2
2
|
import { logger, makeDefaultZkOperator } from "../utils/index.js";
|
|
3
|
-
const ALL_ENC_ALGORITHMS = [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
export const ALL_ENC_ALGORITHMS = [
|
|
4
|
+
'aes-256-ctr',
|
|
5
|
+
'aes-128-ctr',
|
|
6
|
+
'chacha20',
|
|
7
7
|
];
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
/**
|
|
9
|
+
* The goal of this RPC operator is if the attestor client
|
|
10
|
+
* is running in a WebView, it can call the native
|
|
11
|
+
* application to perform the ZK operations
|
|
12
|
+
*/
|
|
13
|
+
export function makeExternalRpcZkOperator(algorithm, zkEngine = 'snarkjs') {
|
|
14
|
+
return {
|
|
15
|
+
async generateWitness(input) {
|
|
16
|
+
const operator = await makeDefaultZkOperator(algorithm, zkEngine, logger);
|
|
17
|
+
return operator.generateWitness(input);
|
|
18
|
+
},
|
|
19
|
+
groth16Prove(input) {
|
|
20
|
+
return callFnZk({ fn: 'groth16Prove', args: [input] });
|
|
21
|
+
},
|
|
22
|
+
groth16Verify(publicSignals, proof) {
|
|
23
|
+
return callFnZk({ fn: 'groth16Verify', args: [publicSignals, proof] });
|
|
24
|
+
},
|
|
25
|
+
};
|
|
21
26
|
}
|
|
22
27
|
function callFnZk(request) {
|
|
23
|
-
|
|
28
|
+
return rpcRequest({ type: 'executeZkFunctionV3', request });
|
|
24
29
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
30
|
+
/**
|
|
31
|
+
* The goal of this RPC operator is if the attestor client
|
|
32
|
+
* is running in a WebView, it can call the native
|
|
33
|
+
* application to perform the OPRF operations
|
|
34
|
+
*/
|
|
35
|
+
export function makeExternalRpcOprfOperator(algorithm, zkEngine = 'snarkjs') {
|
|
36
|
+
return {
|
|
37
|
+
async generateWitness(input) {
|
|
38
|
+
const operator = await makeDefaultZkOperator(algorithm, zkEngine, logger);
|
|
39
|
+
return operator.generateWitness(input);
|
|
40
|
+
},
|
|
41
|
+
groth16Prove(input) {
|
|
42
|
+
return callFnOprf({ fn: 'groth16Prove', args: [input] });
|
|
43
|
+
},
|
|
44
|
+
groth16Verify(publicSignals, proof) {
|
|
45
|
+
return callFnOprf({ fn: 'groth16Verify', args: [publicSignals, proof] });
|
|
46
|
+
},
|
|
47
|
+
generateThresholdKeys(total, threshold) {
|
|
48
|
+
return callFnOprf({ fn: 'generateThresholdKeys', args: [total, threshold] });
|
|
49
|
+
},
|
|
50
|
+
generateOPRFRequestData(data, domainSeparator) {
|
|
51
|
+
return callFnOprf({ fn: 'generateOPRFRequestData', args: [data, domainSeparator] });
|
|
52
|
+
},
|
|
53
|
+
finaliseOPRF(serverPublicKey, request, responses) {
|
|
54
|
+
return callFnOprf({ fn: 'finaliseOPRF', args: [serverPublicKey, request, responses] });
|
|
55
|
+
},
|
|
56
|
+
evaluateOPRF(serverPrivateKey, request) {
|
|
57
|
+
return callFnOprf({ fn: 'evaluateOPRF', args: [serverPrivateKey, request] });
|
|
58
|
+
},
|
|
59
|
+
};
|
|
50
60
|
}
|
|
51
61
|
function callFnOprf(request) {
|
|
52
|
-
|
|
62
|
+
return rpcRequest({ type: 'executeOprfFunctionV3', request });
|
|
53
63
|
}
|
|
54
|
-
export {
|
|
55
|
-
ALL_ENC_ALGORITHMS,
|
|
56
|
-
makeExternalRpcOprfOperator,
|
|
57
|
-
makeExternalRpcZkOperator
|
|
58
|
-
};
|
package/lib/index.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
export * as tls from '@reclaimprotocol/tls';
|
|
2
2
|
export * from "./client/utils/client-socket.js";
|
|
3
3
|
export * from "./config/index.js";
|
|
4
4
|
export * from "./types/index.js";
|
|
5
5
|
export * from "./utils/index.js";
|
|
6
6
|
export * from "./providers/index.js";
|
|
7
|
-
|
|
7
|
+
export * as proto from "./proto/api.js";
|
|
8
8
|
export * from "./client/index.js";
|
|
9
9
|
export * from "./mechain/index.js";
|
|
10
|
-
export {
|
|
11
|
-
proto,
|
|
12
|
-
tls
|
|
13
|
-
};
|