@unicitylabs/sphere-sdk 0.14.3 → 0.14.5
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/dist/connect/index.cjs +1 -1
- package/dist/connect/index.cjs.map +1 -1
- package/dist/connect/index.js +1 -1
- package/dist/connect/index.js.map +1 -1
- package/dist/core/index.cjs +234 -24
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +234 -24
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/connect/index.cjs +1 -1
- package/dist/impl/browser/connect/index.cjs.map +1 -1
- package/dist/impl/browser/connect/index.js +1 -1
- package/dist/impl/browser/connect/index.js.map +1 -1
- package/dist/impl/wallet-api-v2/index.cjs +1 -0
- package/dist/impl/wallet-api-v2/index.cjs.map +1 -1
- package/dist/impl/wallet-api-v2/index.js +1 -0
- package/dist/impl/wallet-api-v2/index.js.map +1 -1
- package/dist/index.cjs +234 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +234 -24
- package/dist/index.js.map +1 -1
- package/dist/modules/payments-v2/index.cjs +144 -17
- package/dist/modules/payments-v2/index.cjs.map +1 -1
- package/dist/modules/payments-v2/index.d.cts +2 -0
- package/dist/modules/payments-v2/index.d.ts +2 -0
- package/dist/modules/payments-v2/index.js +144 -17
- package/dist/modules/payments-v2/index.js.map +1 -1
- package/dist/token-engine/index.cjs +91 -7
- package/dist/token-engine/index.cjs.map +1 -1
- package/dist/token-engine/index.d.cts +5 -1
- package/dist/token-engine/index.d.ts +5 -1
- package/dist/token-engine/index.js +91 -7
- package/dist/token-engine/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -341,7 +341,11 @@ interface EngineConfig {
|
|
|
341
341
|
readonly trustBaseJson: unknown;
|
|
342
342
|
/** Inclusion-proof poll cadence in ms (engine owns the await policy; Spike S1). */
|
|
343
343
|
readonly proofPollIntervalMs?: number;
|
|
344
|
-
/**
|
|
344
|
+
/**
|
|
345
|
+
* Deadline for ONE inclusion-proof wait, in ms. Undefined → 10s. Must be
|
|
346
|
+
* positive: an unbounded wait hangs the op and with it teardown (#739), so
|
|
347
|
+
* there is no "no cap" value — 0 or negative throws INVALID_CONFIG.
|
|
348
|
+
*/
|
|
345
349
|
readonly proofTimeoutMs?: number;
|
|
346
350
|
/**
|
|
347
351
|
* Opt in to parallel verification. Omitted → the sequential verifier, i.e. the
|
|
@@ -341,7 +341,11 @@ interface EngineConfig {
|
|
|
341
341
|
readonly trustBaseJson: unknown;
|
|
342
342
|
/** Inclusion-proof poll cadence in ms (engine owns the await policy; Spike S1). */
|
|
343
343
|
readonly proofPollIntervalMs?: number;
|
|
344
|
-
/**
|
|
344
|
+
/**
|
|
345
|
+
* Deadline for ONE inclusion-proof wait, in ms. Undefined → 10s. Must be
|
|
346
|
+
* positive: an unbounded wait hangs the op and with it teardown (#739), so
|
|
347
|
+
* there is no "no cap" value — 0 or negative throws INVALID_CONFIG.
|
|
348
|
+
*/
|
|
345
349
|
readonly proofTimeoutMs?: number;
|
|
346
350
|
/**
|
|
347
351
|
* Opt in to parallel verification. Omitted → the sequential verifier, i.e. the
|
|
@@ -7,6 +7,7 @@ import { CertificationResponse, CertificationStatus } from "@unicitylabs/state-t
|
|
|
7
7
|
import { StateId } from "@unicitylabs/state-transition-sdk/lib/api/StateId.js";
|
|
8
8
|
import { InclusionProof } from "@unicitylabs/state-transition-sdk/lib/api/InclusionProof.js";
|
|
9
9
|
import { InclusionProofResponse } from "@unicitylabs/state-transition-sdk/lib/api/InclusionProofResponse.js";
|
|
10
|
+
import { JsonRpcNetworkError } from "@unicitylabs/state-transition-sdk/lib/api/json-rpc/JsonRpcNetworkError.js";
|
|
10
11
|
import { RootTrustBase } from "@unicitylabs/state-transition-sdk/lib/api/bft/RootTrustBase.js";
|
|
11
12
|
import { waitInclusionProof } from "@unicitylabs/state-transition-sdk/lib/util/InclusionProofUtils.js";
|
|
12
13
|
import { InclusionProofVerificationStatus } from "@unicitylabs/state-transition-sdk/lib/transaction/verification/rule/InclusionProofVerificationRule.js";
|
|
@@ -284,6 +285,75 @@ function decodeSpherePaymentData(bytes) {
|
|
|
284
285
|
return Promise.resolve(SpherePaymentData.fromCBOR(bytes));
|
|
285
286
|
}
|
|
286
287
|
|
|
288
|
+
// token-engine/proof-wait.ts
|
|
289
|
+
var DEFAULT_PROOF_TIMEOUT_MS = 1e4;
|
|
290
|
+
function resolveProofTimeoutMs(configured) {
|
|
291
|
+
if (configured === void 0) return DEFAULT_PROOF_TIMEOUT_MS;
|
|
292
|
+
if (!Number.isFinite(configured) || configured <= 0) {
|
|
293
|
+
throw new SphereError(
|
|
294
|
+
`proofTimeoutMs must be a positive number of milliseconds (got ${String(configured)}); an unbounded inclusion-proof wait is not supported`,
|
|
295
|
+
"INVALID_CONFIG"
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
return configured;
|
|
299
|
+
}
|
|
300
|
+
var TRANSIENT_HTTP_STATUSES = /* @__PURE__ */ new Set([408, 425, 429, 500, 502, 503, 504]);
|
|
301
|
+
function isTransientGatewayError(err) {
|
|
302
|
+
return err instanceof JsonRpcNetworkError && TRANSIENT_HTTP_STATUSES.has(err.status);
|
|
303
|
+
}
|
|
304
|
+
function pause(ms, signal) {
|
|
305
|
+
return new Promise((resolve) => {
|
|
306
|
+
const timer = setTimeout(resolve, ms);
|
|
307
|
+
signal.addEventListener(
|
|
308
|
+
"abort",
|
|
309
|
+
() => {
|
|
310
|
+
clearTimeout(timer);
|
|
311
|
+
resolve();
|
|
312
|
+
},
|
|
313
|
+
{ once: true }
|
|
314
|
+
);
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
async function awaitProofBounded(deps, transaction, external) {
|
|
318
|
+
const controller = new AbortController();
|
|
319
|
+
const relayAbort = () => {
|
|
320
|
+
controller.abort(external?.reason);
|
|
321
|
+
};
|
|
322
|
+
if (external !== void 0) {
|
|
323
|
+
if (external.aborted) relayAbort();
|
|
324
|
+
else external.addEventListener("abort", relayAbort, { once: true });
|
|
325
|
+
}
|
|
326
|
+
const timer = setTimeout(() => {
|
|
327
|
+
controller.abort(
|
|
328
|
+
new SphereError(
|
|
329
|
+
`inclusion proof not confirmed within ${String(deps.timeoutMs)} ms`,
|
|
330
|
+
"AGGREGATOR_ERROR"
|
|
331
|
+
)
|
|
332
|
+
);
|
|
333
|
+
}, deps.timeoutMs);
|
|
334
|
+
try {
|
|
335
|
+
for (; ; ) {
|
|
336
|
+
try {
|
|
337
|
+
return await waitInclusionProof(
|
|
338
|
+
deps.client,
|
|
339
|
+
deps.trustBase,
|
|
340
|
+
deps.predicateVerifier,
|
|
341
|
+
transaction,
|
|
342
|
+
controller.signal,
|
|
343
|
+
deps.intervalMs
|
|
344
|
+
);
|
|
345
|
+
} catch (err) {
|
|
346
|
+
if (controller.signal.aborted) throw err;
|
|
347
|
+
if (!isTransientGatewayError(err)) throw err;
|
|
348
|
+
await pause(deps.intervalMs, controller.signal);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
} finally {
|
|
352
|
+
clearTimeout(timer);
|
|
353
|
+
external?.removeEventListener("abort", relayAbort);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
287
357
|
// core/uuid.ts
|
|
288
358
|
function randomUUID() {
|
|
289
359
|
const c = globalThis.crypto;
|
|
@@ -941,11 +1011,13 @@ var SphereTokenEngine = class {
|
|
|
941
1011
|
constructor(deps) {
|
|
942
1012
|
this.deps = deps;
|
|
943
1013
|
this.privateKeyHex = HexConverter.encode(deps.privateKey);
|
|
1014
|
+
this.proofTimeoutMs = resolveProofTimeoutMs(deps.proofTimeoutMs);
|
|
944
1015
|
}
|
|
945
1016
|
/** F13 advertisement: mint under a (transferId, opIndex) seed is idempotent-recoverable — a same-seed re-call converges, never double-mints. */
|
|
946
1017
|
deterministicMint = true;
|
|
947
1018
|
/** Hex form of the wallet key — deriveRealization's ikm input (Part E.1). */
|
|
948
1019
|
privateKeyHex;
|
|
1020
|
+
proofTimeoutMs;
|
|
949
1021
|
// ── identity ────────────────────────────────────────────────────────────────
|
|
950
1022
|
getIdentity() {
|
|
951
1023
|
return { chainPubkey: new Uint8Array(this.deps.signingService.publicKey) };
|
|
@@ -1288,14 +1360,17 @@ var SphereTokenEngine = class {
|
|
|
1288
1360
|
submitError = err ?? new SphereError(`${failLabel}: submit failed`, failCode);
|
|
1289
1361
|
}
|
|
1290
1362
|
try {
|
|
1291
|
-
return await
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1363
|
+
return await awaitProofBounded(
|
|
1364
|
+
{
|
|
1365
|
+
client: this.deps.client,
|
|
1366
|
+
trustBase: this.deps.trustBase,
|
|
1367
|
+
predicateVerifier: this.deps.predicateVerifier,
|
|
1368
|
+
timeoutMs: this.proofTimeoutMs,
|
|
1369
|
+
intervalMs: this.deps.proofPollIntervalMs ?? DEFAULT_PROOF_POLL_INTERVAL_MS
|
|
1370
|
+
// #683
|
|
1371
|
+
},
|
|
1295
1372
|
transaction,
|
|
1296
|
-
options?.signal
|
|
1297
|
-
this.deps.proofPollIntervalMs ?? DEFAULT_PROOF_POLL_INTERVAL_MS
|
|
1298
|
-
// #683 finer poll cadence
|
|
1373
|
+
options?.signal
|
|
1299
1374
|
);
|
|
1300
1375
|
} catch (err) {
|
|
1301
1376
|
if (err instanceof Error && err.message === `Invalid inclusion proof status: ${InclusionProofVerificationStatus.TRANSACTION_HASH_MISMATCH}`) {
|
|
@@ -1311,6 +1386,13 @@ var SphereTokenEngine = class {
|
|
|
1311
1386
|
);
|
|
1312
1387
|
}
|
|
1313
1388
|
}
|
|
1389
|
+
/**
|
|
1390
|
+
* One inclusion-proof wait, with the deadline OWNED here (#739). The SDK's own
|
|
1391
|
+
* default deadline is unreliable — see lateDeliveringSignal — and a lost one
|
|
1392
|
+
* means an op that never settles, which also wedges PaymentsFacade.stop().
|
|
1393
|
+
* A deadline hit throws, and the caller maps that to ProofUnconfirmedError
|
|
1394
|
+
* (keep-open), which is the correct posture: the spend may be on-chain.
|
|
1395
|
+
*/
|
|
1314
1396
|
/** Fail fast if this engine's key does not own the token's current state. */
|
|
1315
1397
|
assertOwned(token) {
|
|
1316
1398
|
if (!this.isOwnedBy(token, this.deps.signingService.publicKey)) {
|
|
@@ -1410,6 +1492,8 @@ async function createSphereTokenEngine(config) {
|
|
|
1410
1492
|
networkId: trustBase.networkId,
|
|
1411
1493
|
// #683: forward the (optional) proof-poll cadence; undefined → the engine default.
|
|
1412
1494
|
proofPollIntervalMs: config.proofPollIntervalMs,
|
|
1495
|
+
proofTimeoutMs: config.proofTimeoutMs,
|
|
1496
|
+
// #739: was declared but never wired
|
|
1413
1497
|
// Opt-in parallel verification (2.0.2). Absent → the sequential verifier.
|
|
1414
1498
|
...config.verification ? { tokenVerifier: createWorkerTokenVerifier(config.verification) } : {}
|
|
1415
1499
|
};
|