Repository navigation
refactor(swift-sdk): lean down stale app and SDK layers - #3539
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughRemoves many Swift SDK and example-app compatibility shims and documentation, deletes several wrapper types and a state manager, adds DPP identity/key types and a SwiftData model entry, and updates example app wiring and view imports. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant FetchContractView
participant SDK as SwiftDashSDK
participant ModelContext
participant Parser as DataContractParser
User->>FetchContractView: tap Fetch
FetchContractView->>SDK: dataContractGet(trimmedId)
SDK-->>FetchContractView: Data (contractBytes)
FetchContractView->>FetchContractView: validate id, check duplicates
alt not duplicate
FetchContractView->>ModelContext: insert PersistentDataContract(contractBytes)
ModelContext-->>FetchContractView: saved
FetchContractView->>Parser: parseDataContract(contractBytes)
Parser-->>ModelContext: parsed documents/metadata -> save
FetchContractView-->>User: success (dismiss)
else duplicate / invalid id
FetchContractView-->>User: error (show)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Review GateCommit:
|
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
packages/swift-sdk/Sources/SwiftDashSDK/DPP/DPPIdentity.swift (2)
117-122: Minor:isDisabledevaluates current time on every access.
Date().timeIntervalSince1970 * 1000is recomputed for every read ofisDisabled, and theDouble → UInt64conversion silently truncates sub-millisecond precision. Functionally fine, but if this is hot-pathed (e.g. inside SwiftUI bodies), prefer accepting an explicitnow: TimestampMillisparameter on a method (isDisabled(at:)) so callers control the clock and tests stay deterministic.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/swift-sdk/Sources/SwiftDashSDK/DPP/DPPIdentity.swift` around lines 117 - 122, The isDisabled computed property currently samples Date() on every access and truncates sub-millisecond precision; replace this hot-path property with a deterministic method isDisabled(at: TimestampMillis) that takes an explicit now parameter (using the existing TimestampMillis type) and implement the existing isDisabled to call isDisabled(at: TimestampMillis(Date().timeIntervalSince1970 * 1000)) if you want to keep the convenience property; update callers/tests to pass a controlled TimestampMillis to isDisabled(at:) for deterministic behavior and avoid repeated Date() sampling in hot paths.
51-61: Consider conforming toCustomStringConvertible(or rename) for thedescriptionproperties.
KeyPurpose(lines 51-61),SecurityLevel(lines 86-93), andContractBounds(lines 151-158) each expose a publicdescription: Stringbut do not conform toCustomStringConvertible. In Swift this is a known foot-gun:String(describing: value),"\(value)", andprint(value)will fall back to the reflection-based default and silently bypass these custom strings. Either conform to the protocol so the helper is actually picked up, or rename to e.g.summary/humanReadableto avoid shadowing the standard semantics.♻️ Example fix for `ContractBounds`
-public enum ContractBounds: Codable, Equatable, Sendable { +public enum ContractBounds: Codable, Equatable, Sendable, CustomStringConvertible { case singleContract(id: Identifier) case singleContractDocumentType(id: Identifier, documentTypeName: String)Apply the analogous change to
KeyPurposeandSecurityLevel.Also applies to: 86-93, 151-158
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/swift-sdk/Sources/SwiftDashSDK/DPP/DPPIdentity.swift` around lines 51 - 61, The enums KeyPurpose, SecurityLevel, and ContractBounds expose public description properties but don't conform to CustomStringConvertible; update each enum declaration to adopt CustomStringConvertible (e.g., "enum KeyPurpose: CustomStringConvertible") so their existing public var description: String implementations are actually used by String(describing:) / print, or alternatively rename the property (e.g., summary or humanReadable) if you intentionally don't want the protocol; ensure the signature remains public and remove any conflicting members so the compiler accepts the protocol conformance for KeyPurpose, SecurityLevel, and ContractBounds.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/swift-sdk/Sources/SwiftDashSDK/DPP/DPPIdentity.swift`:
- Around line 151-158: In DPPIdentity.swift update the description computed
property for the enum cases singleContract and singleContractDocumentType to
call the established Data method name: replace id.toBase58() with
id.toBase58String() so the switch arms in var description use the same
toBase58String() convention used elsewhere (e.g., lines ~181/215 and other call
sites).
In
`@packages/swift-sdk/Sources/SwiftDashSDK/Persistence/DashModelContainer.swift`:
- Line 24: The change adds PersistentCoreAddress.self to
DashModelContainer.modelTypes which mutates DashSchemaV1 in place; either
document that this is an intentional lightweight SwiftData migration or create
an explicit new schema/version and migration stage. Fix by adding a clear
comment on DashSchemaV1 (or DashMigrationPlan) stating that adding
PersistentCoreAddress is additive and safe for lightweight migration, or
alternatively add a new DashSchemaV2 with version (1,0,1) or (1,1,0), register
DashSchemaV2 in DashMigrationPlan.schemas and add
MigrationStage.lightweight(fromVersion: .init(1,0,0), toVersion: .init(1,0,1))
to DashMigrationPlan so the upgrade is explicit and deterministic; reference
PersistentCoreAddress, DashModelContainer.modelTypes, DashSchemaV1/DashSchemaV2,
DashMigrationPlan, and MigrationStage.lightweight when making the change.
In
`@packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/ContractsView.swift`:
- Around line 258-266: In fetchContract(), don't route success through
appState.showError or discard the returned contract: instead either call a new
success UI (add and use appState.showInfo if you prefer a separate success
surface) or persist the fetched value into the model container so the
`@Query`(PersistentDataContract) updates; specifically, replace the discarded call
to sdk.dataContractGet(id:) by capturing the returned dictionary, map it into a
PersistentDataContract instance, and insert it into the ModelContainer (or call
the existing contract persister) before closing the sheet, and change the
success notification to use a non-error method (e.g., appState.showInfo) or a
neutral UI path instead of appState.showError.
---
Nitpick comments:
In `@packages/swift-sdk/Sources/SwiftDashSDK/DPP/DPPIdentity.swift`:
- Around line 117-122: The isDisabled computed property currently samples Date()
on every access and truncates sub-millisecond precision; replace this hot-path
property with a deterministic method isDisabled(at: TimestampMillis) that takes
an explicit now parameter (using the existing TimestampMillis type) and
implement the existing isDisabled to call isDisabled(at:
TimestampMillis(Date().timeIntervalSince1970 * 1000)) if you want to keep the
convenience property; update callers/tests to pass a controlled TimestampMillis
to isDisabled(at:) for deterministic behavior and avoid repeated Date() sampling
in hot paths.
- Around line 51-61: The enums KeyPurpose, SecurityLevel, and ContractBounds
expose public description properties but don't conform to
CustomStringConvertible; update each enum declaration to adopt
CustomStringConvertible (e.g., "enum KeyPurpose: CustomStringConvertible") so
their existing public var description: String implementations are actually used
by String(describing:) / print, or alternatively rename the property (e.g.,
summary or humanReadable) if you intentionally don't want the protocol; ensure
the signature remains public and remove any conflicting members so the compiler
accepts the protocol conformance for KeyPurpose, SecurityLevel, and
ContractBounds.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: da534d62-a8f3-4d32-b2b9-b8a95008f21d
📒 Files selected for processing (44)
packages/swift-sdk/IDENTITY_API_FIXES_SUMMARY.mdpackages/swift-sdk/IMPLEMENTATION_SUMMARY.mdpackages/swift-sdk/Sources/SwiftDashSDK/Core/Utils/ModelContainerHelper.swiftpackages/swift-sdk/Sources/SwiftDashSDK/DPP/DPPIdentity.swiftpackages/swift-sdk/Sources/SwiftDashSDK/DPP/DPPTypes.swiftpackages/swift-sdk/Sources/SwiftDashSDK/DataContract.swiftpackages/swift-sdk/Sources/SwiftDashSDK/Identity.swiftpackages/swift-sdk/Sources/SwiftDashSDK/IdentityTypes.swiftpackages/swift-sdk/Sources/SwiftDashSDK/KeyWallet/BIP38.swiftpackages/swift-sdk/Sources/SwiftDashSDK/KeyWallet/KeyWallet.swiftpackages/swift-sdk/Sources/SwiftDashSDK/KeyWallet/README.mdpackages/swift-sdk/Sources/SwiftDashSDK/Persistence/DashModelContainer.swiftpackages/swift-sdk/Sources/SwiftDashSDK/SDK.swiftpackages/swift-sdk/Sources/SwiftDashSDK/Shared/UnifiedStateManager.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/AppState.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/DPP/DPPCoreTypes.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/DPP/DataContract.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/DPP/Document.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/DPP/Identity.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/DPP/README.mdpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/DPP/StateTransition.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/SwiftData/ModelContainer+App.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/SwiftData/PersistentDataContract.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/SwiftData/PersistentDocument.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/SwiftData/PersistentDocumentType.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/SwiftData/PersistentIdentity.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/SwiftData/PersistentIndex.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/SwiftData/PersistentKeyword.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/SwiftData/PersistentProperty.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/SwiftData/PersistentPublicKey.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/SwiftData/PersistentToken.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/SwiftData/PersistentTokenBalance.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/SwiftData/PersistentTokenHistoryEvent.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/SwiftExampleAppApp.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/ContractsView.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/DataContractDetailsView.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/DocumentFieldsView.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/DocumentTypeDetailsView.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/TokenDetailsView.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/TokenSearchView.swiftpackages/swift-sdk/SwiftTests/TEST_FIX_SUMMARY.mdpackages/swift-sdk/TEST_VERIFICATION.mdpackages/swift-sdk/WALLET_IMPLEMENTATION_SUMMARY.mdpackages/swift-sdk/ios_to_dash_api_mapping.md
💤 Files with no reviewable changes (33)
- packages/swift-sdk/Sources/SwiftDashSDK/KeyWallet/BIP38.swift
- packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/SwiftData/PersistentIdentity.swift
- packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/SwiftData/PersistentTokenBalance.swift
- packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/SwiftData/PersistentKeyword.swift
- packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/DPP/README.md
- packages/swift-sdk/IMPLEMENTATION_SUMMARY.md
- packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/SwiftData/PersistentIndex.swift
- packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/SwiftData/PersistentDataContract.swift
- packages/swift-sdk/Sources/SwiftDashSDK/KeyWallet/KeyWallet.swift
- packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/DPP/Identity.swift
- packages/swift-sdk/TEST_VERIFICATION.md
- packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/SwiftData/PersistentDocumentType.swift
- packages/swift-sdk/WALLET_IMPLEMENTATION_SUMMARY.md
- packages/swift-sdk/IDENTITY_API_FIXES_SUMMARY.md
- packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/SwiftData/PersistentTokenHistoryEvent.swift
- packages/swift-sdk/Sources/SwiftDashSDK/Identity.swift
- packages/swift-sdk/SwiftTests/TEST_FIX_SUMMARY.md
- packages/swift-sdk/ios_to_dash_api_mapping.md
- packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/DPP/DPPCoreTypes.swift
- packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/SwiftData/PersistentDocument.swift
- packages/swift-sdk/Sources/SwiftDashSDK/DataContract.swift
- packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/DPP/DataContract.swift
- packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/DPP/StateTransition.swift
- packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/DPP/Document.swift
- packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/AppState.swift
- packages/swift-sdk/Sources/SwiftDashSDK/Core/Utils/ModelContainerHelper.swift
- packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/SwiftData/PersistentProperty.swift
- packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/SwiftData/ModelContainer+App.swift
- packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/SwiftData/PersistentToken.swift
- packages/swift-sdk/Sources/SwiftDashSDK/SDK.swift
- packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Models/SwiftData/PersistentPublicKey.swift
- packages/swift-sdk/Sources/SwiftDashSDK/IdentityTypes.swift
- packages/swift-sdk/Sources/SwiftDashSDK/Shared/UnifiedStateManager.swift
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/swift-sdk/Sources/SwiftDashSDK/DPP/DPPIdentity.swift (1)
117-122: Minor:isDisabledis time-dependent and non-deterministic.
isDisabledreturns different results across calls depending on wall-clock time, which is fine for UI but can surprise tests, caching, orEquatable-based diffing on parent structures. Two small considerations:
- If callers compare
IdentityPublicKeyinstances,isDisabledis excluded fromEquatable(it's a computed property), so that's safe — just worth being aware of.- Consider exposing
isDisabled(at: Date = Date())so tests can inject a clock without freezing time globally.Not blocking.
♻️ Optional refactor
- /// Check if the key is currently disabled - public var isDisabled: Bool { - guard let disabledAt = disabledAt else { return false } - let currentTime = TimestampMillis(Date().timeIntervalSince1970 * 1000) - return disabledAt <= currentTime - } + /// Check if the key is disabled relative to the provided instant (defaults to now). + public func isDisabled(at date: Date = Date()) -> Bool { + guard let disabledAt = disabledAt else { return false } + return disabledAt <= TimestampMillis(date.timeIntervalSince1970 * 1000) + } + + /// Convenience: disabled relative to the current wall clock. + public var isDisabled: Bool { isDisabled(at: Date()) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/swift-sdk/Sources/SwiftDashSDK/DPP/DPPIdentity.swift` around lines 117 - 122, The computed property isDisabled is time-dependent and non-deterministic; add a new API isDisabled(at timestamp: Date = Date()) -> Bool that takes an injectable clock and implement the existing public var isDisabled to call isDisabled(at: Date()), then update any internal uses to call the new method when a specific time is needed to enable deterministic tests; reference the existing property isDisabled and the stored property disabledAt when implementing the check so disabledAt <= TimestampMillis(timestamp.timeIntervalSince1970 * 1000) is used inside isDisabled(at:).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/swift-sdk/Sources/SwiftDashSDK/DPP/DPPIdentity.swift`:
- Around line 71-103: The Comparable ordering is inverted (lower rawValue ==
stricter level) which is surprising; add a brief doc comment on the
SecurityLevel enum that explains "Comparable uses protocol/rawValue ordering:
lower rawValue = stricter security", and add one or two clearly named helpers to
make call-sites readable — e.g. add func meetsOrExceeds(_ required:
SecurityLevel) -> Bool { return self.rawValue <= required.rawValue } and/or func
isLessSecure(than other: SecurityLevel) -> Bool { return self.rawValue >
other.rawValue } (keep the existing Comparable implementation and ffiValue
as-is). Ensure the new helpers are public and documented so callers can use
key.securityLevel.meetsOrExceeds(requiredLevel) instead of relying on raw '<'
semantics.
- Around line 147-168: ContractBounds' synthesized Codable doesn't match Rust's
externally-tagged serde format; implement custom encode(to:) and init(from:) for
enum ContractBounds so it serializes as {"type":"singleContract", "id":...} and
{"type":"singleContractDocumentType", "id":..., "documentType":...} (note the
inner key must be "documentType" for the second case), using the existing cases
singleContract(id:), singleContractDocumentType(id:documentTypeName:), and the
contractId/description helpers for reference; ensure the "type" field uses
camelCase names ("singleContract" and "singleContractDocumentType") and decode
accordingly, throwing decoding errors for unknown types or missing fields.
---
Nitpick comments:
In `@packages/swift-sdk/Sources/SwiftDashSDK/DPP/DPPIdentity.swift`:
- Around line 117-122: The computed property isDisabled is time-dependent and
non-deterministic; add a new API isDisabled(at timestamp: Date = Date()) -> Bool
that takes an injectable clock and implement the existing public var isDisabled
to call isDisabled(at: Date()), then update any internal uses to call the new
method when a specific time is needed to enable deterministic tests; reference
the existing property isDisabled and the stored property disabledAt when
implementing the check so disabledAt <=
TimestampMillis(timestamp.timeIntervalSince1970 * 1000) is used inside
isDisabled(at:).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0dce8d44-44d1-4143-ad1f-afea75b4a04a
📒 Files selected for processing (5)
.gitignorepackages/swift-sdk/Sources/SwiftDashSDK/DPP/DPPIdentity.swiftpackages/swift-sdk/Sources/SwiftDashSDK/Persistence/DashModelContainer.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/AppState.swiftpackages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/DataContractDetailsView.swift
💤 Files with no reviewable changes (1)
- packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/AppState.swift
✅ Files skipped from review due to trivial changes (2)
- packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/DataContractDetailsView.swift
- .gitignore
|
✅ 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: "0fde9e97b3cd44d766b39cb2ebaf3324df63b1770e67295473ecdce3326274e2"
)Xcode manual integration:
|
…ean-wave1 # Conflicts: # packages/swift-sdk/Sources/SwiftDashSDK/Core/Utils/ModelContainerHelper.swift
Summary
Validation
Notes
Summary by CodeRabbit
New Features
Breaking Changes
Documentation