fix(identify): validate public input types #128
<!-- codex-pull-request-review-summary -->
<!-- codex-review-state:v1 {"code_review":{"commit_sha":"92f737cc1206787492623d5d464a7236bef9755f","has_any_findings":true,"has_unresolved_findings":true,"status":"failed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} -->
<details>
<summary><strong>Codex Review Summary</strong>: ❌ Failed</summary>
This comment shows the latest Codex review activity on this pull request.
| Review | Status | Commit | Review trigger |
| --- | --- | --- | --- |
| 📝 Code Review | ❌ Failed <relative-time datetime="2026-11-19T00:01:59.491056Z">2026-11-19T00:01:59.491056Z</relative-time><br/>We couldn’t complete this review. Comment @codex review to try again. | 92f737c | PR opened |
<details> <summary>ℹ️ About Codex in GitHub</summary>
<br/>
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
</details>
</details>
<!-- coderabbit-ai-generated:v1 -->
<!-- This is an auto-generated comment: summarize by coderabbit.ai -->
<!-- review_stack_entry_start -->
<a href="https://app.coderabbit.ai/change-stack/btclib-org/seed-scan/pull/128?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg" alt="Explain Change →" height="32"></picture></a>
<!-- review_stack_entry_end -->
<!-- This is an auto-generated comment: rate limited by coderabbit.ai -->
[!WARNING]
## Review limit reached
> This organization requires a seat for paid usage-based reviews, including automatic and on-demand reviews. Ask an admin to assign a seat or enable paid usage-based reviews for users without a seat in Billing.
> Next included review available in 29 minutes.
> Check out review usage here.
> <details>
<summary><strong>View limit details</strong></summary>
<dl>
<dd>
<br>
> Limit details: You’ve used the included review currently available.
> Learn how review limits work.
> Review configuration:
> <details>
<summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</strong></summary>
<dl>
<dd>
<br>
> - Source mode: Auto
- Repository: [btclib-org/seed-scan](<https://github.com/btclib-org/seed-scan>)
- Branch: [main](<https://github.com/btclib-org/seed-scan/tree/main>)
- File: [.coderabbit.yaml](<https://github.com/btclib-org/seed-scan/blob/700317960f1ccd6f2f015bc97d374a7242c63672/.coderabbit.yaml>)
- Commit: [7003179](<https://github.com/btclib-org/seed-scan/commit/700317960f1ccd6f2f015bc97d374a7242c63672>)
- Layers: Repository YAML
- Review profile: ASSERTIVE
- Plan: Advanced
- Run ID: eb24e7b6-f7cf-4104-a21e-0df829533093> </dd>
</dl>
</details>
> <details>
<summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</strong></summary>
<dl>
<dd>
<br>
> Reviewing files that changed from the base of the PR and between f09fb5d5c79c0340cee68cf4389d2437e61dcd8d and 36b39d1c091b9efc26f8d20432030f63087d0ada.
> </dd>
</dl>
</details>
> <details>
<summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 3</strong></summary>
<dl>
<dd>
<br>
> src/seed_scan/identify.py tests/identify_test.py tests/input_validation_test.py> </dd>
</dl>
</details>
> </dd>
</dl>
</details>
<!-- end of auto-generated comment: rate limited by coderabbit.ai -->
<!-- recent_review_status_start -->
No actionable comments were generated in the recent review.
<!-- recent_review_status_end -->
<!-- walkthrough_start -->
<details>
<summary><strong>Summary</strong></summary>
<dl>
<dd>
<br>
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
Bug Fixes
Invalid passphrase values, prompts, and addresses are now rejected with a clear type error.
Tuples of strings remain accepted as passphrases.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->identify now validates the types of passphrases, prompt, and address and raises SeedScanTypeError for invalid values. Tests cover rejected inputs, tuple acceptance, and removal of the related input-validation exemptions.
Changes: Identify input validation
|Layer / File(s)|Summary|
|:---|:---|
|Declare and validate identify inputs <br> src/seed_scan/identify.py, tests/identify_test.py, tests/input_validation_test.py|identify now accepts a list or tuple of strings for passphrases, requires a callable prompt, and requires address to be a string when provided. Tests cover invalid inputs and tuple acceptance. The input-validation tests no longer exempt these parameters.|
<!-- change_assessment_start -->
Estimated code review effort: 2 (Simple) | ~10 minutes
<!-- change_assessment_commit:"f09fb5d5c79c0340cee68cf4389d2437e61dcd8d" -->
<!-- change_assessment_priority:{"version":1,"urgency":"p3","manual":false} -->
Change: Bug fix · Severity of issue fixed: Low
<!-- change_assessment_end -->
Possibly related PRs
identify command whose input contract this pull request validates.Suggested reviewers: fametrano
</dd>
</dl>
</details>
<!-- walkthrough_end -->
<details>
<summary><strong>Merge Risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-unassessed-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minimal</strong> · previous review <code>f09fb</code></summary>
<dl>
<dd>
<br>
<!-- final_review_risk_start -->
<!-- final_review_risk_label
Merge Risk: ⚪ Minimal · up to f09fb
-->
<!-- final_review_risk_coverage:{"sourceCommitId":"f09fb5d5c79c0340cee68cf4389d2437e61dcd8d","coveredCommitId":"f09fb5d5c79c0340cee68cf4389d2437e61dcd8d","kind":"reviewed"} -->
identify now raises SeedScanTypeError for invalid passphrases, prompt, or address values before doing any work. Tests cover the rejected inputs and a valid tuple. No concrete merge-blocking risk was found.
<!-- final_review_risk_end -->
</dd>
</dl>
</details>
<!-- pre_merge_checks_walkthrough_start -->
<details>
<summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4</strong></summary>
<dl>
<dd>
<br>
| Check name | Status | Explanation |
| :------------------------ | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Title check | !Passed | The title "fix(identify): validate public input types" matches the main change: identify now validates passphrases, prompt, and address types and raises SeedScanTypeError. It uses a conventional commi… |
| Description check | !Passed | The description states that identify now rejects invalid public inputs with SeedScanTypeError. It lists the passphrases, prompt, and address validation, the regression tests, and the removal of three … |
| Linked Issues check | !Passed | Issue #63 requires identify to raise SeedScanTypeError, before deriving anything, for passphrases that are not a list or tuple of str, a non-callable prompt, and an address that is neither None nor st… |
| Out of Scope Changes check | !Passed | All changed hunks map to the issue #63 objective: the identify.py validation and hint change, the new tests in tests/identify_test.py, and the removal of the three #63 entries in tests/input_validatio… |
<details>
<summary><strong>Full details: Title check</strong></summary>
<dl>
<dd>
<br>
Explanation
The title "fix(identify): validate public input types" matches the main change: identify now validates passphrases, prompt, and address types and raises SeedScanTypeError. It uses a conventional commit prefix. The title does not state the exact contract, but it is related to the main change.
</dd>
</dl>
</details>
<details>
<summary><strong>Full details: Description check</strong></summary>
<dl>
<dd>
<br>
Explanation
The description states that identify now rejects invalid public inputs with SeedScanTypeError. It lists the passphrases, prompt, and address validation, the regression tests, and the removal of three _NOT_REFUSED cases. It matches the changeset closely.
</dd>
</dl>
</details>
<details>
<summary><strong>Full details: Linked Issues check</strong></summary>
<dl>
<dd>
<br>
Explanation
Issue #63 requires identify to raise SeedScanTypeError, before deriving anything, for passphrases that are not a list or tuple of str, a non-callable prompt, and an address that is neither None nor str. The head diff of src/seed_scan/identify.py adds these checks at the top of identify, after the mnemonic check and before _assert_bound and any derivation. The checks cover passphrases type, each passphrase element type, callable prompt, and address type. The passphrases hint changes from Sequence[str] to list[str] | tuple[str, ...], which matches the runtime check, as the issue permits. Acceptance criteria: tests/identify_test.py adds parametrized tests for passphrases (None, str, [None], tuple with None), a valid tuple, a non-callable prompt, and non-string addresses (1.5, b"x"). tests/input_validation_test.py removes the three #63 entries from _NOT_REFUSED. Evidence is from the diffs at head versus merge base; the test run results were not independently re-executed.
</dd>
</dl>
</details>
<details>
<summary><strong>Full details: Out of Scope Changes check</strong></summary>
<dl>
<dd>
<br>
Explanation
All changed hunks map to the issue #63 objective: the identify.py validation and hint change, the new tests in tests/identify_test.py, and the removal of the three #63 entries in tests/input_validation_test.py. No unrelated change was found in the reviewed diffs. Reviewer requests in the PR objectives (DCO sign-off, Ruff E501 docstring length, match= assertions) concern process or style and are not scope violations.
</dd>
</dl>
</details>
</dd>
</dl>
</details>
<!-- pre_merge_checks_walkthrough_end -->
<!-- finishing_touch_checkbox_start -->
<details>
<summary><strong>Finishing Touches</strong></summary>
<dl>
<dd>
<br>
<details open>
<summary><strong>Generate unit tests (beta)</strong></summary>
<dl>
<dd>
<br>
</dd>
</dl>
</details>
<!-- finishing_touch_suggestion:fix_ci -->
<details open>
<summary><strong>Fix failing CI checks</strong></summary>
<dl>
<dd>
<br>
</dd>
</dl>
</details>
</dd>
</dl>
</details>
<!-- finishing_touch_checkbox_end -->
<!-- autopilot:start -->
<!-- autopilot:end -->
<!-- tips_start -->
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
<details>
<summary><strong>Share</strong></summary>
<dl>
<dd>
<br>
</dd>
</dl>
</details>
<!-- tips_end -->
<!-- recent_review_start -->
<h6>
<details>
<summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Recent review info</strong></summary>
<dl>
<dd>
<br>
<!-- review_info_content -->
<details>
<summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</strong></summary>
<dl>
<dd>
<br>
62db4f6e-97b4-4327-94d9-e5f1eacee825</dd>
</dl>
</details>
<details>
<summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</strong></summary>
<dl>
<dd>
<br>
Reviewing files that changed from the base of the PR and between 700317960f1ccd6f2f015bc97d374a7242c63672 and f09fb5d5c79c0340cee68cf4389d2437e61dcd8d.
</dd>
</dl>
</details>
<details>
<summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 3</strong></summary>
<dl>
<dd>
<br>
src/seed_scan/identify.py
tests/identify_test.py
tests/input_validation_test.py
</dd>
</dl>
</details>
<details>
<summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-no-changes-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-no-changes.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files with no reviewable changes: 1</strong></summary>
<dl>
<dd>
<br>
tests/input_validation_test.py
</dd>
</dl>
</details>
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
</dd>
</dl>
</details>
</h6>
<!-- recent_review_end -->
SeedScanTypeError._NOT_REFUSED.identify and its regression tests.Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.
<!-- readthedocs-1195074 -->
Documentation build overview
📚 seed-scan | 🛠️ Build #36004513 | 📁 Comparing 36b39d1c091b9efc26f8d20432030f63087d0ada against latest (bf42f43086d8739d74417e165703ff06d19d066f)
<kbd> 🔍 Preview build </kbd>
<details open>
<summary>2 files changed</summary>
<br>
<code>±</code> <a href="https://seed-scan--128.org.readthedocs.build/en/128/seed_scan.html"><code>seed_scan.html</code></a><br>
<code>±</code> <a href="https://seed-scan--128.org.readthedocs.build/en/128/_modules/seed_scan/identify.html"><code>_modules/seed_scan/identify.html</code></a><br>
</details>
Thank you, @Aaqibhafeezkhan: the checks are in the right place, before anything is derived, and they close the three gaps #63 lists. Two things hold it: the sign-off, and a line the linter refuses.
The sign-off. The Sign-off check is required, and your commit 92f737c has no Signed-off-by: trailer. The trailer certifies the Developer Certificate of Origin, so it has to come from you; we cannot add it for you. On your branch, with the address the check names as your git user.email, run:
git rebase --signoff bf42f43086d8739d74417e165703ff06d19d066f
git push --force-with-lease
Under the organization's CONTRIBUTING.md, a pull request whose commits still lack the trailer seven days after it was asked for is closed: for this one, on 2026-11-26. It can come back after that, as the same section says.
What is right: passphrases, prompt and address are each refused with a SeedScanTypeError before _assert_bound and before any reading; no message quotes a passphrase; the tuple case shows the check does not refuse what it should accept; and the three _NOT_REFUSED entries are gone, so tests/input_validation_test.py now holds the package to it.
What is missing:
1. tests/identify_test.py:718: the docstring is 82 characters, and ruff's E501 fails lint and pre-commit.ci on it. Something like """Passphrases are a list or tuple of str, refused without a secret.""" fits.
2. #63 left one question to this review: the signature's hint for passphrases is Sequence[str], wider than the list or tuple the check accepts, so mypy passes a call that the code then refuses (a collections.deque of strings, say). I would narrow the hint to list[str] | tuple[str, ...], so that the type checker tells a caller what the code refuses.
3. The parametrized tests give no match=, so any SeedScanTypeError passes them, and the first one's docstring says the error bears no secret without checking it. Matching invalid passphrases and invalid address type, and calling assert_secret_free(e.value, ["ab"]) on the "ab" case as test_a_mnemonic_that_is_no_str_is_refused does, would hold both.
Once the trailer is in, I will add these on top of your commit, in a commit of my own, and run the review and the gates; or push them yourself first, if you prefer.
@fametrano
Thanks for pointing this out. I've rebased the PR branch onto the specified base commit using --signoff, ensuring that all commits in the PR history include the required Signed-off-by trailer.
The updated commits have been pushed to my fork. Please let me know if anything else is needed. Thanks!
Thank you, @Aaqibhafeezkhan: you took every point of the review yourself, and fixed the vocabulary test the narrowed hint had broken before I got to it. This now waits only on the maintainer's approval.
Review record, on 36b39d1c091b9efc26f8d20432030f63087d0ada:
passphrases hint #63 left to the review (narrowed to list[str] | tuple[str, ...]), and match= with assert_secret_free in the tests. All three taken, in 0f327be, 16d4310 and 36b39d1.CLEARED 36b39d1, after its inputs ran in the sandbox, 59 of 59 as claimed: every wrong passphrases shape (a str, a deque, a generator, a set, a UserList, a non-str element, and more) is refused with SeedScanTypeError; subclasses of list, tuple and str are accepted; a list and a tuple give the same bundle as main does with a list; every refusal comes before anything is derived or bounded and quotes no secret; and on main the same inputs raise other packages' errors or are accepted, so the new tests fail without the fix. Its findings, none blocking:- the title has no
(closes #63), and no commit message says that a caller passing a sequence other than a list or tuple is now refused: both go in the squash subject and message;- the docstring "The prompt must be callable before any reading starts." could read as a rule on the caller: declined, since it is true of the code (the check comes before any reading, as the inputs show) and leads no reader to a wrong step.
uv sync --locked, the hooks on the three files, tests/identify_test.py with tests/input_validation_test.py (213 passed) and the docs build exit 0. The full suite rests on CI, green on 36b39d1 with coverage at 100%.CLEARED stands in for it.main.Approves 36b39d1, on the maintainer's decision in the session. It relies on the dedicated reviewer's CLEARED 36b39d1, given after its 59 sandboxed inputs (Codex unavailable: out of credits since 2026-11-18 20:33 UTC); no rebase. The review bot is absent (fork), Codex's GitHub review failed on its usage limit, and CodeRabbit hit its review limit. Every check passed or was skipped on 36b39d1. Not checked locally: the full suite, which the sandbox cannot run (loopback binds); CI ran it.
Landed as d30d6f5, thank you, @Aaqibhafeezkhan. identify now refuses a wrong passphrases, prompt or address with the package's own SeedScanTypeError, before anything is derived, where it used to let other packages' errors out or, worse, read the string "ab" as two passphrases.
Nothing was added on top: you made every change the review asked for, and fixed the vocabulary test the narrowed hint broke. The squash message records one thing for users: the passphrases hint is now list[str] | tuple[str, ...], so a caller passing another sequence, such as a deque, is refused. When a change narrows what a public function accepts, saying so in the commit is what lets a user find out why their call stopped working.
If you would like another, #61 (evm.Node accepts any transport and timeout) and #62 (scan and forks refuse a wrong reader or node with another package's error) are open and labelled good first issue; both are the same kind of change as this one.
fametrano
Aaqibhafeezkhan
What this changes
Makes
identifyconsistently reject invalid public inputs withSeedScanTypeError.passphrasesis a list or tuple containing only strings.prompt.addressthat is neither a string norNone.tests/input_validation_test.py's_NOT_REFUSEDset.Closes #63.
How it was verified
Added regression coverage in
tests/identify_test.pyfor:Noneand string values supplied aspassphrases.The input-validation matrix now expects these cases to be refused by the package.
Checks
uv run pre-commit run --all-filesis clean (ruff, mypy strict, markdownlint, the copyright notice,uv.lock)uv run pytestpassesAnything the reviewer should know
The runtime validation follows the issue's list-or-tuple requirement rather than accepting every possible
Sequence[str]implementation.