Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions modules/bitgo/test/v2/unit/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
ManageUnspentsOptions,
MessageStandardType,
MessageTypes,
NeedUserSignupError,
PopulatedIntent,
PrebuildTransactionOptions,
PrebuildTransactionWithIntentOptions,
Expand Down Expand Up @@ -1994,6 +1995,48 @@ describe('V2 Wallet:', function () {
createShareNock.isDone().should.be.True();
});

it('should throw NeedUserSignupError when recipient pubkey is missing and spend permission is requested', async function () {
const userId = '456';
const email = 'newuser@sdktest.com';
const permissions = 'view,spend';
const walletPassphrase = 'bitgo1234';

// Simulate a user who has not yet logged in / set up their ECDH key
const getSharingKeyNock = nock(bgUrl)
.post('/api/v1/user/sharingkey', { email })
.reply(200, { userId });

await wallet
.shareWallet({ email, permissions, walletPassphrase })
.should.be.rejectedWith(NeedUserSignupError);

getSharingKeyNock.isDone().should.be.True();
});

it('should not throw NeedUserSignupError when recipient pubkey is missing but spend permission is not requested', async function () {
const userId = '456';
const email = 'newuser@sdktest.com';
const permissions = 'view';

// Sharing key without pubkey is fine for view-only shares
const getSharingKeyNock = nock(bgUrl)
.post('/api/v1/user/sharingkey', { email })
.reply(200, { userId });

const createShareNock = nock(bgUrl)
.post(`/api/v2/tbtc/wallet/${wallet.id()}/share`, {
user: userId,
permissions,
skipKeychain: true,
})
.reply(200, {});

await wallet.shareWallet({ email, permissions });

getSharingKeyNock.isDone().should.be.True();
createShareNock.isDone().should.be.True();
});

describe('Hot Wallet Sharing', function () {
const userId = '123';
const email = 'shareto@sdktest.com';
Expand Down
3 changes: 3 additions & 0 deletions modules/sdk-core/src/bitgo/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2064,6 +2064,9 @@ export class Wallet implements IWallet {
})) as any;
let sharedKeychain;
if (needsKeychain) {
if (!sharing.pubkey) {
throw new NeedUserSignupError(sharing.userId);
}
sharedKeychain = await this.prepareSharedKeychain(
params.walletPassphrase,
sharing.pubkey,
Expand Down
Loading