You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Slowly trying to remove front end dependency on near-ca by keeping the near-ca imports contained to this project and reexporting the necessary tools from here.
PR Type
enhancement, other
Description
Simplified the initialization process of TransactionManager by internalizing the nearAdapter setup.
Updated example script to reflect changes in TransactionManager initialization.
Added accountId, mpcContractId, and privateKey parameters to TransactionManager.create.
Changes walkthrough 📝
Relevant files
Enhancement
send-tx.ts
Simplify TransactionManager initialization in example script
examples/send-tx.ts
Removed nearAdapter setup from TransactionManager.create call.
Added accountId, mpcContractId, and privateKey directly to TransactionManager.create call.
Missing Error Handling The new implementation in TransactionManager.create uses Promise.all to concurrently initialize nearAdapter and safePack. However, there is no error handling for these promises. If any of these initializations fail, the error will not be handled gracefully.
Dependency Concern The PR introduces a direct import from 'near-ca' which includes multiple components (NearEthAdapter, NearEthTxData, BaseTx, Network, setupAdapter). This contradicts the stated goal of the PR to contain near-ca dependencies within this project. Consider refactoring to align with the project's architectural goals.
Add validation for nearAccountId and nearAccountPrivateKey to ensure they are not null or incorrectly formatted
It's recommended to validate the nearAccountId and nearAccountPrivateKey before using them to create a TransactionManager. This ensures that the provided values are not null or incorrectly formatted, which could lead to runtime errors or security vulnerabilities.
+if (!nearAccountId || !nearAccountPrivateKey) {+ throw new Error("Invalid account ID or private key.");+}
const txManager = await TransactionManager.create({
accountId: nearAccountId,
mpcContractId,
pimlicoKey,
privateKey: nearAccountPrivateKey,
});
Suggestion importance[1-10]: 9
Why: This suggestion addresses a potential runtime error and security vulnerability by ensuring that critical parameters are validated before use. This is a significant improvement in terms of robustness and security.
9
Ensure handling of the optional privateKey parameter to avoid unintended behavior
The privateKey parameter in the TransactionManager.create method is optional, which could lead to unintended behavior if not handled properly. Ensure that the logic within TransactionManager.create accounts for cases where privateKey might be undefined.
static async create(config: {
accountId: string;
mpcContractId: string;
pimlicoKey: string;
privateKey?: string;
safeSaltNonce?: string;
}): Promise<TransactionManager> {
+ if (config.privateKey === undefined) {+ console.warn("Warning: privateKey is undefined. Some operations may not be available.");+ }
Suggestion importance[1-10]: 8
Why: This suggestion improves the robustness of the code by handling cases where privateKey might be undefined, preventing potential unintended behavior and providing a warning to the user.
8
Possible bug
Add a check to ensure pimlicoKey exists in config before destructuring
The destructuring of pimlicoKey directly from config in the create method might lead to errors if config is not properly formed. Consider adding a check to ensure config contains pimlicoKey.
+if (!config.pimlicoKey) {+ throw new Error("pimlicoKey is required in the configuration.");+}
const { pimlicoKey } = config;
Suggestion importance[1-10]: 7
Why: This suggestion adds a necessary validation step to ensure that pimlicoKey is present in the configuration, which helps prevent runtime errors due to missing properties.
7
Security
Enhance security by encrypting the private key before use
Consider using a more secure method to handle private keys instead of passing them directly in the method call. This can help prevent security risks such as leakage of sensitive information.
Why: While this suggestion improves security by encrypting the private key, it requires additional context about the encryptKey function and its implementation. It is a good practice but needs careful consideration and implementation.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
Slowly trying to remove front end dependency on near-ca by keeping the near-ca imports contained to this project and reexporting the necessary tools from here.
PR Type
enhancement, other
Description
TransactionManager
by internalizing thenearAdapter
setup.TransactionManager
initialization.accountId
,mpcContractId
, andprivateKey
parameters toTransactionManager.create
.Changes walkthrough 📝
send-tx.ts
Simplify TransactionManager initialization in example script
examples/send-tx.ts
nearAdapter
setup fromTransactionManager.create
call.accountId
,mpcContractId
, andprivateKey
directly toTransactionManager.create
call.tx-manager.ts
Internalize nearAdapter setup in TransactionManager
src/tx-manager.ts
setupAdapter
fromnear-ca
.TransactionManager.create
to initializenearAdapter
internally.
accountId
,mpcContractId
, andprivateKey
toTransactionManager.create
parameters.