Skip to content

feat(sdk-core): add krs mode to safe recovery key params - #10257

Open
yashaanand wants to merge 1 commit into
masterfrom
yashaanand/wcn-4948-safes-coincover-krs-recovery-mode
Open

yashaanand wants to merge 1 commit into
masterfrom
yashaanand/wcn-4948-safes-coincover-krs-recovery-mode

Conversation

@yashaanand

@yashaanand yashaanand commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a krs mode to buildSafeRecoverKeyParams for Wallet Safes whose backup root is held by CoinCover. The params make coin.recover() build a half-signed transaction for CoinCover to countersign.

  • secp256k1Multisig, UTXO coins only: returns { slot, mode: 'krs', userKey, backupKey, bitgoKey, walletPassphrase, krsProvider: 'coincover', walletAddress? }.

    • userKey is the user child xprv, re-encrypted under a fresh ephemeral passphrase.
    • backupKey is the backup child xpub. Any backup private key passed in is ignored.
  • ed25519Multisig, XLM/TXLM only: the same shape, with Stellar S…/G… encodings and never an externalBackupSigner.

  • Rejected in krs mode, before any key handling:

    • The MPC slots.
    • Non-UTXO secp coins such as ETH, XTZ and STX.
    • ALGO and HBAR.

    Their recover() has no KRS path, or no transaction format has been agreed with CoinCover yet.

No abstract-utxo or sdk-coin-xlm source change: both recover() implementations already sign with the user key only when krsProvider is set and the backup key is public.

Public types

  • SafeRecoverMode ('signed' | 'unsigned' | 'krs') is exported.
  • SecpSafeRecoverKeyParams is now a union discriminated on mode. The existing signed/unsigned member is unchanged at runtime and is typed mode?: undefined. The new mode: 'krs' member has walletPassphrase: string. result.mode === 'krs' narrows without an in guard. All existing callers type-check unchanged.
  • Ed25519SafeRecoverKeyParams gains a mode: 'krs' member.

Caller responsibility

The derived child keys don't carry the backup root's provider. The caller must confirm from the safe keycard that the backup root was issued by CoinCover before using krs mode. This is stated in the JSDoc.

Tests

  • sdk-core safe/recovery.ts:
    • The exact krs params for secp and for xlm/txlm, checked against golden vectors.
    • The pub-only external backup child path.
    • Rejection of every unsupported slot and coin, and of an externalBackupSigner, each without any encrypt call.
  • abstract-utxo safeRecovery.ts, for btc, bch and zec: a half-signed PSBT where only the user child signature verifies.
  • sdk-coin-xlm xlmSafeRecovery.ts: the full krs params spread into recover() give an XDR with exactly one signature, the user child's.

Ticket: WCN-4948

@linear-code

linear-code Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

WCN-4948

@yashaanand

Copy link
Copy Markdown
Contributor Author

@claude review

@github-actions

This comment was marked as resolved.

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Compatibility checks are failing on Node.js 27-nightly (experimental, non-blocking). This does not block merge, but it signals an incompatibility to fix before this release becomes supported.

View run

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

@yashaanand
yashaanand force-pushed the yashaanand/wcn-4948-safes-coincover-krs-recovery-mode branch from 580af92 to c98470a Compare November 30, 2026 18:00
@yashaanand

Copy link
Copy Markdown
Contributor Author

@claude

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review: krs mode for buildSafeRecoverKeyParams

The change is well scoped and fails closed. I found no critical issues.

Critical

None.

Internal information leakage

  • The code, comments and test names describe behavior only. No change is needed there.
  • The PR body has a Ticket: WCN-4948 line and a long "Verification" section with test counts and a mutation-check narrative. Commits need a footer reference, so the ticket is fine in the commit footer. Keep the verification narrative out of the squashed commit message.
  • The comment "coincover's fee is $0, but backupKeyRecovery still prices it" in abstract-utxo/test/unit/recovery/safeRecovery.ts is borderline. I suggest "Stub the USD price lookup to keep the test offline."

