@cofhe/sdk 0.6.0 → 0.7.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.
Files changed (114) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/acps/acp.ts +411 -0
  3. package/acps/index.ts +70 -0
  4. package/{permits → acps}/onchain-utils.ts +49 -24
  5. package/acps/sealing.ts +90 -0
  6. package/acps/signature.ts +89 -0
  7. package/acps/store.ts +172 -0
  8. package/acps/test/acp.test.ts +615 -0
  9. package/acps/test/localstorage.test.ts +105 -0
  10. package/acps/test/sealing.test.ts +77 -0
  11. package/acps/test/store.test.ts +88 -0
  12. package/acps/test/validation.test.ts +361 -0
  13. package/acps/test-utils.ts +32 -0
  14. package/acps/types.ts +252 -0
  15. package/acps/validation.ts +392 -0
  16. package/adapters/test/ethers5.test.ts +4 -1
  17. package/adapters/test/ethers6.test.ts +4 -1
  18. package/adapters/test/wagmi.test.ts +5 -2
  19. package/chains/chains/stagingCofhe.ts +21 -0
  20. package/chains/index.ts +3 -1
  21. package/chains/test/chains.test.ts +2 -1
  22. package/core/acps.ts +625 -0
  23. package/core/client.ts +136 -39
  24. package/core/clientTypes.ts +52 -41
  25. package/core/config.ts +66 -5
  26. package/core/debug.ts +72 -0
  27. package/core/decrypt/MockThresholdNetworkAbi.ts +20 -11
  28. package/core/decrypt/apiError.ts +104 -0
  29. package/core/decrypt/cofheMocksDecryptForTx.ts +11 -11
  30. package/core/decrypt/cofheMocksDecryptForView.ts +7 -7
  31. package/core/decrypt/decryptForTxBuilder.ts +102 -102
  32. package/core/decrypt/decryptForViewBuilder.ts +90 -90
  33. package/core/decrypt/submitRetry.ts +38 -30
  34. package/core/decrypt/tnDecryptV1.ts +5 -5
  35. package/core/decrypt/tnDecryptV2.ts +45 -34
  36. package/core/decrypt/tnSealOutputV1.ts +4 -3
  37. package/core/decrypt/tnSealOutputV2.ts +44 -31
  38. package/core/encrypt/cofheMocksZkVerifySign.ts +59 -74
  39. package/core/encrypt/encryptInputsBuilder.ts +86 -52
  40. package/core/encrypt/zkPackProveVerify.ts +25 -18
  41. package/core/error.ts +34 -6
  42. package/core/index.ts +14 -14
  43. package/core/test/acpDefaults.test.ts +52 -0
  44. package/core/test/acps.test.ts +596 -0
  45. package/core/test/apiError.test.ts +130 -0
  46. package/core/test/client.test.ts +22 -19
  47. package/core/test/config.test.ts +25 -5
  48. package/core/test/decrypt.test.ts +40 -35
  49. package/core/test/decryptBuilders.test.ts +68 -68
  50. package/core/test/decryptErrorCodes.test.ts +217 -0
  51. package/core/test/encryptInputsBuilder.test.ts +72 -41
  52. package/core/test/pollCallbacks.test.ts +89 -18
  53. package/core/test/stagingRedirect.ts +18 -0
  54. package/core/test/submitRetry.test.ts +182 -0
  55. package/core/types.ts +9 -69
  56. package/dist/acp-Wi6isVQI.d.cts +407 -0
  57. package/dist/acp-Wi6isVQI.d.ts +407 -0
  58. package/dist/acps.cjs +1081 -0
  59. package/dist/acps.d.cts +480 -0
  60. package/dist/acps.d.ts +480 -0
  61. package/dist/acps.js +2 -0
  62. package/dist/chains.cjs +14 -1
  63. package/dist/chains.d.cts +30 -1
  64. package/dist/chains.d.ts +30 -1
  65. package/dist/chains.js +1 -1
  66. package/dist/{chunk-PE5V5CCV.js → chunk-43USWPEH.js} +1000 -604
  67. package/dist/{chunk-MTRAXQXC.js → chunk-N6IDQRRU.js} +14 -2
  68. package/dist/chunk-Q7CBWGQX.js +1029 -0
  69. package/dist/{clientTypes-CyUvRRzA.d.ts → clientTypes-BN3nbzYM.d.ts} +342 -165
  70. package/dist/{clientTypes-BDy1qIBu.d.cts → clientTypes-CYZjFznO.d.cts} +342 -165
  71. package/dist/core.cjs +1431 -1026
  72. package/dist/core.d.cts +55 -10
  73. package/dist/core.d.ts +55 -10
  74. package/dist/core.js +3 -3
  75. package/dist/node.cjs +1356 -976
  76. package/dist/node.d.cts +2 -2
  77. package/dist/node.d.ts +2 -2
  78. package/dist/node.js +3 -3
  79. package/dist/web.cjs +1356 -976
  80. package/dist/web.d.cts +2 -2
  81. package/dist/web.d.ts +2 -2
  82. package/dist/web.js +3 -3
  83. package/node/test/inherited.test.ts +75 -65
  84. package/node/test/tfheinit.test.ts +23 -8
  85. package/package.json +6 -6
  86. package/web/test/client.web.test.ts +5 -1
  87. package/web/test/inherited.web.test.ts +75 -65
  88. package/web/test/tfheinit.web.test.ts +14 -5
  89. package/web/test/worker.config.web.test.ts +38 -23
  90. package/web/test/worker.output.web.test.ts +25 -24
  91. package/core/encrypt/encryptUtils.ts +0 -67
  92. package/core/permits.ts +0 -206
  93. package/core/test/permits.test.ts +0 -534
  94. package/dist/chunk-VB62WYPL.js +0 -978
  95. package/dist/permit-DnVMDT5h.d.cts +0 -376
  96. package/dist/permit-DnVMDT5h.d.ts +0 -376
  97. package/dist/permits.cjs +0 -1026
  98. package/dist/permits.d.cts +0 -353
  99. package/dist/permits.d.ts +0 -353
  100. package/dist/permits.js +0 -2
  101. package/permits/index.ts +0 -68
  102. package/permits/permit.ts +0 -385
  103. package/permits/sealing.ts +0 -131
  104. package/permits/signature.ts +0 -79
  105. package/permits/store.ts +0 -157
  106. package/permits/test/localstorage.test.ts +0 -113
  107. package/permits/test/permit.test.ts +0 -557
  108. package/permits/test/sealing.test.ts +0 -84
  109. package/permits/test/store.test.ts +0 -88
  110. package/permits/test/validation.test.ts +0 -361
  111. package/permits/test-utils.ts +0 -28
  112. package/permits/types.ts +0 -204
  113. package/permits/validation.ts +0 -327
  114. /package/{permits → acps}/utils.ts +0 -0
