@reclaimprotocol/attestor-core 5.0.1-beta.2 → 5.0.1-beta.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/resources/attestor-browser.min.mjs +4512 -0
- package/lib/avs/abis/avsDirectoryABI.js +338 -341
- package/lib/avs/abis/delegationABI.js +1 -4
- package/lib/avs/abis/registryABI.js +719 -722
- package/lib/avs/client/create-claim-on-avs.js +129 -157
- package/lib/avs/config.js +18 -24
- package/lib/avs/contracts/ReclaimServiceManager.js +1 -0
- package/lib/avs/contracts/common.js +1 -0
- package/lib/avs/contracts/factories/ReclaimServiceManager__factory.js +1139 -1156
- package/lib/avs/contracts/factories/index.js +4 -4
- package/lib/avs/contracts/index.js +2 -6
- package/lib/avs/types/index.js +1 -0
- package/lib/avs/utils/contracts.js +30 -50
- package/lib/avs/utils/register.js +75 -70
- package/lib/avs/utils/tasks.js +38 -45
- package/lib/client/create-claim.js +402 -431
- package/lib/client/tunnels/make-rpc-tcp-tunnel.js +46 -48
- package/lib/client/tunnels/make-rpc-tls-tunnel.js +125 -121
- package/lib/client/utils/attestor-pool.js +23 -22
- package/lib/client/utils/client-socket.js +86 -109
- package/lib/client/utils/message-handler.js +79 -89
- package/lib/config/index.js +40 -58
- package/lib/external-rpc/benchmark.js +61 -74
- package/lib/external-rpc/event-bus.js +12 -15
- package/lib/external-rpc/handle-incoming-msg.js +216 -225
- package/lib/external-rpc/jsc-polyfills/1.js +70 -68
- package/lib/external-rpc/jsc-polyfills/2.js +17 -12
- package/lib/external-rpc/jsc-polyfills/event.js +10 -15
- package/lib/external-rpc/jsc-polyfills/index.js +2 -2
- package/lib/external-rpc/jsc-polyfills/ws.js +77 -79
- package/lib/external-rpc/setup-browser.js +28 -28
- package/lib/external-rpc/setup-jsc.js +17 -17
- package/lib/external-rpc/types.js +1 -0
- package/lib/external-rpc/utils.js +89 -89
- package/lib/external-rpc/zk.js +55 -50
- package/lib/index.js +2 -6
- package/lib/mechain/abis/governanceABI.js +457 -460
- package/lib/mechain/abis/taskABI.js +502 -505
- package/lib/mechain/client/create-claim-on-mechain.js +24 -29
- package/lib/mechain/constants/index.js +3 -8
- package/lib/mechain/types/index.js +1 -0
- package/lib/proto/api.js +4200 -4087
- package/lib/proto/tee-bundle.js +1261 -1241
- package/lib/providers/http/index.js +616 -603
- package/lib/providers/http/patch-parse5-tree.js +27 -29
- package/lib/providers/http/utils.js +289 -248
- package/lib/providers/index.js +3 -6
- package/lib/server/create-server.js +89 -91
- package/lib/server/handlers/claimTeeBundle.js +231 -211
- package/lib/server/handlers/claimTunnel.js +66 -73
- package/lib/server/handlers/completeClaimOnChain.js +20 -25
- package/lib/server/handlers/createClaimOnChain.js +21 -27
- package/lib/server/handlers/createTaskOnMechain.js +40 -50
- package/lib/server/handlers/createTunnel.js +85 -90
- package/lib/server/handlers/disconnectTunnel.js +4 -7
- package/lib/server/handlers/fetchCertificateBytes.js +37 -53
- package/lib/server/handlers/index.js +21 -24
- package/lib/server/handlers/init.js +27 -28
- package/lib/server/handlers/toprf.js +13 -16
- package/lib/server/socket.js +97 -100
- package/lib/server/tunnels/make-tcp-tunnel.js +161 -186
- package/lib/server/utils/apm.js +32 -25
- package/lib/server/utils/assert-valid-claim-request.js +305 -334
- package/lib/server/utils/config-env.js +2 -2
- package/lib/server/utils/dns.js +12 -18
- package/lib/server/utils/gcp-attestation.js +233 -181
- package/lib/server/utils/generics.d.ts +1 -1
- package/lib/server/utils/generics.js +43 -37
- package/lib/server/utils/iso.js +253 -256
- package/lib/server/utils/keep-alive.js +36 -36
- package/lib/server/utils/nitro-attestation.js +295 -220
- package/lib/server/utils/oprf-raw.js +48 -55
- package/lib/server/utils/process-handshake.js +200 -218
- package/lib/server/utils/proxy-session.js +5 -5
- package/lib/server/utils/tee-oprf-mpc-verification.js +82 -78
- package/lib/server/utils/tee-oprf-verification.js +165 -142
- package/lib/server/utils/tee-transcript-reconstruction.js +176 -129
- package/lib/server/utils/tee-verification.js +397 -334
- package/lib/server/utils/validation.js +30 -37
- package/lib/types/bgp.js +1 -0
- package/lib/types/claims.js +1 -0
- package/lib/types/client.js +1 -0
- package/lib/types/general.js +1 -0
- package/lib/types/handlers.js +1 -0
- package/lib/types/providers.d.ts +3 -2
- package/lib/types/providers.gen.js +9 -15
- package/lib/types/providers.js +1 -0
- package/lib/types/rpc.js +1 -0
- package/lib/types/signatures.d.ts +1 -2
- package/lib/types/signatures.js +1 -0
- package/lib/types/tunnel.js +1 -0
- package/lib/types/zk.js +1 -0
- package/lib/utils/auth.js +54 -66
- package/lib/utils/b64-json.js +15 -15
- package/lib/utils/bgp-listener.js +107 -111
- package/lib/utils/claims.js +89 -80
- package/lib/utils/env.js +13 -17
- package/lib/utils/error.js +43 -47
- package/lib/utils/generics.js +284 -235
- package/lib/utils/http-parser.js +232 -187
- package/lib/utils/logger.js +80 -71
- package/lib/utils/prepare-packets.js +69 -67
- package/lib/utils/redactions.js +163 -121
- package/lib/utils/retries.js +22 -24
- package/lib/utils/signatures/eth.js +29 -28
- package/lib/utils/signatures/index.js +5 -10
- package/lib/utils/socket-base.js +84 -88
- package/lib/utils/tls.js +28 -28
- package/lib/utils/ws.js +19 -19
- package/lib/utils/zk.js +542 -582
- package/package.json +12 -5
- package/lib/external-rpc/global.d.js +0 -0
- package/lib/scripts/build-browser.d.ts +0 -1
- package/lib/scripts/build-jsc.d.ts +0 -1
- package/lib/scripts/build-lib.d.ts +0 -1
- package/lib/scripts/check-avs-registration.d.ts +0 -1
- package/lib/scripts/check-avs-registration.js +0 -28
- package/lib/scripts/fallbacks/crypto.d.ts +0 -1
- package/lib/scripts/fallbacks/crypto.js +0 -4
- package/lib/scripts/fallbacks/empty.d.ts +0 -3
- package/lib/scripts/fallbacks/empty.js +0 -4
- package/lib/scripts/fallbacks/re2.d.ts +0 -1
- package/lib/scripts/fallbacks/re2.js +0 -7
- package/lib/scripts/fallbacks/snarkjs.d.ts +0 -1
- package/lib/scripts/fallbacks/snarkjs.js +0 -10
- package/lib/scripts/fallbacks/stwo.d.ts +0 -6
- package/lib/scripts/fallbacks/stwo.js +0 -159
- package/lib/scripts/generate-provider-types.d.ts +0 -5
- package/lib/scripts/generate-provider-types.js +0 -101
- package/lib/scripts/generate-receipt.d.ts +0 -9
- package/lib/scripts/generate-receipt.js +0 -101
- package/lib/scripts/generate-toprf-keys.d.ts +0 -1
- package/lib/scripts/generate-toprf-keys.js +0 -24
- package/lib/scripts/jsc-cli-rpc.d.ts +0 -1
- package/lib/scripts/jsc-cli-rpc.js +0 -35
- package/lib/scripts/register-avs-operator.d.ts +0 -1
- package/lib/scripts/register-avs-operator.js +0 -3
- package/lib/scripts/start-server.d.ts +0 -1
- package/lib/scripts/start-server.js +0 -11
- package/lib/scripts/update-avs-metadata.d.ts +0 -1
- package/lib/scripts/update-avs-metadata.js +0 -20
- package/lib/scripts/utils.d.ts +0 -1
- package/lib/scripts/utils.js +0 -10
- package/lib/scripts/whitelist-operator.d.ts +0 -1
- package/lib/scripts/whitelist-operator.js +0 -16
|
@@ -1,69 +1,71 @@
|
|
|
1
|
-
import { concatenateUint8Arrays, crypto } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
}
|
|
1
|
+
import { concatenateUint8Arrays, crypto } from '@reclaimprotocol/tls';
|
|
2
|
+
import { TranscriptMessageSenderType } from "../proto/api.js";
|
|
3
|
+
import { makeZkProofGenerator } from "./zk.js";
|
|
4
|
+
/**
|
|
5
|
+
* Prepares the packets for reveal to the server
|
|
6
|
+
* according to the specified reveal type
|
|
7
|
+
*/
|
|
8
|
+
export async function preparePacketsForReveal(tlsTranscript, reveals, { onZkProgress, ...opts }) {
|
|
9
|
+
const transcript = [];
|
|
10
|
+
const proofGenerator = await makeZkProofGenerator(opts);
|
|
11
|
+
let zkPacketsDone = 0;
|
|
12
|
+
await Promise.all(tlsTranscript.map(async ({ message, sender }, i) => {
|
|
13
|
+
const msg = {
|
|
14
|
+
sender: sender === 'client'
|
|
15
|
+
? TranscriptMessageSenderType.TRANSCRIPT_MESSAGE_SENDER_TYPE_CLIENT
|
|
16
|
+
: TranscriptMessageSenderType.TRANSCRIPT_MESSAGE_SENDER_TYPE_SERVER,
|
|
17
|
+
message: message.data,
|
|
18
|
+
reveal: undefined
|
|
29
19
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
reveal.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
20
|
+
transcript.push(msg);
|
|
21
|
+
const reveal = reveals.get(message);
|
|
22
|
+
if (!reveal || message.type === 'plaintext') {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
switch (reveal?.type) {
|
|
26
|
+
case 'complete':
|
|
27
|
+
msg.reveal = {
|
|
28
|
+
directReveal: {
|
|
29
|
+
key: await crypto.exportKey(message.encKey),
|
|
30
|
+
iv: message.fixedIv,
|
|
31
|
+
recordNumber: message.recordNumber,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
break;
|
|
35
|
+
case 'zk': {
|
|
36
|
+
// the redacted section can be smaller than the actual
|
|
37
|
+
// plaintext encrypted, in case of TLS1.3 as it has a
|
|
38
|
+
// content type suffix
|
|
39
|
+
reveal.redactedPlaintext = concatenateUint8Arrays([
|
|
40
|
+
reveal.redactedPlaintext,
|
|
41
|
+
message.plaintext.slice(reveal.redactedPlaintext.length)
|
|
42
|
+
]);
|
|
43
|
+
// Capture oprfRawMarkers for server-side OPRF computation
|
|
44
|
+
const oprfRawMarkers = reveal.oprfRawMarkers?.map(m => ({
|
|
45
|
+
dataLocation: m.dataLocation
|
|
46
|
+
})) || [];
|
|
47
|
+
// Capture overshoot from previous block's oprf-raw marker
|
|
48
|
+
const overshotOprfRawLength = reveal.overshotOprfRawFromPrevBlock?.length ?? 0;
|
|
49
|
+
await proofGenerator.addPacketToProve(message, reveal, (proofs, toprfs) => (msg.reveal = {
|
|
50
|
+
zkReveal: { proofs, toprfs, oprfRawMarkers, overshotOprfRawLength }
|
|
51
|
+
}), () => {
|
|
52
|
+
const next = tlsTranscript
|
|
53
|
+
.slice(i + 1)
|
|
54
|
+
.find(t => t.sender === sender);
|
|
55
|
+
return next?.message;
|
|
56
|
+
});
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
default:
|
|
60
|
+
// no reveal
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}));
|
|
64
|
+
const zkPacketsTotal = proofGenerator.getTotalChunksToProve();
|
|
65
|
+
onZkProgress?.(zkPacketsDone, zkPacketsTotal);
|
|
66
|
+
await proofGenerator.generateProofs(() => {
|
|
67
|
+
zkPacketsDone += 1;
|
|
68
|
+
onZkProgress?.(zkPacketsDone, zkPacketsTotal);
|
|
69
|
+
});
|
|
70
|
+
return transcript;
|
|
66
71
|
}
|
|
67
|
-
export {
|
|
68
|
-
preparePacketsForReveal
|
|
69
|
-
};
|
package/lib/utils/redactions.js
CHANGED
|
@@ -1,135 +1,177 @@
|
|
|
1
|
-
import { base64Encode } from
|
|
2
|
-
import { concatenateUint8Arrays } from
|
|
3
|
-
const REDACTION_CHAR =
|
|
4
|
-
const REDACTION_CHAR_CODE = REDACTION_CHAR.charCodeAt(0);
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { base64Encode } from '@bufbuild/protobuf/wire';
|
|
2
|
+
import { concatenateUint8Arrays } from '@reclaimprotocol/tls';
|
|
3
|
+
export const REDACTION_CHAR = '*';
|
|
4
|
+
export const REDACTION_CHAR_CODE = REDACTION_CHAR.charCodeAt(0);
|
|
5
|
+
/**
|
|
6
|
+
* Check if a redacted string is congruent with the original string.
|
|
7
|
+
* @param redacted the redacted content, redacted content is replaced by '*'
|
|
8
|
+
* @param original the original content
|
|
9
|
+
*/
|
|
10
|
+
export function isRedactionCongruent(redacted, original) {
|
|
11
|
+
for (let i = 0; i < redacted.length; i++) {
|
|
12
|
+
const element = redacted[i];
|
|
13
|
+
const areSame = element === original[i]
|
|
14
|
+
|| (typeof element === 'string' && element === REDACTION_CHAR)
|
|
15
|
+
|| (typeof element === 'number' && element === REDACTION_CHAR_CODE);
|
|
16
|
+
if (!areSame) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
11
19
|
}
|
|
12
|
-
|
|
13
|
-
return true;
|
|
20
|
+
return true;
|
|
14
21
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Is the string fully redacted?
|
|
24
|
+
*/
|
|
25
|
+
export function isFullyRedacted(redacted) {
|
|
26
|
+
for (const element of redacted) {
|
|
27
|
+
if (element !== REDACTION_CHAR
|
|
28
|
+
&& element !== REDACTION_CHAR_CODE) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
19
31
|
}
|
|
20
|
-
|
|
21
|
-
return true;
|
|
32
|
+
return true;
|
|
22
33
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Given some plaintext blocks and a redaction function, return the blocks that
|
|
36
|
+
* need to be revealed to the other party
|
|
37
|
+
*
|
|
38
|
+
* Use case: we get the response for a request in several blocks, and want to redact
|
|
39
|
+
* pieces that go through multiple blocks. We can use this function to get the
|
|
40
|
+
* blocks that need to be revealed to the other party
|
|
41
|
+
*
|
|
42
|
+
* @example if we received ["secret is 12","345","678. Thanks"]. We'd want
|
|
43
|
+
* to redact the "12345678" and reveal the rest. We'd pass in the blocks and
|
|
44
|
+
* the redact function will return the redactions, namely [10,19].
|
|
45
|
+
* The function will return the blocks ["secret is **","***. Thanks"].
|
|
46
|
+
* The middle block is fully redacted, so it's not returned
|
|
47
|
+
*
|
|
48
|
+
* @param blocks blocks to reveal
|
|
49
|
+
* @param redact function that returns the redactions
|
|
50
|
+
* @returns blocks to reveal
|
|
51
|
+
*/
|
|
52
|
+
export async function getBlocksToReveal(blocks, redact, performOprf) {
|
|
53
|
+
const slicesWithReveal = blocks.map(block => ({
|
|
54
|
+
block,
|
|
55
|
+
// copy the plaintext to avoid mutating the original
|
|
56
|
+
redactedPlaintext: new Uint8Array(block.plaintext)
|
|
57
|
+
}));
|
|
58
|
+
const total = concatenateUint8Arrays(blocks.map(b => b.plaintext));
|
|
59
|
+
const redactions = redact(total);
|
|
60
|
+
if (!redactions.length) {
|
|
61
|
+
return 'all';
|
|
44
62
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
63
|
+
let blockIdx = 0;
|
|
64
|
+
let cursorInBlock = 0;
|
|
65
|
+
let cursor = 0;
|
|
66
|
+
for (const redaction of redactions) {
|
|
67
|
+
await redactBlocks(redaction);
|
|
68
|
+
}
|
|
69
|
+
// only reveal blocks that have some data to reveal,
|
|
70
|
+
// or are completely plaintext
|
|
71
|
+
return slicesWithReveal
|
|
72
|
+
.filter(s => !isFullyRedacted(s.redactedPlaintext));
|
|
73
|
+
async function redactBlocks(slice) {
|
|
74
|
+
while (cursor < slice.fromIndex) {
|
|
75
|
+
advance();
|
|
55
76
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
77
|
+
// Handle oprf-raw: don't redact, don't call OPRF, just mark position
|
|
78
|
+
// Server will compute OPRF and do replacement
|
|
79
|
+
if (slice.hash === 'oprf-raw') {
|
|
80
|
+
const startBlockIdx = blockIdx;
|
|
81
|
+
const startCursorInBlock = cursorInBlock;
|
|
82
|
+
const totalLength = slice.toIndex - slice.fromIndex;
|
|
83
|
+
// Set marker on first block
|
|
84
|
+
const block = slicesWithReveal[blockIdx];
|
|
85
|
+
block.oprfRawMarkers ||= [];
|
|
86
|
+
block.oprfRawMarkers.push({
|
|
87
|
+
dataLocation: {
|
|
88
|
+
fromIndex: startCursorInBlock,
|
|
89
|
+
length: totalLength
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
// Advance cursor past this slice, tracking overshoot
|
|
93
|
+
let overshootLen = 0;
|
|
94
|
+
while (cursor < slice.toIndex) {
|
|
95
|
+
if (blockIdx !== startBlockIdx) {
|
|
96
|
+
overshootLen += 1;
|
|
97
|
+
}
|
|
98
|
+
advance();
|
|
99
|
+
}
|
|
100
|
+
// If data overshot into next block, mark it
|
|
101
|
+
if (overshootLen) {
|
|
102
|
+
slicesWithReveal[blockIdx]
|
|
103
|
+
.overshotOprfRawFromPrevBlock = { length: overshootLen };
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
61
106
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
107
|
+
if (slice.hash) {
|
|
108
|
+
const plaintext = total.slice(slice.fromIndex, slice.toIndex);
|
|
109
|
+
const { nullifier, responses, mask } = await performOprf(plaintext);
|
|
110
|
+
// set the TOPRF claim on the first blocks this
|
|
111
|
+
// redaction covers
|
|
112
|
+
const toprf = {
|
|
113
|
+
nullifier,
|
|
114
|
+
responses,
|
|
115
|
+
dataLocation: {
|
|
116
|
+
fromIndex: cursorInBlock,
|
|
117
|
+
length: slice.toIndex - slice.fromIndex
|
|
118
|
+
},
|
|
119
|
+
mask,
|
|
120
|
+
plaintext
|
|
121
|
+
};
|
|
122
|
+
const startBlockIdx = blockIdx;
|
|
123
|
+
const block = slicesWithReveal[blockIdx];
|
|
124
|
+
block.toprfs ||= [];
|
|
125
|
+
block.toprfs.push(toprf);
|
|
126
|
+
const nullifierStr = binaryHashToStr(nullifier, toprf.dataLocation.length);
|
|
127
|
+
let i = 0;
|
|
128
|
+
let overshootLen = 0;
|
|
129
|
+
while (cursor < slice.toIndex) {
|
|
130
|
+
if (blockIdx !== startBlockIdx) {
|
|
131
|
+
overshootLen += 1;
|
|
132
|
+
}
|
|
133
|
+
slicesWithReveal[blockIdx].redactedPlaintext[cursorInBlock]
|
|
134
|
+
= nullifierStr.charCodeAt(i);
|
|
135
|
+
advance();
|
|
136
|
+
i += 1;
|
|
137
|
+
}
|
|
138
|
+
if (overshootLen) {
|
|
139
|
+
slicesWithReveal[blockIdx]
|
|
140
|
+
.overshotToprfFromPrevBlock = { length: overshootLen };
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
while (cursor < slice.toIndex) {
|
|
144
|
+
slicesWithReveal[blockIdx]
|
|
145
|
+
.redactedPlaintext[cursorInBlock] = REDACTION_CHAR_CODE;
|
|
146
|
+
advance();
|
|
92
147
|
}
|
|
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
148
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
149
|
+
function advance() {
|
|
150
|
+
cursor += 1;
|
|
151
|
+
cursorInBlock += 1;
|
|
152
|
+
if (cursorInBlock >= blocks[blockIdx].plaintext.length) {
|
|
153
|
+
blockIdx += 1;
|
|
154
|
+
cursorInBlock = 0;
|
|
155
|
+
}
|
|
112
156
|
}
|
|
113
|
-
}
|
|
114
157
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
158
|
+
/**
|
|
159
|
+
* Redact the following slices from the total
|
|
160
|
+
*/
|
|
161
|
+
export function redactSlices(total, slices) {
|
|
162
|
+
const redacted = new Uint8Array(total);
|
|
163
|
+
for (const slice of slices) {
|
|
164
|
+
for (let i = slice.fromIndex; i < slice.toIndex; i++) {
|
|
165
|
+
redacted[i] = REDACTION_CHAR_CODE;
|
|
166
|
+
}
|
|
120
167
|
}
|
|
121
|
-
|
|
122
|
-
return redacted;
|
|
168
|
+
return redacted;
|
|
123
169
|
}
|
|
124
|
-
|
|
125
|
-
|
|
170
|
+
/**
|
|
171
|
+
* Converts the binary hash to an ASCII string of the expected length.
|
|
172
|
+
* If the hash is shorter than the expected length, it will be padded with
|
|
173
|
+
* '0' characters. If it's longer, it will be truncated.
|
|
174
|
+
*/
|
|
175
|
+
export function binaryHashToStr(hash, expLength) {
|
|
176
|
+
return base64Encode(hash).padEnd(expLength, '0').slice(0, expLength);
|
|
126
177
|
}
|
|
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
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Execute a function, and upon failure -- retry
|
|
3
|
+
* based on specified options.
|
|
4
|
+
*/
|
|
5
|
+
export async function executeWithRetries(code, { maxRetries = 3, shouldRetry, logger, }) {
|
|
6
|
+
let retries = 0;
|
|
7
|
+
while (retries < maxRetries) {
|
|
8
|
+
try {
|
|
9
|
+
const result = await code(retries);
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
catch (err) {
|
|
13
|
+
retries += 1;
|
|
14
|
+
if (retries >= maxRetries) {
|
|
15
|
+
throw err;
|
|
16
|
+
}
|
|
17
|
+
if (!shouldRetry(err)) {
|
|
18
|
+
throw err;
|
|
19
|
+
}
|
|
20
|
+
logger.info({ err, retries }, 'retrying failed operation');
|
|
21
|
+
}
|
|
20
22
|
}
|
|
21
|
-
|
|
22
|
-
throw new Error("retries exhausted");
|
|
23
|
+
throw new Error('retries exhausted');
|
|
23
24
|
}
|
|
24
|
-
export {
|
|
25
|
-
executeWithRetries
|
|
26
|
-
};
|
|
@@ -1,31 +1,32 @@
|
|
|
1
|
-
import { computeAddress, getBytes, hexlify, SigningKey, verifyMessage, Wallet } from
|
|
2
|
-
const ETH_SIGNATURE_PROVIDER = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
import { computeAddress, getBytes, hexlify, SigningKey, verifyMessage, Wallet } from 'ethers';
|
|
2
|
+
export const ETH_SIGNATURE_PROVIDER = {
|
|
3
|
+
getPublicKey(privateKey) {
|
|
4
|
+
const pub = SigningKey.computePublicKey(privateKey, true);
|
|
5
|
+
return getBytes(pub);
|
|
6
|
+
},
|
|
7
|
+
getAddress(publicKey) {
|
|
8
|
+
// computeAddress in v6 expects hex string
|
|
9
|
+
const pubKeyHex = typeof publicKey === 'string' ? publicKey : hexlify(publicKey);
|
|
10
|
+
return computeAddress(pubKeyHex).toLowerCase();
|
|
11
|
+
},
|
|
12
|
+
async sign(data, privateKey) {
|
|
13
|
+
const wallet = getEthWallet(privateKey);
|
|
14
|
+
const signature = await wallet.signMessage(data);
|
|
15
|
+
return getBytes(signature);
|
|
16
|
+
},
|
|
17
|
+
async verify(data, signature, addressBytes) {
|
|
18
|
+
const address = typeof addressBytes === 'string'
|
|
19
|
+
? addressBytes
|
|
20
|
+
: hexlify(addressBytes);
|
|
21
|
+
// verifyMessage in v6 expects SignatureLike (hex string)
|
|
22
|
+
const signatureHex = typeof signature === 'string' ? signature : hexlify(signature);
|
|
23
|
+
const signerAddress = verifyMessage(data, signatureHex);
|
|
24
|
+
return signerAddress.toLowerCase() === address.toLowerCase();
|
|
25
|
+
}
|
|
22
26
|
};
|
|
23
27
|
function getEthWallet(privateKey) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
if (!privateKey) {
|
|
29
|
+
throw new Error('Private key missing');
|
|
30
|
+
}
|
|
31
|
+
return new Wallet(privateKey);
|
|
28
32
|
}
|
|
29
|
-
export {
|
|
30
|
-
ETH_SIGNATURE_PROVIDER
|
|
31
|
-
};
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { ServiceSignatureType } from "../../proto/api.js";
|
|
2
|
-
import { ETH_SIGNATURE_PROVIDER } from "
|
|
3
|
-
const SIGNATURES = {
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
const SelectedServiceSignatureType = ServiceSignatureType.SERVICE_SIGNATURE_TYPE_ETH;
|
|
7
|
-
const SelectedServiceSignature = SIGNATURES[SelectedServiceSignatureType];
|
|
8
|
-
export {
|
|
9
|
-
SIGNATURES,
|
|
10
|
-
SelectedServiceSignature,
|
|
11
|
-
SelectedServiceSignatureType
|
|
2
|
+
import { ETH_SIGNATURE_PROVIDER } from "./eth.js";
|
|
3
|
+
export const SIGNATURES = {
|
|
4
|
+
[ServiceSignatureType.SERVICE_SIGNATURE_TYPE_ETH]: ETH_SIGNATURE_PROVIDER,
|
|
12
5
|
};
|
|
6
|
+
export const SelectedServiceSignatureType = ServiceSignatureType.SERVICE_SIGNATURE_TYPE_ETH;
|
|
7
|
+
export const SelectedServiceSignature = SIGNATURES[SelectedServiceSignatureType];
|