fix(sdk-core): handle 404 key not found in getEncryptedUserKeychain#9339
Draft
bitgo-ai-agent-dev[bot] wants to merge 1 commit into
Draft
fix(sdk-core): handle 404 key not found in getEncryptedUserKeychain#9339bitgo-ai-agent-dev[bot] wants to merge 1 commit into
bitgo-ai-agent-dev[bot] wants to merge 1 commit into
Conversation
When sharing a wallet (e.g. cold storage wallets), getEncryptedUserKeychain
iterates through wallet.keys and fetches each key from the backend. For cold
storage wallets like Trade Republic's, some key records may not exist on the
server (they return 404 "key not found" instead of a 200 with no encryptedPrv).
Previously this 404 ApiResponseError was uncaught and propagated to the caller,
breaking the wallet share flow even though the correct behaviour is to treat a
missing key record the same as a key with no encryptedPrv: skip it and try the
next key. If all keys are absent or have no encryptedPrv, the function throws
MissingEncryptedKeychainError, which prepareSharedKeychain already handles by
returning {} (skipKeychain: true) — the cold-wallet code path.
The fix catches ApiResponseError with status 404 inside tryKeyChain and falls
through to the next key, mirroring the existing no-encryptedPrv skip. No
behaviour change for hot wallets or any 4xx/5xx other than 404.
Ticket: WCN-1586
Session-Id: 5f46d7d1-4497-4665-8b70-7c1a40459cb2
Task-Id: 6119806c-2d1f-4106-896f-7bf304043f2c
bitgo-ai-agent-dev
Bot
force-pushed
the
WCN-1586-trade-republic-key-not-found
branch
from
July 23, 2026 09:29
1888fe5 to
0f0b751
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
getEncryptedUserKeychain()(modules/sdk-core/src/bitgo/wallet/wallet.ts), catchApiResponseErrorwith HTTP status 404 insidetryKeyChainand fall through to the next key, rather than propagating the error to callers.Why
getEncryptedUserKeychain()throwsApiResponseError("key not found", 404)when the backend has no keychain record for a key ID.wallet.keysthat have no corresponding keychain record on the server — those keys are stored offline or in KMS, not in the regular key store. A 404 fromGET /api/v2/{coin}/key/{id}is therefore expected and should be handled the same as a key that exists but has noencryptedPrv: skip it and try the next one.encryptedPrv), the function throwsMissingEncryptedKeychainError, whichprepareSharedKeychainalready handles correctly by returning{}(i.e.skipKeychain: true) — the correct cold-wallet code path.MissingEncryptedKeychainErrorwas only thrown when all keys had noencryptedPrv(index past end of array), but a 404ApiResponseErrorwas never caught, breaking the wallet share flow for cold storage wallets.Test plan
should share wallet when key fetch returns 404 (cold wallet with missing key records)— all three key fetches mock 404 and the share completes withskipKeychain: true.should share to cold wallet without passing skipKeychain) continue to pass.Wallet Sharingunit tests pass.sdk-coreunit tests (525) pass.Ticket: WCN-1586