-
Notifications
You must be signed in to change notification settings - Fork 299
fix(wallet-key-share): Optimize createBulkWalletShare to Fetch Keychain Once and Prevent Rate Limiting #7849
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
base: master
Are you sure you want to change the base?
Conversation
| bulkCreateShareOptions.push({ | ||
| user: shareOption.userId, | ||
| permissions: shareOption.permissions, | ||
| keychain: sharedKeychain as BulkWalletShareKeychain, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| path: user.path, | ||
| }, | ||
| })), | ||
| }); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
Ticket: CSI-1548
Type of change
Summary
Optimizes
createBulkWalletShareto 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:
Extract common logic into two new helper methods:
getDecryptedKeychainForSharing()- Fetches and decrypts the keychain onceencryptPrvForUser()- Encrypts the private key for a specific user (no API calls)Optimize
createBulkWalletShare()to fetch the keychain once before the loop, then reuse it for all users