package/dist/core.d.cts CHANGED
@@ -1,9 +1,9 @@
1
- import { a as CofheConfig, c as CofheClientParams, b as CofheClient, d as CofheClientConnectionState, F as FheTypes } from './clientTypes-BDy1qIBu.cjs';
2
- export { O as AnyExternalHash, h as CofheClientPermits, C as CofheInputConfig, f as CofheInternalConfig, W as DecryptEndpoint, ab as DecryptForTxBuilder, ac as DecryptForTxResult, aa as DecryptForViewBuilder, V as DecryptPollCallbackContext, T as DecryptPollCallbackFunction, a9 as EncryptInputsBuilder, X as EncryptSetStateFn, a1 as EncryptStep, Y as EncryptStepCallbackContext, $ as Encryptable, o as EncryptableAddress, i as EncryptableBool, E as EncryptableItem, z as EncryptableToEncryptedItemInputMap, Q as EncryptableToExternalHashMap, n as EncryptableUint128, k as EncryptableUint16, l as EncryptableUint32, m as EncryptableUint64, j as EncryptableUint8, x as EncryptedAddressInput, r as EncryptedBoolInput, q as EncryptedItemInput, y as EncryptedItemInputs, p as EncryptedNumber, w as EncryptedUint128Input, t as EncryptedUint16Input, u as EncryptedUint32Input, v as EncryptedUint64Input, s as EncryptedUint8Input, M as ExternalAddressHash, B as ExternalBoolHash, N as ExternalHashProof, R as ExternalItemHashes, K as ExternalUint128Hash, G as ExternalUint16Hash, H as ExternalUint32Hash, J as ExternalUint64Hash, D as ExternalUint8Hash, _ as FheAllUTypes, a5 as FheKeyDeserializer, A as FheTypeValue, Z as FheUintUTypes, S as HashPlusProofResult, I as IStorage, a7 as KeysStorage, a8 as KeysStore, L as LiteralToPrimitive, P as Primitive, U as UnsealedItem, ad as ZkBuilderAndCrsGenerator, ae as ZkProveWorkerFunction, af as ZkProveWorkerRequest, ag as ZkProveWorkerResponse, a3 as assertCorrectEncryptedItemInput, e as createCofheConfigBase, a6 as createKeysStore, a4 as fetchKeys, g as getCofheConfigItem, a0 as isEncryptableItem, a2 as isLastEncryptionStep, ah as zkProveWithWorker } from './clientTypes-BDy1qIBu.cjs';
1
+ import { a as CofheConfig, c as CofheClientParams, b as CofheClient, d as CofheClientConnectionState, F as FheTypes } from './clientTypes-CYZjFznO.cjs';
2
+ export { A as AnyExternalHash, i as CofheClientACPs, C as CofheInputConfig, h as CofheInternalConfig, K as DecryptEndpoint, a2 as DecryptForTxBuilder, a3 as DecryptForTxResult, a1 as DecryptForViewBuilder, J as DecryptPollCallbackContext, G as DecryptPollCallbackFunction, $ as EncryptInputsBuilder, a0 as EncryptInputsBuilderUnset, M as EncryptSetStateFn, T as EncryptStep, N as EncryptStepCallbackContext, R as Encryptable, p as EncryptableAddress, j as EncryptableBool, E as EncryptableItem, B as EncryptableToExternalHashMap, o as EncryptableUint128, l as EncryptableUint16, m as EncryptableUint32, n as EncryptableUint64, k as EncryptableUint8, q as EncryptedNumber, y as ExternalAddressHash, s as ExternalBoolHash, z as ExternalHashProof, D as ExternalItemHashes, x as ExternalUint128Hash, u as ExternalUint16Hash, v as ExternalUint32Hash, w as ExternalUint64Hash, t as ExternalUint8Hash, Q as FheAllUTypes, X as FheKeyDeserializer, r as FheTypeValue, O as FheUintUTypes, H as HashPlusProofResult, I as IStorage, Z as KeysStorage, _ as KeysStore, L as LiteralToPrimitive, P as Primitive, U as UnsealedItem, a4 as ZkBuilderAndCrsGenerator, a5 as ZkProveWorkerFunction, a6 as ZkProveWorkerRequest, a7 as ZkProveWorkerResponse, f as assertNoRenamedConfigKeys, e as createCofheConfigBase, Y as createKeysStore, W as fetchKeys, g as getCofheConfigItem, S as isEncryptableItem, V as isLastEncryptionStep, a8 as zkProveWithWorker } from './clientTypes-CYZjFznO.cjs';
3
3
  import { Hex, PublicClient } from 'viem';
