@cofhe/react 0.0.0-beta-20260402091708 → 0.0.0-beta-20260402100620

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/dist/index.cjs CHANGED
@@ -750,8 +750,6 @@ __export(index_exports, {
750
750
  actionToString: () => actionToString,
751
751
  createCofheClient: () => import_web4.createCofheClient,
752
752
  createCofheConfig: () => createCofheConfig,
753
- encryptedValueToString: () => encryptedValueToString,
754
- fheTypeToString: () => fheTypeToString,
755
753
  formatRelativeTime: () => formatRelativeTime,
756
754
  getBlockExplorerAddressUrl: () => getBlockExplorerAddressUrl,
757
755
  getBlockExplorerTokenUrl: () => getBlockExplorerTokenUrl,
@@ -1035,33 +1033,6 @@ function isReactNode(data) {
1035
1033
  return false;
1036
1034
  }
1037
1035
 
1038
- // src/utils/logging.ts
1039
- var fheTypeToString = (fheType) => {
1040
- switch (fheType) {
1041
- case "bool":
1042
- return "ebool";
1043
- case "uint8":
1044
- return "euint8";
1045
- case "uint16":
1046
- return "euint16";
1047
- case "uint32":
1048
- return "euint32";
1049
- case "uint64":
1050
- return "euint64";
1051
- case "uint128":
1052
- return "euint128";
1053
- case "address":
1054
- return "eaddress";
1055
- default:
1056
- return "unknown";
1057
- }
1058
- };
1059
- var encryptedValueToString = (fheType, handle) => {
1060
- const hashStr = handle.toString();
1061
- const truncated = hashStr.slice(0, 6) + ".." + hashStr.slice(hashStr.length - 6);
1062
- return `${fheTypeToString(fheType)}(${truncated})`;
1063
- };
1064
-
1065
1036
  // src/utils/debounce.ts
1066
1037
  var debounce = (func, wait) => {
1067
1038
  let timeoutId = null;
@@ -1077,6 +1048,22 @@ var debounce = (func, wait) => {
1077
1048
 
1078
1049
  // src/utils/waitUntilRpcAwareAndReadContract.ts
1079
1050
  var import_viem = require("viem");
1051
+
1052
+ // src/utils/debug.ts
1053
+ var noopCofheReactLoggerMethod = (..._args) => {
1054
+ };
1055
+ var NOOP_LOGGER = {
1056
+ log: noopCofheReactLoggerMethod,
1057
+ warn: noopCofheReactLoggerMethod,
1058
+ debug: noopCofheReactLoggerMethod,
1059
+ error: noopCofheReactLoggerMethod
1060
+ };
1061
+ var cofheLogger = NOOP_LOGGER;
1062
+ function setReactLogger(logger) {
1063
+ cofheLogger = logger ?? NOOP_LOGGER;
1064
+ }
1065
+
1066
+ // src/utils/waitUntilRpcAwareAndReadContract.ts
1080
1067
  function abortError(message = "Aborted") {
1081
1068
  const err = new Error(message);
1082
1069
  err.name = "AbortError";
@@ -1110,7 +1097,7 @@ async function maybeWaitUntilRpcAwareAndReadContract(publicClient, params, optio
1110
1097
  args: params.args
1111
1098
  });
1112
1099
  const pollingInterval = options.pollingInterval ?? 1e3;
1113
- console.log(`Waiting until RPC is aware of block ${params.blockHashToBeAwareOf} to read contract...`);
1100
+ cofheLogger.log(`Waiting until RPC is aware of block ${params.blockHashToBeAwareOf} to read contract...`);
1114
1101
  let done = false;
1115
1102
  while (!done) {
1116
1103
  if (options.signal?.aborted) throw abortError();
@@ -2198,7 +2185,7 @@ function decryptionAwareReadContract({
2198
2185
  }) {
2199
2186
  const decryptionWatchersState = useDecryptionWatchersStore.getState();
2200
2187
  const blockHashToBeAwareOf = decryptionWatchersState.findObservedDecryption(queryKey)?.decryptionObservedAt?.blockHash;
2201
- console.log("Tracked decryption block for unshield claims:", blockHashToBeAwareOf);
2188
+ cofheLogger.log("Tracked decryption block for unshield claims:", blockHashToBeAwareOf);
2202
2189
  const rpcAwarenessOptions = {
2203
2190
  signal,
2204
2191
  pollingInterval: BLOCK_AWARENESS_POLLING_INTERVAL,
@@ -2229,7 +2216,7 @@ function useAwaitingDecryptionQueryKeySet() {
2229
2216
  function useIsWaitingForDecryptionToInvalidate(queryKey) {
2230
2217
  const cacheKeySet = useAwaitingDecryptionQueryKeySet();
2231
2218
  const result = (0, import_react7.useMemo)(() => cacheKeySet.has(JSON.stringify(queryKey)), [cacheKeySet, queryKey]);
2232
- console.log(`isWaitingForDecryption for queryKey ${JSON.stringify(queryKey)}:`, result);
2219
+ cofheLogger.log(`isWaitingForDecryption for queryKey ${JSON.stringify(queryKey)}:`, result);
2233
2220
  return result;
2234
2221
  }
2235
2222
 
@@ -2248,7 +2235,7 @@ function invalidateClaimableQueries({
2248
2235
  accountAddress,
2249
2236
  queryClient
2250
2237
  }) {
2251
- console.log("Invalidating unshield claims queries for token:", token);
2238
+ cofheLogger.log("Invalidating unshield claims queries for token:", token);
2252
2239
  queryClient.invalidateQueries({
2253
2240
  queryKey: constructUnshieldClaimsQueryKeyForInvalidation({
2254
2241
  chainId: token.chainId,
@@ -2649,7 +2636,7 @@ var usePortalNavigation = (0, import_zustand6.create)()((set, get) => {
2649
2636
  const currentPage = get().overridingPage ?? get().pageHistory[get().pageHistory.length - 1];
2650
2637
  const onPage = currentPage?.page === page;
2651
2638
  if (onPage) {
2652
- console.warn(`Attempted to navigate to page ${page} but already on that page`);
2639
+ cofheLogger.warn(`Attempted to navigate to page ${page} but already on that page`);
2653
2640
  }
2654
2641
  return onPage;
2655
2642
  }
@@ -2918,7 +2905,7 @@ function useTransactionGlobalToastsLifecycle() {
2918
2905
  return {
2919
2906
  // 1.tx is submitted
2920
2907
  onTransactionSubmitted: (transaction) => {
2921
- console.log("____ Transaction submitted:", transaction);
2908
+ cofheLogger.log("____ Transaction submitted:", transaction);
2922
2909
  addToast(
2923
2910
  {
2924
2911
  variant: "info",
@@ -2954,7 +2941,7 @@ function useTransactionGlobalToastsLifecycle() {
2954
2941
  },
2955
2942
  // 2.a. tx is mined (could be success or fail)
2956
2943
  onTransactionMined: (transaction, receipt) => {
2957
- console.log("____ Transaction mined:", transaction, "with receipt:", receipt);
2944
+ cofheLogger.log("____ Transaction mined:", transaction, "with receipt:", receipt);
2958
2945
  if (receipt.status === "success") {
2959
2946
  const descriptionPostfix = transaction.isPendingDecryption ? " It is pending decryption now." : "";
2960
2947
  addToast(
@@ -3003,7 +2990,7 @@ function useTransactionGlobalToastsLifecycle() {
3003
2990
  },
3004
2991
  // 3. tx is decrypted (if applicable)
3005
2992
  onTransactionDecrypted: (decryptionCausingTx, decryptionWatcher) => {
3006
- console.log("____ Transaction decrypted:", decryptionCausingTx, "with watcher:", decryptionWatcher);
2993
+ cofheLogger.log("____ Transaction decrypted:", decryptionCausingTx, "with watcher:", decryptionWatcher);
3007
2994
  addToast(
3008
2995
  {
3009
2996
  variant: "success",
@@ -3044,7 +3031,7 @@ function invalidateConfidentialTokenBalanceQueries(token, queryClient) {
3044
3031
  address: token.address,
3045
3032
  functionName: getTokenContractConfig(token.extensions.fhenix.confidentialityType).functionName
3046
3033
  });
3047
- console.log("Invalidating shield/send read contract queries for token:", token);
3034
+ cofheLogger.log("Invalidating shield/send read contract queries for token:", token);
3048
3035
  queryClient.invalidateQueries({
3049
3036
  queryKey: tokenBalanceQueryKey,
3050
3037
  // TODO: it can potentially invalidate irrelevenat queries who happen to belong to the same contract but different function. Not sure if worth fixing
@@ -3061,7 +3048,7 @@ function invalidatePublicTokenBalanceQueries({
3061
3048
  tokenAddress,
3062
3049
  accountAddress
3063
3050
  });
3064
- console.log("Invalidating public token balance read contract queries for token:", tokenBalanceQueryKey);
3051
+ cofheLogger.log("Invalidating public token balance read contract queries for token:", tokenBalanceQueryKey);
3065
3052
  queryClient.invalidateQueries({
3066
3053
  queryKey: tokenBalanceQueryKey
3067
3054
  });
@@ -3130,7 +3117,7 @@ function useTrackPendingTransactionsBase({
3130
3117
  function useHandleInvalidations() {
3131
3118
  const queryClient = useInternalQueryClient();
3132
3119
  const { upsert: upsertDecryptionWatcher, byKey } = useDecryptionWatchersStore();
3133
- console.log("Scheduled invalidations store:", byKey);
3120
+ cofheLogger.log("Scheduled invalidations store:", byKey);
3134
3121
  const handleInvalidations = (tx) => {
3135
3122
  invalidatePublicTokenBalanceQueries(
3136
3123
  {
@@ -3267,7 +3254,7 @@ function useTransactionReceiptsByHash({ hashes, chainId: chainIdInput, enabled:
3267
3254
  queries
3268
3255
  });
3269
3256
  const receiptsByHash = (0, import_react13.useMemo)(() => {
3270
- console.log("useTransactionReceiptsByHash - receiptsByHash recalculated");
3257
+ cofheLogger.log("useTransactionReceiptsByHash - receiptsByHash recalculated");
3271
3258
  if (!hashes) return {};
3272
3259
  return Array.from(hashes).reduce((acc, hash, i) => {
3273
3260
  if (!queriesResults[i]?.data) return acc;
@@ -3393,10 +3380,10 @@ function useCofheReadDecryptionResults(ciphertexts) {
3393
3380
  function useHandleInvalidationsAfterDecryption() {
3394
3381
  const queryClient = useInternalQueryClient();
3395
3382
  return (0, import_react15.useCallback)(
3396
- async (tx, decryptionWatcher) => {
3397
- console.log("Invalidating queries for decryption watcher:", decryptionWatcher);
3383
+ async (_tx, decryptionWatcher) => {
3384
+ cofheLogger.log("Invalidating queries for decryption watcher:", decryptionWatcher);
3398
3385
  for (const queryKey of decryptionWatcher.queryKeys) {
3399
- console.log("Invalidating query due to observed decryption:", queryKey);
3386
+ cofheLogger.log("Invalidating query due to observed decryption:", queryKey);
3400
3387
  await queryClient.invalidateQueries({ queryKey });
3401
3388
  }
3402
3389
  },
@@ -3451,7 +3438,7 @@ function useTrackDecryptingTransactionsBase({ onDecryptionResolve }) {
3451
3438
  false
3452
3439
  // no longer pending decryption
3453
3440
  );
3454
- console.log("Decryption completed for tx, invalidating relevant queries", {
3441
+ cofheLogger.log("Decryption completed for tx, invalidating relevant queries", {
3455
3442
  tx,
3456
3443
  decryptionResult,
3457
3444
  receipt,
@@ -3474,7 +3461,7 @@ function useOnDecryptionCallback({ onDecryptionResolve }) {
3474
3461
  () => Object.values(byKey).filter((item) => item.decryptionObservedAt !== void 0),
3475
3462
  [byKey]
3476
3463
  );
3477
- console.log("All observed decryptions:", watchersWithObservedDecryption);
3464
+ cofheLogger.log("All observed decryptions:", watchersWithObservedDecryption);
3478
3465
  const handleDecryptionResolve = (0, import_react15.useCallback)(async () => {
3479
3466
  const transactionStore = useTransactionStore.getState().transactions;
3480
3467
  for (const sch of watchersWithObservedDecryption) {
@@ -3489,7 +3476,7 @@ function useOnDecryptionCallback({ onDecryptionResolve }) {
3489
3476
  }, [handleDecryptionResolve]);
3490
3477
  (0, import_react15.useEffect)(() => {
3491
3478
  if (watchersWithObservedDecryption.length > 0) {
3492
- console.log("All observed decryption query keys subject to invalidate:", watchersWithObservedDecryption);
3479
+ cofheLogger.log("All observed decryption query keys subject to invalidate:", watchersWithObservedDecryption);
3493
3480
  stableHandleDecryptionResolve.current();
3494
3481
  }
3495
3482
  }, [watchersWithObservedDecryption]);
@@ -3517,7 +3504,7 @@ function useTrackDecryptingTransactions() {
3517
3504
  const { onTransactionDecrypted } = useTransactionGlobalLifecycle();
3518
3505
  useTrackDecryptingTransactionsBase({
3519
3506
  onDecryptionResolve: async (decryptionCausingTx, decryptionWatcher) => {
3520
- console.log("Decryption resolved for tx:", decryptionCausingTx, "with watcher:", decryptionWatcher);
3507
+ cofheLogger.log("Decryption resolved for tx:", decryptionCausingTx, "with watcher:", decryptionWatcher);
3521
3508
  handleInvalidationsAfterDecryption(decryptionCausingTx, decryptionWatcher);
3522
3509
  onTransactionDecrypted(decryptionCausingTx, decryptionWatcher);
3523
3510
  }
@@ -3571,21 +3558,6 @@ function useCofheDecrypt({
3571
3558
  });
3572
3559
  }
3573
3560
 
3574
- // src/utils/isProduction.ts
3575
- var import_meta = {};
3576
- var isProduction = () => {
3577
- if (typeof process !== "undefined" && process.env?.NODE_ENV === "development") {
3578
- return false;
3579
- }
3580
- if (typeof import_meta !== "undefined") {
3581
- const metaEnv = import_meta.env;
3582
- if (metaEnv && metaEnv.MODE === "development" && metaEnv.DEV === true && metaEnv.PROD === false) {
3583
- return false;
3584
- }
3585
- }
3586
- return true;
3587
- };
3588
-
3589
3561
  // src/hooks/useCofheReadContractAndDecrypt.ts
3590
3562
  function isEncryptedValue(value) {
3591
3563
  return typeof value === "object" && value !== null && "ctHash" in value && "utype" in value && Object.values(import_sdk5.FheTypes).includes(value.utype);
@@ -3596,8 +3568,8 @@ function convertCofheReturnTypeToEncryptedReturnType(value) {
3596
3568
  "Auto-decryption now only supports a case where the contract function returns a single encrypted value"
3597
3569
  );
3598
3570
  }
3599
- var onPoll = isProduction() ? void 0 : (context) => {
3600
- console.debug(
3571
+ var onPoll = (context) => {
3572
+ cofheLogger.debug(
3601
3573
  `Decryption poll attemptIndex ${context.attemptIndex}. Operation: ${context.operation}. ${context.elapsedMs}ms elapsed. Request ID: ${context.requestId}.`
3602
3574
  );
3603
3575
  };
@@ -6844,6 +6816,21 @@ var TransactionItem = ({ transaction }) => {
6844
6816
  ] }) });
6845
6817
  };
6846
6818
 
6819
+ // src/utils/isProduction.ts
6820
+ var import_meta = {};
6821
+ var isProduction = () => {
6822
+ if (typeof process !== "undefined" && process.env?.NODE_ENV === "development") {
6823
+ return false;
6824
+ }
6825
+ if (typeof import_meta !== "undefined") {
6826
+ const metaEnv = import_meta.env;
6827
+ if (metaEnv && metaEnv.MODE === "development" && metaEnv.DEV === true && metaEnv.PROD === false) {
6828
+ return false;
6829
+ }
6830
+ }
6831
+ return true;
6832
+ };
6833
+
6847
6834
  // src/components/FnxFloatingButton/pages/MainPage/BottomNavigation.tsx
6848
6835
  var import_jsx_runtime28 = require("react/jsx-runtime");
6849
6836
  var iconClassName = "w-4 h-4";
@@ -10140,6 +10127,31 @@ var import_zod = require("zod");
10140
10127
  var import_sdk10 = require("@cofhe/sdk");
10141
10128
  var import_web2 = require("@cofhe/sdk/web");
10142
10129
  var import_viem26 = require("viem");
10130
+ var noopCofheReactLoggerMethod2 = (..._args) => {
10131
+ };
10132
+ var NOOP_COFHE_REACT_LOGGER = {
10133
+ log: noopCofheReactLoggerMethod2,
10134
+ warn: noopCofheReactLoggerMethod2,
10135
+ debug: noopCofheReactLoggerMethod2,
10136
+ error: noopCofheReactLoggerMethod2
10137
+ };
10138
+ function resolveLoggerMethod(method) {
10139
+ return typeof method === "function" ? method : noopCofheReactLoggerMethod2;
10140
+ }
10141
+ function resolveCofheReactLogger(logger) {
10142
+ if (logger === null || logger === void 0) return NOOP_COFHE_REACT_LOGGER;
10143
+ if (typeof logger !== "object") return NOOP_COFHE_REACT_LOGGER;
10144
+ const obj = logger;
10145
+ return {
10146
+ log: resolveLoggerMethod(obj.log),
10147
+ warn: resolveLoggerMethod(obj.warn),
10148
+ debug: resolveLoggerMethod(obj.debug),
10149
+ error: resolveLoggerMethod(obj.error)
10150
+ };
10151
+ }
10152
+ var CofheReactLoggerSchema = import_zod.z.custom((value) => value === null || typeof value === "object" && value !== null, {
10153
+ error: "Invalid logger"
10154
+ }).optional().default(null).transform((value) => resolveCofheReactLogger(value));
10143
10155
  var addressSchema = import_zod.z.string().refine((val) => (0, import_viem26.isAddress)(val), {
10144
10156
  error: "Invalid address"
10145
10157
  }).refine((val) => val !== import_viem26.zeroAddress, {
@@ -10149,6 +10161,7 @@ var CofheReactConfigSchema = import_zod.z.object({
10149
10161
  shareablePermits: import_zod.z.boolean().optional().default(false),
10150
10162
  enableShieldUnshield: import_zod.z.boolean().optional().default(true),
10151
10163
  autogeneratePermits: import_zod.z.boolean().optional().default(true),
10164
+ logger: CofheReactLoggerSchema,
10152
10165
  permitExpirationOptions: import_zod.z.array(
10153
10166
  import_zod.z.object({
10154
10167
  label: import_zod.z.string(),
@@ -10178,6 +10191,7 @@ function createCofheConfig(config) {
10178
10191
  cause: reactConfigResult.error
10179
10192
  });
10180
10193
  }
10194
+ setReactLogger(reactConfigResult.data.logger);
10181
10195
  return {
10182
10196
  ...webClientConfig,
10183
10197
  react: reactConfigResult.data
@@ -10194,7 +10208,7 @@ function CofheProvider(props) {
10194
10208
  const config = (0, import_react64.useMemo)(() => {
10195
10209
  if (props.config) return props.config;
10196
10210
  if (props.cofheClient) {
10197
- (0, import_ts_essentials25.assert)(config.environment === "react", "Provided cofheClient must have react config");
10211
+ (0, import_ts_essentials25.assert)(props.cofheClient.config.environment === "react", "Provided cofheClient must have react config");
10198
10212
  return props.cofheClient.config;
10199
10213
  }
10200
10214
  return createCofheConfig({ supportedChains: Object.values(import_chains5.chains) });
@@ -10280,7 +10294,7 @@ var FnxEncryptInput = ({
10280
10294
  }, [lastEncryptionStep]);
10281
10295
  const debouncedValidation = (0, import_react65.useRef)(
10282
10296
  debounce((value) => {
10283
- console.log("Debounced validation for:", value);
10297
+ cofheLogger.log("Debounced validation for:", value);
10284
10298
  }, debounceMs)
10285
10299
  ).current;
10286
10300
  (0, import_react65.useEffect)(() => {
@@ -10403,7 +10417,7 @@ var FnxEncryptInput = ({
10403
10417
  2
10404
10418
  );
10405
10419
  await navigator.clipboard.writeText(textToCopy);
10406
- console.log("Copied to clipboard:", textToCopy);
10420
+ cofheLogger.log("Copied to clipboard:", textToCopy);
10407
10421
  setCopySuccess(true);
10408
10422
  setTimeout(() => {
10409
10423
  setCopySuccess(false);
@@ -10418,7 +10432,7 @@ var FnxEncryptInput = ({
10418
10432
  onTypeChange?.(type);
10419
10433
  if (textValue.trim() !== "") {
10420
10434
  try {
10421
- console.log("Auto-encrypting value:", textValue, "as type:", type);
10435
+ cofheLogger.log("Auto-encrypting value:", textValue, "as type:", type);
10422
10436
  onEncryptStart?.({ value: textValue, type });
10423
10437
  (async () => {
10424
10438
  try {
@@ -10564,8 +10578,6 @@ var import_web4 = require("@cofhe/sdk/web");
10564
10578
  actionToString,
10565
10579
  createCofheClient,
10566
10580
  createCofheConfig,
10567
- encryptedValueToString,
10568
- fheTypeToString,
10569
10581
  formatRelativeTime,
10570
10582
  getBlockExplorerAddressUrl,
10571
10583
  getBlockExplorerTokenUrl,