@cofhe/sdk 0.8.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- package/acps/acp.ts +25 -6
- package/acps/index.ts +20 -15
- package/acps/onchain-utils.ts +15 -10
- package/acps/registry.ts +166 -8
- package/acps/sealing.ts +31 -5
- package/acps/share-metadata/appKey.ts +8 -0
- package/acps/share-metadata/decode.ts +120 -0
- package/acps/share-metadata/describe.ts +198 -0
- package/acps/share-metadata/encode.ts +147 -0
- package/acps/share-metadata/erc7984.ts +26 -0
- package/acps/share-metadata/index.ts +9 -0
- package/acps/share-metadata/layout.ts +69 -0
- package/acps/share-metadata/presets.ts +116 -0
- package/acps/share-metadata/schema.ts +47 -0
- package/acps/share-metadata/test/codec.test.ts +140 -0
- package/acps/share-metadata/test/describe.test.ts +112 -0
- package/acps/share-metadata/test/fixtures.ts +157 -0
- package/acps/share-metadata/test/live.test.ts +56 -0
- package/acps/share-metadata/test/presets.test.ts +119 -0
- package/acps/share-metadata/test/verify.test.ts +144 -0
- package/acps/share-metadata/verify.ts +155 -0
- package/acps/store.ts +48 -18
- package/acps/test/aclServedAddresses.test.ts +65 -0
- package/acps/test/acp.test.ts +102 -7
- package/acps/test/localstorage.test.ts +28 -1
- package/acps/test/registry.test.ts +144 -0
- package/acps/test/sealing.test.ts +74 -0
- package/acps/test/store.test.ts +71 -0
- package/acps/test/utils.test.ts +63 -0
- package/acps/test/validation.test.ts +0 -4
- package/acps/types.ts +43 -6
- package/acps/utils.ts +15 -2
- package/acps/validation.ts +3 -1
- package/core/acps.ts +123 -74
- package/core/client.ts +33 -7
- package/core/clientTypes.ts +25 -7
- package/core/config.ts +8 -0
- package/core/decrypt/apiError.ts +4 -1
- package/core/decrypt/verifyDecryptResult.ts +4 -1
- package/core/encrypt/cofheMocksZkVerifySign.ts +19 -2
- package/core/test/acpDefaults.test.ts +108 -19
- package/core/test/acpStoreAccountCase.test.ts +80 -0
- package/core/test/acps.test.ts +38 -3
- package/core/test/apiError.test.ts +8 -0
- package/core/test/appKeyConfig.test.ts +94 -0
- package/core/test/config.test.ts +8 -0
- package/core/test/decryptBuilders.test.ts +110 -2
- package/core/test/incomingShares.test.ts +84 -0
- package/core/test/mocksEncryptRange.test.ts +90 -0
- package/core/test/utils.test.ts +128 -0
- package/core/test/verifyDecryptResult.test.ts +51 -0
- package/core/utils.ts +16 -9
- package/dist/acps.cjs +796 -132
- package/dist/acps.d.cts +367 -35
- package/dist/acps.d.ts +367 -35
- package/dist/acps.js +2 -2
- package/dist/{chunk-UJYOBHYA.js → chunk-3L2IVPMI.js} +688 -203
- package/dist/chunk-J23FYAI2.js +174 -0
- package/dist/{chunk-GGI7Y6AW.js → chunk-O2ITEUEU.js} +110 -269
- package/dist/chunk-WJGTPW7K.js +228 -0
- package/dist/{clientTypes-D3aIXmUp.d.cts → clientTypes-IO6b5Um8.d.cts} +61 -21
- package/dist/{clientTypes-5YPPR16m.d.ts → clientTypes-b1pOxOUE.d.ts} +61 -21
- package/dist/core.cjs +3115 -2584
- package/dist/core.d.cts +6 -3
- package/dist/core.d.ts +6 -3
- package/dist/core.js +4 -3
- package/dist/node.cjs +3001 -2470
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.js +18 -17
- package/dist/{onchain-utils-CUAK8glx.d.cts → onchain-utils-CgOslubH.d.cts} +139 -15
- package/dist/{onchain-utils-CUAK8glx.d.ts → onchain-utils-CgOslubH.d.ts} +139 -15
- package/dist/web.cjs +3011 -2487
- package/dist/web.d.cts +2 -2
- package/dist/web.d.ts +2 -2
- package/dist/web.js +4 -10
- package/dist/zkProve.worker.cjs +14 -7
- package/dist/zkProve.worker.js +2 -8
- package/node/index.ts +1 -10
- package/node/storage.ts +18 -7
- package/node/test/storage-permissions.test.ts +40 -0
- package/package.json +4 -4
- package/web/index.ts +1 -10
- package/web/test/threadPoolBenchHelper.ts +1 -7
- package/web/zkProve.worker.ts +1 -10
- package/dist/chunk-NMKMCAI3.js +0 -14
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// core/error.ts
|
|
2
|
+
var CofheErrorCode = /* @__PURE__ */ ((CofheErrorCode2) => {
|
|
3
|
+
CofheErrorCode2["InternalError"] = "INTERNAL_ERROR";
|
|
4
|
+
CofheErrorCode2["UnknownEnvironment"] = "UNKNOWN_ENVIRONMENT";
|
|
5
|
+
CofheErrorCode2["InitTfheFailed"] = "INIT_TFHE_FAILED";
|
|
6
|
+
CofheErrorCode2["InitViemFailed"] = "INIT_VIEM_FAILED";
|
|
7
|
+
CofheErrorCode2["InitEthersFailed"] = "INIT_ETHERS_FAILED";
|
|
8
|
+
CofheErrorCode2["NotConnected"] = "NOT_CONNECTED";
|
|
9
|
+
CofheErrorCode2["MissingPublicClient"] = "MISSING_PUBLIC_CLIENT";
|
|
10
|
+
CofheErrorCode2["MissingWalletClient"] = "MISSING_WALLET_CLIENT";
|
|
11
|
+
CofheErrorCode2["MissingProviderParam"] = "MISSING_PROVIDER_PARAM";
|
|
12
|
+
CofheErrorCode2["EmptySecurityZonesParam"] = "EMPTY_SECURITY_ZONES_PARAM";
|
|
13
|
+
CofheErrorCode2["InvalidACPData"] = "INVALID_ACP_DATA";
|
|
14
|
+
CofheErrorCode2["InvalidACPDomain"] = "INVALID_ACP_DOMAIN";
|
|
15
|
+
CofheErrorCode2["ACPNotFound"] = "ACP_NOT_FOUND";
|
|
16
|
+
CofheErrorCode2["CannotRemoveLastACP"] = "CANNOT_REMOVE_LAST_ACP";
|
|
17
|
+
CofheErrorCode2["AccountUninitialized"] = "ACCOUNT_UNINITIALIZED";
|
|
18
|
+
CofheErrorCode2["ChainIdUninitialized"] = "CHAIN_ID_UNINITIALIZED";
|
|
19
|
+
CofheErrorCode2["ConsumingContractUninitialized"] = "CONSUMING_CONTRACT_UNINITIALIZED";
|
|
20
|
+
CofheErrorCode2["SealOutputFailed"] = "SEAL_OUTPUT_FAILED";
|
|
21
|
+
CofheErrorCode2["SealOutputReturnedNull"] = "SEAL_OUTPUT_RETURNED_NULL";
|
|
22
|
+
CofheErrorCode2["InvalidUtype"] = "INVALID_UTYPE";
|
|
23
|
+
CofheErrorCode2["DecryptFailed"] = "DECRYPT_FAILED";
|
|
24
|
+
CofheErrorCode2["DecryptReturnedNull"] = "DECRYPT_RETURNED_NULL";
|
|
25
|
+
CofheErrorCode2["ZkMocksInsertCtHashesFailed"] = "ZK_MOCKS_INSERT_CT_HASHES_FAILED";
|
|
26
|
+
CofheErrorCode2["ZkMocksCalcCtHashesFailed"] = "ZK_MOCKS_CALC_CT_HASHES_FAILED";
|
|
27
|
+
CofheErrorCode2["ZkMocksVerifySignFailed"] = "ZK_MOCKS_VERIFY_SIGN_FAILED";
|
|
28
|
+
CofheErrorCode2["ZkMocksCreateProofSignatureFailed"] = "ZK_MOCKS_CREATE_PROOF_SIGNATURE_FAILED";
|
|
29
|
+
CofheErrorCode2["ZkVerifyFailed"] = "ZK_VERIFY_FAILED";
|
|
30
|
+
CofheErrorCode2["ZkPackFailed"] = "ZK_PACK_FAILED";
|
|
31
|
+
CofheErrorCode2["ZkProveFailed"] = "ZK_PROVE_FAILED";
|
|
32
|
+
CofheErrorCode2["EncryptRemainingInItems"] = "ENCRYPT_REMAINING_IN_ITEMS";
|
|
33
|
+
CofheErrorCode2["ZkUninitialized"] = "ZK_UNINITIALIZED";
|
|
34
|
+
CofheErrorCode2["ZkVerifierUrlUninitialized"] = "ZK_VERIFIER_URL_UNINITIALIZED";
|
|
35
|
+
CofheErrorCode2["ThresholdNetworkUrlUninitialized"] = "THRESHOLD_NETWORK_URL_UNINITIALIZED";
|
|
36
|
+
CofheErrorCode2["MissingConfig"] = "MISSING_CONFIG";
|
|
37
|
+
CofheErrorCode2["UnsupportedChain"] = "UNSUPPORTED_CHAIN";
|
|
38
|
+
CofheErrorCode2["MissingZkBuilderAndCrsGenerator"] = "MISSING_ZK_BUILDER_AND_CRS_GENERATOR";
|
|
39
|
+
CofheErrorCode2["MissingTfhePublicKeyDeserializer"] = "MISSING_TFHE_PUBLIC_KEY_DESERIALIZER";
|
|
40
|
+
CofheErrorCode2["MissingCompactPkeCrsDeserializer"] = "MISSING_COMPACT_PKE_CRS_DESERIALIZER";
|
|
41
|
+
CofheErrorCode2["MissingFheKey"] = "MISSING_FHE_KEY";
|
|
42
|
+
CofheErrorCode2["MissingCrs"] = "MISSING_CRS";
|
|
43
|
+
CofheErrorCode2["FetchKeysFailed"] = "FETCH_KEYS_FAILED";
|
|
44
|
+
CofheErrorCode2["PublicWalletGetChainIdFailed"] = "PUBLIC_WALLET_GET_CHAIN_ID_FAILED";
|
|
45
|
+
CofheErrorCode2["PublicWalletGetAddressesFailed"] = "PUBLIC_WALLET_GET_ADDRESSES_FAILED";
|
|
46
|
+
CofheErrorCode2["RehydrateKeysStoreFailed"] = "REHYDRATE_KEYS_STORE_FAILED";
|
|
47
|
+
CofheErrorCode2["TaskManagerUnresolved"] = "TASK_MANAGER_UNRESOLVED";
|
|
48
|
+
CofheErrorCode2["BadRequest"] = "BAD_REQUEST";
|
|
49
|
+
CofheErrorCode2["UnknownChain"] = "UNKNOWN_CHAIN";
|
|
50
|
+
CofheErrorCode2["ACPMalformed"] = "ACP_MALFORMED";
|
|
51
|
+
CofheErrorCode2["ACPDenied"] = "ACP_DENIED";
|
|
52
|
+
CofheErrorCode2["ACPExpired"] = "ACP_EXPIRED";
|
|
53
|
+
CofheErrorCode2["ACPInvalid"] = "ACP_INVALID";
|
|
54
|
+
CofheErrorCode2["ACPRevoked"] = "ACP_REVOKED";
|
|
55
|
+
CofheErrorCode2["NotPubliclyAllowed"] = "NOT_PUBLICLY_ALLOWED";
|
|
56
|
+
CofheErrorCode2["CtNotFound"] = "CT_NOT_FOUND";
|
|
57
|
+
CofheErrorCode2["UnsupportedSecurityZone"] = "UNSUPPORTED_SECURITY_ZONE";
|
|
58
|
+
CofheErrorCode2["UnsupportedType"] = "UNSUPPORTED_TYPE";
|
|
59
|
+
CofheErrorCode2["SigningFailed"] = "SIGNING_FAILED";
|
|
60
|
+
CofheErrorCode2["CtSourceError"] = "CT_SOURCE_ERROR";
|
|
61
|
+
CofheErrorCode2["ACPVerifierError"] = "ACP_VERIFIER_ERROR";
|
|
62
|
+
CofheErrorCode2["CtSourceTimeout"] = "CT_SOURCE_TIMEOUT";
|
|
63
|
+
CofheErrorCode2["ACPVerifierTimeout"] = "ACP_VERIFIER_TIMEOUT";
|
|
64
|
+
CofheErrorCode2["ACPRequired"] = "ACP_REQUIRED";
|
|
65
|
+
CofheErrorCode2["SealFailed"] = "SEAL_FAILED";
|
|
66
|
+
return CofheErrorCode2;
|
|
67
|
+
})(CofheErrorCode || {});
|
|
68
|
+
var CofheError = class _CofheError extends Error {
|
|
69
|
+
code;
|
|
70
|
+
cause;
|
|
71
|
+
hint;
|
|
72
|
+
context;
|
|
73
|
+
apiErrorCode;
|
|
74
|
+
constructor({ code, message, cause, hint, context, apiErrorCode }) {
|
|
75
|
+
const fullMessage = cause ? `${message} | Caused by: ${cause.message}` : message;
|
|
76
|
+
super(fullMessage);
|
|
77
|
+
this.name = "CofheError";
|
|
78
|
+
this.code = code;
|
|
79
|
+
this.cause = cause;
|
|
80
|
+
this.hint = hint;
|
|
81
|
+
this.context = context;
|
|
82
|
+
this.apiErrorCode = apiErrorCode;
|
|
83
|
+
if (Error.captureStackTrace) {
|
|
84
|
+
Error.captureStackTrace(this, _CofheError);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Creates a CofheError from an unknown error
|
|
89
|
+
* If the error is a CofheError, it is returned unchanged, else a new CofheError is created
|
|
90
|
+
* If a wrapperError is provided, it is used to create the new CofheError, else a default is used
|
|
91
|
+
*/
|
|
92
|
+
static fromError(error, wrapperError) {
|
|
93
|
+
if (isCofheError(error))
|
|
94
|
+
return error;
|
|
95
|
+
const cause = error instanceof Error ? error : new Error(`${error}`);
|
|
96
|
+
return new _CofheError({
|
|
97
|
+
code: wrapperError?.code ?? "INTERNAL_ERROR" /* InternalError */,
|
|
98
|
+
message: wrapperError?.message ?? "An internal error occurred",
|
|
99
|
+
hint: wrapperError?.hint,
|
|
100
|
+
context: wrapperError?.context,
|
|
101
|
+
apiErrorCode: wrapperError?.apiErrorCode,
|
|
102
|
+
cause
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Serializes the error to JSON string with proper handling of Error objects
|
|
107
|
+
*/
|
|
108
|
+
serialize() {
|
|
109
|
+
return bigintSafeJsonStringify({
|
|
110
|
+
name: this.name,
|
|
111
|
+
code: this.code,
|
|
112
|
+
message: this.message,
|
|
113
|
+
hint: this.hint,
|
|
114
|
+
context: this.context,
|
|
115
|
+
apiErrorCode: this.apiErrorCode,
|
|
116
|
+
cause: this.cause ? {
|
|
117
|
+
name: this.cause.name,
|
|
118
|
+
message: this.cause.message,
|
|
119
|
+
stack: this.cause.stack
|
|
120
|
+
} : void 0,
|
|
121
|
+
stack: this.stack
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Returns a human-readable string representation of the error
|
|
126
|
+
*/
|
|
127
|
+
toString() {
|
|
128
|
+
const codeSuffix = this.apiErrorCode ? ` (api: ${this.apiErrorCode})` : "";
|
|
129
|
+
const parts = [`${this.name} [${this.code}]${codeSuffix}: ${this.message}`];
|
|
130
|
+
if (this.hint) {
|
|
131
|
+
parts.push(`Hint: ${this.hint}`);
|
|
132
|
+
}
|
|
133
|
+
if (this.context && Object.keys(this.context).length > 0) {
|
|
134
|
+
parts.push(`Context: ${bigintSafeJsonStringify(this.context)}`);
|
|
135
|
+
}
|
|
136
|
+
if (this.stack) {
|
|
137
|
+
parts.push(`
|
|
138
|
+
Stack trace:`);
|
|
139
|
+
parts.push(this.stack);
|
|
140
|
+
}
|
|
141
|
+
if (this.cause) {
|
|
142
|
+
parts.push(`
|
|
143
|
+
Caused by: ${this.cause.name}: ${this.cause.message}`);
|
|
144
|
+
if (this.cause.stack) {
|
|
145
|
+
parts.push(this.cause.stack);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return parts.join("\n");
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
var bigintSafeJsonStringify = (value) => {
|
|
152
|
+
return JSON.stringify(value, (key, value2) => {
|
|
153
|
+
if (typeof value2 === "bigint") {
|
|
154
|
+
return `${value2}n`;
|
|
155
|
+
}
|
|
156
|
+
return value2;
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
var isCofheError = (error) => error instanceof CofheError;
|
|
160
|
+
|
|
161
|
+
// core/consts.ts
|
|
162
|
+
var COFHE_ADDRESS_BOOK_ADDRESS = "0xC0F4e00E531a2B086492Ae3DCC1515038307196b";
|
|
163
|
+
var TASK_MANAGER_ID = 1n;
|
|
164
|
+
var MOCKS_TASK_MANAGER_ADDRESS = "0x0000000000000000000000000000000000005000";
|
|
165
|
+
var MOCKS_ZK_VERIFIER_ADDRESS = "0x0000000000000000000000000000000000005001";
|
|
166
|
+
var MOCKS_THRESHOLD_NETWORK_ADDRESS = "0x0000000000000000000000000000000000005002";
|
|
167
|
+
var MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY = "0x6C8D7F768A6BB4AAFE85E8A2F5A9680355239C7E14646ED62B044E39DE154512";
|
|
168
|
+
var MOCKS_ZK_VERIFIER_SIGNER_ADDRESS = "0x6E12D8C87503D4287c294f2Fdef96ACd9DFf6bd2";
|
|
169
|
+
var MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY = "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d";
|
|
170
|
+
var TFHE_RS_ZK_MAX_BITS = 2048;
|
|
171
|
+
var TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT = BigInt(1 << 30);
|
|
172
|
+
var TFHE_RS_KEY_VERSION = 2;
|
|
173
|
+
|
|
174
|
+
export { COFHE_ADDRESS_BOOK_ADDRESS, CofheError, CofheErrorCode, MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY, MOCKS_TASK_MANAGER_ADDRESS, MOCKS_THRESHOLD_NETWORK_ADDRESS, MOCKS_ZK_VERIFIER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY, TASK_MANAGER_ID, TFHE_RS_KEY_VERSION, TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT, TFHE_RS_ZK_MAX_BITS, isCofheError };
|