@cofhe/sdk 0.2.1 → 0.3.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 +34 -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 +3 -3
- 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
package/dist/core.d.cts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
export { h as
|
|
1
|
+
import { c as CofheClientConnectionState, a as CofheConfig, d as CofheClientParams, b as CofheClient, F as FheTypes } from './clientTypes-Bhq7pCSA.cjs';
|
|
2
|
+
export { h as CofheClientPermits, C as CofheInputConfig, f as CofheInternalConfig, Y as DecryptForTxBuilder, Z as DecryptForTxResult, X as DecryptForViewBuilder, W as EncryptInputsBuilder, B as EncryptSetStateFn, M as EncryptStep, D as EncryptStepCallbackContext, J as Encryptable, o as EncryptableAddress, i as EncryptableBool, E as EncryptableItem, z as EncryptableToEncryptedItemInputMap, 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, H as FheAllUTypes, R as FheKeyDeserializer, A as FheTypeValue, G as FheUintUTypes, I as IStorage, T as KeysStorage, V as KeysStore, L as LiteralToPrimitive, P as Primitive, U as UnsealedItem, _ as ZkBuilderAndCrsGenerator, $ as ZkProveWorkerFunction, a0 as ZkProveWorkerRequest, a1 as ZkProveWorkerResponse, O as assertCorrectEncryptedItemInput, e as createCofheConfigBase, S as createKeysStore, Q as fetchKeys, g as getCofheConfigItem, K as isEncryptableItem, N as isLastEncryptionStep, a2 as zkProveWithWorker } from './clientTypes-Bhq7pCSA.cjs';
|
|
3
3
|
import 'viem';
|
|
4
4
|
import './types-YiAC4gig.cjs';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import './permit-MZ502UBl.cjs';
|
|
7
7
|
import 'zustand/vanilla';
|
|
8
8
|
|
|
9
|
-
declare const InitialConnectStore:
|
|
9
|
+
declare const InitialConnectStore: CofheClientConnectionState;
|
|
10
10
|
/**
|
|
11
|
-
* Creates a CoFHE
|
|
12
|
-
* @param {
|
|
13
|
-
* @returns {
|
|
11
|
+
* Creates a CoFHE client instance (base implementation)
|
|
12
|
+
* @param {CofheClientParams} opts - Initialization options including config and platform-specific serializers
|
|
13
|
+
* @returns {CofheClient} - The CoFHE client instance
|
|
14
14
|
*/
|
|
15
|
-
declare function
|
|
15
|
+
declare function createCofheClientBase<TConfig extends CofheConfig>(opts: CofheClientParams<TConfig>): CofheClient<TConfig>;
|
|
16
16
|
|
|
17
|
-
declare enum
|
|
17
|
+
declare enum CofheErrorCode {
|
|
18
18
|
InternalError = "INTERNAL_ERROR",
|
|
19
19
|
UnknownEnvironment = "UNKNOWN_ENVIRONMENT",
|
|
20
20
|
InitTfheFailed = "INIT_TFHE_FAILED",
|
|
@@ -59,36 +59,36 @@ declare enum CofhesdkErrorCode {
|
|
|
59
59
|
PublicWalletGetAddressesFailed = "PUBLIC_WALLET_GET_ADDRESSES_FAILED",
|
|
60
60
|
RehydrateKeysStoreFailed = "REHYDRATE_KEYS_STORE_FAILED"
|
|
61
61
|
}
|
|
62
|
-
type
|
|
63
|
-
code:
|
|
62
|
+
type CofheErrorParams = {
|
|
63
|
+
code: CofheErrorCode;
|
|
64
64
|
message: string;
|
|
65
65
|
cause?: Error;
|
|
66
66
|
hint?: string;
|
|
67
67
|
context?: Record<string, unknown>;
|
|
68
68
|
};
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
70
|
+
* CofheError class
|
|
71
71
|
* This class is used to create errors that are specific to the CoFHE SDK
|
|
72
72
|
* It extends the Error class and adds a code, cause, hint, and context
|
|
73
73
|
* The code is used to identify the type of error
|
|
74
|
-
* The cause is used to indicate the inner error that caused the
|
|
74
|
+
* The cause is used to indicate the inner error that caused the CofheError
|
|
75
75
|
* The hint is used to provide a hint about how to fix the error
|
|
76
76
|
* The context is used to provide additional context about the state that caused the error
|
|
77
77
|
* The serialize method is used to serialize the error to a JSON string
|
|
78
78
|
* The toString method is used to provide a human-readable string representation of the error
|
|
79
79
|
*/
|
|
80
|
-
declare class
|
|
81
|
-
readonly code:
|
|
80
|
+
declare class CofheError extends Error {
|
|
81
|
+
readonly code: CofheErrorCode;
|
|
82
82
|
readonly cause?: Error;
|
|
83
83
|
readonly hint?: string;
|
|
84
84
|
readonly context?: Record<string, unknown>;
|
|
85
|
-
constructor({ code, message, cause, hint, context }:
|
|
85
|
+
constructor({ code, message, cause, hint, context }: CofheErrorParams);
|
|
86
86
|
/**
|
|
87
|
-
* Creates a
|
|
88
|
-
* If the error is a
|
|
89
|
-
* If a wrapperError is provided, it is used to create the new
|
|
87
|
+
* Creates a CofheError from an unknown error
|
|
88
|
+
* If the error is a CofheError, it is returned unchanged, else a new CofheError is created
|
|
89
|
+
* If a wrapperError is provided, it is used to create the new CofheError, else a default is used
|
|
90
90
|
*/
|
|
91
|
-
static fromError(error: unknown, wrapperError?:
|
|
91
|
+
static fromError(error: unknown, wrapperError?: CofheErrorParams): CofheError;
|
|
92
92
|
/**
|
|
93
93
|
* Serializes the error to JSON string with proper handling of Error objects
|
|
94
94
|
*/
|
|
@@ -98,20 +98,22 @@ declare class CofhesdkError extends Error {
|
|
|
98
98
|
*/
|
|
99
99
|
toString(): string;
|
|
100
100
|
}
|
|
101
|
-
declare const
|
|
101
|
+
declare const isCofheError: (error: unknown) => error is CofheError;
|
|
102
102
|
|
|
103
103
|
/** Main Task Manager contract address */
|
|
104
104
|
declare const TASK_MANAGER_ADDRESS: "0xeA30c4B8b44078Bbf8a6ef5b9f1eC1626C7848D9";
|
|
105
105
|
/** Mock ZK Verifier contract address (used for testing) */
|
|
106
106
|
declare const MOCKS_ZK_VERIFIER_ADDRESS: "0x0000000000000000000000000000000000005001";
|
|
107
|
-
/** Mock
|
|
108
|
-
declare const
|
|
107
|
+
/** Mock Threshold Network contract address (used for testing) */
|
|
108
|
+
declare const MOCKS_THRESHOLD_NETWORK_ADDRESS: "0x0000000000000000000000000000000000005002";
|
|
109
109
|
/** Test Bed contract address (used for testing) */
|
|
110
110
|
declare const TEST_BED_ADDRESS: "0x0000000000000000000000000000000000005003";
|
|
111
111
|
/** Private key for the Mock ZK Verifier signer account */
|
|
112
112
|
declare const MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY: "0x6C8D7F768A6BB4AAFE85E8A2F5A9680355239C7E14646ED62B044E39DE154512";
|
|
113
113
|
/** Address for the Mock ZK Verifier signer account */
|
|
114
114
|
declare const MOCKS_ZK_VERIFIER_SIGNER_ADDRESS: "0x6E12D8C87503D4287c294f2Fdef96ACd9DFf6bd2";
|
|
115
|
+
/** Private key for the Mock decrypt result signer account */
|
|
116
|
+
declare const MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY: "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d";
|
|
115
117
|
|
|
116
118
|
/**
|
|
117
119
|
* Converts FheTypes enum to string representation for serialization
|
|
@@ -119,4 +121,4 @@ declare const MOCKS_ZK_VERIFIER_SIGNER_ADDRESS: "0x6E12D8C87503D4287c294f2Fdef96
|
|
|
119
121
|
*/
|
|
120
122
|
declare function fheTypeToString(utype: FheTypes): string;
|
|
121
123
|
|
|
122
|
-
export { InitialConnectStore as CONNECT_STORE_DEFAULTS,
|
|
124
|
+
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, TEST_BED_ADDRESS, createCofheClientBase, fheTypeToString, isCofheError };
|
package/dist/core.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
export { h as
|
|
1
|
+
import { c as CofheClientConnectionState, a as CofheConfig, d as CofheClientParams, b as CofheClient, F as FheTypes } from './clientTypes-6aTZPQ_4.js';
|
|
2
|
+
export { h as CofheClientPermits, C as CofheInputConfig, f as CofheInternalConfig, Y as DecryptForTxBuilder, Z as DecryptForTxResult, X as DecryptForViewBuilder, W as EncryptInputsBuilder, B as EncryptSetStateFn, M as EncryptStep, D as EncryptStepCallbackContext, J as Encryptable, o as EncryptableAddress, i as EncryptableBool, E as EncryptableItem, z as EncryptableToEncryptedItemInputMap, 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, H as FheAllUTypes, R as FheKeyDeserializer, A as FheTypeValue, G as FheUintUTypes, I as IStorage, T as KeysStorage, V as KeysStore, L as LiteralToPrimitive, P as Primitive, U as UnsealedItem, _ as ZkBuilderAndCrsGenerator, $ as ZkProveWorkerFunction, a0 as ZkProveWorkerRequest, a1 as ZkProveWorkerResponse, O as assertCorrectEncryptedItemInput, e as createCofheConfigBase, S as createKeysStore, Q as fetchKeys, g as getCofheConfigItem, K as isEncryptableItem, N as isLastEncryptionStep, a2 as zkProveWithWorker } from './clientTypes-6aTZPQ_4.js';
|
|
3
3
|
import 'viem';
|
|
4
4
|
import './types-YiAC4gig.js';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import './permit-MZ502UBl.js';
|
|
7
7
|
import 'zustand/vanilla';
|
|
8
8
|
|
|
9
|
-
declare const InitialConnectStore:
|
|
9
|
+
declare const InitialConnectStore: CofheClientConnectionState;
|
|
10
10
|
/**
|
|
11
|
-
* Creates a CoFHE
|
|
12
|
-
* @param {
|
|
13
|
-
* @returns {
|
|
11
|
+
* Creates a CoFHE client instance (base implementation)
|
|
12
|
+
* @param {CofheClientParams} opts - Initialization options including config and platform-specific serializers
|
|
13
|
+
* @returns {CofheClient} - The CoFHE client instance
|
|
14
14
|
*/
|
|
15
|
-
declare function
|
|
15
|
+
declare function createCofheClientBase<TConfig extends CofheConfig>(opts: CofheClientParams<TConfig>): CofheClient<TConfig>;
|
|
16
16
|
|
|
17
|
-
declare enum
|
|
17
|
+
declare enum CofheErrorCode {
|
|
18
18
|
InternalError = "INTERNAL_ERROR",
|
|
19
19
|
UnknownEnvironment = "UNKNOWN_ENVIRONMENT",
|
|
20
20
|
InitTfheFailed = "INIT_TFHE_FAILED",
|
|
@@ -59,36 +59,36 @@ declare enum CofhesdkErrorCode {
|
|
|
59
59
|
PublicWalletGetAddressesFailed = "PUBLIC_WALLET_GET_ADDRESSES_FAILED",
|
|
60
60
|
RehydrateKeysStoreFailed = "REHYDRATE_KEYS_STORE_FAILED"
|
|
61
61
|
}
|
|
62
|
-
type
|
|
63
|
-
code:
|
|
62
|
+
type CofheErrorParams = {
|
|
63
|
+
code: CofheErrorCode;
|
|
64
64
|
message: string;
|
|
65
65
|
cause?: Error;
|
|
66
66
|
hint?: string;
|
|
67
67
|
context?: Record<string, unknown>;
|
|
68
68
|
};
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
70
|
+
* CofheError class
|
|
71
71
|
* This class is used to create errors that are specific to the CoFHE SDK
|
|
72
72
|
* It extends the Error class and adds a code, cause, hint, and context
|
|
73
73
|
* The code is used to identify the type of error
|
|
74
|
-
* The cause is used to indicate the inner error that caused the
|
|
74
|
+
* The cause is used to indicate the inner error that caused the CofheError
|
|
75
75
|
* The hint is used to provide a hint about how to fix the error
|
|
76
76
|
* The context is used to provide additional context about the state that caused the error
|
|
77
77
|
* The serialize method is used to serialize the error to a JSON string
|
|
78
78
|
* The toString method is used to provide a human-readable string representation of the error
|
|
79
79
|
*/
|
|
80
|
-
declare class
|
|
81
|
-
readonly code:
|
|
80
|
+
declare class CofheError extends Error {
|
|
81
|
+
readonly code: CofheErrorCode;
|
|
82
82
|
readonly cause?: Error;
|
|
83
83
|
readonly hint?: string;
|
|
84
84
|
readonly context?: Record<string, unknown>;
|
|
85
|
-
constructor({ code, message, cause, hint, context }:
|
|
85
|
+
constructor({ code, message, cause, hint, context }: CofheErrorParams);
|
|
86
86
|
/**
|
|
87
|
-
* Creates a
|
|
88
|
-
* If the error is a
|
|
89
|
-
* If a wrapperError is provided, it is used to create the new
|
|
87
|
+
* Creates a CofheError from an unknown error
|
|
88
|
+
* If the error is a CofheError, it is returned unchanged, else a new CofheError is created
|
|
89
|
+
* If a wrapperError is provided, it is used to create the new CofheError, else a default is used
|
|
90
90
|
*/
|
|
91
|
-
static fromError(error: unknown, wrapperError?:
|
|
91
|
+
static fromError(error: unknown, wrapperError?: CofheErrorParams): CofheError;
|
|
92
92
|
/**
|
|
93
93
|
* Serializes the error to JSON string with proper handling of Error objects
|
|
94
94
|
*/
|
|
@@ -98,20 +98,22 @@ declare class CofhesdkError extends Error {
|
|
|
98
98
|
*/
|
|
99
99
|
toString(): string;
|
|
100
100
|
}
|
|
101
|
-
declare const
|
|
101
|
+
declare const isCofheError: (error: unknown) => error is CofheError;
|
|
102
102
|
|
|
103
103
|
/** Main Task Manager contract address */
|
|
104
104
|
declare const TASK_MANAGER_ADDRESS: "0xeA30c4B8b44078Bbf8a6ef5b9f1eC1626C7848D9";
|
|
105
105
|
/** Mock ZK Verifier contract address (used for testing) */
|
|
106
106
|
declare const MOCKS_ZK_VERIFIER_ADDRESS: "0x0000000000000000000000000000000000005001";
|
|
107
|
-
/** Mock
|
|
108
|
-
declare const
|
|
107
|
+
/** Mock Threshold Network contract address (used for testing) */
|
|
108
|
+
declare const MOCKS_THRESHOLD_NETWORK_ADDRESS: "0x0000000000000000000000000000000000005002";
|
|
109
109
|
/** Test Bed contract address (used for testing) */
|
|
110
110
|
declare const TEST_BED_ADDRESS: "0x0000000000000000000000000000000000005003";
|
|
111
111
|
/** Private key for the Mock ZK Verifier signer account */
|
|
112
112
|
declare const MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY: "0x6C8D7F768A6BB4AAFE85E8A2F5A9680355239C7E14646ED62B044E39DE154512";
|
|
113
113
|
/** Address for the Mock ZK Verifier signer account */
|
|
114
114
|
declare const MOCKS_ZK_VERIFIER_SIGNER_ADDRESS: "0x6E12D8C87503D4287c294f2Fdef96ACd9DFf6bd2";
|
|
115
|
+
/** Private key for the Mock decrypt result signer account */
|
|
116
|
+
declare const MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY: "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d";
|
|
115
117
|
|
|
116
118
|
/**
|
|
117
119
|
* Converts FheTypes enum to string representation for serialization
|
|
@@ -119,4 +121,4 @@ declare const MOCKS_ZK_VERIFIER_SIGNER_ADDRESS: "0x6E12D8C87503D4287c294f2Fdef96
|
|
|
119
121
|
*/
|
|
120
122
|
declare function fheTypeToString(utype: FheTypes): string;
|
|
121
123
|
|
|
122
|
-
export { InitialConnectStore as CONNECT_STORE_DEFAULTS,
|
|
124
|
+
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, TEST_BED_ADDRESS, createCofheClientBase, fheTypeToString, isCofheError };
|
package/dist/core.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { InitialConnectStore as CONNECT_STORE_DEFAULTS,
|
|
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, zkProveWithWorker } from './chunk-2TPSCOW3.js';
|
|
2
2
|
import './chunk-TBLR7NNE.js';
|
|
3
|
-
export {
|
|
3
|
+
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, TEST_BED_ADDRESS } from './chunk-NWDKXBIP.js';
|