Suggestions

  1. ed25519 externalBackupSigner check runs after encryption. In buildEd25519MultisigRecoverKeyParams, the externalBackupSigner rejection comes after bitgo.encrypt has run, so a rejected call has already encrypted the seed. The other KRS rejections happen before any encrypt call. Move the check up next to the coin-support check. Then the "rejects an externalBackupSigner" test can assert encrypt.callCount === 0, which it doesn't do now.
  2. The 'coincover' provider is hardcoded. SAFE_KRS_PROVIDER is fine for now. If the root metadata already carries provider: 'coincover' (the abstract-utxo test sets it), consider checking that it matches. Otherwise a krs request against a non-CoinCover external root would silently stamp CoinCover on it.
  3. SAFE_KRS_ED25519_COINS is a Record<string, true> checked with hasOwnProperty. A ReadonlySet<string> is simpler and avoids the prototype-key concern.
  4. The else { throw new Error('unexpected krs result') } branches in the existing tests only exist to narrow the type. Consider asserting result.mode explicitly instead.
  5. Public type change. SecpSafeRecoverKeyParams is now a union. Callers that read walletPassphrase get string | undefined in one arm and string in the other. That's compatible, but mention it in the release notes.

Security

  • The user xprv is re-encrypted under a fresh 32-byte randomBytes passphrase with SJCL v1.
  • A public user.prv and a private backup.pub are both rejected.
  • ECDSA and EdDSA MPC slots, plus ALGO, HBAR and non-UTXO secp coins, are rejected before any key material is touched.
  • Because the passphrase is returned alongside the encrypted key, the encryption only protects the key in transit. Callers must treat userKey plus walletPassphrase as equivalent to the plaintext key.

Tests

Coverage is good. It includes golden vectors, end-to-end half-signed PSBT and XDR checks with signature verification per key, and the pub-only BYOK path. Also consider a negative test that the mode: 'krs' extra field is harmless when spread into recover() for coins whose recover() validates its params strictly. The new UTXO test covers btc, bch and zec.

@yashaanand
yashaanand force-pushed the yashaanand/wcn-4948-safes-coincover-krs-recovery-mode branch from c98470a to 3eabd48 Compare December 1, 2026 15:46
@yashaanand

Copy link
Copy Markdown
Contributor Author

@claude

@github-actions

This comment was marked as resolved.

Add a `krs` mode to buildSafeRecoverKeyParams for Wallet Safes whose
backup root is held by CoinCover. It re-encrypts only the user child,
returns the backup child public key and krsProvider 'coincover', so
coin.recover() builds a half-signed PSBT (UTXO) or XDR (XLM) for the
provider to countersign. MPC slots, non-UTXO secp256k1 coins, ALGO and
HBAR reject krs mode because their recover() has no KRS path.

SecpSafeRecoverKeyParams is now a union discriminated on `mode`: the
existing signed/unsigned member is unchanged at runtime and types
`mode?: undefined`, and a `mode: 'krs'` member has walletPassphrase as
a string. Ed25519SafeRecoverKeyParams gains a `mode: 'krs'` member, and
SafeRecoverMode is exported.

Ticket: WCN-4948
@yashaanand
yashaanand force-pushed the yashaanand/wcn-4948-safes-coincover-krs-recovery-mode branch from 3eabd48 to d7c5f2c Compare December 1, 2026 16:26
@yashaanand
yashaanand marked this pull request as ready for review December 2, 2026 18:06
@yashaanand
yashaanand requested review from a team as code owners December 2, 2026 18:06

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@yashaanand

Copy link
Copy Markdown
Contributor Author

@claude ready to merge?

@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @yashaanand's task in 20s —— View job


Merge readiness

I found nothing that blocks merging. I can't approve PRs, so a human reviewer still needs to do that.

  • Earlier review points are in the branch.
    • The secp krs branch now rejects any coin that isn't a statics UtxoCoin (recovery.ts:694), before any key handling.
    • The ed25519 externalBackupSigner check now runs before encrypt (recovery.ts:794).
    • SAFE_KRS_ED25519_COINS is now a ReadonlySet.
  • CI: the three runs on the PR (BitGo SDK, Audit API Spec, Lint GitHub Actions Files) all passed. The only warning is the non-blocking Node 27-nightly compatibility check.
  • Hash mismatch: the comment mentions c98470a, but that hash isn't in my checkout. The checkout is a single commit, d7c5f2c, and it contains the fix, so the hash probably changed when the commit was amended or squashed. I didn't re-run the tests myself.

Before merging, you may want to do the following:

  1. Look at the secp krs branch's own JSDoc. The 'coincover' value is hardcoded, and nothing checks that the backup root's provider is CoinCover. The PR description and JSDoc say the caller must confirm this, and that's acceptable if you want to keep it that way.
  2. Check that the squashed commit message has a ticket footer (WCN-4948) and leaves out the long verification narrative.
  3. Mention in the release notes that SecpSafeRecoverKeyParams is now a union discriminated on mode.
    · branch yashaanand/wcn-4948-safes-coincover-krs-recovery-mode

This branch has not been deployed

No deployments
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.

3 participants