@cofhe/sdk 1.1.0-alpha.0 → 1.1.0-alpha.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/core/decrypt/decryptForTxBuilder.ts +16 -0
- package/core/decrypt/decryptForViewBuilder.ts +14 -0
- package/core/decrypt/submitRetry.ts +16 -0
- package/core/decrypt/tnDecryptV2.ts +19 -9
- package/core/decrypt/tnSealOutputV2.ts +19 -9
- package/core/test/decryptBuilders.test.ts +51 -0
- package/dist/{chunk-2EO4JSR7.js → chunk-VE7DKXSF.js} +51 -20
- package/dist/{clientTypes-CnslFzxB.d.ts → clientTypes-B-qOZCx0.d.ts} +15 -0
- package/dist/{clientTypes-RXwLVWou.d.cts → clientTypes-D2djRDoH.d.cts} +15 -0
- package/dist/core.cjs +51 -20
- package/dist/core.d.cts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.js +1 -1
- package/dist/node.cjs +51 -20
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +1 -1
- package/dist/web.cjs +51 -20
- package/dist/web.d.cts +1 -1
- package/dist/web.d.ts +1 -1
- package/dist/web.js +1 -1
- package/package.json +1 -1
package/dist/web.cjs
CHANGED
|
@@ -3805,6 +3805,16 @@ function mapApiErrorCodeToCofheErrorCode(apiErrorCode, fallback) {
|
|
|
3805
3805
|
|
|
3806
3806
|
// core/decrypt/submitRetry.ts
|
|
3807
3807
|
var DEFAULT_404_RETRY_TIMEOUT_MS = 1e4;
|
|
3808
|
+
var DEFAULT_DECRYPT_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
3809
|
+
function assertDecryptTimeoutMs(timeoutMs, operationLabel) {
|
|
3810
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
3811
|
+
throw new CofheError({
|
|
3812
|
+
code: "INTERNAL_ERROR" /* InternalError */,
|
|
3813
|
+
message: `${operationLabel}: setTimeout(timeoutMs) expects a finite number greater than 0.`,
|
|
3814
|
+
context: { timeoutMs }
|
|
3815
|
+
});
|
|
3816
|
+
}
|
|
3817
|
+
}
|
|
3808
3818
|
function normalize404RetryTimeoutMs(params) {
|
|
3809
3819
|
const { timeoutMs, operationLabel, errorCode } = params;
|
|
3810
3820
|
if (timeoutMs === void 0)
|
|
@@ -3943,7 +3953,6 @@ function parseDecryptedBytesToBigInt(decrypted) {
|
|
|
3943
3953
|
// core/decrypt/tnSealOutputV2.ts
|
|
3944
3954
|
var POLL_INTERVAL_MS = 1e3;
|
|
3945
3955
|
var POLL_MAX_INTERVAL_MS = 1e4;
|
|
3946
|
-
var SEAL_OUTPUT_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
3947
3956
|
var SUBMIT_RETRY_INTERVAL_MS = 1e3;
|
|
3948
3957
|
function numberArrayToUint8Array(arr) {
|
|
3949
3958
|
return new Uint8Array(arr);
|
|
@@ -4001,7 +4010,7 @@ function parseCompletedSealOutputResponse(params) {
|
|
|
4001
4010
|
}
|
|
4002
4011
|
return convertSealedData(sealed);
|
|
4003
4012
|
}
|
|
4004
|
-
async function submitSealOutputRequest(thresholdNetworkUrl, ctHash, chainId, acp, overallStartTime, retry404TimeoutMs, onPoll) {
|
|
4013
|
+
async function submitSealOutputRequest(thresholdNetworkUrl, ctHash, chainId, acp, overallStartTime, retry404TimeoutMs, timeoutMs, onPoll) {
|
|
4005
4014
|
const body = {
|
|
4006
4015
|
ct_tempkey: BigInt(ctHash).toString(16).padStart(64, "0"),
|
|
4007
4016
|
host_chain_id: chainId,
|
|
@@ -4104,7 +4113,7 @@ async function submitSealOutputRequest(thresholdNetworkUrl, ctHash, chainId, acp
|
|
|
4104
4113
|
status: responseClassification.status,
|
|
4105
4114
|
elapsedMs,
|
|
4106
4115
|
retry404TimeoutMs,
|
|
4107
|
-
overallTimeoutMs:
|
|
4116
|
+
overallTimeoutMs: timeoutMs,
|
|
4108
4117
|
thresholdNetworkUrl,
|
|
4109
4118
|
body,
|
|
4110
4119
|
attemptIndex,
|
|
@@ -4116,13 +4125,13 @@ async function submitSealOutputRequest(thresholdNetworkUrl, ctHash, chainId, acp
|
|
|
4116
4125
|
attemptIndex,
|
|
4117
4126
|
elapsedMs,
|
|
4118
4127
|
intervalMs: SUBMIT_RETRY_INTERVAL_MS,
|
|
4119
|
-
timeoutMs
|
|
4128
|
+
timeoutMs
|
|
4120
4129
|
});
|
|
4121
4130
|
await new Promise((resolve) => setTimeout(resolve, SUBMIT_RETRY_INTERVAL_MS));
|
|
4122
4131
|
attemptIndex += 1;
|
|
4123
4132
|
}
|
|
4124
4133
|
}
|
|
4125
|
-
async function pollSealOutputStatus(thresholdNetworkUrl, requestId, overallStartTime, onPoll) {
|
|
4134
|
+
async function pollSealOutputStatus(thresholdNetworkUrl, requestId, overallStartTime, timeoutMs, onPoll) {
|
|
4126
4135
|
let attemptIndex = 0;
|
|
4127
4136
|
while (true) {
|
|
4128
4137
|
const elapsedMs = Date.now() - overallStartTime;
|
|
@@ -4136,17 +4145,17 @@ async function pollSealOutputStatus(thresholdNetworkUrl, requestId, overallStart
|
|
|
4136
4145
|
attemptIndex,
|
|
4137
4146
|
elapsedMs,
|
|
4138
4147
|
intervalMs,
|
|
4139
|
-
timeoutMs
|
|
4148
|
+
timeoutMs
|
|
4140
4149
|
});
|
|
4141
|
-
if (elapsedMs >
|
|
4150
|
+
if (elapsedMs > timeoutMs) {
|
|
4142
4151
|
throw new CofheError({
|
|
4143
4152
|
code: "SEAL_OUTPUT_FAILED" /* SealOutputFailed */,
|
|
4144
|
-
message: `sealOutput polling timed out after ${
|
|
4153
|
+
message: `sealOutput polling timed out after ${timeoutMs}ms`,
|
|
4145
4154
|
hint: "The request may still be processing. Try again later.",
|
|
4146
4155
|
context: {
|
|
4147
4156
|
thresholdNetworkUrl,
|
|
4148
4157
|
requestId,
|
|
4149
|
-
timeoutMs
|
|
4158
|
+
timeoutMs
|
|
4150
4159
|
}
|
|
4151
4160
|
});
|
|
4152
4161
|
}
|
|
@@ -4234,6 +4243,7 @@ async function pollSealOutputStatus(thresholdNetworkUrl, requestId, overallStart
|
|
|
4234
4243
|
}
|
|
4235
4244
|
async function tnSealOutputV2(params) {
|
|
4236
4245
|
const { thresholdNetworkUrl, ctHash, chainId, acp, retry404TimeoutMs, onPoll } = params;
|
|
4246
|
+
const timeoutMs = params.timeoutMs ?? DEFAULT_DECRYPT_TIMEOUT_MS;
|
|
4237
4247
|
const normalized404RetryTimeoutMs = normalize404RetryTimeoutMs({
|
|
4238
4248
|
timeoutMs: retry404TimeoutMs,
|
|
4239
4249
|
operationLabel: "sealOutput",
|
|
@@ -4247,12 +4257,13 @@ async function tnSealOutputV2(params) {
|
|
|
4247
4257
|
acp,
|
|
4248
4258
|
overallStartTime,
|
|
4249
4259
|
normalized404RetryTimeoutMs,
|
|
4260
|
+
timeoutMs,
|
|
4250
4261
|
onPoll
|
|
4251
4262
|
);
|
|
4252
4263
|
if (submitResult.kind === "completed") {
|
|
4253
4264
|
return submitResult.sealed;
|
|
4254
4265
|
}
|
|
4255
|
-
return await pollSealOutputStatus(thresholdNetworkUrl, submitResult.requestId, overallStartTime, onPoll);
|
|
4266
|
+
return await pollSealOutputStatus(thresholdNetworkUrl, submitResult.requestId, overallStartTime, timeoutMs, onPoll);
|
|
4256
4267
|
}
|
|
4257
4268
|
|
|
4258
4269
|
// core/decrypt/decryptForViewBuilder.ts
|
|
@@ -4264,6 +4275,7 @@ var DecryptForViewBuilder = class extends BaseBuilder {
|
|
|
4264
4275
|
acp;
|
|
4265
4276
|
pollCallback;
|
|
4266
4277
|
retry404TimeoutMs = DEFAULT_404_RETRY_TIMEOUT_MS2;
|
|
4278
|
+
timeoutMs;
|
|
4267
4279
|
constructor(params) {
|
|
4268
4280
|
super({
|
|
4269
4281
|
config: params.config,
|
|
@@ -4337,6 +4349,16 @@ var DecryptForViewBuilder = class extends BaseBuilder {
|
|
|
4337
4349
|
this.retry404TimeoutMs = timeoutMs;
|
|
4338
4350
|
return this;
|
|
4339
4351
|
}
|
|
4352
|
+
/**
|
|
4353
|
+
* The whole budget of this decrypt in milliseconds, submit retries and status polling together
|
|
4354
|
+
* (5 minutes by default). Past it, `execute()` rejects with `SealOutputFailed`; a request still
|
|
4355
|
+
* processing on the threshold network is not cancelled.
|
|
4356
|
+
*/
|
|
4357
|
+
setTimeout(timeoutMs) {
|
|
4358
|
+
assertDecryptTimeoutMs(timeoutMs, "decryptForView");
|
|
4359
|
+
this.timeoutMs = timeoutMs;
|
|
4360
|
+
return this;
|
|
4361
|
+
}
|
|
4340
4362
|
withACP(acpOrACPHash) {
|
|
4341
4363
|
if (typeof acpOrACPHash === "string") {
|
|
4342
4364
|
this.acpHash = acpOrACPHash;
|
|
@@ -4466,6 +4488,7 @@ var DecryptForViewBuilder = class extends BaseBuilder {
|
|
|
4466
4488
|
acp: wireAcp,
|
|
4467
4489
|
thresholdNetworkUrl,
|
|
4468
4490
|
retry404TimeoutMs: this.retry404TimeoutMs,
|
|
4491
|
+
timeoutMs: this.timeoutMs,
|
|
4469
4492
|
onPoll: this.pollCallback
|
|
4470
4493
|
});
|
|
4471
4494
|
return ACPUtils.unseal(acp, sealed);
|
|
@@ -4568,7 +4591,6 @@ async function cofheMocksDecryptForTx(ctHash, utype, acp, publicClient) {
|
|
|
4568
4591
|
// core/decrypt/tnDecryptV2.ts
|
|
4569
4592
|
var POLL_INTERVAL_MS2 = 1e3;
|
|
4570
4593
|
var POLL_MAX_INTERVAL_MS2 = 1e4;
|
|
4571
|
-
var DECRYPT_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
4572
4594
|
var SUBMIT_RETRY_INTERVAL_MS2 = 1e3;
|
|
4573
4595
|
function assertDecryptSubmitResponseV2(value) {
|
|
4574
4596
|
if (value == null || typeof value !== "object") {
|
|
@@ -4685,7 +4707,7 @@ function assertDecryptStatusResponseV2(value) {
|
|
|
4685
4707
|
}
|
|
4686
4708
|
return value;
|
|
4687
4709
|
}
|
|
4688
|
-
async function submitDecryptRequestV2(thresholdNetworkUrl, ctHash, chainId, acp, overallStartTime, retry404TimeoutMs, onPoll) {
|
|
4710
|
+
async function submitDecryptRequestV2(thresholdNetworkUrl, ctHash, chainId, acp, overallStartTime, retry404TimeoutMs, timeoutMs, onPoll) {
|
|
4689
4711
|
const body = {
|
|
4690
4712
|
ct_tempkey: BigInt(ctHash).toString(16).padStart(64, "0"),
|
|
4691
4713
|
host_chain_id: chainId
|
|
@@ -4792,7 +4814,7 @@ async function submitDecryptRequestV2(thresholdNetworkUrl, ctHash, chainId, acp,
|
|
|
4792
4814
|
status: responseClassification.status,
|
|
4793
4815
|
elapsedMs,
|
|
4794
4816
|
retry404TimeoutMs,
|
|
4795
|
-
overallTimeoutMs:
|
|
4817
|
+
overallTimeoutMs: timeoutMs,
|
|
4796
4818
|
thresholdNetworkUrl,
|
|
4797
4819
|
body,
|
|
4798
4820
|
attemptIndex,
|
|
@@ -4804,13 +4826,13 @@ async function submitDecryptRequestV2(thresholdNetworkUrl, ctHash, chainId, acp,
|
|
|
4804
4826
|
attemptIndex,
|
|
4805
4827
|
elapsedMs,
|
|
4806
4828
|
intervalMs: SUBMIT_RETRY_INTERVAL_MS2,
|
|
4807
|
-
timeoutMs
|
|
4829
|
+
timeoutMs
|
|
4808
4830
|
});
|
|
4809
4831
|
await new Promise((resolve) => setTimeout(resolve, SUBMIT_RETRY_INTERVAL_MS2));
|
|
4810
4832
|
attemptIndex += 1;
|
|
4811
4833
|
}
|
|
4812
4834
|
}
|
|
4813
|
-
async function pollDecryptStatusV2(thresholdNetworkUrl, requestId, overallStartTime, onPoll) {
|
|
4835
|
+
async function pollDecryptStatusV2(thresholdNetworkUrl, requestId, overallStartTime, timeoutMs, onPoll) {
|
|
4814
4836
|
let attemptIndex = 0;
|
|
4815
4837
|
while (true) {
|
|
4816
4838
|
const elapsedMs = Date.now() - overallStartTime;
|
|
@@ -4824,17 +4846,17 @@ async function pollDecryptStatusV2(thresholdNetworkUrl, requestId, overallStartT
|
|
|
4824
4846
|
attemptIndex,
|
|
4825
4847
|
elapsedMs,
|
|
4826
4848
|
intervalMs,
|
|
4827
|
-
timeoutMs
|
|
4849
|
+
timeoutMs
|
|
4828
4850
|
});
|
|
4829
|
-
if (elapsedMs >
|
|
4851
|
+
if (elapsedMs > timeoutMs) {
|
|
4830
4852
|
throw new CofheError({
|
|
4831
4853
|
code: "DECRYPT_FAILED" /* DecryptFailed */,
|
|
4832
|
-
message: `decrypt polling timed out after ${
|
|
4854
|
+
message: `decrypt polling timed out after ${timeoutMs}ms`,
|
|
4833
4855
|
hint: "The request may still be processing. Try again later.",
|
|
4834
4856
|
context: {
|
|
4835
4857
|
thresholdNetworkUrl,
|
|
4836
4858
|
requestId,
|
|
4837
|
-
timeoutMs
|
|
4859
|
+
timeoutMs
|
|
4838
4860
|
}
|
|
4839
4861
|
});
|
|
4840
4862
|
}
|
|
@@ -4923,6 +4945,7 @@ async function pollDecryptStatusV2(thresholdNetworkUrl, requestId, overallStartT
|
|
|
4923
4945
|
}
|
|
4924
4946
|
async function tnDecryptV2(params) {
|
|
4925
4947
|
const { thresholdNetworkUrl, ctHash, chainId, acp, retry404TimeoutMs, onPoll } = params;
|
|
4948
|
+
const timeoutMs = params.timeoutMs ?? DEFAULT_DECRYPT_TIMEOUT_MS;
|
|
4926
4949
|
const normalized404RetryTimeoutMs = normalize404RetryTimeoutMs({
|
|
4927
4950
|
timeoutMs: retry404TimeoutMs,
|
|
4928
4951
|
operationLabel: "decrypt",
|
|
@@ -4936,12 +4959,13 @@ async function tnDecryptV2(params) {
|
|
|
4936
4959
|
acp,
|
|
4937
4960
|
overallStartTime,
|
|
4938
4961
|
normalized404RetryTimeoutMs,
|
|
4962
|
+
timeoutMs,
|
|
4939
4963
|
onPoll
|
|
4940
4964
|
);
|
|
4941
4965
|
if (submitResult.kind === "completed") {
|
|
4942
4966
|
return submitResult;
|
|
4943
4967
|
}
|
|
4944
|
-
return await pollDecryptStatusV2(thresholdNetworkUrl, submitResult.requestId, overallStartTime, onPoll);
|
|
4968
|
+
return await pollDecryptStatusV2(thresholdNetworkUrl, submitResult.requestId, overallStartTime, timeoutMs, onPoll);
|
|
4945
4969
|
}
|
|
4946
4970
|
|
|
4947
4971
|
// core/decrypt/decryptForTxBuilder.ts
|
|
@@ -4953,6 +4977,7 @@ var DecryptForTxBuilder = class extends BaseBuilder {
|
|
|
4953
4977
|
acpSelection = "unset";
|
|
4954
4978
|
pollCallback;
|
|
4955
4979
|
retry404TimeoutMs = DEFAULT_404_RETRY_TIMEOUT_MS3;
|
|
4980
|
+
timeoutMs;
|
|
4956
4981
|
constructor(params) {
|
|
4957
4982
|
super({
|
|
4958
4983
|
config: params.config,
|
|
@@ -4995,6 +5020,11 @@ var DecryptForTxBuilder = class extends BaseBuilder {
|
|
|
4995
5020
|
this.retry404TimeoutMs = timeoutMs;
|
|
4996
5021
|
return this;
|
|
4997
5022
|
}
|
|
5023
|
+
setTimeout(timeoutMs) {
|
|
5024
|
+
assertDecryptTimeoutMs(timeoutMs, "decryptForTx");
|
|
5025
|
+
this.timeoutMs = timeoutMs;
|
|
5026
|
+
return this;
|
|
5027
|
+
}
|
|
4998
5028
|
withACP(acpOrACPHash) {
|
|
4999
5029
|
if (this.acpSelection === "with-acp") {
|
|
5000
5030
|
throw new CofheError({
|
|
@@ -5128,6 +5158,7 @@ var DecryptForTxBuilder = class extends BaseBuilder {
|
|
|
5128
5158
|
acp: wireAcp,
|
|
5129
5159
|
thresholdNetworkUrl,
|
|
5130
5160
|
retry404TimeoutMs: this.retry404TimeoutMs,
|
|
5161
|
+
timeoutMs: this.timeoutMs,
|
|
5131
5162
|
onPoll: this.pollCallback
|
|
5132
5163
|
});
|
|
5133
5164
|
return {
|
package/dist/web.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as IStorage, C as CofheInputConfig, a as CofheConfig, b as CofheClient, E as EncryptableItem } from './clientTypes-
|
|
1
|
+
import { I as IStorage, C as CofheInputConfig, a as CofheConfig, b as CofheClient, E as EncryptableItem } from './clientTypes-D2djRDoH.cjs';
|
|
2
2
|
import 'viem';
|
|
3
3
|
import './types-C07FK-cL.cjs';
|
|
4
4
|
import 'zod';
|
package/dist/web.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as IStorage, C as CofheInputConfig, a as CofheConfig, b as CofheClient, E as EncryptableItem } from './clientTypes-
|
|
1
|
+
import { I as IStorage, C as CofheInputConfig, a as CofheConfig, b as CofheClient, E as EncryptableItem } from './clientTypes-B-qOZCx0.js';
|
|
2
2
|
import 'viem';
|
|
3
3
|
import './types-C07FK-cL.js';
|
|
4
4
|
import 'zod';
|
package/dist/web.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createCofheConfigBase, createCofheClientBase } from './chunk-
|
|
1
|
+
import { createCofheConfigBase, createCofheClientBase } from './chunk-VE7DKXSF.js';
|
|
2
2
|
import './chunk-UKQAJK4N.js';
|
|
3
3
|
import './chunk-3L2IVPMI.js';
|
|
4
4
|
import { initTfheThreadPool } from './chunk-KSOV5B4B.js';
|