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: remove uuid dependency in favor of crypto.randomUUID() #1608

Closed
wants to merge 14 commits into from

Conversation

nedsalk
Copy link
Contributor

@nedsalk nedsalk commented Jan 4, 2024

This is a quick win that follows what the uuid library suggests:

Note: Only interested in creating a version 4 UUID? You might be able to use crypto.randomUUID(), eliminating the need to install this library.

@nedsalk nedsalk marked this pull request as draft January 4, 2024 14:35
@nedsalk nedsalk self-assigned this Jan 4, 2024
@nedsalk nedsalk added the feat Issue is a feature label Jan 4, 2024
@nedsalk nedsalk added this to the 2 - Beetle milestone Jan 4, 2024
@nedsalk nedsalk marked this pull request as ready for review January 4, 2024 14:54
@nedsalk nedsalk requested a review from arboleya January 4, 2024 14:54
@nedsalk nedsalk modified the milestones: 2 - Beetle, 1 - Salamander Jan 4, 2024
Copy link
Contributor

@Torres-ssf Torres-ssf left a comment

Choose a reason for hiding this comment

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

It seems crypto.randomUUID() is only supportable by Node 19.

So if we are going to make this change, we need to require Node >= 19 on the main package.json.

Comment on lines 1 to 2
---
---
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the changeset should not be empty since we are adding a new exportable helper on the crypto package and made changes on the wallet package.

Therefore we want to bump versions on these 2 packages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cbed7c4

I put crypto into the changeset because of the new export, but didn't put wallet because this is an internal change that doesn't change its functionality at all.

Copy link
Member

Choose a reason for hiding this comment

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

These packages are published independently.

We can't consider things as "internal" in this way.

The usual is to bump everything that will get a new published version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nedsalk
Copy link
Contributor Author

nedsalk commented Jan 4, 2024

It seems crypto.randomUUID() is only supportable by Node 19.

After I integrated randomUUID into our crypto package (2cb31dc), our Node v18 test suite passed. That MDN list you linked to is perhaps referring to crypto being available globally without the need for import crypto from 'crypto', which would be in line with my comment.

They also mentioned on the MDN:

From version 14.17.0, a similar method is available as crypto.randomUUID().

Copy link
Member

@arboleya arboleya left a comment

Choose a reason for hiding this comment

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

This looks great! Could you please add some tests?

This crypto package is unique in providing two different builds for node and browser, so the tests are a bit different and may be slightly off, potentially depending on things from:

Just want to say that this package caused problems in the past and needs special attention. I know it directly relates to #1431 and indirectly to #1610.

You can reach out to @Torres-ssf and @danielbate if you need insights.


@Torres-ssf @danielbate @nedsalk Guys, the final aim is to have the crypto package completely unit-tested in the 💯s when testing in both node and browser envs.

@nedsalk
Copy link
Contributor Author

nedsalk commented Jan 8, 2024

@arboleya

This looks great! Could you please add some tests?

7b18afc

I had to put every test into a separate file because putting them into one file caused them to share the same environment and stubbing globalThis.crypto once with vi.stubGlobal("crypto", whatever) caused it to override the globalThis.crypto for every test, even when calling vi.unstubAllGlobals() after each test. This caused tests to fail because different crypto stubs are necessary for each test to work properly.

@nedsalk nedsalk requested a review from arboleya January 8, 2024 12:12
Copy link
Contributor

github-actions bot commented Jan 8, 2024

Coverage Report:

Lines Branches Functions Statements
79.21%(-2.79%) 68.91%(+1.14%) 77.62%(+2.06%) 79.24%(-2.54%)
Changed Files:
Ok File (✨=New File) Lines Branches Functions Statements
🔴 ✨ internal/check-imports/src/imports.ts 0%
(+0%)
100%
(+100%)
100%
(+100%)
0%
(+0%)
🔴 ✨ internal/check-imports/src/references.ts 0%
(+0%)
100%
(+100%)
100%
(+100%)
0%
(+0%)
🔴 internal/check-tests/src/index.ts 85.71%
(+5.71%)
80%
(+13.34%)
100%
(+0%)
87.5%
(+5.69%)
🔴 ✨ internal/tsup/src/index.ts 0%
(+0%)
100%
(+100%)
100%
(+100%)
0%
(+0%)
🔴 packages/abi-coder/src/abi-coder.ts 89.47%
(+0%)
82.35%
(-2.49%)
87.5%
(+0%)
89.65%
(-0.18%)
🔴 packages/abi-coder/src/constants.ts 96%
(+0.17%)
100%
(+0%)
0%
(+0%)
96%
(+0.17%)
🔴 packages/abi-coder/src/function-fragment.ts 74.28%
(-3.84%)
72.72%
(+0%)
81.81%
(+0%)
75.32%
(+0%)
🔴 packages/abi-coder/src/interface.ts 61.76%
(+1.16%)
50%
(+0%)
76.47%
(+0%)
61.11%
(+0%)
🔴 packages/abi-coder/src/resolved-abi-type.ts 98.57%
(+0.16%)
100%
(+0%)
94.73%
(+0%)
98.66%
(+0%)
🔴 packages/abi-coder/src/utilities.ts 96.72%
(-1.39%)
91.3%
(-3.93%)
93.33%
(+1.67%)
96.87%
(-1.31%)
🔴 ✨ packages/abi-typegen/typegen.js 0%
(+0%)
100%
(+100%)
100%
(+100%)
0%
(+0%)
🔴 ✨ packages/abi-typegen/src/bin.ts 0%
(+0%)
100%
(+100%)
100%
(+100%)
0%
(+0%)
✨ packages/abi-typegen/src/abi/types/StrSliceType.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
🔴 packages/address/src/address.ts 90%
(+2.13%)
79.16%
(+6.94%)
83.33%
(+0.98%)
90%
(+2.13%)
🔴 ✨ packages/address/src/configs.ts 0%
(+0%)
100%
(+100%)
100%
(+100%)
0%
(+0%)
🔴 packages/address/src/utils.ts 84.37%
(-0.47%)
78.94%
(-0.22%)
92.3%
(+0%)
84.84%
(-0.45%)
🔴 ✨ packages/contract/src/contract-factory.ts 0%
(+0%)
0%
(+0%)
0%
(+0%)
0%
(+0%)
🔴 ✨ packages/contract/src/util.ts 0%
(+0%)
0%
(+0%)
0%
(+0%)
0%
(+0%)
🔴 ✨ packages/create-fuels/create-fuels.js 0%
(+0%)
100%
(+100%)
100%
(+100%)
0%
(+0%)
🔴 ✨ packages/create-fuels/scripts/rewriteTemplatePackageJson.ts 0%
(+0%)
100%
(+100%)
100%
(+100%)
0%
(+0%)
🔴 ✨ packages/create-fuels/src/bin.ts 0%
(+0%)
100%
(+100%)
0%
(+0%)
0%
(+0%)
🔴 ✨ packages/create-fuels/src/cli.ts 75%
(+75%)
47.36%
(+47.36%)
100%
(+100%)
75%
(+75%)
🔴 ✨ packages/crypto/src/index.browser.ts 0%
(+0%)
100%
(+100%)
100%
(+100%)
0%
(+0%)
🔴 ✨ packages/crypto/src/browser/aes-ctr.ts 0%
(+0%)
100%
(+100%)
0%
(+0%)
0%
(+0%)
🔴 ✨ packages/crypto/src/browser/bufferFromString.ts 0%
(+0%)
0%
(+0%)
0%
(+0%)
0%
(+0%)
🔴 ✨ packages/crypto/src/browser/crypto.ts 100%
(+100%)
90%
(+90%)
100%
(+100%)
100%
(+100%)
🔴 ✨ packages/crypto/src/browser/encryptJsonWalletData.ts 0%
(+0%)
100%
(+100%)
0%
(+0%)
0%
(+0%)
🔴 ✨ packages/crypto/src/browser/index.ts 0%
(+0%)
100%
(+100%)
100%
(+100%)
0%
(+0%)
🔴 ✨ packages/crypto/src/browser/randomBytes.ts 0%
(+0%)
100%
(+100%)
0%
(+0%)
0%
(+0%)
🔴 ✨ packages/crypto/src/browser/stringFromBuffer.ts 0%
(+0%)
0%
(+0%)
0%
(+0%)
0%
(+0%)
🔴 ✨ packages/forc/lib/bin.js 0%
(+0%)
100%
(+100%)
100%
(+100%)
0%
(+0%)
🔴 ✨ packages/forc/lib/index.js 0%
(+0%)
100%
(+100%)
100%
(+100%)
0%
(+0%)
🔴 ✨ packages/forc/lib/install.js 0%
(+0%)
0%
(+0%)
0%
(+0%)
0%
(+0%)
🔴 ✨ packages/forc/lib/shared.js 0%
(+0%)
0%
(+0%)
0%
(+0%)
0%
(+0%)
🔴 ✨ packages/forc/lib/update.js 0%
(+0%)
0%
(+0%)
0%
(+0%)
0%
(+0%)
🔴 ✨ packages/fuel-core/lib/bin.js 0%
(+0%)
100%
(+100%)
100%
(+100%)
0%
(+0%)
🔴 ✨ packages/fuel-core/lib/index.js 0%
(+0%)
100%
(+100%)
100%
(+100%)
0%
(+0%)
🔴 ✨ packages/fuel-core/lib/install.js 0%
(+0%)
0%
(+0%)
0%
(+0%)
0%
(+0%)
🔴 ✨ packages/fuel-core/lib/shared.js 0%
(+0%)
0%
(+0%)
0%
(+0%)
0%
(+0%)
🔴 ✨ packages/fuel-core/lib/update.js 0%
(+0%)
0%
(+0%)
0%
(+0%)
0%
(+0%)
🔴 ✨ packages/fuels/fuels.js 0%
(+0%)
100%
(+100%)
100%
(+100%)
0%
(+0%)
🔴 ✨ packages/fuels/src/bin.ts 0%
(+0%)
0%
(+0%)
100%
(+100%)
0%
(+0%)
✨ packages/fuels/src/run.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/types.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/commands/withConfig.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/commands/withProgram.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/commands/build/buildSwayProgram.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/commands/build/buildSwayPrograms.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/commands/build/forcHandlers.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/commands/build/generateTypes.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/commands/build/index.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/commands/deploy/createWallet.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
🔴 ✨ packages/fuels/src/cli/commands/deploy/deployContract.ts 100%
(+100%)
75%
(+75%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/commands/deploy/getDeployConfig.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/commands/deploy/index.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/commands/deploy/saveContractIds.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/commands/dev/autoStartFuelCore.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/commands/dev/defaultChainConfig.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/commands/dev/index.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/commands/dev/startFuelCore.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/commands/init/index.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/commands/init/shouldUseBuiltinForc.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/commands/init/shouldUseBuiltinFuelCore.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/config/forcUtils.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/config/loadConfig.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/config/validateConfig.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/templates/fuels.config.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/templates/index.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/utils/createConfig.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
🔴 ✨ packages/fuels/src/cli/utils/findBinPath.ts 80%
(+80%)
50%
(+50%)
100%
(+100%)
80%
(+80%)
✨ packages/fuels/src/cli/utils/getBinarySource.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/fuels/src/cli/utils/logger.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
🔴 packages/hasher/src/hasher.ts 28.57%
(-36.54%)
100%
(+60%)
66.66%
(-33.34%)
28.57%
(-36.54%)
🔴 packages/math/src/bn.ts 88.37%
(+1.79%)
85.71%
(-0.82%)
80%
(+1.22%)
88.37%
(+1.63%)
🔴 ✨ packages/math/src/math.ts 0%
(+0%)
0%
(+0%)
0%
(+0%)
0%
(+0%)
🔴 ✨ packages/merkle/src/binary/types/branch.ts 0%
(+0%)
100%
(+100%)
0%
(+0%)
0%
(+0%)
🔴 ✨ packages/merkle/src/sparse/types/sparseCompactMerkleBranch.ts 0%
(+0%)
100%
(+100%)
0%
(+0%)
0%
(+0%)
🔴 ✨ packages/merkle/src/sparse/types/sparseCompactMerkleSolidityProof.ts 0%
(+0%)
100%
(+100%)
0%
(+0%)
0%
(+0%)
🔴 ✨ packages/merkle/src/sparse/types/sparseMerkleSolidityNode.ts 0%
(+0%)
0%
(+0%)
0%
(+0%)
0%
(+0%)
🔴 packages/mnemonic/src/mnemonic.ts 98.48%
(+0.07%)
90.32%
(+0%)
100%
(+0%)
98.48%
(+0%)
🔴 packages/predicate/src/predicate.ts 64.7%
(-1.96%)
45.83%
(-4.17%)
72.72%
(-5.05%)
64.7%
(-1.96%)
🔴 ✨ packages/providers/src/call-retrier.ts 90%
(+90%)
86.66%
(+86.66%)
100%
(+100%)
90%
(+90%)
🔴 packages/providers/src/coin-quantity.ts 44.44%
(+33.33%)
50%
(+50%)
33.33%
(+33.33%)
42.1%
(+30.99%)
🔴 ✨ packages/providers/src/fuel-graphql-subscriber.ts 80%
(+80%)
37.5%
(+37.5%)
100%
(+100%)
80%
(+80%)
🔴 packages/providers/src/provider.ts 73.54%
(+16.06%)
57.75%
(+5.99%)
67.69%
(+14.25%)
72.07%
(+16%)
🔴 packages/providers/src/resource.ts 80%
(+0%)
100%
(+0%)
25%
(+25%)
62.5%
(+12.5%)
🔴 packages/providers/src/generated/operations.ts 89.89%
(+7.54%)
100%
(+0%)
67.74%
(+24.35%)
90.29%
(+16.84%)
🔴 packages/providers/src/transaction-request/create-transaction-request.ts 58.82%
(+58.82%)
53.33%
(+53.33%)
37.5%
(+37.5%)
58.82%
(+58.82%)
🔴 ✨ packages/providers/src/transaction-request/hash-transaction.ts 55.55%
(+55.55%)
40%
(+40%)
100%
(+100%)
55.55%
(+55.55%)
🔴 packages/providers/src/transaction-request/output.ts 66.66%
(+55.55%)
50%
(+50%)
100%
(+100%)
66.66%
(+55.55%)
🔴 packages/providers/src/transaction-request/script-transaction-request.ts 37.5%
(+9.38%)
57.14%
(+7.14%)
27.77%
(+6.35%)
36.58%
(+9.31%)
🔴 packages/providers/src/transaction-request/transaction-request.ts 71.53%
(+53.14%)
55.93%
(+30.4%)
73.91%
(+59.21%)
71.64%
(+53.67%)
🔴 packages/providers/src/transaction-response/transaction-response.ts 13.51%
(+8.25%)
0%
(+0%)
28.57%
(+28.57%)
13.51%
(+8.25%)
🔴 packages/providers/src/transaction-summary/assemble-transaction-summary.ts 100%
(+0%)
57.14%
(-5.36%)
100%
(+0%)
100%
(+0%)
🔴 ✨ packages/providers/src/transaction-summary/calculate-transaction-fee.ts 100%
(+100%)
87.5%
(+87.5%)
100%
(+100%)
100%
(+100%)
🔴 ✨ packages/providers/src/transaction-summary/get-transaction-summary.ts 0%
(+0%)
0%
(+0%)
0%
(+0%)
0%
(+0%)
🔴 packages/providers/src/transaction-summary/operations.ts 98.09%
(-0.83%)
77.19%
(+0.72%)
100%
(+0%)
98.14%
(+0.19%)
✨ packages/providers/src/utils/gas.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/providers/src/utils/merge-quantities.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
packages/providers/src/utils/sleep.ts 100%
(+100%)
100%
(+0%)
100%
(+100%)
100%
(+100%)
🔴 packages/signer/src/signer.ts 79.31%
(-1.94%)
60%
(+0%)
71.42%
(-3.58%)
79.31%
(-1.94%)
🔴 ✨ packages/transactions/src/configs.ts 0%
(+0%)
100%
(+100%)
100%
(+100%)
0%
(+0%)
🔴 packages/transactions/src/coders/input.ts 77.48%
(+0.93%)
78.57%
(+0%)
87.5%
(+0%)
77.63%
(+0.92%)
🔴 ✨ packages/transactions/src/coders/policy.ts 97.67%
(+97.67%)
94.11%
(+94.11%)
100%
(+100%)
97.77%
(+97.77%)
🔴 packages/transactions/src/coders/transaction.ts 98.56%
(+0.04%)
80%
(+0%)
100%
(+0%)
98.57%
(+0.03%)
packages/utils/src/test-utils/getForcProject.ts 100%
(+2.71%)
100%
(+50%)
100%
(+0%)
100%
(+2.64%)
✨ packages/utils/src/utils/arrayify.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/utils/src/utils/capitalizeString.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/utils/src/utils/hexlify.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
🔴 ✨ packages/versions/versions.js 0%
(+0%)
100%
(+100%)
100%
(+100%)
0%
(+0%)
🔴 ✨ packages/versions/src/bin.ts 0%
(+0%)
100%
(+100%)
100%
(+100%)
0%
(+0%)
✨ packages/versions/src/lib/compareSystemVersions.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/versions/src/lib/fuelUpLink.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/versions/src/lib/getBuiltinVersions.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/versions/src/lib/getSystemVersions.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/versions/src/lib/semver.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
🔴 ✨ packages/wallet-manager/src/types.ts 0%
(+0%)
100%
(+100%)
0%
(+0%)
0%
(+0%)
🔴 packages/wallet-manager/src/vaults/mnemonic-vault.ts 93.75%
(+0.21%)
80%
(+0%)
100%
(+0%)
93.75%
(+0.21%)
🔴 packages/wallet/src/account.ts 78.21%
(-5.3%)
32.25%
(-30.25%)
88.23%
(-4.07%)
78.21%
(-5.3%)
🔴 packages/wallet/src/test-utils/launchNode.ts 98.33%
(-1.67%)
81.48%
(+3.22%)
100%
(+0%)
98.36%
(-1.64%)
🔴 ✨ packages/wordlists/src/index.ts 0%
(+0%)
0%
(+0%)
0%
(+0%)
0%
(+0%)

@nedsalk nedsalk enabled auto-merge (squash) January 8, 2024 15:21
@nedsalk nedsalk mentioned this pull request Jan 9, 2024
44 tasks
Copy link
Member

@arboleya arboleya left a comment

Choose a reason for hiding this comment

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

@nedsalk Having each test on a separate file is a problem. Allowing this to happen in this PR would open the doors for other PRs to do the same. We should invest more time getting to the bottom so this pattern is never introduced in the codebase.

@arboleya
Copy link
Member

arboleya commented Jan 9, 2024

Also, if the gain in terms of bundle size will be marginal, we could drop this PR altogether.

@nedsalk
Copy link
Contributor Author

nedsalk commented Jan 9, 2024

@arboleya Yeah, let's just drop it for the time being. We can revisit it after #1431 is merged. Maybe then the tests will be more straightforward to implement.

@nedsalk nedsalk closed this Jan 9, 2024
auto-merge was automatically disabled January 9, 2024 17:31

Pull request was closed

@arboleya
Copy link
Member

arboleya commented Jan 9, 2024

@nedsalk Alright. Please remember to remove this PR's mention from:

@nedsalk nedsalk deleted the ns/feat/remove-uuid-dependency branch February 26, 2024 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Issue is a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants