Skip to content

fix(utility): validate Soroban contract method specifications (#769) - #876

Merged
Just-Bamford merged 4 commits into
Sorokit:mainfrom
Gezziy:fix-validator-ts
Oct 20, 2026
Merged

Just-Bamford merged 4 commits into
Sorokit:mainfrom
Gezziy:fix-validator-ts

Conversation

@Gezziy

@Gezziy Gezziy commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

closes #769

Summary of Changes

  • Contract Method Spec Validation: Added validateContractMethodSpec(method) to src/utility/validator.ts to validate Soroban contract method signatures prior to transaction invocation and preparation.
  • Method Identifier Enforcement: Enforced Soroban symbol formatting rules per CAP-0046 / ScSymbol:
    • Enforced identifier regex: /^[a-zA-Z_][a-zA-Z0-9_]*$/.
    • Prohibited leading digits (e.g. "123_invalid").
    • Prohibited non-alphanumeric punctuation and whitespace (e.g. "foo-bar").
    • Enforced max length of 32 characters (SOROBAN_MAX_METHOD_NAME_LEN).
    • Rejected Rust and Soroban reserved keywords (fn, let, mut, impl, struct, __constructor, etc.).
  • Type System Enforcement: Validated parameter and return types against the Soroban Environment Specification (ScSpecTypeDef / ScVal):
    • Supported all 15 scalar types: u32, i32, u64, i64, u128, i128, u256, i256, bool, void, (), unit, string, symbol, bytes, bytes32, and address.
    • Supported container types with generic parameter checking: vec<T>, map<Key, Value>, tuple<...>, option<T>, result<Ok, Err>.
    • Enforced arity constraints on container types and prohibited generic arguments on scalar types (u32<string>).
    • Rejected unrecognized types (e.g. "invalid_scval_type", "int", "float", "decimal").
  • Flexible Ergonomics: Supported property name aliases (inputs, parameters, params, args) and (returnType, returns, return_type), accepting string arrays or structured parameter descriptor objects.
  • Convenience Helpers: Added isValidContractMethodSpec(method) returning a boolean check.
  • Test Coverage: Added 22 unit tests in src/tests/validator.test.ts covering invalid method names, reserved words, invalid scalar types, container arity mismatches, void returns, and flexible input shapes (58/58 tests passing).

Reason for Changes

Resolves issue #769. Previously, validator.ts did not validate Soroban contract method specifications, permitting callers to pass malformed method names or non-existent scalar types. These malformed specs failed with cryptic RPC or simulation errors on-chain. Early client-side validation fails fast with clear error messages citing the Soroban specification.

Gezziy and others added 4 commits October 20, 2026 12:00
…nges (Sorokit#763)

- Add automatic background timer eviction for expired SEP-10 challenge contexts
- Implement O(K) early-exit pruning leveraging uniform TTL insertion monotonicity
- Eagerly clean expired challenges on initiateSep10Auth and completeSep10Auth
- Evaluate caller-supplied options.now in completeSep10Auth with clear error on expiry
- Unreference background timer handle to prevent holding the Node.js event loop
- Export pruneExpiredChallenges, getPendingChallengesCount, and clearPendingChallenges helpers
- Add unit and integration tests covering idle background eviction and FIFO limits
…t#769)

- Add validateContractMethodSpec to validate method names, parameters, and return types
- Enforce Soroban method identifier rules (max 32 chars, no leading digits, no reserved keywords)
- Validate parameter and return types against Soroban scalar and container specifications
- Support container generic types (vec, map, option, result, tuple) with arity checking
- Add isValidContractMethodSpec boolean helper and export types
- Add 22 unit tests covering valid edge cases and malformed specs
@drips-wave

drips-wave Bot commented Oct 20, 2026

Copy link
Copy Markdown

@Gezziy Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Just-Bamford
Just-Bamford merged commit 2f831ea into Sorokit:main Oct 20, 2026
5 checks passed
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.

validator.ts does not validate Soroban contract method signatures — accepts malformed method specs

3 participants