Skip to content

Commit 918423e

Browse files
fix(sdk-api): throw from getECDHKeychain when the user has none (Refs: WCN-3735)
getECDHKeychain returned an Error object instead of throwing it when the user's settings had no ecdhKeychain. Callers read encryptedXprv off the result, so they reported "encryptedXprv was not found on sharing keychain" instead of the real cause. The error now tells the client the account is missing its sharing key and to contact support@bitgo.com so it can be set up. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 93aea7d commit 918423e

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

‎modules/sdk-api/src/bitgoAPI.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,9 @@ export class BitGoAPI implements BitGoBase {
18821882
if (!ecdhKeychainPub) {
18831883
const result = await this.get(this.url('/user/settings')).result();
18841884
if (!result.settings.ecdhKeychain) {
1885-
return new Error('ecdh keychain not found for user');
1885+
throw new Error(
1886+
'Your account is missing the sharing key needed for this action. Please contact support@bitgo.com so it can be set up.'
1887+
);
18861888
}
18871889
ecdhKeychainPub = result.settings.ecdhKeychain;
18881890
}

‎modules/sdk-api/test/unit/bitgoAPI.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,3 +1562,24 @@ describe('wallets() v1 facade', function () {
15621562
wallets.resendShareInvite.should.be.a.Function();
15631563
});
15641564
});
1565+
1566+
describe('getECDHKeychain', function () {
1567+
const ROOT = 'https://app.example.local';
1568+
1569+
afterEach(function () {
1570+
nock.cleanAll();
1571+
});
1572+
1573+
it('rejects when the user has no ecdhKeychain in settings', async function () {
1574+
const bitgo = new BitGoAPI({ env: 'custom', customRootURI: ROOT });
1575+
nock(ROOT)
1576+
.get('/api/v1/user/settings')
1577+
.reply(200, { settings: { ecdhKeychain: null } });
1578+
1579+
await bitgo
1580+
.getECDHKeychain()
1581+
.should.be.rejectedWith(
1582+
'Your account is missing the sharing key needed for this action. Please contact support@bitgo.com so it can be set up.'
1583+
);
1584+
});
1585+
});

0 commit comments

Comments
 (0)