Skip to content

refactor(swift-sdk): key management#3050

Merged
QuantumExplorer merged 3 commits into
feat/iOSSupportfrom
refactor/phase-3-key-management
Feb 4, 2026
Merged

refactor(swift-sdk): key management#3050
QuantumExplorer merged 3 commits into
feat/iOSSupportfrom
refactor/phase-3-key-management

Conversation

@alfie-dash
Copy link
Copy Markdown
Contributor

Issue being fixed or feature implemented

Phase 3 of Swift SDK refactoring: Centralize private key management utilities for better code reuse and consistent error handling.

What was done?

Added PrivateKeyUtils.swift with centralized utilities for private key operations:

  • KeyFormatDetector: Detect hex (64 chars) vs WIF format automatically
  • PrivateKeyParser: Parse keys from hex or WIF with detailed error messages and format detection
  • KeyValidator: Validate private keys against identity public keys with structured results
  • KeySizeValidator: Validate key sizes for different key types (ECDSA, BLS, EdDSA)
  • KeyFormatter: Format keys for display (hex, WIF, truncated public keys)

Updated Views to use new centralized utilities:

  • KeyDetailView: Uses PrivateKeyParser and KeyValidator instead of inline parsing logic

How Has This Been Tested?

  • Added 29 unit tests for all key utilities in KeyManagerTests.swift
  • All existing tests pass (130+ total tests)
  • Build verified on iOS Simulator

Breaking Changes

None

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed
- Add new validator methods to AddressValidator:
  - validateBech32mAddress() for bech32m Platform addresses
  - validateAddress() with auto-detection (hex or bech32m)
  - validateHash() for 32-byte hashes
  - validateIdentityIdHex() and isHexIdentityId() for identity IDs

- Create comprehensive unit tests for all validators (40+ tests)
  covering AddressValidator, TransferInputValidator,
  WithdrawInputValidator, TopUpAddressFromAssetLockValidator,
  and Identity validators

- Update views to use centralized validators:
  - AddressQueriesView: use validateHash()
  - DocumentWithPriceView: use isHexIdentityId()
  - TransitionDetailView: use isHexIdentityId()
Add DataTransformers.swift with utilities for address, number, and response transformations:
- AddressTransformer: hex/Data conversion, bech32m parsing, identity ID normalization
- NumberTransformer: UInt64/UInt32 parsing, amount formatting, credits/duffs to Dash
- ResponseParser: PlatformAddressInfo parsing and formatting
- TransferInputBuilder: create transfer inputs/outputs from form strings

Update ViewModels to use new transformers:
- AddressTransferViewModel: use TransferInputBuilder
- WithdrawAddressFundsViewModel: use TransferInputBuilder and NumberTransformer
- TopUpAddressFromAssetLockViewModel: use AddressTransformer and NumberTransformer

Add comprehensive unit tests for all transformer functionality (39 tests).
Add PrivateKeyUtils.swift with utilities for private key management:
- KeyFormatDetector: detect hex vs WIF format
- PrivateKeyParser: parse keys from hex or WIF with detailed error messages
- KeyValidator: validate private keys against public keys
- KeySizeValidator: validate key sizes for different key types
- KeyFormatter: format keys for display (hex, WIF, truncated)

Add comprehensive unit tests for all key utilities (29 tests).

Update KeyDetailView to use centralized PrivateKeyParser and KeyValidator
instead of inline parsing logic.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 4, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/phase-3-key-management

Important

Action Needed: IP Allowlist Update

If your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:

  • 136.113.208.247/32 (new)
  • 34.170.211.100/32
  • 35.222.179.152/32

Reviews will stop working after February 8, 2026 if the new IP is not added to your allowlist.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 4, 2026

✅ DashSDKFFI.xcframework built for this PR.

SwiftPM (host the zip at a stable URL, then use):

.binaryTarget(
  name: "DashSDKFFI",
  url: "https://your.cdn.example/DashSDKFFI.xcframework.zip",
  checksum: "b08c4ea2b28883b77e4a016680b8a15e464a99e9cb7d2159877276173bc1affa"
)

Xcode manual integration:

  • Download 'DashSDKFFI.xcframework' artifact from the run link above.
  • Drag it into your app target (Frameworks, Libraries & Embedded Content) and set Embed & Sign.
  • If using the Swift wrapper package, point its binaryTarget to the xcframework location or add the package and place the xcframework at the expected path.
@QuantumExplorer QuantumExplorer merged commit b4c83e7 into feat/iOSSupport Feb 4, 2026
4 of 5 checks passed
@QuantumExplorer QuantumExplorer deleted the refactor/phase-3-key-management branch February 4, 2026 13:35
shumkov added a commit that referenced this pull request May 13, 2026
Extracts the resumable-asset-lock filter from CreateIdentityView into a
pure static `resumableLocks(in:usedIndices:walletId:)` generic over a
new `AssetLockResumeRow` protocol so unit tests can exercise the
business logic without spinning up a SwiftData ModelContainer. View
keeps its private `resumableAssetLocks(for:)` entry point as a
one-line wrapper that supplies the live `@Query` results.

Eight test cases cover the three pieces of logic that can silently
regress:
- walletId match (cross-wallet bleed)
- statusRaw >= 2 floor (Built/Broadcast rejected, ISLock/CLock
  accepted, forward-compatible for any future status >= 2)
- anti-join against the per-wallet used-slot set (including the
  Int32 -> UInt32 bitPattern bridge for the negative-index edge)

Drive-by fix: KeyManagerTests:178 was calling
`KeyFormatter.toWIF(_, isTestnet:)` but the SDK changed the signature
to `network:` in #3050 (Feb 2026); the test target couldn't build.
Updated the call so `xcodebuild test` works again.

All 8 new tests pass on iPhone 17 Pro sim (iOS 26.4.1).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants