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

Fixes #486 #487

Merged
merged 41 commits into from
Oct 5, 2023
Merged

Fixes #486 #487

merged 41 commits into from
Oct 5, 2023

Conversation

sappenin
Copy link
Collaborator

  1. Add a precondition to PrivateKey.of that enforces the length to 33 bytes (starting with either 0x00 or 0xED).
  2. Update BCKeyUtils to add/remove the padding for secp keys (the way we do for Ed keys).
  3. Add a new function to PrivateKey called valueWithoutPrefix which returns the natural 32 private key bytes.
  4. Update Secp256k1KeyPairService in Seed.java to prefix with private keys with 0x00 if only 32 bytes.
  5. Validate that PrivateKey.keyType() works properly via unit tests.

1. Add a precondition to PrivateKey.of that enforces the length to 33 bytes (starting with either  0x00 or 0xED).
2. Update BCKeyUtils to add/remove the padding for secp keys (the way we do for Ed keys).
3. Add a new function to PrivateKey called `valueWithoutPrefix` which returns the natural 32 private key bytes.
4. Update Secp256k1KeyPairService in Seed.java to prefix with private keys with 0x00 if only 32 bytes.
5. Validate that `PrivateKey.keyType()` works properly via unit tests.
@sappenin sappenin self-assigned this Sep 28, 2023
@sappenin sappenin added the bug Something isn't working label Sep 28, 2023
@codecov
Copy link

codecov bot commented Sep 28, 2023

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (530e969) 90.88% compared to head (408012b) 91.10%.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #487      +/-   ##
============================================
+ Coverage     90.88%   91.10%   +0.21%     
- Complexity     1596     1626      +30     
============================================
  Files           318      319       +1     
  Lines          4489     4553      +64     
  Branches        369      377       +8     
============================================
+ Hits           4080     4148      +68     
+ Misses          282      276       -6     
- Partials        127      129       +2     
Files Coverage Δ
...org/xrpl/xrpl4j/codec/addresses/AddressBase58.java 94.00% <100.00%> (+4.00%) ⬆️
.../org/xrpl/xrpl4j/codec/addresses/AddressCodec.java 85.71% <ø> (ø)
...g/xrpl/xrpl4j/codec/addresses/PrivateKeyCodec.java 100.00% <100.00%> (ø)
...rg/xrpl/xrpl4j/codec/addresses/PublicKeyCodec.java 100.00% <100.00%> (ø)
.../org/xrpl/xrpl4j/codec/addresses/UnsignedByte.java 87.50% <100.00%> (+3.62%) ⬆️
...xrpl/xrpl4j/codec/addresses/UnsignedByteArray.java 100.00% <ø> (ø)
.../java/org/xrpl/xrpl4j/codec/addresses/Version.java 100.00% <100.00%> (ø)
...in/java/org/xrpl/xrpl4j/crypto/keys/PublicKey.java 100.00% <100.00%> (ø)
...ava/org/xrpl/xrpl4j/crypto/keys/bc/BcKeyUtils.java 82.45% <100.00%> (-0.88%) ⬇️
...pl4j/crypto/signing/AbstractTransactionSigner.java 91.66% <ø> (ø)
... and 6 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -127,8 +127,7 @@ protected synchronized Signature ecDsaSign(final PrivateKey privateKey, final Un
Objects.requireNonNull(transactionBytes);

final UnsignedByteArray messageHash = HashingUtils.sha512Half(transactionBytes);

final BigInteger privateKeyInt = new BigInteger(privateKey.value().toByteArray());
final BigInteger privateKeyInt = new BigInteger(privateKey.valueWithPrefixedBytes().toByteArray());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should probably be privateKey.valueWithNaturalBytes? Probably doesn't matter because the prefix will be 0x00 which won't affect the value of the BigInteger, but un-prefixed seems more correct

sappenin and others added 18 commits October 4, 2023 15:08
Calling UBA.toByteArray() will copy the bytes from the UBA inot a newly initialized byte array. This code was doing this twice, just to check the legnth. In addition, the length of the UBA was being checked, whereas the length of the byte[] should have been checked instead. Generally, these two lengths should be the same, but for correctness the byte[] length is preferred.
- valueWithNaturalBytes becomes naturalBytes
- valueWithPrefixedBytes becomes prefixedBytes
@sappenin
Copy link
Collaborator Author

sappenin commented Oct 5, 2023

Merging this now that all tests passing except for two subsets of ITs.

  • build_testnet_reporting is failing only on AMM and Clawback because neither are yet enabled in TestNet.
  • build_testnet_clio is failing only on AMM and Clawback because neither are yet enabled in TestNet and failing on NFToken because of neither account_object supports nft page clio#736 nor Nftids clio#780 are deployed yet.

@sappenin sappenin merged commit 1444cfe into main Oct 5, 2023
17 of 19 checks passed
@sappenin sappenin deleted the df/fixes-486 branch October 5, 2023 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants