Open homura opened 1 year ago
I encountered some difficulties when refactoring the createCipheriv
in @ckb-lumos/hd
, because I found that the brwoserify-cipher
has a dependency on the browserify-aes
, and browserify-aes
still has a dependency on the safe-buffer
, which may not help reduce the bundle size.
During the exploration, I found that we could refactor with the crypto.subtle
, however, most of the subtle API are asynchronous and incompatible with the current lumos synchronous APIs, and we need to evaluate how we should move forward with this part of the work.
stats.json.zip
lumos@82b2a9637e95175101dca3361696e26c3e39989e
uncompressed version: 1.5 MB
Refactored the require("crypto")
to import by demand, reduced about 11.7% bundle size.
This modification also brings more cross-platform benefits to Lumos, so if Lumos needs to be compatible with more JavaScript runtimes in the future, it can be done by implementing the interface in @ckb-lumos/crypto
lumos@5c6be0ad2f37373e3293600bc15b2837cd581e1c
uncompressed version: 1.31 MB
buffer@5.6.0
ckb-lumos/hd
migrated bn.js@4.12
to keep the same with the elliptic
The ES module can be tracked in this issue https://github.com/ckb-js/lumos/issues/528
Background
We've received some feedback from community developers that Lumos is quite large when bundled, which is not friendly for mobile devices
Bundle Analyzer Output
stats.json.zip
lumos@487f3235fcfc83409f7752f94962e343684686b5
uncompressed version: 1.7 MBbn.js
in the bundle, probably due tobrowserify-crypto
andlumos/hd
togetherbuffer.js
in the bundleludash.isequal
Plan
require("crypto")
to import by demandlodash.isequal
module
field to point to ESM resultpackage.json
to"sideEffects: false"
if it is possible@ckb-lumos/config-manager
may not be directly marked as"sideEffect: false"
since theconfig.initializeConfig
is side-effected@ckb-lumos/rpc
from theaxios
, allowing developers to choose their own HTTP client if they don't want to use the lumos integrated one