Skip to content

Add Payment.nano_address() for Nano (XNO) addresses - #1772

Open
dhyabi2 wants to merge 1 commit into
lk-geimfari:masterfrom
dhyabi2:feat/payment-nano-address
Open

dhyabi2 wants to merge 1 commit into
lk-geimfari:masterfrom
dhyabi2:feat/payment-nano-address

Conversation

@dhyabi2

@dhyabi2 dhyabi2 commented Dec 5, 2026

Copy link
Copy Markdown

Add Payment.nano_address() for Nano (XNO) addresses

Payment can 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 seeded random, 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 the nano_ prefix. Since the checksum is real, the generated addresses pass Nano address validation, not only a format check. Only hashlib from the standard library is used, so there is no new dependency, and seeded instances give the same addresses.

Example: nano_3t6k35gi95xu6tergt6p69ck76ogmitsa8mnijtpxm9fkcm736xtoncuohr3

Tests (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 new test_nano_address tests failed with AttributeError).
  • ruff check and ruff format --check on both changed files: clean.
  • Full suite, 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 environment factory_boy, validators, pytz and pytest-mock are 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 touch Payment.

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant