@reclaimprotocol/attestor-core 5.0.1-beta.2 → 5.0.1-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/resources/attestor-browser.min.mjs +4512 -0
- package/lib/external-rpc/index.js +10399 -3
- package/lib/index.js +8323 -10
- package/package.json +9 -4
- 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/global.d.js +0 -0
- 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/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/utils/logger.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { pino, stdTimeFunctions } from "pino";
|
|
2
|
-
import { getEnvVariable } from "../utils/env.js";
|
|
3
|
-
const PII_PROPERTIES = ["ownerPrivateKey", "secretParams"];
|
|
4
|
-
const redactedText = "[REDACTED]";
|
|
5
|
-
const envLevel = getEnvVariable("LOG_LEVEL");
|
|
6
|
-
let logger = pino();
|
|
7
|
-
makeLogger(false, envLevel);
|
|
8
|
-
function makeLogger(redactPii, level, onLog) {
|
|
9
|
-
const opts = {
|
|
10
|
-
// Log human readable time stamps instead of epoch time
|
|
11
|
-
timestamp: stdTimeFunctions.isoTime
|
|
12
|
-
};
|
|
13
|
-
if (redactPii) {
|
|
14
|
-
opts.formatters = { log: redact };
|
|
15
|
-
opts.serializers = { redact };
|
|
16
|
-
opts.browser = {
|
|
17
|
-
write: {
|
|
18
|
-
fatal: (log) => writeLog("fatal", log),
|
|
19
|
-
error: (log) => writeLog("error", log),
|
|
20
|
-
warn: (log) => writeLog("warn", log),
|
|
21
|
-
info: (log) => writeLog("info", log),
|
|
22
|
-
debug: (log) => writeLog("debug", log),
|
|
23
|
-
trace: (log) => writeLog("trace", log)
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
const pLogger = pino(opts);
|
|
28
|
-
pLogger.level = level || "info";
|
|
29
|
-
logger = pLogger;
|
|
30
|
-
return pLogger;
|
|
31
|
-
function writeLog(level2, log) {
|
|
32
|
-
log = redact(log);
|
|
33
|
-
const { msg, ...obj } = log;
|
|
34
|
-
if (console[level2]) {
|
|
35
|
-
console[level2](obj, msg);
|
|
36
|
-
} else {
|
|
37
|
-
console.log(obj, msg);
|
|
38
|
-
}
|
|
39
|
-
onLog?.(level2, log);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function isObjectProperty(property) {
|
|
43
|
-
return typeof property === "object" && !Array.isArray(property) && property !== null;
|
|
44
|
-
}
|
|
45
|
-
function getReplacer() {
|
|
46
|
-
const references = /* @__PURE__ */ new WeakSet();
|
|
47
|
-
return function(key, value) {
|
|
48
|
-
const isObject = typeof value === "object" && value !== null;
|
|
49
|
-
if (isObject) {
|
|
50
|
-
if (references.has(value)) {
|
|
51
|
-
return "[CIRCULAR]";
|
|
52
|
-
}
|
|
53
|
-
references.add(value);
|
|
54
|
-
}
|
|
55
|
-
return value;
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
function redact(json) {
|
|
59
|
-
const isObject = isObjectProperty(json);
|
|
60
|
-
if (!isObject && !Array.isArray(json)) {
|
|
61
|
-
return json;
|
|
62
|
-
}
|
|
63
|
-
const redacted = JSON.parse(JSON.stringify(json, getReplacer()));
|
|
64
|
-
for (const prop in redacted) {
|
|
65
|
-
if (PII_PROPERTIES.includes(prop)) {
|
|
66
|
-
redacted[prop] = redactedText;
|
|
67
|
-
}
|
|
68
|
-
if (Array.isArray(redacted[prop])) {
|
|
69
|
-
for (const [index, value] of redacted[prop].entries()) {
|
|
70
|
-
redacted[prop][index] = redact(value);
|
|
71
|
-
}
|
|
72
|
-
} else if (isObjectProperty(redacted[prop])) {
|
|
73
|
-
redacted[prop] = redact(redacted[prop]);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return redacted;
|
|
77
|
-
}
|
|
78
|
-
export {
|
|
79
|
-
logger,
|
|
80
|
-
makeLogger,
|
|
81
|
-
redact
|
|
82
|
-
};
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { concatenateUint8Arrays, crypto } from "@reclaimprotocol/tls";
|
|
2
|
-
import {
|
|
3
|
-
TranscriptMessageSenderType
|
|
4
|
-
} from "../proto/api.js";
|
|
5
|
-
import { makeZkProofGenerator } from "../utils/zk.js";
|
|
6
|
-
async function preparePacketsForReveal(tlsTranscript, reveals, { onZkProgress, ...opts }) {
|
|
7
|
-
const transcript = [];
|
|
8
|
-
const proofGenerator = await makeZkProofGenerator(opts);
|
|
9
|
-
let zkPacketsDone = 0;
|
|
10
|
-
await Promise.all(tlsTranscript.map(async ({ message, sender }, i) => {
|
|
11
|
-
const msg = {
|
|
12
|
-
sender: sender === "client" ? TranscriptMessageSenderType.TRANSCRIPT_MESSAGE_SENDER_TYPE_CLIENT : TranscriptMessageSenderType.TRANSCRIPT_MESSAGE_SENDER_TYPE_SERVER,
|
|
13
|
-
message: message.data,
|
|
14
|
-
reveal: void 0
|
|
15
|
-
};
|
|
16
|
-
transcript.push(msg);
|
|
17
|
-
const reveal = reveals.get(message);
|
|
18
|
-
if (!reveal || message.type === "plaintext") {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
switch (reveal?.type) {
|
|
22
|
-
case "complete":
|
|
23
|
-
msg.reveal = {
|
|
24
|
-
directReveal: {
|
|
25
|
-
key: await crypto.exportKey(message.encKey),
|
|
26
|
-
iv: message.fixedIv,
|
|
27
|
-
recordNumber: message.recordNumber
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
break;
|
|
31
|
-
case "zk": {
|
|
32
|
-
reveal.redactedPlaintext = concatenateUint8Arrays([
|
|
33
|
-
reveal.redactedPlaintext,
|
|
34
|
-
message.plaintext.slice(reveal.redactedPlaintext.length)
|
|
35
|
-
]);
|
|
36
|
-
const oprfRawMarkers = reveal.oprfRawMarkers?.map((m) => ({
|
|
37
|
-
dataLocation: m.dataLocation
|
|
38
|
-
})) || [];
|
|
39
|
-
const overshotOprfRawLength = reveal.overshotOprfRawFromPrevBlock?.length ?? 0;
|
|
40
|
-
await proofGenerator.addPacketToProve(
|
|
41
|
-
message,
|
|
42
|
-
reveal,
|
|
43
|
-
(proofs, toprfs) => msg.reveal = {
|
|
44
|
-
zkReveal: { proofs, toprfs, oprfRawMarkers, overshotOprfRawLength }
|
|
45
|
-
},
|
|
46
|
-
() => {
|
|
47
|
-
const next = tlsTranscript.slice(i + 1).find((t) => t.sender === sender);
|
|
48
|
-
return next?.message;
|
|
49
|
-
}
|
|
50
|
-
);
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
default:
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
}));
|
|
57
|
-
const zkPacketsTotal = proofGenerator.getTotalChunksToProve();
|
|
58
|
-
onZkProgress?.(zkPacketsDone, zkPacketsTotal);
|
|
59
|
-
await proofGenerator.generateProofs(
|
|
60
|
-
() => {
|
|
61
|
-
zkPacketsDone += 1;
|
|
62
|
-
onZkProgress?.(zkPacketsDone, zkPacketsTotal);
|
|
63
|
-
}
|
|
64
|
-
);
|
|
65
|
-
return transcript;
|
|
66
|
-
}
|
|
67
|
-
export {
|
|
68
|
-
preparePacketsForReveal
|
|
69
|
-
};
|
package/lib/utils/redactions.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { base64Encode } from "@bufbuild/protobuf/wire";
|
|
2
|
-
import { concatenateUint8Arrays } from "@reclaimprotocol/tls";
|
|
3
|
-
const REDACTION_CHAR = "*";
|
|
4
|
-
const REDACTION_CHAR_CODE = REDACTION_CHAR.charCodeAt(0);
|
|
5
|
-
function isRedactionCongruent(redacted, original) {
|
|
6
|
-
for (let i = 0; i < redacted.length; i++) {
|
|
7
|
-
const element = redacted[i];
|
|
8
|
-
const areSame = element === original[i] || typeof element === "string" && element === REDACTION_CHAR || typeof element === "number" && element === REDACTION_CHAR_CODE;
|
|
9
|
-
if (!areSame) {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
function isFullyRedacted(redacted) {
|
|
16
|
-
for (const element of redacted) {
|
|
17
|
-
if (element !== REDACTION_CHAR && element !== REDACTION_CHAR_CODE) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
async function getBlocksToReveal(blocks, redact, performOprf) {
|
|
24
|
-
const slicesWithReveal = blocks.map((block) => ({
|
|
25
|
-
block,
|
|
26
|
-
// copy the plaintext to avoid mutating the original
|
|
27
|
-
redactedPlaintext: new Uint8Array(block.plaintext)
|
|
28
|
-
}));
|
|
29
|
-
const total = concatenateUint8Arrays(blocks.map((b) => b.plaintext));
|
|
30
|
-
const redactions = redact(total);
|
|
31
|
-
if (!redactions.length) {
|
|
32
|
-
return "all";
|
|
33
|
-
}
|
|
34
|
-
let blockIdx = 0;
|
|
35
|
-
let cursorInBlock = 0;
|
|
36
|
-
let cursor = 0;
|
|
37
|
-
for (const redaction of redactions) {
|
|
38
|
-
await redactBlocks(redaction);
|
|
39
|
-
}
|
|
40
|
-
return slicesWithReveal.filter((s) => !isFullyRedacted(s.redactedPlaintext));
|
|
41
|
-
async function redactBlocks(slice) {
|
|
42
|
-
while (cursor < slice.fromIndex) {
|
|
43
|
-
advance();
|
|
44
|
-
}
|
|
45
|
-
if (slice.hash === "oprf-raw") {
|
|
46
|
-
const startBlockIdx = blockIdx;
|
|
47
|
-
const startCursorInBlock = cursorInBlock;
|
|
48
|
-
const totalLength = slice.toIndex - slice.fromIndex;
|
|
49
|
-
const block = slicesWithReveal[blockIdx];
|
|
50
|
-
block.oprfRawMarkers ||= [];
|
|
51
|
-
block.oprfRawMarkers.push({
|
|
52
|
-
dataLocation: {
|
|
53
|
-
fromIndex: startCursorInBlock,
|
|
54
|
-
length: totalLength
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
let overshootLen = 0;
|
|
58
|
-
while (cursor < slice.toIndex) {
|
|
59
|
-
if (blockIdx !== startBlockIdx) {
|
|
60
|
-
overshootLen += 1;
|
|
61
|
-
}
|
|
62
|
-
advance();
|
|
63
|
-
}
|
|
64
|
-
if (overshootLen) {
|
|
65
|
-
slicesWithReveal[blockIdx].overshotOprfRawFromPrevBlock = { length: overshootLen };
|
|
66
|
-
}
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
if (slice.hash) {
|
|
70
|
-
const plaintext = total.slice(slice.fromIndex, slice.toIndex);
|
|
71
|
-
const { nullifier, responses, mask } = await performOprf(plaintext);
|
|
72
|
-
const toprf = {
|
|
73
|
-
nullifier,
|
|
74
|
-
responses,
|
|
75
|
-
dataLocation: {
|
|
76
|
-
fromIndex: cursorInBlock,
|
|
77
|
-
length: slice.toIndex - slice.fromIndex
|
|
78
|
-
},
|
|
79
|
-
mask,
|
|
80
|
-
plaintext
|
|
81
|
-
};
|
|
82
|
-
const startBlockIdx = blockIdx;
|
|
83
|
-
const block = slicesWithReveal[blockIdx];
|
|
84
|
-
block.toprfs ||= [];
|
|
85
|
-
block.toprfs.push(toprf);
|
|
86
|
-
const nullifierStr = binaryHashToStr(nullifier, toprf.dataLocation.length);
|
|
87
|
-
let i = 0;
|
|
88
|
-
let overshootLen = 0;
|
|
89
|
-
while (cursor < slice.toIndex) {
|
|
90
|
-
if (blockIdx !== startBlockIdx) {
|
|
91
|
-
overshootLen += 1;
|
|
92
|
-
}
|
|
93
|
-
slicesWithReveal[blockIdx].redactedPlaintext[cursorInBlock] = nullifierStr.charCodeAt(i);
|
|
94
|
-
advance();
|
|
95
|
-
i += 1;
|
|
96
|
-
}
|
|
97
|
-
if (overshootLen) {
|
|
98
|
-
slicesWithReveal[blockIdx].overshotToprfFromPrevBlock = { length: overshootLen };
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
while (cursor < slice.toIndex) {
|
|
102
|
-
slicesWithReveal[blockIdx].redactedPlaintext[cursorInBlock] = REDACTION_CHAR_CODE;
|
|
103
|
-
advance();
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
function advance() {
|
|
107
|
-
cursor += 1;
|
|
108
|
-
cursorInBlock += 1;
|
|
109
|
-
if (cursorInBlock >= blocks[blockIdx].plaintext.length) {
|
|
110
|
-
blockIdx += 1;
|
|
111
|
-
cursorInBlock = 0;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
function redactSlices(total, slices) {
|
|
116
|
-
const redacted = new Uint8Array(total);
|
|
117
|
-
for (const slice of slices) {
|
|
118
|
-
for (let i = slice.fromIndex; i < slice.toIndex; i++) {
|
|
119
|
-
redacted[i] = REDACTION_CHAR_CODE;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return redacted;
|
|
123
|
-
}
|
|
124
|
-
function binaryHashToStr(hash, expLength) {
|
|
125
|
-
return base64Encode(hash).padEnd(expLength, "0").slice(0, expLength);
|
|
126
|
-
}
|
|
127
|
-
export {
|
|
128
|
-
REDACTION_CHAR,
|
|
129
|
-
REDACTION_CHAR_CODE,
|
|
130
|
-
binaryHashToStr,
|
|
131
|
-
getBlocksToReveal,
|
|
132
|
-
isFullyRedacted,
|
|
133
|
-
isRedactionCongruent,
|
|
134
|
-
redactSlices
|
|
135
|
-
};
|
package/lib/utils/retries.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
async function executeWithRetries(code, {
|
|
2
|
-
maxRetries = 3,
|
|
3
|
-
shouldRetry,
|
|
4
|
-
logger
|
|
5
|
-
}) {
|
|
6
|
-
let retries = 0;
|
|
7
|
-
while (retries < maxRetries) {
|
|
8
|
-
try {
|
|
9
|
-
const result = await code(retries);
|
|
10
|
-
return result;
|
|
11
|
-
} catch (err) {
|
|
12
|
-
retries += 1;
|
|
13
|
-
if (retries >= maxRetries) {
|
|
14
|
-
throw err;
|
|
15
|
-
}
|
|
16
|
-
if (!shouldRetry(err)) {
|
|
17
|
-
throw err;
|
|
18
|
-
}
|
|
19
|
-
logger.info({ err, retries }, "retrying failed operation");
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
throw new Error("retries exhausted");
|
|
23
|
-
}
|
|
24
|
-
export {
|
|
25
|
-
executeWithRetries
|
|
26
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { computeAddress, getBytes, hexlify, SigningKey, verifyMessage, Wallet } from "ethers";
|
|
2
|
-
const ETH_SIGNATURE_PROVIDER = {
|
|
3
|
-
getPublicKey(privateKey) {
|
|
4
|
-
const pub = SigningKey.computePublicKey(privateKey, true);
|
|
5
|
-
return getBytes(pub);
|
|
6
|
-
},
|
|
7
|
-
getAddress(publicKey) {
|
|
8
|
-
const pubKeyHex = typeof publicKey === "string" ? publicKey : hexlify(publicKey);
|
|
9
|
-
return computeAddress(pubKeyHex).toLowerCase();
|
|
10
|
-
},
|
|
11
|
-
async sign(data, privateKey) {
|
|
12
|
-
const wallet = getEthWallet(privateKey);
|
|
13
|
-
const signature = await wallet.signMessage(data);
|
|
14
|
-
return getBytes(signature);
|
|
15
|
-
},
|
|
16
|
-
async verify(data, signature, addressBytes) {
|
|
17
|
-
const address = typeof addressBytes === "string" ? addressBytes : hexlify(addressBytes);
|
|
18
|
-
const signatureHex = typeof signature === "string" ? signature : hexlify(signature);
|
|
19
|
-
const signerAddress = verifyMessage(data, signatureHex);
|
|
20
|
-
return signerAddress.toLowerCase() === address.toLowerCase();
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
function getEthWallet(privateKey) {
|
|
24
|
-
if (!privateKey) {
|
|
25
|
-
throw new Error("Private key missing");
|
|
26
|
-
}
|
|
27
|
-
return new Wallet(privateKey);
|
|
28
|
-
}
|
|
29
|
-
export {
|
|
30
|
-
ETH_SIGNATURE_PROVIDER
|
|
31
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ServiceSignatureType } from "../../proto/api.js";
|
|
2
|
-
import { ETH_SIGNATURE_PROVIDER } from "../../utils/signatures/eth.js";
|
|
3
|
-
const SIGNATURES = {
|
|
4
|
-
[ServiceSignatureType.SERVICE_SIGNATURE_TYPE_ETH]: ETH_SIGNATURE_PROVIDER
|
|
5
|
-
};
|
|
6
|
-
const SelectedServiceSignatureType = ServiceSignatureType.SERVICE_SIGNATURE_TYPE_ETH;
|
|
7
|
-
const SelectedServiceSignature = SIGNATURES[SelectedServiceSignatureType];
|
|
8
|
-
export {
|
|
9
|
-
SIGNATURES,
|
|
10
|
-
SelectedServiceSignature,
|
|
11
|
-
SelectedServiceSignatureType
|
|
12
|
-
};
|
package/lib/utils/socket-base.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { wsMessageHandler } from "../client/utils/message-handler.js";
|
|
2
|
-
import { RPCMessages } from "../proto/api.js";
|
|
3
|
-
import { AttestorError, makeRpcEvent, packRpcMessages } from "../utils/index.js";
|
|
4
|
-
class AttestorSocket {
|
|
5
|
-
eventTarget = new EventTarget();
|
|
6
|
-
socket;
|
|
7
|
-
logger;
|
|
8
|
-
metadata;
|
|
9
|
-
isInitialised = false;
|
|
10
|
-
constructor(socket, metadata, logger) {
|
|
11
|
-
this.socket = socket;
|
|
12
|
-
this.metadata = metadata;
|
|
13
|
-
this.logger = logger;
|
|
14
|
-
socket.addEventListener("error", (event) => {
|
|
15
|
-
const witErr = AttestorError.fromError(
|
|
16
|
-
event.error || new Error(event.message),
|
|
17
|
-
"ERROR_NETWORK_ERROR"
|
|
18
|
-
);
|
|
19
|
-
this.dispatchRPCEvent("connection-terminated", witErr);
|
|
20
|
-
});
|
|
21
|
-
socket.addEventListener("close", () => this.dispatchRPCEvent(
|
|
22
|
-
"connection-terminated",
|
|
23
|
-
new AttestorError(
|
|
24
|
-
"ERROR_NO_ERROR",
|
|
25
|
-
"connection closed"
|
|
26
|
-
)
|
|
27
|
-
));
|
|
28
|
-
socket.addEventListener("message", async (event) => {
|
|
29
|
-
try {
|
|
30
|
-
await wsMessageHandler.call(this, event.data);
|
|
31
|
-
} catch (err) {
|
|
32
|
-
this.logger.error({ err }, "error processing message");
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
get isOpen() {
|
|
37
|
-
return this.socket.readyState === this.socket.OPEN;
|
|
38
|
-
}
|
|
39
|
-
get isClosed() {
|
|
40
|
-
return this.socket.readyState === this.socket.CLOSED || this.socket.readyState === this.socket.CLOSING;
|
|
41
|
-
}
|
|
42
|
-
async sendMessage(...msgs) {
|
|
43
|
-
if (this.isClosed) {
|
|
44
|
-
throw new AttestorError(
|
|
45
|
-
"ERROR_NETWORK_ERROR",
|
|
46
|
-
"Connection closed, cannot send message"
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
if (!this.isOpen) {
|
|
50
|
-
throw new AttestorError(
|
|
51
|
-
"ERROR_NETWORK_ERROR",
|
|
52
|
-
"Wait for connection to open before sending message"
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
const msg = packRpcMessages(...msgs);
|
|
56
|
-
const bytes = RPCMessages.encode(msg).finish();
|
|
57
|
-
this.logger.trace({ msg }, "sending messages");
|
|
58
|
-
if ("sendPromise" in this.socket && this.socket.sendPromise) {
|
|
59
|
-
await this.socket.sendPromise(bytes);
|
|
60
|
-
} else {
|
|
61
|
-
this.socket.send(bytes);
|
|
62
|
-
}
|
|
63
|
-
return msg;
|
|
64
|
-
}
|
|
65
|
-
dispatchRPCEvent(type, data) {
|
|
66
|
-
const event = makeRpcEvent(type, data);
|
|
67
|
-
this.eventTarget.dispatchEvent(event);
|
|
68
|
-
}
|
|
69
|
-
addEventListener(type, listener) {
|
|
70
|
-
this.eventTarget.addEventListener(type, listener);
|
|
71
|
-
}
|
|
72
|
-
removeEventListener(type, listener) {
|
|
73
|
-
this.eventTarget.removeEventListener(type, listener);
|
|
74
|
-
}
|
|
75
|
-
async terminateConnection(err) {
|
|
76
|
-
if (this.isClosed) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
try {
|
|
80
|
-
const witErr = err ? AttestorError.fromError(err) : new AttestorError("ERROR_NO_ERROR", "");
|
|
81
|
-
this.dispatchRPCEvent("connection-terminated", witErr);
|
|
82
|
-
if (this.isOpen) {
|
|
83
|
-
await this.sendMessage({
|
|
84
|
-
connectionTerminationAlert: witErr.toProto()
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
} catch (err2) {
|
|
88
|
-
this.logger?.error({ err: err2 }, "error terminating connection");
|
|
89
|
-
} finally {
|
|
90
|
-
this.socket.close();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
export {
|
|
95
|
-
AttestorSocket
|
|
96
|
-
};
|
package/lib/utils/tls.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { SUPPORTED_NAMED_CURVES } from "@reclaimprotocol/tls";
|
|
2
|
-
import { detectEnvironment } from "../utils/env.js";
|
|
3
|
-
const ZK_CIPHER_SUITES = [
|
|
4
|
-
// chacha-20
|
|
5
|
-
"TLS_CHACHA20_POLY1305_SHA256",
|
|
6
|
-
"TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256",
|
|
7
|
-
"TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256",
|
|
8
|
-
// aes-256
|
|
9
|
-
"TLS_AES_256_GCM_SHA384",
|
|
10
|
-
"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
|
|
11
|
-
"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
|
|
12
|
-
// aes-128
|
|
13
|
-
"TLS_AES_128_GCM_SHA256",
|
|
14
|
-
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
|
|
15
|
-
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
|
|
16
|
-
"TLS_RSA_WITH_AES_128_GCM_SHA256"
|
|
17
|
-
];
|
|
18
|
-
const NAMED_CURVE_LIST = detectEnvironment() === "node" ? SUPPORTED_NAMED_CURVES : SUPPORTED_NAMED_CURVES.filter((c) => c !== "X25519");
|
|
19
|
-
TLS_ADDITIONAL_ROOT_CA_LIST.push(
|
|
20
|
-
`-----BEGIN CERTIFICATE-----
|
|
21
|
-
MIIEszCCA5ugAwIBAgIQCyWUIs7ZgSoVoE6ZUooO+jANBgkqhkiG9w0BAQsFADBh
|
|
22
|
-
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
|
|
23
|
-
d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBH
|
|
24
|
-
MjAeFw0xNzExMDIxMjI0MzNaFw0yNzExMDIxMjI0MzNaMGAxCzAJBgNVBAYTAlVT
|
|
25
|
-
MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j
|
|
26
|
-
b20xHzAdBgNVBAMTFlJhcGlkU1NMIFRMUyBSU0EgQ0EgRzEwggEiMA0GCSqGSIb3
|
|
27
|
-
DQEBAQUAA4IBDwAwggEKAoIBAQC/uVklRBI1FuJdUEkFCuDL/I3aJQiaZ6aibRHj
|
|
28
|
-
ap/ap9zy1aYNrphe7YcaNwMoPsZvXDR+hNJOo9gbgOYVTPq8gXc84I75YKOHiVA4
|
|
29
|
-
NrJJQZ6p2sJQyqx60HkEIjzIN+1LQLfXTlpuznToOa1hyTD0yyitFyOYwURM+/CI
|
|
30
|
-
8FNFMpBhw22hpeAQkOOLmsqT5QZJYeik7qlvn8gfD+XdDnk3kkuuu0eG+vuyrSGr
|
|
31
|
-
5uX5LRhFWlv1zFQDch/EKmd163m6z/ycx/qLa9zyvILc7cQpb+k7TLra9WE17YPS
|
|
32
|
-
n9ANjG+ECo9PDW3N9lwhKQCNvw1gGoguyCQu7HE7BnW8eSSFAgMBAAGjggFmMIIB
|
|
33
|
-
YjAdBgNVHQ4EFgQUDNtsgkkPSmcKuBTuesRIUojrVjgwHwYDVR0jBBgwFoAUTiJU
|
|
34
|
-
IBiV5uNu5g/6+rkS7QYXjzkwDgYDVR0PAQH/BAQDAgGGMB0GA1UdJQQWMBQGCCsG
|
|
35
|
-
AQUFBwMBBggrBgEFBQcDAjASBgNVHRMBAf8ECDAGAQH/AgEAMDQGCCsGAQUFBwEB
|
|
36
|
-
BCgwJjAkBggrBgEFBQcwAYYYaHR0cDovL29jc3AuZGlnaWNlcnQuY29tMEIGA1Ud
|
|
37
|
-
HwQ7MDkwN6A1oDOGMWh0dHA6Ly9jcmwzLmRpZ2ljZXJ0LmNvbS9EaWdpQ2VydEds
|
|
38
|
-
b2JhbFJvb3RHMi5jcmwwYwYDVR0gBFwwWjA3BglghkgBhv1sAQEwKjAoBggrBgEF
|
|
39
|
-
BQcCARYcaHR0cHM6Ly93d3cuZGlnaWNlcnQuY29tL0NQUzALBglghkgBhv1sAQIw
|
|
40
|
-
CAYGZ4EMAQIBMAgGBmeBDAECAjANBgkqhkiG9w0BAQsFAAOCAQEAGUSlOb4K3Wtm
|
|
41
|
-
SlbmE50UYBHXM0SKXPqHMzk6XQUpCheF/4qU8aOhajsyRQFDV1ih/uPIg7YHRtFi
|
|
42
|
-
CTq4G+zb43X1T77nJgSOI9pq/TqCwtukZ7u9VLL3JAq3Wdy2moKLvvC8tVmRzkAe
|
|
43
|
-
0xQCkRKIjbBG80MSyDX/R4uYgj6ZiNT/Zg6GI6RofgqgpDdssLc0XIRQEotxIZcK
|
|
44
|
-
zP3pGJ9FCbMHmMLLyuBd+uCWvVcF2ogYAawufChS/PT61D9rqzPRS5I2uqa3tmIT
|
|
45
|
-
44JhJgWhBnFMb7AGQkvNq9KNS9dd3GWc17H/dXa1enoxzWjE0hBdFjxPhUb0W3wi
|
|
46
|
-
8o34/m8Fxw==
|
|
47
|
-
-----END CERTIFICATE-----`
|
|
48
|
-
//RapidSSL TLS RSA CA G1
|
|
49
|
-
);
|
|
50
|
-
function getDefaultTlsOptions() {
|
|
51
|
-
return {
|
|
52
|
-
cipherSuites: ZK_CIPHER_SUITES,
|
|
53
|
-
namedCurves: NAMED_CURVE_LIST
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
export {
|
|
57
|
-
getDefaultTlsOptions
|
|
58
|
-
};
|
package/lib/utils/ws.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
function makeWebSocket(url) {
|
|
2
|
-
return new WebSocket(url);
|
|
3
|
-
}
|
|
4
|
-
function promisifySend(ws) {
|
|
5
|
-
if (ws.sendPromise) {
|
|
6
|
-
return ws;
|
|
7
|
-
}
|
|
8
|
-
ws.sendPromise = (data) => new Promise((resolve, reject) => {
|
|
9
|
-
ws.send(data, (err) => {
|
|
10
|
-
if (err) {
|
|
11
|
-
reject(err);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
resolve();
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
return ws;
|
|
18
|
-
}
|
|
19
|
-
export {
|
|
20
|
-
makeWebSocket,
|
|
21
|
-
promisifySend
|
|
22
|
-
};
|