4
4
  import './types-C07FK-cL.cjs';
5
5
  import 'zod';
6
- import './permit-DnVMDT5h.cjs';
6
+ import './acp-Wi6isVQI.cjs';
7
7
  import 'zustand/vanilla';
8
8
 
9
9
  declare const InitialConnectStore: CofheClientConnectionState;
@@ -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",
@@ -25,12 +48,13 @@ declare enum CofheErrorCode {
25
48
  MissingWalletClient = "MISSING_WALLET_CLIENT",
26
49
  MissingProviderParam = "MISSING_PROVIDER_PARAM",
27
50
  EmptySecurityZonesParam = "EMPTY_SECURITY_ZONES_PARAM",
28
- InvalidPermitData = "INVALID_PERMIT_DATA",
29
- InvalidPermitDomain = "INVALID_PERMIT_DOMAIN",
30
- PermitNotFound = "PERMIT_NOT_FOUND",
31
- CannotRemoveLastPermit = "CANNOT_REMOVE_LAST_PERMIT",
51
+ InvalidACPData = "INVALID_ACP_DATA",
52
+ InvalidACPDomain = "INVALID_ACP_DOMAIN",
53
+ ACPNotFound = "ACP_NOT_FOUND",
54
+ CannotRemoveLastACP = "CANNOT_REMOVE_LAST_ACP",
32
55
  AccountUninitialized = "ACCOUNT_UNINITIALIZED",
33
56
  ChainIdUninitialized = "CHAIN_ID_UNINITIALIZED",
57
+ ConsumingContractUninitialized = "CONSUMING_CONTRACT_UNINITIALIZED",
34
58
  SealOutputFailed = "SEAL_OUTPUT_FAILED",
35
59
  SealOutputReturnedNull = "SEAL_OUTPUT_RETURNED_NULL",
36
60
  InvalidUtype = "INVALID_UTYPE",
@@ -57,7 +81,25 @@ declare enum CofheErrorCode {
57
81
  FetchKeysFailed = "FETCH_KEYS_FAILED",
58
82
  PublicWalletGetChainIdFailed = "PUBLIC_WALLET_GET_CHAIN_ID_FAILED",
59
83
  PublicWalletGetAddressesFailed = "PUBLIC_WALLET_GET_ADDRESSES_FAILED",
60
- RehydrateKeysStoreFailed = "REHYDRATE_KEYS_STORE_FAILED"
84
+ RehydrateKeysStoreFailed = "REHYDRATE_KEYS_STORE_FAILED",
85
+ BadRequest = "BAD_REQUEST",
86
+ UnknownChain = "UNKNOWN_CHAIN",
87
+ ACPMalformed = "ACP_MALFORMED",
88
+ ACPDenied = "ACP_DENIED",
89
+ ACPExpired = "ACP_EXPIRED",
90
+ ACPInvalid = "ACP_INVALID",
91
+ ACPRevoked = "ACP_REVOKED",
92
+ NotPubliclyAllowed = "NOT_PUBLICLY_ALLOWED",
93
+ CtNotFound = "CT_NOT_FOUND",
94
+ UnsupportedSecurityZone = "UNSUPPORTED_SECURITY_ZONE",
95
+ UnsupportedType = "UNSUPPORTED_TYPE",
96
+ SigningFailed = "SIGNING_FAILED",
97
+ CtSourceError = "CT_SOURCE_ERROR",
98
+ ACPVerifierError = "ACP_VERIFIER_ERROR",
99
+ CtSourceTimeout = "CT_SOURCE_TIMEOUT",
100
+ ACPVerifierTimeout = "ACP_VERIFIER_TIMEOUT",
101
+ ACPRequired = "ACP_REQUIRED",
102
+ SealFailed = "SEAL_FAILED"
61
103
  }
62
104
  type CofheErrorParams = {
63
105
  code: CofheErrorCode;
@@ -65,6 +107,8 @@ type CofheErrorParams = {
65
107
  cause?: Error;
66
108
  hint?: string;
67
109
  context?: Record<string, unknown>;
110
+ /** Raw backend `error` string, when this error originated from a threshold-network response. */
111
+ apiErrorCode?: string;
68
112
  };
69
113
  /**
70
114
  * CofheError class
@@ -82,7 +126,8 @@ declare class CofheError extends Error {
82
126
  readonly cause?: Error;
83
127
  readonly hint?: string;
84
128
  readonly context?: Record<string, unknown>;
85
- constructor({ code, message, cause, hint, context }: CofheErrorParams);
129
+ readonly apiErrorCode?: string;
130
+ constructor({ code, message, cause, hint, context, apiErrorCode }: CofheErrorParams);
86
131
  /**
87
132
  * Creates a CofheError from an unknown error
88
133
  * If the error is a CofheError, it is returned unchanged, else a new CofheError is created
@@ -137,4 +182,4 @@ declare function verifyDecryptResult(handle: bigint | string, cleartext: bigint,
137
182
  */
138
183
  declare function fheTypeToString(utype: FheTypes): string;
139
184
 
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 };
185
+ 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
@@ -1,9 +1,9 @@
1
- import { a as CofheConfig, c as CofheClientParams, b as CofheClient, d as CofheClientConnectionState, F as FheTypes } from './clientTypes-CyUvRRzA.js';
2
- export { O as AnyExternalHash, h as CofheClientPermits, C as CofheInputConfig, f as CofheInternalConfig, W as DecryptEndpoint, ab as DecryptForTxBuilder, ac as DecryptForTxResult, aa as DecryptForViewBuilder, V as DecryptPollCallbackContext, T as DecryptPollCallbackFunction, a9 as EncryptInputsBuilder, X as EncryptSetStateFn, a1 as EncryptStep, Y as EncryptStepCallbackContext, $ as Encryptable, o as EncryptableAddress, i as EncryptableBool, E as EncryptableItem, z as EncryptableToEncryptedItemInputMap, Q as EncryptableToExternalHashMap, n as EncryptableUint128, k as EncryptableUint16, l as EncryptableUint32, m as EncryptableUint64, j as EncryptableUint8, x as EncryptedAddressInput, r as EncryptedBoolInput, q as EncryptedItemInput, y as EncryptedItemInputs, p as EncryptedNumber, w as EncryptedUint128Input, t as EncryptedUint16Input, u as EncryptedUint32Input, v as EncryptedUint64Input, s as EncryptedUint8Input, M as ExternalAddressHash, B as ExternalBoolHash, N as ExternalHashProof, R as ExternalItemHashes, K as ExternalUint128Hash, G as ExternalUint16Hash, H as ExternalUint32Hash, J as ExternalUint64Hash, D as ExternalUint8Hash, _ as FheAllUTypes, a5 as FheKeyDeserializer, A as FheTypeValue, Z as FheUintUTypes, S as HashPlusProofResult, I as IStorage, a7 as KeysStorage, a8 as KeysStore, L as LiteralToPrimitive, P as Primitive, U as UnsealedItem, ad as ZkBuilderAndCrsGenerator, ae as ZkProveWorkerFunction, af as ZkProveWorkerRequest, ag as ZkProveWorkerResponse, a3 as assertCorrectEncryptedItemInput, e as createCofheConfigBase, a6 as createKeysStore, a4 as fetchKeys, g as getCofheConfigItem, a0 as isEncryptableItem, a2 as isLastEncryptionStep, ah as zkProveWithWorker } from './clientTypes-CyUvRRzA.js';
1
+ import { a as CofheConfig, c as CofheClientParams, b as CofheClient, d as CofheClientConnectionState, F as FheTypes } from './clientTypes-BN3nbzYM.js';
2
+ export { A as AnyExternalHash, i as CofheClientACPs, C as CofheInputConfig, h as CofheInternalConfig, K as DecryptEndpoint, a2 as DecryptForTxBuilder, a3 as DecryptForTxResult, a1 as DecryptForViewBuilder, J as DecryptPollCallbackContext, G as DecryptPollCallbackFunction, $ as EncryptInputsBuilder, a0 as EncryptInputsBuilderUnset, M as EncryptSetStateFn, T as EncryptStep, N as EncryptStepCallbackContext, R as Encryptable, p as EncryptableAddress, j as EncryptableBool, E as EncryptableItem, B as EncryptableToExternalHashMap, o as EncryptableUint128, l as EncryptableUint16, m as EncryptableUint32, n as EncryptableUint64, k as EncryptableUint8, q as EncryptedNumber, y as ExternalAddressHash, s as ExternalBoolHash, z as ExternalHashProof, D as ExternalItemHashes, x as ExternalUint128Hash, u as ExternalUint16Hash, v as ExternalUint32Hash, w as ExternalUint64Hash, t as ExternalUint8Hash, Q as FheAllUTypes, X as FheKeyDeserializer, r as FheTypeValue, O as FheUintUTypes, H as HashPlusProofResult, I as IStorage, Z as KeysStorage, _ as KeysStore, L as LiteralToPrimitive, P as Primitive, U as UnsealedItem, a4 as ZkBuilderAndCrsGenerator, a5 as ZkProveWorkerFunction, a6 as ZkProveWorkerRequest, a7 as ZkProveWorkerResponse, f as assertNoRenamedConfigKeys, e as createCofheConfigBase, Y as createKeysStore, W as fetchKeys, g as getCofheConfigItem, S as isEncryptableItem, V as isLastEncryptionStep, a8 as zkProveWithWorker } from './clientTypes-BN3nbzYM.js';
3
3
  import { Hex, PublicClient } from 'viem';
4
4
  import './types-C07FK-cL.js';
5
5
  import 'zod';
6
- import './permit-DnVMDT5h.js';
6
+ import './acp-Wi6isVQI.js';
7
7
  import 'zustand/vanilla';
8
8
 
9
9
  declare const InitialConnectStore: CofheClientConnectionState;
@@ -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",
@@ -25,12 +48,13 @@ declare enum CofheErrorCode {
25
48
  MissingWalletClient = "MISSING_WALLET_CLIENT",
26
49
  MissingProviderParam = "MISSING_PROVIDER_PARAM",
27
50
  EmptySecurityZonesParam = "EMPTY_SECURITY_ZONES_PARAM",
28
- InvalidPermitData = "INVALID_PERMIT_DATA",
29
- InvalidPermitDomain = "INVALID_PERMIT_DOMAIN",
30
- PermitNotFound = "PERMIT_NOT_FOUND",
31
- CannotRemoveLastPermit = "CANNOT_REMOVE_LAST_PERMIT",
51
+ InvalidACPData = "INVALID_ACP_DATA",
52
+ InvalidACPDomain = "INVALID_ACP_DOMAIN",
53
+ ACPNotFound = "ACP_NOT_FOUND",
54
+ CannotRemoveLastACP = "CANNOT_REMOVE_LAST_ACP",
32
55
  AccountUninitialized = "ACCOUNT_UNINITIALIZED",
33
56
  ChainIdUninitialized = "CHAIN_ID_UNINITIALIZED",
57
+ ConsumingContractUninitialized = "CONSUMING_CONTRACT_UNINITIALIZED",
34
58
  SealOutputFailed = "SEAL_OUTPUT_FAILED",
35
59
  SealOutputReturnedNull = "SEAL_OUTPUT_RETURNED_NULL",
36
60
  InvalidUtype = "INVALID_UTYPE",
@@ -57,7 +81,25 @@ declare enum CofheErrorCode {
57
81
  FetchKeysFailed = "FETCH_KEYS_FAILED",
58
82
  PublicWalletGetChainIdFailed = "PUBLIC_WALLET_GET_CHAIN_ID_FAILED",
59
83
  PublicWalletGetAddressesFailed = "PUBLIC_WALLET_GET_ADDRESSES_FAILED",
60
- RehydrateKeysStoreFailed = "REHYDRATE_KEYS_STORE_FAILED"
84
+ RehydrateKeysStoreFailed = "REHYDRATE_KEYS_STORE_FAILED",
85
+ BadRequest = "BAD_REQUEST",
86
+ UnknownChain = "UNKNOWN_CHAIN",
87
+ ACPMalformed = "ACP_MALFORMED",
88
+ ACPDenied = "ACP_DENIED",
89
+ ACPExpired = "ACP_EXPIRED",
90
+ ACPInvalid = "ACP_INVALID",
91
+ ACPRevoked = "ACP_REVOKED",
92
+ NotPubliclyAllowed = "NOT_PUBLICLY_ALLOWED",
93
+ CtNotFound = "CT_NOT_FOUND",
94
+ UnsupportedSecurityZone = "UNSUPPORTED_SECURITY_ZONE",
95
+ UnsupportedType = "UNSUPPORTED_TYPE",
96
+ SigningFailed = "SIGNING_FAILED",
97
+ CtSourceError = "CT_SOURCE_ERROR",
98
+ ACPVerifierError = "ACP_VERIFIER_ERROR",
99
+ CtSourceTimeout = "CT_SOURCE_TIMEOUT",
100
+ ACPVerifierTimeout = "ACP_VERIFIER_TIMEOUT",
101
+ ACPRequired = "ACP_REQUIRED",
102
+ SealFailed = "SEAL_FAILED"
61
103
  }
62
104
  type CofheErrorParams = {
63
105
  code: CofheErrorCode;
@@ -65,6 +107,8 @@ type CofheErrorParams = {
65
107
  cause?: Error;
66
108
  hint?: string;
67
109
  context?: Record<string, unknown>;
110
+ /** Raw backend `error` string, when this error originated from a threshold-network response. */
111
+ apiErrorCode?: string;
68
112
  };
69
113
  /**
70
114
  * CofheError class
@@ -82,7 +126,8 @@ declare class CofheError extends Error {
82
126
  readonly cause?: Error;
83
127
  readonly hint?: string;
84
128
  readonly context?: Record<string, unknown>;
85
- constructor({ code, message, cause, hint, context }: CofheErrorParams);
129
+ readonly apiErrorCode?: string;
130
+ constructor({ code, message, cause, hint, context, apiErrorCode }: CofheErrorParams);
86
131
  /**
87
132
  * Creates a CofheError from an unknown error
88
133
  * If the error is a CofheError, it is returned unchanged, else a new CofheError is created
@@ -137,4 +182,4 @@ declare function verifyDecryptResult(handle: bigint | string, cleartext: bigint,
137
182
  */
138
183
  declare function fheTypeToString(utype: FheTypes): string;
139
184
 
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 };
185
+ 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';
2
- import './chunk-MTRAXQXC.js';
3
- import './chunk-VB62WYPL.js';
1
+ export { InitialConnectStore as CONNECT_STORE_DEFAULTS, CofheError, CofheErrorCode, DecryptForTxBuilder, DecryptForViewBuilder, EncryptInputsBuilder, EncryptStep, Encryptable, FheAllUTypes, FheTypes, FheUintUTypes, assertNoRenamedConfigKeys, cofheFetch, createCofheClientBase, createCofheConfigBase, createKeysStore, fetchKeys, fheTypeToString, getCofheConfigItem, getCofheDebugInterceptors, isCofheError, isEncryptableItem, isLastEncryptionStep, setCofheDebugInterceptors, verifyDecryptResult, zkProveWithWorker } from './chunk-43USWPEH.js';
2
+ import './chunk-N6IDQRRU.js';
3
+ import './chunk-Q7CBWGQX.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';