@cofhe/sdk 0.2.1 → 0.3.0
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/CHANGELOG.md +28 -0
- package/core/baseBuilder.ts +18 -18
- package/core/client.test.ts +58 -55
- package/core/client.ts +50 -30
- package/core/clientTypes.ts +21 -17
- package/core/config.test.ts +32 -33
- package/core/config.ts +47 -48
- package/core/consts.ts +6 -2
- package/core/decrypt/{MockQueryDecrypterAbi.ts → MockThresholdNetworkAbi.ts} +71 -21
- package/core/decrypt/cofheMocksDecryptForTx.ts +142 -0
- package/core/decrypt/{cofheMocksSealOutput.ts → cofheMocksDecryptForView.ts} +12 -12
- package/core/decrypt/decryptForTxBuilder.ts +340 -0
- package/core/decrypt/{decryptHandleBuilder.ts → decryptForViewBuilder.ts} +75 -42
- package/core/decrypt/tnDecrypt.ts +232 -0
- package/core/decrypt/tnSealOutputV1.ts +5 -5
- package/core/decrypt/tnSealOutputV2.ts +27 -27
- package/core/encrypt/cofheMocksZkVerifySign.ts +15 -15
- package/core/encrypt/encryptInputsBuilder.test.ts +57 -61
- package/core/encrypt/encryptInputsBuilder.ts +65 -42
- package/core/encrypt/zkPackProveVerify.ts +11 -11
- package/core/error.ts +18 -18
- package/core/fetchKeys.test.ts +3 -3
- package/core/fetchKeys.ts +3 -3
- package/core/index.ts +14 -11
- package/core/utils.ts +10 -10
- package/dist/{chunk-I5WFEYXX.js → chunk-2TPSCOW3.js} +791 -209
- package/dist/{chunk-R3B5TMVX.js → chunk-NWDKXBIP.js} +3 -2
- package/dist/{clientTypes-RqkgkV2i.d.ts → clientTypes-6aTZPQ_4.d.ts} +204 -85
- package/dist/{clientTypes-e4filDzK.d.cts → clientTypes-Bhq7pCSA.d.cts} +204 -85
- package/dist/core.cjs +799 -214
- package/dist/core.d.cts +25 -23
- package/dist/core.d.ts +25 -23
- package/dist/core.js +2 -2
- package/dist/node.cjs +748 -165
- package/dist/node.d.cts +10 -10
- package/dist/node.d.ts +10 -10
- package/dist/node.js +7 -7
- package/dist/permits.js +1 -1
- package/dist/web.cjs +751 -168
- package/dist/web.d.cts +11 -11
- package/dist/web.d.ts +11 -11
- package/dist/web.js +9 -9
- package/node/client.test.ts +34 -34
- package/node/config.test.ts +11 -11
- package/node/encryptInputs.test.ts +29 -29
- package/node/index.ts +15 -15
- package/package.json +1 -1
- package/web/client.web.test.ts +34 -34
- package/web/config.web.test.ts +11 -11
- package/web/encryptInputs.web.test.ts +29 -29
- package/web/index.ts +19 -19
- package/web/worker.builder.web.test.ts +28 -28
- package/web/worker.config.web.test.ts +47 -47
- package/web/worker.output.web.test.ts +10 -10
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { type Permission } from '@/permits';
|
|
2
|
+
|
|
3
|
+
import { CofheError, CofheErrorCode } from '../error.js';
|
|
4
|
+
|
|
5
|
+
type TnDecryptResponse = {
|
|
6
|
+
// TN returns bytes in big-endian order, e.g. [0,0,0,42]
|
|
7
|
+
decrypted: number[];
|
|
8
|
+
signature: string;
|
|
9
|
+
encryption_type: number;
|
|
10
|
+
error_message: string | null;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function normalizeSignature(signature: unknown): string {
|
|
14
|
+
if (typeof signature !== 'string') {
|
|
15
|
+
throw new CofheError({
|
|
16
|
+
code: CofheErrorCode.DecryptReturnedNull,
|
|
17
|
+
message: 'decrypt response missing signature',
|
|
18
|
+
context: {
|
|
19
|
+
signature,
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const trimmed = signature.trim();
|
|
25
|
+
if (trimmed.length === 0) {
|
|
26
|
+
throw new CofheError({
|
|
27
|
+
code: CofheErrorCode.DecryptReturnedNull,
|
|
28
|
+
message: 'decrypt response returned empty signature',
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// SDK uses "no-0x" signatures in mocks/tests; normalize to that format.
|
|
33
|
+
return trimmed.startsWith('0x') ? trimmed.slice(2) : trimmed;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function parseDecryptedBytesToBigInt(decrypted: unknown): bigint {
|
|
37
|
+
if (!Array.isArray(decrypted)) {
|
|
38
|
+
throw new CofheError({
|
|
39
|
+
code: CofheErrorCode.DecryptReturnedNull,
|
|
40
|
+
message: 'decrypt response field <decrypted> must be a byte array',
|
|
41
|
+
context: {
|
|
42
|
+
decrypted,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (decrypted.length === 0) {
|
|
48
|
+
throw new CofheError({
|
|
49
|
+
code: CofheErrorCode.DecryptReturnedNull,
|
|
50
|
+
message: 'decrypt response field <decrypted> was an empty byte array',
|
|
51
|
+
context: {
|
|
52
|
+
decrypted,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let hex = '';
|
|
58
|
+
for (const b of decrypted as unknown[]) {
|
|
59
|
+
if (typeof b !== 'number' || !Number.isInteger(b) || b < 0 || b > 255) {
|
|
60
|
+
throw new CofheError({
|
|
61
|
+
code: CofheErrorCode.DecryptReturnedNull,
|
|
62
|
+
message: 'decrypt response field <decrypted> contained a non-byte value',
|
|
63
|
+
context: {
|
|
64
|
+
badElement: b,
|
|
65
|
+
decrypted,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
hex += b.toString(16).padStart(2, '0');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return BigInt(`0x${hex}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function assertTnDecryptResponse(value: unknown): TnDecryptResponse {
|
|
76
|
+
if (value == null || typeof value !== 'object') {
|
|
77
|
+
throw new CofheError({
|
|
78
|
+
code: CofheErrorCode.DecryptFailed,
|
|
79
|
+
message: 'decrypt response must be a JSON object',
|
|
80
|
+
context: {
|
|
81
|
+
value,
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const v = value as Record<string, unknown>;
|
|
87
|
+
const decrypted = v.decrypted;
|
|
88
|
+
const signature = v.signature;
|
|
89
|
+
const encryptionType = v.encryption_type;
|
|
90
|
+
const errorMessage = v.error_message;
|
|
91
|
+
|
|
92
|
+
if (!Array.isArray(decrypted)) {
|
|
93
|
+
throw new CofheError({
|
|
94
|
+
code: CofheErrorCode.DecryptReturnedNull,
|
|
95
|
+
message: 'decrypt response missing <decrypted> byte array',
|
|
96
|
+
context: { decryptResponse: value },
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (typeof signature !== 'string') {
|
|
100
|
+
throw new CofheError({
|
|
101
|
+
code: CofheErrorCode.DecryptReturnedNull,
|
|
102
|
+
message: 'decrypt response missing <signature> string',
|
|
103
|
+
context: { decryptResponse: value },
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (typeof encryptionType !== 'number') {
|
|
107
|
+
throw new CofheError({
|
|
108
|
+
code: CofheErrorCode.DecryptFailed,
|
|
109
|
+
message: 'decrypt response missing <encryption_type> number',
|
|
110
|
+
context: { decryptResponse: value },
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
if (!(typeof errorMessage === 'string' || errorMessage === null)) {
|
|
114
|
+
throw new CofheError({
|
|
115
|
+
code: CofheErrorCode.DecryptFailed,
|
|
116
|
+
message: 'decrypt response field <error_message> must be string or null',
|
|
117
|
+
context: { decryptResponse: value },
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
decrypted: decrypted as number[],
|
|
123
|
+
signature,
|
|
124
|
+
encryption_type: encryptionType,
|
|
125
|
+
error_message: errorMessage,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export async function tnDecrypt(
|
|
130
|
+
ctHash: bigint,
|
|
131
|
+
chainId: number,
|
|
132
|
+
permission: Permission | null,
|
|
133
|
+
thresholdNetworkUrl: string
|
|
134
|
+
): Promise<{ decryptedValue: bigint; signature: string }> {
|
|
135
|
+
const body: {
|
|
136
|
+
ct_tempkey: string;
|
|
137
|
+
host_chain_id: number;
|
|
138
|
+
permit?: Permission;
|
|
139
|
+
} = {
|
|
140
|
+
ct_tempkey: ctHash.toString(16).padStart(64, '0'),
|
|
141
|
+
host_chain_id: chainId,
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
if (permission) {
|
|
145
|
+
body.permit = permission;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
let response: Response;
|
|
149
|
+
try {
|
|
150
|
+
response = await fetch(`${thresholdNetworkUrl}/decrypt`, {
|
|
151
|
+
method: 'POST',
|
|
152
|
+
headers: {
|
|
153
|
+
'Content-Type': 'application/json',
|
|
154
|
+
},
|
|
155
|
+
body: JSON.stringify(body),
|
|
156
|
+
});
|
|
157
|
+
} catch (e) {
|
|
158
|
+
throw new CofheError({
|
|
159
|
+
code: CofheErrorCode.DecryptFailed,
|
|
160
|
+
message: `decrypt request failed`,
|
|
161
|
+
hint: 'Ensure the threshold network URL is valid and reachable.',
|
|
162
|
+
cause: e instanceof Error ? e : undefined,
|
|
163
|
+
context: {
|
|
164
|
+
thresholdNetworkUrl,
|
|
165
|
+
body,
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const responseText = await response.text();
|
|
171
|
+
|
|
172
|
+
// Even on non-200 responses, TN may return JSON with { error_message }.
|
|
173
|
+
if (!response.ok) {
|
|
174
|
+
let errorMessage = response.statusText || `HTTP ${response.status}`;
|
|
175
|
+
try {
|
|
176
|
+
const errorBody = JSON.parse(responseText) as Record<string, unknown>;
|
|
177
|
+
const maybeMessage = (errorBody.error_message || errorBody.message) as unknown;
|
|
178
|
+
if (typeof maybeMessage === 'string' && maybeMessage.length > 0) errorMessage = maybeMessage;
|
|
179
|
+
} catch {
|
|
180
|
+
const trimmed = responseText.trim();
|
|
181
|
+
if (trimmed.length > 0) errorMessage = trimmed;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
throw new CofheError({
|
|
185
|
+
code: CofheErrorCode.DecryptFailed,
|
|
186
|
+
message: `decrypt request failed: ${errorMessage}`,
|
|
187
|
+
hint: 'Check the threshold network URL and request parameters.',
|
|
188
|
+
context: {
|
|
189
|
+
thresholdNetworkUrl,
|
|
190
|
+
status: response.status,
|
|
191
|
+
statusText: response.statusText,
|
|
192
|
+
body,
|
|
193
|
+
responseText,
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
let rawJson: unknown;
|
|
199
|
+
try {
|
|
200
|
+
rawJson = JSON.parse(responseText) as unknown;
|
|
201
|
+
} catch (e) {
|
|
202
|
+
throw new CofheError({
|
|
203
|
+
code: CofheErrorCode.DecryptFailed,
|
|
204
|
+
message: `Failed to parse decrypt response`,
|
|
205
|
+
cause: e instanceof Error ? e : undefined,
|
|
206
|
+
context: {
|
|
207
|
+
thresholdNetworkUrl,
|
|
208
|
+
body,
|
|
209
|
+
responseText,
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const decryptResponse = assertTnDecryptResponse(rawJson);
|
|
215
|
+
|
|
216
|
+
if (decryptResponse.error_message) {
|
|
217
|
+
throw new CofheError({
|
|
218
|
+
code: CofheErrorCode.DecryptFailed,
|
|
219
|
+
message: `decrypt request failed: ${decryptResponse.error_message}`,
|
|
220
|
+
context: {
|
|
221
|
+
thresholdNetworkUrl,
|
|
222
|
+
body,
|
|
223
|
+
decryptResponse,
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const decryptedValue = parseDecryptedBytesToBigInt(decryptResponse.decrypted);
|
|
229
|
+
const signature = normalizeSignature(decryptResponse.signature);
|
|
230
|
+
|
|
231
|
+
return { decryptedValue, signature };
|
|
232
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Permission, type EthEncryptedData } from '@/permits';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { CofheError, CofheErrorCode } from '../error.js';
|
|
4
4
|
|
|
5
5
|
export async function tnSealOutputV1(
|
|
6
6
|
ctHash: bigint,
|
|
@@ -31,8 +31,8 @@ export async function tnSealOutputV1(
|
|
|
31
31
|
sealed = sealOutputResult.sealed;
|
|
32
32
|
errorMessage = sealOutputResult.error_message;
|
|
33
33
|
} catch (e) {
|
|
34
|
-
throw new
|
|
35
|
-
code:
|
|
34
|
+
throw new CofheError({
|
|
35
|
+
code: CofheErrorCode.SealOutputFailed,
|
|
36
36
|
message: `sealOutput request failed`,
|
|
37
37
|
hint: 'Ensure the threshold network URL is valid.',
|
|
38
38
|
cause: e instanceof Error ? e : undefined,
|
|
@@ -44,8 +44,8 @@ export async function tnSealOutputV1(
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
if (sealed == null) {
|
|
47
|
-
throw new
|
|
48
|
-
code:
|
|
47
|
+
throw new CofheError({
|
|
48
|
+
code: CofheErrorCode.SealOutputReturnedNull,
|
|
49
49
|
message: `sealOutput request returned no data | Caused by: ${errorMessage}`,
|
|
50
50
|
context: {
|
|
51
51
|
thresholdNetworkUrl,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Permission, type EthEncryptedData } from '@/permits';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { CofheError, CofheErrorCode } from '../error.js';
|
|
4
4
|
|
|
5
5
|
// Polling configuration
|
|
6
6
|
const POLL_INTERVAL_MS = 1000; // 1 second
|
|
@@ -39,8 +39,8 @@ function numberArrayToUint8Array(arr: number[]): Uint8Array {
|
|
|
39
39
|
*/
|
|
40
40
|
function convertSealedData(sealed: SealOutputStatusResponse['sealed']): EthEncryptedData {
|
|
41
41
|
if (!sealed) {
|
|
42
|
-
throw new
|
|
43
|
-
code:
|
|
42
|
+
throw new CofheError({
|
|
43
|
+
code: CofheErrorCode.SealOutputReturnedNull,
|
|
44
44
|
message: 'Sealed data is missing from completed response',
|
|
45
45
|
});
|
|
46
46
|
}
|
|
@@ -77,8 +77,8 @@ async function submitSealOutputRequest(
|
|
|
77
77
|
body: JSON.stringify(body),
|
|
78
78
|
});
|
|
79
79
|
} catch (e) {
|
|
80
|
-
throw new
|
|
81
|
-
code:
|
|
80
|
+
throw new CofheError({
|
|
81
|
+
code: CofheErrorCode.SealOutputFailed,
|
|
82
82
|
message: `sealOutput request failed`,
|
|
83
83
|
hint: 'Ensure the threshold network URL is valid and reachable.',
|
|
84
84
|
cause: e instanceof Error ? e : undefined,
|
|
@@ -100,8 +100,8 @@ async function submitSealOutputRequest(
|
|
|
100
100
|
errorMessage = response.statusText || errorMessage;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
throw new
|
|
104
|
-
code:
|
|
103
|
+
throw new CofheError({
|
|
104
|
+
code: CofheErrorCode.SealOutputFailed,
|
|
105
105
|
message: `sealOutput request failed: ${errorMessage}`,
|
|
106
106
|
hint: 'Check the threshold network URL and request parameters.',
|
|
107
107
|
context: {
|
|
@@ -117,8 +117,8 @@ async function submitSealOutputRequest(
|
|
|
117
117
|
try {
|
|
118
118
|
submitResponse = (await response.json()) as SealOutputSubmitResponse;
|
|
119
119
|
} catch (e) {
|
|
120
|
-
throw new
|
|
121
|
-
code:
|
|
120
|
+
throw new CofheError({
|
|
121
|
+
code: CofheErrorCode.SealOutputFailed,
|
|
122
122
|
message: `Failed to parse sealOutput submit response`,
|
|
123
123
|
cause: e instanceof Error ? e : undefined,
|
|
124
124
|
context: {
|
|
@@ -129,8 +129,8 @@ async function submitSealOutputRequest(
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
if (!submitResponse.request_id) {
|
|
132
|
-
throw new
|
|
133
|
-
code:
|
|
132
|
+
throw new CofheError({
|
|
133
|
+
code: CofheErrorCode.SealOutputFailed,
|
|
134
134
|
message: `sealOutput submit response missing request_id`,
|
|
135
135
|
context: {
|
|
136
136
|
thresholdNetworkUrl,
|
|
@@ -153,8 +153,8 @@ async function pollSealOutputStatus(thresholdNetworkUrl: string, requestId: stri
|
|
|
153
153
|
while (!completed) {
|
|
154
154
|
// Check timeout
|
|
155
155
|
if (Date.now() - startTime > POLL_TIMEOUT_MS) {
|
|
156
|
-
throw new
|
|
157
|
-
code:
|
|
156
|
+
throw new CofheError({
|
|
157
|
+
code: CofheErrorCode.SealOutputFailed,
|
|
158
158
|
message: `sealOutput polling timed out after ${POLL_TIMEOUT_MS}ms`,
|
|
159
159
|
hint: 'The request may still be processing. Try again later.',
|
|
160
160
|
context: {
|
|
@@ -174,8 +174,8 @@ async function pollSealOutputStatus(thresholdNetworkUrl: string, requestId: stri
|
|
|
174
174
|
},
|
|
175
175
|
});
|
|
176
176
|
} catch (e) {
|
|
177
|
-
throw new
|
|
178
|
-
code:
|
|
177
|
+
throw new CofheError({
|
|
178
|
+
code: CofheErrorCode.SealOutputFailed,
|
|
179
179
|
message: `sealOutput status poll failed`,
|
|
180
180
|
hint: 'Ensure the threshold network URL is valid and reachable.',
|
|
181
181
|
cause: e instanceof Error ? e : undefined,
|
|
@@ -188,8 +188,8 @@ async function pollSealOutputStatus(thresholdNetworkUrl: string, requestId: stri
|
|
|
188
188
|
|
|
189
189
|
// Handle 404 - request not found
|
|
190
190
|
if (response.status === 404) {
|
|
191
|
-
throw new
|
|
192
|
-
code:
|
|
191
|
+
throw new CofheError({
|
|
192
|
+
code: CofheErrorCode.SealOutputFailed,
|
|
193
193
|
message: `sealOutput request not found: ${requestId}`,
|
|
194
194
|
hint: 'The request may have expired or been invalid.',
|
|
195
195
|
context: {
|
|
@@ -209,8 +209,8 @@ async function pollSealOutputStatus(thresholdNetworkUrl: string, requestId: stri
|
|
|
209
209
|
errorMessage = response.statusText || errorMessage;
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
-
throw new
|
|
213
|
-
code:
|
|
212
|
+
throw new CofheError({
|
|
213
|
+
code: CofheErrorCode.SealOutputFailed,
|
|
214
214
|
message: `sealOutput status poll failed: ${errorMessage}`,
|
|
215
215
|
context: {
|
|
216
216
|
thresholdNetworkUrl,
|
|
@@ -225,8 +225,8 @@ async function pollSealOutputStatus(thresholdNetworkUrl: string, requestId: stri
|
|
|
225
225
|
try {
|
|
226
226
|
statusResponse = (await response.json()) as SealOutputStatusResponse;
|
|
227
227
|
} catch (e) {
|
|
228
|
-
throw new
|
|
229
|
-
code:
|
|
228
|
+
throw new CofheError({
|
|
229
|
+
code: CofheErrorCode.SealOutputFailed,
|
|
230
230
|
message: `Failed to parse sealOutput status response`,
|
|
231
231
|
cause: e instanceof Error ? e : undefined,
|
|
232
232
|
context: {
|
|
@@ -241,8 +241,8 @@ async function pollSealOutputStatus(thresholdNetworkUrl: string, requestId: stri
|
|
|
241
241
|
// Check if succeeded
|
|
242
242
|
if (statusResponse.is_succeed === false) {
|
|
243
243
|
const errorMessage = statusResponse.error_message || 'Unknown error';
|
|
244
|
-
throw new
|
|
245
|
-
code:
|
|
244
|
+
throw new CofheError({
|
|
245
|
+
code: CofheErrorCode.SealOutputFailed,
|
|
246
246
|
message: `sealOutput request failed: ${errorMessage}`,
|
|
247
247
|
context: {
|
|
248
248
|
thresholdNetworkUrl,
|
|
@@ -254,8 +254,8 @@ async function pollSealOutputStatus(thresholdNetworkUrl: string, requestId: stri
|
|
|
254
254
|
|
|
255
255
|
// Check if sealed data exists
|
|
256
256
|
if (!statusResponse.sealed) {
|
|
257
|
-
throw new
|
|
258
|
-
code:
|
|
257
|
+
throw new CofheError({
|
|
258
|
+
code: CofheErrorCode.SealOutputReturnedNull,
|
|
259
259
|
message: `sealOutput request completed but returned no sealed data`,
|
|
260
260
|
context: {
|
|
261
261
|
thresholdNetworkUrl,
|
|
@@ -274,8 +274,8 @@ async function pollSealOutputStatus(thresholdNetworkUrl: string, requestId: stri
|
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
// This should never be reached, but TypeScript requires it
|
|
277
|
-
throw new
|
|
278
|
-
code:
|
|
277
|
+
throw new CofheError({
|
|
278
|
+
code: CofheErrorCode.SealOutputFailed,
|
|
279
279
|
message: 'Polling loop exited unexpectedly',
|
|
280
280
|
context: {
|
|
281
281
|
thresholdNetworkUrl,
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from 'viem';
|
|
13
13
|
import { MockZkVerifierAbi } from './MockZkVerifierAbi.js';
|
|
14
14
|
import { hardhat } from 'viem/chains';
|
|
15
|
-
import {
|
|
15
|
+
import { CofheError, CofheErrorCode } from '../error.js';
|
|
16
16
|
import { privateKeyToAccount } from 'viem/accounts';
|
|
17
17
|
import { MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY, MOCKS_ZK_VERIFIER_ADDRESS } from '../consts.js';
|
|
18
18
|
|
|
@@ -70,8 +70,8 @@ export async function cofheMocksCheckEncryptableBits(items: EncryptableItem[]):
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
if (totalBits > MAX_ENCRYPTABLE_BITS) {
|
|
73
|
-
throw new
|
|
74
|
-
code:
|
|
73
|
+
throw new CofheError({
|
|
74
|
+
code: CofheErrorCode.ZkPackFailed,
|
|
75
75
|
message: `Total bits ${totalBits} exceeds ${MAX_ENCRYPTABLE_BITS}`,
|
|
76
76
|
hint: `Ensure that the total bits of the items to encrypt does not exceed ${MAX_ENCRYPTABLE_BITS}`,
|
|
77
77
|
context: {
|
|
@@ -110,8 +110,8 @@ async function calcCtHashes(
|
|
|
110
110
|
args: calcCtHashesArgs,
|
|
111
111
|
})) as bigint[];
|
|
112
112
|
} catch (err) {
|
|
113
|
-
throw new
|
|
114
|
-
code:
|
|
113
|
+
throw new CofheError({
|
|
114
|
+
code: CofheErrorCode.ZkMocksCalcCtHashesFailed,
|
|
115
115
|
message: `mockZkVerifySign calcCtHashes failed while calling zkVerifyCalcCtHashesPacked`,
|
|
116
116
|
cause: err instanceof Error ? err : undefined,
|
|
117
117
|
context: {
|
|
@@ -126,8 +126,8 @@ async function calcCtHashes(
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
if (ctHashes.length !== items.length) {
|
|
129
|
-
throw new
|
|
130
|
-
code:
|
|
129
|
+
throw new CofheError({
|
|
130
|
+
code: CofheErrorCode.ZkMocksCalcCtHashesFailed,
|
|
131
131
|
message: `mockZkVerifySign calcCtHashes returned incorrect number of ctHashes`,
|
|
132
132
|
context: {
|
|
133
133
|
items,
|
|
@@ -164,8 +164,8 @@ async function insertCtHashes(items: EncryptableItemWithCtHash[], walletClient:
|
|
|
164
164
|
account: account,
|
|
165
165
|
});
|
|
166
166
|
} catch (err) {
|
|
167
|
-
throw new
|
|
168
|
-
code:
|
|
167
|
+
throw new CofheError({
|
|
168
|
+
code: CofheErrorCode.ZkMocksInsertCtHashesFailed,
|
|
169
169
|
message: `mockZkVerifySign insertPackedCtHashes failed while calling insertPackedCtHashes`,
|
|
170
170
|
cause: err instanceof Error ? err : undefined,
|
|
171
171
|
context: {
|
|
@@ -192,8 +192,8 @@ async function createProofSignatures(items: EncryptableItemWithCtHash[], securit
|
|
|
192
192
|
try {
|
|
193
193
|
encInputSignerClient = createMockZkVerifierSigner();
|
|
194
194
|
} catch (err) {
|
|
195
|
-
throw new
|
|
196
|
-
code:
|
|
195
|
+
throw new CofheError({
|
|
196
|
+
code: CofheErrorCode.ZkMocksCreateProofSignatureFailed,
|
|
197
197
|
message: `mockZkVerifySign createProofSignatures failed while creating wallet client`,
|
|
198
198
|
cause: err instanceof Error ? err : undefined,
|
|
199
199
|
context: {
|
|
@@ -220,8 +220,8 @@ async function createProofSignatures(items: EncryptableItemWithCtHash[], securit
|
|
|
220
220
|
signatures.push(signature);
|
|
221
221
|
}
|
|
222
222
|
} catch (err) {
|
|
223
|
-
throw new
|
|
224
|
-
code:
|
|
223
|
+
throw new CofheError({
|
|
224
|
+
code: CofheErrorCode.ZkMocksCreateProofSignatureFailed,
|
|
225
225
|
message: `mockZkVerifySign createProofSignatures failed while calling signMessage`,
|
|
226
226
|
cause: err instanceof Error ? err : undefined,
|
|
227
227
|
context: {
|
|
@@ -232,8 +232,8 @@ async function createProofSignatures(items: EncryptableItemWithCtHash[], securit
|
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
if (signatures.length !== items.length) {
|
|
235
|
-
throw new
|
|
236
|
-
code:
|
|
235
|
+
throw new CofheError({
|
|
236
|
+
code: CofheErrorCode.ZkMocksCreateProofSignatureFailed,
|
|
237
237
|
message: `mockZkVerifySign createProofSignatures returned incorrect number of signatures`,
|
|
238
238
|
context: {
|
|
239
239
|
items,
|