Repository navigation
Conversation
Payment can generate Bitcoin and Ethereum addresses but has nothing for Nano. nano_address() builds an address from a random 32-byte public key: the key and its 5-byte Blake2b checksum (byte-reversed) are encoded with Nano's base32 alphabet and prefixed with "nano_". Because the checksum is real, the result passes Nano address validation. It uses only hashlib and the provider's seeded random, so seeded instances are reproducible. Tests check the format, verify the checksum of generated addresses with an independent decoder (itself checked against a published address), and check that seeded instances agree.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add Payment.nano_address() for Nano (XNO) addresses
Paymentcan generate Bitcoin and Ethereum addresses, but there is no way to get a Nano (XNO) address for test data.This adds
Payment.nano_address(). It takes a random 32-byte public key from the provider's seededrandom, appends the 5-byte Blake2b checksum of the key (byte-reversed, as Nano does), encodes the 37 bytes with Nano's base32 alphabet (13456789abcdefghijkmnopqrstuwxyz) and adds thenano_prefix. Since the checksum is real, the generated addresses pass Nano address validation, not only a format check. Onlyhashlibfrom the standard library is used, so there is no new dependency, and seeded instances give the same addresses.Example:
nano_3t6k35gi95xu6tergt6p69ck76ogmitsa8mnijtpxm9fkcm736xtoncuohr3Tests (in
tests/test_providers/test_universal/test_payment.py):TestPayment.test_nano_address_checker: the test's own decoder accepts a widely published Nano address and rejects it with one changed checksum character.TestPayment.test_nano_address: 100 generated addresses match^nano_[13][13456789abcdefghijkmnopqrstuwxyz]{59}$and carry a valid checksum.TestSeededPayment.test_nano_address: two providers with the same seed return the same address.Results:
python3 -m pytest -q tests/test_providers/test_universal/test_payment.py: 23 passed (before the change the two newtest_nano_addresstests failed withAttributeError).ruff checkandruff format --checkon both changed files: clean.python3 -m pytest -q --ignore=tests/test_plugins/test_factory --ignore=tests/test_providers/test_universal/test_internet.py: 8544 passed before, 8547 passed after. In my local environmentfactory_boy,validators,pytzandpytest-mockare not installed, so those two paths are skipped and the same 4 failures and 8 errors in date/optional-import tests appear before and after the change; none touchPayment.