Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sdk-core): add bulkShareWallet method #4915

Closed
wants to merge 3 commits into from
Closed
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
17 changes: 12 additions & 5 deletions modules/sdk-core/src/bitgo/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1483,12 +1483,15 @@ export class Wallet implements IWallet {
* @returns {Promise<CreateBulkWalletShareListResponse>} A promise that resolves with the response of the bulk wallet share creation.
*/
async createBulkWalletShare(params: BulkWalletShareOptions): Promise<CreateBulkWalletShareListResponse> {
if (!params.keyShareOptions || Object.keys(params.keyShareOptions).length === 0) {
throw new Error('shareOptions cannot be empty');
}
// if (!params.keyShareOptions || Object.keys(params.keyShareOptions).length === 0) {
// throw new Error('shareOptions cannot be empty');
// }
console.log('Break1');
console.log(params);
const bulkCreateShareOptions: BulkCreateShareOption[] = [];

console.log('Shareoptions');
for (const shareOption of params.keyShareOptions) {
console.log(shareOption);
common.validateParams(shareOption, ['userId', 'pubKey', 'path'], []);

const needsKeychain = shareOption.permissions && shareOption.permissions.includes('spend');
Expand Down Expand Up @@ -1536,6 +1539,8 @@ export class Wallet implements IWallet {
}
const keychain = Object.keys(sharedKeychain ?? {}).length === 0 ? undefined : sharedKeychain;
if (keychain) {
console.log('Break2');
console.log('UID', shareOption.userId);
bulkCreateShareOptions.push({
user: shareOption.userId,
permissions: shareOption.permissions,
Expand All @@ -1560,6 +1565,7 @@ export class Wallet implements IWallet {
* @throws {Error} Throws an error if no valid share options are provided.
*/
async createBulkKeyShares(params: BulkCreateShareOption[] = []): Promise<CreateBulkWalletShareListResponse> {
console.log('createBulkKeyShares', params);
params = params.filter((shareOption) => {
try {
common.validateParams(shareOption.keychain, ['pub', 'encryptedPrv', 'fromPubKey', 'toPubKey', 'path'], []);
Expand All @@ -1569,11 +1575,12 @@ export class Wallet implements IWallet {
return false;
}
});
console.log('Break3', params);

if (!params || Object.keys(params).length === 0) {
throw new Error('shareOptions cannot be empty');
}

console.log('Break4');
const url = this.bitgo.url(`/wallet/${this._wallet.id}/walletshares`, 2);
return this.bitgo.post(url).send({ shareOptions: params }).result();
}
Expand Down
Loading