Skip to content

Add TSS versioning & expiration - #4218

Merged
kajoseph merged 13 commits into
bitpay:masterfrom
kajoseph:addTssVersioningAndExpiry
Aug 28, 2026
Merged

kajoseph merged 13 commits into
bitpay:masterfrom
kajoseph:addTssVersioningAndExpiry

Conversation

@kajoseph

Copy link
Copy Markdown
Collaborator

Description

Adds versioning and expiration to TSS sessions to ensure a) there's some finality to sessions, and b) there's clarity around upgrades

Changelog

  • Adds versioning to TSS
  • Adds expiration to TSS sessions

Testing Notes

Tests have been added for both cases


Checklist

  • I have read CONTRIBUTING.md and verified that this PR follows the guidelines and requirements outlined in it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds TSS scheme version negotiation and session expiration to the Bitcore Wallet Service (BWS) and Bitcore Wallet Client (BWC) TSS flows, aiming to improve upgrade clarity and ensure TSS sessions eventually terminate.

Changes:

  • Added client/server TSS version checks (min/max bounds + session-version matching) for both keygen and signing.
  • Added time-limited TSS sessions (created timestamp + default TTL) and enforced expiry during authenticated TSS operations.
  • Updated BWC to send scheme versions, and expanded test coverage for versioning + expiration scenarios.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/bitcore-wallet-service/src/lib/tss.ts Adds scheme version enforcement and signature immutability checks in TSS keygen/sign flows.
packages/bitcore-wallet-service/src/lib/routes/tss.ts Threads version through TSS HTTP endpoints and documents route groupings.
packages/bitcore-wallet-service/src/lib/routes/middleware/verifyTssMessage.ts Switches to throwing ClientErrors and returning structured API errors via helper.
packages/bitcore-wallet-service/src/lib/routes/middleware/authTssRequest.ts Adds session attachment typing and enforces session expiration for authenticated TSS requests.
packages/bitcore-wallet-service/src/lib/model/tsssign.ts Adds createdOn/timeLimit to signing session model and threads version into model creation.
packages/bitcore-wallet-service/src/lib/model/tsskeygen.ts Adds version parameter and sets a default TTL for keygen sessions.
packages/bitcore-wallet-service/src/lib/errors/errordefinitions.ts Adds new TSS error codes/messages (expired, mismatch version, final sig mismatch).
packages/bitcore-wallet-service/src/lib/common/defaults.ts Bumps default scheme versions to 1.1 and adds default TTL constants.
packages/bitcore-wallet-service/src/lib/common/constants.ts Sets max scheme versions and introduces min server versions for keygen/sign.
packages/bitcore-wallet-client/test/tss.test.ts Adds/updates tests for client version gating and session expiration behaviors.
packages/bitcore-wallet-client/test/data/initialKeyGenState.json Adds fixture data to reproduce/restore a keygen session for expiry tests.
packages/bitcore-wallet-client/src/lib/tsssign.ts Sends signing scheme version on start and per-round message submits.
packages/bitcore-wallet-client/src/lib/tsskey.ts Sends keygen scheme version on start/join and per-round message submits.
packages/bitcore-wallet-client/src/lib/common/constants.ts Introduces client-side TSS scheme version constants.
Suppressed comments (2)

packages/bitcore-wallet-service/src/lib/tss.ts:447

  • Signing session expiration is only enforced via authTssRequest() (GET/store endpoints). The authenticated POST /v1/tss/sign/:id uses authRequest() instead and can still accept and mutate an expired signing session, which undermines the intended expiration semantics.
    if (session) {
      if (!this._isValidBroadcastMessage({ message }) && !this._isValidP2pMessage({ message })) {
        throw Errors.TSS_INVALID_MESSAGE.withMessage('Invalid message provided');
      }

packages/bitcore-wallet-service/src/lib/tss.ts:432

  • Number(params.version || 1.0) can produce NaN (e.g. non-numeric input), and NaN bypasses the current bounds checks. Reject non-finite versions explicitly so the API fails fast with a clear error instead of creating sessions that later always mismatch.
    const version = Number(params.version || 1.0);

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/bitcore-wallet-service/src/lib/tss.ts
Comment thread packages/bitcore-wallet-service/src/lib/tss.ts
Comment thread packages/bitcore-wallet-service/src/lib/model/tsssign.ts Outdated
Comment thread packages/bitcore-wallet-service/src/lib/tss.ts
@kajoseph
kajoseph requested review from MichaelAJay and a lite review from Copilot August 26, 2026 19:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Suppressed comments (1)

packages/bitcore-wallet-service/src/lib/tss.ts:96

  • Keygen version gating is comparing against the siggen min/max constants (TSS_SIGGEN_SCHEME_*) instead of the keygen constants. This will incorrectly gate keygen requests if the allowed ranges diverge (and is already inconsistent with the naming).
    if (version < Constants.TSS_SIGGEN_SCHEME_MIN_SERVER_VERSION) {
      throw Errors.UPGRADE_NEEDED;
    }
    if (version > Constants.TSS_SIGGEN_SCHEME_VERSION_MAX) {
      throw Errors.UPGRADE_NEEDED.withMessage('TSS version too new: ' + version);
    }

Comment thread packages/bitcore-wallet-service/src/lib/model/tsskeygen.ts Outdated
Comment thread packages/bitcore-wallet-service/src/lib/model/tsssign.ts Outdated
Comment thread packages/bitcore-wallet-service/src/lib/model/tsskeygen.ts
Comment thread packages/bitcore-wallet-service/src/lib/common/defaults.ts
Comment thread packages/bitcore-wallet-service/src/lib/model/tsssign.ts
Comment thread packages/bitcore-wallet-service/src/lib/common/constants.ts Outdated
Comment thread packages/bitcore-wallet-service/src/lib/routes/middleware/authTssRequest.ts Outdated
Comment thread packages/bitcore-cli/src/tss.ts
@kajoseph
kajoseph merged commit 4a2b83c into bitpay:master Aug 28, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants