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

Sign block locally #12

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Sign block locally #12

wants to merge 10 commits into from

Conversation

tgerboui
Copy link
Owner

@tgerboui tgerboui commented May 5, 2024

In this PR blocks are now hashed and signed locally.
Work generation (call at the rpc) is now separated in a work module.

The hash and sign methods have been added in the blocks module.
blocks.create uses theses functions with work.generate to format a new block.

Solve #10

@tgerboui tgerboui self-assigned this May 5, 2024
@tgerboui tgerboui linked an issue May 5, 2024 that may be closed by this pull request
@codecov-commenter
Copy link

codecov-commenter commented May 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (c9473e3) to head (a86fd6f).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #12   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           29        31    +2     
  Lines          435       455   +20     
  Branches        76        70    -6     
=========================================
+ Hits           435       455   +20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tgerboui tgerboui changed the title #10 sign block locally Sign block locally May 5, 2024
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it make sense to keep the option to create the block with the RPC server? With your current changes, there is no options to do so, right?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I've thought about it, but I don't think so.
I really don't see the point of using the node to sign the block, it can lead to errors and private key leakage.

The late goal of this feature is to implement the ability to generate local work, where for the work it makes perfect sense to provide the choice to the user, because the local machine or server may not have the hardware to handle this kind of job. And there is no possibility of the private key being leaked.

But if you have an argument against it, I'm open to it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The only reason I see is feature compatibility. If a user has a need to create the block with the RPC server we want to give them the option to do so. Maybe we can provide some warning regard the issue with a private key, but in the end it's a feature the Nano protocol supports, so why should we not include it?

But I will leave this decision up to you. For now we can also just keep it out and see if an issue is raised in the future

@tgerboui tgerboui force-pushed the feat/10-sign-block-locally branch from 3d9f3c3 to 6dda4c6 Compare May 16, 2024 13:30
@@ -212,13 +222,19 @@ describe('Wallet class', () => {
};
const hashInfo = { amount: '2000000000000000000000000000000' };
wallet.info = jest.fn().mockResolvedValue(info);
workMock.generate
.mockResolvedValueOnce({ work: 'work' } as any)
.mockResolvedValueOnce({ work: 'work2' } as any);
blocksMock.info.mockResolvedValue(hashInfo as any);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would consider any bad practice, because the type checking TypeScript provides gets disabled. Maybe you could remove it?

@@ -382,7 +403,8 @@ describe('Wallet class', () => {
const newRepresentative = randomNanoAddress();
const info = { balance: '1000', frontier: 'frontierHash' };
wallet.info = jest.fn().mockResolvedValue(info);
blocksMock.create.mockResolvedValue({ hash: 'createdChangeHash' } as any);
workMock.generate.mockResolvedValue({ work: 'work' } as any);
blocksMock.create.mockReturnValueOnce({ hash: 'createdChangeHash' } as any);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here with any (see above)

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.

Sign block locally
3 participants