@reclaimprotocol/attestor-core 4.0.3 → 5.0.1-beta.2
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/LICENSE +660 -660
- package/README.md +1 -2
- package/lib/avs/abis/avsDirectoryABI.js +341 -342
- package/lib/avs/abis/delegationABI.js +4 -5
- package/lib/avs/abis/registryABI.js +722 -723
- package/lib/avs/client/create-claim-on-avs.d.ts +5 -5
- package/lib/avs/client/create-claim-on-avs.js +160 -139
- package/lib/avs/config.d.ts +1 -1
- package/lib/avs/config.js +25 -23
- package/lib/avs/contracts/ReclaimServiceManager.d.ts +436 -532
- package/lib/avs/contracts/ReclaimServiceManager.js +0 -3
- package/lib/avs/contracts/common.d.ts +40 -11
- package/lib/avs/contracts/common.js +0 -3
- package/lib/avs/contracts/factories/ReclaimServiceManager__factory.d.ts +13 -11
- package/lib/avs/contracts/factories/ReclaimServiceManager__factory.js +1157 -1148
- package/lib/avs/contracts/factories/index.d.ts +1 -1
- package/lib/avs/contracts/factories/index.js +4 -9
- package/lib/avs/contracts/index.d.ts +3 -3
- package/lib/avs/contracts/index.js +6 -40
- package/lib/avs/types/index.d.ts +6 -6
- package/lib/avs/types/index.js +0 -3
- package/lib/avs/utils/contracts.d.ts +14 -14
- package/lib/avs/utils/contracts.js +50 -35
- package/lib/avs/utils/register.d.ts +3 -3
- package/lib/avs/utils/register.js +71 -79
- package/lib/avs/utils/tasks.d.ts +4 -4
- package/lib/avs/utils/tasks.js +44 -41
- package/lib/client/create-claim.d.ts +2 -2
- package/lib/client/create-claim.js +437 -400
- package/lib/client/index.d.ts +3 -3
- package/lib/client/index.js +3 -20
- package/lib/client/tunnels/make-rpc-tcp-tunnel.d.ts +2 -2
- package/lib/client/tunnels/make-rpc-tcp-tunnel.js +49 -56
- package/lib/client/tunnels/make-rpc-tls-tunnel.d.ts +4 -3
- package/lib/client/tunnels/make-rpc-tls-tunnel.js +123 -131
- package/lib/client/utils/attestor-pool.d.ts +3 -1
- package/lib/client/utils/attestor-pool.js +21 -25
- package/lib/client/utils/client-socket.d.ts +4 -4
- package/lib/client/utils/client-socket.js +114 -94
- package/lib/client/utils/message-handler.d.ts +2 -2
- package/lib/client/utils/message-handler.js +89 -86
- package/lib/config/index.d.ts +6 -3
- package/lib/config/index.js +60 -37
- package/lib/external-rpc/benchmark.d.ts +1 -0
- package/lib/external-rpc/benchmark.js +82 -0
- package/lib/external-rpc/event-bus.d.ts +7 -0
- package/lib/external-rpc/event-bus.js +17 -0
- package/lib/external-rpc/global.d.js +0 -0
- package/lib/external-rpc/handle-incoming-msg.d.ts +2 -0
- package/lib/external-rpc/handle-incoming-msg.js +241 -0
- package/lib/external-rpc/index.d.ts +3 -0
- package/lib/external-rpc/index.js +3 -0
- package/lib/external-rpc/jsc-polyfills/1.d.ts +14 -0
- package/lib/external-rpc/jsc-polyfills/1.js +80 -0
- package/lib/external-rpc/jsc-polyfills/2.js +15 -0
- package/lib/external-rpc/jsc-polyfills/event.d.ts +10 -0
- package/lib/external-rpc/jsc-polyfills/event.js +19 -0
- package/lib/external-rpc/jsc-polyfills/index.d.ts +2 -0
- package/lib/external-rpc/jsc-polyfills/index.js +2 -0
- package/lib/external-rpc/jsc-polyfills/ws.d.ts +21 -0
- package/lib/external-rpc/jsc-polyfills/ws.js +83 -0
- package/lib/external-rpc/setup-browser.d.ts +6 -0
- package/lib/external-rpc/setup-browser.js +33 -0
- package/lib/external-rpc/setup-jsc.d.ts +24 -0
- package/lib/external-rpc/setup-jsc.js +22 -0
- package/lib/{window-rpc → external-rpc}/types.d.ts +56 -35
- package/lib/external-rpc/types.js +0 -0
- package/lib/external-rpc/utils.d.ts +20 -0
- package/lib/external-rpc/utils.js +100 -0
- package/lib/external-rpc/zk.d.ts +14 -0
- package/lib/external-rpc/zk.js +58 -0
- package/lib/index.d.ts +8 -9
- package/lib/index.js +12 -49
- package/lib/mechain/abis/governanceABI.js +460 -461
- package/lib/mechain/abis/taskABI.js +505 -506
- package/lib/mechain/client/create-claim-on-mechain.d.ts +3 -3
- package/lib/mechain/client/create-claim-on-mechain.js +31 -30
- package/lib/mechain/client/index.d.ts +1 -1
- package/lib/mechain/client/index.js +1 -18
- package/lib/mechain/constants/index.js +8 -7
- package/lib/mechain/index.d.ts +2 -2
- package/lib/mechain/index.js +2 -19
- package/lib/mechain/types/index.d.ts +2 -2
- package/lib/mechain/types/index.js +0 -3
- package/lib/proto/api.d.ts +182 -39
- package/lib/proto/api.js +4105 -3555
- package/lib/proto/tee-bundle.d.ts +156 -0
- package/lib/proto/tee-bundle.js +1296 -0
- package/lib/providers/http/index.d.ts +16 -1
- package/lib/providers/http/index.js +603 -576
- package/lib/providers/http/patch-parse5-tree.d.ts +6 -0
- package/lib/providers/http/patch-parse5-tree.js +34 -0
- package/lib/providers/http/utils.d.ts +7 -4
- package/lib/providers/http/utils.js +240 -317
- package/lib/providers/index.d.ts +1 -1
- package/lib/providers/index.js +5 -9
- package/lib/scripts/check-avs-registration.d.ts +1 -1
- package/lib/scripts/check-avs-registration.js +24 -25
- package/lib/scripts/fallbacks/crypto.d.ts +1 -0
- package/lib/scripts/fallbacks/crypto.js +4 -0
- package/lib/scripts/fallbacks/empty.d.ts +3 -0
- package/lib/scripts/fallbacks/empty.js +4 -0
- package/lib/scripts/fallbacks/re2.d.ts +1 -0
- package/lib/scripts/fallbacks/re2.js +7 -0
- package/lib/scripts/fallbacks/snarkjs.d.ts +1 -0
- package/lib/scripts/fallbacks/snarkjs.js +10 -0
- package/lib/scripts/fallbacks/stwo.d.ts +6 -0
- package/lib/scripts/fallbacks/stwo.js +159 -0
- package/lib/scripts/generate-provider-types.js +92 -73
- package/lib/scripts/generate-receipt.d.ts +2 -2
- package/lib/scripts/generate-receipt.js +94 -83
- package/lib/scripts/generate-toprf-keys.js +17 -16
- package/lib/scripts/jsc-cli-rpc.d.ts +1 -0
- package/lib/scripts/jsc-cli-rpc.js +35 -0
- package/lib/scripts/register-avs-operator.d.ts +1 -1
- package/lib/scripts/register-avs-operator.js +3 -7
- package/lib/scripts/start-server.d.ts +1 -1
- package/lib/scripts/start-server.js +9 -11
- package/lib/scripts/update-avs-metadata.d.ts +1 -1
- package/lib/scripts/update-avs-metadata.js +17 -19
- package/lib/scripts/utils.js +8 -9
- package/lib/scripts/whitelist-operator.d.ts +1 -1
- package/lib/scripts/whitelist-operator.js +13 -15
- package/lib/server/create-server.d.ts +3 -2
- package/lib/server/create-server.js +98 -85
- package/lib/server/handlers/claimTeeBundle.d.ts +6 -0
- package/lib/server/handlers/claimTeeBundle.js +232 -0
- package/lib/server/handlers/claimTunnel.d.ts +1 -1
- package/lib/server/handlers/claimTunnel.js +75 -73
- package/lib/server/handlers/completeClaimOnChain.d.ts +1 -1
- package/lib/server/handlers/completeClaimOnChain.js +27 -26
- package/lib/server/handlers/createClaimOnChain.d.ts +1 -1
- package/lib/server/handlers/createClaimOnChain.js +30 -29
- package/lib/server/handlers/createTaskOnMechain.d.ts +1 -1
- package/lib/server/handlers/createTaskOnMechain.js +54 -49
- package/lib/server/handlers/createTunnel.d.ts +1 -1
- package/lib/server/handlers/createTunnel.js +91 -94
- package/lib/server/handlers/disconnectTunnel.d.ts +1 -1
- package/lib/server/handlers/disconnectTunnel.js +6 -8
- package/lib/server/handlers/fetchCertificateBytes.d.ts +2 -0
- package/lib/server/handlers/fetchCertificateBytes.js +57 -0
- package/lib/server/handlers/index.d.ts +1 -1
- package/lib/server/handlers/index.js +24 -21
- package/lib/server/handlers/init.d.ts +1 -1
- package/lib/server/handlers/init.js +31 -34
- package/lib/server/handlers/toprf.d.ts +1 -1
- package/lib/server/handlers/toprf.js +17 -19
- package/lib/server/index.d.ts +4 -4
- package/lib/server/index.js +4 -21
- package/lib/server/socket.d.ts +7 -7
- package/lib/server/socket.js +104 -106
- package/lib/server/tunnels/make-tcp-tunnel.d.ts +5 -3
- package/lib/server/tunnels/make-tcp-tunnel.js +189 -162
- package/lib/server/utils/apm.d.ts +1 -1
- package/lib/server/utils/apm.js +26 -40
- package/lib/server/utils/assert-valid-claim-request.d.ts +6 -5
- package/lib/server/utils/assert-valid-claim-request.js +339 -185
- package/lib/server/utils/config-env.js +4 -7
- package/lib/server/utils/dns.js +18 -16
- package/lib/server/utils/gcp-attestation.d.ts +17 -0
- package/lib/server/utils/gcp-attestation.js +237 -0
- package/lib/server/utils/generics.d.ts +3 -3
- package/lib/server/utils/generics.js +37 -51
- package/lib/server/utils/iso.js +255 -256
- package/lib/server/utils/keep-alive.d.ts +2 -2
- package/lib/server/utils/keep-alive.js +36 -40
- package/lib/server/utils/nitro-attestation.d.ts +33 -0
- package/lib/server/utils/nitro-attestation.js +249 -0
- package/lib/server/utils/oprf-raw.d.ts +21 -0
- package/lib/server/utils/oprf-raw.js +61 -0
- package/lib/server/utils/process-handshake.d.ts +3 -3
- package/lib/server/utils/process-handshake.js +217 -175
- package/lib/server/utils/proxy-session.d.ts +1 -0
- package/lib/server/utils/proxy-session.js +6 -0
- package/lib/server/utils/tee-oprf-mpc-verification.d.ts +16 -0
- package/lib/server/utils/tee-oprf-mpc-verification.js +86 -0
- package/lib/server/utils/tee-oprf-verification.d.ts +24 -0
- package/lib/server/utils/tee-oprf-verification.js +151 -0
- package/lib/server/utils/tee-transcript-reconstruction.d.ts +24 -0
- package/lib/server/utils/tee-transcript-reconstruction.js +140 -0
- package/lib/server/utils/tee-verification.d.ts +28 -0
- package/lib/server/utils/tee-verification.js +358 -0
- package/lib/{utils → server/utils}/validation.d.ts +1 -1
- package/lib/server/utils/validation.js +45 -0
- package/lib/types/bgp.js +0 -3
- package/lib/types/claims.d.ts +7 -10
- package/lib/types/claims.js +0 -3
- package/lib/types/client.d.ts +5 -5
- package/lib/types/client.js +0 -3
- package/lib/types/general.d.ts +29 -4
- package/lib/types/general.js +0 -3
- package/lib/types/handlers.d.ts +3 -3
- package/lib/types/handlers.js +0 -3
- package/lib/types/index.d.ts +10 -10
- package/lib/types/index.js +10 -27
- package/lib/types/providers.d.ts +15 -4
- package/lib/types/providers.gen.d.ts +15 -1
- package/lib/types/providers.gen.js +15 -13
- package/lib/types/providers.js +0 -3
- package/lib/types/rpc.d.ts +2 -2
- package/lib/types/rpc.js +0 -3
- package/lib/types/signatures.js +0 -3
- package/lib/types/tunnel.d.ts +2 -2
- package/lib/types/tunnel.js +0 -3
- package/lib/types/zk.d.ts +17 -2
- package/lib/types/zk.js +0 -3
- package/lib/utils/auth.d.ts +2 -1
- package/lib/utils/auth.js +66 -59
- package/lib/utils/b64-json.js +13 -19
- package/lib/utils/bgp-listener.d.ts +1 -1
- package/lib/utils/bgp-listener.js +111 -114
- package/lib/utils/claims.d.ts +3 -3
- package/lib/utils/claims.js +78 -101
- package/lib/utils/env.js +15 -16
- package/lib/utils/error.d.ts +6 -7
- package/lib/utils/error.js +50 -39
- package/lib/utils/generics.d.ts +15 -13
- package/lib/utils/generics.js +217 -297
- package/lib/utils/http-parser.d.ts +1 -1
- package/lib/utils/http-parser.js +186 -237
- package/lib/utils/index.d.ts +13 -12
- package/lib/utils/index.js +13 -29
- package/lib/utils/logger.d.ts +1 -1
- package/lib/utils/logger.js +69 -87
- package/lib/utils/prepare-packets.d.ts +3 -3
- package/lib/utils/prepare-packets.js +66 -58
- package/lib/utils/redactions.d.ts +20 -1
- package/lib/utils/redactions.js +116 -129
- package/lib/utils/retries.d.ts +1 -1
- package/lib/utils/retries.js +24 -26
- package/lib/utils/signatures/eth.d.ts +1 -1
- package/lib/utils/signatures/eth.js +28 -30
- package/lib/utils/signatures/index.d.ts +3 -3
- package/lib/utils/signatures/index.js +11 -10
- package/lib/utils/socket-base.d.ts +6 -5
- package/lib/utils/socket-base.js +89 -88
- package/lib/utils/tls.d.ts +1 -1
- package/lib/utils/tls.js +54 -28
- package/lib/utils/ws.d.ts +1 -6
- package/lib/utils/ws.js +17 -33
- package/lib/utils/zk.d.ts +28 -12
- package/lib/utils/zk.js +587 -406
- package/package.json +72 -60
- package/lib/avs/tests/test.operator.d.ts +0 -11
- package/lib/avs/tests/test.operator.js +0 -313
- package/lib/avs/tests/utils.d.ts +0 -2
- package/lib/avs/tests/utils.js +0 -50
- package/lib/scripts/verify-root-ca.d.ts +0 -1
- package/lib/scripts/verify-root-ca.js +0 -51
- package/lib/tests/describe-with-server.d.ts +0 -20
- package/lib/tests/describe-with-server.js +0 -64
- package/lib/tests/mock-provider-server.d.ts +0 -13
- package/lib/tests/mock-provider-server.js +0 -65
- package/lib/tests/mocks.d.ts +0 -4
- package/lib/tests/mocks.js +0 -23
- package/lib/tests/test.auth.js +0 -75
- package/lib/tests/test.bgp-listener.js +0 -169
- package/lib/tests/test.claim-creation.js +0 -280
- package/lib/tests/test.http-parser.d.ts +0 -1
- package/lib/tests/test.http-parser.js +0 -120
- package/lib/tests/test.http-provider-utils.js +0 -2416
- package/lib/tests/test.http-provider.d.ts +0 -1
- package/lib/tests/test.http-provider.js +0 -114
- package/lib/tests/test.rpc-communication.d.ts +0 -1
- package/lib/tests/test.rpc-communication.js +0 -64
- package/lib/tests/test.rpc-tunnel.d.ts +0 -1
- package/lib/tests/test.rpc-tunnel.js +0 -172
- package/lib/tests/test.signatures.d.ts +0 -1
- package/lib/tests/test.signatures.js +0 -24
- package/lib/tests/test.tcp-tunnel.d.ts +0 -1
- package/lib/tests/test.tcp-tunnel.js +0 -64
- package/lib/tests/test.zk.d.ts +0 -1
- package/lib/tests/test.zk.js +0 -337
- package/lib/tests/utils.d.ts +0 -18
- package/lib/tests/utils.js +0 -64
- package/lib/utils/atomic-operations.d.ts +0 -24
- package/lib/utils/atomic-operations.js +0 -65
- package/lib/utils/benchmark.d.ts +0 -1
- package/lib/utils/benchmark.js +0 -70
- package/lib/utils/connection-state-machine.d.ts +0 -43
- package/lib/utils/connection-state-machine.js +0 -129
- package/lib/utils/resource-monitor.d.ts +0 -61
- package/lib/utils/resource-monitor.js +0 -107
- package/lib/utils/validation.js +0 -46
- package/lib/window-rpc/index.d.ts +0 -3
- package/lib/window-rpc/index.js +0 -20
- package/lib/window-rpc/setup-window-rpc.d.ts +0 -5
- package/lib/window-rpc/setup-window-rpc.js +0 -291
- package/lib/window-rpc/types.js +0 -3
- package/lib/window-rpc/utils.d.ts +0 -14
- package/lib/window-rpc/utils.js +0 -102
- package/lib/window-rpc/window-rpc-zk.d.ts +0 -15
- package/lib/window-rpc/window-rpc-zk.js +0 -85
- /package/lib/{tests/test.auth.d.ts → external-rpc/jsc-polyfills/2.d.ts} +0 -0
- /package/lib/{tests/test.bgp-listener.d.ts → scripts/build-browser.d.ts} +0 -0
- /package/lib/{tests/test.claim-creation.d.ts → scripts/build-jsc.d.ts} +0 -0
- /package/lib/{tests/test.http-provider-utils.d.ts → scripts/build-lib.d.ts} +0 -0
|
@@ -9,6 +9,10 @@ export interface HttpProviderParameters {
|
|
|
9
9
|
* Specify the geographical location from where to proxy the request. 2-letter ISO country code or parameter (public or secret)
|
|
10
10
|
*/
|
|
11
11
|
geoLocation?: string;
|
|
12
|
+
/**
|
|
13
|
+
* 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".
|
|
14
|
+
*/
|
|
15
|
+
proxySessionId?: string;
|
|
12
16
|
/**
|
|
13
17
|
* 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
|
|
14
18
|
*/
|
|
@@ -74,7 +78,7 @@ export interface HttpProviderParameters {
|
|
|
74
78
|
* Eg. if hash is enabled, the original value is "hello", and hashed is "a1b2c", then the attestor will only see "a1b2c".
|
|
75
79
|
* Note: if a regex with named groups is provided, only the named groups will be hashed.
|
|
76
80
|
*/
|
|
77
|
-
hash?: "oprf";
|
|
81
|
+
hash?: "oprf" | "oprf-mpc" | "oprf-raw";
|
|
78
82
|
}[];
|
|
79
83
|
/**
|
|
80
84
|
* 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
|
|
@@ -102,6 +106,11 @@ export declare const HttpProviderParametersJson: {
|
|
|
102
106
|
nullable: boolean;
|
|
103
107
|
description: string;
|
|
104
108
|
};
|
|
109
|
+
proxySessionId: {
|
|
110
|
+
type: string;
|
|
111
|
+
nullable: boolean;
|
|
112
|
+
description: string;
|
|
113
|
+
};
|
|
105
114
|
headers: {
|
|
106
115
|
type: string;
|
|
107
116
|
description: string;
|
|
@@ -289,6 +298,11 @@ export declare const PROVIDER_SCHEMAS: {
|
|
|
289
298
|
nullable: boolean;
|
|
290
299
|
description: string;
|
|
291
300
|
};
|
|
301
|
+
proxySessionId: {
|
|
302
|
+
type: string;
|
|
303
|
+
nullable: boolean;
|
|
304
|
+
description: string;
|
|
305
|
+
};
|
|
292
306
|
headers: {
|
|
293
307
|
type: string;
|
|
294
308
|
description: string;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
"use
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
13
16
|
};
|
|
14
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJvdmlkZXJzLmdlbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90eXBlcy9wcm92aWRlcnMuZ2VuLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxvQkFBb0I7QUFDcEIsaUNBQWlDOzs7QUF5RnBCLFFBQUEsMEJBQTBCLEdBQUcsRUFBQyxPQUFPLEVBQUMsd0JBQXdCLEVBQUMsTUFBTSxFQUFDLFFBQVEsRUFBQyxVQUFVLEVBQUMsQ0FBQyxLQUFLLEVBQUMsUU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FDLEVBQUMsTUFBTSxFQUFDLFFBQVEsRUFBQyxFQUFDLEVBQUMsYUFBYSxFQUFDLEVBQUMsTUFBTSxFQUFDLFFBQVEsRUFBQyxhQUFhLEVBQUMsb0lBQW9JLEVBQUMsc0JBQXNCLEVBQUMsRUFBQyxNQUFNLEVBQUMsUUFBUSxFQUFDLEVBQUMsRUFBQyxFQUFDLHNCQUFzQixFQUFDLEtBQUssRUFBQyxDQUFBO0FBUTV3QixRQUFBLGdCQUFnQixHQUFHO0lBQy9CLElBQUksRUFBRTtRQUNMLFVBQVUsRUFBRSxrQ0FBMEI7UUFDdEMsZ0JBQWdCLEVBQUUsd0NBQWdDO0tBQ2xEO0NBQ0QsQ0FBQSJ9
|
package/lib/types/providers.js
CHANGED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJvdmlkZXJzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3R5cGVzL3Byb3ZpZGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=
|
package/lib/types/rpc.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { RPCMessage, TunnelDisconnectEvent, TunnelMessage } from '
|
|
2
|
-
import type { AttestorError } from '
|
|
1
|
+
import type { RPCMessage, TunnelDisconnectEvent, TunnelMessage } from '#src/proto/api.ts';
|
|
2
|
+
import type { AttestorError } from '#src/utils/error.ts';
|
|
3
3
|
type ExtractPrefix<T, S extends string> = T extends `${infer _}${S}` ? _ : never;
|
|
4
4
|
export type RPCType = ExtractPrefix<keyof RPCMessage, 'Request'>;
|
|
5
5
|
type RPCRequestType<T extends RPCType> = `${T}Request`;
|
package/lib/types/rpc.js
CHANGED
package/lib/types/signatures.js
CHANGED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2lnbmF0dXJlcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90eXBlcy9zaWduYXR1cmVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiIifQ==
|
package/lib/types/tunnel.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CreateTunnelRequest } from '
|
|
1
|
+
import type { CreateTunnelRequest } from '#src/proto/api.ts';
|
|
2
2
|
export type MakeTunnelBaseOpts<O> = O & {
|
|
3
3
|
onClose?(err?: Error): void;
|
|
4
4
|
onMessage?(data: Uint8Array): void;
|
|
@@ -14,5 +14,5 @@ export type Transcript<T> = {
|
|
|
14
14
|
}[];
|
|
15
15
|
export type TCPSocketProperties = {
|
|
16
16
|
transcript: Transcript<Uint8Array>;
|
|
17
|
-
createRequest: Pick<CreateTunnelRequest, 'host' | 'port' | 'geoLocation'>;
|
|
17
|
+
createRequest: Pick<CreateTunnelRequest, 'host' | 'port' | 'geoLocation' | 'proxySessionId'>;
|
|
18
18
|
};
|
package/lib/types/tunnel.js
CHANGED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHVubmVsLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3R5cGVzL3R1bm5lbC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=
|
package/lib/types/zk.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EncryptionAlgorithm, OPRFOperator, ZKEngine, ZKOperator } from '@reclaimprotocol/zk-symmetric-crypto';
|
|
2
|
-
import { TOPRFPayload } from '
|
|
1
|
+
import type { EncryptionAlgorithm, OPRFOperator, ZKEngine, ZKOperator } from '@reclaimprotocol/zk-symmetric-crypto';
|
|
2
|
+
import type { TOPRFPayload } from '#src/proto/api.ts';
|
|
3
3
|
export type ZKOperators = {
|
|
4
4
|
[E in EncryptionAlgorithm]?: ZKOperator;
|
|
5
5
|
};
|
|
@@ -20,4 +20,19 @@ export type PrepareZKProofsBaseOpts = {
|
|
|
20
20
|
export type TOPRFProofParams = TOPRFPayload & {
|
|
21
21
|
mask: Uint8Array;
|
|
22
22
|
plaintext: Uint8Array;
|
|
23
|
+
overshoot?: {
|
|
24
|
+
ciphertext: Uint8Array;
|
|
25
|
+
iv: Uint8Array;
|
|
26
|
+
recordNumber: number;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Marker for server-side OPRF computation (oprf-raw mode).
|
|
31
|
+
* Data is revealed to attestor who computes OPRF directly.
|
|
32
|
+
*/
|
|
33
|
+
export type OPRFRawMarker = {
|
|
34
|
+
dataLocation: {
|
|
35
|
+
fromIndex: number;
|
|
36
|
+
length: number;
|
|
37
|
+
};
|
|
23
38
|
};
|
package/lib/types/zk.js
CHANGED
package/lib/utils/auth.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { AuthenticationRequest, ServiceSignatureType } from '#src/proto/api.ts';
|
|
2
|
+
import { AuthenticatedUserData } from '#src/proto/api.ts';
|
|
2
3
|
export declare function assertValidAuthRequest(request: AuthenticationRequest | undefined, signatureType: ServiceSignatureType): Promise<void>;
|
|
3
4
|
/**
|
|
4
5
|
* Create an authentication request with the given data and private key,
|
package/lib/utils/auth.js
CHANGED
|
@@ -1,64 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const env_1 = require("../utils/env");
|
|
9
|
-
const error_1 = require("../utils/error");
|
|
10
|
-
const generics_1 = require("../utils/generics");
|
|
11
|
-
const signatures_1 = require("../utils/signatures");
|
|
1
|
+
import { getBytes } from "ethers";
|
|
2
|
+
import { DEFAULT_AUTH_EXPIRY_S } from "../config/index.js";
|
|
3
|
+
import { AuthenticatedUserData } from "../proto/api.js";
|
|
4
|
+
import { getEnvVariable } from "../utils/env.js";
|
|
5
|
+
import { AttestorError } from "../utils/error.js";
|
|
6
|
+
import { unixTimestampSeconds } from "../utils/generics.js";
|
|
7
|
+
import { SelectedServiceSignature, SIGNATURES } from "../utils/signatures/index.js";
|
|
12
8
|
async function assertValidAuthRequest(request, signatureType) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
if (!publicKey) {
|
|
24
|
-
throw new error_1.AttestorError('ERROR_BAD_REQUEST', 'The attestor is not configured for authentication');
|
|
25
|
-
}
|
|
26
|
-
const { signature, data } = request;
|
|
27
|
-
if (!data) {
|
|
28
|
-
throw new error_1.AttestorError('ERROR_AUTHENTICATION_FAILED', 'Missing data in auth request');
|
|
29
|
-
}
|
|
30
|
-
if (data.expiresAt < (0, generics_1.unixTimestampSeconds)()) {
|
|
31
|
-
throw new error_1.AttestorError('ERROR_AUTHENTICATION_FAILED', 'Authentication request has expired');
|
|
32
|
-
}
|
|
33
|
-
const proto = api_1.AuthenticatedUserData.encode(data).finish();
|
|
34
|
-
const signatureAlg = signatures_1.SIGNATURES[signatureType];
|
|
35
|
-
const address = signatureAlg.getAddress(await ethers_1.ethers.utils.arrayify(publicKey));
|
|
36
|
-
const verified = await signatureAlg
|
|
37
|
-
.verify(proto, signature, address);
|
|
38
|
-
if (!verified) {
|
|
39
|
-
throw new error_1.AttestorError('ERROR_AUTHENTICATION_FAILED', 'Signature verification failed');
|
|
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
|
+
);
|
|
40
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
|
+
}
|
|
41
50
|
}
|
|
42
|
-
/**
|
|
43
|
-
* Create an authentication request with the given data and private key,
|
|
44
|
-
* which can then be used to authenticate with the service.
|
|
45
|
-
*/
|
|
46
51
|
async function createAuthRequest(_data, privateKey) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return request;
|
|
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;
|
|
63
67
|
}
|
|
64
|
-
|
|
68
|
+
export {
|
|
69
|
+
assertValidAuthRequest,
|
|
70
|
+
createAuthRequest
|
|
71
|
+
};
|
package/lib/utils/b64-json.js
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.B64_JSON_REVIVER = exports.B64_JSON_REPLACER = void 0;
|
|
4
|
-
const utils_1 = require("ethers/lib/utils");
|
|
1
|
+
import { decodeBase64, encodeBase64 } from "ethers";
|
|
5
2
|
const B64_JSON_REPLACER = (key, value) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
&& value.buffer instanceof ArrayBuffer)) {
|
|
11
|
-
return { type: 'uint8array', value: utils_1.base64.encode(value) };
|
|
12
|
-
}
|
|
13
|
-
return 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;
|
|
14
7
|
};
|
|
15
|
-
exports.B64_JSON_REPLACER = B64_JSON_REPLACER;
|
|
16
8
|
const B64_JSON_REVIVER = (key, value) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
|
21
17
|
};
|
|
22
|
-
exports.B64_JSON_REVIVER = B64_JSON_REVIVER;
|
|
23
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYjY0LWpzb24uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbHMvYjY0LWpzb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsNENBQXlDO0FBRWxDLE1BQU0saUJBQWlCLEdBQUcsQ0FBQyxHQUFXLEVBQUUsS0FBVSxFQUFFLEVBQUU7SUFDNUQsSUFDQyxLQUFLLFlBQVksVUFBVTtXQUN4QixDQUNGLE9BQU8sS0FBSyxLQUFLLFFBQVE7ZUFDdEIsS0FBSztlQUNMLFFBQVEsSUFBSSxLQUFLO2VBQ2pCLEtBQUssQ0FBQyxNQUFNLFlBQVksV0FBVyxDQUN0QyxFQUNBLENBQUM7UUFDRixPQUFPLEVBQUUsSUFBSSxFQUFFLFlBQVksRUFBRSxLQUFLLEVBQUUsY0FBTSxDQUFDLE1BQU0sQ0FBQyxLQUFLLENBQUMsRUFBRSxDQUFBO0lBQzNELENBQUM7SUFFRCxPQUFPLEtBQUssQ0FBQTtBQUNiLENBQUMsQ0FBQTtBQWRZLFFBQUEsaUJBQWlCLHFCQWM3QjtBQUVNLE1BQU0sZ0JBQWdCLEdBQUcsQ0FBQyxHQUFXLEVBQUUsS0FBVSxFQUFFLEVBQUU7SUFDM0QsSUFBRyxDQUFBLEtBQUssYUFBTCxLQUFLLHVCQUFMLEtBQUssQ0FBRSxJQUFJLE1BQUssWUFBWSxFQUFFLENBQUM7UUFDakMsT0FBTyxjQUFNLENBQUMsTUFBTSxDQUFDLEtBQUssQ0FBQyxLQUFLLENBQUMsQ0FBQTtJQUNsQyxDQUFDO0lBRUQsT0FBTyxLQUFLLENBQUE7QUFDYixDQUFDLENBQUE7QUFOWSxRQUFBLGdCQUFnQixvQkFNNUIifQ==
|
|
@@ -1,126 +1,123 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createBgpListener = createBgpListener;
|
|
7
|
-
const ip_cidr_1 = __importDefault(require("ip-cidr"));
|
|
8
|
-
const config_1 = require("../config");
|
|
9
|
-
const ws_1 = require("../utils/ws");
|
|
10
|
-
const ANNOUNCEMENT_OVERLAP = 'announcement-overlap';
|
|
1
|
+
import CIDR from "ip-cidr";
|
|
2
|
+
import { BGP_WS_URL } from "../config/index.js";
|
|
3
|
+
import { makeWebSocket } from "../utils/ws.js";
|
|
4
|
+
const ANNOUNCEMENT_OVERLAP = "announcement-overlap";
|
|
11
5
|
class BGPAnnouncementOverlapEvent extends Event {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
data;
|
|
7
|
+
constructor(data) {
|
|
8
|
+
super(ANNOUNCEMENT_OVERLAP);
|
|
9
|
+
this.data = data;
|
|
10
|
+
}
|
|
16
11
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Listens for BGP announcements and emits events whenever
|
|
19
|
-
* an announcement overlaps with a target IP.
|
|
20
|
-
*/
|
|
21
12
|
function createBgpListener(logger) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
function _callback(event) {
|
|
40
|
-
callback(event.data);
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
close() {
|
|
44
|
-
ws.onclose = null;
|
|
45
|
-
ws.onerror = null;
|
|
46
|
-
ws.close();
|
|
47
|
-
closed = true;
|
|
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);
|
|
48
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
|
+
}
|
|
49
60
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
};
|
|
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;
|
|
65
75
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
data: {
|
|
70
|
-
type: 'UPDATE',
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
ws.send(JSON.stringify(subscriptionMessage));
|
|
74
|
-
logger.info('connected to BGP websocket');
|
|
76
|
+
logger.info({ err }, "BGP websocket closed");
|
|
77
|
+
if (!err) {
|
|
78
|
+
return;
|
|
75
79
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
openWs();
|
|
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;
|
|
86
89
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const nextHop = announcement === null || announcement === void 0 ? void 0 : announcement['next_hop'];
|
|
99
|
-
const hasPrefixes = (prefixes === null || prefixes === void 0 ? void 0 : prefixes.length) && (nextHop || asPath);
|
|
100
|
-
if (!hasPrefixes) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
for (const prefix of prefixes) {
|
|
104
|
-
if (!overlapsTargetIps(prefix)) {
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
// emit event
|
|
108
|
-
eventTarget.dispatchEvent(new BGPAnnouncementOverlapEvent({ prefix }));
|
|
109
|
-
}
|
|
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;
|
|
110
101
|
}
|
|
102
|
+
eventTarget.dispatchEvent(
|
|
103
|
+
new BGPAnnouncementOverlapEvent({ prefix })
|
|
104
|
+
);
|
|
105
|
+
}
|
|
111
106
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
return false;
|
|
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
|
+
}
|
|
124
117
|
}
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
125
120
|
}
|
|
126
|
-
|
|
121
|
+
export {
|
|
122
|
+
createBgpListener
|
|
123
|
+
};
|