@reclaimprotocol/attestor-core 5.0.1-beta.13 → 5.0.1-beta.16
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/external-rpc/index.js +17321 -3
- package/lib/index.d.ts +1 -0
- package/lib/index.js +15391 -11
- package/lib/scripts/build-browser-debug.d.ts +1 -0
- package/package.json +1 -1
- 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/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/build-browser.js +0 -38
- package/lib/scripts/build-jsc.js +0 -47
- package/lib/scripts/build-lib.js +0 -47
- 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,241 +0,0 @@
|
|
|
1
|
-
import { hexlify } from "ethers";
|
|
2
|
-
import { createClaimOnAvs } from "#src/avs/client/create-claim-on-avs.js";
|
|
3
|
-
import { createClaimOnAttestor } from "#src/client/index.js";
|
|
4
|
-
import { benchmark } from "#src/external-rpc/benchmark.js";
|
|
5
|
-
import { generateRpcRequestId, getCurrentMemoryUsage, getWsApiUrlFromBaseUrl, RPC_MSG_BRIDGE, sendMessageToApp, waitForResponse } from "#src/external-rpc/utils.js";
|
|
6
|
-
import { ALL_ENC_ALGORITHMS, makeExternalRpcOprfOperator, makeExternalRpcZkOperator } from "#src/external-rpc/zk.js";
|
|
7
|
-
import { createClaimOnMechain } from "#src/mechain/client/create-claim-on-mechain.js";
|
|
8
|
-
import { extractHTMLElement, extractJSONValueIndex, generateRequstAndResponseFromTranscript } from "#src/providers/http/utils.js";
|
|
9
|
-
import { B64_JSON_REVIVER } from "#src/utils/b64-json.js";
|
|
10
|
-
import { AttestorError, getIdentifierFromClaimInfo, logger, makeLogger, uint8ArrayToStr } from "#src/utils/index.js";
|
|
11
|
-
async function handleIncomingMessage(data) {
|
|
12
|
-
let id = "";
|
|
13
|
-
try {
|
|
14
|
-
const req = typeof data === "string" ? JSON.parse(data, B64_JSON_REVIVER) : data;
|
|
15
|
-
id = req.id || "";
|
|
16
|
-
const rslt = await _handleIncomingMessage(req);
|
|
17
|
-
if (!rslt) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
respond(rslt);
|
|
21
|
-
} catch (err) {
|
|
22
|
-
console.error("Error in RPC", { id, error: err });
|
|
23
|
-
respond({
|
|
24
|
-
type: "error",
|
|
25
|
-
data: {
|
|
26
|
-
message: err.message,
|
|
27
|
-
stack: err.stack
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
function respond(data2) {
|
|
32
|
-
const res = {
|
|
33
|
-
...data2,
|
|
34
|
-
id,
|
|
35
|
-
isResponse: true
|
|
36
|
-
};
|
|
37
|
-
return sendMessageToApp(res);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
async function _handleIncomingMessage(req) {
|
|
41
|
-
const { id: reqId, type: reqType } = req;
|
|
42
|
-
if (!reqId || !reqType) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
RPC_MSG_BRIDGE.dispatch(req);
|
|
46
|
-
if ("isResponse" in req && req.isResponse) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
if (!reqId) {
|
|
50
|
-
logger.warn({ req }, "Window RPC request missing ID");
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
logger.info({ req }, "processing RPC request");
|
|
54
|
-
switch (req.type) {
|
|
55
|
-
case "createClaim":
|
|
56
|
-
const claimTunnelRes = await createClaimOnAttestor({
|
|
57
|
-
...req.request,
|
|
58
|
-
context: req.request.context ? JSON.parse(req.request.context) : void 0,
|
|
59
|
-
zkOperators: getZkOperators(
|
|
60
|
-
req.request.zkOperatorMode,
|
|
61
|
-
req.request.zkEngine
|
|
62
|
-
),
|
|
63
|
-
oprfOperators: getOprfOperators(
|
|
64
|
-
req.request.zkOperatorMode,
|
|
65
|
-
req.request.zkEngine
|
|
66
|
-
),
|
|
67
|
-
client: {
|
|
68
|
-
url: getWsApiUrlFromBaseUrl(),
|
|
69
|
-
authRequest: req.request.authRequest
|
|
70
|
-
},
|
|
71
|
-
logger,
|
|
72
|
-
onStep(step) {
|
|
73
|
-
sendMessageToApp({
|
|
74
|
-
type: "createClaimStep",
|
|
75
|
-
step: { name: "attestor-progress", step },
|
|
76
|
-
id: req.id
|
|
77
|
-
});
|
|
78
|
-
},
|
|
79
|
-
updateProviderParams: req.request.updateProviderParams ? updateProviderParams : void 0
|
|
80
|
-
});
|
|
81
|
-
const response = mapToCreateClaimResponse(claimTunnelRes);
|
|
82
|
-
return { type: "createClaimDone", response };
|
|
83
|
-
case "createClaimOnAvs":
|
|
84
|
-
const avsRes = await createClaimOnAvs({
|
|
85
|
-
...req.request,
|
|
86
|
-
payer: req.request.payer === "attestor" ? { attestor: getWsApiUrlFromBaseUrl() } : void 0,
|
|
87
|
-
context: req.request.context ? JSON.parse(req.request.context) : void 0,
|
|
88
|
-
zkOperators: getZkOperators(
|
|
89
|
-
req.request.zkOperatorMode,
|
|
90
|
-
req.request.zkEngine
|
|
91
|
-
),
|
|
92
|
-
oprfOperators: getOprfOperators(
|
|
93
|
-
req.request.zkOperatorMode,
|
|
94
|
-
req.request.zkEngine
|
|
95
|
-
),
|
|
96
|
-
logger,
|
|
97
|
-
onStep(step) {
|
|
98
|
-
sendMessageToApp({
|
|
99
|
-
type: "createClaimOnAvsStep",
|
|
100
|
-
step,
|
|
101
|
-
id: req.id
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
return {
|
|
106
|
-
type: "createClaimOnAvsDone",
|
|
107
|
-
response: avsRes
|
|
108
|
-
};
|
|
109
|
-
case "createClaimOnMechain":
|
|
110
|
-
const mechainRes = await createClaimOnMechain({
|
|
111
|
-
...req.request,
|
|
112
|
-
context: req.request.context ? JSON.parse(req.request.context) : void 0,
|
|
113
|
-
zkOperators: getZkOperators(
|
|
114
|
-
req.request.zkOperatorMode,
|
|
115
|
-
req.request.zkEngine
|
|
116
|
-
),
|
|
117
|
-
oprfOperators: getOprfOperators(
|
|
118
|
-
req.request.zkOperatorMode,
|
|
119
|
-
req.request.zkEngine
|
|
120
|
-
),
|
|
121
|
-
client: { url: getWsApiUrlFromBaseUrl() },
|
|
122
|
-
logger,
|
|
123
|
-
onStep(step) {
|
|
124
|
-
sendMessageToApp({
|
|
125
|
-
type: "createClaimOnMechainStep",
|
|
126
|
-
step,
|
|
127
|
-
id: req.id
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
const claimResponses = [];
|
|
132
|
-
for (let i = 0; i < mechainRes.responses.length; i++) {
|
|
133
|
-
claimResponses[i] = mapToCreateClaimResponse(mechainRes.responses[i]);
|
|
134
|
-
}
|
|
135
|
-
return {
|
|
136
|
-
type: "createClaimOnMechainDone",
|
|
137
|
-
response: { taskId: mechainRes.taskId, data: claimResponses }
|
|
138
|
-
};
|
|
139
|
-
case "extractHtmlElement":
|
|
140
|
-
return {
|
|
141
|
-
type: "extractHtmlElementDone",
|
|
142
|
-
response: extractHTMLElement(
|
|
143
|
-
req.request.html,
|
|
144
|
-
req.request.xpathExpression,
|
|
145
|
-
req.request.contentsOnly
|
|
146
|
-
)
|
|
147
|
-
};
|
|
148
|
-
case "extractJSONValueIndex":
|
|
149
|
-
return {
|
|
150
|
-
type: "extractJSONValueIndexDone",
|
|
151
|
-
response: extractJSONValueIndex(
|
|
152
|
-
req.request.json,
|
|
153
|
-
req.request.jsonPath
|
|
154
|
-
)
|
|
155
|
-
};
|
|
156
|
-
case "getCurrentMemoryUsage":
|
|
157
|
-
return {
|
|
158
|
-
type: "getCurrentMemoryUsageDone",
|
|
159
|
-
response: await getCurrentMemoryUsage()
|
|
160
|
-
};
|
|
161
|
-
case "setLogLevel":
|
|
162
|
-
makeLogger(
|
|
163
|
-
true,
|
|
164
|
-
req.request.logLevel,
|
|
165
|
-
req.request.sendLogsToApp ? (level, message) => sendMessageToApp({
|
|
166
|
-
type: "log",
|
|
167
|
-
level,
|
|
168
|
-
message,
|
|
169
|
-
id: req.id
|
|
170
|
-
}) : void 0
|
|
171
|
-
);
|
|
172
|
-
return { type: "setLogLevelDone", response: void 0 };
|
|
173
|
-
case "benchmarkZK":
|
|
174
|
-
return { type: "benchmarkZKDone", response: await benchmark() };
|
|
175
|
-
case "ping":
|
|
176
|
-
return { type: "pingDone", response: { pong: (/* @__PURE__ */ new Date()).toJSON() } };
|
|
177
|
-
default:
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
function getZkOperators(mode = "default", zkEngine = "snarkjs") {
|
|
182
|
-
if (mode === "default") {
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
const operators = {};
|
|
186
|
-
for (const alg of ALL_ENC_ALGORITHMS) {
|
|
187
|
-
operators[alg] = makeExternalRpcZkOperator(alg, zkEngine);
|
|
188
|
-
}
|
|
189
|
-
return operators;
|
|
190
|
-
}
|
|
191
|
-
function getOprfOperators(mode = "default", zkEngine = "snarkjs") {
|
|
192
|
-
if (mode === "default") {
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
const operators = {};
|
|
196
|
-
for (const alg of ALL_ENC_ALGORITHMS) {
|
|
197
|
-
operators[alg] = makeExternalRpcOprfOperator(alg, zkEngine);
|
|
198
|
-
}
|
|
199
|
-
return operators;
|
|
200
|
-
}
|
|
201
|
-
async function updateProviderParams(transcript, tlsVersion) {
|
|
202
|
-
const { req, res } = generateRequstAndResponseFromTranscript(
|
|
203
|
-
transcript,
|
|
204
|
-
tlsVersion
|
|
205
|
-
);
|
|
206
|
-
const id = generateRpcRequestId();
|
|
207
|
-
const waitForRes = waitForResponse("updateProviderParams", id);
|
|
208
|
-
sendMessageToApp({
|
|
209
|
-
type: "updateProviderParams",
|
|
210
|
-
id,
|
|
211
|
-
request: {
|
|
212
|
-
request: {
|
|
213
|
-
...req,
|
|
214
|
-
body: req.body ? uint8ArrayToStr(req.body) : void 0
|
|
215
|
-
},
|
|
216
|
-
response: { ...res, body: uint8ArrayToStr(res.body) }
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
return waitForRes;
|
|
220
|
-
}
|
|
221
|
-
function mapToCreateClaimResponse(res) {
|
|
222
|
-
if (!res.claim) {
|
|
223
|
-
throw AttestorError.fromProto(res.error);
|
|
224
|
-
}
|
|
225
|
-
return {
|
|
226
|
-
identifier: getIdentifierFromClaimInfo(res.claim),
|
|
227
|
-
claimData: res.claim,
|
|
228
|
-
witnesses: [
|
|
229
|
-
{
|
|
230
|
-
id: res.signatures.attestorAddress,
|
|
231
|
-
url: getWsApiUrlFromBaseUrl()
|
|
232
|
-
}
|
|
233
|
-
],
|
|
234
|
-
signatures: [
|
|
235
|
-
hexlify(res.signatures.claimSignature).toLowerCase()
|
|
236
|
-
]
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
export {
|
|
240
|
-
handleIncomingMessage
|
|
241
|
-
};
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { TextDecoder, TextEncoder } from "@kayahr/text-encoding";
|
|
2
|
-
import { crypto, uint8ArrayToBinaryStr } from "@reclaimprotocol/tls";
|
|
3
|
-
import { fromByteArray, toByteArray } from "base64-js";
|
|
4
|
-
import { EventTarget } from "event-target-shim";
|
|
5
|
-
if (typeof global === "undefined") {
|
|
6
|
-
globalThis.global = globalThis;
|
|
7
|
-
}
|
|
8
|
-
if (typeof console === "undefined") {
|
|
9
|
-
globalThis.console = {
|
|
10
|
-
log: print,
|
|
11
|
-
error: print,
|
|
12
|
-
warn: print,
|
|
13
|
-
info: print,
|
|
14
|
-
debug: print
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
if (typeof globalThis.crypto === "undefined") {
|
|
18
|
-
globalThis.crypto = {
|
|
19
|
-
// @ts-expect-error
|
|
20
|
-
getRandomValues(arr) {
|
|
21
|
-
const randVals = crypto.randomBytes(arr.length);
|
|
22
|
-
for (let i = 0; i < arr.length; i++) {
|
|
23
|
-
arr[i] = randVals[i];
|
|
24
|
-
}
|
|
25
|
-
return arr;
|
|
26
|
-
},
|
|
27
|
-
randomBytes(length) {
|
|
28
|
-
return crypto.randomBytes(length);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
if (typeof globalThis.TextEncoder === "undefined") {
|
|
33
|
-
globalThis.TextEncoder = TextEncoder;
|
|
34
|
-
}
|
|
35
|
-
if (typeof globalThis.TextDecoder === "undefined") {
|
|
36
|
-
globalThis.TextDecoder = TextDecoder;
|
|
37
|
-
}
|
|
38
|
-
if (typeof globalThis.EventTarget === "undefined") {
|
|
39
|
-
globalThis.EventTarget = EventTarget;
|
|
40
|
-
}
|
|
41
|
-
if (typeof globalThis.atob === "undefined") {
|
|
42
|
-
globalThis.atob = (a) => uint8ArrayToBinaryStr(toByteArray(a));
|
|
43
|
-
}
|
|
44
|
-
if (typeof globalThis.btoa === "undefined") {
|
|
45
|
-
let binaryStringToUint8Array = function(binaryString) {
|
|
46
|
-
const uint8Array = new Uint8Array(binaryString.length);
|
|
47
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
48
|
-
uint8Array[i] = binaryString.charCodeAt(i);
|
|
49
|
-
}
|
|
50
|
-
return uint8Array;
|
|
51
|
-
};
|
|
52
|
-
globalThis.btoa = (b) => fromByteArray(binaryStringToUint8Array(b));
|
|
53
|
-
}
|
|
54
|
-
if (typeof globalThis.clearTimeout === "undefined") {
|
|
55
|
-
const ogSettimeout = globalThis.setTimeout;
|
|
56
|
-
if (!ogSettimeout) {
|
|
57
|
-
throw new Error("setTimeout is not defined, no polyfill yet");
|
|
58
|
-
}
|
|
59
|
-
globalThis.setTimeout = (fn, delayMs, ...args) => {
|
|
60
|
-
let aborted = false;
|
|
61
|
-
const abortableFn = (...args2) => {
|
|
62
|
-
if (aborted) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
return fn(...args2);
|
|
66
|
-
};
|
|
67
|
-
const val = ogSettimeout(abortableFn, delayMs, ...args);
|
|
68
|
-
return {
|
|
69
|
-
original: val,
|
|
70
|
-
abort() {
|
|
71
|
-
aborted = true;
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
globalThis.clearTimeout = (id) => {
|
|
76
|
-
if (typeof id === "object" && !!id && "abort" in id) {
|
|
77
|
-
id.abort();
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { URL as WHATWG_URL } from "whatwg-url";
|
|
2
|
-
import { CloseEventPolyfill, ErrorEventPolyfill, EventPolyfill, MessageEventPolyfill } from "#src/external-rpc/jsc-polyfills/event.js";
|
|
3
|
-
import { RPCWebSocket } from "#src/external-rpc/jsc-polyfills/ws.js";
|
|
4
|
-
if (typeof globalThis.URL === "undefined") {
|
|
5
|
-
globalThis.URL = WHATWG_URL;
|
|
6
|
-
}
|
|
7
|
-
if (typeof globalThis.Event === "undefined") {
|
|
8
|
-
globalThis.Event = EventPolyfill;
|
|
9
|
-
globalThis.ErrorEvent = ErrorEventPolyfill;
|
|
10
|
-
globalThis.CloseEvent = CloseEventPolyfill;
|
|
11
|
-
globalThis.MessageEvent = MessageEventPolyfill;
|
|
12
|
-
}
|
|
13
|
-
if (typeof globalThis.WebSocket === "undefined") {
|
|
14
|
-
globalThis.WebSocket = RPCWebSocket;
|
|
15
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
class EventPolyfill {
|
|
2
|
-
type;
|
|
3
|
-
constructor(type, eventInitDict) {
|
|
4
|
-
this.type = type;
|
|
5
|
-
Object.assign(this, eventInitDict);
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
class ErrorEventPolyfill extends EventPolyfill {
|
|
9
|
-
}
|
|
10
|
-
class CloseEventPolyfill extends EventPolyfill {
|
|
11
|
-
}
|
|
12
|
-
class MessageEventPolyfill extends EventPolyfill {
|
|
13
|
-
}
|
|
14
|
-
export {
|
|
15
|
-
CloseEventPolyfill,
|
|
16
|
-
ErrorEventPolyfill,
|
|
17
|
-
EventPolyfill,
|
|
18
|
-
MessageEventPolyfill
|
|
19
|
-
};
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { RPC_MSG_BRIDGE, rpcRequest } from "#src/external-rpc/utils.js";
|
|
2
|
-
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
|
-
}).then(() => this.#callOpen(new Event("open"))).catch((error) => this.#callError(new ErrorEvent("error", { error })));
|
|
28
|
-
}
|
|
29
|
-
send(data) {
|
|
30
|
-
if (typeof data !== "string" && !ArrayBuffer.isView(data)) {
|
|
31
|
-
throw new TypeError("Data must be a string, Uint8Array or ArrayBuffer");
|
|
32
|
-
}
|
|
33
|
-
rpcRequest({ type: "sendWsMessage", request: { id: this.id, data } });
|
|
34
|
-
}
|
|
35
|
-
close(code, reason) {
|
|
36
|
-
this.readyState = this.CLOSING;
|
|
37
|
-
rpcRequest({
|
|
38
|
-
type: "disconnectWs",
|
|
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;
|
|
66
|
-
}
|
|
67
|
-
if (msg.type === "disconnectWs" && msg.request.id === this.id) {
|
|
68
|
-
if (!msg.request.err) {
|
|
69
|
-
this.#callClose(
|
|
70
|
-
new CloseEvent("close", { code: 1e3, reason: "Normal Closure" })
|
|
71
|
-
);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
this.#callError(
|
|
75
|
-
new ErrorEvent("error", { error: new Error(msg.request.err) })
|
|
76
|
-
);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
export {
|
|
82
|
-
RPCWebSocket
|
|
83
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { setCryptoImplementation } from "@reclaimprotocol/tls";
|
|
2
|
-
import { webcryptoCrypto } from "@reclaimprotocol/tls/webcrypto";
|
|
3
|
-
import { handleIncomingMessage } from "#src/external-rpc/handle-incoming-msg.js";
|
|
4
|
-
import { getWsApiUrlFromBaseUrl } from "#src/external-rpc/utils.js";
|
|
5
|
-
import { logger, makeLogger } from "#src/utils/index.js";
|
|
6
|
-
makeLogger(true);
|
|
7
|
-
setCryptoImplementation(webcryptoCrypto);
|
|
8
|
-
function setupWindowRpc(baseUrl, channel = "attestor-core") {
|
|
9
|
-
if (baseUrl) {
|
|
10
|
-
globalThis.ATTESTOR_BASE_URL = baseUrl;
|
|
11
|
-
} else if (typeof window !== "undefined" && window.location) {
|
|
12
|
-
globalThis.ATTESTOR_BASE_URL = window.location.toString();
|
|
13
|
-
} else {
|
|
14
|
-
throw new Error("No base URL provided and window.location unavailable");
|
|
15
|
-
}
|
|
16
|
-
if (channel) {
|
|
17
|
-
globalThis.RPC_CHANNEL_NAME = channel;
|
|
18
|
-
} else if (!globalThis.RPC_CHANNEL_NAME) {
|
|
19
|
-
throw new Error("No channel name provided and globalThis.RPC_CHANNEL_NAME unavailable");
|
|
20
|
-
}
|
|
21
|
-
if (typeof window !== "undefined") {
|
|
22
|
-
window.addEventListener(
|
|
23
|
-
"message",
|
|
24
|
-
(ev) => handleIncomingMessage(ev.data),
|
|
25
|
-
false
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
logger.info({ defaultUrl: getWsApiUrlFromBaseUrl() }, "window RPC setup");
|
|
29
|
-
}
|
|
30
|
-
export * from "#src/index.js";
|
|
31
|
-
export {
|
|
32
|
-
setupWindowRpc
|
|
33
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import "#src/external-rpc/jsc-polyfills/index.js";
|
|
2
|
-
1;
|
|
3
|
-
import { setCryptoImplementation } from "@reclaimprotocol/tls";
|
|
4
|
-
import { pureJsCrypto } from "@reclaimprotocol/tls/purejs-crypto";
|
|
5
|
-
import * as AttestorRPCImport from "#src/external-rpc/index.js";
|
|
6
|
-
import { makeLogger } from "#src/utils/logger.js";
|
|
7
|
-
setCryptoImplementation(pureJsCrypto);
|
|
8
|
-
makeLogger(true);
|
|
9
|
-
function setupJsRpc(baseUrl, channel = "attestor-core") {
|
|
10
|
-
globalThis.ATTESTOR_BASE_URL = baseUrl;
|
|
11
|
-
globalThis.RPC_CHANNEL_NAME = channel;
|
|
12
|
-
const rpcChannel = {
|
|
13
|
-
postMessage(message) {
|
|
14
|
-
return globalThis.sendMessage(channel, message);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
globalThis[channel] = rpcChannel;
|
|
18
|
-
}
|
|
19
|
-
globalThis.AttestorRPC = { ...AttestorRPCImport, setupJsRpc };
|
|
20
|
-
export {
|
|
21
|
-
setupJsRpc
|
|
22
|
-
};
|
|
File without changes
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { WS_PATHNAME } from "#src/config/index.js";
|
|
2
|
-
import { EventBus } from "#src/external-rpc/event-bus.js";
|
|
3
|
-
import { B64_JSON_REPLACER } from "#src/utils/b64-json.js";
|
|
4
|
-
import { AttestorError } from "#src/utils/error.js";
|
|
5
|
-
const RPC_MSG_BRIDGE = new EventBus();
|
|
6
|
-
async function getCurrentMemoryUsage() {
|
|
7
|
-
if (!window.crossOriginIsolated) {
|
|
8
|
-
return {
|
|
9
|
-
available: false,
|
|
10
|
-
content: "N/A (page not cross-origin-isolated)"
|
|
11
|
-
};
|
|
12
|
-
} else if (!performance.measureUserAgentSpecificMemory) {
|
|
13
|
-
return {
|
|
14
|
-
available: false,
|
|
15
|
-
content: "N/A (performance.measureUserAgentSpecificMemory() is not available)"
|
|
16
|
-
};
|
|
17
|
-
} else {
|
|
18
|
-
try {
|
|
19
|
-
const result = performance.measureUserAgentSpecificMemory();
|
|
20
|
-
const totalmb = Math.round(result.bytes / 1024 / 1024);
|
|
21
|
-
return { available: true, content: `${totalmb}mb` };
|
|
22
|
-
} catch (error) {
|
|
23
|
-
if (error instanceof DOMException && error.name === "SecurityError") {
|
|
24
|
-
return { available: false, content: `N/A (${error.message})` };
|
|
25
|
-
}
|
|
26
|
-
throw error;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function generateRpcRequestId() {
|
|
31
|
-
return Math.random().toString(36).slice(2);
|
|
32
|
-
}
|
|
33
|
-
function getWsApiUrlFromBaseUrl() {
|
|
34
|
-
if (typeof ATTESTOR_BASE_URL !== "string") {
|
|
35
|
-
throw new Error("ATTESTOR_BASE_URL is not set");
|
|
36
|
-
}
|
|
37
|
-
const parsed = new URL(ATTESTOR_BASE_URL);
|
|
38
|
-
const { host, protocol } = parsed;
|
|
39
|
-
const wsProtocol = protocol === "https:" ? "wss:" : "ws:";
|
|
40
|
-
return `${wsProtocol}//${host}${WS_PATHNAME}`;
|
|
41
|
-
}
|
|
42
|
-
function rpcRequest(opts) {
|
|
43
|
-
const id = generateRpcRequestId();
|
|
44
|
-
const waitForRes = waitForResponse(opts.type, id);
|
|
45
|
-
sendMessageToApp({
|
|
46
|
-
id,
|
|
47
|
-
type: opts.type,
|
|
48
|
-
request: opts.request
|
|
49
|
-
});
|
|
50
|
-
return waitForRes;
|
|
51
|
-
}
|
|
52
|
-
function waitForResponse(type, requestId, timeoutMs = 6e4) {
|
|
53
|
-
const returnType = `${type}Done`;
|
|
54
|
-
return new Promise((resolve, reject) => {
|
|
55
|
-
const timeout = setTimeout(() => {
|
|
56
|
-
reject(
|
|
57
|
-
new AttestorError(
|
|
58
|
-
"ERROR_INTERNAL",
|
|
59
|
-
`Timeout waiting for response: ${type}`,
|
|
60
|
-
{ requestId }
|
|
61
|
-
)
|
|
62
|
-
);
|
|
63
|
-
cancel();
|
|
64
|
-
}, timeoutMs);
|
|
65
|
-
const cancel = RPC_MSG_BRIDGE.addListener((msg) => {
|
|
66
|
-
if (msg.id !== requestId) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
if (msg.type === "error") {
|
|
70
|
-
reject(new Error(msg.data.message));
|
|
71
|
-
} else if (msg.type === returnType) {
|
|
72
|
-
resolve(msg.response);
|
|
73
|
-
} else {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
clearTimeout(timeout);
|
|
77
|
-
cancel();
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
function sendMessageToApp(data) {
|
|
82
|
-
const str = JSON.stringify(data, B64_JSON_REPLACER);
|
|
83
|
-
if (!RPC_CHANNEL_NAME) {
|
|
84
|
-
throw new Error("global RPC_CHANNEL_NAME is not set");
|
|
85
|
-
}
|
|
86
|
-
const channel = globalThis[RPC_CHANNEL_NAME];
|
|
87
|
-
if (!channel) {
|
|
88
|
-
throw new Error(`RPC channel ${RPC_CHANNEL_NAME} not set on globalThis`);
|
|
89
|
-
}
|
|
90
|
-
channel.postMessage(str);
|
|
91
|
-
}
|
|
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
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { rpcRequest } from "#src/external-rpc/utils.js";
|
|
2
|
-
import { logger, makeDefaultZkOperator } from "#src/utils/index.js";
|
|
3
|
-
const ALL_ENC_ALGORITHMS = [
|
|
4
|
-
"aes-256-ctr",
|
|
5
|
-
"aes-128-ctr",
|
|
6
|
-
"chacha20"
|
|
7
|
-
];
|
|
8
|
-
function makeExternalRpcZkOperator(algorithm, zkEngine = "snarkjs") {
|
|
9
|
-
return {
|
|
10
|
-
async generateWitness(input) {
|
|
11
|
-
const operator = await makeDefaultZkOperator(algorithm, zkEngine, logger);
|
|
12
|
-
return operator.generateWitness(input);
|
|
13
|
-
},
|
|
14
|
-
groth16Prove(input) {
|
|
15
|
-
return callFnZk({ fn: "groth16Prove", args: [input] });
|
|
16
|
-
},
|
|
17
|
-
groth16Verify(publicSignals, proof) {
|
|
18
|
-
return callFnZk({ fn: "groth16Verify", args: [publicSignals, proof] });
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function callFnZk(request) {
|
|
23
|
-
return rpcRequest({ type: "executeZkFunctionV3", request });
|
|
24
|
-
}
|
|
25
|
-
function makeExternalRpcOprfOperator(algorithm, zkEngine = "snarkjs") {
|
|
26
|
-
return {
|
|
27
|
-
async generateWitness(input) {
|
|
28
|
-
const operator = await makeDefaultZkOperator(algorithm, zkEngine, logger);
|
|
29
|
-
return operator.generateWitness(input);
|
|
30
|
-
},
|
|
31
|
-
groth16Prove(input) {
|
|
32
|
-
return callFnOprf({ fn: "groth16Prove", args: [input] });
|
|
33
|
-
},
|
|
34
|
-
groth16Verify(publicSignals, proof) {
|
|
35
|
-
return callFnOprf({ fn: "groth16Verify", args: [publicSignals, proof] });
|
|
36
|
-
},
|
|
37
|
-
generateThresholdKeys(total, threshold) {
|
|
38
|
-
return callFnOprf({ fn: "generateThresholdKeys", args: [total, threshold] });
|
|
39
|
-
},
|
|
40
|
-
generateOPRFRequestData(data, domainSeparator) {
|
|
41
|
-
return callFnOprf({ fn: "generateOPRFRequestData", args: [data, domainSeparator] });
|
|
42
|
-
},
|
|
43
|
-
finaliseOPRF(serverPublicKey, request, responses) {
|
|
44
|
-
return callFnOprf({ fn: "finaliseOPRF", args: [serverPublicKey, request, responses] });
|
|
45
|
-
},
|
|
46
|
-
evaluateOPRF(serverPrivateKey, request) {
|
|
47
|
-
return callFnOprf({ fn: "evaluateOPRF", args: [serverPrivateKey, request] });
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
function callFnOprf(request) {
|
|
52
|
-
return rpcRequest({ type: "executeOprfFunctionV3", request });
|
|
53
|
-
}
|
|
54
|
-
export {
|
|
55
|
-
ALL_ENC_ALGORITHMS,
|
|
56
|
-
makeExternalRpcOprfOperator,
|
|
57
|
-
makeExternalRpcZkOperator
|
|
58
|
-
};
|