@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
package/lib/types/bgp.js
DELETED
|
File without changes
|
package/lib/types/claims.js
DELETED
|
File without changes
|
package/lib/types/client.js
DELETED
|
File without changes
|
package/lib/types/general.js
DELETED
|
File without changes
|
package/lib/types/handlers.js
DELETED
|
File without changes
|
package/lib/types/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from "./providers.js";
|
|
2
|
-
export * from "./general.js";
|
|
3
|
-
export * from "./signatures.js";
|
|
4
|
-
export * from "./claims.js";
|
|
5
|
-
export * from "./zk.js";
|
|
6
|
-
export * from "./client.js";
|
|
7
|
-
export * from "./rpc.js";
|
|
8
|
-
export * from "./tunnel.js";
|
|
9
|
-
export * from "./handlers.js";
|
|
10
|
-
export * from "./bgp.js";
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
const HttpProviderParametersJson = { "title": "HttpProviderParameters", "type": "object", "required": ["url", "method", "responseMatches"], "properties": { "url": { "type": "string", "format": "url", "description": "which URL does the request have to be made to Has to be a valid https URL for eg. https://amazon.in/orders?q=abcd" }, "method": { "type": "string", "enum": ["GET", "POST", "PUT", "PATCH"] }, "geoLocation": { "type": "string", "nullable": true, "description": "Specify the geographical location from where to proxy the request. 2-letter ISO country code or parameter (public or secret)" }, "proxySessionId": { "type": "string", "nullable": true, "description": 'Specify the unique session id for allowing use of same proxy ip across multiple requests. Can be a smallcase alphanumeric string of length 8-14 characters. eg. "mystring12345", "something1234".' }, "headers": { "type": "object", "description": "Any additional headers to be sent with the request Note: these will be revealed to the attestor & won't be redacted from the transcript. To add hidden headers, use 'secretParams.headers' instead", "additionalProperties": { "type": "string" } }, "body": { "description": "Body of the HTTP request", "oneOf": [{ "type": "string", "format": "binary" }, { "type": "string" }] }, "writeRedactionMode": { "type": "string", "description": `If the API doesn't perform well with the "key-update" method of redaction, you can switch to "zk" mode by setting this to "zk"`, "enum": ["zk", "key-update"] }, "additionalClientOptions": { "type": "object", "description": "Apply TLS configuration when creating the tunnel to the attestor.", "nullable": true, "properties": { "supportedProtocolVersions": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "enum": ["TLS1_2", "TLS1_3"] } } } }, "responseMatches": { "type": "array", "minItems": 1, "uniqueItems": true, "description": "The attestor will use this list to check that the redacted response does indeed match all the provided strings/regexes", "items": { "type": "object", "required": ["value", "type"], "properties": { "value": { "type": "string", "description": '"regex": the response must match the regex "contains": the response must contain the provided\n string exactly' }, "type": { "type": "string", "description": "The string/regex to match against", "enum": ["regex", "contains"] }, "invert": { "type": "boolean", "description": "Inverses the matching logic. Fail when match is found and proceed otherwise" } }, "additionalProperties": false } }, "responseRedactions": { "type": "array", "uniqueItems": true, "description": 'which portions to select from a response. These are selected in order, xpath => jsonPath => regex * These redactions are done client side and only the selected portions are sent to the attestor. The attestor will only be able to see the selected portions alongside the first line of the HTTP response (i.e. "HTTP/1.1 200 OK") * To disable any redactions, pass an empty array', "items": { "type": "object", "properties": { "xPath": { "type": "string", "nullable": true, "description": 'expect an HTML response, and to contain a certain xpath for eg. "/html/body/div.a1/div.a2/span.a5"' }, "jsonPath": { "type": "string", "nullable": true, "description": "expect a JSON response, retrieve the item at this path using dot notation for e.g. 'email.addresses.0'" }, "regex": { "type": "string", "nullable": true, "description": "select a regex match from the response" }, "hash": { "type": "string", "description": `If provided, the value inside will be hashed instead of being redacted. Useful for cases where the data inside is an identifiying piece of information that you don't want to reveal to the attestor, eg. an email address.
|
|
2
|
-
If the hash function produces more bytes than the original value, the hash will be truncated.
|
|
3
|
-
Eg. if hash is enabled, the original value is "hello", and hashed is "a1b2c", then the attestor will only see "a1b2c".
|
|
4
|
-
Note: if a regex with named groups is provided, only the named groups will be hashed.`, "enum": ["oprf", "oprf-mpc", "oprf-raw"] } }, "additionalProperties": false } }, "paramValues": { "type": "object", "description": "A map of parameter values which are user in form of {{param}} in URL, responseMatches, responseRedactions, body, geolocation. Those in URL, responseMatches & geo will be put into context and signed This value will NOT be included in provider hash", "additionalProperties": { "type": "string" } } }, "additionalProperties": false };
|
|
5
|
-
const HttpProviderSecretParametersJson = { "title": "HttpProviderSecretParameters", "type": "object", "description": "Secret parameters to be used with HTTP provider. None of the values in this object will be shown to the attestor", "properties": { "cookieStr": { "type": "string", "description": "cookie string for authorisation." }, "authorisationHeader": { "type": "string", "description": "authorisation header value" }, "headers": { "type": "object", "description": "Headers that need to be hidden from the attestor", "additionalProperties": { "type": "string" } }, "paramValues": { "type": "object", "description": "A map of parameter values which are user in form of {{param}} in body these parameters will NOT be shown to attestor and extracted", "additionalProperties": { "type": "string" } } }, "additionalProperties": false };
|
|
6
|
-
const PROVIDER_SCHEMAS = {
|
|
7
|
-
http: {
|
|
8
|
-
parameters: HttpProviderParametersJson,
|
|
9
|
-
secretParameters: HttpProviderSecretParametersJson
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
export {
|
|
13
|
-
HttpProviderParametersJson,
|
|
14
|
-
HttpProviderSecretParametersJson,
|
|
15
|
-
PROVIDER_SCHEMAS
|
|
16
|
-
};
|
package/lib/types/providers.js
DELETED
|
File without changes
|
package/lib/types/rpc.js
DELETED
|
File without changes
|
package/lib/types/signatures.js
DELETED
|
File without changes
|
package/lib/types/tunnel.js
DELETED
|
File without changes
|
package/lib/types/zk.js
DELETED
|
File without changes
|
package/lib/utils/auth.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { getBytes } from "ethers";
|
|
2
|
-
import { DEFAULT_AUTH_EXPIRY_S } from "#src/config/index.js";
|
|
3
|
-
import { AuthenticatedUserData } from "#src/proto/api.js";
|
|
4
|
-
import { getEnvVariable } from "#src/utils/env.js";
|
|
5
|
-
import { AttestorError } from "#src/utils/error.js";
|
|
6
|
-
import { unixTimestampSeconds } from "#src/utils/generics.js";
|
|
7
|
-
import { SelectedServiceSignature, SIGNATURES } from "#src/utils/signatures/index.js";
|
|
8
|
-
async function assertValidAuthRequest(request, signatureType) {
|
|
9
|
-
const publicKey = getEnvVariable("AUTHENTICATION_PUBLIC_KEY");
|
|
10
|
-
if (!request) {
|
|
11
|
-
if (publicKey) {
|
|
12
|
-
throw new AttestorError(
|
|
13
|
-
"ERROR_AUTHENTICATION_FAILED",
|
|
14
|
-
"User must be authenticated"
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
if (!publicKey) {
|
|
20
|
-
throw new AttestorError(
|
|
21
|
-
"ERROR_BAD_REQUEST",
|
|
22
|
-
"The attestor is not configured for authentication"
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
const { signature, data } = request;
|
|
26
|
-
if (!data) {
|
|
27
|
-
throw new AttestorError(
|
|
28
|
-
"ERROR_AUTHENTICATION_FAILED",
|
|
29
|
-
"Missing data in auth request"
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
if (data.expiresAt < unixTimestampSeconds()) {
|
|
33
|
-
throw new AttestorError(
|
|
34
|
-
"ERROR_AUTHENTICATION_FAILED",
|
|
35
|
-
"Authentication request has expired"
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
const proto = AuthenticatedUserData.encode(data).finish();
|
|
39
|
-
const signatureAlg = SIGNATURES[signatureType];
|
|
40
|
-
const address = signatureAlg.getAddress(
|
|
41
|
-
getBytes(publicKey)
|
|
42
|
-
);
|
|
43
|
-
const verified = await signatureAlg.verify(proto, signature, address);
|
|
44
|
-
if (!verified) {
|
|
45
|
-
throw new AttestorError(
|
|
46
|
-
"ERROR_AUTHENTICATION_FAILED",
|
|
47
|
-
"Signature verification failed"
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
async function createAuthRequest(_data, privateKey) {
|
|
52
|
-
const createdAt = unixTimestampSeconds();
|
|
53
|
-
const data = {
|
|
54
|
-
createdAt,
|
|
55
|
-
expiresAt: createdAt + DEFAULT_AUTH_EXPIRY_S,
|
|
56
|
-
id: "",
|
|
57
|
-
hostWhitelist: [],
|
|
58
|
-
..._data
|
|
59
|
-
};
|
|
60
|
-
const proto = AuthenticatedUserData.encode(data).finish();
|
|
61
|
-
const signature = await SelectedServiceSignature.sign(proto, privateKey);
|
|
62
|
-
const request = {
|
|
63
|
-
data,
|
|
64
|
-
signature
|
|
65
|
-
};
|
|
66
|
-
return request;
|
|
67
|
-
}
|
|
68
|
-
export {
|
|
69
|
-
assertValidAuthRequest,
|
|
70
|
-
createAuthRequest
|
|
71
|
-
};
|
package/lib/utils/b64-json.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { decodeBase64, encodeBase64 } from "ethers";
|
|
2
|
-
const B64_JSON_REPLACER = (key, value) => {
|
|
3
|
-
if (value instanceof Uint8Array || typeof value === "object" && value && "buffer" in value && value.buffer instanceof ArrayBuffer) {
|
|
4
|
-
return { type: "uint8array", value: encodeBase64(value) };
|
|
5
|
-
}
|
|
6
|
-
return value;
|
|
7
|
-
};
|
|
8
|
-
const B64_JSON_REVIVER = (key, value) => {
|
|
9
|
-
if (value?.type === "uint8array") {
|
|
10
|
-
return decodeBase64(value.value);
|
|
11
|
-
}
|
|
12
|
-
return value;
|
|
13
|
-
};
|
|
14
|
-
export {
|
|
15
|
-
B64_JSON_REPLACER,
|
|
16
|
-
B64_JSON_REVIVER
|
|
17
|
-
};
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import CIDR from "ip-cidr";
|
|
2
|
-
import { BGP_WS_URL } from "#src/config/index.js";
|
|
3
|
-
import { makeWebSocket } from "#src/utils/ws.js";
|
|
4
|
-
const ANNOUNCEMENT_OVERLAP = "announcement-overlap";
|
|
5
|
-
class BGPAnnouncementOverlapEvent extends Event {
|
|
6
|
-
data;
|
|
7
|
-
constructor(data) {
|
|
8
|
-
super(ANNOUNCEMENT_OVERLAP);
|
|
9
|
-
this.data = data;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
function createBgpListener(logger) {
|
|
13
|
-
let ws;
|
|
14
|
-
let closed = false;
|
|
15
|
-
const targetIps = /* @__PURE__ */ new Set();
|
|
16
|
-
const eventTarget = new EventTarget();
|
|
17
|
-
openWs();
|
|
18
|
-
return {
|
|
19
|
-
onOverlap(ips, callback) {
|
|
20
|
-
for (const ip of ips) {
|
|
21
|
-
targetIps.add(ip);
|
|
22
|
-
}
|
|
23
|
-
eventTarget.addEventListener(
|
|
24
|
-
ANNOUNCEMENT_OVERLAP,
|
|
25
|
-
_callback
|
|
26
|
-
);
|
|
27
|
-
return () => {
|
|
28
|
-
for (const ip of ips) {
|
|
29
|
-
targetIps.delete(ip);
|
|
30
|
-
}
|
|
31
|
-
eventTarget.removeEventListener(
|
|
32
|
-
ANNOUNCEMENT_OVERLAP,
|
|
33
|
-
_callback
|
|
34
|
-
);
|
|
35
|
-
};
|
|
36
|
-
function _callback(event) {
|
|
37
|
-
callback(event.data);
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
close() {
|
|
41
|
-
ws.onclose = null;
|
|
42
|
-
ws.onerror = null;
|
|
43
|
-
ws.close();
|
|
44
|
-
closed = true;
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
function openWs() {
|
|
48
|
-
logger.debug("connecting to BGP websocket");
|
|
49
|
-
ws = makeWebSocket(BGP_WS_URL);
|
|
50
|
-
ws.onopen = onOpen;
|
|
51
|
-
ws.onerror = (ev) => onClose(ev);
|
|
52
|
-
ws.onclose = () => onClose(new Error("Unexpected close"));
|
|
53
|
-
ws.onmessage = ({ data }) => {
|
|
54
|
-
const str = typeof data === "string" ? data : data.toString();
|
|
55
|
-
try {
|
|
56
|
-
onMessage(str);
|
|
57
|
-
} catch (err) {
|
|
58
|
-
logger.error({ data, err }, "error processing BGP message");
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
function onOpen() {
|
|
63
|
-
const subscriptionMessage = {
|
|
64
|
-
type: "ris_subscribe",
|
|
65
|
-
data: {
|
|
66
|
-
type: "UPDATE"
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
ws.send(JSON.stringify(subscriptionMessage));
|
|
70
|
-
logger.info("connected to BGP websocket");
|
|
71
|
-
}
|
|
72
|
-
function onClose(err) {
|
|
73
|
-
if (closed) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
logger.info({ err }, "BGP websocket closed");
|
|
77
|
-
if (!err) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
logger.info("reconnecting to BGP websocket");
|
|
81
|
-
openWs();
|
|
82
|
-
}
|
|
83
|
-
function onMessage(message) {
|
|
84
|
-
const data = JSON.parse(message);
|
|
85
|
-
const announcements = data?.data?.announcements;
|
|
86
|
-
logger.trace({ data }, "got BGP update");
|
|
87
|
-
if (!Array.isArray(announcements)) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
const asPath = data?.data?.path;
|
|
91
|
-
for (const announcement of announcements) {
|
|
92
|
-
const prefixes = announcement?.prefixes;
|
|
93
|
-
const nextHop = announcement?.["next_hop"];
|
|
94
|
-
const hasPrefixes = prefixes?.length && (nextHop || asPath);
|
|
95
|
-
if (!hasPrefixes) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
for (const prefix of prefixes) {
|
|
99
|
-
if (!overlapsTargetIps(prefix)) {
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
eventTarget.dispatchEvent(
|
|
103
|
-
new BGPAnnouncementOverlapEvent({ prefix })
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
function overlapsTargetIps(prefix) {
|
|
109
|
-
if (prefix.endsWith("/0")) {
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
const cidr = new CIDR(prefix);
|
|
113
|
-
for (const ip of targetIps) {
|
|
114
|
-
if (cidr.contains(ip)) {
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
export {
|
|
122
|
-
createBgpListener
|
|
123
|
-
};
|
package/lib/utils/claims.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import canonicalize from "canonicalize";
|
|
2
|
-
import { keccak256 } from "ethers";
|
|
3
|
-
import { DEFAULT_METADATA } from "#src/config/index.js";
|
|
4
|
-
import { ClaimTunnelResponse } from "#src/proto/api.js";
|
|
5
|
-
import { SIGNATURES, strToUint8Array } from "#src/utils/index.js";
|
|
6
|
-
function createSignDataForClaim(data) {
|
|
7
|
-
const lines = [
|
|
8
|
-
getIdentifierFromClaimInfo(data),
|
|
9
|
-
// we lowercase the owner to ensure that the
|
|
10
|
-
// ETH addresses always serialize the same way
|
|
11
|
-
data.owner.toLowerCase(),
|
|
12
|
-
data.timestampS.toString(),
|
|
13
|
-
data.epoch.toString()
|
|
14
|
-
];
|
|
15
|
-
return lines.join("\n");
|
|
16
|
-
}
|
|
17
|
-
async function assertValidClaimSignatures({
|
|
18
|
-
signatures,
|
|
19
|
-
...res
|
|
20
|
-
}, metadata = DEFAULT_METADATA) {
|
|
21
|
-
if (!signatures) {
|
|
22
|
-
throw new Error("No signatures provided");
|
|
23
|
-
}
|
|
24
|
-
const {
|
|
25
|
-
resultSignature,
|
|
26
|
-
claimSignature,
|
|
27
|
-
attestorAddress
|
|
28
|
-
} = signatures;
|
|
29
|
-
const { verify } = SIGNATURES[metadata.signatureType];
|
|
30
|
-
if (signatures?.resultSignature) {
|
|
31
|
-
const resBytes = ClaimTunnelResponse.encode(ClaimTunnelResponse.create(res)).finish();
|
|
32
|
-
const verified = await verify(resBytes, resultSignature, attestorAddress);
|
|
33
|
-
if (!verified) {
|
|
34
|
-
throw new Error("Invalid result signature");
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
if (!res.claim) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const signData = createSignDataForClaim(res.claim);
|
|
41
|
-
const verifiedClaim = await verify(
|
|
42
|
-
strToUint8Array(signData),
|
|
43
|
-
claimSignature,
|
|
44
|
-
attestorAddress
|
|
45
|
-
);
|
|
46
|
-
if (!verifiedClaim) {
|
|
47
|
-
throw new Error("Invalid claim signature");
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
function getIdentifierFromClaimInfo(info) {
|
|
51
|
-
if (info.context?.length > 0) {
|
|
52
|
-
try {
|
|
53
|
-
const ctx = JSON.parse(info.context);
|
|
54
|
-
info.context = canonicalStringify(ctx);
|
|
55
|
-
} catch {
|
|
56
|
-
throw new Error("unable to parse non-empty context. Must be JSON");
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
const str = `${info.provider}
|
|
60
|
-
${info.parameters}
|
|
61
|
-
${info.context || ""}`;
|
|
62
|
-
return keccak256(strToUint8Array(str)).toLowerCase();
|
|
63
|
-
}
|
|
64
|
-
function canonicalStringify(params) {
|
|
65
|
-
if (!params) {
|
|
66
|
-
return "";
|
|
67
|
-
}
|
|
68
|
-
return canonicalize(params) || "";
|
|
69
|
-
}
|
|
70
|
-
function hashProviderParams(params) {
|
|
71
|
-
const filteredParams = {
|
|
72
|
-
url: params.url,
|
|
73
|
-
method: params.method,
|
|
74
|
-
body: params.body,
|
|
75
|
-
responseMatches: params.responseMatches,
|
|
76
|
-
responseRedactions: params.responseRedactions
|
|
77
|
-
};
|
|
78
|
-
const serializedParams = canonicalStringify(filteredParams);
|
|
79
|
-
return keccak256(
|
|
80
|
-
strToUint8Array(serializedParams)
|
|
81
|
-
).toLowerCase();
|
|
82
|
-
}
|
|
83
|
-
export {
|
|
84
|
-
assertValidClaimSignatures,
|
|
85
|
-
canonicalStringify,
|
|
86
|
-
createSignDataForClaim,
|
|
87
|
-
getIdentifierFromClaimInfo,
|
|
88
|
-
hashProviderParams
|
|
89
|
-
};
|
package/lib/utils/env.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
function detectEnvironment() {
|
|
2
|
-
if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
|
|
3
|
-
return "react-native";
|
|
4
|
-
}
|
|
5
|
-
if (typeof window !== "undefined") {
|
|
6
|
-
return "browser";
|
|
7
|
-
}
|
|
8
|
-
return "node";
|
|
9
|
-
}
|
|
10
|
-
function getEnvVariable(name) {
|
|
11
|
-
if (typeof process === "undefined") {
|
|
12
|
-
return void 0;
|
|
13
|
-
}
|
|
14
|
-
return process?.env[name];
|
|
15
|
-
}
|
|
16
|
-
export {
|
|
17
|
-
detectEnvironment,
|
|
18
|
-
getEnvVariable
|
|
19
|
-
};
|
package/lib/utils/error.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { ErrorCode, ErrorData } from "#src/proto/api.js";
|
|
2
|
-
const PROTO_ERROR = ErrorData.fromJSON({});
|
|
3
|
-
class AttestorError extends Error {
|
|
4
|
-
name = "AttestorError";
|
|
5
|
-
code;
|
|
6
|
-
data;
|
|
7
|
-
constructor(code, message, data) {
|
|
8
|
-
super(message);
|
|
9
|
-
this.code = code;
|
|
10
|
-
this.data = data;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Encodes the error as a ErrorData
|
|
14
|
-
* protobuf message
|
|
15
|
-
*/
|
|
16
|
-
toProto() {
|
|
17
|
-
return ErrorData.create({
|
|
18
|
-
code: ErrorCode[this.code],
|
|
19
|
-
message: this.message,
|
|
20
|
-
data: JSON.stringify(this.data)
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
static fromProto(data = PROTO_ERROR) {
|
|
24
|
-
return new AttestorError(
|
|
25
|
-
typeof data.code === "number" ? getKeyForValue(ErrorCode, data.code) || "UNRECOGNIZED" : data.code,
|
|
26
|
-
data.message,
|
|
27
|
-
data.data ? JSON.parse(data.data) : void 0
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
static fromError(err, code = "ERROR_INTERNAL") {
|
|
31
|
-
if (err instanceof AttestorError) {
|
|
32
|
-
return err;
|
|
33
|
-
}
|
|
34
|
-
return new AttestorError(code, err.message);
|
|
35
|
-
}
|
|
36
|
-
static badRequest(message, data) {
|
|
37
|
-
return new AttestorError(
|
|
38
|
-
"ERROR_BAD_REQUEST",
|
|
39
|
-
message,
|
|
40
|
-
data
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
function getKeyForValue(obj, value) {
|
|
45
|
-
for (const key in obj) {
|
|
46
|
-
if (obj[key] === value) {
|
|
47
|
-
return key;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return void 0;
|
|
51
|
-
}
|
|
52
|
-
export {
|
|
53
|
-
AttestorError
|
|
54
|
-
};
|