Repository navigation
fix: throw RangeError for an unsupported network option - #13
Merged
Samarth208P merged 3 commits intoNov 21, 2026
Merged
Conversation
From JavaScript, network: 'foo' made a valid mainnet Bitcoin address fail with NETWORK_MISMATCH while a valid Ethereum address passed with the same option, pointing callers at the recipient instead of their configuration. validateAddress, validateBatch, detectBlockchain and validator validate methods now check the option through a shared assertValidationOptions before reading input, so empty batches and empty, blank or unsafe detection input throw too. undefined and null still mean auto. A valid network paired with a real address on the other network still returns NETWORK_MISMATCH with the decoded network. Closes Samarth208P#6
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.
Closes #6.
User-visible change
An unsupported
networkvalue now throws aRangeError. That's any value other than'mainnet','testnet','auto',undefinedornull. It throws from:validateAddressvalidateBatchdetectBlockchainvalidatemethodThe check runs before any input is read, so the error doesn't depend on the data. An empty batch, and empty, blank or unsafe detection input, all throw too.
Previously,
network: 'foo'made a valid mainnet Bitcoin address fail withNETWORK_MISMATCH, while a valid Ethereum address passed with the same option.undefinedandnullstill meanauto, as onmain, so configurations that store an unset value asnullkeep working. A valid network paired with a real address on the other network still returnsNETWORK_MISMATCHwith the decoded network.README, AGENTS.md and the CHANGELOG ("Unreleased") are updated.
Implementation
A shared
assertValidationOptionsinsrc/validators/base.tsruns at the start of three places:AddressValidator.validatevalidateBatchdetectBlockchainIt isn't exported from the package entry points.
Tests
tests/network-option.test.tscovers each case requested in the issue:'foo','Mainnet','main','',1,trueand{}. Each one throws aRangeErrorfrom:BitcoinValidator,EthereumValidatorandCardanoValidatorinstancesundefined,null,'auto','mainnet'and'testnet'return[]for an empty batch andnullfor empty detection input, without throwing.network: 'mainnet'with the BIP-173 testnet vector returnsNETWORK_MISMATCHwithnetwork: 'testnet'andformat: 'segwit'.NETWORK_MISMATCH.On
main, 35 of the 42 new tests fail; the 7 control tests pass. All of them pass on this branch.Results
npm ci,npm run checkandnpm audit(0 vulnerabilities) on Node 22.23.5, 24.16.0 and 26.13.1, andnpm run test:coverageon Node 24.16.0. All passed.