@cofhe/sdk 0.6.0 → 0.6.1

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @cofhe/sdk Changelog
2
2
 
3
+ ## 0.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 670cda8: Prepare an alpha snapshot release.
8
+
3
9
  ## 0.6.0
4
10
 
5
11
  ### Minor Changes
package/core/debug.ts ADDED
@@ -0,0 +1,72 @@
1
+ // Neutral, opt-in debug interceptors around every low-level SDK network request.
2
+ // Purpose-agnostic: a registered handler can observe, rewrite the URL, mutate the
3
+ // request body/init, replace the response, or throw — enabling fault-injection,
4
+ // logging, latency simulation, endpoint redirection, etc. without any
5
+ // scenario-specific code in the SDK.
6
+ //
7
+ // Nothing is active unless an interceptor is registered (setCofheDebugInterceptors),
8
+ // so this is a no-op in production by default.
9
+
10
+ export interface CofheRequestContext {
11
+ /** Coarse label for the call site, e.g. 'decrypt' | 'sealoutput' | 'fetchKeys'. */
12
+ op: string;
13
+ }
14
+
15
+ export interface CofheRequestOverride {
16
+ url?: string;
17
+ init?: RequestInit;
18
+ }
19
+
20
+ export type CofheOnRequest = (
21
+ url: string,
22
+ init: RequestInit | undefined,
23
+ ctx: CofheRequestContext
24
+ ) => CofheRequestOverride | void | Promise<CofheRequestOverride | void>;
25
+
26
+ export type CofheOnResponse = (
27
+ response: Response,
28
+ ctx: CofheRequestContext
29
+ ) => Response | void | Promise<Response | void>;
30
+
31
+ export interface CofheDebugInterceptors {
32
+ onRequest?: CofheOnRequest;
33
+ onResponse?: CofheOnResponse;
34
+ }
35
+
36
+ const interceptors: CofheDebugInterceptors = {};
37
+
38
+ /** Register (or clear, with null) the debug interceptors. */
39
+ export function setCofheDebugInterceptors(next: CofheDebugInterceptors | null): void {
40
+ interceptors.onRequest = next?.onRequest;
41
+ interceptors.onResponse = next?.onResponse;
42
+ }
43
+
44
+ export function getCofheDebugInterceptors(): CofheDebugInterceptors {
45
+ return interceptors;
46
+ }
47
+
48
+ /**
49
+ * fetch() wrapper used by all low-level SDK network ops. Applies the registered
50
+ * debug interceptors when present; otherwise behaves exactly like fetch().
51
+ */
52
+ export async function cofheFetch(
53
+ url: string,
54
+ init?: RequestInit,
55
+ ctx: CofheRequestContext = { op: 'request' }
56
+ ): Promise<Response> {
57
+ let finalUrl = url;
58
+ let finalInit = init;
59
+ if (interceptors.onRequest) {
60
+ const override = await interceptors.onRequest(finalUrl, finalInit, ctx);
61
+ if (override) {
62
+ if (override.url !== undefined) finalUrl = override.url;
63
+ if (override.init !== undefined) finalInit = override.init;
64
+ }
65
+ }
66
+ let response = await fetch(finalUrl, finalInit);
67
+ if (interceptors.onResponse) {
68
+ const replaced = await interceptors.onResponse(response, ctx);
69
+ if (replaced) response = replaced;
70
+ }
71
+ return response;
72
+ }
@@ -1,4 +1,5 @@
1
1
  import { type Permission } from '@/permits';
2
+ import { cofheFetch } from '../debug.js';
2
3
 
3
4
  import { CofheError, CofheErrorCode } from '../error';
4
5
  import { type DecryptPollCallbackFunction } from '../types';
