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

Make Lumos Work Smother With the Modern Frontend Dev Tools #597

Closed
homura opened this issue Jan 4, 2024 · 3 comments · Fixed by #721
Closed

Make Lumos Work Smother With the Modern Frontend Dev Tools #597

homura opened this issue Jan 4, 2024 · 3 comments · Fixed by #721
Milestone

Comments

@homura
Copy link
Collaborator

homura commented Jan 4, 2024

Currently, Lumos has some methods, particularly crypto-related APIs such as mnemonicToSeedSync(): Buffer in @ckb-lumos/hd. This makes it a bit challenging to integrate Lumos directly with some modern developer tools like Vite. To work with Vite, developers typically require additional configuration to include these methods in the project, which is inconvenient.

I would like to propose a refactor to replace these methods with a modern one such as https://github.com/paulmillr/noble-curves, which is suitable for working with multiple major runtimes. Noble-curves is a trusted option for many projects as it has been audited. However, noble-curves relies on the bigint API, which means a breaking change for Lumos to use it as the NodeJS's node:cyrpto alternative.

Around two years ago, Lumos introduced a big integer library @ckb-lumos/bi and migrated the bigint-related API to the library for compatibility in #212, as some browsers didn't support bigint, especially Safari on iOS < 13.7.

Therefore, if we want to achieve this, some breaking changes will be required:

  • Introduce bigint and drop the compatibility of iOS < 13.7(the market share < 3% at 2023-12)
  • Change the Buffer returned from some methods to Uint8Array

But this makes Lumos

  • Smaller because we don't need the whole browserify-crypto, browserify-buffer, etc.
  • More convenient because we don't need additional polyfill config in the project

Let me know if you think this change is worth it!

Q&A

  • Does the fallback of Buffer to Uint8Array affect massively?

Probably not, the Buffer is extended from Uint8Array, therefore, I suppose it is a slight change, or even without any change if developers do not use the Buffer API.

- const seed = mnemonicToSeedSync()
+ const seed = Buffer.from(mnemonicToSeedSync())
console.log(seed.toString('hex'))
  • For the long-term perspective, how would this change impact BI?

It depends on developers' habits. I'd also like to add that the current BI supports construct via bigint

Notes

@homura homura changed the title Make Lumos Works Smother With the Modern Frontend Dev Tools Make Lumos Work Smother With the Modern Frontend Dev Tools Jan 4, 2024
@jordanmack
Copy link

I support updating. The change sounds reasonable and the updates needed to support it are minimal.

In particular, I personally never liked using BI. I would much prefer to use the native BigInt.

@homura
Copy link
Collaborator Author

homura commented Apr 1, 2024

#645

@homura
Copy link
Collaborator Author

homura commented May 22, 2024

The PR #684 dropped all the fs support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

2 participants