@enclave-e3/sdk 0.1.6 → 0.1.8
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/README.md +1 -1
- package/dist/index.cjs +47 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -71
- package/dist/index.d.ts +19 -71
- package/dist/index.js +47 -77
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -217,7 +217,7 @@ await sdk.requestE3({
|
|
|
217
217
|
});
|
|
218
218
|
|
|
219
219
|
// Activate an E3 computation
|
|
220
|
-
await sdk.activateE3(e3Id: bigint,
|
|
220
|
+
await sdk.activateE3(e3Id: bigint, gasLimit?: bigint);
|
|
221
221
|
|
|
222
222
|
// Publish input data
|
|
223
223
|
await sdk.publishInput(e3Id: bigint, data: `0x${string}`, gasLimit?: bigint);
|
package/dist/index.cjs
CHANGED
|
@@ -30,17 +30,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
BFV_PARAMS_SET: () => BFV_PARAMS_SET,
|
|
34
|
-
BfvProtocolParams: () => BfvProtocolParams,
|
|
35
33
|
ContractClient: () => ContractClient,
|
|
36
34
|
DEFAULT_COMPUTE_PROVIDER_PARAMS: () => DEFAULT_COMPUTE_PROVIDER_PARAMS,
|
|
37
35
|
DEFAULT_E3_CONFIG: () => DEFAULT_E3_CONFIG,
|
|
38
36
|
EnclaveEventType: () => EnclaveEventType,
|
|
39
37
|
EnclaveSDK: () => EnclaveSDK,
|
|
40
38
|
EventListener: () => EventListener,
|
|
41
|
-
FheProtocol: () => FheProtocol,
|
|
42
39
|
RegistryEventType: () => RegistryEventType,
|
|
43
40
|
SDKError: () => SDKError,
|
|
41
|
+
ThresholdBfvParamsPresetNames: () => ThresholdBfvParamsPresetNames,
|
|
44
42
|
calculateStartWindow: () => calculateStartWindow,
|
|
45
43
|
convertToPolynomial: () => convertToPolynomial,
|
|
46
44
|
convertToPolynomialArray: () => convertToPolynomialArray,
|
|
@@ -107,14 +105,6 @@ function generateEventId(log) {
|
|
|
107
105
|
function getCurrentTimestamp() {
|
|
108
106
|
return Math.floor(Date.now() / 1e3);
|
|
109
107
|
}
|
|
110
|
-
var INSECURE_SET_2048_1032193_1 = {
|
|
111
|
-
degree: 2048,
|
|
112
|
-
plaintext_modulus: 1032193,
|
|
113
|
-
moduli: [0x3fffffff000001n],
|
|
114
|
-
// BigInt for the modulus
|
|
115
|
-
error1_variance: "10"
|
|
116
|
-
};
|
|
117
|
-
var BFV_PARAMS_SET = INSECURE_SET_2048_1032193_1;
|
|
118
108
|
var DEFAULT_COMPUTE_PROVIDER_PARAMS = {
|
|
119
109
|
name: "risc0",
|
|
120
110
|
parallel: false,
|
|
@@ -130,7 +120,14 @@ var DEFAULT_E3_CONFIG = {
|
|
|
130
120
|
payment_amount: "0"
|
|
131
121
|
// 0 ETH in wei
|
|
132
122
|
};
|
|
133
|
-
function encodeBfvParams(
|
|
123
|
+
function encodeBfvParams(params) {
|
|
124
|
+
const { degree, plaintextModulus, moduli, error1Variance } = params;
|
|
125
|
+
if (error1Variance === void 0) {
|
|
126
|
+
throw new SDKError(
|
|
127
|
+
"error1Variance is required in ProtocolParams. All BFV parameter sets must specify error1_variance.",
|
|
128
|
+
"MISSING_ERROR1_VARIANCE"
|
|
129
|
+
);
|
|
130
|
+
}
|
|
134
131
|
return (0, import_viem.encodeAbiParameters)(
|
|
135
132
|
[
|
|
136
133
|
{
|
|
@@ -147,9 +144,9 @@ function encodeBfvParams(degree = BFV_PARAMS_SET.degree, plaintext_modulus = BFV
|
|
|
147
144
|
[
|
|
148
145
|
{
|
|
149
146
|
degree: BigInt(degree),
|
|
150
|
-
plaintext_modulus: BigInt(
|
|
147
|
+
plaintext_modulus: BigInt(plaintextModulus),
|
|
151
148
|
moduli: [...moduli],
|
|
152
|
-
error1_variance
|
|
149
|
+
error1_variance: error1Variance
|
|
153
150
|
}
|
|
154
151
|
]
|
|
155
152
|
);
|
|
@@ -305,9 +302,9 @@ var ContractClient = class {
|
|
|
305
302
|
}
|
|
306
303
|
/**
|
|
307
304
|
* Activate an E3 computation
|
|
308
|
-
* activate(uint256 e3Id
|
|
305
|
+
* activate(uint256 e3Id)
|
|
309
306
|
*/
|
|
310
|
-
async activateE3(e3Id,
|
|
307
|
+
async activateE3(e3Id, gasLimit) {
|
|
311
308
|
if (!this.walletClient) {
|
|
312
309
|
throw new SDKError("Wallet client required for write operations", "NO_WALLET");
|
|
313
310
|
}
|
|
@@ -323,7 +320,7 @@ var ContractClient = class {
|
|
|
323
320
|
address: this.addresses.enclave,
|
|
324
321
|
abi: import_types.Enclave__factory.abi,
|
|
325
322
|
functionName: "activate",
|
|
326
|
-
args: [e3Id
|
|
323
|
+
args: [e3Id],
|
|
327
324
|
account,
|
|
328
325
|
gas: gasLimit
|
|
329
326
|
});
|
|
@@ -694,37 +691,10 @@ var RegistryEventType = /* @__PURE__ */ ((RegistryEventType2) => {
|
|
|
694
691
|
RegistryEventType2["INITIALIZED"] = "Initialized";
|
|
695
692
|
return RegistryEventType2;
|
|
696
693
|
})(RegistryEventType || {});
|
|
697
|
-
var
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
})(FheProtocol || {});
|
|
702
|
-
var BfvProtocolParams = {
|
|
703
|
-
/**
|
|
704
|
-
* Recommended parameters for BFV protocol
|
|
705
|
-
* - Degree: 2048
|
|
706
|
-
* - Plaintext modulus: 1032193
|
|
707
|
-
* - Moduli:0x3FFFFFFF000001
|
|
708
|
-
*/
|
|
709
|
-
BFV_NORMAL: {
|
|
710
|
-
degree: 2048,
|
|
711
|
-
plaintextModulus: 1032193n,
|
|
712
|
-
moduli: [0x3fffffff000001n],
|
|
713
|
-
error1Variance: "10"
|
|
714
|
-
},
|
|
715
|
-
/**
|
|
716
|
-
* Recommended parameters for TrBFV protocol
|
|
717
|
-
* - Degree: 8192
|
|
718
|
-
* - Plaintext modulus: 1000
|
|
719
|
-
* - Moduli: [0x00800000022a0001, 0x00800000021a0001, 0x0080000002120001, 0x0080000001f60001]
|
|
720
|
-
*/
|
|
721
|
-
BFV_THRESHOLD: {
|
|
722
|
-
degree: 8192,
|
|
723
|
-
plaintextModulus: 1000n,
|
|
724
|
-
moduli: [0x00800000022a0001n, 0x00800000021a0001n, 0x0080000002120001n, 0x0080000001f60001n],
|
|
725
|
-
error1Variance: "10"
|
|
726
|
-
}
|
|
727
|
-
};
|
|
694
|
+
var ThresholdBfvParamsPresetNames = [
|
|
695
|
+
"INSECURE_THRESHOLD_BFV_512",
|
|
696
|
+
"SECURE_THRESHOLD_BFV_8192"
|
|
697
|
+
];
|
|
728
698
|
|
|
729
699
|
// src/enclave-sdk.ts
|
|
730
700
|
var import_wasm = require("@enclave-e3/wasm");
|
|
@@ -812,15 +782,18 @@ var EnclaveSDK = class _EnclaveSDK {
|
|
|
812
782
|
if (!isValidAddress(config.contracts.feeToken)) {
|
|
813
783
|
throw new SDKError("Invalid FeeToken contract address", "INVALID_ADDRESS");
|
|
814
784
|
}
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
if (!Object.values(FheProtocol).includes(config.protocol)) {
|
|
818
|
-
throw new SDKError(`Invalid protocol: ${config.protocol}`, "INVALID_PROTOCOL");
|
|
785
|
+
if (!config.thresholdBfvParamsPresetName) {
|
|
786
|
+
throw new SDKError("Threshold BFV parameters preset name is required", "MISSING_THRESHOLD_BFV_PARAMS_PRESET_NAME");
|
|
819
787
|
}
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
788
|
+
if (!Object.values(ThresholdBfvParamsPresetNames).includes(config.thresholdBfvParamsPresetName)) {
|
|
789
|
+
throw new SDKError(
|
|
790
|
+
`Invalid threshold BFV parameters preset name: ${config.thresholdBfvParamsPresetName}`,
|
|
791
|
+
"INVALID_THRESHOLD_BFV_PARAMS_PRESET_NAME"
|
|
792
|
+
);
|
|
823
793
|
}
|
|
794
|
+
this.thresholdBfvParamsPresetName = config.thresholdBfvParamsPresetName;
|
|
795
|
+
this.eventListener = new EventListener(config.publicClient);
|
|
796
|
+
this.contractClient = new ContractClient(config.publicClient, config.walletClient, config.contracts);
|
|
824
797
|
this.publicClient = config.publicClient;
|
|
825
798
|
}
|
|
826
799
|
static chains = {
|
|
@@ -832,8 +805,7 @@ var EnclaveSDK = class _EnclaveSDK {
|
|
|
832
805
|
eventListener;
|
|
833
806
|
contractClient;
|
|
834
807
|
initialized = false;
|
|
835
|
-
|
|
836
|
-
protocolParams;
|
|
808
|
+
thresholdBfvParamsPresetName;
|
|
837
809
|
publicClient;
|
|
838
810
|
/**
|
|
839
811
|
* Initialize the SDK
|
|
@@ -855,9 +827,9 @@ var EnclaveSDK = class _EnclaveSDK {
|
|
|
855
827
|
getPublicClient = () => {
|
|
856
828
|
return this.publicClient;
|
|
857
829
|
};
|
|
858
|
-
async
|
|
830
|
+
async getThresholdBfvParamsSet() {
|
|
859
831
|
await (0, import_init.default)();
|
|
860
|
-
let params = (0, import_wasm.get_bfv_params)(
|
|
832
|
+
let params = (0, import_wasm.get_bfv_params)(this.thresholdBfvParamsPresetName);
|
|
861
833
|
return {
|
|
862
834
|
degree: Number(params.degree),
|
|
863
835
|
// degree is returned as a bigint from wasm
|
|
@@ -866,17 +838,15 @@ var EnclaveSDK = class _EnclaveSDK {
|
|
|
866
838
|
error1Variance: params.error1_variance
|
|
867
839
|
};
|
|
868
840
|
}
|
|
869
|
-
async
|
|
841
|
+
async computePublicKeyCommitment(publicKey) {
|
|
870
842
|
await (0, import_init.default)();
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
return await this.getBfvParamsSet("INSECURE_SET_512_10_1");
|
|
879
|
-
}
|
|
843
|
+
const protocolParams = await this.getThresholdBfvParamsSet();
|
|
844
|
+
return (0, import_wasm.compute_pk_commitment)(
|
|
845
|
+
publicKey,
|
|
846
|
+
protocolParams.degree,
|
|
847
|
+
protocolParams.plaintextModulus,
|
|
848
|
+
BigUint64Array.from(protocolParams.moduli)
|
|
849
|
+
);
|
|
880
850
|
}
|
|
881
851
|
/**
|
|
882
852
|
* Encrypt a number using the configured protocol
|
|
@@ -886,7 +856,7 @@ var EnclaveSDK = class _EnclaveSDK {
|
|
|
886
856
|
*/
|
|
887
857
|
async encryptNumber(data, publicKey) {
|
|
888
858
|
await (0, import_init.default)();
|
|
889
|
-
const protocolParams = await this.
|
|
859
|
+
const protocolParams = await this.getThresholdBfvParamsSet();
|
|
890
860
|
return (0, import_wasm.bfv_encrypt_number)(
|
|
891
861
|
data,
|
|
892
862
|
publicKey,
|
|
@@ -903,7 +873,7 @@ var EnclaveSDK = class _EnclaveSDK {
|
|
|
903
873
|
*/
|
|
904
874
|
async encryptVector(data, publicKey) {
|
|
905
875
|
await (0, import_init.default)();
|
|
906
|
-
const protocolParams = await this.
|
|
876
|
+
const protocolParams = await this.getThresholdBfvParamsSet();
|
|
907
877
|
return (0, import_wasm.bfv_encrypt_vector)(
|
|
908
878
|
data,
|
|
909
879
|
publicKey,
|
|
@@ -921,7 +891,7 @@ var EnclaveSDK = class _EnclaveSDK {
|
|
|
921
891
|
*/
|
|
922
892
|
async encryptNumberAndGenInputs(data, publicKey) {
|
|
923
893
|
await (0, import_init.default)();
|
|
924
|
-
const protocolParams = await this.
|
|
894
|
+
const protocolParams = await this.getThresholdBfvParamsSet();
|
|
925
895
|
const [encryptedData, circuitInputs] = (0, import_wasm.bfv_verifiable_encrypt_number)(
|
|
926
896
|
data,
|
|
927
897
|
publicKey,
|
|
@@ -958,7 +928,7 @@ var EnclaveSDK = class _EnclaveSDK {
|
|
|
958
928
|
*/
|
|
959
929
|
async encryptVectorAndGenInputs(data, publicKey) {
|
|
960
930
|
await (0, import_init.default)();
|
|
961
|
-
const protocolParams = await this.
|
|
931
|
+
const protocolParams = await this.getThresholdBfvParamsSet();
|
|
962
932
|
const [encryptedData, circuitInputs] = (0, import_wasm.bfv_verifiable_encrypt_vector)(
|
|
963
933
|
data,
|
|
964
934
|
publicKey,
|
|
@@ -1032,11 +1002,11 @@ var EnclaveSDK = class _EnclaveSDK {
|
|
|
1032
1002
|
/**
|
|
1033
1003
|
* Activate an E3 computation
|
|
1034
1004
|
*/
|
|
1035
|
-
async activateE3(e3Id,
|
|
1005
|
+
async activateE3(e3Id, gasLimit) {
|
|
1036
1006
|
if (!this.initialized) {
|
|
1037
1007
|
await this.initialize();
|
|
1038
1008
|
}
|
|
1039
|
-
return this.contractClient.activateE3(e3Id,
|
|
1009
|
+
return this.contractClient.activateE3(e3Id, gasLimit);
|
|
1040
1010
|
}
|
|
1041
1011
|
/**
|
|
1042
1012
|
* Publish input for an E3 computation
|
|
@@ -1184,24 +1154,21 @@ var EnclaveSDK = class _EnclaveSDK {
|
|
|
1184
1154
|
walletClient,
|
|
1185
1155
|
contracts: options.contracts,
|
|
1186
1156
|
chainId: options.chainId,
|
|
1187
|
-
|
|
1188
|
-
protocolParams: options.protocolParams
|
|
1157
|
+
thresholdBfvParamsPresetName: options.thresholdBfvParamsPresetName
|
|
1189
1158
|
});
|
|
1190
1159
|
}
|
|
1191
1160
|
};
|
|
1192
1161
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1193
1162
|
0 && (module.exports = {
|
|
1194
|
-
BFV_PARAMS_SET,
|
|
1195
|
-
BfvProtocolParams,
|
|
1196
1163
|
ContractClient,
|
|
1197
1164
|
DEFAULT_COMPUTE_PROVIDER_PARAMS,
|
|
1198
1165
|
DEFAULT_E3_CONFIG,
|
|
1199
1166
|
EnclaveEventType,
|
|
1200
1167
|
EnclaveSDK,
|
|
1201
1168
|
EventListener,
|
|
1202
|
-
FheProtocol,
|
|
1203
1169
|
RegistryEventType,
|
|
1204
1170
|
SDKError,
|
|
1171
|
+
ThresholdBfvParamsPresetNames,
|
|
1205
1172
|
calculateStartWindow,
|
|
1206
1173
|
convertToPolynomial,
|
|
1207
1174
|
convertToPolynomialArray,
|