Skip to content

wallets: fix server signer recovery check in useSigner#1784

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1775835949-fix-server-signer-recovery-check
Open

wallets: fix server signer recovery check in useSigner#1784
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1775835949-fix-server-signer-recovery-check

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot commented Apr 10, 2026

Description

Fixes a TypeError: Cannot read properties of undefined (reading 'startsWith') thrown when calling wallet.useSigner({ type: "server", secret: "xmsk1_..." }) on a wallet fetched via getWallet.

Root cause: isRecoverySigner() unconditionally called deriveServerSignerDetails(recovery, ...) on the API-sourced recovery config, which has shape {type: "server", address: "..."} — no secret field. This passed undefined into stripAndValidateSecret(), which called .startsWith() on it.

Fix: The method now checks which fields the recovery config actually has at runtime:

  • API path (getWallet): recovery has address → compare directly
  • User path (createWallet): recovery has secret → derive address then compare
  • Neither: return false

Note: the existing code comment on L1345 already described this intent ("so we use the address directly instead of re-deriving it") but the implementation didn't match — this PR fixes that.

⚠️ For reviewer attention:

  • The ServerSignerConfig type is { type: "server"; secret: string } and does not include address. The API recovery config has a different runtime shape. This fix handles it with "address" in recovery runtime checks rather than updating the type definitions — worth considering whether the types should also be corrected.
  • No new unit test was added for this specific path (isRecoverySigner with API-sourced server recovery config).

Test plan

  • Existing test suite passes (287 passed, 68 skipped)
  • Lint passes cleanly

Package updates

  • @crossmint/wallets-sdk: patch — changeset added

Link to Devin session: https://crossmint.devinenterprise.com/sessions/726ed7808b1f4757a10ca2165051f3dd
Requested by: @xmint-guille


Open in Devin Review

…ners

The API-sourced recovery config has shape {type: 'server', address: '...'} without
a secret field. Calling deriveServerSignerDetails on it caused TypeError because
stripAndValidateSecret received undefined.

Now checks for address field first (API path) and falls back to secret derivation
(createWallet path).
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 10, 2026

🦋 Changeset detected

Latest commit: 9edf8fd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@crossmint/wallets-sdk Patch
@crossmint/wallets-quickstart-devkit Patch
expo-demo Patch
@crossmint/client-sdk-react-base Patch
@crossmint/client-sdk-react-native-ui Patch
@crossmint/client-sdk-react-ui Patch
@crossmint/auth-ssr-nextjs-demo Patch
@crossmint/client-sdk-nextjs-starter Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 10, 2026

Prompt To Fix All With AI
This is a comment left during a code review.
Path: packages/wallets/src/wallets/wallet.ts
Line: 1347-1373

Comment:
**Missing unit test for fixed code path**

The PR description explicitly notes that no test was added for `isRecoverySigner` when `#recovery` is API-sourced (`{ type: "server", address: "..." }` with no `secret`). Without a test, a future refactor could silently regress this exact crash scenario. Consider adding a test that mocks `getWallet` returning a server recovery config and asserts that `useSigner({ type: "server", secret: "..." })` no longer throws.

**Rule Used:** Add unit tests when implementing new validation lo... ([source](https://app.greptile.com/review/custom-context?memory=9dc35ad5-5868-49a3-bbcb-a42edc5ee697))

**Learnt From**
[Paella-Labs/crossbit-main#21014](https://github.com/Paella-Labs/crossbit-main/pull/21014)

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: packages/wallets/src/wallets/wallet.ts
Line: 1358-1360

Comment:
**Type definition does not reflect API runtime shape**

`ServerSignerConfig` is typed as `{ type: "server"; secret: string }` with no `address` field, but the API-sourced recovery object has `{ type: "server", address: "..." }`. The `"address" in recovery` runtime guard works, but `recovery.address` is only accessible because TypeScript's `in`-narrowing widens the type; the declared type never acknowledges this field. This creates a gap where tools like IDE autocomplete, exhaustiveness checks, or future type-level guards may behave unexpectedly.

Consider introducing a discriminated union such as:

```ts
export type ServerSignerConfig =
    | { type: "server"; secret: string }          // user-provided (createWallet)
    | { type: "server"; address: string };         // API-sourced  (getWallet)
```

or adding `address?: string` to the existing type, so the runtime shape is reflected statically.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix: use recovery address directly in is..." | Re-trigger Greptile

Comment on lines +1358 to +1360
if ("address" in recovery && typeof recovery.address === "string") {
return inputDerived === recovery.address;
}
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.

P2 Type definition does not reflect API runtime shape

ServerSignerConfig is typed as { type: "server"; secret: string } with no address field, but the API-sourced recovery object has { type: "server", address: "..." }. The "address" in recovery runtime guard works, but recovery.address is only accessible because TypeScript's in-narrowing widens the type; the declared type never acknowledges this field. This creates a gap where tools like IDE autocomplete, exhaustiveness checks, or future type-level guards may behave unexpectedly.

Consider introducing a discriminated union such as:

export type ServerSignerConfig =
    | { type: "server"; secret: string }          // user-provided (createWallet)
    | { type: "server"; address: string };         // API-sourced  (getWallet)

or adding address?: string to the existing type, so the runtime shape is reflected statically.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/wallets/src/wallets/wallet.ts
Line: 1358-1360

Comment:
**Type definition does not reflect API runtime shape**

`ServerSignerConfig` is typed as `{ type: "server"; secret: string }` with no `address` field, but the API-sourced recovery object has `{ type: "server", address: "..." }`. The `"address" in recovery` runtime guard works, but `recovery.address` is only accessible because TypeScript's `in`-narrowing widens the type; the declared type never acknowledges this field. This creates a gap where tools like IDE autocomplete, exhaustiveness checks, or future type-level guards may behave unexpectedly.

Consider introducing a discriminated union such as:

```ts
export type ServerSignerConfig =
    | { type: "server"; secret: string }          // user-provided (createWallet)
    | { type: "server"; address: string };         // API-sourced  (getWallet)
```

or adding `address?: string` to the existing type, so the runtime shape is reflected statically.

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed that the type definition doesn't reflect the runtime shape. However, updating ServerSignerConfig to a discriminated union would be a broader change that touches many consumers across the codebase (wallet-factory, signer locator utils, etc.) and is better suited as a separate follow-up PR.

The "address" in recovery runtime guard is safe and idiomatic TypeScript narrowing for this bugfix. Keeping the scope minimal here to unblock the customer.

@github-actions
Copy link
Copy Markdown
Contributor

🔥 Smoke Test Results

Status: Failed

Statistics

  • Total Tests: 5
  • Passed: 0 ✅
  • Failed: 1 ❌
  • Skipped: 4 ⚠️
  • Duration: 2.54 min

Test Details


This is a non-blocking smoke test. Full regression tests run separately.

Copy link
Copy Markdown
Contributor Author

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

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.

1 participant