Conversation
…crypto. * Remove dependency on ripemd160 package, replace with node.js crypto usage. * Import only what is used from the `crypto` lib.
…out removing it from the lib.
…f `elliptic` only used for secp256k1 -- good target for replacement
… and reducing docgen command to output html and json in a single-pass.
* develop: (42 commits) Update changelog Remove unneeded line Oops, 4 instead of 3 passes required. Test `GaiaHubError` values Include correct error code Fix error message test Modify getFile test to expect throw on 404 instead of null Add `await` when getting blockstackErrorFromResponse Fix style issues Convert to async function + ts syntax Make functions `async` to account for async method for getting error from rrsponse getgaiaErrorResponse method (allow text or json body) Fix test + styling issues Get rid of getResponseDescription, integrate GaiaHubError Include response data in GaiaHubError types ErrorType -> ErrorData Add GaiaHubError, make gaia errors extend that instead FileNotFound -> DoesNotExistError centralized gaia error handling function support PayloadTooLargeError ... # Conflicts: # .vscode/launch.json # mdincludes/script-dist-file.md # package-lock.json # package.json # src/encryption/ec.ts
…pping the node `crypto` module; WebCrypto implementation coming later)
Extract minimal 4KB implementation of ripemd160 from browserify-crypto polyfilly.
* Moved crypto lib loader into util module, made all crypto loading calls async.
* Add dev dependency for webcrypto lib (has compatbility wrappers for node.js) for unit testing
…king and module transforms
…ion must provide the lib
* develop: #710 Change dist file CDN sample generator to ignore prerelease versions Fix core node endpoint preference from the user not being used for name lookups, removed redundant UserSession AppConfig code # Conflicts: # package-lock.json # package.json
…or web browser environments
Codecov Report
@@ Coverage Diff @@
## develop #737 +/- ##
===========================================
+ Coverage 68.62% 69.15% +0.53%
===========================================
Files 57 65 +8
Lines 3429 3693 +264
Branches 623 658 +35
===========================================
+ Hits 2353 2554 +201
- Misses 778 821 +43
- Partials 298 318 +20
Continue to review full report at Codecov.
|
… crypto and WebCrypto
|
Thanks @zone117x for all the work on this PR. It looks mostly good for me, but I think the latest changes broke some of the tests. I'm getting 12 failed tests right now, mostly on the RIPEMD160 and SHA2 hash tests. |
…d `URLSearchParams` support -- notably NodeJS v8.x and older browsers
…ith improved error handling
|
@yknl If you are still running into test failures, can you ensure Node.js >=10 is being used, and try wiping your |
|
@zone117x looks like this has been approved a while back, any other blockers to merging? |
Description
Closes #691
The goal of this PR is to make the cryptographic operations performed by blockstack.js more efficient -- less CPU & memory intensive and smaller file size (especially for mobile).
This primarily improves the performance of storage and authentication functions.
This PR includes a refactor of all usages of applicable cryptographic operations to use the W3C native Web Crypto APIs.
This includes:
aes-256-cbcencrypt & decryptsha-256andsha-512hash digestshmac-sha256digestpbkdf2-sha256andpbkdf2-sha512password derivationThe
ripemd160hash digest is not available in the Web Crypto API, however, it has been converted to use a minimal and relatively fast JS lib as opposed to the large node.jscryptomodule polyfill.The
tripleseclib is no longer a direct blockstack.js dependency. It must now be provided by the consumer application. It was responsible for ~250KB of the blockstack.js dist, but is used only for decrypting legacy mnemonics. AFAIK no regular apps built on Blockstack use this. Only a few consumer apps use this function (e.g. blockstack-cli, blockstack-browser, wallet[?]). It has been made trivial for consumer apps to import thetripleseclib and pass it to blockstack.js.The
cheeriohtml parsing lib has the same treatment as above. It is used for social proofs, which is not directly used by typical apps. Consumer apps (e.g. Gaia, blockstack-browser) must import this dependency themselves.The dist bundle size is now down to 550KB.
The linter rules were tightened up, especially around Promise/async/await handling. This helped catch several instance of bugs like
`some_string_${promise_variable}`->`some_string_${await promise_variable}`. The stricter rules also ended up requiring minor changes to some code that is not necessarily related to cryptographic operations.For updates on our effected consumer apps, see:
Type of Change
Does this introduce a breaking change?
This is a breaking change and requires a major version update.
Note: the Web Crypto APIs only provide async functions, so the changes to use these propagated up to several other functions in the call graphs.
I kept a list of all functions that were previously synchronous which now return promises. Most of these are not public API functions. These have been listed in the CHANGELOG:
Are documentation updates required?
Possibly -- the API reference docs will be auto updated, but any tutorials referencing the above functions may need updated.
Checklist
npm run testpassesExtra TODO