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

Kels7 wip make it work in the browser #2

Merged

Conversation

KELs7
Copy link
Contributor

@KELs7 KELs7 commented Feb 25, 2024

Pull Request Submission: Update ed25519-hd-key to ed25519-keygen

Issue Description

The npm package ed25519-hd-key currently cannot be run in the browser due to its dependency on create-hmac. This issue has been acknowledged and can be found in the ed25519-hd-key GitHub repository [1]. To address this limitation, the decision was made to replace ed25519-hd-key with the package ed25519-keygen [2].

Changes Made

To resolve the issue, the logic for ed25519-hd-key in the src/lib/wallet.ts file has been replaced with the logic for ed25519-keygen. This replacement ensures that the code can be executed in the browser without any dependency conflicts [2]. The changes can be found in the branch kels7-wip-make-it-work-in-the-browser)

Benefits of Using ed25519-keygen

By switching to ed25519-keygen, the following benefits are achieved:

  • Compatibility with browser environments, allowing the code to be executed seamlessly [2].

Pull Request Details

The pull request includes the following changes:

  • Replaced ed25519-hd-key with ed25519-keygen in the src/lib/wallet.ts file.
  • Ensured compatibility with browser environments by resolving the dependency conflict caused by create-hmac.

Copy link

@benjig123 benjig123 left a comment

Choose a reason for hiding this comment

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

Looks mostly good, your formatter interfered with having a clean diff though. Can you undo those changes and re-request ?

dist/index.d.mts Outdated
sk: string;
vk: string;
sk: any;
vk: any;

Choose a reason for hiding this comment

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

why any ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Weird. I only formatted src/lib/wallet.ts with prettier v3.2.5 and built it. I did not even touch any of your tsup configs

};
};

return wallet();

Choose a reason for hiding this comment

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

Looks like your autoformatter created diffs where there shouldn't be.

return {
sk: new Uint8Array(kp["secretKey"].slice(0, 32)),
vk: new Uint8Array(kp["secretKey"].slice(32, 64)),
};

Choose a reason for hiding this comment

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

auto formatter again

Copy link
Contributor

@duelingbenjos duelingbenjos left a comment

Choose a reason for hiding this comment

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

Hey Kels, thanks for making a PR ! Looks great except for the diffs created from what I assume is your formatter and also the any typings.

const uint8Array: Uint8Array = new Uint8Array(buffer);
const hexArray: string[] = Array.prototype.map.call(uint8Array, (x: number) => ("00" + x.toString(16)).slice(-2));
const hexString: string = hexArray.join("");
return hexString
}
Copy link
Contributor Author

@KELs7 KELs7 Feb 26, 2024

Choose a reason for hiding this comment

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

The issue for the any types was due to buf2hex not written properly in typescript. In the near future all functions in helper.ts should be rewritten in proper typescript

const publicKey = bip32.getPublicKey(key, false).toString("hex");
hdkey = hdkey.derive(derivationPath);
const privateKey = helpers.buf2hex(hdkey.privateKey);
const publicKey = helpers.buf2hex(hdkey.publicKey).slice(2);

Copy link
Contributor Author

@KELs7 KELs7 Feb 26, 2024

Choose a reason for hiding this comment

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

buf2hex was used for getting the privateKey and publicKey in hex strings . But because buf2hex was not properly typed, it returned any.

@KELs7 KELs7 requested a review from duelingbenjos February 26, 2024 23:32
Copy link
Contributor

@duelingbenjos duelingbenjos left a comment

Choose a reason for hiding this comment

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

noice

@duelingbenjos duelingbenjos merged commit 433956c into xian-network:main Feb 27, 2024
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.

4 participants