@@ -200,13 +201,16 @@ async function submitDecryptRequestV2(
200
201
  for (;;) {
201
202
  let response: Response;
202
203
  try {
203
- response = await fetch(`${thresholdNetworkUrl}/v2/decrypt`, {
204
- method: 'POST',
205
- headers: {
206
- 'Content-Type': 'application/json',
207
- },
208
- body: JSON.stringify(body),
209
- });
204
+ response = await cofheFetch(
205
+ `${thresholdNetworkUrl}/v2/decrypt`,
206
+ /*op:decrypt*/ {
207
+ method: 'POST',
208
+ headers: {
209
+ 'Content-Type': 'application/json',
210
+ },
211
+ body: JSON.stringify(body),
212
+ }
213
+ );
210
214
  } catch (e) {
211
215
  throw new CofheError({
212
216
  code: CofheErrorCode.DecryptFailed,
@@ -352,12 +356,15 @@ async function pollDecryptStatusV2(
352
356
 
353
357
  let response: Response;
354
358
  try {
355
- response = await fetch(`${thresholdNetworkUrl}/v2/decrypt/${requestId}`, {
356
- method: 'GET',
357
- headers: {
358
- 'Content-Type': 'application/json',
359
- },
360
- });
359
+ response = await cofheFetch(
360
+ `${thresholdNetworkUrl}/v2/decrypt/${requestId}`,
361
+ /*op:decrypt-poll*/ {
362
+ method: 'GET',
363
+ headers: {
364
+ 'Content-Type': 'application/json',
365
+ },
366
+ }
367
+ );
361
368
  } catch (e) {
362
369
  throw new CofheError({
363
370
  code: CofheErrorCode.DecryptFailed,
@@ -1,4 +1,5 @@
1
1
  import { type Permission, type EthEncryptedData } from '@/permits';
2
+ import { cofheFetch } from '../debug.js';
2
3
 
3
4
  import { CofheError, CofheErrorCode } from '../error.js';
4
5
  import { type DecryptPollCallbackFunction } from '../types.js';
@@ -150,13 +151,16 @@ async function submitSealOutputRequest(
150
151
  for (;;) {
151
152
  let response: Response;
152
153
  try {
153
- response = await fetch(`${thresholdNetworkUrl}/v2/sealoutput`, {
154
- method: 'POST',
155
- headers: {
156
- 'Content-Type': 'application/json',
157
- },
158
- body: JSON.stringify(body),
159
- });
154
+ response = await cofheFetch(
155
+ `${thresholdNetworkUrl}/v2/sealoutput`,
156
+ /*op:sealoutput*/ {
157
+ method: 'POST',
158
+ headers: {
159
+ 'Content-Type': 'application/json',
160
+ },
161
+ body: JSON.stringify(body),
162
+ }
163
+ );
160
164
  } catch (e) {
161
165
  throw new CofheError({
162
166
  code: CofheErrorCode.SealOutputFailed,
@@ -303,12 +307,15 @@ async function pollSealOutputStatus(
303
307
 
304
308
  let response: Response;
305
309
  try {
306
- response = await fetch(`${thresholdNetworkUrl}/v2/sealoutput/${requestId}`, {
307
- method: 'GET',
308
- headers: {
309
- 'Content-Type': 'application/json',
310
- },
311
- });
310
+ response = await cofheFetch(
311
+ `${thresholdNetworkUrl}/v2/sealoutput/${requestId}`,
312
+ /*op:sealoutput-poll*/ {
313
+ method: 'GET',
314
+ headers: {
315
+ 'Content-Type': 'application/json',
316
+ },
317
+ }
318
+ );
312
319
  } catch (e) {
313
320
  throw new CofheError({
314
321
  code: CofheErrorCode.SealOutputFailed,
package/core/index.ts CHANGED
@@ -1,6 +1,16 @@
1
1
  // Client (base implementations)
2
2
  export { createCofheClientBase, InitialConnectStore as CONNECT_STORE_DEFAULTS } from './client.js';
3
3
 
4
+ // Debug interceptors (neutral, opt-in network hooks for fault injection / logging)
5
+ export { setCofheDebugInterceptors, getCofheDebugInterceptors, cofheFetch } from './debug.js';
6
+ export type {
7
+ CofheDebugInterceptors,
8
+ CofheOnRequest,
9
+ CofheOnResponse,
10
+ CofheRequestContext,
11
+ CofheRequestOverride,
12
+ } from './debug.js';
13
+
4
14
  // Configuration (base implementations)
5
15
  export { createCofheConfigBase, getCofheConfigItem } from './config.js';
6
16
  export type { CofheConfig, CofheInputConfig, CofheInternalConfig } from './config.js';
package/core/permits.ts CHANGED
@@ -112,13 +112,18 @@ const selectActivePermit = (chainId: number, account: string, hash: string): voi
112
112
  // GET OR CREATE
113
113
 
114
114
  /**
115
- * Get the active self permit or create a new one if it doesn't exist
115
+ * Get the active self permit if a valid one exists, otherwise create a new one.
116
+ *
117
+ * An active permit is reused only when it is a self permit and is still valid
118
+ * (signed and not expired). An expired or otherwise invalid active permit is
119
+ * treated as missing and a fresh permit is created.
120
+ *
116
121
  * @param publicClient - The public client
117
122
  * @param walletClient - The wallet client
118
123
  * @param chainId - Optional chain ID (will use publicClient if not provided)
119
124
  * @param account - Optional account (will use walletClient if not provided)
120
125
  * @param options - The options for creating a self permit
121
- * @returns The existing or newly created permit
126
+ * @returns The existing valid permit or a newly created one
122
127
  */
123
128
  const getOrCreateSelfPermit = async (
124
129
  publicClient: PublicClient,
@@ -133,22 +138,27 @@ const getOrCreateSelfPermit = async (
133
138
  // Try to get active permit first
134
139
  const activePermit = await getActivePermit(_chainId, _account);
135
140
 
136
- if (activePermit && activePermit.type === 'self') {
141
+ if (activePermit && activePermit.type === 'self' && PermitUtils.isValid(activePermit).valid) {
137
142
  return activePermit;
138
143
  }
139
144
 
140
- // No active permit or wrong type, create new one
145
+ // No active permit, wrong type, or expired/invalid - create new one
141
146
  return createSelf(options ?? { issuer: _account, name: 'Autogenerated Self Permit' }, publicClient, walletClient);
142
147
  };
143
148
 
144
149
  /**
145
- * Get the active sharing permit or create a new one if it doesn't exist
150
+ * Get the active sharing permit if a valid one exists, otherwise create a new one.
151
+ *
152
+ * An active permit is reused only when it is a sharing permit and is still valid
153
+ * (signed and not expired). An expired or otherwise invalid active permit is
154
+ * treated as missing and a fresh permit is created.
155
+ *
146
156
  * @param publicClient - The public client
147
157
  * @param walletClient - The wallet client
148
158
  * @param options - The options for creating a sharing permit (required)
149
159
  * @param chainId - Optional chain ID (will use publicClient if not provided)
150
160
  * @param account - Optional account (will use walletClient if not provided)
151
- * @returns The existing or newly created permit
161
+ * @returns The existing valid permit or a newly created one
152
162
  */
153
163
  const getOrCreateSharingPermit = async (
154
164
  publicClient: PublicClient,
@@ -163,7 +173,7 @@ const getOrCreateSharingPermit = async (
163
173
  // Try to get active permit first
164
174
  const activePermit = await getActivePermit(_chainId, _account);
165
175
 
166
- if (activePermit && activePermit.type === 'sharing') {
176
+ if (activePermit && activePermit.type === 'sharing' && PermitUtils.isValid(activePermit).valid) {
167
177
  return activePermit;
168
178
  }
169
179
 
@@ -304,6 +304,33 @@ describe('Core Permits Tests', () => {
304
304
  expect(Object.keys(allPermits).length).toBe(2);
305
305
  });
306
306
 
307
+ it('should create a new self permit when active permit is expired', async () => {
308
+ // Create an expired self permit (expiration in the past)
309
+ const expiredPermit = await permits.createSelf(
310
+ { name: 'Expired Self Permit', issuer: bobAddress, expiration: Math.floor(Date.now() / 1000) - 3600 },
311
+ publicClient,
312
+ bobWalletClient
313
+ );
314
+
315
+ // Sanity check - it is the active permit and is expired
316
+ const activeBefore = await permits.getActivePermit(chainId, bobAddress);
317
+ expect(activeBefore?.hash).toBe(expiredPermit.hash);
318
+
319
+ // getOrCreateSelfPermit should treat the expired permit as missing and create a fresh one
320
+ const permit = await permits.getOrCreateSelfPermit(publicClient, bobWalletClient, chainId, bobAddress, {
321
+ issuer: bobAddress,
322
+ name: 'Fresh Self Permit',
323
+ });
324
+
325
+ expect(permit.name).toBe('Fresh Self Permit');
326
+ expect(permit.type).toBe('self');
327
+ expect(permit.hash).not.toBe(expiredPermit.hash);
328
+
329
+ // The fresh permit should now be active
330
+ const activeAfter = await permits.getActivePermit(chainId, bobAddress);
331
+ expect(activeAfter?.hash).toBe(permit.hash);
332
+ });
333
+
307
334
  it('should use default options when none provided', async () => {
308
335
  const permit = await permits.getOrCreateSelfPermit(publicClient, bobWalletClient, chainId, bobAddress);
309
336
 
@@ -412,6 +439,41 @@ describe('Core Permits Tests', () => {
412
439
  expect(Object.keys(allPermits).length).toBe(2);
413
440
  });
414
441
 
442
+ it('should create a new sharing permit when active permit is expired', async () => {
443
+ // Create an expired sharing permit (expiration in the past)
444
+ const expiredPermit = await permits.createSharing(
445
+ {
446
+ name: 'Expired Sharing Permit',
447
+ issuer: bobAddress,
448
+ recipient: aliceAddress,
449
+ expiration: Math.floor(Date.now() / 1000) - 3600,
450
+ },
451
+ publicClient,
452
+ bobWalletClient
453
+ );
454
+
455
+ // getOrCreateSharingPermit should treat the expired permit as missing and create a fresh one
456
+ const permit = await permits.getOrCreateSharingPermit(
457
+ publicClient,
458
+ bobWalletClient,
459
+ {
460
+ issuer: bobAddress,
461
+ recipient: aliceAddress,
462
+ name: 'Fresh Sharing Permit',
463
+ },
464
+ chainId,
465
+ bobAddress
466
+ );
467
+
468
+ expect(permit.name).toBe('Fresh Sharing Permit');
469
+ expect(permit.type).toBe('sharing');
470
+ expect(permit.hash).not.toBe(expiredPermit.hash);
471
+
472
+ // The fresh permit should now be active
473
+ const activeAfter = await permits.getActivePermit(chainId, bobAddress);
474
+ expect(activeAfter?.hash).toBe(permit.hash);
475
+ });
476
+
415
477
  it('should use default chainId and account when not provided', async () => {
416
478
  const permit = await permits.getOrCreateSharingPermit(
417
479
  publicClient,
@@ -1730,7 +1730,7 @@ var getOrCreateSelfPermit = async (publicClient, walletClient, chainId, account,
1730
1730
  const _chainId = chainId ?? await publicClient.getChainId();
1731
1731
  const _account = account ?? walletClient.account.address;
1732
1732
  const activePermit = await getActivePermit(_chainId, _account);
1733
- if (activePermit && activePermit.type === "self") {
1733
+ if (activePermit && activePermit.type === "self" && PermitUtils.isValid(activePermit).valid) {
1734
1734
  return activePermit;
1735
1735
  }
1736
1736
  return createSelf(options ?? { issuer: _account, name: "Autogenerated Self Permit" }, publicClient, walletClient);
@@ -1739,7 +1739,7 @@ var getOrCreateSharingPermit = async (publicClient, walletClient, options, chain
1739
1739
  const _chainId = chainId ?? await publicClient.getChainId();
1740
1740
  const _account = account ?? walletClient.account.address;
1741
1741
  const activePermit = await getActivePermit(_chainId, _account);
1742
- if (activePermit && activePermit.type === "sharing") {
1742
+ if (activePermit && activePermit.type === "sharing" && PermitUtils.isValid(activePermit).valid) {
1743
1743
  return activePermit;
1744
1744
  }
1745
1745
  return createSharing(options, publicClient, walletClient);
@@ -1998,6 +1998,36 @@ async function cofheMocksDecryptForView(ctHash, utype, permit, publicClient) {
1998
1998
  return unsealed;
1999
1999
  }
2000
2000
 
2001
+ // core/debug.ts
2002
+ var interceptors = {};
2003
+ function setCofheDebugInterceptors(next) {
2004
+ interceptors.onRequest = next?.onRequest;
2005
+ interceptors.onResponse = next?.onResponse;
2006
+ }
2007
+ function getCofheDebugInterceptors() {
2008
+ return interceptors;
2009
+ }
2010
+ async function cofheFetch(url, init, ctx = { op: "request" }) {
2011
+ let finalUrl = url;
2012
+ let finalInit = init;
2013
+ if (interceptors.onRequest) {
2014
+ const override = await interceptors.onRequest(finalUrl, finalInit, ctx);
2015
+ if (override) {
2016
+ if (override.url !== void 0)
2017
+ finalUrl = override.url;
2018
+ if (override.init !== void 0)
2019
+ finalInit = override.init;
2020
+ }
2021
+ }
2022
+ let response = await fetch(finalUrl, finalInit);
2023
+ if (interceptors.onResponse) {
2024
+ const replaced = await interceptors.onResponse(response, ctx);
2025
+ if (replaced)
2026
+ response = replaced;
2027
+ }
2028
+ return response;
2029
+ }
2030
+
2001
2031
  // core/decrypt/polling.ts
2002
2032
  function computeMinuteRampPollIntervalMs(elapsedMs, params) {
2003
2033
  const elapsedSeconds = Math.floor(elapsedMs / 1e3);
@@ -2167,13 +2197,17 @@ async function submitSealOutputRequest(thresholdNetworkUrl, ctHash, chainId, per
2167
2197
  for (; ; ) {
2168
2198
  let response;
2169
2199
  try {
2170
- response = await fetch(`${thresholdNetworkUrl}/v2/sealoutput`, {
2171
- method: "POST",
2172
- headers: {
2173
- "Content-Type": "application/json"
2174
- },
2175
- body: JSON.stringify(body)
2176
- });
2200
+ response = await cofheFetch(
2201
+ `${thresholdNetworkUrl}/v2/sealoutput`,
2202
+ /*op:sealoutput*/
2203
+ {
2204
+ method: "POST",
2205
+ headers: {
2206
+ "Content-Type": "application/json"
2207
+ },
2208
+ body: JSON.stringify(body)
2209
+ }
2210
+ );
2177
2211
  } catch (e) {
2178
2212
  throw new CofheError({
2179
2213
  code: "SEAL_OUTPUT_FAILED" /* SealOutputFailed */,
@@ -2296,12 +2330,16 @@ async function pollSealOutputStatus(thresholdNetworkUrl, requestId, overallStart
2296
2330
  }
2297
2331
  let response;
2298
2332
  try {
2299
- response = await fetch(`${thresholdNetworkUrl}/v2/sealoutput/${requestId}`, {
2300
- method: "GET",
2301
- headers: {
2302
- "Content-Type": "application/json"
2333
+ response = await cofheFetch(
2334
+ `${thresholdNetworkUrl}/v2/sealoutput/${requestId}`,
2335
+ /*op:sealoutput-poll*/
2336
+ {
2337
+ method: "GET",
2338
+ headers: {
2339
+ "Content-Type": "application/json"
2340
+ }
2303
2341
  }
2304
- });
2342
+ );
2305
2343
  } catch (e) {
2306
2344
  throw new CofheError({
2307
2345
  code: "SEAL_OUTPUT_FAILED" /* SealOutputFailed */,
@@ -2898,13 +2936,17 @@ async function submitDecryptRequestV2(thresholdNetworkUrl, ctHash, chainId, perm
2898
2936
  for (; ; ) {
2899
2937
  let response;
2900
2938
  try {
2901
- response = await fetch(`${thresholdNetworkUrl}/v2/decrypt`, {
2902
- method: "POST",
2903
- headers: {
2904
- "Content-Type": "application/json"
2905
- },
2906
- body: JSON.stringify(body)
2907
- });
2939
+ response = await cofheFetch(
2940
+ `${thresholdNetworkUrl}/v2/decrypt`,
2941
+ /*op:decrypt*/
2942
+ {
2943
+ method: "POST",
2944
+ headers: {
2945
+ "Content-Type": "application/json"
2946
+ },
2947
+ body: JSON.stringify(body)
2948
+ }
2949
+ );
2908
2950
  } catch (e) {
2909
2951
  throw new CofheError({
2910
2952
  code: "DECRYPT_FAILED" /* DecryptFailed */,
@@ -3029,12 +3071,16 @@ async function pollDecryptStatusV2(thresholdNetworkUrl, requestId, overallStartT
3029
3071
  }
3030
3072
  let response;
3031
3073
  try {
3032
- response = await fetch(`${thresholdNetworkUrl}/v2/decrypt/${requestId}`, {
3033
- method: "GET",
3034
- headers: {
3035
- "Content-Type": "application/json"
3074
+ response = await cofheFetch(
3075
+ `${thresholdNetworkUrl}/v2/decrypt/${requestId}`,
3076
+ /*op:decrypt-poll*/
3077
+ {
3078
+ method: "GET",
3079
+ headers: {
3080
+ "Content-Type": "application/json"
3081
+ }
3036
3082
  }
3037
- });
3083
+ );
3038
3084
  } catch (e) {
3039
3085
  throw new CofheError({
3040
3086
  code: "DECRYPT_FAILED" /* DecryptFailed */,
@@ -3633,4 +3679,4 @@ function createCofheClientBase(opts) {
3633
3679
  };
3634
3680
  }
3635
3681
 
3636
- export { CofheError, CofheErrorCode, DecryptForTxBuilder, DecryptForViewBuilder, EncryptInputsBuilder, EncryptStep, Encryptable, FheAllUTypes, FheTypes, FheUintUTypes, InitialConnectStore, assertCorrectEncryptedItemInput, createCofheClientBase, createCofheConfigBase, createKeysStore, fetchKeys, fheTypeToString, getCofheConfigItem, isCofheError, isEncryptableItem, isLastEncryptionStep, verifyDecryptResult, zkProveWithWorker };
3682
+ export { CofheError, CofheErrorCode, DecryptForTxBuilder, DecryptForViewBuilder, EncryptInputsBuilder, EncryptStep, Encryptable, FheAllUTypes, FheTypes, FheUintUTypes, InitialConnectStore, assertCorrectEncryptedItemInput, cofheFetch, createCofheClientBase, createCofheConfigBase, createKeysStore, fetchKeys, fheTypeToString, getCofheConfigItem, getCofheDebugInterceptors, isCofheError, isEncryptableItem, isLastEncryptionStep, setCofheDebugInterceptors, verifyDecryptResult, zkProveWithWorker };
package/dist/core.cjs CHANGED
@@ -2752,7 +2752,7 @@ var getOrCreateSelfPermit = async (publicClient, walletClient, chainId, account,
2752
2752
  const _chainId = chainId ?? await publicClient.getChainId();
2753
2753
  const _account = account ?? walletClient.account.address;
2754
2754
  const activePermit = await getActivePermit2(_chainId, _account);
2755
- if (activePermit && activePermit.type === "self") {
2755
+ if (activePermit && activePermit.type === "self" && PermitUtils.isValid(activePermit).valid) {
2756
2756
  return activePermit;
2757
2757
  }
2758
2758
  return createSelf(options ?? { issuer: _account, name: "Autogenerated Self Permit" }, publicClient, walletClient);
@@ -2761,7 +2761,7 @@ var getOrCreateSharingPermit = async (publicClient, walletClient, options, chain
2761
2761
  const _chainId = chainId ?? await publicClient.getChainId();
2762
2762
  const _account = account ?? walletClient.account.address;
2763
2763
  const activePermit = await getActivePermit2(_chainId, _account);
2764
- if (activePermit && activePermit.type === "sharing") {
2764
+ if (activePermit && activePermit.type === "sharing" && PermitUtils.isValid(activePermit).valid) {
2765
2765
  return activePermit;
2766
2766
  }
2767
2767
  return createSharing(options, publicClient, walletClient);
@@ -3020,6 +3020,36 @@ async function cofheMocksDecryptForView(ctHash, utype, permit, publicClient) {
3020
3020
  return unsealed;
3021
3021
  }
3022
3022
 
3023
+ // core/debug.ts
3024
+ var interceptors = {};
3025
+ function setCofheDebugInterceptors(next) {
3026
+ interceptors.onRequest = next?.onRequest;
3027
+ interceptors.onResponse = next?.onResponse;
3028
+ }
3029
+ function getCofheDebugInterceptors() {
3030
+ return interceptors;
3031
+ }
3032
+ async function cofheFetch(url, init, ctx = { op: "request" }) {
3033
+ let finalUrl = url;
3034
+ let finalInit = init;
3035
+ if (interceptors.onRequest) {
3036
+ const override = await interceptors.onRequest(finalUrl, finalInit, ctx);
3037
+ if (override) {
3038
+ if (override.url !== void 0)
3039
+ finalUrl = override.url;
3040
+ if (override.init !== void 0)
3041
+ finalInit = override.init;
3042
+ }
3043
+ }
3044
+ let response = await fetch(finalUrl, finalInit);
3045
+ if (interceptors.onResponse) {
3046
+ const replaced = await interceptors.onResponse(response, ctx);
3047
+ if (replaced)
3048
+ response = replaced;
3049
+ }
3050
+ return response;
3051
+ }
3052
+
3023
3053
  // core/decrypt/polling.ts
3024
3054
  function computeMinuteRampPollIntervalMs(elapsedMs, params) {
3025
3055
  const elapsedSeconds = Math.floor(elapsedMs / 1e3);
@@ -3189,13 +3219,17 @@ async function submitSealOutputRequest(thresholdNetworkUrl, ctHash, chainId, per
3189
3219
  for (; ; ) {
3190
3220
  let response;
3191
3221
  try {
3192
- response = await fetch(`${thresholdNetworkUrl}/v2/sealoutput`, {
3193
- method: "POST",
3194
- headers: {
3195
- "Content-Type": "application/json"
3196
- },
3197
- body: JSON.stringify(body)
3198
- });
3222
+ response = await cofheFetch(
3223
+ `${thresholdNetworkUrl}/v2/sealoutput`,
3224
+ /*op:sealoutput*/
3225
+ {
3226
+ method: "POST",
3227
+ headers: {
3228
+ "Content-Type": "application/json"
3229
+ },
3230
+ body: JSON.stringify(body)
3231
+ }
3232
+ );
3199
3233
  } catch (e) {
3200
3234
  throw new CofheError({
3201
3235
  code: "SEAL_OUTPUT_FAILED" /* SealOutputFailed */,
@@ -3318,12 +3352,16 @@ async function pollSealOutputStatus(thresholdNetworkUrl, requestId, overallStart
3318
3352
  }
3319
3353
  let response;
3320
3354
  try {
3321
- response = await fetch(`${thresholdNetworkUrl}/v2/sealoutput/${requestId}`, {
3322
- method: "GET",
3323
- headers: {
3324
- "Content-Type": "application/json"
3355
+ response = await cofheFetch(
3356
+ `${thresholdNetworkUrl}/v2/sealoutput/${requestId}`,
3357
+ /*op:sealoutput-poll*/
3358
+ {
3359
+ method: "GET",
3360
+ headers: {
3361
+ "Content-Type": "application/json"
3362
+ }
3325
3363
  }
3326
- });
3364
+ );
3327
3365
  } catch (e) {
3328
3366
  throw new CofheError({
3329
3367
  code: "SEAL_OUTPUT_FAILED" /* SealOutputFailed */,
@@ -3920,13 +3958,17 @@ async function submitDecryptRequestV2(thresholdNetworkUrl, ctHash, chainId, perm
3920
3958
  for (; ; ) {
3921
3959
  let response;
3922
3960
  try {
3923
- response = await fetch(`${thresholdNetworkUrl}/v2/decrypt`, {
3924
- method: "POST",
3925
- headers: {
3926
- "Content-Type": "application/json"
3927
- },
3928
- body: JSON.stringify(body)
3929
- });
3961
+ response = await cofheFetch(
3962
+ `${thresholdNetworkUrl}/v2/decrypt`,
3963
+ /*op:decrypt*/
3964
+ {
3965
+ method: "POST",
3966
+ headers: {
3967
+ "Content-Type": "application/json"
3968
+ },
3969
+ body: JSON.stringify(body)
3970
+ }
3971
+ );
3930
3972
  } catch (e) {
3931
3973
  throw new CofheError({
3932
3974
  code: "DECRYPT_FAILED" /* DecryptFailed */,
@@ -4051,12 +4093,16 @@ async function pollDecryptStatusV2(thresholdNetworkUrl, requestId, overallStartT
4051
4093
  }
4052
4094
  let response;
4053
4095
  try {
4054
- response = await fetch(`${thresholdNetworkUrl}/v2/decrypt/${requestId}`, {
4055
- method: "GET",
4056
- headers: {
4057
- "Content-Type": "application/json"
4096
+ response = await cofheFetch(
4097
+ `${thresholdNetworkUrl}/v2/decrypt/${requestId}`,
4098
+ /*op:decrypt-poll*/
4099
+ {
4100
+ method: "GET",
4101
+ headers: {
4102
+ "Content-Type": "application/json"
4103
+ }
4058
4104
  }
4059
- });
4105
+ );
4060
4106
  } catch (e) {
4061
4107
  throw new CofheError({
4062
4108
  code: "DECRYPT_FAILED" /* DecryptFailed */,
@@ -4675,14 +4721,17 @@ exports.TASK_MANAGER_ADDRESS = TASK_MANAGER_ADDRESS;
4675
4721
  exports.TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT = TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT;
4676
4722
  exports.TFHE_RS_ZK_MAX_BITS = TFHE_RS_ZK_MAX_BITS;
4677
4723
  exports.assertCorrectEncryptedItemInput = assertCorrectEncryptedItemInput;
4724
+ exports.cofheFetch = cofheFetch;
4678
4725
  exports.createCofheClientBase = createCofheClientBase;
4679
4726
  exports.createCofheConfigBase = createCofheConfigBase;
4680
4727
  exports.createKeysStore = createKeysStore;
4681
4728
  exports.fetchKeys = fetchKeys;
4682
4729
  exports.fheTypeToString = fheTypeToString;
4683
4730
  exports.getCofheConfigItem = getCofheConfigItem;
4731
+ exports.getCofheDebugInterceptors = getCofheDebugInterceptors;
4684
4732
  exports.isCofheError = isCofheError;
4685
4733
  exports.isEncryptableItem = isEncryptableItem;
4686
4734
  exports.isLastEncryptionStep = isLastEncryptionStep;
4735
+ exports.setCofheDebugInterceptors = setCofheDebugInterceptors;
4687
4736
  exports.verifyDecryptResult = verifyDecryptResult;
4688
4737
  exports.zkProveWithWorker = zkProveWithWorker;
package/dist/core.d.cts CHANGED
@@ -14,6 +14,29 @@ declare const InitialConnectStore: CofheClientConnectionState;
14
14
  */
15
15
  declare function createCofheClientBase<TConfig extends CofheConfig>(opts: CofheClientParams<TConfig>): CofheClient<TConfig>;
16
16
 
17
+ interface CofheRequestContext {
18
+ /** Coarse label for the call site, e.g. 'decrypt' | 'sealoutput' | 'fetchKeys'. */
19
+ op: string;
20
+ }
21
+ interface CofheRequestOverride {
22
+ url?: string;
23
+ init?: RequestInit;
24
+ }
25
+ type CofheOnRequest = (url: string, init: RequestInit | undefined, ctx: CofheRequestContext) => CofheRequestOverride | void | Promise<CofheRequestOverride | void>;
26
+ type CofheOnResponse = (response: Response, ctx: CofheRequestContext) => Response | void | Promise<Response | void>;
27
+ interface CofheDebugInterceptors {
28
+ onRequest?: CofheOnRequest;
29
+ onResponse?: CofheOnResponse;
30
+ }
31
+ /** Register (or clear, with null) the debug interceptors. */
32
+ declare function setCofheDebugInterceptors(next: CofheDebugInterceptors | null): void;
33
+ declare function getCofheDebugInterceptors(): CofheDebugInterceptors;
34
+ /**
35
+ * fetch() wrapper used by all low-level SDK network ops. Applies the registered
36
+ * debug interceptors when present; otherwise behaves exactly like fetch().
37
+ */
38
+ declare function cofheFetch(url: string, init?: RequestInit, ctx?: CofheRequestContext): Promise<Response>;
39
+
17
40
  declare enum CofheErrorCode {
18
41
  InternalError = "INTERNAL_ERROR",
19
42
  UnknownEnvironment = "UNKNOWN_ENVIRONMENT",
@@ -137,4 +160,4 @@ declare function verifyDecryptResult(handle: bigint | string, cleartext: bigint,
137
160
  */
138
161
  declare function fheTypeToString(utype: FheTypes): string;
139
162
 
140
- export { InitialConnectStore as CONNECT_STORE_DEFAULTS, CofheClient, CofheClientConnectionState, CofheClientParams, CofheConfig, CofheError, CofheErrorCode, type CofheErrorParams, FheTypes, MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY, MOCKS_THRESHOLD_NETWORK_ADDRESS, MOCKS_ZK_VERIFIER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY, TASK_MANAGER_ADDRESS, TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT, TFHE_RS_ZK_MAX_BITS, createCofheClientBase, fheTypeToString, isCofheError, verifyDecryptResult };
163
+ export { InitialConnectStore as CONNECT_STORE_DEFAULTS, CofheClient, CofheClientConnectionState, CofheClientParams, CofheConfig, type CofheDebugInterceptors, CofheError, CofheErrorCode, type CofheErrorParams, type CofheOnRequest, type CofheOnResponse, type CofheRequestContext, type CofheRequestOverride, FheTypes, MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY, MOCKS_THRESHOLD_NETWORK_ADDRESS, MOCKS_ZK_VERIFIER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY, TASK_MANAGER_ADDRESS, TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT, TFHE_RS_ZK_MAX_BITS, cofheFetch, createCofheClientBase, fheTypeToString, getCofheDebugInterceptors, isCofheError, setCofheDebugInterceptors, verifyDecryptResult };
package/dist/core.d.ts CHANGED
@@ -14,6 +14,29 @@ declare const InitialConnectStore: CofheClientConnectionState;
14
14
  */
15
15
  declare function createCofheClientBase<TConfig extends CofheConfig>(opts: CofheClientParams<TConfig>): CofheClient<TConfig>;
16
16
 
17
+ interface CofheRequestContext {
18
+ /** Coarse label for the call site, e.g. 'decrypt' | 'sealoutput' | 'fetchKeys'. */
19
+ op: string;
20
+ }
21
+ interface CofheRequestOverride {
22
+ url?: string;
23
+ init?: RequestInit;
24
+ }
25
+ type CofheOnRequest = (url: string, init: RequestInit | undefined, ctx: CofheRequestContext) => CofheRequestOverride | void | Promise<CofheRequestOverride | void>;
26
+ type CofheOnResponse = (response: Response, ctx: CofheRequestContext) => Response | void | Promise<Response | void>;
27
+ interface CofheDebugInterceptors {
28
+ onRequest?: CofheOnRequest;
29
+ onResponse?: CofheOnResponse;
30
+ }
31
+ /** Register (or clear, with null) the debug interceptors. */
32
+ declare function setCofheDebugInterceptors(next: CofheDebugInterceptors | null): void;
33
+ declare function getCofheDebugInterceptors(): CofheDebugInterceptors;
34
+ /**
35
+ * fetch() wrapper used by all low-level SDK network ops. Applies the registered
36
+ * debug interceptors when present; otherwise behaves exactly like fetch().
37
+ */
38
+ declare function cofheFetch(url: string, init?: RequestInit, ctx?: CofheRequestContext): Promise<Response>;
39
+
17
40
  declare enum CofheErrorCode {
18
41
  InternalError = "INTERNAL_ERROR",
19
42
  UnknownEnvironment = "UNKNOWN_ENVIRONMENT",
@@ -137,4 +160,4 @@ declare function verifyDecryptResult(handle: bigint | string, cleartext: bigint,
137
160
  */
138
161
  declare function fheTypeToString(utype: FheTypes): string;
139
162
 
140
- export { InitialConnectStore as CONNECT_STORE_DEFAULTS, CofheClient, CofheClientConnectionState, CofheClientParams, CofheConfig, CofheError, CofheErrorCode, type CofheErrorParams, FheTypes, MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY, MOCKS_THRESHOLD_NETWORK_ADDRESS, MOCKS_ZK_VERIFIER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY, TASK_MANAGER_ADDRESS, TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT, TFHE_RS_ZK_MAX_BITS, createCofheClientBase, fheTypeToString, isCofheError, verifyDecryptResult };
163
+ export { InitialConnectStore as CONNECT_STORE_DEFAULTS, CofheClient, CofheClientConnectionState, CofheClientParams, CofheConfig, type CofheDebugInterceptors, CofheError, CofheErrorCode, type CofheErrorParams, type CofheOnRequest, type CofheOnResponse, type CofheRequestContext, type CofheRequestOverride, FheTypes, MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY, MOCKS_THRESHOLD_NETWORK_ADDRESS, MOCKS_ZK_VERIFIER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY, TASK_MANAGER_ADDRESS, TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT, TFHE_RS_ZK_MAX_BITS, cofheFetch, createCofheClientBase, fheTypeToString, getCofheDebugInterceptors, isCofheError, setCofheDebugInterceptors, verifyDecryptResult };
package/dist/core.js CHANGED
@@ -1,4 +1,4 @@
1
- export { InitialConnectStore as CONNECT_STORE_DEFAULTS, CofheError, CofheErrorCode, DecryptForTxBuilder, DecryptForViewBuilder, EncryptInputsBuilder, EncryptStep, Encryptable, FheAllUTypes, FheTypes, FheUintUTypes, assertCorrectEncryptedItemInput, createCofheClientBase, createCofheConfigBase, createKeysStore, fetchKeys, fheTypeToString, getCofheConfigItem, isCofheError, isEncryptableItem, isLastEncryptionStep, verifyDecryptResult, zkProveWithWorker } from './chunk-PE5V5CCV.js';
1
+ export { InitialConnectStore as CONNECT_STORE_DEFAULTS, CofheError, CofheErrorCode, DecryptForTxBuilder, DecryptForViewBuilder, EncryptInputsBuilder, EncryptStep, Encryptable, FheAllUTypes, FheTypes, FheUintUTypes, assertCorrectEncryptedItemInput, cofheFetch, createCofheClientBase, createCofheConfigBase, createKeysStore, fetchKeys, fheTypeToString, getCofheConfigItem, getCofheDebugInterceptors, isCofheError, isEncryptableItem, isLastEncryptionStep, setCofheDebugInterceptors, verifyDecryptResult, zkProveWithWorker } from './chunk-NOC3PYB7.js';
2
2
  import './chunk-MTRAXQXC.js';
3
3
  import './chunk-VB62WYPL.js';
4
4
  export { MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY, MOCKS_THRESHOLD_NETWORK_ADDRESS, MOCKS_ZK_VERIFIER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY, TASK_MANAGER_ADDRESS, TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT, TFHE_RS_ZK_MAX_BITS } from './chunk-ESMZCFJY.js';
package/dist/node.cjs CHANGED
@@ -2562,7 +2562,7 @@ var getOrCreateSelfPermit = async (publicClient, walletClient, chainId, account,
2562
2562
  const _chainId = chainId ?? await publicClient.getChainId();
2563
2563
  const _account = account ?? walletClient.account.address;
2564
2564
  const activePermit = await getActivePermit2(_chainId, _account);
2565
- if (activePermit && activePermit.type === "self") {
2565
+ if (activePermit && activePermit.type === "self" && PermitUtils.isValid(activePermit).valid) {
2566
2566
  return activePermit;
2567
2567
  }
2568
2568
  return createSelf(options ?? { issuer: _account, name: "Autogenerated Self Permit" }, publicClient, walletClient);
@@ -2571,7 +2571,7 @@ var getOrCreateSharingPermit = async (publicClient, walletClient, options, chain
2571
2571
  const _chainId = chainId ?? await publicClient.getChainId();
2572
2572
  const _account = account ?? walletClient.account.address;
2573
2573
  const activePermit = await getActivePermit2(_chainId, _account);
2574
- if (activePermit && activePermit.type === "sharing") {
2574
+ if (activePermit && activePermit.type === "sharing" && PermitUtils.isValid(activePermit).valid) {
2575
2575
  return activePermit;
2576
2576
  }
2577
2577
  return createSharing(options, publicClient, walletClient);
@@ -2830,6 +2830,29 @@ async function cofheMocksDecryptForView(ctHash, utype, permit, publicClient) {
2830
2830
  return unsealed;
2831
2831
  }
2832
2832
 
2833
+ // core/debug.ts
2834
+ var interceptors = {};
2835
+ async function cofheFetch(url, init, ctx = { op: "request" }) {
2836
+ let finalUrl = url;
2837
+ let finalInit = init;
2838
+ if (interceptors.onRequest) {
2839
+ const override = await interceptors.onRequest(finalUrl, finalInit, ctx);
2840
+ if (override) {
2841
+ if (override.url !== void 0)
2842
+ finalUrl = override.url;
2843
+ if (override.init !== void 0)
2844
+ finalInit = override.init;
2845
+ }
2846
+ }
2847
+ let response = await fetch(finalUrl, finalInit);
2848
+ if (interceptors.onResponse) {
2849
+ const replaced = await interceptors.onResponse(response, ctx);
2850
+ if (replaced)
2851
+ response = replaced;
2852
+ }
2853
+ return response;
2854
+ }
2855
+
2833
2856
  // core/decrypt/polling.ts
2834
2857
  function computeMinuteRampPollIntervalMs(elapsedMs, params) {
2835
2858
  const elapsedSeconds = Math.floor(elapsedMs / 1e3);
@@ -2999,13 +3022,17 @@ async function submitSealOutputRequest(thresholdNetworkUrl, ctHash, chainId, per
2999
3022
  for (; ; ) {
3000
3023
  let response;
3001
3024
  try {
3002
- response = await fetch(`${thresholdNetworkUrl}/v2/sealoutput`, {
3003
- method: "POST",
3004
- headers: {
3005
- "Content-Type": "application/json"
3006
- },
3007
- body: JSON.stringify(body)
3008
- });
3025
+ response = await cofheFetch(
3026
+ `${thresholdNetworkUrl}/v2/sealoutput`,
3027
+ /*op:sealoutput*/
3028
+ {
3029
+ method: "POST",
3030
+ headers: {
3031
+ "Content-Type": "application/json"
3032
+ },
3033
+ body: JSON.stringify(body)
3034
+ }
3035
+ );
3009
3036
  } catch (e) {
3010
3037
  throw new CofheError({
3011
3038
  code: "SEAL_OUTPUT_FAILED" /* SealOutputFailed */,
@@ -3128,12 +3155,16 @@ async function pollSealOutputStatus(thresholdNetworkUrl, requestId, overallStart
3128
3155
  }
3129
3156
  let response;
3130
3157
  try {
3131
- response = await fetch(`${thresholdNetworkUrl}/v2/sealoutput/${requestId}`, {
3132
- method: "GET",
3133
- headers: {
3134
- "Content-Type": "application/json"
3158
+ response = await cofheFetch(
3159
+ `${thresholdNetworkUrl}/v2/sealoutput/${requestId}`,
3160
+ /*op:sealoutput-poll*/
3161
+ {
3162
+ method: "GET",
3163
+ headers: {
3164
+ "Content-Type": "application/json"
3165
+ }
3135
3166
  }
3136
- });
3167
+ );
3137
3168
  } catch (e) {
3138
3169
  throw new CofheError({
3139
3170
  code: "SEAL_OUTPUT_FAILED" /* SealOutputFailed */,
@@ -3730,13 +3761,17 @@ async function submitDecryptRequestV2(thresholdNetworkUrl, ctHash, chainId, perm
3730
3761
  for (; ; ) {
3731
3762
  let response;
3732
3763
  try {
3733
- response = await fetch(`${thresholdNetworkUrl}/v2/decrypt`, {
3734
- method: "POST",
3735
- headers: {
3736
- "Content-Type": "application/json"
3737
- },
3738
- body: JSON.stringify(body)
3739
- });
3764
+ response = await cofheFetch(
3765
+ `${thresholdNetworkUrl}/v2/decrypt`,
3766
+ /*op:decrypt*/
3767
+ {
3768
+ method: "POST",
3769
+ headers: {
3770
+ "Content-Type": "application/json"
3771
+ },
3772
+ body: JSON.stringify(body)
3773
+ }
3774
+ );
3740
3775
  } catch (e) {
3741
3776
  throw new CofheError({
3742
3777
  code: "DECRYPT_FAILED" /* DecryptFailed */,
@@ -3861,12 +3896,16 @@ async function pollDecryptStatusV2(thresholdNetworkUrl, requestId, overallStartT
3861
3896
  }
3862
3897
  let response;
3863
3898
  try {
3864
- response = await fetch(`${thresholdNetworkUrl}/v2/decrypt/${requestId}`, {
3865
- method: "GET",
3866
- headers: {
3867
- "Content-Type": "application/json"
3899
+ response = await cofheFetch(
3900
+ `${thresholdNetworkUrl}/v2/decrypt/${requestId}`,
3901
+ /*op:decrypt-poll*/
3902
+ {
3903
+ method: "GET",
3904
+ headers: {
3905
+ "Content-Type": "application/json"
3906
+ }
3868
3907
  }
3869
- });
3908
+ );
3870
3909
  } catch (e) {
3871
3910
  throw new CofheError({
3872
3911
  code: "DECRYPT_FAILED" /* DecryptFailed */,
package/dist/node.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createCofheConfigBase, createCofheClientBase } from './chunk-PE5V5CCV.js';
1
+ import { createCofheConfigBase, createCofheClientBase } from './chunk-NOC3PYB7.js';
2
2
  import './chunk-MTRAXQXC.js';
3
3
  import './chunk-VB62WYPL.js';
4
4
  import { TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT } from './chunk-ESMZCFJY.js';
package/dist/web.cjs CHANGED
@@ -2597,7 +2597,7 @@ var getOrCreateSelfPermit = async (publicClient, walletClient, chainId, account,
2597
2597
  const _chainId = chainId ?? await publicClient.getChainId();
2598
2598
  const _account = account ?? walletClient.account.address;
2599
2599
  const activePermit = await getActivePermit2(_chainId, _account);
2600
- if (activePermit && activePermit.type === "self") {
2600
+ if (activePermit && activePermit.type === "self" && PermitUtils.isValid(activePermit).valid) {
2601
2601
  return activePermit;
2602
2602
  }
2603
2603
  return createSelf(options ?? { issuer: _account, name: "Autogenerated Self Permit" }, publicClient, walletClient);
@@ -2606,7 +2606,7 @@ var getOrCreateSharingPermit = async (publicClient, walletClient, options, chain
2606
2606
  const _chainId = chainId ?? await publicClient.getChainId();
2607
2607
  const _account = account ?? walletClient.account.address;
2608
2608
  const activePermit = await getActivePermit2(_chainId, _account);
2609
- if (activePermit && activePermit.type === "sharing") {
2609
+ if (activePermit && activePermit.type === "sharing" && PermitUtils.isValid(activePermit).valid) {
2610
2610
  return activePermit;
2611
2611
  }
2612
2612
  return createSharing(options, publicClient, walletClient);
@@ -2865,6 +2865,29 @@ async function cofheMocksDecryptForView(ctHash, utype, permit, publicClient) {
2865
2865
  return unsealed;
2866
2866
  }
2867
2867
 
2868
+ // core/debug.ts
2869
+ var interceptors = {};
2870
+ async function cofheFetch(url, init, ctx = { op: "request" }) {
2871
+ let finalUrl = url;
2872
+ let finalInit = init;
2873
+ if (interceptors.onRequest) {
2874
+ const override = await interceptors.onRequest(finalUrl, finalInit, ctx);
2875
+ if (override) {
2876
+ if (override.url !== void 0)
2877
+ finalUrl = override.url;
2878
+ if (override.init !== void 0)
2879
+ finalInit = override.init;
2880
+ }
2881
+ }
2882
+ let response = await fetch(finalUrl, finalInit);
2883
+ if (interceptors.onResponse) {
2884
+ const replaced = await interceptors.onResponse(response, ctx);
2885
+ if (replaced)
2886
+ response = replaced;
2887
+ }
2888
+ return response;
2889
+ }
2890
+
2868
2891
  // core/decrypt/polling.ts
2869
2892
  function computeMinuteRampPollIntervalMs(elapsedMs, params) {
2870
2893
  const elapsedSeconds = Math.floor(elapsedMs / 1e3);
@@ -3034,13 +3057,17 @@ async function submitSealOutputRequest(thresholdNetworkUrl, ctHash, chainId, per
3034
3057
  for (; ; ) {
3035
3058
  let response;
3036
3059
  try {
3037
- response = await fetch(`${thresholdNetworkUrl}/v2/sealoutput`, {
3038
- method: "POST",
3039
- headers: {
3040
- "Content-Type": "application/json"
3041
- },
3042
- body: JSON.stringify(body)
3043
- });
3060
+ response = await cofheFetch(
3061
+ `${thresholdNetworkUrl}/v2/sealoutput`,
3062
+ /*op:sealoutput*/
3063
+ {
3064
+ method: "POST",
3065
+ headers: {
3066
+ "Content-Type": "application/json"
3067
+ },
3068
+ body: JSON.stringify(body)
3069
+ }
3070
+ );
3044
3071
  } catch (e) {
3045
3072
  throw new CofheError({
3046
3073
  code: "SEAL_OUTPUT_FAILED" /* SealOutputFailed */,
@@ -3163,12 +3190,16 @@ async function pollSealOutputStatus(thresholdNetworkUrl, requestId, overallStart
3163
3190
  }
3164
3191
  let response;
3165
3192
  try {
3166
- response = await fetch(`${thresholdNetworkUrl}/v2/sealoutput/${requestId}`, {
3167
- method: "GET",
3168
- headers: {
3169
- "Content-Type": "application/json"
3193
+ response = await cofheFetch(
3194
+ `${thresholdNetworkUrl}/v2/sealoutput/${requestId}`,
3195
+ /*op:sealoutput-poll*/
3196
+ {
3197
+ method: "GET",
3198
+ headers: {
3199
+ "Content-Type": "application/json"
3200
+ }
3170
3201
  }
3171
- });
3202
+ );
3172
3203
  } catch (e) {
3173
3204
  throw new CofheError({
3174
3205
  code: "SEAL_OUTPUT_FAILED" /* SealOutputFailed */,
@@ -3765,13 +3796,17 @@ async function submitDecryptRequestV2(thresholdNetworkUrl, ctHash, chainId, perm
3765
3796
  for (; ; ) {
3766
3797
  let response;
3767
3798
  try {
3768
- response = await fetch(`${thresholdNetworkUrl}/v2/decrypt`, {
3769
- method: "POST",
3770
- headers: {
3771
- "Content-Type": "application/json"
3772
- },
3773
- body: JSON.stringify(body)
3774
- });
3799
+ response = await cofheFetch(
3800
+ `${thresholdNetworkUrl}/v2/decrypt`,
3801
+ /*op:decrypt*/
3802
+ {
3803
+ method: "POST",
3804
+ headers: {
3805
+ "Content-Type": "application/json"
3806
+ },
3807
+ body: JSON.stringify(body)
3808
+ }
3809
+ );
3775
3810
  } catch (e) {
3776
3811
  throw new CofheError({
3777
3812
  code: "DECRYPT_FAILED" /* DecryptFailed */,
@@ -3896,12 +3931,16 @@ async function pollDecryptStatusV2(thresholdNetworkUrl, requestId, overallStartT
3896
3931
  }
3897
3932
  let response;
3898
3933
  try {
3899
- response = await fetch(`${thresholdNetworkUrl}/v2/decrypt/${requestId}`, {
3900
- method: "GET",
3901
- headers: {
3902
- "Content-Type": "application/json"
3934
+ response = await cofheFetch(
3935
+ `${thresholdNetworkUrl}/v2/decrypt/${requestId}`,
3936
+ /*op:decrypt-poll*/
3937
+ {
3938
+ method: "GET",
3939
+ headers: {
3940
+ "Content-Type": "application/json"
3941
+ }
3903
3942
  }
3904
- });
3943
+ );
3905
3944
  } catch (e) {
3906
3945
  throw new CofheError({
3907
3946
  code: "DECRYPT_FAILED" /* DecryptFailed */,
package/dist/web.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createCofheConfigBase, createCofheClientBase, fheTypeToString } from './chunk-PE5V5CCV.js';
1
+ import { createCofheConfigBase, createCofheClientBase, fheTypeToString } from './chunk-NOC3PYB7.js';
2
2
  import './chunk-MTRAXQXC.js';
3
3
  import './chunk-VB62WYPL.js';
4
4
  import { TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT } from './chunk-ESMZCFJY.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cofhe/sdk",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "type": "module",
5
5
  "description": "SDK for Fhenix COFHE coprocessor interaction",
6
6
  "main": "./dist/core.cjs",