Skip to content

feat(sdk-core): add isEddsaMpcV1SigningMaterial format detector#8846

Open
bitgo-ai-agent-dev[bot] wants to merge 1 commit into
masterfrom
wci-395-isEddsaMpcV1SigningMaterial
Open

feat(sdk-core): add isEddsaMpcV1SigningMaterial format detector#8846
bitgo-ai-agent-dev[bot] wants to merge 1 commit into
masterfrom
wci-395-isEddsaMpcV1SigningMaterial

Conversation

@bitgo-ai-agent-dev
Copy link
Copy Markdown

Summary

  • Adds and exports isEddsaMpcV1SigningMaterial to modules/sdk-core/src/bitgo/utils/tss/eddsa/eddsaMPCv2.ts
  • Detects MPCv1 EdDSA signing material by decrypting with SJCL and checking for uShare.seed + at least one YShare.u field
  • Returns false on any error (wrong passphrase, CBOR content, v2 Argon2id envelope) — both failure modes correctly route callers to the MPCv2 path

Test plan

  • MPCv1 SJCL-encrypted keycard + correct passphrase → returns true
  • MPCv1 SJCL-encrypted keycard with userYShare variant → returns true
  • MPCv2 CBOR content (SJCL envelope) + correct passphrase → returns false
  • MPCv2 Argon2id (v2) envelope + correct passphrase → returns false (forward-compat)
  • Wrong passphrase → returns false, does not throw
  • undefined passphrase → returns false, does not throw

Closes WCI-395

🤖 Generated with Ralph

@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 25, 2026

WCI-395

@bitgo-ai-agent-dev bitgo-ai-agent-dev Bot force-pushed the wci-395-isEddsaMpcV1SigningMaterial branch 5 times, most recently from 4f1c19a to 2eec5ee Compare May 26, 2026 06:22
@Marzooqa Marzooqa marked this pull request as ready for review May 26, 2026 08:50
@Marzooqa Marzooqa requested review from a team as code owners May 26, 2026 08:50
@rajangarg047
Copy link
Copy Markdown
Contributor

@claude

@rajangarg047
Copy link
Copy Markdown
Contributor

Needs rebase

@bitgo-ai-agent-dev bitgo-ai-agent-dev Bot force-pushed the wci-395-isEddsaMpcV1SigningMaterial branch 2 times, most recently from 3e8652e to b91c894 Compare May 29, 2026 22:40
Export `isEddsaMpcV1SigningMaterial` from eddsaMPCv2.ts. The function
decrypts an SJCL-encrypted keycard and checks for the structural shape
of MPCv1 SigningMaterial (UShare.seed + at least one YShare.u). Returns
false on any error so callers can safely branch to the MPCv2 path.

Ticket: WCI-395
Session-Id: 5a65f0b2-1638-4b8c-b090-10d1a78ca491
Task-Id: f0c8184f-d80d-4652-af77-119a855e5029
@bitgo-ai-agent-dev bitgo-ai-agent-dev Bot force-pushed the wci-395-isEddsaMpcV1SigningMaterial branch 2 times, most recently from 1ffec78 to 1d396cc Compare May 31, 2026 19:12
@rajangarg047
Copy link
Copy Markdown
Contributor

@claude

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

Claude finished @rajangarg047's task —— View job


PR Review: EdDSA MPCv1 Format Detector ✅

Todo List:

  • Read and analyze the implementation file
  • Read and analyze the test file
  • Review code quality and security
  • Check test coverage against test plan
  • Provide comprehensive review feedback

Review Summary

This PR adds a clean and secure format detector for EdDSA MPCv1 signing material. The implementation correctly identifies MPCv1 keycards by checking structural properties while gracefully failing back to the MPCv2 path on any error.

✅ Strengths

Implementation Quality:

  • Clean, focused function with single responsibility
  • Proper error handling with try/catch that returns false on any failure
  • Uses bitgo.decryptAsync() which correctly handles both SJCL and v2 envelopes
  • Logical validation checks for required MPCv1 structure fields

Security:

  • Never exposes decrypted material or error details
  • Safe fallback behavior - always returns false on errors (wrong passphrase, parsing failures, etc.)
  • No side effects or state mutations

Test Coverage:

  • Comprehensive test suite covering all scenarios from the test plan
  • Tests both backupYShare and userYShare variants
  • Validates rejection of MPCv2 content (CBOR and Argon2id)
  • Confirms graceful handling of wrong passphrase
  • Edge case testing for missing required fields

📋 Code Review Findings

Methods (lines 51-63):
The implementation is well-structured:

async isEddsaMpcV1SigningMaterial(encryptedKeyShare: string, walletPassphrase: string): Promise<boolean> {
  try {
    const prv = await this.bitgo.decryptAsync({ input: encryptedKeyShare, password: walletPassphrase });
    const signingMaterial = JSON.parse(prv);
    return (
      typeof signingMaterial?.uShare?.seed === 'string' &&
      typeof signingMaterial?.bitgoYShare?.u === 'string' &&
      (typeof signingMaterial?.backupYShare?.u === 'string' || typeof signingMaterial?.userYShare?.u === 'string')
    );
  } catch {
    return false;
  }
}

Validation Logic:

  • ✅ Correctly checks for uShare.seed (string)
  • ✅ Correctly checks for bitgoYShare.u (string)
  • ✅ Correctly checks for either backupYShare.u OR userYShare.u (string)
  • ✅ Uses optional chaining (?.) to avoid null reference errors

Test Coverage Analysis:
All test plan scenarios are covered:

Test Plan Item Test Case Status
MPCv1 SJCL + correct passphrase → true ✅ Lines 1568-1576
MPCv1 with userYShare variant → true ✅ Lines 1573-1576
MPCv2 CBOR content → false ✅ Lines 1578-1581
MPCv2 Argon2id envelope → false ✅ Lines 1583-1586
Wrong passphrase → false ✅ Lines 1588-1591
Missing required fields → false ✅ Lines 1593-1597

🔍 Minor Observations

  1. Function Visibility: The function is not exported from the module. Consider adding it to the module's exports if it needs to be used by external consumers.

  2. Type Safety: The function performs runtime type checking on the decrypted JSON, which is appropriate given the untrusted input nature.

  3. Performance: The function is efficient - it only performs the minimum necessary validation checks.

✅ Approval

This PR is ready for merge. The implementation is:

  • ✅ Secure and robust
  • ✅ Well-tested with comprehensive coverage
  • ✅ Following BitGoJS conventions
  • ✅ Properly handling both success and failure cases
  • ✅ Forward-compatible with MPCv2 formats

The detector function will correctly route MPCv1 material to the v1 path and safely fall back to v2 for all other cases, exactly as intended.


Job Run: https://github.com/BitGo/BitGoJS/actions

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.

2 participants