Skip to content

Conversation

@abk404
Copy link

@abk404 abk404 commented Jan 6, 2026

Ticket: CSI-1548

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Summary

Optimizes createBulkWalletShare to fetch the wallet keychain only once instead of once per user, drastically reducing API calls and preventing rate limiting (HTTP 429) errors during bulk wallet sharing.

Problem

When sharing a wallet with multiple users via createBulkWalletShare, the SDK was fetching the wallet keychain (v2.key.get) for each user in the share list.

For example, sharing 26 wallets with 15 users each resulted in 390 API calls (26 × 15), causing rate limiting errors and failures with the message: "Failed to process wallet shares after retrying with single requests."
Check the support ticket : CS-6701

Solution

Refactored the code to:

  1. Extract common logic into two new helper methods:

    • getDecryptedKeychainForSharing() - Fetches and decrypts the keychain once
    • encryptPrvForUser() - Encrypts the private key for a specific user (no API calls)
  2. Optimize createBulkWalletShare() to fetch the keychain once before the loop, then reuse it for all users

@abk404 abk404 requested review from a team as code owners January 6, 2026 12:07
@abk404 abk404 changed the title feat: fetch keychain per wallet once fix(wallet-key-share): Optimize createBulkWalletShare to Fetch Keychain Once and Prevent Rate Limiting Jan 6, 2026
bulkCreateShareOptions.push({
user: shareOption.userId,
permissions: shareOption.permissions,
keychain: sharedKeychain as BulkWalletShareKeychain,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing validation: The original code had explicit assertions for keychain fields. Consider keeping runtime validation instead of relying solely on type cast.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, added the explicit assertions and removed the typecast completely.

*/
async getDecryptedKeychainForSharing(
walletPassphrase: string | undefined
): Promise<{ prv: string; pub: string } | undefined> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type improvement: Consider extracting { prv: string; pub: string } into a named interface for reusability.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

path: user.path,
},
})),
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand test coverage: Also verify encryptPrvForUser is called once per user to ensure encryption happens for each recipient.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants