Skip to content

Commit d0190a5

Browse files
authored
Merge pull request #6453 from BitGo/feature/CSI-702
feat: added new error NeedsUserSignupError
2 parents b474699 + 8c9c64a commit d0190a5

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

modules/bitgo/test/v2/unit/wallets.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
WalletWithKeychains,
2727
multisigTypes,
2828
IncorrectPasswordError,
29+
NeedUserSignupError,
2930
} from '@bitgo/sdk-core';
3031
import { BitGo } from '../../../src';
3132
import { afterEach } from 'mocha';
@@ -2525,6 +2526,72 @@ describe('V2 Wallets:', function () {
25252526
}
25262527
});
25272528

2529+
it('should throw NeedsUserSignup error if pubkey is missing', async () => {
2530+
const userId = '[email protected]';
2531+
const permissions = ['view', 'spend'];
2532+
try {
2533+
await wallet.createBulkWalletShare({
2534+
walletPassphrase: 'Test',
2535+
keyShareOptions: [
2536+
{
2537+
userId: userId,
2538+
permissions: permissions,
2539+
path: 'm/999999/1/1',
2540+
},
2541+
],
2542+
} as BulkWalletShareOptions);
2543+
assert.fail('Expected error not thrown');
2544+
} catch (error) {
2545+
assert(error instanceof NeedUserSignupError);
2546+
assert.strictEqual(error.name, 'NeedUserSignupError');
2547+
assert.strictEqual(error.message, userId);
2548+
}
2549+
});
2550+
2551+
it('should throw error if path is missing', async () => {
2552+
const userId = '[email protected]';
2553+
const permissions = ['view', 'spend'];
2554+
try {
2555+
await wallet.createBulkWalletShare({
2556+
walletPassphrase: 'Test',
2557+
keyShareOptions: [
2558+
{
2559+
userId: userId,
2560+
permissions: permissions,
2561+
pubKey: 'm/999999/1/1',
2562+
},
2563+
],
2564+
} as BulkWalletShareOptions);
2565+
assert.fail('Expected error not thrown');
2566+
} catch (error) {
2567+
assert.strictEqual(error.name, 'Error');
2568+
assert.strictEqual(error.message, 'Missing parameter: path');
2569+
}
2570+
});
2571+
2572+
it('should throw NeedsUserSignup error if pubkey is empty string', async () => {
2573+
const userId = '[email protected]';
2574+
const permissions = ['view', 'spend'];
2575+
try {
2576+
await wallet.createBulkWalletShare({
2577+
walletPassphrase: 'Test',
2578+
keyShareOptions: [
2579+
{
2580+
userId: userId,
2581+
pubKey: '',
2582+
permissions: permissions,
2583+
path: 'm/999999/1/1',
2584+
},
2585+
],
2586+
});
2587+
assert.fail('Expected error not thrown');
2588+
} catch (error) {
2589+
assert(error instanceof NeedUserSignupError);
2590+
assert.strictEqual(error.name, 'NeedUserSignupError');
2591+
assert.strictEqual(error.message, userId);
2592+
}
2593+
});
2594+
25282595
it('should correctly process share options and call createBulkKeyShares', async () => {
25292596
const userId = '[email protected]';
25302597
const permissions = ['view', 'spend'];

modules/sdk-core/src/bitgo/errors.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ export class IncorrectPasswordError extends Error {
169169
}
170170
}
171171

172+
export class NeedUserSignupError extends BitGoJsError {
173+
public constructor(message?: string) {
174+
super(message || 'User signup is required');
175+
}
176+
}
177+
172178
export class ApiResponseError<ResponseBodyType = any> extends BitGoJsError {
173179
message: string;
174180
status: number;

modules/sdk-core/src/bitgo/wallet/wallet.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
IncorrectPasswordError,
2424
MethodNotImplementedError,
2525
MissingEncryptedKeychainError,
26+
NeedUserSignupError,
2627
} from '../errors';
2728
import * as internal from '../internal/internal';
2829
import { drawKeycard } from '../internal';
@@ -1602,7 +1603,14 @@ export class Wallet implements IWallet {
16021603
const bulkCreateShareOptions: BulkCreateShareOption[] = [];
16031604

16041605
for (const shareOption of params.keyShareOptions) {
1605-
common.validateParams(shareOption, ['userId', 'pubKey', 'path'], []);
1606+
try {
1607+
common.validateParams(shareOption, ['userId', 'pubKey', 'path'], []);
1608+
} catch (e) {
1609+
if (!shareOption.pubKey) {
1610+
throw new NeedUserSignupError(shareOption.userId);
1611+
}
1612+
throw e;
1613+
}
16061614

16071615
const needsKeychain = shareOption.permissions && shareOption.permissions.includes('spend');
16081616

0 commit comments

Comments
 (0)