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(ironfish,rust-nodejs): Add EncryptedAccount class #5226

Merged

Conversation

rohanjadvani
Copy link
Member

@rohanjadvani rohanjadvani commented Aug 8, 2024

Summary

  • Update Napi encrypt / decrypt to accept and return JS buffers
  • Remove hex conversion from Napi functions and pass raw bytes
  • Refactor AccountValue to DecryptedAccountValue
  • Adds encrypted property to be used as a type guard in subsequent PRs
  • Introduce EncryptedAccountValue to represent encrypted accounts in the database

Testing Plan

Unit test

Documentation

Does this change require any updates to the Iron Fish Docs (ex. the RPC API
Reference
)? If yes, link a
related documentation pull request for the website.

[ ] Yes

Breaking Change

Is this a breaking change? If yes, add notes below on why this is breaking and label it with breaking-change-rpc or breaking-change-sdk.

[ ] Yes

@rohanjadvani rohanjadvani self-assigned this Aug 8, 2024
serialize(value: AccountValue): Buffer {
export type AccountValue = EncryptedAccountValue | DecryptedAccountValue

export class AccountValueEncoding implements IDatabaseEncoding<DecryptedAccountValue> {
Copy link
Member Author

@rohanjadvani rohanjadvani Aug 8, 2024

Choose a reason for hiding this comment

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

This is a temporary change to update the generic and will be changed back to AccountValue (the new union type) in a subsequent PR. We are using DecryptedAccountValue to keep code changes small per PR, and the change will come once the wallet and walletdb are updated to read / store encrypted accounts.

async *loadAccounts(tx?: IDatabaseTransaction): AsyncGenerator<AccountValue, void, unknown> {
async *loadAccounts(
tx?: IDatabaseTransaction,
): AsyncGenerator<DecryptedAccountValue, void, unknown> {
Copy link
Member Author

Choose a reason for hiding this comment

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

Same comment above regarding the generic. Will update once encrypted account encoding is added.

const encoder = new AccountValueEncoding()
const data = encoder.serialize(account.serialize())

const encryptedData = encrypt(data, passphrase)
Copy link
Member Author

Choose a reason for hiding this comment

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

Will be refactored when the decrypted account has an encrypt method for better encapsulation.

@rohanjadvani rohanjadvani marked this pull request as ready for review August 8, 2024 19:43
@rohanjadvani rohanjadvani requested a review from a team as a code owner August 8, 2024 19:43
@rohanjadvani rohanjadvani merged commit de0bdda into staging Aug 8, 2024
15 checks passed
@rohanjadvani rohanjadvani deleted the rohan/ifl-2786-add-encrypted-account-interface branch August 8, 2024 20:54
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.

2 participants